One of my activities is to distribute the card number to the winning user after the lottery, and the card number is already in the database. When the user completes the information to obtain the card secret after the prize, he first checks the usage status, get the card number, and then modify the card number status. What if there is a high concurrency in the process of getting the card number... one of my activities is to distribute the card number to the winning user after the lottery, and the card number is already in the database;
When the user completes the information to obtain the password after winning the prize: first judge the Usage Status, get the card number, and then modify the card number status.
In the process of getting the card number, if there is a high concurrency, how can we handle it reasonably?
The table uses the innodb engine. When the card number is obtained, the row locks cannot be performed based on the primary key, resulting in the entire table lock.
Reply content:
One of my activities is to distribute the card number to the winning user after the lottery, and the card number is already in the database;
When the user completes the information to obtain the password after winning the prize: first judge the Usage Status, get the card number, and then modify the card number status.
In the process of getting the card number, if there is a high concurrency, how can we handle it reasonably?
The table uses the innodb engine. When the card number is obtained, the row locks cannot be performed based on the primary key, resulting in the entire table lock.
The MySQL innodb engine uses the transaction rollback function. Once an SQL operation fails, it rolls back.
Use queues to reduce the load on the business logic server and avoid problems caused by high concurrency.
Put unused card numbers in the Redis Queue, get one and pop one
You may not give him a card number. This is the most convenient way. The winning user must have a record, right? Do you have a status of awards? After the user's information is complete, change the status of the prize, and then tell the user to send the prize in the early morning. Then set up a cron-job, and the job will not be re-sent in minutes. In addition, those who win the prize will have to visit your website at least once again, and those in the province will not receive the prize again.