SOLR-3361: fix "maxNumberOfBackups" to work if backups are triggered on commit

git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1329337 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
James Dyer 2012-04-23 17:12:42 +00:00
parent 9bf158e095
commit 013aebd3ae
4 changed files with 22 additions and 8 deletions

View File

@ -379,6 +379,9 @@ Bug Fixes
* SOLR-3352: eDismax: pf2 should kick in for a query with 2 terms (janhoy) * SOLR-3352: eDismax: pf2 should kick in for a query with 2 terms (janhoy)
* SOLR-3361: ReplicationHandler "maxNumberOfBackups" doesn't work if backups are triggered on commit
(James Dyer, Tomas Fernandez Lobbe)
Other Changes Other Changes
---------------------- ----------------------

View File

@ -993,9 +993,13 @@ public class ReplicationHandler extends RequestHandlerBase implements SolrCoreAw
***/ ***/
} }
if (snapshoot) { if (snapshoot) {
try { try {
int numberToKeep = numberBackupsToKeep;
if (numberToKeep < 1) {
numberToKeep = Integer.MAX_VALUE;
}
SnapShooter snapShooter = new SnapShooter(core, null); SnapShooter snapShooter = new SnapShooter(core, null);
snapShooter.createSnapAsync(currentCommitPoint, ReplicationHandler.this); snapShooter.createSnapAsync(currentCommitPoint, numberToKeep, ReplicationHandler.this);
} catch (Exception e) { } catch (Exception e) {
LOG.error("Exception while snapshooting", e); LOG.error("Exception while snapshooting", e);
} }

View File

@ -32,7 +32,7 @@
<requestHandler name="/replication" class="solr.ReplicationHandler"> <requestHandler name="/replication" class="solr.ReplicationHandler">
<lst name="master"> <lst name="master">
<str name="replicateAfter">commit</str> <str name="backupAfter">commit</str>
<str name="confFiles">schema-replication2.xml:schema.xml</str> <str name="confFiles">schema-replication2.xml:schema.xml</str>
</lst> </lst>
<str name="maxNumberOfBackups">1</str> <str name="maxNumberOfBackups">1</str>

View File

@ -243,7 +243,7 @@ public class TestReplicationHandler extends SolrTestCaseJ4 {
} }
public void test() throws Exception { public void test() throws Exception {
doTestReplicateAfterCoreReload(); doTestReplicateAfterCoreReload();
doTestDetails(); doTestDetails();
doTestReplicateAfterWrite2Slave(); doTestReplicateAfterWrite2Slave();
doTestIndexAndConfigReplication(); doTestIndexAndConfigReplication();
@ -776,7 +776,6 @@ public class TestReplicationHandler extends SolrTestCaseJ4 {
if(random().nextBoolean()) { if(random().nextBoolean()) {
configFile = "solrconfig-master1-keepOneBackup.xml"; configFile = "solrconfig-master1-keepOneBackup.xml";
addNumberToKeepInRequest = false; addNumberToKeepInRequest = false;
backupKeepParamName = ReplicationHandler.NUMBER_BACKUPS_TO_KEEP_INIT_PARAM;
} }
masterJetty.stop(); masterJetty.stop();
@ -864,8 +863,16 @@ public class TestReplicationHandler extends SolrTestCaseJ4 {
File[] snapDir = new File[2]; File[] snapDir = new File[2];
String firstBackupTimestamp = null; String firstBackupTimestamp = null;
for(int i=0 ; i<2 ; i++) { for(int i=0 ; i<2 ; i++) {
BackupThread backupThread = new BackupThread(addNumberToKeepInRequest, backupKeepParamName); BackupThread backupThread = null;
backupThread.start(); if(!addNumberToKeepInRequest) {
if(random().nextBoolean()) {
masterClient.commit();
} else {
backupThread = new BackupThread(addNumberToKeepInRequest, backupKeepParamName);
backupThread.start();
}
}
File dataDir = new File(master.getDataDir()); File dataDir = new File(master.getDataDir());
@ -890,7 +897,7 @@ public class TestReplicationHandler extends SolrTestCaseJ4 {
waitCnt++; waitCnt++;
} }
if(backupThread.fail != null) { if(backupThread!= null && backupThread.fail != null) {
fail(backupThread.fail); fail(backupThread.fail);
} }