You are viewing a plain text version of this content. The canonical link for it is here.
Posted to solr-commits@lucene.apache.org by sh...@apache.org on 2009/03/22 17:33:47 UTC
svn commit: r757209 - in /lucene/solr/trunk: CHANGES.txt
src/common/org/apache/solr/common/util/FileUtils.java
src/java/org/apache/solr/handler/SnapPuller.java
Author: shalin
Date: Sun Mar 22 16:33:46 2009
New Revision: 757209
URL: http://svn.apache.org/viewvc?rev=757209&view=rev
Log:
SOLR-1068 -- Use fsync on replicated index and configuration files
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=757209&r1=757208&r2=757209&view=diff
==============================================================================
--- lucene/solr/trunk/CHANGES.txt (original)
+++ lucene/solr/trunk/CHANGES.txt Sun Mar 22 16:33:46 2009
@@ -365,6 +365,8 @@
21. Upgraded to Lucene 2.9-dev r752164 (shalin)
+22. SOLR-1068: Use fsync on replicated index and configuration files (yonik, shalin)
+
Build
----------------------
1. SOLR-776: Added in ability to sign artifacts via Ant for releases (gsingers)
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=757209&r1=757208&r2=757209&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 Sun Mar 22 16:33:46 2009
@@ -19,6 +19,7 @@
import java.io.File;
import java.io.IOException;
+import java.io.RandomAccessFile;
/**
* @version $Id$
@@ -29,10 +30,10 @@
* Resolves a path relative a base directory.
*
* <p>
- * This method does what "new File(base,path)" <b>Should</b> do, it wasn't
+ * This method does what "new File(base,path)" <b>Should</b> do, it wasn't
* completely lame: If path is absolute, then a File for that path is returned;
* if it's not absoluve, then a File is returnd using "path" as a child
- * of "base")
+ * of "base")
* </p>
*/
public static File resolvePath(File base, String path) throws IOException {
@@ -40,4 +41,44 @@
return r.isAbsolute() ? r : new File(base, path);
}
+ /**
+ * Copied from Lucene's {@link org.apache.lucene.store.FSDirectory#sync(String)}
+ *
+ * @see org.apache.lucene.store.FSDirectory#sync(String)
+ *
+ * @param fullFile the File to be synced to disk
+ * @throws IOException if the file could not be synced
+ */
+ public static void sync(File fullFile) throws IOException {
+ boolean success = false;
+ int retryCount = 0;
+ IOException exc = null;
+ while(!success && retryCount < 5) {
+ retryCount++;
+ RandomAccessFile file = null;
+ try {
+ try {
+ file = new RandomAccessFile(fullFile, "rw");
+ file.getFD().sync();
+ success = true;
+ } finally {
+ if (file != null)
+ file.close();
+ }
+ } catch (IOException ioe) {
+ if (exc == null)
+ exc = ioe;
+ try {
+ // Pause 5 msec
+ Thread.sleep(5);
+ } catch (InterruptedException ie) {
+ Thread.currentThread().interrupt();
+ }
+ }
+ }
+ if (!success)
+ // Throw original exception
+ throw exc;
+ }
+
}
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=757209&r1=757208&r2=757209&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 Sun Mar 22 16:33:46 2009
@@ -23,6 +23,7 @@
import org.apache.solr.common.util.FastInputStream;
import org.apache.solr.common.util.JavaBinCodec;
import org.apache.solr.common.util.NamedList;
+import org.apache.solr.common.util.FileUtils;
import org.apache.solr.core.SolrCore;
import static org.apache.solr.handler.ReplicationHandler.*;
import org.apache.solr.search.SolrIndexSearcher;
@@ -475,7 +476,7 @@
/**
* Copy all index files from the temp index dir to the actual index. The segments_N file is copied last.
*/
- private boolean copyIndexFiles(File snapDir, File indexDir) {
+ private boolean copyIndexFiles(File snapDir, File indexDir) throws IOException {
String segmentsFile = null;
List<String> copiedfiles = new ArrayList<String>();
for (Map<String, Object> f : filesDownloaded) {
@@ -490,11 +491,13 @@
continue;
}
if (!copyAFile(snapDir, indexDir, fname, copiedfiles)) return false;
+ FileUtils.sync(new File(indexDir, fname));
copiedfiles.add(fname);
}
//copy the segments file last
if (segmentsFile != null) {
if (!copyAFile(snapDir, indexDir, segmentsFile, copiedfiles)) return false;
+ FileUtils.sync(new File(indexDir, segmentsFile));
}
return true;
}
@@ -516,7 +519,9 @@
}
}
boolean status = file.renameTo(oldFile);
- if (!status) {
+ if (status) {
+ FileUtils.sync(oldFile);
+ } else {
throw new SolrException(SolrException.ErrorCode.SERVER_ERROR,
"Unable to rename: " + file + " to: " + oldFile);
}