Search in sources :

Example 1 with DefaultRecordStore

use of com.hazelcast.map.impl.recordstore.DefaultRecordStore 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.cluster.Address) PartitionContainer(com.hazelcast.map.impl.PartitionContainer) IPartitionService(com.hazelcast.internal.partition.IPartitionService) EntryCostEstimator(com.hazelcast.map.impl.EntryCostEstimator) MapServiceContext(com.hazelcast.map.impl.MapServiceContext) NodeEngine(com.hazelcast.spi.impl.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 2 with DefaultRecordStore

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

the class RecordStoreTest method testRecordStoreReset.

private IMap<Object, Object> testRecordStoreReset() {
    String mapName = randomName();
    Config config = new Config();
    MapConfig mapConfig = config.getMapConfig(mapName);
    IndexConfig indexConfig = new IndexConfig(IndexType.HASH, "name");
    mapConfig.addIndexConfig(indexConfig);
    HazelcastInstance hazelcastInstance = createHazelcastInstance(config);
    IMap<Object, Object> map = hazelcastInstance.getMap(mapName);
    int key = 1;
    map.put(key, new SampleTestObjects.Employee("tom", 24, true, 10));
    DefaultRecordStore defaultRecordStore = getRecordStore(map, key);
    defaultRecordStore.reset();
    assertNull(map.get(key));
    return map;
}
Also used : IndexConfig(com.hazelcast.config.IndexConfig) HazelcastInstance(com.hazelcast.core.HazelcastInstance) Config(com.hazelcast.config.Config) IndexConfig(com.hazelcast.config.IndexConfig) MapConfig(com.hazelcast.config.MapConfig) SampleTestObjects(com.hazelcast.query.SampleTestObjects) MapConfig(com.hazelcast.config.MapConfig) DefaultRecordStore(com.hazelcast.map.impl.recordstore.DefaultRecordStore)

Example 3 with DefaultRecordStore

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

the class EntryLoaderSimpleTest method testLoadEntryAtCurrentTime.

@Test
public void testLoadEntryAtCurrentTime() {
    testEntryLoader.putExternally("key", "value", 42);
    MapService service = getNodeEngineImpl(instances[0]).getService(MapService.SERVICE_NAME);
    MapServiceContext mapServiceContext = service.getMapServiceContext();
    Config config = mapServiceContext.getNodeEngine().getConfig();
    MapContainer mapContainer = new MapContainer("anyName", config, mapServiceContext);
    Data key = mapServiceContext.toData("key");
    DefaultRecordStore recordStore = new DefaultRecordStore(mapContainer, 0, mock(MapKeyLoader.class), mock(ILogger.class));
    assertNull(recordStore.loadRecordOrNull(key, false, null));
}
Also used : MapKeyLoader(com.hazelcast.map.impl.MapKeyLoader) MapStoreConfig(com.hazelcast.config.MapStoreConfig) Config(com.hazelcast.config.Config) Data(com.hazelcast.internal.serialization.Data) ILogger(com.hazelcast.logging.ILogger) MapService(com.hazelcast.map.impl.MapService) MapServiceContext(com.hazelcast.map.impl.MapServiceContext) MapContainer(com.hazelcast.map.impl.MapContainer) DefaultRecordStore(com.hazelcast.map.impl.recordstore.DefaultRecordStore) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 4 with DefaultRecordStore

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

the class MapSplitBrainHandlerService method onStoreCollection.

/**
 * Clears indexes inside partition thread while collecting merge
 * tasks. Otherwise, if we do this cleanup upon join of merging node,
 * concurrently running merge and migration operations can cause
 * inconsistency over shared index objects between record stores.
 */
@Override
protected void onStoreCollection(RecordStore recordStore) {
    assertRunningOnPartitionThread();
    DefaultRecordStore defaultRecordStore = (DefaultRecordStore) recordStore;
    defaultRecordStore.getMapDataStore().reset();
    defaultRecordStore.getIndexingObserver().onDestroy(false, true);
}
Also used : DefaultRecordStore(com.hazelcast.map.impl.recordstore.DefaultRecordStore)

Example 5 with DefaultRecordStore

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

the class MapLoaderFuturesTest method loadingFutureCount.

private static int loadingFutureCount(String mapName, HazelcastInstance node) {
    int count = 0;
    NodeEngineImpl nodeEngine = getNode(node).getNodeEngine();
    MapService mapService = nodeEngine.getService(MapService.SERVICE_NAME);
    MapServiceContext mapServiceContext = mapService.getMapServiceContext();
    int partitionCount = nodeEngine.getPartitionService().getPartitionCount();
    for (int i = 0; i < partitionCount; i++) {
        RecordStore recordStore = mapServiceContext.getExistingRecordStore(i, mapName);
        if (recordStore != null) {
            count += ((DefaultRecordStore) recordStore).getLoadingFutures().size();
        }
    }
    return count;
}
Also used : NodeEngineImpl(com.hazelcast.spi.impl.NodeEngineImpl) RecordStore(com.hazelcast.map.impl.recordstore.RecordStore) DefaultRecordStore(com.hazelcast.map.impl.recordstore.DefaultRecordStore) MapService(com.hazelcast.map.impl.MapService) MapServiceContext(com.hazelcast.map.impl.MapServiceContext) DefaultRecordStore(com.hazelcast.map.impl.recordstore.DefaultRecordStore)

Aggregations

DefaultRecordStore (com.hazelcast.map.impl.recordstore.DefaultRecordStore)6 MapService (com.hazelcast.map.impl.MapService)3 MapServiceContext (com.hazelcast.map.impl.MapServiceContext)3 RecordStore (com.hazelcast.map.impl.recordstore.RecordStore)3 Config (com.hazelcast.config.Config)2 IPartitionService (com.hazelcast.internal.partition.IPartitionService)2 NodeEngine (com.hazelcast.spi.impl.NodeEngine)2 Address (com.hazelcast.cluster.Address)1 IndexConfig (com.hazelcast.config.IndexConfig)1 MapConfig (com.hazelcast.config.MapConfig)1 MapStoreConfig (com.hazelcast.config.MapStoreConfig)1 HazelcastInstance (com.hazelcast.core.HazelcastInstance)1 Data (com.hazelcast.internal.serialization.Data)1 ILogger (com.hazelcast.logging.ILogger)1 EntryCostEstimator (com.hazelcast.map.impl.EntryCostEstimator)1 MapContainer (com.hazelcast.map.impl.MapContainer)1 MapKeyLoader (com.hazelcast.map.impl.MapKeyLoader)1 PartitionContainer (com.hazelcast.map.impl.PartitionContainer)1 MapProxyImpl (com.hazelcast.map.impl.proxy.MapProxyImpl)1 SampleTestObjects (com.hazelcast.query.SampleTestObjects)1