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 2016/06/05 09:51:17 UTC

[16/19] lucene-solr:master: sequence numbers: improve test debuggability, IW javadocs

sequence numbers: improve test debuggability, IW javadocs


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

Branch: refs/heads/master
Commit: 133590484b981f5f9fed8ab15e7348a96191ec5f
Parents: dbd2a9e
Author: Mike McCandless <mi...@apache.org>
Authored: Thu Jun 2 05:58:09 2016 -0400
Committer: Mike McCandless <mi...@apache.org>
Committed: Thu Jun 2 05:58:09 2016 -0400

----------------------------------------------------------------------
 .../org/apache/lucene/index/IndexWriter.java    |  4 +--
 .../index/TestIndexingSequenceNumbers.java      | 37 ++++++++------------
 2 files changed, 17 insertions(+), 24 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/13359048/lucene/core/src/java/org/apache/lucene/index/IndexWriter.java
----------------------------------------------------------------------
diff --git a/lucene/core/src/java/org/apache/lucene/index/IndexWriter.java b/lucene/core/src/java/org/apache/lucene/index/IndexWriter.java
index 2bdfea7..b5e0c22 100644
--- a/lucene/core/src/java/org/apache/lucene/index/IndexWriter.java
+++ b/lucene/core/src/java/org/apache/lucene/index/IndexWriter.java
@@ -2928,7 +2928,7 @@ public class IndexWriter implements Closeable, TwoPhaseCommit, Accountable {
    *  will internally call prepareCommit.
    *
    * @return The <a href="#sequence_number">sequence number</a>
-   * last operation in the commit.  All sequence numbers &lt;= this value
+   * of the last operation in the commit.  All sequence numbers &lt;= this value
    * will be reflected in the commit, and all others will not.
    */
   @Override
@@ -3128,7 +3128,7 @@ public class IndexWriter implements Closeable, TwoPhaseCommit, Accountable {
    * @see #prepareCommit
    *
    * @return The <a href="#sequence_number">sequence number</a>
-   * last operation in the commit.  All sequence numbers &lt;= this value
+   * of the last operation in the commit.  All sequence numbers &lt;= this value
    * will be reflected in the commit, and all others will not.
    */
   @Override

http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/13359048/lucene/core/src/test/org/apache/lucene/index/TestIndexingSequenceNumbers.java
----------------------------------------------------------------------
diff --git a/lucene/core/src/test/org/apache/lucene/index/TestIndexingSequenceNumbers.java b/lucene/core/src/test/org/apache/lucene/index/TestIndexingSequenceNumbers.java
index 23389dd..f4fc2f0 100644
--- a/lucene/core/src/test/org/apache/lucene/index/TestIndexingSequenceNumbers.java
+++ b/lucene/core/src/test/org/apache/lucene/index/TestIndexingSequenceNumbers.java
@@ -165,7 +165,8 @@ public class TestIndexingSequenceNumbers extends LuceneTestCase {
     Object commitLock = new Object();
     final List<Operation> commits = new ArrayList<>();
 
-    // multiple threads update the same set of documents, and we randomly commit
+    // multiple threads update the same set of documents, and we randomly commit, recording the commit seqNo and then opening each commit in
+    // the end to verify it reflects the correct updates
     for(int i=0;i<threads.length;i++) {
       final List<Operation> ops = new ArrayList<>();
       threadOps.add(ops);
@@ -325,7 +326,8 @@ public class TestIndexingSequenceNumbers extends LuceneTestCase {
 
     List<Operation> ops1 = new ArrayList<>();
     threadOps.add(ops1);
-    
+
+    // pre-index every ID so none are missing:
     for(int id=0;id<idCount;id++) {
       int threadID = 0;
       Operation op = new Operation();
@@ -340,7 +342,8 @@ public class TestIndexingSequenceNumbers extends LuceneTestCase {
       ops1.add(op);
     }
 
-    // multiple threads update the same set of documents, and we randomly commit
+    // multiple threads update the same set of documents, and we randomly commit, recording the commit seqNo and then opening each commit in
+    // the end to verify it reflects the correct updates
     for(int i=0;i<threads.length;i++) {
       final List<Operation> ops;
       if (i == 0) {
@@ -430,31 +433,21 @@ public class TestIndexingSequenceNumbers extends LuceneTestCase {
       for(int id=0;id<idCount;id++) {
         //System.out.println("TEST: check id=" + id + " expectedThreadID=" + expectedThreadIDs[id]);
         TopDocs hits = s.search(new TermQuery(new Term("id", ""+id)), 1);
-                                  
-        if (expectedThreadIDs[id] != -1) {
-          assertEquals(1, hits.totalHits);
-          int actualThreadID = (int) docValues.get(id);
-          if (expectedThreadIDs[id] != actualThreadID) {
-            System.out.println("FAIL: id=" + id + " expectedThreadID=" + expectedThreadIDs[id] + " vs actualThreadID=" + actualThreadID + " commitSeqNo=" + commitSeqNo + " numThreads=" + numThreads);
-            for(int threadID=0;threadID<threadOps.size();threadID++) {
-              for(Operation op : threadOps.get(threadID)) {
-                if (id == op.id) {
-                  System.out.println("  threadID=" + threadID + " seqNo=" + op.seqNo + " " + (op.what == 2 ? "updated" : "deleted"));
-                }
-              }
-            }
-            assertEquals("id=" + id, expectedThreadIDs[id], actualThreadID);
-          }
-        } else if (hits.totalHits != 0) {
-          System.out.println("FAIL: id=" + id + " expectedThreadID=" + expectedThreadIDs[id] + " vs totalHits=" + hits.totalHits + " commitSeqNo=" + commitSeqNo + " numThreads=" + numThreads);
+
+        // We pre-add all ids up front:
+        assert expectedThreadIDs[id] != -1;
+        assertEquals(1, hits.totalHits);
+        int actualThreadID = (int) docValues.get(id);
+        if (expectedThreadIDs[id] != actualThreadID) {
+          System.out.println("FAIL: commit=" + i + " (of " + commits.size() + ") id=" + id + " expectedThreadID=" + expectedThreadIDs[id] + " vs actualThreadID=" + actualThreadID + " commitSeqNo=" + commitSeqNo + " numThreads=" + numThreads);
           for(int threadID=0;threadID<threadOps.size();threadID++) {
             for(Operation op : threadOps.get(threadID)) {
               if (id == op.id) {
-                System.out.println("  threadID=" + threadID + " seqNo=" + op.seqNo + " " + (op.what == 2 ? "updated" : "del"));
+                System.out.println("  threadID=" + threadID + " seqNo=" + op.seqNo);
               }
             }
           }
-          assertEquals(0, hits.totalHits);
+          assertEquals("id=" + id, expectedThreadIDs[id], actualThreadID);
         }
       }
       w.close();