[
https://issues.apache.org/jira/browse/CAMEL-27415?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
]
Work on CAMEL-27415 started by shashank.
----------------------------------------
> camel-mongodb - the change streams consumer retries a resume token that the
> oplog no longer has for as long as the route runs, and the route cannot start
> with it
> -----------------------------------------------------------------------------------------------------------------------------------------------------------------
>
> Key: CAMEL-27415
> URL: https://issues.apache.org/jira/browse/CAMEL-27415
> Project: Camel
> Issue Type: Bug
> Components: camel-mongodb
> Reporter: shashank
> Assignee: shashank
> Priority: Major
>
> h3. What happens
> The change streams consumer keeps only the token of the last event whose
> exchange completed ({{MongoDbChangeStreamsThread}}). It never uses the post
> batch resume token of the change stream. On a collection that sees few
> changes while the rest of the replica set is written, the change stream keeps
> reading the oplog, but the token of its last event falls out of the oplog
> window. The same happens when every event since that token failed.
> After a failure that the driver cannot resume itself (the server cannot be
> reached for longer than the server selection timeout, or a slow failover),
> the consumer opens the change stream again with {{resumeAfter}} that token.
> MongoDB answers ChangeStreamHistoryLost (286). Only InvalidResumeToken (260)
> is handled, so the consumer tries the same token after
> {{cursorRegenerationDelay}} for as long as the route runs, while the route
> shows as started. Changes made afterwards are still in the oplog but are
> never routed.
> With {{changeStreamTokenRepository}}, every start of the route reads the
> stored token and fails with {{FailedToStartRouteException ... error 286
> (ChangeStreamHistoryLost)}}. The only way out is to delete the stored token
> by hand.
> This was noted as a follow-up in the review of CAMEL-26992.
> h3. How to reproduce
> A change streams route with a {{changeStreamTokenRepository}}. Route one
> change, then write only other collections until the oplog rolls past that
> change. Make the server unreachable for longer than the server selection
> timeout: the consumer logs the 286 failure on every attempt and routes
> nothing more. Restart the route: it fails to start.
> Found with a TLA+ model of the consumer thread, its commit manager and the
> oplog.
> h3. Fix
> The consumer reads with {{tryNext()}}, and after a getMore that returns no
> event (when the exchange of the last event it read completed) it takes the
> post batch resume token of the cursor ({{getResumeToken()}}) as the token to
> resume after and commits it. A token that the oplog no longer has (286, or
> 280 and 40576 on MongoDB 4.2) is dropped with a WARN, and the change stream
> is opened at the current time, as the consumer already does for a start time
> that the oplog no longer has (CAMEL-26992).
> _Filed with Claude Code on behalf of allthingssecurity._
--
This message was sent by Atlassian Jira
(v10.3.26#10030026)