From bbcf658604b4995f7aa2e5f9c2f9d9f78036ec45 Mon Sep 17 00:00:00 2001
From: Hou Zhijie <houzj.fnst@cn.fujitsu.com>
Date: Fri, 20 Jan 2023 14:39:38 +0800
Subject: [PATCH v87 1/2] Rename logical_decoding_mode to
 logical_replication_mode

Rename the developer option 'logical_decoding_mode' to the more
flexible name 'logical_replication_mode' because doing so will make it
easier to extend this option in future to help test other areas of
logical replication.
---
 doc/src/sgml/config.sgml                                |  8 ++++----
 src/backend/replication/logical/reorderbuffer.c         | 14 +++++++-------
 src/backend/utils/misc/guc_tables.c                     | 12 ++++++------
 src/include/replication/reorderbuffer.h                 | 10 +++++-----
 src/test/subscription/t/016_stream_subxact.pl           |  2 +-
 src/test/subscription/t/018_stream_subxact_abort.pl     |  2 +-
 src/test/subscription/t/019_stream_subxact_ddl_abort.pl |  2 +-
 src/test/subscription/t/023_twophase_stream.pl          |  2 +-
 src/tools/pgindent/typedefs.list                        |  2 +-
 9 files changed, 27 insertions(+), 27 deletions(-)

diff --git a/doc/src/sgml/config.sgml b/doc/src/sgml/config.sgml
index 89d53f2..c2c5877 100644
--- a/doc/src/sgml/config.sgml
+++ b/doc/src/sgml/config.sgml
@@ -11655,16 +11655,16 @@ LOG:  CleanUpLock: deleting: lock(0xb7acd844) id(24688,24696,0,0,0,1)
       </listitem>
      </varlistentry>
 
-     <varlistentry id="guc-logical-decoding-mode" xreflabel="logical_decoding_mode">
-      <term><varname>logical_decoding_mode</varname> (<type>enum</type>)
+     <varlistentry id="guc-logical-replication-mode" xreflabel="logical_replication_mode">
+      <term><varname>logical_replication_mode</varname> (<type>enum</type>)
       <indexterm>
-       <primary><varname>logical_decoding_mode</varname> configuration parameter</primary>
+       <primary><varname>logical_replication_mode</varname> configuration parameter</primary>
       </indexterm>
       </term>
       <listitem>
        <para>
         Allows streaming or serializing changes immediately in logical decoding.
-        The allowed values of <varname>logical_decoding_mode</varname> are
+        The allowed values of <varname>logical_replication_mode</varname> are
         <literal>buffered</literal> and <literal>immediate</literal>. When set
         to <literal>immediate</literal>, stream each change if
         <literal>streaming</literal> option (see optional parameters set by
diff --git a/src/backend/replication/logical/reorderbuffer.c b/src/backend/replication/logical/reorderbuffer.c
index 54ee824..efe057b 100644
--- a/src/backend/replication/logical/reorderbuffer.c
+++ b/src/backend/replication/logical/reorderbuffer.c
@@ -210,7 +210,7 @@ int			logical_decoding_work_mem;
 static const Size max_changes_in_memory = 4096; /* XXX for restore only */
 
 /* GUC variable */
-int			logical_decoding_mode = LOGICAL_DECODING_MODE_BUFFERED;
+int			logical_replication_mode = LOGICAL_REP_MODE_BUFFERED;
 
 /* ---------------------------------------
  * primary reorderbuffer support routines
@@ -3552,8 +3552,8 @@ ReorderBufferLargestStreamableTopTXN(ReorderBuffer *rb)
  * pick the largest (sub)transaction at-a-time to evict and spill its changes to
  * disk or send to the output plugin until we reach under the memory limit.
  *
- * If logical_decoding_mode is set to "immediate", stream or serialize the changes
- * immediately.
+ * If logical_replication_mode is set to "immediate", stream or serialize the
+ * changes immediately.
  *
  * XXX At this point we select the transactions until we reach under the memory
  * limit, but we might also adapt a more elaborate eviction strategy - for example
@@ -3566,15 +3566,15 @@ ReorderBufferCheckMemoryLimit(ReorderBuffer *rb)
 	ReorderBufferTXN *txn;
 
 	/*
-	 * Bail out if logical_decoding_mode is buffered and we haven't exceeded
+	 * Bail out if logical_replication_mode is buffered and we haven't exceeded
 	 * the memory limit.
 	 */
-	if (logical_decoding_mode == LOGICAL_DECODING_MODE_BUFFERED &&
+	if (logical_replication_mode == LOGICAL_REP_MODE_BUFFERED &&
 		rb->size < logical_decoding_work_mem * 1024L)
 		return;
 
 	/*
-	 * If logical_decoding_mode is immediate, loop until there's no change.
+	 * If logical_replication_mode is immediate, loop until there's no change.
 	 * Otherwise, loop until we reach under the memory limit. One might think
 	 * that just by evicting the largest (sub)transaction we will come under
 	 * the memory limit based on assumption that the selected transaction is
@@ -3584,7 +3584,7 @@ ReorderBufferCheckMemoryLimit(ReorderBuffer *rb)
 	 * change.
 	 */
 	while (rb->size >= logical_decoding_work_mem * 1024L ||
-		   (logical_decoding_mode == LOGICAL_DECODING_MODE_IMMEDIATE &&
+		   (logical_replication_mode == LOGICAL_REP_MODE_IMMEDIATE &&
 			rb->size > 0))
 	{
 		/*
diff --git a/src/backend/utils/misc/guc_tables.c b/src/backend/utils/misc/guc_tables.c
index cd0fc2c..d1dc2d4 100644
--- a/src/backend/utils/misc/guc_tables.c
+++ b/src/backend/utils/misc/guc_tables.c
@@ -395,9 +395,9 @@ static const struct config_enum_entry ssl_protocol_versions_info[] = {
 	{NULL, 0, false}
 };
 
-static const struct config_enum_entry logical_decoding_mode_options[] = {
-	{"buffered", LOGICAL_DECODING_MODE_BUFFERED, false},
-	{"immediate", LOGICAL_DECODING_MODE_IMMEDIATE, false},
+static const struct config_enum_entry logical_replication_mode_options[] = {
+	{"buffered", LOGICAL_REP_MODE_BUFFERED, false},
+	{"immediate", LOGICAL_REP_MODE_IMMEDIATE, false},
 	{NULL, 0, false}
 };
 
@@ -4908,13 +4908,13 @@ struct config_enum ConfigureNamesEnum[] =
 	},
 
 	{
-		{"logical_decoding_mode", PGC_USERSET, DEVELOPER_OPTIONS,
+		{"logical_replication_mode", PGC_USERSET, DEVELOPER_OPTIONS,
 			gettext_noop("Allows streaming or serializing each change in logical decoding."),
 			NULL,
 			GUC_NOT_IN_SAMPLE
 		},
-		&logical_decoding_mode,
-		LOGICAL_DECODING_MODE_BUFFERED, logical_decoding_mode_options,
+		&logical_replication_mode,
+		LOGICAL_REP_MODE_BUFFERED, logical_replication_mode_options,
 		NULL, NULL, NULL
 	},
 
diff --git a/src/include/replication/reorderbuffer.h b/src/include/replication/reorderbuffer.h
index f6c4dd7..5a26ec9 100644
--- a/src/include/replication/reorderbuffer.h
+++ b/src/include/replication/reorderbuffer.h
@@ -18,14 +18,14 @@
 #include "utils/timestamp.h"
 
 extern PGDLLIMPORT int logical_decoding_work_mem;
-extern PGDLLIMPORT int logical_decoding_mode;
+extern PGDLLIMPORT int logical_replication_mode;
 
-/* possible values for logical_decoding_mode */
+/* possible values for logical_replication_mode */
 typedef enum
 {
-	LOGICAL_DECODING_MODE_BUFFERED,
-	LOGICAL_DECODING_MODE_IMMEDIATE
-} LogicalDecodingMode;
+	LOGICAL_REP_MODE_BUFFERED,
+	LOGICAL_REP_MODE_IMMEDIATE
+} LogicalRepMode;
 
 /* an individual tuple, stored in one chunk of memory */
 typedef struct ReorderBufferTupleBuf
diff --git a/src/test/subscription/t/016_stream_subxact.pl b/src/test/subscription/t/016_stream_subxact.pl
index 2f0148c..d830f26 100644
--- a/src/test/subscription/t/016_stream_subxact.pl
+++ b/src/test/subscription/t/016_stream_subxact.pl
@@ -79,7 +79,7 @@ sub test_streaming
 my $node_publisher = PostgreSQL::Test::Cluster->new('publisher');
 $node_publisher->init(allows_streaming => 'logical');
 $node_publisher->append_conf('postgresql.conf',
-	'logical_decoding_mode = immediate');
+	'logical_replication_mode = immediate');
 $node_publisher->start;
 
 # Create subscriber node
diff --git a/src/test/subscription/t/018_stream_subxact_abort.pl b/src/test/subscription/t/018_stream_subxact_abort.pl
index dce14b1..814daf4 100644
--- a/src/test/subscription/t/018_stream_subxact_abort.pl
+++ b/src/test/subscription/t/018_stream_subxact_abort.pl
@@ -130,7 +130,7 @@ sub test_streaming
 my $node_publisher = PostgreSQL::Test::Cluster->new('publisher');
 $node_publisher->init(allows_streaming => 'logical');
 $node_publisher->append_conf('postgresql.conf',
-	'logical_decoding_mode = immediate');
+	'logical_replication_mode = immediate');
 $node_publisher->start;
 
 # Create subscriber node
diff --git a/src/test/subscription/t/019_stream_subxact_ddl_abort.pl b/src/test/subscription/t/019_stream_subxact_ddl_abort.pl
index b30223d..d0e556c 100644
--- a/src/test/subscription/t/019_stream_subxact_ddl_abort.pl
+++ b/src/test/subscription/t/019_stream_subxact_ddl_abort.pl
@@ -16,7 +16,7 @@ use Test::More;
 my $node_publisher = PostgreSQL::Test::Cluster->new('publisher');
 $node_publisher->init(allows_streaming => 'logical');
 $node_publisher->append_conf('postgresql.conf',
-	'logical_decoding_mode = immediate');
+	'logical_replication_mode = immediate');
 $node_publisher->start;
 
 # Create subscriber node
diff --git a/src/test/subscription/t/023_twophase_stream.pl b/src/test/subscription/t/023_twophase_stream.pl
index 75ca837..497245a 100644
--- a/src/test/subscription/t/023_twophase_stream.pl
+++ b/src/test/subscription/t/023_twophase_stream.pl
@@ -301,7 +301,7 @@ $node_publisher->init(allows_streaming => 'logical');
 $node_publisher->append_conf(
 	'postgresql.conf', qq(
 max_prepared_transactions = 10
-logical_decoding_mode = immediate
+logical_replication_mode = immediate
 ));
 $node_publisher->start;
 
diff --git a/src/tools/pgindent/typedefs.list b/src/tools/pgindent/typedefs.list
index 0931603..7d15368 100644
--- a/src/tools/pgindent/typedefs.list
+++ b/src/tools/pgindent/typedefs.list
@@ -1456,7 +1456,6 @@ LogicalDecodeStreamStopCB
 LogicalDecodeStreamTruncateCB
 LogicalDecodeTruncateCB
 LogicalDecodingContext
-LogicalDecodingMode
 LogicalErrorCallbackState
 LogicalOutputPluginInit
 LogicalOutputPluginWriterPrepareWrite
@@ -1466,6 +1465,7 @@ LogicalRepBeginData
 LogicalRepCommitData
 LogicalRepCommitPreparedTxnData
 LogicalRepCtxStruct
+LogicalRepMode
 LogicalRepMsgType
 LogicalRepPartMapEntry
 LogicalRepPreparedTxnData
-- 
2.7.2.windows.1

