Skip to content

Commit 4c7ee35

Browse files
[release-1.0] cherry pick add manual gc (#6326)
1 parent 223aa07 commit 4c7ee35

1 file changed

Lines changed: 32 additions & 6 deletions

File tree

store/tikv/gc_worker.go

Lines changed: 32 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -745,6 +745,16 @@ func (w *GCWorker) genNextGCTask(bo *Backoffer, safePoint uint64, key kv.Key) (*
745745
}
746746

747747
func (w *GCWorker) doGC(ctx goctx.Context, safePoint uint64) error {
748+
concurrency, err := w.loadGCConcurrencyWithDefault()
749+
if err != nil {
750+
log.Errorf("[gc worker] %s failed to load gcConcurrency, err %s", w.uuid, err)
751+
concurrency = gcDefaultConcurrency
752+
}
753+
754+
return w.doGCInternal(ctx, safePoint, concurrency)
755+
}
756+
757+
func (w *GCWorker) doGCInternal(ctx goctx.Context, safePoint uint64, concurrency int) error {
748758
gcWorkerCounter.WithLabelValues("do_gc").Inc()
749759

750760
err := w.saveSafePoint(gcSavedSafePoint, safePoint)
@@ -755,12 +765,6 @@ func (w *GCWorker) doGC(ctx goctx.Context, safePoint uint64) error {
755765
// Sleep to wait for all other tidb instances update their safepoint cache.
756766
time.Sleep(gcSafePointCacheInterval)
757767

758-
concurrency, err := w.loadGCConcurrencyWithDefault()
759-
if err != nil {
760-
log.Errorf("[gc worker] %s failed to load gcConcurrency, err %s", w.uuid, err)
761-
concurrency = gcDefaultConcurrency
762-
}
763-
764768
log.Infof("[gc worker] %s start gc, concurrency %v, safePoint: %v.", w.uuid, concurrency, safePoint)
765769
startTime := time.Now()
766770
var successRegions int32
@@ -999,6 +1003,28 @@ func (w *GCWorker) saveValueToSysTable(key, value string, s tidb.Session) error
9991003
return errors.Trace(err)
10001004
}
10011005

1006+
// RunGCJob sends GC command to KV. it is exported for kv api, do not use it with GCWorker at the same time.
1007+
func RunGCJob(ctx goctx.Context, s *tikvStore, safePoint uint64, identifier string, concurrency int) error {
1008+
gcWorker := &GCWorker{
1009+
store: s,
1010+
uuid: identifier,
1011+
}
1012+
1013+
err := gcWorker.resolveLocks(ctx, safePoint)
1014+
if err != nil {
1015+
return errors.Trace(err)
1016+
}
1017+
1018+
if concurrency <= 0 {
1019+
return errors.Errorf("[gc worker] gc concurrency should greater than 0, current concurrency: %v", concurrency)
1020+
}
1021+
err = gcWorker.doGCInternal(ctx, safePoint, concurrency)
1022+
if err != nil {
1023+
return errors.Trace(err)
1024+
}
1025+
return nil
1026+
}
1027+
10021028
// MockGCWorker is for test.
10031029
type MockGCWorker struct {
10041030
worker *GCWorker

0 commit comments

Comments
 (0)