-
Notifications
You must be signed in to change notification settings - Fork 199
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
Concurrent runs leads to duplicate rows #3866
Comments
One thing I'd appreciate more clarity on is if it's sufficient to limit concurrency per environment or globally, I would suspect globally as it's all the same physical tables, so two environments may interfere? EDIT: Have to limit globally, can be reproduced as above but with |
I believe this happens because the transaction isolation in your postgres instance is set to READ COMMITTED or below. So I think the following happens:
I believe if you set the default isolation level to at least REPEATABLE READ, it should stop happening. |
Default isolation level is not the issue, I can reproduce with:
It's possible to reproduce against postgres in docker-compose running like this: services:
localdb:
image: postgres:17
command: "postgres -c default_transaction_isolation=\"repeatable read\" -c log_statement=all -c log_connections=true -c log_disconnections=true -c log_line_prefix='%m [%d] [%p]'"
environment:
POSTGRES_DB: local
POSTGRES_USER: local
POSTGRES_PASSWORD: local
I think with more granularity what happens is:
Here is full postgres log (with repeatable read as default transaction isolation) postgres log
Postgres logs, filtered down to only process 81 and 83 for readability (The ones doing the inserts) Note 81s "late" COMMIT
I don't have permission to reopen the issue though |
@izeigerman Would you mind reopening this one? |
I see now, @simon-pactum. I think we could lock the table before doing the insert with
|
When two concurrent sqlmesh plans are running, the latter only bails out at the end with something like:
But at that point it's already too late and duplicate rows have been created.
To reproduce:
sqlmesh: 0.158.2
sqlmesh plan
say yes, let it do its thing0
sqlmesh plan
wait for prompt, don't answer yetsqlmesh plan
wait for prompt, don't answer yety
in both terminals in quick successionNow I have twice as many rows as expected in the prod environment:
This probably happened as both did the
INSERT ...
at the same time.I'm not sure if this is an actual bug or just room for documentation improvement.
Either way, it would be nice if it bailed out with an error before causing issues
The text was updated successfully, but these errors were encountered: