@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 ); }
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 void dropIndex( IndexReference reference ) throws KernelException { try ( Transaction transaction = kernel.beginTransaction( implicit, AUTH_DISABLED ) ) { transaction.schemaWrite().indexDrop( reference ); transaction.success(); } }
@Test public void shouldFailToDropNoIndex() throws Exception { //Expect exception.expect( SchemaKernelException.class ); try ( Transaction transaction = beginTransaction() ) { transaction.schemaWrite().indexDrop( IndexReference.NO_INDEX ); transaction.success(); } }
private void dropIndex( IndexReference index ) throws KernelException { try ( Transaction tx = db.beginTx() ) { KernelTransaction ktx = bridge.getKernelTransactionBoundToThisThread( true ); try ( Statement ignore = ktx.acquireStatement() ) { ktx.schemaWrite().indexDrop( index ); } tx.success(); } }
@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 ) ); } }
@Override public void dropIndexDefinitions( IndexDefinition indexDefinition ) { KernelTransaction transaction = safeAcquireTransaction( transactionSupplier ); try ( Statement ignore = transaction.acquireStatement() ) { try { IndexReference reference = getIndexReference( transaction.schemaRead(), transaction.tokenRead(), (IndexDefinitionImpl) indexDefinition ); transaction.schemaWrite().indexDrop( reference ); } catch ( NotFoundException e ) { // Silently ignore invalid label and property names } catch ( SchemaRuleNotFoundException | DropIndexFailureException e ) { throw new ConstraintViolationException( e.getUserMessage( new SilentTokenNameLookup( transaction.tokenRead() ) ), e ); } catch ( InvalidTransactionTypeKernelException | SchemaKernelException e ) { throw new ConstraintViolationException( e.getMessage(), e ); } } }
@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(); } }
@Test public void shouldDisallowDroppingIndexThatDoesNotExist() throws Exception { // given IndexReference index; { SchemaWrite statement = schemaWriteInNewTransaction(); index = statement.indexCreate( descriptor ); commit(); } { SchemaWrite statement = schemaWriteInNewTransaction(); statement.indexDrop( index ); commit(); } // when try { SchemaWrite statement = schemaWriteInNewTransaction(); statement.indexDrop( index ); commit(); } // then catch ( SchemaKernelException e ) { assertEquals( "Unable to drop index on :label[" + labelId + "](property[" + propertyKeyId + "]): " + "No such INDEX ON :label[" + labelId + "](property[" + propertyKeyId + "]).", e.getMessage() ); } commit(); }
@Test public void shouldDropIndex() 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 ); transaction.success(); } try ( Transaction transaction = beginTransaction() ) { SchemaRead schemaRead = transaction.schemaRead(); assertThat( schemaRead.index( label, prop1 ), equalTo( NO_INDEX ) ); } }
@Test public void shouldFailToDropNonExistentIndex() 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 ); transaction.success(); } //Expect exception.expect( SchemaKernelException.class ); try ( Transaction transaction = beginTransaction() ) { transaction.schemaWrite().indexDrop( index ); transaction.success(); } }
@Test public void shouldBeAbleToRemoveAConstraintIndexWithoutOwner() throws Exception { // given NodePropertyAccessor propertyAccessor = mock( NodePropertyAccessor.class ); AssertableLogProvider logProvider = new AssertableLogProvider(); ConstraintIndexCreator creator = new ConstraintIndexCreator( () -> kernel, indexingService, propertyAccessor, logProvider ); String defaultProvider = Config.defaults().get( default_schema_provider ); IndexDescriptor constraintIndex = creator.createConstraintIndex( descriptor, defaultProvider ); // then Transaction transaction = newTransaction(); assertEquals( emptySet(), asSet( transaction.schemaRead().constraintsGetForLabel( labelId ) ) ); commit(); // when SchemaWrite schemaWrite = schemaWriteInNewTransaction(); schemaWrite.indexDrop( constraintIndex ); commit(); // then transaction = newTransaction(); assertEquals( emptySet(), asSet( transaction.schemaRead().indexesGetForLabel( labelId ) ) ); commit(); }
@Test public void shouldListAllIndexes() throws Exception { IndexReference toRetain; IndexReference toRetain2; IndexReference toDrop; IndexReference created; try ( Transaction tx = beginTransaction() ) { toRetain = tx.schemaWrite().indexCreate( labelDescriptor( label, prop1 ) ); toRetain2 = tx.schemaWrite().indexCreate( labelDescriptor( label2, prop1 ) ); toDrop = tx.schemaWrite().indexCreate( labelDescriptor( label, prop2 ) ); tx.success(); } try ( Transaction tx = beginTransaction() ) { created = tx.schemaWrite().indexCreate( labelDescriptor( label2, prop2 ) ); tx.schemaWrite().indexDrop( toDrop ); Iterable<IndexReference> allIndexes = () -> tx.schemaRead().indexesGetAll(); assertThat( allIndexes, containsInAnyOrder( toRetain, toRetain2, created ) ); tx.success(); } }
@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(); } }
@Test public void schemaStateShouldBeEvictedOnIndexDropped() throws Exception { // GIVEN IndexReference idx = createIndex( newTransaction( AUTH_DISABLED ) ); commit(); try ( Transaction tx = db.beginTx() ) { db.schema().awaitIndexesOnline( 20, SECONDS ); getOrCreateSchemaState( "my key", "some state" ); tx.success(); } // WHEN schemaWriteInNewTransaction().indexDrop( idx ); commit(); // THEN schema state should be immediately updated (this works because the schema cache is updated during // transaction apply, while the schema lock is held). assertFalse( schemaStateContains( "my key" ) ); }
@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(); } }
@After public void clean() throws Exception { try ( Transaction tx = graphDatabaseAPI.beginTx() ) { KernelTransaction ktx = ktx(); if ( index.type() == UNIQUE ) { ktx.schemaWrite().constraintDrop( ConstraintDescriptorFactory.uniqueForSchema( index.schema() ) ); } else { ktx.schemaWrite().indexDrop( index ); } tx.success(); } try ( Transaction tx = graphDatabaseAPI.beginTx() ) { for ( Node node : graphDatabaseAPI.getAllNodes() ) { node.delete(); } tx.success(); } }
tx.schemaWrite().indexDrop( index ); tx.success();
tx.schemaWrite().indexDrop( index ); index = tx.schemaWrite().indexCreate( descriptor, FulltextIndexProviderFactory.DESCRIPTOR.name(), Optional.of( NODE_INDEX_NAME ) ); tx.success();
@Override public void dropIndexDefinitions( IndexDefinition indexDefinition ) { KernelTransaction transaction = safeAcquireTransaction( transactionSupplier ); try ( Statement ignore = transaction.acquireStatement() ) { try { IndexReference reference = getIndexReference( transaction.schemaRead(), transaction.tokenRead(), (IndexDefinitionImpl) indexDefinition ); transaction.schemaWrite().indexDrop( reference ); } catch ( NotFoundException e ) { // Silently ignore invalid label and property names } catch ( SchemaRuleNotFoundException | DropIndexFailureException e ) { throw new ConstraintViolationException( e.getUserMessage( new SilentTokenNameLookup( transaction.tokenRead() ) ), e ); } catch ( InvalidTransactionTypeKernelException | SchemaKernelException e ) { throw new ConstraintViolationException( e.getMessage(), e ); } } }