Gargi-jais11 commented on code in PR #9479: URL: https://github.com/apache/ozone/pull/9479#discussion_r2616430190
########## hadoop-hdds/container-service/src/main/java/org/apache/hadoop/ozone/container/common/helpers/EmptyDatanodeIdFileException.java: ########## @@ -0,0 +1,29 @@ +/* + * 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.container.common.helpers; + +import java.io.IOException; + +/** + * Exception thrown when a Datanode ID file is empty. + */ +public class EmptyDatanodeIdFileException extends IOException { Review Comment: I don't think we need to add a new exception class. Let's remove this and it also matches the existing codebase pattern. Use `IOException`. ########## hadoop-hdds/container-service/src/main/java/org/apache/hadoop/ozone/container/common/helpers/DatanodeIdYaml.java: ########## @@ -87,6 +87,11 @@ public static DatanodeDetails readDatanodeIdFile(File path) throw new IOException("Unable to parse yaml file.", e); } + if (datanodeDetailsYaml == null) { + throw new EmptyDatanodeIdFileException( Review Comment: Remove `EmptyDatanodeIdFileException` and use ``` IOException("Datanode ID file is empty or has null UUID: " + path.getAbsolutePath()); ``` ########## hadoop-hdds/container-service/src/main/java/org/apache/hadoop/ozone/container/common/helpers/DatanodeIdYaml.java: ########## @@ -87,6 +87,11 @@ public static DatanodeDetails readDatanodeIdFile(File path) throw new IOException("Unable to parse yaml file.", e); } + if (datanodeDetailsYaml == null) { + throw new EmptyDatanodeIdFileException( + "Datanode ID file is empty: " + path.getAbsolutePath()); + } Review Comment: It may happen that object exists but UUID might be null or empty. So we can have these checks as well. ```suggestion if (datanodeDetailsYaml == null || datanodeDetailsYaml.getUuid() == null || datanodeDetailsYaml.getUuid().isEmpty()) { throw new EmptyDatanodeIdFileException( "Datanode ID file is empty: " + path.getAbsolutePath()); } ``` ########## hadoop-hdds/container-service/src/main/java/org/apache/hadoop/ozone/container/common/helpers/ContainerUtils.java: ########## @@ -166,13 +168,32 @@ public static synchronized void writeDatanodeDetailsTo( * @return {@link DatanodeDetails} * @throws IOException If the id file is malformed or other I/O exceptions */ - public static synchronized DatanodeDetails readDatanodeDetailsFrom(File path) - throws IOException { + public static synchronized DatanodeDetails readDatanodeDetailsFrom( + File path, ConfigurationSource conf) throws IOException { if (!path.exists()) { throw new IOException("Datanode ID file not found."); } try { return DatanodeIdYaml.readDatanodeIdFile(path); + } catch (EmptyDatanodeIdFileException e) { + LOG.warn("Datanode ID file is empty. Recovering from VERSION file.", e); + // Get the datanode UUID from the VERSION file + String dataNodeDir = conf.get(ScmConfigKeys.HDDS_DATANODE_DIR_KEY); + if (dataNodeDir == null || dataNodeDir.isEmpty()) { + throw new IOException("hdds.datanode.dir is not configured.", e); + } + File versionFile = new File(dataNodeDir, "hdds/VERSION"); Review Comment: `hdds.datanode.dir` can be a comma-separated list (e.g., `/data/hdds1,/data/hdds2,/data/hdds3`). conf.get() returns the entire string, creating an invalid path like `/data/hdds1,/data/hdds2,/data/hdds3/hdds/VERSION`. **Solution:** Follow the pattern used in `GeneratorDatanode.java` - use `HddsServerUtil.getDatanodeStorageDirs()` to parse the comma-separated list and read from the first directory (all volumes VERSION file share the same datanode UUID). Step 1: Get all storage directories (handles comma-separated list) Step 2: Try each storage directory until we find a valid VERSION file with datanodeUUID. Step 3: Create a new DaatnodeDetails with UUID found. Step 4: Write the recovered Datanode ID to the datanode.id file -- 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]
