func NewRocksDB(path string) (*RocksDB, error) { opts := gorocksdb.NewDefaultOptions() filter := gorocksdb.NewBloomFilter(14) opts.SetFilterPolicy(filter) opts.SetMaxOpenFiles(10000) db, err := gorocksdb.OpenDbForReadOnly(opts, path, false) if err != nil { return nil, err } return &RocksDB{ db: db, ro: gorocksdb.NewDefaultReadOptions(), hits: metrics.NewMeter(), misses: metrics.NewMeter(), cache: lru.New(1000000), }, nil }
func New(mo store.MergeOperator, config map[string]interface{}) (store.KVStore, error) { path, ok := config["path"].(string) if !ok { return nil, fmt.Errorf("must specify path") } if path == "" { return nil, os.ErrInvalid } rv := Store{ path: path, config: config, opts: gorocksdb.NewDefaultOptions(), } if mo != nil { rv.opts.SetMergeOperator(mo) } _, err := applyConfig(rv.opts, config) if err != nil { return nil, err } b, ok := config["read_only"].(bool) if ok && b { rv.db, err = gorocksdb.OpenDbForReadOnly(rv.opts, rv.path, false) } else { rv.db, err = gorocksdb.OpenDb(rv.opts, rv.path) } if err != nil { return nil, err } b, ok = config["readoptions_verify_checksum"].(bool) if ok { rv.roptVerifyChecksums, rv.roptVerifyChecksumsUse = b, true } b, ok = config["readoptions_fill_cache"].(bool) if ok { rv.roptFillCache, rv.roptFillCacheUse = b, true } v, ok := config["readoptions_read_tier"].(float64) if ok { rv.roptReadTier, rv.roptReadTierUse = int(v), true } b, ok = config["writeoptions_sync"].(bool) if ok { rv.woptSync, rv.woptSyncUse = b, true } b, ok = config["writeoptions_disable_WAL"].(bool) if ok { rv.woptDisableWAL, rv.woptDisableWALUse = b, true } return &rv, nil }