Beispiel #1
0
        public async Task NotInRehabWithDisabledIndexes2()
        {
            var(node, leader) = await CreateRaftCluster(3, watcherCluster : true);

            var database = GetDatabaseName();

            await CreateDatabaseInClusterInner(new DatabaseRecord(database), 3, leader.WebUrl, null);

            using (var store = new DocumentStore
            {
                Database = database,
                Urls = new[] { leader.WebUrl }
            }.Initialize())
            {
                var documentDatabase = await Servers[2].ServerStore.DatabasesLandlord.TryGetOrCreateResourceStore(database);
                var result           = store.Maintenance.Send(new PutIndexesOperation(new[] { new IndexDefinition
                                                                                              {
                                                                                                  Maps = { "from user in docs.Users select new { user.Name }" },
                                                                                                  Name = "MyIndex"
                                                                                              } }));
                var indexResult = result[0];
                await Cluster.WaitForRaftIndexToBeAppliedInClusterAsync(indexResult.RaftCommandIndex, TimeSpan.FromSeconds(15));

                await RollingIndexesClusterTests.WaitForRollingIndex(database, "MyIndex", Servers[2]);

                var index = documentDatabase.IndexStore.GetIndex("MyIndex");
                index.SetState(IndexState.Disabled);

                var record = await store.Maintenance.Server.SendAsync(new GetDatabaseRecordOperation(store.Database));

                record.Topology.Members.Remove(Servers[2].ServerStore.NodeTag);
                record.Topology.Rehabs.Add(Servers[2].ServerStore.NodeTag);
                await store.Maintenance.Server.SendAsync(new UpdateDatabaseOperation(record, record.Etag));

                await WaitAndAssertForValueAsync(async() => await RavenDB_15588.GetMembersAndRehabsCount(store), expectedVal : (MembersCount : 2, RehabsCount : 1));
                await WaitAndAssertForValueAsync(async() => await RavenDB_15588.GetMembersAndRehabsCount(store), expectedVal : (MembersCount : 3, RehabsCount : 0));
            }
        }
Beispiel #2
0
        public async Task NotInRehabWithDisabledIndexes3()
        {
            var(node, leader) = await CreateRaftCluster(3, watcherCluster : true);

            var database = GetDatabaseName();

            await CreateDatabaseInClusterInner(new DatabaseRecord(database), 3, leader.WebUrl, null);

            using (var store = new DocumentStore
            {
                Database = database,
                Urls = new[] { leader.WebUrl }
            }.Initialize())
            {
                var documentDatabase = await Servers[2].ServerStore.DatabasesLandlord.TryGetOrCreateResourceStore(database);
                var result           = store.Maintenance.Send(new PutIndexesOperation(new[] { new IndexDefinition
                                                                                              {
                                                                                                  Maps = { "from user in docs.Users select new { user.Name }" },
                                                                                                  Name = "MyIndex"
                                                                                              } }));
                var indexResult = result[0];
                await Cluster.WaitForRaftIndexToBeAppliedInClusterAsync(indexResult.RaftCommandIndex, TimeSpan.FromSeconds(15));

                await RollingIndexesClusterTests.WaitForRollingIndex(database, "MyIndex", Servers[2]);

                var index = documentDatabase.IndexStore.GetIndex("MyIndex");
                index.SetState(IndexState.Error);

                using (var session = store.OpenSession())
                {
                    session.Store(new User()
                    {
                        Name = "Toli"
                    }, "user/1");
                    session.SaveChanges();
                }

                index.SetState(IndexState.Disabled);

                using (var context = QueryOperationContext.Allocate(documentDatabase, index))
                    using (context.OpenReadTransaction())
                    {
                        var state = index.GetIndexingState(context);
                        Assert.Equal(0, state.LastProcessedEtag);
                    }

                var record = await store.Maintenance.Server.SendAsync(new GetDatabaseRecordOperation(store.Database));

                record.Topology.Members.Remove(Servers[2].ServerStore.NodeTag);
                record.Topology.Rehabs.Add(Servers[2].ServerStore.NodeTag);
                await store.Maintenance.Server.SendAsync(new UpdateDatabaseOperation(record, record.Etag));

                await WaitAndAssertForValueAsync(async() => await RavenDB_15588.GetMembersAndRehabsCount(store), expectedVal : (MembersCount : 2, RehabsCount : 1));

                // assert that Servers[2] is promoted back to Member
                var expectedVal = (MembersCount : 3, RehabsCount : 0);
                var val         = await WaitForPredicateAsync(async() => await RavenDB_15588.GetMembersAndRehabsCount(store), expectedVal : expectedVal);

                Assert.True(val.Equals(expectedVal), await GetDecisionsForDatabase(
                                new StringBuilder("Failed on asserting Members and Rehabs count.")
                                .AppendLine($"Expected {expectedVal}, got : {val}")));
            }
        }