pull/7247/head
Onur Tirtir 2023-10-05 17:28:20 +03:00
parent 0dca65c84d
commit 23fd6f6d00
6 changed files with 72 additions and 3 deletions

View File

@ -1,3 +1,5 @@
-- citus--12.1-1--12.2-1
-- bump version to 12.2-1
#include "udfs/citus_add_rebalance_strategy/12.2-1.sql"

View File

@ -1,2 +1,3 @@
-- citus--12.2-1--12.1-1
-- this is an empty downgrade path since citus--12.2-1--12.1-1.sql is empty for now
#include "../udfs/citus_add_rebalance_strategy/10.1-1.sql"

View File

@ -0,0 +1,32 @@
DROP FUNCTION pg_catalog.citus_add_rebalance_strategy;
CREATE OR REPLACE FUNCTION pg_catalog.citus_add_rebalance_strategy(
name name,
shard_cost_function regproc,
node_capacity_function regproc,
shard_allowed_on_node_function regproc,
default_threshold float4,
minimum_threshold float4 DEFAULT 0,
improvement_threshold float4 DEFAULT 0
)
RETURNS VOID AS $$
INSERT INTO
pg_catalog.pg_dist_rebalance_strategy(
name,
shard_cost_function,
node_capacity_function,
shard_allowed_on_node_function,
default_threshold,
minimum_threshold,
improvement_threshold
) VALUES (
name,
shard_cost_function,
node_capacity_function,
shard_allowed_on_node_function,
default_threshold,
minimum_threshold,
improvement_threshold
);
$$ LANGUAGE sql;
COMMENT ON FUNCTION pg_catalog.citus_add_rebalance_strategy(name,regproc,regproc,regproc,float4, float4, float4)
IS 'adds a new rebalance strategy which can be used when rebalancing shards or draining nodes';

View File

@ -16,14 +16,16 @@ CREATE OR REPLACE FUNCTION pg_catalog.citus_add_rebalance_strategy(
node_capacity_function,
shard_allowed_on_node_function,
default_threshold,
minimum_threshold
minimum_threshold,
improvement_threshold
) VALUES (
name,
shard_cost_function,
node_capacity_function,
shard_allowed_on_node_function,
default_threshold,
minimum_threshold
minimum_threshold,
improvement_threshold
);
$$ LANGUAGE sql;
COMMENT ON FUNCTION pg_catalog.citus_add_rebalance_strategy(name,regproc,regproc,regproc,float4, float4, float4)

View File

@ -2184,6 +2184,26 @@ SELECT citus_add_rebalance_strategy(
0.1
);
ERROR: default_threshold cannot be smaller than minimum_threshold
SELECT citus_add_rebalance_strategy(
'test_improvement_threshold',
'citus_shard_cost_1',
'capacity_high_worker_2',
'citus_shard_allowed_on_node_true',
0.2,
0.1,
0.3
);
citus_add_rebalance_strategy
---------------------------------------------------------------------
(1 row)
SELECT * FROM pg_dist_rebalance_strategy WHERE name='test_improvement_threshold';
name | default_strategy | shard_cost_function | node_capacity_function | shard_allowed_on_node_function | default_threshold | minimum_threshold | improvement_threshold
---------------------------------------------------------------------
test_improvement_threshold | f | citus_shard_cost_1 | capacity_high_worker_2 | citus_shard_allowed_on_node_true | 0.2 | 0.1 | 0.3
(1 row)
-- Make it a data node again
SELECT * from master_set_node_property('localhost', :worker_2_port, 'shouldhaveshards', true);
master_set_node_property

View File

@ -1229,6 +1229,18 @@ SELECT citus_add_rebalance_strategy(
0.1
);
SELECT citus_add_rebalance_strategy(
'test_improvement_threshold',
'citus_shard_cost_1',
'capacity_high_worker_2',
'citus_shard_allowed_on_node_true',
0.2,
0.1,
0.3
);
SELECT * FROM pg_dist_rebalance_strategy WHERE name='test_improvement_threshold';
-- Make it a data node again
SELECT * from master_set_node_property('localhost', :worker_2_port, 'shouldhaveshards', true);
DROP TABLE tab;