Fix InternalEngineTests#testUpgradeOldIndex for 5.0.0 BWC indices

Relates to #21147
This commit is contained in:
Simon Willnauer 2016-11-01 22:25:38 +01:00
parent 79090431af
commit 4db1ac931f
2 changed files with 17 additions and 15 deletions

View File

@ -107,6 +107,7 @@ import org.elasticsearch.indices.mapper.MapperRegistry;
import org.elasticsearch.test.DummyShardLock; import org.elasticsearch.test.DummyShardLock;
import org.elasticsearch.test.ESTestCase; import org.elasticsearch.test.ESTestCase;
import org.elasticsearch.test.IndexSettingsModule; import org.elasticsearch.test.IndexSettingsModule;
import org.elasticsearch.test.OldIndexUtils;
import org.elasticsearch.threadpool.TestThreadPool; import org.elasticsearch.threadpool.TestThreadPool;
import org.elasticsearch.threadpool.ThreadPool; import org.elasticsearch.threadpool.ThreadPool;
import org.hamcrest.MatcherAssert; import org.hamcrest.MatcherAssert;
@ -123,6 +124,7 @@ import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.Base64; import java.util.Base64;
import java.util.Collections; import java.util.Collections;
import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Locale; import java.util.Locale;
import java.util.Map; import java.util.Map;
@ -1790,7 +1792,6 @@ public class InternalEngineTests extends ESTestCase {
return new Mapping(Version.CURRENT, root, new MetadataFieldMapper[0], emptyMap()); return new Mapping(Version.CURRENT, root, new MetadataFieldMapper[0], emptyMap());
} }
@AwaitsFix(bugUrl = "https://github.com/elastic/elasticsearch/issues/21147")
public void testUpgradeOldIndex() throws IOException { public void testUpgradeOldIndex() throws IOException {
List<Path> indexes = new ArrayList<>(); List<Path> indexes = new ArrayList<>();
try (DirectoryStream<Path> stream = Files.newDirectoryStream(getBwcIndicesPath(), "index-*.zip")) { try (DirectoryStream<Path> stream = Files.newDirectoryStream(getBwcIndicesPath(), "index-*.zip")) {
@ -1812,18 +1813,19 @@ public class InternalEngineTests extends ESTestCase {
Path[] list = filterExtraFSFiles(FileSystemUtils.files(unzipDataDir)); Path[] list = filterExtraFSFiles(FileSystemUtils.files(unzipDataDir));
if (list.length != 1) { if (list.length != 1) {
throw new IllegalStateException("Backwards index must contain exactly one cluster but was " + list.length + " " + Arrays.toString(list)); throw new IllegalStateException("Backwards index must contain exactly one cluster but was " + list.length
+ " " + Arrays.toString(list));
} }
// the bwc scripts packs the indices under this path // the bwc scripts packs the indices under this path
Path src = list[0].resolve("nodes/0/indices/" + indexName); Path src = OldIndexUtils.getIndexDir(logger, indexName, indexFile.toString(), list[0]);
Path translog = list[0].resolve("nodes/0/indices/" + indexName).resolve("0").resolve("translog"); Path translog = src.resolve("0").resolve("translog");
assertTrue("[" + indexFile + "] missing index dir: " + src.toString(), Files.exists(src));
assertTrue("[" + indexFile + "] missing translog dir: " + translog.toString(), Files.exists(translog)); assertTrue("[" + indexFile + "] missing translog dir: " + translog.toString(), Files.exists(translog));
Path[] tlogFiles = filterExtraFSFiles(FileSystemUtils.files(translog)); Path[] tlogFiles = filterExtraFSFiles(FileSystemUtils.files(translog));
assertEquals(Arrays.toString(tlogFiles), tlogFiles.length, 2); // ckp & tlog assertEquals(Arrays.toString(tlogFiles), tlogFiles.length, 2); // ckp & tlog
Path tlogFile = tlogFiles[0].getFileName().toString().endsWith("tlog") ? tlogFiles[0] : tlogFiles[1]; Path tlogFile = tlogFiles[0].getFileName().toString().endsWith("tlog") ? tlogFiles[0] : tlogFiles[1];
final long size = Files.size(tlogFiles[0]); final long size = Files.size(tlogFile);
logger.debug("upgrading index {} file: {} size: {}", indexName, tlogFiles[0].getFileName(), size); logger.info("upgrading index {} file: {} size: {}", indexName, tlogFiles[0].getFileName(), size);
Directory directory = newFSDirectory(src.resolve("0").resolve("index")); Directory directory = newFSDirectory(src.resolve("0").resolve("index"));
Store store = createStore(directory); Store store = createStore(directory);
final int iters = randomIntBetween(0, 2); final int iters = randomIntBetween(0, 2);
@ -1967,7 +1969,7 @@ public class InternalEngineTests extends ESTestCase {
public static class TranslogHandler extends TranslogRecoveryPerformer { public static class TranslogHandler extends TranslogRecoveryPerformer {
private final DocumentMapper docMapper; private final MapperService mapperService;
public Mapping mappingUpdate = null; public Mapping mappingUpdate = null;
public final AtomicInteger recoveredOps = new AtomicInteger(0); public final AtomicInteger recoveredOps = new AtomicInteger(0);
@ -1975,7 +1977,6 @@ public class InternalEngineTests extends ESTestCase {
public TranslogHandler(String indexName, Logger logger) { public TranslogHandler(String indexName, Logger logger) {
super(new ShardId("test", "_na_", 0), null, logger); super(new ShardId("test", "_na_", 0), null, logger);
Settings settings = Settings.builder().put(IndexMetaData.SETTING_VERSION_CREATED, Version.CURRENT).build(); Settings settings = Settings.builder().put(IndexMetaData.SETTING_VERSION_CREATED, Version.CURRENT).build();
RootObjectMapper.Builder rootBuilder = new RootObjectMapper.Builder("test");
Index index = new Index(indexName, "_na_"); Index index = new Index(indexName, "_na_");
IndexSettings indexSettings = IndexSettingsModule.newIndexSettings(index, settings); IndexSettings indexSettings = IndexSettingsModule.newIndexSettings(index, settings);
IndexAnalyzers indexAnalyzers = null; IndexAnalyzers indexAnalyzers = null;
@ -1983,14 +1984,14 @@ public class InternalEngineTests extends ESTestCase {
indexAnalyzers = new IndexAnalyzers(indexSettings, defaultAnalyzer, defaultAnalyzer, defaultAnalyzer, Collections.emptyMap()); indexAnalyzers = new IndexAnalyzers(indexSettings, defaultAnalyzer, defaultAnalyzer, defaultAnalyzer, Collections.emptyMap());
SimilarityService similarityService = new SimilarityService(indexSettings, Collections.emptyMap()); SimilarityService similarityService = new SimilarityService(indexSettings, Collections.emptyMap());
MapperRegistry mapperRegistry = new IndicesModule(Collections.emptyList()).getMapperRegistry(); MapperRegistry mapperRegistry = new IndicesModule(Collections.emptyList()).getMapperRegistry();
MapperService mapperService = new MapperService(indexSettings, indexAnalyzers, similarityService, mapperRegistry, () -> null); mapperService = new MapperService(indexSettings, indexAnalyzers, similarityService, mapperRegistry, () -> null);
DocumentMapper.Builder b = new DocumentMapper.Builder(rootBuilder, mapperService);
this.docMapper = b.build(mapperService);
} }
@Override @Override
protected DocumentMapperForType docMapper(String type) { protected DocumentMapperForType docMapper(String type) {
return new DocumentMapperForType(docMapper, mappingUpdate); RootObjectMapper.Builder rootBuilder = new RootObjectMapper.Builder(type);
DocumentMapper.Builder b = new DocumentMapper.Builder(rootBuilder, mapperService);
return new DocumentMapperForType(b.build(mapperService), mappingUpdate);
} }
@Override @Override

View File

@ -124,12 +124,13 @@ public class OldIndexUtils {
return src; return src;
} else { } else {
final List<Path> indexFolders = new ArrayList<>(); final List<Path> indexFolders = new ArrayList<>();
try (DirectoryStream<Path> stream = Files.newDirectoryStream(dataDir.resolve("0/indices"))) { try (DirectoryStream<Path> stream = Files.newDirectoryStream(dataDir.resolve("0/indices"),
(p) -> p.getFileName().startsWith("extra") == false)) { // extra FS can break this...
for (final Path path : stream) { for (final Path path : stream) {
indexFolders.add(path); indexFolders.add(path);
} }
} }
assertThat(indexFolders.size(), equalTo(1)); assertThat(indexFolders.toString(), indexFolders.size(), equalTo(1));
final IndexMetaData indexMetaData = IndexMetaData.FORMAT.loadLatestState(logger, indexFolders.get(0)); final IndexMetaData indexMetaData = IndexMetaData.FORMAT.loadLatestState(logger, indexFolders.get(0));
assertNotNull(indexMetaData); assertNotNull(indexMetaData);
assertThat(indexFolders.get(0).getFileName().toString(), equalTo(indexMetaData.getIndexUUID())); assertThat(indexFolders.get(0).getFileName().toString(), equalTo(indexMetaData.getIndexUUID()));