-
Notifications
You must be signed in to change notification settings - Fork 13.2k
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
fix: SQL Lab show "Refetch Results" button while fetching new query results #15109
fix: SQL Lab show "Refetch Results" button while fetching new query results #15109
Conversation
eafbe9e
to
130c58a
Compare
Codecov Report
@@ Coverage Diff @@
## master #15109 +/- ##
==========================================
- Coverage 77.53% 77.24% -0.29%
==========================================
Files 967 969 +2
Lines 49740 50023 +283
Branches 6351 6436 +85
==========================================
+ Hits 38565 38640 +75
- Misses 10973 11178 +205
- Partials 202 205 +3
Flags with carried forward coverage won't be shown. Click here to find out more.
Continue to review full report at Codecov.
|
}; | ||
if (currentState === 'success') { | ||
// race condition: | ||
// because of asyc behavior, sql lab may still poll a couple of seconds |
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.
sp nit: async
let updatedState = { | ||
...changedQuery, | ||
}; | ||
if (currentState === 'success') { | ||
// race condition: | ||
// because of asyc behavior, sql lab may still poll a couple of seconds | ||
// when it started fetching or finished rendering results | ||
if (['fetching', 'success'].includes(prevState)) { | ||
updatedState = { | ||
...updatedState, | ||
state: prevState, | ||
}; | ||
} | ||
} | ||
newQueries[id] = { ...state.queries[id], ...updatedState }; |
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.
perhaps something like this is cleaner?
let updatedState = { | |
...changedQuery, | |
}; | |
if (currentState === 'success') { | |
// race condition: | |
// because of asyc behavior, sql lab may still poll a couple of seconds | |
// when it started fetching or finished rendering results | |
if (['fetching', 'success'].includes(prevState)) { | |
updatedState = { | |
...updatedState, | |
state: prevState, | |
}; | |
} | |
} | |
newQueries[id] = { ...state.queries[id], ...updatedState }; | |
newQueries[id] = { | |
...state.queries[id], | |
...changedQuery, | |
// race condition: | |
// because of async behavior, sql lab may still poll a couple of seconds | |
// when it started fetching or finished rendering results | |
state: currentState === 'success' && ['fetching', 'success'].includes(prevState) ? prevState : currentState | |
}; |
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.
yes much cleaner!
59059c7
to
94dcb9a
Compare
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, thanks for addressing comments
… query results (apache#15109)" This reverts commit 408d58f.
…esults (apache#15109) * fix: SQL Lab show "Refetch Results" button while fetching new query results * fix comments (cherry picked from commit 408d58f)
* fix: SQL Lab show "Refetch Results" button while fetching new query results (apache#15109) * fix: SQL Lab show "Refetch Results" button while fetching new query results * fix comments (cherry picked from commit 408d58f) * handle exception caused by invalid query id
…esults (apache#15109) * fix: SQL Lab show "Refetch Results" button while fetching new query results * fix comments
… query results (apache#15109)" (apache#15301) This reverts commit 408d58f.
* fix: SQL Lab show "Refetch Results" button while fetching new query results (apache#15109) * fix: SQL Lab show "Refetch Results" button while fetching new query results * fix comments (cherry picked from commit 408d58f) * handle exception caused by invalid query id
…esults (apache#15109) * fix: SQL Lab show "Refetch Results" button while fetching new query results * fix comments
… query results (apache#15109)" (apache#15301) This reverts commit 408d58f.
…esults (apache#15109) * fix: SQL Lab show "Refetch Results" button while fetching new query results * fix comments
… query results (apache#15109)" (apache#15301) This reverts commit e82ca65.
SUMMARY
when user run a query in SQL Lab, after query is done from engine, and then results are fetched into browser, SQL Lab should show results table. But when the results data is big, it may take a few seconds download. Many users saw the "Refetch results" button show up after query is succeed. Here is a screenshot:
I run a simple query against Presto engine:
Because it has a lot of data, it takes long time to download results. SQL Lab shows "Refetch results" for a few seconds, then after results are fetched, it shows results table.
This "Refetch Results" button is very confusing. Many users will just click the button, which cause SQL Lab even longer time to fetch results.
The root cause is pretty simple: race condition. SQL Lab polling query status every second, and once resultKey is returned, it will start another request to fetch result. Sometimes the fetching request sends out before the last poll request returned. So the last poll response reset query state from
fetching
tosuccess
, and this will trigger "Refetch Results" button. After fetch response returned, this strange state will be reset to correct state, results table will show up.This PR is trying to fix this race condition. Currently SQL Lab's query states are bad designed. It seems we are re-use same "success" state twice:
pending -> running -> success -> fetching -> success
there are a lot of logic depends on the current states. If i introduce another state to replace the final "success", it will cause many trouble :( So my fix here is hacky but simple: if query is in "fetching" state, polling should not change its state back to "success".
TESTING INSTRUCTIONS
CI and manual test.
ADDITIONAL INFORMATION