Пример #1
0
        public DocumentDatabase(string name, RavenConfiguration configuration, ServerStore serverStore)
        {
            Scripts       = new ScriptRunnerCache(this);
            _logger       = LoggingSource.Instance.GetLogger <DocumentDatabase>(Name);
            _serverStore  = serverStore;
            StartTime     = SystemTime.UtcNow;
            Name          = name;
            Configuration = configuration;

            try
            {
                using (_serverStore.ContextPool.AllocateOperationContext(out TransactionOperationContext ctx))
                    using (ctx.OpenReadTransaction())
                    {
                        MasterKey = serverStore.GetSecretKey(ctx, Name);

                        var databaseRecord = _serverStore.Cluster.ReadDatabase(ctx, Name);
                        if (databaseRecord != null)
                        {
                            // can happen when we are in the process of restoring a database
                            if (databaseRecord.Encrypted && MasterKey == null)
                            {
                                throw new InvalidOperationException($"Attempt to create encrypted db {Name} without supplying the secret key");
                            }
                            if (databaseRecord.Encrypted == false && MasterKey != null)
                            {
                                throw new InvalidOperationException($"Attempt to create a non-encrypted db {Name}, but a secret key exists for this db.");
                            }
                        }
                    }

                QueryMetadataCache       = new QueryMetadataCache();
                IoChanges                = new IoChangesNotifications();
                Changes                  = new DocumentsChanges();
                DocumentTombstoneCleaner = new DocumentTombstoneCleaner(this);
                DocumentsStorage         = new DocumentsStorage(this);
                IndexStore               = new IndexStore(this, serverStore, _indexAndTransformerLocker);
                EtlLoader                = new EtlLoader(this, serverStore);
                ReplicationLoader        = new ReplicationLoader(this, serverStore);
                SubscriptionStorage      = new SubscriptionStorage(this, serverStore);
                Metrics                  = new MetricsCountersManager();
                TxMerger                 = new TransactionOperationsMerger(this, DatabaseShutdown);
                HugeDocuments            = new HugeDocuments(configuration.PerformanceHints.HugeDocumentsCollectionSize,
                                                             configuration.PerformanceHints.HugeDocumentSize.GetValue(SizeUnit.Bytes));
                ConfigurationStorage            = new ConfigurationStorage(this);
                NotificationCenter              = new NotificationCenter.NotificationCenter(ConfigurationStorage.NotificationsStorage, Name, _databaseShutdown.Token);
                Operations                      = new Operations.Operations(Name, ConfigurationStorage.OperationsStorage, NotificationCenter, Changes);
                DatabaseInfoCache               = serverStore.DatabaseInfoCache;
                RachisLogIndexNotifications     = new RachisLogIndexNotifications(DatabaseShutdown);
                CatastrophicFailureNotification = new CatastrophicFailureNotification(e =>
                {
                    serverStore.DatabasesLandlord.UnloadResourceOnCatastrophicFailure(name, e);
                });
            }
            catch (Exception)
            {
                Dispose();
                throw;
            }
        }
Пример #2
0
        protected LiveIoStatsCollector(IoChangesNotifications ioChanges, List <StorageEnvironmentWithType> environments, IEnumerable <DatabasePerformanceMetrics> performanceMetrics, JsonContextPoolBase <T> contextPool, CancellationToken resourceShutdown)
        {
            _ioChanges                   = ioChanges;
            _environments                = environments;
            _performanceMetrics          = performanceMetrics;
            _contextPool                 = contextPool;
            _resourceShutdown            = resourceShutdown;
            _perEnvironmentsFilesMetrics = new ConcurrentDictionary <string, BlockingCollection <IoMeterBuffer.MeterItem> >();
            _cts = new CancellationTokenSource();

            Task.Run(StartCollectingMetrics);
        }
Пример #3
0
        protected StorageEnvironmentOptions(VoronPathSetting tempPath, IoChangesNotifications ioChangesNotifications, CatastrophicFailureNotification catastrophicFailureNotification)
        {
            SafePosixOpenFlags = SafePosixOpenFlags | DefaultPosixFlags;

            DisposeWaitTime = TimeSpan.FromSeconds(15);

            TempPath = tempPath;

            ShouldUseKeyPrefix = name => false;

            MaxLogFileSize = ((sizeof(int) == IntPtr.Size ? 32 : 256) * Constants.Size.Megabyte);

            InitialLogFileSize = 64 * Constants.Size.Kilobyte;

            MaxScratchBufferSize = ((sizeof(int) == IntPtr.Size ? 32 : 256) * Constants.Size.Megabyte);

            MaxNumberOfPagesInJournalBeforeFlush =
                ((sizeof(int) == IntPtr.Size ? 4 : 32) * Constants.Size.Megabyte) / Constants.Storage.PageSize;

            IdleFlushTimeout = 5000; // 5 seconds

            OwnsPagers = true;

            IncrementalBackupEnabled = false;

            IoMetrics = new IoMetrics(256, 256, ioChangesNotifications);

            _log = LoggingSource.Instance.GetLogger <StorageEnvironment>(tempPath.FullPath);

            _catastrophicFailureNotification = catastrophicFailureNotification ?? new CatastrophicFailureNotification((e) =>
            {
                if (_log.IsOperationsEnabled)
                {
                    _log.Operations($"Catastrophic failure in {this}", e);
                }
            });

            var shouldForceEnvVar = Environment.GetEnvironmentVariable("VORON_INTERNAL_ForceUsing32BitsPager");

            bool result;

            if (bool.TryParse(shouldForceEnvVar, out result))
            {
                ForceUsing32BitsPager = result;
            }
        }
Пример #4
0
            public PureMemoryStorageEnvironmentOptions(string name, VoronPathSetting tempPath,
                                                       IoChangesNotifications ioChangesNotifications, CatastrophicFailureNotification catastrophicFailureNotification)
                : base(tempPath, ioChangesNotifications, catastrophicFailureNotification)
            {
                _name       = name;
                _instanceId = Interlocked.Increment(ref _counter);
                var guid     = Guid.NewGuid();
                var filename = $"ravendb-{Process.GetCurrentProcess().Id}-{_instanceId}-data.pager-{guid}";

                WinOpenFlags = Win32NativeFileAttributes.Temporary | Win32NativeFileAttributes.DeleteOnClose;

                if (Directory.Exists(tempPath.FullPath) == false)
                {
                    Directory.CreateDirectory(tempPath.FullPath);
                }

                _dataPager = new Lazy <AbstractPager>(() => GetTempMemoryMapPager(this, TempPath.Combine(filename), InitialFileSize,
                                                                                  Win32NativeFileAttributes.RandomAccess | Win32NativeFileAttributes.DeleteOnClose | Win32NativeFileAttributes.Temporary), true);
            }
Пример #5
0
            public DirectoryStorageEnvironmentOptions(VoronPathSetting basePath, VoronPathSetting tempPath, VoronPathSetting journalPath,
                                                      IoChangesNotifications ioChangesNotifications, CatastrophicFailureNotification catastrophicFailureNotification)
                : base(tempPath ?? basePath, ioChangesNotifications, catastrophicFailureNotification)
            {
                _basePath    = basePath;
                _journalPath = journalPath ?? basePath;

                if (Directory.Exists(_basePath.FullPath) == false)
                {
                    Directory.CreateDirectory(_basePath.FullPath);
                }

                if (Equals(_basePath, tempPath) == false && Directory.Exists(TempPath.FullPath) == false)
                {
                    Directory.CreateDirectory(TempPath.FullPath);
                }

                if (Equals(_journalPath, tempPath) == false && Directory.Exists(_journalPath.FullPath) == false)
                {
                    Directory.CreateDirectory(_journalPath.FullPath);
                }

                _dataPager = new Lazy <AbstractPager>(() =>
                {
                    FilePath = _basePath.Combine(Constants.DatabaseFilename);

                    return(GetMemoryMapPager(this, InitialFileSize, FilePath, usePageProtection: true));
                });

                // have to be before the journal check, so we'll fail on files in use
                // TODO: Need to verify behavior on Linux, might need to maintain a file lock
                DeleteAllTempBuffers();


                GatherRecyclableJournalFiles(); // if there are any (e.g. after a rude db shut down) let us reuse them
            }
Пример #6
0
 public IoMetrics(int currentBufferSize, int summaryBufferSize, IoChangesNotifications ioChanges = null)
 {
     BufferSize        = currentBufferSize;
     SummaryBufferSize = summaryBufferSize;
     _ioChanges        = ioChanges;
 }
Пример #7
0
        public static StorageEnvironmentOptions ForPath(string path, string tempPath, string journalPath, IoChangesNotifications ioChangesNotifications, CatastrophicFailureNotification catastrophicFailureNotification)
        {
            var pathSetting        = new VoronPathSetting(path);
            var tempPathSetting    = new VoronPathSetting(tempPath ?? GetTempPath(path));
            var journalPathSetting = journalPath != null ? new VoronPathSetting(journalPath) : null;

            return(new DirectoryStorageEnvironmentOptions(pathSetting, tempPathSetting, journalPathSetting, ioChangesNotifications, catastrophicFailureNotification));
        }
Пример #8
0
        public static StorageEnvironmentOptions CreateMemoryOnly(string name, string tempPath, IoChangesNotifications ioChangesNotifications, CatastrophicFailureNotification catastrophicFailureNotification)
        {
            var tempPathSetting = new VoronPathSetting(tempPath ?? GetTempPath());

            return(new PureMemoryStorageEnvironmentOptions(name, tempPathSetting, ioChangesNotifications, catastrophicFailureNotification));
        }