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 2021/08/04 08:12:02 UTC

[GitHub] [ozone] elek commented on a change in pull request #2360: HDDS-5188. Replace GRPC based closed-container replication with Netty based streaming

elek commented on a change in pull request #2360:
URL: https://github.com/apache/ozone/pull/2360#discussion_r682390549



##########
File path: hadoop-hdds/container-service/src/main/java/org/apache/hadoop/ozone/container/replication/ContainerStreamingSource.java
##########
@@ -0,0 +1,101 @@
+/**
+ * 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
+ * <p>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p>
+ * 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 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.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.stream.Collectors;
+
+import org.apache.hadoop.hdds.protocol.datanode.proto.ContainerProtos.ContainerDataProto.State;
+import org.apache.hadoop.hdds.scm.container.common.helpers.StorageContainerException;
+import org.apache.hadoop.ozone.container.common.impl.ContainerSet;
+import org.apache.hadoop.ozone.container.keyvalue.KeyValueContainer;
+import org.apache.hadoop.ozone.container.stream.StreamingSource;
+
+/**
+ * Streaming source for closed-container replication.
+ */
+public class ContainerStreamingSource implements StreamingSource {
+
+  private ContainerSet containerSet;
+
+  public ContainerStreamingSource(ContainerSet containerSet) {
+    this.containerSet = containerSet;
+  }
+
+  @Override
+  public Map<String, Path> getFilesToStream(String id) {
+
+    Map<String, Path> filesToStream = new HashMap<>();
+
+    final long containerId = Long.parseLong(id);
+    final KeyValueContainer container =
+        (KeyValueContainer) containerSet.getContainer(containerId);
+
+    try {
+      container.release();
+    } catch (StorageContainerException e) {
+      throw new RuntimeException("Container couldn't be released: " + id, e);
+    }
+
+    if (container.getContainerState() != State.CLOSED
+        && container.getContainerState() != State.QUASI_CLOSED) {
+      throw new RuntimeException(
+          "Only (quasi)closed containers can be exported, but ContainerId=: "
+              + id + " is in state " + container.getContainerState());
+    }
+
+    try {
+
+      final File dbPath =
+          container.getContainerData().getContainerDBFile();
+
+      final List<Path> dbFiles =
+          Files.list(dbPath.toPath()).collect(Collectors.toList());

Review comment:
       > If timely disposal of file system resources is required, 
   
   Based on my understanding, this is about the `DirectoryStream`. The full context:
   
   >  The returned stream encapsulates a DirectoryStream. If timely disposal of file system resources is required, the try-with-resources construct should be used to ensure that the stream's close method is invoked after the stream operations are completed. 
   
   Based on my understanding, it suggests to explicitly close the stream if you need *timely* disposal of resources. I couldn't see any meaningful operation in the related close methods. So I assume the disposal of resources will happen anyway.
   
   At least this is my understanding.
   
   But to remain on the safe side, I just added the try-catch-resources 76ed04dd9.
    
   Let me know if you have any other concerns, try to help this PR to be merged as it's quite big...




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