use of com.hazelcast.internal.partition.InternalPartition in project hazelcast by hazelcast.
the class MapLoaderTest method findOwnerAndReplicas.
private HazelcastInstance[] findOwnerAndReplicas(HazelcastInstance[] instances, String name) {
Node node = getNode(instances[0]);
InternalPartitionService partitionService = node.getPartitionService();
int partitionId = partitionService.getPartitionId(name);
InternalPartition partition = partitionService.getPartition(partitionId);
HazelcastInstance[] ownerAndReplicas = new HazelcastInstance[instances.length];
for (int i = 0; i < instances.length; i++) {
ownerAndReplicas[i] = getInstanceForAddress(instances, partition.getReplicaAddress(i));
}
return ownerAndReplicas;
}
use of com.hazelcast.internal.partition.InternalPartition in project hazelcast by hazelcast.
the class AdvancedClusterStateTest method partitionTable_shouldBeFrozen_whenMemberLeaves_inFrozenState.
@Test
public void partitionTable_shouldBeFrozen_whenMemberLeaves_inFrozenState() {
Config config = new Config();
TestHazelcastInstanceFactory factory = createHazelcastInstanceFactory(3);
HazelcastInstance[] instances = factory.newInstances(config);
HazelcastInstance hz1 = instances[0];
HazelcastInstance hz2 = instances[1];
HazelcastInstance hz3 = instances[2];
warmUpPartitions(instances);
waitAllForSafeState(instances);
final Address owner = getNode(hz1).getThisAddress();
int partitionId = getPartitionId(hz1);
changeClusterStateEventually(hz2, ClusterState.FROZEN);
terminateInstance(hz1);
final InternalPartition partition = getNode(hz2).getPartitionService().getPartition(partitionId);
assertTrueAllTheTime(new AssertTask() {
@Override
public void run() throws Exception {
assertEquals(owner, partition.getOwnerOrNull());
}
}, 3);
}
use of com.hazelcast.internal.partition.InternalPartition in project hazelcast by hazelcast.
the class AdvancedClusterStateTest method test_eitherClusterStateChange_orPartitionInitialization_shouldBeSuccessful.
@Test
public void test_eitherClusterStateChange_orPartitionInitialization_shouldBeSuccessful() throws Exception {
Config config = new Config();
TestHazelcastInstanceFactory factory = createHazelcastInstanceFactory(3);
HazelcastInstance[] instances = factory.newInstances(config);
HazelcastInstance hz1 = instances[0];
final HazelcastInstance hz2 = instances[1];
HazelcastInstance hz3 = instances[2];
final InternalPartitionService partitionService = getNode(hz1).getPartitionService();
final int initialPartitionStateVersion = partitionService.getPartitionStateVersion();
final ClusterState newState = ClusterState.PASSIVE;
final Future future = spawn(new Runnable() {
public void run() {
try {
changeClusterState(hz2, newState, initialPartitionStateVersion);
} catch (Exception ignored) {
}
}
});
partitionService.firstArrangement();
future.get(2, TimeUnit.MINUTES);
final ClusterState currentState = hz2.getCluster().getClusterState();
if (currentState == newState) {
// if cluster state changed then partition state version should be equal to initial version
assertEquals(initialPartitionStateVersion, partitionService.getPartitionStateVersion());
} else {
assertEquals(ClusterState.ACTIVE, currentState);
final InternalPartition partition = partitionService.getPartition(0, false);
if (partition.getOwnerOrNull() == null) {
// if partition assignment failed then partition state version should be equal to initial version
assertEquals(initialPartitionStateVersion, partitionService.getPartitionStateVersion());
} else {
// if cluster state change failed and partition assignment is done
// then partition state version should be some positive number
final int partitionStateVersion = partitionService.getPartitionStateVersion();
assertTrue("Version should be positive: " + partitionService, partitionStateVersion > 0);
}
}
}
use of com.hazelcast.internal.partition.InternalPartition in project hazelcast by hazelcast.
the class PartitionReplicaStateChecker method hasMissingReplicaOwners.
private boolean hasMissingReplicaOwners() {
if (!needsReplicaStateCheck()) {
return false;
}
int memberGroupsSize = partitionStateManager.getMemberGroupsSize();
int replicaCount = Math.min(InternalPartition.MAX_REPLICA_COUNT, memberGroupsSize);
ClusterServiceImpl clusterService = node.getClusterService();
ClusterState clusterState = clusterService.getClusterState();
boolean isClusterNotActive = (clusterState == ClusterState.FROZEN || clusterState == ClusterState.PASSIVE);
for (InternalPartition partition : partitionStateManager.getPartitions()) {
for (int index = 0; index < replicaCount; index++) {
Address address = partition.getReplicaAddress(index);
if (address == null) {
if (logger.isFinestEnabled()) {
logger.finest("Missing replica=" + index + " for partitionId=" + partition.getPartitionId());
}
return true;
}
if (clusterService.getMember(address) == null && (!isClusterNotActive || !clusterService.isMemberRemovedWhileClusterIsNotActive(address))) {
if (logger.isFinestEnabled()) {
logger.finest("Unknown replica owner= " + address + ", partitionId=" + partition.getPartitionId() + ", replica=" + index);
}
return true;
}
}
}
return false;
}
use of com.hazelcast.internal.partition.InternalPartition in project hazelcast by hazelcast.
the class CheckReplicaVersionTask method run.
@Override
public void run() {
int partitionId = getPartitionId();
int replicaIndex = this.replicaIndex;
InternalPartition partition = partitionService.getPartition(partitionId);
if (partition.isMigrating()) {
notifyCallback(false);
return;
}
Address target = partition.getReplicaAddress(replicaIndex);
if (target == null) {
notifyCallback(false);
return;
}
invokeCheckReplicaVersion(partitionId, replicaIndex, target);
}
Aggregations