本文整理汇总了Golang中github.com/cockroachdb/cockroach/pkg/sql/sqlbase.DescriptorMutation.Direction方法的典型用法代码示例。如果您正苦于以下问题:Golang DescriptorMutation.Direction方法的具体用法?Golang DescriptorMutation.Direction怎么用?Golang DescriptorMutation.Direction使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/cockroachdb/cockroach/pkg/sql/sqlbase.DescriptorMutation
的用法示例。
在下文中一共展示了DescriptorMutation.Direction方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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.ValidateTable(); err != nil {
mt.Fatal(err)
}
if err := mt.kvDB.Put(
context.TODO(),
sqlbase.MakeDescMetadataKey(mt.tableDesc.ID),
sqlbase.WrapDescriptor(mt.tableDesc),
); err != nil {
mt.Fatal(err)
}
}