You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cassandra.apache.org by sl...@apache.org on 2016/01/18 15:27:43 UTC
[04/10] cassandra git commit: Make UUID LSB unique per-process
Make UUID LSB unique per-process
patch by slebresne; reviewed by benedict for CASSANDRA-7925
Project: http://git-wip-us.apache.org/repos/asf/cassandra/repo
Commit: http://git-wip-us.apache.org/repos/asf/cassandra/commit/47e8ef9e
Tree: http://git-wip-us.apache.org/repos/asf/cassandra/tree/47e8ef9e
Diff: http://git-wip-us.apache.org/repos/asf/cassandra/diff/47e8ef9e
Branch: refs/heads/trunk
Commit: 47e8ef9e9ce70c54115681f854f483a53992c988
Parents: 79b9492
Author: Sylvain Lebresne <sy...@datastax.com>
Authored: Fri Jan 15 15:25:03 2016 +0100
Committer: Sylvain Lebresne <sy...@datastax.com>
Committed: Mon Jan 18 15:24:50 2016 +0100
----------------------------------------------------------------------
CHANGES.txt | 1 +
.../org/apache/cassandra/service/StartupChecks.java | 2 +-
src/java/org/apache/cassandra/utils/SigarLibrary.java | 9 ++++++++-
src/java/org/apache/cassandra/utils/UUIDGen.java | 12 ++++++++++++
4 files changed, 22 insertions(+), 2 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/cassandra/blob/47e8ef9e/CHANGES.txt
----------------------------------------------------------------------
diff --git a/CHANGES.txt b/CHANGES.txt
index 2bfba80..f571c29 100644
--- a/CHANGES.txt
+++ b/CHANGES.txt
@@ -1,4 +1,5 @@
2.2.5
+ * Make UUID LSB unique per process (CASSANDRA-7925)
* Avoid NPE when performing sstable tasks (scrub etc.) (CASSANDRA-10980)
* Make sure client gets tombstone overwhelmed warning (CASSANDRA-9465)
* Fix error streaming section more than 2GB (CASSANDRA-10961)
http://git-wip-us.apache.org/repos/asf/cassandra/blob/47e8ef9e/src/java/org/apache/cassandra/service/StartupChecks.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/cassandra/service/StartupChecks.java b/src/java/org/apache/cassandra/service/StartupChecks.java
index 19f32b6..34bc824 100644
--- a/src/java/org/apache/cassandra/service/StartupChecks.java
+++ b/src/java/org/apache/cassandra/service/StartupChecks.java
@@ -195,7 +195,7 @@ public class StartupChecks
{
public void execute()
{
- new SigarLibrary().warnIfRunningInDegradedMode();
+ SigarLibrary.instance.warnIfRunningInDegradedMode();
}
};
http://git-wip-us.apache.org/repos/asf/cassandra/blob/47e8ef9e/src/java/org/apache/cassandra/utils/SigarLibrary.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/cassandra/utils/SigarLibrary.java b/src/java/org/apache/cassandra/utils/SigarLibrary.java
index 7cf4d71..0312204 100644
--- a/src/java/org/apache/cassandra/utils/SigarLibrary.java
+++ b/src/java/org/apache/cassandra/utils/SigarLibrary.java
@@ -25,6 +25,8 @@ public class SigarLibrary
{
private Logger logger = LoggerFactory.getLogger(SigarLibrary.class);
+ public static final SigarLibrary instance = new SigarLibrary();
+
private Sigar sigar;
private FileSystemMap mounts = null;
private boolean initialized = false;
@@ -37,7 +39,7 @@ public class SigarLibrary
// TODO: Determine if file system is remote or local
// TODO: Determine if disk latency is within acceptable limits
- public SigarLibrary()
+ private SigarLibrary()
{
logger.info("Initializing SIGAR library");
try
@@ -154,6 +156,11 @@ public class SigarLibrary
}
}
+ public long getPid()
+ {
+ return initialized ? sigar.getPid() : -1;
+ }
+
public void warnIfRunningInDegradedMode()
{
if (initialized)
http://git-wip-us.apache.org/repos/asf/cassandra/blob/47e8ef9e/src/java/org/apache/cassandra/utils/UUIDGen.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/cassandra/utils/UUIDGen.java b/src/java/org/apache/cassandra/utils/UUIDGen.java
index a777a50..df07e1f 100644
--- a/src/java/org/apache/cassandra/utils/UUIDGen.java
+++ b/src/java/org/apache/cassandra/utils/UUIDGen.java
@@ -26,6 +26,7 @@ import java.util.Random;
import java.util.UUID;
import com.google.common.annotations.VisibleForTesting;
+import com.google.common.base.Charsets;
/**
@@ -309,10 +310,21 @@ public class UUIDGen
{
try
{
+ // Identify the host.
MessageDigest messageDigest = MessageDigest.getInstance("MD5");
for(InetAddress addr : data)
messageDigest.update(addr.getAddress());
+ // Identify the process on the load: we use both the PID and class loader hash.
+ long pid = SigarLibrary.instance.getPid();
+ if (pid < 0)
+ pid = new Random(System.currentTimeMillis()).nextLong();
+ FBUtilities.updateWithLong(messageDigest, pid);
+
+ ClassLoader loader = UUIDGen.class.getClassLoader();
+ int loaderId = loader != null ? System.identityHashCode(loader) : 0;
+ FBUtilities.updateWithInt(messageDigest, loaderId);
+
return messageDigest.digest();
}
catch (NoSuchAlgorithmException nsae)