本文整理汇总了Golang中github.com/pingcap/tidb/store/localstore.Driver类的典型用法代码示例。如果您正苦于以下问题:Golang Driver类的具体用法?Golang Driver怎么用?Golang Driver使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Driver类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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()
}
示例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))
}
示例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)
}
}
示例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
}
示例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)
}
示例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)
}
示例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
})
}
示例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)
}
示例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)
}
示例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)
}
示例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)
}
示例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})
}
示例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)
}
示例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)
}
示例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)
}