示例#1
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: private static void changeStoreId(org.neo4j.causalclustering.discovery.ReadReplica replica) throws java.io.IOException
        private static void ChangeStoreId(ReadReplica replica)
        {
            File      neoStoreFile = DatabaseLayout.of(replica.DatabaseDirectory()).metadataStore();
            PageCache pageCache    = replica.Database().DependencyResolver.resolveDependency(typeof(PageCache));

            MetaDataStore.setRecord(pageCache, neoStoreFile, TIME, DateTimeHelper.CurrentUnixTimeMillis());
        }
示例#2
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldShutdownRatherThanPullUpdatesFromCoreMemberWithDifferentStoreIdIfLocalStoreIsNonEmpty() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldShutdownRatherThanPullUpdatesFromCoreMemberWithDifferentStoreIdIfLocalStoreIsNonEmpty()
        {
//JAVA TO C# CONVERTER WARNING: Java wildcard generics have no direct equivalent in .NET:
//ORIGINAL LINE: org.neo4j.causalclustering.discovery.Cluster<?> cluster = clusterRule.withNumberOfReadReplicas(0).startCluster();
            Cluster <object> cluster = ClusterRule.withNumberOfReadReplicas(0).startCluster();

            cluster.CoreTx(_createSomeData);

            cluster.AwaitCoreMemberWithRole(Role.FOLLOWER, 2, TimeUnit.SECONDS);

            // Get a read replica and make sure that it is operational
            ReadReplica readReplica = cluster.AddReadReplicaWithId(4);

            readReplica.Start();
            readReplica.Database().beginTx().close();

            // Change the store id, so it should fail to join the cluster again
            ChangeStoreId(readReplica);
            readReplica.Shutdown();

            try
            {
                readReplica.Start();
                fail("Should have failed to start");
            }
            catch (Exception required)
            {
                // Lifecycle should throw exception, server should not start.
                assertThat(required.InnerException, instanceOf(typeof(LifecycleException)));
                assertThat(required.InnerException.InnerException, instanceOf(typeof(Exception)));
                assertThat(required.InnerException.InnerException.Message, containsString("This read replica cannot join the cluster. " + "The local database is not empty and has a mismatching storeId:"));
            }
        }
示例#3
0
            public override Optional <MemberId> UpstreamDatabase()
            {
                ReadReplica current = UpstreamFactory.current();

                if (current == null)
                {
                    return(null);
                }
                else
                {
                    return(current.MemberId());
                }
            }
示例#4
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: protected void doWork() throws java.io.IOException
        protected internal override void DoWork()
        {
            int newMemberId = _cluster.readReplicas().Count;
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final org.neo4j.causalclustering.discovery.ReadReplica readReplica = cluster.addReadReplicaWithId(newMemberId);
            ReadReplica readReplica = _cluster.addReadReplicaWithId(newMemberId);

            _log.info("Adding " + readReplica);
            readReplica.Start();

            LagEvaluator lagEvaluator = new LagEvaluator(this.leaderTxId, () => TxId(readReplica), Clock.systemUTC());

            awaitForever(() =>
            {
                if (!Control.keepGoing())
                {
                    return(true);
                }

                Optional <Lag> lagEstimate = lagEvaluator.Evaluate();

                if (lagEstimate.Present)
                {
                    _log.info(lagEstimate.get().ToString());
                    return(lagEstimate.get().timeLagMillis() < MAX_LAG_MS);
                }
                else
                {
                    _log.info("Lag estimate not available");
                    return(false);
                }
            }, SAMPLE_INTERVAL_MS, MILLISECONDS);

            if (!Control.keepGoing())
            {
                return;
            }

            _log.info("Caught up");
            _cluster.removeReadReplicaWithMemberId(newMemberId);

            if (_deleteStore)
            {
                _log.info("Deleting store of " + readReplica);
                _fs.deleteRecursively(readReplica.DatabaseDirectory());
            }
            _deleteStore = !_deleteStore;
        }
示例#5
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldBeAbleToPullTxAfterHavingDownloadedANewStoreAfterPruning() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldBeAbleToPullTxAfterHavingDownloadedANewStoreAfterPruning()
        {
            // given
            IDictionary <string, string> @params = stringMap(GraphDatabaseSettings.keep_logical_logs.name(), "keep_none", GraphDatabaseSettings.logical_log_rotation_threshold.name(), "1M", GraphDatabaseSettings.check_point_interval_time.name(), "100ms");

//JAVA TO C# CONVERTER WARNING: Java wildcard generics have no direct equivalent in .NET:
//ORIGINAL LINE: org.neo4j.causalclustering.discovery.Cluster<?> cluster = clusterRule.withSharedCoreParams(params).startCluster();
            Cluster <object> cluster = ClusterRule.withSharedCoreParams(@params).startCluster();

            cluster.CoreTx((db, tx) =>
            {
                createData(db, 10);
                tx.success();
            });

            awaitEx(() => ReadReplicasUpToDateAsTheLeader(cluster.AwaitLeader(), cluster.ReadReplicas()), 1, TimeUnit.MINUTES);

            ReadReplica readReplica = cluster.GetReadReplicaById(0);
            long        highestReadReplicaLogVersion = PhysicalLogFiles(readReplica).HighestLogVersion;

            readReplica.Shutdown();

            CoreClusterMember core;

            do
            {
                core = cluster.CoreTx((db, tx) =>
                {
                    createData(db, 1_000);
                    tx.success();
                });
            } while (PhysicalLogFiles(core).LowestLogVersion <= highestReadReplicaLogVersion);

            readReplica.Start();

            awaitEx(() => ReadReplicasUpToDateAsTheLeader(cluster.AwaitLeader(), cluster.ReadReplicas()), 1, TimeUnit.MINUTES);

            // when
            cluster.CoreTx((db, tx) =>
            {
                createData(db, 10);
                tx.success();
            });

            // then
            assertEventually("The read replica has the same data as the core members", () => DbRepresentation.of(readReplica.Database()), equalTo(DbRepresentation.of(cluster.AwaitLeader().database())), 10, TimeUnit.SECONDS);
        }
示例#6
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldCatchupThroughHierarchy() throws Throwable
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldCatchupThroughHierarchy()
        {
            ClusterRule = ClusterRule.withInstanceReadReplicaParam(CausalClusteringSettings.server_groups, id => _serverGroups[id]).withInstanceCoreParam(CausalClusteringSettings.server_groups, id => _serverGroups[id]);

            // given
//JAVA TO C# CONVERTER WARNING: Java wildcard generics have no direct equivalent in .NET:
//ORIGINAL LINE: org.neo4j.causalclustering.discovery.Cluster<?> cluster = clusterRule.startCluster();
            Cluster <object> cluster  = ClusterRule.startCluster();
            int numberOfNodesToCreate = 100;

            cluster.CoreTx((db, tx) =>
            {
                Db.schema().constraintFor(label("Foo")).assertPropertyIsUnique("foobar").create();
                tx.success();
            });

            // 0, 1, 2 are core instances
            createLabelledNodesWithProperty(cluster, numberOfNodesToCreate, label("Foo"), () => Pair.of("foobar", string.Format("baz_bat{0}", System.Guid.randomUUID())));

            // 3, 4 are other DCs
            ReadReplica east3 = cluster.AddReadReplicaWithId(3);

            east3.Start();
            ReadReplica west4 = cluster.AddReadReplicaWithId(4);

            west4.Start();

            checkDataHasReplicatedToReadReplicas(cluster, numberOfNodesToCreate);

            foreach (CoreClusterMember coreClusterMember in cluster.CoreMembers())
            {
                coreClusterMember.DisableCatchupServer();
            }

            // 5, 6 are other DCs
            ReadReplica east5 = cluster.AddReadReplicaWithId(5);

            east5.UpstreamDatabaseSelectionStrategy = "connect-randomly-within-server-group";
            east5.Start();
            ReadReplica west6 = cluster.AddReadReplicaWithId(6);

            west6.UpstreamDatabaseSelectionStrategy = "connect-randomly-within-server-group";
            west6.Start();

            checkDataHasReplicatedToReadReplicas(cluster, numberOfNodesToCreate);
        }
示例#7
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldCatchUpFromCoresWhenPreferredReadReplicasAreUnavailable() throws Throwable
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldCatchUpFromCoresWhenPreferredReadReplicasAreUnavailable()
        {
            // given
//JAVA TO C# CONVERTER WARNING: Java wildcard generics have no direct equivalent in .NET:
//ORIGINAL LINE: org.neo4j.causalclustering.discovery.Cluster<?> cluster = clusterRule.startCluster();
            Cluster <object> cluster          = ClusterRule.startCluster();
            int numberOfNodes                 = 1;
            int firstReadReplicaLocalMemberId = 101;

            cluster.CoreTx((db, tx) =>
            {
                Db.schema().constraintFor(label("Foo")).assertPropertyIsUnique("foobar").create();
                tx.success();
            });

            createLabelledNodesWithProperty(cluster, numberOfNodes, label("Foo"), () => Pair.of("foobar", string.Format("baz_bat{0}", System.Guid.randomUUID())));

            ReadReplica firstReadReplica = cluster.AddReadReplicaWithIdAndMonitors(firstReadReplicaLocalMemberId, new Monitors());

            firstReadReplica.Start();

            CheckDataHasReplicatedToReadReplicas(cluster, numberOfNodes);

            upstreamFactory.Current = firstReadReplica;

            ReadReplica secondReadReplica = cluster.AddReadReplicaWithId(202);

            secondReadReplica.UpstreamDatabaseSelectionStrategy = "specific";

            secondReadReplica.Start();

            CheckDataHasReplicatedToReadReplicas(cluster, numberOfNodes);

            firstReadReplica.Shutdown();
            upstreamFactory.reset();

            cluster.RemoveReadReplicaWithMemberId(firstReadReplicaLocalMemberId);

            // when
            // More transactions into core
            createLabelledNodesWithProperty(cluster, numberOfNodes, label("Foo"), () => Pair.of("foobar", string.Format("baz_bat{0}", System.Guid.randomUUID())));

            // then
            // reached second read replica from cores
            CheckDataHasReplicatedToReadReplicas(cluster, numberOfNodes * 2);
        }
示例#8
0
        private static Semaphore AddStoreCopyBlockingMonitor(ReadReplica readReplica)
        {
            Semaphore semaphore = new Semaphore(0);

            readReplica.Monitors().addMonitorListener((FileCopyMonitor)file =>
            {
                try
                {
                    semaphore.acquire();
                }
                catch (InterruptedException e)
                {
                    Thread.CurrentThread.Interrupt();
                    throw new Exception(e);
                }
            });

            return(semaphore);
        }
示例#9
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldEventuallyPullTransactionAcrossReadReplicas() throws Throwable
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldEventuallyPullTransactionAcrossReadReplicas()
        {
            // given
//JAVA TO C# CONVERTER WARNING: Java wildcard generics have no direct equivalent in .NET:
//ORIGINAL LINE: org.neo4j.causalclustering.discovery.Cluster<?> cluster = clusterRule.startCluster();
            Cluster <object> cluster  = ClusterRule.startCluster();
            int numberOfNodesToCreate = 100;

            cluster.CoreTx((db, tx) =>
            {
                Db.schema().constraintFor(label("Foo")).assertPropertyIsUnique("foobar").create();
                tx.success();
            });

            createLabelledNodesWithProperty(cluster, numberOfNodesToCreate, label("Foo"), () => Pair.of("foobar", string.Format("baz_bat{0}", System.Guid.randomUUID())));

            ReadReplica firstReadReplica = cluster.AddReadReplicaWithIdAndMonitors(101, new Monitors());

            firstReadReplica.Start();

            CheckDataHasReplicatedToReadReplicas(cluster, numberOfNodesToCreate);

            foreach (CoreClusterMember coreClusterMember in cluster.CoreMembers())
            {
                coreClusterMember.DisableCatchupServer();
            }

            // when
            upstreamFactory.Current = firstReadReplica;
            ReadReplica secondReadReplica = cluster.AddReadReplicaWithId(202);

            secondReadReplica.UpstreamDatabaseSelectionStrategy = "specific";

            secondReadReplica.Start();

            // then

            CheckDataHasReplicatedToReadReplicas(cluster, numberOfNodesToCreate);
        }
示例#10
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test(timeout = 240_000) public void shouldNotBePossibleToStartTransactionsWhenReadReplicaCopiesStore() throws Throwable
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldNotBePossibleToStartTransactionsWhenReadReplicaCopiesStore()
        {
//JAVA TO C# CONVERTER WARNING: Java wildcard generics have no direct equivalent in .NET:
//ORIGINAL LINE: org.neo4j.causalclustering.discovery.Cluster<?> cluster = clusterRule.startCluster();
            Cluster <object> cluster = ClusterRule.startCluster();

            ReadReplica readReplica = cluster.FindAnyReadReplica();

            readReplica.TxPollingClient().stop();

            WriteSomeDataAndForceLogRotations(cluster);
            Semaphore storeCopyBlockingSemaphore = AddStoreCopyBlockingMonitor(readReplica);

            try
            {
                readReplica.TxPollingClient().start();
                WaitForStoreCopyToStartAndBlock(storeCopyBlockingSemaphore);

                ReadReplicaGraphDatabase replicaGraphDatabase = readReplica.Database();
                try
                {
                    replicaGraphDatabase.BeginTx();
                    fail("Exception expected");
                }
                catch (Exception e)
                {
                    assertThat(e, instanceOf(typeof(TransactionFailureException)));
                    assertThat(e.Message, containsString("Database is stopped to copy store"));
                }
            }
            finally
            {
                // release all waiters of the semaphore
                storeCopyBlockingSemaphore.release(int.MaxValue);
            }
        }
示例#11
0
 internal virtual void Reset()
 {
     CurrentConflict = null;
 }
示例#12
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldEventuallyPullTransactionDownToAllReadReplicas() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldEventuallyPullTransactionDownToAllReadReplicas()
        {
            // given
//JAVA TO C# CONVERTER WARNING: Java wildcard generics have no direct equivalent in .NET:
//ORIGINAL LINE: org.neo4j.causalclustering.discovery.Cluster<?> cluster = clusterRule.withNumberOfReadReplicas(0).startCluster();
            Cluster <object> cluster         = ClusterRule.withNumberOfReadReplicas(0).startCluster();
            int nodesBeforeReadReplicaStarts = 1;

            cluster.CoreTx((db, tx) =>
            {
                Db.schema().constraintFor(Label.label("Foo")).assertPropertyIsUnique("foobar").create();
                tx.success();
            });

            // when
            for (int i = 0; i < 100; i++)
            {
                cluster.CoreTx((db, tx) =>
                {
                    createData(db, nodesBeforeReadReplicaStarts);
                    tx.success();
                });
            }

            ISet <Path> labelScanStoreFiles = new HashSet <Path>();

            cluster.CoreTx((db, tx) => gatherLabelScanStoreFiles(db, labelScanStoreFiles));

            AtomicBoolean labelScanStoreCorrectlyPlaced = new AtomicBoolean(false);
            Monitors      monitors = new Monitors();
            ReadReplica   rr       = cluster.AddReadReplicaWithIdAndMonitors(0, monitors);

            monitors.AddMonitorListener((FileCopyMonitor)file =>
            {
                if (labelScanStoreFiles.Contains(file.toPath().FileName))
                {
                    labelScanStoreCorrectlyPlaced.set(true);
                }
            });

            rr.Start();

            for (int i = 0; i < 100; i++)
            {
                cluster.CoreTx((db, tx) =>
                {
                    createData(db, nodesBeforeReadReplicaStarts);
                    tx.success();
                });
            }

            // then
            foreach (ReadReplica server in cluster.ReadReplicas())
            {
                GraphDatabaseService readReplica = server.database();
                using (Transaction tx = readReplica.BeginTx())
                {
                    ThrowingSupplier <long, Exception> nodeCount = () => count(readReplica.AllNodes);
                    assertEventually("node to appear on read replica", nodeCount, @is(400L), 1, MINUTES);

                    foreach (Node node in readReplica.AllNodes)
                    {
                        assertThat(node.GetProperty("foobar").ToString(), startsWith("baz_bat"));
                    }

                    tx.Success();
                }
            }

            assertTrue(labelScanStoreCorrectlyPlaced.get());
        }