Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Transactions, caching, and version transient cleanup issues #20537

Merged
merged 5 commits into from Jun 15, 2018

Conversation

mikejolley
Copy link
Member

3 changes here, all semi-related, which should be rolled out to prevent current conflicts.

This should also help with #17660, however we're not 100% sure as we're unable to replicate the cases in that thread.

This PR reverts some changes made in 1918e2e which has been causing odd issues on stores due to deadlocks, and is potentially guilty of causing double charges on woo.com (cc @kloon).

To Test:

  • Create some test orders, ensure they go through without error. Try as a guest and logged in user.
  • Ensure unit tests pass.

Transactions
Transactions were used so changes could be rolled back, however, it seems this is causing issue if large amounts of data are written due to all the hooks that fire. e.g. in #20528 Not using transactions could lead to partial updates, however, these are not expected and only occur if something (plugin?) causes an error. As such, I'm confident logging will be enough for an admin to resolve.

Disabling transactions seemed to have a positive impact on woo.com, so rolling this out as a fix.

Transient cleanup
Related to the above and raised in #20528. I noticed cleanup runs immediately. We don't need to clean up right away and slow the current process. Deferring the event via cron will work.

Cache ID 0
Not confirmed, but we theorised caching for order ID 0 could be a factor in #17660. This PR simply checks to ensure there is an ID before using caching.

Closes #17660
Closes #20528

@claudiulodro
Copy link
Contributor

@claudiulodro claudiulodro added needs: author feedback The issue/PR needs a response from any of the parties involved in the issue. and removed status: needs review labels Jun 14, 2018
@woocommerce woocommerce deleted a comment from codecov bot Jun 14, 2018
@mikejolley mikejolley added status: needs review and removed needs: author feedback The issue/PR needs a response from any of the parties involved in the issue. labels Jun 14, 2018
@@ -136,7 +136,7 @@ public static function get_transient_version( $group, $refresh = false ) {
$transient_value = get_transient( $transient_name );

if ( false === $transient_value || true === $refresh ) {
self::delete_version_transients( $transient_value );
self::queue_delete_version_transients( $transient_value );
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is still one failing unit test. It seems to be caused by this change, as reverting this line to instantly delete makes it pass again.

If there is potential for this to cause issues, maybe have the deferred transaction delete only happen if a defined constant is true (e.g. WC_DEFER_TRANSACTION_DELETE)?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tests run so quick I assume it's because time() is returning the same value. Thats a bug.

@codecov
Copy link

codecov bot commented Jun 15, 2018

Codecov Report

❗ No coverage uploaded for pull request base (master@cadca6a). Click here to learn what that means.
The diff coverage is 60%.

Impacted file tree graph

@@            Coverage Diff            @@
##             master   #20537   +/-   ##
=========================================
  Coverage          ?   28.21%           
  Complexity        ?    13227           
=========================================
  Files             ?      356           
  Lines             ?    49707           
  Branches          ?        0           
=========================================
  Hits              ?    14021           
  Misses            ?    35686           
  Partials          ?        0
Impacted Files Coverage Δ Complexity Δ
...s/data-stores/abstract-wc-order-data-store-cpt.php 85.51% <100%> (ø) 45 <0> (?)
includes/class-wc-order.php 76.47% <100%> (ø) 255 <0> (?)
includes/class-wc-cache-helper.php 25.84% <20%> (ø) 42 <3> (?)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update cadca6a...17e97c2. Read the comment docs.

Copy link
Contributor

@claudiulodro claudiulodro left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Recent changes look good and all tests pass.

@claudiulodro claudiulodro merged commit ee47ceb into master Jun 15, 2018
@claudiulodro claudiulodro deleted the update/transactions-revert branch June 15, 2018 16:11
rodrigoprimo added a commit that referenced this pull request Sep 5, 2018
This commit reverts commits 2f8a3ea and 17e97c2 that were created to defer transient cleanup (see #20537) and avoid deadlocks on the wp_options table (see #20528 and #17632). The problem is that deferring transient cleanup to a cron job created an issue when creating or importing multiple products at once (see #21100 and woocommerce/wc-smooth-generator#14 (comment)) and has the potential to impact the checkout as well if we start using more versioned transients for orders.

This problem is happening because when importing or creating multiple products at once, for each product that is created or imported, WooCommerce core enqueues a few 'delete_version_transients' cron events. Events are enqueued faster than they are executed and after a few hundred products are generated, the size of the cron queue, which is stored in a single wp_options entry, starts to impact WordPress performance in general.

To reduce the chance of deadlocks happening again after this change, I already created another PR to optimize the query used to delete transients (#21274) by avoiding an unnecessary filesort, and I'm planning, on a subsequent commit, to improve it further by prefixing the transient name with its version instead of suffixing it as it is currently done. But the ultimate solution for high traffic stores is to use a persistent cache plugin.
mikejolley pushed a commit that referenced this pull request Jan 21, 2019
This commit reverts commits 2f8a3ea and 17e97c2 that were created to defer transient cleanup (see #20537) and avoid deadlocks on the wp_options table (see #20528 and #17632). The problem is that deferring transient cleanup to a cron job created an issue when creating or importing multiple products at once (see #21100 and woocommerce/wc-smooth-generator#14 (comment)) and has the potential to impact the checkout as well if we start using more versioned transients for orders.

This problem is happening because when importing or creating multiple products at once, for each product that is created or imported, WooCommerce core enqueues a few 'delete_version_transients' cron events. Events are enqueued faster than they are executed and after a few hundred products are generated, the size of the cron queue, which is stored in a single wp_options entry, starts to impact WordPress performance in general.

To reduce the chance of deadlocks happening again after this change, I already created another PR to optimize the query used to delete transients (#21274) by avoiding an unnecessary filesort, and I'm planning, on a subsequent commit, to improve it further by prefixing the transient name with its version instead of suffixing it as it is currently done. But the ultimate solution for high traffic stores is to use a persistent cache plugin.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Lock tables issues Orders overwriting when placed at same time
4 participants