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?
722 Views Asked by John At
1
There are 1 best solutions below
Related Questions in MONGODB
- Meteor MapReduce Package Error: A method named is already defined
- Token based authorization in nodejs/ExpressJs and Angular(Single Page Application)
- Big data with spatial queries/indexing
- How to recover from losing all your /data/db
- What are the benefits of using the fields option when querying in Meteor
- Node JS Async Response
- mongoose get property from nested schema after `group`
- What to use for subdocuments ID's in MongoDB?
- ORM Code First versa Database First in Production
- How to profile a Yii2 based API?
- get length of embedded document in mongoDB with jade
- Architecture: Multiple Mongo databases+connections vs multiple collections with Express
- Why are numbers being inserted into MongoDB incorrectly?
- hibernate ogm mongo db, how to get count of collection?
- C++ Mongodb driver, not working
Related Questions in PLAYFRAMEWORK
- Auto reload with play2
- Log of dependency does not show
- Json implicit format with recursive class definition
- Async LDAP authentication with play framework
- Why do I get an IndexOutOfBoundsException when my else should prevent it?
- Play 2.4 scala I am facing issues getting messages implicit in my code
- Play template project requires subscription to typesafe, why?
- hot swap in sbt project without play-plugin
- Getting "Cannot find HTTP header here" in play framework Scala
- How can I redirect to an error page in my Play app?
- How do you iterate over json when the schema is not known up front?
- Play Scala Converting sync to async
- morphia Geo-spatial "near" method in embedded list
- How to modify queryString and body of the request before being processed by the routes in Playframework 2 Scala?
- Not able to access key-values pairs in a JSON using Play library in scala
Related Questions in TRANSACTIONS
- C# MySQL Transaction commit
- Multiple transaction managers - Selecting a one at runtime - Spring
- Django transactions: managing two different transactions atomically inside the overriding of save() method
- How can I add FOR UPDATE to a cakephp3 query?
- Why my mysql transaction is not working properly?
- Multiple Hibernate transactions in a JTA session
- Using transaction in Ruby On Rails controller method
- Google Analytics duplicate transaction id multiple domains
- How to limit dynamic queries to only accept select statements?
- combining rollback in two action rails 4
- Symfony2: transactions fail with "There is no active transaction."
- Can RPUSH and LPUSH in Redis race?
- PHP rollback on IBMi db2 doesn't work
- Error in OleDbTransaction
- Wildfly - Infinispan Transactions configuration
Related Questions in REACTIVEMONGO
- Reactivemongo getAsTry is not a member of PasswordInfo
- Reactivemongo capped collection issues with Play 2.3
- How to store date in MongoDB in ISO format instead of Long [Play, Scala and ReactiveMongo]?
- How do write a date range query in mongodb using reactive mongo in scala
- ReactiveMongo with Play 2.3
- Abstract method error when combining akka 2.3.7, reactive mongo and spray
- Reactivemongo TTL collections
- Composing Futures with For Comprehension
- MongoDB Query: How to add some days to a date field before comparing it with a given date
- how to implement validation in case class used as form (using Json.fromJson)
- Scala Spray + Reactive Mongo Logging
- Reactivemongo serializing a map into a BSONDocument
- How to represent a GeoJSON point in a ReactiveMongo model?
- How to parse this "pretty" BSON in Scala?
- How to create a play.api.libs.iteratee.Enumerator which inserts some data between the items of a given Enumerator?
Related Questions in PLAY-REACTIVEMONGO
- Reactivemongo capped collection issues with Play 2.3
- Matching result of MongoController.serve
- How to store date in MongoDB in ISO format instead of Long [Play, Scala and ReactiveMongo]?
- Reactivemongo TTL collections
- Working with databases containing more than 22 fields in Play 2.x
- How to get a result from FindAndModifyResult?
- Reactivemongo nested JSON structure
- ReactiveMongo + Play Generic NullPointerException
- Updating reactivemongo due to PrimaryUnavailableException
- MongoDB field with Double data type saved as Int64 for no reason
- expecting to save Double in the db but mongo decide to save it as Int64 (big number)
- How can I connect to an Atlas cluster with the SRV connection string format using ReactiveMongo?
- Should I create recursive method for retry in mongodb transaction to avoid document level lock error?
- injection error when running test with sbt
- ReactiveMongo Macros.handler crashes after new field is added
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 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.