本文整理汇总了C#中IDatabaseCommands.ForceReadFromMaster方法的典型用法代码示例。如果您正苦于以下问题:C# IDatabaseCommands.ForceReadFromMaster方法的具体用法?C# IDatabaseCommands.ForceReadFromMaster怎么用?C# IDatabaseCommands.ForceReadFromMaster使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IDatabaseCommands
的用法示例。
在下文中一共展示了IDatabaseCommands.ForceReadFromMaster方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: SetupCommands
private static IDatabaseCommands SetupCommands(IDatabaseCommands databaseCommands, string database, ICredentials credentialsForSession, OpenSessionOptions options)
{
if (database != null)
databaseCommands = databaseCommands.ForDatabase(database);
if (credentialsForSession != null)
databaseCommands = databaseCommands.With(credentialsForSession);
if (options.ForceReadFromMaster)
databaseCommands.ForceReadFromMaster();
return databaseCommands;
}
示例2: GetNextRange
private RangeValue GetNextRange(IDatabaseCommands databaseCommands)
{
using (new TransactionScope(TransactionScopeOption.Suppress))
using (RavenTransactionAccessor.SupressExplicitRavenTransaction())
using (databaseCommands.ForceReadFromMaster())
{
ModifyCapacityIfRequired();
while (true)
{
try
{
var minNextMax = Range.Max;
JsonDocument document;
try
{
document = GetDocument(databaseCommands);
}
catch (ConflictException e)
{
// resolving the conflict by selecting the highest number
var highestMax = e.ConflictedVersionIds
.Select(conflictedVersionId => GetMaxFromDocument(databaseCommands.Get(conflictedVersionId), minNextMax))
.Max();
PutDocument(databaseCommands, new JsonDocument
{
Etag = e.Etag,
Metadata = new RavenJObject(),
DataAsJson = RavenJObject.FromObject(new { Max = highestMax }),
Key = HiLoDocumentKey
});
continue;
}
long min, max;
if (document == null)
{
min = minNextMax + 1;
max = minNextMax + capacity;
document = new JsonDocument
{
Etag = Etag.Empty,
// sending empty etag means - ensure the that the document does NOT exists
Metadata = new RavenJObject(),
DataAsJson = RavenJObject.FromObject(new { Max = max }),
Key = HiLoDocumentKey
};
}
else
{
var oldMax = GetMaxFromDocument(document, minNextMax);
min = oldMax + 1;
max = oldMax + capacity;
document.DataAsJson["Max"] = max;
}
PutDocument(databaseCommands, document);
return new RangeValue(min, max);
}
catch (ConcurrencyException)
{
// expected, we need to retry
}
}
}
}