protected override void Dispose() { var exceptionAggregator = new ExceptionAggregator(Log, "Could not dispose of IndexingExecuter"); exceptionAggregator.Execute(prefetchingBehavior.Dispose); exceptionAggregator.ThrowIfNeeded(); }
protected override void Dispose(ExceptionAggregator exceptionAggregator) { foreach (var store in CreatedStores) { exceptionAggregator.Execute(store.Dispose); } CreatedStores.Clear(); }
protected override void Dispose(ExceptionAggregator exceptionAggregator) { if (_databases.Count == 0) { return; } using (Server.ServerStore.ContextPool.AllocateOperationContext(out TransactionOperationContext context)) { foreach (var database in _databases) { exceptionAggregator.Execute(() => { try { Server.ServerStore.DatabasesLandlord.UnloadDirectly(database); } catch (DatabaseDisabledException) { } catch (AggregateException ae) when(ae.InnerException is DatabaseDisabledException) { } }); exceptionAggregator.Execute(() => { AsyncHelpers.RunSync(async() => { try { var(index, _) = await Server.ServerStore.DeleteDatabaseAsync(database, hardDelete: true, fromNodes: new[] { Server.ServerStore.NodeTag }, Guid.NewGuid().ToString()); await Server.ServerStore.Cluster.WaitForIndexNotification(index); } catch (DatabaseDoesNotExistException) { } catch (Exception e) when(e.InnerException is DatabaseDoesNotExistException) { } }); }); } } }
public void Dispose() { var exceptionAggregator = new ExceptionAggregator(Logger, "Failure to dispose landlord"); exceptionAggregator.Execute(() => { foreach (var databaseTransportState in ResourseTransportStates) { databaseTransportState.Value.Dispose(); } }); using (ResourcesStoresCache.WithAllLocks()) { // shut down all databases in parallel, avoid having to wait for each one Parallel.ForEach(ResourcesStoresCache.Values, dbTask => { if (dbTask.IsCompleted == false) { dbTask.ContinueWith(task => { if (task.Status != TaskStatus.RanToCompletion) { return; } try { task.Result.Dispose(); } catch (Exception e) { Logger.WarnException("Failure in deferred disposal of a database", e); } }); } else if (dbTask.Status == TaskStatus.RanToCompletion) { exceptionAggregator.Execute(dbTask.Result.Dispose); } // there is no else, the db is probably faulted }); ResourcesStoresCache.Clear(); } }
public void Dispose() { _database.Notifications.OnSystemDocumentChange -= HandleSystemDocumentChange; var exceptionAggregator = new ExceptionAggregator(_logger, $"Could not dispose {nameof(BundleLoader)}"); exceptionAggregator.Execute(() => { ExpiredDocumentsCleaner?.Dispose(); ExpiredDocumentsCleaner = null; }); exceptionAggregator.Execute(() => { PeriodicExportRunner?.Dispose(); PeriodicExportRunner = null; }); exceptionAggregator.ThrowIfNeeded(); }
public void Close() { var exceptionAggregator = new ExceptionAggregator(log, "Failed to close response"); exceptionAggregator.Execute(OutputStream.Flush); exceptionAggregator.Execute(OutputStream.Dispose); if (StreamsToDispose != null) { foreach (var stream in StreamsToDispose) { exceptionAggregator.Execute(stream.Flush); exceptionAggregator.Execute(stream.Dispose); } } exceptionAggregator.Execute(response.Close); exceptionAggregator.ThrowIfNeeded(); }
public void Dispose() { var exceptionAggregator = new ExceptionAggregator(log, "Could not properly close index storage"); exceptionAggregator.Execute(() => Parallel.ForEach(indexes.Values, index => exceptionAggregator.Execute(index.Dispose))); exceptionAggregator.Execute(() => dummyAnalyzer.Close()); exceptionAggregator.Execute(() => { if (crashMarker != null) { crashMarker.Dispose(); } }); exceptionAggregator.ThrowIfNeeded(); }
/// <exception cref="ValidationException"></exception> /// <inheritdoc/> protected override void ValidateState() { using (var ea = new ExceptionAggregator()) { ea.Execute(base.ValidateState); base.ValidateState(); var tableColumns = Parent.Columns; var columns = Columns.Select(keyRef => keyRef.Value).ToList(); if (columns.Count == 0) { ea.Execute(() => { throw new ValidationException(Strings.ExEmptyColumnsCollection, Path); }); } ea.Complete(); } }
public virtual void Dispose() { _database.Changes.OnDocumentChange -= NotifyAboutWork; var ea = new ExceptionAggregator(Logger, "Could not dispose ETL loader"); Parallel.ForEach(_processes, x => ea.Execute(x.Dispose)); ea.ThrowIfNeeded(); }
/// <inheritdoc/> public void Validate() { using (var ea = new ExceptionAggregator()) { foreach (var node in list) { ea.Execute(x => x.Validate(), node); } ea.Complete(); } }
public static void DeletePaths(ConcurrentSet <string> pathsToDelete, ExceptionAggregator exceptionAggregator) { var localPathsToDelete = pathsToDelete.ToArray(); foreach (var pathToDelete in localPathsToDelete) { pathsToDelete.TryRemove(pathToDelete); exceptionAggregator.Execute(() => ClearDatabaseDirectory(pathToDelete)); } }
public void ProcessFinalizers() { using (var ea = new ExceptionAggregator()) { // Backward order for (int i = finalizers.Count - 1; i >= 0; i--) { ea.Execute(finalizers[i]); } ea.Complete(); } }
public void Dispose() { var exceptionAggregator = new ExceptionAggregator(Log, string.Format("Could not properly close index storage for file system '{0}'", name)); exceptionAggregator.Execute(() => { if (analyzer != null) { analyzer.Close(); } }); exceptionAggregator.Execute(() => { if (currentIndexSearcherHolder != null) { currentIndexSearcherHolder.SetIndexSearcher(null); } }); exceptionAggregator.Execute(() => SafeDispose(crashMarker)); exceptionAggregator.Execute(() => SafeDispose(writer)); exceptionAggregator.Execute(() => SafeDispose(directory)); exceptionAggregator.ThrowIfNeeded(); }
public void Dispose() { disposerLock.EnterWriteLock(); try { if (disposed) { return; } var exceptionAggregator = new ExceptionAggregator(log, "Could not close database properly"); disposed = true; exceptionAggregator.Execute(current.Dispose); if (documentCacher != null) { exceptionAggregator.Execute(documentCacher.Dispose); } if (inFlightTransactionalState != null) { exceptionAggregator.Execute(inFlightTransactionalState.Dispose); } exceptionAggregator.Execute(() => { Api.JetTerm2(instance, TermGrbit.Complete); GC.SuppressFinalize(this); }); exceptionAggregator.ThrowIfNeeded(); } catch (Exception e) { log.FatalException("Could not dispose of the transactional storage for " + path, e); throw; } finally { disposerLock.ExitWriteLock(); } }
public virtual void Dispose() { _disposed = true; _cancellationTokenSource.Cancel(); var exceptionAggregator = new ExceptionAggregator(_logger, $"Could not dispose {nameof(SqlReplication)} '{ReplicationUniqueName}'"); exceptionAggregator.Execute(() => _replicationThread?.Join()); exceptionAggregator.ThrowIfNeeded(); }
public void Dispose() { GC.SuppressFinalize(this); var exceptionAggregator = new ExceptionAggregator(Log, $"Could not properly close index storage for file system '{name}'"); exceptionAggregator.Execute(() => { if (analyzer != null) { analyzer.Close(); } }); exceptionAggregator.Execute(() => { if (currentIndexSearcherHolder != null) { currentIndexSearcherHolder.SetIndexSearcher(null); } }); exceptionAggregator.Execute(() => SafeDispose(crashMarker)); exceptionAggregator.Execute(() => SafeDispose(writer)); exceptionAggregator.Execute(() => SafeDispose(directory)); exceptionAggregator.ThrowIfNeeded(); }
/// <inheritdoc/> /// <exception cref="ValidationException">Validation error.</exception> protected override void ValidateState() { using (var ea = new ExceptionAggregator()) { ea.Execute(base.ValidateState); base.ValidateState(); var tableColumns = Parent.Columns; var keys = KeyColumns.Select(keyRef => keyRef.Value).ToList(); var values = ValueColumns.Select(valueRef => valueRef.Value).ToList(); var all = keys.Concat(values).ToList(); if (keys.Count == 0) { ea.Execute(() => { throw new ValidationException(Strings.ExEmptyKeyColumnsCollection, Path); }); } if (keys.Where(ci => ci.Type.IsNullable).Count() > 0) { ea.Execute(() => { throw new ValidationException(Strings.ExPrimaryKeyColumnCanNotBeNullable, Path); }); } if (all.Count != tableColumns.Count) { ea.Execute(() => { throw new ValidationException(Strings.ExInvalidPrimaryKeyStructure, Path); }); } if (all.Zip(tableColumns).Where(p => p.First != p.Second).Any()) { ea.Execute(() => { throw new ValidationException(Strings.ExInvalidPrimaryKeyStructure, Path); }); } ea.Complete(); } }
public void Dispose() { disposerLock.EnterWriteLock(); try { if (disposed) { return; } disposed = true; var exceptionAggregator = new ExceptionAggregator("Could not properly dispose TransactionalStorage"); exceptionAggregator.Execute(() => current.Dispose()); exceptionAggregator.Execute(() => disableBatchNesting.Dispose()); if (documentCacher != null) { exceptionAggregator.Execute(documentCacher.Dispose); } if (tableStorage != null) { exceptionAggregator.Execute(() => tableStorage.Dispose()); } if (bufferPool != null) { exceptionAggregator.Execute(() => bufferPool.Dispose()); } exceptionAggregator.ThrowIfNeeded(); } finally { disposerLock.ExitWriteLock(); } }
protected override void Dispose(ExceptionAggregator exceptionAggregator) { foreach (var serverProcess in _testInstanceServerProcesses) { exceptionAggregator.Execute(() => { if (serverProcess.HasExited == false) { serverProcess.Kill(); } }); } }
protected override void Dispose() { var exceptionAggregator = new ExceptionAggregator(Log, "Could not dispose of IndexingExecuter"); foreach (var pendingTask in pendingTasks) { exceptionAggregator.Execute(pendingTask.Wait); } pendingTasks.Clear(); if (indexingCompletedEvent != null) { exceptionAggregator.Execute(indexingCompletedEvent.Dispose); } if (indexingSemaphore != null) { exceptionAggregator.Execute(indexingSemaphore.Dispose); } exceptionAggregator.ThrowIfNeeded(); indexingCompletedEvent = null; indexingSemaphore = null; }
public void Dispose() { var aggregator = new ExceptionAggregator("ClusterManager disposal error."); aggregator.Execute(() => { if (Client != null) { Client.Dispose(); } }); aggregator.Execute(() => { if (Engine != null) { Engine.Dispose(); } }); aggregator.ThrowIfNeeded(); }
/// <inheritdoc/> /// <exception cref="ValidationException">Validations errors.</exception> protected override void ValidateState() { using (var ea = new ExceptionAggregator()) { ea.Execute(base.ValidateState); if (PrimaryKey == null) { ea.Execute(() => { throw new ValidationException(Strings.ExUndefinedPrimaryKey, Path); }); ea.Complete(); return; } var pkColumns = PrimaryKey.KeyColumns; var fkColumns = ForeignKeyColumns; if (pkColumns.Count != pkColumns .Zip(fkColumns, (pkColumn, fkColumn) => new Pair <KeyColumnRef, ForeignKeyColumnRef>(pkColumn, fkColumn)) .Count(p => CompareKeyColumns(p.First, p.Second))) { ea.Execute(() => { throw new ValidationException( Strings.ExInvalidForeignKeyStructure, Path); }); } // var pkTypes = PrimaryKey.KeyColumns.Select(c => c.Value.Type); // var fkTypes = ForeignKeyColumns.Select(c => c.Value.Type); // if (pkTypes.Count()!=pkTypes.Zip(fkTypes).Where(p => p.First==p.Second).Count()) // ea.Execute(() => { // throw new ValidationException( // Strings.ExInvalidForeignKeyStructure, Path); // }); ea.Complete(); } }
/// <inheritdoc/> /// <exception cref="ValidationException"><c>ValidationException</c>.</exception> protected override void ValidateState() { using (var ea = new ExceptionAggregator()) { ea.Execute(base.ValidateState); if (Increment <= 0) { ea.Execute(() => { throw new ValidationException( string.Format(Strings.ExInvalideIncrementValue), Path); }); } if (Type == null) { ea.Execute(() => { throw new ValidationException( string.Format(string.Format(Strings.ExUndefinedTypeOfSequenceX, Name)), Path); }); } ea.Complete(); } }
public void Dispose() { if (disposed) { return; } // give it 3 seconds to complete requests for (int i = 0; i < 30 && Interlocked.Read(ref metricsCounters.ConcurrentRequestsCount) > 0; i++) { Thread.Sleep(100); } AppDomain.CurrentDomain.ProcessExit -= ShouldDispose; AppDomain.CurrentDomain.DomainUnload -= ShouldDispose; disposed = true; var exceptionAggregator = new ExceptionAggregator(Log, "Could not properly dispose RavenFileSystem"); if (synchronizationTask != null) { exceptionAggregator.Execute(synchronizationTask.Dispose); } if (storage != null) { exceptionAggregator.Execute(storage.Dispose); } if (search != null) { exceptionAggregator.Execute(search.Dispose); } if (sigGenerator != null) { exceptionAggregator.Execute(sigGenerator.Dispose); } if (BufferPool != null) { exceptionAggregator.Execute(BufferPool.Dispose); } if (metricsCounters != null) { exceptionAggregator.Execute(metricsCounters.Dispose); } if (Tasks != null) { Tasks.Dispose(exceptionAggregator); } exceptionAggregator.ThrowIfNeeded(); }
public IStorageActionsAccessor CreateAccessor() { var snapshotReference = new Reference <SnapshotReader> { Value = tableStorage.CreateSnapshot() }; var writeBatchReference = new Reference <WriteBatch> { Value = new WriteBatch() }; var accessor = new StorageActionsAccessor(uuidGenerator, _documentCodecs, documentCacher, writeBatchReference, snapshotReference, tableStorage, this, bufferPool); accessor.OnDispose += () => { var exceptionAggregator = new ExceptionAggregator("Could not properly dispose StorageActionsAccessor"); exceptionAggregator.Execute(() => snapshotReference.Value.Dispose()); exceptionAggregator.Execute(() => writeBatchReference.Value.Dispose()); exceptionAggregator.ThrowIfNeeded(); }; return(accessor); }
public void Dispose() { var aggregator = new ExceptionAggregator("ClusterManager disposal error."); aggregator.Execute(SaflyDisposeOfTimer); aggregator.Execute(() => { if (Engine != null && disableReplicationStateChecks == false) { Engine.StateChanged -= OnRaftEngineStateChanged; } }); aggregator.Execute(() => { Client?.Dispose(); }); aggregator.Execute(() => { Engine?.Dispose(); }); aggregator.ThrowIfNeeded(); }
public void Dispose() { var ea = new ExceptionAggregator("Failed during dispose of document replication loader"); ea.Execute(() => { using (var waitHandle = new ManualResetEvent(false)) { if (_reconnectAttemptTimer.Dispose(waitHandle)) { waitHandle.WaitOne(); } } }); ea.Execute(() => ConflictResolver?.ResolveConflictsTask.Wait()); if (_log.IsInfoEnabled) { _log.Info("Closing and disposing document replication connections."); } foreach (var incoming in _incoming) { ea.Execute(incoming.Value.Dispose); } foreach (var outgoing in _outgoing) { ea.Execute(outgoing.Dispose); } Database.DocumentTombstoneCleaner?.Unsubscribe(this); ea.ThrowIfNeeded(); }
public static void DeletePaths(ConcurrentSet <string> pathsToDelete, ExceptionAggregator exceptionAggregator) { var localPathsToDelete = pathsToDelete.ToArray(); foreach (var pathToDelete in localPathsToDelete) { pathsToDelete.TryRemove(pathToDelete); exceptionAggregator.Execute(() => ClearDatabaseDirectory(pathToDelete)); if (File.Exists(pathToDelete)) { exceptionAggregator.Execute(() => { throw new IOException(string.Format("We tried to delete the '{0}' directory, but failed because it is a file.\r\n{1}", pathToDelete, WhoIsLocking.ThisFile(pathToDelete))); }); } else if (Directory.Exists(pathToDelete)) { exceptionAggregator.Execute(() => { string filePath; try { filePath = Directory.GetFiles(pathToDelete, "*", SearchOption.AllDirectories).FirstOrDefault() ?? pathToDelete; } catch (Exception) { filePath = pathToDelete; } throw new IOException(string.Format("We tried to delete the '{0}' directory.\r\n{1}", pathToDelete, WhoIsLocking.ThisFile(filePath))); }); } } }
public void Dispose() { _shutdownNotification.Cancel(); toDispose.Add(DatabasesLandlord); toDispose.Add(_env); toDispose.Add(ContextPool); var exceptionAggregator = new ExceptionAggregator(_logger, $"Could not dispose {nameof(ServerStore)}."); foreach (var disposable in toDispose) { exceptionAggregator.Execute(() => disposable?.Dispose()); } exceptionAggregator.ThrowIfNeeded(); }
public void Dispose() { disposerLock.EnterWriteLock(); try { TenantDatabaseModified.Occured -= TenantDatabaseRemoved; var exceptionAggregator = new ExceptionAggregator(logger, "Could not properly dispose of HttpServer"); exceptionAggregator.Execute(() => { if (databasesCleanupTimer != null) { databasesCleanupTimer.Dispose(); } }); exceptionAggregator.Execute(() => { if (listener != null && listener.IsListening) { listener.Stop(); } }); disposed = true; exceptionAggregator.Execute(() => { lock (ResourcesStoresCache) { foreach (var documentDatabase in ResourcesStoresCache) { var database = documentDatabase.Value; exceptionAggregator.Execute(database.Dispose); } ResourcesStoresCache.Clear(); } }); exceptionAggregator.Execute(currentConfiguration.Dispose); exceptionAggregator.Execute(currentDatabase.Dispose); exceptionAggregator.Execute(currentTenantId.Dispose); exceptionAggregator.ThrowIfNeeded(); } finally { disposerLock.ExitWriteLock(); } }