本文整理汇总了Golang中github.com/pingcap/tidb/meta.Meta.GetDatabase方法的典型用法代码示例。如果您正苦于以下问题:Golang Meta.GetDatabase方法的具体用法?Golang Meta.GetDatabase怎么用?Golang Meta.GetDatabase使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/pingcap/tidb/meta.Meta
的用法示例。
在下文中一共展示了Meta.GetDatabase方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: onDropSchema
func (d *ddl) onDropSchema(t *meta.Meta, job *model.Job) error {
dbInfo, err := t.GetDatabase(job.SchemaID)
if err != nil {
return errors.Trace(err)
}
if dbInfo == nil {
job.State = model.JobCancelled
return errors.Trace(infoschema.ErrDatabaseDropExists)
}
ver, err := updateSchemaVersion(t, job)
if err != nil {
return errors.Trace(err)
}
switch dbInfo.State {
case model.StatePublic:
// public -> write only
job.SchemaState = model.StateWriteOnly
dbInfo.State = model.StateWriteOnly
err = t.UpdateDatabase(dbInfo)
case model.StateWriteOnly:
// write only -> delete only
job.SchemaState = model.StateDeleteOnly
dbInfo.State = model.StateDeleteOnly
err = t.UpdateDatabase(dbInfo)
case model.StateDeleteOnly:
dbInfo.State = model.StateNone
tables, err := t.ListTables(job.SchemaID)
if err != nil {
return errors.Trace(err)
}
err = t.UpdateDatabase(dbInfo)
if err = t.DropDatabase(dbInfo.ID); err != nil {
break
}
// finish this job
addDBHistoryInfo(job, ver, dbInfo)
if len(tables) > 0 {
job.Args = append(job.Args, getIDs(tables))
}
job.State = model.JobDone
job.SchemaState = model.StateNone
default:
// we can't enter here.
err = errors.Errorf("invalid db state %v", dbInfo.State)
}
return errors.Trace(err)
}
示例2: applyCreateSchema
func (b *Builder) applyCreateSchema(m *meta.Meta, diff *model.SchemaDiff) error {
di, err := m.GetDatabase(diff.SchemaID)
if err != nil {
return errors.Trace(err)
}
if di == nil {
// When we apply an old schema diff, the database may has been dropped already, so we need to fall back to
// full load.
return ErrDatabaseNotExists
}
b.is.schemaMap[di.Name.L] = &schemaTables{dbInfo: di, tables: make(map[string]table.Table)}
return nil
}
示例3: applyCreateSchema
func (b *Builder) applyCreateSchema(m *meta.Meta, diff *model.SchemaDiff) error {
di, err := m.GetDatabase(diff.SchemaID)
if err != nil {
return errors.Trace(err)
}
if di == nil {
// When we apply an old schema diff, the database may has been dropped already, so we need to fall back to
// full load.
return ErrDatabaseNotExists
}
b.is.schemas[di.ID] = di
b.is.schemaNameToID[di.Name.L] = di.ID
return nil
}
示例4: onDropSchema
func (d *ddl) onDropSchema(t *meta.Meta, job *model.Job) error {
dbInfo, err := t.GetDatabase(job.SchemaID)
if err != nil {
return errors.Trace(err)
}
if dbInfo == nil {
job.State = model.JobCancelled
return errors.Trace(infoschema.ErrDatabaseNotExists)
}
_, err = t.GenSchemaVersion()
if err != nil {
return errors.Trace(err)
}
switch dbInfo.State {
case model.StatePublic:
// public -> write only
job.SchemaState = model.StateWriteOnly
dbInfo.State = model.StateWriteOnly
err = t.UpdateDatabase(dbInfo)
case model.StateWriteOnly:
// write only -> delete only
job.SchemaState = model.StateDeleteOnly
dbInfo.State = model.StateDeleteOnly
err = t.UpdateDatabase(dbInfo)
case model.StateDeleteOnly:
dbInfo.State = model.StateDeleteReorganization
err = t.UpdateDatabase(dbInfo)
if err = t.DropDatabase(dbInfo.ID); err != nil {
break
}
// finish this job
job.Args = []interface{}{dbInfo}
job.State = model.JobDone
job.SchemaState = model.StateNone
default:
// we can't enter here.
err = errors.Errorf("invalid db state %v", dbInfo.State)
}
return errors.Trace(err)
}
示例5: onDropSchema
func (d *ddl) onDropSchema(t *meta.Meta, job *model.Job) error {
dbInfo, err := t.GetDatabase(job.SchemaID)
if err != nil {
return errors.Trace(err)
}
if dbInfo == nil {
job.State = model.JobCancelled
return errors.Trace(ErrNotExists)
}
_, err = t.GenSchemaVersion()
if err != nil {
return errors.Trace(err)
}
switch dbInfo.State {
case model.StatePublic:
// public -> write only
job.SchemaState = model.StateWriteOnly
dbInfo.State = model.StateWriteOnly
err = t.UpdateDatabase(dbInfo)
return errors.Trace(err)
case model.StateWriteOnly:
// write only -> delete only
job.SchemaState = model.StateDeleteOnly
dbInfo.State = model.StateDeleteOnly
err = t.UpdateDatabase(dbInfo)
return errors.Trace(err)
case model.StateDeleteOnly:
// delete only -> reorganization
job.SchemaState = model.StateDeleteReorganization
dbInfo.State = model.StateDeleteReorganization
err = t.UpdateDatabase(dbInfo)
return errors.Trace(err)
case model.StateDeleteReorganization:
// wait reorganization jobs done and drop meta.
var tables []*model.TableInfo
tables, err = t.ListTables(dbInfo.ID)
if err != nil {
return errors.Trace(err)
}
err = d.runReorgJob(func() error {
return d.dropSchemaData(dbInfo, tables)
})
if terror.ErrorEqual(err, errWaitReorgTimeout) {
// if timeout, we should return, check for the owner and re-wait job done.
return nil
}
if err != nil {
return errors.Trace(err)
}
// all reorganization jobs done, drop this database
if err = t.DropDatabase(dbInfo.ID); err != nil {
return errors.Trace(err)
}
// finish this job
job.State = model.JobDone
job.SchemaState = model.StateNone
return nil
default:
// we can't enter here.
return errors.Errorf("invalid db state %v", dbInfo.State)
}
}