Search in sources :

Example 1 with CachePartitionSegment

use of com.hazelcast.cache.impl.CachePartitionSegment in project hazelcast by hazelcast.

the class CacheReplicationOperationTest method sendsConfigObjectOverWire.

@Test
public void sendsConfigObjectOverWire() throws Exception {
    // new config
    CacheConfig config = new CacheConfig("test-cache");
    // add config to cache service
    NodeEngineImpl nodeEngineImpl = getNodeEngineImpl(createHazelcastInstance());
    CacheService cacheService = nodeEngineImpl.getService(CacheService.SERVICE_NAME);
    cacheService.putCacheConfigIfAbsent(config);
    CachePartitionSegment segment = new CachePartitionSegment(cacheService, 0);
    segment.getOrCreateRecordStore(config.getNameWithPrefix());
    Collection<ServiceNamespace> namespaces = segment.getAllNamespaces(0);
    assertEquals(1, namespaces.size());
    // create operation
    CacheReplicationOperation operation = new CacheReplicationOperation();
    operation.prepare(segment, namespaces, 0);
    // serialize & deserialize operation
    Data data = nodeEngineImpl.toData(operation);
    CacheReplicationOperation cacheReplicationOperation = (CacheReplicationOperation) nodeEngineImpl.toObject(data);
    // new operation instance should have previously added config.
    assertContains(cacheReplicationOperation.getConfigs(), config);
}
Also used : NodeEngineImpl(com.hazelcast.spi.impl.NodeEngineImpl) Accessors.getNodeEngineImpl(com.hazelcast.test.Accessors.getNodeEngineImpl) CachePartitionSegment(com.hazelcast.cache.impl.CachePartitionSegment) ServiceNamespace(com.hazelcast.internal.services.ServiceNamespace) Data(com.hazelcast.internal.serialization.Data) CacheConfig(com.hazelcast.config.CacheConfig) CacheService(com.hazelcast.cache.impl.CacheService) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 2 with CachePartitionSegment

use of com.hazelcast.cache.impl.CachePartitionSegment in project hazelcast by hazelcast.

the class CacheClearExpiredOperation method run.

@Override
public void run() throws Exception {
    if (getNodeEngine().getLocalMember().isLiteMember()) {
        // when converting a data-member to lite-member during merge operations.
        return;
    }
    if (!isOwner()) {
        return;
    }
    CacheService service = getService();
    CachePartitionSegment segment = service.getSegment(getPartitionId());
    Iterator<ICacheRecordStore> iterator = segment.recordStoreIterator();
    while (iterator.hasNext()) {
        ICacheRecordStore store = iterator.next();
        if (store.size() > 0) {
            store.evictExpiredEntries(expirationPercentage);
        }
    }
}
Also used : CachePartitionSegment(com.hazelcast.cache.impl.CachePartitionSegment) ICacheRecordStore(com.hazelcast.cache.impl.ICacheRecordStore) CacheService(com.hazelcast.cache.impl.CacheService)

Example 3 with CachePartitionSegment

use of com.hazelcast.cache.impl.CachePartitionSegment in project hazelcast by hazelcast.

the class CacheClearExpiredOperation method prepareForNextCleanup.

protected void prepareForNextCleanup() {
    CacheService service = getService();
    CachePartitionSegment segment = service.getSegment(getPartitionId());
    segment.setRunningCleanupOperation(false);
    segment.setLastCleanupTime(Clock.currentTimeMillis());
}
Also used : CachePartitionSegment(com.hazelcast.cache.impl.CachePartitionSegment) CacheService(com.hazelcast.cache.impl.CacheService)

Example 4 with CachePartitionSegment

use of com.hazelcast.cache.impl.CachePartitionSegment in project hazelcast by hazelcast.

the class CacheSerializationTest method test_CacheReplicationOperation_serialization.

@Test
public void test_CacheReplicationOperation_serialization() throws Exception {
    TestHazelcastInstanceFactory factory = new TestHazelcastInstanceFactory(1);
    HazelcastInstance hazelcastInstance = factory.newHazelcastInstance();
    try {
        CachingProvider provider = createServerCachingProvider(hazelcastInstance);
        CacheManager manager = provider.getCacheManager();
        CompleteConfiguration configuration = new MutableConfiguration();
        Cache cache1 = manager.createCache("cache1", configuration);
        Cache cache2 = manager.createCache("cache2", configuration);
        Cache cache3 = manager.createCache("cache3", configuration);
        for (int i = 0; i < 1000; i++) {
            cache1.put("key" + i, i);
            cache2.put("key" + i, i);
            cache3.put("key" + i, i);
        }
        HazelcastInstanceProxy proxy = (HazelcastInstanceProxy) hazelcastInstance;
        Field original = HazelcastInstanceProxy.class.getDeclaredField("original");
        original.setAccessible(true);
        HazelcastInstanceImpl impl = (HazelcastInstanceImpl) original.get(proxy);
        NodeEngineImpl nodeEngine = impl.node.nodeEngine;
        CacheService cacheService = nodeEngine.getService(CacheService.SERVICE_NAME);
        int partitionCount = nodeEngine.getPartitionService().getPartitionCount();
        for (int partitionId = 0; partitionId < partitionCount; partitionId++) {
            CachePartitionSegment segment = cacheService.getSegment(partitionId);
            int replicaIndex = 1;
            Collection<ServiceNamespace> namespaces = segment.getAllNamespaces(replicaIndex);
            if (CollectionUtil.isEmpty(namespaces)) {
                continue;
            }
            CacheReplicationOperation operation = new CacheReplicationOperation();
            operation.prepare(segment, namespaces, replicaIndex);
            Data serialized = service.toData(operation);
            try {
                service.toObject(serialized);
            } catch (Exception e) {
                throw new Exception("Partition: " + partitionId, e);
            }
        }
    } finally {
        factory.shutdownAll();
    }
}
Also used : HazelcastInstanceImpl(com.hazelcast.instance.impl.HazelcastInstanceImpl) NodeEngineImpl(com.hazelcast.spi.impl.NodeEngineImpl) CachePartitionSegment(com.hazelcast.cache.impl.CachePartitionSegment) ServiceNamespace(com.hazelcast.internal.services.ServiceNamespace) CacheReplicationOperation(com.hazelcast.cache.impl.operation.CacheReplicationOperation) Data(com.hazelcast.internal.serialization.Data) CachePartitionEventData(com.hazelcast.cache.impl.CachePartitionEventData) HazelcastInstanceProxy(com.hazelcast.instance.impl.HazelcastInstanceProxy) MutableConfiguration(javax.cache.configuration.MutableConfiguration) UnknownHostException(java.net.UnknownHostException) Field(java.lang.reflect.Field) HazelcastInstance(com.hazelcast.core.HazelcastInstance) CompleteConfiguration(javax.cache.configuration.CompleteConfiguration) CacheManager(javax.cache.CacheManager) TestHazelcastInstanceFactory(com.hazelcast.test.TestHazelcastInstanceFactory) CacheTestSupport.createServerCachingProvider(com.hazelcast.cache.CacheTestSupport.createServerCachingProvider) CachingProvider(javax.cache.spi.CachingProvider) Cache(javax.cache.Cache) CacheService(com.hazelcast.cache.impl.CacheService) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Aggregations

CachePartitionSegment (com.hazelcast.cache.impl.CachePartitionSegment)4 CacheService (com.hazelcast.cache.impl.CacheService)4 Data (com.hazelcast.internal.serialization.Data)2 ServiceNamespace (com.hazelcast.internal.services.ServiceNamespace)2 NodeEngineImpl (com.hazelcast.spi.impl.NodeEngineImpl)2 ParallelJVMTest (com.hazelcast.test.annotation.ParallelJVMTest)2 QuickTest (com.hazelcast.test.annotation.QuickTest)2 Test (org.junit.Test)2 CacheTestSupport.createServerCachingProvider (com.hazelcast.cache.CacheTestSupport.createServerCachingProvider)1 CachePartitionEventData (com.hazelcast.cache.impl.CachePartitionEventData)1 ICacheRecordStore (com.hazelcast.cache.impl.ICacheRecordStore)1 CacheReplicationOperation (com.hazelcast.cache.impl.operation.CacheReplicationOperation)1 CacheConfig (com.hazelcast.config.CacheConfig)1 HazelcastInstance (com.hazelcast.core.HazelcastInstance)1 HazelcastInstanceImpl (com.hazelcast.instance.impl.HazelcastInstanceImpl)1 HazelcastInstanceProxy (com.hazelcast.instance.impl.HazelcastInstanceProxy)1 Accessors.getNodeEngineImpl (com.hazelcast.test.Accessors.getNodeEngineImpl)1 TestHazelcastInstanceFactory (com.hazelcast.test.TestHazelcastInstanceFactory)1 Field (java.lang.reflect.Field)1 UnknownHostException (java.net.UnknownHostException)1