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
public void drop() throws IOException
public void drop()
{
actual.drop();
}
Expand All @@ -927,19 +927,19 @@ private IndexUpdater wrap( IndexUpdater actual )
}

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

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

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

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

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

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

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

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

Expand Down Expand Up @@ -68,7 +67,7 @@ public DoubleLatch installPopulationJobCompletionLatch()
mockedPopulator = new IndexPopulator.Adapter()
{
@Override
public void create() throws IOException
public void create()
{
populationCompletionLatch.startAndWaitForAllToStartAndFinish();
super.create();
Expand Down
Expand Up @@ -26,6 +26,7 @@
import java.io.Closeable;
import java.io.File;
import java.io.IOException;
import java.io.UncheckedIOException;
import java.nio.ByteBuffer;
import java.nio.file.NoSuchFileException;
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
* {@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
Expand Down Expand Up @@ -438,12 +439,12 @@ public void startupState( boolean clean )
* or {@link #close()}
* @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.
* @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
*/
public GBPTree( PageCache pageCache, File indexFile, Layout<KEY,VALUE> layout, int tentativePageSize,
Monitor monitor, Header.Reader headerReader, Consumer<PageCursor> headerWriter,
RecoveryCleanupWorkCollector recoveryCleanupWorkCollector ) throws IOException, MetadataMismatchException
RecoveryCleanupWorkCollector recoveryCleanupWorkCollector ) throws MetadataMismatchException
{
this.indexFile = indexFile;
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 ) );
this.layout = layout;

boolean success = false;
try
{
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();
forceState();
cleaning = createCleanupJob( recoveryCleanupWorkCollector, dirtyOnStartup );
success = true;
}
catch ( Throwable t )
catch ( IOException e )
{
appendTreeInformation( t );
throw t;
throw exitConstructor( new UncheckedIOException( e ) );
}
finally
catch ( Throwable e )
{
if ( !success )
{
close();
}
throw exitConstructor( e );
}
}

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
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 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
* written in previous check point.
*
* @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)
*/
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
Expand Down Expand Up @@ -1151,9 +1176,9 @@ public String toString()
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>
Expand Down Expand Up @@ -1231,26 +1256,31 @@ void initialize() throws IOException
}

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

@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
{
treeLogic.insert( cursor, structurePropagation, key, value, valueMerger,
stableGeneration, unstableGeneration );

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

handleStructureChanges();

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

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

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

handleStructureChanges();

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

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
Expand All @@ -38,9 +38,9 @@ public interface Writer<KEY,VALUE> extends Closeable
*
* @param key key to associate with value
* @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}
Expand All @@ -52,16 +52,16 @@ public interface Writer<KEY,VALUE> extends Closeable
* @param key key for which to merge values.
* @param value value to merge with currently associated value for the {@code key}.
* @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.
*
* @param key key to remove.
* @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.