14
14
import org .elasticsearch .cluster .node .DiscoveryNodes ;
15
15
import org .elasticsearch .common .Strings ;
16
16
import org .elasticsearch .common .io .stream .NamedWriteableRegistry ;
17
+ import org .elasticsearch .common .logging .DeprecationCategory ;
18
+ import org .elasticsearch .common .logging .DeprecationLogger ;
17
19
import org .elasticsearch .common .settings .ClusterSettings ;
18
20
import org .elasticsearch .common .settings .IndexScopedSettings ;
19
21
import org .elasticsearch .common .settings .Setting ;
74
76
75
77
public class EnrichPlugin extends Plugin implements SystemIndexPlugin , IngestPlugin {
76
78
79
+ private static final DeprecationLogger deprecationLogger = DeprecationLogger .getLogger (EnrichPlugin .class );
80
+
77
81
static final Setting <Integer > ENRICH_FETCH_SIZE_SETTING = Setting .intSetting (
78
82
"enrich.fetch_size" ,
79
83
10000 ,
@@ -126,9 +130,9 @@ public class EnrichPlugin extends Plugin implements SystemIndexPlugin, IngestPlu
126
130
return String .valueOf (maxConcurrentRequests * maxLookupsPerRequest );
127
131
}, val -> Setting .parseInt (val , 1 , Integer .MAX_VALUE , QUEUE_CAPACITY_SETTING_NAME ), Setting .Property .NodeScope );
128
132
129
- public static final String CACHE_SIZE_SETTING_NAME = "enrich.cache.size " ;
133
+ public static final String CACHE_SIZE_SETTING_NAME = "enrich.cache_size " ;
130
134
public static final Setting <FlatNumberOrByteSizeValue > CACHE_SIZE = new Setting <>(
131
- "enrich.cache.size" ,
135
+ CACHE_SIZE_SETTING_NAME ,
132
136
(String ) null ,
133
137
(String s ) -> FlatNumberOrByteSizeValue .parse (
134
138
s ,
@@ -138,16 +142,58 @@ public class EnrichPlugin extends Plugin implements SystemIndexPlugin, IngestPlu
138
142
Setting .Property .NodeScope
139
143
);
140
144
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
+
141
162
private final Settings settings ;
142
163
private final EnrichCache enrichCache ;
164
+ private final long maxCacheSize ;
143
165
144
166
public EnrichPlugin (final Settings settings ) {
145
167
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
+ }
147
191
if (maxSize .byteSizeValue () != null ) {
148
192
this .enrichCache = new EnrichCache (maxSize .byteSizeValue ());
193
+ this .maxCacheSize = maxSize .byteSizeValue ().getBytes ();
149
194
} else {
150
195
this .enrichCache = new EnrichCache (maxSize .flatNumber ());
196
+ this .maxCacheSize = maxSize .flatNumber ();
151
197
}
152
198
}
153
199
@@ -286,6 +332,11 @@ public String getFeatureDescription() {
286
332
return "Manages data related to Enrich policies" ;
287
333
}
288
334
335
+ // Visible for testing
336
+ long getMaxCacheSize () {
337
+ return maxCacheSize ;
338
+ }
339
+
289
340
/**
290
341
* A class that specifies either a flat (unit-less) number or a byte size value.
291
342
*/
0 commit comments