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

[improve]Improve the hard code in CDC whole database synchronization #443

Merged
merged 4 commits into from
Jul 25, 2024

Conversation

DongLiang-0
Copy link
Contributor

@DongLiang-0 DongLiang-0 commented Jul 24, 2024

Proposed changes

Issue Number: close #xxx

Problem Summary:

There is a lot of hard code in the code of synchronizing the whole databases. This method can easily lead to inconsistent configurations on both sides. And it brings a very bad experience to subsequent development or code reading.

Checklist(Required)

  1. Does it affect the original behavior: (Yes/No/I Don't know)
  2. Has unit tests been added: (Yes/No/No Need)
  3. Has document been added or modified: (Yes/No/No Need)
  4. Does it need to update dependencies: (Yes/No)
  5. Are there any changes that cannot be rolled back: (Yes/No)

Further comments

If this is a relatively large or complex change, kick off the discussion at dev@doris.apache.org by explaining why you chose the solution you did and what alternatives you considered, etc...

@DongLiang-0 DongLiang-0 marked this pull request as draft July 24, 2024 09:01
@DongLiang-0 DongLiang-0 force-pushed the cdc-config branch 2 times, most recently from b76df27 to 0a6bf96 Compare July 24, 2024 09:12
@DongLiang-0 DongLiang-0 marked this pull request as ready for review July 24, 2024 10:26
Comment on lines +181 to +187
case DatabaseSyncConfig.SCAN_STARTUP_MODE_VALUE_INITIAL:
mongoDBSourceBuilder.startupOptions(StartupOptions.initial());
break;
case LATEST_OFFSET_MODE:
case DatabaseSyncConfig.SCAN_STARTUP_MODE_VALUE_LATEST_OFFSET:
mongoDBSourceBuilder.startupOptions(StartupOptions.latest());
break;
case TIMESTAMP_MODE:
case DatabaseSyncConfig.SCAN_STARTUP_MODE_VALUE_TIMESTAMP:
Copy link
Member

Choose a reason for hiding this comment

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

Can we use cdc variables directly here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

These parameters of flink-cdc cannot be directly referenced because they are also privately defined.

Comment on lines +51 to +62
DEFAULT_PROPS.setProperty(DatabaseSyncConfig.CONVERTERS, DatabaseSyncConfig.DATE);
DEFAULT_PROPS.setProperty(
"date.type", "org.apache.doris.flink.tools.cdc.mysql.DateToStringConverter");
DEFAULT_PROPS.setProperty("date.format.date", "yyyy-MM-dd");
DEFAULT_PROPS.setProperty("date.format.datetime", "yyyy-MM-dd HH:mm:ss.SSSSSS");
DEFAULT_PROPS.setProperty("date.format.timestamp", "yyyy-MM-dd HH:mm:ss.SSSSSS");
DEFAULT_PROPS.setProperty("date.format.timestamp.zone", "UTC+8");
DatabaseSyncConfig.DATE_TYPE,
"org.apache.doris.flink.tools.cdc.mysql.DateToStringConverter");
DEFAULT_PROPS.setProperty(
DatabaseSyncConfig.DATE_FORMAT_DATE, DatabaseSyncConfig.YEAR_MONTH_DAY_FORMAT);
DEFAULT_PROPS.setProperty(
DatabaseSyncConfig.DATE_FORMAT_DATETIME, DatabaseSyncConfig.DATETIME_MICRO_FORMAT);
DEFAULT_PROPS.setProperty(
DatabaseSyncConfig.DATE_FORMAT_TIMESTAMP, DatabaseSyncConfig.DATETIME_MICRO_FORMAT);
DEFAULT_PROPS.setProperty(
DatabaseSyncConfig.DATE_FORMAT_TIMESTAMP_ZONE, DatabaseSyncConfig.TIME_ZONE_UTC_8);
Copy link
Member

Choose a reason for hiding this comment

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

If it is only used here, I think it is better to define it inside this convert class

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Each source corresponds to a DateConverter, which basically contains these parameters.

Comment on lines +68 to +86
props,
DatabaseSyncConfig.FORMAT_DATE,
p -> dateFormatter = DateTimeFormatter.ofPattern(p));
readProps(
props,
"format.timestamp",
DatabaseSyncConfig.FORMAT_TIME,
p -> timeFormatter = DateTimeFormatter.ofPattern(p));
readProps(
props,
DatabaseSyncConfig.FORMAT_DATETIME,
p -> datetimeFormatter = DateTimeFormatter.ofPattern(p));
readProps(
props,
DatabaseSyncConfig.FORMAT_TIMESTAMP,
p -> timestampFormatter = DateTimeFormatter.ofPattern(p));
readProps(props, "format.timestamp.zone", z -> timestampZoneId = ZoneId.of(z));
readProps(
props,
DatabaseSyncConfig.FORMAT_TIMESTAMP_ZONE,
z -> timestampZoneId = ZoneId.of(z));
Copy link
Member

Choose a reason for hiding this comment

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

same above

Copy link
Member

@JNSimba JNSimba left a comment

Choose a reason for hiding this comment

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

LGTM

@JNSimba JNSimba merged commit a547ad2 into apache:master Jul 25, 2024
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants