Repository navigation
CBG-5951: make changeCache.initialSequence atomic #8854
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鈥檒l occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
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 hidden or 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
This file contains hidden or 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 |
|---|---|---|
|
|
@@ -3059,6 +3059,55 @@ func TestDocChangedStartupSequenceFilter(t *testing.T) { | |
| assert.Equal(t, "aboveInitial", cached[0].DocID) | ||
| } | ||
|
|
||
| // TestDocChangedBeforeStart delivers feed events between Init and Start, as the DCP feed does on database startup. | ||
| // A replay at initialSequence must still be kept out of the cache once Start runs. | ||
| func TestDocChangedBeforeStart(t *testing.T) { | ||
| const initialSequence = 100 | ||
| database, ctx := db.SetupTestDB(t) | ||
| defer database.Close(ctx) | ||
| collection := db.GetSingleDatabaseCollection(t, database.DatabaseContext) | ||
| collectionID := collection.GetCollectionID() | ||
|
|
||
| changeCache := db.NewChangeCacheForTest(t) | ||
| require.NoError(t, changeCache.Init(ctx, database.DatabaseContext, database.DatabaseContext.ChannelCacheForTest(t), | ||
| nil, nil, database.DatabaseContext.MetadataKeys)) | ||
| defer changeCache.Stop(ctx) | ||
|
|
||
| syncDataFor := func(seq uint64) db.SyncData { | ||
| return db.SyncData{ | ||
| RevAndVersion: channels.RevAndVersion{RevTreeID: "1-abc"}, | ||
| Sequence: seq, | ||
| Channels: channels.ChannelMap{"ABC": nil}, | ||
| History: db.RevTree{"1-abc": &db.RevInfo{ID: "1-abc", Channels: base.SetOf("ABC")}}, | ||
| } | ||
| } | ||
|
|
||
| // The channel has to exist before the feed event or nothing lands in it. | ||
| abcChannel := channels.NewID("ABC", collectionID) | ||
| _, err := database.DatabaseContext.ChannelCacheForTest(t).GetCachedChanges(ctx, abcChannel) | ||
| require.NoError(t, err) | ||
|
|
||
| events := []sgbucket.FeedEvent{ | ||
| feedEventForTest(t, "atInitial", collectionID, syncDataFor(initialSequence)), | ||
| feedEventForTest(t, "aboveInitial", collectionID, syncDataFor(initialSequence+1)), | ||
| } | ||
| var wg sync.WaitGroup | ||
| for _, event := range events { | ||
| wg.Go(func() { | ||
| changeCache.DocChanged(event, db.DocTypeDocument) | ||
| }) | ||
|
torcolvin marked this conversation as resolved.
|
||
| } | ||
|
|
||
| require.NoError(t, changeCache.Start(initialSequence)) | ||
| wg.Wait() | ||
|
Comment on lines
+3094
to
+3102
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Goroutines are needed here otherwise will deadlock. I agree though that this doesn't guarantee that the events are delivered before Start is called. But we already have testing around that handling so no need to worry about the ordering here. |
||
|
|
||
| assert.Equal(t, uint64(initialSequence+1), changeCache.LastSequence()) | ||
| cached, err := database.DatabaseContext.ChannelCacheForTest(t).GetCachedChanges(ctx, abcChannel) | ||
| require.NoError(t, err) | ||
| require.Len(t, cached, 1) | ||
| assert.Equal(t, "aboveInitial", cached[0].DocID) | ||
| } | ||
|
|
||
| // TestDocChangedRecentSequences covers how DocChanged backfills sequences that DCP deduplicated | ||
| // away. A document's recent_sequences carry the sequences it consumed but never emitted; the cache | ||
| // has to synthesise entries for them or sequence buffering stalls. A sequence at which the document | ||
|
|
||
Oops, something went wrong.
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.
This is fine DocChanged may not flag as a sequence below initial sequence on startup when initial sequence is 0 (not yet set) but procesEntry duplicate checking will filter it out and by the time any goroutine acquires change cache lock this value must be set.