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

Validate if snapshot isolation is enabled when outbox is launched with pessimistic concurrency enabled #1370

Open
ramonsmits opened this issue Jan 9, 2024 · 5 comments
Labels

Comments

@ramonsmits
Copy link
Member

Describe the feature.

Validate if snapshot isolation is enabled when outbox is launched with pessimistic concurrency enabled.

When snapshot isolation is enabled queries are not able to use pessimistic concurrency. The endpoint should not launch when it detects that snapshot isolation is enabled.

For example, with SQL Server:

SELECT snapshot_isolation_state_desc
FROM sys.databases 
WHERE name=DB_NAME()

Sources:

For SQL Server

Only querying a specific database might not be sufficient but its important that the catalog that stored the outbox data does not use snapshot isolation.

Additional Context

No response

@bbrandt
Copy link

bbrandt commented Jul 2, 2024

its important that the catalog that stored the outbox data does not use snapshot isolation

@ramonsmits Do you have any details or background for why these options are not compatible?

We commonly set snapshot isolation as our default isolation mode and we are looking at starting to use the NSB Outbox and prefer pessimistic concurrency to support high throughput.

@ramonsmits
Copy link
Member Author

Snapshot isolation is optimistic concurrency control. Changes are applied at commit and not earlier with locking.

@bbrandt
Copy link

bbrandt commented Jul 2, 2024

Thanks! I am realizing today that I knew less about snapshot isolation than I had thought. This issue is specifically targeted at the Outbox Pessimistic locking enabled like this:

var outboxSettings = endpointConfiguration.EnableOutbox();
outboxSettings.UsePessimisticConcurrencyControl();

Right?

@ramonsmits
Copy link
Member Author

@bbrandt Yes, with UsePessimisticConcurrencyControl we do an INSERT just when the message is received but with snapshot isolation enabled on the database even though that INSERT is already sent to the database the actual modification will not happen immediately only once the database transaction is committed.

Snapsnop isolation is great for not locking data and reduce page/table locks because of this but actually not great when with block contention as it will increase conflicts.

@andreasohlund
Copy link
Member

UPDLOCK can be used

https://learn.microsoft.com/en-us/dotnet/framework/data/adonet/sql/snapshot-isolation-in-sql-server#understanding-snapshot-isolation-and-row-versioning

Snapshot isolation uses an optimistic concurrency model. If a snapshot transaction attempts to commit modifications to data that has changed since the transaction began, the transaction will roll back and an error will be raised. You can avoid this by using UPDLOCK hints for SELECT statements that access data to be modified.

@SzymonPobiega @tmasternak we tested this recently right?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants