Exemplo n.º 1
0
        public Task State()
        {
            var id = GetLongQueryString("id");
            // ReSharper disable once PossibleInvalidOperationException
            var state = Database.Operations.GetOperation(id)?.State;

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

            using (ContextPool.AllocateOperationContext(out DocumentsOperationContext context))
            {
                using (var writer = new BlittableJsonTextWriter(context, ResponseBodyStream()))
                {
                    context.Write(writer, state.ToJson());
                    // writes Patch response
                    if (TrafficWatchManager.HasRegisteredClients)
                    {
                        AddStringToHttpContext(writer.ToString(), TrafficWatchChangeType.Operations);
                    }
                }
            }

            return(Task.CompletedTask);
        }
Exemplo n.º 2
0
        public async Task GetNextHiLo()
        {
            using (ContextPool.AllocateOperationContext(out DocumentsOperationContext context))
            {
                var tag                    = GetQueryStringValueAndAssertIfSingleAndNotEmpty("tag");
                var lastSize               = GetLongQueryString("lastBatchSize", false) ?? 0;
                var lastRangeAt            = GetStringQueryString("lastRangeAt", false);
                var identityPartsSeparator = GetStringQueryString("identityPartsSeparator", false) ?? "/";
                var lastMax                = GetLongQueryString("lastMax", false) ?? 0;

                var capacity = CalculateCapacity(lastSize, lastRangeAt);

                var cmd = new MergedNextHiLoCommand
                {
                    Database     = Database,
                    Key          = tag,
                    Capacity     = capacity,
                    Separator    = identityPartsSeparator,
                    LastRangeMax = lastMax
                };

                await Database.TxMerger.Enqueue(cmd);

                HttpContext.Response.StatusCode = (int)HttpStatusCode.Created;

                using (var writer = new BlittableJsonTextWriter(context, ResponseBodyStream()))
                {
                    context.Write(writer, new DynamicJsonValue
                    {
                        ["Prefix"]      = cmd.Prefix,
                        ["Low"]         = cmd.OldMax + 1,
                        ["High"]        = cmd.OldMax + capacity,
                        ["LastSize"]    = capacity,
                        ["ServerTag"]   = ServerStore.NodeTag,
                        ["LastRangeAt"] = DateTime.UtcNow.ToString(DefaultFormat.DateTimeOffsetFormatsToWrite)
                    });
                    if (TrafficWatchManager.HasRegisteredClients)
                    {
                        AddStringToHttpContext(writer.ToString(), TrafficWatchChangeType.Hilo);
                    }
                }
            }
        }