Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit d83c9e3

Browse files
committed
Merge branch 'broadcast' of git.postgrespro.ru:a.sher/pg_shardman into broadcast
2 parents bdc9d87 + d48d20b commit d83c9e3

File tree

2 files changed

+17
-8
lines changed

2 files changed

+17
-8
lines changed

pg_shardman--1.0.sql

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -679,12 +679,10 @@ $$ LANGUAGE sql;
679679

680680
-- Execute command at shardlord
681681
CREATE FUNCTION redirect_to_shardlord(cmd text) RETURNS bool AS $$
682-
DECLARE
683-
am_shardlord bool;
684682
BEGIN
685-
SELECT setting::bool INTO am_shardlord FROM pg_settings WHERE name = 'shardman.shardlord';
686-
IF NOT am_shardlord THEN
687-
PERFORM shardman.broadcast(format('0:SELECT %s;', cmd));
683+
IF NOT shardman.is_shardlord() THEN
684+
RAISE NOTICE 'Redirect command "%" to shardlord',cmd;
685+
PERFORM shardman.broadcast(format('0:SELECT shardman.%s;', cmd));
688686
RETURN true;
689687
ELSE
690688
RETURN false;
@@ -793,10 +791,14 @@ CREATE FUNCTION pq_conninfo_parse(IN conninfo text, OUT keys text[], OUT vals te
793791
CREATE FUNCTION shardlord_connection_string()
794792
RETURNS text AS 'pg_shardman' LANGUAGE C STRICT;
795793

796-
-- Check from configuration parameters is synchronous replication mode was enabled
794+
-- Check from configuration parameters if synchronous replication mode was enabled
797795
CREATE FUNCTION synchronous_replication()
798796
RETURNS bool AS 'pg_shardman' LANGUAGE C STRICT;
799797

798+
-- Check from configuration parameters if node plays role of shardlord
799+
CREATE FUNCTION is_shardlord()
800+
RETURNS bool AS 'pg_shardman' LANGUAGE C STRICT;
801+
800802
-- Wait completion of partition copy using LR
801803
CREATE FUNCTION wait_copy_completion(src_node_id int, part_name text) RETURNS void AS $$
802804
DECLARE

pg_shardman.c

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,13 @@ PG_MODULE_MAGIC;
2525

2626
PG_FUNCTION_INFO_V1(shardlord_connection_string);
2727
PG_FUNCTION_INFO_V1(synchronous_replication);
28+
PG_FUNCTION_INFO_V1(is_shardlord);
2829
PG_FUNCTION_INFO_V1(broadcast);
2930
PG_FUNCTION_INFO_V1(reconstruct_table_attrs);
3031
PG_FUNCTION_INFO_V1(pq_conninfo_parse);
3132

3233
/* GUC variables */
33-
static bool is_shardlord;
34+
static bool is_lord;
3435
static bool sync_replication;
3536
static char *shardlord_connstring;
3637

@@ -56,7 +57,7 @@ _PG_init()
5657
"shardman.shardlord",
5758
"This node is the shardlord?",
5859
NULL,
59-
&is_shardlord,
60+
&is_lord,
6061
false,
6162
PGC_SUSET,
6263
0,
@@ -86,6 +87,12 @@ synchronous_replication(PG_FUNCTION_ARGS)
8687
PG_RETURN_BOOL(sync_replication);
8788
}
8889

90+
Datum
91+
is_shardlord(PG_FUNCTION_ARGS)
92+
{
93+
PG_RETURN_BOOL(is_lord);
94+
}
95+
8996
static bool
9097
wait_command_completion(PGconn* conn)
9198
{

0 commit comments

Comments
 (0)