LUCENE-5953: Revert changes to SnapShooter, just remove useless locking. The tests now pass more often, because snapshot directory does not disappear suddenly (its created explicitely before file copying

git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1637743 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Uwe Schindler 2014-11-09 21:20:13 +00:00
parent e8144f986b
commit 8251f8dbf8
2 changed files with 13 additions and 16 deletions

View File

@ -88,7 +88,6 @@ import org.apache.solr.util.FileUtils;
import org.apache.solr.util.PropertiesInputStream; import org.apache.solr.util.PropertiesInputStream;
import org.apache.solr.util.PropertiesOutputStream; import org.apache.solr.util.PropertiesOutputStream;
import org.apache.solr.util.RefCounted; import org.apache.solr.util.RefCounted;
import org.eclipse.jetty.util.log.Log;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;

View File

@ -54,7 +54,7 @@ public class SnapShooter {
private SolrCore solrCore; private SolrCore solrCore;
private String snapshotName = null; private String snapshotName = null;
private String directoryName = null; private String directoryName = null;
private FSDirectory snapShotDir = null; private File snapShotDir = null;
public SnapShooter(SolrCore core, String location, String snapshotName) { public SnapShooter(SolrCore core, String location, String snapshotName) {
solrCore = core; solrCore = core;
@ -115,16 +115,15 @@ public class SnapShooter {
} }
void validateCreateSnapshot() throws IOException { void validateCreateSnapshot() throws IOException {
final File snapShotFile = new File(snapDir, directoryName); snapShotDir = new File(snapDir, directoryName);
if (snapShotFile.exists()) { if (snapShotDir.exists()) {
throw new SolrException(SolrException.ErrorCode.BAD_REQUEST, throw new SolrException(SolrException.ErrorCode.BAD_REQUEST,
"Snapshot directory already exists: " + snapShotFile.getAbsolutePath()); "Snapshot directory already exists: " + snapShotDir.getAbsolutePath());
} }
if (!snapShotFile.mkdirs()) { if (!snapShotDir.mkdirs()) {
throw new SolrException(SolrException.ErrorCode.BAD_REQUEST, throw new SolrException(SolrException.ErrorCode.BAD_REQUEST,
"Unable to create snapshot directory: " + snapShotFile.getAbsolutePath()); "Unable to create snapshot directory: " + snapShotDir.getAbsolutePath());
} }
snapShotDir = new SimpleFSDirectory(snapShotFile.toPath(), NoLockFactory.INSTANCE);
} }
void createSnapshot(final IndexCommit indexCommit, ReplicationHandler replicationHandler) { void createSnapshot(final IndexCommit indexCommit, ReplicationHandler replicationHandler) {
@ -147,7 +146,7 @@ public class SnapShooter {
details.add("snapshotName", snapshotName); details.add("snapshotName", snapshotName);
LOG.info("Done creating backup snapshot: " + (snapshotName == null ? "<not named>" : snapshotName)); LOG.info("Done creating backup snapshot: " + (snapshotName == null ? "<not named>" : snapshotName));
} catch (Exception e) { } catch (Exception e) {
SnapPuller.delTree(snapShotDir.getDirectory().toFile()); SnapPuller.delTree(snapShotDir);
LOG.error("Exception while creating snapshot", e); LOG.error("Exception while creating snapshot", e);
details.add("snapShootException", e.getMessage()); details.add("snapShootException", e.getMessage());
} finally { } finally {
@ -224,13 +223,12 @@ public class SnapShooter {
public static final String DATE_FMT = "yyyyMMddHHmmssSSS"; public static final String DATE_FMT = "yyyyMMddHHmmssSSS";
private void copyFiles(Directory sourceDir, Collection<String> files, Directory destDir) throws IOException { private static void copyFiles(Directory sourceDir, Collection<String> files, File destDir) throws IOException {
for (String indexFile : files) { try (FSDirectory dir = new SimpleFSDirectory(destDir.toPath(), NoLockFactory.INSTANCE)) {
copyFile(sourceDir, indexFile, destDir); for (String indexFile : files) {
sourceDir.copy(dir, indexFile, indexFile, DirectoryFactory.IOCONTEXT_NO_CACHE);
}
} }
} }
private void copyFile(Directory sourceDir, String indexFile, Directory destDir) throws IOException {
sourceDir.copy(destDir, indexFile, indexFile, DirectoryFactory.IOCONTEXT_NO_CACHE);
}
} }