Skip to content

Commit

Permalink
Kernel API has ability to specify provider at index creation
Browse files Browse the repository at this point in the history
  • Loading branch information
tinwelint authored and MishaDemianenko committed Jun 9, 2018
1 parent de09ebb commit eeb58d8
Show file tree
Hide file tree
Showing 31 changed files with 252 additions and 68 deletions.
Expand Up @@ -62,11 +62,11 @@
import org.neo4j.internal.kernel.api.TokenRead;
import org.neo4j.internal.kernel.api.TokenWrite;
import org.neo4j.internal.kernel.api.exceptions.KernelException;
import org.neo4j.internal.kernel.api.exceptions.TransactionFailureException;
import org.neo4j.io.pagecache.IOLimiter;
import org.neo4j.kernel.api.KernelTransaction;
import org.neo4j.kernel.api.Statement;
import org.neo4j.kernel.api.direct.DirectStoreAccess;
import org.neo4j.internal.kernel.api.exceptions.TransactionFailureException;
import org.neo4j.kernel.api.index.IndexAccessor;
import org.neo4j.kernel.api.index.IndexEntryUpdate;
import org.neo4j.kernel.api.index.IndexPopulator;
Expand Down Expand Up @@ -229,7 +229,7 @@ protected void generateInitialData( GraphDatabaseService db )
key1 = tokenWrite.propertyKeyGetOrCreateForName( PROP1 );
key2 = tokenWrite.propertyKeyGetOrCreateForName( PROP2 );
label3 = ktx.tokenRead().nodeLabel( "label3" );
ktx.schemaWrite().indexCreate( SchemaDescriptorFactory.forLabel( label3, key1, key2 ) );
ktx.schemaWrite().indexCreate( SchemaDescriptorFactory.forLabel( label3, key1, key2 ), null );
}

db.schema().constraintFor( label( "label4" ) ).assertPropertyIsUnique( PROP1 ).create();
Expand Down
Expand Up @@ -716,7 +716,7 @@ final class TransactionBoundQueryContext(tc: TransactionalContextWrapper, val re
def addIndexRule(labelId: Int, propertyKeyId: Int): IdempotentResult[SchemaTypes.IndexDescriptor] = try {
IdempotentResult(
DefaultIndexReference.toDescriptor(
tc.kernelTransaction.schemaWrite().indexCreate(SchemaDescriptorFactory.forLabel(labelId, propertyKeyId)))
tc.kernelTransaction.schemaWrite().indexCreate(SchemaDescriptorFactory.forLabel(labelId, propertyKeyId), null))
)
} catch {
case _: AlreadyIndexedException =>
Expand Down
Expand Up @@ -36,7 +36,7 @@ import org.neo4j.cypher.internal.compiler.v3_1.spi._
import org.neo4j.cypher.internal.frontend.v3_1.SemanticDirection.{BOTH, INCOMING, OUTGOING}
import org.neo4j.cypher.internal.frontend.v3_1.{Bound, EntityNotFoundException, FailedIndexException, SemanticDirection}
import org.neo4j.cypher.internal.javacompat.GraphDatabaseCypherService
import org.neo4j.cypher.internal.runtime.interpreted.{JavaConversionSupport, ResourceManager}
import org.neo4j.cypher.internal.runtime.interpreted.ResourceManager
import org.neo4j.cypher.internal.spi.v3_1.TransactionBoundQueryContext.IndexSearchMonitor
import org.neo4j.cypher.internal.spi.{CursorIterator, PrimitiveCursorIterator}
import org.neo4j.graphalgo.impl.path.ShortestPath
Expand Down Expand Up @@ -731,7 +731,7 @@ final class TransactionBoundQueryContext(txContext: TransactionalContextWrapper,
override def addIndexRule(labelId: Int, propertyKeyId: Int): IdempotentResult[IndexDescriptor] = try {
IdempotentResult(
DefaultIndexReference.toDescriptor(
txContext.kernelTransaction.schemaWrite().indexCreate(SchemaDescriptorFactory.forLabel(labelId, propertyKeyId)))
txContext.kernelTransaction.schemaWrite().indexCreate(SchemaDescriptorFactory.forLabel(labelId, propertyKeyId), null))
)
} catch {
case _: AlreadyIndexedException =>
Expand Down
Expand Up @@ -640,7 +640,7 @@ sealed class TransactionBoundQueryContext(val transactionalContext: Transactiona
override def addIndexRule(descriptor: IndexDescriptor): IdempotentResult[IndexReference] = {
val kernelDescriptor = cypherToKernelSchema(descriptor)
try {
IdempotentResult(transactionalContext.kernelTransaction.schemaWrite().indexCreate(kernelDescriptor))
IdempotentResult(transactionalContext.kernelTransaction.schemaWrite().indexCreate(kernelDescriptor, null))
} catch {
case _: AlreadyIndexedException =>
val indexReference = transactionalContext.kernelTransaction.schemaRead().index(kernelDescriptor.getLabelId, kernelDescriptor.getPropertyIds: _*)
Expand Down
Expand Up @@ -31,12 +31,13 @@
public interface SchemaWrite
{
/**
* Create index from schema descriptor
* Create index from schema descriptor. Optionally a specific provider name can be specified.
*
* @param descriptor description of the index
* @param providerName specific index provider this index will be created for. If {@code null} then the default configured will be used.
* @return the newly created index
*/
IndexReference indexCreate( SchemaDescriptor descriptor ) throws SchemaKernelException;
IndexReference indexCreate( SchemaDescriptor descriptor, String providerName ) throws SchemaKernelException;

/**
* Drop the given index
Expand Down
Expand Up @@ -96,7 +96,7 @@ public void shouldCreateIndex() throws Exception
IndexReference index;
try ( Transaction transaction = session.beginTransaction() )
{
index = transaction.schemaWrite().indexCreate( labelDescriptor( label, prop1 ) );
index = transaction.schemaWrite().indexCreate( labelDescriptor( label, prop1 ), null );
transaction.success();
}

Expand All @@ -112,7 +112,7 @@ public void shouldGetUndecidedVersionAndKeyFromIndexReference() throws Exception
{
try ( Transaction transaction = session.beginTransaction() )
{
transaction.schemaWrite().indexCreate( labelDescriptor( label, prop1 ) );
transaction.schemaWrite().indexCreate( labelDescriptor( label, prop1 ), null );
CapableIndexReference index = transaction.schemaRead().index( label, prop1 );

assertThat( index.providerKey(), equalTo( "Undecided" ));
Expand All @@ -126,7 +126,7 @@ public void createdIndexShouldPopulateInTx() throws Exception
IndexReference index;
try ( Transaction tx = session.beginTransaction() )
{
index = tx.schemaWrite().indexCreate( labelDescriptor( label, prop1 ) );
index = tx.schemaWrite().indexCreate( labelDescriptor( label, prop1 ), null );
assertThat( tx.schemaRead().indexGetState( index ), equalTo( InternalIndexState.POPULATING ) );
tx.success();
}
Expand All @@ -138,7 +138,7 @@ public void shouldDropIndex() throws Exception
IndexReference index;
try ( Transaction transaction = session.beginTransaction() )
{
index = transaction.schemaWrite().indexCreate( labelDescriptor( label, prop1 ) );
index = transaction.schemaWrite().indexCreate( labelDescriptor( label, prop1 ), null );
transaction.success();
}

Expand All @@ -161,7 +161,7 @@ public void shouldFailIfExistingIndex() throws Exception
//Given
try ( Transaction transaction = session.beginTransaction() )
{
transaction.schemaWrite().indexCreate( labelDescriptor( label, prop1 ) );
transaction.schemaWrite().indexCreate( labelDescriptor( label, prop1 ), null );
transaction.success();
}

Expand All @@ -171,7 +171,7 @@ public void shouldFailIfExistingIndex() throws Exception
//When
try ( Transaction transaction = session.beginTransaction() )
{
transaction.schemaWrite().indexCreate( labelDescriptor( label, prop1 ) );
transaction.schemaWrite().indexCreate( labelDescriptor( label, prop1 ), null );
transaction.success();
}
}
Expand All @@ -181,13 +181,13 @@ public void shouldSeeIndexFromTransaction() throws Exception
{
try ( Transaction transaction = session.beginTransaction() )
{
transaction.schemaWrite().indexCreate( labelDescriptor( label, prop1 ) );
transaction.schemaWrite().indexCreate( labelDescriptor( label, prop1 ), null );
transaction.success();
}

try ( Transaction transaction = session.beginTransaction() )
{
transaction.schemaWrite().indexCreate( labelDescriptor( label, prop2 ) );
transaction.schemaWrite().indexCreate( labelDescriptor( label, prop2 ), null );
SchemaRead schemaRead = transaction.schemaRead();
CapableIndexReference index = schemaRead.index( label, prop2 );
assertThat( index.properties(), equalTo( new int[]{prop2} ) );
Expand All @@ -201,7 +201,7 @@ public void shouldNotSeeDroppedIndexFromTransaction() throws Exception
IndexReference index;
try ( Transaction transaction = session.beginTransaction() )
{
index = transaction.schemaWrite().indexCreate( labelDescriptor( label, prop1 ) );
index = transaction.schemaWrite().indexCreate( labelDescriptor( label, prop1 ), null );
transaction.success();
}

Expand All @@ -223,15 +223,15 @@ public void shouldListAllIndexes() throws Exception

try ( Transaction tx = session.beginTransaction() )
{
toRetain = tx.schemaWrite().indexCreate( labelDescriptor( label, prop1 ) );
toRetain2 = tx.schemaWrite().indexCreate( labelDescriptor( label2, prop1 ) );
toDrop = tx.schemaWrite().indexCreate( labelDescriptor( label, prop2 ) );
toRetain = tx.schemaWrite().indexCreate( labelDescriptor( label, prop1 ), null );
toRetain2 = tx.schemaWrite().indexCreate( labelDescriptor( label2, prop1 ), null );
toDrop = tx.schemaWrite().indexCreate( labelDescriptor( label, prop2 ), null );
tx.success();
}

try ( Transaction tx = session.beginTransaction() )
{
created = tx.schemaWrite().indexCreate( labelDescriptor( label2, prop2 ) );
created = tx.schemaWrite().indexCreate( labelDescriptor( label2, prop2 ), null );
tx.schemaWrite().indexDrop( toDrop );

Iterable<IndexReference> allIndexes = () -> tx.schemaRead().indexesGetAll();
Expand All @@ -255,16 +255,16 @@ public void shouldListIndexesByLabel() throws Exception
wrongLabel = tx.tokenWrite().labelGetOrCreateForName( "wrongLabel" );
tx.schemaWrite().uniquePropertyConstraintCreate( labelDescriptor( wrongLabel, prop1 ) );

inStore = tx.schemaWrite().indexCreate( labelDescriptor( label, prop1 ) );
droppedInTx = tx.schemaWrite().indexCreate( labelDescriptor( label, prop2 ) );
inStore = tx.schemaWrite().indexCreate( labelDescriptor( label, prop1 ), null );
droppedInTx = tx.schemaWrite().indexCreate( labelDescriptor( label, prop2 ), null );

tx.success();
}

try ( Transaction tx = session.beginTransaction() )
{
createdInTx = tx.schemaWrite().indexCreate( labelDescriptor( label, prop3 ) );
tx.schemaWrite().indexCreate( labelDescriptor( wrongLabel, prop2 ) );
createdInTx = tx.schemaWrite().indexCreate( labelDescriptor( label, prop3 ), null );
tx.schemaWrite().indexCreate( labelDescriptor( wrongLabel, prop2 ), null );
tx.schemaWrite().indexDrop( droppedInTx );

Iterable<IndexReference> indexes = () -> tx.schemaRead().indexesGetForLabel( label );
Expand Down Expand Up @@ -323,7 +323,7 @@ public void shouldFailToCreateUniqueConstraintIfExistingIndex() throws Exception
//Given
try ( Transaction transaction = session.beginTransaction() )
{
transaction.schemaWrite().indexCreate( labelDescriptor( label, prop1 ) );
transaction.schemaWrite().indexCreate( labelDescriptor( label, prop1 ), null );
transaction.success();
}

Expand Down
Expand Up @@ -538,6 +538,7 @@ public class GraphDatabaseSettings implements LoadableConfig

public enum SchemaIndex
{
// These strings are supposed to match provider names, i.e. key-version, see IndexProvider.Descriptor#name()
NATIVE20( "lucene+native-2.0" ),
NATIVE10( "lucene+native-1.0" ),
LUCENE10( "lucene-1.0" );
Expand Down
Expand Up @@ -687,7 +687,7 @@ private NeoStoreKernelModule buildKernel( LogFiles logFiles, TransactionAppender
availabilityGuard, tracers, storageEngine, procedures, transactionIdStore, clock,
cpuClockRef, heapAllocationRef, accessCapability, DefaultCursors::new, autoIndexing,
explicitIndexStore, versionContextSupplier, collectionsFactorySupplier, constraintSemantics,
databaseSchemaState, indexingService ) );
databaseSchemaState, indexingService, indexProviderMap ) );

buildTransactionMonitor( kernelTransactions, clock, config );

Expand Down
Expand Up @@ -309,6 +309,14 @@ public String getVersion()
return version;
}

/**
* @return a combination of {@link #getKey()} and {@link #getVersion()} with a '-' in between.
*/
public String name()
{
return key + "-" + version;
}

@Override
public int hashCode()
{
Expand Down
Expand Up @@ -52,6 +52,7 @@
import org.neo4j.internal.kernel.api.TokenWrite;
import org.neo4j.internal.kernel.api.Write;
import org.neo4j.internal.kernel.api.exceptions.InvalidTransactionTypeKernelException;
import org.neo4j.internal.kernel.api.exceptions.TransactionFailureException;
import org.neo4j.internal.kernel.api.exceptions.schema.ConstraintValidationException;
import org.neo4j.internal.kernel.api.security.AccessMode;
import org.neo4j.internal.kernel.api.security.AuthSubject;
Expand All @@ -63,13 +64,13 @@
import org.neo4j.kernel.api.SilentTokenNameLookup;
import org.neo4j.kernel.api.exceptions.ConstraintViolationTransactionFailureException;
import org.neo4j.kernel.api.exceptions.Status;
import org.neo4j.internal.kernel.api.exceptions.TransactionFailureException;
import org.neo4j.kernel.api.exceptions.schema.CreateConstraintFailureException;
import org.neo4j.kernel.api.explicitindex.AutoIndexing;
import org.neo4j.kernel.api.schema.index.SchemaIndexDescriptor;
import org.neo4j.kernel.api.txstate.ExplicitIndexTransactionState;
import org.neo4j.kernel.api.txstate.TransactionState;
import org.neo4j.kernel.api.txstate.TxStateHolder;
import org.neo4j.kernel.impl.api.index.IndexProviderMap;
import org.neo4j.kernel.impl.api.index.IndexingService;
import org.neo4j.kernel.impl.api.state.ConstraintIndexCreator;
import org.neo4j.kernel.impl.api.state.TxState;
Expand Down Expand Up @@ -195,7 +196,8 @@ public KernelTransactionImplementation( StatementOperationParts statementOperati
StorageEngine storageEngine, AccessCapability accessCapability, DefaultCursors cursors, AutoIndexing autoIndexing,
ExplicitIndexStore explicitIndexStore, VersionContextSupplier versionContextSupplier,
CollectionsFactorySupplier collectionsFactorySupplier, ConstraintSemantics constraintSemantics,
SchemaState schemaState, IndexingService indexingService )
SchemaState schemaState, IndexingService indexingService,
IndexProviderMap indexProviderMap )
{
this.schemaWriteGuard = schemaWriteGuard;
this.hooks = hooks;
Expand Down Expand Up @@ -227,7 +229,8 @@ public KernelTransactionImplementation( StatementOperationParts statementOperati
new IndexTxStateUpdater( storageEngine.storeReadLayer(), allStoreHolder, indexingService ),
storageStatement,
this, new KernelToken( storeLayer, this ), cursors, autoIndexing, constraintIndexCreator,
constraintSemantics );
constraintSemantics,
indexProviderMap );
this.collectionsFactory = collectionsFactorySupplier.create();
}

Expand Down
Expand Up @@ -40,6 +40,7 @@
import org.neo4j.kernel.api.exceptions.Status;
import org.neo4j.kernel.api.explicitindex.AutoIndexing;
import org.neo4j.kernel.api.txstate.ExplicitIndexTransactionState;
import org.neo4j.kernel.impl.api.index.IndexProviderMap;
import org.neo4j.kernel.impl.api.index.IndexingService;
import org.neo4j.kernel.impl.api.state.ConstraintIndexCreator;
import org.neo4j.kernel.impl.api.state.ExplicitIndexTransactionStateImpl;
Expand Down Expand Up @@ -102,6 +103,7 @@ public class KernelTransactions extends LifecycleAdapter implements Supplier<Ker
private final AutoIndexing autoIndexing;
private final ExplicitIndexStore explicitIndexStore;
private final IndexingService indexingService;
private final IndexProviderMap indexProviderMap;
private final CollectionsFactorySupplier collectionsFactorySupplier;
private final SchemaState schemaState;

Expand Down Expand Up @@ -150,7 +152,8 @@ public KernelTransactions( StatementLocksFactory statementLocksFactory,
CollectionsFactorySupplier collectionsFactorySupplier,
ConstraintSemantics constraintSemantics,
SchemaState schemaState,
IndexingService indexingService )
IndexingService indexingService,
IndexProviderMap indexProviderMap )
{
this.statementLocksFactory = statementLocksFactory;
this.constraintIndexCreator = constraintIndexCreator;
Expand All @@ -171,6 +174,7 @@ public KernelTransactions( StatementLocksFactory statementLocksFactory,
this.autoIndexing = autoIndexing;
this.explicitIndexStore = explicitIndexStore;
this.indexingService = indexingService;
this.indexProviderMap = indexProviderMap;
this.explicitIndexTxStateSupplier = () ->
new CachingExplicitIndexTransactionState(
new ExplicitIndexTransactionStateImpl( indexConfigStore, explicitIndexProviderLookup ) );
Expand Down Expand Up @@ -374,7 +378,8 @@ public KernelTransactionImplementation newInstance()
tracers.pageCursorTracerSupplier, storageEngine, accessCapability,
cursorsSupplier.get(), autoIndexing,
explicitIndexStore, versionContextSupplier, collectionsFactorySupplier, constraintSemantics,
schemaState, indexingService );
schemaState, indexingService,
indexProviderMap );
this.transactions.add( tx );
return tx;
}
Expand Down

0 comments on commit eeb58d8

Please sign in to comment.