cloud_controller_ng icon indicating copy to clipboard operation
cloud_controller_ng copied to clipboard

Fix service instance operations duplicates root cause

Open svkrieger opened this issue 2 years ago • 0 comments

Thanks for contributing to cloud_controller_ng. To speed up the process of reviewing your pull request please provide us with:

  • A short explanation of the proposed change:

Preventing duplicates in the service_instance_operations DB table by encapsulating the deletion of the operation and the insert of the new operation in a transaction and also locking the service instance entry in the DB until the transaction is finished.

  • An explanation of the use cases your change solves

There was a race condition when two workers were processing two different operations on the same service instance. The worker first removed the last_operation of that service instance from the service_instance_operations DB table and after that inserted a new operation.

This was done in two separate transactions, which enabled the second process to insert it's operation after the first process deleted the operation, but before it can insert the new operation. After both processes finished, two operations remained in the table.

  • Links to any other associated PRs

This PR is fixing the root cause. There is already a PR https://github.com/cloudfoundry/cloud_controller_ng/pull/2905 which makes sure that the assumption, which is made in the coding ,that there can be only one entry in the service_instance_operations DB table for each service_instance_id, matches the database structure, which currently does not have this constraint. The PRs can be merged independently. If there is another race condition in the code we would see it after the other PR has been merged, because trying to insert a second entry into the table would result in a key constraint error.

  • [x] I have reviewed the contributing guide

  • [x] I have viewed, signed, and submitted the Contributor License Agreement

  • [x] I have made this pull request to the main branch

  • [x] I have run all the unit tests using bundle exec rake

  • [ ] I have run CF Acceptance Tests

svkrieger avatar Aug 10 '22 08:08 svkrieger