From bbcdf33a91b4ce8cec5f2412e7c2b288e0e989bb Mon Sep 17 00:00:00 2001 From: ngaut Date: Fri, 18 Dec 2015 13:14:02 +0800 Subject: [PATCH] Remove compactor interface in kv.go --- kv/compactor.go | 40 ------------------------------ store/localstore/compactor.go | 20 +++++++++++---- store/localstore/compactor_test.go | 4 +-- 3 files changed, 17 insertions(+), 47 deletions(-) delete mode 100644 kv/compactor.go diff --git a/kv/compactor.go b/kv/compactor.go deleted file mode 100644 index 1687225e82..0000000000 --- a/kv/compactor.go +++ /dev/null @@ -1,40 +0,0 @@ -// Copyright 2015 PingCAP, Inc. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// See the License for the specific language governing permissions and -// limitations under the License. - -package kv - -import "time" - -// CompactPolicy defines gc policy of MVCC storage. -type CompactPolicy struct { - // SafePoint specifies - SafePoint int - // TriggerInterval specifies how often should the compactor - // scans outdated data. - TriggerInterval time.Duration - // BatchDeleteCnt specifies the batch size for - // deleting outdated data transaction. - BatchDeleteCnt int -} - -// Compactor compacts MVCC storage. -type Compactor interface { - // OnGet is the hook point on Txn.Get. - OnGet(k Key) - // OnSet is the hook point on Txn.Set. - OnSet(k Key) - // OnDelete is the hook point on Txn.Delete. - OnDelete(k Key) - // Compact is the function removes the given key. - Compact(k Key) error -} diff --git a/store/localstore/compactor.go b/store/localstore/compactor.go index 2a70276261..97698fd831 100644 --- a/store/localstore/compactor.go +++ b/store/localstore/compactor.go @@ -25,13 +25,23 @@ import ( "github.com/pingcap/tidb/util/bytes" ) -var _ kv.Compactor = (*localstoreCompactor)(nil) - const ( deleteWorkerCnt = 3 ) -var localCompactDefaultPolicy = kv.CompactPolicy{ +// compactPolicy defines gc policy of MVCC storage. +type compactPolicy struct { + // SafePoint specifies + SafePoint int + // TriggerInterval specifies how often should the compactor + // scans outdated data. + TriggerInterval time.Duration + // BatchDeleteCnt specifies the batch size for + // deleting outdated data transaction. + BatchDeleteCnt int +} + +var localCompactDefaultPolicy = compactPolicy{ SafePoint: 20 * 1000, // in ms TriggerInterval: 10 * time.Second, BatchDeleteCnt: 100, @@ -45,7 +55,7 @@ type localstoreCompactor struct { workerWaitGroup *sync.WaitGroup ticker *time.Ticker db engine.DB - policy kv.CompactPolicy + policy compactPolicy } func (gc *localstoreCompactor) OnSet(k kv.Key) { @@ -196,7 +206,7 @@ func (gc *localstoreCompactor) Stop() { gc.workerWaitGroup.Wait() } -func newLocalCompactor(policy kv.CompactPolicy, db engine.DB) *localstoreCompactor { +func newLocalCompactor(policy compactPolicy, db engine.DB) *localstoreCompactor { return &localstoreCompactor{ recentKeys: make(map[string]struct{}), stopCh: make(chan struct{}), diff --git a/store/localstore/compactor_test.go b/store/localstore/compactor_test.go index 0f4da22d13..b3bf436b6f 100644 --- a/store/localstore/compactor_test.go +++ b/store/localstore/compactor_test.go @@ -46,7 +46,7 @@ func (s *localstoreCompactorTestSuite) TestCompactor(c *C) { db := store.(*dbStore).db store.(*dbStore).compactor.Stop() - policy := kv.CompactPolicy{ + policy := compactPolicy{ SafePoint: 500, BatchDeleteCnt: 1, TriggerInterval: 100 * time.Millisecond, @@ -119,7 +119,7 @@ func (s *localstoreCompactorTestSuite) TestStartStop(c *C) { db := store.(*dbStore).db for i := 0; i < 10000; i++ { - policy := kv.CompactPolicy{ + policy := compactPolicy{ SafePoint: 500, BatchDeleteCnt: 1, TriggerInterval: 100 * time.Millisecond,