Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1kIaQF-0007jJ-IR for pgsql-hackers@arkaria.postgresql.org; Wed, 16 Sep 2020 16:36:43 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1kIaQE-0001fv-Bo for pgsql-hackers@arkaria.postgresql.org; Wed, 16 Sep 2020 16:36:42 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1kIaQD-0001eu-Vg for pgsql-hackers@lists.postgresql.org; Wed, 16 Sep 2020 16:36:42 +0000 Received: from mail-qk1-x729.google.com ([2607:f8b0:4864:20::729]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1kIaQ9-0007vf-O7 for pgsql-hackers@lists.postgresql.org; Wed, 16 Sep 2020 16:36:40 +0000 Received: by mail-qk1-x729.google.com with SMTP id 16so8826661qkf.4 for ; Wed, 16 Sep 2020 09:36:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=2ndquadrant-com.20150623.gappssmtp.com; s=20150623; h=date:from:to:cc:subject:message-id:mime-version:content-disposition :content-transfer-encoding:in-reply-to:user-agent; bh=xvbh+QkuG679dwTsDbgmxhppD31yp66Se/EDiF/wFCY=; b=subG79OOThkAVHBPlmdXaaNr0K5lMnOwQkMrZyW622W6kgcQpYZEBM/lpF+d3xlaDR FpNFSJDk7kqbbeEmtmjIvJwxpYOiA7Qgiubv5kERsx6qmzu+sWjCTRIvA9Bakj51y085 hoXqBWjyxLs2WW5pvWo0m+UoowOw2QGmip459tJfapBKFbYcFbv4JCESZGU6zhyxFfU8 5aYTKj32bGMzKwKK/RaPlZ+T/5vU3FzbfLIH3G8I7z+YdsRRzLLYmqbLpmrtxrprMliG oUb8ONNoKv+7aHftXX7iJ7FydeAFT86ZjbgNvrbAbYwD2bx70cNusXpPuW1VNW7+pBLX UgPw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:mime-version :content-disposition:content-transfer-encoding:in-reply-to :user-agent; bh=xvbh+QkuG679dwTsDbgmxhppD31yp66Se/EDiF/wFCY=; b=Cr0yrSwwqDMt/cJ2GBA4QBLND7hMi/9r6r1l5GoX4kxG5wdIjs+JVp4MzUhimJdy+p gRCGrguFxRL4aI9gyzUPO1hzSpBfh0AhG9Q3666BP06+j8u3Liebxa51tj8OKU8K1jOA UCPVYzrBmJ0MYFTqT8g8OfEuWt765FAegC7KgndaUha7ekjOHnTl9pQ6UsxxHOR+QVhM ydJbErFlktglqM5XvI98SCMU5MgzAT/U6w7D6qlgrNFxiljDQlcJ6GyxWOCZSdUwEsvs C3vtj8Ruy1nQzNs7hQI+9A0pk+jXewtinS+kQ4EANoUHKIUXK1sT+Iqt2n5ui1Z29546 Yrnw== X-Gm-Message-State: AOAM531lU741yXO5YhlSwSVG9dDq0Nl125vbxBEfjgtV0vSXhvKuK0wl LvG8IWNekwXMYbQFEXA71eSidQklfI+bykWKshddi+W9JRMSF0gEFFs2vk2GJW0M03t6qOGQ4Ya 7Khzxgr3oBHfIrAXNEmpMPBHVbNnz5wFNM3FDlLkleUqIfz6VqwLodjatI0//Flcja4+SUZY2LU Mn/9RaS2LTQs1BDDld X-Google-Smtp-Source: ABdhPJxqEdDxMvAg7LpSjRGrIh2hC4bDxKFWHtfzIc656SBefYBhuJQUpqwLLXZmMmtyIlXccnWNlQ== X-Received: by 2002:a37:7d87:: with SMTP id y129mr24478970qkc.108.1600274195756; Wed, 16 Sep 2020 09:36:35 -0700 (PDT) Received: from perhan.alvh.no-ip.org ([190.95.19.47]) by smtp.gmail.com with ESMTPSA id w128sm19618627qkb.6.2020.09.16.09.36.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 16 Sep 2020 09:36:34 -0700 (PDT) Received: by perhan.alvh.no-ip.org (Postfix, from userid 1000) id 31DDA2A1565; Wed, 16 Sep 2020 13:36:33 -0300 (-03) Date: Wed, 16 Sep 2020 13:36:33 -0300 From: Alvaro Herrera To: Tom Lane Cc: Michael Paquier , pgsql-hackers@lists.postgresql.org Subject: Re: Gripes about walsender command processing Message-ID: <20200916163633.GA9907@alvherre.pgsql> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="7AUc2qLy4jB3hD7Z" Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <20200915213316.GA12416@alvherre.pgsql> User-Agent: Mutt/1.10.1 (2018-07-13) List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk --7AUc2qLy4jB3hD7Z Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit On 2020-Sep-15, Alvaro Herrera wrote: > I overlooked this in 2f9661311b83. From this perspective, I agree it > looks wrong. We still have to send *some* completion tag (the 'C' > message), but maybe we can invent a separate entry point in dest.c for > that -- EndReplicationCommand() or some such -- that takes values from a > separate enum? It seems simpler than that actually; we don't need to build a lot of infrastructure. -- Álvaro Herrera https://www.2ndQuadrant.com/ PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services --7AUc2qLy4jB3hD7Z Content-Type: text/x-diff; charset=us-ascii Content-Disposition: attachment; filename="replic-cmdtag.patch" commit 2c1eab8dd3eade63598a34f81d8b829d819f6ab5 Author: Alvaro Herrera AuthorDate: Wed Sep 16 13:04:38 2020 -0300 CommitDate: Wed Sep 16 13:04:38 2020 -0300 replication command end diff --git a/src/backend/replication/walsender.c b/src/backend/replication/walsender.c index 67093383e6..a48f2c3c64 100644 --- a/src/backend/replication/walsender.c +++ b/src/backend/replication/walsender.c @@ -1122,11 +1122,7 @@ CreateReplicationSlot(CreateReplicationSlotCmd *cmd) static void DropReplicationSlot(DropReplicationSlotCmd *cmd) { - QueryCompletion qc; - ReplicationSlotDrop(cmd->slotname, !cmd->wait); - SetQueryCompletion(&qc, CMDTAG_DROP_REPLICATION_SLOT, 0); - EndCommand(&qc, DestRemote, false); } /* @@ -1519,7 +1515,6 @@ exec_replication_command(const char *cmd_string) Node *cmd_node; MemoryContext cmd_context; MemoryContext old_context; - QueryCompletion qc; /* * If WAL sender has been told that shutdown is getting close, switch its @@ -1620,19 +1615,23 @@ exec_replication_command(const char *cmd_string) { case T_IdentifySystemCmd: IdentifySystem(); + EndReplicationCommand("IDENTIFY_SYSTEM"); break; case T_BaseBackupCmd: PreventInTransactionBlock(true, "BASE_BACKUP"); SendBaseBackup((BaseBackupCmd *) cmd_node); + EndReplicationCommand("BASE_BACKUP"); break; case T_CreateReplicationSlotCmd: CreateReplicationSlot((CreateReplicationSlotCmd *) cmd_node); + EndReplicationCommand("CREATE_REPLICATION_SLOT"); break; case T_DropReplicationSlotCmd: DropReplicationSlot((DropReplicationSlotCmd *) cmd_node); + EndReplicationCommand("DROP_REPLICATION_SLOT"); break; case T_StartReplicationCmd: @@ -1646,6 +1645,8 @@ exec_replication_command(const char *cmd_string) else StartLogicalReplication(cmd); + /* callees already sent their own completion message */ + Assert(xlogreader != NULL); break; } @@ -1653,6 +1654,7 @@ exec_replication_command(const char *cmd_string) case T_TimeLineHistoryCmd: PreventInTransactionBlock(true, "TIMELINE_HISTORY"); SendTimeLineHistory((TimeLineHistoryCmd *) cmd_node); + EndReplicationCommand("TIMELINE_HISTORY"); break; case T_VariableShowStmt: @@ -1664,6 +1666,7 @@ exec_replication_command(const char *cmd_string) StartTransactionCommand(); GetPGVariable(n->name, dest); CommitTransactionCommand(); + EndReplicationCommand("SHOW"); } break; @@ -1676,10 +1679,6 @@ exec_replication_command(const char *cmd_string) MemoryContextSwitchTo(old_context); MemoryContextDelete(cmd_context); - /* Send CommandComplete message */ - SetQueryCompletion(&qc, CMDTAG_SELECT, 0); - EndCommand(&qc, DestRemote, true); - /* Report to pgstat that this process is now idle */ pgstat_report_activity(STATE_IDLE, NULL); debug_query_string = NULL; diff --git a/src/backend/tcop/dest.c b/src/backend/tcop/dest.c index 7208751ec7..3a1be6b999 100644 --- a/src/backend/tcop/dest.c +++ b/src/backend/tcop/dest.c @@ -211,6 +211,15 @@ EndCommand(const QueryCompletion *qc, CommandDest dest, bool force_undecorated_o } } +/* + * Simplified version EndCommand, for use of replication commands + */ +void +EndReplicationCommand(const char *commandTag) +{ + pq_putmessage('C', commandTag, strlen(commandTag) + 1); +} + /* ---------------- * NullCommand - tell dest that an empty query string was recognized * diff --git a/src/include/tcop/cmdtaglist.h b/src/include/tcop/cmdtaglist.h index 8ef0f55e74..be94852bbd 100644 --- a/src/include/tcop/cmdtaglist.h +++ b/src/include/tcop/cmdtaglist.h @@ -157,7 +157,6 @@ PG_CMDTAG(CMDTAG_DROP_OWNED, "DROP OWNED", true, false, false) PG_CMDTAG(CMDTAG_DROP_POLICY, "DROP POLICY", true, false, false) PG_CMDTAG(CMDTAG_DROP_PROCEDURE, "DROP PROCEDURE", true, false, false) PG_CMDTAG(CMDTAG_DROP_PUBLICATION, "DROP PUBLICATION", true, false, false) -PG_CMDTAG(CMDTAG_DROP_REPLICATION_SLOT, "DROP REPLICATION SLOT", false, false, false) PG_CMDTAG(CMDTAG_DROP_ROLE, "DROP ROLE", false, false, false) PG_CMDTAG(CMDTAG_DROP_ROUTINE, "DROP ROUTINE", true, false, false) PG_CMDTAG(CMDTAG_DROP_RULE, "DROP RULE", true, false, false) diff --git a/src/include/tcop/dest.h b/src/include/tcop/dest.h index 662ce8a56f..2e07f1516d 100644 --- a/src/include/tcop/dest.h +++ b/src/include/tcop/dest.h @@ -139,6 +139,7 @@ extern void BeginCommand(CommandTag commandTag, CommandDest dest); extern DestReceiver *CreateDestReceiver(CommandDest dest); extern void EndCommand(const QueryCompletion *qc, CommandDest dest, bool force_undecorated_output); +extern void EndReplicationCommand(const char *commandTag); /* Additional functions that go with destination management, more or less. */ --7AUc2qLy4jB3hD7Z--