32
32
package org .opensearch .index .engine ;
33
33
34
34
import org .apache .lucene .index .DirectoryReader ;
35
+ import org .apache .lucene .index .IndexFormatTooOldException ;
35
36
import org .apache .lucene .index .IndexReader ;
36
37
import org .apache .lucene .tests .util .LuceneTestCase ;
37
38
import org .apache .lucene .tests .util .TestUtil ;
38
- import org .opensearch .LegacyESVersion ;
39
39
import org .opensearch .Version ;
40
+ import org .opensearch .cluster .metadata .IndexMetadata ;
40
41
import org .opensearch .common .bytes .BytesArray ;
41
42
import org .opensearch .common .lucene .index .OpenSearchDirectoryReader ;
43
+ import org .opensearch .common .settings .Settings ;
44
+ import org .opensearch .common .util .FeatureFlags ;
42
45
import org .opensearch .core .internal .io .IOUtils ;
46
+ import org .opensearch .index .IndexModule ;
47
+ import org .opensearch .index .IndexSettings ;
43
48
import org .opensearch .index .mapper .ParsedDocument ;
44
49
import org .opensearch .index .seqno .SeqNoStats ;
45
50
import org .opensearch .index .seqno .SequenceNumbers ;
46
51
import org .opensearch .index .store .Store ;
47
52
import org .opensearch .index .translog .TranslogStats ;
53
+ import org .opensearch .test .FeatureFlagSetter ;
54
+ import org .opensearch .test .IndexSettingsModule ;
48
55
49
56
import java .io .IOException ;
57
+ import java .io .UncheckedIOException ;
50
58
import java .nio .file .Path ;
51
59
import java .util .List ;
52
60
import java .util .concurrent .atomic .AtomicLong ;
@@ -231,7 +239,33 @@ public void testReadOnly() throws IOException {
231
239
}
232
240
}
233
241
234
- public void testReadOldIndices () throws IOException {
242
+ public void testReadOldIndices () throws Exception {
243
+ IOUtils .close (engine , store );
244
+ // The index has one document in it, so the checkpoint cannot be NO_OPS_PERFORMED
245
+ final AtomicLong globalCheckpoint = new AtomicLong (0 );
246
+ final String pathToTestIndex = "/indices/bwc/es-6.3.0/testIndex-es-6.3.0.zip" ;
247
+ Path tmp = createTempDir ();
248
+ TestUtil .unzip (getClass ().getResourceAsStream (pathToTestIndex ), tmp );
249
+ try (FeatureFlagSetter f = FeatureFlagSetter .set (FeatureFlags .SEARCHABLE_SNAPSHOT_EXTENDED_COMPATIBILITY )) {
250
+ final IndexSettings indexSettings = IndexSettingsModule .newIndexSettings (
251
+ "index" ,
252
+ Settings .builder ()
253
+ .put (IndexMetadata .SETTING_VERSION_CREATED , org .opensearch .Version .CURRENT )
254
+ .put (IndexModule .INDEX_STORE_TYPE_SETTING .getKey (), IndexModule .Type .REMOTE_SNAPSHOT .getSettingsKey ())
255
+ .build ()
256
+ );
257
+ try (Store store = createStore (newFSDirectory (tmp ))) {
258
+ EngineConfig config = config (indexSettings , store , createTempDir (), newMergePolicy (), null , null , globalCheckpoint ::get );
259
+ try (
260
+ ReadOnlyEngine readOnlyEngine = new ReadOnlyEngine (config , null , new TranslogStats (), true , Function .identity (), true )
261
+ ) {
262
+ assertVisibleCount (readOnlyEngine , 1 , false );
263
+ }
264
+ }
265
+ }
266
+ }
267
+
268
+ public void testReadOldIndicesFailure () throws IOException {
235
269
IOUtils .close (engine , store );
236
270
// The index has one document in it, so the checkpoint cannot be NO_OPS_PERFORMED
237
271
final AtomicLong globalCheckpoint = new AtomicLong (0 );
@@ -240,18 +274,10 @@ public void testReadOldIndices() throws IOException {
240
274
TestUtil .unzip (getClass ().getResourceAsStream (pathToTestIndex ), tmp );
241
275
try (Store store = createStore (newFSDirectory (tmp ))) {
242
276
EngineConfig config = config (defaultSettings , store , createTempDir (), newMergePolicy (), null , null , globalCheckpoint ::get );
243
- try (
244
- ReadOnlyEngine readOnlyEngine = new ReadOnlyEngine (
245
- config ,
246
- null ,
247
- new TranslogStats (),
248
- true ,
249
- Function .identity (),
250
- true ,
251
- LegacyESVersion .fromId (6000099 )
252
- )
253
- ) {
254
- assertVisibleCount (readOnlyEngine , 1 , false );
277
+ try {
278
+ new ReadOnlyEngine (config , null , new TranslogStats (), true , Function .identity (), true );
279
+ } catch (UncheckedIOException e ) {
280
+ assertEquals (IndexFormatTooOldException .class , e .getCause ().getClass ());
255
281
}
256
282
}
257
283
}
0 commit comments