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

Commit 96f3c3f

Browse files
committed
Merge remote-tracking branch 'origin/broadcast' into broadcast
2 parents a62f1f7 + 8cf24ca commit 96f3c3f

File tree

1 file changed

+24
-1
lines changed

1 file changed

+24
-1
lines changed

pg_shardman--1.0.sql

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -664,15 +664,38 @@ END
664664
$$ LANGUAGE plpgsql;
665665

666666
-- Get redundancy of the particular partition
667+
-- This command can be executed only at shardlord.
667668
CREATE FUNCTION get_redundancy_of_partition(pname text) returns bigint AS $$
668669
SELECT count(*) FROM shardman.replicas where part_name=pname;
669670
$$ LANGUAGE sql;
670671

671-
-- Get minimal redundancy of the specified relation
672+
-- Get minimal redundancy of the specified relation.
673+
-- This command can be executed only at shardlord.
672674
CREATE FUNCTION get_min_redundancy(rel regclass) returns bigint AS $$
673675
SELECT min(redundancy) FROM (SELECT count(*) redundancy FROM shardman.replicas WHERE relation=rel::text GROUP BY part_name) s;
674676
$$ LANGUAGE sql;
675677

678+
-- Execute command at all shardman nodes.
679+
-- It can be used to perform DDL at all nodes.
680+
CREATE FUNCTION forall(sql text, use_2pc bool = false) returns void AS $$
681+
DECLARE
682+
node_id integer;
683+
cmds text = '';
684+
BEGIN
685+
IF shardman.redirect_to_shardlord(format('forall(%L, %L)', sql, use_2pc))
686+
THEN
687+
RETURN;
688+
END IF;
689+
690+
-- Loop through all nodes
691+
FOR node_id IN SELECT * from shardman.nodes
692+
LOOP
693+
cmds := format('%s%s:%s;', cmds, node_id, sql);
694+
END LOOP;
695+
PERFORM shardman.broadcast(cmds, two_phase => use_2pc);
696+
END
697+
$$ LANGUAGE plpgsql;
698+
676699
---------------------------------------------------------------------
677700
-- Utility functions
678701
---------------------------------------------------------------------

0 commit comments

Comments
 (0)