Skip to content

Cluster reroute api should have a way to assign all unassigned shards #4206

Closed
@nik9000

Description

@nik9000

Sometimes, during a disaster, you end up with shards stuck unassigned and you just want them reassigned regardless of data loss. It'd be great if the cluster reroute api supported an assign_all action that just assigns all the shards to free nodes. It'd need to also support allow_primary. Without this you need some nasty shell script like this:

function reroute() {
    curl -XPOST 'localhost:9200/_cluster/reroute?pretty' -d '{
        "commands" : [ {
                "allocate" : {
                    "index" : "'$1'",
                    "shard" : '$2'
                    "allow_primary" : true,
                    "node" : "<node>"
                }
            }
        ]
    }' > /dev/null
    sleep 1
}
curl -s localhost:9200/_cluster/state?pretty | awk '
    BEGIN {more=1}
    {if (/"UNASSIGNED"/) unassigned=1}
    {if (/"routing_nodes"/) more=0}
    {if (unassigned && /"shard"/) shard=$3}
    {if (more && unassigned && /"index"/) {print "reroute",$3, shard; unassigned=false}}
' > runit
source runit

I'm sure there are better ways to write that script, but great code doesn't typically come in the middle of disasters.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions