You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pulsar.apache.org by GitBox <gi...@apache.org> on 2022/02/19 19:02:24 UTC

[GitHub] [pulsar] eolivelli commented on a change in pull request #14346: [Pulsar-Functions] Use ComputeIfAbsent instead in FunctionCacheManagerImpl

eolivelli commented on a change in pull request #14346:
URL: https://github.com/apache/pulsar/pull/14346#discussion_r810526246



##########
File path: pulsar-functions/utils/src/main/java/org/apache/pulsar/functions/utils/functioncache/FunctionCacheManagerImpl.java
##########
@@ -74,9 +76,9 @@ public void registerFunctionInstance(String fid,
         }
 
         synchronized (cacheFunctions) {
-            FunctionCacheEntry entry = cacheFunctions.get(fid);
-
-            if (null == entry) {
+            final AtomicBoolean computed = new AtomicBoolean(false);
+            final AtomicReference<Throwable> throwable = new AtomicReference<>();
+            FunctionCacheEntry entry = cacheFunctions.computeIfAbsent(fid, __ -> {

Review comment:
       Please note that the contract of computeIfAbsent is that the function must be side effect free because it can be executed multiple times.
   I am not sure that this function is side effect free
   Can you please double check?




-- 
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: commits-unsubscribe@pulsar.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org