use of com.hazelcast.cluster.Address in project hazelcast by hazelcast.
the class MembershipManager method handleExplicitSuspicionTrigger.
void handleExplicitSuspicionTrigger(Address caller, int callerMemberListVersion, MembersViewMetadata suspectedMembersViewMetadata) {
clusterServiceLock.lock();
try {
Address masterAddress = clusterService.getMasterAddress();
int memberListVersion = getMemberListVersion();
if (!(masterAddress.equals(caller) && memberListVersion == callerMemberListVersion)) {
if (logger.isFineEnabled()) {
logger.fine("Ignoring explicit suspicion trigger for " + suspectedMembersViewMetadata + ". Caller: " + caller + ", caller member list version: " + callerMemberListVersion + ", known master: " + masterAddress + ", local member list version: " + memberListVersion);
}
return;
}
clusterService.sendExplicitSuspicion(suspectedMembersViewMetadata);
} finally {
clusterServiceLock.unlock();
}
}
use of com.hazelcast.cluster.Address in project hazelcast by hazelcast.
the class MembershipManager method fetchLatestMembersView.
@SuppressWarnings({ "checkstyle:cyclomaticcomplexity", "checkstyle:npathcomplexity" })
private MembersView fetchLatestMembersView(MemberMap localMemberMap, Set<MemberImpl> members, Map<MemberInfo, Future<MembersView>> futures) {
MembersView latestMembersView = localMemberMap.toTailMembersView(node.getLocalMember(), true);
for (MemberImpl member : members) {
futures.put(new MemberInfo(member), invokeFetchMembersViewOp(member.getAddress(), member.getUuid()));
}
long mastershipClaimTimeout = SECONDS.toMillis(mastershipClaimTimeoutSeconds);
while (clusterService.isJoined()) {
boolean done = true;
for (Entry<MemberInfo, Future<MembersView>> e : new ArrayList<>(futures.entrySet())) {
MemberInfo member = e.getKey();
Address address = member.getAddress();
Future<MembersView> future = e.getValue();
long startNanos = Timer.nanos();
try {
long timeout = min(FETCH_MEMBER_LIST_MILLIS, Math.max(mastershipClaimTimeout, 1));
MembersView membersView = future.get(timeout, MILLISECONDS);
if (membersView.isLaterThan(latestMembersView)) {
if (logger.isFineEnabled()) {
logger.fine("A more recent " + membersView + " is received from " + address);
}
latestMembersView = membersView;
// If we discover a new member via a fetched member list, we should also ask for its members view.
// there are some new members added to the futures map. lets wait for their results.
done &= !fetchMembersViewFromNewMembers(membersView, futures);
}
} catch (InterruptedException ignored) {
Thread.currentThread().interrupt();
} catch (ExecutionException ignored) {
// we couldn't learn MembersView of 'address'. It will be removed from the cluster.
EmptyStatement.ignore(ignored);
} catch (TimeoutException ignored) {
MemberInfo latestMemberInfo = latestMembersView.getMember(address);
MemberImpl memberImpl = new MemberImpl(member.getAddress(), member.getVersion(), false, member.getUuid());
if (mastershipClaimTimeout > 0 && !isMemberSuspected(memberImpl) && latestMemberInfo != null) {
// we don't suspect from 'address' and we need to learn its response
done = false;
// Mastership claim is idempotent.
// We will retry our claim to member until it explicitly rejects or accepts our claim.
// We can't just rely on invocation retries, because if connection is dropped while
// our claim is on the wire, invocation won't get any response and will eventually timeout.
futures.put(latestMemberInfo, invokeFetchMembersViewOp(address, latestMemberInfo.getUuid()));
}
}
mastershipClaimTimeout -= Timer.millisElapsed(startNanos);
}
if (done) {
break;
}
}
return latestMembersView;
}
use of com.hazelcast.cluster.Address in project hazelcast by hazelcast.
the class ClusterDataSerializerHook method createFactory.
@Override
public DataSerializableFactory createFactory() {
ConstructorFunction<Integer, IdentifiedDataSerializable>[] constructors = new ConstructorFunction[LEN];
constructors[AUTH_FAILURE] = arg -> new AuthenticationFailureOp();
constructors[ADDRESS] = arg -> new Address();
constructors[MEMBER] = arg -> new MemberImpl();
constructors[HEARTBEAT] = arg -> new HeartbeatOp();
constructors[CONFIG_CHECK] = arg -> new ConfigCheck();
constructors[MEMBER_HANDSHAKE] = arg -> new MemberHandshake();
constructors[MEMBER_INFO_UPDATE] = arg -> new MembersUpdateOp();
constructors[FINALIZE_JOIN] = arg -> new FinalizeJoinOp();
constructors[BEFORE_JOIN_CHECK_FAILURE] = arg -> new BeforeJoinCheckFailureOp();
constructors[CHANGE_CLUSTER_STATE] = arg -> new CommitClusterStateOp();
constructors[CONFIG_MISMATCH] = arg -> new ConfigMismatchOp();
constructors[CLUSTER_MISMATCH] = arg -> new ClusterMismatchOp();
constructors[SPLIT_BRAIN_MERGE_VALIDATION] = arg -> new SplitBrainMergeValidationOp();
constructors[JOIN_REQUEST_OP] = arg -> new JoinRequestOp();
constructors[LOCK_CLUSTER_STATE] = arg -> new LockClusterStateOp();
constructors[MASTER_CLAIM] = arg -> new JoinMastershipClaimOp();
constructors[WHOIS_MASTER] = arg -> new WhoisMasterOp();
constructors[MERGE_CLUSTERS] = arg -> new MergeClustersOp();
constructors[POST_JOIN] = arg -> new OnJoinOp();
constructors[ROLLBACK_CLUSTER_STATE] = arg -> new RollbackClusterStateOp();
constructors[MASTER_RESPONSE] = arg -> new MasterResponseOp();
constructors[SHUTDOWN_NODE] = arg -> new ShutdownNodeOp();
constructors[TRIGGER_MEMBER_LIST_PUBLISH] = arg -> new TriggerMemberListPublishOp();
constructors[CLUSTER_STATE_TRANSACTION_LOG_RECORD] = arg -> new ClusterStateTransactionLogRecord();
constructors[MEMBER_INFO] = arg -> new MemberInfo();
constructors[JOIN_MESSAGE] = arg -> new JoinMessage();
constructors[JOIN_REQUEST] = arg -> new JoinRequest();
constructors[MIGRATION_INFO] = arg -> new MigrationInfo();
constructors[MEMBER_VERSION] = arg -> new MemberVersion();
constructors[CLUSTER_STATE_CHANGE] = arg -> new ClusterStateChange();
constructors[SPLIT_BRAIN_JOIN_MESSAGE] = arg -> new SplitBrainJoinMessage();
constructors[VERSION] = arg -> new Version();
constructors[FETCH_MEMBER_LIST_STATE] = arg -> new FetchMembersViewOp();
constructors[EXPLICIT_SUSPICION] = arg -> new ExplicitSuspicionOp();
constructors[MEMBERS_VIEW] = arg -> new MembersView();
constructors[TRIGGER_EXPLICIT_SUSPICION] = arg -> new TriggerExplicitSuspicionOp();
constructors[MEMBERS_VIEW_METADATA] = arg -> new MembersViewMetadata();
constructors[HEARTBEAT_COMPLAINT] = arg -> new HeartbeatComplaintOp();
constructors[PROMOTE_LITE_MEMBER] = arg -> new PromoteLiteMemberOp();
constructors[VECTOR_CLOCK] = arg -> new VectorClock();
constructors[ENDPOINT_QUALIFIER] = arg -> new EndpointQualifier();
return new ArrayDataSerializableFactory(constructors);
}
use of com.hazelcast.cluster.Address in project hazelcast by hazelcast.
the class TcpIpJoiner method addPossibleAddresses.
private void addPossibleAddresses(final Set<Address> possibleAddresses, final String host, final InetAddress inetAddress, final int port, final int count) throws UnknownHostException {
for (int i = 0; i < count; i++) {
int currentPort = port + i;
Address address;
if (host != null && inetAddress != null) {
address = new Address(host, inetAddress, currentPort);
} else if (host != null) {
address = new Address(host, currentPort);
} else {
address = new Address(inetAddress, currentPort);
}
if (!isLocalAddress(address)) {
possibleAddresses.add(address);
}
}
}
use of com.hazelcast.cluster.Address in project hazelcast by hazelcast.
the class TcpIpJoiner method searchForOtherClusters.
@Override
public void searchForOtherClusters() {
final Collection<Address> possibleAddresses;
try {
possibleAddresses = getPossibleAddresses();
} catch (Throwable e) {
logger.severe(e);
return;
}
LocalAddressRegistry addressRegistry = node.getLocalAddressRegistry();
possibleAddresses.removeAll(addressRegistry.getLocalAddresses());
node.getClusterService().getMembers().forEach(member -> {
LinkedAddresses addresses = addressRegistry.linkedAddressesOf(member.getUuid());
if (addresses != null) {
Set<Address> knownMemberAddresses = addresses.getAllAddresses();
possibleAddresses.removeAll(knownMemberAddresses);
} else {
// do not expect this case in the normal conditions, except for disconnections happens
// at the same time
possibleAddresses.remove(member.getAddress());
}
});
if (possibleAddresses.isEmpty()) {
return;
}
SplitBrainJoinMessage request = node.createSplitBrainJoinMessage();
for (Address address : possibleAddresses) {
SplitBrainMergeCheckResult result = sendSplitBrainJoinMessageAndCheckResponse(address, request);
if (result == SplitBrainMergeCheckResult.LOCAL_NODE_SHOULD_MERGE) {
logger.warning(node.getThisAddress() + " is merging [tcp/ip] to " + address);
setTargetAddress(address);
startClusterMerge(address, request.getMemberListVersion());
return;
}
}
}
Aggregations