lucene-solr-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From no...@apache.org
Subject svn commit: r792474 - in /lucene/solr/trunk/src: java/org/apache/solr/handler/SnapPuller.java test/org/apache/solr/handler/TestReplicationHandler.java
Date Thu, 09 Jul 2009 09:57:15 GMT
Author: noble
Date: Thu Jul  9 09:57:15 2009
New Revision: 792474

URL: http://svn.apache.org/viewvc?rev=792474&view=rev
Log:
SOLR-1264 if master slave is out of sync w/ master replication is not successful

Modified:
    lucene/solr/trunk/src/java/org/apache/solr/handler/SnapPuller.java
    lucene/solr/trunk/src/test/org/apache/solr/handler/TestReplicationHandler.java

Modified: lucene/solr/trunk/src/java/org/apache/solr/handler/SnapPuller.java
URL: http://svn.apache.org/viewvc/lucene/solr/trunk/src/java/org/apache/solr/handler/SnapPuller.java?rev=792474&r1=792473&r2=792474&view=diff
==============================================================================
--- lucene/solr/trunk/src/java/org/apache/solr/handler/SnapPuller.java (original)
+++ lucene/solr/trunk/src/java/org/apache/solr/handler/SnapPuller.java Thu Jul  9 09:57:15
2009
@@ -280,6 +280,7 @@
       if (isIndexStale())
         isSnapNeeded = true;
       boolean successfulInstall = false;
+      boolean deleteTmpIdxDir = true;
       try {
         File indexDir = new File(core.getIndexDir());
         downloadIndexFiles(isSnapNeeded, tmpIndexDir, latestVersion);
@@ -300,7 +301,8 @@
         } else {
           terminateAndWaitFsyncService();
           if (isSnapNeeded) {
-            modifyIndexProps(tmpIndexDir.getName());
+            successfulInstall = modifyIndexProps(tmpIndexDir.getName());
+            deleteTmpIdxDir =  false;
           } else {
             successfulInstall = copyIndexFiles(tmpIndexDir, indexDir);
           }
@@ -316,10 +318,9 @@
       } catch (SolrException e) {
         throw e;
       } catch (Exception e) {
-        delTree(tmpIndexDir);
         throw new SolrException(SolrException.ErrorCode.SERVER_ERROR, "Index fetch failed
: ", e);
       } finally {
-        delTree(tmpIndexDir);
+        if(deleteTmpIdxDir) delTree(tmpIndexDir);
       }
       return successfulInstall;
     } finally {
@@ -582,7 +583,7 @@
   /**
    * If the index is stale by any chance, load index from a different dir in the data dir.
    */
-  private void modifyIndexProps(String snap) {
+  private boolean modifyIndexProps(String snap) {
     LOG.info("New index installed. Updating index properties...");
     File idxprops = new File(solrCore.getDataDir() + "index.properties");
     Properties p = new Properties();
@@ -608,6 +609,7 @@
     } finally {
       IOUtils.closeQuietly(os);
     }
+      return true;
   }
 
   private final Map<String, FileInfo> confFileInfoCache = new HashMap<String, FileInfo>();

Modified: lucene/solr/trunk/src/test/org/apache/solr/handler/TestReplicationHandler.java
URL: http://svn.apache.org/viewvc/lucene/solr/trunk/src/test/org/apache/solr/handler/TestReplicationHandler.java?rev=792474&r1=792473&r2=792474&view=diff
==============================================================================
--- lucene/solr/trunk/src/test/org/apache/solr/handler/TestReplicationHandler.java (original)
+++ lucene/solr/trunk/src/test/org/apache/solr/handler/TestReplicationHandler.java Thu Jul
 9 09:57:15 2009
@@ -133,15 +133,15 @@
     //get docs from slave and check if number is equal to master
     NamedList slaveQueryRsp = query("*:*", slaveClient);
     SolrDocumentList slaveQueryResult = (SolrDocumentList) slaveQueryRsp.get("response");
-    
-    if(slaveQueryResult.getNumFound() == 0) {
+
+    if (slaveQueryResult.getNumFound() == 0) {
       //try sleeping again in case of slower comp
       Thread.sleep(5000);
-      
-       slaveQueryRsp = query("*:*", slaveClient);
-       slaveQueryResult = (SolrDocumentList) slaveQueryRsp.get("response");
+
+      slaveQueryRsp = query("*:*", slaveClient);
+      slaveQueryResult = (SolrDocumentList) slaveQueryRsp.get("response");
     }
-    
+
     assertEquals(500, slaveQueryResult.getNumFound());
 
     //compare results
@@ -196,15 +196,15 @@
     //get docs from slave and check if number is equal to master
     NamedList slaveQueryRsp = query("*:*", slaveClient);
     SolrDocumentList slaveQueryResult = (SolrDocumentList) slaveQueryRsp.get("response");
-    
-    if(slaveQueryResult.getNumFound() == 0) {
+
+    if (slaveQueryResult.getNumFound() == 0) {
       //try sleeping again in case of slower comp
       Thread.sleep(5000);
-      
-       slaveQueryRsp = query("*:*", slaveClient);
-       slaveQueryResult = (SolrDocumentList) slaveQueryRsp.get("response");
+
+      slaveQueryRsp = query("*:*", slaveClient);
+      slaveQueryResult = (SolrDocumentList) slaveQueryRsp.get("response");
     }
-    
+
     assertEquals(500, slaveQueryResult.getNumFound());
 
     //compare results
@@ -382,6 +382,53 @@
 
   }
 
+  public void testReplicateAfterWrite2Slave() throws Exception {
+
+    //add 500 docs to master
+    for (int i = 0; i < 500; i++)
+      index(masterClient, "id", i, "name", "name = " + i);
+
+    masterClient.commit();
+
+    NamedList masterQueryRsp = query("*:*", masterClient);
+    SolrDocumentList masterQueryResult = (SolrDocumentList) masterQueryRsp.get("response");
+    assertEquals(500, masterQueryResult.getNumFound());
+
+    String masterUrl = "http://localhost:" + masterJetty.getLocalPort() + "/solr/replication?command=disableReplication";
+    URL url = new URL(masterUrl);
+    InputStream stream = url.openStream();
+    try {
+      stream.close();
+    } catch (IOException e) {
+      //e.printStackTrace();
+    }
+
+    index(slaveClient, "id", 555, "name", "name = " + 555);
+    slaveClient.commit(true, true);
+
+    //this doc is added to slave so it should show an item w/ that result
+    NamedList slaveQueryRsp = query("id:555", slaveClient);
+    SolrDocumentList slaveQueryResult = (SolrDocumentList) slaveQueryRsp.get("response");
+    assertEquals(1, slaveQueryResult.getNumFound());
+
+    masterUrl = "http://localhost:" + masterJetty.getLocalPort() + "/solr/replication?command=enableReplication";
+    url = new URL(masterUrl);
+    stream = url.openStream();
+    try {
+      stream.close();
+    } catch (IOException e) {
+      //e.printStackTrace();
+    }
+
+    //sleep for pollinterval time 3s, to let slave pull data.
+    Thread.sleep(3000);
+    //the slave should have done a full copy of the index so the doc with id:555 should not
be there in the slave now
+    slaveQueryRsp = query("id:555", slaveClient);
+    slaveQueryResult = (SolrDocumentList) slaveQueryRsp.get("response");
+    assertEquals(0, slaveQueryResult.getNumFound());
+  }
+
+
   /* character copy of file using UTF-8 */
   void copyFile(File src, File dst) throws IOException {
     copyFile(src, dst, null);



Mime
View raw message