Search in sources :

Example 1 with GetOperation

use of com.hazelcast.replicatedmap.impl.operation.GetOperation 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)

Aggregations

Address (com.hazelcast.cluster.Address)1 Member (com.hazelcast.cluster.Member)1 MemberSelectors (com.hazelcast.cluster.memberselector.MemberSelectors)1 EntryEvent (com.hazelcast.core.EntryEvent)1 EntryListener (com.hazelcast.core.EntryListener)1 Data (com.hazelcast.internal.serialization.Data)1 ILogger (com.hazelcast.logging.ILogger)1 MapEvent (com.hazelcast.map.MapEvent)1 IdentifiedDataSerializable (com.hazelcast.nio.serialization.IdentifiedDataSerializable)1 ReplicatedMap (com.hazelcast.replicatedmap.ReplicatedMap)1 ReplicatedMapService (com.hazelcast.replicatedmap.impl.ReplicatedMapService)1 GetOperation (com.hazelcast.replicatedmap.impl.operation.GetOperation)1 NodeEngine (com.hazelcast.spi.impl.NodeEngine)1 Operation (com.hazelcast.spi.impl.operationservice.Operation)1 OperationService (com.hazelcast.spi.impl.operationservice.OperationService)1 Mapping (com.hazelcast.sql.impl.schema.Mapping)1 View (com.hazelcast.sql.impl.schema.view.View)1 Collection (java.util.Collection)1 List (java.util.List)1 Objects (java.util.Objects)1