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

Commit dbdf82d

Browse files
committed
Fix command redirection to shardlord
1 parent 4d3ccd3 commit dbdf82d

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
@@ -662,12 +662,10 @@ $$ LANGUAGE sql;
662662

663663
-- Execute command at shardlord
664664
CREATE FUNCTION redirect_to_shardlord(cmd text) RETURNS bool AS $$
665-
DECLARE
666-
am_shardlord bool;
667665
BEGIN
668-
SELECT setting::bool INTO am_shardlord FROM pg_settings WHERE name = 'shardman.shardlord';
669-
IF NOT am_shardlord THEN
670-
PERFORM shardman.broadcast(format('0:SELECT %s;', cmd));
666+
IF NOT shardman.is_shardlord() THEN
667+
RAISE NOTICE 'Redirect command "%" to shardlord',cmd;
668+
PERFORM shardman.broadcast(format('0:SELECT shardman.%s;', cmd));
671669
RETURN true;
672670
ELSE
673671
RETURN false;
@@ -772,10 +770,14 @@ CREATE FUNCTION pq_conninfo_parse(IN conninfo text, OUT keys text[], OUT vals te
772770
CREATE FUNCTION shardlord_connection_string()
773771
RETURNS text AS 'pg_shardman' LANGUAGE C STRICT;
774772

775-
-- Check from configuration parameters is synchronous replication mode was enabled
773+
-- Check from configuration parameters if synchronous replication mode was enabled
776774
CREATE FUNCTION synchronous_replication()
777775
RETURNS bool AS 'pg_shardman' LANGUAGE C STRICT;
778776

777+
-- Check from configuration parameters if node plays role of shardlord
778+
CREATE FUNCTION is_shardlord()
779+
RETURNS bool AS 'pg_shardman' LANGUAGE C STRICT;
780+
779781
-- Wait completion of partition copy using LR
780782
CREATE FUNCTION wait_copy_completion(src_node_id int, part_name text) RETURNS void AS $$
781783
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)