Skip to content

Commit

Permalink
Add split-from field for endpoint.KeyspaceGroup
Browse files Browse the repository at this point in the history
Signed-off-by: JmPotato <[email protected]>
  • Loading branch information
JmPotato committed Apr 12, 2023
1 parent 3e6ac89 commit 28245f1
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 1 deletion.
4 changes: 3 additions & 1 deletion pkg/keyspace/tso_keyspace_group.go
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,7 @@ func (m *GroupManager) saveKeyspaceGroups(keyspaceGroups []*endpoint.KeyspaceGro
Members: keyspaceGroup.Members,
Keyspaces: keyspaceGroup.Keyspaces,
InSplit: keyspaceGroup.InSplit,
SplitFrom: keyspaceGroup.SplitFrom,
})
}
return nil
Expand Down Expand Up @@ -339,7 +340,8 @@ func (m *GroupManager) SplitKeyspaceGroupByID(id, newID uint32, keyspaces []uint
Members: oldKg.Members,
Keyspaces: keyspaces,
// Only set the new keyspace group in split state.
InSplit: true,
InSplit: true,
SplitFrom: oldKg.ID,
})
})
}
Expand Down
3 changes: 3 additions & 0 deletions pkg/keyspace/tso_keyspace_group_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -254,11 +254,13 @@ func (suite *keyspaceGroupTestSuite) TestKeyspaceGroupSplit() {
re.Equal(uint32(2), kg2.ID)
re.Equal([]uint32{111, 222}, kg2.Keyspaces)
re.False(kg2.InSplit)
re.Empty(kg2.SplitFrom)
kg4, err := suite.kgm.GetKeyspaceGroupByID(4)
re.NoError(err)
re.Equal(uint32(4), kg4.ID)
re.Equal([]uint32{333}, kg4.Keyspaces)
re.True(kg4.InSplit)
re.Equal(kg2.ID, kg4.SplitFrom)
re.Equal(kg2.UserKind, kg4.UserKind)
re.Equal(kg2.Members, kg4.Members)
// finish the split of keyspace group 4
Expand All @@ -268,6 +270,7 @@ func (suite *keyspaceGroupTestSuite) TestKeyspaceGroupSplit() {
re.NoError(err)
re.Equal(uint32(4), kg4.ID)
re.False(kg4.InSplit)
re.Equal(kg2.ID, kg4.SplitFrom)
// split a non-existing keyspace group
err = suite.kgm.SplitKeyspaceGroupByID(3, 5, nil)
re.ErrorIs(err, ErrKeyspaceGroupNotFound)
Expand Down
2 changes: 2 additions & 0 deletions pkg/storage/endpoint/tso_keyspace_group.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,8 @@ type KeyspaceGroup struct {
UserKind string `json:"user-kind"`
// InSplit indicates whether the keyspace group is in split.
InSplit bool `json:"in-split"`
// SplitFrom is the keyspace group ID which the keyspace group is split from.
SplitFrom uint32 `json:"split-from"`
// Members are the election members which campaign for the primary of the keyspace group.
Members []KeyspaceGroupMember `json:"members"`
// Keyspaces are the keyspace IDs which belong to the keyspace group.
Expand Down
3 changes: 3 additions & 0 deletions tests/server/apiv2/handlers/tso_keyspace_group_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,18 +118,21 @@ func (suite *keyspaceGroupTestSuite) TestSplitKeyspaceGroup() {
re.Equal(uint32(1), kg1.ID)
re.Equal([]uint32{333}, kg1.Keyspaces)
re.False(kg1.InSplit)
re.Empty(kg1.SplitFrom)
// Check keyspace group 2.
kg2 := mustLoadKeyspaceGroupByID(re, suite.server, 2)
re.Equal(uint32(2), kg2.ID)
re.Equal([]uint32{111, 222}, kg2.Keyspaces)
re.True(kg2.InSplit)
re.Equal(kg1.ID, kg2.SplitFrom)
// They should have the same user kind and members.
re.Equal(kg1.UserKind, kg2.UserKind)
re.Equal(kg1.Members, kg2.Members)
// Finish the split and check the split state.
mustFinishSplitKeyspaceGroup(re, suite.server, 2)
kg2 = mustLoadKeyspaceGroupByID(re, suite.server, 2)
re.False(kg2.InSplit)
re.Equal(kg1.ID, kg2.SplitFrom)
}

func sendLoadKeyspaceGroupRequest(re *require.Assertions, server *tests.TestServer, token, limit string) []*endpoint.KeyspaceGroup {
Expand Down

0 comments on commit 28245f1

Please sign in to comment.