Skip to content
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

tso: fix bugs to make split test case to pass #6389

Merged
merged 3 commits into from
Apr 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions pkg/tso/keyspace_group_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,8 +131,10 @@ func (s *state) getKeyspaceGroupMetaWithCheck(
// The keyspace doesn't belong to this keyspace group, we should check if it belongs to any other
// keyspace groups, and return the correct keyspace group meta to the client.
if kgid, ok := s.keyspaceLookupTable[keyspaceID]; ok {
return s.ams[kgid], s.kgs[kgid], kgid,
genNotServedErr(errs.ErrGetAllocatorManager, keyspaceGroupID)
if s.ams[kgid] != nil {
return s.ams[kgid], s.kgs[kgid], kgid, nil
}
return nil, s.kgs[kgid], kgid, genNotServedErr(errs.ErrGetAllocatorManager, keyspaceGroupID)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

when s.ams[kgid] is nil, can s.kgs[kgid] be nil at the same time?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no. s.kgs stores all keyspace groups; s.ams[kgid] only stores allocator managers of the keyspace groups assigned to this server/pod

}

// The keyspace doesn't belong to any keyspace group but the keyspace has been assigned to a
Expand Down Expand Up @@ -463,6 +465,7 @@ func (kgm *KeyspaceGroupManager) watchKeyspaceGroupsMetaChange(revision int64) (
defer watcher.Close()

ksgPrefix := strings.Join([]string{kgm.legacySvcRootPath, endpoint.KeyspaceGroupIDPrefix()}, "/")
log.Info("start to watch keyspace group meta change", zap.Int64("revision", revision), zap.String("prefix", ksgPrefix))

for {
watchChan := watcher.Watch(kgm.ctx, ksgPrefix, clientv3.WithPrefix(), clientv3.WithRev(revision))
Expand Down Expand Up @@ -840,7 +843,7 @@ func (kgm *KeyspaceGroupManager) HandleTSORequest(
return pdpb.Timestamp{}, curKeyspaceGroupID, err
}
ts, err = am.HandleRequest(dcLocation, count)
return ts, keyspaceGroupID, err
return ts, curKeyspaceGroupID, err
}

func (kgm *KeyspaceGroupManager) checkKeySpaceGroupID(id uint32) error {
Expand Down
19 changes: 9 additions & 10 deletions pkg/tso/keyspace_group_manager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -420,21 +420,20 @@ func (suite *keyspaceGroupManagerTestSuite) TestGetKeyspaceGroupMetaWithCheck()
re.Equal(uint32(0), kgid)
re.NotNil(am)
re.NotNil(kg)
// Should succeed and get the meta of keyspace group 0, because keyspace 0
// belongs to group 0, though the specified group 1 doesn't exist.
am, kg, kgid, err = mgr.getKeyspaceGroupMetaWithCheck(0, 1)
re.NoError(err)
re.Equal(uint32(0), kgid)
re.NotNil(am)
re.NotNil(kg)
// Should fail because keyspace 3 isn't explicitly assigned to any keyspace
// group, and the specified group isn't the default keyspace group.
am, kg, kgid, err = mgr.getKeyspaceGroupMetaWithCheck(3, 100)
re.Error(err)
re.Equal(uint32(100), kgid)
re.Nil(am)
re.Nil(kg)
// Should fail but still be able to get the meta of keyspace group 0,
// because keyspace 0 belongs to group 0, though the specified group 1
// doesn't exist.
am, kg, kgid, err = mgr.getKeyspaceGroupMetaWithCheck(0, 1)
re.Error(err)
re.Equal(uint32(0), kgid)
re.NotNil(am)
re.NotNil(kg)
}

// TestDefaultMembershipRestriction tests the restriction of default keyspace always
Expand Down Expand Up @@ -498,9 +497,9 @@ func (suite *keyspaceGroupManagerTestSuite) TestDefaultMembershipRestriction() {
re.Equal(mcsutils.DefaultKeyspaceGroupID, kgid)
re.NotNil(am)
re.NotNil(kg)
// Should fail but still be able to get the keyspace group meta from the default keyspace group
// Should succeed and return the keyspace group meta from the default keyspace group
am, kg, kgid, err = mgr.getKeyspaceGroupMetaWithCheck(mcsutils.DefaultKeyspaceID, 3)
re.Error(err)
re.NoError(err)
re.Equal(mcsutils.DefaultKeyspaceGroupID, kgid)
re.NotNil(am)
re.NotNil(kg)
Expand Down