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/07/21 08:18:39 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_r673760896



##########
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:
       That's an interesting question, I never realized that streams are `AutoClosable`. Tried to find out more information and found this one: 
   
   https://www.baeldung.com/java-stream-close
   
   > When dealing with these sorts of streams, we shouldn't close them explicitly.
   
   I tried to check the implementation of `Files.list`/`Files.walk` and based on my understanding we don't need to close them as there are no open resources (I think `AbstractPipeline.close() is called in both cases). 
   
   But please let me know if I am wrong.




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