-
Notifications
You must be signed in to change notification settings - Fork 25.2k
Make ValuesSourceRegistry immutable after initilization #55493
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Make ValuesSourceRegistry immutable after initilization #55493
Conversation
Pinging @elastic/es-analytics-geo (:Analytics/Aggregations) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice! I left a few small things.
*/ | ||
default List<Consumer<ValuesSourceRegistry>> getBareAggregatorRegistrar() { | ||
default List<Consumer<ValuesSourceRegistry.ValuesSourceRegistryBuilder>> getBareAggregatorRegistrar() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ValuesSourceRegistry.Builder
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Rename method to extendAggregations
or something? Also, now that I'm looking at it, why return a list instead of just a method? Or even just:
default void extendAggregations(ValuesSourceRegistry.Builder builder) {}
?
I know it doesn't line up with the other "return lists of stuff" methods on these classes but ValuesSourceRegistry
is a different animal anyway.
|
||
// after aggs have been registered, see if there are any new VSTypes that need to be linked to core fields | ||
registerFromPlugin(plugins, SearchPlugin::getBareAggregatorRegistrar, this::registerBareAggregatorRegistrar); | ||
registerFromPlugin(plugins, SearchPlugin::getBareAggregatorRegistrar, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe it isn't worth having the method named registerBareAggregatorRegistrar
now.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just use the lambda.
* applied to that type. | ||
* @param aggregatorSupplier An Aggregation-specific specialization of AggregatorSupplier which will construct the mapped aggregator | ||
*/ | ||
public synchronized void register(String aggregationName, Predicate<ValuesSourceType> appliesTo, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think it needs to be synchronized
any more because we do all plugin building in one thread.
@@ -18,6 +18,26 @@ | |||
*/ | |||
package org.elasticsearch.search.aggregations; | |||
|
|||
import static org.elasticsearch.test.InternalAggregationTestCase.DEFAULT_MAX_BUCKETS; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think your import order config is a bit confused here. I believe we usually put static last. Not a big deal, but it makes the diff bigger.
/** | ||
* Register a ValuesSource to Aggregator mapping. | ||
* | ||
* Threading behavior notes: This call is both synchronized and expensive. It copies the entire existing mapping structure each |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this still relevant ?
Conflicts: x-pack/plugin/spatial/src/main/java/org/elasticsearch/xpack/spatial/SpatialPlugin.java
@elasticmachine run elasticsearch-ci/1 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
@@ -81,7 +81,8 @@ protected void innerWriteTo(StreamOutput out) { | |||
|
|||
@Override | |||
protected AvgAggregatorFactory innerBuild(QueryShardContext queryShardContext, ValuesSourceConfig config, | |||
AggregatorFactory parent, Builder subFactoriesBuilder) throws IOException { | |||
AggregatorFactory parent, | |||
AggregatorFactories.Builder subFactoriesBuilder) throws IOException { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
❤️
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Glad you like it. Intellij stuffed in the fully qualified package name there, and I did a manual pass yesterday to trim them down to just AggregatorFactories.Builder
.
*/ | ||
public void registerAny(String aggregationName, AggregatorSupplier aggregatorSupplier) { | ||
register(aggregationName, (ignored) -> true, aggregatorSupplier); | ||
// Maps Aggregation names to (ValuesSourceType, Supplier) pairs, keyed by ValuesSourceType |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Javadoc instead?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sure
WIP: this commit just resolves merge conflicts. Still need to fix compile errors Conflicts: server/src/main/java/org/elasticsearch/search/SearchModule.java server/src/main/java/org/elasticsearch/search/aggregations/bucket/histogram/DateHistogramAggregatorFactory.java server/src/main/java/org/elasticsearch/search/aggregations/bucket/histogram/HistogramAggregatorFactory.java server/src/main/java/org/elasticsearch/search/aggregations/bucket/missing/MissingAggregationBuilder.java server/src/main/java/org/elasticsearch/search/aggregations/bucket/missing/MissingAggregatorFactory.java server/src/main/java/org/elasticsearch/search/aggregations/bucket/range/AbstractRangeAggregatorFactory.java server/src/main/java/org/elasticsearch/search/aggregations/bucket/significant/SignificantTermsAggregatorFactory.java server/src/main/java/org/elasticsearch/search/aggregations/bucket/terms/RareTermsAggregatorFactory.java server/src/main/java/org/elasticsearch/search/aggregations/bucket/terms/TermsAggregatorFactory.java server/src/main/java/org/elasticsearch/search/aggregations/metrics/AvgAggregatorFactory.java server/src/main/java/org/elasticsearch/search/aggregations/metrics/ExtendedStatsAggregationBuilder.java server/src/main/java/org/elasticsearch/search/aggregations/metrics/ExtendedStatsAggregatorFactory.java server/src/main/java/org/elasticsearch/search/aggregations/metrics/MaxAggregatorFactory.java server/src/main/java/org/elasticsearch/search/aggregations/metrics/MinAggregatorFactory.java server/src/main/java/org/elasticsearch/search/aggregations/metrics/PercentileRanksAggregatorFactory.java server/src/main/java/org/elasticsearch/search/aggregations/metrics/PercentilesAggregatorFactory.java server/src/main/java/org/elasticsearch/search/aggregations/metrics/StatsAggregatorFactory.java server/src/main/java/org/elasticsearch/search/aggregations/metrics/SumAggregatorFactory.java server/src/main/java/org/elasticsearch/search/aggregations/support/ValuesSourceRegistry.java server/src/main/java/org/elasticsearch/search/aggregations/support/ValuesSourceType.java test/framework/src/main/java/org/elasticsearch/search/aggregations/AggregatorTestCase.java x-pack/plugin/analytics/src/main/java/org/elasticsearch/xpack/analytics/AnalyticsPlugin.java x-pack/plugin/analytics/src/main/java/org/elasticsearch/xpack/analytics/boxplot/BoxplotAggregatorFactory.java x-pack/plugin/analytics/src/test/java/org/elasticsearch/xpack/analytics/boxplot/BoxplotAggregatorTests.java x-pack/plugin/analytics/src/test/java/org/elasticsearch/xpack/analytics/mapper/HDRPreAggregatedPercentileRanksAggregatorTests.java x-pack/plugin/analytics/src/test/java/org/elasticsearch/xpack/analytics/mapper/HDRPreAggregatedPercentilesAggregatorTests.java x-pack/plugin/analytics/src/test/java/org/elasticsearch/xpack/analytics/mapper/TDigestPreAggregatedPercentileRanksAggregatorTests.java x-pack/plugin/analytics/src/test/java/org/elasticsearch/xpack/analytics/mapper/TDigestPreAggregatedPercentilesAggregatorTests.java x-pack/plugin/analytics/src/test/java/org/elasticsearch/xpack/analytics/stringstats/StringStatsAggregatorTests.java x-pack/plugin/spatial/src/main/java/org/elasticsearch/xpack/spatial/SpatialPlugin.java
This PR separates out the registration methods from the read methods on
ValuesSourceRegistry
, putting the former into a new builder class. The various methods called fromSearchModule
to register aggregators now accept aValuesSourceRegistryBuilder
, and later uses inValuesSourceConfig
&c still use the mainValuesSourceRegistry
class.SearchModule
, after registering all core & plugin aggregations, constructs an immutableValuesSourceRegistry
from the builder, which it then stores and hands out as needed.Once again, we jump through some hoops in building the immutable data structure in order to use the Java 9+ immutable collections, which use less memory and have (marginally) better access performance than the older
unmodifiable
wrappers. (The backport will use theunmodifiable
wrappers, because of java version compatibility).