Skip to content

Apache Lucene open-source search software

SOLR-1736 In the slave , If 'mov'ing file does not succeed , copy the file

Noble Paulc96611b8f11b
diff --git a/CHANGES.txt b/CHANGES.txt
index 9ff1717c18f..f7c7e23f45f 100644
--- a/CHANGES.txt
+++ b/CHANGES.txt
@@ -173,6 +173,8 @@ Bug Fixes
* SOLR-1753: StatsComponent throws NPE when getting statistics for facets in distributed search
(Janne Majaranta via koji)
+* SOLR-1736:In the slave , If 'mov'ing file does not succeed , copy the file (noble)
+
Other Changes
----------------------
diff --git a/src/common/org/apache/solr/common/util/FileUtils.java b/src/common/org/apache/solr/common/util/FileUtils.java
index 61341a07690..3ca2c28e7b2 100644
--- a/src/common/org/apache/solr/common/util/FileUtils.java
+++ b/src/common/org/apache/solr/common/util/FileUtils.java
@@ -17,10 +17,8 @@
package org.apache.solr.common.util;
-import java.io.File;
-import java.io.IOException;
-import java.io.RandomAccessFile;
-import java.io.FileNotFoundException;
+import java.io.*;
+import java.nio.channels.FileChannel;
/**
* @version $Id$
@@ -42,6 +40,19 @@ public class FileUtils {
return r.isAbsolute() ? r : new File(base, path);
}
+ public static void copyFile(File src , File destination) throws IOException {
+ FileChannel in = null;
+ FileChannel out = null;
+ try {
+ in = new FileInputStream(src).getChannel();
+ out = new FileOutputStream(destination).getChannel();
+ in.transferTo(0, in.size(), out);
+ } finally {
+ try { if (in != null) in.close(); } catch (IOException e) {}
+ try { if (out != null) out.close(); } catch (IOException e) {}
+ }
+ }
+
/**
* Copied from Lucene's {@link org.apache.lucene.store.FSDirectory#sync(String)}
*
diff --git a/src/java/org/apache/solr/handler/SnapPuller.java b/src/java/org/apache/solr/handler/SnapPuller.java
index 8c778a0e34e..8275edbbd13 100644
--- a/src/java/org/apache/solr/handler/SnapPuller.java
+++ b/src/java/org/apache/solr/handler/SnapPuller.java
@@ -569,15 +569,23 @@ public class SnapPuller {
/**
* Copy a file by the File#renameTo() method. If it fails, it is considered a failure
* <p/>
- * Todo may be we should try a simple copy if it fails
*/
private boolean copyAFile(File tmpIdxDir, File indexDir, String fname, List<String> copiedfiles) {
File indexFileInTmpDir = new File(tmpIdxDir, fname);
File indexFileInIndex = new File(indexDir, fname);
boolean success = indexFileInTmpDir.renameTo(indexFileInIndex);
+ if(!success){
+ try {
+ LOG.error("Unable to move index file from: " + indexFileInTmpDir
+ + " to: " + indexFileInIndex + "Trying to do a copy");
+ FileUtils.copyFile(indexFileInTmpDir,indexFileInIndex);
+ success = true;
+ } catch (IOException e) {
+ LOG.error("Unable to copy index file from: " + indexFileInTmpDir
+ + " to: " + indexFileInIndex , e);
+ }
+ }
if (!success) {
- LOG.error("Unable to move index file from: " + indexFileInTmpDir
- + " to: " + indexFileInIndex);
for (String f : copiedfiles) {
File indexFile = new File(indexDir, f);
if (indexFile.exists())