Hello! We are on Airbyte Self hosted community v1....
# replication-troubleshooting
r
Hello! We are on Airbyte Self hosted community v1.7.1. 3 weeks ago we were getting a lot of
Copy code
Failure in source: Saved offset is not valid. Please reset the connection, and then increase oplog retention and/or increase sync frequency to prevent his from happening in the future
errors when using source-mongo-v2. We found out that there was a fix and implemented that fix. It resolved the majority of our issues except for two of our sources. On those two sources we still get the errors. Our team has looked at the source oplog and says there shouldn't be issues: Our oplog has a min retention time of two weeks and 50GB. We see that the resume token is actually even still valid when we try it out! I was wondering if there might be anyone that has experienced the same thing and might have some recommendations on what to check.
k
Based on the information in the knowledge sources, you are not alone in experiencing persistent "Saved offset is not valid" errors with source-mongodb-v2, even after applying the fix from issue #62833. Several users have reported similar issues where: - The oplog retention is more than sufficient (e.g., 7 days or more, sometimes even 2 weeks and 50GB). - The resume token appears valid when tested manually. - The error still occurs intermittently or on specific sources, despite other sources working fine with the same configuration. Here are some key points and recommendations gathered from the knowledge sources: ### 1. Oplog Permissions and Visibility Some users discovered that the Airbyte MongoDB user lacked sufficient permissions to read the oplog stats, causing the connector to fall back to a default (possibly incorrect) oplog size. This can lead to unexpected "offset not valid" errors, even if the oplog is large enough. Ensure your Airbyte MongoDB user has at least
read
access on the
local
database. When this permission is missing, you may see warnings like:
Copy code
Unable to query for op log stats, exception: {}Command failed with error 13 (Unauthorized): ‘not authorized on local to execute command { collStats: “oplog.rs”, $db: “local”, ... }’
After granting the correct permissions, the logs should show the actual oplog size, e.g.:
Copy code
Max oplog size is 78383153152 bytes Free space in oplog is 10821718016 bytes
[See user report and mitigation](https://github.com/airbytehq/airbyte/issues/48496#issuecomment-2879259974) ### 2. State/Resume Token Issues There have been cases where the Airbyte state contains multiple resume tokens, and only one is updated, leading to failures. This was addressed in the 2.0.4 fix, but some users still see issues with state not updating as expected for certain sources. Manually updating the stale resume token with the current one has been used as a workaround, but this is not a long-term solution. If you see two state entries, this could be a sign of the issue. ### 3. Data Movement and Sync Frequency If there is little or no data movement in the source collection, the LSN (log sequence number) may not advance, and the resume token can become invalid even if the oplog is large. Ensure that at least some data is being written to the source between syncs, or consider increasing sync frequency to ensure the connector can always find the resume token in the oplog window. This is especially important if your syncs are infrequent or your collections are mostly static[Connector Limitations](https://docs.airbyte.com/integrations/sources/mongodb-v2/mongodb-v2-troubleshooting#connector-limitations). ### 4. Read Preference and Other Configurations Some users reported using
readPreference=secondaryPreferred
and still encountering the issue. There is no clear evidence in the knowledge sources that this is the root cause, but it is worth testing with different read preferences if possible. ### 5. Version-Specific Bugs There have been ongoing fixes and dev builds (e.g., 2.0.4-dev.5b6b076be4) addressing these issues. If you are not already on the latest stable or dev build, consider testing with the most recent version, as some users have reported improvements after upgrading, though not all issues are fully resolved for every environment. --- Summary of Recommendations: - Double-check that your Airbyte MongoDB user has
read
access on the
local
database so the connector can accurately read oplog stats. - Review your Airbyte state for multiple resume tokens and ensure only the correct, up-to-date token is present. - Ensure there is some data movement in the source collections between syncs, or increase sync frequency. - Test with the latest connector version or dev build if you haven't already. - If the issue persists, consider opening a new GitHub issue with detailed logs, oplog stats, and state information, as the Airbyte team is actively working on these problems and may request more details for further troubleshooting. If you have already checked all of the above and the problem persists, unfortunately, the knowledge sources do not provide a definitive root cause or solution for your specific scenario. The issue appears to be complex and may require direct support from the Airbyte team with detailed logs and configuration information. Let me know if you need help with specific log analysis or further troubleshooting steps!
r
@kapa.ai how would giving read to local database help?
k
A message from kapa.ai
Granting
read
access to the
local
database in MongoDB allows the Airbyte connector to query the oplog statistics directly. This is important because, without this permission, the connector cannot determine the actual size and retention window of the oplog. When the connector lacks this access, it falls back to a default or assumed oplog size, which may be incorrect and can lead to the "Saved offset is not valid" error—even if your actual oplog is large enough. A user reported that after granting
read@local
to the Airbyte MongoDB user, the warning about being unable to query oplog stats disappeared from the logs, and the connector was able to retrieve and use the correct oplog size. This resolved the offset error for them: > We gave "read@local" to the Airbyte MongoDB user. Once that is done, the above warning is gone, and instead you'll see something like this: > >
Copy code
> Max oplog size is 78383153152 bytes > Free space in oplog is 10821718016 bytes >
> > The logs now show that the connector was able to retrieve the oplog size and thus, can do its optimization. By doing so, the error mention in the issue description disappeared. > > [See user report and mitigation](https://github.com/airbytehq/airbyte/issues/48496#issuecomment-2879259974) In summary, giving
read
access to the
local
database helps the Airbyte MongoDB connector accurately determine oplog stats, which is critical for reliable incremental syncs and avoiding offset errors.
r
@kapa.ai well. when i give it that access: source WARN main i.a.i.s.m.c.MongoDbCdcInitializer(logOplogInfo):347 Unable to query for op log stats, exception: {}class java.lang.Integer cannot be cast to class java.lang.Long (java.lang.Integer and java.lang.Long are in module java.base of loader 'bootstrap')
k
A message from kapa.ai
The error message you are seeing:
Copy code
Unable to query for op log stats, exception: {}class java.lang.Integer cannot be cast to class java.lang.Long (java.lang.Integer and java.lang.Long are in module java.base of loader 'bootstrap')
is a known issue that has been reported by other Airbyte users as well. This error occurs even after granting the correct
read
access to the
local
database. It is not a permissions issue, but rather a bug in the connector code where the type returned by MongoDB for the oplog size is sometimes an
Integer
instead of a
Long
, and the connector does not handle this type mismatch gracefully. This specific problem was discussed in [issue #62833](https://github.com/airbytehq/airbyte/issues/62833), where users reported that the connector would fail with this class cast exception, leading to the "Saved offset is not valid" error. The Airbyte team released a fix in a development build (e.g.,
2.0.4-dev.5b6b076be4
) to address this type handling issue. Recommendation: If you are still seeing this error after updating permissions, you should ensure you are running a version of the MongoDB source connector that includes the fix for this bug. If you are already on a recent version and still encounter the issue, it may be worth testing the latest dev build or reaching out to the Airbyte team for further support, as this is a connector-side bug and not something you can resolve with configuration or permissions alone. For more details, see the discussion and fix in [issue #62833](https://github.com/airbytehq/airbyte/issues/62833).
r
@kapa.ai where can i find the pr that fixed this
k
A message from kapa.ai
The fix for the
class java.lang.Integer cannot be cast to class java.lang.Long
error in the MongoDB source connector is referenced in the discussion of [issue #62833](https://github.com/airbytehq/airbyte/issues/62833). The Airbyte team provided a development build (
2.0.4-dev.5b6b076be4
) that addresses this issue, but the specific pull request (PR) number is not explicitly mentioned in the knowledge sources provided. The changelog for the connector also does not directly reference a PR for this particular type-casting fix. Therefore, based on the available knowledge sources, I’m sorry, but there is no direct link to the exact PR that fixed this issue. The information only confirms that the fix is included in the
2.0.4
version and its related dev build, as discussed in the GitHub issue comments[issue #62833](https://github.com/airbytehq/airbyte/issues/62833).
m
Maybe not related, but we had the same kind of issue with our Airbyte <> Postgres connection in CDC mode. We have not completely solved it, and we are still checking many things, but the issue got much alleviated when we increased the resources of the job (cpu & memory). Particularly the latter, because our rows are very dense.
r
@Manuel Pozo thanks for chiming in! just to clarify you didn't add more resources to postgres but the airbyte sync job itself? Guessing you did it via one of these methods listed here? I've found that updating actor_definitions doesn't work and only connection level configuration works so we started looking at setting the resource requirements in the metadata.yaml of a custom source-mongodb-v2 connector. Do you mind sharing what cpu and memory worked for you and how you ended up doing it? 😄