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/10/29 16:51:33 UTC

svn commit: r1711296 - /jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/ClusterNodeInfo.java

Author: reschke
Date: Thu Oct 29 15:51:33 2015
New Revision: 1711296

URL: http://svn.apache.org/viewvc?rev=1711296&view=rev
Log:
OAK-3499: Test failures when there is no network interface

- add a system property to simulate lack of hardware network interfaces
- tune discovery to kill only cluster node entries with random machine ids when they have no lease at all

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=1711296&r1=1711295&r2=1711296&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 Thu Oct 29 15:51:33 2015
@@ -457,11 +457,15 @@ public class ClusterNodeInfo {
             String mId = "" + doc.get(MACHINE_ID_KEY);
             String iId = "" + doc.get(INSTANCE_ID_KEY);
 
-            if (mId.startsWith(RANDOM_PREFIX)) {
-                // remove expired entries with random keys
+            // remove entries with "random:" keys if not in use (no lease at all) 
+            if (mId.startsWith(RANDOM_PREFIX) && leaseEnd == null) {
                 store.remove(Collection.CLUSTER_NODES, key);
                 LOG.debug("Cleaned up cluster node info for clusterNodeId {} [machineId: {}, leaseEnd: {}]", id, mId,
                         leaseEnd == null ? "n/a" : Utils.timestampToString(leaseEnd));
+                if (alreadyExistingConfigured == doc) {
+                    // we removed it, so we can't re-use it after all
+                    alreadyExistingConfigured = null;
+                }
                 continue;
             }
 
@@ -786,6 +790,20 @@ public class ClusterNodeInfo {
         }
     }
 
+    /*
+     * Allow external override of hardware address. The special value "(none)"
+     * indicates that a situation where no hardware address is available is to
+     * be simulated.
+     */
+    private static String getHWAFromSystemProperty() {
+        String pname = ClusterNodeInfo.class.getName() + ".HWADDRESS";
+        String hwa = System.getProperty(pname, "");
+        if (!"".equals(hwa)) {
+            LOG.debug("obtaining hardware address from system variable " + pname + ": " + hwa);
+        }
+        return hwa;
+    }
+
     /**
      * Calculate the unique machine id. This usually is the lowest MAC address
      * if available. As an alternative, a randomly generated UUID is used.
@@ -797,24 +815,37 @@ public class ClusterNodeInfo {
         try {
             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[] 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);
+            String hwaFromSysProp = getHWAFromSystemProperty();
+            if ("".equals(hwaFromSysProp)) {
+                Enumeration<NetworkInterface> e = NetworkInterface
+                        .getNetworkInterfaces();
+                while (e.hasMoreElements()) {
+                    NetworkInterface ni = e.nextElement();
+                    try {
+                        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;
+                    }
+                }
+            }
+            else {
+                if (!"(none)".equals(hwaFromSysProp)) {
+                    if (hwaFromSysProp.length() == 12) {
+                        // assume 12 hex digits are a mac address
+                        macAddresses.add(hwaFromSysProp);
+                    } else {
+                        otherAddresses.add(hwaFromSysProp);
                     }
-                } catch (Exception e2) {
-                    exception = e2;
                 }
             }