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 2016/01/18 14:43:23 UTC

svn commit: r1725270 - /jackrabbit/oak/branches/1.2/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/ClusterNodeInfo.java

Author: reschke
Date: Mon Jan 18 13:43:22 2016
New Revision: 1725270

URL: http://svn.apache.org/viewvc?rev=1725270&view=rev
Log:
OAK-3885: enhance stability of clusterNodeInfo's machineId by de-prioritizing interfaces that appear to be virtual (ported to 1.2)

Modified:
    jackrabbit/oak/branches/1.2/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/ClusterNodeInfo.java

Modified: jackrabbit/oak/branches/1.2/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/ClusterNodeInfo.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/branches/1.2/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/ClusterNodeInfo.java?rev=1725270&r1=1725269&r2=1725270&view=diff
==============================================================================
--- jackrabbit/oak/branches/1.2/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/ClusterNodeInfo.java (original)
+++ jackrabbit/oak/branches/1.2/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/ClusterNodeInfo.java Mon Jan 18 13:43:22 2016
@@ -25,6 +25,7 @@ import java.util.ArrayList;
 import java.util.Collections;
 import java.util.Enumeration;
 import java.util.List;
+import java.util.Locale;
 import java.util.UUID;
 
 import org.apache.jackrabbit.oak.commons.StringUtils;
@@ -581,6 +582,7 @@ public class ClusterNodeInfo {
         Exception exception = null;
         try {
             ArrayList<String> macAddresses = new ArrayList<String>();
+            ArrayList<String> likelyVirtualMacAddresses = new ArrayList<String>();
             ArrayList<String> otherAddresses = new ArrayList<String>();
             String hwaFromSysProp = getHWAFromSystemProperty();
             if ("".equals(hwaFromSysProp)) {
@@ -595,7 +597,14 @@ public class ClusterNodeInfo {
                             String str = StringUtils.convertBytesToHex(hwa);
                             if (hwa.length == 6) {
                                 // likely a MAC address
-                                macAddresses.add(str);
+                                String displayName = ni.getDisplayName().toLowerCase(Locale.ENGLISH);
+                                // de-prioritize addresses that are likely to be virtual (see OAK-3885)
+                                boolean looksVirtual = displayName.indexOf("virtual") >= 0 || displayName.indexOf("vpn") >= 0;
+                                if (!looksVirtual) {
+                                    macAddresses.add(str);
+                                } else {
+                                    likelyVirtualMacAddresses.add(str);
+                                }
                             } else {
                                 otherAddresses.add(str);
                             }
@@ -617,7 +626,8 @@ public class ClusterNodeInfo {
             }
 
             if (LOG.isDebugEnabled()) {
-                LOG.debug("getMachineId(): discovered addresses: {} {}", macAddresses, otherAddresses);
+                LOG.debug("getMachineId(): discovered addresses: {} {} {}", macAddresses, likelyVirtualMacAddresses,
+                        otherAddresses);
             }
 
             if (macAddresses.size() > 0) {
@@ -625,6 +635,9 @@ public class ClusterNodeInfo {
                 // the same one is used
                 Collections.sort(macAddresses);
                 return "mac:" + macAddresses.get(0);
+            } else if (likelyVirtualMacAddresses.size() > 0) {
+                Collections.sort(likelyVirtualMacAddresses);
+                return "mac:" + likelyVirtualMacAddresses.get(0);
             } else if (otherAddresses.size() > 0) {
                 // try the lowest "other" address
                 Collections.sort(otherAddresses);