-
Notifications
You must be signed in to change notification settings - Fork 3k
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
Sometimes EventListener.queryCompleted() called too early #20231
Sometimes EventListener.queryCompleted() called too early #20231
Conversation
@@ -22,6 +22,7 @@ | |||
import io.opentelemetry.api.trace.Tracer; | |||
import io.opentelemetry.context.Context; | |||
import io.trino.Session; |
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.
Please extend commit message, e.g: what was the problem?
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.
It is described in the PR description, but I now copied it to the commit extended message.
@@ -58,7 +57,6 @@ public FailedDispatchQuery createFailedDispatchQuery(Session session, String que | |||
BasicQueryInfo queryInfo = failedDispatchQuery.getBasicQueryInfo(); | |||
|
|||
queryMonitor.queryCreatedEvent(queryInfo); | |||
queryMonitor.queryImmediateFailureEvent(queryInfo, toFailure(throwable)); |
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.
Why having it here was causing race condition? queryCreatedEvent
is called just before anyway.
Why query has to be registered via queryTracker.addQuery
?
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 have provided relevant information in the extended commit message, like you asked in the other comment. Let me know whether it's clear now. If not, I will try again to describe it better.
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.
Consider adding QueryTracker
as an arg to createFailedDispatchQuery
. This way you don't have to add queryMonitor
to DispatchManager
54cc3a6
to
bc8163a
Compare
@@ -236,6 +241,7 @@ private <C> void createQueryInternal(QueryId queryId, Span querySpan, Slug slug, | |||
Optional<String> preparedSql = Optional.ofNullable(preparedQuery).flatMap(PreparedQuery::getPrepareSql); | |||
DispatchQuery failedDispatchQuery = failedDispatchQueryFactory.createFailedDispatchQuery(session, query, preparedSql, Optional.empty(), throwable); | |||
queryCreated(failedDispatchQuery); | |||
queryMonitor.queryImmediateFailureEvent(failedDispatchQuery.getBasicQueryInfo(), toFailure(throwable)); |
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 but add a comment whgy this is not happening within createFailedDispatchQuery
for future readers.
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.
Comment added. Let me know if this is what you meant and whether I can do anything else to get an approval?
For happy path and parsable queries, we have the following order of calls: - query is added to the QueryTracker - EventListener.queryCompleted() is called For really bad queries, the ones that do not even parse to a proper SQL, the order is inverted. As a result, when implementing an EventListener that wants to access query detailed information we have to use a workaround for this edge case and artificially invert the sequence of calls. EventListener will typically use a retry mechanism combined with switching to a separate thread, which adds unnecessary complexity and multi-threading to a code that otherwise would be single-threaded.
bc8163a
to
7b8bafb
Compare
Description
For really bad queries, the ones that do not even parse to a proper SQL, we have the following sequence of calls:
EventListener.queryCompleted()
QueryTracker
To work around incorrect sequence of these calls, an
EventListener
will typically use a retry mechanism combined with switching to a separate thread.This PR inverts the sequence of calls so that
EventListener
s can now be coded single-threaded.Additional context and related issues
Release notes
( X ) This is not user-visible or is docs only, and no release notes are required.
( ) Release notes are required. Please propose a release note for me.
( ) Release notes are required, with the following suggested text: