Ejemplo n.º 1
0
  @Override
  public void setReplicaContext(ReplicaContext replicaContext) {
    this.config = replicaContext.getStaticConfiguration();
    if (log == null) {
      globalCheckpointPeriod = config.getGlobalCheckpointPeriod();
      replicaCkpIndex = getCheckpointPortionIndex();
      checkpointPortion = globalCheckpointPeriod / config.getN();

      //			byte[] state = getSnapshot();
      if (config.isToLog()) {
        int replicaId = config.getProcessId();
        boolean isToLog = config.isToLog();
        boolean syncLog = config.isToWriteSyncLog();
        boolean syncCkp = config.isToWriteSyncCkp();
        //				log = new DurableStateLog(replicaId, state, computeHash(state), isToLog, syncLog,
        // syncCkp);
        log = new DurableStateLog(replicaId, null, null, isToLog, syncLog, syncCkp);
        CSTState storedState = log.loadDurableState();
        if (storedState.getLastCID() > -1) {
          System.out.println("LAST CID RECOVERED FROM LOG: " + storedState.getLastCID());
          setState(storedState);
          getStateManager().setLastCID(storedState.getLastCID());
        } else {
          System.out.println("REPLICA IS IN INITIAL STATE");
        }
      }
      getStateManager().askCurrentConsensusId();
    }
  }
Ejemplo n.º 2
0
  @Override
  public int setState(ApplicationState recvState) {
    int lastCID = -1;
    if (recvState instanceof CSTState) {
      CSTState state = (CSTState) recvState;

      int lastCheckpointCID = state.getCheckpointCID();
      lastCID = state.getLastCID();

      bftsmart.tom.util.Logger.println(
          "(DurabilityCoordinator.setState) I'm going to update myself from CID "
              + lastCheckpointCID
              + " to CID "
              + lastCID);

      stateLock.lock();
      if (state.getSerializedState() != null) {
        System.out.println("The state is not null. Will install it");
        log.update(state);
        installSnapshot(state.getSerializedState());
      }

      System.out.print("--- Installing log from " + (lastCheckpointCID + 1) + " to " + lastCID);

      for (int cid = lastCheckpointCID + 1; cid <= lastCID; cid++) {
        try {
          bftsmart.tom.util.Logger.println(
              "(DurabilityCoordinator.setState) interpreting and verifying batched requests for CID "
                  + cid);
          CommandsInfo cmdInfo = state.getMessageBatch(cid);
          byte[][] commands = cmdInfo.commands;
          MessageContext[] msgCtx = cmdInfo.msgCtx;

          if (commands == null || msgCtx == null || msgCtx[0].isNoOp()) {
            continue;
          }

          appExecuteBatch(commands, msgCtx);
        } catch (Exception e) {
          e.printStackTrace(System.err);
        }
      }
      System.out.println("--- Installed");
      stateLock.unlock();
    }

    return lastCID;
  }