diff --git a/hadoop-hdds/server-scm/src/main/java/org/apache/hadoop/hdds/scm/container/replication/ECUnderReplicationHandler.java b/hadoop-hdds/server-scm/src/main/java/org/apache/hadoop/hdds/scm/container/replication/ECUnderReplicationHandler.java index 1b08182e01ed..7f97b2db08a4 100644 --- a/hadoop-hdds/server-scm/src/main/java/org/apache/hadoop/hdds/scm/container/replication/ECUnderReplicationHandler.java +++ b/hadoop-hdds/server-scm/src/main/java/org/apache/hadoop/hdds/scm/container/replication/ECUnderReplicationHandler.java @@ -31,7 +31,6 @@ import java.util.Map; import java.util.Set; import java.util.stream.Collectors; -import org.apache.commons.lang3.tuple.Pair; import org.apache.hadoop.hdds.client.ECReplicationConfig; import org.apache.hadoop.hdds.conf.ConfigurationSource; import org.apache.hadoop.hdds.conf.StorageUnit; @@ -144,15 +143,11 @@ public int processAndSendCommands( } } - Map> sources = - filterSources(replicas, deletionInFlight); - List availableSourceNodes = - sources.values().stream().map(Pair::getLeft) - .map(ContainerReplica::getDatanodeDetails) - .filter(datanodeDetails -> - datanodeDetails.getPersistedOpState() == - HddsProtos.NodeOperationalState.IN_SERVICE) - .collect(Collectors.toList()); + Map sources = filterSources(replicas, deletionInFlight); + List availableSourceNodes = sources.values().stream().map(SourceReplica::replica) + .map(ContainerReplica::getDatanodeDetails).filter(datanodeDetails -> + datanodeDetails.getPersistedOpState() == HddsProtos.NodeOperationalState.IN_SERVICE) + .collect(Collectors.toList()); try { IOException firstException = null; @@ -229,7 +224,7 @@ public int processAndSendCommands( return commandsSent; } - private Map> filterSources( + private Map filterSources( Set replicas, List deletionInFlight) { return replicas.stream().filter(r -> r .getState() == State.CLOSED) @@ -239,25 +234,22 @@ private Map> filterSources( .filter(r -> !deletionInFlight.contains(r.getDatanodeDetails())) .map(r -> { try { - return Pair.of(r, - replicationManager.getNodeStatus(r.getDatanodeDetails())); + return new SourceReplica(r, replicationManager.getNodeStatus(r.getDatanodeDetails())); } catch (NodeNotFoundException e) { throw new IllegalStateException("Unable to find NodeStatus for " + r.getDatanodeDetails(), e); } }) - .filter(pair -> pair.getRight().isHealthy()) + .filter(source -> source.nodeStatus().isHealthy()) // If there are multiple nodes online for a given index, we just // pick any IN_SERVICE one. At the moment, the input streams cannot // handle multiple replicas for the same index, so if we passed them // all through they would not get used anyway. // If neither of the nodes are in service, we just pass one through, // as it will be decommission or maintenance. - .collect(Collectors.toMap( - pair -> pair.getLeft().getReplicaIndex(), - pair -> pair, - (p1, p2) -> { - if (p1.getRight().getOperationalState() == IN_SERVICE) { + .collect(Collectors.toMap(source -> source.replica().getReplicaIndex(), + source -> source, (p1, p2) -> { + if (p1.nodeStatus().getOperationalState() == IN_SERVICE) { return p1; } else { return p2; @@ -272,7 +264,7 @@ private Map> filterSources( */ private int processMissingIndexes( ECContainerReplicaCount replicaCount, Map> sources, + SourceReplica> sources, List availableSourceNodes, List excludedNodes, List usedNodes) throws IOException { @@ -299,7 +291,7 @@ private int processMissingIndexes( private int processReconstruction( ECContainerReplicaCount replicaCount, List missingIndexes, - Map> sources, + Map sources, List availableSourceNodes, List excludedNodes, List usedNodes) throws IOException { @@ -375,13 +367,11 @@ private int processReconstruction( // If we have more than the required number of data blocks, we can // prefer IN_SERVICE nodes to avoid overloading decommissioning nodes. - List> sortedSources = + List sortedSources = sources.values().stream() .sorted((p1, p2) -> { - boolean p1InService = - p1.getRight().getOperationalState() == IN_SERVICE; - boolean p2InService = - p2.getRight().getOperationalState() == IN_SERVICE; + boolean p1InService = p1.nodeStatus().getOperationalState() == IN_SERVICE; + boolean p2InService = p2.nodeStatus().getOperationalState() == IN_SERVICE; if (p1InService && !p2InService) { return -1; } @@ -393,24 +383,24 @@ private int processReconstruction( .collect(Collectors.toList()); int inServiceCount = 0; - for (Pair src : sortedSources) { - if (src.getRight().getOperationalState() == IN_SERVICE) { + for (SourceReplica src : sortedSources) { + if (src.nodeStatus().getOperationalState() == IN_SERVICE) { inServiceCount++; } } - for (Pair src : sortedSources) { + for (SourceReplica src : sortedSources) { // If we have enough in-service nodes to fulfill the reconstruction // requirements, we skip any out-of-service nodes. if (inServiceCount >= repConfig.getData() && - src.getRight().getOperationalState() != IN_SERVICE) { + src.nodeStatus().getOperationalState() != IN_SERVICE) { continue; } sourceDatanodesWithIndex.add( new ReconstructECContainersCommand .DatanodeDetailsAndReplicaIndex( - src.getLeft().getDatanodeDetails(), - src.getLeft().getReplicaIndex())); + src.replica().getDatanodeDetails(), + src.replica().getReplicaIndex())); } final ReconstructECContainersCommand reconstructionCommand = @@ -450,12 +440,9 @@ private int processReconstruction( return commandsSent; } - private static boolean hasSufficientSourcesForDecommissionReconstruction( - Map> sources, - Set decomIndexes, - int requiredDataSources) { - long nonDecommissionSourceCount = sources.keySet().stream() - .filter(index -> !decomIndexes.contains(index)) + private static boolean hasSufficientSourcesForDecommissionReconstruction(Map sources, + Set decomIndexes, int requiredDataSources) { + long nonDecommissionSourceCount = sources.keySet().stream().filter(index -> !decomIndexes.contains(index)) .count(); return nonDecommissionSourceCount >= requiredDataSources; } @@ -478,7 +465,7 @@ private List getTargetDatanodes( */ private int processDecommissioningIndexes( ECContainerReplicaCount replicaCount, - Map> sources, + Map sources, List availableSourceNodes, List excludedNodes, List usedNodes) throws IOException { @@ -489,12 +476,10 @@ private int processDecommissioningIndexes( } if (replicationManager.getConfig().isEcDecommissionReconstructionEnabled()) { - ECReplicationConfig repConfig = - (ECReplicationConfig) container.getReplicationConfig(); + ECReplicationConfig repConfig = (ECReplicationConfig) container.getReplicationConfig(); for (Integer index : decomIndexes) { - Pair source = sources.get(index); - if (source == null || !replicationManager.isNodeHighlyLoaded( - source.getLeft().getDatanodeDetails())) { + SourceReplica source = sources.get(index); + if (source == null || !replicationManager.isNodeHighlyLoaded(source.replica().getDatanodeDetails())) { continue; } if (!hasSufficientSourcesForDecommissionReconstruction( @@ -513,9 +498,8 @@ private int processDecommissioningIndexes( metrics.incrEcReconstructionGlobalLimitReachedTotal(); break; } - LOG.info("Source node {} is highly loaded, switching to " - + "reconstruction for decommissioning container {}", - source.getLeft().getDatanodeDetails(), container.containerID()); + LOG.info("Source node {} is highly loaded, switching to " + "reconstruction for decommissioning container {}", + source.replica().getDatanodeDetails(), container.containerID()); try { int commandsSent = processReconstruction(replicaCount, new ArrayList<>(decomIndexes), sources, availableSourceNodes, @@ -567,19 +551,18 @@ private int processDecommissioningIndexes( int commandsSent = 0; CommandTargetOverloadedException overloadedException = null; for (Integer decomIndex : decomIndexes) { - Pair source = sources.get(decomIndex); + SourceReplica source = sources.get(decomIndex); if (source == null) { LOG.warn("Cannot find source replica for decommissioning index " + "{} in container {}", decomIndex, container.containerID()); continue; } - ContainerReplica sourceReplica = source.getLeft(); + ContainerReplica sourceReplica = source.replica(); if (!iterator.hasNext()) { LOG.warn("Couldn't find enough targets. Available source" + " nodes: {}, the target nodes: {}, excluded nodes: {}," + " usedNodes: {}, and the decommission indexes: {}", - sources.values().stream() - .map(Pair::getLeft).collect(Collectors.toSet()), + sources.values().stream().map(SourceReplica::replica).collect(Collectors.toSet()), selectedDatanodes, excludedNodes, usedNodes, decomIndexes); break; } @@ -623,7 +606,7 @@ private int processDecommissioningIndexes( */ private int processMaintenanceOnlyIndexes( ECContainerReplicaCount replicaCount, - Map> sources, + Map sources, List excludedNodes, List usedNodes) throws IOException { Set maintIndexes = replicaCount.maintenanceOnlyIndexes(true); @@ -657,20 +640,19 @@ private int processMaintenanceOnlyIndexes( if (additionalMaintenanceCopiesNeeded <= 0) { break; } - Pair source = sources.get(maintIndex); + SourceReplica source = sources.get(maintIndex); if (source == null) { LOG.warn("Cannot find source replica for maintenance index " + "{} in container {}", maintIndex, container.containerID()); continue; } - ContainerReplica sourceReplica = source.getLeft(); + ContainerReplica sourceReplica = source.replica(); if (!iterator.hasNext()) { LOG.warn("Couldn't find enough targets. Available source" + " nodes: {}, target nodes: {}, excluded nodes: {}," + " usedNodes: {} and" + " maintenance indexes: {}", - sources.values().stream() - .map(Pair::getLeft).collect(Collectors.toSet()), + sources.values().stream().map(SourceReplica::replica).collect(Collectors.toSet()), targets, excludedNodes, usedNodes, maintIndexes); break; } @@ -830,4 +812,10 @@ private void checkAndRemoveUnhealthyReplica( } } + /** + * A container replica paired with the current status of its host node, + * used as a candidate source for EC reconstruction or replication. + */ + private record SourceReplica(ContainerReplica replica, NodeStatus nodeStatus) { } + } diff --git a/hadoop-hdds/server-scm/src/main/java/org/apache/hadoop/hdds/scm/container/replication/ReplicationManager.java b/hadoop-hdds/server-scm/src/main/java/org/apache/hadoop/hdds/scm/container/replication/ReplicationManager.java index d22093c76d67..e11c19181e6c 100644 --- a/hadoop-hdds/server-scm/src/main/java/org/apache/hadoop/hdds/scm/container/replication/ReplicationManager.java +++ b/hadoop-hdds/server-scm/src/main/java/org/apache/hadoop/hdds/scm/container/replication/ReplicationManager.java @@ -42,7 +42,6 @@ import java.util.concurrent.atomic.AtomicReference; import java.util.concurrent.locks.Lock; import java.util.concurrent.locks.ReentrantLock; -import org.apache.commons.lang3.tuple.Pair; import org.apache.hadoop.hdds.ComponentVersion; import org.apache.hadoop.hdds.HddsConfigKeys; import org.apache.hadoop.hdds.client.ReplicationConfig; @@ -575,8 +574,7 @@ public void sendThrottledReplicationCommand(ContainerInfo containerInfo, List sources, DatanodeDetails target, int replicaIndex) throws CommandTargetOverloadedException, NotLeaderException { long containerID = containerInfo.getContainerID(); - List> sourceWithCmds = - getAvailableDatanodesForReplication(sources); + List sourceWithCmds = getAvailableDatanodesForReplication(sources); if (sourceWithCmds.isEmpty()) { metrics.incrReplicateContainerCmdsDeferredTotal(); throw new CommandTargetOverloadedException("No sources with capacity " + @@ -618,8 +616,7 @@ public void sendThrottledReconstructionCommand(ContainerInfo containerInfo, () -> { // Pick the least-loaded target datanode that can accept the command. List targets = command.getTargetDatanodes(); - List> targetWithCmds = - getAvailableDatanodesForReplication(targets); + List targetWithCmds = getAvailableDatanodesForReplication(targets); if (targetWithCmds.isEmpty()) { metrics.incrECReconstructionCmdsDeferredTotal(); throw new CommandTargetOverloadedException("No target with capacity " + @@ -662,14 +659,14 @@ private DatanodeInfo getDatanodeInfo(DatanodeDetails dnDetails) { } private DatanodeDetails selectAndOptionallyExcludeDatanode( - int additionalCmdCount, List> datanodes) { + int additionalCmdCount, List datanodes) { if (datanodes.isEmpty()) { return null; } // Put the least loaded datanode first - datanodes.sort(Comparator.comparingInt(Pair::getLeft)); - DatanodeDetails datanode = datanodes.get(0).getRight(); - int currentCount = datanodes.get(0).getLeft(); + datanodes.sort(Comparator.comparingInt(DatanodeCommandCount::commandCount)); + DatanodeDetails datanode = datanodes.get(0).datanode(); + int currentCount = datanodes.get(0).commandCount(); if (currentCount + additionalCmdCount >= getReplicationLimit(datanode)) { addExcludedNode(datanode); } @@ -686,10 +683,8 @@ private DatanodeDetails selectAndOptionallyExcludeDatanode( * @return List of datanodes with the current command count that are not over * the limit. */ - private List> - getAvailableDatanodesForReplication(List datanodes) { - List> datanodeWithCommandCount - = new ArrayList<>(); + private List getAvailableDatanodesForReplication(List datanodes) { + List datanodeWithCommandCount = new ArrayList<>(); for (DatanodeDetails dn : datanodes) { try { int totalCount = getQueuedReplicationCount(dn); @@ -701,7 +696,7 @@ private DatanodeDetails selectAndOptionallyExcludeDatanode( addExcludedNode(dn); continue; } - datanodeWithCommandCount.add(Pair.of(totalCount, dn)); + datanodeWithCommandCount.add(new DatanodeCommandCount(totalCount, dn)); } catch (NodeNotFoundException e) { LOG.error("Node {} not found in NodeManager. Should not happen", dn, e); @@ -1893,5 +1888,11 @@ private void releaseSlot() { private interface ReconstructionSendAction { void run() throws CommandTargetOverloadedException, NotLeaderException; } + + /** + * A datanode paired with its current queued replication command count, + * used to pick the least loaded datanode for a new command. + */ + private record DatanodeCommandCount(int commandCount, DatanodeDetails datanode) { } } diff --git a/hadoop-hdds/server-scm/src/test/java/org/apache/hadoop/hdds/scm/container/replication/MisReplicationHandlerTests.java b/hadoop-hdds/server-scm/src/test/java/org/apache/hadoop/hdds/scm/container/replication/MisReplicationHandlerTests.java index 1a8e21c999f1..2c32fb1364cd 100644 --- a/hadoop-hdds/server-scm/src/test/java/org/apache/hadoop/hdds/scm/container/replication/MisReplicationHandlerTests.java +++ b/hadoop-hdds/server-scm/src/test/java/org/apache/hadoop/hdds/scm/container/replication/MisReplicationHandlerTests.java @@ -44,7 +44,6 @@ import java.util.function.Function; import java.util.stream.Collectors; import java.util.stream.IntStream; -import org.apache.commons.lang3.tuple.Pair; import org.apache.hadoop.hdds.client.ReplicationConfig; import org.apache.hadoop.hdds.conf.OzoneConfiguration; import org.apache.hadoop.hdds.protocol.DatanodeDetails; @@ -55,6 +54,7 @@ import org.apache.hadoop.hdds.scm.container.ContainerInfo; import org.apache.hadoop.hdds.scm.container.ContainerReplica; import org.apache.hadoop.hdds.scm.container.replication.ReplicationManager.ReplicationManagerConfiguration; +import org.apache.hadoop.hdds.scm.container.replication.ReplicationTestUtil.DatanodeCommand; import org.apache.hadoop.hdds.scm.net.NodeSchema; import org.apache.hadoop.hdds.scm.net.NodeSchemaManager; import org.apache.hadoop.hdds.scm.node.NodeStatus; @@ -74,7 +74,7 @@ public abstract class MisReplicationHandlerTests { private ContainerInfo container; private OzoneConfiguration conf; private ReplicationManager replicationManager; - private Set>> commandsSent; + private Set commandsSent; private final AtomicBoolean throwThrottledException = new AtomicBoolean(false); private ReplicationManagerMetrics metrics; @@ -229,14 +229,12 @@ protected void testMisReplication(Set availableReplicas, pendingOp, result, maintenanceCnt); } finally { assertEquals(expectedNumberOfCommands, commandsSent.size()); - for (Pair> pair : commandsSent) { - SCMCommand command = pair.getValue(); + for (DatanodeCommand datanodeCommand : commandsSent) { + SCMCommand command = datanodeCommand.command(); assertSame(replicateContainerCommand, command.getType()); - ReplicateContainerCommand replicateContainerCommand = - (ReplicateContainerCommand) command; - assertEquals(replicateContainerCommand.getContainerID(), - container.getContainerID()); - DatanodeDetails replicateSrcDn = pair.getKey(); + ReplicateContainerCommand replicateContainerCommand = (ReplicateContainerCommand) command; + assertEquals(replicateContainerCommand.getContainerID(), container.getContainerID()); + DatanodeDetails replicateSrcDn = datanodeCommand.datanode(); DatanodeDetails target = replicateContainerCommand.getTargetDatanode(); assertThat(sourceDns).contains(replicateSrcDn); assertThat(targetNodes).contains(target); diff --git a/hadoop-hdds/server-scm/src/test/java/org/apache/hadoop/hdds/scm/container/replication/ReplicationTestUtil.java b/hadoop-hdds/server-scm/src/test/java/org/apache/hadoop/hdds/scm/container/replication/ReplicationTestUtil.java index f715c766b08f..336404c32f40 100644 --- a/hadoop-hdds/server-scm/src/test/java/org/apache/hadoop/hdds/scm/container/replication/ReplicationTestUtil.java +++ b/hadoop-hdds/server-scm/src/test/java/org/apache/hadoop/hdds/scm/container/replication/ReplicationTestUtil.java @@ -33,7 +33,6 @@ import java.util.List; import java.util.Set; import java.util.concurrent.atomic.AtomicBoolean; -import org.apache.commons.lang3.tuple.Pair; import org.apache.hadoop.hdds.client.ReplicationConfig; import org.apache.hadoop.hdds.conf.OzoneConfiguration; import org.apache.hadoop.hdds.conf.StorageUnit; @@ -72,19 +71,18 @@ private ReplicationTestUtil() { } @SafeVarargs - public static Set createReplicas(ContainerID containerID, - Pair... nodes) { + public static Set createReplicas(ContainerID containerID, NodeOperationalStateAndIndex... nodes) { return createReplicas(containerID, CLOSED, nodes); } @SafeVarargs public static Set createReplicas(ContainerID containerID, ContainerReplicaProto.State replicaState, - Pair... nodes) { + NodeOperationalStateAndIndex... nodes) { Set replicas = new HashSet<>(); - for (Pair p : nodes) { + for (NodeOperationalStateAndIndex p : nodes) { replicas.add(createContainerReplica( - containerID, p.getRight(), p.getLeft(), replicaState)); + containerID, p.index(), p.state(), replicaState)); } return replicas; } @@ -152,12 +150,12 @@ public static ContainerReplica createEmptyContainerReplica(ContainerID container public static Set createReplicasWithOriginAndOpState( ContainerID containerID, ContainerReplicaProto.State replicaState, - Pair... nodes) { + NodeOperationalStateAndOrigin... nodes) { Set replicas = new HashSet<>(); - for (Pair i : nodes) { + for (NodeOperationalStateAndOrigin i : nodes) { replicas.add(createContainerReplica( - containerID, 0, i.getRight(), replicaState, 123L, 1234L, - MockDatanodeDetails.randomDatanodeDetails(), i.getLeft())); + containerID, 0, i.state(), replicaState, 123L, 1234L, + MockDatanodeDetails.randomDatanodeDetails(), i.origin())); } return replicas; } @@ -292,7 +290,7 @@ public static ContainerInfo createContainer(HddsProtos.LifeCycleState state, @SafeVarargs public static Set createReplicas( - Pair... states) { + NodeOperationalStateAndIndex... states) { return createReplicas(CLOSED, states); } @@ -300,11 +298,10 @@ public static Set createReplicas( @SafeVarargs public static Set createReplicas( ContainerReplicaProto.State replicaState, - Pair... states) { + NodeOperationalStateAndIndex... states) { Set replica = new HashSet<>(); - for (Pair s : states) { - replica.add(createContainerReplica(ContainerID.valueOf(1), s.getRight(), - s.getLeft(), replicaState)); + for (NodeOperationalStateAndIndex s : states) { + replica.add(createContainerReplica(ContainerID.valueOf(1), s.index(), s.state(), replicaState)); } return replica; } @@ -448,7 +445,7 @@ public DatanodeDetails chooseNode(List healthyNodes) { * to false, instead of creating the replicate command. */ public static void mockRMSendThrottleReplicateCommand(ReplicationManager mock, - Set>> commandsSent, + Set commandsSent, AtomicBoolean throwOverloaded) throws NotLeaderException, CommandTargetOverloadedException { doAnswer((Answer) invocationOnMock -> { @@ -462,7 +459,7 @@ public static void mockRMSendThrottleReplicateCommand(ReplicationManager mock, .getReplicateContainerCommand(containerInfo.getContainerID(), invocationOnMock.getArgument(2)); command.setReplicaIndex(invocationOnMock.getArgument(3)); - commandsSent.add(Pair.of(sources.get(0), command)); + commandsSent.add(new DatanodeCommand(sources.get(0), command)); return null; }).when(mock).sendThrottledReplicationCommand( any(ContainerInfo.class), anyList(), any(DatanodeDetails.class), anyInt()); @@ -480,7 +477,7 @@ public static void mockRMSendThrottleReplicateCommand(ReplicationManager mock, */ public static void mockSendThrottledReconstructionCommand( ReplicationManager mock, - Set>> commandsSent, + Set commandsSent, AtomicBoolean throwOverloaded) throws NotLeaderException, CommandTargetOverloadedException { doAnswer((Answer) invocationOnMock -> { @@ -489,7 +486,7 @@ public static void mockSendThrottledReconstructionCommand( throw new CommandTargetOverloadedException("Overloaded"); } ReconstructECContainersCommand cmd = invocationOnMock.getArgument(1); - commandsSent.add(Pair.of(cmd.getTargetDatanodes().get(0), cmd)); + commandsSent.add(new DatanodeCommand(cmd.getTargetDatanodes().get(0), cmd)); return null; }).when(mock).sendThrottledReconstructionCommand(any(ContainerInfo.class), any()); } @@ -502,12 +499,12 @@ public static void mockSendThrottledReconstructionCommand( * @param commandsSent Set to add the command to rather than sending it. */ public static void mockRMSendDatanodeCommand(ReplicationManager mock, - Set>> commandsSent) + Set commandsSent) throws NotLeaderException { doAnswer((Answer) invocationOnMock -> { DatanodeDetails target = invocationOnMock.getArgument(2); SCMCommand command = invocationOnMock.getArgument(0); - commandsSent.add(Pair.of(target, command)); + commandsSent.add(new DatanodeCommand(target, command)); return null; }).when(mock).sendDatanodeCommand(any(), any(), any()); } @@ -520,7 +517,7 @@ public static void mockRMSendDatanodeCommand(ReplicationManager mock, * @param commandsSent Set to add the command to rather than sending it. */ public static void mockRMSendDeleteCommand(ReplicationManager mock, - Set>> commandsSent) + Set commandsSent) throws NotLeaderException { doAnswer((Answer) invocationOnMock -> { ContainerInfo containerInfo = invocationOnMock.getArgument(0); @@ -530,7 +527,7 @@ public static void mockRMSendDeleteCommand(ReplicationManager mock, DeleteContainerCommand deleteCommand = new DeleteContainerCommand( containerInfo.getContainerID(), forceDelete); deleteCommand.setReplicaIndex(replicaIndex); - commandsSent.add(Pair.of(target, deleteCommand)); + commandsSent.add(new DatanodeCommand(target, deleteCommand)); return null; }).when(mock).sendDeleteCommand(any(), anyInt(), any(), anyBoolean()); } @@ -543,7 +540,7 @@ public static void mockRMSendDeleteCommand(ReplicationManager mock, * @param commandsSent Set to add the command to rather than sending it. */ public static void mockRMSendThrottledDeleteCommand(ReplicationManager mock, - Set>> commandsSent) + Set commandsSent) throws NotLeaderException, CommandTargetOverloadedException { mockRMSendThrottledDeleteCommand(mock, commandsSent, new AtomicBoolean(false)); } @@ -559,7 +556,7 @@ public static void mockRMSendThrottledDeleteCommand(ReplicationManager mock, * to false, instead of creating the replicate command. */ public static void mockRMSendThrottledDeleteCommand(ReplicationManager mock, - Set>> commandsSent, AtomicBoolean throwOverloaded) + Set commandsSent, AtomicBoolean throwOverloaded) throws NotLeaderException, CommandTargetOverloadedException { doAnswer((Answer) invocationOnMock -> { if (throwOverloaded.get()) { @@ -573,9 +570,29 @@ public static void mockRMSendThrottledDeleteCommand(ReplicationManager mock, DeleteContainerCommand deleteCommand = new DeleteContainerCommand( containerInfo.getContainerID(), forceDelete); deleteCommand.setReplicaIndex(replicaIndex); - commandsSent.add(Pair.of(target, deleteCommand)); + commandsSent.add(new DatanodeCommand(target, deleteCommand)); return null; }).when(mock) .sendThrottledDeleteCommand(any(), anyInt(), any(), anyBoolean()); } + + /** + * Operational state of the node hosting a test replica, and the replica index. + */ + public record NodeOperationalStateAndIndex(HddsProtos.NodeOperationalState state, int index) { } + + /** + * Origin datanode of a test replica, and the operational state of its node. + */ + public record NodeOperationalStateAndOrigin(DatanodeID origin, HddsProtos.NodeOperationalState state) { } + + /** + * A command sent to a datanode, as recorded by tests. + */ + public record DatanodeCommand(DatanodeDetails datanode, SCMCommand command) { } + + /** + * A command sent to a datanode identified by its ID, as recorded by tests. + */ + public record DatanodeIdCommand(DatanodeID datanodeId, SCMCommand command) { } } diff --git a/hadoop-hdds/server-scm/src/test/java/org/apache/hadoop/hdds/scm/container/replication/TestECContainerReplicaCount.java b/hadoop-hdds/server-scm/src/test/java/org/apache/hadoop/hdds/scm/container/replication/TestECContainerReplicaCount.java index bb31e9cb8e1e..cd9891ea727a 100644 --- a/hadoop-hdds/server-scm/src/test/java/org/apache/hadoop/hdds/scm/container/replication/TestECContainerReplicaCount.java +++ b/hadoop-hdds/server-scm/src/test/java/org/apache/hadoop/hdds/scm/container/replication/TestECContainerReplicaCount.java @@ -38,13 +38,13 @@ import java.util.HashSet; import java.util.List; import java.util.Set; -import org.apache.commons.lang3.tuple.Pair; import org.apache.hadoop.hdds.client.ECReplicationConfig; import org.apache.hadoop.hdds.protocol.MockDatanodeDetails; import org.apache.hadoop.hdds.protocol.proto.HddsProtos; import org.apache.hadoop.hdds.protocol.proto.StorageContainerDatanodeProtocolProtos.ContainerReplicaProto; import org.apache.hadoop.hdds.scm.container.ContainerInfo; import org.apache.hadoop.hdds.scm.container.ContainerReplica; +import org.apache.hadoop.hdds.scm.container.replication.ReplicationTestUtil.NodeOperationalStateAndIndex; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; @@ -66,9 +66,9 @@ public void setup() { @Test public void testPerfectlyReplicatedContainer() { Set replica = ReplicationTestUtil - .createReplicas(Pair.of(IN_SERVICE, 1), Pair.of(IN_SERVICE, 2), - Pair.of(IN_SERVICE, 3), Pair.of(IN_SERVICE, 4), - Pair.of(IN_SERVICE, 5)); + .createReplicas(new NodeOperationalStateAndIndex(IN_SERVICE, 1), + new NodeOperationalStateAndIndex(IN_SERVICE, 2), new NodeOperationalStateAndIndex(IN_SERVICE, 3), + new NodeOperationalStateAndIndex(IN_SERVICE, 4), new NodeOperationalStateAndIndex(IN_SERVICE, 5)); ECContainerReplicaCount rcnt = new ECContainerReplicaCount(container, replica, Collections.emptyList(), 1); @@ -79,8 +79,9 @@ public void testPerfectlyReplicatedContainer() { @Test public void testContainerMissingReplica() { Set replica = ReplicationTestUtil - .createReplicas(Pair.of(IN_SERVICE, 1), Pair.of(IN_SERVICE, 2), - Pair.of(IN_SERVICE, 3), Pair.of(IN_SERVICE, 4)); + .createReplicas(new NodeOperationalStateAndIndex(IN_SERVICE, 1), + new NodeOperationalStateAndIndex(IN_SERVICE, 2), new NodeOperationalStateAndIndex(IN_SERVICE, 3), + new NodeOperationalStateAndIndex(IN_SERVICE, 4)); ECContainerReplicaCount rcnt = new ECContainerReplicaCount(container, replica, Collections.emptyList(), 1); @@ -101,9 +102,9 @@ public void testContainerMissingReplica() { @Test public void testContainerMissingReplicaDueToPendingDelete() { Set replica = ReplicationTestUtil - .createReplicas(Pair.of(IN_SERVICE, 1), Pair.of(IN_SERVICE, 2), - Pair.of(IN_SERVICE, 3), Pair.of(IN_SERVICE, 4), - Pair.of(IN_SERVICE, 5)); + .createReplicas(new NodeOperationalStateAndIndex(IN_SERVICE, 1), + new NodeOperationalStateAndIndex(IN_SERVICE, 2), new NodeOperationalStateAndIndex(IN_SERVICE, 3), + new NodeOperationalStateAndIndex(IN_SERVICE, 4), new NodeOperationalStateAndIndex(IN_SERVICE, 5)); List pending = getContainerReplicaOps(ImmutableList.of(), ImmutableList.of(1)); @@ -139,10 +140,10 @@ public void testUnderReplicationDueToUnhealthyReplica() { @Test public void testContainerExcessReplicasAndPendingDelete() { Set replica = ReplicationTestUtil - .createReplicas(Pair.of(IN_SERVICE, 1), Pair.of(IN_SERVICE, 2), - Pair.of(IN_SERVICE, 3), Pair.of(IN_SERVICE, 4), - Pair.of(IN_SERVICE, 5), Pair.of(IN_SERVICE, 1), - Pair.of(IN_SERVICE, 2)); + .createReplicas(new NodeOperationalStateAndIndex(IN_SERVICE, 1), + new NodeOperationalStateAndIndex(IN_SERVICE, 2), new NodeOperationalStateAndIndex(IN_SERVICE, 3), + new NodeOperationalStateAndIndex(IN_SERVICE, 4), new NodeOperationalStateAndIndex(IN_SERVICE, 5), + new NodeOperationalStateAndIndex(IN_SERVICE, 1), new NodeOperationalStateAndIndex(IN_SERVICE, 2)); List pending = getContainerReplicaOps(ImmutableList.of(), ImmutableList.of(1, 2)); @@ -155,10 +156,10 @@ public void testContainerExcessReplicasAndPendingDelete() { @Test public void testUnderRepContainerWithExcessReplicasAndPendingDelete() { Set replica = ReplicationTestUtil - .createReplicas(Pair.of(IN_SERVICE, 1), Pair.of(IN_SERVICE, 2), - Pair.of(IN_SERVICE, 3), Pair.of(IN_SERVICE, 4), - Pair.of(IN_SERVICE, 5), Pair.of(IN_SERVICE, 1), - Pair.of(IN_SERVICE, 2)); + .createReplicas(new NodeOperationalStateAndIndex(IN_SERVICE, 1), + new NodeOperationalStateAndIndex(IN_SERVICE, 2), new NodeOperationalStateAndIndex(IN_SERVICE, 3), + new NodeOperationalStateAndIndex(IN_SERVICE, 4), new NodeOperationalStateAndIndex(IN_SERVICE, 5), + new NodeOperationalStateAndIndex(IN_SERVICE, 1), new NodeOperationalStateAndIndex(IN_SERVICE, 2)); List pending = getContainerReplicaOps(ImmutableList.of(), ImmutableList.of(1, 2, 2)); @@ -173,9 +174,9 @@ public void testUnderRepContainerWithExcessReplicasAndPendingDelete() { @Test public void testContainerWithMaintenanceReplicasSufficientlyReplicated() { Set replica = ReplicationTestUtil - .createReplicas(Pair.of(IN_SERVICE, 1), Pair.of(IN_SERVICE, 2), - Pair.of(IN_SERVICE, 3), Pair.of(IN_MAINTENANCE, 4), - Pair.of(IN_MAINTENANCE, 5)); + .createReplicas(new NodeOperationalStateAndIndex(IN_SERVICE, 1), + new NodeOperationalStateAndIndex(IN_SERVICE, 2), new NodeOperationalStateAndIndex(IN_SERVICE, 3), + new NodeOperationalStateAndIndex(IN_MAINTENANCE, 4), new NodeOperationalStateAndIndex(IN_MAINTENANCE, 5)); ECContainerReplicaCount rcnt = new ECContainerReplicaCount(container, replica, Collections.emptyList(), 0); @@ -192,10 +193,10 @@ public void testContainerWithMaintenanceReplicasSufficientlyReplicated() { @Test public void testOverReplicatedContainer() { Set replica = ReplicationTestUtil - .createReplicas(Pair.of(IN_SERVICE, 1), Pair.of(IN_SERVICE, 2), - Pair.of(IN_SERVICE, 3), Pair.of(IN_SERVICE, 4), - Pair.of(IN_SERVICE, 5), Pair.of(IN_SERVICE, 1), - Pair.of(IN_SERVICE, 2)); + .createReplicas(new NodeOperationalStateAndIndex(IN_SERVICE, 1), + new NodeOperationalStateAndIndex(IN_SERVICE, 2), new NodeOperationalStateAndIndex(IN_SERVICE, 3), + new NodeOperationalStateAndIndex(IN_SERVICE, 4), new NodeOperationalStateAndIndex(IN_SERVICE, 5), + new NodeOperationalStateAndIndex(IN_SERVICE, 1), new NodeOperationalStateAndIndex(IN_SERVICE, 2)); List pending = getContainerReplicaOps(ImmutableList.of(), ImmutableList.of(1)); @@ -220,10 +221,10 @@ public void testOverReplicatedContainer() { @Test public void testOverReplicatedContainerFixedWithPendingDelete() { Set replica = ReplicationTestUtil - .createReplicas(Pair.of(IN_SERVICE, 1), Pair.of(IN_SERVICE, 2), - Pair.of(IN_SERVICE, 3), Pair.of(IN_SERVICE, 4), - Pair.of(IN_SERVICE, 5), Pair.of(IN_SERVICE, 1), - Pair.of(IN_SERVICE, 2)); + .createReplicas(new NodeOperationalStateAndIndex(IN_SERVICE, 1), + new NodeOperationalStateAndIndex(IN_SERVICE, 2), new NodeOperationalStateAndIndex(IN_SERVICE, 3), + new NodeOperationalStateAndIndex(IN_SERVICE, 4), new NodeOperationalStateAndIndex(IN_SERVICE, 5), + new NodeOperationalStateAndIndex(IN_SERVICE, 1), new NodeOperationalStateAndIndex(IN_SERVICE, 2)); List pending = getContainerReplicaOps(ImmutableList.of(), ImmutableList.of(1)); @@ -243,10 +244,10 @@ public void testOverReplicatedContainerFixedWithPendingDelete() { @Test public void testOverReplicatedAndUnderReplicatedContainer() { Set replica = ReplicationTestUtil - .createReplicas(Pair.of(DECOMMISSIONING, 1), Pair.of(IN_SERVICE, 2), - Pair.of(IN_SERVICE, 3), Pair.of(IN_SERVICE, 4), - Pair.of(IN_SERVICE, 5), Pair.of(IN_SERVICE, 1), - Pair.of(IN_SERVICE, 2)); + .createReplicas(new NodeOperationalStateAndIndex(DECOMMISSIONING, 1), + new NodeOperationalStateAndIndex(IN_SERVICE, 2), new NodeOperationalStateAndIndex(IN_SERVICE, 3), + new NodeOperationalStateAndIndex(IN_SERVICE, 4), new NodeOperationalStateAndIndex(IN_SERVICE, 5), + new NodeOperationalStateAndIndex(IN_SERVICE, 1), new NodeOperationalStateAndIndex(IN_SERVICE, 2)); // this copy of index 4 is unhealthy, so it should not cause over // replication of index 4 ContainerReplica unhealthyIndex4 = @@ -267,10 +268,10 @@ public void testOverReplicatedAndUnderReplicatedContainer() { @Test public void testAdditionalMaintenanceCopiesAllMaintenance() { Set replica = ReplicationTestUtil - .createReplicas(Pair.of(IN_MAINTENANCE, 1), - Pair.of(ENTERING_MAINTENANCE, 2), Pair.of(IN_MAINTENANCE, 3), - Pair.of(IN_MAINTENANCE, 4), Pair.of(IN_MAINTENANCE, 5), - Pair.of(IN_MAINTENANCE, 1)); + .createReplicas(new NodeOperationalStateAndIndex(IN_MAINTENANCE, 1), + new NodeOperationalStateAndIndex(ENTERING_MAINTENANCE, 2), + new NodeOperationalStateAndIndex(IN_MAINTENANCE, 3), new NodeOperationalStateAndIndex(IN_MAINTENANCE, 4), + new NodeOperationalStateAndIndex(IN_MAINTENANCE, 5), new NodeOperationalStateAndIndex(IN_MAINTENANCE, 1)); ECContainerReplicaCount rcnt = new ECContainerReplicaCount(container, replica, Collections.emptyList(), 1); @@ -294,9 +295,10 @@ public void testAdditionalMaintenanceCopiesAllMaintenance() { @Test public void testAdditionalMaintenanceCopiesAlreadyReplicated() { Set replica = ReplicationTestUtil - .createReplicas(Pair.of(IN_SERVICE, 1), Pair.of(IN_SERVICE, 2), - Pair.of(IN_SERVICE, 3), Pair.of(IN_SERVICE, 4), - Pair.of(IN_MAINTENANCE, 5), Pair.of(IN_MAINTENANCE, 1)); + .createReplicas(new NodeOperationalStateAndIndex(IN_SERVICE, 1), + new NodeOperationalStateAndIndex(IN_SERVICE, 2), new NodeOperationalStateAndIndex(IN_SERVICE, 3), + new NodeOperationalStateAndIndex(IN_SERVICE, 4), new NodeOperationalStateAndIndex(IN_MAINTENANCE, 5), + new NodeOperationalStateAndIndex(IN_MAINTENANCE, 1)); ECContainerReplicaCount rcnt = new ECContainerReplicaCount(container, replica, Collections.emptyList(), 1); @@ -323,9 +325,10 @@ public void testAdditionalMaintenanceCopiesAlreadyReplicated() { @Test public void testAdditionalMaintenanceCopiesAlreadyReplicatedWithDelete() { Set replica = ReplicationTestUtil - .createReplicas(Pair.of(IN_SERVICE, 1), Pair.of(IN_SERVICE, 2), - Pair.of(IN_SERVICE, 3), Pair.of(IN_SERVICE, 4), - Pair.of(IN_MAINTENANCE, 5), Pair.of(IN_MAINTENANCE, 1)); + .createReplicas(new NodeOperationalStateAndIndex(IN_SERVICE, 1), + new NodeOperationalStateAndIndex(IN_SERVICE, 2), new NodeOperationalStateAndIndex(IN_SERVICE, 3), + new NodeOperationalStateAndIndex(IN_SERVICE, 4), new NodeOperationalStateAndIndex(IN_MAINTENANCE, 5), + new NodeOperationalStateAndIndex(IN_MAINTENANCE, 1)); List pending = getContainerReplicaOps(ImmutableList.of(), ImmutableList.of(1)); @@ -345,10 +348,11 @@ public void testAdditionalMaintenanceCopiesAlreadyReplicatedWithDelete() { @Test public void testAdditionalMaintenanceCopiesDuplicatesInMaintenance() { Set replica = ReplicationTestUtil - .createReplicas(Pair.of(IN_SERVICE, 1), Pair.of(IN_SERVICE, 2), - Pair.of(IN_SERVICE, 3), Pair.of(IN_SERVICE, 4), - Pair.of(IN_MAINTENANCE, 5), Pair.of(IN_MAINTENANCE, 1), - Pair.of(IN_MAINTENANCE, 1), Pair.of(IN_MAINTENANCE, 5)); + .createReplicas(new NodeOperationalStateAndIndex(IN_SERVICE, 1), + new NodeOperationalStateAndIndex(IN_SERVICE, 2), new NodeOperationalStateAndIndex(IN_SERVICE, 3), + new NodeOperationalStateAndIndex(IN_SERVICE, 4), new NodeOperationalStateAndIndex(IN_MAINTENANCE, 5), + new NodeOperationalStateAndIndex(IN_MAINTENANCE, 1), new NodeOperationalStateAndIndex(IN_MAINTENANCE, 1), + new NodeOperationalStateAndIndex(IN_MAINTENANCE, 5)); ECContainerReplicaCount rcnt = new ECContainerReplicaCount(container, replica, Collections.emptyList(), 1); @@ -375,9 +379,9 @@ public void testAdditionalMaintenanceCopiesDuplicatesInMaintenance() { @Test public void testMaintenanceRedundancyGreaterThanParity() { Set replica = ReplicationTestUtil - .createReplicas(Pair.of(IN_SERVICE, 1), Pair.of(IN_SERVICE, 2), - Pair.of(IN_SERVICE, 3), Pair.of(IN_MAINTENANCE, 4), - Pair.of(IN_MAINTENANCE, 5)); + .createReplicas(new NodeOperationalStateAndIndex(IN_SERVICE, 1), + new NodeOperationalStateAndIndex(IN_SERVICE, 2), new NodeOperationalStateAndIndex(IN_SERVICE, 3), + new NodeOperationalStateAndIndex(IN_MAINTENANCE, 4), new NodeOperationalStateAndIndex(IN_MAINTENANCE, 5)); ECContainerReplicaCount rcnt = new ECContainerReplicaCount(container, replica, Collections.emptyList(), 5); @@ -387,10 +391,10 @@ public void testMaintenanceRedundancyGreaterThanParity() { assertEquals(2, rcnt.additionalMaintenanceCopiesNeeded(false)); // After replication, zero should be needed replica = ReplicationTestUtil - .createReplicas(Pair.of(IN_SERVICE, 1), Pair.of(IN_SERVICE, 2), - Pair.of(IN_SERVICE, 3), Pair.of(IN_MAINTENANCE, 4), - Pair.of(IN_MAINTENANCE, 5), Pair.of(IN_SERVICE, 4), - Pair.of(IN_SERVICE, 5)); + .createReplicas(new NodeOperationalStateAndIndex(IN_SERVICE, 1), + new NodeOperationalStateAndIndex(IN_SERVICE, 2), new NodeOperationalStateAndIndex(IN_SERVICE, 3), + new NodeOperationalStateAndIndex(IN_MAINTENANCE, 4), new NodeOperationalStateAndIndex(IN_MAINTENANCE, 5), + new NodeOperationalStateAndIndex(IN_SERVICE, 4), new NodeOperationalStateAndIndex(IN_SERVICE, 5)); rcnt = new ECContainerReplicaCount(container, replica, Collections.emptyList(), 5); assertEquals(0, rcnt.additionalMaintenanceCopiesNeeded(false)); @@ -400,8 +404,8 @@ public void testMaintenanceRedundancyGreaterThanParity() { @Test public void testUnderReplicatedNoMaintenance() { Set replica = ReplicationTestUtil - .createReplicas(Pair.of(IN_SERVICE, 1), Pair.of(IN_SERVICE, 2), - Pair.of(IN_SERVICE, 3)); + .createReplicas(new NodeOperationalStateAndIndex(IN_SERVICE, 1), + new NodeOperationalStateAndIndex(IN_SERVICE, 2), new NodeOperationalStateAndIndex(IN_SERVICE, 3)); ECContainerReplicaCount rcnt = new ECContainerReplicaCount(container, replica, @@ -421,9 +425,10 @@ public void testUnderReplicatedNoMaintenance() { @Test public void testMaintenanceRedundancyIsMetWithPendingAdd() { Set replica = ReplicationTestUtil - .createReplicas(Pair.of(IN_MAINTENANCE, 1), - Pair.of(ENTERING_MAINTENANCE, 2), Pair.of(IN_MAINTENANCE, 3), - Pair.of(IN_MAINTENANCE, 4), Pair.of(IN_MAINTENANCE, 5)); + .createReplicas(new NodeOperationalStateAndIndex(IN_MAINTENANCE, 1), + new NodeOperationalStateAndIndex(ENTERING_MAINTENANCE, 2), + new NodeOperationalStateAndIndex(IN_MAINTENANCE, 3), new NodeOperationalStateAndIndex(IN_MAINTENANCE, 4), + new NodeOperationalStateAndIndex(IN_MAINTENANCE, 5)); List pending = getContainerReplicaOps(ImmutableList.of(1, 2, 3, 4), ImmutableList.of(1)); @@ -444,8 +449,9 @@ public void testMaintenanceRedundancyIsMetWithPendingAdd() { @Test public void testUnderReplicatedFixedWithPending() { Set replica = ReplicationTestUtil - .createReplicas(Pair.of(IN_SERVICE, 1), Pair.of(IN_SERVICE, 2), - Pair.of(IN_SERVICE, 3)); + .createReplicas(new NodeOperationalStateAndIndex(IN_SERVICE, 1), + new NodeOperationalStateAndIndex(IN_SERVICE, 2), + new NodeOperationalStateAndIndex(IN_SERVICE, 3)); List pending = getContainerReplicaOps(ImmutableList.of(4, 5), ImmutableList.of()); @@ -468,8 +474,9 @@ public void testUnderReplicatedFixedWithPending() { @Test public void testMissingNonMaintenanceReplicas() { Set replica = ReplicationTestUtil - .createReplicas(Pair.of(IN_SERVICE, 1), Pair.of(IN_SERVICE, 2), - Pair.of(IN_SERVICE, 3), Pair.of(IN_MAINTENANCE, 4)); + .createReplicas(new NodeOperationalStateAndIndex(IN_SERVICE, 1), + new NodeOperationalStateAndIndex(IN_SERVICE, 2), new NodeOperationalStateAndIndex(IN_SERVICE, 3), + new NodeOperationalStateAndIndex(IN_MAINTENANCE, 4)); List pending = getContainerReplicaOps(ImmutableList.of(), ImmutableList.of(1)); @@ -487,9 +494,9 @@ public void testMissingNonMaintenanceReplicas() { @Test public void testMissingNonMaintenanceReplicasAllMaintenance() { Set replica = ReplicationTestUtil - .createReplicas(Pair.of(IN_MAINTENANCE, 1), Pair.of(IN_MAINTENANCE, 2), - Pair.of(IN_MAINTENANCE, 3), Pair.of(IN_MAINTENANCE, 4), - Pair.of(IN_MAINTENANCE, 5)); + .createReplicas(new NodeOperationalStateAndIndex(IN_MAINTENANCE, 1), + new NodeOperationalStateAndIndex(IN_MAINTENANCE, 2), new NodeOperationalStateAndIndex(IN_MAINTENANCE, 3), + new NodeOperationalStateAndIndex(IN_MAINTENANCE, 4), new NodeOperationalStateAndIndex(IN_MAINTENANCE, 5)); List pending = getContainerReplicaOps(ImmutableList.of(1), ImmutableList.of()); @@ -509,8 +516,9 @@ public void testMissingNonMaintenanceReplicasAllMaintenance() { @Test public void testMissingNonMaintenanceReplicasPendingAdd() { Set replica = ReplicationTestUtil - .createReplicas(Pair.of(IN_SERVICE, 1), Pair.of(IN_SERVICE, 2), - Pair.of(IN_SERVICE, 3), Pair.of(IN_SERVICE, 4)); + .createReplicas(new NodeOperationalStateAndIndex(IN_SERVICE, 1), + new NodeOperationalStateAndIndex(IN_SERVICE, 2), + new NodeOperationalStateAndIndex(IN_SERVICE, 3), new NodeOperationalStateAndIndex(IN_SERVICE, 4)); // 5 is missing, but there is a pending add. List pending = @@ -553,21 +561,20 @@ public void testUnRecoverable() { assertEquals(5, rcnt.unavailableIndexes(true).size()); Set replica = ReplicationTestUtil - .createReplicas(Pair.of(IN_SERVICE, 1), Pair.of(IN_MAINTENANCE, 2)); + .createReplicas(new NodeOperationalStateAndIndex(IN_SERVICE, 1), + new NodeOperationalStateAndIndex(IN_MAINTENANCE, 2)); // The unhealthy replica does not help with recovery even though we now // have 3 replicas. - replica.addAll(ReplicationTestUtil.createReplicas( - UNHEALTHY, Pair.of(IN_SERVICE, 3))); + replica.addAll(ReplicationTestUtil.createReplicas(UNHEALTHY, new NodeOperationalStateAndIndex(IN_SERVICE, 3))); rcnt = new ECContainerReplicaCount(container, replica, Collections.emptyList(), 1); assertTrue(rcnt.isUnrecoverable()); assertEquals(3, rcnt.unavailableIndexes(true).size()); assertEquals(0, rcnt.additionalMaintenanceCopiesNeeded(false)); - replica = ReplicationTestUtil - .createReplicas(Pair.of(DECOMMISSIONED, 1), Pair.of(DECOMMISSIONED, 2), - Pair.of(DECOMMISSIONED, 3), Pair.of(DECOMMISSIONED, 4), - Pair.of(DECOMMISSIONED, 5)); + replica = ReplicationTestUtil.createReplicas(new NodeOperationalStateAndIndex(DECOMMISSIONED, 1), + new NodeOperationalStateAndIndex(DECOMMISSIONED, 2), new NodeOperationalStateAndIndex(DECOMMISSIONED, 3), + new NodeOperationalStateAndIndex(DECOMMISSIONED, 4), new NodeOperationalStateAndIndex(DECOMMISSIONED, 5)); rcnt = new ECContainerReplicaCount(container, replica, Collections.emptyList(), 1); // Not missing as the decommission replicas are still online @@ -575,10 +582,9 @@ public void testUnRecoverable() { assertEquals(0, rcnt.unavailableIndexes(true).size()); // All unhealthy replicas is still un-recoverable. - replica = ReplicationTestUtil.createReplicas( - UNHEALTHY, Pair.of(IN_SERVICE, 1), - Pair.of(IN_SERVICE, 2), Pair.of(IN_SERVICE, 3), - Pair.of(IN_SERVICE, 4), Pair.of(IN_SERVICE, 5)); + replica = ReplicationTestUtil.createReplicas(UNHEALTHY, new NodeOperationalStateAndIndex(IN_SERVICE, 1), + new NodeOperationalStateAndIndex(IN_SERVICE, 2), new NodeOperationalStateAndIndex(IN_SERVICE, 3), + new NodeOperationalStateAndIndex(IN_SERVICE, 4), new NodeOperationalStateAndIndex(IN_SERVICE, 5)); rcnt = new ECContainerReplicaCount(container, replica, Collections.emptyList(), 1); // Not missing as the decommission replicas are still online @@ -596,25 +602,23 @@ public void testIsMissingAndUnhealthy() { // 1 unhealthy Set replica = ReplicationTestUtil - .createReplicas(UNHEALTHY, Pair.of(IN_SERVICE, 1)); + .createReplicas(UNHEALTHY, new NodeOperationalStateAndIndex(IN_SERVICE, 1)); rcnt = new ECContainerReplicaCount(container, replica, Collections.emptyList(), 1); assertTrue(rcnt.isMissing()); assertTrue(rcnt.isUnrecoverable()); // 2 unhealthy - replica = ReplicationTestUtil - .createReplicas(UNHEALTHY, Pair.of(IN_SERVICE, 1), - Pair.of(IN_SERVICE, 2)); + replica = ReplicationTestUtil.createReplicas(UNHEALTHY, new NodeOperationalStateAndIndex(IN_SERVICE, 1), + new NodeOperationalStateAndIndex(IN_SERVICE, 2)); rcnt = new ECContainerReplicaCount(container, replica, Collections.emptyList(), 1); assertTrue(rcnt.isMissing()); assertTrue(rcnt.isUnrecoverable()); // 3 unhealthy - replica = ReplicationTestUtil - .createReplicas(UNHEALTHY, Pair.of(IN_SERVICE, 1), - Pair.of(IN_SERVICE, 2), Pair.of(IN_SERVICE, 3)); + replica = ReplicationTestUtil.createReplicas(UNHEALTHY, new NodeOperationalStateAndIndex(IN_SERVICE, 1), + new NodeOperationalStateAndIndex(IN_SERVICE, 2), new NodeOperationalStateAndIndex(IN_SERVICE, 3)); rcnt = new ECContainerReplicaCount(container, replica, Collections.emptyList(), 1); assertFalse(rcnt.isMissing()); @@ -623,9 +627,9 @@ public void testIsMissingAndUnhealthy() { // 3 replicas, with 1 unhealthy replica = ReplicationTestUtil - .createReplicas(Pair.of(IN_SERVICE, 1), Pair.of(IN_SERVICE, 2)); - replica.addAll(ReplicationTestUtil.createReplicas( - UNHEALTHY, Pair.of(IN_SERVICE, 3))); + .createReplicas(new NodeOperationalStateAndIndex(IN_SERVICE, 1), + new NodeOperationalStateAndIndex(IN_SERVICE, 2)); + replica.addAll(ReplicationTestUtil.createReplicas(UNHEALTHY, new NodeOperationalStateAndIndex(IN_SERVICE, 3))); rcnt = new ECContainerReplicaCount(container, replica, Collections.emptyList(), 1); assertFalse(rcnt.isMissing()); @@ -633,10 +637,9 @@ public void testIsMissingAndUnhealthy() { // 4 replicas, with 1 unhealthy replica = ReplicationTestUtil - .createReplicas(Pair.of(IN_SERVICE, 1), Pair.of(IN_SERVICE, 2), - Pair.of(IN_SERVICE, 3)); - replica.addAll(ReplicationTestUtil.createReplicas( - UNHEALTHY, Pair.of(IN_SERVICE, 4))); + .createReplicas(new NodeOperationalStateAndIndex(IN_SERVICE, 1), + new NodeOperationalStateAndIndex(IN_SERVICE, 2), new NodeOperationalStateAndIndex(IN_SERVICE, 3)); + replica.addAll(ReplicationTestUtil.createReplicas(UNHEALTHY, new NodeOperationalStateAndIndex(IN_SERVICE, 4))); rcnt = new ECContainerReplicaCount(container, replica, Collections.emptyList(), 1); assertFalse(rcnt.isMissing()); @@ -646,9 +649,9 @@ public void testIsMissingAndUnhealthy() { @Test public void testDecommissioningOnlyIndexes() { Set replica = ReplicationTestUtil - .createReplicas(Pair.of(DECOMMISSIONING, 1), Pair.of(IN_SERVICE, 2), - Pair.of(IN_SERVICE, 3), Pair.of(IN_SERVICE, 4), - Pair.of(IN_SERVICE, 5)); + .createReplicas(new NodeOperationalStateAndIndex(DECOMMISSIONING, 1), + new NodeOperationalStateAndIndex(IN_SERVICE, 2), new NodeOperationalStateAndIndex(IN_SERVICE, 3), + new NodeOperationalStateAndIndex(IN_SERVICE, 4), new NodeOperationalStateAndIndex(IN_SERVICE, 5)); List pending = getContainerReplicaOps(ImmutableList.of(1), ImmutableList.of()); @@ -662,7 +665,7 @@ public void testDecommissioningOnlyIndexes() { @Test public void testSufficientlyReplicatedForOffline() { Set replica = ReplicationTestUtil - .createReplicas(Pair.of(IN_SERVICE, 2)); + .createReplicas(new NodeOperationalStateAndIndex(IN_SERVICE, 2)); ContainerReplica inServiceReplica = ReplicationTestUtil.createContainerReplica(container.containerID(), @@ -701,11 +704,9 @@ public void testSufficientlyReplicatedForOffline() { @Test public void testSufficientlyReplicatedWithUnhealthyAndPendingDelete() { Set replica = ReplicationTestUtil - .createReplicas(Pair.of(IN_SERVICE, 1), - Pair.of(IN_SERVICE, 2), - Pair.of(IN_SERVICE, 3), - Pair.of(IN_SERVICE, 4), - Pair.of(IN_SERVICE, 5)); + .createReplicas(new NodeOperationalStateAndIndex(IN_SERVICE, 1), + new NodeOperationalStateAndIndex(IN_SERVICE, 2), new NodeOperationalStateAndIndex(IN_SERVICE, 3), + new NodeOperationalStateAndIndex(IN_SERVICE, 4), new NodeOperationalStateAndIndex(IN_SERVICE, 5)); ContainerReplica unhealthyReplica = ReplicationTestUtil.createContainerReplica(container.containerID(), diff --git a/hadoop-hdds/server-scm/src/test/java/org/apache/hadoop/hdds/scm/container/replication/TestECMisReplicationHandler.java b/hadoop-hdds/server-scm/src/test/java/org/apache/hadoop/hdds/scm/container/replication/TestECMisReplicationHandler.java index 5bcba983a2c2..409a7b71f711 100644 --- a/hadoop-hdds/server-scm/src/test/java/org/apache/hadoop/hdds/scm/container/replication/TestECMisReplicationHandler.java +++ b/hadoop-hdds/server-scm/src/test/java/org/apache/hadoop/hdds/scm/container/replication/TestECMisReplicationHandler.java @@ -36,7 +36,6 @@ import java.util.List; import java.util.Map; import java.util.Set; -import org.apache.commons.lang3.tuple.Pair; import org.apache.hadoop.hdds.client.ECReplicationConfig; import org.apache.hadoop.hdds.conf.OzoneConfiguration; import org.apache.hadoop.hdds.protocol.DatanodeDetails; @@ -44,6 +43,7 @@ import org.apache.hadoop.hdds.scm.ContainerPlacementStatus; import org.apache.hadoop.hdds.scm.PlacementPolicy; import org.apache.hadoop.hdds.scm.container.ContainerReplica; +import org.apache.hadoop.hdds.scm.container.replication.ReplicationTestUtil.NodeOperationalStateAndIndex; import org.apache.hadoop.hdds.scm.exceptions.SCMException; import org.apache.hadoop.hdds.scm.node.states.NodeNotFoundException; import org.apache.hadoop.hdds.scm.pipeline.InsufficientDatanodesException; @@ -73,9 +73,9 @@ void setup(@TempDir File testDir) throws NodeNotFoundException, public void testMisReplicationWithAllNodesAvailable(int misreplicationCount) throws IOException { Set availableReplicas = ReplicationTestUtil - .createReplicas(Pair.of(IN_SERVICE, 1), Pair.of(IN_SERVICE, 2), - Pair.of(IN_SERVICE, 3), Pair.of(IN_SERVICE, 4), - Pair.of(IN_SERVICE, 5)); + .createReplicas(new NodeOperationalStateAndIndex(IN_SERVICE, 1), + new NodeOperationalStateAndIndex(IN_SERVICE, 2), new NodeOperationalStateAndIndex(IN_SERVICE, 3), + new NodeOperationalStateAndIndex(IN_SERVICE, 4), new NodeOperationalStateAndIndex(IN_SERVICE, 5)); testMisReplication(availableReplicas, Collections.emptyList(), 0, misreplicationCount, Math.min(misreplicationCount, 5)); } @@ -83,9 +83,9 @@ public void testMisReplicationWithAllNodesAvailable(int misreplicationCount) @Test public void testMisReplicationWithNoNodesReturned() throws IOException { Set availableReplicas = ReplicationTestUtil - .createReplicas(Pair.of(IN_SERVICE, 1), Pair.of(IN_SERVICE, 2), - Pair.of(IN_SERVICE, 3), Pair.of(IN_SERVICE, 4), - Pair.of(IN_SERVICE, 5)); + .createReplicas(new NodeOperationalStateAndIndex(IN_SERVICE, 1), + new NodeOperationalStateAndIndex(IN_SERVICE, 2), new NodeOperationalStateAndIndex(IN_SERVICE, 3), + new NodeOperationalStateAndIndex(IN_SERVICE, 4), new NodeOperationalStateAndIndex(IN_SERVICE, 5)); PlacementPolicy placementPolicy = mock(PlacementPolicy.class); ContainerPlacementStatus mockedContainerPlacementStatus = mock(ContainerPlacementStatus.class); @@ -105,9 +105,9 @@ public void testMisReplicationWithNoNodesReturned() throws IOException { public void testMisReplicationWithSomeNodesNotInService( int misreplicationCount) throws IOException { Set availableReplicas = ReplicationTestUtil - .createReplicas(Pair.of(IN_SERVICE, 1), Pair.of(IN_SERVICE, 2), - Pair.of(IN_MAINTENANCE, 3), Pair.of(IN_MAINTENANCE, 4), - Pair.of(IN_SERVICE, 5)); + .createReplicas(new NodeOperationalStateAndIndex(IN_SERVICE, 1), + new NodeOperationalStateAndIndex(IN_SERVICE, 2), new NodeOperationalStateAndIndex(IN_MAINTENANCE, 3), + new NodeOperationalStateAndIndex(IN_MAINTENANCE, 4), new NodeOperationalStateAndIndex(IN_SERVICE, 5)); testMisReplication(availableReplicas, Collections.emptyList(), 0, misreplicationCount, Math.min(misreplicationCount, 3)); } @@ -115,18 +115,19 @@ public void testMisReplicationWithSomeNodesNotInService( @Test public void testMisReplicationWithUndereplication() throws IOException { Set availableReplicas = ReplicationTestUtil - .createReplicas(Pair.of(IN_SERVICE, 2), - Pair.of(IN_SERVICE, 3), Pair.of(IN_SERVICE, 4), - Pair.of(IN_SERVICE, 5)); + .createReplicas(new NodeOperationalStateAndIndex(IN_SERVICE, 2), + new NodeOperationalStateAndIndex(IN_SERVICE, 3), new NodeOperationalStateAndIndex(IN_SERVICE, 4), + new NodeOperationalStateAndIndex(IN_SERVICE, 5)); testMisReplication(availableReplicas, Collections.emptyList(), 0, 1, 0); } @Test public void testMisReplicationWithOvereplication() throws IOException { Set availableReplicas = ReplicationTestUtil - .createReplicas(Pair.of(IN_SERVICE, 1), Pair.of(IN_SERVICE, 1), - Pair.of(IN_SERVICE, 2), Pair.of(IN_SERVICE, 3), - Pair.of(IN_SERVICE, 4), Pair.of(IN_SERVICE, 5)); + .createReplicas(new NodeOperationalStateAndIndex(IN_SERVICE, 1), + new NodeOperationalStateAndIndex(IN_SERVICE, 1), + new NodeOperationalStateAndIndex(IN_SERVICE, 2), new NodeOperationalStateAndIndex(IN_SERVICE, 3), + new NodeOperationalStateAndIndex(IN_SERVICE, 4), new NodeOperationalStateAndIndex(IN_SERVICE, 5)); testMisReplication(availableReplicas, Collections.emptyList(), 0, 1, 0); } @@ -134,9 +135,9 @@ public void testMisReplicationWithOvereplication() throws IOException { public void testMisReplicationWithSatisfiedPlacementPolicy() throws IOException { Set availableReplicas = ReplicationTestUtil - .createReplicas(Pair.of(IN_SERVICE, 1), Pair.of(IN_SERVICE, 2), - Pair.of(IN_SERVICE, 3), Pair.of(IN_SERVICE, 4), - Pair.of(IN_SERVICE, 5)); + .createReplicas(new NodeOperationalStateAndIndex(IN_SERVICE, 1), + new NodeOperationalStateAndIndex(IN_SERVICE, 2), new NodeOperationalStateAndIndex(IN_SERVICE, 3), + new NodeOperationalStateAndIndex(IN_SERVICE, 4), new NodeOperationalStateAndIndex(IN_SERVICE, 5)); PlacementPolicy placementPolicy = mock(PlacementPolicy.class); ContainerPlacementStatus mockedContainerPlacementStatus = mock(ContainerPlacementStatus.class); @@ -151,9 +152,9 @@ public void testMisReplicationWithSatisfiedPlacementPolicy() public void testMisReplicationWithPendingOps() throws IOException { Set availableReplicas = ReplicationTestUtil - .createReplicas(Pair.of(IN_SERVICE, 1), Pair.of(IN_SERVICE, 2), - Pair.of(IN_SERVICE, 3), Pair.of(IN_SERVICE, 4), - Pair.of(IN_SERVICE, 5)); + .createReplicas(new NodeOperationalStateAndIndex(IN_SERVICE, 1), + new NodeOperationalStateAndIndex(IN_SERVICE, 2), new NodeOperationalStateAndIndex(IN_SERVICE, 3), + new NodeOperationalStateAndIndex(IN_SERVICE, 4), new NodeOperationalStateAndIndex(IN_SERVICE, 5)); PlacementPolicy placementPolicy = mock(PlacementPolicy.class); ContainerPlacementStatus mockedContainerPlacementStatus = mock(ContainerPlacementStatus.class); @@ -179,9 +180,9 @@ public void testAllSourcesOverloaded() throws IOException { .when(replicationManager).sendThrottledReplicationCommand(any(), anyList(), any(), anyInt()); Set availableReplicas = ReplicationTestUtil - .createReplicas(Pair.of(IN_SERVICE, 1), Pair.of(IN_SERVICE, 2), - Pair.of(IN_SERVICE, 3), Pair.of(IN_SERVICE, 4), - Pair.of(IN_SERVICE, 5)); + .createReplicas(new NodeOperationalStateAndIndex(IN_SERVICE, 1), + new NodeOperationalStateAndIndex(IN_SERVICE, 2), new NodeOperationalStateAndIndex(IN_SERVICE, 3), + new NodeOperationalStateAndIndex(IN_SERVICE, 4), new NodeOperationalStateAndIndex(IN_SERVICE, 5)); assertThrows(CommandTargetOverloadedException.class, () -> testMisReplication(availableReplicas, mockPlacementPolicy(), Collections.emptyList(), 0, 1, 1, 0)); @@ -191,9 +192,9 @@ public void testAllSourcesOverloaded() throws IOException { public void testFirstSourcesOverloaded() { setThrowThrottledException(true); Set availableReplicas = ReplicationTestUtil - .createReplicas(Pair.of(IN_SERVICE, 1), Pair.of(IN_SERVICE, 2), - Pair.of(IN_SERVICE, 3), Pair.of(IN_SERVICE, 4), - Pair.of(IN_SERVICE, 5)); + .createReplicas(new NodeOperationalStateAndIndex(IN_SERVICE, 1), + new NodeOperationalStateAndIndex(IN_SERVICE, 2), new NodeOperationalStateAndIndex(IN_SERVICE, 3), + new NodeOperationalStateAndIndex(IN_SERVICE, 4), new NodeOperationalStateAndIndex(IN_SERVICE, 5)); assertThrows(CommandTargetOverloadedException.class, () -> testMisReplication(availableReplicas, mockPlacementPolicy(), Collections.emptyList(), 0, 2, 2, 1)); @@ -202,9 +203,9 @@ public void testFirstSourcesOverloaded() { @Test public void commandsForFewerThanRequiredNodes() throws IOException { Set availableReplicas = ReplicationTestUtil - .createReplicas(Pair.of(IN_SERVICE, 1), Pair.of(IN_SERVICE, 2), - Pair.of(IN_SERVICE, 3), Pair.of(IN_SERVICE, 4), - Pair.of(IN_SERVICE, 5)); + .createReplicas(new NodeOperationalStateAndIndex(IN_SERVICE, 1), + new NodeOperationalStateAndIndex(IN_SERVICE, 2), new NodeOperationalStateAndIndex(IN_SERVICE, 3), + new NodeOperationalStateAndIndex(IN_SERVICE, 4), new NodeOperationalStateAndIndex(IN_SERVICE, 5)); PlacementPolicy placementPolicy = mock(PlacementPolicy.class); List targetDatanodes = singletonList( availableReplicas.iterator().next().getDatanodeDetails()); diff --git a/hadoop-hdds/server-scm/src/test/java/org/apache/hadoop/hdds/scm/container/replication/TestECOverReplicationHandler.java b/hadoop-hdds/server-scm/src/test/java/org/apache/hadoop/hdds/scm/container/replication/TestECOverReplicationHandler.java index 533ac8983924..1ae7def76c54 100644 --- a/hadoop-hdds/server-scm/src/test/java/org/apache/hadoop/hdds/scm/container/replication/TestECOverReplicationHandler.java +++ b/hadoop-hdds/server-scm/src/test/java/org/apache/hadoop/hdds/scm/container/replication/TestECOverReplicationHandler.java @@ -48,7 +48,6 @@ import java.util.Set; import java.util.concurrent.atomic.AtomicBoolean; import java.util.stream.Collectors; -import org.apache.commons.lang3.tuple.Pair; import org.apache.hadoop.hdds.client.ECReplicationConfig; import org.apache.hadoop.hdds.conf.OzoneConfiguration; import org.apache.hadoop.hdds.protocol.DatanodeDetails; @@ -58,6 +57,8 @@ import org.apache.hadoop.hdds.scm.container.ContainerInfo; import org.apache.hadoop.hdds.scm.container.ContainerReplica; import org.apache.hadoop.hdds.scm.container.MockNodeManager; +import org.apache.hadoop.hdds.scm.container.replication.ReplicationTestUtil.DatanodeCommand; +import org.apache.hadoop.hdds.scm.container.replication.ReplicationTestUtil.NodeOperationalStateAndIndex; import org.apache.hadoop.hdds.scm.net.NodeSchema; import org.apache.hadoop.hdds.scm.net.NodeSchemaManager; import org.apache.hadoop.hdds.scm.node.NodeManager; @@ -80,7 +81,7 @@ public class TestECOverReplicationHandler { private ReplicationManager replicationManager; private PlacementPolicy policy; private DatanodeDetails staleNode; - private Set>> commandsSent; + private Set commandsSent; @BeforeEach void setup(@TempDir File testDir) throws NodeNotFoundException, NotLeaderException, @@ -117,9 +118,9 @@ void setup(@TempDir File testDir) throws NodeNotFoundException, NotLeaderExcepti public void testNoOverReplication() throws NotLeaderException, CommandTargetOverloadedException { Set availableReplicas = ReplicationTestUtil - .createReplicas(Pair.of(IN_SERVICE, 1), - Pair.of(IN_SERVICE, 2), Pair.of(IN_SERVICE, 3), - Pair.of(IN_SERVICE, 4), Pair.of(IN_SERVICE, 5)); + .createReplicas(new NodeOperationalStateAndIndex(IN_SERVICE, 1), + new NodeOperationalStateAndIndex(IN_SERVICE, 2), new NodeOperationalStateAndIndex(IN_SERVICE, 3), + new NodeOperationalStateAndIndex(IN_SERVICE, 4), new NodeOperationalStateAndIndex(IN_SERVICE, 5)); testOverReplicationWithIndexes(availableReplicas, Collections.emptyMap(), ImmutableList.of()); } @@ -128,9 +129,9 @@ public void testNoOverReplication() public void testOverReplicationFixedByPendingDelete() throws NotLeaderException, CommandTargetOverloadedException { Set availableReplicas = ReplicationTestUtil - .createReplicas(Pair.of(IN_SERVICE, 1), - Pair.of(IN_SERVICE, 2), Pair.of(IN_SERVICE, 3), - Pair.of(IN_SERVICE, 4), Pair.of(IN_SERVICE, 5)); + .createReplicas(new NodeOperationalStateAndIndex(IN_SERVICE, 1), + new NodeOperationalStateAndIndex(IN_SERVICE, 2), new NodeOperationalStateAndIndex(IN_SERVICE, 3), + new NodeOperationalStateAndIndex(IN_SERVICE, 4), new NodeOperationalStateAndIndex(IN_SERVICE, 5)); ContainerReplica excess = ReplicationTestUtil.createContainerReplica( container.containerID(), 5, IN_SERVICE, ContainerReplicaProto.State.CLOSED); @@ -146,10 +147,10 @@ public void testOverReplicationFixedByPendingDelete() public void testOverReplicationWithDecommissionIndexes() throws NotLeaderException, CommandTargetOverloadedException { Set availableReplicas = ReplicationTestUtil - .createReplicas(Pair.of(IN_SERVICE, 1), - Pair.of(IN_SERVICE, 2), Pair.of(IN_SERVICE, 3), - Pair.of(IN_SERVICE, 4), Pair.of(IN_SERVICE, 5), - Pair.of(DECOMMISSIONING, 5)); + .createReplicas(new NodeOperationalStateAndIndex(IN_SERVICE, 1), + new NodeOperationalStateAndIndex(IN_SERVICE, 2), new NodeOperationalStateAndIndex(IN_SERVICE, 3), + new NodeOperationalStateAndIndex(IN_SERVICE, 4), new NodeOperationalStateAndIndex(IN_SERVICE, 5), + new NodeOperationalStateAndIndex(DECOMMISSIONING, 5)); testOverReplicationWithIndexes(availableReplicas, Collections.emptyMap(), ImmutableList.of()); } @@ -158,9 +159,9 @@ public void testOverReplicationWithDecommissionIndexes() public void testOverReplicationWithStaleIndexes() throws NotLeaderException, CommandTargetOverloadedException { Set availableReplicas = ReplicationTestUtil - .createReplicas(Pair.of(IN_SERVICE, 1), - Pair.of(IN_SERVICE, 2), Pair.of(IN_SERVICE, 3), - Pair.of(IN_SERVICE, 4), Pair.of(IN_SERVICE, 5)); + .createReplicas(new NodeOperationalStateAndIndex(IN_SERVICE, 1), + new NodeOperationalStateAndIndex(IN_SERVICE, 2), new NodeOperationalStateAndIndex(IN_SERVICE, 3), + new NodeOperationalStateAndIndex(IN_SERVICE, 4), new NodeOperationalStateAndIndex(IN_SERVICE, 5)); ContainerReplica stale = ReplicationTestUtil.createContainerReplica( container.containerID(), 5, IN_SERVICE, ContainerReplicaProto.State.CLOSED); @@ -176,9 +177,9 @@ public void testOverReplicationWithStaleIndexes() public void testOverReplicationWithOpenReplica() throws NotLeaderException, CommandTargetOverloadedException { Set availableReplicas = ReplicationTestUtil - .createReplicas(Pair.of(IN_SERVICE, 1), - Pair.of(IN_SERVICE, 2), Pair.of(IN_SERVICE, 3), - Pair.of(IN_SERVICE, 4), Pair.of(IN_SERVICE, 5)); + .createReplicas(new NodeOperationalStateAndIndex(IN_SERVICE, 1), + new NodeOperationalStateAndIndex(IN_SERVICE, 2), new NodeOperationalStateAndIndex(IN_SERVICE, 3), + new NodeOperationalStateAndIndex(IN_SERVICE, 4), new NodeOperationalStateAndIndex(IN_SERVICE, 5)); ContainerReplica open = ReplicationTestUtil.createContainerReplica( container.containerID(), 5, IN_SERVICE, ContainerReplicaProto.State.OPEN); @@ -196,9 +197,9 @@ public void testOverReplicationWithOpenReplica() public void testOverReplicationButPolicyReturnsWrongIndexes() throws NotLeaderException, CommandTargetOverloadedException { Set availableReplicas = ReplicationTestUtil - .createReplicas(Pair.of(IN_SERVICE, 2), Pair.of(IN_SERVICE, 3), - Pair.of(IN_SERVICE, 4), Pair.of(IN_SERVICE, 5), - Pair.of(IN_SERVICE, 5)); + .createReplicas(new NodeOperationalStateAndIndex(IN_SERVICE, 2), + new NodeOperationalStateAndIndex(IN_SERVICE, 3), new NodeOperationalStateAndIndex(IN_SERVICE, 4), + new NodeOperationalStateAndIndex(IN_SERVICE, 5), new NodeOperationalStateAndIndex(IN_SERVICE, 5)); ContainerReplica toReturn = ReplicationTestUtil.createContainerReplica( container.containerID(), 1, IN_SERVICE, ContainerReplicaProto.State.CLOSED); @@ -213,10 +214,10 @@ public void testOverReplicationButPolicyReturnsWrongIndexes() public void testOverReplicationWithOneSameIndexes() throws NotLeaderException, CommandTargetOverloadedException { Set availableReplicas = ReplicationTestUtil - .createReplicas(Pair.of(IN_SERVICE, 1), - Pair.of(IN_SERVICE, 1), Pair.of(IN_SERVICE, 1), - Pair.of(IN_SERVICE, 2), Pair.of(IN_SERVICE, 3), - Pair.of(IN_SERVICE, 4), Pair.of(IN_SERVICE, 5)); + .createReplicas(new NodeOperationalStateAndIndex(IN_SERVICE, 1), + new NodeOperationalStateAndIndex(IN_SERVICE, 1), new NodeOperationalStateAndIndex(IN_SERVICE, 1), + new NodeOperationalStateAndIndex(IN_SERVICE, 2), new NodeOperationalStateAndIndex(IN_SERVICE, 3), + new NodeOperationalStateAndIndex(IN_SERVICE, 4), new NodeOperationalStateAndIndex(IN_SERVICE, 5)); testOverReplicationWithIndexes(availableReplicas, //num of index 1 is 3, but it should be 1, so 2 excess @@ -228,13 +229,13 @@ public void testOverReplicationWithOneSameIndexes() public void testOverReplicationWithMultiSameIndexes() throws NotLeaderException, CommandTargetOverloadedException { Set availableReplicas = ReplicationTestUtil - .createReplicas(Pair.of(IN_SERVICE, 1), - Pair.of(IN_SERVICE, 1), Pair.of(IN_SERVICE, 1), - Pair.of(IN_SERVICE, 2), Pair.of(IN_SERVICE, 2), - Pair.of(IN_SERVICE, 2), Pair.of(IN_SERVICE, 3), - Pair.of(IN_SERVICE, 3), Pair.of(IN_SERVICE, 3), - Pair.of(IN_SERVICE, 4), Pair.of(IN_SERVICE, 4), - Pair.of(IN_SERVICE, 5), Pair.of(IN_SERVICE, 5)); + .createReplicas(new NodeOperationalStateAndIndex(IN_SERVICE, 1), + new NodeOperationalStateAndIndex(IN_SERVICE, 1), new NodeOperationalStateAndIndex(IN_SERVICE, 1), + new NodeOperationalStateAndIndex(IN_SERVICE, 2), new NodeOperationalStateAndIndex(IN_SERVICE, 2), + new NodeOperationalStateAndIndex(IN_SERVICE, 2), new NodeOperationalStateAndIndex(IN_SERVICE, 3), + new NodeOperationalStateAndIndex(IN_SERVICE, 3), new NodeOperationalStateAndIndex(IN_SERVICE, 3), + new NodeOperationalStateAndIndex(IN_SERVICE, 4), new NodeOperationalStateAndIndex(IN_SERVICE, 4), + new NodeOperationalStateAndIndex(IN_SERVICE, 5), new NodeOperationalStateAndIndex(IN_SERVICE, 5)); testOverReplicationWithIndexes(availableReplicas, //num of index 1 is 3, but it should be 1, so 2 excess @@ -253,10 +254,9 @@ public void testOverReplicationWithUnderReplication() throws NotLeaderException, CommandTargetOverloadedException { Set availableReplicas = ReplicationTestUtil .createReplicas( - Pair.of(IN_SERVICE, 1), Pair.of(IN_SERVICE, 1), - Pair.of(IN_SERVICE, 3), - Pair.of(IN_SERVICE, 4), - Pair.of(IN_SERVICE, 5)); + new NodeOperationalStateAndIndex(IN_SERVICE, 1), new NodeOperationalStateAndIndex(IN_SERVICE, 1), + new NodeOperationalStateAndIndex(IN_SERVICE, 3), new NodeOperationalStateAndIndex(IN_SERVICE, 4), + new NodeOperationalStateAndIndex(IN_SERVICE, 5)); ContainerHealthResult.UnderReplicatedHealthResult health = new ContainerHealthResult.UnderReplicatedHealthResult( @@ -269,19 +269,17 @@ public void testOverReplicationWithUnderReplication() health, 1); assertEquals(1, commandsSent.size()); - SCMCommand cmd = commandsSent.iterator().next().getValue(); + SCMCommand cmd = commandsSent.iterator().next().command(); assertEquals(1, ((DeleteContainerCommand)cmd).getReplicaIndex()); } @Test public void testDeleteThrottling() throws IOException { Set availableReplicas = ReplicationTestUtil - .createReplicas( - Pair.of(IN_SERVICE, 1), Pair.of(IN_SERVICE, 1), - Pair.of(IN_SERVICE, 2), Pair.of(IN_SERVICE, 2), - Pair.of(IN_SERVICE, 3), - Pair.of(IN_SERVICE, 4), - Pair.of(IN_SERVICE, 5)); + .createReplicas(new NodeOperationalStateAndIndex(IN_SERVICE, 1), + new NodeOperationalStateAndIndex(IN_SERVICE, 1), new NodeOperationalStateAndIndex(IN_SERVICE, 2), + new NodeOperationalStateAndIndex(IN_SERVICE, 2), new NodeOperationalStateAndIndex(IN_SERVICE, 3), + new NodeOperationalStateAndIndex(IN_SERVICE, 4), new NodeOperationalStateAndIndex(IN_SERVICE, 5)); ContainerHealthResult.UnderReplicatedHealthResult health = new ContainerHealthResult.UnderReplicatedHealthResult( @@ -302,7 +300,7 @@ public void testDeleteThrottling() throws IOException { DeleteContainerCommand deleteCommand = new DeleteContainerCommand( containerInfo.getContainerID(), forceDelete); deleteCommand.setReplicaIndex(replicaIndex); - commandsSent.add(Pair.of(target, deleteCommand)); + commandsSent.add(new DatanodeCommand(target, deleteCommand)); return null; }).when(replicationManager) .sendThrottledDeleteCommand(any(), anyInt(), any(), anyBoolean()); @@ -337,7 +335,7 @@ private void testOverReplicationWithIndexes( // Each command should have a non-zero replica index commandsSent.forEach(pair -> assertNotEquals(0, - ((DeleteContainerCommand) pair.getValue()).getReplicaIndex())); + ((DeleteContainerCommand) pair.command()).getReplicaIndex())); // command num of each index should be equal to the excess num // of this index @@ -347,7 +345,7 @@ private void testOverReplicationWithIndexes( ContainerReplica::getReplicaIndex)); Map index2commandNum = new HashMap<>(); commandsSent.forEach(pair -> index2commandNum.merge( - datanodeDetails2Index.get(pair.getKey()), 1, Integer::sum) + datanodeDetails2Index.get(pair.datanode()), 1, Integer::sum) ); index2commandNum.keySet().forEach(i -> { diff --git a/hadoop-hdds/server-scm/src/test/java/org/apache/hadoop/hdds/scm/container/replication/TestECUnderReplicationHandler.java b/hadoop-hdds/server-scm/src/test/java/org/apache/hadoop/hdds/scm/container/replication/TestECUnderReplicationHandler.java index 10e2ccbeb7fe..b0ac99dc625a 100644 --- a/hadoop-hdds/server-scm/src/test/java/org/apache/hadoop/hdds/scm/container/replication/TestECUnderReplicationHandler.java +++ b/hadoop-hdds/server-scm/src/test/java/org/apache/hadoop/hdds/scm/container/replication/TestECUnderReplicationHandler.java @@ -63,13 +63,11 @@ import java.util.HashSet; import java.util.LinkedHashSet; import java.util.List; -import java.util.Map; import java.util.Set; import java.util.TreeSet; import java.util.concurrent.atomic.AtomicBoolean; import java.util.concurrent.atomic.AtomicInteger; import java.util.stream.IntStream; -import org.apache.commons.lang3.tuple.Pair; import org.apache.hadoop.hdds.client.ECReplicationConfig; import org.apache.hadoop.hdds.conf.OzoneConfiguration; import org.apache.hadoop.hdds.protocol.DatanodeDetails; @@ -84,6 +82,8 @@ import org.apache.hadoop.hdds.scm.container.MockNodeManager; import org.apache.hadoop.hdds.scm.container.placement.algorithms.ContainerPlacementStatusDefault; import org.apache.hadoop.hdds.scm.container.replication.ContainerHealthResult.UnderReplicatedHealthResult; +import org.apache.hadoop.hdds.scm.container.replication.ReplicationTestUtil.DatanodeCommand; +import org.apache.hadoop.hdds.scm.container.replication.ReplicationTestUtil.NodeOperationalStateAndIndex; import org.apache.hadoop.hdds.scm.exceptions.SCMException; import org.apache.hadoop.hdds.scm.net.NodeSchema; import org.apache.hadoop.hdds.scm.net.NodeSchemaManager; @@ -120,7 +120,7 @@ public class TestECUnderReplicationHandler { private static final int PARITY = 2; private PlacementPolicy ecPlacementPolicy; private int remainingMaintenanceRedundancy = 1; - private Set>> commandsSent; + private Set commandsSent; private final AtomicBoolean throwOverloadedExceptionOnReplication = new AtomicBoolean(false); private final AtomicBoolean throwOverloadedExceptionOnReconstruction @@ -327,8 +327,9 @@ public void testUnderReplicationWithMissingParityIndex5() throws IOException { @Test public void testUnderReplicationWithMissingIndex34() throws IOException { Set availableReplicas = ReplicationTestUtil - .createReplicas(Pair.of(IN_SERVICE, 1), Pair.of(IN_SERVICE, 2), - Pair.of(IN_SERVICE, 5)); + .createReplicas(new NodeOperationalStateAndIndex(IN_SERVICE, 1), + new NodeOperationalStateAndIndex(IN_SERVICE, 2), + new NodeOperationalStateAndIndex(IN_SERVICE, 5)); testUnderReplicationWithMissingIndexes(ImmutableList.of(3, 4), availableReplicas, 0, 0, policy); } @@ -363,16 +364,14 @@ public void testThrowsWhenTargetsOverloaded() throws IOException { @Test public void testUnderReplicationWithDecomIndex1() throws IOException { Set availableReplicas = ReplicationTestUtil - .createReplicas(Pair.of(DECOMMISSIONING, 1), Pair.of(IN_SERVICE, 2), - Pair.of(IN_SERVICE, 3), Pair.of(IN_SERVICE, 4), - Pair.of(IN_SERVICE, 5)); - Set>> cmds = - testUnderReplicationWithMissingIndexes( + .createReplicas(new NodeOperationalStateAndIndex(DECOMMISSIONING, 1), + new NodeOperationalStateAndIndex(IN_SERVICE, 2), new NodeOperationalStateAndIndex(IN_SERVICE, 3), + new NodeOperationalStateAndIndex(IN_SERVICE, 4), new NodeOperationalStateAndIndex(IN_SERVICE, 5)); + Set cmds = testUnderReplicationWithMissingIndexes( Lists.emptyList(), availableReplicas, 1, 0, policy); assertEquals(1, cmds.size()); // Check the replicate command has index 1 set - ReplicateContainerCommand cmd = (ReplicateContainerCommand) cmds - .iterator().next().getValue(); + ReplicateContainerCommand cmd = (ReplicateContainerCommand) cmds.iterator().next().command(); assertEquals(1, cmd.getReplicaIndex()); } @@ -400,23 +399,20 @@ public NodeStatus getNodeStatus(DatanodeDetails dd) { }; availableReplicas.addAll(ReplicationTestUtil - .createReplicas(Pair.of(DECOMMISSIONING, 1), - Pair.of(IN_MAINTENANCE, 2), - Pair.of(IN_SERVICE, 3), Pair.of(IN_SERVICE, 4), - Pair.of(IN_SERVICE, 5))); + .createReplicas(new NodeOperationalStateAndIndex(DECOMMISSIONING, 1), + new NodeOperationalStateAndIndex(IN_MAINTENANCE, 2), new NodeOperationalStateAndIndex(IN_SERVICE, 3), + new NodeOperationalStateAndIndex(IN_SERVICE, 4), new NodeOperationalStateAndIndex(IN_SERVICE, 5))); // Note that maintenanceIndexes is set to zero as we do not expect any // maintenance commands to be created, as they are solved by the earlier // decommission command. - Set>> cmds = - testUnderReplicationWithMissingIndexes( + Set cmds = testUnderReplicationWithMissingIndexes( Lists.emptyList(), availableReplicas, 1, 0, policy); assertEquals(1, cmds.size()); // Check the replicate command has index 1 set - for (Pair> c : cmds) { + for (DatanodeCommand c : cmds) { // Ensure neither of the commands are for the dead maintenance node - assertNotEquals(deadMaintenance.getDatanodeDetails(), - c.getKey()); + assertNotEquals(deadMaintenance.getDatanodeDetails(), c.datanode()); } } @@ -424,9 +420,9 @@ public NodeStatus getNodeStatus(DatanodeDetails dd) { public void testUnderReplicationWithDecomNodesOverloaded() throws IOException { Set availableReplicas = ReplicationTestUtil - .createReplicas(Pair.of(DECOMMISSIONING, 1), Pair.of(IN_SERVICE, 2), - Pair.of(IN_SERVICE, 3), Pair.of(IN_SERVICE, 4), - Pair.of(IN_SERVICE, 5)); + .createReplicas(new NodeOperationalStateAndIndex(DECOMMISSIONING, 1), + new NodeOperationalStateAndIndex(IN_SERVICE, 2), new NodeOperationalStateAndIndex(IN_SERVICE, 3), + new NodeOperationalStateAndIndex(IN_SERVICE, 4), new NodeOperationalStateAndIndex(IN_SERVICE, 5)); doThrow(new CommandTargetOverloadedException("Overloaded")) .when(replicationManager).sendThrottledReplicationCommand( any(), anyList(), any(), anyInt()); @@ -441,9 +437,9 @@ public void testUnderReplicationWithDecomNodesSwitchToReconstruction() throws IOException { replicationManager.getConfig().setEcDecommissionReconstructionEnabled(true); Set availableReplicas = ReplicationTestUtil - .createReplicas(Pair.of(DECOMMISSIONING, 1), Pair.of(IN_SERVICE, 2), - Pair.of(IN_SERVICE, 3), Pair.of(IN_SERVICE, 4), - Pair.of(IN_SERVICE, 5)); + .createReplicas(new NodeOperationalStateAndIndex(DECOMMISSIONING, 1), + new NodeOperationalStateAndIndex(IN_SERVICE, 2), new NodeOperationalStateAndIndex(IN_SERVICE, 3), + new NodeOperationalStateAndIndex(IN_SERVICE, 4), new NodeOperationalStateAndIndex(IN_SERVICE, 5)); // Mock node 1 as highly loaded DatanodeDetails decomNode = availableReplicas.stream() @@ -464,15 +460,14 @@ public void testUnderReplicationWithDecomNodesSwitchToReconstruction() // We expect 1 reconstruction command for index 1, and 0 replicate commands int replicateCommand = 0; int reconstructCommand = 0; - for (Pair> dnCommand : commandsSent) { - if (dnCommand.getValue() instanceof ReplicateContainerCommand) { + for (DatanodeCommand dnCommand : commandsSent) { + if (dnCommand.command() instanceof ReplicateContainerCommand) { replicateCommand++; - } else if (dnCommand.getValue() instanceof ReconstructECContainersCommand) { + } else if (dnCommand.command() instanceof ReconstructECContainersCommand) { reconstructCommand++; - ReconstructECContainersCommand reconCmd = - (ReconstructECContainersCommand) dnCommand.getValue(); - assertEquals(ECUnderReplicationHandler.integers2ByteString( - ImmutableList.of(1)), reconCmd.getMissingContainerIndexes()); + ReconstructECContainersCommand reconCmd = (ReconstructECContainersCommand) dnCommand.command(); + assertEquals(ECUnderReplicationHandler.integers2ByteString(ImmutableList.of(1)), + reconCmd.getMissingContainerIndexes()); // verify source offloading: decomNode should NOT be in the source list // because we have 4 other IN_SERVICE nodes (DATA=3) @@ -496,9 +491,9 @@ public void testUnderReplicationWithDecomNodesFallsBackWhenLimitReached() throws IOException { replicationManager.getConfig().setEcDecommissionReconstructionEnabled(true); Set availableReplicas = ReplicationTestUtil - .createReplicas(Pair.of(DECOMMISSIONING, 1), Pair.of(IN_SERVICE, 2), - Pair.of(IN_SERVICE, 3), Pair.of(IN_SERVICE, 4), - Pair.of(IN_SERVICE, 5)); + .createReplicas(new NodeOperationalStateAndIndex(DECOMMISSIONING, 1), + new NodeOperationalStateAndIndex(IN_SERVICE, 2), new NodeOperationalStateAndIndex(IN_SERVICE, 3), + new NodeOperationalStateAndIndex(IN_SERVICE, 4), new NodeOperationalStateAndIndex(IN_SERVICE, 5)); DatanodeDetails decomNode = availableReplicas.stream() .filter(r -> r.getReplicaIndex() == 1) @@ -517,9 +512,9 @@ public void testUnderReplicationWithDecomNodesFallsBackWhenLimitReached() result, remainingMaintenanceRedundancy); assertTrue(commandsSent.stream() - .anyMatch(c -> c.getValue() instanceof ReplicateContainerCommand)); + .anyMatch(c -> c.command() instanceof ReplicateContainerCommand)); assertTrue(commandsSent.stream() - .noneMatch(c -> c.getValue() instanceof ReconstructECContainersCommand)); + .noneMatch(c -> c.command() instanceof ReconstructECContainersCommand)); assertEquals(0, metrics.getEcReconstructionDecommissionTriggeredTotal()); assertEquals(1, metrics.getEcReconstructionGlobalLimitReachedTotal()); } @@ -529,9 +524,9 @@ public void testUnderReplicationWithDecomNodesFallsBackWhenReconstructionThrottl throws IOException { replicationManager.getConfig().setEcDecommissionReconstructionEnabled(true); Set availableReplicas = ReplicationTestUtil - .createReplicas(Pair.of(DECOMMISSIONING, 1), Pair.of(IN_SERVICE, 2), - Pair.of(IN_SERVICE, 3), Pair.of(IN_SERVICE, 4), - Pair.of(IN_SERVICE, 5)); + .createReplicas(new NodeOperationalStateAndIndex(DECOMMISSIONING, 1), + new NodeOperationalStateAndIndex(IN_SERVICE, 2), new NodeOperationalStateAndIndex(IN_SERVICE, 3), + new NodeOperationalStateAndIndex(IN_SERVICE, 4), new NodeOperationalStateAndIndex(IN_SERVICE, 5)); DatanodeDetails decomNode = availableReplicas.stream() .filter(r -> r.getReplicaIndex() == 1) @@ -550,9 +545,9 @@ public void testUnderReplicationWithDecomNodesFallsBackWhenReconstructionThrottl result, remainingMaintenanceRedundancy); assertTrue(commandsSent.stream() - .anyMatch(c -> c.getValue() instanceof ReplicateContainerCommand)); + .anyMatch(c -> c.command() instanceof ReplicateContainerCommand)); assertTrue(commandsSent.stream() - .noneMatch(c -> c.getValue() instanceof ReconstructECContainersCommand)); + .noneMatch(c -> c.command() instanceof ReconstructECContainersCommand)); assertEquals(1, metrics.getEcDecommissionReconstructionFallbackTargetOverloadedTotal()); } @@ -561,9 +556,9 @@ public void testUnderReplicationWithDecomNodesFallsBackWhenReconstructionThrottl throws IOException { replicationManager.getConfig().setEcDecommissionReconstructionEnabled(true); Set availableReplicas = ReplicationTestUtil - .createReplicas(Pair.of(DECOMMISSIONING, 1), Pair.of(IN_SERVICE, 2), - Pair.of(IN_SERVICE, 3), Pair.of(IN_SERVICE, 4), - Pair.of(IN_SERVICE, 5)); + .createReplicas(new NodeOperationalStateAndIndex(DECOMMISSIONING, 1), + new NodeOperationalStateAndIndex(IN_SERVICE, 2), new NodeOperationalStateAndIndex(IN_SERVICE, 3), + new NodeOperationalStateAndIndex(IN_SERVICE, 4), new NodeOperationalStateAndIndex(IN_SERVICE, 5)); DatanodeDetails decomNode = availableReplicas.stream() .filter(r -> r.getReplicaIndex() == 1) @@ -588,9 +583,9 @@ public void testUnderReplicationWithDecomNodesFallsBackWhenReconstructionThrottl assertEquals(2, spy.callCount()); assertEquals(spy.usedNodes(0).size(), spy.usedNodes(1).size()); assertTrue(commandsSent.stream() - .anyMatch(c -> c.getValue() instanceof ReplicateContainerCommand)); + .anyMatch(c -> c.command() instanceof ReplicateContainerCommand)); assertTrue(commandsSent.stream() - .noneMatch(c -> c.getValue() instanceof ReconstructECContainersCommand)); + .noneMatch(c -> c.command() instanceof ReconstructECContainersCommand)); assertEquals(1, metrics.getEcDecommissionReconstructionFallbackTargetOverloadedTotal()); } @@ -599,9 +594,9 @@ public void testUnderReplicationWithDecomNodesFallsBackWhenInsufficientSources() throws IOException { replicationManager.getConfig().setEcDecommissionReconstructionEnabled(true); Set availableReplicas = ReplicationTestUtil - .createReplicas(Pair.of(DECOMMISSIONING, 1), - Pair.of(DECOMMISSIONING, 2), Pair.of(DECOMMISSIONING, 3), - Pair.of(IN_SERVICE, 4), Pair.of(IN_SERVICE, 5)); + .createReplicas(new NodeOperationalStateAndIndex(DECOMMISSIONING, 1), + new NodeOperationalStateAndIndex(DECOMMISSIONING, 2), new NodeOperationalStateAndIndex(DECOMMISSIONING, 3), + new NodeOperationalStateAndIndex(IN_SERVICE, 4), new NodeOperationalStateAndIndex(IN_SERVICE, 5)); DatanodeDetails decomNode = availableReplicas.stream() .filter(r -> r.getReplicaIndex() == 1) @@ -619,9 +614,9 @@ public void testUnderReplicationWithDecomNodesFallsBackWhenInsufficientSources() result, remainingMaintenanceRedundancy); assertTrue(commandsSent.stream() - .anyMatch(c -> c.getValue() instanceof ReplicateContainerCommand)); + .anyMatch(c -> c.command() instanceof ReplicateContainerCommand)); assertTrue(commandsSent.stream() - .noneMatch(c -> c.getValue() instanceof ReconstructECContainersCommand)); + .noneMatch(c -> c.command() instanceof ReconstructECContainersCommand)); assertEquals(1, metrics.getEcDecommissionReconstructionFallbackInsufficientSourcesTotal()); } @@ -630,9 +625,9 @@ public void testUnderReplicationWithDecomNodesFallsBackWhenReconstructionNoOp() throws IOException { replicationManager.getConfig().setEcDecommissionReconstructionEnabled(true); Set availableReplicas = ReplicationTestUtil - .createReplicas(Pair.of(DECOMMISSIONING, 1), Pair.of(IN_SERVICE, 2), - Pair.of(IN_SERVICE, 3), Pair.of(IN_SERVICE, 4), - Pair.of(IN_SERVICE, 5)); + .createReplicas(new NodeOperationalStateAndIndex(DECOMMISSIONING, 1), + new NodeOperationalStateAndIndex(IN_SERVICE, 2), new NodeOperationalStateAndIndex(IN_SERVICE, 3), + new NodeOperationalStateAndIndex(IN_SERVICE, 4), new NodeOperationalStateAndIndex(IN_SERVICE, 5)); DatanodeDetails decomNode = availableReplicas.stream() .filter(r -> r.getReplicaIndex() == 1) @@ -669,9 +664,9 @@ public void testUnderReplicationWithDecomNodesFallsBackWhenReconstructionNoOp() assertEquals(0, metrics.getEcDecommissionReconstructionFallbackInsufficientSourcesTotal()); assertEquals(0, metrics.getEcDecommissionReconstructionFallbackTargetOverloadedTotal()); assertTrue(commandsSent.stream() - .anyMatch(c -> c.getValue() instanceof ReplicateContainerCommand)); + .anyMatch(c -> c.command() instanceof ReplicateContainerCommand)); assertTrue(commandsSent.stream() - .noneMatch(c -> c.getValue() instanceof ReconstructECContainersCommand)); + .noneMatch(c -> c.command() instanceof ReconstructECContainersCommand)); } @Test @@ -679,9 +674,9 @@ public void testUnderReplicationWithDecomNodesRethrowsOnPartialReconstruction() throws IOException { replicationManager.getConfig().setEcDecommissionReconstructionEnabled(true); Set availableReplicas = ReplicationTestUtil - .createReplicas(Pair.of(DECOMMISSIONING, 1), - Pair.of(DECOMMISSIONING, 2), Pair.of(IN_SERVICE, 3), - Pair.of(IN_SERVICE, 4), Pair.of(IN_SERVICE, 5)); + .createReplicas(new NodeOperationalStateAndIndex(DECOMMISSIONING, 1), + new NodeOperationalStateAndIndex(DECOMMISSIONING, 2), new NodeOperationalStateAndIndex(IN_SERVICE, 3), + new NodeOperationalStateAndIndex(IN_SERVICE, 4), new NodeOperationalStateAndIndex(IN_SERVICE, 5)); DatanodeDetails decomNode = availableReplicas.stream() .filter(r -> r.getReplicaIndex() == 1) @@ -714,10 +709,10 @@ public void testUnderReplicationWithDecomNodesRethrowsOnPartialReconstruction() result, remainingMaintenanceRedundancy)); assertEquals(1, commandsSent.stream() - .filter(c -> c.getValue() instanceof ReconstructECContainersCommand) + .filter(c -> c.command() instanceof ReconstructECContainersCommand) .count()); assertEquals(0, commandsSent.stream() - .filter(c -> c.getValue() instanceof ReplicateContainerCommand) + .filter(c -> c.command() instanceof ReplicateContainerCommand) .count()); assertEquals(0, metrics.getEcDecommissionReconstructionFallbackNoOpTotal()); assertEquals(1, metrics.getEcReconstructionDecommissionTriggeredTotal()); @@ -726,9 +721,9 @@ public void testUnderReplicationWithDecomNodesRethrowsOnPartialReconstruction() @Test public void testUnderReplicationWithDecomIndex12() throws IOException { Set availableReplicas = ReplicationTestUtil - .createReplicas(Pair.of(DECOMMISSIONING, 1), - Pair.of(DECOMMISSIONING, 2), Pair.of(IN_SERVICE, 3), - Pair.of(IN_SERVICE, 4), Pair.of(IN_SERVICE, 5)); + .createReplicas(new NodeOperationalStateAndIndex(DECOMMISSIONING, 1), + new NodeOperationalStateAndIndex(DECOMMISSIONING, 2), new NodeOperationalStateAndIndex(IN_SERVICE, 3), + new NodeOperationalStateAndIndex(IN_SERVICE, 4), new NodeOperationalStateAndIndex(IN_SERVICE, 5)); testUnderReplicationWithMissingIndexes(Lists.emptyList(), availableReplicas, 2, 0, policy); } @@ -737,9 +732,9 @@ public void testUnderReplicationWithDecomIndex12() throws IOException { public void testUnderReplicationWithMixedDecomAndMissingIndexes() throws IOException { Set availableReplicas = ReplicationTestUtil - .createReplicas(Pair.of(DECOMMISSIONING, 1), - Pair.of(DECOMMISSIONING, 2), Pair.of(IN_SERVICE, 3), - Pair.of(IN_SERVICE, 4)); + .createReplicas(new NodeOperationalStateAndIndex(DECOMMISSIONING, 1), + new NodeOperationalStateAndIndex(DECOMMISSIONING, 2), new NodeOperationalStateAndIndex(IN_SERVICE, 3), + new NodeOperationalStateAndIndex(IN_SERVICE, 4)); testUnderReplicationWithMissingIndexes(ImmutableList.of(5), availableReplicas, 2, 0, policy); } @@ -747,9 +742,9 @@ public void testUnderReplicationWithMixedDecomAndMissingIndexes() @Test public void testUnderReplicationWithMaintenanceIndex12() throws IOException { Set availableReplicas = ReplicationTestUtil - .createReplicas(Pair.of(IN_MAINTENANCE, 1), - Pair.of(IN_MAINTENANCE, 2), Pair.of(IN_SERVICE, 3), - Pair.of(IN_SERVICE, 4), Pair.of(IN_SERVICE, 5)); + .createReplicas(new NodeOperationalStateAndIndex(IN_MAINTENANCE, 1), + new NodeOperationalStateAndIndex(IN_MAINTENANCE, 2), new NodeOperationalStateAndIndex(IN_SERVICE, 3), + new NodeOperationalStateAndIndex(IN_SERVICE, 4), new NodeOperationalStateAndIndex(IN_SERVICE, 5)); testUnderReplicationWithMissingIndexes(Lists.emptyList(), availableReplicas, 0, 2, policy); } @@ -758,9 +753,9 @@ public void testUnderReplicationWithMaintenanceIndex12() throws IOException { public void testUnderReplicationWithMaintenanceAndMissingIndexes() throws IOException { Set availableReplicas = ReplicationTestUtil - .createReplicas(Pair.of(IN_MAINTENANCE, 1), - Pair.of(IN_MAINTENANCE, 2), Pair.of(IN_SERVICE, 3), - Pair.of(IN_SERVICE, 4)); + .createReplicas(new NodeOperationalStateAndIndex(IN_MAINTENANCE, 1), + new NodeOperationalStateAndIndex(IN_MAINTENANCE, 2), new NodeOperationalStateAndIndex(IN_SERVICE, 3), + new NodeOperationalStateAndIndex(IN_SERVICE, 4)); testUnderReplicationWithMissingIndexes(ImmutableList.of(5), availableReplicas, 0, 2, policy); } @@ -769,9 +764,9 @@ public void testUnderReplicationWithMaintenanceAndMissingIndexes() public void testUnderReplicationWithMissingDecomAndMaintenanceIndexes() throws IOException { Set availableReplicas = ReplicationTestUtil - .createReplicas(Pair.of(IN_MAINTENANCE, 1), - Pair.of(IN_MAINTENANCE, 2), Pair.of(DECOMMISSIONING, 3), - Pair.of(IN_SERVICE, 4)); + .createReplicas(new NodeOperationalStateAndIndex(IN_MAINTENANCE, 1), + new NodeOperationalStateAndIndex(IN_MAINTENANCE, 2), new NodeOperationalStateAndIndex(DECOMMISSIONING, 3), + new NodeOperationalStateAndIndex(IN_SERVICE, 4)); testUnderReplicationWithMissingIndexes(ImmutableList.of(5), availableReplicas, 1, 2, policy); } @@ -784,9 +779,9 @@ public void testUnderReplicationWithMissingDecomAndMaintenanceIndexes() public void testUnderReplicationWithInvalidPlacement() throws IOException { Set availableReplicas = ReplicationTestUtil - .createReplicas(Pair.of(DECOMMISSIONING, 1), - Pair.of(DECOMMISSIONING, 2), Pair.of(IN_SERVICE, 3), - Pair.of(IN_SERVICE, 4)); + .createReplicas(new NodeOperationalStateAndIndex(DECOMMISSIONING, 1), + new NodeOperationalStateAndIndex(DECOMMISSIONING, 2), new NodeOperationalStateAndIndex(IN_SERVICE, 3), + new NodeOperationalStateAndIndex(IN_SERVICE, 4)); PlacementPolicy mockedPolicy = spy(policy); ContainerPlacementStatus mockedContainerPlacementStatus = mock(ContainerPlacementStatus.class); @@ -813,9 +808,9 @@ public void testExceptionIfNoNodesFound() { PlacementPolicy noNodesPolicy = ReplicationTestUtil .getNoNodesTestPlacementPolicy(nodeManager, conf); Set availableReplicas = ReplicationTestUtil - .createReplicas(Pair.of(DECOMMISSIONING, 1), - Pair.of(DECOMMISSIONING, 2), Pair.of(IN_SERVICE, 3), - Pair.of(IN_SERVICE, 4)); + .createReplicas(new NodeOperationalStateAndIndex(DECOMMISSIONING, 1), + new NodeOperationalStateAndIndex(DECOMMISSIONING, 2), new NodeOperationalStateAndIndex(IN_SERVICE, 3), + new NodeOperationalStateAndIndex(IN_SERVICE, 4)); assertThrows(SCMException.class, () -> testUnderReplicationWithMissingIndexes(ImmutableList.of(5), availableReplicas, 2, 0, noNodesPolicy)); @@ -931,9 +926,9 @@ public void testUnhealthyNodeDeletedIfNoTargetsFound() for (ContainerReplica toAdd : replicasToAdd) { clearInvocations(replicationManager); Set existingReplicas = ReplicationTestUtil - .createReplicas(Pair.of(IN_SERVICE, 5), - Pair.of(IN_SERVICE, 2), Pair.of(IN_SERVICE, 3), - Pair.of(IN_SERVICE, 4)); + .createReplicas(new NodeOperationalStateAndIndex(IN_SERVICE, 5), + new NodeOperationalStateAndIndex(IN_SERVICE, 2), new NodeOperationalStateAndIndex(IN_SERVICE, 3), + new NodeOperationalStateAndIndex(IN_SERVICE, 4)); if (toAdd != null) { existingReplicas.add(toAdd); } @@ -963,9 +958,8 @@ public void testUnhealthyNodeDeletedIfNoTargetsFound() */ commandsSent.clear(); doAnswer(invocation -> { - commandsSent.add(Pair.of(invocation.getArgument(2), - createDeleteContainerCommand(invocation.getArgument(0), - invocation.getArgument(1)))); + commandsSent.add(new DatanodeCommand(invocation.getArgument(2), + createDeleteContainerCommand(invocation.getArgument(0), invocation.getArgument(1)))); return null; }) .when(replicationManager) @@ -981,18 +975,12 @@ public void testUnhealthyNodeDeletedIfNoTargetsFound() unhealthyReplica.getReplicaIndex(), unhealthyReplica.getDatanodeDetails(), true); assertEquals(1, commandsSent.size()); - Pair> command = - commandsSent.iterator().next(); - assertEquals(SCMCommandProto.Type.deleteContainerCommand, - command.getValue().getType()); - DeleteContainerCommand deleteCommand = - (DeleteContainerCommand) command.getValue(); - assertEquals(unhealthyReplica.getDatanodeDetails(), - command.getKey()); - assertEquals(container.containerID(), - ContainerID.valueOf(deleteCommand.getContainerID())); - assertEquals(unhealthyReplica.getReplicaIndex(), - deleteCommand.getReplicaIndex()); + DatanodeCommand command = commandsSent.iterator().next(); + assertEquals(SCMCommandProto.Type.deleteContainerCommand, command.command().getType()); + DeleteContainerCommand deleteCommand = (DeleteContainerCommand) command.command(); + assertEquals(unhealthyReplica.getDatanodeDetails(), command.datanode()); + assertEquals(container.containerID(), ContainerID.valueOf(deleteCommand.getContainerID())); + assertEquals(unhealthyReplica.getReplicaIndex(), deleteCommand.getReplicaIndex()); } } @@ -1012,8 +1000,7 @@ public void testPartialReconstructionIfNotEnoughNodes() { ecURH.processAndSendCommands(availableReplicas, emptyList(), underRep, 1)); assertEquals(1, commandsSent.size()); - ReconstructECContainersCommand cmd = (ReconstructECContainersCommand) - commandsSent.iterator().next().getValue(); + ReconstructECContainersCommand cmd = (ReconstructECContainersCommand) commandsSent.iterator().next().command(); assertEquals(1, cmd.getTargetDatanodes().size()); assertEquals(1, metrics.getEcPartialReconstructionNoneOverloadedTotal()); } @@ -1021,10 +1008,9 @@ public void testPartialReconstructionIfNotEnoughNodes() { @Test public void testOverloadedReconstructionContinuesNextStages() { Set availableReplicas = ReplicationTestUtil - .createReplicas(Pair.of(IN_SERVICE, 1), - Pair.of(IN_SERVICE, 2), Pair.of(DECOMMISSIONING, 3)); - ECUnderReplicationHandler ecURH = new ECUnderReplicationHandler( - policy, conf, replicationManager); + .createReplicas(new NodeOperationalStateAndIndex(IN_SERVICE, 1), + new NodeOperationalStateAndIndex(IN_SERVICE, 2), new NodeOperationalStateAndIndex(DECOMMISSIONING, 3)); + ECUnderReplicationHandler ecURH = new ECUnderReplicationHandler(policy, conf, replicationManager); UnderReplicatedHealthResult underRep = new UnderReplicatedHealthResult(container, @@ -1037,17 +1023,16 @@ public void testOverloadedReconstructionContinuesNextStages() { ecURH.processAndSendCommands(availableReplicas, emptyList(), underRep, 1)); assertEquals(1, commandsSent.size()); - SCMCommand cmd = commandsSent.iterator().next().getValue(); - assertEquals( - SCMCommandProto.Type.replicateContainerCommand, cmd.getType()); + SCMCommand cmd = commandsSent.iterator().next().command(); + assertEquals(SCMCommandProto.Type.replicateContainerCommand, cmd.getType()); } @Test public void testPartialDecommissionIfNotEnoughNodes() { Set availableReplicas = ReplicationTestUtil - .createReplicas(Pair.of(IN_SERVICE, 1), - Pair.of(IN_SERVICE, 2), Pair.of(IN_SERVICE, 3), - Pair.of(DECOMMISSIONING, 4), Pair.of(DECOMMISSIONING, 5)); + .createReplicas(new NodeOperationalStateAndIndex(IN_SERVICE, 1), + new NodeOperationalStateAndIndex(IN_SERVICE, 2), new NodeOperationalStateAndIndex(IN_SERVICE, 3), + new NodeOperationalStateAndIndex(DECOMMISSIONING, 4), new NodeOperationalStateAndIndex(DECOMMISSIONING, 5)); PlacementPolicy placementPolicy = ReplicationTestUtil .getInsufficientNodesTestPlacementPolicy(nodeManager, conf, 2); ECUnderReplicationHandler ecURH = new ECUnderReplicationHandler( @@ -1061,19 +1046,17 @@ public void testPartialDecommissionIfNotEnoughNodes() { ecURH.processAndSendCommands(availableReplicas, emptyList(), underRep, 1)); assertEquals(1, commandsSent.size()); - SCMCommand cmd = commandsSent.iterator().next().getValue(); - assertEquals( - SCMCommandProto.Type.replicateContainerCommand, cmd.getType()); - assertEquals(1, - metrics.getEcPartialReplicationForOutOfServiceReplicasTotal()); + SCMCommand cmd = commandsSent.iterator().next().command(); + assertEquals(SCMCommandProto.Type.replicateContainerCommand, cmd.getType()); + assertEquals(1, metrics.getEcPartialReplicationForOutOfServiceReplicasTotal()); } @Test public void testPartialDecommissionOverloadedNodes() { Set availableReplicas = ReplicationTestUtil - .createReplicas(Pair.of(IN_SERVICE, 1), - Pair.of(IN_SERVICE, 2), Pair.of(IN_SERVICE, 3), - Pair.of(DECOMMISSIONING, 4), Pair.of(DECOMMISSIONING, 5)); + .createReplicas(new NodeOperationalStateAndIndex(IN_SERVICE, 1), + new NodeOperationalStateAndIndex(IN_SERVICE, 2), new NodeOperationalStateAndIndex(IN_SERVICE, 3), + new NodeOperationalStateAndIndex(DECOMMISSIONING, 4), new NodeOperationalStateAndIndex(DECOMMISSIONING, 5)); ECUnderReplicationHandler ecURH = new ECUnderReplicationHandler( policy, conf, replicationManager); @@ -1086,7 +1069,7 @@ public void testPartialDecommissionOverloadedNodes() { ecURH.processAndSendCommands(availableReplicas, emptyList(), underRep, 1)); assertEquals(1, commandsSent.size()); - SCMCommand cmd = commandsSent.iterator().next().getValue(); + SCMCommand cmd = commandsSent.iterator().next().command(); assertEquals( SCMCommandProto.Type.replicateContainerCommand, cmd.getType()); // The partial recovery here is due to overloaded nodes, not insufficient @@ -1099,10 +1082,10 @@ public void testPartialDecommissionOverloadedNodes() { @Test public void testPartialMaintenanceIfNotEnoughNodes() { Set availableReplicas = ReplicationTestUtil - .createReplicas(Pair.of(IN_SERVICE, 1), - Pair.of(IN_SERVICE, 2), Pair.of(IN_SERVICE, 3), - Pair.of(ENTERING_MAINTENANCE, 4), - Pair.of(ENTERING_MAINTENANCE, 5)); + .createReplicas(new NodeOperationalStateAndIndex(IN_SERVICE, 1), + new NodeOperationalStateAndIndex(IN_SERVICE, 2), new NodeOperationalStateAndIndex(IN_SERVICE, 3), + new NodeOperationalStateAndIndex(ENTERING_MAINTENANCE, 4), + new NodeOperationalStateAndIndex(ENTERING_MAINTENANCE, 5)); PlacementPolicy placementPolicy = ReplicationTestUtil .getInsufficientNodesTestPlacementPolicy(nodeManager, conf, 2); ECUnderReplicationHandler ecURH = new ECUnderReplicationHandler( @@ -1116,20 +1099,18 @@ public void testPartialMaintenanceIfNotEnoughNodes() { ecURH.processAndSendCommands(availableReplicas, emptyList(), underRep, 2)); assertEquals(1, commandsSent.size()); - SCMCommand cmd = commandsSent.iterator().next().getValue(); - assertEquals( - SCMCommandProto.Type.replicateContainerCommand, cmd.getType()); - assertEquals(1, - metrics.getEcPartialReplicationForOutOfServiceReplicasTotal()); + SCMCommand cmd = commandsSent.iterator().next().command(); + assertEquals(SCMCommandProto.Type.replicateContainerCommand, cmd.getType()); + assertEquals(1, metrics.getEcPartialReplicationForOutOfServiceReplicasTotal()); } @Test public void testPartialMaintenanceOverloadedNodes() { Set availableReplicas = ReplicationTestUtil - .createReplicas(Pair.of(IN_SERVICE, 1), - Pair.of(IN_SERVICE, 2), Pair.of(IN_SERVICE, 3), - Pair.of(ENTERING_MAINTENANCE, 4), - Pair.of(ENTERING_MAINTENANCE, 5)); + .createReplicas(new NodeOperationalStateAndIndex(IN_SERVICE, 1), + new NodeOperationalStateAndIndex(IN_SERVICE, 2), new NodeOperationalStateAndIndex(IN_SERVICE, 3), + new NodeOperationalStateAndIndex(ENTERING_MAINTENANCE, 4), + new NodeOperationalStateAndIndex(ENTERING_MAINTENANCE, 5)); ECUnderReplicationHandler ecURH = new ECUnderReplicationHandler( policy, conf, replicationManager); @@ -1142,9 +1123,8 @@ public void testPartialMaintenanceOverloadedNodes() { ecURH.processAndSendCommands(availableReplicas, emptyList(), underRep, 2)); assertEquals(1, commandsSent.size()); - SCMCommand cmd = commandsSent.iterator().next().getValue(); - assertEquals( - SCMCommandProto.Type.replicateContainerCommand, cmd.getType()); + SCMCommand cmd = commandsSent.iterator().next().command(); + 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. @@ -1188,8 +1168,8 @@ public void testUnderRepWithDecommissionAndNotEnoughNodes() // entering_maintenance replica 5. Set availableReplicas = ReplicationTestUtil .createReplicas( - Pair.of(IN_SERVICE, 2), Pair.of(IN_SERVICE, 3), - Pair.of(IN_SERVICE, 4), Pair.of(IN_SERVICE, 4)); + new NodeOperationalStateAndIndex(IN_SERVICE, 2), new NodeOperationalStateAndIndex(IN_SERVICE, 3), + new NodeOperationalStateAndIndex(IN_SERVICE, 4), new NodeOperationalStateAndIndex(IN_SERVICE, 4)); if (toAdd != null) { availableReplicas.add(toAdd); } @@ -1201,12 +1181,10 @@ public void testUnderRepWithDecommissionAndNotEnoughNodes() verify(replicationManager, times(1)) .processOverReplicatedContainer(underRep); assertEquals(1, commandsSent.size()); - Pair> pair = - commandsSent.iterator().next(); - assertEquals(newNode, pair.getKey()); - assertEquals( - SCMCommandProto.Type.reconstructECContainersCommand, - pair.getValue().getType()); + DatanodeCommand pair = commandsSent.iterator().next(); + assertEquals(newNode, pair.datanode()); + assertEquals(SCMCommandProto.Type.reconstructECContainersCommand, + pair.command().getType()); clearInvocations(replicationManager); commandsSent.clear(); } @@ -1221,9 +1199,10 @@ public void testUnderRepDueToDecomAndOverRep() // found. This will cause an exception to be thrown out, as the container is // not also over replicated. Set availableReplicas = ReplicationTestUtil - .createReplicas(Pair.of(IN_SERVICE, 1), - Pair.of(IN_SERVICE, 2), Pair.of(IN_SERVICE, 3), - Pair.of(IN_SERVICE, 4), Pair.of(DECOMMISSIONING, 5)); + .createReplicas(new NodeOperationalStateAndIndex(IN_SERVICE, 1), + new NodeOperationalStateAndIndex(IN_SERVICE, 2), + new NodeOperationalStateAndIndex(IN_SERVICE, 3), new NodeOperationalStateAndIndex(IN_SERVICE, 4), + new NodeOperationalStateAndIndex(DECOMMISSIONING, 5)); ECUnderReplicationHandler ecURH = new ECUnderReplicationHandler( @@ -1244,9 +1223,8 @@ public void testUnderRepDueToDecomAndOverRep() 4, IN_SERVICE, CLOSED); availableReplicas.add(overRepReplica); - Set>> expectedDelete = new HashSet<>(); - expectedDelete.add(Pair.of(overRepReplica.getDatanodeDetails(), - createDeleteContainerCommand(container, + Set expectedDelete = new HashSet<>(); + expectedDelete.add(new DatanodeCommand(overRepReplica.getDatanodeDetails(), createDeleteContainerCommand(container, overRepReplica.getReplicaIndex()))); when(replicationManager.processOverReplicatedContainer( @@ -1269,9 +1247,9 @@ public void testMissingAndDecomIndexWithOnlyOneNewNodeAvailable() .getSameNodeTestPlacementPolicy(nodeManager, conf, newDn); // Just have a missing index, this should return OK. Set availableReplicas = ReplicationTestUtil - .createReplicas(Pair.of(IN_SERVICE, 1), - Pair.of(IN_SERVICE, 2), Pair.of(IN_SERVICE, 3), - Pair.of(IN_SERVICE, 4)); + .createReplicas(new NodeOperationalStateAndIndex(IN_SERVICE, 1), + new NodeOperationalStateAndIndex(IN_SERVICE, 2), + new NodeOperationalStateAndIndex(IN_SERVICE, 3), new NodeOperationalStateAndIndex(IN_SERVICE, 4)); // Passing zero for decommIndexes, as we don't expect the decom command to // get created due to the placement policy returning an already used node testUnderReplicationWithMissingIndexes(ImmutableList.of(5), @@ -1283,9 +1261,9 @@ public void testMissingAndDecomIndexWithOnlyOneNewNodeAvailable() // come up the stack and be thrown out to indicate this container must be // retried. Set replicas = ReplicationTestUtil - .createReplicas(Pair.of(DECOMMISSIONING, 1), - Pair.of(IN_SERVICE, 2), Pair.of(IN_SERVICE, 3), - Pair.of(IN_SERVICE, 4), Pair.of(IN_SERVICE, 4)); + .createReplicas(new NodeOperationalStateAndIndex(DECOMMISSIONING, 1), + new NodeOperationalStateAndIndex(IN_SERVICE, 2), new NodeOperationalStateAndIndex(IN_SERVICE, 3), + new NodeOperationalStateAndIndex(IN_SERVICE, 4), new NodeOperationalStateAndIndex(IN_SERVICE, 4)); assertThrows(SCMException.class, () -> testUnderReplicationWithMissingIndexes(ImmutableList.of(5), replicas, @@ -1295,15 +1273,15 @@ public void testMissingAndDecomIndexWithOnlyOneNewNodeAvailable() @Test public void testUnderAndOverReplication() throws IOException { Set availableReplicas = ReplicationTestUtil - .createReplicas(Pair.of(DECOMMISSIONING, 1), Pair.of(IN_SERVICE, 1), - Pair.of(IN_MAINTENANCE, 1), Pair.of(IN_MAINTENANCE, 1), - Pair.of(IN_SERVICE, 4), Pair.of(IN_SERVICE, 5)); - Set>> cmds = - testUnderReplicationWithMissingIndexes(ImmutableList.of(2, 3), + .createReplicas(new NodeOperationalStateAndIndex(DECOMMISSIONING, 1), + new NodeOperationalStateAndIndex(IN_SERVICE, 1), new NodeOperationalStateAndIndex(IN_MAINTENANCE, 1), + new NodeOperationalStateAndIndex(IN_MAINTENANCE, 1), new NodeOperationalStateAndIndex(IN_SERVICE, 4), + new NodeOperationalStateAndIndex(IN_SERVICE, 5)); + Set cmds = testUnderReplicationWithMissingIndexes(ImmutableList.of(2, 3), availableReplicas, 0, 0, policy); assertEquals(1, cmds.size()); ReconstructECContainersCommand cmd = - (ReconstructECContainersCommand) cmds.iterator().next().getValue(); + (ReconstructECContainersCommand) cmds.iterator().next().command(); // Ensure that all source nodes are IN_SERVICE, we should not have picked // the non in-service nodes for index 1. for (ReconstructECContainersCommand.DatanodeDetailsAndReplicaIndex s @@ -1321,9 +1299,9 @@ public void testUnderAndOverReplication() throws IOException { @Test public void testMaintenanceDoesNotRequestZeroNodes() throws IOException { Set availableReplicas = ReplicationTestUtil - .createReplicas(Pair.of(DECOMMISSIONING, 1), Pair.of(IN_SERVICE, 2), - Pair.of(IN_MAINTENANCE, 3), Pair.of(IN_SERVICE, 4), - Pair.of(IN_SERVICE, 5)); + .createReplicas(new NodeOperationalStateAndIndex(DECOMMISSIONING, 1), + new NodeOperationalStateAndIndex(IN_SERVICE, 2), new NodeOperationalStateAndIndex(IN_MAINTENANCE, 3), + new NodeOperationalStateAndIndex(IN_SERVICE, 4), new NodeOperationalStateAndIndex(IN_SERVICE, 5)); when(ecPlacementPolicy.chooseDatanodes(anyList(), anyList(), isNull(), anyInt(), anyLong(), anyLong())) @@ -1390,24 +1368,22 @@ public void testDatanodesPendingAddAreNotSelectedAsTargets() handler.processAndSendCommands(availableReplicas, pendingOps, result, 1); assertEquals(1, commandsSent.size()); - assertNotEquals(dn, commandsSent.iterator().next().getKey()); + assertNotEquals(dn, commandsSent.iterator().next().datanode()); } @Test public void testDecommissioningIndexCopiedWhenContainerUnRecoverable() throws IOException { Set availableReplicas = ReplicationTestUtil - .createReplicas(Pair.of(IN_SERVICE, 1)); + .createReplicas(new NodeOperationalStateAndIndex(IN_SERVICE, 1)); ContainerReplica decomReplica = createContainerReplica( container.containerID(), 2, DECOMMISSIONING, CLOSED); availableReplicas.add(decomReplica); - Set>> cmds = - testUnderReplicationWithMissingIndexes(emptyList(), - availableReplicas, 1, 0, policy); + Set cmds = testUnderReplicationWithMissingIndexes(emptyList(), availableReplicas, 1, 0, policy); assertEquals(1, cmds.size()); // With push replication the command should always be sent to the // decommissioning source. - DatanodeDetails target = cmds.iterator().next().getKey(); + DatanodeDetails target = cmds.iterator().next().datanode(); assertEquals(decomReplica.getDatanodeDetails(), target); } @@ -1415,13 +1391,11 @@ public void testDecommissioningIndexCopiedWhenContainerUnRecoverable() public void testMaintenanceIndexCopiedWhenContainerUnRecoverable() throws IOException { Set availableReplicas = ReplicationTestUtil - .createReplicas(Pair.of(IN_SERVICE, 1)); - ContainerReplica maintReplica = createContainerReplica( - container.containerID(), 2, ENTERING_MAINTENANCE, CLOSED); + .createReplicas(new NodeOperationalStateAndIndex(IN_SERVICE, 1)); + ContainerReplica maintReplica = createContainerReplica(container.containerID(), 2, ENTERING_MAINTENANCE, CLOSED); availableReplicas.add(maintReplica); - Set>> cmds = - testUnderReplicationWithMissingIndexes(emptyList(), + Set cmds = testUnderReplicationWithMissingIndexes(emptyList(), availableReplicas, 0, 1, policy); assertEquals(0, cmds.size()); @@ -1433,12 +1407,11 @@ public void testMaintenanceIndexCopiedWhenContainerUnRecoverable() assertEquals(1, cmds.size()); // With push replication the command should always be sent to the // entering_maintenance source. - DatanodeDetails target = cmds.iterator().next().getKey(); + DatanodeDetails target = cmds.iterator().next().datanode(); assertEquals(maintReplica.getDatanodeDetails(), target); } - public Set>> - testUnderReplicationWithMissingIndexes( + public Set testUnderReplicationWithMissingIndexes( List missingIndexes, Set availableReplicas, int decomIndexes, int maintenanceIndexes, PlacementPolicy placementPolicy) throws IOException { @@ -1457,15 +1430,13 @@ public void testMaintenanceIndexCopiedWhenContainerUnRecoverable() boolean shouldReconstructCommandExist = !missingIndexes.isEmpty() && missingIndexes.size() <= repConfig .getParity(); - for (Map.Entry> dnCommand : commandsSent) { - if (dnCommand.getValue() instanceof ReplicateContainerCommand) { + for (DatanodeCommand dnCommand : commandsSent) { + if (dnCommand.command() instanceof ReplicateContainerCommand) { replicateCommand++; - } else if (dnCommand - .getValue() instanceof ReconstructECContainersCommand) { + } else if (dnCommand.command() instanceof ReconstructECContainersCommand) { if (shouldReconstructCommandExist) { assertEquals(ECUnderReplicationHandler.integers2ByteString(missingIndexes), - ((ReconstructECContainersCommand) dnCommand.getValue()) - .getMissingContainerIndexes()); + ((ReconstructECContainersCommand) dnCommand.command()).getMissingContainerIndexes()); } reconstructCommand++; } diff --git a/hadoop-hdds/server-scm/src/test/java/org/apache/hadoop/hdds/scm/container/replication/TestQuasiClosedStuckOverReplicationHandler.java b/hadoop-hdds/server-scm/src/test/java/org/apache/hadoop/hdds/scm/container/replication/TestQuasiClosedStuckOverReplicationHandler.java index b1aa74916736..dd4563c2204b 100644 --- a/hadoop-hdds/server-scm/src/test/java/org/apache/hadoop/hdds/scm/container/replication/TestQuasiClosedStuckOverReplicationHandler.java +++ b/hadoop-hdds/server-scm/src/test/java/org/apache/hadoop/hdds/scm/container/replication/TestQuasiClosedStuckOverReplicationHandler.java @@ -33,7 +33,6 @@ import java.util.List; import java.util.Set; import java.util.concurrent.atomic.AtomicBoolean; -import org.apache.commons.lang3.tuple.Pair; import org.apache.hadoop.hdds.client.RatisReplicationConfig; import org.apache.hadoop.hdds.conf.OzoneConfiguration; import org.apache.hadoop.hdds.protocol.DatanodeDetails; @@ -43,6 +42,8 @@ import org.apache.hadoop.hdds.protocol.proto.StorageContainerDatanodeProtocolProtos; import org.apache.hadoop.hdds.scm.container.ContainerInfo; import org.apache.hadoop.hdds.scm.container.ContainerReplica; +import org.apache.hadoop.hdds.scm.container.replication.ReplicationTestUtil.DatanodeCommand; +import org.apache.hadoop.hdds.scm.container.replication.ReplicationTestUtil.NodeOperationalStateAndOrigin; import org.apache.hadoop.hdds.scm.node.NodeStatus; import org.apache.hadoop.hdds.scm.node.states.NodeNotFoundException; import org.apache.hadoop.ozone.protocol.commands.SCMCommand; @@ -58,7 +59,7 @@ public class TestQuasiClosedStuckOverReplicationHandler { private static final RatisReplicationConfig RATIS_REPLICATION_CONFIG = RatisReplicationConfig.getInstance(THREE); private ContainerInfo container; private ReplicationManager replicationManager; - private Set>> commandsSent; + private Set commandsSent; private QuasiClosedStuckOverReplicationHandler handler; private final DatanodeID origin1 = DatanodeID.randomID(); private final DatanodeID origin2 = DatanodeID.randomID(); @@ -98,10 +99,10 @@ void setup() throws NodeNotFoundException, public void testReturnsZeroIfNotOverReplicated() throws IOException { Set replicas = ReplicationTestUtil.createReplicasWithOriginAndOpState(container.containerID(), QUASI_CLOSED, - Pair.of(origin1, IN_SERVICE), - Pair.of(origin1, IN_SERVICE), - Pair.of(origin2, IN_SERVICE), - Pair.of(origin2, IN_SERVICE)); + new NodeOperationalStateAndOrigin(origin1, IN_SERVICE), + new NodeOperationalStateAndOrigin(origin1, IN_SERVICE), + new NodeOperationalStateAndOrigin(origin2, IN_SERVICE), + new NodeOperationalStateAndOrigin(origin2, IN_SERVICE)); int count = handler.processAndSendCommands(replicas, Collections.emptyList(), getOverReplicatedHealthResult(), 1); assertEquals(0, count); @@ -111,12 +112,12 @@ public void testReturnsZeroIfNotOverReplicated() throws IOException { public void testNoCommandsScheduledIfPendingOps() throws IOException { Set replicas = ReplicationTestUtil.createReplicasWithOriginAndOpState(container.containerID(), QUASI_CLOSED, - Pair.of(origin1, IN_SERVICE), - Pair.of(origin1, IN_SERVICE), - Pair.of(origin1, IN_SERVICE), - Pair.of(origin2, IN_SERVICE), - Pair.of(origin2, IN_SERVICE), - Pair.of(origin2, IN_SERVICE)); + new NodeOperationalStateAndOrigin(origin1, IN_SERVICE), + new NodeOperationalStateAndOrigin(origin1, IN_SERVICE), + new NodeOperationalStateAndOrigin(origin1, IN_SERVICE), + new NodeOperationalStateAndOrigin(origin2, IN_SERVICE), + new NodeOperationalStateAndOrigin(origin2, IN_SERVICE), + new NodeOperationalStateAndOrigin(origin2, IN_SERVICE)); List pendingOps = new ArrayList<>(); pendingOps.add(new ContainerReplicaOp( ContainerReplicaOp.PendingOpType.DELETE, @@ -150,7 +151,7 @@ public void testCommandScheduledForOverReplicatedContainer() throws IOException int count = handler.processAndSendCommands(replicas, Collections.emptyList(), getOverReplicatedHealthResult(), 1); assertEquals(1, count); - SCMCommand command = commandsSent.iterator().next().getRight(); + SCMCommand command = commandsSent.iterator().next().command(); assertEquals(StorageContainerDatanodeProtocolProtos.SCMCommandProto.Type.deleteContainerCommand, command.getType()); } diff --git a/hadoop-hdds/server-scm/src/test/java/org/apache/hadoop/hdds/scm/container/replication/TestQuasiClosedStuckReplicaCount.java b/hadoop-hdds/server-scm/src/test/java/org/apache/hadoop/hdds/scm/container/replication/TestQuasiClosedStuckReplicaCount.java index bfa27006d54a..cc8e2893b23e 100644 --- a/hadoop-hdds/server-scm/src/test/java/org/apache/hadoop/hdds/scm/container/replication/TestQuasiClosedStuckReplicaCount.java +++ b/hadoop-hdds/server-scm/src/test/java/org/apache/hadoop/hdds/scm/container/replication/TestQuasiClosedStuckReplicaCount.java @@ -30,10 +30,10 @@ import java.util.HashSet; import java.util.List; import java.util.Set; -import org.apache.commons.lang3.tuple.Pair; import org.apache.hadoop.hdds.protocol.DatanodeID; import org.apache.hadoop.hdds.scm.container.ContainerID; import org.apache.hadoop.hdds.scm.container.ContainerReplica; +import org.apache.hadoop.hdds.scm.container.replication.ReplicationTestUtil.NodeOperationalStateAndOrigin; import org.junit.jupiter.api.Test; /** @@ -82,7 +82,8 @@ public void testCorrectReplicationWithTwoOrigins() { public void testCorrectReplicationWithOneOrigin() { Set replicas = ReplicationTestUtil.createReplicasWithOriginAndOpState( ContainerID.valueOf(1), QUASI_CLOSED, - Pair.of(origin1, IN_SERVICE), Pair.of(origin1, IN_SERVICE), Pair.of(origin1, IN_SERVICE)); + new NodeOperationalStateAndOrigin(origin1, IN_SERVICE), new NodeOperationalStateAndOrigin(origin1, IN_SERVICE), + new NodeOperationalStateAndOrigin(origin1, IN_SERVICE)); QuasiClosedStuckReplicaCount replicaCount = new QuasiClosedStuckReplicaCount(replicas, 1, 3, 2); assertFalse(replicaCount.isUnderReplicated()); @@ -155,7 +156,7 @@ public void testUnderReplicationWithTwoOrigins() { public void testUnderReplicationWithOneOrigin() { Set replicas = ReplicationTestUtil.createReplicasWithOriginAndOpState( ContainerID.valueOf(1), QUASI_CLOSED, - Pair.of(origin1, IN_SERVICE)); + new NodeOperationalStateAndOrigin(origin1, IN_SERVICE)); QuasiClosedStuckReplicaCount replicaCount = new QuasiClosedStuckReplicaCount(replicas, 1, 3, 2); assertTrue(replicaCount.isUnderReplicated()); @@ -202,8 +203,8 @@ public void testOverReplicationWithTwoOrigins() { public void testOverReplicationWithOneOrigin() { Set replicas = ReplicationTestUtil.createReplicasWithOriginAndOpState( ContainerID.valueOf(1), QUASI_CLOSED, - Pair.of(origin1, IN_SERVICE), Pair.of(origin1, IN_SERVICE), Pair.of(origin1, IN_SERVICE), - Pair.of(origin1, IN_SERVICE)); + new NodeOperationalStateAndOrigin(origin1, IN_SERVICE), new NodeOperationalStateAndOrigin(origin1, IN_SERVICE), + new NodeOperationalStateAndOrigin(origin1, IN_SERVICE), new NodeOperationalStateAndOrigin(origin1, IN_SERVICE)); QuasiClosedStuckReplicaCount replicaCount = new QuasiClosedStuckReplicaCount(replicas, 1, 3, 2); assertFalse(replicaCount.isUnderReplicated()); @@ -251,7 +252,9 @@ public void testUnderReplicationDueToDecommissionWithTwoOrigins() { public void testUnderReplicationDueToDecommissionWithOneOrigin() { Set replicas = ReplicationTestUtil.createReplicasWithOriginAndOpState( ContainerID.valueOf(1), QUASI_CLOSED, - Pair.of(origin1, IN_SERVICE), Pair.of(origin1, DECOMMISSIONING), Pair.of(origin1, DECOMMISSIONING)); + new NodeOperationalStateAndOrigin(origin1, IN_SERVICE), + new NodeOperationalStateAndOrigin(origin1, DECOMMISSIONING), + new NodeOperationalStateAndOrigin(origin1, DECOMMISSIONING)); QuasiClosedStuckReplicaCount replicaCount = new QuasiClosedStuckReplicaCount(replicas, 1, 3, 2); assertTrue(replicaCount.isUnderReplicated()); @@ -300,8 +303,9 @@ public void testNoOverReplicationWithOutOfServiceReplicasWithTwoOrigins() { public void testNoOverReplicationWithOutOfServiceReplicasWithOneOrigin() { Set replicas = ReplicationTestUtil.createReplicasWithOriginAndOpState( ContainerID.valueOf(1), QUASI_CLOSED, - Pair.of(origin1, IN_SERVICE), Pair.of(origin1, IN_SERVICE), Pair.of(origin1, IN_SERVICE), - Pair.of(origin1, DECOMMISSIONED)); + new NodeOperationalStateAndOrigin(origin1, IN_SERVICE), new NodeOperationalStateAndOrigin(origin1, IN_SERVICE), + new NodeOperationalStateAndOrigin(origin1, IN_SERVICE), + new NodeOperationalStateAndOrigin(origin1, DECOMMISSIONED)); QuasiClosedStuckReplicaCount replicaCount = new QuasiClosedStuckReplicaCount(replicas, 1, 3, 2); assertFalse(replicaCount.isUnderReplicated()); @@ -312,7 +316,8 @@ public void testNoOverReplicationWithOutOfServiceReplicasWithOneOrigin() { public void testUnderReplicationWithMaintenanceWithOneOrigin() { Set replicas = ReplicationTestUtil.createReplicasWithOriginAndOpState( ContainerID.valueOf(1), QUASI_CLOSED, - Pair.of(origin1, IN_SERVICE), Pair.of(origin1, IN_SERVICE), Pair.of(origin1, ENTERING_MAINTENANCE)); + new NodeOperationalStateAndOrigin(origin1, IN_SERVICE), new NodeOperationalStateAndOrigin(origin1, IN_SERVICE), + new NodeOperationalStateAndOrigin(origin1, ENTERING_MAINTENANCE)); QuasiClosedStuckReplicaCount replicaCount = new QuasiClosedStuckReplicaCount(replicas, 1, 3, 2); assertFalse(replicaCount.isUnderReplicated()); @@ -320,7 +325,9 @@ public void testUnderReplicationWithMaintenanceWithOneOrigin() { replicas = ReplicationTestUtil.createReplicasWithOriginAndOpState( ContainerID.valueOf(1), QUASI_CLOSED, - Pair.of(origin1, IN_SERVICE), Pair.of(origin1, ENTERING_MAINTENANCE), Pair.of(origin1, ENTERING_MAINTENANCE)); + new NodeOperationalStateAndOrigin(origin1, IN_SERVICE), + new NodeOperationalStateAndOrigin(origin1, ENTERING_MAINTENANCE), + new NodeOperationalStateAndOrigin(origin1, ENTERING_MAINTENANCE)); replicaCount = new QuasiClosedStuckReplicaCount(replicas, 2, 3, 2); assertTrue(replicaCount.isUnderReplicated()); @@ -381,8 +388,9 @@ public void testNoOverReplicationWithExcessMaintenanceReplicasTwoOrigins() { public void testNoOverReplicationWithExcessMaintenanceReplicasOneOrigin() { Set replicas = ReplicationTestUtil.createReplicasWithOriginAndOpState( ContainerID.valueOf(1), QUASI_CLOSED, - Pair.of(origin1, IN_SERVICE), Pair.of(origin1, IN_SERVICE), Pair.of(origin1, IN_SERVICE), - Pair.of(origin1, IN_MAINTENANCE)); + new NodeOperationalStateAndOrigin(origin1, IN_SERVICE), new NodeOperationalStateAndOrigin(origin1, IN_SERVICE), + new NodeOperationalStateAndOrigin(origin1, IN_SERVICE), + new NodeOperationalStateAndOrigin(origin1, IN_MAINTENANCE)); QuasiClosedStuckReplicaCount replicaCount = new QuasiClosedStuckReplicaCount(replicas, 1, 3, 2); assertFalse(replicaCount.isUnderReplicated()); diff --git a/hadoop-hdds/server-scm/src/test/java/org/apache/hadoop/hdds/scm/container/replication/TestQuasiClosedStuckUnderReplicationHandler.java b/hadoop-hdds/server-scm/src/test/java/org/apache/hadoop/hdds/scm/container/replication/TestQuasiClosedStuckUnderReplicationHandler.java index 73734b373676..be21aaa8c120 100644 --- a/hadoop-hdds/server-scm/src/test/java/org/apache/hadoop/hdds/scm/container/replication/TestQuasiClosedStuckUnderReplicationHandler.java +++ b/hadoop-hdds/server-scm/src/test/java/org/apache/hadoop/hdds/scm/container/replication/TestQuasiClosedStuckUnderReplicationHandler.java @@ -34,7 +34,6 @@ import java.util.List; import java.util.Set; import java.util.concurrent.atomic.AtomicBoolean; -import org.apache.commons.lang3.tuple.Pair; import org.apache.hadoop.hdds.client.RatisReplicationConfig; import org.apache.hadoop.hdds.conf.OzoneConfiguration; import org.apache.hadoop.hdds.protocol.DatanodeDetails; @@ -44,13 +43,14 @@ import org.apache.hadoop.hdds.scm.PlacementPolicy; import org.apache.hadoop.hdds.scm.container.ContainerInfo; import org.apache.hadoop.hdds.scm.container.ContainerReplica; +import org.apache.hadoop.hdds.scm.container.replication.ReplicationTestUtil.DatanodeCommand; +import org.apache.hadoop.hdds.scm.container.replication.ReplicationTestUtil.NodeOperationalStateAndOrigin; import org.apache.hadoop.hdds.scm.exceptions.SCMException; import org.apache.hadoop.hdds.scm.node.NodeManager; import org.apache.hadoop.hdds.scm.node.NodeStatus; import org.apache.hadoop.hdds.scm.node.states.NodeNotFoundException; import org.apache.hadoop.hdds.scm.pipeline.InsufficientDatanodesException; import org.apache.hadoop.ozone.container.common.SCMTestUtils; -import org.apache.hadoop.ozone.protocol.commands.SCMCommand; import org.apache.ratis.protocol.exceptions.NotLeaderException; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; @@ -66,7 +66,7 @@ public class TestQuasiClosedStuckUnderReplicationHandler { private NodeManager nodeManager; private OzoneConfiguration conf; private ReplicationManager replicationManager; - private Set>> commandsSent; + private Set commandsSent; private QuasiClosedStuckUnderReplicationHandler handler; @BeforeEach @@ -114,7 +114,9 @@ void setup(@TempDir File testDir) throws NodeNotFoundException, public void testReturnsZeroIfNotUnderReplicated() throws IOException { final DatanodeID origin = DatanodeID.randomID(); Set replicas = ReplicationTestUtil.createReplicasWithOriginAndOpState(container.containerID(), - QUASI_CLOSED, Pair.of(origin, IN_SERVICE), Pair.of(origin, IN_SERVICE), Pair.of(origin, IN_SERVICE)); + QUASI_CLOSED, new NodeOperationalStateAndOrigin(origin, IN_SERVICE), + new NodeOperationalStateAndOrigin(origin, IN_SERVICE), + new NodeOperationalStateAndOrigin(origin, IN_SERVICE)); int count = handler.processAndSendCommands(replicas, Collections.emptyList(), getUnderReplicatedHealthResult(), 1); assertEquals(0, count); @@ -124,7 +126,8 @@ public void testReturnsZeroIfNotUnderReplicated() throws IOException { public void testNoCommandsScheduledIfPendingOps() throws IOException { final DatanodeID origin = DatanodeID.randomID(); Set replicas = ReplicationTestUtil.createReplicasWithOriginAndOpState(container.containerID(), - QUASI_CLOSED, Pair.of(origin, IN_SERVICE), Pair.of(origin, IN_SERVICE)); + QUASI_CLOSED, new NodeOperationalStateAndOrigin(origin, IN_SERVICE), + new NodeOperationalStateAndOrigin(origin, IN_SERVICE)); List pendingOps = new ArrayList<>(); pendingOps.add(new ContainerReplicaOp( ContainerReplicaOp.PendingOpType.ADD, MockDatanodeDetails.randomDatanodeDetails(), 0, null, Long.MAX_VALUE, 0)); @@ -137,7 +140,7 @@ public void testNoCommandsScheduledIfPendingOps() throws IOException { public void testCommandScheduledForUnderReplicatedContainer() throws IOException { final DatanodeID origin = DatanodeID.randomID(); Set replicas = ReplicationTestUtil.createReplicasWithOriginAndOpState(container.containerID(), - QUASI_CLOSED, Pair.of(origin, IN_SERVICE)); + QUASI_CLOSED, new NodeOperationalStateAndOrigin(origin, IN_SERVICE)); int count = handler.processAndSendCommands(replicas, Collections.emptyList(), getUnderReplicatedHealthResult(), 1); assertEquals(2, count); @@ -168,7 +171,8 @@ public void testInsufficientNodesExceptionThrown() { final DatanodeID origin1 = DatanodeID.randomID(); final DatanodeID origin2 = DatanodeID.randomID(); Set replicas = ReplicationTestUtil.createReplicasWithOriginAndOpState(container.containerID(), - QUASI_CLOSED, Pair.of(origin1, IN_SERVICE), Pair.of(origin2, IN_SERVICE)); + QUASI_CLOSED, new NodeOperationalStateAndOrigin(origin1, IN_SERVICE), + new NodeOperationalStateAndOrigin(origin2, IN_SERVICE)); PlacementPolicy policy = ReplicationTestUtil.getNoNodesTestPlacementPolicy(nodeManager, conf); handler = new QuasiClosedStuckUnderReplicationHandler(policy, conf, replicationManager); @@ -182,7 +186,7 @@ public void testInsufficientNodesExceptionThrown() { public void testPartialReplicationExceptionThrown() { final DatanodeID origin1 = DatanodeID.randomID(); Set replicas = ReplicationTestUtil.createReplicasWithOriginAndOpState(container.containerID(), - QUASI_CLOSED, Pair.of(origin1, IN_SERVICE)); + QUASI_CLOSED, new NodeOperationalStateAndOrigin(origin1, IN_SERVICE)); PlacementPolicy policy = ReplicationTestUtil.getInsufficientNodesTestPlacementPolicy(nodeManager, conf, 2); handler = new QuasiClosedStuckUnderReplicationHandler(policy, conf, replicationManager); diff --git a/hadoop-hdds/server-scm/src/test/java/org/apache/hadoop/hdds/scm/container/replication/TestRatisMisReplicationHandler.java b/hadoop-hdds/server-scm/src/test/java/org/apache/hadoop/hdds/scm/container/replication/TestRatisMisReplicationHandler.java index 47352876009e..890c33bdea2a 100644 --- a/hadoop-hdds/server-scm/src/test/java/org/apache/hadoop/hdds/scm/container/replication/TestRatisMisReplicationHandler.java +++ b/hadoop-hdds/server-scm/src/test/java/org/apache/hadoop/hdds/scm/container/replication/TestRatisMisReplicationHandler.java @@ -41,7 +41,6 @@ import java.util.List; import java.util.Map; import java.util.Set; -import org.apache.commons.lang3.tuple.Pair; import org.apache.hadoop.hdds.client.RatisReplicationConfig; import org.apache.hadoop.hdds.conf.OzoneConfiguration; import org.apache.hadoop.hdds.protocol.DatanodeDetails; @@ -56,6 +55,7 @@ import org.apache.hadoop.hdds.scm.container.ContainerReplica; import org.apache.hadoop.hdds.scm.container.placement.algorithms.SCMContainerPlacementMetrics; import org.apache.hadoop.hdds.scm.container.placement.algorithms.SCMContainerPlacementRackAware; +import org.apache.hadoop.hdds.scm.container.replication.ReplicationTestUtil.NodeOperationalStateAndIndex; import org.apache.hadoop.hdds.scm.exceptions.SCMException; import org.apache.hadoop.hdds.scm.net.NetworkTopology; import org.apache.hadoop.hdds.scm.net.NetworkTopologyImpl; @@ -91,8 +91,9 @@ void setup(@TempDir File testDir) throws NodeNotFoundException, public void testMisReplicationWithAllNodesAvailable(int misreplicationCount) throws IOException { Set availableReplicas = ReplicationTestUtil - .createReplicas(Pair.of(IN_SERVICE, 0), Pair.of(IN_SERVICE, 0), - Pair.of(IN_SERVICE, 0)); + .createReplicas(new NodeOperationalStateAndIndex(IN_SERVICE, 0), + new NodeOperationalStateAndIndex(IN_SERVICE, 0), + new NodeOperationalStateAndIndex(IN_SERVICE, 0)); testMisReplication(availableReplicas, Collections.emptyList(), 0, misreplicationCount, Math.min(misreplicationCount, 3)); } @@ -102,8 +103,8 @@ public void testMisReplicationWithAllNodesAvailable(int misreplicationCount) public void testMisReplicationWithAllNodesAvailableQuasiClosed( int misreplicationCount) throws IOException { Set availableReplicas = ReplicationTestUtil - .createReplicas(State.QUASI_CLOSED, Pair.of(IN_SERVICE, 0), - Pair.of(IN_SERVICE, 0), Pair.of(IN_SERVICE, 0)); + .createReplicas(State.QUASI_CLOSED, new NodeOperationalStateAndIndex(IN_SERVICE, 0), + new NodeOperationalStateAndIndex(IN_SERVICE, 0), new NodeOperationalStateAndIndex(IN_SERVICE, 0)); testMisReplication(availableReplicas, Collections.emptyList(), 0, misreplicationCount, Math.min(misreplicationCount, 3)); } @@ -111,8 +112,8 @@ public void testMisReplicationWithAllNodesAvailableQuasiClosed( @Test public void testMisReplicationWithNoNodesReturned() throws IOException { Set availableReplicas = ReplicationTestUtil - .createReplicas(Pair.of(IN_SERVICE, 0), Pair.of(IN_SERVICE, 0), - Pair.of(IN_SERVICE, 0)); + .createReplicas(new NodeOperationalStateAndIndex(IN_SERVICE, 0), + new NodeOperationalStateAndIndex(IN_SERVICE, 0), new NodeOperationalStateAndIndex(IN_SERVICE, 0)); PlacementPolicy placementPolicy = mock(PlacementPolicy.class); ContainerPlacementStatus mockedContainerPlacementStatus = mock(ContainerPlacementStatus.class); when(mockedContainerPlacementStatus.isPolicySatisfied()).thenReturn(false); @@ -132,8 +133,9 @@ public void testMisReplicationWithNoNodesReturned() throws IOException { public void testMisReplicationWithSomeNodesNotInService( int misreplicationCount) throws IOException { Set availableReplicas = ReplicationTestUtil - .createReplicas(Pair.of(IN_SERVICE, 0), Pair.of(IN_SERVICE, 0), - Pair.of(IN_MAINTENANCE, 0)); + .createReplicas(new NodeOperationalStateAndIndex(IN_SERVICE, 0), + new NodeOperationalStateAndIndex(IN_SERVICE, 0), + new NodeOperationalStateAndIndex(IN_MAINTENANCE, 0)); testMisReplication(availableReplicas, Collections.emptyList(), 0, misreplicationCount, Math.min(misreplicationCount, 2)); } @@ -141,16 +143,17 @@ public void testMisReplicationWithSomeNodesNotInService( @Test public void testMisReplicationWithUndereplication() throws IOException { Set availableReplicas = ReplicationTestUtil - .createReplicas(Pair.of(IN_SERVICE, 0), - Pair.of(IN_SERVICE, 0)); + .createReplicas(new NodeOperationalStateAndIndex(IN_SERVICE, 0), + new NodeOperationalStateAndIndex(IN_SERVICE, 0)); testMisReplication(availableReplicas, Collections.emptyList(), 0, 1, 0); } @Test public void testMisReplicationWithOvereplication() throws IOException { Set availableReplicas = ReplicationTestUtil - .createReplicas(Pair.of(IN_SERVICE, 0), Pair.of(IN_SERVICE, 0), - Pair.of(IN_SERVICE, 0), Pair.of(IN_SERVICE, 0)); + .createReplicas(new NodeOperationalStateAndIndex(IN_SERVICE, 0), + new NodeOperationalStateAndIndex(IN_SERVICE, 0), new NodeOperationalStateAndIndex(IN_SERVICE, 0), + new NodeOperationalStateAndIndex(IN_SERVICE, 0)); testMisReplication(availableReplicas, Collections.emptyList(), 0, 1, 0); } @@ -158,8 +161,8 @@ public void testMisReplicationWithOvereplication() throws IOException { public void testMisReplicationWithSatisfiedPlacementPolicy() throws IOException { Set availableReplicas = ReplicationTestUtil - .createReplicas(Pair.of(IN_SERVICE, 0), Pair.of(IN_SERVICE, 0), - Pair.of(IN_SERVICE, 0)); + .createReplicas(new NodeOperationalStateAndIndex(IN_SERVICE, 0), + new NodeOperationalStateAndIndex(IN_SERVICE, 0), new NodeOperationalStateAndIndex(IN_SERVICE, 0)); PlacementPolicy placementPolicy = mock(PlacementPolicy.class); ContainerPlacementStatus mockedContainerPlacementStatus = mock(ContainerPlacementStatus.class); when(mockedContainerPlacementStatus.isPolicySatisfied()).thenReturn(true); @@ -173,8 +176,8 @@ public void testMisReplicationWithSatisfiedPlacementPolicy() public void testMisReplicationWithPendingOps() throws IOException { Set availableReplicas = ReplicationTestUtil - .createReplicas(Pair.of(IN_SERVICE, 0), Pair.of(IN_SERVICE, 0), - Pair.of(IN_SERVICE, 0)); + .createReplicas(new NodeOperationalStateAndIndex(IN_SERVICE, 0), + new NodeOperationalStateAndIndex(IN_SERVICE, 0), new NodeOperationalStateAndIndex(IN_SERVICE, 0)); PlacementPolicy placementPolicy = mock(PlacementPolicy.class); ContainerPlacementStatus mockedContainerPlacementStatus = mock(ContainerPlacementStatus.class); when(mockedContainerPlacementStatus.isPolicySatisfied()).thenReturn(true); @@ -195,7 +198,9 @@ public void testMisReplicationWithPendingOps() @Test public void testCopyIsSkippedUntilItReducesMisReplication() throws IOException { Set availableReplicas = ReplicationTestUtil - .createReplicas(Pair.of(IN_SERVICE, 0), Pair.of(IN_SERVICE, 0), Pair.of(IN_SERVICE, 0)); + .createReplicas(new NodeOperationalStateAndIndex(IN_SERVICE, 0), + new NodeOperationalStateAndIndex(IN_SERVICE, 0), + new NodeOperationalStateAndIndex(IN_SERVICE, 0)); // The target doesn't help, e.g. because it is on the same rack as all the existing replicas. PlacementPolicy placementPolicy = mock(PlacementPolicy.class); ContainerPlacementStatus mockedContainerPlacementStatus = mock(ContainerPlacementStatus.class); @@ -261,8 +266,9 @@ public void testAllSourcesOverloaded() throws IOException { anyList(), any(), anyInt()); Set availableReplicas = ReplicationTestUtil - .createReplicas(Pair.of(IN_SERVICE, 0), Pair.of(IN_SERVICE, 0), - Pair.of(IN_SERVICE, 0)); + .createReplicas(new NodeOperationalStateAndIndex(IN_SERVICE, 0), + new NodeOperationalStateAndIndex(IN_SERVICE, 0), + new NodeOperationalStateAndIndex(IN_SERVICE, 0)); assertThrows(CommandTargetOverloadedException.class, () -> testMisReplication(availableReplicas, mockPlacementPolicy(), Collections.emptyList(), 0, 1, 1, 0)); diff --git a/hadoop-hdds/server-scm/src/test/java/org/apache/hadoop/hdds/scm/container/replication/TestRatisOverReplicationHandler.java b/hadoop-hdds/server-scm/src/test/java/org/apache/hadoop/hdds/scm/container/replication/TestRatisOverReplicationHandler.java index 84dabae7686a..8fe72d3cdb82 100644 --- a/hadoop-hdds/server-scm/src/test/java/org/apache/hadoop/hdds/scm/container/replication/TestRatisOverReplicationHandler.java +++ b/hadoop-hdds/server-scm/src/test/java/org/apache/hadoop/hdds/scm/container/replication/TestRatisOverReplicationHandler.java @@ -47,7 +47,6 @@ import java.util.Set; import java.util.concurrent.atomic.AtomicBoolean; import java.util.stream.Collectors; -import org.apache.commons.lang3.tuple.Pair; import org.apache.hadoop.hdds.client.RatisReplicationConfig; import org.apache.hadoop.hdds.protocol.DatanodeDetails; import org.apache.hadoop.hdds.protocol.MockDatanodeDetails; @@ -58,10 +57,10 @@ import org.apache.hadoop.hdds.scm.container.ContainerInfo; import org.apache.hadoop.hdds.scm.container.ContainerReplica; import org.apache.hadoop.hdds.scm.container.placement.algorithms.ContainerPlacementStatusDefault; +import org.apache.hadoop.hdds.scm.container.replication.ReplicationTestUtil.DatanodeCommand; import org.apache.hadoop.hdds.scm.node.NodeStatus; import org.apache.hadoop.hdds.scm.node.states.NodeNotFoundException; import org.apache.hadoop.ozone.protocol.commands.DeleteContainerCommand; -import org.apache.hadoop.ozone.protocol.commands.SCMCommand; import org.apache.ozone.test.GenericTestUtils; import org.apache.ratis.protocol.exceptions.NotLeaderException; import org.junit.jupiter.api.BeforeEach; @@ -78,7 +77,7 @@ public class TestRatisOverReplicationHandler { RatisReplicationConfig.getInstance(HddsProtos.ReplicationFactor.THREE); private PlacementPolicy policy; private ReplicationManager replicationManager; - private Set>> commandsSent; + private Set commandsSent; @BeforeEach public void setup() throws NodeNotFoundException, NotLeaderException, @@ -238,13 +237,11 @@ public void testClosedOverReplicatedWithExcessUnhealthy() throws IOException { State.UNHEALTHY); replicas.add(unhealthyReplica); - Set>> commands = - testProcessing(replicas, Collections.emptyList(), - getOverReplicatedHealthResult(), - 1); - Pair> command = commands.iterator().next(); + Set commands = + testProcessing(replicas, Collections.emptyList(), getOverReplicatedHealthResult(), 1); + DatanodeCommand command = commands.iterator().next(); assertEquals(unhealthyReplica.getDatanodeDetails(), - command.getKey()); + command.datanode()); } /** @@ -310,13 +307,10 @@ public void testOverReplicatedAllUnhealthySameBCSID() .sorted(Comparator.comparingLong(ContainerReplica::hashCode)) .findFirst().get(); - Set>> commands = - testProcessing(replicas, Collections.emptyList(), - getOverReplicatedHealthResult(), 1); - Pair> commandPair - = commands.iterator().next(); - assertEquals(shouldDelete.getDatanodeDetails(), - commandPair.getKey()); + Set commands = + testProcessing(replicas, Collections.emptyList(), getOverReplicatedHealthResult(), 1); + DatanodeCommand commandPair = commands.iterator().next(); + assertEquals(shouldDelete.getDatanodeDetails(), commandPair.datanode()); } @Test @@ -331,13 +325,10 @@ public void testOverReplicatedAllUnhealthyPicksLowestBCSID() replicas.add(createContainerReplica(container.containerID(), 0, IN_SERVICE, State.UNHEALTHY, sequenceID + i)); } - Set>> commands = - testProcessing(replicas, Collections.emptyList(), - getOverReplicatedHealthResult(), 1); - Pair> commandPair - = commands.iterator().next(); - assertEquals(lowestSequenceIDReplica.getDatanodeDetails(), - commandPair.getKey()); + Set commands = testProcessing(replicas, Collections.emptyList(), + getOverReplicatedHealthResult(), 1); + DatanodeCommand commandPair = commands.iterator().next(); + assertEquals(lowestSequenceIDReplica.getDatanodeDetails(), commandPair.datanode()); } /** @@ -366,10 +357,9 @@ public void testOverReplicatedClosedContainerWithQuasiClosedReplica() argThat(list -> list.size() <= 4), anyInt())) .thenReturn(new ContainerPlacementStatusDefault(1, 2, 3)); - Set>> commands = testProcessing( + Set commands = testProcessing( replicas, Collections.emptyList(), getOverReplicatedHealthResult(), 2); - Set datanodes = - commands.stream().map(Pair::getKey).collect(Collectors.toSet()); + Set datanodes = commands.stream().map(DatanodeCommand::datanode).collect(Collectors.toSet()); assertThat(datanodes).contains(quasiClosedReplica.getDatanodeDetails()); } @@ -389,10 +379,9 @@ public void testOverReplicatedWithDecomAndMaintenanceReplicas() replicas.add(decommissioningReplica); replicas.add(maintenanceReplica); - Set>> commands = testProcessing( + Set commands = testProcessing( replicas, Collections.emptyList(), getOverReplicatedHealthResult(), 1); - Set datanodes = - commands.stream().map(Pair::getKey).collect(Collectors.toSet()); + Set datanodes = commands.stream().map(DatanodeCommand::datanode).collect(Collectors.toSet()); assertThat(datanodes).doesNotContain(decommissioningReplica.getDatanodeDetails()); assertThat(datanodes).doesNotContain(maintenanceReplica.getDatanodeDetails()); } @@ -476,9 +465,8 @@ public void testDeleteThrottlingMisMatchedReplica() throws IOException { () -> handler.processAndSendCommands(replicas, Collections.emptyList(), getOverReplicatedHealthResult(), 2)); assertEquals(1, commandsSent.size()); - Pair> cmd = commandsSent.iterator().next(); - assertNotEquals(quasiClosedReplica.getDatanodeDetails(), - cmd.getKey()); + DatanodeCommand cmd = commandsSent.iterator().next(); + assertNotEquals(quasiClosedReplica.getDatanodeDetails(), cmd.datanode()); } @Test @@ -501,7 +489,7 @@ public void testDeleteThrottling() throws IOException { DeleteContainerCommand deleteCommand = new DeleteContainerCommand( containerInfo.getContainerID(), forceDelete); deleteCommand.setReplicaIndex(replicaIndex); - commandsSent.add(Pair.of(target, deleteCommand)); + commandsSent.add(new DatanodeCommand(target, deleteCommand)); return null; }).when(replicationManager) .sendThrottledDeleteCommand(any(), anyInt(), any(), anyBoolean()); @@ -530,7 +518,7 @@ public void testDeleteThrottling() throws IOException { * the handler * @return set of commands */ - private Set>> testProcessing( + private Set testProcessing( Set replicas, List pendingOps, ContainerHealthResult healthResult, int expectNumCommands) throws IOException { diff --git a/hadoop-hdds/server-scm/src/test/java/org/apache/hadoop/hdds/scm/container/replication/TestRatisUnderReplicationHandler.java b/hadoop-hdds/server-scm/src/test/java/org/apache/hadoop/hdds/scm/container/replication/TestRatisUnderReplicationHandler.java index b368e56150ed..1b542f02d712 100644 --- a/hadoop-hdds/server-scm/src/test/java/org/apache/hadoop/hdds/scm/container/replication/TestRatisUnderReplicationHandler.java +++ b/hadoop-hdds/server-scm/src/test/java/org/apache/hadoop/hdds/scm/container/replication/TestRatisUnderReplicationHandler.java @@ -49,7 +49,6 @@ import java.util.List; import java.util.Set; import java.util.concurrent.atomic.AtomicBoolean; -import org.apache.commons.lang3.tuple.Pair; import org.apache.hadoop.hdds.client.RatisReplicationConfig; import org.apache.hadoop.hdds.conf.OzoneConfiguration; import org.apache.hadoop.hdds.protocol.DatanodeDetails; @@ -62,12 +61,13 @@ import org.apache.hadoop.hdds.scm.container.ContainerReplica; import org.apache.hadoop.hdds.scm.container.replication.ContainerHealthResult.UnderReplicatedHealthResult; import org.apache.hadoop.hdds.scm.container.replication.ReplicationManager.ReplicationManagerConfiguration; +import org.apache.hadoop.hdds.scm.container.replication.ReplicationTestUtil.DatanodeCommand; +import org.apache.hadoop.hdds.scm.container.replication.ReplicationTestUtil.NodeOperationalStateAndIndex; import org.apache.hadoop.hdds.scm.node.NodeManager; import org.apache.hadoop.hdds.scm.node.NodeStatus; import org.apache.hadoop.hdds.scm.node.states.NodeNotFoundException; import org.apache.hadoop.hdds.scm.pipeline.InsufficientDatanodesException; import org.apache.hadoop.ozone.container.common.SCMTestUtils; -import org.apache.hadoop.ozone.protocol.commands.SCMCommand; import org.apache.ratis.protocol.exceptions.NotLeaderException; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; @@ -85,7 +85,7 @@ public class TestRatisUnderReplicationHandler { RatisReplicationConfig.getInstance(THREE); private PlacementPolicy policy; private ReplicationManager replicationManager; - private Set>> commandsSent; + private Set commandsSent; private ReplicationManagerMetrics metrics; @BeforeEach @@ -179,8 +179,8 @@ public void testUnderReplicatedFixedByPendingAdd() throws IOException { public void testUnderReplicatedBecauseOfDecommissioningReplica() throws IOException { Set replicas = ReplicationTestUtil - .createReplicas(Pair.of(DECOMMISSIONING, 0), Pair.of(IN_SERVICE, 0), - Pair.of(IN_SERVICE, 0)); + .createReplicas(new NodeOperationalStateAndIndex(DECOMMISSIONING, 0), + new NodeOperationalStateAndIndex(IN_SERVICE, 0), new NodeOperationalStateAndIndex(IN_SERVICE, 0)); testProcessing(replicas, Collections.emptyList(), getUnderReplicatedHealthResult(), 2, 1); @@ -195,8 +195,8 @@ public void testUnderReplicatedBecauseOfDecommissioningReplica() public void testUnderReplicatedBecauseOfMaintenanceReplica() throws IOException { Set replicas = ReplicationTestUtil - .createReplicas(Pair.of(ENTERING_MAINTENANCE, 0), - Pair.of(IN_SERVICE, 0), Pair.of(IN_SERVICE, 0)); + .createReplicas(new NodeOperationalStateAndIndex(ENTERING_MAINTENANCE, 0), + new NodeOperationalStateAndIndex(IN_SERVICE, 0), new NodeOperationalStateAndIndex(IN_SERVICE, 0)); testProcessing(replicas, Collections.emptyList(), getUnderReplicatedHealthResult(), 3, 1); @@ -210,8 +210,8 @@ public void testUnderReplicatedBecauseOfMaintenanceReplica() public void testSufficientlyReplicatedDespiteMaintenanceReplica() throws IOException { Set replicas = ReplicationTestUtil - .createReplicas(Pair.of(ENTERING_MAINTENANCE, 0), - Pair.of(IN_SERVICE, 0), Pair.of(IN_SERVICE, 0)); + .createReplicas(new NodeOperationalStateAndIndex(ENTERING_MAINTENANCE, 0), + new NodeOperationalStateAndIndex(IN_SERVICE, 0), new NodeOperationalStateAndIndex(IN_SERVICE, 0)); testProcessing(replicas, Collections.emptyList(), getUnderReplicatedHealthResult(), 2, 0); @@ -315,10 +315,10 @@ public void testNoTargetsFoundBecauseOfPlacementPolicyRemoveUnhealthy() { () -> handler.processAndSendCommands(replicas, Collections.emptyList(), getUnderReplicatedHealthResult(), 2)); assertEquals(1, commandsSent.size()); - Pair> cmd = commandsSent.iterator().next(); - assertEquals(shouldDelete.getDatanodeDetails(), cmd.getKey()); + DatanodeCommand cmd = commandsSent.iterator().next(); + assertEquals(shouldDelete.getDatanodeDetails(), cmd.datanode()); assertEquals(StorageContainerDatanodeProtocolProtos.SCMCommandProto - .Type.deleteContainerCommand, cmd.getValue().getType()); + .Type.deleteContainerCommand, cmd.command().getType()); } @Test @@ -375,10 +375,10 @@ public void testNoTargetsFoundRemoveQuasiClosedWithLowestSeq() { () -> handler.processAndSendCommands(replicas, Collections.emptyList(), getUnderReplicatedHealthResult(), 2)); assertEquals(1, commandsSent.size()); - Pair> cmd = commandsSent.iterator().next(); - assertEquals(shouldDelete.getDatanodeDetails(), cmd.getKey()); + DatanodeCommand cmd = commandsSent.iterator().next(); + assertEquals(shouldDelete.getDatanodeDetails(), cmd.datanode()); assertEquals(StorageContainerDatanodeProtocolProtos.SCMCommandProto - .Type.deleteContainerCommand, cmd.getValue().getType()); + .Type.deleteContainerCommand, cmd.command().getType()); } @Test @@ -400,7 +400,7 @@ public void testDecommissionWithAllUnhealthyReplicas() Set replicas = createReplicas(container.containerID(), State.UNHEALTHY, 0, 0); replicas.addAll(createReplicas(container.containerID(), State.UNHEALTHY, - Pair.of(DECOMMISSIONING, 0))); + new NodeOperationalStateAndIndex(DECOMMISSIONING, 0))); testProcessing(replicas, Collections.emptyList(), getUnderReplicatedHealthResult(), 2, 1); @@ -415,12 +415,10 @@ public void onlyHealthyReplicasShouldBeReplicatedWhenAvailable() container.containerID(), 0, IN_SERVICE, State.CLOSED); replicas.add(closedReplica); - Set>> commands = - testProcessing(replicas, Collections.emptyList(), - getUnderReplicatedHealthResult(), 2, 2); - commands.forEach( - command -> assertEquals(closedReplica.getDatanodeDetails(), - command.getKey())); + Set commands = + testProcessing(replicas, Collections.emptyList(), getUnderReplicatedHealthResult(), 2, 2); + commands.forEach(command -> assertEquals(closedReplica.getDatanodeDetails(), + command.datanode())); } /** @@ -438,12 +436,10 @@ public void testUnderReplicationBecauseOfUnhealthyReplica() container.containerID(), 0, IN_SERVICE, State.UNHEALTHY); replicas.add(unhealthyReplica); - Set>> commands = - testProcessing(replicas, Collections.emptyList(), + Set commands = testProcessing(replicas, Collections.emptyList(), getUnderReplicatedHealthResult(), 2, 1); - commands.forEach( - command -> assertNotEquals(unhealthyReplica.getDatanodeDetails(), - command.getKey())); + commands.forEach(command -> assertNotEquals(unhealthyReplica.getDatanodeDetails(), + command.datanode())); } @Test @@ -543,13 +539,10 @@ public void testUnderReplicationDueToQuasiClosedReplicaWithWrongSequenceID() IN_SERVICE, State.QUASI_CLOSED, sequenceID - 1); replicas.add(quasiClosedReplica); - final Set>> commands = - testProcessing(replicas, Collections.emptyList(), - getUnderReplicatedHealthResult(), 2, 2); - commands.forEach( - command -> assertNotEquals( - quasiClosedReplica.getDatanodeDetails(), - command.getKey())); + final Set commands = + testProcessing(replicas, Collections.emptyList(), getUnderReplicatedHealthResult(), 2, 2); + commands.forEach(command -> assertNotEquals(quasiClosedReplica.getDatanodeDetails(), + command.datanode())); } /** @@ -575,9 +568,8 @@ public void testUnderReplicationWithVulnerableReplicas() throws IOException { UnderReplicatedHealthResult result = getUnderReplicatedHealthResult(); when(result.hasVulnerableUnhealthy()).thenReturn(true); - final Set>> commands = testProcessing(replicas, Collections.emptyList(), - result, 2, 1); - assertEquals(unhealthyReplica.getDatanodeDetails(), commands.iterator().next().getKey()); + final Set commands = testProcessing(replicas, Collections.emptyList(), result, 2, 1); + assertEquals(unhealthyReplica.getDatanodeDetails(), commands.iterator().next().datanode()); } /** @@ -604,9 +596,8 @@ public void testUnderReplicationWithVulnerableReplicasOnUniqueOrigins() throws I UnderReplicatedHealthResult result = getUnderReplicatedHealthResult(); when(result.hasVulnerableUnhealthy()).thenReturn(true); - final Set>> commands = testProcessing(replicas, Collections.emptyList(), - result, 2, 1); - assertEquals(unhealthyReplica.getDatanodeDetails(), commands.iterator().next().getKey()); + final Set commands = testProcessing(replicas, Collections.emptyList(), result, 2, 1); + assertEquals(unhealthyReplica.getDatanodeDetails(), commands.iterator().next().datanode()); } /** @@ -647,7 +638,7 @@ public void testUnderReplicationWithVulnerableReplicasAndTargetOverloadedExcepti assertThrows(CommandTargetOverloadedException.class, () -> handler.processAndSendCommands(replicas, Collections.emptyList(), result, 2)); assertEquals(1, commandsSent.size()); - DatanodeDetails dn = commandsSent.iterator().next().getKey(); + DatanodeDetails dn = commandsSent.iterator().next().datanode(); assertTrue(unhealthyReplica.getDatanodeDetails().equals(dn) || unhealthyReplica2.getDatanodeDetails().equals(dn)); } @@ -664,13 +655,10 @@ public void testOnlyQuasiClosedReplicaWithWrongSequenceIdIsAvailable() IN_SERVICE, State.QUASI_CLOSED, sequenceID - 1); replicas.add(quasiClosedReplica); - final Set>> commands = - testProcessing(replicas, Collections.emptyList(), + final Set commands = testProcessing(replicas, Collections.emptyList(), getUnderReplicatedHealthResult(), 2, 2); - commands.forEach( - command -> assertEquals( - quasiClosedReplica.getDatanodeDetails(), - command.getKey())); + commands.forEach(command -> assertEquals(quasiClosedReplica.getDatanodeDetails(), + command.datanode())); } @Test @@ -687,12 +675,10 @@ public void testOnlyClosedReplicasOfClosedContainersAreSources() replicas.add(createContainerReplica(container.containerID(), 0, IN_SERVICE, State.QUASI_CLOSED, 1)); - final Set>> commands = - testProcessing(replicas, Collections.emptyList(), - getUnderReplicatedHealthResult(), 2, 1); - commands.forEach( - command -> assertEquals(closedReplica.getDatanodeDetails(), - command.getKey())); + final Set commands = + testProcessing(replicas, Collections.emptyList(), getUnderReplicatedHealthResult(), 2, 1); + commands.forEach(command -> assertEquals(closedReplica.getDatanodeDetails(), + command.datanode())); } @Test @@ -733,7 +719,7 @@ public void testQuasiClosedReplicasAreSourcesWhenOnlyTheyAreAvailable() * @param expectNumCommands number of commands expected to be created by * the handler */ - private Set>> testProcessing( + private Set testProcessing( Set replicas, List pendingOps, ContainerHealthResult healthResult, int minHealthyForMaintenance, int expectNumCommands) throws IOException { diff --git a/hadoop-hdds/server-scm/src/test/java/org/apache/hadoop/hdds/scm/container/replication/TestReplicationManager.java b/hadoop-hdds/server-scm/src/test/java/org/apache/hadoop/hdds/scm/container/replication/TestReplicationManager.java index 90711f5df05a..0d6fc50bc052 100644 --- a/hadoop-hdds/server-scm/src/test/java/org/apache/hadoop/hdds/scm/container/replication/TestReplicationManager.java +++ b/hadoop-hdds/server-scm/src/test/java/org/apache/hadoop/hdds/scm/container/replication/TestReplicationManager.java @@ -71,7 +71,6 @@ import java.util.concurrent.atomic.AtomicBoolean; import java.util.concurrent.atomic.AtomicInteger; import java.util.function.Function; -import org.apache.commons.lang3.tuple.Pair; import org.apache.hadoop.hdds.ComponentVersion; import org.apache.hadoop.hdds.HDDSVersion; import org.apache.hadoop.hdds.client.ECReplicationConfig; @@ -94,6 +93,8 @@ import org.apache.hadoop.hdds.scm.container.ContainerReplica; import org.apache.hadoop.hdds.scm.container.ReplicationManagerReport; import org.apache.hadoop.hdds.scm.container.placement.algorithms.ContainerPlacementStatusDefault; +import org.apache.hadoop.hdds.scm.container.replication.ReplicationTestUtil.DatanodeIdCommand; +import org.apache.hadoop.hdds.scm.container.replication.ReplicationTestUtil.NodeOperationalStateAndIndex; import org.apache.hadoop.hdds.scm.events.SCMEvents; import org.apache.hadoop.hdds.scm.exceptions.SCMException; import org.apache.hadoop.hdds.scm.ha.SCMContext; @@ -145,7 +146,7 @@ public class TestReplicationManager { private ReplicationConfig repConfig; private ReplicationManagerReport repReport; private ReplicationQueue repQueue; - private Set>> commandsSent; + private Set commandsSent; @BeforeEach public void setup() throws IOException, NodeNotFoundException { @@ -167,7 +168,7 @@ public void setup() throws IOException, NodeNotFoundException { commandsSent = new HashSet<>(); eventPublisher = mock(EventPublisher.class); doAnswer(invocation -> { - commandsSent.add(Pair.of(invocation.getArgument(0), + commandsSent.add(new DatanodeIdCommand(invocation.getArgument(0), invocation.getArgument(1))); return null; }).when(nodeManager).addDatanodeCommand(any(), any()); @@ -419,10 +420,8 @@ public void testQuasiClosedContainerWithExcessUnhealthyReplica() handler.processAndSendCommands(replicas, Collections.emptyList(), repQueue.dequeueOverReplicatedContainer(), 2); assertTrue(commandsSent.iterator().hasNext()); - assertEquals(unhealthy.getDatanodeDetails().getID(), - commandsSent.iterator().next().getKey()); - assertEquals(SCMCommandProto.Type.deleteContainerCommand, - commandsSent.iterator().next().getValue().getType()); + assertEquals(unhealthy.getDatanodeDetails().getID(), commandsSent.iterator().next().datanodeId()); + assertEquals(SCMCommandProto.Type.deleteContainerCommand, commandsSent.iterator().next().command().getType()); } @@ -893,17 +892,12 @@ public void testUnderReplicationBlockedByUnhealthyReplicas() // a delete command should also have been sent for UNHEALTHY replica of // index 1 assertEquals(1, commandsSent.size()); - Pair> command = commandsSent.iterator().next(); - assertEquals(SCMCommandProto.Type.deleteContainerCommand, - command.getValue().getType()); - DeleteContainerCommand deleteCommand = - (DeleteContainerCommand) command.getValue(); - assertEquals(unhealthyReplica1.getDatanodeDetails().getID(), - command.getKey()); - assertEquals(container.containerID(), - ContainerID.valueOf(deleteCommand.getContainerID())); - assertEquals(unhealthyReplica1.getReplicaIndex(), - deleteCommand.getReplicaIndex()); + DatanodeIdCommand command = commandsSent.iterator().next(); + assertEquals(SCMCommandProto.Type.deleteContainerCommand, command.command().getType()); + DeleteContainerCommand deleteCommand = (DeleteContainerCommand) command.command(); + assertEquals(unhealthyReplica1.getDatanodeDetails().getID(), command.datanodeId()); + assertEquals(container.containerID(), ContainerID.valueOf(deleteCommand.getContainerID())); + assertEquals(unhealthyReplica1.getReplicaIndex(), deleteCommand.getReplicaIndex()); } @Test @@ -1046,9 +1040,9 @@ public void testUnderReplicationQueuePopulated() { ContainerInfo decomContainer = createContainerInfo(repConfig, 1, HddsProtos.LifeCycleState.CLOSED); addReplicas(decomContainer, ContainerReplicaProto.State.CLOSED, - Pair.of(DECOMMISSIONING, 1), - Pair.of(DECOMMISSIONING, 2), Pair.of(DECOMMISSIONING, 3), - Pair.of(DECOMMISSIONING, 4), Pair.of(DECOMMISSIONING, 5)); + new NodeOperationalStateAndIndex(DECOMMISSIONING, 1), + new NodeOperationalStateAndIndex(DECOMMISSIONING, 2), new NodeOperationalStateAndIndex(DECOMMISSIONING, 3), + new NodeOperationalStateAndIndex(DECOMMISSIONING, 4), new NodeOperationalStateAndIndex(DECOMMISSIONING, 5)); ContainerInfo underRep1 = createContainerInfo(repConfig, 2, HddsProtos.LifeCycleState.CLOSED); @@ -1331,12 +1325,10 @@ private void testReplicationCommand( container, new ArrayList<>(sourceNodes), destination, replicaIndex); assertEquals(1, commandsSent.size()); - Pair> cmdWithTarget = commandsSent.iterator().next(); - assertEquals(expectedTarget.getID(), cmdWithTarget.getLeft()); - assertEquals(ReplicateContainerCommand.class, - cmdWithTarget.getRight().getClass()); - ReplicateContainerCommand cmd = - (ReplicateContainerCommand) cmdWithTarget.getRight(); + DatanodeIdCommand cmdWithTarget = commandsSent.iterator().next(); + assertEquals(expectedTarget.getID(), cmdWithTarget.datanodeId()); + assertEquals(ReplicateContainerCommand.class, cmdWithTarget.command().getClass()); + ReplicateContainerCommand cmd = (ReplicateContainerCommand) cmdWithTarget.command(); assertEquals(destination, cmd.getTargetDatanode()); assertEquals(replicaIndex, cmd.getReplicaIndex()); } @@ -1393,10 +1385,9 @@ public void testSendThrottledReconstructionCommand() replicationManager.sendThrottledReconstructionCommand(container, command); assertEquals(1, commandsSent.size()); - Pair> cmd = commandsSent.iterator().next(); - assertEquals(cmdTarget.getID(), cmd.getLeft()); - assertEquals(0, replicationManager.getMetrics() - .getEcReconstructionCmdsDeferredTotal()); + DatanodeIdCommand cmd = commandsSent.iterator().next(); + assertEquals(cmdTarget.getID(), cmd.datanodeId()); + assertEquals(0, replicationManager.getMetrics().getEcReconstructionCmdsDeferredTotal()); } @Test @@ -1476,9 +1467,8 @@ private void assertReconstructionCarriesLowestApparentVersion(boolean sourceIsLo replicationManager.sendThrottledReconstructionCommand(container, command); assertEquals(1, commandsSent.size()); - Pair> cmd = commandsSent.iterator().next(); - ReconstructECContainersCommand sent = - (ReconstructECContainersCommand) cmd.getValue(); + DatanodeIdCommand cmd = commandsSent.iterator().next(); + ReconstructECContainersCommand sent = (ReconstructECContainersCommand) cmd.command(); assertEquals(lower, sent.getApparentVersion()); } @@ -1675,10 +1665,10 @@ public void testPendingOpExpiry() throws ContainerNotFoundException { replicationManager.opCompleted(delOp, ContainerID.valueOf(1L), true); assertEquals(1, commandsSent.size()); - Pair> sentCommand = commandsSent.iterator().next(); + DatanodeIdCommand sentCommand = commandsSent.iterator().next(); // The target should be DN2 and the deadline should have been updated from the value set in commandDeadline above - assertEquals(dn2.getID(), sentCommand.getLeft()); - assertNotEquals(commandDeadline, sentCommand.getRight().getDeadline()); + assertEquals(dn2.getID(), sentCommand.datanodeId()); + assertNotEquals(commandDeadline, sentCommand.command().getDeadline()); } @ParameterizedTest @@ -1796,7 +1786,7 @@ public void testReconfigureContainerSampleLimit() { @SafeVarargs private final Set addReplicas(ContainerInfo container, ContainerReplicaProto.State replicaState, - Pair... nodes) { + NodeOperationalStateAndIndex... nodes) { final Set replicas = createReplicas(container.containerID(), replicaState, nodes); storeContainerAndReplicas(container, replicas); diff --git a/hadoop-hdds/server-scm/src/test/java/org/apache/hadoop/hdds/scm/container/replication/TestReplicationManagerScenarios.java b/hadoop-hdds/server-scm/src/test/java/org/apache/hadoop/hdds/scm/container/replication/TestReplicationManagerScenarios.java index 15cce574ee95..9fc984da7079 100644 --- a/hadoop-hdds/server-scm/src/test/java/org/apache/hadoop/hdds/scm/container/replication/TestReplicationManagerScenarios.java +++ b/hadoop-hdds/server-scm/src/test/java/org/apache/hadoop/hdds/scm/container/replication/TestReplicationManagerScenarios.java @@ -44,7 +44,6 @@ import java.util.Map; import java.util.Set; import java.util.stream.Stream; -import org.apache.commons.lang3.tuple.Pair; import org.apache.hadoop.hdds.HDDSVersion; import org.apache.hadoop.hdds.client.ECReplicationConfig; import org.apache.hadoop.hdds.client.RatisReplicationConfig; @@ -63,6 +62,7 @@ import org.apache.hadoop.hdds.scm.container.ContainerManager; import org.apache.hadoop.hdds.scm.container.ContainerReplica; import org.apache.hadoop.hdds.scm.container.ReplicationManagerReport; +import org.apache.hadoop.hdds.scm.container.replication.ReplicationTestUtil.DatanodeIdCommand; import org.apache.hadoop.hdds.scm.ha.SCMContext; import org.apache.hadoop.hdds.scm.node.DatanodeInfo; import org.apache.hadoop.hdds.scm.node.NodeManager; @@ -70,7 +70,6 @@ import org.apache.hadoop.hdds.scm.node.states.NodeNotFoundException; import org.apache.hadoop.hdds.server.events.EventPublisher; import org.apache.hadoop.ozone.protocol.commands.ReplicateContainerCommand; -import org.apache.hadoop.ozone.protocol.commands.SCMCommand; import org.apache.ozone.test.MockClock; import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.BeforeEach; @@ -103,7 +102,7 @@ public class TestReplicationManagerScenarios { private Map> containerReplicaMap; private Set containerInfoSet; private ContainerReplicaPendingOps containerReplicaPendingOps; - private Set>> commandsSent; + private Set commandsSent; private OzoneConfiguration configuration; private ContainerManager containerManager; @@ -180,8 +179,7 @@ public void setup() throws IOException, NodeNotFoundException { commandsSent = new HashSet<>(); eventPublisher = mock(EventPublisher.class); doAnswer(invocation -> { - commandsSent.add(Pair.of(invocation.getArgument(0), - invocation.getArgument(1))); + commandsSent.add(new DatanodeIdCommand(invocation.getArgument(0), invocation.getArgument(1))); return null; }).when(nodeManager).addDatanodeCommand(any(), any()); @@ -342,11 +340,11 @@ private void assertExpectedCommands(Scenario scenario, // datanodes. for (ExpectedCommands expectedCommand : expectedCommands) { boolean found = false; - for (Pair> command : commandsSent) { - if (command.getRight().getType() == expectedCommand.getType()) { + for (DatanodeIdCommand command : commandsSent) { + if (command.command().getType() == expectedCommand.getType()) { if (expectedCommand.hasExpectedDatanode()) { // We need to assert against the command the datanode is sent to - DatanodeDetails commandDatanode = findDatanode(command.getKey()); + DatanodeDetails commandDatanode = findDatanode(command.datanodeId()); if (commandDatanode != null && expectedCommand.isTargetExpected(commandDatanode)) { found = true; commandsSent.remove(command); diff --git a/hadoop-hdds/server-scm/src/test/java/org/apache/hadoop/hdds/scm/container/replication/health/TestECMisReplicationCheckHandler.java b/hadoop-hdds/server-scm/src/test/java/org/apache/hadoop/hdds/scm/container/replication/health/TestECMisReplicationCheckHandler.java index d4ce26a8cc58..a82f65404d4d 100644 --- a/hadoop-hdds/server-scm/src/test/java/org/apache/hadoop/hdds/scm/container/replication/health/TestECMisReplicationCheckHandler.java +++ b/hadoop-hdds/server-scm/src/test/java/org/apache/hadoop/hdds/scm/container/replication/health/TestECMisReplicationCheckHandler.java @@ -37,7 +37,6 @@ import java.util.Collections; import java.util.List; import java.util.Set; -import org.apache.commons.lang3.tuple.Pair; import org.apache.hadoop.hdds.client.ECReplicationConfig; import org.apache.hadoop.hdds.client.RatisReplicationConfig; import org.apache.hadoop.hdds.protocol.DatanodeDetails; @@ -55,6 +54,7 @@ import org.apache.hadoop.hdds.scm.container.replication.ContainerReplicaOp; import org.apache.hadoop.hdds.scm.container.replication.ReplicationManager; import org.apache.hadoop.hdds.scm.container.replication.ReplicationQueue; +import org.apache.hadoop.hdds.scm.container.replication.ReplicationTestUtil.NodeOperationalStateAndIndex; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; @@ -134,9 +134,9 @@ public void shouldHandleMisReplicatedContainer() { new ContainerPlacementStatusDefault(4, 5, 9)); Set replicas = createReplicas(container.containerID(), - Pair.of(IN_SERVICE, 1), Pair.of(IN_SERVICE, 2), - Pair.of(IN_SERVICE, 3), Pair.of(IN_SERVICE, 4), - Pair.of(IN_SERVICE, 5)); + new NodeOperationalStateAndIndex(IN_SERVICE, 1), new NodeOperationalStateAndIndex(IN_SERVICE, 2), + new NodeOperationalStateAndIndex(IN_SERVICE, 3), new NodeOperationalStateAndIndex(IN_SERVICE, 4), + new NodeOperationalStateAndIndex(IN_SERVICE, 5)); ContainerCheckRequest request = requestBuilder .setContainerReplicas(replicas) .setContainerInfo(container) @@ -180,9 +180,9 @@ public void shouldReturnFalseForMisReplicatedContainerFixedByPending() { ADD, MockDatanodeDetails.randomDatanodeDetails(), 1, null, Long.MAX_VALUE, 0)); Set replicas = createReplicas(container.containerID(), - Pair.of(IN_SERVICE, 1), Pair.of(IN_SERVICE, 2), - Pair.of(IN_SERVICE, 3), Pair.of(IN_SERVICE, 4), - Pair.of(IN_SERVICE, 5)); + new NodeOperationalStateAndIndex(IN_SERVICE, 1), new NodeOperationalStateAndIndex(IN_SERVICE, 2), + new NodeOperationalStateAndIndex(IN_SERVICE, 3), new NodeOperationalStateAndIndex(IN_SERVICE, 4), + new NodeOperationalStateAndIndex(IN_SERVICE, 5)); ContainerCheckRequest request = requestBuilder .setContainerReplicas(replicas) .setContainerInfo(container) @@ -225,9 +225,9 @@ public void testMisReplicationWithUnhealthyReplica() { }); Set replicas = createReplicas(container.containerID(), - Pair.of(IN_SERVICE, 1), Pair.of(IN_SERVICE, 2), - Pair.of(IN_SERVICE, 3), Pair.of(IN_SERVICE, 4), - Pair.of(IN_SERVICE, 5)); + new NodeOperationalStateAndIndex(IN_SERVICE, 1), new NodeOperationalStateAndIndex(IN_SERVICE, 2), + new NodeOperationalStateAndIndex(IN_SERVICE, 3), new NodeOperationalStateAndIndex(IN_SERVICE, 4), + new NodeOperationalStateAndIndex(IN_SERVICE, 5)); ContainerReplica unhealthyReplica = createContainerReplica(container.containerID(), 1, IN_SERVICE, State.UNHEALTHY); diff --git a/hadoop-hdds/server-scm/src/test/java/org/apache/hadoop/hdds/scm/container/replication/health/TestECReplicationCheckHandler.java b/hadoop-hdds/server-scm/src/test/java/org/apache/hadoop/hdds/scm/container/replication/health/TestECReplicationCheckHandler.java index 1647a035add0..1d6fe4018bf3 100644 --- a/hadoop-hdds/server-scm/src/test/java/org/apache/hadoop/hdds/scm/container/replication/health/TestECReplicationCheckHandler.java +++ b/hadoop-hdds/server-scm/src/test/java/org/apache/hadoop/hdds/scm/container/replication/health/TestECReplicationCheckHandler.java @@ -42,7 +42,6 @@ import java.util.Collections; import java.util.List; import java.util.Set; -import org.apache.commons.lang3.tuple.Pair; import org.apache.hadoop.hdds.client.ECReplicationConfig; import org.apache.hadoop.hdds.protocol.MockDatanodeDetails; import org.apache.hadoop.hdds.protocol.proto.HddsProtos; @@ -62,6 +61,7 @@ import org.apache.hadoop.hdds.scm.container.replication.ReplicationManager; import org.apache.hadoop.hdds.scm.container.replication.ReplicationQueue; import org.apache.hadoop.hdds.scm.container.replication.ReplicationTestUtil; +import org.apache.hadoop.hdds.scm.container.replication.ReplicationTestUtil.NodeOperationalStateAndIndex; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; @@ -170,9 +170,9 @@ public void testUnderReplicatedContainerFixedWithPending() { public void testUnderReplicatedDueToOutOfService() { ContainerInfo container = createContainerInfo(repConfig); Set replicas = createReplicas(container.containerID(), - Pair.of(IN_SERVICE, 1), Pair.of(IN_SERVICE, 2), - Pair.of(IN_SERVICE, 3), Pair.of(DECOMMISSIONING, 4), - Pair.of(DECOMMISSIONED, 5)); + new NodeOperationalStateAndIndex(IN_SERVICE, 1), new NodeOperationalStateAndIndex(IN_SERVICE, 2), + new NodeOperationalStateAndIndex(IN_SERVICE, 3), new NodeOperationalStateAndIndex(DECOMMISSIONING, 4), + new NodeOperationalStateAndIndex(DECOMMISSIONED, 5)); ContainerCheckRequest request = requestBuilder .setContainerReplicas(replicas) .setContainerInfo(container) @@ -197,9 +197,9 @@ public void testUnderReplicatedDueToOutOfService() { public void testUnderReplicatedDueToOutOfServiceFixedWithPending() { ContainerInfo container = createContainerInfo(repConfig); Set replicas = createReplicas(container.containerID(), - Pair.of(IN_SERVICE, 1), Pair.of(IN_SERVICE, 2), - Pair.of(IN_SERVICE, 3), Pair.of(DECOMMISSIONING, 4), - Pair.of(IN_SERVICE, 4), Pair.of(DECOMMISSIONED, 5)); + new NodeOperationalStateAndIndex(IN_SERVICE, 1), new NodeOperationalStateAndIndex(IN_SERVICE, 2), + new NodeOperationalStateAndIndex(IN_SERVICE, 3), new NodeOperationalStateAndIndex(DECOMMISSIONING, 4), + new NodeOperationalStateAndIndex(IN_SERVICE, 4), new NodeOperationalStateAndIndex(DECOMMISSIONED, 5)); List pending = new ArrayList<>(); pending.add(new ContainerReplicaOp( ADD, MockDatanodeDetails.randomDatanodeDetails(), 5, null, Long.MAX_VALUE, 0)); @@ -229,8 +229,8 @@ public void testUnderReplicatedDueToOutOfServiceFixedWithPending() { public void testUnderReplicatedDueToOutOfServiceAndMissingReplica() { ContainerInfo container = createContainerInfo(repConfig); Set replicas = createReplicas(container.containerID(), - Pair.of(IN_SERVICE, 1), Pair.of(IN_SERVICE, 2), - Pair.of(DECOMMISSIONING, 4), Pair.of(DECOMMISSIONED, 5)); + new NodeOperationalStateAndIndex(IN_SERVICE, 1), new NodeOperationalStateAndIndex(IN_SERVICE, 2), + new NodeOperationalStateAndIndex(DECOMMISSIONING, 4), new NodeOperationalStateAndIndex(DECOMMISSIONED, 5)); List pending = new ArrayList<>(); pending.add(new ContainerReplicaOp( ADD, MockDatanodeDetails.randomDatanodeDetails(), 3, null, Long.MAX_VALUE, 0)); @@ -258,7 +258,7 @@ public void testUnderReplicatedDueToOutOfServiceAndMissingReplica() { public void testUnderReplicatedAndUnrecoverable() { ContainerInfo container = createContainerInfo(repConfig); Set replicas = createReplicas(container.containerID(), - Pair.of(IN_SERVICE, 1), Pair.of(IN_SERVICE, 2)); + new NodeOperationalStateAndIndex(IN_SERVICE, 1), new NodeOperationalStateAndIndex(IN_SERVICE, 2)); ContainerCheckRequest request = requestBuilder .setContainerReplicas(replicas) .setContainerInfo(container) @@ -288,9 +288,9 @@ public void testUnderReplicatedAndUnrecoverable() { public void testUnderReplicatedAndUnhealthy() { ContainerInfo container = createContainerInfo(repConfig); Set replicas = createReplicas(container.containerID(), - Pair.of(IN_SERVICE, 1), Pair.of(IN_SERVICE, 2)); - replicas.addAll(createReplicas(UNHEALTHY, Pair.of(IN_SERVICE, 3), - Pair.of(IN_SERVICE, 4))); + new NodeOperationalStateAndIndex(IN_SERVICE, 1), new NodeOperationalStateAndIndex(IN_SERVICE, 2)); + replicas.addAll(createReplicas(UNHEALTHY, new NodeOperationalStateAndIndex(IN_SERVICE, 3), + new NodeOperationalStateAndIndex(IN_SERVICE, 4))); ContainerCheckRequest request = requestBuilder .setContainerReplicas(replicas) .setContainerInfo(container) @@ -331,7 +331,7 @@ private void testUnderReplicatedAndUnrecoverableWithOffline( HddsProtos.NodeOperationalState offlineState) { ContainerInfo container = createContainerInfo(repConfig); Set replicas = createReplicas(container.containerID(), - Pair.of(IN_SERVICE, 1), Pair.of(offlineState, 2)); + new NodeOperationalStateAndIndex(IN_SERVICE, 1), new NodeOperationalStateAndIndex(offlineState, 2)); ContainerCheckRequest request = requestBuilder .setContainerReplicas(replicas) .setContainerInfo(container) @@ -373,7 +373,7 @@ private void testUnderReplicatedAndUnrecoverableWithOfflinePending( HddsProtos.NodeOperationalState offlineState) { ContainerInfo container = createContainerInfo(repConfig); Set replicas = createReplicas(container.containerID(), - Pair.of(IN_SERVICE, 1), Pair.of(offlineState, 2)); + new NodeOperationalStateAndIndex(IN_SERVICE, 1), new NodeOperationalStateAndIndex(offlineState, 2)); List pending = new ArrayList<>(); pending.add(new ContainerReplicaOp( ADD, MockDatanodeDetails.randomDatanodeDetails(), 2, null, Long.MAX_VALUE, 0)); @@ -479,10 +479,10 @@ public void testSufficientlyReplicatedDespiteUnhealthyReplicas() { public void testOverReplicatedContainer() { ContainerInfo container = createContainerInfo(repConfig); Set replicas = createReplicas(container.containerID(), - Pair.of(IN_SERVICE, 1), Pair.of(IN_SERVICE, 2), - Pair.of(IN_SERVICE, 3), Pair.of(IN_SERVICE, 4), - Pair.of(IN_SERVICE, 5), - Pair.of(IN_SERVICE, 1), Pair.of(IN_SERVICE, 2)); + new NodeOperationalStateAndIndex(IN_SERVICE, 1), new NodeOperationalStateAndIndex(IN_SERVICE, 2), + new NodeOperationalStateAndIndex(IN_SERVICE, 3), new NodeOperationalStateAndIndex(IN_SERVICE, 4), + new NodeOperationalStateAndIndex(IN_SERVICE, 5), new NodeOperationalStateAndIndex(IN_SERVICE, 1), + new NodeOperationalStateAndIndex(IN_SERVICE, 2)); ContainerCheckRequest request = requestBuilder .setContainerReplicas(replicas) @@ -506,10 +506,10 @@ public void testOverReplicatedContainer() { public void testOverReplicatedContainerFixedByPending() { ContainerInfo container = createContainerInfo(repConfig); Set replicas = createReplicas(container.containerID(), - Pair.of(IN_SERVICE, 1), Pair.of(IN_SERVICE, 2), - Pair.of(IN_SERVICE, 3), Pair.of(IN_SERVICE, 4), - Pair.of(IN_SERVICE, 5), - Pair.of(IN_SERVICE, 1), Pair.of(IN_SERVICE, 2)); + new NodeOperationalStateAndIndex(IN_SERVICE, 1), new NodeOperationalStateAndIndex(IN_SERVICE, 2), + new NodeOperationalStateAndIndex(IN_SERVICE, 3), new NodeOperationalStateAndIndex(IN_SERVICE, 4), + new NodeOperationalStateAndIndex(IN_SERVICE, 5), new NodeOperationalStateAndIndex(IN_SERVICE, 1), + new NodeOperationalStateAndIndex(IN_SERVICE, 2)); List pending = new ArrayList<>(); pending.add(new ContainerReplicaOp( @@ -539,10 +539,10 @@ public void testOverReplicatedContainerFixedByPending() { public void testOverReplicatedContainerDueToMaintenance() { ContainerInfo container = createContainerInfo(repConfig); Set replicas = createReplicas(container.containerID(), - Pair.of(IN_SERVICE, 1), Pair.of(IN_SERVICE, 2), - Pair.of(IN_SERVICE, 3), Pair.of(IN_SERVICE, 4), - Pair.of(IN_SERVICE, 5), - Pair.of(IN_MAINTENANCE, 1), Pair.of(IN_MAINTENANCE, 2)); + new NodeOperationalStateAndIndex(IN_SERVICE, 1), new NodeOperationalStateAndIndex(IN_SERVICE, 2), + new NodeOperationalStateAndIndex(IN_SERVICE, 3), new NodeOperationalStateAndIndex(IN_SERVICE, 4), + new NodeOperationalStateAndIndex(IN_SERVICE, 5), new NodeOperationalStateAndIndex(IN_MAINTENANCE, 1), + new NodeOperationalStateAndIndex(IN_MAINTENANCE, 2)); ContainerCheckRequest request = requestBuilder .setContainerReplicas(replicas) .setContainerInfo(container) @@ -563,9 +563,9 @@ public void testOverReplicatedContainerDueToMaintenance() { public void testOverAndUnderReplicated() { ContainerInfo container = createContainerInfo(repConfig); Set replicas = createReplicas(container.containerID(), - Pair.of(IN_SERVICE, 1), Pair.of(IN_SERVICE, 2), - Pair.of(IN_SERVICE, 3), Pair.of(IN_SERVICE, 4), - Pair.of(IN_SERVICE, 1), Pair.of(IN_SERVICE, 2)); + new NodeOperationalStateAndIndex(IN_SERVICE, 1), new NodeOperationalStateAndIndex(IN_SERVICE, 2), + new NodeOperationalStateAndIndex(IN_SERVICE, 3), new NodeOperationalStateAndIndex(IN_SERVICE, 4), + new NodeOperationalStateAndIndex(IN_SERVICE, 1), new NodeOperationalStateAndIndex(IN_SERVICE, 2)); ContainerCheckRequest request = requestBuilder .setContainerReplicas(replicas) .setContainerInfo(container) @@ -596,8 +596,8 @@ public void testUnderAndMisReplicatedContainer() { new ContainerPlacementStatusDefault(4, 5, 9)); Set replicas = createReplicas(container.containerID(), - Pair.of(IN_SERVICE, 1), Pair.of(IN_SERVICE, 2), - Pair.of(IN_SERVICE, 3), Pair.of(IN_SERVICE, 4)); + new NodeOperationalStateAndIndex(IN_SERVICE, 1), new NodeOperationalStateAndIndex(IN_SERVICE, 2), + new NodeOperationalStateAndIndex(IN_SERVICE, 3), new NodeOperationalStateAndIndex(IN_SERVICE, 4)); ContainerCheckRequest request = requestBuilder .setContainerReplicas(replicas) .setContainerInfo(container) @@ -631,9 +631,9 @@ public void testOverAndMisReplicatedContainer() { new ContainerPlacementStatusDefault(4, 5, 9)); Set replicas = createReplicas(container.containerID(), - Pair.of(IN_SERVICE, 1), Pair.of(IN_SERVICE, 2), - Pair.of(IN_SERVICE, 3), Pair.of(IN_SERVICE, 4), - Pair.of(IN_SERVICE, 5), Pair.of(IN_SERVICE, 5)); + new NodeOperationalStateAndIndex(IN_SERVICE, 1), new NodeOperationalStateAndIndex(IN_SERVICE, 2), + new NodeOperationalStateAndIndex(IN_SERVICE, 3), new NodeOperationalStateAndIndex(IN_SERVICE, 4), + new NodeOperationalStateAndIndex(IN_SERVICE, 5), new NodeOperationalStateAndIndex(IN_SERVICE, 5)); ContainerCheckRequest request = requestBuilder .setContainerReplicas(replicas) .setContainerInfo(container) @@ -659,9 +659,9 @@ public void testOverAndMisReplicatedContainer() { public void testUnhealthyReplicaWithOtherCopyAndPendingDelete() { ContainerInfo container = createContainerInfo(repConfig); Set replicas = createReplicas(container.containerID(), - Pair.of(IN_SERVICE, 1), Pair.of(IN_SERVICE, 2), - Pair.of(IN_SERVICE, 3), Pair.of(IN_SERVICE, 4), - Pair.of(IN_SERVICE, 5)); + new NodeOperationalStateAndIndex(IN_SERVICE, 1), new NodeOperationalStateAndIndex(IN_SERVICE, 2), + new NodeOperationalStateAndIndex(IN_SERVICE, 3), new NodeOperationalStateAndIndex(IN_SERVICE, 4), + new NodeOperationalStateAndIndex(IN_SERVICE, 5)); ContainerReplica unhealthyReplica = ReplicationTestUtil .createContainerReplica(container.containerID(), 1, IN_SERVICE, diff --git a/hadoop-hdds/server-scm/src/test/java/org/apache/hadoop/hdds/scm/container/replication/health/TestQuasiClosedStuckReplicationCheck.java b/hadoop-hdds/server-scm/src/test/java/org/apache/hadoop/hdds/scm/container/replication/health/TestQuasiClosedStuckReplicationCheck.java index e41e9582033f..79e8d03deaf4 100644 --- a/hadoop-hdds/server-scm/src/test/java/org/apache/hadoop/hdds/scm/container/replication/health/TestQuasiClosedStuckReplicationCheck.java +++ b/hadoop-hdds/server-scm/src/test/java/org/apache/hadoop/hdds/scm/container/replication/health/TestQuasiClosedStuckReplicationCheck.java @@ -30,7 +30,6 @@ import java.util.HashSet; import java.util.List; import java.util.Set; -import org.apache.commons.lang3.tuple.Pair; import org.apache.hadoop.hdds.client.RatisReplicationConfig; import org.apache.hadoop.hdds.conf.OzoneConfiguration; import org.apache.hadoop.hdds.protocol.DatanodeID; @@ -45,6 +44,7 @@ import org.apache.hadoop.hdds.scm.container.replication.ReplicationManager; import org.apache.hadoop.hdds.scm.container.replication.ReplicationQueue; import org.apache.hadoop.hdds.scm.container.replication.ReplicationTestUtil; +import org.apache.hadoop.hdds.scm.container.replication.ReplicationTestUtil.NodeOperationalStateAndOrigin; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; @@ -77,7 +77,7 @@ public void testClosedContainerReturnsFalse() { Set containerReplicas = ReplicationTestUtil .createReplicasWithOriginAndOpState(containerInfo.containerID(), State.QUASI_CLOSED, - Pair.of(origin1, IN_SERVICE)); + new NodeOperationalStateAndOrigin(origin1, IN_SERVICE)); ContainerCheckRequest request = new ContainerCheckRequest.Builder() .setPendingOps(Collections.emptyList()) .setReport(new ReplicationManagerReport(rmConf.getContainerSampleLimit())) @@ -100,7 +100,9 @@ public void testQuasiClosedNotStuckReturnsFalse() { Set containerReplicas = ReplicationTestUtil .createReplicasWithOriginAndOpState(containerInfo.containerID(), State.QUASI_CLOSED, - Pair.of(origin1, IN_SERVICE), Pair.of(origin2, IN_SERVICE), Pair.of(origin3, IN_SERVICE)); + new NodeOperationalStateAndOrigin(origin1, IN_SERVICE), + new NodeOperationalStateAndOrigin(origin2, IN_SERVICE), + new NodeOperationalStateAndOrigin(origin3, IN_SERVICE)); ContainerCheckRequest request = new ContainerCheckRequest.Builder() .setPendingOps(Collections.emptyList()) .setReport(report) @@ -123,10 +125,11 @@ public void testQuasiClosedStuckWithOpenReturnsFalse() { Set containerReplicas = ReplicationTestUtil .createReplicasWithOriginAndOpState(containerInfo.containerID(), State.QUASI_CLOSED, - Pair.of(origin1, IN_SERVICE), Pair.of(origin2, IN_SERVICE)); + new NodeOperationalStateAndOrigin(origin1, IN_SERVICE), + new NodeOperationalStateAndOrigin(origin2, IN_SERVICE)); containerReplicas.addAll(ReplicationTestUtil .createReplicasWithOriginAndOpState(containerInfo.containerID(), State.OPEN, - Pair.of(origin3, IN_SERVICE))); + new NodeOperationalStateAndOrigin(origin3, IN_SERVICE))); ContainerCheckRequest request = new ContainerCheckRequest.Builder() .setPendingOps(Collections.emptyList()) .setReport(report) @@ -200,7 +203,8 @@ public void testUnderReplicatedOneOriginNotHandled() { Set containerReplicas = ReplicationTestUtil .createReplicasWithOriginAndOpState(containerInfo.containerID(), State.QUASI_CLOSED, - Pair.of(origin1, IN_SERVICE), Pair.of(origin1, IN_SERVICE)); + new NodeOperationalStateAndOrigin(origin1, IN_SERVICE), + new NodeOperationalStateAndOrigin(origin1, IN_SERVICE)); ContainerCheckRequest request = new ContainerCheckRequest.Builder() .setPendingOps(Collections.emptyList()) @@ -220,7 +224,8 @@ public void testUnderReplicatedWithPendingAddIsNotQueued() { Set containerReplicas = ReplicationTestUtil .createReplicasWithOriginAndOpState(containerInfo.containerID(), State.QUASI_CLOSED, - Pair.of(origin1, IN_SERVICE), Pair.of(origin2, IN_SERVICE)); + new NodeOperationalStateAndOrigin(origin1, IN_SERVICE), + new NodeOperationalStateAndOrigin(origin2, IN_SERVICE)); List pendingOps = new ArrayList<>(); pendingOps.add(new ContainerReplicaOp( diff --git a/hadoop-hdds/server-scm/src/test/java/org/apache/hadoop/hdds/scm/container/replication/health/TestRatisReplicationCheckHandler.java b/hadoop-hdds/server-scm/src/test/java/org/apache/hadoop/hdds/scm/container/replication/health/TestRatisReplicationCheckHandler.java index 5fbf6cceff20..a313d0c9af9f 100644 --- a/hadoop-hdds/server-scm/src/test/java/org/apache/hadoop/hdds/scm/container/replication/health/TestRatisReplicationCheckHandler.java +++ b/hadoop-hdds/server-scm/src/test/java/org/apache/hadoop/hdds/scm/container/replication/health/TestRatisReplicationCheckHandler.java @@ -41,7 +41,6 @@ import java.util.HashSet; import java.util.List; import java.util.Set; -import org.apache.commons.lang3.tuple.Pair; import org.apache.hadoop.hdds.client.ECReplicationConfig; import org.apache.hadoop.hdds.client.RatisReplicationConfig; import org.apache.hadoop.hdds.client.ReplicationConfig; @@ -67,6 +66,7 @@ import org.apache.hadoop.hdds.scm.container.replication.ReplicationManager; import org.apache.hadoop.hdds.scm.container.replication.ReplicationQueue; import org.apache.hadoop.hdds.scm.container.replication.ReplicationTestUtil; +import org.apache.hadoop.hdds.scm.container.replication.ReplicationTestUtil.NodeOperationalStateAndIndex; import org.apache.hadoop.hdds.scm.node.NodeStatus; import org.apache.hadoop.hdds.scm.node.states.NodeNotFoundException; import org.junit.jupiter.api.BeforeEach; @@ -220,8 +220,8 @@ public void testUnderReplicatedContainerFixedWithPending() { public void testUnderReplicatedDueToOutOfService() { ContainerInfo container = createContainerInfo(repConfig); Set replicas = createReplicas(container.containerID(), - Pair.of(IN_SERVICE, 0), Pair.of(DECOMMISSIONING, 0), - Pair.of(DECOMMISSIONED, 0)); + new NodeOperationalStateAndIndex(IN_SERVICE, 0), new NodeOperationalStateAndIndex(DECOMMISSIONING, 0), + new NodeOperationalStateAndIndex(DECOMMISSIONED, 0)); requestBuilder.setContainerReplicas(replicas) .setContainerInfo(container); @@ -243,7 +243,7 @@ public void testUnderReplicatedDueToOutOfService() { @MethodSource("org.apache.hadoop.hdds.scm.node.NodeStatus#outOfServiceStates") void testUnderReplicatedDueToAllOutOfService( HddsProtos.NodeOperationalState state) { - Pair pair = Pair.of(state, 0); + NodeOperationalStateAndIndex pair = new NodeOperationalStateAndIndex(state, 0); ContainerInfo container = createContainerInfo(repConfig); Set replicas = createReplicas(container.containerID(), @@ -275,8 +275,8 @@ void testUnderReplicatedDueToAllOutOfService( public void testUnderReplicatedDueToOutOfServiceFixedWithPending() { ContainerInfo container = createContainerInfo(repConfig); Set replicas = createReplicas(container.containerID(), - Pair.of(IN_SERVICE, 0), Pair.of(IN_SERVICE, 0), - Pair.of(DECOMMISSIONED, 0)); + new NodeOperationalStateAndIndex(IN_SERVICE, 0), new NodeOperationalStateAndIndex(IN_SERVICE, 0), + new NodeOperationalStateAndIndex(DECOMMISSIONED, 0)); List pending = new ArrayList<>(); pending.add(new ContainerReplicaOp( ADD, MockDatanodeDetails.randomDatanodeDetails(), 0, null, Long.MAX_VALUE, 0)); @@ -304,7 +304,7 @@ public void testUnderReplicatedDueToOutOfServiceFixedWithPending() { public void testUnderReplicatedDueToOutOfServiceAndMissing() { ContainerInfo container = createContainerInfo(repConfig); Set replicas = createReplicas(container.containerID(), - Pair.of(IN_SERVICE, 0), Pair.of(DECOMMISSIONED, 0)); + new NodeOperationalStateAndIndex(IN_SERVICE, 0), new NodeOperationalStateAndIndex(DECOMMISSIONED, 0)); List pending = new ArrayList<>(); pending.add(new ContainerReplicaOp( ADD, MockDatanodeDetails.randomDatanodeDetails(), 0, null, Long.MAX_VALUE, 0)); @@ -450,10 +450,10 @@ public void testHandlerReturnsFalseWhenAllReplicasAreUnhealthy() { public void testOverReplicatedContainer() { ContainerInfo container = createContainerInfo(repConfig); Set replicas = createReplicas(container.containerID(), - Pair.of(IN_SERVICE, 0), Pair.of(IN_SERVICE, 0), - Pair.of(IN_SERVICE, 0), Pair.of(IN_SERVICE, 0), - Pair.of(IN_SERVICE, 0), - Pair.of(IN_SERVICE, 0), Pair.of(IN_SERVICE, 0)); + new NodeOperationalStateAndIndex(IN_SERVICE, 0), new NodeOperationalStateAndIndex(IN_SERVICE, 0), + new NodeOperationalStateAndIndex(IN_SERVICE, 0), new NodeOperationalStateAndIndex(IN_SERVICE, 0), + new NodeOperationalStateAndIndex(IN_SERVICE, 0), + new NodeOperationalStateAndIndex(IN_SERVICE, 0), new NodeOperationalStateAndIndex(IN_SERVICE, 0)); List pending = new ArrayList<>(); pending.add(new ContainerReplicaOp( @@ -666,8 +666,8 @@ public void testHandlerAddsToQueueWhenExcessUnhealthyReplicas() { public void testOverReplicatedContainerFixedByPending() { ContainerInfo container = createContainerInfo(repConfig); Set replicas = createReplicas(container.containerID(), - Pair.of(IN_SERVICE, 0), Pair.of(IN_SERVICE, 0), - Pair.of(IN_SERVICE, 0), Pair.of(IN_SERVICE, 0)); + new NodeOperationalStateAndIndex(IN_SERVICE, 0), new NodeOperationalStateAndIndex(IN_SERVICE, 0), + new NodeOperationalStateAndIndex(IN_SERVICE, 0), new NodeOperationalStateAndIndex(IN_SERVICE, 0)); List pending = new ArrayList<>(); pending.add(new ContainerReplicaOp( @@ -695,9 +695,9 @@ public void testOverReplicatedContainerFixedByPending() { public void testOverReplicatedContainerWithMaintenance() { ContainerInfo container = createContainerInfo(repConfig); Set replicas = createReplicas(container.containerID(), - Pair.of(IN_SERVICE, 0), Pair.of(IN_SERVICE, 0), - Pair.of(IN_SERVICE, 0), Pair.of(IN_SERVICE, 0), - Pair.of(IN_MAINTENANCE, 0), Pair.of(DECOMMISSIONED, 0)); + new NodeOperationalStateAndIndex(IN_SERVICE, 0), new NodeOperationalStateAndIndex(IN_SERVICE, 0), + new NodeOperationalStateAndIndex(IN_SERVICE, 0), new NodeOperationalStateAndIndex(IN_SERVICE, 0), + new NodeOperationalStateAndIndex(IN_MAINTENANCE, 0), new NodeOperationalStateAndIndex(DECOMMISSIONED, 0)); requestBuilder.setContainerReplicas(replicas) .setContainerInfo(container); @@ -718,9 +718,9 @@ public void testOverReplicatedContainerWithMaintenance() { public void testOverReplicatedContainerDueToMaintenanceIsHealthy() { ContainerInfo container = createContainerInfo(repConfig); Set replicas = createReplicas(container.containerID(), - Pair.of(IN_SERVICE, 0), Pair.of(IN_SERVICE, 0), - Pair.of(IN_SERVICE, 0), Pair.of(IN_MAINTENANCE, 0), - Pair.of(IN_MAINTENANCE, 0)); + new NodeOperationalStateAndIndex(IN_SERVICE, 0), new NodeOperationalStateAndIndex(IN_SERVICE, 0), + new NodeOperationalStateAndIndex(IN_SERVICE, 0), new NodeOperationalStateAndIndex(IN_MAINTENANCE, 0), + new NodeOperationalStateAndIndex(IN_MAINTENANCE, 0)); requestBuilder.setContainerReplicas(replicas) .setContainerInfo(container);