Search in sources :

Example 21 with ServiceNamespace

use of com.hazelcast.internal.services.ServiceNamespace in project hazelcast by hazelcast.

the class MigrationCommitServiceTest method clearReplicaIndex.

private PartitionReplica clearReplicaIndex(final int partitionId, int replicaIndexToClear) {
    final InternalPartitionServiceImpl partitionService = (InternalPartitionServiceImpl) getPartitionService(instances[0]);
    InternalPartitionImpl partition = (InternalPartitionImpl) partitionService.getPartition(partitionId);
    final PartitionReplica oldReplicaOwner = partition.getReplica(replicaIndexToClear);
    partition.setReplica(replicaIndexToClear, null);
    assertTrueEventually(new AssertTask() {

        @Override
        public void run() {
            partitionService.checkClusterPartitionRuntimeStates();
            for (HazelcastInstance instance : instances) {
                assertEquals(partitionService.getPartitionStateStamp(), getPartitionService(instance).getPartitionStateStamp());
            }
        }
    });
    HazelcastInstance oldReplicaOwnerInstance = factory.getInstance(oldReplicaOwner.address());
    ClearReplicaRunnable op = new ClearReplicaRunnable(partitionId, getNodeEngineImpl(oldReplicaOwnerInstance));
    getOperationService(oldReplicaOwnerInstance).execute(op);
    assertTrueEventually(new AssertTask() {

        @Override
        public void run() {
            PartitionReplicaVersionsView replicaVersionsView = getPartitionReplicaVersionsView(getNode(factory.getInstance(oldReplicaOwner.address())), partitionId);
            for (ServiceNamespace namespace : replicaVersionsView.getNamespaces()) {
                assertArrayEquals(new long[InternalPartition.MAX_BACKUP_COUNT], replicaVersionsView.getVersions(namespace));
            }
        }
    });
    TestMigrationAwareService migrationAwareService = getService(oldReplicaOwner.address());
    migrationAwareService.clearPartitionReplica(partitionId);
    for (HazelcastInstance instance : instances) {
        TestMigrationAwareService service = getNodeEngineImpl(instance).getService(TestMigrationAwareService.SERVICE_NAME);
        service.clearEvents();
    }
    return oldReplicaOwner;
}
Also used : TestMigrationAwareService(com.hazelcast.internal.partition.service.TestMigrationAwareService) HazelcastInstance(com.hazelcast.core.HazelcastInstance) PartitionReplica(com.hazelcast.internal.partition.PartitionReplica) ServiceNamespace(com.hazelcast.internal.services.ServiceNamespace) AssertTask(com.hazelcast.test.AssertTask) PartitionReplicaVersionsView(com.hazelcast.internal.partition.PartitionReplicaVersionsView) TestPartitionUtils.getPartitionReplicaVersionsView(com.hazelcast.internal.partition.TestPartitionUtils.getPartitionReplicaVersionsView)

Example 22 with ServiceNamespace

use of com.hazelcast.internal.services.ServiceNamespace in project hazelcast by hazelcast.

the class TestFragmentedMigrationAwareService method prepareReplicationOperation.

@Override
public Operation prepareReplicationOperation(PartitionReplicationEvent event, Collection<ServiceNamespace> namespaces) {
    if (event.getReplicaIndex() > backupCount || namespaces.isEmpty()) {
        return null;
    }
    Collection<ServiceNamespace> knownNamespaces = getAllServiceNamespaces(event);
    Map<TestServiceNamespace, Integer> values = new HashMap<TestServiceNamespace, Integer>(namespaces.size());
    for (ServiceNamespace ns : namespaces) {
        assertThat(ns, isIn(knownNamespaces));
        TestServiceNamespace testNs = (TestServiceNamespace) ns;
        Integer value = get(testNs.name, event.getPartitionId());
        if (value != null) {
            values.put(testNs, value);
        }
    }
    return values.isEmpty() ? null : new TestFragmentReplicationOperation(values).setServiceName(SERVICE_NAME);
}
Also used : ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) ServiceNamespace(com.hazelcast.internal.services.ServiceNamespace)

Example 23 with ServiceNamespace

use of com.hazelcast.internal.services.ServiceNamespace 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)

Example 24 with ServiceNamespace

use of com.hazelcast.internal.services.ServiceNamespace in project hazelcast by hazelcast.

the class MultiMapService method prepareReplicationOperation.

@Override
public Operation prepareReplicationOperation(PartitionReplicationEvent event, Collection<ServiceNamespace> namespaces) {
    if (namespaces.isEmpty()) {
        return null;
    }
    MultiMapPartitionContainer partitionContainer = partitionContainers[event.getPartitionId()];
    int replicaIndex = event.getReplicaIndex();
    Map<String, Map<Data, MultiMapValue>> map = createHashMap(namespaces.size());
    for (ServiceNamespace namespace : namespaces) {
        assert isKnownServiceNamespace(namespace) : namespace + " is not a MultiMapService namespace!";
        ObjectNamespace ns = (ObjectNamespace) namespace;
        MultiMapContainer container = partitionContainer.containerMap.get(ns.getObjectName());
        if (container == null) {
            continue;
        }
        if (container.getConfig().getTotalBackupCount() < replicaIndex) {
            continue;
        }
        map.put(ns.getObjectName(), container.getMultiMapValues());
    }
    return map.isEmpty() ? null : new MultiMapReplicationOperation(map).setServiceName(MultiMapService.SERVICE_NAME).setNodeEngine(nodeEngine);
}
Also used : ServiceNamespace(com.hazelcast.internal.services.ServiceNamespace) MultiMapReplicationOperation(com.hazelcast.multimap.impl.operations.MultiMapReplicationOperation) Map(java.util.Map) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) MapUtil.createHashMap(com.hazelcast.internal.util.MapUtil.createHashMap) ConcurrentMap(java.util.concurrent.ConcurrentMap) MapUtil.createConcurrentHashMap(com.hazelcast.internal.util.MapUtil.createConcurrentHashMap) ObjectNamespace(com.hazelcast.internal.services.ObjectNamespace) MigrationEndpoint(com.hazelcast.internal.partition.MigrationEndpoint)

Example 25 with ServiceNamespace

use of com.hazelcast.internal.services.ServiceNamespace in project hazelcast by hazelcast.

the class SplitBrainProtectionServiceImpl method getSplitBrainProtectionAwareService.

private SplitBrainProtectionAwareService getSplitBrainProtectionAwareService(Operation op) {
    Object service;
    if (op instanceof ServiceNamespaceAware) {
        ServiceNamespace serviceNamespace = ((ServiceNamespaceAware) op).getServiceNamespace();
        service = nodeEngine.getService(serviceNamespace.getServiceName());
    } else {
        service = op.getService();
    }
    if (service instanceof SplitBrainProtectionAwareService) {
        return (SplitBrainProtectionAwareService) service;
    }
    return null;
}
Also used : ServiceNamespaceAware(com.hazelcast.internal.services.ServiceNamespaceAware) SplitBrainProtectionAwareService(com.hazelcast.internal.services.SplitBrainProtectionAwareService) ServiceNamespace(com.hazelcast.internal.services.ServiceNamespace)

Aggregations

ServiceNamespace (com.hazelcast.internal.services.ServiceNamespace)40 InternalPartitionServiceImpl (com.hazelcast.internal.partition.impl.InternalPartitionServiceImpl)11 NonFragmentedServiceNamespace (com.hazelcast.internal.partition.NonFragmentedServiceNamespace)10 Operation (com.hazelcast.spi.impl.operationservice.Operation)9 ObjectNamespace (com.hazelcast.internal.services.ObjectNamespace)8 HashMap (java.util.HashMap)7 PartitionReplicaManager (com.hazelcast.internal.partition.impl.PartitionReplicaManager)6 ILogger (com.hazelcast.logging.ILogger)6 HazelcastInstance (com.hazelcast.core.HazelcastInstance)4 MigrationEndpoint (com.hazelcast.internal.partition.MigrationEndpoint)4 PartitionReplicaVersionManager (com.hazelcast.internal.partition.PartitionReplicaVersionManager)4 PartitionReplicationEvent (com.hazelcast.internal.partition.PartitionReplicationEvent)4 HashSet (java.util.HashSet)4 Address (com.hazelcast.cluster.Address)3 ChunkSupplier (com.hazelcast.internal.partition.ChunkSupplier)3 PartitionReplica (com.hazelcast.internal.partition.PartitionReplica)3 ParallelJVMTest (com.hazelcast.test.annotation.ParallelJVMTest)3 CachePartitionSegment (com.hazelcast.cache.impl.CachePartitionSegment)2 CacheService (com.hazelcast.cache.impl.CacheService)2 CacheConfig (com.hazelcast.config.CacheConfig)2