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;
}
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());
}
}
}
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()));
}
}
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);
}
}
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;
}
Aggregations