From 2fa9bff99df0dc22054038aae9033a6b57055d9d Mon Sep 17 00:00:00 2001 From: Peter Smith Date: Thu, 23 Nov 2023 09:20:34 +1100 Subject: [PATCH v1] replorigin_session_setup refactoring --- src/backend/replication/logical/origin.c | 21 +++++++++------------ 1 file changed, 9 insertions(+), 12 deletions(-) diff --git a/src/backend/replication/logical/origin.c b/src/backend/replication/logical/origin.c index 460e3dc..9ca3fd7 100644 --- a/src/backend/replication/logical/origin.c +++ b/src/backend/replication/logical/origin.c @@ -1134,28 +1134,26 @@ replorigin_session_setup(RepOriginId node, int acquired_by) if (curstate->roident != node) continue; - else if (curstate->acquired_by != 0 && acquired_by == 0) - { + if (curstate->acquired_by != 0 && acquired_by == 0) ereport(ERROR, (errcode(ERRCODE_OBJECT_IN_USE), errmsg("replication origin with ID %d is already active for PID %d", curstate->roident, curstate->acquired_by))); - } /* ok, found slot */ session_replication_state = curstate; break; } - - if (session_replication_state == NULL && free_slot == -1) - ereport(ERROR, - (errcode(ERRCODE_CONFIGURATION_LIMIT_EXCEEDED), - errmsg("could not find free replication state slot for replication origin with ID %d", - node), - errhint("Increase max_replication_slots and try again."))); - else if (session_replication_state == NULL) + if (session_replication_state == NULL) { + if (free_slot == -1) + ereport(ERROR, + (errcode(ERRCODE_CONFIGURATION_LIMIT_EXCEEDED), + errmsg("could not find free replication state slot for replication origin with ID %d", + node), + errhint("Increase max_replication_slots and try again."))); + /* initialize new slot */ session_replication_state = &replication_states[free_slot]; Assert(session_replication_state->remote_lsn == InvalidXLogRecPtr); @@ -1163,7 +1161,6 @@ replorigin_session_setup(RepOriginId node, int acquired_by) session_replication_state->roident = node; } - Assert(session_replication_state->roident != InvalidRepOriginId); if (acquired_by == 0) -- 1.8.3.1