Exemple #1
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: private void testFailOver(int clusterSize) throws Throwable
        private void TestFailOver(int clusterSize)
        {
            // given
            ClusterManager clusterManager = (new ClusterManager.Builder()).withRootDirectory(Dir.cleanDirectory("failover")).withCluster(ClusterManager.clusterOfSize(clusterSize)).build();

            clusterManager.Start();
            ClusterManager.ManagedCluster cluster = clusterManager.Cluster;

            cluster.Await(ClusterManager.allSeesAllAsAvailable());
            HighlyAvailableGraphDatabase oldMaster = cluster.Master;

            // When
            long start = System.nanoTime();

            ClusterManager.RepairKit repairKit = cluster.Fail(oldMaster);
            Logger.Logger.warning("Shut down master");

            // Then
            cluster.Await(ClusterManager.masterAvailable(oldMaster));
            long end = System.nanoTime();

            Logger.Logger.warning("Failover took:" + (end - start) / 1000000 + "ms");

            repairKit.Repair();
            Thread.Sleep(3000);                 // give repaired instance chance to cleanly rejoin and exit faster

            clusterManager.SafeShutdown();
        }
Exemple #2
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void lastTxCommitTimestampShouldBeUnknownAfterStartIfNoFiledOrLogsPresent() throws Throwable
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void LastTxCommitTimestampShouldBeUnknownAfterStartIfNoFiledOrLogsPresent()
        {
            ClusterManager clusterManager = (new ClusterManager.Builder(TestDirectory.directory(TestName.MethodName))).withCluster(ClusterManager.clusterOfSize(3)).build();

            try
            {
                clusterManager.Start();
                ClusterManager.ManagedCluster cluster = clusterManager.Cluster;
                cluster.Await(allSeesAllAsAvailable());

                RunSomeTransactions(cluster.Master);
                cluster.Sync();

                HighlyAvailableGraphDatabase slave      = cluster.AnySlave;
                DatabaseLayout           databaseLayout = slave.DatabaseLayout();
                ClusterManager.RepairKit slaveRepairKit = cluster.Shutdown(slave);

                ClearLastTransactionCommitTimestampField(databaseLayout);
                DeleteLogs(databaseLayout);

                HighlyAvailableGraphDatabase repairedSlave = slaveRepairKit.Repair();
                cluster.Await(allSeesAllAsAvailable());

                assertEquals(Org.Neo4j.Kernel.impl.transaction.log.TransactionIdStore_Fields.UNKNOWN_TX_COMMIT_TIMESTAMP, LastCommittedTxTimestamp(repairedSlave));
            }
            finally
            {
                clusterManager.Stop();
            }
        }
Exemple #3
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void given4instanceClusterWhenMasterGoesDownThenElectNewMaster() throws Throwable
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void Given4instanceClusterWhenMasterGoesDownThenElectNewMaster()
        {
            ClusterManager clusterManager = (new ClusterManager.Builder(TestDirectory.directory(TestName.MethodName))).withCluster(ClusterManager.clusterOfSize(4)).build();

            try
            {
                clusterManager.Start();
                ClusterManager.ManagedCluster cluster = clusterManager.Cluster;
                cluster.Await(allSeesAllAsAvailable());

                Logging.Logger.info("STOPPING MASTER");
                cluster.Shutdown(cluster.Master);
                Logging.Logger.info("STOPPED MASTER");

                cluster.Await(ClusterManager.masterAvailable());

                GraphDatabaseService master = cluster.Master;
                Logging.Logger.info("CREATE NODE");
                using (Transaction tx = master.BeginTx())
                {
                    master.CreateNode();
                    Logging.Logger.info("CREATED NODE");
                    tx.Success();
                }

                Logging.Logger.info("STOPPING CLUSTER");
            }
            finally
            {
                clusterManager.SafeShutdown();
            }
        }
Exemple #4
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void updatePullerSwitchOnNodeModeSwitch() throws Throwable
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void UpdatePullerSwitchOnNodeModeSwitch()
        {
            ClusterManager.ManagedCluster cluster = ClusterRule.startCluster();

            Label firstLabel = Label.label("firstLabel");

            CreateLabeledNodeOnMaster(cluster, firstLabel);
            // force update puller to work
            PullUpdatesOnSlave(cluster);
            // node should exist on slave now
            CheckLabeledNodeExistenceOnSlave(cluster, firstLabel);
            // verify that puller working on slave and not working on master
            VerifyUpdatePullerThreads(cluster);

            for (int i = 1; i <= 2; i++)
            {
                // switch roles in cluster - now update puller should be stopped on old slave and start on old master.
                ClusterManager.RepairKit repairKit = cluster.Shutdown(cluster.Master);
                cluster.Await(masterAvailable());

                Label currentLabel = Label.label("label_" + i);

                CreateLabeledNodeOnMaster(cluster, currentLabel);

                repairKit.Repair();
                cluster.Await(allSeesAllAsAvailable(), 120);

                // forcing updates pulling
                PullUpdatesOnSlave(cluster);
                CheckLabeledNodeExistenceOnSlave(cluster, currentLabel);
                // checking pulling threads
                VerifyUpdatePullerThreads(cluster);
            }
        }
Exemple #5
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void makeSureUpdatePullerGetsGoingAfterMasterSwitch() throws Throwable
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void MakeSureUpdatePullerGetsGoingAfterMasterSwitch()
        {
            ClusterManager.ManagedCluster cluster = ClusterRule.withSharedSetting(HaSettings.pull_interval, PULL_INTERVAL + "ms").startCluster();

            cluster.Info("### Creating initial dataset");
            long commonNodeId = CreateNodeOnMaster(cluster);

            HighlyAvailableGraphDatabase master = cluster.Master;

            SetProperty(master, commonNodeId, 1);
            cluster.Info("### Initial dataset created");
            AwaitPropagation(1, commonNodeId, cluster);

            cluster.Info("### Shutting down master");
            ClusterManager.RepairKit masterShutdownRK = cluster.Shutdown(master);

            cluster.Info("### Awaiting new master");
            cluster.Await(masterAvailable(master));
            cluster.Await(masterSeesSlavesAsAvailable(1));

            cluster.Info("### Doing a write to master");
            SetProperty(cluster.Master, commonNodeId, 2);
            AwaitPropagation(2, commonNodeId, cluster, master);

            cluster.Info("### Repairing cluster");
            masterShutdownRK.Repair();
            cluster.Await(masterAvailable());
            cluster.Await(masterSeesSlavesAsAvailable(2));
            cluster.Await(allSeesAllAsAvailable());

            cluster.Info("### Awaiting change propagation");
            AwaitPropagation(2, commonNodeId, cluster);
        }
Exemple #6
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldCopyStoreFromMasterIfBranched() throws Throwable
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldCopyStoreFromMasterIfBranched()
        {
            // GIVEN
            File           dir            = _directory.directory();
            ClusterManager clusterManager = _life.add(new ClusterManager.Builder(dir)
                                                      .withCluster(clusterOfSize(2)).build());

            ClusterManager.ManagedCluster cluster = clusterManager.Cluster;
            cluster.Await(allSeesAllAsAvailable());
            CreateNode(cluster.Master, "A");
            cluster.Sync();

            // WHEN
            HighlyAvailableGraphDatabase slave = cluster.AnySlave;
            File databaseDir = slave.DatabaseLayout().databaseDirectory();

            ClusterManager.RepairKit     starter = cluster.Shutdown(slave);
            HighlyAvailableGraphDatabase master  = cluster.Master;

            CreateNode(master, "B1");
            CreateNode(master, "C");
            CreateNodeOffline(databaseDir, "B2");
            slave = starter.Repair();

            // THEN
            cluster.Await(allSeesAllAsAvailable());
            slave.BeginTx().close();
        }
Exemple #7
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void lastTxCommitTimestampShouldGetInitializedOnSlaveIfNotPresent() throws Throwable
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void LastTxCommitTimestampShouldGetInitializedOnSlaveIfNotPresent()
        {
            ClusterManager clusterManager = (new ClusterManager.Builder(TestDirectory.directory(TestName.MethodName))).withCluster(ClusterManager.clusterOfSize(3)).build();

            try
            {
                clusterManager.Start();
                ClusterManager.ManagedCluster cluster = clusterManager.Cluster;
                cluster.Await(allSeesAllAsAvailable());

                RunSomeTransactions(cluster.Master);
                cluster.Sync();

                HighlyAvailableGraphDatabase slave      = cluster.AnySlave;
                DatabaseLayout           databaseLayout = slave.DatabaseLayout();
                ClusterManager.RepairKit slaveRepairKit = cluster.Shutdown(slave);

                ClearLastTransactionCommitTimestampField(databaseLayout);

                HighlyAvailableGraphDatabase repairedSlave = slaveRepairKit.Repair();
                cluster.Await(allSeesAllAsAvailable());

                assertEquals(LastCommittedTxTimestamp(cluster.Master), LastCommittedTxTimestamp(repairedSlave));
            }
            finally
            {
                clusterManager.Stop();
            }
        }
Exemple #8
0
        private ClusterManager.RepairKit KillIncrementally(ClusterManager.ManagedCluster cluster, HighlyAvailableGraphDatabase failed1, HighlyAvailableGraphDatabase failed2, HighlyAvailableGraphDatabase failed3)
        {
            ClusterManager.RepairKit firstFailure = cluster.Fail(failed1);
            cluster.Await(instanceEvicted(failed1));
            cluster.Fail(failed2);
            cluster.Await(instanceEvicted(failed2));
            cluster.Fail(failed3);
            cluster.Await(instanceEvicted(failed3));

            return(firstFailure);
        }
Exemple #9
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void onlineSchemaIndicesOnMasterShouldBeBroughtOnlineOnSlavesAfterStoreCopy() throws Throwable
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void OnlineSchemaIndicesOnMasterShouldBeBroughtOnlineOnSlavesAfterStoreCopy()
        {
            /*
             * The master has an index that is online.
             * Then a slave comes online and contacts the master to get copies of the store files.
             * Because the index is online, it should be copied, and the slave should successfully bring the index online.
             */

            // GIVEN
            ControlledGraphDatabaseFactory dbFactory = new ControlledGraphDatabaseFactory();

            ClusterManager.ManagedCluster cluster = ClusterRule.withDbFactory(dbFactory).withSharedSetting(GraphDatabaseSettings.default_schema_provider, _controlledProviderDescriptor.name()).startCluster();
            cluster.Await(allSeesAllAsAvailable(), 120);

            HighlyAvailableGraphDatabase slave = cluster.AnySlave;

            // All slaves in the cluster, except the one I care about, proceed as normal
            ProceedAsNormalWithIndexPopulationOnAllSlavesExcept(dbFactory, cluster, slave);

            // A slave is offline, and has no store files
            ClusterManager.RepairKit slaveDown = BringSlaveOfflineAndRemoveStoreFiles(cluster, slave);

            // And I create an index on the master, and wait for population to start
            HighlyAvailableGraphDatabase master = cluster.Master;
            IDictionary <object, Node>   data   = CreateSomeData(master);

            CreateIndex(master);
            dbFactory.AwaitPopulationStarted(master);

            // And the population finishes
            dbFactory.TriggerFinish(master);
            IndexDefinition index;

            using (Transaction tx = master.BeginTx())
            {
                index = single(master.Schema().Indexes);
                AwaitIndexOnline(index, master, data);
                tx.Success();
            }

            // WHEN the slave comes online after population has finished on the master
            slave = slaveDown.Repair();
            cluster.Await(allSeesAllAsAvailable());
            cluster.Sync();

            // THEN the index should work on the slave
            dbFactory.TriggerFinish(slave);
            using (Transaction tx = slave.BeginTx())
            {
                AwaitIndexOnline(index, slave, data);
                tx.Success();
            }
        }
Exemple #10
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldContinueServingBoltRequestsBetweenInternalRestarts() throws Throwable
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldContinueServingBoltRequestsBetweenInternalRestarts()
        {
            // given

            /*
             * Interestingly, it is enough to simply start a slave and then direct sessions to it. The problem seems
             * to arise immediately, since simply from startup to being into SLAVE at least one internal restart happens
             * and that seems sufficient to break the bolt server.
             * However, that would make the test really weird, so we'll start the cluster, make sure we can connect and
             * then isolate the slave, make it shutdown internally, then have it rejoin and it will switch to slave.
             * At the end of this process, it must still be possible to open and execute transactions against the instance.
             */
            ClusterManager.ManagedCluster cluster = ClusterRule.startCluster();
            HighlyAvailableGraphDatabase  slave1  = cluster.AnySlave;

            Driver driver = GraphDatabase.driver(cluster.GetBoltAddress(slave1), AuthTokens.basic("neo4j", "neo4j"));

            /*
             * We'll use a bookmark to enforce use of kernel internals by the bolt server, to make sure that parts that are
             * switched during an internal restart are actually refreshed. Technically, this is not necessary, since the
             * bolt server makes such use for every request. But this puts a nice bow on top of it.
             */
            string lastBookmark = InExpirableSession(driver, Driver.session, s =>
            {
                using (Transaction tx = s.beginTransaction())
                {
                    tx.run("CREATE (person:Person {name: {name}, title: {title}})", parameters("name", "Webber", "title", "Mr"));
                    tx.success();
                }
                return(s.lastBookmark());
            });

            // when
            ClusterManager.RepairKit slaveFailRK = cluster.Fail(slave1);

            cluster.Await(entireClusterSeesMemberAsNotAvailable(slave1));
            slaveFailRK.Repair();
            cluster.Await(masterSeesMembers(3));

            // then
            int?count = InExpirableSession(driver, Driver.session, s =>
            {
                Record record;
                using (Transaction tx = s.beginTransaction(lastBookmark))
                {
                    record = tx.run("MATCH (n:Person) RETURN COUNT(*) AS count").next();
                    tx.success();
                }
                return(record.get("count").asInt());
            });

            assertEquals(1, count.Value);
        }
Exemple #11
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: private void reelectTheSameMasterMakingItGoToPendingAndBack(org.neo4j.kernel.impl.ha.ClusterManager.ManagedCluster cluster) throws Throwable
        private void ReelectTheSameMasterMakingItGoToPendingAndBack(ClusterManager.ManagedCluster cluster)
        {
            HighlyAvailableGraphDatabase master = cluster.Master;

            // Fail master and wait for master to go to pending, since it detects it's partitioned away
            ClusterManager.RepairKit masterRepair = cluster.Fail(master, false, ClusterManager.NetworkFlag.IN, ClusterManager.NetworkFlag.OUT);
            cluster.Await(memberThinksItIsRole(master, UNKNOWN));

            // Then Immediately repair
            masterRepair.Repair();

            // Wait for this instance to go to master again, since the other instances are slave only
            cluster.Await(memberThinksItIsRole(master, MASTER));
            cluster.Await(ClusterManager.masterAvailable());
            assertEquals(master, cluster.Master);
        }
Exemple #12
0
        private ClusterManager.ManagedCluster StartCluster()
        {
            _clusterRule.withSharedSetting(GraphDatabaseSettings.lock_manager, LockManagerName);

            ClusterManager.ManagedCluster cluster = _clusterRule.startCluster();
            cluster.Await(ClusterManager.allSeesAllAsAvailable());
            return(cluster);
        }
Exemple #13
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void givenClusterWhenMasterGoesDownAndTxIsRunningThenDontWaitToSwitch() throws Throwable
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void GivenClusterWhenMasterGoesDownAndTxIsRunningThenDontWaitToSwitch()
        {
            ClusterManager clusterManager = (new ClusterManager.Builder(TestDirectory.directory(TestName.MethodName))).withCluster(ClusterManager.clusterOfSize(3)).build();

            try
            {
                clusterManager.Start();
                ClusterManager.ManagedCluster cluster = clusterManager.Cluster;
                cluster.Await(allSeesAllAsAvailable());

                HighlyAvailableGraphDatabase slave = cluster.AnySlave;

                Transaction tx = slave.BeginTx();
                // Do a little write operation so that all "write" aspects of this tx is initializes properly
                slave.CreateNode();

                // Shut down master while we're keeping this transaction open
                cluster.Shutdown(cluster.Master);

                cluster.Await(masterAvailable());
                cluster.Await(masterSeesSlavesAsAvailable(1));
                // Ending up here means that we didn't wait for this transaction to complete

                tx.Success();

                try
                {
                    tx.Close();
                    fail("Exception expected");
                }
                catch (Exception e)
                {
                    assertThat(e, instanceOf(typeof(TransientTransactionFailureException)));
                    Exception rootCause = rootCause(e);
                    assertThat(rootCause, instanceOf(typeof(TransactionTerminatedException)));
                    assertThat((( TransactionTerminatedException )rootCause).status(), Matchers.equalTo(Org.Neo4j.Kernel.Api.Exceptions.Status_General.DatabaseUnavailable));
                }
            }
            finally
            {
                clusterManager.Stop();
            }
        }
Exemple #14
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: private void testFailoverWithAdditionalSlave(int clusterSize, int[] slaveIndexes) throws Throwable
		 private void TestFailoverWithAdditionalSlave( int clusterSize, int[] slaveIndexes )
		 {
			  File root = Dir.cleanDirectory( "testcluster_" + Name.MethodName );
			  ClusterManager manager = ( new ClusterManager.Builder() ).withRootDirectory(root).withCluster(ClusterManager.clusterOfSize(clusterSize)).build();

			  try
			  {
					manager.Start();
					ClusterManager.ManagedCluster cluster = manager.Cluster;

					cluster.Await( allSeesAllAsAvailable() );
					cluster.Await( masterAvailable() );

					ICollection<HighlyAvailableGraphDatabase> failed = new List<HighlyAvailableGraphDatabase>();
					ICollection<ClusterManager.RepairKit> repairKits = new List<ClusterManager.RepairKit>();

					foreach ( int slaveIndex in slaveIndexes )
					{
						 HighlyAvailableGraphDatabase nthSlave = GetNthSlave( cluster, slaveIndex );
						 failed.Add( nthSlave );
						 ClusterManager.RepairKit repairKit = cluster.Fail( nthSlave );
						 repairKits.Add( repairKit );
					}

					HighlyAvailableGraphDatabase oldMaster = cluster.Master;
					failed.Add( oldMaster );
					repairKits.Add( cluster.Fail( oldMaster ) );

					cluster.Await( masterAvailable( ToArray( failed ) ) );

					foreach ( ClusterManager.RepairKit repairKit in repairKits )
					{
						 repairKit.Repair();
					}

					Thread.Sleep( 3000 ); // give repaired instances a chance to cleanly rejoin and exit faster
			  }
			  finally
			  {
					manager.SafeShutdown();
			  }
		 }
Exemple #15
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void migratingOlderDataAndThanStartAClusterUsingTheNewerDataShouldWork() throws Throwable
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
            public virtual void MigratingOlderDataAndThanStartAClusterUsingTheNewerDataShouldWork()
            {
                // migrate the store using a single instance
                File storeDir                = TestDir.storeDir("initialData");
                File databaseDirectory       = Store.prepareDirectory(TestDir.databaseDir(storeDir));
                GraphDatabaseFactory factory = new TestGraphDatabaseFactory();
                GraphDatabaseBuilder builder = factory.NewEmbeddedDatabaseBuilder(databaseDirectory);

                builder.SetConfig(GraphDatabaseSettings.allow_upgrade, "true");
                builder.SetConfig(GraphDatabaseSettings.pagecache_memory, "8m");
                builder.setConfig(GraphDatabaseSettings.logs_directory, TestDir.directory("logs").AbsolutePath);
                builder.SetConfig(OnlineBackupSettings.online_backup_enabled, Settings.FALSE);
                GraphDatabaseService db = builder.NewGraphDatabase();

                try
                {
                    CheckInstance(Store, ( GraphDatabaseAPI )db);
                }
                finally
                {
                    Db.shutdown();
                }

                assertConsistentStore(DatabaseLayout.of(databaseDirectory));

                // start the cluster with the db migrated from the old instance
                File           haDir          = TestDir.storeDir("ha-stuff");
                ClusterManager clusterManager = (new ClusterManager.Builder(haDir)).withSeedDir(databaseDirectory).withCluster(clusterOfSize(2)).build();

                HighlyAvailableGraphDatabase master;
                HighlyAvailableGraphDatabase slave;

                try
                {
                    clusterManager.Start();
                    ClusterManager.ManagedCluster cluster = clusterManager.Cluster;

                    cluster.Await(allSeesAllAsAvailable());

                    master = cluster.Master;
                    CheckInstance(Store, master);
                    slave = cluster.AnySlave;
                    CheckInstance(Store, slave);
                    clusterManager.SafeShutdown();

                    assertConsistentStore(master.DatabaseLayout());
                    assertConsistentStore(slave.DatabaseLayout());
                }
                finally
                {
                    clusterManager.SafeShutdown();
                }
            }
Exemple #16
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void isolatedMasterShouldRemoveSelfFromClusterAndBecomeReadOnly() throws Throwable
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void IsolatedMasterShouldRemoveSelfFromClusterAndBecomeReadOnly()
        {
            int clusterSize = 3;

            ClusterManager manager = (new ClusterManager.Builder()).withRootDirectory(Dir.cleanDirectory("testcluster")).withCluster(ClusterManager.clusterOfSize(clusterSize)).build();

            try
            {
                manager.Start();
                ClusterManager.ManagedCluster cluster = manager.Cluster;

                cluster.Await(allSeesAllAsAvailable());
                cluster.Await(masterAvailable());

                HighlyAvailableGraphDatabase oldMaster = cluster.Master;

                System.Threading.CountdownEvent masterTransitionLatch = new System.Threading.CountdownEvent(1);
                SetupForWaitOnSwitchToDetached(oldMaster, masterTransitionLatch);

                AddSomeData(oldMaster);

                ClusterManager.RepairKit fail = cluster.fail(oldMaster, Enum.GetValues(typeof(ClusterManager.NetworkFlag)));
                cluster.Await(instanceEvicted(oldMaster), 20);

                masterTransitionLatch.await();

                EnsureInstanceIsReadOnlyInPendingState(oldMaster);

                fail.Repair();

                cluster.Await(allSeesAllAsAvailable());

                EnsureInstanceIsWritable(oldMaster);
            }
            finally
            {
                manager.SafeShutdown();
            }
        }
Exemple #17
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: private static void restartingTheClusterShouldWork(org.neo4j.test.ha.ClusterRule clusterRule) throws Exception
        private static void RestartingTheClusterShouldWork(ClusterRule clusterRule)
        {
            ClusterManager.ManagedCluster cluster = clusterRule.StartCluster();
            try
            {
                cluster.Await(allSeesAllAsAvailable(), 180);
            }
            finally
            {
                clusterRule.ShutdownCluster();
            }

            AssertAllStoreConsistent(cluster);
        }
Exemple #18
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void indexPopulationJobsShouldContinueThroughRoleSwitch() throws Throwable
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void IndexPopulationJobsShouldContinueThroughRoleSwitch()
        {
            // GIVEN a cluster of 3
            ControlledGraphDatabaseFactory dbFactory = new ControlledGraphDatabaseFactory();

            ClusterManager.ManagedCluster cluster     = ClusterRule.withDbFactory(dbFactory).withSharedSetting(GraphDatabaseSettings.default_schema_provider, _controlledProviderDescriptor.name()).startCluster();
            HighlyAvailableGraphDatabase  firstMaster = cluster.Master;

            // where the master gets some data created as well as an index
            IDictionary <object, Node> data = CreateSomeData(firstMaster);

            CreateIndex(firstMaster);
            //dbFactory.awaitPopulationStarted( firstMaster );
            dbFactory.TriggerFinish(firstMaster);

            // Pick a slave, pull the data and the index
            HighlyAvailableGraphDatabase aSlave = cluster.AnySlave;

            aSlave.DependencyResolver.resolveDependency(typeof(UpdatePuller)).pullUpdates();

            // and await the index population to start. It will actually block as long as we want it to
            dbFactory.AwaitPopulationStarted(aSlave);

            // WHEN we shut down the master
            cluster.Shutdown(firstMaster);

            dbFactory.TriggerFinish(aSlave);
            cluster.Await(masterAvailable(firstMaster));
            // get the new master, which should be the slave we pulled from above
            HighlyAvailableGraphDatabase newMaster = cluster.Master;

            // THEN
            assertEquals("Unexpected new master", aSlave, newMaster);
            using (Transaction tx = newMaster.BeginTx())
            {
                IndexDefinition index = single(newMaster.Schema().Indexes);
                AwaitIndexOnline(index, newMaster, data);
                tx.Success();
            }
            // FINALLY: let all db's finish
            foreach (HighlyAvailableGraphDatabase db in cluster.AllMembers)
            {
                dbFactory.TriggerFinish(db);
            }
        }
Exemple #19
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Before public void setup() throws Throwable
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
            public virtual void Setup()
            {
                // setup a cluster with some data and entries in log files in fully functional and shutdown state
                ClusterManager.ManagedCluster cluster = ClusterRule.startCluster();

                try
                {
                    cluster.Await(allSeesAllAsAvailable());

                    OldMaster = cluster.Master;
                    CreateSomeData(OldMaster);
                    cluster.Sync();

                    OldSlave1 = cluster.AnySlave;
                    OldSlave2 = cluster.GetAnySlave(OldSlave1);
                }
                finally
                {
                    ClusterRule.shutdownCluster();
                }
                AssertAllStoreConsistent(cluster);
            }
Exemple #20
0
        /// <summary>
        /// Main difference to <seealso cref="shouldCopyStoreFromMasterIfBranched()"/> is that no instances are shut down
        /// during the course of the test. This to test functionality of some internal components being restarted.
        /// </summary>
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @SuppressWarnings("unchecked") @Test public void shouldCopyStoreFromMasterIfBranchedInLiveScenario() throws Throwable
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldCopyStoreFromMasterIfBranchedInLiveScenario()
        {
            // GIVEN a cluster of 3, all having the same data (node A)
            // thor is whoever is the master to begin with
            // odin is whoever is picked as _the_ slave given thor as initial master
            File           storeDirectory = _directory.directory();
            ClusterManager clusterManager = _life.add(new ClusterManager.Builder(storeDirectory)
                                                      .withSharedConfig(stringMap(HaSettings.tx_push_factor.name(), "0", HaSettings.pull_interval.name(), "0")).build());

            ClusterManager.ManagedCluster cluster = clusterManager.Cluster;
            cluster.Await(allSeesAllAsAvailable());
            HighlyAvailableGraphDatabase thor = cluster.Master;
            string indexName = "valhalla";

            CreateNode(thor, "A", AndIndexInto(indexName));
            cluster.Sync();

            // WHEN creating a node B1 on thor (note the disabled cluster transaction propagation)
            CreateNode(thor, "B1", AndIndexInto(indexName));
            // and right after that failing the master so that it falls out of the cluster
            HighlyAvailableGraphDatabase odin = cluster.AnySlave;

            cluster.Info(format("%n   ==== TAMPERING WITH " + thor + "'s CABLES ====%n"));
            ClusterManager.RepairKit thorRepairKit = cluster.Fail(thor);
            // try to create a transaction on odin until it succeeds
            cluster.Await(ClusterManager.masterAvailable(thor));
            cluster.Await(ClusterManager.memberThinksItIsRole(odin, HighAvailabilityModeSwitcher.MASTER));
            assertTrue(odin.Master);
            RetryOnTransactionFailure(odin, db => createNode(db, "B2", AndIndexInto(indexName)));
            // perform transactions so that index files changes under the hood
            ISet <File> odinLuceneFilesBefore = Iterables.asSet(GatherLuceneFiles(odin, indexName));

            for (char prefix = 'C'; !Changed(odinLuceneFilesBefore, Iterables.asSet(GatherLuceneFiles(odin, indexName))); prefix++)
            {
                char fixedPrefix = prefix;
                RetryOnTransactionFailure(odin, db => createNodes(odin, fixedPrefix.ToString(), 10_000, AndIndexInto(indexName)));
                cluster.Force();                         // Force will most likely cause lucene explicit indexes to commit and change file structure
            }
            // so anyways, when thor comes back into the cluster
            cluster.Info(format("%n   ==== REPAIRING CABLES ====%n"));
            cluster.Await(memberThinksItIsRole(thor, UNKNOWN));
            BranchMonitor thorHasBranched = InstallBranchedDataMonitor(cluster.GetMonitorsByDatabase(thor));

            thorRepairKit.Repair();
            cluster.Await(memberThinksItIsRole(thor, SLAVE));
            cluster.Await(memberThinksItIsRole(odin, MASTER));
            cluster.Await(allSeesAllAsAvailable());
            assertFalse(thor.Master);
            assertTrue("No store-copy performed", thorHasBranched.CopyCompleted);
            assertTrue("Store-copy unsuccessful", thorHasBranched.CopySuccessful);

            // Now do some more transactions on current master (odin) and have thor pull those
            for (int i = 0; i < 3; i++)
            {
                int ii = i;
                RetryOnTransactionFailure(odin, db => createNodes(odin, ("" + ii).ToString(), 10, AndIndexInto(indexName)));
                cluster.Sync();
                cluster.Force();
            }

            // THEN thor should be a slave, having copied a store from master and good to go
            assertFalse(HasNode(thor, "B1"));
            assertTrue(HasNode(thor, "B2"));
            assertTrue(HasNode(thor, "C-0"));
            assertTrue(HasNode(thor, "0-0"));
            assertTrue(HasNode(odin, "0-0"));
        }
Exemple #21
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void populatingSchemaIndicesOnMasterShouldBeBroughtOnlineOnSlavesAfterStoreCopy() throws Throwable
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void PopulatingSchemaIndicesOnMasterShouldBeBroughtOnlineOnSlavesAfterStoreCopy()
        {
            /*
             * The master has an index that is currently populating.
             * Then a slave comes online and contacts the master to get copies of the store files.
             * Because the index is still populating, it won't be copied. Instead the slave will build its own.
             * We want to observe that the slave builds an index that eventually comes online.
             */

            // GIVEN
            ControlledGraphDatabaseFactory dbFactory = new ControlledGraphDatabaseFactory(_isMaster);

            ClusterManager.ManagedCluster cluster = ClusterRule.withDbFactory(dbFactory).withSharedSetting(GraphDatabaseSettings.default_schema_provider, NativeLuceneFusionIndexProviderFactory20.DESCRIPTOR.name()).startCluster();

            try
            {
                cluster.Await(allSeesAllAsAvailable());

                HighlyAvailableGraphDatabase slave = cluster.AnySlave;

                // A slave is offline, and has no store files
                ClusterManager.RepairKit slaveDown = BringSlaveOfflineAndRemoveStoreFiles(cluster, slave);

                // And I create an index on the master, and wait for population to start
                HighlyAvailableGraphDatabase master = cluster.Master;
                IDictionary <object, Node>   data   = CreateSomeData(master);
                CreateIndex(master);
                dbFactory.AwaitPopulationStarted(master);

                // WHEN the slave comes online before population has finished on the master
                slave = slaveDown.Repair();
                cluster.Await(allSeesAllAsAvailable(), 180);
                cluster.Sync();

                // THEN, population should finish successfully on both master and slave
                dbFactory.TriggerFinish(master);

                // Check master
                IndexDefinition index;
                using (Transaction tx = master.BeginTx())
                {
                    index = single(master.Schema().Indexes);
                    AwaitIndexOnline(index, master, data);
                    tx.Success();
                }

                // Check slave
                using (Transaction tx = slave.BeginTx())
                {
                    AwaitIndexOnline(index, slave, data);
                    tx.Success();
                }
            }
            finally
            {
                foreach (HighlyAvailableGraphDatabase db in cluster.AllMembers)
                {
                    dbFactory.TriggerFinish(db);
                }
            }
        }
Exemple #22
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void losingQuorumAbruptlyShouldMakeAllInstancesPendingAndReadOnly() throws Throwable
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void LosingQuorumAbruptlyShouldMakeAllInstancesPendingAndReadOnly()
        {
            int clusterSize = 5;               // we need 5 to differentiate between all other instances gone and just quorum being gone

            assumeTrue(TestRunConditions.shouldRunAtClusterSize(clusterSize));

            ClusterManager manager = (new ClusterManager.Builder()).withRootDirectory(Dir.cleanDirectory("testcluster")).withCluster(ClusterManager.clusterOfSize(clusterSize)).withSharedConfig(Config()).build();

            try
            {
                manager.Start();
                ClusterManager.ManagedCluster cluster = manager.Cluster;

                cluster.Await(allSeesAllAsAvailable());
                cluster.Await(masterAvailable());

                HighlyAvailableGraphDatabase master = cluster.Master;
                AddSomeData(master);

                /*
                 * we need 3 failures. We'll end up with the old master and a slave connected. They should both be in
                 * PENDING state, allowing reads but not writes. Repairing just one of the removed instances should
                 * result in a master being elected and all instances being read and writable.
                 * The instances we remove do not need additional verification for their state. Their behaviour is already
                 * known by other tests.
                 */
                HighlyAvailableGraphDatabase failed1;
                ClusterManager.RepairKit     rk1;
                HighlyAvailableGraphDatabase failed2;
                HighlyAvailableGraphDatabase failed3;
                HighlyAvailableGraphDatabase remainingSlave;

                failed1        = cluster.AnySlave;
                failed2        = cluster.GetAnySlave(failed1);
                failed3        = cluster.GetAnySlave(failed1, failed2);
                remainingSlave = cluster.GetAnySlave(failed1, failed2, failed3);

                System.Threading.CountdownEvent masterTransitionLatch = new System.Threading.CountdownEvent(1);
                System.Threading.CountdownEvent slaveTransitionLatch  = new System.Threading.CountdownEvent(1);

                SetupForWaitOnSwitchToDetached(master, masterTransitionLatch);
                SetupForWaitOnSwitchToDetached(remainingSlave, slaveTransitionLatch);

                rk1 = KillAbruptly(cluster, failed1, failed2, failed3);

                cluster.Await(memberSeesOtherMemberAsFailed(remainingSlave, failed1));
                cluster.Await(memberSeesOtherMemberAsFailed(remainingSlave, failed2));
                cluster.Await(memberSeesOtherMemberAsFailed(remainingSlave, failed3));

                cluster.Await(memberSeesOtherMemberAsFailed(master, failed1));
                cluster.Await(memberSeesOtherMemberAsFailed(master, failed2));
                cluster.Await(memberSeesOtherMemberAsFailed(master, failed3));

                masterTransitionLatch.await();
                slaveTransitionLatch.await();

                EnsureInstanceIsReadOnlyInPendingState(master);
                EnsureInstanceIsReadOnlyInPendingState(remainingSlave);

                rk1.Repair();

                cluster.Await(masterAvailable(failed2, failed3));
                cluster.Await(masterSeesSlavesAsAvailable(2));

                EnsureInstanceIsWritable(master);
                EnsureInstanceIsWritable(remainingSlave);
                EnsureInstanceIsWritable(failed1);
            }
            finally
            {
                manager.Shutdown();
            }
        }