@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;
  }
Beispiel #2
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);
  }
Beispiel #3
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);
  }
Beispiel #4
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;
    }
  }