本文整理汇总了Golang中github.com/pingcap/tidb/infoschema.NewHandle函数的典型用法代码示例。如果您正苦于以下问题:Golang NewHandle函数的具体用法?Golang NewHandle怎么用?Golang NewHandle使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了NewHandle函数的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: 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
示例2: TestConstraintNames
func (ts *testSuite) TestConstraintNames(c *C) {
handle := infoschema.NewHandle(ts.store)
handle.Set(nil)
dd := ddl.NewDDL(ts.store, handle)
se, _ := tidb.CreateSession(ts.store)
ctx := se.(context.Context)
schemaName := model.NewCIStr("test")
tblName := model.NewCIStr("t")
tbIdent := table.Ident{
Schema: schemaName,
Name: tblName,
}
err := dd.CreateSchema(ctx, tbIdent.Schema)
c.Assert(err, IsNil)
tbStmt := statement("create table t (a int, b int, index a (a, b), index a (a))").(*stmts.CreateTableStmt)
err = dd.CreateTable(ctx, tbIdent, tbStmt.Cols, tbStmt.Constraints)
c.Assert(err, NotNil)
tbStmt = statement("create table t (a int, b int, index A (a, b), index (a))").(*stmts.CreateTableStmt)
err = dd.CreateTable(ctx, tbIdent, tbStmt.Cols, tbStmt.Constraints)
c.Assert(err, IsNil)
tbl, err := handle.Get().TableByName(schemaName, tblName)
indices := tbl.Indices()
c.Assert(len(indices), Equals, 2)
c.Assert(indices[0].Name.O, Equals, "A")
c.Assert(indices[1].Name.O, Equals, "a_2")
err = dd.DropSchema(ctx, tbIdent.Schema)
c.Assert(err, IsNil)
}
开发者ID:nengwang,项目名称:tidb,代码行数:30,代码来源:ddl_test.go
示例3: NewDomain
// NewDomain creates a new domain. Should not create multiple domains for the same store.
func NewDomain(store kv.Storage, lease time.Duration) (d *Domain, err error) {
d = &Domain{
store: store,
SchemaValidity: &schemaValidityInfo{},
exit: make(chan struct{}),
}
d.infoHandle, err = infoschema.NewHandle(d.store)
if err != nil {
return nil, errors.Trace(err)
}
d.ddl = ddl.NewDDL(d.store, d.infoHandle, &ddlCallback{do: d}, lease)
if err = d.Reload(); err != nil {
return nil, errors.Trace(err)
}
d.SchemaValidity.SetExpireInfo(false, 0)
variable.RegisterStatistics(d)
// Only when the store is local that the lease value is 0.
// If the store is local, it doesn't need loadSchemaInLoop and checkValidityInLoop.
if lease > 0 {
go d.checkValidityInLoop(lease)
}
// Local store needs to get the change information for every DDL state in each session.
go d.loadSchemaInLoop(lease)
return d, nil
}
开发者ID:pingcap,项目名称:tidb,代码行数:30,代码来源:domain.go
示例4: 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
示例5: NewDomain
// NewDomain creates a new domain.
func NewDomain(store kv.Storage) (d *Domain, err error) {
d = &Domain{
store: store,
}
d.infoHandle = infoschema.NewHandle(d.store)
d.ddl = ddl.NewDDL(d.store, d.infoHandle, d.onDDLChange)
err = d.reload()
return d, errors.Trace(err)
}
开发者ID:remotesyssupport,项目名称:tidb,代码行数:11,代码来源:domain.go
示例6: NewDomain
// NewDomain creates a new domain.
func NewDomain(store kv.Storage, lease time.Duration) (d *Domain, err error) {
d = &Domain{
store: store,
leaseCh: make(chan time.Duration, 1),
}
d.infoHandle = infoschema.NewHandle(d.store)
d.ddl = ddl.NewDDL(d.store, d.infoHandle, &ddlCallback{do: d}, lease)
d.mustReload()
variable.RegisterStatistics(d)
go d.loadSchemaInLoop(lease)
return d, nil
}
开发者ID:lovedboy,项目名称:tidb,代码行数:17,代码来源:domain.go
示例7: NewDomain
// NewDomain creates a new domain.
func NewDomain(store kv.Storage, lease int) (d *Domain, err error) {
d = &Domain{
store: store,
lease: lease,
}
d.infoHandle = infoschema.NewHandle(d.store)
d.ddl = ddl.NewDDL(d.store, d.infoHandle, d.onDDLChange, lease)
err = d.reload()
if err != nil {
log.Fatalf("load schema err %v", err)
}
go d.loadSchemaInLoop()
return d, nil
}
开发者ID:netroby,项目名称:tidb,代码行数:18,代码来源:domain.go
示例8: NewDomain
// NewDomain creates a new domain.
func NewDomain(store kv.Storage, lease time.Duration) (d *Domain, err error) {
d = &Domain{store: store}
d.infoHandle, err = infoschema.NewHandle(d.store)
if err != nil {
return nil, errors.Trace(err)
}
d.ddl = ddl.NewDDL(d.store, d.infoHandle, &ddlCallback{do: d}, lease)
d.mustReload()
variable.RegisterStatistics(d)
// Only when the store is local that the lease value is 0.
// If the store is local, it doesn't need loadSchemaInLoop.
if lease > 0 {
d.leaseCh = make(chan time.Duration, 1)
go d.loadSchemaInLoop(lease)
}
return d, nil
}
开发者ID:yubobo,项目名称:tidb,代码行数:22,代码来源:domain.go
示例9: TestT
func (ts *testSuite) TestT(c *C) {
handle := infoschema.NewHandle(ts.store)
handle.Set(nil)
dd := ddl.NewDDL(ts.store, handle)
se, _ := tidb.CreateSession(ts.store)
ctx := se.(context.Context)
schemaName := model.NewCIStr("test")
tblName := model.NewCIStr("t")
tbIdent := table.Ident{
Schema: schemaName,
Name: tblName,
}
noExist := model.NewCIStr("noexist")
err := dd.CreateSchema(ctx, tbIdent.Schema)
c.Assert(err, IsNil)
err = dd.CreateSchema(ctx, tbIdent.Schema)
c.Assert(errors2.ErrorEqual(err, ddl.ErrExists), IsTrue)
tbStmt := statement("create table t (a int primary key not null, b varchar(255), key idx_b (b), c int, d int unique)").(*stmts.CreateTableStmt)
err = dd.CreateTable(ctx, table.Ident{Schema: noExist, Name: tbIdent.Name}, tbStmt.Cols, tbStmt.Constraints)
c.Assert(errors2.ErrorEqual(err, qerror.ErrDatabaseNotExist), IsTrue)
err = dd.CreateTable(ctx, tbIdent, tbStmt.Cols, tbStmt.Constraints)
c.Assert(err, IsNil)
err = dd.CreateTable(ctx, tbIdent, tbStmt.Cols, tbStmt.Constraints)
c.Assert(errors2.ErrorEqual(err, ddl.ErrExists), IsTrue)
tbIdent2 := tbIdent
tbIdent2.Name = model.NewCIStr("t2")
tbStmt = statement("create table t2 (a int unique not null)").(*stmts.CreateTableStmt)
err = dd.CreateTable(ctx, tbIdent2, tbStmt.Cols, tbStmt.Constraints)
c.Assert(err, IsNil)
tb, err := handle.Get().TableByName(tbIdent.Schema, tbIdent.Name)
c.Assert(err, IsNil)
_, err = tb.AddRecord(ctx, []interface{}{1, "b", 2, 4})
c.Assert(err, IsNil)
alterStmt := statement("alter table t add column aa int first").(*stmts.AlterTableStmt)
dd.AlterTable(ctx, tbIdent, alterStmt.Specs)
c.Assert(alterStmt.Specs[0].String(), Not(Equals), "")
// Check indices info
is := handle.Get()
tbl, err := is.TableByName(schemaName, tblName)
c.Assert(err, IsNil)
c.Assert(tbl, NotNil)
expectedOffset := make(map[string]int)
expectedOffset["a"] = 1
expectedOffset["b"] = 2
expectedOffset["d"] = 4
for _, idx := range tbl.Indices() {
for _, col := range idx.Columns {
o, ok := expectedOffset[col.Name.L]
c.Assert(ok, IsTrue)
c.Assert(col.Offset, Equals, o)
}
}
alterStmt = statement("alter table t add column bb int after b").(*stmts.AlterTableStmt)
err = dd.AlterTable(ctx, tbIdent, alterStmt.Specs)
c.Assert(err, IsNil)
c.Assert(alterStmt.Specs[0].String(), Not(Equals), "")
// Inserting a duplicated column will cause error.
alterStmt = statement("alter table t add column bb int after b").(*stmts.AlterTableStmt)
err = dd.AlterTable(ctx, tbIdent, alterStmt.Specs)
c.Assert(err, NotNil)
idxStmt := statement("CREATE INDEX idx_c ON t (c)").(*stmts.CreateIndexStmt)
idxName := model.NewCIStr(idxStmt.IndexName)
err = dd.CreateIndex(ctx, tbIdent, idxStmt.Unique, idxName, idxStmt.IndexColNames)
c.Assert(err, IsNil)
tbs := handle.Get().SchemaTables(tbIdent.Schema)
c.Assert(len(tbs), Equals, 2)
err = dd.DropIndex(ctx, tbIdent.Schema, tbIdent.Name, idxName)
c.Assert(err, IsNil)
err = dd.DropTable(ctx, tbIdent)
c.Assert(err, IsNil)
tbs = handle.Get().SchemaTables(tbIdent.Schema)
c.Assert(len(tbs), Equals, 1)
err = dd.DropSchema(ctx, noExist)
c.Assert(errors2.ErrorEqual(err, ddl.ErrNotExists), IsTrue)
err = dd.DropSchema(ctx, tbIdent.Schema)
c.Assert(err, IsNil)
}
开发者ID:nengwang,项目名称:tidb,代码行数:86,代码来源:ddl_test.go
示例10: TestT
func (*testSuite) TestT(c *C) {
table.TableFromMeta = tables.TableFromMeta
driver := localstore.Driver{Driver: goleveldb.MemoryDriver{}}
store, err := driver.Open("memory")
c.Assert(err, IsNil)
defer store.Close()
handle := infoschema.NewHandle(store)
dbName := model.NewCIStr("Test")
tbName := model.NewCIStr("T")
colName := model.NewCIStr("A")
idxName := model.NewCIStr("idx")
noexist := model.NewCIStr("noexist")
colInfo := &model.ColumnInfo{
ID: 3,
Name: colName,
Offset: 0,
FieldType: *types.NewFieldType(mysqldef.TypeLonglong),
}
idxInfo := &model.IndexInfo{
Name: idxName,
Table: tbName,
Columns: []*model.IndexColumn{
&model.IndexColumn{
Name: colName,
Offset: 0,
Length: 10,
},
},
Unique: true,
Primary: true,
}
tblInfo := &model.TableInfo{
ID: 2,
Name: tbName,
Columns: []*model.ColumnInfo{colInfo},
Indices: []*model.IndexInfo{idxInfo},
}
dbInfo := &model.DBInfo{
ID: 1,
Name: dbName,
Tables: []*model.TableInfo{tblInfo},
}
dbInfos := []*model.DBInfo{dbInfo}
handle.Set(dbInfos)
is := handle.Get()
schemaNames := is.AllSchemaNames()
c.Assert(len(schemaNames), Equals, 1)
c.Assert(schemaNames[0], Equals, "Test")
schemas := is.AllSchemas()
c.Assert(len(schemas), Equals, 1)
schemas = is.Clone()
c.Assert(len(schemas), Equals, 1)
c.Assert(is.SchemaExists(dbName), IsTrue)
c.Assert(is.SchemaExists(noexist), IsFalse)
schema, ok := is.SchemaByID(1)
c.Assert(ok, IsTrue)
c.Assert(schema, NotNil)
schema, ok = is.SchemaByID(2)
c.Assert(ok, IsFalse)
c.Assert(schema, IsNil)
schema, ok = is.SchemaByName(dbName)
c.Assert(ok, IsTrue)
c.Assert(schema, NotNil)
schema, ok = is.SchemaByName(noexist)
c.Assert(ok, IsFalse)
c.Assert(schema, IsNil)
c.Assert(is.TableExists(dbName, tbName), IsTrue)
c.Assert(is.TableExists(dbName, noexist), IsFalse)
tb, ok := is.TableByID(2)
c.Assert(ok, IsTrue)
c.Assert(tb, NotNil)
tb, ok = is.TableByID(3)
c.Assert(ok, IsFalse)
c.Assert(tb, IsNil)
tb, err = is.TableByName(dbName, tbName)
c.Assert(err, IsNil)
c.Assert(tb, NotNil)
tb, err = is.TableByName(dbName, noexist)
c.Assert(err, NotNil)
//.........这里部分代码省略.........
开发者ID:rchunping,项目名称:tidb,代码行数:101,代码来源:infoschema_test.go
示例11: TestT
func (*testSuite) TestT(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)
dbName := model.NewCIStr("Test")
tbName := model.NewCIStr("T")
colName := model.NewCIStr("A")
idxName := model.NewCIStr("idx")
noexist := model.NewCIStr("noexist")
colID, err := genGlobalID(store)
c.Assert(err, IsNil)
colInfo := &model.ColumnInfo{
ID: colID,
Name: colName,
Offset: 0,
FieldType: *types.NewFieldType(mysql.TypeLonglong),
State: model.StatePublic,
}
idxInfo := &model.IndexInfo{
Name: idxName,
Table: tbName,
Columns: []*model.IndexColumn{
{
Name: colName,
Offset: 0,
Length: 10,
},
},
Unique: true,
Primary: true,
State: model.StatePublic,
}
tbID, err := genGlobalID(store)
c.Assert(err, IsNil)
tblInfo := &model.TableInfo{
ID: tbID,
Name: tbName,
Columns: []*model.ColumnInfo{colInfo},
Indices: []*model.IndexInfo{idxInfo},
State: model.StatePublic,
}
dbID, err := genGlobalID(store)
c.Assert(err, IsNil)
dbInfo := &model.DBInfo{
ID: dbID,
Name: dbName,
Tables: []*model.TableInfo{tblInfo},
State: model.StatePublic,
}
dbInfos := []*model.DBInfo{dbInfo}
err = kv.RunInNewTxn(store, true, func(txn kv.Transaction) error {
meta.NewMeta(txn).CreateDatabase(dbInfo)
return errors.Trace(err)
})
c.Assert(err, IsNil)
builder, err := infoschema.NewBuilder(handle).InitWithDBInfos(dbInfos, 1)
c.Assert(err, IsNil)
txn, err := store.Begin()
c.Assert(err, IsNil)
checkApplyCreateNonExistsSchemaDoesNotPanic(c, txn, builder)
checkApplyCreateNonExistsTableDoesNotPanic(c, txn, builder, dbID)
txn.Rollback()
err = builder.Build()
c.Assert(err, IsNil)
is := handle.Get()
schemaNames := is.AllSchemaNames()
c.Assert(schemaNames, HasLen, 3)
c.Assert(testutil.CompareUnorderedStringSlice(schemaNames, []string{infoschema.Name, perfschema.Name, "Test"}), IsTrue)
schemas := is.AllSchemas()
c.Assert(schemas, HasLen, 3)
schemas = is.Clone()
c.Assert(schemas, HasLen, 3)
c.Assert(is.SchemaExists(dbName), IsTrue)
c.Assert(is.SchemaExists(noexist), IsFalse)
schema, ok := is.SchemaByID(dbID)
c.Assert(ok, IsTrue)
c.Assert(schema, NotNil)
schema, ok = is.SchemaByID(tbID)
c.Assert(ok, IsFalse)
c.Assert(schema, IsNil)
//.........这里部分代码省略.........
开发者ID:jmptrader,项目名称:tidb,代码行数:101,代码来源:infoschema_test.go
示例12: TestT
func (*testSuite) TestT(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)
dbName := model.NewCIStr("Test")
tbName := model.NewCIStr("T")
colName := model.NewCIStr("A")
idxName := model.NewCIStr("idx")
noexist := model.NewCIStr("noexist")
colID, err := genGlobalID(store)
c.Assert(err, IsNil)
colInfo := &model.ColumnInfo{
ID: colID,
Name: colName,
Offset: 0,
FieldType: *types.NewFieldType(mysql.TypeLonglong),
State: model.StatePublic,
}
idxInfo := &model.IndexInfo{
Name: idxName,
Table: tbName,
Columns: []*model.IndexColumn{
{
Name: colName,
Offset: 0,
Length: 10,
},
},
Unique: true,
Primary: true,
State: model.StatePublic,
}
tbID, err := genGlobalID(store)
c.Assert(err, IsNil)
tblInfo := &model.TableInfo{
ID: tbID,
Name: tbName,
Columns: []*model.ColumnInfo{colInfo},
Indices: []*model.IndexInfo{idxInfo},
State: model.StatePublic,
}
dbID, err := genGlobalID(store)
c.Assert(err, IsNil)
dbInfo := &model.DBInfo{
ID: dbID,
Name: dbName,
Tables: []*model.TableInfo{tblInfo},
State: model.StatePublic,
}
dbInfos := []*model.DBInfo{dbInfo}
handle.Set(dbInfos, 1)
is := handle.Get()
schemaNames := is.AllSchemaNames()
c.Assert(schemaNames, HasLen, 3)
c.Assert(testutil.CompareUnorderedStringSlice(schemaNames, []string{infoschema.Name, perfschema.Name, "Test"}), IsTrue)
schemas := is.AllSchemas()
c.Assert(schemas, HasLen, 3)
schemas = is.Clone()
c.Assert(schemas, HasLen, 3)
c.Assert(is.SchemaExists(dbName), IsTrue)
c.Assert(is.SchemaExists(noexist), IsFalse)
schema, ok := is.SchemaByID(dbID)
c.Assert(ok, IsTrue)
c.Assert(schema, NotNil)
schema, ok = is.SchemaByID(tbID)
c.Assert(ok, IsFalse)
c.Assert(schema, IsNil)
schema, ok = is.SchemaByName(dbName)
c.Assert(ok, IsTrue)
c.Assert(schema, NotNil)
schema, ok = is.SchemaByName(noexist)
c.Assert(ok, IsFalse)
c.Assert(schema, IsNil)
c.Assert(is.TableExists(dbName, tbName), IsTrue)
c.Assert(is.TableExists(dbName, noexist), IsFalse)
tb, ok := is.TableByID(tbID)
c.Assert(ok, IsTrue)
c.Assert(tb, NotNil)
tb, ok = is.TableByID(dbID)
//.........这里部分代码省略.........
开发者ID:XuHuaiyu,项目名称:tidb,代码行数:101,代码来源:infoschema_test.go
注:本文中的github.com/pingcap/tidb/infoschema.NewHandle函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论