Skip to content

Commit

Permalink
fix(localstore): corrupt reserve size (#2735)
Browse files Browse the repository at this point in the history
Fixes a bug where incorrect reserve size bookkeeping was done on Put calls that were using a variadic number of parameters.
  • Loading branch information
acud authored Jan 25, 2022
1 parent 9348c07 commit 5b9637b
Show file tree
Hide file tree
Showing 6 changed files with 215 additions and 79 deletions.
2 changes: 1 addition & 1 deletion pkg/localstore/gc.go
Original file line number Diff line number Diff line change
Expand Up @@ -374,7 +374,7 @@ func (db *DB) evictReserve() (totalEvicted uint64, done bool, err error) {
if err != nil {
return 0, false, err
}
if reserveSizeStart == target {
if reserveSizeStart <= target {
return 0, true, nil
}

Expand Down
18 changes: 17 additions & 1 deletion pkg/localstore/localstore_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -381,7 +381,7 @@ func newItemsCountTest(i shed.Index, want int) func(t *testing.T) {
}
}

// newIndexGCSizeTest retruns a test function that validates if DB.gcSize
// newIndexGCSizeTest returns a test function that validates if DB.gcSize
// value is the same as the number of items in DB.gcIndex.
func newIndexGCSizeTest(db *DB) func(t *testing.T) {
return func(t *testing.T) {
Expand All @@ -405,6 +405,22 @@ func newIndexGCSizeTest(db *DB) func(t *testing.T) {
}
}

// reserveSizeTest checks that the reserveSize scalar is equal
// to the expected value.
func reserveSizeTest(db *DB, want uint64) func(t *testing.T) {
return func(t *testing.T) {
t.Helper()

got, err := db.reserveSize.Get()
if err != nil {
t.Fatal(err)
}
if got != want {
t.Errorf("got reserve size %v, want %v", got, want)
}
}
}

// testIndexChunk embeds storageChunk with additional data that is stored
// in database. It is used for index values validations.
type testIndexChunk struct {
Expand Down
Loading

0 comments on commit 5b9637b

Please sign in to comment.