You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by er...@apache.org on 2017/01/31 06:37:13 UTC

lucene-solr:master: SOLR-10060: Add test for implicit commit of uncommitted docs aged out of the transient cache.

Repository: lucene-solr
Updated Branches:
  refs/heads/master 338615279 -> 0ccce22fc


SOLR-10060: Add test for implicit commit of uncommitted docs aged out of the transient cache.


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

Branch: refs/heads/master
Commit: 0ccce22fcd8afa8ad7befa95e0f246e896a788c2
Parents: 3386152
Author: Erick Erickson <er...@apache.org>
Authored: Mon Jan 30 22:36:23 2017 -0800
Committer: Erick Erickson <er...@apache.org>
Committed: Mon Jan 30 22:37:01 2017 -0800

----------------------------------------------------------------------
 .../org/apache/solr/core/TestLazyCores.java     | 75 ++++++++++++++++++++
 1 file changed, 75 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/0ccce22f/solr/core/src/test/org/apache/solr/core/TestLazyCores.java
----------------------------------------------------------------------
diff --git a/solr/core/src/test/org/apache/solr/core/TestLazyCores.java b/solr/core/src/test/org/apache/solr/core/TestLazyCores.java
index 34cd306..385b9c5 100644
--- a/solr/core/src/test/org/apache/solr/core/TestLazyCores.java
+++ b/solr/core/src/test/org/apache/solr/core/TestLazyCores.java
@@ -42,12 +42,20 @@ import org.apache.solr.update.AddUpdateCommand;
 import org.apache.solr.update.CommitUpdateCommand;
 import org.apache.solr.update.UpdateHandler;
 import org.apache.solr.util.ReadOnlyCoresLocator;
+import org.junit.BeforeClass;
 import org.junit.Test;
 
 public class TestLazyCores extends SolrTestCaseJ4 {
 
   private File solrHomeDirectory;
 
+  @BeforeClass
+  public static void setupClass() throws Exception {
+    // Need to use a disk-based directory because there are tests that close a core after adding documents
+    // then expect to be able to re-open that core and execute a search
+    useFactory("solr.StandardDirectoryFactory");
+  }
+
   private static CoreDescriptor makeCoreDescriptor(CoreContainer cc, String coreName, String isTransient, String loadOnStartup) {
     return new CoreDescriptor(cc, coreName, cc.getCoreRootDirectory().resolve(coreName),
         CoreDescriptor.CORE_TRANSIENT, isTransient,
@@ -721,4 +729,71 @@ public class TestLazyCores extends SolrTestCaseJ4 {
     }
   }
 
+  // Insure that when a core is aged out of the transient cache, any uncommitted docs are preserved.
+  // Note, this needs FS-based indexes to persist!
+  // Cores 2, 3, 6, 7, 8, 9 are transient
+  @Test
+  public void testNoCommit() throws Exception {
+    CoreContainer cc = init();
+    String[] coreList = new String[]{
+        "collection2",
+        "collection3",
+        "collection6",
+        "collection7",
+        "collection8",
+        "collection9"
+    };
+    try {
+      // First, go through all the transient cores and add some docs. DO NOT COMMIT!
+      // The aged-out core should commit the docs when it gets closed.
+      List<SolrCore> openCores = new ArrayList<>();
+      for (String coreName : coreList) {
+        SolrCore core = cc.getCore(coreName);
+        openCores.add(core);
+        add10(core);
+      }
+      
+      // Just proving that some cores have been aged out.
+      checkNotInCores(cc, "collection2", "collection3");
+
+      // Close our get of all cores above.
+      for (SolrCore core : openCores) core.close();
+      openCores.clear();
+      
+      // We still should have 6, 7, 8, 9 loaded, their reference counts have NOT dropped to zero 
+      checkInCores(cc, "collection6", "collection7", "collection8", "collection9");
+
+      for (String coreName : coreList) {
+        // The point of this test is to insure that when cores are aged out and re-opened
+        // that the docs are there, so insure that the core we're testing is gone, gone, gone. 
+        checkNotInCores(cc, coreName);
+        
+        // Load the core up again.
+        SolrCore core = cc.getCore(coreName);
+        openCores.add(core);
+        
+        // Insure docs are still there.
+        check10(core);
+      }
+      for (SolrCore core : openCores) core.close();
+    } finally {
+      cc.shutdown();
+    }
+  }
+
+  private void add10(SolrCore core) throws IOException {
+    for (int idx = 0; idx < 10; ++idx) {
+      addLazy(core, "id", "0" + idx);
+    }
+    SolrQueryRequest req = makeReq(core);
+
+  }
+
+  private void check10(SolrCore core) {
+    // Just get a couple of searches to work!
+    assertQ("test closing core without committing",
+        makeReq(core, "q", "*:*")
+        , "//result[@numFound='10']"
+    );
+  }
 }