Exemplo n.º 1
0
  /** Synchs in-core transactions to data file and opens a fresh log */
  private void synchronizeLogFromMemory() throws IOException {
    close();

    TreeSet<BlockIo> blockList = new TreeSet<BlockIo>(new BlockIoComparator());

    int numBlocks = 0;
    int writtenBlocks = 0;
    for (int i = 0; i < _maxTxns; i++) {
      if (txns[i] == null) continue;
      // Add each block to the blockList, replacing the old copy of this
      // block if necessary, thus avoiding writing the same block twice
      for (Iterator<BlockIo> k = txns[i].iterator(); k.hasNext(); ) {
        BlockIo block = k.next();
        if (blockList.contains(block)) {
          block.decrementTransactionCount();
        } else {
          writtenBlocks++;
          boolean result = blockList.add(block);
        }
        numBlocks++;
      }

      txns[i] = null;
    }
    // Write the blocks from the blockList to disk
    synchronizeBlocks(blockList, true);

    owner.sync();
    open();
  }
Exemplo n.º 2
0
  /** Discards the indicated blocks and notify the owner. */
  private void discardBlocks(ArrayList<BlockIo> blocks) throws IOException {
    for (BlockIo cur : blocks) {

      cur.decrementTransactionCount();
      if (!cur.isInTransaction()) {
        owner.releaseFromTransaction(cur, false);
      }
    }
  }
Exemplo n.º 3
0
    public int compare(BlockIo block1, BlockIo block2) {

      if (block1.getBlockId() == block2.getBlockId()) {
        return 0;
      } else if (block1.getBlockId() < block2.getBlockId()) {
        return -1;
      } else {
        return 1;
      }
    }
Exemplo n.º 4
0
 /** Sets the current size */
 static void setCurrentSize(final BlockIo block, final short pos, int value) {
   if (value == 0) {
     block.writeByte(pos + O_CURRENTSIZE, (byte) (MAX_SIZE_SPACE + 1));
     return;
   }
   int availSize = getAvailableSize(block, pos);
   if (value < (availSize - MAX_SIZE_SPACE) || value > availSize)
     throw new IllegalArgumentException(
         "currentSize out of bounds, need to realocate " + value + " - " + availSize);
   block.writeByte(pos + O_CURRENTSIZE, (byte) (availSize - value));
 }
Exemplo n.º 5
0
 /** Synchronizes the indicated blocks with the owner. */
 private void synchronizeBlocks(Iterable<BlockIo> blocks, boolean fromCore) throws IOException {
   // write block vector elements to the data file.
   for (BlockIo cur : blocks) {
     owner.synch(cur);
     if (fromCore) {
       cur.decrementTransactionCount();
       if (!cur.isInTransaction()) {
         owner.releaseFromTransaction(cur, true);
       }
     }
   }
 }
Exemplo n.º 6
0
  /** Sets the available size */
  static void setAvailableSize(final BlockIo block, final short pos, int value) {
    if (value != roundAvailableSize(value))
      throw new IllegalArgumentException("value is not rounded");
    int oldCurrSize = getCurrentSize(block, pos);

    block.writeShort(pos + O_AVAILABLESIZE, convertAvailSize(value));
    setCurrentSize(block, pos, oldCurrSize);
  }
Exemplo n.º 7
0
 /** Indicates the block is part of the transaction. */
 void add(BlockIo block) throws IOException {
   block.incrementTransactionCount();
   txns[curTxn].add(block);
 }
Exemplo n.º 8
0
 /** Set clean flag on the blocks. */
 private void setClean(ArrayList<BlockIo> blocks) throws IOException {
   for (BlockIo cur : blocks) {
     cur.setClean();
   }
 }
Exemplo n.º 9
0
 /** Returns the available size */
 static int getAvailableSize(final BlockIo block, final short pos) {
   return deconvertAvailSize(block.readShort(pos + O_AVAILABLESIZE));
 }
Exemplo n.º 10
0
 /** Returns the current size */
 static int getCurrentSize(final BlockIo block, final short pos) {
   int s = block.readByte(pos + O_CURRENTSIZE) & 0xFF;
   if (s == MAX_SIZE_SPACE + 1) return 0;
   return getAvailableSize(block, pos) - s;
 }
Exemplo n.º 11
0
 /** Factory method to create or return a data page for the indicated block. */
 static FreePhysicalRowIdPage getFreePhysicalRowIdPageView(BlockIo block, int pageSize) {
   BlockView view = block.getView();
   if (view != null && view instanceof FreePhysicalRowIdPage) return (FreePhysicalRowIdPage) view;
   else return new FreePhysicalRowIdPage(block, pageSize);
 }