use of com.linkedin.databus.core.InvalidCheckpointException in project databus by linkedin.
the class BootstrapStartScnHttpResponseProcessor method finishResponse.
@Override
public void finishResponse() throws Exception {
super.finishResponse();
if (_errorHandled) {
return;
}
try {
String exceptionName = RemoteExceptionHandler.getExceptionName(_decorated);
Throwable remoteException = _remoteExceptionHandler.getException(_decorated);
if (null != remoteException && remoteException instanceof BootstrapDatabaseTooOldException) {
_remoteExceptionHandler.handleException(remoteException);
} else if (null != exceptionName) {
LOG.error("/targetScn response error: " + RemoteExceptionHandler.getExceptionMessage(_decorated));
_stateReuse.switchToTargetScnResponseError();
} else {
InputStream bodyStream = Channels.newInputStream(_decorated);
ObjectMapper mapper = new ObjectMapper();
String scnString = mapper.readValue(bodyStream, String.class);
LOG.info("targetScn:" + scnString);
long targetScn = Long.parseLong(scnString);
_stateReuse.switchToTargetScnSuccess();
// make sure we are in the expected mode -- sanity checks
Checkpoint ckpt = _checkpoint;
if (ckpt.getConsumptionMode() != DbusClientMode.BOOTSTRAP_SNAPSHOT) {
throw new InvalidCheckpointException("TargetScnResponseProcessor:" + " expecting in client mode: " + DbusClientMode.BOOTSTRAP_SNAPSHOT, ckpt);
} else if (!ckpt.isSnapShotSourceCompleted()) {
throw new InvalidCheckpointException("TargetScnResponseProcessor: current snapshot source not completed", ckpt);
}
LOG.info("Target SCN " + targetScn + " received for bootstrap catchup source " + ckpt.getCatchupSource() + " after completion of snapshot source " + ckpt.getSnapshotSource());
ckpt.setBootstrapTargetScn(targetScn);
}
} catch (Exception ex) {
LOG.error("/targetScn response error:" + ex.getMessage(), ex);
_stateReuse.switchToTargetScnResponseError();
}
_callback.enqueueMessage(_stateReuse);
}
use of com.linkedin.databus.core.InvalidCheckpointException in project databus by linkedin.
the class BootstrapPullThread method determineNextStateFromCheckpoint.
/**
* Determines the next state based on the checkpoint. The idea is to determine where we are in the bootstrap flow and
* move to the next state.
*
* <pre>
* 1. Request startSCN (State=REQUEST_START_SCN, SNAPSHOT, !cp.isBootstrapStartScnSet())
* 2. For each snapshot source:
* 2.1. Start snapshot (State=REQUEST_STREAM, SNAPSHOT, cp.isBootstrapStartScnSet() &&
* 0 == cp.getSnapshotOffset())
* 2.2. While (! cp.isSnapShotSourceCompleted())
* 2.2.1. Continue snapshot (State=REQUEST_STREAM, SNAPSHOT, cp.isBootstrapStartScnSet() &&
* 0 < cp.getSnapshotOffset())
* 2.3. Request targetSCN (State=REQUEST_TARGET_SCN, SNAPSHOT, cp.isBootstrapStartScnSet() &&
* cp.isSnapShotSourceCompleted() && 0 == cp.getWindowOffset())
* 2.4. For each catchup source <= the snapshot source:
* 2.4.1. Start catchup (State=REQUEST_STREAM, CATCHUP, 0==cp.getWindowOffset() && handler.needsMoreCatchup())
* 2.4.2. While (! cp.isCatchupSourceCompleted())
* 2.4.2.1. Continue catchup (State=REQUEST_STREAM, CATCHUP, ! cp.isCatchupSourceCompleted())
* </pre>
* @param curState the bootstrap checkpoint
*/
private void determineNextStateFromCheckpoint(ConnectionState curState) {
try {
final Checkpoint cp = curState.getCheckpoint();
final BootstrapCheckpointHandler cpHandler = curState.getBstCheckpointHandler();
cpHandler.assertBootstrapCheckpoint(cp);
switch(cp.getConsumptionMode()) {
case BOOTSTRAP_SNAPSHOT:
determineNextStateFromSnapshotCheckpoint(cp, cpHandler, curState);
break;
case BOOTSTRAP_CATCHUP:
determineNextStateFromCatchupCheckpoint(cp, cpHandler, curState);
break;
default:
_log.fatal("unexpected bootstrap checkpoint type: " + cp + "; shutting down");
curState.switchToClosed();
}
} catch (InvalidCheckpointException e) {
_log.fatal("invalid bootstrap checkpoint:", e);
curState.switchToClosed();
}
}
Aggregations