Skip to content

Commit

Permalink
gc: central GC mode is deprecated (#23389)
Browse files Browse the repository at this point in the history
  • Loading branch information
hicqu authored Mar 18, 2021
1 parent 389bc5f commit 9f88887
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 43 deletions.
44 changes: 16 additions & 28 deletions store/gcworker/gc_worker.go
Original file line number Diff line number Diff line change
Expand Up @@ -636,16 +636,7 @@ func (w *GCWorker) runGCJob(ctx context.Context, safePoint uint64, concurrency i
return errors.Trace(err)
}

useDistributedGC, err := w.checkUseDistributedGC()
if err != nil {
logutil.Logger(ctx).Error("[gc worker] failed to load gc mode, fall back to central mode.",
zap.String("uuid", w.uuid),
zap.Error(err))
metrics.GCJobFailureCounter.WithLabelValues("check_gc_mode").Inc()
useDistributedGC = false
}

if useDistributedGC {
if w.checkUseDistributedGC() {
err = w.uploadSafePointToPD(ctx, safePoint)
if err != nil {
logutil.Logger(ctx).Error("[gc worker] failed to upload safe point to PD",
Expand Down Expand Up @@ -949,27 +940,24 @@ func (w *GCWorker) loadGCConcurrencyWithDefault() (int, error) {
return jobConcurrency, nil
}

func (w *GCWorker) checkUseDistributedGC() (bool, error) {
str, err := w.loadValueFromSysTable(gcModeKey)
if err != nil {
return false, errors.Trace(err)
}
if str == "" {
// Central mode is deprecated in v5.0. This function will always return true.
func (w *GCWorker) checkUseDistributedGC() bool {
mode, err := w.loadValueFromSysTable(gcModeKey)
if err == nil && mode == "" {
err = w.saveValueToSysTable(gcModeKey, gcModeDefault)
if err != nil {
return false, errors.Trace(err)
}
str = gcModeDefault
}
if strings.EqualFold(str, gcModeDistributed) {
return true, nil
}
if strings.EqualFold(str, gcModeCentral) {
return false, nil
if err != nil {
logutil.BgLogger().Error("[gc worker] failed to load gc mode, fall back to distributed mode",
zap.String("uuid", w.uuid),
zap.Error(err))
metrics.GCJobFailureCounter.WithLabelValues("check_gc_mode").Inc()
} else if strings.EqualFold(mode, gcModeCentral) {
logutil.BgLogger().Warn("[gc worker] distributed mode will be used as central mode is deprecated")
} else if !strings.EqualFold(mode, gcModeDistributed) {
logutil.BgLogger().Warn("[gc worker] distributed mode will be used",
zap.String("invalid gc mode", mode))
}
logutil.BgLogger().Warn("[gc worker] distributed mode will be used",
zap.String("invalid gc mode", str))
return true, nil
return true
}

func (w *GCWorker) checkUsePhysicalScanLock() (bool, error) {
Expand Down
26 changes: 11 additions & 15 deletions store/gcworker/gc_worker_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -487,30 +487,28 @@ func (s *testGCWorkerSuite) TestDoGC(c *C) {
}

func (s *testGCWorkerSuite) TestCheckGCMode(c *C) {
useDistributedGC, err := s.gcWorker.checkUseDistributedGC()
c.Assert(err, IsNil)
useDistributedGC := s.gcWorker.checkUseDistributedGC()
c.Assert(useDistributedGC, Equals, true)
// Now the row must be set to the default value.
str, err := s.gcWorker.loadValueFromSysTable(gcModeKey)
c.Assert(err, IsNil)
c.Assert(str, Equals, gcModeDistributed)

// Central mode is deprecated in v5.0.
err = s.gcWorker.saveValueToSysTable(gcModeKey, gcModeCentral)
c.Assert(err, IsNil)
useDistributedGC, err = s.gcWorker.checkUseDistributedGC()
useDistributedGC = s.gcWorker.checkUseDistributedGC()
c.Assert(err, IsNil)
c.Assert(useDistributedGC, Equals, false)
c.Assert(useDistributedGC, Equals, true)

err = s.gcWorker.saveValueToSysTable(gcModeKey, gcModeDistributed)
c.Assert(err, IsNil)
useDistributedGC, err = s.gcWorker.checkUseDistributedGC()
c.Assert(err, IsNil)
useDistributedGC = s.gcWorker.checkUseDistributedGC()
c.Assert(useDistributedGC, Equals, true)

err = s.gcWorker.saveValueToSysTable(gcModeKey, "invalid_mode")
c.Assert(err, IsNil)
useDistributedGC, err = s.gcWorker.checkUseDistributedGC()
c.Assert(err, IsNil)
useDistributedGC = s.gcWorker.checkUseDistributedGC()
c.Assert(useDistributedGC, Equals, true)
}

Expand Down Expand Up @@ -987,11 +985,10 @@ func (s *testGCWorkerSuite) TestRunGCJob(c *C) {
gcSafePointCacheInterval = 0

// Test distributed mode
useDistributedGC, err := s.gcWorker.checkUseDistributedGC()
c.Assert(err, IsNil)
useDistributedGC := s.gcWorker.checkUseDistributedGC()
c.Assert(useDistributedGC, IsTrue)
safePoint := s.mustAllocTs(c)
err = s.gcWorker.runGCJob(context.Background(), safePoint, 1)
err := s.gcWorker.runGCJob(context.Background(), safePoint, 1)
c.Assert(err, IsNil)

pdSafePoint := s.mustGetSafePointFromPd(c)
Expand All @@ -1004,12 +1001,11 @@ func (s *testGCWorkerSuite) TestRunGCJob(c *C) {
err = s.gcWorker.runGCJob(context.Background(), safePoint-1, 1)
c.Assert(err, NotNil)

// Test central mode
// Central mode is deprecated in v5.0, fallback to distributed mode if it's set.
err = s.gcWorker.saveValueToSysTable(gcModeKey, gcModeCentral)
c.Assert(err, IsNil)
useDistributedGC, err = s.gcWorker.checkUseDistributedGC()
c.Assert(err, IsNil)
c.Assert(useDistributedGC, IsFalse)
useDistributedGC = s.gcWorker.checkUseDistributedGC()
c.Assert(useDistributedGC, IsTrue)

p := s.createGCProbe(c, "k1")
safePoint = s.mustAllocTs(c)
Expand Down

0 comments on commit 9f88887

Please sign in to comment.