本文整理汇总了Golang中github.com/cockroachdb/cockroach/config.SystemConfig.Get方法的典型用法代码示例。如果您正苦于以下问题:Golang SystemConfig.Get方法的具体用法?Golang SystemConfig.Get怎么用?Golang SystemConfig.Get使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/cockroachdb/cockroach/config.SystemConfig
的用法示例。
在下文中一共展示了SystemConfig.Get方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: GetZoneConfig
// GetZoneConfig returns the zone config for the object with 'id'.
func GetZoneConfig(cfg *config.SystemConfig, id uint32) (*config.ZoneConfig, error) {
// Look in the zones table.
if val, ok := cfg.Get(MakeZoneKey(ID(id))); ok {
zone := &config.ZoneConfig{}
if err := gogoproto.Unmarshal(val, zone); err != nil {
return nil, err
}
// We're done.
return zone, nil
}
// No zone config for this ID. We need to figure out if it's a database
// or table. Lookup its descriptor.
rawDesc, ok := cfg.Get(MakeDescMetadataKey(ID(id)))
if !ok {
// No descriptor. This table/db could have been deleted,
// just return the default config.
return config.DefaultZoneConfig, nil
}
// Determine whether this is a database or table.
// TODO(marc): we need a better way of doing this. Options include:
// - add a type field on the descriptor table
// - separate descriptor tables for databases and tables
// - prebuild list of databases and tables in the system config
var dbDesc DatabaseDescriptor
if err := gogoproto.Unmarshal(rawDesc, &dbDesc); err == nil {
// parses as a database: return default config.
return config.DefaultZoneConfig, nil
}
var tableDesc TableDescriptor
if err := gogoproto.Unmarshal(rawDesc, &tableDesc); err != nil {
// does not parse as a table either: this means an entry in the
// descriptor table we're not familiar with.
return nil, util.Errorf("descriptor for object ID %d is not a table or database", id)
}
// This is a table descriptor. Lookup its parent database zone config.
return GetZoneConfig(cfg, uint32(tableDesc.ParentID))
}