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; }
private void InitializeInternal() { TxMerger.Start(); _indexStoreTask = IndexStore.InitializeAsync(); _transformerStoreTask = TransformerStore.InitializeAsync(); SqlReplicationLoader.Initialize(); DocumentTombstoneCleaner.Initialize(); BundleLoader = new BundleLoader(this); try { _indexStoreTask.Wait(DatabaseShutdown); } finally { _indexStoreTask = null; } try { _transformerStoreTask.Wait(DatabaseShutdown); } finally { _transformerStoreTask = null; } SubscriptionStorage.Initialize(); //Index Metadata Store shares Voron env and context pool with documents storage, //so replication of both documents and indexes/transformers can be made within one transaction ConfigurationStorage.Initialize(IndexStore, TransformerStore); DocumentReplicationLoader.Initialize(); }
public void Dispose() { //before we dispose of the database we take its latest info to be displayed in the studio var databaseInfo = GenerateDatabaseInfo(); DatabaseInfoCache?.InsertDatabaseInfo(databaseInfo, Name); _databaseShutdown.Cancel(); // we'll wait for 1 minute to drain all the requests // from the database for (int i = 0; i < 60; i++) { if (Interlocked.Read(ref _usages) == 0) { break; } _waitForUsagesOnDisposal.Wait(100); } var exceptionAggregator = new ExceptionAggregator(_logger, $"Could not dispose {nameof(DocumentDatabase)}"); foreach (var connection in RunningTcpConnections) { exceptionAggregator.Execute(() => { connection.Dispose(); }); } exceptionAggregator.Execute(() => { TxMerger.Dispose(); }); exceptionAggregator.Execute(() => { DocumentReplicationLoader.Dispose(); }); if (_indexStoreTask != null) { exceptionAggregator.Execute(() => { _indexStoreTask.Wait(DatabaseShutdown); _indexStoreTask = null; }); } if (_transformerStoreTask != null) { exceptionAggregator.Execute(() => { _transformerStoreTask.Wait(DatabaseShutdown); _transformerStoreTask = null; }); } exceptionAggregator.Execute(() => { IndexStore?.Dispose(); IndexStore = null; }); exceptionAggregator.Execute(() => { BundleLoader?.Dispose(); BundleLoader = null; }); exceptionAggregator.Execute(() => { DocumentTombstoneCleaner?.Dispose(); DocumentTombstoneCleaner = null; }); exceptionAggregator.Execute(() => { DocumentReplicationLoader?.Dispose(); DocumentReplicationLoader = null; }); exceptionAggregator.Execute(() => { SqlReplicationLoader?.Dispose(); SqlReplicationLoader = null; }); exceptionAggregator.Execute(() => { Operations?.Dispose(exceptionAggregator); Operations = null; }); exceptionAggregator.Execute(() => { SubscriptionStorage?.Dispose(); }); exceptionAggregator.Execute(() => { ConfigurationStorage?.Dispose(); }); exceptionAggregator.Execute(() => { DocumentsStorage?.Dispose(); DocumentsStorage = null; }); exceptionAggregator.ThrowIfNeeded(); }