-
Notifications
You must be signed in to change notification settings - Fork 3.9k
[feature](routineload) Add routine load target-table alter support #64878
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
base: master
Are you sure you want to change the base?
Changes from all commits
fb5a55b
03cf626
a8bd6be
9b2cf36
760890d
931b717
48f1b8c
0f1be9e
4a34f9f
000c838
cd0cd0c
cfb7382
bd1fad5
77cb200
e848c18
8b19f60
e93f300
0f81dc7
ba918d0
a756d7c
0fca4e7
04a5e10
963ed3e
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 |
|---|---|---|
|
|
@@ -782,9 +782,12 @@ public void modifyProperties(AlterRoutineLoadCommand command) throws UserExcepti | |
| } | ||
|
|
||
| modifyPropertiesInternal(jobProperties, dataSourceProperties); | ||
| if (command.hasTargetTable()) { | ||
| tableId = command.getTargetTableId(); | ||
|
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. [P1] Re-seed progress when a broker-list change selects a different Kafka cluster. With the topic unchanged, modifyPropertiesInternal() only replaces brokerList; it retains progress, custom/current partitions, and the latest-offset cache. Pinned jobs then skip metadata discovery, and a dynamic job whose new cluster has the same numeric partition IDs appears unchanged, so tasks combine the new brokers and target here with offsets from the old cluster. Switching cluster A at offset 1000 to cluster B can therefore skip B's first 1000 records or pause with OFFSET_OUT_OF_RANGE. Resolve the cluster ID and any requested offsets against the effective new brokers outside the job lock; if the cluster changed, require those validated offsets or reset/reseed all progress and partition caches, persist that prepared decision for replay, and recheck the job generation before committing.
0AyanamiRei marked this conversation as resolved.
|
||
| } | ||
|
|
||
| AlterRoutineLoadJobOperationLog log = new AlterRoutineLoadJobOperationLog(this.id, | ||
| jobProperties, dataSourceProperties); | ||
| jobProperties, dataSourceProperties, command.getTargetTableId()); | ||
| Env.getCurrentEnv().getEditLog().logAlterRoutineLoadJob(log); | ||
| } finally { | ||
| writeUnlock(); | ||
|
|
@@ -908,6 +911,9 @@ private void resetCloudProgress(Cloud.ResetRLProgressRequest.Builder builder) th | |
| public void replayModifyProperties(AlterRoutineLoadJobOperationLog log) { | ||
| try { | ||
| modifyPropertiesInternal(log.getJobProperties(), (KafkaDataSourceProperties) log.getDataSourceProperties()); | ||
| if (log.getTargetTableId() != 0) { | ||
|
0AyanamiRei marked this conversation as resolved.
|
||
| tableId = log.getTargetTableId(); | ||
| } | ||
| } catch (UserException e) { | ||
| // should not happen | ||
| LOG.error("failed to replay modify kafka routine load job: {}", id, e); | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -37,12 +37,20 @@ public class AlterRoutineLoadJobOperationLog implements Writable { | |
| private Map<String, String> jobProperties; | ||
| @SerializedName(value = "dataSourceProperties") | ||
| private AbstractDataSourceProperties dataSourceProperties; | ||
| @SerializedName(value = "targetTableId") | ||
| private long targetTableId; | ||
|
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. [P1] Prevent old FE followers from silently dropping the target switch. This field is added to the existing |
||
|
|
||
| public AlterRoutineLoadJobOperationLog(long jobId, Map<String, String> jobProperties, | ||
| AbstractDataSourceProperties dataSourceProperties) { | ||
| this(jobId, jobProperties, dataSourceProperties, 0L); | ||
| } | ||
|
|
||
| public AlterRoutineLoadJobOperationLog(long jobId, Map<String, String> jobProperties, | ||
| AbstractDataSourceProperties dataSourceProperties, long targetTableId) { | ||
| this.jobId = jobId; | ||
| this.jobProperties = jobProperties; | ||
| this.dataSourceProperties = dataSourceProperties; | ||
| this.targetTableId = targetTableId; | ||
| } | ||
|
|
||
| public long getJobId() { | ||
|
|
@@ -57,6 +65,10 @@ public AbstractDataSourceProperties getDataSourceProperties() { | |
| return dataSourceProperties; | ||
| } | ||
|
|
||
| public long getTargetTableId() { | ||
| return targetTableId; | ||
| } | ||
|
|
||
| public static AlterRoutineLoadJobOperationLog read(DataInput in) throws IOException { | ||
| String json = Text.readString(in); | ||
| return GsonUtils.GSON.fromJson(json, AlterRoutineLoadJobOperationLog.class); | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -40,10 +40,13 @@ | |
| import org.apache.doris.load.routineload.kafka.KafkaRoutineLoadJob; | ||
| import org.apache.doris.load.routineload.kafka.KafkaTaskInfo; | ||
| import org.apache.doris.mysql.privilege.MockedAuth; | ||
| import org.apache.doris.nereids.trees.plans.commands.AlterRoutineLoadCommand; | ||
| import org.apache.doris.nereids.trees.plans.commands.info.CreateRoutineLoadInfo; | ||
| import org.apache.doris.nereids.trees.plans.commands.info.LabelNameInfo; | ||
| import org.apache.doris.nereids.trees.plans.commands.load.LoadProperty; | ||
| import org.apache.doris.nereids.trees.plans.commands.load.LoadSeparator; | ||
| import org.apache.doris.persist.AlterRoutineLoadJobOperationLog; | ||
| import org.apache.doris.persist.EditLog; | ||
| import org.apache.doris.qe.ConnectContext; | ||
| import org.apache.doris.thrift.TResourceInfo; | ||
|
|
||
|
|
@@ -57,6 +60,7 @@ | |
| import org.junit.Assert; | ||
| import org.junit.Before; | ||
| import org.junit.Test; | ||
| import org.mockito.ArgumentCaptor; | ||
| import org.mockito.MockedStatic; | ||
| import org.mockito.Mockito; | ||
|
|
||
|
|
@@ -237,6 +241,101 @@ public void testUpdateLagRebuildsConvertedPropertiesAfterReplay() throws UserExc | |
| } | ||
| } | ||
|
|
||
| @Test | ||
| public void testModifyTargetTableWithJobAndDataSourceProperties() throws Exception { | ||
| KafkaRoutineLoadJob routineLoadJob = new KafkaRoutineLoadJob(1L, "kafka_routine_load_job", 1L, | ||
| 101L, "127.0.0.1:9020", "topic1", UserIdentity.ADMIN); | ||
| Deencapsulation.setField(routineLoadJob, "state", RoutineLoadJob.JobState.PAUSED); | ||
| KafkaProgress progress = new KafkaProgress(Maps.newHashMap()); | ||
| Deencapsulation.setField(routineLoadJob, "progress", progress); | ||
|
|
||
| Map<String, String> sourceProperties = Maps.newHashMap(); | ||
| sourceProperties.put("property.client.id", "target-switch"); | ||
|
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. [P1] Preserve the existing Kafka default in this custom-only combined ALTER. Although this statement supplies only client.id, KafkaDataSourceProperties.analyze() falls through to analyzeKafkaDefaultOffsetProperty(), which synthesizes kafka_default_offsets=OFFSET_END; modifyPropertiesInternal() then merges that value into the live job before assigning and journaling the new target. A job created with OFFSET_BEGINNING can therefore execute the advertised SET TARGET TABLE ... FROM KAFKA("property.client.id"=...) form and silently make every later-discovered partition start at the end, skipping its backlog. This test masks the overwrite because the job starts with the implicit END default and never asserts it. Keep the default absent from an ALTER delta unless it was explicitly supplied (or needed for explicit partitions), and cover live/replay/image preservation from OFFSET_BEGINNING. |
||
| KafkaDataSourceProperties dataSourceProperties = new KafkaDataSourceProperties(sourceProperties); | ||
| dataSourceProperties.setAlter(true); | ||
| dataSourceProperties.setTimezone("UTC"); | ||
| dataSourceProperties.analyze(); | ||
|
|
||
| Map<String, String> jobProperties = Maps.newHashMap(); | ||
| jobProperties.put(CreateRoutineLoadInfo.MAX_ERROR_NUMBER_PROPERTY, "10"); | ||
| AlterRoutineLoadCommand command = Mockito.mock(AlterRoutineLoadCommand.class); | ||
| Mockito.when(command.hasTargetTable()).thenReturn(true); | ||
| Mockito.when(command.getTargetTableId()).thenReturn(202L); | ||
| Mockito.when(command.getAnalyzedJobProperties()).thenReturn(jobProperties); | ||
| Mockito.when(command.getDataSourceProperties()).thenReturn(dataSourceProperties); | ||
|
|
||
| Env env = Mockito.mock(Env.class); | ||
| EditLog editLog = Mockito.mock(EditLog.class); | ||
| Mockito.when(env.getEditLog()).thenReturn(editLog); | ||
| try (MockedStatic<Env> envStatic = Mockito.mockStatic(Env.class)) { | ||
| envStatic.when(Env::getCurrentEnv).thenReturn(env); | ||
| routineLoadJob.modifyProperties(command); | ||
| } | ||
|
|
||
| Assert.assertEquals(202L, routineLoadJob.getTableId()); | ||
| Assert.assertSame(progress, routineLoadJob.getProgress()); | ||
| Assert.assertEquals(10L, ((Long) Deencapsulation.getField(routineLoadJob, "maxErrorNum")).longValue()); | ||
| Assert.assertEquals("target-switch", | ||
| routineLoadJob.getCustomProperties().get("property.client.id")); | ||
| ArgumentCaptor<AlterRoutineLoadJobOperationLog> logCaptor = | ||
| ArgumentCaptor.forClass(AlterRoutineLoadJobOperationLog.class); | ||
| Mockito.verify(editLog).logAlterRoutineLoadJob(logCaptor.capture()); | ||
| Assert.assertEquals(202L, logCaptor.getValue().getTargetTableId()); | ||
| } | ||
|
|
||
| @Test | ||
| public void testModifyTargetTableOnly() throws Exception { | ||
| KafkaRoutineLoadJob routineLoadJob = new KafkaRoutineLoadJob(1L, "kafka_routine_load_job", 1L, | ||
| 101L, "127.0.0.1:9020", "topic1", UserIdentity.ADMIN); | ||
| Deencapsulation.setField(routineLoadJob, "state", RoutineLoadJob.JobState.PAUSED); | ||
| KafkaProgress progress = new KafkaProgress(Maps.newHashMap()); | ||
| Deencapsulation.setField(routineLoadJob, "progress", progress); | ||
|
|
||
| AlterRoutineLoadCommand command = Mockito.mock(AlterRoutineLoadCommand.class); | ||
| Mockito.when(command.hasTargetTable()).thenReturn(true); | ||
| Mockito.when(command.getTargetTableId()).thenReturn(202L); | ||
| Mockito.when(command.getAnalyzedJobProperties()).thenReturn(Maps.newHashMap()); | ||
| Mockito.when(command.getDataSourceProperties()).thenReturn(null); | ||
|
|
||
| Env env = Mockito.mock(Env.class); | ||
| EditLog editLog = Mockito.mock(EditLog.class); | ||
| Mockito.when(env.getEditLog()).thenReturn(editLog); | ||
| try (MockedStatic<Env> envStatic = Mockito.mockStatic(Env.class)) { | ||
| envStatic.when(Env::getCurrentEnv).thenReturn(env); | ||
| routineLoadJob.modifyProperties(command); | ||
| } | ||
|
|
||
| Assert.assertEquals(202L, routineLoadJob.getTableId()); | ||
| Assert.assertSame(progress, routineLoadJob.getProgress()); | ||
| ArgumentCaptor<AlterRoutineLoadJobOperationLog> logCaptor = | ||
| ArgumentCaptor.forClass(AlterRoutineLoadJobOperationLog.class); | ||
| Mockito.verify(editLog).logAlterRoutineLoadJob(logCaptor.capture()); | ||
| Assert.assertEquals(202L, logCaptor.getValue().getTargetTableId()); | ||
| Assert.assertTrue(logCaptor.getValue().getJobProperties().isEmpty()); | ||
| Assert.assertNull(logCaptor.getValue().getDataSourceProperties()); | ||
| } | ||
|
|
||
| @Test | ||
| public void testReplayModifyPropertiesSwitchesTargetTableWithoutResettingProgress() { | ||
| KafkaRoutineLoadJob routineLoadJob = new KafkaRoutineLoadJob(1L, "kafka_routine_load_job", 1L, | ||
| 101L, "127.0.0.1:9020", "topic1", UserIdentity.ADMIN); | ||
| Map<Integer, Long> partitionToOffset = Maps.newHashMap(); | ||
| partitionToOffset.put(1, 123L); | ||
| KafkaProgress progress = new KafkaProgress(partitionToOffset); | ||
| Deencapsulation.setField(routineLoadJob, "progress", progress); | ||
|
|
||
| routineLoadJob.replayModifyProperties(new AlterRoutineLoadJobOperationLog( | ||
| 1L, Maps.newHashMap(), null)); | ||
| Assert.assertEquals(101L, routineLoadJob.getTableId()); | ||
|
|
||
| routineLoadJob.replayModifyProperties(new AlterRoutineLoadJobOperationLog( | ||
| 1L, Maps.newHashMap(), null, 202L)); | ||
| Assert.assertEquals(202L, routineLoadJob.getTableId()); | ||
| Assert.assertSame(progress, routineLoadJob.getProgress()); | ||
| Assert.assertEquals(Long.valueOf(123L), | ||
| ((KafkaProgress) routineLoadJob.getProgress()).getOffsetByPartition(1)); | ||
| } | ||
|
|
||
| @Test | ||
| public void testUpdateProgressWarnsWhenReadCommittedTaskHasZeroRowsAndLag() throws UserException { | ||
| KafkaRoutineLoadJob routineLoadJob = new KafkaRoutineLoadJob(1L, "kafka_routine_load_job", 1L, | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.