Skip to content

Commit

Permalink
Merge pull request #44 from DataDog/dylan.forciea/redres-820-add-comp…
Browse files Browse the repository at this point in the history
…act-on-delettion-collector-factory

[REDRES-820] Add rocks options for compaction
  • Loading branch information
dforciea authored Jul 1, 2024
2 parents abc1365 + 3b1c13b commit 2a82964
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 1 deletion.
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
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

0 comments on commit 2a82964

Please sign in to comment.