Windows Azure - Leader instance without a single point of failure

I am looking for a way to have a "Singleton" module over multiple instances of the employee role. I would like to have a parallel execution model with queues and multiple worker roles in Azure.

The idea is that we would like to have a "master" instance that allows us to check new data and schedule it, adding it to the queue, processing all messages from a special queue that are not processed by anyone else, and set the blob storage as a virtual disk with access for reading / writing.

I will always have only one “primary instance”. When this instance of the wizard leaves for some reason, another instance from the already created instance should be very quickly "selected" for the main instance (a couple of seconds). This should happen before the broken instance is replaced with the new Azure environment (about 15 minutes).

Thus, it will be some kind of self-organizing dynamic environment. I was thinking about having a lock based on the storage or table data. the ability to set blocking timeouts and some kind of watchdog timer if we can talk with microprocessor terminology.

+4
source share
1 answer

There is a general approach to achieving the goal.

Firstly, your main instance. You can make your check based on the instance id. This is pretty easy. You need RoleEnvironment.CurrentRoleInstance to get the "Current Instance", now compare the Id property to what you get from RoleEnvironment.CurrentRoleInstance.Role.Instances the first element ordered by ID. Sort of:

var instance = RoleEnvironment.CurrentRoleInstance; if(instance.Id.Equals(instance.Role.Instances.OrderBy(ins => ins.Id).First().Id)) { // you are in the single master } 

Now you need to select the wizard for "Healing" / recycling. You need to get the RoleEnvironment Changed event. Check that it is a TopologyChange (just check if this topological change has changed, you do not need an exact topology change). And if it is a Topological change, choose the next wizard based on the above algorithm. Check out this great blog post on how to accurately bind and change events.

Forgot to add.

If you like locks - renting a blob is the best way to acquire / check locks. However, working only with RoleEnvironment events and simple wizard selections based on instance ID, I don’t think you need this complicated locking mechanism. In addition, everything runs in the queue until it is successfully processed. . Therefore, if a master dies before he processes something, the “next master” will process it.

+5
source

Source: https://habr.com/ru/post/1444455/


All Articles