Skip to content

Clean up SqlQueryManager#11518

Merged
dain merged 11 commits intoprestodb:masterfrom
dain:SqlQueryManager-cleanup
Oct 17, 2018
Merged

Clean up SqlQueryManager#11518
dain merged 11 commits intoprestodb:masterfrom
dain:SqlQueryManager-cleanup

Conversation

@dain
Copy link
Contributor

@dain dain commented Sep 19, 2018

  • Fix warnings
  • Extract out complex book keeping like query timeout tracking
  • Simplify session creation code
  • Prepare manager for split into dispatcher and coordinator

@raghavsethi raghavsethi self-assigned this Sep 19, 2018
@raghavsethi raghavsethi self-requested a review September 19, 2018 00:51
@dain dain force-pushed the SqlQueryManager-cleanup branch 2 times, most recently from 8c52864 to f406efc Compare September 19, 2018 00:58
@facebook-github-bot
Copy link
Collaborator

Thank you for your pull request. We require contributors to sign our Contributor License Agreement, and yours has expired.

Before we can review or merge your code, we need you to email cla@fb.com with your details so we can update your status.

@dain dain force-pushed the SqlQueryManager-cleanup branch from f406efc to 0161718 Compare September 26, 2018 00:19
Copy link
Contributor

@raghavsethi raghavsethi left a comment

Choose a reason for hiding this comment

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

Fix IntelliJ warnings LGTM

Copy link
Contributor

@raghavsethi raghavsethi left a comment

Choose a reason for hiding this comment

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

Move worker specific bindings to WorkerModule LGTM

Copy link
Contributor

@raghavsethi raghavsethi left a comment

Choose a reason for hiding this comment

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

Fix raw use of ResourceGroupManager type LGTM. Thank you for cleaning up my mess.

Copy link
Contributor

@raghavsethi raghavsethi left a comment

Choose a reason for hiding this comment

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

Add abstraction for applying default session properties LGTM with nits.

@dain
Copy link
Contributor Author

dain commented Sep 26, 2018

The changes to auto commit handling depend on #11511. The TestTpchDistributedStats ends up using com.facebook.presto.tests.DistributedQueryRunner#createPlan which cancel's the query, triggering the auto commit cleanup, so later when com.facebook.presto.tests.statistics.MetricComparator#getEstimatedValuesInternal tries to calculate stats and access the metadata, and error is thrown because the transaction is gone.

Copy link
Contributor

@raghavsethi raghavsethi left a comment

Choose a reason for hiding this comment

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

Add abstraction for processing prepared statement has minor comments.

Copy link
Contributor

@raghavsethi raghavsethi left a comment

Choose a reason for hiding this comment

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

Add abstraction to manage abandonment and expiration of queries LGTM. As far as I can tell, this a pure refactor, no functional changes, right?

Copy link
Contributor

Choose a reason for hiding this comment

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

How would this appear in debugging/ops tools? What would the object name be?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Actually, this is totally wrong. QueryTracker is not exported to JMX, so it won't show up at all. I'm going to change query tracker to take the executor in the constructor, and will use the existing executor in the SqlQueryManager, so there will be no change to the existing JMX exports.

Copy link
Contributor

@raghavsethi raghavsethi left a comment

Choose a reason for hiding this comment

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

Simplify FailedQueryExecution has some question marks

Copy link
Contributor

Choose a reason for hiding this comment

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

I've never seen a public logger shared between classes. Not sure why we went in this direction.

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 QUERY_STATE_LOG is a special log that all of the query state changes are logged to, and I want to maintain that behavior.

Copy link
Contributor

Choose a reason for hiding this comment

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

Don't all failed queries become a FailedQueryExecution (including ones with resource groups)?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It makes the code a bit messier. How important is it to have this?

Copy link
Contributor

@raghavsethi raghavsethi left a comment

Choose a reason for hiding this comment

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

Inline FailedQueryExecution static factory LGTM

Copy link
Contributor

@raghavsethi raghavsethi left a comment

Choose a reason for hiding this comment

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

Remove unnecessary metadata cleanup in SqlQueryManager LGTM assuming you're sure that there is no case where metadata is created for a failed execution.

Copy link
Contributor

Choose a reason for hiding this comment

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

I thought there might be a race between the two calls, but it seems the only way to remove the transaction is to call asyncAbort which is guarded by the state machine.

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 extra call is required for ROLLBACK which immediately removes the transaction from the manager, so without the exists check the call to isAutoCommit fails. I looked as having an explicit check for ROLLBACK here, but that would require breaking to many abstractions. I also looked at making isAutoCommit, return Optional, or just false, for unknown queries, but that makes is difficult to work with in the normal case.

Copy link
Contributor

Choose a reason for hiding this comment

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

I think we can get rid of transactionControl now, here and all the way up, including in DataDefinitionTask.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@electrum transactionControl is used on the next line of this code: if (!session.getTransactionId().isPresent() && !transactionControl) {

@dain dain force-pushed the SqlQueryManager-cleanup branch 3 times, most recently from c883d82 to 497e2e5 Compare October 8, 2018 22:49
@dain
Copy link
Contributor Author

dain commented Oct 9, 2018

@raghavsethi changes applied. Please review again.

@electrum
Copy link
Contributor

electrum commented Oct 9, 2018

I reviewed the two transaction related commits and they look good.

@dain dain force-pushed the SqlQueryManager-cleanup branch 4 times, most recently from c5faf04 to 83568a2 Compare October 12, 2018 21:55
@raghavsethi
Copy link
Contributor

Looks good to merge after rebase + tests.

@dain dain force-pushed the SqlQueryManager-cleanup branch from 83568a2 to 26c7586 Compare October 17, 2018 00:25
@dain dain force-pushed the SqlQueryManager-cleanup branch from 26c7586 to 921fcf2 Compare October 17, 2018 01:13
Copy link
Contributor

@raghavsethi raghavsethi left a comment

Choose a reason for hiding this comment

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

Looks good.

dain added 11 commits October 16, 2018 20:54
Application of defaults during session creation conflicts with resource group
selection and query parsing. Separating out the application of default session
properties allows us to refactor query creation in SqlQueryManager.
Processing and validation of prepared statements is complex and performed
in several locations.
Instead of using a QueryStateMachine to create QueryInfo, add helpers to
directly create a QueryInfo for a failed query. Also add cleanup performed
by QueryStateMachine to FailedQueryExecution.
When a query fails during construction of QueryExecution, the metadata
system for the query has not be initialized, so clean up of metadata is
not necessary.
@dain dain force-pushed the SqlQueryManager-cleanup branch from 921fcf2 to 2002a15 Compare October 17, 2018 03:54
@dain dain closed this Oct 17, 2018
@dain dain deleted the SqlQueryManager-cleanup branch October 17, 2018 03:54
@dain dain merged commit 2002a15 into prestodb:master Oct 17, 2018
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.

4 participants