Esempio n. 1
0
File: db.go Progetto: tradia/gotable
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
}
Esempio n. 2
0
// SetCache places a cache object in the database when a database is opened.
//
// This is usually wise to use. See also ReadOptions.SetFillCache.
func (o *BlockBasedOptions) SetCache(cache *Cache) {
	C.rocksdb_block_based_options_set_block_cache(o.Opt, cache.Cache)
}
// Control over blocks (user data is stored in a set of blocks, and
// a block is the unit of reading from disk).
//
// If set, use the specified cache for blocks.
// If nil, rocksdb will automatically create and use an 8MB internal cache.
// Default: nil
func (self *BlockBasedTableOptions) SetBlockCache(value *Cache) {
	self.cache = value

	C.rocksdb_block_based_options_set_block_cache(self.c, value.c)
}
Esempio n. 4
0
// SetBlockCache sets the control over blocks (user data is soptsred in a set of blocks, and
// a block is the unit of reading from disk).
//
// If set, use the specified cache for blocks.
// If nil, rocksdb will auoptsmatically create and use an 8MB internal cache.
// Default: nil
func (opts *BlockBasedTableOptions) SetBlockCache(cache *Cache) {
	opts.cache = cache
	C.rocksdb_block_based_options_set_block_cache(opts.c, cache.c)
}