Exemple #1
0
  @Override
  public void begin(Transaction txn) {
    // debug("%s begin", txn.getLabel()) ;

    if (this.txn.getTxnId() != txn.getTxnId())
      throw new TDBException(
          String.format("Different transactions: %s %s", this.txn.getLabel(), txn.getLabel()));
    if (passthrough) throw new TDBException("Already active");
    passthrough = false;

    allocOffset = base.allocOffset().getId();
    // base node table empty e.g. first use.
    journalObjFileStartOffset = journalObjFile.length();
    // Because the data is written in prepare, the journal of object data is
    // always empty at the start of a transaction.
    if (journalObjFileStartOffset != 0)
      warn(
          log,
          "%s journalStartOffset not zero: %d/0x%02X",
          txn.getLabel(),
          journalObjFileStartOffset,
          journalObjFileStartOffset);
    allocOffset += journalObjFileStartOffset;

    this.nodeTableJournal = new NodeTableNative(nodeIndex, journalObjFile);
    this.nodeTableJournal = NodeTableCache.create(nodeTableJournal, CacheSize, CacheSize, 100);
    // This class knows about non-mappable inline values.   mapToJournal(NodeId)/mapFromJournal.
    this.nodeTableJournal = NodeTableInline.create(nodeTableJournal);
  }
Exemple #2
0
  @Override
  public void commitPrepare(Transaction txn) {
    debug("commitPrepare");

    // The node table is append-only so it can be written during prepare.
    // The index isn't written (via the transaction journal) until enact.
    if (nodeTableJournal == null)
      throw new TDBTransactionException(
          txn.getLabel() + ": Not in a transaction for a commit to happen");
    writeNodeJournal();

    if (journalObjFile != null && journalObjFile.length() != 0) {
      long x = journalObjFile.length();
      throw new TDBTransactionException(
          txn.getLabel() + ": journalObjFile not cleared (" + x + ")");
    }
  }
Exemple #3
0
  private void writeNodeJournal() {
    long expected = base.allocOffset().getId();
    long len = journalObjFile.length();
    if (expected != allocOffset)
      warn(log, "Inconsistency: base.allocOffset() = %d : allocOffset = %d", expected, allocOffset);

    long newbase = -1;
    append(); // Calls all() which does a buffer flish.
    // Reset (in case we use this again)
    nodeIndex.clear();
    journalObjFile.truncate(journalObjFileStartOffset); // Side effect is a buffer flush.
    // journalObjFile.sync() ;
    journalObjFile.close(); // Side effect is a buffer flush.
    journalObjFile = null;
    base.sync();
    allocOffset =
        -99; // base.allocOffset().getId() ; // Will be invalid as we may write through to the base
             // table later.
    passthrough = true;
  }