You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@polaris.apache.org by "adutra (via GitHub)" <gi...@apache.org> on 2026/02/12 18:41:17 UTC
[PR] Use CopyOnWriteArrayList for PolarisConfiguration internal list [polaris]
adutra opened a new pull request, #3755:
URL: https://github.com/apache/polaris/pull/3755
The `ALL_CONFIGURATIONS` field is using `ArrayList` which is not thread-safe.
The field is only accessed via `registerConfiguration()`, and all configurations are currently registered during static initialization.
But we have two subclasses, `FeatureConfiguration` and `BehaviorChangeConfiguration`, that both call that method.
Consider this scenario:
1. Thread A triggers loading of `FeatureConfiguration`;
2. Thread B triggers loading of `BehaviorChangeConfiguration`;
3. Both classes' static initializers run in parallel;
4. Both call `registerConfiguration()` on the shared list concurrently.
In order to avoid this, this PR changes the list to `CopyOnWriteArrayList`.
<!--
๐ Describe what changes you're proposing, especially breaking or user-facing changes.
๐ See https://github.com/apache/polaris/blob/main/CONTRIBUTING.md for more.
-->
## Checklist
- [ ] ๐ก๏ธ Don't disclose security issues! (contact security@apache.org)
- [ ] ๐ Clearly explained why the changes are needed, or linked related issues: Fixes #
- [ ] ๐งช Added/updated tests with good coverage, or manually tested (and explained how)
- [ ] ๐ก Added comments for complex logic
- [ ] ๐งพ Updated `CHANGELOG.md` (if needed)
- [ ] ๐ Updated documentation in `site/content/in-dev/unreleased` (if needed)
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@polaris.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Synchronize on PolarisConfiguration.registerConfiguration() [polaris]
Posted by "dimas-b (via GitHub)" <gi...@apache.org>.
dimas-b commented on code in PR #3755:
URL: https://github.com/apache/polaris/pull/3755#discussion_r2818073306
##########
polaris-core/src/main/java/org/apache/polaris/core/config/PolarisConfiguration.java:
##########
@@ -71,12 +72,12 @@ private static void registerConfiguration(PolarisConfiguration<?> configuration)
}
}
}
- allConfigurations.add(configuration);
+ ALL_CONFIGURATIONS.add(configuration);
}
/** Returns a list of all PolarisConfigurations that have been registered */
public static List<PolarisConfiguration<?>> getAllConfigurations() {
- return List.copyOf(allConfigurations);
+ return List.copyOf(ALL_CONFIGURATIONS);
Review Comment:
I'm fine with simple `synchronized` methods. The affected code is not on the hot path, AFAIK.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@polaris.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Synchronize on PolarisConfiguration.registerConfiguration() [polaris]
Posted by "snazy (via GitHub)" <gi...@apache.org>.
snazy commented on code in PR #3755:
URL: https://github.com/apache/polaris/pull/3755#discussion_r2805754392
##########
polaris-core/src/main/java/org/apache/polaris/core/config/PolarisConfiguration.java:
##########
@@ -71,12 +72,12 @@ private static void registerConfiguration(PolarisConfiguration<?> configuration)
}
}
}
- allConfigurations.add(configuration);
+ ALL_CONFIGURATIONS.add(configuration);
}
/** Returns a list of all PolarisConfigurations that have been registered */
public static List<PolarisConfiguration<?>> getAllConfigurations() {
- return List.copyOf(allConfigurations);
+ return List.copyOf(ALL_CONFIGURATIONS);
Review Comment:
The writes to `ALL_CONFIGURATIONS` via `registerConfiguration` are fine, but this one can still yield wrong results (no fence/barrier here).
I suspect that the there are maybe just a handful calls to `registerConfiguration`.
WDYT of using a copy-on-write but save the `List.copyOf()` on every read?
```java
private static volatile List<PolarisConfiguration<?>> allConfigurations = List.of();
// The `synchronized` is only needed to to have no concurrent executions of registerConfiguration(), not needed as a memory fence/barrier..
synchronized void registerConfiguration(...) {
var updatedConfigs = new ArrayList(allConfigurations);
// register dance
allConfigurations = List.copyOf(updatedConfigs);
}
static List<PolarisConfiguration<?>> getAllConfigurations() {
// reads the current immutable list object
return allConfigurations;
}
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@polaris.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Synchronize on PolarisConfiguration.registerConfiguration() [polaris]
Posted by "adutra (via GitHub)" <gi...@apache.org>.
adutra commented on code in PR #3755:
URL: https://github.com/apache/polaris/pull/3755#discussion_r2821733550
##########
polaris-core/src/main/java/org/apache/polaris/core/config/PolarisConfiguration.java:
##########
@@ -71,12 +72,12 @@ private static void registerConfiguration(PolarisConfiguration<?> configuration)
}
}
}
- allConfigurations.add(configuration);
+ ALL_CONFIGURATIONS.add(configuration);
}
/** Returns a list of all PolarisConfigurations that have been registered */
public static List<PolarisConfiguration<?>> getAllConfigurations() {
- return List.copyOf(allConfigurations);
+ return List.copyOf(ALL_CONFIGURATIONS);
Review Comment:
Well I had to fix a conflict, so I seized the opportunity to remove `AllowlistHolder`.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@polaris.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Use CopyOnWriteArrayList for PolarisConfiguration internal list [polaris]
Posted by "dimas-b (via GitHub)" <gi...@apache.org>.
dimas-b commented on code in PR #3755:
URL: https://github.com/apache/polaris/pull/3755#discussion_r2800635860
##########
polaris-core/src/main/java/org/apache/polaris/core/config/PolarisConfiguration.java:
##########
@@ -50,7 +52,7 @@ public abstract class PolarisConfiguration<T> {
* configs.
*/
private static void registerConfiguration(PolarisConfiguration<?> configuration) {
- for (PolarisConfiguration<?> existingConfiguration : allConfigurations) {
+ for (PolarisConfiguration<?> existingConfiguration : ALL_CONFIGURATIONS) {
if (existingConfiguration.key.equals(configuration.key)) {
throw new IllegalArgumentException(
String.format("Config '%s' is already in use", configuration.key));
Review Comment:
The change looks good to me... yet, the use case described in the PR makes me wonder if perhaps this check may be circumvented in the concurrent load situation ๐
not a big deal, IMHO.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@polaris.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Synchronize on PolarisConfiguration.registerConfiguration() [polaris]
Posted by "dimas-b (via GitHub)" <gi...@apache.org>.
dimas-b commented on code in PR #3755:
URL: https://github.com/apache/polaris/pull/3755#discussion_r2823047073
##########
polaris-core/src/main/java/org/apache/polaris/core/config/PolarisConfiguration.java:
##########
@@ -55,33 +59,33 @@ public abstract class PolarisConfiguration<T> {
* configs.
*/
private static void registerConfiguration(PolarisConfiguration<?> configuration) {
- for (PolarisConfiguration<?> existingConfiguration : allConfigurations) {
- if (existingConfiguration.key.equals(configuration.key)) {
+ if (ALL_CONFIGURATIONS.putIfAbsent(configuration.key(), configuration) != null) {
+ throw new IllegalArgumentException(
+ String.format("Config '%s' is already in use", configuration.key));
+ }
+ if (configuration.hasCatalogConfig()) {
+ if (!ALL_CATALOG_CONFIGS.add(configuration.catalogConfig())) {
Review Comment:
nit: I think this is still a bit racy if we want to be strict. A configuration may be added `ALL_CONFIGURATIONS`, but fail the catalog property checks, which will lead to inconsistent entries.
Not a big deal, since failures are likely to break the whole runtime in the current state of the code... but the intent of this PR is to ensure multi-threaded correctness, so I wonder if it is worth the trouble to use async collections compared to simple `synchronized` methods? (not a blocker)
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@polaris.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Synchronize on PolarisConfiguration.registerConfiguration() [polaris]
Posted by "adutra (via GitHub)" <gi...@apache.org>.
adutra commented on code in PR #3755:
URL: https://github.com/apache/polaris/pull/3755#discussion_r2821648343
##########
polaris-core/src/main/java/org/apache/polaris/core/config/PolarisConfiguration.java:
##########
@@ -71,12 +72,12 @@ private static void registerConfiguration(PolarisConfiguration<?> configuration)
}
}
}
- allConfigurations.add(configuration);
+ ALL_CONFIGURATIONS.add(configuration);
}
/** Returns a list of all PolarisConfigurations that have been registered */
public static List<PolarisConfiguration<?>> getAllConfigurations() {
- return List.copyOf(allConfigurations);
+ return List.copyOf(ALL_CONFIGURATIONS);
Review Comment:
Let's merge this as is and see if we can improve `ReservedProperties.AllowlistHolder` later. I suspect there is a ton of improvement opportunities.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@polaris.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Synchronize on PolarisConfiguration.registerConfiguration() [polaris]
Posted by "snazy (via GitHub)" <gi...@apache.org>.
snazy commented on code in PR #3755:
URL: https://github.com/apache/polaris/pull/3755#discussion_r2816744638
##########
polaris-core/src/main/java/org/apache/polaris/core/config/PolarisConfiguration.java:
##########
@@ -71,12 +72,12 @@ private static void registerConfiguration(PolarisConfiguration<?> configuration)
}
}
}
- allConfigurations.add(configuration);
+ ALL_CONFIGURATIONS.add(configuration);
}
/** Returns a list of all PolarisConfigurations that have been registered */
public static List<PolarisConfiguration<?>> getAllConfigurations() {
- return List.copyOf(allConfigurations);
+ return List.copyOf(ALL_CONFIGURATIONS);
Review Comment:
Hm, could the allow-list holder functionality be moved into PolarisConfiguration and make the allow-list part of the builder?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@polaris.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Use CopyOnWriteArrayList for PolarisConfiguration internal list [polaris]
Posted by "adutra (via GitHub)" <gi...@apache.org>.
adutra commented on code in PR #3755:
URL: https://github.com/apache/polaris/pull/3755#discussion_r2803761221
##########
polaris-core/src/main/java/org/apache/polaris/core/config/PolarisConfiguration.java:
##########
@@ -50,7 +52,7 @@ public abstract class PolarisConfiguration<T> {
* configs.
*/
private static void registerConfiguration(PolarisConfiguration<?> configuration) {
- for (PolarisConfiguration<?> existingConfiguration : allConfigurations) {
+ for (PolarisConfiguration<?> existingConfiguration : ALL_CONFIGURATIONS) {
if (existingConfiguration.key.equals(configuration.key)) {
throw new IllegalArgumentException(
String.format("Config '%s' is already in use", configuration.key));
Review Comment:
Hmm that's right. We might just as well make this method synchronized. I wanted to avoid that because it's less future-proof than using `CopyOnWriteArrayList`, but ๐คทโโ๏ธ
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@polaris.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Synchronize on PolarisConfiguration.registerConfiguration() [polaris]
Posted by "dimas-b (via GitHub)" <gi...@apache.org>.
dimas-b commented on code in PR #3755:
URL: https://github.com/apache/polaris/pull/3755#discussion_r2825159790
##########
polaris-core/src/main/java/org/apache/polaris/core/config/PolarisConfiguration.java:
##########
@@ -55,33 +59,33 @@ public abstract class PolarisConfiguration<T> {
* configs.
*/
private static void registerConfiguration(PolarisConfiguration<?> configuration) {
- for (PolarisConfiguration<?> existingConfiguration : allConfigurations) {
- if (existingConfiguration.key.equals(configuration.key)) {
+ if (ALL_CONFIGURATIONS.putIfAbsent(configuration.key(), configuration) != null) {
+ throw new IllegalArgumentException(
+ String.format("Config '%s' is already in use", configuration.key));
+ }
+ if (configuration.hasCatalogConfig()) {
+ if (!ALL_CATALOG_CONFIGS.add(configuration.catalogConfig())) {
Review Comment:
fair point
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@polaris.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Synchronize on PolarisConfiguration.registerConfiguration() [polaris]
Posted by "adutra (via GitHub)" <gi...@apache.org>.
adutra commented on code in PR #3755:
URL: https://github.com/apache/polaris/pull/3755#discussion_r2823568417
##########
polaris-core/src/main/java/org/apache/polaris/core/config/PolarisConfiguration.java:
##########
@@ -55,33 +59,33 @@ public abstract class PolarisConfiguration<T> {
* configs.
*/
private static void registerConfiguration(PolarisConfiguration<?> configuration) {
- for (PolarisConfiguration<?> existingConfiguration : allConfigurations) {
- if (existingConfiguration.key.equals(configuration.key)) {
+ if (ALL_CONFIGURATIONS.putIfAbsent(configuration.key(), configuration) != null) {
+ throw new IllegalArgumentException(
+ String.format("Config '%s' is already in use", configuration.key));
+ }
+ if (configuration.hasCatalogConfig()) {
+ if (!ALL_CATALOG_CONFIGS.add(configuration.catalogConfig())) {
Review Comment:
> since failures are likely to break the whole runtime in the current state of the code
Yes, the assumption is that any error here is fatal and will make the JVM exit. I don't think we could bring the collections to contain inconsistent data.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@polaris.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Synchronize on PolarisConfiguration.registerConfiguration() [polaris]
Posted by "adutra (via GitHub)" <gi...@apache.org>.
adutra commented on code in PR #3755:
URL: https://github.com/apache/polaris/pull/3755#discussion_r2811684686
##########
polaris-core/src/main/java/org/apache/polaris/core/config/PolarisConfiguration.java:
##########
@@ -71,12 +72,12 @@ private static void registerConfiguration(PolarisConfiguration<?> configuration)
}
}
}
- allConfigurations.add(configuration);
+ ALL_CONFIGURATIONS.add(configuration);
}
/** Returns a list of all PolarisConfigurations that have been registered */
public static List<PolarisConfiguration<?>> getAllConfigurations() {
- return List.copyOf(allConfigurations);
+ return List.copyOf(ALL_CONFIGURATIONS);
Review Comment:
Isn't it simpler to just synchronize `getAllConfigurations`? It's only used in `org.apache.polaris.service.config.ReservedProperties.AllowlistHolder`.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@polaris.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Synchronize on PolarisConfiguration.registerConfiguration() [polaris]
Posted by "adutra (via GitHub)" <gi...@apache.org>.
adutra merged PR #3755:
URL: https://github.com/apache/polaris/pull/3755
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@polaris.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Synchronize on PolarisConfiguration.registerConfiguration() [polaris]
Posted by "dimas-b (via GitHub)" <gi...@apache.org>.
dimas-b commented on code in PR #3755:
URL: https://github.com/apache/polaris/pull/3755#discussion_r2806024112
##########
polaris-core/src/main/java/org/apache/polaris/core/config/PolarisConfiguration.java:
##########
@@ -71,12 +72,12 @@ private static void registerConfiguration(PolarisConfiguration<?> configuration)
}
}
}
- allConfigurations.add(configuration);
+ ALL_CONFIGURATIONS.add(configuration);
}
/** Returns a list of all PolarisConfigurations that have been registered */
public static List<PolarisConfiguration<?>> getAllConfigurations() {
- return List.copyOf(allConfigurations);
+ return List.copyOf(ALL_CONFIGURATIONS);
Review Comment:
+1
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@polaris.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Synchronize on PolarisConfiguration.registerConfiguration() [polaris]
Posted by "dimas-b (via GitHub)" <gi...@apache.org>.
dimas-b commented on code in PR #3755:
URL: https://github.com/apache/polaris/pull/3755#discussion_r2823047073
##########
polaris-core/src/main/java/org/apache/polaris/core/config/PolarisConfiguration.java:
##########
@@ -55,33 +59,33 @@ public abstract class PolarisConfiguration<T> {
* configs.
*/
private static void registerConfiguration(PolarisConfiguration<?> configuration) {
- for (PolarisConfiguration<?> existingConfiguration : allConfigurations) {
- if (existingConfiguration.key.equals(configuration.key)) {
+ if (ALL_CONFIGURATIONS.putIfAbsent(configuration.key(), configuration) != null) {
+ throw new IllegalArgumentException(
+ String.format("Config '%s' is already in use", configuration.key));
+ }
+ if (configuration.hasCatalogConfig()) {
+ if (!ALL_CATALOG_CONFIGS.add(configuration.catalogConfig())) {
Review Comment:
nit: I think this is still a bit racy if we want to be strict. A configuration may be added `ALL_CONFIGURATIONS`, but fail the catalog property checks, which will lead to inconsistent entries.
Not a big deal, since failures are likely to break the whole runtime in the current state of the code... but the intent of this PR is to ensure multi-threaded correctness, so I wonder if it is worth the trouble to use async collections compared to a simple `synchronized` methods? (not a blocker)
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@polaris.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Synchronize on PolarisConfiguration.registerConfiguration() [polaris]
Posted by "adutra (via GitHub)" <gi...@apache.org>.
adutra commented on code in PR #3755:
URL: https://github.com/apache/polaris/pull/3755#discussion_r2821736311
##########
polaris-core/src/main/java/org/apache/polaris/core/config/PolarisConfiguration.java:
##########
@@ -55,33 +59,33 @@ public abstract class PolarisConfiguration<T> {
* configs.
*/
private static void registerConfiguration(PolarisConfiguration<?> configuration) {
- for (PolarisConfiguration<?> existingConfiguration : allConfigurations) {
- if (existingConfiguration.key.equals(configuration.key)) {
+ if (ALL_CONFIGURATIONS.putIfAbsent(configuration.key(), configuration) != null) {
+ throw new IllegalArgumentException(
+ String.format("Config '%s' is already in use", configuration.key));
+ }
+ if (configuration.hasCatalogConfig()) {
+ if (!ALL_CATALOG_CONFIGS.add(configuration.catalogConfig())) {
throw new IllegalArgumentException(
- String.format("Config '%s' is already in use", configuration.key));
- } else {
- var configs =
- Stream.of(
- configuration.catalogConfigImpl,
- configuration.catalogConfigUnsafeImpl,
- existingConfiguration.catalogConfigImpl,
- existingConfiguration.catalogConfigUnsafeImpl)
- .flatMap(Optional::stream)
- .collect(Collectors.groupingBy(Function.identity(), Collectors.counting()));
- for (var entry : configs.entrySet()) {
- if (entry.getValue() > 1) {
- throw new IllegalArgumentException(
- String.format("Catalog config %s is already in use", entry.getKey()));
- }
- }
+ String.format("Catalog config '%s' is already in use", configuration.catalogConfig()));
+ }
+ }
+ if (configuration.hasCatalogConfigUnsafe()) {
+ if (!ALL_CATALOG_CONFIGS.add(configuration.catalogConfigUnsafe())) {
+ throw new IllegalArgumentException(
+ String.format(
+ "Catalog config '%s' is already in use", configuration.catalogConfigUnsafe()));
}
}
- allConfigurations.add(configuration);
}
- /** Returns a list of all PolarisConfigurations that have been registered */
+ /** Returns a list of all PolarisConfigurations that have been registered. */
public static List<PolarisConfiguration<?>> getAllConfigurations() {
Review Comment:
Now unused.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@polaris.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org