private void GetCompareExchangeValuesByKey(TransactionOperationContext context, Microsoft.Extensions.Primitives.StringValues keys)
        {
            var sw = Stopwatch.StartNew();

            var items = new List <(string Key, long Index, BlittableJsonReaderObject Value)>(keys.Count);

            foreach (var key in keys)
            {
                var item = ServerStore.Cluster.GetCompareExchangeValue(context, CompareExchangeCommandBase.GetActualKey(Database.Name, key));
                if (item.Value == null && keys.Count == 1)
                {
                    HttpContext.Response.StatusCode = (int)HttpStatusCode.NotFound;
                    return;
                }

                items.Add((key, item.Index, item.Value));
            }

            var  numberOfResults           = 0;
            long totalDocumentsSizeInBytes = 0;

            using (var writer = new BlittableJsonTextWriter(context, ResponseBodyStream()))
            {
                writer.WriteStartObject();

                writer.WriteArray(context, "Results", items,
                                  (textWriter, operationContext, item) =>
                {
                    numberOfResults++;
                    totalDocumentsSizeInBytes += item.Value?.Size ?? 0;
                    operationContext.Write(textWriter, new DynamicJsonValue
                    {
                        ["Key"]   = item.Key,
                        ["Value"] = item.Value,
                        ["Index"] = item.Index
                    });
                });

                writer.WriteEndObject();
            }

            AddPagingPerformanceHint(PagingOperationType.CompareExchange, nameof(GetCompareExchangeValuesByKey), HttpContext.Request.QueryString.Value,
                                     numberOfResults, keys.Count, sw.ElapsedMilliseconds, totalDocumentsSizeInBytes);
        }
        private void GetCompareExchangeValues(TransactionOperationContext context)
        {
            var sw = Stopwatch.StartNew();

            var start    = GetStart();
            var pageSize = GetPageSize();

            var startsWithKey = GetStringQueryString("startsWith", false);
            var items         = ServerStore.Cluster.GetCompareExchangeValuesStartsWith(context, Database.Name, CompareExchangeCommandBase.GetActualKey(Database.Name, startsWithKey), start, pageSize);

            var numberOfResults = 0;

            using (var writer = new BlittableJsonTextWriter(context, ResponseBodyStream()))
            {
                writer.WriteStartObject();

                writer.WriteArray(context, "Results", items,
                                  (textWriter, operationContext, item) =>
                {
                    numberOfResults++;
                    operationContext.Write(textWriter, new DynamicJsonValue
                    {
                        [nameof(CompareExchangeListItem.Key)]   = item.Key,
                        [nameof(CompareExchangeListItem.Value)] = item.Value,
                        [nameof(CompareExchangeListItem.Index)] = item.Index
                    });
                });

                writer.WriteEndObject();
            }

            AddPagingPerformanceHint(PagingOperationType.CompareExchange, nameof(ClusterStateMachine.GetCompareExchangeValuesStartsWith),
                                     HttpContext.Request.QueryString.Value, numberOfResults, pageSize, sw.ElapsedMilliseconds);
        }
Exemple #3
0
        public IEnumerable <(string key, long index, BlittableJsonReaderObject value)> GetCompareExchangeValues()
        {
            Debug.Assert(_serverContext != null);

            return(_database.ServerStore.Cluster.GetCompareExchangeValuesStartsWith(_serverContext, _database.Name, CompareExchangeCommandBase.GetActualKey(_database.Name, null), 0, int.MaxValue));
        }