Search in sources :

Example 1 with PartitionIteratingOperation

use of com.hazelcast.spi.impl.operationservice.impl.operations.PartitionIteratingOperation in project hazelcast by hazelcast.

the class OperationDescriptors method toOperationDesc.

public static String toOperationDesc(Operation op) {
    Class<? extends Operation> operationClass = op.getClass();
    if (PartitionIteratingOperation.class.isAssignableFrom(operationClass)) {
        PartitionIteratingOperation partitionIteratingOperation = (PartitionIteratingOperation) op;
        OperationFactory operationFactory = partitionIteratingOperation.getOperationFactory();
        String desc = DESCRIPTORS.get(operationFactory.getClass().getName());
        if (desc == null) {
            desc = PartitionIteratingOperation.class.getSimpleName() + "(" + operationFactory.getClass().getName() + ")";
            DESCRIPTORS.put(operationFactory.getClass().getName(), desc);
        }
        return desc;
    } else if (Backup.class.isAssignableFrom(operationClass)) {
        Backup backup = (Backup) op;
        Operation backupOperation = backup.getBackupOp();
        String desc = DESCRIPTORS.get(backupOperation.getClass().getName());
        if (desc == null) {
            desc = Backup.class.getSimpleName() + "(" + backup.getBackupOp().getClass().getName() + ")";
            DESCRIPTORS.put(backupOperation.getClass().getName(), desc);
        }
        return desc;
    } else {
        return operationClass.getName();
    }
}
Also used : PartitionIteratingOperation(com.hazelcast.spi.impl.operationservice.impl.operations.PartitionIteratingOperation) Backup(com.hazelcast.spi.impl.operationservice.impl.operations.Backup) PartitionIteratingOperation(com.hazelcast.spi.impl.operationservice.impl.operations.PartitionIteratingOperation) Operation(com.hazelcast.spi.impl.operationservice.Operation) OperationFactory(com.hazelcast.spi.impl.operationservice.OperationFactory)

Example 2 with PartitionIteratingOperation

use of com.hazelcast.spi.impl.operationservice.impl.operations.PartitionIteratingOperation in project hazelcast by hazelcast.

the class InvokeOnPartitions method invokeOnAllPartitions.

private void invokeOnAllPartitions() {
    if (memberPartitions.isEmpty()) {
        future.complete(Collections.EMPTY_MAP);
        return;
    }
    for (final Map.Entry<Address, List<Integer>> mp : memberPartitions.entrySet()) {
        final Address address = mp.getKey();
        List<Integer> partitions = mp.getValue();
        PartitionIteratingOperation op = new PartitionIteratingOperation(operationFactory, toIntArray(partitions));
        operationService.createInvocationBuilder(serviceName, op, address).setTryCount(TRY_COUNT).setTryPauseMillis(TRY_PAUSE_MILLIS).invoke().whenCompleteAsync(new FirstAttemptExecutionCallback(partitions));
    }
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) PartitionIteratingOperation(com.hazelcast.spi.impl.operationservice.impl.operations.PartitionIteratingOperation) Address(com.hazelcast.cluster.Address) List(java.util.List) MapUtil.createHashMap(com.hazelcast.internal.util.MapUtil.createHashMap) Map(java.util.Map)

Example 3 with PartitionIteratingOperation

use of com.hazelcast.spi.impl.operationservice.impl.operations.PartitionIteratingOperation in project hazelcast by hazelcast.

the class InvocationRegistry method retire.

public void retire(Invocation invocation) {
    if (!profilerEnabled) {
        return;
    }
    Operation op = invocation.op;
    Class c = op.getClass();
    if (op instanceof PartitionIteratingOperation) {
        c = ((PartitionIteratingOperation) op).getOperationFactory().getClass();
    }
    LatencyDistribution distribution = latencyDistributions.computeIfAbsent(c, k -> new LatencyDistribution());
    distribution.done(invocation.firstInvocationTimeNanos);
}
Also used : PartitionIteratingOperation(com.hazelcast.spi.impl.operationservice.impl.operations.PartitionIteratingOperation) Operation(com.hazelcast.spi.impl.operationservice.Operation) PartitionIteratingOperation(com.hazelcast.spi.impl.operationservice.impl.operations.PartitionIteratingOperation) LatencyDistribution(com.hazelcast.internal.util.LatencyDistribution)

Example 4 with PartitionIteratingOperation

use of com.hazelcast.spi.impl.operationservice.impl.operations.PartitionIteratingOperation in project hazelcast by hazelcast.

the class OperationRunnerImpl method run.

/**
 * Runs the provided operation.
 *
 * @param op         the operation to execute
 * @param startNanos the time, as returned by {@link System#nanoTime} when this operation
 *                   started execution
 * @return {@code true} if this operation was not executed and should be retried at a later time,
 * {@code false} if the operation should not be retried, either because it
 * timed out or has run successfully
 */
private boolean run(Operation op, long startNanos) {
    executedOperationsCounter.inc();
    boolean publishCurrentTask = publishCurrentTask();
    if (publishCurrentTask) {
        currentTask = op;
    }
    try {
        checkNodeState(op);
        if (timeout(op)) {
            return false;
        }
        ensureNoPartitionProblems(op);
        ensureNoSplitBrain(op);
        if (op.isTenantAvailable()) {
            op.pushThreadContext();
            op.beforeRun();
            call(op);
        } else {
            return true;
        }
    } catch (Throwable e) {
        handleOperationError(op, e);
    } finally {
        op.afterRunFinal();
        if (publishCurrentTask) {
            currentTask = null;
        }
        op.popThreadContext();
        if (opLatencyDistributions != null) {
            Class c = op.getClass();
            if (op instanceof PartitionIteratingOperation) {
                c = ((PartitionIteratingOperation) op).getOperationFactory().getClass();
            }
            LatencyDistribution distribution = opLatencyDistributions.computeIfAbsent(c, k -> new LatencyDistribution());
            distribution.recordNanos(System.nanoTime() - startNanos);
        }
    }
    return false;
}
Also used : PartitionIteratingOperation(com.hazelcast.spi.impl.operationservice.impl.operations.PartitionIteratingOperation) LatencyDistribution(com.hazelcast.internal.util.LatencyDistribution)

Example 5 with PartitionIteratingOperation

use of com.hazelcast.spi.impl.operationservice.impl.operations.PartitionIteratingOperation in project hazelcast by hazelcast.

the class OperationDescriptorsTest method testPartitionIteratingOperation.

@Test
public void testPartitionIteratingOperation() {
    PartitionIteratingOperation op = new PartitionIteratingOperation(new DummyOperationFactory(), new int[0]);
    String result = toOperationDesc(op);
    assertEquals(format("PartitionIteratingOperation(%s)", DummyOperationFactory.class.getName()), result);
}
Also used : PartitionIteratingOperation(com.hazelcast.spi.impl.operationservice.impl.operations.PartitionIteratingOperation) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Aggregations

PartitionIteratingOperation (com.hazelcast.spi.impl.operationservice.impl.operations.PartitionIteratingOperation)5 LatencyDistribution (com.hazelcast.internal.util.LatencyDistribution)2 Operation (com.hazelcast.spi.impl.operationservice.Operation)2 Address (com.hazelcast.cluster.Address)1 MapUtil.createHashMap (com.hazelcast.internal.util.MapUtil.createHashMap)1 OperationFactory (com.hazelcast.spi.impl.operationservice.OperationFactory)1 Backup (com.hazelcast.spi.impl.operationservice.impl.operations.Backup)1 ParallelJVMTest (com.hazelcast.test.annotation.ParallelJVMTest)1 QuickTest (com.hazelcast.test.annotation.QuickTest)1 List (java.util.List)1 Map (java.util.Map)1 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1 Test (org.junit.Test)1