Search in sources :

Example 56 with RecordStore

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

the class MapMergePolicyQuickTest method testLatestUpdateMapMergePolicy.

@Test
public void testLatestUpdateMapMergePolicy() {
    HazelcastInstance instance = createHazelcastInstance(getConfig());
    String name = randomString();
    IMap<String, String> map = instance.getMap(name);
    MapServiceContext mapServiceContext = getMapServiceContext(instance);
    Data dataKey = mapServiceContext.toData("key");
    Data dataValue = mapServiceContext.toData("value1");
    Data dataValue2 = mapServiceContext.toData("value2");
    RecordStore recordStore = mapServiceContext.getRecordStore(getPartitionId(instance, "key"), name);
    recordStore.beforeOperation();
    NodeEngine nodeEngine = mapServiceContext.getNodeEngine();
    SplitBrainMergePolicyProvider mergePolicyProvider = nodeEngine.getSplitBrainMergePolicyProvider();
    SplitBrainMergePolicy mergePolicy = mergePolicyProvider.getMergePolicy(LatestUpdateMergePolicy.class.getName());
    long now = Clock.currentTimeMillis();
    SimpleEntryView<Data, Data> initialEntry = new SimpleEntryView<>(dataKey, dataValue);
    initialEntry.setCreationTime(now);
    initialEntry.setLastUpdateTime(now);
    // need some latency to be sure that target members time is greater than now
    sleepMillis(100);
    recordStore.merge(createMergingEntry(nodeEngine.getSerializationService(), initialEntry), mergePolicy, CallerProvenance.NOT_WAN);
    SimpleEntryView<Data, Data> mergingEntry = new SimpleEntryView<>(dataKey, dataValue2);
    now = Clock.currentTimeMillis();
    mergingEntry.setCreationTime(now);
    mergingEntry.setLastUpdateTime(now);
    recordStore.merge(createMergingEntry(nodeEngine.getSerializationService(), mergingEntry), mergePolicy, CallerProvenance.NOT_WAN);
    assertEquals("value2", map.get("key"));
    recordStore.afterOperation();
}
Also used : LatestUpdateMergePolicy(com.hazelcast.spi.merge.LatestUpdateMergePolicy) Data(com.hazelcast.internal.serialization.Data) SplitBrainMergePolicyProvider(com.hazelcast.spi.merge.SplitBrainMergePolicyProvider) MapServiceContext(com.hazelcast.map.impl.MapServiceContext) NodeEngine(com.hazelcast.spi.impl.NodeEngine) SplitBrainMergePolicy(com.hazelcast.spi.merge.SplitBrainMergePolicy) HazelcastInstance(com.hazelcast.core.HazelcastInstance) RecordStore(com.hazelcast.map.impl.recordstore.RecordStore) SimpleEntryView(com.hazelcast.map.impl.SimpleEntryView) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 57 with RecordStore

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

the class QueryResultSizeLimiterTest method initMocksWithConfiguration.

private void initMocksWithConfiguration(int maxResultSizeLimit, int maxLocalPartitionLimitForPreCheck) {
    Config config = new Config();
    config.setProperty(QUERY_RESULT_SIZE_LIMIT.getName(), valueOf(maxResultSizeLimit));
    config.setProperty(QUERY_MAX_LOCAL_PARTITION_LIMIT_FOR_PRE_CHECK.getName(), valueOf(maxLocalPartitionLimitForPreCheck));
    config.setProperty(ClusterProperty.PARTITION_COUNT.getName(), valueOf(PARTITION_COUNT));
    HazelcastProperties hazelcastProperties = new HazelcastProperties(config);
    InternalPartitionService partitionService = mock(InternalPartitionService.class);
    when(partitionService.getPartitionCount()).thenReturn(PARTITION_COUNT);
    NodeEngine nodeEngine = mock(NodeEngine.class);
    when(nodeEngine.getProperties()).thenReturn(hazelcastProperties);
    when(nodeEngine.getPartitionService()).thenReturn(partitionService);
    RecordStore recordStore = mock(RecordStore.class);
    when(recordStore.size()).then(new RecordStoreAnswer(localPartitions.values()));
    MapServiceContext mapServiceContext = mock(MapServiceContext.class);
    when(mapServiceContext.getNodeEngine()).thenReturn(nodeEngine);
    when(mapServiceContext.getRecordStore(anyInt(), anyString())).thenReturn(recordStore);
    when(mapServiceContext.getOrInitCachedMemberPartitions()).thenReturn(new PartitionIdSet(PARTITION_COUNT, localPartitions.keySet()));
    limiter = new QueryResultSizeLimiter(mapServiceContext, Logger.getLogger(QueryResultSizeLimiterTest.class));
}
Also used : NodeEngine(com.hazelcast.spi.impl.NodeEngine) HazelcastProperties(com.hazelcast.spi.properties.HazelcastProperties) InternalPartitionService(com.hazelcast.internal.partition.InternalPartitionService) Config(com.hazelcast.config.Config) RecordStore(com.hazelcast.map.impl.recordstore.RecordStore) PartitionIdSet(com.hazelcast.internal.util.collection.PartitionIdSet) MapServiceContext(com.hazelcast.map.impl.MapServiceContext)

Example 58 with RecordStore

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

the class JsonMetadataCreationMigrationTest method getMetadata.

protected JsonMetadata getMetadata(String mapName, Object key, int replicaIndex) {
    HazelcastInstance[] instances = factory.getAllHazelcastInstances().toArray(new HazelcastInstance[] { null });
    HazelcastInstance instance = factory.getAllHazelcastInstances().iterator().next();
    InternalSerializationService serializationService = getSerializationService(instance);
    Data keyData = serializationService.toData(key);
    int partitionId = getPartitionService(instance).getPartitionId(key);
    NodeEngineImpl nodeEngine = getNodeEngineImpl(getBackupInstance(instances, partitionId, replicaIndex));
    MapService mapService = nodeEngine.getService(MapService.SERVICE_NAME);
    RecordStore recordStore = mapService.getMapServiceContext().getPartitionContainer(partitionId).getRecordStore(mapName);
    return recordStore.getOrCreateMetadataStore().get(keyData);
}
Also used : NodeEngineImpl(com.hazelcast.spi.impl.NodeEngineImpl) Accessors.getNodeEngineImpl(com.hazelcast.test.Accessors.getNodeEngineImpl) HazelcastInstance(com.hazelcast.core.HazelcastInstance) RecordStore(com.hazelcast.map.impl.recordstore.RecordStore) Data(com.hazelcast.internal.serialization.Data) InternalSerializationService(com.hazelcast.internal.serialization.InternalSerializationService) MapService(com.hazelcast.map.impl.MapService)

Example 59 with RecordStore

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

the class MapStoreWriteBehindTest method writeBehindQueueSize.

private int writeBehindQueueSize(HazelcastInstance node, String mapName) {
    int size = 0;
    final NodeEngineImpl nodeEngine = getNode(node).getNodeEngine();
    MapService mapService = nodeEngine.getService(MapService.SERVICE_NAME);
    final MapServiceContext mapServiceContext = mapService.getMapServiceContext();
    final int partitionCount = nodeEngine.getPartitionService().getPartitionCount();
    for (int i = 0; i < partitionCount; i++) {
        final RecordStore recordStore = mapServiceContext.getExistingRecordStore(i, mapName);
        if (recordStore == null) {
            continue;
        }
        final MapDataStore mapDataStore = recordStore.getMapDataStore();
        size += ((WriteBehindStore) mapDataStore).getWriteBehindQueue().size();
    }
    return size;
}
Also used : NodeEngineImpl(com.hazelcast.spi.impl.NodeEngineImpl) MapDataStore(com.hazelcast.map.impl.mapstore.MapDataStore) RecordStore(com.hazelcast.map.impl.recordstore.RecordStore) MapService(com.hazelcast.map.impl.MapService) MapServiceContext(com.hazelcast.map.impl.MapServiceContext)

Example 60 with RecordStore

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

the class WriteBehindOnBackupsTest method writeBehindQueueSize.

public static int writeBehindQueueSize(HazelcastInstance node, String mapName) {
    int size = 0;
    final NodeEngineImpl nodeEngine = getNode(node).getNodeEngine();
    MapService mapService = nodeEngine.getService(MapService.SERVICE_NAME);
    final MapServiceContext mapServiceContext = mapService.getMapServiceContext();
    final int partitionCount = nodeEngine.getPartitionService().getPartitionCount();
    for (int i = 0; i < partitionCount; i++) {
        final RecordStore recordStore = mapServiceContext.getExistingRecordStore(i, mapName);
        if (recordStore == null) {
            continue;
        }
        final MapDataStore mapDataStore = recordStore.getMapDataStore();
        if (mapDataStore instanceof WriteBehindStore) {
            size += ((WriteBehindStore) mapDataStore).getWriteBehindQueue().size();
        }
    }
    return size;
}
Also used : NodeEngineImpl(com.hazelcast.spi.impl.NodeEngineImpl) MapDataStore(com.hazelcast.map.impl.mapstore.MapDataStore) RecordStore(com.hazelcast.map.impl.recordstore.RecordStore) MapService(com.hazelcast.map.impl.MapService) MapServiceContext(com.hazelcast.map.impl.MapServiceContext)

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