SOLR-1264 if master slave is out of sync w/ master replication is not successful

git-svn-id: https://svn.apache.org/repos/asf/lucene/solr/trunk@792474 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Noble Paul 2009-07-09 09:57:15 +00:00
parent 1ed4c39835
commit 511ea76b32
2 changed files with 65 additions and 16 deletions

View File

@ -280,6 +280,7 @@ public class SnapPuller {
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 @@ public class SnapPuller {
} else {
terminateAndWaitFsyncService();
if (isSnapNeeded) {
modifyIndexProps(tmpIndexDir.getName());
successfulInstall = modifyIndexProps(tmpIndexDir.getName());
deleteTmpIdxDir = false;
} else {
successfulInstall = copyIndexFiles(tmpIndexDir, indexDir);
}
@ -316,10 +318,9 @@ public class SnapPuller {
} 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 @@ public class SnapPuller {
/**
* 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 @@ public class SnapPuller {
} finally {
IOUtils.closeQuietly(os);
}
return true;
}
private final Map<String, FileInfo> confFileInfoCache = new HashMap<String, FileInfo>();

View File

@ -133,15 +133,15 @@ public class TestReplicationHandler extends TestCase {
//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 @@ public class TestReplicationHandler extends TestCase {
//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 class TestReplicationHandler extends TestCase {
}
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);