Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 339718

Summary: [DB] Incorrect CDOCommitInfo is loaded from branch when HorizontalBranchingMappingStrategyWithRanges is used
Product: [Modeling] EMF Reporter: Szabolcs Bardy <szbardy>
Component: cdo.dbAssignee: Stefan Winkler <stefan>
Status: NEW --- QA Contact: Eike Stepper <stepper>
Severity: normal    
Priority: P3 CC: cbateman
Version: 4.13   
Target Milestone: ---   
Hardware: PC   
OS: Windows 7   
Whiteboard:
Attachments:
Description Flags
Test project to reproduce the error
none
CDO test case to reproduce the error
none
Test v2 none

Description Szabolcs Bardy CLA 2011-03-11 11:36:57 EST
Build Identifier: 

If using a DBStore with HorizontalBranchingMappingStrategyWithRanges, when trying to load the commit infos in a branch, once the repository has been shut down and restarted, the obtained commit info contains uneccessary elements in the changed objects list. It seems that when list features of two revisions of a changed object are compared, the old revision's list is filled with CDORevisionUtil.UNINITIALIZED elements, while the new revision contains loaded CDOIDs. CDORevisionDeltaImpl.compare will create ADD and REMOVE feature deltas. 

Happens only when loading commit info from branch and using the 'withRanges' mapping strategy.

Reproducible: Always

Steps to Reproduce:
1. Open a CDO repository connection
2. If not exists, create a resource and add sample elements to it
3. Create a branch and commit an additional element to the resource
4. Inspect the commit info in the branch -> correct
5. Dispose CDO connection and connect to the repository again
6. Try to inspect the same commit info -> incorrect elements appear in the changed objects list
Comment 1 Szabolcs Bardy CLA 2011-03-11 11:40:27 EST
Created attachment 191000 [details]
Test project to reproduce the error

Attaching a test project that contains unit tests to reproduce the bug. The class LoadCommitDataFromBranchTest contains the test case.
Comment 2 Szabolcs Bardy CLA 2011-03-29 08:30:33 EDT
After digging into the issue if I understand correctly the following happens: The incorrect initialization of the base revision happens in the readValues() method of the BranchingListTableMappingWithRanges class. When the current revision of an object in the branch is initialized, in case of using chunk loading, list features are initialized partially from the base revision from the parent branch. In order to do this the createBaseChunkReader() method creates the base revision, but as the chunk size is hardcoded to 0, its lists remain uninitialized. This revision however gets into the revision cache.
When later the delta between the two revisions is calculated, the uninitialized base revision is grabbed from the cache, thus the compare will result invalid values.

One solution I tried was to initialize the base revision also by providing -1 for the chunk size in the createBaseChunkReader() method instead of 0, but this resulted in an exception from the SmartPreparedStatementCache.Cache class put() method: org.eclipse.net4j.util.ImplementationError: SELECT cdo_idx, cdo_value FROM eresource_CDOResource_contents_list WHERE cdo_source=? AND cdo_branch=? AND cdo_version_added<=? AND (cdo_version_removed IS NULL OR cdo_version_removed>?) ORDER BY cdo_idx already in cache
	at org.eclipse.emf.cdo.server.internal.db.SmartPreparedStatementCache$Cache.put(SmartPreparedStatementCache.java:123)
	at org.eclipse.emf.cdo.server.internal.db.SmartPreparedStatementCache.releasePreparedStatement(SmartPreparedStatementCache.java:61)
	at org.eclipse.emf.cdo.server.internal.db.mapping.horizontal.BranchingListTableMappingWithRanges.readValues(BranchingListTableMappingWithRanges.java:384)

This bug is probably related to the bug https://bugs.eclipse.org/bugs/show_bug.cgi?id=339313 , which solves the exception caused by the uninitalized lists, but doesn't solve the initialization itself.

Do you have any hint where the initialization of the base revision should happen?
Comment 3 Szabolcs Bardy CLA 2011-04-27 07:34:45 EDT
Created attachment 194144 [details]
CDO test case to reproduce the error

Attaching a test case patch for the project org.eclipse.emf.cdo.test that reproduces the error.
Comment 4 Eike Stepper CLA 2011-04-28 05:01:35 EDT
Created attachment 194245 [details]
Test v2
Comment 5 Eike Stepper CLA 2012-06-05 07:28:04 EDT
Moving all open bug reports to 4.1 because the release is very near and it's hghly unlikely that there will be spare time to address 4.0 problems.

Please make sure that your patches can be applied against the master branch and that your problem is not already fixed there!!!
Comment 6 Eike Stepper CLA 2012-08-14 22:52:21 EDT
Moving all open issues to 4.2. Open bugs can be ported to 4.1 maintenance after they've been fixed in master.
Comment 7 Eike Stepper CLA 2013-06-29 12:18:16 EDT
We'll try to address open problems in 4.3 (master) first and then port fixes back to 4.2.
Comment 8 Eike Stepper CLA 2015-07-14 02:12:18 EDT
Moving all open bugzillas to 4.5.
Comment 9 Eike Stepper CLA 2016-07-31 00:54:54 EDT
Moving all unaddressed bugzillas to 4.6.
Comment 10 Eike Stepper CLA 2017-12-28 01:09:33 EST
Moving all open bugs to 4.7
Comment 11 Eike Stepper CLA 2019-11-08 02:12:54 EST
Moving all unresolved issues to version 4.8-
Comment 12 Eike Stepper CLA 2019-12-13 12:49:09 EST
Moving all unresolved issues to version 4.9
Comment 13 Eike Stepper CLA 2020-12-11 10:46:42 EST
Moving to 4.13.