Skip to content

Commit

Permalink
[release-1.0] cherry pick add manual gc (#6326)
Browse files Browse the repository at this point in the history
  • Loading branch information
zhangjinpeng87 authored Apr 20, 2018
1 parent 223aa07 commit 4c7ee35
Showing 1 changed file with 32 additions and 6 deletions.
38 changes: 32 additions & 6 deletions store/tikv/gc_worker.go
Original file line number Diff line number Diff line change
Expand Up @@ -745,6 +745,16 @@ func (w *GCWorker) genNextGCTask(bo *Backoffer, safePoint uint64, key kv.Key) (*
}

func (w *GCWorker) doGC(ctx goctx.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 goctx.Context, safePoint uint64, concurrency int) error {
gcWorkerCounter.WithLabelValues("do_gc").Inc()

err := w.saveSafePoint(gcSavedSafePoint, safePoint)
Expand All @@ -755,12 +765,6 @@ func (w *GCWorker) doGC(ctx goctx.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 @@ -999,6 +1003,28 @@ func (w *GCWorker) saveValueToSysTable(key, value string, s tidb.Session) error
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 goctx.Context, s *tikvStore, safePoint uint64, identifier string, concurrency int) error {
gcWorker := &GCWorker{
store: s,
uuid: identifier,
}

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

if concurrency <= 0 {
return errors.Errorf("[gc worker] gc concurrency should greater than 0, current concurrency: %v", concurrency)
}
err = gcWorker.doGCInternal(ctx, safePoint, concurrency)
if err != nil {
return errors.Trace(err)
}
return nil
}

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

0 comments on commit 4c7ee35

Please sign in to comment.