Remove compactor interface in kv.go

This commit is contained in:
ngaut
2015-12-18 13:14:02 +08:00
parent 34304b1050
commit bbcdf33a91
3 changed files with 17 additions and 47 deletions

View File

@ -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
}

View File

@ -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{}),

View File

@ -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,