Search in sources :

Example 36 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 37 with RecordStore

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

the class MergePolicySerializationTest method testIssue2665.

@Test
public void testIssue2665() {
    String name = randomString();
    String serviceName = "hz:impl:mapService";
    HazelcastInstance instance = createHazelcastInstance(getConfig());
    IMap<String, MyObject> map = instance.getMap(name);
    MyObject myObjectExisting = new MyObject();
    map.put("key", myObjectExisting);
    NodeEngineImpl nodeEngine = HazelcastTestSupport.getNode(instance).getNodeEngine();
    MapService mapService = nodeEngine.getService(serviceName);
    MapServiceContext mapServiceContext = mapService.getMapServiceContext();
    int partitionId = nodeEngine.getPartitionService().getPartitionId("key");
    Data dataKey = mapServiceContext.toData("key");
    RecordStore recordStore = mapServiceContext.getRecordStore(partitionId, name);
    MapMergePolicy mergePolicy = mapServiceContext.getMergePolicyProvider().getMergePolicy(PutIfAbsentMapMergePolicy.class.getName());
    EntryView<String, MyObject> mergingEntryView = new SimpleEntryView<String, MyObject>("key", new MyObject());
    recordStore.merge(dataKey, mergingEntryView, mergePolicy);
    int deSerializedCount = MyObject.deserializedCount;
    assertEquals(0, deSerializedCount);
}
Also used : NodeEngineImpl(com.hazelcast.spi.impl.NodeEngineImpl) Data(com.hazelcast.nio.serialization.Data) MapServiceContext(com.hazelcast.map.impl.MapServiceContext) HazelcastInstance(com.hazelcast.core.HazelcastInstance) RecordStore(com.hazelcast.map.impl.recordstore.RecordStore) PutIfAbsentMapMergePolicy(com.hazelcast.map.merge.PutIfAbsentMapMergePolicy) SimpleEntryView(com.hazelcast.map.impl.SimpleEntryView) MapService(com.hazelcast.map.impl.MapService) PutIfAbsentMapMergePolicy(com.hazelcast.map.merge.PutIfAbsentMapMergePolicy) MapMergePolicy(com.hazelcast.map.merge.MapMergePolicy) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 38 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) {
    if (event.getMigrationEndpoint() == DESTINATION) {
        populateIndexes(event, TargetIndexes.GLOBAL, "commitMigration");
    } else {
        depopulateIndexes(event, "commitMigration");
    }
    if (SOURCE == event.getMigrationEndpoint()) {
        // Do not change order of below methods
        removeWbqCountersHavingLesserBackupCountThan(event.getPartitionId(), event.getNewReplicaIndex());
        removeRecordStoresHavingLesserBackupCountThan(event.getPartitionId(), event.getNewReplicaIndex());
    }
    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.nullifyOwnedPartitions();
    removeOrRegenerateNearCacheUuid(event);
}
Also used : RecordStore(com.hazelcast.map.impl.recordstore.RecordStore)

Example 39 with RecordStore

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

the class MapService method onBeforeLock.

@Override
public void onBeforeLock(String distributedObjectName, Data key) {
    int partitionId = mapServiceContext.getNodeEngine().getPartitionService().getPartitionId(key);
    RecordStore recordStore = mapServiceContext.getRecordStore(partitionId, distributedObjectName);
    // we have no use for the return value, invoked just for the side-effects
    recordStore.beforeOperation();
    try {
        recordStore.getRecordOrNull(key);
    } finally {
        recordStore.afterOperation();
    }
}
Also used : RecordStore(com.hazelcast.map.impl.recordstore.RecordStore)

Example 40 with RecordStore

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

the class MapServiceContextImpl method removeWbqCountersFromMatchingPartitionsWith.

@Override
public void removeWbqCountersFromMatchingPartitionsWith(Predicate<RecordStore> predicate, int partitionId) {
    PartitionContainer container = partitionContainers[partitionId];
    if (container == null) {
        return;
    }
    Iterator<RecordStore> partitionIterator = container.getMaps().values().iterator();
    while (partitionIterator.hasNext()) {
        RecordStore partition = partitionIterator.next();
        if (predicate.test(partition)) {
            partition.getMapDataStore().getTxnReservedCapacityCounter().releaseAllReservations();
        }
    }
}
Also used : DefaultRecordStore(com.hazelcast.map.impl.recordstore.DefaultRecordStore) 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