Repository navigation
Write each log record with one write() per destination - #76
Open
teknogeek0 wants to merge 2 commits into
Open
teknogeek0 wants to merge 2 commits into
teknogeek0 wants to merge 2 commits into
Conversation
The PGCOPYDB_LOG_FILENAME file used a buffered FILE* that was not flushed per record or before fork(), so lines from different processes were torn, copied into children, or lost on a crash. JSON messages longer than 2048 bytes overflowed a stack buffer. Each record is now built in one buffer and written with one write() to stderr, to the log file, and to a new JSON Lines file at <dir>/log/pgcopydb.jsonl (PGCOPYDB_LOG_WORKDIR). The SIGQUIT handler no longer logs from signal context. The new tests/logging suite checks that the text and JSON output does not change and that concurrent writers do not tear or duplicate records.
Remove the list indentation and the trailing space in a code span.
This was referenced Oct 30, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Each log record is now built in one buffer and written with one
write()to each destination: stderr, thePGCOPYDB_LOG_FILENAMEfile, and a new JSON Lines file at<dir>/log/pgcopydb.jsonl. The stderr and log file output is byte-identical to the current output. The newtests/loggingsuite stores the current output as golden files and compares against them.Defects in the current logger that the new suite shows:
PGCOPYDB_LOG_FILENAMEfile is a bufferedFILE*that is not flushed per record or beforefork(). In a stress run with 16 writers, up to 93% of the text records were torn.PGCOPYDB_LOG_JSONorPGCOPYDB_LOG_JSON_FILE, a message longer than 2048 bytes overflows a stack buffer and the process crashes.semaphore_log_lock_functionunlocks after a failed lock, which sets the semaphore value to 2.catch_quit_and_exitlogs and callsexit()from the signal handler.Behavior changes:
<dir>/log/pgcopydb.jsonlis written when--diris set. It gets INFO records, or more with-v,-d, or-z, and it is appended to across runs.PGCOPYDB_LOG_WORKDIR=off|<level>controls it. Its records addrun_idandrolekeys.rolekey aftermessage.�. Before, themessagekey was dropped.SIGQUIT received, exiting nowto stderr, removes the System V resources it owns, and calls_exit().