Skip to content

Comments

DeterministicQueue refactor and enhancement#140151

Merged
elasticsearchmachine merged 34 commits intoelastic:mainfrom
ywangd:deterministic-queue-refactor
Jan 7, 2026
Merged

DeterministicQueue refactor and enhancement#140151
elasticsearchmachine merged 34 commits intoelastic:mainfrom
ywangd:deterministic-queue-refactor

Conversation

@ywangd
Copy link
Member

@ywangd ywangd commented Jan 5, 2026

This PR makes following changes to DeterministicTaskQueue

  1. Promote the anonymous ThreadPool class to a named inner class, DeterministicThreadPool.
  2. Fix threadContext preservation for all tasks
  3. Add a basic implementation for ScheduledExecutorService#schedule(Runnable, long, TimeUnit).

The PR is split from #138333

Also support waiting for a condition before starting the restart node.
@ywangd ywangd requested a review from DaveCTurner January 5, 2026 07:12
@ywangd ywangd added >test Issues or PRs that are addressing/adding tests :Distributed Coordination/Distributed labels Jan 5, 2026
@ywangd ywangd added the v9.4.0 label Jan 5, 2026
@elasticsearchmachine
Copy link
Collaborator

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

@elasticsearchmachine elasticsearchmachine added the Team:Distributed Coordination (obsolete) Meta label for Distributed Coordination team. Obsolete. Please do not use. label Jan 5, 2026
Copy link
Contributor

@DaveCTurner DaveCTurner left a comment

Choose a reason for hiding this comment

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

Nice, LGTM

FutureUtils.cancel(cancelledBeforeExecution);
taskQueue.runAllTasks();

assertThat(strings, containsInAnyOrder("runnable", "also runnable", "deferred", "not quite so deferred", "further deferred"));
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: maybe should be a Set<String> if we don't care about the order?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yep changed in d6d1bd4

Copy link
Contributor

Choose a reason for hiding this comment

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

I meant so that we can just say equals(Set.of(...)) here.

But I think I was confused by the name containsInAnyOrder - not only does this check that the collection contains those items in any order, but also apparently that it only contains those items. TIL. So we were already checking for set equality here.

Shame that these things have to be cast to (Runnable) now. Maybe I prefer it how it was.

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah both contains and containsInAnyOrder are quite confusing names.
I reverted in db8a451
Thanks

@ywangd ywangd added the auto-merge-without-approval Automatically merge pull request when CI checks pass (NB doesn't wait for reviews!) label Jan 5, 2026
Copy link
Contributor

@DaveCTurner DaveCTurner left a comment

Choose a reason for hiding this comment

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

LGTM still but maybe I prefer how it was...

FutureUtils.cancel(cancelledBeforeExecution);
taskQueue.runAllTasks();

assertThat(strings, containsInAnyOrder("runnable", "also runnable", "deferred", "not quite so deferred", "further deferred"));
Copy link
Contributor

Choose a reason for hiding this comment

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

I meant so that we can just say equals(Set.of(...)) here.

But I think I was confused by the name containsInAnyOrder - not only does this check that the collection contains those items in any order, but also apparently that it only contains those items. TIL. So we were already checking for set equality here.

Shame that these things have to be cast to (Runnable) now. Maybe I prefer it how it was.

@elasticsearchmachine elasticsearchmachine merged commit 12ad949 into elastic:main Jan 7, 2026
35 checks passed
@ywangd ywangd deleted the deterministic-queue-refactor branch January 7, 2026 00:27
szybia added a commit to szybia/elasticsearch that referenced this pull request Jan 7, 2026
* upstream/main: (191 commits)
  Overall Decision for Deciders prioritizes THROTTLE (elastic#140237)
  Apply group by all logic not only to top-level aggregates (elastic#140248)
  [ES|QL] Refactor MV_UNION and MV_INTERSECTION to use shared set operation helper (elastic#139982)
  Avoid reading entire bloom filter file on reader open (elastic#139374)
  Mark bloom filter files for random access (elastic#139375)
  Ensure that the buffer used for ES93BloomFilterStoredFieldsFormat is zeroed (elastic#139034)
  Add busy assertion to avoid race condition for testStalledShardMigrationProperlyDetected (elastic#140230)
  Remove line number check for testTransitiveFindsDeepCallChain (elastic#140228)
  Allow a slight difference in rescored docs (elastic#139931)
  Mute org.elasticsearch.xpack.inference.integration.AuthorizationTaskExecutorIT testCreatesEisChatCompletion_DoesNotRemoveEndpointWhenNoLongerAuthorized elastic#138480
  Start exchange sink fetchers concurrently (elastic#140196)
  Allow allocation to replacement target node on vacate completion (elastic#140150)
  Ignore JNA cleaner threads in SecureHdfsRepositoryAnalysisRestIT (elastic#139925)
  DeterministicQueue refactor and enhancement (elastic#140151)
  Always error out if CCS expression shows up when CCS is not supported (elastic#139009)
  Use IllegalArgumentException over RepositoryException for readonly-repository checks (elastic#140200)
  Guard promql capabilities in AnalyzerTests (elastic#140232)
  [Inference API] Fix flaky AuthorizationTaskExecutorIT tests (elastic#139978)
  Cleaning up exitable vector value impls (elastic#140190)
  [Inference API] Fix auth exception listener not called bug (elastic#139966)
  ...
sidosera pushed a commit to sidosera/elasticsearch that referenced this pull request Jan 7, 2026
This PR makes following changes to DeterministicTaskQueue 1. Promote the
anonymous ThreadPool class to a named inner class,
`DeterministicThreadPool`. 2. Fix threadContext preservation for all
tasks 3. Add a basic implementation for
`ScheduledExecutorService#schedule(Runnable, long, TimeUnit)`. 

The PR is split from elastic#138333
@repantis repantis added :Distributed/Distributed A catch all label for anything in the Distributed Area. Please avoid if you can. and removed :Distributed Coordination/Distributed labels Jan 28, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

auto-merge-without-approval Automatically merge pull request when CI checks pass (NB doesn't wait for reviews!) :Distributed/Distributed A catch all label for anything in the Distributed Area. Please avoid if you can. Team:Distributed Coordination (obsolete) Meta label for Distributed Coordination team. Obsolete. Please do not use. >test Issues or PRs that are addressing/adding tests v9.4.0

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants