question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Session & Transaction Support

See original GitHub issue

Support two levels of transactions - transaction that wrap the SaveChanges call from the MongoDbContext and the internal batch write calls in the DbEntityWriter.

https://mongodb.github.io/mongo-csharp-driver/2.7/what_is_new/ https://mongodb.github.io/mongo-csharp-driver/2.7/reference/driver/crud/sessions_and_transactions/

Will need to maintain backwards compatibility when the MongoDB server isn’t running v4

More investigation will be required on how best to implement this functionality.

Issue Analytics

  • State:open
  • Created 5 years ago
  • Comments:10 (7 by maintainers)

github_iconTop GitHub Comments

1reaction
dthk-cogmatixcommented, Aug 17, 2020

Thoughts from “the field.”

I’ve been running a my own patched version of MongoFramework for the past 9 months where I’ve added session/transaction support. I’ve been using a Mongo Client pre 4.4 and have approached indexes and collection creation as a manual activity prior to code deployment. This is similar to (older) Entity Framework behavior, unless you specify in initialization to have Entity Framework handle the schema creation. I don’t see a “huge” issue here, but it definitely doesn’t feel as clean, polished, or robust.

Thoughts on how to handle this: #1) Imitate Entity Framework behavior. Create initialization handlers/code that allow the developer to specify initialization behavior. Delete(), Create(), CreateIfNotExists(), EnsureCreated(), etc. It seems like the executing context of this code wouldn’t really require a session. This seems like the appropriate time to check if Collections exist for all entities and if any necessary indexes are in place.

#2) Further simplify the process and have an option flag that is like: AutoCreateCollections. Document behavior and call it good enough for now. If someone is using client 4.4+ and sets this to true, no issue. If it’s set to true and the client is 4.2, they will receive an exception during creation. Not terrible…

#3) Prioritize operations and executions: Pre-Transaction and during Transaction. If you’re tracking all changes locally before submitting to the server, you could then prioritize execution of collections/indexes before beginning a transaction and sending to the server.

I’m not sure how the code in the latest version is looking, but that may dictate which approach is most appropriate.

1reaction
dthk-cogmatixcommented, Dec 5, 2019

I like what you’ve proposed and it’s a much more thoughtful implementation of what I’ve mentioned above. I completely agree with wrapping the Session and usage of IDisposable. I think the only other add I would consider is putting an IsDisposed property on the Session? That way you can minimize having to catch and swallow ObjectDisposedExceptions?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Transactions and Connection Management
Changed in version 1.4: Session transaction management has been revised to be clearer and easier to use. In particular, it now features “autobegin” ......
Read more >
Hibernate sessions and transaction management guidelines
Manual Transaction Management in Plugins. If the plugin system uses a different version of Spring to the version shipped with Confluence, ...
Read more >
Chapter 2. Transactions and concurrency control
The first concept in understanding Hibernate transaction support is the ... Session acts as a transaction-scoped cache providing repeatable reads for lookup ...
Read more >
Hibernate session and transaction management for bulk ...
In various places in Confluence, we work around this with manual session and transaction management to limit the amount of memory needed for ......
Read more >
Understanding User Session Transactions and Instan...
queue_size_default_pool. Per a few support articles I found where there were other use cases for adjusting the Max Waiters property, ServiceNow ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found