Пример #1
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void testSchemaIndexMatchIndexingService() throws org.neo4j.internal.kernel.api.exceptions.schema.IndexNotFoundKernelException
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void TestSchemaIndexMatchIndexingService()
        {
            using (Transaction transaction = _database.beginTx())
            {
                _database.schema().constraintFor(Label.label(CLOTHES_LABEL)).assertPropertyIsUnique(PROPERTY_NAME).create();
                _database.schema().indexFor(Label.label(WEATHER_LABEL)).on(PROPERTY_NAME).create();

                transaction.Success();
            }

            using (Transaction ignored = _database.beginTx())
            {
                _database.schema().awaitIndexesOnline(1, TimeUnit.MINUTES);
            }

            IndexingService indexingService = GetIndexingService(_database);
            int             clothedLabelId  = GetLabelId(CLOTHES_LABEL);
            int             weatherLabelId  = GetLabelId(WEATHER_LABEL);
            int             propertyId      = GetPropertyKeyId(PROPERTY_NAME);

            IndexProxy clothesIndex = indexingService.getIndexProxy(forLabel(clothedLabelId, propertyId));
            IndexProxy weatherIndex = indexingService.getIndexProxy(forLabel(weatherLabelId, propertyId));

            assertEquals(InternalIndexState.ONLINE, clothesIndex.State);
            assertEquals(InternalIndexState.ONLINE, weatherIndex.State);
        }
Пример #2
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldReleaseLabelLockWhileAwaitingIndexPopulation() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldReleaseLabelLockWhileAwaitingIndexPopulation()
        {
            // given
            StubKernel      kernel          = new StubKernel(this);
            IndexingService indexingService = mock(typeof(IndexingService));

            NodePropertyAccessor nodePropertyAccessor = mock(typeof(NodePropertyAccessor));

            when(_schemaRead.indexGetCommittedId(_indexReference)).thenReturn(INDEX_ID);
            IndexProxy indexProxy = mock(typeof(IndexProxy));

            when(indexingService.getIndexProxy(anyLong())).thenReturn(indexProxy);
            when(indexingService.getIndexProxy(_descriptor)).thenReturn(indexProxy);

            when(_schemaRead.index(LABEL_ID, PROPERTY_KEY_ID)).thenReturn(IndexReference.NO_INDEX);

            ConstraintIndexCreator creator = new ConstraintIndexCreator(() => kernel, indexingService, nodePropertyAccessor, _logProvider);

            // when
            KernelTransactionImplementation transaction = CreateTransaction();

            creator.CreateUniquenessConstraintIndex(transaction, _descriptor, DefaultProvider);

            // then
            verify(transaction.StatementLocks().pessimistic()).releaseExclusive(ResourceTypes.LABEL, _descriptor.LabelId);

            verify(transaction.StatementLocks().pessimistic()).acquireExclusive(transaction.LockTracer(), ResourceTypes.LABEL, _descriptor.LabelId);
        }
Пример #3
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldCreateConstraintIndexForSpecifiedProvider() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldCreateConstraintIndexForSpecifiedProvider()
        {
            // given
            IndexingService indexingService = mock(typeof(IndexingService));
            StubKernel      kernel          = new StubKernel(this);

            when(_schemaRead.indexGetCommittedId(_indexReference)).thenReturn(INDEX_ID);
            IndexProxy indexProxy = mock(typeof(IndexProxy));

            when(indexingService.GetIndexProxy(INDEX_ID)).thenReturn(indexProxy);
            when(indexingService.getIndexProxy(_descriptor)).thenReturn(indexProxy);
            NodePropertyAccessor    nodePropertyAccessor = mock(typeof(NodePropertyAccessor));
            ConstraintIndexCreator  creator            = new ConstraintIndexCreator(() => kernel, indexingService, nodePropertyAccessor, _logProvider);
            IndexProviderDescriptor providerDescriptor = new IndexProviderDescriptor("Groovy", "1.2");

            // when
            KernelTransactionImplementation transaction = CreateTransaction();

            creator.CreateUniquenessConstraintIndex(transaction, _descriptor, providerDescriptor.Name());

            // then
            assertEquals(1, kernel.Transactions.Count);
            KernelTransactionImplementation transactionInstance = kernel.Transactions[0];

            verify(transactionInstance).indexUniqueCreate(eq(_descriptor), eq(providerDescriptor.Name()));
            verify(_schemaRead).index(_descriptor);
            verify(_schemaRead).indexGetCommittedId(any());
            verifyNoMoreInteractions(_schemaRead);
        }
Пример #4
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldContainFedNodeUpdate() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldContainFedNodeUpdate()
        {
            OnlineIndexUpdates onlineIndexUpdates = new OnlineIndexUpdates(_nodeStore, _relationshipStore, _indexingService, _propertyPhysicalToLogicalConverter);

            int        nodeId        = 0;
            NodeRecord inUse         = GetNode(nodeId, true);
            Value      propertyValue = Values.of("hej");
            long       propertyId    = CreateNodeProperty(inUse, propertyValue, 1);
            NodeRecord notInUse      = GetNode(nodeId, false);

            _nodeStore.updateRecord(inUse);

            Command.NodeCommand nodeCommand    = new Command.NodeCommand(inUse, notInUse);
            PropertyRecord      propertyBlocks = new PropertyRecord(propertyId);

            propertyBlocks.NodeId = nodeId;
            Command.PropertyCommand propertyCommand = new Command.PropertyCommand(_recordAccess.getIfLoaded(propertyId).forReadingData(), propertyBlocks);

            StoreIndexDescriptor indexDescriptor = forSchema(multiToken(_entityTokens, NODE, 1, 4, 6), EMPTY.ProviderDescriptor).withId(0);

            _indexingService.createIndexes(indexDescriptor);
            _indexingService.getIndexProxy(indexDescriptor.Schema()).awaitStoreScanCompleted(0, MILLISECONDS);

            onlineIndexUpdates.Feed(NodeGroup(nodeCommand, propertyCommand), RelationshipGroup(null));
            assertTrue(onlineIndexUpdates.HasUpdates());
            IEnumerator <IndexEntryUpdate <SchemaDescriptor> > iterator = onlineIndexUpdates.GetEnumerator();

//JAVA TO C# CONVERTER TODO TASK: Java iterators are only converted within the context of 'while' and 'for' loops:
            assertEquals(iterator.next(), IndexEntryUpdate.remove(nodeId, indexDescriptor, propertyValue, null, null));
//JAVA TO C# CONVERTER TODO TASK: Java iterators are only converted within the context of 'while' and 'for' loops:
            assertFalse(iterator.hasNext());
        }
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: private void waitIndexOnline(org.neo4j.kernel.impl.api.index.IndexingService indexService, int propertyId, int labelId) throws org.neo4j.internal.kernel.api.exceptions.schema.IndexNotFoundKernelException, org.neo4j.kernel.api.exceptions.index.IndexPopulationFailedKernelException, InterruptedException, org.neo4j.kernel.api.exceptions.index.IndexActivationFailedKernelException
        private void WaitIndexOnline(IndexingService indexService, int propertyId, int labelId)
        {
            IndexProxy indexProxy = indexService.getIndexProxy(SchemaDescriptorFactory.forLabel(labelId, propertyId));

            indexProxy.AwaitStoreScanCompleted(0, TimeUnit.MILLISECONDS);
            while (indexProxy.State != InternalIndexState.ONLINE)
            {
                Thread.Sleep(10);
            }
            indexProxy.Activate();
        }
Пример #6
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: public org.neo4j.graphdb.ResourceIterator<org.neo4j.storageengine.api.StoreFileMetadata> getSnapshot(long indexId) throws java.io.IOException
        public virtual ResourceIterator <StoreFileMetadata> GetSnapshot(long indexId)
        {
            try
            {
                ResourceIterator <File>  snapshot = _indexingService.getIndexProxy(indexId).snapshotFiles();
                List <StoreFileMetadata> files    = new List <StoreFileMetadata>();
                GetSnapshotFilesMetadata(snapshot, files);
                return(resourceIterator(Files.GetEnumerator(), snapshot));
            }
            catch (IndexNotFoundKernelException)
            {
                // Perhaps it got dropped after getIndexIds() was called.
                return(Iterators.emptyResourceIterator());
            }
        }
Пример #7
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldDropIndexIfPopulationFails() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldDropIndexIfPopulationFails()
        {
            // given

            StubKernel kernel = new StubKernel(this);

            IndexingService indexingService = mock(typeof(IndexingService));
            IndexProxy      indexProxy      = mock(typeof(IndexProxy));

            when(indexingService.GetIndexProxy(INDEX_ID)).thenReturn(indexProxy);
            when(indexingService.getIndexProxy(_descriptor)).thenReturn(indexProxy);
            when(indexProxy.Descriptor).thenReturn(_index.withId(INDEX_ID).withoutCapabilities());

            IndexEntryConflictException cause = new IndexEntryConflictException(2, 1, Values.of("a"));

            doThrow(new IndexPopulationFailedKernelException("some index", cause)).when(indexProxy).awaitStoreScanCompleted(anyLong(), any());
            NodePropertyAccessor nodePropertyAccessor = mock(typeof(NodePropertyAccessor));

            when(_schemaRead.index(any(typeof(SchemaDescriptor)))).thenReturn(IndexReference.NO_INDEX).thenReturn(_indexReference);                           // then after it failed claim it does exist
            ConstraintIndexCreator creator = new ConstraintIndexCreator(() => kernel, indexingService, nodePropertyAccessor, _logProvider);

            // when
            KernelTransactionImplementation transaction = CreateTransaction();

            try
            {
                creator.CreateUniquenessConstraintIndex(transaction, _descriptor, DefaultProvider);

                fail("expected exception");
            }
            // then
            catch (UniquePropertyValueValidationException e)
            {
                assertEquals("Existing data does not satisfy CONSTRAINT ON ( label[123]:label[123] ) " + "ASSERT label[123].property[456] IS UNIQUE: Both node 2 and node 1 share the property value ( String(\"a\") )", e.Message);
            }
            assertEquals(2, kernel.Transactions.Count);
            KernelTransactionImplementation tx1 = kernel.Transactions[0];
            SchemaDescriptor newIndex           = _index.schema();

            verify(tx1).indexUniqueCreate(eq(newIndex), eq(DefaultProvider));
            verify(_schemaRead).indexGetCommittedId(_indexReference);
            verify(_schemaRead, times(2)).index(_descriptor);
            verifyNoMoreInteractions(_schemaRead);
            TransactionState tx2 = kernel.Transactions[1].txState();

            verify(tx2).indexDoDrop(_index);
            verifyNoMoreInteractions(tx2);
        }
Пример #8
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: void shouldCreateWithSpecificExistingProviderName(IndexCreator creator) throws org.neo4j.internal.kernel.api.exceptions.KernelException
        internal virtual void ShouldCreateWithSpecificExistingProviderName(IndexCreator creator)
        {
            int labelId = 0;

            foreach (GraphDatabaseSettings.SchemaIndex indexSetting in GraphDatabaseSettings.SchemaIndex.values())
            {
                // given
                SchemaWrite           schemaWrite = SchemaWriteInNewTransaction();
                string                provider    = indexSetting.providerName();
                LabelSchemaDescriptor descriptor  = forLabel(labelId++, 0);
                creator.Create(schemaWrite, descriptor, provider);

                // when
                Commit();

                // then
                assertEquals(provider, IndexingService.getIndexProxy(descriptor).Descriptor.providerDescriptor().name());
            }
        }
Пример #9
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void logMessagesAboutConstraintCreation() throws org.neo4j.internal.kernel.api.exceptions.schema.SchemaKernelException, org.neo4j.kernel.api.exceptions.schema.UniquePropertyValueValidationException, org.neo4j.internal.kernel.api.exceptions.TransactionFailureException, org.neo4j.internal.kernel.api.exceptions.schema.IndexNotFoundKernelException
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void LogMessagesAboutConstraintCreation()
        {
            StubKernel      kernel          = new StubKernel(this);
            IndexProxy      indexProxy      = mock(typeof(IndexProxy));
            IndexingService indexingService = mock(typeof(IndexingService));

            when(indexingService.GetIndexProxy(INDEX_ID)).thenReturn(indexProxy);
            when(indexingService.getIndexProxy(_descriptor)).thenReturn(indexProxy);
            when(indexProxy.Descriptor).thenReturn(_index.withId(INDEX_ID).withoutCapabilities());
            NodePropertyAccessor            propertyAccessor = mock(typeof(NodePropertyAccessor));
            ConstraintIndexCreator          creator          = new ConstraintIndexCreator(() => kernel, indexingService, propertyAccessor, _logProvider);
            KernelTransactionImplementation transaction      = CreateTransaction();

            creator.CreateUniquenessConstraintIndex(transaction, _descriptor, "indexProviderByName-1.0");

            _logProvider.rawMessageMatcher().assertContains("Starting constraint creation: %s.");
            _logProvider.rawMessageMatcher().assertContains("Constraint %s populated, starting verification.");
            _logProvider.rawMessageMatcher().assertContains("Constraint %s verified.");
        }
Пример #10
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void testManualIndexPopulation() throws InterruptedException, org.neo4j.internal.kernel.api.exceptions.schema.IndexNotFoundKernelException
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void TestManualIndexPopulation()
        {
            using (Transaction tx = _database.beginTx())
            {
                _database.schema().indexFor(Label.label(FOOD_LABEL)).on(PROPERTY_NAME).create();
                tx.Success();
            }

            int labelId       = GetLabelId(FOOD_LABEL);
            int propertyKeyId = GetPropertyKeyId(PROPERTY_NAME);

            IndexingService indexingService = GetIndexingService(_database);
            IndexProxy      indexProxy      = indexingService.getIndexProxy(forLabel(labelId, propertyKeyId));

            WaitIndexOnline(indexProxy);
            assertEquals(InternalIndexState.ONLINE, indexProxy.State);
            PopulationProgress progress = indexProxy.IndexPopulationProgress;

            assertEquals(progress.Completed, progress.Total);
        }
Пример #11
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void testManualRelationshipIndexPopulation() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void TestManualRelationshipIndexPopulation()
        {
            RelationTypeSchemaDescriptor descriptor;

            using ([email protected] tx = (( GraphDatabaseAPI )_database).DependencyResolver.resolveDependency(typeof(Kernel)).beginTransaction(@explicit, AUTH_DISABLED))
            {
                int foodId     = tx.TokenWrite().relationshipTypeGetOrCreateForName(FOOD_LABEL);
                int propertyId = tx.TokenWrite().propertyKeyGetOrCreateForName(PROPERTY_NAME);
                descriptor = forRelType(foodId, propertyId);
                tx.SchemaWrite().indexCreate(descriptor);
                tx.Success();
            }

            IndexingService indexingService = GetIndexingService(_database);
            IndexProxy      indexProxy      = indexingService.getIndexProxy(descriptor);

            WaitIndexOnline(indexProxy);
            assertEquals(InternalIndexState.ONLINE, indexProxy.State);
            PopulationProgress progress = indexProxy.IndexPopulationProgress;

            assertEquals(progress.Completed, progress.Total);
        }
Пример #12
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldCreateIndexInAnotherTransaction() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldCreateIndexInAnotherTransaction()
        {
            // given
            StubKernel      kernel          = new StubKernel(this);
            IndexProxy      indexProxy      = mock(typeof(IndexProxy));
            IndexingService indexingService = mock(typeof(IndexingService));

            when(indexingService.GetIndexProxy(INDEX_ID)).thenReturn(indexProxy);
            when(indexingService.getIndexProxy(_descriptor)).thenReturn(indexProxy);
            when(indexProxy.Descriptor).thenReturn(_index.withId(INDEX_ID).withoutCapabilities());
            NodePropertyAccessor   nodePropertyAccessor = mock(typeof(NodePropertyAccessor));
            ConstraintIndexCreator creator = new ConstraintIndexCreator(() => kernel, indexingService, nodePropertyAccessor, _logProvider);

            // when
            long indexId = creator.CreateUniquenessConstraintIndex(CreateTransaction(), _descriptor, DefaultProvider);

            // then
            assertEquals(INDEX_ID, indexId);
            verify(_schemaRead).indexGetCommittedId(_indexReference);
            verify(_schemaRead).index(_descriptor);
            verifyNoMoreInteractions(_schemaRead);
            verify(indexProxy).awaitStoreScanCompleted(anyLong(), any());
        }
Пример #13
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Before public void setup() throws org.neo4j.internal.kernel.api.exceptions.schema.IndexNotFoundKernelException
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void Setup()
        {
            _txState = mock(typeof(TransactionState));

            Dictionary <int, Value> map = new Dictionary <int, Value>();

            map[PROP_ID1] = Values.of("hi1");
            map[PROP_ID2] = Values.of("hi2");
            map[PROP_ID3] = Values.of("hi3");
            _node         = (new StubNodeCursor()).withNode(0, new long[] { LABEL_ID1, LABEL_ID2 }, map);
            _node.next();

            _propertyCursor = new StubPropertyCursor();

            Read readOps = mock(typeof(Read));

            when(readOps.TxState()).thenReturn(_txState);

            IndexingService indexingService = mock(typeof(IndexingService));
            IndexProxy      indexProxy      = mock(typeof(IndexProxy));

            when(indexingService.getIndexProxy(any(typeof(SchemaDescriptor)))).thenReturn(indexProxy);
            when(indexingService.getRelatedIndexes(any(), anyInt(), any())).thenAnswer(invocationOnMock =>
            {
                long[] labels     = invocationOnMock.getArgument(0);
                int propertyKeyId = invocationOnMock.getArgument(1);
                ISet <SchemaDescriptor> descriptors = new HashSet <SchemaDescriptor>();
                foreach (IndexDescriptor index in _indexes)
                {
                    if (contains(labels, index.schema().keyId()) && contains(index.schema().PropertyIds, propertyKeyId))
                    {
                        descriptors.add(index.schema());
                    }
                }
                return(descriptors);
            });
            when(indexingService.getRelatedIndexes(any(), any(typeof(int[])), any())).thenAnswer(invocationOnMock =>
            {
                long[] labels        = invocationOnMock.getArgument(0);
                int[] propertyKeyIds = invocationOnMock.getArgument(1);
                ISet <SchemaDescriptor> descriptors = new HashSet <SchemaDescriptor>();
                foreach (IndexDescriptor index in _indexes)
                {
                    if (contains(labels, index.schema().keyId()))
                    {
                        bool containsAll = true;
                        foreach (int propertyId in index.schema().PropertyIds)
                        {
                            containsAll &= contains(propertyKeyIds, propertyId);
                        }
                        if (containsAll)
                        {
                            descriptors.add(index.schema());
                        }
                    }
                }
                return(descriptors);
            });

            _indexTxUpdater = new IndexTxStateUpdater(readOps, indexingService);
        }
Пример #14
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: public org.neo4j.storageengine.api.schema.IndexReader newUnCachedReader(org.neo4j.storageengine.api.schema.IndexDescriptor descriptor) throws org.neo4j.internal.kernel.api.exceptions.schema.IndexNotFoundKernelException
        public override IndexReader NewUnCachedReader(IndexDescriptor descriptor)
        {
            IndexProxy index = IndexingService.getIndexProxy(descriptor.Schema());

            return(index.NewReader());
        }
Пример #15
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: public org.neo4j.internal.kernel.api.InternalIndexState indexGetState(org.neo4j.storageengine.api.schema.IndexDescriptor descriptor) throws org.neo4j.internal.kernel.api.exceptions.schema.IndexNotFoundKernelException
        public override InternalIndexState IndexGetState(IndexDescriptor descriptor)
        {
            return(_indexService.getIndexProxy(descriptor.Schema()).State);
        }
Пример #16
0
        /// <summary>
        /// You MUST hold a label write lock before you call this method.
        /// However the label write lock is temporarily released while populating the index backing the constraint.
        /// It goes a little like this:
        /// <ol>
        /// <li>Prerequisite: Getting here means that there's an open schema transaction which has acquired the
        /// LABEL WRITE lock.</li>
        /// <li>Index schema rule which is backing the constraint is created in a nested mini-transaction
        /// which doesn't acquire any locking, merely adds tx state and commits so that the index rule is applied
        /// to the store, which triggers the index population</li>
        /// <li>Release the LABEL WRITE lock</li>
        /// <li>Await index population to complete</li>
        /// <li>Acquire the LABEL WRITE lock (effectively blocking concurrent transactions changing
        /// data related to this constraint, and it so happens, most other transactions as well) and verify
        /// the uniqueness of the built index</li>
        /// <li>Leave this method, knowing that the uniqueness constraint rule will be added to tx state
        /// and this tx committed, which will create the uniqueness constraint</li>
        /// </ol>
        /// </summary>
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: public long createUniquenessConstraintIndex(org.neo4j.kernel.impl.api.KernelTransactionImplementation transaction, org.neo4j.internal.kernel.api.schema.SchemaDescriptor descriptor, String provider) throws org.neo4j.internal.kernel.api.exceptions.TransactionFailureException, org.neo4j.internal.kernel.api.exceptions.schema.CreateConstraintFailureException, org.neo4j.kernel.api.exceptions.schema.UniquePropertyValueValidationException, org.neo4j.kernel.api.exceptions.schema.AlreadyConstrainedException
        public virtual long CreateUniquenessConstraintIndex(KernelTransactionImplementation transaction, SchemaDescriptor descriptor, string provider)
        {
            UniquenessConstraintDescriptor constraint = ConstraintDescriptorFactory.uniqueForSchema(descriptor);

            _log.info("Starting constraint creation: %s.", constraint.OwnedIndexDescriptor());

            IndexReference index;
            SchemaRead     schemaRead = transaction.SchemaRead();

            try
            {
                index = GetOrCreateUniquenessConstraintIndex(schemaRead, transaction.TokenRead(), descriptor, provider);
            }
            catch (AlreadyConstrainedException e)
            {
                throw e;
            }
            catch (Exception e) when(e is SchemaKernelException || e is IndexNotFoundKernelException)
            {
                throw new CreateConstraintFailureException(constraint, e);
            }

            bool         success             = false;
            bool         reacquiredLabelLock = false;
            Locks_Client locks = transaction.StatementLocks().pessimistic();

            try
            {
                long       indexId = schemaRead.IndexGetCommittedId(index);
                IndexProxy proxy   = _indexingService.getIndexProxy(indexId);

                // Release the LABEL WRITE lock during index population.
                // At this point the integrity of the constraint to be created was checked
                // while holding the lock and the index rule backing the soon-to-be-created constraint
                // has been created. Now it's just the population left, which can take a long time
                locks.ReleaseExclusive(descriptor.KeyType(), descriptor.KeyId());

                AwaitConstraintIndexPopulation(constraint, proxy, transaction);
                _log.info("Constraint %s populated, starting verification.", constraint.OwnedIndexDescriptor());

                // Index population was successful, but at this point we don't know if the uniqueness constraint holds.
                // Acquire LABEL WRITE lock and verify the constraints here in this user transaction
                // and if everything checks out then it will be held until after the constraint has been
                // created and activated.
                locks.AcquireExclusive(transaction.LockTracer(), descriptor.KeyType(), descriptor.KeyId());
                reacquiredLabelLock = true;

                _indexingService.getIndexProxy(indexId).verifyDeferredConstraints(_nodePropertyAccessor);
                _log.info("Constraint %s verified.", constraint.OwnedIndexDescriptor());
                success = true;
                return(indexId);
            }
            catch (SchemaKernelException e)
            {
                throw new System.InvalidOperationException(string.Format("Index ({0}) that we just created does not exist.", descriptor), e);
            }
            catch (IndexNotFoundKernelException e)
            {
                throw new TransactionFailureException(string.Format("Index ({0}) that we just created does not exist.", descriptor), e);
            }
            catch (IndexEntryConflictException e)
            {
                throw new UniquePropertyValueValidationException(constraint, VERIFICATION, e);
            }
            catch (Exception e) when(e is InterruptedException || e is IOException)
            {
                throw new CreateConstraintFailureException(constraint, e);
            }
            finally
            {
                if (!success)
                {
                    if (!reacquiredLabelLock)
                    {
                        locks.AcquireExclusive(transaction.LockTracer(), descriptor.KeyType(), descriptor.KeyId());
                    }

                    if (IndexStillExists(schemaRead, descriptor, index))
                    {
                        DropUniquenessConstraintIndex(( IndexDescriptor )index);
                    }
                }
            }
        }