Skip to content

feat(sourcemaps): Backfill and index has_debug_ids on project artifact bundles - #130424

Merged
jan-auer merged 3 commits into
masterfrom
feat/backfill-artifact-bundle-has-debug-ids
Nov 13, 2026
Merged

jan-auer merged 3 commits into
masterfrom
feat/backfill-artifact-bundle-has-debug-ids

Conversation

@sentry-junior

@sentry-junior sentry-junior Bot commented Nov 9, 2026 •

Copy link
Copy Markdown
Contributor

Links created before #130422 have has_debug_ids = false, also when their bundle has debug-ID rows. This PR adds two post-deployment migrations. Run them in this order, after #130422 is deployed to all regions:

  1. 1257_backfill_projectartifactbundle_has_debug_ids sets the flag on these links. It works in batches of 10,000 links of sentry_projectartifactbundle (about 103M rows). For each batch, it reads the ID 10,000 links ahead through the primary key, then updates the ID range up to that ID, so batches stay full where IDs are sparse. For each link, it checks for one debug-ID row through the artifact_bundle_id index. It only sets the flag to true, so it is safe to run again. It prints a progress line every 10 batches.
  2. 1258_add_projectartifactbundle_debug_ids_index adds a partial index:
CREATE INDEX CONCURRENTLY "sentry_pab_project_debug_idx" ON "sentry_projectartifactbundle" ("project_id") WHERE "has_debug_ids";

Important

Large regions (us, de): run the backfill as a custom job, not through post-deploy-migrations. There, 1257 scans about 103M rows and takes too long for the migration pipeline. The custom job backfill-projectartifactbundle-has-debug-ids (getsentry/getsentry#23184) runs the same queries and can resume from START_FROM. The deploy fakes 1257, so in these regions run only the job, then 1258 through post-deploy-migrations. Smaller regions run both migrations through post-deploy-migrations.

The update bounds are literal values, so the planner estimates about 10,000 rows per batch and probes the debug-ID index once per link. With a bound computed in a subquery instead, it can switch to a hash join over a sequential scan of all debug-ID rows.

The table is large, so the index is a post-deployment migration, as the migration guidelines require. The migration framework creates the index concurrently, so it does not block writes. The migration is not atomic. It runs after the backfill, so that the backfill does not also write to the index.

The index contains only the links with the flag. A query for one project goes down the tree once. If the project has no such link, the query finds no entry and stops. It does not read the other links of the project.

Do not merge #130425 before the backfill and the index ran in all regions.

Requires #130422

via @jan-auer.

--

View Session [Sentry]

@sentry-junior
sentry-junior Bot requested a review from a team as a code owner November 9, 2026 14:01
@sentry-junior
sentry-junior Bot added this pull request to stack #130423 November 9, 2026 14:01
@github-actions github-actions Bot added the Scope: Backend Automatically applied to PRs that change backend components label Nov 9, 2026
lcian
lcian previously approved these changes Nov 9, 2026
@mchen-sentry mchen-sentry added the Trigger: getsentry tests Once code is reviewed: apply label to PR to trigger getsentry tests label Nov 9, 2026
wedamija
wedamija previously approved these changes Nov 9, 2026

@wedamija wedamija left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This table has around 100m rows. It'll probably take a while to process this, but I think it should be able to run successfully.

@sentry-junior
sentry-junior Bot force-pushed the feat/backfill-artifact-bundle-has-debug-ids branch from 4e63fd3 to ffce04c Compare November 10, 2026 15:32
@sentry-junior
sentry-junior Bot requested a review from a team as a code owner November 10, 2026 15:32
@sentry-junior sentry-junior Bot changed the title feat(sourcemaps): Backfill has_debug_ids on artifact bundles feat(sourcemaps): Backfill and index has_debug_ids on project artifact bundles Nov 10, 2026
@sentry-junior
sentry-junior Bot dismissed stale reviews from lcian and wedamija November 10, 2026 15:33

The stack changed: has_debug_ids moved from ArtifactBundle to ProjectArtifactBundle with a partial index on project_id, and the PRs are rebased on master. Please review again.

@sentry

sentry Bot commented Nov 10, 2026 •

Copy link
Copy Markdown
Contributor

Sentry Snapshot Testing

Name Added Removed Changed Renamed Unchanged Skipped Status
sentry-frontend
sentry-frontend
0 0 0 0 932 0 ✅ Unchanged

⚙️ sentry-frontend Snapshot Settings

@sentry-junior
sentry-junior Bot force-pushed the feat/backfill-artifact-bundle-has-debug-ids branch 2 times, most recently from 61b8ad7 to 2c8f0b6 Compare November 12, 2026 13:42
@jan-auer

Copy link
Copy Markdown
Member

I'm adding a getsentry custom job that we'll run in the large regions instead of the migration.

@sentry-junior
sentry-junior Bot force-pushed the feat/backfill-artifact-bundle-has-debug-ids branch 2 times, most recently from 5805a1c to 1e99a0f Compare November 12, 2026 20:29
@github-actions

github-actions Bot commented Nov 12, 2026 •

Copy link
Copy Markdown
Contributor

This PR has a migration; here is the generated SQL for src/sentry/migrations/1260_backfill_projectartifactbundle_has_debug_ids.py src/sentry/migrations/1261_add_projectartifactbundle_debug_ids_index.py

for 1260_backfill_projectartifactbundle_has_debug_ids in sentry

--
-- Raw Python operation
--
-- THIS OPERATION CANNOT BE WRITTEN AS SQL

for 1261_add_projectartifactbundle_debug_ids_index in sentry

--
-- Create index sentry_pab_project_debug_idx on field(s) project_id of model projectartifactbundle
--
CREATE INDEX CONCURRENTLY "sentry_pab_project_debug_idx" ON "sentry_projectartifactbundle" ("project_id") WHERE "has_debug_ids";

@sentry-junior
sentry-junior Bot force-pushed the feat/backfill-artifact-bundle-has-debug-ids branch 2 times, most recently from 622a4bb to 596f9c8 Compare November 13, 2026 09:15
@jan-auer
jan-auer force-pushed the feat/backfill-artifact-bundle-has-debug-ids branch from 596f9c8 to a018f0c Compare November 13, 2026 09:24
Base automatically changed from feat/artifact-bundle-write-has-debug-ids to master November 13, 2026 09:35
@jan-auer
jan-auer requested a review from a team as a code owner November 13, 2026 09:35
sentry-junior Bot and others added 3 commits November 13, 2026 10:35
Sets the flag on every ProjectArtifactBundle whose bundle has DebugIdArtifactBundle rows. Links created since the write path deployed already have it, so this has to run after that change is deployed.

Co-Authored-By: Jan Michael Auer <[email protected]>
Co-Authored-By: Lorenzo Cian <[email protected]>
Adds a partial index on ProjectArtifactBundle.project_id that holds only the links with has_debug_ids set. Checking whether a project has any such link becomes one index lookup, whether or not the project has one. The table is large, so this is a post-deployment migration and the index is created concurrently. It runs after the backfill so that the backfill does not also have to update the index.

Co-Authored-By: Jan Michael Auer <[email protected]>
Co-Authored-By: Lorenzo Cian <[email protected]>
Each batch now reads only the id 10k links ahead and updates the id range
up to it. That keeps batches full where ids are sparse, replaces the IN list
of 1k ids with one range scan on the primary key, and drops the transfer of
the ids through Python. The literal bounds keep the planner on index probes
into the debug-ID rows.

Co-Authored-By: Jan Michael Auer <[email protected]>
@jan-auer
jan-auer force-pushed the feat/backfill-artifact-bundle-has-debug-ids branch from a018f0c to fba6f5f Compare November 13, 2026 09:35
@jan-auer
jan-auer merged commit bdd41ed into master Nov 13, 2026
99 checks passed
@jan-auer
jan-auer deleted the feat/backfill-artifact-bundle-has-debug-ids branch November 13, 2026 10:01
jan-auer added a commit that referenced this pull request Nov 17, 2026
The source map debugger checks if a project uploaded any file with a
debug ID. This check now queries `ProjectArtifactBundle` for a link of
the project with `has_debug_ids = true`. It does not read the debug-ID
rows of the organization anymore.

The partial index from #130424 answers this query with one index lookup.
This is true when the project has such a link and when it does not. A
local check on a synthetic table with 2M rows gave an index-only scan on
the partial index that read 4 to 6 buffers in both cases.

The query is now bounded, so this PR removes the
`debug-id-check-max-bundles` cap and its code path. The cap also gave a
wrong result for projects whose debug IDs were only in older bundles.

Co-authored-by: sentry-junior[bot] <264270552+sentry-junior[bot]@users.noreply.github.com>
Co-authored-by: Jan Michael Auer <[email protected]>
Co-authored-by: Lorenzo Cian <[email protected]>
@linear-code

linear-code Bot commented Nov 23, 2026

Copy link
Copy Markdown

FS-659

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Scope: Backend Automatically applied to PRs that change backend components Trigger: getsentry tests Once code is reviewed: apply label to PR to trigger getsentry tests

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants