From 55b429e5e816bea33afbd810d5f1e4f560ef0069 Mon Sep 17 00:00:00 2001 From: Vasily Date: Thu, 5 Mar 2020 20:40:17 +0300 Subject: Moved migration routines to their own directory --- .../Routines/DisableTranscodingThrottling.cs | 32 ++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 Jellyfin.Server/Migrations/Routines/DisableTranscodingThrottling.cs (limited to 'Jellyfin.Server/Migrations/Routines/DisableTranscodingThrottling.cs') diff --git a/Jellyfin.Server/Migrations/Routines/DisableTranscodingThrottling.cs b/Jellyfin.Server/Migrations/Routines/DisableTranscodingThrottling.cs new file mode 100644 index 000000000..eff6469e2 --- /dev/null +++ b/Jellyfin.Server/Migrations/Routines/DisableTranscodingThrottling.cs @@ -0,0 +1,32 @@ +using System; +using System.IO; +using MediaBrowser.Common.Configuration; +using MediaBrowser.Model.Configuration; +using Microsoft.Extensions.Configuration; +using Microsoft.Extensions.Logging; + +namespace Jellyfin.Server.Migrations.Routines +{ + /// + /// Updater that takes care of bringing configuration up to 10.5.0 standards. + /// + internal class DisableTranscodingThrottling : IUpdater + { + /// + public string Name => "DisableTranscodingThrottling"; + + /// + public void Perform(CoreAppHost host, ILogger logger) + { + // Set EnableThrottling to false as it wasn't used before, and in 10.5.0 it may introduce issues + var encoding = ((IConfigurationManager)host.ServerConfigurationManager).GetConfiguration("encoding"); + if (encoding.EnableThrottling) + { + logger.LogInformation("Disabling transcoding throttling during migration"); + encoding.EnableThrottling = false; + + host.ServerConfigurationManager.SaveConfiguration("encoding", encoding); + } + } + } +} -- cgit v1.2.3 From 4c2b543b307b55b2220472c59396b9b4a604cfb7 Mon Sep 17 00:00:00 2001 From: Mark Monteiro Date: Fri, 6 Mar 2020 21:51:50 +0100 Subject: Rename IUpdater to IMigrationRoutine --- Jellyfin.Server/Migrations/IMigrationRoutine.cs | 23 ++++++++++++++++++++++ Jellyfin.Server/Migrations/IUpdater.cs | 23 ---------------------- Jellyfin.Server/Migrations/MigrationRunner.cs | 18 ++++++++--------- .../Routines/CreateUserLoggingConfigFile.cs | 2 +- .../Routines/DisableTranscodingThrottling.cs | 2 +- 5 files changed, 34 insertions(+), 34 deletions(-) create mode 100644 Jellyfin.Server/Migrations/IMigrationRoutine.cs delete mode 100644 Jellyfin.Server/Migrations/IUpdater.cs (limited to 'Jellyfin.Server/Migrations/Routines/DisableTranscodingThrottling.cs') diff --git a/Jellyfin.Server/Migrations/IMigrationRoutine.cs b/Jellyfin.Server/Migrations/IMigrationRoutine.cs new file mode 100644 index 000000000..20a3aa3d6 --- /dev/null +++ b/Jellyfin.Server/Migrations/IMigrationRoutine.cs @@ -0,0 +1,23 @@ +using System; +using Microsoft.Extensions.Logging; + +namespace Jellyfin.Server.Migrations +{ + /// + /// Interface that describes a migration routine. + /// + internal interface IMigrationRoutine + { + /// + /// Gets the name of the migration, must be unique. + /// + public string Name { get; } + + /// + /// Execute the migration routine. + /// + /// Host that hosts current version. + /// Host logger. + public void Perform(CoreAppHost host, ILogger logger); + } +} diff --git a/Jellyfin.Server/Migrations/IUpdater.cs b/Jellyfin.Server/Migrations/IUpdater.cs deleted file mode 100644 index 9b749841c..000000000 --- a/Jellyfin.Server/Migrations/IUpdater.cs +++ /dev/null @@ -1,23 +0,0 @@ -using System; -using Microsoft.Extensions.Logging; - -namespace Jellyfin.Server.Migrations -{ - /// - /// Interface that descibes a migration routine. - /// - internal interface IUpdater - { - /// - /// Gets the name of the migration, must be unique. - /// - public abstract string Name { get; } - - /// - /// Execute the migration routine. - /// - /// Host that hosts current version. - /// Host logger. - public abstract void Perform(CoreAppHost host, ILogger logger); - } -} diff --git a/Jellyfin.Server/Migrations/MigrationRunner.cs b/Jellyfin.Server/Migrations/MigrationRunner.cs index ac7f3d77a..8e786f34e 100644 --- a/Jellyfin.Server/Migrations/MigrationRunner.cs +++ b/Jellyfin.Server/Migrations/MigrationRunner.cs @@ -13,7 +13,7 @@ namespace Jellyfin.Server.Migrations /// /// The list of known migrations, in order of applicability. /// - internal static readonly IUpdater[] Migrations = + internal static readonly IMigrationRoutine[] Migrations = { new Routines.DisableTranscodingThrottling(), new Routines.CreateUserLoggingConfigFile() @@ -43,26 +43,26 @@ namespace Jellyfin.Server.Migrations for (var i = 0; i < Migrations.Length; i++) { - var updater = Migrations[i]; - if (applied.Contains(updater.Name)) + var migrationRoutine = Migrations[i]; + if (applied.Contains(migrationRoutine.Name)) { - logger.LogDebug("Skipping migration {Name} as it is already applied", updater.Name); + logger.LogDebug("Skipping migration {Name} as it is already applied", migrationRoutine.Name); continue; } - logger.LogInformation("Applying migration {Name}", updater.Name); + logger.LogInformation("Applying migration {Name}", migrationRoutine.Name); try { - updater.Perform(host, logger); + migrationRoutine.Perform(host, logger); } catch (Exception ex) { - logger.LogError(ex, "Cannot apply migration {Name}", updater.Name); + logger.LogError(ex, "Cannot apply migration {Name}", migrationRoutine.Name); continue; } - logger.LogInformation("Migration {Name} applied successfully", updater.Name); - applied.Add(updater.Name); + logger.LogInformation("Migration {Name} applied successfully", migrationRoutine.Name); + applied.Add(migrationRoutine.Name); } if (applied.Count > migrationOptions.Applied.Length) diff --git a/Jellyfin.Server/Migrations/Routines/CreateUserLoggingConfigFile.cs b/Jellyfin.Server/Migrations/Routines/CreateUserLoggingConfigFile.cs index 7a089680e..6dbeb2776 100644 --- a/Jellyfin.Server/Migrations/Routines/CreateUserLoggingConfigFile.cs +++ b/Jellyfin.Server/Migrations/Routines/CreateUserLoggingConfigFile.cs @@ -13,7 +13,7 @@ namespace Jellyfin.Server.Migrations.Routines /// If the deprecated logging.json file exists and has a custom config, it will be used as logging.user.json, /// otherwise a blank file will be created. /// - internal class CreateUserLoggingConfigFile : IUpdater + internal class CreateUserLoggingConfigFile : IMigrationRoutine { /// /// An empty logging JSON configuration, which will be used as the default contents for the user settings config file. diff --git a/Jellyfin.Server/Migrations/Routines/DisableTranscodingThrottling.cs b/Jellyfin.Server/Migrations/Routines/DisableTranscodingThrottling.cs index eff6469e2..db0bef885 100644 --- a/Jellyfin.Server/Migrations/Routines/DisableTranscodingThrottling.cs +++ b/Jellyfin.Server/Migrations/Routines/DisableTranscodingThrottling.cs @@ -10,7 +10,7 @@ namespace Jellyfin.Server.Migrations.Routines /// /// Updater that takes care of bringing configuration up to 10.5.0 standards. /// - internal class DisableTranscodingThrottling : IUpdater + internal class DisableTranscodingThrottling : IMigrationRoutine { /// public string Name => "DisableTranscodingThrottling"; -- cgit v1.2.3 From 1295f6c79bdf76274501838c9e42094e4b1dd3c0 Mon Sep 17 00:00:00 2001 From: Mark Monteiro Date: Sat, 7 Mar 2020 20:18:45 +0100 Subject: Documentation and log message cleanup --- Jellyfin.Server/Migrations/MigrationOptions.cs | 2 +- Jellyfin.Server/Migrations/MigrationRunner.cs | 10 +++++----- Jellyfin.Server/Migrations/MigrationsFactory.cs | 2 +- .../Migrations/Routines/DisableTranscodingThrottling.cs | 4 ++-- 4 files changed, 9 insertions(+), 9 deletions(-) (limited to 'Jellyfin.Server/Migrations/Routines/DisableTranscodingThrottling.cs') diff --git a/Jellyfin.Server/Migrations/MigrationOptions.cs b/Jellyfin.Server/Migrations/MigrationOptions.cs index b96288cc1..6b7831158 100644 --- a/Jellyfin.Server/Migrations/MigrationOptions.cs +++ b/Jellyfin.Server/Migrations/MigrationOptions.cs @@ -15,7 +15,7 @@ namespace Jellyfin.Server.Migrations #pragma warning disable CA1819 // Properties should not return arrays /// - /// Gets or sets he list of applied migration routine names. + /// Gets or sets the list of applied migration routine names. /// public string[] Applied { get; set; } #pragma warning restore CA1819 // Properties should not return arrays diff --git a/Jellyfin.Server/Migrations/MigrationRunner.cs b/Jellyfin.Server/Migrations/MigrationRunner.cs index 15c1e75aa..ca4c79cfd 100644 --- a/Jellyfin.Server/Migrations/MigrationRunner.cs +++ b/Jellyfin.Server/Migrations/MigrationRunner.cs @@ -6,7 +6,7 @@ using Microsoft.Extensions.Logging; namespace Jellyfin.Server.Migrations { /// - /// The class that knows how migrate between different Jellyfin versions. + /// The class that knows which migrations to apply and how to apply them. /// public sealed class MigrationRunner { @@ -45,22 +45,22 @@ namespace Jellyfin.Server.Migrations var updater = Migrations[i]; if (applied.Contains(updater.Name)) { - logger.LogDebug("Skipping migration {Name} as it is already applied", updater.Name); + logger.LogDebug("Skipping migration '{Name}' since it is already applied", updater.Name); continue; } - logger.LogInformation("Applying migration {Name}", updater.Name); + logger.LogInformation("Applying migration '{Name}'", updater.Name); try { updater.Perform(host, logger); } catch (Exception ex) { - logger.LogError(ex, "Cannot apply migration {Name}", updater.Name); + logger.LogError(ex, "Could not apply migration '{Name}'", updater.Name); throw; } - logger.LogInformation("Migration {Name} applied successfully", updater.Name); + logger.LogInformation("Migration '{Name}' applied successfully", updater.Name); applied.Add(updater.Name); } diff --git a/Jellyfin.Server/Migrations/MigrationsFactory.cs b/Jellyfin.Server/Migrations/MigrationsFactory.cs index ed01dc646..23c1b1ee6 100644 --- a/Jellyfin.Server/Migrations/MigrationsFactory.cs +++ b/Jellyfin.Server/Migrations/MigrationsFactory.cs @@ -4,7 +4,7 @@ using MediaBrowser.Common.Configuration; namespace Jellyfin.Server.Migrations { /// - /// A factory that teachs Jellyfin how to find a peristent file which lists all applied migrations. + /// A factory that can find a persistent file of the migration configuration, which lists all applied migrations. /// public class MigrationsFactory : IConfigurationFactory { diff --git a/Jellyfin.Server/Migrations/Routines/DisableTranscodingThrottling.cs b/Jellyfin.Server/Migrations/Routines/DisableTranscodingThrottling.cs index eff6469e2..936c3640e 100644 --- a/Jellyfin.Server/Migrations/Routines/DisableTranscodingThrottling.cs +++ b/Jellyfin.Server/Migrations/Routines/DisableTranscodingThrottling.cs @@ -8,7 +8,7 @@ using Microsoft.Extensions.Logging; namespace Jellyfin.Server.Migrations.Routines { /// - /// Updater that takes care of bringing configuration up to 10.5.0 standards. + /// Disable transcode throttling for all installations since it is currently broken for certain video formats. /// internal class DisableTranscodingThrottling : IUpdater { @@ -18,7 +18,7 @@ namespace Jellyfin.Server.Migrations.Routines /// public void Perform(CoreAppHost host, ILogger logger) { - // Set EnableThrottling to false as it wasn't used before, and in 10.5.0 it may introduce issues + // Set EnableThrottling to false since it wasn't used before and may introduce issues var encoding = ((IConfigurationManager)host.ServerConfigurationManager).GetConfiguration("encoding"); if (encoding.EnableThrottling) { -- cgit v1.2.3 From 72bf920291d1c486aaf66544ccd6eb64c13e254b Mon Sep 17 00:00:00 2001 From: Mark Monteiro Date: Sun, 8 Mar 2020 16:05:31 +0100 Subject: Use a Guid to uniquely identify migrations instead of a string name Also use a list instead of an array to store executed migrations in the configuration class --- Jellyfin.Server/Migrations/IMigrationRoutine.cs | 7 ++++++- Jellyfin.Server/Migrations/MigrationOptions.cs | 11 ++++++----- Jellyfin.Server/Migrations/MigrationRunner.cs | 11 ++++------- .../Migrations/Routines/CreateUserLoggingConfigFile.cs | 3 +++ .../Migrations/Routines/DisableTranscodingThrottling.cs | 3 +++ 5 files changed, 22 insertions(+), 13 deletions(-) (limited to 'Jellyfin.Server/Migrations/Routines/DisableTranscodingThrottling.cs') diff --git a/Jellyfin.Server/Migrations/IMigrationRoutine.cs b/Jellyfin.Server/Migrations/IMigrationRoutine.cs index 20a3aa3d6..eab995d67 100644 --- a/Jellyfin.Server/Migrations/IMigrationRoutine.cs +++ b/Jellyfin.Server/Migrations/IMigrationRoutine.cs @@ -9,7 +9,12 @@ namespace Jellyfin.Server.Migrations internal interface IMigrationRoutine { /// - /// Gets the name of the migration, must be unique. + /// Gets the unique id for this migration. This should never be modified after the migration has been created. + /// + public Guid Id { get; } + + /// + /// Gets the display name of the migration. /// public string Name { get; } diff --git a/Jellyfin.Server/Migrations/MigrationOptions.cs b/Jellyfin.Server/Migrations/MigrationOptions.cs index 6b7831158..d95354145 100644 --- a/Jellyfin.Server/Migrations/MigrationOptions.cs +++ b/Jellyfin.Server/Migrations/MigrationOptions.cs @@ -1,3 +1,6 @@ +using System; +using System.Collections.Generic; + namespace Jellyfin.Server.Migrations { /// @@ -10,14 +13,12 @@ namespace Jellyfin.Server.Migrations /// public MigrationOptions() { - Applied = System.Array.Empty(); + Applied = new List(); } -#pragma warning disable CA1819 // Properties should not return arrays /// - /// Gets or sets the list of applied migration routine names. + /// Gets the list of applied migration routine names. /// - public string[] Applied { get; set; } -#pragma warning restore CA1819 // Properties should not return arrays + public List Applied { get; } } } diff --git a/Jellyfin.Server/Migrations/MigrationRunner.cs b/Jellyfin.Server/Migrations/MigrationRunner.cs index 821f51c02..2081143d2 100644 --- a/Jellyfin.Server/Migrations/MigrationRunner.cs +++ b/Jellyfin.Server/Migrations/MigrationRunner.cs @@ -29,22 +29,20 @@ namespace Jellyfin.Server.Migrations var logger = loggerFactory.CreateLogger(); var migrationOptions = ((IConfigurationManager)host.ServerConfigurationManager).GetConfiguration(MigrationsListStore.StoreKey); - if (!host.ServerConfigurationManager.Configuration.IsStartupWizardCompleted && migrationOptions.Applied.Length == 0) + if (!host.ServerConfigurationManager.Configuration.IsStartupWizardCompleted && migrationOptions.Applied.Count == 0) { // If startup wizard is not finished, this is a fresh install. // Don't run any migrations, just mark all of them as applied. logger.LogInformation("Marking all known migrations as applied because this is fresh install"); - migrationOptions.Applied = Migrations.Select(m => m.Name).ToArray(); + migrationOptions.Applied.AddRange(Migrations.Select(m => m.Id)); host.ServerConfigurationManager.SaveConfiguration(MigrationsListStore.StoreKey, migrationOptions); return; } - var applied = migrationOptions.Applied.ToList(); - for (var i = 0; i < Migrations.Length; i++) { var migrationRoutine = Migrations[i]; - if (applied.Contains(migrationRoutine.Name)) + if (migrationOptions.Applied.Contains(migrationRoutine.Id)) { logger.LogDebug("Skipping migration '{Name}' since it is already applied", migrationRoutine.Name); continue; @@ -64,8 +62,7 @@ namespace Jellyfin.Server.Migrations // Mark the migration as completed logger.LogInformation("Migration '{Name}' applied successfully", migrationRoutine.Name); - applied.Add(migrationRoutine.Name); - migrationOptions.Applied = applied.ToArray(); + migrationOptions.Applied.Add(migrationRoutine.Id); host.ServerConfigurationManager.SaveConfiguration(MigrationsListStore.StoreKey, migrationOptions); logger.LogDebug("Migration '{Name}' marked as applied in configuration.", migrationRoutine.Name); } diff --git a/Jellyfin.Server/Migrations/Routines/CreateUserLoggingConfigFile.cs b/Jellyfin.Server/Migrations/Routines/CreateUserLoggingConfigFile.cs index 834099ea0..3bc32c047 100644 --- a/Jellyfin.Server/Migrations/Routines/CreateUserLoggingConfigFile.cs +++ b/Jellyfin.Server/Migrations/Routines/CreateUserLoggingConfigFile.cs @@ -36,6 +36,9 @@ namespace Jellyfin.Server.Migrations.Routines @"{""Serilog"":{""MinimumLevel"":""Information"",""WriteTo"":[{""Name"":""Console"",""Args"":{""outputTemplate"":""[{Timestamp:HH:mm:ss}] [{Level:u3}] [{ThreadId}] {SourceContext}: {Message:lj}{NewLine}{Exception}""}},{""Name"":""Async"",""Args"":{""configure"":[{""Name"":""File"",""Args"":{""path"":""%JELLYFIN_LOG_DIR%//log_.log"",""rollingInterval"":""Day"",""retainedFileCountLimit"":3,""rollOnFileSizeLimit"":true,""fileSizeLimitBytes"":100000000,""outputTemplate"":""[{Timestamp:yyyy-MM-dd HH:mm:ss.fff zzz}] [{Level:u3}] [{ThreadId}] {SourceContext}:{Message}{NewLine}{Exception}""}}]}}],""Enrich"":[""FromLogContext"",""WithThreadId""]}}", }; + /// + public Guid Id => Guid.Parse("{EF103419-8451-40D8-9F34-D1A8E93A1679}"); + /// public string Name => "CreateLoggingConfigHeirarchy"; diff --git a/Jellyfin.Server/Migrations/Routines/DisableTranscodingThrottling.cs b/Jellyfin.Server/Migrations/Routines/DisableTranscodingThrottling.cs index 279e7bbea..673f0e415 100644 --- a/Jellyfin.Server/Migrations/Routines/DisableTranscodingThrottling.cs +++ b/Jellyfin.Server/Migrations/Routines/DisableTranscodingThrottling.cs @@ -12,6 +12,9 @@ namespace Jellyfin.Server.Migrations.Routines /// internal class DisableTranscodingThrottling : IMigrationRoutine { + /// + public Guid Id => Guid.Parse("{4124C2CD-E939-4FFB-9BE9-9B311C413638}"); + /// public string Name => "DisableTranscodingThrottling"; -- cgit v1.2.3