Skip to content

Commit 6a93b31

Browse files
committed
Avoid locking up the metadata dumper if it builds a big backlog, fixes #1606
1 parent fd9fa03 commit 6a93b31

File tree

2 files changed

+15
-11
lines changed

2 files changed

+15
-11
lines changed

src/Command/DumpPackagesV2Command.php

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
use Symfony\Component\Console\Input\InputInterface;
2323
use Symfony\Component\Console\Input\InputOption;
2424
use Symfony\Component\Console\Output\OutputInterface;
25+
use Graze\DogStatsD\Client as StatsDClient;
2526

2627
/**
2728
* @author Jordi Boggiano <[email protected]>
@@ -30,17 +31,15 @@ class DumpPackagesV2Command extends Command
3031
{
3132
use \App\Util\DoctrineTrait;
3233

33-
private V2Dumper $dumper;
34-
private Locker $locker;
35-
private ManagerRegistry $doctrine;
36-
private string $cacheDir;
37-
38-
public function __construct(V2Dumper $dumper, Locker $locker, ManagerRegistry $doctrine, string $cacheDir, private Logger $logger)
34+
public function __construct(
35+
private V2Dumper $dumper,
36+
private Locker $locker,
37+
private ManagerRegistry $doctrine,
38+
private string $cacheDir,
39+
private Logger $logger,
40+
private StatsDClient $statsd,
41+
)
3942
{
40-
$this->dumper = $dumper;
41-
$this->locker = $locker;
42-
$this->doctrine = $doctrine;
43-
$this->cacheDir = $cacheDir;
4443
parent::__construct();
4544
}
4645

@@ -105,6 +104,11 @@ protected function execute(InputInterface $input, OutputInterface $output): int
105104
$ids = $this->getEM()->getConnection()->fetchFirstColumn('SELECT id FROM package WHERE frozen IS NULL ORDER BY id ASC');
106105
} else {
107106
$ids = $this->getEM()->getRepository(Package::class)->getStalePackagesForDumpingV2();
107+
$this->statsd->gauge('packagist.metadata_dump_queue', \count($ids));
108+
if (\count($ids) > 2000) {
109+
$this->logger->emergency('Huge backlog in packages to be dumped is abnormal', ['count' => \count($ids)]);
110+
$ids = array_slice($ids, 0, 2000);
111+
}
108112
}
109113

110114
if ($ids || $force) {

src/Package/V2Dumper.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@ public function dump(array $packageIds, bool $force = false, bool $verbose = fal
181181
}
182182

183183
// Verify all written files match CDN versions
184-
if (!empty($this->writtenFiles) && !$force) {
184+
if (!empty($this->writtenFiles) && !$force && \count($this->writtenFiles) < 50) {
185185
if ($verbose) {
186186
echo 'Verifying ' . count($this->writtenFiles) . ' written files match CDN versions'.\PHP_EOL;
187187
}

0 commit comments

Comments
 (0)