diff --git a/src/main/java/org/elasticsearch/index/translog/Translog.java b/src/main/java/org/elasticsearch/index/translog/Translog.java index ac993dedac7..4acdbf8715b 100644 --- a/src/main/java/org/elasticsearch/index/translog/Translog.java +++ b/src/main/java/org/elasticsearch/index/translog/Translog.java @@ -33,7 +33,6 @@ import org.elasticsearch.common.io.stream.StreamInput; import org.elasticsearch.common.io.stream.StreamOutput; import org.elasticsearch.common.io.stream.Streamable; import org.elasticsearch.common.lease.Releasable; -import org.elasticsearch.common.logging.ESLogger; import org.elasticsearch.common.lucene.uid.Versions; import org.elasticsearch.common.unit.ByteSizeValue; import org.elasticsearch.index.VersionType; @@ -41,7 +40,6 @@ import org.elasticsearch.index.engine.Engine; import org.elasticsearch.index.shard.IndexShardComponent; import java.io.Closeable; -import java.io.EOFException; import java.io.IOException; import java.nio.file.Path; import java.util.Collection; @@ -145,10 +143,9 @@ public interface Translog extends IndexShardComponent, Closeable, Accountable { public Path[] locations(); /** - * Returns the translog file with the given id as a Path. This - * will return a relative path. + * Returns the translog filename for the given id. */ - Path getPath(long translogId); + String getFilename(long translogId); /** * return stats diff --git a/src/main/java/org/elasticsearch/index/translog/fs/FsTranslog.java b/src/main/java/org/elasticsearch/index/translog/fs/FsTranslog.java index 85164fda6fb..7032587bb47 100644 --- a/src/main/java/org/elasticsearch/index/translog/fs/FsTranslog.java +++ b/src/main/java/org/elasticsearch/index/translog/fs/FsTranslog.java @@ -239,7 +239,7 @@ public class FsTranslog extends AbstractIndexShardComponent implements Translog } } try { - newFile = type.create(shardId, id, new InternalChannelReference(location.resolve(getPath(id)), StandardOpenOption.READ, StandardOpenOption.WRITE, StandardOpenOption.CREATE_NEW), bufferSize); + newFile = type.create(shardId, id, new InternalChannelReference(location.resolve(getFilename(id)), StandardOpenOption.READ, StandardOpenOption.WRITE, StandardOpenOption.CREATE_NEW), bufferSize); } catch (IOException e) { throw new TranslogException(shardId, "failed to create new translog file", e); } @@ -265,7 +265,7 @@ public class FsTranslog extends AbstractIndexShardComponent implements Translog location = file; } } - this.trans = type.create(shardId, id, new InternalChannelReference(location.resolve(getPath(id)), StandardOpenOption.READ, StandardOpenOption.WRITE, StandardOpenOption.CREATE_NEW), transientBufferSize); + this.trans = type.create(shardId, id, new InternalChannelReference(location.resolve(getFilename(id)), StandardOpenOption.READ, StandardOpenOption.WRITE, StandardOpenOption.CREATE_NEW), transientBufferSize); } catch (IOException e) { throw new TranslogException(shardId, "failed to create new translog file", e); } finally { @@ -431,8 +431,8 @@ public class FsTranslog extends AbstractIndexShardComponent implements Translog } @Override - public Path getPath(long translogId) { - return Paths.get(TRANSLOG_FILE_PREFIX + translogId); + public String getFilename(long translogId) { + return TRANSLOG_FILE_PREFIX + translogId; } @Override @@ -473,14 +473,14 @@ public class FsTranslog extends AbstractIndexShardComponent implements Translog @Override public OperationIterator openIterator(long translogId) throws IOException { - final Path translogName = getPath(translogId); + final String translogName = getFilename(translogId); Path recoveringTranslogFile = null; logger.trace("try open translog file {} locations: {}", translogName, Arrays.toString(locations())); OUTER: for (Path translogLocation : locations()) { // we have to support .recovering since it's a leftover from previous version but might still be on the filesystem // we used to rename the foo into foo.recovering since foo was reused / overwritten but we fixed that in 2.0 - for (Path recoveryFiles : FileSystemUtils.files(translogLocation, translogName.getFileName() + "{.recovering,}")) { + for (Path recoveryFiles : FileSystemUtils.files(translogLocation, translogName + "{.recovering,}")) { logger.trace("translog file found in {}", recoveryFiles); recoveringTranslogFile = recoveryFiles; break OUTER; diff --git a/src/test/java/org/elasticsearch/index/translog/AbstractSimpleTranslogTests.java b/src/test/java/org/elasticsearch/index/translog/AbstractSimpleTranslogTests.java index 154d7081386..c1df57afdc7 100644 --- a/src/test/java/org/elasticsearch/index/translog/AbstractSimpleTranslogTests.java +++ b/src/test/java/org/elasticsearch/index/translog/AbstractSimpleTranslogTests.java @@ -383,16 +383,16 @@ public abstract class AbstractSimpleTranslogTests extends ElasticsearchTestCase public void assertFileIsPresent(Translog translog, long id) { for (Path location : translog.locations()) { - if (Files.exists(location.resolve(translog.getPath(id)))) { + if (Files.exists(location.resolve(translog.getFilename(id)))) { return; } } - fail(translog.getPath(id) + " is not present in any location: " + Arrays.toString(translog.locations())); + fail(translog.getFilename(id) + " is not present in any location: " + Arrays.toString(translog.locations())); } public void assertFileDeleted(Translog translog, long id) { for (Path location : translog.locations()) { - assertFalse(Files.exists(location.resolve(translog.getPath(id)))); + assertFalse(Files.exists(location.resolve(translog.getFilename(id)))); } }