1

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?

MyStackRunnethOver
  • 4,872
  • 2
  • 28
  • 42

1 Answers1

1

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.

amirouche
  • 7,682
  • 6
  • 40
  • 94
  • Thanks! Can you clarify: do the two `Slice`'s passed to `Range` act as prefixes for the `Range` lookup? Or do they fully define the start and end key? E.g. for set `[A, AA, B, BA]`, does `Range(A, B)` return `[A, AA, B]` or `[A, AA, B, BA]`? – MyStackRunnethOver Sep 27 '21 at 13:19
  • If the prefix is `ABC` you must call `range(ABC, strinc(ABC))` it describe the range `[ABC, strinc(ABC)[` that is `strinc(ABC)` is excluded from the range because `strinc(ABC)` does not start with ABC. – amirouche Sep 28 '21 at 14:40
  • Does it makes sense? – amirouche Sep 28 '21 at 14:40
  • I assume by `Slice` you mean a string of bytes, then I think you go it. Except a range is a range, from point A to point B. `strinc(ABC)` will compute the immediatly next byte string that is not prefix of `ABC`. So `Range(ABC, strinc(ABC))` describe the range of key that starts with / have the prefix `ABC`. – amirouche Sep 29 '21 at 19:23
  • `Range(0x0A, 0x0B)` will return `0x0A, 0x0A00, 0x0A01, .... 0x0AFFFFFF...` possibly it will also return the end key `0x0B` but not further down the keyspace (no 0x0B00 or 0x0B01...) – amirouche Sep 29 '21 at 19:27
  • @MyStackRunnethOver please mark my answer as good answer if it is the case. If there is something unclear I can expand the answer. I can also elaborate why `strinc` helps to retrieve a range of key that starts with a given prefix? – amirouche Sep 30 '21 at 06:24
  • 1
    Nope your clarification of how Range's arguments work cleared it up for me! Thanks for the answer :) – MyStackRunnethOver Oct 01 '21 at 14:01