Search in sources :

Example 1 with PrepareResponse

use of org.apache.hadoop.ozone.protocol.proto.OzoneManagerProtocolProtos.PrepareResponse in project ozone by apache.

the class OzoneManagerProtocolClientSideTranslatorPB method prepareOzoneManager.

@Override
public long prepareOzoneManager(long txnApplyWaitTimeoutSeconds, long txnApplyCheckIntervalSeconds) throws IOException {
    Preconditions.checkArgument(txnApplyWaitTimeoutSeconds > 0, "txnApplyWaitTimeoutSeconds has to be > zero");
    Preconditions.checkArgument(txnApplyCheckIntervalSeconds > 0 && txnApplyCheckIntervalSeconds < txnApplyWaitTimeoutSeconds / 2, "txnApplyCheckIntervalSeconds has to be > zero and < half " + "of txnApplyWaitTimeoutSeconds to make sense.");
    PrepareRequest prepareRequest = PrepareRequest.newBuilder().setArgs(PrepareRequestArgs.newBuilder().setTxnApplyWaitTimeoutSeconds(txnApplyWaitTimeoutSeconds).setTxnApplyCheckIntervalSeconds(txnApplyCheckIntervalSeconds).build()).build();
    OMRequest omRequest = createOMRequest(Type.Prepare).setPrepareRequest(prepareRequest).build();
    PrepareResponse prepareResponse = handleError(submitRequest(omRequest)).getPrepareResponse();
    return prepareResponse.getTxnID();
}
Also used : OMRequest(org.apache.hadoop.ozone.protocol.proto.OzoneManagerProtocolProtos.OMRequest) CancelPrepareResponse(org.apache.hadoop.ozone.protocol.proto.OzoneManagerProtocolProtos.CancelPrepareResponse) PrepareResponse(org.apache.hadoop.ozone.protocol.proto.OzoneManagerProtocolProtos.PrepareResponse) CancelPrepareRequest(org.apache.hadoop.ozone.protocol.proto.OzoneManagerProtocolProtos.CancelPrepareRequest) PrepareRequest(org.apache.hadoop.ozone.protocol.proto.OzoneManagerProtocolProtos.PrepareRequest)

Example 2 with PrepareResponse

use of org.apache.hadoop.ozone.protocol.proto.OzoneManagerProtocolProtos.PrepareResponse in project ozone by apache.

the class OMPrepareRequest method validateAndUpdateCache.

@Override
public OMClientResponse validateAndUpdateCache(OzoneManager ozoneManager, long transactionLogIndex, OzoneManagerDoubleBufferHelper ozoneManagerDoubleBufferHelper) {
    LOG.info("OM {} Received prepare request with log index {}", ozoneManager.getOMNodeId(), transactionLogIndex);
    OMRequest omRequest = getOmRequest();
    OzoneManagerProtocolProtos.PrepareRequestArgs args = omRequest.getPrepareRequest().getArgs();
    OMResponse.Builder responseBuilder = OmResponseUtil.getOMResponseBuilder(omRequest);
    responseBuilder.setCmdType(Type.Prepare);
    OMClientResponse response = null;
    // Allow double buffer this many seconds to flush all transactions before
    // returning an error to the caller.
    Duration flushTimeout = Duration.of(args.getTxnApplyWaitTimeoutSeconds(), ChronoUnit.SECONDS);
    // Time between checks to see if double buffer finished flushing.
    Duration flushCheckInterval = Duration.of(args.getTxnApplyCheckIntervalSeconds(), ChronoUnit.SECONDS);
    try {
        // Create response.
        PrepareResponse omResponse = PrepareResponse.newBuilder().setTxnID(transactionLogIndex).build();
        responseBuilder.setPrepareResponse(omResponse);
        response = new OMPrepareResponse(responseBuilder.build(), transactionLogIndex);
        // Add response to double buffer before clearing logs.
        // This guarantees the log index of this request will be the same as
        // the snapshot index in the prepared state.
        ozoneManagerDoubleBufferHelper.add(response, transactionLogIndex);
        OzoneManagerRatisServer omRatisServer = ozoneManager.getOmRatisServer();
        RaftServer.Division division = omRatisServer.getServer().getDivision(omRatisServer.getRaftGroup().getGroupId());
        // Wait for outstanding double buffer entries to flush to disk,
        // so they will not be purged from the log before being persisted to
        // the DB.
        // Since the response for this request was added to the double buffer
        // already, once this index reaches the state machine, we know all
        // transactions have been flushed.
        waitForLogIndex(transactionLogIndex, ozoneManager, division, flushTimeout, flushCheckInterval);
        takeSnapshotAndPurgeLogs(transactionLogIndex, division);
        // Save prepare index to a marker file, so if the OM restarts,
        // it will remain in prepare mode as long as the file exists and its
        // log indices are >= the one in the file.
        ozoneManager.getPrepareState().finishPrepare(transactionLogIndex);
        LOG.info("OM {} prepared at log index {}. Returning response {} with " + "log index {}", ozoneManager.getOMNodeId(), transactionLogIndex, omResponse, omResponse.getTxnID());
    } catch (OMException e) {
        LOG.error("Prepare Request Apply failed in {}. ", ozoneManager.getOMNodeId(), e);
        response = new OMPrepareResponse(createErrorOMResponse(responseBuilder, e));
    } catch (InterruptedException | IOException e) {
        // Set error code so that prepare failure does not cause the OM to
        // terminate.
        LOG.error("Prepare Request Apply failed in {}. ", ozoneManager.getOMNodeId(), e);
        response = new OMPrepareResponse(createErrorOMResponse(responseBuilder, new OMException(e, OMException.ResultCodes.PREPARE_FAILED)));
        // above error response to the caller.
        try {
            ozoneManager.getPrepareState().cancelPrepare();
        } catch (IOException ex) {
            LOG.error("Failed to delete prepare marker file.", ex);
        }
        if (e instanceof InterruptedException) {
            Thread.currentThread().interrupt();
        }
    }
    return response;
}
Also used : OMClientResponse(org.apache.hadoop.ozone.om.response.OMClientResponse) PrepareResponse(org.apache.hadoop.ozone.protocol.proto.OzoneManagerProtocolProtos.PrepareResponse) OMPrepareResponse(org.apache.hadoop.ozone.om.response.upgrade.OMPrepareResponse) RaftServer(org.apache.ratis.server.RaftServer) Duration(java.time.Duration) IOException(java.io.IOException) OMResponse(org.apache.hadoop.ozone.protocol.proto.OzoneManagerProtocolProtos.OMResponse) OMRequest(org.apache.hadoop.ozone.protocol.proto.OzoneManagerProtocolProtos.OMRequest) OzoneManagerProtocolProtos(org.apache.hadoop.ozone.protocol.proto.OzoneManagerProtocolProtos) OzoneManagerRatisServer(org.apache.hadoop.ozone.om.ratis.OzoneManagerRatisServer) OMPrepareResponse(org.apache.hadoop.ozone.om.response.upgrade.OMPrepareResponse) OMException(org.apache.hadoop.ozone.om.exceptions.OMException)

Aggregations

OMRequest (org.apache.hadoop.ozone.protocol.proto.OzoneManagerProtocolProtos.OMRequest)2 PrepareResponse (org.apache.hadoop.ozone.protocol.proto.OzoneManagerProtocolProtos.PrepareResponse)2 IOException (java.io.IOException)1 Duration (java.time.Duration)1 OMException (org.apache.hadoop.ozone.om.exceptions.OMException)1 OzoneManagerRatisServer (org.apache.hadoop.ozone.om.ratis.OzoneManagerRatisServer)1 OMClientResponse (org.apache.hadoop.ozone.om.response.OMClientResponse)1 OMPrepareResponse (org.apache.hadoop.ozone.om.response.upgrade.OMPrepareResponse)1 OzoneManagerProtocolProtos (org.apache.hadoop.ozone.protocol.proto.OzoneManagerProtocolProtos)1 CancelPrepareRequest (org.apache.hadoop.ozone.protocol.proto.OzoneManagerProtocolProtos.CancelPrepareRequest)1 CancelPrepareResponse (org.apache.hadoop.ozone.protocol.proto.OzoneManagerProtocolProtos.CancelPrepareResponse)1 OMResponse (org.apache.hadoop.ozone.protocol.proto.OzoneManagerProtocolProtos.OMResponse)1 PrepareRequest (org.apache.hadoop.ozone.protocol.proto.OzoneManagerProtocolProtos.PrepareRequest)1 RaftServer (org.apache.ratis.server.RaftServer)1