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);
}
}
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);
}
});
}
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);
}
});
}
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);
}
});
}
Aggregations