# How Translog Work on elastic

**URL:** <https://discuss.elastic.co/t/how-translog-work-on-elastic/325880>\
**Category:** Elasticsearch\
**Created:** [February 18, 2023, 5:23am UTC](https://discuss.elastic.co/t/how-translog-work-on-elastic/325880 "2023-02-18T05:23:33Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![yuswanul](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/yuswanul/32/101662_2.png) [@yuswanul](https://discuss.elastic.co/u/yuswanul)\
**Post date:** [February 18, 2023, 5:23am UTC](https://discuss.elastic.co/t/how-translog-work-on-elastic/325880/1 "2023-02-18T05:23:33Z")

</div>

Hi everyone,

I have a question about translog. So here is the situation:

I have one index with 1 primary and 1 replica shard and continuously ingesting data. If i read documentation, it says that primary and replica shards are write their operations to the translog. Cmiiw

So my question is, if there is a issue for example the cluster become yellow or red, and the primary and replica shards become unassigned, how do they recover from the translog until they have the latest data? while the translog itself is written by the shard as written in the documentation

> "so each shard copy also writes operations into its transaction log known as the translog"

if the shards becomes unassigned, then it can't receive the latest data right? therefore it recovers through translog. however, the translog itself is written by the shard. so even recovering via translog can't make the shard have the latest data. if so, how will the shard catch up with its data?

Thanks

---

<div class="post-metadata">

**Author:** ![Christian\_Dahlqvist](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/christian_dahlqvist/32/4617_2.png) [@Christian\_Dahlqvist](https://discuss.elastic.co/u/Christian_Dahlqvist)\
**Post date:** [February 18, 2023, 6:04am UTC](https://discuss.elastic.co/t/how-translog-work-on-elastic/325880/2 "2023-02-18T06:04:36Z")

</div>

If a replica shard becomes unavailable, the primary shard will continue to accept writes and write these to the transaction log.

If the primary becomes unavailable and there is a replica shard in place, this will get promoted to primary and continue accepting writes as in the first scenario.

If the primary as well as all replicas of a specific shard becomes unavailable the index will go red and no writes will be accepeted to any shards in that index. When one of the unavailable shards become available this will become the primary and the index will again accept writes.

---

<div class="post-metadata">

**Author:** ![yuswanul](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/yuswanul/32/101662_2.png) [@yuswanul](https://discuss.elastic.co/u/yuswanul)\
**Post date:** [March 11, 2023, 9:01am UTC](https://discuss.elastic.co/t/how-translog-work-on-elastic/325880/3 "2023-03-11T09:01:32Z")

</div>

Ok, pretty clear. But i want to know one more thing. If the primary shard becomes unavailable, the replica shard become primary and accept writes. So my question is, the old primary shard, recover from which translog? because in the documentation on my first post, it said each shard, (which is primary and replica), has it's own translog. so will it recover using its own translog or using the replica's translog which obviously has the latest data?

Thanks

---

<div class="post-metadata">

**Author:** ![Christian\_Dahlqvist](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/christian_dahlqvist/32/4617_2.png) [@Christian\_Dahlqvist](https://discuss.elastic.co/u/Christian_Dahlqvist)\
**Post date:** [March 11, 2023, 9:18am UTC](https://discuss.elastic.co/t/how-translog-work-on-elastic/325880/4 "2023-03-11T09:18:41Z")

</div>

If the old primary shard comes back it will become a replica shard (assuming a replica shard still need to be assigned) and recover from the current primary shard.

---

<div class="post-metadata">

**Author:** ![yuswanul](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/yuswanul/32/101662_2.png) [@yuswanul](https://discuss.elastic.co/u/yuswanul)\
**Post date:** [March 11, 2023, 9:40am UTC](https://discuss.elastic.co/t/how-translog-work-on-elastic/325880/5 "2023-03-11T09:40:40Z")

</div>

that means the translog is only used for reassigning the shards right? After that, the new replica will replicate the data from the current primary shard?

---

<div class="post-metadata">

**Author:** ![Christian\_Dahlqvist](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/christian_dahlqvist/32/4617_2.png) [@Christian\_Dahlqvist](https://discuss.elastic.co/u/Christian_Dahlqvist)\
**Post date:** [March 11, 2023, 9:48am UTC](https://discuss.elastic.co/t/how-translog-work-on-elastic/325880/6 "2023-03-11T09:48:47Z")

</div>

The transaction log is a local buffer holding indexd data until a new segment can be created during a flush. Writes are sent to both primary and secondary shards and are written to each shards transaction log.

In more recent versions writes use sequence numbers, which can be used when recovery takes place and to identify what has and has not been written to segments or local transaction log.

When the failed primary shard comes back in the example we discussed, the cluster can identify it is behind the current primary shard based on the sequence numbers. It will then recover based on the current primary shard. This may include procesing the local transaction log and then receive missed writes based on sequence numbers or simply copy the whole primary shard if it is very far behind.

---

<div class="post-metadata">

**Author:** ![yuswanul](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/yuswanul/32/101662_2.png) [@yuswanul](https://discuss.elastic.co/u/yuswanul)\
**Post date:** [March 11, 2023, 10:35am UTC](https://discuss.elastic.co/t/how-translog-work-on-elastic/325880/7 "2023-03-11T10:35:29Z")

</div>

i see, thanks by the way

Pada tanggal Sab, 11 Mar 2023 16.58, Christian Dahlqvist via Discuss the Elastic Stack \<[notifications@elastic.discoursemail.com](mailto:notifications@elastic.discoursemail.com)\> menulis:

---

<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:** [April 8, 2023, 10:35am UTC](https://discuss.elastic.co/t/how-translog-work-on-elastic/325880/8 "2023-04-08T10:35:34Z")

</div>

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