public static bool TryToCreateTransactionalStorage(InMemoryRavenConfiguration ravenConfiguration, bool hasCompression, EncryptionConfiguration encryption, bool isRavenFs, out ITransactionalStorage storage, out Database.FileSystem.Storage.ITransactionalStorage fileStorage) { storage = null; fileStorage = null; if (File.Exists(Path.Combine(ravenConfiguration.DataDirectory, Voron.Impl.Constants.DatabaseFilename))) { if (isRavenFs) { fileStorage = RavenFileSystem.CreateTransactionalStorage(ravenConfiguration); } else { storage = ravenConfiguration.CreateTransactionalStorage(InMemoryRavenConfiguration.VoronTypeName, () => { }, () => { }); } } else if (File.Exists(Path.Combine(ravenConfiguration.DataDirectory, "Data.jfm"))) { if (isRavenFs) { fileStorage = RavenFileSystem.CreateTransactionalStorage(ravenConfiguration); } else { storage = ravenConfiguration.CreateTransactionalStorage(InMemoryRavenConfiguration.EsentTypeName, () => { }, () => { }); } } if (storage == null && fileStorage == null) { return(false); } if (isRavenFs) { var filesOrderedPartCollection = new OrderedPartCollection <Database.FileSystem.Plugins.AbstractFileCodec>(); fileStorage.Initialize(new UuidGenerator(), filesOrderedPartCollection); return(true); } var orderedPartCollection = new OrderedPartCollection <AbstractDocumentCodec>(); if (encryption != null) { var documentEncryption = new DocumentEncryption(); documentEncryption.SetSettings(new EncryptionSettings(encryption.EncryptionKey, encryption.SymmetricAlgorithmType, encryption.EncryptIndexes, encryption.PreferedEncryptionKeyBitsSize)); orderedPartCollection.Add(documentEncryption); } if (hasCompression) { orderedPartCollection.Add(new DocumentCompression()); } storage.Initialize(new SequentialUuidGenerator { EtagBase = 0 }, orderedPartCollection); return(true); }
public void InitializeTransactionalStorage(IUuidGenerator uuidGenerator) { string storageEngineTypeName = configuration.SelectStorageEngineAndFetchTypeName(); database.TransactionalStorage = configuration.CreateTransactionalStorage(storageEngineTypeName, database.WorkContext.HandleWorkNotifications); database.TransactionalStorage.Initialize(uuidGenerator, database.DocumentCodecs); }
public static bool TryToCreateTransactionalStorage(InMemoryRavenConfiguration ravenConfiguration, bool hasCompression, EncryptionConfiguration encryption, out ITransactionalStorage storage) { storage = null; if (File.Exists(Path.Combine(ravenConfiguration.DataDirectory, Voron.Impl.Constants.DatabaseFilename))) { storage = ravenConfiguration.CreateTransactionalStorage(InMemoryRavenConfiguration.VoronTypeName, () => { }, () => { }); } else if (File.Exists(Path.Combine(ravenConfiguration.DataDirectory, "Data"))) { storage = ravenConfiguration.CreateTransactionalStorage(InMemoryRavenConfiguration.EsentTypeName, () => { }, () => { }); } if (storage == null) { return(false); } var orderedPartCollection = new OrderedPartCollection <AbstractDocumentCodec>(); if (encryption != null) { var documentEncryption = new DocumentEncryption(); documentEncryption.SetSettings(new EncryptionSettings(encryption.EncryptionKey, encryption.SymmetricAlgorithmType, encryption.EncryptIndexes, encryption.PreferedEncryptionKeyBitsSize)); orderedPartCollection.Add(documentEncryption); } if (hasCompression) { orderedPartCollection.Add(new DocumentCompression()); } uuidGenerator = new SequentialUuidGenerator(); storage.Initialize(uuidGenerator, orderedPartCollection); /* * Added configuration steps */ storage.Batch(actions => { var nextIdentityValue = actions.General.GetNextIdentityValue("Raven/Etag"); uuidGenerator.EtagBase = nextIdentityValue; }); return(true); }
public DocumentDatabase(InMemoryRavenConfiguration configuration) { Configuration = configuration; configuration.Container.SatisfyImportsOnce(this); workContext = new WorkContext { IndexUpdateTriggers = IndexUpdateTriggers, ReadTriggers = ReadTriggers }; dynamicQueryRunner = new DynamicQueryRunner(this); suggestionQueryRunner = new SuggestionQueryRunner(this); TransactionalStorage = configuration.CreateTransactionalStorage(workContext.HandleWorkNotifications); configuration.Container.SatisfyImportsOnce(TransactionalStorage); bool newDb; try { newDb = TransactionalStorage.Initialize(this); } catch (Exception) { TransactionalStorage.Dispose(); throw; } TransactionalStorage.Batch(actions => currentEtagBase = actions.General.GetNextIdentityValue("Raven/Etag")); IndexDefinitionStorage = new IndexDefinitionStorage( configuration, TransactionalStorage, configuration.DataDirectory, configuration.Container.GetExportedValues<AbstractViewGenerator>(), Extensions); IndexStorage = new IndexStorage(IndexDefinitionStorage, configuration); workContext.IndexStorage = IndexStorage; workContext.TransactionaStorage = TransactionalStorage; workContext.IndexDefinitionStorage = IndexDefinitionStorage; try { InitializeTriggers(); ExecuteStartupTasks(); } catch (Exception) { Dispose(); throw; } if (!newDb) return; OnNewlyCreatedDatabase(); }
public static bool TryToCreateTransactionalStorage(InMemoryRavenConfiguration ravenConfiguration, out ITransactionalStorage storage) { storage = null; if (File.Exists(Path.Combine(ravenConfiguration.DataDirectory, Voron.Impl.Constants.DatabaseFilename))) { storage = ravenConfiguration.CreateTransactionalStorage(InMemoryRavenConfiguration.VoronTypeName, () => { }, () => { }); } else if (File.Exists(Path.Combine(ravenConfiguration.DataDirectory, "Data"))) { storage = ravenConfiguration.CreateTransactionalStorage(InMemoryRavenConfiguration.EsentTypeName, () => { }, () => { }); } if (storage != null) { storage.Initialize(new SequentialUuidGenerator { EtagBase = 0 }, new OrderedPartCollection <AbstractDocumentCodec>()); return(true); } return(false); }
public void InitializeTransactionalStorage(IUuidGenerator uuidGenerator) { string storageEngineTypeName = configuration.SelectStorageEngineAndFetchTypeName(); database.TransactionalStorage = configuration.CreateTransactionalStorage(storageEngineTypeName, database.WorkContext.HandleWorkNotifications, () => { if (database.StorageInaccessible != null) { database.StorageInaccessible(database, EventArgs.Empty); } }); database.TransactionalStorage.Initialize(uuidGenerator, database.DocumentCodecs); }
public DocumentDatabase(InMemoryRavenConfiguration configuration) { ExternalState = new ConcurrentDictionary <string, object>(); if (configuration.BackgroundTasksPriority != ThreadPriority.Normal) { backgroundTaskScheduler = new TaskSchedulerWithCustomPriority( // we need a minimum of three task threads - one for indexing dispatch, one for tasks, one for indexing ops Math.Max(3, configuration.MaxNumberOfParallelIndexTasks + 2), configuration.BackgroundTasksPriority); } else { backgroundTaskScheduler = TaskScheduler.Current; } ExtensionsState = new ConcurrentDictionary <object, object>(); Configuration = configuration; configuration.Container.SatisfyImportsOnce(this); workContext = new WorkContext { IndexUpdateTriggers = IndexUpdateTriggers, ReadTriggers = ReadTriggers }; TransactionalStorage = configuration.CreateTransactionalStorage(workContext.HandleWorkNotifications); configuration.Container.SatisfyImportsOnce(TransactionalStorage); try { TransactionalStorage.Initialize(this); } catch (Exception) { TransactionalStorage.Dispose(); throw; } TransactionalStorage.Batch(actions => currentEtagBase = actions.General.GetNextIdentityValue("Raven/Etag")); IndexDefinitionStorage = new IndexDefinitionStorage( configuration, TransactionalStorage, configuration.DataDirectory, configuration.Container.GetExportedValues <AbstractViewGenerator>(), Extensions); IndexStorage = new IndexStorage(IndexDefinitionStorage, configuration); workContext.Configuration = configuration; workContext.IndexStorage = IndexStorage; workContext.TransactionaStorage = TransactionalStorage; workContext.IndexDefinitionStorage = IndexDefinitionStorage; try { InitializeTriggers(); ExecuteStartupTasks(); } catch (Exception) { Dispose(); throw; } }
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; } } }
public DocumentDatabase(InMemoryRavenConfiguration configuration) { ExternalState = new ConcurrentDictionary<string, object>(); Name = configuration.DatabaseName; 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 ConcurrentDictionary<object, object>(); Configuration = configuration; ExecuteAlterConfiguration(); configuration.Container.SatisfyImportsOnce(this); workContext = new WorkContext { IndexUpdateTriggers = IndexUpdateTriggers, ReadTriggers = ReadTriggers }; TransactionalStorage = configuration.CreateTransactionalStorage(workContext.HandleWorkNotifications); configuration.Container.SatisfyImportsOnce(TransactionalStorage); try { TransactionalStorage.Initialize(this); } catch (Exception) { TransactionalStorage.Dispose(); throw; } TransactionalStorage.Batch(actions => currentEtagBase = actions.General.GetNextIdentityValue("Raven/Etag")); IndexDefinitionStorage = new IndexDefinitionStorage( configuration, TransactionalStorage, configuration.DataDirectory, configuration.Container.GetExportedValues<AbstractViewGenerator>(), Extensions); IndexStorage = new IndexStorage(IndexDefinitionStorage, configuration); workContext.Configuration = configuration; workContext.IndexStorage = IndexStorage; workContext.TransactionaStorage = TransactionalStorage; workContext.IndexDefinitionStorage = IndexDefinitionStorage; try { InitializeTriggers(); ExecuteStartupTasks(); } catch (Exception) { Dispose(); throw; } }
public static bool TryToCreateTransactionalStorage(InMemoryRavenConfiguration ravenConfiguration, bool hasCompression, EncryptionConfiguration encryption, out ITransactionalStorage storage) { storage = null; if (File.Exists(Path.Combine(ravenConfiguration.DataDirectory, Voron.Impl.Constants.DatabaseFilename))) storage = ravenConfiguration.CreateTransactionalStorage(InMemoryRavenConfiguration.VoronTypeName, () => { }, () => { }); else if (File.Exists(Path.Combine(ravenConfiguration.DataDirectory, "Data"))) storage = ravenConfiguration.CreateTransactionalStorage(InMemoryRavenConfiguration.EsentTypeName, () => { }, () => { }); if (storage == null) return false; var orderedPartCollection = new OrderedPartCollection<AbstractDocumentCodec>(); if (encryption != null) { var documentEncryption = new DocumentEncryption(); documentEncryption.SetSettings(new EncryptionSettings(encryption.EncryptionKey, encryption.SymmetricAlgorithmType, encryption.EncryptIndexes, encryption.PreferedEncryptionKeyBitsSize)); orderedPartCollection.Add(documentEncryption); } if (hasCompression) { orderedPartCollection.Add(new DocumentCompression()); } storage.Initialize(new SequentialUuidGenerator {EtagBase = 0}, orderedPartCollection); return true; }
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; } } }
public static bool TryToCreateTransactionalStorage(InMemoryRavenConfiguration ravenConfiguration, out ITransactionalStorage storage) { storage = null; if (File.Exists(Path.Combine(ravenConfiguration.DataDirectory, Voron.Impl.Constants.DatabaseFilename))) storage = ravenConfiguration.CreateTransactionalStorage(InMemoryRavenConfiguration.VoronTypeName, () => { }, () => { }); else if (File.Exists(Path.Combine(ravenConfiguration.DataDirectory, "Data"))) storage = ravenConfiguration.CreateTransactionalStorage(InMemoryRavenConfiguration.EsentTypeName, () => { }, () => { }); if (storage != null) { storage.Initialize(new SequentialUuidGenerator {EtagBase = 0}, new OrderedPartCollection<AbstractDocumentCodec>()); return true; } return false; }
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; } }