use of com.hazelcast.cluster.Address in project hazelcast by hazelcast.
the class MulticastJoiner method searchForOtherClusters.
@Override
public void searchForOtherClusters() {
node.multicastService.send(node.createSplitBrainJoinMessage());
SplitBrainJoinMessage splitBrainMsg;
try {
while ((splitBrainMsg = splitBrainJoinMessages.poll(3, TimeUnit.SECONDS)) != null) {
if (logger.isFineEnabled()) {
logger.fine("Received " + splitBrainMsg);
}
Address targetAddress = splitBrainMsg.getAddress();
if (node.clusterService.getMember(targetAddress) != null) {
if (logger.isFineEnabled()) {
logger.fine("Ignoring merge join response, since " + targetAddress + " is already a member.");
}
continue;
}
SplitBrainJoinMessage request = node.createSplitBrainJoinMessage();
SplitBrainMergeCheckResult result = sendSplitBrainJoinMessageAndCheckResponse(targetAddress, request);
if (result == SplitBrainMergeCheckResult.LOCAL_NODE_SHOULD_MERGE) {
logger.warning(node.getThisAddress() + " is merging [multicast] to " + targetAddress);
startClusterMerge(targetAddress, clusterService.getMemberListVersion());
return;
}
if (result == SplitBrainMergeCheckResult.REMOTE_NODE_SHOULD_MERGE) {
// other side should join to us. broadcast a new SplitBrainJoinMessage.
node.multicastService.send(node.createSplitBrainJoinMessage());
}
}
} catch (InterruptedException e) {
currentThread().interrupt();
logger.fine(e);
} catch (Exception e) {
logger.warning(e);
}
}
use of com.hazelcast.cluster.Address in project hazelcast by hazelcast.
the class MembershipManager method removeMember.
private void removeMember(MemberImpl member, String reason, boolean shouldCloseConn) {
clusterServiceLock.lock();
try {
assert clusterService.isMaster() : "Master: " + clusterService.getMasterAddress();
if (!clusterService.isJoined()) {
logger.warning("Not removing " + member + " for reason: " + reason + ", because not joined!");
return;
}
Address address = member.getAddress();
if (shouldCloseConn) {
closeConnections(address, reason);
}
MemberMap currentMembers = memberMapRef.get();
if (currentMembers.getMember(address, member.getUuid()) == null) {
if (logger.isFineEnabled()) {
logger.fine("No need to remove " + member + ", not a member.");
}
return;
}
logger.info("Removing " + member);
clusterService.getClusterJoinManager().removeJoin(address);
clusterService.getClusterJoinManager().addLeftMember(member);
clusterService.getClusterHeartbeatManager().removeMember(member);
partialDisconnectionHandler.removeMember(member);
MemberMap newMembers = MemberMap.cloneExcluding(currentMembers, member);
setMembers(newMembers);
node.getNodeExtension().getAuditlogService().eventBuilder(AuditlogTypeIds.CLUSTER_MEMBER_SUSPECTED).message("Member is removed").addParameter("address", address).addParameter("reason", reason).log();
if (logger.isFineEnabled()) {
logger.fine(member + " is removed. Publishing new member list.");
}
sendMemberListToOthers();
handleMemberRemove(newMembers, member);
clusterService.printMemberList();
} finally {
clusterServiceLock.unlock();
}
}
use of com.hazelcast.cluster.Address in project hazelcast by hazelcast.
the class MembershipManager method fetchMembersViewFromNewMembers.
private boolean fetchMembersViewFromNewMembers(MembersView membersView, Map<MemberInfo, Future<MembersView>> futures) {
boolean isNewMemberPresent = false;
for (MemberInfo member : membersView.getMembers()) {
Address memberAddress = member.getAddress();
if (!(node.getThisAddress().equals(memberAddress) || isMemberSuspected(new MemberImpl(member.getAddress(), member.getVersion(), false, member.getUuid())) || futures.containsKey(member))) {
// this is a new member for us. lets ask its members view
if (logger.isFineEnabled()) {
logger.fine("Asking MembersView of " + memberAddress);
}
futures.put(member, invokeFetchMembersViewOp(memberAddress, member.getUuid()));
isNewMemberPresent = true;
}
}
return isNewMemberPresent;
}
use of com.hazelcast.cluster.Address in project hazelcast by hazelcast.
the class MembershipManager method updateMembers.
// handles both new and left members
void updateMembers(MembersView membersView) {
MemberMap currentMemberMap = memberMapRef.get();
Collection<MemberImpl> addedMembers = new LinkedList<>();
Collection<MemberImpl> removedMembers = new LinkedList<>();
ClusterHeartbeatManager clusterHeartbeatManager = clusterService.getClusterHeartbeatManager();
MemberImpl[] members = new MemberImpl[membersView.size()];
int memberIndex = 0;
// Indicates whether we received a notification on lite member membership change
// (e.g. its promotion to a data member)
boolean updatedLiteMember = false;
for (MemberInfo memberInfo : membersView.getMembers()) {
Address address = memberInfo.getAddress();
MemberImpl member = currentMemberMap.getMember(address);
if (member != null && member.getUuid().equals(memberInfo.getUuid())) {
if (member.isLiteMember()) {
updatedLiteMember = true;
}
member = createNewMemberImplIfChanged(memberInfo, member);
members[memberIndex++] = member;
continue;
}
if (member != null) {
assert !(member.localMember() && member.equals(getLocalMember())) : "Local " + member + " cannot be replaced with " + memberInfo;
// UUID changed: means member has gone and come back with a new uuid
removedMembers.add(member);
}
member = createMember(memberInfo, memberInfo.getAttributes());
addedMembers.add(member);
long now = clusterService.getClusterTime();
clusterHeartbeatManager.onHeartbeat(member, now);
repairPartitionTableIfReturningMember(member);
members[memberIndex++] = member;
}
MemberMap newMemberMap = membersView.toMemberMap();
for (MemberImpl member : currentMemberMap.getMembers()) {
if (!newMemberMap.contains(member.getAddress())) {
removedMembers.add(member);
}
}
setMembers(MemberMap.createNew(membersView.getVersion(), members));
if (updatedLiteMember) {
node.partitionService.updateMemberGroupSize();
}
for (MemberImpl member : removedMembers) {
closeConnections(member.getAddress(), "Member left event received from master");
handleMemberRemove(memberMapRef.get(), member);
}
clusterService.getClusterJoinManager().insertIntoRecentlyJoinedMemberSet(addedMembers);
sendMembershipEvents(currentMemberMap.getMembers(), addedMembers, !clusterService.isJoined());
removeFromMissingMembers(members);
clusterHeartbeatManager.heartbeat();
clusterService.printMemberList();
// async call
node.getNodeExtension().scheduleClusterVersionAutoUpgrade();
}
use of com.hazelcast.cluster.Address in project hazelcast by hazelcast.
the class MembershipManager method clearMemberSuspicion.
boolean clearMemberSuspicion(MemberImpl member, String reason) {
clusterServiceLock.lock();
try {
if (!isMemberSuspected(member)) {
return true;
}
MemberMap memberMap = getMemberMap();
Address masterAddress = clusterService.getMasterAddress();
if (memberMap.isBeforeThan(member.getAddress(), masterAddress)) {
if (logger.isFineEnabled()) {
logger.fine("Not removing suspicion of " + member + " since it is before than current master " + masterAddress + " in member list.");
}
return false;
}
if (suspectedMembers.remove(member)) {
logger.info("Removed suspicion of " + member + ". Reason: " + reason);
}
} finally {
clusterServiceLock.unlock();
}
return true;
}
Aggregations