Search in sources :

Example 26 with RecordStore

use of com.hazelcast.map.impl.recordstore.RecordStore in project hazelcast by hazelcast.

the class ClearExpiredOperation method run.

@Override
public void run() throws Exception {
    final MapService mapService = getService();
    MapServiceContext mapServiceContext = mapService.getMapServiceContext();
    final PartitionContainer partitionContainer = mapServiceContext.getPartitionContainer(getPartitionId());
    final ConcurrentMap<String, RecordStore> recordStores = partitionContainer.getMaps();
    final boolean backup = !isOwner();
    for (final RecordStore recordStore : recordStores.values()) {
        if (recordStore.size() > 0 && recordStore.isExpirable()) {
            recordStore.evictExpiredEntries(expirationPercentage, backup);
            recordStore.disposeDeferredBlocks();
        }
    }
}
Also used : PartitionContainer(com.hazelcast.map.impl.PartitionContainer) RecordStore(com.hazelcast.map.impl.recordstore.RecordStore) MapService(com.hazelcast.map.impl.MapService) MapServiceContext(com.hazelcast.map.impl.MapServiceContext)

Example 27 with RecordStore

use of com.hazelcast.map.impl.recordstore.RecordStore 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 28 with RecordStore

use of com.hazelcast.map.impl.recordstore.RecordStore in project hazelcast by hazelcast.

the class MapNearCacheStateHolder method prepare.

void prepare(PartitionContainer container, int replicaIndex) {
    MapService mapService = container.getMapService();
    MetaDataGenerator metaData = getPartitionMetaDataGenerator(mapService);
    int partitionId = container.getPartitionId();
    partitionUuid = metaData.getUuidOrNull(partitionId);
    ConcurrentMap<String, RecordStore> maps = container.getMaps();
    for (Map.Entry<String, RecordStore> entry : maps.entrySet()) {
        if (mapNameSequencePairs == emptyList()) {
            mapNameSequencePairs = new ArrayList(container.getMaps().size());
        }
        String mapName = entry.getKey();
        mapNameSequencePairs.add(mapName);
        mapNameSequencePairs.add(metaData.currentSequence(mapName, partitionId));
    }
}
Also used : RecordStore(com.hazelcast.map.impl.recordstore.RecordStore) ArrayList(java.util.ArrayList) MapService(com.hazelcast.map.impl.MapService) MetaDataGenerator(com.hazelcast.internal.nearcache.impl.invalidation.MetaDataGenerator) ConcurrentMap(java.util.concurrent.ConcurrentMap) Map(java.util.Map)

Example 29 with RecordStore

use of com.hazelcast.map.impl.recordstore.RecordStore in project hazelcast by hazelcast.

the class MapReplicationStateHolder method applyState.

void applyState() {
    if (data != null) {
        for (Map.Entry<String, Set<RecordReplicationInfo>> dataEntry : data.entrySet()) {
            Set<RecordReplicationInfo> recordReplicationInfos = dataEntry.getValue();
            final String mapName = dataEntry.getKey();
            RecordStore recordStore = mapReplicationOperation.getRecordStore(mapName);
            recordStore.reset();
            recordStore.setPreMigrationLoadedStatus(loaded.get(mapName));
            for (RecordReplicationInfo recordReplicationInfo : recordReplicationInfos) {
                Data key = recordReplicationInfo.getKey();
                final Data value = recordReplicationInfo.getValue();
                Record newRecord = recordStore.createRecord(value, -1L, Clock.currentTimeMillis());
                applyRecordInfo(newRecord, recordReplicationInfo);
                recordStore.putRecord(key, newRecord);
            }
        }
    }
}
Also used : Set(java.util.Set) HashSet(java.util.HashSet) RecordReplicationInfo(com.hazelcast.map.impl.record.RecordReplicationInfo) RecordStore(com.hazelcast.map.impl.recordstore.RecordStore) Data(com.hazelcast.nio.serialization.Data) Record(com.hazelcast.map.impl.record.Record) HashMap(java.util.HashMap) Map(java.util.Map)

Example 30 with RecordStore

use of com.hazelcast.map.impl.recordstore.RecordStore in project hazelcast by hazelcast.

the class MapReplicationStateHolder method prepare.

void prepare(PartitionContainer container, int replicaIndex) {
    data = new HashMap<String, Set<RecordReplicationInfo>>(container.getMaps().size());
    loaded = new HashMap<String, Boolean>(container.getMaps().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) {
            continue;
        }
        MapServiceContext mapServiceContext = mapContainer.getMapServiceContext();
        String mapName = entry.getKey();
        loaded.put(mapName, recordStore.isLoaded());
        // now prepare data to migrate records
        Set<RecordReplicationInfo> recordSet = new HashSet<RecordReplicationInfo>(recordStore.size());
        final Iterator<Record> iterator = recordStore.iterator();
        while (iterator.hasNext()) {
            Record record = iterator.next();
            Data key = record.getKey();
            RecordReplicationInfo recordReplicationInfo = mapReplicationOperation.createRecordReplicationInfo(key, record, mapServiceContext);
            recordSet.add(recordReplicationInfo);
        }
        data.put(mapName, recordSet);
    }
}
Also used : Set(java.util.Set) HashSet(java.util.HashSet) Data(com.hazelcast.nio.serialization.Data) MapContainer(com.hazelcast.map.impl.MapContainer) MapServiceContext(com.hazelcast.map.impl.MapServiceContext) RecordReplicationInfo(com.hazelcast.map.impl.record.RecordReplicationInfo) RecordStore(com.hazelcast.map.impl.recordstore.RecordStore) Record(com.hazelcast.map.impl.record.Record) MapConfig(com.hazelcast.config.MapConfig) HashMap(java.util.HashMap) Map(java.util.Map) HashSet(java.util.HashSet)

Aggregations

RecordStore (com.hazelcast.map.impl.recordstore.RecordStore)31 MapServiceContext (com.hazelcast.map.impl.MapServiceContext)12 MapService (com.hazelcast.map.impl.MapService)8 Data (com.hazelcast.nio.serialization.Data)7 Map (java.util.Map)7 PartitionContainer (com.hazelcast.map.impl.PartitionContainer)6 HashMap (java.util.HashMap)6 IPartitionService (com.hazelcast.spi.partition.IPartitionService)5 ArrayList (java.util.ArrayList)5 HazelcastInstance (com.hazelcast.core.HazelcastInstance)4 SimpleEntryView (com.hazelcast.map.impl.SimpleEntryView)4 DelayedEntry (com.hazelcast.map.impl.mapstore.writebehind.entry.DelayedEntry)4 Record (com.hazelcast.map.impl.record.Record)4 DefaultRecordStore (com.hazelcast.map.impl.recordstore.DefaultRecordStore)4 MapMergePolicy (com.hazelcast.map.merge.MapMergePolicy)4 PutIfAbsentMapMergePolicy (com.hazelcast.map.merge.PutIfAbsentMapMergePolicy)4 NodeEngine (com.hazelcast.spi.NodeEngine)4 NodeEngineImpl (com.hazelcast.spi.impl.NodeEngineImpl)4 ParallelTest (com.hazelcast.test.annotation.ParallelTest)4 QuickTest (com.hazelcast.test.annotation.QuickTest)4