Skip to content

ref(hybridcloud): widen externalactorreplica.externalactor_id to bigint#119348

Open
strongs wants to merge 2 commits into
masterfrom
strongs/widen-externalactorreplica-externalactor-id-bigint
Open

ref(hybridcloud): widen externalactorreplica.externalactor_id to bigint#119348
strongs wants to merge 2 commits into
masterfrom
strongs/widen-externalactorreplica-externalactor-id-bigint

Conversation

@strongs

@strongs strongs commented Jul 9, 2026

Copy link
Copy Markdown
Member

hybridcloud_externalactorreplica.externalactor_id is a simulated foreign key onto the primary key of sentry.ExternalActor, which is a BoundedBigAutoField. The replica column was created as int4 straight from its Django model definition. That's a 32-bit column pointing at a 64-bit ID space which is just waiting to overflow

This is an ALTER COLUMN ... TYPE, so it rewrites the table under an ACCESS EXCLUSIVE lock, which the zero-downtime safety framework blocks on the normal AlterField path. I split state from DB with SeparateDatabaseAndState:

I gave a good look at how safe running this migration would be, and I think it should be fine; the table is small (217k rows) and I put together a DD dashboard which shows traffic against it to be minimal; ~0.05 scans/s for reads, ~0.01 rows/s writes

externalactor_id is a simulated FK onto the bigint PK of sentry.ExternalActor
but the replica column was created as int4 from the Django model definition.
Widen it to int8 so it can hold the full source ID range.

Part of the Disjoint ID ranges for cells work (Phase 1: widen int4 columns to
int8). Refs INFRENG.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@strongs strongs requested review from a team as code owners July 9, 2026 20:41
@github-actions github-actions Bot added the Scope: Backend Automatically applied to PRs that change backend components label Jul 9, 2026
@github-actions

github-actions Bot commented Jul 9, 2026

Copy link
Copy Markdown
Contributor

This PR has a migration; here is the generated SQL for src/sentry/hybridcloud/migrations/0031_widen_externalactorreplica_externalactor_id.py

for 0031_widen_externalactorreplica_externalactor_id in hybridcloud

--
-- Custom state/database change combination
--
ALTER TABLE "hybridcloud_externalactorreplica" ALTER COLUMN "externalactor_id" TYPE bigint USING "externalactor_id"::bigint;

@strongs strongs marked this pull request as draft July 9, 2026 21:42
@strongs strongs marked this pull request as ready for review July 9, 2026 21:56
SafeRunSQL(
f'ALTER TABLE "{TABLE}" ALTER COLUMN "{COLUMN}" TYPE bigint USING "{COLUMN}"::bigint;',
reverse_sql=f'ALTER TABLE "{TABLE}" ALTER COLUMN "{COLUMN}" TYPE integer USING "{COLUMN}"::integer;',
hints={"tables": [TABLE]},

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.

You can also set checked = False on the migration to disable the safety checks instead of dodging the checker this way.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

using the stock schema editor would take away the timeout we get from SafeRunSQL, but I'll use this in the future for simplicity probably

@markstory

Copy link
Copy Markdown
Member

The writes to this table are done in an outbox handler, and the reads are in integration code. Adding lock contention to the writes should be ok as if those writes fail, they will be retried.

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants