@@ -702,9 +702,12 @@ CREATE FUNCTION get_node_partitions_count(node int) returns bigint AS $$
702
702
SELECT count (* ) from shardman .partitions WHERE node_id= node;
703
703
$$ LANGUAGE sql;
704
704
705
- -- Rebalance partitions between nodes. This function tries to evenly redistribute partition between all nodes of replication groups.
705
+ -- Rebalance partitions between nodes. This function tries to evenly
706
+ -- redistribute partitions of tables which names match LIKE 'pattern'
707
+ -- between all nodes of replication groups.
706
708
-- It is not able to move partition between replication groups.
707
- -- This function intentionally move one partition per time to minimize influence on system performance.
709
+ -- This function intentionally moves one partition per time to minimize
710
+ -- influence on system performance.
708
711
CREATE FUNCTION rebalance (table_pattern text = ' %' ) RETURNS void AS $$
709
712
DECLARE
710
713
dst_node int ;
@@ -726,7 +729,7 @@ BEGIN
726
729
FOR repl_group IN SELECT DISTINCT replication_group FROM shardman .nodes
727
730
LOOP
728
731
-- Select node in this group with minimal number of partitions
729
- SELECT node_id, count (* ) n_parts INTO dst_node,min_count
732
+ SELECT node_id, count (* ) n_parts INTO dst_node, min_count
730
733
FROM shardman .partitions p JOIN shardman .nodes n ON p .node_id = n .id
731
734
WHERE n .replication_group = repl_group AND p .relation LIKE table_pattern
732
735
GROUP BY node_id
@@ -737,7 +740,8 @@ BEGIN
737
740
WHERE n .replication_group = repl_group AND p .relation LIKE table_pattern
738
741
GROUP BY node_id
739
742
ORDER BY n_parts DESC LIMIT 1 ;
740
- -- If difference of number of partitions on this nodes is greater than 1, then move random partition
743
+ -- If difference of number of partitions on this nodes is greater
744
+ -- than 1, then move random partition
741
745
IF max_count - min_count > 1 THEN
742
746
SELECT p .part_name INTO mv_part_name
743
747
FROM shardman .partitions p
@@ -897,7 +901,7 @@ BEGIN
897
901
898
902
RAISE DEBUG ' Replication lag %' , lag;
899
903
IF locked THEN
900
- IF lag<= 0 THEN
904
+ IF lag <= 0 THEN
901
905
RETURN;
902
906
END IF;
903
907
ELSIF lag < caughtup_threshold THEN
0 commit comments