Using 'functional' comparator to index RocksDB Java classes instead of raw byte array.

47 views
Skip to first unread message

Alexandr Soldiernetizen

unread,
Sep 28, 2022, 1:17:08 AM9/28/22
to rocksdb
I have a demo of using serialized first class Java objects as indexes for RocksDB in GitHub; github.com/neocoretechs/RockSack.

I filled out the contributor form if anyone wants it for examples. 

The RocksDBSample.java from examples in main distro is modified there to demonstrate. It was really just a matter of adding the comparator class derived from org.rocksdb.AbstractComparator, overriding the compare method, and setting that class in the Options.

The heart of the compare method involves deserializing the ByteBuffers for the 2 keys under scrutiny, then calling the compareTo method of the first instance upon the second instance in the derived AbstractComparator.compare method.

The assumption is that classes for indexing implement the java.lang.Comparable.compareTo method, which most do by default, including String.

For each end-user key access operation, deserialize the byte array that was retrieved by RocksDB as shown in the example.

I have built the only (as far as I know) 'functional' database in Java called the 'Relatrix' using my own key/value store and am hoping to replace that with RocksDB. The critical element is having the ability to have a 'functional' index provided by class methods instead of raw byte values.
Reply all
Reply to author
Forward
0 new messages