本文整理汇总了Golang中github.com/pingcap/tidb/meta.GenGlobalID函数的典型用法代码示例。如果您正苦于以下问题:Golang GenGlobalID函数的具体用法?Golang GenGlobalID怎么用?Golang GenGlobalID使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了GenGlobalID函数的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: 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))
}
示例2: CreateSchema
func (d *ddl) CreateSchema(ctx context.Context, schema model.CIStr) (err error) {
is := d.GetInformationSchema()
_, ok := is.SchemaByName(schema)
if ok {
return errors.Trace(ErrExists)
}
info := &model.DBInfo{Name: schema}
info.ID, err = meta.GenGlobalID(d.store)
if err != nil {
return errors.Trace(err)
}
err = kv.RunInNewTxn(d.store, false, func(txn kv.Transaction) error {
err := d.verifySchemaMetaVersion(txn, is.SchemaMetaVersion())
if err != nil {
return errors.Trace(err)
}
err = d.writeSchemaInfo(info, txn)
return errors.Trace(err)
})
if d.onDDLChange != nil {
err = d.onDDLChange(err)
}
return errors.Trace(err)
}
示例3: CreateSchema
func (d *ddl) CreateSchema(ctx context.Context, schema model.CIStr) (err error) {
is := d.GetInformationSchema()
_, ok := is.SchemaByName(schema)
if ok {
return ErrExists
}
info := &model.DBInfo{Name: schema}
info.ID, err = meta.GenGlobalID(d.store)
if err != nil {
return errors.Trace(err)
}
err = d.writeSchemaInfo(info)
if err != nil {
return errors.Trace(err)
}
newInfo := append(is.Clone(), info)
d.infoHandle.Set(newInfo)
return nil
}
示例4: buildTableInfo
func (d *ddl) buildTableInfo(tableName model.CIStr, cols []*column.Col, constraints []*coldef.TableConstraint) (tbInfo *model.TableInfo, err error) {
tbInfo = &model.TableInfo{
Name: tableName,
}
tbInfo.ID, err = meta.GenGlobalID(d.store)
if err != nil {
return nil, errors.Trace(err)
}
for _, v := range cols {
tbInfo.Columns = append(tbInfo.Columns, &v.ColumnInfo)
}
for _, constr := range constraints {
// 1. check if the column is exists
// 2. add index
indexColumns := make([]*model.IndexColumn, 0, len(constr.Keys))
for _, key := range constr.Keys {
col := column.FindCol(cols, key.ColumnName)
if col == nil {
return nil, errors.Errorf("No such column: %v", key)
}
indexColumns = append(indexColumns, &model.IndexColumn{
Name: model.NewCIStr(key.ColumnName),
Offset: col.Offset,
Length: key.Length,
})
}
idxInfo := &model.IndexInfo{
Name: model.NewCIStr(constr.ConstrName),
Columns: indexColumns,
}
switch constr.Tp {
case coldef.ConstrPrimaryKey:
idxInfo.Unique = true
idxInfo.Primary = true
idxInfo.Name = model.NewCIStr(column.PrimaryKeyName)
case coldef.ConstrUniq, coldef.ConstrUniqKey, coldef.ConstrUniqIndex:
idxInfo.Unique = true
}
tbInfo.Indices = append(tbInfo.Indices, idxInfo)
}
return
}
示例5: buildColumnAndConstraint
func (d *ddl) buildColumnAndConstraint(offset int, colDef *coldef.ColumnDef) (*column.Col, []*coldef.TableConstraint, error) {
// set charset
if len(colDef.Tp.Charset) == 0 {
switch colDef.Tp.Tp {
case mysql.TypeString, mysql.TypeVarchar, mysql.TypeVarString, mysql.TypeBlob, mysql.TypeTinyBlob, mysql.TypeMediumBlob, mysql.TypeLongBlob:
colDef.Tp.Charset, colDef.Tp.Collate = getDefaultCharsetAndCollate()
default:
colDef.Tp.Charset = charset.CharsetBin
colDef.Tp.Collate = charset.CharsetBin
}
}
// convert colDef into col
col, cts, err := coldef.ColumnDefToCol(offset, colDef)
if err != nil {
return nil, nil, errors.Trace(err)
}
col.ID, err = meta.GenGlobalID(d.store)
if err != nil {
return nil, nil, errors.Trace(err)
}
return col, cts, nil
}