我正在编写一种自动重新平衡群集范围的单例管理器,它使用hazelcast的MembershipListener来跟踪上/下事件:
hazelcastInstance.getCluster().addMembershipListener(new MembershipListener() {
@Override
public void memberAdded(MembershipEvent membershipEvent) {
log.info("{}: got memberAdded event {} ", thisInstance, membershipEvent);
rebalanceLiveNodes(membershipEvent.getMembers());
}
@Override
public void memberRemoved(MembershipEvent membershipEvent) {
log.info("{}: got memberRemoved event {} ", thisInstance, membershipEvent);
rebalanceDeadNodes(membershipEvent.getMembers());
}
@Override
public void memberAttributeChanged(MemberAttributeEvent memberAttributeEvent) {
}
});
然而,看起来如果节点重新启动足够快,它就不会触发"删除"事件,但只是"添加":
2015-03-25 16:33:17.736 INFO 21612 --- [ ] [cached.thread-3] n.i.i.m.s.b.AmqpHazelcastBalancer : Member [10.140.140.106]:4242 this: got memberAdded event MembershipEvent {member=Member [10.140.140.107]:4242,type=added}
2015-03-25 16:34:02.408 INFO 21612 --- [ ] [cached.thread-4] n.i.i.m.s.b.AmqpHazelcastBalancer : Member [10.140.140.106]:4242 this: got memberAdded event MembershipEvent {member=Member [10.140.140.108]:4242,type=added}
2015-03-25 16:49:41.160 INFO 26759 --- [ ] [cached.thread-1] n.i.i.m.s.b.AmqpHazelcastBalancer : Member [10.140.140.106]:4242 this: got memberAdded event MembershipEvent {member=Member [10.140.140.108]:4242,type=added}
2015-03-25 16:52:05.635 INFO 29135 --- [ ] [cached.thread-4] n.i.i.m.s.b.AmqpHazelcastBalancer : Member [10.140.140.106]:4242 this: got memberRemoved event MembershipEvent {member=Member [10.140.140.108]:4242,type=removed}
2015-03-25 16:52:20.000 INFO 29135 --- [ ] [cached.thread-5] n.i.i.m.s.b.AmqpHazelcastBalancer : Member [10.140.140.106]:4242 this: got memberAdded event MembershipEvent {member=Member [10.140.140.108]:4242,type=added}
2015-03-25 20:46:29.040 INFO 11780 --- [ ] [cached.thread-3] n.i.i.m.s.b.AmqpHazelcastBalancer : Member [10.140.140.106]:4242 this: got memberAdded event MembershipEvent {member=Member [10.140.140.107]:4242,type=added}
2015-03-25 20:47:04.547 INFO 11780 --- [ ] [cached.thread-6] n.i.i.m.s.b.AmqpHazelcastBalancer : Member [10.140.140.106]:4242 this: got memberAdded event MembershipEvent {member=Member [10.140.140.108]:4242,type=added}
2015-03-26 00:46:39.974 INFO 22198 --- [ ] [cached.thread-4] n.i.i.m.s.b.AmqpHazelcastBalancer : Member [10.140.140.106]:4242 this: got memberAdded event MembershipEvent {member=Member [10.140.140.107]:4242,type=added}
2015-03-26 00:47:17.475 INFO 22198 --- [ ] [cached.thread-5] n.i.i.m.s.b.AmqpHazelcastBalancer : Member [10.140.140.106]:4242 this: got memberAdded event MembershipEvent {member=Member [10.140.140.108]:4242,type=added}
2015-03-26 04:46:50.135 INFO 31576 --- [ ] [cached.thread-2] n.i.i.m.s.b.AmqpHazelcastBalancer : Member [10.140.140.106]:4242 this: got memberAdded event MembershipEvent {member=Member [10.140.140.107]:4242,type=added}
2015-03-26 04:47:30.472 INFO 31576 --- [ ] [cached.thread-1] n.i.i.m.s.b.AmqpHazelcastBalancer : Member [10.140.140.106]:4242 this: got memberAdded event MembershipEvent {member=Member [10.140.140.108]:4242,type=added}
2015-03-26 08:46:25.538 INFO 9252 --- [ ] [cached.thread-4] n.i.i.m.s.b.AmqpHazelcastBalancer : Member [10.140.140.106]:4242 this: got memberAdded event MembershipEvent {member=Member [10.140.140.107]:4242,type=added}
2015-03-26 08:47:02.734 INFO 9252 --- [ ] [cached.thread-3] n.i.i.m.s.b.AmqpHazelcastBalancer : Member [10.140.140.106]:4242 this: got memberAdded event MembershipEvent {member=Member [10.140.140.108]:4242,type=added}
2015-03-26 12:46:32.546 INFO 18528 --- [ ] [cached.thread-1] n.i.i.m.s.b.AmqpHazelcastBalancer : Member [10.140.140.106]:4242 this: got memberAdded event MembershipEvent {member=Member [10.140.140.107]:4242,type=added}
2015-03-26 12:47:14.577 INFO 18528 --- [ ] [cached.thread-4] n.i.i.m.s.b.AmqpHazelcastBalancer : Member [10.140.140.106]:4242 this: got memberAdded event MembershipEvent {member=Member [10.140.140.108]:4242,type=added}
我们使用Hazelcast 3.2。 不接受"删除"是否正常节点重启的事件?..