Extend C API to expose base db of transaction db (#11562)

Summary:
Add `rocksdb_transactiondb_get_base_db` and `rocksdb_transactiondb_close_base_db` functions to the C API modeled after `rocksdb_optimistictransactiondb_get_base_db` and `rocksdb_optimistictransactiondb_close_base_db`:
ca50ccc71a/include/rocksdb/c.h (L2711-L2716)

With this pair of functions, it is possible to get a `rocksdb_t *` from a `rocksdb_transactiondb_t *`. The main goal is to be able to use the approximate memory usage API, only accessible to the `rocksdb_t *` type:
ca50ccc71a/include/rocksdb/c.h (L2821-L2833)

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

Reviewed By: ajkr

Differential Revision: D47603343

Pulled By: jowlyzhang

fbshipit-source-id: c70cf6af5834026e232fe7791634db3a396f7d5e
oxigraph-main
Rémi Calixte 1 year ago committed by Facebook GitHub Bot
parent 86634885eb
commit 6628ff12d6
  1. 17
      db/c.cc
  2. 11
      db/c_test.c
  3. 6
      include/rocksdb/c.h

@ -5623,6 +5623,23 @@ int rocksdb_transactiondb_property_int(rocksdb_transactiondb_t* db,
} }
} }
rocksdb_t* rocksdb_transactiondb_get_base_db(
rocksdb_transactiondb_t* txn_db) {
DB* base_db = txn_db->rep->GetBaseDB();
if (base_db != nullptr) {
rocksdb_t* result = new rocksdb_t;
result->rep = base_db;
return result;
}
return nullptr;
}
void rocksdb_transactiondb_close_base_db(rocksdb_t* base_db) {
delete base_db;
}
rocksdb_transaction_t* rocksdb_transaction_begin( rocksdb_transaction_t* rocksdb_transaction_begin(
rocksdb_transactiondb_t* txn_db, rocksdb_transactiondb_t* txn_db,
const rocksdb_writeoptions_t* write_options, const rocksdb_writeoptions_t* write_options,

@ -3122,6 +3122,17 @@ int main(int argc, char** argv) {
CheckTxnDBGetCF(txn_db, roptions, cfh, "cf_foo", NULL); CheckTxnDBGetCF(txn_db, roptions, cfh, "cf_foo", NULL);
CheckTxnDBPinGetCF(txn_db, roptions, cfh, "cf_foo", NULL); CheckTxnDBPinGetCF(txn_db, roptions, cfh, "cf_foo", NULL);
//memory usage
rocksdb_t* base_db = rocksdb_transactiondb_get_base_db(txn_db);
rocksdb_memory_consumers_t* consumers = rocksdb_memory_consumers_create();
rocksdb_memory_consumers_add_db(consumers, base_db);
rocksdb_memory_usage_t* usage = rocksdb_approximate_memory_usage_create(consumers, &err);
CheckNoError(err);
rocksdb_approximate_memory_usage_destroy(usage);
rocksdb_memory_consumers_destroy(consumers);
rocksdb_transactiondb_close_base_db(base_db);
// flush // flush
rocksdb_flushoptions_t* flush_options = rocksdb_flushoptions_create(); rocksdb_flushoptions_t* flush_options = rocksdb_flushoptions_create();
rocksdb_flushoptions_set_wait(flush_options, 1); rocksdb_flushoptions_set_wait(flush_options, 1);

@ -2457,6 +2457,12 @@ extern ROCKSDB_LIBRARY_API char* rocksdb_transactiondb_property_value(
extern ROCKSDB_LIBRARY_API int rocksdb_transactiondb_property_int( extern ROCKSDB_LIBRARY_API int rocksdb_transactiondb_property_int(
rocksdb_transactiondb_t* db, const char* propname, uint64_t* out_val); rocksdb_transactiondb_t* db, const char* propname, uint64_t* out_val);
extern ROCKSDB_LIBRARY_API rocksdb_t* rocksdb_transactiondb_get_base_db(
rocksdb_transactiondb_t* txn_db);
extern ROCKSDB_LIBRARY_API void rocksdb_transactiondb_close_base_db(
rocksdb_t* base_db);
extern ROCKSDB_LIBRARY_API rocksdb_transaction_t* rocksdb_transaction_begin( extern ROCKSDB_LIBRARY_API rocksdb_transaction_t* rocksdb_transaction_begin(
rocksdb_transactiondb_t* txn_db, rocksdb_transactiondb_t* txn_db,
const rocksdb_writeoptions_t* write_options, const rocksdb_writeoptions_t* write_options,

Loading…
Cancel
Save