Преглед изворни кода

Remove completion postings format extension (#125253)

A while ago we introduced a completion postings format extension to eventually
be able to customize how completion FSTs are loaded. See #111494.

We have never leveraged this extension, and meanwhile Lucene is moving
to always load FSTs off-heap, and no longer allow on-heap.
See https://github.com/apache/lucene/pull/14364 .

This commit removes the SPI extension as it is no longer needed.
Luca Cavanna пре 7 месеци
родитељ
комит
8fdf44d708

+ 1 - 5
server/src/main/java/module-info.java

@@ -7,7 +7,6 @@
  * License v3.0 only", or the "Server Side Public License, v 1".
  */
 
-import org.elasticsearch.internal.CompletionsPostingsFormatExtension;
 import org.elasticsearch.plugins.internal.RestExtension;
 
 /** The Elasticsearch Server Module. */
@@ -291,8 +290,7 @@ module org.elasticsearch.server {
         to
             org.elasticsearch.serverless.version,
             org.elasticsearch.serverless.buildinfo,
-            org.elasticsearch.serverless.constants,
-            org.elasticsearch.serverless.codec;
+            org.elasticsearch.serverless.constants;
     exports org.elasticsearch.lucene.analysis.miscellaneous;
     exports org.elasticsearch.lucene.grouping;
     exports org.elasticsearch.lucene.queries;
@@ -401,7 +399,6 @@ module org.elasticsearch.server {
             org.elasticsearch.stateless,
             org.elasticsearch.settings.secure,
             org.elasticsearch.serverless.constants,
-            org.elasticsearch.serverless.codec,
             org.elasticsearch.serverless.apifiltering,
             org.elasticsearch.internal.security;
 
@@ -422,7 +419,6 @@ module org.elasticsearch.server {
     uses org.elasticsearch.node.internal.TerminationHandlerProvider;
     uses org.elasticsearch.internal.VersionExtension;
     uses org.elasticsearch.internal.BuildExtension;
-    uses CompletionsPostingsFormatExtension;
     uses org.elasticsearch.features.FeatureSpecification;
     uses org.elasticsearch.plugins.internal.LoggingDataProvider;
 

+ 2 - 18
server/src/main/java/org/elasticsearch/index/codec/PerFieldFormatSupplier.java

@@ -25,10 +25,6 @@ import org.elasticsearch.index.mapper.IdFieldMapper;
 import org.elasticsearch.index.mapper.Mapper;
 import org.elasticsearch.index.mapper.MapperService;
 import org.elasticsearch.index.mapper.vectors.DenseVectorFieldMapper;
-import org.elasticsearch.internal.CompletionsPostingsFormatExtension;
-import org.elasticsearch.plugins.ExtensionLoader;
-
-import java.util.ServiceLoader;
 
 /**
  * Class that encapsulates the logic of figuring out the most appropriate file format for a given field, across postings, doc values and
@@ -40,6 +36,7 @@ public class PerFieldFormatSupplier {
     private static final KnnVectorsFormat knnVectorsFormat = new Lucene99HnswVectorsFormat();
     private static final ES87TSDBDocValuesFormat tsdbDocValuesFormat = new ES87TSDBDocValuesFormat();
     private static final ES812PostingsFormat es812PostingsFormat = new ES812PostingsFormat();
+    private static final PostingsFormat completionPostingsFormat = PostingsFormat.forName("Completion101");
 
     private final ES87BloomFilterPostingsFormat bloomFilterPostingsFormat;
     private final MapperService mapperService;
@@ -60,26 +57,13 @@ public class PerFieldFormatSupplier {
         if (mapperService != null) {
             Mapper mapper = mapperService.mappingLookup().getMapper(field);
             if (mapper instanceof CompletionFieldMapper) {
-                return CompletionPostingsFormatHolder.POSTINGS_FORMAT;
+                return completionPostingsFormat;
             }
         }
         // return our own posting format using PFOR
         return es812PostingsFormat;
     }
 
-    private static class CompletionPostingsFormatHolder {
-        private static final PostingsFormat POSTINGS_FORMAT = getCompletionPostingsFormat();
-
-        private static PostingsFormat getCompletionPostingsFormat() {
-            String defaultName = "Completion101"; // Caution: changing this name will result in exceptions if a field is created during a
-            // rolling upgrade and the new codec (specified by the name) is not available on all nodes in the cluster.
-            String codecName = ExtensionLoader.loadSingleton(ServiceLoader.load(CompletionsPostingsFormatExtension.class))
-                .map(CompletionsPostingsFormatExtension::getFormatName)
-                .orElse(defaultName);
-            return PostingsFormat.forName(codecName);
-        }
-    }
-
     boolean useBloomFilter(String field) {
         if (mapperService == null) {
             return false;

+ 0 - 28
server/src/main/java/org/elasticsearch/internal/CompletionsPostingsFormatExtension.java

@@ -1,28 +0,0 @@
-/*
- * 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", the "GNU Affero General Public License v3.0 only", 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", the "GNU Affero General Public
- * License v3.0 only", or the "Server Side Public License, v 1".
- */
-
-package org.elasticsearch.internal;
-
-import org.apache.lucene.search.suggest.document.CompletionPostingsFormat;
-
-/**
- * Allows plugging-in the Completions Postings Format.
- */
-public interface CompletionsPostingsFormatExtension {
-
-    /**
-     * Returns the name of the  {@link CompletionPostingsFormat} that Elasticsearch should use. Should return null if the extension
-     * is not enabled.
-     * <p>
-     * Note that the name must match a codec that is available on all nodes in the cluster, otherwise IndexCorruptionExceptions will occur.
-     * A feature can be used to protect against this scenario, or alternatively, the codec code can be rolled out prior to its usage by this
-     * extension.
-     */
-    String getFormatName();
-}