本文整理汇总了C#中IFdbTransaction.GetAsync方法的典型用法代码示例。如果您正苦于以下问题:C# IFdbTransaction.GetAsync方法的具体用法?C# IFdbTransaction.GetAsync怎么用?C# IFdbTransaction.GetAsync使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IFdbTransaction
的用法示例。
在下文中一共展示了IFdbTransaction.GetAsync方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Scenario6
private async Task Scenario6(IFdbTransaction tr)
{
var location = FdbSubspace.Create(Slice.FromAscii("TEST"));
tr.AtomicAdd(location.Pack("ATOMIC"), Slice.FromFixed32(0x55555555));
var x = await tr.GetAsync(location.Pack("ATOMIC"));
Console.WriteLine(x.ToInt32().ToString("x"));
}
示例2: GetChunkAtAsync
private async Task<Chunk> GetChunkAtAsync(IFdbTransaction trans, long offset)
{
Contract.Requires(trans != null && offset >= 0);
var chunkKey = await trans.GetKeyAsync(FdbKeySelector.LastLessOrEqual(DataKey(offset))).ConfigureAwait(false);
if (chunkKey.IsNull)
{ // nothing before (sparse)
return default(Chunk);
}
if (chunkKey < DataKey(0))
{ // off beginning
return default(Chunk);
}
long chunkOffset = DataKeyOffset(chunkKey);
Slice chunkData = await trans.GetAsync(chunkKey).ConfigureAwait(false);
if (chunkOffset + chunkData.Count <= offset)
{ // in sparse region after chunk
return default(Chunk);
}
return new Chunk(chunkKey, chunkData, chunkOffset);
}
示例3: Signup
/// <summary>
/// Signup a student to a class
/// </summary>
public async Task Signup(IFdbTransaction tr, string s, string c)
{
var rec = AttendsKey(s, c);
if ((await tr.GetAsync(rec)).IsPresent)
{ // already signed up
return;
}
int seatsLeft = Int32.Parse((await tr.GetAsync(ClassKey(c))).ToAscii());
if (seatsLeft <= 0)
{
throw new InvalidOperationException("No remaining seats");
}
var classes = await tr.GetRange(AttendsKeys(s)).ToListAsync();
if (classes.Count >= 5) throw new InvalidOperationException("Too many classes");
tr.Set(ClassKey(c), Slice.FromAscii((seatsLeft - 1).ToString()));
tr.Set(rec, Slice.Empty);
}
示例4: Drop
/// <summary>
/// Drop a student from a class
/// </summary>
public async Task Drop(IFdbTransaction tr, string s, string c)
{
var rec = AttendsKey(s, c);
if ((await tr.GetAsync(rec)).IsNullOrEmpty)
{ // not taking this class
return;
}
var students = Int32.Parse((await tr.GetAsync(ClassKey(c))).ToAscii());
tr.Set(ClassKey(c), Slice.FromAscii((students + 1).ToString()));
tr.Clear(rec);
}
示例5: Scenario1
// Compare the behavior of the MemoryDB against a FoundationDB database
private async Task Scenario1(IFdbTransaction tr)
{
tr.Set(Slice.FromAscii("hello"), Slice.FromAscii("world!"));
tr.Clear(Slice.FromAscii("removed"));
var result = await tr.GetAsync(Slice.FromAscii("narf"));
}
示例6: CheckWriteVersionAsync
private async Task CheckWriteVersionAsync(IFdbTransaction trans)
{
var value = await trans.GetAsync(this.RootNode.Pack(VersionKey)).ConfigureAwait(false);
if (value.IsNullOrEmpty)
{
InitializeDirectory(trans);
}
else
{
CheckVersion(value, true);
}
}
示例7: AllocateAsync
/// <summary>Returns a 64-bit integer that
/// 1) has never and will never be returned by another call to this
/// method on the same subspace
/// 2) is nearly as short as possible given the above
/// </summary>
public async Task<long> AllocateAsync(IFdbTransaction trans)
{
// find the current window size, by reading the last entry in the 'counters' subspace
long start = 0, count = 0;
var kv = await trans
.Snapshot
.GetRange(this.Counters.ToRange())
.LastOrDefaultAsync();
if (kv.Key.IsPresent)
{
start = this.Counters.UnpackSingle<long>(kv.Key);
count = kv.Value.ToInt64();
}
// check if the window is full
int window = GetWindowSize(start);
if ((count + 1) * 2 >= window)
{ // advance the window
trans.ClearRange(this.Counters.Key, this.Counters.Pack(start) + FdbKey.MinValue);
start += window;
trans.ClearRange(this.Recent.Key, this.Recent.Pack(start));
}
// Increment the allocation count for the current window
trans.AtomicAdd(this.Counters.Pack(start), Slice.FromFixed64(1));
// As of the snapshot being read from, the window is less than half
// full, so this should be expected to take 2 tries. Under high
// contention (and when the window advances), there is an additional
// subsequent risk of conflict for this transaction.
while (true)
{
// Find a random free slot in the current window...
long candidate;
lock (m_rnd)
{
candidate = start + m_rnd.Next(window);
}
// test if the key is used
var key = this.Recent.Pack(candidate);
var value = await trans.GetAsync(key).ConfigureAwait(false);
if (value.IsNull)
{ // free slot
// mark as used
trans.Set(key, Slice.Empty);
return candidate;
}
// no luck this time, try again...
}
}