Search in sources :

Example 1 with TargetAware

use of com.hazelcast.spi.impl.operationservice.TargetAware in project hazelcast by hazelcast.

the class OperationBackupHandler method sendSingleBackup.

private int sendSingleBackup(BackupAwareOperation backupAwareOp, InternalPartition partition, long[] replicaVersions, int syncBackups, int replica) {
    Operation backupOp = getBackupOperation(backupAwareOp);
    PartitionReplica target = partition.getReplica(replica);
    if (target != null) {
        if (skipSendingBackupToTarget(partition, target)) {
            return 0;
        }
        // without any unnecessary memory allocation and copy when it is used as object inside `Backup`.
        if (backupOp instanceof TargetAware) {
            ((TargetAware) backupOp).setTarget(target.address());
        }
        boolean isSyncBackup = syncBackups == 1;
        Backup backup = newBackup(backupAwareOp, backupOp, replicaVersions, 1, isSyncBackup);
        outboundOperationHandler.send(backup, target.address());
        if (isSyncBackup) {
            return 1;
        }
    }
    return 0;
}
Also used : PartitionReplica(com.hazelcast.internal.partition.PartitionReplica) Backup(com.hazelcast.spi.impl.operationservice.impl.operations.Backup) TargetAware(com.hazelcast.spi.impl.operationservice.TargetAware) BackupAwareOperation(com.hazelcast.spi.impl.operationservice.BackupAwareOperation) Operation(com.hazelcast.spi.impl.operationservice.Operation)

Example 2 with TargetAware

use of com.hazelcast.spi.impl.operationservice.TargetAware in project hazelcast by hazelcast.

the class Invocation method initInvocationTarget.

/**
 * Initializes the invocation target.
 *
 * @throws Exception if the initialization was a failure
 */
final void initInvocationTarget() throws Exception {
    Member previousTargetMember = targetMember;
    T target = getInvocationTarget();
    if (target == null) {
        throw newTargetNullException();
    }
    targetMember = toTargetMember(target);
    if (targetMember != null) {
        targetAddress = targetMember.getAddress();
    } else {
        targetAddress = toTargetAddress(target);
    }
    memberListVersion = context.clusterService.getMemberListVersion();
    if (targetMember == null) {
        if (previousTargetMember != null) {
            // then it means a member left.
            throw new MemberLeftException(previousTargetMember);
        }
        if (!(isJoinOperation(op) || isWanReplicationOperation(op))) {
            throw new TargetNotMemberException(target, op.getPartitionId(), op.getClass().getName(), op.getServiceName());
        }
    }
    if (op instanceof TargetAware) {
        ((TargetAware) op).setTarget(targetAddress);
    }
}
Also used : TargetNotMemberException(com.hazelcast.spi.exception.TargetNotMemberException) TIMEOUT(com.hazelcast.spi.impl.operationservice.impl.Invocation.HeartbeatTimeout.TIMEOUT) HEARTBEAT_TIMEOUT(com.hazelcast.spi.impl.operationservice.impl.InvocationConstant.HEARTBEAT_TIMEOUT) CALL_TIMEOUT(com.hazelcast.spi.impl.operationservice.impl.InvocationConstant.CALL_TIMEOUT) FINEST(java.util.logging.Level.FINEST) TargetAware(com.hazelcast.spi.impl.operationservice.TargetAware) Member(com.hazelcast.cluster.Member) MemberLeftException(com.hazelcast.core.MemberLeftException)

Example 3 with TargetAware

use of com.hazelcast.spi.impl.operationservice.TargetAware in project hazelcast by hazelcast.

the class OperationBackupHandler method sendMultipleBackups.

private int sendMultipleBackups(BackupAwareOperation backupAwareOp, InternalPartition partition, long[] replicaVersions, int syncBackups, int totalBackups) {
    int sendSyncBackups = 0;
    Operation backupOp = getBackupOperation(backupAwareOp);
    if (!(backupOp instanceof TargetAware)) {
        // optimize common case: serialize operation once and send to multiple targets
        Data backupOpData = nodeEngine.getSerializationService().toData(backupOp);
        for (int replicaIndex = 1; replicaIndex <= totalBackups; replicaIndex++) {
            PartitionReplica target = partition.getReplica(replicaIndex);
            if (target == null) {
                continue;
            }
            if (skipSendingBackupToTarget(partition, target)) {
                continue;
            }
            boolean isSyncBackup = replicaIndex <= syncBackups;
            Backup backup = newBackup(backupAwareOp, backupOpData, replicaVersions, replicaIndex, isSyncBackup);
            outboundOperationHandler.send(backup, target.address());
            if (isSyncBackup) {
                sendSyncBackups++;
            }
        }
    } else {
        for (int replicaIndex = 1; replicaIndex <= totalBackups; replicaIndex++) {
            int syncBackupSent = sendSingleBackup(backupAwareOp, partition, replicaVersions, syncBackups, replicaIndex);
            sendSyncBackups += syncBackupSent;
        }
    }
    return sendSyncBackups;
}
Also used : PartitionReplica(com.hazelcast.internal.partition.PartitionReplica) Backup(com.hazelcast.spi.impl.operationservice.impl.operations.Backup) TargetAware(com.hazelcast.spi.impl.operationservice.TargetAware) Data(com.hazelcast.internal.serialization.Data) BackupAwareOperation(com.hazelcast.spi.impl.operationservice.BackupAwareOperation) Operation(com.hazelcast.spi.impl.operationservice.Operation)

Aggregations

TargetAware (com.hazelcast.spi.impl.operationservice.TargetAware)3 PartitionReplica (com.hazelcast.internal.partition.PartitionReplica)2 BackupAwareOperation (com.hazelcast.spi.impl.operationservice.BackupAwareOperation)2 Operation (com.hazelcast.spi.impl.operationservice.Operation)2 Backup (com.hazelcast.spi.impl.operationservice.impl.operations.Backup)2 Member (com.hazelcast.cluster.Member)1 MemberLeftException (com.hazelcast.core.MemberLeftException)1 Data (com.hazelcast.internal.serialization.Data)1 TargetNotMemberException (com.hazelcast.spi.exception.TargetNotMemberException)1 TIMEOUT (com.hazelcast.spi.impl.operationservice.impl.Invocation.HeartbeatTimeout.TIMEOUT)1 CALL_TIMEOUT (com.hazelcast.spi.impl.operationservice.impl.InvocationConstant.CALL_TIMEOUT)1 HEARTBEAT_TIMEOUT (com.hazelcast.spi.impl.operationservice.impl.InvocationConstant.HEARTBEAT_TIMEOUT)1 FINEST (java.util.logging.Level.FINEST)1