Exemplo n.º 1
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void makeSureBackupCanBePerformed() throws Throwable
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void MakeSureBackupCanBePerformed()
        {
            // Run backup
            ManagedCluster               cluster      = ClusterRule.startCluster();
            DbRepresentation             beforeChange = DbRepresentation.of(cluster.Master);
            HighlyAvailableGraphDatabase hagdb        = cluster.AllMembers.GetEnumerator().next();
            HostnamePort address      = cluster.GetBackupAddress(hagdb);
            string       databaseName = "basic";

            assertEquals(0, runBackupToolFromOtherJvmToGetExitCode(_backupPath, BackupArguments(address.ToString(), _backupPath, databaseName)));

            // Add some new data
            DbRepresentation afterChange = createSomeData(cluster.Master);

            cluster.Sync();

            // Verify that backed up database can be started and compare representation
            Config           config = Config.builder().withSetting(OnlineBackupSettings.online_backup_enabled, Settings.FALSE).withSetting(GraphDatabaseSettings.active_database, databaseName).build();
            DbRepresentation backupRepresentation = DbRepresentation.of(DatabaseLayout.of(_backupPath, databaseName).databaseDirectory(), config);

            assertEquals(beforeChange, backupRepresentation);
            assertNotEquals(backupRepresentation, afterChange);
        }
Exemplo n.º 2
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void givenClusterWithReadOnlySlaveWhenAddNewRelTypeOnSlaveThenThrowException()
        public virtual void GivenClusterWithReadOnlySlaveWhenAddNewRelTypeOnSlaveThenThrowException()
        {
            // Given
            ManagedCluster cluster = ClusterRule.startCluster();
            Node           node;
            Node           node2;
            HighlyAvailableGraphDatabase master = cluster.Master;

            using (Transaction tx = master.BeginTx())
            {
                node  = master.CreateNode();
                node2 = master.CreateNode();
                tx.Success();
            }

            // When
            HighlyAvailableGraphDatabase readOnlySlave = cluster.GetMemberByServerId(new InstanceId(2));

            try
            {
                using (Transaction tx = readOnlySlave.BeginTx())
                {
                    Node slaveNode  = readOnlySlave.GetNodeById(node.Id);
                    Node slaveNode2 = readOnlySlave.GetNodeById(node2.Id);

                    // Then
                    slaveNode.CreateRelationshipTo(slaveNode2, RelationshipType.withName("KNOWS"));
                    tx.Success();
                    fail("Should have thrown exception");
                }
            }
            catch (WriteOperationsNotAllowedException)
            {
                // Ok!
            }
        }
Exemplo n.º 3
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void aPendingMemberShouldBeAbleToServeReads() throws Throwable
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void APendingMemberShouldBeAbleToServeReads()
        {
            // given
            CreateNodeOnMaster(_testLabel, _cluster.Master);
            _cluster.sync();

            HighlyAvailableGraphDatabase slave = _cluster.AnySlave;

            _cluster.fail(slave, Enum.GetValues(typeof(ClusterManager.NetworkFlag)));
            _cluster.await(instanceEvicted(slave));

            assertEquals(PENDING, slave.InstanceState);

            // when
            for (int i = 0; i < 10; i++)
            {
                try
                {
                    using (Transaction tx = slave.BeginTx())
                    {
                        Node  single = Iterables.single(slave.AllNodes);
                        Label label  = Iterables.single(single.Labels);
                        assertEquals(_testLabel, label);
                        tx.Success();
                        break;
                    }
                }
                catch (TransactionTerminatedException)
                {
                    // Race between going to pending and reading, try again in a little while
                    Thread.Sleep(1_000);
                }
            }

            // then no exceptions thrown
        }
Exemplo n.º 4
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void givenClusterWithReadOnlySlaveWhenCreatingNodeOnMasterThenSlaveShouldBeAbleToPullUpdates()
        public virtual void GivenClusterWithReadOnlySlaveWhenCreatingNodeOnMasterThenSlaveShouldBeAbleToPullUpdates()
        {
            ManagedCluster cluster = ClusterRule.startCluster();
            HighlyAvailableGraphDatabase master = cluster.Master;
            Label label = Label.label("label");

            using (Transaction tx = master.BeginTx())
            {
                master.CreateNode(label);
                tx.Success();
            }

            IEnumerable <HighlyAvailableGraphDatabase> allMembers = cluster.AllMembers;

            foreach (HighlyAvailableGraphDatabase member in allMembers)
            {
                using (Transaction tx = member.BeginTx())
                {
                    long count = count(member.FindNodes(label));
                    tx.Success();
                    assertEquals(1, count);
                }
            }
        }
Exemplo n.º 5
0
//JAVA TO C# CONVERTER WARNING: 'final' parameters are ignored unless the option to convert to C# 7.2 'in' parameters is selected:
//ORIGINAL LINE: private Runnable readContestant(final ReadContestantActions action, final long entityId, final org.neo4j.kernel.ha.HighlyAvailableGraphDatabase slave, final java.util.concurrent.atomic.AtomicBoolean end)
        private ThreadStart ReadContestant(ReadContestantActions action, long entityId, HighlyAvailableGraphDatabase slave, AtomicBoolean end)
        {
            return(() =>
            {
                while (!end.get())
                {
                    try
                    {
                        using (Transaction tx = slave.BeginTx())
                        {
                            for (int i = 0; i < 10; i++)
                            {
                                action.VerifyProperties(slave, entityId);
                            }

                            tx.success();
                        }
                    }
                    catch (Exception ignored) when(ignored is TransactionTerminatedException || ignored is TransientTransactionFailureException)
                    {
                    }
                }
            });
        }
Exemplo n.º 6
0
 private HighAvailability Ha(HighlyAvailableGraphDatabase db)
 {
     return(Beans(db).HighAvailabilityBean);
 }
Exemplo n.º 7
0
 private Neo4jManager Beans(HighlyAvailableGraphDatabase db)
 {
     return(new Neo4jManager(Db.DependencyResolver.resolveDependency(typeof(JmxKernelExtension)).getSingleManagementBean(typeof(Kernel))));
 }
Exemplo n.º 8
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: private static void checkPoint(org.neo4j.kernel.ha.HighlyAvailableGraphDatabase db) throws java.io.IOException
        private static void CheckPoint(HighlyAvailableGraphDatabase db)
        {
            Db.DependencyResolver.resolveDependency(typeof(CheckPointer)).forceCheckPoint(new SimpleTriggerInfo("test")
                                                                                          );
        }
Exemplo n.º 9
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void makeSureSlaveCanJoinEvenIfTooFarBackComparedToMaster() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void MakeSureSlaveCanJoinEvenIfTooFarBackComparedToMaster()
        {
            string key   = "foo";
            string value = "bar";

            HighlyAvailableGraphDatabase master = null;
            HighlyAvailableGraphDatabase slave  = null;
            File masterDir = TestDirectory.databaseDir("master");
            File slaveDir  = TestDirectory.databaseDir("slave");

            try
            {
                int masterClusterPort = PortAuthority.allocatePort();
                int masterHaPort      = PortAuthority.allocatePort();
                master = Start(masterDir, 0, stringMap(keep_logical_logs.name(), "1 txs", ClusterSettings.initial_hosts.name(), "127.0.0.1:" + masterClusterPort), masterClusterPort, masterHaPort);
                CreateNode(master, "something", "unimportant");
                CheckPoint(master);
                // Need to start and shutdown the slave so when we start it up later it verifies instead of copying
                int slaveClusterPort = PortAuthority.allocatePort();
                int slaveHaPort      = PortAuthority.allocatePort();
                slave = Start(slaveDir, 1, stringMap(ClusterSettings.initial_hosts.name(), "127.0.0.1:" + masterClusterPort), slaveClusterPort, slaveHaPort);
                slave.Shutdown();

                CreateNode(master, key, value);
                CheckPoint(master);
                // Rotating, moving the above transactions away so they are removed on shutdown.
                RotateLog(master);

                /*
                 * We need to shutdown - rotating is not enough. The problem is that log positions are cached and they
                 * are not removed from the cache until we run into the cache limit. This means that the information
                 * contained in the log can actually be available even if the log is removed. So, to trigger the case
                 * of the master information missing from the master we need to also flush the log entry cache - hence,
                 * restart.
                 */
                master.Shutdown();
                master = Start(masterDir, 0, stringMap(keep_logical_logs.name(), "1 txs", ClusterSettings.initial_hosts.name(), "127.0.0.1:" + masterClusterPort), masterClusterPort, masterHaPort);

                /*
                 * The new log on master needs to have at least one transaction, so here we go.
                 */
                int importantNodeCount = 10;
                for (int i = 0; i < importantNodeCount; i++)
                {
                    CreateNode(master, key, value);
                    CheckPoint(master);
                    RotateLog(master);
                }

                CheckPoint(master);

                slave = Start(slaveDir, 1, stringMap(ClusterSettings.initial_hosts.name(), "127.0.0.1:" + masterClusterPort), slaveClusterPort, slaveHaPort);
                slave.DependencyResolver.resolveDependency(typeof(UpdatePuller)).pullUpdates();

                using (Transaction ignore = slave.BeginTx())
                {
                    assertEquals("store contents differ", importantNodeCount + 1, NodesHavingProperty(slave, key, value));
                }
            }
            finally
            {
                if (slave != null)
                {
                    slave.Shutdown();
                }

                if (master != null)
                {
                    master.Shutdown();
                }
            }
        }
Exemplo n.º 10
0
 internal virtual PropertyContainer GetEntity(HighlyAvailableGraphDatabase db, long id)
 {
     return(Node ? Db.getNodeById(id) : Db.getRelationshipById(id));
 }
Exemplo n.º 11
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: private org.neo4j.kernel.impl.ha.ClusterManager.RepairKit takeExclusiveLockAndKillSlave(org.neo4j.graphdb.Label testLabel, org.neo4j.kernel.ha.HighlyAvailableGraphDatabase db) throws org.neo4j.internal.kernel.api.exceptions.EntityNotFoundException
        private ClusterManager.RepairKit TakeExclusiveLockAndKillSlave(Label testLabel, HighlyAvailableGraphDatabase db)
        {
            TakeExclusiveLock(testLabel, db);
            return(_cluster.shutdown(db));
        }
Exemplo n.º 12
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: private void takeExclusiveLockOnSameNodeAfterSwitch(org.neo4j.graphdb.Label testLabel, org.neo4j.kernel.ha.HighlyAvailableGraphDatabase master, org.neo4j.kernel.ha.HighlyAvailableGraphDatabase db) throws org.neo4j.internal.kernel.api.exceptions.EntityNotFoundException
        private void TakeExclusiveLockOnSameNodeAfterSwitch(Label testLabel, HighlyAvailableGraphDatabase master, HighlyAvailableGraphDatabase db)
        {
            using (Transaction transaction = Db.beginTx())
            {
                Node node = GetNode(master, testLabel);
                transaction.AcquireWriteLock(node);
                node.SetProperty("key", "value");
                transaction.Success();
            }
        }
Exemplo n.º 13
0
 public HeartbeatListener_AdapterAnonymousInnerClass(PullUpdatesAppliedIT outerInstance, HighlyAvailableGraphDatabase masterDb, System.Threading.CountdownEvent latch2)
 {
     this.outerInstance = outerInstance;
     this._masterDb     = masterDb;
     this._latch2       = latch2;
 }
Exemplo n.º 14
0
 private InstanceId ServerId(HighlyAvailableGraphDatabase db)
 {
     return(Db.DependencyResolver.resolveDependency(typeof(Config)).get(ClusterSettings.server_id));
 }
Exemplo n.º 15
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: private static void deleteAllLogsOn(org.neo4j.kernel.ha.HighlyAvailableGraphDatabase instance) throws java.io.IOException
        private static void DeleteAllLogsOn(HighlyAvailableGraphDatabase instance)
        {
            DeleteAllLogsOn(instance.DatabaseLayout().databaseDirectory());
        }
Exemplo n.º 16
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: private static void deleteAllFilesOn(org.neo4j.kernel.ha.HighlyAvailableGraphDatabase instance) throws java.io.IOException
        private static void DeleteAllFilesOn(HighlyAvailableGraphDatabase instance)
        {
            FileUtils.deleteRecursively(instance.DatabaseLayout().databaseDirectory());
        }
Exemplo n.º 17
0
            public override void VerifyProperties(HighlyAvailableGraphDatabase db, long entityId)
            {
                object value = FetchProperty(db, entityId, KEY, Node);

                AssertPropertyValue(value, ValueA, ValueB);
            }
Exemplo n.º 18
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);
                }
            }
        }
Exemplo n.º 19
0
 public override void VerifyProperties(HighlyAvailableGraphDatabase db, long entityId)
 {
     AssertPropertyChain(asSet(GetEntity(db, entityId).PropertyKeys), KeyPrefixA, KeyPrefixB);
 }
Exemplo n.º 20
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @SuppressWarnings("ResultOfMethodCallIgnored") private org.neo4j.kernel.impl.ha.ClusterManager.RepairKit bringSlaveOfflineAndRemoveStoreFiles(org.neo4j.kernel.impl.ha.ClusterManager.ManagedCluster cluster, org.neo4j.kernel.ha.HighlyAvailableGraphDatabase slave) throws java.io.IOException
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        private ClusterManager.RepairKit BringSlaveOfflineAndRemoveStoreFiles(ClusterManager.ManagedCluster cluster, HighlyAvailableGraphDatabase slave)
        {
            ClusterManager.RepairKit slaveDown = cluster.Shutdown(slave);

            File databaseDir = slave.DatabaseLayout().databaseDirectory();

            deleteRecursively(databaseDir);
            databaseDir.mkdir();
            return(slaveDown);
        }
Exemplo n.º 21
0
 private void ForceMaintenance(HighlyAvailableGraphDatabase master)
 {
     master.DependencyResolver.resolveDependency(typeof(IdController)).maintenance();
 }
Exemplo n.º 22
0
 private static void AwaitStart(HighlyAvailableGraphDatabase db)
 {
     Db.beginTx().close();
 }
Exemplo n.º 23
0
 private void ProceedAsNormalWithIndexPopulationOnAllSlavesExcept(ControlledGraphDatabaseFactory dbFactory, ClusterManager.ManagedCluster cluster, HighlyAvailableGraphDatabase slaveToIgnore)
 {
     foreach (HighlyAvailableGraphDatabase db in cluster.AllMembers)
     {
         if (db != slaveToIgnore && Db.InstanceState == HighAvailabilityMemberState.SLAVE)
         {
             dbFactory.TriggerFinish(db);
         }
     }
 }
Exemplo n.º 24
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldPullUpdatesOnStartupNoMatterWhat() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldPullUpdatesOnStartupNoMatterWhat()
        {
            HighlyAvailableGraphDatabase slave  = null;
            HighlyAvailableGraphDatabase master = null;

            try
            {
                File testRootDir       = ClusterRule.cleanDirectory("shouldPullUpdatesOnStartupNoMatterWhat");
                File masterDir         = ClusterRule.TestDirectory.databaseDir("master");
                int  masterClusterPort = PortAuthority.allocatePort();
                master = ( HighlyAvailableGraphDatabase )(new TestHighlyAvailableGraphDatabaseFactory()).newEmbeddedDatabaseBuilder(masterDir).setConfig(ClusterSettings.server_id, "1").setConfig(ClusterSettings.cluster_server, "127.0.0.1:" + masterClusterPort).setConfig(ClusterSettings.initial_hosts, "localhost:" + masterClusterPort).setConfig(HaSettings.ha_server, "127.0.0.1:" + PortAuthority.allocatePort()).setConfig(OnlineBackupSettings.online_backup_enabled, Settings.FALSE).newGraphDatabase();

                // Copy the store, then shutdown, so update pulling later makes sense
                File slaveDir = ClusterRule.TestDirectory.databaseDir("slave");
                slave = ( HighlyAvailableGraphDatabase )(new TestHighlyAvailableGraphDatabaseFactory()).newEmbeddedDatabaseBuilder(slaveDir).setConfig(ClusterSettings.server_id, "2").setConfig(ClusterSettings.cluster_server, "127.0.0.1:" + PortAuthority.allocatePort()).setConfig(ClusterSettings.initial_hosts, "localhost:" + masterClusterPort).setConfig(HaSettings.ha_server, "127.0.0.1:" + PortAuthority.allocatePort()).setConfig(OnlineBackupSettings.online_backup_enabled, Settings.FALSE).newGraphDatabase();

                // Required to block until the slave has left for sure
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final java.util.concurrent.CountDownLatch slaveLeftLatch = new java.util.concurrent.CountDownLatch(1);
                System.Threading.CountdownEvent slaveLeftLatch = new System.Threading.CountdownEvent(1);
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final org.neo4j.cluster.client.ClusterClient masterClusterClient = master.getDependencyResolver().resolveDependency(org.neo4j.cluster.client.ClusterClient.class);
                ClusterClient masterClusterClient = master.DependencyResolver.resolveDependency(typeof(ClusterClient));
                masterClusterClient.AddClusterListener(new ClusterListener_AdapterAnonymousInnerClass(this, slaveLeftLatch, masterClusterClient));

                master.DependencyResolver.resolveDependency(typeof(LogService)).getInternalLog(this.GetType()).info("SHUTTING DOWN SLAVE");
                slave.Shutdown();
                slave = null;

                // Make sure that the slave has left, because shutdown() may return before the master knows
                assertTrue("Timeout waiting for slave to leave", slaveLeftLatch.await(60, TimeUnit.SECONDS));

                long nodeId;
                using (Transaction tx = master.BeginTx())
                {
                    Node node = master.CreateNode();
                    node.SetProperty("from", "master");
                    nodeId = node.Id;
                    tx.Success();
                }

                // Store is already in place, should pull updates
                slave = ( HighlyAvailableGraphDatabase )(new TestHighlyAvailableGraphDatabaseFactory()).newEmbeddedDatabaseBuilder(slaveDir).setConfig(ClusterSettings.server_id, "2").setConfig(ClusterSettings.cluster_server, "127.0.0.1:" + PortAuthority.allocatePort()).setConfig(ClusterSettings.initial_hosts, "localhost:" + masterClusterPort).setConfig(HaSettings.ha_server, "127.0.0.1:" + PortAuthority.allocatePort()).setConfig(HaSettings.pull_interval, "0").setConfig(OnlineBackupSettings.online_backup_enabled, Settings.FALSE).newGraphDatabase();

                slave.BeginTx().close();                         // Make sure switch to slave completes and so does the update pulling on startup

                using (Transaction tx = slave.BeginTx())
                {
                    assertEquals("master", slave.GetNodeById(nodeId).getProperty("from"));
                    tx.Success();
                }
            }
            finally
            {
                if (slave != null)
                {
                    slave.Shutdown();
                }
                if (master != null)
                {
                    master.Shutdown();
                }
            }
        }
Exemplo n.º 25
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"));
        }
Exemplo n.º 26
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: private static void rotateLog(org.neo4j.kernel.ha.HighlyAvailableGraphDatabase db) throws java.io.IOException
        private static void RotateLog(HighlyAvailableGraphDatabase db)
        {
            Db.DependencyResolver.resolveDependency(typeof(LogRotation)).rotateLogFile();
        }