manajit
asked on
How do I lock a MySQL table so that other process can not read the table.
Hi,
I am using PHP Laravel. I am storing the count of items in a table. When a customer purchases an item, we first look at the count of items available, then there are some other related DB operations that are done and there is a logic to reduce the item count and store it back.
However, if 2 customers purchase the item at the same time, there is a race condition and the count gets reduced only by 1. There is a lot of other backend logic and DB operations that happen before the value is updated in the table.
How can I manage the race condition either at the DB level, so that the table is locked for reading till the previous transaction is completed or at the code level, the code is considered as a critical section and locked till the complete code for one purchase goes through.
Help will be appreciated.
I am using PHP Laravel. I am storing the count of items in a table. When a customer purchases an item, we first look at the count of items available, then there are some other related DB operations that are done and there is a logic to reduce the item count and store it back.
However, if 2 customers purchase the item at the same time, there is a race condition and the count gets reduced only by 1. There is a lot of other backend logic and DB operations that happen before the value is updated in the table.
How can I manage the race condition either at the DB level, so that the table is locked for reading till the previous transaction is completed or at the code level, the code is considered as a critical section and locked till the complete code for one purchase goes through.
Help will be appreciated.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
abandoned question