Hi <@U04S8PLJWMT> getting this error in the mongo ...
# ask-ai
i
Hi @kapa.ai getting this error in the mongo db source connection v1.5.14 io.airbyte.cdk.integrations.source.relationaldb.state.FailedRecordIteratorException: java.lang.RuntimeException: java.lang.RuntimeException: io.debezium.DebeziumException: Error while attempting to Checking change stream
k
I can see you're encountering a
FailedRecordIteratorException
with a Debezium error related to change streams in MongoDB source connector v1.5.14. Based on the knowledge sources, this type of error is typically related to issues with MongoDB's Change Data Capture (CDC) functionality. The error you're experiencing is similar to several documented issues with the MongoDB connector. Here are the most common causes and solutions: ## Common Causes 1. Invalid Resume Token / Oplog Issues: The saved offset may no longer be valid because the resume point is no longer in the oplog. This happens when: - The oplog retention period is too short - Syncs run less frequently than the oplog retention period - The time between syncs exceeds what the oplog can retain 2. Replica Set Configuration: For self-managed replica sets, there may be issues with how the
replicaSet
parameter is handled in the connection string. ## Recommended Solutions According to the [MongoDB troubleshooting documentation](https://docs.airbyte.com/integrations/sources/mongodb-v2/mongodb-v2-troubleshooting#connector-limitations): 1. Reset the connection and then take these preventive measures: - Increase the oplog retention period - Increase the oplog size (recommended: at least 24 hours, ideally 1 week of data) - Increase the Airbyte sync frequency 2. Verify your oplog configuration by running the commands outlined in [this MongoDB tutorial](https://www.mongodb.com/docs/manual/tutorial/troubleshoot-replica-sets/#check-the-size-of-the-oplog) 3. Check your cluster type: Ensure you're using a [replica set cluster](https://www.mongodb.com/docs/manual/replication/), as this is required for CDC functionality 4. Consider upgrading: You're using v1.5.14, and there have been several fixes in later versions. The [changelog](https://docs.airbyte.com/integrations/sources/mongodb-v2#changelog) shows improvements in versions 1.5.15 and beyond. If the issue persists after trying these solutions, you may want to check the full error logs for more specific details about which part of the change stream operation is failing.
i
@kapa.ai but how is airbyte reading data from mongodb ?
k
A message from kapa.ai
Based on the knowledge sources, Airbyte reads data from MongoDB using two primary methods: ## Change Data Capture (CDC) For incremental syncs, Airbyte utilizes [MongoDB's change streams feature](https://www.mongodb.com/docs/manual/changeStreams/) on a [replica set](https://www.mongodb.com/docs/manual/replication/) to capture inserts, updates, and deletes. According to the [replication methods documentation](https://docs.airbyte.com/integrations/sources/mongodb-v2#replication-methods), this CDC approach works by: 1. Initial Snapshot: The first time a sync runs, Airbyte takes a snapshot of the current state of the data. This snapshot is created with a read operation and is effectively a Full Refresh (meaning changes won't be logged during this initial load). 2. Incremental Updates: Subsequent syncs use the change streams/oplog to determine which changes took place since the last sync. Airbyte keeps track of the current log position between syncs. 3. Checkpointing: The connector uses [checkpointing](https://docs.airbyte.com/understanding-airbyte/airbyte-protocol/#state--checkpointing) and chunking of data reads to reliably replicate collections of any size. ## Full Refresh Mode Starting in v4.0.0, the MongoDB source also supports [Full Refresh sync mode](https://docs.airbyte.com/integrations/sources/mongodb-v2#replication-methods), which reads the entire contents of a collection repeatedly. Even in Full Refresh mode, the connector uses checkpointing, so if a sync fails (for example, due to a network error), it will continue from the last known point rather than starting over. ## How CDC Works According to the [CDC documentation](https://docs.airbyte.com/platform/understanding-airbyte/cdc), Airbyte reads data from the previously synced position in the logs up to the start time of the sync. The connector doesn't treat CDC sources as infinite streaming sources - syncs are launched regularly based on your configured schedule. This is why you're seeing the change stream error - the connector is trying to read from MongoDB's change streams, but encountering issues with the resume token or oplog configuration.
i
@kapa.ai can you tell me what do you mean by the connector is trying to read from MongoDB's change streams, but encountering issues with the resume token or oplog configuration. ?
k
A message from kapa.ai
Based on the knowledge sources, let me explain what happens when the MongoDB connector encounters resume token or oplog issues: ## How Change Streams Work When Airbyte uses CDC (Change Data Capture) with MongoDB, it relies on [MongoDB's change streams](https://www.mongodb.com/docs/manual/changeStreams/), which are based on the [replica set oplog](https://www.mongodb.com/docs/manual/core/replica-set-oplog/). The connector maintains a resume token - essentially a bookmark that tells it where to continue reading changes from the next time it syncs. ## What Goes Wrong According to the [troubleshooting documentation](https://docs.airbyte.com/integrations/sources/mongodb-v2/mongodb-v2-troubleshooting#connector-limitations), several issues describe what happens: 1. Resume Token Becomes Invalid: When you see errors like "Saved offset is not valid" or "cannot resume stream; the resume token was not found", it means the position (resume token) that Airbyte saved from the last sync no longer exists in MongoDB's oplog. 2. Oplog Retention Limitations: The oplog has a limited retention period. As described in [issue #46569](https://github.com/airbytehq/airbyte/issues/46569), if syncs run less frequently than the oplog retention period, the connector may try to resume from a position that has already been purged from the oplog. 3. The Actual Error: When this happens, MongoDB returns errors like: -
Command failed with error 280 (ChangeStreamFatalError): 'PlanExecutor error during aggregation :: caused by :: cannot resume stream; the resume token was not found'
-
Command failed with error 286 (ChangeStreamHistoryLost): 'Resume of change stream was not possible, as the resume point may no longer be in the oplog'
## Why It Matters As explained in the [troubleshooting guide](https://docs.airbyte.com/integrations/sources/mongodb-v2/mongodb-v2-troubleshooting#connector-limitations), when importing a large MongoDB collection for the first time, the import duration might exceed the oplog retention period. Since the oplog is crucial for incremental updates, an invalid resume token will require the MongoDB collection to be re-imported to ensure no source updates were missed. This is why the recommended solutions involve: - Increasing the oplog retention period (ideally to hold at least 24 hours, preferably a week of changes) - Increasing sync frequency so syncs complete before the oplog position expires - Resetting the connection when the resume token becomes invalid
i
@kapa.ai my oplog retention period is 24 hrs while my airbyte frequenyc is also around that 24 hours. Would this cause a problem ?
k
A message from kapa.ai
Yes, having both your oplog retention period and sync frequency at 24 hours is problematic and likely causing your issues. ## Why This Is a Problem According to the [CDC best practices documentation](https://docs.airbyte.com/platform/understanding-airbyte/cdc-best-practices#general-airbyte-configuration), there's a critical requirement: "Sync frequency must be shorter than WAL retention period" - If retention is 3 days, sync at least every 2 days - This prevents LSN loss and sync failures The documentation explicitly states: "While 7-day retention is recommended for all scenarios, you may use shorter retention periods (3+ days) if your database is highly active and you're confident your sync frequency will remain consistent." ## What's Happening in Your Case With a 24-hour oplog retention and 24-hour sync frequency, you have no buffer. This means: 1. If a sync takes longer than expected to complete 2. If there's any delay in starting the next sync 3. If the sync fails and needs to retry ...the resume token from the previous sync will already be purged from the oplog before the next sync can use it. As noted in [issue #62833](https://github.com/airbytehq/airbyte/issues/62833), a contributor explained: "Within that window, you need at least one successful sync that reads changes and advances the LSN. If the LSN does not advance before the oplog recycles, you can lose the position and the following sync will fail." ## Recommended Solution Based on the [best practices documentation](https://docs.airbyte.com/platform/understanding-airbyte/cdc-best-practices#general-airbyte-configuration), you should: 1. Increase your oplog retention to 7 days (recommended for all scenarios) 2. Increase your sync frequency - for near real-time replication with 7-day retention, sync every 1-4 hours 3. Ensure at least one successful sync runs per day that reads data so the LSN advances The 7-day retention provides a buffer against unexpected delays or maintenance windows, which is exactly what you need to avoid the "Saved offset is not valid" errors you're experiencing.