/** * Stores data into the filesystem and returns stored stats * * @param BackupJob $job * @param JobStats $jobStats * @param OutputInterface $output * @return array * @author Daniel Wendlandt */ private function storeData(BackupJob $job, JobStats $jobStats, OutputInterface $output) { $memoryAtSection = memory_get_usage(); $timeStartSection = microtime(true); $output->writeln('<info>*** Starting with data storing ***</info>' . PHP_EOL); $docCount = $this->elastic->getDocCountByIndexType($job->getHost(), $job->getPort()); $storedStats = array(); /** @var Index $index */ foreach ($job->getMappings()->getIndices() as $index) { if (0 === $docCount->getDocCount($index->getName())) { continue; } /** @var Type $type */ foreach ($index->getTypes() as $type) { $docsInType = $docCount->getDocCount($index->getName(), $type->getName()); if (0 === $docsInType) { continue; } $scrollId = $this->elastic->createScrollSearch($index->getName(), $type->getName(), $job->getHost(), $job->getPort()); $storedStats[$index->getName()][$type->getName()]['aggregatedNumberOfDocs'] = $docsInType; $storedStats[$index->getName()][$type->getName()]['storedNumberOfDocs'] = 0; $output->writeln('<comment>Store Data for: ' . $index->getName() . '/' . $type->getName() . '</comment>'); $progress = new ProgressBar($output, $docsInType); $progress->setFormat('debug'); $progress->display(); $progress->start(); while (true) { $data = $this->elastic->getScrollSearchData($scrollId, $job->getHost(), $job->getPort()); if (0 === count($data['hits'])) { break; } $scrollId = $data['scrollId']; $storedDocs = $this->filesystem->storeData($job->getPath(), $index->getName(), $type->getName(), $data['hits']); $storedStats[$index->getName()][$type->getName()]['storedNumberOfDocs'] += $storedDocs; $progress->advance($storedDocs); } $progress->finish(); $output->writeln(PHP_EOL); } } $jobStats->setStoreData(microtime(true) - $timeStartSection, memory_get_usage(), memory_get_usage() - $memoryAtSection, array('stats' => $storedStats)); return $storedStats; }
public function testGetScrollSearchData() { $version = '1.6.0'; $serverInfoData = $this->getServerInfoData($version); $scrollId = 'abcdef'; $scrollTimeUnit = '1m'; $data = ['_scroll_id' => 'abc']; $hits = [['_source' => []]]; $this->request = $this->getMockBuilder('Elastification\\Client\\Request\\V1x\\SearchScrollRequest')->disableOriginalConstructor()->getMock(); $this->response = $this->getMockBuilder('Elastification\\Client\\Response\\V1x\\SearchResponse')->disableOriginalConstructor()->getMock(); $this->serverInfoResponse->expects($this->exactly(3))->method('getData')->willReturn($serverInfoData); $this->request->expects($this->once())->method('setScroll')->with($scrollTimeUnit); $this->request->expects($this->once())->method('setScrollId')->with($scrollId); $this->response->expects($this->once())->method('getData')->willReturn($data); $this->response->expects($this->once())->method('getHitsHits')->willReturn($hits); $this->requestFactory->expects($this->once())->method('create')->with('SearchScrollRequest', $version, null, null, $this->serializer)->willReturn($this->request); $this->client->expects($this->exactly(2))->method('send')->withConsecutive($this->isInstanceOf('Elastification\\Client\\Request\\V1x\\NodeInfoRequest'), $this->isInstanceOf('Elastification\\Client\\Request\\V1x\\SearchRequest'))->willReturnOnConsecutiveCalls($this->serverInfoResponse, $this->response); $result = $this->repository->getScrollSearchData($scrollId, self::HOST, self::PORT, $scrollTimeUnit); $this->assertTrue(isset($result['scrollId'])); $this->assertTrue(isset($result['hits'])); $this->assertSame($data['_scroll_id'], $result['scrollId']); $this->assertSame($hits, $result['hits']); }