Repository: hadoop
Updated Branches:
  refs/heads/HDFS-7240 507447c81 -> 72e301622


HDFS-12178. Ozone: OzoneClient: Handling SCM container creationFlag at client 
side. Contributed by Nandakumar.


Project: http://git-wip-us.apache.org/repos/asf/hadoop/repo
Commit: http://git-wip-us.apache.org/repos/asf/hadoop/commit/72e30162
Tree: http://git-wip-us.apache.org/repos/asf/hadoop/tree/72e30162
Diff: http://git-wip-us.apache.org/repos/asf/hadoop/diff/72e30162

Branch: refs/heads/HDFS-7240
Commit: 72e3016224749c06d8345106fc8165b281bc3c09
Parents: 507447c
Author: Anu Engineer <[email protected]>
Authored: Fri Aug 4 10:17:45 2017 -0700
Committer: Anu Engineer <[email protected]>
Committed: Fri Aug 4 10:17:45 2017 -0700

----------------------------------------------------------------------
 .../web/storage/ChunkGroupOutputStream.java     | 35 ++++++++++++++++----
 1 file changed, 28 insertions(+), 7 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/hadoop/blob/72e30162/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/ozone/web/storage/ChunkGroupOutputStream.java
----------------------------------------------------------------------
diff --git 
a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/ozone/web/storage/ChunkGroupOutputStream.java
 
b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/ozone/web/storage/ChunkGroupOutputStream.java
index f479f0a..59c2639 100644
--- 
a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/ozone/web/storage/ChunkGroupOutputStream.java
+++ 
b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/ozone/web/storage/ChunkGroupOutputStream.java
@@ -19,6 +19,7 @@ package org.apache.hadoop.ozone.web.storage;
 
 import com.google.common.annotations.VisibleForTesting;
 import com.google.common.base.Preconditions;
+import org.apache.hadoop.hdfs.ozone.protocol.proto.ContainerProtos.Result;
 import org.apache.hadoop.ksm.helpers.KsmKeyInfo;
 import org.apache.hadoop.ksm.helpers.KsmKeyLocationInfo;
 import org.apache.hadoop.scm.XceiverClientManager;
@@ -34,6 +35,8 @@ import org.slf4j.LoggerFactory;
 import java.io.IOException;
 import java.io.OutputStream;
 import java.util.ArrayList;
+import java.util.HashSet;
+import java.util.Set;
 
 /**
  * Maintaining a list of ChunkInputStream. Write based on offset.
@@ -55,6 +58,10 @@ public class ChunkGroupOutputStream extends OutputStream {
   private long totalSize;
   private long byteOffset;
 
+  //This has to be removed once HDFS-11888 is resolved.
+  //local cache which will have list of created container names.
+  private static Set<String> containersCreated = new HashSet<>();
+
   public ChunkGroupOutputStream() {
     this.streamEntries = new ArrayList<>();
     this.currentStreamIndex = 0;
@@ -285,13 +292,27 @@ public class ChunkGroupOutputStream extends OutputStream {
           xceiverClientManager.acquireClient(pipeline);
       // create container if needed
       // TODO : should be subKeyInfo.getShouldCreateContainer(), but for now
-      // always true.
-      boolean shouldCreate = true;
-      if (shouldCreate) {
-        try {
-          ContainerProtocolCalls.createContainer(xceiverClient, requestId);
-        } catch (StorageContainerException sce) {
-          LOG.warn("Create container failed with {}", containerName, sce);
+      //The following change has to reverted once HDFS-11888 is fixed.
+      if(!containersCreated.contains(containerName)) {
+        synchronized (containerName.intern()) {
+          //checking again, there is a chance that some other thread has
+          // created it.
+          if (!containersCreated.contains(containerName)) {
+            LOG.debug("Need to create container {}.", containerName);
+            try {
+              ContainerProtocolCalls.createContainer(xceiverClient, requestId);
+            } catch (StorageContainerException ex) {
+              if (ex.getResult().equals(Result.CONTAINER_EXISTS)) {
+                //container already exist.
+                LOG.debug("Container {} already exists.", containerName);
+              } else {
+                LOG.error("Container creation failed for {}.",
+                    containerName, ex);
+                throw ex;
+              }
+            }
+            containersCreated.add(containerName);
+          }
         }
       }
 


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to