Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[REDRES-820] Add rocks options for compaction #44

Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Fix up error handling
  • Loading branch information
dforciea committed Jun 26, 2024
commit 3b1c13b5de415f11383afbc1f5403430073b650b
7 changes: 5 additions & 2 deletions 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 @@ -907,7 +907,10 @@ func (db *DB) SetOptionsCF(cf *ColumnFamilyHandle, keys, values []string) (err e
&cValues[0],
&cErr,
)
err = fromCError(cErr)
if cErr != nil {
err = errors.New(C.GoString(cErr))
C.rocksdb_free(unsafe.Pointer(cErr))
}

// free before return

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
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 {
Expand Down
17 changes: 2 additions & 15 deletions v8/util.go
Original file line number Diff line number Diff line change
@@ -1,13 +1,9 @@
package gorocksdb

// #include <stdlib.h>
// #include "rocksdb/c.h"
import "C"

import (
"errors"
"unsafe"
)
import "C"
import "unsafe"

// btoi converts a bool value to int.
func btoi(b bool) int {
Expand Down Expand Up @@ -68,12 +64,3 @@ func charSlice(data **C.char, len C.int) []*C.char {
func sizeSlice(data *C.size_t, len C.int) []C.size_t {
return unsafe.Slice(data, int(len))
}

// fromCError returns go error and free c_err if need.
func fromCError(cErr *C.char) (err error) {
if cErr != nil {
err = errors.New(C.GoString(cErr))
C.rocksdb_free(unsafe.Pointer(cErr))
}
return
}