本文整理汇总了Golang中github.com/cockroachdb/cockroach/storage.Replica.GetReplica方法的典型用法代码示例。如果您正苦于以下问题:Golang Replica.GetReplica方法的具体用法?Golang Replica.GetReplica怎么用?Golang Replica.GetReplica使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/cockroachdb/cockroach/storage.Replica
的用法示例。
在下文中一共展示了Replica.GetReplica方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: lookupReplica
// lookupReplica looks up replica by key [range]. Lookups are done
// by consulting each store in turn via Store.LookupRange(key).
// Returns RangeID and replica on success; RangeKeyMismatch error
// if not found.
// This is only for testing usage; performance doesn't matter.
func (ls *LocalSender) lookupReplica(start, end roachpb.RKey) (rangeID roachpb.RangeID, replica *roachpb.ReplicaDescriptor, err error) {
ls.mu.RLock()
defer ls.mu.RUnlock()
var rng *storage.Replica
for _, store := range ls.storeMap {
rng = store.LookupReplica(start, end)
if rng == nil {
if tmpRng := store.LookupReplica(start, nil); tmpRng != nil {
log.Warningf(fmt.Sprintf("range not contained in one range: [%s,%s), but have [%s,%s)", start, end, tmpRng.Desc().StartKey, tmpRng.Desc().EndKey))
}
continue
}
if replica == nil {
rangeID = rng.Desc().RangeID
replica = rng.GetReplica()
continue
}
// Should never happen outside of tests.
return 0, nil, util.Errorf(
"range %+v exists on additional store: %+v", rng, store)
}
if replica == nil {
err = roachpb.NewRangeKeyMismatchError(start.AsRawKey(), end.AsRawKey(), nil)
}
return rangeID, replica, err
}
示例2: lookupReplica
// lookupReplica looks up replica by key [range]. Lookups are done
// by consulting each store in turn via Store.LookupRange(key).
// Returns RangeID and replica on success; RangeKeyMismatch error
// if not found.
// TODO(tschottdorf) with a very large number of stores, the LocalSender
// may want to avoid scanning the whole map of stores on each invocation.
func (ls *LocalSender) lookupReplica(start, end proto.Key) (rangeID proto.RangeID, replica *proto.Replica, err error) {
ls.mu.RLock()
defer ls.mu.RUnlock()
var rng *storage.Replica
for _, store := range ls.storeMap {
rng = store.LookupReplica(start, end)
if rng == nil {
continue
}
if replica == nil {
rangeID = rng.Desc().RangeID
replica = rng.GetReplica()
continue
}
// Should never happen outside of tests.
return 0, nil, util.Errorf(
"range %+v exists on additional store: %+v", rng, store)
}
if replica == nil {
err = proto.NewRangeKeyMismatchError(start, end, nil)
}
return rangeID, replica, err
}