# In-memory buffer

**URL:** <https://discuss.elastic.co/t/in-memory-buffer/41254>\
**Category:** Elasticsearch\
**Created:** [February 9, 2016, 9:01am UTC](https://discuss.elastic.co/t/in-memory-buffer/41254 "2016-02-09T09:01:42Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![skumar](https://avatars.discourse-cdn.com/v4/letter/s/e9c0ed/32.png) [@skumar](https://discuss.elastic.co/u/skumar)\
**Post date:** [February 9, 2016, 9:01am UTC](https://discuss.elastic.co/t/in-memory-buffer/41254/1 "2016-02-09T09:01:42Z")

</div>

Hi,  
when indexing a doc, it is first indexed on primary and doc is written to in-memory buffer as well as translog buffer and then goes to replica , but then replica goes down such that quorum is not satisfied now and indexing is not successful.What happens to the doc that are written to in memory buffer and translog buffer of primary shard? are these buffers get deleted? Can someone explain it?Thanks

---

<div class="post-metadata">

**Author:** ![Mark\_Harwood](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/mark_harwood/32/10538_2.png) [@Mark\_Harwood](https://discuss.elastic.co/u/Mark_Harwood)\
**Post date:** [February 9, 2016, 5:39pm UTC](https://discuss.elastic.co/t/in-memory-buffer/41254/2 "2016-02-09T17:39:54Z")

</div>

The quorum is a condition that must be satisfied _before a write is attempted_ - see [1]

[1] [https://www.elastic.co/guide/en/elasticsearch/guide/master/distrib-write.html](https://www.elastic.co/guide/en/elasticsearch/guide/master/distrib-write.html)

---

<div class="post-metadata">

**Author:** ![skumar](https://avatars.discourse-cdn.com/v4/letter/s/e9c0ed/32.png) [@skumar](https://discuss.elastic.co/u/skumar)\
**Post date:** [February 10, 2016, 5:08am UTC](https://discuss.elastic.co/t/in-memory-buffer/41254/3 "2016-02-10T05:08:10Z")

</div>

Hi Mark , Lets say quorum is satisfied before a write operation is performed on primary shard, so at this point it writes doc into in-memory buffer and translog buffer and now it hand over this process to replica phase but at this point replica goes down (such that active shards less than quorum) and writing operation is not successful. My question is what will happen to in-memory buffer of primary shard in which doc has been written previously? Whether in-memory buffer gets deleted ? or doc get deleted ? or doc remains there in buffer and when next write operation comes, new docs are appended to it?

Or is it like docs will be written to buffer only if complete indexing process(all shards of quorum) is successful? Thanks

---

<div class="post-metadata">

**Author:** ![bleskes](https://avatars.discourse-cdn.com/v4/letter/b/71c47a/32.png) [@bleskes](https://discuss.elastic.co/u/bleskes)\
**Post date:** [February 10, 2016, 2:07pm UTC](https://discuss.elastic.co/t/in-memory-buffer/41254/4 "2016-02-10T14:07:55Z")

</div>

As mark said the quorum check is done before we start indexing into the primary. Once the doc past the check it will not be removed. When a replica fails, as you say, the master will be notified to fail the replica and the primary will continue without it. With 2.x this means that the translog with the doc will be fsynced and we ack the write to the client. Note that the response will indicate how many successful copies were made (2.x feature). Of, course the master will also immediately start creating a new replica on another node.

---

<div class="post-metadata">

**Author:** ![skumar](https://avatars.discourse-cdn.com/v4/letter/s/e9c0ed/32.png) [@skumar](https://discuss.elastic.co/u/skumar)\
**Post date:** [February 11, 2016, 1:13pm UTC](https://discuss.elastic.co/t/in-memory-buffer/41254/5 "2016-02-11T13:13:08Z")

</div>

Thanks Boaz!! can you point me to elasticsearch git code base java class where writing in buffer actually happens.

---

<div class="post-metadata">

**Author:** ![bleskes](https://avatars.discourse-cdn.com/v4/letter/b/71c47a/32.png) [@bleskes](https://discuss.elastic.co/u/bleskes)\
**Post date:** [March 7, 2016, 9:56am UTC](https://discuss.elastic.co/t/in-memory-buffer/41254/6 "2016-03-07T09:56:03Z")

</div>

I'm not sure exactly what you mean. Lucene has it's own memory buffer (and is very complex). ES has a small buffer in it's `BufferingTranslogWriter` class on 2.x and TranslogWriter in master.

---

<div class="post-metadata">

**Author:** ![skumar](https://avatars.discourse-cdn.com/v4/letter/s/e9c0ed/32.png) [@skumar](https://discuss.elastic.co/u/skumar)\
**Post date:** [March 7, 2016, 9:59am UTC](https://discuss.elastic.co/t/in-memory-buffer/41254/7 "2016-03-07T09:59:30Z")

</div>

Yeah I was able to find it out but thanks for you reply:grinning:

---

<div class="post-metadata">

**Author:** ![bleskes](https://avatars.discourse-cdn.com/v4/letter/b/71c47a/32.png) [@bleskes](https://discuss.elastic.co/u/bleskes)\
**Post date:** [March 7, 2016, 10:03am UTC](https://discuss.elastic.co/t/in-memory-buffer/41254/8 "2016-03-07T10:03:01Z")

</div>

> [@skumar](#):
>
> I was able to find it out

Even better 🙂

Sorry for the late response...

---

<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 5, 2017, 11:10pm UTC](https://discuss.elastic.co/t/in-memory-buffer/41254/9 "2017-07-05T23:10:46Z")

</div>


