作者:joshuawatso
项目:cockroac
// destroyOptions destroys the options used for creating, reading, and writing
// from the db. It is meant to be used in conjunction with createOptions.
func (r *RocksDB) destroyOptions() {
C.rocksdb_options_destroy(r.opts)
C.rocksdb_readoptions_destroy(r.rOpts)
C.rocksdb_writeoptions_destroy(r.wOpts)
r.opts = nil
r.rOpts = nil
r.wOpts = nil
}
作者:tradi
项目:gotabl
func (opt *ReadOptions) Destroy() {
if opt.rOpt != nil {
C.rocksdb_readoptions_destroy(opt.rOpt)
opt.rOpt = nil
}
if opt.snap != nil {
C.rocksdb_release_snapshot(opt.db, opt.snap)
opt.snap = nil
opt.db = nil
}
}
作者:kuguobin
项目:cockroac
// Scan returns up to max key/value objects starting from
// start (inclusive) and ending at end (non-inclusive).
// If max is zero then the number of key/values returned is unbounded.
func (r *RocksDB) Scan(start, end Key, max int64) ([]RawKeyValue, error) {
var keyVals []RawKeyValue
if bytes.Compare(start, end) >= 0 {
return keyVals, nil
}
// In order to prevent content displacement, caching is disabled
// when performing scans. Any options set within the shared read
// options field that should be carried over needs to be set here
// as well.
opts := C.rocksdb_readoptions_create()
C.rocksdb_readoptions_set_fill_cache(opts, 0)
defer C.rocksdb_readoptions_destroy(opts)
it := C.rocksdb_create_iterator(r.rdb, opts)
defer C.rocksdb_iter_destroy(it)
byteCount := len(start)
if byteCount == 0 {
// start=Key("") needs special treatment since we need
// to access start[0] in an explicit seek.
C.rocksdb_iter_seek_to_first(it)
} else {
C.rocksdb_iter_seek(it, bytesPointer(start), C.size_t(byteCount))
}
for i := int64(1); C.rocksdb_iter_valid(it) == 1; C.rocksdb_iter_next(it) {
if max > 0 && i > max {
break
}
var l C.size_t
// The data returned by rocksdb_iter_{key,value} is not meant to be
// freed by the client. It is a direct reference to the data managed
// by the iterator, so it is copied instead of freed.
data := C.rocksdb_iter_key(it, &l)
k := C.GoBytes(unsafe.Pointer(data), C.int(l))
if bytes.Compare(k, end) >= 0 {
break
}
data = C.rocksdb_iter_value(it, &l)
v := C.GoBytes(unsafe.Pointer(data), C.int(l))
keyVals = append(keyVals, RawKeyValue{
Key: k,
Value: v,
})
i++
}
// Check for any errors during iteration.
var cErr *C.char
C.rocksdb_iter_get_error(it, &cErr)
if cErr != nil {
return nil, charToErr(cErr)
}
return keyVals, nil
}
作者:GavinHw
项目:cockroac
// destroyOptions destroys the options used for creating, reading, and writing
// from the db. It is meant to be used in conjunction with createOptions.
func (r *RocksDB) destroyOptions() {
// The merge operator is stored inside of r.opts as a std::shared_ptr,
// so it will actually be freed automatically.
// Calling rocksdb_mergeoperator_destroy will ignore that shared_ptr,
// and a subsequent rocksdb_options_destroy would segfault.
// The following line zeroes the shared_ptr instead, effectively
// deallocating the merge operator if one is set.
C.rocksdb_options_set_merge_operator(r.opts, nil)
C.rocksdb_options_destroy(r.opts)
C.rocksdb_readoptions_destroy(r.rOpts)
C.rocksdb_writeoptions_destroy(r.wOpts)
r.mergeOperator = nil
r.opts = nil
r.rOpts = nil
r.wOpts = nil
}
作者:kuguobin
项目:cockroac
// destroyOptions destroys the options used for creating, reading, and writing
// from the db. It is meant to be used in conjunction with createOptions.
func (r *RocksDB) destroyOptions() {
// The merge operator and compaction filter are stored inside of
// r.opts using std::shared_ptrs, so they'll be freed
// automatically. Calling the *_destroy methods directly would
// ignore the shared_ptrs, and a subsequent rocksdb_options_destroy
// would segfault. The following lines zero the shared_ptrs instead,
// which deletes the underlying values.
C.rocksdb_options_set_merge_operator(r.opts, nil)
C.rocksdb_options_set_compaction_filter_factory(r.opts, nil)
C.rocksdb_options_destroy(r.opts)
C.rocksdb_readoptions_destroy(r.rOpts)
C.rocksdb_writeoptions_destroy(r.wOpts)
r.mergeOperator = nil
r.compactionFilterFactory = nil
r.opts = nil
r.rOpts = nil
r.wOpts = nil
}
作者:Zemnme
项目:cockroac
// scan returns up to max key/value objects starting from
// start (inclusive) and ending at end (non-inclusive).
// If max is zero then the number of key/values returned is unbounded.
func (r *RocksDB) scan(start, end Key, max int64) ([]KeyValue, error) {
// In order to prevent content displacement, caching is disabled
// when performing scans. Any options set within the shared read
// options field that should be carried over needs to be set here
// as well.
opts := C.rocksdb_readoptions_create()
C.rocksdb_readoptions_set_fill_cache(opts, 0)
defer C.rocksdb_readoptions_destroy(opts)
it := C.rocksdb_create_iterator(r.rdb, opts)
defer C.rocksdb_iter_destroy(it)
keyVals := []KeyValue{}
C.rocksdb_iter_seek(it, (*C.char)(unsafe.Pointer(&start[0])), C.size_t(len(start)))
for i := int64(1); C.rocksdb_iter_valid(it) == 1; C.rocksdb_iter_next(it) {
if max > 0 && i > max {
break
}
var l C.size_t
// The data returned by rocksdb_iter_{key,value} is not meant to be
// freed by the client. It is a direct reference to the data managed
// by the iterator, so it is copied instead of freed.
data := C.rocksdb_iter_key(it, &l)
k := C.GoBytes(unsafe.Pointer(data), C.int(l))
if bytes.Equal(k, end) {
break
}
data = C.rocksdb_iter_value(it, &l)
v := C.GoBytes(unsafe.Pointer(data), C.int(l))
keyVals = append(keyVals, KeyValue{
Key: k,
Value: Value{Bytes: v},
})
i++
}
// Check for any errors during iteration.
var cErr *C.char
C.rocksdb_iter_get_error(it, &cErr)
if cErr != nil {
return nil, charToErr(cErr)
}
return keyVals, nil
}
作者:tradi
项目:gotabl
func (db *DB) Close() {
if db.db != nil {
C.rocksdb_close(db.db)
db.db = nil
if db.opt != nil {
C.rocksdb_options_destroy(db.opt)
}
if db.rOpt != nil {
C.rocksdb_readoptions_destroy(db.rOpt)
}
if db.wOpt != nil {
C.rocksdb_writeoptions_destroy(db.wOpt)
}
if db.cache != nil {
C.rocksdb_cache_destroy(db.cache)
}
if db.fp != nil {
C.rocksdb_filterpolicy_destroy(db.fp)
}
}
}
作者:zack
项目:rocksd
// Close deallocates the ReadOptions, freeing its underlying C struct.
func (ro *ReadOptions) Close() {
C.rocksdb_readoptions_destroy(ro.Opt)
}
作者:pavank
项目:gorocksd
// Destroy deallocates the ReadOptions object.
func (self *ReadOptions) Destroy() {
C.rocksdb_readoptions_destroy(self.c)
self.c = nil
}
作者:unigrap
项目:rd
// Destroy deallocates the ReadOptions object.
func (opts *ReadOptions) Destroy() {
C.rocksdb_readoptions_destroy(opts.c)
opts.c = nil
}
作者:daak
项目:gorocksd
// Release deallocates the ReadOptions object.
func (o *ReadOptions) Release() {
C.rocksdb_readoptions_destroy(o.c)
o.c = nil
}