@@ -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 {
0 commit comments