Dispose() public method

public Dispose ( ) : void
return void
        public static void Init()
        {
            if (database != null)
                return;

            lock (locker)
            {
                if (database != null)
                    return;

                try
                {
                    var ravenConfiguration = new RavenConfiguration();
                    if (RoleEnvironment.IsAvailable)
                    {
                        ravenConfiguration.RunInMemory = true;
                        // Mount Cloud drive and set it as Data Directory
                        //var currentConfiguredRavenDataDir = ConfigurationManager.AppSettings["Raven/DataDir"] ?? string.Empty;
                        //string azureDrive = @"D:\"; // Environment.GetEnvironmentVariable(RavenDriveConfiguration.AzureDriveEnvironmentVariableName, EnvironmentVariableTarget.Machine);
                        //if (string.IsNullOrWhiteSpace(azureDrive))
                        //{
                        //    throw new ArgumentException("RavenDb drive environment variable is not yet set by worker role. Please, retry in a couple of seconds");
                        //}

                        //string azurePath = Path.Combine(azureDrive,
                        //    currentConfiguredRavenDataDir.StartsWith(@"~\")
                        //        ? currentConfiguredRavenDataDir.Substring(2)
                        //        : "Data");
                        //ravenConfiguration.DataDirectory = azurePath;

                        // Read port number specified for this Raven instance and set it in configuration
                        var endpoint = RoleEnvironment.CurrentRoleInstance.InstanceEndpoints["Raven"];
                        ravenConfiguration.Port = endpoint.IPEndpoint.Port;

                        // When mounting drives in emulator only Munin storage is supported, since drive is not actually present and low level access to it failes (Esent mode)
                    }
                    HttpEndpointRegistration.RegisterHttpEndpointTarget();
                    database = new DocumentDatabase(ravenConfiguration);
                    database.SpinBackgroundWorkers();
                    server = new HttpServer(ravenConfiguration, database);
                    server.Init();
                }
                catch
                {
                    if (database != null)
                    {
                        database.Dispose();
                        database = null;
                    }
                    if (server != null)
                    {
                        server.Dispose();
                        server = null;
                    }
                    throw;
                }

                HostingEnvironment.RegisterObject(new ReleaseRavenDBWhenAppDomainIsTornDown());
            }
        }
		public static void Init()
		{
			if (database != null)
				return;

			lock (locker)
			{
				if (database != null)
					return;

				try
				{
					var ravenConfiguration = new RavenConfiguration();
					HttpEndpointRegistration.RegisterHttpEndpointTarget();
					database = new DocumentDatabase(ravenConfiguration);
					database.SpinBackgroundWorkers();
					server = new HttpServer(ravenConfiguration, database);
					server.Init();
				}
				catch
				{
					if (database != null)
					{
						database.Dispose();
						database = null;
					}
					if (server != null)
					{
						server.Dispose();
						server = null;
					}
					throw;
				}
			}
		}
Ejemplo n.º 3
0
		public RavenDbServer(InMemoryRavenConfiguration settings)
		{
			database = new DocumentDatabase(settings);

			try
			{
				database.SpinBackgroundWorkers();
				server = new HttpServer(settings, database);
				server.StartListening();
			}
			catch (Exception)
			{
				database.Dispose();
				database = null;
				
				throw;
			}
		}
Ejemplo n.º 4
0
		public RavenDbServer(RavenConfiguration settings)
		{
			settings.LoadLoggingSettings();
			database = new DocumentDatabase(settings);

			try
			{
				database.SpinBackgroundWorkers();
				server = new HttpServer(settings, database);
				server.Start();
			}
			catch (Exception)
			{
				database.Dispose();
				database = null;
				
				throw;
			}
		}
        public static void Init()
        {
            if (database != null)
                return;

            lock (locker)
            {
                if (database != null)
                    return;

                log.Info("Setting up RavenDB Http Integration to the ASP.Net Pipeline");
                try
                {
                    var ravenConfiguration = new RavenConfiguration();
                    HttpEndpointRegistration.RegisterHttpEndpointTarget();
                    database = new DocumentDatabase(ravenConfiguration);
                    database.SpinBackgroundWorkers();
                    server = new HttpServer(ravenConfiguration, database);
                    server.Init();
                }
                catch
                {
                    if (database != null)
                    {
                        database.Dispose();
                        database = null;
                    }
                    if (server != null)
                    {
                        server.Dispose();
                        server = null;
                    }
                    throw;
                }

                shutdownDetector = new ShutdownDetector(log);
                shutdownDetector.Initialize();

                shutdownDetector.Token.Register(OnShutdown);
            }
        }
		public static void Init()
		{
			if (database != null)
				return;

			lock (locker)
			{
				if (database != null)
					return;

				log.Info("Setting up RavenDB Http Integration to the ASP.Net Pipeline");
				try
				{
					var ravenConfiguration = new RavenConfiguration();
					HttpEndpointRegistration.RegisterHttpEndpointTarget();
					database = new DocumentDatabase(ravenConfiguration);
					database.SpinBackgroundWorkers();
					server = new HttpServer(ravenConfiguration, database);
					server.Init();
				}
				catch
				{
					if (database != null)
					{
						database.Dispose();
						database = null;
					}
					if (server != null)
					{
						server.Dispose();
						server = null;
					}
					throw;
				}

				HostingEnvironment.RegisterObject(new ReleaseRavenDBWhenAppDomainIsTornDown());
			}
		}
Ejemplo n.º 7
0
		public void AfterBackupRestore_IndexConsistentWithWritesDuringBackup()
		{
			var count = 1;
			var docId = string.Format("ayende{0}", count++.ToString("D4"));
			db.Documents.Put(docId, null, RavenJObject.Parse("{'email':'*****@*****.**'}"), RavenJObject.Parse("{'Raven-Entity-Name':'Users'}"), null);
			db.SpinBackgroundWorkers();

			QueryResult queryResult;
			do
			{
				queryResult = db.Queries.Query("Raven/DocumentsByEntityName", new IndexQuery
				{
					Query = "Tag:[[Users]]",
					PageSize = 10
				}, CancellationToken.None);
			} while (queryResult.IsStale);
			Assert.Equal(1, queryResult.Results.Count);

			var runInserts = true;
			Task.Run(() =>
			{
				while (runInserts)
				{
					docId = string.Format("ayende{0}", count++.ToString("D4"));
					db.Documents.Put(docId, null, RavenJObject.Parse("{'email':'*****@*****.**'}"), RavenJObject.Parse("{'Raven-Entity-Name':'Users'}"), null);
					db.IndexStorage.FlushMapIndexes();
				}
			});

			db.Maintenance.StartBackup(BackupDir, false, new DatabaseDocument());
			WaitForBackup(db, true);
			runInserts = false;

			db.Dispose();
			IOExtensions.DeleteDirectory(DataDir);

			MaintenanceActions.Restore(new RavenConfiguration(), new DatabaseRestoreRequest
			{
				BackupLocation = BackupDir,
				DatabaseLocation = DataDir,
				Defrag = true
			}, s => { });

			db = new DocumentDatabase(new RavenConfiguration { DataDirectory = DataDir });
			docId = string.Format("ayende{0}", count++.ToString("D4"));
			db.Documents.Put(docId, null, RavenJObject.Parse("{'email':'*****@*****.**'}"), RavenJObject.Parse("{'Raven-Entity-Name':'Users'}"), null);
			db.SpinBackgroundWorkers();

			int next = 0;
			var storedDocs = new List<string>();

			while (true)
			{
				var batch = db.Documents.GetDocumentsWithIdStartingWith("ayende", null, null, next, 1024, CancellationToken.None, ref next);
				storedDocs.AddRange(batch.Select(doc => doc.Value<RavenJObject>("@metadata").Value<string>("@id")));
				if (batch.Length < 1024) break;
			}

			List<string> indexedDocs;
			bool stale;
			do
			{
				indexedDocs = db.Queries.QueryDocumentIds("Raven/DocumentsByEntityName", new IndexQuery
				{
					Query = "Tag:[[Users]]",
					PageSize = int.MaxValue,
					WaitForNonStaleResultsAsOfNow = true
				}, new CancellationTokenSource(), out stale).ToList();
			} while (stale);

			if (storedDocs.Count != indexedDocs.Count)
			{
				var storedHash = new HashSet<string>(storedDocs);
				var indexedHash = new HashSet<string>(indexedDocs);
				foreach (var id in storedDocs.Union(indexedDocs).OrderBy(x => x))
				{
					Debug.WriteLine("{0} Database:{1} Indexed:{2}", id, storedHash.Contains(id), indexedHash.Contains(id));
				}
			}

			Assert.Equal(storedDocs.Count, indexedDocs.Count());
			db.Dispose();
		}
Ejemplo n.º 8
0
 private void StartRaven(RavenConfiguration config)
 {
     try
     {
         _database = new DocumentDatabase(config);
         _database.SpinBackgroundWorkers();
         _server = new RavenDbHttpServer(config, _database);
         try
         {
             _server.Start();
         }
         catch (Exception)
         {
             _server.Dispose();
             _server = null;
             throw;
         }
     }
     catch (Exception)
     {
         _database.Dispose();
         _database = null;
         throw;
     }
 }
Ejemplo n.º 9
0
        private void StartRaven()
        {
            try
            {
                Trace.TraceInformation("RavenDb: Starting...");

                AnonymousUserAccessMode anonymousUserAccessMode;
                if (!Enum.TryParse(RoleEnvironment.GetConfigurationSettingValue("AnonymousUserAccessMode"), true, out anonymousUserAccessMode))
                    anonymousUserAccessMode = AnonymousUserAccessMode.Get;
                Trace.TraceInformation("Raven Configuration AnonymousUserAccessMode: {0}", anonymousUserAccessMode);

                var httpCompression = Boolean.Parse(RoleEnvironment.GetConfigurationSettingValue("HttpCompression"));
                Trace.TraceInformation("Raven Configuration HttpCompression: {0}", httpCompression);

                var defaultStorageTypeName = RoleEnvironment.GetConfigurationSettingValue("DefaultStorageTypeName");
                Trace.TraceInformation("Raven Configuration DefaultStorageTypeName: {0}", defaultStorageTypeName);

                var port = RoleEnvironment.CurrentRoleInstance.InstanceEndpoints["Raven"].IPEndpoint.Port;
                Trace.TraceInformation("Raven Configuration Port: {0}", port);

                Trace.TraceInformation("RavenDb: Ensure Can ListenTo When In Non Admin Context...");
                NonAdminHttp.EnsureCanListenToWhenInNonAdminContext(port);

                var config = new RavenConfiguration
                {
                    DataDirectory = _dataDrive.LocalPath.EndsWith("\\")
                                        ? _dataDrive.LocalPath + "Data\\"
                                        : _dataDrive.LocalPath + "\\Data\\",
                    AnonymousUserAccessMode = anonymousUserAccessMode,
                    HttpCompression = httpCompression,
                    DefaultStorageTypeName = defaultStorageTypeName,
                    Port = port,
                    PluginsDirectory = "Plugins"
                };
                _database = new DocumentDatabase(config);

                Trace.TraceInformation("RavenDb: Spin Background Workers...");
                _database.SpinBackgroundWorkers();

                _server = new HttpServer(config, _database);
                try
                {
                    Trace.TraceInformation("Http Server: Initializing ...");
                    _server.Init();
                    Trace.TraceInformation("Http Server: Start Listening ...");
                    _server.StartListening();
                }
                catch (Exception)
                {
                    _server.Dispose();
                    _server = null;
                    throw;
                }

                Trace.TraceInformation("RavenDb: Started.");
            }
            catch (Exception)
            {
                if (_database != null)
                {
                    _database.Dispose();
                    _database = null;
                }
                throw;
            }
        }
        public void NonIncrementalBackup_Restore_CanReadDocument(string storageName)
        {
            InitializeDocumentDatabase(storageName);
            IOExtensions.DeleteDirectory(BackupDir);

            db.Documents.Put("Foo", null, RavenJObject.Parse("{'email':'*****@*****.**'}"), new RavenJObject(), null);

            db.Maintenance.StartBackup(BackupDir, false, new DatabaseDocument());
            WaitForBackup(db, true);

            db.Dispose();
            IOExtensions.DeleteDirectory(DataDir);

            MaintenanceActions.Restore(new RavenConfiguration
            {
                DefaultStorageTypeName = storageName,
                DataDirectory = DataDir,
                RunInMemory = false,
                RunInUnreliableYetFastModeThatIsNotSuitableForProduction = false,
                Settings =
	            {
	                {"Raven/Esent/CircularLog", "false"},
					{"Raven/Voron/AllowIncrementalBackups", "true"}
	            }

            }, new DatabaseRestoreRequest
            {
                BackupLocation = BackupDir,
                DatabaseLocation = DataDir,
                Defrag = true
            }, s => { });

            db = new DocumentDatabase(new RavenConfiguration { DataDirectory = DataDir });

            var fetchedData = db.Documents.Get("Foo", null);
            Assert.NotNull(fetchedData);

            var jObject = fetchedData.ToJson();
            Assert.NotNull(jObject);
            Assert.Equal("*****@*****.**", jObject.Value<string>("email"));

            db.Dispose();
        }