use of com.hazelcast.spi.impl.operationservice.impl.OperationServiceImpl in project hazelcast by hazelcast.
the class MapPublisherCreateMessageTask method createInvocations.
private void createInvocations(Collection<MemberImpl> members, List<Future> futures) {
final OperationServiceImpl operationService = nodeEngine.getOperationService();
for (MemberImpl member : members) {
Predicate predicate = serializationService.toObject(parameters.predicate);
AccumulatorInfo accumulatorInfo = AccumulatorInfo.toAccumulatorInfo(parameters.mapName, parameters.cacheName, predicate, parameters.batchSize, parameters.bufferSize, parameters.delaySeconds, false, parameters.populate, parameters.coalesce);
PublisherCreateOperation operation = new PublisherCreateOperation(accumulatorInfo);
operation.setCallerUuid(endpoint.getUuid());
Address address = member.getAddress();
InvocationBuilder invocationBuilder = operationService.createInvocationBuilder(SERVICE_NAME, operation, address);
Future future = invocationBuilder.invoke();
futures.add(future);
}
}
use of com.hazelcast.spi.impl.operationservice.impl.OperationServiceImpl 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.OperationServiceImpl in project hazelcast by hazelcast.
the class TcpIpJoiner method claimMastership.
private boolean claimMastership(Collection<Address> possibleAddresses) {
if (logger.isFineEnabled()) {
Set<Address> votingEndpoints = new HashSet<>(possibleAddresses);
votingEndpoints.removeAll(blacklistedAddresses.keySet());
logger.fine("Claiming myself as master node! Asking to endpoints: " + votingEndpoints);
}
claimingMastership = true;
OperationServiceImpl operationService = node.getNodeEngine().getOperationService();
Collection<Future<Boolean>> futures = new LinkedList<>();
for (Address address : possibleAddresses) {
try {
if (isBlacklisted(address) || isLocalAddress(address)) {
continue;
}
} catch (UnknownHostException e) {
logger.warning(e);
ignore(e);
}
Future<Boolean> future = operationService.createInvocationBuilder(SERVICE_NAME, new JoinMastershipClaimOp(), address).setTryCount(1).invoke();
futures.add(future);
}
try {
Collection<Boolean> responses = returnWithDeadline(futures, MASTERSHIP_CLAIM_TIMEOUT, TimeUnit.SECONDS, RETHROW_EVERYTHING);
for (Boolean response : responses) {
if (!response) {
return false;
}
}
return true;
} catch (Exception e) {
logger.fine(e);
return false;
}
}
use of com.hazelcast.spi.impl.operationservice.impl.OperationServiceImpl in project hazelcast by hazelcast.
the class ClusterShutdownTest method clusterShutdown_shouldNotBeRejected_byBackpressure.
@Test
public void clusterShutdown_shouldNotBeRejected_byBackpressure() throws Exception {
Config config = new Config();
config.setProperty(ClusterProperty.PARTITION_COUNT.toString(), "1");
config.setProperty(ClusterProperty.BACKPRESSURE_ENABLED.toString(), "true");
config.setProperty(ClusterProperty.BACKPRESSURE_BACKOFF_TIMEOUT_MILLIS.toString(), "100");
config.setProperty(ClusterProperty.BACKPRESSURE_MAX_CONCURRENT_INVOCATIONS_PER_PARTITION.toString(), "3");
HazelcastInstance hz = createHazelcastInstance(config);
final OperationServiceImpl operationService = getOperationService(hz);
final Address address = getAddress(hz);
for (int i = 0; i < 10; i++) {
Future<Object> future = spawn(new Callable<Object>() {
@Override
public Object call() {
operationService.invokeOnTarget(null, new AlwaysBlockingOperation(), address);
return null;
}
});
try {
future.get();
} catch (ExecutionException e) {
assertInstanceOf(HazelcastOverloadException.class, e.getCause());
}
}
Node node = getNode(hz);
hz.getCluster().shutdown();
assertFalse(hz.getLifecycleService().isRunning());
assertEquals(NodeState.SHUT_DOWN, node.getState());
}
use of com.hazelcast.spi.impl.operationservice.impl.OperationServiceImpl in project hazelcast by hazelcast.
the class AbstractFencedLockFailureTest method testRetriedTryLockWithTimeoutDoesNotCancelPendingLockRequest.
@Test(timeout = 300_000)
public void testRetriedTryLockWithTimeoutDoesNotCancelPendingLockRequest() {
lockByOtherThread();
// there is a session id now
RaftGroupId groupId = lock.getGroupId();
long sessionId = getSessionManager().getSession(groupId);
RaftInvocationManager invocationManager = getRaftInvocationManager();
UUID invUid = newUnsecureUUID();
invocationManager.invoke(groupId, new TryLockOp(objectName, sessionId, getThreadId(), invUid, MINUTES.toMillis(5)));
NodeEngineImpl nodeEngine = getNodeEngineImpl(primaryInstance);
LockService service = nodeEngine.getService(LockService.SERVICE_NAME);
assertTrueEventually(() -> {
LockRegistry registry = service.getRegistryOrNull(groupId);
assertNotNull(registry);
assertNotNull(registry.getResourceOrNull(objectName));
assertEquals(1, registry.getWaitTimeouts().size());
});
invocationManager.invoke(groupId, new TryLockOp(objectName, sessionId, getThreadId(), invUid, MINUTES.toMillis(5)));
assertTrueEventually(() -> {
RaftService raftService = getNodeEngineImpl(primaryInstance).getService(RaftService.SERVICE_NAME);
int partitionId = raftService.getCPGroupPartitionId(groupId);
LockRegistry registry = service.getRegistryOrNull(groupId);
boolean[] verified = new boolean[1];
CountDownLatch latch = new CountDownLatch(1);
OperationServiceImpl operationService = nodeEngine.getOperationService();
operationService.execute(new PartitionSpecificRunnable() {
@Override
public int getPartitionId() {
return partitionId;
}
@Override
public void run() {
Lock lock = registry.getResourceOrNull(objectName);
Map<Object, WaitKeyContainer<LockInvocationKey>> waitKeys = lock.getInternalWaitKeysMap();
verified[0] = (waitKeys.size() == 1 && waitKeys.values().iterator().next().retryCount() == 1);
latch.countDown();
}
});
latch.await(60, SECONDS);
assertTrue(verified[0]);
});
}
Aggregations