Search in sources :

Example 21 with RecordStore

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

the class MapMigrationAwareService method commitMigration.

@Override
public void commitMigration(PartitionMigrationEvent event) {
    migrateIndex(event);
    if (SOURCE == event.getMigrationEndpoint()) {
        clearMapsHavingLesserBackupCountThan(event.getPartitionId(), event.getNewReplicaIndex());
        getMetaDataGenerator().removeUuidAndSequence(event.getPartitionId());
    } else if (DESTINATION == event.getMigrationEndpoint()) {
        if (event.getNewReplicaIndex() != 0) {
            getMetaDataGenerator().regenerateUuid(event.getPartitionId());
        }
    }
    PartitionContainer partitionContainer = mapServiceContext.getPartitionContainer(event.getPartitionId());
    for (RecordStore recordStore : partitionContainer.getAllRecordStores()) {
        // in case the record store has been created without loading during migration trigger again
        // if loading has been already started this call will do nothing
        recordStore.startLoading();
    }
    mapServiceContext.reloadOwnedPartitions();
    QueryCacheContext queryCacheContext = mapServiceContext.getQueryCacheContext();
    PublisherContext publisherContext = queryCacheContext.getPublisherContext();
    if (event.getMigrationEndpoint() == MigrationEndpoint.SOURCE) {
        int partitionId = event.getPartitionId();
        flushAccumulator(publisherContext, partitionId);
        removeAccumulator(publisherContext, partitionId);
    }
}
Also used : RecordStore(com.hazelcast.map.impl.recordstore.RecordStore) QueryCacheContext(com.hazelcast.map.impl.querycache.QueryCacheContext) PublisherContext(com.hazelcast.map.impl.querycache.publisher.PublisherContext) MigrationEndpoint(com.hazelcast.spi.partition.MigrationEndpoint)

Example 22 with RecordStore

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

the class MapMigrationAwareService method migrateIndex.

private void migrateIndex(PartitionMigrationEvent event) {
    final long now = getNow();
    final PartitionContainer container = mapServiceContext.getPartitionContainer(event.getPartitionId());
    for (RecordStore recordStore : container.getMaps().values()) {
        final MapContainer mapContainer = mapServiceContext.getMapContainer(recordStore.getName());
        final Indexes indexes = mapContainer.getIndexes();
        if (!indexes.hasIndex()) {
            continue;
        }
        final Iterator<Record> iterator = recordStore.iterator(now, false);
        while (iterator.hasNext()) {
            Record record = iterator.next();
            Data key = record.getKey();
            if (event.getMigrationEndpoint() == SOURCE) {
                assert event.getNewReplicaIndex() != 0 : "Invalid migration event: " + event;
                Object value = Records.getValueOrCachedValue(record, serializationService);
                indexes.removeEntryIndex(key, value);
            } else if (event.getNewReplicaIndex() == 0) {
                Object value = Records.getValueOrCachedValue(record, serializationService);
                if (value != null) {
                    QueryableEntry queryEntry = mapContainer.newQueryEntry(record.getKey(), value);
                    indexes.saveEntryIndex(queryEntry, null);
                }
            }
        }
    }
}
Also used : RecordStore(com.hazelcast.map.impl.recordstore.RecordStore) Record(com.hazelcast.map.impl.record.Record) Data(com.hazelcast.nio.serialization.Data) Indexes(com.hazelcast.query.impl.Indexes) QueryableEntry(com.hazelcast.query.impl.QueryableEntry)

Example 23 with RecordStore

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

the class LocalMapStatsProvider method createAllLocalMapStats.

public Map<String, LocalMapStats> createAllLocalMapStats() {
    Map statsPerMap = new HashMap();
    PartitionContainer[] partitionContainers = mapServiceContext.getPartitionContainers();
    for (PartitionContainer partitionContainer : partitionContainers) {
        IPartition partition = partitionService.getPartition(partitionContainer.getPartitionId());
        Collection<RecordStore> allRecordStores = partitionContainer.getAllRecordStores();
        for (RecordStore recordStore : allRecordStores) {
            if (!isStatsCalculationEnabledFor(recordStore)) {
                continue;
            }
            if (partition.isLocal()) {
                addPrimaryStatsOf(recordStore, getOrCreateOnDemandStats(statsPerMap, recordStore));
            } else {
                addReplicaStatsOf(recordStore, getOrCreateOnDemandStats(statsPerMap, recordStore));
            }
        }
    }
    // reuse same HashMap to return calculated LocalMapStats.
    for (Object object : statsPerMap.entrySet()) {
        Map.Entry entry = (Map.Entry) object;
        String mapName = ((String) entry.getKey());
        LocalMapStatsImpl existingStats = getLocalMapStatsImpl(mapName);
        LocalMapOnDemandCalculatedStats onDemand = ((LocalMapOnDemandCalculatedStats) entry.getValue());
        addNearCacheStats(mapName, existingStats, onDemand);
        LocalMapStatsImpl updatedStats = onDemand.updateAndGet(existingStats);
        entry.setValue(updatedStats);
    }
    addStatsOfNoDataIncludedMaps(statsPerMap);
    return statsPerMap;
}
Also used : LocalMapStatsImpl(com.hazelcast.monitor.impl.LocalMapStatsImpl) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) RecordStore(com.hazelcast.map.impl.recordstore.RecordStore) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) ConcurrentMap(java.util.concurrent.ConcurrentMap) Map(java.util.Map) IPartition(com.hazelcast.spi.partition.IPartition)

Example 24 with RecordStore

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

the class RecordStoreTest method getRecordStore.

private DefaultRecordStore getRecordStore(IMap<Object, Object> map, int key) {
    MapServiceContext mapServiceContext = getMapServiceContext((MapProxyImpl) map);
    NodeEngine nodeEngine = mapServiceContext.getNodeEngine();
    IPartitionService partitionService = nodeEngine.getPartitionService();
    int partitionId = partitionService.getPartitionId(key);
    PartitionContainer container = mapServiceContext.getPartitionContainer(partitionId);
    RecordStore recordStore = container.getRecordStore(map.getName());
    return (DefaultRecordStore) recordStore;
}
Also used : NodeEngine(com.hazelcast.spi.NodeEngine) IPartitionService(com.hazelcast.spi.partition.IPartitionService) RecordStore(com.hazelcast.map.impl.recordstore.RecordStore) DefaultRecordStore(com.hazelcast.map.impl.recordstore.DefaultRecordStore) DefaultRecordStore(com.hazelcast.map.impl.recordstore.DefaultRecordStore)

Example 25 with RecordStore

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

the class PartitionContainer method createRecordStore.

private RecordStore createRecordStore(String name) {
    MapServiceContext serviceContext = mapService.getMapServiceContext();
    MapContainer mapContainer = serviceContext.getMapContainer(name);
    MapConfig mapConfig = mapContainer.getMapConfig();
    NodeEngine nodeEngine = serviceContext.getNodeEngine();
    IPartitionService ps = nodeEngine.getPartitionService();
    OperationService opService = nodeEngine.getOperationService();
    ExecutionService execService = nodeEngine.getExecutionService();
    HazelcastProperties hazelcastProperties = nodeEngine.getProperties();
    MapKeyLoader keyLoader = new MapKeyLoader(name, opService, ps, nodeEngine.getClusterService(), execService, mapContainer.toData());
    keyLoader.setMaxBatch(hazelcastProperties.getInteger(GroupProperty.MAP_LOAD_CHUNK_SIZE));
    keyLoader.setMaxSize(getMaxSizePerNode(mapConfig.getMaxSizeConfig()));
    keyLoader.setHasBackup(mapConfig.getTotalBackupCount() > 0);
    keyLoader.setMapOperationProvider(serviceContext.getMapOperationProvider(name));
    RecordStore recordStore = serviceContext.createRecordStore(mapContainer, partitionId, keyLoader);
    recordStore.init();
    return recordStore;
}
Also used : NodeEngine(com.hazelcast.spi.NodeEngine) HazelcastProperties(com.hazelcast.spi.properties.HazelcastProperties) IPartitionService(com.hazelcast.spi.partition.IPartitionService) RecordStore(com.hazelcast.map.impl.recordstore.RecordStore) MapConfig(com.hazelcast.config.MapConfig) OperationService(com.hazelcast.spi.OperationService) ExecutionService(com.hazelcast.spi.ExecutionService)

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