public RavenDBOptions(InMemoryRavenConfiguration configuration, DocumentDatabase db = null)
		{
			if (configuration == null)
				throw new ArgumentNullException("configuration");
			
			try
			{
				HttpEndpointRegistration.RegisterHttpEndpointTarget();
			    HttpEndpointRegistration.RegisterAdminLogsTarget();
				if (db == null)
				{
					configuration.UpdateDataDirForLegacySystemDb();
					systemDatabase = new DocumentDatabase(configuration);
					systemDatabase.SpinBackgroundWorkers();
				}
				else
				{
					systemDatabase = db;
				}
			    fileSystemLandlord = new FileSystemsLandlord(systemDatabase);
				databasesLandlord = new DatabasesLandlord(systemDatabase);
				countersLandlord = new CountersLandlord(systemDatabase);
				requestManager = new RequestManager(databasesLandlord);
				mixedModeRequestAuthorizer = new MixedModeRequestAuthorizer();
				mixedModeRequestAuthorizer.Initialize(systemDatabase, new RavenServer(databasesLandlord.SystemDatabase, configuration));
			}
			catch
			{
				if (systemDatabase != null)
					systemDatabase.Dispose();
				throw;
			}
		}
 public WebSocketsRequestParser(DatabasesLandlord databasesLandlord, CountersLandlord countersLandlord, FileSystemsLandlord fileSystemsLandlord, MixedModeRequestAuthorizer authorizer, string expectedRequestSuffix)
 {
     DatabasesLandlord = databasesLandlord;
     this.countersLandlord = countersLandlord;
     this.fileSystemsLandlord = fileSystemsLandlord;
     this.authorizer = authorizer;
     this.expectedRequestSuffix = expectedRequestSuffix;
 }
		private void CleanupFileSystems(DatabasesLandlord databaseLandlord, FileSystemsLandlord fileSystemLandlord)
		{
			var systemDatabase = databaseLandlord.SystemDatabase;

			int nextStart = 0;
			var fileSystemDocuments = systemDatabase
				.Documents
                .GetDocumentsWithIdStartingWith(Constants.FileSystem.Prefix, null, null, 0, int.MaxValue, CancellationToken.None, ref nextStart);

			var fileSystemIds = fileSystemDocuments
				.Select(x => ((RavenJObject)x)["@metadata"])
				.Where(x => x != null)
				.Select(x => x.Value<string>("@id"))
				.Where(x => x != null && x != Constants.SystemDatabase)
				.ToList();

			foreach (var fileSystemId in fileSystemIds)
			{
				try
				{
					var key = fileSystemId;
                    if (key.StartsWith(Constants.FileSystem.Prefix))
                        key = key.Substring(Constants.FileSystem.Prefix.Length);

					var shouldCleanup = false;

					DateTime value;
					if (fileSystemLandlord.IsFileSystemLoaded(key) == false) 
						shouldCleanup = true;
					else if (fileSystemLandlord.LastRecentlyUsed.TryGetValue(key, out value) == false || (SystemTime.UtcNow - value) > maxTimeResourceCanBeIdle) 
						shouldCleanup = true;

					if (shouldCleanup == false) 
						continue;

					var configuration = fileSystemLandlord.CreateTenantConfiguration(key, true);

					fileSystemLandlord.Cleanup(key, maxTimeResourceCanBeIdle, database => false);

                    var docKey = Constants.FileSystem.Prefix + key;
					systemDatabase.Documents.Delete(docKey, null, null);

					if (configuration == null)
						continue;

					IOExtensions.DeleteDirectory(configuration.FileSystem.DataDirectory);
				}
				catch (Exception e)
				{
					log.WarnException(string.Format("Failed to cleanup '{0}' filesystem.", fileSystemId), e);
				}
			}
		}
Example #4
0
		public RequestManager(DatabasesLandlord landlord)
		{

			BeforeRequest += OnBeforeRequest;
			cancellationTokenSource = new CancellationTokenSource();
			this.landlord = landlord;
			
			maxTimeDatabaseCanBeIdle = TimeSpan.FromSeconds(landlord.MaxIdleTimeForTenantDatabaseInSec);
			frequencyToCheckForIdleDatabases = TimeSpan.FromSeconds(landlord.FrequencyToCheckForIdleDatabasesInSec);

			Init();
			cancellationToken = cancellationTokenSource.Token;
		}
Example #5
0
	    public RequestManager(DatabasesLandlord landlord)
		{
            BeforeRequest+=OnBeforeRequest;
		    cancellationTokenSource = new CancellationTokenSource();
		    this.landlord = landlord;
			int val;
			if (int.TryParse(landlord.SystemConfiguration.Settings["Raven/Tenants/MaxIdleTimeForTenantDatabase"], out val) == false)
				val = 900;
			maxTimeDatabaseCanBeIdle = TimeSpan.FromSeconds(val);

			if (int.TryParse(landlord.SystemConfiguration.Settings["Raven/Tenants/FrequencyToCheckForIdleDatabases"], out val) == false)
				val = 60;
			frequencyToCheckForIdleDatabases = TimeSpan.FromSeconds(val);

			Init();
		    cancellationToken = cancellationTokenSource.Token;
		}
Example #6
0
        public RavenDBOptions(InMemoryRavenConfiguration configuration, DocumentDatabase db = null)
        {
            if (configuration == null)
                throw new ArgumentNullException("configuration");
            
            try
            {
                HttpEndpointRegistration.RegisterHttpEndpointTarget();
                HttpEndpointRegistration.RegisterAdminLogsTarget();
                ThreadPool.SetMinThreads(configuration.MinThreadPoolWorkerThreads, configuration.MinThreadPoolCompletionThreads);
                if (db == null)
                {
                    configuration.UpdateDataDirForLegacySystemDb();
                    systemDatabase = new DocumentDatabase(configuration);
                    systemDatabase.SpinBackgroundWorkers(false);
                }
                else
                {
                    systemDatabase = db;
                }

                WebSocketBufferPool.Initialize(configuration.WebSockets.InitialBufferPoolSize);
                fileSystemLandlord = new FileSystemsLandlord(systemDatabase);
                databasesLandlord = new DatabasesLandlord(systemDatabase);
                countersLandlord = new CountersLandlord(systemDatabase);
                requestManager = new RequestManager(databasesLandlord);
                mixedModeRequestAuthorizer = new MixedModeRequestAuthorizer();
                mixedModeRequestAuthorizer.Initialize(systemDatabase, new RavenServer(databasesLandlord.SystemDatabase, configuration));

                serverStartupTasks = configuration.Container.GetExportedValues<IServerStartupTask>();

                foreach (var task in serverStartupTasks)
                {
                    toDispose.Add(task);
                    task.Execute(this);
                }
            }
            catch
            {
                if (systemDatabase != null)
                    systemDatabase.Dispose();
                throw;
            }
        }
Example #7
0
		private static HttpConfiguration CreateHttpCfg(
            DatabasesLandlord databasesLandlord, 
            FileSystemsLandlord fileSystemsLandlord,
            MixedModeRequestAuthorizer mixedModeRequestAuthorizer, 
            RequestManager requestManager)
		{
			var cfg = new HttpConfiguration();
			cfg.Properties[typeof(DatabasesLandlord)] = databasesLandlord;
            cfg.Properties[typeof(FileSystemsLandlord)] = fileSystemsLandlord;
			cfg.Properties[typeof(MixedModeRequestAuthorizer)] = mixedModeRequestAuthorizer;
			cfg.Properties[typeof(RequestManager)] = requestManager;
			cfg.Formatters.Remove(cfg.Formatters.XmlFormatter);
			cfg.Formatters.JsonFormatter.SerializerSettings.Converters.Add(new NaveValueCollectionJsonConverterOnlyForConfigFormatters());

			cfg.Services.Replace(typeof(IAssembliesResolver), new MyAssemblyResolver());
			cfg.Filters.Add(new RavenExceptionFilterAttribute());
			cfg.MapHttpAttributeRoutes();

			cfg.Routes.MapHttpRoute(
				"RavenFs", "ravenfs/{controller}/{action}",
				new {id = RouteParameter.Optional});

			cfg.Routes.MapHttpRoute(
				"API Default", "{controller}/{action}",
				new { id = RouteParameter.Optional });

			cfg.Routes.MapHttpRoute(
				"Database Route", "databases/{databaseName}/{controller}/{action}",
				new { id = RouteParameter.Optional });

			cfg.MessageHandlers.Add(new GZipToJsonAndCompressHandler());

			cfg.Services.Replace(typeof(IHostBufferPolicySelector), new SelectiveBufferPolicySelector());
			cfg.EnsureInitialized();
			return cfg;
		}
 public AdminLogsWebSocketsRequestParser(DatabasesLandlord databasesLandlord, CountersLandlord countersLandlord, FileSystemsLandlord fileSystemsLandlord, MixedModeRequestAuthorizer authorizer, string expectedRequestSuffix)
     : base(databasesLandlord, countersLandlord, fileSystemsLandlord, authorizer, expectedRequestSuffix)
 {
 }
        private static bool IsIncrementalBackupIsAllowed(DatabasesLandlord databaseLandlord,DatabaseDocument dbDoc)
        {
            // check if DatabaseDocument contains either of the incremental flags
            bool isVoronIncrementalBackup = dbDoc.Settings.ContainsKey("Raven/Voron/AllowIncrementalBackups");
            bool isEsentCircularLog = dbDoc.Settings.ContainsKey("Raven/Esent/CircularLog");
            if ( isVoronIncrementalBackup || isEsentCircularLog)
            {
                if (isEsentCircularLog && bool.TryParse(dbDoc.Settings["Raven/Esent/CircularLog"], out isEsentCircularLog))
                {
                    return (isEsentCircularLog) ? false : true;

                }
                else if (isVoronIncrementalBackup && bool.TryParse(dbDoc.Settings["Raven/Voron/AllowIncrementalBackups"], out isVoronIncrementalBackup))
                {
                    return isVoronIncrementalBackup;
                }
            }
            // if not check if system configuration has one of the incremental flags up.
            string isVoronIncrementalBackupStr = databaseLandlord.SystemConfiguration.Settings["Raven/Voron/AllowIncrementalBackups"];
            string isEsentCircularLogStr = databaseLandlord.SystemConfiguration.Settings["Raven/Esent/CircularLog"];
            if (isVoronIncrementalBackupStr != null || isEsentCircularLogStr != null)
            {
                if (isEsentCircularLogStr != null && bool.TryParse(isEsentCircularLogStr, out isEsentCircularLog))
                {
                    return (isEsentCircularLog) ? false : true;

                }
                else if (isVoronIncrementalBackupStr != null && bool.TryParse(isVoronIncrementalBackupStr, out isVoronIncrementalBackup))
                {
                    return isVoronIncrementalBackup;
                }
            }
            return false;

        }