public Stream<BuiltInProcedures.SchemaIndexInfo> createIndex( String indexSpecification, String providerName ) throws ProcedureException { return createIndex( indexSpecification, providerName, "index created", ( schemaWrite, descriptor, provider ) -> schemaWrite.indexCreate( descriptor, provider, Optional.empty() ) ); }
private ThrowingAction<Exception> dropAndReCreateIndex( IndexReference descriptor, SchemaDescriptor newDescriptor ) { return () -> { aliceLatch.await(); bobLatch.await(); try ( KernelTransactionImplementation transaction = getKernelTransaction() ) { SchemaWrite schemaWrite = transaction.schemaWrite(); schemaWrite.indexDrop( descriptor ); schemaWrite.indexCreate( newDescriptor, FulltextIndexProviderFactory.DESCRIPTOR.name(), Optional.of( "nodes" ) ); transaction.success(); } }; }
private IndexReference createIndex( int[] entityTokens, int[] propertyIds ) throws TransactionFailureException, InvalidTransactionTypeKernelException, SchemaKernelException { IndexReference fulltext; try ( KernelTransactionImplementation transaction = getKernelTransaction() ) { MultiTokenSchemaDescriptor multiTokenSchemaDescriptor = multiToken( entityTokens, EntityType.NODE, propertyIds ); FulltextSchemaDescriptor schema = new FulltextSchemaDescriptor( multiTokenSchemaDescriptor, new Properties() ); fulltext = transaction.schemaWrite().indexCreate( schema, DESCRIPTOR.name(), Optional.of( NAME ) ); transaction.success(); } return fulltext; }
private IndexReference createInitialIndex( SchemaDescriptor descriptor ) throws Exception { IndexReference index; try ( KernelTransactionImplementation transaction = getKernelTransaction() ) { SchemaWrite schemaWrite = transaction.schemaWrite(); index = schemaWrite.indexCreate( descriptor, FulltextIndexProviderFactory.DESCRIPTOR.name(), Optional.of( "nodes" ) ); transaction.success(); } await( index ); return index; }
@Test public void createdIndexShouldPopulateInTx() throws Exception { IndexReference index; try ( Transaction tx = beginTransaction() ) { index = tx.schemaWrite().indexCreate( labelDescriptor( label, prop1 ) ); assertThat( tx.schemaRead().indexGetState( index ), equalTo( InternalIndexState.POPULATING ) ); tx.success(); } }
private IndexReference createIndex() throws KernelException { try ( Transaction transaction = kernel.beginTransaction( implicit, AUTH_DISABLED ) ) { IndexReference reference = transaction.schemaWrite().indexCreate( SchemaDescriptorFactory.forLabel( 1, 1 ) ); transaction.success(); return reference; } }
@Test( expected = SchemaKernelException.class ) public void shouldFailIndexCreateForRepeatedProperties() throws Exception { try ( Transaction tx = beginTransaction() ) { tx.schemaWrite().indexCreate( labelDescriptor( label, prop1, prop1 ) ); } }
@Test public void shouldSeeIndexFromTransaction() throws Exception { try ( Transaction transaction = beginTransaction() ) { transaction.schemaWrite().indexCreate( labelDescriptor( label, prop1 ) ); transaction.success(); } try ( Transaction transaction = beginTransaction() ) { transaction.schemaWrite().indexCreate( labelDescriptor( label, prop2 ) ); SchemaRead schemaRead = transaction.schemaRead(); IndexReference index = schemaRead.index( label, prop2 ); assertThat( index.properties(), equalTo( new int[]{prop2} ) ); assertThat( 2, equalTo( Iterators.asList( schemaRead.indexesGetAll() ).size() ) ); } }
@Test( timeout = 10_000 ) public void createIndexesForDifferentLabelsConcurrently() throws Throwable { TokenWrite tokenWrite = tokenWriteInNewTransaction(); int label2 = tokenWrite.labelGetOrCreateForName( "Label2" ); LabelSchemaDescriptor anotherLabelDescriptor = SchemaDescriptorFactory.forLabel( label2, propertyKeyId ); schemaWriteInNewTransaction().indexCreate( anotherLabelDescriptor ); Future<?> indexFuture = executorService.submit( createIndex( db, label( LABEL ), PROPERTY_KEY ) ); indexFuture.get(); commit(); }
private IndexReference createIndex( org.neo4j.internal.kernel.api.Transaction transaction ) throws SchemaKernelException, InvalidTransactionTypeKernelException { TokenWrite tokenWrite = transaction.tokenWrite(); SchemaWrite schemaWrite = transaction.schemaWrite(); LabelSchemaDescriptor schemaDescriptor = forLabel( tokenWrite.labelGetOrCreateForName( "hello" ), tokenWrite.propertyKeyGetOrCreateForName( "hepp" ) ); return schemaWrite.indexCreate( schemaDescriptor ); }
@Test public void shouldCreateIndex() throws Exception { IndexReference index; try ( Transaction transaction = beginTransaction() ) { index = transaction.schemaWrite().indexCreate( labelDescriptor( label, prop1 ) ); transaction.success(); } try ( Transaction transaction = beginTransaction() ) { SchemaRead schemaRead = transaction.schemaRead(); assertThat( schemaRead.index( label, prop1 ), equalTo( index ) ); } }
@Test public void createAndRetainRelationshipFulltextIndex() throws Exception { IndexReference indexReference; try ( KernelTransactionImplementation transaction = getKernelTransaction() ) { MultiTokenSchemaDescriptor multiTokenSchemaDescriptor = multiToken( new int[]{0, 1, 2}, EntityType.RELATIONSHIP, 0, 1, 2, 3 ); FulltextSchemaDescriptor schema = new FulltextSchemaDescriptor( multiTokenSchemaDescriptor, new Properties() ); indexReference = transaction.schemaWrite().indexCreate( schema, DESCRIPTOR.name(), Optional.of( "fulltext" ) ); transaction.success(); } await( indexReference ); db.restartDatabase( DatabaseRule.RestartAction.EMPTY ); verifyThatFulltextIndexIsPresent( indexReference ); }
@Test public void shouldListAll() throws Exception { // given SchemaWrite schemaWrite = schemaWriteInNewTransaction(); IndexReference index1 = schemaWrite.indexCreate( descriptor ); IndexReference index2 = ((IndexBackedConstraintDescriptor) schemaWrite.uniquePropertyConstraintCreate( descriptor2 )) .ownedIndexDescriptor(); commit(); // then/when SchemaRead schemaRead = newTransaction().schemaRead(); List<IndexReference> indexes = Iterators.asList( schemaRead.indexesGetAll() ); assertThat( indexes, containsInAnyOrder( index1, index2 ) ); commit(); }
@Test public void shouldNotSeeDroppedIndexFromTransaction() throws Exception { IndexReference index; try ( Transaction transaction = beginTransaction() ) { index = transaction.schemaWrite().indexCreate( labelDescriptor( label, prop1 ) ); transaction.success(); } try ( Transaction transaction = beginTransaction() ) { transaction.schemaWrite().indexDrop( index ); SchemaRead schemaRead = transaction.schemaRead(); assertThat( schemaRead.index( label, prop2 ), equalTo( NO_INDEX ) ); } }
@Test public void rollBackIndexRuleShouldNotBeCommitted() throws Exception { // GIVEN SchemaWrite schemaWrite = schemaWriteInNewTransaction(); // WHEN schemaWrite.indexCreate( descriptor ); // don't mark as success rollback(); // THEN Transaction transaction = newTransaction(); assertEquals( emptySet(), asSet( transaction.schemaRead().indexesGetForLabel( labelId ) ) ); commit(); }
@Test public void committedAndTransactionalIndexRulesShouldBeMerged() throws Exception { // GIVEN SchemaWrite schemaWriteOperations = schemaWriteInNewTransaction(); IndexReference existingRule = schemaWriteOperations.indexCreate( descriptor ); commit(); // WHEN Transaction transaction = newTransaction( AUTH_DISABLED ); IndexReference addedRule = transaction.schemaWrite() .indexCreate( SchemaDescriptorFactory.forLabel( labelId, 10 ) ); Set<IndexReference> indexRulesInTx = asSet( transaction.schemaRead().indexesGetForLabel( labelId ) ); commit(); // THEN assertEquals( asSet( existingRule, addedRule ), indexRulesInTx ); }
@Test public void createIndexForAnotherLabelWhileHoldingSharedLockOnOtherLabel() throws KernelException { TokenWrite tokenWrite = tokenWriteInNewTransaction(); int label2 = tokenWrite.labelGetOrCreateForName( "Label2" ); Write write = dataWriteInNewTransaction(); long nodeId = write.nodeCreate(); write.nodeAddLabel( nodeId, label2 ); schemaWriteInNewTransaction().indexCreate( descriptor ); commit(); }
@Override protected void createCompositeIndex( GraphDatabaseService graphDb, String label, String... properties ) throws Exception { GraphDatabaseAPI internal = (GraphDatabaseAPI) graphDb; KernelTransaction ktx = internal.getDependencyResolver() .resolveDependency( ThreadToStatementContextBridge.class ) .getKernelTransactionBoundToThisThread( true ); SchemaWrite schemaWrite = ktx.schemaWrite(); TokenWrite token = ktx.tokenWrite(); schemaWrite.indexCreate( SchemaDescriptorFactory.forLabel( token.labelGetOrCreateForName( "Person" ), token.propertyKeyGetOrCreateForName( "firstname" ), token.propertyKeyGetOrCreateForName( "surname" ) ) ); } }
private IndexReference createPersonNameIndex() throws KernelException { try ( Transaction tx = db.beginTx() ) { IndexReference index; KernelTransaction ktx = bridge.getKernelTransactionBoundToThisThread( true ); try ( Statement ignore = ktx.acquireStatement() ) { int labelId = ktx.tokenWrite().labelGetOrCreateForName( PERSON_LABEL ); int propertyKeyId = ktx.tokenWrite().propertyKeyGetOrCreateForName( NAME_PROPERTY ); LabelSchemaDescriptor descriptor = forLabel( labelId, propertyKeyId ); index = ktx.schemaWrite().indexCreate( descriptor ); } tx.success(); return index; } }
@Test public void addIndexRuleInATransaction() throws Exception { // GIVEN SchemaWrite schemaWriteOperations = schemaWriteInNewTransaction(); // WHEN IndexReference expectedRule = schemaWriteOperations.indexCreate( descriptor ); commit(); // THEN SchemaRead schemaRead = newTransaction().schemaRead(); assertEquals( asSet( expectedRule ), asSet( schemaRead.indexesGetForLabel( labelId ) ) ); assertEquals( expectedRule, schemaRead.index( descriptor.getLabelId(), descriptor.getPropertyIds() ) ); commit(); }