JacksonYao287 commented on code in PR #3542: URL: https://github.com/apache/ozone/pull/3542#discussion_r907106862
########## hadoop-hdds/server-scm/src/main/java/org/apache/hadoop/hdds/scm/container/replication/ECUnderReplicationCommandCreator.java: ########## @@ -0,0 +1,239 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.hadoop.hdds.scm.container.replication; + +import com.google.common.collect.ImmutableList; +import com.google.common.collect.ImmutableMap; +import org.apache.hadoop.hdds.client.ECReplicationConfig; +import org.apache.hadoop.hdds.conf.ConfigurationSource; +import org.apache.hadoop.hdds.conf.StorageUnit; +import org.apache.hadoop.hdds.protocol.DatanodeDetails; +import org.apache.hadoop.hdds.protocol.proto.StorageContainerDatanodeProtocolProtos; +import org.apache.hadoop.hdds.scm.PlacementPolicy; +import org.apache.hadoop.hdds.scm.ScmConfigKeys; +import org.apache.hadoop.hdds.scm.container.ContainerID; +import org.apache.hadoop.hdds.scm.container.ContainerInfo; +import org.apache.hadoop.hdds.scm.container.ContainerReplica; +import org.apache.hadoop.hdds.scm.container.ECContainerReplicaCount; +import org.apache.hadoop.hdds.scm.node.NodeManager; +import org.apache.hadoop.ozone.protocol.commands.ReconstructECContainersCommand; +import org.apache.hadoop.ozone.protocol.commands.ReplicateContainerCommand; +import org.apache.hadoop.ozone.protocol.commands.SCMCommand; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.io.IOException; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.Iterator; +import java.util.List; +import java.util.Map; +import java.util.Set; +import java.util.stream.Collectors; + +/** + * Handles the EC Under replication processing and forming the respective SCM + * commands. + */ +public class ECUnderReplicationCommandCreator + implements ReplicationCommandCreator { + + public static final Logger LOG = + LoggerFactory.getLogger(ECUnderReplicationCommandCreator.class); + private final PlacementPolicy containerPlacement; + private final long currentContainerSize; + private final NodeManager nodeManager; + + public ECUnderReplicationCommandCreator( + final PlacementPolicy containerPlacement, final ConfigurationSource conf, + NodeManager nodeManager) { + this.containerPlacement = containerPlacement; + this.currentContainerSize = (long) conf + .getStorageSize(ScmConfigKeys.OZONE_SCM_CONTAINER_SIZE, + ScmConfigKeys.OZONE_SCM_CONTAINER_SIZE_DEFAULT, StorageUnit.BYTES); + this.nodeManager = nodeManager; + } + + /** + * Identify a new set of datanode(s) to reconstruct the container and form the + * SCM command to send it to DN. In the case of decommission, it will just + * generate the replicate commands instead of reconstruction commands. + * + * @param replicas - An instance of ContainerReplicaCount, containing the + * current replica count and inflight adds and deletes + * @param pendingOps - Inflight replications and deletion metrics. + * @param result - Health check result. + * @param remainingMaintenanceRedundancy - represents that how many nodes go + * into maintenance. + * @return Returns the key value pair of destination dn where the command gets + * executed and the command itself. + */ + @Override + public Map<DatanodeDetails, SCMCommand> processAndCreateCommands( + final Set<ContainerReplica> replicas, + final ContainerReplicaPendingOps pendingOps, + final ContainerHealthResult result, + final int remainingMaintenanceRedundancy) { + ContainerInfo container = result.getContainerInfo(); + ECReplicationConfig repConfig = + (ECReplicationConfig) container.getReplicationConfig(); + + final ECContainerReplicaCount replicaCount = + new ECContainerReplicaCount(container, replicas, + pendingOps.getPendingOps(container.containerID()), + remainingMaintenanceRedundancy); + ContainerHealthResult containerHealthResult = + new ECContainerHealthCheck().checkHealth(container, replicaCount); Review Comment: NIT: can we not create a ECContainerHealthCheck instance here? just make ECContainerHealthCheck as a member variable of ECUnderReplicationCommandCreator ########## hadoop-hdds/server-scm/src/main/java/org/apache/hadoop/hdds/scm/container/replication/ECContainerHealthCheck.java: ########## @@ -89,19 +96,33 @@ public ContainerHealthResult checkHealth(ContainerInfo container, return new ContainerHealthResult.HealthyResult(container); } - private ECContainerReplicaCount getReplicaCountWithPending( + private static ECContainerReplicaCount getReplicaCountWithPending( ContainerInfo container, Set<ContainerReplica> replicas, List<Pair<Integer, DatanodeDetails>> replicasPendingAdd, List<Pair<Integer, DatanodeDetails>> replicasPendingDelete, int remainingRedundancyForMaintenance) { - List<Integer> indexesPendingAdd = replicasPendingAdd.stream() - .map(i -> i.getLeft()).collect(Collectors.toList()); - List<Integer> indexesPendingDelete = replicasPendingDelete.stream() - .map(i -> i.getLeft()).collect(Collectors.toList()); + ContainerReplicaPendingOps pendingOps = Review Comment: i think we can collect all the `pendingAdd` and `pendinDelete` ops to a list , and then pass this list to the creator of `ECContainerReplicaCount`. it seems unnecessary to build a `ContainerReplicaPendingOps` and putting all the pending ops into it , and then extract all the pending ops from it. ########## hadoop-hdds/server-scm/src/main/java/org/apache/hadoop/hdds/scm/container/replication/ECUnderReplicationCommandCreator.java: ########## @@ -0,0 +1,239 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.hadoop.hdds.scm.container.replication; + +import com.google.common.collect.ImmutableList; +import com.google.common.collect.ImmutableMap; +import org.apache.hadoop.hdds.client.ECReplicationConfig; +import org.apache.hadoop.hdds.conf.ConfigurationSource; +import org.apache.hadoop.hdds.conf.StorageUnit; +import org.apache.hadoop.hdds.protocol.DatanodeDetails; +import org.apache.hadoop.hdds.protocol.proto.StorageContainerDatanodeProtocolProtos; +import org.apache.hadoop.hdds.scm.PlacementPolicy; +import org.apache.hadoop.hdds.scm.ScmConfigKeys; +import org.apache.hadoop.hdds.scm.container.ContainerID; +import org.apache.hadoop.hdds.scm.container.ContainerInfo; +import org.apache.hadoop.hdds.scm.container.ContainerReplica; +import org.apache.hadoop.hdds.scm.container.ECContainerReplicaCount; +import org.apache.hadoop.hdds.scm.node.NodeManager; +import org.apache.hadoop.ozone.protocol.commands.ReconstructECContainersCommand; +import org.apache.hadoop.ozone.protocol.commands.ReplicateContainerCommand; +import org.apache.hadoop.ozone.protocol.commands.SCMCommand; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.io.IOException; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.Iterator; +import java.util.List; +import java.util.Map; +import java.util.Set; +import java.util.stream.Collectors; + +/** + * Handles the EC Under replication processing and forming the respective SCM + * commands. + */ +public class ECUnderReplicationCommandCreator + implements ReplicationCommandCreator { + + public static final Logger LOG = + LoggerFactory.getLogger(ECUnderReplicationCommandCreator.class); + private final PlacementPolicy containerPlacement; + private final long currentContainerSize; + private final NodeManager nodeManager; + + public ECUnderReplicationCommandCreator( + final PlacementPolicy containerPlacement, final ConfigurationSource conf, + NodeManager nodeManager) { + this.containerPlacement = containerPlacement; + this.currentContainerSize = (long) conf + .getStorageSize(ScmConfigKeys.OZONE_SCM_CONTAINER_SIZE, + ScmConfigKeys.OZONE_SCM_CONTAINER_SIZE_DEFAULT, StorageUnit.BYTES); + this.nodeManager = nodeManager; + } + + /** + * Identify a new set of datanode(s) to reconstruct the container and form the + * SCM command to send it to DN. In the case of decommission, it will just + * generate the replicate commands instead of reconstruction commands. + * + * @param replicas - An instance of ContainerReplicaCount, containing the + * current replica count and inflight adds and deletes + * @param pendingOps - Inflight replications and deletion metrics. + * @param result - Health check result. + * @param remainingMaintenanceRedundancy - represents that how many nodes go + * into maintenance. + * @return Returns the key value pair of destination dn where the command gets + * executed and the command itself. + */ + @Override + public Map<DatanodeDetails, SCMCommand> processAndCreateCommands( + final Set<ContainerReplica> replicas, + final ContainerReplicaPendingOps pendingOps, + final ContainerHealthResult result, + final int remainingMaintenanceRedundancy) { + ContainerInfo container = result.getContainerInfo(); + ECReplicationConfig repConfig = + (ECReplicationConfig) container.getReplicationConfig(); + + final ECContainerReplicaCount replicaCount = + new ECContainerReplicaCount(container, replicas, + pendingOps.getPendingOps(container.containerID()), + remainingMaintenanceRedundancy); + ContainerHealthResult containerHealthResult = + new ECContainerHealthCheck().checkHealth(container, replicaCount); + + LOG.debug("Handling under-replicated EC container: {}", container); + + if (containerHealthResult.getHealthState() + != ContainerHealthResult.HealthState.UNDER_REPLICATED) { + LOG.info( + "The container {} with replicas {} is sufficiently replicated", + container.getContainerID(), replicaCount.getReplicas()); + // Assert replicaCount also telling it's sufficiently replicated. + return null; + } + final ContainerID id = container.containerID(); + try { + // State is UNDER_REPLICATED + List<ContainerReplicaOp> pendingOpsForContainer = + pendingOps.getPendingOps(id); + final List<DatanodeDetails> deletionInFlight = new ArrayList<>(); + for (ContainerReplicaOp op : pendingOpsForContainer) { + if (op.getOpType() == ContainerReplicaOp.PendingOpType.DELETE) { + deletionInFlight.add(op.getTarget()); + } + } + List<Integer> missingIndexes = replicaCount.unavailableIndexes(true); Review Comment: if an EC container is under-replicated, it may 1 miss some indexes of replica 2 all the indexes of replica is available, but they does not satisfy the placement policy we should take the seconde scenario into account later ########## hadoop-hdds/server-scm/src/main/java/org/apache/hadoop/hdds/scm/container/replication/ECUnderReplicationCommandCreator.java: ########## @@ -0,0 +1,239 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.hadoop.hdds.scm.container.replication; + +import com.google.common.collect.ImmutableList; +import com.google.common.collect.ImmutableMap; +import org.apache.hadoop.hdds.client.ECReplicationConfig; +import org.apache.hadoop.hdds.conf.ConfigurationSource; +import org.apache.hadoop.hdds.conf.StorageUnit; +import org.apache.hadoop.hdds.protocol.DatanodeDetails; +import org.apache.hadoop.hdds.protocol.proto.StorageContainerDatanodeProtocolProtos; +import org.apache.hadoop.hdds.scm.PlacementPolicy; +import org.apache.hadoop.hdds.scm.ScmConfigKeys; +import org.apache.hadoop.hdds.scm.container.ContainerID; +import org.apache.hadoop.hdds.scm.container.ContainerInfo; +import org.apache.hadoop.hdds.scm.container.ContainerReplica; +import org.apache.hadoop.hdds.scm.container.ECContainerReplicaCount; +import org.apache.hadoop.hdds.scm.node.NodeManager; +import org.apache.hadoop.ozone.protocol.commands.ReconstructECContainersCommand; +import org.apache.hadoop.ozone.protocol.commands.ReplicateContainerCommand; +import org.apache.hadoop.ozone.protocol.commands.SCMCommand; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.io.IOException; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.Iterator; +import java.util.List; +import java.util.Map; +import java.util.Set; +import java.util.stream.Collectors; + +/** + * Handles the EC Under replication processing and forming the respective SCM + * commands. + */ +public class ECUnderReplicationCommandCreator Review Comment: NIT, can we rename this to ECReconstructionCommandCreator ########## hadoop-hdds/server-scm/src/main/java/org/apache/hadoop/hdds/scm/container/replication/ECUnderReplicationCommandCreator.java: ########## @@ -0,0 +1,239 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.hadoop.hdds.scm.container.replication; + +import com.google.common.collect.ImmutableList; +import com.google.common.collect.ImmutableMap; +import org.apache.hadoop.hdds.client.ECReplicationConfig; +import org.apache.hadoop.hdds.conf.ConfigurationSource; +import org.apache.hadoop.hdds.conf.StorageUnit; +import org.apache.hadoop.hdds.protocol.DatanodeDetails; +import org.apache.hadoop.hdds.protocol.proto.StorageContainerDatanodeProtocolProtos; +import org.apache.hadoop.hdds.scm.PlacementPolicy; +import org.apache.hadoop.hdds.scm.ScmConfigKeys; +import org.apache.hadoop.hdds.scm.container.ContainerID; +import org.apache.hadoop.hdds.scm.container.ContainerInfo; +import org.apache.hadoop.hdds.scm.container.ContainerReplica; +import org.apache.hadoop.hdds.scm.container.ECContainerReplicaCount; +import org.apache.hadoop.hdds.scm.node.NodeManager; +import org.apache.hadoop.ozone.protocol.commands.ReconstructECContainersCommand; +import org.apache.hadoop.ozone.protocol.commands.ReplicateContainerCommand; +import org.apache.hadoop.ozone.protocol.commands.SCMCommand; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.io.IOException; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.Iterator; +import java.util.List; +import java.util.Map; +import java.util.Set; +import java.util.stream.Collectors; + +/** + * Handles the EC Under replication processing and forming the respective SCM + * commands. + */ +public class ECUnderReplicationCommandCreator + implements ReplicationCommandCreator { + + public static final Logger LOG = + LoggerFactory.getLogger(ECUnderReplicationCommandCreator.class); + private final PlacementPolicy containerPlacement; + private final long currentContainerSize; + private final NodeManager nodeManager; + + public ECUnderReplicationCommandCreator( + final PlacementPolicy containerPlacement, final ConfigurationSource conf, + NodeManager nodeManager) { + this.containerPlacement = containerPlacement; + this.currentContainerSize = (long) conf + .getStorageSize(ScmConfigKeys.OZONE_SCM_CONTAINER_SIZE, + ScmConfigKeys.OZONE_SCM_CONTAINER_SIZE_DEFAULT, StorageUnit.BYTES); + this.nodeManager = nodeManager; + } + + /** + * Identify a new set of datanode(s) to reconstruct the container and form the + * SCM command to send it to DN. In the case of decommission, it will just + * generate the replicate commands instead of reconstruction commands. + * + * @param replicas - An instance of ContainerReplicaCount, containing the + * current replica count and inflight adds and deletes + * @param pendingOps - Inflight replications and deletion metrics. + * @param result - Health check result. + * @param remainingMaintenanceRedundancy - represents that how many nodes go + * into maintenance. + * @return Returns the key value pair of destination dn where the command gets + * executed and the command itself. + */ + @Override + public Map<DatanodeDetails, SCMCommand> processAndCreateCommands( + final Set<ContainerReplica> replicas, + final ContainerReplicaPendingOps pendingOps, + final ContainerHealthResult result, + final int remainingMaintenanceRedundancy) { + ContainerInfo container = result.getContainerInfo(); + ECReplicationConfig repConfig = + (ECReplicationConfig) container.getReplicationConfig(); + + final ECContainerReplicaCount replicaCount = + new ECContainerReplicaCount(container, replicas, + pendingOps.getPendingOps(container.containerID()), + remainingMaintenanceRedundancy); + ContainerHealthResult containerHealthResult = + new ECContainerHealthCheck().checkHealth(container, replicaCount); + + LOG.debug("Handling under-replicated EC container: {}", container); + + if (containerHealthResult.getHealthState() Review Comment: in fact , the the health state of an EC container may be both under and over replicated. for example, EC-3-2, the health stat is 1,2,3,4,5, but we might have 1,1,2,3,4. so , think we should have more enum items for `HealthState` -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
