-
Notifications
You must be signed in to change notification settings - Fork 2.1k
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
VTGate Buffering: Use a more accurate heuristic for determining if we're doing a reshard #13856
Merged
Merged
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
555a5e8
Use a more accurate heuristic for determining if we're doing a reshard
mattlord a2e5577
Add unit tests
mattlord a14ed98
Import nits
mattlord 16f2a5e
Prevent data race
mattlord 712b337
Sync test names with function names
mattlord 9fd0646
Be sure not to leak HC resources
mattlord 748c425
Minor comment improvements
mattlord 6161737
Merge remote-tracking branch 'origin/main' into reshard_buffering_fix
mattlord 9edd1d6
Minor comment tweaks pt 2
mattlord 194debf
Consolidate the two unit tests
mattlord 9d53d46
Add a couple more test cases`
mattlord dcaf5a0
Minor tweaks after FINAL self review :-D
mattlord 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -24,10 +24,12 @@ import ( | |
|
||
"github.com/stretchr/testify/require" | ||
|
||
topodatapb "vitess.io/vitess/go/vt/proto/topodata" | ||
vschemapb "vitess.io/vitess/go/vt/proto/vschema" | ||
"vitess.io/vitess/go/vt/topo" | ||
"vitess.io/vitess/go/vt/topo/faketopo" | ||
|
||
querypb "vitess.io/vitess/go/vt/proto/query" | ||
topodatapb "vitess.io/vitess/go/vt/proto/topodata" | ||
vschemapb "vitess.io/vitess/go/vt/proto/vschema" | ||
) | ||
|
||
func TestSrvKeyspaceWithNilNewKeyspace(t *testing.T) { | ||
|
@@ -38,6 +40,7 @@ func TestSrvKeyspaceWithNilNewKeyspace(t *testing.T) { | |
ts := faketopo.NewFakeTopoServer(factory) | ||
ts2 := &fakeTopoServer{} | ||
hc := NewHealthCheck(context.Background(), 1*time.Millisecond, time.Hour, ts, cell, "") | ||
defer hc.Close() | ||
kew := NewKeyspaceEventWatcher(context.Background(), ts2, hc, cell) | ||
kss := &keyspaceState{ | ||
kew: kew, | ||
|
@@ -55,6 +58,220 @@ func TestSrvKeyspaceWithNilNewKeyspace(t *testing.T) { | |
require.True(t, kss.onSrvKeyspace(nil, nil)) | ||
} | ||
|
||
// TestKeyspaceEventTypes confirms that the keyspace event watcher determines | ||
// that the unavailability event is caused by the correct scenario. We should | ||
// consider it to be caused by a resharding operation when the following | ||
// conditions are present: | ||
// 1. The keyspace is inconsistent (in the middle of an availability event) | ||
// 2. The target tablet is a primary | ||
// 3. The keyspace has overlapping shards | ||
// 4. The overlapping shard's tablet is serving | ||
// And we should consider the cause to be a primary not serving when the | ||
// following conditions exist: | ||
// 1. The keyspace is inconsistent (in the middle of an availability event) | ||
// 2. The target tablet is a primary | ||
// 3. The target tablet is not serving | ||
// 4. The shard's externallyReparented time is not 0 | ||
// 5. The shard's currentPrimary state is not nil | ||
// We should never consider both as a possible cause given the same | ||
// keyspace state. | ||
func TestKeyspaceEventTypes(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. ❤️ 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. Nice test description 💯 |
||
cell := "cell" | ||
keyspace := "testks" | ||
factory := faketopo.NewFakeTopoFactory() | ||
factory.AddCell(cell) | ||
ts := faketopo.NewFakeTopoServer(factory) | ||
ts2 := &fakeTopoServer{} | ||
hc := NewHealthCheck(context.Background(), 1*time.Millisecond, time.Hour, ts, cell, "") | ||
defer hc.Close() | ||
kew := NewKeyspaceEventWatcher(context.Background(), ts2, hc, cell) | ||
|
||
type testCase struct { | ||
name string | ||
kss *keyspaceState | ||
shardToCheck string | ||
expectResharding bool | ||
expectPrimaryNotServing bool | ||
} | ||
|
||
testCases := []testCase{ | ||
{ | ||
name: "one to two resharding in progress", | ||
kss: &keyspaceState{ | ||
kew: kew, | ||
keyspace: keyspace, | ||
shards: map[string]*shardState{ | ||
"-": { | ||
target: &querypb.Target{ | ||
Keyspace: keyspace, | ||
Shard: "-", | ||
TabletType: topodatapb.TabletType_PRIMARY, | ||
}, | ||
serving: false, | ||
}, | ||
"-80": { | ||
target: &querypb.Target{ | ||
Keyspace: keyspace, | ||
Shard: "-80", | ||
TabletType: topodatapb.TabletType_PRIMARY, | ||
}, | ||
serving: true, | ||
}, | ||
"80-": { | ||
target: &querypb.Target{ | ||
Keyspace: keyspace, | ||
Shard: "80-", | ||
TabletType: topodatapb.TabletType_PRIMARY, | ||
}, | ||
serving: false, | ||
}, | ||
}, | ||
consistent: false, | ||
}, | ||
shardToCheck: "-", | ||
expectResharding: true, | ||
expectPrimaryNotServing: false, | ||
}, | ||
{ | ||
name: "two to four resharding in progress", | ||
kss: &keyspaceState{ | ||
kew: kew, | ||
keyspace: keyspace, | ||
shards: map[string]*shardState{ | ||
"-80": { | ||
target: &querypb.Target{ | ||
Keyspace: keyspace, | ||
Shard: "-80", | ||
TabletType: topodatapb.TabletType_PRIMARY, | ||
}, | ||
serving: false, | ||
}, | ||
"80-": { | ||
target: &querypb.Target{ | ||
Keyspace: keyspace, | ||
Shard: "80-", | ||
TabletType: topodatapb.TabletType_PRIMARY, | ||
}, | ||
serving: true, | ||
}, | ||
"-40": { | ||
target: &querypb.Target{ | ||
Keyspace: keyspace, | ||
Shard: "-40", | ||
TabletType: topodatapb.TabletType_PRIMARY, | ||
}, | ||
serving: true, | ||
}, | ||
"40-80": { | ||
target: &querypb.Target{ | ||
Keyspace: keyspace, | ||
Shard: "40-80", | ||
TabletType: topodatapb.TabletType_PRIMARY, | ||
}, | ||
serving: true, | ||
}, | ||
"80-c0": { | ||
target: &querypb.Target{ | ||
Keyspace: keyspace, | ||
Shard: "80-c0", | ||
TabletType: topodatapb.TabletType_PRIMARY, | ||
}, | ||
serving: false, | ||
}, | ||
"c0-": { | ||
target: &querypb.Target{ | ||
Keyspace: keyspace, | ||
Shard: "c0-", | ||
TabletType: topodatapb.TabletType_PRIMARY, | ||
}, | ||
serving: false, | ||
}, | ||
}, | ||
consistent: false, | ||
}, | ||
shardToCheck: "-80", | ||
expectResharding: true, | ||
expectPrimaryNotServing: false, | ||
}, | ||
{ | ||
name: "unsharded primary not serving", | ||
kss: &keyspaceState{ | ||
kew: kew, | ||
keyspace: keyspace, | ||
shards: map[string]*shardState{ | ||
"-": { | ||
target: &querypb.Target{ | ||
Keyspace: keyspace, | ||
Shard: "-", | ||
TabletType: topodatapb.TabletType_PRIMARY, | ||
}, | ||
serving: false, | ||
externallyReparented: time.Now().UnixNano(), | ||
currentPrimary: &topodatapb.TabletAlias{ | ||
Cell: cell, | ||
Uid: 100, | ||
}, | ||
}, | ||
}, | ||
consistent: false, | ||
}, | ||
shardToCheck: "-", | ||
expectResharding: false, | ||
expectPrimaryNotServing: true, | ||
}, | ||
{ | ||
name: "sharded primary not serving", | ||
kss: &keyspaceState{ | ||
kew: kew, | ||
keyspace: keyspace, | ||
shards: map[string]*shardState{ | ||
"-80": { | ||
target: &querypb.Target{ | ||
Keyspace: keyspace, | ||
Shard: "-80", | ||
TabletType: topodatapb.TabletType_PRIMARY, | ||
}, | ||
serving: false, | ||
externallyReparented: time.Now().UnixNano(), | ||
currentPrimary: &topodatapb.TabletAlias{ | ||
Cell: cell, | ||
Uid: 100, | ||
}, | ||
}, | ||
"80-": { | ||
target: &querypb.Target{ | ||
Keyspace: keyspace, | ||
Shard: "80-", | ||
TabletType: topodatapb.TabletType_PRIMARY, | ||
}, | ||
serving: true, | ||
}, | ||
}, | ||
consistent: false, | ||
}, | ||
shardToCheck: "-80", | ||
expectResharding: false, | ||
expectPrimaryNotServing: true, | ||
}, | ||
} | ||
|
||
for _, tc := range testCases { | ||
t.Run(tc.name, func(t *testing.T) { | ||
kew.mu.Lock() | ||
kew.keyspaces[keyspace] = tc.kss | ||
kew.mu.Unlock() | ||
|
||
require.NotNil(t, tc.kss.shards[tc.shardToCheck], "the specified shardToCheck of %q does not exist in the shardState", tc.shardToCheck) | ||
|
||
resharding := kew.TargetIsBeingResharded(tc.kss.shards[tc.shardToCheck].target) | ||
require.Equal(t, resharding, tc.expectResharding, "TargetIsBeingResharded should return %t", tc.expectResharding) | ||
|
||
_, primaryDown := kew.PrimaryIsNotServing(tc.kss.shards[tc.shardToCheck].target) | ||
require.Equal(t, primaryDown, tc.expectPrimaryNotServing, "PrimaryIsNotServing should return %t", tc.expectPrimaryNotServing) | ||
}) | ||
} | ||
} | ||
|
||
type fakeTopoServer struct { | ||
} | ||
|
||
|
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 merely makes it easier for users to test buffering related behavior in the local examples moving forward.