public DocumentDatabase(string name, RavenConfiguration configuration, ServerStore serverStore) { StartTime = SystemTime.UtcNow; Name = name; ResourceName = "db/" + name; Configuration = configuration; _logger = LoggingSource.Instance.GetLogger <DocumentDatabase>(Name); Notifications = new DocumentsNotifications(); DocumentsStorage = new DocumentsStorage(this); IndexStore = new IndexStore(this); TransformerStore = new TransformerStore(this); SqlReplicationLoader = new SqlReplicationLoader(this); DocumentReplicationLoader = new DocumentReplicationLoader(this); DocumentTombstoneCleaner = new DocumentTombstoneCleaner(this); SubscriptionStorage = new SubscriptionStorage(this); Operations = new DatabaseOperations(this); Metrics = new MetricsCountersManager(); IoMetrics = serverStore?.IoMetrics ?? new IoMetrics(256, 256); Patch = new PatchDocument(this); TxMerger = new TransactionOperationsMerger(this, DatabaseShutdown); HugeDocuments = new HugeDocuments(configuration.Databases.MaxCollectionSizeHugeDocuments, configuration.Databases.MaxWarnSizeHugeDocuments); ConfigurationStorage = new ConfigurationStorage(this, serverStore); DatabaseInfoCache = serverStore?.DatabaseInfoCache; }
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; } }