本文整理汇总了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;
}
}
示例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;
}
示例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);
}
}
}
示例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;
}
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}