Search in sources :

Example 1 with OMPrepareResponse

use of org.apache.hadoop.ozone.om.response.upgrade.OMPrepareResponse in project ozone by apache.

the class OMCancelPrepareRequest method validateAndUpdateCache.

@Override
public OMClientResponse validateAndUpdateCache(OzoneManager ozoneManager, long transactionLogIndex, OzoneManagerDoubleBufferHelper ozoneManagerDoubleBufferHelper) {
    LOG.info("OM {} Received cancel prepare request with log index {}", ozoneManager.getOMNodeId(), transactionLogIndex);
    OMRequest omRequest = getOmRequest();
    OMResponse.Builder responseBuilder = OmResponseUtil.getOMResponseBuilder(omRequest);
    responseBuilder.setCmdType(Type.CancelPrepare);
    OMClientResponse response = null;
    try {
        String username = getOmRequest().getUserInfo().getUserName();
        if (ozoneManager.getAclsEnabled() && !ozoneManager.isAdmin(username)) {
            throw new OMException("Access denied for user " + username + ". " + "Superuser privilege is required to cancel ozone manager " + "preparation.", OMException.ResultCodes.ACCESS_DENIED);
        }
        // Create response.
        CancelPrepareResponse omResponse = CancelPrepareResponse.newBuilder().build();
        responseBuilder.setCancelPrepareResponse(omResponse);
        response = new OMCancelPrepareResponse(responseBuilder.build());
        // Deletes on disk marker file, does not update DB and therefore does
        // not update cache.
        ozoneManager.getPrepareState().cancelPrepare();
        ozoneManagerDoubleBufferHelper.add(response, transactionLogIndex);
        LOG.info("OM {} prepare state cancelled at log index {}. Returning " + "response {}", ozoneManager.getOMNodeId(), transactionLogIndex, omResponse);
    } catch (IOException e) {
        LOG.error("Cancel Prepare Request apply failed in {}. ", ozoneManager.getOMNodeId(), e);
        response = new OMPrepareResponse(createErrorOMResponse(responseBuilder, e));
    }
    return response;
}
Also used : OMRequest(org.apache.hadoop.ozone.protocol.proto.OzoneManagerProtocolProtos.OMRequest) OMClientResponse(org.apache.hadoop.ozone.om.response.OMClientResponse) CancelPrepareResponse(org.apache.hadoop.ozone.protocol.proto.OzoneManagerProtocolProtos.CancelPrepareResponse) OMCancelPrepareResponse(org.apache.hadoop.ozone.om.response.upgrade.OMCancelPrepareResponse) IOException(java.io.IOException) OMCancelPrepareResponse(org.apache.hadoop.ozone.om.response.upgrade.OMCancelPrepareResponse) OMException(org.apache.hadoop.ozone.om.exceptions.OMException) OMPrepareResponse(org.apache.hadoop.ozone.om.response.upgrade.OMPrepareResponse) OMResponse(org.apache.hadoop.ozone.protocol.proto.OzoneManagerProtocolProtos.OMResponse)

Example 2 with OMPrepareResponse

use of org.apache.hadoop.ozone.om.response.upgrade.OMPrepareResponse 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

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