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