use of com.hazelcast.cluster.ClusterState in project hazelcast by hazelcast.
the class HttpGetCommandProcessor method handleHealthcheck.
private void handleHealthcheck(HttpGetCommand command) {
Node node = textCommandService.getNode();
NodeState nodeState = node.getState();
ClusterServiceImpl clusterService = node.getClusterService();
ClusterState clusterState = clusterService.getClusterState();
int clusterSize = clusterService.getMembers().size();
InternalPartitionService partitionService = node.getPartitionService();
boolean memberStateSafe = partitionService.isMemberStateSafe();
boolean clusterSafe = memberStateSafe && !partitionService.hasOnGoingMigration();
long migrationQueueSize = partitionService.getMigrationQueueSize();
StringBuilder res = new StringBuilder();
res.append("Hazelcast::NodeState=").append(nodeState).append("\n");
res.append("Hazelcast::ClusterState=").append(clusterState).append("\n");
res.append("Hazelcast::ClusterSafe=").append(Boolean.toString(clusterSafe).toUpperCase()).append("\n");
res.append("Hazelcast::MigrationQueueSize=").append(migrationQueueSize).append("\n");
res.append("Hazelcast::ClusterSize=").append(clusterSize).append("\n");
command.setResponse(MIME_TEXT_PLAIN, stringToBytes(res.toString()));
}
use of com.hazelcast.cluster.ClusterState 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.cluster.ClusterState in project hazelcast by hazelcast.
the class GetClusterStateRequest method writeResponse.
@Override
public void writeResponse(ManagementCenterService mcs, JsonObject out) throws Exception {
ClusterState clusterState = mcs.getHazelcastInstance().getCluster().getClusterState();
JsonObject result = new JsonObject();
result.add("result", clusterState.toString());
out.add("result", result);
}
use of com.hazelcast.cluster.ClusterState 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.cluster.ClusterState in project hazelcast by hazelcast.
the class PartitionStateManager method initializePartitionAssignments.
boolean initializePartitionAssignments(Set<Address> excludedAddresses) {
if (!isPartitionAssignmentAllowed()) {
return false;
}
Collection<MemberGroup> memberGroups = createMemberGroups(excludedAddresses);
if (memberGroups.isEmpty()) {
logger.warning("No member group is available to assign partition ownership...");
return false;
}
logger.info("Initializing cluster partition table arrangement...");
Address[][] newState = partitionStateGenerator.arrange(memberGroups, partitions);
if (newState.length != partitionCount) {
throw new HazelcastException("Invalid partition count! " + "Expected: " + partitionCount + ", Actual: " + newState.length);
}
// increment state version to make fail cluster state transaction
// if it's started and not locked the state yet.
stateVersion.incrementAndGet();
ClusterState clusterState = node.getClusterService().getClusterState();
if (clusterState != ClusterState.ACTIVE) {
// cluster state is either changed or locked, decrement version back and fail.
stateVersion.decrementAndGet();
logger.warning("Partitions can't be assigned since cluster-state= " + clusterState);
return false;
}
for (int partitionId = 0; partitionId < partitionCount; partitionId++) {
InternalPartitionImpl partition = partitions[partitionId];
Address[] replicas = newState[partitionId];
partition.setReplicaAddresses(replicas);
}
setInitialized();
return true;
}
Aggregations