项目需要,在写Master/Slave底层分布式通信模块,它的体系结构图:
通信模式:可以选择Socket和或者Socket之上的RPC协议来进行,考虑到项目的需求,使用了RPC来支持Master和Slave之间的通信。
Master与Slave之间实现互联的功能并不难,但是Master与Slave之间的相互感知功能,Master节点的异常或者Slave节点的宕机,都是在设计时应该考虑的问题。
1)Slave节点正常退出之前,应该通知Master。这个功能通过Slave节点运行时添加Runtime.getRuntime().addShutdownHook(? extends Thread), 的方法来做处理, 在具体的Thread方法中仍然可以使用RPC来通知Master.
2) Slave节点非正常退出,这个原因可能是多方面的。这个由Master根据收到的Slave节点的心跳包的异常,比方说,Master原来是每10s收到一个心跳包,但是Slave A已经1分钟没有发送心跳包了,这时Master会把Slave节点从active列表中取出,然后通过发送ping来验证,Slave后面的端口是否还存在。
3)Master正常退出和非正常宕机,可以将这两点统一对待,因为Master一旦不工作,将会对整个系统的影响是毁灭性的,所以,必须提高LOG的级别为SERVER.
提供Master的容错能力可以通过以下步骤来做:
1) Master退出之后,使用Zookeeper选择一个新的Master,需要对于记录系统执行的详细状态,并持久化到文件中。
2) 准备一个Standby Master, 在开始阶段Standby Master不提供服务,等到一个Master宕机之后,Standby Master开始代替原Master进行工作。
3)Slave节点对于在心跳阶段条件轮询功能,探测Master节点的状态,探测Master节点not available,则对于slave与Master通信的线程,暂时suspend,等到新的master到来之后的notify。
实现一个系统,不仅仅是功能的实现,更多的时候,还有对于整体上的把握,要是每一个模块清晰,透彻,哪怕一个很复杂的功能实现,都要经过一步一步的剖析,直到每一块都是清晰可见
from:http://blog.sina.com.cn/s/blog_4a1f59bf0100nd6c.html
相关推荐
用于指导部署activemq master/slave架构,采用NFS
i2s串行线广泛用于音频通信中,这里包括了master和slave的代码.
Arduino上的MODBUS库,可与PLC等进行MODBUS通讯
mysql master-slave 主从配置的讲解
Xilinx提供的I2C控制器代码,Master/Slave全功能
Master-Slave的数据库机构解决了很多问题,特别是read/write比较高的web2.0应用: 1、写操作全部在Master结点执行,并由Slave数据库结点定时(默认60s)读取Master的bin-log 2、将众多的用户读请求分散到更多的...
F00x_SPI0_EEPROM_Polled_Mode/F00x_SPI0_Master/F00x_SPI0_Slave c source code that can be applied to C8051f00x
master slave tx_rx code master for cc2500
The devices embed four universal synchronous/asynchronous receiver transmitters (USART1, USART2, USART3 and USART6) and four universal asynchronous receiver ...have LIN Master/Slave capability.
verilog实现axis接口读写I2C,代码中包含master/slave两部分 master: axis to I2C slave : I2C to axis
axi协议的vip,包括master和slave
主从多机通信系统问题研究建模即其可靠性研究
cypress gpif config code,auto mode,include master and slave mode.
ARM Keil I2C Peripheral
主从多机通信系统建模仿真,研究各种措施对提高系统可靠性所起的效果
Building Automation House Control with LOGO! 8 and Master-Slave Communication (LOGO! Set 9)
spi master or slave verilog rtl code,include simulation environment
AHB arbiter design for the multi master multi slave implementation
i2cSerialInterface its can be used for serial interfafe(to slave) from master.