You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by mi...@apache.org on 2015/06/04 21:24:08 UTC

svn commit: r1683615 [7/12] - in /lucene/dev/branches/LUCENE-6481: ./ dev-tools/ dev-tools/idea/.idea/ dev-tools/maven/solr/core/src/test/ dev-tools/scripts/ lucene/ lucene/codecs/ lucene/codecs/src/java/org/apache/lucene/codecs/simpletext/ lucene/core...

Modified: lucene/dev/branches/LUCENE-6481/solr/contrib/morphlines-core/src/test-files/solr/minimr/conf/solrconfig.xml
URL: http://svn.apache.org/viewvc/lucene/dev/branches/LUCENE-6481/solr/contrib/morphlines-core/src/test-files/solr/minimr/conf/solrconfig.xml?rev=1683615&r1=1683614&r2=1683615&view=diff
==============================================================================
--- lucene/dev/branches/LUCENE-6481/solr/contrib/morphlines-core/src/test-files/solr/minimr/conf/solrconfig.xml (original)
+++ lucene/dev/branches/LUCENE-6481/solr/contrib/morphlines-core/src/test-files/solr/minimr/conf/solrconfig.xml Thu Jun  4 19:24:05 2015
@@ -236,19 +236,6 @@
     -->
       <lockType>${solr.lock.type:hdfs}</lockType>
 
-    <!-- Unlock On Startup
-
-         If true, unlock any held write or commit locks on startup.
-         This defeats the locking mechanism that allows multiple
-         processes to safely access a lucene index, and should be used
-         with care. Default is "false".
-
-         This is not needed if lock type is 'single'
-     -->
-    <!--
-    <unlockOnStartup>false</unlockOnStartup>
-      -->
-
     <!-- If true, IndexReaders will be reopened (often more efficient)
          instead of closed and then opened. Default: true
       -->

Modified: lucene/dev/branches/LUCENE-6481/solr/contrib/morphlines-core/src/test-files/solr/mrunit/conf/solrconfig.xml
URL: http://svn.apache.org/viewvc/lucene/dev/branches/LUCENE-6481/solr/contrib/morphlines-core/src/test-files/solr/mrunit/conf/solrconfig.xml?rev=1683615&r1=1683614&r2=1683615&view=diff
==============================================================================
--- lucene/dev/branches/LUCENE-6481/solr/contrib/morphlines-core/src/test-files/solr/mrunit/conf/solrconfig.xml (original)
+++ lucene/dev/branches/LUCENE-6481/solr/contrib/morphlines-core/src/test-files/solr/mrunit/conf/solrconfig.xml Thu Jun  4 19:24:05 2015
@@ -238,19 +238,6 @@
     -->
       <lockType>${solr.lock.type:hdfs}</lockType>
 
-    <!-- Unlock On Startup
-
-         If true, unlock any held write or commit locks on startup.
-         This defeats the locking mechanism that allows multiple
-         processes to safely access a lucene index, and should be used
-         with care. Default is "false".
-
-         This is not needed if lock type is 'single'
-     -->
-    <!--
-    <unlockOnStartup>false</unlockOnStartup>
-      -->
-    
     <!-- If true, IndexReaders will be reopened (often more efficient)
          instead of closed and then opened. Default: true
       -->

Modified: lucene/dev/branches/LUCENE-6481/solr/contrib/morphlines-core/src/test-files/solr/solrcelltest/collection1/conf/solrconfig.xml
URL: http://svn.apache.org/viewvc/lucene/dev/branches/LUCENE-6481/solr/contrib/morphlines-core/src/test-files/solr/solrcelltest/collection1/conf/solrconfig.xml?rev=1683615&r1=1683614&r2=1683615&view=diff
==============================================================================
--- lucene/dev/branches/LUCENE-6481/solr/contrib/morphlines-core/src/test-files/solr/solrcelltest/collection1/conf/solrconfig.xml (original)
+++ lucene/dev/branches/LUCENE-6481/solr/contrib/morphlines-core/src/test-files/solr/solrcelltest/collection1/conf/solrconfig.xml Thu Jun  4 19:24:05 2015
@@ -220,19 +220,6 @@
     -->
     <!-- <lockType>native</lockType> -->
 
-    <!-- Unlock On Startup
-
-         If true, unlock any held write or commit locks on startup.
-         This defeats the locking mechanism that allows multiple
-         processes to safely access a lucene index, and should be used
-         with care. Default is "false".
-
-         This is not needed if lock type is 'none' or 'single'
-     -->
-    <!--
-    <unlockOnStartup>false</unlockOnStartup>
-      -->
-
     <!-- If true, IndexReaders will be reopened (often more efficient)
          instead of closed and then opened. Default: true
       -->

Modified: lucene/dev/branches/LUCENE-6481/solr/contrib/morphlines-core/src/test-files/solr/solrcloud/conf/solrconfig.xml
URL: http://svn.apache.org/viewvc/lucene/dev/branches/LUCENE-6481/solr/contrib/morphlines-core/src/test-files/solr/solrcloud/conf/solrconfig.xml?rev=1683615&r1=1683614&r2=1683615&view=diff
==============================================================================
--- lucene/dev/branches/LUCENE-6481/solr/contrib/morphlines-core/src/test-files/solr/solrcloud/conf/solrconfig.xml (original)
+++ lucene/dev/branches/LUCENE-6481/solr/contrib/morphlines-core/src/test-files/solr/solrcloud/conf/solrconfig.xml Thu Jun  4 19:24:05 2015
@@ -239,19 +239,6 @@
     -->
       <lockType>${solr.lock.type:hdfs}</lockType>
 
-    <!-- Unlock On Startup
-
-         If true, unlock any held write or commit locks on startup.
-         This defeats the locking mechanism that allows multiple
-         processes to safely access a lucene index, and should be used
-         with care. Default is "false".
-
-         This is not needed if lock type is 'single'
-     -->
-    <!--
-    <unlockOnStartup>false</unlockOnStartup>
-      -->
-    
     <!-- If true, IndexReaders will be reopened (often more efficient)
          instead of closed and then opened. Default: true
       -->

Modified: lucene/dev/branches/LUCENE-6481/solr/contrib/velocity/src/java/org/apache/solr/response/VelocityResponseWriter.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/LUCENE-6481/solr/contrib/velocity/src/java/org/apache/solr/response/VelocityResponseWriter.java?rev=1683615&r1=1683614&r2=1683615&view=diff
==============================================================================
--- lucene/dev/branches/LUCENE-6481/solr/contrib/velocity/src/java/org/apache/solr/response/VelocityResponseWriter.java (original)
+++ lucene/dev/branches/LUCENE-6481/solr/contrib/velocity/src/java/org/apache/solr/response/VelocityResponseWriter.java Thu Jun  4 19:24:05 2015
@@ -326,19 +326,18 @@ public class VelocityResponseWriter impl
   // see: http://svn.apache.org/repos/asf/velocity/tools/branches/2.0.x/src/main/java/org/apache/velocity/tools/generic/ResourceTool.java
   private class SolrVelocityResourceTool extends ResourceTool {
 
-    private final Locale locale;
     private ClassLoader solrClassLoader;
 
     public SolrVelocityResourceTool(ClassLoader cl, String localeString) {
       this.solrClassLoader = cl;
       Locale l = toLocale(localeString);
-      this.locale = (l == null ? Locale.ROOT : l);
+      this.setLocale(l == null ? Locale.ROOT : l);
     }
 
     @Override
     protected ResourceBundle getBundle(String baseName, Object loc) {
       // resource bundles for this tool must be in velocity "package"
-      return ResourceBundle.getBundle("velocity." + baseName, locale, solrClassLoader);
+      return ResourceBundle.getBundle("velocity." + baseName, getLocale(), solrClassLoader);
     }
 
     // Why did Velocity Tools make this private?  Copied from ResourceTools.java

Modified: lucene/dev/branches/LUCENE-6481/solr/core/src/java/org/apache/solr/client/solrj/embedded/JettyConfig.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/LUCENE-6481/solr/core/src/java/org/apache/solr/client/solrj/embedded/JettyConfig.java?rev=1683615&r1=1683614&r2=1683615&view=diff
==============================================================================
--- lucene/dev/branches/LUCENE-6481/solr/core/src/java/org/apache/solr/client/solrj/embedded/JettyConfig.java (original)
+++ lucene/dev/branches/LUCENE-6481/solr/core/src/java/org/apache/solr/client/solrj/embedded/JettyConfig.java Thu Jun  4 19:24:05 2015
@@ -30,6 +30,8 @@ public class JettyConfig {
   public final String context;
 
   public final boolean stopAtShutdown;
+  
+  public final Long waitForLoadingCoresToFinishMs;
 
   public final Map<ServletHolder, String> extraServlets;
 
@@ -37,11 +39,12 @@ public class JettyConfig {
 
   public final SSLConfig sslConfig;
 
-  private JettyConfig(int port, String context, boolean stopAtShutdown, Map<ServletHolder, String> extraServlets,
+  private JettyConfig(int port, String context, boolean stopAtShutdown, Long waitForLoadingCoresToFinishMs, Map<ServletHolder, String> extraServlets,
                       Map<Class<? extends Filter>, String> extraFilters, SSLConfig sslConfig) {
     this.port = port;
     this.context = context;
     this.stopAtShutdown = stopAtShutdown;
+    this.waitForLoadingCoresToFinishMs = waitForLoadingCoresToFinishMs;
     this.extraServlets = extraServlets;
     this.extraFilters = extraFilters;
     this.sslConfig = sslConfig;
@@ -67,6 +70,7 @@ public class JettyConfig {
     int port = 0;
     String context = "/solr";
     boolean stopAtShutdown = true;
+    Long waitForLoadingCoresToFinishMs = 300000L;
     Map<ServletHolder, String> extraServlets = new TreeMap<>();
     Map<Class<? extends Filter>, String> extraFilters = new TreeMap<>();
     SSLConfig sslConfig = null;
@@ -85,6 +89,11 @@ public class JettyConfig {
       this.stopAtShutdown = stopAtShutdown;
       return this;
     }
+    
+    public Builder waitForLoadingCoresToFinish(Long waitForLoadingCoresToFinishMs) {
+      this.waitForLoadingCoresToFinishMs = waitForLoadingCoresToFinishMs;
+      return this;
+    }
 
     public Builder withServlet(ServletHolder servlet, String servletName) {
       extraServlets.put(servlet, servletName);
@@ -114,7 +123,7 @@ public class JettyConfig {
     }
 
     public JettyConfig build() {
-      return new JettyConfig(port, context, stopAtShutdown, extraServlets, extraFilters, sslConfig);
+      return new JettyConfig(port, context, stopAtShutdown, waitForLoadingCoresToFinishMs, extraServlets, extraFilters, sslConfig);
     }
 
   }

Modified: lucene/dev/branches/LUCENE-6481/solr/core/src/java/org/apache/solr/client/solrj/embedded/JettySolrRunner.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/LUCENE-6481/solr/core/src/java/org/apache/solr/client/solrj/embedded/JettySolrRunner.java?rev=1683615&r1=1683614&r2=1683615&view=diff
==============================================================================
--- lucene/dev/branches/LUCENE-6481/solr/core/src/java/org/apache/solr/client/solrj/embedded/JettySolrRunner.java (original)
+++ lucene/dev/branches/LUCENE-6481/solr/core/src/java/org/apache/solr/client/solrj/embedded/JettySolrRunner.java Thu Jun  4 19:24:05 2015
@@ -17,6 +17,7 @@
 
 package org.apache.solr.client.solrj.embedded;
 
+import org.apache.solr.core.CoreContainer;
 import org.apache.solr.servlet.SolrDispatchFilter;
 import org.eclipse.jetty.server.Connector;
 import org.eclipse.jetty.server.HttpConfiguration;
@@ -393,6 +394,8 @@ public class JettySolrRunner {
           }
         }
       }
+      
+      if (config.waitForLoadingCoresToFinishMs != null && config.waitForLoadingCoresToFinishMs > 0L) waitForLoadingCoresToFinish(config.waitForLoadingCoresToFinishMs);
     } finally {
       if (prevContext != null)  {
         MDC.setContextMap(prevContext);
@@ -562,4 +565,14 @@ public class JettySolrRunner {
   public String getSolrHome() {
     return solrHome;
   }
+
+  private void waitForLoadingCoresToFinish(long timeoutMs) {
+    if (dispatchFilter != null) {
+      SolrDispatchFilter solrFilter = (SolrDispatchFilter) dispatchFilter.getFilter();
+      CoreContainer cores = solrFilter.getCores();
+      if (cores != null) {
+        cores.waitForLoadingCoresToFinish(timeoutMs);
+      }
+    }
+  }
 }

Modified: lucene/dev/branches/LUCENE-6481/solr/core/src/java/org/apache/solr/cloud/ElectionContext.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/LUCENE-6481/solr/core/src/java/org/apache/solr/cloud/ElectionContext.java?rev=1683615&r1=1683614&r2=1683615&view=diff
==============================================================================
--- lucene/dev/branches/LUCENE-6481/solr/core/src/java/org/apache/solr/cloud/ElectionContext.java (original)
+++ lucene/dev/branches/LUCENE-6481/solr/core/src/java/org/apache/solr/cloud/ElectionContext.java Thu Jun  4 19:24:05 2015
@@ -1,5 +1,11 @@
 package org.apache.solr.cloud;
 
+import java.io.Closeable;
+import java.io.IOException;
+import java.util.List;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.TimeUnit;
+
 import org.apache.lucene.search.MatchAllDocsQuery;
 import org.apache.solr.cloud.overseer.OverseerAction;
 import org.apache.solr.common.SolrException;
@@ -15,7 +21,7 @@ import org.apache.solr.common.util.Retry
 import org.apache.solr.common.util.RetryUtil.RetryCmd;
 import org.apache.solr.core.CoreContainer;
 import org.apache.solr.core.SolrCore;
-import org.apache.solr.logging.MDCUtils;
+import org.apache.solr.logging.MDCLoggingContext;
 import org.apache.solr.search.SolrIndexSearcher;
 import org.apache.solr.update.UpdateLog;
 import org.apache.solr.util.RefCounted;
@@ -25,14 +31,6 @@ import org.apache.zookeeper.KeeperExcept
 import org.apache.zookeeper.KeeperException.NodeExistsException;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
-import org.slf4j.MDC;
-
-import java.io.Closeable;
-import java.io.IOException;
-import java.util.List;
-import java.util.Map;
-import java.util.concurrent.ExecutorService;
-import java.util.concurrent.TimeUnit;
 
 /*
  * Licensed to the Apache Software Foundation (ASF) under one or more
@@ -117,8 +115,6 @@ class ShardLeaderElectionContextBase ext
     this.shardId = shardId;
     this.collection = collection;
 
-    Map previousMDCContext = MDC.getCopyOfContextMap();
-    MDCUtils.setMDC(collection, shardId, null, null);
     try {
       new ZkCmdExecutor(zkStateReader.getZkClient().getZkClientTimeout())
           .ensureExists(ZkStateReader.COLLECTIONS_ZKNODE + "/" + collection,
@@ -128,8 +124,6 @@ class ShardLeaderElectionContextBase ext
     } catch (InterruptedException e) {
       Thread.currentThread().interrupt();
       throw new SolrException(ErrorCode.SERVER_ERROR, e);
-    } finally {
-      MDCUtils.cleanupMDC(previousMDCContext);
     }
   }
   
@@ -203,158 +197,152 @@ final class ShardLeaderElectionContext e
    */
   @Override
   void runLeaderProcess(boolean weAreReplacement, int pauseBeforeStart) throws KeeperException,
-      InterruptedException, IOException {
-    log.info("Running the leader process for shard " + shardId);
-    
+ InterruptedException, IOException {
     String coreName = leaderProps.getStr(ZkStateReader.CORE_NAME_PROP);
     ActionThrottle lt;
     try (SolrCore core = cc.getCore(coreName)) {
-
       if (core == null) {
         cancelElection();
-        throw new SolrException(ErrorCode.SERVER_ERROR,
-            "SolrCore not found:" + coreName + " in "
-                + cc.getCoreNames());
+        throw new SolrException(ErrorCode.SERVER_ERROR, "SolrCore not found:" + coreName + " in " + cc.getCoreNames());
       }
-      
+      MDCLoggingContext.setCore(core);
       lt = core.getUpdateHandler().getSolrCoreState().getLeaderThrottle();
     }
-    
-    lt.minimumWaitBetweenActions();
-    lt.markAttemptingAction();
-    
-    // clear the leader in clusterstate
-    ZkNodeProps m = new ZkNodeProps(Overseer.QUEUE_OPERATION, OverseerAction.LEADER.toLower(),
-        ZkStateReader.SHARD_ID_PROP, shardId, ZkStateReader.COLLECTION_PROP,
-        collection);
-    Overseer.getInQueue(zkClient).offer(ZkStateReader.toJSON(m));
-    
-    int leaderVoteWait = cc.getZkController().getLeaderVoteWait();
-    if (!weAreReplacement) {
-      waitForReplicasToComeUp(leaderVoteWait);
-    }
 
-    try (SolrCore core = cc.getCore(coreName)) {
-
-      if (core == null) {
-        cancelElection();
-        throw new SolrException(ErrorCode.SERVER_ERROR,
-            "SolrCore not found:" + coreName + " in "
-                + cc.getCoreNames());
-      }
+    try {
+      lt.minimumWaitBetweenActions();
+      lt.markAttemptingAction();
       
-      // should I be leader?
-      if (weAreReplacement && !shouldIBeLeader(leaderProps, core, weAreReplacement)) {
-        rejoinLeaderElection(core);
-        return;
+      log.info("Running the leader process for shard " + shardId);
+      // clear the leader in clusterstate
+      ZkNodeProps m = new ZkNodeProps(Overseer.QUEUE_OPERATION, OverseerAction.LEADER.toLower(),
+          ZkStateReader.SHARD_ID_PROP, shardId, ZkStateReader.COLLECTION_PROP, collection);
+      Overseer.getInQueue(zkClient).offer(ZkStateReader.toJSON(m));
+      
+      int leaderVoteWait = cc.getZkController().getLeaderVoteWait();
+      if (!weAreReplacement) {
+        waitForReplicasToComeUp(leaderVoteWait);
       }
       
-      log.info("I may be the new leader - try and sync");
- 
-      
-      // we are going to attempt to be the leader
-      // first cancel any current recovery
-      core.getUpdateHandler().getSolrCoreState().cancelRecovery();
-      
-      if (weAreReplacement) {
-        // wait a moment for any floating updates to finish
-        try {
-          Thread.sleep(2500);
-        } catch (InterruptedException e) {
-          Thread.currentThread().interrupt();
-          throw new SolrException(ErrorCode.SERVICE_UNAVAILABLE, e);
+      try (SolrCore core = cc.getCore(coreName)) {
+        
+        if (core == null) {
+          cancelElection();
+          throw new SolrException(ErrorCode.SERVER_ERROR,
+              "SolrCore not found:" + coreName + " in " + cc.getCoreNames());
         }
-      }
-      
-      boolean success = false;
-      try {
-        success = syncStrategy.sync(zkController, core, leaderProps, weAreReplacement);
-      } catch (Exception e) {
-        SolrException.log(log, "Exception while trying to sync", e);
-        success = false;
-      }
-      
-      UpdateLog ulog = core.getUpdateHandler().getUpdateLog();
-
-      if (!success) {
-        boolean hasRecentUpdates = false;
-        if (ulog != null) {
-          // TODO: we could optimize this if necessary
-          UpdateLog.RecentUpdates recentUpdates = ulog.getRecentUpdates();
+        
+        // should I be leader?
+        if (weAreReplacement && !shouldIBeLeader(leaderProps, core, weAreReplacement)) {
+          rejoinLeaderElection(core);
+          return;
+        }
+        
+        log.info("I may be the new leader - try and sync");
+        
+        // we are going to attempt to be the leader
+        // first cancel any current recovery
+        core.getUpdateHandler().getSolrCoreState().cancelRecovery();
+        
+        if (weAreReplacement) {
+          // wait a moment for any floating updates to finish
           try {
-            hasRecentUpdates = !recentUpdates.getVersions(1).isEmpty();
-          } finally {
-            recentUpdates.close();
+            Thread.sleep(2500);
+          } catch (InterruptedException e) {
+            Thread.currentThread().interrupt();
+            throw new SolrException(ErrorCode.SERVICE_UNAVAILABLE, e);
           }
         }
-
-        if (!hasRecentUpdates) {
-          // we failed sync, but we have no versions - we can't sync in that case
-          // - we were active
-          // before, so become leader anyway
-          log.info("We failed sync, but we have no versions - we can't sync in that case - we were active before, so become leader anyway");
-          success = true;
-        }
-      }
-      
-      // solrcloud_debug
-      if (log.isDebugEnabled()) {
+        
+        boolean success = false;
         try {
-          RefCounted<SolrIndexSearcher> searchHolder = core
-              .getNewestSearcher(false);
-          SolrIndexSearcher searcher = searchHolder.get();
+          success = syncStrategy.sync(zkController, core, leaderProps, weAreReplacement);
+        } catch (Exception e) {
+          SolrException.log(log, "Exception while trying to sync", e);
+          success = false;
+        }
+        
+        UpdateLog ulog = core.getUpdateHandler().getUpdateLog();
+        
+        if (!success) {
+          boolean hasRecentUpdates = false;
+          if (ulog != null) {
+            // TODO: we could optimize this if necessary
+            UpdateLog.RecentUpdates recentUpdates = ulog.getRecentUpdates();
+            try {
+              hasRecentUpdates = !recentUpdates.getVersions(1).isEmpty();
+            } finally {
+              recentUpdates.close();
+            }
+          }
+          
+          if (!hasRecentUpdates) {
+            // we failed sync, but we have no versions - we can't sync in that case
+            // - we were active
+            // before, so become leader anyway
+            log.info(
+                "We failed sync, but we have no versions - we can't sync in that case - we were active before, so become leader anyway");
+            success = true;
+          }
+        }
+        
+        // solrcloud_debug
+        if (log.isDebugEnabled()) {
           try {
-            log.debug(core.getCoreDescriptor().getCoreContainer()
-                .getZkController().getNodeName()
-                + " synched "
-                + searcher.search(new MatchAllDocsQuery(), 1).totalHits);
-          } finally {
-            searchHolder.decref();
+            RefCounted<SolrIndexSearcher> searchHolder = core.getNewestSearcher(false);
+            SolrIndexSearcher searcher = searchHolder.get();
+            try {
+              log.debug(core.getCoreDescriptor().getCoreContainer().getZkController().getNodeName() + " synched "
+                  + searcher.search(new MatchAllDocsQuery(), 1).totalHits);
+            } finally {
+              searchHolder.decref();
+            }
+          } catch (Exception e) {
+            log.error("Error in solrcloud_debug block", e);
           }
-        } catch (Exception e) {
-          log.error("Error in solrcloud_debug block", e);
         }
-      }
-      if (!success) {
-        rejoinLeaderElection(core);
-        return;
-      }
-
-      log.info("I am the new leader: "
-          + ZkCoreNodeProps.getCoreUrl(leaderProps) + " " + shardId);
-      core.getCoreDescriptor().getCloudDescriptor().setLeader(true);
-    }
-
-    boolean isLeader = true;
-    try {
-      super.runLeaderProcess(weAreReplacement, 0);
-    } catch (Exception e) {
-      isLeader = false;
-      SolrException.log(log, "There was a problem trying to register as the leader", e);
-  
-      try (SolrCore core = cc.getCore(coreName)) {
-
-        if (core == null) {
-          log.debug("SolrCore not found:" + coreName + " in " + cc.getCoreNames());
+        if (!success) {
+          rejoinLeaderElection(core);
           return;
         }
         
-        core.getCoreDescriptor().getCloudDescriptor().setLeader(false);
-        
-        // we could not publish ourselves as leader - try and rejoin election
-        rejoinLeaderElection(core);
+        log.info("I am the new leader: " + ZkCoreNodeProps.getCoreUrl(leaderProps) + " " + shardId);
+        core.getCoreDescriptor().getCloudDescriptor().setLeader(true);
       }
-    }
-
-    if (isLeader) {
-      // check for any replicas in my shard that were set to down by the previous leader
+      
+      boolean isLeader = true;
       try {
-        startLeaderInitiatedRecoveryOnReplicas(coreName);
-      } catch (Exception exc) {
-        // don't want leader election to fail because of
-        // an error trying to tell others to recover
+        super.runLeaderProcess(weAreReplacement, 0);
+      } catch (Exception e) {
+        isLeader = false;
+        SolrException.log(log, "There was a problem trying to register as the leader", e);
+        
+        try (SolrCore core = cc.getCore(coreName)) {
+          
+          if (core == null) {
+            log.debug("SolrCore not found:" + coreName + " in " + cc.getCoreNames());
+            return;
+          }
+          
+          core.getCoreDescriptor().getCloudDescriptor().setLeader(false);
+          
+          // we could not publish ourselves as leader - try and rejoin election
+          rejoinLeaderElection(core);
+        }
       }
-    }    
+      
+      if (isLeader) {
+        // check for any replicas in my shard that were set to down by the previous leader
+        try {
+          startLeaderInitiatedRecoveryOnReplicas(coreName);
+        } catch (Exception exc) {
+          // don't want leader election to fail because of
+          // an error trying to tell others to recover
+        }
+      }
+    } finally {
+      MDCLoggingContext.clear();
+    }
   }
   
   private void startLeaderInitiatedRecoveryOnReplicas(String coreName) throws Exception {
@@ -493,8 +481,7 @@ final class ShardLeaderElectionContext e
   }
 
   private boolean shouldIBeLeader(ZkNodeProps leaderProps, SolrCore core, boolean weAreReplacement) {
-    log.info("Checking if I (core={},coreNodeName={}) should try and be the leader.", core.getName(),
-        core.getCoreDescriptor().getCloudDescriptor().getCoreNodeName());
+    log.info("Checking if I should try and be the leader.");
     
     if (isClosed) {
       log.info("Bailing on leader process because we have been closed");
@@ -534,7 +521,7 @@ final class ShardLeaderElectionContext e
 }
 
 final class OverseerElectionContext extends ElectionContext {
-  
+  private static Logger log = LoggerFactory.getLogger(OverseerElectionContext.class);
   private final SolrZkClient zkClient;
   private Overseer overseer;
   public static final String PATH = "/overseer_elect";