8000 When using --trace then enforce logging of the apply SQL statements. by dimitri · Pull Request #252 · dimitri/pgcopydb · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

When using --trace then enforce logging of the apply SQL statements. #252

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 18 additions & 2 deletions src/bin/pgcopydb/cli_clone_follow.c
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,13 @@ clone_and_follow(CopyDataSpec *copySpecs)
{
StreamSpecs streamSpecs = { 0 };

/*
* Refrain from logging SQL statements in the apply module, because they
* contain user data. That said, when --trace has been used, bypass that
* privacy feature.
*/
bool logSQL = log_get_level() <= LOG_TRACE;

if (!stream_init_specs(&streamSpecs,
&(copySpecs->cfPaths.cdc),
copySpecs->source_pguri,
Expand All @@ -198,7 +205,8 @@ clone_and_follow(CopyDataSpec *copySpecs)
copyDBoptions.endpos,
STREAM_MODE_CATCHUP,
copyDBoptions.stdIn,
copyDBoptions.stdOut))
copyDBoptions.stdOut,
logSQL))
{
/* errors have already been logged */
exit(EXIT_CODE_INTERNAL_ERROR);
Expand Down Expand Up @@ -316,6 +324,13 @@ cli_follow(int argc, char **argv)

(void) cli_copy_prepare_specs(&copySpecs, DATA_SECTION_ALL);

/*
* Refrain from logging SQL statements in the apply module, because they
* contain user data. That said, when --trace has been used, bypass that
* privacy feature.
*/
bool logSQL = log_get_level() <= LOG_TRACE;

StreamSpecs specs = { 0 };

if (!stream_init_specs(&specs,
Expand All @@ -328,7 +343,8 @@ cli_follow(int argc, char **argv)
copyDBoptions.endpos,
STREAM_MODE_CATCHUP,
copyDBoptions.stdIn,
copyDBoptions.stdOut))
copyDBoptions.stdOut,
logSQL))
{
/* errors have already been logged */
exit(EXIT_CODE_INTERNAL_ERROR);
Expand Down
53 changes: 47 additions & 6 deletions src/bin/pgcopydb/cli_stream.c
Original file line number Diff line number Diff line change
Expand Up @@ -660,6 +660,13 @@ cli_stream_catchup(int argc, char **argv)
exit(EXIT_CODE_INTERNAL_ERROR);
}

/*
* Refrain from logging SQL statements in the apply module, because they
* contain user data. That said, when --trace has been used, bypass that
* privacy feature.
*/
bool logSQL = log_get_level() <= LOG_TRACE;

StreamSpecs specs = { 0 };

if (!stream_init_specs(&specs,
Expand All @@ -672,7 +679,8 @@ cli_stream_catchup(int argc, char **argv)
streamDBoptions.endpos,
STREAM_MODE_CATCHUP,
streamDBoptions.stdIn,
streamDBoptions.stdOut))
streamDBoptions.stdOut,
logSQL))
{
/* errors have already been logged */
exit(EXIT_CODE_INTERNAL_ERROR);
Expand Down Expand Up @@ -736,6 +744,13 @@ cli_stream_replay(int argc, char **argv)
exit(EXIT_CODE_INTERNAL_ERROR);
}

/*
* Refrain from logging SQL statements in the apply module, because they
* contain user data. That said, when --trace has been used, bypass that
* privacy feature.
*/
bool logSQL = log_get_level() <= LOG_TRACE;

StreamSpecs specs = { 0 };

if (!stream_init_specs(&specs,
Expand All @@ -748,7 +763,8 @@ cli_stream_replay(int argc, char **argv)
streamDBoptions.endpos,
STREAM_MODE_REPLAY,
true, /* stdin */
true)) /* stdout */
true, /* stdout */
logSQL))
{
/* errors have already been logged */
exit(EXIT_CODE_INTERNAL_ERROR);
Expand Down Expand Up @@ -854,6 +870,13 @@ cli_stream_transform(int argc, char **argv)
exit(EXIT_CODE_INTERNAL_ERROR);
}

/*
* Refrain from logging SQL statements in the apply module, because they
* contain user data. That said, when --trace has been used, bypass that
* privacy feature.
*/
bool logSQL = log_get_level() <= LOG_TRACE;

StreamSpecs specs = { 0 };

if (!stream_init_specs(&specs,
Expand All @@ -866,7 +889,8 @@ cli_stream_transform(int argc, char **argv)
streamDBoptions.endpos,
STREAM_MODE_CATCHUP,
streamDBoptions.stdIn,
streamDBoptions.stdOut))
streamDBoptions.stdOut,
logSQL))
{
/* errors have already been logged */
exit(EXIT_CODE_INTERNAL_ERROR);
Expand Down Expand Up @@ -972,6 +996,13 @@ cli_stream_apply(int argc, char **argv)
exit(EXIT_CODE_INTERNAL_ERROR);
}

/*
* Refrain from logging SQL statements in the apply module, because they
* contain user data. That said, when --trace has been used, bypass that
* privacy feature.
*/
bool logSQL = log_get_level() <= LOG_TRACE;

/*
* Force the SQL filename to the given argument, bypassing filename
* computations based on origin tracking. Already known-applied
Expand All @@ -994,7 +1025,8 @@ cli_stream_apply(int argc, char **argv)
streamDBoptions.endpos,
STREAM_MODE_CATCHUP,
true, /* streamDBoptions.stdIn */
false /* streamDBoptions.stdOut */))
false, /* streamDBoptions.stdOut */
logSQL))
{
/* errors have already been logged */
exit(EXIT_CODE_INTERNAL_ERROR);
Expand All @@ -1021,7 +1053,8 @@ cli_stream_apply(int argc, char **argv)
streamDBoptions.target_pguri,
streamDBoptions.origin,
streamDBoptions.endpos,
true))
true,
logSQL))
{
log_error("Failed to setup replication origin on the target database");
exit(EXIT_CODE_TARGET);
Expand Down Expand Up @@ -1073,6 +1106,13 @@ stream_start_in_mode(LogicalStreamMode mode)
exit(EXIT_CODE_INTERNAL_ERROR);
}

/*
* Refrain from logging SQL statements in the apply module, because they
* contain user data. That said, when --trace has been used, bypass that
* privacy feature.
*/
bool logSQL = log_get_level() <= LOG_TRACE;

StreamSpecs specs = { 0 };

if (!stream_init_specs(&specs,
Expand All @@ -1085,7 +1125,8 @@ stream_start_in_mode(LogicalStreamMode mode)
streamDBoptions.endpos,
mode,
streamDBoptions.stdIn,
streamDBoptions.stdOut))
streamDBoptions.stdOut,
logSQL))
{
/* errors have already been logged */
exit(EXIT_CODE_INTERNAL_ERROR);
Expand Down
14 changes: 8 additions & 6 deletions src/bin/pgcopydb/ld_apply.c
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,8 @@ stream_apply_catchup(StreamSpecs *specs)
specs->target_pguri,
specs->origin,
specs->endpos,
context.apply))
context.apply,
specs->logSQL))
{
log_error("Failed to setup replication origin on the target database");
return false;
Expand Down Expand Up @@ -210,7 +211,7 @@ stream_apply_wait_for_sentinel(StreamSpecs *specs, StreamApplyContext *context)
}

/* skip logging the sentinel queries, we log_debug the values fetched */
src.logSQL = false;
src.logSQL = context->logSQL;

while (!sentinel.apply)
{
Expand Down Expand Up @@ -287,7 +288,7 @@ stream_apply_sync_sentinel(StreamApplyContext *context)
}

/* limit the amount of logging of the apply process */
src.logSQL = false;
src.logSQL = context->logSQL;

if (!pgsql_sync_sentinel_apply(&src, context->previousLSN, &sentinel))
{
Expand Down Expand Up @@ -677,7 +678,8 @@ setupReplicationOrigin(StreamApplyContext *context,
char *target_pguri,
char *origin,
uint64_t endpos,
bool apply)
bool apply,
bool logSQL)
{
PGSQL *pgsql = &(context->pgsql);
char *nodeName = context->origin;
Expand Down Expand Up @@ -718,8 +720,8 @@ setupReplicationOrigin(StreamApplyContext *context,
/* we're going to send several replication origin commands */
pgsql->connectionStatementType = PGSQL_CONNECTIO 9E81 N_MULTI_STATEMENT;

/* we also want to skip logging any SQL query that we apply */
pgsql->logSQL = false;
/* we also might want to skip logging any SQL query that we apply */
pgsql->logSQL = logSQL;

uint32_t oid = 0;

Expand Down
3 changes: 2 additions & 1 deletion src/bin/pgcopydb/ld_replay.c
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,8 @@ stream_apply_replay(StreamSpecs *specs)
specs->target_pguri,
specs->origin,
specs->endpos,
context->apply))
context->apply,
specs->logSQL))
{
log_error("Failed to setup replication origin on the target database");
return false;
Expand Down
4 changes: 3 additions & 1 deletion src/bin/pgcopydb/ld_stream.c
Original file line number Diff line number Diff line change
Expand Up @@ -51,12 +51,14 @@ stream_init_specs(StreamSpecs *specs,
uint64_t endpos,
LogicalStreamMode mode,
bool stdin,
bool stdout)
bool stdout,
bool logSQL)
{
/* just copy into StreamSpecs what's been initialized in copySpecs */
specs->mode = mode;
specs->stdIn = stdin;
specs->stdOut = stdout;
specs->logSQL = logSQL;

specs->paths = *paths;
specs->endpos = endpos;
Expand Down
9 changes: 7 additions & 2 deletions src/bin/pgcopydb/ld_stream.h
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,8 @@ typedef struct StreamApplyContext
bool reachedStartPos;
bool reachedEndPos;

bool logSQL;

char wal[MAXPGPATH];
char sqlFileName[MAXPGPATH];
} StreamApplyContext;
Expand Down Expand Up @@ -331,6 +333,7 @@ struct StreamSpecs

bool restart;
bool resume;
bool logSQL;

/* subprocess management */
FollowSubProcess prefetch;
Expand Down Expand Up @@ -372,7 +375,8 @@ bool stream_init_specs(StreamSpecs *specs,
uint64_t endpos,
LogicalStreamMode mode,
bool stdIn,
bool stdOut);
bool stdOut,
bool logSQL);

bool stream_init_for_mode(StreamSpecs *specs, LogicalStreamMode mode);

Expand Down Expand Up @@ -525,7 +529,8 @@ bool setupReplicationOrigin(StreamApplyContext *context,
char *target_pguri,
char *origin,
uint64_t endpos,
bool apply);
bool apply,
bool logSQL);

bool computeSQLFileName(StreamApplyContext *context);

Expand Down
0