Example #1
0
  @SuppressWarnings("unchecked")
  private boolean packTransactionalInstance(final Field afield, OutputObjectState os) {
    Object ptr = null;

    try {
      ptr = afield.get(_theObject);

      if (ptr == null) {
        os.packBoolean(false);
      } else {
        os.packBoolean(true);
        UidHelper.packInto(_container.getUidForHandle((T) ptr), os);
      }
    } catch (final ClassCastException ex) {
      System.err.println("Field " + ptr + " is not a transactional instance!");

      return false;
    } catch (final Exception ex) {
      ex.printStackTrace();

      return false;
    }

    return true;
  }
Example #2
0
  /**
   * Normally returns the current state of the log entry. However, this is never called during
   * normal (non-recovery) execution. Therefore, the overhead of having to scan all of the logs (if
   * it's not one we're using) is minimal.
   */
  public int currentState(Uid objUid, String tName) throws ObjectStoreException {
    InputObjectState ios = new InputObjectState();

    /*
     * TODO
     *
     * It's possible that the entry has been marked to be deleted but
     * that the removal entry hasn't been written yet. We could check the
     * async cache. However, since we really only care about this during
     * recovery, it's not going to cause us  problems anyway.
     */

    if (allObjUids(tName, ios, StateStatus.OS_UNKNOWN)) {
      Uid tempUid = new Uid(Uid.nullUid());

      do {
        try {
          tempUid = UidHelper.unpackFrom(ios);
        } catch (final Exception ex) {
          ex.printStackTrace();

          return StateStatus.OS_UNKNOWN;
        }

        if (tempUid.equals(objUid)) return StateStatus.OS_COMMITTED;

      } while (tempUid.notEquals(Uid.nullUid()));

      return StateStatus.OS_UNKNOWN;
    } else return StateStatus.OS_UNKNOWN;
  }
Example #3
0
  public synchronized void unpackFrom(InputBuffer buff) throws IOException {
    imageType = buff.unpackString();

    bufferUid = UidHelper.unpackFrom(buff);

    super.unpackFrom(buff);
  }
Example #4
0
  public final InputObjectState allObjUids() throws ObjectStoreException {
    OutputObjectState state = new OutputObjectState();
    Iterator<Uid> iter = _ids.keySet().iterator();

    try {
      while (iter.hasNext()) {
        UidHelper.packInto(iter.next(), state);
      }

      // don't forget to null terminate

      UidHelper.packInto(Uid.nullUid(), state);
    } catch (final IOException ex) {
      throw new ObjectStoreException(ex);
    }

    return new InputObjectState(state);
  }
Example #5
0
  private boolean unpackTransactionalInstance(final Field afield, InputObjectState os) {
    try {
      boolean ptr = os.unpackBoolean();

      if (!ptr) afield.set(_theObject, null);
      else {
        Uid u = UidHelper.unpackFrom(os);

        afield.set(_theObject, _container.getHandle(u));
      }
    } catch (final Exception ex) {
      ex.printStackTrace();

      return false;
    }

    return true;
  }
Example #6
0
  private final void listLogs(String type) throws IOException {
    InputObjectState buff = new InputObjectState();

    try {
      if (StoreManager.getRecoveryStore()
          .allObjUids(TransactionTypeManager.getInstance().getTransactionType(type), buff)) {
        Uid u = null;

        do {
          u = UidHelper.unpackFrom(buff);

          if (Uid.nullUid().notEquals(u)) {
            System.out.println("Log: " + u);
          }
        } while (Uid.nullUid().notEquals(u));
      }
    } catch (final ObjectStoreException ex) {
      throw new IOException();
    }
  }
Example #7
0
  @Test
  public void test() {
    RecoveryStore recoveryStore = StoreManager.getRecoveryStore();
    OutputObjectState fluff = new OutputObjectState();
    Uid kungfuTx = new Uid();
    boolean passed = false;
    final String tn = new AtomicAction().type();

    try {
      UidHelper.packInto(kungfuTx, fluff);

      System.err.println("Creating dummy log");

      recoveryStore.write_committed(kungfuTx, tn, fluff);

      if (recoveryStore.currentState(kungfuTx, tn) == StateStatus.OS_COMMITTED) {
        System.err.println("Wrote dummy transaction " + kungfuTx);

        // quicker to deal with scanner directly

        ExpiredTransactionScanner scanner =
            new ExpiredTransactionScanner(tn, "/StateManager/ExpiredEntries");

        scanner.scan();

        scanner.scan();

        if (recoveryStore.currentState(kungfuTx, tn) == StateStatus.OS_COMMITTED)
          System.err.println("Transaction log not moved!");
        else {
          System.err.println("Transaction log moved!");

          passed = true;
        }
      } else System.err.println("State is not committed!");
    } catch (final Exception ex) {
      ex.printStackTrace();
    }

    assertTrue(passed);
  }
Example #8
0
  protected static OSRecordHolder readObjectStoreRecord(String type) {
    try {
      RecoveryStore recoveryStore = StoreManager.getRecoveryStore();
      InputObjectState states = new InputObjectState();

      if (recoveryStore.allObjUids(type, states) && states.notempty()) {

        Uid uid = UidHelper.unpackFrom(states);

        if (uid.notEquals(Uid.nullUid())) {
          InputObjectState ios = recoveryStore.read_committed(uid, type);

          return new OSRecordHolder(uid, type, ios);
        }
      }
    } catch (Exception e) {
      e.printStackTrace();
    }

    return null;
  }
Example #9
0
  private static void clearObjectStore(String type) {
    try {
      RecoveryStore recoveryStore = StoreManager.getRecoveryStore();
      InputObjectState states = new InputObjectState();

      if (recoveryStore.allObjUids(type, states) && states.notempty()) {
        boolean finished = false;

        do {
          Uid uid = UidHelper.unpackFrom(states);

          if (uid.notEquals(Uid.nullUid())) {
            recoveryStore.remove_committed(uid, type);
          } else {
            finished = true;
          }
        } while (!finished);
      }
    } catch (Exception e) {
      e.printStackTrace();
    }
  }
Example #10
0
  /**
   * This is a recovery-only method and should not be called during normal execution. As such we
   * need to load in all of the logs we can find that aren't already loaded (or activated).
   */
  public boolean allObjUids(String tName, InputObjectState state, int match)
      throws ObjectStoreException {
    /*
     * match will always be OS_COMMITTED since that's all we ever write for
     * the logs.
     */

    // in case of asynchronous removals trigger the purger now.

    _purger.trigger();

    /*
     * Get a list of logs. Load them in to memory if we aren't already
     * working on them/it. But we can prune the entry once we're
     * finished or the memory footprint will grow. We should do this
     * for all frozen entries eventually too.
     */

    InputObjectState logs = new InputObjectState();
    OutputObjectState objUids = new OutputObjectState();

    /*
     * We never call this method except during recovery. As such we shouldn't
     * need to worry about optimizations such as checking whether or not the
     * log is in current working memory.
     */

    if (!super.allObjUids(tName, logs, match)) return false;
    else {
      /*
       * Now we have all of the log names let's attach to each one
       * and locate the committed instances (not deleted.)
       */

      Uid logName = new Uid(Uid.nullUid());

      try {
        do {
          logName = UidHelper.unpackFrom(logs);

          if (logName.notEquals(Uid.nullUid())) {
            /*
             * Could check to see if log is in current working memory.
             */

            /*
             * TODO
             *
             * First purge the log if we can, but we need to know that
             * we're not playing with an instance that is being manipulated
             * from another VM instance.
             */

            ArrayList<InputObjectState> txs = scanLog(logName, tName);

            if (txs.size() > 0) {
              for (int i = 0; i < txs.size(); i++) {
                UidHelper.packInto(txs.get(i).stateUid(), objUids);
              }
            }
          }
        } while (logName.notEquals(Uid.nullUid()));

        // remember null terminator

        UidHelper.packInto(Uid.nullUid(), objUids);

        state.setBuffer(objUids.buffer());
      } catch (final IOException ex) {
        ex.printStackTrace();

        return false;
      }

      return true;
    }
  }