Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Segment Replication] Bump segment infos counter before commit during replica promotion #4365

Merged
merged 4 commits into from
Sep 2, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ Inspired from [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)
- Add timeout on Mockito.verify to reduce flakyness in testReplicationOnDone test([#4314](https://github.com/opensearch-project/OpenSearch/pull/4314))
- Commit workflow for dependabot changelog helper ([#4331](https://github.com/opensearch-project/OpenSearch/pull/4331))
- Fixed cancellation of segment replication events ([#4225](https://github.com/opensearch-project/OpenSearch/pull/4225))
- [Segment Replication] Bump segment infos counter before commit during replica promotion ([#4365](https://github.com/opensearch-project/OpenSearch/pull/4365))
- Bugs for dependabot changelog verifier workflow ([#4364](https://github.com/opensearch-project/OpenSearch/pull/4364))
- Fix flaky random test `NRTReplicationEngineTests.testUpdateSegments` ([#4352](https://github.com/opensearch-project/OpenSearch/pull/4352))

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ public class NRTReplicationEngine extends Engine {
private final LocalCheckpointTracker localCheckpointTracker;
private final WriteOnlyTranslogManager translogManager;

private static final int SI_COUNTER_INCREMENT = 10;

public NRTReplicationEngine(EngineConfig engineConfig) {
super(engineConfig);
store.incRef();
Expand Down Expand Up @@ -142,6 +144,13 @@ public synchronized void updateSegments(final SegmentInfos infos, long seqNo) th
public void commitSegmentInfos() throws IOException {
// TODO: This method should wait for replication events to finalize.
final SegmentInfos latestSegmentInfos = getLatestSegmentInfos();
/*
This is a workaround solution which decreases the chances of conflict on replica nodes when same file is copied
from two different primaries during failover. Increasing counter helps in avoiding this conflict as counter is
used to generate new segment file names. The ideal solution is to identify the counter from previous primary.
*/
latestSegmentInfos.counter = latestSegmentInfos.counter + SI_COUNTER_INCREMENT;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not opposed to this as a "best-effort" approach but it would be great if we could somehow fetch and increment from the previous primary's counter instead of this replica's latest infos. latestSegmentInfos on the replica here could still potentially be more than 10 generations behind and get promoted as primary.

I'm not sure exactly how we'd do that though with any accuracy.

I'm ok with this as best-effort, because we can still fail & recover the replicas that have conflicts as needed and attempt to select the furthest ahead during promotion.

Copy link
Member Author

@dreamer-89 dreamer-89 Sep 2, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure exactly how we'd do that though with any accuracy.

I added few alternatives in the description. But this solution works well and prevents file conflicts on nodes. I ran tests in continuation (with some tweaks on refresh/commits) but did not face any issue or side-effects. If this doesn't hurt let's move forward with this solution. This is also in general helpful not just for #4295 but overall working of segment replication.

latestSegmentInfos.changed();
store.commitSegmentInfos(latestSegmentInfos, localCheckpointTracker.getMaxSeqNo(), localCheckpointTracker.getProcessedCheckpoint());
translogManager.syncTranslog();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,8 @@ public void testCommitSegmentInfos() throws Exception {
// ensure getLatestSegmentInfos returns an updated infos ref with correct userdata.
final SegmentInfos latestSegmentInfos = nrtEngine.getLatestSegmentInfos();
assertEquals(previousInfos.getGeneration(), latestSegmentInfos.getLastGeneration());
assertEquals(previousInfos.getVersion(), latestSegmentInfos.getVersion());
assertEquals(previousInfos.counter, latestSegmentInfos.counter);
Map<String, String> userData = latestSegmentInfos.getUserData();
assertEquals(processedCheckpoint, localCheckpointTracker.getProcessedCheckpoint());
assertEquals(maxSeqNo, Long.parseLong(userData.get(MAX_SEQ_NO)));
Expand Down