Windows Azure的 - 没有failiure的单点领导者的实例 [英] Windows Azure - leader instance without single point of failiure

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

问题描述

我要寻找一种方式来拥有在多个工作者角色实例的单身模块。
我想有在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.

我会永远的仅一个主实例。当该主实例关闭由于某些原因,从已经实例化的另一个实例应该非常迅速地选出为一个主实例(几秒钟)。破碎的实例是通过由天青环境(约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.

任何其他想法的实施或例子是AP preciated。

Any other implementation ideas or examples are appreciated.

推荐答案

有普遍的方法来你寻求达到的目标。

There is general approach to what you seek to achieve.

首先,你的主实例。你可以基于实例ID做你检查。这是相当容易的。您需要<一个href=\"http://msdn.microsoft.com/en-us/library/microsoft.windowsazure.serviceruntime.roleenvironment.currentroleinstance.aspx\">RoleEnvironment.CurrentRoleInstance获得当前实例,现在比较<一个href=\"http://msdn.microsoft.com/en-us/library/windowsazure/microsoft.windowsazure.serviceruntime.roleinstance.id.aspx\">Id物业与你得到了什么出<一个href=\"http://msdn.microsoft.com/en-us/library/windowsazure/microsoft.windowsazure.serviceruntime.role.instances.aspx\">RoleEnvironment.CurrentRoleInstance.Role.Instances通过编号排序第一个成员。是这样的:

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的<一个href=\"http://msdn.microsoft.com/en-us/library/microsoft.windowsazure.serviceruntime.roleenvironment.changed.aspx\">Changed事件。检查它是否是<一个href=\"http://msdn.microsoft.com/en-us/library/microsoft.windowsazure.serviceruntime.roleenvironmenttopologychange.aspx\">TopologyChange (只检查是否是拓扑变化,你不需要在拓扑结构中的零钱)。如果它是拓扑变化 - 选出基于上述算法的下一个主。查看<一个href=\"http://brentda$c$cmonkey.word$p$pss.com/2011/09/24/leveraging-the-roleentrypoint-year-of-azure-week-12/\">this伟大的博客帖子上如何准确执行挂钩的事件和变化检测。

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的 - 没有failiure的单点领导者的实例的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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