Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 39 additions & 1 deletion v8/db.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I noticed the SetOptions function does not free the cstrings. Is that a bug or do we not need to free these?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we probably do need to technically. Although I don't think it is super high impact since we would not be continuously setting options.

Might be a better idea to make a separate PR to fix that, though

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
Expand Down
14 changes: 14 additions & 0 deletions v8/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
13 changes: 13 additions & 0 deletions v8/transactiondb.go
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down