Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[release-1.0] cherry pick add manual gc #6326

Merged
merged 4 commits into from
Apr 20, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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