Details
-
Type:
Improvement
-
Status: In Progress
-
Priority:
Major
-
Resolution: Unresolved
-
Affects Version/s: 4.7.11
-
Fix Version/s: Unscheduled
-
Component/s: Core CiviCRM
-
Labels:
-
Versioning Impact:Patch (backwards-compatible bug fixes)
-
Documentation Required?:None
-
Funding Source:Paid Issue Queue
Description
After some digging into cache table deadlocks I have concluded that REMOVING the auto increment field may improve the frequency of deadlocks. The issue is that when it goes to INSERT into a table it locks the number of ids it will need for the insert. If the query is at all slow then it takes time to calculate this lock.
So, 2 separate processes cannot insert to the same table at the same time because it has to finish one to calculate the next auto-increment.
However, the id field adds no value to these cache tables:
civicrm_group_contact_cache
civicrm_acl_contact_cache
civicrm_cache
With some hesitation I would also add to that list
civicrm_prevnext_cache
I had a go at removing the id from civicrm_group_contact_cache and I will add a PR for the changes I had to make to get past any errors. So far it seems to have led to a reduction in auto-inc errors
I'm also playing with adjusting the indexes on group_contact_cache to
UNIQUE INDEX `UI_contact_group` (`group_id`, `contact_id`),
INDEX `index_contact` (`contact_id`)
The logic being the gap lock will lock less rows for the unique index with group first since it is usually only a single group, but a wide range of contacts
See this one for more on gap locks & also for my next approach
{{SET TRANSACTION ISOLATION LEVEL READ COMMITTED;
session2> BEGIN;
session2> INSERT INTO actor (first_name,last_name) VALUES ('Bob','Davis');Query OK, 1 row affected (0.02 sec)
session1> COMMIT}};
http://blog.9minutesnooze.com/diagnosing-mysql-autoinc-gap-locks-ideeli-tech-blog/
Attachments
Issue Links
- links to
OK - just a diff at the moment...
diff --git a/sites/all/modules/civicrm/CRM/Contact/BAO/Group.php b/sites/all/modules/civicrm/CRM/Contact/BAO/Group.php
index caf8147..b007755 100644
— a/sites/all/modules/civicrm/CRM/Contact/BAO/Group.php
+++ b/sites/all/modules/civicrm/CRM/Contact/BAO/Group.php
@@ -993,7 +993,7 @@ class CRM_Contact_BAO_Group extends CRM_Contact_DAO_Group {
}
// Exclude deleted contacts
$where .= " and c.id = g.contact_id AND c.is_deleted = 0";
+ $dao = CRM_Core_DAO::executeQuery("SELECT g.group_id, COUNT
while ($dao->fetch()) { $values[$dao->group_id]['count'] = $dao->count; }
diff --git a/sites/all/modules/civicrm/CRM/Group/Page/Group.php b/sites/all/modules/civicrm/CRM/Group/Page/Group.php
index d0f6efd..036f8ea 100644
+++ b/sites/all/modules/civicrm/CRM/Group/Page/Group.php
@@ -143,7 +143,7 @@ class CRM_Group_Page_Group extends CRM_Core_Page_Basic {
if (!empty($_GET['update_smart_groups'])) { CRM_Contact_BAO_GroupContactCache::loadAll(); }
+ elseif (!CRM_Core_DAO::singleValueQuery("SELECT contact_id FROM civicrm_group_contact_cache LIMIT 1")) { CRM_Core_Session::setStatus(ts('Count data for smart groups is not currently calculated. You may click Update Smart Groups to generate it. Be aware this can cau }