Repository navigation
fix(user-history): create the profile sync index before the hinted query - #4022
Open
polylane[bot] wants to merge 1 commit into
Open
polylane[bot] wants to merge 1 commit into
polylane[bot] wants to merge 1 commit into
Conversation
Co-authored-by: polylane[bot] <277585245+polylane[bot]@users.noreply.github.com>
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Profile sync sends its history query to MongoDB with a hint that names the user history (uid, server_time_stamp) index. Nothing guarantees that index exists, so on a database without it Mongo rejects the query and every syncing client gets HTTP 500. After this change the sync creates the index before it sends the hinted query, so the hint is always valid. The index is only declared in
ensure_indices(), whose sole caller is a one-off migration script, so a database restored without secondary indexes has none. I reproduced the OperationFailure on a real mongod and confirmed the hinted query passes once the index exists; the hinted query keeps its performance intent.Production impact at
a3b356b: Profile sync creates its index idempotently; no production behavior changesFix walkthrough
Watch the fix explained (1:25). Recorded for commit
a3b356bcd13992db9a38c7ed51f01ac3b6b8ee7c.Full analysis
Detection evidence
Affected:
int_1d0fec24c001pa40590o8ub5Production impact
The change only calls
create_indexfor theuser_history(uid, server_time_stamp)index before the hinted query. Production already has this index, so the call is a metadata no-op there; Datadog shows no missing-index error in 14 days, andcreate_indexon an existing index does not rebuild it. The added index only appears in environments that lacked it (CI sandbox, dev restores), where it was previously a 500.Checked and not affected (2)
//container.googleapis.com/projects/production-deployment/locations/us-east1-b/clusters/cluster-1/k8s/default/Service/mongoSefaria-ProjectObservability
pymongo.errors.OperationFailure: hint provided does not correspond to an existing indexfrom the sync path is the signal to watch; it should stop.Polylane assessed this pull request at
a3b356b.Causal chain
2 files changed (+114/-1)
sefaria/model/tests/user_history_sync_index_test.py: added, +76/-0sefaria/model/user_profile.py: modified, +38/-1Generated by Polylane. You can ask follow-ups by mentioning @polylane in a comment. If you close this pull request without merging, add a comment that says why. Polylane reads it to make its next fixes better.