- Notifications
You must be signed in to change notification settings - Fork4.9k
Commit0434033

Amit Kapila
Fix data loss in logical replication.
Data loss can happen when the DDLs like ALTER PUBLICATION ... ADD TABLE ...or ALTER TYPE ... that don't take a strong lock on table happensconcurrently to DMLs on the tables involved in the DDL. This happensbecause logical decoding doesn't distribute invalidations to concurrenttransactions and those transactions use stale cache data to decode thechanges. The problem becomes bigger because we keep using the stale cacheeven after those in-progress transactions are finished and skip thechanges required to be sent to the client.This commit fixes the issue by distributing invalidation messages fromcatalog-modifying transactions to all concurrent in-progress transactions.This allows the necessary rebuild of the catalog cache when decoding newchanges after concurrent DDL.We observed performance regression primarily during frequent execution of*publication DDL* statements that modify the published tables. Theregression is minor or nearly nonexistent for DDLs that do not affect thepublished tables or occur infrequently, making this a worthwhile cost toresolve a longstanding data loss issue.An alternative approach considered was to take a strong lock on eachaffected table during publication modification. However, this would onlyaddress issues related to publication DDLs (but not the ALTER TYPE ...)and require locking every relation in the database for publicationscreated as FOR ALL TABLES, which is impractical.The bug exists in all supported branches, but we are backpatching till 14.The fix for 13 requires somewhat bigger changes than this fix, so the fixfor that branch is still under discussion.Reported-by: hubert depesz lubaczewski <depesz@depesz.com>Reported-by: Tomas Vondra <tomas.vondra@enterprisedb.com>Author: Shlok Kyal <shlok.kyal.oss@gmail.com>Author: Hayato Kuroda <kuroda.hayato@fujitsu.com>Reviewed-by: Zhijie Hou <houzj.fnst@fujitsu.com>Reviewed-by: Masahiko Sawada <sawada.mshk@gmail.com>Reviewed-by: Amit Kapila <amit.kapila16@gmail.com>Tested-by: Benoit Lobréau <benoit.lobreau@dalibo.com>Backpatch-through: 14Discussion:https://postgr.es/m/de52b282-1166-1180-45a2-8d8917ca74c6@enterprisedb.comDiscussion:https://postgr.es/m/CAD21AoAenVqiMjpN-PvGHL1N9DWnHSq673bfgr6phmBUzx=kLQ@mail.gmail.com1 parent115f45e commit0434033
File tree
6 files changed
+134
-15
lines changed- contrib/test_decoding
- expected
- specs
- src
- backend/replication/logical
- include/replication
6 files changed
+134
-15
lines changedLines changed: 2 additions & 1 deletion
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
8 | 8 |
| |
9 | 9 |
| |
10 | 10 |
| |
11 |
| - | |
| 11 | + | |
| 12 | + | |
12 | 13 |
| |
13 | 14 |
| |
14 | 15 |
| |
|
Lines changed: 20 additions & 0 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + |
Lines changed: 32 additions & 0 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + |
Lines changed: 23 additions & 0 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
5196 | 5196 |
| |
5197 | 5197 |
| |
5198 | 5198 |
| |
| 5199 | + | |
| 5200 | + | |
| 5201 | + | |
| 5202 | + | |
| 5203 | + | |
| 5204 | + | |
| 5205 | + | |
| 5206 | + | |
| 5207 | + | |
| 5208 | + | |
| 5209 | + | |
| 5210 | + | |
| 5211 | + | |
| 5212 | + | |
| 5213 | + | |
| 5214 | + | |
| 5215 | + | |
| 5216 | + | |
| 5217 | + | |
| 5218 | + | |
| 5219 | + | |
| 5220 | + | |
| 5221 | + |
Lines changed: 53 additions & 14 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
290 | 290 |
| |
291 | 291 |
| |
292 | 292 |
| |
293 |
| - | |
| 293 | + | |
294 | 294 |
| |
295 | 295 |
| |
296 | 296 |
| |
| |||
843 | 843 |
| |
844 | 844 |
| |
845 | 845 |
| |
846 |
| - | |
847 |
| - | |
848 |
| - | |
849 |
| - | |
850 |
| - | |
851 |
| - | |
| 846 | + | |
| 847 | + | |
| 848 | + | |
| 849 | + | |
| 850 | + | |
| 851 | + | |
852 | 852 |
| |
853 | 853 |
| |
854 |
| - | |
| 854 | + | |
855 | 855 |
| |
856 | 856 |
| |
857 | 857 |
| |
858 | 858 |
| |
859 | 859 |
| |
860 | 860 |
| |
861 | 861 |
| |
862 |
| - | |
| 862 | + | |
| 863 | + | |
863 | 864 |
| |
864 | 865 |
| |
865 | 866 |
| |
| |||
872 | 873 |
| |
873 | 874 |
| |
874 | 875 |
| |
| 876 | + | |
| 877 | + | |
| 878 | + | |
| 879 | + | |
| 880 | + | |
| 881 | + | |
| 882 | + | |
| 883 | + | |
875 | 884 |
| |
876 | 885 |
| |
877 | 886 |
| |
| |||
881 | 890 |
| |
882 | 891 |
| |
883 | 892 |
| |
884 |
| - | |
885 |
| - | |
| 893 | + | |
| 894 | + | |
886 | 895 |
| |
887 | 896 |
| |
888 | 897 |
| |
889 | 898 |
| |
890 |
| - | |
| 899 | + | |
891 | 900 |
| |
892 | 901 |
| |
893 | 902 |
| |
| |||
897 | 906 |
| |
898 | 907 |
| |
899 | 908 |
| |
| 909 | + | |
| 910 | + | |
| 911 | + | |
| 912 | + | |
| 913 | + | |
| 914 | + | |
| 915 | + | |
| 916 | + | |
| 917 | + | |
| 918 | + | |
| 919 | + | |
| 920 | + | |
| 921 | + | |
| 922 | + | |
| 923 | + | |
| 924 | + | |
| 925 | + | |
| 926 | + | |
| 927 | + | |
| 928 | + | |
| 929 | + | |
| 930 | + | |
| 931 | + | |
| 932 | + | |
| 933 | + | |
| 934 | + | |
| 935 | + | |
900 | 936 |
| |
901 | 937 |
| |
902 | 938 |
| |
| |||
1175 | 1211 |
| |
1176 | 1212 |
| |
1177 | 1213 |
| |
1178 |
| - | |
1179 |
| - | |
| 1214 | + | |
| 1215 | + | |
| 1216 | + | |
| 1217 | + | |
| 1218 | + | |
1180 | 1219 |
| |
1181 | 1220 |
| |
1182 | 1221 |
| |
|
Lines changed: 4 additions & 0 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
676 | 676 |
| |
677 | 677 |
| |
678 | 678 |
| |
| 679 | + | |
| 680 | + | |
| 681 | + | |
| 682 | + | |
679 | 683 |
| |
680 | 684 |
| |
681 | 685 |
|
0 commit comments
Comments
(0)