Skip to content

Commit

Permalink
Export DB properties
Browse files Browse the repository at this point in the history
  • Loading branch information
aalda committed Apr 5, 2019
1 parent f72e430 commit 9178532
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 1 deletion.
39 changes: 38 additions & 1 deletion rocksdb/db.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@

package rocksdb

// #include <rocksdb/c.h>
// #include "rocksdb/c.h"
// #include "extended.h"
// #include <stdlib.h>
import "C"
import (
Expand Down Expand Up @@ -377,3 +378,39 @@ func (db *DB) Flush(fo *FlushOptions) error {
}
return nil
}

// GetProperty returns the value of a database property.
func (db *DB) GetProperty(propName string) string {
cProp := C.CString(propName)
defer C.free(unsafe.Pointer(cProp))
cValue := C.rocksdb_property_value(db.c, cProp)
defer C.free(unsafe.Pointer(cValue))
return C.GoString(cValue)
}

// GetPropertyCF returns the value of a database property.
func (db *DB) GetPropertyCF(propName string, cf *ColumnFamilyHandle) string {
cProp := C.CString(propName)
defer C.free(unsafe.Pointer(cProp))
cValue := C.rocksdb_property_value_cf(db.c, cf.c, cProp)
defer C.free(unsafe.Pointer(cValue))
return C.GoString(cValue)
}

// GetUint64Property returns the value of a database property.
func (db *DB) GetUint64Property(propName string) uint64 {
cProp := C.CString(propName)
defer C.free(unsafe.Pointer(cProp))
var cValue C.uint64_t
C.rocksdb_property_int(db.c, cProp, &cValue)
return uint64(cValue)
}

// GetUint64PropertyCF returns the value of a database property.
func (db *DB) GetUint64PropertyCF(propName string, cf *ColumnFamilyHandle) uint64 {
cProp := C.CString(propName)
defer C.free(unsafe.Pointer(cProp))
var cValue C.uint64_t
C.rocksdb_property_int_cf(db.c, cf.c, cProp, &cValue)
return uint64(cValue)
}
17 changes: 17 additions & 0 deletions rocksdb/extended.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,23 +17,30 @@
#include "extended.h"

#include "rocksdb/c.h"
//#include "rocksdb/slice.h"
#include "rocksdb/db.h"
#include "rocksdb/statistics.h"
#include "rocksdb/options.h"

using rocksdb::DB;
using rocksdb::ColumnFamilyHandle;
using rocksdb::Statistics;
using rocksdb::HistogramData;
using rocksdb::StatsLevel;
using rocksdb::Options;
using rocksdb::Cache;
using rocksdb::NewLRUCache;
using rocksdb::Slice;
using std::shared_ptr;

extern "C" {

struct rocksdb_t { DB* rep; };
struct rocksdb_statistics_t { std::shared_ptr<Statistics> rep; };
struct rocksdb_histogram_data_t { rocksdb::HistogramData* rep; };
struct rocksdb_options_t { Options rep; };
struct rocksdb_cache_t { std::shared_ptr<Cache> rep; };
struct rocksdb_column_family_handle_t { ColumnFamilyHandle* rep; };

void rocksdb_options_set_atomic_flush(
rocksdb_options_t* opts, unsigned char value) {
Expand All @@ -53,6 +60,16 @@ rocksdb_statistics_t* rocksdb_create_statistics() {
return result;
}

int rocksdb_property_int_cf(
rocksdb_t* db, rocksdb_column_family_handle_t* column_family,
const char* propname, uint64_t *out_val) {
if (db->rep->GetIntProperty(column_family->rep, Slice(propname), out_val)) {
return 0;
} else {
return -1;
}
}

void rocksdb_options_set_statistics(
rocksdb_options_t* opts,
rocksdb_statistics_t* stats) {
Expand Down
5 changes: 5 additions & 0 deletions rocksdb/extended.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,11 @@ typedef struct rocksdb_histogram_data_t rocksdb_histogram_data_t;

extern rocksdb_statistics_t* rocksdb_create_statistics();

/* returns 0 on success, -1 otherwise */
extern int rocksdb_property_int_cf(
rocksdb_t* db, rocksdb_column_family_handle_t* column_family,
const char* propname, uint64_t *out_val);

/* Options */

extern void rocksdb_options_set_atomic_flush(
Expand Down

0 comments on commit 9178532

Please sign in to comment.