Search in sources :

Example 1 with PartitionAwareOperationFactory

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

the class InvokeOnPartitions method retryFailedPartitions.

private void retryFailedPartitions() throws InterruptedException, ExecutionException {
    List<Integer> failedPartitions = new LinkedList<Integer>();
    for (Map.Entry<Integer, Object> partitionResult : partitionResults.entrySet()) {
        int partitionId = partitionResult.getKey();
        Object result = partitionResult.getValue();
        if (result instanceof Throwable) {
            failedPartitions.add(partitionId);
        }
    }
    for (Integer failedPartition : failedPartitions) {
        Operation operation;
        PartitionAwareOperationFactory partitionAwareFactory = extractPartitionAware(operationFactory);
        if (partitionAwareFactory != null) {
            operation = partitionAwareFactory.createPartitionOperation(failedPartition);
        } else {
            operation = operationFactory.createOperation();
        }
        Future future = operationService.createInvocationBuilder(serviceName, operation, failedPartition).invoke();
        partitionResults.put(failedPartition, future);
    }
    for (Integer failedPartition : failedPartitions) {
        Future future = (Future) partitionResults.get(failedPartition);
        Object result = future.get();
        partitionResults.put(failedPartition, result);
    }
}
Also used : PartitionAwareOperationFactory(com.hazelcast.spi.impl.operationservice.impl.operations.PartitionAwareOperationFactory) Future(java.util.concurrent.Future) Operation(com.hazelcast.spi.Operation) PartitionIteratingOperation(com.hazelcast.spi.impl.operationservice.impl.operations.PartitionIteratingOperation) HashMap(java.util.HashMap) Map(java.util.Map) LinkedList(java.util.LinkedList)

Example 2 with PartitionAwareOperationFactory

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

the class MapRemoveAllMessageTask method processMessage.

@Override
protected void processMessage() {
    if (!(predicate instanceof PartitionPredicate)) {
        super.processMessage();
        return;
    }
    int partitionId = clientMessage.getPartitionId();
    OperationFactory operationFactory = createOperationFactory();
    OperationServiceImpl operationService = nodeEngine.getOperationService();
    // We are running on a partition thread now and we are not allowed
    // to call invokeOnPartitions(Async) on operation service because of
    // that.
    Operation operation;
    if (operationFactory instanceof PartitionAwareOperationFactory) {
        // If operation factory is partition-aware, we should utilize this to our advantage
        // since for the on-heap storages this may speed up the operation via indexes
        // (see PartitionWideEntryWithPredicateOperationFactory.createFactoryOnRunner).
        PartitionAwareOperationFactory partitionAwareOperationFactory = (PartitionAwareOperationFactory) operationFactory;
        partitionAwareOperationFactory = partitionAwareOperationFactory.createFactoryOnRunner(nodeEngine, new int[] { partitionId });
        operation = partitionAwareOperationFactory.createPartitionOperation(partitionId);
    } else {
        operation = operationFactory.createOperation();
    }
    final int thisPartitionId = partitionId;
    operation.setCallerUuid(endpoint.getUuid());
    InvocationFuture<Object> future = operationService.invokeOnPartition(getServiceName(), operation, partitionId);
    future.whenCompleteAsync((response, throwable) -> {
        if (throwable == null) {
            sendResponse(reduce(Collections.singletonMap(thisPartitionId, response)));
        } else {
            handleProcessingFailure(throwable);
        }
    });
}
Also used : PartitionAwareOperationFactory(com.hazelcast.spi.impl.operationservice.impl.operations.PartitionAwareOperationFactory) PartitionPredicate(com.hazelcast.query.PartitionPredicate) Operation(com.hazelcast.spi.impl.operationservice.Operation) OperationServiceImpl(com.hazelcast.spi.impl.operationservice.impl.OperationServiceImpl) PartitionAwareOperationFactory(com.hazelcast.spi.impl.operationservice.impl.operations.PartitionAwareOperationFactory) OperationFactory(com.hazelcast.spi.impl.operationservice.OperationFactory)

Example 3 with PartitionAwareOperationFactory

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

the class MapPutAllWrongTargetForPartitionTest method testPutAllPerMemberOperation.

/**
 * Tests that all entries and backups of a {@link PutAllPartitionAwareOperationFactory} are sent to the correct members.
 * <p>
 * The test creates a cluster with a single partition per member and invokes {@link PutAllPartitionAwareOperationFactory}
 * which contains a single entry for every partition in the cluster. So just a single entry is for the member the factory
 * is executed on.
 * <p>
 * After the operation is invoked we assert that each member owns one entry of the map and that all backups have been written.
 */
private void testPutAllPerMemberOperation(final int entriesPerPartition) throws Exception {
    final int expectedEntryCount = INSTANCE_COUNT * entriesPerPartition;
    final String mapName = randomMapName();
    HazelcastInstance hz = instances[0];
    NodeEngineImpl nodeEngine = getNodeEngineImpl(hz);
    SerializationService serializationService = nodeEngine.getSerializationService();
    // create a PutAllPerMemberOperation with entries for all partitions
    int[] allPartitions = getAllPartitions();
    PartitionAwareOperationFactory factory = createPutAllOperationFactory(allPartitions, entriesPerPartition, mapName, hz, serializationService);
    // invoke the operation on a random remote target
    OperationServiceImpl operationService = nodeEngine.getOperationService();
    operationService.invokeOnPartitions(MapService.SERVICE_NAME, factory, allPartitions);
    // assert that all entries have been written
    IMap<String, String> map = hz.getMap(mapName);
    assertEquals(format("Expected %d entries in the map", expectedEntryCount), expectedEntryCount, map.size());
    for (Map.Entry<String, String> entry : map.entrySet()) {
        assertEquals("Expected that key and value are the same", entry.getKey(), entry.getValue());
    }
    // assert that each member owns entriesPerPartition entries of the map and that all backups have been written
    assertTrueEventually(new AssertTask() {

        @Override
        public void run() {
            int totalBackups = 0;
            for (int i = 0; i < INSTANCE_COUNT; i++) {
                IMap map = instances[i].getMap(mapName);
                assertEquals(format("Each member should own %d entries of the map", entriesPerPartition), entriesPerPartition, map.getLocalMapStats().getOwnedEntryCount());
                totalBackups += map.getLocalMapStats().getBackupEntryCount();
            }
            assertEquals(format("Expected to find %d backups in the cluster", expectedEntryCount), expectedEntryCount, totalBackups);
        }
    });
}
Also used : NodeEngineImpl(com.hazelcast.spi.impl.NodeEngineImpl) Accessors.getNodeEngineImpl(com.hazelcast.test.Accessors.getNodeEngineImpl) SerializationService(com.hazelcast.internal.serialization.SerializationService) PartitionAwareOperationFactory(com.hazelcast.spi.impl.operationservice.impl.operations.PartitionAwareOperationFactory) PutAllPartitionAwareOperationFactory(com.hazelcast.map.impl.operation.PutAllPartitionAwareOperationFactory) HazelcastInstance(com.hazelcast.core.HazelcastInstance) AssertTask(com.hazelcast.test.AssertTask) Map(java.util.Map) OperationServiceImpl(com.hazelcast.spi.impl.operationservice.impl.OperationServiceImpl)

Example 4 with PartitionAwareOperationFactory

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

the class InvokeOnPartitions method retryPartition.

private void retryPartition(final int partitionId) {
    Operation operation;
    PartitionAwareOperationFactory partitionAwareFactory = extractPartitionAware(operationFactory);
    if (partitionAwareFactory != null) {
        operation = partitionAwareFactory.createPartitionOperation(partitionId);
    } else {
        operation = operationFactory.createOperation();
    }
    operationService.createInvocationBuilder(serviceName, operation, partitionId).invoke().whenCompleteAsync((response, throwable) -> {
        if (throwable == null) {
            setPartitionResult(partitionId, response);
            decrementLatchAndHandle(1);
        } else {
            setPartitionResult(partitionId, throwable);
            decrementLatchAndHandle(1);
        }
    });
}
Also used : PartitionAwareOperationFactory(com.hazelcast.spi.impl.operationservice.impl.operations.PartitionAwareOperationFactory) PartitionIteratingOperation(com.hazelcast.spi.impl.operationservice.impl.operations.PartitionIteratingOperation) Operation(com.hazelcast.spi.impl.operationservice.Operation)

Aggregations

PartitionAwareOperationFactory (com.hazelcast.spi.impl.operationservice.impl.operations.PartitionAwareOperationFactory)4 Operation (com.hazelcast.spi.impl.operationservice.Operation)2 OperationServiceImpl (com.hazelcast.spi.impl.operationservice.impl.OperationServiceImpl)2 PartitionIteratingOperation (com.hazelcast.spi.impl.operationservice.impl.operations.PartitionIteratingOperation)2 Map (java.util.Map)2 HazelcastInstance (com.hazelcast.core.HazelcastInstance)1 SerializationService (com.hazelcast.internal.serialization.SerializationService)1 PutAllPartitionAwareOperationFactory (com.hazelcast.map.impl.operation.PutAllPartitionAwareOperationFactory)1 PartitionPredicate (com.hazelcast.query.PartitionPredicate)1 Operation (com.hazelcast.spi.Operation)1 NodeEngineImpl (com.hazelcast.spi.impl.NodeEngineImpl)1 OperationFactory (com.hazelcast.spi.impl.operationservice.OperationFactory)1 Accessors.getNodeEngineImpl (com.hazelcast.test.Accessors.getNodeEngineImpl)1 AssertTask (com.hazelcast.test.AssertTask)1 HashMap (java.util.HashMap)1 LinkedList (java.util.LinkedList)1 Future (java.util.concurrent.Future)1