diff options
author | Chocobozzz <me@florianbigard.com> | 2019-08-12 08:46:46 +0200 |
---|---|---|
committer | Chocobozzz <me@florianbigard.com> | 2019-08-12 08:46:46 +0200 |
commit | 0b353d1d8a659140d10b8f7bff3f114698c1a715 (patch) | |
tree | 4d6cadfff782baa8ec253898a20849d05f584733 /server | |
parent | e2600d8b261994abbbeb1ff921edaefd267fc122 (diff) | |
download | PeerTube-0b353d1d8a659140d10b8f7bff3f114698c1a715.tar.gz PeerTube-0b353d1d8a659140d10b8f7bff3f114698c1a715.tar.zst PeerTube-0b353d1d8a659140d10b8f7bff3f114698c1a715.zip |
Fix redundancy exceeding the limit
Diffstat (limited to 'server')
-rw-r--r-- | server/lib/schedulers/videos-redundancy-scheduler.ts | 5 | ||||
-rw-r--r-- | server/models/redundancy/video-redundancy.ts | 38 | ||||
-rw-r--r-- | server/tests/api/videos/multiple-servers.ts | 6 |
3 files changed, 36 insertions, 13 deletions
diff --git a/server/lib/schedulers/videos-redundancy-scheduler.ts b/server/lib/schedulers/videos-redundancy-scheduler.ts index 90caed96d..04f601bfb 100644 --- a/server/lib/schedulers/videos-redundancy-scheduler.ts +++ b/server/lib/schedulers/videos-redundancy-scheduler.ts | |||
@@ -105,7 +105,10 @@ export class VideosRedundancyScheduler extends AbstractScheduler { | |||
105 | private async extendsRedundancy (redundancyModel: VideoRedundancyModel) { | 105 | private async extendsRedundancy (redundancyModel: VideoRedundancyModel) { |
106 | const redundancy = CONFIG.REDUNDANCY.VIDEOS.STRATEGIES.find(s => s.strategy === redundancyModel.strategy) | 106 | const redundancy = CONFIG.REDUNDANCY.VIDEOS.STRATEGIES.find(s => s.strategy === redundancyModel.strategy) |
107 | // Redundancy strategy disabled, remove our redundancy instead of extending expiration | 107 | // Redundancy strategy disabled, remove our redundancy instead of extending expiration |
108 | if (!redundancy) await removeVideoRedundancy(redundancyModel) | 108 | if (!redundancy) { |
109 | await removeVideoRedundancy(redundancyModel) | ||
110 | return | ||
111 | } | ||
109 | 112 | ||
110 | await this.extendsExpirationOf(redundancyModel, redundancy.minLifetime) | 113 | await this.extendsExpirationOf(redundancyModel, redundancy.minLifetime) |
111 | } | 114 | } |
diff --git a/server/models/redundancy/video-redundancy.ts b/server/models/redundancy/video-redundancy.ts index eb2222256..8621a5c6c 100644 --- a/server/models/redundancy/video-redundancy.ts +++ b/server/models/redundancy/video-redundancy.ts | |||
@@ -325,23 +325,45 @@ export class VideoRedundancyModel extends Model<VideoRedundancyModel> { | |||
325 | 325 | ||
326 | static async getTotalDuplicated (strategy: VideoRedundancyStrategy) { | 326 | static async getTotalDuplicated (strategy: VideoRedundancyStrategy) { |
327 | const actor = await getServerActor() | 327 | const actor = await getServerActor() |
328 | const redundancyInclude = { | ||
329 | attributes: [], | ||
330 | model: VideoRedundancyModel, | ||
331 | required: true, | ||
332 | where: { | ||
333 | actorId: actor.id, | ||
334 | strategy | ||
335 | } | ||
336 | } | ||
328 | 337 | ||
329 | const query: FindOptions = { | 338 | const queryFiles: FindOptions = { |
339 | include: [ redundancyInclude ] | ||
340 | } | ||
341 | |||
342 | const queryStreamingPlaylists: FindOptions = { | ||
330 | include: [ | 343 | include: [ |
331 | { | 344 | { |
332 | attributes: [], | 345 | attributes: [], |
333 | model: VideoRedundancyModel, | 346 | model: VideoModel.unscoped(), |
334 | required: true, | 347 | required: true, |
335 | where: { | 348 | include: [ |
336 | actorId: actor.id, | 349 | { |
337 | strategy | 350 | attributes: [], |
338 | } | 351 | model: VideoStreamingPlaylistModel.unscoped(), |
352 | include: [ | ||
353 | redundancyInclude | ||
354 | ] | ||
355 | } | ||
356 | ] | ||
339 | } | 357 | } |
340 | ] | 358 | ] |
341 | } | 359 | } |
342 | 360 | ||
343 | return VideoFileModel.aggregate('size', 'SUM', query) | 361 | return Promise.all([ |
344 | .then(result => parseAggregateResult(result)) | 362 | VideoFileModel.aggregate('size', 'SUM', queryFiles), |
363 | VideoFileModel.aggregate('size', 'SUM', queryStreamingPlaylists) | ||
364 | ]).then(([ r1, r2 ]) => { | ||
365 | return parseAggregateResult(r1) + parseAggregateResult(r2) | ||
366 | }) | ||
345 | } | 367 | } |
346 | 368 | ||
347 | static async listLocalExpired () { | 369 | static async listLocalExpired () { |
diff --git a/server/tests/api/videos/multiple-servers.ts b/server/tests/api/videos/multiple-servers.ts index 651765776..0169498e9 100644 --- a/server/tests/api/videos/multiple-servers.ts +++ b/server/tests/api/videos/multiple-servers.ts | |||
@@ -508,10 +508,8 @@ describe('Test multiple servers', function () { | |||
508 | 508 | ||
509 | await wait(1000) | 509 | await wait(1000) |
510 | 510 | ||
511 | await Promise.all([ | 511 | await viewVideo(servers[2].url, localVideosServer3[0]) |
512 | viewVideo(servers[2].url, localVideosServer3[0]), | 512 | await viewVideo(servers[2].url, localVideosServer3[0]) |
513 | viewVideo(servers[2].url, localVideosServer3[0]) | ||
514 | ]) | ||
515 | 513 | ||
516 | await waitJobs(servers) | 514 | await waitJobs(servers) |
517 | 515 | ||