Duplicate key value violates unique constraint "spy_sales_order-order_reference"
Hi All,
we moved the order prozessin to use the queue. But if for some reason we get a flood of messages we get this message:
Duplicate key value violates unique constraint "spy_sales_order-order_reference"
First we thought it might be sprykers sequence number module. But after looking at the code it is basically impossible because they load and lock the row with the lastest order key by propel and so there should be a transaction until the save() call. And there is a unique key restriction on the number so the code and table will never ever generate the same insert.
But what could load the spy_sales_order and try to insert it again?
Our own implementation passes the quote in the end into sprykers SalesOrderSaver and I can't see any path that would load an existing sales order.
Any idea or suggestion?
Cheers Karsten
Answers
-
Heyhey @KFrw ,
we moved the order prozessin to use the queue
How does this look like?
You have the quote-transfer and when someone submits the cart (checks out) instead of already running the CheckoutWorkflow you put the quotetransfer directly to a queue or do you persist and lock it somehow first? In which format?
Then, when you read the quotetransfer from the queue, you use the checkoutworkflow class and create the actual sales-order entity?
All the best,
Florian
0 -
Propel\Runtime\Exception\PropelException -
Unable to execute INSERT statement
[INSERT INTO spy_sales_order
(id_sales_order, fk_locale, fk_sales_order_address_billing, currency_iso_code, customer_number, customer_reference, email, first_name, ips_quote_uuid, is_test, last_name, oms_processor_identifier, order_channel, order_reference, price_mode, salutation, store, created_at, updated_at) VALUES (:p0, :p1, :p2, :p3, :p4, :p5, :p6, :p7, :p8, :p9, :p10, :p11, :p12, :p13, :p14, :p15, :p16, :p17, :p18)] in "/data/src/Orm/Zed/Sales/Persistence/Base/SpySalesOrder.php::2591"
This happened again yesterday. I tried to hammer the spryker sequence script and it just didn't show any problems. The PgSql runs SELECTΒ FROM spy_sequence_number FOR UPDATE which should be a read and write lock.But we can confirm that it is not a late read of the same spy_sales_order and then trying to INSERT it again into the database but there where two orders with the same refrence number which should be impossible.
Our hoster tells us he sees the same error in other projects. Currently I am clueless how this could happen. There is no SQL replication or anything running that could cause a split brain situation.I am currently out of ideas here.
0 -
We are thinking about moving away from DB number generation because we don't care about a real sequence. But even if this would fix our problem I would feel a lot better if i knew how this could happen.
0
Categories
- All Categories
- 42 Getting Started & Guidelines
- 7 Getting Started in the Community
- 8 Additional Resources
- 7 Community Ideas and Feedback
- 92 Spryker News
- 1K Developer Corner
- 855 Spryker Development
- 93 Spryker Dev Environment
- 362 Spryker Releases
- 3 Oryx frontend framework
- 36 Propel ORM
- 68 Community Projects
- 3 Community Ideation Board
- 30 Hackathon
- 3 PHP Bridge
- 6 Gacela Project
- 35 Job Opportunities
- 3.2K π Slack Archives
- 116 Academy
- 5 Business Users
- 370 Docker
- 551 Slack General
- 2K Help
- 75 Knowledge Sharing
- 6 Random Stuff
- 4 Code Testing
- 34 Product & Business Questions
- 70 Spryker Safari Questions
- 51 Random