Exemple #1
0
        private PerformanceHint GetOrCreatePerformanceHint(out HugeDocumentsDetails details)
        {
            //Read() is transactional, so this is thread-safe
            using (_notificationsStorage.Read(HugeDocumentsId, out var ntv))
            {
                if (ntv == null || ntv.Json.TryGet(nameof(PerformanceHint.Details), out BlittableJsonReaderObject detailsJson) == false || detailsJson == null)
                {
                    details = new HugeDocumentsDetails();
                }
                else
                {
                    details = DocumentConventions.DefaultForServer.Serialization.DefaultConverter.FromBlittable <HugeDocumentsDetails>(detailsJson, HugeDocumentsId);
                }

                string message = $"We have detected that some documents has surpassed the configured size threshold ({new Size(_maxWarnSize, SizeUnit.Bytes)}). It might have performance impact. You can alter warning limits by changing '{RavenConfiguration.GetKey(x => x.PerformanceHints.HugeDocumentSize)}' configuration value.";

                return(PerformanceHint.Create(
                           _database,
                           "Huge documents",
                           message,
                           PerformanceHintType.HugeDocuments,
                           NotificationSeverity.Warning,
                           PerformanceHintSource,
                           details
                           ));
            }
        }
Exemple #2
0
        public async Task Huge_document_hints_are_stored_and_can_be_read()
        {
            using (var store = GetDocumentStore())
            {
                var database = await GetDatabase(store.Database);

                // this tests write to storage
                database.HugeDocuments.AddIfDocIsHuge("orders/1-A", 10 * 1024 * 1024);

                // this tests merge with existing item
                database.HugeDocuments.AddIfDocIsHuge("orders/2-A", 20 * 1024 * 1024);
                database.HugeDocuments.AddIfDocIsHuge("orders/3-A", 30 * 1024 * 1024);
                database.HugeDocuments.AddIfDocIsHuge("orders/4-A", 40 * 1024 * 1024);

                database.HugeDocuments.UpdateHugeDocuments(null);

                Assert.True(database.ConfigurationStorage.NotificationsStorage.GetPerformanceHintCount() > 0);

                // now read directly from storage and verify
                using (database.ConfigurationStorage.NotificationsStorage.Read(HugeDocuments.HugeDocumentsId, out var ntv))
                {
                    if (ntv == null || ntv.Json.TryGet(nameof(PerformanceHint.Details), out BlittableJsonReaderObject detailsJson) == false || detailsJson == null)
                    {
                        Assert.False(true, "Unable to read stored notification");
                    }
                    else
                    {
                        HugeDocumentsDetails details = (HugeDocumentsDetails)EntityToBlittable.ConvertToEntity(
                            typeof(HugeDocumentsDetails),
                            HugeDocuments.HugeDocumentsId,
                            detailsJson,
                            DocumentConventions.Default);

                        Assert.NotNull(details);
                        Assert.Equal(4, details.HugeDocuments.Count);

                        var ids = details.HugeDocuments.Values.Select(x => x.Id).ToList();
                        Assert.Contains("orders/1-A", ids);
                        Assert.Contains("orders/2-A", ids);
                        Assert.Contains("orders/3-A", ids);
                        Assert.Contains("orders/4-A", ids);
                    }
                }
            }
        }