openlibrary icon indicating copy to clipboard operation
openlibrary copied to clipboard

Search index updates sometimes get dropped

Open tfmorris opened this issue 3 years ago • 6 comments

Search index updates for edits/merges today have been dropped in at least two cases that I've kept track of. In both cases, edits/merges before and after the missing ones did correctly appear in the search index.

NOTE: This is separate from the updates which got dropped as part of the recent outage. I'm ignoring that as a one time event.

Evidence

  1. This merge: https://openlibrary.org/recentchanges/2022/12/31/merge-authors/110156479 didn't result in the works showing up in this author's record: https://openlibrary.org/authors/OL2274627A

  2. This merge: https://openlibrary.org/recentchanges/2022/12/31/merge-authors/110153037 didn't result in the works showing up under this author's record: https://openlibrary.org/authors/OL2197410A

Because of the way the works list is constructed for the author's page, this basically means the works have disappeared forever (or until a complete reindex is done).

Proposal & Constraints

Related files

Stakeholders

@cdrini

tfmorris avatar Dec 31 '22 23:12 tfmorris

Here's another example from yesterday afternoon. This author record: https://openlibrary.org/authors/OL2253024A is missing the works that should have been added by this merge: https://openlibrary.org/recentchanges/2023/01/01/merge-authors/110174702

tfmorris avatar Jan 01 '23 19:01 tfmorris

Labelling as P3 because this generally only happens when solr-updater has an outage causing it to try to catch up, which should happen rarely.

cdrini avatar Jan 03 '23 20:01 cdrini

@cdrini Please re-read the issue, especially the NOTE:

This is not related to any outage and in all three cases merges which were done both immediately before and immediately after the missing update got indexed correctly.

tfmorris avatar Jan 03 '23 22:01 tfmorris

Ahh gotcha!

cdrini avatar Jan 05 '23 21:01 cdrini

Hi @cdrini, I looked into this and I think it's the same race my open PR #14080 fixes.

What happens during an author merge

  1. merge_authors.py loads the affected works to rewrite their author, then saves everything in one save_many (action="merge-authors"). Since the merge just read those works, they're likely in memcache.
  2. In infogami's save_many, the database commit comes first, then the save_many event, which writes the log record the Solr updater polls. Memcache only gets the new versions at the end of the request, in cache.unloadhook(), which server.py registers as an unload hook.
  3. The updater sees the log record during that window and rereads each work through get_many. On master that goes through MemcacheMiddleware.get_many, so it gets the old cached copy, still pointing at the duplicate author.
  4. The work is indexed under the old author_key, and nothing queues it again, so it's missing from the master author until a full reindex. That matches all three examples here, including the edits just before and after being fine. Merges are the likeliest victims, because one long request saves many documents that were all just read.

Why #14080 fixes it #14080 gives the updater's DatabaseDataProvider a connection without MemcacheMiddleware. Every document read in the data provider goes through get_many (via preload_documents0), and Infobase's get_many is a straight SQL query (dbstore.get_many), so it always sees the committed version.

I haven't reproduced this in production. It's what the code does, and it fits every example in the report.

What I'd do if you assign this to me

  1. A regression test for the window: a merge-style save whose cached copy is still stale when the updater reads it. It should fail on master and pass with #14080.
  2. A script that finds works still indexed under a redirected author, meaning their author_key points at an author that's now a redirect, and queues them through solr-force-update. That would restore the works lost so far. Someone with production access would need to run it.

I can do these as a follow-up to #14080, or fold them into it if you'd rather have one PR.

Animesh-Jantwal avatar Nov 10 '26 11:11 Animesh-Jantwal

If it helps, here's a more recent example. This merge: https://openlibrary.org/recentchanges/2026/10/30/merge-works/174769477 is not reflected in the works listed on author Donald Knuth's page a week and a half later.

tfmorris avatar Nov 12 '26 00:11 tfmorris