@@ -188,6 +188,7 @@ func (alloc *autoIDValue) rebase4Unsigned(ctx context.Context,
188
188
}
189
189
190
190
var newBase , newEnd uint64
191
+ var oldValue int64
191
192
startTime := time .Now ()
192
193
ctx = kv .WithInternalSourceType (ctx , kv .InternalTxnMeta )
193
194
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,
196
197
if err1 != nil {
197
198
return err1
198
199
}
200
+ oldValue = currentEnd
199
201
uCurrentEnd := uint64 (currentEnd )
200
202
newBase = mathutil .Max (uCurrentEnd , requiredBase )
201
203
newEnd = mathutil .Min (math .MaxUint64 - uint64 (batch ), newBase ) + uint64 (batch )
@@ -206,6 +208,13 @@ func (alloc *autoIDValue) rebase4Unsigned(ctx context.Context,
206
208
if err != nil {
207
209
return err
208
210
}
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 ))
209
218
alloc .base , alloc .end = int64 (newBase ), int64 (newEnd )
210
219
return nil
211
220
}
@@ -221,22 +230,32 @@ func (alloc *autoIDValue) rebase4Signed(ctx context.Context, store kv.Storage, d
221
230
return nil
222
231
}
223
232
224
- var newBase , newEnd int64
233
+ var oldValue , newBase , newEnd int64
234
+ startTime := time .Now ()
225
235
ctx = kv .WithInternalSourceType (ctx , kv .InternalTxnMeta )
226
236
err := kv .RunInNewTxn (ctx , store , true , func (ctx context.Context , txn kv.Transaction ) error {
227
237
idAcc := meta .NewMeta (txn ).GetAutoIDAccessors (dbID , tblID ).IncrementID (model .TableInfoVersion5 )
228
238
currentEnd , err1 := idAcc .Get ()
229
239
if err1 != nil {
230
240
return err1
231
241
}
242
+ oldValue = currentEnd
232
243
newBase = mathutil .Max (currentEnd , requiredBase )
233
244
newEnd = mathutil .Min (math .MaxInt64 - batch , newBase ) + batch
234
245
_ , err1 = idAcc .Inc (newEnd - currentEnd )
235
246
return err1
236
247
})
248
+ metrics .AutoIDHistogram .WithLabelValues (metrics .TableAutoIDRebase , metrics .RetLabel (err )).Observe (time .Since (startTime ).Seconds ())
237
249
if err != nil {
238
250
return err
239
251
}
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" ))
240
259
alloc .base , alloc .end = newBase , newEnd
241
260
return nil
242
261
}
@@ -277,6 +296,11 @@ func New(selfAddr string, etcdAddr []string, store kv.Storage, tlsConfig *tls.Co
277
296
278
297
func newWithCli (selfAddr string , cli * clientv3.Client , store kv.Storage ) * Service {
279
298
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
+ })
280
304
// 10 means that autoid service's etcd lease is 10s.
281
305
err := l .CampaignOwner (10 )
282
306
if err != nil {
@@ -471,12 +495,14 @@ func (s *Service) allocAutoID(ctx context.Context, req *autoid.AutoIDRequest) (*
471
495
472
496
func (alloc * autoIDValue ) forceRebase (ctx context.Context , store kv.Storage , dbID , tblID , requiredBase int64 , isUnsigned bool ) error {
473
497
ctx = kv .WithInternalSourceType (ctx , kv .InternalTxnMeta )
498
+ var oldValue int64
474
499
err := kv .RunInNewTxn (ctx , store , true , func (ctx context.Context , txn kv.Transaction ) error {
475
500
idAcc := meta .NewMeta (txn ).GetAutoIDAccessors (dbID , tblID ).IncrementID (model .TableInfoVersion5 )
476
501
currentEnd , err1 := idAcc .Get ()
477
502
if err1 != nil {
478
503
return err1
479
504
}
505
+ oldValue = currentEnd
480
506
var step int64
481
507
if ! isUnsigned {
482
508
step = requiredBase - currentEnd
@@ -490,6 +516,13 @@ func (alloc *autoIDValue) forceRebase(ctx context.Context, store kv.Storage, dbI
490
516
if err != nil {
491
517
return err
492
518
}
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" ))
493
526
alloc .base , alloc .end = requiredBase , requiredBase
494
527
return nil
495
528
}
0 commit comments