public override void Initialize(NameValueCollection settings)
        {
            base.Initialize(settings);

            if (_InitialNumberOfItemsToProcessInSingleBatch != null)
            {
                InitialNumberOfItemsToProcessInSingleBatch = Math.Min(_InitialNumberOfItemsToProcessInSingleBatch.Value, MaxNumberOfItemsToProcessInSingleBatch);
            }
            else
            {
                InitialNumberOfItemsToProcessInSingleBatch = MaxNumberOfItemsToProcessInSingleBatch == (int)GetDefaultValue <CoreConfiguration>(x => x.MaxNumberOfItemsToProcessInSingleBatch) ?
                                                             defaultInitialNumberOfItemsToProcessInSingleBatch :
                                                             Math.Max(16, Math.Min(MaxNumberOfItemsToProcessInSingleBatch / 256, defaultInitialNumberOfItemsToProcessInSingleBatch));
            }

            if (_InitialNumberOfItemsToReduceInSingleBatch != null)
            {
                InitialNumberOfItemsToReduceInSingleBatch = Math.Min(_InitialNumberOfItemsToReduceInSingleBatch.Value, MaxNumberOfItemsToReduceInSingleBatch);
            }
            else
            {
                InitialNumberOfItemsToReduceInSingleBatch = MaxNumberOfItemsToReduceInSingleBatch == (int)GetDefaultValue <CoreConfiguration>(x => x.MaxNumberOfItemsToReduceInSingleBatch) ?
                                                            defaultInitialNumberOfItemsToProcessInSingleBatch / 2 :
                                                            Math.Max(16, Math.Min(MaxNumberOfItemsToReduceInSingleBatch / 256, defaultInitialNumberOfItemsToProcessInSingleBatch / 2));
            }

            if (string.IsNullOrEmpty(parent.DatabaseName)) // we only use this for root database
            {
                Port = PortUtil.GetPort(PortStringValue, RunInMemory);
            }

            if (string.IsNullOrEmpty(TaskScheduler) == false)
            {
                var type = Type.GetType(TaskScheduler);
                parent.CustomTaskScheduler = (TaskScheduler)Activator.CreateInstance(type);
            }

            HeadersToIgnore = new HashSet <string>(_HeadersToIgnoreString.GetSemicolonSeparatedValues(), StringComparer.OrdinalIgnoreCase);
        }
Exemple #2
0
        public void Initialize()
        {
            // Core settings
            var maxPageSizeStr = Settings["Raven/MaxPageSize"];

            MaxPageSize = maxPageSizeStr != null?int.Parse(maxPageSizeStr) : 1024;

            MaxPageSize = Math.Max(MaxPageSize, 10);

            var cacheMemoryLimitMegabytes = Settings["Raven/MemoryCacheLimitMegabytes"];

            MemoryCacheLimitMegabytes = cacheMemoryLimitMegabytes == null
                                                                                        ? GetDefaultMemoryCacheLimitMegabytes()
                                                                                        : int.Parse(cacheMemoryLimitMegabytes);

            var memoryCacheExpiration = Settings["Raven/MemoryCacheExpiration"];

            MemoryCacheExpiration = memoryCacheExpiration == null
                                                                                ? TimeSpan.FromMinutes(5)
                                                                                : TimeSpan.FromSeconds(int.Parse(memoryCacheExpiration));

            var memoryCacheLimitPercentage = Settings["Raven/MemoryCacheLimitPercentage"];

            MemoryCacheLimitPercentage = memoryCacheLimitPercentage == null
                                                                ? 0 // auto-size
                                                                : int.Parse(memoryCacheLimitPercentage);
            var memoryCacheLimitCheckInterval = Settings["Raven/MemoryCacheLimitCheckInterval"];

            MemoryCacheLimitCheckInterval = memoryCacheLimitCheckInterval == null
                                                                ? MemoryCache.Default.PollingInterval
                                                                : TimeSpan.Parse(memoryCacheLimitCheckInterval);

            // Index settings
            var maxIndexingRunLatencyStr = Settings["Raven/MaxIndexingRunLatency"];

            if (maxIndexingRunLatencyStr != null)
            {
                MaxIndexingRunLatency = TimeSpan.Parse(maxIndexingRunLatencyStr);
            }

            var maxNumberOfItemsToIndexInSingleBatch = Settings["Raven/MaxNumberOfItemsToIndexInSingleBatch"];

            if (maxNumberOfItemsToIndexInSingleBatch != null)
            {
                MaxNumberOfItemsToIndexInSingleBatch     = Math.Max(int.Parse(maxNumberOfItemsToIndexInSingleBatch), 128);
                InitialNumberOfItemsToIndexInSingleBatch = Math.Min(MaxNumberOfItemsToIndexInSingleBatch,
                                                                    InitialNumberOfItemsToIndexInSingleBatch);
            }
            var availableMemoryForRaisingIndexBatchSizeLimit = Settings["Raven/AvailableMemoryForRaisingIndexBatchSizeLimit"];

            if (availableMemoryForRaisingIndexBatchSizeLimit != null)
            {
                AvailableMemoryForRaisingIndexBatchSizeLimit = int.Parse(availableMemoryForRaisingIndexBatchSizeLimit);
            }
            var initialNumberOfItemsToIndexInSingleBatch = Settings["Raven/InitialNumberOfItemsToIndexInSingleBatch"];

            if (initialNumberOfItemsToIndexInSingleBatch != null)
            {
                InitialNumberOfItemsToIndexInSingleBatch = Math.Min(int.Parse(initialNumberOfItemsToIndexInSingleBatch),
                                                                    MaxNumberOfItemsToIndexInSingleBatch);
            }
            var maxNumberOfItemsToReduceInSingleBatch = Settings["Raven/MaxNumberOfItemsToReduceInSingleBatch"];

            if (maxNumberOfItemsToReduceInSingleBatch != null)
            {
                MaxNumberOfItemsToReduceInSingleBatch     = Math.Max(int.Parse(maxNumberOfItemsToReduceInSingleBatch), 128);
                InitialNumberOfItemsToReduceInSingleBatch = Math.Min(MaxNumberOfItemsToReduceInSingleBatch,
                                                                     InitialNumberOfItemsToReduceInSingleBatch);
            }
            var numberOfItemsToExecuteReduceInSingleStep = Settings["Raven/NumberOfItemsToExecuteReduceInSingleStep"];

            if (numberOfItemsToExecuteReduceInSingleStep != null)
            {
                NumberOfItemsToExecuteReduceInSingleStep = int.Parse(numberOfItemsToExecuteReduceInSingleStep);
            }

            var initialNumberOfItemsToReduceInSingleBatch = Settings["Raven/InitialNumberOfItemsToReduceInSingleBatch"];

            if (initialNumberOfItemsToReduceInSingleBatch != null)
            {
                InitialNumberOfItemsToReduceInSingleBatch = Math.Min(int.Parse(initialNumberOfItemsToReduceInSingleBatch),
                                                                     MaxNumberOfItemsToReduceInSingleBatch);
            }

            var maxNumberOfParallelIndexTasks = Settings["Raven/MaxNumberOfParallelIndexTasks"];

            MaxNumberOfParallelIndexTasks = maxNumberOfParallelIndexTasks != null?int.Parse(maxNumberOfParallelIndexTasks) : Environment.ProcessorCount;

            MaxNumberOfParallelIndexTasks = Math.Max(1, MaxNumberOfParallelIndexTasks);

            var minimumQueryCount = Settings["Raven/TempIndexPromotionMinimumQueryCount"];

            TempIndexPromotionMinimumQueryCount = minimumQueryCount != null?int.Parse(minimumQueryCount) : 100;

            var queryThreshold = Settings["Raven/TempIndexPromotionThreshold"];

            TempIndexPromotionThreshold = queryThreshold != null?int.Parse(queryThreshold) : 60000;               // once a minute

            var cleanupPeriod = Settings["Raven/TempIndexCleanupPeriod"];

            TempIndexCleanupPeriod = cleanupPeriod != null?TimeSpan.FromSeconds(int.Parse(cleanupPeriod)) : TimeSpan.FromMinutes(10);

            var cleanupThreshold = Settings["Raven/TempIndexCleanupThreshold"];

            TempIndexCleanupThreshold = cleanupThreshold != null?TimeSpan.FromSeconds(int.Parse(cleanupThreshold)) : TimeSpan.FromMinutes(20);

            var tempMemoryMaxMb = Settings["Raven/TempIndexInMemoryMaxMB"];

            TempIndexInMemoryMaxBytes = tempMemoryMaxMb != null?int.Parse(tempMemoryMaxMb) * 1024 * 1024 : 26214400;

            TempIndexInMemoryMaxBytes = Math.Max(1024 * 1024, TempIndexInMemoryMaxBytes);

            // Data settings
            RunInMemory = GetConfigurationValue <bool>("Raven/RunInMemory") ?? false;
            if (string.IsNullOrEmpty(DefaultStorageTypeName))
            {
                DefaultStorageTypeName = Settings["Raven/StorageTypeName"] ?? Settings["Raven/StorageEngine"] ?? "esent";
            }

            CreateTemporaryIndexesForAdHocQueriesIfNeeded =
                GetConfigurationValue <bool>("Raven/CreateTemporaryIndexesForAdHocQueriesIfNeeded") ?? true;

            ResetIndexOnUncleanShutdown = GetConfigurationValue <bool>("Raven/ResetIndexOnUncleanShutdown") ?? false;

            SetupTransactionMode();

            DataDirectory = Settings["Raven/DataDir"] ?? @"~\Data";

            if (string.IsNullOrEmpty(Settings["Raven/IndexStoragePath"]) == false)
            {
                IndexStoragePath = Settings["Raven/IndexStoragePath"];
            }

            // HTTP settings
            HostName = Settings["Raven/HostName"];
            if (string.IsNullOrEmpty(DatabaseName))             // we only use this for root database
            {
                Port = PortUtil.GetPort(Settings["Raven/Port"]);
            }
            SetVirtualDirectory();

            bool httpCompressionTemp;

            if (bool.TryParse(Settings["Raven/HttpCompression"], out httpCompressionTemp) == false)
            {
                httpCompressionTemp = true;
            }
            HttpCompression = httpCompressionTemp;

            AccessControlAllowOrigin    = Settings["Raven/AccessControlAllowOrigin"];
            AccessControlMaxAge         = Settings["Raven/AccessControlMaxAge"] ?? "1728000";     // 20 days
            AccessControlAllowMethods   = Settings["Raven/AccessControlAllowMethods"] ?? "PUT,PATCH,GET,DELETE,POST";
            AccessControlRequestHeaders = Settings["Raven/AccessControlRequestHeaders"];

            AnonymousUserAccessMode = GetAnonymousUserAccessMode();

            RedirectStudioUrl = Settings["Raven/RedirectStudioUrl"];

            DisableDocumentPreFetchingForIndexing = GetConfigurationValue <bool>("Raven/DisableDocumentPreFetchingForIndexing") ??
                                                    false;

            // Misc settings
            WebDir = Settings["Raven/WebDir"] ?? GetDefaultWebDir();

            PluginsDirectory = (Settings["Raven/PluginsDirectory"] ?? @"~\Plugins").ToFullPath();

            var taskSchedulerType = Settings["Raven/TaskScheduler"];

            if (taskSchedulerType != null)
            {
                var type = Type.GetType(taskSchedulerType);
                CustomTaskScheduler = (TaskScheduler)Activator.CreateInstance(type);
            }

            AllowLocalAccessWithoutAuthorization = GetConfigurationValue <bool>("Raven/AllowLocalAccessWithoutAuthorization") ?? false;

            PostInit();
        }
Exemple #3
0
        public void Initialize()
        {
            // Core settings
            var maxPageSizeStr = Settings["Raven/MaxPageSize"];

            MaxPageSize = maxPageSizeStr != null?int.Parse(maxPageSizeStr) : 1024;

            MaxPageSize = Math.Max(MaxPageSize, 10);

            var backgroundTasksPriority = Settings["Raven/BackgroundTasksPriority"];

            BackgroundTasksPriority = backgroundTasksPriority == null
                                                                ? ThreadPriority.Normal
                                                                : (ThreadPriority)Enum.Parse(typeof(ThreadPriority), backgroundTasksPriority);

            var cacheMemoryLimitMegabytes = Settings["Raven/MemoryCacheLimitMegabytes"];

            MemoryCacheLimitMegabytes = cacheMemoryLimitMegabytes == null
                                                                                        ? GetDefaultMemoryCacheLimitMegabytes()
                                                                                        : int.Parse(cacheMemoryLimitMegabytes);

            var memoryCacheExpiration = Settings["Raven/MemoryCacheExpiration"];

            MemoryCacheExpiration = memoryCacheExpiration == null
                                                        ? TimeSpan.FromMinutes(5)
                                                        : TimeSpan.FromSeconds(int.Parse(memoryCacheExpiration));

            var memoryCacheLimitPercentage = Settings["Raven/MemoryCacheLimitPercentage"];

            MemoryCacheLimitPercentage = memoryCacheLimitPercentage == null
                                                                ? 0 // auto-size
                                                                : int.Parse(memoryCacheLimitPercentage);
            var memoryCacheLimitCheckInterval = Settings["Raven/MemoryCacheLimitCheckInterval"];

            MemoryCacheLimitCheckInterval = memoryCacheLimitCheckInterval == null
                                                                ? MemoryCache.Default.PollingInterval
                                                                : TimeSpan.Parse(memoryCacheLimitCheckInterval);

            // Index settings
            var maxNumberOfItemsToIndexInSingleBatch = Settings["Raven/MaxNumberOfItemsToIndexInSingleBatch"];

            MaxNumberOfItemsToIndexInSingleBatch = maxNumberOfItemsToIndexInSingleBatch != null?int.Parse(maxNumberOfItemsToIndexInSingleBatch) : 2500;

            MaxNumberOfItemsToIndexInSingleBatch = Math.Max(MaxNumberOfItemsToIndexInSingleBatch, 128);

            var maxNumberOfParallelIndexTasks = Settings["Raven/MaxNumberOfParallelIndexTasks"];

            MaxNumberOfParallelIndexTasks = maxNumberOfParallelIndexTasks != null?int.Parse(maxNumberOfParallelIndexTasks) : Environment.ProcessorCount;

            MaxNumberOfParallelIndexTasks = Math.Max(1, MaxNumberOfParallelIndexTasks);

            var minimumQueryCount = Settings["Raven/TempIndexPromotionMinimumQueryCount"];

            TempIndexPromotionMinimumQueryCount = minimumQueryCount != null?int.Parse(minimumQueryCount) : 100;

            var queryThreshold = Settings["Raven/TempIndexPromotionThreshold"];

            TempIndexPromotionThreshold = queryThreshold != null?int.Parse(queryThreshold) : 60000;               // once a minute

            var cleanupPeriod = Settings["Raven/TempIndexCleanupPeriod"];

            TempIndexCleanupPeriod = cleanupPeriod != null?TimeSpan.FromSeconds(int.Parse(cleanupPeriod)) : TimeSpan.FromMinutes(10);

            var cleanupThreshold = Settings["Raven/TempIndexCleanupThreshold"];

            TempIndexCleanupThreshold = cleanupThreshold != null?TimeSpan.FromSeconds(int.Parse(cleanupThreshold)) : TimeSpan.FromMinutes(20);

            var tempMemoryMaxMb = Settings["Raven/TempIndexInMemoryMaxMB"];

            TempIndexInMemoryMaxBytes = tempMemoryMaxMb != null?int.Parse(tempMemoryMaxMb) * 1024 * 1024 : 26214400;

            TempIndexInMemoryMaxBytes = Math.Max(1024 * 1024, TempIndexInMemoryMaxBytes);

            // Data settings
            RunInMemory            = GetConfigurationValue <bool>("Raven/RunInMemory") ?? false;
            DefaultStorageTypeName = Settings["Raven/StorageTypeName"] ?? Settings["Raven/StorageEngine"] ?? "esent";

            var             transactionMode = Settings["Raven/TransactionMode"];
            TransactionMode result;

            if (Enum.TryParse(transactionMode, true, out result) == false)
            {
                result = TransactionMode.Safe;
            }
            TransactionMode = result;

            DataDirectory = Settings["Raven/DataDir"] ?? @"~\Data";
            if (string.IsNullOrEmpty(Settings["Raven/IndexStoragePath"]) == false)
            {
                IndexStoragePath = Settings["Raven/IndexStoragePath"];
            }

            // HTTP settings
            HostName = Settings["Raven/HostName"];
            Port     = PortUtil.GetPort(Settings["Raven/Port"]);
            SetVirtualDirectory();

            bool httpCompressionTemp;

            if (bool.TryParse(Settings["Raven/HttpCompression"], out httpCompressionTemp) == false)
            {
                httpCompressionTemp = true;
            }
            HttpCompression = httpCompressionTemp;

            AccessControlAllowOrigin    = Settings["Raven/AccessControlAllowOrigin"];
            AccessControlMaxAge         = Settings["Raven/AccessControlMaxAge"] ?? "1728000";     // 20 days
            AccessControlAllowMethods   = Settings["Raven/AccessControlAllowMethods"] ?? "PUT,PATCH,GET,DELETE,POST";
            AccessControlRequestHeaders = Settings["Raven/AccessControlRequestHeaders"];

            AnonymousUserAccessMode = GetAnonymousUserAccessMode();

            // Misc settings
            WebDir = Settings["Raven/WebDir"] ?? GetDefaultWebDir();

            PluginsDirectory = (Settings["Raven/PluginsDirectory"] ?? @"~\Plugins").ToFullPath();

            // OAuth
            AuthenticationMode = Settings["Raven/AuthenticationMode"] ?? AuthenticationMode ?? "windows";
            if (string.Equals(AuthenticationMode, "oauth", StringComparison.InvariantCultureIgnoreCase))
            {
                SetupOAuth();
            }
        }
        public void Initialize()
        {
            // Core settings
            var maxPageSizeStr = Settings["Raven/MaxPageSize"];

            MaxPageSize = maxPageSizeStr != null?int.Parse(maxPageSizeStr) : 1024;

            MaxPageSize = Math.Max(MaxPageSize, 10);

            var backgroundTasksPriority = Settings["Raven/BackgroundTasksPriority"];

            BackgroundTasksPriority = backgroundTasksPriority == null
                                                                ? ThreadPriority.Normal
                                                                : (ThreadPriority)Enum.Parse(typeof(ThreadPriority), backgroundTasksPriority);

            var cacheMemoryLimitMegabytes = Settings["Raven/MemoryCacheLimitMegabytes"];

            MemoryCacheLimitMegabytes = cacheMemoryLimitMegabytes == null
                                                                                        ? GetDefaultMemoryCacheLimitMegabytes()
                                                        : int.Parse(cacheMemoryLimitMegabytes);



            var memoryCacheLimitPercentage = Settings["Raven/MemoryCacheLimitPercentage"];

            MemoryCacheLimitPercentage = memoryCacheLimitPercentage == null
                                                                ? 0 // auto-size
                                                                : int.Parse(memoryCacheLimitPercentage);
            var memoryCacheLimitCheckInterval = Settings["Raven/MemoryCacheLimitCheckInterval"];

            MemoryCacheLimitCheckInterval = memoryCacheLimitCheckInterval == null
                                                                ? MemoryCache.Default.PollingInterval
                                                                : TimeSpan.Parse(memoryCacheLimitCheckInterval);

            // Index settings
            var maxNumberOfItemsToIndexInSingleBatch = Settings["Raven/MaxNumberOfItemsToIndexInSingleBatch"];

            MaxNumberOfItemsToIndexInSingleBatch = maxNumberOfItemsToIndexInSingleBatch != null?int.Parse(maxNumberOfItemsToIndexInSingleBatch) : 2500;

            MaxNumberOfItemsToIndexInSingleBatch = Math.Max(MaxNumberOfItemsToIndexInSingleBatch, 128);

            var maxNumberOfParallelIndexTasks = Settings["Raven/MaxNumberOfParallelIndexTasks"];

            MaxNumberOfParallelIndexTasks = maxNumberOfParallelIndexTasks != null?int.Parse(maxNumberOfParallelIndexTasks) : Environment.ProcessorCount;

            MaxNumberOfParallelIndexTasks = Math.Max(1, MaxNumberOfParallelIndexTasks);

            var minimumQueryCount = Settings["Raven/TempIndexPromotionMinimumQueryCount"];

            TempIndexPromotionMinimumQueryCount = minimumQueryCount != null?int.Parse(minimumQueryCount) : 100;

            var queryThreshold = Settings["Raven/TempIndexPromotionThreshold"];

            TempIndexPromotionThreshold = queryThreshold != null?int.Parse(queryThreshold) : 60000;               // once a minute

            var cleanupPeriod = Settings["Raven/TempIndexCleanupPeriod"];

            TempIndexCleanupPeriod = cleanupPeriod != null?TimeSpan.FromSeconds(int.Parse(cleanupPeriod)) : TimeSpan.FromMinutes(10);

            var cleanupThreshold = Settings["Raven/TempIndexCleanupThreshold"];

            TempIndexCleanupThreshold = cleanupThreshold != null?TimeSpan.FromSeconds(int.Parse(cleanupThreshold)) : TimeSpan.FromMinutes(20);

            var tempMemoryMaxMb = Settings["Raven/TempIndexInMemoryMaxMB"];

            TempIndexInMemoryMaxBytes = tempMemoryMaxMb != null?int.Parse(tempMemoryMaxMb) * 1024000 : 26214400;

            TempIndexInMemoryMaxBytes = Math.Max(1024000, TempIndexInMemoryMaxBytes);

            // Data settings
            RunInMemory            = GetConfigurationValue <bool>("Raven/RunInMemory") ?? false;
            DefaultStorageTypeName = Settings["Raven/StorageTypeName"] ?? Settings["Raven/StorageEngine"] ?? "esent";

            var             transactionMode = Settings["Raven/TransactionMode"];
            TransactionMode result;

            if (Enum.TryParse(transactionMode, true, out result) == false)
            {
                result = TransactionMode.Safe;
            }
            TransactionMode = result;

            DataDirectory = Settings["Raven/DataDir"] ?? @"~\Data";
            if (string.IsNullOrEmpty(Settings["Raven/IndexStoragePath"]) == false)
            {
                IndexStoragePath = Settings["Raven/IndexStoragePath"];
            }

            // HTTP settings
            HostName         = Settings["Raven/HostName"];
            Port             = PortUtil.GetPort(Settings["Raven/Port"]);
            VirtualDirectory = Settings["Raven/VirtualDirectory"] ?? "/";

            if (VirtualDirectory.EndsWith("/"))
            {
                VirtualDirectory = VirtualDirectory.Substring(0, VirtualDirectory.Length - 1);
            }
            if (VirtualDirectory.StartsWith("/") == false)
            {
                VirtualDirectory = "/" + VirtualDirectory;
            }

            bool httpCompressionTemp;

            if (bool.TryParse(Settings["Raven/HttpCompression"], out httpCompressionTemp) == false)
            {
                httpCompressionTemp = true;
            }
            HttpCompression = httpCompressionTemp;

            AccessControlAllowOrigin = Settings["Raven/AccessControlAllowOrigin"];

            AnonymousUserAccessMode = GetAnonymousUserAccessMode();

            // Misc settings
            WebDir = Settings["Raven/WebDir"] ?? GetDefaultWebDir();

            PluginsDirectory = Settings["Raven/PluginsDirectory"] ?? @"~\Plugins";
            if (PluginsDirectory.StartsWith(@"~\"))
            {
                PluginsDirectory = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, PluginsDirectory.Substring(2));
            }

            // OAuth
            AuthenticationMode = Settings["Raven/AuthenticationMode"] ?? "windows";
        }
        public void Initialize()
        {
            int defaultMaxNumberOfItemsToIndexInSingleBatch     = Environment.Is64BitProcess ? 128 * 1024 : 16 * 1024;
            int defaultInitialNumberOfItemsToIndexInSingleBatch = Environment.Is64BitProcess ? 512 : 256;

            var ravenSettings = new StronglyTypedRavenSettings(Settings);

            ravenSettings.Setup(defaultMaxNumberOfItemsToIndexInSingleBatch, defaultInitialNumberOfItemsToIndexInSingleBatch);

            // Core settings
            MaxPageSize = ravenSettings.MaxPageSize.Value;

            MemoryCacheLimitMegabytes = ravenSettings.MemoryCacheLimitMegabytes.Value;

            MemoryCacheExpiration = ravenSettings.MemoryCacheExpiration.Value;

            MemoryCacheLimitPercentage = ravenSettings.MemoryCacheLimitPercentage.Value;

            MemoryCacheLimitCheckInterval = ravenSettings.MemoryCacheLimitCheckInterval.Value;

            // Discovery
            DisableClusterDiscovery = ravenSettings.DisableClusterDiscovery.Value;

            // TODO: Validate the cluster name. Valid names are only valid chars in documents IDs.
            ClusterName = ravenSettings.ClusterName.Value;

            ServerName = ravenSettings.ServerName.Value;

            MaxStepsForScript = ravenSettings.MaxStepsForScript.Value;
            AdditionalStepsForScriptBasedOnDocumentSize = ravenSettings.AdditionalStepsForScriptBasedOnDocumentSize.Value;

            // Index settings
            MaxIndexingRunLatency        = ravenSettings.MaxIndexingRunLatency.Value;
            MaxIndexWritesBeforeRecreate = ravenSettings.MaxIndexWritesBeforeRecreate.Value;

            MaxNumberOfItemsToIndexInSingleBatch = ravenSettings.MaxNumberOfItemsToIndexInSingleBatch.Value;

            var initialNumberOfItemsToIndexInSingleBatch = Settings["Raven/InitialNumberOfItemsToIndexInSingleBatch"];

            if (initialNumberOfItemsToIndexInSingleBatch != null)
            {
                InitialNumberOfItemsToIndexInSingleBatch = Math.Min(int.Parse(initialNumberOfItemsToIndexInSingleBatch),
                                                                    MaxNumberOfItemsToIndexInSingleBatch);
            }
            else
            {
                InitialNumberOfItemsToIndexInSingleBatch = MaxNumberOfItemsToIndexInSingleBatch == ravenSettings.MaxNumberOfItemsToIndexInSingleBatch.Default ?
                                                           defaultInitialNumberOfItemsToIndexInSingleBatch :
                                                           Math.Max(16, Math.Min(MaxNumberOfItemsToIndexInSingleBatch / 256, defaultInitialNumberOfItemsToIndexInSingleBatch));
            }
            AvailableMemoryForRaisingIndexBatchSizeLimit = ravenSettings.AvailableMemoryForRaisingIndexBatchSizeLimit.Value;



            MaxNumberOfItemsToReduceInSingleBatch     = ravenSettings.MaxNumberOfItemsToReduceInSingleBatch.Value;
            InitialNumberOfItemsToReduceInSingleBatch = MaxNumberOfItemsToReduceInSingleBatch == ravenSettings.MaxNumberOfItemsToReduceInSingleBatch.Default ?
                                                        defaultInitialNumberOfItemsToIndexInSingleBatch / 2 :
                                                        Math.Max(16, Math.Min(MaxNumberOfItemsToIndexInSingleBatch / 256, defaultInitialNumberOfItemsToIndexInSingleBatch / 2));

            NumberOfItemsToExecuteReduceInSingleStep = ravenSettings.NumberOfItemsToExecuteReduceInSingleStep.Value;

            var initialNumberOfItemsToReduceInSingleBatch = Settings["Raven/InitialNumberOfItemsToReduceInSingleBatch"];

            if (initialNumberOfItemsToReduceInSingleBatch != null)
            {
                InitialNumberOfItemsToReduceInSingleBatch = Math.Min(int.Parse(initialNumberOfItemsToReduceInSingleBatch),
                                                                     MaxNumberOfItemsToReduceInSingleBatch);
            }

            MaxNumberOfParallelIndexTasks = ravenSettings.MaxNumberOfParallelIndexTasks.Value;

            NewIndexInMemoryMaxBytes = ravenSettings.NewIndexInMemoryMaxMb.Value;

            MaxIndexCommitPointStoreTimeInterval = ravenSettings.MaxIndexCommitPointStoreTimeInterval.Value;

            MinIndexingTimeIntervalToStoreCommitPoint = ravenSettings.MinIndexingTimeIntervalToStoreCommitPoint.Value;

            MaxNumberOfStoredCommitPoints = ravenSettings.MaxNumberOfStoredCommitPoints.Value;

            // Data settings
            RunInMemory = ravenSettings.RunInMemory.Value;

            if (string.IsNullOrEmpty(DefaultStorageTypeName))
            {
                DefaultStorageTypeName = Settings["Raven/StorageTypeName"] ?? Settings["Raven/StorageEngine"] ?? "esent";
            }

            CreateAutoIndexesForAdHocQueriesIfNeeded = ravenSettings.CreateAutoIndexesForAdHocQueriesIfNeeded.Value;

            TimeToWaitBeforeRunningIdleIndexes     = ravenSettings.TimeToWaitBeforeRunningIdleIndexes.Value;
            TimeToWaitBeforeMarkingAutoIndexAsIdle = ravenSettings.TimeToWaitBeforeMarkingAutoIndexAsIdle.Value;

            TimeToWaitBeforeMarkingIdleIndexAsAbandoned = ravenSettings.TimeToWaitBeforeMarkingIdleIndexAsAbandoned.Value;
            TimeToWaitBeforeRunningAbandonedIndexes     = ravenSettings.TimeToWaitBeforeRunningAbandonedIndexes.Value;

            ResetIndexOnUncleanShutdown = ravenSettings.ResetIndexOnUncleanShutdown.Value;

            SetupTransactionMode();

            DataDirectory = ravenSettings.DataDir.Value;

            var indexStoragePathSettingValue = ravenSettings.IndexStoragePath.Value;

            if (string.IsNullOrEmpty(indexStoragePathSettingValue) == false)
            {
                IndexStoragePath = indexStoragePathSettingValue;
            }

            // HTTP settings
            HostName = ravenSettings.HostName.Value;

            if (string.IsNullOrEmpty(DatabaseName))             // we only use this for root database
            {
                Port   = PortUtil.GetPort(ravenSettings.Port.Value);
                UseSsl = ravenSettings.UseSsl.Value;
            }

            SetVirtualDirectory();

            HttpCompression = ravenSettings.HttpCompression.Value;

            AccessControlAllowOrigin    = ravenSettings.AccessControlAllowOrigin.Value;
            AccessControlMaxAge         = ravenSettings.AccessControlMaxAge.Value;
            AccessControlAllowMethods   = ravenSettings.AccessControlAllowMethods.Value;
            AccessControlRequestHeaders = ravenSettings.AccessControlRequestHeaders.Value;

            AnonymousUserAccessMode = GetAnonymousUserAccessMode();

            RedirectStudioUrl = ravenSettings.RedirectStudioUrl.Value;

            DisableDocumentPreFetchingForIndexing = ravenSettings.DisableDocumentPreFetchingForIndexing.Value;

            MaxNumberOfItemsToPreFetchForIndexing = ravenSettings.MaxNumberOfItemsToPreFetchForIndexing.Value;

            // Misc settings
            WebDir = ravenSettings.WebDir.Value;

            PluginsDirectory = ravenSettings.PluginsDirectory.Value.ToFullPath();

            CompiledIndexCacheDirectory = ravenSettings.CompiledIndexCacheDirectory.Value.ToFullPath();

            var taskSchedulerType = ravenSettings.TaskScheduler.Value;

            if (taskSchedulerType != null)
            {
                var type = Type.GetType(taskSchedulerType);
                CustomTaskScheduler = (TaskScheduler)Activator.CreateInstance(type);
            }

            AllowLocalAccessWithoutAuthorization = ravenSettings.AllowLocalAccessWithoutAuthorization.Value;

            PostInit();
        }
        public void Initialize()
        {
            int defaultMaxNumberOfItemsToIndexInSingleBatch     = Environment.Is64BitProcess ? 128 * 1024 : 16 * 1024;
            int defaultInitialNumberOfItemsToIndexInSingleBatch = Environment.Is64BitProcess ? 512 : 256;

            var ravenSettings = new StronglyTypedRavenSettings(Settings);

            ravenSettings.Setup(defaultMaxNumberOfItemsToIndexInSingleBatch, defaultInitialNumberOfItemsToIndexInSingleBatch);

            // Important! this value is synchronized with the max sessions number in esent
            // since we cannot have more requests in the system than we have sessions for them
            // and we also need to allow sessions for background operations and for multi get requests
            MaxConcurrentServerRequests = ravenSettings.MaxConcurrentServerRequests.Value;

            MaxConcurrentMultiGetRequests = ravenSettings.MaxConcurrentMultiGetRequests.Value;
            if (ConcurrentMultiGetRequests == null)
            {
                ConcurrentMultiGetRequests = new SemaphoreSlim(MaxConcurrentMultiGetRequests);
            }

            MemoryLimitForIndexingInMB = ravenSettings.MemoryLimitForIndexing.Value;

            EncryptionKeyBitsPreference = ravenSettings.EncryptionKeyBitsPreference.Value;
            // Core settings
            MaxPageSize = ravenSettings.MaxPageSize.Value;

            MemoryCacheLimitMegabytes = ravenSettings.MemoryCacheLimitMegabytes.Value;

            MemoryCacheExpiration = ravenSettings.MemoryCacheExpiration.Value;

            MemoryCacheLimitPercentage = ravenSettings.MemoryCacheLimitPercentage.Value;

            MemoryCacheLimitCheckInterval = ravenSettings.MemoryCacheLimitCheckInterval.Value;

            // Discovery
            DisableClusterDiscovery = ravenSettings.DisableClusterDiscovery.Value;

            // TODO: Validate the cluster name. Valid names are only valid chars in documents IDs.
            ClusterName = ravenSettings.ClusterName.Value;

            ServerName = ravenSettings.ServerName.Value;

            MaxStepsForScript = ravenSettings.MaxStepsForScript.Value;
            AdditionalStepsForScriptBasedOnDocumentSize = ravenSettings.AdditionalStepsForScriptBasedOnDocumentSize.Value;

            // Index settings
            MaxIndexingRunLatency        = ravenSettings.MaxIndexingRunLatency.Value;
            MaxIndexWritesBeforeRecreate = ravenSettings.MaxIndexWritesBeforeRecreate.Value;

            PreventAutomaticSuggestionCreation = ravenSettings.PreventAutomaticSuggestionCreation.Value;

            DisablePerformanceCounters = ravenSettings.DisablePerformanceCounters.Value;

            PrewarmFacetsOnIndexingMaxAge   = ravenSettings.PrewarmFacetsOnIndexingMaxAge.Value;
            PrewarmFacetsSyncronousWaitTime = ravenSettings.PrewarmFacetsSyncronousWaitTime.Value;

            MaxNumberOfItemsToIndexInSingleBatch = ravenSettings.MaxNumberOfItemsToIndexInSingleBatch.Value;
            FlushIndexToDiskSizeInMb             = ravenSettings.FlushIndexToDiskSizeInMb.Value;

            var initialNumberOfItemsToIndexInSingleBatch = Settings["Raven/InitialNumberOfItemsToIndexInSingleBatch"];

            if (initialNumberOfItemsToIndexInSingleBatch != null)
            {
                InitialNumberOfItemsToIndexInSingleBatch = Math.Min(int.Parse(initialNumberOfItemsToIndexInSingleBatch),
                                                                    MaxNumberOfItemsToIndexInSingleBatch);
            }
            else
            {
                InitialNumberOfItemsToIndexInSingleBatch = MaxNumberOfItemsToIndexInSingleBatch == ravenSettings.MaxNumberOfItemsToIndexInSingleBatch.Default ?
                                                           defaultInitialNumberOfItemsToIndexInSingleBatch :
                                                           Math.Max(16, Math.Min(MaxNumberOfItemsToIndexInSingleBatch / 256, defaultInitialNumberOfItemsToIndexInSingleBatch));
            }
            AvailableMemoryForRaisingIndexBatchSizeLimit = ravenSettings.AvailableMemoryForRaisingIndexBatchSizeLimit.Value;

            MaxNumberOfItemsToReduceInSingleBatch     = ravenSettings.MaxNumberOfItemsToReduceInSingleBatch.Value;
            InitialNumberOfItemsToReduceInSingleBatch = MaxNumberOfItemsToReduceInSingleBatch == ravenSettings.MaxNumberOfItemsToReduceInSingleBatch.Default ?
                                                        defaultInitialNumberOfItemsToIndexInSingleBatch / 2 :
                                                        Math.Max(16, Math.Min(MaxNumberOfItemsToIndexInSingleBatch / 256, defaultInitialNumberOfItemsToIndexInSingleBatch / 2));

            NumberOfItemsToExecuteReduceInSingleStep = ravenSettings.NumberOfItemsToExecuteReduceInSingleStep.Value;

            var initialNumberOfItemsToReduceInSingleBatch = Settings["Raven/InitialNumberOfItemsToReduceInSingleBatch"];

            if (initialNumberOfItemsToReduceInSingleBatch != null)
            {
                InitialNumberOfItemsToReduceInSingleBatch = Math.Min(int.Parse(initialNumberOfItemsToReduceInSingleBatch),
                                                                     MaxNumberOfItemsToReduceInSingleBatch);
            }

            MaxNumberOfParallelIndexTasks = ravenSettings.MaxNumberOfParallelIndexTasks.Value;

            NewIndexInMemoryMaxBytes = ravenSettings.NewIndexInMemoryMaxMb.Value;

            MaxIndexCommitPointStoreTimeInterval = ravenSettings.MaxIndexCommitPointStoreTimeInterval.Value;

            MinIndexingTimeIntervalToStoreCommitPoint = ravenSettings.MinIndexingTimeIntervalToStoreCommitPoint.Value;

            MaxNumberOfStoredCommitPoints = ravenSettings.MaxNumberOfStoredCommitPoints.Value;

            // Data settings
            RunInMemory = ravenSettings.RunInMemory.Value;

            if (string.IsNullOrEmpty(DefaultStorageTypeName))
            {
                DefaultStorageTypeName = Settings["Raven/StorageTypeName"] ?? Settings["Raven/StorageEngine"] ?? "esent";
            }

            CreateAutoIndexesForAdHocQueriesIfNeeded = ravenSettings.CreateAutoIndexesForAdHocQueriesIfNeeded.Value;

            DatbaseOperationTimeout = ravenSettings.DatbaseOperationTimeout.Value;

            TimeToWaitBeforeRunningIdleIndexes     = ravenSettings.TimeToWaitBeforeRunningIdleIndexes.Value;
            TimeToWaitBeforeMarkingAutoIndexAsIdle = ravenSettings.TimeToWaitBeforeMarkingAutoIndexAsIdle.Value;

            TimeToWaitBeforeMarkingIdleIndexAsAbandoned = ravenSettings.TimeToWaitBeforeMarkingIdleIndexAsAbandoned.Value;
            TimeToWaitBeforeRunningAbandonedIndexes     = ravenSettings.TimeToWaitBeforeRunningAbandonedIndexes.Value;

            ResetIndexOnUncleanShutdown = ravenSettings.ResetIndexOnUncleanShutdown.Value;
            DisableInMemoryIndexing     = ravenSettings.DisableInMemoryIndexing.Value;

            SetupTransactionMode();

            DataDirectory = ravenSettings.DataDir.Value;

            var indexStoragePathSettingValue = ravenSettings.IndexStoragePath.Value;

            if (string.IsNullOrEmpty(indexStoragePathSettingValue) == false)
            {
                IndexStoragePath = indexStoragePathSettingValue;
            }

            MaxRecentTouchesToRemember = ravenSettings.MaxRecentTouchesToRemember.Value;

            // HTTP settings
            HostName = ravenSettings.HostName.Value;

            if (string.IsNullOrEmpty(DatabaseName))             // we only use this for root database
            {
                Port   = PortUtil.GetPort(ravenSettings.Port.Value);
                UseSsl = ravenSettings.UseSsl.Value;
            }

            SetVirtualDirectory();

            HttpCompression = ravenSettings.HttpCompression.Value;

            AccessControlAllowOrigin    = ravenSettings.AccessControlAllowOrigin.Value;
            AccessControlMaxAge         = ravenSettings.AccessControlMaxAge.Value;
            AccessControlAllowMethods   = ravenSettings.AccessControlAllowMethods.Value;
            AccessControlRequestHeaders = ravenSettings.AccessControlRequestHeaders.Value;

            AnonymousUserAccessMode = GetAnonymousUserAccessMode();

            RedirectStudioUrl = ravenSettings.RedirectStudioUrl.Value;

            DisableDocumentPreFetchingForIndexing = ravenSettings.DisableDocumentPreFetchingForIndexing.Value;

            MaxNumberOfItemsToPreFetchForIndexing = ravenSettings.MaxNumberOfItemsToPreFetchForIndexing.Value;

            // Misc settings
            WebDir = ravenSettings.WebDir.Value;

            PluginsDirectory = ravenSettings.PluginsDirectory.Value.ToFullPath();

            CompiledIndexCacheDirectory = ravenSettings.CompiledIndexCacheDirectory.Value.ToFullPath();

            var taskSchedulerType = ravenSettings.TaskScheduler.Value;

            if (taskSchedulerType != null)
            {
                var type = Type.GetType(taskSchedulerType);
                CustomTaskScheduler = (TaskScheduler)Activator.CreateInstance(type);
            }

            AllowLocalAccessWithoutAuthorization = ravenSettings.AllowLocalAccessWithoutAuthorization.Value;

            FetchingDocumentsFromDiskTimeoutInSeconds = ravenSettings.FetchingDocumentsFromDiskTimeoutInSeconds.Value;
            MaximumSizeAllowedToFetchFromStorageInMb  = ravenSettings.MaximumSizeAllowedToFetchFromStorageInMb.Value;

            PostInit();
        }
        public void Initialize()
        {
            int defaultMaxNumberOfItemsToIndexInSingleBatch     = Environment.Is64BitProcess ? 128 * 1024 : 64 * 1024;
            int defaultInitialNumberOfItemsToIndexInSingleBatch = Environment.Is64BitProcess ? 512 : 256;

            var ravenSettings = new StronglyTypedRavenSettings(Settings);

            ravenSettings.Setup(defaultMaxNumberOfItemsToIndexInSingleBatch, defaultInitialNumberOfItemsToIndexInSingleBatch);

            // Core settings
            MaxPageSize = ravenSettings.MaxPageSize.Value;

            MemoryCacheLimitMegabytes = ravenSettings.MemoryCacheLimitMegabytes.Value;

            MemoryCacheExpiration = ravenSettings.MemoryCacheExpiration.Value;

            MemoryCacheLimitPercentage = ravenSettings.MemoryCacheLimitPercentage.Value;

            MemoryCacheLimitCheckInterval = ravenSettings.MemoryCacheLimitCheckInterval.Value;

            // Index settings
            MaxIndexingRunLatency = ravenSettings.MaxIndexingRunLatency.Value;

            MaxNumberOfItemsToIndexInSingleBatch = ravenSettings.MaxNumberOfItemsToIndexInSingleBatch.Value;

            var initialNumberOfItemsToIndexInSingleBatch = Settings["Raven/InitialNumberOfItemsToIndexInSingleBatch"];

            if (initialNumberOfItemsToIndexInSingleBatch != null)
            {
                InitialNumberOfItemsToIndexInSingleBatch = Math.Min(int.Parse(initialNumberOfItemsToIndexInSingleBatch),
                                                                    MaxNumberOfItemsToIndexInSingleBatch);
            }
            else
            {
                InitialNumberOfItemsToIndexInSingleBatch = MaxNumberOfItemsToIndexInSingleBatch == ravenSettings.MaxNumberOfItemsToIndexInSingleBatch.Default ?
                                                           defaultInitialNumberOfItemsToIndexInSingleBatch :
                                                           Math.Max(16, Math.Min(MaxNumberOfItemsToIndexInSingleBatch / 256, defaultInitialNumberOfItemsToIndexInSingleBatch));
            }
            AvailableMemoryForRaisingIndexBatchSizeLimit = ravenSettings.AvailableMemoryForRaisingIndexBatchSizeLimit.Value;



            MaxNumberOfItemsToReduceInSingleBatch     = ravenSettings.MaxNumberOfItemsToReduceInSingleBatch.Value;
            InitialNumberOfItemsToReduceInSingleBatch = MaxNumberOfItemsToReduceInSingleBatch == ravenSettings.MaxNumberOfItemsToReduceInSingleBatch.Default?
                                                        defaultInitialNumberOfItemsToIndexInSingleBatch / 2 :
                                                        Math.Max(16, Math.Min(MaxNumberOfItemsToIndexInSingleBatch / 256, defaultInitialNumberOfItemsToIndexInSingleBatch / 2));

            NumberOfItemsToExecuteReduceInSingleStep = ravenSettings.NumberOfItemsToExecuteReduceInSingleStep.Value;

            var initialNumberOfItemsToReduceInSingleBatch = Settings["Raven/InitialNumberOfItemsToReduceInSingleBatch"];

            if (initialNumberOfItemsToReduceInSingleBatch != null)
            {
                InitialNumberOfItemsToReduceInSingleBatch = Math.Min(int.Parse(initialNumberOfItemsToReduceInSingleBatch),
                                                                     MaxNumberOfItemsToReduceInSingleBatch);
            }

            MaxNumberOfParallelIndexTasks = ravenSettings.MaxNumberOfParallelIndexTasks.Value;

            TempIndexPromotionMinimumQueryCount = ravenSettings.TempIndexPromotionMinimumQueryCount.Value;

            TempIndexPromotionThreshold = ravenSettings.TempIndexPromotionThreshold.Value;

            TempIndexCleanupPeriod = ravenSettings.TempIndexCleanupPeriod.Value;

            TempIndexCleanupThreshold = ravenSettings.TempIndexCleanupThreshold.Value;

            TempIndexInMemoryMaxBytes = ravenSettings.TempIndexInMemoryMaxMb.Value;

            // Data settings
            RunInMemory = ravenSettings.RunInMemory.Value;

            if (string.IsNullOrEmpty(DefaultStorageTypeName))
            {
                DefaultStorageTypeName = Settings["Raven/StorageTypeName"] ?? Settings["Raven/StorageEngine"] ?? "esent";
            }

            CreateTemporaryIndexesForAdHocQueriesIfNeeded = ravenSettings.CreateTemporaryIndexesForAdHocQueriesIfNeeded.Value;

            ResetIndexOnUncleanShutdown = ravenSettings.ResetIndexOnUncleanShutdown.Value;

            SetupTransactionMode();

            DataDirectory = ravenSettings.DataDir.Value;

            var indexStoragePathSettingValue = ravenSettings.IndexStoragePath.Value;

            if (string.IsNullOrEmpty(indexStoragePathSettingValue) == false)
            {
                IndexStoragePath = indexStoragePathSettingValue;
            }

            // HTTP settings
            HostName = ravenSettings.HostName.Value;

            if (string.IsNullOrEmpty(DatabaseName))             // we only use this for root database
            {
                Port = PortUtil.GetPort(ravenSettings.Port.Value);
            }
            SetVirtualDirectory();

            HttpCompression = ravenSettings.HttpCompression.Value;

            AccessControlAllowOrigin    = ravenSettings.AccessControlAllowOrigin.Value;
            AccessControlMaxAge         = ravenSettings.AccessControlMaxAge.Value;
            AccessControlAllowMethods   = ravenSettings.AccessControlAllowMethods.Value;
            AccessControlRequestHeaders = ravenSettings.AccessControlRequestHeaders.Value;

            AnonymousUserAccessMode = GetAnonymousUserAccessMode();

            RedirectStudioUrl = ravenSettings.RedirectStudioUrl.Value;

            DisableDocumentPreFetchingForIndexing = ravenSettings.DisableDocumentPreFetchingForIndexing.Value;

            // Misc settings
            WebDir = ravenSettings.WebDir.Value;

            PluginsDirectory = ravenSettings.PluginsDirectory.Value.ToFullPath();

            var taskSchedulerType = ravenSettings.TaskScheduler.Value;

            if (taskSchedulerType != null)
            {
                var type = Type.GetType(taskSchedulerType);
                CustomTaskScheduler = (TaskScheduler)Activator.CreateInstance(type);
            }

            AllowLocalAccessWithoutAuthorization = ravenSettings.AllowLocalAccessWithoutAuthorization.Value;

            PostInit();
        }