Search in sources :

Example 6 with MetaDataGenerator

use of com.hazelcast.internal.nearcache.impl.invalidation.MetaDataGenerator in project hazelcast by hazelcast.

the class ClientCacheMetaDataFetcherTest method distortRandomPartitionSequence.

private void distortRandomPartitionSequence(String cacheName, int partition, long sequence, HazelcastInstance member) {
    NodeEngineImpl nodeEngineImpl = getNodeEngineImpl(member);
    CacheService service = nodeEngineImpl.getService(SERVICE_NAME);
    CacheEventHandler cacheEventHandler = service.getCacheEventHandler();
    MetaDataGenerator metaDataGenerator = cacheEventHandler.getMetaDataGenerator();
    metaDataGenerator.setCurrentSequence(cacheName, partition, sequence);
}
Also used : NodeEngineImpl(com.hazelcast.spi.impl.NodeEngineImpl) CacheEventHandler(com.hazelcast.cache.impl.CacheEventHandler) MetaDataGenerator(com.hazelcast.internal.nearcache.impl.invalidation.MetaDataGenerator) CacheService(com.hazelcast.cache.impl.CacheService)

Example 7 with MetaDataGenerator

use of com.hazelcast.internal.nearcache.impl.invalidation.MetaDataGenerator in project hazelcast by hazelcast.

the class ClientMapMetaDataFetcherTest method distortRandomPartitionSequence.

private void distortRandomPartitionSequence(String mapName, int partition, long sequence, HazelcastInstance member) {
    NodeEngineImpl nodeEngineImpl = getNodeEngineImpl(member);
    MapService mapService = nodeEngineImpl.getService(SERVICE_NAME);
    MapServiceContext mapServiceContext = mapService.getMapServiceContext();
    MapNearCacheManager mapNearCacheManager = mapServiceContext.getMapNearCacheManager();
    Invalidator invalidator = mapNearCacheManager.getInvalidator();
    MetaDataGenerator metaDataGenerator = invalidator.getMetaDataGenerator();
    metaDataGenerator.setCurrentSequence(mapName, partition, sequence);
}
Also used : NodeEngineImpl(com.hazelcast.spi.impl.NodeEngineImpl) MapNearCacheManager(com.hazelcast.map.impl.nearcache.MapNearCacheManager) Invalidator(com.hazelcast.internal.nearcache.impl.invalidation.Invalidator) MapService(com.hazelcast.map.impl.MapService) MetaDataGenerator(com.hazelcast.internal.nearcache.impl.invalidation.MetaDataGenerator) MapServiceContext(com.hazelcast.map.impl.MapServiceContext)

Example 8 with MetaDataGenerator

use of com.hazelcast.internal.nearcache.impl.invalidation.MetaDataGenerator in project hazelcast by hazelcast.

the class ClientCacheMetaDataFetcherTest method distortRandomPartitionUuid.

private void distortRandomPartitionUuid(int partition, UUID uuid, HazelcastInstance member) {
    NodeEngineImpl nodeEngineImpl = getNodeEngineImpl(member);
    CacheService service = nodeEngineImpl.getService(SERVICE_NAME);
    CacheEventHandler cacheEventHandler = service.getCacheEventHandler();
    MetaDataGenerator metaDataGenerator = cacheEventHandler.getMetaDataGenerator();
    metaDataGenerator.setUuid(partition, uuid);
}
Also used : NodeEngineImpl(com.hazelcast.spi.impl.NodeEngineImpl) CacheEventHandler(com.hazelcast.cache.impl.CacheEventHandler) MetaDataGenerator(com.hazelcast.internal.nearcache.impl.invalidation.MetaDataGenerator) CacheService(com.hazelcast.cache.impl.CacheService)

Example 9 with MetaDataGenerator

use of com.hazelcast.internal.nearcache.impl.invalidation.MetaDataGenerator in project hazelcast by hazelcast.

the class InvalidationMemberAddRemoveTest method ensure_nearCachedClient_and_member_data_sync_eventually.

@Test
public void ensure_nearCachedClient_and_member_data_sync_eventually() throws Exception {
    final AtomicBoolean stopTest = new AtomicBoolean();
    final Config config = createConfig();
    hazelcastFactory.newHazelcastInstance(config);
    CachingProvider provider = HazelcastServerCachingProvider.createCachingProvider(serverInstance);
    final CacheManager serverCacheManager = provider.getCacheManager();
    // populated from member.
    final Cache<Integer, Integer> memberCache = serverCacheManager.createCache(DEFAULT_CACHE_NAME, createCacheConfig(BINARY));
    for (int i = 0; i < KEY_COUNT; i++) {
        memberCache.put(i, i);
    }
    ClientConfig clientConfig = createClientConfig();
    clientConfig.addNearCacheConfig(createNearCacheConfig(BINARY));
    HazelcastClientProxy client = (HazelcastClientProxy) hazelcastFactory.newHazelcastClient(clientConfig);
    CachingProvider clientCachingProvider = HazelcastClientCachingProvider.createCachingProvider(client);
    final Cache<Integer, Integer> clientCache = clientCachingProvider.getCacheManager().createCache(DEFAULT_CACHE_NAME, createCacheConfig(BINARY));
    ArrayList<Thread> threads = new ArrayList<Thread>();
    // continuously adds and removes member
    Thread shadowMember = new Thread(new Runnable() {

        @Override
        public void run() {
            while (!stopTest.get()) {
                HazelcastInstance member = hazelcastFactory.newHazelcastInstance(config);
                sleepSeconds(5);
                member.getLifecycleService().terminate();
            }
        }
    });
    threads.add(shadowMember);
    for (int i = 0; i < NEAR_CACHE_POPULATOR_THREAD_COUNT; i++) {
        // populates client near-cache
        Thread populateClientNearCache = new Thread(new Runnable() {

            public void run() {
                while (!stopTest.get()) {
                    for (int i = 0; i < KEY_COUNT; i++) {
                        clientCache.get(i);
                    }
                }
            }
        });
        threads.add(populateClientNearCache);
    }
    // updates data from member.
    Thread putFromMember = new Thread(new Runnable() {

        public void run() {
            while (!stopTest.get()) {
                int key = getInt(KEY_COUNT);
                int value = getInt(Integer.MAX_VALUE);
                memberCache.put(key, value);
                sleepAtLeastMillis(2);
            }
        }
    });
    threads.add(putFromMember);
    Thread clearFromMember = new Thread(new Runnable() {

        public void run() {
            while (!stopTest.get()) {
                memberCache.clear();
                sleepSeconds(3);
            }
        }
    });
    threads.add(clearFromMember);
    // start threads
    for (Thread thread : threads) {
        thread.start();
    }
    // stress system some seconds
    sleepSeconds(TEST_RUN_SECONDS);
    //stop threads
    stopTest.set(true);
    for (Thread thread : threads) {
        thread.join();
    }
    assertTrueEventually(new AssertTask() {

        @Override
        public void run() throws Exception {
            for (int i = 0; i < KEY_COUNT; i++) {
                Integer valueSeenFromMember = memberCache.get(i);
                Integer valueSeenFromClient = clientCache.get(i);
                String msg = createFailureMessage(i);
                assertEquals(msg, valueSeenFromMember, valueSeenFromClient);
            }
        }

        private String createFailureMessage(int i) {
            InternalPartitionService partitionService = getPartitionService(serverInstance);
            Data keyData = getSerializationService(serverInstance).toData(i);
            int partitionId = partitionService.getPartitionId(keyData);
            AbstractNearCacheRecordStore nearCacheRecordStore = getAbstractNearCacheRecordStore();
            NearCacheRecord record = nearCacheRecordStore.getRecord(keyData);
            long recordSequence = record == null ? NO_SEQUENCE : record.getInvalidationSequence();
            MetaDataGenerator metaDataGenerator = getMetaDataGenerator();
            long memberSequence = metaDataGenerator.currentSequence("/hz/" + DEFAULT_CACHE_NAME, partitionId);
            MetaDataContainer metaDataContainer = nearCacheRecordStore.getStaleReadDetector().getMetaDataContainer(keyData);
            return String.format("partition=%d, onRecordSequence=%d, latestSequence=%d, staleSequence=%d, memberSequence=%d", partitionService.getPartitionId(keyData), recordSequence, metaDataContainer.getSequence(), metaDataContainer.getStaleSequence(), memberSequence);
        }

        private MetaDataGenerator getMetaDataGenerator() {
            CacheEventHandler cacheEventHandler = ((CacheService) ((CacheProxy) memberCache).getService()).getCacheEventHandler();
            return cacheEventHandler.getMetaDataGenerator();
        }

        private AbstractNearCacheRecordStore getAbstractNearCacheRecordStore() {
            DefaultNearCache defaultNearCache = (DefaultNearCache) ((ClientCacheProxy) clientCache).getNearCache().unwrap(DefaultNearCache.class);
            return (AbstractNearCacheRecordStore) defaultNearCache.getNearCacheRecordStore();
        }
    });
}
Also used : DefaultNearCache(com.hazelcast.internal.nearcache.impl.DefaultNearCache) ClientConfig(com.hazelcast.client.config.ClientConfig) Config(com.hazelcast.config.Config) CacheConfig(com.hazelcast.config.CacheConfig) NearCacheConfig(com.hazelcast.config.NearCacheConfig) ArrayList(java.util.ArrayList) CacheEventHandler(com.hazelcast.cache.impl.CacheEventHandler) MetaDataContainer(com.hazelcast.internal.nearcache.impl.invalidation.MetaDataContainer) ClientCacheProxy(com.hazelcast.client.cache.impl.ClientCacheProxy) CacheProxy(com.hazelcast.cache.impl.CacheProxy) CacheManager(javax.cache.CacheManager) AbstractNearCacheRecordStore(com.hazelcast.internal.nearcache.impl.store.AbstractNearCacheRecordStore) ClientConfig(com.hazelcast.client.config.ClientConfig) HazelcastClientProxy(com.hazelcast.client.impl.HazelcastClientProxy) MetaDataGenerator(com.hazelcast.internal.nearcache.impl.invalidation.MetaDataGenerator) HazelcastServerCachingProvider(com.hazelcast.cache.impl.HazelcastServerCachingProvider) CachingProvider(javax.cache.spi.CachingProvider) HazelcastClientCachingProvider(com.hazelcast.client.cache.impl.HazelcastClientCachingProvider) InternalPartitionService(com.hazelcast.internal.partition.InternalPartitionService) Data(com.hazelcast.nio.serialization.Data) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) HazelcastInstance(com.hazelcast.core.HazelcastInstance) NearCacheRecord(com.hazelcast.internal.nearcache.NearCacheRecord) AssertTask(com.hazelcast.test.AssertTask) NightlyTest(com.hazelcast.test.annotation.NightlyTest) Test(org.junit.Test)

Example 10 with MetaDataGenerator

use of com.hazelcast.internal.nearcache.impl.invalidation.MetaDataGenerator in project hazelcast by hazelcast.

the class InvalidationMetadataDistortionTest method distortRandomPartitionUuid.

private void distortRandomPartitionUuid(HazelcastInstance member) {
    NodeEngineImpl nodeEngineImpl = getNodeEngineImpl(member);
    int partitionCount = nodeEngineImpl.getPartitionService().getPartitionCount();
    CacheService service = nodeEngineImpl.getService(CacheService.SERVICE_NAME);
    CacheEventHandler cacheEventHandler = service.getCacheEventHandler();
    MetaDataGenerator metaDataGenerator = cacheEventHandler.getMetaDataGenerator();
    UUID uuid = UuidUtil.newSecureUUID();
    int randomPartition = getInt(partitionCount);
    metaDataGenerator.setUuid(randomPartition, uuid);
}
Also used : NodeEngineImpl(com.hazelcast.spi.impl.NodeEngineImpl) CacheEventHandler(com.hazelcast.cache.impl.CacheEventHandler) MetaDataGenerator(com.hazelcast.internal.nearcache.impl.invalidation.MetaDataGenerator) UUID(java.util.UUID) CacheService(com.hazelcast.cache.impl.CacheService)

Aggregations

MetaDataGenerator (com.hazelcast.internal.nearcache.impl.invalidation.MetaDataGenerator)23 NodeEngineImpl (com.hazelcast.spi.impl.NodeEngineImpl)14 MapService (com.hazelcast.map.impl.MapService)12 Invalidator (com.hazelcast.internal.nearcache.impl.invalidation.Invalidator)10 MapServiceContext (com.hazelcast.map.impl.MapServiceContext)10 MapNearCacheManager (com.hazelcast.map.impl.nearcache.MapNearCacheManager)10 HashMap (java.util.HashMap)6 CacheEventHandler (com.hazelcast.cache.impl.CacheEventHandler)5 CacheService (com.hazelcast.cache.impl.CacheService)5 ArrayList (java.util.ArrayList)5 InternalPartitionService (com.hazelcast.internal.partition.InternalPartitionService)4 UUID (java.util.UUID)4 Map (java.util.Map)3 ICacheService (com.hazelcast.cache.impl.ICacheService)2 AbstractMap (java.util.AbstractMap)2 List (java.util.List)2 AbstractCacheService (com.hazelcast.cache.impl.AbstractCacheService)1 CacheProxy (com.hazelcast.cache.impl.CacheProxy)1 HazelcastServerCachingProvider (com.hazelcast.cache.impl.HazelcastServerCachingProvider)1 ICacheRecordStore (com.hazelcast.cache.impl.ICacheRecordStore)1