From 9a3db678f56eda37d222cf2d2232ae0ef5d533d2 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Tue, 2 May 2023 13:38:00 +0200 Subject: Fix import video file lock --- server/lib/job-queue/handlers/transcoding-job-builder.ts | 3 ++- server/lib/job-queue/handlers/video-import.ts | 7 ++++--- server/lib/job-queue/handlers/video-studio-edition.ts | 2 +- server/lib/transcoding/create-transcoding-job.ts | 1 + server/lib/transcoding/shared/job-builders/abstract-job-builder.ts | 1 + .../shared/job-builders/transcoding-job-queue-builder.ts | 7 +++++-- .../shared/job-builders/transcoding-runner-job-builder.ts | 7 +++++-- 7 files changed, 19 insertions(+), 9 deletions(-) diff --git a/server/lib/job-queue/handlers/transcoding-job-builder.ts b/server/lib/job-queue/handlers/transcoding-job-builder.ts index cb45337df..8621b109f 100644 --- a/server/lib/job-queue/handlers/transcoding-job-builder.ts +++ b/server/lib/job-queue/handlers/transcoding-job-builder.ts @@ -23,7 +23,8 @@ async function processTranscodingJobBuilder (job: Job) { video, videoFile, - user + user, + videoFileAlreadyLocked: false }) } diff --git a/server/lib/job-queue/handlers/video-import.ts b/server/lib/job-queue/handlers/video-import.ts index 2a063282c..cdd362f6e 100644 --- a/server/lib/job-queue/handlers/video-import.ts +++ b/server/lib/job-queue/handlers/video-import.ts @@ -242,7 +242,7 @@ async function processFile (downloader: () => Promise, videoImport: MVid }) }) - await afterImportSuccess({ videoImport: videoImportUpdated, video, videoFile, user: videoImport.User }) + await afterImportSuccess({ videoImport: videoImportUpdated, video, videoFile, user: videoImport.User, videoFileAlreadyLocked: true }) } finally { videoFileLockReleaser() } @@ -292,8 +292,9 @@ async function afterImportSuccess (options: { video: MVideoFullLight videoFile: MVideoFile user: MUserId + videoFileAlreadyLocked: boolean }) { - const { video, videoFile, videoImport, user } = options + const { video, videoFile, videoImport, user, videoFileAlreadyLocked } = options Notifier.Instance.notifyOnFinishedVideoImport({ videoImport: Object.assign(videoImport, { Video: video }), success: true }) @@ -313,7 +314,7 @@ async function afterImportSuccess (options: { } if (video.state === VideoState.TO_TRANSCODE) { // Create transcoding jobs? - await createOptimizeOrMergeAudioJobs({ video, videoFile, isNewVideo: true, user }) + await createOptimizeOrMergeAudioJobs({ video, videoFile, isNewVideo: true, user, videoFileAlreadyLocked }) } } diff --git a/server/lib/job-queue/handlers/video-studio-edition.ts b/server/lib/job-queue/handlers/video-studio-edition.ts index 991d11ef1..fbb55a388 100644 --- a/server/lib/job-queue/handlers/video-studio-edition.ts +++ b/server/lib/job-queue/handlers/video-studio-edition.ts @@ -95,7 +95,7 @@ async function processVideoStudioEdition (job: Job) { const user = await UserModel.loadByVideoId(video.id) - await createOptimizeOrMergeAudioJobs({ video, videoFile: newFile, isNewVideo: false, user }) + await createOptimizeOrMergeAudioJobs({ video, videoFile: newFile, isNewVideo: false, user, videoFileAlreadyLocked: false }) } // --------------------------------------------------------------------------- diff --git a/server/lib/transcoding/create-transcoding-job.ts b/server/lib/transcoding/create-transcoding-job.ts index 46831a912..abe32684d 100644 --- a/server/lib/transcoding/create-transcoding-job.ts +++ b/server/lib/transcoding/create-transcoding-job.ts @@ -7,6 +7,7 @@ export function createOptimizeOrMergeAudioJobs (options: { videoFile: MVideoFile isNewVideo: boolean user: MUserId + videoFileAlreadyLocked: boolean }) { return getJobBuilder().createOptimizeOrMergeAudioJobs(options) } diff --git a/server/lib/transcoding/shared/job-builders/abstract-job-builder.ts b/server/lib/transcoding/shared/job-builders/abstract-job-builder.ts index f1e9efdcf..576e786d5 100644 --- a/server/lib/transcoding/shared/job-builders/abstract-job-builder.ts +++ b/server/lib/transcoding/shared/job-builders/abstract-job-builder.ts @@ -10,6 +10,7 @@ export abstract class AbstractJobBuilder { videoFile: MVideoFile isNewVideo: boolean user: MUserId + videoFileAlreadyLocked: boolean }): Promise abstract createTranscodingJobs (options: { diff --git a/server/lib/transcoding/shared/job-builders/transcoding-job-queue-builder.ts b/server/lib/transcoding/shared/job-builders/transcoding-job-queue-builder.ts index c09c6b8ce..5a9c93ee5 100644 --- a/server/lib/transcoding/shared/job-builders/transcoding-job-queue-builder.ts +++ b/server/lib/transcoding/shared/job-builders/transcoding-job-queue-builder.ts @@ -27,13 +27,16 @@ export class TranscodingJobQueueBuilder extends AbstractJobBuilder { videoFile: MVideoFile isNewVideo: boolean user: MUserId + videoFileAlreadyLocked: boolean }) { - const { video, videoFile, isNewVideo, user } = options + const { video, videoFile, isNewVideo, user, videoFileAlreadyLocked } = options let mergeOrOptimizePayload: MergeAudioTranscodingPayload | OptimizeTranscodingPayload let nextTranscodingSequentialJobPayloads: (NewWebTorrentResolutionTranscodingPayload | HLSTranscodingPayload)[][] = [] - const mutexReleaser = await VideoPathManager.Instance.lockFiles(video.uuid) + const mutexReleaser = videoFileAlreadyLocked + ? () => {} + : await VideoPathManager.Instance.lockFiles(video.uuid) try { await VideoPathManager.Instance.makeAvailableVideoFile(videoFile.withVideoOrPlaylist(video), async videoFilePath => { diff --git a/server/lib/transcoding/shared/job-builders/transcoding-runner-job-builder.ts b/server/lib/transcoding/shared/job-builders/transcoding-runner-job-builder.ts index c7a63d2e2..274dce21b 100644 --- a/server/lib/transcoding/shared/job-builders/transcoding-runner-job-builder.ts +++ b/server/lib/transcoding/shared/job-builders/transcoding-runner-job-builder.ts @@ -26,10 +26,13 @@ export class TranscodingRunnerJobBuilder extends AbstractJobBuilder { videoFile: MVideoFile isNewVideo: boolean user: MUserId + videoFileAlreadyLocked: boolean }) { - const { video, videoFile, isNewVideo, user } = options + const { video, videoFile, isNewVideo, user, videoFileAlreadyLocked } = options - const mutexReleaser = await VideoPathManager.Instance.lockFiles(video.uuid) + const mutexReleaser = videoFileAlreadyLocked + ? () => {} + : await VideoPathManager.Instance.lockFiles(video.uuid) try { await VideoPathManager.Instance.makeAvailableVideoFile(videoFile.withVideoOrPlaylist(video), async videoFilePath => { -- cgit v1.2.3