Search in sources :

Example 91 with OperationService

use of com.hazelcast.spi.impl.operationservice.OperationService in project hazelcast by hazelcast.

the class TablesStorage method awaitMappingOnAllMembers.

/**
 * Temporary measure to ensure schema is propagated to all the members.
 */
@SuppressWarnings("BusyWait")
private void awaitMappingOnAllMembers(String name, IdentifiedDataSerializable metadata) {
    Data keyData = nodeEngine.getSerializationService().toData(name);
    int keyPartitionId = nodeEngine.getPartitionService().getPartitionId(keyData);
    OperationService operationService = nodeEngine.getOperationService();
    Collection<Address> memberAddresses = getMemberAddresses();
    for (int i = 0; i < MAX_CHECK_ATTEMPTS && !memberAddresses.isEmpty(); i++) {
        List<CompletableFuture<Address>> futures = memberAddresses.stream().map(memberAddress -> {
            Operation operation = new GetOperation(CATALOG_MAP_NAME, keyData).setPartitionId(keyPartitionId).setValidateTarget(false);
            return operationService.createInvocationBuilder(ReplicatedMapService.SERVICE_NAME, operation, memberAddress).setTryCount(1).invoke().toCompletableFuture().thenApply(result -> Objects.equals(metadata, result) ? memberAddress : null);
        }).collect(toList());
        for (CompletableFuture<Address> future : futures) {
            try {
                memberAddresses.remove(future.join());
            } catch (Exception e) {
                logger.warning("Error occurred while trying to fetch mapping: " + e.getMessage(), e);
            }
        }
        if (!memberAddresses.isEmpty()) {
            try {
                Thread.sleep(SLEEP_MILLIS);
            } catch (InterruptedException e) {
                break;
            }
        }
    }
}
Also used : EntryEvent(com.hazelcast.core.EntryEvent) Address(com.hazelcast.cluster.Address) IdentifiedDataSerializable(com.hazelcast.nio.serialization.IdentifiedDataSerializable) ReplicatedMap(com.hazelcast.replicatedmap.ReplicatedMap) NodeEngine(com.hazelcast.spi.impl.NodeEngine) Member(com.hazelcast.cluster.Member) Collection(java.util.Collection) Data(com.hazelcast.internal.serialization.Data) EntryListener(com.hazelcast.core.EntryListener) CompletableFuture(java.util.concurrent.CompletableFuture) Collectors(java.util.stream.Collectors) ReplicatedMapService(com.hazelcast.replicatedmap.impl.ReplicatedMapService) Objects(java.util.Objects) Mapping(com.hazelcast.sql.impl.schema.Mapping) List(java.util.List) Collectors.toList(java.util.stream.Collectors.toList) ILogger(com.hazelcast.logging.ILogger) GetOperation(com.hazelcast.replicatedmap.impl.operation.GetOperation) Operation(com.hazelcast.spi.impl.operationservice.Operation) MemberSelectors(com.hazelcast.cluster.memberselector.MemberSelectors) View(com.hazelcast.sql.impl.schema.view.View) MapEvent(com.hazelcast.map.MapEvent) OperationService(com.hazelcast.spi.impl.operationservice.OperationService) Collectors.toSet(java.util.stream.Collectors.toSet) GetOperation(com.hazelcast.replicatedmap.impl.operation.GetOperation) Address(com.hazelcast.cluster.Address) Data(com.hazelcast.internal.serialization.Data) GetOperation(com.hazelcast.replicatedmap.impl.operation.GetOperation) Operation(com.hazelcast.spi.impl.operationservice.Operation) CompletableFuture(java.util.concurrent.CompletableFuture) OperationService(com.hazelcast.spi.impl.operationservice.OperationService)

Example 92 with OperationService

use of com.hazelcast.spi.impl.operationservice.OperationService in project hazelcast by hazelcast.

the class MigrationManager method publishCompletedMigrations.

private void publishCompletedMigrations() {
    if (!partitionService.isLocalMemberMaster()) {
        return;
    }
    assert partitionStateManager.isInitialized();
    final List<MigrationInfo> migrations = getCompletedMigrationsCopy();
    if (logger.isFineEnabled()) {
        logger.fine("Publishing completed migrations [" + migrations.size() + "]: " + migrations);
    }
    OperationService operationService = nodeEngine.getOperationService();
    ClusterServiceImpl clusterService = node.clusterService;
    final Collection<Member> members = clusterService.getMembers();
    final AtomicInteger latch = new AtomicInteger(members.size() - 1);
    for (Member member : members) {
        if ((member.localMember())) {
            continue;
        }
        Operation operation = new PublishCompletedMigrationsOperation(migrations);
        InternalCompletableFuture<Boolean> f = operationService.invokeOnTarget(SERVICE_NAME, operation, member.getAddress());
        f.whenCompleteAsync((response, t) -> {
            if (t == null) {
                if (!Boolean.TRUE.equals(response)) {
                    logger.fine(member + " rejected completed migrations with response " + response);
                    partitionService.sendPartitionRuntimeState(member.getAddress());
                    return;
                }
                if (latch.decrementAndGet() == 0) {
                    logger.fine("Evicting " + migrations.size() + " completed migrations.");
                    evictCompletedMigrations(migrations);
                }
            } else {
                logger.fine("Failure while publishing completed migrations to " + member, t);
                partitionService.sendPartitionRuntimeState(member.getAddress());
            }
        }, asyncExecutor);
    }
}
Also used : MigrationInfo(com.hazelcast.internal.partition.MigrationInfo) PublishCompletedMigrationsOperation(com.hazelcast.internal.partition.operation.PublishCompletedMigrationsOperation) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) ClusterServiceImpl(com.hazelcast.internal.cluster.impl.ClusterServiceImpl) OperationService(com.hazelcast.spi.impl.operationservice.OperationService) ShutdownResponseOperation(com.hazelcast.internal.partition.operation.ShutdownResponseOperation) MigrationCommitOperation(com.hazelcast.internal.partition.operation.MigrationCommitOperation) MigrationRequestOperation(com.hazelcast.internal.partition.operation.MigrationRequestOperation) Operation(com.hazelcast.spi.impl.operationservice.Operation) FinalizeMigrationOperation(com.hazelcast.internal.partition.operation.FinalizeMigrationOperation) PartitionStateOperation(com.hazelcast.internal.partition.operation.PartitionStateOperation) PromotionCommitOperation(com.hazelcast.internal.partition.operation.PromotionCommitOperation) PublishCompletedMigrationsOperation(com.hazelcast.internal.partition.operation.PublishCompletedMigrationsOperation) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) Member(com.hazelcast.cluster.Member)

Example 93 with OperationService

use of com.hazelcast.spi.impl.operationservice.OperationService in project hazelcast by hazelcast.

the class PartitionReplicaStateChecker method hasOnGoingMigrationMaster.

boolean hasOnGoingMigrationMaster(Level level) {
    ClusterService clusterService = node.getClusterService();
    Address masterAddress = clusterService.getMasterAddress();
    if (masterAddress == null) {
        return clusterService.isJoined();
    }
    Operation operation = new HasOngoingMigration();
    OperationService operationService = nodeEngine.getOperationService();
    InvocationFuture<Boolean> future = operationService.createInvocationBuilder(SERVICE_NAME, operation, masterAddress).setTryCount(INVOCATION_TRY_COUNT).setTryPauseMillis(INVOCATION_TRY_PAUSE_MILLIS).invoke();
    try {
        return future.joinInternal();
    } catch (Exception e) {
        logger.log(level, "Could not get a response from master about migrations! -> " + e.toString());
    }
    return false;
}
Also used : ClusterService(com.hazelcast.internal.cluster.ClusterService) HasOngoingMigration(com.hazelcast.internal.partition.operation.HasOngoingMigration) Address(com.hazelcast.cluster.Address) Operation(com.hazelcast.spi.impl.operationservice.Operation) OperationService(com.hazelcast.spi.impl.operationservice.OperationService) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean)

Example 94 with OperationService

use of com.hazelcast.spi.impl.operationservice.OperationService in project hazelcast by hazelcast.

the class InternalPartitionServiceImpl method publishPartitionRuntimeState.

/**
 * Called on the master node to publish the current partition state to all cluster nodes. It will not publish the partition
 * state if the partitions have not yet been initialized, there is ongoing repartitioning or a node is joining the cluster.
 */
@SuppressWarnings("checkstyle:npathcomplexity")
void publishPartitionRuntimeState() {
    if (!partitionStateManager.isInitialized()) {
        // do not send partition state until initialized!
        return;
    }
    if (!isLocalMemberMaster()) {
        return;
    }
    if (!areMigrationTasksAllowed()) {
        // migration is disabled because of a member leave, wait till enabled!
        return;
    }
    PartitionRuntimeState partitionState = createPartitionStateInternal();
    if (partitionState == null) {
        return;
    }
    if (logger.isFineEnabled()) {
        logger.fine("Publishing partition state, stamp: " + partitionState.getStamp());
    }
    PartitionStateOperation op = new PartitionStateOperation(partitionState, false);
    OperationService operationService = nodeEngine.getOperationService();
    Collection<Member> members = node.clusterService.getMembers();
    for (Member member : members) {
        if (!member.localMember()) {
            try {
                operationService.send(op, member.getAddress());
            } catch (Exception e) {
                logger.finest(e);
            }
        }
    }
}
Also used : PartitionRuntimeState(com.hazelcast.internal.partition.PartitionRuntimeState) OperationService(com.hazelcast.spi.impl.operationservice.OperationService) FetchPartitionStateOperation(com.hazelcast.internal.partition.operation.FetchPartitionStateOperation) PartitionStateOperation(com.hazelcast.internal.partition.operation.PartitionStateOperation) Member(com.hazelcast.cluster.Member) HazelcastInstanceNotActiveException(com.hazelcast.core.HazelcastInstanceNotActiveException) TimeoutException(java.util.concurrent.TimeoutException) TargetNotMemberException(com.hazelcast.spi.exception.TargetNotMemberException) NoDataMemberInClusterException(com.hazelcast.partition.NoDataMemberInClusterException) MemberLeftException(com.hazelcast.core.MemberLeftException)

Example 95 with OperationService

use of com.hazelcast.spi.impl.operationservice.OperationService in project hazelcast by hazelcast.

the class AbstractPartitionPrimaryReplicaAntiEntropyTask method invokePartitionBackupReplicaAntiEntropyOp.

final void invokePartitionBackupReplicaAntiEntropyOp(int replicaIndex, PartitionReplica target, Collection<ServiceNamespace> namespaces, BiConsumer<Object, Throwable> callback) {
    if (skipSendingToTarget(target)) {
        return;
    }
    PartitionReplicaManager replicaManager = partitionService.getReplicaManager();
    Map<ServiceNamespace, Long> versionMap = new HashMap<>();
    for (ServiceNamespace ns : namespaces) {
        long[] versions = replicaManager.getPartitionReplicaVersions(partitionId, ns);
        long currentReplicaVersion = versions[replicaIndex - 1];
        versionMap.put(ns, currentReplicaVersion);
    }
    boolean hasCallback = (callback != null);
    Operation op = new PartitionBackupReplicaAntiEntropyOperation(versionMap, hasCallback);
    op.setPartitionId(partitionId).setReplicaIndex(replicaIndex).setServiceName(SERVICE_NAME);
    ILogger logger = nodeEngine.getLogger(getClass());
    if (logger.isFinestEnabled()) {
        logger.finest("Sending anti-entropy operation to " + target + " for partitionId=" + partitionId + ", replicaIndex=" + replicaIndex + ", namespaces=" + versionMap);
    }
    OperationService operationService = nodeEngine.getOperationService();
    if (hasCallback) {
        operationService.createInvocationBuilder(SERVICE_NAME, op, target.address()).setTryCount(OPERATION_TRY_COUNT).setTryPauseMillis(OPERATION_TRY_PAUSE_MILLIS).invoke().whenCompleteAsync(callback);
    } else {
        operationService.send(op, target.address());
    }
}
Also used : HashMap(java.util.HashMap) PartitionBackupReplicaAntiEntropyOperation(com.hazelcast.internal.partition.operation.PartitionBackupReplicaAntiEntropyOperation) NonFragmentedServiceNamespace(com.hazelcast.internal.partition.NonFragmentedServiceNamespace) ServiceNamespace(com.hazelcast.internal.services.ServiceNamespace) ILogger(com.hazelcast.logging.ILogger) PartitionBackupReplicaAntiEntropyOperation(com.hazelcast.internal.partition.operation.PartitionBackupReplicaAntiEntropyOperation) UrgentSystemOperation(com.hazelcast.spi.impl.operationservice.UrgentSystemOperation) Operation(com.hazelcast.spi.impl.operationservice.Operation) OperationService(com.hazelcast.spi.impl.operationservice.OperationService)

Aggregations

OperationService (com.hazelcast.spi.impl.operationservice.OperationService)140 Operation (com.hazelcast.spi.impl.operationservice.Operation)55 Test (org.junit.Test)54 HazelcastInstance (com.hazelcast.core.HazelcastInstance)46 QuickTest (com.hazelcast.test.annotation.QuickTest)41 Accessors.getOperationService (com.hazelcast.test.Accessors.getOperationService)40 ParallelJVMTest (com.hazelcast.test.annotation.ParallelJVMTest)40 Address (com.hazelcast.cluster.Address)31 NodeEngine (com.hazelcast.spi.impl.NodeEngine)31 InternalCompletableFuture (com.hazelcast.spi.impl.InternalCompletableFuture)24 Future (java.util.concurrent.Future)24 TestHazelcastInstanceFactory (com.hazelcast.test.TestHazelcastInstanceFactory)23 Config (com.hazelcast.config.Config)22 Member (com.hazelcast.cluster.Member)21 Data (com.hazelcast.internal.serialization.Data)12 SlowTest (com.hazelcast.test.annotation.SlowTest)12 ClusterService (com.hazelcast.internal.cluster.ClusterService)9 ILogger (com.hazelcast.logging.ILogger)7 ArrayList (java.util.ArrayList)7 IPartitionService (com.hazelcast.internal.partition.IPartitionService)6