zookeeper-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From an...@apache.org
Subject zookeeper git commit: ZOOKEEPER-1990: fix Random instances
Date Mon, 10 Sep 2018 09:45:10 GMT
Repository: zookeeper
Updated Branches:
  refs/heads/branch-3.5 87a2d458f -> 5bcbb2ca6


ZOOKEEPER-1990: fix Random instances

See the jira for more info.

Basically we have multiple ways of creating Random instances in ZooKeeper. Since java 1.7,
the default constructor is good enough even in multi-threaded environment, we get a good seed.
But in some places, we just create a random instance, where System.nanotime is the seed, which
is not a good practice in multi-threaded environments.

I only replaced those, and I also left the tests as is, because in some cases it is intentional
in them.

I created the PR to bring more attention to the ticket, please feel free to share your ideas
on the topic!

Author: Norbert Kalmar <nkalmar@yahoo.com>

Reviewers: fangmin@apache.org, andor@apache.org

Closes #617 from nkalmar/ZOOKEEPER-1990

(cherry picked from commit 181de25c0dc703eaff77dd6415b676f09564277a)
Signed-off-by: Andor Molnar <andor@apache.org>


Project: http://git-wip-us.apache.org/repos/asf/zookeeper/repo
Commit: http://git-wip-us.apache.org/repos/asf/zookeeper/commit/5bcbb2ca
Tree: http://git-wip-us.apache.org/repos/asf/zookeeper/tree/5bcbb2ca
Diff: http://git-wip-us.apache.org/repos/asf/zookeeper/diff/5bcbb2ca

Branch: refs/heads/branch-3.5
Commit: 5bcbb2ca61309f37634b530788c01989e7a4001a
Parents: 87a2d45
Author: Norbert Kalmar <nkalmar@yahoo.com>
Authored: Mon Sep 10 11:44:50 2018 +0200
Committer: Andor Molnar <andor@apache.org>
Committed: Mon Sep 10 11:45:06 2018 +0200

----------------------------------------------------------------------
 src/java/main/org/apache/zookeeper/ClientCnxn.java                 | 2 +-
 .../main/org/apache/zookeeper/server/SyncRequestProcessor.java     | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/zookeeper/blob/5bcbb2ca/src/java/main/org/apache/zookeeper/ClientCnxn.java
----------------------------------------------------------------------
diff --git a/src/java/main/org/apache/zookeeper/ClientCnxn.java b/src/java/main/org/apache/zookeeper/ClientCnxn.java
index b28c980..f02142f 100644
--- a/src/java/main/org/apache/zookeeper/ClientCnxn.java
+++ b/src/java/main/org/apache/zookeeper/ClientCnxn.java
@@ -801,7 +801,7 @@ public class ClientCnxn {
     class SendThread extends ZooKeeperThread {
         private long lastPingSentNs;
         private final ClientCnxnSocket clientCnxnSocket;
-        private Random r = new Random(System.nanoTime());        
+        private Random r = new Random();
         private boolean isFirstConnect = true;
 
         void readResponse(ByteBuffer incomingBuffer) throws IOException {

http://git-wip-us.apache.org/repos/asf/zookeeper/blob/5bcbb2ca/src/java/main/org/apache/zookeeper/server/SyncRequestProcessor.java
----------------------------------------------------------------------
diff --git a/src/java/main/org/apache/zookeeper/server/SyncRequestProcessor.java b/src/java/main/org/apache/zookeeper/server/SyncRequestProcessor.java
index 47701dc..57cca9c 100644
--- a/src/java/main/org/apache/zookeeper/server/SyncRequestProcessor.java
+++ b/src/java/main/org/apache/zookeeper/server/SyncRequestProcessor.java
@@ -61,7 +61,7 @@ public class SyncRequestProcessor extends ZooKeeperCriticalThread implements
      * invoked after flush returns successfully.
      */
     private final LinkedList<Request> toFlush = new LinkedList<Request>();
-    private final Random r = new Random(System.nanoTime());
+    private final Random r = new Random();
     /**
      * The number of log entries to log before starting a snapshot
      */


Mime
View raw message