Skip to content

Commit

Permalink
gc_worker: enable green GC by default (#18167)
Browse files Browse the repository at this point in the history
Signed-off-by: youjiali1995 <zlwgx1023@gmail.com>

Co-authored-by: ti-srebot <66930949+ti-srebot@users.noreply.github.com>
Co-authored-by: Shirly <wuxuelian@pingcap.com>
  • Loading branch information
3 people authored Jun 27, 2020
1 parent 773b291 commit 43d7b0e
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 9 deletions.
8 changes: 6 additions & 2 deletions store/tikv/gcworker/gc_worker.go
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ const (
gcScanLockModeKey = "tikv_gc_scan_lock_mode"
gcScanLockModeLegacy = "legacy"
gcScanLockModePhysical = "physical"
gcScanLockModeDefault = gcScanLockModeLegacy
gcScanLockModeDefault = gcScanLockModePhysical

gcAutoConcurrencyKey = "tikv_gc_auto_concurrency"
gcDefaultAutoConcurrency = true
Expand All @@ -157,6 +157,7 @@ var gcVariableComments = map[string]string{
gcEnableKey: "Current GC enable status",
gcModeKey: "Mode of GC, \"central\" or \"distributed\"",
gcAutoConcurrencyKey: "Let TiDB pick the concurrency automatically. If set false, tikv_gc_concurrency will be used",
gcScanLockModeKey: "Mode of scanning locks, \"physical\" or \"legacy\"",
}

func (w *GCWorker) start(ctx context.Context, wg *sync.WaitGroup) {
Expand Down Expand Up @@ -914,7 +915,10 @@ func (w *GCWorker) checkUsePhysicalScanLock() (bool, error) {
return false, errors.Trace(err)
}
if str == "" {
// Do not save it here, so that this config is hidden.
err = w.saveValueToSysTable(gcScanLockModeKey, gcScanLockModeDefault)
if err != nil {
return false, errors.Trace(err)
}
str = gcScanLockModeDefault
}
if strings.EqualFold(str, gcScanLockModePhysical) {
Expand Down
14 changes: 7 additions & 7 deletions store/tikv/gcworker/gc_worker_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -481,23 +481,23 @@ func (s *testGCWorkerSuite) TestCheckGCMode(c *C) {
func (s *testGCWorkerSuite) TestCheckScanLockMode(c *C) {
usePhysical, err := s.gcWorker.checkUsePhysicalScanLock()
c.Assert(err, IsNil)
c.Assert(usePhysical, Equals, false)
// This is a hidden config, so default value will not be inserted to table.
c.Assert(usePhysical, Equals, gcScanLockModeDefault == gcScanLockModePhysical)
// Now the row must be set to the default value.
str, err := s.gcWorker.loadValueFromSysTable(gcScanLockModeKey)
c.Assert(err, IsNil)
c.Assert(str, Equals, "")
c.Assert(str, Equals, gcScanLockModeDefault)

err = s.gcWorker.saveValueToSysTable(gcScanLockModeKey, gcScanLockModePhysical)
err = s.gcWorker.saveValueToSysTable(gcScanLockModeKey, gcScanLockModeLegacy)
c.Assert(err, IsNil)
usePhysical, err = s.gcWorker.checkUsePhysicalScanLock()
c.Assert(err, IsNil)
c.Assert(usePhysical, Equals, true)
c.Assert(usePhysical, Equals, false)

err = s.gcWorker.saveValueToSysTable(gcScanLockModeKey, gcScanLockModeLegacy)
err = s.gcWorker.saveValueToSysTable(gcScanLockModeKey, gcScanLockModePhysical)
c.Assert(err, IsNil)
usePhysical, err = s.gcWorker.checkUsePhysicalScanLock()
c.Assert(err, IsNil)
c.Assert(usePhysical, Equals, false)
c.Assert(usePhysical, Equals, true)

err = s.gcWorker.saveValueToSysTable(gcScanLockModeKey, "invalid_mode")
c.Assert(err, IsNil)
Expand Down

0 comments on commit 43d7b0e

Please sign in to comment.