Search in sources :

Example 11 with RecordStore

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

the class EvictionMaxSizePolicyTest method setTestSizeEstimator.

public static void setTestSizeEstimator(IMap map, final long oneEntryHeapCostInBytes) {
    final MapProxyImpl mapProxy = (MapProxyImpl) map;
    final MapService mapService = (MapService) mapProxy.getService();
    final MapServiceContext mapServiceContext = mapService.getMapServiceContext();
    final NodeEngine nodeEngine = mapServiceContext.getNodeEngine();
    final IPartitionService partitionService = nodeEngine.getPartitionService();
    for (int i = 0; i < partitionService.getPartitionCount(); i++) {
        final Address owner = partitionService.getPartitionOwner(i);
        if (nodeEngine.getThisAddress().equals(owner)) {
            final PartitionContainer container = mapServiceContext.getPartitionContainer(i);
            if (container == null) {
                continue;
            }
            final RecordStore recordStore = container.getRecordStore(map.getName());
            final DefaultRecordStore defaultRecordStore = (DefaultRecordStore) recordStore;
            defaultRecordStore.setSizeEstimator(new EntryCostEstimator() {

                long size;

                @Override
                public long getEstimate() {
                    return size;
                }

                @Override
                public void adjustEstimateBy(long size) {
                    this.size += size;
                }

                @Override
                public long calculateValueCost(Object record) {
                    if (record == null) {
                        return 0L;
                    }
                    return oneEntryHeapCostInBytes;
                }

                @Override
                public long calculateEntryCost(Object key, Object record) {
                    if (record == null) {
                        return 0L;
                    }
                    return 2 * oneEntryHeapCostInBytes;
                }

                @Override
                public void reset() {
                    size = 0;
                }
            });
        }
    }
}
Also used : Address(com.hazelcast.nio.Address) PartitionContainer(com.hazelcast.map.impl.PartitionContainer) IPartitionService(com.hazelcast.spi.partition.IPartitionService) EntryCostEstimator(com.hazelcast.map.impl.EntryCostEstimator) MapServiceContext(com.hazelcast.map.impl.MapServiceContext) NodeEngine(com.hazelcast.spi.NodeEngine) MapProxyImpl(com.hazelcast.map.impl.proxy.MapProxyImpl) DefaultRecordStore(com.hazelcast.map.impl.recordstore.DefaultRecordStore) RecordStore(com.hazelcast.map.impl.recordstore.RecordStore) MapService(com.hazelcast.map.impl.MapService) DefaultRecordStore(com.hazelcast.map.impl.recordstore.DefaultRecordStore)

Example 12 with RecordStore

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

the class MapMergePolicyQuickTest method testPutIfAbsentMapMergePolicy.

@Test
public void testPutIfAbsentMapMergePolicy() {
    HazelcastInstance instance = createHazelcastInstance(getConfig());
    String name = randomString();
    IMap<String, String> map = instance.getMap(name);
    MapServiceContext mapServiceContext = getMapServiceContext(instance);
    Data dataKey = mapServiceContext.toData("key");
    RecordStore recordStore = mapServiceContext.getRecordStore(getPartitionId(instance, "key"), name);
    MapMergePolicy mergePolicy = mapServiceContext.getMergePolicyProvider().getMergePolicy(PutIfAbsentMapMergePolicy.class.getName());
    SimpleEntryView<String, String> initialEntry = new SimpleEntryView<String, String>("key", "value1");
    recordStore.merge(dataKey, initialEntry, mergePolicy);
    SimpleEntryView<String, String> mergingEntry = new SimpleEntryView<String, String>("key", "value2");
    recordStore.merge(dataKey, mergingEntry, mergePolicy);
    assertEquals("value1", map.get("key"));
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) RecordStore(com.hazelcast.map.impl.recordstore.RecordStore) PutIfAbsentMapMergePolicy(com.hazelcast.map.merge.PutIfAbsentMapMergePolicy) SimpleEntryView(com.hazelcast.map.impl.SimpleEntryView) Data(com.hazelcast.nio.serialization.Data) MapServiceContext(com.hazelcast.map.impl.MapServiceContext) PutIfAbsentMapMergePolicy(com.hazelcast.map.merge.PutIfAbsentMapMergePolicy) MapMergePolicy(com.hazelcast.map.merge.MapMergePolicy) LatestUpdateMapMergePolicy(com.hazelcast.map.merge.LatestUpdateMapMergePolicy) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 13 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) RecordStore(com.hazelcast.map.impl.recordstore.RecordStore) MapService(com.hazelcast.map.impl.MapService) MapServiceContext(com.hazelcast.map.impl.MapServiceContext) WriteBehindStore(com.hazelcast.map.impl.mapstore.writebehind.WriteBehindStore)

Example 14 with RecordStore

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

the class DynamicMapConfigTest method isRecordStoreExpirable.

private boolean isRecordStoreExpirable(IMap map) {
    MapProxyImpl mapProxy = (MapProxyImpl) map;
    MapService mapService = (MapService) mapProxy.getService();
    MapServiceContext mapServiceContext = (MapServiceContext) mapService.getMapServiceContext();
    PartitionContainer container = mapServiceContext.getPartitionContainer(0);
    RecordStore recordStore = container.getExistingRecordStore(map.getName());
    return recordStore.isExpirable();
}
Also used : PartitionContainer(com.hazelcast.map.impl.PartitionContainer) MapProxyImpl(com.hazelcast.map.impl.proxy.MapProxyImpl) RecordStore(com.hazelcast.map.impl.recordstore.RecordStore) MapService(com.hazelcast.map.impl.MapService) MapServiceContext(com.hazelcast.map.impl.MapServiceContext)

Example 15 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, int partitionCount) {
    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(PARTITION_COUNT.getName(), valueOf(partitionCount));
    HazelcastProperties hazelcastProperties = new HazelcastProperties(config);
    InternalPartitionService partitionService = mock(InternalPartitionService.class);
    when(partitionService.getPartitionCount()).thenReturn(partitionCount);
    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.getOwnedPartitions()).thenReturn(localPartitions.keySet());
    limiter = new QueryResultSizeLimiter(mapServiceContext, Logger.getLogger(QueryResultSizeLimiterTest.class));
}
Also used : NodeEngine(com.hazelcast.spi.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) MapServiceContext(com.hazelcast.map.impl.MapServiceContext)

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