/** * Get the next state based on this checkpoint state. * * @param recovering if in recovering phase * @return the next checkpoint state based on this state. */ public CheckPointState nextState(boolean recovering) { CheckPointState nextState; switch (state) { case PREPARING: nextState = recovering ? new CheckPointState(txid - 1, State.COMMITTED) : new CheckPointState(txid, State.COMMITTING); break; case COMMITTING: nextState = new CheckPointState(txid, State.COMMITTED); break; case COMMITTED: nextState = recovering ? this : new CheckPointState(txid + 1, State.PREPARING); break; default: throw new IllegalStateException("Unknown state " + state); } return nextState; }
private void doCheckpoint() { LOG.debug("In checkpoint"); if (curTxState.getState() == CheckPointState.State.COMMITTED) { saveTxState(curTxState.nextState(false)); lastCheckpointTs = System.currentTimeMillis(); } Action action = curTxState.nextAction(false); emit(curTxState.getTxid(), action); }
private void handleRecovery() { LOG.debug("In recovery"); Action action = curTxState.nextAction(true); emit(curTxState.getTxid(), action); }
private void handleRecoveryAck() { CheckPointState nextState = curTxState.nextState(true); if (curTxState != nextState) { saveTxState(nextState); } else { LOG.debug("Recovery complete, current state {}", curTxState); recovering = false; } }
private boolean shouldCheckpoint() { return !recovering && !checkpointStepInProgress && (curTxState.getState() != CheckPointState.State.COMMITTED || checkpointIntervalElapsed()); }
@Override public void ack(Object msgId) { LOG.debug("Got ack with txid {}, current txState {}", msgId, curTxState); if (curTxState.getTxid() == ((Number) msgId).longValue()) { if (recovering) { handleRecoveryAck(); } else { handleCheckpointAck(); } } else { LOG.warn("Ack msgid {}, txState.txid {} mismatch", msgId, curTxState.getTxid()); } resetProgress(); }
private void handleRecovery() { LOG.debug("In recovery"); Action action = curTxState.nextAction(true); emit(curTxState.getTxid(), action); }
private void handleCheckpointAck() { CheckPointState nextState = curTxState.nextState(false); saveTxState(nextState); }
private boolean shouldCheckpoint() { return !recovering && !checkpointStepInProgress && (curTxState.getState() != CheckPointState.State.COMMITTED || checkpointIntervalElapsed()); }
@Override public void ack(Object msgId) { LOG.debug("Got ack with txid {}, current txState {}", msgId, curTxState); if (curTxState.getTxid() == ((Number) msgId).longValue()) { if (recovering) { handleRecoveryAck(); } else { handleCheckpointAck(); } } else { LOG.warn("Ack msgid {}, txState.txid {} mismatch", msgId, curTxState.getTxid()); } resetProgress(); }
private void doCheckpoint() { LOG.debug("In checkpoint"); if (curTxState.getState() == CheckPointState.State.COMMITTED) { saveTxState(curTxState.nextState(false)); lastCheckpointTs = System.currentTimeMillis(); } Action action = curTxState.nextAction(false); emit(curTxState.getTxid(), action); }
private void handleRecoveryAck() { CheckPointState nextState = curTxState.nextState(true); if (curTxState != nextState) { saveTxState(nextState); } else { LOG.debug("Recovery complete, current state {}", curTxState); recovering = false; } }
/** * Loads the last saved checkpoint state the from persistent storage. */ private KeyValueState<String, CheckPointState> loadCheckpointState(Map conf, TopologyContext ctx) { String namespace = ctx.getThisComponentId() + "-" + ctx.getThisTaskId(); KeyValueState<String, CheckPointState> state = (KeyValueState<String, CheckPointState>) StateFactory.getState(namespace, conf, ctx); if (state.get(TX_STATE_KEY) == null) { CheckPointState txState = new CheckPointState(-1, CheckPointState.State.COMMITTED); state.put(TX_STATE_KEY, txState); state.commit(); LOG.debug("Initialized checkpoint spout state with txState {}", txState); } else { LOG.debug("Got checkpoint spout state {}", state.get(TX_STATE_KEY)); } return state; }
private void handleCheckpointAck() { CheckPointState nextState = curTxState.nextState(false); saveTxState(nextState); }
/** * Get the next state based on this checkpoint state. * * @param recovering if in recovering phase * @return the next checkpoint state based on this state. */ public CheckPointState nextState(boolean recovering) { CheckPointState nextState; switch (state) { case PREPARING: nextState = recovering ? new CheckPointState(txid - 1, State.COMMITTED) : new CheckPointState(txid, State.COMMITTING); break; case COMMITTING: nextState = new CheckPointState(txid, State.COMMITTED); break; case COMMITTED: nextState = recovering ? this : new CheckPointState(txid + 1, State.PREPARING); break; default: throw new IllegalStateException("Unknown state " + state); } return nextState; }
/** * Loads the last saved checkpoint state the from persistent storage. */ private KeyValueState<String, CheckPointState> loadCheckpointState(Map conf, TopologyContext ctx) { String namespace = ctx.getThisComponentId() + "-" + ctx.getThisTaskId(); KeyValueState<String, CheckPointState> state = (KeyValueState<String, CheckPointState>) StateFactory.getState(namespace, conf, ctx); if (state.get(TX_STATE_KEY) == null) { CheckPointState txState = new CheckPointState(-1, CheckPointState.State.COMMITTED); state.put(TX_STATE_KEY, txState); state.commit(); LOG.debug("Initialized checkpoint spout state with txState {}", txState); } else { LOG.debug("Got checkpoint spout state {}", state.get(TX_STATE_KEY)); } return state; }