Fix redundancy exceeding the limit
authorChocobozzz <me@florianbigard.com>
Mon, 12 Aug 2019 06:46:46 +0000 (08:46 +0200)
committerChocobozzz <me@florianbigard.com>
Mon, 12 Aug 2019 06:46:46 +0000 (08:46 +0200)
client/proxy.config.json
server/lib/schedulers/videos-redundancy-scheduler.ts
server/models/redundancy/video-redundancy.ts
server/tests/api/videos/multiple-servers.ts

index 81a0fc4c1d562f5c86decb0e89dec9407df138b5..e7070522af7fb499a600db04f8ce6031009a028d 100644 (file)
     "target": "http://localhost:9000",
     "secure": false
   },
+  "/lazy-static": {
+    "target": "http://localhost:9000",
+    "secure": false
+  },
   "/socket.io": {
     "target": "ws://localhost:9000",
     "secure": false,
index 90caed96d3ca920d298183a2302d4379082ee332..04f601bfb9266f8cd2ec693c38d813e75495737f 100644 (file)
@@ -105,7 +105,10 @@ export class VideosRedundancyScheduler extends AbstractScheduler {
   private async extendsRedundancy (redundancyModel: VideoRedundancyModel) {
     const redundancy = CONFIG.REDUNDANCY.VIDEOS.STRATEGIES.find(s => s.strategy === redundancyModel.strategy)
     // Redundancy strategy disabled, remove our redundancy instead of extending expiration
-    if (!redundancy) await removeVideoRedundancy(redundancyModel)
+    if (!redundancy) {
+      await removeVideoRedundancy(redundancyModel)
+      return
+    }
 
     await this.extendsExpirationOf(redundancyModel, redundancy.minLifetime)
   }
index eb2222256319a7c15ea939d03490fdae354e84c0..8621a5c6c1f83e23866caa63adbbf757659594fb 100644 (file)
@@ -325,23 +325,45 @@ export class VideoRedundancyModel extends Model<VideoRedundancyModel> {
 
   static async getTotalDuplicated (strategy: VideoRedundancyStrategy) {
     const actor = await getServerActor()
+    const redundancyInclude = {
+      attributes: [],
+      model: VideoRedundancyModel,
+      required: true,
+      where: {
+        actorId: actor.id,
+        strategy
+      }
+    }
 
-    const query: FindOptions = {
+    const queryFiles: FindOptions = {
+      include: [ redundancyInclude ]
+    }
+
+    const queryStreamingPlaylists: FindOptions = {
       include: [
         {
           attributes: [],
-          model: VideoRedundancyModel,
+          model: VideoModel.unscoped(),
           required: true,
-          where: {
-            actorId: actor.id,
-            strategy
-          }
+          include: [
+            {
+              attributes: [],
+              model: VideoStreamingPlaylistModel.unscoped(),
+              include: [
+                redundancyInclude
+              ]
+            }
+          ]
         }
       ]
     }
 
-    return VideoFileModel.aggregate('size', 'SUM', query)
-      .then(result => parseAggregateResult(result))
+    return Promise.all([
+      VideoFileModel.aggregate('size', 'SUM', queryFiles),
+      VideoFileModel.aggregate('size', 'SUM', queryStreamingPlaylists)
+    ]).then(([ r1, r2 ]) => {
+      return parseAggregateResult(r1) + parseAggregateResult(r2)
+    })
   }
 
   static async listLocalExpired () {
index 65176577601111daf1ff61e3e9e95f88a246b282..0169498e9ecf7bc2831c969b5e92abb04d4e74e5 100644 (file)
@@ -508,10 +508,8 @@ describe('Test multiple servers', function () {
 
       await wait(1000)
 
-      await Promise.all([
-        viewVideo(servers[2].url, localVideosServer3[0]),
-        viewVideo(servers[2].url, localVideosServer3[0])
-      ])
+      await viewVideo(servers[2].url, localVideosServer3[0])
+      await viewVideo(servers[2].url, localVideosServer3[0])
 
       await waitJobs(servers)