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


Golang storage.OpenFile函数代码示例

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


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

示例1: NewMDServerLocal

// NewMDServerLocal constructs a new MDServerLocal object that stores
// data in the directories specified as parameters to this function.
func NewMDServerLocal(config Config, handleDbfile string, mdDbfile string,
	branchDbfile string) (*MDServerLocal, error) {

	handleStorage, err := storage.OpenFile(handleDbfile)
	if err != nil {
		return nil, err
	}

	mdStorage, err := storage.OpenFile(mdDbfile)
	if err != nil {
		return nil, err
	}

	branchStorage, err := storage.OpenFile(branchDbfile)
	if err != nil {
		return nil, err
	}

	// Always use memory for the lock storage, so it gets wiped after
	// a restart.
	lockStorage := storage.NewMemStorage()

	return newMDServerLocalWithStorage(config, handleStorage, mdStorage,
		branchStorage, lockStorage)
}
开发者ID:keybase,项目名称:kbfs-beta,代码行数:27,代码来源:mdserver_local.go

示例2: openDBBench

func openDBBench(b *testing.B) *dbBench {
	_, err := os.Stat(benchDB)
	if err == nil {
		err = os.RemoveAll(benchDB)
		if err != nil {
			b.Fatal("cannot remove old db: ", err)
		}
	}

	p := &dbBench{b: b}
	p.stor, err = storage.OpenFile(benchDB)
	if err != nil {
		b.Fatal("cannot open stor: ", err)
	}

	p.o = &opt.Options{
		Flag: opt.OFCreateIfMissing,
	}
	p.ro = &opt.ReadOptions{}
	p.wo = &opt.WriteOptions{}

	p.db, err = Open(p.stor, p.o)
	if err != nil {
		b.Fatal("cannot open db: ", err)
	}

	runtime.GOMAXPROCS(runtime.NumCPU())
	return p
}
开发者ID:JensRantil,项目名称:goleveldb,代码行数:29,代码来源:bench_test.go

示例3: openDBBench

func openDBBench(b *testing.B, noCompress bool) *dbBench {
	_, err := os.Stat(benchDB)
	if err == nil {
		err = os.RemoveAll(benchDB)
		if err != nil {
			b.Fatal("cannot remove old db: ", err)
		}
	}

	p := &dbBench{
		b:  b,
		o:  &opt.Options{},
		ro: &opt.ReadOptions{},
		wo: &opt.WriteOptions{},
	}
	p.stor, err = storage.OpenFile(benchDB, false)
	if err != nil {
		b.Fatal("cannot open stor: ", err)
	}
	if noCompress {
		p.o.Compression = opt.NoCompression
	}

	p.db, err = Open(p.stor, p.o)
	if err != nil {
		b.Fatal("cannot open db: ", err)
	}

	return p
}
开发者ID:syndtr,项目名称:goleveldb,代码行数:30,代码来源:bench_test.go

示例4: OpenLeveldb

// Open will open and possibly create a datastore at the given directory.
func OpenLeveldb(path string, create bool, kvOpts Options) (db Engine, err error) {
	goOpts := kvOpts.(*goKeyValueOptions)
	if goOpts == nil {
		err = fmt.Errorf("Nil pointer passed in as key-value options to Openleveldb()!")
		return
	}

	leveldb_stor, err := storage.OpenFile(path)
	if err != nil {
		return
	}

	// Set the CreateIfMissing flag.
	if create {
		goOpts.Options.Flag |= opt.OFCreateIfMissing
		goOpts.Options.Flag |= opt.OFErrorIfExist
	}

	// Open the leveldb
	leveldb_db, err := leveldb.Open(leveldb_stor, goOpts.Options)
	if err != nil {
		return
	}
	db = &goLDB{
		directory: path,
		opts:      *goOpts, // We want a copy at time of Open()
		stor:      leveldb_stor,
		ldb:       leveldb_db,
	}
	return
}
开发者ID:hanslovsky,项目名称:dvid,代码行数:32,代码来源:leveldbgo.go

示例5: TestDb_CreateReopenDbOnFile

func TestDb_CreateReopenDbOnFile(t *testing.T) {
	dbpath := filepath.Join(os.TempDir(), fmt.Sprintf("goleveldbtestCreateReopenDbOnFile-%d", os.Getuid()))
	if err := os.RemoveAll(dbpath); err != nil {
		t.Fatal("cannot remove old db: ", err)
	}
	defer os.RemoveAll(dbpath)

	for i := 0; i < 3; i++ {
		stor, err := storage.OpenFile(dbpath)
		if err != nil {
			t.Fatalf("(%d) cannot open storage: %s", i, err)
		}
		db, err := Open(stor, &opt.Options{Flag: opt.OFCreateIfMissing})
		if err != nil {
			t.Fatalf("(%d) cannot open db: %s", i, err)
		}
		if err := db.Put([]byte("foo"), []byte("bar"), &opt.WriteOptions{}); err != nil {
			t.Fatalf("(%d) cannot write to db: %s", i, err)
		}
		if err := db.Close(); err != nil {
			t.Fatalf("(%d) cannot close db: %s", i, err)
		}
		if err := stor.Close(); err != nil {
			t.Fatalf("(%d) cannot close storage: %s", i, err)
		}
	}
}
开发者ID:29n,项目名称:goleveldb,代码行数:27,代码来源:db_test.go

示例6: NewStorage

func NewStorage() *Storage {
	var stor storage.Storage
	var closeFn func() error
	if storageUseFS {
		for {
			storageMu.Lock()
			num := storageNum
			storageNum++
			storageMu.Unlock()
			path := filepath.Join(os.TempDir(), fmt.Sprintf("goleveldb-test%d0%d0%d", os.Getuid(), os.Getpid(), num))
			if _, err := os.Stat(path); os.IsNotExist(err) {
				stor, err = storage.OpenFile(path)
				ExpectWithOffset(1, err).NotTo(HaveOccurred(), "creating storage at %s", path)
				closeFn = func() error {
					if storageKeepFS {
						return nil
					}
					return os.RemoveAll(path)
				}
				break
			}
		}
	} else {
		stor = storage.NewMemStorage()
	}
	s := &Storage{
		Storage: stor,
		closeFn: closeFn,
		opens:   make(map[uint64]bool),
	}
	s.stallCond.L = &s.mu
	return s
}
开发者ID:CedarLogic,项目名称:go-ethereum,代码行数:33,代码来源:storage.go

示例7: main

// Main method. Will panic if things are so bad that the application
// will not start.
func main() {
	flag.Parse()

	log.Println("Event store to use:", *eventStorePath)
	log.Println("Command socket path:", *commandSocketZPath)
	log.Println("Event publishing socket path:", *eventPublishZPath)
	log.Println()

	var stor storage.Storage
	if *inMemoryStore {
		log.Println("!!! WARNING: Using in-memory store.")
		log.Println("!!! Events will not be persisted.")
		log.Println()
		stor = &storage.MemStorage{}
	} else {
		stor, err := storage.OpenFile(*eventStorePath)
		if err != nil {
			log.Panicln("could not create DB storage")
		}
		defer stor.Close()
	}

	estore, err := eventstore.New(stor)
	if err != nil {
		log.Panicln(os.Stderr, "could not create event store")
	}

	context, err := zmq.NewContext()
	if err != nil {
		log.Panicln(err)
	}

	initParams := server.InitParams{
		Store:              estore,
		CommandSocketZPath: commandSocketZPath,
		EvPubSocketZPath:   eventPublishZPath,
		ZMQContext:         context,
	}
	serv, err := server.New(&initParams)
	if err != nil {
		panic(err.Error())
	}

	sigchan := make(chan os.Signal, 5)
	serverStopper := func() {
		sig := <-sigchan
		if sig == os.Interrupt {
			serv.Stop()
		}
	}
	go serverStopper()
	signal.Notify(sigchan)

	serv.Start()
	serv.Wait()
}
开发者ID:JensRantil,项目名称:gorewind,代码行数:58,代码来源:gorewind.go

示例8: OpenDatabase

func (ulevel) OpenDatabase(name string, o level.UnderlyingOptions) (dtb level.UnderlyingDatabase, err error) {
	stor, err := storage.OpenFile(name)
	if err != nil {
		return
	}
	var dtbe *leveldb.DB
	dtbe, err = leveldb.Open(stor, o.(opts).Options)
	dtb = db{dtbe, stor}
	return
}
开发者ID:TShadwell,项目名称:level,代码行数:10,代码来源:golevel.go

示例9: newTestStorage

func newTestStorage(t *testing.T) *testStorage {
	var stor storage.Storage
	var closeFn func() error
	if tsFS {
		for {
			tsMU.Lock()
			num := tsNum
			tsNum++
			tsMU.Unlock()
			path := filepath.Join(os.TempDir(), fmt.Sprintf("goleveldb-test%d0%d0%d", os.Getuid(), os.Getpid(), num))
			if _, err := os.Stat(path); err != nil {
				stor, err = storage.OpenFile(path)
				if err != nil {
					t.Fatalf("F: cannot create storage: %v", err)
				}
				t.Logf("I: storage created: %s", path)
				closeFn = func() error {
					for _, name := range []string{"LOG.old", "LOG"} {
						f, err := os.Open(filepath.Join(path, name))
						if err != nil {
							continue
						}
						if log, err := ioutil.ReadAll(f); err != nil {
							t.Logf("---------------------- %s ----------------------", name)
							t.Logf("cannot read log: %v", err)
							t.Logf("---------------------- %s ----------------------", name)
						} else if len(log) > 0 {
							t.Logf("---------------------- %s ----------------------\n%s", name, string(log))
							t.Logf("---------------------- %s ----------------------", name)
						}
						f.Close()
					}
					if tsKeepFS {
						return nil
					}
					return os.RemoveAll(path)
				}

				break
			}
		}
	} else {
		stor = storage.NewMemStorage()
	}
	ts := &testStorage{
		t:       t,
		Storage: stor,
		closeFn: closeFn,
		opens:   make(map[uint64]bool),
	}
	ts.cond.L = &ts.mu
	return ts
}
开发者ID:pombredanne,项目名称:goleveldb,代码行数:53,代码来源:storage_test.go

示例10: NewMDServerLocal

// NewMDServerLocal constructs a new MDServerLocal object that stores
// data in the directories specified as parameters to this function.
func NewMDServerLocal(config Config, handleDbfile string, mdDbfile string,
	branchDbfile string) (*MDServerLocal, error) {

	handleStorage, err := storage.OpenFile(handleDbfile)
	if err != nil {
		return nil, err
	}

	mdStorage, err := storage.OpenFile(mdDbfile)
	if err != nil {
		return nil, err
	}

	branchStorage, err := storage.OpenFile(branchDbfile)
	if err != nil {
		return nil, err
	}

	return newMDServerLocalWithStorage(config, handleStorage, mdStorage,
		branchStorage)
}
开发者ID:gozes,项目名称:kbfs-beta,代码行数:23,代码来源:mdserver_local.go

示例11: RecoverFile

// RecoverFile recovers and opens a DB with missing or corrupted manifest files
// for the given path. It will ignore any manifest files, valid or not.
// The DB must already exist or it will returns an error.
// Also, Recover will ignore ErrorIfMissing and ErrorIfExist options.
//
// RecoverFile uses standard file-system backed storage implementation as desribed
// in the leveldb/storage package.
//
// The returned DB instance is goroutine-safe.
// The DB must be closed after use, by calling Close method.
func RecoverFile(path string, o *opt.Options) (db *DB, err error) {
	stor, err := storage.OpenFile(path)
	if err != nil {
		return
	}
	db, err = Recover(stor, o)
	if err != nil {
		stor.Close()
	} else {
		db.closer = stor
	}
	return
}
开发者ID:Blueprint-Marketing,项目名称:syncthing,代码行数:23,代码来源:db.go

示例12: OpenFile

// OpenFile opens or creates a DB for the given path.
// The DB will be created if not exist, unless ErrorIfMissing is true.
// Also, if ErrorIfExist is true and the DB exist OpenFile will returns
// os.ErrExist error.
//
// OpenFile uses standard file-system backed storage implementation as
// desribed in the leveldb/storage package.
//
// OpenFile will return an error with type of ErrCorrupted if corruption
// detected in the DB. Corrupted DB can be recovered with Recover
// function.
//
// The returned DB instance is goroutine-safe.
// The DB must be closed after use, by calling Close method.
func OpenFile(path string, o *opt.Options) (db *DB, err error) {
	stor, err := storage.OpenFile(path, o.GetReadOnly())
	if err != nil {
		return
	}
	db, err = Open(stor, o)
	if err != nil {
		stor.Close()
	} else {
		db.closer = stor
	}
	return
}
开发者ID:KosyanMedia,项目名称:burlesque,代码行数:27,代码来源:db.go

示例13: OpenFile

// OpenFile open or create database from given file.
//
// This is alias of:
//	stor, err := storage.OpenFile("path/to/db")
//	...
//	db, err := Open(stor, &opt.Options{})
//	...
func OpenFile(path string, o *opt.Options) (db *DB, err error) {
	stor, err := storage.OpenFile(path)
	if err != nil {
		return
	}
	db, err = Open(stor, o)
	if err == nil {
		db.closeCb = func() error {
			return stor.Close()
		}
	}
	return
}
开发者ID:29n,项目名称:goleveldb,代码行数:20,代码来源:db.go

示例14: RecoverDB

// RecoverDB recovers LevelDB database from corruption
func RecoverDB(path string) error {
	stor, err := storage.OpenFile(path, false)
	if err != nil {
		return err
	}

	db, err := leveldb.Recover(stor, nil)
	if err != nil {
		return err
	}

	db.Close()
	stor.Close()

	return nil
}
开发者ID:pombredanne,项目名称:aptly,代码行数:17,代码来源:leveldb.go

示例15: Main

func (ec *recoverCmd) Main() {
	ec.configuredCmd.Main()
	InitLog()
	path := openpgp.Config().Settings.TomlTree.Get("symflux.recon.leveldb.path").(string)
	stor, err := storage.OpenFile(path)
	if err != nil {
		die(err)
	}
	log.Println("database storage opened, recovering...")
	db, err := leveldb.Recover(stor, nil)
	if err != nil {
		die(err)
	}
	log.Println("recovery complete")
	db.Close()
}
开发者ID:pruthvirajsinh,项目名称:prlpks,代码行数:16,代码来源:recover.go


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