コード例 #1
0
ファイル: JournalWriter.java プロジェクト: ame89/nfsdb
  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();
    }
  }
コード例 #2
0
ファイル: JournalWriter.java プロジェクト: ame89/nfsdb
  private void switchAppendPartition(long timestamp) throws JournalException {
    boolean computeTimestampLo = appendPartition == null;

    appendPartition = getAppendPartition(timestamp);

    Interval interval = appendPartition.getInterval();
    if (interval == null) {
      appendTimestampHi = Long.MAX_VALUE;
    } else {
      appendTimestampHi = interval.getHi();
    }

    if (computeTimestampLo) {
      FixedColumn column = appendPartition.getTimestampColumn();
      long sz;
      if ((sz = column.size()) > 0) {
        appendTimestampLo = column.getLong(sz - 1);
      }
    } else {
      appendTimestampLo = appendPartition.getInterval().getLo();
    }
  }
コード例 #3
0
ファイル: JournalWriter.java プロジェクト: ame89/nfsdb
 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);
   }
 }