One of the activities that I did was to distribute the card number to the winning user after the lottery, and the card number was put into the db by hand;
When the user after winning the perfect data to obtain Cartmel: First judge the use of the state, get the card number, and then modify the card number status.
In this acquisition card number process, if there is high concurrency situation, how to handle reasonable?
Table is used by the InnoDB engine, when acquiring the card number when the judgment is not used can not be based on the primary key to row locks, resulting in the entire table lock.
Reply content:
One of the activities that I did was to distribute the card number to the winning user after the lottery, and the card number was put into the db by hand;
When the user after winning the perfect data to obtain Cartmel: First judge the use of the state, get the card number, and then modify the card number status.
In this acquisition card number process, if there is high concurrency situation, how to handle reasonable?
Table is used by the InnoDB engine, when acquiring the card number when the judgment is not used can not be based on the primary key to row locks, resulting in the entire table lock.
The MySQL InnoDB engine takes advantage of the transaction rollback feature, which is rolled back once a SQL operation fails.
Use the queue to reduce the load on the business logic server and avoid the problems caused by high concurrency.
Place the unused card number in the Redis queue and get a single pop
You can not give him the card number, this is the most convenient way. The winning user must have a record, right? Awards, you got a status? User information after the change of awards state, and then told the user this morning awards on the line. Then set up a cron-job, then the minute will certainly not be heavy. And the winner will have at least one more visit to your website, and the provincial people will never come after the award.