@Override public void force( boolean metaData ) throws IOException { delegate.force( metaData ); }
@Override public void force( boolean metaData ) throws IOException { delegateChannel.force( metaData ); }
private void closeChannel() throws IOException { fileChannel.force( false ); fileChannel.close(); fileChannel = null; closed = true; }
@Override public void force( boolean b ) throws IOException { fs.ensureHasSpace(); inner.force( b ); }
private void write( StoreChannel channel, long time, long identifier, long version, long lastCommittedTxId, long indexVersion ) throws IOException { buf.clear(); buf.putLong( time ).putLong( identifier ).putLong( version ).putLong( lastCommittedTxId ).putLong( indexVersion ); buf.flip(); channel.writeAll( buf, 0 ); channel.force( true ); }
@Override public void force( boolean metaData ) throws IOException { delegate.force( metaData ); }
private void markAsSticky() throws IOException { ByteBuffer buffer = ByteBuffer.allocate( Byte.BYTES ); buffer.put( STICKY_GENERATOR ).flip(); fileChannel.position( 0 ); fileChannel.writeAll( buffer ); fileChannel.force( false ); }
private void forceAndRetryIfInterrupted( int attemptsLeft ) throws IOException { try { channel( tokenFilePageId ).force( false ); } catch ( ClosedChannelException e ) { tryReopen( tokenFilePageId, e ); if ( attemptsLeft < 1 ) { throw new IOException( "IO failed due to interruption", e ); } boolean interrupted = Thread.interrupted(); forceAndRetryIfInterrupted( attemptsLeft - 1 ); if ( interrupted ) { Thread.currentThread().interrupt(); } } }
@Override public void force( boolean metaData ) throws IOException { adversary.injectFailure( IOException.class ); delegate.force( metaData ); }
@Override public void close() throws IOException { ByteBuffer writeBuffer = ByteBuffer.allocate( batchSize * ID_ENTRY_SIZE ); flushFreeIds( writeBuffer ); freeIds.addAll( readFromDisk ); flushFreeIds( writeBuffer ); if ( !aggressiveMode ) { compact( writeBuffer ); } channel.force( false ); }
static void saveFulltextIndexSettings( FulltextIndexDescriptor descriptor, PartitionedIndexStorage indexStorage, FileSystemAbstraction fs ) throws IOException { File indexConfigFile = new File( indexStorage.getIndexFolder(), INDEX_CONFIG_FILE ); Properties settings = new Properties(); settings.getProperty( INDEX_CONFIG_EVENTUALLY_CONSISTENT, Boolean.toString( descriptor.isEventuallyConsistent() ) ); settings.setProperty( INDEX_CONFIG_ANALYZER, descriptor.analyzerName() ); settings.setProperty( INDEX_CONFIG_PROPERTY_NAMES, descriptor.propertyNames().stream().collect( Collectors.joining( ", ", "[", "]" )) ); settings.setProperty( "_propertyIds", Arrays.toString( descriptor.properties() ) ); settings.setProperty( "_name", descriptor.name() ); settings.setProperty( "_schema_entityType", descriptor.schema().entityType().name() ); settings.setProperty( "_schema_entityTokenIds", Arrays.toString( descriptor.schema().getEntityTokenIds() ) ); try ( StoreChannel channel = fs.create( indexConfigFile ); Writer writer = fs.openAsWriter( indexConfigFile, StandardCharsets.UTF_8, false ) ) { settings.store( writer, "Auto-generated file. Do not modify!" ); writer.flush(); channel.force( true ); } } }
@Test void force() throws Exception { channel.force( false ); verify( actual ).force( false ); }
/** * Create/reserve an empty failure file for the given indexId. * * This will overwrite any pre-existing failure file. * * @throws IOException if the failure file could not be created */ public synchronized void reserveForIndex() throws IOException { fs.mkdirs( folderLayout.getIndexFolder() ); File failureFile = failureFile(); try ( StoreChannel channel = fs.create( failureFile ) ) { channel.writeAll( ByteBuffer.wrap( new byte[MAX_FAILURE_SIZE] ) ); channel.force( true ); } }
@Test( expected = ClosedByInterruptException.class ) public void ch_force() throws IOException { chan( true ).force( true ); }
private void write( File file ) { StoreChannel channel = null; try { channel = fileSystem.open( file, OpenMode.READ_WRITE ); channel.writeAll( ByteBuffer.wrap( MAGIC ) ); IoPrimitiveUtils.writeInt( channel, buffer( 4 ), VERSION ); writeMap( channel, nodeConfig ); writeMap( channel, relConfig ); channel.force( false ); } catch ( IOException e ) { throw new RuntimeException( e ); } finally { close( channel ); } }
/** * Store failure in failure file for index with the given id * * @param failure message describing the failure that needs to be stored * @throws IOException if the failure could not be stored */ public synchronized void storeIndexFailure( String failure ) throws IOException { File failureFile = failureFile(); try ( StoreChannel channel = fs.open( failureFile, OpenMode.READ_WRITE ) ) { byte[] existingData = new byte[(int) channel.size()]; channel.readAll( ByteBuffer.wrap( existingData ) ); channel.position( lengthOf( existingData ) ); byte[] data = UTF8.encode( failure ); channel.writeAll( ByteBuffer.wrap( data, 0, Math.min( data.length, MAX_FAILURE_SIZE ) ) ); channel.force( true ); channel.close(); } }
verify( channel ).force( true ); verify( channel ).close(); verifyNoMoreInteractions( channel );
@After public void verifyInterruptionAndChannelState() throws IOException { assertTrue( Thread.interrupted() ); assertThat( "channelShouldBeClosed? " + channelShouldBeClosed, channel.isOpen(), is( !channelShouldBeClosed ) ); if ( channelShouldBeClosed ) { try { channel.force( true ); fail( "Operating on a closed channel should fail" ); } catch ( ClosedChannelException expected ) { // This is good. What we expect to see. } } channel.close(); fs.close(); }
buffer.flip(); storeChannel.writeAll( buffer ); storeChannel.force( false ); storeChannel.close();
@Test void shouldNotLoseDataForcedBeforeFileSystemCrashes() throws Exception { try ( EphemeralFileSystemAbstraction fs = new EphemeralFileSystemAbstraction() ) { // given int numberOfBytesForced = 8; File aFile = new File( "yo" ); StoreChannel channel = fs.open( aFile, OpenMode.READ_WRITE ); writeLong( channel, 1111 ); // when channel.force( true ); writeLong( channel, 2222 ); fs.crash(); // then StoreChannel readChannel = fs.open( aFile, OpenMode.READ ); assertEquals( numberOfBytesForced, readChannel.size() ); assertEquals( 1111, readLong( readChannel ).getLong() ); } }