/** * Deletes a record. */ void delete( Location rowid ) throws IOException { free( rowid ); }
/** * Insert data at forced logicalRowId, use only for defragmentation !! * @param logicalRowId * @param bb data * @throws IOException */ private void forceInsert(long logicalRowId, byte[] data) throws IOException { long physLoc = _physMgr.insert(data, 0, data.length); _logicMgr.forceInsert(logicalRowId, physLoc); }
/** * 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; }
/** * Allocate a new rowid with the indicated size. */ private Location alloc( int size ) throws IOException { Location retval = freeman.get( size ); if ( retval == null ) { // temporary work around for DIRSERVER-1459 retval = allocNew( size * 2, pageManager.getLast( Magic.USED_PAGE ) ); } return retval; }
/** * 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 ); }
/** * Creates a record manager for the indicated file * * @throws IOException when the file cannot be opened or is not * a valid file content-wise. */ public BaseRecordManager( String filename ) throws IOException { recordFile = new RecordFile( filename ); pageMgr = new PageManager( recordFile ); physMgr = new PhysicalRowIdManager( pageMgr ); logMgr = new LogicalRowIdManager( pageMgr ); lockElements = new ConcurrentHashMap<Long, LockElement>(); }
public synchronized void delete( long logRowId ) throws IOException { checkIfClosed(); if ( logRowId <= 0 ) { throw new IllegalArgumentException( "Argument 'recid' is invalid: " + logRowId ); } if ( DEBUG ) { System.out.println( "BaseRecordManager.delete() recid " + logRowId ) ; } logRowId = decompressRecid(logRowId); long physRowId = _logicMgr.fetch( logRowId ); _physMgr.delete( physRowId ); _logicMgr.delete( logRowId ); }
/** * 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 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; }
/** * Allocate a new rowid with the indicated size. */ private Location alloc( int size ) throws IOException { Location retval = freeman.get( size ); if ( retval == null ) { // temporary work around for DIRSERVER-1459 retval = allocNew( size * 2, pageman.getLast( Magic.USED_PAGE ) ); } return retval; }
/** * 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 ); }
/** * Creates a record manager for the indicated file * * @throws IOException when the file cannot be opened or is not * a valid file content-wise. */ public BaseRecordManager( String filename ) throws IOException { recordFile = new RecordFile( filename ); pageMgr = new PageManager( recordFile ); physMgr = new PhysicalRowIdManager( recordFile, pageMgr ); logMgr = new LogicalRowIdManager( recordFile, pageMgr ); }
/** * 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 ); }
Location newRecid = physMgr.update( physRecid, data, 0, data.length );
/** * 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; }
/** * Allocate a new rowid with the indicated size. */ private Location alloc( int size ) throws IOException { Location retval = freePageManager.get( size ); if ( retval == null ) { // temporary work around for DIRSERVER-1459 retval = allocNew( size * 2, pageManager.getLast( Magic.USED_PAGE ) ); } return retval; }
/** * 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; }
_physMgr.fetch(b, physRowId); byte[] bb = b.toByteArray();