You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by sh...@apache.org on 2018/03/28 07:11:05 UTC

lucene-solr:master: SOLR-10734: AtomicUpdateRequestProcessor can cause wrong/old values to be set under concurrent updates for the same document. Multithreaded test for AtomicUpdateRequestProcessor was also beefed up and fixed.

Repository: lucene-solr
Updated Branches:
  refs/heads/master 3e29c7dbd -> ab3250624


SOLR-10734: AtomicUpdateRequestProcessor can cause wrong/old values to be set under concurrent updates for the same document. Multithreaded test for AtomicUpdateRequestProcessor was also beefed up and fixed.


Project: http://git-wip-us.apache.org/repos/asf/lucene-solr/repo
Commit: http://git-wip-us.apache.org/repos/asf/lucene-solr/commit/ab325062
Tree: http://git-wip-us.apache.org/repos/asf/lucene-solr/tree/ab325062
Diff: http://git-wip-us.apache.org/repos/asf/lucene-solr/diff/ab325062

Branch: refs/heads/master
Commit: ab325062435726f31cce6176bf5ed881f44973bb
Parents: 3e29c7d
Author: Shalin Shekhar Mangar <sh...@apache.org>
Authored: Wed Mar 28 12:40:57 2018 +0530
Committer: Shalin Shekhar Mangar <sh...@apache.org>
Committed: Wed Mar 28 12:40:57 2018 +0530

----------------------------------------------------------------------
 solr/CHANGES.txt                                |  6 +++--
 .../processor/AtomicUpdateProcessorFactory.java | 25 +++++++++++++-------
 .../AtomicUpdateProcessorFactoryTest.java       |  1 -
 3 files changed, 20 insertions(+), 12 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/ab325062/solr/CHANGES.txt
----------------------------------------------------------------------
diff --git a/solr/CHANGES.txt b/solr/CHANGES.txt
index fcf1f9c..da63c93 100644
--- a/solr/CHANGES.txt
+++ b/solr/CHANGES.txt
@@ -86,6 +86,10 @@ Bug Fixes
 * SOLR-12035: ExtendedDismaxQParser fails to include charfilters in nostopanalyzer (Tim Allison via
   Tomás Fernández Löbbe)
 
+* SOLR-10734: AtomicUpdateRequestProcessor can cause wrong/old values to be set under concurrent updates for the same
+  document. Multithreaded test for AtomicUpdateRequestProcessor was also beefed up and fixed.
+  (Ishan Chattopadhyaya, Noble Paul, Amrit Sarkar, shalin)
+
 Optimizations
 ----------------------
 
@@ -122,8 +126,6 @@ Other Changes
 
 * SOLR-12118: Solr Ref-Guide can now use some ivy version props directly as attributes in content (hossman)
 
-* SOLR-10734: Multithreaded test/support for AtomicURP broken. (Ishan Chattopadhyaya, Noble Paul, Amrit Sarkar, shalin)
-
 ==================  7.3.0 ==================
 
 Consult the LUCENE_CHANGES.txt file for additional, low level, changes in this release.

http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/ab325062/solr/core/src/java/org/apache/solr/update/processor/AtomicUpdateProcessorFactory.java
----------------------------------------------------------------------
diff --git a/solr/core/src/java/org/apache/solr/update/processor/AtomicUpdateProcessorFactory.java b/solr/core/src/java/org/apache/solr/update/processor/AtomicUpdateProcessorFactory.java
index 84bf03a..c3522f0 100644
--- a/solr/core/src/java/org/apache/solr/update/processor/AtomicUpdateProcessorFactory.java
+++ b/solr/core/src/java/org/apache/solr/update/processor/AtomicUpdateProcessorFactory.java
@@ -153,17 +153,17 @@ public class AtomicUpdateProcessorFactory extends UpdateRequestProcessorFactory
       // if atomic, put _version_ for optimistic concurrency if doc present in index
       if (isAtomicUpdateAddedByMe) {
         Long lastVersion = vinfo.lookupVersion(cmd.getIndexedId());
-        if (lastVersion != null) {
-          orgdoc.setField(VERSION, lastVersion);
-        }
-        processAddWithRetry(cmd, 0);
+        // if lastVersion is null then we put -1 to assert that document must not exist
+        lastVersion = lastVersion == null ? -1 : lastVersion;
+        orgdoc.setField(VERSION, lastVersion);
+        processAddWithRetry(cmd, 1, cmd.getSolrInputDocument().deepCopy());
       } else {
         super.processAdd(cmd);
       }
       // else send it for doc to get inserted for the first time
     }
 
-    private void processAddWithRetry(AddUpdateCommand cmd, int attempts) throws IOException {
+    private void processAddWithRetry(AddUpdateCommand cmd, int attempts, SolrInputDocument clonedOriginalDoc) throws IOException {
       try {
         super.processAdd(cmd);
       } catch (SolrException e) {
@@ -174,11 +174,18 @@ public class AtomicUpdateProcessorFactory extends UpdateRequestProcessorFactory
         if (e.code() == ErrorCode.CONFLICT.code) { // version conflict
           log.warn("Atomic update failed due to " + e.getMessage() +
               " Retrying with new version .... (" + attempts + ")");
+
           Long lastVersion = vinfo.lookupVersion(cmd.getIndexedId());
-          if (lastVersion != null) {
-            cmd.solrDoc.setField(VERSION, lastVersion);
-          }
-          processAddWithRetry(cmd, attempts);
+          // if lastVersion is null then we put -1 to assert that document must not exist
+          lastVersion = lastVersion == null ? -1 : lastVersion;
+
+          // The AtomicUpdateDocumentMerger modifies the AddUpdateCommand.solrDoc to populate the real values of the
+          // modified fields. We don't want those absolute values because they are out-of-date due to the conflict
+          // so we restore the original document created in processAdd method and set the right version on it
+          cmd.solrDoc = clonedOriginalDoc;
+          cmd.solrDoc.setField(VERSION, lastVersion);
+
+          processAddWithRetry(cmd, attempts, clonedOriginalDoc);
         }
       }
     }

http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/ab325062/solr/core/src/test/org/apache/solr/update/processor/AtomicUpdateProcessorFactoryTest.java
----------------------------------------------------------------------
diff --git a/solr/core/src/test/org/apache/solr/update/processor/AtomicUpdateProcessorFactoryTest.java b/solr/core/src/test/org/apache/solr/update/processor/AtomicUpdateProcessorFactoryTest.java
index 92a16d8..7d377fa 100644
--- a/solr/core/src/test/org/apache/solr/update/processor/AtomicUpdateProcessorFactoryTest.java
+++ b/solr/core/src/test/org/apache/solr/update/processor/AtomicUpdateProcessorFactoryTest.java
@@ -198,7 +198,6 @@ public class AtomicUpdateProcessorFactoryTest extends SolrTestCaseJ4 {
 
   }
 
-  @BadApple(bugUrl = "https://issues.apache.org/jira/browse/SOLR-10734")
   public void testMultipleThreads() throws Exception {
     clearIndex();
     String[] strings = new String[5];