Skip to content

Commit e6182c2

Browse files
committed
Address PR comments.
1 parent 0c2d57b commit e6182c2

2 files changed

Lines changed: 74 additions & 11 deletions

File tree

db/c_test.c

Lines changed: 53 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1703,23 +1703,65 @@ int main(int argc, char** argv) {
17031703
db = rocksdb_open(db_options, dbname, &err);
17041704
CheckNoError(err);
17051705

1706-
char** list_const_cf_names = (char**)malloc(2 * sizeof(char*));
1707-
list_const_cf_names[0] = "cf_with_options";
1708-
list_const_cf_names[1] = "cf_with_option";
1706+
char** cf_names = (char**)malloc(2 * sizeof(char*));
1707+
cf_names[0] = "cf1";
1708+
cf_names[1] = "cf2";
17091709
size_t cflen;
1710-
const rocksdb_options_t* create_cf_options[2] = {db_options, db_options};
1711-
rocksdb_column_family_handle_t** new_column_family_handle =
1710+
1711+
rocksdb_options_t* cf1_options = rocksdb_options_create();
1712+
rocksdb_options_set_paranoid_checks(cf1_options, true);
1713+
rocksdb_options_set_create_if_missing(cf1_options, true);
1714+
1715+
rocksdb_options_t* cf2_options = rocksdb_options_create();
1716+
rocksdb_options_set_max_bytes_for_level_base(cf2_options, 4 * 1024);
1717+
rocksdb_options_set_create_if_missing(cf2_options, true);
1718+
1719+
const rocksdb_options_t* cf_options[2] = {cf1_options, cf2_options};
1720+
rocksdb_column_family_handle_t** column_family_handle =
17121721
rocksdb_create_column_families_with_options(
1713-
db, 2, (const char* const*)list_const_cf_names, create_cf_options,
1714-
&cflen, &err);
1715-
free(list_const_cf_names);
1722+
db, 2, (const char* const*)cf_names, cf_options, &cflen, &err);
1723+
free(cf_names);
17161724
CheckNoError(err);
17171725
assert(cflen == 2);
17181726

1719-
rocksdb_column_family_handle_destroy(new_column_family_handle[0]);
1720-
rocksdb_column_family_handle_destroy(new_column_family_handle[1]);
1727+
rocksdb_writeoptions_t* write_options = rocksdb_writeoptions_create();
1728+
1729+
rocksdb_put_cf(db, write_options, column_family_handle[0], "cf1", 3, "val1",
1730+
4, &err);
1731+
CheckNoError(err);
1732+
1733+
rocksdb_put_cf(db, write_options, column_family_handle[1], "cf2", 3, "val2",
1734+
4, &err);
1735+
CheckNoError(err);
1736+
1737+
rocksdb_writeoptions_destroy(write_options);
1738+
1739+
size_t val_len;
1740+
1741+
rocksdb_readoptions_t* read_options = rocksdb_readoptions_create();
1742+
1743+
char* value1 = rocksdb_get_cf(db, read_options, column_family_handle[0],
1744+
"cf1", 3, &val_len, &err);
1745+
CheckNoError(err);
1746+
CheckEqual("val1", value1, val_len);
1747+
Free(&value1);
1748+
1749+
char* value2 = rocksdb_get_cf(db, read_options, column_family_handle[1],
1750+
"cf2", 3, &val_len, &err);
1751+
CheckNoError(err);
1752+
CheckEqual("val2", value2, val_len);
1753+
Free(&value2);
1754+
1755+
rocksdb_readoptions_destroy(read_options);
1756+
1757+
rocksdb_column_family_handle_destroy(column_family_handle[0]);
1758+
rocksdb_column_family_handle_destroy(column_family_handle[1]);
1759+
1760+
rocksdb_create_column_families_destroy(column_family_handle);
1761+
1762+
rocksdb_options_destroy(cf1_options);
1763+
rocksdb_options_destroy(cf2_options);
17211764

1722-
rocksdb_create_column_families_destroy(new_column_family_handle);
17231765
rocksdb_options_destroy(db_options);
17241766
}
17251767

include/rocksdb/c.h

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -434,6 +434,27 @@ rocksdb_create_column_families(rocksdb_t* db,
434434
const char* const* column_family_names,
435435
size_t* lencfs, char** errptr);
436436

437+
/**
438+
* @brief Creates multiple column families in the specified RocksDB database
439+
* with the given options for each column family.
440+
*
441+
* @param db A pointer to the RocksDB database instance.
442+
* @param num_column_families The number of column families to create.
443+
* @param column_family_names An array of null-terminated strings, each
444+
* representing the name of a column family to create.
445+
* @param column_family_options An array of pointers to rocksdb_options_t
446+
* structures, each specifying the options for the corresponding column family.
447+
* @param lencfs A pointer to a size_t variable where the length of the created
448+
* column families will be stored.
449+
* @param errptr A pointer to a char pointer. If an error occurs, a descriptive
450+
* error message will be stored in the memory pointed to by errptr. The caller
451+
* must free this memory using rocksdb_free when it is no longer needed.
452+
*
453+
* @return An array of pointers to rocksdb_column_family_handle_t structures,
454+
* each representing a handle to the created column families. The length of this
455+
* array is stored in the variable pointed to by lencfs. If an error occurs,
456+
* NULL is returned and errptr is set to a descriptive error message.
457+
*/
437458
extern ROCKSDB_LIBRARY_API rocksdb_column_family_handle_t**
438459
rocksdb_create_column_families_with_options(
439460
rocksdb_t* db, int num_column_families,

0 commit comments

Comments
 (0)