vanzin commented on a change in pull request #27010: [SPARK-30313][CORE] Ensure 
EndpointRef is available MasterWebUI/WorkerPage
URL: https://github.com/apache/spark/pull/27010#discussion_r362651134
 
 

 ##########
 File path: core/src/main/scala/org/apache/spark/rpc/netty/Dispatcher.scala
 ##########
 @@ -68,11 +66,27 @@ private[netty] class Dispatcher(nettyEnv: NettyRpcEnv, 
numUsableCores: Int) exte
       if (stopped) {
         throw new IllegalStateException("RpcEnv has been stopped")
       }
-      if (endpoints.putIfAbsent(name, getMessageLoop(name, endpoint)) != null) 
{
+      if (endpoints.containsKey(name)) {
         throw new IllegalArgumentException(s"There is already an RpcEndpoint 
called $name")
       }
+      val msgLoop = findMessageLoop(name, endpoint)
+      endpoints.put(name, msgLoop)
+      try {
+        endpointRefs.put(endpoint, endpointRef)
 
 Review comment:
   Hmm. This is all correct but feels a bit overkill. Seems like a simpler 
version would be:
   
   ```
   endpointRefs.put(endpoint, endpointRef)
   try {
     endpoints.put(name, getMessageLoop(name, endpoint))
   } catch {
     // cleanup endpointRefs
   }
   ```
   
   Yes, that uses the old `getMessageLoop()` (which could be inlined here for 
clarity), but that's ok as long as it's done after the `containsKey` check. 
Then you don't even need the changes to the other file.

----------------------------------------------------------------
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.
 
For queries about this service, please contact Infrastructure at:
[email protected]


With regards,
Apache Git Services

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

Reply via email to