DB row lock contention in `organizationonboardingtask` on cache miss

Aperta
#4,373 7 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 2 giorni

Nessuno ha ancora preso questa issue.

  • #117305 di @vitka — chiusa senza merge

Valutazione

Difficoltà
4/5
Tempo stimato
3-5 giorni
Idoneità per principianti
48/100
Tipo di issue
Bug
Chiarezza
Abbastanza chiara
Stato di attività
Tranquilla
Stack tecnologico
postgresql

Direzione di ricerca

Inizia da OrganizationOnboardingTaskManager.record() e traccia il percorso di cache miss attraverso update_or_create() per una riga onboarding-task esistente in uno stato terminale. Verifica, utilizzando lo scenario di contesa PostgreSQL riportato, che il percorso della riga completata eviti SELECT ... FOR UPDATE e gli aggiornamenti delle righe, preservando al contempo il comportamento di riempimento della cache.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

Bug
Environment

self-hosted (https://develop.sentry.dev/self-hosted/)

Steps to Reproduce

OrganizationOnboardingTaskManager.record() can create severe PostgreSQL row-lock contention when many workers miss the onboarding-task cache for the same (organization_id, task) key at the same time.

In my case it produced a thundering herd of workers queued on the same small set of sentry_organizationonboardingtask rows. My self-hosted Sentry hit a production database incident where queries like SELECT ... FROM sentry_organizationonboardingtask ... FOR UPDATE dominated PostgreSQL master. It consumed around 95% of all DB CPU time and had mean execution time around 1.85s

The problematic workload came from onboarding-task recording on high-volume signal paths, especially events with sourcemaps. Once a hot onboarding task row already exists and is complete, repeated cache misses still drive workers into update_or_create() instead of taking a non-locking no-op path.

There are mitigations added since 25.5.1 (large cache TTL and completed-onboarding bypass), but a cache miss can still fall through to update_or_create() that performs a locking read/update of the target row. Also, skip option defaults to False and only helps once organization option onboarding:complete exists.

Expected Result

When the onboarding task row already exists in terminal state, record() should be able to return without issuing a SELECT ... FOR UPDATE or updating the row.

For an already-complete task, cache miss should be a cheap non-locking read followed by cache refill, not a locking write path.

Actual Result

Heavy DB load and lock contention on sentry_organizationonboardingtask.

Product Area

Other

Link

No response

DSN

No response

Version

25.5.1

Lingua principale
Shell
Stelle
9.7k
Fork
2k
Merge medio
3g 2h
PR unite (30g)
16

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di getsentry/self-hosted

Tutte le issue di getsentry/self-hosted

Issue simili

Altre issue su Shell/Bash

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.