CiviCRM Community Forums (archive)

*

News:

Have a question about CiviCRM?
Get it answered quickly at the new
CiviCRM Stack Exchange Q+A site

This forum was archived on 25 November 2017. Learn more.
How to get involved.
What to do if you think you've found a bug.



  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Support »
  • Using CiviCRM »
  • Using Core CiviCRM Functions (Moderator: Yashodha Chaku) »
  • Database deadlock
Pages: [1]

Author Topic: Database deadlock  (Read 3714 times)

clemenbor

  • I’m new here
  • *
  • Posts: 16
  • Karma: 1
  • CiviCRM version: 4.1.5
  • CMS version: Drupal 6
  • MySQL version: 5.1.48
  • PHP version: 5.2.1
Database deadlock
November 22, 2011, 09:47:06 am
I´m trying to make a simple search by a group of contacts and I´m getting the following error:


Database Error Code: Deadlock found when trying to get lock; try restarting transaction, 1213
Additional Details:

"Array
(
    [callback] => Array
        (
           
  • => CRM_Core_Error
  • [1] => handle
            )

       
[code1] => a515ac9c2796ca0e23adbe92c68fc9fc
    [message] => DB Error: a515ac9c2796ca0e23adbe92c68fc9fc
    [mode] => 16
    [debug_info] => REPLACE INTO civicrm_group_contact_cache (group_id,contact_id) VALUES (13,4856),(13,4857),.....(13,4860); [nativecode=1213 ** Deadlock found when trying to get lock; try restarting transaction]
    [to_string] => [db_error: message="DB Error: a515ac9c2796ca0e23adbe92c68fc9fc" code=0 mode=callback callback=CRM_Core_Error::handle prefix="" info="REPLACE INTO civicrm_group_contact_cache (group_id,contact_id) VALUES (13,4856),........(13,4860); [nativecode=1213 ** Deadlock found when trying to get lock; try restarting transaction]"]
)"

It looks that there is some kind of problem with the civicrm_group_contact_cache table, but I´m nor sure how to solve it. Is there a way to empty this table with drush or something??

Any suggestions would be helpful..

Regards,

Hershel

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4640
  • Karma: 176
    • CiviHosting
  • CiviCRM version: Latest
  • CMS version: Mostly WordPress and Drupal
Re: Database deadlock
November 23, 2011, 05:20:13 am
You could try to TRUNCATE that table in MySQL. If you have phpMyAdmin you can do it, or via MySQL command line interface.
CiviHosting and CiviOnline -- The CiviCRM hosting experts, since 2007

See here for the official: What to do if you think you've found a bug.

clemenbor

  • I’m new here
  • *
  • Posts: 16
  • Karma: 1
  • CiviCRM version: 4.1.5
  • CMS version: Drupal 6
  • MySQL version: 5.1.48
  • PHP version: 5.2.1
Re: Database deadlock
November 23, 2011, 06:41:03 am
Ok, I could try to TRUNCATE this table, but I´m just concerned about what I´m going to loose here. Is this table used for smart groups??

Thanks in advance..

Hershel

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4640
  • Karma: 176
    • CiviHosting
  • CiviCRM version: Latest
  • CMS version: Mostly WordPress and Drupal
Re: Database deadlock
November 23, 2011, 07:42:02 am
It's a cache table and it should be safe to truncate AFAIK.
CiviHosting and CiviOnline -- The CiviCRM hosting experts, since 2007

See here for the official: What to do if you think you've found a bug.

Eileen

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4195
  • Karma: 218
    • Fuzion
Re: Database deadlock
November 23, 2011, 12:59:29 pm
Are you using hierarchical groups. This situation arises if you have a group that is a subgroup of another group but also has that other group in it's criteria.
Make today the day you step up to support CiviCRM and all the amazing organisations that are using it to improve our world - http://civicrm.org/contribute

clemenbor

  • I’m new here
  • *
  • Posts: 16
  • Karma: 1
  • CiviCRM version: 4.1.5
  • CMS version: Drupal 6
  • MySQL version: 5.1.48
  • PHP version: 5.2.1
Re: Database deadlock
November 24, 2011, 06:17:05 am
Yes, there were some hierarchical groups. I just tagged them and then deleted the child groups.

Now, when I want to search the parent group... I get a WSOD after a couple minutes. I have been checking the behavior on the civicrm_group_contact_cache, and the system is filling and clearing this table every time I try the searching under this group, it looks like a loop or something.

Truncating this table didn´t make it :(

Right now I´m kind of stuck trying to recover the parent group....

Any other ideas?

Thanks in advance...


Eileen

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4195
  • Karma: 218
    • Fuzion
Re: Database deadlock
November 24, 2011, 12:12:27 pm
There was a minor fix to the way the cache is truncated that went in at one point - I can't remember if it was before or after 3.4.2 though. It didn't fix the circular group problem which is where a group has it's parent group in the criteria (which produces the symptoms you describe but which you seem to have dealt to now..

Make today the day you step up to support CiviCRM and all the amazing organisations that are using it to improve our world - http://civicrm.org/contribute

sanook

  • I post occasionally
  • **
  • Posts: 32
  • Karma: 1
Re: Database deadlock
November 28, 2011, 10:39:21 am
I am experiencing similar issues running 3.4.7 on drupal 6.x

I run into the error when trying to start a new mailing in CiviMail.  At the first step when i name the mailing and choose a group it runs for a long time then gives this error.  I have tried removing child groups, truncating the table, all to no avail.  PLEASE HELP

my error code:

Database Error Code: Deadlock found when trying to get lock; try restarting transaction, 1213
Additional Details:
Array
(
    [callback] => Array
        (
           
  • => CRM_Core_Error
  • [1] => handle
            )

       
Code: [Select]
=> a515ac9c2796ca0e23adbe92c68fc9fc
    [message] => DB Error: a515ac9c2796ca0e23adbe92c68fc9fc
    [mode] => 16
    [debug_info] => REPLACE INTO civicrm_group_contact_cache (group_id,contact_id) VALUES (90,12651),(90,11734),(90,11079),(90,10683),(90,10298),(90,12127),(90,22347),(90,10925),(90,11002),(90,11750),(90,11877),(90,11815),(90,12215),(90,11614),(90,11017),(90,12072),(90,12402),(90,12169),(90,10447),(90,10497),(90,10300),(90,11985),(90,12301),(90,11458),(90,18183),(90,22370),(90,10322),(90,10868),(90,21181),(90,12201),(90,10856),(90,23754),(90,22318),(90,23783),(90,11362),(90,11952),(90,22228),(90,22352),(90,23854),(90,22227),(90,10452),(90,10618),(90,10650),(90,10649),(90,18203),(90,11775),(90,12391),(90,9796),(90,11322),(90,10393),(90,12132),(90,9803),(90,11528),(90,12221),(90,10419),(90,22358),(90,10569),(90,11613),(90,11539),(90,11031),(90,22285),(90,11247),(90,11236),(90,11243),(90,23760),(90,11849),(90,11605),(90,11214),(90,23886),(90,10816),(90,12638),(90,12355),(90,10867),(90,12118),(90,11329),(90,11452),(90,10567),(90,10390),(90,11506),(90,12689),(90,12014),(90,10900),(90,10279),(90,17206),(90,10825),(90,10952),(90,12095),(90,11112),(90,9743),(90,11797),(90,11068),(90,11770),(90,23884),(90,10581),(90,18174),(90,11015),(90,23774),(90,11304),(90,17538),(90,12338),(90,12281),(90,12020),(90,10292),(90,12612),(90,12468),(90,9802),(90,12692),(90,10614),(90,11830),(90,11163),(90,10511),(90,12010),(90,11518),(90,22377),(90,12258),(90,11194),(90,12162),(90,22367),(90,12309),(90,12450),(90,12647),(90,10653),(90,12242),(90,23867),(90,24027),(90,23883),(90,10365),(90,12092),(90,10884),(90,11997),(90,11916),(90,11173),(90,10818),(90,12084),(90,11192),(90,18004),(90,11262),(90,11288),(90,10388),(90,22383),(90,11515),(90,11437),(90,12175),(90,23793),(90,18202),(90,11526),(90,12004),(90,10538),(90,11691),(90,22340),(90,10449),(90,11665),(90,9775),(90,10726),(90,12047),(90,11152),(90,12100),(90,10391),(90,11711),(90,11901),(90,11881),(90,11254),(90,9805),(90,10789),(90,11352),(90,22350),(90,12037),(90,12007),(90,12153),(90,11101),(90,12633),(90,12641),(90,9806),(90,22388),(90,10896),(90,12346),(90,12233),(90,10578),(90,10302),(90,11792),(90,10956),(90,10815),(90,12253),(90,10426),(90,22204),(90,11306),(90,11714),(90,11380),(90,10982),(90,10489),(90,10487),(90,11242),(90,22356),(90,11878),(90,11317),(90,11070),(90,23762),(90,12287),(90,10436),(90,12380); [nativecode=1213 ** Deadlock found when trying to get lock; try restarting transaction]
    [type] => DB_Error
    [user_info] => REPLACE INTO civicrm_group_contact_cache (group_id,contact_id) VALUES (90,12651),(90,11734),(90,11079),(90,10683),(90,10298),(90,12127),(90,22347),(90,10925),(90,11002),(90,11750),(90,11877),(90,11815),(90,12215),(90,11614),(90,11017),(90,12072),(90,12402),(90,12169),(90,10447),(90,10497),(90,10300),(90,11985),(90,12301),(90,11458),(90,18183),(90,22370),(90,10322),(90,10868),(90,21181),(90,12201),(90,10856),(90,23754),(90,22318),(90,23783),(90,11362),(90,11952),(90,22228),(90,22352),(90,23854),(90,22227),(90,10452),(90,10618),(90,10650),(90,10649),(90,18203),(90,11775),(90,12391),(90,9796),(90,11322),(90,10393),(90,12132),(90,9803),(90,11528),(90,12221),(90,10419),(90,22358),(90,10569),(90,11613),(90,11539),(90,11031),(90,22285),(90,11247),(90,11236),(90,11243),(90,23760),(90,11849),(90,11605),(90,11214),(90,23886),(90,10816),(90,12638),(90,12355),(90,10867),(90,12118),(90,11329),(90,11452),(90,10567),(90,10390),(90,11506),(90,12689),(90,12014),(90,10900),(90,10279),(90,17206),(90,10825),(90,10952),(90,12095),(90,11112),(90,9743),(90,11797),(90,11068),(90,11770),(90,23884),(90,10581),(90,18174),(90,11015),(90,23774),(90,11304),(90,17538),(90,12338),(90,12281),(90,12020),(90,10292),(90,12612),(90,12468),(90,9802),(90,12692),(90,10614),(90,11830),(90,11163),(90,10511),(90,12010),(90,11518),(90,22377),(90,12258),(90,11194),(90,12162),(90,22367),(90,12309),(90,12450),(90,12647),(90,10653),(90,12242),(90,23867),(90,24027),(90,23883),(90,10365),(90,12092),(90,10884),(90,11997),(90,11916),(90,11173),(90,10818),(90,12084),(90,11192),(90,18004),(90,11262),(90,11288),(90,10388),(90,22383),(90,11515),(90,11437),(90,12175),(90,23793),(90,18202),(90,11526),(90,12004),(90,10538),(90,11691),(90,22340),(90,10449),(90,11665),(90,9775),(90,10726),(90,12047),(90,11152),(90,12100),(90,10391),(90,11711),(90,11901),(90,11881),(90,11254),(90,9805),(90,10789),(90,11352),(90,22350),(90,12037),(90,12007),(90,12153),(90,11101),(90,12633),(90,12641),(90,9806),(90,22388),(90,10896),(90,12346),(90,12233),(90,10578),(90,10302),(90,11792),(90,10956),(90,10815),(90,12253),(90,10426),(90,22204),(90,11306),(90,11714),(90,11380),(90,10982),(90,10489),(90,10487),(90,11242),(90,22356),(90,11878),(90,11317),(90,11070),(90,23762),(90,12287),(90,10436),(90,12380); [nativecode=1213 ** Deadlock found when trying to get lock; try restarting transaction]
    [to_string] => [db_error: message="DB Error: a515ac9c2796ca0e23adbe92c68fc9fc" code=0 mode=callback callback=CRM_Core_Error::handle prefix="" info="REPLACE INTO civicrm_group_contact_cache (group_id,contact_id) VALUES (90,12651),(90,11734),(90,11079),(90,10683),(90,10298),(90,12127),(90,22347),(90,10925),(90,11002),(90,11750),(90,11877),(90,11815),(90,12215),(90,11614),(90,11017),(90,12072),(90,12402),(90,12169),(90,10447),(90,10497),(90,10300),(90,11985),(90,12301),(90,11458),(90,18183),(90,22370),(90,10322),(90,10868),(90,21181),(90,12201),(90,10856),(90,23754),(90,22318),(90,23783),(90,11362),(90,11952),(90,22228),(90,22352),(90,23854),(90,22227),(90,10452),(90,10618),(90,10650),(90,10649),(90,18203),(90,11775),(90,12391),(90,9796),(90,11322),(90,10393),(90,12132),(90,9803),(90,11528),(90,12221),(90,10419),(90,22358),(90,10569),(90,11613),(90,11539),(90,11031),(90,22285),(90,11247),(90,11236),(90,11243),(90,23760),(90,11849),(90,11605),(90,11214),(90,23886),(90,10816),(90,12638),(90,12355),(90,10867),(90,12118),(90,11329),(90,11452),(90,10567),(90,10390),(90,11506),(90,12689),(90,12014),(90,10900),(90,10279),(90,17206),(90,10825),(90,10952),(90,12095),(90,11112),(90,9743),(90,11797),(90,11068),(90,11770),(90,23884),(90,10581),(90,18174),(90,11015),(90,23774),(90,11304),(90,17538),(90,12338),(90,12281),(90,12020),(90,10292),(90,12612),(90,12468),(90,9802),(90,12692),(90,10614),(90,11830),(90,11163),(90,10511),(90,12010),(90,11518),(90,22377),(90,12258),(90,11194),(90,12162),(90,22367),(90,12309),(90,12450),(90,12647),(90,10653),(90,12242),(90,23867),(90,24027),(90,23883),(90,10365),(90,12092),(90,10884),(90,11997),(90,11916),(90,11173),(90,10818),(90,12084),(90,11192),(90,18004),(90,11262),(90,11288),(90,10388),(90,22383),(90,11515),(90,11437),(90,12175),(90,23793),(90,18202),(90,11526),(90,12004),(90,10538),(90,11691),(90,22340),(90,10449),(90,11665),(90,9775),(90,10726),(90,12047),(90,11152),(90,12100),(90,10391),(90,11711),(90,11901),(90,11881),(90,11254),(90,9805),(90,10789),(90,11352),(90,22350),(90,12037),(90,12007),(90,12153),(90,11101),(90,12633),(90,12641),(90,9806),(90,22388),(90,10896),(90,12346),(90,12233),(90,10578),(90,10302),(90,11792),(90,10956),(90,10815),(90,12253),(90,10426),(90,22204),(90,11306),(90,11714),(90,11380),(90,10982),(90,10489),(90,10487),(90,11242),(90,22356),(90,11878),(90,11317),(90,11070),(90,23762),(90,12287),(90,10436),(90,12380); [nativecode=1213 ** Deadlock found when trying to get lock; try restarting transaction]"]
)

sanook

  • I post occasionally
  • **
  • Posts: 32
  • Karma: 1
Re: Database deadlock
November 28, 2011, 10:49:05 am
ok.  I deleted the smart group and recreated.  Seemed to have fixed the issue..... for now.

davej

  • Ask me questions
  • ****
  • Posts: 404
  • Karma: 21
Re: Database deadlock
March 28, 2012, 08:24:57 am
Hi,

I've encountered the same error:

Database Error Code: Deadlock found when trying to get lock; try restarting transaction, 1213
REPLACE INTO civicrm_group_contact_cache (group_id,contact_id) VALUES ...

on two different sites on two different servers, running 4.0.7 and 4.0.8, using Advanced Search with the following criteria:

Activity Status - 'Completed' ...AND...
Added Date - greater than or equal to "February 1st, 2012 12:00 AM" ...AND...
Contacts IN MyGroup AND Group Status - "Added"

Oddly though, where the error appears is after clicking on "Edit Search Criteria", inside either the "Change Log" or "Activities" sections of the search criteria.

In both cases, the group is a normal static group. In one case the group has a child group, in the other case it doesn't.

I wasn't able to replicate on demo. I suspect the error only occurs when there are a lot of contacts and demo only has 102, of which only 1 had a change log entry. The sites I tested have 14000 / 61000 contacts and the searches I tried return 600 / 6000 results.

The problem appears to be related to the performance of the db server: I tried the bigger site on a dev server with 8G RAM and a solid-state drive for dbs and didn't get the error there.

Dave J

Eileen

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4195
  • Karma: 218
    • Fuzion
Re: Database deadlock
March 28, 2012, 02:03:56 pm
Where I have seen this the problem is that it is dealing with a hierarchical group

e.g parent group is "NSW State"
child group is "All pedestrians in NSW state"

People use the parent group as criteria in the child group - to narrow it down - but when the cache is rebuilt it has to define the parent to define the child to define the parent to define the child.

I think a good enhancement would be to allow child groups to restrict parent groups.

DaveJ - this problem is especially prevalent in multisites
Make today the day you step up to support CiviCRM and all the amazing organisations that are using it to improve our world - http://civicrm.org/contribute

davej

  • Ask me questions
  • ****
  • Posts: 404
  • Karma: 21
Re: Database deadlock
April 03, 2012, 08:00:37 am
Hi Eileen,

I've just posted about the issue of a child smart group referring to the parent group in its search criteria, in the developer forum: http://forum.civicrm.org/index.php/topic,24128.0.html .

The symptom we were getting there was searches on the parent group spinning until they hit max execution time or memory limit, with civicrm_group_contact_cache being constantly populated & cleared for the parent group. I found that de-parenting the smart group got rid of that problem.

However it did not stop the problem I described in my post above: deadlock error on civicrm_group_contact_cache, appearing under "Edit Search Criteria". And as I said, that error is occurring on two different sites and in one case (not a multi-org), the group we're searching on doesn't have a parent or children. So there seem to be two different issues going on.

Dave J

Eileen

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4195
  • Karma: 218
    • Fuzion
Re: Database deadlock
April 03, 2012, 08:37:41 am
Dave - can you describe the criteria of the groups in question?

BTW - am at the sprint starting tomorrow so hope to pick people's brains :-)
Make today the day you step up to support CiviCRM and all the amazing organisations that are using it to improve our world - http://civicrm.org/contribute

davej

  • Ask me questions
  • ****
  • Posts: 404
  • Karma: 21
Re: Database deadlock
April 03, 2012, 09:02:04 am
Hi Eileen,

For the deadlock-error-in-Edit-Search-Criteria issue, the search was as described above:

Quote from: davej on March 28, 2012, 08:24:57 am
...Advanced Search with the following criteria:

Activity Status - 'Completed' ...AND...
Added Date - greater than or equal to "February 1st, 2012 12:00 AM" ...AND...
Contacts IN MyGroup AND Group Status - "Added"

Oddly though, where the error appears is after clicking on "Edit Search Criteria", inside either the "Change Log" or "Activities" sections of the search criteria.

In both cases, the group is a normal static group. In one case the group has a child group, in the other case it doesn't.

Have fun at the sprint! If you feel like drawing attention to my post on the dev forum too (Smart groups, parent groups and bottomless recursion), that might be handy.

Thanks,

Dave J

davej

  • Ask me questions
  • ****
  • Posts: 404
  • Karma: 21
Re: Database deadlock
April 26, 2012, 05:10:37 am
Quote from: davej on April 03, 2012, 09:02:04 am
For the deadlock-error-in-Edit-Search-Criteria issue...

I've made progress with this. It was occurring on a 4.0.8 site and I was going to try a patch of Tim Otten's for CRM/Contact/BAO/GroupContactCache.php but found that there had been other changes to that file between 4.0.8 and the base version of Tim's patch. One of these was changeset 38384 for CRM-9493 . I tried applying that change first and it fixed the problem - well, I saw the problem once in tens of trials with the patch, compared to seeing it nearly every time without.

I tested each of the two parts of the patch separately, to see which was making a difference. I found that this was the one:

+        // sort the values so we put group IDs in front and hence optimize
+        // mysql storage (or so we think) CRM-9493
+        sort( $values );

Thinking of further optimisation, I was wondering whether the pattern currently used:

DELETE g
FROM civicrm_group_contact_cache g
WHERE g.group_id IN ( '7' )

then

INSERT IGNORE INTO civicrm_group_contact_cache (group_id,contact_id) <thousands of values>

is maybe a bit wasteful, given that writes are expensive. Wondered whether it might be possible to insert/delete only the values that differ between what's already there and what we want. That could involve holding more stuff in memory, though.

Cheers,

Dave J

Pages: [1]
  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Support »
  • Using CiviCRM »
  • Using Core CiviCRM Functions (Moderator: Yashodha Chaku) »
  • Database deadlock

This forum was archived on 2017-11-26.