Skip to content

Apply bigint migrations to build_events partitions and read from old/new columns instead - #6305

Merged
vito merged 9 commits into
concourse:masterfrom
vito:bigint-partitions
Dec 1, 2020
Merged

vito merged 9 commits into
concourse:masterfrom
vito:bigint-partitions

Conversation

@vito

@vito vito commented Nov 22, 2020 •

Copy link
Copy Markdown
Contributor

What does this PR accomplish?

Bug Fix

  • Update indexes for pipeline_build_events_N partitions in the same way that they were updated for build_events
  • Add indexes for team_build_events_N partitions (they were mysteriously missing)
  • Simplify our migration library's handling of .sql migrations by eliminating the statement parsing and just evaluating the file contents directly
    • the parsing was pretty brittle and didn't like my migration syntax, so I removed it as part of this PR; we never used the functionality this was for anyway
    • note: with these changes it is no longer possible for the database to enter the 'dirty' state, since we no longer try to detect whether a migration was transactional. we never really needed this, and the situations where you'd not be able to use a transaction are extremely narrow, so it seems like we can remove this eventually, but I haven't because that'd probably involve a meta-migration (migrating the schema table), which is scary.
  • Tidy up a small gap in the cleanup for build_events when creating new check builds
  • Remove the batch event migrator; it was too slow.
  • Read build events by looking at both the build_id (bigint) and build_id_old (integer) columns.

Notes to reviewer:

In order to unclog the pipeline I have manually evaluated the up migration in the ci.concourse-ci.org environment. When we try to upgrade, the migrations will fail, so we should evaluate the down migration manually beforehand.

Release Note

  • Rather than migrating the build_events table's build_id column to bigint, which we found to be too slow in large deployments, this PR adds a new bigint column to the build_events table that is populated at runtime
  • When querying for build events, we consider both the old and new column, since builds run prior to the upgrade to 7.0.0 will only have the old column set

Contributor Checklist

Reviewer Checklist

  • Code reviewed
  • Tests reviewed
  • Documentation reviewed
  • Release notes reviewed
  • PR acceptance performed
  • New config flags added? Ensure that they are added to the
    BOSH and
    Helm packaging; otherwise, ignored for
    the integration
    tests

    (for example, if they are Garden configs that are not displayed in the
    --help text).

@vito vito added bug release/no-impact This is an issue that never affected released versions (i.e. a regression caught prior to shipping). labels Nov 22, 2020
@vito
vito force-pushed the bigint-partitions branch from 1206de2 to 98f7717 Compare November 29, 2020 23:28
@vito vito changed the title Apply bigint migrations to build events partitions (+ simplify SQL migrations handling) Apply bigint migrations to build events partitions, remove batch events migrator, simplify SQL migrations handling Nov 29, 2020
@vito vito changed the title Apply bigint migrations to build events partitions, remove batch events migrator, simplify SQL migrations handling Apply bigint migrations to build_events partitions, remove batch events migrator and read from old/new columns instead, simplify SQL migrations handling Nov 29, 2020
vito added 8 commits November 29, 2020 19:03
rather than parsing out all the statements and supporting special syntax
for transactionless migrations, just evaluate the whole content.

the parsing was super brittle and would break if you used comments or
special syntax in certain ways.

we've been consistently adding BEGIN ... COMMIT in all our migrations,
so it doesn't seem worth the hassle; if you need it to not run in a
transaction, just don't add the BEGIN / COMMIT.

Signed-off-by: Alex Suraci <[email protected]>
previously the build_id and build_id_old indexes were only applied to
the parent table; they were not inherited by the child tables. child
table indexes must be manually created.

this migration loops over all existing pipelines and performs the same
index dance that is done for the parent table.

it also adds indexes for all team build events partitions and updates
the trigger function to create them; they didn't exist before, and there
doesn't seem to be a good reason not to do it. (team build events
partitions are used for one-off builds.)

note that newly created pipelines partitions will only have indexes for
the new build_id bigint columns. we could update the trigger function to
create both, but it really shouldn't be necessary; let's just let them
go away when we finally drop the build_id_old column in the future.

Signed-off-by: Alex Suraci <[email protected]>
previously this would only remove the events for one previous build. if
there were many, i.e. if a user manually triggered a bunch, they would
leak forever.

now it will remove events for all builds that were removed.

Signed-off-by: Alex Suraci <[email protected]>
this will make it so newly created pipelines *also* have build_id_old
and build_id indexes, instead of just existing ones. this fixes the down
migration.

this will also be necessary for upcoming commits which bail on the batch
migration approach and instead just query using both keys + indexes.

Signed-off-by: Alex Suraci <[email protected]>
this didn't really work out; it was reasonably performant in local
testing but extremely slow in production - even just the 'SELECT' query
to find the start range for the batch took ~20 minutes.

so rather than doing a long and painful migration, let's just query by
build_id OR build_id_old - it should be fast enough since they're both
indexed. we can phase out build_id_old when we redo how logs are stored
and probably come up with an entirely new schema anyhow.

Signed-off-by: Alex Suraci <[email protected]>
rather than performing an incredibly expensive migration affecting
potentially hundreds of millions of rows, let's just make use of both
indexes.

this kicks the can down the road and leaves build_id_old around for now.
if/when we get around to implementing something like concourse#3879 we can figure
out a plan for phasing out build_events altogether.

Signed-off-by: Alex Suraci <[email protected]>
using 'self' and 'this' is an anti-pattern; it should be named as if it
is any other argument

Signed-off-by: Alex Suraci <[email protected]>
@vito
vito force-pushed the bigint-partitions branch from 98f7717 to 491bca0 Compare November 30, 2020 00:04

@taylorsilva taylorsilva 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.

LGTM. Reviewed the tests and did a little acceptance locally, everything looks good!

@vito
vito merged commit fe6a042 into concourse:master Dec 1, 2020
@vito
vito deleted the bigint-partitions branch December 1, 2020 16:25
@aoldershaw aoldershaw changed the title Apply bigint migrations to build_events partitions, remove batch events migrator and read from old/new columns instead, simplify SQL migrations handling Apply bigint migrations to build_events partitions and read from old/new columns instead Jan 25, 2021
@xtremerui xtremerui mentioned this pull request Nov 16, 2022
1 of 2 tasks
@taylorsilva

Copy link
Copy Markdown
Member

This PR was a follow-up to #6203 for anyone else doing commit spelunking.

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

Labels

bug misc release/no-impact This is an issue that never affected released versions (i.e. a regression caught prior to shipping).

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants