From bb9116c48543a75dab792331178e2ab0a8794f5c Mon Sep 17 00:00:00 2001 From: Dawid Weiss Date: Tue, 3 Jun 2014 06:21:14 +0000 Subject: [PATCH] SOLR-6119: TestReplicationHandler attempts to remove open folders (and other fixes). git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1599422 13f79535-47bb-0310-9956-ffa450edef68 --- .../org/apache/solr/handler/SnapShooter.java | 8 +- .../solr/handler/TestReplicationHandler.java | 74 +++++++++---------- 2 files changed, 38 insertions(+), 44 deletions(-) diff --git a/solr/core/src/java/org/apache/solr/handler/SnapShooter.java b/solr/core/src/java/org/apache/solr/handler/SnapShooter.java index 83bec1d0c86..48213ceace9 100644 --- a/solr/core/src/java/org/apache/solr/handler/SnapShooter.java +++ b/solr/core/src/java/org/apache/solr/handler/SnapShooter.java @@ -118,13 +118,12 @@ public class SnapShooter { } void validateCreateSnapshot() throws IOException { - Lock lock = lockFactory.makeLock(directoryName + ".lock"); + snapShotDir = new File(snapDir, directoryName); if (lock.isLocked()) { throw new SolrException(SolrException.ErrorCode.BAD_REQUEST, "Unable to acquire lock for snapshot directory: " + snapShotDir.getAbsolutePath()); } - snapShotDir = new File(snapDir, directoryName); if (snapShotDir.exists()) { throw new SolrException(SolrException.ErrorCode.BAD_REQUEST, "Snapshot directory already exists: " + snapShotDir.getAbsolutePath()); @@ -198,7 +197,7 @@ public class SnapShooter { LOG.info("Deleting snapshot: " + snapshotName); NamedList details = new NamedList<>(); - boolean isSuccess = false; + boolean isSuccess; File f = new File(snapDir, "snapshot." + snapshotName); isSuccess = SnapPuller.delTree(f); @@ -236,7 +235,6 @@ public class SnapShooter { } } - public static final String SNAP_DIR = "snapDir"; public static final String DATE_FMT = "yyyyMMddHHmmssSSS"; @@ -271,6 +269,4 @@ public class SnapShooter { sourceDir.copy(destDir, indexFile, indexFile, DirectoryFactory.IOCONTEXT_NO_CACHE); } } - - } diff --git a/solr/core/src/test/org/apache/solr/handler/TestReplicationHandler.java b/solr/core/src/test/org/apache/solr/handler/TestReplicationHandler.java index 61d5bcfc341..aec754ce1e2 100644 --- a/solr/core/src/test/org/apache/solr/handler/TestReplicationHandler.java +++ b/solr/core/src/test/org/apache/solr/handler/TestReplicationHandler.java @@ -1444,9 +1444,10 @@ public class TestReplicationHandler extends SolrTestCaseJ4 { }; File[] snapDir = new File[2]; + boolean namedBackup = random().nextBoolean(); try { String firstBackupTimestamp = null; - boolean namedBackup = true; + String[] backupNames = null; if (namedBackup) { backupNames = new String[2]; @@ -1503,7 +1504,7 @@ public class TestReplicationHandler extends SolrTestCaseJ4 { files = dataDir.listFiles(new FilenameFilter() { @Override public boolean accept(File dir, String name) { - if (name.startsWith("snapshot." + backupName)) { + if (name.equals("snapshot." + backupName)) { return true; } return false; @@ -1520,49 +1521,46 @@ public class TestReplicationHandler extends SolrTestCaseJ4 { reader.close(); dir.close(); - if (!namedBackup && snapDir[0].exists()) { - fail("The first backup should have been cleaned up because " + backupKeepParamName + " was set to 1."); + } + + if (!namedBackup && snapDir[0].exists()) { + fail("The first backup should have been cleaned up because " + backupKeepParamName + " was set to 1."); + } + + //Test Deletion of named backup + if(namedBackup) { + for (int i = 0; i < 2; i++) { + BackupThread deleteBackupThread = new BackupThread(backupNames[i], ReplicationHandler.CMD_DELETE_BACKUP); + deleteBackupThread.start(); + int waitCnt = 0; + CheckDeleteBackupStatus checkDeleteBackupStatus = new CheckDeleteBackupStatus(); + while (true) { + checkDeleteBackupStatus.fetchStatus(); + if (checkDeleteBackupStatus.fail != null) { + fail(checkDeleteBackupStatus.fail); + } + if (checkDeleteBackupStatus.success) { + break; + } + Thread.sleep(200); + if (waitCnt == 20) { + fail("Delete Backup success not detected:" + checkDeleteBackupStatus.response); + } + waitCnt++; + } + + if (deleteBackupThread.fail != null) { + fail(deleteBackupThread.fail); + } } } - for (int i = 0; i < 2; i++) { - //Test Deletion of named backup - BackupThread deleteBackupThread = new BackupThread(backupNames[i], ReplicationHandler.CMD_DELETE_BACKUP); - deleteBackupThread.start(); - int waitCnt = 0; - CheckDeleteBackupStatus checkDeleteBackupStatus = new CheckDeleteBackupStatus(); - while (true) { - checkDeleteBackupStatus.fetchStatus(); - if (checkDeleteBackupStatus.fail != null) { - fail(checkDeleteBackupStatus.fail); - } - if (checkDeleteBackupStatus.success) { - break; - } - Thread.sleep(200); - if (waitCnt == 20) { - fail("Delete Backup success not detected:" + checkDeleteBackupStatus.response); - } - waitCnt++; - } - - if (deleteBackupThread.fail != null) { - fail(deleteBackupThread.fail); - } - } } finally { - // FIXME: SOLR-6119 This is a test bug in that it tries to remove snapDirs that are still open. - try { + if(!namedBackup) { TestUtil.rm(snapDir); - } catch (IOException e) { - // Ignore failures. } - } - } - /* character copy of file using UTF-8 */ - private static void copyFile(File src, File dst) throws IOException { - copyFile(src, dst, null, false); + } } /**