Skip to content

Commit 632901f

Browse files
authored
Allow opting out of known Lucene file extensions check (#74316)
Allows plugin developers of custom codecs to opt out of the assertion in LuceneFilesExtensionsTests that checks that all encountered Lucene file extensions are known to this class. In the future, we would like to add a proper plugin extension point for this. Relates #74150
1 parent 05d3316 commit 632901f

File tree

3 files changed

+54
-2
lines changed

3 files changed

+54
-2
lines changed
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
/*
2+
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
3+
* or more contributor license agreements. Licensed under the Elastic License
4+
* 2.0 and the Server Side Public License, v 1; you may not use this file except
5+
* in compliance with, at your election, the Elastic License 2.0 or the Server
6+
* Side Public License, v 1.
7+
*/
8+
9+
package org.elasticsearch.index.store;
10+
11+
import org.elasticsearch.Assertions;
12+
import org.elasticsearch.core.SuppressForbidden;
13+
import org.elasticsearch.test.ESTestCase;
14+
15+
import static org.hamcrest.Matchers.containsString;
16+
17+
public class LuceneFilesExtensionsTests extends ESTestCase {
18+
19+
public void testUnknownFileExtension() {
20+
if (Assertions.ENABLED) {
21+
AssertionError e = expectThrows(AssertionError.class, () -> LuceneFilesExtensions.fromExtension("abc"));
22+
assertThat(e.getMessage(), containsString("unknown Lucene file extension [abc]"));
23+
24+
setEsAllowUnknownLuceneFileExtensions("true");
25+
try {
26+
assertNull(LuceneFilesExtensions.fromExtension("abc"));
27+
} finally {
28+
setEsAllowUnknownLuceneFileExtensions(null);
29+
}
30+
} else {
31+
assertNull(LuceneFilesExtensions.fromExtension("abc"));
32+
}
33+
}
34+
35+
@SuppressForbidden(reason = "set or clear system property es.allow_unknown_lucene_file_extensions")
36+
public void setEsAllowUnknownLuceneFileExtensions(final String value) {
37+
if (value == null) {
38+
System.clearProperty("es.allow_unknown_lucene_file_extensions");
39+
} else {
40+
System.setProperty("es.allow_unknown_lucene_file_extensions", value);
41+
}
42+
}
43+
}

server/src/main/java/org/elasticsearch/index/store/LuceneFilesExtensions.java

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,16 @@ public enum LuceneFilesExtensions {
7171
// Lucene 9.0 indexed vectors metadata
7272
VEM("vem","Vector Metadata", true, false);
7373

74+
/**
75+
* Allow plugin developers of custom codecs to opt out of the assertion in {@link #fromExtension}
76+
* that checks that all encountered file extensions are known to this class.
77+
* In the future, we would like to add a proper plugin extension point for this.
78+
*/
79+
private static boolean allowUnknownLuceneFileExtensions() {
80+
return Boolean.parseBoolean(
81+
System.getProperty("es.allow_unknown_lucene_file_extensions", "false"));
82+
}
83+
7484
/**
7585
* Lucene file's extension.
7686
*/
@@ -128,7 +138,7 @@ public boolean shouldMmap() {
128138
public static LuceneFilesExtensions fromExtension(String ext) {
129139
if (ext != null && ext.isEmpty() == false) {
130140
final LuceneFilesExtensions extension = extensions.get(ext);
131-
assert extension != null: "unknown Lucene file extension [" + ext + ']';
141+
assert allowUnknownLuceneFileExtensions() || extension != null: "unknown Lucene file extension [" + ext + ']';
132142
return extension;
133143
}
134144
return null;

x-pack/plugin/searchable-snapshots/src/main/java/org/elasticsearch/xpack/searchablesnapshots/cache/blob/BlobStoreCacheService.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -260,7 +260,6 @@ public void onFailure(Exception e) {
260260
*/
261261
public ByteRange computeBlobCacheByteRange(String fileName, long fileLength, ByteSizeValue maxMetadataLength) {
262262
final LuceneFilesExtensions fileExtension = LuceneFilesExtensions.fromExtension(IndexFileNames.getExtension(fileName));
263-
assert fileExtension != null : "unknown Lucene file extension [" + fileName + "] - should it be considered a metadata file?";
264263

265264
if (useLegacyCachedBlobSizes()) {
266265
if (fileLength <= ByteSizeUnit.KB.toBytes(8L)) {

0 commit comments

Comments
 (0)