Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0 and the Server Side Public License, v 1; you may not use this file except
* in compliance with, at your election, the Elastic License 2.0 or the Server
* Side Public License, v 1.
*/

package org.elasticsearch.index.store;

import org.elasticsearch.Assertions;
import org.elasticsearch.core.SuppressForbidden;
import org.elasticsearch.test.ESTestCase;

import static org.hamcrest.Matchers.containsString;

public class LuceneFilesExtensionsTests extends ESTestCase {

public void testUnknownFileExtension() {
if (Assertions.ENABLED) {
AssertionError e = expectThrows(AssertionError.class, () -> LuceneFilesExtensions.fromExtension("abc"));
assertThat(e.getMessage(), containsString("unknown Lucene file extension [abc]"));

setEsAllowUnknownLuceneFileExtensions("true");
try {
assertNull(LuceneFilesExtensions.fromExtension("abc"));
} finally {
setEsAllowUnknownLuceneFileExtensions(null);
}
} else {
assertNull(LuceneFilesExtensions.fromExtension("abc"));
}
}

@SuppressForbidden(reason = "set or clear system property es.allow_unknown_lucene_file_extensions")
public void setEsAllowUnknownLuceneFileExtensions(final String value) {
if (value == null) {
System.clearProperty("es.allow_unknown_lucene_file_extensions");
} else {
System.setProperty("es.allow_unknown_lucene_file_extensions", value);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,16 @@ public enum LuceneFilesExtensions {
// Lucene 9.0 indexed vectors metadata
VEM("vem","Vector Metadata", true, false);

/**
* Allow plugin developers of custom codecs to opt out of the assertion in {@link #fromExtension}
* that checks that all encountered file extensions are known to this class.
* In the future, we would like to add a proper plugin extension point for this.
*/
private static boolean allowUnknownLuceneFileExtensions() {
return Boolean.parseBoolean(
System.getProperty("es.allow_unknown_lucene_file_extensions", "false"));
}

/**
* Lucene file's extension.
*/
Expand Down Expand Up @@ -128,7 +138,7 @@ public boolean shouldMmap() {
public static LuceneFilesExtensions fromExtension(String ext) {
if (ext != null && ext.isEmpty() == false) {
final LuceneFilesExtensions extension = extensions.get(ext);
assert extension != null: "unknown Lucene file extension [" + ext + ']';
assert allowUnknownLuceneFileExtensions() || extension != null: "unknown Lucene file extension [" + ext + ']';
return extension;
}
return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,6 @@ public void onFailure(Exception e) {
*/
public ByteRange computeBlobCacheByteRange(String fileName, long fileLength, ByteSizeValue maxMetadataLength) {
final LuceneFilesExtensions fileExtension = LuceneFilesExtensions.fromExtension(IndexFileNames.getExtension(fileName));
assert fileExtension != null : "unknown Lucene file extension [" + fileName + "] - should it be considered a metadata file?";

if (useLegacyCachedBlobSizes()) {
if (fileLength <= ByteSizeUnit.KB.toBytes(8L)) {
Expand Down