func (db *DB) Open(name string, createIfMissing bool, maxOpenFiles int, writeBufSize int, cacheSize int64, compression int) error { db.opt = C.rocksdb_options_create() C.rocksdb_options_set_create_if_missing(db.opt, boolToUchar(createIfMissing)) C.rocksdb_options_set_write_buffer_size(db.opt, C.size_t(writeBufSize)) C.rocksdb_options_set_max_open_files(db.opt, C.int(maxOpenFiles)) C.rocksdb_options_set_compression(db.opt, C.int(compression)) var block_options = C.rocksdb_block_based_options_create() if cacheSize > 0 { db.cache = C.rocksdb_cache_create_lru(C.size_t(cacheSize)) C.rocksdb_block_based_options_set_block_cache(block_options, db.cache) } else { C.rocksdb_block_based_options_set_no_block_cache(block_options, 1) } db.fp = C.rocksdb_filterpolicy_create_bloom(10) C.rocksdb_block_based_options_set_filter_policy(block_options, db.fp) C.rocksdb_options_set_block_based_table_factory(db.opt, block_options) cname := C.CString(name) defer C.free(unsafe.Pointer(cname)) var errStr *C.char db.db = C.rocksdb_open(db.opt, cname, &errStr) if errStr != nil { defer C.free(unsafe.Pointer(errStr)) return errors.New(C.GoString(errStr)) } db.rOpt = C.rocksdb_readoptions_create() db.wOpt = C.rocksdb_writeoptions_create() return nil }
// NewBloomFilter returns a new filter policy that uses a bloom filter with approximately // the specified number of bits per key. A good value for bits_per_key // is 10, which yields a filter with ~1% false positive rate. // // Note: if you are using a custom comparator that ignores some parts // of the keys being compared, you must not use NewBloomFilterPolicy() // and must provide your own FilterPolicy that also ignores the // corresponding parts of the keys. For example, if the comparator // ignores trailing spaces, it would be incorrect to use a // FilterPolicy (like NewBloomFilterPolicy) that does not ignore // trailing spaces in keys. func NewBloomFilter(bitsPerKey int) FilterPolicy { return NewNativeFilterPolicy(C.rocksdb_filterpolicy_create_bloom(C.int(bitsPerKey))) }
// NewBloomFilter creates a filter policy that will create a bloom filter when // necessary with the given number of bits per key. // // See the FilterPolicy documentation for more. func NewBloomFilter(bitsPerKey int) *FilterPolicy { policy := C.rocksdb_filterpolicy_create_bloom(C.int(bitsPerKey)) return &FilterPolicy{policy} }