Skip to content

Commit 74c25bd

Browse files
committed
Incorporating PR feedback from @mch2
Signed-off-by: Kartik Ganesh <[email protected]>
1 parent b95e49c commit 74c25bd

File tree

4 files changed

+47
-50
lines changed

4 files changed

+47
-50
lines changed

server/src/main/java/org/opensearch/index/IndexSettings.java

+2
Original file line numberDiff line numberDiff line change
@@ -756,6 +756,8 @@ public IndexSettings(final IndexMetadata indexMetadata, final Settings nodeSetti
756756

757757
if (isRemoteSnapshot && FeatureFlags.isEnabled(SEARCHABLE_SNAPSHOT_EXTENDED_COMPATIBILITY)) {
758758
extendedCompatibilitySnapshotVersion = SEARCHABLE_SNAPSHOT_EXTENDED_COMPATIBILITY_MINIMUM_VERSION;
759+
} else {
760+
extendedCompatibilitySnapshotVersion = Version.CURRENT.minimumIndexCompatibilityVersion();
759761
}
760762
this.searchThrottled = INDEX_SEARCH_THROTTLED.get(settings);
761763
this.queryStringLenient = QUERY_STRING_LENIENT_SETTING.get(settings);

server/src/main/java/org/opensearch/index/engine/ReadOnlyEngine.java

+4-27
Original file line numberDiff line numberDiff line change
@@ -97,28 +97,6 @@ public class ReadOnlyEngine extends Engine {
9797

9898
protected volatile TranslogStats translogStats;
9999

100-
/**
101-
* Wrapper constructor that turns off support for reading old indices.
102-
*/
103-
public ReadOnlyEngine(
104-
EngineConfig config,
105-
SeqNoStats seqNoStats,
106-
TranslogStats translogStats,
107-
boolean obtainLock,
108-
Function<DirectoryReader, DirectoryReader> readerWrapperFunction,
109-
boolean requireCompleteHistory
110-
) {
111-
this(
112-
config,
113-
seqNoStats,
114-
translogStats,
115-
obtainLock,
116-
readerWrapperFunction,
117-
requireCompleteHistory,
118-
Version.CURRENT.minimumIndexCompatibilityVersion()
119-
);
120-
}
121-
122100
/**
123101
* Creates a new ReadOnlyEngine. This ctor can also be used to open a read-only engine on top of an already opened
124102
* read-write engine. It allows to optionally obtain the writer locks for the shard which would time-out if another
@@ -131,20 +109,19 @@ public ReadOnlyEngine(
131109
* the lock won't be obtained
132110
* @param readerWrapperFunction allows to wrap the index-reader for this engine.
133111
* @param requireCompleteHistory indicates whether this engine permits an incomplete history (i.e. LCP &lt; MSN)
134-
* @param minimumSupportedVersion for extended backward compatibility use-cases, the minimum {@link Version} this engine is allowed to read
135112
*/
136113
public ReadOnlyEngine(
137114
EngineConfig config,
138115
SeqNoStats seqNoStats,
139116
TranslogStats translogStats,
140117
boolean obtainLock,
141118
Function<DirectoryReader, DirectoryReader> readerWrapperFunction,
142-
boolean requireCompleteHistory,
143-
Version minimumSupportedVersion
119+
boolean requireCompleteHistory
144120
) {
145121
super(config);
146122
this.requireCompleteHistory = requireCompleteHistory;
147-
this.minimumSupportedVersion = minimumSupportedVersion;
123+
// fetch the minimum Version for extended backward compatibility use-cases
124+
this.minimumSupportedVersion = config.getIndexSettings().getExtendedCompatibilitySnapshotVersion();
148125
try {
149126
Store store = config.getStore();
150127
store.incRef();
@@ -263,7 +240,7 @@ protected DirectoryReader open(IndexCommit commit) throws IOException {
263240
}
264241

265242
private boolean isExtendedCompatibility() {
266-
return this.minimumSupportedVersion.before(Version.CURRENT.minimumIndexCompatibilityVersion());
243+
return Version.CURRENT.minimumIndexCompatibilityVersion().onOrAfter(this.minimumSupportedVersion);
267244
}
268245

269246
@Override

server/src/main/java/org/opensearch/indices/IndicesService.java

+1-9
Original file line numberDiff line numberDiff line change
@@ -888,15 +888,7 @@ private EngineFactory getEngineFactory(final IndexSettings idxSettings) {
888888
return new NRTReplicationEngineFactory();
889889
}
890890
if (idxSettings.isRemoteSnapshot()) {
891-
return config -> new ReadOnlyEngine(
892-
config,
893-
new SeqNoStats(0, 0, 0),
894-
new TranslogStats(),
895-
true,
896-
Function.identity(),
897-
false,
898-
idxSettings.getExtendedCompatibilitySnapshotVersion()
899-
);
891+
return config -> new ReadOnlyEngine(config, new SeqNoStats(0, 0, 0), new TranslogStats(), true, Function.identity(), false);
900892
}
901893
return new InternalEngineFactory();
902894
} else if (engineFactories.size() == 1) {

server/src/test/java/org/opensearch/index/engine/ReadOnlyEngineTests.java

+40-14
Original file line numberDiff line numberDiff line change
@@ -32,21 +32,29 @@
3232
package org.opensearch.index.engine;
3333

3434
import org.apache.lucene.index.DirectoryReader;
35+
import org.apache.lucene.index.IndexFormatTooOldException;
3536
import org.apache.lucene.index.IndexReader;
3637
import org.apache.lucene.tests.util.LuceneTestCase;
3738
import org.apache.lucene.tests.util.TestUtil;
38-
import org.opensearch.LegacyESVersion;
3939
import org.opensearch.Version;
40+
import org.opensearch.cluster.metadata.IndexMetadata;
4041
import org.opensearch.common.bytes.BytesArray;
4142
import org.opensearch.common.lucene.index.OpenSearchDirectoryReader;
43+
import org.opensearch.common.settings.Settings;
44+
import org.opensearch.common.util.FeatureFlags;
4245
import org.opensearch.core.internal.io.IOUtils;
46+
import org.opensearch.index.IndexModule;
47+
import org.opensearch.index.IndexSettings;
4348
import org.opensearch.index.mapper.ParsedDocument;
4449
import org.opensearch.index.seqno.SeqNoStats;
4550
import org.opensearch.index.seqno.SequenceNumbers;
4651
import org.opensearch.index.store.Store;
4752
import org.opensearch.index.translog.TranslogStats;
53+
import org.opensearch.test.FeatureFlagSetter;
54+
import org.opensearch.test.IndexSettingsModule;
4855

4956
import java.io.IOException;
57+
import java.io.UncheckedIOException;
5058
import java.nio.file.Path;
5159
import java.util.List;
5260
import 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

Comments
 (0)