コード例 #1
0
ファイル: local_db_test.go プロジェクト: GavinHwa/cockroach
func (db *LocalDB) addTestRange(start, end engine.Key) *storage.Range {
	r := storage.Range{}
	rep := storage.Replica{NodeID: 1, StoreID: 1, RangeID: int64(len(db.ranges) + 1)}
	r.Meta = storage.RangeMetadata{
		ClusterID:       "some-cluster",
		RangeID:         rep.RangeID,
		RangeDescriptor: storage.RangeDescriptor{StartKey: start, EndKey: end, Replicas: []storage.Replica{rep}},
	}
	db.ranges = append(db.ranges, &r)
	return &r
}
コード例 #2
0
ファイル: local_kv_test.go プロジェクト: bigrats/cockroach
func addTestRange(kv *LocalKV, start, end engine.Key) *storage.Range {
	r := storage.Range{}
	rep := proto.Replica{NodeID: 1, StoreID: 1, RangeID: int64(len(kv.ranges) + 1)}
	r.Meta = &proto.RangeMetadata{
		ClusterID:       "some-cluster",
		RangeID:         rep.RangeID,
		RangeDescriptor: proto.RangeDescriptor{StartKey: start, EndKey: end, Replicas: []proto.Replica{rep}},
	}
	kv.ranges = append(kv.ranges, &r)
	return &r
}
コード例 #3
0
ファイル: local_sender.go プロジェクト: routhcr/cockroach
// lookupReplica looks up replica by key [range]. Lookups are done
// by consulting each store in turn via Store.LookupRange(key).
// Returns RaftID 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) (raftID proto.RaftID, replica *proto.Replica, err error) {
	ls.mu.RLock()
	defer ls.mu.RUnlock()
	var rng *storage.Range
	for _, store := range ls.storeMap {
		rng = store.LookupRange(start, end)
		if rng == nil {
			continue
		}
		if replica == nil {
			raftID = rng.Desc().RaftID
			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 raftID, replica, err
}