|
35 | 35 | import org.apache.logging.log4j.LogManager; |
36 | 36 | import org.apache.logging.log4j.Logger; |
37 | 37 | import org.apache.lucene.codecs.Codec; |
38 | | -import org.apache.lucene.codecs.StoredFieldsWriter; |
| 38 | +import org.apache.lucene.codecs.lucene90.Lucene90StoredFieldsFormat; |
| 39 | +import org.apache.lucene.codecs.lucene90.Lucene90StoredFieldsFormatComparator; |
39 | 40 | import org.apache.lucene.index.FilterMergePolicy; |
40 | 41 | import org.apache.lucene.index.IndexWriter; |
41 | 42 | import org.apache.lucene.index.MergePolicy; |
42 | 43 | import org.apache.lucene.index.SegmentCommitInfo; |
43 | 44 | import org.apache.lucene.index.SegmentInfos; |
44 | | -import org.apache.lucene.store.ByteBuffersDirectory; |
45 | | -import org.apache.lucene.store.IOContext; |
46 | 45 | import org.opensearch.Version; |
47 | 46 |
|
48 | 47 | import java.io.IOException; |
@@ -112,18 +111,13 @@ private boolean shouldUpgrade(SegmentCommitInfo info) { |
112 | 111 | } |
113 | 112 |
|
114 | 113 | if (info.info.getAttributes() != null) { |
115 | | - // Only way to compare Codec.mode(BEST_SPEED or BEST_COMPRESSION) is try to create fields writer |
116 | | - // and catch an IllegalStateException if they are different, and ignore others exceptions |
117 | | - try { |
118 | | - StoredFieldsWriter writer = actualCodec.storedFieldsFormat().fieldsWriter(new ByteBuffersDirectory(), info.info, IOContext.DEFAULT); |
119 | | - writer.close(); |
120 | | - } catch (IllegalStateException e) { |
121 | | - // fieldsWriter throw an exception if previous mode not equal to current |
122 | | - logger.debug("Received expected IllegalStateException", e); |
123 | | - return true; |
124 | | - } catch (Exception e) { |
125 | | - // Most of the time it will be java.nio.file.FileAlreadyExistsException, which means codec mode same as should be, |
126 | | - // otherwise it is something wrong and will be processed somewhere else |
| 114 | + if (info.info.getCodec().storedFieldsFormat() instanceof Lucene90StoredFieldsFormat |
| 115 | + && actualCodec.storedFieldsFormat() instanceof Lucene90StoredFieldsFormat) { |
| 116 | + var current = (Lucene90StoredFieldsFormat) info.info.getCodec().storedFieldsFormat(); |
| 117 | + var target = (Lucene90StoredFieldsFormat) actualCodec.storedFieldsFormat(); |
| 118 | + if (!Lucene90StoredFieldsFormatComparator.equal(current, target)) { |
| 119 | + return true; |
| 120 | + } |
127 | 121 | } |
128 | 122 | } |
129 | 123 |
|
|
0 commit comments