How do I specify a Range including everything in a RocksDB column?

Viewed 269

I want to publish metrics about my RocksDB instance, including the disk size of each column over time. I've come across a likely API method to calculate disk size for a column:

GetApproximateSizes():

Status s = GetApproximateSizes(options, column_family, ranges.data(), NUM_RANGES, sizes.data());

This is a nice API, but I don't know how to provide a Range that will specify my entire column. Is there a way to do so without finding the min/max key in the column?

1 Answers

For the whole database, you can approximate it using 0x00 or the empty byte string and an arbitrarily big key as end such as 0xFFFFFF.

Otherwise, if the column share a common prefix, use the following function to compute the end key:

def strinc(key):
    key = key.rstrip(b"\xff")
    return key[:-1] + int2byte(ord(key[-1:]) + 1)

strinc will compute the next byte string that is not prefix of key, together they describe the whole keyspace having KEY as prefix.

Related