3232package org .opensearch .index .engine ;
3333
3434import org .apache .lucene .index .DirectoryReader ;
35+ import org .apache .lucene .index .IndexFormatTooOldException ;
3536import org .apache .lucene .index .IndexReader ;
3637import org .apache .lucene .tests .util .LuceneTestCase ;
3738import org .apache .lucene .tests .util .TestUtil ;
38- import org .opensearch .LegacyESVersion ;
3939import org .opensearch .Version ;
40+ import org .opensearch .cluster .metadata .IndexMetadata ;
4041import org .opensearch .common .bytes .BytesArray ;
4142import org .opensearch .common .lucene .index .OpenSearchDirectoryReader ;
43+ import org .opensearch .common .settings .Settings ;
44+ import org .opensearch .common .util .FeatureFlags ;
4245import org .opensearch .core .internal .io .IOUtils ;
46+ import org .opensearch .index .IndexModule ;
47+ import org .opensearch .index .IndexSettings ;
4348import org .opensearch .index .mapper .ParsedDocument ;
4449import org .opensearch .index .seqno .SeqNoStats ;
4550import org .opensearch .index .seqno .SequenceNumbers ;
4651import org .opensearch .index .store .Store ;
4752import org .opensearch .index .translog .TranslogStats ;
53+ import org .opensearch .test .FeatureFlagSetter ;
54+ import org .opensearch .test .IndexSettingsModule ;
4855
4956import java .io .IOException ;
57+ import java .io .UncheckedIOException ;
5058import java .nio .file .Path ;
5159import java .util .List ;
5260import java .util .concurrent .atomic .AtomicLong ;
@@ -231,7 +239,33 @@ public void testReadOnly() throws IOException {
231239 }
232240 }
233241
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 {
235269 IOUtils .close (engine , store );
236270 // The index has one document in it, so the checkpoint cannot be NO_OPS_PERFORMED
237271 final AtomicLong globalCheckpoint = new AtomicLong (0 );
@@ -240,18 +274,10 @@ public void testReadOldIndices() throws IOException {
240274 TestUtil .unzip (getClass ().getResourceAsStream (pathToTestIndex ), tmp );
241275 try (Store store = createStore (newFSDirectory (tmp ))) {
242276 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 ());
255281 }
256282 }
257283 }
0 commit comments