Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MySQL CDC sync fails because starting binlog position not found in DB #6425 #9514

Merged
merged 12 commits into from
Feb 10, 2022

Conversation

mkhokh-33
Copy link
Contributor

@mkhokh-33 mkhokh-33 commented Jan 14, 2022

What

Check required binlog for CDC sync on mysql server before data sync and add error description into log if it absent

How

Before start CDC sync implementation will check required binary log on mysql server and if it's absent will add error description about it with corresponding explanation and as possible solution will as to make "reset data"

Recommended reading order

  1. x.java
  2. y.python

🚨 User Impact 🚨

Are there any breaking changes? What is the end result perceived by the user? If yes, please merge this PR with the 🚨🚨 emoji so changelog authors can further highlight this if needed.

Pre-merge Checklist

Expand the relevant checklist and delete the others.

New Connector

Community member or Airbyter

  • Community member? Grant edit access to maintainers (instructions)
  • Secrets in the connector's spec are annotated with airbyte_secret
  • Unit & integration tests added and passing. Community members, please provide proof of success locally e.g: screenshot or copy-paste unit, integration, and acceptance test output. To run acceptance tests for a Python connector, follow instructions in the README. For java connectors run ./gradlew :airbyte-integrations:connectors:<name>:integrationTest.
  • Code reviews completed
  • Documentation updated
    • Connector's README.md
    • Connector's bootstrap.md. See description and examples
    • docs/SUMMARY.md
    • docs/integrations/<source or destination>/<name>.md including changelog. See changelog example
    • docs/integrations/README.md
    • airbyte-integrations/builds.md
  • PR name follows PR naming conventions

Airbyter

If this is a community PR, the Airbyte engineer reviewing this PR is responsible for the below items.

  • Create a non-forked branch based on this PR and test the below items on it
  • Build is successful
  • Credentials added to Github CI. Instructions.
  • /test connector=connectors/<name> command is passing.
  • New Connector version released on Dockerhub by running the /publish command described here
  • After the connector is published, connector added to connector index as described here
  • Seed specs have been re-generated by building the platform and committing the changes to the seed spec files, as described here

Updating a connector

Community member or Airbyter

  • Grant edit access to maintainers (instructions)
  • Secrets in the connector's spec are annotated with airbyte_secret
  • Unit & integration tests added and passing. Community members, please provide proof of success locally e.g: screenshot or copy-paste unit, integration, and acceptance test output. To run acceptance tests for a Python connector, follow instructions in the README. For java connectors run ./gradlew :airbyte-integrations:connectors:<name>:integrationTest.
  • Code reviews completed
  • Documentation updated
    • Connector's README.md
    • Connector's bootstrap.md. See description and examples
    • Changelog updated in docs/integrations/<source or destination>/<name>.md including changelog. See changelog example
  • PR name follows PR naming conventions

Airbyter

If this is a community PR, the Airbyte engineer reviewing this PR is responsible for the below items.

  • Create a non-forked branch based on this PR and test the below items on it
  • Build is successful
  • Credentials added to Github CI. Instructions.
  • /test connector=connectors/<name> command is passing.
  • New Connector version released on Dockerhub by running the /publish command described here
  • After the new connector version is published, connector version bumped in the seed directory as described here
  • Seed specs have been re-generated by building the platform and committing the changes to the seed spec files, as described here

Connector Generator

  • Issue acceptance criteria met
  • PR name follows PR naming conventions
  • If adding a new generator, add it to the list of scaffold modules being tested
  • The generator test modules (all connectors with -scaffold in their name) have been updated with the latest scaffold by running ./gradlew :airbyte-integrations:connector-templates:generator:testScaffoldTemplates then checking in your changes
  • Documentation which references the generator is updated as needed.


This change is Reviewable

@github-actions github-actions bot added area/connectors Connector related issues area/documentation Improvements or additions to documentation labels Jan 14, 2022
@mkhokh-33 mkhokh-33 temporarily deployed to more-secrets January 14, 2022 13:49 Inactive
@mkhokh-33
Copy link
Contributor Author

mkhokh-33 commented Jan 14, 2022

/test connector=connectors/source-mysql

🕑 connectors/source-mysql https://github.com/airbytehq/airbyte/actions/runs/1698036559
✅ connectors/source-mysql https://github.com/airbytehq/airbyte/actions/runs/1698036559
No Python unittests run

@mkhokh-33
Copy link
Contributor Author

mkhokh-33 commented Jan 14, 2022

/test connector=connectors/source-mysql-strict-encrypt

🕑 connectors/source-mysql-strict-encrypt https://github.com/airbytehq/airbyte/actions/runs/1698038159
❌ connectors/source-mysql-strict-encrypt https://github.com/airbytehq/airbyte/actions/runs/1698038159
🐛

@octavia-squidington-iii octavia-squidington-iii temporarily deployed to more-secrets January 14, 2022 14:09 Inactive
@octavia-squidington-iii octavia-squidington-iii temporarily deployed to more-secrets January 14, 2022 14:10 Inactive
@mkhokh-33 mkhokh-33 temporarily deployed to more-secrets January 14, 2022 14:10 Inactive
@mkhokh-33
Copy link
Contributor Author

mkhokh-33 commented Jan 14, 2022

/test connector=connectors/source-mysql-strict-encrypt

🕑 connectors/source-mysql-strict-encrypt https://github.com/airbytehq/airbyte/actions/runs/1698142773
✅ connectors/source-mysql-strict-encrypt https://github.com/airbytehq/airbyte/actions/runs/1698142773
No Python unittests run

@mkhokh-33 mkhokh-33 temporarily deployed to more-secrets January 14, 2022 14:34 Inactive
@octavia-squidington-iii octavia-squidington-iii temporarily deployed to more-secrets January 14, 2022 14:35 Inactive
@mkhokh-33 mkhokh-33 temporarily deployed to more-secrets January 14, 2022 14:51 Inactive
@mkhokh-33 mkhokh-33 temporarily deployed to more-secrets January 14, 2022 15:23 Inactive
@mkhokh-33 mkhokh-33 temporarily deployed to more-secrets January 17, 2022 09:40 Inactive
@mkhokh-33 mkhokh-33 temporarily deployed to more-secrets January 17, 2022 10:07 Inactive
@mkhokh-33 mkhokh-33 temporarily deployed to more-secrets January 17, 2022 11:11 Inactive
@mkhokh-33 mkhokh-33 temporarily deployed to more-secrets January 17, 2022 11:38 Inactive
@mkhokh-33 mkhokh-33 marked this pull request as ready for review January 17, 2022 12:52
@mkhokh-33 mkhokh-33 temporarily deployed to more-secrets January 18, 2022 08:42 Inactive
@@ -180,8 +185,12 @@ private static boolean shouldUseCDC(final ConfiguredAirbyteCatalog catalog) {
new AirbyteDebeziumHandler(sourceConfig, MySqlCdcTargetPosition.targetPosition(database), MySqlCdcProperties.getDebeziumProperties(),
catalog, true);

return handler.getIncrementalIterators(new MySqlCdcSavedInfoFetcher(stateManager.getCdcStateManager().getCdcState()),
new MySqlCdcStateHandler(stateManager), new MySqlCdcConnectorMetadataInjector(), emittedAt);
CdcState cdcState = stateManager.getCdcStateManager().getCdcState();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could stateManager.getCdcStateManager() return null?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no, from what I can see from the code :
public StateManager(final DbState serialized, final ConfiguredAirbyteCatalog catalog) {
this.cdcStateManager = new CdcStateManager(serialized.getCdcState());
this.isCdc = serialized.getCdc();
if (serialized.getCdc() == null) {
this.isCdc = false;
}

new MySqlCdcStateHandler(stateManager), new MySqlCdcConnectorMetadataInjector(), emittedAt);
CdcState cdcState = stateManager.getCdcStateManager().getCdcState();
MySqlCdcSavedInfoFetcher fetcher = new MySqlCdcSavedInfoFetcher(cdcState);
if (cdcState != null) {
Copy link
Contributor

@alexandertsukanov alexandertsukanov Jan 19, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it possible to use Optional type here?

@@ -229,4 +238,42 @@ public static void main(final String[] args) throws Exception {
};
}

private void checkBinlog(JsonNode offset, JdbcDatabase database) {
String binlog = getBinlog(offset);
if (binlog != null && !binlog.isEmpty()) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it possible to use Optional type here?

LOGGER.info(String.format("Binlog %s is available", binlog));
} else {
String error =
String.format("Binlog %s is not available. This is a critical error, it means that requested binlog is not present on mysql server. " +
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe, we can use Text block here instead of string concatenation https://openjdk.java.net/jeps/378, as we migrate to Java 17.

Map.Entry<String, JsonNode> jsonField = fields.next();
return Jsons.deserialize(jsonField.getValue().asText()).path("file").asText();
}
return null;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we return null here?

@mkhokh-33 mkhokh-33 temporarily deployed to more-secrets February 1, 2022 17:57 Inactive
@mkhokh-33 mkhokh-33 temporarily deployed to more-secrets February 1, 2022 18:29 Inactive
@mkhokh-33
Copy link
Contributor Author

mkhokh-33 commented Feb 1, 2022

/test connector=connectors/source-mysql

🕑 connectors/source-mysql https://github.com/airbytehq/airbyte/actions/runs/1780403486
✅ connectors/source-mysql https://github.com/airbytehq/airbyte/actions/runs/1780403486
No Python unittests run

@mkhokh-33
Copy link
Contributor Author

mkhokh-33 commented Feb 1, 2022

/test connector=connectors/source-mysql-strict-encrypt

🕑 connectors/source-mysql-strict-encrypt https://github.com/airbytehq/airbyte/actions/runs/1780404136
✅ connectors/source-mysql-strict-encrypt https://github.com/airbytehq/airbyte/actions/runs/1780404136
No Python unittests run

@octavia-squidington-iii octavia-squidington-iii temporarily deployed to more-secrets February 1, 2022 19:57 Inactive
@octavia-squidington-iii octavia-squidington-iii temporarily deployed to more-secrets February 1, 2022 19:57 Inactive
Comment on lines +53 to +59
String error =
"""
Binlog %s is not available. This is a critical error, it means that requested binlog is not present on mysql server. To fix data synchronization you need to reset your data. Please check binlog retention policy configurations."""
.formatted(binlog);
LOGGER.error(error);
throw new RuntimeException("""
Binlog %s is not available.""".formatted(binlog));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this part of the code executed too if binlogOptional.ifPresent is not true?

Copy link
Contributor Author

@mkhokh-33 mkhokh-33 Feb 4, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this part of the code executed too if binlogOptional.ifPresent is not true?

  • binlogOptional.ifPresent check that saved cdc_offset contain information about last sync binlog and returns binlog file name

  • if (isBinlogAvailable(binlog, database)) - will check that required for sync binlog file is present on mysql-server

if binlog is not on mysql server anymore only then this part of code will be executed.

@alexandr-shegeda
Copy link
Contributor

@ChristopheDuong can we proceed with publishing this changes?
cc @misteryeo @oustynova

@mkhokh-33 mkhokh-33 temporarily deployed to more-secrets February 10, 2022 09:13 Inactive
@mkhokh-33
Copy link
Contributor Author

mkhokh-33 commented Feb 10, 2022

/publish connector=connectors/source-mysql

🕑 connectors/source-mysql https://github.com/airbytehq/airbyte/actions/runs/1824009361
✅ connectors/source-mysql https://github.com/airbytehq/airbyte/actions/runs/1824009361

@mkhokh-33 mkhokh-33 temporarily deployed to more-secrets February 10, 2022 13:29 Inactive
@mkhokh-33
Copy link
Contributor Author

mkhokh-33 commented Feb 10, 2022

/publish connector=connectors/source-mysql-strict-encrypt

🕑 connectors/source-mysql-strict-encrypt https://github.com/airbytehq/airbyte/actions/runs/1824010892
✅ connectors/source-mysql-strict-encrypt https://github.com/airbytehq/airbyte/actions/runs/1824010892

@octavia-squidington-iii octavia-squidington-iii temporarily deployed to more-secrets February 10, 2022 13:32 Inactive
@octavia-squidington-iii octavia-squidington-iii temporarily deployed to more-secrets February 10, 2022 13:32 Inactive
@mkhokh-33 mkhokh-33 temporarily deployed to more-secrets February 10, 2022 14:03 Inactive
@mkhokh-33
Copy link
Contributor Author

mkhokh-33 commented Feb 10, 2022

/test connector=connectors/source-mysql

🕑 connectors/source-mysql https://github.com/airbytehq/airbyte/actions/runs/1824228756
✅ connectors/source-mysql https://github.com/airbytehq/airbyte/actions/runs/1824228756
No Python unittests run

@mkhokh-33
Copy link
Contributor Author

mkhokh-33 commented Feb 10, 2022

/publish connector=connectors/source-mysql-strict-encrypt

🕑 connectors/source-mysql-strict-encrypt https://github.com/airbytehq/airbyte/actions/runs/1824230013
❌ connectors/source-mysql-strict-encrypt https://github.com/airbytehq/airbyte/actions/runs/1824230013

@octavia-squidington-iii octavia-squidington-iii temporarily deployed to more-secrets February 10, 2022 14:17 Inactive
@octavia-squidington-iii octavia-squidington-iii temporarily deployed to more-secrets February 10, 2022 14:17 Inactive
@mkhokh-33
Copy link
Contributor Author

mkhokh-33 commented Feb 10, 2022

/test connector=connectors/source-mysql-strict-encrypt

🕑 connectors/source-mysql-strict-encrypt https://github.com/airbytehq/airbyte/actions/runs/1824259499
✅ connectors/source-mysql-strict-encrypt https://github.com/airbytehq/airbyte/actions/runs/1824259499
No Python unittests run

@octavia-squidington-iii octavia-squidington-iii temporarily deployed to more-secrets February 10, 2022 14:22 Inactive
@mkhokh-33 mkhokh-33 merged commit b230543 into master Feb 10, 2022
@mkhokh-33 mkhokh-33 deleted the mkhokh/6425-mysql-source-cdc-binlog-not-found branch February 10, 2022 14:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/connectors Connector related issues area/documentation Improvements or additions to documentation
Projects
None yet
Development

Successfully merging this pull request may close these issues.

MySQL CDC sync fails because starting binlog position not found in DB
5 participants