Search in sources :

Example 96 with NodeEngine

use of com.hazelcast.spi.impl.NodeEngine in project hazelcast by hazelcast.

the class ExecutionPlanBuilder method getPartitionAssignment.

/**
 * Assign the partitions to their owners. Partitions whose owner isn't in
 * the {@code memberList}, are assigned to one of the members in a
 * round-robin way.
 */
public static Map<MemberInfo, int[]> getPartitionAssignment(NodeEngine nodeEngine, List<MemberInfo> memberList) {
    IPartitionService partitionService = nodeEngine.getPartitionService();
    Map<Address, MemberInfo> membersByAddress = memberList.stream().collect(toMap(MemberInfo::getAddress, identity()));
    final MemberInfo[] partitionOwners = new MemberInfo[partitionService.getPartitionCount()];
    int memberIndex = 0;
    for (int partitionId = 0; partitionId < partitionOwners.length; partitionId++) {
        Address address = partitionService.getPartitionOwnerOrWait(partitionId);
        MemberInfo member = membersByAddress.get(address);
        if (member == null) {
            // if the partition owner isn't in the current memberList, assign to one of the other members in
            // round-robin fashion
            member = memberList.get(memberIndex++ % memberList.size());
        }
        partitionOwners[partitionId] = member;
    }
    return IntStream.range(0, partitionOwners.length).mapToObj(i -> tuple2(partitionOwners[i], i)).collect(Collectors.groupingBy(Tuple2::f0, Collectors.mapping(Tuple2::f1, Collectors.collectingAndThen(Collectors.<Integer>toList(), intList -> intList.stream().mapToInt(Integer::intValue).toArray()))));
}
Also used : IntStream(java.util.stream.IntStream) Address(com.hazelcast.cluster.Address) EdgeConfig(com.hazelcast.jet.config.EdgeConfig) Util.checkSerializable(com.hazelcast.jet.impl.util.Util.checkSerializable) Util.doWithClassLoader(com.hazelcast.jet.impl.util.Util.doWithClassLoader) HashMap(java.util.HashMap) ExceptionUtil.sneakyThrow(com.hazelcast.jet.impl.util.ExceptionUtil.sneakyThrow) Function(java.util.function.Function) ArrayList(java.util.ArrayList) PrefixedLogger.prefixedLogger(com.hazelcast.jet.impl.util.PrefixedLogger.prefixedLogger) LinkedHashMap(java.util.LinkedHashMap) Collectors.toMap(java.util.stream.Collectors.toMap) ILogger(com.hazelcast.logging.ILogger) MemberInfo(com.hazelcast.internal.cluster.MemberInfo) Map(java.util.Map) DAG(com.hazelcast.jet.core.DAG) Edge(com.hazelcast.jet.core.Edge) ProcessorSupplier(com.hazelcast.jet.core.ProcessorSupplier) Tuple2(com.hazelcast.jet.datamodel.Tuple2) NodeEngineImpl(com.hazelcast.spi.impl.NodeEngineImpl) PrefixedLogger.prefix(com.hazelcast.jet.impl.util.PrefixedLogger.prefix) NodeEngine(com.hazelcast.spi.impl.NodeEngine) Util.toList(com.hazelcast.jet.impl.util.Util.toList) ProcessorMetaSupplier(com.hazelcast.jet.core.ProcessorMetaSupplier) IPartitionService(com.hazelcast.internal.partition.IPartitionService) JobConfig(com.hazelcast.jet.config.JobConfig) MetaSupplierCtx(com.hazelcast.jet.impl.execution.init.Contexts.MetaSupplierCtx) Collectors(java.util.stream.Collectors) Subject(javax.security.auth.Subject) Vertex(com.hazelcast.jet.core.Vertex) List(java.util.List) Tuple2.tuple2(com.hazelcast.jet.datamodel.Tuple2.tuple2) FunctionEx.identity(com.hazelcast.function.FunctionEx.identity) Entry(java.util.Map.Entry) JobClassLoaderService(com.hazelcast.jet.impl.JobClassLoaderService) JetServiceBackend(com.hazelcast.jet.impl.JetServiceBackend) Address(com.hazelcast.cluster.Address) MemberInfo(com.hazelcast.internal.cluster.MemberInfo) IPartitionService(com.hazelcast.internal.partition.IPartitionService) Tuple2(com.hazelcast.jet.datamodel.Tuple2)

Example 97 with NodeEngine

use of com.hazelcast.spi.impl.NodeEngine in project hazelcast by hazelcast.

the class MapContainer method initEvictor.

public final void initEvictor() {
    NodeEngine nodeEngine = mapServiceContext.getNodeEngine();
    EvictionPolicyComparator evictionPolicyComparator = getEvictionPolicyComparator(mapConfig.getEvictionConfig(), nodeEngine.getConfigClassLoader());
    evictor = evictionPolicyComparator != null ? newEvictor(evictionPolicyComparator, nodeEngine.getProperties().getInteger(MAP_EVICTION_BATCH_SIZE), nodeEngine.getPartitionService()) : NULL_EVICTOR;
}
Also used : NodeEngine(com.hazelcast.spi.impl.NodeEngine) EvictionPolicyComparator(com.hazelcast.spi.eviction.EvictionPolicyComparator) EvictionPolicyEvaluatorProvider.getEvictionPolicyComparator(com.hazelcast.internal.eviction.EvictionPolicyEvaluatorProvider.getEvictionPolicyComparator)

Example 98 with NodeEngine

use of com.hazelcast.spi.impl.NodeEngine in project hazelcast by hazelcast.

the class NodeQueryCacheEventService method canPassFilter.

private boolean canPassFilter(LocalEntryEventData localEntryEventData, EventFilter filter, Extractors extractors) {
    if (filter == null || filter instanceof TrueEventFilter) {
        return true;
    }
    NodeEngine nodeEngine = mapServiceContext.getNodeEngine();
    SerializationService serializationService = nodeEngine.getSerializationService();
    Data keyData = localEntryEventData.getKeyData();
    Object value = getValueOrOldValue(localEntryEventData);
    QueryableEntry entry = new QueryEntry(serializationService, keyData, value, extractors);
    return filter.eval(entry);
}
Also used : NodeEngine(com.hazelcast.spi.impl.NodeEngine) QueryEntry(com.hazelcast.query.impl.QueryEntry) SerializationService(com.hazelcast.internal.serialization.SerializationService) LocalCacheWideEventData(com.hazelcast.map.impl.querycache.event.LocalCacheWideEventData) EventData(com.hazelcast.map.impl.event.EventData) Data(com.hazelcast.internal.serialization.Data) LocalEntryEventData(com.hazelcast.map.impl.querycache.event.LocalEntryEventData) TrueEventFilter(com.hazelcast.spi.impl.eventservice.impl.TrueEventFilter) QueryableEntry(com.hazelcast.query.impl.QueryableEntry)

Example 99 with NodeEngine

use of com.hazelcast.spi.impl.NodeEngine in project hazelcast by hazelcast.

the class MultiMapProxyImpl method toObjectSet.

private Set<K> toObjectSet(Set<Data> dataSet) {
    NodeEngine nodeEngine = getNodeEngine();
    Set<K> keySet = createHashSet(dataSet.size());
    for (Data dataKey : dataSet) {
        keySet.add((K) nodeEngine.toObject(dataKey));
    }
    if (config.isStatisticsEnabled()) {
        getService().getLocalMultiMapStatsImpl(name).incrementOtherOperations();
    }
    return keySet;
}
Also used : NodeEngine(com.hazelcast.spi.impl.NodeEngine) Data(com.hazelcast.internal.serialization.Data)

Example 100 with NodeEngine

use of com.hazelcast.spi.impl.NodeEngine in project hazelcast by hazelcast.

the class MultiMapProxySupport method clear.

public void clear() {
    NodeEngine nodeEngine = getNodeEngine();
    try {
        Map<Integer, Object> resultMap = nodeEngine.getOperationService().invokeOnAllPartitions(MultiMapService.SERVICE_NAME, new MultiMapOperationFactory(name, OperationFactoryType.CLEAR));
        if (config.isStatisticsEnabled()) {
            getService().getLocalMultiMapStatsImpl(name).incrementOtherOperations();
        }
        int numberOfAffectedEntries = 0;
        for (Object o : resultMap.values()) {
            numberOfAffectedEntries += (Integer) o;
        }
        publishMultiMapEvent(numberOfAffectedEntries, EntryEventType.CLEAR_ALL);
    } catch (Throwable throwable) {
        throw ExceptionUtil.rethrow(throwable);
    }
}
Also used : NodeEngine(com.hazelcast.spi.impl.NodeEngine) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) MultiMapOperationFactory(com.hazelcast.multimap.impl.operations.MultiMapOperationFactory) AbstractDistributedObject(com.hazelcast.spi.impl.AbstractDistributedObject)

Aggregations

NodeEngine (com.hazelcast.spi.impl.NodeEngine)165 Data (com.hazelcast.internal.serialization.Data)48 OperationService (com.hazelcast.spi.impl.operationservice.OperationService)30 Address (com.hazelcast.cluster.Address)22 Test (org.junit.Test)21 ILogger (com.hazelcast.logging.ILogger)20 HazelcastInstance (com.hazelcast.core.HazelcastInstance)18 ParallelJVMTest (com.hazelcast.test.annotation.ParallelJVMTest)18 QuickTest (com.hazelcast.test.annotation.QuickTest)18 Config (com.hazelcast.config.Config)17 Operation (com.hazelcast.spi.impl.operationservice.Operation)16 MapServiceContext (com.hazelcast.map.impl.MapServiceContext)15 IPartitionService (com.hazelcast.internal.partition.IPartitionService)12 Nonnull (javax.annotation.Nonnull)12 ArrayList (java.util.ArrayList)11 Future (java.util.concurrent.Future)11 Member (com.hazelcast.cluster.Member)10 UUID (java.util.UUID)10 InitializingObject (com.hazelcast.spi.impl.InitializingObject)9 TestHazelcastInstanceFactory (com.hazelcast.test.TestHazelcastInstanceFactory)9