From 5d95dabc6977e4fa7a7bd5a267b6fa73ba8aacd7 Mon Sep 17 00:00:00 2001 From: Sebastian Burckhardt Date: Tue, 1 Jun 2021 14:42:46 -0700 Subject: [PATCH 1/2] Use more explicit serialization/deserialization for storage format string. --- .../Faster/AzureBlobs/BlobManager.cs | 42 +++++++++++++++---- 1 file changed, 34 insertions(+), 8 deletions(-) diff --git a/src/DurableTask.Netherite/StorageProviders/Faster/AzureBlobs/BlobManager.cs b/src/DurableTask.Netherite/StorageProviders/Faster/AzureBlobs/BlobManager.cs index 98e9b130..9416c14d 100644 --- a/src/DurableTask.Netherite/StorageProviders/Faster/AzureBlobs/BlobManager.cs +++ b/src/DurableTask.Netherite/StorageProviders/Faster/AzureBlobs/BlobManager.cs @@ -101,37 +101,63 @@ partial class BlobManager : ICheckpointManager, ILogCommitManager (numPartitions <= 16) ? 21 : // 2MB 20, // 1MB }; - + + // increment this after changes of the storage representation that break compatibility const int StorageFormatVersion = 1; public static string GetStorageFormat(NetheriteOrchestrationServiceSettings settings) { - return JsonConvert.SerializeObject(new + return JsonConvert.SerializeObject(new StorageFormatSettings() { UseAlternateObjectStore = settings.UseAlternateObjectStore, UsePSFQueries = settings.UsePSFQueries, FormatVersion = StorageFormatVersion, }, - Formatting.None); + serializerSettings); + } + + [JsonObject] + class StorageFormatSettings + { + // this must stay the same + [JsonProperty("FormatVersion")] + public int FormatVersion { get; set; } + + // the following can be changed between versions + + [JsonProperty("UseAlternateObjectStore", DefaultValueHandling=DefaultValueHandling.Ignore)] + public bool? UseAlternateObjectStore { get; set; } + + [JsonProperty("UsePSFQueries", DefaultValueHandling = DefaultValueHandling.Ignore)] + public bool? UsePSFQueries { get; set; } } + static readonly JsonSerializerSettings serializerSettings = new JsonSerializerSettings() + { + TypeNameHandling = TypeNameHandling.None, + MissingMemberHandling = MissingMemberHandling.Ignore, + CheckAdditionalContent = false, + Formatting = Formatting.None, + }; + + public static void CheckStorageFormat(string format, NetheriteOrchestrationServiceSettings settings) { try { - JObject json = JsonConvert.DeserializeObject(format); + var taskhubFormat = JsonConvert.DeserializeObject(format); - if ((bool)json["UseAlternateObjectStore"] != settings.UseAlternateObjectStore) + if (taskhubFormat.UseAlternateObjectStore != settings.UseAlternateObjectStore) { throw new InvalidOperationException("The Netherite configuration setting 'UseAlternateObjectStore' is incompatible with the existing taskhub."); } - if ((bool)json["UsePSFQueries"] != settings.UsePSFQueries) + if (taskhubFormat.UsePSFQueries != settings.UsePSFQueries) { throw new InvalidOperationException("The Netherite configuration setting 'UsePSFQueries' is incompatible with the existing taskhub."); } - if ((int)json["FormatVersion"] != StorageFormatVersion) + if (taskhubFormat.FormatVersion != StorageFormatVersion) { - throw new InvalidOperationException("The current storage format version is incompatible with the existing taskhub."); + throw new InvalidOperationException($"The current storage format version (={StorageFormatVersion}) is incompatible with the existing taskhub (={taskhubFormat.FormatVersion})."); } } catch(Exception e) From 08437db7e37c4545cacb00c36f9f5b7c1ccbb973 Mon Sep 17 00:00:00 2001 From: Sebastian Burckhardt Date: Tue, 1 Jun 2021 14:58:14 -0700 Subject: [PATCH 2/2] include settings for deserialization also. --- .../StorageProviders/Faster/AzureBlobs/BlobManager.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/DurableTask.Netherite/StorageProviders/Faster/AzureBlobs/BlobManager.cs b/src/DurableTask.Netherite/StorageProviders/Faster/AzureBlobs/BlobManager.cs index 9416c14d..7e282155 100644 --- a/src/DurableTask.Netherite/StorageProviders/Faster/AzureBlobs/BlobManager.cs +++ b/src/DurableTask.Netherite/StorageProviders/Faster/AzureBlobs/BlobManager.cs @@ -145,7 +145,7 @@ public static void CheckStorageFormat(string format, NetheriteOrchestrationServi { try { - var taskhubFormat = JsonConvert.DeserializeObject(format); + var taskhubFormat = JsonConvert.DeserializeObject(format, serializerSettings); if (taskhubFormat.UseAlternateObjectStore != settings.UseAlternateObjectStore) {