Skip to content

Commit

Permalink
Fix setting of completed date on reset.
Browse files Browse the repository at this point in the history
  • Loading branch information
chullybun committed Oct 4, 2023
1 parent 6357524 commit 3e732f7
Show file tree
Hide file tree
Showing 7 changed files with 34 additions and 16 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

Represents the **NuGet** versions.

## v2.3.3
- *Fixed:* Stored procedure `spXxxBatchReset` updated to correctly set the completed date within the batch tracking table.

## v2.3.2
- *Enhancement:* Added new `spXxxBatchReset` stored procedure to reset the bacth tracking to the latest lsn. Can be used to fix data loss batch by completing with the latest lsn. Also useful to support unit testing.
- *Fixed:* Updated `DbEx` (`v2.3.11`) and `CoreEx` (`v3.3.1`).
Expand Down
2 changes: 1 addition & 1 deletion Common.targets
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<Project>
<PropertyGroup>
<Version>2.3.2</Version>
<Version>2.3.3</Version>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<Authors>NTangle Developers</Authors>
<Company>Avanade</Company>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,16 @@ BEGIN
BEGIN TRANSACTION

-- Get the maximum lsn.
DECLARE @MaxLsn BINARY(10)
DECLARE @MaxLsn BINARY(10), @CompletedDate DATETIME2;
SET @MaxLsn = sys.fn_cdc_get_max_lsn();
SET @CompletedDate = GETUTCDATE();

-- Complete any incomplete batch (with data loss) with max lsn.
UPDATE [_batch] SET
[_batch].[ContactMaxLsn] = @MaxLsn,
[_batch].[AddressMaxLsn] = @MaxLsn,
[_batch].[IsComplete] = 1,
[_batch].[CompletedDate] = GETUTCDATE(),
[_batch].[CompletedDate] = @CompletedDate,
[_batch].[HasDataLoss] = 1
FROM [NTangle].[ContactBatchTracking] AS [_batch]
WHERE [_batch].[IsComplete] = 0;
Expand All @@ -34,6 +35,7 @@ BEGIN
[AddressMinLsn],
[AddressMaxLsn],
[CreatedDate],
[CompletedDate],
[IsComplete],
[CorrelationId],
[HasDataLoss]
Expand All @@ -43,7 +45,8 @@ BEGIN
@MaxLsn,
@MaxLsn,
@MaxLsn,
GETUTCDATE(),
@CompletedDate,
@CompletedDate,
1,
LOWER(CONVERT(NVARCHAR(64), NEWID())),
1
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,16 @@ BEGIN
BEGIN TRANSACTION

-- Get the maximum lsn.
DECLARE @MaxLsn BINARY(10)
DECLARE @MaxLsn BINARY(10), @CompletedDate DATETIME2;
SET @MaxLsn = sys.fn_cdc_get_max_lsn();
SET @CompletedDate = GETUTCDATE();

-- Complete any incomplete batch (with data loss) with max lsn.
UPDATE [_batch] SET
[_batch].[ContactMaxLsn] = @MaxLsn,
[_batch].[AddressMaxLsn] = @MaxLsn,
[_batch].[IsComplete] = 1,
[_batch].[CompletedDate] = GETUTCDATE(),
[_batch].[CompletedDate] = @CompletedDate,
[_batch].[HasDataLoss] = 1
FROM [NTangle].[ContactBatchTracking] AS [_batch]
WHERE [_batch].[IsComplete] = 0;
Expand All @@ -34,6 +35,7 @@ BEGIN
[AddressMinLsn],
[AddressMaxLsn],
[CreatedDate],
[CompletedDate],
[IsComplete],
[CorrelationId],
[HasDataLoss]
Expand All @@ -43,7 +45,8 @@ BEGIN
@MaxLsn,
@MaxLsn,
@MaxLsn,
GETUTCDATE(),
@CompletedDate,
@CompletedDate,
1,
LOWER(CONVERT(NVARCHAR(64), NEWID())),
1
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,15 @@ BEGIN
BEGIN TRANSACTION

-- Get the maximum lsn.
DECLARE @MaxLsn BINARY(10)
DECLARE @MaxLsn BINARY(10), @CompletedDate DATETIME2;
SET @MaxLsn = sys.fn_cdc_get_max_lsn();
SET @CompletedDate = GETUTCDATE();

-- Complete any incomplete batch (with data loss) with max lsn.
UPDATE [_batch] SET
[_batch].[CustomerMaxLsn] = @MaxLsn,
[_batch].[IsComplete] = 1,
[_batch].[CompletedDate] = GETUTCDATE(),
[_batch].[CompletedDate] = @CompletedDate,
[_batch].[HasDataLoss] = 1
FROM [NTangle].[CustomerBatchTracking] AS [_batch]
WHERE [_batch].[IsComplete] = 0;
Expand All @@ -31,14 +32,16 @@ BEGIN
[CustomerMinLsn],
[CustomerMaxLsn],
[CreatedDate],
[CompletedDate],
[IsComplete],
[CorrelationId],
[HasDataLoss]
)
VALUES (
@MaxLsn,
@MaxLsn,
GETUTCDATE(),
@CompletedDate,
@CompletedDate,
1,
LOWER(CONVERT(NVARCHAR(64), NEWID())),
1
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,9 @@ BEGIN
BEGIN TRANSACTION

-- Get the maximum lsn.
DECLARE @MaxLsn BINARY(10)
DECLARE @MaxLsn BINARY(10), @CompletedDate DATETIME2;
SET @MaxLsn = sys.fn_cdc_get_max_lsn();
SET @CompletedDate = GETUTCDATE();

-- Complete any incomplete batch (with data loss) with max lsn.
UPDATE [_batch] SET
Expand All @@ -22,7 +23,7 @@ BEGIN
[_batch].[CommentsTagsMaxLsn] = @MaxLsn,
[_batch].[PostsTagsMaxLsn] = @MaxLsn,
[_batch].[IsComplete] = 1,
[_batch].[CompletedDate] = GETUTCDATE(),
[_batch].[CompletedDate] = @CompletedDate,
[_batch].[HasDataLoss] = 1
FROM [NTangle].[PostsBatchTracking] AS [_batch]
WHERE [_batch].[IsComplete] = 0;
Expand All @@ -40,6 +41,7 @@ BEGIN
[PostsTagsMinLsn],
[PostsTagsMaxLsn],
[CreatedDate],
[CompletedDate],
[IsComplete],
[CorrelationId],
[HasDataLoss]
Expand All @@ -53,7 +55,8 @@ BEGIN
@MaxLsn,
@MaxLsn,
@MaxLsn,
GETUTCDATE(),
@CompletedDate,
@CompletedDate,
1,
LOWER(CONVERT(NVARCHAR(64), NEWID())),
1
Expand Down
9 changes: 6 additions & 3 deletions tools/NTangle.CodeGen/Templates/SpResetBatch_sql.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,9 @@ BEGIN
BEGIN TRANSACTION

-- Get the maximum lsn.
DECLARE @MaxLsn BINARY(10)
DECLARE @MaxLsn BINARY(10), @CompletedDate DATETIME2;
SET @MaxLsn = sys.fn_cdc_get_max_lsn();
SET @CompletedDate = GETUTCDATE();

-- Complete any incomplete batch (with data loss) with max lsn.
UPDATE [_batch] SET
Expand All @@ -23,7 +24,7 @@ BEGIN
[_batch].[{{pascal Name}}MaxLsn] = @MaxLsn,
{{/each}}
[_batch].[IsComplete] = 1,
[_batch].[CompletedDate] = GETUTCDATE(),
[_batch].[CompletedDate] = @CompletedDate,
[_batch].[HasDataLoss] = 1
FROM [{{CdcSchema}}].[{{BatchTrackingTable}}] AS [_batch]
WHERE [_batch].[IsComplete] = 0;
Expand All @@ -39,6 +40,7 @@ BEGIN
[{{pascal Name}}MaxLsn],
{{/each}}
[CreatedDate],
[CompletedDate],
[IsComplete],
[CorrelationId],
[HasDataLoss]
Expand All @@ -50,7 +52,8 @@ BEGIN
@MaxLsn,
@MaxLsn,
{{/each}}
GETUTCDATE(),
@CompletedDate,
@CompletedDate,
1,
LOWER(CONVERT(NVARCHAR(64), NEWID())),
1
Expand Down

0 comments on commit 3e732f7

Please sign in to comment.