Search in sources :

Example 46 with RecordStore

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

the class MapClearExpiredRecordsTask method notHaveAnyExpirableRecord.

/**
 * Here we check if that partition has any expirable record or not,
 * if no expirable record exists in that partition no need to fire
 * an expiration operation.
 *
 * @param partitionContainer corresponding partition container.
 * @return <code>true</code> if no expirable record in that
 * partition <code>false</code> otherwise.
 */
@Override
protected boolean notHaveAnyExpirableRecord(PartitionContainer partitionContainer) {
    boolean notExist = true;
    final ConcurrentMap<String, RecordStore> maps = partitionContainer.getMaps();
    for (RecordStore store : maps.values()) {
        if (store.isExpirable()) {
            notExist = false;
            break;
        }
    }
    return notExist;
}
Also used : RecordStore(com.hazelcast.map.impl.recordstore.RecordStore)

Example 47 with RecordStore

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

the class MapReplicationStateHolder method applyState.

@SuppressWarnings({ "checkstyle:npathcomplexity", "checkstyle:methodlength", "checkstyle:cyclomaticcomplexity", "checkstyle:nestedifdepth" })
void applyState() {
    ThreadUtil.assertRunningOnPartitionThread();
    applyIndexesState();
    if (!isNullOrEmpty(data)) {
        for (Map.Entry<String, List> dataEntry : data.entrySet()) {
            String mapName = dataEntry.getKey();
            List keyRecordExpiry = dataEntry.getValue();
            RecordStore recordStore = operation.getRecordStore(mapName);
            recordStore.beforeOperation();
            try {
                initializeRecordStore(mapName, recordStore);
                recordStore.setPreMigrationLoadedStatus(loaded.get(mapName));
                MapContainer mapContainer = recordStore.getMapContainer();
                PartitionContainer partitionContainer = recordStore.getMapContainer().getMapServiceContext().getPartitionContainer(operation.getPartitionId());
                for (Map.Entry<String, IndexConfig> indexDefinition : mapContainer.getIndexDefinitions().entrySet()) {
                    Indexes indexes = mapContainer.getIndexes(partitionContainer.getPartitionId());
                    indexes.addOrGetIndex(indexDefinition.getValue());
                }
                final Indexes indexes = mapContainer.getIndexes(partitionContainer.getPartitionId());
                final boolean populateIndexes = indexesMustBePopulated(indexes, operation);
                InternalIndex[] indexesSnapshot = null;
                if (populateIndexes) {
                    // defensively clear possible stale leftovers in non-global indexes from
                    // the previous failed promotion attempt
                    indexesSnapshot = indexes.getIndexes();
                    Indexes.beginPartitionUpdate(indexesSnapshot);
                    indexes.clearAll();
                }
                long nowInMillis = Clock.currentTimeMillis();
                forEachReplicatedRecord(keyRecordExpiry, mapContainer, recordStore, populateIndexes, nowInMillis);
                if (populateIndexes) {
                    Indexes.markPartitionAsIndexed(partitionContainer.getPartitionId(), indexesSnapshot);
                }
            } finally {
                recordStore.afterOperation();
            }
        }
    }
    for (Map.Entry<String, LocalRecordStoreStats> statsEntry : recordStoreStatsPerMapName.entrySet()) {
        String mapName = statsEntry.getKey();
        LocalRecordStoreStats stats = statsEntry.getValue();
        RecordStore recordStore = operation.getRecordStore(mapName);
        recordStore.setStats(stats);
    }
}
Also used : PartitionContainer(com.hazelcast.map.impl.PartitionContainer) Indexes(com.hazelcast.query.impl.Indexes) MapContainer(com.hazelcast.map.impl.MapContainer) LocalRecordStoreStats(com.hazelcast.internal.monitor.LocalRecordStoreStats) InternalIndex(com.hazelcast.query.impl.InternalIndex) IndexConfig(com.hazelcast.config.IndexConfig) RecordStore(com.hazelcast.map.impl.recordstore.RecordStore) ArrayList(java.util.ArrayList) List(java.util.List) HashMap(java.util.HashMap) MapUtil.createHashMap(com.hazelcast.internal.util.MapUtil.createHashMap) Map(java.util.Map) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap)

Example 48 with RecordStore

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

the class MapReplicationStateHolder method entryCountOnThisNode.

// owned or backup
private long entryCountOnThisNode(MapContainer mapContainer) {
    int replicaIndex = operation.getReplicaIndex();
    long owned = 0;
    if (mapContainer.getEvictor() != Evictor.NULL_EVICTOR && PER_NODE == mapContainer.getMapConfig().getEvictionConfig().getMaxSizePolicy()) {
        MapService mapService = operation.getService();
        MapServiceContext mapServiceContext = mapService.getMapServiceContext();
        IPartitionService partitionService = mapServiceContext.getNodeEngine().getPartitionService();
        int partitionCount = partitionService.getPartitionCount();
        for (int partitionId = 0; partitionId < partitionCount; partitionId++) {
            if (replicaIndex == 0 ? partitionService.isPartitionOwner(partitionId) : !partitionService.isPartitionOwner(partitionId)) {
                RecordStore store = mapServiceContext.getExistingRecordStore(partitionId, mapContainer.getName());
                if (store != null) {
                    owned += store.size();
                }
            }
        }
    }
    return owned;
}
Also used : IPartitionService(com.hazelcast.internal.partition.IPartitionService) RecordStore(com.hazelcast.map.impl.recordstore.RecordStore) MapService(com.hazelcast.map.impl.MapService) MapServiceContext(com.hazelcast.map.impl.MapServiceContext)

Example 49 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 50 with RecordStore

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

the class MapChunk method run.

@Override
public final void run() throws Exception {
    RecordStore recordStore = getRecordStore(mapName);
    if (firstChunk) {
        addIndexes(recordStore, mapIndexInfo.getIndexConfigs());
        initializeRecordStore(mapName, recordStore);
        recordStore.setStats(stats);
        recordStore.setPreMigrationLoadedStatus(loaded);
        applyWriteBehindState(recordStore);
        applyNearCacheState(recordStore);
        applyIndexStateBefore(recordStore);
    }
    if (isNotEmpty(keyRecordExpiry)) {
        putInto(recordStore);
        logProgress(recordStore);
    }
    if (lastChunk) {
        applyIndexStateAfter(recordStore);
    }
}
Also used : RecordStore(com.hazelcast.map.impl.recordstore.RecordStore)

Aggregations

RecordStore (com.hazelcast.map.impl.recordstore.RecordStore)66 MapServiceContext (com.hazelcast.map.impl.MapServiceContext)21 MapService (com.hazelcast.map.impl.MapService)20 PartitionContainer (com.hazelcast.map.impl.PartitionContainer)12 HazelcastInstance (com.hazelcast.core.HazelcastInstance)10 NodeEngineImpl (com.hazelcast.spi.impl.NodeEngineImpl)10 Data (com.hazelcast.internal.serialization.Data)9 MapContainer (com.hazelcast.map.impl.MapContainer)8 DefaultRecordStore (com.hazelcast.map.impl.recordstore.DefaultRecordStore)8 Indexes (com.hazelcast.query.impl.Indexes)8 Map (java.util.Map)8 NodeEngine (com.hazelcast.spi.impl.NodeEngine)7 QuickTest (com.hazelcast.test.annotation.QuickTest)7 HashMap (java.util.HashMap)7 Test (org.junit.Test)7 MapConfig (com.hazelcast.config.MapConfig)6 IPartitionService (com.hazelcast.internal.partition.IPartitionService)6 Record (com.hazelcast.map.impl.record.Record)6 ParallelJVMTest (com.hazelcast.test.annotation.ParallelJVMTest)6 ArrayList (java.util.ArrayList)6