/** Returns the current size */ static int getCurrentSize(final BlockIo block, final short pos) { int s = block.readUnsignedshort(pos + O_CURRENTSIZE); if(s == BlockIo.UNSIGNED_SHORT_MAX) return 0; return getAvailableSize(block, pos) - s; }
/** Sets the current size */ static void setCurrentSize(final BlockIo block, final short pos,int value) { if(value == 0){ block.writeUnsignedShort(pos + O_CURRENTSIZE, BlockIo.UNSIGNED_SHORT_MAX); 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.writeUnsignedShort(pos + O_CURRENTSIZE, availSize - value); }
public String toString() { return "RH( " + block.getBlockId() + " : " + pos + ", avl = " + getAvailableSize() + ", cur = " + getCurrentSize() + " )"; } }
public String toString() { return "RH( " + block.getBlockId() + " : " + pos + ", avl = " + getAvailableSize() + ", cur = " + getCurrentSize() + " )"; } }
public String toString() { return "RH( " + block.getBlockId() + " : " + pos + ", avl = " + getAvailableSize() + ", cur = " + getCurrentSize() + " )"; } }
private void free( Location id ) throws IOException { // get the rowid, and write a zero current size into it. BlockIo curBlock = file.get( id.getBlock() ); RecordHeader hdr = new RecordHeader( curBlock, id.getOffset() ); hdr.setCurrentSize( 0 ); file.release( id.getBlock(), true ); // write the rowid to the free list freeman.put( id, hdr.getAvailableSize() ); }
private void free( Location id ) throws IOException { // get the rowid, and write a zero current size into it. BlockIo curBlock = file.get( id.getBlock() ); RecordHeader hdr = new RecordHeader( curBlock, id.getOffset() ); hdr.setCurrentSize( 0 ); file.release( id.getBlock(), true ); // write the rowid to the free list freePageManager.put( id, hdr.getAvailableSize() ); }
private void free( Location id ) throws IOException { // get the rowid, and write a zero current size into it. BlockIo curBlock = file.get( id.getBlock() ); RecordHeader hdr = new RecordHeader( curBlock, id.getOffset() ); hdr.setCurrentSize( 0 ); file.release( id.getBlock(), true ); // write the rowid to the free list freeman.put( id, hdr.getAvailableSize() ); }
private void free(long id) throws IOException { // get the rowid, and write a zero current size into it. BlockIo curBlock = file.get(Location.getBlock(id)); DataPage curPage = DataPage.getDataPageView(curBlock,BLOCK_SIZE); RecordHeader.setCurrentSize(curBlock, Location.getOffset(id), 0); file.release(Location.getBlock(id), true); // write the rowid to the free list freeman.put(id, RecordHeader.getAvailableSize(curBlock, Location.getOffset(id))); }
/** * Updates an existing record. Returns the possibly changed physical rowid. */ long update(long rowid, byte[] data, int start, int length) throws IOException { // fetch the record header BlockIo block = file.get(Location.getBlock(rowid)); short head = Location.getOffset(rowid); int availSize = RecordHeader.getAvailableSize(block, head); if (length > availSize || //difference between free and available space can be only 64KB. //if bigger, need to realocate and free block availSize - length > RecordHeader.MAX_SIZE_SPACE ) { // not enough space - we need to copy to a new rowid. file.release(block); free(rowid); rowid = alloc(length); } else { file.release(block); } // 'nuff space, write it in and return the rowid. write(rowid, data, start, length); return rowid; }
/** * Updates an existing record. Returns the possibly changed * physical rowid. */ Location update( Location rowid, byte[] data, int start, int length ) throws IOException { // fetch the record header BlockIo block = file.get( rowid.getBlock() ); RecordHeader head = new RecordHeader( block, rowid.getOffset() ); if ( length > head.getAvailableSize() ) { // not enough space - we need to copy to a new rowid. file.release( block ); free( rowid ); rowid = alloc( length ); } else { file.release( block ); } // 'nuff space, write it in and return the rowid. write( rowid, data, start, length ); return rowid; }
/** * Updates an existing record. Returns the possibly changed * physical rowid. */ Location update( Location rowid, byte[] data, int start, int length ) throws IOException { // fetch the record header BlockIo block = pageManager.getRecordFile().get( rowid.getBlock() ); RecordHeader head = new RecordHeader( block, rowid.getOffset() ); if ( length > head.getAvailableSize() ) { // not enough space - we need to copy to a new rowid. pageManager.getRecordFile().release( block ); free( rowid ); rowid = alloc( length ); } else { pageManager.getRecordFile().release( block ); } // 'nuff space, write it in and return the rowid. write( rowid, data, start, length ); return rowid; }
/** * Updates an existing record. Returns the possibly changed * physical rowid. */ Location update( Location rowid, byte[] data, int start, int length ) throws IOException { // fetch the record header BlockIo block = pageManager.getRecordFile().get( rowid.getBlock() ); RecordHeader head = new RecordHeader( block, rowid.getOffset() ); if ( length > head.getAvailableSize() ) { // not enough space - we need to copy to a new rowid. pageManager.getRecordFile().release( block ); free( rowid ); rowid = alloc( length ); } else { pageManager.getRecordFile().release( block ); } // 'nuff space, write it in and return the rowid. write( rowid, data, start, length ); return rowid; }
while (RecordHeader.getAvailableSize(curBlock, hdr) != 0 && pos < BLOCK_SIZE) { pos += RecordHeader.getAvailableSize(curBlock, hdr) + RecordHeader.SIZE; if (pos == BLOCK_SIZE) {
while ( hdr.getAvailableSize() != 0 && pos < RecordFile.BLOCK_SIZE ) pos += hdr.getAvailableSize() + RecordHeader.SIZE;
while ( hdr.getAvailableSize() != 0 && pos < RecordFile.BLOCK_SIZE ) { pos += hdr.getAvailableSize() + RecordHeader.SIZE; if ( pos == RecordFile.BLOCK_SIZE ) {
while ( hdr.getAvailableSize() != 0 && pos < RecordFile.BLOCK_SIZE ) { pos += hdr.getAvailableSize() + RecordHeader.SIZE; if ( pos == RecordFile.BLOCK_SIZE ) {