Skip to content

Commit

Permalink
Specific TxStateVisitor.Decorator interface
Browse files Browse the repository at this point in the history
  • Loading branch information
tinwelint committed Jun 11, 2018
1 parent 4b6bd93 commit f6844ee
Show file tree
Hide file tree
Showing 11 changed files with 34 additions and 26 deletions.
Expand Up @@ -21,7 +21,7 @@


import org.eclipse.collections.api.iterator.LongIterator; import org.eclipse.collections.api.iterator.LongIterator;
import org.eclipse.collections.api.set.primitive.MutableLongSet; import org.eclipse.collections.api.set.primitive.MutableLongSet;
import org.eclipse.collections.impl.factory.primitive.LongSets; import org.eclipse.collections.impl.iterator.ImmutableEmptyLongIterator;
import org.eclipse.collections.impl.set.mutable.primitive.LongHashSet; import org.eclipse.collections.impl.set.mutable.primitive.LongHashSet;


import org.neo4j.internal.kernel.api.LabelSet; import org.neo4j.internal.kernel.api.LabelSet;
Expand Down Expand Up @@ -57,7 +57,7 @@ void scan( Read read )
this.read = read; this.read = read;
this.single = NO_ID; this.single = NO_ID;
this.hasChanges = HasChanges.MAYBE; this.hasChanges = HasChanges.MAYBE;
this.addedNodes = LongSets.immutable.empty().longIterator(); this.addedNodes = ImmutableEmptyLongIterator.INSTANCE;
} }


void single( long reference, Read read ) void single( long reference, Read read )
Expand All @@ -66,7 +66,7 @@ void single( long reference, Read read )
this.read = read; this.read = read;
this.single = reference; this.single = reference;
this.hasChanges = HasChanges.MAYBE; this.hasChanges = HasChanges.MAYBE;
this.addedNodes = LongSets.immutable.empty().longIterator(); this.addedNodes = ImmutableEmptyLongIterator.INSTANCE;
} }


@Override @Override
Expand Down Expand Up @@ -199,7 +199,7 @@ public void close()
{ {
read = null; read = null;
hasChanges = HasChanges.MAYBE; hasChanges = HasChanges.MAYBE;
addedNodes = LongSets.immutable.empty().longIterator(); addedNodes = ImmutableEmptyLongIterator.INSTANCE;
storeCursor.close(); storeCursor.close();


pool.accept( this ); pool.accept( this );
Expand Down Expand Up @@ -227,7 +227,7 @@ private boolean hasChanges()
if ( single != NO_ID ) if ( single != NO_ID )
{ {
addedNodes = read.txState().nodeIsAddedInThisTx( single ) ? addedNodes = read.txState().nodeIsAddedInThisTx( single ) ?
LongHashSet.newSetWith( single ).longIterator() : LongSets.immutable.empty().longIterator(); LongHashSet.newSetWith( single ).longIterator() : ImmutableEmptyLongIterator.INSTANCE;
} }
else else
{ {
Expand Down
Expand Up @@ -20,7 +20,7 @@
package org.neo4j.kernel.impl.newapi; package org.neo4j.kernel.impl.newapi;


import org.eclipse.collections.api.iterator.LongIterator; import org.eclipse.collections.api.iterator.LongIterator;
import org.eclipse.collections.impl.factory.primitive.LongSets; import org.eclipse.collections.impl.iterator.ImmutableEmptyLongIterator;
import org.eclipse.collections.impl.set.mutable.primitive.LongHashSet; import org.eclipse.collections.impl.set.mutable.primitive.LongHashSet;


import org.neo4j.internal.kernel.api.RelationshipScanCursor; import org.neo4j.internal.kernel.api.RelationshipScanCursor;
Expand All @@ -45,7 +45,7 @@ void scan( int type, Read read )
this.type = type; this.type = type;
this.single = NO_ID; this.single = NO_ID;
init( read ); init( read );
this.addedRelationships = LongSets.immutable.empty().longIterator(); this.addedRelationships = ImmutableEmptyLongIterator.INSTANCE;
} }


void single( long reference, Read read ) void single( long reference, Read read )
Expand All @@ -54,7 +54,7 @@ void single( long reference, Read read )
type = -1; type = -1;
this.single = reference; this.single = reference;
init( read ); init( read );
this.addedRelationships = LongSets.immutable.empty().longIterator(); this.addedRelationships = ImmutableEmptyLongIterator.INSTANCE;
} }


@Override @Override
Expand Down Expand Up @@ -119,7 +119,7 @@ protected void collectAddedTxStateSnapshot()
{ {
addedRelationships = read.txState().relationshipIsAddedInThisTx( single ) addedRelationships = read.txState().relationshipIsAddedInThisTx( single )
? LongHashSet.newSetWith( single ).longIterator() ? LongHashSet.newSetWith( single ).longIterator()
: LongSets.immutable.empty().longIterator(); : ImmutableEmptyLongIterator.INSTANCE;
} }
else else
{ {
Expand Down
Expand Up @@ -24,7 +24,6 @@
import java.util.Collection; import java.util.Collection;
import java.util.Collections; import java.util.Collections;
import java.util.List; import java.util.List;
import java.util.function.Function;
import java.util.function.Supplier; import java.util.function.Supplier;


import org.neo4j.graphdb.factory.GraphDatabaseSettings; import org.neo4j.graphdb.factory.GraphDatabaseSettings;
Expand Down Expand Up @@ -267,7 +266,7 @@ public CommandReaderFactory commandReaderFactory()
@SuppressWarnings( "resource" ) @SuppressWarnings( "resource" )
@Override @Override
public void createCommands( Collection<StorageCommand> commands, ReadableTransactionState txState, StorageReader storageReader, ResourceLocker locks, public void createCommands( Collection<StorageCommand> commands, ReadableTransactionState txState, StorageReader storageReader, ResourceLocker locks,
long lastTransactionIdWhenStarted, Function<TxStateVisitor,TxStateVisitor> additionalTxStateVisitor ) long lastTransactionIdWhenStarted, TxStateVisitor.Decorator additionalTxStateVisitor )
throws TransactionFailureException, CreateConstraintFailureException, ConstraintValidationException throws TransactionFailureException, CreateConstraintFailureException, ConstraintValidationException
{ {
if ( txState != null ) if ( txState != null )
Expand Down
Expand Up @@ -20,7 +20,6 @@
package org.neo4j.storageengine.api; package org.neo4j.storageengine.api;


import java.util.Collection; import java.util.Collection;
import java.util.function.Function;
import java.util.stream.Stream; import java.util.stream.Stream;


import org.neo4j.internal.kernel.api.exceptions.TransactionFailureException; import org.neo4j.internal.kernel.api.exceptions.TransactionFailureException;
Expand Down Expand Up @@ -49,7 +48,7 @@ public interface StorageEngine


/** /**
* @return a new {@link CommandCreationContext} meant to be kept for multiple calls to * @return a new {@link CommandCreationContext} meant to be kept for multiple calls to
* {@link #createCommands(Collection, ReadableTransactionState, StorageReader, ResourceLocker, long, Function)}. * {@link #createCommands(Collection, ReadableTransactionState, StorageReader, ResourceLocker, long, TxStateVisitor.Decorator)}.
* Must be {@link CommandCreationContext#close() closed} after used, before being discarded. * Must be {@link CommandCreationContext#close() closed} after used, before being discarded.
*/ */
CommandCreationContext allocateCommandCreationContext(); CommandCreationContext allocateCommandCreationContext();
Expand Down Expand Up @@ -87,7 +86,7 @@ void createCommands(
StorageReader storageReader, StorageReader storageReader,
ResourceLocker locks, ResourceLocker locks,
long lastTransactionIdWhenStarted, long lastTransactionIdWhenStarted,
Function<TxStateVisitor,TxStateVisitor> additionalTxStateVisitor ) TxStateVisitor.Decorator additionalTxStateVisitor )
throws TransactionFailureException, CreateConstraintFailureException, ConstraintValidationException; throws TransactionFailureException, CreateConstraintFailureException, ConstraintValidationException;


/** /**
Expand Down
Expand Up @@ -23,6 +23,7 @@
import org.eclipse.collections.api.set.primitive.LongSet; import org.eclipse.collections.api.set.primitive.LongSet;


import java.util.Iterator; import java.util.Iterator;
import java.util.function.Function;


import org.neo4j.internal.kernel.api.exceptions.schema.ConstraintValidationException; import org.neo4j.internal.kernel.api.exceptions.schema.ConstraintValidationException;
import org.neo4j.internal.kernel.api.schema.constraints.ConstraintDescriptor; import org.neo4j.internal.kernel.api.schema.constraints.ConstraintDescriptor;
Expand Down Expand Up @@ -272,4 +273,13 @@ public void close()
actual.close(); actual.close();
} }
} }

/**
* Interface for allowing decoration of a TxStateVisitor with one or more other visitor(s).
*/
interface Decorator extends Function<TxStateVisitor,TxStateVisitor>
{
}

Decorator NO_DECORATION = txStateVisitor -> txStateVisitor;
} }
Expand Up @@ -33,7 +33,6 @@
import java.util.concurrent.atomic.AtomicLong; import java.util.concurrent.atomic.AtomicLong;
import java.util.concurrent.atomic.AtomicReference; import java.util.concurrent.atomic.AtomicReference;
import java.util.function.Consumer; import java.util.function.Consumer;
import java.util.function.Function;


import org.neo4j.graphdb.TransactionTerminatedException; import org.neo4j.graphdb.TransactionTerminatedException;
import org.neo4j.internal.kernel.api.exceptions.TransactionFailureException; import org.neo4j.internal.kernel.api.exceptions.TransactionFailureException;
Expand All @@ -54,6 +53,7 @@
import org.neo4j.storageengine.api.StorageCommand; import org.neo4j.storageengine.api.StorageCommand;
import org.neo4j.storageengine.api.StorageReader; import org.neo4j.storageengine.api.StorageReader;
import org.neo4j.storageengine.api.lock.ResourceLocker; import org.neo4j.storageengine.api.lock.ResourceLocker;
import org.neo4j.storageengine.api.txstate.TxStateVisitor;
import org.neo4j.test.DoubleLatch; import org.neo4j.test.DoubleLatch;


import static java.util.concurrent.TimeUnit.MILLISECONDS; import static java.util.concurrent.TimeUnit.MILLISECONDS;
Expand Down Expand Up @@ -382,7 +382,7 @@ public void shouldUseStartTimeAndTxIdFromWhenStartingTxAsHeader() throws Excepti
any( TransactionState.class ), any( TransactionState.class ),
any( StorageReader.class ), any( StorageReader.class ),
any( ResourceLocker.class ), any( ResourceLocker.class ),
anyLong(), any( Function.class ) ); anyLong(), any( TxStateVisitor.Decorator.class ) );


try ( KernelTransactionImplementation transaction = newTransaction( loginContext() ) ) try ( KernelTransactionImplementation transaction = newTransaction( loginContext() ) )
{ {
Expand Down
Expand Up @@ -28,7 +28,6 @@


import java.util.Collection; import java.util.Collection;
import java.util.concurrent.atomic.AtomicReference; import java.util.concurrent.atomic.AtomicReference;
import java.util.function.Function;
import java.util.function.Supplier; import java.util.function.Supplier;


import org.neo4j.collection.pool.Pool; import org.neo4j.collection.pool.Pool;
Expand Down Expand Up @@ -71,6 +70,7 @@
import org.neo4j.storageengine.api.TransactionApplicationMode; import org.neo4j.storageengine.api.TransactionApplicationMode;
import org.neo4j.storageengine.api.lock.ResourceLocker; import org.neo4j.storageengine.api.lock.ResourceLocker;
import org.neo4j.storageengine.api.txstate.ReadableTransactionState; import org.neo4j.storageengine.api.txstate.ReadableTransactionState;
import org.neo4j.storageengine.api.txstate.TxStateVisitor;
import org.neo4j.time.Clocks; import org.neo4j.time.Clocks;
import org.neo4j.time.FakeClock; import org.neo4j.time.FakeClock;


Expand Down Expand Up @@ -119,7 +119,7 @@ public void before() throws Exception
any( ReadableTransactionState.class ), any( ReadableTransactionState.class ),
any( StorageReader.class ), any( ResourceLocker.class ), any( StorageReader.class ), any( ResourceLocker.class ),
anyLong(), anyLong(),
any( Function.class ) ); any( TxStateVisitor.Decorator.class ) );
} }


public KernelTransactionImplementation newTransaction( long transactionTimeoutMillis ) public KernelTransactionImplementation newTransaction( long transactionTimeoutMillis )
Expand Down
Expand Up @@ -32,7 +32,6 @@
import java.util.concurrent.atomic.AtomicBoolean; import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.atomic.AtomicReference; import java.util.concurrent.atomic.AtomicReference;
import java.util.concurrent.atomic.AtomicReferenceArray; import java.util.concurrent.atomic.AtomicReferenceArray;
import java.util.function.Function;


import org.neo4j.graphdb.DatabaseShutdownException; import org.neo4j.graphdb.DatabaseShutdownException;
import org.neo4j.graphdb.security.AuthorizationExpiredException; import org.neo4j.graphdb.security.AuthorizationExpiredException;
Expand Down Expand Up @@ -78,6 +77,7 @@
import org.neo4j.storageengine.api.TransactionApplicationMode; import org.neo4j.storageengine.api.TransactionApplicationMode;
import org.neo4j.storageengine.api.lock.ResourceLocker; import org.neo4j.storageengine.api.lock.ResourceLocker;
import org.neo4j.storageengine.api.txstate.ReadableTransactionState; import org.neo4j.storageengine.api.txstate.ReadableTransactionState;
import org.neo4j.storageengine.api.txstate.TxStateVisitor;
import org.neo4j.test.OtherThreadExecutor; import org.neo4j.test.OtherThreadExecutor;
import org.neo4j.test.Race; import org.neo4j.test.Race;
import org.neo4j.test.rule.concurrent.OtherThreadRule; import org.neo4j.test.rule.concurrent.OtherThreadRule;
Expand Down Expand Up @@ -564,7 +564,8 @@ private static KernelTransactions newKernelTransactions( boolean testKernelTrans
any( ReadableTransactionState.class ), any( ReadableTransactionState.class ),
any( StorageReader.class ), any( StorageReader.class ),
any( ResourceLocker.class ), any( ResourceLocker.class ),
anyLong(), any( Function.class ) ); anyLong(),
any( TxStateVisitor.Decorator.class ) );


return newKernelTransactions( locks, storageEngine, commitProcess, testKernelTransactions ); return newKernelTransactions( locks, storageEngine, commitProcess, testKernelTransactions );
} }
Expand Down
Expand Up @@ -61,13 +61,13 @@
import org.neo4j.values.storable.Values; import org.neo4j.values.storable.Values;


import static java.util.Collections.singletonList; import static java.util.Collections.singletonList;
import static java.util.function.Function.identity;
import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertFalse;
import static org.neo4j.helpers.TimeUtil.parseTimeMillis; import static org.neo4j.helpers.TimeUtil.parseTimeMillis;
import static org.neo4j.kernel.impl.transaction.command.Commands.createIndexRule; import static org.neo4j.kernel.impl.transaction.command.Commands.createIndexRule;
import static org.neo4j.kernel.impl.transaction.command.Commands.transactionRepresentation; import static org.neo4j.kernel.impl.transaction.command.Commands.transactionRepresentation;
import static org.neo4j.kernel.impl.transaction.log.Commitment.NO_COMMITMENT; import static org.neo4j.kernel.impl.transaction.log.Commitment.NO_COMMITMENT;
import static org.neo4j.storageengine.api.txstate.TxStateVisitor.NO_DECORATION;


public class IndexWorkSyncTransactionApplicationStressIT public class IndexWorkSyncTransactionApplicationStressIT
{ {
Expand Down Expand Up @@ -205,7 +205,7 @@ private TransactionToApply createNodeAndProperty( int progress ) throws Exceptio
Collection<StorageCommand> commands = new ArrayList<>(); Collection<StorageCommand> commands = new ArrayList<>();
try ( StorageReader statement = storageEngine.newReader() ) try ( StorageReader statement = storageEngine.newReader() )
{ {
storageEngine.createCommands( commands, txState, statement, null, 0, identity() ); storageEngine.createCommands( commands, txState, statement, null, 0, NO_DECORATION );
} }
return tx( commands ); return tx( commands );
} }
Expand Down
Expand Up @@ -47,7 +47,7 @@
import org.neo4j.storageengine.api.Token; import org.neo4j.storageengine.api.Token;
import org.neo4j.storageengine.api.lock.ResourceLocker; import org.neo4j.storageengine.api.lock.ResourceLocker;


import static java.util.function.Function.identity; import static org.neo4j.storageengine.api.txstate.TxStateVisitor.NO_DECORATION;


abstract class ReplicatedTokenHolder<TOKEN extends Token> implements TokenHolder<TOKEN> abstract class ReplicatedTokenHolder<TOKEN extends Token> implements TokenHolder<TOKEN>
{ {
Expand Down Expand Up @@ -133,7 +133,7 @@ private byte[] createCommands( String tokenName )
createToken( txState, tokenName, tokenId ); createToken( txState, tokenName, tokenId );
try ( StorageReader statement = storageEngine.newReader() ) try ( StorageReader statement = storageEngine.newReader() )
{ {
storageEngine.createCommands( commands, txState, statement, ResourceLocker.NONE, Long.MAX_VALUE, identity() ); storageEngine.createCommands( commands, txState, statement, ResourceLocker.NONE, Long.MAX_VALUE, NO_DECORATION );
} }
catch ( CreateConstraintFailureException | TransactionFailureException | ConstraintValidationException e ) catch ( CreateConstraintFailureException | TransactionFailureException | ConstraintValidationException e )
{ {
Expand Down
Expand Up @@ -26,7 +26,6 @@


import java.util.Collection; import java.util.Collection;
import java.util.concurrent.CompletableFuture; import java.util.concurrent.CompletableFuture;
import java.util.function.Function;


import org.neo4j.kernel.impl.store.id.IdGenerator; import org.neo4j.kernel.impl.store.id.IdGenerator;
import org.neo4j.kernel.impl.store.id.IdGeneratorFactory; import org.neo4j.kernel.impl.store.id.IdGeneratorFactory;
Expand Down Expand Up @@ -140,7 +139,7 @@ public void visitCreatedLabelToken( long id, String name )
} ); } );
return null; return null;
} ).when( storageEngine ).createCommands( anyCollection(), any( ReadableTransactionState.class ), } ).when( storageEngine ).createCommands( anyCollection(), any( ReadableTransactionState.class ),
any( StorageReader.class ), any( ResourceLocker.class ), anyLong(), any( Function.class ) ); any( StorageReader.class ), any( ResourceLocker.class ), anyLong(), any( TxStateVisitor.Decorator.class ) );


StorageReader readLayer = mock( StorageReader.class ); StorageReader readLayer = mock( StorageReader.class );
when( storageEngine.newReader() ).thenReturn( readLayer ); when( storageEngine.newReader() ).thenReturn( readLayer );
Expand Down

0 comments on commit f6844ee

Please sign in to comment.