Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

enh(metadata): Introduce a memory limit for metadata generation #42800

Merged
merged 1 commit into from
Aug 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions config/config.sample.php
Original file line number Diff line number Diff line change
Expand Up @@ -1373,6 +1373,15 @@
'OC\Preview\XBitmap',
],

/**
* Maximum file size for metadata generation.
* If a file exceeds this size, metadata generation will be skipped.
* Note: memory equivalent to this size will be used for metadata generation.
*
* Default: 256 megabytes.
*/
'metadata_max_filesize' => 256,

/**
* LDAP
*
Expand Down
14 changes: 14 additions & 0 deletions core/BackgroundJobs/GenerateMetadataJob.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,17 @@
use OCP\FilesMetadata\Exceptions\FilesMetadataNotFoundException;
use OCP\FilesMetadata\IFilesMetadataManager;
use OCP\IAppConfig;
use OCP\IConfig;
use OCP\IUserManager;
use Psr\Log\LoggerInterface;

class GenerateMetadataJob extends TimedJob {
// Default file size limit for metadata generation (MBytes).
protected const DEFAULT_MAX_FILESIZE = 256;

public function __construct(
ITimeFactory $time,
private IConfig $config,
private IAppConfig $appConfig,
private IRootFolder $rootFolder,
private IUserManager $userManager,
Expand Down Expand Up @@ -88,6 +93,15 @@ private function scanFolder(Folder $folder): void {
continue;
}

// Don't generate metadata for files bigger than configured metadata_max_filesize
// Files are loaded in memory so very big files can lead to an OOM on the server
$nodeSize = $node->getSize();
$nodeLimit = $this->config->getSystemValueInt('metadata_max_filesize', self::DEFAULT_MAX_FILESIZE);
if ($nodeSize > $nodeLimit * 1000000) {
$this->logger->debug("Skipping generating metadata for fileid " . $node->getId() . " as its size exceeds configured 'metadata_max_filesize'.");
continue;
}

Fixed Show fixed Hide fixed
try {
$this->filesMetadataManager->getMetadata($node->getId(), false);
} catch (FilesMetadataNotFoundException) {
Expand Down
Loading