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

webui: separate search results by job ids #170

Closed
wants to merge 1 commit into from

Conversation

junhaoliao
Copy link
Member

References

Kirk reported that race conditions in search results and/or metadata were discovered when the server was undergoing high load.

Description

  1. Create a single search metadata collection for all and store each job's results metadata per document.
  2. Instead of storing search results per session, store those per job with the collection name being results_${job_id}.
  3. In the webui-query-handler, pass job_id as part of the state reporting back to the meteor server, which is later propagated to the meteor client side.
  4. For each search / timeline update, pull results from results_${job_id} and metadata from results-metadata's document meta-job-${job_id}.

Validation performed

Manual integration test. Steps include:

  1. Rebuild clp-package.
  2. Start clp-package.
  3. Session A: In the Chromium-based Microsoft Edge browser, visit http://localhost:4000 and start a search query.
  4. Session B: Open a "New InPrivate Window" in Microsoft Edge and visit http://localhost:4000, effectively emulating another user visiting the same site. Start a search query.
  5. Keep both Session A and B open, adjust pipeline strings (search keywords) in both Session A and B, and observe search results showing up independently in each session.
  6. Keep both Session A and B open, adjust the timeline in both Session A and B, and observe updated search results showing up independently in each session.

Copy link
Member

@LinZhihao-723 LinZhihao-723 left a comment

Choose a reason for hiding this comment

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

Added some comments on the coding style. I will leave the core functionality review to Kirk

});

Meteor.publish(Meteor.settings.public.SearchResultsCollectionName, function search_results_publication({
visibleTimeRange,
fieldToSortBy,
visibleSearchResultsLimit
}) {
if ((!currentServerStateList[this.userId]) || !(currentServerStateList[this.userId].jobID)) {
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
if ((!currentServerStateList[this.userId]) || !(currentServerStateList[this.userId].jobID)) {
if (null === currentServerStateList[this.userId] || undefined === currentServerStateList[this.userId].jobID) {

We should make explicit comparison rather than using !

Comment on lines +52 to +53
if ((MyCollections[Meteor.settings.public.SearchResultsCollectionName] !== undefined) &&
(MyCollections[Meteor.settings.public.SearchResultsCollectionName]._name === collectionName)) {
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
if ((MyCollections[Meteor.settings.public.SearchResultsCollectionName] !== undefined) &&
(MyCollections[Meteor.settings.public.SearchResultsCollectionName]._name === collectionName)) {
if (undefined !== MyCollections[Meteor.settings.public.SearchResultsCollectionName] &&
collectionName === MyCollections[Meteor.settings.public.SearchResultsCollectionName]._name) {

We should try to keep the rvalue on the lhs

const [resultHighlightRegex, numSearchResultsOnServer, timeline] = useTracker(() => {
if ((!serverState) || !(serverState.jobID)) {
Copy link
Member

@LinZhihao-723 LinZhihao-723 Oct 23, 2023

Choose a reason for hiding this comment

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

Suggested change
if ((!serverState) || !(serverState.jobID)) {
if ((null === serverState) || (undefined === serverState.jobID)) {

@@ -534,10 +533,12 @@ async def cancel_metadata_task(task, pending_tasks, query_done_event):
query_done_event.clear()


# FIXME: only clear specific job in meta
Copy link
Member

Choose a reason for hiding this comment

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

Can we move this inline comment to the function body and mark it as TODO?

Comment on lines +10 to +11
if ((MyCollections[sessionId] !== undefined) &&
(MyCollections[sessionId][Meteor.settings.public.SearchResultsCollectionName]._name === collectionName)) {
Copy link
Member

@LinZhihao-723 LinZhihao-723 Oct 24, 2023

Choose a reason for hiding this comment

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

Suggested change
if ((MyCollections[sessionId] !== undefined) &&
(MyCollections[sessionId][Meteor.settings.public.SearchResultsCollectionName]._name === collectionName)) {
if (undefined !== MyCollections[sessionId] &&
collectionName === MyCollections[sessionId][Meteor.settings.public.SearchResultsCollectionName]._name) {

@@ -109,33 +117,43 @@ const SearchView = () => {
findOptions["sort"] = sort;
}

if ((!serverState) || !(serverState.jobID)) {
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
if ((!serverState) || !(serverState.jobID)) {
if (null === serverState || undefined === serverState.jobID) {

I am not sure if it is possible for serverState.jobID to be null as well

timeline = timelineDoc;
// FIXME: add job id
const metaDoc = SearchResultsMetadataCollection.findOne({_id: `meta-job-${serverState.jobID}`});
if (metaDoc) {
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
if (metaDoc) {
if (null !== metaDoc) {

@@ -604,7 +624,7 @@ const SearchResultsTable = ({
}

let result = searchResult[columnName];
if (typeof(result) === "object") {
if (typeof (result) === "object") {
Copy link
Member

Choose a reason for hiding this comment

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

Why do we need the space here?

@@ -88,6 +88,7 @@ class WebUiQueryHandlerWebsocket {
case ServerMessageType.QUERY_STARTED:
if (SearchState.WAITING_FOR_QUERY_TO_START === currentServerStateList[this.__sessionId].state) {
currentServerStateList[this.__sessionId].state = SearchState.QUERY_IN_PROGRESS;
currentServerStateList[this.__sessionId].jobID = message['value']['jobID']
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
currentServerStateList[this.__sessionId].jobID = message['value']['jobID']
currentServerStateList[this.__sessionId].jobID = message['value']['jobID'];

const timelineDoc = MyCollections[Meteor.settings.public.SearchResultsMetadataCollectionName].findOne({_id: "timeline"});
if (timelineDoc) {
timeline = timelineDoc;
// FIXME: add job id
Copy link
Member

Choose a reason for hiding this comment

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

Can we use TODO instead?

@junhaoliao
Copy link
Member Author

Closing this as refactoring changes has been proposed and being PR'ed at #250 .

@junhaoliao junhaoliao closed this Jan 26, 2024
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.

2 participants