![]() ![]() Here, with optimistic locking the transactions work on their initial state and can commit only if there were no concurrent changes on it. one of the user, when writing her new state, will get an error message like "sorry, someone booked the same room since, it was not actually free, bad luck".Both transactions work, during their whole transaction, on their final state at commit, by blocking the concurrent changes with pessimistic locking. This guarantees that its initial state is the final state of the other one. one of the user, when reading the initial state, will have to wait with a message like "someone else is booking this room, please wait to see if he commits or cancels".There are two acceptable outcomes for a consistent result: To avoid this situation, it requires some coordination between the transactions so that they read a consistent state independent on concurrent operations. Or that only one booking was recorded, without the other knowing of the lost one. Without special coordination, the final state, depending on the data model, may be that both will end in the same bed. ![]() Then, both decide to book this room, which is a write to the database, and commits it, which is the final state. Both start to read a state where the room 42 is free. Think of it like two people booking an hotel room at the same time. If a concurrent transaction is doing its read and writes at the same time, it cannot work on the other's intermediate state, or the result would be inconsistent. I'll try to explain both.Ī transaction can do many reads and writes, bringing the database from one state to another. Isolation Level is the concept, and locking, pessimistic or optimistic, is the implementation. Unlike most of other Relational and SQL concepts, isolation levels was never correctly defined, because the definition, in the seventies, was based on an idea of a possible implementation, which wasn't the one used later. If this is your case, don't panic, the fault is not yours. One of the most difficult concept to understand in SQL databases is probably about transaction Isolation Level (the I in ACID). ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |