Duplicate key entry in cache
For the user, the problem occurred when he has tried to send a test email and I was able to reproduce when opening an draft mass emailing (non-mosaico).
I've noticed in the log of several of our sites a few instances of this problem over the years and was able to see it in the database.
First the log :
[debug_info] => UPDATE civicrm_cache SET data = '...', created_date = FROM_UNIXTIME(1582213285), expired_date = FROM_UNIXTIME(1582234886) WHERE group_name = "contact-20fields" AND path = "custom importableFields 95d8b67bffebbc8912554acdd22d0310"
[nativecode=1062 ** Duplicate entry 'contact-20fields-custom importableFields 95d8b67bffebbc8912554ac' for key 'UI_group_path_date']
In the civicrm_cache table, there are indeed 2 entries that correspond and that are updated at the same time - hence the duplicate key entry :
select id, created_date from civicrm_cache where group_name = "contact-20fields" AND path = "custom importableFields 95d8b67bffebbc8912554acdd22d0310";
+-------+---------------------+
| id | created_date |
+-------+---------------------+
| 79704 | 2020-02-20 04:29:51 |
| 79709 | 2020-02-20 04:29:52 |
+-------+---------------------+
2 rows in set (0.001 sec)
The problem seems to have resolved itself after some auto-cleanup of the cache (the duplicate entries were in the database for 7 hours)
I suppose we could solve this by one of the following :
- if we don't have the created_date, do not update based on group_name + path alone, delete + insert instead
- forbid creation of 2 entries with the same group_name + path (but i'm pretty sure there a good reason for allowing that so probably not a good idea)
Anyway, it seems to be a rare case and really not sure if the solution above would create more problem that it resolves.
I don't plan to work on this. Feel free to close if the priority is too low in comparison to the complexity to solve it.