Search in sources :

Example 51 with OperationServiceImpl

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);
    }
}
Also used : Address(com.hazelcast.cluster.Address) MemberImpl(com.hazelcast.cluster.impl.MemberImpl) Future(java.util.concurrent.Future) AccumulatorInfo(com.hazelcast.map.impl.querycache.accumulator.AccumulatorInfo) InvocationBuilder(com.hazelcast.spi.impl.operationservice.InvocationBuilder) PublisherCreateOperation(com.hazelcast.map.impl.querycache.subscriber.operation.PublisherCreateOperation) OperationServiceImpl(com.hazelcast.spi.impl.operationservice.impl.OperationServiceImpl) Predicate(com.hazelcast.query.Predicate)

Example 52 with OperationServiceImpl

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);
        }
    });
}
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 53 with OperationServiceImpl

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;
    }
}
Also used : Address(com.hazelcast.cluster.Address) InetAddress(java.net.InetAddress) UnknownHostException(java.net.UnknownHostException) LinkedList(java.util.LinkedList) InvalidAddressException(com.hazelcast.internal.util.AddressUtil.InvalidAddressException) UnknownHostException(java.net.UnknownHostException) Future(java.util.concurrent.Future) OperationServiceImpl(com.hazelcast.spi.impl.operationservice.impl.OperationServiceImpl) HashSet(java.util.HashSet) JoinMastershipClaimOp(com.hazelcast.internal.cluster.impl.operations.JoinMastershipClaimOp)

Example 54 with OperationServiceImpl

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());
}
Also used : Accessors.getAddress(com.hazelcast.test.Accessors.getAddress) Config(com.hazelcast.config.Config) HazelcastOverloadException(com.hazelcast.core.HazelcastOverloadException) Accessors.getNode(com.hazelcast.test.Accessors.getNode) Node(com.hazelcast.instance.impl.Node) HazelcastInstance(com.hazelcast.core.HazelcastInstance) ExecutionException(java.util.concurrent.ExecutionException) OperationServiceImpl(com.hazelcast.spi.impl.operationservice.impl.OperationServiceImpl) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 55 with OperationServiceImpl

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]);
    });
}
Also used : TryLockOp(com.hazelcast.cp.internal.datastructures.lock.operation.TryLockOp) NodeEngineImpl(com.hazelcast.spi.impl.NodeEngineImpl) Accessors.getNodeEngineImpl(com.hazelcast.test.Accessors.getNodeEngineImpl) RaftInvocationManager(com.hazelcast.cp.internal.RaftInvocationManager) RaftService(com.hazelcast.cp.internal.RaftService) RaftGroupId(com.hazelcast.cp.internal.RaftGroupId) CountDownLatch(java.util.concurrent.CountDownLatch) PartitionSpecificRunnable(com.hazelcast.spi.impl.PartitionSpecificRunnable) UuidUtil.newUnsecureUUID(com.hazelcast.internal.util.UuidUtil.newUnsecureUUID) UUID(java.util.UUID) Map(java.util.Map) OperationServiceImpl(com.hazelcast.spi.impl.operationservice.impl.OperationServiceImpl) Test(org.junit.Test)

Aggregations

OperationServiceImpl (com.hazelcast.spi.impl.operationservice.impl.OperationServiceImpl)70 Test (org.junit.Test)29 ParallelJVMTest (com.hazelcast.test.annotation.ParallelJVMTest)26 QuickTest (com.hazelcast.test.annotation.QuickTest)25 Address (com.hazelcast.cluster.Address)22 NodeEngineImpl (com.hazelcast.spi.impl.NodeEngineImpl)16 HazelcastInstance (com.hazelcast.core.HazelcastInstance)15 Operation (com.hazelcast.spi.impl.operationservice.Operation)12 PartitionIdSet (com.hazelcast.internal.util.collection.PartitionIdSet)11 IndexIterationPointer (com.hazelcast.internal.iteration.IndexIterationPointer)10 MapFetchIndexOperationResult (com.hazelcast.map.impl.operation.MapFetchIndexOperation.MapFetchIndexOperationResult)10 Config (com.hazelcast.config.Config)9 ExecutionException (java.util.concurrent.ExecutionException)9 Accessors.getNodeEngineImpl (com.hazelcast.test.Accessors.getNodeEngineImpl)8 AssertTask (com.hazelcast.test.AssertTask)7 CountDownLatch (java.util.concurrent.CountDownLatch)7 Member (com.hazelcast.cluster.Member)5 Data (com.hazelcast.internal.serialization.Data)5 MapService (com.hazelcast.map.impl.MapService)5 MapServiceContext (com.hazelcast.map.impl.MapServiceContext)5