Page MenuHomePhabricator

Duplicate contributions after import
Closed, ResolvedPublic

Description

@Elbar53 noticed that after last week's Engage Individual import of 9/18 gifts there were some duplicates in Civi. We haven't removed them from Civi yet and they are noted below (only 3 total):

Batch 19611
- CID 64300817
- CID 40947961
Batch 30385
- CID 27970542

Wondering if this is because our files are getting larger? I noticed it can take a while for them to process on their own and usually I get an error that tells me a gift is a duplicate contribution, but somehow these went through. Let me know what you think and we will continue to keep an eye on it!

Event Timeline

So on the first CID we have

Contribution IDinsert timecontact IDlog connectionImport Jobimport job table
1119945862024-09-25 21:08:356430081766f47acd79d9bKpRK
1119946112024-09-25 21:10:236430081766f47b42f2d1enBGO1597civicrm_tmp_d_dflt_601869e4d110fc4a309dd7b7ce25f908
1119949472024-09-25 21:20:564094796166f47acd79d9bKpRK
1119949482024-09-25 21:22:294094796166f47ea664fa8KUZf1597civicrm_tmp_d_dflt_601869e4d110fc4a309dd7b7ce25f908
1119945062024-09-25 21:06:132797054266f47acd79d9bKpRK
1119945852024-09-25 21:08:172797054266f47b42f2d1enBGO1597civicrm_tmp_d_dflt_601869e4d110fc4a309dd7b7ce25f908

I did find some sign of deadlock but not on these

2024-09-25 20:54:28+0000 [info] Retrying after Database lock encountered hit on attempt 1 at query : INSERT INTO `civicrm_
contribution` (contact_id , financial_type_id , payment_instrument_id , receive_date , total_amount , `fee_amount
, net_amount` , currency , thankyou_date , source , contribution_status_id , check_number , tax_amount ) VAL
UES ( 3281034 , 9 , 4 , 20240918000000 , 600.00 , 0 , 600 , 'USD' , 20240925000000 , 'USD 600.00' , 1 , '4409193' ,

0 )

2024-09-25 20:54:32+0000 [info] Retrying after Database deadlock encountered hit on attempt 1 at query : INSERT INTO wmf_c
ontribution_extra ( gateway,gateway_txn_id,postmark_date,original_currency,original_amount,entity_id ) VALUES
( 'Engage','b5468d4146b8b0277c9a22535c11c638',20240806000000,'USD','2000.00',111994143 )

[2024-09-25T21:04:13.847199+00:00] civicrm.DEBUG: Running task: Snooze contact [] []
[2024-09-25T21:04:13.917558+00:00] civicrm.DEBUG: Running task: Processed 100 rows out of 292 [] []
2024-09-25 21:11:06+0000 [info] Retrying after Database deadlock encountered hit on attempt 1 at query : INSERT INTO wmf_c
ontribution_extra ( gateway,gateway_txn_id,postmark_date,original_currency,original_amount,entity_id ) VALUES
( 'Engage','37960ddfd52f887f1f06ee964d7c0730',20240907000000,'USD','100.00',111994628 )

looking at the 3rd one - it is the last of 89 in the set done under the connection - which suggests it crashed

select id,log_date FROM log_civicrm_contribution WHERE log_conn_id = '66f47acd79d9bKpRK';
+-----------+---------------------+

idlog_date

+-----------+---------------------+

1119944512024-09-25 21:04:24
1119944522024-09-25 21:04:24
1119944532024-09-25 21:04:25
1119944542024-09-25 21:04:25
1119944552024-09-25 21:04:26
1119944562024-09-25 21:04:28
1119945062024-09-25 21:06:13
1119945072024-09-25 21:06:14
1119945082024-09-25 21:06:14
1119945092024-09-25 21:06:14
1119945102024-09-25 21:06:15
1119945112024-09-25 21:06:15
1119945122024-09-25 21:06:15
1119945132024-09-25 21:06:16
1119945142024-09-25 21:06:16
1119945152024-09-25 21:06:17
1119945162024-09-25 21:06:18
1119945172024-09-25 21:06:23
1119945862024-09-25 21:08:35
1119945872024-09-25 21:08:37
1119945882024-09-25 21:08:39
1119945892024-09-25 21:08:42
1119945902024-09-25 21:08:44
1119945912024-09-25 21:08:45
1119945922024-09-25 21:08:45
1119945932024-09-25 21:08:47
1119945942024-09-25 21:08:47
1119945952024-09-25 21:08:53
1119945962024-09-25 21:08:53
1119945972024-09-25 21:08:53
1119945982024-09-25 21:08:54
1119945992024-09-25 21:08:54
1119946002024-09-25 21:08:54
1119946012024-09-25 21:08:55
1119946022024-09-25 21:08:55
1119946032024-09-25 21:08:55
1119946042024-09-25 21:08:56
1119946052024-09-25 21:09:01
1119946062024-09-25 21:09:02
1119946072024-09-25 21:09:03
1119946082024-09-25 21:09:03
1119946092024-09-25 21:09:04
1119946102024-09-25 21:09:06
1119946292024-09-25 21:11:06
1119946542024-09-25 21:11:12
1119946582024-09-25 21:11:12
1119946602024-09-25 21:11:12
1119946622024-09-25 21:11:13
1119946732024-09-25 21:11:15
1119946762024-09-25 21:11:16
1119946912024-09-25 21:11:19
1119946952024-09-25 21:11:20
1119946962024-09-25 21:11:21
1119946972024-09-25 21:13:02
1119946982024-09-25 21:13:04
1119946992024-09-25 21:13:04
1119947002024-09-25 21:13:04
1119947642024-09-25 21:14:48
1119947652024-09-25 21:14:49
1119947662024-09-25 21:14:49
1119947672024-09-25 21:14:50
1119947682024-09-25 21:14:50
1119947692024-09-25 21:14:50
1119947702024-09-25 21:14:55
1119947712024-09-25 21:14:56
1119947722024-09-25 21:15:01
1119947732024-09-25 21:15:02
1119947742024-09-25 21:15:02
1119947752024-09-25 21:15:03
1119947762024-09-25 21:15:08
1119947782024-09-25 21:17:02
1119947852024-09-25 21:17:03
1119947872024-09-25 21:17:04
1119947892024-09-25 21:17:04
1119947922024-09-25 21:17:04
1119947992024-09-25 21:17:06
1119948012024-09-25 21:17:06
1119948102024-09-25 21:17:08
1119948152024-09-25 21:17:09
1119948172024-09-25 21:17:09
1119948212024-09-25 21:17:10
1119948672024-09-25 21:18:56
1119948682024-09-25 21:18:59
1119948692024-09-25 21:19:00
1119948702024-09-25 21:19:00
1119948712024-09-25 21:19:00
1119948722024-09-25 21:19:01
1119948732024-09-25 21:19:05
1119949472024-09-25 21:20:56

+-----------+---------------------+
89 rows in set (0.002 sec)

select id, log_date FROM log_civicrm_contribution WHERE log_conn_id = '66f47b42f2d1enBGO';

idlog_date
1119945852024-09-25 21:08:17
1119946112024-09-25 21:10:23

select id,log_date FROM log_civicrm_contribution WHERE log_conn_id = '66f47ea664fa8KUZf';

idlog_date
1119949482024-09-25 21:22:29

@MDemosWMF I did some digging - I can't really conclude more than - 'let's monitor it' - I can see that a bit about what process created the contributions and I can see they were created in a process of 89 rows that finished at 2024-09-25 21:20:56 but the other processes that ALSO processed the rows started before that one finished.

I wonder if there is a possible race condition whereby one job starts while the last is still running and grabs the 'next 50 rows' but the original job is in the process of doing a row. Maybe at the start of processing a row if could be updated to 'in progress'

I've done some more pondering about this and the reason this does not happen all the time is the Queue.claimItem action should ensure the import task is only available to one process at a time. At this point it would appear the item was not correctly claimed - however, that currently has happened on one process - so I guess the question is whether it will happen again. If so there are 2 sides to this

  1. can we figure out why claimItem did not work? Perhaps the siteBusy check was slow & that allows 2 jobs to grab the item at once?
  2. we could probably harden the import code to cope if it doesn't - this would allow us to run imports in paralell but I suspect that would lead to more deadlocks.
Eileenmcnaughton lowered the priority of this task from High to Medium.Oct 1 2024, 3:06 AM

I've triage the task back down to medium since I think monitoring is the best course of action for now - if it happens again bump back to high

Possibly connected to this is that it takes a long time for the files to process so we sometimes open the list of donations and select them to push through to import a page at a time. Would be great to increase the speed of the import like it was on the drupal platform! Can we look into that?

For now Ellen and I will not push through the import and just let it run in the background to avoid this. We will monitor, but I think the speed of the import would be great to look into and see if it's possible for it to process a bit quicker especially when volume is high during busy season.

@MDemosWMF we can look at whether there are are any bottlenecks in the code we can improve (maybe add a phab) - but I suspect the slow down is that we have set the import to pause when the server is under high load to reduce deadlocks both within the import and in our queue processing. If the drupal imports are faster under load it's probably because they are slowing down the main queue to achieve that

Thanks Eileen - I opened a new phab for that - T376337. I think it's worth taking a look and we will try to monitor speeds as best we can on our end!

@MDemosWMF I just pushed out a patch that will add create new contacts and add them to group Duplicate from csv imports https://civicrm.wikimedia.org/civicrm/group/search?force=1&context=smog&gid=2244&component_mode=1 rather than bouncing.

This is across all imports & is actually a hack rather than a fix because I wanted something in place before you head away - so I'm going to create a follow on phab for that

@Eileenmcnaughton Wanted to update you that we ran the Engage imports today after your patch went out and there were no duplicate errors! Looks like some records have gone into the group you created as intended. There was only 1 DB deadlock that was easily reimported. Here are @Elbar53 's notes:

Wiki Organization - imported instantly and no errors
Wiki Individual (193 items) - import took 35 min and 1 error. Error was deadlock so it imported instantly
Endowment individual - import took 20 min and no errors

Things have definitely improved! Thank you!

@MDemosWMF you will work with @SHust on managing that group?

Those individual ones do seem slow

@SHust @krobinson Let me know if this works for your team! The idea is that dupes will funnel into this group after import and can be worked on by DR.

@Eileenmcnaughton I thought so too - and likely will get slower with higher volumes in the files.

@MDemosWMF the admin team can support this group dedupe, how often do imports happen?

@SHust Amazing! Thank you DR admin team. There are various weekly imports happening throughout the week based on when data entry is complete.

XenoRyet set Final Story Points to 4.