Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How can I get the default CF_handle by C API? #12316

Open
979357361 opened this issue Jan 31, 2024 · 2 comments · May be fixed by #12514
Open

How can I get the default CF_handle by C API? #12316

979357361 opened this issue Jan 31, 2024 · 2 comments · May be fixed by #12514

Comments

@979357361
Copy link

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!

@jowlyzhang
Copy link
Contributor

In C++, there is a straightforward API DB::DefaultColumnFamily for this, but there is no counterpart API in C.

virtual ColumnFamilyHandle* DefaultColumnFamily() const = 0;

A workaround would be to use this rocksdb_open_column_families API to open the DB

rocksdb/db/c.cc

Lines 915 to 919 in 046ac91

rocksdb_t* rocksdb_open_column_families(
const rocksdb_options_t* db_options, const char* name,
int num_column_families, const char* const* column_family_names,
const rocksdb_options_t* const* column_family_options,
rocksdb_column_family_handle_t** column_family_handles, char** errptr) {

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

@979357361
Copy link
Author

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.

@ajkr ajkr linked a pull request Apr 9, 2024 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants