Search in sources :

Example 6 with DelayedEntry

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

the class DefaultWriteBehindProcessor method callHandler.

/**
     * Decides how entries should be passed to handlers.
     * It passes entries to handler's single or batch handling
     * methods.
     *
     * @param delayedEntries sorted entries to be processed.
     * @return failed entry list if any.
     */
private List<DelayedEntry> callHandler(Collection<DelayedEntry> delayedEntries, StoreOperationType operationType) {
    final int size = delayedEntries.size();
    if (size == 0) {
        return Collections.emptyList();
    }
    // when writeCoalescing is false.
    if (size == 1 || !writeCoalescing) {
        return processEntriesOneByOne(delayedEntries, operationType);
    }
    final DelayedEntry[] delayedEntriesArray = delayedEntries.toArray(new DelayedEntry[delayedEntries.size()]);
    final Map<Object, DelayedEntry> batchMap = prepareBatchMap(delayedEntriesArray);
    // if all batch is on same key, call single store.
    if (batchMap.size() == 1) {
        final DelayedEntry delayedEntry = delayedEntriesArray[delayedEntriesArray.length - 1];
        return callSingleStoreWithListeners(delayedEntry, operationType);
    }
    final List<DelayedEntry> failedEntryList = callBatchStoreWithListeners(batchMap, operationType);
    final List<DelayedEntry> failedTries = new ArrayList<DelayedEntry>();
    for (DelayedEntry entry : failedEntryList) {
        final Collection<DelayedEntry> tmpFails = callSingleStoreWithListeners(entry, operationType);
        failedTries.addAll(tmpFails);
    }
    return failedTries;
}
Also used : ArrayList(java.util.ArrayList) DelayedEntry(com.hazelcast.map.impl.mapstore.writebehind.entry.DelayedEntry)

Example 7 with DelayedEntry

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

the class StoreWorker method reAddFailedStoreOperationsToQueues.

private void reAddFailedStoreOperationsToQueues(String mapName, Map<Integer, List<DelayedEntry>> failuresPerPartition) {
    if (failuresPerPartition.isEmpty()) {
        return;
    }
    for (Map.Entry<Integer, List<DelayedEntry>> entry : failuresPerPartition.entrySet()) {
        Integer partitionId = entry.getKey();
        List<DelayedEntry> failures = failuresPerPartition.get(partitionId);
        if (isEmpty(failures)) {
            continue;
        }
        RecordStore recordStore = getRecordStoreOrNull(mapName, partitionId);
        if (recordStore == null) {
            continue;
        }
        final WriteBehindQueue<DelayedEntry> queue = getWriteBehindQueue(recordStore);
        queue.addFirst(failures);
    }
}
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) Map(java.util.Map)

Example 8 with DelayedEntry

use of com.hazelcast.map.impl.mapstore.writebehind.entry.DelayedEntry 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 9 with DelayedEntry

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

the class WriteBehindStateHolder method readData.

@Override
public void readData(ObjectDataInput in) throws IOException {
    int size = in.readInt();
    delayedEntries = new HashMap<String, List<DelayedEntry>>(size);
    for (int i = 0; i < size; i++) {
        String mapName = in.readUTF();
        int listSize = in.readInt();
        List<DelayedEntry> delayedEntriesList = new ArrayList<DelayedEntry>(listSize);
        for (int j = 0; j < listSize; j++) {
            Data key = in.readData();
            Data value = in.readData();
            long storeTime = in.readLong();
            int partitionId = in.readInt();
            long sequence = in.readLong();
            DelayedEntry<Data, Data> entry = DelayedEntries.createDefault(key, value, storeTime, partitionId);
            entry.setSequence(sequence);
            delayedEntriesList.add(entry);
        }
        delayedEntries.put(mapName, delayedEntriesList);
    }
    int expectedSize = in.readInt();
    flushSequences = new HashMap<String, Queue<WriteBehindStore.Sequence>>(expectedSize);
    for (int i = 0; i < expectedSize; i++) {
        String mapName = in.readUTF();
        int setSize = in.readInt();
        Queue<WriteBehindStore.Sequence> queue = new ArrayDeque<WriteBehindStore.Sequence>(setSize);
        for (int j = 0; j < setSize; j++) {
            queue.add(new WriteBehindStore.Sequence(in.readLong(), in.readBoolean()));
        }
        flushSequences.put(mapName, queue);
    }
}
Also used : ArrayList(java.util.ArrayList) Data(com.hazelcast.nio.serialization.Data) DelayedEntry(com.hazelcast.map.impl.mapstore.writebehind.entry.DelayedEntry) WriteBehindStore(com.hazelcast.map.impl.mapstore.writebehind.WriteBehindStore) ArrayDeque(java.util.ArrayDeque) ArrayList(java.util.ArrayList) List(java.util.List) WriteBehindQueue(com.hazelcast.map.impl.mapstore.writebehind.WriteBehindQueue) Queue(java.util.Queue)

Example 10 with DelayedEntry

use of com.hazelcast.map.impl.mapstore.writebehind.entry.DelayedEntry 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)

Aggregations

DelayedEntry (com.hazelcast.map.impl.mapstore.writebehind.entry.DelayedEntry)28 ArrayList (java.util.ArrayList)9 Data (com.hazelcast.nio.serialization.Data)7 HashMap (java.util.HashMap)6 List (java.util.List)6 WriteBehindStore (com.hazelcast.map.impl.mapstore.writebehind.WriteBehindStore)5 Map (java.util.Map)5 RecordStore (com.hazelcast.map.impl.recordstore.RecordStore)4 WriteBehindQueue (com.hazelcast.map.impl.mapstore.writebehind.WriteBehindQueue)3 ParallelTest (com.hazelcast.test.annotation.ParallelTest)3 QuickTest (com.hazelcast.test.annotation.QuickTest)3 Queue (java.util.Queue)3 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)3 Test (org.junit.Test)3 MapConfig (com.hazelcast.config.MapConfig)1 DefaultSerializationServiceBuilder (com.hazelcast.internal.serialization.impl.DefaultSerializationServiceBuilder)1 MapContainer (com.hazelcast.map.impl.MapContainer)1 MapService (com.hazelcast.map.impl.MapService)1 MapServiceContext (com.hazelcast.map.impl.MapServiceContext)1 MapDataStore (com.hazelcast.map.impl.mapstore.MapDataStore)1