magento / magento2

Prior to making any Submission(s), you must sign an Adobe Contributor License Agreement, available here at: https://opensource.adobe.com/cla.html. All Submissions you make to Adobe Inc. and its affiliates, assigns and subsidiaries (collectively “Adobe”) are subject to the terms of the Adobe Contributor License Agreement.
http://www.magento.com
Open Software License 3.0
11.47k stars 9.28k forks source link

Queue Management Issue (DB MQ) #37559

Closed makkoff closed 1 year ago

makkoff commented 1 year ago

Preconditions and environment

Steps to reproduce

Note: Can reproduce this issue only at magneto cloud staging environment since there we use slave connection to the DB.

  1. Proceed to checkout
  2. Click on "Place Order" button

Expected result

The order was placed and the inventory.reservations.updateSalabilityStatus queue was successfully added

Actual result

Getting the error: image

the inventory.reservations.updateSalabilityStatus queue fails because the \Magento\MysqlMq\Model\ResourceModel\Queue::saveMessage returns 0 instead of the last insert id(message id).

I added a rewrite for Magento\ResourceConnections\DB\Adapter\Pdo\MysqlProxy to log the last insert IDs of slave and master connections:

image

And here is the result: [2023-05-30T12:47:36.737265+00:00] db_queue_logger.DEBUG: CONNECTIONS LOG: [] [] [2023-05-30T12:47:36.737307+00:00] db_queue_logger.DEBUG: MASTER Connection last insert ID - 9312 [] [] [2023-05-30T12:47:36.737347+00:00] db_queue_logger.DEBUG: MASTER Connection last insert ID with "queue" table - 9312 [] [] [2023-05-30T12:47:36.737387+00:00] db_queue_logger.DEBUG: SLAVE Connection last insert ID - 0 [] [] [2023-05-30T12:47:36.737425+00:00] db_queue_logger.DEBUG: SLAVE Connection last insert ID with "queue" table - 0

Additional information

DB query log: ...

      2023-05-25 15:04:45
        QUERY
          SQL: INSERT  INTO `queue_message_status` (`queue_id`,`message_id`,`status`) VALUES (?, ?, ?)
    BIND: array (
  0 => '44',
  1 => '0',
  2 => 2,
) 
   TIME: 0.0011
TRACE: #1 Magento\Framework\DB\Logger\File[Magento\Framework\DB\Logger\LoggerAbstract]#00000000000001300000000000000000#->getStats('query', 'INSERT  INTO `qu...', array(44, 0, 2), NULL) called at [vendor/magento/framework/DB/Logger/File.php:67]
#2 Magento\Framework\DB\Logger\File#00000000000001300000000000000000#->logStats('query', 'INSERT  INTO `qu...', array(44, 0, 2), NULL) called at [vendor/magento/framework/DB/Logger/LoggerProxy.php:152]
#3 Magento\Framework\DB\Logger\LoggerProxy#000000000000010c0000000000000000#->logStats('query', 'INSERT  INTO `qu...', array(44, 0, 2)) called at [vendor/magento/framework/DB/Adapter/Pdo/Mysql.php:597]
#4 Magento\Framework\DB\Adapter\Pdo\Mysql\Interceptor[Magento\Framework\DB\Adapter\Pdo\Mysql]#00000000000010830000000000000000#->_query('INSERT  INTO `qu...', array(44, 0, 2)) called at [vendor/magento/framework/DB/Adapter/Pdo/Mysql.php:634]
#5 Magento\Framework\DB\Adapter\Pdo\Mysql\Interceptor[Magento\Framework\DB\Adapter\Pdo\Mysql]#00000000000010830000000000000000#->query('INSERT  INTO `qu...', array(44, 0, 2)) called at [vendor/magento/framework/DB/Adapter/Pdo/Mysql.php:2125]
#6 Magento\Framework\DB\Adapter\Pdo\Mysql\Interceptor[Magento\Framework\DB\Adapter\Pdo\Mysql]#00000000000010830000000000000000#->insertArray('queue_message_st...', array('queue_id', 'message_id', 'status'), array(array(44, 0, 2)), 0) called at [vendor/magento/module-resource-connections/DB/Adapter/Pdo/MysqlProxy.php:609]
#7 Magento\ResourceConnections\DB\Adapter\Pdo\MysqlProxy\Interceptor[Magento\ResourceConnections\DB\Adapter\Pdo\MysqlProxy]#000000000000010f0000000000000000#->insertArray('queue_message_st...', array('queue_id', 'message_id', 'status'), array(array(44, 0, 2))) called at [vendor/magento/module-mysql-mq/Model/ResourceModel/Queue.php:98]
#8 Magento\MysqlMq\Model\ResourceModel\Queue#000000000000140f0000000000000000#->linkMessagesWithQueues(array(0), array('inventory.reserv...')) called at [vendor/magento/module-mysql-mq/Model/ResourceModel/Queue.php:72]
#9 Magento\MysqlMq\Model\ResourceModel\Queue#000000000000140f0000000000000000#->linkQueues(0, array('inventory.reserv...')) called at [vendor/magento/module-mysql-mq/Model/QueueManagement.php:89]
#10 Magento\MysqlMq\Model\QueueManagement#00000000000014110000000000000000#->addMessageToQueues('inventory.reserv...', '{"skus":["Macboo...', array('inventory.reserv...')) called at [vendor/magento/module-mysql-mq/Model/Driver/Exchange.php:73]
#11 Magento\MysqlMq\Model\Driver\Exchange#00000000000014120000000000000000#->enqueue('inventory.reserv...', &Magento\Framework\MessageQueue\Envelope#00000000000013e90000000000000000#) called at [vendor/magento/framework-message-queue/Publisher.php:95]
#12 Magento\Framework\MessageQueue\Publisher#0000000000000fb50000000000000000#->publish('inventory.reserv...', '{"skus":["Macboo...') called at [vendor/magento/framework-message-queue/PublisherPool.php:89]
#13 Magento\Framework\MessageQueue\PublisherPool#0000000000000fb40000000000000000#->publish('inventory.reserv...', &Magento\InventoryIndexer\Model\Queue\ReservationData#00000000000013e30000000000000000#) called at [vendor/magento/module-inventory-indexer/Plugin/InventorySales/EnqueueAfterPlaceReservationsForSalesEvent.php:77]
#14 

...

   2023-05-25 15:04:45
    EXCEPTION
    PDOException: SQLSTATE[23000]: Integrity constraint violation: 1452 Cannot add or update a child row: a foreign key constraint fails (`{magento cloud project id}`.`queue_message_status`, CONSTRAINT `QUEUE_MESSAGE_STATUS_MESSAGE_ID_QUEUE_MESSAGE_ID` FOREIGN KEY (`message_id`) REFERENCES `queue_message` (`id`) ON DELETE CASCADE) in /app/{magento cloud project id}/vendor/magento/framework/DB/Statement/Pdo/Mysql.php:90
    Stack trace:
    #0 /app/{magento cloud project id}/vendor/magento/framework/DB/Statement/Pdo/Mysql.php(90): PDOStatement->execute(Array)
    #1 /app/{magento cloud project id}/vendor/magento/framework/DB/Statement/Pdo/Mysql.php(106): Magento\Framework\DB\Statement\Pdo\Mysql->Magento\Framework\DB\Statement\Pdo\{closure}()
    #2 /app/{magento cloud project id}/vendor/magento/framework/DB/Statement/Pdo/Mysql.php(91): Magento\Framework\DB\Statement\Pdo\Mysql->tryExecute(Object(Closure))
    #3 /app/{magento cloud project id}/vendor/magento/zend-db/library/Zend/Db/Statement.php(313): Magento\Framework\DB\Statement\Pdo\Mysql->_execute(Array)
    #4 /app/{magento cloud project id}/vendor/magento/zend-db/library/Zend/Db/Adapter/Abstract.php(480): Zend_Db_Statement->execute(Array)
    #5 /app/{magento cloud project id}/vendor/magento/zend-db/library/Zend/Db/Adapter/Pdo/Abstract.php(238): Zend_Db_Adapter_Abstract->query('INSERT  INTO `q...', Array)
    #6 /app/{magento cloud project id}/vendor/magento/framework/DB/Adapter/Pdo/Mysql.php(564): Zend_Db_Adapter_Pdo_Abstract->query('INSERT  INTO `q...', Array)
    #7 /app/{magento cloud project id}/vendor/magento/framework/DB/Adapter/Pdo/Mysql.php(634): Magento\Framework\DB\Adapter\Pdo\Mysql->_query('INSERT  INTO `q...', Array)
    #8 /app/{magento cloud project id}/vendor/magento/framework/DB/Adapter/Pdo/Mysql.php(2125): Magento\Framework\DB\Adapter\Pdo\Mysql->query('INSERT  INTO `q...', Array)
    #9 /app/{magento cloud project id}/vendor/magento/module-resource-connections/DB/Adapter/Pdo/MysqlProxy.php(609): Magento\Framework\DB\Adapter\Pdo\Mysql->insertArray('queue_message_s...', Array, Array, 0)
    #10 /app/{magento cloud project id}/vendor/magento/module-mysql-mq/Model/ResourceModel/Queue.php(98): Magento\ResourceConnections\DB\Adapter\Pdo\MysqlProxy->insertArray('queue_message_s...', Array, Array)
    #11 /app/{magento cloud project id}/vendor/magento/module-mysql-mq/Model/ResourceModel/Queue.php(72): Magento\MysqlMq\Model\ResourceModel\Queue->linkMessagesWithQueues(Array, Array)
    #12 /app/{magento cloud project id}/vendor/magento/module-mysql-mq/Model/QueueManagement.php(89): Magento\MysqlMq\Model\ResourceModel\Queue->linkQueues('0', Array)
    #13 /app/{magento cloud project id}/vendor/magento/module-mysql-mq/Model/Driver/Exchange.php(73): Magento\MysqlMq\Model\QueueManagement->addMessageToQueues('inventory.reser...', '{"skus":["Macbo...', Array)
    #14 /app/{magento cloud project id}/vendor/magento/framework-message-queue/Publisher.php(95): Magento\MysqlMq\Model\Driver\Exchange->enqueue('inventory.reser...', Object(Magento\Framework\MessageQueue\Envelope))
    #15 /app/{magento cloud project id}/vendor/magento/framework-message-queue/PublisherPool.php(89): Magento\Framework\MessageQueue\Publisher->publish('inventory.reser...', '{"skus":["Macbo...')
    #16 /app/{magento cloud project id}/vendor/magento/module-inventory-indexer/Plugin/InventorySales/EnqueueAfterPlaceReservationsForSalesEvent.php(77): Magento\Framework\MessageQueue\PublisherPool->publish('invent`

Release note

This part of code was changed in 2.4.6 \Magento\ResourceConnections\DB\Adapter\Pdo\MysqlProxy::selectConnection

image

Triage and priority

m2-assistant[bot] commented 1 year ago

Hi @makkoff. Thank you for your report. To speed up processing of this issue, make sure that the issue is reproducible on the vanilla Magento instance following Steps to reproduce. To deploy vanilla Magento instance on our environment, Add a comment to the issue:

m2-assistant[bot] commented 1 year ago

Hi @engcom-Bravo. Thank you for working on this issue. In order to make sure that issue has enough information and ready for development, please read and check the following instruction: :point_down:

engcom-Bravo commented 1 year ago

Hi @makkoff,

Thank you for reporting and collaboration.

Verified the issue on Magento 2.4.6 cloud instance and the issue is not reproducible.Kindly refer the attached video.

Steps to reproduce

We are able to place the order successfully.

https://github.com/magento/magento2/assets/51680745/436c8aac-1cf4-48a6-bc12-f7d845219542

Kindly recheck the behaviour on Magento 2.4.6 cloud instance and elaborate steps to reproduce if the issue is still reproducible.

Thanks.

engcom-Bravo commented 1 year ago

Hi @makkoff,

Kindly provide us latest update on this https://github.com/magento/magento2/issues/37559#issuecomment-1587220412 you are able to reproduce the issue or still working on this issue and also please let us know if we are missing anything.

Thanks.

engcom-Bravo commented 1 year ago

Hi @makkoff,

We have noticed that this issue has not been updated since long time.
Hence we assume that this issue is fixed now, so we are closing it. Please feel to raise a fresh ticket or reopen this ticket if you need more assistance on this.

Thanks.