Beispiel #1
0
        public void Replicate_all_indexes_should_respect_disable_indexing_flag()
        {
            var requestFactory = new HttpRavenRequestFactory();

            using (var sourceServer = GetNewServer(9077))
                using (var source = NewRemoteDocumentStore(ravenDbServer: sourceServer, fiddler: true))
                    using (var destinationServer1 = GetNewServer(9078))
                        using (var destination1 = NewRemoteDocumentStore(ravenDbServer: destinationServer1, fiddler: true))
                            using (var destinationServer2 = GetNewServer())
                                using (var destination2 = NewRemoteDocumentStore(ravenDbServer: destinationServer2, fiddler: true))
                                    using (var destinationServer3 = GetNewServer(9081))
                                        using (var destination3 = NewRemoteDocumentStore(ravenDbServer: destinationServer3, fiddler: true))
                                        {
                                            CreateDatabaseWithReplication(source, "testDB");
                                            CreateDatabaseWithReplication(destination1, "testDB");
                                            CreateDatabaseWithReplication(destination2, "testDB");
                                            CreateDatabaseWithReplication(destination3, "testDB");

                                            //turn-off automatic index replication - precaution
                                            source.Conventions.IndexAndTransformerReplicationMode = IndexAndTransformerReplicationMode.None;
                                            // ReSharper disable once AccessToDisposedClosure
                                            //we setup replication so replication to destination2 will have "disabled" flag
                                            SetupReplication(source, "testDB", store => store == destination2, destination1, destination2, destination3);

                                            //make sure not to replicate the index automatically
                                            var userIndex           = new UserIndex();
                                            var anotherUserIndex    = new AnotherUserIndex();
                                            var yetAnotherUserIndex = new YetAnotherUserIndex();
                                            source.DatabaseCommands.ForDatabase("testDB").PutIndex(userIndex.IndexName, userIndex.CreateIndexDefinition());
                                            source.DatabaseCommands.ForDatabase("testDB").PutIndex(anotherUserIndex.IndexName, anotherUserIndex.CreateIndexDefinition());
                                            source.DatabaseCommands.ForDatabase("testDB").PutIndex(yetAnotherUserIndex.IndexName, yetAnotherUserIndex.CreateIndexDefinition());

                                            var replicationRequestUrl = string.Format("{0}/databases/testDB/replication/replicate-indexes?op=replicate-all", source.Url);
                                            var replicationRequest    = requestFactory.Create(replicationRequestUrl, "POST", new RavenConnectionStringOptions
                                            {
                                                Url = source.Url
                                            });
                                            replicationRequest.ExecuteRequest();

                                            var expectedIndexNames = new HashSet <string>(StringComparer.InvariantCultureIgnoreCase)
                                            {
                                                userIndex.IndexName, anotherUserIndex.IndexName, yetAnotherUserIndex.IndexName
                                            };
                                            var indexStatsAfterReplication1 = destination1.DatabaseCommands.ForDatabase("testDB").GetStatistics().Indexes.Select(x => x.Name);
                                            Assert.True(expectedIndexNames.SetEquals(indexStatsAfterReplication1));


                                            var indexStatsAfterReplication3 = destination3.DatabaseCommands.ForDatabase("testDB").GetStatistics().Indexes.Select(x => x.Name);
                                            Assert.True(expectedIndexNames.SetEquals(indexStatsAfterReplication3));

                                            //since destination2 has disabled flag - indexes should not replicate to here
                                            var indexStatsAfterReplication2 = destination2.DatabaseCommands.ForDatabase("testDB").GetStatistics().Indexes.Select(x => x.Name);
                                            Assert.Empty(indexStatsAfterReplication2);
                                        }
        }
Beispiel #2
0
        public void Should_replicate_all_indexes_only_to_specific_destination_if_relevant_endpoint_hit()
        {
            var requestFactory = new HttpRavenRequestFactory();

            using (var sourceServer = GetNewServer(8077))
                using (var source = NewRemoteDocumentStore(ravenDbServer: sourceServer))
                    using (var destinationServer1 = GetNewServer(8078))
                        using (var destination1 = NewRemoteDocumentStore(ravenDbServer: destinationServer1))
                            using (var destinationServer2 = GetNewServer())
                                using (var destination2 = NewRemoteDocumentStore(ravenDbServer: destinationServer2))
                                    using (var destinationServer3 = GetNewServer(8081))
                                        using (var destination3 = NewRemoteDocumentStore(ravenDbServer: destinationServer3))
                                        {
                                            CreateDatabaseWithReplication(source, "testDB");
                                            CreateDatabaseWithReplication(destination1, "testDB");
                                            CreateDatabaseWithReplication(destination2, "testDB");
                                            CreateDatabaseWithReplication(destination3, "testDB");

                                            //turn-off automatic index replication - precaution
                                            source.Conventions.IndexAndTransformerReplicationMode = IndexAndTransformerReplicationMode.None;
                                            // ReSharper disable once AccessToDisposedClosure
                                            var destinationDocuments = SetupReplication(source, "testDB", store => false, destination1, destination2, destination3);

                                            //make sure not to replicate the index automatically
                                            var userIndex           = new UserIndex();
                                            var anotherUserIndex    = new AnotherUserIndex();
                                            var yetAnotherUserIndex = new YetAnotherUserIndex();
                                            source.DatabaseCommands.ForDatabase("testDB").PutIndex(userIndex.IndexName, userIndex.CreateIndexDefinition());
                                            source.DatabaseCommands.ForDatabase("testDB").PutIndex(anotherUserIndex.IndexName, anotherUserIndex.CreateIndexDefinition());
                                            source.DatabaseCommands.ForDatabase("testDB").PutIndex(yetAnotherUserIndex.IndexName, yetAnotherUserIndex.CreateIndexDefinition());

                                            var replicationRequestUrl = string.Format("{0}/databases/testDB/replication/replicate-indexes?op=replicate-all-to-destination", source.Url);
                                            var replicationRequest    = requestFactory.Create(replicationRequestUrl, "POST", new RavenConnectionStringOptions
                                            {
                                                Url = source.Url
                                            });

                                            replicationRequest.Write(RavenJObject.FromObject(destinationDocuments[1]));
                                            replicationRequest.ExecuteRequest();

                                            var expectedIndexNames = new HashSet <string>(StringComparer.InvariantCultureIgnoreCase)
                                            {
                                                userIndex.IndexName, anotherUserIndex.IndexName, yetAnotherUserIndex.IndexName
                                            };
                                            var indexStatsAfterReplication1 = destination1.DatabaseCommands.ForDatabase("testDB").GetStatistics().Indexes.Select(x => x.Name);
                                            var indexStatsAfterReplication2 = destination2.DatabaseCommands.ForDatabase("testDB").GetStatistics().Indexes.Select(x => x.Name);
                                            var indexStatsAfterReplication3 = destination3.DatabaseCommands.ForDatabase("testDB").GetStatistics().Indexes.Select(x => x.Name);

                                            Assert.Equal(0, indexStatsAfterReplication1.Count());
                                            Assert.True(expectedIndexNames.SetEquals(indexStatsAfterReplication2));
                                            Assert.Equal(0, indexStatsAfterReplication3.Count());
                                        }
        }
Beispiel #3
0
        public async Task Should_replicate_indexes_periodically()
        {
            using (var sourceServer = GetNewServer(8077))
                using (var source = NewRemoteDocumentStore(ravenDbServer: sourceServer))
                    using (var destinationServer1 = GetNewServer(8078))
                        using (var destination1 = NewRemoteDocumentStore(ravenDbServer: destinationServer1))
                            using (var destinationServer2 = GetNewServer())
                                using (var destination2 = NewRemoteDocumentStore(ravenDbServer: destinationServer2))
                                    using (var destinationServer3 = GetNewServer(8081))
                                        using (var destination3 = NewRemoteDocumentStore(ravenDbServer: destinationServer3))
                                        {
                                            CreateDatabaseWithReplication(source, "testDB");
                                            CreateDatabaseWithReplication(destination1, "testDB");
                                            CreateDatabaseWithReplication(destination2, "testDB");
                                            CreateDatabaseWithReplication(destination3, "testDB");

                                            //turn-off automatic index replication - precaution
                                            source.Conventions.IndexAndTransformerReplicationMode = IndexAndTransformerReplicationMode.None;
                                            // ReSharper disable once AccessToDisposedClosure
                                            SetupReplication(source, "testDB", store => false, destination1, destination2, destination3);

                                            //make sure not to replicate the index automatically
                                            var userIndex           = new UserIndex();
                                            var anotherUserIndex    = new AnotherUserIndex();
                                            var yetAnotherUserIndex = new YetAnotherUserIndex();
                                            source.DatabaseCommands.ForDatabase("testDB").PutIndex(userIndex.IndexName, userIndex.CreateIndexDefinition());
                                            source.DatabaseCommands.ForDatabase("testDB").PutIndex(anotherUserIndex.IndexName, anotherUserIndex.CreateIndexDefinition());
                                            source.DatabaseCommands.ForDatabase("testDB").PutIndex(yetAnotherUserIndex.IndexName, yetAnotherUserIndex.CreateIndexDefinition());

                                            var sourceDB = await sourceServer.Server.GetDatabaseInternal("testDB");

                                            var replicationTask = sourceDB.StartupTasks.OfType <ReplicationTask>().First();
                                            replicationTask.ReplicateIndexesAndTransformersTask(null);

                                            var expectedIndexNames = new HashSet <string>(StringComparer.InvariantCultureIgnoreCase)
                                            {
                                                userIndex.IndexName, anotherUserIndex.IndexName, yetAnotherUserIndex.IndexName
                                            };
                                            var indexStatsAfterReplication1 = destination1.DatabaseCommands.ForDatabase("testDB").GetStatistics().Indexes.Select(x => x.Name);
                                            Assert.True(expectedIndexNames.SetEquals(indexStatsAfterReplication1));

                                            var indexStatsAfterReplication3 = destination3.DatabaseCommands.ForDatabase("testDB").GetStatistics().Indexes.Select(x => x.Name);
                                            Assert.True(expectedIndexNames.SetEquals(indexStatsAfterReplication3));

                                            var indexStatsAfterReplication2 = destination2.DatabaseCommands.ForDatabase("testDB").GetStatistics().Indexes.Select(x => x.Name);
                                            Assert.True(expectedIndexNames.SetEquals(indexStatsAfterReplication2));
                                        }
        }
Beispiel #4
0
        public async Task Should_send_last_queried_index_time_periodically()
        {
            using (var sourceServer = GetNewServer(8077))
                using (var source = NewRemoteDocumentStore(ravenDbServer: sourceServer))
                    using (var destinationServer1 = GetNewServer(8078))
                        using (var destination1 = NewRemoteDocumentStore(ravenDbServer: destinationServer1))
                            using (var destinationServer2 = GetNewServer())
                                using (var destination2 = NewRemoteDocumentStore(ravenDbServer: destinationServer2))
                                    using (var destinationServer3 = GetNewServer(8081))
                                        using (var destination3 = NewRemoteDocumentStore(ravenDbServer: destinationServer3))
                                        {
                                            CreateDatabaseWithReplication(source, "testDB");
                                            CreateDatabaseWithReplication(destination1, "testDB");
                                            CreateDatabaseWithReplication(destination2, "testDB");
                                            CreateDatabaseWithReplication(destination3, "testDB");

                                            //turn-off automatic index replication - precaution
                                            source.Conventions.IndexAndTransformerReplicationMode = IndexAndTransformerReplicationMode.None;
                                            // ReSharper disable once AccessToDisposedClosure
                                            SetupReplication(source, "testDB", store => false, destination1, destination2, destination3);

                                            //make sure not to replicate the index automatically
                                            var userIndex           = new UserIndex();
                                            var anotherUserIndex    = new AnotherUserIndex();
                                            var yetAnotherUserIndex = new YetAnotherUserIndex();
                                            source.DatabaseCommands.ForDatabase("testDB").PutIndex(userIndex.IndexName, userIndex.CreateIndexDefinition());
                                            source.DatabaseCommands.ForDatabase("testDB").PutIndex(anotherUserIndex.IndexName, anotherUserIndex.CreateIndexDefinition());
                                            source.DatabaseCommands.ForDatabase("testDB").PutIndex(yetAnotherUserIndex.IndexName, yetAnotherUserIndex.CreateIndexDefinition());

                                            using (var session = source.OpenSession("testDB"))
                                            {
// ReSharper disable ReturnValueOfPureMethodIsNotUsed
                                                session.Query <UserIndex>(userIndex.IndexName).ToList();                     //update last queried time
                                                session.Query <AnotherUserIndex>(anotherUserIndex.IndexName).ToList();       //update last queried time
                                                session.Query <YetAnotherUserIndex>(yetAnotherUserIndex.IndexName).ToList(); //update last queried time
// ReSharper restore ReturnValueOfPureMethodIsNotUsed

                                                session.SaveChanges();
                                            }

                                            var sourceDB = await sourceServer.Server.GetDatabaseInternal("testDB");

                                            var replicationTask = sourceDB.StartupTasks.OfType <ReplicationTask>().First();
                                            replicationTask.SendLastQueriedTask(null);

                                            var indexNames = new[] { userIndex.IndexName, anotherUserIndex.IndexName, yetAnotherUserIndex.IndexName };

                                            var sourceIndexStats       = source.DatabaseCommands.ForDatabase("testDB").GetStatistics().Indexes.Where(x => indexNames.Contains(x.Name)).ToList();
                                            var destination1IndexStats = source.DatabaseCommands.ForDatabase("testDB").GetStatistics().Indexes.Where(x => indexNames.Contains(x.Name)).ToList();
                                            var destination2IndexStats = source.DatabaseCommands.ForDatabase("testDB").GetStatistics().Indexes.Where(x => indexNames.Contains(x.Name)).ToList();
                                            var destination3IndexStats = source.DatabaseCommands.ForDatabase("testDB").GetStatistics().Indexes.Where(x => indexNames.Contains(x.Name)).ToList();

                                            Assert.NotNull(sourceIndexStats.First(x => x.Name == userIndex.IndexName).LastQueryTimestamp);           //sanity check
                                            Assert.NotNull(sourceIndexStats.First(x => x.Name == anotherUserIndex.IndexName).LastQueryTimestamp);    //sanity check
                                            Assert.NotNull(sourceIndexStats.First(x => x.Name == yetAnotherUserIndex.IndexName).LastQueryTimestamp); //sanity check

                                            Assert.Equal(sourceIndexStats.First(x => x.Name == userIndex.IndexName).LastQueryTimestamp, destination1IndexStats.First(x => x.Name == userIndex.IndexName).LastQueryTimestamp);
                                            Assert.Equal(sourceIndexStats.First(x => x.Name == anotherUserIndex.IndexName).LastQueryTimestamp, destination1IndexStats.First(x => x.Name == anotherUserIndex.IndexName).LastQueryTimestamp);
                                            Assert.Equal(sourceIndexStats.First(x => x.Name == yetAnotherUserIndex.IndexName).LastQueryTimestamp, destination1IndexStats.First(x => x.Name == yetAnotherUserIndex.IndexName).LastQueryTimestamp);

                                            Assert.Equal(sourceIndexStats.First(x => x.Name == userIndex.IndexName).LastQueryTimestamp, destination2IndexStats.First(x => x.Name == userIndex.IndexName).LastQueryTimestamp);
                                            Assert.Equal(sourceIndexStats.First(x => x.Name == anotherUserIndex.IndexName).LastQueryTimestamp, destination2IndexStats.First(x => x.Name == anotherUserIndex.IndexName).LastQueryTimestamp);
                                            Assert.Equal(sourceIndexStats.First(x => x.Name == yetAnotherUserIndex.IndexName).LastQueryTimestamp, destination2IndexStats.First(x => x.Name == yetAnotherUserIndex.IndexName).LastQueryTimestamp);

                                            Assert.Equal(sourceIndexStats.First(x => x.Name == userIndex.IndexName).LastQueryTimestamp, destination3IndexStats.First(x => x.Name == userIndex.IndexName).LastQueryTimestamp);
                                            Assert.Equal(sourceIndexStats.First(x => x.Name == anotherUserIndex.IndexName).LastQueryTimestamp, destination3IndexStats.First(x => x.Name == anotherUserIndex.IndexName).LastQueryTimestamp);
                                            Assert.Equal(sourceIndexStats.First(x => x.Name == yetAnotherUserIndex.IndexName).LastQueryTimestamp, destination3IndexStats.First(x => x.Name == yetAnotherUserIndex.IndexName).LastQueryTimestamp);
                                        }
        }