You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sling.apache.org by st...@apache.org on 2015/11/03 14:15:48 UTC

svn commit: r1712291 - in /sling/trunk/bundles/extensions/discovery/impl/src/main/java/org/apache/sling/discovery/impl: cluster/voting/ common/ common/heartbeat/

Author: stefanegli
Date: Tue Nov  3 13:15:48 2015
New Revision: 1712291

URL: http://svn.apache.org/viewvc?rev=1712291&view=rev
Log:
SLING-5243 : make tests more resilient by better handling incomplete votings (that should not occur in real-life though): View.matches/matchesLiveView now throw an Exception when they notice an incomplete structure - such as no members resource - and the callers of these methods properly react: analyzeVotings skips such a voting and the heartbeatHandler switches to TOPOLOGY_CHANGING in this case, but without starting a new vote

Modified:
    sling/trunk/bundles/extensions/discovery/impl/src/main/java/org/apache/sling/discovery/impl/cluster/voting/VotingHandler.java
    sling/trunk/bundles/extensions/discovery/impl/src/main/java/org/apache/sling/discovery/impl/cluster/voting/VotingHelper.java
    sling/trunk/bundles/extensions/discovery/impl/src/main/java/org/apache/sling/discovery/impl/cluster/voting/VotingView.java
    sling/trunk/bundles/extensions/discovery/impl/src/main/java/org/apache/sling/discovery/impl/common/View.java
    sling/trunk/bundles/extensions/discovery/impl/src/main/java/org/apache/sling/discovery/impl/common/heartbeat/HeartbeatHandler.java

Modified: sling/trunk/bundles/extensions/discovery/impl/src/main/java/org/apache/sling/discovery/impl/cluster/voting/VotingHandler.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/extensions/discovery/impl/src/main/java/org/apache/sling/discovery/impl/cluster/voting/VotingHandler.java?rev=1712291&r1=1712290&r2=1712291&view=diff
==============================================================================
--- sling/trunk/bundles/extensions/discovery/impl/src/main/java/org/apache/sling/discovery/impl/cluster/voting/VotingHandler.java (original)
+++ sling/trunk/bundles/extensions/discovery/impl/src/main/java/org/apache/sling/discovery/impl/cluster/voting/VotingHandler.java Tue Nov  3 13:15:48 2015
@@ -286,7 +286,17 @@ public class VotingHandler implements Ev
                 }
                 continue;
             }
-            String liveComparison = voting.matchesLiveView(config);
+            if (!voting.isOngoingVoting(config)) {
+                logger.debug("analyzeVotings: vote is not ongoing (ignoring): "+voting);
+                continue;
+            }
+            String liveComparison;
+            try {
+                liveComparison = voting.matchesLiveView(config);
+            } catch (Exception e) {
+                logger.error("analyzeVotings: could not compare voting with live view: "+e, e);
+                continue;
+            }
             if (liveComparison != null) {
                 if (!votedNo) {
                     logger.info("analyzeVotings: vote doesnt match my live view, voting no. "
@@ -298,10 +308,6 @@ public class VotingHandler implements Ev
                 }
                 continue;
             }
-            if (!voting.isOngoingVoting(config)) {
-                logger.debug("analyzeVotings: vote is not ongoing (ignoring): "+voting);
-                continue;
-            }
             if (yesVote != null) {
                 // as soon as I found the one I should vote yes for, 
                 // vote no for the rest

Modified: sling/trunk/bundles/extensions/discovery/impl/src/main/java/org/apache/sling/discovery/impl/cluster/voting/VotingHelper.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/extensions/discovery/impl/src/main/java/org/apache/sling/discovery/impl/cluster/voting/VotingHelper.java?rev=1712291&r1=1712290&r2=1712291&view=diff
==============================================================================
--- sling/trunk/bundles/extensions/discovery/impl/src/main/java/org/apache/sling/discovery/impl/cluster/voting/VotingHelper.java (original)
+++ sling/trunk/bundles/extensions/discovery/impl/src/main/java/org/apache/sling/discovery/impl/cluster/voting/VotingHelper.java Tue Nov  3 13:15:48 2015
@@ -72,7 +72,13 @@ public class VotingHelper {
         while (it.hasNext()) {
             Resource aChild = it.next();
             VotingView c = new VotingView(aChild);
-            String matchesLiveView = c.matchesLiveView(config);
+            String matchesLiveView;
+            try {
+                matchesLiveView = c.matchesLiveView(config);
+            } catch (Exception e) {
+                logger.error("listOpenNonWinningVotings: could not compare voting with live view: "+e, e);
+                continue;
+            }
             boolean ongoingVoting = c.isOngoingVoting(config);
             boolean hasNoVotes = c.hasNoVotes();
             boolean isWinning = c.isWinning();
@@ -90,7 +96,7 @@ public class VotingHelper {
             	if (logger.isDebugEnabled()) {
 	                logger.debug("listOpenNonWinningVotings: a non-open voting: "
 	                        + aChild
-	                        + ", matches live: " + c.matchesLiveView(config)
+	                        + ", matches live: " + matchesLiveView
 	                        + ", is ongoing: " + ongoingVoting
 	                        + ", has no votes: " + hasNoVotes
 	                        + ", is winning: " + isWinning

Modified: sling/trunk/bundles/extensions/discovery/impl/src/main/java/org/apache/sling/discovery/impl/cluster/voting/VotingView.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/extensions/discovery/impl/src/main/java/org/apache/sling/discovery/impl/cluster/voting/VotingView.java?rev=1712291&r1=1712290&r2=1712291&view=diff
==============================================================================
--- sling/trunk/bundles/extensions/discovery/impl/src/main/java/org/apache/sling/discovery/impl/cluster/voting/VotingView.java (original)
+++ sling/trunk/bundles/extensions/discovery/impl/src/main/java/org/apache/sling/discovery/impl/cluster/voting/VotingView.java Tue Nov  3 13:15:48 2015
@@ -464,12 +464,13 @@ public class VotingView extends View {
 
     /**
      * Checks if this voting matches the current live view
+     * @throws Exception when something failed during matching
      */
-    public String matchesLiveView(final Config config) {
+    public String matchesLiveView(final Config config) throws Exception {
         Resource clusterNodesRes = getResource().getResourceResolver()
                 .getResource(config.getClusterInstancesPath());
         if (clusterNodesRes == null) {
-            return "no clusterNodesRes["+getResource()+"]";
+            throw new Exception("no clusterNodesRes["+getResource()+"]");
         }
         return matchesLiveView(clusterNodesRes, config);
     }

Modified: sling/trunk/bundles/extensions/discovery/impl/src/main/java/org/apache/sling/discovery/impl/common/View.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/extensions/discovery/impl/src/main/java/org/apache/sling/discovery/impl/common/View.java?rev=1712291&r1=1712290&r2=1712291&view=diff
==============================================================================
--- sling/trunk/bundles/extensions/discovery/impl/src/main/java/org/apache/sling/discovery/impl/common/View.java (original)
+++ sling/trunk/bundles/extensions/discovery/impl/src/main/java/org/apache/sling/discovery/impl/common/View.java Tue Nov  3 13:15:48 2015
@@ -103,8 +103,11 @@ public class View {
      * Checks whether this view matches the 'live view' as represented in the clusterInstances resource
      * @param clusterInstancesRes the clusterInstances resource against which to check
      * @return null if view matches, not-null-details about what differs if they don't match
+     * @throws Exception thrown the view cannot be properly matched
+     * - eg when the ./members resource doesn't exist at all or
+     * a RuntimeException occurs
      */
-    public String matchesLiveView(final Resource clusterInstancesRes, final Config config) {
+    public String matchesLiveView(final Resource clusterInstancesRes, final Config config) throws Exception {
         return matches(ViewHelper.determineLiveInstances(clusterInstancesRes,
                 config));
     }
@@ -113,12 +116,15 @@ public class View {
      * Compare this view with the given set of slingIds
      * @param view a set of slingIds against which to compare this view
      * @return true if this view matches the given set of slingIds
+     * @throws Exception thrown the view cannot be properly matched
+     * - eg when the ./members resource doesn't exist at all or
+     * a RuntimeException occurs
      */
-    public String matches(final Set<String> view) {
+    public String matches(final Set<String> view) throws Exception {
         final Set<String> viewCopy = new HashSet<String>(view);
         final Resource members = getResource().getChild("members");
         if (members == null) {
-            return "no members resource found";
+            throw new Exception("no members resource found");
         }
         try{
 	        final Iterator<Resource> it = members.getChildren().iterator();
@@ -157,7 +163,7 @@ public class View {
         	//              by another party simultaneously
         	//              so treat this situation nicely
         	logger.info("matches: cannot compare due to "+re);
-        	return "RuntimeException: "+re;
+        	throw new Exception("RuntimeException: "+re, re);
         }
     }
 

Modified: sling/trunk/bundles/extensions/discovery/impl/src/main/java/org/apache/sling/discovery/impl/common/heartbeat/HeartbeatHandler.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/extensions/discovery/impl/src/main/java/org/apache/sling/discovery/impl/common/heartbeat/HeartbeatHandler.java?rev=1712291&r1=1712290&r2=1712291&view=diff
==============================================================================
--- sling/trunk/bundles/extensions/discovery/impl/src/main/java/org/apache/sling/discovery/impl/common/heartbeat/HeartbeatHandler.java (original)
+++ sling/trunk/bundles/extensions/discovery/impl/src/main/java/org/apache/sling/discovery/impl/common/heartbeat/HeartbeatHandler.java Tue Nov  3 13:15:48 2015
@@ -597,7 +597,15 @@ public class HeartbeatHandler extends Ba
             if (establishedView == null) {
                 establishedViewMatches = false;
             } else {
-                String mismatchDetails = establishedView.matches(liveInstances);
+                String mismatchDetails;
+                try{
+                    mismatchDetails = establishedView.matches(liveInstances);
+                } catch(Exception e) {
+                    logger.error("doCheckViewWith: could not compare established view with live ones: "+e, e);
+                    invalidateCurrentEstablishedView();
+                    discoveryServiceImpl.handleTopologyChanging();
+                    return;
+                }
                 if (mismatchDetails != null) {
                     logger.info("doCheckView: established view does not match. (details: " + mismatchDetails + ")");
                 } else {