当前位置: 首页>>代码示例>>C#>>正文


C# DocumentDatabase.SpinBackgroundWorkers方法代码示例

本文整理汇总了C#中DocumentDatabase.SpinBackgroundWorkers方法的典型用法代码示例。如果您正苦于以下问题:C# DocumentDatabase.SpinBackgroundWorkers方法的具体用法?C# DocumentDatabase.SpinBackgroundWorkers怎么用?C# DocumentDatabase.SpinBackgroundWorkers使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在DocumentDatabase的用法示例。


在下文中一共展示了DocumentDatabase.SpinBackgroundWorkers方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: RavenDBOptions

		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;
			}
		}
开发者ID:bbqchickenrobot,项目名称:ravendb,代码行数:33,代码来源:RavenDBOptions.cs

示例2: TryGetOrCreateResourceStore

        protected override bool TryGetOrCreateResourceStore(string tenantId, out IResourceStore database)
        {
            if (ResourcesStoresCache.TryGetValue(tenantId, out database))
                return true;

            JsonDocument jsonDocument;

            using (DocumentRetriever.DisableReadTriggers())
                jsonDocument = DefaultDatabase.Get("Raven/Databases/" + tenantId, null);

            if (jsonDocument == null)
                return false;

            var document = jsonDocument.DataAsJson.JsonDeserialization<DatabaseDocument>();

            database = ResourcesStoresCache.GetOrAdd(tenantId, s =>
            {
                var config = new InMemoryRavenConfiguration
                {
                    Settings = DefaultConfiguration.Settings,
                };
                config.Settings["Raven/VirtualDir"] = config.Settings["Raven/VirtualDir"] + "/" + tenantId;
                foreach (var setting in document.Settings)
                {
                    config.Settings[setting.Key] = setting.Value;
                }
                config.Initialize();
                var documentDatabase = new DocumentDatabase(config);
                documentDatabase.SpinBackgroundWorkers();
                return documentDatabase;
            });
            return true;
        }
开发者ID:vinone,项目名称:ravendb,代码行数:33,代码来源:RavenDbHttpServer.cs

示例3: ShouldNotSetAutoIndexesToAbandonedPriorityAfterDatabaseRecovery

		public void ShouldNotSetAutoIndexesToAbandonedPriorityAfterDatabaseRecovery()
		{
			using (var db = new DocumentDatabase(new RavenConfiguration
			{
				DataDirectory = DataDir,
				RunInUnreliableYetFastModeThatIsNotSuitableForProduction = false
			}))
			{
				db.SpinBackgroundWorkers();
				db.PutIndex(new RavenDocumentsByEntityName().IndexName, new RavenDocumentsByEntityName().CreateIndexDefinition());

				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);

				var results = db.ExecuteDynamicQuery("Users", new IndexQuery()
				{
					PageSize = 128,
					Start = 0,
					Cutoff = SystemTime.UtcNow,
					Query = "Name:Arek"
				}, CancellationToken.None);

				WaitForIndexing(db);

				var autoIdexes = db.Statistics.Indexes.Where(x => x.Name.StartsWith("Auto")).ToList();

				Assert.True(autoIdexes.Count > 0);

				autoIdexes.ForEach(x => db.TransactionalStorage.Batch(accessor => accessor.Indexing.SetIndexPriority(x.Name, IndexingPriority.Idle)));
				
				db.StartBackup(BackupDir, false, new DatabaseDocument());
				WaitForBackup(db, true);
			}
			IOExtensions.DeleteDirectory(DataDir);

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

			using (var db = new DocumentDatabase(new RavenConfiguration
			{
				DataDirectory = DataDir,
				RunInUnreliableYetFastModeThatIsNotSuitableForProduction = false,
			}))
			{
				db.SpinBackgroundWorkers();
				db.RunIdleOperations();

				var autoIndexes = db.Statistics.Indexes.Where(x => x.Name.StartsWith("Auto")).ToList();

				Assert.True(autoIndexes.Count > 0);

				foreach (var indexStats in autoIndexes)
				{
					Assert.NotEqual(indexStats.Priority, IndexingPriority.Abandoned);
				}
			}
		}
开发者ID:925coder,项目名称:ravendb,代码行数:56,代码来源:RavenDB_1600.cs

示例4: RavenDBOptions

        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;
            }
        }
开发者ID:IdanHaim,项目名称:ravendb,代码行数:44,代码来源:RavenDBOptions.cs

示例5: TryGetOrCreateResourceStore

		protected override bool TryGetOrCreateResourceStore(string tenantId, out IResourceStore database)
		{
			if (ResourcesStoresCache.TryGetValue(tenantId, out database))
				return true;

			JsonDocument jsonDocument;

			using (DefaultDatabase.DisableAllTriggersForCurrentThread())
				jsonDocument = DefaultDatabase.Get("Raven/Databases/" + tenantId, null);

			if (jsonDocument == null)
				return false;

			var document = jsonDocument.DataAsJson.JsonDeserialization<DatabaseDocument>();

			database = ResourcesStoresCache.GetOrAddAtomically(tenantId, s =>
			{
				var config = new InMemoryRavenConfiguration
				{
					Settings = DefaultConfiguration.Settings,
				};
				foreach (var setting in document.Settings)
				{
					config.Settings[setting.Key] = setting.Value;
				}
				var dataDir = config.Settings["Raven/DataDir"];
				if (dataDir == null)
					throw new InvalidOperationException("Could not find Raven/DataDir");
				if (dataDir.StartsWith("~/") || dataDir.StartsWith(@"~\"))
				{
					var baseDataPath = Path.GetDirectoryName(DefaultDatabase.Configuration.DataDirectory);
					if (baseDataPath == null)
						throw new InvalidOperationException("Could not find root data path");
					config.Settings["Raven/DataDir"] = Path.Combine(baseDataPath, dataDir.Substring(2));
				}
				config.Settings["Raven/VirtualDir"] = config.Settings["Raven/VirtualDir"] + "/" + tenantId;

				config.DatabaseName = tenantId;

				config.Initialize();
				var documentDatabase = new DocumentDatabase(config);
				documentDatabase.SpinBackgroundWorkers();
				return documentDatabase;
			});
			return true;
		}
开发者ID:JPT123,项目名称:ravendb,代码行数:46,代码来源:RavenDbHttpServer.cs

示例6: TryGetOrCreateResourceStore

		protected bool TryGetOrCreateResourceStore(string tenantId, out Task<DocumentDatabase> database)
		{
			if (ResourcesStoresCache.TryGetValue(tenantId, out database))
			{
				if (database.IsFaulted || database.IsCanceled)
				{
					ResourcesStoresCache.TryRemove(tenantId, out database);
					DateTime time;
					databaseLastRecentlyUsed.TryRemove(tenantId, out time);
					// and now we will try creating it again
				}
				else
				{
					return true;
				}
			}

			if (LockedDatabases.Contains(tenantId))
				throw new InvalidOperationException("Database '" + tenantId + "' is currently locked and cannot be accessed");

			var config = CreateTenantConfiguration(tenantId);
			if (config == null)
				return false;

			database = ResourcesStoresCache.GetOrAdd(tenantId, __ => Task.Factory.StartNew(() =>
			{
			    var transportState = databaseTransportStates.GetOrAdd(tenantId, s => new TransportState());
			    var documentDatabase = new DocumentDatabase(config, transportState);

			    AssertLicenseParameters(config);
				documentDatabase.SpinBackgroundWorkers();
				InitializeRequestResponders(documentDatabase);

				// if we have a very long init process, make sure that we reset the last idle time for this db.
				databaseLastRecentlyUsed.AddOrUpdate(tenantId, SystemTime.UtcNow, (_, time) => SystemTime.UtcNow);
				return documentDatabase;
			}).ContinueWith(task =>
			{
				if (task.Status == TaskStatus.Faulted) // this observes the task exception
				{
					logger.WarnException("Failed to create database " + tenantId, task.Exception);
				}
				return task;
			}).Unwrap());
			return true;
		}
开发者ID:urbanfly,项目名称:ravendb,代码行数:46,代码来源:HttpServer.cs

示例7: TryGetOrCreateResourceStore

		protected bool TryGetOrCreateResourceStore(string tenantId, out Task<DocumentDatabase> database)
		{
			if (ResourcesStoresCache.TryGetValue(tenantId, out database))
			{
				if (database.IsFaulted && database.Exception != null)
				{
					// if we are here, there is an error, and if there is an error, we need to clear it from the 
					// resource store cache so we can try to reload it.
					// Note that we return the faulted task anyway, because we need the user to look at the error
					if (database.Exception.Data.Contains("Raven/KeepInResourceStore") == false)
					{
						Task<DocumentDatabase> val;
						ResourcesStoresCache.TryRemove(tenantId, out val);
					}
				}

				return true;
			}

			if (LockedDatabases.Contains(tenantId))
				throw new InvalidOperationException("Database '" + tenantId + "' is currently locked and cannot be accessed");

			var config = CreateTenantConfiguration(tenantId);
			if (config == null)
				return false;

			database = ResourcesStoresCache.GetOrAdd(tenantId, __ => Task.Factory.StartNew(() =>
			{
				var transportState = databaseTransportStates.GetOrAdd(tenantId, s => new TransportState());
				var documentDatabase = new DocumentDatabase(config, transportState);
				try
				{
					AssertLicenseParameters(config);
					documentDatabase.SpinBackgroundWorkers();
					InitializeRequestResponders(documentDatabase);

					// if we have a very long init process, make sure that we reset the last idle time for this db.
					documentDatabase.WorkContext.UpdateFoundWork();
				}
				catch (Exception)
				{
					documentDatabase.Dispose();
					throw;
				}
				documentDatabase.Disposing += DocumentDatabaseDisposingStarted;
				documentDatabase.DisposingEnded += DocumentDatabaseDisposingEnded;
				return documentDatabase;
			}).ContinueWith(task =>
			{
				if (task.Status == TaskStatus.Faulted) // this observes the task exception
				{
					logger.WarnException("Failed to create database " + tenantId, task.Exception);
				}
				return task;
			}).Unwrap());

			return true;
		}
开发者ID:jon-adams,项目名称:ravendb,代码行数:58,代码来源:HttpServer.cs

示例8: TryGetOrCreateResourceStore

		protected bool TryGetOrCreateResourceStore(string tenantId, out DocumentDatabase database)
		{
			if (ResourcesStoresCache.TryGetValue(tenantId, out database))
				return true;

			if(LockedDatabases.Contains(tenantId))
				throw new InvalidOperationException("Database '" + tenantId +"' is currently locked and cannot be accessed");
			
			var config = CreateTenantConfiguration(tenantId);

			database = ResourcesStoresCache.GetOrAddAtomically(tenantId, s =>
			{
				
				var documentDatabase = new DocumentDatabase(config);
				documentDatabase.SpinBackgroundWorkers();
				return documentDatabase;
			});
			return true;
		}
开发者ID:royra,项目名称:ravendb,代码行数:19,代码来源:HttpServer.cs


注:本文中的DocumentDatabase.SpinBackgroundWorkers方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。