Example #1
0
        public static BlittableJsonReaderObject WriteDummyDocumentForAttachment(DocumentsOperationContext context, LegacyAttachmentDetails details)
        {
            var attachment = new DynamicJsonValue
            {
                ["Name"]        = details.Key,
                ["Hash"]        = details.Hash,
                ["ContentType"] = string.Empty,
                ["Size"]        = details.Size,
            };
            var attachmets = new DynamicJsonArray();

            attachmets.Add(attachment);
            var metadata = new DynamicJsonValue
            {
                [Constants.Documents.Metadata.Collection]  = "@files",
                [Constants.Documents.Metadata.Attachments] = attachmets,
                [Constants.Documents.Metadata.LegacyAttachmentsMetadata] = details.Metadata
            };
            var djv = new DynamicJsonValue
            {
                [Constants.Documents.Metadata.Key] = metadata,
            };

            return(context.ReadObject(djv, details.Id));
        }
        protected override IDataProvider <EmbeddedArrayValue> CreateArrayEmbedDataProvider(ReferenceInformation refInfo, DbConnection connection)
        {
            var queryParameters = string.Join(" and ", refInfo.ForeignKeyColumns.Select((column, idx) => $"\"{QuoteColumn(column)}\" = :p{idx}"));

            var query = $"select * from \"{QuoteTable(refInfo.SourceSchema, refInfo.SourceTableName)}\" where {queryParameters}";

            return(new SqlStatementProvider <EmbeddedArrayValue>(connection, query, specialColumns => GetColumns(specialColumns, refInfo.SourcePrimaryKeyColumns), reader =>
            {
                var objectProperties = new DynamicJsonArray();
                var specialProperties = new List <DynamicJsonValue>();
                var attachments = new List <Dictionary <string, byte[]> >();
                while (reader.Read())
                {
                    objectProperties.Add(ExtractFromReader(reader, refInfo.TargetDocumentColumns));
                    attachments.Add(ExtractAttachments(reader, refInfo.TargetAttachmentColumns));

                    if (refInfo.ChildReferences != null)
                    {
                        // fill only when used
                        specialProperties.Add(ExtractFromReader(reader, refInfo.TargetSpecialColumnsNames));
                    }
                }

                return new EmbeddedArrayValue
                {
                    ArrayOfNestedObjects = objectProperties,
                    SpecialColumnsValues = specialProperties,
                    Attachments = attachments
                };
            }));
        }
Example #3
0
        private QueryResult GetUnstableQueryResult(IDocumentStore store, DocumentStoreExtensions.DatabaseCommands commands, string query)
        {
            WaitForIndexing(store);

            var q = commands.Query(new IndexQuery()
            {
                Query = $"FROM INDEX 'CommentsCountPerBlog' WHERE {query} LIMIT 10 OFFSET 0"
            });

            var array = new DynamicJsonArray();

            foreach (BlittableJsonReaderObject result in q.Results)
            {
                result.Modifications = new DynamicJsonValue(result);
                result.Modifications.Remove("@metadata");

                array.Add(commands.Context.ReadObject(result, "blog"));
            }

            var djv = new DynamicJsonValue
            {
                ["_"] = array
            };

            var json = commands.Context.ReadObject(djv, "blog");

            q.Results = (BlittableJsonReaderArray)json["_"];
            return(q);
        }
        public DynamicJsonValue ToJson()
        {
            var djv = new DynamicJsonValue();

            var dict = new DynamicJsonValue();

            djv[nameof(RequestLatencies)] = dict;

            foreach (var key in RequestLatencies.Keys)
            {
                var queue = RequestLatencies[key];
                if (queue == null)
                {
                    continue;
                }

                var list = new DynamicJsonArray();
                foreach (var details in queue)
                {
                    list.Add(details.ToJson());
                }

                dict[key] = list;
            }

            return(djv);
        }
Example #5
0
        private DynamicJsonArray GetProcessThreadCollection(Process proc)
        {
            var dja        = new DynamicJsonArray();
            var collection = proc.Threads;

            for (var idx = 0; idx < collection.Count; idx++)
            {
                var i   = idx;
                var djv = new DynamicJsonValue();

                AddValue(djv, "Id", () => collection[i].Id);
                AddValue(djv, "BasePriority", () => collection[i].BasePriority);
                AddValue(djv, "CurrentPriority", () => collection[i].CurrentPriority);
                AddValue(djv, "PriorityBoostEnabled", () => collection[i].PriorityBoostEnabled);
                AddValue(djv, "PriorityLevel", () => collection[i].PriorityLevel);
                AddValue(djv, "StartAddress", () => collection[i].StartAddress.ToInt64());
                AddValue(djv, "ThreadState", () => collection[i].ThreadState);
                AddValue(djv, "WaitReason", () => collection[i].WaitReason);
                AddValue(djv, "PrivilegedProcessorTime", () => collection[i].PrivilegedProcessorTime);
                AddValue(djv, "StartTime", () => collection[i].StartTime);
                AddValue(djv, "TotalProcessorTime", () => collection[i].TotalProcessorTime);
                AddValue(djv, "UserProcessorTime", () => collection[i].UserProcessorTime);
                AddValue(djv, "Site", () => collection[i].Site);
                AddValue(djv, "Container", () => collection[i].Container);

                dja.Add(djv);
            }
            return(dja);
        }
Example #6
0
        public DynamicJsonValue ToJsonWithFilter(CanAccessDatabase filter)
        {
            var json = ToJsonInternal();

            var ravenSize            = 0L;
            var ravenTempBuffersSize = 0L;

            var items = new DynamicJsonArray();

            foreach (var databaseDiskUsage in Items)
            {
                if (filter(databaseDiskUsage.Database, requiresWrite: false))
                {
                    items.Add(databaseDiskUsage.ToJson());
                    ravenSize            += databaseDiskUsage.Size;
                    ravenTempBuffersSize += databaseDiskUsage.TempBuffersSize;
                }
            }

            if (items.Count == 0)
            {
                return(null);
            }

            json[nameof(Items)]                = items;
            json[nameof(RavenSize)]            = ravenSize;
            json[nameof(RavenTempBuffersSize)] = ravenTempBuffersSize;

            return(json);
        }
Example #7
0
        public override DynamicJsonValue ToJsonWithFilter(CanAccessDatabase filter)
        {
            var items = new DynamicJsonArray();

            foreach (var mountPointUsage in Items)
            {
                var usageAsJson = mountPointUsage.ToJsonWithFilter(filter);
                if (usageAsJson != null)
                {
                    usageAsJson.RemoveInMemoryPropertyByName(nameof(MountPointUsage.Items));

                    items.Add(usageAsJson);
                }
            }

            if (items.Count == 0)
            {
                return(null);
            }

            var json = base.ToJson();

            json[nameof(Items)] = items;

            return(json);
        }
Example #8
0
        public async Task GetReplicationOutgoingFailureStats()
        {
            using (ContextPool.AllocateOperationContext(out DocumentsOperationContext context))
                await using (var writer = new AsyncBlittableJsonTextWriter(context, ResponseBodyStream()))
                {
                    var data = new DynamicJsonArray();
                    foreach (var item in Database.ReplicationLoader.OutgoingFailureInfo)
                    {
                        data.Add(new DynamicJsonValue
                        {
                            ["Key"] = new DynamicJsonValue
                            {
                                [nameof(item.Key.Url)]      = item.Key.Url,
                                [nameof(item.Key.Database)] = item.Key.Database,
                                [nameof(item.Key.Disabled)] = item.Key.Disabled
                            },
                            ["Value"] = new DynamicJsonValue
                            {
                                ["ErrorsCount"]                         = item.Value.Errors.Count,
                                [nameof(item.Value.Errors)]             = new DynamicJsonArray(item.Value.Errors.Select(e => e.ToString())),
                                [nameof(item.Value.NextTimeout)]        = item.Value.NextTimeout,
                                [nameof(item.Value.RetryOn)]            = item.Value.RetryOn,
                                [nameof(item.Value.External)]           = item.Value.External,
                                [nameof(item.Value.DestinationDbId)]    = item.Value.DestinationDbId,
                                [nameof(item.Value.LastHeartbeatTicks)] = item.Value.LastHeartbeatTicks,
                            }
                        });
                    }

                    context.Write(writer, new DynamicJsonValue
                    {
                        ["Stats"] = data
                    });
                }
        }
Example #9
0
        public DynamicJsonValue ToJson()
        {
            var djv = new DynamicJsonValue();

            foreach (var key in Warnings.Keys)
            {
                var queue = Warnings[key];
                if (queue == null)
                {
                    continue;
                }

                var list = new DynamicJsonArray();
                foreach (var details in queue)
                {
                    list.Add(new DynamicJsonValue
                    {
                        [nameof(WarningDetails.NumberOfExceedingDocuments)]  = details.NumberOfExceedingDocuments,
                        [nameof(WarningDetails.SampleDocumentId)]            = details.SampleDocumentId,
                        [nameof(WarningDetails.MaxNumberOutputsPerDocument)] = details.MaxNumberOutputsPerDocument,
                        [nameof(WarningDetails.Suggestion)]      = details.Suggestion,
                        [nameof(WarningDetails.LastWarningTime)] = details.LastWarningTime
                    });
                }

                djv[key] = list;
            }

            return(new DynamicJsonValue(GetType())
            {
                [nameof(Warnings)] = djv
            });
        }
Example #10
0
        private async Task GetConflictsForDocument(string docId)
        {
            long maxEtag = 0;

            using (ContextPool.AllocateOperationContext(out DocumentsOperationContext context))
                await using (var writer = new AsyncBlittableJsonTextWriter(context, ResponseBodyStream()))
                    using (context.OpenReadTransaction())
                    {
                        var array     = new DynamicJsonArray();
                        var conflicts = context.DocumentDatabase.DocumentsStorage.ConflictsStorage.GetConflictsFor(context, docId);

                        foreach (var conflict in conflicts)
                        {
                            if (maxEtag < conflict.Etag)
                            {
                                maxEtag = conflict.Etag;
                            }

                            array.Add(new DynamicJsonValue
                            {
                                [nameof(GetConflictsResult.Conflict.ChangeVector)] = conflict.ChangeVector,
                                [nameof(GetConflictsResult.Conflict.Doc)]          = conflict.Doc,
                                [nameof(GetConflictsResult.Conflict.LastModified)] = conflict.LastModified
                            });
                        }

                        context.Write(writer, new DynamicJsonValue
                        {
                            [nameof(GetConflictsResult.Id)]          = docId,
                            [nameof(GetConflictsResult.LargestEtag)] = maxEtag,
                            [nameof(GetConflictsResult.Results)]     = array
                        });
                    }
        }
Example #11
0
        public override DynamicJsonValue ToJson(JsonOperationContext context)
        {
            var djv = base.ToJson(context);

            if (Commands != null)
            {
                var dja = new DynamicJsonArray();
                foreach (var command in Commands)
                {
                    dja.Add(command.ToJson(context));
                }
                djv[nameof(Commands)] = dja;
            }

            if (RemoveCommands != null)
            {
                var dja2 = new DynamicJsonArray();
                foreach (var command in RemoveCommands)
                {
                    dja2.Add(command.ToJson(context));
                }

                djv[nameof(RemoveCommands)] = dja2;
            }

            return(djv);
        }
Example #12
0
        public async Task GetReplicationIncomingActivityTimes()
        {
            using (ContextPool.AllocateOperationContext(out DocumentsOperationContext context))
                await using (var writer = new AsyncBlittableJsonTextWriter(context, ResponseBodyStream()))
                {
                    var data = new DynamicJsonArray();
                    foreach (var item in Database.ReplicationLoader.IncomingLastActivityTime)
                    {
                        data.Add(new DynamicJsonValue
                        {
                            ["Key"] = new DynamicJsonValue
                            {
                                ["SourceDatabaseId"]   = item.Key.SourceDatabaseId,
                                ["SourceDatabaseName"] = item.Key.SourceDatabaseName,
                                ["SourceMachineName"]  = item.Key.SourceMachineName,
                                ["SourceUrl"]          = item.Key.SourceUrl
                            },
                            ["Value"] = item.Value
                        });
                    }

                    context.Write(writer, new DynamicJsonValue
                    {
                        ["Stats"] = data
                    });
                }
        }
Example #13
0
        public async Task GetReplicationIncomingRejectionInfo()
        {
            using (ContextPool.AllocateOperationContext(out DocumentsOperationContext context))
                await using (var writer = new AsyncBlittableJsonTextWriter(context, ResponseBodyStream()))
                {
                    var stats = new DynamicJsonArray();
                    foreach (var statItem in Database.ReplicationLoader.IncomingRejectionStats)
                    {
                        stats.Add(new DynamicJsonValue
                        {
                            ["Key"] = new DynamicJsonValue
                            {
                                ["SourceDatabaseId"]   = statItem.Key.SourceDatabaseId,
                                ["SourceDatabaseName"] = statItem.Key.SourceDatabaseName,
                                ["SourceMachineName"]  = statItem.Key.SourceMachineName,
                                ["SourceUrl"]          = statItem.Key.SourceUrl
                            },
                            ["Value"] = new DynamicJsonArray(statItem.Value.Select(x => new DynamicJsonValue
                            {
                                ["Reason"] = x.Reason,
                                ["When"]   = x.When
                            }))
                        });
                    }

                    context.Write(writer, new DynamicJsonValue
                    {
                        ["Stats"] = stats
                    });
                }
        }
Example #14
0
        public async Task GetReplicationActiveConnections()
        {
            using (ContextPool.AllocateOperationContext(out DocumentsOperationContext context))
                await using (var writer = new AsyncBlittableJsonTextWriter(context, ResponseBodyStream()))
                {
                    var incoming = new DynamicJsonArray();
                    foreach (var item in Database.ReplicationLoader.IncomingConnections)
                    {
                        incoming.Add(new DynamicJsonValue
                        {
                            ["SourceDatabaseId"]   = item.SourceDatabaseId,
                            ["SourceDatabaseName"] = item.SourceDatabaseName,
                            ["SourceMachineName"]  = item.SourceMachineName,
                            ["SourceUrl"]          = item.SourceUrl
                        });
                    }

                    var outgoing = new DynamicJsonArray();
                    foreach (var item in Database.ReplicationLoader.OutgoingConnections)
                    {
                        outgoing.Add(new DynamicJsonValue
                        {
                            ["Url"]      = item.Url,
                            ["Database"] = item.Database,
                            ["Disabled"] = item.Disabled
                        });
                    }

                    context.Write(writer, new DynamicJsonValue
                    {
                        ["IncomingConnections"] = incoming,
                        ["OutgoingConnections"] = outgoing
                    });
                }
        }
Example #15
0
        public Task GetReplicationOutgoingFailureStats()
        {
            using (ContextPool.AllocateOperationContext(out DocumentsOperationContext context))
                using (var writer = new BlittableJsonTextWriter(context, ResponseBodyStream()))
                {
                    var data = new DynamicJsonArray();
                    foreach (var item in Database.ReplicationLoader.OutgoingFailureInfo)
                    {
                        data.Add(new DynamicJsonValue
                        {
                            ["Key"] = new DynamicJsonValue
                            {
                                ["Url"]      = item.Key.Url,
                                ["Database"] = item.Key.Database,
                                ["Disabled"] = item.Key.Disabled
                            },
                            ["Value"] = new DynamicJsonValue
                            {
                                ["ErrorCount"]  = item.Value.ErrorCount,
                                ["NextTimeout"] = item.Value.NextTimeout
                            }
                        });
                    }

                    context.Write(writer, new DynamicJsonValue
                    {
                        ["Stats"] = data
                    });
                }
            return(Task.CompletedTask);
        }
        public DynamicJsonValue ToJson()
        {
            var djv = new DynamicJsonValue();

            foreach (var key in Actions.Keys)
            {
                var queue = Actions[key];
                if (queue == null)
                {
                    continue;
                }

                var list = new DynamicJsonArray();
                foreach (var details in queue)
                {
                    list.Add(new DynamicJsonValue
                    {
                        [nameof(ActionDetails.NumberOfResults)] = details.NumberOfResults,
                        [nameof(ActionDetails.PageSize)]        = details.PageSize,
                        [nameof(ActionDetails.Occurrence)]      = details.Occurrence,
                        [nameof(ActionDetails.Duration)]        = details.Duration,
                        [nameof(ActionDetails.Details)]         = details.Details
                    });
                }

                djv[key] = list;
            }

            return(new DynamicJsonValue(GetType())
            {
                [nameof(Actions)] = djv
            });
        }
Example #17
0
            public static DynamicJsonValue ToJson(ServerStore serverStore, TransactionOperationContext context)
            {
                var djv = new DynamicJsonValue
                {
                    [$"@{nameof(General)}"] = General.ToJson()
                };

                var mapping = SnmpWatcher.GetMapping(serverStore, context);

                foreach (var kvp in mapping)
                {
                    var record = serverStore.LoadDatabaseRecord(kvp.Key, out _);
                    if (record == null)
                    {
                        continue;
                    }

                    var array = new DynamicJsonArray();
                    foreach (var field in typeof(Databases).GetFields())
                    {
                        var fieldValue = GetFieldValue(field);
                        var oid        = string.Format(fieldValue.Oid, kvp.Value);
                        array.Add(CreateJsonItem(Root + oid, fieldValue.Description));
                    }

                    djv[kvp.Key] = new DynamicJsonValue
                    {
                        [$"@{nameof(General)}"] = array,
                        [nameof(Indexes)]       = Indexes.ToJson(serverStore, context, record, kvp.Value)
                    };
                }

                return(djv);
            }
Example #18
0
                public static DynamicJsonValue ToJson(ServerStore serverStore, TransactionOperationContext context, DatabaseRecord record, long databaseIndex)
                {
                    var mapping = SnmpDatabase.GetIndexMapping(context, serverStore, record.DatabaseName);

                    var djv = new DynamicJsonValue();

                    if (mapping.Count == 0)
                    {
                        return(djv);
                    }

                    foreach (var indexName in record.Indexes.Keys)
                    {
                        if (mapping.TryGetValue(indexName, out var index) == false)
                        {
                            continue;
                        }

                        var array = new DynamicJsonArray();
                        foreach (var field in typeof(Indexes).GetFields())
                        {
                            var fieldValue  = GetFieldValue(field);
                            var databaseOid = string.Format(fieldValue.Oid, databaseIndex);
                            var indexOid    = string.Format(databaseOid, index);
                            array.Add(CreateJsonItem(Root + indexOid, fieldValue.Description));
                        }

                        djv[indexName] = array;
                    }

                    return(djv);
                }
Example #19
0
        private DynamicJsonValue ProcStatsInternal()
        {
            using (var proc = Process.GetCurrentProcess())
            {
                var dja = new DynamicJsonArray();
                var djv = new DynamicJsonValue();

                AddValue(djv, "Id", () => proc.Id);
                AddValue(djv, "Handle", () => proc.Handle.ToInt64());
                AddValue(djv, "BasePriority", () => proc.BasePriority);
                AddValue(djv, "StartTime", () => proc.StartTime);
                AddValue(djv, "MachineName", () => proc.MachineName);
                AddValue(djv, "MaxWorkingSet", () => proc.MaxWorkingSet.ToInt64());
                AddValue(djv, "MinWorkingSet", () => proc.MinWorkingSet.ToInt64());
                AddValue(djv, "NonpagedSystemMemorySize64", () => proc.NonpagedSystemMemorySize64);
                AddValue(djv, "PagedMemorySize64", () => proc.PagedMemorySize64);
                AddValue(djv, "PagedSystemMemorySize64", () => proc.PagedSystemMemorySize64);
                AddValue(djv, "PeakPagedMemorySize64", () => proc.PeakPagedMemorySize64);
                AddValue(djv, "PeakWorkingSet64", () => proc.PeakWorkingSet64);
                AddValue(djv, "PeakVirtualMemorySize64", () => proc.PeakVirtualMemorySize64);
                AddValue(djv, "PriorityBoostEnabled", () => proc.PriorityBoostEnabled);
                AddValue(djv, "PriorityClass", () => proc.PriorityClass);
                AddValue(djv, "PrivateMemorySize64", () => proc.PrivateMemorySize64);
                AddValue(djv, "ProcessName", () => proc.ProcessName);
                AddValue(djv, "ProcessorAffinity", () => proc.ProcessorAffinity.ToInt64());
                AddValue(djv, "SessionId", () => proc.SessionId);
                AddValue(djv, "StartInfo", () => proc.StartInfo);
                AddValue(djv, "HandleCount", () => proc.HandleCount);
                AddValue(djv, "VirtualMemorySize64", () => proc.VirtualMemorySize64);
                AddValue(djv, "EnableRaisingEvents", () => proc.EnableRaisingEvents);
                AddValue(djv, "StandardInput", () => proc.StandardInput);
                AddValue(djv, "StandardOutput", () => proc.StandardOutput);
                AddValue(djv, "StandardError", () => proc.StandardError);
                AddValue(djv, "WorkingSet64", () => proc.WorkingSet64);
                AddValue(djv, "Responding", () => proc.Responding);
                AddValue(djv, "MainWindowTitle", () => proc.MainWindowTitle);
                AddValue(djv, "MainWindowHandle", () => proc.MainWindowHandle.ToInt64());
                AddValue(djv, "SynchronizingObject", () => proc.SynchronizingObject);
                AddValue(djv, "MainModuleFileName", () => proc.MainModule.FileName);
                AddValue(djv, "MainModuleFileVersionInfoFileVersion", () => proc.MainModule.FileVersionInfo.FileVersion);
                AddValue(djv, "MainModuleModuleName", () => proc.MainModule.ModuleName);
                AddValue(djv, "MainModuleModuleMemorySize", () => proc.MainModule.ModuleMemorySize);
                AddValue(djv, "PrivilegedProcessorTime", () => proc.PrivilegedProcessorTime);
                AddValue(djv, "TotalProcessorTime", () => proc.TotalProcessorTime);
                AddValue(djv, "UserProcessorTime", () => proc.UserProcessorTime);
                AddValue(djv, "Site", () => proc.Site);
                AddValue(djv, "Container", () => proc.Container);

                djv["Threads"] = GetProcessThreadCollection(proc);
                djv["Modules"] = GetProcessModuleCollection(proc);

                dja.Add(djv);

                return(new DynamicJsonValue
                {
                    ["ProcStats"] = dja
                });
            }
        }
Example #20
0
        public async Task TotalTime()
        {
            var indexes = GetIndexesToReportOn();

            using (Database.DocumentsStorage.ContextPool.AllocateOperationContext(out DocumentsOperationContext context))
                await using (var writer = new AsyncBlittableJsonTextWriter(context, ResponseBodyStream()))
                {
                    var dja = new DynamicJsonArray();

                    foreach (var index in indexes)
                    {
                        DateTime baseLine = DateTime.MinValue;
                        using (context.OpenReadTransaction())
                        {
                            foreach (var collection in index.Collections)
                            {
                                switch (index.SourceType)
                                {
                                case IndexSourceType.Documents:
                                    var etag     = Database.DocumentsStorage.GetLastDocumentEtag(context.Transaction.InnerTransaction, collection);
                                    var document = Database.DocumentsStorage.GetDocumentsFrom(context, collection, etag, 0, 1, DocumentFields.Default).FirstOrDefault();
                                    if (document != null && document.LastModified > baseLine)
                                    {
                                        baseLine = document.LastModified;
                                    }
                                    break;

                                case IndexSourceType.Counters:
                                case IndexSourceType.TimeSeries:
                                    break;

                                default:
                                    throw new NotSupportedException($"Index with source type '{index.SourceType}' is not supported.");
                                }
                            }
                        }
                        var createdTimestamp = index.GetStats().CreatedTimestamp;
                        if (createdTimestamp > baseLine)
                        {
                            baseLine = createdTimestamp;
                        }

                        var lastBatch = index.GetIndexingPerformance()
                                        .LastOrDefault(x => x.Completed != null)
                                        ?.Completed ?? DateTime.UtcNow;

                        dja.Add(new DynamicJsonValue
                        {
                            ["Name"] = index.Name,
                            ["TotalIndexingTime"] = index.TimeSpentIndexing.Elapsed.ToString("c"),
                            ["LagTime"]           = (lastBatch - baseLine).ToString("c")
                        });
                    }

                    context.Write(writer, dja);
                }
        }
Example #21
0
        private static DynamicJsonArray EnumerableToJsonArray(IEnumerable propertyEnumerable, object root, bool flattenArrays, int recursiveLevel, Engine engine, JsonOperationContext context)
        {
            var dja = new DynamicJsonArray();

            foreach (var x in propertyEnumerable)
            {
                dja.Add(ToBlittableSupportedType(root, x, flattenArrays, recursiveLevel + 1, engine, context));
            }

            return(dja);
        }
Example #22
0
            protected void AddPutResult(DocumentsStorage.PutOperationResults putResult)
            {
                LastChangeVector = putResult.ChangeVector;
                ModifiedCollections?.Add(putResult.Collection.Name);

                // Make sure all the metadata fields are always been add
                var putReply = new DynamicJsonValue
                {
                    ["Type"] = nameof(CommandType.PUT),
                    [Constants.Documents.Metadata.Id]           = putResult.Id,
                    [Constants.Documents.Metadata.Collection]   = putResult.Collection.Name,
                    [Constants.Documents.Metadata.ChangeVector] = putResult.ChangeVector,
                    [Constants.Documents.Metadata.LastModified] = putResult.LastModified
                };

                if (putResult.Flags != DocumentFlags.None)
                {
                    putReply[Constants.Documents.Metadata.Flags] = putResult.Flags;
                }

                Reply.Add(putReply);
            }
Example #23
0
                public static DynamicJsonArray ToJson()
                {
                    var array = new DynamicJsonArray();

                    foreach (var field in typeof(General).GetFields())
                    {
                        var fieldValue = GetFieldValue(field);

                        array.Add(CreateJsonItem(Root + fieldValue.Oid, fieldValue.Description));
                    }

                    return(array);
                }
Example #24
0
        public Task TotalTime()
        {
            var indexes = GetIndexesToReportOn();
            DocumentsOperationContext context;

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

                    foreach (var index in indexes)
                    {
                        DateTime baseLine = DateTime.MinValue;
                        using (context.OpenReadTransaction())
                        {
                            foreach (var collection in index.Collections)
                            {
                                var etag     = Database.DocumentsStorage.GetLastDocumentEtag(context, collection);
                                var document = Database.DocumentsStorage.GetDocumentsFrom(context, collection, etag, 0, 1).FirstOrDefault();
                                if (document != null)
                                {
                                    if (document.LastModified > baseLine)
                                    {
                                        baseLine = document.LastModified;
                                    }
                                }
                            }
                        }
                        var createdTimestamp = index.GetStats().CreatedTimestamp;
                        if (createdTimestamp > baseLine)
                        {
                            baseLine = createdTimestamp;
                        }

                        var lastBatch = index.GetIndexingPerformance(0)
                                        .LastOrDefault(x => x.Completed != null)
                                        ?.Completed ?? DateTime.UtcNow;


                        dja.Add(new DynamicJsonValue
                        {
                            ["Name"] = index.Name,
                            ["TotalIndexingTime"] = index.TimeSpentIndexing.Elapsed.ToString("c"),
                            ["LagTime"]           = (lastBatch - baseLine).ToString("c")
                        });
                    }

                    context.Write(writer, dja);
                }
            return(Task.CompletedTask);
        }
Example #25
0
        public static DynamicJsonValue LowMemLogInternal()
        {
            var lowMemLog = LowMemoryNotification.Instance.LowMemEventDetailsStack;
            var dja       = new DynamicJsonArray();

            foreach (var item in lowMemLog.OrderByDescending(x =>
            {
                if (x != null)
                {
                    return(x.Time);
                }
                return(DateTime.MinValue);
            }))
            {
                if (item == null || item.Reason == LowMemoryNotification.LowMemReason.None)
                {
                    continue;
                }

                var humanSizes = new DynamicJsonValue
                {
                    ["FreeMem"]             = Size.Humane(item.FreeMem),
                    ["CurrentCommitCharge"] = Size.Humane(item.CurrentCommitCharge),
                    ["TotalUnmanaged"]      = Size.Humane(item.TotalUnmanaged),
                    ["TotalScratchDirty"]   = Size.Humane(item.TotalScratchDirty),
                    ["PhysicalMem"]         = Size.Humane(item.PhysicalMem),
                    ["Threshold"]           = Size.Humane(item.LowMemThreshold)
                };

                var json = new DynamicJsonValue
                {
                    ["Event"]               = item.Reason,
                    ["FreeMem"]             = item.FreeMem,
                    ["CurrentCommitCharge"] = item.CurrentCommitCharge,
                    ["TotalUnmanaged"]      = item.TotalUnmanaged,
                    ["TotalScratchDirty"]   = item.TotalScratchDirty,
                    ["PhysicalMem"]         = item.PhysicalMem,
                    ["TimeOfEvent"]         = item.Time,
                    ["HumanlyReadSizes"]    = humanSizes
                };

                dja.Add(json);
            }

            var djv = new DynamicJsonValue
            {
                ["Low Memory Events"] = dja
            };

            return(djv);
        }
Example #26
0
            public static DynamicJsonArray ToJson()
            {
                var array = new DynamicJsonArray();

                foreach (var field in typeof(Server).GetFields())
                {
                    var fieldValue = GetFieldValue(field);
                    var fullOid    = field.Name == nameof(UpTimeGlobal) ? fieldValue.Oid : Root + fieldValue.Oid;

                    array.Add(CreateJsonItem(fullOid, fieldValue.Description));
                }

                return(array);
            }
Example #27
0
        private async Task HandleClusterTransaction(DocumentsOperationContext context, MergedBatchCommand command, ClusterTransactionCommand.ClusterTransactionOptions options)
        {
            var clusterTransactionCommand = new ClusterTransactionCommand(Database.Name, command.ParsedCommands, options);
            var result = await ServerStore.SendToLeaderAsync(clusterTransactionCommand);

            if (result.Result is List <string> errors)
            {
                HttpContext.Response.StatusCode = (int)HttpStatusCode.Conflict;
                throw new ConcurrencyException($"Failed to execute cluster transaction due to the following issues: {string.Join(Environment.NewLine, errors)}");
            }

            var array = new DynamicJsonArray();

            if (clusterTransactionCommand.DatabaseCommandsCount > 0)
            {
                var reply = (ClusterTransactionCompletionResult)await Database.ClusterTransactionWaiter.WaitForResults(options.TaskId, HttpContext.RequestAborted);

                if (reply.IndexTask != null)
                {
                    await reply.IndexTask;
                }

                array = reply.Array;
            }
            else
            {
                // wait for the command to be applied on this node (batch of cmpxchng ops only)
                await ServerStore.WaitForCommitIndexChange(RachisConsensus.CommitIndexModification.GreaterOrEqual, result.Index);
            }

            foreach (var clusterCommands in clusterTransactionCommand.ClusterCommands)
            {
                array.Add(new DynamicJsonValue
                {
                    ["Type"]  = clusterCommands.Type,
                    ["Key"]   = clusterCommands.Id,
                    ["Index"] = result.Index
                });
            }

            HttpContext.Response.StatusCode = (int)HttpStatusCode.Created;
            using (var writer = new BlittableJsonTextWriter(context, ResponseBodyStream()))
            {
                context.Write(writer, new DynamicJsonValue
                {
                    [nameof(BatchCommandResult.Results)]          = array,
                    [nameof(BatchCommandResult.TransactionIndex)] = result.Index
                });
            }
        }
Example #28
0
        public static DynamicJsonArray ToJson(this ChangeVectorEntry[] self)
        {
            var results = new DynamicJsonArray();

            foreach (var entry in self)
            {
                results.Add(new DynamicJsonValue
                {
                    ["DbId"] = entry.DbId.ToString(),
                    ["Etag"] = entry.Etag
                });
            }
            return(results);
        }
Example #29
0
        public DynamicJsonValue ToJson()
        {
            var result = new DynamicJsonValue();

            var statements = new DynamicJsonArray();

            foreach (var details in Statements)
            {
                statements.Add(details.ToJson());
            }

            result[nameof(Statements)] = statements;

            return(result);
        }
Example #30
0
        public DynamicJsonValue ToJson()
        {
            var result = new DynamicJsonValue();

            var errors = new DynamicJsonArray();

            foreach (var details in Errors)
            {
                errors.Add(details.ToJson());
            }

            result[nameof(Errors)] = errors;

            return(result);
        }