Reputation: 1866
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?
Upvotes: 1
Views: 1412
Reputation: 22747
You can override OnChangeRoleAsync
and check the ReplicaRole
parameter. Note that:
RunAsync
is only executed on primary replicas (will be cancelled if the role changes) - so you can safely place your initialization code therePartition
's ReadStatus
and WriteStatus
Upvotes: 3