C-Azzopardi
C-Azzopardi

Reputation: 1

CITUS - WARNING: Not allowed to move shard <id> anywhere from <nodename>:<nodeport>

I am trying out the Citus PSQL extension for sharding, and am trying the custom rebalancing strategies. I created the following function that is meant to check the current shardid's groupid against a table called geo_node with all countries and which groupid they should be in - if it matches it will return true, and false if not (i.e. it should be moved):

CREATE FUNCTION distribute_geographical(shardidarg bigint, nodeidarg int)
    RETURNS boolean AS $$
    DECLARE query text;
            link text; 
            port int; 
            grp int;
    BEGIN
    
    DROP TABLE IF EXISTS locs;
    
    port:=(select nodeport from pg_dist_node a inner join pg_dist_placement b on a.groupid = b.groupid where shardid=shardidarg and noderole = 'primary');
    query:='select * from radius_data_'||shardidarg||';';
    link:='host=127.0.0.1 port='||port||' dbname=radius';
    grp:=(select groupid from pg_dist_placement where shardid=shardidarg);
    
    
    CREATE TABLE locs AS
    SELECT distinct location, gn.groupid
    FROM   dblink(link,query)
    AS     noderes(id int, location text, stuff text)
    INNER JOIN geo_node gn on country=noderes.location; 
    
    IF EXISTS (SELECT * FROM locs a WHERE grp != a.groupid) THEN
        RETURN 0;
    ELSE 
        RETURN 1;
    END IF;
    
    END;
    $$ LANGUAGE plpgsql;

Which I then referenced in pg_dist_rebalance_strategy as so (and set that strategy as default):

SELECT * FROM pg_dist_rebalance_strategy;

"by_shard_count"    false   "citus_shard_cost_1"    "citus_node_capacity_1" "citus_shard_allowed_on_node_true"  0   0   0
"by_disk_size"  false   "citus_shard_cost_by_disk_size" "citus_node_capacity_1" "citus_shard_allowed_on_node_true"  0.1 0.01    0.5
"by_geo"    true    "citus_shard_cost_1"    "citus_node_capacity_1" "distribute_geographical"   0   0   0

If I run SELECT rebalance_table_shards('radius_data'); to rebalance the shards, it will output the following error in Messages:

WARNING:  Not allowed to move shard 102161 anywhere from worker2:5434
Successfully run. Total query runtime: 9 secs 694 msec.
1 rows affected.

That shard is correctly caught - i.e. it is on worker2 which is on groupid2, but it should be on a node on groupid1 (worker1).

Why is it saying that it is 'Not allowed' to move the shard? And how can I allow this please?

Upvotes: 0

Views: 175

Answers (1)

Emel Hasdal
Emel Hasdal

Reputation: 1

Try running

SELECT * FROM get_rebalance_table_shards_plan('radius_data');

to see the planned moves according to your strategy.

Also make sure that for every node

pg_dist_node.shouldhaveshards is set to true.

You can change it by:

SELECT citus_set_node_property(:nodehost, :nodeport, 'shouldhaveshards', true);

Upvotes: 0

Related Questions