Package org.xtreemfs.babudb.index

Examples of org.xtreemfs.babudb.index.ByteRange


                   
                    Object nextBuffer = it.next();
                   
                    // check if the entry is the last from the buffer; if so, free it
                    if(nextBuffer instanceof ByteRange) {
                        ByteRange rng = (ByteRange) nextBuffer;
                        if(rng.getReusableBuf() != null)
                            BufferPool.free(rng.getReusableBuf());
                    }
                   
                    writtenBytes += writeBuffer(out, nextBuffer);
                }
                assert (writtenBytes == serializedBlock.size());
View Full Code Here


            return bytes.length;
        }

        else {
           
            ByteRange range = (ByteRange) buf;
           
            // crate a slice from the range's buffer that only contains the data
            // in the range
            range.getBuf().position(range.getStartOffset());
            ByteBuffer slice = range.getBuf().slice();
            slice.limit(range.getSize());
            return out.getChannel().write(slice);
        }
       
    }
View Full Code Here

    }
   
    public ByteRange getEntry(int n) {
        assert (offset < buf.limit()) : "offset == " + offset + ", buf.limit == " + buf.limit()
            + ", entrySize == " + entrySize + ", n == " + n;
        return new ByteRange(buf, offset + n * entrySize, offset + (n + 1) * entrySize - 1);
    }
View Full Code Here

        int offsetEnd = offset;
        offsetEnd += buf.getInt(offsetListStart + n * Integer.SIZE / 8);
       
        assert (offsetEnd > offsetStart);
       
        return new ByteRange(buf, offsetStart, offsetEnd);
    }
View Full Code Here

       
        if (buf instanceof byte[])
            return ((byte[]) buf)[offset];
       
        else {
            ByteRange range = (ByteRange) buf;
           
            assert (range.getSize() <= offset);
            return range.getBuf().get(range.getStartOffset() + offset);
        }
    }
View Full Code Here

        int endBlockOffset;
        if (indexPosition == blockIndex.getNumEntries() - 1)
            // the last block in the block index
            endBlockOffset = -1;
        else {
            ByteRange indexPos = getBlockEntry(indexPosition + 1, blockIndex);
            ByteBuffer indexPosBuf = indexPos.getBuf();
            endBlockOffset = getBlockIndexOffset(indexPosBuf, indexPos.getStartOffset());
           
            // is this the last block of the current block file?
            // then the endBlockOffset should be set to the end of the file
            if (getBlockIndexFileId(indexPosBuf, indexPos.getStartOffset()) > fileId)
                endBlockOffset = -1;
           
            // endBlockOffset = getBlockOffset(indexPosition + 1, blockIndex);
        }
       
        // create a view buffer on the target block
        BlockReader targetBlock = null;
        try {
            targetBlock = mmaped ? getBlock(startBlockOffset, endBlockOffset, dbFiles[fileId]) : getBlock(
                startBlockOffset, endBlockOffset, dbFileChannels[fileId]);
        } catch (IOException e) {
            Logging.logError(Logging.LEVEL_ERROR, this, e);
        }
       
        // search for the key in the target block and return the result
        ByteRange val = targetBlock.lookup(key);
        byte[] result = val == null ? null : val.toBuffer();
        targetBlock.free();
       
        return result;
    }
View Full Code Here

     * @param index
     *            the block index
     * @return the offset
     */
    protected static int getBlockOffset(int indexPosition, BlockReader index) {
        ByteRange range = index.getValues().getEntry(indexPosition);
        return range.getBuf().getInt(range.getStartOffset());
    }
View Full Code Here

     * @param index
     *            the block index
     * @return the block file id
     */
    protected static short getBlockFileId(int indexPosition, BlockReader index) {
        ByteRange range = index.getValues().getEntry(indexPosition);
        // block file index is after the int indicating the offset in the index
        // file
        return range.getBuf().getShort(range.getStartOffset() + (Integer.SIZE / 8));
    }
View Full Code Here

        // file
        return range.getBuf().getShort(range.getStartOffset() + (Integer.SIZE / 8));
    }
   
    protected static ByteRange getBlockEntry(int indexPosition, BlockReader index) {
        ByteRange range = index.getValues().getEntry(indexPosition);
        // block file index is after the int indicating the offset in the index
        // file
        return range;
    }
View Full Code Here

       
        // binary search
        while (low <= high) {
           
            mid = (low + high) >>> 1;
            ByteRange currKey = page.getEntry(mid);
           
            cmp = comp.compare(currKey, entry);
            if (cmp < 0)
                low = mid + 1;
            else if (cmp > 0)
View Full Code Here

TOP

Related Classes of org.xtreemfs.babudb.index.ByteRange

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.