-
Notifications
You must be signed in to change notification settings - Fork 25k
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
Nonblocking master service #94325
Nonblocking master service #94325
Conversation
The changes introduced in elastic#92021 mean that there is no need for the master service to block its thread while waiting for each publication to complete. This commit removes the now-unnecessary blocking. This commit also removes the now-unnecessary fake blocking in the `FakeThreadPoolMasterService` used in tests, bringing the implementation covered by tests closer to the production implementation.
844ad98
to
b0a4aa8
Compare
@@ -2369,7 +2377,7 @@ public void taskSucceeded(ClusterStateUpdateTask clusterStateTaskListener, Void | |||
public ClusterState execute(ClusterState currentState) { | |||
assertEquals(priority, prioritiesQueue.poll()); | |||
assertEquals(priority, priority()); | |||
return currentState; | |||
return randomBoolean() ? currentState : ClusterState.builder(currentState).build(); |
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.
We're using a single-threaded executor here, so by sometimes triggering a publication and sometimes forking the publication handling onto a separate thread we demonstrate that there is no longer any blocking involved in the publication process.
Pinging @elastic/es-distributed (Team:Distributed) |
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.
tip: ignoring whitespace will make this easier to review
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 this looks good, but have a question/comment that you can maybe clarify quickly?
server/src/main/java/org/elasticsearch/cluster/service/MasterService.java
Show resolved
Hide resolved
Bah, ok, we're not always on the master thread where I thought we were (because rejections might leave us on the applier thread). I'll remove that comment for now and follow up later. |
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.
LGTM.
threadPool.executor(randomFrom(ThreadPool.Names.SAME, ThreadPool.Names.GENERIC)).execute(() -> { | ||
final var threadName = Thread.currentThread().getName(); | ||
try { | ||
Thread.currentThread().setName("[" + MasterService.MASTER_UPDATE_THREAD_NAME + "]"); |
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 seems unnecessary now that we use the ThreadedActionListener
. I think we should remove this line (and the try-finally), that would validate that we can call the publish listener from any thread.
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, yes - see 464358c.
These tests submit tasks to the master service and wait for the state to be applied, but not for the publication to complete, and without that wait they may clean up too soon. This commit makes them wait for the master service to finish its work before cleaning up. Relates elastic#94325 Closes elastic#94900
In elastic#94325 we introduced another forking step when submitting a publication, so we must extend the timeout in this test (and `DEFAULT_CLUSTER_STATE_UPDATE_DELAY`) by `DEFAULT_DELAY_VARIABILITY`. Closes elastic#94905
The changes introduced in #92021 mean that there is no need for the master service to block its thread while waiting for each publication to complete. This commit removes the now-unnecessary blocking.
This commit also removes the now-unnecessary fake blocking in the
FakeThreadPoolMasterService
used in tests, bringing the implementation covered by tests closer to the production implementation.