SpinBackgroundWorkers() public méthode

public SpinBackgroundWorkers ( ) : void
Résultat void
Exemple #1
0
        public RavenDbServer(RavenConfiguration settings)
        {
            settings.LoadLoggingSettings();
            if (settings.ShouldCreateDefaultsWhenBuildingNewDatabaseFromScratch)
                settings.DatabaseCreatedFromScratch += OnDatabaseCreatedFromScratch;
            database = new DocumentDatabase(settings);
            database.SpinBackgroundWorkers();
            server = new HttpServer(settings,
                                    typeof (RequestResponder).Assembly.GetTypes()
                                        .Where(
                                            t => typeof (RequestResponder).IsAssignableFrom(t) && t.IsAbstract == false)

                                        // to ensure that we would get consistent order, so we would always
                                        // have the responders using the same order, otherwise we get possibly
                                        // random ordering, and that might cause issues
                                        .OrderBy(x => x.Name)
                                        .Select(t => (RequestResponder) Activator.CreateInstance(t))
                                        .Select(r =>
                                        {
                                            r.Database = database;
                                            r.Settings = settings;
                                            return r;
                                        })
                );
            server.Start();
        }
        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());
            }
        }
Exemple #3
0
		public void AfterBackupRestoreCanQueryIndex_CreatedAfterRestore()
		{
			db.Put("ayende", null, RavenJObject.Parse("{'email':'*****@*****.**'}"), RavenJObject.Parse("{'Raven-Entity-Name':'Users'}"), null);

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

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

			DocumentDatabase.Restore(new RavenConfiguration(), BackupDir, DataDir, s => { }, defrag: true);

			db = new DocumentDatabase(new RavenConfiguration { DataDirectory = DataDir });
			db.SpinBackgroundWorkers();
			QueryResult queryResult;
			do
			{
				queryResult = db.Query("Raven/DocumentsByEntityName", new IndexQuery
				{
					Query = "Tag:[[Users]]",
					PageSize = 10
				}, CancellationToken.None);
			} while (queryResult.IsStale);
			Assert.Equal(1, queryResult.Results.Count);
		}
		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;
				}
			}
		}
Exemple #5
0
        public void AfterBackupRestoreCanQueryIndex_CreatedAfterRestore()
        {
            db.Put("ayende", null, JObject.Parse("{'email':'*****@*****.**'}"), JObject.Parse("{'Raven-Entity-Name':'Users'}"), null);

            db.StartBackup("raven.db.test.backup");
            WaitForBackup();

            db.Dispose();

            DeleteIfExists("raven.db.test.esent");

            DocumentDatabase.Restore(new RavenConfiguration(), "raven.db.test.backup", "raven.db.test.esent");

            db = new DocumentDatabase(new RavenConfiguration { DataDirectory = "raven.db.test.esent" });
            db.SpinBackgroundWorkers();
            QueryResult queryResult;
            do
            {
                queryResult = db.Query("Raven/DocumentsByEntityName", new IndexQuery
                {
                    Query = "Tag:[[Users]]",
                    PageSize = 10
                });
            } while (queryResult.IsStale);
            Assert.Equal(1, queryResult.Results.Count);
        }
Exemple #6
0
		public RavenDbServer(RavenConfiguration settings)
		{
			settings.LoadLoggingSettings();
			database = new DocumentDatabase(settings);
			database.SpinBackgroundWorkers();
			server = new HttpServer(settings, database);
			server.Start();
		}
Exemple #7
0
		public SpatialIndexTest()
		{
			db = new DocumentDatabase(new RavenConfiguration
			{
				RunInMemory = true
			});
			db.SpinBackgroundWorkers();
		}
 public ParameterisedDynamicQuery()
 {
     db = new DocumentDatabase(new RavenConfiguration
         {
             DataDirectory = "raven.db.test.esent",
         });
     db.SpinBackgroundWorkers();
 }
Exemple #9
0
		public SpatialIndex()
		{
			db = new DocumentDatabase(new RavenConfiguration
			{
				DataDirectory = "raven.db.test.esent",
				RunInUnreliableYetFastModeThatIsNotSuitableForProduction = true
			});
			db.SpinBackgroundWorkers();
		}
		public ComplexIndexOnNotAnalyzedField()
		{
			db = new DocumentDatabase(new RavenConfiguration
			{
				DataDirectory = DataDir,
				RunInUnreliableYetFastModeThatIsNotSuitableForProduction = true
			});
			db.SpinBackgroundWorkers();
		}
Exemple #11
0
		public MapReduce()
		{
			db = new DocumentDatabase(new RavenConfiguration
			{
				DataDirectory = DataDir,
				RunInUnreliableYetFastModeThatIsNotSuitableForProduction = true
			});
			db.PutIndex("CommentsCountPerBlog", new IndexDefinition{Map = map, Reduce = reduce, Indexes = {{"blog_id", FieldIndexing.NotAnalyzed}}});
			db.SpinBackgroundWorkers();
		}
Exemple #12
0
 public CompiledIndex()
 {
     db = new DocumentDatabase(new RavenConfiguration
     {
         DataDirectory = "raven.db.test.esent",
         RunInUnreliableYetFastModeThatIsNotSuitableForProduction = true,
         Catalog = { Catalogs = { new TypeCatalog(typeof(ShoppingCartEventsToShopingCart), typeof(MapOnlyView)) } }
     });
     db.SpinBackgroundWorkers();
 }
Exemple #13
0
 public IndexTriggers()
 {
     db = new DocumentDatabase(new RavenConfiguration
     {
         DataDirectory = "raven.db.test.esent",
         Container = new CompositionContainer(new TypeCatalog(
             typeof(IndexToDataTable))),
         RunInUnreliableYetFastModeThatIsNotSuitableForProduction = true
     });
     db.SpinBackgroundWorkers();
 }
		static ForwardToRavenRespondersFactory()
		{
			lock (locker)
			{
				if (database != null)
					return;

				database = new DocumentDatabase(ravenConfiguration);
				database.SpinBackgroundWorkers();
				server = new RavenDbHttpServer(ravenConfiguration, database);
			}
		}
Exemple #15
0
        public MapReduce()
        {
            db = new DocumentDatabase(new RavenConfiguration {DataDirectory = "raven.db.test.esent"});
            db.PutIndex("CommentsCountPerBlog", new IndexDefinition{Map = map, Reduce = reduce, Indexes = {{"blog_id", FieldIndexing.Untokenized}}});
            db.SpinBackgroundWorkers();

            BasicConfigurator.Configure(
                new OutputDebugStringAppender
                {
                    Layout = new SimpleLayout()
                });
        }
Exemple #16
0
        public Statistics()
        {
            db = new DocumentDatabase(new RavenConfiguration {DataDirectory = "raven.db.test.esent", RunInUnreliableYetFastModeThatIsNotSuitableForProduction = true});
            db.SpinBackgroundWorkers();

            db.PutIndex("pagesByTitle2",
                        new IndexDefinition
                        {
                            Map = @"
                    from doc in docs
                    where doc.type == ""page""
                    select new {  f = 2 / doc.size };
                "
                        });
        }
Exemple #17
0
        public Statistics()
        {
            db = new DocumentDatabase(new RavenConfiguration {DataDirectory = "raven.db.test.esent"});
            db.SpinBackgroundWorkers();

            db.PutIndex("pagesByTitle2",
                        new IndexDefinition
                        {
                            Map = @"
                    from doc in docs
                    where doc.type == ""page""
                    select new {  f = 2 / doc.size };
                "
                        });
        }
Exemple #18
0
		public void AfterFailedRestoreOfIndex_ShouldGenerateWarningAndResetIt()
		{
			db.Put("users/1", null, RavenJObject.Parse("{'Name':'Arek'}"), RavenJObject.Parse("{'Raven-Entity-Name':'Users'}"), null);
			db.Put("users/2", null, RavenJObject.Parse("{'Name':'David'}"), RavenJObject.Parse("{'Raven-Entity-Name':'Users'}"), null);

			WaitForIndexing(db);

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

			db.Put("users/3", null, RavenJObject.Parse("{'Name':'Daniel'}"), RavenJObject.Parse("{'Raven-Entity-Name':'Users'}"), null);

			WaitForIndexing(db);

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

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

			var incrementalDirectories = Directory.GetDirectories(BackupDir, "Inc*");

			// delete 'index-files.required-for-index-restore' to make backup corrupted according to the reported error
			File.Delete(Path.Combine(incrementalDirectories.First(),
			                         "Indexes\\Raven%2fDocumentsByEntityName\\index-files.required-for-index-restore"));

			var sb = new StringBuilder();

			DocumentDatabase.Restore(new RavenConfiguration(), BackupDir, DataDir, s => sb.Append(s), defrag: true);

			Assert.Contains(
				"Error: Index Raven%2fDocumentsByEntityName could not be restored. All already copied index files was deleted." +
				" Index will be recreated after launching Raven instance",
				sb.ToString());

			db = new DocumentDatabase(new RavenConfiguration { DataDirectory = DataDir });
			db.SpinBackgroundWorkers();
			QueryResult queryResult;
			do
			{
				queryResult = db.Query("Raven/DocumentsByEntityName", new IndexQuery
				{
					Query = "Tag:[[Users]]",
					PageSize = 10
				});
			} while (queryResult.IsStale);
			Assert.Equal(3, queryResult.Results.Count);
		}
Exemple #19
0
		public RavenDB_1007_incremental_backup()
		{
			IOExtensions.DeleteDirectory(BackupDir);

			db = new DocumentDatabase(new RavenConfiguration
			{
				DataDirectory = DataDir,
				RunInUnreliableYetFastModeThatIsNotSuitableForProduction = false,
				Settings =
					{
						{"Raven/Esent/CircularLog", "false"}
					}
			});
			db.SpinBackgroundWorkers();
			db.PutIndex(new RavenDocumentsByEntityName().IndexName, new RavenDocumentsByEntityName().CreateIndexDefinition());
		}
		public static void Init()
		{
			if (database != null)
				return;
			lock (locker)
			{
				if (database != null)
					return;

				var ravenConfiguration = new RavenConfiguration();
				HttpServer.RegisterHttpEndpointTarget();
				database = new DocumentDatabase(ravenConfiguration);
				database.SpinBackgroundWorkers();
				server = new HttpServer(ravenConfiguration, database);
			}
		}
Exemple #21
0
		public ReadTriggers()
		{
			db = new DocumentDatabase(new RavenConfiguration
			{
				DataDirectory = "raven.db.test.esent",
				Container = new CompositionContainer(new TypeCatalog(
					typeof(VetoReadsOnCapitalNamesTrigger),
					typeof(HiddenDocumentsTrigger),
					typeof(UpperCaseNamesTrigger)))
			});
			db.SpinBackgroundWorkers();
			db.PutIndex("ByName",
			            new IndexDefinition
			            {
			            	Map = "from doc in docs select new{ doc.name}"
			            });
		}
Exemple #22
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;
			}
		}
Exemple #23
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());
			}
		}
Exemple #26
0
        public IDocumentStore Initialise()
        {
            try
            {
                if (String.IsNullOrEmpty(server))
                {
                    var embeddedDatabase = new DocumentDatabase(new RavenConfiguration {DataDirectory = DataDirectory});
                    embeddedDatabase.SpinBackgroundWorkers();
                    DatabaseCommands = new EmbededDatabaseCommands(embeddedDatabase);
                }
                else
                {
                    DatabaseCommands = new ServerClient(server, port);
                }
            }
            catch (Exception)
            {
                Dispose();
                throw;
            }

            return this;
        }
Exemple #27
0
        private void StartTheServer()
        {
            try
            {
                var ravenConfiguration = new RavenConfiguration
                {
                    AnonymousUserAccessMode = AnonymousUserAccessMode.All,
                    Port = _endPoint.Port,
                    ListenerProtocol = ListenerProtocol.Tcp,
                    DataDirectory = _ravenDrivePath
                };

                _documentDatabase = new DocumentDatabase(ravenConfiguration);
                _documentDatabase.SpinBackgroundWorkers();

                _ravenHttpServer = new HttpServer(ravenConfiguration, _documentDatabase);
                _ravenHttpServer.Start();
            }
            catch (Exception ex)
            {
                Log.Error(ex.ToString());
            }
        }
		/// <summary>
		/// Initialize the document store access method to RavenDB
		/// </summary>
		protected override void InitializeInternal()
		{
			if (configuration != null && Url == null)
			{
				configuration.PostInit();
				if(configuration.RunInMemory || configuration.RunInUnreliableYetFastModeThatIsNotSuitableForProduction)
				{
					ResourceManagerId = Guid.NewGuid(); // avoid conflicts
				}
				DocumentDatabase = new DocumentDatabase(configuration);
				DocumentDatabase.SpinBackgroundWorkers();
				if (UseEmbeddedHttpServer)
				{
					httpServer = new HttpServer(configuration, DocumentDatabase);
					httpServer.StartListening();
				}
				databaseCommandsGenerator = () => new EmbeddedDatabaseCommands(DocumentDatabase, Conventions, currentSessionId);
			}
			else
			{
				base.InitializeInternal();
			}
		}
Exemple #29
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();
		}
 /// <summary>
 /// Initialize the document store access method to RavenDB
 /// </summary>
 protected override void InitializeInternal()
 {
     if (configuration != null && Url == null)
     {
         DocumentDatabase = new DocumentDatabase(configuration);
         DocumentDatabase.SpinBackgroundWorkers();
         if (UseEmbeddedHttpServer)
         {
             httpServer = new RavenDbHttpServer(configuration, DocumentDatabase);
             httpServer.Start();
         }
         databaseCommandsGenerator = () => new EmbededDatabaseCommands(DocumentDatabase, Conventions);
     }
     else
     {
         base.InitializeInternal();
     }
 }