Skip to content

Commit 582174e

Browse files
committed
minor
1 parent c4133db commit 582174e

File tree

1 file changed

+8
-21
lines changed

1 file changed

+8
-21
lines changed

pkg/kv/kv.go

Lines changed: 8 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -25,22 +25,16 @@ type KV interface {
2525
var _ KV = new(CometKV)
2626

2727
type CometKV struct {
28-
mem memtable.IMemtable
29-
sst sst.IO
30-
31-
localInsertCounter int64
32-
globalLongRangeScanCount atomic.Int64
33-
globalLongRangeScanDuration time.Duration
28+
mem memtable.IMemtable
29+
sst sst.IO
30+
localInsertCounter int64
3431
}
3532

3633
func NewCometKV(ctx context.Context, mTyp memtable.Typ, dTyp sst.Type, gcInterval, ttl, flushInterval time.Duration) KV {
3734
kv := CometKV{
38-
mem: NewMemtable(mTyp, gcInterval, ttl, true, ctx),
39-
sst: sst.NewSstIO(dTyp),
40-
41-
localInsertCounter: 0,
42-
globalLongRangeScanCount: atomic.Int64{},
43-
globalLongRangeScanDuration: time.Duration(0),
35+
mem: NewMemtable(mTyp, gcInterval, ttl, true, ctx),
36+
sst: sst.NewSstIO(dTyp),
37+
localInsertCounter: 0,
4438
}
4539
kv.startFlushThread(flushInterval, ctx)
4640
return &kv
@@ -79,6 +73,7 @@ func (c *CometKV) Delete(key string) {
7973
func (c *CometKV) Close() {
8074
c.mem.Close()
8175
c.sst.Destroy()
76+
c.localInsertCounter = 0
8277
}
8378

8479
func (c *CometKV) startFlushThread(flushInterval time.Duration, ctx context.Context) {
@@ -92,17 +87,8 @@ func (c *CometKV) startFlushThread(flushInterval time.Duration, ctx context.Cont
9287
return
9388
case <-ticker.C:
9489
totalInsertsForLongRangeDuration := c.atomicCasLocalInsertCounter()
95-
96-
startTs := time.Now()
97-
9890
records := c.mem.Scan("", int(totalInsertsForLongRangeDuration), memtable.ScanOptions{SnapshotTs: time.Now()})
9991
_ = c.sst.Create(records)
100-
101-
endTs := time.Now()
102-
diff := endTs.Sub(startTs)
103-
104-
c.globalLongRangeScanCount.Add(int64(len(records)))
105-
c.globalLongRangeScanDuration += diff
10692
}
10793
}
10894
}()
@@ -122,6 +108,7 @@ func (c *CometKV) atomicCasLocalInsertCounter() int64 {
122108
func (c *CometKV) MemTableName() string {
123109
return c.mem.Name()
124110
}
111+
125112
func (c *CometKV) SstStorageName() string {
126113
return c.sst.Name()
127114
}

0 commit comments

Comments
 (0)