Skip to content

1.18.0

Choose a tag to compare

@spryker-release-bot spryker-release-bot released this 01 Apr 13:04
· 58 commits to master since this release

Included commits: 1.17.0...1.18.0

Improvements

  • Added Spryker\Zed\DataImport\Business\Model\DataSet\DataSetStepBrokerElasticBatchTransactionAware to be used for dynamic batch size of data import.

  • Added Spryker\Zed\DataImport\Business\Model\ElasticBatch\MemoryAllocatedElasticBatch to be used for control memory usage with isFull() and reset() methods.

  • Added Spryker\Zed\DataImport\Business\Model\Memory\PhpSystemMemory class which wraps PHP system functions to work with memory.

  • Added DataImportConstants::BULK_MODE_GRADUALITY_FACTOR constant to be used for configuration of gradual memory consumption algorithm.

  • Added DataImportConstants::BULK_MODE_MEMORY_THESHOLD_PERCENT constant to be used for configuration of how much percentage of allowed memory Bulk import can use (a way to avoid insufficient memory errors).

Project level configuration

Dynamic chunks for Bulk DataImport mode must be configured on project level. There is a list of steps required for configuration.

  • Configuration of Bulk mode on the project level could be done in the file config/Shared/config_default.php by settings settings
use Spryker\Shared\DataImport\DataImportConstants;

$config[DataImportConstants::BULK_MODE_GRADUALITY_FACTOR] = 5;
$config[DataImportConstants::BULK_MODE_MEMORY_THESHOLD_PERCENT] = 90;
  • Usage ofDataSetStepBrokerElasticBatchTransactionAware must be done via already existing method
    $dataSetStepBroker = $this->createElasticBatchTransactionAwareDataSetStepBroker();

  • Creation of DataSet writers must be done via plugins

$dataImporter->setDataSetWriter($this->createProductAbstractElasticDataImportWriters());
// ...
protected function createProductAbstractElasticDataImportWriters(): DataSetWriterInterface
{
    return new DataSetWriterCollection(
        [
            $this->createProductAbstractElasticBatchPdoWriterPlugin(),
        ],
    );
}

protected function createProductAbstractElasticBatchPdoWriterPlugin(): DataSetWriterPluginInterface
{
    return new ProductAbstractElasticBatchPdoWriterPlugin();
}
  • Writer Plugin must implement DataSetWriterPluginInterface and DataSetWriterPluginApplicableAwareInterface.
class ProductAbstractElasticBatchPdoWriterPlugin extends AbstractPlugin implements DataSetWriterPluginInterface, DataSetWriterPluginApplicableAwareInterface
{
    public function write(DataSetInterface $dataSet): void
    {
        $this->getFacade()->writeProductAbstractElasticBatchPdoDataSet($dataSet);
    }
    
    public function flush(): void
    {
        $this->getFacade()->flushProductAbstractElasticBatchPdoDataImporter();
    }
    
    public function isApplicable(): bool
    {
        return $this->getConfig()->isBulkEnabled();
    }
}
  • For plugin developer must implement all actual functionality in Facade like in example.
public function writeProductAbstractElasticBatchPdoDataSet(DataSetInterface $dataSet): void
{
    $this->getFactory()->createProductAbstractElasticBatchPdoWriter()->write($dataSet);
}

public function flushProductAbstractElasticBatchPdoDataImporter(): void
{
    $this->getFactory()->createProductAbstractElasticBatchPdoWriter()->flush();
}
  • Creating Elastic Batch writer consist of creating 2 methods in the Business Factory.
public function createProductAbstractElasticBatchPdoWriter(): DataSetWriterInterface
{
    $determineStrategy = new DatabaseDetermineStrategy(
        [
            $this->createProductAbstractElasticBatchPdoDataSetWriter(),
            $this->createProductAbstractElasticBatchPdoMariaDbDataSetWriter(),
        ],
    );

    return $determineStrategy->getApplicableDataSetWriter();
}

public function createProductAbstractElasticBatchPdoMariaDbDataSetWriter(): DataSetWriterInterface
{
    return new ProductAbstractElasticBatchPdoMariaDbDataSetWriter(
        $this->getConfig(),
        $this->createMemoryAllocatedElasticBatch(),
    );
}
  • Creating an implementation of Dataset writer consists of creating 2 classes: Abstract class and Concrete class with implementation of inserting data.
abstract class AbstractProductAbstractElasticBatchPdoDataSetWriter implements DataSetWriterInterface
{
}

class ProductAbstractElasticBatchPdoMariaDbDataSetWriter extends AbstractProductAbstractElasticBatchPdoDataSetWriter implements DataSetWriterInterface, ApplicableDatabaseEngineAwareInterface
{
}