Skip to content

Commit e83aa9f

Browse files
committed
Simplify some logic in CreateReplicationSlot()
This refactoring reduces the code in charge of creating replication slots from two "if" block to a single one, making it slightly cleaner. This change is possible since 1d04a59, that has removed the intermediate code that existed between the two "if" blocks in charge of initializing the output message buffer. Author: Peter Smith Discussion: https://postgr.es/m/CAHut+PtnJzqKT41Zt8pChRzba=QgCqjtfYvcf84NMj3VFJoKfw@mail.gmail.com
1 parent 7c3fb50 commit e83aa9f

File tree

1 file changed

+16
-16
lines changed

1 file changed

+16
-16
lines changed

src/backend/replication/walsender.c

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1061,9 +1061,25 @@ CreateReplicationSlot(CreateReplicationSlotCmd *cmd)
10611061
ReplicationSlotCreate(cmd->slotname, false,
10621062
cmd->temporary ? RS_TEMPORARY : RS_PERSISTENT,
10631063
false);
1064+
1065+
if (reserve_wal)
1066+
{
1067+
ReplicationSlotReserveWal();
1068+
1069+
ReplicationSlotMarkDirty();
1070+
1071+
/* Write this slot to disk if it's a permanent one. */
1072+
if (!cmd->temporary)
1073+
ReplicationSlotSave();
1074+
}
10641075
}
10651076
else
10661077
{
1078+
LogicalDecodingContext *ctx;
1079+
bool need_full_snapshot = false;
1080+
1081+
Assert(cmd->kind == REPLICATION_KIND_LOGICAL);
1082+
10671083
CheckLogicalDecodingRequirements();
10681084

10691085
/*
@@ -1076,12 +1092,6 @@ CreateReplicationSlot(CreateReplicationSlotCmd *cmd)
10761092
ReplicationSlotCreate(cmd->slotname, true,
10771093
cmd->temporary ? RS_TEMPORARY : RS_EPHEMERAL,
10781094
two_phase);
1079-
}
1080-
1081-
if (cmd->kind == REPLICATION_KIND_LOGICAL)
1082-
{
1083-
LogicalDecodingContext *ctx;
1084-
bool need_full_snapshot = false;
10851095

10861096
/*
10871097
* Do options check early so that we can bail before calling the
@@ -1175,16 +1185,6 @@ CreateReplicationSlot(CreateReplicationSlotCmd *cmd)
11751185
if (!cmd->temporary)
11761186
ReplicationSlotPersist();
11771187
}
1178-
else if (cmd->kind == REPLICATION_KIND_PHYSICAL && reserve_wal)
1179-
{
1180-
ReplicationSlotReserveWal();
1181-
1182-
ReplicationSlotMarkDirty();
1183-
1184-
/* Write this slot to disk if it's a permanent one. */
1185-
if (!cmd->temporary)
1186-
ReplicationSlotSave();
1187-
}
11881188

11891189
snprintf(xloc, sizeof(xloc), "%X/%X",
11901190
LSN_FORMAT_ARGS(MyReplicationSlot->data.confirmed_flush));

0 commit comments

Comments
 (0)