本文整理匯總了Golang中github.com/cockroachdb/cockroach/gossip.Gossip.GetInfo方法的典型用法代碼示例。如果您正苦於以下問題:Golang Gossip.GetInfo方法的具體用法?Golang Gossip.GetInfo怎麽用?Golang Gossip.GetInfo使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/cockroachdb/cockroach/gossip.Gossip
的用法示例。
在下文中一共展示了Gossip.GetInfo方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: computeSplitKeys
// computeSplitKeys returns an array of keys at which the supplied
// range should be split, as computed by intersecting the range with
// accounting and zone config map boundaries.
func computeSplitKeys(g *gossip.Gossip, rng *Range) []proto.Key {
// Now split the range into pieces by intersecting it with the
// boundaries of the config map.
splitKeys := proto.KeySlice{}
for _, configKey := range []string{gossip.KeyConfigAccounting, gossip.KeyConfigZone} {
info, err := g.GetInfo(configKey)
if err != nil {
log.Errorf("unable to fetch %s config from gossip: %s", configKey, err)
continue
}
configMap := info.(PrefixConfigMap)
splits, err := configMap.SplitRangeByPrefixes(rng.Desc().StartKey, rng.Desc().EndKey)
if err != nil {
log.Errorf("unable to split %s by prefix map %s", rng, configMap)
continue
}
// Gather new splits.
for _, split := range splits {
if split.end.Less(rng.Desc().EndKey) {
splitKeys = append(splitKeys, split.end)
}
}
}
// Sort and unique the combined split keys from intersections with
// both the accounting and zone config maps.
sort.Sort(splitKeys)
var unique []proto.Key
for i, key := range splitKeys {
if i == 0 || !key.Equal(splitKeys[i-1]) {
unique = append(unique, key)
}
}
return unique
}
示例2: lookupZoneConfig
// lookupZoneConfig returns the zone config matching the range.
func lookupZoneConfig(g *gossip.Gossip, rng *Range) (proto.ZoneConfig, error) {
zoneMap, err := g.GetInfo(gossip.KeyConfigZone)
if err != nil || zoneMap == nil {
return proto.ZoneConfig{}, util.Errorf("unable to lookup zone config for range %s: %s", rng, err)
}
prefixConfig := zoneMap.(PrefixConfigMap).MatchByPrefix(rng.Desc().StartKey)
return *prefixConfig.Config.(*proto.ZoneConfig), nil
}
示例3: storeDescFromGossip
// storeDescFromGossip retrieves a StoreDescriptor from the specified
// capacity gossip key. Returns an error if the gossip doesn't exist
// or is not a StoreDescriptor.
func storeDescFromGossip(key string, g *gossip.Gossip) (*proto.StoreDescriptor, error) {
info, err := g.GetInfo(key)
if err != nil {
return nil, err
}
storeDesc, ok := info.(proto.StoreDescriptor)
if !ok {
return nil, fmt.Errorf("gossiped info is not a StoreDescriptor: %+v", info)
}
return &storeDesc, nil
}