Skip to content

Commit

Permalink
Convert IOException to UncheckedIOException for some index related
Browse files Browse the repository at this point in the history
classes to simplify lambda usages.
  • Loading branch information
klaren authored and MishaDemianenko committed Jul 20, 2018
1 parent a3865a3 commit b286cd3
Show file tree
Hide file tree
Showing 48 changed files with 507 additions and 385 deletions.
Expand Up @@ -910,7 +910,7 @@ public class UpdateCapturingIndexAccessor implements IndexAccessor
} }


@Override @Override
public void drop() throws IOException public void drop()
{ {
actual.drop(); actual.drop();
} }
Expand All @@ -927,19 +927,19 @@ private IndexUpdater wrap( IndexUpdater actual )
} }


@Override @Override
public void force( IOLimiter ioLimiter ) throws IOException public void force( IOLimiter ioLimiter )
{ {
actual.force( ioLimiter ); actual.force( ioLimiter );
} }


@Override @Override
public void refresh() throws IOException public void refresh()
{ {
actual.refresh(); actual.refresh();
} }


@Override @Override
public void close() throws IOException public void close()
{ {
actual.close(); actual.close();
} }
Expand All @@ -957,13 +957,13 @@ public BoundedIterable<Long> newAllEntriesReader()
} }


@Override @Override
public ResourceIterator<File> snapshotFiles() throws IOException public ResourceIterator<File> snapshotFiles()
{ {
return actual.snapshotFiles(); return actual.snapshotFiles();
} }


@Override @Override
public void verifyDeferredConstraints( NodePropertyAccessor propertyAccessor ) throws IndexEntryConflictException, IOException public void verifyDeferredConstraints( NodePropertyAccessor propertyAccessor ) throws IndexEntryConflictException
{ {
actual.verifyDeferredConstraints( propertyAccessor ); actual.verifyDeferredConstraints( propertyAccessor );
} }
Expand Down Expand Up @@ -992,14 +992,14 @@ public class UpdateCapturingIndexUpdater implements IndexUpdater
} }


@Override @Override
public void process( IndexEntryUpdate<?> update ) throws IOException, IndexEntryConflictException public void process( IndexEntryUpdate<?> update ) throws IndexEntryConflictException
{ {
actual.process( update ); actual.process( update );
updatesTarget.add( update ); updatesTarget.add( update );
} }


@Override @Override
public void close() throws IOException, IndexEntryConflictException public void close() throws IndexEntryConflictException
{ {
actual.close(); actual.close();
} }
Expand Down
Expand Up @@ -19,7 +19,6 @@
*/ */
package org.neo4j.kernel.impl.api.index; package org.neo4j.kernel.impl.api.index;


import java.io.IOException;
import java.util.concurrent.CountDownLatch; import java.util.concurrent.CountDownLatch;
import java.util.concurrent.atomic.AtomicInteger; import java.util.concurrent.atomic.AtomicInteger;


Expand Down Expand Up @@ -68,7 +67,7 @@ public DoubleLatch installPopulationJobCompletionLatch()
mockedPopulator = new IndexPopulator.Adapter() mockedPopulator = new IndexPopulator.Adapter()
{ {
@Override @Override
public void create() throws IOException public void create()
{ {
populationCompletionLatch.startAndWaitForAllToStartAndFinish(); populationCompletionLatch.startAndWaitForAllToStartAndFinish();
super.create(); super.create();
Expand Down
Expand Up @@ -26,6 +26,7 @@
import java.io.Closeable; import java.io.Closeable;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.io.UncheckedIOException;
import java.nio.ByteBuffer; import java.nio.ByteBuffer;
import java.nio.file.NoSuchFileException; import java.nio.file.NoSuchFileException;
import java.nio.file.StandardOpenOption; import java.nio.file.StandardOpenOption;
Expand Down Expand Up @@ -354,7 +355,7 @@ public void startupState( boolean clean )
* Whether or not this tree has been closed. Accessed and changed solely in * Whether or not this tree has been closed. Accessed and changed solely in
* {@link #close()} to be able to close tree multiple times gracefully. * {@link #close()} to be able to close tree multiple times gracefully.
*/ */
private boolean closed = true; private boolean closed;


/** /**
* True if tree is clean, false if dirty * True if tree is clean, false if dirty
Expand Down Expand Up @@ -438,12 +439,12 @@ public void startupState( boolean clean )
* or {@link #close()} * or {@link #close()}
* @param headerWriter writes header data if indexFile is created as a result of this call. * @param headerWriter writes header data if indexFile is created as a result of this call.
* @param recoveryCleanupWorkCollector collects recovery cleanup jobs for execution after recovery. * @param recoveryCleanupWorkCollector collects recovery cleanup jobs for execution after recovery.
* @throws IOException on page cache error * @throws UncheckedIOException on page cache error
* @throws MetadataMismatchException if meta information does not match constructor parameters or meta page is missing * @throws MetadataMismatchException if meta information does not match constructor parameters or meta page is missing
*/ */
public GBPTree( PageCache pageCache, File indexFile, Layout<KEY,VALUE> layout, int tentativePageSize, public GBPTree( PageCache pageCache, File indexFile, Layout<KEY,VALUE> layout, int tentativePageSize,
Monitor monitor, Header.Reader headerReader, Consumer<PageCursor> headerWriter, Monitor monitor, Header.Reader headerReader, Consumer<PageCursor> headerWriter,
RecoveryCleanupWorkCollector recoveryCleanupWorkCollector ) throws IOException, MetadataMismatchException RecoveryCleanupWorkCollector recoveryCleanupWorkCollector ) throws MetadataMismatchException
{ {
this.indexFile = indexFile; this.indexFile = indexFile;
this.monitor = monitor; this.monitor = monitor;
Expand All @@ -452,7 +453,6 @@ public GBPTree( PageCache pageCache, File indexFile, Layout<KEY,VALUE> layout, i
setRoot( rootId, Generation.unstableGeneration( generation ) ); setRoot( rootId, Generation.unstableGeneration( generation ) );
this.layout = layout; this.layout = layout;


boolean success = false;
try try
{ {
this.pagedFile = openOrCreate( pageCache, indexFile, tentativePageSize ); this.pagedFile = openOrCreate( pageCache, indexFile, tentativePageSize );
Expand Down Expand Up @@ -491,20 +491,31 @@ public GBPTree( PageCache pageCache, File indexFile, Layout<KEY,VALUE> layout, i
bumpUnstableGeneration(); bumpUnstableGeneration();
forceState(); forceState();
cleaning = createCleanupJob( recoveryCleanupWorkCollector, dirtyOnStartup ); cleaning = createCleanupJob( recoveryCleanupWorkCollector, dirtyOnStartup );
success = true;
} }
catch ( Throwable t ) catch ( IOException e )
{ {
appendTreeInformation( t ); throw exitConstructor( new UncheckedIOException( e ) );
throw t;
} }
finally catch ( Throwable e )
{ {
if ( !success ) throw exitConstructor( e );
{ }
close(); }
}
private RuntimeException exitConstructor( Throwable throwable )
{
try
{
close();
}
catch ( IOException e )
{
Exceptions.chain( new UncheckedIOException( e ), throwable );
} }

appendTreeInformation( throwable );
Exceptions.throwIfUnchecked( throwable );
return new RuntimeException( throwable );
} }


private void initializeAfterCreation( Consumer<PageCursor> headerWriter ) throws IOException private void initializeAfterCreation( Consumer<PageCursor> headerWriter ) throws IOException
Expand Down Expand Up @@ -871,24 +882,38 @@ public RawCursor<Hit<KEY,VALUE>,IOException> seek( KEY fromInclusive, KEY toExcl
* *
* @param ioLimiter for controlling I/O usage. * @param ioLimiter for controlling I/O usage.
* @param headerWriter hook for writing header data, must leave cursor at end of written header. * @param headerWriter hook for writing header data, must leave cursor at end of written header.
* @throws IOException on error flushing to storage. * @throws UncheckedIOException on error flushing to storage.
*/ */
public void checkpoint( IOLimiter ioLimiter, Consumer<PageCursor> headerWriter ) throws IOException public void checkpoint( IOLimiter ioLimiter, Consumer<PageCursor> headerWriter )
{ {
checkpoint( ioLimiter, replace( headerWriter ) ); try
{
checkpoint( ioLimiter, replace( headerWriter ) );
}
catch ( IOException e )
{
throw new UncheckedIOException( e );
}
} }


/** /**
* Performs a {@link #checkpoint(IOLimiter, Consumer) check point}, keeping any header information * Performs a {@link #checkpoint(IOLimiter, Consumer) check point}, keeping any header information
* written in previous check point. * written in previous check point.
* *
* @param ioLimiter for controlling I/O usage. * @param ioLimiter for controlling I/O usage.
* @throws IOException on error flushing to storage. * @throws UncheckedIOException on error flushing to storage.
* @see #checkpoint(IOLimiter, Consumer) * @see #checkpoint(IOLimiter, Consumer)
*/ */
public void checkpoint( IOLimiter ioLimiter ) throws IOException public void checkpoint( IOLimiter ioLimiter )
{ {
checkpoint( ioLimiter, CARRY_OVER_PREVIOUS_HEADER ); try
{
checkpoint( ioLimiter, CARRY_OVER_PREVIOUS_HEADER );
}
catch ( IOException e )
{
throw new UncheckedIOException( e );
}
} }


private void checkpoint( IOLimiter ioLimiter, Header.Writer headerWriter ) throws IOException private void checkpoint( IOLimiter ioLimiter, Header.Writer headerWriter ) throws IOException
Expand Down Expand Up @@ -1151,9 +1176,9 @@ public String toString()
stableGeneration( generation ), unstableGeneration( generation ) ); stableGeneration( generation ), unstableGeneration( generation ) );
} }


private <E extends Throwable> E appendTreeInformation( E e ) private <E extends Throwable> void appendTreeInformation( E e )
{ {
return Exceptions.withMessage( e, e.getMessage() + " | " + toString() ); Exceptions.withMessage( e, e.getMessage() + " | " + toString() );
} }


private class SingleWriter implements Writer<KEY,VALUE> private class SingleWriter implements Writer<KEY,VALUE>
Expand Down Expand Up @@ -1231,26 +1256,31 @@ void initialize() throws IOException
} }


@Override @Override
public void put( KEY key, VALUE value ) throws IOException public void put( KEY key, VALUE value )
{ {
merge( key, value, ValueMergers.overwrite() ); merge( key, value, ValueMergers.overwrite() );
} }


@Override @Override
public void merge( KEY key, VALUE value, ValueMerger<KEY,VALUE> valueMerger ) throws IOException public void merge( KEY key, VALUE value, ValueMerger<KEY,VALUE> valueMerger )
{ {
try try
{ {
treeLogic.insert( cursor, structurePropagation, key, value, valueMerger, treeLogic.insert( cursor, structurePropagation, key, value, valueMerger,
stableGeneration, unstableGeneration ); stableGeneration, unstableGeneration );

handleStructureChanges();
} }
catch ( Throwable e ) catch ( IOException e )
{ {
appendTreeInformation( e ); appendTreeInformation( e );
throw e; throw new UncheckedIOException( e );
}
catch ( Throwable t )
{
appendTreeInformation( t );
throw t;
} }

handleStructureChanges();


checkOutOfBounds( cursor ); checkOutOfBounds( cursor );
} }
Expand All @@ -1263,22 +1293,27 @@ private void setRoot( long rootPointer )
} }


@Override @Override
public VALUE remove( KEY key ) throws IOException public VALUE remove( KEY key )
{ {
VALUE result; VALUE result;
try try
{ {
result = treeLogic.remove( cursor, structurePropagation, key, layout.newValue(), result = treeLogic.remove( cursor, structurePropagation, key, layout.newValue(),
stableGeneration, unstableGeneration ); stableGeneration, unstableGeneration );

handleStructureChanges();
}
catch ( IOException e )
{
appendTreeInformation( e );
throw new UncheckedIOException( e );
} }
catch ( Throwable e ) catch ( Throwable e )
{ {
appendTreeInformation( e ); appendTreeInformation( e );
throw e; throw e;
} }


handleStructureChanges();

checkOutOfBounds( cursor ); checkOutOfBounds( cursor );
return result; return result;
} }
Expand Down
Expand Up @@ -20,7 +20,7 @@
package org.neo4j.index.internal.gbptree; package org.neo4j.index.internal.gbptree;


import java.io.Closeable; import java.io.Closeable;
import java.io.IOException; import java.io.UncheckedIOException;


/** /**
* Able to {@link #merge(Object, Object, ValueMerger)} and {@link #remove(Object)} key/value pairs * Able to {@link #merge(Object, Object, ValueMerger)} and {@link #remove(Object)} key/value pairs
Expand All @@ -38,9 +38,9 @@ public interface Writer<KEY,VALUE> extends Closeable
* *
* @param key key to associate with value * @param key key to associate with value
* @param value value to associate with key * @param value value to associate with key
* @throws IOException on index access error. * @throws UncheckedIOException on index access error.
*/ */
void put( KEY key, VALUE value ) throws IOException; void put( KEY key, VALUE value );


/** /**
* If the {@code key} doesn't already exist in the index the {@code key} will be added and the {@code value} * If the {@code key} doesn't already exist in the index the {@code key} will be added and the {@code value}
Expand All @@ -52,16 +52,16 @@ public interface Writer<KEY,VALUE> extends Closeable
* @param key key for which to merge values. * @param key key for which to merge values.
* @param value value to merge with currently associated value for the {@code key}. * @param value value to merge with currently associated value for the {@code key}.
* @param valueMerger {@link ValueMerger} to consult if key already exists. * @param valueMerger {@link ValueMerger} to consult if key already exists.
* @throws IOException on index access error. * @throws UncheckedIOException on index access error.
*/ */
void merge( KEY key, VALUE value, ValueMerger<KEY,VALUE> valueMerger ) throws IOException; void merge( KEY key, VALUE value, ValueMerger<KEY,VALUE> valueMerger );


/** /**
* Removes a key, returning it's associated value, if found. * Removes a key, returning it's associated value, if found.
* *
* @param key key to remove. * @param key key to remove.
* @return value which was associated with the remove key, if found, otherwise {@code null}. * @return value which was associated with the remove key, if found, otherwise {@code null}.
* @throws IOException on index access error. * @throws UncheckedIOException on index access error.
*/ */
VALUE remove( KEY key ) throws IOException; VALUE remove( KEY key );
} }

0 comments on commit b286cd3

Please sign in to comment.