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

HDDS-8850. ReplicationManager: Add metrics for partial replication / reconstruction and cluster limit #4917

Merged
merged 5 commits into from
Jun 17, 2023
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ public class ECUnderReplicationHandler implements UnhealthyReplicationHandler {
private final PlacementPolicy containerPlacement;
private final long currentContainerSize;
private final ReplicationManager replicationManager;
private final ReplicationManagerMetrics metrics;

ECUnderReplicationHandler(final PlacementPolicy containerPlacement,
final ConfigurationSource conf, ReplicationManager replicationManager) {
Expand All @@ -72,6 +73,7 @@ public class ECUnderReplicationHandler implements UnhealthyReplicationHandler {
.getStorageSize(ScmConfigKeys.OZONE_SCM_CONTAINER_SIZE,
ScmConfigKeys.OZONE_SCM_CONTAINER_SIZE_DEFAULT, StorageUnit.BYTES);
this.replicationManager = replicationManager;
this.metrics = replicationManager.getMetrics();
}

private boolean validatePlacement(List<DatanodeDetails> replicaNodes,
Expand Down Expand Up @@ -281,6 +283,7 @@ private int processMissingIndexes(
(ECReplicationConfig)container.getReplicationConfig();
List<Integer> missingIndexes = replicaCount.unavailableIndexes(true);
final int expectedTargetCount = missingIndexes.size();
boolean recoveryIsCritical = expectedTargetCount == repConfig.getParity();
if (expectedTargetCount == 0) {
return 0;
}
Expand All @@ -307,7 +310,7 @@ private int processMissingIndexes(
// selection allows partial recovery
0 < targetCount && targetCount < expectedTargetCount &&
// recovery is not yet critical
expectedTargetCount < repConfig.getParity()) {
!recoveryIsCritical) {

// check if placement exists when overloaded nodes are not excluded
final List<DatanodeDetails> targetsMaybeOverloaded = getTargetDatanodes(
Expand All @@ -319,7 +322,7 @@ private int processMissingIndexes(
+ " target nodes to be fully reconstructed, but {} selected"
+ " nodes are currently overloaded.",
container.getContainerID(), expectedTargetCount, overloadedCount);

metrics.incrECPartialReconstructionSkippedTotal();
throw new InsufficientDatanodesException(expectedTargetCount,
targetCount);
}
Expand Down Expand Up @@ -369,6 +372,11 @@ private int processMissingIndexes(
LOG.debug("Insufficient nodes were returned from the placement policy" +
" to fully reconstruct container {}. Requested {} received {}",
container.getContainerID(), expectedTargetCount, targetCount);
if (hasOverloaded && recoveryIsCritical) {
metrics.incrECPartialReconstructionCriticalTotal();
} else {
metrics.incrEcPartialReconstructionNoneOverloadedTotal();
}
throw new InsufficientDatanodesException(expectedTargetCount,
targetCount);
}
Expand Down Expand Up @@ -454,6 +462,7 @@ private int processDecommissioningIndexes(
" to fully replicate the decommission indexes for container {}." +
" Requested {} received {}", container.getContainerID(),
decomIndexes.size(), selectedDatanodes.size());
metrics.incrEcPartialReplicationForOutOfServiceReplicasTotal();
throw new InsufficientDatanodesException(decomIndexes.size(),
selectedDatanodes.size());
}
Expand Down Expand Up @@ -538,6 +547,7 @@ private int processMaintenanceOnlyIndexes(
" to fully replicate the maintenance indexes for container {}." +
" Requested {} received {}", container.getContainerID(),
maintIndexes.size(), targets.size());
metrics.incrEcPartialReplicationForOutOfServiceReplicasTotal();
throw new InsufficientDatanodesException(maintIndexes.size(),
targets.size());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ public abstract class MisReplicationHandler implements
private final PlacementPolicy containerPlacement;
private final long currentContainerSize;
private final ReplicationManager replicationManager;
private final ReplicationManagerMetrics metrics;

public MisReplicationHandler(
final PlacementPolicy containerPlacement,
Expand All @@ -65,6 +66,7 @@ public MisReplicationHandler(
ScmConfigKeys.OZONE_SCM_CONTAINER_SIZE,
ScmConfigKeys.OZONE_SCM_CONTAINER_SIZE_DEFAULT, StorageUnit.BYTES);
this.replicationManager = replicationManager;
this.metrics = replicationManager.getMetrics();
}

protected ReplicationManager getReplicationManager() {
Expand Down Expand Up @@ -164,6 +166,11 @@ public int processAndSendCommands(

int found = targetDatanodes.size();
if (found < requiredNodes) {
if (container.getReplicationType() == HddsProtos.ReplicationType.EC) {
metrics.incrEcPartialReplicationForMisReplicationTotal();
} else {
metrics.incrPartialReplicationForMisReplicationTotal();
}
LOG.warn("Placement Policy {} found only {} nodes for Container: {}," +
" number of required nodes: {}, usedNodes : {}",
containerPlacement.getClass(), found,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ public class RatisUnderReplicationHandler
private final PlacementPolicy placementPolicy;
private final long currentContainerSize;
private final ReplicationManager replicationManager;
private final ReplicationManagerMetrics metrics;

public RatisUnderReplicationHandler(final PlacementPolicy placementPolicy,
final ConfigurationSource conf,
Expand All @@ -64,6 +65,7 @@ public RatisUnderReplicationHandler(final PlacementPolicy placementPolicy,
.getStorageSize(ScmConfigKeys.OZONE_SCM_CONTAINER_SIZE,
ScmConfigKeys.OZONE_SCM_CONTAINER_SIZE_DEFAULT, StorageUnit.BYTES);
this.replicationManager = replicationManager;
this.metrics = replicationManager.getMetrics();
}

/**
Expand Down Expand Up @@ -128,6 +130,7 @@ public int processAndSendCommands(
"additional replicas needed: {}",
containerInfo, targetDatanodes.size(),
replicaCount.additionalReplicaNeeded());
metrics.incrPartialReplicationTotal();
throw new InsufficientDatanodesException(
replicaCount.additionalReplicaNeeded(), targetDatanodes.size());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,10 @@ public final class ReplicationManagerMetrics implements MetricsSource {
" due to the configured limit.")
private MutableCounterLong inflightDeletionSkippedTotal;

@Metric("Number of times under replication processing has paused due to" +
" reaching the cluster inflight replication limit.")
private MutableCounterLong pendingReplicationLimitReachedTotal;

private MetricsRegistry registry;

private final ReplicationManager replicationManager;
Expand Down Expand Up @@ -183,6 +187,34 @@ public final class ReplicationManagerMetrics implements MetricsSource {
@Metric("Number of EC replicas scheduled for delete which timed out.")
private MutableCounterLong ecReplicaDeleteTimeoutTotal;

@Metric("Number of times partial EC reconstruction was needed due to " +
"overloaded nodes, but skipped as there was still sufficient redundancy.")
private MutableCounterLong ecPartialReconstructionSkippedTotal;

@Metric("Number of times partial EC reconstruction was used due to " +
"insufficient nodes available and reconstruction was critical.")
private MutableCounterLong ecPartialReconstructionCriticalTotal;

@Metric("Number of times partial EC reconstruction was used due to " +
"insufficient nodes available and with no overloaded nodes.")
private MutableCounterLong ecPartialReconstructionNoneOverloadedTotal;

@Metric("Number of times EC decommissioning or entering maintenance mode " +
"replicas were not all replicated due to insufficient nodes available.")
private MutableCounterLong ecPartialReplicationForOutOfServiceReplicasTotal;

@Metric("Number of times partial Ratis replication occurred due to " +
"insufficient nodes available.")
private MutableCounterLong partialReplicationTotal;

@Metric("Number of times partial replication occurred to fix a " +
"mis-replicated ratis container due to insufficient nodes available.")
private MutableCounterLong partialReplicationForMisReplicationTotal;

@Metric("Number of times partial replication occurred to fix a " +
"mis-replicated EC container due to insufficient nodes available.")
private MutableCounterLong ecPartialReplicationForMisReplicationTotal;

@Metric("NUmber of Reconstruct EC Container commands that could not be sent "
+ "due to the pending commands on the target datanode")
private MutableCounterLong ecReconstructionCmdsDeferredTotal;
Expand Down Expand Up @@ -272,6 +304,14 @@ public void getMetrics(MetricsCollector collector, boolean all) {
ecReconstructionCmdsDeferredTotal.snapshot(builder, all);
deleteContainerCmdsDeferredTotal.snapshot(builder, all);
replicateContainerCmdsDeferredTotal.snapshot(builder, all);
pendingReplicationLimitReachedTotal.snapshot(builder, all);
ecPartialReconstructionSkippedTotal.snapshot(builder, all);
ecPartialReconstructionCriticalTotal.snapshot(builder, all);
ecPartialReconstructionNoneOverloadedTotal.snapshot(builder, all);
ecPartialReplicationForOutOfServiceReplicasTotal.snapshot(builder, all);
partialReplicationTotal.snapshot(builder, all);
ecPartialReplicationForMisReplicationTotal.snapshot(builder, all);
partialReplicationForMisReplicationTotal.snapshot(builder, all);
}

public void unRegister() {
Expand Down Expand Up @@ -505,4 +545,68 @@ public long getReplicateContainerCmdsDeferredTotal() {
return replicateContainerCmdsDeferredTotal.value();
}

public void incrPendingReplicationLimitReachedTotal() {
this.pendingReplicationLimitReachedTotal.incr();
}

public long getPendingReplicationLimitReachedTotal() {
return pendingReplicationLimitReachedTotal.value();
}

public long getECPartialReconstructionSkippedTotal() {
return ecPartialReconstructionSkippedTotal.value();
}

public void incrECPartialReconstructionSkippedTotal() {
this.ecPartialReconstructionSkippedTotal.incr();
}

public long getECPartialReconstructionCriticalTotal() {
return ecPartialReconstructionCriticalTotal.value();
}

public void incrECPartialReconstructionCriticalTotal() {
this.ecPartialReconstructionCriticalTotal.incr();
}

public long getEcPartialReconstructionNoneOverloadedTotal() {
return ecPartialReconstructionNoneOverloadedTotal.value();
}

public void incrEcPartialReconstructionNoneOverloadedTotal() {
this.ecPartialReconstructionNoneOverloadedTotal.incr();
}

public long getEcPartialReplicationForOutOfServiceReplicasTotal() {
return ecPartialReplicationForOutOfServiceReplicasTotal.value();
}

public void incrEcPartialReplicationForOutOfServiceReplicasTotal() {
this.ecPartialReplicationForOutOfServiceReplicasTotal.incr();
}

public long getPartialReplicationTotal() {
return partialReplicationTotal.value();
}

public void incrPartialReplicationTotal() {
this.partialReplicationTotal.incr();
}

public void incrEcPartialReplicationForMisReplicationTotal() {
this.ecPartialReplicationForMisReplicationTotal.incr();
}

public long getEcPartialReplicationForMisReplicationTotal() {
return this.ecPartialReplicationForMisReplicationTotal.value();
}

public void incrPartialReplicationForMisReplicationTotal() {
this.partialReplicationForMisReplicationTotal.incr();
}

public long getPartialReplicationForMisReplicationTotal() {
return this.partialReplicationForMisReplicationTotal.value();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,8 @@ public void processAll(ReplicationQueue queue) {
inflightOperationLimitReached(replicationManager, inflightLimit)) {
LOG.info("The maximum number of pending replicas ({}) are scheduled. " +
"Ending the iteration.", inflightLimit);
replicationManager
.getMetrics().incrPendingReplicationLimitReachedTotal();
break;
}
HealthResult healthResult =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
import static java.util.Collections.singletonList;
import static org.apache.hadoop.hdds.protocol.proto.HddsProtos.NodeOperationalState.IN_MAINTENANCE;
import static org.apache.hadoop.hdds.protocol.proto.HddsProtos.NodeOperationalState.IN_SERVICE;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertThrows;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyInt;
Expand Down Expand Up @@ -216,6 +217,8 @@ public void commandsForFewerThanRequiredNodes() throws IOException {
assertThrows(InsufficientDatanodesException.class,
() -> testMisReplication(availableReplicas, Collections.emptyList(),
0, 2, 1));
assertEquals(1,
getMetrics().getEcPartialReplicationForMisReplicationTotal());
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ public class TestECUnderReplicationHandler {
private ContainerInfo container;
private NodeManager nodeManager;
private ReplicationManager replicationManager;
private ReplicationManagerMetrics metrics;
private OzoneConfiguration conf;
private PlacementPolicy policy;
private static final int DATA = 3;
Expand Down Expand Up @@ -137,6 +138,8 @@ public NodeStatus getNodeStatus(DatanodeDetails dd) {
new ReplicationManager.ReplicationManagerConfiguration();
when(replicationManager.getConfig())
.thenReturn(rmConf);
metrics = ReplicationManagerMetrics.create(replicationManager);
when(replicationManager.getMetrics()).thenReturn(metrics);

when(replicationManager.getNodeStatus(any(DatanodeDetails.class)))
.thenAnswer(invocation -> {
Expand Down Expand Up @@ -200,6 +203,7 @@ void defersNonCriticalPartialReconstruction(String rep) throws IOException {
assertEquals(e.getRequiredNodes() - excluded.size(), e.getAvailableNodes());
verify(replicationManager, never())
.sendThrottledReconstructionCommand(any(), any());
assertEquals(1, metrics.getECPartialReconstructionSkippedTotal());
}

private static UnderReplicatedHealthResult mockUnderReplicated(
Expand Down Expand Up @@ -258,6 +262,7 @@ void performsCriticalPartialReconstruction(String rep) throws IOException {
assertEquals(e.getRequiredNodes() - excluded.size(), e.getAvailableNodes());
verify(replicationManager, times(1))
.sendThrottledReconstructionCommand(any(), any());
assertEquals(1, metrics.getECPartialReconstructionCriticalTotal());
}

@Test
Expand Down Expand Up @@ -711,6 +716,7 @@ public void testPartialReconstructionIfNotEnoughNodes() {
ReconstructECContainersCommand cmd = (ReconstructECContainersCommand)
commandsSent.iterator().next().getValue();
assertEquals(1, cmd.getTargetDatanodes().size());
assertEquals(1, metrics.getEcPartialReconstructionNoneOverloadedTotal());
}

@Test
Expand Down Expand Up @@ -759,6 +765,8 @@ public void testPartialDecommissionIfNotEnoughNodes() {
SCMCommand<?> cmd = commandsSent.iterator().next().getValue();
assertEquals(
SCMCommandProto.Type.replicateContainerCommand, cmd.getType());
assertEquals(1,
metrics.getEcPartialReplicationForOutOfServiceReplicasTotal());
}

@Test
Expand All @@ -782,6 +790,11 @@ public void testPartialDecommissionOverloadedNodes() {
SCMCommand<?> cmd = commandsSent.iterator().next().getValue();
assertEquals(
SCMCommandProto.Type.replicateContainerCommand, cmd.getType());
// The partial recovery here is due to overloaded nodes, not insufficient
// nodes. The "deferred" metric should be updated when all sources are
// overloaded.
assertEquals(0,
metrics.getEcPartialReplicationForOutOfServiceReplicasTotal());
}

@Test
Expand All @@ -807,6 +820,8 @@ public void testPartialMaintenanceIfNotEnoughNodes() {
SCMCommand<?> cmd = commandsSent.iterator().next().getValue();
assertEquals(
SCMCommandProto.Type.replicateContainerCommand, cmd.getType());
assertEquals(1,
metrics.getEcPartialReplicationForOutOfServiceReplicasTotal());
}

@Test
Expand All @@ -831,6 +846,11 @@ public void testPartialMaintenanceOverloadedNodes() {
SCMCommand<?> cmd = commandsSent.iterator().next().getValue();
assertEquals(
SCMCommandProto.Type.replicateContainerCommand, cmd.getType());
// The partial recovery here is due to overloaded nodes, not insufficient
// nodes. The "deferred" metric should be updated when all sources are
// overloaded.
assertEquals(0,
metrics.getEcPartialReplicationForOutOfServiceReplicasTotal());
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ public abstract class TestMisReplicationHandler {
private Set<Pair<DatanodeDetails, SCMCommand<?>>> commandsSent;
private final AtomicBoolean throwThrottledException =
new AtomicBoolean(false);
private ReplicationManagerMetrics metrics;

protected void setup(ReplicationConfig repConfig)
throws NodeNotFoundException, CommandTargetOverloadedException,
Expand All @@ -89,6 +90,8 @@ protected void setup(ReplicationConfig repConfig)
conf.getObject(ReplicationManagerConfiguration.class);
Mockito.when(replicationManager.getConfig())
.thenReturn(rmConf);
metrics = ReplicationManagerMetrics.create(replicationManager);
Mockito.when(replicationManager.getMetrics()).thenReturn(metrics);

commandsSent = new HashSet<>();
ReplicationTestUtil.mockRMSendDatanodeCommand(
Expand All @@ -107,6 +110,10 @@ protected ReplicationManager getReplicationManager() {
return replicationManager;
}

protected ReplicationManagerMetrics getMetrics() {
return metrics;
}

protected void setThrowThrottledException(boolean showThrow) {
throwThrottledException.set(showThrow);
}
Expand Down