本文整理匯總了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
}