You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@ozone.apache.org by "sodonnel (via GitHub)" <gi...@apache.org> on 2023/01/23 12:55:49 UTC

[GitHub] [ozone] sodonnel commented on a diff in pull request #4197: HDDS-7776. Container replication in push model

sodonnel commented on code in PR #4197:
URL: https://github.com/apache/ozone/pull/4197#discussion_r1084022505


##########
hadoop-hdds/container-service/src/main/java/org/apache/hadoop/ozone/container/replication/ContainerImporter.java:
##########
@@ -0,0 +1,126 @@
+/*
+ * 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.replication;
+
+import org.apache.hadoop.hdds.conf.ConfigurationSource;
+import org.apache.hadoop.hdds.conf.StorageUnit;
+import org.apache.hadoop.hdds.scm.ScmConfigKeys;
+import org.apache.hadoop.ozone.container.common.impl.ContainerDataYaml;
+import org.apache.hadoop.ozone.container.common.impl.ContainerSet;
+import org.apache.hadoop.ozone.container.common.interfaces.Container;
+import org.apache.hadoop.ozone.container.common.interfaces.VolumeChoosingPolicy;
+import org.apache.hadoop.ozone.container.common.utils.StorageVolumeUtil;
+import org.apache.hadoop.ozone.container.common.volume.HddsVolume;
+import org.apache.hadoop.ozone.container.common.volume.MutableVolumeSet;
+import org.apache.hadoop.ozone.container.common.volume.RoundRobinVolumeChoosingPolicy;
+import org.apache.hadoop.ozone.container.keyvalue.KeyValueContainerData;
+import org.apache.hadoop.ozone.container.keyvalue.TarContainerPacker;
+import org.apache.hadoop.ozone.container.ozoneimpl.ContainerController;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.io.FileInputStream;
+import java.io.IOException;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.nio.file.Paths;
+
+import static org.apache.hadoop.hdds.HddsConfigKeys.HDDS_DATANODE_VOLUME_CHOOSING_POLICY;
+
+/**
+ * Imports container from tarball.
+ */
+public class ContainerImporter {
+
+  private static final Logger LOG =
+      LoggerFactory.getLogger(ContainerImporter.class);
+
+  public static final String CONTAINER_COPY_DIR = "container-copy";
+  private static final String CONTAINER_COPY_TMP_DIR = "tmp";
+  private final ContainerSet containerSet;
+  private final ContainerController controller;
+  private final TarContainerPacker packer;
+  private final MutableVolumeSet volumeSet;
+  private final VolumeChoosingPolicy volumeChoosingPolicy;
+  private final long containerSize;
+
+  public ContainerImporter(ConfigurationSource conf, ContainerSet containerSet,
+      ContainerController controller, TarContainerPacker tarContainerPacker,
+      MutableVolumeSet volumeSet) {
+    this.containerSet = containerSet;
+    this.controller = controller;
+    this.packer = tarContainerPacker;
+    this.volumeSet = volumeSet;
+    try {
+      volumeChoosingPolicy = conf.getClass(
+          HDDS_DATANODE_VOLUME_CHOOSING_POLICY, RoundRobinVolumeChoosingPolicy
+              .class, VolumeChoosingPolicy.class).newInstance();
+    } catch (Exception e) {
+      throw new RuntimeException(e);
+    }
+    containerSize = (long) conf.getStorageSize(
+        ScmConfigKeys.OZONE_SCM_CONTAINER_SIZE,
+        ScmConfigKeys.OZONE_SCM_CONTAINER_SIZE_DEFAULT, StorageUnit.BYTES);
+  }
+
+  public void importContainer(long containerID, Path tarFilePath,
+      HddsVolume hddsVolume) throws IOException {
+
+    HddsVolume targetVolume = hddsVolume;
+    if (targetVolume == null) {
+      targetVolume = chooseNextVolume();
+    }
+    try {
+      KeyValueContainerData containerData;
+
+      try (FileInputStream input = new FileInputStream(tarFilePath.toFile())) {
+        byte[] containerDescriptorYaml =

Review Comment:
   Not an issue with this PR, but I thought it was interesting we pull out a specific "container descriptor" file and then another step to pull out the container data.
   
   A tar file isn't really indexed, and it doesn't have a "directory listing" section to list the files in it, it skips from one file header to the next seeking down the file. So if this file is always at the end, it must check all other file headers in the archive first.
   
   In TarContainerPacker.pack:
   
   ```
     @Override
     public void pack(Container<KeyValueContainerData> container,
         OutputStream output)
         throws IOException {
   
       KeyValueContainerData containerData = container.getContainerData();
   
       try (OutputStream compressed = compress(output);
            ArchiveOutputStream archiveOutput = tar(compressed)) {
   
         includePath(getDbPath(containerData), DB_DIR_NAME,
             archiveOutput);
   
         includePath(Paths.get(containerData.getChunksPath()), CHUNKS_DIR_NAME,
             archiveOutput);
   
         includeFile(container.getContainerFile(), CONTAINER_FILE_NAME,
             archiveOutput);
       } catch (CompressorException e) {
         throw new IOException(
             "Can't compress the container: " + containerData.getContainerID(),
             e);
       }
     }
   ```
   
   We can see it adds this descriptor to the end of the archive, which is the worst place it can be in, if we always want to extract that file individually! I have no idea what this costs in terms of overhead, but it feels like it might be a good idea to place this file at the start of the archive, especially if its the only one we want to extract individually.



-- 
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