Package com.caucho.db.block

Examples of com.caucho.db.block.Block


                          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

    db.init();

    BlockStore store = new BlockStore(db, "test", null);
    store.create();

    Block block = store.allocateIndexBlock();
    long blockId = block.getBlockId();
    block.free();

    return new BTree(store, blockId, keySize, new KeyCompare());
  }
View Full Code Here

    public void write(byte []buffer, int offset, int length)
      throws IOException
    {
      while (length > 0) {
        while (_blockList.size() <= _length / BlockStore.BLOCK_SIZE) {
          Block block = _store.allocateBlock();

          _blockList.add(block.getBlockId());
         
          block.free();
        }

        int blockOffset = (int) (_length % BlockStore.BLOCK_SIZE);
        long blockAddress = _blockList.get(_blockList.size() - 1);

        int sublen = BlockStore.BLOCK_SIZE - blockOffset;
        if (length < sublen)
          sublen = length;

        _length += sublen;
       
        Block block = _store.writeBlock(blockAddress, blockOffset,
                                        buffer, offset, sublen);
       
        _xa.addUpdateBlock(block);

        length -= sublen;
View Full Code Here

    public void write(char []buffer, int offset, int length)
      throws IOException
    {
      while (length > 0) {
        while (_blockList.size() <= _length / BlockStore.BLOCK_SIZE) {
          Block block = _store.allocateBlock();

          _blockList.add(block.getBlockId());
         
          block.free();
        }

        int blockOffset = (int) (_length % BlockStore.BLOCK_SIZE);
        long blockId = _blockList.get(_blockList.size() - 1);

        int sublen = (BlockStore.BLOCK_SIZE - blockOffset) / 2;
        if (length < sublen)
          sublen = length;

        _length += 2 * sublen;
        Block block = _store.writeBlock(blockId, blockOffset,
                                        buffer, offset, sublen);

        _xa.addUpdateBlock(block);
       
        length -= sublen;
View Full Code Here

      throw new IllegalStateException();

    int len = _tableIterators.length;

    for (int i = 0; i < len; i++) {
      Block bestBlock = null;
      long bestId = Long.MAX_VALUE;

      loop:
      for (int j = 0; j < len; j++) {
        TableIterator iter = _tableIterators[j];

        if (iter == null)
          continue;

        Block block = iter.getBlock();

        if (block == null)
          continue;

        long id = block.getBlockId();
        if (bestId <= id)
          continue;

        for (int k = 0; k < i; k++) {
          if (_blockLocks[k] == block)
View Full Code Here

    int len = _blockLocks.length;

    // need to unlock first since the writeData/commit will wait for
    // write locks to clear before committing
    for (int i = len - 1; i >= 0; i--) {
      Block block = _blockLocks[i];

      if (block == null) {
      }
      else if (_isWrite) {
        block.getLock().unlockReadAndWrite();
      }
      else {
        block.getLock().unlockRead();
      }
    }

    try {
      _xa.writeData();
    } finally {
      for (int i = len - 1; i >= 0; i--) {
        Block block = _blockLocks[i];
        _blockLocks[i] = null;

        if (block == null) {
        }
        else if (_isWrite) {
          try {
            block.commit();
          } catch (Exception e) {
            log.log(Level.FINE, e.toString(), e);
          }
        }
      }
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.