Example #1
0
// SetMergeOperator sets the merge operator which will be called
// if a merge operations are used.
// Default: nil
func (opts *Options) SetMergeOperator(value MergeOperator) {
	if nmo, ok := value.(nativeMergeOperator); ok {
		opts.cmo = nmo.c
	} else {
		idx := registerMergeOperator(value)
		opts.cmo = C.gorocksdb_mergeoperator_create(C.uintptr_t(idx))
	}
	C.rocksdb_options_set_merge_operator(opts.c, opts.cmo)
}
Example #2
0
// The merge operator will called if Merge operations are used.
// Default: nil
func (self *Options) SetMergeOperator(value MergeOperator) {
	if nmo, ok := value.(nativeMergeOperator); ok {
		self.cmo = nmo.c
	} else {
		h := unsafe.Pointer(&value)
		self.mo = &value
		self.cmo = C.gorocksdb_mergeoperator_create(h)
	}
	C.rocksdb_options_set_merge_operator(self.c, self.cmo)
}
Example #3
0
// createOptions sets the default options for creating, reading, and writing
// from the db. destroyOptions should be called when the options aren't needed
// anymore.
func (r *RocksDB) createOptions() {
	// TODO(andybons): Set the cache size.
	r.opts = C.rocksdb_options_create()
	C.rocksdb_options_set_create_if_missing(r.opts, 1)
	// This enables us to use rocksdb_merge with counter semantics.
	// See rocksdb.{c,h} for the C implementation.
	r.mergeOperator = C.MakeMergeOperator()
	C.rocksdb_options_set_merge_operator(r.opts, r.mergeOperator)

	r.wOpts = C.rocksdb_writeoptions_create()
	r.rOpts = C.rocksdb_readoptions_create()
}
Example #4
0
// createOptions sets the default options for creating, reading, and writing
// from the db. destroyOptions should be called when the options aren't needed
// anymore.
func (r *RocksDB) createOptions() {
	// TODO(andybons): Set the cache size.
	r.opts = C.rocksdb_options_create()
	C.rocksdb_options_set_create_if_missing(r.opts, 1)
	// This enables us to use rocksdb_merge with counter semantics.
	// See rocksdb.{c,h} for the C implementation.
	r.mergeOperator = C.make_merge_operator()
	C.rocksdb_options_set_merge_operator(r.opts, r.mergeOperator)
	// This enables garbage collection of transaction and response cache rows.
	r.compactionFilterFactory = C.make_gc_compaction_filter_factory(unsafe.Pointer(r))
	C.rocksdb_options_set_compaction_filter_factory(r.opts, r.compactionFilterFactory)

	r.wOpts = C.rocksdb_writeoptions_create()
	r.rOpts = C.rocksdb_readoptions_create()
}
Example #5
0
// 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
}
Example #6
0
// 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
}