-
Notifications
You must be signed in to change notification settings - Fork 727
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
*: add test for misusing keyspace ID when creating the client #6754
Merged
Merged
Changes from all commits
Commits
Show all changes
2 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -24,3 +24,4 @@ report.xml | |
coverage.xml | ||
coverage | ||
*.txt | ||
go.work* |
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 |
---|---|---|
|
@@ -493,6 +493,7 @@ func TestTwiceSplitKeyspaceGroup(t *testing.T) { | |
ctx, cancel := context.WithCancel(context.Background()) | ||
defer cancel() | ||
re.NoError(failpoint.Enable("github.com/tikv/pd/pkg/keyspace/acceleratedAllocNodes", `return(true)`)) | ||
re.NoError(failpoint.Enable("github.com/tikv/pd/pkg/tso/fastGroupSplitPatroller", `return(true)`)) | ||
|
||
// Init api server config but not start. | ||
tc, err := tests.NewTestAPICluster(ctx, 1, func(conf *config.Config, _ string) { | ||
|
@@ -503,21 +504,6 @@ func TestTwiceSplitKeyspaceGroup(t *testing.T) { | |
re.NoError(err) | ||
pdAddr := tc.GetConfig().GetClientURL() | ||
|
||
// Start pd client and wait pd server start. | ||
var clients sync.Map | ||
go func() { | ||
apiCtx := pd.NewAPIContextV2("keyspace_b") // its keyspace id is 2. | ||
cli, err := pd.NewClientWithAPIContext(ctx, apiCtx, []string{pdAddr}, pd.SecurityOption{}) | ||
re.NoError(err) | ||
clients.Store("keyspace_b", cli) | ||
}() | ||
go func() { | ||
apiCtx := pd.NewAPIContextV2("keyspace_a") // its keyspace id is 1. | ||
cli, err := pd.NewClientWithAPIContext(ctx, apiCtx, []string{pdAddr}, pd.SecurityOption{}) | ||
re.NoError(err) | ||
clients.Store("keyspace_a", cli) | ||
}() | ||
|
||
// Start api server and tso server. | ||
err = tc.RunInitialServers() | ||
re.NoError(err) | ||
|
@@ -531,20 +517,6 @@ func TestTwiceSplitKeyspaceGroup(t *testing.T) { | |
defer tsoCluster.Destroy() | ||
tsoCluster.WaitForDefaultPrimaryServing(re) | ||
|
||
// Wait pd clients are ready. | ||
testutil.Eventually(re, func() bool { | ||
count := 0 | ||
clients.Range(func(_, _ interface{}) bool { | ||
count++ | ||
return true | ||
}) | ||
return count == 2 | ||
}) | ||
clientA, ok := clients.Load("keyspace_a") | ||
re.True(ok) | ||
clientB, ok := clients.Load("keyspace_b") | ||
re.True(ok) | ||
|
||
// First split keyspace group 0 to 1 with keyspace 2. | ||
kgm := leaderServer.GetServer().GetKeyspaceGroupManager() | ||
re.NotNil(kgm) | ||
|
@@ -553,27 +525,15 @@ func TestTwiceSplitKeyspaceGroup(t *testing.T) { | |
return err == nil | ||
}) | ||
|
||
// Trigger checkTSOSplit to ensure the split is finished. | ||
testutil.Eventually(re, func() bool { | ||
_, _, err = clientB.(pd.Client).GetTS(ctx) | ||
return err == nil | ||
}) | ||
waitFinishSplit(re, leaderServer, 0, 1, []uint32{mcsutils.DefaultKeyspaceID, 1}, []uint32{2}) | ||
clientB.(pd.Client).Close() | ||
|
||
// Then split keyspace group 0 to 2 with keyspace 1. | ||
testutil.Eventually(re, func() bool { | ||
err = kgm.SplitKeyspaceGroupByID(0, 2, []uint32{1}) | ||
return err == nil | ||
}) | ||
|
||
// Trigger checkTSOSplit to ensure the split is finished. | ||
testutil.Eventually(re, func() bool { | ||
_, _, err = clientA.(pd.Client).GetTS(ctx) | ||
return err == nil | ||
}) | ||
waitFinishSplit(re, leaderServer, 0, 2, []uint32{mcsutils.DefaultKeyspaceID}, []uint32{1}) | ||
clientA.(pd.Client).Close() | ||
|
||
// Check the keyspace group 0 is split to 1 and 2. | ||
kg0 := handlersutil.MustLoadKeyspaceGroupByID(re, leaderServer, 0) | ||
|
@@ -586,6 +546,7 @@ func TestTwiceSplitKeyspaceGroup(t *testing.T) { | |
re.False(kg1.IsSplitting()) | ||
re.False(kg2.IsSplitting()) | ||
|
||
re.NoError(failpoint.Disable("github.com/tikv/pd/pkg/tso/fastGroupSplitPatroller")) | ||
re.NoError(failpoint.Disable("github.com/tikv/pd/pkg/keyspace/acceleratedAllocNodes")) | ||
} | ||
|
||
|
@@ -724,3 +685,73 @@ func (suite *tsoKeyspaceGroupManagerTestSuite) TestTSOKeyspaceGroupMergeClient() | |
cancel() | ||
wg.Wait() | ||
} | ||
|
||
// See https://github.com/tikv/pd/issues/6748 | ||
func TestGetTSOImmediately(t *testing.T) { | ||
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. accurate |
||
re := require.New(t) | ||
ctx, cancel := context.WithCancel(context.Background()) | ||
defer cancel() | ||
re.NoError(failpoint.Enable("github.com/tikv/pd/pkg/tso/fastPrimaryPriorityCheck", `return(true)`)) | ||
re.NoError(failpoint.Enable("github.com/tikv/pd/pkg/keyspace/acceleratedAllocNodes", `return(true)`)) | ||
re.NoError(failpoint.Enable("github.com/tikv/pd/pkg/tso/fastGroupSplitPatroller", `return(true)`)) | ||
|
||
// Init api server config but not start. | ||
tc, err := tests.NewTestAPICluster(ctx, 1, func(conf *config.Config, _ string) { | ||
conf.Keyspace.PreAlloc = []string{ | ||
"keyspace_a", "keyspace_b", | ||
} | ||
}) | ||
re.NoError(err) | ||
pdAddr := tc.GetConfig().GetClientURL() | ||
|
||
// Start api server and tso server. | ||
err = tc.RunInitialServers() | ||
re.NoError(err) | ||
defer tc.Destroy() | ||
tc.WaitLeader() | ||
leaderServer := tc.GetServer(tc.GetLeader()) | ||
re.NoError(leaderServer.BootstrapCluster()) | ||
|
||
tsoCluster, err := mcs.NewTestTSOCluster(ctx, 2, pdAddr) | ||
re.NoError(err) | ||
defer tsoCluster.Destroy() | ||
tsoCluster.WaitForDefaultPrimaryServing(re) | ||
|
||
// First split keyspace group 0 to 1 with keyspace 2. | ||
kgm := leaderServer.GetServer().GetKeyspaceGroupManager() | ||
re.NotNil(kgm) | ||
testutil.Eventually(re, func() bool { | ||
err = kgm.SplitKeyspaceGroupByID(0, 1, []uint32{2}) | ||
return err == nil | ||
}) | ||
|
||
waitFinishSplit(re, leaderServer, 0, 1, []uint32{mcsutils.DefaultKeyspaceID, 1}, []uint32{2}) | ||
|
||
kg0 := handlersutil.MustLoadKeyspaceGroupByID(re, leaderServer, 0) | ||
kg1 := handlersutil.MustLoadKeyspaceGroupByID(re, leaderServer, 1) | ||
re.Equal([]uint32{0, 1}, kg0.Keyspaces) | ||
re.Equal([]uint32{2}, kg1.Keyspaces) | ||
re.False(kg0.IsSplitting()) | ||
re.False(kg1.IsSplitting()) | ||
|
||
// Let group 0 and group 1 have different primary node. | ||
kgm.SetPriorityForKeyspaceGroup(0, kg0.Members[0].Address, 100) | ||
kgm.SetPriorityForKeyspaceGroup(1, kg1.Members[1].Address, 100) | ||
testutil.Eventually(re, func() bool { | ||
p0, err := kgm.GetKeyspaceGroupPrimaryByID(0) | ||
re.NoError(err) | ||
p1, err := kgm.GetKeyspaceGroupPrimaryByID(1) | ||
re.NoError(err) | ||
return p0 == kg0.Members[0].Address && p1 == kg1.Members[1].Address | ||
}, testutil.WithWaitFor(5*time.Second), testutil.WithTickInterval(50*time.Millisecond)) | ||
|
||
apiCtx := pd.NewAPIContextV2("keyspace_b") // its keyspace id is 2. | ||
cli, err := pd.NewClientWithAPIContext(ctx, apiCtx, []string{pdAddr}, pd.SecurityOption{}) | ||
re.NoError(err) | ||
_, _, err = cli.GetTS(ctx) | ||
re.NoError(err) | ||
cli.Close() | ||
re.NoError(failpoint.Disable("github.com/tikv/pd/pkg/tso/fastPrimaryPriorityCheck")) | ||
re.NoError(failpoint.Disable("github.com/tikv/pd/pkg/keyspace/acceleratedAllocNodes")) | ||
re.NoError(failpoint.Disable("github.com/tikv/pd/pkg/tso/fastGroupSplitPatroller")) | ||
} |
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.
Do we need to move this part to
pkg/storage/endpoint/key_path.go
?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.
Yes, it waits for #6747 to do the changes.