当前位置: 首页>>代码示例>>Golang>>正文


Golang gorocksdb.NewDefaultOptions函数代码示例

本文整理汇总了Golang中github.com/tecbot/gorocksdb.NewDefaultOptions函数的典型用法代码示例。如果您正苦于以下问题:Golang NewDefaultOptions函数的具体用法?Golang NewDefaultOptions怎么用?Golang NewDefaultOptions使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了NewDefaultOptions函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: DeleteState

// DeleteState delets ALL state keys/values from the DB. This is generally
// only used during state synchronization when creating a new state from
// a snapshot.
func (openchainDB *OpenchainDB) DeleteState() error {
	err := openchainDB.DB.DropColumnFamily(openchainDB.StateCF)
	if err != nil {
		dbLogger.Error("Error dropping state CF", err)
		return err
	}
	err = openchainDB.DB.DropColumnFamily(openchainDB.StateDeltaCF)
	if err != nil {
		dbLogger.Error("Error dropping state delta CF", err)
		return err
	}
	opts := gorocksdb.NewDefaultOptions()
	defer opts.Destroy()
	openchainDB.StateCF, err = openchainDB.DB.CreateColumnFamily(opts, stateCF)
	if err != nil {
		dbLogger.Error("Error creating state CF", err)
		return err
	}
	openchainDB.StateDeltaCF, err = openchainDB.DB.CreateColumnFamily(opts, stateDeltaCF)
	if err != nil {
		dbLogger.Error("Error creating state delta CF", err)
		return err
	}
	return nil
}
开发者ID:butine,项目名称:research,代码行数:28,代码来源:db.go

示例2: NewRocksdbStorage

func NewRocksdbStorage(dbfname string, dbtype string, mergeOp gorocksdb.MergeOperator) (*RocksdbStorage, error) {
	var sto *RocksdbStorage

	if dbtype != "kv" && dbtype != "json" {
		return sto, fmt.Errorf("Unkown db type")
	}

	opts := gorocksdb.NewDefaultOptions()

	if mergeOp != nil {
		opts.SetMergeOperator(mergeOp)
	}
	// opts.IncreaseParallelism(runtime.NumCPU())
	// opts.OptimizeLevelStyleCompaction(0)
	opts.SetCreateIfMissing(true)

	db, err := gorocksdb.OpenDb(opts, dbfname)
	if err != nil {
		return sto, err
	}
	ro := gorocksdb.NewDefaultReadOptions()
	wo := gorocksdb.NewDefaultWriteOptions()

	sto = &RocksdbStorage{
		dbfname: dbfname,
		db:      db,
		ro:      ro,
		wo:      wo,
	}
	return sto, nil
}
开发者ID:yuyang0,项目名称:gkv,代码行数:31,代码来源:rocksdb.go

示例3: write_multi_cfs

func write_multi_cfs() error {
	dbOpts := gorocksdb.NewDefaultOptions()
	dbOpts.SetCreateIfMissing(true)
	if err := os.RemoveAll("/tmp/multicf_db"); err != nil {
		return err
	}

	db, err := gorocksdb.OpenDb(dbOpts, "/tmp/multicf_db")
	if err != nil {
		return err
	}

	var handles []*gorocksdb.ColumnFamilyHandle
	for i := 0; i < 4; i++ {
		handle, err := db.CreateColumnFamily(dbOpts, fmt.Sprint(i))
		if err != nil {
			return err
		}
		handles = append(handles, handle)
	}

	writeOpts := gorocksdb.NewDefaultWriteOptions()
	if err := db.Put(writeOpts, []byte("default"), []byte("default")); err != nil {
		return err
	}
	for i := 0; i < 16; i++ {
		key := []byte(fmt.Sprint(i))
		if err := db.PutCF(writeOpts, handles[i%4], key, key); err != nil {
			return err
		}
	}
	db.Close()
	return nil
}
开发者ID:pavanka,项目名称:gorocksext_test,代码行数:34,代码来源:gorocksext.go

示例4: read_multi_cfs

func read_multi_cfs() error {
	dbOpts := gorocksdb.NewDefaultOptions()
	defaultRO := gorocksdb.NewDefaultReadOptions()
	db, handles, err := gorocksdb.OpenDbColumnFamilies(
		dbOpts,
		"/tmp/multicf_db",
		[]string{"default", "0", "1", "2", "3"},
		[]*gorocksdb.Options{dbOpts, dbOpts, dbOpts, dbOpts, dbOpts},
	)
	iters, err := gorocksext.NewIterators(defaultRO, db, handles)
	if err != nil {
		return err
	}
	for i, iter := range iters {
		fmt.Printf("COUTING FOR ITER: %d\n", i)
		iter.SeekToFirst()
		for iter.Valid() {
			fmt.Println(string(iter.Key().Data()))
			defer iter.Key().Free()
			iter.Next()
		}
	}
	db.Close()
	return nil
}
开发者ID:pavanka,项目名称:gorocksext_test,代码行数:25,代码来源:gorocksext.go

示例5: CreateDB

// CreateDB creates a rocks db database
func CreateDB() error {
	dbPath := getDBPath()
	dbLogger.Debug("Creating DB at [%s]", dbPath)
	missing, err := dirMissingOrEmpty(dbPath)
	if err != nil {
		return err
	}

	if !missing {
		return fmt.Errorf("db dir [%s] already exists", dbPath)
	}
	err = os.MkdirAll(path.Dir(dbPath), 0755)
	if err != nil {
		dbLogger.Error("Error calling  os.MkdirAll for directory path [%s]: %s", dbPath, err)
		return fmt.Errorf("Error making directory path [%s]: %s", dbPath, err)
	}
	opts := gorocksdb.NewDefaultOptions()
	defer opts.Destroy()
	opts.SetCreateIfMissing(true)

	db, err := gorocksdb.OpenDb(opts, dbPath)
	if err != nil {
		return err
	}

	defer db.Close()

	dbLogger.Debug("DB created at [%s]", dbPath)
	return nil
}
开发者ID:RicHernandez2,项目名称:fabric,代码行数:31,代码来源:db.go

示例6: NewRocksDB

func NewRocksDB(path string) (*RocksDB, error) {
	opts := gorocksdb.NewDefaultOptions()
	//opts.SetBlockCache(gorocksdb.NewLRUCache(3 << 30))
	opts.SetCreateIfMissing(true)
	db, err := gorocksdb.OpenDb(opts, path)
	return &RocksDB{db: db}, err
}
开发者ID:sheki,项目名称:rocksiterbench,代码行数:7,代码来源:rocks.go

示例7: openDB

func openDB() (*OpenchainDB, error) {
	if isOpen {
		return openchainDB, nil
	}

	dbPath := getDBPath()
	opts := gorocksdb.NewDefaultOptions()
	defer opts.Destroy()

	opts.SetCreateIfMissing(false)
	opts.SetCreateIfMissingColumnFamilies(true)

	cfNames := []string{"default"}
	cfNames = append(cfNames, columnfamilies...)
	var cfOpts []*gorocksdb.Options
	for _ = range cfNames {
		cfOpts = append(cfOpts, opts)
	}

	db, cfHandlers, err := gorocksdb.OpenDbColumnFamilies(opts, dbPath, cfNames, cfOpts)

	if err != nil {
		fmt.Println("Error opening DB", err)
		return nil, err
	}
	isOpen = true
	// XXX should we close cfHandlers[0]?
	return &OpenchainDB{db, cfHandlers[1], cfHandlers[2], cfHandlers[3], cfHandlers[4], cfHandlers[5]}, nil
}
开发者ID:RicHernandez2,项目名称:fabric,代码行数:29,代码来源:db.go

示例8: New

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")
	}

	rv := Store{
		path: path,
		opts: gorocksdb.NewDefaultOptions(),
	}

	if mo != nil {
		rv.opts.SetMergeOperator(mo)
	}

	_, err := applyConfig(rv.opts, config)
	if err != nil {
		return nil, err
	}

	rv.db, err = gorocksdb.OpenDb(rv.opts, rv.path)
	if err != nil {
		return nil, err
	}

	return &rv, nil
}
开发者ID:ferhatelmas,项目名称:blevex,代码行数:28,代码来源:store.go

示例9: main

func main() {
	dbName := "/data/mydb"
	cache := gorocksdb.NewLRUCache(512 * 1024 * 1024)
	filter := gorocksdb.NewBloomFilter(15)
	to := gorocksdb.NewDefaultBlockBasedTableOptions()
	to.SetBlockSize(256 * 1024)
	to.SetBlockCache(cache)
	to.SetFilterPolicy(filter)
	options := gorocksdb.NewDefaultOptions()
	options.SetBlockBasedTableFactory(to)
	options.SetCreateIfMissing(true)
	options.SetStatsDumpPeriodSec(60 * 1) // dump stats at 10 minute interval
	options.SetCompactionStyle(gorocksdb.UniversalCompactionStyle)
	options.SetWriteBufferSize(512 * 1024 * 1024)
	options.SetMaxWriteBufferNumber(5)
	options.SetMinWriteBufferNumberToMerge(2)
	db, err := gorocksdb.OpenDb(options, dbName)
	if err != nil {
		fmt.Println(err)
		os.Exit(1)
	}
	putStatch := doPut(db, 16*1024, 32*1024)
	for {
		p := <-putStatch
		fmt.Println("avgTime ", p.avgTime, "maxTime", p.maxTime)
	}
}
开发者ID:krishnasrinivas,项目名称:random-progs,代码行数:27,代码来源:random-db-put.go

示例10: newRocksDB

func newRocksDB(dir string) *rocks.DB {
	opts := gorocksdb.NewDefaultOptions()
	opts.SetCreateIfMissing(true)
	rdb, err := gorocksdb.OpenDb(opts, dir)
	if err != nil {
		panic(err)
	}
	return rocks.New(rdb)
}
开发者ID:CowLeo,项目名称:GoRedis,代码行数:9,代码来源:main.go

示例11: newRocksDB

func newRocksDB(t *testing.T) *gorocksdb.DB {
	dir, err := ioutil.TempDir("", "rocks")
	ensure.Nil(t, err)

	opts := gorocksdb.NewDefaultOptions()
	opts.SetCreateIfMissing(true)
	db, err := gorocksdb.OpenDb(opts, dir)
	ensure.Nil(t, err)

	return db
}
开发者ID:CowLeo,项目名称:GoRedis,代码行数:11,代码来源:db_test.go

示例12: New

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")
	}

	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
	}

	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
}
开发者ID:mschoch,项目名称:blevex,代码行数:54,代码来源:store.go

示例13: New

func New(path string, config map[string]interface{}) (*Store, error) {
	rv := Store{
		path: path,
		opts: gorocksdb.NewDefaultOptions(),
	}

	_, err := applyConfig(rv.opts, config)
	if err != nil {
		return nil, err
	}

	return &rv, nil
}
开发者ID:postfix,项目名称:name_pending,代码行数:13,代码来源:store.go

示例14: Open

// Open open underlying rocksdb
func (openchainDB *OpenchainDB) Open() {
	openchainDB.mux.Lock()
	if openchainDB.dbState == opened {
		openchainDB.mux.Unlock()
		return
	}

	defer openchainDB.mux.Unlock()

	dbPath := getDBPath()
	missing, err := dirMissingOrEmpty(dbPath)
	if err != nil {
		panic(fmt.Sprintf("Error while trying to open DB: %s", err))
	}
	dbLogger.Debugf("Is db path [%s] empty [%t]", dbPath, missing)

	if missing {
		err = os.MkdirAll(path.Dir(dbPath), 0755)
		if err != nil {
			panic(fmt.Sprintf("Error making directory path [%s]: %s", dbPath, err))
		}
	}

	opts := gorocksdb.NewDefaultOptions()
	defer opts.Destroy()

	opts.SetCreateIfMissing(missing)
	opts.SetCreateIfMissingColumnFamilies(true)

	cfNames := []string{"default"}
	cfNames = append(cfNames, columnfamilies...)
	var cfOpts []*gorocksdb.Options
	for range cfNames {
		cfOpts = append(cfOpts, opts)
	}

	db, cfHandlers, err := gorocksdb.OpenDbColumnFamilies(opts, dbPath, cfNames, cfOpts)

	if err != nil {
		panic(fmt.Sprintf("Error opening DB: %s", err))
	}

	openchainDB.DB = db
	openchainDB.BlockchainCF = cfHandlers[1]
	openchainDB.StateCF = cfHandlers[2]
	openchainDB.StateDeltaCF = cfHandlers[3]
	openchainDB.IndexesCF = cfHandlers[4]
	openchainDB.PersistCF = cfHandlers[5]
	openchainDB.dbState = opened
}
开发者ID:C0rWin,项目名称:fabric,代码行数:51,代码来源:db.go

示例15: create_purge_backups

func create_purge_backups() error {
	dbOpts := gorocksdb.NewDefaultOptions()
	dbOpts.SetCreateIfMissing(true)
	if err := os.RemoveAll("/tmp/backups_db"); err != nil {
		return err
	}

	db, err := gorocksdb.OpenDb(dbOpts, "/tmp/backups_db")
	if err != nil {
		return err
	}

	if err := os.RemoveAll("/tmp/db_backups"); err != nil {
		return err
	}
	be, err := gorocksdb.OpenBackupEngine(dbOpts, "/tmp/db_backups")
	if err != nil {
		return err
	}

	writeOpts := gorocksdb.NewDefaultWriteOptions()
	for i := 0; i < 5; i++ {
		key := []byte(fmt.Sprint(i))
		if err := db.Put(writeOpts, key, key); err != nil {
			return err
		}
		if err := be.CreateNewBackup(db); err != nil {
			return err
		}
	}
	fmt.Println("Num available initially: ", be.GetInfo().GetCount())
	if err := gorocksext.PurgeOldBackups(be, 4); err != nil {
		return err
	}
	fmt.Println(be.GetInfo().GetCount())
	if err := gorocksext.PurgeOldBackups(be, 2); err != nil {
		return err
	}
	fmt.Println(be.GetInfo().GetCount())
	if err := gorocksext.PurgeOldBackups(be, 0); err != nil {
		return err
	}
	fmt.Println(be.GetInfo().GetCount())

	db.Close()
	return nil
}
开发者ID:pavanka,项目名称:gorocksext_test,代码行数:47,代码来源:gorocksext.go


注:本文中的github.com/tecbot/gorocksdb.NewDefaultOptions函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。