Esempio n. 1
0
        public static void WriteOperationId(this BlittableJsonTextWriter writer, JsonOperationContext context, long operationId)
        {
            writer.WriteStartObject();

            writer.WritePropertyName("OperationId");
            writer.WriteInteger(operationId);

            writer.WriteEndObject();
        }
Esempio n. 2
0
        public Task GetDocSize()
        {
            var id = GetQueryStringValueAndAssertIfSingleAndNotEmpty("id");

            using (ContextPool.AllocateOperationContext(out DocumentsOperationContext context))
                using (context.OpenReadTransaction())
                {
                    var document = Database.DocumentsStorage.GetDocumentMetrics(context, id);
                    if (document == null)
                    {
                        HttpContext.Response.StatusCode = (int)HttpStatusCode.NotFound;
                        return(Task.CompletedTask);
                    }
                    using (var writer = new BlittableJsonTextWriter(context, ResponseBodyStream()))
                    {
                        writer.WriteStartObject();

                        writer.WritePropertyName("Id");
                        writer.WriteString(id);
                        writer.WriteComma();

                        writer.WritePropertyName("ActualSize");
                        writer.WriteInteger(document.Value.ActualSize);
                        writer.WriteComma();


                        writer.WritePropertyName("HumaneActualSize");
                        writer.WriteString(Sizes.Humane(document.Value.ActualSize));
                        writer.WriteComma();


                        writer.WritePropertyName("AllocatedSize");
                        writer.WriteInteger(document.Value.AllocatedSize);
                        writer.WriteComma();

                        writer.WritePropertyName("HumaneAllocatedSize");
                        writer.WriteString(Sizes.Humane(document.Value.AllocatedSize));

                        writer.WriteEndObject();
                    }

                    return(Task.CompletedTask);
                }
        }
        public Task RunningQueries()
        {
            var indexes = Database
                          .IndexStore
                          .GetIndexes()
                          .ToList();

            DocumentsOperationContext context;

            using (ContextPool.AllocateOperationContext(out context))
                using (var writer = new BlittableJsonTextWriter(context, ResponseBodyStream()))
                {
                    writer.WriteStartObject();
                    foreach (var index in indexes)
                    {
                        writer.WritePropertyName(index.Name);
                        writer.WriteStartArray();

                        var isFirstInternal = true;
                        foreach (var query in index.CurrentlyRunningQueries)
                        {
                            if (isFirstInternal == false)
                            {
                                writer.WriteComma();
                            }

                            isFirstInternal = false;

                            writer.WriteStartObject();

                            writer.WritePropertyName((nameof(query.Duration)));
                            writer.WriteString(query.Duration.ToString());
                            writer.WriteComma();

                            writer.WritePropertyName((nameof(query.QueryId)));
                            writer.WriteInteger(query.QueryId);
                            writer.WriteComma();

                            writer.WritePropertyName((nameof(query.StartTime)));
                            writer.WriteString(query.StartTime.GetDefaultRavenFormat());
                            writer.WriteComma();

                            writer.WritePropertyName((nameof(query.QueryInfo)));
                            writer.WriteIndexQuery(context, query.QueryInfo);

                            writer.WriteEndObject();
                        }

                        writer.WriteEndArray();
                    }

                    writer.WriteEndObject();
                }

            return(Task.CompletedTask);
        }
Esempio n. 4
0
        public async Task Put()
        {
            DocumentsOperationContext context;

            using (ContextPool.AllocateOperationContext(out context))
            {
                var id = GetQueryStringValueAndAssertIfSingleAndNotEmpty("id");

                var doc = await context.ReadForDiskAsync(RequestBodyStream(), id);

                var etag = GetLongFromHeaders("If-Match");

                var cmd = new MergedPutCommand
                {
                    Database     = Database,
                    ExepctedEtag = etag,
                    Key          = id,
                    Document     = doc
                };

                await Database.TxMerger.Enqueue(cmd);

                if (cmd.ConcurrencyException != null)
                {
                    HttpContext.Response.StatusCode = (int)HttpStatusCode.Conflict;
                    using (var writer = new BlittableJsonTextWriter(context, ResponseBodyStream()))
                    {
                        writer.WriteStartObject();
                        writer.WritePropertyName("Key");
                        writer.WriteString(cmd.Key);
                        writer.WriteComma();
                        writer.WritePropertyName("Error");
                        writer.WriteString(cmd.ConcurrencyException.Message);
                        writer.WriteEndObject();
                    }
                    return;
                }

                HttpContext.Response.StatusCode = 201;

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

                    writer.WritePropertyName(("Key"));
                    writer.WriteString(cmd.PutResult.Key);
                    writer.WriteComma();

                    writer.WritePropertyName(("Etag"));
                    writer.WriteInteger(cmd.PutResult.Etag);

                    writer.WriteEndObject();
                }
            }
        }
Esempio n. 5
0
        public void Persist(JsonOperationContext context, BlittableJsonTextWriter writer)
        {
            writer.WriteStartObject();

            writer.WritePropertyName(nameof(Name));
            writer.WriteString(Name);
            writer.WriteComma();

            writer.WritePropertyName(nameof(Version));
            writer.WriteInteger(Version);
            writer.WriteComma();

            writer.WritePropertyName(nameof(Collections));
            writer.WriteStartArray();
            var isFirst = true;

            foreach (var collection in Collections)
            {
                if (isFirst == false)
                {
                    writer.WriteComma();
                }

                isFirst = false;
                writer.WriteString((collection));
            }

            writer.WriteEndArray();
            writer.WriteComma();

            writer.WritePropertyName(nameof(LockMode));
            writer.WriteInteger((int)LockMode);
            writer.WriteComma();

            writer.WritePropertyName(nameof(Priority));
            writer.WriteInteger((int)Priority);
            writer.WriteComma();

            PersistFields(context, writer);

            writer.WriteEndObject();
        }
Esempio n. 6
0
 private void HandleNoRoute(JsonOperationContext context, BlittableJsonTextWriter writer, string method, string url, string query, LazyStringValue statusProperty, LazyStringValue resultProperty)
 {
     writer.WritePropertyName(statusProperty);
     writer.WriteInteger((int)HttpStatusCode.BadRequest);
     writer.WritePropertyName(resultProperty);
     context.Write(writer, new DynamicJsonValue
     {
         ["Error"] = $"There is no handler for path: {method} {url}{query}"
     });
     writer.WriteEndObject();
 }
Esempio n. 7
0
        public Task GetClientConfiguration()
        {
            var inherit = GetBoolValueQueryString("inherit", required: false) ?? true;

            var  configuration       = Database.ClientConfiguration;
            long etag                = configuration?.Etag ?? -1;
            var  serverConfiguration = GetServerClientConfiguration(out long serverIndex);

            etag = Hashing.Combine(etag, serverConfiguration?.Etag ?? -2);
            if (inherit)
            {
                if (configuration == null || configuration.Disabled)
                {
                    if (serverConfiguration != null)
                    {
                        configuration = serverConfiguration;
                        etag          = serverIndex;
                    }
                }
            }

            using (ContextPool.AllocateOperationContext(out JsonOperationContext context))
            {
                BlittableJsonReaderObject clientConfigurationJson = null;
                if (configuration != null)
                {
                    var val = configuration.ToJson();
                    clientConfigurationJson = context.ReadObject(val, Constants.Configuration.ClientId);
                }

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

                    writer.WritePropertyName(nameof(GetClientConfigurationOperation.Result.Etag));
                    writer.WriteInteger(etag);
                    writer.WriteComma();

                    writer.WritePropertyName(nameof(GetClientConfigurationOperation.Result.Configuration));
                    if (clientConfigurationJson != null)
                    {
                        writer.WriteObject(clientConfigurationJson);
                    }
                    else
                    {
                        writer.WriteNull();
                    }

                    writer.WriteEndObject();
                }
            }

            return(Task.CompletedTask);
        }
        public async Task RegisterHubAccess()
        {
            var hubTaskName = GetStringQueryString("name", true);

            if (ResourceNameValidator.IsValidResourceName(Database.Name, ServerStore.Configuration.Core.DataDirectory.FullPath, out string errorMessage) == false)
            {
                throw new BadRequestException(errorMessage);
            }

            ServerStore.LicenseManager.AssertCanAddPullReplicationAsHub();

            using (ServerStore.ContextPool.AllocateOperationContext(out TransactionOperationContext context))
            {
                PullReplicationDefinition hubDefinition;

                using (context.OpenReadTransaction())
                {
                    hubDefinition = Server.ServerStore.Cluster.ReadPullReplicationDefinition(Database.Name, hubTaskName, context);
                    if (hubDefinition == null)
                    {
                        HttpContext.Response.StatusCode = (int)HttpStatusCode.NotFound;
                        return;
                    }
                }

#pragma warning disable CS0618 // Type or member is obsolete
                if (hubDefinition.Certificates != null && hubDefinition.Certificates.Count > 0)
#pragma warning restore CS0618 // Type or member is obsolete
                {
                    // handle backward compatibility
                    throw new InvalidOperationException("Cannot register hub access to a replication hub that already has inline certificates: " + hubTaskName +
                                                        ". Create a new replication hub and try again");
                }

                var blittableJson = await context.ReadForMemoryAsync(RequestBodyStream(), "register-hub-access");

                var access = JsonDeserializationClient.ReplicationHubAccess(blittableJson);
                access.Validate(hubDefinition.WithFiltering);

                using var cert = new X509Certificate2(Convert.FromBase64String(access.CertificateBase64));

                var command = new RegisterReplicationHubAccessCommand(Database.Name, hubTaskName, access, cert, GetRaftRequestIdFromQuery());
                var result  = await Server.ServerStore.SendToLeaderAsync(command);
                await WaitForIndexToBeApplied(context, result.Index);

                using (var writer = new BlittableJsonTextWriter(context, ResponseBodyStream()))
                {
                    writer.WriteStartObject();
                    writer.WritePropertyName(nameof(ReplicationHubAccessResponse.RaftCommandIndex));
                    writer.WriteInteger(result.Index);
                    writer.WriteEndObject();
                }
            }
        }
Esempio n. 9
0
        private void GetRevisions(DocumentsOperationContext context, bool metadataOnly)
        {
            var sw = Stopwatch.StartNew();

            var id       = GetQueryStringValueAndAssertIfSingleAndNotEmpty("id");
            var before   = GetDateTimeQueryString("before");
            var start    = GetStart();
            var pageSize = GetPageSize();

            Document[] revisions = Array.Empty <Document>();
            long       count     = 0;

            if (before != null)
            {
                var revision = Database.DocumentsStorage.RevisionsStorage.GetRevisionBefore(context, id, before.Value);
                if (revision != null)
                {
                    count     = 1;
                    revisions = new[] { revision };
                }
            }
            else
            {
                (revisions, count) = Database.DocumentsStorage.RevisionsStorage.GetRevisions(context, id, start, pageSize);
            }


            var actualChangeVector = revisions.Length == 0 ? "" : revisions[0].ChangeVector;

            if (GetStringFromHeaders("If-None-Match") == actualChangeVector)
            {
                HttpContext.Response.StatusCode = (int)HttpStatusCode.NotModified;
                return;
            }

            HttpContext.Response.Headers["ETag"] = "\"" + actualChangeVector + "\"";

            int loadedRevisionsCount;

            using (var writer = new BlittableJsonTextWriter(context, ResponseBodyStream()))
            {
                writer.WriteStartObject();
                writer.WritePropertyName("Results");
                writer.WriteDocuments(context, revisions, metadataOnly, out loadedRevisionsCount);

                writer.WriteComma();

                writer.WritePropertyName("TotalResults");
                writer.WriteInteger(count);
                writer.WriteEndObject();
            }

            AddPagingPerformanceHint(PagingOperationType.Revisions, nameof(GetRevisions), HttpContext.Request.QueryString.Value, loadedRevisionsCount, pageSize, sw.ElapsedMilliseconds);
        }
        public static void WriteIndexEntriesQueryResult(this BlittableJsonTextWriter writer, JsonOperationContext context, IndexEntriesQueryResult result)
        {
            writer.WriteStartObject();

            writer.WritePropertyName(nameof(result.TotalResults));
            writer.WriteInteger(result.TotalResults);
            writer.WriteComma();

            writer.WritePropertyName(nameof(result.SkippedResults));
            writer.WriteInteger(result.SkippedResults);
            writer.WriteComma();

            writer.WritePropertyName(nameof(result.DurationInMs));
            writer.WriteInteger(result.DurationInMs);
            writer.WriteComma();

            writer.WriteQueryResult(context, result, metadataOnly: false, numberOfResults: out int _, partial: true);

            writer.WriteEndObject();
        }
        public static void WriteMoreLikeThisQueryResult(this BlittableJsonTextWriter writer, JsonOperationContext context, MoreLikeThisQueryResultServerSide result, out int numberOfResults)
        {
            writer.WriteStartObject();

            writer.WritePropertyName(nameof(result.DurationInMs));
            writer.WriteInteger(result.DurationInMs);
            writer.WriteComma();

            writer.WriteQueryResult(context, result, metadataOnly: false, numberOfResults: out numberOfResults, partial: true);

            writer.WriteEndObject();
        }
Esempio n. 12
0
 private void WriteClusterMaintenanceConnectionHeader(BlittableJsonTextWriter writer)
 {
     writer.WriteStartObject();
     {
         writer.WritePropertyName(nameof(ClusterMaintenanceConnectionHeader.LeaderClusterTag));
         writer.WriteString(_parent._leaderClusterTag);
         writer.WritePropertyName(nameof(ClusterMaintenanceConnectionHeader.Term));
         writer.WriteInteger(_parent._term);
     }
     writer.WriteEndObject();
     writer.Flush();
 }
Esempio n. 13
0
            private void WriteClientConfiguration(ClientConfiguration clientConfiguration)
            {
                if (clientConfiguration == null)
                {
                    _writer.WriteNull();
                    return;
                }

                _writer.WriteStartObject();

                _writer.WritePropertyName(nameof(clientConfiguration.Etag));
                _writer.WriteInteger(clientConfiguration.Etag);
                _writer.WriteComma();

                _writer.WritePropertyName(nameof(clientConfiguration.Disabled));
                _writer.WriteBool(clientConfiguration.Disabled);

                if (clientConfiguration.MaxNumberOfRequestsPerSession.HasValue)
                {
                    _writer.WriteComma();
                    _writer.WritePropertyName(nameof(clientConfiguration.MaxNumberOfRequestsPerSession));
                    _writer.WriteInteger(clientConfiguration.MaxNumberOfRequestsPerSession.Value);
                }

                if (clientConfiguration.PrettifyGeneratedLinqExpressions.HasValue)
                {
                    _writer.WriteComma();
                    _writer.WritePropertyName(nameof(clientConfiguration.PrettifyGeneratedLinqExpressions));
                    _writer.WriteBool(clientConfiguration.PrettifyGeneratedLinqExpressions.Value);
                }

                if (clientConfiguration.ReadBalanceBehavior.HasValue)
                {
                    _writer.WriteComma();
                    _writer.WritePropertyName(nameof(clientConfiguration.ReadBalanceBehavior));
                    _writer.WriteString(clientConfiguration.ReadBalanceBehavior.Value.ToString());
                }

                _writer.WriteEndObject();
            }
Esempio n. 14
0
        private void WriteStreamQueryStatistics()
        {
            _writer.WritePropertyName(nameof(StreamQueryStatistics.ResultEtag));
            _writer.WriteInteger(ResultEtag);
            _writer.WriteComma();

            _writer.WritePropertyName(nameof(StreamQueryStatistics.IsStale));
            _writer.WriteBool(IsStale);
            _writer.WriteComma();

            _writer.WritePropertyName(nameof(StreamQueryStatistics.IndexName));
            _writer.WriteString(IndexName);
            _writer.WriteComma();

            _writer.WritePropertyName(nameof(StreamQueryStatistics.TotalResults));
            _writer.WriteInteger(TotalResults);
            _writer.WriteComma();

            _writer.WritePropertyName(nameof(StreamQueryStatistics.IndexTimestamp));
            _writer.WriteString(IndexTimestamp.GetDefaultRavenFormat(isUtc: true));
            _writer.WriteComma();
        }
        public void WriteQueryStatistics(long resultEtag, bool isStale, string indexName, long totalResults, DateTime timestamp)
        {
            _writer.WritePropertyName(nameof(StreamQueryStatistics.ResultEtag));
            _writer.WriteInteger(resultEtag);
            _writer.WriteComma();

            _writer.WritePropertyName(nameof(StreamQueryStatistics.IsStale));
            _writer.WriteBool(isStale);
            _writer.WriteComma();

            _writer.WritePropertyName(nameof(StreamQueryStatistics.IndexName));
            _writer.WriteString(indexName);
            _writer.WriteComma();

            _writer.WritePropertyName(nameof(StreamQueryStatistics.TotalResults));
            _writer.WriteInteger(totalResults);
            _writer.WriteComma();

            _writer.WritePropertyName(nameof(StreamQueryStatistics.IndexTimestamp));
            _writer.WriteString(timestamp.GetDefaultRavenFormat(isUtc: true));
            _writer.WriteComma();
        }
Esempio n. 16
0
        private async Task Send(string command, string value, string[] values)
        {
            var taskCompletionSource = new TaskCompletionSource <object>(TaskCreationOptions.RunContinuationsAsynchronously);
            int currentCommandId;
            await _semaphore.WaitAsync(_cts.Token).ConfigureAwait(false);

            try
            {
                currentCommandId = ++_commandId;
                using (_requestExecutor.ContextPool.AllocateOperationContext(out var context))
                    using (var writer = new BlittableJsonTextWriter(context, _ms))
                    {
                        writer.WriteStartObject();
                        writer.WritePropertyName("CommandId");
                        writer.WriteInteger(currentCommandId);

                        writer.WriteComma();
                        writer.WritePropertyName("Command");
                        writer.WriteString(command);
                        writer.WriteComma();

                        writer.WritePropertyName("Param");
                        writer.WriteString(value);

                        if (values != null && values.Length > 0)
                        {
                            writer.WriteComma();
                            writer.WriteArray("Params", values);
                        }

                        writer.WriteEndObject();
                    }

                _ms.TryGetBuffer(out var buffer);

                _confirmations.TryAdd(currentCommandId, taskCompletionSource);

                await _client.SendAsync(buffer, WebSocketMessageType.Text, endOfMessage : true, cancellationToken : _cts.Token).ConfigureAwait(false);
            }
            finally
            {
                _ms.SetLength(0);
                _semaphore.Release();
            }

            if (await taskCompletionSource.Task.WaitWithTimeout(TimeSpan.FromSeconds(15)).ConfigureAwait(false) == false)
            {
                throw new TimeoutException("Did not get a confirmation for command #" + currentCommandId);
            }
        }
Esempio n. 17
0
 private void WriteOperationHeaderToRemote(BlittableJsonTextWriter writer)
 {
     writer.WriteStartObject();
     {
         writer.WritePropertyName(nameof(TcpConnectionHeaderMessage.Operation));
         writer.WriteString(TcpConnectionHeaderMessage.OperationTypes.Heartbeats.ToString());
         writer.WritePropertyName(nameof(TcpConnectionHeaderMessage.OperationVersion));
         writer.WriteInteger(TcpConnectionHeaderMessage.HeartbeatsTcpVersion);
         writer.WritePropertyName(nameof(TcpConnectionHeaderMessage.DatabaseName));
         writer.WriteNull();
     }
     writer.WriteEndObject();
     writer.Flush();
 }
Esempio n. 18
0
        public static void WriteDocumentQueryResult(this BlittableJsonTextWriter writer, JsonOperationContext context, DocumentQueryResult result, bool metadataOnly, out int numberOfResults)
        {
            writer.WriteStartObject();

            writer.WritePropertyName(nameof(result.TotalResults));
            writer.WriteInteger(result.TotalResults);
            writer.WriteComma();

            writer.WritePropertyName(nameof(result.SkippedResults));
            writer.WriteInteger(result.SkippedResults);
            writer.WriteComma();

            writer.WritePropertyName(nameof(result.DurationInMs));
            writer.WriteInteger(result.DurationInMs);
            writer.WriteComma();

            writer.WriteArray(nameof(result.IncludedPaths),
                              result.IncludedPaths);
            writer.WriteComma();

            writer.WriteQueryResult(context, result, metadataOnly, out numberOfResults, partial: true);

            writer.WriteEndObject();
        }
Esempio n. 19
0
        protected void PersistMapFields(JsonOperationContext context, BlittableJsonTextWriter writer)
        {
            writer.WritePropertyName((nameof(MapFields)));
            writer.WriteStartArray();
            var first = true;

            foreach (var field in MapFields.Values)
            {
                if (first == false)
                {
                    writer.WriteComma();
                }

                writer.WriteStartObject();

                writer.WritePropertyName((nameof(field.Name)));
                writer.WriteString((field.Name));
                writer.WriteComma();

                writer.WritePropertyName((nameof(field.Highlighted)));
                writer.WriteBool(field.Highlighted);
                writer.WriteComma();

                writer.WritePropertyName((nameof(field.SortOption)));
                writer.WriteInteger((int)(field.SortOption ?? SortOptions.None));
                writer.WriteComma();

                writer.WritePropertyName((nameof(field.MapReduceOperation)));
                writer.WriteInteger((int)(field.MapReduceOperation));

                writer.WriteEndObject();

                first = false;
            }
            writer.WriteEndArray();
        }
Esempio n. 20
0
        public static void WriteSuggestionQuery(this BlittableJsonTextWriter writer, DocumentConventions conventions, JsonOperationContext context, SuggestionQuery query)
        {
            writer.WriteStartObject();

            writer.WritePropertyName(nameof(query.IndexName));
            writer.WriteString(query.IndexName);
            writer.WriteComma();

            if (query.Popularity)
            {
                writer.WritePropertyName(nameof(query.Popularity));
                writer.WriteBool(query.Popularity);
                writer.WriteComma();
            }

            if (query.Accuracy.HasValue)
            {
                writer.WritePropertyName(nameof(query.Accuracy));
                writer.WriteDouble(query.Accuracy.Value);
                writer.WriteComma();
            }

            if (query.Distance.HasValue)
            {
                writer.WritePropertyName(nameof(query.Distance));
                writer.WriteString(query.Distance.Value.ToString());
                writer.WriteComma();
            }

            if (string.IsNullOrEmpty(query.Field) == false)
            {
                writer.WritePropertyName(nameof(query.Field));
                writer.WriteString(query.Field);
                writer.WriteComma();
            }

            if (string.IsNullOrEmpty(query.Term) == false)
            {
                writer.WritePropertyName(nameof(query.Term));
                writer.WriteString(query.Term);
                writer.WriteComma();
            }

            writer.WritePropertyName(nameof(query.MaxSuggestions));
            writer.WriteInteger(query.MaxSuggestions);

            writer.WriteEndObject();
        }
Esempio n. 21
0
        public Task GetNextOperationId()
        {
            var nextId = Database.Operations.GetNextOperationId();

            DocumentsOperationContext context;

            using (ContextPool.AllocateOperationContext(out context))
            {
                using (var writer = new BlittableJsonTextWriter(context, ResponseBodyStream()))
                {
                    writer.WriteInteger(nextId);
                }
            }

            return(Task.CompletedTask);
        }
        public static void WriteTermsQueryResult(this BlittableJsonTextWriter writer, JsonOperationContext context, TermsQueryResultServerSide queryResult)
        {
            writer.WriteStartObject();

            writer.WritePropertyName(nameof(queryResult.IndexName));
            writer.WriteString(queryResult.IndexName);
            writer.WriteComma();

            writer.WritePropertyName(nameof(queryResult.ResultEtag));
            writer.WriteInteger(queryResult.ResultEtag);
            writer.WriteComma();

            writer.WriteArray(nameof(queryResult.Terms), queryResult.Terms);

            writer.WriteEndObject();
        }
Esempio n. 23
0
 private static void WriteOperationHeaderToRemote(BlittableJsonTextWriter writer, TcpConnectionHeaderMessage.OperationTypes operation, string databaseName)
 {
     writer.WriteStartObject();
     {
         writer.WritePropertyName(nameof(TcpConnectionHeaderMessage.Operation));
         writer.WriteString(operation.ToString());
         writer.WriteComma();
         writer.WritePropertyName(nameof(TcpConnectionHeaderMessage.OperationVersion));
         writer.WriteInteger(TcpConnectionHeaderMessage.GetOperationTcpVersion(operation));
         writer.WriteComma();
         writer.WritePropertyName(nameof(TcpConnectionHeaderMessage.DatabaseName));
         writer.WriteString(databaseName);
     }
     writer.WriteEndObject();
     writer.Flush();
 }
        public Task HugeDocuments()
        {
            using (ContextPool.AllocateOperationContext(out DocumentsOperationContext context))
                using (var writer = new BlittableJsonTextWriter(context, ResponseBodyStream()))
                    using (context.OpenReadTransaction())
                    {
                        writer.WriteStartObject();
                        writer.WritePropertyName("Results");

                        writer.WriteStartArray();

                        var isFirst = true;

                        foreach (var pair in context.DocumentDatabase.HugeDocuments.GetHugeDocuments())
                        {
                            if (isFirst == false)
                            {
                                writer.WriteComma();
                            }

                            isFirst = false;

                            writer.WriteStartObject();

                            writer.WritePropertyName("Id");
                            writer.WriteString(pair.Key.Item1);

                            writer.WriteComma();

                            writer.WritePropertyName("Size");
                            writer.WriteInteger(pair.Value);

                            writer.WriteComma();

                            writer.WritePropertyName("LastAccess");
                            writer.WriteString(pair.Key.Item2.ToString("o", CultureInfo.InvariantCulture));

                            writer.WriteEndObject();
                        }

                        writer.WriteEndArray();

                        writer.WriteEndObject();
                    }

            return(Task.CompletedTask);
        }
        protected override void PersistMapFields(JsonOperationContext context, BlittableJsonTextWriter writer)
        {
            writer.WritePropertyName(nameof(MapFields));
            writer.WriteStartArray();
            var first = true;

            foreach (var field in MapFields.Values.Select(x => x.As <AutoIndexField>()))
            {
                if (first == false)
                {
                    writer.WriteComma();
                }

                writer.WriteStartObject();

                writer.WritePropertyName(nameof(field.Name));
                writer.WriteString(field.Name);
                writer.WriteComma();

                writer.WritePropertyName(nameof(field.Indexing));
                writer.WriteString(field.Indexing.ToString());
                writer.WriteComma();

                writer.WritePropertyName(nameof(field.Aggregation));
                writer.WriteInteger((int)field.Aggregation);
                writer.WriteComma();

                writer.WritePropertyName(nameof(field.Spatial));
                if (field.Spatial == null)
                {
                    writer.WriteNull();
                }
                else
                {
                    writer.WriteObject(DocumentConventions.DefaultForServer.Serialization.DefaultConverter.ToBlittable(field.Spatial, context));
                }
                writer.WriteComma();

                writer.WritePropertyName(nameof(field.HasSuggestions));
                writer.WriteBool(field.HasSuggestions);

                writer.WriteEndObject();

                first = false;
            }
            writer.WriteEndArray();
        }
Esempio n. 26
0
        public Task GetRevisions()
        {
            var etag     = GetLongQueryString("etag", false) ?? 0;
            var pageSize = GetPageSize();

            using (ContextPool.AllocateOperationContext(out DocumentsOperationContext context))
                using (context.OpenReadTransaction())
                    using (var writer = new BlittableJsonTextWriter(context, ResponseBodyStream()))
                    {
                        writer.WriteStartObject();
                        writer.WritePropertyName("Revisions");
                        writer.WriteStartArray();

                        var first = true;
                        foreach (var revision in Database.DocumentsStorage.RevisionsStorage.GetRevisionsFrom(context, etag, pageSize))
                        {
                            if (first == false)
                            {
                                writer.WriteComma();
                            }
                            first = false;

                            writer.WriteStartObject();

                            writer.WritePropertyName(nameof(Document.Id));
                            writer.WriteString(revision.Id);
                            writer.WriteComma();

                            writer.WritePropertyName(nameof(Document.Etag));
                            writer.WriteInteger(revision.Etag);
                            writer.WriteComma();

                            writer.WritePropertyName(nameof(Document.LastModified));
                            writer.WriteDateTime(revision.LastModified, true);
                            writer.WriteComma();

                            writer.WritePropertyName(nameof(Document.ChangeVector));
                            writer.WriteString(revision.ChangeVector);

                            writer.WriteEndObject();
                        }

                        writer.WriteEndArray();
                        writer.WriteEndObject();
                    }
            return(Task.CompletedTask);
        }
Esempio n. 27
0
        public Task GetNextOperationId()
        {
            var nextId = ServerStore.Operations.GetNextOperationId();

            using (ServerStore.ContextPool.AllocateOperationContext(out JsonOperationContext context))
            {
                using (var writer = new BlittableJsonTextWriter(context, ResponseBodyStream()))
                {
                    writer.WriteStartObject();
                    writer.WritePropertyName("Id");
                    writer.WriteInteger(nextId);
                    writer.WriteEndObject();
                }
            }

            return(Task.CompletedTask);
        }
Esempio n. 28
0
        public Task Reset()
        {
            var name = GetQueryStringValueAndAssertIfSingleAndNotEmpty("name");

            var newIndexId = Database.IndexStore.ResetIndex(name);

            using (ContextPool.AllocateOperationContext(out DocumentsOperationContext context))
                using (var writer = new BlittableJsonTextWriter(context, ResponseBodyStream()))
                {
                    writer.WriteStartObject();
                    writer.WritePropertyName("IndexId");
                    writer.WriteInteger(newIndexId);
                    writer.WriteEndObject();
                }

            return(Task.CompletedTask);
        }
        public async Task Cleanup()
        {
            var count = await Database.TombstoneCleaner.ExecuteCleanup();

            using (Database.DocumentsStorage.ContextPool.AllocateOperationContext(out JsonOperationContext context))
            {
                using (var writer = new BlittableJsonTextWriter(context, ResponseBodyStream()))
                {
                    writer.WriteStartObject();

                    writer.WritePropertyName("Value");
                    writer.WriteInteger(count);

                    writer.WriteEndObject();
                }
            }
        }
Esempio n. 30
0
        public IDisposable Initialize(DatabaseSmugglerOptions options, SmugglerResult result, long buildVersion)
        {
            _gzipStream = new GZipStream(_stream, CompressionMode.Compress, leaveOpen: true);
            _writer     = new BlittableJsonTextWriter(_context, _gzipStream);

            _writer.WriteStartObject();

            _writer.WritePropertyName("BuildVersion");
            _writer.WriteInteger(buildVersion);

            return(new DisposableAction(() =>
            {
                _writer.WriteEndObject();
                _writer.Dispose();
                _gzipStream.Dispose();
            }));
        }