Table of Contents

Class MongoDbStalePositionDetector

Namespace
Excalibur.Cdc.MongoDB
Assembly
Excalibur.Cdc.MongoDB.dll

Detects and classifies stale CDC position errors from MongoDB exceptions.

public static class MongoDbStalePositionDetector
Inheritance
MongoDbStalePositionDetector
Inherited Members

Remarks

MongoDB reports stale position scenarios through specific error codes:

  • 136 - ChangeStreamHistoryLost (resume token not in oplog)
  • 286 - ChangeStreamFatalError (invalid resume token)
  • 26 - NamespaceNotFound (collection dropped)
  • 73 - InvalidNamespace (collection renamed)
  • 133 - StaleShardVersion (shard migration)

Fields

ChangeStreamFatalError

MongoDB error code for ChangeStreamFatalError (invalid resume token).

public const int ChangeStreamFatalError = 286

Field Value

int

ChangeStreamHistoryLost

MongoDB error code for ChangeStreamHistoryLost (resume token not in oplog).

public const int ChangeStreamHistoryLost = 136

Field Value

int

InvalidNamespace

MongoDB error code for InvalidNamespace (collection renamed).

public const int InvalidNamespace = 73

Field Value

int

NamespaceNotFound

MongoDB error code for NamespaceNotFound (collection dropped).

public const int NamespaceNotFound = 26

Field Value

int

StaleShardVersion

MongoDB error code for StaleShardVersion (shard migration).

public const int StaleShardVersion = 133

Field Value

int

Properties

StalePositionErrorCodes

Gets the set of MongoDB error codes that indicate a stale CDC position.

public static IReadOnlySet<int> StalePositionErrorCodes { get; }

Property Value

IReadOnlySet<int>

Methods

CreateEventArgs(Exception, string, MongoDbCdcPosition?, MongoDbCdcPosition?, string?, string?)

Creates a CdcPositionResetEventArgs from an exception and context.

public static CdcPositionResetEventArgs CreateEventArgs(Exception exception, string processorId, MongoDbCdcPosition? stalePosition = null, MongoDbCdcPosition? newPosition = null, string? databaseName = null, string? collectionName = null)

Parameters

exception Exception

The exception that was caught.

processorId string

The identifier of the CDC processor.

stalePosition MongoDbCdcPosition?

The resume token position that was detected as stale.

newPosition MongoDbCdcPosition?

The new position to resume from, if known.

databaseName string

The affected database name, if known.

collectionName string

The affected collection name, if known.

Returns

CdcPositionResetEventArgs

A populated CdcPositionResetEventArgs instance.

GetReasonCode(MongoException?)

Determines the appropriate reason code from a MongoDB exception.

public static string GetReasonCode(MongoException? exception)

Parameters

exception MongoException

The MongoDB exception to analyze.

Returns

string

The reason code string.

GetStalePositionErrorCode(Exception?)

Extracts the error code that indicates a stale position from the exception.

public static int? GetStalePositionErrorCode(Exception? exception)

Parameters

exception Exception

The exception to analyze.

Returns

int?

The MongoDB error code if found; otherwise, null.

IsStalePositionErrorCode(int)

Determines if an error code indicates a stale position scenario.

public static bool IsStalePositionErrorCode(int errorCode)

Parameters

errorCode int

The MongoDB error code.

Returns

bool

true if the error code indicates stale position.

IsStalePositionException(Exception?)

Determines whether the specified exception indicates a stale CDC position.

public static bool IsStalePositionException(Exception? exception)

Parameters

exception Exception

The exception to analyze.

Returns

bool

true if the exception indicates a stale position; otherwise, false.