Class CdcStateStore
Provides methods to manage the CDC (Change Data Capture) processing state in a database.
public class CdcStateStore : ISqlServerCdcStateStore, ICdcStateStore, IAsyncDisposable, IDisposable
- Inheritance
-
CdcStateStore
- Implements
- Inherited Members
Constructors
CdcStateStore(Func<IDbConnection>)
Initializes a new instance of the CdcStateStore class.
public CdcStateStore(Func<IDbConnection> connectionFactory)
Parameters
connectionFactoryFunc<IDbConnection>Supplies a connection for each operation. The store opens the connection it is given, uses it for one statement, and disposes it, so pooled connections are returned promptly and two overlapping operations never share one.
Exceptions
- ArgumentNullException
Thrown if
connectionFactoryisnull.
CdcStateStore(Func<IDbConnection>, IOptions<SqlServerCdcStateStoreOptions>)
Initializes a new instance of the CdcStateStore class with options.
public CdcStateStore(Func<IDbConnection> connectionFactory, IOptions<SqlServerCdcStateStoreOptions> options)
Parameters
connectionFactoryFunc<IDbConnection>Supplies a connection for each operation.
optionsIOptions<SqlServerCdcStateStoreOptions>The CDC state store options.
Methods
Dispose()
Releases all resources used by the CdcStateStore.
public void Dispose()
Dispose(bool)
Core disposal implementation.
protected virtual void Dispose(bool disposing)
Parameters
disposingboolTrue if disposing managed resources; otherwise, false.
DisposeAsync()
Asynchronously releases the unmanaged resources used by the CdcStateStore.
public ValueTask DisposeAsync()
Returns
- ValueTask
A value task that represents the asynchronous dispose operation.
DisposeCoreAsync()
Core asynchronous disposal implementation.
protected virtual ValueTask DisposeCoreAsync()
Returns
- ValueTask
A value task that represents the asynchronous disposal operation.
GetLastProcessedPositionAsync(string, string, CancellationToken)
Retrieves the last processed position for a specified database connection and name.
public Task<IEnumerable<CdcProcessingState>> GetLastProcessedPositionAsync(string databaseConnectionIdentifier, string databaseName, CancellationToken cancellationToken)
Parameters
databaseConnectionIdentifierstringThe unique identifier for the database connection.
databaseNamestringThe name of the database to retrieve the processing state for.
cancellationTokenCancellationTokenA token to observe while waiting for the task to complete.
Returns
- Task<IEnumerable<CdcProcessingState>>
A task that represents the asynchronous operation, containing a collection of the last processed CdcProcessingState for each capture instance.
UpdateLastProcessedPositionAsync(string, string, string, byte[], byte[]?, DateTime?, long?, CancellationToken)
Updates the last processed position for a specified database connection and name.
public Task<int> UpdateLastProcessedPositionAsync(string databaseConnectionIdentifier, string databaseName, string tableName, byte[] position, byte[]? sequenceValue, DateTime? commitTime, long? fencingToken, CancellationToken cancellationToken)
Parameters
databaseConnectionIdentifierstringThe unique identifier for the database connection.
databaseNamestringThe name of the database to update the processing state for.
tableNamestringThe name of the table to update the processing state for.
positionbyte[]The LSN position to set as the last processed position.
sequenceValuebyte[]The sequence value associated with the last processed position, if any.
commitTimeDateTime?The commit time of the last processed LSN.
fencingTokenlong?The current leadership tenure's fencing token, or null when leader-election fencing is not configured. When non-null, the checkpoint write is a non-decreasing compare-and-swap: it is applied only if the stored token is less than or equal to this token (a demoted leader presenting an older token is rejected, leaving the LSN checkpoint unchanged — no regression or skip). The return value is the number of rows written, so
0with a non-null token signals a superseded leader.cancellationTokenCancellationTokenA token to observe while waiting for the task to complete.