# How are shards chosen when disk usage exceeds high water mark?

**URL:** <https://discuss.elastic.co/t/how-are-shards-chosen-when-disk-usage-exceeds-high-water-mark/162467>\
**Category:** Elasticsearch\
**Created:** [December 31, 2018, 3:07am UTC](https://discuss.elastic.co/t/how-are-shards-chosen-when-disk-usage-exceeds-high-water-mark/162467 "2018-12-31T03:07:06Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![YuWatanabe](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/yuwatanabe/32/13259_2.png) [@YuWatanabe](https://discuss.elastic.co/u/YuWatanabe)\
**Post date:** [December 31, 2018, 3:07am UTC](https://discuss.elastic.co/t/how-are-shards-chosen-when-disk-usage-exceeds-high-water-mark/162467/1 "2018-12-31T03:07:06Z")

</div>

I appreciate if I could get help to understand behavior of _disk high watermark_ in elasticsearch.

From the [document](https://www.elastic.co/guide/en/elasticsearch/reference/6.4/disk-allocator.html#disk-allocator), I have understood that when disk usage of the partion where _path.data_ exists exceeds _high watemark_ then shards will begin to be relocated to other nodes.

> Controls the high watermark. It defaults to 90% , meaning that Elasticsearch will attempt to relocate shards away from a node whose disk usage is above 90%

But how will the shards chosen that needs to be relocated ? Will be chosen from the largest ones ?

I came across with this [code](https://github.com/elastic/elasticsearch/blob/master/server/src/main/java/org/elasticsearch/cluster/routing/allocation/DiskThresholdMonitor.java) , but couldn't find the part where it decides the shard.

---

<div class="post-metadata">

**Author:** ![DavidTurner](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/davidturner/32/22453_2.png) [@DavidTurner](https://discuss.elastic.co/u/DavidTurner)\
**Post date:** [December 31, 2018, 8:43am UTC](https://discuss.elastic.co/t/how-are-shards-chosen-when-disk-usage-exceeds-high-water-mark/162467/2 "2018-12-31T08:43:56Z")

</div>

The order is undefined, and no effort is made to move the largest or smallest shards first. Here is the loop that goes through the shards checking whether they can remain:

> <https://github.com/elastic/elasticsearch/blob/022726011ce1d9e4748fd39293a3aeae6954b3ac/server/src/main/java/org/elasticsearch/cluster/routing/allocation/allocator/BalancedShardsAllocator.java#L626-L628>

And here is the decider:

> <https://github.com/elastic/elasticsearch/blob/022726011ce1d9e4748fd39293a3aeae6954b3ac/server/src/main/java/org/elasticsearch/cluster/routing/allocation/decider/DiskThresholdDecider.java#L256-L309>

---

<div class="post-metadata">

**Author:** ![YuWatanabe](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/yuwatanabe/32/13259_2.png) [@YuWatanabe](https://discuss.elastic.co/u/YuWatanabe)\
**Post date:** [January 7, 2019, 2:05am UTC](https://discuss.elastic.co/t/how-are-shards-chosen-when-disk-usage-exceeds-high-water-mark/162467/3 "2019-01-07T02:05:01Z")

</div>

I see. I will mark your comment as _solution_.

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [February 4, 2019, 2:05am UTC](https://discuss.elastic.co/t/how-are-shards-chosen-when-disk-usage-exceeds-high-water-mark/162467/4 "2019-02-04T02:05:10Z")

</div>

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.
