Commit 201297d
committed
Use temporary file when compressing rotated logs and atomically rename to prevent reading incomplete files
If another process is watching for `*.gz` files then it's possible to
begin reading the archive before it has been completely created,
resulting in corruption if the other process is copying the archive to
another location (for example: archival to s3).
To resolve this, we can use a different suffix when writing the file so
that other programs do not read it while it's being created. Once the
archive has been completely created, we atomically rename it to the
desired file name with the `*.gz` extension, ensuring external programs
only ever see the finished archive.
Signed-off-by: Chance Zibolski <[email protected]>1 parent 47ffae2 commit 201297d
1 file changed
+29
-3
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
38 | 38 | | |
39 | 39 | | |
40 | 40 | | |
| 41 | + | |
41 | 42 | | |
42 | 43 | | |
43 | 44 | | |
| |||
477 | 478 | | |
478 | 479 | | |
479 | 480 | | |
480 | | - | |
| 481 | + | |
| 482 | + | |
| 483 | + | |
| 484 | + | |
| 485 | + | |
481 | 486 | | |
482 | 487 | | |
483 | 488 | | |
484 | 489 | | |
485 | 490 | | |
486 | | - | |
| 491 | + | |
487 | 492 | | |
488 | 493 | | |
489 | 494 | | |
| |||
493 | 498 | | |
494 | 499 | | |
495 | 500 | | |
496 | | - | |
| 501 | + | |
497 | 502 | | |
498 | 503 | | |
499 | 504 | | |
500 | 505 | | |
501 | 506 | | |
502 | 507 | | |
503 | 508 | | |
| 509 | + | |
| 510 | + | |
| 511 | + | |
| 512 | + | |
| 513 | + | |
| 514 | + | |
| 515 | + | |
| 516 | + | |
| 517 | + | |
| 518 | + | |
| 519 | + | |
| 520 | + | |
504 | 521 | | |
505 | 522 | | |
506 | 523 | | |
| 524 | + | |
| 525 | + | |
507 | 526 | | |
508 | 527 | | |
509 | 528 | | |
510 | 529 | | |
| 530 | + | |
511 | 531 | | |
512 | 532 | | |
513 | 533 | | |
| 534 | + | |
| 535 | + | |
| 536 | + | |
| 537 | + | |
| 538 | + | |
| 539 | + | |
514 | 540 | | |
515 | 541 | | |
516 | 542 | | |
| |||
0 commit comments