myskov commented on code in PR #3741: URL: https://github.com/apache/ozone/pull/3741#discussion_r965858045
########## 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: @xBis7 yes, but it's better for error description to be part of the exception. If catch statement will be changed in the future, this exception may be left as is. -- 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]
