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

The following examples show how to use org.apache.hadoop.hbase.regionserver.HRegion#getRowLock() . 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 Apache License 2.0 5 votes vote down vote up
private static void acquireLock(HRegion region, byte[] key, List<RowLock> locks)
    throws IOException {
    RowLock rowLock = region.getRowLock(key);
    if (rowLock == null) {
        throw new IOException("Failed to acquire lock on " + Bytes.toStringBinary(key));
    }
    locks.add(rowLock);
}
 
Example 2
Source File: SequenceRegionObserver.java    From phoenix with Apache License 2.0 5 votes vote down vote up
private static void acquireLock(HRegion region, byte[] key, List<RowLock> locks)
    throws IOException {
    RowLock rowLock = region.getRowLock(key);
    if (rowLock == null) {
        throw new IOException("Failed to acquire lock on " + Bytes.toStringBinary(key));
    }
    locks.add(rowLock);
}
 
Example 3
Source File: MetaDataEndpointImpl.java    From phoenix with Apache License 2.0 4 votes vote down vote up
private PTable doGetTable(byte[] key, long clientTimeStamp, RowLock rowLock) throws IOException, SQLException {
    ImmutableBytesPtr cacheKey = new ImmutableBytesPtr(key);
    Cache<ImmutableBytesPtr, PTable> metaDataCache =
            GlobalCache.getInstance(this.env).getMetaDataCache();
    PTable table = metaDataCache.getIfPresent(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
    // 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.
     */
    final boolean wasLocked = (rowLock != null);
    if (!wasLocked) {
        rowLock = region.getRowLock(key);
        if (rowLock == 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.getIfPresent(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 (!wasLocked) rowLock.release();
    }
}