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;
}
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);
}
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();
}
}
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);
}
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;
}
Aggregations