-
Notifications
You must be signed in to change notification settings - Fork 6
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Parallelize scrubbing a single model #13
Conversation
When a table has tens of millions of records, scrubbing it can take a long time. I added a rake task to parallelize that task so it can go much faster. I'm assuming the model has an ID column, which may not always be true. [#166599401]
# if the ENV variable is set | ||
|
||
unless ENV["SCRUB_CLASSES"].blank? | ||
if ENV["SCRUB_CLASSES"].present? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
💯
|
||
# create even ID ranges for the table | ||
def id_ranges_for(ar_class:, count:) | ||
last_id = 2147483647 # naive maximum ID value for sorting |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
2^31-1 ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I pulled this from the MySQL docs. Like the comment says, naive, because it depends on the data type and the database server. If we find a way to discover that information, we can add it in another PR.
answer = ask("Type '#{db_host}' to continue. \n".red + '-> '.white) | ||
unless answer == db_host | ||
@logger.error "exiting ...".red | ||
exit |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we want this rake task to be chainable? exit
breaks chaining
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is an error case, so probably not.
When a table has tens of millions of records, scrubbing it can take a long time. I added a rake task to parallelize that task so it can go much faster.
I'm assuming the model has an ID column, which may not always be true. For now, this felt good enough. We can always add another PR!
I arbitrarily chose 256 as the number of batches; in my testing it didn't really help to go up or down from there. I'm working on getting a larger data set to test with, though, so I may update that.
I wasn't able to add tests for this—the
NullDB
adapter doesn't allow you to actually find records. I just tested it on a real application.