Ejemplo n.º 1
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;
  }