Example #1
0
        public RavenFileSystem(InMemoryRavenConfiguration config, string name, TransportState receivedTransportState = null)
        {
            ExtensionsState = new AtomicDictionary <object>();

            Name          = name;
            ResourceName  = string.Concat(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;
            }
        }
Example #2
0
        public DocumentDatabase(InMemoryRavenConfiguration configuration, TransportState recievedTransportState = null)
        {
            TimerManager    = new ResourceTimerManager();
            DocumentLock    = 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.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 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"));

                    // 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);
                    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);

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

                    CompleteWorkContextSetup();

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

                    RaiseIndexingWiringComplete();

                    InitializeTriggersExceptIndexCodecs();
                    SecondStageInitialization();
                    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;
                }
            }
        }