Skip to content

Use TaskId in TaskAwareRequest.createRequest #130131

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

Merged

Conversation

GalLalouche
Copy link
Contributor

@GalLalouche GalLalouche commented Jun 26, 2025

This PR resolves the TODOs introduced in #127472.

  1. Use TaskId instead of passing a node name and ID individually.
  2. After consideration, I've also decided to remove the other TODO in this file. Forcing the hundred+ implementors to use the version with the task ID isn't better design and just introduces stamp coupling to those implementations.

@GalLalouche GalLalouche added :Distributed Coordination/Task Management Issues for anything around the Tasks API - both persistent and node level. >refactoring Team:Distributed Coordination Meta label for Distributed Coordination team labels Jun 26, 2025
Use TaskId instead of passing a node name and ID individually.
@GalLalouche GalLalouche force-pushed the refactor/task_aware_request_task_id branch from 429db8b to 0f9d2bd Compare June 29, 2025 14:43
@GalLalouche GalLalouche requested a review from rjernst June 30, 2025 06:54
@GalLalouche GalLalouche marked this pull request as ready for review June 30, 2025 06:54
@GalLalouche GalLalouche requested a review from a team as a code owner June 30, 2025 06:54
@elasticsearchmachine
Copy link
Collaborator

Pinging @elastic/es-distributed-coordination (Team:Distributed Coordination)

@@ -141,9 +149,9 @@ public Task register(String type, String action, TaskAwareRequest request, boole
headers.put(key, httpHeader);
}
}
String localNodeId = Optional.ofNullable(lastDiscoveryNodes.getLocalNodeId()).orElse(initialNodeId);
Copy link
Member

Choose a reason for hiding this comment

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

The node id from NodeEnvironment isn't the "initial" node id, it is the node id. That's what is passed in to the local node in DiscoveryNodes, see the LocalNodeFactory in NodeConstruction.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

But can't lastDiscoverNodes change, thereby changing the node ID? Or is the applyClusterState not really meant for mutation, but rather is just a way to set this value post-construction?

Copy link
Member

Choose a reason for hiding this comment

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

The local node in DiscoveryNodes won't effectively change, see DiscoveryNodes.readFrom where the local node id is passed in, not ready from the wire.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

OK, I've renamed this to nodeId, and added a comment on the field to make its existence clearer.

@@ -141,9 +150,9 @@ public Task register(String type, String action, TaskAwareRequest request, boole
headers.put(key, httpHeader);
}
}
String localNodeId = Optional.ofNullable(lastDiscoveryNodes.getLocalNodeId()).orElse(nodeId);
Copy link
Member

Choose a reason for hiding this comment

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

Sorry I didn't make my point clear: there is no need to look at DiscoveryNodes at all, this is the node id, it can't change.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ah, got it! I've replaced to code to only use nodeId.

Copy link
Member

@rjernst rjernst left a comment

Choose a reason for hiding this comment

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

seems there are a few remaining places calling it "initial" node id. Also, the PR title should be updated, the "TODO refactor" is not needed

ThreadPool threadPool,
Set<String> taskHeaders,
Tracer tracer,
@Nullable String initialNodeId
Copy link
Member

Choose a reason for hiding this comment

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

This should not be nullable, and also not "initial"?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good catch! I've went over and removed all new @Nullable, and renamed initialNodeId to nodeId.

@GalLalouche GalLalouche force-pushed the refactor/task_aware_request_task_id branch from 7f0b984 to d4de01c Compare July 2, 2025 11:10
@GalLalouche GalLalouche changed the title TODO refactor: Use TaskId in TaskAwareRequest.createRequest Use TaskId in TaskAwareRequest.createRequest Jul 2, 2025
@@ -59,9 +59,7 @@ protected MockTransportService createTransportService() {
new NoneCircuitBreakerService(),
new SharedGroupFactory(Settings.EMPTY)
),
threadPool,
TransportService.NOOP_TRANSPORT_INTERCEPTOR,
Copy link
Contributor Author

@GalLalouche GalLalouche Jul 2, 2025

Choose a reason for hiding this comment

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

It seemed all clients passed the same Settings.EMPTY, interceptor, and null in the clusterSettings to this constructor (refactored to a factory method), so I've simplified the method by removing those parameters.

@GalLalouche GalLalouche requested a review from rjernst July 2, 2025 11:14
Copy link
Member

@rjernst rjernst left a comment

Choose a reason for hiding this comment

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

LGTM

@@ -96,10 +98,15 @@ public TaskManager(Settings settings, ThreadPool threadPool, Set<String> taskHea
}

public TaskManager(Settings settings, ThreadPool threadPool, Set<String> taskHeaders, Tracer tracer) {
Copy link
Member

Choose a reason for hiding this comment

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

please mention with a comment this is just for tests (creating the uuid). we should move all these uses to explicitly pass a test nodeid, but that can be a followup

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

@GalLalouche GalLalouche force-pushed the refactor/task_aware_request_task_id branch from 26af770 to 8fe47d9 Compare July 6, 2025 11:58
@GalLalouche
Copy link
Contributor Author

Thanks for the review @rjernst!

@GalLalouche GalLalouche enabled auto-merge (squash) July 6, 2025 11:58
@GalLalouche GalLalouche merged commit 96315ec into elastic:main Jul 6, 2025
32 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
:Distributed Coordination/Task Management Issues for anything around the Tasks API - both persistent and node level. >refactoring Team:Distributed Coordination Meta label for Distributed Coordination team v9.2.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants