-
Notifications
You must be signed in to change notification settings - Fork 455
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 races triggered by TestRoundtrip in flushManager and bootstrapManager #2586
Merged
Merged
Changes from 1 commit
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
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
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
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
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 |
---|---|---|
|
@@ -25,6 +25,7 @@ import ( | |
"time" | ||
|
||
"github.com/golang/mock/gomock" | ||
xtime "github.com/m3db/m3/src/x/time" | ||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
|
@@ -34,16 +35,17 @@ func TestDatabaseIsBootstrappedAndDurable(t *testing.T) { | |
|
||
var ( | ||
validIsBootstrapped = true | ||
validShardSetAssignedAt = time.Now() | ||
validLastBootstrapCompletionTime = validShardSetAssignedAt.Add(time.Second) | ||
validLastSuccessfulSnapshotStartTime = validLastBootstrapCompletionTime.Add(time.Second) | ||
validShardSetAssignedAt = xtime.ToUnixNano(time.Now()) | ||
validLastBootstrapCompletionTime = xtime.ToUnixNano(validShardSetAssignedAt.ToTime().Add(time.Second)) | ||
validLastSuccessfulSnapshotStartTime = xtime.ToUnixNano(validLastBootstrapCompletionTime.ToTime().Add(time.Second)) | ||
zeroTime = xtime.UnixNano(0) | ||
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. nit: This can just be |
||
) | ||
testCases := []struct { | ||
title string | ||
isBootstrapped bool | ||
lastBootstrapCompletionTime time.Time | ||
lastSuccessfulSnapshotStartTime time.Time | ||
shardSetAssignedAt time.Time | ||
lastBootstrapCompletionTime xtime.UnixNano | ||
lastSuccessfulSnapshotStartTime xtime.UnixNano | ||
shardSetAssignedAt xtime.UnixNano | ||
expectedResult bool | ||
}{ | ||
{ | ||
|
@@ -57,7 +59,7 @@ func TestDatabaseIsBootstrappedAndDurable(t *testing.T) { | |
{ | ||
title: "False if no last bootstrap completion time", | ||
isBootstrapped: validIsBootstrapped, | ||
lastBootstrapCompletionTime: time.Time{}, | ||
lastBootstrapCompletionTime: zeroTime, | ||
lastSuccessfulSnapshotStartTime: validLastSuccessfulSnapshotStartTime, | ||
shardSetAssignedAt: validShardSetAssignedAt, | ||
expectedResult: false, | ||
|
@@ -66,7 +68,7 @@ func TestDatabaseIsBootstrappedAndDurable(t *testing.T) { | |
title: "False if no last successful snapshot start time", | ||
isBootstrapped: validIsBootstrapped, | ||
lastBootstrapCompletionTime: validLastBootstrapCompletionTime, | ||
lastSuccessfulSnapshotStartTime: time.Time{}, | ||
lastSuccessfulSnapshotStartTime: zeroTime, | ||
shardSetAssignedAt: validShardSetAssignedAt, | ||
expectedResult: false, | ||
}, | ||
|
@@ -91,7 +93,7 @@ func TestDatabaseIsBootstrappedAndDurable(t *testing.T) { | |
isBootstrapped: validIsBootstrapped, | ||
lastBootstrapCompletionTime: validLastBootstrapCompletionTime, | ||
lastSuccessfulSnapshotStartTime: validLastSuccessfulSnapshotStartTime, | ||
shardSetAssignedAt: validLastBootstrapCompletionTime.Add(time.Second), | ||
shardSetAssignedAt: validLastBootstrapCompletionTime + xtime.UnixNano(xtime.Second), | ||
expectedResult: false, | ||
}, | ||
{ | ||
|
@@ -113,7 +115,7 @@ func TestDatabaseIsBootstrappedAndDurable(t *testing.T) { | |
|
||
mediator := NewMockdatabaseMediator(ctrl) | ||
d.mediator = mediator | ||
d.lastReceivedNewShards = tc.shardSetAssignedAt | ||
d.lastReceivedNewShards = tc.shardSetAssignedAt.ToTime() | ||
|
||
mediator.EXPECT().IsBootstrapped().Return(tc.isBootstrapped) | ||
if !tc.isBootstrapped { | ||
|
@@ -122,17 +124,17 @@ func TestDatabaseIsBootstrappedAndDurable(t *testing.T) { | |
return | ||
} | ||
|
||
if tc.lastBootstrapCompletionTime.IsZero() { | ||
mediator.EXPECT().LastBootstrapCompletionTime().Return(time.Time{}, false) | ||
if tc.lastBootstrapCompletionTime == 0 { | ||
mediator.EXPECT().LastBootstrapCompletionTime().Return(zeroTime, false) | ||
assert.Equal(t, tc.expectedResult, d.IsBootstrappedAndDurable()) | ||
// Early return because other mock calls will not get called. | ||
return | ||
} | ||
|
||
mediator.EXPECT().LastBootstrapCompletionTime().Return(tc.lastBootstrapCompletionTime, true) | ||
|
||
if tc.lastSuccessfulSnapshotStartTime.IsZero() { | ||
mediator.EXPECT().LastSuccessfulSnapshotStartTime().Return(time.Time{}, false) | ||
if tc.lastSuccessfulSnapshotStartTime == 0 { | ||
mediator.EXPECT().LastSuccessfulSnapshotStartTime().Return(zeroTime, false) | ||
assert.Equal(t, tc.expectedResult, d.IsBootstrappedAndDurable()) | ||
// Early return because other mock calls will not get called. | ||
return | ||
|
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
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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.
Probably could just use the existing sync.RWMutex to protect this state yeah?
Here it seems fine, but just in general for not highly contended code paths would prefer to stick to simple solutions, otherwise folks start to do lots of tricky hand offs and CompareAndSwaps... etc when they could have just as easily used a mutex.
Thoughts?
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.
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.
Sure thing! I just assumed it was as gnarly as
flushManager
, so used the same apporach.