Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[apache/helix] --> Update logic for metric calculation when replica is set to ANY_LIVEINSTANCE #2804

Merged
merged 1 commit into from
Jun 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -272,17 +272,9 @@ public void updateResourceState(ExternalView externalView, IdealState idealState
long numOfPartitionWithTopState = 0;

Set<String> partitions = idealState.getPartitionSet();
int replica;
try {
replica = Integer.valueOf(idealState.getReplicas());
} catch (NumberFormatException e) {
_logger.info("Unspecified replica count for {}, skip updating the ResourceMonitor Mbean: {}", _resourceName,
idealState.getReplicas());
return;
} catch (Exception ex) {
_logger.warn("Failed to get replica count for {}, cannot update the ResourceMonitor Mbean.", _resourceName);
return;
}

// returns -1 when replica is set to ANY_LIVEINSTANCE.
int replica = idealState.getReplicaCount(-1);

int minActiveReplica = idealState.getMinActiveReplicas();
minActiveReplica = (minActiveReplica >= 0) ? minActiveReplica : replica;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@

import com.google.common.collect.ImmutableMap;
import org.apache.helix.TestHelper;
import org.apache.helix.model.ResourceConfig;
import org.apache.helix.zookeeper.datamodel.ZNRecord;
import org.apache.helix.model.BuiltInStateModelDefinitions;
import org.apache.helix.model.ExternalView;
Expand Down Expand Up @@ -220,6 +221,26 @@ public void testReportData() throws JMException {
monitor.setRebalanceState(ResourceMonitor.RebalanceStatus.INTERMEDIATE_STATE_CAL_FAILED);
Assert.assertEquals(monitor.getRebalanceState(),
ResourceMonitor.RebalanceStatus.INTERMEDIATE_STATE_CAL_FAILED.name());

// test when replica is set to ANY_LIVEINSTANCE and all instances are taken offline.
idealState.setReplicas(ResourceConfig.ResourceConfigConstants.ANY_LIVEINSTANCE.name());

for (int i = 0; i < _partitions; i++) {
String partition = _dbName + "_" + i;
Map<String, String> externalViewStateMap = externalView.getStateMap(partition);
for (String key : externalViewStateMap.keySet()) {
if (externalViewStateMap.get(key).equalsIgnoreCase("MASTER")) {
externalViewStateMap.put(key, "OFFLINE");
}
}
externalView.setStateMap(partition, externalViewStateMap);
}

monitor.updateResourceState(externalView, idealState, stateModelDef);

Assert.assertEquals(monitor.getMissingTopStatePartitionGauge(), _partitions);
Assert.assertEquals(monitor.getMissingReplicaPartitionGauge(), 0);
Assert.assertEquals(monitor.getMissingMinActiveReplicaPartitionGauge(), 0);
} finally {
// Has to unregister this monitor to clean up. Otherwise, later tests may be affected and fail.
monitor.unregister();
Expand Down
Loading