asterixdb-notifications mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Ildar Absalyamov (Code Review)" <do-not-re...@asterixdb.incubator.apache.org>
Subject Change in asterixdb[master]: Fixed race condition during ncMap lookup
Date Tue, 30 May 2017 18:06:57 GMT
Ildar Absalyamov has uploaded a new change for review.

  https://asterix-gerrit.ics.uci.edu/1792

Change subject: Fixed race condition during ncMap lookup
......................................................................

Fixed race condition during ncMap lookup

Change-Id: I1bfbe712c100f48011a516c373ac8994028dc3dd
---
M asterixdb/asterix-external-data/src/main/java/org/apache/asterix/external/util/NodeResolver.java
1 file changed, 29 insertions(+), 29 deletions(-)


  git pull ssh://asterix-gerrit.ics.uci.edu:29418/asterixdb refs/changes/92/1792/1

diff --git a/asterixdb/asterix-external-data/src/main/java/org/apache/asterix/external/util/NodeResolver.java
b/asterixdb/asterix-external-data/src/main/java/org/apache/asterix/external/util/NodeResolver.java
index 5b15e9e..5a0189b 100644
--- a/asterixdb/asterix-external-data/src/main/java/org/apache/asterix/external/util/NodeResolver.java
+++ b/asterixdb/asterix-external-data/src/main/java/org/apache/asterix/external/util/NodeResolver.java
@@ -45,43 +45,43 @@
     @Override
     public String resolveNode(ICcApplicationContext appCtx, String value) throws AsterixException
{
         try {
-            if (ncMap.isEmpty()) {
-                NodeResolver.updateNCs(appCtx);
-            }
-            if (ncs.contains(value)) {
-                return value;
-            } else {
-                NodeResolver.updateNCs(appCtx);
-                if (ncs.contains(value)) {
-                    return value;
+            synchronized (ncMap) {
+                synchronized (ncs) {
+                    if (ncMap.isEmpty()) {
+                        NodeResolver.updateNCs(appCtx);
+                    }
+                    if (ncs.contains(value)) {
+                        return value;
+                    } else {
+                        NodeResolver.updateNCs(appCtx);
+                        if (ncs.contains(value)) {
+                            return value;
+                        }
+                    }
+                    InetAddress ipAddress = null;
+                    try {
+                        ipAddress = InetAddress.getByName(value);
+                    } catch (UnknownHostException e) {
+                        throw new AsterixException(ErrorCode.NODE_RESOLVER_UNABLE_RESOLVE_HOST,
e, value);
+                    }
+                    Set<String> nodeControllers = ncMap.get(ipAddress);
+                    if (nodeControllers == null || nodeControllers.isEmpty()) {
+                        throw new AsterixException(ErrorCode.NODE_RESOLVER_NO_NODE_CONTROLLERS,
value);
+                    }
+                    return nodeControllers.toArray(new String[] {})[random.nextInt(nodeControllers.size())];
                 }
             }
-            InetAddress ipAddress = null;
-            try {
-                ipAddress = InetAddress.getByName(value);
-            } catch (UnknownHostException e) {
-                throw new AsterixException(ErrorCode.NODE_RESOLVER_UNABLE_RESOLVE_HOST, e,
value);
-            }
-            Set<String> nodeControllers = ncMap.get(ipAddress);
-            if (nodeControllers == null || nodeControllers.isEmpty()) {
-                throw new AsterixException(ErrorCode.NODE_RESOLVER_NO_NODE_CONTROLLERS, value);
-            }
-            return nodeControllers.toArray(new String[] {})[random.nextInt(nodeControllers.size())];
         } catch (Exception e) {
             throw new AsterixException(e);
         }
     }
 
     private static void updateNCs(ICcApplicationContext appCtx) throws Exception {
-        synchronized (ncMap) {
-            ncMap.clear();
-            RuntimeUtils.getNodeControllerMap(appCtx, ncMap);
-            synchronized (ncs) {
-                ncs.clear();
-                for (Entry<InetAddress, Set<String>> entry : ncMap.entrySet())
{
-                    ncs.addAll(entry.getValue());
-                }
-            }
+        ncMap.clear();
+        RuntimeUtils.getNodeControllerMap(appCtx, ncMap);
+        ncs.clear();
+        for (Entry<InetAddress, Set<String>> entry : ncMap.entrySet()) {
+            ncs.addAll(entry.getValue());
         }
     }
 }

-- 
To view, visit https://asterix-gerrit.ics.uci.edu/1792
To unsubscribe, visit https://asterix-gerrit.ics.uci.edu/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I1bfbe712c100f48011a516c373ac8994028dc3dd
Gerrit-PatchSet: 1
Gerrit-Project: asterixdb
Gerrit-Branch: master
Gerrit-Owner: Ildar Absalyamov <ildar.absalyamov@gmail.com>

Mime
View raw message