File tree Expand file tree Collapse file tree 1 file changed +24
-1
lines changed Expand file tree Collapse file tree 1 file changed +24
-1
lines changed Original file line number Diff line number Diff line change @@ -664,15 +664,38 @@ END
664
664
$$ LANGUAGE plpgsql;
665
665
666
666
-- Get redundancy of the particular partition
667
+ -- This command can be executed only at shardlord.
667
668
CREATE FUNCTION get_redundancy_of_partition (pname text ) returns bigint AS $$
668
669
SELECT count (* ) FROM shardman .replicas where part_name= pname;
669
670
$$ LANGUAGE sql;
670
671
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.
672
674
CREATE FUNCTION get_min_redundancy (rel regclass) returns bigint AS $$
673
675
SELECT min (redundancy) FROM (SELECT count (* ) redundancy FROM shardman .replicas WHERE relation= rel::text GROUP BY part_name) s;
674
676
$$ LANGUAGE sql;
675
677
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
+
676
699
-- -------------------------------------------------------------------
677
700
-- Utility functions
678
701
-- -------------------------------------------------------------------
You can’t perform that action at this time.
0 commit comments