Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit60bf0b3

Browse files
committed
Fix problem with process utulity statement context filter
1 parent8ad6794 commit60bf0b3

File tree

2 files changed

+27
-14
lines changed

2 files changed

+27
-14
lines changed

‎contrib/mmts/multimaster--1.0.sql

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -99,18 +99,23 @@ BEGIN
9999
FOR seq_classIN
100100
SELECT*FROM pg_classWHEREpg_class.relkind='S'
101101
LOOP
102-
EXECUTE'select * from'||seq_class.relname||';' INTO seq_tuple;
103-
IFseq_tuple.increment_by!= max_nodes THEN
104-
altered := true;
105-
RAISE NOTICE'Altering step for sequence % to %.',seq_tuple.sequence_name, max_nodes;
106-
EXECUTE'ALTER SEQUENCE'||seq_class.relname||' INCREMENT BY'|| max_nodes||';';
107-
END IF;
108-
IF (seq_tuple.last_value % max_nodes)!= node_id THEN
109-
altered := true;
110-
new_start := (seq_tuple.last_value/ max_nodes+1)*max_nodes+ node_id;
111-
RAISE NOTICE'Altering start for sequence % to %.',seq_tuple.sequence_name, new_start;
112-
EXECUTE'ALTER SEQUENCE'||seq_class.relname||' RESTART WITH'|| new_start||';';
113-
END IF;
102+
BEGIN
103+
EXECUTE'select * from'||seq_class.relname||';' INTO seq_tuple;
104+
IFseq_tuple.increment_by!= max_nodes THEN
105+
altered := true;
106+
RAISE NOTICE'Altering step for sequence % to %.',seq_tuple.sequence_name, max_nodes;
107+
EXECUTE'ALTER SEQUENCE'||seq_class.relname||' INCREMENT BY'|| max_nodes||';';
108+
END IF;
109+
IF (seq_tuple.last_value % max_nodes)!= node_id THEN
110+
altered := true;
111+
new_start := (seq_tuple.last_value/ max_nodes+1)*max_nodes+ node_id;
112+
RAISE NOTICE'Altering start for sequence % to %.',seq_tuple.sequence_name, new_start;
113+
EXECUTE'ALTER SEQUENCE'||seq_class.relname||' RESTART WITH'|| new_start||';';
114+
END IF;
115+
EXCEPTION
116+
WHEN OTHERS THEN
117+
RAISE NOTICE'Failed to alter sequence %s',seq_class.relname;
118+
END;
114119
END LOOP;
115120
IF altered= false THEN
116121
RAISE NOTICE'All found sequnces have proper params.';

‎contrib/mmts/multimaster.c

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@
4646
#include"utils/builtins.h"
4747
#include"utils/memutils.h"
4848
#include"commands/dbcommands.h"
49+
#include"commands/extension.h"
4950
#include"postmaster/autovacuum.h"
5051
#include"storage/pmsignal.h"
5152
#include"storage/proc.h"
@@ -4865,7 +4866,8 @@ static void MtmProcessUtility(Node *parsetree, const char *queryString,
48654866
boolskipCommand= false;
48664867
boolexecuted= false;
48674868

4868-
MTM_LOG3("%d: Process utility statement %s",MyProcPid,queryString);
4869+
MTM_LOG3("%d: Process utility statement tag=%d, context=%d, issubtrans=%d, query=%s",
4870+
MyProcPid,nodeTag(parsetree),context,IsSubTransaction(),queryString);
48694871
switch (nodeTag(parsetree))
48704872
{
48714873
caseT_TransactionStmt:
@@ -5119,7 +5121,13 @@ static void MtmProcessUtility(Node *parsetree, const char *queryString,
51195121
}
51205122

51215123
/* XXX: dirty. Clear on new tx */
5122-
if (!skipCommand&& (context!=PROCESS_UTILITY_SUBCOMMAND||MtmUtilityProcessedInXid!=GetCurrentTransactionId()))
5124+
/* Some "black magic here":( We want to avoid redundant execution of utility statement by ProcessUtilitySlow (which is done with PROCESS_UTILITY_SUBCOMMAND).
5125+
* But if we allow only PROCESS_UTILITY_TOPLEVEL context, then we will not replicated DDL inside dynamic queries in plpgsql functions (see https://jira.postgrespro.ru/browse/CORE-526).
5126+
* If we disable only PROCESS_UTILITY_SUBCOMMAND, then we will get problems with "create extension" which is executed also in PROCESS_UTILITY_QUERY context.
5127+
* So workaround at this moment is to treat extension as special case.
5128+
* TODO: try to find right solution and rewrite this dummy check.
5129+
*/
5130+
if (!skipCommand&& (context==PROCESS_UTILITY_TOPLEVEL|| (context==PROCESS_UTILITY_QUERY&& !creating_extension)||MtmUtilityProcessedInXid!=GetCurrentTransactionId()))
51235131
MtmUtilityProcessedInXid=InvalidTransactionId;
51245132

51255133
if (!skipCommand&& !MtmTx.isReplicated&& (MtmUtilityProcessedInXid==InvalidTransactionId)) {

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp