-
Notifications
You must be signed in to change notification settings - Fork 180
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #6603 from onflow/leo/db-ops-dbstore
[Storage] Pruning - add a test case to verify compaction can reclaim disk space
- Loading branch information
Showing
11 changed files
with
577 additions
and
39 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package badgerimpl | ||
|
||
import ( | ||
"github.com/dgraph-io/badger/v2" | ||
|
||
"github.com/onflow/flow-go/storage" | ||
) | ||
|
||
func ToDB(db *badger.DB) storage.DB { | ||
return &dbStore{db: db} | ||
} | ||
|
||
type dbStore struct { | ||
db *badger.DB | ||
} | ||
|
||
func (b *dbStore) Reader() storage.Reader { | ||
return dbReader{db: b.db} | ||
} | ||
|
||
func (b *dbStore) WithReaderBatchWriter(fn func(storage.ReaderBatchWriter) error) error { | ||
return WithReaderBatchWriter(b.db, fn) | ||
} | ||
|
||
func (b *dbStore) NewBatch() storage.Batch { | ||
return NewReaderBatchWriter(b.db) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package pebbleimpl | ||
|
||
import ( | ||
"github.com/cockroachdb/pebble" | ||
|
||
"github.com/onflow/flow-go/storage" | ||
) | ||
|
||
func ToDB(db *pebble.DB) storage.DB { | ||
return &dbStore{db: db} | ||
} | ||
|
||
type dbStore struct { | ||
db *pebble.DB | ||
} | ||
|
||
func (b *dbStore) Reader() storage.Reader { | ||
return dbReader{db: b.db} | ||
} | ||
|
||
func (b *dbStore) WithReaderBatchWriter(fn func(storage.ReaderBatchWriter) error) error { | ||
return WithReaderBatchWriter(b.db, fn) | ||
} | ||
|
||
func (b *dbStore) NewBatch() storage.Batch { | ||
return NewReaderBatchWriter(b.db) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
package operation_test | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/require" | ||
|
||
"github.com/onflow/flow-go/storage" | ||
"github.com/onflow/flow-go/storage/operation" | ||
"github.com/onflow/flow-go/storage/operation/dbtest" | ||
) | ||
|
||
func BenchmarkRetrieve(t *testing.B) { | ||
dbtest.BenchWithStorages(t, func(t *testing.B, r storage.Reader, withWriter dbtest.WithWriter) { | ||
e := Entity{ID: 1337} | ||
require.NoError(t, withWriter(operation.Upsert(e.Key(), e))) | ||
|
||
t.ResetTimer() | ||
|
||
for i := 0; i < t.N; i++ { | ||
var readBack Entity | ||
require.NoError(t, operation.Retrieve(e.Key(), &readBack)(r)) | ||
} | ||
}) | ||
} | ||
|
||
func BenchmarkNonExist(t *testing.B) { | ||
dbtest.BenchWithStorages(t, func(t *testing.B, r storage.Reader, withWriter dbtest.WithWriter) { | ||
for i := 0; i < t.N; i++ { | ||
e := Entity{ID: uint64(i)} | ||
require.NoError(t, withWriter(operation.Upsert(e.Key(), e))) | ||
} | ||
|
||
t.ResetTimer() | ||
nonExist := Entity{ID: uint64(t.N + 1)} | ||
for i := 0; i < t.N; i++ { | ||
var exists bool | ||
require.NoError(t, operation.Exists(nonExist.Key(), &exists)(r)) | ||
} | ||
}) | ||
} | ||
|
||
func BenchmarkIterate(t *testing.B) { | ||
dbtest.BenchWithStorages(t, func(t *testing.B, r storage.Reader, withWriter dbtest.WithWriter) { | ||
prefix1 := []byte("prefix-1") | ||
prefix2 := []byte("prefix-2") | ||
for i := 0; i < t.N; i++ { | ||
e := Entity{ID: uint64(i)} | ||
key1 := append(prefix1, e.Key()...) | ||
key2 := append(prefix2, e.Key()...) | ||
|
||
require.NoError(t, withWriter(operation.Upsert(key1, e))) | ||
require.NoError(t, withWriter(operation.Upsert(key2, e))) | ||
} | ||
|
||
t.ResetTimer() | ||
var found [][]byte | ||
require.NoError(t, operation.Iterate(prefix1, prefix2, func(key []byte) error { | ||
found = append(found, key) | ||
return nil | ||
})(r), "should iterate forward without error") | ||
}) | ||
} |
Oops, something went wrong.