Search in sources :

Example 16 with Address

use of com.hazelcast.nio.Address in project hazelcast by hazelcast.

the class InternalPartitionServiceImpl method searchUnknownAddressesInPartitionTable.

private void searchUnknownAddressesInPartitionTable(Address sender, Set<Address> unknownAddresses, int partitionId, Address[] addresses) {
    final ClusterServiceImpl clusterService = node.clusterService;
    final ClusterState clusterState = clusterService.getClusterState();
    for (int index = 0; index < InternalPartition.MAX_REPLICA_COUNT; index++) {
        Address address = addresses[index];
        if (address != null && node.clusterService.getMember(address) == null) {
            if (clusterState == ClusterState.ACTIVE || !clusterService.isMemberRemovedWhileClusterIsNotActive(address)) {
                if (logger.isFinestEnabled()) {
                    logger.finest("Unknown " + address + " found in partition table sent from master " + sender + ". It has probably already left the cluster. partitionId=" + partitionId);
                }
                unknownAddresses.add(address);
            }
        }
    }
}
Also used : ClusterState(com.hazelcast.cluster.ClusterState) Address(com.hazelcast.nio.Address) ClusterServiceImpl(com.hazelcast.internal.cluster.impl.ClusterServiceImpl)

Example 17 with Address

use of com.hazelcast.nio.Address in project hazelcast by hazelcast.

the class InternalPartitionServiceImpl method logUnknownAddressesInPartitionTable.

private void logUnknownAddressesInPartitionTable(Address sender, Set<Address> unknownAddresses) {
    if (!unknownAddresses.isEmpty() && 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 (Address address : unknownAddresses) {
            s.append("\n\t").append(address);
        }
        s.append("\n}");
        logger.warning(s.toString());
    }
}
Also used : Address(com.hazelcast.nio.Address)

Example 18 with Address

use of com.hazelcast.nio.Address in project hazelcast by hazelcast.

the class MigrationPlanner method fixCycle.

// Fix cyclic partition replica movements.
// When there are cycles among replica migrations, it's impossible to define a migration order.
// For example followings are cycles:
// - [A,B] -> [B,A]
// - [A,B,C] -> [B,C,A]
boolean fixCycle(Address[] oldReplicas, Address[] newReplicas) {
    boolean cyclic = false;
    for (int i = 0; i < oldReplicas.length; i++) {
        final Address oldAddress = oldReplicas[i];
        final Address newAddress = newReplicas[i];
        if (oldAddress == null || newAddress == null || oldAddress.equals(newAddress)) {
            continue;
        }
        if (isCyclic(oldReplicas, newReplicas, i)) {
            fixCycle(oldReplicas, newReplicas, i);
            cyclic = true;
        }
    }
    return cyclic;
}
Also used : Address(com.hazelcast.nio.Address)

Example 19 with Address

use of com.hazelcast.nio.Address in project hazelcast by hazelcast.

the class MigrationPlanner method isCyclic.

// Finds whether there's a migration cycle.
// For example followings are cycles:
// - [A,B] -> [B,A]
// - [A,B,C] -> [B,C,A]
boolean isCyclic(Address[] oldReplicas, Address[] newReplicas) {
    for (int i = 0; i < oldReplicas.length; i++) {
        final Address oldAddress = oldReplicas[i];
        final Address newAddress = newReplicas[i];
        if (oldAddress == null || newAddress == null || oldAddress.equals(newAddress)) {
            continue;
        }
        if (isCyclic(oldReplicas, newReplicas, i)) {
            return true;
        }
    }
    return false;
}
Also used : Address(com.hazelcast.nio.Address)

Example 20 with Address

use of com.hazelcast.nio.Address in project hazelcast by hazelcast.

the class PartitionReplicaManager method triggerPartitionReplicaSync.

/**
     * This method is called on a backup node (replica). Given all conditions are satisfied, this method initiates a replica sync
     * operation and registers it to replicaSyncRequest. The operation is scheduled for a future execution if :
     * <ul>
     * <li>the {@code delayMillis} is greater than 0</li>
     * <li>if a migration is not allowed (during repartitioning or a node joining the cluster)</li>
     * <li>the partition is currently migrating</li>
     * <li>another sync request has already been sent</li>
     * <li>the maximum number of parallel synchronizations has already been reached</li>
     * </ul>
     *
     * @param partitionId  the partition which is being synchronized
     * @param replicaIndex the index of the replica which is being synchronized
     * @param delayMillis  the delay before the sync operation is sent
     * @throws IllegalArgumentException if the replica index is not between 0 and {@link InternalPartition#MAX_REPLICA_COUNT}
     */
public void triggerPartitionReplicaSync(int partitionId, int replicaIndex, long delayMillis) {
    if (replicaIndex < 0 || replicaIndex > InternalPartition.MAX_REPLICA_COUNT) {
        throw new IllegalArgumentException("Invalid replica index! replicaIndex=" + replicaIndex + " for partitionId=" + partitionId);
    }
    if (!checkSyncPartitionTarget(partitionId, replicaIndex)) {
        return;
    }
    InternalPartitionImpl partition = partitionStateManager.getPartitionImpl(partitionId);
    Address target = partition.getOwnerOrNull();
    ReplicaSyncInfo syncInfo = new ReplicaSyncInfo(partitionId, replicaIndex, target);
    if (delayMillis > 0) {
        schedulePartitionReplicaSync(syncInfo, target, delayMillis, "EXPLICIT DELAY");
        return;
    }
    // conform checkstyle return-count rule.
    if (!partitionService.isReplicaSyncAllowed() || partition.isMigrating()) {
        schedulePartitionReplicaSync(syncInfo, target, REPLICA_SYNC_RETRY_DELAY, "MIGRATION IS DISABLED OR PARTITION IS MIGRATING");
        return;
    }
    if (replicaSyncRequests.compareAndSet(partitionId, null, syncInfo)) {
        if (fireSyncReplicaRequest(syncInfo, target)) {
            return;
        }
        replicaSyncRequests.compareAndSet(partitionId, syncInfo, null);
        schedulePartitionReplicaSync(syncInfo, target, REPLICA_SYNC_RETRY_DELAY, "NO PERMIT AVAILABLE");
        return;
    }
    long scheduleDelay = getReplicaSyncScheduleDelay(partitionId);
    schedulePartitionReplicaSync(syncInfo, target, scheduleDelay, "ANOTHER SYNC IN PROGRESS");
}
Also used : Address(com.hazelcast.nio.Address)

Aggregations

Address (com.hazelcast.nio.Address)274 Test (org.junit.Test)44 QuickTest (com.hazelcast.test.annotation.QuickTest)36 HashMap (java.util.HashMap)33 ParallelTest (com.hazelcast.test.annotation.ParallelTest)29 Member (com.hazelcast.core.Member)27 ArrayList (java.util.ArrayList)27 Map (java.util.Map)26 ILogger (com.hazelcast.logging.ILogger)25 InetAddress (java.net.InetAddress)25 MemberImpl (com.hazelcast.instance.MemberImpl)21 List (java.util.List)20 HashSet (java.util.HashSet)18 Connection (com.hazelcast.nio.Connection)17 NodeEngine (com.hazelcast.spi.NodeEngine)16 NodeEngineImpl (com.hazelcast.spi.impl.NodeEngineImpl)16 IOException (java.io.IOException)16 ClusterServiceImpl (com.hazelcast.internal.cluster.impl.ClusterServiceImpl)14 HazelcastInstance (com.hazelcast.core.HazelcastInstance)13 IPartitionService (com.hazelcast.spi.partition.IPartitionService)13