You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by yo...@apache.org on 2015/12/15 22:06:33 UTC

svn commit: r1720250 - in /lucene/dev/trunk/solr: CHANGES.txt core/src/java/org/apache/solr/cloud/RecoveryStrategy.java core/src/java/org/apache/solr/update/UpdateLog.java core/src/test/org/apache/solr/search/TestRecovery.java

Author: yonik
Date: Tue Dec 15 21:06:32 2015
New Revision: 1720250

URL: http://svn.apache.org/viewvc?rev=1720250&view=rev
Log:
SOLR-8372: continue buffering if recovery is canceled/failed

Modified:
    lucene/dev/trunk/solr/CHANGES.txt
    lucene/dev/trunk/solr/core/src/java/org/apache/solr/cloud/RecoveryStrategy.java
    lucene/dev/trunk/solr/core/src/java/org/apache/solr/update/UpdateLog.java
    lucene/dev/trunk/solr/core/src/test/org/apache/solr/search/TestRecovery.java

Modified: lucene/dev/trunk/solr/CHANGES.txt
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/solr/CHANGES.txt?rev=1720250&r1=1720249&r2=1720250&view=diff
==============================================================================
--- lucene/dev/trunk/solr/CHANGES.txt (original)
+++ lucene/dev/trunk/solr/CHANGES.txt Tue Dec 15 21:06:32 2015
@@ -247,6 +247,14 @@ Bug Fixes
 * SOLR-2469: MM ignored in edismax queries with operators.
   (Greg Pendlebury, Jan Høydahl et. al. via Erick Erickson)
 
+* SOLR-8372: Canceled recovery can rarely lead to inconsistent shards:
+  If a replica is recovering via index replication, and that recovery fails
+  (for example if the leader goes down), and then some more updates are received
+  (there could be a few left to be processed from the leader that just went down),
+  and then that replica is brought down, it will think it is up-to-date when
+  restarted. (shalin, Mark Miller, yonik)
+
+
 Other Changes
 ----------------------
 

Modified: lucene/dev/trunk/solr/core/src/java/org/apache/solr/cloud/RecoveryStrategy.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/solr/core/src/java/org/apache/solr/cloud/RecoveryStrategy.java?rev=1720250&r1=1720249&r2=1720250&view=diff
==============================================================================
--- lucene/dev/trunk/solr/core/src/java/org/apache/solr/cloud/RecoveryStrategy.java (original)
+++ lucene/dev/trunk/solr/core/src/java/org/apache/solr/cloud/RecoveryStrategy.java Tue Dec 15 21:06:32 2015
@@ -457,11 +457,19 @@ public class RecoveryStrategy extends Th
         SolrException.log(log, "Error while trying to recover. core=" + coreName, e);
       } finally {
         if (!replayed) {
+          // dropBufferedUpdate()s currently only supports returning to ACTIVE state, which risks additional updates
+          // being added w/o UpdateLog.FLAG_GAP, hence losing the info on restart that we are not up-to-date.
+          // For now, ulog will simply remain in BUFFERING state, and an additional call to bufferUpdates() will
+          // reset our starting point for playback.
+          log.info("Replay not started, or was not successful... still buffering updates.");
+
+          /** this prev code is retained in case we want to switch strategies.
           try {
             ulog.dropBufferedUpdates();
           } catch (Exception e) {
             SolrException.log(log, "", e);
           }
+          **/
         }
         if (successfulRecovery) {
           log.info("Registering as Active after recovery.");

Modified: lucene/dev/trunk/solr/core/src/java/org/apache/solr/update/UpdateLog.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/solr/core/src/java/org/apache/solr/update/UpdateLog.java?rev=1720250&r1=1720249&r2=1720250&view=diff
==============================================================================
--- lucene/dev/trunk/solr/core/src/java/org/apache/solr/update/UpdateLog.java (original)
+++ lucene/dev/trunk/solr/core/src/java/org/apache/solr/update/UpdateLog.java Tue Dec 15 21:06:32 2015
@@ -1115,13 +1115,19 @@ public class UpdateLog implements Plugin
     // it checks the state first
     // assert state == State.ACTIVE;
 
-    recoveryInfo = new RecoveryInfo();
-
     // block all updates to eliminate race conditions
-    // reading state and acting on it in the update processor
+    // reading state and acting on it in the distributed update processor
     versionInfo.blockUpdates();
     try {
-      if (state != State.ACTIVE) return;
+      if (state == State.BUFFERING) {
+        log.info("Restarting buffering. previous=" + recoveryInfo);
+      } else if (state != State.ACTIVE) {
+        // we don't currently have support for handling other states
+        log.warn("Unexpected state for bufferUpdates: " + state + ", Ignoring request.");
+        return;
+      }
+
+      recoveryInfo = new RecoveryInfo();
 
       if (log.isInfoEnabled()) {
         log.info("Starting to buffer updates. " + this);

Modified: lucene/dev/trunk/solr/core/src/test/org/apache/solr/search/TestRecovery.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/solr/core/src/test/org/apache/solr/search/TestRecovery.java?rev=1720250&r1=1720249&r2=1720250&view=diff
==============================================================================
--- lucene/dev/trunk/solr/core/src/test/org/apache/solr/search/TestRecovery.java (original)
+++ lucene/dev/trunk/solr/core/src/test/org/apache/solr/search/TestRecovery.java Tue Dec 15 21:06:32 2015
@@ -488,6 +488,110 @@ public class TestRecovery extends SolrTe
 
   }
 
+  @Test
+  public void testBufferedMultipleCalls() throws Exception {
+
+    DirectUpdateHandler2.commitOnClose = false;
+    final Semaphore logReplay = new Semaphore(0);
+    final Semaphore logReplayFinish = new Semaphore(0);
+
+    UpdateLog.testing_logReplayHook = new Runnable() {
+      @Override
+      public void run() {
+        try {
+          assertTrue(logReplay.tryAcquire(timeout, TimeUnit.SECONDS));
+        } catch (Exception e) {
+          throw new RuntimeException(e);
+        }
+      }
+    };
+
+    UpdateLog.testing_logReplayFinishHook = new Runnable() {
+      @Override
+      public void run() {
+        logReplayFinish.release();
+      }
+    };
+
+
+    SolrQueryRequest req = req();
+    UpdateHandler uhandler = req.getCore().getUpdateHandler();
+    UpdateLog ulog = uhandler.getUpdateLog();
+    Future<UpdateLog.RecoveryInfo> rinfoFuture;
+
+    try {
+      clearIndex();
+      assertU(commit());
+      assertEquals(UpdateLog.State.ACTIVE, ulog.getState());
+
+      ulog.bufferUpdates();
+      assertEquals(UpdateLog.State.BUFFERING, ulog.getState());
+
+      // simulate updates from a leader
+      updateJ(jsonAdd(sdoc("id","c1", "_version_","101")), params(DISTRIB_UPDATE_PARAM,FROM_LEADER));
+      updateJ(jsonAdd(sdoc("id","c2", "_version_","102")), params(DISTRIB_UPDATE_PARAM,FROM_LEADER));
+      updateJ(jsonAdd(sdoc("id","c3", "_version_","103")), params(DISTRIB_UPDATE_PARAM,FROM_LEADER));
+
+      // call bufferUpdates again (this currently happens when recovery fails)... we should get a new starting point
+      ulog.bufferUpdates();
+      assertEquals(UpdateLog.State.BUFFERING, ulog.getState());
+
+      updateJ(jsonAdd(sdoc("id", "c4", "_version_","104")), params(DISTRIB_UPDATE_PARAM,FROM_LEADER));
+      updateJ(jsonAdd(sdoc("id", "c5", "_version_","105")), params(DISTRIB_UPDATE_PARAM,FROM_LEADER));
+
+      logReplay.release(1000);
+      rinfoFuture = ulog.applyBufferedUpdates();
+      UpdateLog.RecoveryInfo rinfo = rinfoFuture.get();
+      assertEquals(2, rinfo.adds);
+
+      assertJQ(req("qt","/get", "getVersions","2")
+          ,"=={'versions':[105,104]}"
+      );
+
+      // this time add some docs first before buffering starts (so tlog won't be at pos 0)
+      updateJ(jsonAdd(sdoc("id","c100", "_version_","200")), params(DISTRIB_UPDATE_PARAM,FROM_LEADER));
+      updateJ(jsonAdd(sdoc("id","c101", "_version_","201")), params(DISTRIB_UPDATE_PARAM,FROM_LEADER));
+
+      ulog.bufferUpdates();
+      updateJ(jsonAdd(sdoc("id","c103", "_version_","203")), params(DISTRIB_UPDATE_PARAM,FROM_LEADER));
+      updateJ(jsonAdd(sdoc("id","c104", "_version_","204")), params(DISTRIB_UPDATE_PARAM,FROM_LEADER));
+
+      // call bufferUpdates again (this currently happens when recovery fails)... we should get a new starting point
+      ulog.bufferUpdates();
+      updateJ(jsonAdd(sdoc("id","c105", "_version_","205")), params(DISTRIB_UPDATE_PARAM,FROM_LEADER));
+      updateJ(jsonAdd(sdoc("id","c106", "_version_","206")), params(DISTRIB_UPDATE_PARAM,FROM_LEADER));
+
+      rinfoFuture = ulog.applyBufferedUpdates();
+      rinfo = rinfoFuture.get();
+      assertEquals(2, rinfo.adds);
+
+      assertJQ(req("q", "*:*", "sort","_version_ asc", "fl","id,_version_")
+          , "/response/docs==["
+              + "{'id':'c4','_version_':104}"
+              + ",{'id':'c5','_version_':105}"
+              + ",{'id':'c100','_version_':200}"
+              + ",{'id':'c101','_version_':201}"
+              + ",{'id':'c105','_version_':205}"
+              + ",{'id':'c106','_version_':206}"
+              +"]"
+      );
+
+      // The updates that were buffered (but never applied) still appear in recent versions!
+      // This is good for some uses, but may not be good for others.
+      assertJQ(req("qt","/get", "getVersions","11")
+          ,"=={'versions':[206,205,204,203,201,200,105,104,103,102,101]}"
+      );
+
+      assertEquals(UpdateLog.State.ACTIVE, ulog.getState()); // leave each test method in a good state
+    } finally {
+      DirectUpdateHandler2.commitOnClose = true;
+      UpdateLog.testing_logReplayHook = null;
+      UpdateLog.testing_logReplayFinishHook = null;
+
+      req().close();
+    }
+
+  }
 
 
   // we need to make sure that the log is informed of a core reload