You are viewing a plain text version of this content. The canonical link for it is here.
Posted to oak-commits@jackrabbit.apache.org by re...@apache.org on 2015/09/22 16:15:55 UTC
svn commit: r1704636 -
/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/ClusterNodeInfo.java
Author: reschke
Date: Tue Sep 22 14:15:52 2015
New Revision: 1704636
URL: http://svn.apache.org/viewvc?rev=1704636&view=rev
Log:
OAK-3418: when computing the machineId, prioritize (likely) MAC addresses over other hardware addresses
Modified:
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/ClusterNodeInfo.java
Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/ClusterNodeInfo.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/ClusterNodeInfo.java?rev=1704636&r1=1704635&r2=1704636&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/ClusterNodeInfo.java (original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/ClusterNodeInfo.java Tue Sep 22 14:15:52 2015
@@ -741,34 +741,50 @@ public class ClusterNodeInfo {
}
/**
- * Calculate the unique machine id. This is the lowest MAC address if
- * available. As an alternative, a randomly generated UUID is used.
+ * Calculate the unique machine id. This usually is the lowest MAC address
+ * if available. As an alternative, a randomly generated UUID is used.
*
* @return the unique id
*/
private static String getMachineId() {
Exception exception = null;
try {
- ArrayList<String> list = new ArrayList<String>();
+ ArrayList<String> macAddresses = new ArrayList<String>();
+ ArrayList<String> otherAddresses = new ArrayList<String>();
Enumeration<NetworkInterface> e = NetworkInterface
.getNetworkInterfaces();
while (e.hasMoreElements()) {
NetworkInterface ni = e.nextElement();
try {
- byte[] mac = ni.getHardwareAddress();
- if (mac != null) {
- String x = StringUtils.convertBytesToHex(mac);
- list.add(x);
+ byte[] hwa = ni.getHardwareAddress();
+ // empty addresses have been seen on loopback devices
+ if (hwa != null && hwa.length != 0) {
+ String str = StringUtils.convertBytesToHex(hwa);
+ if (hwa.length == 6) {
+ // likely a MAC address
+ macAddresses.add(str);
+ } else {
+ otherAddresses.add(str);
+ }
}
} catch (Exception e2) {
exception = e2;
}
}
- if (list.size() > 0) {
- // use the lowest value, such that if the order changes,
+
+ if (LOG.isDebugEnabled()) {
+ LOG.debug("getMachineId(): discovered addresses: {} {}", macAddresses, otherAddresses);
+ }
+
+ if (macAddresses.size() > 0) {
+ // use the lowest MAC value, such that if the order changes,
// the same one is used
- Collections.sort(list);
- return "mac:" + list.get(0);
+ Collections.sort(macAddresses);
+ return "mac:" + macAddresses.get(0);
+ } else if (otherAddresses.size() > 0) {
+ // try the lowest "other" address
+ Collections.sort(otherAddresses);
+ return "hwa:" + otherAddresses.get(0);
}
} catch (Exception e) {
exception = e;