Esempio n. 1
0
// LookupRangeMetadata attempts to locate metadata for the range containing the
// given Key. This is done by querying the two-level lookup table of range
// metadata 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
// metadata for the range where the key's value resides. Range metadata
// 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 *RangeMetadataCache) LookupRangeMetadata(key engine.Key) (*proto.RangeDescriptor, error) {
	_, r := rmc.getCachedRangeMetadata(key)
	if r != nil {
		return r, nil
	}

	rs, err := rmc.db.getRangeMetadata(key)
	if err != nil {
		return nil, err
	}
	rmc.rangeCacheMu.Lock()
	for i := range rs {
		rmc.rangeCache.Add(rangeCacheKey(engine.RangeMetadataLookupKey(&rs[i])), &rs[i])
	}
	rmc.rangeCacheMu.Unlock()
	return &rs[0], nil
}
Esempio n. 2
0
func (a testMetadataNode) Compare(b llrb.Comparable) int {
	aKey := engine.RangeMetadataLookupKey(a.RangeDescriptor)
	bKey := engine.RangeMetadataLookupKey(b.(testMetadataNode).RangeDescriptor)
	return bytes.Compare(aKey, bKey)
}