Skip to content

Commit d9a4852

Browse files
committed
add comment
Signed-off-by: tongjian <1045931706@qq.com>
1 parent fb0182c commit d9a4852

File tree

2 files changed

+18
-12
lines changed

2 files changed

+18
-12
lines changed

pkg/keyspace/keyspace.go

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,8 @@ type Config interface {
8080
ToWaitRegionSplit() bool
8181
GetWaitRegionSplitTimeout() time.Duration
8282
GetCheckRegionSplitInterval() time.Duration
83+
// GetMetaServiceGroups returns the meta-service groups for keyspace assignment.
84+
// key is the meta-service group id and value is the meta-service group addresses.
8385
SetMetaServiceGroups(map[string]string)
8486
GetMetaServiceGroups() map[string]string
8587
}
@@ -269,6 +271,19 @@ func (manager *Manager) CreateKeyspace(request *CreateKeyspaceRequest) (*keyspac
269271
tracer.SetKeyspace(newID, request.Name)
270272
tracer.OnAllocateIDFinished()
271273

274+
// assign meta-service group for the new keyspace if meta-service groups exist.
275+
assignToMetaServiceGroup := manager.mgm != nil && len(manager.mgm.GetGroups()) > 0
276+
if assignToMetaServiceGroup {
277+
metaServiceGroup, err := manager.mgm.AssignToGroup(1)
278+
if err != nil {
279+
return nil, err
280+
}
281+
if request.Config == nil {
282+
request.Config = make(map[string]string)
283+
}
284+
request.Config[MetaServiceGroupIDKey] = metaServiceGroup
285+
}
286+
272287
// Get keyspace config.
273288
userKind := endpoint.StringUserKind(request.Config[UserKindKey])
274289
config, err := manager.kgm.GetKeyspaceConfigByKind(userKind)
@@ -283,17 +298,7 @@ func (manager *Manager) CreateKeyspace(request *CreateKeyspaceRequest) (*keyspac
283298
request.Config[UserKindKey] = config[UserKindKey]
284299
}
285300
}
286-
assignToMetaServiceGroup := manager.mgm != nil && len(manager.mgm.GetGroups()) > 0
287-
if assignToMetaServiceGroup {
288-
metaServiceGroup, err := manager.mgm.AssignToGroup(1)
289-
if err != nil {
290-
return nil, err
291-
}
292-
if request.Config == nil {
293-
request.Config = make(map[string]string)
294-
}
295-
request.Config[MetaServiceGroupIDKey] = metaServiceGroup
296-
}
301+
297302
// Set default value of GCManagementType to KeyspaceLevelGC for NextGen
298303
if kerneltype.IsNextGen() {
299304
if request.Config == nil {

pkg/keyspace/keyspace_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,8 @@ type mockConfig struct {
6868
WaitRegionSplit bool
6969
WaitRegionSplitTimeout typeutil.Duration
7070
CheckRegionSplitInterval typeutil.Duration
71-
MetaServiceGroups map[string]string
71+
// MetaServiceGroups is used to mock the meta-service groups for keyspace assignment.
72+
MetaServiceGroups map[string]string
7273
}
7374

7475
func (m *mockConfig) GetPreAlloc() []string {

0 commit comments

Comments
 (0)