aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/lib
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2022-10-25 14:18:59 +0200
committerChocobozzz <me@florianbigard.com>2022-10-25 14:18:59 +0200
commitaa887096f9a305568dc3a846d0c9cdf7e45f1c67 (patch)
tree5dc455d680ebdd24644ebe29b2f129afb903b421 /server/lib
parent508c1b1e9f3b26752a961e945b7fa59b72b30827 (diff)
downloadPeerTube-aa887096f9a305568dc3a846d0c9cdf7e45f1c67.tar.gz
PeerTube-aa887096f9a305568dc3a846d0c9cdf7e45f1c67.tar.zst
PeerTube-aa887096f9a305568dc3a846d0c9cdf7e45f1c67.zip
Correctly delete live files from object storage
Diffstat (limited to 'server/lib')
-rw-r--r--server/lib/live/live-utils.ts6
-rw-r--r--server/lib/live/shared/muxing-session.ts4
-rw-r--r--server/lib/object-storage/shared/object-storage-helpers.ts9
-rw-r--r--server/lib/object-storage/videos.ts16
4 files changed, 27 insertions, 8 deletions
diff --git a/server/lib/live/live-utils.ts b/server/lib/live/live-utils.ts
index d2b8e3a55..c0dec9829 100644
--- a/server/lib/live/live-utils.ts
+++ b/server/lib/live/live-utils.ts
@@ -3,7 +3,7 @@ import { basename, join } from 'path'
3import { logger } from '@server/helpers/logger' 3import { logger } from '@server/helpers/logger'
4import { MStreamingPlaylist, MStreamingPlaylistVideo, MVideo } from '@server/types/models' 4import { MStreamingPlaylist, MStreamingPlaylistVideo, MVideo } from '@server/types/models'
5import { VideoStorage } from '@shared/models' 5import { VideoStorage } from '@shared/models'
6import { listHLSFileKeysOf, removeHLSFileObjectStorage, removeHLSObjectStorage } from '../object-storage' 6import { listHLSFileKeysOf, removeHLSFileObjectStorageByFullKey, removeHLSObjectStorage } from '../object-storage'
7import { getLiveDirectory } from '../paths' 7import { getLiveDirectory } from '../paths'
8 8
9function buildConcatenatedName (segmentOrPlaylistPath: string) { 9function buildConcatenatedName (segmentOrPlaylistPath: string) {
@@ -77,11 +77,13 @@ async function cleanupTMPLiveFilesFromFilesystem (video: MVideo) {
77async function cleanupTMPLiveFilesFromObjectStorage (streamingPlaylist: MStreamingPlaylistVideo) { 77async function cleanupTMPLiveFilesFromObjectStorage (streamingPlaylist: MStreamingPlaylistVideo) {
78 if (streamingPlaylist.storage !== VideoStorage.OBJECT_STORAGE) return 78 if (streamingPlaylist.storage !== VideoStorage.OBJECT_STORAGE) return
79 79
80 logger.info('Cleanup TMP live files from object storage for %s.', streamingPlaylist.Video.uuid)
81
80 const keys = await listHLSFileKeysOf(streamingPlaylist) 82 const keys = await listHLSFileKeysOf(streamingPlaylist)
81 83
82 for (const key of keys) { 84 for (const key of keys) {
83 if (isTMPLiveFile(key)) { 85 if (isTMPLiveFile(key)) {
84 await removeHLSFileObjectStorage(streamingPlaylist, key) 86 await removeHLSFileObjectStorageByFullKey(key)
85 } 87 }
86 } 88 }
87} 89}
diff --git a/server/lib/live/shared/muxing-session.ts b/server/lib/live/shared/muxing-session.ts
index 64add2611..6ec126955 100644
--- a/server/lib/live/shared/muxing-session.ts
+++ b/server/lib/live/shared/muxing-session.ts
@@ -10,7 +10,7 @@ import { getLiveMuxingCommand, getLiveTranscodingCommand } from '@server/helpers
10import { logger, loggerTagsFactory, LoggerTagsFn } from '@server/helpers/logger' 10import { logger, loggerTagsFactory, LoggerTagsFn } from '@server/helpers/logger'
11import { CONFIG } from '@server/initializers/config' 11import { CONFIG } from '@server/initializers/config'
12import { MEMOIZE_TTL, VIDEO_LIVE } from '@server/initializers/constants' 12import { MEMOIZE_TTL, VIDEO_LIVE } from '@server/initializers/constants'
13import { removeHLSFileObjectStorage, storeHLSFileFromFilename, storeHLSFileFromPath } from '@server/lib/object-storage' 13import { removeHLSFileObjectStorageByPath, storeHLSFileFromFilename, storeHLSFileFromPath } from '@server/lib/object-storage'
14import { VideoFileModel } from '@server/models/video/video-file' 14import { VideoFileModel } from '@server/models/video/video-file'
15import { MStreamingPlaylistVideo, MUserId, MVideoLiveVideo } from '@server/types/models' 15import { MStreamingPlaylistVideo, MUserId, MVideoLiveVideo } from '@server/types/models'
16import { VideoStorage } from '@shared/models' 16import { VideoStorage } from '@shared/models'
@@ -341,7 +341,7 @@ class MuxingSession extends EventEmitter {
341 341
342 if (this.streamingPlaylist.storage === VideoStorage.OBJECT_STORAGE) { 342 if (this.streamingPlaylist.storage === VideoStorage.OBJECT_STORAGE) {
343 try { 343 try {
344 await removeHLSFileObjectStorage(this.streamingPlaylist, segmentPath) 344 await removeHLSFileObjectStorageByPath(this.streamingPlaylist, segmentPath)
345 } catch (err) { 345 } catch (err) {
346 logger.error('Cannot remove segment %s from object storage', segmentPath, { err, ...this.lTags() }) 346 logger.error('Cannot remove segment %s from object storage', segmentPath, { err, ...this.lTags() })
347 } 347 }
diff --git a/server/lib/object-storage/shared/object-storage-helpers.ts b/server/lib/object-storage/shared/object-storage-helpers.ts
index d13c25798..3046d76bc 100644
--- a/server/lib/object-storage/shared/object-storage-helpers.ts
+++ b/server/lib/object-storage/shared/object-storage-helpers.ts
@@ -110,11 +110,15 @@ function updatePrefixACL (options: {
110function removeObject (objectStorageKey: string, bucketInfo: BucketInfo) { 110function removeObject (objectStorageKey: string, bucketInfo: BucketInfo) {
111 const key = buildKey(objectStorageKey, bucketInfo) 111 const key = buildKey(objectStorageKey, bucketInfo)
112 112
113 logger.debug('Removing file %s in bucket %s', key, bucketInfo.BUCKET_NAME, lTags()) 113 return removeObjectByFullKey(key, bucketInfo)
114}
115
116function removeObjectByFullKey (fullKey: string, bucketInfo: BucketInfo) {
117 logger.debug('Removing file %s in bucket %s', fullKey, bucketInfo.BUCKET_NAME, lTags())
114 118
115 const command = new DeleteObjectCommand({ 119 const command = new DeleteObjectCommand({
116 Bucket: bucketInfo.BUCKET_NAME, 120 Bucket: bucketInfo.BUCKET_NAME,
117 Key: key 121 Key: fullKey
118 }) 122 })
119 123
120 return getClient().send(command) 124 return getClient().send(command)
@@ -195,6 +199,7 @@ export {
195 storeObject, 199 storeObject,
196 200
197 removeObject, 201 removeObject,
202 removeObjectByFullKey,
198 removePrefix, 203 removePrefix,
199 204
200 makeAvailable, 205 makeAvailable,
diff --git a/server/lib/object-storage/videos.ts b/server/lib/object-storage/videos.ts
index 003807826..b764e4b22 100644
--- a/server/lib/object-storage/videos.ts
+++ b/server/lib/object-storage/videos.ts
@@ -11,6 +11,7 @@ import {
11 lTags, 11 lTags,
12 makeAvailable, 12 makeAvailable,
13 removeObject, 13 removeObject,
14 removeObjectByFullKey,
14 removePrefix, 15 removePrefix,
15 storeObject, 16 storeObject,
16 updateObjectACL, 17 updateObjectACL,
@@ -76,10 +77,18 @@ function removeHLSObjectStorage (playlist: MStreamingPlaylistVideo) {
76 return removePrefix(generateHLSObjectBaseStorageKey(playlist), CONFIG.OBJECT_STORAGE.STREAMING_PLAYLISTS) 77 return removePrefix(generateHLSObjectBaseStorageKey(playlist), CONFIG.OBJECT_STORAGE.STREAMING_PLAYLISTS)
77} 78}
78 79
79function removeHLSFileObjectStorage (playlist: MStreamingPlaylistVideo, filename: string) { 80function removeHLSFileObjectStorageByFilename (playlist: MStreamingPlaylistVideo, filename: string) {
80 return removeObject(generateHLSObjectStorageKey(playlist, filename), CONFIG.OBJECT_STORAGE.STREAMING_PLAYLISTS) 81 return removeObject(generateHLSObjectStorageKey(playlist, filename), CONFIG.OBJECT_STORAGE.STREAMING_PLAYLISTS)
81} 82}
82 83
84function removeHLSFileObjectStorageByPath (playlist: MStreamingPlaylistVideo, path: string) {
85 return removeObject(generateHLSObjectStorageKey(playlist, basename(path)), CONFIG.OBJECT_STORAGE.STREAMING_PLAYLISTS)
86}
87
88function removeHLSFileObjectStorageByFullKey (key: string) {
89 return removeObjectByFullKey(key, CONFIG.OBJECT_STORAGE.STREAMING_PLAYLISTS)
90}
91
83// --------------------------------------------------------------------------- 92// ---------------------------------------------------------------------------
84 93
85function removeWebTorrentObjectStorage (videoFile: MVideoFile) { 94function removeWebTorrentObjectStorage (videoFile: MVideoFile) {
@@ -162,7 +171,10 @@ export {
162 updateHLSFilesACL, 171 updateHLSFilesACL,
163 172
164 removeHLSObjectStorage, 173 removeHLSObjectStorage,
165 removeHLSFileObjectStorage, 174 removeHLSFileObjectStorageByFilename,
175 removeHLSFileObjectStorageByPath,
176 removeHLSFileObjectStorageByFullKey,
177
166 removeWebTorrentObjectStorage, 178 removeWebTorrentObjectStorage,
167 179
168 makeWebTorrentFileAvailable, 180 makeWebTorrentFileAvailable,