use of com.hazelcast.nio.Address in project neo4j by neo4j.
the class HazelcastClusterTopologyTest method shouldLogAndExcludeMembersWithMissingAttributes.
@Test
public void shouldLogAndExcludeMembersWithMissingAttributes() throws Exception {
// given
Set<Member> hazelcastMembers = new HashSet<>();
List<MemberId> coreMembers = new ArrayList<>();
for (int i = 0; i < 4; i++) {
MemberId memberId = new MemberId(UUID.randomUUID());
coreMembers.add(memberId);
Config config = Config.defaults();
HashMap<String, String> settings = new HashMap<>();
settings.put(new BoltConnector("bolt").type.name(), "BOLT");
settings.put(new BoltConnector("bolt").enabled.name(), "true");
settings.put(new BoltConnector("bolt").advertised_address.name(), "bolt:" + (i + 1));
settings.put(new BoltConnector("http").type.name(), "HTTP");
settings.put(new BoltConnector("http").enabled.name(), "true");
settings.put(new BoltConnector("http").advertised_address.name(), "http:" + (i + 1));
config.augment(settings);
Map<String, Object> attributes = buildMemberAttributesForCore(memberId, config).getAttributes();
if (i == 2) {
attributes.remove(HazelcastClusterTopology.RAFT_SERVER);
}
hazelcastMembers.add(new MemberImpl(new Address("localhost", i), null, attributes, false));
}
// when
Map<MemberId, CoreServerInfo> map = toCoreMemberMap(hazelcastMembers, NullLog.getInstance(), hzInstance);
// then
assertThat(map.keySet(), hasItems(coreMembers.get(0), coreMembers.get(1), coreMembers.get(3)));
assertThat(map.keySet(), not(hasItems(coreMembers.get(2))));
}
use of com.hazelcast.nio.Address in project hazelcast by hazelcast.
the class ClusterHeartbeatManager method sendMasterConfirmation.
/**
* Sends a {@link MasterConfirmationOperation} to the master if this node is joined, it is not in the
* {@link NodeState#SHUT_DOWN} state and is not the master node.
*/
public void sendMasterConfirmation() {
if (!node.joined() || node.getState() == NodeState.SHUT_DOWN || node.isMaster()) {
return;
}
Address masterAddress = node.getMasterAddress();
if (masterAddress == null) {
logger.fine("Could not send MasterConfirmation, masterAddress is null!");
return;
}
MemberImpl masterMember = clusterService.getMember(masterAddress);
if (masterMember == null) {
logger.fine("Could not send MasterConfirmation, masterMember is null!");
return;
}
if (logger.isFineEnabled()) {
logger.fine("Sending MasterConfirmation to " + masterMember);
}
nodeEngine.getOperationService().send(new MasterConfirmationOperation(clusterClock.getClusterTime()), masterAddress);
}
use of com.hazelcast.nio.Address in project hazelcast by hazelcast.
the class ClusterJoinManager method checkIfJoinRequestFromAnExistingMember.
private boolean checkIfJoinRequestFromAnExistingMember(JoinMessage joinMessage, Connection connection) {
Address target = joinMessage.getAddress();
MemberImpl member = clusterService.getMember(target);
if (member == null) {
return checkIfUsingAnExistingMemberUuid(joinMessage);
}
if (joinMessage.getUuid().equals(member.getUuid())) {
sendMasterAnswer(target);
if (node.isMaster()) {
if (logger.isFineEnabled()) {
logger.fine(format("Ignoring join request, member already exists: %s", joinMessage));
}
// send members update back to node trying to join again...
Operation[] postJoinOps = nodeEngine.getPostJoinOperations();
boolean isPostJoinOperation = postJoinOps != null && postJoinOps.length > 0;
PostJoinOperation postJoinOp = isPostJoinOperation ? new PostJoinOperation(postJoinOps) : null;
PartitionRuntimeState partitionRuntimeState = node.getPartitionService().createPartitionState();
List<MemberInfo> memberInfos = createMemberInfoList(clusterService.getMemberImpls());
Operation operation = new FinalizeJoinOperation(member.getUuid(), memberInfos, postJoinOp, clusterClock.getClusterTime(), clusterService.getClusterId(), clusterClock.getClusterStartTime(), clusterStateManager.getState(), clusterService.getClusterVersion(), partitionRuntimeState, false);
nodeEngine.getOperationService().send(operation, target);
}
return true;
}
// and wants to join back, so drop old member and process join request if this node becomes master
if (node.isMaster() || target.equals(node.getMasterAddress())) {
String msg = format("New join request has been received from an existing endpoint %s." + " Removing old member and processing join request...", member);
logger.warning(msg);
clusterService.doRemoveAddress(target, msg, false);
Connection existing = node.connectionManager.getConnection(target);
if (existing != connection) {
if (existing != null) {
existing.close(msg, null);
}
node.connectionManager.registerConnection(target, connection);
}
return false;
}
return true;
}
use of com.hazelcast.nio.Address in project hazelcast by hazelcast.
the class ClusterServiceImpl method repairPartitionTableIfReturningMember.
private void repairPartitionTableIfReturningMember(MemberImpl member) {
if (!isMaster()) {
return;
}
if (getClusterState() == ClusterState.ACTIVE) {
return;
}
if (!node.getNodeExtension().isStartCompleted()) {
return;
}
Address address = member.getAddress();
MemberImpl memberRemovedWhileClusterIsNotActive = getMemberRemovedWhileClusterIsNotActive(member.getUuid());
if (memberRemovedWhileClusterIsNotActive != null) {
Address oldAddress = memberRemovedWhileClusterIsNotActive.getAddress();
if (!oldAddress.equals(address)) {
assert !isMemberRemovedWhileClusterIsNotActive(address);
logger.warning(member + " is returning with a new address. Old one was: " + oldAddress + ". Will update partition table with the new address.");
InternalPartitionServiceImpl partitionService = node.partitionService;
partitionService.replaceAddress(oldAddress, address);
}
}
}
use of com.hazelcast.nio.Address in project hazelcast by hazelcast.
the class ClusterServiceImpl method sendMemberRemoveOperation.
private void sendMemberRemoveOperation(Member deadMember) {
for (Member member : getMembers()) {
Address address = member.getAddress();
if (!thisAddress.equals(address) && !address.equals(deadMember.getAddress())) {
MemberRemoveOperation op = new MemberRemoveOperation(deadMember.getAddress(), deadMember.getUuid());
nodeEngine.getOperationService().send(op, address);
}
}
}
Aggregations