# Open deleted file handles with elasticsearch

**URL:** https://discuss.elastic.co/t/open-deleted-file-handles-with-elasticsearch/8207
**Category:** Elasticsearch
**Created:** [June 24, 2012, 7:47am UTC](https://discuss.elastic.co/t/open-deleted-file-handles-with-elasticsearch/8207 "2012-06-24T07:47:25Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![spinscale](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/spinscale/32/25011_2.png) [@spinscale](https://discuss.elastic.co/u/spinscale)
#### Post date: [June 24, 2012, 7:47am UTC](https://discuss.elastic.co/t/open-deleted-file-handles-with-elasticsearch/8207/1 "2012-06-24T07:47:25Z")

</div>

Hi there,

we have a problem with open file handles of deleted lucene indices on one  
elasticsearch instance, and I am not sure how to figure this out.

Setup: ES 0.19.3 with result grouping, one index, plus FST suggester (where  
I suspect the leak, as it is my code).

After a bug in our river, the ES instance imported like 60 products per  
second constantly for several days. It always imported the same documents  
(several ten thousands) every n minutes and then immediately restarted  
after 30 seconds break.

This slowly filled up the available disk space, because lucene segments  
were deleted but the filehandle was still kept open, lsof looks like this:

java 2695 elasticsearch 6783r REG 251,0 275  
797199  
/var/lib/elasticsearch/production/nodes/0/indices/products1/0/index/\_f3n.nrm  
(deleted)  
java 2695 elasticsearch 6784r REG 251,0 1293  
797193  
/var/lib/elasticsearch/production/nodes/0/indices/products1/0/index/\_f3n.fdt  
(deleted)  
java 2695 elasticsearch 6785r REG 251,0 12  
797194  
/var/lib/elasticsearch/production/nodes/0/indices/products1/0/index/\_f3n.fdx  
(deleted)  
java 2695 elasticsearch 6787r REG 251,0 2592  
797166  
/var/lib/elasticsearch/production/nodes/0/indices/products1/0/index/\_f3r.fdt  
(deleted)  
java 2695 elasticsearch 6790r REG 251,0 20  
797174  
/var/lib/elasticsearch/production/nodes/0/indices/products1/0/index/\_f3r.fdx  
(deleted)

There are around 6500 deleted files open concurrently.

I fixed this by calling also closing the indexReader instance I used in my  
fst-suggest plugin. This somewhat changed the behaviour of my problem.

When not closing the indexreader, the es instance had lots of open files  
and ate all the diskspace. Now i changed the problem behaviour to not  
consume the diskspace but still having tons of open deleted files lurking  
around.

The inMemory structure I am using for my suggest feature contains an  
IndexReader, a SpellChecker, and FSTLookup and a ShardId.

Are there any ES resources I need to take care of additionally, before  
writing to the lucene mailinglist? 🙂

Thanks for any pointers in this regard, my Lucene knowledge is not the best  
🙂

--Alexander

---

<div class="post-metadata">

### Author: ![kimchy](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/kimchy/32/44952_2.png) [@kimchy](https://discuss.elastic.co/u/kimchy)
#### Post date: [June 25, 2012, 12:16pm UTC](https://discuss.elastic.co/t/open-deleted-file-handles-with-elasticsearch/8207/2 "2012-06-25T12:16:54Z")

</div>

The delete file handles problem usually comes from not properly closing  
index reader. In elasticsearch, usually you get a searcher and then you  
need to release it when you are done. Can you point me to the suggester  
code that handles it?

On Sun, Jun 24, 2012 at 9:47 AM, Alexander Reelsen [alr@spinscale.de](mailto:alr@spinscale.de) wrote:

> Hi there,
> 
> we have a problem with open file handles of deleted lucene indices on one  
> elasticsearch instance, and I am not sure how to figure this out.
> 
> Setup: ES 0.19.3 with result grouping, one index, plus FST suggester  
> (where I suspect the leak, as it is my code).
> 
> After a bug in our river, the ES instance imported like 60 products per  
> second constantly for several days. It always imported the same documents  
> (several ten thousands) every n minutes and then immediately restarted  
> after 30 seconds break.
> 
> This slowly filled up the available disk space, because lucene segments  
> were deleted but the filehandle was still kept open, lsof looks like this:
> 
> java 2695 elasticsearch 6783r REG 251,0 275  
> 797199  
> /var/lib/elasticsearch/production/nodes/0/indices/products1/0/index/\_f3n.nrm  
> (deleted)  
> java 2695 elasticsearch 6784r REG 251,0 1293  
> 797193  
> /var/lib/elasticsearch/production/nodes/0/indices/products1/0/index/\_f3n.fdt  
> (deleted)  
> java 2695 elasticsearch 6785r REG 251,0 12  
> 797194  
> /var/lib/elasticsearch/production/nodes/0/indices/products1/0/index/\_f3n.fdx  
> (deleted)  
> java 2695 elasticsearch 6787r REG 251,0 2592  
> 797166  
> /var/lib/elasticsearch/production/nodes/0/indices/products1/0/index/\_f3r.fdt  
> (deleted)  
> java 2695 elasticsearch 6790r REG 251,0 20  
> 797174  
> /var/lib/elasticsearch/production/nodes/0/indices/products1/0/index/\_f3r.fdx  
> (deleted)
> 
> There are around 6500 deleted files open concurrently.
> 
> I fixed this by calling also closing the indexReader instance I used in my  
> fst-suggest plugin. This somewhat changed the behaviour of my problem.
> 
> When not closing the indexreader, the es instance had lots of open files  
> and ate all the diskspace. Now i changed the problem behaviour to not  
> consume the diskspace but still having tons of open deleted files lurking  
> around.
> 
> The inMemory structure I am using for my suggest feature contains an  
> IndexReader, a SpellChecker, and FSTLookup and a ShardId.
> 
> Are there any ES resources I need to take care of additionally, before  
> writing to the lucene mailinglist? 🙂
> 
> Thanks for any pointers in this regard, my Lucene knowledge is not the  
> best 🙂
> 
> --Alexander

---

<div class="post-metadata">

### Author: ![spinscale](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/spinscale/32/25011_2.png) [@spinscale](https://discuss.elastic.co/u/spinscale)
#### Post date: [June 29, 2012, 9:04pm UTC](https://discuss.elastic.co/t/open-deleted-file-handles-with-elasticsearch/8207/3 "2012-06-29T21:04:57Z")

</div>

Hi Shay,

sorry for the late response...

On Mon, Jun 25, 2012 at 2:16 PM, Shay Banon [kimchy@gmail.com](mailto:kimchy@gmail.com) wrote:

> The delete file handles problem usually comes from not properly closing  
> index reader. In elasticsearch, usually you get a searcher and then you  
> need to release it when you are done. Can you point me to the suggester  
> code that handles it?

Check  
[https://github.com/spinscale/elasticsearch-suggest-plugin/blob/master/src/main/java/org/elasticsearch/service/suggest/SuggestService.java-](https://github.com/spinscale/elasticsearch-suggest-plugin/blob/master/src/main/java/org/elasticsearch/service/suggest/SuggestService.java-)  
line 73, the suggest() method. I put the release() method in a finally  
block.

The Suggester class uses the indexReader and is closed, whenever the fst  
suggester is updated - this happens usually every 10 minutes. The Suggester  
class can be seen here  
[https://github.com/spinscale/elasticsearch-suggest-plugin/blob/master/src/main/java/org/elasticsearch/service/suggest/Suggester.javaand](https://github.com/spinscale/elasticsearch-suggest-plugin/blob/master/src/main/java/org/elasticsearch/service/suggest/Suggester.javaand)  
has a cleanUpResources() method where it closes the spellchecker and  
the indexReader.

If you have any further questions or I answered to blurry, feel free to  
tell.

Thanks for your help!

--Alexander

---

<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: [July 6, 2017, 3:21am UTC](https://discuss.elastic.co/t/open-deleted-file-handles-with-elasticsearch/8207/4 "2017-07-06T03:21:58Z")

</div>


