Expose rocksdb_open_column_families_with_ttl C function (#7314)

Summary:
This PR creates `rocksdb_open_column_families_with_ttl` which allows C API users to open a DBWithTLL with column families.

Pull Request resolved: https://github.com/facebook/rocksdb/pull/7314

Reviewed By: cheng-chang

Differential Revision: D23430287

Pulled By: ajkr

fbshipit-source-id: 307aa21d170d1402653263a91f6f832ef76afba0
main
Eduardo Barreto Alexandre 4 years ago committed by Facebook GitHub Bot
parent d0c1a01c1b
commit 5b1ccdc191
  1. 47
      db/c.cc
  2. 12
      include/rocksdb/c.h

@ -707,6 +707,41 @@ rocksdb_t* rocksdb_open_column_families(
return result; return result;
} }
rocksdb_t* rocksdb_open_column_families_with_ttl(
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, const int* ttls,
char** errptr) {
std::vector<int32_t> ttls_vec;
std::vector<ColumnFamilyDescriptor> column_families;
for (int i = 0; i < num_column_families; i++) {
ttls_vec.push_back(ttls[i]);
column_families.push_back(ColumnFamilyDescriptor(
std::string(column_family_names[i]),
ColumnFamilyOptions(column_family_options[i]->rep)));
}
ROCKSDB_NAMESPACE::DBWithTTL* db;
std::vector<ColumnFamilyHandle*> handles;
if (SaveError(errptr, ROCKSDB_NAMESPACE::DBWithTTL::Open(
DBOptions(db_options->rep), std::string(name),
column_families, &handles, &db, ttls_vec))) {
return nullptr;
}
for (size_t i = 0; i < handles.size(); i++) {
rocksdb_column_family_handle_t* c_handle =
new rocksdb_column_family_handle_t;
c_handle->rep = handles[i];
column_family_handles[i] = c_handle;
}
rocksdb_t* result = new rocksdb_t;
result->rep = db;
return result;
}
rocksdb_t* rocksdb_open_for_read_only_column_families( rocksdb_t* rocksdb_open_for_read_only_column_families(
const rocksdb_options_t* db_options, const char* name, const rocksdb_options_t* db_options, const char* name,
int num_column_families, const char* const* column_family_names, int num_column_families, const char* const* column_family_names,
@ -805,6 +840,18 @@ rocksdb_column_family_handle_t* rocksdb_create_column_family(
return handle; return handle;
} }
rocksdb_column_family_handle_t* rocksdb_create_column_family_with_ttl(
rocksdb_t* db, const rocksdb_options_t* column_family_options,
const char* column_family_name, int ttl, char** errptr) {
ROCKSDB_NAMESPACE::DBWithTTL* db_with_ttl =
static_cast<ROCKSDB_NAMESPACE::DBWithTTL*>(db->rep);
rocksdb_column_family_handle_t* handle = new rocksdb_column_family_handle_t;
SaveError(errptr, db_with_ttl->CreateColumnFamilyWithTtl(
ColumnFamilyOptions(column_family_options->rep),
std::string(column_family_name), &(handle->rep), ttl));
return handle;
}
void rocksdb_drop_column_family( void rocksdb_drop_column_family(
rocksdb_t* db, rocksdb_t* db,
rocksdb_column_family_handle_t* handle, rocksdb_column_family_handle_t* handle,

@ -219,6 +219,13 @@ extern ROCKSDB_LIBRARY_API rocksdb_t* rocksdb_open_column_families(
const rocksdb_options_t* const* column_family_options, const rocksdb_options_t* const* column_family_options,
rocksdb_column_family_handle_t** column_family_handles, char** errptr); rocksdb_column_family_handle_t** column_family_handles, char** errptr);
extern ROCKSDB_LIBRARY_API rocksdb_t* rocksdb_open_column_families_with_ttl(
const rocksdb_options_t* 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, const int* ttls,
char** errptr);
extern ROCKSDB_LIBRARY_API rocksdb_t* extern ROCKSDB_LIBRARY_API rocksdb_t*
rocksdb_open_for_read_only_column_families( rocksdb_open_for_read_only_column_families(
const rocksdb_options_t* options, const char* name, int num_column_families, const rocksdb_options_t* options, const char* name, int num_column_families,
@ -246,6 +253,11 @@ rocksdb_create_column_family(rocksdb_t* db,
const rocksdb_options_t* column_family_options, const rocksdb_options_t* column_family_options,
const char* column_family_name, char** errptr); const char* column_family_name, char** errptr);
extern ROCKSDB_LIBRARY_API rocksdb_column_family_handle_t*
rocksdb_create_column_family_with_ttl(
rocksdb_t* db, const rocksdb_options_t* column_family_options,
const char* column_family_name, int ttl, char** errptr);
extern ROCKSDB_LIBRARY_API void rocksdb_drop_column_family( extern ROCKSDB_LIBRARY_API void rocksdb_drop_column_family(
rocksdb_t* db, rocksdb_column_family_handle_t* handle, char** errptr); rocksdb_t* db, rocksdb_column_family_handle_t* handle, char** errptr);

Loading…
Cancel
Save