fix(order): prevent duplicate order numbers under concurrent submit#399
Open
Ibochkarev wants to merge 1 commit into
Open
fix(order): prevent duplicate order numbers under concurrent submit#399Ibochkarev wants to merge 1 commit into
Ibochkarev wants to merge 1 commit into
Conversation
Allocate and persist msOrder.num under MySQL GET_LOCK, add UNIQUE index with NULL drafts, and centralize generation in OrderNumberGenerator.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Описание
Параллельный checkout/finalize мог выдать один и тот же
msOrder.num: оба потока делалиSELECT … LIKE prefix% ORDER BY id DESC, увеличивали счётчик и сохраняли без блокировки.Теперь номер выделяется и сохраняется под MySQL
GET_LOCKвOrderNumberGenerator::runWithNextNumber(), для черновиковnumостаётсяNULL, на колонку вешается UNIQUE (миграция чистит''и разводит существующие дубликаты). Submit и finalize менеджера ходят через этот сервис.Тип изменений
Связанные Issues
Closes #380
Как это было протестировано?
Конфигурация тестирования:
fix/issue-380-order-num-raceКоманды (exit 0):
php -lна всех затронутых PHP-файлахphp tests/OrderNumberGeneratorTest.phpphp tests/PhinxMigrationTablePrefixTest.php(+ остальныеtests/*.php)Миграцию на живой БД в этом прогоне не применяли. Нагрузочный concurrent checkout не гоняли.
Скриншоты (если применимо)
Чеклист
Дополнительные заметки
20260716120000_add_unique_index_on_order_num.Order::getNewOrderNum()/generate()помечены deprecated (WARN в лог): allocate без persist всё ещё подвержен гонке у плагинов; основные пути submit/finalize используютrunWithNextNumber().