public static void dump( FileSystemAbstraction fs, DatabaseLayout databaseLayout, Dumper dumper, TxFilter txFilter ) throws IOException { File writeLogFile = writeLogBaseFile( databaseLayout ); String writeLogFileBaseName = writeLogFile.getName(); File[] files = fs.listFiles( databaseLayout.databaseDirectory(), ( dir, name ) -> name.startsWith( writeLogFileBaseName ) ); Arrays.sort( files, comparing( file -> file.getName().equals( writeLogFileBaseName ) ? 0 : millisOf( file ) ) ); long session = 0; for ( File file : files ) { dumper.file( file ); session = dumpFile( fs, file, dumper, txFilter, session ); } }
@Test public void shouldRotateExistingFileOnOpen() { // given LabelScanWriteMonitor writeMonitor = new LabelScanWriteMonitor( fs, directory.databaseLayout() ); writeMonitor.close(); // when LabelScanWriteMonitor secondWriteMonitor = new LabelScanWriteMonitor( fs, directory.databaseLayout() ); secondWriteMonitor.close(); // then assertEquals( 2, directory.databaseDir().listFiles( ( dir, name ) -> name.startsWith( baseName ) ).length ); }
LabelScanWriteMonitor( FileSystemAbstraction fs, DatabaseLayout databaseLayout, long rotationThreshold, ByteUnit rotationThresholdUnit, long pruneThreshold, TimeUnit pruneThresholdUnit ) { this.fs = fs; this.rotationThreshold = rotationThresholdUnit.toBytes( rotationThreshold ); this.pruneThreshold = pruneThresholdUnit.toMillis( pruneThreshold ); this.storeDir = databaseLayout.databaseDirectory(); this.file = writeLogBaseFile( databaseLayout ); try { if ( fs.fileExists( file ) ) { moveAwayFile(); } this.channel = instantiateChannel(); } catch ( IOException e ) { throw new UncheckedIOException( e ); } }
TxFilter txFilter = parseTxFilter( arguments.get( ARG_TXFILTER, null ) ); PrintStream out = System.out; boolean redirectsToFile = arguments.getBoolean( ARG_TOFILE ); if ( redirectsToFile ) File outFile = new File( writeLogBaseFile( databaseLayout ).getAbsolutePath() + ".txt" ); System.out.println( "Redirecting output to " + outFile ); out = new PrintStream( new BufferedOutputStream( new FileOutputStream( outFile ) ) ); dump( fs, databaseLayout, dumper, txFilter ); if ( redirectsToFile )
moveAwayFile(); position.reset(); channel = instantiateChannel(); for ( File file : fs.listFiles( storeDir, ( dir, name ) -> name.startsWith( file.getName() + "-" ) ) ) if ( millisOf( file ) < threshold )
@Test public void shouldParseSimpleSingleTxFilter() { // given LabelScanWriteMonitor.TxFilter txFilter = LabelScanWriteMonitor.parseTxFilter( "123" ); // when/then assertFalse( txFilter.contains( 122 ) ); assertTrue( txFilter.contains( 123 ) ); assertFalse( txFilter.contains( 124 ) ); }
case TYPE_PREPARE_ADD: case TYPE_PREPARE_REMOVE: dumpPrepare( dumper, type, channel, range, labelId, txFilter, session, flush ); break; case TYPE_MERGE_ADD: case TYPE_MERGE_REMOVE: dumpMerge( dumper, type, channel, range, labelId, txFilter, session, flush ); break; case TYPE_FLUSH:
@Before public void before() { baseName = LabelScanWriteMonitor.writeLogBaseFile( directory.databaseLayout() ).getName(); }
@Override public void mergeAdd( LabelScanValue existingValue, LabelScanValue newValue ) { merge( TYPE_MERGE_ADD, existingValue, newValue ); }
TxFilter txFilter = parseTxFilter( arguments.get( ARG_TXFILTER, null ) ); PrintStream out = System.out; boolean redirectsToFile = arguments.getBoolean( ARG_TOFILE ); if ( redirectsToFile ) File outFile = new File( writeLogBaseFile( databaseLayout ).getAbsolutePath() + ".txt" ); System.out.println( "Redirecting output to " + outFile ); out = new PrintStream( new BufferedOutputStream( new FileOutputStream( outFile ) ) ); dump( fs, databaseLayout, dumper, txFilter ); if ( redirectsToFile )
moveAwayFile(); position.reset(); channel = instantiateChannel(); for ( File file : fs.listFiles( storeDir, ( dir, name ) -> name.startsWith( file.getName() + "-" ) ) ) if ( millisOf( file ) < threshold )
@Test public void shouldParseSimpleMultipleTxFilters() { // given LabelScanWriteMonitor.TxFilter txFilter = LabelScanWriteMonitor.parseTxFilter( "123,146,123456" ); // when/then assertFalse( txFilter.contains( 122 ) ); assertTrue( txFilter.contains( 123 ) ); assertTrue( txFilter.contains( 146 ) ); assertTrue( txFilter.contains( 123456 ) ); assertFalse( txFilter.contains( 147 ) ); }
case TYPE_PREPARE_ADD: case TYPE_PREPARE_REMOVE: dumpPrepare( dumper, type, channel, range, labelId, txFilter, session, flush ); break; case TYPE_MERGE_ADD: case TYPE_MERGE_REMOVE: dumpMerge( dumper, type, channel, range, labelId, txFilter, session, flush ); break; case TYPE_FLUSH:
@Override public void mergeRemove( LabelScanValue existingValue, LabelScanValue newValue ) { merge( TYPE_MERGE_REMOVE, existingValue, newValue ); }
public static void dump( FileSystemAbstraction fs, DatabaseLayout databaseLayout, Dumper dumper, TxFilter txFilter ) throws IOException { File writeLogFile = writeLogBaseFile( databaseLayout ); String writeLogFileBaseName = writeLogFile.getName(); File[] files = fs.listFiles( databaseLayout.databaseDirectory(), ( dir, name ) -> name.startsWith( writeLogFileBaseName ) ); Arrays.sort( files, comparing( file -> file.getName().equals( writeLogFileBaseName ) ? 0 : millisOf( file ) ) ); long session = 0; for ( File file : files ) { dumper.file( file ); session = dumpFile( fs, file, dumper, txFilter, session ); } }
LabelScanWriteMonitor( FileSystemAbstraction fs, DatabaseLayout databaseLayout, long rotationThreshold, ByteUnit rotationThresholdUnit, long pruneThreshold, TimeUnit pruneThresholdUnit ) { this.fs = fs; this.rotationThreshold = rotationThresholdUnit.toBytes( rotationThreshold ); this.pruneThreshold = pruneThresholdUnit.toMillis( pruneThreshold ); this.storeDir = databaseLayout.databaseDirectory(); this.file = writeLogBaseFile( databaseLayout ); try { if ( fs.fileExists( file ) ) { moveAwayFile(); } this.channel = instantiateChannel(); } catch ( IOException e ) { throw new UncheckedIOException( e ); } }
@Test public void shouldParseRangedSingleTxFilter() { // given LabelScanWriteMonitor.TxFilter txFilter = LabelScanWriteMonitor.parseTxFilter( "123-126" ); // when/then assertFalse( txFilter.contains( 122 ) ); assertTrue( txFilter.contains( 123 ) ); assertTrue( txFilter.contains( 124 ) ); assertTrue( txFilter.contains( 125 ) ); assertTrue( txFilter.contains( 126 ) ); assertFalse( txFilter.contains( 127 ) ); }
@Override public void mergeRemove( LabelScanValue existingValue, LabelScanValue newValue ) { merge( TYPE_MERGE_REMOVE, existingValue, newValue ); }
@Test public void shouldParseRangedMultipleTxFilters() { // given LabelScanWriteMonitor.TxFilter txFilter = LabelScanWriteMonitor.parseTxFilter( "123-125,345-567" ); // when/then assertFalse( txFilter.contains( 122 ) ); assertTrue( txFilter.contains( 123 ) ); assertTrue( txFilter.contains( 124 ) ); assertTrue( txFilter.contains( 125 ) ); assertFalse( txFilter.contains( 201 ) ); assertTrue( txFilter.contains( 345 ) ); assertTrue( txFilter.contains( 405 ) ); assertTrue( txFilter.contains( 567 ) ); assertFalse( txFilter.contains( 568 ) ); }
@Override public void mergeAdd( LabelScanValue existingValue, LabelScanValue newValue ) { merge( TYPE_MERGE_ADD, existingValue, newValue ); }