- Notifications
You must be signed in to change notification settings - Fork5.2k
Commit8980c72
committed
pg_dump: Fix compression API errorhandling
Compression in pg_dump is abstracted using an API with multipleimplementations which can be selected at runtime by the user.The API and its implementations have evolved over time, notablecommits includebf9aa49,e996073,84adc8e, and0da243f.The errorhandling defined by the API was however problematic andthe implementations had a few bugs and/or were not following theAPI specification. This commit modifies the API to ensure thatcallers can perform errorhandling efficiently and fixes all theimplementations such that they all implement the API in the sameway. A full list of the changes can be seen below. * write_func: - Make write_func throw an error on all error conditions. All callers of write_func were already checking for success and calling pg_fatal on all errors, so we might as well make the API support that case directly with simpler errorhandling as a result. * open_func: - zstd: move stream initialization from the open function to the read and write functions as they can have fatal errors. Also ensure to dup the file descriptor like none and gzip. - lz4: Ensure to dup the file descriptor like none and gzip. * close_func: - zstd: Ensure to close the file descriptor even if closing down the compressor fails, and clean up state allocation on fclose failures. Make sure to capture errors set by fclose. - lz4: Ensure to close the file descriptor even if closing down the compressor fails, and instead of calling pg_fatal log the failures using pg_log_error. Make sure to capture errors set by fclose. - none: Make sure to catch errors set by fclose. * read_func / gets_func: - Make read_func unconditionally return the number of read bytes instead of making it optional per implementation. - lz4: Make sure to call throw an error and not return -1 - gzip: gzread returning zero cannot be assumed to indicate EOF as it is documented to return zero for some types of errors. - lz4, zstd: Convert the _read_internal helper functions to not call pg_fatal on errors to be able to handle gets_func returning NULL on error. * getc_func: - zstd: Use an unsigned char rather than an int to read char into. * LZ4Stream_init: - Make sure to not switch to inited state until we know that initialization succeeded and reset errno just in case.On top of these changes there are minor comment cleanups andimprovements as well as an attempt to consistently reset errnoin codepaths where it is inspected.This work was initiated by a report of API misuse, which turnedinto a larger body of work. As this is an internal API thesechanges can be backpatched into all affected branches.Author: Tom Lane <tgl@sss.pgh.pa.us>Author: Daniel Gustafsson <daniel@yesql.se>Reported-by: Evgeniy Gorbanev <gorbanyoves@basealt.ru>Discussion:https://postgr.es/m/517794.1750082166@sss.pgh.pa.usBackpatch-through: 161 parent0c97c72 commit8980c72
File tree
8 files changed
+208
-165
lines changed- src/bin/pg_dump
8 files changed
+208
-165
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
251 | 251 | | |
252 | 252 | | |
253 | 253 | | |
254 | | - | |
255 | | - | |
| 254 | + | |
| 255 | + | |
256 | 256 | | |
257 | 257 | | |
258 | 258 | | |
259 | 259 | | |
260 | 260 | | |
261 | | - | |
| 261 | + | |
| 262 | + | |
| 263 | + | |
| 264 | + | |
| 265 | + | |
| 266 | + | |
| 267 | + | |
262 | 268 | | |
263 | 269 | | |
264 | | - | |
| 270 | + | |
| 271 | + | |
| 272 | + | |
| 273 | + | |
| 274 | + | |
| 275 | + | |
265 | 276 | | |
266 | 277 | | |
267 | 278 | | |
268 | 279 | | |
269 | 280 | | |
270 | | - | |
271 | | - | |
272 | | - | |
273 | | - | |
| 281 | + | |
274 | 282 | | |
275 | 283 | | |
276 | | - | |
| 284 | + | |
277 | 285 | | |
278 | 286 | | |
279 | 287 | | |
| 288 | + | |
| 289 | + | |
280 | 290 | | |
281 | | - | |
| 291 | + | |
| 292 | + | |
| 293 | + | |
| 294 | + | |
| 295 | + | |
| 296 | + | |
282 | 297 | | |
283 | 298 | | |
284 | 299 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
269 | 269 | | |
270 | 270 | | |
271 | 271 | | |
| 272 | + | |
272 | 273 | | |
273 | 274 | | |
274 | 275 | | |
| |||
289 | 290 | | |
290 | 291 | | |
291 | 292 | | |
| 293 | + | |
292 | 294 | | |
293 | 295 | | |
294 | 296 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
123 | 123 | | |
124 | 124 | | |
125 | 125 | | |
126 | | - | |
127 | | - | |
| 126 | + | |
| 127 | + | |
128 | 128 | | |
129 | | - | |
| 129 | + | |
| 130 | + | |
130 | 131 | | |
131 | | - | |
| 132 | + | |
132 | 133 | | |
133 | 134 | | |
134 | 135 | | |
135 | 136 | | |
136 | 137 | | |
137 | | - | |
| 138 | + | |
138 | 139 | | |
139 | | - | |
140 | | - | |
| 140 | + | |
| 141 | + | |
141 | 142 | | |
142 | 143 | | |
143 | 144 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
12 | 12 | | |
13 | 13 | | |
14 | 14 | | |
| 15 | + | |
15 | 16 | | |
16 | 17 | | |
17 | 18 | | |
| |||
358 | 359 | | |
359 | 360 | | |
360 | 361 | | |
361 | | - | |
362 | 362 | | |
363 | 363 | | |
364 | 364 | | |
| |||
367 | 367 | | |
368 | 368 | | |
369 | 369 | | |
| 370 | + | |
370 | 371 | | |
371 | 372 | | |
372 | 373 | | |
| |||
390 | 391 | | |
391 | 392 | | |
392 | 393 | | |
| 394 | + | |
393 | 395 | | |
394 | 396 | | |
395 | 397 | | |
| |||
457 | 459 | | |
458 | 460 | | |
459 | 461 | | |
| 462 | + | |
| 463 | + | |
| 464 | + | |
460 | 465 | | |
| 466 | + | |
461 | 467 | | |
462 | 468 | | |
463 | 469 | | |
| |||
484 | 490 | | |
485 | 491 | | |
486 | 492 | | |
| 493 | + | |
| 494 | + | |
487 | 495 | | |
| 496 | + | |
488 | 497 | | |
489 | 498 | | |
490 | 499 | | |
| |||
501 | 510 | | |
502 | 511 | | |
503 | 512 | | |
| 513 | + | |
| 514 | + | |
504 | 515 | | |
505 | 516 | | |
506 | 517 | | |
| |||
558 | 569 | | |
559 | 570 | | |
560 | 571 | | |
561 | | - | |
| 572 | + | |
562 | 573 | | |
563 | 574 | | |
564 | 575 | | |
| |||
567 | 578 | | |
568 | 579 | | |
569 | 580 | | |
570 | | - | |
| 581 | + | |
| 582 | + | |
571 | 583 | | |
572 | 584 | | |
573 | 585 | | |
| |||
578 | 590 | | |
579 | 591 | | |
580 | 592 | | |
581 | | - | |
582 | | - | |
583 | | - | |
584 | | - | |
| 593 | + | |
585 | 594 | | |
| 595 | + | |
586 | 596 | | |
587 | 597 | | |
588 | 598 | | |
589 | | - | |
| 599 | + | |
590 | 600 | | |
591 | 601 | | |
592 | 602 | | |
593 | 603 | | |
594 | | - | |
595 | | - | |
596 | 604 | | |
597 | 605 | | |
598 | 606 | | |
599 | 607 | | |
600 | 608 | | |
601 | | - | |
602 | | - | |
| 609 | + | |
| 610 | + | |
603 | 611 | | |
604 | 612 | | |
605 | 613 | | |
606 | 614 | | |
607 | 615 | | |
608 | 616 | | |
609 | 617 | | |
610 | | - | |
611 | | - | |
612 | | - | |
613 | | - | |
| 618 | + | |
614 | 619 | | |
615 | 620 | | |
616 | 621 | | |
| |||
643 | 648 | | |
644 | 649 | | |
645 | 650 | | |
646 | | - | |
647 | | - | |
648 | 651 | | |
649 | | - | |
650 | | - | |
| 652 | + | |
| 653 | + | |
| 654 | + | |
| 655 | + | |
| 656 | + | |
| 657 | + | |
651 | 658 | | |
652 | 659 | | |
653 | 660 | | |
| |||
669 | 676 | | |
670 | 677 | | |
671 | 678 | | |
| 679 | + | |
672 | 680 | | |
673 | 681 | | |
674 | 682 | | |
| |||
677 | 685 | | |
678 | 686 | | |
679 | 687 | | |
680 | | - | |
681 | | - | |
682 | | - | |
683 | 688 | | |
684 | | - | |
685 | | - | |
| 689 | + | |
| 690 | + | |
| 691 | + | |
| 692 | + | |
| 693 | + | |
| 694 | + | |
| 695 | + | |
| 696 | + | |
| 697 | + | |
| 698 | + | |
| 699 | + | |
686 | 700 | | |
687 | 701 | | |
688 | 702 | | |
689 | 703 | | |
690 | | - | |
691 | | - | |
| 704 | + | |
| 705 | + | |
692 | 706 | | |
693 | 707 | | |
694 | 708 | | |
695 | 709 | | |
696 | 710 | | |
697 | | - | |
698 | | - | |
| 711 | + | |
| 712 | + | |
699 | 713 | | |
700 | 714 | | |
701 | 715 | | |
702 | 716 | | |
703 | 717 | | |
704 | 718 | | |
705 | 719 | | |
| 720 | + | |
706 | 721 | | |
707 | | - | |
| 722 | + | |
| 723 | + | |
| 724 | + | |
| 725 | + | |
| 726 | + | |
| 727 | + | |
| 728 | + | |
| 729 | + | |
| 730 | + | |
708 | 731 | | |
709 | 732 | | |
710 | 733 | | |
711 | 734 | | |
712 | 735 | | |
713 | 736 | | |
714 | | - | |
715 | 737 | | |
716 | 738 | | |
717 | 739 | | |
718 | | - | |
| 740 | + | |
719 | 741 | | |
720 | | - | |
721 | | - | |
| 742 | + | |
| 743 | + | |
722 | 744 | | |
723 | 745 | | |
724 | 746 | | |
725 | 747 | | |
726 | 748 | | |
727 | | - | |
728 | | - | |
729 | 749 | | |
730 | 750 | | |
731 | 751 | | |
| |||
0 commit comments
Comments
(0)