/** * 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; }
/** * 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); } }
/** * 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 ); } }
/** * Deletes a record. * * @param recid the rowid for the record that should be deleted. * @throws IOException when one of the underlying I/O operations fails. */ public synchronized void delete( long recid ) throws IOException { checkIfClosed(); if ( recid <= 0 ) { throw new IllegalArgumentException( I18n.err( I18n.ERR_536, recid ) ); } if ( DEBUG ) { System.out.println( "BaseRecordManager.delete() recid " + recid ); } Location logRowId = new Location( recid ); Location physRowId = logMgr.fetch( logRowId ); physMgr.delete( physRowId ); logMgr.delete( logRowId ); }
static long decompressRecid(long recid){ long block = recid >>8; short offset = (short) (((recid & 0xff) ) * 8+TranslationPage.O_TRANS); return Location.toLong(block, offset); }}
/** * Insert at forced location, use only for defragmentation !! * @param logicalRowId * @param physLoc * @throws IOException */ void forceInsert(long logicalRowId, long physLoc) throws IOException { //create pages until we reach requested block long lastBlock = pageman.getLast(Magic.TRANSLATION_PAGE); while(lastBlock!=Location.getBlock(logicalRowId)){ lastBlock = pageman.allocate(Magic.TRANSLATION_PAGE); if(lastBlock>Location.getBlock(logicalRowId)) throw new Error("outallocated"); } if(fetch(logicalRowId) != 0) throw new Error("can not forceInsert, record already exists: "+logicalRowId); update(logicalRowId, physLoc); }
/** * Deletes a record. * * @param recid the rowid for the record that should be deleted. * @throws IOException when one of the underlying I/O operations fails. */ public synchronized void delete( long recid ) throws IOException { checkIfClosed(); if ( recid <= 0 ) { throw new IllegalArgumentException( I18n.err( I18n.ERR_536, recid ) ); } if ( DEBUG ) { System.out.println( "BaseRecordManager.delete() recid " + recid ) ; } Location logRowId = new Location( recid ); Location physRowId = logMgr.fetch( logRowId ); physMgr.delete( physRowId ); logMgr.delete( logRowId ); }
public long slotToLocation(int slot) { short pos = slotToOffset(slot); return Location.toLong(getLocationBlock(pos),getLocationOffset(pos)); }
/** * Updates a record using a custom serializer. * * @param recid the recid for the record that is to be updated. * @param obj the new object for the record. * @param serializer a custom serializer * @throws IOException when one of the underlying I/O operations fails. */ public synchronized void update( long recid, Object obj, Serializer serializer ) throws IOException { checkIfClosed(); if ( recid <= 0 ) { throw new IllegalArgumentException( I18n.err( I18n.ERR_536, recid ) ); } Location logRecid = new Location( recid ); Location physRecid = logMgr.fetch( logRecid ); byte[] data = serializer.serialize( obj ); if ( DEBUG ) { System.out.println( "BaseRecordManager.update() recid " + recid + " length " + data.length ); } Location newRecid = physMgr.update( physRecid, data, 0, data.length ); if ( !newRecid.equals( physRecid ) ) { logMgr.update( logRecid, newRecid ); } }
/** * 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); }
/** * 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); } }
/** * Fetches a record using a custom serializer. * * @param recid the recid for the record that must be fetched. * @param serializer a custom serializer * @return the object contained in the record. * @throws IOException when one of the underlying I/O operations fails. */ public synchronized Object fetch( long recid, Serializer serializer ) throws IOException { byte[] data; checkIfClosed(); if ( recid <= 0 ) { throw new IllegalArgumentException( I18n.err( I18n.ERR_536, recid ) ); } data = physMgr.fetch( logMgr.fetch( new Location( recid ) ) ); if ( DEBUG ) { System.out.println( "BaseRecordManager.fetch() recid " + recid + " length " + data.length ); } return serializer.deserialize( data ); }
public long slotToLocation(int slot) { short pos = slotToOffset(slot); return Location.toLong(getLocationBlock(pos),getLocationOffset(pos)); }
/** * 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 ); }
/** * 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 ); } }
/** * Fetches a record using a custom serializer. * * @param recid the recid for the record that must be fetched. * @param serializer a custom serializer * @return the object contained in the record. * @throws IOException when one of the underlying I/O operations fails. */ public synchronized Object fetch( long recid, Serializer serializer ) throws IOException { byte[] data; checkIfClosed(); if ( recid <= 0 ) { throw new IllegalArgumentException( I18n.err( I18n.ERR_536, recid ) ); } data = physMgr.fetch( logMgr.fetch( new Location( recid ) ) ); if ( DEBUG ) { System.out.println( "BaseRecordManager.fetch() recid " + recid + " length " + data.length ) ; } return serializer.deserialize( data ); }
/** * Inserts a new record using a custom serializer. * * @param obj the object for the new record. * @param serializer a custom serializer * @return the rowid for the new record. * @throws IOException when one of the underlying I/O operations fails. */ public long insert( Object obj, Serializer serializer ) throws IOException { byte[] data; long recid; Location physRowId; checkIfClosed(); data = serializer.serialize( obj ); physRowId = physMgr.insert( data, 0, data.length ); recid = logMgr.insert( physRowId ).toLong(); LOG.debug( "BaseRecordManager.insert() recid {} length {}", recid, data.length ); return recid; }
/** * 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 ); }