Repository navigation
Migrate build_id references to bigint - #6203
Conversation
some of these tables can be quite large, but none are near the magnitude of build_events, which we'll have to do in batches - this will be handled in subsequent commits. Signed-off-by: Alex Suraci <[email protected]>
* runs as a component, migrating one batch every interval (default 10 seconds). when all events are migrated, it cleans up the schema. * default batch size is 100,000 build events. in totally empirical testing on my local machine that seemed to be a good balance. this should be safe with concurrent build event writes even by older ATCs, because the migration starts by renaming the current column to build_id_old and creates a new build_id bigint column. all new writes will be automatically saved as bigint, and the batch migrator will slowly convert batches of rows at a time, starting from the newest and working backwards. this adds a test suite which runs against a local postgres server instead of running one itself - the postgresrunner is a bit too automagical to be used for tests at the migration level. the suite only runs if you set $BATCH_POSTGRES_HOST. there's also a benchmark test which only runs with $SLOW configured. i don't plan to run these tests in CI - they're a bit slow and won't be covering a hot code path. Signed-off-by: Alex Suraci <[email protected]>
06d22c8 to
97f0f2c
Compare
also: during down migration, update newly written bigint-only events. just do this in-place, assuming it won't be *too* many rows. it's not really safe to run this because it makes it impossible to run the 'down' migration. let's just leave this extra data around for now and address it in a future release. it kind of seems like this could be turned into a feature integrated into the migration library so it's less awkward to handle, but that's a voyage for another day. (we should probably also integrate voyager btw.) Signed-off-by: Alex Suraci <[email protected]>
aoldershaw
left a comment
There was a problem hiding this comment.
Getting the following error when trying to migrate up from some other dev version:
web_1 | error: failed to migrate database: 1 error occurred:
web_1 | * Migration '1603401316_alter_build_integers_to_bigints.up.sql' failed: 2 errors occurred:
web_1 | * Transaction ALTER TABLE jobs
web_1 | ALTER COLUMN next_build_id TYPE bigint,
web_1 | ALTER COLUMN latest_completed_build_id TYPE bigint,
web_1 | ALTER COLUMN transition_build_id TYPE bigint failed, rolled back the migration
web_1 | * pq: cannot alter type of a column used in a trigger definition
Not sure if my DB got in a weird state for some reason as a result of jumping around between dev versions. Not sure what column/trigger is causing issues, will try to investigate
|
@aoldershaw hmm maybe it's the dashboard event polling stuff? |
There was a problem hiding this comment.
The batch migration seems to work well - I happened to have ~200,000 build events just lying around, so was able to see it work in batches, and it appeared to handle the 100,000 row updates without a sweat. I can see this taking a fairly long time on some massive deployments with the default batch settings, but that's not the end of the world, especially considering it starts with the most recent builds. I migrated down and back up several times, and that also worked well.
As a side note - it does seem concerning that I have 200,000 build events, given that I have only 9 resources and haven't been running any "builds" (they're pretty much all check builds). To be fair, my local deployment has been up for a while, checks were erroring due to a misconfigured var, and #6192 wasn't merged yet.
I see you have a comment about this in the linked issue:
Which led me to discovering that build events don't have a foreign key reference for the build_id column. 🤔 This probably means that resource checking builds are leaking their build events forever. This is probably so we can just truncate/drop the whole table partition when a pipeline is deleted - but maybe we could just truncate it first so the cascade doesn't fire? Maybe we need a new garbage collector to remove build events for deleted builds? ...might be challenging to even find which ones to remove efficiently though. Hmm....
Is that something we should look into before 6.7? Rather than adding a GC component, could we just delete the events when we delete the previous resource check build? I recognize this won't work for builds that are deleted elsewhere, but at least the build events won't pile up as resource checking occurs
EDIT: Opened #6211
|
@aoldershaw Woops I forgot to post the results of the benchmark tests - my finding was that 100k was a good balance of update throughput and not taking too long for each batch. On my machine 100k row batches took ~1 second. Smaller batch sizes were faster but it took longer to migrate everything. I don't think you want to set it too high since it might affect performance of writing new events. Haven't tested it though. |
What does this PR accomplish?
fixes #6199
follow-up to #6022
This introduces a handful of migrations which convert
build_idforeign key references tobigintin-place. Forbuild_eventsthat approach would grind everything to a halt because it can have millions of rows, so this PR adds a batch migration component which will migrate build events in batches of 100,000 (by default) every 10 seconds (by default). Flags are also added for both settings just in case operators feel that it's too aggressive or too slow depending on their situation.The migration first renames
build_events.build_idtobuild_events.build_id_old, and then adds a "new"build_id bigintcolumn and updates the indexes. This rename dance ensures otherwebnodes which may be running mid-upgrade will write their events asbigints, so that the batch migrator doesn't have to play "catch-up." Build events are migrated from newest to oldest. Older builds will just not have any logs until the migrator gets to them. When all events are migrated, a final schema cleanup is performed and the primary key is updated.Release Note
webnodes may take a while to start upon upgrading.build_eventstable - that is handled in Apply bigint migrations to build_events partitions and read from old/new columns instead #6305Contributor Checklist
Reviewer Checklist
BOSH and
Helm packaging; otherwise, ignored for
the integration
tests
(for example, if they are Garden configs that are not displayed in the
--helptext).