Return-Path: X-Original-To: archive-asf-public-internal@cust-asf2.ponee.io Delivered-To: archive-asf-public-internal@cust-asf2.ponee.io Received: from cust-asf.ponee.io (cust-asf.ponee.io [163.172.22.183]) by cust-asf2.ponee.io (Postfix) with ESMTP id CEEEA200C1F for ; Sat, 18 Feb 2017 08:06:33 +0100 (CET) Received: by cust-asf.ponee.io (Postfix) id CD771160B66; Sat, 18 Feb 2017 07:06:33 +0000 (UTC) Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by cust-asf.ponee.io (Postfix) with SMTP id EF8F1160B63 for ; Sat, 18 Feb 2017 08:06:32 +0100 (CET) Received: (qmail 64139 invoked by uid 500); 18 Feb 2017 07:06:27 -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 64127 invoked by uid 99); 18 Feb 2017 07:06:26 -0000 Received: from pnap-us-west-generic-nat.apache.org (HELO spamd2-us-west.apache.org) (209.188.14.142) by apache.org (qpsmtpd/0.29) with ESMTP; Sat, 18 Feb 2017 07:06:26 +0000 Received: from localhost (localhost [127.0.0.1]) by spamd2-us-west.apache.org (ASF Mail Server at spamd2-us-west.apache.org) with ESMTP id 2C8011A0525 for ; Sat, 18 Feb 2017 07:06:26 +0000 (UTC) X-Virus-Scanned: Debian amavisd-new at spamd2-us-west.apache.org X-Spam-Flag: NO X-Spam-Score: 2.481 X-Spam-Level: ** X-Spam-Status: No, score=2.481 tagged_above=-999 required=6.31 tests=[DKIM_SIGNED=0.1, DKIM_VALID=-0.1, HTML_MESSAGE=2, HTML_OBFUSCATE_05_10=0.001, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H3=-0.01, RCVD_IN_MSPIKE_WL=-0.01, RCVD_IN_SORBS_SPAM=0.5, SPF_PASS=-0.001, URIBL_BLOCKED=0.001] autolearn=disabled Authentication-Results: spamd2-us-west.apache.org (amavisd-new); dkim=pass (2048-bit key) header.d=hotwaxsystems-com.20150623.gappssmtp.com Received: from mx1-lw-eu.apache.org ([10.40.0.8]) by localhost (spamd2-us-west.apache.org [10.40.0.9]) (amavisd-new, port 10024) with ESMTP id 7hb9c3CinfwM for ; Sat, 18 Feb 2017 07:06:23 +0000 (UTC) Received: from mail-ua0-f174.google.com (mail-ua0-f174.google.com [209.85.217.174]) by mx1-lw-eu.apache.org (ASF Mail Server at mx1-lw-eu.apache.org) with ESMTPS id E670B5F3FF for ; Sat, 18 Feb 2017 07:06:22 +0000 (UTC) Received: by mail-ua0-f174.google.com with SMTP id k3so6596556uak.2 for ; Fri, 17 Feb 2017 23:06:22 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=hotwaxsystems-com.20150623.gappssmtp.com; s=20150623; h=mime-version:in-reply-to:references:from:date:message-id:subject:to; bh=4xwGtSun8rTY32UakEOVnwJRgvFttrwtA/0kqTsb5Vo=; b=JMEiFjYyXTMjnu7Xv3Fi80IHsIab35Z8/CKgLF0JbKm9BU/r04/LnB5TSAsI8aec+T xbtQU3001G2ajYWtXb5KjFdpKpU+T10w8mFFS1jATn4iLTTTPx3Cb8E45hixsTrTqZSr 0YuVa5gFae/TQIML8ebVGydvTzXlvxY9Td4QF6Rx69V18ETr5JZQXZV4PZf08iCv3/Yz QFIVZofR11nvJIwPmkHez+veN1M0bIcTv7LpbP5K2pbqZ0Rc4fOEaMmAM0kFW9tNBc/u ucbwicJZuiy7ubUnlP7d8r0SyjlJBqKGapx3ZGN482pN2QE1mKJrAnor9SZ36wKt6LIK o25g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to; bh=4xwGtSun8rTY32UakEOVnwJRgvFttrwtA/0kqTsb5Vo=; b=oKhfSLHS7YAPgwVtYSiG/txduQslTtmNU/eGH2xiWPOtWZB7ysEMd5zYTOprx6gnex cgiz83G4QoxSp4WPJNudpykqu4fx2KRyt9dx/QFU15PCyIpbmc2ZeWKakFcjGp62R+Io PhzEmp4wZqL/h/zWu8AMKfaj/EWX+uwmbTakSVY/X9b8dgUcNbrx/6BH2l6PqmWTj81T zUz/KW3Owuj1sXROWJ4eAKxDjMrDzKOBo5hRXMZnUWL68v8Dc0PveW+XHrAzYfeK67qa 2sRQeaE7aRMerSv2cfTeoUS0SQBGmCLq5l4Obh4OvgLF6CcLprSCNn8hJpW2OJAmGjOs ZYUQ== X-Gm-Message-State: AMke39lO+DMFOuUyJBw3USqVSpxOzi5jPq2tuTPXKIZzLtpgmiT8IOcPT3wIBg3ZVFxouAUoC6KJbnnkO/v4EQ== X-Received: by 10.176.2.113 with SMTP id 104mr5213841uas.155.1487401581742; Fri, 17 Feb 2017 23:06:21 -0800 (PST) MIME-Version: 1.0 Received: by 10.103.0.5 with HTTP; Fri, 17 Feb 2017 23:06:21 -0800 (PST) Received: by 10.103.0.5 with HTTP; Fri, 17 Feb 2017 23:06:21 -0800 (PST) In-Reply-To: <8a82eea1-06e2-ae47-1fa0-12ce91546e8f@les7arts.com> References: <8a82eea1-06e2-ae47-1fa0-12ce91546e8f@les7arts.com> From: Scott Gray Date: Sat, 18 Feb 2017 20:06:21 +1300 Message-ID: Subject: Re: MySQL Deadlocks in OfBiz 12.04 To: user@ofbiz.apache.org Content-Type: multipart/alternative; boundary=001a113e4b92eb26f70548c8aac4 archived-at: Sat, 18 Feb 2017 07:06:34 -0000 --001a113e4b92eb26f70548c8aac4 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Which bug are you referring to Jacques? FinAccount services certainly need to be refactored but the use case that I mentioned was unusual so it probably isn't worth fixing unless a more common scenario comes along. It just happened to be a simple example I had on hand. Regards Scott On 18/02/2017 01:52, "Jacques Le Roux" wrote= : > Hi Scott, > > Should we not open a Jira and try to fix this bug? > > Jacques > > > Le 16/02/2017 =C3=A0 04:04, Scott Gray a =C3=A9crit : > >> For example, a current project has some heavily used FinAccount rows and >> the OFBiz implementation has a tendency to modify the child rows >> (FinAccountAuth/FinAccountTrans) before modifying the parent FinAccount >> row. This very easily results in a deadlock as soon as one of the >> competing transactions attempts to perform an update on the FinAccount >> record. This happens because the child row modifications result in a >> shared lock on the parent row due to the foreign key constraint, but onc= e >> multiple transactions both have that shared lock, neither can update the >> FinAccount without causing a deadlock exception. >> >> So my quick fix solution is to acquire a lock on the FinAccount record >> *before* any child rows are modified: >> delegator.storeByCondition("FinAccount", UtilMisc.toMap("lastUpdatedSta >> mp", >> UtilDateTime.nowTimestamp()), EntityCondition.makeCondition( >> "finAccountId", >> finAccountId)); >> >> Assuming all code paths relating to modifying FinAccount data are >> following >> this strategy then each transaction will have to queue on this update >> statement until their turn comes up. Voila, deadlocks are gone. >> >> Regards >> Scott >> >> >> On 16 February 2017 at 09:29, Robb Wagoner wrote: >> >> Thanks Scott. Since I am new to OfBiz can you provide a code example? I.= e. >>> by what means are you issuing an arbitrary no-op update statement on a >>> parent row? >>> >>> On Wed, Feb 15, 2017 at 1:02 PM Scott Gray >> > >>> wrote: >>> >>> Hi Robb, >>> >>> I've encountered similar deadlocks in the past and have simply issued a= n >>> update statement on the main row before attempting to work with any chi= ld >>> rows. That has the same effect as the FOR UPDATE statement but without >>> needing to enhance the framework. >>> >>> Regards >>> Scott >>> >>> On 16/02/2017 08:03, "Robb Wagoner" wrote: >>> >>> We are running OfBiz 12.04 and are using MySQL 5.6 as the RDBMS. We are >>>> experiencing database deadlocks and would like to be able to add >>>> MySQL-specific statements to deal with the deadlocks. For example: >>>> >>> `SELECT >>> >>>> ... FOR UPDATE` on PRIMARY KEYs and/or FOREIGN KEYs in the transaction= s. >>>> >>>> Being new to OfBiz, I've been reviewing the ofbiz-user and ofbiz-dev >>>> archives, OfBiz Wiki, Packt's *Apache OfBiz Cookbook*, and other >>>> >>> resources >>> >>>> to learn how we can achieve this. >>>> I see mentions of deadlocks in the archives and in JIRA issues ( >>>> https://issues.apache.org/jira/browse/OFBIZ-5065). Nothing conclusive >>>> or >>>> directly actionable on managing/dealing with deadlocks is mentioned. >>>> >>>> What is the OfBiz-way of dealing with RDBMS deadlocks? >>>> >>>> >>>> *Deadlocking statements:* >>>> UPDATE SHIPMENT >>>> UPDATE INVENTORY_ITEM >>>> UPDATE GL_ACCOUNT_ORGANIZATION >>>> INSERT INTO ACCTG_TRANS_ENTRY >>>> >>>> >>>> *entityengine.xml datasource element:* >>>> >>> helper-class=3D"org.ofbiz.entit >>>> y.datasource.GenericHelperDAO" >>>> field-type-name=3D"mysql" >>>> check-on-start=3D"true" >>>> add-missing-on-start=3D"true" >>>> check-pks-on-start=3D"false" >>>> check-indices-on-start=3D"false" >>>> use-foreign-keys=3D"true" >>>> join-style=3D"ansi-no-parenthesis" >>>> alias-view-columns=3D"false" >>>> drop-fk-use-foreign-key-keyword=3D"true" >>>> table-type=3D"InnoDB" >>>> character-set=3D"utf8" >>>> collate=3D"utf8_general_ci"> >>>> >>>> >>>> >>>> >>>> >>>> >>> jdbc-driver=3D"com.mysql.jdbc.Driver" >>>> jdbc-uri=3D"jdbc:mysql:// >>>> ofbiz-db.example.com/ofbiz?autoReconnect=3Dtrue" >>>> jdbc-username=3D"ofbiz" >>>> jdbc-password=3D"XXXXpasswordXXXX" >>>> isolation-level=3D"ReadCommitted" >>>> pool-minsize=3D"2" >>>> pool-maxsize=3D"250" >>>> time-between-eviction-runs-millis=3D"600000"/> >>>> >>>> >>>> >>>> > --001a113e4b92eb26f70548c8aac4--