Skip to content

Commit

Permalink
Add test
Browse files Browse the repository at this point in the history
Signed-off-by: Bin Shi <binshi.bing@gmail.com>
  • Loading branch information
binshi-bing committed Apr 25, 2023
1 parent a0eb272 commit 53bf68e
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 3 deletions.
7 changes: 4 additions & 3 deletions pkg/tso/keyspace_group_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,13 +130,14 @@ func (s *state) getAMWithMembershipCheck(
return nil, kgid, genNotServedErr(errs.ErrGetAllocatorManager, keyspaceGroupID)
}

// The keyspace doesn't belong to any keyspace group but the keyspace has been assigned to a
// keyspace group before, which means the keyspace group hasn't initialized yet.
if keyspaceGroupID != mcsutils.DefaultKeyspaceGroupID {
return nil, keyspaceGroupID, errs.ErrKeyspaceNotAssigned.FastGenByArgs(keyspaceID)
}

// The keyspace doesn't belong to any keyspace group, so return the default keyspace group.
// It's for migrating the existing keyspaces which have no keyspace group assigned, so the
// the default keyspace group is used to serve the keyspaces.
// For migrating the existing keyspaces which have no keyspace group assigned as configured in the
// keyspace meta. All these keyspaces will be served by the default keyspace group.
if s.ams[mcsutils.DefaultKeyspaceGroupID] == nil {
return nil, mcsutils.DefaultKeyspaceGroupID, errs.ErrKeyspaceNotAssigned.FastGenByArgs(keyspaceID)
}
Expand Down
42 changes: 42 additions & 0 deletions tests/integrations/mcs/tso/keyspace_group_manager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import (
pd "github.com/tikv/pd/client"
"github.com/tikv/pd/client/testutil"
"github.com/tikv/pd/pkg/election"
mcsutils "github.com/tikv/pd/pkg/mcs/utils"
"github.com/tikv/pd/pkg/member"
"github.com/tikv/pd/pkg/storage/endpoint"
tsopkg "github.com/tikv/pd/pkg/tso"
Expand Down Expand Up @@ -86,6 +87,47 @@ func cleanupKeyspaceGroups(re *require.Assertions, server *tests.TestServer) {
}
}

func (suite *tsoKeyspaceGroupManagerTestSuite) TestKeyspacesServedByDefaultKeyspaceGroup() {
// There is only default keyspace group. All keyspaces which have not been assigned to
// any keyspace group will be served by the default keyspace group; otherwise,
// they won't be served by any keyspace group.
re := suite.Require()
testutil.Eventually(re, func() bool {
for _, server := range suite.tsoCluster.GetServers() {
allServed := true
for _, keyspaceID := range []uint32{0, 1, 2} {
if server.IsKeyspaceServing(keyspaceID, mcsutils.DefaultKeyspaceGroupID) {
tam, err := server.GetTSOAllocatorManager(mcsutils.DefaultKeyspaceGroupID)
re.NoError(err)
re.NotNil(tam)
} else {
allServed = false
}
}
return allServed
}
return false
}, testutil.WithWaitFor(5*time.Second), testutil.WithTickInterval(50*time.Millisecond))

// All keyspaces which have been assigned to any keyspace group before, except default
// keyspace, won't be served at this time. Default keyspace will be served by default
// keyspace group all the time.
for _, server := range suite.tsoCluster.GetServers() {
server.IsKeyspaceServing(mcsutils.DefaultKeyspaceID, mcsutils.DefaultKeyspaceGroupID)
for _, keyspaceGroupID := range []uint32{1, 2, 3} {
server.IsKeyspaceServing(mcsutils.DefaultKeyspaceID, keyspaceGroupID)
server.IsKeyspaceServing(mcsutils.DefaultKeyspaceID, keyspaceGroupID)
for _, keyspaceID := range []uint32{1, 2, 3} {
if server.IsKeyspaceServing(keyspaceID, keyspaceGroupID) {
tam, err := server.GetTSOAllocatorManager(keyspaceGroupID)
re.NoError(err)
re.NotNil(tam)
}
}
}
}
}

func (suite *tsoKeyspaceGroupManagerTestSuite) TestTSOKeyspaceGroupSplit() {
re := suite.Require()
// Create the keyspace group 1 with keyspaces [111, 222, 333].
Expand Down

0 comments on commit 53bf68e

Please sign in to comment.