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
11 changes: 8 additions & 3 deletions compaction_filter.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,16 +42,21 @@ func (c nativeCompactionFilter) Name() string { return "" }
// Hold references to compaction filters.
var compactionFilters = NewCOWList()

type compactionFilterWrapper struct {
name *C.char
filter CompactionFilter
}

func registerCompactionFilter(filter CompactionFilter) int {
return compactionFilters.Append(filter)
return compactionFilters.Append(compactionFilterWrapper{C.CString(filter.Name()), filter})
}

//export gorocksdb_compactionfilter_filter
func gorocksdb_compactionfilter_filter(idx int, cLevel C.int, cKey *C.char, cKeyLen C.size_t, cVal *C.char, cValLen C.size_t, cNewVal **C.char, cNewValLen *C.size_t, cValChanged *C.uchar) C.int {
key := charToByte(cKey, cKeyLen)
val := charToByte(cVal, cValLen)

remove, newVal := compactionFilters.Get(idx).(CompactionFilter).Filter(int(cLevel), key, val)
remove, newVal := compactionFilters.Get(idx).(compactionFilterWrapper).filter.Filter(int(cLevel), key, val)
if remove {
return C.int(1)
} else if newVal != nil {
Expand All @@ -64,5 +69,5 @@ func gorocksdb_compactionfilter_filter(idx int, cLevel C.int, cKey *C.char, cKey

//export gorocksdb_compactionfilter_name
func gorocksdb_compactionfilter_name(idx int) *C.char {
return stringToChar(compactionFilters.Get(idx).(CompactionFilter).Name())
return compactionFilters.Get(idx).(compactionFilterWrapper).name
}
11 changes: 8 additions & 3 deletions comparator.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,18 +31,23 @@ func (c nativeComparator) Name() string { return "" }
// Hold references to comperators.
var comperators = NewCOWList()

type comperatorWrapper struct {
name *C.char
comparator Comparator
}

func registerComperator(cmp Comparator) int {
return comperators.Append(cmp)
return comperators.Append(comperatorWrapper{C.CString(cmp.Name()), cmp})
}

//export gorocksdb_comparator_compare
func gorocksdb_comparator_compare(idx int, cKeyA *C.char, cKeyALen C.size_t, cKeyB *C.char, cKeyBLen C.size_t) C.int {
keyA := charToByte(cKeyA, cKeyALen)
keyB := charToByte(cKeyB, cKeyBLen)
return C.int(comperators.Get(idx).(Comparator).Compare(keyA, keyB))
return C.int(comperators.Get(idx).(comperatorWrapper).comparator.Compare(keyA, keyB))
}

//export gorocksdb_comparator_name
func gorocksdb_comparator_name(idx int) *C.char {
return stringToChar(comperators.Get(idx).(Comparator).Name())
return comperators.Get(idx).(comperatorWrapper).name
}
13 changes: 9 additions & 4 deletions filter_policy.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,13 @@ func NewBloomFilter(bitsPerKey int) FilterPolicy {
// Hold references to filter policies.
var filterPolicies = NewCOWList()

type filterPolicyWrapper struct {
name *C.char
filterPolicy FilterPolicy
}

func registerFilterPolicy(fp FilterPolicy) int {
return filterPolicies.Append(fp)
return filterPolicies.Append(filterPolicyWrapper{C.CString(fp.Name()), fp})
}

//export gorocksdb_filterpolicy_create_filter
Expand All @@ -65,7 +70,7 @@ func gorocksdb_filterpolicy_create_filter(idx int, cKeys **C.char, cKeysLen *C.s
keys[i] = charToByte(rawKeys[i], len)
}

dst := filterPolicies.Get(idx).(FilterPolicy).CreateFilter(keys)
dst := filterPolicies.Get(idx).(filterPolicyWrapper).filterPolicy.CreateFilter(keys)
*cDstLen = C.size_t(len(dst))
return cByteSlice(dst)
}
Expand All @@ -74,10 +79,10 @@ func gorocksdb_filterpolicy_create_filter(idx int, cKeys **C.char, cKeysLen *C.s
func gorocksdb_filterpolicy_key_may_match(idx int, cKey *C.char, cKeyLen C.size_t, cFilter *C.char, cFilterLen C.size_t) C.uchar {
key := charToByte(cKey, cKeyLen)
filter := charToByte(cFilter, cFilterLen)
return boolToChar(filterPolicies.Get(idx).(FilterPolicy).KeyMayMatch(key, filter))
return boolToChar(filterPolicies.Get(idx).(filterPolicyWrapper).filterPolicy.KeyMayMatch(key, filter))
}

//export gorocksdb_filterpolicy_name
func gorocksdb_filterpolicy_name(idx int) *C.char {
return stringToChar(filterPolicies.Get(idx).(FilterPolicy).Name())
return filterPolicies.Get(idx).(filterPolicyWrapper).name
}
13 changes: 9 additions & 4 deletions merge_operator.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,13 @@ func (mo nativeMergeOperator) Name() string { return "" }
// Hold references to merge operators.
var mergeOperators = NewCOWList()

type mergeOperatorWrapper struct {
name *C.char
mergeOperator MergeOperator
}

func registerMergeOperator(merger MergeOperator) int {
return mergeOperators.Append(merger)
return mergeOperators.Append(mergeOperatorWrapper{C.CString(merger.Name()), merger})
}

//export gorocksdb_mergeoperator_full_merge
Expand All @@ -82,7 +87,7 @@ func gorocksdb_mergeoperator_full_merge(idx int, cKey *C.char, cKeyLen C.size_t,
operands[i] = charToByte(rawOperands[i], len)
}

newValue, success := mergeOperators.Get(idx).(MergeOperator).FullMerge(key, existingValue, operands)
newValue, success := mergeOperators.Get(idx).(mergeOperatorWrapper).mergeOperator.FullMerge(key, existingValue, operands)
newValueLen := len(newValue)

*cNewValueLen = C.size_t(newValueLen)
Expand All @@ -104,7 +109,7 @@ func gorocksdb_mergeoperator_partial_merge_multi(idx int, cKey *C.char, cKeyLen
var newValue []byte
success := true

merger := mergeOperators.Get(idx).(MergeOperator)
merger := mergeOperators.Get(idx).(mergeOperatorWrapper).mergeOperator
leftOperand := operands[0]
for i := 1; i < int(cNumOperands); i++ {
newValue, success = merger.PartialMerge(key, leftOperand, operands[i])
Expand All @@ -123,5 +128,5 @@ func gorocksdb_mergeoperator_partial_merge_multi(idx int, cKey *C.char, cKeyLen

//export gorocksdb_mergeoperator_name
func gorocksdb_mergeoperator_name(idx int) *C.char {
return stringToChar(mergeOperators.Get(idx).(MergeOperator).Name())
return mergeOperators.Get(idx).(mergeOperatorWrapper).name
}
15 changes: 10 additions & 5 deletions slice_transform.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,33 +40,38 @@ func (st nativeSliceTransform) Name() string { return "" }
// Hold references to slice transforms.
var sliceTransforms = NewCOWList()

type sliceTransformWrapper struct {
name *C.char
sliceTransform SliceTransform
}

func registerSliceTransform(st SliceTransform) int {
return sliceTransforms.Append(st)
return sliceTransforms.Append(sliceTransformWrapper{C.CString(st.Name()), st})
}

//export gorocksdb_slicetransform_transform
func gorocksdb_slicetransform_transform(idx int, cKey *C.char, cKeyLen C.size_t, cDstLen *C.size_t) *C.char {
key := charToByte(cKey, cKeyLen)
dst := sliceTransforms.Get(idx).(SliceTransform).Transform(key)
dst := sliceTransforms.Get(idx).(sliceTransformWrapper).sliceTransform.Transform(key)
*cDstLen = C.size_t(len(dst))
return cByteSlice(dst)
}

//export gorocksdb_slicetransform_in_domain
func gorocksdb_slicetransform_in_domain(idx int, cKey *C.char, cKeyLen C.size_t) C.uchar {
key := charToByte(cKey, cKeyLen)
inDomain := sliceTransforms.Get(idx).(SliceTransform).InDomain(key)
inDomain := sliceTransforms.Get(idx).(sliceTransformWrapper).sliceTransform.InDomain(key)
return boolToChar(inDomain)
}

//export gorocksdb_slicetransform_in_range
func gorocksdb_slicetransform_in_range(idx int, cKey *C.char, cKeyLen C.size_t) C.uchar {
key := charToByte(cKey, cKeyLen)
inRange := sliceTransforms.Get(idx).(SliceTransform).InRange(key)
inRange := sliceTransforms.Get(idx).(sliceTransformWrapper).sliceTransform.InRange(key)
return boolToChar(inRange)
}

//export gorocksdb_slicetransform_name
func gorocksdb_slicetransform_name(idx int) *C.char {
return stringToChar(sliceTransforms.Get(idx).(SliceTransform).Name())
return sliceTransforms.Get(idx).(sliceTransformWrapper).name
}
6 changes: 0 additions & 6 deletions util.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,12 +51,6 @@ func cByteSlice(b []byte) *C.char {
return c
}

// stringToChar returns *C.char from string.
func stringToChar(s string) *C.char {
ptrStr := (*reflect.StringHeader)(unsafe.Pointer(&s))
return (*C.char)(unsafe.Pointer(ptrStr.Data))
}

// charSlice converts a C array of *char to a []*C.char.
func charSlice(data **C.char, len C.int) []*C.char {
var value []*C.char
Expand Down