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

Golang levigo.NewReadOptions函数代码示例

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

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



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

示例1: 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


示例2: 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


示例3: newSnapshot

func newSnapshot(db *DB) *Snapshot {
	s := new(Snapshot)
	s.db = db
	s.s = db.db.NewSnapshot()

	s.readOpts = levigo.NewReadOptions()
	s.readOpts.SetSnapshot(s.s)

	s.iteratorOpts = levigo.NewReadOptions()
	s.iteratorOpts.SetSnapshot(s.s)
	s.iteratorOpts.SetFillCache(false)

	return s
}
开发者ID:kingpro,项目名称:golib,代码行数:14,代码来源:snapshot.go


示例4: OpenWithConfig

func OpenWithConfig(cfg *Config) (*DB, error) {
	db := new(DB)
	db.cfg = cfg

	db.opts = db.initOptions(cfg)

	db.readOpts = levigo.NewReadOptions()
	db.writeOpts = levigo.NewWriteOptions()
	db.iteratorOpts = levigo.NewReadOptions()
	db.iteratorOpts.SetFillCache(false)

	var err error
	db.db, err = levigo.Open(cfg.Path, db.opts)
	return db, err
}
开发者ID:kingpro,项目名称:golib,代码行数:15,代码来源:db.go


示例5: AddProc

func AddProc(procID int, db *levigo.DB) error {
	ro := levigo.NewReadOptions()
	wo := levigo.NewWriteOptions()

	data, err := db.Get(ro, []byte("procs"))
	spdata := bytes.Split(data, []byte(":"))

	for i, e := range spdata {

		if string(e) != "" {
			fmt.Println("ProcID: #", i, string(e))
			pid, err := strconv.Atoi(string(e))
			if err != nil {
				return err
			}
			if pid == procID {
				return errors.New("Process already exists")
			}
			if isProcAlive(pid) == false {
				removeProc(pid, db)
			}
		}

		if err != nil {
			return err
		}
	}

	strdata := string(data)
	strdata = strdata + ":" + strconv.Itoa(procID)

	err = db.Put(wo, []byte("procs"), []byte(strdata))
	return err
}
开发者ID:jdpaton,项目名称:Overseer,代码行数:34,代码来源:overseerdb.go


示例6: GetAllKeysByAnchor

func (l *Level) GetAllKeysByAnchor(anchor []byte) []byte {
	l.mu.Lock()
	defer l.mu.Unlock()
	var buffer bytes.Buffer
	ro := levigo.NewReadOptions()
	defer ro.Close()
	ro.SetFillCache(false)
	it := l.db.NewIterator(ro)
	defer it.Close()
	buffer.WriteByte('[')
	it.Seek(anchor)
	if !it.Valid() {
		return nil
	}
	it.Next()
	for it.Valid() && bytes.HasPrefix(it.Key(), anchor) {
		buffer.Write(it.Value())
		buffer.WriteByte(',')
		it.Next()

	}
	bs := buffer.Bytes()
	bs = bytes.TrimRight(bs, ",")
	bs = append(bs, ']')
	if err := it.GetError(); err != nil {
		fmt.Println(err)
	}
	return bs
}
开发者ID:psychoss,项目名称:Go-Server-Source-Code,代码行数:29,代码来源:leveldb.go


示例7: 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


示例8: 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


示例9: DeleteAllRecords

func (store *LevelDbStore) DeleteAllRecords() error {
	store.dbOpenLock.Lock()
	defer store.dbOpenLock.Unlock()

	if store.readOptions == nil && store.writeOptions == nil {
		panic("You may only call DeleteAllRecords after starting reading or writing")
	}

	writeOptions := store.writeOptions
	if writeOptions == nil {
		writeOptions = levigo.NewWriteOptions()
		defer writeOptions.Close()
	}
	readOptions := store.readOptions
	if readOptions == nil {
		readOptions = levigo.NewReadOptions()
		defer readOptions.Close()
	}
	it := store.db.NewIterator(readOptions)
	defer it.Close()
	it.SeekToFirst()
	for ; it.Valid(); it.Next() {
		if err := store.db.Delete(writeOptions, it.Key()); err != nil {
			return fmt.Errorf("Error clearing keys from database: %v", err)
		}
	}
	if err := it.GetError(); err != nil {
		return fmt.Errorf("Error iterating through database: %v", err)
	}
	return nil
}
开发者ID:sburnett,项目名称:transformer,代码行数:31,代码来源:leveldb.go


示例10: 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


示例11: replayFromLog

func (self *LevelDbDatastore) replayFromLog(seekKey []byte, requestLog *requestLogDb, yield func(*[]byte) error) error {
	ro := levigo.NewReadOptions()
	defer ro.Close()
	ro.SetFillCache(false)
	it := requestLog.db.NewIterator(ro)
	defer it.Close()

	startingKey := seekKey[:len(seekKey)-8]
	sliceTo := len(startingKey)
	it.Seek(seekKey)
	if it.Valid() {
		if bytes.Equal(it.Key(), seekKey) {
			it.Next()
		}
	}

	for it = it; it.Valid(); it.Next() {
		k := it.Key()
		if !bytes.Equal(k[:sliceTo], startingKey) {
			return nil
		}
		b := it.Value()
		err := yield(&b)
		if err != nil {
			return err
		}
	}
	return nil
}
开发者ID:ronaldevers,项目名称:influxdb,代码行数:29,代码来源:leveldb_datastore.go


示例12: ReadDBCount

// Get the data count from leveldb
//
// @param string dbName The levelDb database name.
// @param func   filter The condition filter function.
//
func ReadDBCount(dbName, condition string) (int, error) {
	dbfile, err := getDbName(dbName)
	if err != nil {
		return 0, err
	}

	dbfile = DBRoot + "/" + dbfile

	db, err := openDB(dbfile)
	if err != nil {
		return 0, err
	}

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

	foundCnt := 0
	for it.Seek([]byte(condition)); it.Valid(); it.Next() {
		foundCnt++
	}

	if err := it.GetError(); err != nil {
		return 0, err
	}

	return foundCnt, nil
}
开发者ID:nangong92t,项目名称:go_src,代码行数:34,代码来源:leveldb.go


示例13: 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


示例14: getPlaylistFromDB

func getPlaylistFromDB(db *levigo.DB) []playListItem {
	log.Println("Loading Playlist from file...")

	ro := levigo.NewReadOptions()

	data, err := db.Get(ro, []byte("playlist"))
	if err != nil {
		log.Fatal(err)
	}

	p := bytes.NewBuffer(data)

	dec := gob.NewDecoder(p)

	var playlist []playListItem
	//we must decode into a pointer, so we'll take the address of e
	err = dec.Decode(&playlist)
	if err != nil {
		log.Print(err)
		playlist = []playListItem{}
	}

	log.Println("Loaded ", len(playlist), " items into playlist")
	log.Println(playlist)
	return playlist

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


示例15: Test_DelKey

func Test_DelKey(t *testing.T) {
	_key, _val, expectedVal := "name", "levigoNS", ""
	dbpath := "/tmp/delete-this-leveldb"
	db := CreateDB(dbpath)

	writer := levigo.NewWriteOptions()
	defer writer.Close()

	keyname := []byte(_key)
	value := []byte(_val)
	err := db.Put(writer, keyname, value)
	if err != nil {
		t.Error("Fail: (DelKey) Pushing key " + _key + " for value " + _val + " failed")
	}

	statusDelete := DelKey(_key, db)

	reader := levigo.NewReadOptions()
	defer reader.Close()

	resultVal, err := db.Get(reader, []byte(_key))
	if err != nil {
		t.Error("Fail: (DelKey) Reading key " + _key + " failed")
	}
	if string(resultVal) != expectedVal {
		t.Error("Fail: DelKey sets " + string(resultVal))
	}
	if !statusDelete {
		t.Error("Fail: DelKey returns False status")
	}

	CloseAndDeleteDB(dbpath, db)
}
开发者ID:carriercomm,项目名称:levigoNS,代码行数:33,代码来源:leveldb_test.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: GetTx

// Fetch a Tx by hash
func GetTx(db *levigo.DB, txHash string) (tx *Tx, err error) {
	ro := levigo.NewReadOptions()
	defer ro.Close()
	txKey, blockErr := db.Get(ro, []byte(fmt.Sprintf("tx!%s", txHash)))
	if blockErr != nil {
		err = errors.New("Tx not found")
		return
	}

	txData, blockErr := db.Get(ro, txKey)
	if blockErr != nil {
		err = errors.New("Tx not found")
		return
	}

	tx = new(Tx)
	err = json.Unmarshal(txData, tx)
	if err != nil {
		return
	}

	for txo_index, txo := range tx.TxOuts {
		txo.Spent, _ = GetTxoSpent(db, txo.Addr, tx.Hash, txo_index)
	}

	return
}
开发者ID:pombredanne,项目名称:btcplex,代码行数:28,代码来源:tx.go


示例18: loadUsers

func loadUsers(db *levigo.DB) map[string]User {
	log.Println("Loading Users from file...")

	ro := levigo.NewReadOptions()

	data, err := db.Get(ro, []byte("Users"))
	if err != nil {
		log.Fatal(err)
	}

	p := bytes.NewBuffer(data)

	dec := gob.NewDecoder(p)

	var users map[string]User
	//we must decode into a pointer, so we'll take the address of e
	err = dec.Decode(&users)
	if err != nil {
		log.Print(err)
		users = map[string]User{}
	}

	log.Println("Loaded ", len(users), " users")
	log.Printf("%+v", users)
	return users

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


示例19: ProcessInput

func (dw *DbWriter) ProcessInput() {
	wo := levigo.NewWriteOptions()
	ro := levigo.NewReadOptions()
	defer wo.Close()
	defer ro.Close()

	var buffer bytes.Buffer
	enc := gob.NewEncoder(&buffer)
	enc.Encode(Minute{})

	dec := gob.NewDecoder(&buffer)
	var m Minute
	dec.Decode(&m)
	buffer.Reset()

	for input := range dw.Input {
		//first write minutes
		key := []byte(input.Key)
		err := enc.Encode(input.Minute)
		if err != nil {
			//there is smth really wrong...some kind of help cry would good
			panic(err)
		}
		payload := buffer.Bytes()
		//log.Println(len(payload))
		//save
		dw.Db.Put(wo, key, payload)
		var m Minute
		dec.Decode(&m)

		log.Println(m)
		buffer.Reset()
	}
}
开发者ID:roa,项目名称:go_leveldb_server,代码行数:34,代码来源:db_writer.go


示例20: replayFromLog

func (self *LevelDbDatastore) replayFromLog(seekKey WALKey, requestLog *requestLogDb, yield func(*[]byte) error) error {
	ro := levigo.NewReadOptions()
	defer ro.Close()
	ro.SetFillCache(false)
	it := requestLog.db.NewIterator(ro)
	defer it.Close()

	it.Seek(seekKey)
	if it.Valid() {
		if bytes.Equal(it.Key(), seekKey) {
			it.Next()
		}
	}

	for it = it; it.Valid(); it.Next() {
		key := NewWALKeyFromBytes(it.Key())
		if !key.EqualsIgnoreSequenceNumber(seekKey) {
			return nil
		}
		b := it.Value()
		err := yield(&b)
		if err != nil {
			return err
		}
	}
	return nil
}
开发者ID:rn2dy,项目名称:influxdb,代码行数:27,代码来源:leveldb_datastore.go



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
Golang levigo.NewWriteBatch函数代码示例发布时间:2022-05-23
下一篇:
Golang levigo.NewOptions函数代码示例发布时间: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