Search in sources :

Example 31 with Address

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

the class ReplicaSyncResponse method nodeNotOwnsBackup.

/** Fail all replication operations with the exception that this node is no longer the replica with the sent index */
private void nodeNotOwnsBackup(InternalPartitionImpl partition) {
    int partitionId = getPartitionId();
    int replicaIndex = getReplicaIndex();
    Address thisAddress = getNodeEngine().getThisAddress();
    int currentReplicaIndex = partition.getReplicaIndex(thisAddress);
    ILogger logger = getLogger();
    if (logger.isFinestEnabled()) {
        logger.finest("This node is not backup replica of partitionId=" + partitionId + ", replicaIndex=" + replicaIndex + " anymore. current replicaIndex=" + currentReplicaIndex);
    }
    if (tasks != null) {
        Throwable throwable = new WrongTargetException(thisAddress, partition.getReplicaAddress(replicaIndex), partitionId, replicaIndex, getClass().getName());
        for (Operation op : tasks) {
            prepareOperation(op);
            onOperationFailure(op, throwable);
        }
    }
}
Also used : Address(com.hazelcast.nio.Address) ILogger(com.hazelcast.logging.ILogger) UrgentSystemOperation(com.hazelcast.spi.UrgentSystemOperation) PartitionAwareOperation(com.hazelcast.spi.PartitionAwareOperation) Operation(com.hazelcast.spi.Operation) BackupOperation(com.hazelcast.spi.BackupOperation) WrongTargetException(com.hazelcast.spi.exception.WrongTargetException)

Example 32 with Address

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

the class ReplicaSyncRetryResponse method run.

@Override
public void run() throws Exception {
    final InternalPartitionServiceImpl partitionService = getService();
    final int partitionId = getPartitionId();
    final int replicaIndex = getReplicaIndex();
    partitionService.getReplicaManager().clearReplicaSyncRequest(partitionId, replicaIndex);
    PartitionStateManager partitionStateManager = partitionService.getPartitionStateManager();
    InternalPartitionImpl partition = partitionStateManager.getPartitionImpl(partitionId);
    Address thisAddress = getNodeEngine().getThisAddress();
    ILogger logger = getLogger();
    int currentReplicaIndex = partition.getReplicaIndex(thisAddress);
    if (currentReplicaIndex > 0) {
        if (logger.isFinestEnabled()) {
            logger.finest("Retrying replica sync request for partitionId=" + partitionId + ", initial-replicaIndex=" + replicaIndex + ", current-replicaIndex=" + currentReplicaIndex);
        }
        partitionService.getReplicaManager().triggerPartitionReplicaSync(partitionId, currentReplicaIndex, InternalPartitionService.REPLICA_SYNC_RETRY_DELAY);
    } else if (logger.isFinestEnabled()) {
        logger.finest("No need to retry replica sync request for partitionId=" + partitionId + ", initial-replicaIndex=" + replicaIndex + ", current-replicaIndex=" + currentReplicaIndex);
    }
}
Also used : Address(com.hazelcast.nio.Address) InternalPartitionServiceImpl(com.hazelcast.internal.partition.impl.InternalPartitionServiceImpl) InternalPartitionImpl(com.hazelcast.internal.partition.impl.InternalPartitionImpl) ILogger(com.hazelcast.logging.ILogger) PartitionStateManager(com.hazelcast.internal.partition.impl.PartitionStateManager)

Example 33 with Address

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

the class ReplicaSyncRequest method preCheckReplicaSync.

/** Checks if we can continue with the replication or not. Can send a retry or empty response to the replica in some cases */
private boolean preCheckReplicaSync(NodeEngineImpl nodeEngine, int partitionId, int replicaIndex) throws IOException {
    InternalPartitionServiceImpl partitionService = (InternalPartitionServiceImpl) nodeEngine.getPartitionService();
    PartitionStateManager partitionStateManager = partitionService.getPartitionStateManager();
    InternalPartitionImpl partition = partitionStateManager.getPartitionImpl(partitionId);
    Address owner = partition.getOwnerOrNull();
    long[] replicaVersions = partitionService.getPartitionReplicaVersions(partitionId);
    long currentVersion = replicaVersions[replicaIndex - 1];
    ILogger logger = getLogger();
    if (!nodeEngine.getThisAddress().equals(owner)) {
        if (logger.isFinestEnabled()) {
            logger.finest("Wrong target! " + toString() + " cannot be processed! Target should be: " + owner);
        }
        sendRetryResponse();
        return false;
    }
    if (currentVersion == 0) {
        if (logger.isFinestEnabled()) {
            logger.finest("Current replicaVersion=0, sending empty response for partitionId=" + getPartitionId() + ", replicaIndex=" + getReplicaIndex() + ", replicaVersions=" + Arrays.toString(replicaVersions));
        }
        sendEmptyResponse();
        return false;
    }
    if (!partitionService.getReplicaManager().tryToAcquireReplicaSyncPermit()) {
        if (logger.isFinestEnabled()) {
            logger.finest("Max parallel replication process limit exceeded! Could not run replica sync -> " + toString());
        }
        sendRetryResponse();
        return false;
    }
    return true;
}
Also used : Address(com.hazelcast.nio.Address) InternalPartitionServiceImpl(com.hazelcast.internal.partition.impl.InternalPartitionServiceImpl) InternalPartitionImpl(com.hazelcast.internal.partition.impl.InternalPartitionImpl) ILogger(com.hazelcast.logging.ILogger) PartitionStateManager(com.hazelcast.internal.partition.impl.PartitionStateManager)

Example 34 with Address

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

the class ReplicaSyncRequest method sendRetryResponse.

/** Send a response to the replica to retry the replica sync */
private void sendRetryResponse() {
    NodeEngine nodeEngine = getNodeEngine();
    int partitionId = getPartitionId();
    int replicaIndex = getReplicaIndex();
    ReplicaSyncRetryResponse response = new ReplicaSyncRetryResponse();
    response.setPartitionId(partitionId).setReplicaIndex(replicaIndex);
    Address target = getCallerAddress();
    OperationService operationService = nodeEngine.getOperationService();
    operationService.send(response, target);
}
Also used : NodeEngine(com.hazelcast.spi.NodeEngine) Address(com.hazelcast.nio.Address) OperationService(com.hazelcast.spi.OperationService)

Example 35 with Address

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

the class PartitionStateGeneratorImpl method initialize.

private void initialize(InternalPartition[] currentState, Address[][] state) {
    int partitionCount = currentState.length;
    for (int partitionId = 0; partitionId < partitionCount; partitionId++) {
        InternalPartition p = currentState[partitionId];
        Address[] replicas = state[partitionId];
        boolean empty = true;
        for (int index = 0; index < InternalPartition.MAX_REPLICA_COUNT; index++) {
            replicas[index] = p.getReplicaAddress(index);
            empty &= replicas[index] == null;
        }
        if (empty) {
            continue;
        }
        // auto shift-up colder replicas to hotter replicas to fill the empty gaps
        int maxReplicaIndex = InternalPartition.MAX_REPLICA_COUNT - 1;
        for (int index = 0; index < InternalPartition.MAX_REPLICA_COUNT; index++) {
            if (replicas[index] == null) {
                for (int k = maxReplicaIndex; k > index; k--) {
                    if (replicas[k] != null) {
                        replicas[index] = replicas[k];
                        replicas[k] = null;
                        maxReplicaIndex = k - 1;
                        break;
                    }
                }
            }
        }
    }
}
Also used : Address(com.hazelcast.nio.Address) InternalPartition(com.hazelcast.internal.partition.InternalPartition)

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