Windows Azure-无单点故障的领导者实例 [英] Windows Azure - leader instance without single point of failure

查看:46
本文介绍了Windows Azure-无单点故障的领导者实例的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在寻找一种在多个辅助角色实例上具有"Singleton"模块的方法.我想在Azure中建立一个具有队列和多个工作角色的并行执行模型.

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

这个想法是想拥有一个主"实例,即检查新数据,并通过将其添加到队列中进行调度,处理来自特殊队列的所有消息,没有其他人,并且已将blob存储安装为具有读取/写入访问权限的虚拟驱动器.

The idea is that would like to have a "master" instance, that is let's say checking for new data, and is scheduling it by adding it to a queue, processing all messages from a special queue, that is not processed by nobody else, and has mounted blob storage as a virtual drive, with read/write access.

我将始终只有主实例".当该主实例由于某种原因而关闭时,已经实例化的另一个实例应非常快地选出"一个主实例(几秒钟).这应该在Azure环境将损坏的实例替换为新实例之前发生(大约15分钟).

I will always have only one "master instance". When that master instance goes down for some reason, another instance from the one already instantiated should very quickly be "elected" for a master instance (couple of seconds). This should happen before the broken instance is replaced by a new one by the Azure environment (about 15 min).

因此它将是某种自组织的动态环境.我当时正在考虑基于存储或表数据进行一些锁定.如果我们可以与微处理器术语进行交谈,则有机会设置锁定超时和某种看门狗"计时器.

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

推荐答案

对于要实现的目标,有通用的方法.

There is general approach to what you seek to achieve.

首先,您的主实例.您可以根据实例ID进行检查.这很容易.您需要 RoleEnvironment.CurrentRoleInstance 来获取当前实例",现在比较="nofollow noreferrer"> RoleEnvironment.CurrentRoleInstance.Role.Instances 由ID排序的第一个成员.像这样:

First, your master instance. You could do your check based on instance ID. It is fairly easy. You need RoleEnvironment.CurrentRoleInstance to get the "Current instance", now compare the Id property with what you get out of RoleEnvironment.CurrentRoleInstance.Role.Instances first member ordered by Id. Something like:

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

现在,您需要在修复"/回收上选举主人.您需要获取RoleEnvironment的已更改事件.检查它是否为 TopologyChange (只需检查无论是拓扑更改,您都不需要拓扑的确切更改).如果是拓扑更改,请根据上述算法选择下一个主机.查看这个很棒的博客发布有关如何准确执行事件挂钩和更改检测.

Now you need to elect master upon "Healing"/recycling. You need to get the RoleEnvironment's Changed event. Check if it is TopologyChange (just check whether it is topology change, you don't need the exact change in topology). And if it is Topology Change - elect the next master based on the above algorithm. Check out this great blog post on how to exactly perform events hooking and change detection.

忘记添加.

如果您喜欢锁-Blob租约是获取/检查锁的最佳方法.但是,仅使用RoleEnvironment事件和基于实例ID的简单主选举,我认为您不需要那种复杂的锁定机制.此外-一切都在队列中,直到成功被处理.因此,如果母版在处理某些东西之前就死了,那么下一个母版"将对其进行处理.

If you like locks - blob lease is the best way to acquire / check locks. However working with just the RoleEnvironment events and the simple master election based on Instance ID, I don't think you'll need that complicated locking mechanism. Besides - everything lives in the Queue until it is successfully processed. So if the master dies before it processes something, the "next master" will process it.

这篇关于Windows Azure-无单点故障的领导者实例的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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