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 ;
2325import  org .elasticsearch .common .unit .MemorySizeValue ;
2426import  org .elasticsearch .core .Nullable ;
2527import  org .elasticsearch .core .TimeValue ;
28+ import  org .elasticsearch .core .UpdateForV10 ;
2629import  org .elasticsearch .features .NodeFeature ;
2730import  org .elasticsearch .indices .SystemIndexDescriptor ;
2831import  org .elasticsearch .ingest .Processor ;
7477
7578public  class  EnrichPlugin  extends  Plugin  implements  SystemIndexPlugin , IngestPlugin  {
7679
80+     private  static  final  DeprecationLogger  deprecationLogger  = DeprecationLogger .getLogger (EnrichPlugin .class );
81+ 
7782    static  final  Setting <Integer > ENRICH_FETCH_SIZE_SETTING  = Setting .intSetting (
7883        "enrich.fetch_size" ,
7984        10000 ,
@@ -126,9 +131,9 @@ public class EnrichPlugin extends Plugin implements SystemIndexPlugin, IngestPlu
126131        return  String .valueOf (maxConcurrentRequests  * maxLookupsPerRequest );
127132    }, val  -> Setting .parseInt (val , 1 , Integer .MAX_VALUE , QUEUE_CAPACITY_SETTING_NAME ), Setting .Property .NodeScope );
128133
129-     public  static  final  String  CACHE_SIZE_SETTING_NAME  = "enrich.cache.size " ;
134+     public  static  final  String  CACHE_SIZE_SETTING_NAME  = "enrich.cache_size " ;
130135    public  static  final  Setting <FlatNumberOrByteSizeValue > CACHE_SIZE  = new  Setting <>(
131-         "enrich.cache.size" ,
136+         CACHE_SIZE_SETTING_NAME ,
132137        (String ) null ,
133138        (String  s ) -> FlatNumberOrByteSizeValue .parse (
134139            s ,
@@ -138,16 +143,59 @@ public class EnrichPlugin extends Plugin implements SystemIndexPlugin, IngestPlu
138143        Setting .Property .NodeScope 
139144    );
140145
146+     /** 
147+      * This setting solely exists because the original setting was accidentally renamed in 
148+      * https://github.com/elastic/elasticsearch/pull/111412. 
149+      */ 
150+     @ UpdateForV10 (owner  = UpdateForV10 .Owner .DATA_MANAGEMENT )
151+     public  static  final  String  CACHE_SIZE_SETTING_BWC_NAME  = "enrich.cache.size" ;
152+     public  static  final  Setting <FlatNumberOrByteSizeValue > CACHE_SIZE_BWC  = new  Setting <>(
153+         CACHE_SIZE_SETTING_BWC_NAME ,
154+         (String ) null ,
155+         (String  s ) -> FlatNumberOrByteSizeValue .parse (
156+             s ,
157+             CACHE_SIZE_SETTING_BWC_NAME ,
158+             new  FlatNumberOrByteSizeValue (ByteSizeValue .ofBytes ((long ) (0.01  * JvmInfo .jvmInfo ().getConfiguredMaxHeapSize ())))
159+         ),
160+         Setting .Property .NodeScope ,
161+         Setting .Property .Deprecated 
162+     );
163+ 
141164    private  final  Settings  settings ;
142165    private  final  EnrichCache  enrichCache ;
166+     private  final  long  maxCacheSize ;
143167
144168    public  EnrichPlugin (final  Settings  settings ) {
145169        this .settings  = settings ;
146-         FlatNumberOrByteSizeValue  maxSize  = CACHE_SIZE .get (settings );
170+         FlatNumberOrByteSizeValue  maxSize ;
171+         if  (settings .hasValue (CACHE_SIZE_SETTING_BWC_NAME )) {
172+             if  (settings .hasValue (CACHE_SIZE_SETTING_NAME )) {
173+                 throw  new  IllegalArgumentException (
174+                     Strings .format (
175+                         "Both [{}] and [{}] are set, please use [{}]" ,
176+                         CACHE_SIZE_SETTING_NAME ,
177+                         CACHE_SIZE_SETTING_BWC_NAME ,
178+                         CACHE_SIZE_SETTING_NAME 
179+                     )
180+                 );
181+             }
182+             deprecationLogger .warn (
183+                 DeprecationCategory .SETTINGS ,
184+                 "enrich_cache_size_name" ,
185+                 "The [{}] setting is deprecated and will be removed in a future version. Please use [{}] instead." ,
186+                 CACHE_SIZE_SETTING_BWC_NAME ,
187+                 CACHE_SIZE_SETTING_NAME 
188+             );
189+             maxSize  = CACHE_SIZE_BWC .get (settings );
190+         } else  {
191+             maxSize  = CACHE_SIZE .get (settings );
192+         }
147193        if  (maxSize .byteSizeValue () != null ) {
148194            this .enrichCache  = new  EnrichCache (maxSize .byteSizeValue ());
195+             this .maxCacheSize  = maxSize .byteSizeValue ().getBytes ();
149196        } else  {
150197            this .enrichCache  = new  EnrichCache (maxSize .flatNumber ());
198+             this .maxCacheSize  = maxSize .flatNumber ();
151199        }
152200    }
153201
@@ -286,6 +334,11 @@ public String getFeatureDescription() {
286334        return  "Manages data related to Enrich policies" ;
287335    }
288336
337+     // Visible for testing 
338+     long  getMaxCacheSize () {
339+         return  maxCacheSize ;
340+     }
341+ 
289342    /** 
290343     * A class that specifies either a flat (unit-less) number or a byte size value. 
291344     */ 
0 commit comments