本文整理汇总了Golang中github.com/cockroachdb/cockroach/pkg/sql/sqlbase.Descriptor类的典型用法代码示例。如果您正苦于以下问题:Golang Descriptor类的具体用法?Golang Descriptor怎么用?Golang Descriptor使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Descriptor类的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: GetZoneConfig
// GetZoneConfig returns the zone config for the object with 'id'.
func GetZoneConfig(cfg config.SystemConfig, id uint32) (config.ZoneConfig, bool, error) {
// Look in the zones table.
if zoneVal := cfg.GetValue(sqlbase.MakeZoneKey(sqlbase.ID(id))); zoneVal != nil {
// We're done.
zone, err := config.MigrateZoneConfig(zoneVal)
return zone, true, err
}
// No zone config for this ID. We need to figure out if it's a database
// or table. Lookup its descriptor.
if descVal := cfg.GetValue(sqlbase.MakeDescMetadataKey(sqlbase.ID(id))); descVal != nil {
// Determine whether this is a database or table.
var desc sqlbase.Descriptor
if err := descVal.GetProto(&desc); err != nil {
return config.ZoneConfig{}, false, err
}
if tableDesc := desc.GetTable(); tableDesc != nil {
// This is a table descriptor. Lookup its parent database zone config.
return GetZoneConfig(cfg, uint32(tableDesc.ParentID))
}
}
// Retrieve the default zone config, but only as long as that wasn't the ID
// we were trying to retrieve (avoid infinite recursion).
if id != keys.RootNamespaceID {
return GetZoneConfig(cfg, keys.RootNamespaceID)
}
// No descriptor or not a table.
return config.ZoneConfig{}, false, nil
}
示例2: restoreTableDesc
func restoreTableDesc(
ctx context.Context,
txn *client.Txn,
database sqlbase.DatabaseDescriptor,
table sqlbase.TableDescriptor,
) error {
// Run getDescriptorID again to make sure the database hasn't been dropped
// while we were importing.
var err error
if table.ParentID, err = getDescriptorID(txn, tableKey{name: database.Name}); err != nil {
return err
}
tableIDKey := tableKey{parentID: table.ParentID, name: table.Name}.Key()
tableDescKey := sqlbase.MakeDescMetadataKey(table.ID)
// Check for an existing table.
var existingDesc sqlbase.Descriptor
existingIDKV, err := txn.Get(tableIDKey)
if err != nil {
return err
}
if existingIDKV.Value != nil {
existingID, err := existingIDKV.Value.GetInt()
if err != nil {
return err
}
existingDescKV, err := txn.Get(sqlbase.MakeDescMetadataKey(sqlbase.ID(existingID)))
if err != nil {
return err
}
if err := existingDescKV.Value.GetProto(&existingDesc); err != nil {
return err
}
}
// Write the new descriptors. First the ID -> TableDescriptor for the new
// table, then flip (or initialize) the name -> ID entry so any new queries
// will use the new one. If there was an existing table, it can now be
// cleaned up.
b := txn.NewBatch()
b.CPut(tableDescKey, sqlbase.WrapDescriptor(&table), nil)
if existingTable := existingDesc.GetTable(); existingTable == nil {
b.CPut(tableIDKey, table.ID, nil)
} else {
existingIDKV.Value.ClearChecksum()
b.CPut(tableIDKey, table.ID, existingIDKV.Value)
// TODO(dan): This doesn't work for interleaved tables. Fix it when we
// fix the empty range interleaved table TODO below.
existingDataPrefix := roachpb.Key(keys.MakeTablePrefix(uint32(existingTable.ID)))
b.DelRange(existingDataPrefix, existingDataPrefix.PrefixEnd(), false)
zoneKey, _, descKey := GetKeysForTableDescriptor(existingTable)
// Delete the desc and zone entries. Leave the name because the new
// table is using it.
b.Del(descKey)
b.Del(zoneKey)
}
return txn.Run(b)
}
示例3: isDeleted
func isDeleted(tableID sqlbase.ID, cfg config.SystemConfig) bool {
descKey := sqlbase.MakeDescMetadataKey(tableID)
val := cfg.GetValue(descKey)
if val == nil {
return false
}
var descriptor sqlbase.Descriptor
if err := val.GetProto(&descriptor); err != nil {
panic("unable to unmarshal table descriptor")
}
table := descriptor.GetTable()
return table.Dropped()
}
示例4: isRenamed
// isRenamed tests if a descriptor is updated by gossip to the specified name
// and version.
func isRenamed(
tableID sqlbase.ID,
expectedName string,
expectedVersion sqlbase.DescriptorVersion,
cfg config.SystemConfig,
) bool {
descKey := sqlbase.MakeDescMetadataKey(tableID)
val := cfg.GetValue(descKey)
if val == nil {
return false
}
var descriptor sqlbase.Descriptor
if err := val.GetProto(&descriptor); err != nil {
panic("unable to unmarshal table descriptor")
}
table := descriptor.GetTable()
return table.Name == expectedName && table.Version == expectedVersion
}
示例5: waitForConfigChange
func waitForConfigChange(t *testing.T, s *server.TestServer) config.SystemConfig {
var foundDesc sqlbase.Descriptor
var cfg config.SystemConfig
testutils.SucceedsSoon(t, func() error {
var ok bool
if cfg, ok = s.Gossip().GetSystemConfig(); ok {
if val := cfg.GetValue(configDescKey); val != nil {
if err := val.GetProto(&foundDesc); err != nil {
t.Fatal(err)
}
if id := foundDesc.GetDatabase().GetID(); id != configID {
return errors.Errorf("expected database id %d; got %d", configID, id)
}
return nil
}
}
return errors.Errorf("got nil system config")
})
return cfg
}