示例#1
0
        public DocumentDatabase(string name, RavenConfiguration configuration, ServerStore serverStore)
        {
            Scripts       = new ScriptRunnerCache(this);
            _logger       = LoggingSource.Instance.GetLogger <DocumentDatabase>(Name);
            _serverStore  = serverStore;
            StartTime     = SystemTime.UtcNow;
            Name          = name;
            Configuration = configuration;

            try
            {
                using (_serverStore.ContextPool.AllocateOperationContext(out TransactionOperationContext ctx))
                    using (ctx.OpenReadTransaction())
                    {
                        MasterKey = serverStore.GetSecretKey(ctx, Name);

                        var databaseRecord = _serverStore.Cluster.ReadDatabase(ctx, Name);
                        if (databaseRecord != null)
                        {
                            // can happen when we are in the process of restoring a database
                            if (databaseRecord.Encrypted && MasterKey == null)
                            {
                                throw new InvalidOperationException($"Attempt to create encrypted db {Name} without supplying the secret key");
                            }
                            if (databaseRecord.Encrypted == false && MasterKey != null)
                            {
                                throw new InvalidOperationException($"Attempt to create a non-encrypted db {Name}, but a secret key exists for this db.");
                            }
                        }
                    }

                QueryMetadataCache       = new QueryMetadataCache();
                IoChanges                = new IoChangesNotifications();
                Changes                  = new DocumentsChanges();
                DocumentTombstoneCleaner = new DocumentTombstoneCleaner(this);
                DocumentsStorage         = new DocumentsStorage(this);
                IndexStore               = new IndexStore(this, serverStore, _indexAndTransformerLocker);
                EtlLoader                = new EtlLoader(this, serverStore);
                ReplicationLoader        = new ReplicationLoader(this, serverStore);
                SubscriptionStorage      = new SubscriptionStorage(this, serverStore);
                Metrics                  = new MetricsCountersManager();
                TxMerger                 = new TransactionOperationsMerger(this, DatabaseShutdown);
                HugeDocuments            = new HugeDocuments(configuration.PerformanceHints.HugeDocumentsCollectionSize,
                                                             configuration.PerformanceHints.HugeDocumentSize.GetValue(SizeUnit.Bytes));
                ConfigurationStorage            = new ConfigurationStorage(this);
                NotificationCenter              = new NotificationCenter.NotificationCenter(ConfigurationStorage.NotificationsStorage, Name, _databaseShutdown.Token);
                Operations                      = new Operations.Operations(Name, ConfigurationStorage.OperationsStorage, NotificationCenter, Changes);
                DatabaseInfoCache               = serverStore.DatabaseInfoCache;
                RachisLogIndexNotifications     = new RachisLogIndexNotifications(DatabaseShutdown);
                CatastrophicFailureNotification = new CatastrophicFailureNotification(e =>
                {
                    serverStore.DatabasesLandlord.UnloadResourceOnCatastrophicFailure(name, e);
                });
            }
            catch (Exception)
            {
                Dispose();
                throw;
            }
        }
示例#2
0
        public void Should_cache_metadata_of_queries_without_parameters()
        {
            var cache = new QueryMetadataCache();

            Assert.False(cache.TryGetMetadata(new IndexQueryServerSide("from Users order by Name"), addSpatialProperties: false, out var metadataHash, out var metadata));

            Assert.NotEqual((ulong)0, metadataHash);

            cache.MaybeAddToCache(new QueryMetadata("from Users order by Name", null, metadataHash), "test");

            Assert.True(cache.TryGetMetadata(new IndexQueryServerSide("from Users order by Name"), addSpatialProperties: false, out metadataHash, out metadata));
        }
示例#3
0
        public void Should_not_cache_query_metadata_if_addSpatialProperties_is_set_to_true()
        {
            var cache = new QueryMetadataCache();

            Assert.False(cache.TryGetMetadata(new IndexQueryServerSide("from Users order by Name"), addSpatialProperties: false, out var originalMetadataHash, out _));

            Assert.NotEqual((ulong)0, originalMetadataHash);

            cache.MaybeAddToCache(new QueryMetadata("from Users order by Name", null, cacheKey: originalMetadataHash, addSpatialProperties: true), "test");

            Assert.False(cache.TryGetMetadata(new IndexQueryServerSide("from Users order by Name"), addSpatialProperties: false, out var metadataHash, out _));

            Assert.False(cache.TryGetMetadata(new IndexQueryServerSide("from Users order by Name"), addSpatialProperties: true, out metadataHash, out _));

            cache.MaybeAddToCache(new QueryMetadata("from Users order by Name", null, cacheKey: originalMetadataHash, addSpatialProperties: false), "test");

            Assert.True(cache.TryGetMetadata(new IndexQueryServerSide("from Users order by Name"), addSpatialProperties: false, out metadataHash, out _));

            Assert.False(cache.TryGetMetadata(new IndexQueryServerSide("from Users order by Name"), addSpatialProperties: true, out metadataHash, out _));
        }
示例#4
0
        public static unsafe (FacetQueryServerSide FacetQuery, long?FacetsEtag) Create(BlittableJsonReaderObject json, JsonOperationContext context, QueryMetadataCache cache)
        {
            var result = JsonDeserializationServer.FacetQuery(json);

            if (result.PageSize == 0 && json.TryGet(nameof(PageSize), out int _) == false)
            {
                result.PageSize = int.MaxValue;
            }

            if (string.IsNullOrWhiteSpace(result.Query))
            {
                throw new InvalidOperationException($"Facet query does not contain '{nameof(Query)}' field.");
            }

            long?facetsEtag = null;

            if (json.TryGet(nameof(Facets), out BlittableJsonReaderArray facetsArray) && facetsArray != null)
            {
                facetsEtag = Hashing.XXHash32.Calculate(facetsArray.Parent.BasePointer, facetsArray.Parent.Size);
            }

            result.Metadata = cache.TryGetMetadata(result, context, out var metadataHash, out var metadata)
                ? metadata
                : new QueryMetadata(result.Query, result.QueryParameters, metadataHash);
            return(result, facetsEtag);
        }