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