From 57c6a5ce11a2c9a672ca73f1904b2d6c665d8f8a Mon Sep 17 00:00:00 2001 From: Ameya Rele Date: Fri, 16 Sep 2022 14:36:41 +0530 Subject: [PATCH] Add comments to explain LastSyncVersion selection --- src/TriggerBinding/SqlTableChangeMonitor.cs | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/TriggerBinding/SqlTableChangeMonitor.cs b/src/TriggerBinding/SqlTableChangeMonitor.cs index 908f10248..fb90f9af6 100644 --- a/src/TriggerBinding/SqlTableChangeMonitor.cs +++ b/src/TriggerBinding/SqlTableChangeMonitor.cs @@ -586,8 +586,14 @@ private long RecomputeLastSyncVersion() changeVersionSet.Add(long.Parse(changeVersion, CultureInfo.InvariantCulture)); } - // If there are more than one version numbers in the set, return the second highest one. Otherwise, return + // The batch of changes are gotten in ascending order of the version number. + // With this, it is ensured that if there are multiple version numbers in the changeVersionSet, + // all the other rows with version numbers less than the highest should have either been processed or + // have leases acquired on them by another worker. + // Therefore, if there are more than one version numbers in the set, return the second highest one. Otherwise, return // the only version number in the set. + // Also this LastSyncVersion is actually updated in the GlobalState table only after verifying that the changes with + // changeVersion <= newLastSyncVersion have been processed in BuildUpdateTablesPostInvocation query. long lastSyncVersion = changeVersionSet.ElementAt(changeVersionSet.Count > 1 ? changeVersionSet.Count - 2 : 0); this._logger.LogDebugWithThreadId($"RecomputeLastSyncVersion. LastSyncVersion={lastSyncVersion} ChangeVersionSet={string.Join(",", changeVersionSet)}"); return lastSyncVersion;