From 3b008a85612ba42fe7a75777aa6ff54e26e3a987 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Yoann=20Rodi=C3=A8re?= Date: Tue, 14 May 2024 09:49:53 +0200 Subject: [PATCH] Rework `quarkus.transaction-manager.unsafe-multiple-last-resources` to accept `warn-first` and `warn-each` --- docs/src/main/asciidoc/datasource.adoc | 10 +++++++--- .../narayana/jta/deployment/NarayanaJtaProcessor.java | 11 +++++++++-- .../narayana/jta/runtime/NarayanaJtaRecorder.java | 4 ++-- .../runtime/TransactionManagerBuildTimeConfig.java | 7 ++++++- 4 files changed, 24 insertions(+), 8 deletions(-) diff --git a/docs/src/main/asciidoc/datasource.adoc b/docs/src/main/asciidoc/datasource.adoc index 74789deccc678..8c40a26fe3580 100644 --- a/docs/src/main/asciidoc/datasource.adoc +++ b/docs/src/main/asciidoc/datasource.adoc @@ -579,9 +579,13 @@ could possibly be applied to only some of the non-XA datasources, with other non-XA datasources having already committed their changes, leaving your overall system in an inconsistent state. -Setting this property to `warn` leads to the same unsafe behavior, -but with a warning being logged on each offending transaction, -instead of a single one on startup. +Alternatively, you can allow the same unsafe behavior, +but with warnings when it is taken advantage of: + +* setting the property to `warn-each` +would result in logging a warning on *each* offending transaction. +* setting the property to `warn-first` +would result in logging a warning on the *first* offending transaction. We do not recommend using this configuration property, and we plan to remove it in the future, diff --git a/extensions/narayana-jta/deployment/src/main/java/io/quarkus/narayana/jta/deployment/NarayanaJtaProcessor.java b/extensions/narayana-jta/deployment/src/main/java/io/quarkus/narayana/jta/deployment/NarayanaJtaProcessor.java index 63b968dac6f9c..51cce765f1fa9 100644 --- a/extensions/narayana-jta/deployment/src/main/java/io/quarkus/narayana/jta/deployment/NarayanaJtaProcessor.java +++ b/extensions/narayana-jta/deployment/src/main/java/io/quarkus/narayana/jta/deployment/NarayanaJtaProcessor.java @@ -182,7 +182,14 @@ public void allowUnsafeMultipleLastResources(NarayanaJtaRecorder recorder, logCleanupFilters.produce( new LogCleanupFilterBuildItem("com.arjuna.ats.arjuna", "ARJUNA012139", "ARJUNA012141", "ARJUNA012142")); } - case WARN -> { + case WARN_FIRST -> { + recorder.allowUnsafeMultipleLastResources(capabilities.isPresent(Capability.AGROAL), true); + // we will handle the warnings ourselves at runtime init when the option is set explicitly + // but we still want Narayana to produce a warning on the first offending transaction + logCleanupFilters.produce( + new LogCleanupFilterBuildItem("com.arjuna.ats.arjuna", "ARJUNA012139", "ARJUNA012142")); + } + case WARN_EACH -> { recorder.allowUnsafeMultipleLastResources(capabilities.isPresent(Capability.AGROAL), false); // we will handle the warnings ourselves at runtime init when the option is set explicitly // but we still want Narayana to produce one warning per offending transaction @@ -199,7 +206,7 @@ public void nativeImageFeature(TransactionManagerBuildTimeConfig transactionMana BuildProducer nativeImageFeatures) { switch (transactionManagerBuildTimeConfig.unsafeMultipleLastResources .orElse(UnsafeMultipleLastResourcesMode.DEFAULT)) { - case ALLOW, WARN -> { + case ALLOW, WARN_FIRST, WARN_EACH -> { nativeImageFeatures.produce(new NativeImageFeatureBuildItem(DisableLoggingFeature.class)); } } diff --git a/extensions/narayana-jta/runtime/src/main/java/io/quarkus/narayana/jta/runtime/NarayanaJtaRecorder.java b/extensions/narayana-jta/runtime/src/main/java/io/quarkus/narayana/jta/runtime/NarayanaJtaRecorder.java index 3f858f774e592..156dbd6d1c865 100644 --- a/extensions/narayana-jta/runtime/src/main/java/io/quarkus/narayana/jta/runtime/NarayanaJtaRecorder.java +++ b/extensions/narayana-jta/runtime/src/main/java/io/quarkus/narayana/jta/runtime/NarayanaJtaRecorder.java @@ -7,7 +7,6 @@ import java.util.Arrays; import java.util.Collections; import java.util.List; -import java.util.Locale; import java.util.Map; import java.util.Properties; import java.util.Set; @@ -30,6 +29,7 @@ import io.quarkus.runtime.ShutdownContext; import io.quarkus.runtime.annotations.Recorder; import io.quarkus.runtime.configuration.ConfigurationException; +import io.quarkus.runtime.util.StringUtil; @Recorder public class NarayanaJtaRecorder { @@ -132,7 +132,7 @@ public void logUnsafeMultipleLastResourcesOnStartup( TransactionManagerBuildTimeConfig.UnsafeMultipleLastResourcesMode mode) { log.warnf( "Setting quarkus.transaction-manager.unsafe-multiple-last-resources to '%s' makes adding multiple resources to the same transaction unsafe.", - mode.name().toLowerCase(Locale.ROOT)); + StringUtil.hyphenate(mode.name()).replace('_', '-')); } private void setObjectStoreDir(String name, TransactionManagerConfiguration config) { diff --git a/extensions/narayana-jta/runtime/src/main/java/io/quarkus/narayana/jta/runtime/TransactionManagerBuildTimeConfig.java b/extensions/narayana-jta/runtime/src/main/java/io/quarkus/narayana/jta/runtime/TransactionManagerBuildTimeConfig.java index 70cde49f3efe7..dced5709b63cc 100644 --- a/extensions/narayana-jta/runtime/src/main/java/io/quarkus/narayana/jta/runtime/TransactionManagerBuildTimeConfig.java +++ b/extensions/narayana-jta/runtime/src/main/java/io/quarkus/narayana/jta/runtime/TransactionManagerBuildTimeConfig.java @@ -42,11 +42,16 @@ public enum UnsafeMultipleLastResourcesMode { * but not on each use of multiple XA unaware resources in the same transactional demarcation. */ ALLOW, + /** + * Allow using multiple XA unaware resources in the same transactional demarcation, + * but log a warning on the first occurrence. + */ + WARN_FIRST, /** * Allow using multiple XA unaware resources in the same transactional demarcation, * but log a warning on each occurrence. */ - WARN, + WARN_EACH, /** * Allow using multiple XA unaware resources in the same transactional demarcation, * but log a warning on each occurrence.