Return-Path: X-Original-To: apmail-ofbiz-user-archive@www.apache.org Delivered-To: apmail-ofbiz-user-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 5459211794 for ; Wed, 6 Aug 2014 07:09:33 +0000 (UTC) Received: (qmail 89128 invoked by uid 500); 6 Aug 2014 07:09:32 -0000 Delivered-To: apmail-ofbiz-user-archive@ofbiz.apache.org Received: (qmail 89101 invoked by uid 500); 6 Aug 2014 07:09:32 -0000 Mailing-List: contact user-help@ofbiz.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: user@ofbiz.apache.org Delivered-To: mailing list user@ofbiz.apache.org Received: (qmail 89089 invoked by uid 99); 6 Aug 2014 07:09:32 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 06 Aug 2014 07:09:32 +0000 X-ASF-Spam-Status: No, hits=-0.7 required=5.0 tests=RCVD_IN_DNSWL_LOW,SPF_PASS X-Spam-Check-By: apache.org Received-SPF: pass (athena.apache.org: domain of chunlinyao@gmail.com designates 209.85.192.175 as permitted sender) Received: from [209.85.192.175] (HELO mail-pd0-f175.google.com) (209.85.192.175) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 06 Aug 2014 07:09:26 +0000 Received: by mail-pd0-f175.google.com with SMTP id r10so2796817pdi.34 for ; Wed, 06 Aug 2014 00:09:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=content-type:mime-version:subject:from:in-reply-to:date :content-transfer-encoding:message-id:references:to; bh=bEJQMl3bHHLOxG1XOoVt2I3z75j/HA1iwKHZw4Efq0E=; b=N/9wK7c3Lwu0VWITEAS8IheE5nRb52TUTfTVelywkyKpyzGg5CxCST80JuLgiUzHne e2e74n26WYIr5Vrgt8QDToVge594ZPO39oPXKqYd+2PjadfjYlyQGHzRRqvAgroVJ2AB oU/l1gIzJzd90DPAVbgQmd/twcJnlpFiN3l7VqnOAmUAPj8La5zHribmFC3a0yLu9zDl 121QuI/aUV8B3qEEkWnTwmopY7Z1bI78TtJhtwJDnuVG7mvTiIP75K2UY12+TdFpVEv9 J951DdBJLax/acVdteKY/QCDCrlHOvtyfd8cIHCSehLgMFUwkl/2cnMlCPC/JnHVHCKR ZByQ== X-Received: by 10.68.93.65 with SMTP id cs1mr9528612pbb.52.1407308945266; Wed, 06 Aug 2014 00:09:05 -0700 (PDT) Received: from [172.28.1.168] (KD113154025018.ppp-bb.dion.ne.jp. [113.154.25.18]) by mx.google.com with ESMTPSA id fy1sm230625pdb.66.2014.08.06.00.09.02 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Wed, 06 Aug 2014 00:09:04 -0700 (PDT) Content-Type: text/plain; charset=utf-8 Mime-Version: 1.0 (Mac OS X Mail 7.3 \(1878.6\)) Subject: Re: Should we use some lock when update qoh of InventoryItem From: YaoCL In-Reply-To: <53E1CED4.3090909@sandglass-software.com> Date: Wed, 6 Aug 2014 15:08:57 +0800 Content-Transfer-Encoding: quoted-printable Message-Id: References: <53E1C005.2040508@sandglass-software.com> <53E1CED4.3090909@sandglass-software.com> To: user@ofbiz.apache.org X-Mailer: Apple Mail (2.1878.6) X-Virus-Checked: Checked by ClamAV on apache.org Did you mean storeByCondition method. With it I must check the updated = row count, if equals 0 retry again. SELECT FOR UPDATE will block one = transaction to wait until the end of another transaction. On Wed, Aug 06, 2014 at 14:44, Adrian Crum = Wrote: >=20 > The entity engine supports updates that include a WHERE clause - so it = would be possible to update only when the lastUpdatedStamp matches. >=20 > Adrian Crum > Sandglass Software > www.sandglass-software.com >=20 > On 8/6/2014 7:31 AM, Yaocl wrote: >> I can only consider a solution use SELECT FOR UPDATE, lock the >> inventory item then SELECT ... sum(...) FROM inventory_item_detail >> GROUP BY ...., then update the inventory item. But it seems >> EntityEngine not support FOR UPDATE. >> -- >> YaoCL >>=20 >> On Wed, Aug 6, 2014 at 1:41 PM, Adrian Crum >> wrote: >>> This has been discussed on the dev mailing list, and there are = differing >>> opinions. I agree this is a bug and should be fixed, but others = believe it >>> is highly unlikely two people will be modifying the same invoice at = the same >>> time - so it is not a problem. >>>=20 >>> Adrian Crum >>> Sandglass Software >>> www.sandglass-software.com >>>=20 >>>=20 >>> On 8/6/2014 3:01 AM, YaoCL wrote: >>>>=20 >>>> Hi, >>>>=20 >>>> When create a new InventoryItemDetail the InventoryItem will be = updated by >>>> eeca. But If two threads create InventoryItemDetails = simultaneously. Because >>>> we use ReadCommitted Isolation level, Neither will see = InventoryItemDetails >>>> created by other threads before transaction commit. >>>> updateInventoryItemFromDetail service will get incorrect qoh, and >>>> InventoryItem will be updated. Two threads will all be committed >>>> successfully. >>>>=20 >>>> I can confirm the behavior by set a breakpoint in >>>> org.ofbiz.minilang.method.entityops.StoreValue.exec(MethodContext) = to >>>> emulate above process. The result can be checked by this SQL. >>>>=20 >>>> select * from inventory_item t1 left join ( >>>> select inventory_item_id, sum(quantity_on_hand_diff) as qoh, >>>> sum(available_to_promise_diff) as atp from inventory_item_detail >>>> group by inventory_item_id) t2 on t1.inventory_item_id =3D >>>> t2.inventory_item_id >>>> where t1.quantity_on_hand_total <> t2.qoh; >>>>=20 >>>> =E2=80=94 >>>> YaoCL >>>>=20 >>>=20