use of com.hazelcast.cluster.Address in project hazelcast by hazelcast.
the class InternalPartitionServiceImpl method onShutdown.
@Override
public boolean onShutdown(long timeout, TimeUnit unit) {
if (!node.getClusterService().isJoined()) {
return true;
}
if (node.isLiteMember()) {
return true;
}
CountDownLatch latch = getShutdownLatch();
OperationServiceImpl operationService = nodeEngine.getOperationService();
long timeoutMillis = unit.toMillis(timeout);
long awaitStep = Math.min(SAFE_SHUTDOWN_MAX_AWAIT_STEP_MILLIS, timeoutMillis);
try {
do {
Address masterAddress = nodeEngine.getMasterAddress();
if (masterAddress == null) {
logger.warning("Safe shutdown failed, master member is not known!");
return false;
}
if (node.getThisAddress().equals(masterAddress)) {
onShutdownRequest(node.getLocalMember());
} else {
operationService.send(new ShutdownRequestOperation(), masterAddress);
}
if (latch.await(awaitStep, TimeUnit.MILLISECONDS)) {
return true;
}
timeoutMillis -= awaitStep;
} while (timeoutMillis > 0);
} catch (InterruptedException e) {
currentThread().interrupt();
logger.info("Safe shutdown is interrupted!");
}
return false;
}
use of com.hazelcast.cluster.Address in project hazelcast by hazelcast.
the class InternalPartitionServiceImpl method requestMemberListUpdateIfUnknownMembersFound.
private void requestMemberListUpdateIfUnknownMembersFound(Address sender, InternalPartition[] partitions) {
ClusterServiceImpl clusterService = node.clusterService;
ClusterState clusterState = clusterService.getClusterState();
Set<PartitionReplica> unknownReplicas = new HashSet<>();
for (InternalPartition partition : partitions) {
for (int index = 0; index < InternalPartition.MAX_REPLICA_COUNT; index++) {
PartitionReplica replica = partition.getReplica(index);
if (replica == null) {
continue;
}
if (node.clusterService.getMember(replica.address(), replica.uuid()) == null && (clusterState.isJoinAllowed() || !clusterService.isMissingMember(replica.address(), replica.uuid()))) {
unknownReplicas.add(replica);
}
}
}
if (!unknownReplicas.isEmpty()) {
if (logger.isWarningEnabled()) {
StringBuilder s = new StringBuilder("Following unknown addresses are found in partition table").append(" sent from master[").append(sender).append("].").append(" (Probably they have recently joined or left the cluster.)").append(" {");
for (PartitionReplica replica : unknownReplicas) {
s.append("\n\t").append(replica);
}
s.append("\n}");
logger.warning(s.toString());
}
Address masterAddress = node.getClusterService().getMasterAddress();
// If node is shutting down, master can be null.
if (masterAddress != null && !masterAddress.equals(node.getThisAddress())) {
// unknown addresses found in partition table, request a new member-list from master
nodeEngine.getOperationService().send(new TriggerMemberListPublishOp(), masterAddress);
}
}
}
use of com.hazelcast.cluster.Address in project hazelcast by hazelcast.
the class PartitionServiceProxy method isClusterSafe.
@Override
public boolean isClusterSafe() {
Collection<Member> members = nodeEngine.getClusterService().getMembers();
if (members == null || members.isEmpty()) {
return true;
}
final Collection<Future<Boolean>> futures = new ArrayList<>(members.size());
for (Member member : members) {
final Address target = member.getAddress();
final Operation operation = new SafeStateCheckOperation();
final Future<Boolean> future = nodeEngine.getOperationService().invokeOnTarget(InternalPartitionService.SERVICE_NAME, operation, target);
futures.add(future);
}
// todo this max wait is appropriate?
final int maxWaitTime = getMaxWaitTime();
Collection<Boolean> results = FutureUtil.returnWithDeadline(futures, maxWaitTime, TimeUnit.SECONDS, exceptionHandler);
if (results.size() != futures.size()) {
return false;
}
for (Boolean result : results) {
if (!result) {
return false;
}
}
return true;
}
use of com.hazelcast.cluster.Address in project hazelcast by hazelcast.
the class TcpServerConnectionManager method register.
@Override
public synchronized boolean register(Address primaryAddress, Address targetAddress, Collection<Address> remoteAddressAliases, UUID remoteUuid, final ServerConnection c, int planeIndex) {
Plane plane = planes[planeIndex];
TcpServerConnection connection = (TcpServerConnection) c;
try {
if (!connection.isAlive()) {
if (logger.isFinestEnabled()) {
logger.finest(connection + " to " + remoteUuid + " is not registered since connection is not active.");
}
return false;
}
connection.setRemoteAddress(primaryAddress);
connection.setRemoteUuid(remoteUuid);
if (!connection.isClient()) {
connection.setErrorHandler(getErrorHandler(primaryAddress, plane.index).reset());
}
registerAddresses(remoteUuid, primaryAddress, targetAddress, remoteAddressAliases);
// handle self connection
if (remoteUuid.equals(serverContext.getThisUuid())) {
connection.close("Connecting to self!", null);
return false;
}
plane.putConnection(remoteUuid, connection);
serverContext.getEventService().executeEventCallback(new StripedRunnable() {
@Override
public void run() {
connectionListeners.forEach(listener -> listener.connectionAdded(connection));
}
@Override
public int getKey() {
return primaryAddress.hashCode();
}
});
return true;
} finally {
if (targetAddress != null) {
plane.removeConnectionInProgress(targetAddress);
}
}
}
use of com.hazelcast.cluster.Address in project hazelcast by hazelcast.
the class TcpServerControl method process.
private synchronized void process(TcpServerConnection connection, MemberHandshake handshake) {
if (logger.isFinestEnabled()) {
logger.finest("Handshake " + connection + ", complete message is " + handshake);
}
Map<ProtocolType, Collection<Address>> remoteAddressesPerProtocolType = handshake.getLocalAddresses();
List<Address> allAliases = new ArrayList<>();
// public address in address registration phase
if (supportedProtocolTypes.contains(ProtocolType.MEMBER) && remoteAddressesPerProtocolType.containsKey(ProtocolType.MEMBER)) {
allAliases.addAll(remoteAddressesPerProtocolType.remove(ProtocolType.MEMBER));
}
for (Map.Entry<ProtocolType, Collection<Address>> remoteAddresses : remoteAddressesPerProtocolType.entrySet()) {
if (supportedProtocolTypes.contains(remoteAddresses.getKey())) {
allAliases.addAll(remoteAddresses.getValue());
}
}
// key 192.168.1.1:5701.
assert (connectionManager.getEndpointQualifier() != EndpointQualifier.MEMBER || connection.getConnectionType().equals(ConnectionType.MEMBER)) : "When handling MEMBER connections, connection type" + " must be already set";
boolean isMemberConnection = (connection.getConnectionType().equals(ConnectionType.MEMBER) && (connectionManager.getEndpointQualifier() == EndpointQualifier.MEMBER || unifiedEndpointManager));
boolean mustRegisterRemoteSocketAddress = !handshake.isReply();
Address remoteEndpoint = null;
if (isMemberConnection) {
// address of the target member will be set correctly in TcpIpConnection.setEndpoint.
if (mustRegisterRemoteSocketAddress) {
allAliases.add(new Address(connection.getRemoteSocketAddress()));
}
} else {
// when not a member connection, register the remote socket address
remoteEndpoint = new Address(connection.getRemoteSocketAddress());
}
process0(connection, remoteEndpoint, allAliases, handshake);
}
Aggregations