aryangupta1998 commented on code in PR #8422: URL: https://github.com/apache/ozone/pull/8422#discussion_r2120889142
########## hadoop-ozone/tools/src/main/java/org/apache/hadoop/ozone/debug/replicas/ContainerStateVerifier.java: ########## @@ -0,0 +1,181 @@ +/* + * 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.ozone.debug.replicas; + +import static org.apache.hadoop.hdds.protocol.proto.HddsProtos.ReplicationFactor.ONE; + +import com.google.common.cache.Cache; +import com.google.common.cache.CacheBuilder; +import java.io.IOException; +import java.util.Collections; +import java.util.Objects; +import org.apache.hadoop.hdds.client.StandaloneReplicationConfig; +import org.apache.hadoop.hdds.conf.OzoneConfiguration; +import org.apache.hadoop.hdds.protocol.DatanodeDetails; +import org.apache.hadoop.hdds.protocol.datanode.proto.ContainerProtos.ContainerDataProto; +import org.apache.hadoop.hdds.protocol.datanode.proto.ContainerProtos.ReadContainerResponseProto; +import org.apache.hadoop.hdds.protocol.proto.HddsProtos; +import org.apache.hadoop.hdds.scm.XceiverClientManager; +import org.apache.hadoop.hdds.scm.XceiverClientSpi; +import org.apache.hadoop.hdds.scm.cli.ContainerOperationClient; +import org.apache.hadoop.hdds.scm.container.ContainerInfo; +import org.apache.hadoop.hdds.scm.pipeline.Pipeline; +import org.apache.hadoop.hdds.scm.storage.ContainerProtocolCalls; +import org.apache.hadoop.ozone.om.helpers.OmKeyLocationInfo; + +/** + * Verifies the state of a replica from the DN. + * [DELETED, UNHEALTHY, INVALID] are considered bad states. + */ +public class ContainerStateVerifier implements ReplicaVerifier { + private static final String CHECK_TYPE = "replicaState"; + private final ContainerOperationClient containerOperationClient; + private final XceiverClientManager xceiverClientManager; + // cache for container info and encodedToken from the SCM + private final Cache<Long, ContainerInfoToken> encodedTokenCache; + + public ContainerStateVerifier(OzoneConfiguration conf, long containerCacheSize) throws IOException { + containerOperationClient = new ContainerOperationClient(conf); + xceiverClientManager = containerOperationClient.getXceiverClientManager(); + encodedTokenCache = CacheBuilder.newBuilder() + .maximumSize((containerCacheSize < 1) ? 1000000 : containerCacheSize) + .build(); + } + + @Override + public String getType() { + return CHECK_TYPE; + } + + @Override + public BlockVerificationResult verifyBlock(DatanodeDetails datanode, OmKeyLocationInfo keyLocation, + int replicaIndex) { + try { + StringBuilder replicaCheckMsg = new StringBuilder().append("Replica state is "); + boolean pass = false; + + ContainerInfoToken containerInfoToken = getContainerInfoToken(keyLocation.getContainerID()); + ContainerDataProto containerData = fetchContainerDataFromDatanode(datanode, keyLocation.getContainerID(), + keyLocation, replicaIndex, containerInfoToken); + + ContainerDataProto.State state = containerData.getState(); + replicaCheckMsg.append(state.name()); + if (state != ContainerDataProto.State.UNHEALTHY && + state != ContainerDataProto.State.INVALID && + state != ContainerDataProto.State.DELETED && + containerInfoToken.getContainerState() != HddsProtos.LifeCycleState.DELETING && + containerInfoToken.getContainerState() != HddsProtos.LifeCycleState.DELETED) { Review Comment: Not necessary, but there are too many conditions in this 'if', may move them to a helper method for better readability. ########## hadoop-ozone/tools/src/main/java/org/apache/hadoop/ozone/debug/replicas/ContainerStateVerifier.java: ########## @@ -0,0 +1,181 @@ +/* + * 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.ozone.debug.replicas; + +import static org.apache.hadoop.hdds.protocol.proto.HddsProtos.ReplicationFactor.ONE; + +import com.google.common.cache.Cache; +import com.google.common.cache.CacheBuilder; +import java.io.IOException; +import java.util.Collections; +import java.util.Objects; +import org.apache.hadoop.hdds.client.StandaloneReplicationConfig; +import org.apache.hadoop.hdds.conf.OzoneConfiguration; +import org.apache.hadoop.hdds.protocol.DatanodeDetails; +import org.apache.hadoop.hdds.protocol.datanode.proto.ContainerProtos.ContainerDataProto; +import org.apache.hadoop.hdds.protocol.datanode.proto.ContainerProtos.ReadContainerResponseProto; +import org.apache.hadoop.hdds.protocol.proto.HddsProtos; +import org.apache.hadoop.hdds.scm.XceiverClientManager; +import org.apache.hadoop.hdds.scm.XceiverClientSpi; +import org.apache.hadoop.hdds.scm.cli.ContainerOperationClient; +import org.apache.hadoop.hdds.scm.container.ContainerInfo; +import org.apache.hadoop.hdds.scm.pipeline.Pipeline; +import org.apache.hadoop.hdds.scm.storage.ContainerProtocolCalls; +import org.apache.hadoop.ozone.om.helpers.OmKeyLocationInfo; + +/** + * Verifies the state of a replica from the DN. + * [DELETED, UNHEALTHY, INVALID] are considered bad states. + */ +public class ContainerStateVerifier implements ReplicaVerifier { + private static final String CHECK_TYPE = "replicaState"; + private final ContainerOperationClient containerOperationClient; + private final XceiverClientManager xceiverClientManager; + // cache for container info and encodedToken from the SCM + private final Cache<Long, ContainerInfoToken> encodedTokenCache; + + public ContainerStateVerifier(OzoneConfiguration conf, long containerCacheSize) throws IOException { + containerOperationClient = new ContainerOperationClient(conf); + xceiverClientManager = containerOperationClient.getXceiverClientManager(); + encodedTokenCache = CacheBuilder.newBuilder() + .maximumSize((containerCacheSize < 1) ? 1000000 : containerCacheSize) + .build(); + } + + @Override + public String getType() { + return CHECK_TYPE; + } + + @Override + public BlockVerificationResult verifyBlock(DatanodeDetails datanode, OmKeyLocationInfo keyLocation, + int replicaIndex) { + try { + StringBuilder replicaCheckMsg = new StringBuilder().append("Replica state is "); + boolean pass = false; + + ContainerInfoToken containerInfoToken = getContainerInfoToken(keyLocation.getContainerID()); + ContainerDataProto containerData = fetchContainerDataFromDatanode(datanode, keyLocation.getContainerID(), + keyLocation, replicaIndex, containerInfoToken); + + ContainerDataProto.State state = containerData.getState(); Review Comment: Something like to avoid NPE, ```suggestion if (containerData == null) { return BlockVerificationResult.failIncomplete("No container data returned from DN."); } ContainerDataProto.State state = containerData.getState(); ``` ########## hadoop-ozone/tools/src/main/java/org/apache/hadoop/ozone/debug/replicas/ContainerStateVerifier.java: ########## @@ -0,0 +1,181 @@ +/* + * 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.ozone.debug.replicas; + +import static org.apache.hadoop.hdds.protocol.proto.HddsProtos.ReplicationFactor.ONE; + +import com.google.common.cache.Cache; +import com.google.common.cache.CacheBuilder; +import java.io.IOException; +import java.util.Collections; +import java.util.Objects; +import org.apache.hadoop.hdds.client.StandaloneReplicationConfig; +import org.apache.hadoop.hdds.conf.OzoneConfiguration; +import org.apache.hadoop.hdds.protocol.DatanodeDetails; +import org.apache.hadoop.hdds.protocol.datanode.proto.ContainerProtos.ContainerDataProto; +import org.apache.hadoop.hdds.protocol.datanode.proto.ContainerProtos.ReadContainerResponseProto; +import org.apache.hadoop.hdds.protocol.proto.HddsProtos; +import org.apache.hadoop.hdds.scm.XceiverClientManager; +import org.apache.hadoop.hdds.scm.XceiverClientSpi; +import org.apache.hadoop.hdds.scm.cli.ContainerOperationClient; +import org.apache.hadoop.hdds.scm.container.ContainerInfo; +import org.apache.hadoop.hdds.scm.pipeline.Pipeline; +import org.apache.hadoop.hdds.scm.storage.ContainerProtocolCalls; +import org.apache.hadoop.ozone.om.helpers.OmKeyLocationInfo; + +/** + * Verifies the state of a replica from the DN. + * [DELETED, UNHEALTHY, INVALID] are considered bad states. + */ +public class ContainerStateVerifier implements ReplicaVerifier { + private static final String CHECK_TYPE = "replicaState"; + private final ContainerOperationClient containerOperationClient; + private final XceiverClientManager xceiverClientManager; + // cache for container info and encodedToken from the SCM + private final Cache<Long, ContainerInfoToken> encodedTokenCache; + + public ContainerStateVerifier(OzoneConfiguration conf, long containerCacheSize) throws IOException { + containerOperationClient = new ContainerOperationClient(conf); + xceiverClientManager = containerOperationClient.getXceiverClientManager(); + encodedTokenCache = CacheBuilder.newBuilder() + .maximumSize((containerCacheSize < 1) ? 1000000 : containerCacheSize) + .build(); Review Comment: Let's use a constant for the default container cache size. ```suggestion if (containerCacheSize < 1) { LOG.warn("Invalid cache size provided: {}. Falling back to default ({})", containerCacheSize, DEFAULT_CONTAINER_CACHE_SIZE); containerCacheSize = DEFAULT_CONTAINER_CACHE_SIZE; } encodedTokenCache = CacheBuilder.newBuilder().maximumSize(containerCacheSize).build(); ``` -- 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]
