akr*_*smv 3 azure-service-fabric
我正在尝试消化服务结构架构模式及其最佳实践。
用例:
我定义了一个有 26 个分区的有状态服务,并且在每个分区中我存储了具有相同首字母的单词。
3)难道说一个状态服务是工作单位,它需要知道要操作的分区,并不能做出自己的决定?在这里,我指的是有状态服务的 RunAsync 方法内部的许多示例,其中有对底层可靠存储的调用,例如,取自这篇文章的代码:
protected override async Task RunAsync(CancellationToken cancelServicePartitionReplica)
{
var myDictionary = await this.StateManager.GetOrAddAsync<IReliableDictionary<string, int>> ("myDictionary");
var partition = base.ServicePartition.PartitionInfo.Id;
byte append = partition.ToByteArray()[0];
while (!cancelServicePartitionReplica.IsCancellationRequested)
{
// Create a transaction to perform operations on data within this partition's replica.
using (var tx = this.StateManager.CreateTransaction())
{
var result = await myDictionary.TryGetValueAsync(tx, "A");
await myDictionary.AddOrUpdateAsync(tx, "A", 0, (k, v) => v + append);
ServiceEventSource.Current.ServiceMessage(this,
$"Append {append}: {(result.HasValue ? result.Value : -1)}");
await tx.CommitAsync();
}
// Pause for 1 second before continue processing.
await Task.Delay(TimeSpan.FromSeconds(3), cancelServicePartitionReplica);
}
}
Run Code Online (Sandbox Code Playgroud)因此,可能我的陈述 3) 是错误的 - 有状态服务可能会调用其内部存储,而没有人(服务客户端)在外部调用它并提供确切分区的信息。但是,上面的代码如何决定将其数据放入哪个分区?最重要的是,以后如何通过应提供准确分区 ID 的服务客户端查询该数据?
| 归档时间: |
|
| 查看次数: |
1156 次 |
| 最近记录: |