确定有状态副本在服务结构中的角色 [英] Determine role of stateful replica in service fabric

查看:59
本文介绍了确定有状态副本在服务结构中的角色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Service Fabric中有一个状态服务,其中包含多个分区和副本.我已经对其进行了配置,以便主副本和ActiveSecondary副本都公开其端点.目的是使我可以利用辅助副本进行读取操作.

I have a stateful service in Service Fabric with multiple partitions and replicas. I have configured it so that both the Primary and ActiveSecondary replicas expose their endpoints. The purpose is so that I can leverage the secondary replicas for read operations.

我遇到的问题是,在服务内部我希望能够告诉它是Primary还是ActiveSecondary,因为不需要为辅助副本运行某些共享的默认代码. (因为将默认值插入ReliableStateManager会引发次要事件.)

The problem I'm having is that inside the service I want to be able to tell it is a Primary or ActiveSecondary because some shared defaulting code needs to not run for the secondary replicas. (Because inserting defaults into the ReliableStateManager throws on secondaries.)

我可以在运行时确定副本角色吗?

Can I determine the Replica Role at runtime?

推荐答案

您可以覆盖OnChangeRoleAsync并检查ReplicaRole参数.请注意:

You can override OnChangeRoleAsync and check the ReplicaRole parameter. Note that:

  • 角色可以在服务的生命周期内发生变化(例如,将辅助角色提升为主要角色)
  • RunAsync仅在主副本上执行(如果角色更改,该副本将被取消)-因此您可以安全地将初始化代码放在此处
  • 对于更高级的方案,您还可以检查PartitionReadStatusWriteStatus
  • The role can change during the lifetime of a service (e.g. secondary promoted to primary)
  • RunAsync is only executed on primary replicas (will be cancelled if the role changes) - so you can safely place your initialization code there
  • For more advanced scenarios, you can also check the Partition's ReadStatus and WriteStatus

这篇关于确定有状态副本在服务结构中的角色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆