Skip to content

Commit

Permalink
store/tikv/gcworker: add manual gc back for some kv api users (#6123)
Browse files Browse the repository at this point in the history
* use fake gc_worker instead of bringing funcs out of gc_worker
* fix comments
  • Loading branch information
wentaoxu authored Mar 26, 2018
1 parent 4ac1451 commit 9fe407f
Showing 1 changed file with 28 additions and 6 deletions.
34 changes: 28 additions & 6 deletions store/tikv/gcworker/gc_worker.go
Original file line number Diff line number Diff line change
Expand Up @@ -666,6 +666,16 @@ func (w *GCWorker) genNextGCTask(bo *tikv.Backoffer, safePoint uint64, key kv.Ke
}

func (w *GCWorker) doGC(ctx context.Context, safePoint uint64) error {
concurrency, err := w.loadGCConcurrencyWithDefault()
if err != nil {
log.Errorf("[gc worker] %s failed to load gcConcurrency, err %s", w.uuid, err)
concurrency = gcDefaultConcurrency
}

return w.doGCInternal(ctx, safePoint, concurrency)
}

func (w *GCWorker) doGCInternal(ctx context.Context, safePoint uint64, concurrency int) error {
gcWorkerCounter.WithLabelValues("do_gc").Inc()

err := w.saveSafePoint(w.store.GetSafePointKV(), tikv.GcSavedSafePoint, safePoint)
Expand All @@ -676,12 +686,6 @@ func (w *GCWorker) doGC(ctx context.Context, safePoint uint64) error {
// Sleep to wait for all other tidb instances update their safepoint cache.
time.Sleep(gcSafePointCacheInterval)

concurrency, err := w.loadGCConcurrencyWithDefault()
if err != nil {
log.Errorf("[gc worker] %s failed to load gcConcurrency, err %s", w.uuid, err)
concurrency = gcDefaultConcurrency
}

log.Infof("[gc worker] %s start gc, concurrency %v, safePoint: %v.", w.uuid, concurrency, safePoint)
startTime := time.Now()
var successRegions int32
Expand Down Expand Up @@ -911,6 +915,24 @@ func (w *GCWorker) saveValueToSysTable(key, value string, s session.Session) err
return errors.Trace(err)
}

// RunGCJob sends GC command to KV. it is exported for kv api, do not use it with GCWorker at the same time.
func RunGCJob(ctx context.Context, s tikv.Storage, safePoint uint64, identifier string) error {
gcWorker := &GCWorker{
store: s,
uuid: identifier,
}

err := gcWorker.resolveLocks(ctx, safePoint)
if err != nil {
return errors.Trace(err)
}
err = gcWorker.doGCInternal(ctx, safePoint, gcDefaultConcurrency)
if err != nil {
return errors.Trace(err)
}
return nil
}

// MockGCWorker is for test.
type MockGCWorker struct {
worker *GCWorker
Expand Down

0 comments on commit 9fe407f

Please sign in to comment.