Skip to content

Commit 78681fb

Browse files
committed
Incorporating PR feedback
Signed-off-by: Kartik Ganesh <[email protected]>
1 parent 3567807 commit 78681fb

File tree

9 files changed

+98
-29
lines changed

9 files changed

+98
-29
lines changed

server/src/main/java/org/opensearch/common/lucene/Lucene.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ public static SegmentInfos readSegmentInfos(Directory directory) throws IOExcept
171171
* the latest index commit is opened via {@link DirectoryReader} by including a minimum supported
172172
* Lucene major version based on the minimum compatibility of the given {@link org.opensearch.Version}.
173173
*/
174-
public static SegmentInfos readSegmentInfosExtendedCompatbility(Directory directory, org.opensearch.Version minimumVersion)
174+
public static SegmentInfos readSegmentInfosExtendedCompatibility(Directory directory, org.opensearch.Version minimumVersion)
175175
throws IOException {
176176
// This list is sorted from oldest to latest
177177
List<IndexCommit> indexCommits = DirectoryReader.listCommits(directory);

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -758,8 +758,8 @@ public IndexSettings(final IndexMetadata indexMetadata, final Settings nodeSetti
758758
isRemoteTranslogStoreEnabled = settings.getAsBoolean(IndexMetadata.SETTING_REMOTE_TRANSLOG_STORE_ENABLED, false);
759759
isRemoteSnapshot = IndexModule.Type.REMOTE_SNAPSHOT.match(this);
760760
if (isRemoteSnapshot) {
761-
Integer minVersion = settings.getAsInt(SEARCHABLE_SNAPSHOT_MINIMUM_VERSION.getKey(), 0);
762-
if (minVersion > 0) {
761+
Integer minVersion = settings.getAsInt(SEARCHABLE_SNAPSHOT_MINIMUM_VERSION.getKey(), Version.V_EMPTY_ID);
762+
if (minVersion > Version.V_EMPTY_ID) {
763763
extendedCompatibilitySnapshotVersion = LegacyESVersion.fromId(minVersion);
764764
}
765765
}

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ public ReadOnlyEngine(
151151
if (this.minimumSupportedVersion == null) {
152152
this.lastCommittedSegmentInfos = Lucene.readSegmentInfos(directory);
153153
} else {
154-
this.lastCommittedSegmentInfos = Lucene.readSegmentInfosExtendedCompatbility(directory, this.minimumSupportedVersion);
154+
this.lastCommittedSegmentInfos = Lucene.readSegmentInfosExtendedCompatibility(directory, this.minimumSupportedVersion);
155155
}
156156
if (seqNoStats == null) {
157157
seqNoStats = buildSeqNoStats(config, lastCommittedSegmentInfos);

server/src/main/java/org/opensearch/index/shard/IndexShard.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -2042,7 +2042,7 @@ private boolean assertSequenceNumbersInCommit() throws IOException {
20422042
final Map<String, String> userData;
20432043
if (indexSettings.isRemoteSnapshot() && indexSettings.getExtendedCompatibilitySnapshotVersion() != null) {
20442044
// Inefficient method to support reading old Lucene indexes
2045-
userData = Lucene.readSegmentInfosExtendedCompatbility(
2045+
userData = Lucene.readSegmentInfosExtendedCompatibility(
20462046
store.directory(),
20472047
indexSettings.getExtendedCompatibilitySnapshotVersion()
20482048
).getUserData();

server/src/main/java/org/opensearch/index/store/Store.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -263,7 +263,7 @@ private static SegmentInfos readSegmentsInfo(IndexCommit commit, Directory direc
263263
private static SegmentInfos readSegmentInfosExtendedCompatbility(Directory directory, org.opensearch.Version minimumVersion)
264264
throws IOException {
265265
try {
266-
return Lucene.readSegmentInfosExtendedCompatbility(directory, minimumVersion);
266+
return Lucene.readSegmentInfosExtendedCompatibility(directory, minimumVersion);
267267
} catch (EOFException eof) {
268268
// TODO this should be caught by lucene - EOF is almost certainly an index corruption
269269
throw new CorruptIndexException("Read past EOF while reading segment infos", "<latest-commit>", eof);

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

+9-20
Original file line numberDiff line numberDiff line change
@@ -888,26 +888,15 @@ private EngineFactory getEngineFactory(final IndexSettings idxSettings) {
888888
return new NRTReplicationEngineFactory();
889889
}
890890
if (idxSettings.isRemoteSnapshot()) {
891-
if (idxSettings.getExtendedCompatibilitySnapshotVersion() != null) {
892-
return config -> new ReadOnlyEngine(
893-
config,
894-
new SeqNoStats(0, 0, 0),
895-
new TranslogStats(),
896-
true,
897-
Function.identity(),
898-
false,
899-
idxSettings.getExtendedCompatibilitySnapshotVersion()
900-
);
901-
} else {
902-
return config -> new ReadOnlyEngine(
903-
config,
904-
new SeqNoStats(0, 0, 0),
905-
new TranslogStats(),
906-
true,
907-
Function.identity(),
908-
false
909-
);
910-
}
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+
);
911900
}
912901
return new InternalEngineFactory();
913902
} else if (engineFactories.size() == 1) {

server/src/test/java/org/opensearch/common/lucene/LuceneTests.java

+25-2
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,10 @@
3131

3232
package org.opensearch.common.lucene;
3333

34+
import org.apache.lucene.document.LatLonPoint;
35+
import org.apache.lucene.index.IndexCommit;
3436
import org.apache.lucene.index.IndexFormatTooOldException;
37+
import org.apache.lucene.index.StandardDirectoryReader;
3538
import org.apache.lucene.tests.analysis.MockAnalyzer;
3639
import org.apache.lucene.analysis.core.KeywordAnalyzer;
3740
import org.apache.lucene.document.Document;
@@ -76,6 +79,7 @@
7679
import org.apache.lucene.util.Bits;
7780
import org.apache.lucene.util.BytesRef;
7881
import org.opensearch.LegacyESVersion;
82+
import org.opensearch.Version;
7983
import org.opensearch.common.collect.Tuple;
8084
import org.opensearch.common.io.stream.NamedWriteableRegistry;
8185
import org.opensearch.core.internal.io.IOUtils;
@@ -372,15 +376,34 @@ public void testNumDocs() throws IOException {
372376
dir.close();
373377
}
374378

375-
public void testReadAnySegmentInfos() throws IOException {
379+
/**
380+
* Tests whether old segments are readable and queryable based on the data documented
381+
* in the README <a href="file:../../../../../resources/indices/bwc/testIndex-6.3.0.md">here</a>.
382+
*
383+
* @throws IOException
384+
*/
385+
public void testReadSegmentInfosExtendedCompatibility() throws IOException {
376386
final String pathToTestIndex = "/indices/bwc/testIndex-6.3.0.zip";
387+
final Version minVersion = LegacyESVersion.fromId(6000099);
377388
Path tmp = createTempDir();
378389
TestUtil.unzip(getClass().getResourceAsStream(pathToTestIndex), tmp);
379390
MockDirectoryWrapper dir = newMockFSDirectory(tmp);
380391
// The standard API will throw an exception
381392
expectThrows(IndexFormatTooOldException.class, () -> Lucene.readSegmentInfos(dir));
382-
SegmentInfos si = Lucene.readSegmentInfosExtendedCompatbility(dir, LegacyESVersion.fromId(6000099));
393+
SegmentInfos si = Lucene.readSegmentInfosExtendedCompatibility(dir, minVersion);
383394
assertEquals(1, Lucene.getNumDocs(si));
395+
IndexCommit indexCommit = Lucene.getIndexCommit(si, dir);
396+
// uses the "expert" Lucene API
397+
StandardDirectoryReader reader = (StandardDirectoryReader) DirectoryReader.open(
398+
indexCommit,
399+
minVersion.minimumIndexCompatibilityVersion().luceneVersion.major,
400+
null
401+
);
402+
IndexSearcher searcher = newSearcher(reader);
403+
// radius too small, should get no results
404+
assertFalse(Lucene.exists(searcher, LatLonPoint.newDistanceQuery("testLocation", 48.57532, -112.87695, 2)));
405+
assertTrue(Lucene.exists(searcher, LatLonPoint.newDistanceQuery("testLocation", 48.57532, -112.87695, 20000)));
406+
reader.close();
384407
dir.close();
385408
}
386409

server/src/test/java/org/opensearch/index/IndexSettingsTests.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -961,7 +961,7 @@ public void testExtendedCompatibilityVersionForRemoteSnapshot() {
961961
assertEquals(expected, settings.getExtendedCompatibilitySnapshotVersion());
962962
}
963963

964-
public void testExtendedCompatibilityVersionForNonSnapshot() {
964+
public void testExtendedCompatibilityVersionForNonRemoteSnapshot() {
965965
IndexMetadata metadata = newIndexMeta(
966966
"index",
967967
Settings.builder()
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
# README for _testIndex-6.3.0.zip_
2+
3+
This zip file holds a Lucene index created using ElasticSearch 6.3.0.
4+
It was created by running the underlying commands against a single-node cluster,
5+
then compressing the contents of the underlying Lucene index directory i.e.
6+
the files under `<elasticsearch-root>/data/nodes/0/indices/<index-uuid>/0/index`.
7+
The index contains one document.
8+
9+
## Commands
10+
11+
```
12+
curl -X PUT -H 'Content-Type: application/json' 'localhost:9200/testindex?pretty' -d'
13+
{
14+
"settings": {
15+
"number_of_shards": 1,
16+
"number_of_replicas": 0
17+
},
18+
"mappings": {
19+
"testData": {
20+
"properties": {
21+
"id": { "type": "keyword" },
22+
"isTestData": { "type": "boolean" },
23+
"testNum": { "type": "short" },
24+
"testRange": {"type": "integer_range" },
25+
"testMessage": {
26+
"type": "text",
27+
"fields": {
28+
"length": {
29+
"type": "token_count",
30+
"analyzer": "standard"
31+
}
32+
}
33+
},
34+
"testBlob": { "type": "binary", "index": false },
35+
"testDate": { "type": "date" },
36+
"testLocation": { "type": "geo_point"}
37+
}
38+
}
39+
}
40+
}'
41+
42+
curl -X POST "localhost:9200/testindex/testData/?pretty" -H 'Content-Type: application/json' -d'
43+
{
44+
"id": "testData1",
45+
"isTestData": true,
46+
"testNum": 99,
47+
"testRange": {
48+
"gte": 0,
49+
"lte": 100
50+
},
51+
"testMessage": "The OpenSearch Project",
52+
"testBlob": "VGhlIE9wZW5TZWFyY2ggUHJvamVjdA==",
53+
"testDate": "1970-01-02",
54+
"testLocation": "48.553532,-113.022881"
55+
}
56+
'
57+
```

0 commit comments

Comments
 (0)