/** * 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; }
/** * 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; }