From 66e11879efcd2a77476ca9704fa938e89776956c Mon Sep 17 00:00:00 2001 From: Vasily Date: Thu, 5 Mar 2020 18:21:27 +0300 Subject: [PATCH 01/10] Shuffle migrations in a more manageable structure --- Jellyfin.Server/CoreAppHost.cs | 2 +- Jellyfin.Server/Migrations.cs | 92 ------------------- Jellyfin.Server/Migrations/IUpdater.cs | 26 ++++++ Jellyfin.Server/Migrations/MigrationRunner.cs | 46 ++++++++++ Jellyfin.Server/Migrations/Pre_10_5.cs | 33 +++++++ 5 files changed, 106 insertions(+), 93 deletions(-) delete mode 100644 Jellyfin.Server/Migrations.cs create mode 100644 Jellyfin.Server/Migrations/IUpdater.cs create mode 100644 Jellyfin.Server/Migrations/MigrationRunner.cs create mode 100644 Jellyfin.Server/Migrations/Pre_10_5.cs diff --git a/Jellyfin.Server/CoreAppHost.cs b/Jellyfin.Server/CoreAppHost.cs index cd5a2ce853..7f4bd3dea2 100644 --- a/Jellyfin.Server/CoreAppHost.cs +++ b/Jellyfin.Server/CoreAppHost.cs @@ -69,7 +69,7 @@ namespace Jellyfin.Server case 1: Logger.LogWarning("Version check shows Jellyfin was updated: previous version={0}, current version={1}", previousVersion, ApplicationVersion); - Migrations.Run(this, Logger); + Migrations.MigrationRunner.Run(this, Logger); ConfigurationManager.CommonConfiguration.PreviousVersion = ApplicationVersion; ConfigurationManager.SaveConfiguration(); diff --git a/Jellyfin.Server/Migrations.cs b/Jellyfin.Server/Migrations.cs deleted file mode 100644 index 95fea4ea55..0000000000 --- a/Jellyfin.Server/Migrations.cs +++ /dev/null @@ -1,92 +0,0 @@ -using System; -using System.Collections.Generic; -using MediaBrowser.Common.Configuration; -using MediaBrowser.Model.Configuration; -using Microsoft.Extensions.Logging; - -namespace Jellyfin.Server -{ - /// - /// The class that knows how migrate between different Jellyfin versions. - /// - internal static class Migrations - { - private static readonly IUpdater[] _migrations = - { - new Pre10_5() - }; - - /// - /// Interface that descibes a migration routine. - /// - private interface IUpdater - { - /// - /// Gets maximum version this Updater applies to. - /// If current version is greater or equal to it, skip the updater. - /// - public abstract Version Maximum { get; } - - /// - /// Execute the migration from version "from". - /// - /// Host that hosts current version. - /// Host logger. - /// Version to migrate from. - /// Whether configuration was changed. - public abstract bool Perform(CoreAppHost host, ILogger logger, Version from); - } - - /// - /// Run all needed migrations. - /// - /// CoreAppHost that hosts current version. - /// AppHost logger. - /// Whether anything was changed. - public static bool Run(CoreAppHost host, ILogger logger) - { - bool updated = false; - var version = host.ServerConfigurationManager.CommonConfiguration.PreviousVersion; - - for (var i = 0; i < _migrations.Length; i++) - { - var updater = _migrations[i]; - if (version.CompareTo(updater.Maximum) >= 0) - { - logger.LogDebug("Skipping updater {0} as current version {1} >= its maximum applicable version {2}", updater, version, updater.Maximum); - continue; - } - - if (updater.Perform(host, logger, version)) - { - updated = true; - } - - version = updater.Maximum; - } - - return updated; - } - - private class Pre10_5 : IUpdater - { - public Version Maximum { get => Version.Parse("10.5.0"); } - - public bool Perform(CoreAppHost host, ILogger logger, Version from) - { - // 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); - return true; - } - - return false; - } - } - } -} diff --git a/Jellyfin.Server/Migrations/IUpdater.cs b/Jellyfin.Server/Migrations/IUpdater.cs new file mode 100644 index 0000000000..60d9702567 --- /dev/null +++ b/Jellyfin.Server/Migrations/IUpdater.cs @@ -0,0 +1,26 @@ +using System; +using Microsoft.Extensions.Logging; + +namespace Jellyfin.Server.Migrations +{ + /// + /// Interface that descibes a migration routine. + /// + internal interface IUpdater + { + /// + /// Gets maximum version this Updater applies to. + /// If current version is greater or equal to it, skip the updater. + /// + public abstract Version Maximum { get; } + + /// + /// Execute the migration from version "from". + /// + /// Host that hosts current version. + /// Host logger. + /// Version to migrate from. + /// Whether configuration was changed. + public abstract bool Perform(CoreAppHost host, ILogger logger, Version from); + } +} diff --git a/Jellyfin.Server/Migrations/MigrationRunner.cs b/Jellyfin.Server/Migrations/MigrationRunner.cs new file mode 100644 index 0000000000..ad54fa38e6 --- /dev/null +++ b/Jellyfin.Server/Migrations/MigrationRunner.cs @@ -0,0 +1,46 @@ +using Microsoft.Extensions.Logging; + +namespace Jellyfin.Server.Migrations +{ + /// + /// The class that knows how migrate between different Jellyfin versions. + /// + public static class MigrationRunner + { + private static readonly IUpdater[] _migrations = + { + new Pre_10_5() + }; + + /// + /// Run all needed migrations. + /// + /// CoreAppHost that hosts current version. + /// AppHost logger. + /// Whether anything was changed. + public static bool Run(CoreAppHost host, ILogger logger) + { + bool updated = false; + var version = host.ServerConfigurationManager.CommonConfiguration.PreviousVersion; + + for (var i = 0; i < _migrations.Length; i++) + { + var updater = _migrations[i]; + if (version.CompareTo(updater.Maximum) >= 0) + { + logger.LogDebug("Skipping updater {0} as current version {1} >= its maximum applicable version {2}", updater, version, updater.Maximum); + continue; + } + + if (updater.Perform(host, logger, version)) + { + updated = true; + } + + version = updater.Maximum; + } + + return updated; + } + } +} diff --git a/Jellyfin.Server/Migrations/Pre_10_5.cs b/Jellyfin.Server/Migrations/Pre_10_5.cs new file mode 100644 index 0000000000..5389a2ad98 --- /dev/null +++ b/Jellyfin.Server/Migrations/Pre_10_5.cs @@ -0,0 +1,33 @@ +using System; +using MediaBrowser.Common.Configuration; +using MediaBrowser.Model.Configuration; +using Microsoft.Extensions.Logging; + +namespace Jellyfin.Server.Migrations +{ + /// + /// Updater that takes care of bringing configuration up to 10.5.0 standards. + /// + internal class Pre_10_5 : IUpdater + { + /// + public Version Maximum { get => Version.Parse("10.5.0"); } + + /// + public bool Perform(CoreAppHost host, ILogger logger, Version from) + { + // 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); + return true; + } + + return false; + } + } +} From ecaa7f8014666a474c87481471ce7cda7006165a Mon Sep 17 00:00:00 2001 From: Vasily Date: Thu, 5 Mar 2020 20:09:33 +0300 Subject: [PATCH 02/10] Improve migration logic --- Jellyfin.Server/CoreAppHost.cs | 28 ----------- ...0_5.cs => DisableTranscodingThrottling.cs} | 11 ++--- .../Migrations/DisableZealousLogging.cs | 29 +++++++++++ Jellyfin.Server/Migrations/IUpdater.cs | 31 ++++++------ .../Migrations/MigrationOptions.cs | 23 +++++++++ Jellyfin.Server/Migrations/MigrationRunner.cs | 49 +++++++++++++------ .../Migrations/MigrationsFactory.cs | 20 ++++++++ .../Migrations/MigrationsListStore.cs | 19 +++++++ Jellyfin.Server/Program.cs | 11 +++-- 9 files changed, 151 insertions(+), 70 deletions(-) rename Jellyfin.Server/Migrations/{Pre_10_5.cs => DisableTranscodingThrottling.cs} (79%) create mode 100644 Jellyfin.Server/Migrations/DisableZealousLogging.cs create mode 100644 Jellyfin.Server/Migrations/MigrationOptions.cs create mode 100644 Jellyfin.Server/Migrations/MigrationsFactory.cs create mode 100644 Jellyfin.Server/Migrations/MigrationsListStore.cs diff --git a/Jellyfin.Server/CoreAppHost.cs b/Jellyfin.Server/CoreAppHost.cs index 7f4bd3dea2..8b4b61e290 100644 --- a/Jellyfin.Server/CoreAppHost.cs +++ b/Jellyfin.Server/CoreAppHost.cs @@ -57,33 +57,5 @@ namespace Jellyfin.Server /// protected override void ShutdownInternal() => Program.Shutdown(); - - /// - /// Runs the migration routines if necessary. - /// - public void TryMigrate() - { - var previousVersion = ConfigurationManager.CommonConfiguration.PreviousVersion; - switch (ApplicationVersion.CompareTo(previousVersion)) - { - case 1: - Logger.LogWarning("Version check shows Jellyfin was updated: previous version={0}, current version={1}", previousVersion, ApplicationVersion); - - Migrations.MigrationRunner.Run(this, Logger); - - ConfigurationManager.CommonConfiguration.PreviousVersion = ApplicationVersion; - ConfigurationManager.SaveConfiguration(); - break; - case 0: - // nothing to do, versions match - break; - case -1: - Logger.LogWarning("Version check shows Jellyfin was rolled back, use at your own risk: previous version={0}, current version={1}", previousVersion, ApplicationVersion); - // no "rollback" routines for now - ConfigurationManager.CommonConfiguration.PreviousVersion = ApplicationVersion; - ConfigurationManager.SaveConfiguration(); - break; - } - } } } diff --git a/Jellyfin.Server/Migrations/Pre_10_5.cs b/Jellyfin.Server/Migrations/DisableTranscodingThrottling.cs similarity index 79% rename from Jellyfin.Server/Migrations/Pre_10_5.cs rename to Jellyfin.Server/Migrations/DisableTranscodingThrottling.cs index 5389a2ad98..83624bdadd 100644 --- a/Jellyfin.Server/Migrations/Pre_10_5.cs +++ b/Jellyfin.Server/Migrations/DisableTranscodingThrottling.cs @@ -1,6 +1,8 @@ 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 @@ -8,13 +10,13 @@ namespace Jellyfin.Server.Migrations /// /// Updater that takes care of bringing configuration up to 10.5.0 standards. /// - internal class Pre_10_5 : IUpdater + internal class DisableTranscodingThrottling : IUpdater { /// - public Version Maximum { get => Version.Parse("10.5.0"); } + public string Name => "DisableTranscodingThrottling"; /// - public bool Perform(CoreAppHost host, ILogger logger, Version from) + 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"); @@ -24,10 +26,7 @@ namespace Jellyfin.Server.Migrations encoding.EnableThrottling = false; host.ServerConfigurationManager.SaveConfiguration("encoding", encoding); - return true; } - - return false; } } } diff --git a/Jellyfin.Server/Migrations/DisableZealousLogging.cs b/Jellyfin.Server/Migrations/DisableZealousLogging.cs new file mode 100644 index 0000000000..a0a934d4ab --- /dev/null +++ b/Jellyfin.Server/Migrations/DisableZealousLogging.cs @@ -0,0 +1,29 @@ +using System; +using System.IO; +using MediaBrowser.Common.Configuration; +using MediaBrowser.Model.Configuration; +using Microsoft.Extensions.Configuration; +using Microsoft.Extensions.Logging; +using Serilog; +using ILogger = Microsoft.Extensions.Logging.ILogger; + +namespace Jellyfin.Server.Migrations +{ + /// + /// Updater that takes care of bringing configuration up to 10.5.0 standards. + /// + internal class DisableZealousLogging : IUpdater + { + /// + public string Name => "DisableZealousLogging"; + + /// + // This tones down logging from some components + public void Perform(CoreAppHost host, ILogger logger) + { + string configPath = Path.Combine(host.ServerConfigurationManager.ApplicationPaths.ConfigurationDirectoryPath, Program.LoggingConfigFile); + // TODO: fix up the config + throw new NotImplementedException("don't know how to fix logging yet"); + } + } +} diff --git a/Jellyfin.Server/Migrations/IUpdater.cs b/Jellyfin.Server/Migrations/IUpdater.cs index 60d9702567..10ada73d5f 100644 --- a/Jellyfin.Server/Migrations/IUpdater.cs +++ b/Jellyfin.Server/Migrations/IUpdater.cs @@ -3,24 +3,21 @@ using Microsoft.Extensions.Logging; namespace Jellyfin.Server.Migrations { + /// + /// Interface that descibes a migration routine. + /// + internal interface IUpdater + { /// - /// Interface that descibes a migration routine. + /// Gets the name of the migration, must be unique. /// - internal interface IUpdater - { - /// - /// Gets maximum version this Updater applies to. - /// If current version is greater or equal to it, skip the updater. - /// - public abstract Version Maximum { get; } + public abstract string Name { get; } - /// - /// Execute the migration from version "from". - /// - /// Host that hosts current version. - /// Host logger. - /// Version to migrate from. - /// Whether configuration was changed. - public abstract bool Perform(CoreAppHost host, ILogger logger, Version from); - } + /// + /// Execute the migration from version "from". + /// + /// Host that hosts current version. + /// Host logger. + public abstract void Perform(CoreAppHost host, ILogger logger); + } } diff --git a/Jellyfin.Server/Migrations/MigrationOptions.cs b/Jellyfin.Server/Migrations/MigrationOptions.cs new file mode 100644 index 0000000000..b96288cc1b --- /dev/null +++ b/Jellyfin.Server/Migrations/MigrationOptions.cs @@ -0,0 +1,23 @@ +namespace Jellyfin.Server.Migrations +{ + /// + /// Configuration part that holds all migrations that were applied. + /// + public class MigrationOptions + { + /// + /// Initializes a new instance of the class. + /// + public MigrationOptions() + { + Applied = System.Array.Empty(); + } + +#pragma warning disable CA1819 // Properties should not return arrays + /// + /// Gets or sets he 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 ad54fa38e6..04d0378521 100644 --- a/Jellyfin.Server/Migrations/MigrationRunner.cs +++ b/Jellyfin.Server/Migrations/MigrationRunner.cs @@ -1,3 +1,6 @@ +using System; +using System.Linq; +using MediaBrowser.Common.Configuration; using Microsoft.Extensions.Logging; namespace Jellyfin.Server.Migrations @@ -5,42 +8,56 @@ namespace Jellyfin.Server.Migrations /// /// The class that knows how migrate between different Jellyfin versions. /// - public static class MigrationRunner + public sealed class MigrationRunner { - private static readonly IUpdater[] _migrations = + /// + /// The list of known migrations, in order of applicability. + /// + internal static readonly IUpdater[] Migrations = { - new Pre_10_5() + new DisableTranscodingThrottling(), + new DisableZealousLogging() }; /// /// Run all needed migrations. /// /// CoreAppHost that hosts current version. - /// AppHost logger. - /// Whether anything was changed. - public static bool Run(CoreAppHost host, ILogger logger) + /// Factory for making the logger. + public static void Run(CoreAppHost host, ILoggerFactory loggerFactory) { - bool updated = false; - var version = host.ServerConfigurationManager.CommonConfiguration.PreviousVersion; + var logger = loggerFactory.CreateLogger(); + var migrationOptions = ((IConfigurationManager)host.ServerConfigurationManager).GetConfiguration("migrations"); + var applied = migrationOptions.Applied.ToList(); - for (var i = 0; i < _migrations.Length; i++) + for (var i = 0; i < Migrations.Length; i++) { - var updater = _migrations[i]; - if (version.CompareTo(updater.Maximum) >= 0) + var updater = Migrations[i]; + if (applied.Contains(updater.Name)) { - logger.LogDebug("Skipping updater {0} as current version {1} >= its maximum applicable version {2}", updater, version, updater.Maximum); + logger.LogDebug("Skipping migration {0} as it is already applied", updater.Name); continue; } - if (updater.Perform(host, logger, version)) + try { - updated = true; + updater.Perform(host, logger); + } + catch (Exception ex) + { + logger.LogError(ex, "Cannot apply migration {0}", updater.Name); + continue; } - version = updater.Maximum; + applied.Add(updater.Name); } - return updated; + if (applied.Count > migrationOptions.Applied.Length) + { + logger.LogInformation("Some migrations were run, saving the state"); + migrationOptions.Applied = applied.ToArray(); + host.ServerConfigurationManager.SaveConfiguration("migrations", migrationOptions); + } } } } diff --git a/Jellyfin.Server/Migrations/MigrationsFactory.cs b/Jellyfin.Server/Migrations/MigrationsFactory.cs new file mode 100644 index 0000000000..ed01dc646a --- /dev/null +++ b/Jellyfin.Server/Migrations/MigrationsFactory.cs @@ -0,0 +1,20 @@ +using System.Collections.Generic; +using MediaBrowser.Common.Configuration; + +namespace Jellyfin.Server.Migrations +{ + /// + /// A factory that teachs Jellyfin how to find a peristent file which lists all applied migrations. + /// + public class MigrationsFactory : IConfigurationFactory + { + /// + public IEnumerable GetConfigurations() + { + return new[] + { + new MigrationsListStore() + }; + } + } +} diff --git a/Jellyfin.Server/Migrations/MigrationsListStore.cs b/Jellyfin.Server/Migrations/MigrationsListStore.cs new file mode 100644 index 0000000000..d91d602c14 --- /dev/null +++ b/Jellyfin.Server/Migrations/MigrationsListStore.cs @@ -0,0 +1,19 @@ +using MediaBrowser.Common.Configuration; + +namespace Jellyfin.Server.Migrations +{ + /// + /// A configuration that lists all the migration routines that were applied. + /// + public class MigrationsListStore : ConfigurationStore + { + /// + /// Initializes a new instance of the class. + /// + public MigrationsListStore() + { + ConfigurationType = typeof(MigrationOptions); + Key = "migrations"; + } + } +} diff --git a/Jellyfin.Server/Program.cs b/Jellyfin.Server/Program.cs index aa1bdb1691..0271861054 100644 --- a/Jellyfin.Server/Program.cs +++ b/Jellyfin.Server/Program.cs @@ -38,6 +38,11 @@ namespace Jellyfin.Server /// public static class Program { + /// + /// The name of logging configuration file. + /// + public static readonly string LoggingConfigFile = "logging.json"; + private static readonly CancellationTokenSource _tokenSource = new CancellationTokenSource(); private static readonly ILoggerFactory _loggerFactory = new SerilogLoggerFactory(); private static ILogger _logger = NullLogger.Instance; @@ -182,7 +187,7 @@ namespace Jellyfin.Server // A bit hacky to re-use service provider since ASP.NET doesn't allow a custom service collection. appHost.ServiceProvider = host.Services; appHost.FindParts(); - appHost.TryMigrate(); + Migrations.MigrationRunner.Run(appHost, _loggerFactory); try { @@ -438,7 +443,7 @@ namespace Jellyfin.Server private static async Task CreateConfiguration(IApplicationPaths appPaths) { const string ResourcePath = "Jellyfin.Server.Resources.Configuration.logging.json"; - string configPath = Path.Combine(appPaths.ConfigurationDirectoryPath, "logging.json"); + string configPath = Path.Combine(appPaths.ConfigurationDirectoryPath, LoggingConfigFile); if (!File.Exists(configPath)) { @@ -460,7 +465,7 @@ namespace Jellyfin.Server return new ConfigurationBuilder() .SetBasePath(appPaths.ConfigurationDirectoryPath) .AddInMemoryCollection(ConfigurationOptions.Configuration) - .AddJsonFile("logging.json", false, true) + .AddJsonFile(LoggingConfigFile, false, true) .AddEnvironmentVariables("JELLYFIN_") .Build(); } From ccafebca68fc09040572d0a21420ea9e5d6c1088 Mon Sep 17 00:00:00 2001 From: Vasily Date: Thu, 5 Mar 2020 20:37:49 +0300 Subject: [PATCH 03/10] Extract "migrations" config name to a proper constant --- Jellyfin.Server/Migrations/MigrationRunner.cs | 4 ++-- Jellyfin.Server/Migrations/MigrationsListStore.cs | 7 ++++++- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/Jellyfin.Server/Migrations/MigrationRunner.cs b/Jellyfin.Server/Migrations/MigrationRunner.cs index 04d0378521..1db99f5961 100644 --- a/Jellyfin.Server/Migrations/MigrationRunner.cs +++ b/Jellyfin.Server/Migrations/MigrationRunner.cs @@ -27,7 +27,7 @@ namespace Jellyfin.Server.Migrations public static void Run(CoreAppHost host, ILoggerFactory loggerFactory) { var logger = loggerFactory.CreateLogger(); - var migrationOptions = ((IConfigurationManager)host.ServerConfigurationManager).GetConfiguration("migrations"); + var migrationOptions = ((IConfigurationManager)host.ServerConfigurationManager).GetConfiguration(MigrationsListStore.StoreKey); var applied = migrationOptions.Applied.ToList(); for (var i = 0; i < Migrations.Length; i++) @@ -56,7 +56,7 @@ namespace Jellyfin.Server.Migrations { logger.LogInformation("Some migrations were run, saving the state"); migrationOptions.Applied = applied.ToArray(); - host.ServerConfigurationManager.SaveConfiguration("migrations", migrationOptions); + host.ServerConfigurationManager.SaveConfiguration(MigrationsListStore.StoreKey, migrationOptions); } } } diff --git a/Jellyfin.Server/Migrations/MigrationsListStore.cs b/Jellyfin.Server/Migrations/MigrationsListStore.cs index d91d602c14..7a1ca66714 100644 --- a/Jellyfin.Server/Migrations/MigrationsListStore.cs +++ b/Jellyfin.Server/Migrations/MigrationsListStore.cs @@ -7,13 +7,18 @@ namespace Jellyfin.Server.Migrations /// public class MigrationsListStore : ConfigurationStore { + /// + /// The name of the configuration in the storage. + /// + public static readonly string StoreKey = "migrations"; + /// /// Initializes a new instance of the class. /// public MigrationsListStore() { ConfigurationType = typeof(MigrationOptions); - Key = "migrations"; + Key = StoreKey; } } } From 55b429e5e816bea33afbd810d5f1e4f560ef0069 Mon Sep 17 00:00:00 2001 From: Vasily Date: Thu, 5 Mar 2020 20:40:17 +0300 Subject: [PATCH 04/10] Moved migration routines to their own directory --- Jellyfin.Server/Migrations/MigrationRunner.cs | 4 ++-- .../Migrations/{ => Routines}/DisableTranscodingThrottling.cs | 2 +- .../Migrations/{ => Routines}/DisableZealousLogging.cs | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) rename Jellyfin.Server/Migrations/{ => Routines}/DisableTranscodingThrottling.cs (96%) rename Jellyfin.Server/Migrations/{ => Routines}/DisableZealousLogging.cs (95%) diff --git a/Jellyfin.Server/Migrations/MigrationRunner.cs b/Jellyfin.Server/Migrations/MigrationRunner.cs index 1db99f5961..8b72cb467e 100644 --- a/Jellyfin.Server/Migrations/MigrationRunner.cs +++ b/Jellyfin.Server/Migrations/MigrationRunner.cs @@ -15,8 +15,8 @@ namespace Jellyfin.Server.Migrations /// internal static readonly IUpdater[] Migrations = { - new DisableTranscodingThrottling(), - new DisableZealousLogging() + new Routines.DisableTranscodingThrottling(), + new Routines.DisableZealousLogging() }; /// diff --git a/Jellyfin.Server/Migrations/DisableTranscodingThrottling.cs b/Jellyfin.Server/Migrations/Routines/DisableTranscodingThrottling.cs similarity index 96% rename from Jellyfin.Server/Migrations/DisableTranscodingThrottling.cs rename to Jellyfin.Server/Migrations/Routines/DisableTranscodingThrottling.cs index 83624bdadd..eff6469e20 100644 --- a/Jellyfin.Server/Migrations/DisableTranscodingThrottling.cs +++ b/Jellyfin.Server/Migrations/Routines/DisableTranscodingThrottling.cs @@ -5,7 +5,7 @@ using MediaBrowser.Model.Configuration; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.Logging; -namespace Jellyfin.Server.Migrations +namespace Jellyfin.Server.Migrations.Routines { /// /// Updater that takes care of bringing configuration up to 10.5.0 standards. diff --git a/Jellyfin.Server/Migrations/DisableZealousLogging.cs b/Jellyfin.Server/Migrations/Routines/DisableZealousLogging.cs similarity index 95% rename from Jellyfin.Server/Migrations/DisableZealousLogging.cs rename to Jellyfin.Server/Migrations/Routines/DisableZealousLogging.cs index a0a934d4ab..501f8f8654 100644 --- a/Jellyfin.Server/Migrations/DisableZealousLogging.cs +++ b/Jellyfin.Server/Migrations/Routines/DisableZealousLogging.cs @@ -7,7 +7,7 @@ using Microsoft.Extensions.Logging; using Serilog; using ILogger = Microsoft.Extensions.Logging.ILogger; -namespace Jellyfin.Server.Migrations +namespace Jellyfin.Server.Migrations.Routines { /// /// Updater that takes care of bringing configuration up to 10.5.0 standards. From 216e425cc55e8de1718df76f89c923cdf54de871 Mon Sep 17 00:00:00 2001 From: Vasily Date: Thu, 5 Mar 2020 20:52:00 +0300 Subject: [PATCH 05/10] Fix comment --- Jellyfin.Server/Migrations/IUpdater.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Jellyfin.Server/Migrations/IUpdater.cs b/Jellyfin.Server/Migrations/IUpdater.cs index 10ada73d5f..9b749841cf 100644 --- a/Jellyfin.Server/Migrations/IUpdater.cs +++ b/Jellyfin.Server/Migrations/IUpdater.cs @@ -14,7 +14,7 @@ namespace Jellyfin.Server.Migrations public abstract string Name { get; } /// - /// Execute the migration from version "from". + /// Execute the migration routine. /// /// Host that hosts current version. /// Host logger. From d4564d8e29274a854bdc46df3ebcaf0c1e39e906 Mon Sep 17 00:00:00 2001 From: Vasily Date: Fri, 6 Mar 2020 13:22:44 +0300 Subject: [PATCH 06/10] More logging, mark all migrations as applied if setup wizard is not complete --- Jellyfin.Server/Migrations/MigrationRunner.cs | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/Jellyfin.Server/Migrations/MigrationRunner.cs b/Jellyfin.Server/Migrations/MigrationRunner.cs index 8b72cb467e..00a7c3a00d 100644 --- a/Jellyfin.Server/Migrations/MigrationRunner.cs +++ b/Jellyfin.Server/Migrations/MigrationRunner.cs @@ -28,6 +28,17 @@ namespace Jellyfin.Server.Migrations { var logger = loggerFactory.CreateLogger(); var migrationOptions = ((IConfigurationManager)host.ServerConfigurationManager).GetConfiguration(MigrationsListStore.StoreKey); + + if (!host.ServerConfigurationManager.Configuration.IsStartupWizardCompleted) + { + // 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(); + host.ServerConfigurationManager.SaveConfiguration(MigrationsListStore.StoreKey, migrationOptions); + return; + } + var applied = migrationOptions.Applied.ToList(); for (var i = 0; i < Migrations.Length; i++) @@ -35,20 +46,22 @@ namespace Jellyfin.Server.Migrations var updater = Migrations[i]; if (applied.Contains(updater.Name)) { - logger.LogDebug("Skipping migration {0} as it is already applied", updater.Name); + logger.LogDebug("Skipping migration {Name} as it is already applied", updater.Name); continue; } + logger.LogInformation("Applying migration {Name}", updater.Name); try { updater.Perform(host, logger); } catch (Exception ex) { - logger.LogError(ex, "Cannot apply migration {0}", updater.Name); + logger.LogError(ex, "Cannot apply migration {Name}", updater.Name); continue; } + logger.LogInformation("Migration {Name} applied successfully", updater.Name); applied.Add(updater.Name); } From 098d3538e32f4440bf6ed3a14844ff3a3b2a6fca Mon Sep 17 00:00:00 2001 From: Vasily Date: Fri, 6 Mar 2020 17:22:22 +0300 Subject: [PATCH 07/10] Disable logging.json migration as it is not ready yet --- Jellyfin.Server/Migrations/MigrationRunner.cs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/Jellyfin.Server/Migrations/MigrationRunner.cs b/Jellyfin.Server/Migrations/MigrationRunner.cs index 00a7c3a00d..caaa58ae15 100644 --- a/Jellyfin.Server/Migrations/MigrationRunner.cs +++ b/Jellyfin.Server/Migrations/MigrationRunner.cs @@ -15,8 +15,7 @@ namespace Jellyfin.Server.Migrations /// internal static readonly IUpdater[] Migrations = { - new Routines.DisableTranscodingThrottling(), - new Routines.DisableZealousLogging() + new Routines.DisableTranscodingThrottling() }; /// From 5a0f1fe848aa16176ee1f697af8fe91b92c15c54 Mon Sep 17 00:00:00 2001 From: Vasily Date: Fri, 6 Mar 2020 19:01:07 +0300 Subject: [PATCH 08/10] Implement review suggestion --- Jellyfin.Server/Migrations/MigrationRunner.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Jellyfin.Server/Migrations/MigrationRunner.cs b/Jellyfin.Server/Migrations/MigrationRunner.cs index caaa58ae15..0274e68a1d 100644 --- a/Jellyfin.Server/Migrations/MigrationRunner.cs +++ b/Jellyfin.Server/Migrations/MigrationRunner.cs @@ -28,7 +28,7 @@ namespace Jellyfin.Server.Migrations var logger = loggerFactory.CreateLogger(); var migrationOptions = ((IConfigurationManager)host.ServerConfigurationManager).GetConfiguration(MigrationsListStore.StoreKey); - if (!host.ServerConfigurationManager.Configuration.IsStartupWizardCompleted) + if (!host.ServerConfigurationManager.Configuration.IsStartupWizardCompleted && migrationOptions.Applied.Length == 0) { // If startup wizard is not finished, this is a fresh install. // Don't run any migrations, just mark all of them as applied. From 7ecb16a46e44b8e2f8cc23329a2b66dad6aeb2fd Mon Sep 17 00:00:00 2001 From: Mark Monteiro Date: Sat, 7 Mar 2020 18:23:32 +0100 Subject: [PATCH 09/10] do not ignore exceptions during migration execution --- Jellyfin.Server/Migrations/MigrationRunner.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Jellyfin.Server/Migrations/MigrationRunner.cs b/Jellyfin.Server/Migrations/MigrationRunner.cs index 0274e68a1d..15c1e75aaf 100644 --- a/Jellyfin.Server/Migrations/MigrationRunner.cs +++ b/Jellyfin.Server/Migrations/MigrationRunner.cs @@ -57,7 +57,7 @@ namespace Jellyfin.Server.Migrations catch (Exception ex) { logger.LogError(ex, "Cannot apply migration {Name}", updater.Name); - continue; + throw; } logger.LogInformation("Migration {Name} applied successfully", updater.Name); From 1295f6c79bdf76274501838c9e42094e4b1dd3c0 Mon Sep 17 00:00:00 2001 From: Mark Monteiro Date: Sat, 7 Mar 2020 20:18:45 +0100 Subject: [PATCH 10/10] Documentation and log message cleanup --- Jellyfin.Server/Migrations/MigrationOptions.cs | 2 +- Jellyfin.Server/Migrations/MigrationRunner.cs | 10 +++++----- Jellyfin.Server/Migrations/MigrationsFactory.cs | 2 +- .../Routines/DisableTranscodingThrottling.cs | 4 ++-- 4 files changed, 9 insertions(+), 9 deletions(-) diff --git a/Jellyfin.Server/Migrations/MigrationOptions.cs b/Jellyfin.Server/Migrations/MigrationOptions.cs index b96288cc1b..6b7831158f 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 15c1e75aaf..ca4c79cfd3 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 ed01dc646a..23c1b1ee6f 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 eff6469e20..936c3640e0 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) {