diff --git a/v8/db.go b/v8/db.go index ae3e298..3ce274f 100755 --- a/v8/db.go +++ b/v8/db.go @@ -734,7 +734,7 @@ func (db *DB) CreateColumnFamilyWithTTL(opts *Options, name string, ttl int) (*C var ( cErr *C.char cName = C.CString(name) - cTtl = C.int(ttl) + cTtl = C.int(ttl) ) defer C.free(unsafe.Pointer(cName)) cHandle := C.rocksdb_create_column_family_with_ttl(db.c, opts.c, cName, cTtl, &cErr) @@ -883,6 +883,44 @@ func (db *DB) SetOptions(keys, values []string) error { return nil } +// SetOptionsCF dynamically changes options through the SetOptions API for specific Column Family. +func (db *DB) SetOptionsCF(cf *ColumnFamilyHandle, keys, values []string) (err error) { + numKeys := len(keys) + if numKeys == 0 { + return nil + } + + cKeys := make([]*C.char, numKeys) + cValues := make([]*C.char, numKeys) + for i := range keys { + cKeys[i] = C.CString(keys[i]) + cValues[i] = C.CString(values[i]) + } + + var cErr *C.char + + C.rocksdb_set_options_cf( + db.c, + cf.c, + C.int(numKeys), + &cKeys[0], + &cValues[0], + &cErr, + ) + if cErr != nil { + err = errors.New(C.GoString(cErr)) + C.rocksdb_free(unsafe.Pointer(cErr)) + } + + // free before return + for i := range cKeys { + C.free(unsafe.Pointer(cKeys[i])) + C.free(unsafe.Pointer(cValues[i])) + } + + return +} + // LiveFileMetadata is a metadata which is associated with each SST file. type LiveFileMetadata struct { Name string diff --git a/v8/options.go b/v8/options.go index f9a5e54..fca6b39 100644 --- a/v8/options.go +++ b/v8/options.go @@ -1221,6 +1221,20 @@ func (opts *Options) SetAtomicFlush(value bool) { C.rocksdb_options_set_atomic_flush(opts.c, C.uchar(btoi(value))) } +// AddCompactOnDeletionCollectorFactory marks a SST +// file as need-compaction when it observe at least "D" deletion +// entries in any "N" consecutive entries or the ratio of tombstone +// entries in the whole file >= the specified deletion ratio. +func (opts *Options) AddCompactOnDeletionCollectorFactory(windowSize, numDelsTrigger uint) { + C.rocksdb_options_add_compact_on_deletion_collector_factory(opts.c, C.size_t(windowSize), C.size_t(numDelsTrigger)) +} + +// AddCompactOnDeletionCollectorFactoryWithRatio similar to AddCompactOnDeletionCollectorFactory +// with specific deletion ratio. +func (opts *Options) AddCompactOnDeletionCollectorFactoryWithRatio(windowSize, numDelsTrigger uint, deletionRatio float64) { + C.rocksdb_options_add_compact_on_deletion_collector_factory_del_ratio(opts.c, C.size_t(windowSize), C.size_t(numDelsTrigger), C.double(deletionRatio)) +} + // SetMaxSubcompactions represents the maximum number of threads that will // concurrently perform a compaction job by breaking it into multiple, // smaller ones that are run simultaneously. diff --git a/v8/transactiondb.go b/v8/transactiondb.go index 047bdae..eb12f04 100644 --- a/v8/transactiondb.go +++ b/v8/transactiondb.go @@ -128,6 +128,19 @@ func (db *TransactionDB) ReleaseSnapshot(snapshot *Snapshot) { snapshot.c = nil } +// GetBaseDB gets base db. +func (db *TransactionDB) GetBaseDB() *DB { + base := C.rocksdb_transactiondb_get_base_db(db.c) + return &DB{c: base} +} + +// CloseBaseDBOfTransactionDB closes base db of TransactionDB. +func CloseBaseDBOfTransactionDB(db *DB) { + if db != nil && db.c != nil { + C.rocksdb_transactiondb_close_base_db(db.c) + } +} + // TransactionBegin begins a new transaction // with the WriteOptions and TransactionOptions given. func (db *TransactionDB) TransactionBegin(