Finalize conversion to bigint for push_event_payloads (take 3)
What does this MR do?
This is same change as !65795 (merged), which had to be reverted because we hit deadlock when deploying to GitLab.com.
This time we changed the lock order to be the same as in EventCreateService#create_push_event, this should avoid the deadlock.
- Ensure the migration of
event_id
toevent_id_convert_to_bigint
is completed. - Check column types to make sure swapping is not already done
- Copy indexes and FKs (this is already executed on GitLab.com)
- Swap columns
See #288005 (closed).
Database migrations
⏱ Timing
Index and FK are already created on GitLab.com (when we attempted to deploy !65795 (merged)), so this time we have to do just the column swap, which should be very fast. This can be confirmed by the migrations testing pipeline - !67299 (comment 643550375).
⬆ Up
$ bundle exec rails db:migrate:up VERSION=20210802043253
== 20210802043253 FinalizePushEventPayloadsBigintConversion3: migrating =======
-- columns("push_event_payloads")
-> 0.0014s
-- transaction_open?()
-> 0.0000s
-- index_exists?("push_event_payloads", :event_id_convert_to_bigint, {:unique=>true, :name=>"index_push_event_payloads_on_event_id_convert_to_bigint", :algorithm=>:concurrently})
-> 0.0018s
-- execute("SET statement_timeout TO 0")
-> 0.0007s
-- add_index("push_event_payloads", :event_id_convert_to_bigint, {:unique=>true, :name=>"index_push_event_payloads_on_event_id_convert_to_bigint", :algorithm=>:concurrently})
-> 0.0035s
-- execute("RESET ALL")
-> 0.0006s
-- transaction_open?()
-> 0.0000s
-- foreign_keys("push_event_payloads")
-> 0.0036s
-- execute("LOCK TABLE events, push_event_payloads IN SHARE ROW EXCLUSIVE MODE")
-> 0.0007s
-- execute("ALTER TABLE push_event_payloads\nADD CONSTRAINT fk_a5e47ac4c5\nFOREIGN KEY (event_id_convert_to_bigint)\nREFERENCES events (id)\nON DELETE CASCADE\nNOT VALID;\n")
-> 0.0018s
-- execute("ALTER TABLE push_event_payloads VALIDATE CONSTRAINT fk_a5e47ac4c5;")
-> 0.0058s
-- execute("LOCK TABLE events, push_event_payloads IN ACCESS EXCLUSIVE MODE")
-> 0.0007s
-- quote_table_name("push_event_payloads")
-> 0.0000s
-- quote_column_name(:event_id)
-> 0.0000s
-- quote_column_name("event_id_tmp")
-> 0.0000s
-- execute("ALTER TABLE \"push_event_payloads\" RENAME COLUMN \"event_id\" TO \"event_id_tmp\"")
-> 0.0008s
-- quote_table_name("push_event_payloads")
-> 0.0000s
-- quote_column_name(:event_id_convert_to_bigint)
-> 0.0000s
-- quote_column_name(:event_id)
-> 0.0000s
-- execute("ALTER TABLE \"push_event_payloads\" RENAME COLUMN \"event_id_convert_to_bigint\" TO \"event_id\"")
-> 0.0007s
-- quote_table_name("push_event_payloads")
-> 0.0000s
-- quote_column_name("event_id_tmp")
-> 0.0000s
-- quote_column_name(:event_id_convert_to_bigint)
-> 0.0000s
-- execute("ALTER TABLE \"push_event_payloads\" RENAME COLUMN \"event_id_tmp\" TO \"event_id_convert_to_bigint\"")
-> 0.0007s
-- quote_table_name("trigger_07c94931164e")
-> 0.0000s
-- execute("ALTER FUNCTION \"trigger_07c94931164e\" RESET ALL")
-> 0.0008s
-- change_column_default("push_event_payloads", :event_id, nil)
-> 0.0023s
-- change_column_default("push_event_payloads", :event_id_convert_to_bigint, 0)
-> 0.0023s
-- execute("ALTER TABLE push_event_payloads DROP CONSTRAINT push_event_payloads_pkey")
-> 0.0010s
-- rename_index("push_event_payloads", "index_push_event_payloads_on_event_id_convert_to_bigint", "push_event_payloads_pkey")
-> 0.0008s
-- execute("ALTER TABLE push_event_payloads ADD CONSTRAINT push_event_payloads_pkey PRIMARY KEY USING INDEX push_event_payloads_pkey")
-> 0.0008s
-- remove_foreign_key("push_event_payloads", {:name=>"fk_36c74129da"})
-> 0.0040s
-- quote_table_name("push_event_payloads")
-> 0.0000s
-- quote_column_name("fk_a5e47ac4c5")
-> 0.0000s
-- quote_column_name("fk_36c74129da")
-> 0.0000s
-- execute("ALTER TABLE \"push_event_payloads\"\nRENAME CONSTRAINT \"fk_a5e47ac4c5\" TO \"fk_36c74129da\"\n")
-> 0.0009s
== 20210802043253 FinalizePushEventPayloadsBigintConversion3: migrated (0.0687s)
⬇ Down
$ bundle exec rails db:migrate:down VERSION=20210802043253
== 20210802043253 FinalizePushEventPayloadsBigintConversion3: reverting =======
-- transaction_open?()
-> 0.0000s
-- index_exists?("push_event_payloads", :event_id_convert_to_bigint, {:unique=>true, :name=>"index_push_event_payloads_on_event_id_convert_to_bigint", :algorithm=>:concurrently})
-> 0.0022s
-- execute("SET statement_timeout TO 0")
-> 0.0006s
-- add_index("push_event_payloads", :event_id_convert_to_bigint, {:unique=>true, :name=>"index_push_event_payloads_on_event_id_convert_to_bigint", :algorithm=>:concurrently})
-> 0.0048s
-- execute("RESET ALL")
-> 0.0014s
-- transaction_open?()
-> 0.0000s
-- foreign_keys("push_event_payloads")
-> 0.0042s
-- execute("LOCK TABLE events, push_event_payloads IN SHARE ROW EXCLUSIVE MODE")
-> 0.0013s
-- execute("ALTER TABLE push_event_payloads\nADD CONSTRAINT fk_a5e47ac4c5\nFOREIGN KEY (event_id_convert_to_bigint)\nREFERENCES events (id)\nON DELETE CASCADE\nNOT VALID;\n")
-> 0.0677s
-- execute("ALTER TABLE push_event_payloads VALIDATE CONSTRAINT fk_a5e47ac4c5;")
-> 0.0040s
-- execute("LOCK TABLE events, push_event_payloads IN ACCESS EXCLUSIVE MODE")
-> 0.0008s
-- quote_table_name("push_event_payloads")
-> 0.0000s
-- quote_column_name(:event_id)
-> 0.0000s
-- quote_column_name("event_id_tmp")
-> 0.0000s
-- execute("ALTER TABLE \"push_event_payloads\" RENAME COLUMN \"event_id\" TO \"event_id_tmp\"")
-> 0.0008s
-- quote_table_name("push_event_payloads")
-> 0.0000s
-- quote_column_name(:event_id_convert_to_bigint)
-> 0.0000s
-- quote_column_name(:event_id)
-> 0.0000s
-- execute("ALTER TABLE \"push_event_payloads\" RENAME COLUMN \"event_id_convert_to_bigint\" TO \"event_id\"")
-> 0.0008s
-- quote_table_name("push_event_payloads")
-> 0.0000s
-- quote_column_name("event_id_tmp")
-> 0.0000s
-- quote_column_name(:event_id_convert_to_bigint)
-> 0.0000s
-- execute("ALTER TABLE \"push_event_payloads\" RENAME COLUMN \"event_id_tmp\" TO \"event_id_convert_to_bigint\"")
-> 0.0009s
-- quote_table_name("trigger_07c94931164e")
-> 0.0000s
-- execute("ALTER FUNCTION \"trigger_07c94931164e\" RESET ALL")
-> 0.0008s
-- change_column_default("push_event_payloads", :event_id, nil)
-> 0.0024s
-- change_column_default("push_event_payloads", :event_id_convert_to_bigint, 0)
-> 0.0022s
-- execute("ALTER TABLE push_event_payloads DROP CONSTRAINT push_event_payloads_pkey")
-> 0.0009s
-- rename_index("push_event_payloads", "index_push_event_payloads_on_event_id_convert_to_bigint", "push_event_payloads_pkey")
-> 0.0008s
-- execute("ALTER TABLE push_event_payloads ADD CONSTRAINT push_event_payloads_pkey PRIMARY KEY USING INDEX push_event_payloads_pkey")
-> 0.0008s
-- remove_foreign_key("push_event_payloads", {:name=>"fk_36c74129da"})
-> 0.0036s
-- quote_table_name("push_event_payloads")
-> 0.0000s
-- quote_column_name("fk_a5e47ac4c5")
-> 0.0000s
-- quote_column_name("fk_36c74129da")
-> 0.0000s
-- execute("ALTER TABLE \"push_event_payloads\"\nRENAME CONSTRAINT \"fk_a5e47ac4c5\" TO \"fk_36c74129da\"\n")
-> 0.0007s
== 20210802043253 FinalizePushEventPayloadsBigintConversion3: reverted (0.1245s)
Does this MR meet the acceptance criteria?
Conformity
-
I have included changelog trailers, or none are needed. (Does this MR need a changelog?) -
I have added/updated documentation, or it's not needed. (Is documentation required?) -
I have properly separated EE content from FOSS, or this MR is FOSS only. (Where should EE code go?) -
I have added information for database reviewers in the MR description, or it's not needed. (Does this MR have database related changes?) -
I have self-reviewed this MR per code review guidelines. -
This MR does not harm performance, or I have asked a reviewer to help assess the performance impact. (Merge request performance guidelines) -
I have followed the style guides. -
This change is backwards compatible across updates, or this does not apply.
Availability and Testing
-
I have added/updated tests following the Testing Guide, or it's not needed. (Consider all test levels. See the Test Planning Process.) -
I have tested this MR in all supported browsers, or it's not needed. -
I have informed the Infrastructure department of a default or new setting change per definition of done, or it's not needed.
Security
Does this MR contain changes to processing or storing of credentials or tokens, authorization and authentication methods or other items described in the security review guidelines? If not, then delete this Security section.
-
Label as security and @ mention @gitlab-com/gl-security/appsec
-
The MR includes necessary changes to maintain consistency between UI, API, email, or other methods -
Security reports checked/validated by a reviewer from the AppSec team
Related to #288005 (closed)