siddhantsangwan commented on code in PR #5191:
URL: https://github.com/apache/ozone/pull/5191#discussion_r1297246239


##########
hadoop-hdds/server-scm/src/main/java/org/apache/hadoop/hdds/scm/container/ContainerManagerImpl.java:
##########
@@ -202,22 +205,26 @@ public ContainerInfo allocateContainer(
             " matching pipeline for replicationConfig: " + replicationConfig
             + ", State:PipelineState.OPEN", e);
       }
-      pipelineManager.acquireReadLock();
-      lock.lock();
+
       try {
-        pipelines = pipelineManager
-            .getPipelines(replicationConfig, Pipeline.PipelineState.OPEN);
-        if (!pipelines.isEmpty()) {
-          pipeline = pipelines.get(random.nextInt(pipelines.size()));
-          containerInfo = createContainer(pipeline, owner);
-        } else {
-          throw new IOException("Could not allocate container. Cannot get any" 
+
-              " matching pipeline for replicationConfig: " + replicationConfig
-              + ", State:PipelineState.OPEN");
+        lock.lock();
+        try {
+          pipelineManager.acquireReadLock();

Review Comment:
   Is there any reason for acquiring locks inside try blocks? If not, it's 
better to move them outside the try blocks. 
   
   My reasoning: If some implementation of these locks ends up throwing an 
unchecked exception when trying to lock, then we won't acquire the lock but 
still try to unlock it in finally. That will throw a runtime exception.



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

Reply via email to