RocksDb Java API support for Transactions

581 Views Asked by At

Does RocksJavaAPI have the support for transactions? I see that there is a Transaction DB class present in the JAR. I am not able to do a begin transaction on transaction Db class.

RocksDB db = TransactionDB.open(options, "/Users/jagannathan/Desktop/My Files/db/rocksdb")

I am not able to do db.beginTransaction as such methods are not available. Any pointers on how to accomplish in Java are appreciated.

1

There are 1 best solutions below

0
On BEST ANSWER

You need to use a different open method. You currently use the open method of the base class (RocksDB).

Use either:

public static TransactionDB open(Options options,
                 TransactionDBOptions transactionDbOptions,
                 java.lang.String path)

or

public static TransactionDB open(DBOptions dbOptions,
                 TransactionDBOptions transactionDbOptions,
                 java.lang.String path,
                 java.util.List<ColumnFamilyDescriptor> columnFamilyDescriptors,
                 java.util.List<ColumnFamilyHandle> columnFamilyHandles)

To get a TransactionDB object. This object you can then use to call #beginTransaction, which will return an Transaction object. This transaction can then be used similar to a RocksDB, where you can put, delete etc. and commit if you're done.