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(); } }; }
@Test public void shouldListAllConstraints() throws Exception { ConstraintDescriptor toRetain; ConstraintDescriptor toRetain2; ConstraintDescriptor toDrop; ConstraintDescriptor created; try ( Transaction tx = beginTransaction() ) { toRetain = tx.schemaWrite().uniquePropertyConstraintCreate( labelDescriptor( label, prop1 ) ); toRetain2 = tx.schemaWrite().uniquePropertyConstraintCreate( labelDescriptor( label2, prop1 ) ); toDrop = tx.schemaWrite().uniquePropertyConstraintCreate( labelDescriptor( label, prop2 ) ); tx.success(); } try ( Transaction tx = beginTransaction() ) { created = tx.schemaWrite().nodePropertyExistenceConstraintCreate( labelDescriptor( label, prop1 ) ); tx.schemaWrite().constraintDrop( toDrop ); Iterable<ConstraintDescriptor> allConstraints = () -> tx.schemaRead().constraintsGetAll(); assertThat( allConstraints, containsInAnyOrder( toRetain, toRetain2, created ) ); tx.success(); } }
@Test public void shouldNotSeeDroppedNodeKeyConstraintFromTransaction() throws Exception { ConstraintDescriptor existing; try ( Transaction transaction = beginTransaction() ) { existing = transaction.schemaWrite().nodeKeyConstraintCreate( labelDescriptor( label, prop1 ) ); transaction.success(); } try ( Transaction transaction = beginTransaction() ) { transaction.schemaWrite().constraintDrop( existing ); SchemaRead schemaRead = transaction.schemaRead(); assertFalse( schemaRead.constraintExists( existing ) ); assertThat( asList( schemaRead.constraintsGetForLabel( label ) ), empty() ); } }
@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(); }
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() ) ); }
@Test public void shouldListIndexesByLabel() throws Exception { int wrongLabel; IndexReference inStore; IndexReference droppedInTx; IndexReference createdInTx; try ( Transaction tx = beginTransaction() ) { 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 ) ); tx.success(); } try ( Transaction tx = beginTransaction() ) { createdInTx = tx.schemaWrite().indexCreate( labelDescriptor( label, prop3 ) ); tx.schemaWrite().indexCreate( labelDescriptor( wrongLabel, prop2 ) ); tx.schemaWrite().indexDrop( droppedInTx ); Iterable<IndexReference> indexes = () -> tx.schemaRead().indexesGetForLabel( label ); assertThat( indexes, containsInAnyOrder( inStore, createdInTx ) ); tx.success(); } }
@Description( "Drop the specified index." ) @Procedure( name = "db.index.fulltext.drop", mode = SCHEMA ) public void drop( @Name( "indexName" ) String name ) throws InvalidTransactionTypeKernelException, SchemaKernelException { IndexReference indexReference = getValidIndexReference( name ); tx.schemaWrite().indexDrop( indexReference ); }
@Before public void setUp() throws Exception { try ( Transaction transaction = beginTransaction() ) { SchemaRead schemaRead = transaction.schemaRead(); SchemaWrite schemaWrite = transaction.schemaWrite(); Iterator<ConstraintDescriptor> constraints = schemaRead.constraintsGetAll(); while ( constraints.hasNext() ) { schemaWrite.constraintDrop( constraints.next() ); } Iterator<IndexReference> indexes = schemaRead.indexesGetAll(); while ( indexes.hasNext() ) { schemaWrite.indexDrop( indexes.next() ); } TokenWrite tokenWrite = transaction.tokenWrite(); label = tokenWrite.labelGetOrCreateForName( "label" ); label2 = tokenWrite.labelGetOrCreateForName( "label2" ); type = tokenWrite.relationshipTypeGetOrCreateForName( "relationship" ); prop1 = tokenWrite.propertyKeyGetOrCreateForName( "prop1" ); prop2 = tokenWrite.propertyKeyGetOrCreateForName( "prop2" ); prop3 = tokenWrite.propertyKeyGetOrCreateForName( "prop3" ); transaction.success(); } }
private ConstraintDescriptor createConstraint() throws KernelException { try ( Transaction transaction = kernel.beginTransaction( implicit, AUTH_DISABLED ) ) { ConstraintDescriptor descriptor = transaction.schemaWrite().uniquePropertyConstraintCreate( SchemaDescriptorFactory.forLabel( 1, 1 ) ); transaction.success(); return descriptor; } }
@Test public void shouldFailToDropIndexIfExistingUniqueConstraint() throws Exception { //Given try ( Transaction transaction = beginTransaction() ) { transaction.schemaWrite().uniquePropertyConstraintCreate( labelDescriptor( label, prop1 ) ); transaction.success(); } //Expect exception.expect( SchemaKernelException.class ); //When try ( Transaction transaction = beginTransaction() ) { IndexReference index = transaction.schemaRead().index( label, prop1 ); transaction.schemaWrite().indexDrop( index ); transaction.success(); } }
private void dropConstraint( ConstraintDescriptor descriptor ) throws KernelException { try ( Transaction transaction = kernel.beginTransaction( implicit, AUTH_DISABLED ) ) { transaction.schemaWrite().constraintDrop( descriptor ); transaction.success(); } }
@Test public void shouldNotSeeDroppedUniqueConstraintFromTransaction() throws Exception { ConstraintDescriptor existing; try ( Transaction transaction = beginTransaction() ) { existing = transaction.schemaWrite().uniquePropertyConstraintCreate( labelDescriptor( label, prop1 ) ); transaction.success(); } try ( Transaction transaction = beginTransaction() ) { transaction.schemaWrite().constraintDrop( existing ); SchemaRead schemaRead = transaction.schemaRead(); assertFalse( schemaRead.constraintExists( existing ) ); assertThat( asList( schemaRead.constraintsGetForLabel( label ) ), empty() ); } }
@Test public void shouldNotSeeDroppedNodePropertyExistenceConstraintFromTransaction() throws Exception { ConstraintDescriptor existing; try ( Transaction transaction = beginTransaction() ) { existing = transaction.schemaWrite().nodePropertyExistenceConstraintCreate( labelDescriptor( label, prop1 ) ); transaction.success(); } try ( Transaction transaction = beginTransaction() ) { transaction.schemaWrite().constraintDrop( existing ); SchemaRead schemaRead = transaction.schemaRead(); assertFalse( schemaRead.constraintExists( existing ) ); assertThat( schemaRead.index( label, prop2 ), equalTo( NO_INDEX ) ); assertThat( asList( schemaRead.constraintsGetForLabel( label ) ), empty() ); } }
@Test public void shouldNotSeeDroppedRelationshipPropertyExistenceConstraintFromTransaction() throws Exception { ConstraintDescriptor existing; try ( Transaction transaction = beginTransaction() ) { existing = transaction.schemaWrite() .relationshipPropertyExistenceConstraintCreate( typeDescriptor( type, prop1 ) ); transaction.success(); } try ( Transaction transaction = beginTransaction() ) { transaction.schemaWrite().constraintDrop( existing ); SchemaRead schemaRead = transaction.schemaRead(); assertFalse( schemaRead.constraintExists( existing ) ); assertThat( schemaRead.index( type, prop2 ), equalTo( NO_INDEX ) ); assertThat( asList( schemaRead.constraintsGetForLabel( label ) ), empty() ); } }
@Test( expected = SchemaKernelException.class ) public void shouldFailNodeKeyCreateForRepeatedProperties() throws Exception { try ( Transaction tx = beginTransaction() ) { tx.schemaWrite().nodeKeyConstraintCreate( labelDescriptor( label, prop1, prop1 ) ); } }
@Test public void shouldCreateNodePropertyExistenceConstraint() throws Exception { ConstraintDescriptor constraint; try ( Transaction transaction = beginTransaction() ) { constraint = transaction.schemaWrite().nodePropertyExistenceConstraintCreate( labelDescriptor( label, prop1 ) ); transaction.success(); } try ( Transaction transaction = beginTransaction() ) { SchemaRead schemaRead = transaction.schemaRead(); assertTrue( schemaRead.constraintExists( constraint ) ); Iterator<ConstraintDescriptor> constraints = schemaRead.constraintsGetForLabel( label ); assertThat( asList( constraints ), equalTo( singletonList( constraint ) ) ); } }
@Test public void shouldCreateRelationshipPropertyExistenceConstraint() throws Exception { ConstraintDescriptor constraint; try ( Transaction transaction = beginTransaction() ) { constraint = transaction.schemaWrite() .relationshipPropertyExistenceConstraintCreate( typeDescriptor( type, prop1 ) ); transaction.success(); } try ( Transaction transaction = beginTransaction() ) { SchemaRead schemaRead = transaction.schemaRead(); assertTrue( schemaRead.constraintExists( constraint ) ); Iterator<ConstraintDescriptor> constraints = schemaRead.constraintsGetForRelationshipType( type ); assertThat( asList( constraints ), equalTo( singletonList( constraint ) ) ); } }
@Description( "Create a relationship fulltext index for the given relationship types and properties. " + "The optional 'config' map parameter can be used to supply settings to the index. " + "Note: index specific settings are currently experimental, and might not replicated correctly in a cluster, or during backup. " + "Supported settings are '" + INDEX_CONFIG_ANALYZER + "', for specifying what analyzer to use " + "when indexing and querying. Use the `db.index.fulltext.listAvailableAnalyzers` procedure to see what options are available. " + "And '" + INDEX_CONFIG_EVENTUALLY_CONSISTENT + "' which can be set to 'true' to make this index eventually consistent, " + "such that updates from committing transactions are applied in a background thread." ) @Procedure( name = "db.index.fulltext.createRelationshipIndex", mode = SCHEMA ) public void createRelationshipFulltextIndex( @Name( "indexName" ) String name, @Name( "relationshipTypes" ) List<String> relTypes, @Name( "propertyNames" ) List<String> properties, @Name( value = "config", defaultValue = "" ) Map<String,String> config ) throws InvalidTransactionTypeKernelException, SchemaKernelException { Properties settings = new Properties(); settings.putAll( config ); SchemaDescriptor schemaDescriptor = accessor.schemaFor( EntityType.RELATIONSHIP, stringArray( relTypes ), settings, stringArray( properties ) ); tx.schemaWrite().indexCreate( schemaDescriptor, DESCRIPTOR.name(), Optional.of( name ) ); }
@Test public void shouldFailToCreateUniqueConstraintIfExistingIndex() throws Exception { //Given try ( Transaction transaction = beginTransaction() ) { transaction.schemaWrite().indexCreate( labelDescriptor( label, prop1 ) ); transaction.success(); } //Expect exception.expect( SchemaKernelException.class ); //When try ( Transaction transaction = beginTransaction() ) { transaction.schemaWrite().uniquePropertyConstraintCreate( labelDescriptor( label, prop1 ) ); transaction.success(); } }
private void dropIndex( IndexReference reference ) throws KernelException { try ( Transaction transaction = kernel.beginTransaction( implicit, AUTH_DISABLED ) ) { transaction.schemaWrite().indexDrop( reference ); transaction.success(); } }