use of com.hazelcast.internal.partition.impl.InternalPartitionImpl in project hazelcast by hazelcast.
the class InternalPartitionImplConstructorTest method testConstructor.
@Test
public void testConstructor() throws Exception {
PartitionReplica local = new PartitionReplica(new Address("172.16.16.1", 4223), UuidUtil.newUnsecureUUID());
PartitionReplica[] replicas = new PartitionReplica[] { new PartitionReplica(new Address("127.0.0.1", 2342), UuidUtil.newUnsecureUUID()) };
InternalPartition partition = new InternalPartitionImpl(42, local, replicas, 1, null);
InternalPartitionImplConstructor constructor = new InternalPartitionImplConstructor(InternalPartitionImpl.class);
InternalPartition clonedPartition = (InternalPartition) constructor.createNew(partition);
assertEquals(partition.getPartitionId(), clonedPartition.getPartitionId());
assertEquals(partition.version(), clonedPartition.version());
assertEquals(partition.getOwnerOrNull(), clonedPartition.getOwnerOrNull());
assertEquals(partition.getReplicaAddress(0), clonedPartition.getReplicaAddress(0));
assertEquals(partition.getReplica(0), clonedPartition.getReplica(0));
assertEquals(partition.getReplicaIndex(replicas[0]), clonedPartition.getReplicaIndex(replicas[0]));
}
use of com.hazelcast.internal.partition.impl.InternalPartitionImpl in project hazelcast by hazelcast.
the class PartitionReplicaConstructorTest method testConstructor.
@Test
public void testConstructor() {
HazelcastInstance hz = createHazelcastInstance();
warmUpPartitions(hz);
InternalPartitionService partitionService = getNode(hz).getPartitionService();
InternalPartition[] partitions = partitionService.getInternalPartitions();
InternalPartitionImpl partition = (InternalPartitionImpl) partitions[0];
PartitionReplica replica = partition.getReplica(0);
PartitionReplicaConstructor constructor = new PartitionReplicaConstructor(PartitionReplica.class);
PartitionReplica clonedReplica = (PartitionReplica) constructor.createNew(replica);
assertEquals(replica.address(), clonedReplica.address());
assertEquals(replica.uuid(), clonedReplica.uuid());
}
use of com.hazelcast.internal.partition.impl.InternalPartitionImpl in project hazelcast by hazelcast.
the class StaleReadDuringMigrationTest method invokeOperation.
private InternalCompletableFuture<Boolean> invokeOperation(final Config config) {
final TestHazelcastInstanceFactory factory = createHazelcastInstanceFactory(1);
final HazelcastInstance instance = factory.newHazelcastInstance(config);
warmUpPartitions(instance);
final int partitionId = 0;
final InternalPartitionServiceImpl partitionService = (InternalPartitionServiceImpl) getPartitionService(instance);
final InternalPartitionImpl partition = (InternalPartitionImpl) partitionService.getPartition(partitionId);
partition.setMigrating();
final OperationServiceImpl operationService = getOperationService(instance);
final InvocationBuilder invocationBuilder = operationService.createInvocationBuilder(InternalPartitionService.SERVICE_NAME, new DummyOperation(), partitionId);
return invocationBuilder.invoke();
}
use of com.hazelcast.internal.partition.impl.InternalPartitionImpl in project hazelcast by hazelcast.
the class PartitionTableViewTest method test_createUsingInternalPartitions.
@Test
public void test_createUsingInternalPartitions() throws Exception {
Address[][] addresses = createRandomAddresses();
InternalPartition[] partitions = new InternalPartition[addresses.length];
for (int i = 0; i < partitions.length; i++) {
partitions[i] = new InternalPartitionImpl(i, null, null, addresses[i]);
}
PartitionTableView table = new PartitionTableView(partitions, 0);
assertEquals(partitions.length, table.getLength());
for (int i = 0; i < addresses.length; i++) {
for (int j = 0; j < InternalPartition.MAX_REPLICA_COUNT; j++) {
assertEquals(partitions[i].getReplicaAddress(j), table.getAddress(i, j));
}
}
}
use of com.hazelcast.internal.partition.impl.InternalPartitionImpl in project hazelcast by hazelcast.
the class PartitionBackupReplicaAntiEntropyOperation method run.
@Override
public void run() {
if (!isNodeStartCompleted()) {
response = false;
return;
}
InternalPartitionServiceImpl partitionService = getService();
int partitionId = getPartitionId();
int replicaIndex = getReplicaIndex();
InternalPartitionImpl partition = partitionService.getPartitionStateManager().getPartitionImpl(partitionId);
int currentReplicaIndex = partition.getReplicaIndex(PartitionReplica.from(getNodeEngine().getLocalMember()));
ILogger logger = getLogger();
if (replicaIndex != currentReplicaIndex) {
logger.fine("Anti-entropy operation for partitionId=" + getPartitionId() + ", replicaIndex=" + getReplicaIndex() + " is received, but this node is not the expected backup replica!" + " Current replicaIndex=" + currentReplicaIndex);
response = false;
return;
}
Address ownerAddress = partition.getOwnerOrNull();
if (!getCallerAddress().equals(ownerAddress)) {
logger.fine("Anti-entropy operation for partitionId=" + getPartitionId() + ", replicaIndex=" + getReplicaIndex() + " is received from " + getCallerAddress() + ", but it's not the known primary replica owner: " + ownerAddress);
response = false;
return;
}
PartitionReplicaManager replicaManager = partitionService.getReplicaManager();
replicaManager.retainNamespaces(partitionId, versions.keySet());
if (logger.isFinestEnabled()) {
logger.finest("Retained namespaces for partitionId=" + partitionId + ", replicaIndex=" + replicaIndex + ". Namespaces=" + replicaManager.getNamespaces(partitionId));
}
Iterator<Map.Entry<ServiceNamespace, Long>> iter = versions.entrySet().iterator();
while (iter.hasNext()) {
Map.Entry<ServiceNamespace, Long> entry = iter.next();
ServiceNamespace ns = entry.getKey();
long primaryVersion = entry.getValue();
long[] currentVersions = replicaManager.getPartitionReplicaVersions(partitionId, ns);
long currentVersion = currentVersions[replicaIndex - 1];
if (replicaManager.isPartitionReplicaVersionDirty(partitionId, ns) || currentVersion != primaryVersion) {
logBackupVersionMismatch(ns, currentVersion, primaryVersion);
continue;
}
iter.remove();
}
if (!versions.isEmpty()) {
replicaManager.triggerPartitionReplicaSync(partitionId, versions.keySet(), replicaIndex);
response = false;
}
}
Aggregations