Skip to content

Commit

Permalink
refactor: use minimumTableSize directly
Browse files Browse the repository at this point in the history
  • Loading branch information
buraksezer committed May 13, 2022
1 parent de7fb53 commit 69bc5f2
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 9 deletions.
6 changes: 3 additions & 3 deletions internal/kvstore/kvstore.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ func (kv *KVStore) Fork(c *storage.Config) (storage.Engine, error) {
config: c,
minimumTableSize: size.(int),
}
t := newTable(child.calculateTableSize(0))
t := newTable(child.minimumTableSize)
child.tables = append(child.tables, t)
return child, nil
}
Expand All @@ -113,7 +113,7 @@ func (kv *KVStore) PutRaw(hkey uint64, value []byte) error {
err := t.putRaw(hkey, value)
if err == errNotEnoughSpace {
// Create a new table and put the new k/v pair in it.
// The value includes the metadata, so there is no need to use requiredSpaceForAnEntry.
// The value includes its metadata, so there is no need to use requiredSpaceForAnEntry.
ntSize := kv.calculateTableSize(len(value))
nt := newTable(ntSize)
kv.tables = append(kv.tables, nt)
Expand Down Expand Up @@ -293,7 +293,7 @@ func (kv *KVStore) Delete(hkey uint64) error {
t := kv.tables[0]
if float64(t.allocated)*maxGarbageRatio <= float64(t.garbage) {
// Create a new table here.
nt := newTable(kv.calculateTableSize(0))
nt := newTable(kv.minimumTableSize)
kv.tables = append(kv.tables, nt)
return storage.ErrFragmented
}
Expand Down
13 changes: 7 additions & 6 deletions internal/kvstore/kvstore_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -742,9 +742,10 @@ func Test_ExpandTable(t *testing.T) {
}

st := kv.Stats()
tableSize := kv.calculateTableSize(0)
if tableSize != st.Inuse*2 {
t.Fatalf("Calculated tableSize(%d) has to be equal to Inuse*2(%d)", tableSize, st.Inuse*2)
minimumRequiredSize := 1000
tableSize := kv.calculateTableSize(minimumRequiredSize)
if tableSize != (st.Inuse+minimumRequiredSize)*2 {
t.Fatalf("Calculated tableSize(%d) has to be equal to (Inuse+minimumRequiredSize)*2(%d)", tableSize, st.Inuse*2)
}
}

Expand All @@ -768,9 +769,9 @@ func Test_ExpandTable_With_Big_Value(t *testing.T) {
}

st := kv.Stats()
bigValueSize := 1 << 21
tableSize := kv.calculateTableSize(bigValueSize)
calculatedTableSize := (st.Inuse + bigValueSize) * 2
bigEntrySize := 1 << 21 // including metadata
tableSize := kv.calculateTableSize(bigEntrySize)
calculatedTableSize := (st.Inuse + bigEntrySize) * 2
if tableSize != calculatedTableSize {
t.Fatalf("Calculated tableSize(%d) has to be equal to Inuse*2 + valueSize(%d)", tableSize, calculatedTableSize)
}
Expand Down

0 comments on commit 69bc5f2

Please sign in to comment.