forked frompostgres/postgres
- Notifications
You must be signed in to change notification settings - Fork6
Commit94173d3
committed
Fix assorted issues in parallel vacuumdb.
Avoid storing the result of PQsocket() in a pgsocket variable; it'sdeclared as int, and the no-socket test is properly written as "x < 0"not "x == PGINVALID_SOCKET". This accidentally had no bad effectbecause we never got to init_slot() with a bad connection, but it'sstill wrong.Actually, it seems like we should avoid storing the result for a longperiod at all. The function's not so expensive that it's worth avoiding,and the existing coding technique here would fail if anyone tried toPQreset the connection during the life of the program. Hence, justre-call PQsocket every time we construct a select(2) mask.Speaking of select(), GetIdleSlot imagined that it could compute theselect mask once and continue to use it over multiple calls toselect_loop(), which is pretty bogus since that would stomp on themask on return. This could only matter if the function's outer loopiterated more than once, which is unlikely (it'd take some connectionreceiving data, but not enough to complete its command). But if itdid happen, we'd acquire "tunnel vision" and stop watching the otherconnections for query termination, with the effect of losing parallelism.Another way in which GetIdleSlot could lose parallelism is that oncePQisBusy returns false, it would lock in on that connection and doPQgetResult until that returns NULL; in some cases that could resultin blocking. (Perhaps this can never happen in vacuumdb due to thelimited set of commands that it can issue, but I'm not quite sureof that, and even if true today it's not a future-proof assumption.)Refactor the code to do that properly, so that it risks blocking inPQgetResult only in cases where we need to wait anyway.Another loss-of-parallelism problem, which *is* easily demonstrable,is that any setup queries issued during prepare_vacuum_command() werealways issued on the last-to-be-created connection, whether or notthat was idle. Long-running operations on that connection thusprevented issuance of additional operations on the other ones, exceptin the limited cases where no preparatory query was needed. Instead,wait till we've identified a free connection and use that one.Also, avoid core dump due to undersized malloc request in the casethat no tables are identified to be vacuumed.The bogus no-socket test was noted by CharSyam, the other problemsidentified in my own code review. Back-patch to 9.5 where parallelvacuumdb was introduced.Discussion:https://postgr.es/m/CAMrLSE6etb33-192DTEUGkV-TsvEcxtBDxGWG1tgNOMnQHwgDA@mail.gmail.com1 parent5635c7a commit94173d3
1 file changed
+114
-78
lines changedLines changed: 114 additions & 78 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
28 | 28 |
| |
29 | 29 |
| |
30 | 30 |
| |
31 |
| - | |
32 |
| - | |
33 |
| - | |
| 31 | + | |
| 32 | + | |
34 | 33 |
| |
35 | 34 |
| |
36 | 35 |
| |
| |||
71 | 70 |
| |
72 | 71 |
| |
73 | 72 |
| |
| 73 | + | |
| 74 | + | |
| 75 | + | |
74 | 76 |
| |
75 | 77 |
| |
76 | 78 |
| |
77 | 79 |
| |
78 | 80 |
| |
79 | 81 |
| |
80 |
| - | |
| 82 | + | |
81 | 83 |
| |
82 | 84 |
| |
83 | 85 |
| |
| |||
343 | 345 |
| |
344 | 346 |
| |
345 | 347 |
| |
346 |
| - | |
| 348 | + | |
347 | 349 |
| |
348 | 350 |
| |
349 | 351 |
| |
| |||
387 | 389 |
| |
388 | 390 |
| |
389 | 391 |
| |
390 |
| - | |
391 | 392 |
| |
392 | 393 |
| |
393 | 394 |
| |
| |||
432 | 433 |
| |
433 | 434 |
| |
434 | 435 |
| |
| 436 | + | |
| 437 | + | |
435 | 438 |
| |
436 |
| - | |
| 439 | + | |
437 | 440 |
| |
438 | 441 |
| |
439 | 442 |
| |
440 | 443 |
| |
441 | 444 |
| |
442 | 445 |
| |
443 |
| - | |
| 446 | + | |
444 | 447 |
| |
445 | 448 |
| |
446 | 449 |
| |
| |||
462 | 465 |
| |
463 | 466 |
| |
464 | 467 |
| |
465 |
| - | |
466 | 468 |
| |
467 |
| - | |
468 |
| - | |
469 |
| - | |
| 469 | + | |
470 | 470 |
| |
471 | 471 |
| |
472 | 472 |
| |
| |||
498 | 498 |
| |
499 | 499 |
| |
500 | 500 |
| |
| 501 | + | |
| 502 | + | |
| 503 | + | |
| 504 | + | |
| 505 | + | |
| 506 | + | |
| 507 | + | |
501 | 508 |
| |
502 | 509 |
| |
503 | 510 |
| |
504 |
| - | |
| 511 | + | |
505 | 512 |
| |
506 | 513 |
| |
507 | 514 |
| |
| |||
514 | 521 |
| |
515 | 522 |
| |
516 | 523 |
| |
| 524 | + | |
517 | 525 |
| |
518 | 526 |
| |
519 |
| - | |
520 | 527 |
| |
521 | 528 |
| |
522 |
| - | |
523 |
| - | |
524 | 529 |
| |
525 | 530 |
| |
526 | 531 |
| |
| |||
691 | 696 |
| |
692 | 697 |
| |
693 | 698 |
| |
694 |
| - | |
| 699 | + | |
| 700 | + | |
695 | 701 |
| |
696 | 702 |
| |
697 | 703 |
| |
| |||
739 | 745 |
| |
740 | 746 |
| |
741 | 747 |
| |
742 |
| - | |
743 |
| - | |
744 |
| - | |
745 |
| - | |
746 | 748 |
| |
747 | 749 |
| |
748 | 750 |
| |
| |||
751 | 753 |
| |
752 | 754 |
| |
753 | 755 |
| |
754 |
| - | |
755 |
| - | |
756 |
| - | |
757 |
| - | |
758 |
| - | |
759 |
| - | |
760 |
| - | |
761 |
| - | |
762 | 756 |
| |
763 |
| - | |
| 757 | + | |
764 | 758 |
| |
765 | 759 |
| |
766 |
| - | |
767 |
| - | |
768 |
| - | |
| 760 | + | |
| 761 | + | |
769 | 762 |
| |
770 | 763 |
| |
771 | 764 |
| |
772 | 765 |
| |
773 | 766 |
| |
774 | 767 |
| |
775 |
| - | |
| 768 | + | |
776 | 769 |
| |
| 770 | + | |
| 771 | + | |
777 | 772 |
| |
778 | 773 |
| |
| 774 | + | |
| 775 | + | |
| 776 | + | |
| 777 | + | |
| 778 | + | |
| 779 | + | |
| 780 | + | |
| 781 | + | |
| 782 | + | |
| 783 | + | |
| 784 | + | |
| 785 | + | |
| 786 | + | |
| 787 | + | |
| 788 | + | |
| 789 | + | |
| 790 | + | |
| 791 | + | |
| 792 | + | |
779 | 793 |
| |
780 | 794 |
| |
781 | 795 |
| |
| |||
793 | 807 |
| |
794 | 808 |
| |
795 | 809 |
| |
796 |
| - | |
797 |
| - | |
798 |
| - | |
799 |
| - | |
800 |
| - | |
801 |
| - | |
| 810 | + | |
802 | 811 |
| |
803 |
| - | |
| 812 | + | |
| 813 | + | |
| 814 | + | |
| 815 | + | |
| 816 | + | |
804 | 817 |
| |
805 |
| - | |
806 |
| - | |
| 818 | + | |
| 819 | + | |
| 820 | + | |
| 821 | + | |
807 | 822 |
| |
808 |
| - | |
809 |
| - | |
| 823 | + | |
| 824 | + | |
| 825 | + | |
| 826 | + | |
| 827 | + | |
| 828 | + | |
| 829 | + | |
| 830 | + | |
| 831 | + | |
| 832 | + | |
| 833 | + | |
| 834 | + | |
| 835 | + | |
| 836 | + | |
| 837 | + | |
| 838 | + | |
810 | 839 |
| |
811 | 840 |
| |
812 | 841 |
| |
813 | 842 |
| |
814 | 843 |
| |
815 | 844 |
| |
| 845 | + | |
| 846 | + | |
| 847 | + | |
| 848 | + | |
| 849 | + | |
| 850 | + | |
| 851 | + | |
| 852 | + | |
| 853 | + | |
| 854 | + | |
| 855 | + | |
| 856 | + | |
| 857 | + | |
| 858 | + | |
| 859 | + | |
| 860 | + | |
| 861 | + | |
| 862 | + | |
| 863 | + | |
| 864 | + | |
| 865 | + | |
| 866 | + | |
| 867 | + | |
| 868 | + | |
| 869 | + | |
| 870 | + | |
| 871 | + | |
| 872 | + | |
| 873 | + | |
| 874 | + | |
| 875 | + | |
| 876 | + | |
816 | 877 |
| |
817 | 878 |
| |
818 | 879 |
| |
819 |
| - | |
820 |
| - | |
821 |
| - | |
| 880 | + | |
| 881 | + | |
822 | 882 |
| |
823 | 883 |
| |
824 | 884 |
| |
825 | 885 |
| |
| 886 | + | |
826 | 887 |
| |
827 | 888 |
| |
828 | 889 |
| |
829 | 890 |
| |
830 | 891 |
| |
831 |
| - | |
832 |
| - | |
833 |
| - | |
834 |
| - | |
835 |
| - | |
836 |
| - | |
837 |
| - | |
838 |
| - | |
839 |
| - | |
840 |
| - | |
841 |
| - | |
842 |
| - | |
843 |
| - | |
844 |
| - | |
845 |
| - | |
846 |
| - | |
847 |
| - | |
848 |
| - | |
849 |
| - | |
| 892 | + | |
| 893 | + | |
850 | 894 |
| |
851 | 895 |
| |
852 |
| - | |
853 |
| - | |
| 896 | + | |
854 | 897 |
| |
855 | 898 |
| |
856 | 899 |
| |
| |||
942 | 985 |
| |
943 | 986 |
| |
944 | 987 |
| |
945 |
| - | |
| 988 | + | |
946 | 989 |
| |
947 | 990 |
| |
| 991 | + | |
948 | 992 |
| |
949 |
| - | |
950 |
| - | |
951 |
| - | |
952 |
| - | |
953 |
| - | |
954 |
| - | |
955 |
| - | |
956 |
| - | |
957 | 993 |
| |
958 | 994 |
| |
959 | 995 |
| |
|
0 commit comments
Comments
(0)