rocksdb icon indicating copy to clipboard operation
rocksdb copied to clipboard

How can I get the default CF_handle by C API?

Open 979357361 opened this issue 1 year ago • 2 comments

I use RocksDB in C. Now I need to multi_get a list of keys, there are two C API: rocksdb_multi_get and rocksdb_batched_multi_get_cf, notes tell that the later has performance improvement, but it need a cf arg<rocksdb_colume_family_handle_t> and this can not be NULL, as I only use the default cf, I can't find any API to get the default cf handle, more important, other C APIs I use are all no-cf arg, change them to cf-version is troublesome.

How can I get the CF_handle of default cf by C API? thanks!

979357361 avatar Jan 31 '24 09:01 979357361

In C++, there is a straightforward API DB::DefaultColumnFamily for this, but there is no counterpart API in C. https://github.com/facebook/rocksdb/blob/046ac91a7f887b1c1a970a7a950dd1e1689189e0/include/rocksdb/db.h#L1927

A workaround would be to use this rocksdb_open_column_families API to open the DB https://github.com/facebook/rocksdb/blob/046ac91a7f887b1c1a970a7a950dd1e1689189e0/db/c.cc#L915-L919

Passing the column_family_handles output argument to get a handle for the default column family to keep for your own use.

jowlyzhang avatar Feb 02 '24 19:02 jowlyzhang

Maybe we should add a C API to easy get the default CF_handle, as C API with "_cf" ending is hard to use and most time the default CF is enough, but "rocksdb_batched_multi_get_cf" must have it.

Later I will make a submit to add the C API, the code is straightforward.

979357361 avatar Apr 03 '24 07:04 979357361