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:44:56 GMT
Repository: zookeeper
Updated Branches:
  refs/heads/master 27db6bd28 -> 181de25c0


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


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

Branch: refs/heads/master
Commit: 181de25c0dc703eaff77dd6415b676f09564277a
Parents: 27db6bd
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:44:50 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/181de25c/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/181de25c/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