mirror of https://github.com/facebook/rocksdb.git
add c-api to get default cf handle (#12514)
Summary: rocksdb_batched_multi_get_cf has performance improvement than normal multi_get, however it needs a cf_handle arg, so add a C-API to get and destroy the default cf_handle, as many user only use the default cf. Fixes https://github.com/facebook/rocksdb/issues/12316 Pull Request resolved: https://github.com/facebook/rocksdb/pull/12514 Reviewed By: hx235 Differential Revision: D55922517 Pulled By: ajkr fbshipit-source-id: c4cc4289f2cfd9efbb8f390a44a9d8d1ed08d9f0
This commit is contained in:
parent
b9e82f5162
commit
21a16f9e64
24
db/c.cc
24
db/c.cc
|
@ -231,6 +231,7 @@ struct rocksdb_livefiles_t {
|
|||
};
|
||||
struct rocksdb_column_family_handle_t {
|
||||
ColumnFamilyHandle* rep;
|
||||
bool immortal; /* only true for default cf */
|
||||
};
|
||||
struct rocksdb_column_family_metadata_t {
|
||||
ColumnFamilyMetaData rep;
|
||||
|
@ -906,6 +907,7 @@ rocksdb_t* rocksdb_open_and_trim_history(
|
|||
rocksdb_column_family_handle_t* c_handle =
|
||||
new rocksdb_column_family_handle_t;
|
||||
c_handle->rep = handles[i];
|
||||
c_handle->immortal = false;
|
||||
column_family_handles[i] = c_handle;
|
||||
}
|
||||
rocksdb_t* result = new rocksdb_t;
|
||||
|
@ -936,6 +938,7 @@ rocksdb_t* rocksdb_open_column_families(
|
|||
rocksdb_column_family_handle_t* c_handle =
|
||||
new rocksdb_column_family_handle_t;
|
||||
c_handle->rep = handles[i];
|
||||
c_handle->immortal = false;
|
||||
column_family_handles[i] = c_handle;
|
||||
}
|
||||
rocksdb_t* result = new rocksdb_t;
|
||||
|
@ -971,6 +974,7 @@ rocksdb_t* rocksdb_open_column_families_with_ttl(
|
|||
rocksdb_column_family_handle_t* c_handle =
|
||||
new rocksdb_column_family_handle_t;
|
||||
c_handle->rep = handles[i];
|
||||
c_handle->immortal = false;
|
||||
column_family_handles[i] = c_handle;
|
||||
}
|
||||
rocksdb_t* result = new rocksdb_t;
|
||||
|
@ -1004,6 +1008,7 @@ rocksdb_t* rocksdb_open_for_read_only_column_families(
|
|||
rocksdb_column_family_handle_t* c_handle =
|
||||
new rocksdb_column_family_handle_t;
|
||||
c_handle->rep = handles[i];
|
||||
c_handle->immortal = false;
|
||||
column_family_handles[i] = c_handle;
|
||||
}
|
||||
rocksdb_t* result = new rocksdb_t;
|
||||
|
@ -1035,6 +1040,7 @@ rocksdb_t* rocksdb_open_as_secondary_column_families(
|
|||
rocksdb_column_family_handle_t* c_handle =
|
||||
new rocksdb_column_family_handle_t;
|
||||
c_handle->rep = handles[i];
|
||||
c_handle->immortal = false;
|
||||
column_family_handles[i] = c_handle;
|
||||
}
|
||||
rocksdb_t* result = new rocksdb_t;
|
||||
|
@ -1072,6 +1078,7 @@ rocksdb_column_family_handle_t* rocksdb_create_column_family(
|
|||
SaveError(errptr, db->rep->CreateColumnFamily(
|
||||
ColumnFamilyOptions(column_family_options->rep),
|
||||
std::string(column_family_name), &(handle->rep)));
|
||||
handle->immortal = false;
|
||||
return handle;
|
||||
}
|
||||
|
||||
|
@ -1095,6 +1102,7 @@ rocksdb_column_family_handle_t** rocksdb_create_column_families(
|
|||
for (size_t i = 0; i != handles.size(); ++i) {
|
||||
c_handles[i] = new rocksdb_column_family_handle_t;
|
||||
c_handles[i]->rep = handles[i];
|
||||
c_handles[i]->immortal = false;
|
||||
}
|
||||
|
||||
return c_handles;
|
||||
|
@ -1114,6 +1122,7 @@ rocksdb_column_family_handle_t* rocksdb_create_column_family_with_ttl(
|
|||
SaveError(errptr, db_with_ttl->CreateColumnFamilyWithTtl(
|
||||
ColumnFamilyOptions(column_family_options->rep),
|
||||
std::string(column_family_name), &(handle->rep), ttl));
|
||||
handle->immortal = false;
|
||||
return handle;
|
||||
}
|
||||
|
||||
|
@ -1135,9 +1144,19 @@ char* rocksdb_column_family_handle_get_name(
|
|||
return CopyString(name);
|
||||
}
|
||||
|
||||
rocksdb_column_family_handle_t* rocksdb_get_default_column_family_handle(
|
||||
rocksdb_t* db) {
|
||||
rocksdb_column_family_handle_t* handle = new rocksdb_column_family_handle_t;
|
||||
handle->rep = db->rep->DefaultColumnFamily();
|
||||
handle->immortal = true;
|
||||
return handle;
|
||||
}
|
||||
|
||||
void rocksdb_column_family_handle_destroy(
|
||||
rocksdb_column_family_handle_t* handle) {
|
||||
delete handle->rep;
|
||||
if (!handle->immortal) {
|
||||
delete handle->rep;
|
||||
}
|
||||
delete handle;
|
||||
}
|
||||
|
||||
|
@ -5789,6 +5808,7 @@ rocksdb_column_family_handle_t* rocksdb_transactiondb_create_column_family(
|
|||
SaveError(errptr, txn_db->rep->CreateColumnFamily(
|
||||
ColumnFamilyOptions(column_family_options->rep),
|
||||
std::string(column_family_name), &(handle->rep)));
|
||||
handle->immortal = false;
|
||||
return handle;
|
||||
}
|
||||
|
||||
|
@ -5831,6 +5851,7 @@ rocksdb_transactiondb_t* rocksdb_transactiondb_open_column_families(
|
|||
rocksdb_column_family_handle_t* c_handle =
|
||||
new rocksdb_column_family_handle_t;
|
||||
c_handle->rep = handles[i];
|
||||
c_handle->immortal = false;
|
||||
column_family_handles[i] = c_handle;
|
||||
}
|
||||
rocksdb_transactiondb_t* result = new rocksdb_transactiondb_t;
|
||||
|
@ -6625,6 +6646,7 @@ rocksdb_optimistictransactiondb_open_column_families(
|
|||
rocksdb_column_family_handle_t* c_handle =
|
||||
new rocksdb_column_family_handle_t;
|
||||
c_handle->rep = handles[i];
|
||||
c_handle->immortal = false;
|
||||
column_family_handles[i] = c_handle;
|
||||
}
|
||||
rocksdb_optimistictransactiondb_t* result =
|
||||
|
|
|
@ -434,6 +434,9 @@ rocksdb_create_column_family_with_ttl(
|
|||
extern ROCKSDB_LIBRARY_API void rocksdb_drop_column_family(
|
||||
rocksdb_t* db, rocksdb_column_family_handle_t* handle, char** errptr);
|
||||
|
||||
extern ROCKSDB_LIBRARY_API rocksdb_column_family_handle_t*
|
||||
rocksdb_get_default_column_family_handle(rocksdb_t* db);
|
||||
|
||||
extern ROCKSDB_LIBRARY_API void rocksdb_column_family_handle_destroy(
|
||||
rocksdb_column_family_handle_t*);
|
||||
|
||||
|
|
Loading…
Reference in New Issue