# A question about primary/replica re-sync implementation

**URL:** <https://discuss.elastic.co/t/a-question-about-primary-replica-re-sync-implementation/219109>\
**Category:** Elasticsearch\
**Created:** [February 13, 2020, 2:29am UTC](https://discuss.elastic.co/t/a-question-about-primary-replica-re-sync-implementation/219109 "2020-02-13T02:29:36Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![iamorchid](https://avatars.discourse-cdn.com/v4/letter/i/bbce88/32.png) [@iamorchid](https://discuss.elastic.co/u/iamorchid)\
**Post date:** [February 13, 2020, 2:29am UTC](https://discuss.elastic.co/t/a-question-about-primary-replica-re-sync-implementation/219109/1 "2020-02-13T02:29:36Z")

</div>

Let's say we have 3 replicas for one index shard and they have the following local op seqs:  
node#1(primary) : 1, 2, 3, 4, 5, 6, 7, 8 (local checkpoint: 8, max seqNo: 8, global checkpoint: 5)  
node#2(replica#1): 1, 2, 3, 4, 5, 7, 8 (local checkpoint: 5, max seqNo: 8, global checkpoint: 5)  
node#3(replica#2): 1, 2, 3, 4, 5, 6, 7 (local checkpoint: 7, max seqNo: 7, global checkpoint: 5)

Suppose node#1 crashed, and node#3(replica#2) is promoted to new primary. Then there will be a re-sync during which node#3 sends op 6 and 7 to node#2. Also for node#2, the re-sync would trim all its translog ops that are above max seqNo of node#3 (namely, seq 8 would be trimmed).

The question here is after re-sync, node#3 would only have changes from seq 1 to seq 7 in its local Lucene. However, node#2 would have the additional change of seq 8 (the translog trimming doesn't rollback the changes in lucene). So there could be data in-consistency between node#3 and node#2 in their lucenes after re-sync (though their translogs are consistent)。

Have I missed anything here?

---

<div class="post-metadata">

**Author:** ![nhat](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/nhat/32/22170_2.png) [@nhat](https://discuss.elastic.co/u/nhat)\
**Post date:** [February 13, 2020, 4:06am UTC](https://discuss.elastic.co/t/a-question-about-primary-replica-re-sync-implementation/219109/2 "2020-02-13T04:06:21Z")

</div>

@iamorchid When a replica detects the new primary, it will [rollback its Lucene index](https://github.com/elastic/elasticsearch/blob/master/server/src/main/java/org/elasticsearch/index/shard/IndexShard.java#L3297), then recover locally up to the global checkpoint. In your example, operation #8 won't exist in the copy of node#2 after the primary-replica resync.

---

<div class="post-metadata">

**Author:** ![iamorchid](https://avatars.discourse-cdn.com/v4/letter/i/bbce88/32.png) [@iamorchid](https://discuss.elastic.co/u/iamorchid)\
**Post date:** [February 13, 2020, 6:30am UTC](https://discuss.elastic.co/t/a-question-about-primary-replica-re-sync-implementation/219109/3 "2020-02-13T06:30:33Z")

</div>

Thanks for your reply. Do we have such logic also for 6.4.2 ? Currently, I'm looking at 6.4.2 implemenation (and didn't notice such logic so far). Not sure if this is added in newer version.

---

<div class="post-metadata">

**Author:** ![nhat](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/nhat/32/22170_2.png) [@nhat](https://discuss.elastic.co/u/nhat)\
**Post date:** [February 13, 2020, 2:10pm UTC](https://discuss.elastic.co/t/a-question-about-primary-replica-re-sync-implementation/219109/4 "2020-02-13T14:10:12Z")

</div>

Hi @iamorchid,

It was implemented in 6.5.0 (see [https://github.com/elastic/elasticsearch/pull/33473](https://github.com/elastic/elasticsearch/pull/33473)).

---

<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:** [March 12, 2020, 2:10pm UTC](https://discuss.elastic.co/t/a-question-about-primary-replica-re-sync-implementation/219109/5 "2020-03-12T14:10:45Z")

</div>

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