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


Golang levigo.NewWriteOptions函数代码示例

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


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

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

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

示例4: Put

func (s *Store) Put(record *Record) error {
	s.mutex.Lock()
	defer s.mutex.Unlock()

	id := s.id + 1

	var buf bytes.Buffer
	enc := gob.NewEncoder(&buf)
	err := enc.Encode(record)
	if err != nil {
		panic(fmt.Sprintf("queued.Store: Error encoding record: %v", err))
	}

	wopts := levigo.NewWriteOptions()
	wopts.SetSync(s.sync)

	err = s.db.Put(wopts, key(id), buf.Bytes())
	if err != nil {
		return err
	}

	record.id = id
	s.id = id

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

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

示例6: ApplyToStateMachine

//func ApplyToStateMachine(kvs *KVserver) {
func (kvs *KVserver) ApplyToStateMachine() {
	kvs.P("Apply to State Machine Routine", 0, 0)
	for {
		logdata := <-kvs.ReplServer.Inbox()
		switch logdata.Data.(type) {
		case SMCommand:
			{
				com, _ := logdata.Data.(SMCommand)
				kvs.P("Received msg from State machine ", com.UserId, com.RequestId)
				if com.Command == "PUT" || com.Command == "put" {
					wo := levigo.NewWriteOptions()
					err := kvs.DataDb.Put(wo, []byte(com.Key), []byte(com.Value))
					if kvs.ReplServer.WhoIsLeader() == kvs.MyPid {
						res := new(SMResp)
						res.RequestId = com.RequestId
						kvs.P("I am leader so will allow to send to client, req id", com.UserId, com.RequestId)
						if err != nil {
							res.Value = []byte("ERROR_IN_DB")
							res.Error = 1
						} else {
							res.Value = []byte("SUCCESS")
							res.Error = 0
						}

						kvs.P("Finally as a Leader Will send to client, req id", com.UserId, res.RequestId)
						kvs.OuterComm.Outbox() <- &Envelope{Pid: com.UserId, MsgId: 0, Msg: res}
						kvs.RepComplete <- res //Now can accept the next command
					}
				}
			} //end of case for SMC
		} //end of switch
	}
}
开发者ID:kalloldey,项目名称:Raft,代码行数:34,代码来源:KVstore.go

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

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

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

示例10: Delete

// Delete the record by key
// Concurrent-safe
func (l *Level) Delete(key []byte) {
	l.mu.Lock()
	defer l.mu.Unlock()
	wo := levigo.NewWriteOptions()
	l.db.Delete(wo, key)
	wo.Close()
}
开发者ID:psychoss,项目名称:Go-Server-Source-Code,代码行数:9,代码来源:leveldb.go

示例11: Add

func (db *TorrentDB) Add(t *core.Torrent) error {
	db.lock.Lock()
	defer db.lock.Unlock()
	data, err := json.Marshal(t)
	wo := levigo.NewWriteOptions()
	defer wo.Close()
	err = db.db.Put(wo, []byte("t"+t.Hash), data)
	if err != nil {
		return err
	}

	bad := make([]int, 0)
	for i, w := range db.writers {
		select {
		case w <- t:
		default:
			close(w)
			bad = append(bad, i)
		}
	}

	for c, i := range bad {
		i = i - c
		db.writers = append(db.writers[:i], db.writers[i+1:]...)
	}
	return nil
}
开发者ID:sdgoij,项目名称:TheDistributedBay,代码行数:27,代码来源:database.go

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

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

示例14: UpdateDB

func UpdateDB(k string, v interface{}, dbName string) error {
	dbfile, err := getDbName(dbName)
	if err != nil {
		return err
	}

	dbfile = DBRoot + "/" + dbfile

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

	data, err := json.Marshal(v)
	if err != nil {
		return err
	}

	wo := levigo.NewWriteOptions()
	err = db.Delete(wo, []byte(k))
	if err != nil {
		return err
	}

	err = db.Put(wo, []byte(k), data)
	if err != nil {
		return err
	}

	//db.Close()
	return nil
}
开发者ID:nangong92t,项目名称:go_src,代码行数:32,代码来源:leveldb.go

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


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