Skip to content
This repository has been archived by the owner on Jul 11, 2022. It is now read-only.

Bug 1323332 - Orphaned configuration left in database #257

Merged
merged 1 commit into from May 31, 2016

Conversation

jshaughn
Copy link
Contributor

We knew from observation that drift-related configs were being orphaned in
the DB. Running some i-tests showed backing configs for drift definitions
being orphaned. This addresses a few different causes:

  • improper use of EntityManager.getReference()
    • This method is basically an optimized version of EntityManager.find(),
      with the difference being that it is not required to go to the DB, and
      instead basically wraps the given ID in a proxy for the desired class.
      It should generally not be used for reasons outside of using the proxy
      to set FK references in other entities, or to explicitly call setters
      on the proxy in some circumstances. It should not be used for an
      existence check, a way to perform subsequent gets on the proxy, or
      passed to EntityManager.remove(). We were violating all of these rules
      in various places. The calls to EM.remove were the cause of some
      orphaned config because the getReference proxy did not provide the
      proxy necessary for EM.remove to provide the cascade delete.
  • improper update of a DriftDefinition or DriftDefinitionTemplate
    • When updating these entities we were not removing the old backing
      config, or backing drift definition for a template, when replacing
      it with the new one.
  • improper test cleanup
    • this would not affect production. We were directly deleting
      DriftDefinition and DriftDefinitionTemplate, so the cascade delete
      was not happening. By changing the cleanup code to use EM.remove() the
      configs are now cleaned up properly.

Note that this commit does not guarantee to solve this BZ entirely or
even partially, but it is guaranteed to stop some orphan issues, as proven
in testing. Also, it includes analogous changes outside of the drift domain.

We knew from observation that drift-related configs were being orphaned in
the DB.  Running some i-tests showed backing configs for drift definitions
being orphaned. This addresses a few different causes:
- improper use of EntityManager.getReference()
  - This method is basically an optimized version of EntityManager.find(),
    with the difference being that it is not required to go to the DB, and
    instead basically wraps the given ID in a proxy for the desired class.
    It should generally not be used for reasons outside of using the proxy
    to set FK references in other entities, or to explicitly call setters
    on the proxy in some circumstances.  It should not be used for an
    existence check, a way to perform subsequent gets on the proxy, or
    passed to EntityManager.remove(). We were violating all of these rules
    in various places.  The calls to EM.remove were the cause of some
    orphaned config because the getReference proxy did not provide the
    proxy necessary for EM.remove to provide the cascade delete.
- improper update of a DriftDefinition or DriftDefinitionTemplate
  - When updating these entities we were not removing the old backing
    config, or backing drift definition for a template, when replacing
    it with the new one.
- improper test cleanup
  - this would not affect production. We were directly deleting
    DriftDefinition and DriftDefinitionTemplate, so the cascade delete
    was not happening. By changing the cleanup code to use EM.remove() the
    configs are now cleaned up properly.

Note that this commit does not guarantee to solve this BZ entirely or
even partially, but it is guaranteed to stop some orphan issues, as proven
in testing.  Also, it includes analogous changes outside of the drift domain.
@burmanm burmanm merged commit 835cca5 into rhq-project:master May 31, 2016
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
2 participants