Esempio n. 1
0
        public async Task GetSubscriptionResend()
        {
            var subscriptionName = GetStringQueryString("name");

            using (ServerStore.Engine.ContextPool.AllocateOperationContext(out ClusterOperationContext context))
                using (context.OpenReadTransaction())
                    await using (var writer = new AsyncBlittableJsonTextWriter(context, ResponseBodyStream()))
                    {
                        var subscriptionState = Database
                                                .SubscriptionStorage
                                                .GetSubscriptionFromServerStore(subscriptionName);

                        if (subscriptionState == null)
                        {
                            HttpContext.Response.StatusCode = (int)HttpStatusCode.NotFound;
                            return;
                        }

                        var subscriptionConnections = Database.SubscriptionStorage.GetSubscriptionConnectionsState(context, subscriptionName);
                        var items = SubscriptionStorage.GetResendItems(context, Database.Name, subscriptionState.SubscriptionId);

                        writer.WriteStartObject();
                        writer.WriteArray("Active", subscriptionConnections.GetActiveBatches());
                        writer.WriteComma();
                        writer.WriteArray("Results", items.Select(i => i.ToJson()), context);
                        writer.WriteEndObject();
                    }
        }
Esempio n. 2
0
        public async Task CanSnapshotSubscriptionState()
        {
            var(_, leader) = await CreateRaftCluster(1, watcherCluster : true);

            using (var store = GetDocumentStore(options: new Options
            {
                Server = leader
            }))
            {
                var sub = await store.Subscriptions.CreateAsync <User>();

                var worker = store.Subscriptions.GetSubscriptionWorker <User>(sub);

                var waitForBatch = new ManualResetEvent(false);
                var t            = worker.Run((batch) => { waitForBatch.WaitOne(TimeSpan.FromSeconds(15)); });

                using (var session = store.OpenAsyncSession())
                {
                    await session.StoreAsync(new User());

                    await session.SaveChangesAsync();
                }

                var database = await leader.ServerStore.DatabasesLandlord.TryGetOrCreateResourceStore(store.Database);

                database.SubscriptionStorage.GetSubscriptionFromServerStore(sub);


                var server2    = GetNewServer();
                var server2Url = server2.ServerStore.GetNodeHttpServerUrl();
                Servers.Add(server2);

                using (var requestExecutor = ClusterRequestExecutor.CreateForSingleNode(leader.WebUrl, null))
                    using (requestExecutor.ContextPool.AllocateOperationContext(out var ctx))
                    {
                        await requestExecutor.ExecuteAsync(new AddClusterNodeCommand(server2Url, watcher : true), ctx);

                        var addDatabaseNode = new AddDatabaseNodeOperation(store.Database);
                        await store.Maintenance.Server.SendAsync(addDatabaseNode);
                        await WaitAndAssertForValueAsync(() => GetMembersCount(store), 2);
                    }

                database = await server2.ServerStore.DatabasesLandlord.TryGetOrCreateResourceStore(store.Database);

                var state = database.SubscriptionStorage.GetSubscriptionFromServerStore(sub);

                using (server2.ServerStore.Engine.ContextPool.AllocateOperationContext(out ClusterOperationContext context))
                    using (context.OpenReadTransaction())
                    {
                        Assert.Single(SubscriptionStorage.GetResendItems(context, store.Database, state.SubscriptionId));
                    }

                waitForBatch.Set();
            }
        }