diff --git a/store/tikv/gcworker/gc_worker.go b/store/tikv/gcworker/gc_worker.go index cdd51cbb595d2..0a05aa9256e6e 100644 --- a/store/tikv/gcworker/gc_worker.go +++ b/store/tikv/gcworker/gc_worker.go @@ -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 @@ -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) { @@ -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) { diff --git a/store/tikv/gcworker/gc_worker_test.go b/store/tikv/gcworker/gc_worker_test.go index 3cafc340b5c9f..ebe2345ce0cd2 100644 --- a/store/tikv/gcworker/gc_worker_test.go +++ b/store/tikv/gcworker/gc_worker_test.go @@ -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)