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


Golang leveldb.Open函数代码示例

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


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

示例1: newMDServerLocalWithStorage

func newMDServerLocalWithStorage(config Config, handleStorage, mdStorage,
	branchStorage, lockStorage storage.Storage) (*MDServerLocal, error) {
	handleDb, err := leveldb.Open(handleStorage, leveldbOptions)
	if err != nil {
		return nil, err
	}
	mdDb, err := leveldb.Open(mdStorage, leveldbOptions)
	if err != nil {
		return nil, err
	}
	branchDb, err := leveldb.Open(branchStorage, leveldbOptions)
	if err != nil {
		return nil, err
	}
	locksDb, err := leveldb.Open(lockStorage, leveldbOptions)
	if err != nil {
		return nil, err
	}
	log := config.MakeLogger("")
	mdserv := &MDServerLocal{config, handleDb, mdDb, branchDb, log,
		&sync.Mutex{}, locksDb, &sync.Mutex{},
		make(map[TlfID]map[*MDServerLocal]chan<- error),
		make(map[TlfID]*MDServerLocal), new(bool), &sync.RWMutex{}}
	return mdserv, nil
}
开发者ID:keybase,项目名称:kbfs-beta,代码行数:25,代码来源:mdserver_local.go

示例2: BenchmarkRequest

func BenchmarkRequest(b *testing.B) {
	db, _ := leveldb.Open(storage.NewMemStorage(), nil)
	m := NewModel("/tmp", nil, "syncthing", "dev", db)
	m.AddRepo(config.RepositoryConfiguration{ID: "default", Directory: "testdata"})
	m.ScanRepo("default")

	const n = 1000
	files := make([]protocol.FileInfo, n)
	t := time.Now().Unix()
	for i := 0; i < n; i++ {
		files[i] = protocol.FileInfo{
			Name:     fmt.Sprintf("file%d", i),
			Modified: t,
			Blocks:   []protocol.BlockInfo{{0, 100, []byte("some hash bytes")}},
		}
	}

	fc := FakeConnection{
		id:          node1,
		requestData: []byte("some data to return"),
	}
	m.AddConnection(fc, fc)
	m.Index(node1, "default", files)

	b.ResetTimer()
	for i := 0; i < b.N; i++ {
		data, err := m.requestGlobal(node1, "default", files[i%n].Name, 0, 32, nil)
		if err != nil {
			b.Error(err)
		}
		if data == nil {
			b.Error("nil data")
		}
	}
}
开发者ID:rom1504,项目名称:syncthing,代码行数:35,代码来源:model_test.go

示例3: Benchmark10kUpdateChg

func Benchmark10kUpdateChg(b *testing.B) {
	var remote []protocol.FileInfo
	for i := 0; i < 10000; i++ {
		remote = append(remote, protocol.FileInfo{Name: fmt.Sprintf("file%d", i), Version: 1000})
	}

	ldb, err := leveldb.Open(storage.NewMemStorage(), nil)
	if err != nil {
		b.Fatal(err)
	}

	m := db.NewFileSet("test", ldb)
	m.Replace(remoteDevice0, remote)

	var local []protocol.FileInfo
	for i := 0; i < 10000; i++ {
		local = append(local, protocol.FileInfo{Name: fmt.Sprintf("file%d", i), Version: 1000})
	}

	m.ReplaceWithDelete(protocol.LocalDeviceID, local)

	b.ResetTimer()
	for i := 0; i < b.N; i++ {
		b.StopTimer()
		for j := range local {
			local[j].Version++
		}
		b.StartTimer()
		m.Update(protocol.LocalDeviceID, local)
	}
}
开发者ID:qbit,项目名称:syncthing,代码行数:31,代码来源:set_test.go

示例4: TestUpdateToInvalid

func TestUpdateToInvalid(t *testing.T) {
	ldb, err := leveldb.Open(storage.NewMemStorage(), nil)
	if err != nil {
		t.Fatal(err)
	}

	s := db.NewFileSet("test", ldb)

	localHave := fileList{
		protocol.FileInfo{Name: "a", Version: protocol.Vector{{ID: myID, Value: 1000}}, Blocks: genBlocks(1)},
		protocol.FileInfo{Name: "b", Version: protocol.Vector{{ID: myID, Value: 1001}}, Blocks: genBlocks(2)},
		protocol.FileInfo{Name: "c", Version: protocol.Vector{{ID: myID, Value: 1002}}, Blocks: genBlocks(5), Flags: protocol.FlagInvalid},
		protocol.FileInfo{Name: "d", Version: protocol.Vector{{ID: myID, Value: 1003}}, Blocks: genBlocks(7)},
	}

	s.Replace(protocol.LocalDeviceID, localHave)

	have := fileList(haveList(s, protocol.LocalDeviceID))
	sort.Sort(have)

	if fmt.Sprint(have) != fmt.Sprint(localHave) {
		t.Errorf("Have incorrect before invalidation;\n A: %v !=\n E: %v", have, localHave)
	}

	localHave[1] = protocol.FileInfo{Name: "b", Version: protocol.Vector{{ID: myID, Value: 1001}}, Flags: protocol.FlagInvalid}
	s.Update(protocol.LocalDeviceID, localHave[1:2])

	have = fileList(haveList(s, protocol.LocalDeviceID))
	sort.Sort(have)

	if fmt.Sprint(have) != fmt.Sprint(localHave) {
		t.Errorf("Have incorrect after invalidation;\n A: %v !=\n E: %v", have, localHave)
	}
}
开发者ID:raonyguimaraes,项目名称:syncthing,代码行数:34,代码来源:set_test.go

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

示例6: Benchmark10kGlobal

func Benchmark10kGlobal(b *testing.B) {
	var remote []protocol.FileInfo
	for i := 0; i < 10000; i++ {
		remote = append(remote, protocol.FileInfo{Name: fmt.Sprintf("file%d", i), Version: protocol.Vector{{ID: myID, Value: 1000}}})
	}

	ldb, err := leveldb.Open(storage.NewMemStorage(), nil)
	if err != nil {
		b.Fatal(err)
	}

	m := db.NewFileSet("test", ldb)
	m.Replace(remoteDevice0, remote)

	var local []protocol.FileInfo
	for i := 0; i < 2000; i++ {
		local = append(local, protocol.FileInfo{Name: fmt.Sprintf("file%d", i), Version: protocol.Vector{{ID: myID, Value: 1000}}})
	}
	for i := 2000; i < 10000; i++ {
		local = append(local, protocol.FileInfo{Name: fmt.Sprintf("file%d", i), Version: protocol.Vector{{1, 980}}})
	}

	m.Replace(protocol.LocalDeviceID, local)

	b.ResetTimer()
	for i := 0; i < b.N; i++ {
		fs := globalList(m)
		if l := len(fs); l != 10000 {
			b.Errorf("wrong length %d != 10k", l)
		}
	}
}
开发者ID:raonyguimaraes,项目名称:syncthing,代码行数:32,代码来源:set_test.go

示例7: Benchmark10kUpdateSme

func Benchmark10kUpdateSme(b *testing.B) {
	var remote []protocol.FileInfo
	for i := 0; i < 10000; i++ {
		remote = append(remote, protocol.FileInfo{Name: fmt.Sprintf("file%d", i), Version: 1000})
	}

	db, err := leveldb.Open(storage.NewMemStorage(), nil)
	if err != nil {
		b.Fatal(err)
	}
	m := files.NewSet("test", db)
	m.Replace(remoteNode0, remote)

	var local []protocol.FileInfo
	for i := 0; i < 10000; i++ {
		local = append(local, protocol.FileInfo{Name: fmt.Sprintf("file%d", i), Version: 1000})
	}

	m.ReplaceWithDelete(protocol.LocalNodeID, local)

	b.ResetTimer()
	for i := 0; i < b.N; i++ {
		m.Update(protocol.LocalNodeID, local)
	}
}
开发者ID:hotoracle,项目名称:syncthing,代码行数:25,代码来源:set_test.go

示例8: Benchmark10kHaveFullList

func Benchmark10kHaveFullList(b *testing.B) {
	var remote []protocol.FileInfo
	for i := 0; i < 10000; i++ {
		remote = append(remote, protocol.FileInfo{Name: fmt.Sprintf("file%d", i), Version: 1000})
	}

	db, err := leveldb.Open(storage.NewMemStorage(), nil)
	if err != nil {
		b.Fatal(err)
	}

	m := files.NewSet("test", db)
	m.Replace(remoteNode0, remote)

	var local []protocol.FileInfo
	for i := 0; i < 2000; i++ {
		local = append(local, protocol.FileInfo{Name: fmt.Sprintf("file%d", i), Version: 1000})
	}
	for i := 2000; i < 10000; i++ {
		local = append(local, protocol.FileInfo{Name: fmt.Sprintf("file%d", i), Version: 980})
	}

	m.ReplaceWithDelete(protocol.LocalNodeID, local)

	b.ResetTimer()
	for i := 0; i < b.N; i++ {
		fs := haveList(m, protocol.LocalNodeID)
		if l := len(fs); l != 10000 {
			b.Errorf("wrong length %d != 10k", l)
		}
	}
}
开发者ID:hotoracle,项目名称:syncthing,代码行数:32,代码来源:set_test.go

示例9: TestLongPath

func TestLongPath(t *testing.T) {
	ldb, err := leveldb.Open(storage.NewMemStorage(), nil)
	if err != nil {
		t.Fatal(err)
	}

	s := db.NewFileSet("test", ldb)

	var b bytes.Buffer
	for i := 0; i < 100; i++ {
		b.WriteString("012345678901234567890123456789012345678901234567890")
	}
	name := b.String() // 5000 characters

	local := []protocol.FileInfo{
		{Name: string(name), Version: protocol.Vector{{ID: myID, Value: 1000}}},
	}

	s.Replace(protocol.LocalDeviceID, local)

	gf := globalList(s)
	if l := len(gf); l != 1 {
		t.Fatalf("Incorrect len %d != 1 for global list", l)
	}
	if gf[0].Name != local[0].Name {
		t.Errorf("Incorrect long filename;\n%q !=\n%q",
			gf[0].Name, local[0].Name)
	}
}
开发者ID:raonyguimaraes,项目名称:syncthing,代码行数:29,代码来源:set_test.go

示例10: TestLocalVersion

func TestLocalVersion(t *testing.T) {
	ldb, err := leveldb.Open(storage.NewMemStorage(), nil)
	if err != nil {
		t.Fatal(err)
	}

	m := db.NewFileSet("test", ldb)

	local1 := []protocol.FileInfo{
		{Name: "a", Version: protocol.Vector{{ID: myID, Value: 1000}}},
		{Name: "b", Version: protocol.Vector{{ID: myID, Value: 1000}}},
		{Name: "c", Version: protocol.Vector{{ID: myID, Value: 1000}}},
		{Name: "d", Version: protocol.Vector{{ID: myID, Value: 1000}}},
	}

	local2 := []protocol.FileInfo{
		local1[0],
		// [1] deleted
		local1[2],
		{Name: "d", Version: protocol.Vector{{ID: myID, Value: 1002}}},
		{Name: "e", Version: protocol.Vector{{ID: myID, Value: 1000}}},
	}

	m.Replace(protocol.LocalDeviceID, local1)
	c0 := m.LocalVersion(protocol.LocalDeviceID)

	m.Replace(protocol.LocalDeviceID, local2)
	c1 := m.LocalVersion(protocol.LocalDeviceID)
	if !(c1 > c0) {
		t.Fatal("Local version number should have incremented")
	}
}
开发者ID:raonyguimaraes,项目名称:syncthing,代码行数:32,代码来源:set_test.go

示例11: Benchmark10kUpdateSme

func Benchmark10kUpdateSme(b *testing.B) {
	var remote []protocol.FileInfo
	for i := 0; i < 10000; i++ {
		remote = append(remote, protocol.FileInfo{Name: fmt.Sprintf("file%d", i), Version: protocol.Vector{{ID: myID, Value: 1000}}})
	}

	ldb, err := leveldb.Open(storage.NewMemStorage(), nil)
	if err != nil {
		b.Fatal(err)
	}
	m := db.NewFileSet("test", ldb)
	m.Replace(remoteDevice0, remote)

	var local []protocol.FileInfo
	for i := 0; i < 10000; i++ {
		local = append(local, protocol.FileInfo{Name: fmt.Sprintf("file%d", i), Version: protocol.Vector{{ID: myID, Value: 1000}}})
	}

	m.Replace(protocol.LocalDeviceID, local)

	b.ResetTimer()
	for i := 0; i < b.N; i++ {
		m.Update(protocol.LocalDeviceID, local)
	}
}
开发者ID:raonyguimaraes,项目名称:syncthing,代码行数:25,代码来源:set_test.go

示例12: TestNamespacedReset

func TestNamespacedReset(t *testing.T) {
	ldb, err := leveldb.Open(storage.NewMemStorage(), nil)
	if err != nil {
		t.Fatal(err)
	}

	n1 := NewNamespacedKV(ldb, "foo")

	n1.PutString("test1", "yo1")
	n1.PutString("test2", "yo2")
	n1.PutString("test3", "yo3")

	if v, ok := n1.String("test1"); v != "yo1" || !ok {
		t.Errorf("Incorrect return v %q != \"yo1\" || ok %v != true", v, ok)
	}
	if v, ok := n1.String("test2"); v != "yo2" || !ok {
		t.Errorf("Incorrect return v %q != \"yo2\" || ok %v != true", v, ok)
	}
	if v, ok := n1.String("test3"); v != "yo3" || !ok {
		t.Errorf("Incorrect return v %q != \"yo3\" || ok %v != true", v, ok)
	}

	n1.Reset()

	if v, ok := n1.String("test1"); v != "" || ok {
		t.Errorf("Incorrect return v %q != \"\" || ok %v != false", v, ok)
	}
	if v, ok := n1.String("test2"); v != "" || ok {
		t.Errorf("Incorrect return v %q != \"\" || ok %v != false", v, ok)
	}
	if v, ok := n1.String("test3"); v != "" || ok {
		t.Errorf("Incorrect return v %q != \"\" || ok %v != false", v, ok)
	}
}
开发者ID:tomschlenkhoff,项目名称:syncthing,代码行数:34,代码来源:namespaced_test.go

示例13: TestLastResortPulling

// Make sure that the copier routine hashes the content when asked, and pulls
// if it fails to find the block.
func TestLastResortPulling(t *testing.T) {
	db, _ := leveldb.Open(storage.NewMemStorage(), nil)
	m := NewModel(defaultConfig, protocol.LocalDeviceID, "device", "syncthing", "dev", db)
	m.AddFolder(defaultFolderConfig)

	// Add a file to index (with the incorrect block representation, as content
	// doesn't actually match the block list)
	file := protocol.FileInfo{
		Name:     "empty",
		Flags:    0,
		Modified: 0,
		Blocks:   []protocol.BlockInfo{blocks[0]},
	}
	m.updateLocals("default", []protocol.FileInfo{file})

	// Pretend that we are handling a new file of the same content but
	// with a different name (causing to copy that particular block)
	file.Name = "newfile"

	iterFn := func(folder, file string, index int32) bool {
		return true
	}

	// Check that that particular block is there
	if !m.finder.Iterate(blocks[0].Hash, iterFn) {
		t.Error("Expected block not found")
	}

	p := rwFolder{
		folder: "default",
		dir:    "testdata",
		model:  m,
	}

	copyChan := make(chan copyBlocksState)
	pullChan := make(chan pullBlockState, 1)
	finisherChan := make(chan *sharedPullerState, 1)

	// Run a single copier routine
	go p.copierRoutine(copyChan, pullChan, finisherChan)

	p.handleFile(file, copyChan, finisherChan)

	// Copier should hash empty file, realise that the region it has read
	// doesn't match the hash which was advertised by the block map, fix it
	// and ask to pull the block.
	<-pullChan

	// Verify that it did fix the incorrect hash.
	if m.finder.Iterate(blocks[0].Hash, iterFn) {
		t.Error("Found unexpected block")
	}

	if !m.finder.Iterate(scanner.SHA256OfNothing, iterFn) {
		t.Error("Expected block not found")
	}

	(<-finisherChan).fd.Close()
	os.Remove(filepath.Join("testdata", defTempNamer.TempName("newfile")))
}
开发者ID:tomschlenkhoff,项目名称:syncthing,代码行数:62,代码来源:rwfolder_test.go

示例14: setup

func setup() (*leveldb.DB, *BlockFinder) {
	// Setup

	db, err := leveldb.Open(storage.NewMemStorage(), nil)
	if err != nil {
		panic(err)
	}
	return db, NewBlockFinder(db)
}
开发者ID:rwx-zwx-awx,项目名称:syncthing,代码行数:9,代码来源:blockmap_test.go

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


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