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

Remove SqlQueryScheduler#abort method #13416

Merged
merged 1 commit into from
Aug 16, 2022

Conversation

arhimondr
Copy link
Contributor

Description

SqlQueryScheduler registers a query state listener internally to
terminate query scheduling when the query is cancelled, failed or
finished early

Is this change a fix, improvement, new feature, refactoring, or other?

Refactor

Is this a change to the core query engine, a connector, client library, or the SPI interfaces? (be specific)

Core engine

How would you describe this change to a non-technical end user or system administrator?

Non user visible

Related issues, pull requests, and links

-

Documentation

(X) No documentation is needed.
( ) Sufficient documentation is included in this PR.
( ) Documentation PR is available with #prnumber.
( ) Documentation issue #issuenumber is filed, and can be handled later.

Release notes

(X) No release notes entries required.
( ) Release notes entries required with the following suggested text:

# Section
* Fix some things. ({issue}`issuenumber`)

// directly since the callback may have already fired
if (stateMachine.isDone()) {
scheduler.abort();
queryScheduler.set(null);
Copy link
Member

Choose a reason for hiding this comment

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

Shouldn't queryScheduler.set(null); be called anyway (e.g. to free resources)?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The queryScheduler variable is nullified in buildQueryInfo after building a final query info. It is currently not nullified in case of a failure or completion anywhere else, thus it seemed to be weird to nullify it here.

Copy link
Member

Choose a reason for hiding this comment

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

It is currently not nullified in case of a failure or completion anywhere else, thus it seemed to be weird to nullify it here.

So was this a race between buildQueryInfo and nullification here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I doubt there any. It looked very weird. Later on there's another check where the scheduler is not getting nullified: https://github.com/trinodb/trino/blob/master/core/trino-main/src/main/java/io/trino/execution/SqlQueryExecution.java#L423.

}

// query is now done, so abort any work that is still running
SqlQueryScheduler scheduler = queryScheduler.get();
Copy link
Member

Choose a reason for hiding this comment

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

Do we have test for aborting? Can it be that this listener covers some flow that is not covered by SqlQueryScheduler?

Copy link
Contributor Author

@arhimondr arhimondr Aug 1, 2022

Choose a reason for hiding this comment

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

Today the SqlQueryScheduler is responsible of attaching the listeners that terminate the scheduling process upon query completion (due to a failure / cancellation or early finish): https://github.com/trinodb/trino/blob/master/core/trino-main/src/main/java/io/trino/execution/scheduler/SqlQueryScheduler.java#L303. SqlQueryScheduler attaches the listener before the scheduling process starts and uses an internal lock to prevent race conditions.

These listeners do exactly what the abort method does. Having an external listener calling the abort method is not necessary and might be confusing for the readers.

Copy link
Member

@sopel39 sopel39 left a comment

Choose a reason for hiding this comment

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

I would like another set of eyes to look at it, e.g: @losipiuk or @martint

// directly since the callback may have already fired
if (stateMachine.isDone()) {
scheduler.abort();
queryScheduler.set(null);
Copy link
Member

Choose a reason for hiding this comment

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

It is currently not nullified in case of a failure or completion anywhere else, thus it seemed to be weird to nullify it here.

So was this a race between buildQueryInfo and nullification here?

SqlQueryScheduler registers a query state listener internally to
terminate query scheduling when the query is cancelled, failed or
finished early
@arhimondr arhimondr force-pushed the drop-scheduler-abort-method branch from ba50d50 to 671aeb9 Compare August 2, 2022 15:30
@arhimondr arhimondr merged commit 6589ba6 into trinodb:master Aug 16, 2022
@arhimondr arhimondr deleted the drop-scheduler-abort-method branch August 16, 2022 21:40
@github-actions github-actions bot added this to the 393 milestone Aug 16, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

Successfully merging this pull request may close these issues.

4 participants