In Windows 10, Yii2.0, and MySQL, the unique index of the combination is realized, and the process of data repeated writing in high concurrent situations is solved.
1. In the production environment, the data in the skill data table is repeatedly written, as shown in Figure 1
2. However, before writing, it is judged whether the record exists. The combination of GAME_CODE and TEAM_CODE should be the only one, as shown in Figure 2
3. It is recommended to check the website first: http://www.shuijingwanwq.com/2017/04/18/1568/ , due to the mechanism of the program requested by POST, the POST file of AB only supports the parameters of the request, and cannot simulate the real scene. The real scene should be that the parameters of each request are different, so the bug in the production environment cannot be reproduced
4. By commenting out the conditions for judging whether the record exists, each request is inserted, and the data is inserted, and the scenario where there are multiple skill data in a game is simulated, as shown in Figure 3
5. Based on Postman, two consecutive requests with different parameters have been executed, and finally there are 4 records in MySQL, as shown in Figure 4 and 5
6. In order to avoid the occurrence of this situation, it is decided to modify the table structure in mysql, delete the 4 records in the table, and put GAME_CODE and TEAM_C ODE is added as the unique index of the combination, select GAME_CODE and TEAM_CODE in phpMyAdmin, and click the unique button, as shown in Figure 6
7. The SQL statement has been successfully run, and the unique index of the combination is added successfully, as shown in Figure 7 and 8
ALTER TABLE `KQ_GAME_TEAM_SKILL` add unique( `GAME_CODE`, `TEAM_CODE`);
8. Based on GII, regenerate new model files, as shown in Figure 9
9. Insert a new line in Rules(), as shown in Figure 10
10. Based on Postman, two consecutive requests with different parameters are executed, and an error is reported when executing the second time, as shown in Figure 11
11. The error message has been processed, and the original error message is printed out, as shown in Figure 12
12. The original error message: $gameteamskill->Errors is as follows, as shown in Figure 13
13. Check MySQL at this time. There are only 2 records in the skill data corresponding to a game, and only 1 in a team, which is in line with expectations, as shown in Figure 14
14. Even if the bug in the production environment is not simulated through AB pressure testing, through the realization of adding a unique index to mysql, in theory, the reproduction of this bug is prevented, but the code display is not a number, which needs to be optimized and processed.













