Search in sources :

Example 16 with PartitionContainer

use of com.hazelcast.map.impl.PartitionContainer 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 17 with PartitionContainer

use of com.hazelcast.map.impl.PartitionContainer in project hazelcast by hazelcast.

the class MapOperation method getRecordStoreOrNull.

private RecordStore getRecordStoreOrNull() {
    int partitionId = getPartitionId();
    if (partitionId == -1) {
        return null;
    }
    PartitionContainer partitionContainer = mapServiceContext.getPartitionContainer(partitionId);
    if (createRecordStoreOnDemand) {
        return partitionContainer.getRecordStore(name);
    } else {
        return partitionContainer.getExistingRecordStore(name);
    }
}
Also used : PartitionContainer(com.hazelcast.map.impl.PartitionContainer)

Example 18 with PartitionContainer

use of com.hazelcast.map.impl.PartitionContainer in project hazelcast by hazelcast.

the class MapChunk method applyIndexStateBefore.

private void applyIndexStateBefore(RecordStore recordStore) {
    MapContainer mapContainer = recordStore.getMapContainer();
    PartitionContainer partitionContainer = mapContainer.getMapServiceContext().getPartitionContainer(getPartitionId());
    for (Map.Entry<String, IndexConfig> indexDefinition : mapContainer.getIndexDefinitions().entrySet()) {
        Indexes indexes = mapContainer.getIndexes(partitionContainer.getPartitionId());
        indexes.addOrGetIndex(indexDefinition.getValue());
    }
    Indexes indexes = mapContainer.getIndexes(partitionContainer.getPartitionId());
    boolean populateIndexes = indexesMustBePopulated(indexes);
    if (populateIndexes) {
        // defensively clear possible stale
        // leftovers in non-global indexes from
        // the previous failed promotion attempt
        Indexes.beginPartitionUpdate(indexes.getIndexes());
        indexes.clearAll();
    }
}
Also used : IndexConfig(com.hazelcast.config.IndexConfig) PartitionContainer(com.hazelcast.map.impl.PartitionContainer) Indexes(com.hazelcast.query.impl.Indexes) Map(java.util.Map) MapUtil.createHashMap(com.hazelcast.internal.util.MapUtil.createHashMap) MapContainer(com.hazelcast.map.impl.MapContainer)

Example 19 with PartitionContainer

use of com.hazelcast.map.impl.PartitionContainer in project hazelcast by hazelcast.

the class MapProxySupport method readBackupDataOrNull.

private Data readBackupDataOrNull(Data key) {
    int partitionId = partitionService.getPartitionId(key);
    IPartition partition = partitionService.getPartition(partitionId, false);
    if (!partition.isOwnerOrBackup(thisAddress)) {
        return null;
    }
    PartitionContainer partitionContainer = mapServiceContext.getPartitionContainer(partitionId);
    RecordStore recordStore = partitionContainer.getExistingRecordStore(name);
    if (recordStore == null) {
        return null;
    }
    return recordStore.readBackupData(key);
}
Also used : PartitionContainer(com.hazelcast.map.impl.PartitionContainer) RecordStore(com.hazelcast.map.impl.recordstore.RecordStore) IPartition(com.hazelcast.internal.partition.IPartition)

Example 20 with PartitionContainer

use of com.hazelcast.map.impl.PartitionContainer in project hazelcast by hazelcast.

the class MetadataResolver method resolveFromHeap.

@Nullable
@SuppressWarnings("rawtypes")
private Metadata resolveFromHeap(String name, MapServiceContext context) {
    for (PartitionContainer partitionContainer : context.getPartitionContainers()) {
        RecordStore<?> recordStore = partitionContainer.getExistingRecordStore(name);
        if (recordStore == null) {
            continue;
        }
        Iterator<Entry<Data, Record>> recordStoreIterator = recordStore.iterator();
        if (!recordStoreIterator.hasNext()) {
            continue;
        }
        Entry<Data, Record> entry = recordStoreIterator.next();
        return resolveMetadata(entry.getKey(), entry.getValue().getValue());
    }
    return null;
}
Also used : Entry(java.util.Map.Entry) QueryableEntry(com.hazelcast.query.impl.QueryableEntry) PartitionContainer(com.hazelcast.map.impl.PartitionContainer) Data(com.hazelcast.internal.serialization.Data) Record(com.hazelcast.map.impl.record.Record) Nullable(javax.annotation.Nullable)

Aggregations

PartitionContainer (com.hazelcast.map.impl.PartitionContainer)28 MapService (com.hazelcast.map.impl.MapService)15 MapServiceContext (com.hazelcast.map.impl.MapServiceContext)15 RecordStore (com.hazelcast.map.impl.recordstore.RecordStore)13 MapContainer (com.hazelcast.map.impl.MapContainer)8 Map (java.util.Map)6 HazelcastInstance (com.hazelcast.core.HazelcastInstance)5 IPartition (com.hazelcast.internal.partition.IPartition)5 Indexes (com.hazelcast.query.impl.Indexes)5 Node (com.hazelcast.instance.impl.Node)4 MapProxyImpl (com.hazelcast.map.impl.proxy.MapProxyImpl)4 Record (com.hazelcast.map.impl.record.Record)4 QueryableEntry (com.hazelcast.query.impl.QueryableEntry)4 Accessors.getNode (com.hazelcast.test.Accessors.getNode)4 IndexConfig (com.hazelcast.config.IndexConfig)3 NodeEngineImpl (com.hazelcast.spi.impl.NodeEngineImpl)3 Accessors.getNodeEngineImpl (com.hazelcast.test.Accessors.getNodeEngineImpl)3 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)3 Address (com.hazelcast.cluster.Address)2 Config (com.hazelcast.config.Config)2