header != null ? header.toString() : "null header." ) ); return new PhysicalLogVersionedStoreChannel( rawChannel, version, header.logFormatVersion );
@Override public void start() throws IOException { // Recovery has taken place before this, so the log file has been truncated to last known good tx // Just read header and move to the end long lastLogVersionUsed = logVersionRepository.getCurrentLogVersion(); channel = logFiles.createLogChannelForVersion( lastLogVersionUsed, OpenMode.READ_WRITE, context::getLastCommittedTransactionId ); // Move to the end channel.position( channel.size() ); writer = new PositionAwarePhysicalFlushableChannel( channel ); }
@Override public long write( ByteBuffer[] srcs, int offset, int length ) throws IOException { return advance( delegateChannel.write( srcs, offset, length ) ); }
private void verifyTransactionLogs( File txDirectory, File storeDir ) throws IOException { FileSystemAbstraction fileSystem = fileSystemRule.get(); LogFiles storeDirLogs = LogFilesBuilder.logFilesBasedOnlyBuilder( storeDir, fileSystem ).build(); assertFalse( storeDirLogs.versionExists( 0 ) ); LogFiles txDirectoryLogs = LogFilesBuilder.logFilesBasedOnlyBuilder( txDirectory, fileSystem ).build(); assertTrue( txDirectoryLogs.versionExists( 0 ) ); try ( PhysicalLogVersionedStoreChannel physicalLogVersionedStoreChannel = txDirectoryLogs.openForVersion( 0 ) ) { assertThat( physicalLogVersionedStoreChannel.size(), greaterThan( 0L ) ); } }
@Override public void shutdown() throws IOException { if ( writer != null ) { writer.close(); } if ( channel != null ) { channel.close(); } }
@Override public boolean rotationNeeded() { /* * Whereas channel.size() should be fine, we're safer calling position() due to possibility * of this file being memory mapped or whatever. */ return channel.position() >= rotateAtSize.get(); }
@Override public void flush() throws IOException { force( false ); } }
@Override public void init() throws IOException { logVersionRepository = context.getLogVersionRepository(); // Make sure at least a bare bones log file is available before recovery long lastLogVersionUsed = this.logVersionRepository.getCurrentLogVersion(); channel = logFiles.createLogChannelForVersion( lastLogVersionUsed, OpenMode.READ_WRITE, context::getLastCommittedTransactionId ); channel.close(); }
@Override public ReadableLogChannel getReader( LogPosition position, LogVersionBridge logVersionBridge ) throws IOException { PhysicalLogVersionedStoreChannel logChannel = logFiles.openForVersion( position.getLogVersion() ); logChannel.position( position.getByteOffset() ); return new ReadAheadLogChannel( logChannel, logVersionBridge ); }
@Override public void flush() throws IOException { force( false ); } }
@Test public void shouldOpenTheNextChannelWhenItExists() throws IOException { // given final StoreChannel newStoreChannel = mock( StoreChannel.class ); final ReaderLogVersionBridge bridge = new ReaderLogVersionBridge( logFiles ); when( channel.getVersion() ).thenReturn( version ); when( channel.getLogFormatVersion() ).thenReturn( CURRENT_LOG_VERSION ); when( fs.fileExists( any( File.class ) ) ).thenReturn( true ); when( fs.open( any( File.class ), eq( OpenMode.READ ) ) ).thenReturn( newStoreChannel ); when( newStoreChannel.read( ArgumentMatchers.<ByteBuffer>any() ) ).then( invocationOnMock -> { ByteBuffer buffer = invocationOnMock.getArgument( 0 ); buffer.putLong( encodeLogVersion( version + 1 ) ); buffer.putLong( 42 ); return LOG_HEADER_SIZE; } ); // when final LogVersionedStoreChannel result = bridge.next( channel ); // then PhysicalLogVersionedStoreChannel expected = new PhysicalLogVersionedStoreChannel( newStoreChannel, version + 1, CURRENT_LOG_VERSION ); assertEquals( expected, result ); verify( channel, times( 1 ) ).close(); }
@Override public void start() throws IOException { // Recovery has taken place before this, so the log file has been truncated to last known good tx // Just read header and move to the end long lastLogVersionUsed = logVersionRepository.getCurrentLogVersion(); channel = logFiles.createLogChannelForVersion( lastLogVersionUsed, OpenMode.READ_WRITE, context::getLastCommittedTransactionId ); // Move to the end channel.position( channel.size() ); writer = new PositionAwarePhysicalFlushableChannel( channel ); }
@Override public long write( ByteBuffer[] srcs ) throws IOException { return advance( delegateChannel.write( srcs ) ); }
@Override public void shutdown() throws IOException { if ( writer != null ) { writer.close(); } if ( channel != null ) { channel.close(); } }
@Override public boolean rotationNeeded() { /* * Whereas channel.size() should be fine, we're safer calling position() due to possibility * of this file being memory mapped or whatever. */ return channel.position() >= rotateAtSize.get(); }
@Override public LogVersionedStoreChannel next( LogVersionedStoreChannel channel ) throws IOException { if ( !returned ) { returned = true; channel.close(); return new PhysicalLogVersionedStoreChannel( fileSystemRule.get().open( file( 1 ), OpenMode.READ ), -1 /* ignored */, (byte) -1 /* ignored */ ); } return channel; } }, 10 ) )
@Override public void writeAll( ByteBuffer src ) throws IOException { advance( src.remaining() ); delegateChannel.writeAll( src ); }
@Override public void init() throws IOException { logVersionRepository = context.getLogVersionRepository(); // Make sure at least a bare bones log file is available before recovery long lastLogVersionUsed = this.logVersionRepository.getCurrentLogVersion(); channel = logFiles.createLogChannelForVersion( lastLogVersionUsed, OpenMode.READ_WRITE, context::getLastCommittedTransactionId ); channel.close(); }
@Override public ReadableLogChannel getReader( LogPosition position, LogVersionBridge logVersionBridge ) throws IOException { PhysicalLogVersionedStoreChannel logChannel = logFiles.openForVersion( position.getLogVersion() ); logChannel.position( position.getByteOffset() ); return new ReadAheadLogChannel( logChannel, logVersionBridge ); }
return new PhysicalLogVersionedStoreChannel( storeChannel, forVersion, formatVersion );