Search in sources :

Example 61 with MemberImpl

use of com.hazelcast.instance.MemberImpl in project hazelcast by hazelcast.

the class InternalPartitionServiceImpl method publishPartitionRuntimeState.

@SuppressWarnings("checkstyle:npathcomplexity")
void publishPartitionRuntimeState() {
    if (!partitionStateManager.isInitialized()) {
        // do not send partition state until initialized!
        return;
    }
    if (!node.isMaster()) {
        return;
    }
    if (!isReplicaSyncAllowed()) {
        // migration is disabled because of a member leave, wait till enabled!
        return;
    }
    PartitionRuntimeState partitionState = createPartitionStateInternal();
    if (partitionState == null) {
        return;
    }
    if (logger.isFineEnabled()) {
        logger.fine("Publishing partition state, version: " + partitionState.getVersion());
    }
    PartitionStateOperation op = new PartitionStateOperation(partitionState);
    OperationService operationService = nodeEngine.getOperationService();
    Collection<MemberImpl> members = node.clusterService.getMemberImpls();
    for (MemberImpl member : members) {
        if (!member.localMember()) {
            try {
                operationService.send(op, member.getAddress());
            } catch (Exception e) {
                logger.finest(e);
            }
        }
    }
}
Also used : MemberImpl(com.hazelcast.instance.MemberImpl) PartitionRuntimeState(com.hazelcast.internal.partition.PartitionRuntimeState) OperationService(com.hazelcast.spi.OperationService) InternalOperationService(com.hazelcast.spi.impl.operationservice.InternalOperationService) FetchPartitionStateOperation(com.hazelcast.internal.partition.operation.FetchPartitionStateOperation) PartitionStateOperation(com.hazelcast.internal.partition.operation.PartitionStateOperation) HazelcastInstanceNotActiveException(com.hazelcast.core.HazelcastInstanceNotActiveException) TargetNotMemberException(com.hazelcast.spi.exception.TargetNotMemberException) NoDataMemberInClusterException(com.hazelcast.partition.NoDataMemberInClusterException) MemberLeftException(com.hazelcast.core.MemberLeftException) ExecutionException(java.util.concurrent.ExecutionException)

Example 62 with MemberImpl

use of com.hazelcast.instance.MemberImpl in project hazelcast by hazelcast.

the class InternalPartitionServiceImpl method syncPartitionRuntimeState.

@SuppressWarnings("checkstyle:npathcomplexity")
boolean syncPartitionRuntimeState() {
    if (!partitionStateManager.isInitialized()) {
        // do not send partition state until initialized!
        return false;
    }
    if (!node.isMaster()) {
        return false;
    }
    PartitionRuntimeState partitionState = createPartitionStateInternal();
    if (partitionState == null) {
        return false;
    }
    if (logger.isFineEnabled()) {
        logger.fine("Sync'ing partition state, version: " + partitionState.getVersion());
    }
    OperationService operationService = nodeEngine.getOperationService();
    Collection<MemberImpl> members = node.clusterService.getMemberImpls();
    List<Future<Boolean>> calls = firePartitionStateOperation(members, partitionState, operationService);
    Collection<Boolean> results = returnWithDeadline(calls, PTABLE_SYNC_TIMEOUT_SECONDS, TimeUnit.SECONDS, partitionStateSyncTimeoutHandler);
    if (calls.size() != results.size()) {
        return false;
    }
    for (Boolean result : results) {
        if (!result) {
            if (logger.isFineEnabled()) {
                logger.fine("Partition state, version: " + partitionState.getVersion() + " sync failed to one of the members!");
            }
            return false;
        }
    }
    return true;
}
Also used : MemberImpl(com.hazelcast.instance.MemberImpl) PartitionRuntimeState(com.hazelcast.internal.partition.PartitionRuntimeState) Future(java.util.concurrent.Future) OperationService(com.hazelcast.spi.OperationService) InternalOperationService(com.hazelcast.spi.impl.operationservice.InternalOperationService) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean)

Example 63 with MemberImpl

use of com.hazelcast.instance.MemberImpl in project hazelcast by hazelcast.

the class InternalPartitionServiceImpl method firePartitionStateOperation.

private List<Future<Boolean>> firePartitionStateOperation(Collection<MemberImpl> members, PartitionRuntimeState partitionState, OperationService operationService) {
    final ClusterServiceImpl clusterService = node.clusterService;
    List<Future<Boolean>> calls = new ArrayList<Future<Boolean>>(members.size());
    for (MemberImpl member : members) {
        if (!(member.localMember() || clusterService.isMemberRemovedWhileClusterIsNotActive(member.getAddress()))) {
            try {
                Address address = member.getAddress();
                PartitionStateOperation operation = new PartitionStateOperation(partitionState, true);
                Future<Boolean> f = operationService.invokeOnTarget(SERVICE_NAME, operation, address);
                calls.add(f);
            } catch (Exception e) {
                logger.finest(e);
            }
        }
    }
    return calls;
}
Also used : Address(com.hazelcast.nio.Address) MemberImpl(com.hazelcast.instance.MemberImpl) ClusterServiceImpl(com.hazelcast.internal.cluster.impl.ClusterServiceImpl) ArrayList(java.util.ArrayList) Future(java.util.concurrent.Future) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) FetchPartitionStateOperation(com.hazelcast.internal.partition.operation.FetchPartitionStateOperation) PartitionStateOperation(com.hazelcast.internal.partition.operation.PartitionStateOperation) HazelcastInstanceNotActiveException(com.hazelcast.core.HazelcastInstanceNotActiveException) TargetNotMemberException(com.hazelcast.spi.exception.TargetNotMemberException) NoDataMemberInClusterException(com.hazelcast.partition.NoDataMemberInClusterException) MemberLeftException(com.hazelcast.core.MemberLeftException) ExecutionException(java.util.concurrent.ExecutionException)

Example 64 with MemberImpl

use of com.hazelcast.instance.MemberImpl in project hazelcast by hazelcast.

the class ClusterServiceImpl method doRemoveAddress.

void doRemoveAddress(Address deadAddress, String reason, boolean destroyConnection) {
    if (!ensureMemberIsRemovable(deadAddress)) {
        return;
    }
    lock.lock();
    try {
        if (deadAddress.equals(node.getMasterAddress())) {
            assignNewMaster();
        }
        if (node.isMaster()) {
            clusterJoinManager.removeJoin(deadAddress);
        }
        Connection conn = node.connectionManager.getConnection(deadAddress);
        if (destroyConnection && conn != null) {
            conn.close(reason, null);
        }
        MemberImpl deadMember = getMember(deadAddress);
        if (deadMember != null) {
            removeMember(deadMember);
            logger.info(membersString());
        }
    } finally {
        lock.unlock();
    }
}
Also used : MemberImpl(com.hazelcast.instance.MemberImpl) Connection(com.hazelcast.nio.Connection)

Example 65 with MemberImpl

use of com.hazelcast.instance.MemberImpl in project hazelcast by hazelcast.

the class DiscoveryJoiner method getPossibleAddresses.

@Override
protected Collection<Address> getPossibleAddresses() {
    Iterable<DiscoveryNode> discoveredNodes = checkNotNull(discoveryService.discoverNodes(), "Discovered nodes cannot be null!");
    MemberImpl localMember = node.nodeEngine.getLocalMember();
    Address localAddress = localMember.getAddress();
    Collection<Address> possibleMembers = new ArrayList<Address>();
    for (DiscoveryNode discoveryNode : discoveredNodes) {
        Address discoveredAddress = usePublicAddress ? discoveryNode.getPublicAddress() : discoveryNode.getPrivateAddress();
        if (localAddress.equals(discoveredAddress)) {
            continue;
        }
        possibleMembers.add(discoveredAddress);
    }
    return possibleMembers;
}
Also used : DiscoveryNode(com.hazelcast.spi.discovery.DiscoveryNode) Address(com.hazelcast.nio.Address) MemberImpl(com.hazelcast.instance.MemberImpl) ArrayList(java.util.ArrayList)

Aggregations

MemberImpl (com.hazelcast.instance.MemberImpl)86 Address (com.hazelcast.nio.Address)37 Test (org.junit.Test)18 Member (com.hazelcast.core.Member)17 QuickTest (com.hazelcast.test.annotation.QuickTest)16 ParallelTest (com.hazelcast.test.annotation.ParallelTest)14 ArrayList (java.util.ArrayList)12 InetAddress (java.net.InetAddress)9 Future (java.util.concurrent.Future)9 HashSet (java.util.HashSet)8 HazelcastInstance (com.hazelcast.core.HazelcastInstance)7 MemberInfo (com.hazelcast.internal.cluster.MemberInfo)7 ClusterService (com.hazelcast.internal.cluster.ClusterService)5 MemberInfoUpdateOperation (com.hazelcast.internal.cluster.impl.operations.MemberInfoUpdateOperation)5 PartitionRuntimeState (com.hazelcast.internal.partition.PartitionRuntimeState)5 ILogger (com.hazelcast.logging.ILogger)5 OperationService (com.hazelcast.spi.OperationService)5 InternalOperationService (com.hazelcast.spi.impl.operationservice.InternalOperationService)5 Before (org.junit.Before)5 ClusterServiceImpl (com.hazelcast.internal.cluster.impl.ClusterServiceImpl)4