[TEST] Fix ShadowEngineTests writing to CWD

After #a3f0789 these tests fail because the translog getPath returns a
path that is a CWD path (even though it is unneeded)
This commit is contained in:
Lee Hinman 2015-04-15 15:37:55 -06:00
parent a3f078985b
commit 2d768bb3e8
3 changed files with 11 additions and 14 deletions

View File

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

View File

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

View File

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