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;
}
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;
}
Aggregations