示例#1
0
  @Override
  public void prepareToCommit(TerminateTransactionRequestMessage msg) {
    ExecutionHistory executionHistory = msg.getExecutionHistory();

    PartitionDependenceVector<String> commitVC =
        receivedVectors.get(executionHistory.getTransactionHandler().getId());

    /*
     * Assigning commitVC to the entities
     */
    for (JessyEntity entity : executionHistory.getWriteSet().getEntities()) {
      entity.setLocalVector(commitVC.clone());
      entity.temporaryObject = null;
      entity.getLocalVector().setSelfKey(manager.getMyGroup().name());
    }
  }
示例#2
0
  @Override
  public boolean transactionDeliveredForTermination(
      ConcurrentLinkedHashMap<UUID, Object> terminatedTransactions,
      ConcurrentHashMap<TransactionHandler, VotingQuorum> quorumes,
      TerminateTransactionRequestMessage msg) {
    try {
      if (msg.getExecutionHistory().getTransactionType() != TransactionType.INIT_TRANSACTION) {
        int seqNo = PartitionDependenceVector.lastCommitSeqNo.incrementAndGet();
        PartitionDependenceVector<String> vector = new PartitionDependenceVector<String>();
        for (JessyEntity entity : msg.getExecutionHistory().getReadSet().getEntities()) {
          vector.update(entity.getLocalVector());
        }
        vector.update(PartitionDependenceVector.lastCommit);
        vector.setSelfKey(manager.getMyGroup().name());
        vector.setValue(vector.getSelfKey(), seqNo);
        msg.setComputedObjectUponDelivery(vector);
      }
    } catch (Exception ex) {
      ex.printStackTrace();
    }

    return true;
  }
示例#3
0
  @SuppressWarnings("unchecked")
  public boolean certify(ExecutionHistory executionHistory) {
    TransactionType transactionType = executionHistory.getTransactionType();

    if (ConstantPool.logging) {
      logger.debug(executionHistory.getTransactionHandler() + " >> " + transactionType.toString());
      logger.debug("ReadSet Vector" + executionHistory.getReadSet().getCompactVector().toString());
      logger.debug(
          "CreateSet Vectors" + executionHistory.getCreateSet().getCompactVector().toString());
      logger.debug(
          "WriteSet Vectors" + executionHistory.getWriteSet().getCompactVector().toString());
    }

    /*
     * if the transaction is an initialization transaction, it first
     * increments the vectors and then commits.
     */
    if (transactionType == TransactionType.INIT_TRANSACTION) {

      for (JessyEntity tmp : executionHistory.getCreateSet().getEntities()) {

        PartitionDependenceVector<String> commitVC =
            new PartitionDependenceVector<String>(manager.getMyGroup().name(), 0);
        tmp.setLocalVector(commitVC);
      }

      return true;
    }

    /*
     * If the transaction is not read-only or init, we consider the create
     * operations as update operations. Thus, we move them to the writeSet
     * List.
     */
    if (executionHistory.getCreateSet() != null && executionHistory.getCreateSet().size() > 0)
      executionHistory.getWriteSet().addEntity(executionHistory.getCreateSet());

    JessyEntity lastComittedEntity;

    for (JessyEntity tmp : executionHistory.getReadSet().getEntities()) {

      if (!manager.getPartitioner().isLocal(tmp.getKey())) continue;

      try {

        lastComittedEntity =
            store
                .get(
                    new ReadRequest<JessyEntity>(
                        (Class<JessyEntity>) tmp.getClass(), "secondaryKey", tmp.getKey(), null))
                .getEntity()
                .iterator()
                .next();

        /*
         * instead of locking, we simply checks against the latest
         * committed values
         */
        if (lastComittedEntity.getLocalVector().getSelfValue()
            > tmp.getLocalVector().getSelfValue()) {
          if (ConstantPool.logging)
            logger.error(
                "Certification fails (writeSet) : Reads key "
                    + tmp.getKey()
                    + " with the vector "
                    + tmp.getLocalVector()
                    + " while the last committed vector is "
                    + lastComittedEntity.getLocalVector());
          return false;
        }

      } catch (NullPointerException e) {
        // nothing to do.
        // the key is simply not there.
      }
    }

    return true;
  }