Skip to content

Commit b83e3cf

Browse files
authored
fix(webui): Improve Presto search metadata handling: (#1280)
- Defer query done status until all data is delivered. - Quantize Presto search signal as required for CLP. - Reset the number of results to zero when submitting a new query.
1 parent c38ea39 commit b83e3cf

File tree

5 files changed

+29
-24
lines changed

5 files changed

+29
-24
lines changed

components/webui/client/src/pages/SearchPage/SearchControls/Presto/presto-search-requests.ts

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import {
88
clearQueryResults,
99
submitQuery,
1010
} from "../../../../api/presto-search";
11-
import useSearchStore from "../../SearchState";
11+
import useSearchStore, {SEARCH_STATE_DEFAULT} from "../../SearchState";
1212
import {SEARCH_UI_STATE} from "../../SearchState/typings";
1313

1414

@@ -43,7 +43,13 @@ const handlePrestoClearResults = () => {
4343
* @param payload
4444
*/
4545
const handlePrestoQuerySubmit = (payload: PrestoQueryJobCreation) => {
46-
const {updateSearchJobId, updateSearchUiState, searchUiState} = useSearchStore.getState();
46+
const {
47+
updateNumSearchResultsTable,
48+
updateNumSearchResultsMetadata,
49+
updateSearchJobId,
50+
updateSearchUiState,
51+
searchUiState,
52+
} = useSearchStore.getState();
4753

4854
// User should NOT be able to submit a new query while an existing query is in progress.
4955
if (
@@ -58,6 +64,8 @@ const handlePrestoQuerySubmit = (payload: PrestoQueryJobCreation) => {
5864

5965
handlePrestoClearResults();
6066

67+
updateNumSearchResultsTable(SEARCH_STATE_DEFAULT.numSearchResultsTable);
68+
updateNumSearchResultsMetadata(SEARCH_STATE_DEFAULT.numSearchResultsMetadata);
6169
updateSearchUiState(SEARCH_UI_STATE.QUERY_ID_PENDING);
6270

6371
submitQuery(payload)

components/webui/client/src/pages/SearchPage/SearchControls/search-requests.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@ const handleQuerySubmit = (payload: QueryJobCreation) => {
9595

9696
store.updateNumSearchResultsTable(SEARCH_STATE_DEFAULT.numSearchResultsTable);
9797
store.updateNumSearchResultsTimeline(SEARCH_STATE_DEFAULT.numSearchResultsTimeline);
98+
store.updateNumSearchResultsMetadata(SEARCH_STATE_DEFAULT.numSearchResultsMetadata);
9899
store.updateSearchUiState(SEARCH_UI_STATE.QUERY_ID_PENDING);
99100

100101
submitQuery(payload)

components/webui/client/src/pages/SearchPage/SearchState/useUpdateStateWithMetadata.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ const useUpdateStateWithMetadata = () => {
3838

3939
switch (resultsMetadata.lastSignal) {
4040
case SEARCH_SIGNAL.RESP_DONE:
41-
case PRESTO_SEARCH_SIGNAL.FINISHED:
41+
case PRESTO_SEARCH_SIGNAL.DONE:
4242
updateSearchUiState(SEARCH_UI_STATE.DONE);
4343
break;
4444
case PRESTO_SEARCH_SIGNAL.FAILED:

components/webui/common/src/metadata.ts

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -23,16 +23,8 @@ enum SEARCH_SIGNAL {
2323
* Presto search-related signals.
2424
*/
2525
enum PRESTO_SEARCH_SIGNAL {
26-
WAITING_FOR_PREREQUISITES = "WAITING_FOR_PREREQUISITES",
27-
QUEUED = "QUEUED",
28-
WAITING_FOR_RESOURCES = "WAITING_FOR_RESOURCES",
29-
DISPATCHING = "DISPATCHING",
30-
PLANNING = "PLANNING",
31-
STARTING = "STARTING",
32-
RUNNING = "RUNNING",
33-
FINISHING = "FINISHING",
34-
FINISHED = "FINISHED",
35-
CANCELED = "CANCELED",
26+
QUERYING = "QUERYING",
27+
DONE = "DONE",
3628
FAILED = "FAILED",
3729
}
3830

components/webui/server/src/routes/api/presto-search/index.ts

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -150,8 +150,6 @@ const plugin: FastifyPluginAsyncTypebox = async (fastify) => {
150150
},
151151
query: queryString,
152152
state: (_, queryId, stats) => {
153-
// Type cast `presto-client` string literal type to our enum type.
154-
const newState = stats.state as PRESTO_SEARCH_SIGNAL;
155153
request.log.info({
156154
searchJobId: queryId,
157155
state: stats.state,
@@ -163,24 +161,30 @@ const plugin: FastifyPluginAsyncTypebox = async (fastify) => {
163161
_id: queryId,
164162
errorMsg: null,
165163
errorName: null,
166-
lastSignal: newState,
164+
lastSignal: PRESTO_SEARCH_SIGNAL.QUERYING,
167165
queryEngine: CLP_QUERY_ENGINES.PRESTO,
168166
}).catch((err: unknown) => {
169167
request.log.error(err, "Failed to insert Presto metadata");
170168
});
171169
isResolved = true;
172170
resolve(queryId);
173-
} else {
174-
// Update metadata on subsequent calls
175-
searchResultsMetadataCollection.updateOne(
176-
{_id: queryId},
177-
{$set: {lastSignal: newState}}
178-
).catch((err: unknown) => {
179-
request.log.error(err, "Failed to update Presto metadata");
180-
});
181171
}
182172
},
183173
success: () => {
174+
if (false === isResolved) {
175+
request.log.error(
176+
"Presto query finished before searchJobId was resolved; "
177+
);
178+
179+
return;
180+
}
181+
searchResultsMetadataCollection.updateOne(
182+
{_id: searchJobId},
183+
{$set: {lastSignal: PRESTO_SEARCH_SIGNAL.DONE}}
184+
).catch((err: unknown) => {
185+
request.log.error(err, "Failed to update Presto metadata");
186+
});
187+
184188
request.log.info("Presto search succeeded");
185189
},
186190
timeout: null,

0 commit comments

Comments
 (0)