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

[10.0] Remove RowExclusiveLock on exception_rule #1647

Merged
merged 1 commit into from
Sep 11, 2019

Conversation

guewen
Copy link
Member

@guewen guewen commented Aug 14, 2019

The goal of the modified method is to create or remove the relationship
(in the M2m relation tabel) between the tested model (such as
sale_order) and the exception rules. When the ORM writes on
ExceptionRule.sale_ids (using the example of sale_exception), it will
first proceeds with these updates:

  • an UPDATE on exception_rule to set the write_date
  • INSERT or DELETE on the relation table
  • but then, as "write" is called on the exception rule, the ORM will
    trigger the api.depends to recompute all the "main_exception_ids"
    of the records (sales, ...) related to it, leading to an UPDATE
    for each sale order

We end up with RowExclusiveLock on such records:

  • All the records of the relation table added / deleted for the current
    sale order
  • All the records of exception_rule matching the current sale order
  • All the records of sale_order related to the exception rules matching
    the current sale order

The first one is expected, the next 2 are not. We can remove the lock on
the exception_rule table by removing _log_access, however in any case,
the main_exception_ids computed field will continue to lock many sale
orders, effectively preventing 2 sales orders with the same exception
to be confirmed at the same time.

Reversing the write by writing on SaleOrder instead of ExceptionRule
fixes the 2 unexpected locks. It should not result in more queries: the
"to remove" part generates one DELETE on the relation table for the rule
to remove and the "to add" part generates one INSERT (with unnest) for the rule to add,
both will be exactly the same in both cases.

Related to #1642
Replaces #1638

Copy link
Contributor

@sebalix sebalix left a comment

Choose a reason for hiding this comment

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

Small comment, but approving.

base_exception/models/base_exception.py Show resolved Hide resolved
Copy link
Contributor

@florian-dacosta florian-dacosta left a comment

Choose a reason for hiding this comment

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

Thanks a lot for the fix @guewen
It seems fine to me.
I agree these concurrent update issues have to be fixed and we'll eventually fix some other performance issue in the future if necessary, having this issue in mind.

The goal of the modified method is to create or remove the relationship
(in the M2m relation tabel) between the tested model (such as
sale_order) and the exception rules. When the ORM writes on
ExceptionRule.sale_ids (using the example of sale_exception), it will
first proceeds with these updates:

* an UPDATE on exception_rule to set the write_date
* INSERT or DELETE on the relation table
* but then, as "write" is called on the exception rule, the ORM will
  trigger the api.depends to recompute all the "main_exception_ids"
  of the records (sales, ...) related to it, leading to an UPDATE
  for each sale order

We end up with RowExclusiveLock on such records:

* All the records of the relation table added / deleted for the current
sale order
* All the records of exception_rule matching the current sale order
* All the records of sale_order related to the exception rules matching
the current sale order

The first one is expected, the next 2 are not. We can remove the lock on
the exception_rule table by removing `_log_access`, however in any case,
the main_exception_ids computed field will continue to lock many sale
orders, effectively preventing 2 sales orders with the same exception
to be confirmed at the same time.

Reversing the write by writing on SaleOrder instead of ExceptionRule
fixes the 2 unexpected locks. It should not result in more queries: the
"to remove" part generates a DELETE on the relation table for the rule
to remove and the "to add" part generates an INSERT for the rule to add,
both will be exactly the same in both cases.

Related to OCA#1642
Replaces OCA#1638
@guewen guewen force-pushed the 10.0-base_exception-concurrent-errors branch from 248da11 to 6a301a1 Compare August 15, 2019 05:40
@guewen
Copy link
Member Author

guewen commented Aug 15, 2019

Squashed the fixup

@OCA-git-bot
Copy link
Contributor

This PR has the approved label and has been created more than 5 days ago. It should therefore be ready to merge by a maintainer (or a PSC member if the concerned addon has no declared maintainer). 🤖

@guewen
Copy link
Member Author

guewen commented Sep 11, 2019

/ocabot merge minor

@OCA-git-bot
Copy link
Contributor

On my way to merge this fine PR!
Prepared branch 10.0-ocabot-merge-pr-1647-by-guewen-bump-minor, awaiting test results.

OCA-git-bot added a commit that referenced this pull request Sep 11, 2019
Signed-off-by guewen
@OCA-git-bot
Copy link
Contributor

Congratulations, your PR was merged at 8df0132. Thanks a lot for contributing to OCA. ❤️

@OCA-git-bot OCA-git-bot merged commit 6a301a1 into OCA:10.0 Sep 11, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants