Skip to content

[fix](fe) Preserve Kinesis job state when ALTER validation fails - #67696

Closed
0AyanamiRei wants to merge 1 commit into
apache:masterfrom
0AyanamiRei:fix/kinesis-alter-validation-atomicity
Closed

0AyanamiRei wants to merge 1 commit into
apache:masterfrom
0AyanamiRei:fix/kinesis-alter-validation-atomicity

Conversation

@0AyanamiRei

Copy link
Copy Markdown
Contributor

What problem does this PR solve?

Issue Number: N/A

Related PR: N/A

Problem Summary:

A failed ALTER ROUTINE LOAD can leave a Kinesis job partially modified in memory, even though the statement returns an error and no ALTER journal entry is written.

For example, pause a job whose progress contains shard-0, then alter its region, endpoint, or default position together with an explicit shard list containing an unknown shard. Omit kinesis_stream so that the existing-progress membership check applies. Before this change, modifyPropertiesInternal() updates the live data-source properties and replaces customKinesisShards before KinesisProgress.checkShards() rejects the unknown shard. The exception releases the job lock without restoring those fields.

The leader can therefore retain configuration that journal replay does not apply to other FEs. A residual explicit shard list can also bypass remote shard discovery after resume. There is another failure point in the same ALTER path: common-property validation for flexible partial updates can fail after Kinesis state and some common properties have already changed.

This change orders validation before mutation:

  1. Read the requested Kinesis changes into local variables and check shard membership before modifying any job state. Preserve the existing progress-reset behavior when a stream is provided.
  2. Validate the requested unique-key update mode and flexible partial-update constraints before assigning any common job properties in RoutineLoadJob.
  3. Apply the common properties before updating Kinesis configuration, shard lists, and progress. The existing successful ALTER path then writes its journal entry.

The guarantee covers shard-membership and common-property validation failures. These failures now occur before any live state changes, so they require no rollback. The shared RoutineLoadJob adjustment is necessary to keep common-property validation from becoming another source of partial Kinesis ALTER updates.

Release note

Kinesis Routine Load preserves its previous configuration, shard selection, and progress when ALTER fails shard-membership or common-property validation.

Check List (For Author)

  • Test
    • Regression test
    • Unit Test
    • Manual test (add detailed scripts or steps below)
    • No need to test or manual test. Explain why:
  • Behavior changed:
    • No.
    • Yes. Failed validation leaves the Kinesis job state unchanged and does not write an ALTER journal entry.
  • Does this need documentation?
    • No.
    • Yes.

Validation:

  • Before the fix, the four new failure-atomicity test cases fail because job state changes after the expected ALTER error. The other 11 Kinesis job tests pass.

  • After the fix, all 47 tests pass, with no failures, errors, or skipped tests:

    ./run-fe-ut.sh --run org.apache.doris.load.routineload.KinesisRoutineLoadJobTest,org.apache.doris.load.routineload.RoutineLoadJobTest,org.apache.doris.load.routineload.KafkaRoutineLoadJobTest,org.apache.doris.load.routineload.kinesis.KinesisDataSourcePropertiesTest
  • New tests cover dynamic and explicit shard selection, shared open/explicit shard list instances, unchanged state and no journal entry on failure, shard discovery after the resume state transition, common-property validation failures with and without a stream change, and successful ALTER journal serialization/replay.

  • FE build via build.sh --fe -j48 passes with DISABLE_BUILD_UI=ON and DISABLE_JAVA_CHECK_STYLE=OFF; output is directed to a separate local build directory. Checkstyle reports zero violations. UI building is disabled because the local npm dependency installation fails.

  • git diff --check passes.

  • Real AWS Kinesis consumption and multi-FE failover have not been tested. Shard discovery is mocked in the unit tests.

Check List (For Reviewer who merge this PR)

  • Confirm the release note
  • Confirm test cases
  • Confirm document
  • Add branch pick label

### What problem does this PR solve?

Issue Number: N/A

Related PR: N/A

Problem Summary:

A failed `ALTER ROUTINE LOAD` can leave a Kinesis job partially modified in memory, even though the statement returns an error and no ALTER journal entry is written.

For example, pause a job whose progress contains `shard-0`, then alter its region, endpoint, or default position together with an explicit shard list containing an unknown shard. Omit `kinesis_stream` so that the existing-progress membership check applies. Before this change, `modifyPropertiesInternal()` updates the live data-source properties and replaces `customKinesisShards` before `KinesisProgress.checkShards()` rejects the unknown shard. The exception releases the job lock without restoring those fields.

The leader can therefore retain configuration that journal replay does not apply to other FEs. A residual explicit shard list can also bypass remote shard discovery after resume. There is another failure point in the same ALTER path: common-property validation for flexible partial updates can fail after Kinesis state and some common properties have already changed.

This change orders validation before mutation:

1. Read the requested Kinesis changes into local variables and check shard membership before modifying any job state. Preserve the existing progress-reset behavior when a stream is provided.
2. Validate the requested unique-key update mode and flexible partial-update constraints before assigning any common job properties in `RoutineLoadJob`.
3. Apply the common properties before updating Kinesis configuration, shard lists, and progress. The existing successful ALTER path then writes its journal entry.

The guarantee covers shard-membership and common-property validation failures. These failures now occur before any live state changes, so they require no rollback. The shared `RoutineLoadJob` adjustment is necessary to keep common-property validation from becoming another source of partial Kinesis ALTER updates.

### Release note

Kinesis Routine Load preserves its previous configuration, shard selection, and progress when ALTER fails shard-membership or common-property validation.

### Check List (For Author)

- Test
    - [ ] Regression test
    - [x] Unit Test
    - [ ] Manual test (add detailed scripts or steps below)
    - [ ] No need to test or manual test. Explain why:
- Behavior changed:
    - [ ] No.
    - [x] Yes. Failed validation leaves the Kinesis job state unchanged and does not write an ALTER journal entry.
- Does this need documentation?
    - [x] No.
    - [ ] Yes.

Validation:

- Before the fix, the four new failure-atomicity test cases fail because job state changes after the expected ALTER error. The other 11 Kinesis job tests pass.
- After the fix, all 47 tests pass, with no failures, errors, or skipped tests:

  ```bash
  ./run-fe-ut.sh --run org.apache.doris.load.routineload.KinesisRoutineLoadJobTest,org.apache.doris.load.routineload.RoutineLoadJobTest,org.apache.doris.load.routineload.KafkaRoutineLoadJobTest,org.apache.doris.load.routineload.kinesis.KinesisDataSourcePropertiesTest
  ```

- New tests cover dynamic and explicit shard selection, shared open/explicit shard list instances, unchanged state and no journal entry on failure, shard discovery after the resume state transition, common-property validation failures with and without a stream change, and successful ALTER journal serialization/replay.
- FE build via `build.sh --fe -j48` passes with `DISABLE_BUILD_UI=ON` and `DISABLE_JAVA_CHECK_STYLE=OFF`; output is directed to a separate local build directory. Checkstyle reports zero violations. UI building is disabled because the local npm dependency installation fails.
- `git diff --check` passes.
- Real AWS Kinesis consumption and multi-FE failover have not been tested. Shard discovery is mocked in the unit tests.
@hello-stephen

Copy link
Copy Markdown
Contributor

Thank you for your contribution to Apache Doris.
Don't know what should be done next? See How to process your PR.

Please clearly describe your PR:

  1. What problem was fixed (it's best to include specific error reporting information). How it was fixed.
  2. Which behaviors were modified. What was the previous behavior, what is it now, why was it modified, and what possible impacts might there be.
  3. What features were added. Why was this function added?
  4. Which code was refactored and why was this part of the code refactored?
  5. Which functions were optimized and what is the difference before and after the optimization?

@0AyanamiRei

Copy link
Copy Markdown
Contributor Author

run buildall

@hello-stephen

Copy link
Copy Markdown
Contributor
TPC-H: Total hot run time: 16669 ms
machine: 'aliyun_ecs.c7a.8xlarge_32C64G'
scripts: https://github.com/apache/doris/tree/master/tools/tpch-tools
Tpch sf100 test result on commit 9e964978534b02af35c6f263a5ab9df95ffce5a8, data reload: false

------ Round 1 ----------------------------------
============================================
q1	17572	2992	3033	2992
q2	2093	251	224	224
q3	10245	870	533	533
q4	4668	252	200	200
q5	7688	576	397	397
q6	133	113	94	94
q7	527	503	392	392
q8	9252	903	917	903
q9	3497	2421	2392	2392
q10	6523	858	710	710
q11	403	202	177	177
q12	642	273	199	199
q13	18135	1527	1134	1134
q14	162	151	137	137
q15	q16	451	398	373	373
q17	1369	917	778	778
q18	3047	2247	2234	2234
q19	1110	903	773	773
q20	376	288	210	210
q21	5330	1590	1818	1590
q22	322	265	227	227
Total cold run time: 93545 ms
Total hot run time: 16669 ms

----- Round 2, with runtime_filter_mode=off -----
============================================
q1	3349	3228	3273	3228
q2	512	387	379	379
q3	2205	2286	2135	2135
q4	1185	1172	881	881
q5	2165	2122	2151	2122
q6	165	121	88	88
q7	1032	920	840	840
q8	1575	1374	1385	1374
q9	3108	3074	3097	3074
q10	1846	1807	1626	1626
q11	361	266	248	248
q12	455	432	344	344
q13	1487	1554	1145	1145
q14	170	188	154	154
q15	q16	395	392	357	357
q17	3609	3354	3240	3240
q18	4848	4452	4723	4452
q19	859	824	924	824
q20	1046	999	829	829
q21	3874	3104	3292	3104
q22	416	332	333	332
Total cold run time: 34662 ms
Total hot run time: 30776 ms

@hello-stephen

Copy link
Copy Markdown
Contributor
TPC-DS: Total hot run time: 81908 ms
machine: 'aliyun_ecs.c7a.8xlarge_32C64G'
scripts: https://github.com/apache/doris/tree/master/tools/tpcds-tools
TPC-DS sf100 test result on commit 9e964978534b02af35c6f263a5ab9df95ffce5a8, data reload: false

query5	4252	422	355	355
query6	388	139	151	139
query7	4897	451	222	222
query8	280	130	125	125
query9	8704	2886	2881	2881
query10	408	221	185	185
query11	5384	1047	937	937
query12	127	70	71	70
query13	1210	427	324	324
query14	6096	2210	2098	2098
query14_1	2011	1967	1970	1967
query15	170	121	110	110
query16	904	365	349	349
query17	793	459	369	369
query18	2328	324	237	237
query19	164	139	110	110
query20	70	68	77	68
query21	194	101	87	87
query22	5326	5380	5484	5380
query23	6726	6196	5984	5984
query23_1	6157	6071	6211	6071
query24	7269	1117	759	759
query24_1	808	798	750	750
query25	399	270	224	224
query26	1226	231	126	126
query27	2794	440	252	252
query28	4669	1510	1485	1485
query29	914	416	343	343
query30	250	149	132	132
query31	807	398	323	323
query32	123	79	72	72
query33	444	215	171	171
query34	978	843	446	446
query35	414	408	353	353
query36	583	556	527	527
query37	115	82	66	66
query38	996	836	811	811
query39	479	470	478	470
query39_1	464	477	474	474
query40	201	92	75	75
query41	55	56	54	54
query42	75	73	76	73
query43	239	244	210	210
query44	992	522	550	522
query45	110	105	102	102
query46	770	842	536	536
query47	788	775	714	714
query48	322	305	227	227
query49	542	234	182	182
query50	765	266	196	196
query51	8026	8009	8085	8009
query52	67	67	60	60
query53	200	205	144	144
query54	223	185	159	159
query55	66	61	55	55
query56	214	174	152	152
query57	769	676	632	632
query58	205	173	158	158
query59	1195	1216	1099	1099
query60	247	185	179	179
query61	117	118	126	118
query62	350	212	168	168
query63	177	138	140	138
query64	2658	756	588	588
query65	1669	1566	1606	1566
query66	1919	259	227	227
query67	9764	9748	9623	9623
query68	2786	1161	760	760
query69	342	222	190	190
query70	662	634	618	618
query71	249	177	166	166
query72	2267	1641	1538	1538
query73	629	618	360	360
query74	1564	1232	1150	1150
query75	1178	1099	964	964
query76	2285	720	551	551
query77	257	253	214	214
query78	3987	3507	3257	3257
query79	1472	818	554	554
query80	1170	327	258	258
query81	482	151	139	139
query82	607	128	93	93
query83	314	217	191	191
query84	291	108	85	85
query85	777	330	273	273
query86	393	213	179	179
query87	1021	974	882	882
query88	2793	2117	2137	2117
query89	278	201	175	175
query90	1926	131	135	131
query91	132	119	99	99
query92	73	70	71	70
query93	1304	1114	729	729
query94	643	251	219	219
query95	535	259	226	226
query96	852	564	276	276
query97	1038	1044	1006	1006
query98	145	136	133	133
query99	409	349	306	306
Total cold run time: 175346 ms
Total hot run time: 81908 ms

@hello-stephen

Copy link
Copy Markdown
Contributor
ClickBench: Total hot run time: 14.73 s
machine: 'aliyun_ecs.c7a.8xlarge_32C64G'
scripts: https://github.com/apache/doris/tree/master/tools/clickbench-tools
ClickBench test result on commit 9e964978534b02af35c6f263a5ab9df95ffce5a8, data reload: false

query1	0.00	0.01	0.00
query2	0.07	0.03	0.03
query3	0.25	0.12	0.09
query4	1.59	0.08	0.10
query5	0.17	0.17	0.17
query6	1.26	0.74	0.68
query7	0.03	0.01	0.00
query8	0.05	0.03	0.03
query9	0.29	0.20	0.21
query10	0.35	0.34	0.35
query11	0.17	0.12	0.11
query12	0.15	0.12	0.13
query13	0.31	0.31	0.31
query14	0.46	0.45	0.46
query15	0.37	0.36	0.36
query16	0.20	0.23	0.22
query17	0.74	0.70	0.71
query18	0.18	0.16	0.16
query19	1.17	1.22	1.19
query20	0.01	0.01	0.01
query21	15.44	0.15	0.12
query22	5.07	0.04	0.05
query23	16.17	0.25	0.11
query24	3.00	0.35	0.26
query25	0.10	0.04	0.03
query26	0.76	0.16	0.12
query27	0.03	0.02	0.03
query28	3.69	0.56	0.26
query29	12.45	3.18	2.55
query30	0.25	0.12	0.12
query31	2.76	0.38	0.17
query32	3.51	0.33	0.23
query33	1.34	1.43	1.41
query34	15.36	2.19	1.79
query35	1.76	1.74	1.76
query36	0.45	0.31	0.29
query37	0.06	0.04	0.04
query38	0.04	0.02	0.02
query39	0.04	0.02	0.02
query40	0.11	0.09	0.07
query41	0.08	0.03	0.02
query42	0.03	0.03	0.03
query43	0.04	0.03	0.02
Total cold run time: 90.36 s
Total hot run time: 14.73 s

@hello-stephen

Copy link
Copy Markdown
Contributor

FE Regression Coverage Report

Increment line coverage 3.50% (7/200) 🎉
Increment coverage report
Complete coverage report

@0AyanamiRei
0AyanamiRei marked this pull request as draft September 15, 2026 19:08
@0AyanamiRei

Copy link
Copy Markdown
Contributor Author

draft,计划是希望对routine load kinese先去持久化的维护一个shards父子关系的拓扑图

@0AyanamiRei

Copy link
Copy Markdown
Contributor Author

Absorbed into the Kinesis shard topology change, closing this draft.

  • RoutineLoadJob.modifyCommonJobProperties: UNIQUE_KEY_UPDATE_MODE is parsed and validated before any other job property is mutated, so a failed validation leaves the job untouched. Landed verbatim.
  • KinesisRoutineLoadJob.modifyPropertiesInternal: the validate-before-mutate restructure landed, extended with the sourceGeneration guard so a pending asynchronous LATEST scan for the old source is invalidated when ALTER changes stream/region/endpoint.
  • KinesisRoutineLoadJobTest: testFailedAlterPreservesStateAndShardDiscovery, testFailedCommonPropertyValidationPreservesKinesisState and testSuccessfulAlterMatchesJournalReplay are in the branch. The shard-discovery assertions were adapted to the topology API (getAllKinesisShardInfos, and the explicit-shard case now also refreshes the shard list instead of skipping it, since explicit shards are validated against ListShards).

0AyanamiRei added a commit to 0AyanamiRei/doris that referenced this pull request Sep 23, 2026
### What problem does this PR solve?

Issue Number: None

Related PR: apache#67678, apache#67696, apache#67869, apache#67874, apache#67879

Problem Summary: Kinesis shards can split and merge while a routine load job is running. Maintaining only open/closed shard lists and progress cannot express parent-child lineage or the COMMITTED-to-VISIBLE completion barrier, which can schedule children too early, lose lineage, or recreate completed parents. This change adds a durable shard topology state machine, concrete initial-position persistence, idempotent journal/image replay, and Kinesis BE progress handling for EOF and ChildShards metadata. New FE, BE, and regression coverage verifies shard transitions, transaction visibility, latest-position resolution, reshard boundaries, and deterministic Kinesis upstream behavior.

### Release note

Add parent-child shard topology tracking and visibility-gated scheduling for Kinesis Routine Load.

### Check List (For Author)

- Test: Unit Test
    - `./run-be-ut.sh --run --filter='*Kinesis*' -j48`
    - Result: 18 Kinesis tests passed
    - No FE unit test or AWS regression test was run in this environment.
- Behavior changed: Yes (Kinesis Routine Load now schedules shards through the topology state machine.)
- Does this need documentation: No
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