1414import org .elasticsearch .cluster .node .DiscoveryNodes ;
1515import org .elasticsearch .common .Strings ;
1616import org .elasticsearch .common .io .stream .NamedWriteableRegistry ;
17+ import org .elasticsearch .common .logging .DeprecationCategory ;
18+ import org .elasticsearch .common .logging .DeprecationLogger ;
1719import org .elasticsearch .common .settings .ClusterSettings ;
1820import org .elasticsearch .common .settings .IndexScopedSettings ;
1921import org .elasticsearch .common .settings .Setting ;
7476
7577public class EnrichPlugin extends Plugin implements SystemIndexPlugin , IngestPlugin {
7678
79+ private static final DeprecationLogger deprecationLogger = DeprecationLogger .getLogger (EnrichPlugin .class );
80+
7781 static final Setting <Integer > ENRICH_FETCH_SIZE_SETTING = Setting .intSetting (
7882 "enrich.fetch_size" ,
7983 10000 ,
@@ -126,9 +130,9 @@ public class EnrichPlugin extends Plugin implements SystemIndexPlugin, IngestPlu
126130 return String .valueOf (maxConcurrentRequests * maxLookupsPerRequest );
127131 }, val -> Setting .parseInt (val , 1 , Integer .MAX_VALUE , QUEUE_CAPACITY_SETTING_NAME ), Setting .Property .NodeScope );
128132
129- public static final String CACHE_SIZE_SETTING_NAME = "enrich.cache.size " ;
133+ public static final String CACHE_SIZE_SETTING_NAME = "enrich.cache_size " ;
130134 public static final Setting <FlatNumberOrByteSizeValue > CACHE_SIZE = new Setting <>(
131- "enrich.cache.size" ,
135+ CACHE_SIZE_SETTING_NAME ,
132136 (String ) null ,
133137 (String s ) -> FlatNumberOrByteSizeValue .parse (
134138 s ,
@@ -138,16 +142,58 @@ public class EnrichPlugin extends Plugin implements SystemIndexPlugin, IngestPlu
138142 Setting .Property .NodeScope
139143 );
140144
145+ /**
146+ * This setting solely exists because the original setting was accidentally renamed in
147+ * https://github.com/elastic/elasticsearch/pull/111412.
148+ */
149+ public static final String CACHE_SIZE_SETTING_BWC_NAME = "enrich.cache.size" ;
150+ public static final Setting <FlatNumberOrByteSizeValue > CACHE_SIZE_BWC = new Setting <>(
151+ CACHE_SIZE_SETTING_BWC_NAME ,
152+ (String ) null ,
153+ (String s ) -> FlatNumberOrByteSizeValue .parse (
154+ s ,
155+ CACHE_SIZE_SETTING_BWC_NAME ,
156+ new FlatNumberOrByteSizeValue (ByteSizeValue .ofBytes ((long ) (0.01 * JvmInfo .jvmInfo ().getConfiguredMaxHeapSize ())))
157+ ),
158+ Setting .Property .NodeScope ,
159+ Setting .Property .Deprecated
160+ );
161+
141162 private final Settings settings ;
142163 private final EnrichCache enrichCache ;
164+ private final long maxCacheSize ;
143165
144166 public EnrichPlugin (final Settings settings ) {
145167 this .settings = settings ;
146- FlatNumberOrByteSizeValue maxSize = CACHE_SIZE .get (settings );
168+ FlatNumberOrByteSizeValue maxSize ;
169+ if (settings .hasValue (CACHE_SIZE_SETTING_BWC_NAME )) {
170+ if (settings .hasValue (CACHE_SIZE_SETTING_NAME )) {
171+ throw new IllegalArgumentException (
172+ Strings .format (
173+ "Both [{}] and [{}] are set, please use [{}]" ,
174+ CACHE_SIZE_SETTING_NAME ,
175+ CACHE_SIZE_SETTING_BWC_NAME ,
176+ CACHE_SIZE_SETTING_NAME
177+ )
178+ );
179+ }
180+ deprecationLogger .warn (
181+ DeprecationCategory .SETTINGS ,
182+ "enrich_cache_size_name" ,
183+ "The [{}] setting is deprecated and will be removed in a future version. Please use [{}] instead." ,
184+ CACHE_SIZE_SETTING_BWC_NAME ,
185+ CACHE_SIZE_SETTING_NAME
186+ );
187+ maxSize = CACHE_SIZE_BWC .get (settings );
188+ } else {
189+ maxSize = CACHE_SIZE .get (settings );
190+ }
147191 if (maxSize .byteSizeValue () != null ) {
148192 this .enrichCache = new EnrichCache (maxSize .byteSizeValue ());
193+ this .maxCacheSize = maxSize .byteSizeValue ().getBytes ();
149194 } else {
150195 this .enrichCache = new EnrichCache (maxSize .flatNumber ());
196+ this .maxCacheSize = maxSize .flatNumber ();
151197 }
152198 }
153199
@@ -286,6 +332,11 @@ public String getFeatureDescription() {
286332 return "Manages data related to Enrich policies" ;
287333 }
288334
335+ // Visible for testing
336+ long getMaxCacheSize () {
337+ return maxCacheSize ;
338+ }
339+
289340 /**
290341 * A class that specifies either a flat (unit-less) number or a byte size value.
291342 */
0 commit comments