[TRANSLOG] Make translog file parsing more picky

This commit is contained in:
Simon Willnauer 2015-05-05 14:11:32 +02:00
parent 3cda9b2bd7
commit 00d663f594
2 changed files with 11 additions and 3 deletions

View File

@ -67,7 +67,7 @@ public class FsTranslog extends AbstractIndexShardComponent implements Translog,
public static final String INDEX_TRANSLOG_BUFFER_SIZE = "index.translog.fs.buffer_size";
public static final String INDEX_TRANSLOG_SYNC_INTERVAL = "index.translog.sync_interval";
public static final String TRANSLOG_FILE_PREFIX = "translog-";
private static final Pattern PARSE_ID_PATTERN = Pattern.compile(TRANSLOG_FILE_PREFIX + "(\\d+).*");
static final Pattern PARSE_ID_PATTERN = Pattern.compile(TRANSLOG_FILE_PREFIX + "(\\d+)(\\.recovering)?$");
private final TimeValue syncInterval;
private volatile ScheduledFuture<?> syncScheduler;

View File

@ -120,13 +120,21 @@ public abstract class AbstractTranslogTests extends ElasticsearchTestCase {
file = translogDir.resolve(FsTranslog.TRANSLOG_FILE_PREFIX + id + ".recovering");
assertThat(FsTranslog.parseIdFromFileName(file), equalTo(id));
file = translogDir.resolve(FsTranslog.TRANSLOG_FILE_PREFIX + randomRealisticUnicodeOfCodepointLength(randomIntBetween(1, 10)) + id);
file = translogDir.resolve(FsTranslog.TRANSLOG_FILE_PREFIX + randomNonTranslogPatternString(1, 10) + id);
assertThat(FsTranslog.parseIdFromFileName(file), equalTo(-1l));
file = translogDir.resolve(randomRealisticUnicodeOfCodepointLength(randomIntBetween(1, FsTranslog.TRANSLOG_FILE_PREFIX.length() - 1)));
file = translogDir.resolve(randomNonTranslogPatternString(1, FsTranslog.TRANSLOG_FILE_PREFIX.length() - 1));
assertThat(FsTranslog.parseIdFromFileName(file), equalTo(-1l));
}
private static String randomNonTranslogPatternString(int min, int max) {
String string;
do {
string = randomRealisticUnicodeOfCodepointLength(randomIntBetween(min, max));
} while (FsTranslog.PARSE_ID_PATTERN.matcher(string).matches());
return string;
}
@Test
public void testRead() throws IOException {
Translog.Location loc1 = translog.add(new Translog.Create("test", "1", new byte[]{1}));