I am using mongodb transaction. Sometimes it may happen that for concurrent transaction in same document data update the second transaction will create transient transaction error which will abort the second concurrent update.
In this case retry helps. My question is there better design for retry of the second transaction instead of recursive method call on error? Or retry is possible in mongodb query level ?
Note: I am using it in scala playframework with reactivemongo.
Should I create recursive method for retry in mongodb transaction to avoid document level lock error?
723 Views Asked by John At
1
There are 1 best solutions below
Related Questions in MONGODB
- MongoDb not connecting C#
- How do I link two models in mongoose?
- MERN Stack App - User Avatar Upload - 500 Error After Deployment on Render
- On the server side, it returns undefined but on the client side, logs the values no problem
- Laravel: Using belongsToMany relationship with MongoDB
- What are some MERN projects that will grow me from junior dev to senior
- Save Interface in DB golang
- findOneAndUpdate not updating value in mongodb?
- Get Type Error when using .countDocuments with mongoDB
- Getting a Large Error Output When Calling MongoDB/Mongoose Functions Without an Error Message
- How to enter data in mongodb array at specific position such that if there is only 2 data in array and I want to insert at 5, then rest data is null
- using Python to insert_one to my mongo_db, How do I pass key values into a function?
- SSL Certificate Verification Error When Scraping Website and Inserting Data into MongoDB
- connect ECONNREFUSED 43.205.72.30:27017 while connecting to Atlas
- Vite is probably changing my import path. What should I do?
Related Questions in PLAYFRAMEWORK
- Install Play 1.7.1 on Windows
- Handling of WebSocket Client Messages in Play Framework
- Handling WebSocket Connections in Play Framework
- Handling WebSocket Connections in Play Framework in Scala
- build.sbt error: value addRepositoryAuthentication is not a member of lmcoursier.CoursierConfiguration
- How to log incoming request with Scala & Play Framework?
- Optionally enable Scala play to accept mLTS credentials?
- reactivemongo with scala3, pekko, play-3
- Specs 2 - I want to mock one of the injected modules into the controller class
- Scala3 equivalent to -Wconf src filter
- Using Selenium in Scala play not only for testing
- How to execute PUT REST client code using playframework in scala
- ERROR akka.actor.ActorSystemImpl(applica Uncaught error from thread, shutting down JVM since 'akka.jvm-exit-on-fatal-error' is enabled for ActorSystem
- Autogenerating unnapply for play form handling in scala3 for single-element case classes
- Play framework + Java +Ebean models.Donation is NOT an Entity Bean registered with this server?
Related Questions in TRANSACTIONS
- How to design the file operation interface involving status and transactions?
- Internal events cannot be consumed in spring boot. Only when using Kafka Consume
- How do you categorize a pending transaction immediately after making a purchase and have it save?
- Spring JPA + Hibernate + Rest services + long time transactions
- How to Identify Specific Transaction Anomalies in a Given Schedule?
- When does shared and exclusive locks are acquired and released in a MySql transactions?
- How to write a reusable DB transaction wrapper?
- "No data" after sending tx Jupiter Swap Python
- Perform multiple Identity actions in a transaction
- Running a program on different computers with different users that access a central database simultaneously - VB.NET XAMPP/MySQL
- Proper way to implement transactional HOTP?
- Transactional role in Java Spring Boot
- Is there a way of increasing MAX_INTEGER in web3.js
- Single transaction, multiple service calls to Entity Framework updating database
- Saving to Reactive Redis and Postgres in a single transaction
Related Questions in REACTIVEMONGO
- Spring webflux not streaming instead gives response after the processing is complete
- reactivemongo with scala3, pekko, play-3
- Reactive mongo group elements and count them
- expecting to save Double in the db but mongo decide to save it as Int64 (big number)
- MongoDB field with Double data type saved as Int64 for no reason
- Updating reactivemongo due to PrimaryUnavailableException
- How do I read a primitive type from database with ReactiveMongo?
- Custom Instant BSON Format in ReactiveMongo
- ReactiveMongo with Primary-Secondary-Arbiter (PSA) Architecture
- Update a document with ReactiveMongo using a condition based on the data inside the document and get the updated doc at the end
- Scala - get BSON document size with new ReactiveMongo(2.13)
- How to convert BSONDocument to JsObject in reactiveMongo 1.0
- Implementing custom commands for ReactiveMongo 1.x.x
- How to write JSON reads/writes and also ReactiveMongo handlers when case classes contain a generic type parameter?
- My case class contains a property of type Any, how do I create an implicit for Any?
Related Questions in PLAY-REACTIVEMONGO
- expecting to save Double in the db but mongo decide to save it as Int64 (big number)
- MongoDB field with Double data type saved as Int64 for no reason
- Updating reactivemongo due to PrimaryUnavailableException
- How do I read a primitive type from database with ReactiveMongo?
- Error when connection to mongodb version 6
- How to convert BSONDocument to JsObject in reactiveMongo 1.0
- ReactiveMongo query to count documents
- ReactiveMongo 0.20.12-Play28 crashing on Startup with a MatchError: Success exception
- ReactiveMongo with Play-json responsibility's division
- Working with ReactiveMongo (for play framework apps) in 2020
- BSON to Play JSON support for Long values
- Should I create recursive method for retry in mongodb transaction to avoid document level lock error?
- How can I connect to an Atlas cluster with the SRV connection string format using ReactiveMongo?
- Given transaction number 1 does not match any in-progress transactions. The active transaction number is -1
- The play app terminates for reactive mongo update operation
Trending Questions
- UIImageView Frame Doesn't Reflect Constraints
- Is it possible to use adb commands to click on a view by finding its ID?
- How to create a new web character symbol recognizable by html/javascript?
- Why isn't my CSS3 animation smooth in Google Chrome (but very smooth on other browsers)?
- Heap Gives Page Fault
- Connect ffmpeg to Visual Studio 2008
- Both Object- and ValueAnimator jumps when Duration is set above API LvL 24
- How to avoid default initialization of objects in std::vector?
- second argument of the command line arguments in a format other than char** argv or char* argv[]
- How to improve efficiency of algorithm which generates next lexicographic permutation?
- Navigating to the another actvity app getting crash in android
- How to read the particular message format in android and store in sqlite database?
- Resetting inventory status after order is cancelled
- Efficiently compute powers of X in SSE/AVX
- Insert into an external database using ajax and php : POST 500 (Internal Server Error)
Popular # Hahtags
Popular Questions
- How do I undo the most recent local commits in Git?
- How can I remove a specific item from an array in JavaScript?
- How do I delete a Git branch locally and remotely?
- Find all files containing a specific text (string) on Linux?
- How do I revert a Git repository to a previous commit?
- How do I create an HTML button that acts like a link?
- How do I check out a remote Git branch?
- How do I force "git pull" to overwrite local files?
- How do I list all files of a directory?
- How to check whether a string contains a substring in JavaScript?
- How do I redirect to another webpage?
- How can I iterate over rows in a Pandas DataFrame?
- How do I convert a String to an int in Java?
- Does Python have a string 'contains' substring method?
- How do I check if a string contains a specific word?
Every driver for MongoDB has two types of APIs:
Callback API, that incorporates logic to
TransientTransactionError.UnknownTransactionCommitResult.Core API, that does not incorporate retry logic for the above errors, instead applications should explicitly implement retry logic for the error.
The default implementation of retry logic for the NodeJS driver can be found here and is probably the best one in 90% of the cases. As you can see the
attemptTransactionmethod is recursively called untilMAX_WITH_TRANSACTION_TIMEOUT(fixed to 2 minutes) is reached.Just for completeness, this approach of continuously rolling back and retrying the transaction is in line with the optimistic MVCC adopted by MongoDB, i.e. the snapshot isolation. The above errors are considered as transient errors, meaning that they are temporary and the transaction could be successful if restarted.
If you do not have any particular needs, then this implementation is good enough, otherwise your only choice is to use Core APIs and do it yourself. In this case you should provide additional info on why the default design available from Callback APIs is not suitable in your project.