コード例 #1
0
ファイル: RavenFileSystem.cs プロジェクト: jesuslpm/ravendb
		public RavenFileSystem(InMemoryRavenConfiguration systemConfiguration, string name, TransportState recievedTransportState = null)
		{
		    this.Name = name;
			this.systemConfiguration = systemConfiguration;

		    var storageType = systemConfiguration.FileSystem.DefaultStorageTypeName;

            storage = CreateTransactionalStorage(storageType, systemConfiguration);
			search = new IndexStorage(systemConfiguration.FileSystem.IndexStoragePath, systemConfiguration.Settings);
			sigGenerator = new SigGenerator();
			var replicationHiLo = new SynchronizationHiLo(storage);
			var sequenceActions = new SequenceActions(storage);
			transportState = recievedTransportState ?? new TransportState();
			notificationPublisher = new NotificationPublisher(transportState);
			fileLockManager = new FileLockManager();
			storage.Initialize();
			search.Initialize();
			var uuidGenerator = new UuidGenerator(sequenceActions);
			historian = new Historian(storage, replicationHiLo, uuidGenerator);
			BufferPool = new BufferPool(1024 * 1024 * 1024, 65 * 1024);
			conflictArtifactManager = new ConflictArtifactManager(storage, search);
			conflictDetector = new ConflictDetector();
			conflictResolver = new ConflictResolver(storage, new CompositionContainer(systemConfiguration.Catalog));
			synchronizationTask = new SynchronizationTask(storage, sigGenerator, notificationPublisher, systemConfiguration);
			storageOperationsTask = new StorageOperationsTask(storage, search, notificationPublisher);
            metricsCounters = new MetricsCountersManager();

			AppDomain.CurrentDomain.ProcessExit += ShouldDispose;
			AppDomain.CurrentDomain.DomainUnload += ShouldDispose;
		}
コード例 #2
0
		public RavenFileSystem(InMemoryRavenConfiguration systemConfiguration, string name, TransportState receivedTransportState = null)
		{
			ExtensionsState = new AtomicDictionary<object>();

		    Name = name;
			this.systemConfiguration = systemConfiguration;

			systemConfiguration.Container.SatisfyImportsOnce(this);

            transportState = receivedTransportState ?? new TransportState();

            storage = CreateTransactionalStorage(systemConfiguration);

            sigGenerator = new SigGenerator();
            fileLockManager = new FileLockManager();			        
   
            BufferPool = new BufferPool(1024 * 1024 * 1024, 65 * 1024);
            conflictDetector = new ConflictDetector();
            conflictResolver = new ConflictResolver(storage, new CompositionContainer(systemConfiguration.Catalog));

            notificationPublisher = new NotificationPublisher(transportState);
            synchronizationTask = new SynchronizationTask(storage, sigGenerator, notificationPublisher, systemConfiguration);

            metricsCounters = new MetricsCountersManager();

            search = new IndexStorage(name, systemConfiguration);

            conflictArtifactManager = new ConflictArtifactManager(storage, search);
            storageOperationsTask = new StorageOperationsTask(storage, DeleteTriggers, search, notificationPublisher); 

			AppDomain.CurrentDomain.ProcessExit += ShouldDispose;
			AppDomain.CurrentDomain.DomainUnload += ShouldDispose;
		}        
コード例 #3
0
ファイル: RavenFileSystem.cs プロジェクト: j2jensen/ravendb
        public RavenFileSystem(InMemoryRavenConfiguration config, string name, TransportState receivedTransportState = null)
        {
            ExtensionsState = new AtomicDictionary<object>();

            Name = name;
            ResourceName = string.Concat(Abstractions.Data.Constants.FileSystem.UrlPrefix, "/", name);
            configuration = config;

            try
            {
                ValidateStorage();

                configuration.Container.SatisfyImportsOnce(this);

                transportState = receivedTransportState ?? new TransportState();

                storage = CreateTransactionalStorage(configuration);

                sigGenerator = new SigGenerator();
                fileLockManager = new FileLockManager();			        
   
                BufferPool = new BufferPool(1024 * 1024 * 1024, 65 * 1024);
                conflictDetector = new ConflictDetector();
                conflictResolver = new ConflictResolver(storage, new CompositionContainer(configuration.Catalog));

                notificationPublisher = new NotificationPublisher(transportState);
                synchronizationTask = new SynchronizationTask(storage, sigGenerator, notificationPublisher, configuration);

                metricsCounters = new MetricsCountersManager();

                search = new IndexStorage(name, configuration);

                conflictArtifactManager = new ConflictArtifactManager(storage, search);

                TimerManager = new ResourceTimerManager();

                Tasks = new TaskActions(this, Log);
                Files = new FileActions(this, Log);
                Synchronizations = new SynchronizationActions(this, Log);

                AppDomain.CurrentDomain.ProcessExit += ShouldDispose;
                AppDomain.CurrentDomain.DomainUnload += ShouldDispose;
            }
            catch (Exception e)
            {
                Log.ErrorException(string.Format("Could not create file system '{0}'", Name ?? "unknown name"), e);
                try
                {
                    Dispose();
                }
                catch (Exception ex)
                {
                    Log.FatalException("Failed to dispose when already getting an error in file system ctor", ex);
                }
                throw;
            }
        }
コード例 #4
0
ファイル: CounterStorage.cs プロジェクト: cocytus/ravendb
		public CounterStorage(string serverUrl, string storageName, InMemoryRavenConfiguration configuration, TransportState recievedTransportState = null)
		{
            CounterStorageUrl = String.Format("{0}counters/{1}", serverUrl, storageName);
            Name = storageName;
                
			var options = configuration.RunInMemory ? StorageEnvironmentOptions.CreateMemoryOnly()
				: CreateStorageOptionsFromConfiguration(configuration.CountersDataDirectory, configuration.Settings);

			storageEnvironment = new StorageEnvironment(options);
            ReplicationTask = new RavenCounterReplication(this);

			//TODO: add an option to create a ReplicationRequestTimeout when creating a new counter storage
		    ReplicationTimeoutInMs = configuration.GetConfigurationValue<int>("Raven/Replication/ReplicationRequestTimeout") ?? 60*1000;

            metricsCounters = new CountersMetricsManager();
			transportState = recievedTransportState ?? new TransportState();
            Initialize();
		}
コード例 #5
0
ファイル: RavenFileSystem.cs プロジェクト: randacc/ravendb
		public RavenFileSystem(InMemoryRavenConfiguration systemConfiguration, TransportState transportState, string name)
		{
		    this.Name = name;
			this.systemConfiguration = systemConfiguration;

		    var storageType = systemConfiguration.DefaultFileSystemStorageTypeName;
            if (string.Equals(InMemoryRavenConfiguration.VoronTypeName, storageType, StringComparison.OrdinalIgnoreCase) == false)
            {
                if (Directory.Exists(systemConfiguration.FileSystemDataDirectory) &&
                        Directory.EnumerateFileSystemEntries(systemConfiguration.FileSystemDataDirectory).Any())
                    throw new InvalidOperationException(
                        string.Format(
                            "We do not allow to run on a storage engine other then Voron, while we are in the early pre-release phase of RavenDB 3.0. You are currently running on {0}",
                            storageType));

                Trace.WriteLine("Forcing filesystem to run on Voron - pre release behavior only, mind " + Path.GetFileName(Path.GetDirectoryName(systemConfiguration.FileSystemDataDirectory)));
                storageType = InMemoryRavenConfiguration.VoronTypeName;
            }

            storage = CreateTransactionalStorage(storageType, systemConfiguration.FileSystemDataDirectory, systemConfiguration.Settings);
			search = new IndexStorage(systemConfiguration.FileSystemIndexStoragePath, systemConfiguration.Settings);
			sigGenerator = new SigGenerator();
			var replicationHiLo = new SynchronizationHiLo(storage);
			var sequenceActions = new SequenceActions(storage);
			this.transportState = transportState;
			notificationPublisher = new NotificationPublisher(transportState);
			fileLockManager = new FileLockManager();
			storage.Initialize();
			search.Initialize();
			var uuidGenerator = new UuidGenerator(sequenceActions);
			historian = new Historian(storage, replicationHiLo, uuidGenerator);
			BufferPool = new BufferPool(1024 * 1024 * 1024, 65 * 1024);
			conflictArtifactManager = new ConflictArtifactManager(storage, search);
			conflictDetector = new ConflictDetector();
			conflictResolver = new ConflictResolver();
			synchronizationTask = new SynchronizationTask(storage, sigGenerator, notificationPublisher, systemConfiguration);
			storageOperationsTask = new StorageOperationsTask(storage, search, notificationPublisher);
            metricsCounters = new MetricsCountersManager();

			AppDomain.CurrentDomain.ProcessExit += ShouldDispose;
			AppDomain.CurrentDomain.DomainUnload += ShouldDispose;
		}
コード例 #6
0
ファイル: CounterStorage.cs プロジェクト: j2jensen/ravendb
        public CounterStorage(string serverUrl, string storageName, InMemoryRavenConfiguration configuration, TransportState recievedTransportState = null)
        {
            CounterStorageUrl = String.Format("{0}counters/{1}", serverUrl, storageName);
            Name = storageName;
            ResourceName = string.Concat(Constants.Counter.UrlPrefix, "/", storageName);
                
            var options = configuration.RunInMemory ? StorageEnvironmentOptions.CreateMemoryOnly()
                : CreateStorageOptionsFromConfiguration(configuration.CountersDataDirectory, configuration.Settings);

            storageEnvironment = new StorageEnvironment(options);
            ReplicationTask = new RavenCounterReplication(this);

            //TODO: add an option to create a ReplicationRequestTimeout when creating a new counter storage
            ReplicationTimeoutInMs = configuration.Replication.ReplicationRequestTimeoutInMilliseconds;

            metricsCounters = new CountersMetricsManager();
            transportState = recievedTransportState ?? new TransportState();
            Configuration = configuration;
            ExtensionsState = new AtomicDictionary<object>();
            Initialize();
        }
コード例 #7
0
ファイル: DocumentDatabase.cs プロジェクト: cocytus/ravendb
		public DocumentDatabase(InMemoryRavenConfiguration configuration, TransportState recievedTransportState = null)
		{
			DocumentLock = new PutSerialLock();
			Name = configuration.DatabaseName;
			Configuration = configuration;
			transportState = recievedTransportState ?? new TransportState();
			ExtensionsState = new AtomicDictionary<object>();

			using (LogManager.OpenMappedContext("database", Name ?? Constants.SystemDatabase))
			{
				Log.Debug("Start loading the following database: {0}", Name ?? Constants.SystemDatabase);

				initializer = new DocumentDatabaseInitializer(this, configuration);

				initializer.InitializeEncryption();
				initializer.ValidateLicense();

				initializer.SubscribeToDomainUnloadOrProcessExit();
				initializer.ExecuteAlterConfiguration();
				initializer.SatisfyImportsOnce();

				backgroundTaskScheduler = configuration.CustomTaskScheduler ?? TaskScheduler.Default;


				recentTouches = new SizeLimitedConcurrentDictionary<string, TouchedDocumentInfo>(configuration.MaxRecentTouchesToRemember, StringComparer.OrdinalIgnoreCase);

				configuration.Container.SatisfyImportsOnce(this);

				workContext = new WorkContext
				{
					Database = this,
					DatabaseName = Name,
					IndexUpdateTriggers = IndexUpdateTriggers,
					ReadTriggers = ReadTriggers,
					TaskScheduler = backgroundTaskScheduler,
					Configuration = configuration,
					IndexReaderWarmers = IndexReaderWarmers
				};

				try
				{
					uuidGenerator = new SequentialUuidGenerator();
					initializer.InitializeTransactionalStorage(uuidGenerator);
					lastCollectionEtags = new LastCollectionEtags(WorkContext);
				}
				catch (Exception)
				{
					if (TransactionalStorage != null)
						TransactionalStorage.Dispose();
					throw;
				}

				try
				{
					TransactionalStorage.Batch(actions => uuidGenerator.EtagBase = actions.General.GetNextIdentityValue("Raven/Etag"));

					// Index codecs must be initialized before we try to read an index
					InitializeIndexCodecTriggers();
					initializer.InitializeIndexStorage();

					Attachments = new AttachmentActions(this, recentTouches, uuidGenerator, Log);
					Documents = new DocumentActions(this, recentTouches, uuidGenerator, Log);
					Indexes = new IndexActions(this, recentTouches, uuidGenerator, Log);
					Maintenance = new MaintenanceActions(this, recentTouches, uuidGenerator, Log);
					Notifications = new NotificationActions(this, recentTouches, uuidGenerator, Log);
					Patches = new PatchActions(this, recentTouches, uuidGenerator, Log);
					Queries = new QueryActions(this, recentTouches, uuidGenerator, Log);
					Tasks = new TaskActions(this, recentTouches, uuidGenerator, Log);
					Transformers = new TransformerActions(this, recentTouches, uuidGenerator, Log);

					inFlightTransactionalState = TransactionalStorage.GetInFlightTransactionalState(this, Documents.Put, Documents.Delete);

					CompleteWorkContextSetup();

					prefetcher = new Prefetcher(workContext);
					indexingExecuter = new IndexingExecuter(workContext, prefetcher);

					RaiseIndexingWiringComplete();

					InitializeTriggersExceptIndexCodecs();
					SecondStageInitialization();
					ExecuteStartupTasks();
					lastCollectionEtags.InitializeBasedOnIndexingResults();

					Log.Debug("Finish loading the following database: {0}", configuration.DatabaseName ?? Constants.SystemDatabase);
				}
				catch (Exception)
				{
					Dispose();
					throw;
				}
			}
		}
コード例 #8
0
		public DocumentDatabase(InMemoryRavenConfiguration configuration)
		{
			this.configuration = configuration;

			using (LogManager.OpenMappedContext("database", configuration.DatabaseName ?? Constants.SystemDatabase))
			{
				if (configuration.IsTenantDatabase == false)
				{
					validateLicense = new ValidateLicense();
					validateLicense.Execute(configuration);
				}
				AppDomain.CurrentDomain.DomainUnload += DomainUnloadOrProcessExit;
				AppDomain.CurrentDomain.ProcessExit += DomainUnloadOrProcessExit;

				Name = configuration.DatabaseName;
				backgroundTaskScheduler = configuration.CustomTaskScheduler ?? TaskScheduler.Current;

				ExtensionsState = new AtomicDictionary<object>();
				Configuration = configuration;

				ExecuteAlterConfiguration();

				configuration.Container.SatisfyImportsOnce(this);

				workContext = new WorkContext
				{
					Database = this,
					DatabaseName = Name,
					IndexUpdateTriggers = IndexUpdateTriggers,
					ReadTriggers = ReadTriggers,
					RaiseIndexChangeNotification = RaiseNotifications,
					TaskScheduler = backgroundTaskScheduler,
					Configuration = configuration
				};

				TransactionalStorage = configuration.CreateTransactionalStorage(workContext.HandleWorkNotifications);

				try
				{
					sequentialUuidGenerator = new SequentialUuidGenerator();
					TransactionalStorage.Initialize(sequentialUuidGenerator, DocumentCodecs);
				}
				catch (Exception)
				{
					TransactionalStorage.Dispose();
					throw;
				}

				try
				{

					TransactionalStorage.Batch(actions =>
						sequentialUuidGenerator.EtagBase = actions.General.GetNextIdentityValue("Raven/Etag"));

					TransportState = new TransportState();

					// Index codecs must be initialized before we try to read an index
					InitializeIndexCodecTriggers();

					IndexDefinitionStorage = new IndexDefinitionStorage(
						configuration,
						TransactionalStorage,
						configuration.DataDirectory,
						configuration.Container.GetExportedValues<AbstractViewGenerator>(),
						Extensions);
					IndexStorage = new IndexStorage(IndexDefinitionStorage, configuration, this);

					CompleteWorkContextSetup();

					indexingExecuter = new IndexingExecuter(workContext);

					InitializeTriggersExceptIndexCodecs();
					SecondStageInitialization();

					ExecuteStartupTasks();
				}
				catch (Exception)
				{
					Dispose();
					throw;
				}
			}
		}
コード例 #9
0
        public DocumentDatabase(InMemoryRavenConfiguration configuration, TransportState recievedTransportState = null)
        {
            TimerManager = new ResourceTimerManager();
            DocumentLock = new PutSerialLock();
            IdentityLock = new PutSerialLock();
            Name = configuration.DatabaseName;
            ResourceName = Name;
            Configuration = configuration;
            transportState = recievedTransportState ?? new TransportState();
            ExtensionsState = new AtomicDictionary<object>();

            using (LogManager.OpenMappedContext("database", Name ?? Constants.SystemDatabase))
            {
                Log.Debug("Start loading the following database: {0}", Name ?? Constants.SystemDatabase);

                initializer = new DocumentDatabaseInitializer(this, configuration);
                initializer.ValidateLicense();

                initializer.ValidateStorage();

                initializer.InitializeEncryption();

                initializer.SubscribeToDomainUnloadOrProcessExit();
                initializer.SubscribeToDiskSpaceChanges();
                initializer.ExecuteAlterConfiguration();
                initializer.SatisfyImportsOnce();

                backgroundTaskScheduler = configuration.CustomTaskScheduler ?? TaskScheduler.Default;


                recentTouches = new SizeLimitedConcurrentDictionary<string, TouchedDocumentInfo>(configuration.MaxRecentTouchesToRemember, StringComparer.OrdinalIgnoreCase);

                configuration.Container.SatisfyImportsOnce(this);

                workContext = new WorkContext
                {
                    Database = this,
                    DatabaseName = Name,
                    IndexUpdateTriggers = IndexUpdateTriggers,
                    ReadTriggers = ReadTriggers,
                    TaskScheduler = backgroundTaskScheduler,
                    Configuration = configuration,
                    IndexReaderWarmers = IndexReaderWarmers
                };

                try
                {
                    uuidGenerator = new SequentialUuidGenerator();
                    initializer.InitializeTransactionalStorage(uuidGenerator);
                    lastCollectionEtags = new LastCollectionEtags(WorkContext);
                }
                catch (Exception ex)
                {
                    Log.ErrorException("Could not initialize transactional storage, not creating database", ex);
                    try
                    {
                        if (TransactionalStorage != null)
                            TransactionalStorage.Dispose();
                        if (initializer != null)
                        {
                            initializer.UnsubscribeToDomainUnloadOrProcessExit();
                            initializer.Dispose();
                        }
                    }
                    catch (Exception e)
                    {
                        Log.ErrorException("Could not dispose on initialized DocumentDatabase members", e);
                    }

                    throw;
                }

                try
                {
                    TransactionalStorage.Batch(actions => uuidGenerator.EtagBase = actions.General.GetNextIdentityValue("Raven/Etag"));
                    initializer.InitializeIndexDefinitionStorage();
                    Indexes = new IndexActions(this, recentTouches, uuidGenerator, Log);
                    Attachments = new AttachmentActions(this, recentTouches, uuidGenerator, Log);
                    Maintenance = new MaintenanceActions(this, recentTouches, uuidGenerator, Log);
                    Notifications = new NotificationActions(this, recentTouches, uuidGenerator, Log);
                    Subscriptions = new SubscriptionActions(this, Log);
                    Patches = new PatchActions(this, recentTouches, uuidGenerator, Log);
                    Queries = new QueryActions(this, recentTouches, uuidGenerator, Log);
                    Tasks = new TaskActions(this, recentTouches, uuidGenerator, Log);
                    Transformers = new TransformerActions(this, recentTouches, uuidGenerator, Log);
                    Documents = new DocumentActions(this, recentTouches, uuidGenerator, Log);

                    inFlightTransactionalState = TransactionalStorage.InitializeInFlightTransactionalState(this, 
                        (key, etag, document, metadata, transactionInformation) => Documents.Put(key, etag, document, metadata, transactionInformation), 
                        (key, etag, transactionInformation) => Documents.Delete(key, etag, transactionInformation));

                    InitializeTriggersExceptIndexCodecs();
                    // Second stage initializing before index storage for determining the hash algotihm for encrypted databases that were upgraded from 2.5
                    SecondStageInitialization();

                    // Index codecs must be initialized before we try to read an index
                    InitializeIndexCodecTriggers();
                    initializer.InitializeIndexStorage();

                
                    CompleteWorkContextSetup();

                    prefetcher = new Prefetcher(workContext);
                    
                    IndexReplacer = new IndexReplacer(this);
                    indexingExecuter = new IndexingExecuter(workContext, prefetcher, IndexReplacer);
                    InitializeTriggersExceptIndexCodecs();

                    EnsureAllIndexDefinitionsHaveIndexes();

                    RaiseIndexingWiringComplete();

                    ExecuteStartupTasks();
                    lastCollectionEtags.InitializeBasedOnIndexingResults();

                    Log.Debug("Finish loading the following database: {0}", configuration.DatabaseName ?? Constants.SystemDatabase);
                }
                catch (Exception e)
                {
                    Log.ErrorException("Could not create database", e);
                    try
                    {
                        Dispose();
                    }
                    catch (Exception ex)
                    {
                        Log.FatalException("Failed to disposed when already getting an error during ctor", ex);
                    }
                    throw;
                }
            }
        }
コード例 #10
0
 public NotificationPublisher(TransportState transportState)
 {
     this.transportState = transportState;
 }
コード例 #11
0
ファイル: DocumentDatabase.cs プロジェクト: nishizhen/ravendb
        public DocumentDatabase(InMemoryRavenConfiguration configuration, TransportState transportState = null)
        {
            DocumentLock = new PutSerialLock();
            this.configuration = configuration;
            this.transportState = transportState ?? new TransportState();
            
            using (LogManager.OpenMappedContext("database", configuration.DatabaseName ?? Constants.SystemDatabase))
            {
                log.Debug("Start loading the following database: {0}", configuration.DatabaseName ?? Constants.SystemDatabase);

                if (configuration.IsTenantDatabase == false)
                {
                    validateLicense = new ValidateLicense();
                    validateLicense.Execute(configuration);
                }
                AppDomain.CurrentDomain.DomainUnload += DomainUnloadOrProcessExit;
                AppDomain.CurrentDomain.ProcessExit += DomainUnloadOrProcessExit;

                Name = configuration.DatabaseName;
                backgroundTaskScheduler = configuration.CustomTaskScheduler ?? TaskScheduler.Default;
                
                ExtensionsState = new AtomicDictionary<object>();
                Configuration = configuration;

                ExecuteAlterConfiguration();

                recentTouches = new SizeLimitedConcurrentDictionary<string, TouchedDocumentInfo>(configuration.MaxRecentTouchesToRemember, StringComparer.OrdinalIgnoreCase);

                configuration.Container.SatisfyImportsOnce(this);

                workContext = new WorkContext
                {
                    Database = this,
                    DatabaseName = Name,
                    IndexUpdateTriggers = IndexUpdateTriggers,
                    ReadTriggers = ReadTriggers,
                    RaiseIndexChangeNotification = RaiseNotifications,
                    TaskScheduler = backgroundTaskScheduler,
                    Configuration = configuration,
                    IndexReaderWarmers = IndexReaderWarmers
                };

                TransactionalStorage = configuration.CreateTransactionalStorage(workContext.HandleWorkNotifications);

                try
                {
                    sequentialUuidGenerator = new SequentialUuidGenerator();
                    TransactionalStorage.Initialize(sequentialUuidGenerator, DocumentCodecs);
                }
                catch (Exception)
                {
                    TransactionalStorage.Dispose();
                    throw;
                }

                try
                {

	                inFlightTransactionalState = TransactionalStorage.GetInFlightTransactionalState(Put, Delete);

                    TransactionalStorage.Batch(actions =>
                        sequentialUuidGenerator.EtagBase = actions.General.GetNextIdentityValue("Raven/Etag"));

                    // Index codecs must be initialized before we try to read an index
                    InitializeIndexCodecTriggers();

                    IndexDefinitionStorage = new IndexDefinitionStorage(
                        configuration,
                        TransactionalStorage,
                        configuration.DataDirectory,
                        configuration.Container.GetExportedValues<AbstractViewGenerator>(),
                        Extensions);
                    IndexStorage = new IndexStorage(IndexDefinitionStorage, configuration, this);

                    CompleteWorkContextSetup();

					prefetcher = new Prefetcher(workContext);
                    indexingExecuter = new IndexingExecuter(workContext, prefetcher);

                    InitializeTriggersExceptIndexCodecs();
                    SecondStageInitialization();

                    ExecuteStartupTasks();
                    log.Debug("Finish loading the following database: {0}", configuration.DatabaseName ?? Constants.SystemDatabase);
                }
                catch (Exception)
                {
                    Dispose();
                    throw;
                }
            }
        }
コード例 #12
0
		public DocumentDatabase(InMemoryRavenConfiguration configuration)
		{
			if (configuration.IsTenantDatabase == false)
			{
				validateLicense = new ValidateLicense();
				validateLicense.Execute(configuration);
			}
			AppDomain.CurrentDomain.DomainUnload += DomainUnloadOrProcessExit;
			AppDomain.CurrentDomain.ProcessExit += DomainUnloadOrProcessExit;

			Name = configuration.DatabaseName;
			if (configuration.CustomTaskScheduler != null)
			{
				backgroundTaskScheduler = configuration.CustomTaskScheduler;
			}
			else if (configuration.BackgroundTasksPriority != ThreadPriority.Normal)
			{
				backgroundTaskScheduler = new TaskSchedulerWithCustomPriority(
					// we need a minimum of four task threads - one for indexing dispatch, one for reducing dispatch, one for tasks, one for indexing/reducing ops
					Math.Max(4, configuration.MaxNumberOfParallelIndexTasks + 2),
					configuration.BackgroundTasksPriority);
			}
			else
			{
				backgroundTaskScheduler = TaskScheduler.Current;
			}

			ExtensionsState = new AtomicDictionary<object>();
			Configuration = configuration;

			ExecuteAlterConfiguration();

			configuration.Container.SatisfyImportsOnce(this);

			workContext = new WorkContext
			{
				DatabaseName = Name,
				IndexUpdateTriggers = IndexUpdateTriggers,
				ReadTriggers = ReadTriggers,
				RaiseIndexChangeNotification = RaiseNotifications,
				TaskScheduler = backgroundTaskScheduler,
				Configuration = configuration
			};

			TransactionalStorage = configuration.CreateTransactionalStorage(workContext.HandleWorkNotifications);

			try
			{
				TransactionalStorage.Initialize(this, DocumentCodecs);
			}
			catch (Exception)
			{
				TransactionalStorage.Dispose();
				throw;
			}

			try
			{

				TransactionalStorage.Batch(actions => currentEtagBase = actions.General.GetNextIdentityValue("Raven/Etag"));

				TransportState = new TransportState();

				// Index codecs must be initialized before we try to read an index
				InitializeIndexCodecTriggers();

				IndexDefinitionStorage = new IndexDefinitionStorage(
					configuration,
					TransactionalStorage,
					configuration.DataDirectory,
					configuration.Container.GetExportedValues<AbstractViewGenerator>(),
					Extensions);
				IndexStorage = new IndexStorage(IndexDefinitionStorage, configuration, this);

				CompleteWorkContextSetup();

				indexingExecuter = new IndexingExecuter(workContext);

				InitializeTriggersExceptIndexCodecs();

				ExecuteStartupTasks();
			}
			catch (Exception)
			{
				Dispose();
				throw;
			}
		}