Skip to content

Commit

Permalink
fix a redundant opts
Browse files Browse the repository at this point in the history
  • Loading branch information
roseduan committed Mar 20, 2022
1 parent f2fc1c1 commit 4390b27
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 33 deletions.
11 changes: 2 additions & 9 deletions db_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -206,19 +206,12 @@ func TestLotusDB_Get(t *testing.T) {
}
}

func TestLotusDB_GetKVFromIndexer(t *testing.T) {
// set the threshold bigger that value will be stored only in indexer.
testGetKV(t, 64<<20)
}

func TestLotusDB_GetKeyFromIndexerAndValFromVLog(t *testing.T) {
// set the threshold smaller that value will be stored in value log.
testGetKV(t, 0)
testGetKV(t)
}

func testGetKV(t *testing.T, valueThreshold int) {
func testGetKV(t *testing.T) {
opts := DefaultOptions("/tmp" + separator + "lotusdb")
opts.CfOpts.ValueThreshold = valueThreshold
db, err := Open(opts)
assert.Nil(t, err)
defer destroyDB(db)
Expand Down
28 changes: 12 additions & 16 deletions flush.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,22 +70,18 @@ func (cf *ColumnFamily) listenAndFlush() {
if mv.typ == byte(logfile.TypeDelete) || (mv.expiredAt != 0 && mv.expiredAt <= time.Now().Unix()) {
deletedKeys = append(deletedKeys, key)
} else {
if len(mv.value) >= cf.opts.ValueThreshold {
valuePos, esize, err := cf.vlog.Write(&logfile.LogEntry{
Key: key,
Value: mv.value,
ExpiredAt: mv.expiredAt,
})
if err != nil {
return err
}
node.Meta = &index.IndexerMeta{
Fid: valuePos.Fid,
Offset: valuePos.Offset,
EntrySize: esize,
}
} else {
node.Meta = &index.IndexerMeta{Value: mv.value}
valuePos, esize, err := cf.vlog.Write(&logfile.LogEntry{
Key: key,
Value: mv.value,
ExpiredAt: mv.expiredAt,
})
if err != nil {
return err
}
node.Meta = &index.IndexerMeta{
Fid: valuePos.Fid,
Offset: valuePos.Offset,
EntrySize: esize,
}
nodes = append(nodes, node)
}
Expand Down
10 changes: 2 additions & 8 deletions options.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ func DefaultOptions(path string) Options {
WalMMap: false,
ValueLogFileSize: 1024 << 20,
ValueLogMmap: false,
ValueThreshold: 0,
ValueLogGCRatio: 0.5,
ValueLogGCInterval: time.Minute * 10,
},
Expand All @@ -43,7 +42,6 @@ func DefaultColumnFamilyOptions(name string) ColumnFamilyOptions {
WalMMap: false,
ValueLogFileSize: 1024 << 20,
ValueLogMmap: false,
ValueThreshold: 0,
ValueLogGCRatio: 0.5,
ValueLogGCInterval: time.Minute * 10,
}
Expand Down Expand Up @@ -79,6 +77,7 @@ type ColumnFamilyOptions struct {

// MemSpaceWaitTimeout represents timeout for waiting enough memtable space to write.
// In this scenario will wait: memtable has reached the maximum nums, and has no time to be flushed into disk.
// Default value is 100ms.
MemSpaceWaitTimeout time.Duration

// IndexerDir dir path to store index meta data, default value is dir path.
Expand Down Expand Up @@ -108,11 +107,6 @@ type ColumnFamilyOptions struct {
// ValueLogMmap similar to WalMMap, default value is false.
ValueLogMmap bool

// ValueThreshold sets the threshold used to decide whether a value is stored directly in the Index(B+Tree right now) or separately in value log file.
// If the threshold is zero, that means all values will be stored in value log file.
// Default value is 0.
ValueThreshold int

// ValueLogGCRatio if discarded data in value log exceeds this ratio, it can be picked up for compaction(garbage collection)
// And if there are many files reached the ratio, we will pick the highest one by one.
// The recommended ratio is 0.5, half of the file can be compacted.
Expand Down Expand Up @@ -145,7 +139,7 @@ type WriteOptions struct {
// Default value is false.
DisableWal bool

// ExpiredAt time to live for the specified key, a time.Unix value.
// ExpiredAt time to live for the specified key, must be a time.Unix value.
// It will be ignored if it`s not a positive number.
// Default value is 0.
ExpiredAt int64
Expand Down

0 comments on commit 4390b27

Please sign in to comment.