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

VimPerformanceState#purge_timer for old records #22605

Merged
merged 1 commit into from
Jul 7, 2023

Conversation

kbrock
Copy link
Member

@kbrock kbrock commented Jul 7, 2023

Will purge for both orphans and records older than 6 months

fixes #11868

Will purge for both orphans and records older than 6 months
@kbrock
Copy link
Member Author

kbrock commented Jul 7, 2023

update:

  • added a spec
  • no other changes

@miq-bot
Copy link
Member

miq-bot commented Jul 7, 2023

Checked commit kbrock@8e19738 with ruby 2.6.10, rubocop 1.28.2, haml-lint 0.35.0, and yamllint
3 files checked, 0 offenses detected
Everything looks fine. 👍

@Fryguy
Copy link
Member

Fryguy commented Jul 7, 2023

I'm ok to merge this as is, but I'm reading through the purging code, and I don't understand the purpose of purge_orphaned at all. The reason I'm saying that is that I started looking at supporting "multiple" purging strategies in a cleaner way after this PR, and then I noticed that some tables already do it using purge_by_scope, and it seems so much simpler. For example, binary blobs supports both older than or orphaned via a single scope:

where(:resource_id => nil).where(arel_table[:created_at].lteq(older_than))

and then just uses [:scope, purge_date] as the purge mode.

Comment on lines +30 to +32
def purge_scope(older_than)
where(arel_table[:timestamp].lt(older_than))
end
Copy link
Member

@Fryguy Fryguy Jul 7, 2023

Choose a reason for hiding this comment

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

Based on my comment above, I think this can just more succintly be:

Suggested change
def purge_scope(older_than)
where(arel_table[:timestamp].lt(older_than))
end
def purge_scope(older_than)
where(:resource_id => nil).where(arel_table[:timestamp].lt(older_than))
end

And then change the purge_mode_and_value to:

        def purge_mode_and_value
-         %w(orphaned resource)
+         [:scope, purge_date]
        end

Copy link
Member Author

Choose a reason for hiding this comment

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

so after a discussion, we determined orphaned is saying that this record is owned by a record that was removed from the database.

In theory, I understand how this can happen, but it looked like all of the references were setup to destroy this record.

Copy link
Member

Choose a reason for hiding this comment

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

Oh right - we discussed this and there are 2 types of orphans

  1. resource_id is nil
  2. resource_id is not nil but the corresponding record not longer exists

The main way this can happen is whether the caller uses dependent => :nullify (1) vs nothing at all (2).

where(:resource_id => nil) would only handle the first case, whereas orphaned scope handles the second case.

BinaryBlobs in partucular does where(:resource_id => nil).where(arel_table[:timestamp].lt(older_than)), which partially handles the first case by applying a timestamp check AND and resource_id => nil check. If I recall, we can create BinaryBlobs without a resource_id in some cases, particularly in provisioning, and there was a bug where that BinaryBlob was getting removed during the provisioning and breaking things, which is why that one is "special"

Copy link
Member Author

@kbrock kbrock Jul 11, 2023

Choose a reason for hiding this comment

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

To further clarify what "nothing at all" means for future readers:

It means there is no dependent: ... clause defined. Or the association is not even mentioned in the source (deleted) model.

Copy link
Member Author

@kbrock kbrock Jul 11, 2023

Choose a reason for hiding this comment

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

aah, came across this example:

class ExtManagementSystem
  has_many    :vim_performance_states, :as => :resource  # Destroy will be handled by purger
end

So in this case, the ems will be deleted but the vim performance state will point to an ems_id that does not exist.

@Fryguy Fryguy self-assigned this Jul 7, 2023
@Fryguy
Copy link
Member

Fryguy commented Jul 7, 2023

Going to merge anyway, but let's discuss my comments above.

@Fryguy Fryguy merged commit 41dc875 into ManageIQ:master Jul 7, 2023
9 checks passed
@kbrock kbrock deleted the vps_purging branch July 8, 2023 01:58
@Fryguy
Copy link
Member

Fryguy commented Aug 2, 2023

Backported to petrosian in commit 64332eb.

commit 64332eb3280042c51987a25e4cd841918913fbc4
Author: Jason Frey <fryguy9@gmail.com>
Date:   Fri Jul 7 16:32:50 2023 -0400

    Merge pull request #22605 from kbrock/vps_purging
    
    VimPerformanceState#purge_timer for old records
    
    (cherry picked from commit 41dc875b7e59ec1209fa9b1413264ff093ec1ae8)

Fryguy added a commit that referenced this pull request Aug 2, 2023
VimPerformanceState#purge_timer for old records

(cherry picked from commit 41dc875)
@Fryguy Fryguy added this to the Quinteros milestone Jun 11, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: Quinteros
Development

Successfully merging this pull request may close these issues.

Purge dated VimPerformanceStates
4 participants