Search in sources :

Example 1 with Accumulator

use of com.hazelcast.map.impl.querycache.accumulator.Accumulator in project hazelcast by hazelcast.

the class AccumulatorConsumerOperation method run.

@Override
public void run() throws Exception {
    QueryCacheContext context = getQueryCacheContext();
    QueryCacheEventService queryCacheEventService = context.getQueryCacheEventService();
    EventPublisherAccumulatorProcessor processor = new EventPublisherAccumulatorProcessor(queryCacheEventService);
    AccumulatorHandler<Sequenced> handler = new PublisherAccumulatorHandler(context, processor);
    int processed = 0;
    do {
        Accumulator accumulator = accumulators.poll();
        if (accumulator == null) {
            break;
        }
        if (isLocal()) {
            // consume the accumulator if only this node is the owner
            // of accumulators partition
            publishAccumulator(processor, handler, accumulator);
        } else {
            // if the accumulator is not local, it should be a leftover
            // stayed after partition migrations and remove that accumulator
            removeAccumulator(context, accumulator);
        }
        processed++;
    } while (processed <= maxProcessableAccumulatorCount);
}
Also used : Accumulator(com.hazelcast.map.impl.querycache.accumulator.Accumulator) QueryCacheEventService(com.hazelcast.map.impl.querycache.QueryCacheEventService) EventPublisherAccumulatorProcessor(com.hazelcast.map.impl.querycache.publisher.EventPublisherAccumulatorProcessor) Sequenced(com.hazelcast.map.impl.querycache.event.sequence.Sequenced) PublisherAccumulatorHandler(com.hazelcast.map.impl.querycache.publisher.PublisherAccumulatorHandler) QueryCacheContext(com.hazelcast.map.impl.querycache.QueryCacheContext)

Example 2 with Accumulator

use of com.hazelcast.map.impl.querycache.accumulator.Accumulator in project hazelcast by hazelcast.

the class ReadAndResetAccumulatorOperation method run.

@Override
public void run() throws Exception {
    QueryCacheContext context = getQueryCacheContext();
    Map<Integer, Accumulator> accumulators = getAccumulators(context, name, cacheName);
    Accumulator<Sequenced> accumulator = accumulators.get(getPartitionId());
    if (accumulator.isEmpty()) {
        return;
    }
    eventDataList = new ArrayList<Sequenced>(accumulator.size());
    for (Sequenced sequenced : accumulator) {
        eventDataList.add(sequenced);
    }
    accumulator.reset();
}
Also used : Accumulator(com.hazelcast.map.impl.querycache.accumulator.Accumulator) Sequenced(com.hazelcast.map.impl.querycache.event.sequence.Sequenced) QueryCacheContext(com.hazelcast.map.impl.querycache.QueryCacheContext)

Example 3 with Accumulator

use of com.hazelcast.map.impl.querycache.accumulator.Accumulator in project hazelcast by hazelcast.

the class DefaultQueryCache method tryRecover.

@Override
public boolean tryRecover() {
    SubscriberContext subscriberContext = context.getSubscriberContext();
    MapSubscriberRegistry mapSubscriberRegistry = subscriberContext.getMapSubscriberRegistry();
    SubscriberRegistry subscriberRegistry = mapSubscriberRegistry.getOrNull(mapName);
    if (subscriberRegistry == null) {
        return true;
    }
    Accumulator accumulator = subscriberRegistry.getOrNull(cacheName);
    if (accumulator == null) {
        return true;
    }
    SubscriberAccumulator subscriberAccumulator = (SubscriberAccumulator) accumulator;
    ConcurrentMap<Integer, Long> brokenSequences = subscriberAccumulator.getBrokenSequences();
    if (brokenSequences.isEmpty()) {
        return true;
    }
    return isTryRecoverSucceeded(brokenSequences);
}
Also used : Accumulator(com.hazelcast.map.impl.querycache.accumulator.Accumulator)

Example 4 with Accumulator

use of com.hazelcast.map.impl.querycache.accumulator.Accumulator in project hazelcast by hazelcast.

the class AccumulatorSweeper method flushAccumulator.

public static void flushAccumulator(PublisherContext publisherContext, int partitionId) {
    QueryCacheEventData endOfSequenceEvent = createEndOfSequenceEvent(partitionId);
    QueryCacheContext context = publisherContext.getContext();
    EventPublisherAccumulatorProcessor processor = new EventPublisherAccumulatorProcessor(context.getQueryCacheEventService());
    PublisherAccumulatorHandler handler = new PublisherAccumulatorHandler(context, processor);
    MapPublisherRegistry mapPublisherRegistry = publisherContext.getMapPublisherRegistry();
    Map<String, PublisherRegistry> allPublisherRegistryMap = mapPublisherRegistry.getAll();
    for (PublisherRegistry publisherRegistry : allPublisherRegistryMap.values()) {
        Map<String, PartitionAccumulatorRegistry> accumulatorRegistryMap = publisherRegistry.getAll();
        for (PartitionAccumulatorRegistry accumulatorRegistry : accumulatorRegistryMap.values()) {
            Map<Integer, Accumulator> accumulatorMap = accumulatorRegistry.getAll();
            Accumulator accumulator = accumulatorMap.get(partitionId);
            if (accumulator == null) {
                continue;
            }
            processor.setInfo(accumulator.getInfo());
            // give 0 to delay-time in order to fetch all events in the accumulator
            accumulator.poll(handler, 0, TimeUnit.SECONDS);
            // send end event
            processor.process(endOfSequenceEvent);
        }
    }
}
Also used : Accumulator(com.hazelcast.map.impl.querycache.accumulator.Accumulator) QueryCacheContext(com.hazelcast.map.impl.querycache.QueryCacheContext) QueryCacheEventData(com.hazelcast.map.impl.querycache.event.QueryCacheEventData)

Example 5 with Accumulator

use of com.hazelcast.map.impl.querycache.accumulator.Accumulator in project hazelcast by hazelcast.

the class QueryCacheEventPublisher method addEventToQueryCache.

public void addEventToQueryCache(Object eventData) {
    checkInstanceOf(EventData.class, eventData, "eventData");
    String mapName = ((EventData) eventData).getMapName();
    int eventType = ((EventData) eventData).getEventType();
    // this collection contains all defined query-caches on an IMap
    Collection<PartitionAccumulatorRegistry> partitionAccumulatorRegistries = getPartitionAccumulatorRegistries(mapName);
    if (isEmpty(partitionAccumulatorRegistries)) {
        return;
    }
    if (!(eventData instanceof EntryEventData)) {
        return;
    }
    EntryEventData entryEvenData = (EntryEventData) eventData;
    Data dataKey = entryEvenData.getDataKey();
    Data dataNewValue = entryEvenData.getDataNewValue();
    Data dataOldValue = entryEvenData.getDataOldValue();
    int partitionId = queryCacheContext.getPartitionId(entryEvenData.dataKey);
    for (PartitionAccumulatorRegistry registry : partitionAccumulatorRegistries) {
        DefaultQueryCacheEventData singleEventData = (DefaultQueryCacheEventData) convertQueryCacheEventDataOrNull(registry, dataKey, dataNewValue, dataOldValue, eventType, partitionId, mapName);
        if (singleEventData == null) {
            continue;
        }
        Accumulator accumulator = registry.getOrCreate(partitionId);
        accumulator.accumulate(singleEventData);
    }
}
Also used : Accumulator(com.hazelcast.map.impl.querycache.accumulator.Accumulator) PartitionAccumulatorRegistry(com.hazelcast.map.impl.querycache.publisher.PartitionAccumulatorRegistry) DefaultQueryCacheEventData(com.hazelcast.map.impl.querycache.event.DefaultQueryCacheEventData) Data(com.hazelcast.internal.serialization.Data) DefaultQueryCacheEventData(com.hazelcast.map.impl.querycache.event.DefaultQueryCacheEventData) QueryCacheEventData(com.hazelcast.map.impl.querycache.event.QueryCacheEventData) DefaultQueryCacheEventData(com.hazelcast.map.impl.querycache.event.DefaultQueryCacheEventData) QueryCacheEventData(com.hazelcast.map.impl.querycache.event.QueryCacheEventData)

Aggregations

Accumulator (com.hazelcast.map.impl.querycache.accumulator.Accumulator)13 QueryCacheContext (com.hazelcast.map.impl.querycache.QueryCacheContext)7 QueryCacheEventData (com.hazelcast.map.impl.querycache.event.QueryCacheEventData)4 Sequenced (com.hazelcast.map.impl.querycache.event.sequence.Sequenced)3 DefaultQueryCacheEventData (com.hazelcast.map.impl.querycache.event.DefaultQueryCacheEventData)2 PartitionAccumulatorRegistry (com.hazelcast.map.impl.querycache.publisher.PartitionAccumulatorRegistry)2 Node (com.hazelcast.instance.impl.Node)1 Data (com.hazelcast.internal.serialization.Data)1 MapService (com.hazelcast.map.impl.MapService)1 MapServiceContext (com.hazelcast.map.impl.MapServiceContext)1 QueryCacheEventService (com.hazelcast.map.impl.querycache.QueryCacheEventService)1 AccumulatorInfo (com.hazelcast.map.impl.querycache.accumulator.AccumulatorInfo)1 EventPublisherAccumulatorProcessor (com.hazelcast.map.impl.querycache.publisher.EventPublisherAccumulatorProcessor)1 PublisherAccumulatorHandler (com.hazelcast.map.impl.querycache.publisher.PublisherAccumulatorHandler)1 InternalQueryCache (com.hazelcast.map.impl.querycache.subscriber.InternalQueryCache)1 QueryCacheFactory (com.hazelcast.map.impl.querycache.subscriber.QueryCacheFactory)1 SubscriberRegistry (com.hazelcast.map.impl.querycache.subscriber.SubscriberRegistry)1 Accessors.getNode (com.hazelcast.test.Accessors.getNode)1 ParallelJVMTest (com.hazelcast.test.annotation.ParallelJVMTest)1 QuickTest (com.hazelcast.test.annotation.QuickTest)1