本文整理汇总了Golang中github.com/jmhodges/levigo.Open函数的典型用法代码示例。如果您正苦于以下问题:Golang Open函数的具体用法?Golang Open怎么用?Golang Open使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了Open函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: Format
// formats a new filesystem in the given data dir
func Format(dataDir string, rootUid, rootGid uint32) error {
// wipe out previous
err := os.RemoveAll(dataDir)
if err != nil {
return err
}
// create
err = os.Mkdir(dataDir, 0755)
if err != nil {
return fmt.Errorf("issue creating namenode home dir: %s\n", err.Error())
}
err = os.Mkdir(dataDir+"/"+dir_inodb, 0755)
if err != nil {
return fmt.Errorf("issue creating inodb parent dir: %s\n", err.Error())
}
err = os.Mkdir(dataDir+"/"+dir_counters, 0755)
if err != nil {
return fmt.Errorf("issue creating counters parent dir: %s\n", err.Error())
}
opts := levigo.NewOptions()
defer opts.Close()
opts.SetCreateIfMissing(true)
// create inodb
db, err := levigo.Open(dataDir+"/"+dir_inodb, opts)
if err != nil {
return err
}
// add root node
ino := maggiefs.NewInode(1, maggiefs.FTYPE_DIR, 0755, rootUid, rootGid)
binSize := ino.BinSize()
inoBytes := make([]byte, binSize)
ino.ToBytes(inoBytes)
rootNodeId := make([]byte, 8)
binary.LittleEndian.PutUint64(rootNodeId, 1)
db.Put(WriteOpts, rootNodeId, inoBytes)
db.Close()
db, err = levigo.Open(dataDir+"/"+dir_counters, opts)
if err != nil {
return err
}
// put 1 for inode counter so other nodes are higher
key := []byte(COUNTER_INODE)
val := make([]byte, 8)
binary.LittleEndian.PutUint64(val, 1)
err = db.Put(WriteOpts, key, val)
if err != nil {
return err
}
db.Close()
return nil
}
开发者ID:jonpugh,项目名称:maggiefs,代码行数:55,代码来源:namedata.go
示例2: 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
示例3: 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
示例4: 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
示例5: 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
示例6: 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
示例7: 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
示例8: 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
示例9: 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
示例10: 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
示例11: 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
示例12: 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
示例13: 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
示例14: 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
示例15: GetOrCreateShard
func (self *LevelDbShardDatastore) GetOrCreateShard(id uint32) (cluster.LocalShardDb, error) {
now := time.Now().Unix()
self.shardsLock.Lock()
defer self.shardsLock.Unlock()
db := self.shards[id]
self.lastAccess[id] = now
if db != nil {
self.incrementShardRefCountAndCloseOldestIfNeeded(id)
return db, nil
}
dbDir := self.shardDir(id)
log.Info("DATASTORE: opening or creating shard %s", dbDir)
ldb, err := levigo.Open(dbDir, self.levelDbOptions)
if err != nil {
return nil, err
}
db, err = NewLevelDbShard(ldb, self.pointBatchSize)
if err != nil {
return nil, err
}
self.shards[id] = db
self.incrementShardRefCountAndCloseOldestIfNeeded(id)
return db, nil
}
开发者ID:sploit,项目名称:influxdb,代码行数:28,代码来源:leveldb_shard_datastore.go
示例16: 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
示例17: 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
示例18: 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
示例19: 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")
}
if path == "" {
return nil, os.ErrInvalid
}
rv := Store{
path: path,
opts: levigo.NewOptions(),
mo: mo,
}
_, err := applyConfig(rv.opts, config)
if err != nil {
return nil, err
}
rv.db, err = levigo.Open(rv.path, rv.opts)
if err != nil {
return nil, err
}
return &rv, nil
}
开发者ID:blevesearch,项目名称:blevex,代码行数:26,代码来源:store.go
示例20: 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
注:本文中的github.com/jmhodges/levigo.Open函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论