How to deal with the issue of the distribution card number

Source: Internet
Author: User
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.

  1. The MySQL InnoDB engine takes advantage of the transaction rollback feature, which is rolled back once a SQL operation fails.

  2. 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.

  • Related Article

    Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.