Search in sources :

Example 1 with WriteBehindStore

use of com.hazelcast.map.impl.mapstore.writebehind.WriteBehindStore in project hazelcast by hazelcast.

the class MapDataStores method createWriteBehindStore.

/**
     * Creates a write behind data store.
     *
     * @param mapStoreContext      context for map store operations.
     * @param partitionId          partition id of partition.
     * @param writeBehindProcessor the {@link WriteBehindProcessor}
     * @param <K>                  type of key to store.
     * @param <V>                  type of value to store.
     * @return new write behind store manager.
     */
public static <K, V> MapDataStore<K, V> createWriteBehindStore(MapStoreContext mapStoreContext, int partitionId, WriteBehindProcessor writeBehindProcessor) {
    MapServiceContext mapServiceContext = mapStoreContext.getMapServiceContext();
    MapStoreConfig mapStoreConfig = mapStoreContext.getMapStoreConfig();
    WriteBehindStore mapDataStore = new WriteBehindStore(mapStoreContext, partitionId);
    mapDataStore.setWriteBehindQueue(newWriteBehindQueue(mapServiceContext, mapStoreConfig.isWriteCoalescing()));
    mapDataStore.setWriteBehindProcessor(writeBehindProcessor);
    return (MapDataStore<K, V>) mapDataStore;
}
Also used : MapStoreConfig(com.hazelcast.config.MapStoreConfig) MapServiceContext(com.hazelcast.map.impl.MapServiceContext) WriteBehindStore(com.hazelcast.map.impl.mapstore.writebehind.WriteBehindStore)

Example 2 with WriteBehindStore

use of com.hazelcast.map.impl.mapstore.writebehind.WriteBehindStore in project hazelcast by hazelcast.

the class WriteBehindStateHolder method applyState.

void applyState() {
    for (Map.Entry<String, List<DelayedEntry>> entry : delayedEntries.entrySet()) {
        String mapName = entry.getKey();
        RecordStore recordStore = mapReplicationOperation.getRecordStore(mapName);
        WriteBehindStore mapDataStore = (WriteBehindStore) recordStore.getMapDataStore();
        mapDataStore.reset();
        mapDataStore.setFlushSequences(flushSequences.get(mapName));
        Collection<DelayedEntry> replicatedEntries = entry.getValue();
        for (DelayedEntry delayedEntry : replicatedEntries) {
            mapDataStore.add(delayedEntry);
            mapDataStore.setSequence(delayedEntry.getSequence());
        }
    }
}
Also used : RecordStore(com.hazelcast.map.impl.recordstore.RecordStore) ArrayList(java.util.ArrayList) List(java.util.List) DelayedEntry(com.hazelcast.map.impl.mapstore.writebehind.entry.DelayedEntry) HashMap(java.util.HashMap) Map(java.util.Map) WriteBehindStore(com.hazelcast.map.impl.mapstore.writebehind.WriteBehindStore)

Example 3 with WriteBehindStore

use of com.hazelcast.map.impl.mapstore.writebehind.WriteBehindStore in project hazelcast by hazelcast.

the class WriteBehindStateHolder method prepare.

void prepare(PartitionContainer container, int replicaIndex) {
    int size = container.getMaps().size();
    flushSequences = new HashMap<String, Queue<WriteBehindStore.Sequence>>(size);
    delayedEntries = new HashMap<String, List<DelayedEntry>>(size);
    for (Map.Entry<String, RecordStore> entry : container.getMaps().entrySet()) {
        RecordStore recordStore = entry.getValue();
        MapContainer mapContainer = recordStore.getMapContainer();
        MapConfig mapConfig = mapContainer.getMapConfig();
        if (mapConfig.getTotalBackupCount() < replicaIndex || !mapContainer.getMapStoreContext().isWriteBehindMapStoreEnabled()) {
            continue;
        }
        WriteBehindStore mapDataStore = (WriteBehindStore) recordStore.getMapDataStore();
        WriteBehindQueue<DelayedEntry> writeBehindQueue = mapDataStore.getWriteBehindQueue();
        List<DelayedEntry> entries = writeBehindQueue.asList();
        if (entries == null || entries.isEmpty()) {
            continue;
        }
        String mapName = entry.getKey();
        delayedEntries.put(mapName, entries);
        flushSequences.put(mapName, new ArrayDeque<WriteBehindStore.Sequence>(mapDataStore.getFlushSequences()));
    }
}
Also used : DelayedEntry(com.hazelcast.map.impl.mapstore.writebehind.entry.DelayedEntry) WriteBehindStore(com.hazelcast.map.impl.mapstore.writebehind.WriteBehindStore) MapContainer(com.hazelcast.map.impl.MapContainer) RecordStore(com.hazelcast.map.impl.recordstore.RecordStore) ArrayList(java.util.ArrayList) List(java.util.List) MapConfig(com.hazelcast.config.MapConfig) WriteBehindQueue(com.hazelcast.map.impl.mapstore.writebehind.WriteBehindQueue) Queue(java.util.Queue) HashMap(java.util.HashMap) Map(java.util.Map)

Example 4 with WriteBehindStore

use of com.hazelcast.map.impl.mapstore.writebehind.WriteBehindStore in project hazelcast by hazelcast.

the class DefaultRecordStore method updateStoreStats.

private void updateStoreStats() {
    if (!(mapDataStore instanceof WriteBehindStore) || !mapContainer.getMapConfig().isStatisticsEnabled()) {
        return;
    }
    long now = Clock.currentTimeMillis();
    WriteBehindQueue<DelayedEntry> writeBehindQueue = ((WriteBehindStore) mapDataStore).getWriteBehindQueue();
    List<DelayedEntry> delayedEntries = writeBehindQueue.asList();
    for (DelayedEntry delayedEntry : delayedEntries) {
        Record record = getRecordOrNull(toData(delayedEntry.getKey()), now, false);
        onStore(record);
    }
}
Also used : Record(com.hazelcast.map.impl.record.Record) DelayedEntry(com.hazelcast.map.impl.mapstore.writebehind.entry.DelayedEntry) WriteBehindStore(com.hazelcast.map.impl.mapstore.writebehind.WriteBehindStore)

Example 5 with WriteBehindStore

use of com.hazelcast.map.impl.mapstore.writebehind.WriteBehindStore in project hazelcast by hazelcast.

the class MapStoreWriteBehindTest method writeBehindQueueSize.

private int writeBehindQueueSize(HazelcastInstance node, String mapName) {
    int size = 0;
    final NodeEngineImpl nodeEngine = getNode(node).getNodeEngine();
    MapService mapService = nodeEngine.getService(MapService.SERVICE_NAME);
    final MapServiceContext mapServiceContext = mapService.getMapServiceContext();
    final int partitionCount = nodeEngine.getPartitionService().getPartitionCount();
    for (int i = 0; i < partitionCount; i++) {
        final RecordStore recordStore = mapServiceContext.getExistingRecordStore(i, mapName);
        if (recordStore == null) {
            continue;
        }
        final MapDataStore mapDataStore = recordStore.getMapDataStore();
        size += ((WriteBehindStore) mapDataStore).getWriteBehindQueue().size();
    }
    return size;
}
Also used : NodeEngineImpl(com.hazelcast.spi.impl.NodeEngineImpl) RecordStore(com.hazelcast.map.impl.recordstore.RecordStore) MapService(com.hazelcast.map.impl.MapService) MapServiceContext(com.hazelcast.map.impl.MapServiceContext) WriteBehindStore(com.hazelcast.map.impl.mapstore.writebehind.WriteBehindStore)

Aggregations

WriteBehindStore (com.hazelcast.map.impl.mapstore.writebehind.WriteBehindStore)6 DelayedEntry (com.hazelcast.map.impl.mapstore.writebehind.entry.DelayedEntry)3 RecordStore (com.hazelcast.map.impl.recordstore.RecordStore)3 MapServiceContext (com.hazelcast.map.impl.MapServiceContext)2 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 List (java.util.List)2 Map (java.util.Map)2 MapConfig (com.hazelcast.config.MapConfig)1 MapStoreConfig (com.hazelcast.config.MapStoreConfig)1 MapContainer (com.hazelcast.map.impl.MapContainer)1 MapService (com.hazelcast.map.impl.MapService)1 MapDataStore (com.hazelcast.map.impl.mapstore.MapDataStore)1 WriteBehindQueue (com.hazelcast.map.impl.mapstore.writebehind.WriteBehindQueue)1 Record (com.hazelcast.map.impl.record.Record)1 NodeEngineImpl (com.hazelcast.spi.impl.NodeEngineImpl)1 Queue (java.util.Queue)1