-
Notifications
You must be signed in to change notification settings - Fork 2.7k
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
Use the new Vertx local context storage #40725
base: main
Are you sure you want to change the base?
Conversation
extensions/vertx/runtime/src/main/java/io/quarkus/vertx/core/runtime/QuarkusAccessModes.java
Outdated
Show resolved
Hide resolved
extensions/vertx/runtime/src/main/java/io/quarkus/vertx/core/runtime/VertxLocalsHelper.java
Show resolved
Hide resolved
extensions/vertx/runtime/src/main/java/io/quarkus/vertx/runtime/VertxCurrentContextFactory.java
Outdated
Show resolved
Hide resolved
extensions/vertx/runtime/src/main/java/io/quarkus/vertx/runtime/VertxCurrentContextFactory.java
Outdated
Show resolved
Hide resolved
extensions/vertx/runtime/src/main/java/io/quarkus/vertx/runtime/VertxCurrentContextFactory.java
Outdated
Show resolved
Hide resolved
extensions/vertx/runtime/src/main/java/io/quarkus/vertx/runtime/VertxCurrentContextFactory.java
Outdated
Show resolved
Hide resolved
PTAL @mariofusco @mkouba Note: I'm still concerned about the ordering by which these statically defined "keys" are generated, in order to happen before |
extensions/vertx/runtime/src/main/java/io/quarkus/vertx/runtime/VertxCurrentContextFactory.java
Show resolved
Hide resolved
extensions/vertx/runtime/src/main/java/io/quarkus/vertx/runtime/VertxCurrentContextFactory.java
Outdated
Show resolved
Hide resolved
In order to enforce the ordering of key creation I should make a vertx provider which is look-up before |
* This provider exists with the sole purpose of reliably get the optimized local keys created before | ||
* the Vertx instance is created. | ||
*/ | ||
public class QuarkusLocalStorageKeyVertxServiceProvider implements VertxServiceProvider { |
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.
@geoand @cescoffier I don't like to make spi loading to happen just for this TBH and I could, maybe, hack the Vertx
recorder to just perform the init at the right time, but IDK what's the cost of this, usually. Any suggestion?
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.
The question is: can we preload this at build time (static init). It would be interesting to do that and just use the result at runtime. I don't believe there is a good reason to change the SPI at runtime.
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 we can skip the service loading in this case and just use this class, no?
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.
Yeah, I don't believe we should allow any other implementation.
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.
thanks both, yeah, I'm not very happy about it either: so i can just have a not vertx service provider, but an holder class which is going to be initialized in the vertx recorder before vertx instances are allocated, wdyt?
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.
Sounds fine to me
extensions/vertx/runtime/src/main/java/io/quarkus/vertx/runtime/VertxCurrentContextFactory.java
Show resolved
Hide resolved
@@ -22,6 +24,11 @@ public static void throwOnRootContextAccess() { | |||
public static <T> T getLocal(ContextInternal context, Object key) { | |||
if (VertxContext.isDuplicatedContext(context)) { | |||
// We are on a duplicated context, allow accessing the locals | |||
if (key instanceof ContextLocalImpl<?>) { |
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.
@cescoffier I will probably add the new ContextLocal
-based methods to avoid this terrible hack .-.
I made it in order to have the existing code in the toggle to just use the now-deprecated methods and still get the benefit of the new API, but given that these methods are going to disappear to favour the new API, I'll probably tackle this on the current PR already, wdyt?
...ns/vertx/runtime/src/main/resources/META-INF/services/io.vertx.core.spi.VertxServiceProvider
Show resolved
Hide resolved
public static ContextLocal<Boolean> registerAccessToggleKey() { | ||
if (FULLY_DISABLED) | ||
return null; | ||
return ContextLocal.registerLocal(Boolean.class); |
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.
@vietj is this ok?
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.
this is not how it should be used imho
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.
what do you mean?
In our context (quarkus) we can disable specific keys, in a stable way (via the sys property), meaning that we don't have to register any local key there.
Do you have another way to provide a similar behaviour?
This PR will remain in draft till eclipse-vertx/vert.x#5215 is going to be into Vertx 4.x because ATM we have no way to duplicate "optimized" keys while creating a new duplicate context. |
This PR is still blocked by the mentioned eclipse-vertx/vert.x#5215 one, which should be ported to 4.x as well. |
@cescoffier https://github.com/eclipse-vertx/vertx-grpc/blob/main/vertx-grpc-context-storage/src/main/java/io/grpc/override/ContextStorageOverride.java#L27 probably I need to send a PR just to fix this which is should be broken in master |
This is to keep up with the Vertx API changes for eclipse-vertx/vert.x@88cf77b, although I'm not very happy with the current state (that's why is in draft):
VertxLocalsHelper.
is "stealthy" using the new API by intercepting when users are passingContextLocal
-like keys, which means performing 2 instanceof checks (one being an interface check too, which is not yet safe with JDK till 21...)TODO
parts, we have some ordering issue: we need the keys statically defined asACCESS_TOGGLE_KEY
to be initialized before instantiating theVertx
instance has to use them, due to https://github.com/eclipse-vertx/vert.x/blob/4.5.7/src/main/java/io/vertx/core/impl/VertxImpl.java#L194 which is forcing every new context creation to dedicate the fixed amount of "optimized" keys in the context's local storageAccessMode
I've defined is good enough that having a new method inAccessMode::putRelease
, would have been better IMO (@vietj )For @mkouba and @Ladicek : the new "optimized" API for local storage is double edge sword because it needs some care on init ordering, need some care in dev mode (I think, @geoand ? @Sanne ?) and requires to create local "permanent" keys only for the ones we're 100% are going to be stored on each context (and I need some help from @Ladicek and @mkouba for such, I have no IDEA!)
Additionally there are some weird things in the original API (but is ok, the purpose of dog fooding is indeed to try things and found how to use them!): @vietj see https://github.com/quarkusio/quarkus/compare/main...franz1981:quarkus:local_ctx?expand=1#diff-af571e338cf42e877b9b99b70840f0842b293365f18c24d5fb24c930e5b0b064R64: this one is just wrong, because we cannot query all the local storage
ContextLocal
's values stored in the source context...we cannot do it unless we have a new method asContextInternal::addLocals(ContextInternal from, AccessMode accessMode)