Skip to content

Commit

Permalink
address comments
Browse files Browse the repository at this point in the history
Signed-off-by: lhy1024 <admin@liudos.us>
  • Loading branch information
lhy1024 committed May 9, 2023
1 parent 15513ba commit c8c9068
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 17 deletions.
36 changes: 20 additions & 16 deletions pkg/keyspace/keyspace.go
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ func (manager *Manager) CreateKeyspace(request *CreateKeyspaceRequest) (*keyspac
err = manager.saveNewKeyspace(keyspace)
if err != nil {
log.Warn("[keyspace] failed to create keyspace",
zap.Uint32("ID", keyspace.GetId()),
zap.Uint32("keyspace-id", keyspace.GetId()),
zap.String("name", keyspace.GetName()),
zap.Error(err),
)
Expand All @@ -228,7 +228,7 @@ func (manager *Manager) CreateKeyspace(request *CreateKeyspaceRequest) (*keyspac
return nil, err
}
log.Info("[keyspace] keyspace created",
zap.Uint32("ID", keyspace.GetId()),
zap.Uint32("keyspace-id", keyspace.GetId()),
zap.String("name", keyspace.GetName()),
)
return keyspace, nil
Expand Down Expand Up @@ -281,7 +281,7 @@ func (manager *Manager) splitKeyspaceRegion(id uint32, waitRegionSplit bool) (er
err = cl.GetRegionLabeler().SetLabelRule(keyspaceRule)
if err != nil {
log.Warn("[keyspace] failed to add region label for keyspace",
zap.Uint32("keyspaceID", id),
zap.Uint32("keyspace-id", id),
zap.Error(err),
)
return err
Expand All @@ -294,6 +294,10 @@ func (manager *Manager) splitKeyspaceRegion(id uint32, waitRegionSplit bool) (er

if waitRegionSplit {
ranges := keyspaceRule.Data.([]*labeler.KeyRangeRule)
if len(ranges) < 2 {
log.Warn("[keyspace] failed to split keyspace region with insufficient range", zap.Any("label-rule", keyspaceRule))
return ErrRegionSplitFailed
}
rawLeftBound, rawRightBound := ranges[0].StartKey, ranges[0].EndKey
txnLeftBound, txnRightBound := ranges[1].StartKey, ranges[1].EndKey

Expand Down Expand Up @@ -325,20 +329,20 @@ func (manager *Manager) splitKeyspaceRegion(id uint32, waitRegionSplit bool) (er
}
case <-timer.C:
log.Warn("[keyspace] wait region split timeout",
zap.Uint32("keyspaceID", id),
zap.Uint32("keyspace-id", id),
zap.Error(err),
)
err = ErrRegionSplitTimeout
return
}
log.Info("[keyspace] wait reigon split successfully", zap.Uint32("keyspaceID", id))
log.Info("[keyspace] wait region split successfully", zap.Uint32("keyspace-id", id))
break
}
}

log.Info("[keyspace] added region label for keyspace",
zap.Uint32("keyspaceID", id),
zap.Any("LabelRule", keyspaceRule),
zap.Uint32("keyspace-id", id),
zap.Any("label-rule", keyspaceRule),
zap.Duration("takes", time.Since(start)),
)
return
Expand Down Expand Up @@ -482,16 +486,16 @@ func (manager *Manager) UpdateKeyspaceConfig(name string, mutations []*Mutation)

if err != nil {
log.Warn("[keyspace] failed to update keyspace config",
zap.Uint32("ID", meta.GetId()),
zap.Uint32("keyspace-id", meta.GetId()),
zap.String("name", meta.GetName()),
zap.Error(err),
)
return nil, err
}
log.Info("[keyspace] keyspace config updated",
zap.Uint32("ID", meta.GetId()),
zap.Uint32("keyspace-id", meta.GetId()),
zap.String("name", meta.GetName()),
zap.Any("new config", meta.GetConfig()),
zap.Any("new-config", meta.GetConfig()),
)
return meta, nil
}
Expand Down Expand Up @@ -534,16 +538,16 @@ func (manager *Manager) UpdateKeyspaceState(name string, newState keyspacepb.Key
})
if err != nil {
log.Warn("[keyspace] failed to update keyspace config",
zap.Uint32("ID", meta.GetId()),
zap.Uint32("keyspace-id", meta.GetId()),
zap.String("name", meta.GetName()),
zap.Error(err),
)
return nil, err
}
log.Info("[keyspace] keyspace state updated",
zap.Uint32("ID", meta.GetId()),
zap.String("name", meta.GetName()),
zap.String("new state", newState.String()),
zap.String("keyspace-id", meta.GetName()),
zap.String("new-state", newState.String()),
)
return meta, nil
}
Expand Down Expand Up @@ -579,16 +583,16 @@ func (manager *Manager) UpdateKeyspaceStateByID(id uint32, newState keyspacepb.K
})
if err != nil {
log.Warn("[keyspace] failed to update keyspace config",
zap.Uint32("ID", meta.GetId()),
zap.Uint32("keyspace-id", meta.GetId()),
zap.String("name", meta.GetName()),
zap.Error(err),
)
return nil, err
}
log.Info("[keyspace] keyspace state updated",
zap.Uint32("ID", meta.GetId()),
zap.Uint32("keyspace-id", meta.GetId()),
zap.String("name", meta.GetName()),
zap.String("new state", newState.String()),
zap.String("new-state", newState.String()),
)
return meta, nil
}
Expand Down
2 changes: 2 additions & 0 deletions pkg/keyspace/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ var (
ErrKeyspaceNotFound = errors.New("keyspace does not exist")
// ErrRegionSplitTimeout indices to split region timeout
ErrRegionSplitTimeout = errors.New("region split timeout")
// ErrRegionSplitFailed indices to split region failed
ErrRegionSplitFailed = errors.New("region split failed")
// ErrKeyspaceExists indicates target keyspace already exists.
// It's used when creating a new keyspace.
ErrKeyspaceExists = errors.New("keyspace already exists")
Expand Down
2 changes: 1 addition & 1 deletion tests/integrations/mcs/tso/server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ func (suite *tsoServerTestSuite) TestTSOServerStartAndStopNormally() {
}
}

func (suite *tsoServerTestSuite) TestPariticipantStartWithAdvertiseListenAddr() {
func (suite *tsoServerTestSuite) TestParticipantStartWithAdvertiseListenAddr() {
re := suite.Require()

cfg := tso.NewConfig()
Expand Down

0 comments on commit c8c9068

Please sign in to comment.