Skip to content

Commit

Permalink
Address PR comments.
Browse files Browse the repository at this point in the history
  • Loading branch information
rhubner committed Aug 5, 2024
1 parent 00a1c6a commit e134e79
Show file tree
Hide file tree
Showing 2 changed files with 74 additions and 11 deletions.
64 changes: 53 additions & 11 deletions db/c_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -1634,23 +1634,65 @@ int main(int argc, char** argv) {
db = rocksdb_open(db_options, dbname, &err);
CheckNoError(err);

char** list_const_cf_names = (char**)malloc(2 * sizeof(char*));
list_const_cf_names[0] = "cf_with_options";
list_const_cf_names[1] = "cf_with_option";
char** cf_names = (char**)malloc(2 * sizeof(char*));
cf_names[0] = "cf1";
cf_names[1] = "cf2";
size_t cflen;
const rocksdb_options_t* create_cf_options[2] = {db_options, db_options};
rocksdb_column_family_handle_t** new_column_family_handle =

rocksdb_options_t* cf1_options = rocksdb_options_create();
rocksdb_options_set_paranoid_checks(cf1_options, true);
rocksdb_options_set_create_if_missing(cf1_options, true);

rocksdb_options_t* cf2_options = rocksdb_options_create();
rocksdb_options_set_max_bytes_for_level_base(cf2_options, 4 * 1024);
rocksdb_options_set_create_if_missing(cf2_options, true);

const rocksdb_options_t* cf_options[2] = {cf1_options, cf2_options};
rocksdb_column_family_handle_t** column_family_handle =
rocksdb_create_column_families_with_options(
db, 2, (const char* const*)list_const_cf_names, create_cf_options,
&cflen, &err);
free(list_const_cf_names);
db, 2, (const char* const*)cf_names, cf_options, &cflen, &err);
free(cf_names);
CheckNoError(err);
assert(cflen == 2);

rocksdb_column_family_handle_destroy(new_column_family_handle[0]);
rocksdb_column_family_handle_destroy(new_column_family_handle[1]);
rocksdb_writeoptions_t* write_options = rocksdb_writeoptions_create();

rocksdb_put_cf(db, write_options, column_family_handle[0], "cf1", 3, "val1",
4, &err);
CheckNoError(err);

rocksdb_put_cf(db, write_options, column_family_handle[1], "cf2", 3, "val2",
4, &err);
CheckNoError(err);

rocksdb_writeoptions_destroy(write_options);

size_t val_len;

rocksdb_readoptions_t* read_options = rocksdb_readoptions_create();

char* value1 = rocksdb_get_cf(db, read_options, column_family_handle[0],
"cf1", 3, &val_len, &err);
CheckNoError(err);
CheckEqual("val1", value1, val_len);
Free(&value1);

char* value2 = rocksdb_get_cf(db, read_options, column_family_handle[1],
"cf2", 3, &val_len, &err);
CheckNoError(err);
CheckEqual("val2", value2, val_len);
Free(&value2);

rocksdb_readoptions_destroy(read_options);

rocksdb_column_family_handle_destroy(column_family_handle[0]);
rocksdb_column_family_handle_destroy(column_family_handle[1]);

rocksdb_create_column_families_destroy(column_family_handle);

rocksdb_options_destroy(cf1_options);
rocksdb_options_destroy(cf2_options);

rocksdb_create_column_families_destroy(new_column_family_handle);
rocksdb_options_destroy(db_options);
}

Expand Down
21 changes: 21 additions & 0 deletions include/rocksdb/c.h
Original file line number Diff line number Diff line change
Expand Up @@ -423,6 +423,27 @@ rocksdb_create_column_families(rocksdb_t* db,
const char* const* column_family_names,
size_t* lencfs, char** errptr);

/**
* @brief Creates multiple column families in the specified RocksDB database
* with the given options for each column family.
*
* @param db A pointer to the RocksDB database instance.
* @param num_column_families The number of column families to create.
* @param column_family_names An array of null-terminated strings, each
* representing the name of a column family to create.
* @param column_family_options An array of pointers to rocksdb_options_t
* structures, each specifying the options for the corresponding column family.
* @param lencfs A pointer to a size_t variable where the length of the created
* column families will be stored.
* @param errptr A pointer to a char pointer. If an error occurs, a descriptive
* error message will be stored in the memory pointed to by errptr. The caller
* must free this memory using rocksdb_free when it is no longer needed.
*
* @return An array of pointers to rocksdb_column_family_handle_t structures,
* each representing a handle to the created column families. The length of this
* array is stored in the variable pointed to by lencfs. If an error occurs,
* NULL is returned and errptr is set to a descriptive error message.
*/
extern ROCKSDB_LIBRARY_API rocksdb_column_family_handle_t**
rocksdb_create_column_families_with_options(
rocksdb_t* db, int num_column_families,
Expand Down

0 comments on commit e134e79

Please sign in to comment.