diff options
author | kontrollanten <6680299+kontrollanten@users.noreply.github.com> | 2021-11-09 11:05:35 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-11-09 11:05:35 +0100 |
commit | e1ab52d7ec7370a6f9f5937192d6003206af1ac0 (patch) | |
tree | aecc8b696b0021e073fd205dd6e126fb4f178e8f /server/lib | |
parent | c49c366ac320fe5ac3dc08f5891fe5898c1b34e3 (diff) | |
download | PeerTube-e1ab52d7ec7370a6f9f5937192d6003206af1ac0.tar.gz PeerTube-e1ab52d7ec7370a6f9f5937192d6003206af1ac0.tar.zst PeerTube-e1ab52d7ec7370a6f9f5937192d6003206af1ac0.zip |
Add migrate-to-object-storage script (#4481)
* add migrate-to-object-storage-script
closes #4467
* add migrate-to-unique-playlist-filenames script
* fix(migrate-to-unique-playlist-filenames): update master/segments256
run updateMasterHLSPlaylist and updateSha256VODSegments after
file rename.
* Improve move to object storage scripts
* PR remarks
Co-authored-by: Chocobozzz <me@florianbigard.com>
Diffstat (limited to 'server/lib')
-rw-r--r-- | server/lib/hls.ts | 6 | ||||
-rw-r--r-- | server/lib/job-queue/job-queue.ts | 8 | ||||
-rw-r--r-- | server/lib/video-state.ts | 38 |
3 files changed, 33 insertions, 19 deletions
diff --git a/server/lib/hls.ts b/server/lib/hls.ts index 0828a2d0f..8160e7949 100644 --- a/server/lib/hls.ts +++ b/server/lib/hls.ts | |||
@@ -1,7 +1,7 @@ | |||
1 | import { close, ensureDir, move, open, outputJSON, read, readFile, remove, stat, writeFile } from 'fs-extra' | 1 | import { close, ensureDir, move, open, outputJSON, read, readFile, remove, stat, writeFile } from 'fs-extra' |
2 | import { flatten, uniq } from 'lodash' | 2 | import { flatten, uniq } from 'lodash' |
3 | import { basename, dirname, join } from 'path' | 3 | import { basename, dirname, join } from 'path' |
4 | import { MStreamingPlaylistFilesVideo, MVideoWithFile } from '@server/types/models' | 4 | import { MStreamingPlaylistFilesVideo, MVideo, MVideoUUID } from '@server/types/models' |
5 | import { sha256 } from '../helpers/core-utils' | 5 | import { sha256 } from '../helpers/core-utils' |
6 | import { getAudioStreamCodec, getVideoStreamCodec, getVideoStreamSize } from '../helpers/ffprobe-utils' | 6 | import { getAudioStreamCodec, getVideoStreamCodec, getVideoStreamSize } from '../helpers/ffprobe-utils' |
7 | import { logger } from '../helpers/logger' | 7 | import { logger } from '../helpers/logger' |
@@ -31,7 +31,7 @@ async function updateStreamingPlaylistsInfohashesIfNeeded () { | |||
31 | } | 31 | } |
32 | } | 32 | } |
33 | 33 | ||
34 | async function updateMasterHLSPlaylist (video: MVideoWithFile, playlist: MStreamingPlaylistFilesVideo) { | 34 | async function updateMasterHLSPlaylist (video: MVideo, playlist: MStreamingPlaylistFilesVideo) { |
35 | const masterPlaylists: string[] = [ '#EXTM3U', '#EXT-X-VERSION:3' ] | 35 | const masterPlaylists: string[] = [ '#EXTM3U', '#EXT-X-VERSION:3' ] |
36 | 36 | ||
37 | for (const file of playlist.VideoFiles) { | 37 | for (const file of playlist.VideoFiles) { |
@@ -63,7 +63,7 @@ async function updateMasterHLSPlaylist (video: MVideoWithFile, playlist: MStream | |||
63 | }) | 63 | }) |
64 | } | 64 | } |
65 | 65 | ||
66 | async function updateSha256VODSegments (video: MVideoWithFile, playlist: MStreamingPlaylistFilesVideo) { | 66 | async function updateSha256VODSegments (video: MVideoUUID, playlist: MStreamingPlaylistFilesVideo) { |
67 | const json: { [filename: string]: { [range: string]: string } } = {} | 67 | const json: { [filename: string]: { [range: string]: string } } = {} |
68 | 68 | ||
69 | // For all the resolutions available for this video | 69 | // For all the resolutions available for this video |
diff --git a/server/lib/job-queue/job-queue.ts b/server/lib/job-queue/job-queue.ts index 53d6b6a9c..0eab720d9 100644 --- a/server/lib/job-queue/job-queue.ts +++ b/server/lib/job-queue/job-queue.ts | |||
@@ -108,7 +108,7 @@ class JobQueue { | |||
108 | private constructor () { | 108 | private constructor () { |
109 | } | 109 | } |
110 | 110 | ||
111 | init () { | 111 | init (produceOnly = false) { |
112 | // Already initialized | 112 | // Already initialized |
113 | if (this.initialized === true) return | 113 | if (this.initialized === true) return |
114 | this.initialized = true | 114 | this.initialized = true |
@@ -124,6 +124,12 @@ class JobQueue { | |||
124 | 124 | ||
125 | for (const handlerName of (Object.keys(handlers) as JobType[])) { | 125 | for (const handlerName of (Object.keys(handlers) as JobType[])) { |
126 | const queue = new Bull(handlerName, queueOptions) | 126 | const queue = new Bull(handlerName, queueOptions) |
127 | |||
128 | if (produceOnly) { | ||
129 | queue.pause(true) | ||
130 | .catch(err => logger.error('Cannot pause queue %s in produced only job queue', handlerName, { err })) | ||
131 | } | ||
132 | |||
127 | const handler = handlers[handlerName] | 133 | const handler = handlers[handlerName] |
128 | 134 | ||
129 | queue.process(this.getJobConcurrency(handlerName), handler) | 135 | queue.process(this.getJobConcurrency(handlerName), handler) |
diff --git a/server/lib/video-state.ts b/server/lib/video-state.ts index 9352a67d1..d5bbbec43 100644 --- a/server/lib/video-state.ts +++ b/server/lib/video-state.ts | |||
@@ -57,10 +57,33 @@ function moveToNextState (video: MVideoUUID, isNewVideo = true) { | |||
57 | }) | 57 | }) |
58 | } | 58 | } |
59 | 59 | ||
60 | async function moveToExternalStorageState (video: MVideoFullLight, isNewVideo: boolean, transaction: Transaction) { | ||
61 | const videoJobInfo = await VideoJobInfoModel.load(video.id, transaction) | ||
62 | const pendingTranscode = videoJobInfo?.pendingTranscode || 0 | ||
63 | |||
64 | // We want to wait all transcoding jobs before moving the video on an external storage | ||
65 | if (pendingTranscode !== 0) return false | ||
66 | |||
67 | await video.setNewState(VideoState.TO_MOVE_TO_EXTERNAL_STORAGE, isNewVideo, transaction) | ||
68 | |||
69 | logger.info('Creating external storage move job for video %s.', video.uuid, { tags: [ video.uuid ] }) | ||
70 | |||
71 | try { | ||
72 | await addMoveToObjectStorageJob(video, isNewVideo) | ||
73 | |||
74 | return true | ||
75 | } catch (err) { | ||
76 | logger.error('Cannot add move to object storage job', { err }) | ||
77 | |||
78 | return false | ||
79 | } | ||
80 | } | ||
81 | |||
60 | // --------------------------------------------------------------------------- | 82 | // --------------------------------------------------------------------------- |
61 | 83 | ||
62 | export { | 84 | export { |
63 | buildNextVideoState, | 85 | buildNextVideoState, |
86 | moveToExternalStorageState, | ||
64 | moveToNextState | 87 | moveToNextState |
65 | } | 88 | } |
66 | 89 | ||
@@ -82,18 +105,3 @@ async function moveToPublishedState (video: MVideoFullLight, isNewVideo: boolean | |||
82 | Notifier.Instance.notifyOnVideoPublishedAfterTranscoding(video) | 105 | Notifier.Instance.notifyOnVideoPublishedAfterTranscoding(video) |
83 | } | 106 | } |
84 | } | 107 | } |
85 | |||
86 | async function moveToExternalStorageState (video: MVideoFullLight, isNewVideo: boolean, transaction: Transaction) { | ||
87 | const videoJobInfo = await VideoJobInfoModel.load(video.id, transaction) | ||
88 | const pendingTranscode = videoJobInfo?.pendingTranscode || 0 | ||
89 | |||
90 | // We want to wait all transcoding jobs before moving the video on an external storage | ||
91 | if (pendingTranscode !== 0) return | ||
92 | |||
93 | await video.setNewState(VideoState.TO_MOVE_TO_EXTERNAL_STORAGE, isNewVideo, transaction) | ||
94 | |||
95 | logger.info('Creating external storage move job for video %s.', video.uuid, { tags: [ video.uuid ] }) | ||
96 | |||
97 | addMoveToObjectStorageJob(video, isNewVideo) | ||
98 | .catch(err => logger.error('Cannot add move to object storage job', { err })) | ||
99 | } | ||