Skip to content

Commit

Permalink
remove upperbound option
Browse files Browse the repository at this point in the history
  • Loading branch information
weiihann committed Dec 17, 2024
1 parent 9021e42 commit e4b412b
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 12 deletions.
4 changes: 2 additions & 2 deletions cmd/juno/dbcmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ func dbSize(cmd *cobra.Command, args []string) error {
buckets := db.BucketValues()
for _, b := range buckets {
fmt.Fprintf(cmd.OutOrStdout(), "Calculating size of %s, remaining buckets: %d\n", b, len(db.BucketValues())-int(b)-1)
bucketItem, err := pebble.CalculatePrefixSize(cmd.Context(), pebbleDB.(*pebble.DB), []byte{byte(b)}, true)
bucketItem, err := pebble.CalculatePrefixSize(cmd.Context(), pebbleDB.(*pebble.DB), []byte{byte(b)})
if err != nil {
return err
}
Expand All @@ -232,7 +232,7 @@ func dbSize(cmd *cobra.Command, args []string) error {
// check if there is any data left in the db
lastBucket := buckets[len(buckets)-1]
fmt.Fprintln(cmd.OutOrStdout(), "Calculating remaining data in the db")
lastBucketItem, err := pebble.CalculatePrefixSize(cmd.Context(), pebbleDB.(*pebble.DB), []byte{byte(lastBucket + 1)}, false)
lastBucketItem, err := pebble.CalculatePrefixSize(cmd.Context(), pebbleDB.(*pebble.DB), []byte{byte(lastBucket + 1)})
if err != nil {
return err
}
Expand Down
8 changes: 2 additions & 6 deletions db/pebble/db.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ func (i *Item) add(size utils.DataSize) {
i.Size += size
}

func CalculatePrefixSize(ctx context.Context, pDB *DB, prefix []byte, withUpperBound bool) (*Item, error) {
func CalculatePrefixSize(ctx context.Context, pDB *DB, prefix []byte) (*Item, error) {
var (
err error
v []byte
Expand All @@ -138,12 +138,8 @@ func CalculatePrefixSize(ctx context.Context, pDB *DB, prefix []byte, withUpperB
)

pebbleDB := pDB.Impl().(*pebble.DB)
iterOpt := &pebble.IterOptions{LowerBound: prefix}
if withUpperBound {
iterOpt.UpperBound = upperBound(prefix)
}

it, err := pebbleDB.NewIter(iterOpt)
it, err := pebbleDB.NewIter(&pebble.IterOptions{LowerBound: prefix, UpperBound: upperBound(prefix)})
if err != nil {
// No need to call utils.RunAndWrapOnError() since iterator couldn't be created
return nil, err
Expand Down
8 changes: 4 additions & 4 deletions db/pebble/db_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -424,7 +424,7 @@ func TestCalculatePrefixSize(t *testing.T) {
t.Run("empty db", func(t *testing.T) {
testDB := pebble.NewMemTest(t).(*pebble.DB)

s, err := pebble.CalculatePrefixSize(context.Background(), testDB, []byte("0"), true)
s, err := pebble.CalculatePrefixSize(context.Background(), testDB, []byte("0"))
require.NoError(t, err)
assert.Zero(t, s.Count)
assert.Zero(t, s.Size)
Expand All @@ -435,7 +435,7 @@ func TestCalculatePrefixSize(t *testing.T) {
require.NoError(t, testDB.Update(func(txn db.Transaction) error {
return txn.Set(append([]byte("0"), []byte("randomKey")...), []byte("someValue"))
}))
s, err := pebble.CalculatePrefixSize(context.Background(), testDB.(*pebble.DB), []byte("1"), true)
s, err := pebble.CalculatePrefixSize(context.Background(), testDB.(*pebble.DB), []byte("1"))
require.NoError(t, err)
assert.Zero(t, s.Count)
assert.Zero(t, s.Size)
Expand All @@ -455,7 +455,7 @@ func TestCalculatePrefixSize(t *testing.T) {
return txn.Set(k3, v3)
}))

s, err := pebble.CalculatePrefixSize(context.Background(), testDB.(*pebble.DB), p, true)
s, err := pebble.CalculatePrefixSize(context.Background(), testDB.(*pebble.DB), p)
require.NoError(t, err)
assert.Equal(t, uint(3), s.Count)
assert.Equal(t, utils.DataSize(expectedSize), s.Size)
Expand All @@ -464,7 +464,7 @@ func TestCalculatePrefixSize(t *testing.T) {
ctx, cancel := context.WithCancel(context.Background())
cancel()

s, err := pebble.CalculatePrefixSize(ctx, testDB.(*pebble.DB), p, true)
s, err := pebble.CalculatePrefixSize(ctx, testDB.(*pebble.DB), p)
assert.EqualError(t, err, context.Canceled.Error())
assert.Zero(t, s.Count)
assert.Zero(t, s.Size)
Expand Down

0 comments on commit e4b412b

Please sign in to comment.