diff --git a/community/community-it/kernel-it/src/test/java/org/neo4j/kernel/RecoveryIT.java b/community/community-it/kernel-it/src/test/java/org/neo4j/kernel/RecoveryIT.java index 1635ee984ca36..3fa188487ea5e 100644 --- a/community/community-it/kernel-it/src/test/java/org/neo4j/kernel/RecoveryIT.java +++ b/community/community-it/kernel-it/src/test/java/org/neo4j/kernel/RecoveryIT.java @@ -910,7 +910,7 @@ public class UpdateCapturingIndexAccessor implements IndexAccessor } @Override - public void drop() throws IOException + public void drop() { actual.drop(); } @@ -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(); } @@ -957,13 +957,13 @@ public BoundedIterable newAllEntriesReader() } @Override - public ResourceIterator snapshotFiles() throws IOException + public ResourceIterator snapshotFiles() { return actual.snapshotFiles(); } @Override - public void verifyDeferredConstraints( NodePropertyAccessor propertyAccessor ) throws IndexEntryConflictException, IOException + public void verifyDeferredConstraints( NodePropertyAccessor propertyAccessor ) throws IndexEntryConflictException { actual.verifyDeferredConstraints( propertyAccessor ); } @@ -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(); } diff --git a/community/community-it/kernel-it/src/test/java/org/neo4j/kernel/impl/api/index/ControlledPopulationIndexProvider.java b/community/community-it/kernel-it/src/test/java/org/neo4j/kernel/impl/api/index/ControlledPopulationIndexProvider.java index 336285e608e80..e5b40a3c59766 100644 --- a/community/community-it/kernel-it/src/test/java/org/neo4j/kernel/impl/api/index/ControlledPopulationIndexProvider.java +++ b/community/community-it/kernel-it/src/test/java/org/neo4j/kernel/impl/api/index/ControlledPopulationIndexProvider.java @@ -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; @@ -68,7 +67,7 @@ public DoubleLatch installPopulationJobCompletionLatch() mockedPopulator = new IndexPopulator.Adapter() { @Override - public void create() throws IOException + public void create() { populationCompletionLatch.startAndWaitForAllToStartAndFinish(); super.create(); diff --git a/community/index/src/main/java/org/neo4j/index/internal/gbptree/GBPTree.java b/community/index/src/main/java/org/neo4j/index/internal/gbptree/GBPTree.java index 4de8ca31e2ab0..d4da1e3603860 100644 --- a/community/index/src/main/java/org/neo4j/index/internal/gbptree/GBPTree.java +++ b/community/index/src/main/java/org/neo4j/index/internal/gbptree/GBPTree.java @@ -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; @@ -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 @@ -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 layout, int tentativePageSize, Monitor monitor, Header.Reader headerReader, Consumer headerWriter, - RecoveryCleanupWorkCollector recoveryCleanupWorkCollector ) throws IOException, MetadataMismatchException + RecoveryCleanupWorkCollector recoveryCleanupWorkCollector ) throws MetadataMismatchException { this.indexFile = indexFile; this.monitor = monitor; @@ -452,7 +453,6 @@ public GBPTree( PageCache pageCache, File indexFile, Layout layout, i setRoot( rootId, Generation.unstableGeneration( generation ) ); this.layout = layout; - boolean success = false; try { this.pagedFile = openOrCreate( pageCache, indexFile, tentativePageSize ); @@ -491,20 +491,31 @@ public GBPTree( PageCache pageCache, File indexFile, Layout 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 headerWriter ) throws IOException @@ -871,11 +882,18 @@ public RawCursor,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 headerWriter ) throws IOException + public void checkpoint( IOLimiter ioLimiter, Consumer headerWriter ) { - checkpoint( ioLimiter, replace( headerWriter ) ); + try + { + checkpoint( ioLimiter, replace( headerWriter ) ); + } + catch ( IOException e ) + { + throw new UncheckedIOException( e ); + } } /** @@ -883,12 +901,19 @@ public void checkpoint( IOLimiter ioLimiter, Consumer headerWriter ) * 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 @@ -1151,9 +1176,9 @@ public String toString() stableGeneration( generation ), unstableGeneration( generation ) ); } - private E appendTreeInformation( E e ) + private void appendTreeInformation( E e ) { - return Exceptions.withMessage( e, e.getMessage() + " | " + toString() ); + Exceptions.withMessage( e, e.getMessage() + " | " + toString() ); } private class SingleWriter implements Writer @@ -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 valueMerger ) throws IOException + public void merge( KEY key, VALUE value, ValueMerger 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 ); } @@ -1263,13 +1293,20 @@ 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 ) { @@ -1277,8 +1314,6 @@ public VALUE remove( KEY key ) throws IOException throw e; } - handleStructureChanges(); - checkOutOfBounds( cursor ); return result; } diff --git a/community/index/src/main/java/org/neo4j/index/internal/gbptree/Writer.java b/community/index/src/main/java/org/neo4j/index/internal/gbptree/Writer.java index 25040bdc86691..a038ed918f897 100644 --- a/community/index/src/main/java/org/neo4j/index/internal/gbptree/Writer.java +++ b/community/index/src/main/java/org/neo4j/index/internal/gbptree/Writer.java @@ -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 @@ -38,9 +38,9 @@ public interface Writer 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} @@ -52,16 +52,16 @@ public interface Writer 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 valueMerger ) throws IOException; + void merge( KEY key, VALUE value, ValueMerger 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 ); } diff --git a/community/kernel/src/main/java/org/neo4j/kernel/api/index/IndexAccessor.java b/community/kernel/src/main/java/org/neo4j/kernel/api/index/IndexAccessor.java index ec5b44122ad08..79c1b54d0b7b2 100644 --- a/community/kernel/src/main/java/org/neo4j/kernel/api/index/IndexAccessor.java +++ b/community/kernel/src/main/java/org/neo4j/kernel/api/index/IndexAccessor.java @@ -21,7 +21,7 @@ import java.io.Closeable; import java.io.File; -import java.io.IOException; +import java.io.UncheckedIOException; import java.util.Iterator; import org.neo4j.graphdb.ResourceIterator; @@ -47,9 +47,9 @@ public interface IndexAccessor extends Closeable * Deletes this index as well as closes all used external resources. * There will not be any interactions after this call. * - * @throws IOException if unable to drop index. + * @throws UncheckedIOException if unable to drop index. */ - void drop() throws IOException; + void drop(); /** * Return an updater for applying a set of changes to this index. @@ -67,9 +67,9 @@ public interface IndexAccessor extends Closeable * hasn't been forced to disk. * * @param ioLimiter The {@link IOLimiter} to use for implementations living on top of {@link org.neo4j.io.pagecache.PageCache}. - * @throws IOException if there was a problem forcing the state to persistent storage. + * @throws UncheckedIOException if there was a problem forcing the state to persistent storage. */ - void force( IOLimiter ioLimiter ) throws IOException; + void force( IOLimiter ioLimiter ); /** * Refreshes this index, so that {@link #newReader() readers} created after completion of this call @@ -77,18 +77,18 @@ public interface IndexAccessor extends Closeable * w/ {@link IndexUpdateMode#ONLINE}, but not guaranteed for {@link IndexUpdateMode#RECOVERY}. * Therefore this call is complementary for updates that has taken place with {@link IndexUpdateMode#RECOVERY}. * - * @throws IOException if there was a problem refreshing the index. + * @throws UncheckedIOException if there was a problem refreshing the index. */ - void refresh() throws IOException; + void refresh(); /** * Closes this index accessor. There will not be any interactions after this call. * After completion of this call there cannot be any essential state that hasn't been forced to disk. * - * @throws IOException if unable to close index. + * @throws UncheckedIOException if unable to close index. */ @Override - void close() throws IOException; + void close(); /** * @return a new {@link IndexReader} responsible for looking up results in the index. The returned @@ -103,7 +103,7 @@ public interface IndexAccessor extends Closeable * need to remain available until the resource iterator returned here is closed. This is used to duplicate created * indexes across clusters, among other things. */ - ResourceIterator snapshotFiles() throws IOException; + ResourceIterator snapshotFiles(); /** * Verifies that each value in this index is unique. @@ -112,9 +112,9 @@ public interface IndexAccessor extends Closeable * @param nodePropertyAccessor {@link NodePropertyAccessor} for accessing properties from database storage * in the event of conflicting values. * @throws IndexEntryConflictException for first detected uniqueness conflict, if any. - * @throws IOException on error reading from source files. + * @throws UncheckedIOException on error reading from source files. */ - void verifyDeferredConstraints( NodePropertyAccessor nodePropertyAccessor ) throws IndexEntryConflictException, IOException; + void verifyDeferredConstraints( NodePropertyAccessor nodePropertyAccessor ) throws IndexEntryConflictException; /** * @return true if index was not shutdown properly and its internal state is dirty, false otherwise @@ -215,7 +215,7 @@ public Delegator( IndexAccessor delegate ) } @Override - public void drop() throws IOException + public void drop() { delegate.drop(); } @@ -227,19 +227,19 @@ public IndexUpdater newUpdater( IndexUpdateMode mode ) } @Override - public void force( IOLimiter ioLimiter ) throws IOException + public void force( IOLimiter ioLimiter ) { delegate.force( ioLimiter ); } @Override - public void refresh() throws IOException + public void refresh() { delegate.refresh(); } @Override - public void close() throws IOException + public void close() { delegate.close(); } @@ -257,7 +257,7 @@ public BoundedIterable newAllEntriesReader() } @Override - public ResourceIterator snapshotFiles() throws IOException + public ResourceIterator snapshotFiles() { return delegate.snapshotFiles(); } @@ -269,8 +269,7 @@ public String toString() } @Override - public void verifyDeferredConstraints( NodePropertyAccessor nodePropertyAccessor ) - throws IndexEntryConflictException, IOException + public void verifyDeferredConstraints( NodePropertyAccessor nodePropertyAccessor ) throws IndexEntryConflictException { delegate.verifyDeferredConstraints( nodePropertyAccessor ); } diff --git a/community/kernel/src/main/java/org/neo4j/kernel/api/index/IndexPopulator.java b/community/kernel/src/main/java/org/neo4j/kernel/api/index/IndexPopulator.java index 86bdac766b56c..dea5df793bf15 100644 --- a/community/kernel/src/main/java/org/neo4j/kernel/api/index/IndexPopulator.java +++ b/community/kernel/src/main/java/org/neo4j/kernel/api/index/IndexPopulator.java @@ -19,7 +19,7 @@ */ package org.neo4j.kernel.api.index; -import java.io.IOException; +import java.io.UncheckedIOException; import java.util.Collection; import org.neo4j.internal.kernel.api.InternalIndexState; @@ -37,9 +37,9 @@ public interface IndexPopulator /** * Remove all data in the index and paves the way for populating an index. * - * @throws IOException on I/O error. + * @throws UncheckedIOException on I/O error. */ - void create() throws IOException; + void create(); /** * Closes and deletes this index. @@ -59,10 +59,9 @@ public interface IndexPopulator * @throws IndexEntryConflictException if this is a uniqueness index and any of the updates are detected * to violate that constraint. Implementations may choose to not detect in this call, but instead do one efficient * pass over the index in {@link #verifyDeferredConstraints(NodePropertyAccessor)}. - * @throws IOException on I/O error. + * @throws UncheckedIOException on I/O error. */ - void add( Collection> updates ) - throws IndexEntryConflictException, IOException; + void add( Collection> updates ) throws IndexEntryConflictException; /** * Verifies that each value in this index is unique. @@ -72,9 +71,9 @@ void add( Collection> updates ) * @param nodePropertyAccessor {@link NodePropertyAccessor} for accessing properties from database storage * in the event of conflicting values. * @throws IndexEntryConflictException for first detected uniqueness conflict, if any. - * @throws IOException on error reading from source files. + * @throws UncheckedIOException on error reading from source files. */ - void verifyDeferredConstraints( NodePropertyAccessor nodePropertyAccessor ) throws IndexEntryConflictException, IOException; + void verifyDeferredConstraints( NodePropertyAccessor nodePropertyAccessor ) throws IndexEntryConflictException; /** * Return an updater for applying a set of changes to this index, generally this will be a set of changes from a @@ -113,9 +112,9 @@ void add( Collection> updates ) * be marked as {@link InternalIndexState#ONLINE}, otherwise {@code false} where index should be marked as * {@link InternalIndexState#FAILED} and the failure, previously handed to this populator using {@link #markAsFailed(String)} * should be stored and made available for later requests from {@link IndexProvider#getPopulationFailure(StoreIndexDescriptor)}. - * @throws IOException on I/O error. + * @throws UncheckedIOException on I/O error. */ - void close( boolean populationCompletedSuccessfully ) throws IOException; + void close( boolean populationCompletedSuccessfully ); /** * Called then a population failed. The failure string should be stored for future retrieval by @@ -123,9 +122,9 @@ void add( Collection> updates ) * if there was a failure during population. * * @param failure the description of the failure. - * @throws IOException if marking failed. + * @throws UncheckedIOException if marking failed. */ - void markAsFailed( String failure ) throws IOException; + void markAsFailed( String failure ); /** * Add the given {@link IndexEntryUpdate update} to the sampler for this index. @@ -144,7 +143,7 @@ void add( Collection> updates ) class Adapter implements IndexPopulator { @Override - public void create() throws IOException + public void create() { } @@ -165,7 +164,7 @@ public IndexUpdater newPopulatingUpdater( NodePropertyAccessor accessor ) } @Override - public void close( boolean populationCompletedSuccessfully ) throws IOException + public void close( boolean populationCompletedSuccessfully ) { } @@ -186,8 +185,7 @@ public IndexSample sampleResult() } @Override - public void verifyDeferredConstraints( NodePropertyAccessor nodePropertyAccessor ) - throws IndexEntryConflictException, IOException + public void verifyDeferredConstraints( NodePropertyAccessor nodePropertyAccessor ) throws IndexEntryConflictException { } } diff --git a/community/kernel/src/main/java/org/neo4j/kernel/api/index/IndexUpdater.java b/community/kernel/src/main/java/org/neo4j/kernel/api/index/IndexUpdater.java index aa4d33d1f5987..1d8e78f2d3576 100644 --- a/community/kernel/src/main/java/org/neo4j/kernel/api/index/IndexUpdater.java +++ b/community/kernel/src/main/java/org/neo4j/kernel/api/index/IndexUpdater.java @@ -19,8 +19,6 @@ */ package org.neo4j.kernel.api.index; -import java.io.IOException; - import org.neo4j.kernel.api.exceptions.index.IndexEntryConflictException; /** @@ -33,8 +31,8 @@ */ public interface IndexUpdater extends AutoCloseable { - void process( IndexEntryUpdate update ) throws IOException, IndexEntryConflictException; + void process( IndexEntryUpdate update ) throws IndexEntryConflictException; @Override - void close() throws IOException, IndexEntryConflictException; + void close() throws IndexEntryConflictException; } diff --git a/community/kernel/src/main/java/org/neo4j/kernel/impl/api/index/ContractCheckingIndexProxy.java b/community/kernel/src/main/java/org/neo4j/kernel/impl/api/index/ContractCheckingIndexProxy.java index 158e7c66c3fd8..0d27b1782b98b 100644 --- a/community/kernel/src/main/java/org/neo4j/kernel/impl/api/index/ContractCheckingIndexProxy.java +++ b/community/kernel/src/main/java/org/neo4j/kernel/impl/api/index/ContractCheckingIndexProxy.java @@ -99,7 +99,7 @@ public IndexUpdater newUpdater( IndexUpdateMode mode ) return new DelegatingIndexUpdater( super.newUpdater( mode ) ) { @Override - public void close() throws IOException, IndexEntryConflictException + public void close() throws IndexEntryConflictException { try { diff --git a/community/kernel/src/main/java/org/neo4j/kernel/impl/api/index/FlippableIndexProxy.java b/community/kernel/src/main/java/org/neo4j/kernel/impl/api/index/FlippableIndexProxy.java index 898307f69fab3..2d55bc743b70c 100644 --- a/community/kernel/src/main/java/org/neo4j/kernel/impl/api/index/FlippableIndexProxy.java +++ b/community/kernel/src/main/java/org/neo4j/kernel/impl/api/index/FlippableIndexProxy.java @@ -460,7 +460,7 @@ private LockingIndexUpdater( IndexUpdater delegate ) } @Override - public void close() throws IOException, IndexEntryConflictException + public void close() throws IndexEntryConflictException { try { diff --git a/community/kernel/src/main/java/org/neo4j/kernel/impl/api/index/IndexUpdaterMap.java b/community/kernel/src/main/java/org/neo4j/kernel/impl/api/index/IndexUpdaterMap.java index c5db9991fe6ca..48aa5ca99f3dc 100644 --- a/community/kernel/src/main/java/org/neo4j/kernel/impl/api/index/IndexUpdaterMap.java +++ b/community/kernel/src/main/java/org/neo4j/kernel/impl/api/index/IndexUpdaterMap.java @@ -19,7 +19,7 @@ */ package org.neo4j.kernel.impl.api.index; -import java.io.IOException; +import java.io.UncheckedIOException; import java.util.HashMap; import java.util.HashSet; import java.util.Iterator; @@ -83,14 +83,13 @@ public void close() throws UnderlyingStorageException { updater.close(); } - catch ( IOException | IndexEntryConflictException e ) + catch ( UncheckedIOException | IndexEntryConflictException e ) { if ( null == exceptions ) { exceptions = new HashSet<>(); } - exceptions.add( Pair.of( updaterEntry.getKey(), - new UnderlyingStorageException( e ) ) ); + exceptions.add( Pair.of( updaterEntry.getKey(), new UnderlyingStorageException( e ) ) ); } } diff --git a/community/kernel/src/main/java/org/neo4j/kernel/impl/api/index/OnlineIndexProxy.java b/community/kernel/src/main/java/org/neo4j/kernel/impl/api/index/OnlineIndexProxy.java index 80de78cc2d682..196d6d97e5834 100644 --- a/community/kernel/src/main/java/org/neo4j/kernel/impl/api/index/OnlineIndexProxy.java +++ b/community/kernel/src/main/java/org/neo4j/kernel/impl/api/index/OnlineIndexProxy.java @@ -118,14 +118,7 @@ private IndexUpdater updateCountingUpdater( final IndexUpdater indexUpdater ) public void drop() { indexCountsRemover.remove(); - try - { - accessor.drop(); - } - catch ( IOException e ) - { - throw new RuntimeException( "Failed to drop index ", e ); - } + accessor.drop(); } @Override @@ -141,13 +134,13 @@ public InternalIndexState getState() } @Override - public void force( IOLimiter ioLimiter ) throws IOException + public void force( IOLimiter ioLimiter ) { accessor.force( ioLimiter ); } @Override - public void refresh() throws IOException + public void refresh() { accessor.refresh(); } @@ -201,7 +194,7 @@ public PopulationProgress getIndexPopulationProgress() } @Override - public ResourceIterator snapshotFiles() throws IOException + public ResourceIterator snapshotFiles() { return accessor.snapshotFiles(); } @@ -213,8 +206,7 @@ public String toString() } @Override - public void verifyDeferredConstraints( NodePropertyAccessor nodePropertyAccessor ) - throws IndexEntryConflictException, IOException + public void verifyDeferredConstraints( NodePropertyAccessor nodePropertyAccessor ) throws IndexEntryConflictException { accessor.verifyDeferredConstraints( nodePropertyAccessor ); } diff --git a/community/kernel/src/main/java/org/neo4j/kernel/impl/api/index/TentativeConstraintIndexProxy.java b/community/kernel/src/main/java/org/neo4j/kernel/impl/api/index/TentativeConstraintIndexProxy.java index c223f9e4442fa..ec7aeaaa916e1 100644 --- a/community/kernel/src/main/java/org/neo4j/kernel/impl/api/index/TentativeConstraintIndexProxy.java +++ b/community/kernel/src/main/java/org/neo4j/kernel/impl/api/index/TentativeConstraintIndexProxy.java @@ -64,7 +64,7 @@ public class TentativeConstraintIndexProxy extends AbstractDelegatingIndexProxy private final OnlineIndexProxy target; private final Collection failures = new CopyOnWriteArrayList<>(); - public TentativeConstraintIndexProxy( FlippableIndexProxy flipper, OnlineIndexProxy target ) + TentativeConstraintIndexProxy( FlippableIndexProxy flipper, OnlineIndexProxy target ) { this.flipper = flipper; this.target = target; @@ -81,7 +81,6 @@ public IndexUpdater newUpdater( IndexUpdateMode mode ) { @Override public void process( IndexEntryUpdate update ) - throws IOException { try { @@ -94,7 +93,7 @@ public void process( IndexEntryUpdate update ) } @Override - public void close() throws IOException + public void close() { try { diff --git a/community/kernel/src/main/java/org/neo4j/kernel/impl/api/index/updater/DelegatingIndexUpdater.java b/community/kernel/src/main/java/org/neo4j/kernel/impl/api/index/updater/DelegatingIndexUpdater.java index 9b53891cdac6c..d568d5770c966 100644 --- a/community/kernel/src/main/java/org/neo4j/kernel/impl/api/index/updater/DelegatingIndexUpdater.java +++ b/community/kernel/src/main/java/org/neo4j/kernel/impl/api/index/updater/DelegatingIndexUpdater.java @@ -19,8 +19,6 @@ */ package org.neo4j.kernel.impl.api.index.updater; -import java.io.IOException; - import org.neo4j.kernel.api.exceptions.index.IndexEntryConflictException; import org.neo4j.kernel.api.index.IndexEntryUpdate; import org.neo4j.kernel.api.index.IndexUpdater; @@ -35,7 +33,7 @@ public DelegatingIndexUpdater( IndexUpdater delegate ) } @Override - public void process( IndexEntryUpdate update ) throws IOException, IndexEntryConflictException + public void process( IndexEntryUpdate update ) throws IndexEntryConflictException { delegate.process( update ); } diff --git a/community/kernel/src/main/java/org/neo4j/kernel/impl/api/index/updater/UpdateCountingIndexUpdater.java b/community/kernel/src/main/java/org/neo4j/kernel/impl/api/index/updater/UpdateCountingIndexUpdater.java index 3ad768f98beed..4bfd22f518553 100644 --- a/community/kernel/src/main/java/org/neo4j/kernel/impl/api/index/updater/UpdateCountingIndexUpdater.java +++ b/community/kernel/src/main/java/org/neo4j/kernel/impl/api/index/updater/UpdateCountingIndexUpdater.java @@ -19,8 +19,6 @@ */ package org.neo4j.kernel.impl.api.index.updater; -import java.io.IOException; - import org.neo4j.kernel.api.exceptions.index.IndexEntryConflictException; import org.neo4j.kernel.api.index.IndexEntryUpdate; import org.neo4j.kernel.api.index.IndexUpdater; @@ -41,14 +39,14 @@ public UpdateCountingIndexUpdater( IndexStoreView storeView, long indexId, Index } @Override - public void process( IndexEntryUpdate update ) throws IOException, IndexEntryConflictException + public void process( IndexEntryUpdate update ) throws IndexEntryConflictException { delegate.process( update ); updates++; } @Override - public void close() throws IOException, IndexEntryConflictException + public void close() throws IndexEntryConflictException { delegate.close(); storeView.incrementIndexUpdates( indexId, updates ); diff --git a/community/kernel/src/main/java/org/neo4j/kernel/impl/index/labelscan/NativeLabelScanStore.java b/community/kernel/src/main/java/org/neo4j/kernel/impl/index/labelscan/NativeLabelScanStore.java index 3a6e73c44c06f..c6e8fc08452ed 100644 --- a/community/kernel/src/main/java/org/neo4j/kernel/impl/index/labelscan/NativeLabelScanStore.java +++ b/community/kernel/src/main/java/org/neo4j/kernel/impl/index/labelscan/NativeLabelScanStore.java @@ -256,7 +256,7 @@ public void force( IOLimiter limiter ) throws UnderlyingStorageException { index.checkpoint( limiter ); } - catch ( IOException e ) + catch ( UncheckedIOException e ) { throw new UnderlyingStorageException( e ); } diff --git a/community/kernel/src/main/java/org/neo4j/kernel/impl/index/schema/DeferredConflictCheckingIndexUpdater.java b/community/kernel/src/main/java/org/neo4j/kernel/impl/index/schema/DeferredConflictCheckingIndexUpdater.java index cdde83457c86f..d377107b16d7f 100644 --- a/community/kernel/src/main/java/org/neo4j/kernel/impl/index/schema/DeferredConflictCheckingIndexUpdater.java +++ b/community/kernel/src/main/java/org/neo4j/kernel/impl/index/schema/DeferredConflictCheckingIndexUpdater.java @@ -19,7 +19,6 @@ */ package org.neo4j.kernel.impl.index.schema; -import java.io.IOException; import java.util.HashSet; import java.util.Set; import java.util.function.Supplier; @@ -73,7 +72,7 @@ public DeferredConflictCheckingIndexUpdater( IndexUpdater actual, Supplier update ) throws IOException, IndexEntryConflictException + public void process( IndexEntryUpdate update ) throws IndexEntryConflictException { actual.process( update ); if ( update.updateMode() != REMOVED ) @@ -83,7 +82,7 @@ public void process( IndexEntryUpdate update ) throws IOException, IndexEntry } @Override - public void close() throws IOException, IndexEntryConflictException + public void close() throws IndexEntryConflictException { actual.close(); try ( IndexReader reader = readerSupplier.get() ) diff --git a/community/kernel/src/main/java/org/neo4j/kernel/impl/index/schema/NativeIndex.java b/community/kernel/src/main/java/org/neo4j/kernel/impl/index/schema/NativeIndex.java index e6b3af05e1242..74af5d1bf3ace 100644 --- a/community/kernel/src/main/java/org/neo4j/kernel/impl/index/schema/NativeIndex.java +++ b/community/kernel/src/main/java/org/neo4j/kernel/impl/index/schema/NativeIndex.java @@ -22,6 +22,7 @@ import java.io.Closeable; import java.io.File; import java.io.IOException; +import java.io.UncheckedIOException; import java.util.function.Consumer; import org.neo4j.index.internal.gbptree.GBPTree; @@ -59,7 +60,6 @@ abstract class NativeIndex, VALUE extends Native } void instantiateTree( RecoveryCleanupWorkCollector recoveryCleanupWorkCollector, Consumer headerWriter ) - throws IOException { ensureDirectoryExist(); GBPTree.Monitor monitor = treeMonitor(); @@ -71,21 +71,35 @@ private GBPTree.Monitor treeMonitor( ) return new NativeIndexTreeMonitor(); } - private void ensureDirectoryExist() throws IOException + private void ensureDirectoryExist() { - fileSystem.mkdirs( storeFile.getParentFile() ); + try + { + fileSystem.mkdirs( storeFile.getParentFile() ); + } + catch ( IOException e ) + { + throw new UncheckedIOException( e ); + } } - void closeTree() throws IOException + void closeTree() { tree = closeIfPresent( tree ); } - private T closeIfPresent( T closeable ) throws IOException + private static T closeIfPresent( T closeable ) { if ( closeable != null ) { - closeable.close(); + try + { + closeable.close(); + } + catch ( IOException e ) + { + throw new UncheckedIOException( e ); + } } return null; } diff --git a/community/kernel/src/main/java/org/neo4j/kernel/impl/index/schema/NativeIndexAccessor.java b/community/kernel/src/main/java/org/neo4j/kernel/impl/index/schema/NativeIndexAccessor.java index 43d7a76e5d8d9..a2220eb66ffe2 100644 --- a/community/kernel/src/main/java/org/neo4j/kernel/impl/index/schema/NativeIndexAccessor.java +++ b/community/kernel/src/main/java/org/neo4j/kernel/impl/index/schema/NativeIndexAccessor.java @@ -59,10 +59,17 @@ public abstract class NativeIndexAccessor, VALUE } @Override - public void drop() throws IOException + public void drop() { closeTree(); - fileSystem.deleteFileOrThrow( storeFile ); + try + { + fileSystem.deleteFileOrThrow( storeFile ); + } + catch ( IOException e ) + { + throw new UncheckedIOException( e ); + } } @Override @@ -80,7 +87,7 @@ public NativeIndexUpdater newUpdater( IndexUpdateMode mode ) } @Override - public void force( IOLimiter ioLimiter ) throws IOException + public void force( IOLimiter ioLimiter ) { tree.checkpoint( ioLimiter ); } @@ -92,7 +99,7 @@ public void refresh() } @Override - public void close() throws IOException + public void close() { closeTree(); } diff --git a/community/kernel/src/main/java/org/neo4j/kernel/impl/index/schema/NativeIndexPopulator.java b/community/kernel/src/main/java/org/neo4j/kernel/impl/index/schema/NativeIndexPopulator.java index 1a99e7f02fc4b..e663c7b2f950e 100644 --- a/community/kernel/src/main/java/org/neo4j/kernel/impl/index/schema/NativeIndexPopulator.java +++ b/community/kernel/src/main/java/org/neo4j/kernel/impl/index/schema/NativeIndexPopulator.java @@ -107,18 +107,18 @@ public abstract class NativeIndexPopulator, VALU } } - public void clear() throws IOException + public void clear() { deleteFileIfPresent( fileSystem, storeFile ); } @Override - public synchronized void create() throws IOException + public synchronized void create() { create( new NativeIndexHeaderWriter( BYTE_POPULATING ) ); } - protected synchronized void create( Consumer headerWriter ) throws IOException + protected synchronized void create( Consumer headerWriter ) { assertNotDropped(); assertNotClosed(); @@ -144,10 +144,6 @@ public synchronized void drop() closeTree(); deleteFileIfPresent( fileSystem, storeFile ); } - catch ( IOException e ) - { - throw new UncheckedIOException( e ); - } finally { dropped = true; @@ -156,7 +152,7 @@ public synchronized void drop() } @Override - public void add( Collection> updates ) throws IOException, IndexEntryConflictException + public void add( Collection> updates ) throws IndexEntryConflictException { applyWithWorkSync( additionsWorkSync, updates ); } @@ -183,7 +179,7 @@ public void process( IndexEntryUpdate update ) } @Override - public void close() throws IOException, IndexEntryConflictException + public void close() throws IndexEntryConflictException { applyWithWorkSync( updatesWorkSync, updates ); closed = true; @@ -210,7 +206,7 @@ private void assertOpen() abstract IndexReader newReader(); @Override - public synchronized void close( boolean populationCompletedSuccessfully ) throws IOException + public synchronized void close( boolean populationCompletedSuccessfully ) { if ( populationCompletedSuccessfully && failureBytes != null ) { @@ -239,7 +235,7 @@ public synchronized void close( boolean populationCompletedSuccessfully ) throws } private void applyWithWorkSync( WorkSync,IndexUpdateWork> workSync, - Collection> updates ) throws IOException, IndexEntryConflictException + Collection> updates ) throws IndexEntryConflictException { try { @@ -250,13 +246,13 @@ private void applyWithWorkSync( WorkSync,IndexUpdate Throwable cause = e.getCause(); if ( cause instanceof IOException ) { - throw (IOException) cause; + throw new UncheckedIOException( (IOException) cause ); } if ( cause instanceof IndexEntryConflictException ) { throw (IndexEntryConflictException) cause; } - throw new IOException( cause ); + throw new RuntimeException( cause ); } } @@ -282,7 +278,7 @@ public void markAsFailed( String failure ) failureBytes = failure.getBytes( StandardCharsets.UTF_8 ); } - private void ensureTreeInstantiated() throws IOException + private void ensureTreeInstantiated() { if ( tree == null ) { @@ -298,7 +294,7 @@ private void assertPopulatorOpen() } } - private void markTreeAsFailed() throws IOException + private void markTreeAsFailed() { if ( failureBytes == null ) { @@ -307,7 +303,7 @@ private void markTreeAsFailed() throws IOException tree.checkpoint( IOLimiter.UNLIMITED, new FailureHeaderWriter( failureBytes ) ); } - void markTreeAsOnline() throws IOException + void markTreeAsOnline() { tree.checkpoint( IOLimiter.UNLIMITED, pc -> pc.putByte( BYTE_ONLINE ) ); } @@ -431,7 +427,7 @@ public IndexSample sampleResult() } } - private static void deleteFileIfPresent( FileSystemAbstraction fs, File storeFile ) throws IOException + private static void deleteFileIfPresent( FileSystemAbstraction fs, File storeFile ) { try { @@ -441,5 +437,9 @@ private static void deleteFileIfPresent( FileSystemAbstraction fs, File storeFil { // File does not exist, we don't need to delete } + catch ( IOException e ) + { + throw new UncheckedIOException( e ); + } } } diff --git a/community/kernel/src/main/java/org/neo4j/kernel/impl/index/schema/NativeIndexUpdater.java b/community/kernel/src/main/java/org/neo4j/kernel/impl/index/schema/NativeIndexUpdater.java index aff9549a6bbc7..bfa551bf8a3ed 100644 --- a/community/kernel/src/main/java/org/neo4j/kernel/impl/index/schema/NativeIndexUpdater.java +++ b/community/kernel/src/main/java/org/neo4j/kernel/impl/index/schema/NativeIndexUpdater.java @@ -20,6 +20,7 @@ package org.neo4j.kernel.impl.index.schema; import java.io.IOException; +import java.io.UncheckedIOException; import org.neo4j.index.internal.gbptree.Writer; import org.neo4j.kernel.api.exceptions.index.IndexEntryConflictException; @@ -55,17 +56,24 @@ NativeIndexUpdater initialize( Writer writer ) } @Override - public void process( IndexEntryUpdate update ) throws IOException, IndexEntryConflictException + public void process( IndexEntryUpdate update ) throws IndexEntryConflictException { assertOpen(); processUpdate( treeKey, treeValue, update, writer, conflictDetectingValueMerger ); } @Override - public void close() throws IOException + public void close() { - writer.close(); closed = true; + try + { + writer.close(); + } + catch ( IOException e ) + { + throw new UncheckedIOException( e ); + } } private void assertOpen() @@ -78,7 +86,7 @@ private void assertOpen() static , VALUE extends NativeIndexValue> void processUpdate( KEY treeKey, VALUE treeValue, IndexEntryUpdate update, Writer writer, ConflictDetectingValueMerger conflictDetectingValueMerger ) - throws IOException, IndexEntryConflictException + throws IndexEntryConflictException { switch ( update.updateMode() ) { @@ -97,7 +105,7 @@ static , VALUE extends NativeIndexValue> void pr } private static , VALUE extends NativeIndexValue> void processRemove( KEY treeKey, - IndexEntryUpdate update, Writer writer ) throws IOException + IndexEntryUpdate update, Writer writer ) { // todo Do we need to verify that we actually removed something at all? // todo Difference between online and recovery? @@ -108,7 +116,7 @@ private static , VALUE extends NativeIndexValue> private static , VALUE extends NativeIndexValue> void processChange( KEY treeKey, VALUE treeValue, IndexEntryUpdate update, Writer writer, ConflictDetectingValueMerger conflictDetectingValueMerger ) - throws IOException, IndexEntryConflictException + throws IndexEntryConflictException { // Remove old entry treeKey.from( update.getEntityId(), update.beforeValues() ); @@ -121,10 +129,9 @@ private static , VALUE extends NativeIndexValue> conflictDetectingValueMerger.checkConflict( update.values() ); } - static , VALUE extends NativeIndexValue> void processAdd( KEY treeKey, VALUE treeValue, - IndexEntryUpdate update, Writer writer, - ConflictDetectingValueMerger conflictDetectingValueMerger ) - throws IOException, IndexEntryConflictException + private static , VALUE extends NativeIndexValue> void processAdd( KEY treeKey, VALUE treeValue, IndexEntryUpdate update, + Writer writer, ConflictDetectingValueMerger conflictDetectingValueMerger ) + throws IndexEntryConflictException { treeKey.from( update.getEntityId(), update.values() ); treeValue.from( update.values() ); diff --git a/community/kernel/src/main/java/org/neo4j/kernel/impl/index/schema/SpatialIndexAccessor.java b/community/kernel/src/main/java/org/neo4j/kernel/impl/index/schema/SpatialIndexAccessor.java index c2d7ec66219a8..54cad84438a98 100644 --- a/community/kernel/src/main/java/org/neo4j/kernel/impl/index/schema/SpatialIndexAccessor.java +++ b/community/kernel/src/main/java/org/neo4j/kernel/impl/index/schema/SpatialIndexAccessor.java @@ -75,7 +75,7 @@ class SpatialIndexAccessor extends SpatialIndexCache update ) throws IOException, IndexEntryConflictException + public void process( IndexEntryUpdate update ) throws IndexEntryConflictException { PointValue value = (PointValue) update.values()[0]; switch ( update.updateMode() ) @@ -74,7 +72,7 @@ public void process( IndexEntryUpdate update ) throws IOException, IndexEntry } @Override - public void close() throws IOException, IndexEntryConflictException + public void close() throws IndexEntryConflictException { for ( IndexUpdater updater : this ) { @@ -94,7 +92,7 @@ static class PartFactory implements Factory } @Override - public IndexUpdater newSpatial( CoordinateReferenceSystem crs ) throws IOException + public IndexUpdater newSpatial( CoordinateReferenceSystem crs ) { return populator.select( crs ).newPopulatingUpdater( nodePropertyAccessor ); } diff --git a/community/kernel/src/main/java/org/neo4j/kernel/impl/index/schema/SpatialIndexPopulator.java b/community/kernel/src/main/java/org/neo4j/kernel/impl/index/schema/SpatialIndexPopulator.java index c6022c68ee33a..378ffc1dc3491 100644 --- a/community/kernel/src/main/java/org/neo4j/kernel/impl/index/schema/SpatialIndexPopulator.java +++ b/community/kernel/src/main/java/org/neo4j/kernel/impl/index/schema/SpatialIndexPopulator.java @@ -19,7 +19,6 @@ */ package org.neo4j.kernel.impl.index.schema; -import java.io.IOException; import java.util.ArrayList; import java.util.Collection; import java.util.HashMap; @@ -57,7 +56,7 @@ class SpatialIndexPopulator extends SpatialIndexCache> updates ) throws IOException, IndexEntryConflictException + public void add( Collection> updates ) throws IndexEntryConflictException { Map>> batchMap = new HashMap<>(); for ( IndexEntryUpdate update : updates ) @@ -94,7 +93,6 @@ public void add( Collection> updates ) throws IOEx @Override public void verifyDeferredConstraints( NodePropertyAccessor nodePropertyAccessor ) - throws IndexEntryConflictException, IOException { // No-op, uniqueness is checked for each update in add(IndexEntryUpdate) } @@ -106,7 +104,7 @@ public IndexUpdater newPopulatingUpdater( NodePropertyAccessor accessor ) } @Override - public synchronized void close( boolean populationCompletedSuccessfully ) throws IOException + public synchronized void close( boolean populationCompletedSuccessfully ) { closeInstantiateCloseLock(); for ( NativeIndexPopulator part : this ) @@ -163,13 +161,13 @@ IndexReader newReader() } @Override - public synchronized void create() throws IOException + public synchronized void create() { create( settings.headerWriter( BYTE_POPULATING ) ); } @Override - void markTreeAsOnline() throws IOException + void markTreeAsOnline() { tree.checkpoint( IOLimiter.UNLIMITED, settings.headerWriter( BYTE_ONLINE ) ); } @@ -198,12 +196,12 @@ static class PartFactory implements Factory } @Override - public PartPopulator newSpatial( CoordinateReferenceSystem crs ) throws IOException + public PartPopulator newSpatial( CoordinateReferenceSystem crs ) { return create( spatialIndexFiles.forCrs( crs ).getLayoutForNewIndex() ); } - private PartPopulator create( SpatialIndexFiles.SpatialFileLayout fileLayout ) throws IOException + private PartPopulator create( SpatialIndexFiles.SpatialFileLayout fileLayout ) { PartPopulator populator = new PartPopulator( pageCache, fs, fileLayout, monitor, descriptor, samplingConfig, configuration ); populator.create(); diff --git a/community/kernel/src/main/java/org/neo4j/kernel/impl/index/schema/SpatialIndexUpdater.java b/community/kernel/src/main/java/org/neo4j/kernel/impl/index/schema/SpatialIndexUpdater.java index 55985720625b3..23bd578e8faa0 100644 --- a/community/kernel/src/main/java/org/neo4j/kernel/impl/index/schema/SpatialIndexUpdater.java +++ b/community/kernel/src/main/java/org/neo4j/kernel/impl/index/schema/SpatialIndexUpdater.java @@ -19,8 +19,6 @@ */ package org.neo4j.kernel.impl.index.schema; -import java.io.IOException; - import org.neo4j.kernel.api.exceptions.index.IndexEntryConflictException; import org.neo4j.kernel.api.index.IndexEntryUpdate; import org.neo4j.kernel.api.index.IndexUpdater; @@ -38,7 +36,7 @@ public class SpatialIndexUpdater extends SpatialIndexCache update ) throws IOException, IndexEntryConflictException + public void process( IndexEntryUpdate update ) throws IndexEntryConflictException { IndexUpdater to = select( ((PointValue)update.values()[0]).getCoordinateReferenceSystem() ); switch ( update.updateMode() ) @@ -68,7 +66,7 @@ public void process( IndexEntryUpdate update ) throws IOException, IndexEntry } @Override - public void close() throws IOException + public void close() { forAll( NativeIndexUpdater::close, this ); } @@ -86,7 +84,7 @@ static class PartFactory implements Factory newSpatial( CoordinateReferenceSystem crs ) throws IOException + public NativeIndexUpdater newSpatial( CoordinateReferenceSystem crs ) { return accessor.select( crs ).newUpdater( mode ); } diff --git a/community/kernel/src/main/java/org/neo4j/kernel/impl/index/schema/TemporalIndexAccessor.java b/community/kernel/src/main/java/org/neo4j/kernel/impl/index/schema/TemporalIndexAccessor.java index 2af760f9ce5c6..82a730586f545 100644 --- a/community/kernel/src/main/java/org/neo4j/kernel/impl/index/schema/TemporalIndexAccessor.java +++ b/community/kernel/src/main/java/org/neo4j/kernel/impl/index/schema/TemporalIndexAccessor.java @@ -62,7 +62,7 @@ class TemporalIndexAccessor extends TemporalIndexCache update ) throws IOException, IndexEntryConflictException + public void process( IndexEntryUpdate update ) throws IndexEntryConflictException { switch ( update.updateMode() ) { @@ -71,7 +71,7 @@ public void process( IndexEntryUpdate update ) throws IOException, IndexEntry } @Override - public void close() throws IOException, IndexEntryConflictException + public void close() throws IndexEntryConflictException { for ( IndexUpdater part : this ) { diff --git a/community/kernel/src/main/java/org/neo4j/kernel/impl/index/schema/TemporalIndexPopulator.java b/community/kernel/src/main/java/org/neo4j/kernel/impl/index/schema/TemporalIndexPopulator.java index 38d67f53e13fe..9daaa02bd5e41 100644 --- a/community/kernel/src/main/java/org/neo4j/kernel/impl/index/schema/TemporalIndexPopulator.java +++ b/community/kernel/src/main/java/org/neo4j/kernel/impl/index/schema/TemporalIndexPopulator.java @@ -19,7 +19,6 @@ */ package org.neo4j.kernel.impl.index.schema; -import java.io.IOException; import java.util.ArrayList; import java.util.Collection; import java.util.HashMap; @@ -53,7 +52,7 @@ class TemporalIndexPopulator extends TemporalIndexCache> updates ) throws IndexEntryConflictException, IOException + public void add( Collection> updates ) throws IndexEntryConflictException { Map>> batchMap = new HashMap<>(); for ( IndexEntryUpdate update : updates ) @@ -89,7 +88,6 @@ public void add( Collection> updates ) throws Inde @Override public void verifyDeferredConstraints( NodePropertyAccessor nodePropertyAccessor ) - throws IndexEntryConflictException, IOException { // No-op, uniqueness is checked for each update in add(IndexEntryUpdate) } @@ -101,7 +99,7 @@ public IndexUpdater newPopulatingUpdater( NodePropertyAccessor accessor ) } @Override - public synchronized void close( boolean populationCompletedSuccessfully ) throws IOException + public synchronized void close( boolean populationCompletedSuccessfully ) { closeInstantiateCloseLock(); for ( NativeIndexPopulator part : this ) @@ -174,42 +172,42 @@ static class PartFactory implements TemporalIndexCache.Factory> } @Override - public PartPopulator newDate() throws IOException + public PartPopulator newDate() { return create( temporalIndexFiles.date() ); } @Override - public PartPopulator newLocalDateTime() throws IOException + public PartPopulator newLocalDateTime() { return create( temporalIndexFiles.localDateTime() ); } @Override - public PartPopulator newZonedDateTime() throws IOException + public PartPopulator newZonedDateTime() { return create( temporalIndexFiles.zonedDateTime() ); } @Override - public PartPopulator newLocalTime() throws IOException + public PartPopulator newLocalTime() { return create( temporalIndexFiles.localTime() ); } @Override - public PartPopulator newZonedTime() throws IOException + public PartPopulator newZonedTime() { return create( temporalIndexFiles.zonedTime() ); } @Override - public PartPopulator newDuration() throws IOException + public PartPopulator newDuration() { return create( temporalIndexFiles.duration() ); } - private > PartPopulator create( TemporalIndexFiles.FileLayout fileLayout ) throws IOException + private > PartPopulator create( TemporalIndexFiles.FileLayout fileLayout ) { PartPopulator populator = new PartPopulator<>( pageCache, fs, fileLayout, monitor, descriptor, samplingConfig ); populator.create(); diff --git a/community/kernel/src/main/java/org/neo4j/kernel/impl/index/schema/TemporalIndexUpdater.java b/community/kernel/src/main/java/org/neo4j/kernel/impl/index/schema/TemporalIndexUpdater.java index c9fffd610428e..7911ff1611796 100644 --- a/community/kernel/src/main/java/org/neo4j/kernel/impl/index/schema/TemporalIndexUpdater.java +++ b/community/kernel/src/main/java/org/neo4j/kernel/impl/index/schema/TemporalIndexUpdater.java @@ -19,8 +19,6 @@ */ package org.neo4j.kernel.impl.index.schema; -import java.io.IOException; - import org.neo4j.kernel.api.exceptions.index.IndexEntryConflictException; import org.neo4j.kernel.api.index.IndexEntryUpdate; import org.neo4j.kernel.api.index.IndexUpdater; @@ -37,7 +35,7 @@ public class TemporalIndexUpdater extends TemporalIndexCache update ) throws IOException, IndexEntryConflictException + public void process( IndexEntryUpdate update ) throws IndexEntryConflictException { IndexUpdater to = select( update.values()[0].valueGroup() ); switch ( update.updateMode() ) @@ -67,7 +65,7 @@ public void process( IndexEntryUpdate update ) throws IOException, IndexEntry } @Override - public void close() throws IOException + public void close() { forAll( NativeIndexUpdater::close, this ); } @@ -85,37 +83,37 @@ static class PartFactory implements TemporalIndexCache.Factory newDate() throws IOException + public NativeIndexUpdater newDate() { return accessor.select( ValueGroup.DATE ).newUpdater( mode ); } @Override - public NativeIndexUpdater newLocalDateTime() throws IOException + public NativeIndexUpdater newLocalDateTime() { return accessor.select(ValueGroup.LOCAL_DATE_TIME).newUpdater( mode ); } @Override - public NativeIndexUpdater newZonedDateTime() throws IOException + public NativeIndexUpdater newZonedDateTime() { return accessor.select(ValueGroup.ZONED_DATE_TIME).newUpdater( mode ); } @Override - public NativeIndexUpdater newLocalTime() throws IOException + public NativeIndexUpdater newLocalTime() { return accessor.select(ValueGroup.LOCAL_TIME).newUpdater( mode ); } @Override - public NativeIndexUpdater newZonedTime() throws IOException + public NativeIndexUpdater newZonedTime() { return accessor.select(ValueGroup.ZONED_TIME).newUpdater( mode ); } @Override - public NativeIndexUpdater newDuration() throws IOException + public NativeIndexUpdater newDuration() { return accessor.select(ValueGroup.DURATION).newUpdater( mode ); } diff --git a/community/kernel/src/main/java/org/neo4j/kernel/impl/index/schema/fusion/FusionIndexAccessor.java b/community/kernel/src/main/java/org/neo4j/kernel/impl/index/schema/fusion/FusionIndexAccessor.java index 83c7fec976692..c47299dd87798 100644 --- a/community/kernel/src/main/java/org/neo4j/kernel/impl/index/schema/fusion/FusionIndexAccessor.java +++ b/community/kernel/src/main/java/org/neo4j/kernel/impl/index/schema/fusion/FusionIndexAccessor.java @@ -20,7 +20,6 @@ package org.neo4j.kernel.impl.index.schema.fusion; import java.io.File; -import java.io.IOException; import java.util.Iterator; import org.neo4j.graphdb.ResourceIterator; @@ -55,7 +54,7 @@ class FusionIndexAccessor extends FusionIndexBase implements Inde } @Override - public void drop() throws IOException + public void drop() { instanceSelector.forAll( IndexAccessor::drop ); dropAction.drop( descriptor.getId() ); @@ -69,19 +68,19 @@ public IndexUpdater newUpdater( IndexUpdateMode mode ) } @Override - public void force( IOLimiter ioLimiter ) throws IOException + public void force( IOLimiter ioLimiter ) { instanceSelector.forAll( accessor -> accessor.force( ioLimiter ) ); } @Override - public void refresh() throws IOException + public void refresh() { instanceSelector.forAll( IndexAccessor::refresh ); } @Override - public void close() throws IOException + public void close() { instanceSelector.close( IndexAccessor::close ); } @@ -131,14 +130,13 @@ public Iterator iterator() } @Override - public ResourceIterator snapshotFiles() throws IOException + public ResourceIterator snapshotFiles() { return concatResourceIterators( instanceSelector.transform( IndexAccessor::snapshotFiles ).iterator() ); } @Override - public void verifyDeferredConstraints( NodePropertyAccessor nodePropertyAccessor ) - throws IndexEntryConflictException, IOException + public void verifyDeferredConstraints( NodePropertyAccessor nodePropertyAccessor ) throws IndexEntryConflictException { for ( IndexSlot slot : IndexSlot.values() ) { diff --git a/community/kernel/src/main/java/org/neo4j/kernel/impl/index/schema/fusion/FusionIndexPopulator.java b/community/kernel/src/main/java/org/neo4j/kernel/impl/index/schema/fusion/FusionIndexPopulator.java index d9ce8321daec6..7eb545f67765c 100644 --- a/community/kernel/src/main/java/org/neo4j/kernel/impl/index/schema/fusion/FusionIndexPopulator.java +++ b/community/kernel/src/main/java/org/neo4j/kernel/impl/index/schema/fusion/FusionIndexPopulator.java @@ -19,7 +19,6 @@ */ package org.neo4j.kernel.impl.index.schema.fusion; -import java.io.IOException; import java.util.ArrayList; import java.util.Collection; @@ -49,7 +48,7 @@ class FusionIndexPopulator extends FusionIndexBase implements In } @Override - public void create() throws IOException + public void create() { dropAction.drop( indexId, archiveFailedIndex ); instanceSelector.forAll( IndexPopulator::create ); @@ -63,7 +62,7 @@ public void drop() } @Override - public void add( Collection> updates ) throws IndexEntryConflictException, IOException + public void add( Collection> updates ) throws IndexEntryConflictException { LazyInstanceSelector>> batchSelector = new LazyInstanceSelector<>( slot -> new ArrayList<>() ); for ( IndexEntryUpdate update : updates ) @@ -83,8 +82,7 @@ public void add( Collection> updates ) throws Inde } @Override - public void verifyDeferredConstraints( NodePropertyAccessor nodePropertyAccessor ) - throws IndexEntryConflictException, IOException + public void verifyDeferredConstraints( NodePropertyAccessor nodePropertyAccessor ) throws IndexEntryConflictException { // Manual loop due do multiple exception types for ( IndexSlot slot : IndexSlot.values() ) @@ -102,13 +100,13 @@ public IndexUpdater newPopulatingUpdater( NodePropertyAccessor accessor ) } @Override - public void close( boolean populationCompletedSuccessfully ) throws IOException + public void close( boolean populationCompletedSuccessfully ) { instanceSelector.close( populator -> populator.close( populationCompletedSuccessfully ) ); } @Override - public void markAsFailed( String failure ) throws IOException + public void markAsFailed( String failure ) { instanceSelector.forAll( populator -> populator.markAsFailed( failure ) ); } diff --git a/community/kernel/src/main/java/org/neo4j/kernel/impl/index/schema/fusion/FusionIndexUpdater.java b/community/kernel/src/main/java/org/neo4j/kernel/impl/index/schema/fusion/FusionIndexUpdater.java index 726e015c8e31c..6a0fb90a5a621 100644 --- a/community/kernel/src/main/java/org/neo4j/kernel/impl/index/schema/fusion/FusionIndexUpdater.java +++ b/community/kernel/src/main/java/org/neo4j/kernel/impl/index/schema/fusion/FusionIndexUpdater.java @@ -19,7 +19,7 @@ */ package org.neo4j.kernel.impl.index.schema.fusion; -import java.io.IOException; +import java.util.concurrent.atomic.AtomicReference; import org.neo4j.kernel.api.exceptions.index.IndexEntryConflictException; import org.neo4j.kernel.api.index.IndexEntryUpdate; @@ -33,7 +33,7 @@ class FusionIndexUpdater extends FusionIndexBase implements IndexU } @Override - public void process( IndexEntryUpdate update ) throws IOException, IndexEntryConflictException + public void process( IndexEntryUpdate update ) throws IndexEntryConflictException { switch ( update.updateMode() ) { @@ -68,20 +68,28 @@ public void process( IndexEntryUpdate update ) throws IOException, IndexEntry } @Override - public void close() throws IOException, IndexEntryConflictException + public void close() throws IndexEntryConflictException { - try - { - instanceSelector.close( IndexUpdater::close ); - } - catch ( IOException | IndexEntryConflictException | RuntimeException e ) + AtomicReference chainedExceptions = new AtomicReference<>(); + + instanceSelector.close( indexUpdater -> { - throw e; - } - catch ( Exception e ) + try + { + indexUpdater.close(); + } + catch ( IndexEntryConflictException e ) + { + if ( !chainedExceptions.compareAndSet( null, e ) ) + { + chainedExceptions.get().addSuppressed( e ); + } + } + } ); + + if ( chainedExceptions.get() != null ) { - // This catch-clause is basically only here to satisfy the compiler - throw new RuntimeException( e ); + throw chainedExceptions.get(); } } } diff --git a/community/kernel/src/main/java/org/neo4j/kernel/impl/index/schema/fusion/InstanceSelector.java b/community/kernel/src/main/java/org/neo4j/kernel/impl/index/schema/fusion/InstanceSelector.java index e58fce09b734c..5df3e865f44c8 100644 --- a/community/kernel/src/main/java/org/neo4j/kernel/impl/index/schema/fusion/InstanceSelector.java +++ b/community/kernel/src/main/java/org/neo4j/kernel/impl/index/schema/fusion/InstanceSelector.java @@ -22,6 +22,7 @@ import java.util.ArrayList; import java.util.EnumMap; import java.util.List; +import java.util.function.Consumer; import org.neo4j.function.ThrowingConsumer; import org.neo4j.function.ThrowingFunction; @@ -124,12 +125,10 @@ Iterable transform( ThrowingFunction converter * Convenience method for doing something to all instances, even those that haven't already been instantiated. * * @param consumer {@link ThrowingConsumer} which performs some action on an instance. - * @param type of exception the action may throw. - * @throws E exception from action. */ - void forAll( ThrowingConsumer consumer ) throws E + void forAll( Consumer consumer ) { - E exception = null; + RuntimeException exception = null; for ( IndexSlot slot : IndexSlot.values() ) { exception = consumeAndChainException( select( slot ), consumer, exception ); @@ -144,10 +143,8 @@ void forAll( ThrowingConsumer consumer ) throws E * Perform a final action on instantiated instances and then closes this selector, preventing further instantiation. * * @param consumer {@link ThrowingConsumer} which performs some action on an instance. - * @param type of exception the action may throw. - * @throws E exception from action. */ - void close( ThrowingConsumer consumer ) throws E + void close( Consumer consumer ) { if ( !closed ) { @@ -172,12 +169,10 @@ public String toString() * Convenience method for doing something to already instantiated instances. * * @param consumer {@link ThrowingConsumer} which performs some action on an instance. - * @param type of exception the action may throw. - * @throws E exception from action. */ - private void forInstantiated( ThrowingConsumer consumer ) throws E + private void forInstantiated( Consumer consumer ) { - E exception = null; + RuntimeException exception = null; for ( T instance : instances.values() ) { if ( instance != null ) @@ -191,15 +186,15 @@ private void forInstantiated( ThrowingConsumer consum } } - private E consumeAndChainException( T instance, ThrowingConsumer consumer, E exception ) + private RuntimeException consumeAndChainException( T instance, Consumer consumer, RuntimeException exception ) { try { consumer.accept( instance ); } - catch ( Exception e ) + catch ( RuntimeException e ) { - exception = Exceptions.chain( exception, (E) e ); + exception = Exceptions.chain( exception, e ); } return exception; } diff --git a/community/kernel/src/main/java/org/neo4j/kernel/impl/newapi/Read.java b/community/kernel/src/main/java/org/neo4j/kernel/impl/newapi/Read.java index 2c6faf2904302..42950bfce724e 100644 --- a/community/kernel/src/main/java/org/neo4j/kernel/impl/newapi/Read.java +++ b/community/kernel/src/main/java/org/neo4j/kernel/impl/newapi/Read.java @@ -654,7 +654,7 @@ private void assertIndexOnline( IndexReference index ) } } - private void assertPredicatesMatchSchema( IndexReference index, IndexQuery.ExactPredicate[] predicates ) + private static void assertPredicatesMatchSchema( IndexReference index, IndexQuery.ExactPredicate[] predicates ) throws IndexNotApplicableKernelException { int[] propertyIds = index.properties(); diff --git a/community/kernel/src/main/java/org/neo4j/unsafe/batchinsert/internal/BatchInserterImpl.java b/community/kernel/src/main/java/org/neo4j/unsafe/batchinsert/internal/BatchInserterImpl.java index b863a08aaa1f6..e17b81cfa8d47 100644 --- a/community/kernel/src/main/java/org/neo4j/unsafe/batchinsert/internal/BatchInserterImpl.java +++ b/community/kernel/src/main/java/org/neo4j/unsafe/batchinsert/internal/BatchInserterImpl.java @@ -351,7 +351,7 @@ private StoreLocker tryLockStore( FileSystemAbstraction fileSystem ) return storeLocker; } - private Map getDefaultParams() + private static Map getDefaultParams() { Map params = new HashMap<>(); params.put( GraphDatabaseSettings.pagecache_memory.name(), "32m" ); @@ -619,7 +619,7 @@ private StoreIndexDescriptor[] getIndexesNeedingPopulation() indexesNeedingPopulation.add( rule ); } } - return indexesNeedingPopulation.toArray( new StoreIndexDescriptor[indexesNeedingPopulation.size()] ); + return indexesNeedingPopulation.toArray( new StoreIndexDescriptor[0] ); } @Override @@ -714,7 +714,7 @@ private boolean primitiveHasProperty( PrimitiveRecord record, String propertyNam recordAccess.getPropertyRecords(), false ) != Record.NO_NEXT_PROPERTY.intValue(); } - private void rejectAutoUpgrade( Map params ) + private static void rejectAutoUpgrade( Map params ) { if ( parseBoolean( params.get( GraphDatabaseSettings.allow_upgrade.name() ) ) ) { @@ -788,7 +788,7 @@ private long[] getOrCreateLabelIds( Label[] labels ) return ids; } - private boolean arrayContains( long[] ids, int cursor, int labelId ) + private static boolean arrayContains( long[] ids, int cursor, int labelId ) { for ( int i = 0; i < cursor; i++ ) { @@ -1119,7 +1119,7 @@ public IdGeneratorFactory getIdGeneratorFactory() return idGeneratorFactory; } - private void dumpConfiguration( Map config, PrintStream out ) + private static void dumpConfiguration( Map config, PrintStream out ) { for ( Entry entry : config.entrySet() ) { @@ -1327,7 +1327,7 @@ public IndexDescriptor index() return index; } - public void add( IndexEntryUpdate update ) throws IndexEntryConflictException, IOException + public void add( IndexEntryUpdate update ) throws IndexEntryConflictException { batchedUpdates.add( update ); if ( batchedUpdates.size() > batchSize ) @@ -1338,8 +1338,7 @@ public void add( IndexEntryUpdate update ) throws IndexEntryConflictException } @Override - public void verifyDeferredConstraints( NodePropertyAccessor nodePropertyAccessor ) - throws IndexEntryConflictException, IOException + public void verifyDeferredConstraints( NodePropertyAccessor nodePropertyAccessor ) throws IndexEntryConflictException { populator.add( batchedUpdates ); populator.verifyDeferredConstraints( nodePropertyAccessor ); @@ -1352,7 +1351,7 @@ public void close() throws IOException } @Override - public void close( boolean populationCompletedSuccessfully ) throws IOException + public void close( boolean populationCompletedSuccessfully ) { if ( !closed ) { diff --git a/community/kernel/src/test/java/org/neo4j/kernel/impl/index/schema/SpatialIndexCacheTest.java b/community/kernel/src/test/java/org/neo4j/kernel/impl/index/schema/SpatialIndexCacheTest.java index dd1ce5b0427e5..22e04e28195e2 100644 --- a/community/kernel/src/test/java/org/neo4j/kernel/impl/index/schema/SpatialIndexCacheTest.java +++ b/community/kernel/src/test/java/org/neo4j/kernel/impl/index/schema/SpatialIndexCacheTest.java @@ -22,8 +22,6 @@ import org.apache.commons.lang3.mutable.MutableInt; import org.junit.Test; -import java.io.IOException; -import java.io.UncheckedIOException; import java.util.Random; import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; @@ -143,15 +141,9 @@ public void run() private void stress() { - try - { - // select - cache.select( coordinateReferenceSystems[random.nextInt( coordinateReferenceSystems.length )] ); - } - catch ( IOException e ) - { - throw new UncheckedIOException( e ); - } + // select + cache.select( coordinateReferenceSystems[random.nextInt( coordinateReferenceSystems.length )] ); + // iterate for ( String s : cache ) { diff --git a/community/kernel/src/test/java/org/neo4j/kernel/impl/index/schema/TemporalIndexCacheTest.java b/community/kernel/src/test/java/org/neo4j/kernel/impl/index/schema/TemporalIndexCacheTest.java index 666ad25bc9f28..19d8e538b29f7 100644 --- a/community/kernel/src/test/java/org/neo4j/kernel/impl/index/schema/TemporalIndexCacheTest.java +++ b/community/kernel/src/test/java/org/neo4j/kernel/impl/index/schema/TemporalIndexCacheTest.java @@ -22,8 +22,6 @@ import org.apache.commons.lang3.mutable.MutableInt; import org.junit.Test; -import java.io.IOException; -import java.io.UncheckedIOException; import java.util.Random; import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; @@ -173,15 +171,9 @@ public void run() private void stress() { - try - { - // select - cache.select( valueGroups[r.nextInt( valueGroups.length )] ); - } - catch ( IOException e ) - { - throw new UncheckedIOException( e ); - } + // select + cache.select( valueGroups[r.nextInt( valueGroups.length )] ); + // iterate for ( String s : cache ) { diff --git a/community/kernel/src/test/java/org/neo4j/kernel/impl/index/schema/fusion/FusionIndexAccessorTest.java b/community/kernel/src/test/java/org/neo4j/kernel/impl/index/schema/fusion/FusionIndexAccessorTest.java index e130564535e3b..4e26e5b6e0f7c 100644 --- a/community/kernel/src/test/java/org/neo4j/kernel/impl/index/schema/fusion/FusionIndexAccessorTest.java +++ b/community/kernel/src/test/java/org/neo4j/kernel/impl/index/schema/fusion/FusionIndexAccessorTest.java @@ -27,6 +27,7 @@ import org.mockito.ArgumentMatchers; import java.io.IOException; +import java.io.UncheckedIOException; import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; @@ -197,14 +198,14 @@ public void fusionIndexIsDirtyWhenAnyIsDirty() private void verifyFailOnSingleDropFailure( IndexAccessor failingAccessor, FusionIndexAccessor fusionIndexAccessor ) throws IOException { - IOException expectedFailure = new IOException( "fail" ); + UncheckedIOException expectedFailure = new UncheckedIOException( new IOException( "fail" ) ); doThrow( expectedFailure ).when( failingAccessor ).drop(); try { fusionIndexAccessor.drop(); fail( "Should have failed" ); } - catch ( IOException e ) + catch ( UncheckedIOException e ) { assertSame( expectedFailure, e ); } @@ -215,10 +216,10 @@ private void verifyFailOnSingleDropFailure( IndexAccessor failingAccessor, Fusio public void dropMustThrowIfAllFail() throws Exception { // given - List exceptions = new ArrayList<>(); + List exceptions = new ArrayList<>(); for ( IndexAccessor indexAccessor : aliveAccessors ) { - IOException exception = new IOException( indexAccessor.getClass().getSimpleName() + " fail" ); + UncheckedIOException exception = new UncheckedIOException( new IOException( indexAccessor.getClass().getSimpleName() + " fail" ) ); exceptions.add( exception ); doThrow( exception ).when( indexAccessor ).drop(); } @@ -229,7 +230,7 @@ public void dropMustThrowIfAllFail() throws Exception fusionIndexAccessor.drop(); fail( "Should have failed" ); } - catch ( IOException e ) + catch ( UncheckedIOException e ) { // then assertThat( exceptions, hasItem( e ) ); diff --git a/community/kernel/src/test/java/org/neo4j/kernel/impl/index/schema/fusion/FusionIndexPopulatorTest.java b/community/kernel/src/test/java/org/neo4j/kernel/impl/index/schema/fusion/FusionIndexPopulatorTest.java index 6e6dfbdcf0ed5..a03f5fabf196c 100644 --- a/community/kernel/src/test/java/org/neo4j/kernel/impl/index/schema/fusion/FusionIndexPopulatorTest.java +++ b/community/kernel/src/test/java/org/neo4j/kernel/impl/index/schema/fusion/FusionIndexPopulatorTest.java @@ -321,7 +321,7 @@ public void closeMustThrowIfCloseAnyThrow() throws Exception private void verifyOtherCloseOnThrow( IndexPopulator throwingPopulator ) throws Exception { // given - IOException failure = new IOException( "fail" ); + UncheckedIOException failure = new UncheckedIOException( new IOException( "fail" ) ); doThrow( failure ).when( throwingPopulator ).close( anyBoolean() ); // when @@ -330,7 +330,7 @@ private void verifyOtherCloseOnThrow( IndexPopulator throwingPopulator ) throws fusionIndexPopulator.close( true ); fail( "Should have failed" ); } - catch ( IOException ignore ) + catch ( UncheckedIOException ignore ) { } @@ -355,10 +355,10 @@ public void closeMustCloseOthersIfAnyThrow() throws Exception public void closeMustThrowIfAllThrow() throws Exception { // given - List failures = new ArrayList<>(); + List failures = new ArrayList<>(); for ( IndexPopulator alivePopulator : alivePopulators ) { - IOException failure = new IOException( "FAILURE[" + alivePopulator + "]" ); + UncheckedIOException failure = new UncheckedIOException( new IOException( "FAILURE[" + alivePopulator + "]" ) ); failures.add( failure ); doThrow( failure ).when( alivePopulator ).close( anyBoolean() ); } @@ -369,7 +369,7 @@ public void closeMustThrowIfAllThrow() throws Exception fusionIndexPopulator.close( anyBoolean() ); fail( "Should have failed" ); } - catch ( IOException e ) + catch ( UncheckedIOException e ) { // then if ( !failures.contains( e ) ) diff --git a/community/kernel/src/test/java/org/neo4j/kernel/impl/index/schema/fusion/LazyInstanceSelectorTest.java b/community/kernel/src/test/java/org/neo4j/kernel/impl/index/schema/fusion/LazyInstanceSelectorTest.java index 74b81e06201f4..157a4b85fcbc7 100644 --- a/community/kernel/src/test/java/org/neo4j/kernel/impl/index/schema/fusion/LazyInstanceSelectorTest.java +++ b/community/kernel/src/test/java/org/neo4j/kernel/impl/index/schema/fusion/LazyInstanceSelectorTest.java @@ -21,10 +21,9 @@ import org.junit.Test; +import java.util.function.Consumer; import java.util.function.Function; -import org.neo4j.function.ThrowingConsumer; - import static org.junit.Assert.assertNull; import static org.junit.Assert.fail; import static org.mockito.ArgumentMatchers.any; @@ -82,7 +81,7 @@ public void shouldPerformActionOnAll() selector.select( STRING ); // when - ThrowingConsumer consumer = mock( ThrowingConsumer.class ); + Consumer consumer = mock( Consumer.class ); selector.forAll( consumer ); // then @@ -103,7 +102,7 @@ public void shouldCloseAllInstantiated() selector.select( STRING ); // when - ThrowingConsumer consumer = mock( ThrowingConsumer.class ); + Consumer consumer = mock( Consumer.class ); selector.close( consumer ); // then @@ -122,7 +121,7 @@ public void shouldPreventInstantiationAfterClose() selector.select( STRING ); // when - selector.close( mock( ThrowingConsumer.class ) ); + selector.close( mock( Consumer.class ) ); // then try diff --git a/community/lucene-index/src/main/java/org/neo4j/kernel/api/impl/index/AbstractLuceneIndexAccessor.java b/community/lucene-index/src/main/java/org/neo4j/kernel/api/impl/index/AbstractLuceneIndexAccessor.java index 3b7aa91a02070..cd83ea86b5d29 100644 --- a/community/lucene-index/src/main/java/org/neo4j/kernel/api/impl/index/AbstractLuceneIndexAccessor.java +++ b/community/lucene-index/src/main/java/org/neo4j/kernel/api/impl/index/AbstractLuceneIndexAccessor.java @@ -23,6 +23,7 @@ import java.io.File; import java.io.IOException; +import java.io.UncheckedIOException; import java.util.function.ToLongFunction; import org.neo4j.graphdb.ResourceIterator; @@ -74,26 +75,47 @@ public void drop() } @Override - public void force( IOLimiter ioLimiter ) throws IOException + public void force( IOLimiter ioLimiter ) { - // We never change status of read-only indexes. - if ( !luceneIndex.isReadOnly() ) + try { - luceneIndex.markAsOnline(); + // We never change status of read-only indexes. + if ( !luceneIndex.isReadOnly() ) + { + luceneIndex.markAsOnline(); + } + luceneIndex.maybeRefreshBlocking(); + } + catch ( IOException e ) + { + throw new UncheckedIOException( e ); } - luceneIndex.maybeRefreshBlocking(); } @Override - public void refresh() throws IOException + public void refresh() { - luceneIndex.maybeRefreshBlocking(); + try + { + luceneIndex.maybeRefreshBlocking(); + } + catch ( IOException e ) + { + throw new UncheckedIOException( e ); + } } @Override - public void close() throws IOException + public void close() { - luceneIndex.close(); + try + { + luceneIndex.close(); + } + catch ( IOException e ) + { + throw new UncheckedIOException( e ); + } } @Override @@ -115,13 +137,20 @@ public BoundedIterable newAllEntriesReader( ToLongFunction entit } @Override - public ResourceIterator snapshotFiles() throws IOException + public ResourceIterator snapshotFiles() { - return luceneIndex.snapshot(); + try + { + return luceneIndex.snapshot(); + } + catch ( IOException e ) + { + throw new UncheckedIOException( e ); + } } @Override - public abstract void verifyDeferredConstraints( NodePropertyAccessor propertyAccessor ) throws IndexEntryConflictException, IOException; + public abstract void verifyDeferredConstraints( NodePropertyAccessor propertyAccessor ) throws IndexEntryConflictException; @Override public boolean isDirty() @@ -143,7 +172,7 @@ protected AbstractLuceneIndexUpdater( boolean idempotent, boolean refresh ) } @Override - public void process( IndexEntryUpdate update ) throws IOException + public void process( IndexEntryUpdate update ) { // we do not support adding partial entries assert update.indexKey().schema().equals( descriptor.schema() ); @@ -173,20 +202,27 @@ public void process( IndexEntryUpdate update ) throws IOException } @Override - public void close() throws IOException + public void close() { if ( hasChanges && refresh ) { - luceneIndex.maybeRefreshBlocking(); + try + { + luceneIndex.maybeRefreshBlocking(); + } + catch ( IOException e ) + { + throw new UncheckedIOException( e ); + } } } - protected abstract void addIdempotent( long nodeId, Value[] values ) throws IOException; + protected abstract void addIdempotent( long nodeId, Value[] values ); - protected abstract void add( long nodeId, Value[] values ) throws IOException; + protected abstract void add( long nodeId, Value[] values ); - protected abstract void change( long nodeId, Value[] values ) throws IOException; + protected abstract void change( long nodeId, Value[] values ); - protected abstract void remove( long nodeId ) throws IOException; + protected abstract void remove( long nodeId ); } } diff --git a/community/lucene-index/src/main/java/org/neo4j/kernel/api/impl/schema/LuceneIndexAccessor.java b/community/lucene-index/src/main/java/org/neo4j/kernel/api/impl/schema/LuceneIndexAccessor.java index 803fd13bdd576..72d6a1a1a019e 100644 --- a/community/lucene-index/src/main/java/org/neo4j/kernel/api/impl/schema/LuceneIndexAccessor.java +++ b/community/lucene-index/src/main/java/org/neo4j/kernel/api/impl/schema/LuceneIndexAccessor.java @@ -20,6 +20,7 @@ package org.neo4j.kernel.api.impl.schema; import java.io.IOException; +import java.io.UncheckedIOException; import org.neo4j.helpers.collection.BoundedIterable; import org.neo4j.kernel.api.exceptions.index.IndexEntryConflictException; @@ -54,9 +55,16 @@ public BoundedIterable newAllEntriesReader() @Override public void verifyDeferredConstraints( NodePropertyAccessor nodePropertyAccessor ) - throws IndexEntryConflictException, IOException + throws IndexEntryConflictException { - luceneIndex.verifyUniqueness( nodePropertyAccessor, descriptor.schema().getPropertyIds() ); + try + { + luceneIndex.verifyUniqueness( nodePropertyAccessor, descriptor.schema().getPropertyIds() ); + } + catch ( IOException e ) + { + throw new UncheckedIOException( e ); + } } @Override @@ -78,29 +86,57 @@ protected LuceneSchemaIndexUpdater( boolean idempotent, boolean refresh ) } @Override - protected void addIdempotent( long nodeId, Value[] values ) throws IOException + protected void addIdempotent( long nodeId, Value[] values ) { - writer.updateDocument( LuceneDocumentStructure.newTermForChangeOrRemove( nodeId ), - LuceneDocumentStructure.documentRepresentingProperties( nodeId, values ) ); + try + { + writer.updateDocument( LuceneDocumentStructure.newTermForChangeOrRemove( nodeId ), + LuceneDocumentStructure.documentRepresentingProperties( nodeId, values ) ); + } + catch ( IOException e ) + { + throw new UncheckedIOException( e ); + } } @Override - protected void add( long nodeId, Value[] values ) throws IOException + protected void add( long nodeId, Value[] values ) { - writer.addDocument( LuceneDocumentStructure.documentRepresentingProperties( nodeId, values ) ); + try + { + writer.addDocument( LuceneDocumentStructure.documentRepresentingProperties( nodeId, values ) ); + } + catch ( IOException e ) + { + throw new UncheckedIOException( e ); + } } @Override - protected void change( long nodeId, Value[] values ) throws IOException + protected void change( long nodeId, Value[] values ) { - writer.updateDocument( LuceneDocumentStructure.newTermForChangeOrRemove( nodeId ), - LuceneDocumentStructure.documentRepresentingProperties( nodeId, values ) ); + try + { + writer.updateDocument( LuceneDocumentStructure.newTermForChangeOrRemove( nodeId ), + LuceneDocumentStructure.documentRepresentingProperties( nodeId, values ) ); + } + catch ( IOException e ) + { + throw new UncheckedIOException( e ); + } } @Override - protected void remove( long nodeId ) throws IOException + protected void remove( long nodeId ) { - writer.deleteDocuments( LuceneDocumentStructure.newTermForChangeOrRemove( nodeId ) ); + try + { + writer.deleteDocuments( LuceneDocumentStructure.newTermForChangeOrRemove( nodeId ) ); + } + catch ( IOException e ) + { + throw new UncheckedIOException( e ); + } } } } diff --git a/community/lucene-index/src/main/java/org/neo4j/kernel/api/impl/schema/populator/LuceneIndexPopulatingUpdater.java b/community/lucene-index/src/main/java/org/neo4j/kernel/api/impl/schema/populator/LuceneIndexPopulatingUpdater.java index 1dcc68f6440ca..2dd56c72ef7f3 100644 --- a/community/lucene-index/src/main/java/org/neo4j/kernel/api/impl/schema/populator/LuceneIndexPopulatingUpdater.java +++ b/community/lucene-index/src/main/java/org/neo4j/kernel/api/impl/schema/populator/LuceneIndexPopulatingUpdater.java @@ -23,9 +23,9 @@ import org.apache.lucene.index.Term; import java.io.IOException; +import java.io.UncheckedIOException; import java.util.Arrays; -import org.neo4j.kernel.api.exceptions.index.IndexEntryConflictException; import org.neo4j.kernel.api.impl.schema.LuceneDocumentStructure; import org.neo4j.kernel.api.impl.schema.writer.LuceneIndexWriter; import org.neo4j.kernel.api.index.IndexEntryUpdate; @@ -47,28 +47,35 @@ public LuceneIndexPopulatingUpdater( LuceneIndexWriter writer ) } @Override - public void process( IndexEntryUpdate update ) throws IOException + public void process( IndexEntryUpdate update ) { long nodeId = update.getEntityId(); - switch ( update.updateMode() ) + try { - case ADDED: - added( update ); - writer.updateDocument( LuceneDocumentStructure.newTermForChangeOrRemove( nodeId ), - LuceneDocumentStructure.documentRepresentingProperties( nodeId, update.values() ) ); - break; - case CHANGED: - changed( update ); - writer.updateDocument( LuceneDocumentStructure.newTermForChangeOrRemove( nodeId ), - LuceneDocumentStructure.documentRepresentingProperties( nodeId, update.values() ) ); - break; - case REMOVED: - removed( update ); - writer.deleteDocuments( LuceneDocumentStructure.newTermForChangeOrRemove( nodeId ) ); - break; - default: - throw new IllegalStateException( "Unknown update mode " + Arrays.toString( update.values() ) ); + switch ( update.updateMode() ) + { + case ADDED: + added( update ); + writer.updateDocument( LuceneDocumentStructure.newTermForChangeOrRemove( nodeId ), + LuceneDocumentStructure.documentRepresentingProperties( nodeId, update.values() ) ); + break; + case CHANGED: + changed( update ); + writer.updateDocument( LuceneDocumentStructure.newTermForChangeOrRemove( nodeId ), + LuceneDocumentStructure.documentRepresentingProperties( nodeId, update.values() ) ); + break; + case REMOVED: + removed( update ); + writer.deleteDocuments( LuceneDocumentStructure.newTermForChangeOrRemove( nodeId ) ); + break; + default: + throw new IllegalStateException( "Unknown update mode " + Arrays.toString( update.values() ) ); + } + } + catch ( IOException e ) + { + throw new UncheckedIOException( e ); } } diff --git a/community/lucene-index/src/main/java/org/neo4j/kernel/api/impl/schema/populator/LuceneIndexPopulator.java b/community/lucene-index/src/main/java/org/neo4j/kernel/api/impl/schema/populator/LuceneIndexPopulator.java index 0628dc7a0c643..fcf03e2783de5 100644 --- a/community/lucene-index/src/main/java/org/neo4j/kernel/api/impl/schema/populator/LuceneIndexPopulator.java +++ b/community/lucene-index/src/main/java/org/neo4j/kernel/api/impl/schema/populator/LuceneIndexPopulator.java @@ -22,6 +22,7 @@ import org.apache.lucene.document.Document; import java.io.IOException; +import java.io.UncheckedIOException; import java.util.Collection; import org.neo4j.io.IOUtils; @@ -45,11 +46,18 @@ protected LuceneIndexPopulator( INDEX luceneIndex ) } @Override - public void create() throws IOException + public void create() { - luceneIndex.create(); - luceneIndex.open(); - writer = luceneIndex.getIndexWriter(); + try + { + luceneIndex.create(); + luceneIndex.open(); + writer = luceneIndex.getIndexWriter(); + } + catch ( IOException e ) + { + throw new UncheckedIOException( e ); + } } @Override @@ -59,18 +67,26 @@ public void drop() } @Override - public void add( Collection> updates ) throws IOException + public void add( Collection> updates ) { assert updatesForCorrectIndex( updates ); - // Lucene documents stored in a ThreadLocal and reused so we can't create an eager collection of documents here - // That is why we create a lazy Iterator and then Iterable - writer.addDocuments( updates.size(), () -> updates.stream() - .map( LuceneIndexPopulator::updateAsDocument ) - .iterator() ); + + try + { + // Lucene documents stored in a ThreadLocal and reused so we can't create an eager collection of documents here + // That is why we create a lazy Iterator and then Iterable + writer.addDocuments( updates.size(), () -> updates.stream() + .map( LuceneIndexPopulator::updateAsDocument ) + .iterator() ); + } + catch ( IOException e ) + { + throw new UncheckedIOException( e ); + } } @Override - public void close( boolean populationCompletedSuccessfully ) throws IOException + public void close( boolean populationCompletedSuccessfully ) { try { @@ -79,6 +95,10 @@ public void close( boolean populationCompletedSuccessfully ) throws IOException luceneIndex.markAsOnline(); } } + catch ( IOException e ) + { + throw new UncheckedIOException( e ); + } finally { IOUtils.closeAllSilently( luceneIndex ); @@ -86,9 +106,16 @@ public void close( boolean populationCompletedSuccessfully ) throws IOException } @Override - public void markAsFailed( String failure ) throws IOException + public void markAsFailed( String failure ) { - luceneIndex.markAsFailed( failure ); + try + { + luceneIndex.markAsFailed( failure ); + } + catch ( IOException e ) + { + throw new UncheckedIOException( e ); + } } private boolean updatesForCorrectIndex( Collection> updates ) diff --git a/community/lucene-index/src/main/java/org/neo4j/kernel/api/impl/schema/populator/UniqueLuceneIndexPopulatingUpdater.java b/community/lucene-index/src/main/java/org/neo4j/kernel/api/impl/schema/populator/UniqueLuceneIndexPopulatingUpdater.java index 9234de3b50d0d..45e34c47a62a1 100644 --- a/community/lucene-index/src/main/java/org/neo4j/kernel/api/impl/schema/populator/UniqueLuceneIndexPopulatingUpdater.java +++ b/community/lucene-index/src/main/java/org/neo4j/kernel/api/impl/schema/populator/UniqueLuceneIndexPopulatingUpdater.java @@ -20,6 +20,7 @@ package org.neo4j.kernel.api.impl.schema.populator; import java.io.IOException; +import java.io.UncheckedIOException; import java.util.ArrayList; import java.util.List; @@ -75,8 +76,15 @@ protected void removed( IndexEntryUpdate update ) } @Override - public void close() throws IOException, IndexEntryConflictException + public void close() throws IndexEntryConflictException { - luceneIndex.verifyUniqueness( nodePropertyAccessor, propertyKeyIds, updatedValueTuples ); + try + { + luceneIndex.verifyUniqueness( nodePropertyAccessor, propertyKeyIds, updatedValueTuples ); + } + catch ( IOException e ) + { + throw new UncheckedIOException( e ); + } } } diff --git a/community/lucene-index/src/main/java/org/neo4j/kernel/api/impl/schema/populator/UniqueLuceneIndexPopulator.java b/community/lucene-index/src/main/java/org/neo4j/kernel/api/impl/schema/populator/UniqueLuceneIndexPopulator.java index a5f4e405aa195..964a3c21ff1f4 100644 --- a/community/lucene-index/src/main/java/org/neo4j/kernel/api/impl/schema/populator/UniqueLuceneIndexPopulator.java +++ b/community/lucene-index/src/main/java/org/neo4j/kernel/api/impl/schema/populator/UniqueLuceneIndexPopulator.java @@ -20,6 +20,7 @@ package org.neo4j.kernel.api.impl.schema.populator; import java.io.IOException; +import java.io.UncheckedIOException; import org.neo4j.kernel.api.exceptions.index.IndexEntryConflictException; import org.neo4j.kernel.api.impl.schema.SchemaIndex; @@ -49,9 +50,16 @@ public UniqueLuceneIndexPopulator( SchemaIndex index, IndexDescriptor descriptor } @Override - public void verifyDeferredConstraints( NodePropertyAccessor accessor ) throws IndexEntryConflictException, IOException + public void verifyDeferredConstraints( NodePropertyAccessor accessor ) throws IndexEntryConflictException { - luceneIndex.verifyUniqueness( accessor, propertyKeyIds ); + try + { + luceneIndex.verifyUniqueness( accessor, propertyKeyIds ); + } + catch ( IOException e ) + { + throw new UncheckedIOException( e ); + } } @Override diff --git a/enterprise/ha/src/test/java/org/neo4j/kernel/api/SchemaIndexHaIT.java b/enterprise/ha/src/test/java/org/neo4j/kernel/api/SchemaIndexHaIT.java index a50314828471d..257ee09b30a74 100644 --- a/enterprise/ha/src/test/java/org/neo4j/kernel/api/SchemaIndexHaIT.java +++ b/enterprise/ha/src/test/java/org/neo4j/kernel/api/SchemaIndexHaIT.java @@ -427,7 +427,7 @@ private static class ControlledIndexPopulator implements IndexPopulator } @Override - public void create() throws IOException + public void create() { delegate.create(); } @@ -439,14 +439,14 @@ public void drop() } @Override - public void add( Collection> updates ) throws IndexEntryConflictException, IOException + public void add( Collection> updates ) throws IndexEntryConflictException { delegate.add( updates ); latch.startAndWaitForAllToStartAndFinish(); } @Override - public void verifyDeferredConstraints( NodePropertyAccessor nodePropertyAccessor ) throws IndexEntryConflictException, IOException + public void verifyDeferredConstraints( NodePropertyAccessor nodePropertyAccessor ) throws IndexEntryConflictException { delegate.verifyDeferredConstraints( nodePropertyAccessor ); } @@ -458,7 +458,7 @@ public IndexUpdater newPopulatingUpdater( NodePropertyAccessor nodePropertyAcces } @Override - public void close( boolean populationCompletedSuccessfully ) throws IOException + public void close( boolean populationCompletedSuccessfully ) { delegate.close( populationCompletedSuccessfully ); assertTrue( "Expected population to succeed :(", populationCompletedSuccessfully ); @@ -466,7 +466,7 @@ public void close( boolean populationCompletedSuccessfully ) throws IOException } @Override - public void markAsFailed( String failure ) throws IOException + public void markAsFailed( String failure ) { delegate.markAsFailed( failure ); }