You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@druid.apache.org by as...@apache.org on 2019/01/25 11:49:25 UTC

[incubator-druid] branch master updated: Issue#6892- Replaced Math.random() with ThreadLocalRandom.current().nextDouble() (#6914)

This is an automated email from the ASF dual-hosted git repository.

asdf2014 pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-druid.git


The following commit(s) were added to refs/heads/master by this push:
     new e1033bb  Issue#6892- Replaced Math.random() with ThreadLocalRandom.current().nextDouble() (#6914)
e1033bb is described below

commit e1033bb412244fc9dff9dea1c89d43a8e0081fd3
Author: Himanshu Pandey <hp...@pivotal.io>
AuthorDate: Fri Jan 25 03:49:20 2019 -0800

    Issue#6892- Replaced Math.random() with ThreadLocalRandom.current().nextDouble() (#6914)
    
    *  Replacing Math.random() with ThreadLocalRandom.current().nextDouble()
    
    * Added java.lang.Math#random() in forbidden-apis.txt
    
    * Minor change in the message - druid-forbidden-apis.txt
---
 codestyle/druid-forbidden-apis.txt                                    | 1 +
 .../apache/druid/indexing/common/actions/SegmentAllocateAction.java   | 3 ++-
 .../java/org/apache/druid/segment/data/CompressedFloatsSerdeTest.java | 4 ++--
 .../java/org/apache/druid/segment/data/CompressedLongsSerdeTest.java  | 4 ++--
 4 files changed, 7 insertions(+), 5 deletions(-)

diff --git a/codestyle/druid-forbidden-apis.txt b/codestyle/druid-forbidden-apis.txt
index 25735d0..c21ca25 100644
--- a/codestyle/druid-forbidden-apis.txt
+++ b/codestyle/druid-forbidden-apis.txt
@@ -31,5 +31,6 @@ java.lang.String#replaceAll(java.lang.String,java.lang.String) @ Use one of the
 java.lang.String#replaceFirst(java.lang.String,java.lang.String) @ Use String.indexOf() and substring methods, or compile and cache a Pattern explicitly
 java.util.LinkedList @ Use ArrayList or ArrayDeque instead
 java.util.Random#<init>() @ Use ThreadLocalRandom.current() or the constructor with a seed (the latter in tests only!)
+java.lang.Math#random() @ Use ThreadLocalRandom.current()
 java.util.regex.Pattern#matches(java.lang.String,java.lang.CharSequence) @ Use String.startsWith(), endsWith(), contains(), or compile and cache a Pattern explicitly
 org.apache.commons.io.FileUtils#getTempDirectory() @ Use org.junit.rules.TemporaryFolder for tests instead
\ No newline at end of file
diff --git a/indexing-service/src/main/java/org/apache/druid/indexing/common/actions/SegmentAllocateAction.java b/indexing-service/src/main/java/org/apache/druid/indexing/common/actions/SegmentAllocateAction.java
index 69d8dcf..a6a58bc 100644
--- a/indexing-service/src/main/java/org/apache/druid/indexing/common/actions/SegmentAllocateAction.java
+++ b/indexing-service/src/main/java/org/apache/druid/indexing/common/actions/SegmentAllocateAction.java
@@ -42,6 +42,7 @@ import org.joda.time.Interval;
 
 import java.util.List;
 import java.util.Set;
+import java.util.concurrent.ThreadLocalRandom;
 import java.util.stream.Collectors;
 
 /**
@@ -184,7 +185,7 @@ public class SegmentAllocateAction implements TaskAction<SegmentIdWithShardSpec>
 
       if (!ImmutableSet.copyOf(msc.getUsedSegmentsForInterval(dataSource, rowInterval)).equals(usedSegmentsForRow)) {
         if (attempt < MAX_ATTEMPTS) {
-          final long shortRandomSleep = 50 + (long) (Math.random() * 450);
+          final long shortRandomSleep = 50 + (long) (ThreadLocalRandom.current().nextDouble() * 450);
           log.debug(
               "Used segment set changed for rowInterval[%s]. Retrying segment allocation in %,dms (attempt = %,d).",
               rowInterval,
diff --git a/processing/src/test/java/org/apache/druid/segment/data/CompressedFloatsSerdeTest.java b/processing/src/test/java/org/apache/druid/segment/data/CompressedFloatsSerdeTest.java
index 7d7bd6f..ef041a2 100644
--- a/processing/src/test/java/org/apache/druid/segment/data/CompressedFloatsSerdeTest.java
+++ b/processing/src/test/java/org/apache/druid/segment/data/CompressedFloatsSerdeTest.java
@@ -129,8 +129,8 @@ public class CompressedFloatsSerdeTest
 
     assertIndexMatchesVals(floats, values);
     for (int i = 0; i < 10; i++) {
-      int a = (int) (Math.random() * values.length);
-      int b = (int) (Math.random() * values.length);
+      int a = (int) (ThreadLocalRandom.current().nextDouble() * values.length);
+      int b = (int) (ThreadLocalRandom.current().nextDouble() * values.length);
       int start = a < b ? a : b;
       int end = a < b ? b : a;
       tryFill(floats, values, start, end - start);
diff --git a/processing/src/test/java/org/apache/druid/segment/data/CompressedLongsSerdeTest.java b/processing/src/test/java/org/apache/druid/segment/data/CompressedLongsSerdeTest.java
index 0f65d65..02e30f6 100644
--- a/processing/src/test/java/org/apache/druid/segment/data/CompressedLongsSerdeTest.java
+++ b/processing/src/test/java/org/apache/druid/segment/data/CompressedLongsSerdeTest.java
@@ -152,8 +152,8 @@ public class CompressedLongsSerdeTest
 
     assertIndexMatchesVals(longs, values);
     for (int i = 0; i < 10; i++) {
-      int a = (int) (Math.random() * values.length);
-      int b = (int) (Math.random() * values.length);
+      int a = (int) (ThreadLocalRandom.current().nextDouble() * values.length);
+      int b = (int) (ThreadLocalRandom.current().nextDouble() * values.length);
       int start = a < b ? a : b;
       int end = a < b ? b : a;
       tryFill(longs, values, start, end - start);


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org