OpenJPA
  1. OpenJPA
  2. OPENJPA-151

Added field in enhanced vesrion of a class is not serialized. Hence the change in detached+serialized instances is not registered under certain conditions.

    Details

    • Type: Improvement Improvement
    • Status: Closed
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: 0.9.7
    • Component/s: kernel
    • Labels:
      None

      Description

      Enhancement adds a transient byte member field pcFlags to the class. This field is originally used to optimize field access/mutation i.e. to short-circuit mediation via StateManager under certain conditions (e.g. when the field is part of the default fetch group). The field is transient, perhaps, to maintain serialization compatibility. However, later changes such as DetachedStateManager and improved attach strategies have made the usage of these flag redundant.

      This issue is a proposal to remove this field from the enhanced classes. The proposed change is initiated by the following observation:
      1. class A has one-to-one relation to class B
      2. an instance a of A is related to b1 of B. b2 is another instance of B.
      3. a, b1, b2 are detached, serialized, transported over the wire, desrialized in a remote process as a*, b1* and b2*.
      4. in the remote process a* is associated with b2*
      5. a* is merged to the original process.

      The change is not persisted when OpenJPA kernel is used with a JDO facade. It works with JPA facade.
      The initial analysis shows that the reason can be attributed to pcFlags and the optimization in enhanced classes based on to its value. Because pcFlags is not
      serialized, in a* instance pcFlags has a value of 0. Hence, the mutation of a*'s relation to b2* from b1* is not mediated via the StateManager (yes, the detached version was carrying its own StateManager). While merging the instance a* back, it was adjudged clean while actually it was dirty. In JPA facade, the enhancement process did not add the extra optimization for setter and so the cloned owner instance was righly marked dirty.

      Please note that if this proposal is accepted by the community, it will require reenhancement of existing domain classes. The change will impact the internal StateManager and PersistenceCapable API (essentally removal of certain methods than any other behavioural change).

      1. diff.txt
        10 kB
        Pinaki Poddar
      2. PCEnhancer.AddVersion.Diff.txt
        6 kB
        Pinaki Poddar

        Activity

        Hide
        Pinaki Poddar added a comment -

        Fixed with SVN revision 511998: http://svn.apache.org/viewvc?view=rev&rev=511998

        Show
        Pinaki Poddar added a comment - Fixed with SVN revision 511998: http://svn.apache.org/viewvc?view=rev&rev=511998
        Hide
        Craig L Russell added a comment -

        I'd avoid the method name getEnhancementContractVersion because this might be used by the class developer. I'd suggest PRE+GetEnhancementContractVersion instead to avoid name conflicts.

        Show
        Craig L Russell added a comment - I'd avoid the method name getEnhancementContractVersion because this might be used by the class developer. I'd suggest PRE+GetEnhancementContractVersion instead to avoid name conflicts.
        Hide
        Patrick Linskey added a comment -

        > 1. Should the method be static?

        No; it should be part of the interface.

        The code looks good to me. Please make sure to run it through the Kodo test suites before committing, though – sadly, we don't have as much enhancement coverage in the OpenJPA test suites as we should.

        Show
        Patrick Linskey added a comment - > 1. Should the method be static? No; it should be part of the interface. The code looks good to me. Please make sure to run it through the Kodo test suites before committing, though – sadly, we don't have as much enhancement coverage in the OpenJPA test suites as we should.
        Hide
        Pinaki Poddar added a comment -

        Added a public int getEnhancementContractVersion() to all enhanced classes.
        Please review these baby steps into bytecode manipulation.

        The diff also contains removal of pcFlags related changes.
        It does not include the change in PersistenceCapable interface.

        1. Should the method be static?
        2. The ENHANCER_VERSION is public static final in PCEnhncer. So the user can:

        PersistenceCapable pc = ...
        if (pc.getEnhancementContractVersion() < PCEnhancer.ENHANCER_VERSION)
        // warn or throw exception

        3. What is a good central location to add the above check?

        Show
        Pinaki Poddar added a comment - Added a public int getEnhancementContractVersion() to all enhanced classes. Please review these baby steps into bytecode manipulation. The diff also contains removal of pcFlags related changes. It does not include the change in PersistenceCapable interface. 1. Should the method be static? 2. The ENHANCER_VERSION is public static final in PCEnhncer. So the user can: PersistenceCapable pc = ... if (pc.getEnhancementContractVersion() < PCEnhancer.ENHANCER_VERSION) // warn or throw exception 3. What is a good central location to add the above check?
        Hide
        Patrick Linskey added a comment -

        Another would be to add a new getEnhancementContractVersion() method to the PersistenceCapable interface. This would cause immediate breakage of the old classes, since they don't have that method, and allow us to detect other subtle behavior changes in the future by checking that the version is compatible.

        Show
        Patrick Linskey added a comment - Another would be to add a new getEnhancementContractVersion() method to the PersistenceCapable interface. This would cause immediate breakage of the old classes, since they don't have that method, and allow us to detect other subtle behavior changes in the future by checking that the version is compatible.
        Hide
        Pinaki Poddar added a comment -

        One way is to add some extra checks on isPersistenceCapable() for the deprecated pcFlags() method and warn if the enhanced version is "old". Or is that too arbitrary?

        Show
        Pinaki Poddar added a comment - One way is to add some extra checks on isPersistenceCapable() for the deprecated pcFlags() method and warn if the enhanced version is "old". Or is that too arbitrary?
        Hide
        Patrick Linskey added a comment -

        Maybe we should do something explicit to make sure that classes enhanced with the old enhancer can't load anymore. It sounds like currently, classes will just silently start to behave differently.

        Show
        Patrick Linskey added a comment - Maybe we should do something explicit to make sure that classes enhanced with the old enhancer can't load anymore. It sounds like currently, classes will just silently start to behave differently.
        Hide
        Pinaki Poddar added a comment -

        > Why will this require re-enhancement?
        ======================================================
        Previous enhancement:
        private static final void pcSetdepartment(Employee employee, Department department1) {
        if(employee.pcFlags == 0)

        { employee.department = department1; return; }
        if(employee.pcStateManager == null) { employee.department = department1; return; }

        else

        { employee.pcStateManager.settingObjectField(employee, pcInheritedFieldCount + 0, employee.department, department1, 0); return; }
        }

        ================================================
        Enhanced version once pcFlags is removed:

        private static final void pcSetdepartment(Employee employee, Department department1) {
        if(employee.pcStateManager == null) { employee.department = department1; return; } else { employee.pcStateManager.settingObjectField(employee, pcInheritedFieldCount + 0, employee.department, department1, 0); return; }

        }
        ==================================================

        If the previous enhanced version is used, the behaviour of serialized domain class will remain unchanged even with new OpenJPA runtime (i.e. PC/SM interfaces without calling back on pcReplaceFlags()).

        But all this optimization to short-circuit StateManager mediation is only happening with JDO facade that too when the accessed field in not in default fetch group.

        Show
        Pinaki Poddar added a comment - > Why will this require re-enhancement? ====================================================== Previous enhancement: private static final void pcSetdepartment(Employee employee, Department department1) { if(employee.pcFlags == 0) { employee.department = department1; return; } if(employee.pcStateManager == null) { employee.department = department1; return; } else { employee.pcStateManager.settingObjectField(employee, pcInheritedFieldCount + 0, employee.department, department1, 0); return; } } ================================================ Enhanced version once pcFlags is removed: private static final void pcSetdepartment(Employee employee, Department department1) { if(employee.pcStateManager == null) { employee.department = department1; return; } else { employee.pcStateManager.settingObjectField(employee, pcInheritedFieldCount + 0, employee.department, department1, 0); return; } } ================================================== If the previous enhanced version is used, the behaviour of serialized domain class will remain unchanged even with new OpenJPA runtime (i.e. PC/SM interfaces without calling back on pcReplaceFlags()). But all this optimization to short-circuit StateManager mediation is only happening with JDO facade that too when the accessed field in not in default fetch group.
        Hide
        Abe White added a comment -

        +1 on the patch from me. Fixes a problem and gets rid of unneeded code baggage at the same time. The re-enhancement isn't much of an issue to me – we've required re-enhancement for various upgrades in the past and it's never been an issue with users, surprisingly enough.

        Show
        Abe White added a comment - +1 on the patch from me. Fixes a problem and gets rid of unneeded code baggage at the same time. The re-enhancement isn't much of an issue to me – we've required re-enhancement for various upgrades in the past and it's never been an issue with users, surprisingly enough.
        Hide
        Abe White added a comment -

        > Why will this require re-enhancement?

        We'll no longer be setting pcFlags values – the callbacks won't even exist to do so. Instances of classes that aren't re-enhanced will therefore never get their pcFlags set to LOAD_REQUIRED as needed to ensure their StateManagers are able to intercept all field access.

        Show
        Abe White added a comment - > Why will this require re-enhancement? We'll no longer be setting pcFlags values – the callbacks won't even exist to do so. Instances of classes that aren't re-enhanced will therefore never get their pcFlags set to LOAD_REQUIRED as needed to ensure their StateManagers are able to intercept all field access.
        Hide
        Patrick Linskey added a comment -

        > Please note that if this proposal is accepted by the community, it will require reenhancement
        > of existing domain classes. The change will impact the internal StateManager and
        > PersistenceCapable API (essentally removal of certain methods than any other behavioural
        > change).

        Why will this require re-enhancement? The previously-enhanced classes will just have some extra methods that are no longer part of the interface.

        Classes enhanced with the new version will not work with older OpenJPA versions, though.

        Show
        Patrick Linskey added a comment - > Please note that if this proposal is accepted by the community, it will require reenhancement > of existing domain classes. The change will impact the internal StateManager and > PersistenceCapable API (essentally removal of certain methods than any other behavioural > change). Why will this require re-enhancement? The previously-enhanced classes will just have some extra methods that are no longer part of the interface. Classes enhanced with the new version will not work with older OpenJPA versions, though.
        Hide
        Pinaki Poddar added a comment -

        Prposed changes to remove pcFlags from enhanced classes

        i. remove pcFlags related interface method from PersistenceCapable and StateManager
        ii. remove pcFlags related code generation from PCEnhancer

        Show
        Pinaki Poddar added a comment - Prposed changes to remove pcFlags from enhanced classes i. remove pcFlags related interface method from PersistenceCapable and StateManager ii. remove pcFlags related code generation from PCEnhancer

          People

          • Assignee:
            Pinaki Poddar
            Reporter:
            Pinaki Poddar
          • Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Development