-
Notifications
You must be signed in to change notification settings - Fork 2.5k
/
HibernateSearchElasticsearchRuntimeConfigPersistenceUnit.java
527 lines (466 loc) · 18.1 KB
/
HibernateSearchElasticsearchRuntimeConfigPersistenceUnit.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
package io.quarkus.hibernate.search.orm.elasticsearch.runtime;
import java.time.Duration;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.Optional;
import java.util.OptionalInt;
import org.hibernate.search.backend.elasticsearch.index.IndexStatus;
import org.hibernate.search.engine.cfg.spi.ParseUtils;
import org.hibernate.search.mapper.orm.schema.management.SchemaManagementStrategyName;
import org.hibernate.search.mapper.orm.search.loading.EntityLoadingCacheLookupStrategy;
import org.hibernate.search.util.common.SearchException;
import io.quarkus.runtime.annotations.ConfigDocMapKey;
import io.quarkus.runtime.annotations.ConfigDocSection;
import io.quarkus.runtime.annotations.ConfigGroup;
import io.quarkus.runtime.annotations.ConfigItem;
@ConfigGroup
public class HibernateSearchElasticsearchRuntimeConfigPersistenceUnit {
/**
* Whether Hibernate Search is enabled.
*/
@ConfigItem(defaultValue = "true")
public boolean enabled;
/**
* Default backend
*/
@ConfigItem(name = "elasticsearch")
@ConfigDocSection
ElasticsearchBackendRuntimeConfig defaultBackend;
/**
* Named backends
*/
@ConfigItem(name = "elasticsearch")
@ConfigDocSection
public ElasticsearchNamedBackendsRuntimeConfig namedBackends;
/**
* Configuration for automatic creation and validation of the Elasticsearch schema:
* indexes, their mapping, their settings.
*/
@ConfigItem
SchemaManagementConfig schemaManagement;
/**
* Configuration for how entities are loaded by a search query.
*/
@ConfigItem(name = "query.loading")
SearchQueryLoadingConfig queryLoading;
/**
* Configuration for the automatic indexing.
*/
@ConfigItem
AutomaticIndexingConfig automaticIndexing;
/**
* Configuration for multi-tenancy.
*/
@ConfigItem
MultiTenancyConfig multiTenancy;
@ConfigGroup
public static class ElasticsearchNamedBackendsRuntimeConfig {
/**
* Named backends
*/
@ConfigDocMapKey("backend-name")
public Map<String, ElasticsearchBackendRuntimeConfig> backends;
}
@ConfigGroup
public static class ElasticsearchBackendRuntimeConfig {
/**
* The list of hosts of the Elasticsearch servers.
*/
@ConfigItem(defaultValue = "localhost:9200")
List<String> hosts;
/**
* The protocol to use when contacting Elasticsearch servers.
* Set to "https" to enable SSL/TLS.
*/
@ConfigItem(defaultValue = "http")
ElasticsearchClientProtocol protocol;
/**
* The username used for authentication.
*/
@ConfigItem
Optional<String> username;
/**
* The password used for authentication.
*/
@ConfigItem
Optional<String> password;
/**
* The timeout when establishing a connection to an Elasticsearch server.
*/
@ConfigItem(defaultValue = "1S")
Duration connectionTimeout;
/**
* The timeout when reading responses from an Elasticsearch server.
*/
@ConfigItem(defaultValue = "30S")
Duration readTimeout;
/**
* The timeout when executing a request to an Elasticsearch server.
* <p>
* This includes the time needed to wait for a connection to be available,
* send the request and read the response.
*/
@ConfigItem
Optional<Duration> requestTimeout;
/**
* The maximum number of connections to all the Elasticsearch servers.
*/
@ConfigItem(defaultValue = "20")
int maxConnections;
/**
* The maximum number of connections per Elasticsearch server.
*/
@ConfigItem(defaultValue = "10")
int maxConnectionsPerRoute;
/**
* Configuration for the automatic discovery of new Elasticsearch nodes.
*/
@ConfigItem
DiscoveryConfig discovery;
/**
* Configuration for the thread pool assigned to the backend.
*/
@ConfigItem
ThreadPoolConfig threadPool;
/**
* Whether Hibernate Search should check the version of the Elasticsearch cluster on startup.
* <p>
* Set to {@code false} if the Elasticsearch cluster may not be available on startup.
*/
@ConfigItem(name = "version-check.enabled", defaultValue = "true")
public boolean versionCheck;
/**
* The default configuration for the Elasticsearch indexes.
*/
@ConfigItem(name = ConfigItem.PARENT)
ElasticsearchIndexRuntimeConfig indexDefaults;
/**
* Per-index specific configuration.
*/
@ConfigItem
@ConfigDocMapKey("index-name")
Map<String, ElasticsearchIndexRuntimeConfig> indexes;
}
public enum ElasticsearchClientProtocol {
/**
* Use clear-text HTTP, with SSL/TLS disabled.
*/
HTTP("http"),
/**
* Use HTTPS, with SSL/TLS enabled.
*/
HTTPS("https");
public static ElasticsearchClientProtocol of(String value) {
return ParseUtils.parseDiscreteValues(
values(),
ElasticsearchClientProtocol::getHibernateSearchString,
(invalidValue, validValues) -> new SearchException(
String.format(
Locale.ROOT,
"Invalid protocol: '%1$s'. Valid protocols are: %2$s.",
invalidValue,
validValues)),
value);
}
private final String hibernateSearchString;
ElasticsearchClientProtocol(String hibernateSearchString) {
this.hibernateSearchString = hibernateSearchString;
}
public String getHibernateSearchString() {
return hibernateSearchString;
}
}
@ConfigGroup
public static class ElasticsearchIndexRuntimeConfig {
/**
* Configuration for the schema management of the indexes.
*/
@ConfigItem
ElasticsearchIndexSchemaManagementConfig schemaManagement;
/**
* Configuration for the indexing process that creates, updates and deletes documents.
*/
@ConfigItem
ElasticsearchIndexIndexingConfig indexing;
}
@ConfigGroup
public static class DiscoveryConfig {
/**
* Defines if automatic discovery is enabled.
*/
@ConfigItem
boolean enabled;
/**
* Refresh interval of the node list.
*/
@ConfigItem(defaultValue = "10S")
Duration refreshInterval;
}
@ConfigGroup
public static class AutomaticIndexingConfig {
/**
* Configuration for synchronization with the index when indexing automatically.
*/
@ConfigItem
AutomaticIndexingSynchronizationConfig synchronization;
/**
* Whether to check if dirty properties are relevant to indexing before actually reindexing an entity.
* <p>
* When enabled, re-indexing of an entity is skipped if the only changes are on properties that are not used when
* indexing.
*/
@ConfigItem(defaultValue = "true")
boolean enableDirtyCheck;
}
@ConfigGroup
public static class AutomaticIndexingSynchronizationConfig {
// @formatter:off
/**
* The synchronization strategy to use when indexing automatically.
*
* Defines how complete indexing should be before resuming the application thread
* after a database transaction is committed.
*
* [WARNING]
* ====
* Indexing synchronization is only relevant when coordination is disabled (which is the default).
*
* With the <<coordination,`outbox-polling` coordination strategy>>,
* indexing happens in background threads and is always asynchronous;
* the behavior is equivalent to the `write-sync` synchronization strategy.
* ====
*
* Available values:
*
* [cols=5]
* !===
* .2+h!Strategy
* .2+h!Throughput
* 3+^h!Guarantees when the application thread resumes
*
* h!Changes applied
* h!Changes safe from crash/power loss
* h!Changes visible on search
*
* !async
* !Best
* ^!icon:times[role=red]
* ^!icon:times[role=red]
* ^!icon:times[role=red]
*
* !write-sync (**default**)
* !Medium
* ^!icon:check[role=lime]
* ^!icon:check[role=lime]
* ^!icon:times[role=red]
*
* !read-sync
* !Medium to worst
* ^!icon:check[role=lime]
* ^!icon:times[role=red]
* ^!icon:check[role=lime]
*
* !sync
* !Worst
* ^!icon:check[role=lime]
* ^!icon:check[role=lime]
* ^!icon:check[role=lime]
* !===
*
* This property also accepts a <<bean-reference-note-anchor,bean reference>>
* to a custom implementations of `AutomaticIndexingSynchronizationStrategy`.
*
* See
* link:{hibernate-search-doc-prefix}#mapper-orm-indexing-automatic-synchronization[this section of the reference documentation]
* for more information.
*
* @asciidoclet
*/
// @formatter:on
@ConfigItem(defaultValueDocumentation = "write-sync")
Optional<String> strategy;
}
@ConfigGroup
public static class SearchQueryLoadingConfig {
/**
* Configuration for cache lookup when loading entities during the execution of a search query.
*/
@ConfigItem
SearchQueryLoadingCacheLookupConfig cacheLookup;
/**
* The fetch size to use when loading entities during the execution of a search query.
*/
@ConfigItem(defaultValue = "100")
int fetchSize;
}
@ConfigGroup
public static class SearchQueryLoadingCacheLookupConfig {
/**
* The strategy to use when loading entities during the execution of a search query.
*/
@ConfigItem(defaultValue = "skip")
EntityLoadingCacheLookupStrategy strategy;
}
@ConfigGroup
public static class SchemaManagementConfig {
// @formatter:off
/**
* The schema management strategy, controlling how indexes and their schema
* are created, updated, validated or dropped on startup and shutdown.
*
* Available values:
*
* [cols=2]
* !===
* h!Strategy
* h!Definition
*
* !none
* !Do nothing: assume that indexes already exist and that their schema matches Hibernate Search's expectations.
*
* !validate
* !Validate that indexes exist and that their schema matches Hibernate Search's expectations.
*
* If it does not, throw an exception, but make no attempt to fix the problem.
*
* !create
* !For indexes that do not exist, create them along with their schema.
*
* For indexes that already exist, do nothing: assume that their schema matches Hibernate Search's expectations.
*
* !create-or-validate (**default** unless using Dev Services)
* !For indexes that do not exist, create them along with their schema.
*
* For indexes that already exist, validate that their schema matches Hibernate Search's expectations.
*
* If it does not, throw an exception, but make no attempt to fix the problem.
*
* !create-or-update
* !For indexes that do not exist, create them along with their schema.
*
* For indexes that already exist, validate that their schema matches Hibernate Search's expectations;
* if it does not match expectations, try to update it.
*
* **This strategy is unfit for production environments**,
* due to several important limitations,
* but can be useful when developing.
*
* !drop-and-create
* !For indexes that do not exist, create them along with their schema.
*
* For indexes that already exist, drop them, then create them along with their schema.
*
* !drop-and-create-and-drop (**default** when using Dev Services)
* !For indexes that do not exist, create them along with their schema.
*
* For indexes that already exist, drop them, then create them along with their schema.
*
* Also, drop indexes and their schema on shutdown.
* !===
*
* See https://docs.jboss.org/hibernate/stable/search/reference/en-US/html_single/#mapper-orm-schema-management-strategy[this section of the reference documentation]
* for more information.
*
* @asciidoclet
*/
// @formatter:on
@ConfigItem(defaultValue = "create-or-validate", defaultValueDocumentation = "drop-and-create-and-drop when using Dev Services; create-or-validate otherwise")
SchemaManagementStrategyName strategy;
}
@ConfigGroup
public static class ThreadPoolConfig {
/**
* The size of the thread pool assigned to the backend.
* <p>
* Note that number is <em>per backend</em>, not per index.
* Adding more indexes will not add more threads.
* <p>
* As all operations happening in this thread-pool are non-blocking,
* raising its size above the number of processor cores available to the JVM will not bring noticeable performance
* benefit.
* The only reason to alter this setting would be to reduce the number of threads;
* for example, in an application with a single index with a single indexing queue,
* running on a machine with 64 processor cores,
* you might want to bring down the number of threads.
* <p>
* Defaults to the number of processor cores available to the JVM on startup.
*/
// We can't set an actual default value here: see comment on this class.
@ConfigItem
OptionalInt size;
}
// We can't set actual default values in this section,
// otherwise "quarkus.hibernate-search-orm.elasticsearch.index-defaults" will be ignored.
@ConfigGroup
public static class ElasticsearchIndexSchemaManagementConfig {
/**
* The minimal cluster status required.
*/
// We can't set an actual default value here: see comment on this class.
@ConfigItem(defaultValueDocumentation = "yellow")
Optional<IndexStatus> requiredStatus;
/**
* How long we should wait for the status before failing the bootstrap.
*/
// We can't set an actual default value here: see comment on this class.
@ConfigItem(defaultValueDocumentation = "10S")
Optional<Duration> requiredStatusWaitTimeout;
}
// We can't set actual default values in this section,
// otherwise "quarkus.hibernate-search-orm.elasticsearch.index-defaults" will be ignored.
@ConfigGroup
public static class ElasticsearchIndexIndexingConfig {
/**
* The number of indexing queues assigned to each index.
* <p>
* Higher values will lead to more connections being used in parallel,
* which may lead to higher indexing throughput,
* but incurs a risk of overloading Elasticsearch,
* i.e. of overflowing its HTTP request buffers and tripping
* <a href="https://www.elastic.co/guide/en/elasticsearch/reference/7.9/circuit-breaker.html">circuit breakers</a>,
* leading to Elasticsearch giving up on some request and resulting in indexing failures.
*/
// We can't set an actual default value here: see comment on this class.
@ConfigItem(defaultValueDocumentation = "10")
OptionalInt queueCount;
/**
* The size of indexing queues.
* <p>
* Lower values may lead to lower memory usage, especially if there are many queues,
* but values that are too low will reduce the likeliness of reaching the max bulk size
* and increase the likeliness of application threads blocking because the queue is full,
* which may lead to lower indexing throughput.
*/
// We can't set an actual default value here: see comment on this class.
@ConfigItem(defaultValueDocumentation = "1000")
OptionalInt queueSize;
/**
* The maximum size of bulk requests created when processing indexing queues.
* <p>
* Higher values will lead to more documents being sent in each HTTP request sent to Elasticsearch,
* which may lead to higher indexing throughput,
* but incurs a risk of overloading Elasticsearch,
* i.e. of overflowing its HTTP request buffers and tripping
* <a href="https://www.elastic.co/guide/en/elasticsearch/reference/7.9/circuit-breaker.html">circuit breakers</a>,
* leading to Elasticsearch giving up on some request and resulting in indexing failures.
* <p>
* Note that raising this number above the queue size has no effect,
* as bulks cannot include more requests than are contained in the queue.
*/
// We can't set an actual default value here: see comment on this class.
@ConfigItem(defaultValueDocumentation = "100")
OptionalInt maxBulkSize;
}
@ConfigGroup
public static class MultiTenancyConfig {
/**
* An exhaustive list of all tenant identifiers that may be used by the application when multi-tenancy is enabled.
* <p>
* Mainly useful when using the {@code outbox-polling} coordination strategy,
* since it involves setting up one background processor per tenant.
*/
@ConfigItem
Optional<List<String>> tenantIds;
}
}