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

Expose mongo transactions #3369

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

Conversation

hahn-kev
Copy link
Contributor

@hahn-kev hahn-kev commented Sep 27, 2024

From this discussion and a follow up with Jason he mentioned that transactions haven't been exposed to utilize them in mongo.

In order for transactions to work across repos there needs to only be one Mongo client in a given request, I've refactored all the type specific contexts to get the IMongoDb from the new IMongoDbContext which is a scoped service so there's only one instance per request.

Then I changed a couple methods in the Merge service to make changes inside transactions. You'll notice that the transaction is not aborted in our user code, this is because the transaction is disposable and if it's disposed before it's committed then it will be aborted, so if an exception is thrown between Begin and Commit then the changes made will be rolled back.

Feel free to suggest changes, I don't really love how I had to mock out and expose the transactions via the IMongoDbContext which also contains the IMongoDatabase, but I didn't really feel like making a separate service just for transactions, @jasonleenaylor let me know what you think there if we want to split those out.


This change is Reviewable

Make it a scoped service so only 1 MongoClient is created per request
Use that to expose transactions which are now shared across all Repos
Copy link

codecov bot commented Sep 27, 2024

Codecov Report

Attention: Patch coverage is 29.03226% with 22 lines in your changes missing coverage. Please review.

Project coverage is 74.49%. Comparing base (2184716) to head (dd7a351).
Report is 3 commits behind head on master.

Files with missing lines Patch % Lines
Backend/Contexts/MongoDbContext.cs 0.00% 22 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #3369      +/-   ##
==========================================
- Coverage   74.73%   74.49%   -0.25%     
==========================================
  Files         280      281       +1     
  Lines       10743    10801      +58     
  Branches     1297     1300       +3     
==========================================
+ Hits         8029     8046      +17     
- Misses       2349     2389      +40     
- Partials      365      366       +1     
Flag Coverage Δ
backend 83.54% <29.03%> (-0.45%) ⬇️
frontend 66.61% <ø> (-0.07%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@imnasnainaec
Copy link
Collaborator

I extended this pr's branch with some cleanup and a fix (adding the missing StartTransaction): https://github.com/sillsdev/TheCombine/tree/mongo-context

@imnasnainaec imnasnainaec marked this pull request as draft October 7, 2024 19:38
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