Ejemplo n.º 1
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()
}
Ejemplo n.º 2
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
}