Skip to content

Read records in KMS migration job while timeout is in effect#9297

Merged
jmhooper merged 1 commit intomainfrom
jmhooper-load-records-with-timeout
Oct 2, 2023
Merged

Read records in KMS migration job while timeout is in effect#9297
jmhooper merged 1 commit intomainfrom
jmhooper-load-records-with-timeout

Conversation

@jmhooper
Copy link
Contributor

@jmhooper jmhooper commented Oct 2, 2023

Currently the ProfileMigrationJob and UserMigrationJob make expensive queries to find users to migrate. These queries need a large amount of time to run. To enable this we run them in a transaction with a local statement timeout.

I discovered an issue with this approach. The query was not actually executed in the transaction block. The transaction returned a relation and the query was executed when we attempted to iterated over the records in the relation. This commit adds a #to_a call to the relation to ensure the query is run and the records are loaded into memory before the transaction block is complete.

[skip changelog]

Currently the ProfileMigrationJob and UserMigrationJob make expensive queries to find users to migrate. These queries need a large amount of time to run. To enable this we run them in a transaction with a local statement timeout.

I discovered an issue with this approach. The query was not actually executed in the transaction block. The transaction returned a relation and the query was executed when we attempted to iterated over the records in the relation. This commit adds a `#to_a` call to the relation to ensure the query is run and the records are loaded into memory before the transaction block is complete.

[skip changelog]
@jmhooper jmhooper merged commit b379f14 into main Oct 2, 2023
@jmhooper jmhooper deleted the jmhooper-load-records-with-timeout branch October 2, 2023 17:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants