use of com.linkedin.databus.core.DispatcherRetriesExhaustedException in project databus by linkedin.
the class GenericDispatcher method doRollback.
protected void doRollback(DispatcherState curState, SCN rollbackScn, boolean checkRetries, boolean regressItr) {
boolean success = true;
boolean debugEnabled = _log.isDebugEnabled();
if (!curState.getStateId().equals(StateId.ROLLBACK)) {
success = false;
_log.error("ROLLBACK state is expected by the dispatcher, but the current state is:" + curState.getStateId());
}
int retriesLeft = Integer.MAX_VALUE;
if (checkRetries) {
retriesLeft = getStatus().getRetriesLeft();
_log.info("Rolling back the dispatcher to last successful checkpoint. Number of remaining retries for dispatcher to replay events = " + retriesLeft);
success = success && (retriesLeft > 0);
if (success) {
if (0 == getStatus().getRetriesNum())
getStatus().retryOnError("rollback");
else
getStatus().retryOnLastError();
}
}
if (success) {
Checkpoint lastCp = curState.getLastSuccessfulCheckpoint();
if ((null != lastCp) || (!regressItr)) {
ConsumerCallbackResult callbackResult = ConsumerCallbackResult.ERROR;
try {
_log.info("Rolling back to SCN : " + rollbackScn);
callbackResult = getAsyncCallback().onRollback(rollbackScn);
} catch (RuntimeException e) {
_log.error("Internal onRollback error: " + e.getMessage(), e);
}
success = ConsumerCallbackResult.isSuccess(callbackResult);
if (success) {
if (debugEnabled)
_log.debug("Rollback consumer callback succeeded");
} else {
_log.error("Rollback consumer callback failed");
}
}
if (regressItr) {
if (null != curState.getLastSuccessfulIterator()) {
_log.info("Rolled back to last successful checkpoint position in the buffer: " + curState.getLastSuccessfulIterator());
_currentWindowSizeInBytes = 0;
curState.switchToReplayDataEvents();
} else {
_log.fatal("Unable to rollback, this usually means that the events belonging to the last checkpoint" + " are no longer to be found in the buffer. Please checkpoint more frequently to avoid this. Restarting the client " + "will fix this problem, last checkpoint found: \n" + lastCp);
curState.switchToClosed();
}
}
} else {
DispatcherRetriesExhaustedException exp = new DispatcherRetriesExhaustedException();
_log.info("Invoke onError callback as dispatcher retries have exhausted");
getAsyncCallback().onError(exp);
curState.switchToClosed();
}
}
Aggregations