-
Notifications
You must be signed in to change notification settings - Fork 130
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix partitioned session window bug during checkpoint restore #143
Open
arunkm
wants to merge
1
commit into
master
Choose a base branch
from
users/arunkm/fix-PartitionedSessionWindow-bug
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
100 changes: 100 additions & 0 deletions
100
Sources/Test/SimpleTesting/Partitioned/PartitionedStreamCheckpointTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
// ********************************************************************* | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT License | ||
// ********************************************************************* | ||
using System; | ||
using System.Collections.Generic; | ||
using System.IO; | ||
using System.Linq; | ||
using System.Reactive.Linq; | ||
using System.Reactive.Subjects; | ||
using Microsoft.StreamProcessing; | ||
using Microsoft.VisualStudio.TestTools.UnitTesting; | ||
|
||
namespace SimpleTesting | ||
{ | ||
/* This testcase verifies fix for bug where PartitionedSessionWindowPipe is not restored (from checkpoint) properly causing an exception | ||
* | ||
* Cause of the Bug: | ||
* The PartitionedSessionWindowPipe keeps multiple dictionary states. | ||
* One of the dictionary does not have a [DataMember] attribute, Because the value type is a LinkedList which does not support serialization. | ||
* On checkpoint and then Restore, this dictionary is re-created using other data members in UpdatePointers callback. | ||
* During this, the scenario of empty LinkedList value is missed and not restored. | ||
* When next data event appears for the partition, the partitionKey is indexed on the dictionary resulting in KeyNotFoundException | ||
*/ | ||
[TestClass] | ||
public class PartitionedStreamCheckpointTests : TestWithConfigSettingsWithoutMemoryLeakDetection | ||
{ | ||
[TestMethod, TestCategory("Gated")] | ||
public void CheckpointPartitionedSessionWindow() | ||
{ | ||
Config.DataBatchSize = 1; | ||
|
||
var data = new PartitionedStreamEvent<int, double>[] | ||
{ | ||
PartitionedStreamEvent.CreatePoint(0, 5, 1.0), | ||
PartitionedStreamEvent.CreatePunctuation<int, double>(0, 8), | ||
PartitionedStreamEvent.CreatePunctuation<int, double>(0, 11), | ||
PartitionedStreamEvent.CreatePunctuation<int, double>(0, 14), | ||
PartitionedStreamEvent.CreatePunctuation<int, double>(0, 17), | ||
PartitionedStreamEvent.CreatePunctuation<int, double>(0, 21), | ||
PartitionedStreamEvent.CreatePoint(0, 24, 1.0), | ||
PartitionedStreamEvent.CreatePunctuation<int, double>(0, 100), | ||
}; | ||
|
||
var expected = new PartitionedStreamEvent<int, double>[] | ||
{ | ||
PartitionedStreamEvent.CreateStart(0, 5, 1.0), | ||
PartitionedStreamEvent.CreatePunctuation<int, double>(0, 8), | ||
PartitionedStreamEvent.CreateEnd(0, 9, 5, 1.0), | ||
PartitionedStreamEvent.CreatePunctuation<int, double>(0, 11), | ||
PartitionedStreamEvent.CreatePunctuation<int, double>(0, 14), | ||
PartitionedStreamEvent.CreatePunctuation<int, double>(0, 17), | ||
PartitionedStreamEvent.CreatePunctuation<int, double>(0, 21), | ||
PartitionedStreamEvent.CreateStart(0, 24, 1.0), | ||
PartitionedStreamEvent.CreateEnd(0, 28, 24, 1.0), | ||
PartitionedStreamEvent.CreatePunctuation<int, double>(0, 100), | ||
}; | ||
|
||
// This index represents the point when the checkpoint restore needs to happen to trigger the bug. | ||
const int checkpointIndex = 6; | ||
|
||
var subject = new Subject<PartitionedStreamEvent<int, double>>(); | ||
var output = new List<PartitionedStreamEvent<int, double>>(); | ||
var process = CreateQueryContainerForPartitionedStream(subject, output); | ||
|
||
for (int i = 0; i < data.Length; i++) | ||
{ | ||
if (i == checkpointIndex) | ||
{ | ||
using (var ms = new MemoryStream()) | ||
{ | ||
process.Checkpoint(ms); | ||
ms.Seek(0, SeekOrigin.Begin); | ||
|
||
subject = new Subject<PartitionedStreamEvent<int, double>>(); | ||
process = CreateQueryContainerForPartitionedStream(subject, output, ms); | ||
} | ||
} | ||
|
||
subject.OnNext(data[i]); | ||
} | ||
|
||
Assert.IsTrue(expected.SequenceEqual(output)); | ||
} | ||
|
||
private Process CreateQueryContainerForPartitionedStream( | ||
Subject<PartitionedStreamEvent<int, double>> subject, | ||
List<PartitionedStreamEvent<int, double>> output, | ||
Stream stream = null) | ||
{ | ||
var qc = new QueryContainer(); | ||
var input = qc.RegisterInput(subject); | ||
var streamableOutput = input.SessionTimeoutWindow(4, 5).Sum(o => o); | ||
var egress = qc.RegisterOutput(streamableOutput).ForEachAsync(o => output.Add(o)); | ||
var process = qc.Restore(stream); | ||
|
||
return process; | ||
} | ||
} | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please add comments to explain why this is necessary - e.g., orderedKeysDictionary is not included in checkpoint, so needs to be restored, and every entry in the other collections also needs to be present in orderedKeysDictionary upon restore as that assumption is made throughout this class, etc. #Closed