Skip to content

Commit

Permalink
Add in_repliate_ddl_command variable
Browse files Browse the repository at this point in the history
Add a global in_repliate_ddl_command variable that mirrors the one in
pgl3, which may be used in user ProcessUtility_hook code to test whether
it's running in the context of pglogical.replicate_ddl_command.

This is not exposed to SQL because it's not much use. The event triggers
for sql_drop and ddl_command_end fire after pglogical_replicate_ddl_command
has returned. There's no way to annotate the information they collect and
return with whether they were replicated or not. Also, for drops, the catalog
changes are already visible so we can't even see if the table was replicated
or not.

RM#5881
  • Loading branch information
ringerc committed Nov 1, 2018
1 parent 500e314 commit e59a85b
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 8 deletions.
2 changes: 2 additions & 0 deletions pglogical.h
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,8 @@ extern void pglogical_create_sequence_state_record(Oid seqoid);
extern void pglogical_drop_sequence_state_record(Oid seqoid);
extern int64 sequence_get_last_value(Oid seqoid);

extern bool in_pglogical_replicate_ddl_command;

#include "utils/memdebug.h"

/*
Expand Down
30 changes: 22 additions & 8 deletions pglogical_functions.c
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,8 @@ static void gen_slot_name(Name slot_name, char *dbname,
const char *provider_name,
const char *subscriber_name);

bool in_pglogical_replicate_ddl_command = false;

static PGLogicalLocalNode *
check_local_node(bool for_update)
{
Expand Down Expand Up @@ -1761,13 +1763,26 @@ pglogical_replicate_ddl_command(PG_FUNCTION_ARGS)
queue_message(replication_sets, GetUserId(),
QUEUE_COMMAND_TYPE_SQL, cmd.data);

/* Execute the query locally. */
pglogical_execute_sql_command(query, GetUserNameFromId(GetUserId()
#if PG_VERSION_NUM >= 90500
, false
#endif
),
false);
/*
* Execute the query locally.
* Use PG_TRY to ensure in_pglogical_replicate_ddl_command gets cleaned up
*/
in_pglogical_replicate_ddl_command = true;
PG_TRY();
{
pglogical_execute_sql_command(query, GetUserNameFromId(GetUserId()
#if PG_VERSION_NUM >= 90500
, false
#endif
),
false);
}
PG_CATCH();
{
in_pglogical_replicate_ddl_command = false;
PG_RE_THROW();
}
PG_END_TRY();

/*
* Restore the GUC variables we set above.
Expand All @@ -1777,7 +1792,6 @@ pglogical_replicate_ddl_command(PG_FUNCTION_ARGS)
PG_RETURN_BOOL(true);
}


/*
* pglogical_queue_trigger
*
Expand Down

0 comments on commit e59a85b

Please sign in to comment.