Add Java process information to UUIDs.makeNode() hash

Description

Currently there is a chance of collision if multiple Java processes on the same machine are using DataStax Java Driver to generate UUIDs. This is because the hash in UUIDs.makeNode() (https://github.com/datastax/java-driver/blob/2.1/driver-core/src/main/java/com/datastax/driver/core/utils/UUIDs.java#L88) doesn't include any process information, such as PID. A simple fix would be to append the value of ManagementFactory.getRuntimeMXBean().getName() to the hash too.


Resolution:
The driver now tries various methods to include the PID in the hash, look at the javadocs of UUIDs for the detailed description.

Environment

None

Pull Requests

None

Attachments

1

Activity

Alex Dutra February 16, 2016 at 6:14 PM

thank you for your initial patch. There has been indeed some discussion about how to properly obtain the PID.

First of all, as pointed out in your initial pull request, Sigar is too heavyweight for the Java driver and its binaries do not seem to be up-to-date in Maven Central.

Secondly, thanks to JAVA-727, the driver can now use JNR when available.

So my suggestion here is to try the following methods one by one, in the order they are listed below:

  1. If the System property com.datastax.driver.PID is set then the value to use as a PID will be read from that property;

  2. Otherwise, if a native call to getpid() is possible, then the PID will be read from that call;

  3. Otherwise, an attempt will be made to read the PID from JMX's RuntimeMXBean name, which is a well-known, yet undocumented "hack";

  4. If all of the above methods fail, a random integer will be generated and used as a surrogate PID.

Peter February 15, 2016 at 1:35 PM

Good to see this issue is now in progress. Please note that there has been some discussion about the patch supplied to this ticket: https://github.com/datastax/java-driver/pull/521

Peter November 12, 2015 at 10:29 AM

Same Issue within Cassandra Server is now planned for C* v2.2 https://issues.apache.org/jira/browse/CASSANDRA-7925

Alex Popescu October 8, 2015 at 1:54 AM

can you guys double check in the other drivers? thanks

Fixed

Details

Assignee

Reporter

Fix versions

Priority

Created September 5, 2014 at 8:19 AM
Updated June 21, 2020 at 5:36 PM
Resolved March 9, 2016 at 9:29 PM