FS Gateway: Allow to configure is native file copying will be used, closes #202.

This commit is contained in:
kimchy 2010-06-02 12:06:41 +03:00
parent 5ef421e779
commit c2d583064e
2 changed files with 12 additions and 7 deletions

View File

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

View File

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