/** * Compress recid from physical form (block - offset) to (block - slot). * This way resulting number is smaller and can be easyer packed with LongPacker */ static long compressRecid(long recid){ long block = Location.getBlock(recid); short offset= Location.getOffset(recid); offset = (short) (offset - TranslationPage.O_TRANS); if(offset%8!=0) throw new InternalError("not 8"); long slot = offset /8; if(slot<0||slot>255) throw new InternalError("too big slot: "+slot); return (block << 8) + (long) slot; }
/** * Updates the mapping * * @param rowid * The logical rowid * @param loc * The physical rowid */ void update(long rowid, long loc) throws IOException { TranslationPage xlatPage = TranslationPage.getTranslationPageView(file.get(Location.getBlock(rowid)),blockSize); //make sure it is right type of page // PhysicalRowId physid = xlatPage.get(rowid.getOffset()); // physid.setBlock(loc.getBlock()); // physid.setOffset(loc.getOffset()); xlatPage.setLocationBlock(Location.getOffset(rowid), Location.getBlock(loc)); xlatPage.setLocationOffset(Location.getOffset(rowid), Location.getOffset(loc)); file.release(Location.getBlock(rowid), true); }
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))); }
/** * Releases the indicated logical rowid. */ void delete(long rowid) throws IOException { //zero out old location, is needed for defragmentation TranslationPage xlatPage = TranslationPage.getTranslationPageView(file.get(Location.getBlock(rowid)),blockSize); xlatPage.setLocationBlock(Location.getOffset(rowid), 0); xlatPage.setLocationOffset(Location.getOffset(rowid), (short)0); file.release(Location.getBlock(rowid), true); freeman.put(rowid); }
/** * Updates the mapping * * @param rowid The logical rowid * @param loc The physical rowid */ void update( Location rowid, Location loc ) throws IOException { TranslationPage xlatPage = TranslationPage.getTranslationPageView( recordFile.get( rowid.getBlock() ) ); PhysicalRowId physid = xlatPage.get( rowid.getOffset() ); physid.setBlock( loc.getBlock() ); physid.setOffset( loc.getOffset() ); recordFile.release( rowid.getBlock(), true ); }
/** * Updates the mapping * * @param rowid The logical rowid * @param loc The physical rowid */ void update( Location rowid, Location loc ) throws IOException { TranslationPage xlatPage = TranslationPage.getTranslationPageView( recordFile.get( rowid.getBlock() ) ); PhysicalRowId physid = xlatPage.get( rowid.getOffset() ); physid.setBlock( loc.getBlock() ); physid.setOffset( loc.getOffset() ); recordFile.release( rowid.getBlock(), true ); }
/** * Updates the mapping * * @param rowid The logical rowid * @param loc The physical rowid */ void update(Location rowid, Location loc) throws IOException { TranslationPage xlatPage = TranslationPage.getTranslationPageView( file.get(rowid.getBlock())); PhysicalRowId physid = xlatPage.get(rowid.getOffset()); physid.setBlock(loc.getBlock()); physid.setOffset(loc.getOffset()); file.release(rowid.getBlock(), true); }
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( 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() ); }
/** * Returns a mapping * * @param rowid The logical rowid * @return The physical rowid */ Location fetch( Location rowid ) throws IOException { TranslationPage xlatPage = TranslationPage.getTranslationPageView( recordFile.get( rowid.getBlock() ) ); try { Location retval = new Location( xlatPage.get( rowid.getOffset() ) ); return retval; } finally { recordFile.release( rowid.getBlock(), false ); } }
/** * Returns a mapping * * @param rowid The logical rowid * @return The physical rowid */ Location fetch(Location rowid) throws IOException { TranslationPage xlatPage = TranslationPage.getTranslationPageView( file.get(rowid.getBlock())); try { Location retval = new Location(xlatPage.get(rowid.getOffset())); return retval; } finally { file.release(rowid.getBlock(), false); } }
/** * Returns a mapping * * @param rowid The logical rowid * @return The physical rowid */ Location fetch( Location rowid ) throws IOException { TranslationPage xlatPage = TranslationPage.getTranslationPageView( recordFile.get( rowid.getBlock() ) ); try { Location retval = new Location( xlatPage.get( rowid.getOffset() ) ); return retval; } finally { recordFile.release( rowid.getBlock(), false ); } }
/** * 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; }
/** * Returns a mapping * * @param rowid * The logical rowid * @return The physical rowid, 0 if does not exist */ long fetch(long rowid) throws IOException { final long block = Location.getBlock(rowid); long last = pageman.getLast(Magic.TRANSLATION_PAGE); if(last+1<block) return 0; final short offset = Location.getOffset(rowid); BlockIo bio = file.get(block); TranslationPage xlatPage = TranslationPage.getTranslationPageView(bio,blockSize); try { long retval = Location.toLong( xlatPage.getLocationBlock(offset), xlatPage.getLocationOffset(offset)); return retval; } finally { file.release(block, false); } }
/** * 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; }
free.setOffset(rowid.getOffset()); file.release(freePage, true);
free.setOffset( rowid.getOffset() ); free.setSize( size ); recordFile.release( freePage, true );