Beispiel #1
0
  private void rollback0(long address, boolean writeDiscard) throws JournalException {

    if (address == -1L) {
      notifyTxError();
      throw new IncompatibleJournalException(
          "Server txn is not compatible with %s", this.getLocation());
    }

    txLog.read(address, tx);

    if (tx.address == 0) {
      throw new JournalException("Invalid transaction address");
    }

    if (writeDiscard) {
      LOGGER.info(
          "Journal %s is rolling back to transaction #%d, timestamp %s",
          metadata.getLocation(), tx.txn, Dates.toString(tx.timestamp));
      writeDiscardFile(tx.journalMaxRowID);
    }

    // partitions need to be dealt with first to make sure new lag is assigned a correct
    // partitionIndex
    rollbackPartitions(tx);

    Partition<T> lag = getIrregularPartition();
    if (tx.lagName != null
        && tx.lagName.length() > 0
        && (lag == null || !tx.lagName.equals(lag.getName()))) {
      Partition<T> newLag = createTempPartition(tx.lagName);
      setIrregularPartition(newLag);
      newLag.applyTx(tx.lagSize, tx.lagIndexPointers);
    } else if (lag != null && tx.lagName == null) {
      removeIrregularPartitionInternal();
    } else if (lag != null) {
      lag.truncate(tx.lagSize);
    }

    if (tx.symbolTableSizes.length == 0) {
      for (int i = 0, sz = getSymbolTableCount(); i < sz; i++) {
        getSymbolTable(i).truncate();
      }
    } else {
      for (int i = 0, sz = getSymbolTableCount(); i < sz; i++) {
        getSymbolTable(i).truncate(tx.symbolTableSizes[i]);
      }
    }
    appendTimestampLo = -1;
    appendTimestampHi = -1;
    appendPartition = null;
    txLog.writeTxAddress(tx.address);
    txActive = false;
  }
Beispiel #2
0
  public void truncate() throws JournalException {
    beginTx();
    int partitionCount = getPartitionCount();
    for (int i = 0; i < partitionCount; i++) {
      Partition<T> partition = getPartition(i, true);
      partition.truncate(0);
      partition.close();
      Files.deleteOrException(partition.getPartitionDir());
    }

    closePartitions();

    for (int i = 0, sz = getSymbolTableCount(); i < sz; i++) {
      getSymbolTable(i).truncate();
    }
    appendTimestampLo = -1;
    commitDurable();
  }
Beispiel #3
0
  private void rollbackPartitions(Tx tx) throws JournalException {
    int partitionIndex = tx.journalMaxRowID == -1 ? 0 : Rows.toPartitionIndex(tx.journalMaxRowID);
    while (true) {
      Partition<T> p = partitions.getLast();
      if (p == null) {
        break;
      }

      if (p.getPartitionIndex() > partitionIndex) {
        p.close();
        Files.deleteOrException(p.getPartitionDir());
        partitions.remove(partitions.size() - 1);
      } else if (p.getPartitionIndex() == partitionIndex) {
        p.open();
        p.truncate(tx.journalMaxRowID == -1 ? 0 : Rows.toLocalRowID(tx.journalMaxRowID));
        break;
      } else {
        break;
      }
    }
  }