Skip to content

Commit

Permalink
Remove all external accesses to Statement#dataWriteOperations
Browse files Browse the repository at this point in the history
  • Loading branch information
pontusmelke committed Apr 4, 2018
1 parent 9fb42f0 commit 573df2c
Show file tree
Hide file tree
Showing 10 changed files with 183 additions and 48 deletions.
Expand Up @@ -74,6 +74,15 @@ void nodeExplicitIndexQuery( NodeExplicitIndexCursor cursor, String index, Strin
*/ */
boolean nodeExplicitIndexExists( String indexName, Map<String,String> customConfiguration ); boolean nodeExplicitIndexExists( String indexName, Map<String,String> customConfiguration );


/**
* Return the configuration of the given index
* @param indexName the name of the index
* @return the configuration of the index with the given
* @throws ExplicitIndexNotFoundKernelException if the index is not there
*/
Map<String, String> nodeExplicitIndexGetConfiguration( String indexName )
throws ExplicitIndexNotFoundKernelException;

/** /**
* Finds item from explicit index * Finds item from explicit index
* *
Expand Down Expand Up @@ -138,4 +147,13 @@ void relationshipExplicitIndexQuery(
* @return the names of all relationship explicit indexes * @return the names of all relationship explicit indexes
*/ */
String[] relationshipExplicitIndexesGetAll(); String[] relationshipExplicitIndexesGetAll();

/**
* Return the configuration of the given index
* @param indexName the name of the index
* @return the configuration of the index with the given
* @throws ExplicitIndexNotFoundKernelException if the index doesn't exist
*/
Map<String, String> relationshipExplicitIndexGetConfiguration( String indexName )
throws ExplicitIndexNotFoundKernelException;
} }
Expand Up @@ -79,6 +79,27 @@ void nodeRemoveFromExplicitIndex( String indexName, long node, String key ) thro
*/ */
void nodeExplicitIndexDrop( String indexName ) throws ExplicitIndexNotFoundKernelException; void nodeExplicitIndexDrop( String indexName ) throws ExplicitIndexNotFoundKernelException;


/**
* Updates configuration of the given index
* @param indexName the name of the index
* @param key the configuration key
* @param value the value to be associated with the key
* @return The old value associated with the key or <tt>null</tt> if nothing associated with the key.
* @throws ExplicitIndexNotFoundKernelException if no such index exists
*/
String nodeExplicitIndexSetConfiguration( String indexName, String key, String value )
throws ExplicitIndexNotFoundKernelException;

/**
* Remove a configuration of the given index
* @param indexName the name of the index
* @param key the configuration key
* @return The old value associated with the key or <tt>null</tt> if nothing associated with the key.
* @throws ExplicitIndexNotFoundKernelException if no such index exists
*/
String nodeExplicitIndexRemoveConfiguration( String indexName, String key )
throws ExplicitIndexNotFoundKernelException;

/** /**
* Adds relationship to explicit index. * Adds relationship to explicit index.
* *
Expand Down Expand Up @@ -161,4 +182,26 @@ void relationshipRemoveFromExplicitIndex( String indexName, long relationship )
* @param indexName the index to drop * @param indexName the index to drop
*/ */
void relationshipExplicitIndexDrop( String indexName ) throws ExplicitIndexNotFoundKernelException; void relationshipExplicitIndexDrop( String indexName ) throws ExplicitIndexNotFoundKernelException;

/**
* Updates configuration of the given index
* @param indexName the name of the index
* @param key the configuration key
* @param value the value to be associated with the key
* @return The old value associated with the key or <tt>null</tt> if nothing associated with the key.
* @throws ExplicitIndexNotFoundKernelException if no such index exists
*/
String relationshipExplicitIndexSetConfiguration( String indexName, String key, String value )
throws ExplicitIndexNotFoundKernelException;

/**
* Remove a configuration of the given index
* @param indexName the name of the index
* @param key the configuration key
* @return The old value associated with the key or <tt>null</tt> if nothing associated with the key.
* @throws ExplicitIndexNotFoundKernelException if no such index exists
*/
String relationshipExplicitIndexRemoveConfiguration( String indexName, String key )
throws ExplicitIndexNotFoundKernelException;

} }
Expand Up @@ -32,19 +32,19 @@
import org.neo4j.graphdb.index.IndexManager; import org.neo4j.graphdb.index.IndexManager;
import org.neo4j.graphdb.index.RelationshipAutoIndexer; import org.neo4j.graphdb.index.RelationshipAutoIndexer;
import org.neo4j.graphdb.index.RelationshipIndex; import org.neo4j.graphdb.index.RelationshipIndex;
import org.neo4j.internal.kernel.api.Transaction;
import org.neo4j.internal.kernel.api.exceptions.InvalidTransactionTypeKernelException; import org.neo4j.internal.kernel.api.exceptions.InvalidTransactionTypeKernelException;
import org.neo4j.internal.kernel.api.exceptions.explicitindex.ExplicitIndexNotFoundKernelException; import org.neo4j.internal.kernel.api.exceptions.explicitindex.ExplicitIndexNotFoundKernelException;
import org.neo4j.kernel.api.Statement;
import org.neo4j.kernel.impl.api.explicitindex.InternalAutoIndexing; import org.neo4j.kernel.impl.api.explicitindex.InternalAutoIndexing;


public class IndexManagerImpl implements IndexManager public class IndexManagerImpl implements IndexManager
{ {
private final Supplier<Statement> transactionBridge; private final Supplier<Transaction> transactionBridge;
private final IndexProvider provider; private final IndexProvider provider;
private final AutoIndexer<Node> nodeAutoIndexer; private final AutoIndexer<Node> nodeAutoIndexer;
private final RelationshipAutoIndexer relAutoIndexer; private final RelationshipAutoIndexer relAutoIndexer;


public IndexManagerImpl( Supplier<Statement> bridge, public IndexManagerImpl( Supplier<Transaction> bridge,
IndexProvider provider, IndexProvider provider,
AutoIndexer<Node> nodeAutoIndexer, AutoIndexer<Node> nodeAutoIndexer,
RelationshipAutoIndexer relAutoIndexer ) RelationshipAutoIndexer relAutoIndexer )
Expand All @@ -58,9 +58,9 @@ public IndexManagerImpl( Supplier<Statement> bridge,
@Override @Override
public boolean existsForNodes( String indexName ) public boolean existsForNodes( String indexName )
{ {
try ( Statement statement = transactionBridge.get() ) try
{ {
statement.readOperations().nodeExplicitIndexGetConfiguration( indexName ); transactionBridge.get().indexRead().nodeExplicitIndexGetConfiguration( indexName );
return true; return true;
} }
catch ( ExplicitIndexNotFoundKernelException e ) catch ( ExplicitIndexNotFoundKernelException e )
Expand Down Expand Up @@ -91,18 +91,16 @@ public Index<Node> forNodes( String indexName, Map<String,String> customConfigur
@Override @Override
public String[] nodeIndexNames() public String[] nodeIndexNames()
{ {
try ( Statement statement = transactionBridge.get() )
{ return transactionBridge.get().indexRead().nodeExplicitIndexesGetAll();
return statement.readOperations().nodeExplicitIndexesGetAll();
}
} }


@Override @Override
public boolean existsForRelationships( String indexName ) public boolean existsForRelationships( String indexName )
{ {
try ( Statement statement = transactionBridge.get() ) try
{ {
statement.readOperations().relationshipExplicitIndexGetConfiguration( indexName ); transactionBridge.get().indexRead().relationshipExplicitIndexGetConfiguration( indexName );
return true; return true;
} }
catch ( ExplicitIndexNotFoundKernelException e ) catch ( ExplicitIndexNotFoundKernelException e )
Expand Down Expand Up @@ -134,24 +132,23 @@ public RelationshipIndex forRelationships( String indexName,
@Override @Override
public String[] relationshipIndexNames() public String[] relationshipIndexNames()
{ {
try ( Statement statement = transactionBridge.get() )
{ return transactionBridge.get().indexRead().relationshipExplicitIndexesGetAll();
return statement.readOperations().relationshipExplicitIndexesGetAll();
}
} }


@Override @Override
public Map<String,String> getConfiguration( Index<? extends PropertyContainer> index ) public Map<String,String> getConfiguration( Index<? extends PropertyContainer> index )
{ {
try ( Statement statement = transactionBridge.get() ) try
{ {
Transaction transaction = transactionBridge.get();
if ( index.getEntityType().equals( Node.class ) ) if ( index.getEntityType().equals( Node.class ) )
{ {
return statement.readOperations().nodeExplicitIndexGetConfiguration( index.getName() ); return transaction.indexRead().nodeExplicitIndexGetConfiguration( index.getName() );
} }
if ( index.getEntityType().equals( Relationship.class ) ) if ( index.getEntityType().equals( Relationship.class ) )
{ {
return statement.readOperations().relationshipExplicitIndexGetConfiguration( index.getName() ); return transaction.indexRead().relationshipExplicitIndexGetConfiguration( index.getName() );
} }
throw new IllegalArgumentException( "Unknown entity type " + index.getEntityType().getSimpleName() ); throw new IllegalArgumentException( "Unknown entity type " + index.getEntityType().getSimpleName() );
} }
Expand All @@ -166,15 +163,16 @@ public String setConfiguration( Index<? extends PropertyContainer> index, String
{ {
// Configuration changes should be done transactionally. However this // Configuration changes should be done transactionally. However this
// has always been done non-transactionally, so it's not a regression. // has always been done non-transactionally, so it's not a regression.
try ( Statement statement = transactionBridge.get() ) try
{ {
Transaction transaction = transactionBridge.get();
if ( index.getEntityType().equals( Node.class ) ) if ( index.getEntityType().equals( Node.class ) )
{ {
return statement.dataWriteOperations().nodeExplicitIndexSetConfiguration( index.getName(), key, value ); return transaction.indexWrite().nodeExplicitIndexSetConfiguration( index.getName(), key, value );
} }
if ( index.getEntityType().equals( Relationship.class ) ) if ( index.getEntityType().equals( Relationship.class ) )
{ {
return statement.dataWriteOperations().relationshipExplicitIndexSetConfiguration( return transaction.indexWrite().relationshipExplicitIndexSetConfiguration(
index.getName(), key, value ); index.getName(), key, value );
} }
throw new IllegalArgumentException( "Unknown entity type " + index.getEntityType().getSimpleName() ); throw new IllegalArgumentException( "Unknown entity type " + index.getEntityType().getSimpleName() );
Expand All @@ -194,15 +192,17 @@ public String removeConfiguration( Index<? extends PropertyContainer> index, Str
{ {
// Configuration changes should be done transactionally. However this // Configuration changes should be done transactionally. However this
// has always been done non-transactionally, so it's not a regression. // has always been done non-transactionally, so it's not a regression.
try ( Statement statement = transactionBridge.get() )
try
{ {
Transaction transaction = transactionBridge.get();
if ( index.getEntityType().equals( Node.class ) ) if ( index.getEntityType().equals( Node.class ) )
{ {
return statement.dataWriteOperations().nodeExplicitIndexRemoveConfiguration( index.getName(), key ); return transaction.indexWrite().nodeExplicitIndexRemoveConfiguration( index.getName(), key );
} }
if ( index.getEntityType().equals( Relationship.class ) ) if ( index.getEntityType().equals( Relationship.class ) )
{ {
return statement.dataWriteOperations().relationshipExplicitIndexRemoveConfiguration( return transaction.indexWrite().relationshipExplicitIndexRemoveConfiguration(
index.getName(), key ); index.getName(), key );
} }
throw new IllegalArgumentException( "Unknown entity type " + index.getEntityType().getSimpleName() ); throw new IllegalArgumentException( "Unknown entity type " + index.getEntityType().getSimpleName() );
Expand Down
Expand Up @@ -226,7 +226,8 @@ public void init( EditionModule editionModule, SPI spi, Guard guard, ThreadToSta
idxProvider.getOrCreateRelationshipIndex( RELATIONSHIP_AUTO_INDEX, null ) ), idxProvider.getOrCreateRelationshipIndex( RELATIONSHIP_AUTO_INDEX, null ) ),
spi.autoIndexing().relationships() ); spi.autoIndexing().relationships() );


return new IndexManagerImpl( txBridge, idxProvider, nodeAutoIndexer, relAutoIndexer ); return new IndexManagerImpl( () -> txBridge.getKernelTransactionBoundToThisThread( true ), idxProvider,
nodeAutoIndexer, relAutoIndexer );
} ); } );


this.contextFactory = Neo4jTransactionalContextFactory.create( spi, guard, txBridge, locker ); this.contextFactory = Neo4jTransactionalContextFactory.create( spi, guard, txBridge, locker );
Expand Down
Expand Up @@ -35,7 +35,6 @@
import org.neo4j.internal.kernel.api.exceptions.explicitindex.ExplicitIndexNotFoundKernelException; import org.neo4j.internal.kernel.api.exceptions.explicitindex.ExplicitIndexNotFoundKernelException;
import org.neo4j.kernel.api.InwardKernel; import org.neo4j.kernel.api.InwardKernel;
import org.neo4j.kernel.api.KernelTransaction; import org.neo4j.kernel.api.KernelTransaction;
import org.neo4j.kernel.api.Statement;
import org.neo4j.kernel.configuration.Config; import org.neo4j.kernel.configuration.Config;
import org.neo4j.kernel.spi.explicitindex.IndexImplementation; import org.neo4j.kernel.spi.explicitindex.IndexImplementation;


Expand Down Expand Up @@ -175,17 +174,16 @@ private Map<String, String> getOrCreateIndexConfig(


// We were the first one here, let's create this config // We were the first one here, let's create this config
try ( KernelTransaction transaction = try ( KernelTransaction transaction =
kernel.get().newTransaction( KernelTransaction.Type.implicit, AUTH_DISABLED ); kernel.get().newTransaction( KernelTransaction.Type.implicit, AUTH_DISABLED ) )
Statement statement = transaction.acquireStatement() )
{ {
switch ( entityType ) switch ( entityType )
{ {
case Node: case Node:
statement.dataWriteOperations().nodeExplicitIndexCreate( indexName, config ); transaction.indexWrite().nodeExplicitIndexCreate( indexName, config );
break; break;


case Relationship: case Relationship:
statement.dataWriteOperations().relationshipExplicitIndexCreate( indexName, config ); transaction.indexWrite().relationshipExplicitIndexCreate( indexName, config );
break; break;


default: default:
Expand Down
Expand Up @@ -288,6 +288,14 @@ public boolean nodeExplicitIndexExists( String indexName, Map<String,String> cus
return explicitIndexTxState().checkIndexExistence( IndexEntityType.Node, indexName, customConfiguration ); return explicitIndexTxState().checkIndexExistence( IndexEntityType.Node, indexName, customConfiguration );
} }


@Override
public Map<String,String> nodeExplicitIndexGetConfiguration( String indexName )
throws ExplicitIndexNotFoundKernelException
{
ktx.assertOpen();
return explicitIndexStore.getNodeIndexConfiguration( indexName );
}

@Override @Override
public String[] relationshipExplicitIndexesGetAll() public String[] relationshipExplicitIndexesGetAll()
{ {
Expand All @@ -302,6 +310,14 @@ public boolean relationshipExplicitIndexExists( String indexName, Map<String,Str
return explicitIndexTxState().checkIndexExistence( IndexEntityType.Relationship, indexName, customConfiguration ); return explicitIndexTxState().checkIndexExistence( IndexEntityType.Relationship, indexName, customConfiguration );
} }


@Override
public Map<String,String> relationshipExplicitIndexGetConfiguration( String indexName )
throws ExplicitIndexNotFoundKernelException
{
ktx.assertOpen();
return explicitIndexStore.getRelationshipIndexConfiguration( indexName );
}

@Override @Override
public CapableIndexReference index( int label, int... properties ) public CapableIndexReference index( int label, int... properties )
{ {
Expand Down Expand Up @@ -1019,6 +1035,11 @@ public void schemaStateFlush()
schemaState.clear(); schemaState.clear();
} }


ExplicitIndexStore explicitIndexStore()
{
return explicitIndexStore;
}

private RawIterator<Object[],ProcedureException> callProcedure( private RawIterator<Object[],ProcedureException> callProcedure(
int id, Object[] input, final AccessMode override ) int id, Object[] input, final AccessMode override )
throws ProcedureException throws ProcedureException
Expand Down
Expand Up @@ -642,6 +642,22 @@ public void nodeExplicitIndexDrop( String indexName ) throws ExplicitIndexNotFou
txState.deleteIndex( IndexEntityType.Node, indexName ); txState.deleteIndex( IndexEntityType.Node, indexName );
} }


@Override
public String nodeExplicitIndexSetConfiguration( String indexName, String key, String value )
throws ExplicitIndexNotFoundKernelException
{
ktx.assertOpen();
return allStoreHolder.explicitIndexStore().setNodeIndexConfiguration( indexName, key, value );
}

@Override
public String nodeExplicitIndexRemoveConfiguration( String indexName, String key )
throws ExplicitIndexNotFoundKernelException
{
ktx.assertOpen();
return allStoreHolder.explicitIndexStore().removeNodeIndexConfiguration( indexName, key );
}

@Override @Override
public void relationshipAddToExplicitIndex( String indexName, long relationship, String key, Object value ) public void relationshipAddToExplicitIndex( String indexName, long relationship, String key, Object value )
throws ExplicitIndexNotFoundKernelException, EntityNotFoundException throws ExplicitIndexNotFoundKernelException, EntityNotFoundException
Expand Down Expand Up @@ -966,6 +982,22 @@ public ConstraintDescriptor relationshipPropertyExistenceConstraintCreate( Relat


} }


@Override
public String relationshipExplicitIndexSetConfiguration( String indexName, String key, String value )
throws ExplicitIndexNotFoundKernelException
{
ktx.assertOpen();
return allStoreHolder.explicitIndexStore().setRelationshipIndexConfiguration( indexName, key, value );
}

@Override
public String relationshipExplicitIndexRemoveConfiguration( String indexName, String key )
throws ExplicitIndexNotFoundKernelException
{
ktx.assertOpen();
return allStoreHolder.explicitIndexStore().removeRelationshipIndexConfiguration( indexName, key );
}

@Override @Override
public void constraintDrop( ConstraintDescriptor descriptor ) throws SchemaKernelException public void constraintDrop( ConstraintDescriptor descriptor ) throws SchemaKernelException
{ {
Expand Down
Expand Up @@ -372,10 +372,8 @@ private void deleteNode( long nodeId ) throws KernelException
{ {
try ( Transaction tx = db.beginTx() ) try ( Transaction tx = db.beginTx() )
{ {
try ( Statement statement = bridge.get() )
{ bridge.getKernelTransactionBoundToThisThread( true ).dataWrite().nodeDelete( nodeId );
statement.dataWriteOperations().nodeDelete( nodeId );
}
tx.success(); tx.success();
} }
} }
Expand Down
Expand Up @@ -36,6 +36,7 @@
import org.neo4j.internal.kernel.api.InternalIndexState; import org.neo4j.internal.kernel.api.InternalIndexState;
import org.neo4j.internal.kernel.api.exceptions.KernelException; import org.neo4j.internal.kernel.api.exceptions.KernelException;
import org.neo4j.internal.kernel.api.exceptions.ProcedureException; import org.neo4j.internal.kernel.api.exceptions.ProcedureException;
import org.neo4j.internal.kernel.api.exceptions.explicitindex.ExplicitIndexNotFoundKernelException;
import org.neo4j.internal.kernel.api.exceptions.schema.SchemaKernelException; import org.neo4j.internal.kernel.api.exceptions.schema.SchemaKernelException;
import org.neo4j.internal.kernel.api.procs.ProcedureHandle; import org.neo4j.internal.kernel.api.procs.ProcedureHandle;
import org.neo4j.internal.kernel.api.procs.ProcedureSignature; import org.neo4j.internal.kernel.api.procs.ProcedureSignature;
Expand Down Expand Up @@ -416,6 +417,13 @@ public boolean nodeExplicitIndexExists( String indexName, Map<String,String> cus
throw new UnsupportedOperationException(); throw new UnsupportedOperationException();
} }


@Override
public Map<String,String> nodeExplicitIndexGetConfiguration( String indexName )
throws ExplicitIndexNotFoundKernelException
{
throw new UnsupportedOperationException();
}

@Override @Override
public boolean relationshipExplicitIndexExists( String indexName, Map<String,String> customConfiguration ) public boolean relationshipExplicitIndexExists( String indexName, Map<String,String> customConfiguration )
{ {
Expand All @@ -434,6 +442,13 @@ public String[] relationshipExplicitIndexesGetAll()
throw new UnsupportedOperationException(); throw new UnsupportedOperationException();
} }


@Override
public Map<String,String> relationshipExplicitIndexGetConfiguration( String indexName )
throws ExplicitIndexNotFoundKernelException
{
throw new UnsupportedOperationException();
}

private abstract static class Record<R extends AbstractBaseRecord> private abstract static class Record<R extends AbstractBaseRecord>
{ {
abstract void initialize( R record ); abstract void initialize( R record );
Expand Down

0 comments on commit 573df2c

Please sign in to comment.