Search in sources :

Example 71 with Address

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;
}
Also used : Address(com.hazelcast.cluster.Address) CountDownLatch(java.util.concurrent.CountDownLatch) ShutdownRequestOperation(com.hazelcast.internal.partition.operation.ShutdownRequestOperation) OperationServiceImpl(com.hazelcast.spi.impl.operationservice.impl.OperationServiceImpl)

Example 72 with Address

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);
        }
    }
}
Also used : ClusterState(com.hazelcast.cluster.ClusterState) Address(com.hazelcast.cluster.Address) PartitionReplica(com.hazelcast.internal.partition.PartitionReplica) ClusterServiceImpl(com.hazelcast.internal.cluster.impl.ClusterServiceImpl) InternalPartition(com.hazelcast.internal.partition.InternalPartition) ReadonlyInternalPartition(com.hazelcast.internal.partition.ReadonlyInternalPartition) TriggerMemberListPublishOp(com.hazelcast.internal.cluster.impl.operations.TriggerMemberListPublishOp) HashSet(java.util.HashSet)

Example 73 with Address

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;
}
Also used : Address(com.hazelcast.cluster.Address) SafeStateCheckOperation(com.hazelcast.internal.partition.operation.SafeStateCheckOperation) ArrayList(java.util.ArrayList) InvocationFuture(com.hazelcast.spi.impl.operationservice.impl.InvocationFuture) Future(java.util.concurrent.Future) Operation(com.hazelcast.spi.impl.operationservice.Operation) SafeStateCheckOperation(com.hazelcast.internal.partition.operation.SafeStateCheckOperation) Member(com.hazelcast.cluster.Member)

Example 74 with Address

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);
        }
    }
}
Also used : REST_CLIENT(com.hazelcast.internal.nio.ConnectionType.REST_CLIENT) Address(com.hazelcast.cluster.Address) TCP_TAG_ENDPOINT(com.hazelcast.internal.metrics.MetricDescriptorConstants.TCP_TAG_ENDPOINT) ServerConnection(com.hazelcast.internal.server.ServerConnection) TimeoutException(java.util.concurrent.TimeoutException) Packet(com.hazelcast.internal.nio.Packet) TCP_PREFIX_CONNECTION(com.hazelcast.internal.metrics.MetricDescriptorConstants.TCP_PREFIX_CONNECTION) TCP_METRIC_ENDPOINT_MANAGER_IN_PROGRESS_COUNT(com.hazelcast.internal.metrics.MetricDescriptorConstants.TCP_METRIC_ENDPOINT_MANAGER_IN_PROGRESS_COUNT) Future(java.util.concurrent.Future) SocketChannel(java.nio.channels.SocketChannel) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Map(java.util.Map) DynamicMetricsProvider(com.hazelcast.internal.metrics.DynamicMetricsProvider) ChannelInitializer(com.hazelcast.internal.networking.ChannelInitializer) TCP_DISCRIMINATOR_BINDADDRESS(com.hazelcast.internal.metrics.MetricDescriptorConstants.TCP_DISCRIMINATOR_BINDADDRESS) ServerContext(com.hazelcast.internal.server.ServerContext) Probe(com.hazelcast.internal.metrics.Probe) Collection(java.util.Collection) ExceptionUtil(com.hazelcast.internal.util.ExceptionUtil) Set(java.util.Set) IOUtil.close(com.hazelcast.internal.nio.IOUtil.close) UUID(java.util.UUID) EndpointConfig(com.hazelcast.config.EndpointConfig) Collectors(java.util.stream.Collectors) Objects(java.util.Objects) List(java.util.List) TCP_METRIC_CLIENT_COUNT(com.hazelcast.internal.metrics.MetricDescriptorConstants.TCP_METRIC_CLIENT_COUNT) Arrays.stream(java.util.Arrays.stream) MANDATORY(com.hazelcast.internal.metrics.ProbeLevel.MANDATORY) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) TCP_DISCRIMINATOR_ENDPOINT(com.hazelcast.internal.metrics.MetricDescriptorConstants.TCP_DISCRIMINATOR_ENDPOINT) Function(java.util.function.Function) ProtocolType(com.hazelcast.instance.ProtocolType) IOUtil.setChannelOptions(com.hazelcast.internal.nio.IOUtil.setChannelOptions) MetricDescriptor(com.hazelcast.internal.metrics.MetricDescriptor) NetworkStats(com.hazelcast.internal.server.NetworkStats) Networking(com.hazelcast.internal.networking.Networking) Nonnull(javax.annotation.Nonnull) ConnectionListener(com.hazelcast.internal.nio.ConnectionListener) IOUtil(com.hazelcast.internal.nio.IOUtil) COUNT(com.hazelcast.internal.metrics.ProbeUnit.COUNT) EndpointQualifier(com.hazelcast.instance.EndpointQualifier) StripedRunnable(com.hazelcast.internal.util.executor.StripedRunnable) MetricsCollectionContext(com.hazelcast.internal.metrics.MetricsCollectionContext) MEMCACHE_CLIENT(com.hazelcast.internal.nio.ConnectionType.MEMCACHE_CLIENT) IOException(java.io.IOException) Preconditions.checkNotNull(com.hazelcast.internal.util.Preconditions.checkNotNull) Channel(com.hazelcast.internal.networking.Channel) ExecutionException(java.util.concurrent.ExecutionException) TimeUnit(java.util.concurrent.TimeUnit) Consumer(java.util.function.Consumer) Collections.unmodifiableSet(java.util.Collections.unmodifiableSet) TCP_METRIC_ENDPOINT_MANAGER_COUNT(com.hazelcast.internal.metrics.MetricDescriptorConstants.TCP_METRIC_ENDPOINT_MANAGER_COUNT) Collections(java.util.Collections) TCP_METRIC_TEXT_COUNT(com.hazelcast.internal.metrics.MetricDescriptorConstants.TCP_METRIC_TEXT_COUNT) StripedRunnable(com.hazelcast.internal.util.executor.StripedRunnable)

Example 75 with Address

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);
}
Also used : Address(com.hazelcast.cluster.Address) ProtocolType(com.hazelcast.instance.ProtocolType) ArrayList(java.util.ArrayList) Collection(java.util.Collection) Map(java.util.Map)

Aggregations

Address (com.hazelcast.cluster.Address)540 Test (org.junit.Test)211 QuickTest (com.hazelcast.test.annotation.QuickTest)191 ParallelJVMTest (com.hazelcast.test.annotation.ParallelJVMTest)178 HazelcastInstance (com.hazelcast.core.HazelcastInstance)92 InetAddress (java.net.InetAddress)75 ArrayList (java.util.ArrayList)66 Member (com.hazelcast.cluster.Member)63 Accessors.getAddress (com.hazelcast.test.Accessors.getAddress)54 MemberImpl (com.hazelcast.cluster.impl.MemberImpl)48 Config (com.hazelcast.config.Config)43 PartitionReplica (com.hazelcast.internal.partition.PartitionReplica)43 UUID (java.util.UUID)43 ILogger (com.hazelcast.logging.ILogger)37 HashMap (java.util.HashMap)36 Operation (com.hazelcast.spi.impl.operationservice.Operation)35 List (java.util.List)35 OperationService (com.hazelcast.spi.impl.operationservice.OperationService)34 Map (java.util.Map)33 InetSocketAddress (java.net.InetSocketAddress)32