Search in sources :

Example 1 with FlushRegionCallable

use of org.apache.hadoop.hbase.client.FlushRegionCallable in project hbase by apache.

the class RegionReplicaFlushHandler method triggerFlushInPrimaryRegion.

void triggerFlushInPrimaryRegion(final HRegion region) throws IOException, RuntimeException {
    long pause = connection.getConfiguration().getLong(HConstants.HBASE_CLIENT_PAUSE, HConstants.DEFAULT_HBASE_CLIENT_PAUSE);
    int maxAttempts = getRetriesCount(connection.getConfiguration());
    RetryCounter counter = new RetryCounterFactory(maxAttempts, (int) pause).create();
    if (LOG.isDebugEnabled()) {
        LOG.debug("Attempting to do an RPC to the primary region replica " + ServerRegionReplicaUtil.getRegionInfoForDefaultReplica(region.getRegionInfo()).getEncodedName() + " of region " + region.getRegionInfo().getEncodedName() + " to trigger a flush");
    }
    while (!region.isClosing() && !region.isClosed() && !server.isAborted() && !server.isStopped()) {
        FlushRegionCallable flushCallable = new FlushRegionCallable(connection, rpcControllerFactory, RegionReplicaUtil.getRegionInfoForDefaultReplica(region.getRegionInfo()), true);
        // TODO: flushRegion() is a blocking call waiting for the flush to complete. Ideally we
        // do not have to wait for the whole flush here, just initiate it.
        FlushRegionResponse response = null;
        try {
            response = rpcRetryingCallerFactory.<FlushRegionResponse>newCaller().callWithRetries(flushCallable, this.operationTimeout);
        } catch (IOException ex) {
            if (ex instanceof TableNotFoundException || connection.isTableDisabled(region.getRegionInfo().getTable())) {
                return;
            }
            throw ex;
        }
        if (response.getFlushed()) {
            // a complete flush cycle or replay a region open event
            if (LOG.isDebugEnabled()) {
                LOG.debug("Successfully triggered a flush of primary region replica " + ServerRegionReplicaUtil.getRegionInfoForDefaultReplica(region.getRegionInfo()).getEncodedName() + " of region " + region.getRegionInfo().getEncodedName() + " Now waiting and blocking reads until observing a full flush cycle");
            }
            break;
        } else {
            if (response.hasWroteFlushWalMarker()) {
                if (response.getWroteFlushWalMarker()) {
                    if (LOG.isDebugEnabled()) {
                        LOG.debug("Successfully triggered an empty flush marker(memstore empty) of primary " + "region replica " + ServerRegionReplicaUtil.getRegionInfoForDefaultReplica(region.getRegionInfo()).getEncodedName() + " of region " + region.getRegionInfo().getEncodedName() + " Now waiting and " + "blocking reads until observing a flush marker");
                    }
                    break;
                } else {
                    // closing or already flushing. Retry flush again after some sleep.
                    if (!counter.shouldRetry()) {
                        throw new IOException("Cannot cause primary to flush or drop a wal marker after " + "retries. Failing opening of this region replica " + region.getRegionInfo().getEncodedName());
                    }
                }
            } else {
                // nothing to do. Are we dealing with an old server?
                LOG.warn("Was not able to trigger a flush from primary region due to old server version? " + "Continuing to open the secondary region replica: " + region.getRegionInfo().getEncodedName());
                region.setReadsEnabled(true);
                break;
            }
        }
        try {
            counter.sleepUntilNextRetry();
        } catch (InterruptedException e) {
            throw new InterruptedIOException(e.getMessage());
        }
    }
}
Also used : TableNotFoundException(org.apache.hadoop.hbase.TableNotFoundException) InterruptedIOException(java.io.InterruptedIOException) RetryCounterFactory(org.apache.hadoop.hbase.util.RetryCounterFactory) RetryCounter(org.apache.hadoop.hbase.util.RetryCounter) FlushRegionCallable(org.apache.hadoop.hbase.client.FlushRegionCallable) FlushRegionResponse(org.apache.hadoop.hbase.shaded.protobuf.generated.AdminProtos.FlushRegionResponse) IOException(java.io.IOException) InterruptedIOException(java.io.InterruptedIOException)

Aggregations

IOException (java.io.IOException)1 InterruptedIOException (java.io.InterruptedIOException)1 TableNotFoundException (org.apache.hadoop.hbase.TableNotFoundException)1 FlushRegionCallable (org.apache.hadoop.hbase.client.FlushRegionCallable)1 FlushRegionResponse (org.apache.hadoop.hbase.shaded.protobuf.generated.AdminProtos.FlushRegionResponse)1 RetryCounter (org.apache.hadoop.hbase.util.RetryCounter)1 RetryCounterFactory (org.apache.hadoop.hbase.util.RetryCounterFactory)1