openjpa-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Ravi P Palacherla (JIRA)" <j...@apache.org>
Subject [jira] Commented: (OPENJPA-1163) Data consistency issues while modifying collections.
Date Thu, 23 Jul 2009 19:18:15 GMT

    [ https://issues.apache.org/jira/browse/OPENJPA-1163?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12734736#action_12734736
] 

Ravi P Palacherla commented on OPENJPA-1163:
--------------------------------------------

Hi Mike,

In my example, data dealt with Trans1 and Trans2 is not interfering with each other.
Both Trans1 and Trans2 are working on different objects and different rows of table.
Hence I fail to understand what you meant by "This patch demonstrates a race condition more
than anything else."

The whole idea of my testcase is to demonstrate that the results in database are different
if I execute same code but the number of rows updates are different.

A Item has 10 rows.
Trans1 --> deletes 10 rows. (0 to 9)
                   Adds 10 rows.(10 to 19)
Trans2 --> Adds 10 rows.(20 to 29)
Commit Trans2.
Commit Trans1.

Rows in talbe AItems after above execution : ( 10 to 19) = 10 rows in total.

The same code when I manipulate only 3 rows.
A Item has 10 rows.
Trans1 --> deletes 3 rows. (0 to 6)
                   Adds 3 rows.(10 to 12)
Trans2 --> Adds 3 rows.(20 to 22)
Commit Trans2.
Commit Trans1.
Rows in talbe AItems after above execution : (0 to 6 , 10 to 12 , 20 to 22) = 13 rows in total

If only Trans1 has to win , then the results should be ( 0 to 6 ,10 to 12 = 10 in total) rather
than 13.

So the results in AItems are different even though the same code is executed.

>> You mentioned "The last one to commit wins."
When the data in both the transactions are not interfering with each other then both the transactions
has to win , isn't it ?

Please correct me if I am loosing the track.

Thanks,
Ravi.

> Data consistency issues while modifying collections.
> ----------------------------------------------------
>
>                 Key: OPENJPA-1163
>                 URL: https://issues.apache.org/jira/browse/OPENJPA-1163
>             Project: OpenJPA
>          Issue Type: Bug
>          Components: kernel
>    Affects Versions: 2.0.0
>         Environment: openJPA trunk. Derby DB.
>            Reporter: Ravi P Palacherla
>            Assignee: Ravi P Palacherla
>             Fix For: 2.0.0
>
>         Attachments: OPENJPA-1163_trunk.patch
>
>
> There are data consistency issues when modifying more number of elements in a collection
Vs less number of elements.
> Following is a detailed explanation about the issue with example:
>  
> - Entity A has a collection of Entities AItems with cascade ALL.
> - Test case :
>   Clear all the data inside tables representing Entity A and AItems.  
>   Create 3 entity managers em1,em2 and em3.
>    
>   em1.begin()
>       create A on em1 with id "1"
>       add 10 elements of AItems (id's from 0-9) to the created A(id 1).
>       persist A.
>   em1.commit()
>  
>   em1.begin()
>       merge A ( created in the previous step)
>       Remove 3 elements of AItems from the merged A.
>       Add 3 elements of AItems ( id's 10,11,12) to the merged A (id 1).
>    
> With out committing em1
>    
>   em2.begin()
>       query database to fetch A and construct object result2 of entity A.
>       Add 3 elements of AItems ( id's 13,14,15) to fetched A ( result2)      
>    em2.commit ()
>    em1.commit()
>    
>   em3.begin()
>      query database to check the size of AItems that are related to A ( id 1)
>   em3.commit()
>    
>   The result on em3's query for AItems related to A, returns 13 as expected.
>   13 ( Initial 10 - em1's 3 + em1's 3 + em2's 3).
>    
> When the same test case is repeated with removing and adding 10 elements instead of 3
as before then I get wrong results.
>    
>     Add initial 10 AItems (id's 0-9) for A.
>     commit()
>    
>     em1 will remove 10 AItems from the collection of A.
>     em1 will add 10 AItems (id's 10-19) to collection of A.
>    
>     em2 will add 10 AItems (id's 20-29) to collection of A.
>    
>     Commit em2.
>     Commit em1.
>    
>     Then instead of 20 elements ( Initial 10 - em1's 10 + em1's 10 + em2's 10), I see
only 10 elements.
>    
>     The 10 elements that I see are from em1's added AItems ( id's 10-19).
> I think the cause of the issue is that, when more number of elements (compared to initial
element count of collection) in a collection are modified then collection tracking is disabled
and openJPA tries to do the following:
>  -- Delete every thing from the collection
>  -- Insert data back to collection.
> While Inserting the data back it does not consider adding the dirty records ( em2's 10
added elements ) because the collection tracking is disabled.

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


Mime
View raw message