![]() How to solve this problem elegantly and without having such big transactions? One option is use what is defined as “Optimistic Concurrency”. While this will work perfectly from a functional perspective, if you are in a highly concurrent system and you need to have a very scalable solution where an extreme number of executions can be done in parallel, you really want to have such protection around your transaction – the isolation – for the shortest time possible, as for as long as you are using that data in your algorithm, other may have to wait for accessing it, to avoid interfering with your activity. Everything works and changes will be persisted, or nothing works and changes will be undone. This behavior is also known as atomicity: the two steps are indivisible. ![]() You need a transaction, that will provide the needed isolation so that interference won’t happen.Īs the chosen algorithm is comprised of two separate steps, you must create a transaction big enough to keep both steps under the same umbrella, so that the two physical separate steps will logically work like one. As you can easily understand, in fact, if you have done the first action, you really need to be sure that in-scope data doesn’t change before you can do the second action, otherwise the result may be wrong or inconsistent. ![]() The moment you have two actions, where one depends on another, you need to make sure that the data used by both doesn’t change in the meantime because of some other action done by someone else. The problem, in fact, lies in the algorithm itself. This approach has a flaw, whatever the database you are using and no matter the database if relational or not. Many developers will solve it by trying to execute two steps: Generalizing the problem, it can be described as the requirement of insert some data into a table only if that data is not there already. Recently I found a quite common request on StackOverflow.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |