Azure-Samples / service-fabric-dotnet-getting-started

Get started with Service Fabric with these simple introductory sample projects.
MIT License
230 stars 329 forks source link

StateManager availability in ICommunicationListeners #49

Open SeanFeldman opened 7 years ago

SeanFeldman commented 7 years ago

This is more of a question.

From the samples, it looks like StateManager is available when communication listeners are created/opened. For example, in the AlphabetPartitions sample, Alphabet.Web HttpCommunicationListener the usage of the state manager to access and write the RC "dictionary" seems to be possible the moment communication listener is opened (OpenAsync() in invoked). The request will be processed right away. Based on what I've seen, the state manager while available is not really usable until RunAsync() of a service in invoked.

Tried to sketch a lifecycle and state manager timeline image

  1. Is that so?
  2. If StateManager cannot be used until certain point in the life-cycle of a stateful service, does that mean SF simply doesn't forward any HTTP requests to the service even though communication listenersOpenAsync()has been executed?
masnider commented 7 years ago
  1. No - they're really orthogonal. Read this: https://docs.microsoft.com/en-us/azure/service-fabric/service-fabric-reliable-services-lifecycle

  2. No - Most of the time SF isn't in the communication flow. As just one simple example the Azure LB could be what is sending to the service and there's no control there. Furthermore even when SF is in the path, the only control is whether the open of the listeners have completed. If they have, the service's addresses are registered in naming. At that point the service and those endpoints are discoverable and calls could start showing up. Even if we did wait for the state manager to be ready it could become unready at any time (quorum loss, upgrade, primary demotion for other reasons, whatever).

SeanFeldman commented 7 years ago

@masnider thank you. That means that there's a chance that first request to the service might actually fail.

The scenario I'm looking at is when consuming messages from an external queuing service from the communication listener upon OpenAsync() invocation. Just like in the documentation you pointed to, there's no real need in service`s RunAsync(). But that causes an exception when trying to operate on the reliable collection. Hence my question.