• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Golang localstore.Driver类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: TestConcurrent

// Make sure it is safe to concurrently create handle on multiple stores.
func (testSuite) TestConcurrent(c *C) {
	defer testleak.AfterTest(c)()
	storeCount := 5
	stores := make([]kv.Storage, storeCount)
	for i := 0; i < storeCount; i++ {
		driver := localstore.Driver{Driver: goleveldb.MemoryDriver{}}
		store, err := driver.Open(fmt.Sprintf("memory_path_%d", i))
		c.Assert(err, IsNil)
		stores[i] = store
	}
	defer func() {
		for _, store := range stores {
			store.Close()
		}
	}()
	var wg sync.WaitGroup
	wg.Add(storeCount)
	for _, store := range stores {
		go func(s kv.Storage) {
			defer wg.Done()
			_, err := infoschema.NewHandle(s)
			c.Assert(err, IsNil)
		}(store)
	}
	wg.Wait()
}
开发者ID:jmptrader,项目名称:tidb,代码行数:27,代码来源:infoschema_test.go


示例2: TestT

func (*testSuite) TestT(c *C) {
	driver := localstore.Driver{Driver: goleveldb.MemoryDriver{}}
	store, err := driver.Open("memory")
	c.Assert(err, IsNil)
	defer store.Close()

	// For GenID
	txn, err := store.Begin()
	c.Assert(err, IsNil)
	key := []byte(meta.AutoIDKey(1))
	id, err := meta.GenID(txn, key, 1)
	c.Assert(id, Equals, int64(1))
	id, err = meta.GenID(txn, key, 2)
	c.Assert(id, Equals, int64(3))
	id, err = meta.GenID(txn, []byte{}, 1)
	c.Assert(err, NotNil)

	// For DBMetaKey
	mkey := meta.DBMetaKey(1)
	c.Assert(mkey, Equals, "mDB::1")

	//For AutoIDKey
	mkey = meta.AutoIDKey(1)
	c.Assert(mkey, Equals, "mTable::1_autoID")
	mkey = meta.AutoIDKey(0)
	c.Assert(mkey, Equals, "mTable::0_autoID")

	// For GenGlobalID
	id, err = meta.GenGlobalID(store)
	c.Assert(err, IsNil)
	c.Assert(id, Equals, int64(1))
	id, err = meta.GenGlobalID(store)
	c.Assert(err, IsNil)
	c.Assert(id, Equals, int64(2))
}
开发者ID:ninefive,项目名称:tidb,代码行数:35,代码来源:meta_test.go


示例3: TestInfoTables

// Make sure that all tables of infomation_schema could be found in infoschema handle.
func (*testSuite) TestInfoTables(c *C) {
	defer testleak.AfterTest(c)()
	driver := localstore.Driver{Driver: goleveldb.MemoryDriver{}}
	store, err := driver.Open("memory")
	c.Assert(err, IsNil)
	defer store.Close()
	handle, err := infoschema.NewHandle(store)
	c.Assert(err, IsNil)
	builder, err := infoschema.NewBuilder(handle).InitWithDBInfos(nil, 0)
	c.Assert(err, IsNil)
	err = builder.Build()
	c.Assert(err, IsNil)
	is := handle.Get()
	c.Assert(is, NotNil)

	info_tables := []string{
		"SCHEMATA",
		"TABLES",
		"COLUMNS",
		"STATISTICS",
		"CHARACTER_SETS",
		"COLLATIONS",
		"FILES",
		"PROFILING",
		"PARTITIONS",
		"KEY_COLUMN_USAGE",
		"REFERENTIAL_CONSTRAINTS",
	}
	for _, t := range info_tables {
		tb, err1 := is.TableByName(model.NewCIStr(infoschema.Name), model.NewCIStr(t))
		c.Assert(err1, IsNil)
		c.Assert(tb, NotNil)
	}
}
开发者ID:jmptrader,项目名称:tidb,代码行数:35,代码来源:infoschema_test.go


示例4: SetUpSuite

func (s *testIndexSuite) SetUpSuite(c *C) {
	path := "memory:"
	d := localstore.Driver{Driver: goleveldb.MemoryDriver{}}
	store, err := d.Open(path)
	c.Assert(err, IsNil)
	s.s = store
}
开发者ID:hanjinze,项目名称:tidb,代码行数:7,代码来源:index_iter_test.go


示例5: TestT

func (*testSuite) TestT(c *C) {
	driver := localstore.Driver{Driver: goleveldb.MemoryDriver{}}
	store, err := driver.Open("memory")
	c.Assert(err, IsNil)
	defer store.Close()

	m := meta.NewMeta(store)
	err = m.RunInNewTxn(false, func(m *meta.TMeta) error {
		err = m.CreateDatabase(&model.DBInfo{ID: 1, Name: model.NewCIStr("a")})
		c.Assert(err, IsNil)
		err = m.CreateTable(1, &model.TableInfo{ID: 1, Name: model.NewCIStr("t")})
		c.Assert(err, IsNil)
		return nil
	})
	c.Assert(err, IsNil)

	alloc := autoid.NewAllocator(m, 1)
	c.Assert(alloc, NotNil)

	id, err := alloc.Alloc(1)
	c.Assert(err, IsNil)
	c.Assert(id, Equals, int64(1))
	id, err = alloc.Alloc(1)
	c.Assert(err, IsNil)
	c.Assert(id, Equals, int64(2))
	id, err = alloc.Alloc(0)
	c.Assert(err, NotNil)
}
开发者ID:stumaxim28,项目名称:tidb,代码行数:28,代码来源:autoid_test.go


示例6: TestSnapshot

func (s *testSuite) TestSnapshot(c *C) {
	defer testleak.AfterTest(c)()
	driver := localstore.Driver{Driver: goleveldb.MemoryDriver{}}
	store, err := driver.Open("memory")
	c.Assert(err, IsNil)
	defer store.Close()

	txn, _ := store.Begin()
	m := meta.NewMeta(txn)
	m.GenGlobalID()
	n, _ := m.GetGlobalID()
	c.Assert(n, Equals, int64(1))
	txn.Commit()

	ver1, _ := store.CurrentVersion()
	time.Sleep(time.Millisecond)
	txn, _ = store.Begin()
	m = meta.NewMeta(txn)
	m.GenGlobalID()
	n, _ = m.GetGlobalID()
	c.Assert(n, Equals, int64(2))
	txn.Commit()

	snapshot, _ := store.GetSnapshot(ver1)
	snapMeta := meta.NewSnapshotMeta(snapshot)
	n, _ = snapMeta.GetGlobalID()
	c.Assert(n, Equals, int64(1))
	_, err = snapMeta.GenGlobalID()
	c.Assert(err, NotNil)
}
开发者ID:jmptrader,项目名称:tidb,代码行数:30,代码来源:meta_test.go


示例7: TestBoltDBDeadlock

func (s *testKVSuite) TestBoltDBDeadlock(c *C) {
	d := localstore.Driver{
		Driver: boltdb.Driver{},
	}
	path := "boltdb_test"
	defer os.Remove(path)
	store, err := d.Open(path)
	c.Assert(err, IsNil)
	defer store.Close()

	kv.RunInNewTxn(store, false, func(txn kv.Transaction) error {
		txn.Set([]byte("a"), []byte("0"))
		kv.IncInt64(txn, []byte("a"), 1)

		kv.RunInNewTxn(store, false, func(txn kv.Transaction) error {
			txn.Set([]byte("b"), []byte("0"))
			kv.IncInt64(txn, []byte("b"), 1)

			return nil
		})

		return nil
	})

	kv.RunInNewTxn(store, false, func(txn kv.Transaction) error {
		n, err := kv.GetInt64(txn, []byte("a"))
		c.Assert(err, IsNil)
		c.Assert(n, Equals, int64(1))

		n, err = kv.GetInt64(txn, []byte("b"))
		c.Assert(err, IsNil)
		c.Assert(n, Equals, int64(1))
		return nil
	})
}
开发者ID:lovedboy,项目名称:tidb,代码行数:35,代码来源:store_test.go


示例8: SetUpSuite

func (ts *testMemoryTableSuite) SetUpSuite(c *C) {
	driver := localstore.Driver{Driver: goleveldb.MemoryDriver{}}
	store, err := driver.Open("memory")
	c.Check(err, IsNil)
	ts.store = store
	ts.se, err = tidb.CreateSession(ts.store)
	c.Assert(err, IsNil)

	// create table
	tp1 := types.NewFieldType(mysql.TypeLong)
	col1 := &model.ColumnInfo{
		ID:        1,
		Name:      model.NewCIStr("a"),
		Offset:    0,
		FieldType: *tp1,
	}
	tp2 := types.NewFieldType(mysql.TypeVarchar)
	tp2.Flen = 255
	col2 := &model.ColumnInfo{
		ID:        2,
		Name:      model.NewCIStr("b"),
		Offset:    1,
		FieldType: *tp2,
	}

	tblInfo := &model.TableInfo{
		ID:      100,
		Name:    model.NewCIStr("t"),
		Columns: []*model.ColumnInfo{col1, col2},
	}
	alloc := autoid.NewMemoryAllocator(int64(10))
	ts.tbl, _ = tables.MemoryTableFromMeta(alloc, tblInfo)
}
开发者ID:XuHuaiyu,项目名称:tidb,代码行数:33,代码来源:memory_tables_test.go


示例9: TestT

func (*testSuite) TestT(c *C) {
	driver := localstore.Driver{Driver: goleveldb.MemoryDriver{}}
	store, err := driver.Open("memory")
	c.Assert(err, IsNil)
	defer store.Close()

	ctx := mock.NewContext()

	dom, err := NewDomain(store, 0)
	c.Assert(err, IsNil)
	store = dom.Store()
	dd := dom.DDL()
	c.Assert(dd, NotNil)
	err = dd.CreateSchema(ctx, model.NewCIStr("aaa"))
	c.Assert(err, IsNil)
	is := dom.InfoSchema()
	c.Assert(is, NotNil)
	dom, err = NewDomain(store, 0)
	c.Assert(err, IsNil)

	dom.SetLease(10 * time.Second)

	m, err := dom.Stats()
	c.Assert(err, IsNil)
	c.Assert(m[ddlLastReloadSchemaTS], GreaterEqual, int64(0))

	dom.SetLease(50 * time.Millisecond)
	store.Close()
	time.Sleep(1 * time.Second)
}
开发者ID:yzl11,项目名称:vessel,代码行数:30,代码来源:domain_test.go


示例10: TestT

func (*testSuite) TestT(c *C) {
	driver := localstore.Driver{Driver: goleveldb.MemoryDriver{}}
	store, err := driver.Open("memory")
	c.Assert(err, IsNil)
	defer testleak.AfterTest(c)()

	ctx := mock.NewContext()

	dom, err := NewDomain(store, 0)
	c.Assert(err, IsNil)
	store = dom.Store()
	dd := dom.DDL()
	c.Assert(dd, NotNil)
	cs := &ast.CharsetOpt{
		Chs: "utf8",
		Col: "utf8_bin",
	}
	err = dd.CreateSchema(ctx, model.NewCIStr("aaa"), cs)
	c.Assert(err, IsNil)
	is := dom.InfoSchema()
	c.Assert(is, NotNil)
	dom, err = NewDomain(store, 0)
	c.Assert(err, IsNil)

	dom.SetLease(10 * time.Second)

	m, err := dom.Stats()
	c.Assert(err, IsNil)
	c.Assert(m[ddlLastReloadSchemaTS], GreaterEqual, int64(0))

	c.Assert(dom.GetScope("dummy_status"), Equals, variable.DefaultScopeFlag)

	dom.SetLease(10 * time.Millisecond)
	time.Sleep(20 * time.Millisecond)
	atomic.StoreInt64(&dom.lastLeaseTS, 0)
	dom.tryReload()
	time.Sleep(1 * time.Second)

	// for schemaValidity
	err = dom.SchemaValidity.Check(0)
	c.Assert(err, IsNil)
	dom.SchemaValidity.MockReloadFailed = true
	err = dom.MustReload()
	c.Assert(err, NotNil)
	err = dom.SchemaValidity.Check(0)
	c.Assert(err, NotNil)
	dom.SchemaValidity.MockReloadFailed = false
	err = dom.MustReload()
	c.Assert(err, IsNil)
	err = dom.SchemaValidity.Check(0)
	c.Assert(err, IsNil)

	// for goroutine exit in Reload
	defaultMinReloadTimeout = 1 * time.Second
	err = store.Close()
	c.Assert(err, IsNil)
	err = dom.Reload()
	c.Assert(err, NotNil)
}
开发者ID:XuHuaiyu,项目名称:tidb,代码行数:59,代码来源:domain_test.go


示例11: SetUpSuite

func (ts *testSuite) SetUpSuite(c *C) {
	driver := localstore.Driver{Driver: goleveldb.MemoryDriver{}}
	store, err := driver.Open("memory")
	c.Check(err, IsNil)
	ts.store = store
	ts.se, err = tidb.CreateSession(ts.store)
	c.Assert(err, IsNil)
}
开发者ID:xxwwbb3,项目名称:tidb,代码行数:8,代码来源:tables_test.go


示例12: SetUpSuite

func (s *tesTxStructureSuite) SetUpSuite(c *C) {
	path := "memory:"
	d := localstore.Driver{
		Driver: goleveldb.MemoryDriver{},
	}
	store, err := d.Open(path)
	c.Assert(err, IsNil)
	s.s = NewStore(store, []byte{0x00})
}
开发者ID:stumaxim28,项目名称:tidb,代码行数:9,代码来源:structure_test.go


示例13: TestT

func (*testSuite) TestT(c *C) {
	driver := localstore.Driver{Driver: goleveldb.MemoryDriver{}}
	store, err := driver.Open("memory")
	c.Assert(err, IsNil)
	defer testleak.AfterTest(c)()
	ctx := mock.NewContext()

	dom, err := NewDomain(store, 80*time.Millisecond)
	c.Assert(err, IsNil)
	store = dom.Store()
	dd := dom.DDL()
	c.Assert(dd, NotNil)
	c.Assert(dd.GetLease(), Equals, 80*time.Millisecond)
	cs := &ast.CharsetOpt{
		Chs: "utf8",
		Col: "utf8_bin",
	}
	err = dd.CreateSchema(ctx, model.NewCIStr("aaa"), cs)
	c.Assert(err, IsNil)
	is := dom.InfoSchema()
	c.Assert(is, NotNil)

	m, err := dom.Stats()
	c.Assert(err, IsNil)
	c.Assert(m[ddlLastReloadSchemaTS], GreaterEqual, int64(0))
	c.Assert(dom.GetScope("dummy_status"), Equals, variable.DefaultScopeFlag)

	// for setting lease
	lease := 100 * time.Millisecond

	// for schemaValidity
	schemaVer, err := dom.SchemaValidity.Check(0, 0)
	c.Assert(err, IsNil)
	dom.SchemaValidity.MockReloadFailed.SetValue(true)
	err = dom.Reload()
	c.Assert(err, NotNil)
	time.Sleep(lease)
	_, err = dom.SchemaValidity.Check(0, 0)
	c.Assert(err, NotNil)
	_, err = dom.SchemaValidity.Check(0, schemaVer)
	c.Assert(err, NotNil)
	dom.SchemaValidity.MockReloadFailed.SetValue(false)
	dom.SchemaValidity.SetExpireInfo(false, 0)
	_, err = dom.SchemaValidity.Check(1, 0)
	c.Assert(err, NotNil)
	schemaVer1, err := dom.SchemaValidity.Check(0, schemaVer)
	c.Assert(err, IsNil)
	err = dom.Reload()
	c.Assert(err, IsNil)
	time.Sleep(lease)
	schemaVer2, err := dom.SchemaValidity.Check(0, 0)
	c.Assert(err, IsNil)
	c.Assert(schemaVer1, Equals, schemaVer2)

	err = store.Close()
	c.Assert(err, IsNil)
}
开发者ID:pingcap,项目名称:tidb,代码行数:57,代码来源:domain_test.go


示例14: SetUpSuite

func (ts *testSuite) SetUpSuite(c *C) {
	table.TableFromMeta = tables.TableFromMeta
	driver := localstore.Driver{goleveldb.MemoryDriver{}}
	store, err := driver.Open("memory")
	c.Check(err, IsNil)
	ts.store = store
	ts.se, err = tidb.CreateSession(ts.store)
	c.Assert(err, IsNil)
	_, err = ts.se.Execute("CREATE DATABASE test")
	c.Assert(err, IsNil)
}
开发者ID:npk,项目名称:tidb,代码行数:11,代码来源:tables_test.go


示例15: TestDDL

func (s *testSuite) TestDDL(c *C) {
	driver := localstore.Driver{Driver: goleveldb.MemoryDriver{}}
	store, err := driver.Open("memory")
	c.Assert(err, IsNil)
	defer store.Close()

	m := meta.NewMeta(store)

	t, err := m.Begin()
	c.Assert(err, IsNil)

	defer t.Rollback()

	owner := &model.Owner{OwnerID: "1"}
	err = t.SetDDLOwner(owner)
	c.Assert(err, IsNil)
	ov, err := t.GetDDLOwner()
	c.Assert(err, IsNil)
	c.Assert(owner, DeepEquals, ov)

	job := &model.Job{ID: 1}
	err = t.EnQueueDDLJob(job)
	c.Assert(err, IsNil)
	n, err := t.DDLJobLength()
	c.Assert(err, IsNil)
	c.Assert(n, Equals, int64(1))

	v, err := t.GetDDLJob(0)
	c.Assert(err, IsNil)
	c.Assert(v, DeepEquals, job)

	v, err = t.GetDDLJob(1)
	c.Assert(err, IsNil)
	c.Assert(v, IsNil)

	job.ID = 2
	err = t.UpdateDDLJob(0, job)
	c.Assert(err, IsNil)

	v, err = t.DeQueueDDLJob()
	c.Assert(err, IsNil)
	c.Assert(v, DeepEquals, job)

	err = t.AddHistoryDDLJob(job)
	c.Assert(err, IsNil)

	v, err = t.GetHistoryDDLJob(2)
	c.Assert(err, IsNil)
	c.Assert(v, DeepEquals, job)

	err = t.Commit()
	c.Assert(err, IsNil)
}
开发者ID:stumaxim28,项目名称:tidb,代码行数:53,代码来源:meta_test.go


示例16: SetUpSuite

func (s *testPrefixSuite) SetUpSuite(c *C) {
	path := "memory:"
	d := localstore.Driver{
		Driver: goleveldb.MemoryDriver{},
	}
	store, err := d.Open(path)
	c.Assert(err, IsNil)
	s.s = store

	// must in cache
	cacheS, _ := d.Open(path)
	c.Assert(cacheS, Equals, store)
}
开发者ID:nengwang,项目名称:tidb,代码行数:13,代码来源:prefix_helper_test.go


示例17: TestDBClose

func (s *testKVSuite) TestDBClose(c *C) {
	defer testleak.AfterTest(c)()
	path := "memory:test"
	d := localstore.Driver{
		Driver: goleveldb.MemoryDriver{},
	}
	store, err := d.Open(path)
	c.Assert(err, IsNil)

	txn, err := store.Begin()
	c.Assert(err, IsNil)

	err = txn.Set([]byte("a"), []byte("b"))
	c.Assert(err, IsNil)

	err = txn.Commit()
	c.Assert(err, IsNil)

	ver, err := store.CurrentVersion()
	c.Assert(err, IsNil)
	c.Assert(kv.MaxVersion.Cmp(ver), Equals, 1)

	snap, err := store.GetSnapshot(kv.MaxVersion)
	c.Assert(err, IsNil)

	_, err = snap.Get([]byte("a"))
	c.Assert(err, IsNil)

	txn, err = store.Begin()
	c.Assert(err, IsNil)

	err = store.Close()
	c.Assert(err, IsNil)

	_, err = store.Begin()
	c.Assert(err, NotNil)

	_, err = store.GetSnapshot(kv.MaxVersion)
	c.Assert(err, NotNil)

	err = txn.Set([]byte("a"), []byte("b"))
	c.Assert(err, IsNil)

	err = txn.Commit()
	c.Assert(err, NotNil)

	snap.Release()
}
开发者ID:anywhy,项目名称:tidb,代码行数:48,代码来源:store_test.go


示例18: TestT

func (*testSuite) TestT(c *C) {
	driver := localstore.Driver{goleveldb.MemoryDriver{}}
	store, err := driver.Open("memory")
	c.Assert(err, IsNil)
	defer store.Close()

	dom, err := NewDomain(store)
	c.Assert(err, IsNil)
	store = dom.Store()
	dd := dom.DDL()
	c.Assert(dd, NotNil)
	err = dd.CreateSchema(nil, model.NewCIStr("aaa"))
	c.Assert(err, IsNil)
	is := dom.InfoSchema()
	c.Assert(is, NotNil)
	dom, err = NewDomain(store)
	c.Assert(err, IsNil)
}
开发者ID:npk,项目名称:tidb,代码行数:18,代码来源:domain_test.go


示例19: TestT

func (*testSuite) TestT(c *C) {
	driver := localstore.Driver{Driver: goleveldb.MemoryDriver{}}
	store, err := driver.Open("memory")
	c.Assert(err, IsNil)
	defer store.Close()

	alloc := autoid.NewAllocator(store)
	c.Assert(alloc, NotNil)

	id, err := alloc.Alloc(1)
	c.Assert(err, IsNil)
	c.Assert(id, Equals, int64(1))
	id, err = alloc.Alloc(1)
	c.Assert(err, IsNil)
	c.Assert(id, Equals, int64(2))
	id, err = alloc.Alloc(0)
	c.Assert(err, NotNil)
}
开发者ID:ninefive,项目名称:tidb,代码行数:18,代码来源:autoid_test.go


示例20: TestT

func (*testSuite) TestT(c *C) {
	var ident = ast.Ident{
		Name: model.NewCIStr("t"),
	}
	c.Assert(ident.String(), Not(Equals), "")
	driver := localstore.Driver{Driver: goleveldb.MemoryDriver{}}
	store, err := driver.Open("memory")
	c.Assert(err, IsNil)
	se, err := tidb.CreateSession(store)
	c.Assert(err, IsNil)
	ctx := se.(context.Context)
	db.BindCurrentSchema(ctx, "test")
	fullIdent := ident.Full(ctx)
	c.Assert(fullIdent.Schema.L, Equals, "test")
	c.Assert(fullIdent.Name.L, Equals, "t")
	c.Assert(fullIdent.String(), Not(Equals), "")
	fullIdent2 := fullIdent.Full(ctx)
	c.Assert(fullIdent2.Schema.L, Equals, fullIdent.Schema.L)
}
开发者ID:astaxie,项目名称:tidb,代码行数:19,代码来源:table_test.go



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Golang engine.Batch类代码示例发布时间:2022-05-28
下一篇:
Golang localstore.IsLocalStore函数代码示例发布时间:2022-05-28
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap