Search in sources :

Example 21 with DelayedEntry

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

the class StoreWorker method hasEntryInWriteBehindQueue.

private boolean hasEntryInWriteBehindQueue(RecordStore recordStore) {
    if (recordStore == null) {
        return false;
    }
    MapDataStore mapDataStore = recordStore.getMapDataStore();
    WriteBehindStore dataStore = (WriteBehindStore) mapDataStore;
    WriteBehindQueue<DelayedEntry> writeBehindQueue = dataStore.getWriteBehindQueue();
    return writeBehindQueue.size() != 0;
}
Also used : MapDataStore(com.hazelcast.map.impl.mapstore.MapDataStore) DelayedEntry(com.hazelcast.map.impl.mapstore.writebehind.entry.DelayedEntry)

Example 22 with DelayedEntry

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

the class StoreWorker method runInternal.

private void runInternal() {
    final long now = Clock.currentTimeMillis();
    // if this node is the owner of a partition, we use this criteria time.
    final long ownerHighestStoreTime = calculateHighestStoreTime(lastHighestStoreTime, now);
    // if this node is the backup of a partition, we use this criteria time because backups are processed after delay.
    final long backupHighestStoreTime = ownerHighestStoreTime - backupDelayMillis;
    lastHighestStoreTime = ownerHighestStoreTime;
    List<DelayedEntry> ownersList = null;
    List<DelayedEntry> backupsList = null;
    for (int partitionId = 0; partitionId < partitionCount; partitionId++) {
        if (currentThread().isInterrupted()) {
            break;
        }
        RecordStore recordStore = getRecordStoreOrNull(mapName, partitionId);
        if (!hasEntryInWriteBehindQueue(recordStore)) {
            continue;
        }
        boolean localPartition = isPartitionLocal(partitionId);
        if (!localPartition) {
            backupsList = initListIfNull(backupsList, partitionCount);
            selectEntriesToStore(recordStore, backupsList, backupHighestStoreTime);
        } else {
            ownersList = initListIfNull(ownersList, partitionCount);
            selectEntriesToStore(recordStore, ownersList, ownerHighestStoreTime);
        }
    }
    if (!isEmpty(ownersList)) {
        Map<Integer, List<DelayedEntry>> failuresPerPartition = writeBehindProcessor.process(ownersList);
        removeFinishedStoreOperationsFromQueues(mapName, ownersList);
        reAddFailedStoreOperationsToQueues(mapName, failuresPerPartition);
    }
    if (!isEmpty(backupsList)) {
        doInBackup(backupsList);
    }
    notifyFlush();
}
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)

Example 23 with DelayedEntry

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

the class WriteBehindManager method newWriteBehindProcessor.

private WriteBehindProcessor newWriteBehindProcessor(final MapStoreContext mapStoreContext) {
    WriteBehindProcessor writeBehindProcessor = createWriteBehindProcessor(mapStoreContext);
    StoreListener<DelayedEntry> storeListener = new InternalStoreListener(mapStoreContext);
    writeBehindProcessor.addStoreListener(storeListener);
    return writeBehindProcessor;
}
Also used : WriteBehindProcessors.createWriteBehindProcessor(com.hazelcast.map.impl.mapstore.writebehind.WriteBehindProcessors.createWriteBehindProcessor) DelayedEntry(com.hazelcast.map.impl.mapstore.writebehind.entry.DelayedEntry)

Example 24 with DelayedEntry

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

the class WriteBehindStore method notifyFlush.

public void notifyFlush() {
    long nextSequenceNumber = sequence.get() + 1;
    DelayedEntry firstEntry = writeBehindQueue.peek();
    if (firstEntry == null) {
        if (!flushSequences.isEmpty()) {
            findAwaitingFlushesAndSendNotification(nextSequenceNumber);
        }
    } else {
        findAwaitingFlushesAndSendNotification(firstEntry.getSequence());
    }
}
Also used : DelayedEntry(com.hazelcast.map.impl.mapstore.writebehind.entry.DelayedEntry)

Example 25 with DelayedEntry

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

the class CoalescedWriteBehindQueue method calculateStoreTime.

/**
     * If this is an existing key in this queue, use previously set store time;
     * since we do not want to shift store time of an existing key on every update.
     */
private void calculateStoreTime(DelayedEntry delayedEntry) {
    Data key = (Data) delayedEntry.getKey();
    DelayedEntry currentEntry = map.get(key);
    if (currentEntry != null) {
        long currentStoreTime = currentEntry.getStoreTime();
        delayedEntry.setStoreTime(currentStoreTime);
    }
}
Also used : Data(com.hazelcast.nio.serialization.Data) DelayedEntry(com.hazelcast.map.impl.mapstore.writebehind.entry.DelayedEntry)

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