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

Support duplicated context duplication #5215

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

vietj
Copy link
Member

@vietj vietj commented May 30, 2024

Duplicating a duplicated context is supported but the semantic of the actual locals is not defined.

This update the duplicated context duplication by doing a copy of each local in the duplicated duplicate. This introduce a duplicator for each local that is responsible for copying the object when it is not null.

  • Periodic tasks should duplicate a duplicated context using this API ?

@vietj vietj added this to the 5.0.0 milestone May 30, 2024
@vietj vietj self-assigned this May 30, 2024
@vietj
Copy link
Member Author

vietj commented May 30, 2024

@franz1981 @cescoffier please have a look

@franz1981
Copy link
Contributor

This can be related (and better used at) quarkusio/quarkus#40725

can you checkout my branch there and show how the changes there will translate with the new API, bud? I'm travelling, but I would like, before it got merged, to make sure the semantic and behaviours won't change too much and instead we save some code by leveraging this new feature (which is super cool!)

@vietj
Copy link
Member Author

vietj commented May 30, 2024

for now this is a tentative PR, we can discuss next week @franz1981 I think

@franz1981
Copy link
Contributor

Yep, let's sync once I'm back, thanks @vietj 🙏


final int index;
final Class<T> type;
final Function<T, ? extends T> duplicator;
Copy link
Contributor

Choose a reason for hiding this comment

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

valueDuplicator

@@ -164,7 +164,28 @@ public boolean isWorkerContext() {

@Override
public ContextInternal duplicate() {
return new DuplicatedContext(delegate, locals.length == 0 ? VertxImpl.EMPTY_CONTEXT_LOCALS : new Object[locals.length]);
Object[] localsDuplicate = locals.length == 0 ? VertxImpl.EMPTY_CONTEXT_LOCALS : locals.clone();
ContextLocal<?>[] contextLocals = ((VertxImpl) delegate.owner()).contextLocals;
Copy link
Contributor

@franz1981 franz1981 May 30, 2024

Choose a reason for hiding this comment

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

Given that the CHM is forcibly at index 0 why we cannot just treat it already separately without having a specific interface to perform the duplication?

This will make the tight loop here to be replaced by an optimized Arrays's batch copy (using Arrays.copyOf-like methods) + a "special" reset of the 0 key - which is the CHM one

… actual locals is not defined.

This update the duplicated context duplication by doing a copy of each local in the duplicated duplicate. This introduce a duplicator for each local that is responsible for copying the object when it is not null.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants