Skip to content

Commit 9fdf362

Browse files
authored
autoid_service: add some debug log for rebase related operation (#46526) (#46530)
ref #46444
1 parent 5704f50 commit 9fdf362

File tree

1 file changed

+34
-1
lines changed

1 file changed

+34
-1
lines changed

autoid_service/autoid.go

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,7 @@ func (alloc *autoIDValue) rebase4Unsigned(ctx context.Context,
188188
}
189189

190190
var newBase, newEnd uint64
191+
var oldValue int64
191192
startTime := time.Now()
192193
ctx = kv.WithInternalSourceType(ctx, kv.InternalTxnMeta)
193194
err := kv.RunInNewTxn(ctx, store, true, func(ctx context.Context, txn kv.Transaction) error {
@@ -196,6 +197,7 @@ func (alloc *autoIDValue) rebase4Unsigned(ctx context.Context,
196197
if err1 != nil {
197198
return err1
198199
}
200+
oldValue = currentEnd
199201
uCurrentEnd := uint64(currentEnd)
200202
newBase = mathutil.Max(uCurrentEnd, requiredBase)
201203
newEnd = mathutil.Min(math.MaxUint64-uint64(batch), newBase) + uint64(batch)
@@ -206,6 +208,13 @@ func (alloc *autoIDValue) rebase4Unsigned(ctx context.Context,
206208
if err != nil {
207209
return err
208210
}
211+
212+
logutil.BgLogger().Info("rebase4Unsigned from",
213+
zap.String("category", "autoid service"),
214+
zap.Int64("dbID", dbID),
215+
zap.Int64("tblID", tblID),
216+
zap.Int64("from", oldValue),
217+
zap.Uint64("to", newEnd))
209218
alloc.base, alloc.end = int64(newBase), int64(newEnd)
210219
return nil
211220
}
@@ -221,22 +230,32 @@ func (alloc *autoIDValue) rebase4Signed(ctx context.Context, store kv.Storage, d
221230
return nil
222231
}
223232

224-
var newBase, newEnd int64
233+
var oldValue, newBase, newEnd int64
234+
startTime := time.Now()
225235
ctx = kv.WithInternalSourceType(ctx, kv.InternalTxnMeta)
226236
err := kv.RunInNewTxn(ctx, store, true, func(ctx context.Context, txn kv.Transaction) error {
227237
idAcc := meta.NewMeta(txn).GetAutoIDAccessors(dbID, tblID).IncrementID(model.TableInfoVersion5)
228238
currentEnd, err1 := idAcc.Get()
229239
if err1 != nil {
230240
return err1
231241
}
242+
oldValue = currentEnd
232243
newBase = mathutil.Max(currentEnd, requiredBase)
233244
newEnd = mathutil.Min(math.MaxInt64-batch, newBase) + batch
234245
_, err1 = idAcc.Inc(newEnd - currentEnd)
235246
return err1
236247
})
248+
metrics.AutoIDHistogram.WithLabelValues(metrics.TableAutoIDRebase, metrics.RetLabel(err)).Observe(time.Since(startTime).Seconds())
237249
if err != nil {
238250
return err
239251
}
252+
253+
logutil.BgLogger().Info("rebase4Signed from",
254+
zap.Int64("dbID", dbID),
255+
zap.Int64("tblID", tblID),
256+
zap.Int64("from", oldValue),
257+
zap.Int64("to", newEnd),
258+
zap.String("category", "autoid service"))
240259
alloc.base, alloc.end = newBase, newEnd
241260
return nil
242261
}
@@ -277,6 +296,11 @@ func New(selfAddr string, etcdAddr []string, store kv.Storage, tlsConfig *tls.Co
277296

278297
func newWithCli(selfAddr string, cli *clientv3.Client, store kv.Storage) *Service {
279298
l := owner.NewOwnerManager(context.Background(), cli, "autoid", selfAddr, autoIDLeaderPath)
299+
l.SetBeOwnerHook(func() {
300+
logutil.BgLogger().Info("leader change of autoid service, this node become owner",
301+
zap.String("addr", selfAddr),
302+
zap.String("category", "autoid service"))
303+
})
280304
// 10 means that autoid service's etcd lease is 10s.
281305
err := l.CampaignOwner(10)
282306
if err != nil {
@@ -471,12 +495,14 @@ func (s *Service) allocAutoID(ctx context.Context, req *autoid.AutoIDRequest) (*
471495

472496
func (alloc *autoIDValue) forceRebase(ctx context.Context, store kv.Storage, dbID, tblID, requiredBase int64, isUnsigned bool) error {
473497
ctx = kv.WithInternalSourceType(ctx, kv.InternalTxnMeta)
498+
var oldValue int64
474499
err := kv.RunInNewTxn(ctx, store, true, func(ctx context.Context, txn kv.Transaction) error {
475500
idAcc := meta.NewMeta(txn).GetAutoIDAccessors(dbID, tblID).IncrementID(model.TableInfoVersion5)
476501
currentEnd, err1 := idAcc.Get()
477502
if err1 != nil {
478503
return err1
479504
}
505+
oldValue = currentEnd
480506
var step int64
481507
if !isUnsigned {
482508
step = requiredBase - currentEnd
@@ -490,6 +516,13 @@ func (alloc *autoIDValue) forceRebase(ctx context.Context, store kv.Storage, dbI
490516
if err != nil {
491517
return err
492518
}
519+
logutil.BgLogger().Info("forceRebase from",
520+
zap.Int64("dbID", dbID),
521+
zap.Int64("tblID", tblID),
522+
zap.Int64("from", oldValue),
523+
zap.Int64("to", requiredBase),
524+
zap.Bool("isUnsigned", isUnsigned),
525+
zap.String("category", "autoid service"))
493526
alloc.base, alloc.end = requiredBase, requiredBase
494527
return nil
495528
}

0 commit comments

Comments
 (0)