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

git-svn-id: https://svn.apache.org/repos/asf/lucene/solr/trunk@906905 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Noble Paul 2010-02-05 11:44:10 +00:00
parent 000500e3e4
commit c96611b8f1
3 changed files with 28 additions and 7 deletions

View File

@ -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
----------------------

View File

@ -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)}
*

View File

@ -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())