/
githubmirror
/
magento2
Обзор
Документация
Войти
/
githubmirror
/
magento2
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
2.4-develop
lib/internal/Magento/Framework/Indexer/BatchSizeManagement.php
65 строк
2 KB
Alexandra Zota
ACP2E-4019: CE copyright updates for 2.4.9-beta1
22 окт 2025, 17:47
22 окт 2025, 17:47
1b769b7
Код
Авторство
О чём код?
<?php /** * Copyright 2017 Adobe * All Rights Reserved. */ namespace Magento\Framework\Indexer; /** * Class set MEMORY table size for indexer processes according batch size and index row size. */ class BatchSizeManagement implements \Magento\Framework\Indexer\BatchSizeManagementInterface { /** * @var \Magento\Framework\Indexer\IndexTableRowSizeEstimatorInterface */ private $rowSizeEstimator; /** * @var \Psr\Log\LoggerInterface */ private $logger; /** * CompositeProductBatchSizeCalculator constructor. * @param \Magento\Framework\Indexer\IndexTableRowSizeEstimatorInterface $rowSizeEstimator * @param \Psr\Log\LoggerInterface $logger */ public function __construct( \Magento\Framework\Indexer\IndexTableRowSizeEstimatorInterface $rowSizeEstimator, \Psr\Log\LoggerInterface $logger ) { $this->rowSizeEstimator = $rowSizeEstimator; $this->logger = $logger; } /** * @inheritdoc */ public function ensureBatchSize(\Magento\Framework\DB\Adapter\AdapterInterface $connection, $batchSize) { $rowMemory = $this->rowSizeEstimator->estimateRowSize(); $maxHeapTableSize = $connection->fetchOne('SELECT @@max_heap_table_size;'); $tmpTableSize = $connection->fetchOne('SELECT @@tmp_table_size;'); $bufferPoolSize = $connection->fetchOne('SELECT @@innodb_buffer_pool_size;'); $maxMemoryTableSize = min($maxHeapTableSize, $tmpTableSize); $size = (int) ($rowMemory * $batchSize); // Log warning if allocated memory for temp table greater than 20% of innodb_buffer_pool_size if ($size > $bufferPoolSize * .2) { $message = 'Memory size allocated for the temporary table is more than 20% of innodb_buffer_pool_size. ' . 'Please update innodb_buffer_pool_size or decrease batch size value '. '(which decreases memory usages for the temporary table). ' . 'Current batch size: %1; Allocated memory size: %2 bytes; InnoDB buffer pool size: %3 bytes.'; $this->logger->warning(new \Magento\Framework\Phrase($message, [$batchSize, $size, $bufferPoolSize])); } if ($maxMemoryTableSize < $size) { $connection->query('SET SESSION tmp_table_size = ' . $size . ';'); $connection->query('SET SESSION max_heap_table_size = ' . $size . ';'); } } }