flink-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From se...@apache.org
Subject [54/63] [abbrv] git commit: Improved distribution of IDs. Previous implementation lost bits due to double-to-long multiplication and rounding.
Date Sun, 21 Sep 2014 02:13:18 GMT
Improved distribution of IDs. Previous implementation lost bits due to double-to-long multiplication
and rounding.


Project: http://git-wip-us.apache.org/repos/asf/incubator-flink/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-flink/commit/28764555
Tree: http://git-wip-us.apache.org/repos/asf/incubator-flink/tree/28764555
Diff: http://git-wip-us.apache.org/repos/asf/incubator-flink/diff/28764555

Branch: refs/heads/master
Commit: 2876455503b64177279ecfdd7e00a22aab53e17e
Parents: 5d13ddb
Author: Stephan Ewen <sewen@apache.org>
Authored: Wed Sep 17 00:03:00 2014 +0200
Committer: Stephan Ewen <sewen@apache.org>
Committed: Sat Sep 20 20:21:01 2014 +0200

----------------------------------------------------------------------
 .../java/org/apache/flink/runtime/AbstractID.java  | 17 ++++++-----------
 1 file changed, 6 insertions(+), 11 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-flink/blob/28764555/flink-runtime/src/main/java/org/apache/flink/runtime/AbstractID.java
----------------------------------------------------------------------
diff --git a/flink-runtime/src/main/java/org/apache/flink/runtime/AbstractID.java b/flink-runtime/src/main/java/org/apache/flink/runtime/AbstractID.java
index 1fa9491..e651f6c 100644
--- a/flink-runtime/src/main/java/org/apache/flink/runtime/AbstractID.java
+++ b/flink-runtime/src/main/java/org/apache/flink/runtime/AbstractID.java
@@ -21,6 +21,7 @@ package org.apache.flink.runtime;
 
 import java.io.IOException;
 import java.nio.ByteBuffer;
+import java.util.Random;
 
 import org.apache.flink.core.io.IOReadableWritable;
 import org.apache.flink.core.memory.DataInputView;
@@ -35,6 +36,9 @@ import io.netty.buffer.ByteBuf;
 public class AbstractID implements IOReadableWritable, Comparable<AbstractID>, java.io.Serializable
{
 
 	private static final long serialVersionUID = 1L;
+	
+	private static final Random RND = new Random();
+	
 
 	/** The size of a long in bytes */
 	private static final int SIZE_OF_LONG = 8;
@@ -94,8 +98,8 @@ public class AbstractID implements IOReadableWritable, Comparable<AbstractID>,
j
 	 * Constructs a new random ID from a uniform distribution.
 	 */
 	public AbstractID() {
-		this.lowerPart = generateRandomLong();
-		this.upperPart = generateRandomLong();
+		this.lowerPart = RND.nextLong();
+		this.upperPart = RND.nextLong();
 	}
 	
 	// --------------------------------------------------------------------------------------------
@@ -109,15 +113,6 @@ public class AbstractID implements IOReadableWritable, Comparable<AbstractID>,
j
 	}
 
 	// --------------------------------------------------------------------------------------------
-	
-	/**
-	 * Generates a uniformly distributed random positive long.
-	 *
-	 * @return a uniformly distributed random positive long
-	 */
-	protected static long generateRandomLong() {
-		return (long) (Math.random() * Long.MAX_VALUE);
-	}
 
 	/**
 	 * Converts the given byte array to a long.


Mime
View raw message