You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@ozone.apache.org by GitBox <gi...@apache.org> on 2022/09/08 08:07:38 UTC

[GitHub] [ozone] myskov commented on a diff in pull request #3741: HDDS-6449. Failed container delete can leave artifacts on disk

myskov commented on code in PR #3741:
URL: https://github.com/apache/ozone/pull/3741#discussion_r965629751


##########
hadoop-hdds/container-service/src/main/java/org/apache/hadoop/ozone/container/common/helpers/CleanUpManager.java:
##########
@@ -0,0 +1,207 @@
+/*
+ * 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 org.apache.commons.io.FileUtils;
+import org.apache.hadoop.hdds.conf.ConfigurationSource;
+import org.apache.hadoop.ozone.OzoneConsts;
+import org.apache.hadoop.ozone.container.common.utils.HddsVolumeUtil;
+import org.apache.hadoop.ozone.container.common.volume.HddsVolume;
+import org.apache.hadoop.ozone.container.keyvalue.KeyValueContainerData;
+import org.apache.hadoop.ozone.container.upgrade.VersionedDatanodeFeatures;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.io.File;
+import java.io.IOException;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.nio.file.Paths;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.ListIterator;
+
+/**
+ * Helper class for handling /tmp/container_delete_service
+ * operations used for container delete when Schema V3 is enabled.
+ */
+public class CleanUpManager {
+
+  private static final Logger LOG =
+      LoggerFactory.getLogger(CleanUpManager.class);
+
+  private static final String FILE_SEPARATOR = File.separator;
+
+  private static final String TMP_DELETE_SERVICE_DIR =
+      FILE_SEPARATOR + "tmp" + FILE_SEPARATOR + "container_delete_service";
+
+  private Path tmpDirPath;
+
+  public CleanUpManager(HddsVolume hddsVolume) {
+    setTmpDirPath(hddsVolume);
+
+    if (Files.notExists(tmpDirPath)) {
+      try {
+        Files.createDirectories(tmpDirPath);
+      } catch (IOException ex) {
+        LOG.error("Error creating {}", tmpDirPath.toString(), ex);
+      }
+    }
+  }
+
+  public Path getTmpDirPath() {
+    return tmpDirPath;
+  }
+
+  public static boolean checkContainerSchemaV3Enabled(
+      KeyValueContainerData keyValueContainerData) {
+    return (keyValueContainerData.getSchemaVersion()
+        .equals(OzoneConsts.SCHEMA_V3));
+  }
+
+  public static boolean checkContainerSchemaV3Enabled(
+      ConfigurationSource config) {
+    return VersionedDatanodeFeatures.SchemaV3
+        .isFinalizedAndEnabled(config);
+  }
+
+  private void setTmpDirPath(HddsVolume hddsVolume) {
+    StringBuilder stringBuilder = new StringBuilder();
+
+    // HddsVolume root directory path
+    String hddsRoot = hddsVolume.getHddsRootDir().toString();
+
+    // HddsVolume path
+    String volPath = HddsVolumeUtil.getHddsRoot(hddsRoot);
+
+    stringBuilder.append(volPath);
+    stringBuilder.append(FILE_SEPARATOR);
+
+    String clusterId = "";
+    try {
+      clusterId += hddsVolume.getClusterID();
+
+      if (clusterId == null) {
+        throw new IOException();

Review Comment:
   I think the exception should contain a message



##########
hadoop-hdds/container-service/src/main/java/org/apache/hadoop/ozone/container/common/helpers/CleanUpManager.java:
##########
@@ -0,0 +1,207 @@
+/*
+ * 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 org.apache.commons.io.FileUtils;
+import org.apache.hadoop.hdds.conf.ConfigurationSource;
+import org.apache.hadoop.ozone.OzoneConsts;
+import org.apache.hadoop.ozone.container.common.utils.HddsVolumeUtil;
+import org.apache.hadoop.ozone.container.common.volume.HddsVolume;
+import org.apache.hadoop.ozone.container.keyvalue.KeyValueContainerData;
+import org.apache.hadoop.ozone.container.upgrade.VersionedDatanodeFeatures;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.io.File;
+import java.io.IOException;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.nio.file.Paths;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.ListIterator;
+
+/**
+ * Helper class for handling /tmp/container_delete_service
+ * operations used for container delete when Schema V3 is enabled.
+ */
+public class CleanUpManager {
+
+  private static final Logger LOG =
+      LoggerFactory.getLogger(CleanUpManager.class);
+
+  private static final String FILE_SEPARATOR = File.separator;
+
+  private static final String TMP_DELETE_SERVICE_DIR =
+      FILE_SEPARATOR + "tmp" + FILE_SEPARATOR + "container_delete_service";
+
+  private Path tmpDirPath;
+
+  public CleanUpManager(HddsVolume hddsVolume) {
+    setTmpDirPath(hddsVolume);
+
+    if (Files.notExists(tmpDirPath)) {
+      try {
+        Files.createDirectories(tmpDirPath);
+      } catch (IOException ex) {
+        LOG.error("Error creating {}", tmpDirPath.toString(), ex);
+      }
+    }
+  }
+
+  public Path getTmpDirPath() {
+    return tmpDirPath;
+  }
+
+  public static boolean checkContainerSchemaV3Enabled(
+      KeyValueContainerData keyValueContainerData) {
+    return (keyValueContainerData.getSchemaVersion()
+        .equals(OzoneConsts.SCHEMA_V3));
+  }
+
+  public static boolean checkContainerSchemaV3Enabled(
+      ConfigurationSource config) {
+    return VersionedDatanodeFeatures.SchemaV3
+        .isFinalizedAndEnabled(config);
+  }
+
+  private void setTmpDirPath(HddsVolume hddsVolume) {
+    StringBuilder stringBuilder = new StringBuilder();
+
+    // HddsVolume root directory path
+    String hddsRoot = hddsVolume.getHddsRootDir().toString();
+
+    // HddsVolume path
+    String volPath = HddsVolumeUtil.getHddsRoot(hddsRoot);
+
+    stringBuilder.append(volPath);
+    stringBuilder.append(FILE_SEPARATOR);
+
+    String clusterId = "";
+    try {
+      clusterId += hddsVolume.getClusterID();
+
+      if (clusterId == null) {
+        throw new IOException();
+      }
+    } catch (IOException ex) {
+      LOG.error("Volume has not been initialized, " +
+          "clusterId is null.", ex);
+    }
+
+    String pathId = "";
+    try {
+      pathId += VersionedDatanodeFeatures.ScmHA
+          .chooseContainerPathID(hddsVolume, clusterId);
+    } catch (IOException ex) {
+      LOG.error("Failed to get the container path Id", ex);
+    }
+
+    stringBuilder.append(pathId);
+    stringBuilder.append(TMP_DELETE_SERVICE_DIR);
+
+    String tmpPath = stringBuilder.toString();
+    this.tmpDirPath = Paths.get(tmpPath);
+  }
+
+  public boolean renameDir(KeyValueContainerData keyValueContainerData) {

Review Comment:
   It would be great to have a javadoc for this method



##########
hadoop-hdds/container-service/src/main/java/org/apache/hadoop/ozone/container/common/helpers/CleanUpManager.java:
##########
@@ -0,0 +1,207 @@
+/*
+ * 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 org.apache.commons.io.FileUtils;
+import org.apache.hadoop.hdds.conf.ConfigurationSource;
+import org.apache.hadoop.ozone.OzoneConsts;
+import org.apache.hadoop.ozone.container.common.utils.HddsVolumeUtil;
+import org.apache.hadoop.ozone.container.common.volume.HddsVolume;
+import org.apache.hadoop.ozone.container.keyvalue.KeyValueContainerData;
+import org.apache.hadoop.ozone.container.upgrade.VersionedDatanodeFeatures;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.io.File;
+import java.io.IOException;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.nio.file.Paths;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.ListIterator;
+
+/**
+ * Helper class for handling /tmp/container_delete_service
+ * operations used for container delete when Schema V3 is enabled.
+ */
+public class CleanUpManager {
+
+  private static final Logger LOG =
+      LoggerFactory.getLogger(CleanUpManager.class);
+
+  private static final String FILE_SEPARATOR = File.separator;
+
+  private static final String TMP_DELETE_SERVICE_DIR =
+      FILE_SEPARATOR + "tmp" + FILE_SEPARATOR + "container_delete_service";
+
+  private Path tmpDirPath;
+
+  public CleanUpManager(HddsVolume hddsVolume) {
+    setTmpDirPath(hddsVolume);
+
+    if (Files.notExists(tmpDirPath)) {
+      try {
+        Files.createDirectories(tmpDirPath);
+      } catch (IOException ex) {
+        LOG.error("Error creating {}", tmpDirPath.toString(), ex);
+      }
+    }
+  }
+
+  public Path getTmpDirPath() {
+    return tmpDirPath;
+  }
+
+  public static boolean checkContainerSchemaV3Enabled(
+      KeyValueContainerData keyValueContainerData) {
+    return (keyValueContainerData.getSchemaVersion()
+        .equals(OzoneConsts.SCHEMA_V3));
+  }
+
+  public static boolean checkContainerSchemaV3Enabled(
+      ConfigurationSource config) {
+    return VersionedDatanodeFeatures.SchemaV3
+        .isFinalizedAndEnabled(config);
+  }
+
+  private void setTmpDirPath(HddsVolume hddsVolume) {
+    StringBuilder stringBuilder = new StringBuilder();
+
+    // HddsVolume root directory path
+    String hddsRoot = hddsVolume.getHddsRootDir().toString();
+
+    // HddsVolume path
+    String volPath = HddsVolumeUtil.getHddsRoot(hddsRoot);
+
+    stringBuilder.append(volPath);
+    stringBuilder.append(FILE_SEPARATOR);
+
+    String clusterId = "";
+    try {
+      clusterId += hddsVolume.getClusterID();
+
+      if (clusterId == null) {
+        throw new IOException();
+      }
+    } catch (IOException ex) {
+      LOG.error("Volume has not been initialized, " +
+          "clusterId is null.", ex);
+    }
+
+    String pathId = "";
+    try {
+      pathId += VersionedDatanodeFeatures.ScmHA
+          .chooseContainerPathID(hddsVolume, clusterId);
+    } catch (IOException ex) {
+      LOG.error("Failed to get the container path Id", ex);
+    }
+
+    stringBuilder.append(pathId);
+    stringBuilder.append(TMP_DELETE_SERVICE_DIR);
+
+    String tmpPath = stringBuilder.toString();
+    this.tmpDirPath = Paths.get(tmpPath);
+  }
+
+  public boolean renameDir(KeyValueContainerData keyValueContainerData) {
+    String containerPath = keyValueContainerData.getContainerPath();
+    File container = new File(containerPath);
+    String containerDirName = container.getName();
+
+    String destinationDirPath = tmpDirPath
+        .resolve(Paths.get(containerDirName)).toString();
+
+    boolean success = container.renameTo(new File(destinationDirPath));
+
+    if (success) {
+      keyValueContainerData.setMetadataPath(destinationDirPath +
+          FILE_SEPARATOR + OzoneConsts.CONTAINER_META_PATH);
+      keyValueContainerData.setChunksPath(destinationDirPath +
+          FILE_SEPARATOR + OzoneConsts.STORAGE_DIR_CHUNKS);
+    }
+    return success;
+  }
+
+  /**
+   * Get direct files under /tmp/container_delete_service
+   * and store them in a list.
+   * @return iterator to the list of the leftover files
+   */
+  public ListIterator<File> getDeleteLeftovers() {

Review Comment:
   The only usage of this method outside of the class is test (TestContainerPersistence). Can we avoid keeping it public?



-- 
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: issues-unsubscribe@ozone.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@ozone.apache.org
For additional commands, e-mail: issues-help@ozone.apache.org