-
Notifications
You must be signed in to change notification settings - Fork 3.8k
[Improve](streaming-job) support specifying offset for StreamingInsertJob create and alter #62490
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
Changes from all commits
d0fd0b1
44f21e4
14306bb
7ccb97b
5360d8f
4a8183a
a543e1b
651316b
3537e0e
0feb39c
70eaeff
d605d89
528a075
b7c7a15
0865d94
98ca5b9
85a43d1
daf67ba
1349e84
7836643
2b7aae6
0811de1
c28ab44
c7b1dcd
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -369,6 +369,17 @@ public void initLogicalPlan(boolean regen) { | |
| } | ||
| } | ||
|
|
||
| /** | ||
| * Validate the offset format for ALTER JOB, delegating to the provider. | ||
| */ | ||
| public void validateAlterOffset(String offset) throws AnalysisException { | ||
| try { | ||
| offsetProvider.validateAlterOffset(offset); | ||
| } catch (Exception ex) { | ||
| throw new AnalysisException(ex.getMessage()); | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * Check whether Offset can be serialized into the corresponding data source | ||
| * */ | ||
|
|
@@ -793,11 +804,12 @@ public void replayOnUpdated(StreamingInsertJob replayJob) { | |
| */ | ||
| private void modifyPropertiesInternal(Map<String, String> inputProperties) throws AnalysisException, JobException { | ||
| StreamingJobProperties inputStreamProps = new StreamingJobProperties(inputProperties); | ||
| if (StringUtils.isNotEmpty(inputStreamProps.getOffsetProperty()) | ||
| && S3TableValuedFunction.NAME.equalsIgnoreCase(this.tvfType)) { | ||
| if (StringUtils.isNotEmpty(inputStreamProps.getOffsetProperty())) { | ||
| Offset offset = validateOffset(inputStreamProps.getOffsetProperty()); | ||
|
JNSimba marked this conversation as resolved.
|
||
| this.offsetProvider.updateOffset(offset); | ||
| this.offsetProviderPersist = offsetProvider.getPersistInfo(); | ||
| log.info("modifyPropertiesInternal: offset updated to {}, job {}", | ||
| inputStreamProps.getOffsetProperty(), getJobId()); | ||
| if (Config.isCloudMode()) { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
| resetCloudProgress(offset); | ||
| } | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -18,6 +18,7 @@ | |
| package org.apache.doris.job.offset.jdbc; | ||
|
|
||
| import org.apache.doris.catalog.Env; | ||
| import org.apache.doris.common.AnalysisException; | ||
| import org.apache.doris.httpv2.entity.ResponseBody; | ||
| import org.apache.doris.httpv2.rest.RestApiStatusCode; | ||
| import org.apache.doris.job.cdc.DataSourceConfigKeys; | ||
|
|
@@ -29,6 +30,7 @@ | |
| import org.apache.doris.job.cdc.split.SnapshotSplit; | ||
| import org.apache.doris.job.common.DataSourceType; | ||
| import org.apache.doris.job.exception.JobException; | ||
| import org.apache.doris.job.extensions.insert.streaming.DataSourceConfigValidator; | ||
| import org.apache.doris.job.extensions.insert.streaming.StreamingInsertJob; | ||
| import org.apache.doris.job.extensions.insert.streaming.StreamingJobProperties; | ||
| import org.apache.doris.job.offset.Offset; | ||
|
|
@@ -361,10 +363,33 @@ public Offset deserializeOffset(String offset) { | |
|
|
||
| @Override | ||
| public Offset deserializeOffsetProperty(String offset) { | ||
| // no need cause cdc_stream has offset property | ||
| if (offset == null || offset.trim().isEmpty()) { | ||
| return null; | ||
| } | ||
| // JSON format: {"file":"binlog.000003","pos":154} or {"lsn":"123456"} | ||
| if (DataSourceConfigValidator.isJsonOffset(offset)) { | ||
| try { | ||
| Map<String, String> offsetMap = objectMapper.readValue(offset, | ||
| new TypeReference<Map<String, String>>() {}); | ||
| return new JdbcOffset(Collections.singletonList(new BinlogSplit(offsetMap))); | ||
|
JNSimba marked this conversation as resolved.
|
||
| } catch (Exception e) { | ||
| log.warn("Failed to parse JSON offset: {}", offset, e); | ||
| return null; | ||
| } | ||
| } | ||
| return null; | ||
| } | ||
|
|
||
| @Override | ||
|
JNSimba marked this conversation as resolved.
|
||
| public void validateAlterOffset(String offset) throws Exception { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
| if (!DataSourceConfigValidator.isJsonOffset(offset)) { | ||
| throw new AnalysisException( | ||
| "ALTER JOB for CDC only supports JSON specific offset, " | ||
| + "e.g. '{\"file\":\"binlog.000001\",\"pos\":\"154\"}' for MySQL " | ||
| + "or '{\"lsn\":\"12345678\"}' for PostgreSQL"); | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * Replay snapshot splits if needed | ||
| */ | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -166,7 +166,8 @@ private void validate() throws Exception { | |
| boolean sourcePropModified = | ||
| isPropertiesModified(streamingJob.getSourceProperties(), this.getSourceProperties()); | ||
| if (sourcePropModified) { | ||
| DataSourceConfigValidator.validateSource(this.getSourceProperties()); | ||
| DataSourceConfigValidator.validateSource(this.getSourceProperties(), | ||
|
JNSimba marked this conversation as resolved.
|
||
| streamingJob.getDataSourceType().name()); | ||
| checkUnmodifiableSourceProperties(streamingJob.getSourceProperties()); | ||
| } | ||
|
|
||
|
|
@@ -213,6 +214,14 @@ private void checkUnmodifiableSourceProperties(Map<String, String> originSourceP | |
| "The exclude_tables property cannot be modified in ALTER JOB"); | ||
| } | ||
|
|
||
| if (sourceProperties.containsKey(DataSourceConfigKeys.OFFSET)) { | ||
| Preconditions.checkArgument(Objects.equals( | ||
| originSourceProperties.get(DataSourceConfigKeys.OFFSET), | ||
| sourceProperties.get(DataSourceConfigKeys.OFFSET)), | ||
| "The offset in source properties cannot be modified in ALTER JOB. " | ||
| + "Use PROPERTIES('offset'='{...}') to alter offset"); | ||
| } | ||
|
|
||
| // slot_name / publication_name decide Doris-vs-user ownership at create time; flipping | ||
| // them afterwards would orphan Doris-created resources or let Doris drop user-owned ones. | ||
| if (sourceProperties.containsKey(DataSourceConfigKeys.SLOT_NAME)) { | ||
|
|
@@ -233,9 +242,8 @@ private void checkUnmodifiableSourceProperties(Map<String, String> originSourceP | |
| private void validateProps(StreamingInsertJob streamingJob) throws AnalysisException { | ||
| StreamingJobProperties jobProperties = new StreamingJobProperties(properties); | ||
| jobProperties.validate(); | ||
| // from to job no need valiate offset in job properties | ||
| if (streamingJob.getDataSourceType() == null | ||
| && jobProperties.getOffsetProperty() != null) { | ||
| if (jobProperties.getOffsetProperty() != null) { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This only validates the |
||
| streamingJob.validateAlterOffset(jobProperties.getOffsetProperty()); | ||
| streamingJob.validateOffset(jobProperties.getOffsetProperty()); | ||
| } | ||
| } | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.