• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Golang levigo.NewOptions函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: main

func main() {
	flag.Parse()

	if *showVersion {
		fmt.Printf("gocountme: v%s\n", VERSION)
		return
	}

	if *defaultSize <= 0 {
		fmt.Printf("--default-size must be greater than 0\n")
		return
	}

	if _, err := os.Stat(*dblocation); err != nil {
		if os.IsNotExist(err) {
			fmt.Println("Database location does not exist:", *dblocation)
			return
		}
	}

	log.Println("Opening levelDB")
	Default_KMinValues_Size = *defaultSize
	opts := levigo.NewOptions()
	opts.SetCache(levigo.NewLRUCache(*leveldbLRUCache))
	opts.SetCreateIfMissing(true)
	db, err := levigo.Open(*dblocation, opts)
	defer db.Close()

	if err != nil {
		log.Panicln(err)
	}

	RequestChan = make(chan RequestCommand, *nWorkers)
	workerWaitGroup := sync.WaitGroup{}
	log.Printf("Starting %d workers", *nWorkers)
	for i := 0; i < *nWorkers; i++ {
		go func(id int) {
			workerWaitGroup.Add(1)
			levelDBWorker(db, RequestChan)
			workerWaitGroup.Done()
		}(i)
	}

	http.HandleFunc("/get", GetHandler)
	http.HandleFunc("/delete", DeleteHandler)
	http.HandleFunc("/cardinality", CardinalityHandler)
	http.HandleFunc("/jaccard", JaccardHandler)
	http.HandleFunc("/correlation", CorrelationMatrixHandler)
	http.HandleFunc("/add", AddHandler)
	http.HandleFunc("/addhash", AddHashHandler)
	http.HandleFunc("/query", QueryHandler)
	http.HandleFunc("/exit", ExitHandler)

	log.Printf("Starting gocountme HTTP server on %s", *httpAddress)
	go func() {
		log.Fatal(http.ListenAndServe(*httpAddress, nil))
	}()

	workerWaitGroup.Wait()
}
开发者ID:jehiah,项目名称:gocountme,代码行数:60,代码来源:httpapi.go


示例2: main

func main() {
	dbname := "leveldb"
	opts := levigo.NewOptions()
	opts.SetCache(levigo.NewLRUCache(3 << 20))
	opts.SetCreateIfMissing(true)
	_ = levigo.DestroyDatabase(dbname, opts)
	db, _ := levigo.Open(dbname, opts)

	wo := levigo.NewWriteOptions()
	ro := levigo.NewReadOptions()

	start := time.Now()

	for i := 0; i < 10e4; i++ {
		db.Put(wo, []byte(fmt.Sprintf("a%v", i)), []byte(strconv.Itoa(i)))
	}
	for i := 0; i < 10e4; i++ {
		db.Get(ro, []byte(fmt.Sprintf("a%v", i)))
	}
	for i := 0; i < 10e4; i++ {
		db.Delete(wo, []byte(fmt.Sprintf("a%v", i)))
	}
	duration := time.Since(start)
	log.Printf("Elapsed: %v.", duration)
}
开发者ID:rif,项目名称:gocmd,代码行数:25,代码来源:leveldb_bench.go


示例3: New

func New(directory string) (*Level, error) {
	options := levigo.NewOptions()
	options.SetCreateIfMissing(true)
	options.SetCompression(levigo.SnappyCompression)
	db, err := levigo.Open(directory, options)
	return &Level{db: db}, err
}
开发者ID:psychoss,项目名称:Go-Server-Source-Code,代码行数:7,代码来源:leveldb.go


示例4: TestLevigo

func TestLevigo(t *testing.T) {
	path := "/tmp/levigo_test_10101"
	os.RemoveAll(path)

	opts := levigo.NewOptions()
	filter := levigo.NewBloomFilter(10)
	opts.SetFilterPolicy(filter)
	opts.SetCache(levigo.NewLRUCache(1024 << 20)) // 1G
	opts.SetCreateIfMissing(true)
	if ldb, err := levigo.Open(path, opts); err == nil {
		key := []byte("test-test hwl0dsfds")
		val := []byte("value")

		if err = ldb.Put(levigo.NewWriteOptions(), key, val); err != nil {
			t.Fail()
		} else {
			ro := levigo.NewReadOptions()
			if data, err := ldb.Get(ro, key); err == nil && reflect.DeepEqual(data, val) {
				ro.SetFillCache(false)
				it := ldb.NewIterator(ro)
				it.Seek([]byte{0})
				for ; it.Valid(); it.Next() {
					log.Printf("%s => %s", it.Key(), it.Value())
				}
			} else {
				t.Fail()
			}
		}
	} else {
		t.Fail()
	}
}
开发者ID:shenfeng,项目名称:proxies,代码行数:32,代码来源:cache_test.go


示例5: NewLevelDB

func NewLevelDB(path string, config interface{}) (Engine, error) {
	c, ok := config.(*LevelDbConfiguration)
	if !ok {
		return nil, fmt.Errorf("Config is of type %T instead of %T", config, LevelDbConfiguration{})
	}

	// if it wasn't set, set it to 100
	if c.MaxOpenFiles == 0 {
		c.MaxOpenFiles = 100
	}

	// if it wasn't set, set it to 200 MB
	if c.LruCacheSize == 0 {
		c.LruCacheSize = 200 * 1024 * 1024
	}

	// initialize the global cache
	if cache == nil {
		cacheLock.Lock()
		if cache == nil {
			cache = levigo.NewLRUCache(int(c.LruCacheSize))
		}
		cacheLock.Unlock()
	}

	opts := levigo.NewOptions()
	opts.SetCache(cache)
	opts.SetCreateIfMissing(true)
	opts.SetMaxOpenFiles(c.MaxOpenFiles)
	db, err := levigo.Open(path, opts)
	wopts := levigo.NewWriteOptions()
	ropts := levigo.NewReadOptions()
	return LevelDB{db, opts, wopts, ropts, path}, err
}
开发者ID:hanshenu,项目名称:influxdb,代码行数:34,代码来源:leveldb.go


示例6: Open

// Open returns a keyvalue DB backed by a LevelDB database at the given
// filepath.  If opts==nil, the DefaultOptions are used.
func Open(path string, opts *Options) (keyvalue.DB, error) {
	if opts == nil {
		opts = DefaultOptions
	}

	options := levigo.NewOptions()
	defer options.Close()
	cache := levigo.NewLRUCache(opts.CacheCapacity)
	options.SetCache(cache)
	options.SetCreateIfMissing(!opts.MustExist)
	if opts.WriteBufferSize > 0 {
		options.SetWriteBufferSize(opts.WriteBufferSize)
	}
	db, err := levigo.Open(path, options)
	if err != nil {
		return nil, fmt.Errorf("could not open LevelDB at %q: %v", path, err)
	}
	largeReadOpts := levigo.NewReadOptions()
	largeReadOpts.SetFillCache(opts.CacheLargeReads)
	return &levelDB{
		db:            db,
		cache:         cache,
		readOpts:      levigo.NewReadOptions(),
		largeReadOpts: largeReadOpts,
		writeOpts:     levigo.NewWriteOptions(),
	}, nil
}
开发者ID:bowlofstew,项目名称:kythe,代码行数:29,代码来源:leveldb.go


示例7: NewTree

func NewTree(dbname string) *Tree {
	debug("New tree")
	n := new(Tree)
	n.closed = false
	opts := levigo.NewOptions()
	opts.SetCache(levigo.NewLRUCache(3 << 30))
	opts.SetCreateIfMissing(true)
	d, err := levigo.Open(dbname, opts)

	if err != nil {
		Error(err)
	}
	n.DB = d
	if n.Root, err = n.Get(nil, 0); err != nil {
		debug("could not get", err)
		n.Root = &Node{Parent: 0}
		if err := n.Put(nil, n.Root); err != nil {
			Error("could not set", err)
		}
	}
	n.Newid = make(chan int)
	go func() {
		id := n.Root.Parent + 1
		for ; ; id++ {
			n.Newid <- id
			if n.closed {
				break
			}
		}
		log.Println("exiting Newid goroutine")
	}()
	return n
}
开发者ID:hagna,项目名称:pt,代码行数:33,代码来源:pt.go


示例8: NewLeveldbCache

func NewLeveldbCache(dbname string, cacheM int) (*LeveldbCache, error) {
	opts := levigo.NewOptions()
	filter := levigo.NewBloomFilter(10)
	cache := levigo.NewLRUCache(1024 * 1024 * cacheM)
	opts.SetFilterPolicy(filter)
	opts.SetCache(cache)
	opts.SetCreateIfMissing(true)
	opts.SetWriteBufferSize(8 * 1024 * 104) // 8M
	opts.SetCompression(levigo.SnappyCompression)

	if ldb, err := levigo.Open(dbname, opts); err == nil {
		so := levigo.NewReadOptions()
		so.SetFillCache(false)
		return &LeveldbCache{
			db:    ldb,
			fp:    filter,
			cache: cache,
			Ro:    levigo.NewReadOptions(),
			Wo:    levigo.NewWriteOptions(),
			So:    so,
		}, nil
	} else {
		return nil, err
	}
}
开发者ID:shenfeng,项目名称:proxies,代码行数:25,代码来源:cache.go


示例9: NewLevelDBPersistence

func NewLevelDBPersistence(storageRoot string, cacheCapacity, bitsPerBloomFilterEncoded int) (p *LevelDBPersistence, err error) {
	options := levigo.NewOptions()
	options.SetCreateIfMissing(true)
	options.SetParanoidChecks(true)

	cache := levigo.NewLRUCache(cacheCapacity)
	options.SetCache(cache)

	filterPolicy := levigo.NewBloomFilter(bitsPerBloomFilterEncoded)
	options.SetFilterPolicy(filterPolicy)

	storage, err := levigo.Open(storageRoot, options)
	if err != nil {
		return
	}

	readOptions := levigo.NewReadOptions()
	writeOptions := levigo.NewWriteOptions()
	writeOptions.SetSync(true)

	p = &LevelDBPersistence{
		cache:        cache,
		filterPolicy: filterPolicy,
		options:      options,
		readOptions:  readOptions,
		storage:      storage,
		writeOptions: writeOptions,
	}

	return
}
开发者ID:grobie,项目名称:prometheus,代码行数:31,代码来源:leveldb.go


示例10: NewStore

func NewStore(path string, sync bool) *Store {
	opts := levigo.NewOptions()
	opts.SetCreateIfMissing(true)

	db, err := levigo.Open(path, opts)
	if err != nil {
		panic(fmt.Sprintf("queued.Store: Unable to open db: %v", err))
	}

	id := 0

	it := db.NewIterator(levigo.NewReadOptions())
	defer it.Close()

	it.SeekToLast()
	if it.Valid() {
		id, err = strconv.Atoi(string(it.Key()))
		if err != nil {
			panic(fmt.Sprintf("queued: Error loading db: %v", err))
		}
	}

	store := &Store{
		id:   id,
		path: path,
		sync: sync,
		db:   db,
	}

	return store
}
开发者ID:pauldub,项目名称:queued,代码行数:31,代码来源:store.go


示例11: NewLevelDbDatastore

func NewLevelDbDatastore(dbDir string) (Datastore, error) {
	opts := levigo.NewOptions()
	opts.SetCache(levigo.NewLRUCache(ONE_GIGABYTE))
	opts.SetCreateIfMissing(true)
	opts.SetBlockSize(TWO_FIFTY_SIX_KILOBYTES)
	filter := levigo.NewBloomFilter(BLOOM_FILTER_BITS_PER_KEY)
	opts.SetFilterPolicy(filter)
	db, err := levigo.Open(dbDir, opts)
	if err != nil {
		return nil, err
	}

	ro := levigo.NewReadOptions()

	lastIdBytes, err2 := db.Get(ro, NEXT_ID_KEY)
	if err2 != nil {
		return nil, err2
	}

	lastId := uint64(0)
	if lastIdBytes != nil {
		lastId, err2 = binary.ReadUvarint(bytes.NewBuffer(lastIdBytes))
		if err2 != nil {
			return nil, err2
		}
	}

	wo := levigo.NewWriteOptions()

	return &LevelDbDatastore{db: db, lastIdUsed: lastId, readOptions: ro, writeOptions: wo}, nil
}
开发者ID:jondot,项目名称:influxdb,代码行数:31,代码来源:leveldb_datastore.go


示例12: NewLevelDBStore

func NewLevelDBStore(basePath string) LogeStore {

	var opts = levigo.NewOptions()
	opts.SetCreateIfMissing(true)
	db, err := levigo.Open(basePath, opts)

	if err != nil {
		panic(fmt.Sprintf("Can't open DB at %s: %v", basePath, err))
	}

	var store = &levelDBStore{
		basePath: basePath,
		db:       db,
		types:    spack.NewTypeSet(),

		writeQueue: make(chan *levelDBContext),
		flushed:    false,
	}

	store.types.LastTag = ldb_START_TAG
	store.loadTypeMetadata()
	go store.writer()

	return store
}
开发者ID:brendonh,项目名称:loge,代码行数:25,代码来源:leveldb.go


示例13: initOptions

func (db *DB) initOptions(cfg *Config) *levigo.Options {
	opts := levigo.NewOptions()

	opts.SetCreateIfMissing(true)

	if cfg.CacheSize > 0 {
		db.cache = levigo.NewLRUCache(cfg.CacheSize)
		opts.SetCache(db.cache)
	}

	//we must use bloomfilter
	db.filter = levigo.NewBloomFilter(defaultFilterBits)
	opts.SetFilterPolicy(db.filter)

	if !cfg.Compression {
		opts.SetCompression(levigo.NoCompression)
	}

	if cfg.BlockSize > 0 {
		opts.SetBlockSize(cfg.BlockSize)
	}

	if cfg.WriteBufferSize > 0 {
		opts.SetWriteBufferSize(cfg.WriteBufferSize)
	}

	return opts
}
开发者ID:kingpro,项目名称:golib,代码行数:28,代码来源:db.go


示例14: InitDB

func InitDB() (*levigo.DB, error) {
	opts := levigo.NewOptions()
	opts.SetCache(levigo.NewLRUCache(1024 * 1024))
	opts.SetCreateIfMissing(true)

	homedir := os.Getenv("HOME")
	dbdir := homedir + "/.overseer/db"
	os.MkdirAll(dbdir, 0700)

	db, err := levigo.Open(dbdir, opts)

	if err != nil {
		fmt.Println("Failed to open database", err)
		return nil, err
	}

	procs, err := ListProcs(db)
	for p, status := range procs {
		log.Printf("Proc ID: %d, status: %d", p, status)
		if isProcAlive(p) == false {
			setProcStatus(db, p, PROC_STOPPED)
		} else {
			setProcStatus(db, p, PROC_ALIVE)
		}
	}
	return db, nil
}
开发者ID:jdpaton,项目名称:Overseer,代码行数:27,代码来源:overseerdb.go


示例15: Destroy

func (db *DB) Destroy() {
	db.Close()
	opts := levigo.NewOptions()
	defer opts.Close()

	levigo.DestroyDatabase(db.cfg.Path, opts)
}
开发者ID:kingpro,项目名称:golib,代码行数:7,代码来源:db.go


示例16: open

func (c *cache) open(path string) error {
	opts := levigo.NewOptions()
	opts.SetCreateIfMissing(true)
	if c.options.CacheSizeM > 0 {
		c.cache = levigo.NewLRUCache(c.options.CacheSizeM * 1024 * 1024)
		opts.SetCache(c.cache)
	}
	if c.options.MaxOpenFiles > 0 {
		opts.SetMaxOpenFiles(c.options.MaxOpenFiles)
	}
	if c.options.BlockRestartInterval > 0 {
		opts.SetBlockRestartInterval(c.options.BlockRestartInterval)
	}
	if c.options.WriteBufferSizeM > 0 {
		opts.SetWriteBufferSize(c.options.WriteBufferSizeM * 1024 * 1024)
	}
	if c.options.BlockSizeK > 0 {
		opts.SetBlockSize(c.options.BlockSizeK * 1024)
	}

	db, err := levigo.Open(path, opts)
	if err != nil {
		return err
	}
	c.db = db
	c.wo = levigo.NewWriteOptions()
	c.ro = levigo.NewReadOptions()
	return nil
}
开发者ID:Rachine,项目名称:imposm3,代码行数:29,代码来源:osm.go


示例17: DestroyBucket

func (buckets *Database) DestroyBucket(name string) error {
	if _, ok := buckets.DBMap[name]; ok {
		delete(buckets.DBMap, name)
		return levigo.DestroyDatabase(name, levigo.NewOptions())
	}
	return nil
}
开发者ID:shyrobbiani,项目名称:levelupdb,代码行数:7,代码来源:databases.go


示例18: initDB

func initDB() (*levigo.DB, error) {
	opts := levigo.NewOptions()
	opts.SetCache(levigo.NewLRUCache(3 << 30))
	opts.SetCreateIfMissing(true)
	return levigo.Open(settings.dir+"/db", opts)

}
开发者ID:egelmex,项目名称:hgd2,代码行数:7,代码来源:main.go


示例19: NewLevelDbShardDatastore

func NewLevelDbShardDatastore(config *configuration.Configuration) (*LevelDbShardDatastore, error) {
	baseDbDir := filepath.Join(config.DataDir, SHARD_DATABASE_DIR)
	err := os.MkdirAll(baseDbDir, 0744)
	if err != nil {
		return nil, err
	}
	opts := levigo.NewOptions()
	opts.SetCache(levigo.NewLRUCache(config.LevelDbLruCacheSize))
	opts.SetCreateIfMissing(true)
	opts.SetBlockSize(64 * ONE_KILOBYTE)
	filter := levigo.NewBloomFilter(SHARD_BLOOM_FILTER_BITS_PER_KEY)
	opts.SetFilterPolicy(filter)
	opts.SetMaxOpenFiles(config.LevelDbMaxOpenFiles)

	return &LevelDbShardDatastore{
		baseDbDir:      baseDbDir,
		config:         config,
		shards:         make(map[uint32]*LevelDbShard),
		levelDbOptions: opts,
		maxOpenShards:  config.LevelDbMaxOpenShards,
		lastAccess:     make(map[uint32]int64),
		shardRefCounts: make(map[uint32]int),
		shardsToClose:  make(map[uint32]bool),
		pointBatchSize: config.LevelDbPointBatchSize,
	}, nil
}
开发者ID:sploit,项目名称:influxdb,代码行数:26,代码来源:leveldb_shard_datastore.go


示例20: NewDatabase

// Will panic if there is a problem with the database.
// Should only be called on server initialization.
func NewDatabase(databaseLocation string) *Database {
	buckets := new(Database)
	buckets.DBMap = make(map[string]*levigo.DB)
	buckets.BaseLocation = databaseLocation

	os.MkdirAll(databaseLocation, 0755)

	files, err := ioutil.ReadDir(databaseLocation)
	if err != nil {
		panic(err)
	}

	for _, file := range files {
		if !file.IsDir() || strings.HasPrefix(file.Name(), "_") {
			continue
		}
		opts := levigo.NewOptions()
		opts.SetCreateIfMissing(true)
		opts.SetCache(levigo.NewLRUCache(4194304))
		buckets.DBMap[file.Name()], err = levigo.Open(path.Join(databaseLocation, file.Name()), opts)
		if err != nil {
			panic(err)
		}
	}
	return buckets
}
开发者ID:shyrobbiani,项目名称:levelupdb,代码行数:28,代码来源:databases.go



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Golang levigo.NewReadOptions函数代码示例发布时间:2022-05-23
下一篇:
Golang levigo.NewLRUCache函数代码示例发布时间:2022-05-23
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap