From dev-return-18927-apmail-openjpa-dev-archive=openjpa.apache.org@openjpa.apache.org Sat Apr 09 11:45:45 2011 Return-Path: Delivered-To: apmail-openjpa-dev-archive@www.apache.org Received: (qmail 77844 invoked from network); 9 Apr 2011 11:45:45 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.3) by minotaur.apache.org with SMTP; 9 Apr 2011 11:45:45 -0000 Received: (qmail 25778 invoked by uid 500); 9 Apr 2011 11:45:45 -0000 Delivered-To: apmail-openjpa-dev-archive@openjpa.apache.org Received: (qmail 25723 invoked by uid 500); 9 Apr 2011 11:45:44 -0000 Mailing-List: contact dev-help@openjpa.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@openjpa.apache.org Delivered-To: mailing list dev@openjpa.apache.org Received: (qmail 25433 invoked by uid 99); 9 Apr 2011 11:45:43 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Sat, 09 Apr 2011 11:45:43 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=5.0 tests=ALL_TRUSTED,T_RP_MATCHES_RCVD X-Spam-Check-By: apache.org Received: from [140.211.11.116] (HELO hel.zones.apache.org) (140.211.11.116) by apache.org (qpsmtpd/0.29) with ESMTP; Sat, 09 Apr 2011 11:45:42 +0000 Received: from hel.zones.apache.org (hel.zones.apache.org [140.211.11.116]) by hel.zones.apache.org (Postfix) with ESMTP id B842499DA8 for ; Sat, 9 Apr 2011 11:45:05 +0000 (UTC) Date: Sat, 9 Apr 2011 11:45:05 +0000 (UTC) From: "Rick Curtis (JIRA)" To: dev@openjpa.apache.org Message-ID: <1774048706.46209.1302349505736.JavaMail.tomcat@hel.zones.apache.org> In-Reply-To: <1846093963.15845.1301277245789.JavaMail.tomcat@hel.zones.apache.org> Subject: [jira] [Updated] (OPENJPA-1967) Got stale data from cache in multi threaded application MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit X-JIRA-FingerPrint: 30527f35849b9dde25b450d4833f0394 [ https://issues.apache.org/jira/browse/OPENJPA-1967?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ] Rick Curtis updated OPENJPA-1967: --------------------------------- Attachment: OPENJPA-1967.ut.patch Uploading the test as a patch file. > Got stale data from cache in multi threaded application > ------------------------------------------------------- > > Key: OPENJPA-1967 > URL: https://issues.apache.org/jira/browse/OPENJPA-1967 > Project: OpenJPA > Issue Type: Bug > Components: datacache > Affects Versions: 1.2.2, 2.1.0 > Reporter: Noriyuki Kajitani > Priority: Minor > Attachments: OPENJPA-1967.ut.patch, OpenJPA-1967_UT.zip > > > In multi threaded application, I experienced getting a stale data from > OpenJPA even right after updating it. Let's say a thread (named T1) > updates a data with a value (V0) to (V1), then retrieves it from > OpenJPA. An another thread also retrieves it in a same time. Here, > it is expected that T1 retrieves a value V1, but it may get old value > V0, which is not expected behavior. > The cause seems OpenJPA's putting a stale data in its cache. It could > occur in the following three cases in both OpenJPA 1.2.2 and 2.1.0. > case 1: > See org.apache.openjpa.datacache.DataCacheStoreManager.java#load method. > Let's say a thread is going to acquire write lock at the Line 402. At the same time, the other thread can cached the data out during its operation. In such case, the data becomes null when it reaches the Line 404. > 404:data = cache.get(sm.getObjectId()); > It does not compare the data version, so stale data is cached in the following part even if data has been updated in other threads. > 405:if (data != null && compareVersion(sm, sm.getVersion(), > 406: data.getVersion()) == VERSION_EARLIER) > .... > 410: boolean isNew = data == null; > 411: if (isNew) > 412: data = newPCData(sm); > 413: data.store(sm, fields); > 414: if (isNew) > 415: cache.put(data); > case 2: > See org.apache.openjpa.datacache.DataCacheStoreManager.java#initialize method. > Let's say a thread is going to acquire write lock at the Line 358. At the same time, the other thread can cached the data out during its operation. In such case, the data becomes null when it reaches the Line 360. > 360:data = cache.get(sm.getObjectId()); > It does not compare the data version, so stale data is cached in the following part even if data has been updated in other threads. > 361:if (data != null && compareVersion(sm, sm.getVersion(), > 362: data.getVersion()) == VERSION_EARLIER) > .... > 368: if (data == null) > 369: data = newPCData(sm); > 370: data.store(sm); > 371: cache.put(data); > case 3: > See org.apache.openjpa.datacache.DataCacheStoreManager.java#updateCaches. > The cache was not locked during its access. So it could cache a stale data in multithreaded application. Here's a case: > The thread1 gets the data from OpenJPA. > The thread2 updates and gets the data from OpenJPA. > thread2:gets the data from cache. > thread2:sets something value to column. > thread2:updates to database. > thread2:flush > thread2:gets data from cache. > thread1:OpenJPA expires the cached data. > thread1:creates cache data. > thread2:sets something value different from previous set value to column. > thread2:puts data in cache. > thread1:puts data in cache. <= override by stale data. -- This message is automatically generated by JIRA. For more information on JIRA, see: http://www.atlassian.com/software/jira