Skip to content

Commit

Permalink
convert lsn functions to biginteger for lsn (#43)
Browse files Browse the repository at this point in the history
  • Loading branch information
runeanielsen authored Jan 12, 2022
1 parent 2a1662e commit 9889cb4
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 8 deletions.
5 changes: 3 additions & 2 deletions examples/Example/Program.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Numerics;
using System.Text.Json;
using System.Text.Json.Serialization;
using System.Threading;
Expand All @@ -24,7 +25,7 @@ public static void Main(string[] args)
var changeDataChannel = Channel.CreateUnbounded<IReadOnlyCollection<ChangeRow<dynamic>>>();
_ = Task.Factory.StartNew(async () =>
{
long lowBoundLsn = await GetStartLsn(connectionString);
var lowBoundLsn = await GetStartLsn(connectionString);
while (true)
{
if (cdcCancellationToken.IsCancellationRequested)
Expand Down Expand Up @@ -99,7 +100,7 @@ public static void Main(string[] args)
cdcCancellation.Cancel();
}

private static async Task<long> GetStartLsn(string connectionString)
private static async Task<BigInteger> GetStartLsn(string connectionString)
{
using var connection = new SqlConnection(connectionString);
await connection.OpenAsync();
Expand Down
6 changes: 3 additions & 3 deletions src/MsSqlCdc/Cdc.cs
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ public static async Task<BigInteger> MapTimeToLsn(
/// Returns the date and time value from the tran_end_time column in the cdc.lsn_time_mapping
/// system table for the specified log sequence number (LSN).
/// </returns>
public static async Task<DateTime> MapLsnToTime(SqlConnection connection, long lsn)
public static async Task<DateTime> MapLsnToTime(SqlConnection connection, BigInteger lsn)
{
var lsnToTime = await CdcDatabase.MapLsnToTime(connection, lsn);
if (!lsnToTime.HasValue)
Expand Down Expand Up @@ -230,7 +230,7 @@ public static async Task<BigInteger> GetMaxLsn(SqlConnection connection)
/// <param name="connection">An open connection to a MS-SQL database.</param>
/// <param name="lsn">The LSN number that should be used as the point to get the previous LSN.</param>
/// <returns>Return the high endpoint of the change data capture timeline for any capture instance.</returns>
public static async Task<BigInteger> GetPreviousLsn(SqlConnection connection, long lsn)
public static async Task<BigInteger> GetPreviousLsn(SqlConnection connection, BigInteger lsn)
{
var previousLsnBytes = await CdcDatabase.DecrementLsn(connection, lsn);
if (previousLsnBytes is null)
Expand All @@ -245,7 +245,7 @@ public static async Task<BigInteger> GetPreviousLsn(SqlConnection connection, lo
/// <param name="connection">An open connection to a MS-SQL database.</param>
/// <param name="lsn">The LSN number that should be used as the point to get the next LSN.</param>
/// <returns>Get the next log sequence number (LSN) in the sequence based upon the specified LSN.</returns>
public static async Task<BigInteger> GetNextLsn(SqlConnection connection, long lsn)
public static async Task<BigInteger> GetNextLsn(SqlConnection connection, BigInteger lsn)
{
var nextLsnBytes = await CdcDatabase.IncrementLsn(connection, lsn);
if (nextLsnBytes is null)
Expand Down
6 changes: 3 additions & 3 deletions src/MsSqlCdc/CdcDatabase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ internal static class CdcDatabase
return (int?)(await command.ExecuteScalarAsync());
}

public static async Task<DateTime?> MapLsnToTime(SqlConnection connection, long lsn)
public static async Task<DateTime?> MapLsnToTime(SqlConnection connection, BigInteger lsn)
{
var sql = "SELECT sys.fn_cdc_map_lsn_to_time(@lsn)";

Expand Down Expand Up @@ -87,7 +87,7 @@ internal static class CdcDatabase
return (byte[]?)(await command.ExecuteScalarAsync());
}

public static async Task<byte[]?> DecrementLsn(SqlConnection connection, long lsn)
public static async Task<byte[]?> DecrementLsn(SqlConnection connection, BigInteger lsn)
{
var sql = "SELECT sys.fn_cdc_decrement_lsn(@lsn)";
using var command = new SqlCommand(sql, connection);
Expand All @@ -96,7 +96,7 @@ internal static class CdcDatabase
return (byte[]?)(await command.ExecuteScalarAsync());
}

public static async Task<byte[]?> IncrementLsn(SqlConnection connection, long lsn)
public static async Task<byte[]?> IncrementLsn(SqlConnection connection, BigInteger lsn)
{
var sql = "SELECT sys.fn_cdc_increment_lsn(@lsn)";
using var command = new SqlCommand(sql, connection);
Expand Down

0 comments on commit 9889cb4

Please sign in to comment.