Skip to content
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

Add a temporary config property to allow multiple resources #40365

Merged
merged 6 commits into from
May 14, 2024

Conversation

gsmet
Copy link
Member

@gsmet gsmet commented Apr 30, 2024

The plan is to remove this property in the future but we need to provide a way for people to update to latest security fixes without having to significantly adjust their applications.

When we remove it, we need to document this breaking change properly and also provide guidance on how to fix the most common issues that could be encountered due to this breaking change.

TODO:

  • Document in the 3.8 migration guide (and maybe the other versions too) - the migration guide should clearly state the error message so that people can find it with the error message
  • I wonder if we should have a paragraph in the documentation too, again with the explicit error message and strategies on how to fix the apps (part of this section should stay in 3.11 as the plan is to drop the property).

Fixes #39283

@gsmet gsmet requested review from Sanne, maxandersen and yrodiere April 30, 2024 10:48
@quarkus-bot quarkus-bot bot added the area/narayana Transactions / Narayana label Apr 30, 2024
Copy link
Member

@Sanne Sanne left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great to me.

I'm not 100% sure if we should really remove this in the future - yes we should be clear that we don't recommend (nor support!) this option, and perhaps even link to an explainer (a Narayana article/blog would be great to explain to people why this is important!), but I'd be willing to be pragmatic about it: some people might appreciate that, especially while creating POCs.

@gsmet
Copy link
Member Author

gsmet commented Apr 30, 2024

/cc @mmusgrov @zhfeng

Copy link
Contributor

@zhfeng zhfeng left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @gsmet - LGTM !

Copy link
Contributor

@mmusgrov mmusgrov left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The code changes are good but I have requested additional text for the javadoc for the new config property.

@mmusgrov
Copy link
Contributor

Looks great to me.

I'm not 100% sure if we should really remove this in the future - yes we should be clear that we don't recommend (nor support!) this option, and perhaps even link to an explainer (a Narayana article/blog would be great to explain to people why this is important!), but I'd be willing to be pragmatic about it: some people might appreciate that, especially while creating POCs.

This was my concern, once it's in there will be reluctance to remove it. It is useful for development but I haven't been able to come up with any other use-case.

@gsmet gsmet force-pushed the allow-multiple-resources branch from e29ccea to 2931a6e Compare April 30, 2024 11:30
@gsmet
Copy link
Member Author

gsmet commented Apr 30, 2024

I included @mmusgrov 's changes and changed the wording a bit for the removal, asking users to open issues if they see a valid use case. That way we will be able to take an educated decision in the future.

@gsmet
Copy link
Member Author

gsmet commented Apr 30, 2024

@mmusgrov I did some further tests with the reproducer and I encountered the following warning twice:

2024-04-30 14:07:03,796 WARN [com.arj.ats.arjuna] (Camel (camel-1) thread #1 - scheduler://read-clean-write) ARJUNA012141: Multiple last resources have been added to the current transaction. This is transactionally unsafe and should not be relied upon. Current resource is LastResourceRecord(XAOnePhaseResource(io.agroal.narayana.LocalXAResource@68e1bf3d))

Is it a warning that will be logged for each transaction? Because if so I don't think it will fly as we will flood the log.

@gsmet
Copy link
Member Author

gsmet commented Apr 30, 2024

OK, I filtered your warnings and added a warning of our own saying:

2024-04-30 14:24:05,908 WARN [io.qua.nar.jta.run.NarayanaJtaRecorder] (main) Setting quarkus.transaction-manager.allow-unsafe-multiple-last-resources to true makes adding multiple resources to the same transaction unsafe.

I think this should be good enough. It will be displayed only once when the application is started.

@Sanne
Copy link
Member

Sanne commented Apr 30, 2024

I think this should be good enough. It will be displayed only once when the application is started.

Just curious, you really mean it's going to be shown once? I didn't know we had that capability.

@mmusgrov
Copy link
Contributor

OK, I filtered your warnings and added a warning of our own saying:

2024-04-30 14:24:05,908 WARN [io.qua.nar.jta.run.NarayanaJtaRecorder] (main) Setting quarkus.transaction-manager.allow-unsafe-multiple-last-resources to true makes adding multiple resources to the same transaction unsafe.

I think this should be good enough. It will be displayed only once when the application is started.

@gsmet There is another property to disable it:

`arjPropertyManager.getCoreEnvironmentBean().setDisableMultipleLastResourcesWarning`

But the warning should only be issued once for each last resource, since you have two such last resources I'd expect to see it printed twice. I think it's valid to report the warning on each such attempt to register a last resource, ie I don't think it should be swallowed.

@mmusgrov
Copy link
Contributor

ie I think it's valid to report the warning on each attempt to register a last resource (we only report it once per offending resource anyway), ie I don't think the second one should be swallowed since the user needs to know that he's heading into choppy waters with the second resource.

@gsmet gsmet force-pushed the allow-multiple-resources branch from becf17b to 2931a6e Compare April 30, 2024 13:44
@gsmet
Copy link
Member Author

gsmet commented Apr 30, 2024

Ah OK, if it's issued only once then it's all good. I removed the two additional commits then.

@mmusgrov
Copy link
Contributor

Actually I think it may still be printed on each transaction unless that property (setDisableMultipleLastResourcesWarning) is set. The check for whether to report a warning is here. Would you be able to check your reproducer with two transactions?

@mmusgrov
Copy link
Contributor

We also print a warning during start up if setAllowMultipleLastResources(true) has been called.

@mmusgrov
Copy link
Contributor

Similarly if setDisableMultipleLastResourcesWarning(true) has been called. As you can probably tell, we are keen to let the user know he's using multiple last resources.

gsmet added 2 commits May 14, 2024 09:28
The plan is to remove this property in 3.11 but we need to provide a way
for people to update to latest security fixes without having to
significantly adjust their applications.

In 3.11, we need to document this breaking change properly and also
provide guidance on how to fix the most common issues that could be
encountered due to this breaking change.
This to make sure we have a consistent experience between JVM and native
modes.
@Sanne
Copy link
Member

Sanne commented May 14, 2024

@Sanne :

I've made some suggestions to clarify the docs about this; in particular it seems to suggest that the defaults don't allow to use multiple XA resources which isn't exact.

Well technically XA isn't enabled by default, so the documentation is exact. If you want more datasources, you need extra configuration: enable XA, or use workarounds. That's why the documentation is structured this way.

I can rephrase the first sentence like this if you want:

By default, a transaction may include at most one non-XA datasource.

Yes please, it's much more precise and clear.

But I'd keep the same structure, as I suspect the people needing this section the most will not be familiar with XA. WDYT?

I'm surprised that you'd hink that most users will not be familiar with XA. Sure, I don't expect many to be expert in it, but at least being familiar with the notion should be a requirement to make applications.

@yrodiere
Copy link
Member

yrodiere commented May 14, 2024

but at least being familiar with the notion should be a requirement to make applications.

Sanne, people struggle with basic SQL.

EDIT: Besides, I'm not worried about "most users", but rather about "the minority who doesn't understand this stuff and will need this documentation the most".

yrodiere added 4 commits May 14, 2024 11:38
…ces` into `quarkus.transaction-manager.unsafe-multiple-last-resources`

* The property is now named `quarkus.transaction-manager.unsafe-multiple-last-resources`
* It has three possible values:
   * `allow`: allow unsafe multiple last resources, no warning per offending transaction
   * `warn`: allow unsafe multiple last resources, one warning log per offending transaction
   * `fail`: fail on unsafe multiple last resources
* It will log a warning on startup if *explicitly* set to `allow` or `warn`.
* It defaults to `fail` in this commit.
* The plan is to make it default to `warn` in 3.8, which means no log on startup,
  but one per offending transaction.
  People will be able to set it to `allow` explicitly to suppress the warning per
  offending transaction,
  but will get a warning on startup (since they set the property explicitly).
The log level we get in beforeAnalysis may be null, in which case we
still want to reset it after analysis.

From the javadoc of Logger#getLevel:

> Get the log Level that has been specified for this Logger.
> The result may be null, which means that this logger's effective level will be inherited from its parent.
@yrodiere yrodiere force-pushed the allow-multiple-resources branch from 27d4ca9 to 3b008a8 Compare May 14, 2024 09:42
Copy link
Member

@yrodiere yrodiere left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I addressed @Sanne 's comments and split the warn option.

So here's what we have now:

  • The property is named quarkus.transaction-manager.unsafe-multiple-last-resources
  • It has four possible values:
    • allow: allow unsafe multiple last resources, no warning per offending transaction
    • warn-first: allow unsafe multiple last resources, one warning on the first offending transaction only, no warning after that
    • warn-each: allow unsafe multiple last resources, one warning log per offending transaction
    • fail: fail on unsafe multiple last resources
  • It will log a warning on startup if explicitly set to allow or warn-first or warn-each.
  • It defaults to fail in this PR.
  • The plan is to make it default to warn-first in 3.8, which means no log on startup, but one per offending transaction. People will be able to set it to allow explicitly to suppress the warning on the first transaction, but will get a warning on startup (since they set the property explicitly).

@gsmet you can test this using my fork of the reproducer, which processes batches of 2 items, so it'll open multiple transactions: https://github.com/yrodiere/quarkus-camel-transactions/tree/fix

docs/src/main/asciidoc/datasource.adoc Outdated Show resolved Hide resolved
docs/src/main/asciidoc/datasource.adoc Outdated Show resolved Hide resolved
docs/src/main/asciidoc/datasource.adoc Show resolved Hide resolved
docs/src/main/asciidoc/datasource.adoc Outdated Show resolved Hide resolved
docs/src/main/asciidoc/datasource.adoc Outdated Show resolved Hide resolved
Copy link

quarkus-bot bot commented May 14, 2024

Status for workflow Quarkus Documentation CI

This is the status report for running Quarkus Documentation CI on commit 3b008a8.

✅ The latest workflow run for the pull request has completed successfully.

It should be safe to merge provided you have a look at the other checks in the summary.

⚠️ There are other workflow runs running, you probably need to wait for their status before merging.

Copy link

quarkus-bot bot commented May 14, 2024

Status for workflow Quarkus CI

This is the status report for running Quarkus CI on commit 3b008a8.

✅ The latest workflow run for the pull request has completed successfully.

It should be safe to merge provided you have a look at the other checks in the summary.

You can consult the Develocity build scans.

@yrodiere yrodiere requested a review from Sanne May 14, 2024 11:37
@gsmet gsmet dismissed Sanne’s stale review May 14, 2024 13:15

I think Yoann addressed your concerns and we can tweak the doc further later if needed. I'm trying to wrap up 3.11.0.CR1 and 3.10.1.

@gsmet gsmet merged commit 77c033f into quarkusio:main May 14, 2024
45 checks passed
@quarkus-bot quarkus-bot bot added this to the 3.11 - main milestone May 14, 2024
@mmusgrov
Copy link
Contributor

@shawkins @yrodiere Reporting mixed outcomes (first resource commits and the second one rolls back) from XA unaware participants requires some invasive changes to ArjunaCore so that we can support crash recovery and it will take us a while to design the changes. But we can detect such heuristic outcomes so would it be sufficient, in the short term, to log a WARNing instead and longer term we'd report the HeuristicMixedException?

Note also that the probability of mixed outcomes is much higher than LRCO because the window between committing the first and second resources includes a network call so that window is quite long compared to the LRCO window of exposure.

@yrodiere
Copy link
Member

I'll let @shawkins answer about the HeuristicMixedException, personally I'm not familiar with that. I think @shawkins wanted to open a dedicated issue about the specific needs of Keycloak in this area?

As far as I'm concerned, logging a warning in case of dodgy rollbacks seems like a reasonable first step, at least better than no information at all. I'm not sure it will help a lot but it will at least help debugging.

Though IMO solving #40431 (getting a clear exception in case of multiple non-XA datasources in a single transaction) would be more beneficial to Quarkus users in general -- those who didn't enable dangerous settings.

@shawkins
Copy link
Contributor

I'll let @shawkins answer about the HeuristicMixedException, personally I'm not familiar with that. I think @shawkins wanted to open a dedicated issue about the specific needs of Keycloak in this area?

The main concern is around making users aware / documenting that a mixed situation has occurred. If that's via log, it will work as a first step.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/docstyle issues related for manual docstyle review area/documentation area/narayana Transactions / Narayana kind/bugfix triage/flaky-test
Projects
8 participants