Search in sources :

Example 1 with FlushRegionResponse

use of org.apache.hadoop.hbase.shaded.protobuf.generated.AdminProtos.FlushRegionResponse in project hbase by apache.

the class RSRpcServices method flushRegion.

/**
   * Flush a region on the region server.
   *
   * @param controller the RPC controller
   * @param request the request
   * @throws ServiceException
   */
@Override
@QosPriority(priority = HConstants.ADMIN_QOS)
public FlushRegionResponse flushRegion(final RpcController controller, final FlushRegionRequest request) throws ServiceException {
    try {
        checkOpen();
        requestCount.increment();
        Region region = getRegion(request.getRegion());
        LOG.info("Flushing " + region.getRegionInfo().getRegionNameAsString());
        boolean shouldFlush = true;
        if (request.hasIfOlderThanTs()) {
            shouldFlush = region.getEarliestFlushTimeForAllStores() < request.getIfOlderThanTs();
        }
        FlushRegionResponse.Builder builder = FlushRegionResponse.newBuilder();
        if (shouldFlush) {
            boolean writeFlushWalMarker = request.hasWriteFlushWalMarker() ? request.getWriteFlushWalMarker() : false;
            // Go behind the curtain so we can manage writing of the flush WAL marker
            HRegion.FlushResultImpl flushResult = (HRegion.FlushResultImpl) ((HRegion) region).flushcache(true, writeFlushWalMarker);
            boolean compactionNeeded = flushResult.isCompactionNeeded();
            if (compactionNeeded) {
                regionServer.compactSplitThread.requestSystemCompaction(region, "Compaction through user triggered flush");
            }
            builder.setFlushed(flushResult.isFlushSucceeded());
            builder.setWroteFlushWalMarker(flushResult.wroteFlushWalMarker);
        }
        builder.setLastFlushTime(region.getEarliestFlushTimeForAllStores());
        return builder.build();
    } catch (DroppedSnapshotException ex) {
        // Cache flush can fail in a few places. If it fails in a critical
        // section, we get a DroppedSnapshotException and a replay of wal
        // is required. Currently the only way to do this is a restart of
        // the server.
        regionServer.abort("Replay of WAL required. Forcing server shutdown", ex);
        throw new ServiceException(ex);
    } catch (IOException ie) {
        throw new ServiceException(ie);
    }
}
Also used : DroppedSnapshotException(org.apache.hadoop.hbase.DroppedSnapshotException) ServiceException(org.apache.hadoop.hbase.shaded.com.google.protobuf.ServiceException) FlushRegionResponse(org.apache.hadoop.hbase.shaded.protobuf.generated.AdminProtos.FlushRegionResponse) InterruptedIOException(java.io.InterruptedIOException) IOException(java.io.IOException) DoNotRetryIOException(org.apache.hadoop.hbase.DoNotRetryIOException) HBaseIOException(org.apache.hadoop.hbase.HBaseIOException) QosPriority(org.apache.hadoop.hbase.ipc.QosPriority)

Example 2 with FlushRegionResponse

use of org.apache.hadoop.hbase.shaded.protobuf.generated.AdminProtos.FlushRegionResponse 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)2 InterruptedIOException (java.io.InterruptedIOException)2 FlushRegionResponse (org.apache.hadoop.hbase.shaded.protobuf.generated.AdminProtos.FlushRegionResponse)2 DoNotRetryIOException (org.apache.hadoop.hbase.DoNotRetryIOException)1 DroppedSnapshotException (org.apache.hadoop.hbase.DroppedSnapshotException)1 HBaseIOException (org.apache.hadoop.hbase.HBaseIOException)1 TableNotFoundException (org.apache.hadoop.hbase.TableNotFoundException)1 FlushRegionCallable (org.apache.hadoop.hbase.client.FlushRegionCallable)1 QosPriority (org.apache.hadoop.hbase.ipc.QosPriority)1 ServiceException (org.apache.hadoop.hbase.shaded.com.google.protobuf.ServiceException)1 RetryCounter (org.apache.hadoop.hbase.util.RetryCounter)1 RetryCounterFactory (org.apache.hadoop.hbase.util.RetryCounterFactory)1