Пример #1
0
// LookupRangeDescriptor attempts to locate a descriptor for the range
// containing the given Key. This is done by querying the two-level
// lookup table of range descriptors which cockroach maintains.
//
// This method first looks up the specified key in the first level of
// range metadata, which returns the location of the key within the
// second level of range metadata. This second level location is then
// queried to retrieve a descriptor for the range where the key's
// value resides. Range descriptors retrieved during each search are
// cached for subsequent lookups.
//
// This method returns the RangeDescriptor for the range containing
// the key's data, or an error if any occurred.
func (rmc *RangeDescriptorCache) LookupRangeDescriptor(key proto.Key) (*proto.RangeDescriptor, error) {
	_, r := rmc.getCachedRangeDescriptor(key)
	if r != nil {
		return r, nil
	}

	rs, err := rmc.db.getRangeDescriptor(key)
	if err != nil {
		return nil, err
	}
	rmc.rangeCacheMu.Lock()
	for i := range rs {
		rmc.rangeCache.Add(rangeCacheKey(engine.RangeMetaLookupKey(&rs[i])), &rs[i])
	}
	rmc.rangeCacheMu.Unlock()
	return &rs[0], nil
}
Пример #2
0
func (a testDescriptorNode) Compare(b llrb.Comparable) int {
	aKey := engine.RangeMetaLookupKey(a.RangeDescriptor)
	bKey := engine.RangeMetaLookupKey(b.(testDescriptorNode).RangeDescriptor)
	return bytes.Compare(aKey, bKey)
}