putyourlightson / craft-blitz

Intelligent static page caching for creating lightning-fast sites with Craft CMS.
https://putyourlightson.com/plugins/blitz
Other
150 stars 36 forks source link

Integrity constraint violation #133

Closed michaelhue closed 5 years ago

michaelhue commented 5 years ago

I get repeated integrity constraint violation errors on my Blitz powered site.

Here is an example:

SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry '2373395357' for key 'blitz_elementqueries_index_unq_idx' The SQL being executed was: INSERT INTO blitz_elementqueries (index, type, params) VALUES (2373395357, 'craft\elements\Asset', '{\"id\":50006,\"status\":null,\"siteId\":\"5\",\"enabledForSite\":false,\"limit\":1}')

I followed the advice in #84, re-installed the plugin and checked the indexes. But that didn't help. Any ideas?

Full stack trace:

PDOException: SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry '2373395357' for key 'blitz_elementqueries_index_unq_idx'
#74 vendor/yiisoft/yii2/db/Command.php(1290): execute
#73 vendor/yiisoft/yii2/db/Command.php(1290): internalExecute
#72 vendor/yiisoft/yii2/db/Command.php(1091): execute
#71 vendor/putyourlightson/craft-blitz/src/services/GenerateCacheService.php(150): addElementQuery
#70 vendor/putyourlightson/craft-blitz/src/Blitz.php(212): putyourlightson\blitz\{closure}
#69 vendor/putyourlightson/craft-blitz/src/Blitz.php(0): call_user_func
#68 vendor/yiisoft/yii2/base/Event.php(312): trigger
#67 vendor/yiisoft/yii2/base/Component.php(636): trigger
#66 vendor/craftcms/cms/src/elements/db/ElementQuery.php(1889): beforePrepare
#65 vendor/craftcms/cms/src/elements/db/AssetQuery.php(800): beforePrepare
#64 vendor/craftcms/cms/src/elements/db/ElementQuery.php(1327): prepare
#63 vendor/yiisoft/yii2/db/QueryBuilder.php(227): build
#62 vendor/yiisoft/yii2/db/Query.php(146): createCommand
#61 vendor/yiisoft/yii2/db/Query.php(274): one
#60 vendor/craftcms/cms/src/db/Query.php(177): one
#59 vendor/craftcms/cms/src/elements/db/ElementQuery.php(1502): one
#58 vendor/craftcms/cms/src/services/Elements.php(291): getElementById
#57 vendor/craftcms/cms/src/services/Assets.php(116): getAssetById
#56 vendor/craftcms/cms/src/services/AssetTransforms.php(655): _generateTransform
#55 vendor/craftcms/cms/src/services/AssetTransforms.php(611): ensureTransformUrlByIndexModel
#54 vendor/craftcms/cms/src/services/Assets.php(598): getAssetUrl
#53 vendor/craftcms/cms/src/elements/Asset.php(793): getUrl
#52 modules/tabmag/variables/TabmagVariable.php(65): tabmag\variables\{closure}
#51 modules/tabmag/variables/TabmagVariable.php(0): array_map
#50 modules/tabmag/variables/TabmagVariable.php(64): getResponsiveImage
#49 vendor/twig/twig/src/Extension/CoreExtension.php(1495): twig_get_attribute
#48 vendor/craftcms/cms/src/helpers/Template.php(105): attribute
#47 storage/runtime/compiled_templates/44/4448bd0682a134695d466dbf465d46edd60b0ab8bc2d85aa99f09f23c939a8ab.php(51): doDisplay
#46 vendor/twig/twig/src/Template.php(407): displayWithErrorHandling
#45 vendor/twig/twig/src/Template.php(380): display
#44 vendor/twig/twig/src/Template.php(392): render
#43 vendor/twig/twig/src/Extension/CoreExtension.php(1219): twig_include
#42 storage/runtime/compiled_templates/dc/dc73d2b83953e72a66522ea91da8871f26d7b2281dccbc9b625deac1003d3ba4.php(128): macro_render_block
#41 vendor/twig/twig/src/Extension/CoreExtension.php(1105): twig_call_macro
#40 storage/runtime/compiled_templates/dc/dc73d2b83953e72a66522ea91da8871f26d7b2281dccbc9b625deac1003d3ba4.php(178): macro_render_blocks
#39 vendor/twig/twig/src/Extension/CoreExtension.php(1105): twig_call_macro
#38 storage/runtime/compiled_templates/43/439ccd64f155b8d05adaaf240a85a276510c034e8fb187519e0304433fc98dbc.php(77): doDisplay
#37 vendor/twig/twig/src/Template.php(407): displayWithErrorHandling
#36 vendor/twig/twig/src/Template.php(380): display
#35 vendor/twig/twig/src/Template.php(392): render
#34 vendor/twig/twig/src/Extension/CoreExtension.php(1219): twig_include
#33 storage/runtime/compiled_templates/dc/dc73d2b83953e72a66522ea91da8871f26d7b2281dccbc9b625deac1003d3ba4.php(128): macro_render_block
#32 vendor/twig/twig/src/Extension/CoreExtension.php(1105): twig_call_macro
#31 storage/runtime/compiled_templates/dc/dc73d2b83953e72a66522ea91da8871f26d7b2281dccbc9b625deac1003d3ba4.php(218): macro_render_root_blocks
#30 vendor/twig/twig/src/Extension/CoreExtension.php(1105): twig_call_macro
#29 storage/runtime/compiled_templates/1e/1e79ab4ad0a7e84559236cd7326d84254d0922819851e9bf04f95f437c622aaa.php(93): block_main
#28 vendor/twig/twig/src/Template.php(184): displayBlock
#27 storage/runtime/compiled_templates/00/0021d30615a24c232604b355f2afbe6bb0885856eb324f701c0de7bfc5fa6041.php(111): doDisplay
#26 vendor/twig/twig/src/Template.php(407): displayWithErrorHandling
#25 vendor/twig/twig/src/Template.php(380): display
#24 storage/runtime/compiled_templates/1e/1e79ab4ad0a7e84559236cd7326d84254d0922819851e9bf04f95f437c622aaa.php(72): doDisplay
#23 vendor/twig/twig/src/Template.php(407): displayWithErrorHandling
#22 vendor/twig/twig/src/Template.php(380): display
#21 vendor/twig/twig/src/Template.php(392): render
#20 vendor/twig/twig/src/Extension/CoreExtension.php(1219): twig_include
#19 storage/runtime/compiled_templates/f4/f41b791fe6f28a223391b793bd9ecadca0732814406f918ac4e3eff0d72988f3.php(40): doDisplay
#18 vendor/twig/twig/src/Template.php(407): displayWithErrorHandling
#17 vendor/twig/twig/src/Template.php(380): display
#16 vendor/twig/twig/src/Template.php(392): render
#15 vendor/twig/twig/src/TemplateWrapper.php(45): render
#14 vendor/twig/twig/src/Environment.php(318): render
#13 vendor/craftcms/cms/src/web/View.php(344): renderTemplate
#12 vendor/craftcms/cms/src/web/View.php(393): renderPageTemplate
#11 vendor/craftcms/cms/src/web/Controller.php(243): renderTemplate
#10 vendor/craftcms/cms/src/controllers/TemplatesController.php(101): actionRender
#9 vendor/craftcms/cms/src/controllers/TemplatesController.php(0): call_user_func_array
#8 vendor/yiisoft/yii2/base/InlineAction.php(57): runWithParams
#7 vendor/yiisoft/yii2/base/Controller.php(157): runAction
#6 vendor/craftcms/cms/src/web/Controller.php(187): runAction
#5 vendor/yiisoft/yii2/base/Module.php(528): runAction
#4 vendor/craftcms/cms/src/web/Application.php(299): runAction
#3 vendor/yiisoft/yii2/web/Application.php(103): handleRequest
#2 vendor/craftcms/cms/src/web/Application.php(284): handleRequest
#1 vendor/yiisoft/yii2/base/Application.php(386): run
#0 index.php(24): null
putyourlightson commented 5 years ago

What version of Blitz are you running? And is this happening during cache warming or simply when visiting the site?

michaelhue commented 5 years ago

I'm on the latest v2.3.2 but did have issues with earlier versions as well. There is no automated cache warming on my site, seems to happen when visitors access entry pages.

michaelhue commented 5 years ago

Here is another error:

SQLSTATE[23000]: Integrity constraint violation: 1452 Cannot add or update a child row: a foreign key constraint fails (tabmag2.blitz_elementcaches, CONSTRAINT blitz_elementcaches_cacheId_fk FOREIGN KEY (cacheId) REFERENCES blitz_caches (id) ON DELETE CASCADE ON UPDATE CASCADE) The SQL being executed was: INSERT INTO blitz_elementcaches (cacheId, elementId) VALUES (27, 24180), (27, 1339), (27, 22657), (27, 26301), (27, 22652), (27, 83147), (27, 45702), (27, 24408), (27, 24976), (27, 24977), (27, 6274), (27, 1359), (27, 1357), (27, 135333), (27, 14799), (27, 20128), (27, 32639), (27, 6857), (27, 28969), (27, 36945), (27, 36996), (27, 37672), (27, 40057), (27, 41905), (27, 41982), (27, 133947), (27, 42410), (27, 49946), (27, 89636), (27, 124865), (27, 43973), (27, 19648), (27, 42298), (27, 14849), (27, 22653), (27, 25388), (27, 28933), (27, 36086), (27, 37000), (27, 37649), (27, 39809), (27, 41660), (27, 41930), (27, 43974), (27, 64754), (27, 1366)

I'm using Sentry for error tracking, so I have good data for every error event. Let me know if you need more info.

putyourlightson commented 5 years ago

If you are on discord then would you mind chatting me (BenCroker) and we can troubleshoot together? There are mutex locks in place to avoid integrity constraint violations so I'm not sure why this might be happening.

michaelhue commented 5 years ago

Sure thing, I just need your four-digit tag to add you on Discord. I'm happyentropy#2066.

putyourlightson commented 5 years ago

You'll find me in the Craft channel :) BenCroker#7494

putyourlightson commented 5 years ago

Just released 2.3.3 which optimises the cache invalidation process. The cache should be refreshed following the update to take advantage of the improvements.

michaelhue commented 5 years ago

I updated to 2.3.3 on friday and haven't seen any errors since. I think we can close this for now, thanks for your help!

putyourlightson commented 5 years ago

Glad to hear it!