lucene-solr-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From no...@apache.org
Subject svn commit: r906905 - in /lucene/solr/trunk: CHANGES.txt src/common/org/apache/solr/common/util/FileUtils.java src/java/org/apache/solr/handler/SnapPuller.java
Date Fri, 05 Feb 2010 11:44:10 GMT
Author: noble
Date: Fri Feb  5 11:44:10 2010
New Revision: 906905

URL: http://svn.apache.org/viewvc?rev=906905&view=rev
Log:
SOLR-1736 In the slave , If 'mov'ing file does not succeed , copy the file

Modified:
    lucene/solr/trunk/CHANGES.txt
    lucene/solr/trunk/src/common/org/apache/solr/common/util/FileUtils.java
    lucene/solr/trunk/src/java/org/apache/solr/handler/SnapPuller.java

Modified: lucene/solr/trunk/CHANGES.txt
URL: http://svn.apache.org/viewvc/lucene/solr/trunk/CHANGES.txt?rev=906905&r1=906904&r2=906905&view=diff
==============================================================================
--- lucene/solr/trunk/CHANGES.txt (original)
+++ lucene/solr/trunk/CHANGES.txt Fri Feb  5 11:44:10 2010
@@ -173,6 +173,8 @@
 * 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
 ----------------------
 

Modified: lucene/solr/trunk/src/common/org/apache/solr/common/util/FileUtils.java
URL: http://svn.apache.org/viewvc/lucene/solr/trunk/src/common/org/apache/solr/common/util/FileUtils.java?rev=906905&r1=906904&r2=906905&view=diff
==============================================================================
--- lucene/solr/trunk/src/common/org/apache/solr/common/util/FileUtils.java (original)
+++ lucene/solr/trunk/src/common/org/apache/solr/common/util/FileUtils.java Fri Feb  5 11:44:10
2010
@@ -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 @@
     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)}
    *

Modified: lucene/solr/trunk/src/java/org/apache/solr/handler/SnapPuller.java
URL: http://svn.apache.org/viewvc/lucene/solr/trunk/src/java/org/apache/solr/handler/SnapPuller.java?rev=906905&r1=906904&r2=906905&view=diff
==============================================================================
--- lucene/solr/trunk/src/java/org/apache/solr/handler/SnapPuller.java (original)
+++ lucene/solr/trunk/src/java/org/apache/solr/handler/SnapPuller.java Fri Feb  5 11:44:10
2010
@@ -569,15 +569,23 @@
   /**
    * 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())



Mime
View raw message