Java Code Examples for org.apache.hadoop.hbase.regionserver.HRegion#releaseRowLock()

The following examples show how to use org.apache.hadoop.hbase.regionserver.HRegion#releaseRowLock() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: MetaDataEndpointImpl.java    From phoenix with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
private static void releaseLocks(HRegion region, List<Integer> lids) {
    for (Integer lid : lids) {
        region.releaseRowLock(lid);
    }
}
 
Example 2
Source File: MetaDataEndpointImpl.java    From phoenix with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
private PTable doGetTable(byte[] key, long clientTimeStamp) throws IOException, SQLException {
    ImmutableBytesPtr cacheKey = new ImmutableBytesPtr(key);
    Map<ImmutableBytesPtr,PTable> metaDataCache = GlobalCache.getInstance(this.getEnvironment()).getMetaDataCache();
    PTable table = metaDataCache.get(cacheKey);
    // We only cache the latest, so we'll end up building the table with every call if the client connection has specified an SCN.
    // TODO: If we indicate to the client that we're returning an older version, but there's a newer version available, the client
    // can safely not call this, since we only allow modifications to the latest.
    if (table != null && table.getTimeStamp() < clientTimeStamp) {
        // Table on client is up-to-date with table on server, so just return
        if (isTableDeleted(table)) {
            return null;
        }
        return table;
    }
    // Ask Lars about the expense of this call - if we don't take the lock, we still won't get partial results
    // get the co-processor environment
    RegionCoprocessorEnvironment env = getEnvironment();
    // TODO: check that key is within region.getStartKey() and region.getEndKey()
    // and return special code to force client to lookup region from meta.
    HRegion region = env.getRegion();
    /*
     * Lock directly on key, though it may be an index table.
     * This will just prevent a table from getting rebuilt
     * too often.
     */
    Integer lid = region.getLock(null, key, true);
    if (lid == null) {
        throw new IOException("Failed to acquire lock on " + Bytes.toStringBinary(key));
    }
    try {
        // Try cache again in case we were waiting on a lock
        table = metaDataCache.get(cacheKey);
        // We only cache the latest, so we'll end up building the table with every call if the client connection has specified an SCN.
        // TODO: If we indicate to the client that we're returning an older version, but there's a newer version available, the client
        // can safely not call this, since we only allow modifications to the latest.
        if (table != null && table.getTimeStamp() < clientTimeStamp) {
            // Table on client is up-to-date with table on server, so just return
            if (isTableDeleted(table)) {
                return null;
            }
            return table;
        }
        // Query for the latest table first, since it's not cached
        table = buildTable(key, cacheKey, region, HConstants.LATEST_TIMESTAMP);
        if (table != null && table.getTimeStamp() < clientTimeStamp) {
            return table;
        }
        // Otherwise, query for an older version of the table - it won't be cached 
        return buildTable(key, cacheKey, region, clientTimeStamp);
    } finally {
        if (lid != null) region.releaseRowLock(lid);
    }
}