mirror of
https://github.com/postgres/postgres.git
synced 2025-11-10 17:42:29 +03:00
Add option to enable two_phase commits via pg_create_logical_replication_slot.
Commit 0aa8a01d04 extends the output plugin API to allow decoding of
prepared xacts and allowed the user to enable/disable the two-phase option
via pg_logical_slot_get_changes(). This can lead to a problem such that
the first time when it gets changes via pg_logical_slot_get_changes()
without two_phase option enabled it will not get the prepared even though
prepare is after consistent snapshot. Now next time during getting changes,
if the two_phase option is enabled it can skip prepare because by that
time start decoding point has been moved. So the user will only get commit
prepared.
Allow to enable/disable this option at the create slot time and default
will be false. It will break the existing slots which is fine in a major
release.
Author: Ajin Cherian
Reviewed-by: Amit Kapila and Vignesh C
Discussion: https://postgr.es/m/d0f60d60-133d-bf8d-bd70-47784d8fabf3@enterprisedb.com
This commit is contained in:
@@ -50,7 +50,7 @@ create_physical_replication_slot(char *name, bool immediately_reserve,
|
||||
|
||||
/* acquire replication slot, this will check for conflicting names */
|
||||
ReplicationSlotCreate(name, false,
|
||||
temporary ? RS_TEMPORARY : RS_PERSISTENT);
|
||||
temporary ? RS_TEMPORARY : RS_PERSISTENT, false);
|
||||
|
||||
if (immediately_reserve)
|
||||
{
|
||||
@@ -124,7 +124,8 @@ pg_create_physical_replication_slot(PG_FUNCTION_ARGS)
|
||||
*/
|
||||
static void
|
||||
create_logical_replication_slot(char *name, char *plugin,
|
||||
bool temporary, XLogRecPtr restart_lsn,
|
||||
bool temporary, bool two_phase,
|
||||
XLogRecPtr restart_lsn,
|
||||
bool find_startpoint)
|
||||
{
|
||||
LogicalDecodingContext *ctx = NULL;
|
||||
@@ -140,7 +141,7 @@ create_logical_replication_slot(char *name, char *plugin,
|
||||
* error as well.
|
||||
*/
|
||||
ReplicationSlotCreate(name, true,
|
||||
temporary ? RS_TEMPORARY : RS_EPHEMERAL);
|
||||
temporary ? RS_TEMPORARY : RS_EPHEMERAL, two_phase);
|
||||
|
||||
/*
|
||||
* Create logical decoding context to find start point or, if we don't
|
||||
@@ -177,6 +178,7 @@ pg_create_logical_replication_slot(PG_FUNCTION_ARGS)
|
||||
Name name = PG_GETARG_NAME(0);
|
||||
Name plugin = PG_GETARG_NAME(1);
|
||||
bool temporary = PG_GETARG_BOOL(2);
|
||||
bool two_phase = PG_GETARG_BOOL(3);
|
||||
Datum result;
|
||||
TupleDesc tupdesc;
|
||||
HeapTuple tuple;
|
||||
@@ -193,6 +195,7 @@ pg_create_logical_replication_slot(PG_FUNCTION_ARGS)
|
||||
create_logical_replication_slot(NameStr(*name),
|
||||
NameStr(*plugin),
|
||||
temporary,
|
||||
two_phase,
|
||||
InvalidXLogRecPtr,
|
||||
true);
|
||||
|
||||
@@ -236,7 +239,7 @@ pg_drop_replication_slot(PG_FUNCTION_ARGS)
|
||||
Datum
|
||||
pg_get_replication_slots(PG_FUNCTION_ARGS)
|
||||
{
|
||||
#define PG_GET_REPLICATION_SLOTS_COLS 13
|
||||
#define PG_GET_REPLICATION_SLOTS_COLS 14
|
||||
ReturnSetInfo *rsinfo = (ReturnSetInfo *) fcinfo->resultinfo;
|
||||
TupleDesc tupdesc;
|
||||
Tuplestorestate *tupstore;
|
||||
@@ -432,6 +435,8 @@ pg_get_replication_slots(PG_FUNCTION_ARGS)
|
||||
values[i++] = Int64GetDatum(failLSN - currlsn);
|
||||
}
|
||||
|
||||
values[i++] = BoolGetDatum(slot_contents.data.two_phase);
|
||||
|
||||
Assert(i == PG_GET_REPLICATION_SLOTS_COLS);
|
||||
|
||||
tuplestore_putvalues(tupstore, tupdesc, values, nulls);
|
||||
@@ -796,6 +801,7 @@ copy_replication_slot(FunctionCallInfo fcinfo, bool logical_slot)
|
||||
create_logical_replication_slot(NameStr(*dst_name),
|
||||
plugin,
|
||||
temporary,
|
||||
false,
|
||||
src_restart_lsn,
|
||||
false);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user