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: add transactions for numbers #5729

Draft
wants to merge 4 commits into
base: develop
Choose a base branch
from

Conversation

vsukhin
Copy link
Collaborator

@vsukhin vsukhin commented Aug 5, 2024

Pull request description

Checklist (choose whats happened)

  • breaking change! (describe)
  • tested locally
  • tested on cluster
  • added new dependencies
  • updated the docs
  • added a test

Breaking changes

Changes

Fixes

Signed-off-by: Vladislav Sukhin <[email protected]>
Signed-off-by: Vladislav Sukhin <[email protected]>
Signed-off-by: Vladislav Sukhin <[email protected]>
Signed-off-by: Vladislav Sukhin <[email protected]>
}
defer session.EndSession(ctx)

_, err = session.WithTransaction(ctx, func(sessCtx mongo.SessionContext) (interface{}, error) {
Copy link
Member

Choose a reason for hiding this comment

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

Either that should be an atomic MongoDB query, or better to go with an external lock (NATS or Mongo?) - mixing the Golang logic with MongoDB queries will lead to broken results anyway; in best case, for concurrent transactions, it will increment sequence correctly, but will try with the duplicated execution name

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

yes, transactions are supported only for replicaset and will not help, external lock with Mongo might work

Copy link
Collaborator Author

@vsukhin vsukhin Aug 5, 2024

Choose a reason for hiding this comment

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

actualy, distributed lock is also not a silver bullet, if connection fails before the lock is removed, it will be necessary to wait till it is expired. so instead of simply rerunning the test and have a missed number, user will need to wait sometime and not sure, it's a better option for him. I would rather discuss it first, if we need it or not

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.

2 participants