protected ApplicationState loadDurableState() { FileRecoverer fr = new FileRecoverer(id, DEFAULT_DIR); lastCkpPath = fr.getLatestFile(".ckp"); logPath = fr.getLatestFile(".log"); byte[] checkpoint = null; if (lastCkpPath != null) checkpoint = fr.getCkpState(lastCkpPath); CommandsInfo[] log = null; if (logPath != null) log = fr.getLogState(0, logPath); int ckpLastConsensusId = fr.getCkpLastConsensusId(); int logLastConsensusId = fr.getLogLastConsensusId(); System.out.println("log last consensus di: " + logLastConsensusId); ApplicationState state = new DefaultApplicationState( log, ckpLastConsensusId, logLastConsensusId, checkpoint, fr.getCkpStateHash()); if (logLastConsensusId > ckpLastConsensusId) { super.setLastEid(logLastConsensusId); } else super.setLastEid(ckpLastConsensusId); super.setLastCheckpointEid(ckpLastConsensusId); return state; }
/** * Constructs a TransferableState using this log information * * @param eid Execution ID correspondent to desired state * @return TransferableState Object containing this log information */ public DefaultApplicationState getApplicationState(int eid, boolean sendState) { // readingState = true; CommandsInfo[] batches = null; int lastCheckpointEid = getLastCheckpointEid(); int lastEid = getLastEid(); System.out.println("LAST CKP EID = " + lastCheckpointEid); System.out.println("EID = " + eid); System.out.println("LAST EID = " + lastEid); if (eid >= lastCheckpointEid && eid <= lastEid) { int size = eid - lastCheckpointEid; FileRecoverer fr = new FileRecoverer(id, DEFAULT_DIR); // if (size > 0 && sendState) { if (size > 0) { CommandsInfo[] recoveredBatches = fr.getLogState(size, logPath); batches = new CommandsInfo[size]; for (int i = 0; i < size; i++) batches[i] = recoveredBatches[i]; } checkpointLock.lock(); byte[] ckpState = fr.getCkpState(lastCkpPath); byte[] ckpStateHash = fr.getCkpStateHash(); checkpointLock.unlock(); System.out.println("--- FINISHED READING STATE"); // readingState = false; // return new DefaultApplicationState((sendState ? batches : null), lastCheckpointEid, return new DefaultApplicationState( batches, lastCheckpointEid, eid, (sendState ? ckpState : null), ckpStateHash); } return null; }