Skip to content

Expose mongo transactions#3369

Closed
hahn-kev wants to merge 4 commits intosillsdev:masterfrom
hahn-kev:expose-mongo-transactions
Closed

Expose mongo transactions#3369
hahn-kev wants to merge 4 commits intosillsdev:masterfrom
hahn-kev:expose-mongo-transactions

Conversation

@hahn-kev
Copy link
Copy Markdown
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
@hahn-kev hahn-kev force-pushed the expose-mongo-transactions branch from b73f10a to 8704d45 Compare September 27, 2024 07:06
@codecov
Copy link
Copy Markdown

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 27 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
Copy Markdown
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
@imnasnainaec
Copy link
Copy Markdown
Collaborator

Replaced by #3484

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