コード例 #1
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: private static java.util.List<java.util.Map<String,Object>> indexes(org.neo4j.internal.kernel.api.TokenRead tokens, org.neo4j.internal.kernel.api.SchemaRead schemaRead, Anonymizer anonymizer) throws org.neo4j.internal.kernel.api.exceptions.schema.IndexNotFoundKernelException
        private static IList <IDictionary <string, object> > Indexes(TokenRead tokens, SchemaRead schemaRead, Anonymizer anonymizer)
        {
            IList <IDictionary <string, object> > indexes = new List <IDictionary <string, object> >();

            SilentTokenNameLookup tokenLookup = new SilentTokenNameLookup(tokens);

            IEnumerator <IndexReference> iterator = schemaRead.IndexesGetAll();

            while (iterator.MoveNext())
            {
                IndexReference index = iterator.Current;

                IDictionary <string, object> data = new Dictionary <string, object>();
                data["labels"] = Map(index.Schema().EntityTokenIds, id => anonymizer.Label(tokenLookup.LabelGetName(id), id));

                data["properties"] = Map(index.Schema().PropertyIds, id => anonymizer.PropertyKey(tokenLookup.PropertyKeyGetName(id), id));

                Org.Neo4j.Register.Register_DoubleLongRegister register = Registers.newDoubleLongRegister();
                schemaRead.IndexUpdatesAndSize(index, register);
                data["totalSize"] = register.ReadSecond();
                data["updatesSinceEstimation"] = register.ReadFirst();
                schemaRead.IndexSample(index, register);
                data["estimatedUniqueSize"] = register.ReadFirst();

                indexes.Add(data);
            }

            return(indexes);
        }
コード例 #2
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldSampleUniqueIndex() throws Throwable
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldSampleUniqueIndex()
        {
            GraphDatabaseService db = null;
            long deletedNodes       = 0;

            try
            {
                // Given
                db = (new TestGraphDatabaseFactory()).newEmbeddedDatabase(TestDirectory.storeDir());
                using (Transaction tx = Db.beginTx())
                {
                    Db.schema().constraintFor(_label).assertPropertyIsUnique(_property).create();
                    tx.Success();
                }

                using (Transaction tx = Db.beginTx())
                {
                    for (int i = 0; i < _nodes; i++)
                    {
                        Db.createNode(_label).setProperty(_property, "" + i);
                        tx.Success();
                    }
                }

                using (Transaction tx = Db.beginTx())
                {
                    for (int i = 0; i < _nodes; i++)
                    {
                        if (i % 10 == 0)
                        {
                            deletedNodes++;
                            Db.findNode(_label, _property, "" + i).delete();
                            tx.Success();
                        }
                    }
                }
            }
            finally
            {
                if (db != null)
                {
                    Db.shutdown();
                }
            }

            // When
            TriggerIndexResamplingOnNextStartup();

            // Then
            Register_DoubleLongRegister indexSampleRegister = FetchIndexSamplingValues(db);

            assertEquals(_nodes - deletedNodes, indexSampleRegister.ReadFirst());
            assertEquals(_nodes - deletedNodes, indexSampleRegister.ReadSecond());

            Register_DoubleLongRegister indexSizeRegister = FetchIndexSizeValues(db);

            assertEquals(0, indexSizeRegister.ReadFirst());
            assertEquals(_nodes - deletedNodes, indexSizeRegister.ReadSecond());
        }
コード例 #3
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test @Resources.Life(STARTED) public void shouldNotEndUpInBrokenStateAfterRotationFailure() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldNotEndUpInBrokenStateAfterRotationFailure()
        {
            // GIVEN
            FakeClock         clock             = Clocks.fakeClock();
            CallTrackingClock callTrackingClock = new CallTrackingClock(clock);
            CountsTracker     tracker           = ResourceManager.managed(NewTracker(callTrackingClock, EmptyVersionContextSupplier.EMPTY));
            int labelId = 1;

            using (Org.Neo4j.Kernel.Impl.Api.CountsAccessor_Updater tx = tracker.Apply(2).get())
            {
                tx.IncrementNodeCount(labelId, 1);                           // now at 1
            }

            // WHEN
            System.Predicate <Thread> arrived  = thread => stackTraceContains(thread, all(classNameContains("Rotation"), methodIs("rotate")));
            Future <object>           rotation = Threading.executeAndAwait(t => t.rotate(4), tracker, arrived, 1, SECONDS);

            using (Org.Neo4j.Kernel.Impl.Api.CountsAccessor_Updater tx = tracker.Apply(3).get())
            {
                tx.IncrementNodeCount(labelId, 1);                           // now at 2
            }
            while (callTrackingClock.CallsToNanos() == 0)
            {
                Thread.Sleep(10);
            }
            clock.Forward(Config.defaults().get(GraphDatabaseSettings.counts_store_rotation_timeout).toMillis() * 2, MILLISECONDS);
            try
            {
                rotation.get();
                fail("Should've failed rotation due to timeout");
            }
            catch (ExecutionException e)
            {
                // good
                assertTrue(e.InnerException is RotationTimeoutException);
            }

            // THEN
            Org.Neo4j.Register.Register_DoubleLongRegister register = Registers.newDoubleLongRegister();
            tracker.Get(CountsKeyFactory.nodeKey(labelId), register);
            assertEquals(2, register.ReadSecond());

            // and WHEN later attempting rotation again
            using (Org.Neo4j.Kernel.Impl.Api.CountsAccessor_Updater tx = tracker.Apply(4).get())
            {
                tx.IncrementNodeCount(labelId, 1);                           // now at 3
            }
            tracker.Rotate(4);

            // THEN
            tracker.Get(CountsKeyFactory.nodeKey(labelId), register);
            assertEquals(3, register.ReadSecond());
        }
コード例 #4
0
ファイル: Indexes.cs プロジェクト: Neo4Net/Neo4Net
        /// <summary>
        /// For each index, await a resampling event unless it has zero pending updates.
        /// </summary>
        /// <param name="schemaRead"> backing schema read </param>
        /// <param name="timeout"> timeout in seconds. If this limit is passed, a TimeoutException is thrown. </param>
        /// <exception cref="TimeoutException"> if all indexes are not resampled within the timeout. </exception>
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: public static void awaitResampling(org.neo4j.internal.kernel.api.SchemaRead schemaRead, long timeout) throws java.util.concurrent.TimeoutException
        public static void AwaitResampling(SchemaRead schemaRead, long timeout)
        {
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final java.util.Iterator<org.neo4j.internal.kernel.api.IndexReference> indexes = schemaRead.indexesGetAll();
            IEnumerator <IndexReference> indexes = schemaRead.IndexesGetAll();

//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final org.neo4j.register.Register_DoubleLongRegister register = org.neo4j.register.Registers.newDoubleLongRegister();
            Org.Neo4j.Register.Register_DoubleLongRegister register = Registers.newDoubleLongRegister();
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final long t0 = System.currentTimeMillis();
            long t0 = DateTimeHelper.CurrentUnixTimeMillis();
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final long timeoutMillis = 1000 * timeout;
            long timeoutMillis = 1000 * timeout;

            while (indexes.MoveNext())
            {
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final org.neo4j.internal.kernel.api.IndexReference index = indexes.Current;
                IndexReference index = indexes.Current;
                try
                {
                    long readUpdates = readUpdates(index, schemaRead, register);
                    long updateCount = readUpdates;
                    bool hasTimedOut = false;

                    while (updateCount > 0 && updateCount <= readUpdates && !hasTimedOut)
                    {
                        Thread.Sleep(10);
                        hasTimedOut = DateTimeHelper.CurrentUnixTimeMillis() - t0 >= timeoutMillis;
                        updateCount = Math.Max(updateCount, readUpdates);
                        readUpdates = readUpdates(index, schemaRead, register);
                    }

                    if (hasTimedOut)
                    {
                        throw new TimeoutException(string.Format("Indexes were not resampled within {0} {1}", timeout, TimeUnit.SECONDS));
                    }
                }
                catch (InterruptedException e)
                {
                    Thread.CurrentThread.Interrupt();
                    throw new Exception(e);
                }
                catch (IndexNotFoundKernelException e)
                {
                    throw new ConcurrentModificationException("Index was dropped while awaiting resampling", e);
                }
            }
        }
コード例 #5
0
 public override Org.Neo4j.Register.Register_DoubleLongRegister IndexSample(long indexId, Org.Neo4j.Register.Register_DoubleLongRegister output)
 {
     return(_neoStoreIndexStoreView.indexSample(indexId, output));
 }
コード例 #6
0
ファイル: Read.cs プロジェクト: Neo4Net/Neo4Net
 public abstract Org.Neo4j.Register.Register_DoubleLongRegister IndexUpdatesAndSize(IndexReference index, Org.Neo4j.Register.Register_DoubleLongRegister target);
コード例 #7
0
ファイル: CountsTracker.cs プロジェクト: Neo4Net/Neo4Net
 public override Org.Neo4j.Register.Register_DoubleLongRegister RelationshipCount(int startLabelId, int typeId, int endLabelId, Org.Neo4j.Register.Register_DoubleLongRegister target)
 {
     return(Get(relationshipKey(startLabelId, typeId, endLabelId), target));
 }
コード例 #8
0
 private void MockLabelNodeCount(CountsTracker countStore, int labelId)
 {
     Org.Neo4j.Register.Register_DoubleLongRegister register = Registers.newDoubleLongRegister(labelId, labelId);
     when(countStore.NodeCount(eq(labelId), any(typeof(Org.Neo4j.Register.Register_DoubleLongRegister)))).thenReturn(register);
 }
コード例 #9
0
ファイル: Read.cs プロジェクト: Neo4Net/Neo4Net
 public abstract Org.Neo4j.Register.Register_DoubleLongRegister IndexSample(IndexReference index, Org.Neo4j.Register.Register_DoubleLongRegister target);
コード例 #10
0
ファイル: Indexes.cs プロジェクト: Neo4Net/Neo4Net
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: private static long readUpdates(org.neo4j.internal.kernel.api.IndexReference index, org.neo4j.internal.kernel.api.SchemaRead schemaRead, org.neo4j.register.Register_DoubleLongRegister register) throws org.neo4j.internal.kernel.api.exceptions.schema.IndexNotFoundKernelException
        private static long ReadUpdates(IndexReference index, SchemaRead schemaRead, Org.Neo4j.Register.Register_DoubleLongRegister register)
        {
            schemaRead.IndexUpdatesAndSize(index, register);
            return(register.ReadFirst());
        }
コード例 #11
0
        private static void AssertDoubleLongEquals(int expectedFirst, int expectedSecond, Register_DoubleLongRegister actualValues)
        {
            string msg = string.Format("Expected ({0:D},{1:D}) but was ({2:D},{3:D})", expectedFirst, expectedSecond, actualValues.ReadFirst(), actualValues.ReadSecond());

            assertTrue(msg, actualValues.HasValues(expectedFirst, expectedSecond));
        }
コード例 #12
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldSampleNotUniqueIndex() throws Throwable
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldSampleNotUniqueIndex()
        {
            GraphDatabaseService db = null;
            long deletedNodes       = 0;

            try
            {
                // Given
                db = (new TestGraphDatabaseFactory()).newEmbeddedDatabase(TestDirectory.storeDir());
                IndexDefinition indexDefinition;
                using (Transaction tx = Db.beginTx())
                {
                    indexDefinition = Db.schema().indexFor(_label).on(_property).create();
                    tx.Success();
                }

                using (Transaction tx = Db.beginTx())
                {
                    Db.schema().awaitIndexOnline(indexDefinition, 10, TimeUnit.SECONDS);
                    tx.Success();
                }

                using (Transaction tx = Db.beginTx())
                {
                    for (int i = 0; i < _nodes; i++)
                    {
                        Db.createNode(_label).setProperty(_property, _names[i % _names.Length]);
                        tx.Success();
                    }
                }

                using (Transaction tx = Db.beginTx())
                {
                    for (int i = 0; i < (_nodes / 10); i++)
                    {
                        using (ResourceIterator <Node> nodes = Db.findNodes(_label, _property, _names[i % _names.Length]))
                        {
//JAVA TO C# CONVERTER TODO TASK: Java iterators are only converted within the context of 'while' and 'for' loops:
                            nodes.next().delete();
                        }
                        deletedNodes++;
                        tx.Success();
                    }
                }
            }
            finally
            {
                if (db != null)
                {
                    Db.shutdown();
                }
            }

            // When
            TriggerIndexResamplingOnNextStartup();

            // Then

            // lucene will consider also the delete nodes, native won't
            Register_DoubleLongRegister register = FetchIndexSamplingValues(db);

            assertEquals(_names.Length, register.ReadFirst());
            assertThat(register.ReadSecond(), allOf(greaterThanOrEqualTo(nodes - deletedNodes), lessThanOrEqualTo(nodes)));

            // but regardless, the deleted nodes should not be considered in the index size value
            Register_DoubleLongRegister indexSizeRegister = FetchIndexSizeValues(db);

            assertEquals(0, indexSizeRegister.ReadFirst());
            assertEquals(nodes - deletedNodes, indexSizeRegister.ReadSecond());
        }
コード例 #13
0
ファイル: CountsTracker.cs プロジェクト: Neo4Net/Neo4Net
//JAVA TO C# CONVERTER WARNING: 'final' parameters are ignored unless the option to convert to C# 7.2 'in' parameters is selected:
//ORIGINAL LINE: public org.neo4j.register.Register_DoubleLongRegister nodeCount(int labelId, final org.neo4j.register.Register_DoubleLongRegister target)
        public override Org.Neo4j.Register.Register_DoubleLongRegister NodeCount(int labelId, Org.Neo4j.Register.Register_DoubleLongRegister target)
        {
            return(Get(nodeKey(labelId), target));
        }
コード例 #14
0
ファイル: CountsTracker.cs プロジェクト: Neo4Net/Neo4Net
 public override Org.Neo4j.Register.Register_DoubleLongRegister IndexUpdatesAndSize(long indexId, Org.Neo4j.Register.Register_DoubleLongRegister target)
 {
     return(Get(indexStatisticsKey(indexId), target));
 }
コード例 #15
0
 private void AssertEqualRegisters(string message, Register_DoubleLongRegister expected, Register_DoubleLongRegister actual)
 {
     assertEquals(message + " (first part of register)", expected.ReadFirst(), actual.ReadFirst());
     assertEquals(message + " (second part of register)", expected.ReadSecond(), actual.ReadSecond());
 }
コード例 #16
0
ファイル: CountsOracle.cs プロジェクト: Neo4Net/Neo4Net
 public void visitIndexSample(long indexId, long unique, long size)
 {
     Org.Neo4j.Register.Register_DoubleLongRegister output = _tracker.indexSample(indexId, newDoubleLongRegister());
     assertEquals("Should be able to read visited state.", output.ReadFirst(), unique);
     assertEquals("Should be able to read visited state.", output.ReadSecond(), size);
 }
コード例 #17
0
ファイル: CountsOracle.cs プロジェクト: Neo4Net/Neo4Net
 public void visitIndexStatistics(long indexId, long updates, long size)
 {
     Org.Neo4j.Register.Register_DoubleLongRegister output = _tracker.indexUpdatesAndSize(indexId, newDoubleLongRegister());
     assertEquals("Should be able to read visited state.", output.ReadFirst(), updates);
     assertEquals("Should be able to read visited state.", output.ReadSecond(), size);
 }
コード例 #18
0
ファイル: CountsTracker.cs プロジェクト: Neo4Net/Neo4Net
 public override Org.Neo4j.Register.Register_DoubleLongRegister IndexSample(long indexId, Org.Neo4j.Register.Register_DoubleLongRegister target)
 {
     return(Get(indexSampleKey(indexId), target));
 }
コード例 #19
0
 public override Org.Neo4j.Register.Register_DoubleLongRegister IndexSample(SchemaDescriptor descriptor, Org.Neo4j.Register.Register_DoubleLongRegister target)
 {
     throw new System.NotSupportedException("Not implemented yet");
 }
コード例 #20
0
ファイル: CountsTracker.cs プロジェクト: Neo4Net/Neo4Net
 public virtual Org.Neo4j.Register.Register_DoubleLongRegister Get(CountsKey key, Org.Neo4j.Register.Register_DoubleLongRegister target)
 {
     try
     {
         return(Lookup(key, new ValueRegister(target)));
     }
     catch (IOException e)
     {
         throw new UnderlyingStorageException(e);
     }
 }