@Override public void write( MetaDataRecord record, PageCursor cursor, int recordSize ) { assert record.inUse(); cursor.putByte( Record.IN_USE.byteValue() ); cursor.putLong( record.getValue() ); } }
private long getRecordValue( PageCursor cursor, Position position, long defaultValue ) { MetaDataRecord record = newRecord(); try { record.setId( position.id ); recordFormat.read( record, cursor, FORCE, RECORD_SIZE ); if ( record.inUse() ) { return record.getValue(); } return defaultValue; } catch ( IOException e ) { throw new UnderlyingStorageException( e ); } }
@Test public void mustSupportScanningAllRecords() throws Exception { File file = createMetaDataFile(); MetaDataStore.Position[] positions = MetaDataStore.Position.values(); long storeVersion = versionStringToLong( Standard.LATEST_RECORD_FORMATS.storeVersion()); writeCorrectMetaDataRecord( file, positions, storeVersion ); List<Long> actualValues = new ArrayList<>(); try ( MetaDataStore store = newMetaDataStore() ) { store.scanAllRecords( record -> { actualValues.add( record.getValue() ); return false; } ); } List<Long> expectedValues = Arrays.stream( positions ).map( p -> { if ( p == MetaDataStore.Position.STORE_VERSION ) { return storeVersion; } else { return p.ordinal() + 1L; } } ).collect( Collectors.toList() ); assertThat( actualValues, is( expectedValues ) ); }
if ( record.inUse() ) actualValues.add( record.getValue() );
if ( record.inUse() ) value = record.getValue();
@Override public void write( MetaDataRecord record, PageCursor cursor, int recordSize ) { assert record.inUse(); cursor.putByte( Record.IN_USE.byteValue() ); cursor.putLong( record.getValue() ); } }
private long getRecordValue( PageCursor cursor, Position position, long defaultValue ) { MetaDataRecord record = newRecord(); try { record.setId( position.id ); recordFormat.read( record, cursor, FORCE, RECORD_SIZE ); if ( record.inUse() ) { return record.getValue(); } return defaultValue; } catch ( IOException e ) { throw new UnderlyingStorageException( e ); } }
if ( record.inUse() ) value = record.getValue();