SLING-4617 : in case of a local heartbeat timing out before even having a chance to be included in the view that the local instance generates - that vote is now not created an instead a warning is issued

git-svn-id: https://svn.apache.org/repos/asf/sling/trunk@1710610 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/src/main/java/org/apache/sling/discovery/impl/cluster/voting/VotingView.java b/src/main/java/org/apache/sling/discovery/impl/cluster/voting/VotingView.java
index f50a065..facc6e4 100644
--- a/src/main/java/org/apache/sling/discovery/impl/cluster/voting/VotingView.java
+++ b/src/main/java/org/apache/sling/discovery/impl/cluster/voting/VotingView.java
@@ -64,6 +64,14 @@
     public static VotingView newVoting(final ResourceResolver resourceResolver,
             final Config config,
             final String newViewId, String initiatorId, final Set<String> liveInstances) throws PersistenceException {
+        if (!liveInstances.contains(initiatorId)) {
+            // SLING-4617 : a voting, on a single instance, was created without the local instance
+            // this should in no case happen - the local instance should always be part of the live
+            // instances. if that's not the case, then something's fishy and we should not create
+            // the new voting - and instead rely on a retry later.
+            logger.warn("newVoting: liveInstances does not include initiatorId (local instance) - not creating new, invalid, voting");
+            return null;
+        }
         final Resource votingResource = ResourceHelper.getOrCreateResource(
                 resourceResolver, config.getOngoingVotingsPath() + "/"
                         + newViewId);