@@ -105,8 +105,6 @@ type CreateKeyspaceRequest struct {
105105 Config map [string ]string
106106 // CreateTime is the timestamp used to record creation time.
107107 CreateTime int64
108- // IsPreAlloc indicates whether the keyspace is pre-allocated when the cluster starts.
109- IsPreAlloc bool
110108}
111109
112110// NewKeyspaceManager creates a Manager of keyspace related data.
@@ -167,24 +165,28 @@ func (manager *Manager) Bootstrap() error {
167165 // Initialize pre-alloc keyspace.
168166 preAlloc := manager .config .GetPreAlloc ()
169167 for _ , keyspaceName := range preAlloc {
170- config , err := manager .kgm .GetKeyspaceConfigByKind (endpoint .Basic )
171- if err != nil {
172- return err
173- }
174- req := & CreateKeyspaceRequest {
175- Name : keyspaceName ,
176- CreateTime : now ,
177- IsPreAlloc : true ,
178- Config : config ,
179- }
180- keyspace , err := manager .CreateKeyspace (req )
181- // Ignore the keyspaceExists error for the same reason as saving default keyspace.
182- if err != nil && err != errs .ErrKeyspaceExists {
183- return err
184- }
185- if err := manager .kgm .UpdateKeyspaceForGroup (endpoint .Basic , config [TSOKeyspaceGroupIDKey ], keyspace .GetId (), opAdd ); err != nil {
186- return err
187- }
168+ go func () {
169+ config , err := manager .kgm .GetKeyspaceConfigByKind (endpoint .Basic )
170+ if err != nil {
171+ log .Error ("[keyspace] failed to get keyspace config for pre-alloc keyspace" , zap .String ("keyspaceName" , keyspaceName ), zap .Error (err ))
172+ return
173+ }
174+ req := & CreateKeyspaceRequest {
175+ Name : keyspaceName ,
176+ CreateTime : now ,
177+ Config : config ,
178+ }
179+ keyspace , err := manager .CreateKeyspace (req )
180+ // Ignore the keyspaceExists error for the same reason as saving default keyspace.
181+ if err != nil && err != errs .ErrKeyspaceExists {
182+ log .Error ("[keyspace] failed to create pre-alloc keyspace" , zap .String ("keyspaceName" , keyspaceName ), zap .Error (err ))
183+ return
184+ }
185+ if err := manager .kgm .UpdateKeyspaceForGroup (endpoint .Basic , config [TSOKeyspaceGroupIDKey ], keyspace .GetId (), opAdd ); err != nil {
186+ log .Error ("[keyspace] failed to update pre-alloc keyspace for group" , zap .String ("keyspaceName" , keyspaceName ), zap .Error (err ))
187+ return
188+ }
189+ }()
188190 }
189191 return nil
190192}
@@ -236,11 +238,8 @@ func (manager *Manager) CreateKeyspace(request *CreateKeyspaceRequest) (*keyspac
236238 )
237239 return nil , err
238240 }
239- // If the request to create a keyspace is pre-allocated when the PD starts,
240- // there is no need to wait for the region split, because TiKV has not started.
241- waitRegionSplit := ! request .IsPreAlloc && manager .config .ToWaitRegionSplit ()
242241 // Split keyspace region.
243- err = manager .splitKeyspaceRegion (newID , waitRegionSplit )
242+ err = manager .splitKeyspaceRegion (newID , manager . config . ToWaitRegionSplit () )
244243 if err != nil {
245244 err2 := manager .store .RunInTxn (manager .ctx , func (txn kv.Txn ) error {
246245 idPath := keypath .KeyspaceIDPath (request .Name )
@@ -535,7 +534,6 @@ func (manager *Manager) UpdateKeyspaceConfig(name string, mutations []*Mutation)
535534 }
536535 return nil
537536 })
538-
539537 if err != nil {
540538 log .Warn ("[keyspace] failed to update keyspace config" ,
541539 zap .Uint32 ("keyspace-id" , meta .GetId ()),
0 commit comments