Esempio n. 1
0
 /**
  * Opens existing lag partition if it exists or creates new one if parent journal is configured to
  * have lag partitions.
  *
  * @return Lag partition instance.
  * @throws com.nfsdb.exceptions.JournalException
  */
 public Partition<T> openOrCreateLagPartition() throws JournalException {
   Partition<T> result = getIrregularPartition();
   if (result == null) {
     result = createTempPartition();
     setIrregularPartition(result);
   }
   return result.open();
 }
Esempio n. 2
0
  private void commit(byte command, long txn, long txPin) throws JournalException {
    boolean force = command == Tx.TX_FORCE;
    Partition<T> partition = lastNonEmptyNonLag();
    Partition<T> lag = getIrregularPartition();

    tx.command = command;
    tx.txn = txn;
    tx.txPin = txPin;
    tx.prevTxAddress = txLog.getCurrentTxAddress();
    tx.journalMaxRowID =
        partition == null ? -1 : Rows.toRowID(partition.getPartitionIndex(), partition.size());
    tx.lastPartitionTimestamp =
        partition == null || partition.getInterval() == null ? 0 : partition.getInterval().getLo();
    tx.lagSize = lag == null ? 0 : lag.open().size();
    tx.lagName = lag == null ? null : lag.getName();
    tx.symbolTableSizes = new int[getSymbolTableCount()];
    tx.symbolTableIndexPointers = new long[tx.symbolTableSizes.length];
    for (int i = 0; i < tx.symbolTableSizes.length; i++) {
      SymbolTable tab = getSymbolTable(i);
      tab.commit();
      if (force) {
        tab.force();
      }
      tx.symbolTableSizes[i] = tab.size();
      tx.symbolTableIndexPointers[i] = tab.getIndexTxAddress();
    }
    tx.indexPointers = new long[getMetadata().getColumnCount()];

    for (int i = Math.max(txPartitionIndex, 0), sz = nonLagPartitionCount(); i < sz; i++) {
      Partition<T> p = getPartition(i, true);
      p.commit();
      if (force) {
        p.force();
      }
    }

    if (partition != null) {
      partition.getIndexPointers(tx.indexPointers);
    }

    tx.lagIndexPointers = new long[tx.indexPointers.length];
    if (lag != null) {
      lag.commit();
      if (force) {
        lag.force();
      }
      lag.getIndexPointers(tx.lagIndexPointers);
    }

    txLog.write(tx, txn != -1);
    if (force) {
      txLog.force();
    }
  }
Esempio n. 3
0
 public Partition<T> getAppendPartition(long timestamp) throws JournalException {
   int sz = partitions.size();
   if (sz > 0) {
     Partition<T> par = partitions.getQuick(sz - 1);
     Interval interval = par.getInterval();
     if (interval == null || interval.contains(timestamp)) {
       return par.open().access();
     } else if (interval.isBefore(timestamp)) {
       return createPartition(new Interval(timestamp, getMetadata().getPartitionType()), sz);
     } else {
       throw new JournalException("%s cannot be appended to %s", Dates.toString(timestamp), this);
     }
   } else {
     return createPartition(new Interval(timestamp, getMetadata().getPartitionType()), 0);
   }
 }
Esempio n. 4
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;
      }
    }
  }