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 (Moderator: Dave Greenberg) »
  • MySQL slave stop on inserts into civicrm_uf_match
Pages: [1]

Author Topic: MySQL slave stop on inserts into civicrm_uf_match  (Read 5401 times)

jlam

  • I’m new here
  • *
  • Posts: 8
  • Karma: 0
MySQL slave stop on inserts into civicrm_uf_match
September 14, 2008, 12:58:03 pm
Twice now I've had a mysql slave stops because of duplicate key errors.  The tables involved are:

main_crm_db.civicrm_uf_match
main_cms_db.users
main_cms_db.users_roles

where main_crm_db is the CiviCRM db and main_cms_db is the Drupal database.

Specifically, the errors are:

      Last_Error: Error 'Duplicate entry '11233' for key 1' on query. Default database: 'main_crm_db'. Query: 'INSERT INTO civicrm_uf_match(uf_id,contact_id,domain_id,email) values(xxx)'

...which I then try to correct manually, only to have....

                 Last_Error: Error 'Duplicate entry '10928' for key 1' on query. Default database: 'main_cms_db'. Query: 'INSERT INTO users(uid,name,pass,mail,created,status,language) values(xxx)'

...which I then try to correct manually, only to have....

                 Last_Error: Error 'Duplicate entry '10928-9' for key 1' on query. Default database: 'main_cms_db'. Query: 'INSERT INTO users_roles(uid,rid) values(xxx)'

...which I then try to correct manually.  After this cycle, another cycle starts, involving similar statements and the same tables in the same order.


I thought it might be this, because civicrm_uf_match is InnoDB and users and users_roles is MyISAM:
"Replication and CASCADE.   Cascading actions for InnoDB tables on the master are replicated to the slave only  if both the master's and slave' versions of the tables sharing the foreign key relation use InnoDB. For example, suppose you have started replication, and then create two tables on the master using the following CREATE TABLE  statements:"
-- http://dev.mysql.com/doc/refman/5.0/en/innodb-and-mysql-replication.html

But I'm not seing a chain of foreign keys between the 3:

mysql> select CONSTRAINT_NAME, TABLE_SCHEMA, TABLE_NAME, REFERENCED_TABLE_NAME from KEY_COLUMN_USAGE where table_name in ('civicrm_uf_match', 'users', 'users_roles') or REFERENCED_TABLE_NAME in ('civicrm_uf_match', 'users', 'users_roles') ;

+-------------------------+--------------+------------------+-----------------------+
| CONSTRAINT_NAME         | TABLE_SCHEMA | TABLE_NAME       | REFERENCED_TABLE_NAME |
+-------------------------+--------------+------------------+-----------------------+
| PRIMARY                 | main_cms_db  | users            | NULL                  |
| name                    | main_cms_db  | users            | NULL                  |
| PRIMARY                 | main_cms_db  | users_roles      | NULL                  |
| PRIMARY                 | main_cms_db  | users_roles      | NULL                  |
| PRIMARY                 | main_crm_db  | civicrm_uf_match | NULL                  |
| UI_contact              | main_crm_db  | civicrm_uf_match | NULL                  |
| UI_uf_domain_id         | main_crm_db  | civicrm_uf_match | NULL                  |
| UI_uf_domain_id         | main_crm_db  | civicrm_uf_match | NULL                  |
| civicrm_uf_match_ibfk_1 | main_crm_db  | civicrm_uf_match | civicrm_contact       |
| civicrm_uf_match_ibfk_2 | main_crm_db  | civicrm_uf_match | civicrm_domain        |
+-------------------------+--------------+------------------+-----------------------+

« Last Edit: September 14, 2008, 01:00:56 pm by jlam »

jlam

  • I’m new here
  • *
  • Posts: 8
  • Karma: 0
Re: MySQL slave stop on inserts into civicrm_uf_match
September 14, 2008, 01:09:45 pm
Both slave stop occurred at the same time, so I suspect its a query ran by daily_crm_cron.php that, for some reason, causes mysql replication to stop.

Dave Greenberg

  • Administrator
  • I’m (like) Lobo ;)
  • *****
  • Posts: 5760
  • Karma: 226
    • My CiviCRM Blog
Re: MySQL slave stop on inserts into civicrm_uf_match
September 15, 2008, 10:04:00 am
I don't have experience with MySQL replication - so others may have better insight here. However, it migth help us understand why the query is failing if you provide the "values" that it's trying to insert.

Also, I'm not aware of any PHP script that is part of the CiviCRM distribution which would attempt to insert records to the civicrm_uf_match table. Are you running custom PHP scripts via cron?

NOTE: The civicrm_uf_match table is a join table between your CMS user table ('users' in Drupal) and the CiviCRM contact table (civicrm_contact). The uf_id is an implicit foreign key to users.uid. It does look like the queries are trying to insert a record for a user that already exists in those tables - but not sure why.
Protect your investment in CiviCRM by  becoming a Member!

jlam

  • I’m new here
  • *
  • Posts: 8
  • Karma: 0
Re: MySQL slave stop on inserts into civicrm_uf_match
September 15, 2008, 10:13:38 am
The values I'm trying to insert are (with private client information removed):

      Last_Error: Error 'Duplicate entry '11233' for key 1' on query. Default database: 'main_crm_db'. Query: 'INSERT INTO civicrm_uf_match(uf_id,contact_id,domain_id,email) values('10928','73478','1','xxx')'

                 Last_Error: Error 'Duplicate entry '10928' for key 1' on query. Default database: 'main_cms_db'. Query: 'INSERT INTO users(uid,name,pass,mail,created,status,language) values('10928','xxx','837b5364536acaad37014a47fe3a3d19','xxx','1221375659','1','en')'


                 Last_Error: Error 'Duplicate entry '10928-9' for key 1' on query. Default database: 'main_cms_db'. Query: 'INSERT INTO users_roles(uid,rid) values('10928','9')'

Dave Greenberg

  • Administrator
  • I’m (like) Lobo ;)
  • *****
  • Posts: 5760
  • Karma: 226
    • My CiviCRM Blog
Re: MySQL slave stop on inserts into civicrm_uf_match
September 15, 2008, 11:19:40 am
It's clear that the replication is trying to insert records which already exist in the slave copy (for user 10928). However, I don't know why this is happening. Since this seems more like a general replication issue - your best bet might be to consult with someone who is knowledgeable about replication issues.
Protect your investment in CiviCRM by  becoming a Member!

jlam

  • I’m new here
  • *
  • Posts: 8
  • Karma: 0
Re: MySQL slave stop on inserts into civicrm_uf_match
September 15, 2008, 02:23:58 pm
Saw the error today on production (rather than the slave) when a user tried to change his password:

Code: [Select]
unrecoverable error
    Sorry. A non-recoverable error has occurred.

    Database Error Code: Duplicate entry '34230' for key 2, 1062

    Return to home page.

Error Details:
Array
(
    [callback] => Array
        (
            [0] => CRM_Core_Error
            [1] => handle
        )

    [code] => -5
    [message] => DB Error: already exists
    [mode] => 16
    [debug_info] => INSERT INTO civicrm_uf_match (uf_id , contact_id , domain_id , email ) VALUES ( 848 ,  34230 ,  1 , 'xxx' )  [nativecode=1062 ** Duplicate entry '34230' for key 2]
    [type] => DB_Error
    [user_info] => INSERT INTO civicrm_uf_match (uf_id , contact_id , domain_id , email ) VALUES ( 848 ,  34230 ,  1 , 'xxx' )  [nativecode=1062 ** Duplicate entry '34230' for key 2]
    [to_string] => [db_error: message="DB Error: already exists" code=-5 mode=callback callback=CRM_Core_Error::handle prefix="" info="INSERT INTO civicrm_uf_match (uf_id , contact_id , domain_id , email ) VALUES ( 848 ,  34230 ,  1 , 'xxx' )  [nativecode=1062 ** Duplicate entry '34230' for key 2]"]
)



### There are reports of this error elsewhere:
http://fossplanet.com/crm.civicrm.devel/message-824581-different/
http://issues.civicrm.org/jira/browse/CRM-1816
http://drupal.org/node/186693
http://osdir.com/ml/crm.civicrm.devel/2007-01/msg00613.html


### I'll report back once I've found out more.   I've asked a dev to look at the solution proposed at http://fossplanet.com/crm.civicrm.devel/message-824581-different/[/code]

ryanpitt

  • I post occasionally
  • **
  • Posts: 42
  • Karma: 0
Re: MySQL slave stop on inserts into civicrm_uf_match
July 29, 2009, 07:46:13 am
I Just wanted to follow up on this as there seemed to be no clear resolution here.
I got the same error and not quite sure what caused it.
To resolve the issue, I simply went into the table civicrm_uf_match and deleted the entry that the system was complaining about. The user then logged in and a new record for that user was created in the table with the correct links.
Hope this helps someone else out.
Sincerely,
Ryan

Pages: [1]
  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Support »
  • Using CiviCRM (Moderator: Dave Greenberg) »
  • MySQL slave stop on inserts into civicrm_uf_match

This forum was archived on 2017-11-26.