|
67 | 67 | import org.apache.lucene.util.BytesRef; |
68 | 68 | import org.apache.lucene.util.FixedBitSet; |
69 | 69 | import org.apache.lucene.util.IOUtils; |
70 | | -import org.apache.lucene.util.TestUtil; |
71 | 70 | import org.elasticsearch.ElasticsearchException; |
72 | 71 | import org.elasticsearch.Version; |
73 | 72 | import org.elasticsearch.action.index.IndexRequest; |
|
83 | 82 | import org.elasticsearch.common.bytes.BytesArray; |
84 | 83 | import org.elasticsearch.common.bytes.BytesReference; |
85 | 84 | import org.elasticsearch.common.collect.Tuple; |
86 | | -import org.elasticsearch.common.io.FileSystemUtils; |
87 | 85 | import org.elasticsearch.common.logging.Loggers; |
88 | 86 | import org.elasticsearch.common.lucene.Lucene; |
89 | 87 | import org.elasticsearch.common.lucene.uid.Versions; |
|
120 | 118 | import org.elasticsearch.index.mapper.SeqNoFieldMapper; |
121 | 119 | import org.elasticsearch.index.mapper.SourceFieldMapper; |
122 | 120 | import org.elasticsearch.index.mapper.Uid; |
123 | | -import org.elasticsearch.index.mapper.UidFieldMapper; |
124 | 121 | import org.elasticsearch.index.seqno.SequenceNumbers; |
125 | 122 | import org.elasticsearch.index.seqno.SequenceNumbersService; |
126 | 123 | import org.elasticsearch.index.shard.IndexSearcherWrapper; |
|
138 | 135 | import org.elasticsearch.test.DummyShardLock; |
139 | 136 | import org.elasticsearch.test.ESTestCase; |
140 | 137 | import org.elasticsearch.test.IndexSettingsModule; |
141 | | -import org.elasticsearch.test.OldIndexUtils; |
142 | 138 | import org.elasticsearch.threadpool.TestThreadPool; |
143 | 139 | import org.elasticsearch.threadpool.ThreadPool; |
144 | 140 | import org.hamcrest.MatcherAssert; |
145 | 141 | import org.junit.After; |
146 | 142 | import org.junit.Before; |
147 | 143 |
|
148 | 144 | import java.io.IOException; |
149 | | -import java.io.InputStream; |
150 | 145 | import java.io.UncheckedIOException; |
151 | 146 | import java.nio.charset.Charset; |
152 | | -import java.nio.file.DirectoryStream; |
153 | 147 | import java.nio.file.Files; |
154 | 148 | import java.nio.file.Path; |
155 | 149 | import java.util.ArrayList; |
|
161 | 155 | import java.util.HashSet; |
162 | 156 | import java.util.LinkedHashMap; |
163 | 157 | import java.util.List; |
164 | | -import java.util.Locale; |
165 | 158 | import java.util.Map; |
166 | 159 | import java.util.Queue; |
167 | 160 | import java.util.Set; |
@@ -2592,93 +2585,6 @@ private Mapping dynamicUpdate() { |
2592 | 2585 | return new Mapping(Version.CURRENT, root, new MetadataFieldMapper[0], emptyMap()); |
2593 | 2586 | } |
2594 | 2587 |
|
2595 | | - public void testUpgradeOldIndex() throws IOException { |
2596 | | - List<Path> indexes = new ArrayList<>(); |
2597 | | - try (DirectoryStream<Path> stream = Files.newDirectoryStream(getBwcIndicesPath(), "index-*.zip")) { |
2598 | | - for (Path path : stream) { |
2599 | | - indexes.add(path); |
2600 | | - } |
2601 | | - } |
2602 | | - Collections.shuffle(indexes, random()); |
2603 | | - for (Path indexFile : indexes.subList(0, scaledRandomIntBetween(1, indexes.size() / 2))) { |
2604 | | - final String indexName = indexFile.getFileName().toString().replace(".zip", "").toLowerCase(Locale.ROOT); |
2605 | | - Path unzipDir = createTempDir(); |
2606 | | - Path unzipDataDir = unzipDir.resolve("data"); |
2607 | | - // decompress the index |
2608 | | - try (InputStream stream = Files.newInputStream(indexFile)) { |
2609 | | - TestUtil.unzip(stream, unzipDir); |
2610 | | - } |
2611 | | - // check it is unique |
2612 | | - assertTrue(Files.exists(unzipDataDir)); |
2613 | | - Path[] list = filterExtraFSFiles(FileSystemUtils.files(unzipDataDir)); |
2614 | | - |
2615 | | - if (list.length != 1) { |
2616 | | - throw new IllegalStateException("Backwards index must contain exactly one cluster but was " + list.length |
2617 | | - + " " + Arrays.toString(list)); |
2618 | | - } |
2619 | | - |
2620 | | - // the bwc scripts packs the indices under this path |
2621 | | - Path src = OldIndexUtils.getIndexDir(logger, indexName, indexFile.toString(), list[0]); |
2622 | | - Path translog = src.resolve("0").resolve("translog"); |
2623 | | - assertTrue("[" + indexFile + "] missing translog dir: " + translog.toString(), Files.exists(translog)); |
2624 | | - Path[] tlogFiles = filterExtraFSFiles(FileSystemUtils.files(translog)); |
2625 | | - assertEquals(Arrays.toString(tlogFiles), tlogFiles.length, 2); // ckp & tlog |
2626 | | - Path tlogFile = tlogFiles[0].getFileName().toString().endsWith("tlog") ? tlogFiles[0] : tlogFiles[1]; |
2627 | | - final long size = Files.size(tlogFile); |
2628 | | - logger.debug("upgrading index {} file: {} size: {}", indexName, tlogFiles[0].getFileName(), size); |
2629 | | - Directory directory = newFSDirectory(src.resolve("0").resolve("index")); |
2630 | | - final IndexMetaData indexMetaData = IndexMetaData.FORMAT.loadLatestState(logger, xContentRegistry(), src); |
2631 | | - final IndexSettings indexSettings = IndexSettingsModule.newIndexSettings(indexMetaData); |
2632 | | - final Store store = createStore(indexSettings, directory); |
2633 | | - final int iters = randomIntBetween(0, 2); |
2634 | | - int numDocs = -1; |
2635 | | - for (int i = 0; i < iters; i++) { // make sure we can restart on an upgraded index |
2636 | | - try (InternalEngine engine = createEngine(indexSettings, store, translog, newMergePolicy())) { |
2637 | | - try (Searcher searcher = engine.acquireSearcher("test")) { |
2638 | | - if (i > 0) { |
2639 | | - assertEquals(numDocs, searcher.reader().numDocs()); |
2640 | | - } |
2641 | | - TopDocs search = searcher.searcher().search(new MatchAllDocsQuery(), 1); |
2642 | | - numDocs = searcher.reader().numDocs(); |
2643 | | - assertTrue(search.totalHits > 1); |
2644 | | - } |
2645 | | - CommitStats commitStats = engine.commitStats(); |
2646 | | - Map<String, String> userData = commitStats.getUserData(); |
2647 | | - assertTrue("user data doesn't contain uuid", userData.containsKey(Translog.TRANSLOG_UUID_KEY)); |
2648 | | - assertTrue("user data doesn't contain generation key", userData.containsKey(Translog.TRANSLOG_GENERATION_KEY)); |
2649 | | - assertFalse("user data contains legacy marker", userData.containsKey("translog_id")); |
2650 | | - } |
2651 | | - } |
2652 | | - |
2653 | | - try (InternalEngine engine = createEngine(indexSettings, store, translog, newMergePolicy())) { |
2654 | | - if (numDocs == -1) { |
2655 | | - try (Searcher searcher = engine.acquireSearcher("test")) { |
2656 | | - numDocs = searcher.reader().numDocs(); |
2657 | | - } |
2658 | | - } |
2659 | | - final int numExtraDocs = randomIntBetween(1, 10); |
2660 | | - for (int i = 0; i < numExtraDocs; i++) { |
2661 | | - ParsedDocument doc = testParsedDocument("extra" + Integer.toString(i), null, testDocument(), new BytesArray("{}"), null); |
2662 | | - Term uid; |
2663 | | - if (indexMetaData.getCreationVersion().onOrAfter(Version.V_6_0_0_alpha1)) { |
2664 | | - uid = new Term(IdFieldMapper.NAME, doc.id()); |
2665 | | - } else { |
2666 | | - uid = new Term(UidFieldMapper.NAME, Uid.createUid(doc.type(), doc.id())); |
2667 | | - } |
2668 | | - Engine.Index firstIndexRequest = new Engine.Index(uid, doc, SequenceNumbersService.UNASSIGNED_SEQ_NO, 0, Versions.MATCH_DELETED, VersionType.INTERNAL, PRIMARY, System.nanoTime(), -1, false); |
2669 | | - Engine.IndexResult indexResult = engine.index(firstIndexRequest); |
2670 | | - assertThat(indexResult.getVersion(), equalTo(1L)); |
2671 | | - } |
2672 | | - engine.refresh("test"); |
2673 | | - try (Engine.Searcher searcher = engine.acquireSearcher("test")) { |
2674 | | - TopDocs topDocs = searcher.searcher().search(new MatchAllDocsQuery(), randomIntBetween(numDocs, numDocs + numExtraDocs)); |
2675 | | - assertThat(topDocs.totalHits, equalTo((long) numDocs + numExtraDocs)); |
2676 | | - } |
2677 | | - } |
2678 | | - IOUtils.close(store, directory); |
2679 | | - } |
2680 | | - } |
2681 | | - |
2682 | 2588 | private Path[] filterExtraFSFiles(Path[] files) { |
2683 | 2589 | List<Path> paths = new ArrayList<>(); |
2684 | 2590 | for (Path p : files) { |
|
0 commit comments