/** * Verifies that a record's in use status is in line with the mode, might throw {@link InvalidRecordException}. */ public final boolean verify( AbstractBaseRecord record ) { boolean inUse = record.inUse(); if ( this == NORMAL & !inUse ) { throw new InvalidRecordException( record + " not in use" ); } return this == FORCE | inUse; }
@Override public void prepareForCommit( RECORD record, IdSequence idSequence ) { if ( record.inUse() ) { recordFormat.prepare( record, recordSize, idSequence ); } }
public boolean append( RecordStore<RECORD> store, PageCursor cursor, RECORD[] array, long id, int index ) { RECORD record = array[index]; store.getRecordByCursor( id, record, RecordLoad.CHECK, cursor ); return record.inUse() && filter.test( record ); }
public static Mode fromRecordState( AbstractBaseRecord record ) { return fromRecordState( record.isCreated(), record.inUse() ); } }
private static String commandActionToken( AbstractBaseRecord record ) { if ( !record.inUse() ) { return "deleted"; } if ( record.isCreated() ) { return "created"; } return "updated"; }
@Override protected void process( T[] batch, BatchSender sender ) { for ( T item : batch ) { if ( item != null && item.inUse() ) { if ( !processor.process( item ) ) { // No change for this record item.setInUse( false ); } } } // This step can be used in different stage settings, possible as the last step, // where nothing should be emitted if ( !endOfLine ) { sender.send( batch ); } }
@Override protected R fetchNextOrNull() { while ( ids.hasNext() ) { store.getRecordByCursor( ids.next(), record, RecordLoad.CHECK, cursor ); if ( record.inUse() ) { if ( passesFilters( record ) ) { return record; } } } return null; }
@Override public <EXCEPTION extends Exception> void scanAllRecords( Visitor<RECORD,EXCEPTION> visitor ) throws EXCEPTION { try ( PageCursor cursor = openPageCursorForReading( 0 ) ) { RECORD record = newRecord(); long highId = getHighId(); for ( long id = getNumberOfReservedLowIds(); id < highId; id++ ) { getRecordByCursor( id, record, CHECK, cursor ); if ( record.inUse() ) { visitor.visit( record ); } } } }
@Override protected void process( RECORD[] batch, BatchSender sender ) { LongFunction<IdSequence> idSequence = prepareIdSequence.apply( store ); int recordsUpdatedInThisBatch = 0; for ( RECORD record : batch ) { if ( record != null && record.inUse() && !IdValidator.isReservedId( record.getId() ) ) { store.prepareForCommit( record, idSequence.apply( record.getId() ) ); store.updateRecord( record ); recordsUpdatedInThisBatch++; } } recordsUpdated.add( recordsUpdatedInThisBatch ); }
public static <RECORD extends AbstractBaseRecord> int numberOfRecordsInUse( RecordStore<RECORD> store ) { int inUse = 0; for ( long id = store.getNumberOfReservedLowIds(); id < store.getHighId(); id++ ) { RECORD record = store.getRecord( id, store.newRecord(), RecordLoad.FORCE ); if ( record.inUse() ) { inUse++; } } return inUse; }
private <R extends AbstractBaseRecord> void writeRecord( R record, RecordFormat<R> format, PagedFile storeFile, int recordSize, BatchingIdSequence idSequence ) throws IOException { try ( PageCursor cursor = storeFile.io( 0, PagedFile.PF_SHARED_WRITE_LOCK ) ) { assertedNext( cursor ); if ( record.inUse() ) { format.prepare( record, recordSize, idSequence ); } int offset = Math.toIntExact( record.getId() * recordSize ); cursor.setOffset( offset ); format.write( record, cursor, recordSize ); assertWithinBounds( record, cursor, "writing" ); } }
public boolean append( RecordStore<RECORD> store, PageCursor cursor, RECORD[] array, long id, int index ) { RECORD record = array[index]; store.getRecordByCursor( id, record, RecordLoad.CHECK, cursor ); return record.inUse() && filter.test( record ); }
@Override public void prepareForCommit( RECORD record, IdSequence idSequence ) { if ( record.inUse() ) { recordFormat.prepare( record, recordSize, idSequence ); } }
/** * Verifies that a record's in use status is in line with the mode, might throw {@link InvalidRecordException}. */ public final boolean verify( AbstractBaseRecord record ) { boolean inUse = record.inUse(); if ( this == NORMAL & !inUse ) { throw new InvalidRecordException( record + " not in use" ); } return this == FORCE | inUse; }
public static Mode fromRecordState( AbstractBaseRecord record ) { return fromRecordState( record.isCreated(), record.inUse() ); } }
@Override protected R fetchNextOrNull() { while ( ids.hasNext() ) { store.getRecordByCursor( ids.next(), record, RecordLoad.CHECK, cursor ); if ( record.inUse() ) { if ( passesFilters( record ) ) { return record; } } } return null; }
@Override public final void prepare( RECORD record, int recordSize, IdSequence idSequence ) { if ( record.inUse() ) { int requiredLength = HEADER_BYTE + requiredDataLength( record ); boolean requiresSecondaryUnit = requiredLength > recordSize; record.setRequiresSecondaryUnit( requiresSecondaryUnit ); if ( record.requiresSecondaryUnit() && !record.hasSecondaryUnitId() ) { // Allocate a new id at this point, but this is not the time to free this ID the the case where // this record doesn't need this secondary unit anymore... that needs to be done when applying to store. record.setSecondaryUnitId( idSequence.nextId() ); } } }
@Override protected void process( RECORD[] batch, BatchSender sender ) { LongFunction<IdSequence> idSequence = prepareIdSequence.apply( store ); int recordsUpdatedInThisBatch = 0; for ( RECORD record : batch ) { if ( record != null && record.inUse() && !IdValidator.isReservedId( record.getId() ) ) { store.prepareForCommit( record, idSequence.apply( record.getId() ) ); store.updateRecord( record ); recordsUpdatedInThisBatch++; } } recordsUpdated.add( recordsUpdatedInThisBatch ); }