Package com.caucho.db.block

Examples of com.caucho.db.block.Block


  public Block readBlock(BlockStore store, long blockAddress)
    throws IOException
  {
    long blockId = store.addressToBlockId(blockAddress);
     
    Block block = null;

    if (block != null)
      block.allocate();
    else
      block = store.readBlock(blockId);

    return block;
  }
View Full Code Here


  public Block loadBlock(BlockStore store, long blockAddress)
    throws IOException
  {
    long blockId = store.addressToBlockId(blockAddress);
     
    Block block = store.loadBlock(blockId);

    return block;
  }
View Full Code Here

    ArrayList<Block> updateBlocks = _updateBlocks;
    _updateBlocks = null;
   
    if (updateBlocks != null) {
      while (updateBlocks.size() > 0) {
        Block block = updateBlocks.remove(updateBlocks.size() - 1);

        try {
          block.getStore().saveAllocation();
        } catch (IOException e) {
          log.log(Level.WARNING, e.toString(), e);
        }
       
        try {
          block.commit();
        } catch (IOException e) {
          log.log(Level.WARNING, e.toString(), e);
        }
      }
    }

    if (_deallocateBlocks != null) {
      while (_deallocateBlocks.size() > 0) {
        Block block = _deallocateBlocks.remove(0);

        try {
          block.getStore().deallocateBlock(block.getBlockId());
        } catch (IOException e) {
          throw new SQLExceptionWrapper(e);
        }
      }
    }
View Full Code Here

   * Closes the buffer.
   */
  public void close()
  {
    if (_block != null) {
      Block block = _block;
      _block = null;
      block.free();
    }
  }
View Full Code Here

   */
  public void readBlock()
    throws IOException
  {
    if (_block != null) {
      Block block = _block;
      _block = null;
      block.free();
    }

    long addr;

    int blockCount = (int) (_offset / BlockStore.BLOCK_SIZE);
     
    if (blockCount < INODE_DIRECT_BLOCKS) {
      addr = readLong(_inode, _inodeOffset + 8 * (blockCount + 1));
    }
    else {
      long ptrAddr = readLong(_inode,
                              _inodeOffset + 8 * (INODE_DIRECT_BLOCKS + 1));

      Block ptr = _store.readBlock(_store.addressToBlockId(ptrAddr));

      addr = readLong(ptr.getBuffer(), 8 * (blockCount - INODE_DIRECT_BLOCKS));

      ptr.free();
    }

    _block = _store.readBlock(_store.addressToBlockId(addr));
    _buffer = _block.getBuffer();

View Full Code Here

        writeMiniFragAddr(inode, inodeOffset,
                          store, xa,
                          currentLength, miniFragAddr);

        Block writeBlock = store.writeMiniFragment(miniFragAddr, 0,
                                                   buffer, offset, sublen);
        xa.addUpdateBlock(writeBlock);

        offset += sublen;
        length -= sublen;
View Full Code Here

        int sublen = length;

        if (BLOCK_SIZE - blockOffset < sublen)
          sublen = BLOCK_SIZE - blockOffset;

        Block block = store.writeBlock(addr, blockOffset,
                                       buffer, offset, sublen);
        xa.addUpdateBlock(block);

        offset += sublen;
        length -= sublen;

        currentLength += sublen;
      }
      else {
        int sublen = length;

        if (BLOCK_SIZE < sublen)
          sublen = BLOCK_SIZE;

        Block block = store.allocateBlock();

        long blockAddr = BlockStore.blockIdToAddress(block.getBlockId());

        block.free();

        if (blockAddr == 0) {
          store.setCorrupted(true);

          throw new IllegalStateException(L.l("{0}: illegal block",
                                              store));
        }

        writeBlockAddr(inode, inodeOffset,
                       store, xa,
                       currentLength, blockAddr);

        Block writeBlock = store.writeBlock(blockAddr, 0,
                                            buffer, offset, sublen);
        xa.addUpdateBlock(writeBlock);

        offset += sublen;
        length -= sublen;
View Full Code Here

                          currentLength, miniFragAddr);

        int charSublen = sublen / 2;

        // XXX: store in XA?
        Block writeBlock = store.writeMiniFragment(miniFragAddr, 0,
                                                   buffer, offset, charSublen);
        xa.addUpdateBlock(writeBlock);

        offset += charSublen;
        charLength -= charSublen;
View Full Code Here

        if (BLOCK_SIZE - blockOffset < sublen)
          sublen = BLOCK_SIZE - blockOffset;

        int charSublen = sublen / 2;

        Block writeBlock = store.writeBlock(addr, blockOffset,
                                            buffer, offset, charSublen);
        xa.addUpdateBlock(writeBlock);

        offset += charSublen;
        charLength -= charSublen;

        currentLength += sublen;
      }
      else {
        int sublen = 2 * charLength;

        if (BLOCK_SIZE < sublen)
          sublen = BLOCK_SIZE;

        int charSublen = sublen / 2;

        Block block = store.allocateBlock();
        long blockAddr = block.getBlockId();
        block.free();

        Block writeBlock = store.writeBlock(blockAddr, 0,
                                            buffer, offset, charSublen);
       
        xa.addUpdateBlock(writeBlock);

        writeBlockAddr(inode, inodeOffset,
View Full Code Here

    }
    else if (fileOffset < SINGLE_INDIRECT_MAX) {
      long indAddr = readLong(inode, inodeOffset + (DIRECT_BLOCKS + 1) * 8);

      if (indAddr == 0) {
        Block block = store.allocateBlock();
        indAddr = block.getBlockId();
        block.free();

        writeLong(inode, inodeOffset + (DIRECT_BLOCKS + 1) * 8, indAddr);
      }

      int blockOffset = 8 * (blockCount - DIRECT_BLOCKS);

      Block writeBlock = store.writeBlockLong(indAddr, blockOffset, blockAddr);
      xa.addUpdateBlock(writeBlock);
    }
    else if (fileOffset < DOUBLE_INDIRECT_MAX) {
      long indAddr = readLong(inode, inodeOffset + (DIRECT_BLOCKS + 1) * 8);

      if (indAddr == 0) {
        store.setCorrupted(true);

        throw new IllegalStateException(L.l("{0} null block id", store));
      }
     
      blockCount = blockCount - DIRECT_BLOCKS - SINGLE_INDIRECT_BLOCKS;
       
      int dblBlockCount = blockCount / INDIRECT_BLOCKS;

      int dblBlockIndex = 8 * (SINGLE_INDIRECT_BLOCKS + dblBlockCount);

      long dblIndAddr = store.readBlockLong(indAddr, dblBlockIndex);

      if (dblIndAddr == 0) {
        Block block = store.allocateBlock();

        dblIndAddr = BlockStore.blockIdToAddress(block.getBlockId());

        block.free();

        Block writeBlock = store.writeBlockLong(indAddr, dblBlockIndex, dblIndAddr);
        xa.addUpdateBlock(writeBlock);
      }

      int blockOffset = 8 * (blockCount % INDIRECT_BLOCKS);

      Block writeBlock = store.writeBlockLong(dblIndAddr, blockOffset, blockAddr);
      xa.addUpdateBlock(writeBlock);
    }
    else {
      store.setCorrupted(true);

View Full Code Here

TOP

Related Classes of com.caucho.db.block.Block

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.