Determine role of stateful replica in service fabric

霸气de小男生 提交于 2019-12-24 18:05:32

问题


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.

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?


回答1:


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

  • 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


来源:https://stackoverflow.com/questions/37636023/determine-role-of-stateful-replica-in-service-fabric

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!