本文整理汇总了Golang中github.com/cockroachdb/cockroach/pkg/config.SystemConfig.GetValue方法的典型用法代码示例。如果您正苦于以下问题:Golang SystemConfig.GetValue方法的具体用法?Golang SystemConfig.GetValue怎么用?Golang SystemConfig.GetValue使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/cockroachdb/cockroach/pkg/config.SystemConfig
的用法示例。
在下文中一共展示了SystemConfig.GetValue方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: GetTableDesc
// GetTableDesc returns the table descriptor for the table with 'id'.
// Returns nil if the descriptor is not present, or is present but is not a
// table.
func GetTableDesc(cfg config.SystemConfig, id sqlbase.ID) (*sqlbase.TableDescriptor, error) {
if descVal := cfg.GetValue(sqlbase.MakeDescMetadataKey(id)); descVal != nil {
desc := &sqlbase.Descriptor{}
if err := descVal.GetProto(desc); err != nil {
return nil, err
}
return desc.GetTable(), nil
}
return nil, nil
}
示例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: expectDescriptorID
func expectDescriptorID(systemConfig config.SystemConfig, idKey roachpb.Key, id sqlbase.ID) error {
idValue := systemConfig.GetValue(idKey)
if idValue == nil {
return errStaleMetadata
}
cachedID, err := idValue.GetInt()
if err != nil {
return err
}
if sqlbase.ID(cachedID) != id {
return errStaleMetadata
}
return nil
}
示例5: expectDescriptor
func expectDescriptor(
systemConfig config.SystemConfig, idKey roachpb.Key, desc *sqlbase.Descriptor,
) error {
descValue := systemConfig.GetValue(idKey)
if descValue == nil {
return errStaleMetadata
}
var cachedDesc sqlbase.Descriptor
if err := descValue.GetProto(&cachedDesc); err != nil {
return err
}
if !proto.Equal(&cachedDesc, desc) {
return errStaleMetadata
}
return nil
}
示例6: 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
}
示例7: TestGet
func TestGet(t *testing.T) {
defer leaktest.AfterTest(t)()
emptyKeys := []roachpb.KeyValue{}
someKeys := []roachpb.KeyValue{
plainKV("a", "vala"),
plainKV("c", "valc"),
plainKV("d", "vald"),
}
aVal := roachpb.MakeValueFromString("vala")
bVal := roachpb.MakeValueFromString("valc")
cVal := roachpb.MakeValueFromString("vald")
testCases := []struct {
values []roachpb.KeyValue
key string
value *roachpb.Value
}{
{emptyKeys, "a", nil},
{emptyKeys, "b", nil},
{emptyKeys, "c", nil},
{emptyKeys, "d", nil},
{emptyKeys, "e", nil},
{someKeys, "", nil},
{someKeys, "b", nil},
{someKeys, "e", nil},
{someKeys, "a0", nil},
{someKeys, "a", &aVal},
{someKeys, "c", &bVal},
{someKeys, "d", &cVal},
}
cfg := config.SystemConfig{}
for tcNum, tc := range testCases {
cfg.Values = tc.values
if val := cfg.GetValue([]byte(tc.key)); !proto.Equal(val, tc.value) {
t.Errorf("#%d: expected=%s, found=%s", tcNum, tc.value, val)
}
}
}
示例8: 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
}
示例9: expectDeleted
func expectDeleted(systemConfig config.SystemConfig, key roachpb.Key) error {
if systemConfig.GetValue(key) != nil {
return errStaleMetadata
}
return nil
}