Commit 1c283c0
[SPARK-54063][SS] Trigger snapshot for next batch when upload lag
## What changes were proposed in this pull request?
We are adding a functionality for StateStoreProvider to force creating a snapshot on commit when creating a StateStore when it detects that the corresponding StateStoreProvider is lagging in creating snapshot (i.e. having too many changelog). This applies to both RocksDB and HDFS. This feature is only enabled when `STATE_STORE_COORDINATOR_REPORT_SNAPSHOT_UPLOAD_LAG` is true as well (introduced in [PR 50123](https://github.com/apache/spark/pull/50123/files#diff-7c577967a171f51523afddd7a5eca49806432fae2da8dc35c114d9699e6e3e40))
We also added a StateStoreCustomMetric `CUSTOM_METRIC_FORCE_SNAPSHOT` to track the number of forced snapshot
The changes made in this PR includes
- `StateStoreCoordinator` now keeps track of a list of lagging state stores and update it accordingly on receiveing `LogLaggingStateStores` (update the set) and `DeactivateInstances` (remove all lagging stores from set)
- Change `ReportActiveInstance` in StateStoreCoordinator to also return `shouldForceSnapshot`, which indicates if current `StateStore` should create a snapshot on next commit
- Add a new param `forceSnapshotOnCommit: Boolean = false` to StateStoreProvider function `getStore`, and its inherited provider can create state stores that will force a snapshot on commit
- When StateStore singleton `get()` is called, it will call `ReportActiveInstance` to check if it should create a snapshot in the next commit.
### Does this PR introduce _any_ user-facing change?
No
### How was this patch tested?
Added integration test in StateStoreCoordinatorSuite, where it tests if RocksDBStateStore and HDFSBackedStateStore can both auto-trigger a snapshot on commit when delay in snapshot upload is detected
Also added unit test in StateStoreBaseSuite to test if the metric is populated correctly when a snapshot is forced.
### Was this patch authored or co-authored using generative AI tooling?
Yes
Closes #52773 from zifeif2/trigger-snapshot.
Authored-by: Ubuntu <zifei.feng@your.hostname.com>
Signed-off-by: Anish Shrigondekar <anish.shrigondekar@databricks.com>1 parent 19ff859 commit 1c283c0
File tree
15 files changed
+467
-60
lines changed- common/utils-java/src/main/java/org/apache/spark/internal
- sql
- catalyst/src/main/scala/org/apache/spark/sql/internal
- connect/client/jvm/src/test/scala/org/apache/spark/sql/connect/streaming
- core/src
- main/scala/org/apache/spark/sql/execution/streaming/state
- test/scala/org/apache/spark/sql
- execution/streaming/state
- internal
- streaming
15 files changed
+467
-60
lines changedLines changed: 1 addition & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
787 | 787 | | |
788 | 788 | | |
789 | 789 | | |
| 790 | + | |
790 | 791 | | |
791 | 792 | | |
792 | 793 | | |
| |||
Lines changed: 23 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2710 | 2710 | | |
2711 | 2711 | | |
2712 | 2712 | | |
| 2713 | + | |
| 2714 | + | |
| 2715 | + | |
| 2716 | + | |
| 2717 | + | |
| 2718 | + | |
| 2719 | + | |
| 2720 | + | |
| 2721 | + | |
| 2722 | + | |
| 2723 | + | |
| 2724 | + | |
2713 | 2725 | | |
2714 | 2726 | | |
2715 | 2727 | | |
| |||
6921 | 6933 | | |
6922 | 6934 | | |
6923 | 6935 | | |
| 6936 | + | |
| 6937 | + | |
| 6938 | + | |
| 6939 | + | |
| 6940 | + | |
| 6941 | + | |
| 6942 | + | |
| 6943 | + | |
| 6944 | + | |
| 6945 | + | |
| 6946 | + | |
6924 | 6947 | | |
6925 | 6948 | | |
6926 | 6949 | | |
| |||
Lines changed: 1 addition & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
101 | 101 | | |
102 | 102 | | |
103 | 103 | | |
| 104 | + | |
104 | 105 | | |
105 | 106 | | |
106 | 107 | | |
| |||
Lines changed: 23 additions & 9 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
109 | 109 | | |
110 | 110 | | |
111 | 111 | | |
112 | | - | |
| 112 | + | |
| 113 | + | |
113 | 114 | | |
114 | 115 | | |
115 | 116 | | |
| |||
196 | 197 | | |
197 | 198 | | |
198 | 199 | | |
199 | | - | |
| 200 | + | |
200 | 201 | | |
201 | 202 | | |
202 | 203 | | |
| |||
254 | 255 | | |
255 | 256 | | |
256 | 257 | | |
257 | | - | |
| 258 | + | |
| 259 | + | |
258 | 260 | | |
259 | 261 | | |
260 | 262 | | |
| |||
317 | 319 | | |
318 | 320 | | |
319 | 321 | | |
320 | | - | |
| 322 | + | |
| 323 | + | |
| 324 | + | |
| 325 | + | |
321 | 326 | | |
322 | 327 | | |
323 | 328 | | |
324 | 329 | | |
325 | 330 | | |
326 | 331 | | |
327 | 332 | | |
328 | | - | |
329 | | - | |
| 333 | + | |
| 334 | + | |
| 335 | + | |
| 336 | + | |
330 | 337 | | |
331 | 338 | | |
332 | 339 | | |
| |||
446 | 453 | | |
447 | 454 | | |
448 | 455 | | |
449 | | - | |
450 | | - | |
| 456 | + | |
451 | 457 | | |
452 | 458 | | |
453 | 459 | | |
| |||
524 | 530 | | |
525 | 531 | | |
526 | 532 | | |
| 533 | + | |
| 534 | + | |
| 535 | + | |
| 536 | + | |
527 | 537 | | |
528 | 538 | | |
529 | 539 | | |
| |||
532 | 542 | | |
533 | 543 | | |
534 | 544 | | |
535 | | - | |
| 545 | + | |
| 546 | + | |
536 | 547 | | |
537 | 548 | | |
| 549 | + | |
| 550 | + | |
| 551 | + | |
538 | 552 | | |
539 | 553 | | |
540 | 554 | | |
| |||
Lines changed: 5 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1469 | 1469 | | |
1470 | 1470 | | |
1471 | 1471 | | |
1472 | | - | |
| 1472 | + | |
1473 | 1473 | | |
1474 | 1474 | | |
1475 | 1475 | | |
1476 | 1476 | | |
1477 | 1477 | | |
1478 | 1478 | | |
| 1479 | + | |
| 1480 | + | |
| 1481 | + | |
| 1482 | + | |
1479 | 1483 | | |
1480 | 1484 | | |
1481 | 1485 | | |
| |||
Lines changed: 32 additions & 12 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
46 | 46 | | |
47 | 47 | | |
48 | 48 | | |
49 | | - | |
| 49 | + | |
| 50 | + | |
50 | 51 | | |
51 | 52 | | |
52 | 53 | | |
| |||
448 | 449 | | |
449 | 450 | | |
450 | 451 | | |
451 | | - | |
| 452 | + | |
452 | 453 | | |
453 | 454 | | |
454 | 455 | | |
| |||
568 | 569 | | |
569 | 570 | | |
570 | 571 | | |
571 | | - | |
| 572 | + | |
| 573 | + | |
572 | 574 | | |
573 | 575 | | |
574 | 576 | | |
| |||
716 | 718 | | |
717 | 719 | | |
718 | 720 | | |
| 721 | + | |
719 | 722 | | |
720 | 723 | | |
721 | 724 | | |
722 | 725 | | |
723 | 726 | | |
724 | 727 | | |
725 | | - | |
| 728 | + | |
| 729 | + | |
726 | 730 | | |
727 | 731 | | |
728 | 732 | | |
| |||
761 | 765 | | |
762 | 766 | | |
763 | 767 | | |
| 768 | + | |
764 | 769 | | |
765 | 770 | | |
766 | 771 | | |
767 | 772 | | |
768 | | - | |
| 773 | + | |
769 | 774 | | |
770 | 775 | | |
771 | 776 | | |
| |||
792 | 797 | | |
793 | 798 | | |
794 | 799 | | |
795 | | - | |
796 | | - | |
| 800 | + | |
| 801 | + | |
| 802 | + | |
| 803 | + | |
| 804 | + | |
| 805 | + | |
| 806 | + | |
| 807 | + | |
| 808 | + | |
797 | 809 | | |
798 | 810 | | |
799 | 811 | | |
800 | 812 | | |
801 | 813 | | |
802 | | - | |
| 814 | + | |
| 815 | + | |
803 | 816 | | |
804 | 817 | | |
805 | 818 | | |
806 | 819 | | |
807 | 820 | | |
808 | 821 | | |
809 | 822 | | |
810 | | - | |
811 | | - | |
| 823 | + | |
| 824 | + | |
| 825 | + | |
| 826 | + | |
| 827 | + | |
812 | 828 | | |
813 | 829 | | |
814 | 830 | | |
| |||
932 | 948 | | |
933 | 949 | | |
934 | 950 | | |
935 | | - | |
| 951 | + | |
936 | 952 | | |
937 | 953 | | |
938 | 954 | | |
| |||
1283 | 1299 | | |
1284 | 1300 | | |
1285 | 1301 | | |
| 1302 | + | |
| 1303 | + | |
| 1304 | + | |
1286 | 1305 | | |
1287 | 1306 | | |
1288 | 1307 | | |
| |||
1297 | 1316 | | |
1298 | 1317 | | |
1299 | 1318 | | |
1300 | | - | |
| 1319 | + | |
| 1320 | + | |
1301 | 1321 | | |
1302 | 1322 | | |
1303 | 1323 | | |
| |||
0 commit comments