Skip to content

Commit

Permalink
Update for 6.16
Browse files Browse the repository at this point in the history
  • Loading branch information
flier authored and roysc committed Jul 14, 2021
1 parent 494acbb commit bb72fba
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 16 deletions.
34 changes: 24 additions & 10 deletions db.go
Original file line number Diff line number Diff line change
Expand Up @@ -592,10 +592,11 @@ func (db *DB) DropColumnFamily(c *ColumnFamilyHandle) error {
//
// The keys counted will begin at Range.Start and end on the key before
// Range.Limit.
func (db *DB) GetApproximateSizes(ranges []Range) []uint64 {
sizes := make([]uint64, len(ranges))
func (db *DB) GetApproximateSizes(ranges []Range) (sizes []uint64, err error) {
var cErr *C.char
sizes = make([]uint64, len(ranges))
if len(ranges) == 0 {
return sizes
return
}

cStarts := make([]*C.char, len(ranges))
Expand Down Expand Up @@ -623,20 +624,27 @@ func (db *DB) GetApproximateSizes(ranges []Range) []uint64 {
&cStartLens[0],
&cLimits[0],
&cLimitLens[0],
(*C.uint64_t)(&sizes[0]))
(*C.uint64_t)(&sizes[0]),
&cErr,
)
if cErr != nil {
defer C.rocksdb_free(unsafe.Pointer(cErr))
err = errors.New(C.GoString(cErr))
}

return sizes
return
}

// GetApproximateSizesCF returns the approximate number of bytes of file system
// space used by one or more key ranges in the column family.
//
// The keys counted will begin at Range.Start and end on the key before
// Range.Limit.
func (db *DB) GetApproximateSizesCF(cf *ColumnFamilyHandle, ranges []Range) []uint64 {
sizes := make([]uint64, len(ranges))
func (db *DB) GetApproximateSizesCF(cf *ColumnFamilyHandle, ranges []Range) (sizes []uint64, err error) {
var cErr *C.char
sizes = make([]uint64, len(ranges))
if len(ranges) == 0 {
return sizes
return
}

cStarts := make([]*C.char, len(ranges))
Expand Down Expand Up @@ -665,9 +673,15 @@ func (db *DB) GetApproximateSizesCF(cf *ColumnFamilyHandle, ranges []Range) []ui
&cStartLens[0],
&cLimits[0],
&cLimitLens[0],
(*C.uint64_t)(&sizes[0]))
(*C.uint64_t)(&sizes[0]),
&cErr,
)
if cErr != nil {
defer C.rocksdb_free(unsafe.Pointer(cErr))
err = errors.New(C.GoString(cErr))
}

return sizes
return
}

// SetOptions dynamically changes options through the SetOptions API.
Expand Down
18 changes: 12 additions & 6 deletions db_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -210,15 +210,18 @@ func TestDBGetApproximateSizes(t *testing.T) {
defer db.Close()

// no ranges
sizes := db.GetApproximateSizes(nil)
sizes, err := db.GetApproximateSizes(nil)
ensure.Nil(t, err)
ensure.DeepEqual(t, len(sizes), 0)

// range will nil start and limit
sizes = db.GetApproximateSizes([]Range{{Start: nil, Limit: nil}})
sizes, err = db.GetApproximateSizes([]Range{{Start: nil, Limit: nil}})
ensure.Nil(t, err)
ensure.DeepEqual(t, sizes, []uint64{0})

// valid range
sizes = db.GetApproximateSizes([]Range{{Start: []byte{0x00}, Limit: []byte{0xFF}}})
sizes, err = db.GetApproximateSizes([]Range{{Start: []byte{0x00}, Limit: []byte{0xFF}}})
ensure.Nil(t, err)
ensure.DeepEqual(t, sizes, []uint64{0})
}

Expand All @@ -232,14 +235,17 @@ func TestDBGetApproximateSizesCF(t *testing.T) {
ensure.Nil(t, err)

// no ranges
sizes := db.GetApproximateSizesCF(cf, nil)
sizes, err := db.GetApproximateSizesCF(cf, nil)
ensure.Nil(t, err)
ensure.DeepEqual(t, len(sizes), 0)

// range will nil start and limit
sizes = db.GetApproximateSizesCF(cf, []Range{{Start: nil, Limit: nil}})
sizes, err = db.GetApproximateSizesCF(cf, []Range{{Start: nil, Limit: nil}})
ensure.Nil(t, err)
ensure.DeepEqual(t, sizes, []uint64{0})

// valid range
sizes = db.GetApproximateSizesCF(cf, []Range{{Start: []byte{0x00}, Limit: []byte{0xFF}}})
sizes, err = db.GetApproximateSizesCF(cf, []Range{{Start: []byte{0x00}, Limit: []byte{0xFF}}})
ensure.Nil(t, err)
ensure.DeepEqual(t, sizes, []uint64{0})
}

0 comments on commit bb72fba

Please sign in to comment.