Search in sources :

Example 71 with Operation

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

the class ClearOperation method replicateClearOperation.

private void replicateClearOperation(long version) {
    OperationService operationService = getNodeEngine().getOperationService();
    Collection<Address> members = getMemberAddresses();
    for (Address address : members) {
        Operation op = new ClearOperation(mapName, false, version).setPartitionId(getPartitionId()).setValidateTarget(false);
        operationService.createInvocationBuilder(getServiceName(), op, address).setTryCount(INVOCATION_TRY_COUNT).invoke();
    }
}
Also used : Address(com.hazelcast.cluster.Address) OperationService(com.hazelcast.spi.impl.operationservice.OperationService) MutatingOperation(com.hazelcast.spi.impl.operationservice.MutatingOperation) Operation(com.hazelcast.spi.impl.operationservice.Operation)

Example 72 with Operation

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

the class NodeEngineImpl method getPostJoinOperations.

/**
 * Collects all post-join operations from {@link PostJoinAwareService}s.
 * <p>
 * Post join operations should return response, at least a {@code null} response.
 * <p>
 * <b>Note</b>: Post join operations must be lock free, meaning no locks at all:
 * no partition locks, no key-based locks, no service level locks, no database interaction!
 * The {@link Operation#getPartitionId()} method should return a negative value.
 * This means that the operations should not implement {@link PartitionAwareOperation}.
 *
 * @return the operations to be executed at the end of a finalized join
 */
public Collection<Operation> getPostJoinOperations() {
    Collection<Operation> postJoinOps = new LinkedList<>();
    Collection<PostJoinAwareService> services = getServices(PostJoinAwareService.class);
    for (PostJoinAwareService service : services) {
        Operation postJoinOperation = service.getPostJoinOperation();
        if (postJoinOperation != null) {
            if (postJoinOperation.getPartitionId() >= 0) {
                logger.severe("Post-join operations should not have partition ID set! Service: " + service + ", Operation: " + postJoinOperation);
                continue;
            }
            postJoinOps.add(postJoinOperation);
        }
    }
    return postJoinOps;
}
Also used : PostJoinAwareService(com.hazelcast.internal.services.PostJoinAwareService) PartitionAwareOperation(com.hazelcast.spi.impl.operationservice.PartitionAwareOperation) Operation(com.hazelcast.spi.impl.operationservice.Operation) LinkedList(java.util.LinkedList)

Example 73 with Operation

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

the class NodeEngineImpl method getPreJoinOperations.

public Collection<Operation> getPreJoinOperations() {
    Collection<Operation> preJoinOps = new LinkedList<>();
    Collection<PreJoinAwareService> services = getServices(PreJoinAwareService.class);
    for (PreJoinAwareService service : services) {
        Operation preJoinOperation = service.getPreJoinOperation();
        if (preJoinOperation != null) {
            if (preJoinOperation.getPartitionId() >= 0) {
                logger.severe("Pre-join operations operations should not have partition ID set! Service: " + service + ", Operation: " + preJoinOperation);
                continue;
            }
            preJoinOps.add(preJoinOperation);
        }
    }
    return preJoinOps;
}
Also used : PreJoinAwareService(com.hazelcast.internal.services.PreJoinAwareService) PartitionAwareOperation(com.hazelcast.spi.impl.operationservice.PartitionAwareOperation) Operation(com.hazelcast.spi.impl.operationservice.Operation) LinkedList(java.util.LinkedList)

Example 74 with Operation

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

the class OperationBackupHandler method newBackup.

private static Backup newBackup(BackupAwareOperation backupAwareOp, Object backupOp, long[] replicaVersions, int replicaIndex, boolean respondBack) {
    Operation op = (Operation) backupAwareOp;
    Backup backup;
    if (backupOp instanceof Operation) {
        backup = new Backup((Operation) backupOp, op.getCallerAddress(), replicaVersions, respondBack, op.getClientCallId());
    } else if (backupOp instanceof Data) {
        backup = new Backup((Data) backupOp, op.getCallerAddress(), replicaVersions, respondBack, op.getClientCallId());
    } else {
        throw new IllegalArgumentException("Only 'Data' or 'Operation' typed backup operation is supported!");
    }
    backup.setPartitionId(op.getPartitionId()).setReplicaIndex(replicaIndex).setCallerUuid(op.getCallerUuid());
    if (hasActiveInvocation(op)) {
        setCallId(backup, op.getCallId());
    }
    return backup;
}
Also used : Backup(com.hazelcast.spi.impl.operationservice.impl.operations.Backup) Data(com.hazelcast.internal.serialization.Data) BackupAwareOperation(com.hazelcast.spi.impl.operationservice.BackupAwareOperation) Operation(com.hazelcast.spi.impl.operationservice.Operation)

Example 75 with Operation

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

the class OperationBackupHandler method sendBackups0.

int sendBackups0(BackupAwareOperation backupAwareOp) {
    int requestedSyncBackups = requestedSyncBackups(backupAwareOp);
    int requestedAsyncBackups = requestedAsyncBackups(backupAwareOp);
    int requestedTotalBackups = requestedTotalBackups(backupAwareOp);
    if (requestedTotalBackups == 0) {
        return 0;
    }
    Operation op = (Operation) backupAwareOp;
    PartitionReplicaVersionManager versionManager = node.getPartitionService().getPartitionReplicaVersionManager();
    ServiceNamespace namespace = versionManager.getServiceNamespace(op);
    long[] replicaVersions = versionManager.incrementPartitionReplicaVersions(op.getPartitionId(), namespace, requestedTotalBackups);
    boolean syncForced = backpressureRegulator.isSyncForced(backupAwareOp);
    int syncBackups = syncBackups(requestedSyncBackups, requestedAsyncBackups, syncForced);
    int asyncBackups = asyncBackups(requestedSyncBackups, requestedAsyncBackups, syncForced);
    // TODO: This could cause a problem with back pressure
    if (!op.returnsResponse()) {
        asyncBackups += syncBackups;
        syncBackups = 0;
    }
    if (syncBackups + asyncBackups == 0) {
        return 0;
    }
    return makeBackups(backupAwareOp, op.getPartitionId(), replicaVersions, syncBackups, asyncBackups);
}
Also used : ServiceNamespace(com.hazelcast.internal.services.ServiceNamespace) BackupAwareOperation(com.hazelcast.spi.impl.operationservice.BackupAwareOperation) Operation(com.hazelcast.spi.impl.operationservice.Operation) PartitionReplicaVersionManager(com.hazelcast.internal.partition.PartitionReplicaVersionManager)

Aggregations

Operation (com.hazelcast.spi.impl.operationservice.Operation)271 Test (org.junit.Test)80 QuickTest (com.hazelcast.test.annotation.QuickTest)79 ParallelJVMTest (com.hazelcast.test.annotation.ParallelJVMTest)59 OperationService (com.hazelcast.spi.impl.operationservice.OperationService)56 Address (com.hazelcast.cluster.Address)31 HazelcastInstance (com.hazelcast.core.HazelcastInstance)25 Data (com.hazelcast.internal.serialization.Data)24 Future (java.util.concurrent.Future)24 Member (com.hazelcast.cluster.Member)22 ArrayList (java.util.ArrayList)21 NodeEngine (com.hazelcast.spi.impl.NodeEngine)18 NodeEngineImpl (com.hazelcast.spi.impl.NodeEngineImpl)17 TestHazelcastInstanceFactory (com.hazelcast.test.TestHazelcastInstanceFactory)17 AssertTask (com.hazelcast.test.AssertTask)15 ILogger (com.hazelcast.logging.ILogger)14 UrgentSystemOperation (com.hazelcast.spi.impl.operationservice.UrgentSystemOperation)13 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)13 Config (com.hazelcast.config.Config)12 CompletableFuture (java.util.concurrent.CompletableFuture)12