Example usage for java.util.concurrent ConcurrentSkipListMap floorEntry

List of usage examples for java.util.concurrent ConcurrentSkipListMap floorEntry

Introduction

In this page you can find the example usage for java.util.concurrent ConcurrentSkipListMap floorEntry.

Prototype

public Map.Entry<K, V> floorEntry(K key) 

Source Link

Document

Returns a key-value mapping associated with the greatest key less than or equal to the given key, or null if there is no such key.

Usage

From source file:org.apache.hadoop.hbase.client.MetaCache.java

/**
 * Search the cache for a location that fits our table and row key.
 * Return null if no suitable region is located.
 *
 *
 * @param tableName//from  w  ww .j a  v  a 2 s  . c  om
 * @param row
 * @return Null or region location found in cache.
 */
public RegionLocations getCachedLocation(final TableName tableName, final byte[] row) {
    ConcurrentSkipListMap<byte[], RegionLocations> tableLocations = getTableLocations(tableName);

    Entry<byte[], RegionLocations> e = tableLocations.floorEntry(row);
    if (e == null) {
        return null;
    }
    RegionLocations possibleRegion = e.getValue();

    // make sure that the end key is greater than the row we're looking
    // for, otherwise the row actually belongs in the next region, not
    // this one. the exception case is when the endkey is
    // HConstants.EMPTY_END_ROW, signifying that the region we're
    // checking is actually the last region in the table.
    byte[] endKey = possibleRegion.getRegionLocation().getRegionInfo().getEndKey();
    // Here we do direct Bytes.compareTo and not doing CellComparator/MetaCellComparator path.
    // MetaCellComparator is for comparing against data in META table which need special handling.
    // Not doing that is ok for this case because
    // 1. We are getting the Region location for the given row in non META tables only. The compare
    // checks the given row is within the end key of the found region. So META regions are not
    // coming in here.
    // 2. Even if META region comes in, its end key will be empty byte[] and so Bytes.equals(endKey,
    // HConstants.EMPTY_END_ROW) check itself will pass.
    if (Bytes.equals(endKey, HConstants.EMPTY_END_ROW)
            || Bytes.compareTo(endKey, 0, endKey.length, row, 0, row.length) > 0) {
        return possibleRegion;
    }

    // Passed all the way through, so we got nothing - complete cache miss
    return null;
}