You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by jd...@apache.org on 2012/04/24 20:07:49 UTC
svn commit: r1329906 - in /lucene/dev/trunk/solr/core/src:
test-files/solr/conf/solrconfig-master1-keepOneBackup.xml
test/org/apache/solr/handler/TestReplicationHandler.java
Author: jdyer
Date: Tue Apr 24 18:07:49 2012
New Revision: 1329906
URL: http://svn.apache.org/viewvc?rev=1329906&view=rev
Log:
SOLR-3361: fix "maxNumberOfBackups" to work if backups are triggered on commit
Modified:
lucene/dev/trunk/solr/core/src/test-files/solr/conf/solrconfig-master1-keepOneBackup.xml
lucene/dev/trunk/solr/core/src/test/org/apache/solr/handler/TestReplicationHandler.java
Modified: lucene/dev/trunk/solr/core/src/test-files/solr/conf/solrconfig-master1-keepOneBackup.xml
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/solr/core/src/test-files/solr/conf/solrconfig-master1-keepOneBackup.xml?rev=1329906&r1=1329905&r2=1329906&view=diff
==============================================================================
--- lucene/dev/trunk/solr/core/src/test-files/solr/conf/solrconfig-master1-keepOneBackup.xml (original)
+++ lucene/dev/trunk/solr/core/src/test-files/solr/conf/solrconfig-master1-keepOneBackup.xml Tue Apr 24 18:07:49 2012
@@ -32,7 +32,7 @@
<requestHandler name="/replication" class="solr.ReplicationHandler">
<lst name="master">
- <str name="backupAfter">commit</str>
+ <str name="replicateAfter">commit</str>
<str name="confFiles">schema-replication2.xml:schema.xml</str>
</lst>
<str name="maxNumberOfBackups">1</str>
Modified: lucene/dev/trunk/solr/core/src/test/org/apache/solr/handler/TestReplicationHandler.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/solr/core/src/test/org/apache/solr/handler/TestReplicationHandler.java?rev=1329906&r1=1329905&r2=1329906&view=diff
==============================================================================
--- lucene/dev/trunk/solr/core/src/test/org/apache/solr/handler/TestReplicationHandler.java (original)
+++ lucene/dev/trunk/solr/core/src/test/org/apache/solr/handler/TestReplicationHandler.java Tue Apr 24 18:07:49 2012
@@ -776,6 +776,7 @@ public class TestReplicationHandler exte
if(random().nextBoolean()) {
configFile = "solrconfig-master1-keepOneBackup.xml";
addNumberToKeepInRequest = false;
+ backupKeepParamName = ReplicationHandler.NUMBER_BACKUPS_TO_KEEP_INIT_PARAM;
}
masterJetty.stop();
@@ -791,24 +792,6 @@ public class TestReplicationHandler exte
index(masterClient, "id", i, "name", "name = " + i);
masterClient.commit();
- boolean checkOnCommit = random().nextBoolean();
- //Check to see if 2 commits results in only one backup. (maxBackupsToKeep=1)
- if(!addNumberToKeepInRequest && checkOnCommit) {
- Thread.sleep(1000); //ensure the 2 backups have a separate timestamp.
- masterClient.commit();
- File[] files = new File(master.getDataDir()).listFiles(new FilenameFilter() {
- public boolean accept(File dir, String name) {
- if(name.startsWith("snapshot")) {
- return true;
- }
- return false;
- }
- });
- assertEquals(1, files.length);
- for(File f : files) {
- AbstractSolrTestCase.recurseDelete(f); // clean up the snap dir
- }
- }
class BackupThread extends Thread {
volatile String fail = null;
@@ -878,66 +861,65 @@ public class TestReplicationHandler exte
};
};
- if(!checkOnCommit) {
- File[] snapDir = new File[2];
- String firstBackupTimestamp = null;
- for(int i=0 ; i<2 ; i++) {
- BackupThread backupThread = new BackupThread(addNumberToKeepInRequest, backupKeepParamName);
- backupThread.start();
-
- File dataDir = new File(master.getDataDir());
-
- int waitCnt = 0;
- CheckStatus checkStatus = new CheckStatus(firstBackupTimestamp);
- while(true) {
- checkStatus.run();
- if(checkStatus.fail != null) {
- fail(checkStatus.fail);
- }
- if(checkStatus.success) {
- if(i==0) {
- firstBackupTimestamp = checkStatus.backupTimestamp;
- Thread.sleep(1000); //ensure the next backup will have a different timestamp.
- }
- break;
- }
- Thread.sleep(200);
- if(waitCnt == 10) {
- fail("Backup success not detected:" + checkStatus.response);
+ File[] snapDir = new File[2];
+ String firstBackupTimestamp = null;
+ for(int i=0 ; i<2 ; i++) {
+ BackupThread backupThread = new BackupThread(addNumberToKeepInRequest, backupKeepParamName);
+ backupThread.start();
+
+ File dataDir = new File(master.getDataDir());
+
+ int waitCnt = 0;
+ CheckStatus checkStatus = new CheckStatus(firstBackupTimestamp);
+ while(true) {
+ checkStatus.run();
+ if(checkStatus.fail != null) {
+ fail(checkStatus.fail);
+ }
+ if(checkStatus.success) {
+ if(i==0) {
+ firstBackupTimestamp = checkStatus.backupTimestamp;
+ Thread.sleep(1000); //ensure the next backup will have a different timestamp.
}
- waitCnt++;
+ break;
}
-
- if(backupThread.fail != null) {
- fail(backupThread.fail);
+ Thread.sleep(200);
+ if(waitCnt == 10) {
+ fail("Backup success not detected:" + checkStatus.response);
}
-
- File[] files = dataDir.listFiles(new FilenameFilter() {
-
- public boolean accept(File dir, String name) {
- if(name.startsWith("snapshot")) {
- return true;
- }
- return false;
- }
- });
- assertEquals(1, files.length);
- snapDir[i] = files[0];
- Directory dir = new SimpleFSDirectory(snapDir[i].getAbsoluteFile());
- IndexReader reader = IndexReader.open(dir);
- IndexSearcher searcher = new IndexSearcher(reader);
- TopDocs hits = searcher.search(new MatchAllDocsQuery(), 1);
- assertEquals(nDocs, hits.totalHits);
- reader.close();
- dir.close();
- }
- if(snapDir[0].exists()) {
- fail("The first backup should have been cleaned up because " + backupKeepParamName + " was set to 1.");
+ waitCnt++;
}
- for(int i=0 ; i< snapDir.length ; i++) {
- AbstractSolrTestCase.recurseDelete(snapDir[i]); // clean up the snap dir
+
+ if(backupThread.fail != null) {
+ fail(backupThread.fail);
}
- }
+
+ File[] files = dataDir.listFiles(new FilenameFilter() {
+
+ public boolean accept(File dir, String name) {
+ if(name.startsWith("snapshot")) {
+ return true;
+ }
+ return false;
+ }
+ });
+ assertEquals(1, files.length);
+ snapDir[i] = files[0];
+ Directory dir = new SimpleFSDirectory(snapDir[i].getAbsoluteFile());
+ IndexReader reader = IndexReader.open(dir);
+ IndexSearcher searcher = new IndexSearcher(reader);
+ TopDocs hits = searcher.search(new MatchAllDocsQuery(), 1);
+ assertEquals(nDocs, hits.totalHits);
+ reader.close();
+ dir.close();
+ }
+ if(snapDir[0].exists()) {
+ fail("The first backup should have been cleaned up because " + backupKeepParamName + " was set to 1.");
+ }
+
+ for(int i=0 ; i< snapDir.length ; i++) {
+ AbstractSolrTestCase.recurseDelete(snapDir[i]); // clean up the snap dir
+ }
}
/* character copy of file using UTF-8 */