forked frompostgres/postgres
- Notifications
You must be signed in to change notification settings - Fork6
Commit0da92dc
committed
Logical decoding of sequences
This extends the logical decoding to also decode sequence increments.We differentiate between sequences created in the current (in-progress)transaction, and sequences created earlier. This mixed behavior isnecessary because while sequences are not transactional (increments arenot subject to ROLLBACK), relfilenode changes are. So we do this:* Changes for sequences created in the same top-level transaction are treated as transactional, i.e. just like any other change from that transaction, and discarded in case of a rollback.* Changes for sequences created earlier are applied immediately, as if performed outside any transaction. This applies also after ALTER SEQUENCE, which may create a new relfilenode.Moreover, if we ever get support for DDL replication, the sequencewon't exist until the transaction gets applied.Sequences created in the current transaction are tracked in a simplehash table, identified by a relfilenode. That means a sequence mayalready exist, but if a transaction does ALTER SEQUENCE then theincrements for the new relfilenode will be treated as transactional.For each relfilenode we track the XID of (sub)transaction that createdit, which is needed for cleanup at transaction end. We don't need tocheck the XID to decide if an increment is transactional - if we find amatch in the hash table, it has to be the same transaction.This requires two minor changes to WAL-logging. Firstly, we need toensure the sequence record has a valid XID - until now the the incrementmight have XID 0 if it was the first change in a subxact. But thesequence might have been created in the same top-level transaction. Sowe ensure the XID is assigned when WAL-logging increments.The other change is addition of "created" flag, marking increments fornewly created relfilenodes. This makes it easier to maintain the hashtable of sequences that need transactional handling.Note: This is needed because of subxacts. A XID 0 might still have thesequence created in a different subxact of the same top-level xact.This does not include any changes to test_decoding and/or the built-inreplication - those will be committed in separate patches.A patch adding decoding of sequences was originally submitted by CaryHuang. This commit reworks various important aspects (e.g. the WALlogging and transactional/non-transactional handling). However, theoriginal patch and reviews were very useful.Author: Tomas Vondra, Cary HuangReviewed-by: Peter Eisentraut, Hannu Krosing, Andres FreundDiscussion:https://postgr.es/m/d045f3c2-6cfb-06d3-5540-e63c320df8bc@enterprisedb.comDiscussion:https://postgr.es/m/1710ed7e13b.cd7177461430746.3372264562543607781@highgo.ca1 parent0d4513b commit0da92dc
File tree
10 files changed
+786
-7
lines changed- doc/src/sgml
- src
- backend
- commands
- replication/logical
- include
- access
- commands
- replication
10 files changed
+786
-7
lines changedLines changed: 60 additions & 5 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
458 | 458 |
| |
459 | 459 |
| |
460 | 460 |
| |
| 461 | + | |
461 | 462 |
| |
462 | 463 |
| |
463 | 464 |
| |
| |||
472 | 473 |
| |
473 | 474 |
| |
474 | 475 |
| |
| 476 | + | |
475 | 477 |
| |
476 | 478 |
| |
477 | 479 |
| |
| |||
481 | 483 |
| |
482 | 484 |
| |
483 | 485 |
| |
484 |
| - | |
485 |
| - | |
| 486 | + | |
| 487 | + | |
486 | 488 |
| |
| 489 | + | |
| 490 | + | |
487 | 491 |
| |
488 | 492 |
| |
489 | 493 |
| |
| |||
492 | 496 |
| |
493 | 497 |
| |
494 | 498 |
| |
495 |
| - | |
| 499 | + | |
| 500 | + | |
496 | 501 |
| |
497 | 502 |
| |
498 | 503 |
| |
| |||
808 | 813 |
| |
809 | 814 |
| |
810 | 815 |
| |
| 816 | + | |
| 817 | + | |
| 818 | + | |
| 819 | + | |
| 820 | + | |
| 821 | + | |
| 822 | + | |
| 823 | + | |
| 824 | + | |
| 825 | + | |
| 826 | + | |
| 827 | + | |
| 828 | + | |
| 829 | + | |
| 830 | + | |
| 831 | + | |
| 832 | + | |
| 833 | + | |
| 834 | + | |
| 835 | + | |
| 836 | + | |
| 837 | + | |
| 838 | + | |
| 839 | + | |
| 840 | + | |
| 841 | + | |
| 842 | + | |
| 843 | + | |
| 844 | + | |
811 | 845 |
| |
812 | 846 |
| |
813 | 847 |
| |
| |||
1017 | 1051 |
| |
1018 | 1052 |
| |
1019 | 1053 |
| |
| 1054 | + | |
| 1055 | + | |
| 1056 | + | |
| 1057 | + | |
| 1058 | + | |
| 1059 | + | |
| 1060 | + | |
| 1061 | + | |
| 1062 | + | |
| 1063 | + | |
| 1064 | + | |
| 1065 | + | |
| 1066 | + | |
| 1067 | + | |
| 1068 | + | |
| 1069 | + | |
| 1070 | + | |
| 1071 | + | |
| 1072 | + | |
| 1073 | + | |
1020 | 1074 |
| |
1021 | 1075 |
| |
1022 | 1076 |
| |
| |||
1197 | 1251 |
| |
1198 | 1252 |
| |
1199 | 1253 |
| |
1200 |
| - | |
1201 |
| - | |
| 1254 | + | |
| 1255 | + | |
| 1256 | + | |
1202 | 1257 |
| |
1203 | 1258 |
| |
1204 | 1259 |
| |
|
Lines changed: 32 additions & 0 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
378 | 378 |
| |
379 | 379 |
| |
380 | 380 |
| |
| 381 | + | |
381 | 382 |
| |
382 | 383 |
| |
| 384 | + | |
| 385 | + | |
| 386 | + | |
| 387 | + | |
383 | 388 |
| |
384 | 389 |
| |
385 | 390 |
| |
| |||
399 | 404 |
| |
400 | 405 |
| |
401 | 406 |
| |
| 407 | + | |
402 | 408 |
| |
403 | 409 |
| |
404 | 410 |
| |
| |||
764 | 770 |
| |
765 | 771 |
| |
766 | 772 |
| |
| 773 | + | |
| 774 | + | |
| 775 | + | |
| 776 | + | |
| 777 | + | |
| 778 | + | |
| 779 | + | |
| 780 | + | |
| 781 | + | |
| 782 | + | |
| 783 | + | |
| 784 | + | |
| 785 | + | |
767 | 786 |
| |
768 | 787 |
| |
| 788 | + | |
769 | 789 |
| |
770 | 790 |
| |
| 791 | + | |
| 792 | + | |
| 793 | + | |
| 794 | + | |
771 | 795 |
| |
772 | 796 |
| |
773 | 797 |
| |
| |||
803 | 827 |
| |
804 | 828 |
| |
805 | 829 |
| |
| 830 | + | |
806 | 831 |
| |
807 | 832 |
| |
808 | 833 |
| |
| |||
977 | 1002 |
| |
978 | 1003 |
| |
979 | 1004 |
| |
| 1005 | + | |
980 | 1006 |
| |
981 | 1007 |
| |
| 1008 | + | |
| 1009 | + | |
| 1010 | + | |
| 1011 | + | |
982 | 1012 |
| |
983 | 1013 |
| |
984 | 1014 |
| |
| |||
999 | 1029 |
| |
1000 | 1030 |
| |
1001 | 1031 |
| |
| 1032 | + | |
| 1033 | + | |
1002 | 1034 |
| |
1003 | 1035 |
| |
1004 | 1036 |
| |
|
Lines changed: 129 additions & 0 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
42 | 42 |
| |
43 | 43 |
| |
44 | 44 |
| |
| 45 | + | |
45 | 46 |
| |
46 | 47 |
| |
47 | 48 |
| |
| |||
63 | 64 |
| |
64 | 65 |
| |
65 | 66 |
| |
| 67 | + | |
66 | 68 |
| |
67 | 69 |
| |
68 | 70 |
| |
| |||
1250 | 1252 |
| |
1251 | 1253 |
| |
1252 | 1254 |
| |
| 1255 | + | |
| 1256 | + | |
| 1257 | + | |
| 1258 | + | |
| 1259 | + | |
| 1260 | + | |
| 1261 | + | |
| 1262 | + | |
| 1263 | + | |
| 1264 | + | |
| 1265 | + | |
| 1266 | + | |
| 1267 | + | |
| 1268 | + | |
| 1269 | + | |
| 1270 | + | |
| 1271 | + | |
| 1272 | + | |
| 1273 | + | |
| 1274 | + | |
| 1275 | + | |
| 1276 | + | |
| 1277 | + | |
| 1278 | + | |
| 1279 | + | |
| 1280 | + | |
| 1281 | + | |
| 1282 | + | |
| 1283 | + | |
| 1284 | + | |
| 1285 | + | |
| 1286 | + | |
| 1287 | + | |
| 1288 | + | |
| 1289 | + | |
| 1290 | + | |
| 1291 | + | |
| 1292 | + | |
| 1293 | + | |
| 1294 | + | |
| 1295 | + | |
| 1296 | + | |
| 1297 | + | |
| 1298 | + | |
| 1299 | + | |
| 1300 | + | |
| 1301 | + | |
| 1302 | + | |
| 1303 | + | |
| 1304 | + | |
| 1305 | + | |
| 1306 | + | |
| 1307 | + | |
| 1308 | + | |
| 1309 | + | |
| 1310 | + | |
| 1311 | + | |
| 1312 | + | |
| 1313 | + | |
| 1314 | + | |
| 1315 | + | |
| 1316 | + | |
| 1317 | + | |
| 1318 | + | |
| 1319 | + | |
| 1320 | + | |
| 1321 | + | |
| 1322 | + | |
| 1323 | + | |
| 1324 | + | |
| 1325 | + | |
| 1326 | + | |
| 1327 | + | |
| 1328 | + | |
| 1329 | + | |
| 1330 | + | |
| 1331 | + | |
| 1332 | + | |
| 1333 | + | |
| 1334 | + | |
| 1335 | + | |
| 1336 | + | |
| 1337 | + | |
| 1338 | + | |
| 1339 | + | |
| 1340 | + | |
| 1341 | + | |
| 1342 | + | |
| 1343 | + | |
| 1344 | + | |
| 1345 | + | |
| 1346 | + | |
| 1347 | + | |
| 1348 | + | |
| 1349 | + | |
| 1350 | + | |
| 1351 | + | |
| 1352 | + | |
| 1353 | + | |
| 1354 | + | |
| 1355 | + | |
| 1356 | + | |
| 1357 | + | |
| 1358 | + | |
| 1359 | + | |
| 1360 | + | |
| 1361 | + | |
| 1362 | + | |
| 1363 | + | |
| 1364 | + | |
| 1365 | + | |
| 1366 | + | |
| 1367 | + | |
| 1368 | + | |
| 1369 | + | |
| 1370 | + | |
| 1371 | + | |
| 1372 | + | |
| 1373 | + | |
| 1374 | + | |
| 1375 | + | |
| 1376 | + | |
| 1377 | + | |
| 1378 | + | |
| 1379 | + | |
| 1380 | + | |
| 1381 | + |
0 commit comments
Comments
(0)