Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

autoid_service: add some debug log for rebase related operation (#46526) #46531

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 34 additions & 1 deletion autoid_service/autoid.go
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,7 @@ func (alloc *autoIDValue) rebase4Unsigned(ctx context.Context,
}

var newBase, newEnd uint64
var oldValue int64
startTime := time.Now()
ctx = kv.WithInternalSourceType(ctx, kv.InternalTxnMeta)
err := kv.RunInNewTxn(ctx, store, true, func(ctx context.Context, txn kv.Transaction) error {
Expand All @@ -195,6 +196,7 @@ func (alloc *autoIDValue) rebase4Unsigned(ctx context.Context,
if err1 != nil {
return err1
}
oldValue = currentEnd
uCurrentEnd := uint64(currentEnd)
newBase = mathutil.Max(uCurrentEnd, requiredBase)
newEnd = mathutil.Min(math.MaxUint64-uint64(batch), newBase) + uint64(batch)
Expand All @@ -205,6 +207,13 @@ func (alloc *autoIDValue) rebase4Unsigned(ctx context.Context,
if err != nil {
return err
}

logutil.BgLogger().Info("rebase4Unsigned from",
zap.String("category", "autoid service"),
zap.Int64("dbID", dbID),
zap.Int64("tblID", tblID),
zap.Int64("from", oldValue),
zap.Uint64("to", newEnd))
alloc.base, alloc.end = int64(newBase), int64(newEnd)
return nil
}
Expand All @@ -220,22 +229,32 @@ func (alloc *autoIDValue) rebase4Signed(ctx context.Context, store kv.Storage, d
return nil
}

var newBase, newEnd int64
var oldValue, newBase, newEnd int64
startTime := time.Now()
ctx = kv.WithInternalSourceType(ctx, kv.InternalTxnMeta)
err := kv.RunInNewTxn(ctx, store, true, func(ctx context.Context, txn kv.Transaction) error {
idAcc := meta.NewMeta(txn).GetAutoIDAccessors(dbID, tblID).IncrementID(model.TableInfoVersion5)
currentEnd, err1 := idAcc.Get()
if err1 != nil {
return err1
}
oldValue = currentEnd
newBase = mathutil.Max(currentEnd, requiredBase)
newEnd = mathutil.Min(math.MaxInt64-batch, newBase) + batch
_, err1 = idAcc.Inc(newEnd - currentEnd)
return err1
})
metrics.AutoIDHistogram.WithLabelValues(metrics.TableAutoIDRebase, metrics.RetLabel(err)).Observe(time.Since(startTime).Seconds())
if err != nil {
return err
}

logutil.BgLogger().Info("rebase4Signed from",
zap.Int64("dbID", dbID),
zap.Int64("tblID", tblID),
zap.Int64("from", oldValue),
zap.Int64("to", newEnd),
zap.String("category", "autoid service"))
alloc.base, alloc.end = newBase, newEnd
return nil
}
Expand Down Expand Up @@ -272,6 +291,11 @@ func New(selfAddr string, etcdAddr []string, store kv.Storage, tlsConfig *tls.Co
}

l := owner.NewOwnerManager(context.Background(), cli, "autoid", selfAddr, autoIDLeaderPath)
l.SetBeOwnerHook(func() {
logutil.BgLogger().Info("leader change of autoid service, this node become owner",
zap.String("addr", selfAddr),
zap.String("category", "autoid service"))
})
err = l.CampaignOwner()
if err != nil {
panic(err)
Expand Down Expand Up @@ -465,12 +489,14 @@ func (s *Service) allocAutoID(ctx context.Context, req *autoid.AutoIDRequest) (*

func (alloc *autoIDValue) forceRebase(ctx context.Context, store kv.Storage, dbID, tblID, requiredBase int64, isUnsigned bool) error {
ctx = kv.WithInternalSourceType(ctx, kv.InternalTxnMeta)
var oldValue int64
err := kv.RunInNewTxn(ctx, store, true, func(ctx context.Context, txn kv.Transaction) error {
idAcc := meta.NewMeta(txn).GetAutoIDAccessors(dbID, tblID).IncrementID(model.TableInfoVersion5)
currentEnd, err1 := idAcc.Get()
if err1 != nil {
return err1
}
oldValue = currentEnd
var step int64
if !isUnsigned {
step = requiredBase - currentEnd
Expand All @@ -484,6 +510,13 @@ func (alloc *autoIDValue) forceRebase(ctx context.Context, store kv.Storage, dbI
if err != nil {
return err
}
logutil.BgLogger().Info("forceRebase from",
zap.Int64("dbID", dbID),
zap.Int64("tblID", tblID),
zap.Int64("from", oldValue),
zap.Int64("to", requiredBase),
zap.Bool("isUnsigned", isUnsigned),
zap.String("category", "autoid service"))
alloc.base, alloc.end = requiredBase, requiredBase
return nil
}
Expand Down