From c2d583064e95b1bb06f102a7d3610442a2ed8038 Mon Sep 17 00:00:00 2001 From: kimchy Date: Wed, 2 Jun 2010 12:06:41 +0300 Subject: [PATCH] FS Gateway: Allow to configure is native file copying will be used, closes #202. --- .../index/gateway/fs/FsIndexShardGateway.java | 11 ++++++++--- .../org/elasticsearch/util/lucene/Directories.java | 8 ++++---- 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/index/gateway/fs/FsIndexShardGateway.java b/modules/elasticsearch/src/main/java/org/elasticsearch/index/gateway/fs/FsIndexShardGateway.java index 66b51caddec..57327c356ec 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/index/gateway/fs/FsIndexShardGateway.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/index/gateway/fs/FsIndexShardGateway.java @@ -71,6 +71,9 @@ public class FsIndexShardGateway extends AbstractIndexShardComponent implements private final Store store; + + private final boolean nativeCopy; + private final File location; private final File locationIndex; @@ -85,6 +88,8 @@ public class FsIndexShardGateway extends AbstractIndexShardComponent implements this.store = store; this.recoveryThrottler = recoveryThrottler; + this.nativeCopy = componentSettings.getAsBoolean("native_copy", true); + this.location = new File(((FsIndexGateway) fsIndexGateway).indexGatewayHome(), Integer.toString(shardId.id())); this.locationIndex = new File(location, "index"); this.locationTranslog = new File(location, "translog"); @@ -167,7 +172,7 @@ public class FsIndexShardGateway extends AbstractIndexShardComponent implements @Override public void run() { File copyTo = new File(locationIndex, fileName); try { - copyFromDirectory(snapshotIndexCommit.getDirectory(), fileName, copyTo); + copyFromDirectory(snapshotIndexCommit.getDirectory(), fileName, copyTo, nativeCopy); } catch (Exception e) { lastException.set(new IndexShardGatewaySnapshotFailedException(shardId, "Failed to copy to [" + copyTo + "], from dir [" + snapshotIndexCommit.getDirectory() + "] and file [" + fileName + "]", e)); } finally { @@ -249,7 +254,7 @@ public class FsIndexShardGateway extends AbstractIndexShardComponent implements indexTotalFilesSize += snapshotIndexCommit.getDirectory().fileLength(snapshotIndexCommit.getSegmentsFileName()); long time = System.currentTimeMillis(); copyFromDirectory(snapshotIndexCommit.getDirectory(), snapshotIndexCommit.getSegmentsFileName(), - new File(locationIndex, snapshotIndexCommit.getSegmentsFileName())); + new File(locationIndex, snapshotIndexCommit.getSegmentsFileName()), nativeCopy); indexTime += (System.currentTimeMillis() - time); } } catch (Exception e) { @@ -324,7 +329,7 @@ public class FsIndexShardGateway extends AbstractIndexShardComponent implements Thread.sleep(recoveryThrottler.throttleInterval().millis()); } throttlingWaitTime.addAndGet(System.currentTimeMillis() - throttlingStartTime); - copyToDirectory(file, store.directory(), file.getName()); + copyToDirectory(file, store.directory(), file.getName(), nativeCopy); } catch (Exception e) { logger.debug("Failed to read [" + file + "] into [" + store + "]", e); lastException.set(e); diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/lucene/Directories.java b/modules/elasticsearch/src/main/java/org/elasticsearch/util/lucene/Directories.java index 065b7857578..7c37ae27f8f 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/lucene/Directories.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/util/lucene/Directories.java @@ -80,8 +80,8 @@ public class Directories { return checksum(dir.openInput(name)); } - public static void copyFromDirectory(Directory dir, String fileName, File copyTo) throws IOException { - if (dir instanceof FSDirectory) { + public static void copyFromDirectory(Directory dir, String fileName, File copyTo, boolean nativeCopy) throws IOException { + if (nativeCopy && (dir instanceof FSDirectory)) { if (!copyTo.exists()) { copyTo.createNewFile(); } @@ -127,8 +127,8 @@ public class Directories { } } - public static void copyToDirectory(File copyFrom, Directory dir, String fileName) throws IOException { - if (dir instanceof FSDirectory) { + public static void copyToDirectory(File copyFrom, Directory dir, String fileName, boolean nativeCopy) throws IOException { + if (nativeCopy && (dir instanceof FSDirectory)) { File destinationFile = new File(((FSDirectory) dir).getFile(), fileName); if (!destinationFile.exists()) { destinationFile.createNewFile();