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

fix: Stop locking catalog for every resources. #80

Merged
merged 5 commits into from
May 21, 2021
Merged

Conversation

cyrilgdn
Copy link
Owner

@cyrilgdn cyrilgdn commented Apr 23, 2021

Historically, this provider takes a (golang) lock on a database for every resource of this database.
So only one create/update/delete of resource by database can be done at the same time.

(As it's a RWLock, read of resources can be parallelized)

Since #5 refactoring, I mistakenly change the lock which now takes a write lock even for read operations
(basically the plan part of Terraform). So provider was slower since v1.10

We could fix this and take a read lock for read operations as before but actually I don't see the point of this lock.
For me, most operations could be done at the same time.

Most of the request are now done in a transaction, the only risk is that a transaction will fail to commit
if multiple resources modifies the same database line.
That's the case for postgresql_default_privileges, one pg_default_acl row could represents multiple resources,
so this PR takes a lock on the owner role to avoid that.

This should make the provider way faster.

Tested with this code: https://github.com/cyrilgdn/terraform-provider-postgresql/tree/master/examples/issues/48

Fix #48

Historically, this provider takes a (golang) lock on a database for every resource of this database.
So only one create/update/delete of resource by database can be done at the same time.

(As it's a RWLock, read of resources can be parallelized)

Since #5 refactoring, I mistakenly change the lock which now takes a write lock even for read operations
(basically the plan part of Terraform). So provider was slower since v1.10

We could fix this and take a read lock for read operations as before but actually I don't see the point of this lock.
For me, most operations could be done at the same time.

Most of the request are now done in a transaction, the only risk is that a transaction will fail to commit
if multiple resources modifies the same database line.
That's the case for `postgresql_default_privileges`, one `pg_default_acl` row could represents multiple resources,
so this PR takes a lock on the owner role to avoid that.

This should make the provider way faster.

Fix #48
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.

Terraform plans times doubled since 1.10
1 participant