Skip to content
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

Don't choke on lhmn_* in cleanup with range #119

Closed
wants to merge 1 commit into from

Conversation

sj26
Copy link
Contributor

@sj26 sj26 commented Jul 6, 2015

When running an Lhm.cleanup with a range it tries to strptime every table name, but if there are unswitched new tables then it fails:

 > Lhm.cleanup(false)

 Existing LHM backup tables: lhmn_statement_lines.
 Existing LHM triggers: .
 Run Lhm.cleanup(true) to drop them all.

 > Lhm.cleanup(true, until: 1.week.ago)

 ...:in `eval': invalid strptime format - `lhma_%Y_%m_%d_%H_%M_%S' (ArgumentError)
    from .../lhm-2.2.0/lib/lhm.rb:64:in `block in cleanup'
    from .../lhm-2.2.0/lib/lhm.rb:63:in `select!'
    from .../lhm-2.2.0/lib/lhm.rb:63:in `cleanup'

This patch includes the table in cleanup over a time range. We can't really date this table, so can't apply the range logic, but it should just be duplicated data in the table so should be safe to delete.

When running an Lhm.cleanup with a range it tries to strptime every
table name, but if there are unswitched new tables then it fails:

   > Lhm.cleanup(false)

   Existing LHM backup tables: lhmn_statement_lines.
   Existing LHM triggers: .
   Run Lhm.cleanup(true) to drop them all.

   > Lhm.cleanup(true, until: 1.week.ago)

   ...:in `eval': invalid strptime format - `lhma_%Y_%m_%d_%H_%M_%S' (ArgumentError)
      from .../lhm-2.2.0/lib/lhm.rb:64:in `block in cleanup'
      from .../lhm-2.2.0/lib/lhm.rb:63:in `select!'
      from .../lhm-2.2.0/lib/lhm.rb:63:in `cleanup'

This patch includes the table in cleanup over a time range. We can't really
date this table, so can't apply the range logic, but it should just be
duplicated data in the table so should be safe to delete.
@taonic
Copy link

taonic commented Jul 6, 2015

+1 on the fix. But I'm wondering if we are introducing risk by removing lhmn_ all together when the intention of until is to remove lhma_ with the specified date range only.

@sj26
Copy link
Contributor Author

sj26 commented Jul 15, 2015

Yeah I was wondering that too, @taoza, but this is generated duplicate data, not canonical data:

should just be duplicated data in the table so should be safe to delete

@tguo
Copy link

tguo commented Jul 15, 2015

@sj26 Any chance the Lhm.cleanup is triggered while an online migration is in process and lhmn_ is being used to make copy?

@sj26
Copy link
Contributor Author

sj26 commented Jul 15, 2015

@tguo sure, but if you're running your migrations in multiple places then I think you have bigger problems.

@@ -59,9 +59,11 @@ def change_table(table_name, options = {}, &block)
def cleanup(run = false, options = {})
lhm_tables = connection.select_values('show tables').select { |name| name =~ /^lhm(a|n)_/ }
if options[:until]
lhm_tables.select! do |table|
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of changing this code block, what about just changing the regex on line 60 to ^lhma_?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because we want to clean up all lhm tables, but only filter the archive tables.

@sj26
Copy link
Contributor Author

sj26 commented Feb 7, 2017

I'll close this one if there's no movement. :-)

@sj26 sj26 closed this Feb 7, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants