コード例 #1
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test void shouldStayBoundUnderStress() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        internal virtual void ShouldStayBoundUnderStress()
        {
            // GIVEN
            MutableLongSet acquired           = new LongHashSet();
            IList <long>   acquiredList       = new List <long>();     // for quickly finding random to remove
            long           stableGeneration   = GenerationSafePointer.MIN_GENERATION;
            long           unstableGeneration = stableGeneration + 1;
            int            iterations         = 100;

            // WHEN
            for (int i = 0; i < iterations; i++)
            {
                for (int j = 0; j < 10; j++)
                {
                    if (_random.nextBoolean())
                    {
                        // acquire
                        int count = _random.intBetween(5, 10);
                        for (int k = 0; k < count; k++)
                        {
                            long acquiredId = _freelist.acquireNewId(stableGeneration, unstableGeneration);
                            assertTrue(acquired.add(acquiredId));
                            acquiredList.Add(acquiredId);
                        }
                    }
                    else
                    {
                        // release
                        int count = _random.intBetween(5, 20);
                        for (int k = 0; k < count && !acquired.Empty; k++)
                        {
                            long id = acquiredList.RemoveAt(_random.Next(acquiredList.Count));
                            assertTrue(acquired.remove(id));
                            _freelist.releaseId(stableGeneration, unstableGeneration, id);
                        }
                    }
                }

                foreach (long id in acquiredList)
                {
                    _freelist.releaseId(stableGeneration, unstableGeneration, id);
                }
                acquiredList.Clear();
                acquired.clear();

                // checkpoint, sort of
                stableGeneration = unstableGeneration;
                unstableGeneration++;
            }

            // THEN
            assertTrue(_freelist.lastId() < 200, _freelist.lastId().ToString());
        }
コード例 #2
0
        // TODO analyzer setting must be replicates to all cluster members
        // TODO eventually_consistent setting must be replicated to all cluster members.

//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: private void awaitCatchup() throws InterruptedException
        private void AwaitCatchup()
        {
            MutableLongSet appliedTransactions = new LongHashSet();

            System.Action <ClusterMember> awaitPopulationAndCollectionAppliedTransactionId = member =>
            {
                GraphDatabaseAPI db = member.database();
                try
                {
                    using (Transaction ignore = Db.beginTx())
                    {
                        Db.schema().awaitIndexesOnline(20, TimeUnit.SECONDS);
                        Db.execute(AWAIT_REFRESH).close();
                        DependencyResolver dependencyResolver = Db.DependencyResolver;
                        TransactionIdStore transactionIdStore = dependencyResolver.resolveDependency(typeof(TransactionIdStore));
                        appliedTransactions.add(transactionIdStore.LastClosedTransactionId);
                    }
                }
                catch (Exception e) when(e is QueryExecutionException || e is System.ArgumentException)
                {
                    if (e.Message.Equals("No index was found"))
                    {
                        // Looks like the index creation hasn't been replicated yet, so we force a retry by making sure that
                        // the 'appliedTransactions' set will definitely contain more than one element.
                        appliedTransactions.add(-1L);
                        appliedTransactions.add(-2L);
                    }
                }
                catch (NotFoundException)
                {
                    // This can happen due to a race inside `db.schema().awaitIndexesOnline`, where the list of indexes are provided by the SchemaCache, which is
                    // updated during command application in commit, but the index status is then fetched from the IndexMap, which is updated when the applier is
                    // closed during commit (which comes later in the commit process than command application). So we are told by the SchemaCache that an index
                    // exists, but we are then also told by the IndexMap that the index does not exist, hence this NotFoundException. Normally, these two are
                    // protected by the schema locks that are taken on index create and index status check. However, those locks are 1) incorrectly managed around
                    // index population, and 2) those locks are NOT TAKEN in Causal Cluster command replication!
                    // So we need to anticipate this, and if the race happens, we simply have to try again. But yeah, it needs to be fixed properly at some point.
                    appliedTransactions.add(-1L);
                    appliedTransactions.add(-2L);
                }
            };
            do
            {
                appliedTransactions.clear();
                Thread.Sleep(25);
                ICollection <CoreClusterMember> cores        = _cluster.coreMembers();
                ICollection <ReadReplica>       readReplicas = _cluster.readReplicas();
                cores.forEach(awaitPopulationAndCollectionAppliedTransactionId);
                readReplicas.forEach(awaitPopulationAndCollectionAppliedTransactionId);
            } while (appliedTransactions.size() != 1);
        }