zookeeper-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From br...@apache.org
Subject svn commit: r1088792 - in /zookeeper/trunk: CHANGES.txt src/c/src/zookeeper.c src/c/tests/TestZookeeperInit.cc
Date Mon, 04 Apr 2011 21:06:27 GMT
Author: breed
Date: Mon Apr  4 21:06:27 2011
New Revision: 1088792

URL: http://svn.apache.org/viewvc?rev=1088792&view=rev
Log:
ZOOKEEPER-1018. The connection permutation in get_addrs uses a weak and inefficient shuffle

Modified:
    zookeeper/trunk/CHANGES.txt
    zookeeper/trunk/src/c/src/zookeeper.c
    zookeeper/trunk/src/c/tests/TestZookeeperInit.cc

Modified: zookeeper/trunk/CHANGES.txt
URL: http://svn.apache.org/viewvc/zookeeper/trunk/CHANGES.txt?rev=1088792&r1=1088791&r2=1088792&view=diff
==============================================================================
--- zookeeper/trunk/CHANGES.txt (original)
+++ zookeeper/trunk/CHANGES.txt Mon Apr  4 21:06:27 2011
@@ -194,6 +194,8 @@ BUGFIXES: 
 
   ZOOKEEPER-880. QuorumCnxManager$SendWorker grows without bounds (vishal via breed)
 
+  ZOOKEEPER-1018. The connection permutation in get_addrs uses a weak and inefficient shuffle
(Stephen Tyree via breed)
+
 IMPROVEMENTS:
   ZOOKEEPER-724. Improve junit test integration - log harness information 
   (phunt via mahadev)

Modified: zookeeper/trunk/src/c/src/zookeeper.c
URL: http://svn.apache.org/viewvc/zookeeper/trunk/src/c/src/zookeeper.c?rev=1088792&r1=1088791&r2=1088792&view=diff
==============================================================================
--- zookeeper/trunk/src/c/src/zookeeper.c (original)
+++ zookeeper/trunk/src/c/src/zookeeper.c Mon Apr  4 21:06:27 2011
@@ -605,13 +605,12 @@ int getaddrs(zhandle_t *zh)
     if(!disable_conn_permute){
         setup_random();
         /* Permute */
-        for(i = 0; i < zh->addrs_count; i++) {
-            struct sockaddr_storage *s1 = zh->addrs + random()%zh->addrs_count;
-            struct sockaddr_storage *s2 = zh->addrs + random()%zh->addrs_count;
-            if (s1 != s2) {
-                struct sockaddr_storage t = *s1;
-                *s1 = *s2;
-                *s2 = t;
+        for (i = zh->addrs_count - 1; i > 0; --i) {
+            long int j = random()%(i+1);
+            if (i != j) {
+                struct sockaddr_storage t = zh->addrs[i];
+                zh->addrs[i] = zh->addrs[j];
+                zh->addrs[j] = t;
             }
         }
     }

Modified: zookeeper/trunk/src/c/tests/TestZookeeperInit.cc
URL: http://svn.apache.org/viewvc/zookeeper/trunk/src/c/tests/TestZookeeperInit.cc?rev=1088792&r1=1088791&r2=1088792&view=diff
==============================================================================
--- zookeeper/trunk/src/c/tests/TestZookeeperInit.cc (original)
+++ zookeeper/trunk/src/c/tests/TestZookeeperInit.cc Mon Apr  4 21:06:27 2011
@@ -279,7 +279,7 @@ public:
         const char EXPECTED[][5]={"\0\0\0\0","\1\1\1\1","\2\2\2\2","\3\3\3\3"};
         const int EXPECTED_ADDR_COUNT=COUNTOF(EXPECTED);
 
-        const int RAND_SEQ[]={0,1,2,3,1,3,2,0,-1};
+        const int RAND_SEQ[]={0,1,1,-1};
         const int RAND_SIZE=COUNTOF(RAND_SEQ);
         Mock_random randomMock;
         randomMock.randomReturns.assign(RAND_SEQ,RAND_SEQ+RAND_SIZE-1);



Mime
View raw message