<@U04S8PLJWMT> I have a slow moving table on mongo...
# ask-ai
t
@kapa.ai I have a slow moving table on mongodb which has to be moved to Snowflake on incremental basis. I have 24 hours oplog but even with 12 hours I don't have enough documents to keep it running without failing with saved offset not valid error
k
Based on the knowledge sources, the "Saved offset is not valid" error you're experiencing with slow-moving MongoDB tables is a known issue with the MongoDB connector, particularly when syncing tables with infrequent changes. ## The Core Problem The issue occurs because when using CDC (Change Data Capture) with MongoDB, the LSN (Log Sequence Number) needs to advance with each sync. If a table has no data changes between syncs, the resume token doesn't update properly, and eventually falls outside the oplog retention window, causing the sync to fail. As explained in the [GitHub issue comments](https://github.com/airbytehq/airbyte/issues/62833): > "When using CDC, it's important to include a table with data movement so the LSN continues to advance and doesn't get lost." ## Recommended Solutions 1. Ensure at least one table with active changes: Include at least one table in your sync that has regular data movement. This ensures the LSN advances with each sync, even if your slow-moving table has no changes. 2. Increase oplog retention: While you have 24 hours, the recommendation is to expand it to maintain at least a week's worth of data for optimal results. See the [MongoDB troubleshooting documentation](https://docs.airbyte.com/integrations/sources/mongodb-v2/mongodb-v2-troubleshooting#connector-limitations). 3. Grant read permissions on the local database: Some users found that granting
read@local
permissions to the Airbyte MongoDB user helped the connector properly read oplog size and manage resume tokens. This was mentioned in [this GitHub comment](https://github.com/airbytehq/airbyte/issues/48496). 4. Try the latest connector version: There's a fix available in version 2.0.4 (or the dev version
2.0.4-dev.5b6b076be4
) that addresses some of these resume token issues, as mentioned in [this GitHub issue](https://github.com/airbytehq/airbyte/issues/62833). ## Important Note The 24-hour oplog retention may be insufficient for your workload, especially with slow-moving tables. You need at least one successful sync that reads changes and advances the LSN within that window, or the position can be lost when the oplog recycles.
The "Saved offset is not valid" error in Airbyte's MongoDB source connector is a common issue when syncing slow-moving tables, especially with limited oplog retention (e.g., 24 hours). This happens because the connector relies on MongoDB's oplog to track changes for incremental syncs. If there are no changes in the collection for a period longer than the oplog retention window, the resume token (offset) saved by Airbyte becomes invalid—MongoDB has already purged the relevant oplog entries, so the connector cannot resume from the last known position and fails with this error. Key points from the knowledge sources: - Oplog Retention Limitation: If your sync frequency is less than the oplog retention period, and there are no changes in the collection, the resume token can become invalid. This is especially problematic for slow-moving tables where changes are infrequent. The documentation explicitly states: > "Syncs that run less frequently than the retention period of the Oplog may encounter issues with missing data." > "When importing a large MongoDB collection for the first time, the import duration might exceed the Oplog retention period. The Oplog is crucial for incremental updates, and an invalid resume token will require the MongoDB collection to be re-imported to ensure no source updates were missed." [Troubleshooting MongoDB Sources](https://docs.airbyte.com/integrations/sources/mongodb-v2/mongodb-v2-troubleshooting#connector-limitations) - Workarounds and Recommendations: - Increase Oplog Retention: The most reliable solution is to increase the oplog size so it can retain changes for a longer period (ideally a week or more). However, this may not be feasible in all environments. - Increase Sync Frequency: Run syncs more frequently than the oplog retention window, but as you noted, if there are no changes, this alone may not help. - Ensure Data Movement: The connector needs at least one change in the collection within the oplog window to advance the resume token. If there are no changes, the offset will not advance, and the next sync may fail once the oplog recycles. > "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." [Github Issue #62833](https://github.com/airbytehq/airbyte/issues/62833) - Manual Workarounds: Some users have resorted to manually updating the resume token in the connection state, but this is not a sustainable or recommended solution for production. - No Permanent Fix Yet: Even with recent connector updates (e.g., v2.0.4), users still report this issue for slow-moving tables, especially when the oplog window is not long enough to cover periods of inactivity. [Github Issue #62833](https://github.com/airbytehq/airbyte/issues/62833) Summary: For slow-moving tables, you must ensure that either: - The oplog retention is long enough to cover the longest period without changes in your collection, or - There is at least one change in the collection within every oplog window (which may not be practical). Otherwise, the "Saved offset is not valid" error is likely to recur, and there is currently no built-in Airbyte solution to handle this scenario automatically. If you cannot increase the oplog retention or guarantee regular changes, you may need to periodically reset the connection and perform a full re-sync to avoid data loss. If you need more robust handling for slow-moving tables, you may want to follow ongoing Airbyte issues for updates or request a feature that better supports this use case.
t
So if I increase the OPLog retention to 30h and keep the sync interval for 24 hours. It would solve the issue?
@kapa.ai So if I increase the OPLog retention to 30h and keep the sync interval for 24 hours. It would solve the issue?
k
A message from kapa.ai
Based on the knowledge sources, increasing the oplog retention to 30 hours with a 24-hour sync interval may not fully solve your issue, especially for slow-moving tables. ## Why This May Not Be Enough The core problem isn't just about having enough oplog retention time relative to your sync frequency. As explained in the [GitHub issue](https://github.com/airbytehq/airbyte/issues/62833): > "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." The critical issue: If your slow-moving table has no changes between syncs, the resume token doesn't advance, even if you sync within the oplog retention window. This means the saved offset can still become invalid. ## What You Should Do Instead 1. Include a table with regular changes: Add at least one table to your sync that has frequent data movement. This ensures the LSN advances with each sync, even when your slow-moving table has no changes. 2. Increase oplog retention significantly: The [MongoDB troubleshooting documentation](https://docs.airbyte.com/integrations/sources/mongodb-v2/mongodb-v2-troubleshooting#connector-limitations) recommends: > "We recommend adjusting the Oplog size for your MongoDB cluster to ensure it holds at least 24 hours of changes. For optimal results, we suggest expanding it to maintain a week's worth of data." 3. Ensure data movement: As stated in the [GitHub comments](https://github.com/airbytehq/airbyte/issues/62833): > "make sure you run a sync at least once per day and that it reads data so the LSN advances before oplog retention is reached." Simply increasing the buffer between oplog retention and sync frequency won't solve the underlying issue if there's no data movement to advance the LSN.