本文整理汇总了Golang中github.com/cockroachdb/cockroach/sql/sqlbase.DescriptorMutation类的典型用法代码示例。如果您正苦于以下问题:Golang DescriptorMutation类的具体用法?Golang DescriptorMutation怎么用?Golang DescriptorMutation使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了DescriptorMutation类的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: writeMutation
// writeMutation writes the mutation to the table descriptor. If the
// State or the Direction is undefined, these values are populated via
// picking random values before the mutation is written.
func (mt mutationTest) writeMutation(m sqlbase.DescriptorMutation) {
if m.Direction == sqlbase.DescriptorMutation_NONE {
// randomly pick ADD/DROP mutation if this is the first mutation, or
// pick the direction already chosen for the first mutation.
if len(mt.tableDesc.Mutations) > 0 {
m.Direction = mt.tableDesc.Mutations[0].Direction
} else {
m.Direction = sqlbase.DescriptorMutation_DROP
if rand.Intn(2) == 0 {
m.Direction = sqlbase.DescriptorMutation_ADD
}
}
}
if m.State == sqlbase.DescriptorMutation_UNKNOWN {
// randomly pick DELETE_ONLY/WRITE_ONLY state.
r := rand.Intn(2)
if r == 0 {
m.State = sqlbase.DescriptorMutation_DELETE_ONLY
} else {
m.State = sqlbase.DescriptorMutation_WRITE_ONLY
}
}
mt.tableDesc.Mutations = append(mt.tableDesc.Mutations, m)
if err := mt.tableDesc.Validate(); err != nil {
mt.Fatal(err)
}
if err := mt.kvDB.Put(
sqlbase.MakeDescMetadataKey(mt.tableDesc.ID),
sqlbase.WrapDescriptor(mt.tableDesc),
); err != nil {
mt.Fatal(err)
}
}
示例2: writeMutation
// writeMutation writes the mutation to the table descriptor. If the
// State or the Direction is undefined, these values are populated via
// picking random values before the mutation is written.
func (mt mutationTest) writeMutation(m sqlbase.DescriptorMutation) {
if m.Direction == sqlbase.DescriptorMutation_NONE {
// randomly pick ADD/DROP mutation.
r := rand.Intn(2)
if r == 0 {
m.Direction = sqlbase.DescriptorMutation_ADD
} else {
m.Direction = sqlbase.DescriptorMutation_DROP
}
}
if m.State == sqlbase.DescriptorMutation_UNKNOWN {
// randomly pick DELETE_ONLY/WRITE_ONLY state.
r := rand.Intn(2)
if r == 0 {
m.State = sqlbase.DescriptorMutation_DELETE_ONLY
} else {
m.State = sqlbase.DescriptorMutation_WRITE_ONLY
}
}
tableDesc := mt.desc.GetTable()
tableDesc.Mutations = append(tableDesc.Mutations, m)
if err := tableDesc.Validate(); err != nil {
mt.Fatal(err)
}
if err := mt.kvDB.Put(mt.descKey, mt.desc); err != nil {
mt.Fatal(err)
}
}
示例3: writeColumnMutation
// writeColumnMutation adds column as a mutation and writes the
// descriptor to the DB.
func (mt mutationTest) writeColumnMutation(column string, m sqlbase.DescriptorMutation) {
_, i, err := mt.tableDesc.FindColumnByName(column)
if err != nil {
mt.Fatal(err)
}
col := mt.tableDesc.Columns[i]
mt.tableDesc.Columns = append(mt.tableDesc.Columns[:i], mt.tableDesc.Columns[i+1:]...)
m.Descriptor_ = &sqlbase.DescriptorMutation_Column{Column: &col}
mt.writeMutation(m)
}
示例4: writeIndexMutation
// writeIndexMutation adds index as a mutation and writes the
// descriptor to the DB.
func (mt mutationTest) writeIndexMutation(index string, m sqlbase.DescriptorMutation) {
tableDesc := mt.tableDesc
_, i, err := tableDesc.FindIndexByName(index)
if err != nil {
mt.Fatal(err)
}
idx := tableDesc.Indexes[i]
tableDesc.Indexes = append(tableDesc.Indexes[:i], tableDesc.Indexes[i+1:]...)
m.Descriptor_ = &sqlbase.DescriptorMutation_Index{Index: &idx}
mt.writeMutation(m)
}