Class MongoDbStalePositionDetector
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
ChangeStreamHistoryLost
MongoDB error code for ChangeStreamHistoryLost (resume token not in oplog).
public const int ChangeStreamHistoryLost = 136
Field Value
InvalidNamespace
MongoDB error code for InvalidNamespace (collection renamed).
public const int InvalidNamespace = 73
Field Value
NamespaceNotFound
MongoDB error code for NamespaceNotFound (collection dropped).
public const int NamespaceNotFound = 26
Field Value
StaleShardVersion
MongoDB error code for StaleShardVersion (shard migration).
public const int StaleShardVersion = 133
Field Value
Properties
StalePositionErrorCodes
Gets the set of MongoDB error codes that indicate a stale CDC position.
public static IReadOnlySet<int> StalePositionErrorCodes { get; }
Property Value
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
exceptionExceptionThe exception that was caught.
processorIdstringThe identifier of the CDC processor.
stalePositionMongoDbCdcPosition?The resume token position that was detected as stale.
newPositionMongoDbCdcPosition?The new position to resume from, if known.
databaseNamestringThe affected database name, if known.
collectionNamestringThe 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
exceptionMongoExceptionThe 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
exceptionExceptionThe exception to analyze.
Returns
IsStalePositionErrorCode(int)
Determines if an error code indicates a stale position scenario.
public static bool IsStalePositionErrorCode(int errorCode)
Parameters
errorCodeintThe MongoDB error code.
Returns
IsStalePositionException(Exception?)
Determines whether the specified exception indicates a stale CDC position.
public static bool IsStalePositionException(Exception? exception)
Parameters
exceptionExceptionThe exception to analyze.