本文整理汇总了Golang中github.com/jmhodges/levigo.NewBloomFilter函数的典型用法代码示例。如果您正苦于以下问题:Golang NewBloomFilter函数的具体用法?Golang NewBloomFilter怎么用?Golang NewBloomFilter使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了NewBloomFilter函数的16个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: 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
示例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: 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
示例4: 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
示例5: 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
示例6: Init
func (engine *LevelDbEngine) Init(config *proto.DBConfigs) error {
if config == nil {
return proto.ErrNoEngineConfig
}
if config.LevelDbConfigs == nil {
config.LevelDbConfigs = DefaultLevelDbConf
}
options := levigo.NewOptions()
// options.SetCreateIfMissing(config.CreateIfMissing)
options.SetCreateIfMissing(true)
options.SetParanoidChecks(config.LevelDbConfigs.ParanoidCheck)
if config.LevelDbConfigs.LRUCacheSize > 0 {
options.SetCache(levigo.NewLRUCache(config.LevelDbConfigs.LRUCacheSize))
}
if config.LevelDbConfigs.BloomFilterLength > 0 {
options.SetFilterPolicy(levigo.NewBloomFilter(config.LevelDbConfigs.BloomFilterLength))
}
engine.config = config
engine.dbOptions = options
db, err := levigo.Open(engine.config.DataPath, engine.dbOptions)
if err != nil {
return err
}
engine.db = db
return nil
}
开发者ID:dongzerun,项目名称:RationalDb,代码行数:26,代码来源:engine.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: NewLevelDbDatastore
func NewLevelDbDatastore(dbDir string) (Datastore, error) {
mainDbDir := filepath.Join(dbDir, DATABASE_DIR)
requestLogDir := filepath.Join(dbDir, REQUEST_LOG_BASE_DIR)
err := os.MkdirAll(mainDbDir, 0744)
if err != nil {
return nil, err
}
previousLog, err := NewRequestLogDb(getRequestLogDirForDate(requestLogDir, time.Now().Add(-time.Hour*24)))
if err != nil {
return nil, err
}
currentLog, err := NewRequestLogDb(getRequestLogDirForDate(requestLogDir, time.Now()))
if err != nil {
return nil, err
}
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()
leveldbStore := &LevelDbDatastore{
db: db,
lastIdUsed: lastId,
readOptions: ro,
writeOptions: wo,
requestLogDir: requestLogDir,
currentRequestLog: currentLog,
previousRequestLog: previousLog}
go leveldbStore.periodicallyRotateRequestLog()
return leveldbStore, nil
}
开发者ID:rn2dy,项目名称:influxdb,代码行数:58,代码来源:leveldb_datastore.go
示例9: openDB
func openDB() {
opts := levigo.NewOptions()
cache := levigo.NewLRUCache(128 * 1024 * 1024) // 128MB cache
opts.SetCache(cache)
filter := levigo.NewBloomFilter(10)
opts.SetFilterPolicy(filter)
opts.SetCreateIfMissing(true)
var err error
DB, err = levigo.Open("db", opts)
maybeFatal(err)
}
开发者ID:scozss,项目名称:setdb,代码行数:12,代码来源:db.go
示例10: NewTorrentDB
func NewTorrentDB(dir string) (*TorrentDB, error) {
opts := levigo.NewOptions()
filter := levigo.NewBloomFilter(10)
opts.SetFilterPolicy(filter)
opts.SetCreateIfMissing(true)
defer opts.Close()
db, err := levigo.Open(dir, opts)
if err != nil {
return nil, err
}
return &TorrentDB{db, nil, &sync.RWMutex{}}, nil
}
开发者ID:sdgoij,项目名称:TheDistributedBay,代码行数:12,代码来源:database.go
示例11: openDb
func openDb(path string) (*levigo.DB, error) {
opts := levigo.NewOptions()
opts.SetCreateIfMissing(true)
opts.SetFilterPolicy(levigo.NewBloomFilter(16))
opts.SetCache(levigo.NewLRUCache(10490000))
opts.SetMaxOpenFiles(500)
opts.SetWriteBufferSize(62914560)
opts.SetEnv(levigo.NewDefaultEnv())
dbn, err := levigo.Open(path, opts)
if err != nil {
return nil, fmt.Errorf("failed to open db at %s: %v\n", path, err)
}
return dbn, nil
}
开发者ID:uwedeportivo,项目名称:romba,代码行数:14,代码来源:clevel.go
示例12: NewRequestLogDb
func NewRequestLogDb(dir string) (*requestLogDb, error) {
err := os.MkdirAll(dir, 0744)
if err != nil {
return nil, err
}
opts := levigo.NewOptions()
opts.SetCache(levigo.NewLRUCache(ONE_MEGABYTE))
opts.SetCreateIfMissing(true)
opts.SetBlockSize(TWO_FIFTY_SIX_KILOBYTES)
filter := levigo.NewBloomFilter(BLOOM_FILTER_BITS_PER_KEY)
opts.SetFilterPolicy(filter)
db, err := levigo.Open(dir, opts)
if err != nil {
return nil, err
}
return &requestLogDb{dir: dir, db: db}, nil
}
开发者ID:rn2dy,项目名称:influxdb,代码行数:17,代码来源:leveldb_datastore.go
示例13: NewLevelDBPersistence
// NewLevelDBPersistence returns an initialized LevelDBPersistence object,
// created with the given options.
func NewLevelDBPersistence(o LevelDBOptions) (*LevelDBPersistence, error) {
options := levigo.NewOptions()
options.SetCreateIfMissing(true)
options.SetParanoidChecks(o.UseParanoidChecks)
compression := levigo.SnappyCompression
if o.Compression == Uncompressed {
compression = levigo.NoCompression
}
options.SetCompression(compression)
cache := levigo.NewLRUCache(o.CacheSizeBytes)
options.SetCache(cache)
filterPolicy := levigo.NewBloomFilter(10)
options.SetFilterPolicy(filterPolicy)
options.SetMaxOpenFiles(o.OpenFileAllowance)
storage, err := levigo.Open(o.Path, options)
if err != nil {
return nil, err
}
readOptions := levigo.NewReadOptions()
writeOptions := levigo.NewWriteOptions()
writeOptions.SetSync(o.FlushOnMutate)
return &LevelDBPersistence{
path: o.Path,
name: o.Name,
purpose: o.Purpose,
cache: cache,
filterPolicy: filterPolicy,
options: options,
readOptions: readOptions,
writeOptions: writeOptions,
storage: storage,
}, nil
}
开发者ID:pjjw,项目名称:prometheus,代码行数:46,代码来源:leveldb.go
示例14: applyConfig
func applyConfig(o *levigo.Options, config map[string]interface{}) (
*levigo.Options, error) {
cim, ok := config["create_if_missing"].(bool)
if ok {
o.SetCreateIfMissing(cim)
}
eie, ok := config["error_if_exists"].(bool)
if ok {
o.SetErrorIfExists(eie)
}
wbs, ok := config["write_buffer_size"].(float64)
if ok {
o.SetWriteBufferSize(int(wbs))
}
bs, ok := config["block_size"].(float64)
if ok {
o.SetBlockSize(int(bs))
}
bri, ok := config["block_restart_interval"].(float64)
if ok {
o.SetBlockRestartInterval(int(bri))
}
lcc, ok := config["lru_cache_capacity"].(float64)
if ok {
lruCache := levigo.NewLRUCache(int(lcc))
o.SetCache(lruCache)
}
bfbpk, ok := config["bloom_filter_bits_per_key"].(float64)
if ok {
bf := levigo.NewBloomFilter(int(bfbpk))
o.SetFilterPolicy(bf)
}
return o, nil
}
开发者ID:steveyen,项目名称:blevex,代码行数:42,代码来源:config.go
示例15: NewLevelDBPersistence
func NewLevelDBPersistence(storageRoot string, cacheCapacity, bitsPerBloomFilterEncoded int) (p *LevelDBPersistence, err error) {
options := levigo.NewOptions()
options.SetCreateIfMissing(true)
options.SetParanoidChecks(*leveldbUseParanoidChecks)
compression := levigo.NoCompression
if *leveldbUseSnappy {
compression = levigo.SnappyCompression
}
options.SetCompression(compression)
cache := levigo.NewLRUCache(cacheCapacity)
options.SetCache(cache)
filterPolicy := levigo.NewBloomFilter(bitsPerBloomFilterEncoded)
options.SetFilterPolicy(filterPolicy)
storage, err := levigo.Open(storageRoot, options)
if err != nil {
return
}
var (
readOptions = levigo.NewReadOptions()
writeOptions = levigo.NewWriteOptions()
)
writeOptions.SetSync(*leveldbFlushOnMutate)
p = &LevelDBPersistence{
cache: cache,
filterPolicy: filterPolicy,
options: options,
readOptions: readOptions,
storage: storage,
writeOptions: writeOptions,
}
return
}
开发者ID:bernerdschaefer,项目名称:prometheus,代码行数:38,代码来源:leveldb.go
示例16: main
func main() {
fmt.Printf("GOMAXPROCS is %d\n", getGOMAXPROCS())
confFile := "config.json"
conf, err := btcplex.LoadConfig(confFile)
if err != nil {
log.Fatalf("Can't load config file: %v", err)
}
pool, err := btcplex.GetSSDB(conf)
if err != nil {
log.Fatalf("Can't connect to SSDB: %v", err)
}
opts := levigo.NewOptions()
opts.SetCreateIfMissing(true)
filter := levigo.NewBloomFilter(10)
opts.SetFilterPolicy(filter)
ldb, err := levigo.Open(conf.LevelDbPath, opts) //alpha
defer ldb.Close()
if err != nil {
log.Fatalf("failed to load db: %s\n", err)
}
wo := levigo.NewWriteOptions()
//wo.SetSync(true)
defer wo.Close()
ro := levigo.NewReadOptions()
defer ro.Close()
wb := levigo.NewWriteBatch()
defer wb.Close()
conn := pool.Get()
defer conn.Close()
log.Println("Waiting 3 seconds before starting...")
time.Sleep(3 * time.Second)
latestheight := 0
log.Printf("Latest height: %v\n", latestheight)
running = true
cs := make(chan os.Signal, 1)
signal.Notify(cs, os.Interrupt)
go func() {
for sig := range cs {
running = false
log.Printf("Captured %v, waiting for everything to finish...\n", sig)
wg.Wait()
defer os.Exit(1)
}
}()
concurrency := 250
sem := make(chan bool, concurrency)
// Real network magic byte
blockchain, blockchainerr := blkparser.NewBlockchain(conf.BitcoindBlocksPath, [4]byte{0xF8, 0xB5, 0x03, 0xDF})
if blockchainerr != nil {
log.Fatalf("Error loading block file: ", blockchainerr)
}
block_height := uint(0)
for {
if !running {
break
}
wg.Add(1)
bl, er := blockchain.NextBlock()
if er != nil {
log.Println("Initial import done.")
break
}
bl.Raw = nil
if bl.Parent == "" {
block_height = uint(0)
conn.Do("HSET", fmt.Sprintf("block:%v:h", bl.Hash), "main", true)
conn.Do("HSET", fmt.Sprintf("block:%v:h", bl.Hash), "height", 0)
} else {
parentheight, _ := redis.Int(conn.Do("HGET", fmt.Sprintf("block:%v:h", bl.Parent), "height"))
block_height = uint(parentheight + 1)
conn.Do("HSET", fmt.Sprintf("block:%v:h", bl.Hash), "height", block_height)
prevheight := block_height - 1
prevhashtest := bl.Parent
prevnext := bl.Hash
for {
prevkey := fmt.Sprintf("height:%v", prevheight)
prevcnt, _ := redis.Int(conn.Do("ZCARD", prevkey))
// SSDB doesn't support negative slice yet
prevs, _ := redis.Strings(conn.Do("ZRANGE", prevkey, 0, prevcnt-1))
for _, cprevhash := range prevs {
if cprevhash == prevhashtest {
// current block parent
prevhashtest, _ = redis.String(conn.Do("HGET", fmt.Sprintf("block:%v:h", cprevhash), "parent"))
//.........这里部分代码省略.........
开发者ID:mazaclub,项目名称:btcplex,代码行数:101,代码来源:btcplex-import.go
注:本文中的github.com/jmhodges/levigo.NewBloomFilter函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论