-
Notifications
You must be signed in to change notification settings - Fork 1.9k
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] Adding PrimaryMode check before publishing checkpoint and processing a received checkpoint. #4157
Changes from 2 commits
e0dcca6
c048700
31db9c7
a7dfbb8
fde5a61
9f2be06
7519ba7
226f1c0
66fbfcb
4989d2b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -206,7 +206,10 @@ | |
import static org.hamcrest.Matchers.nullValue; | ||
import static org.hamcrest.Matchers.oneOf; | ||
import static org.hamcrest.Matchers.sameInstance; | ||
import static org.mockito.ArgumentMatchers.any; | ||
import static org.mockito.Mockito.mock; | ||
import static org.mockito.Mockito.times; | ||
import static org.mockito.Mockito.verify; | ||
import static org.opensearch.cluster.routing.TestShardRouting.newShardRouting; | ||
import static org.opensearch.common.lucene.Lucene.cleanLuceneIndex; | ||
import static org.opensearch.common.xcontent.ToXContent.EMPTY_PARAMS; | ||
|
@@ -3522,7 +3525,43 @@ public void testCheckpointRefreshListenerWithNull() throws IOException { | |
} | ||
|
||
/** | ||
* creates a new initializing shard. The shard will will be put in its proper path under the | ||
* here we are starting a new primary shard in PrimaryMode and testing if the shard publishes checkpoint after refresh. | ||
*/ | ||
public void testPublishCheckpointOnPrimaryMode() throws IOException { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we move these segrep specific tests to SegmentReplicationIndexShardTests? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. +1 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sure, moved to SegmentReplicationIndexShardTests in new PR. |
||
final SegmentReplicationCheckpointPublisher mock = mock(SegmentReplicationCheckpointPublisher.class); | ||
IndexShard shard = newStartedShard(p -> newShard(mock), true); | ||
CheckpointRefreshListener refreshListener = new CheckpointRefreshListener(shard, mock); | ||
refreshListener.afterRefresh(true); | ||
|
||
// verify checkpoint is published | ||
verify(mock, times(1)).publish(any()); | ||
closeShards(shard); | ||
} | ||
|
||
/** | ||
* here we are starting a new primary shard in PrimaryMode intially and starting relocation handoff. Later we complete relocation handoff then shard is no longer | ||
* in PrimaryMode, and we test if the shard does not publish checkpoint after refresh. | ||
*/ | ||
public void testPublishCheckpointAfterRelocationHandOff() throws IOException { | ||
final SegmentReplicationCheckpointPublisher mock = mock(SegmentReplicationCheckpointPublisher.class); | ||
IndexShard shard = newStartedShard(p -> newShard(mock), true); | ||
CheckpointRefreshListener refreshListener = new CheckpointRefreshListener(shard, mock); | ||
String id = shard.routingEntry().allocationId().getId(); | ||
|
||
// Starting relocation handoff | ||
shard.getReplicationTracker().startRelocationHandoff(id); | ||
|
||
// Completing relocation handoff | ||
shard.getReplicationTracker().completeRelocationHandoff(); | ||
refreshListener.afterRefresh(true); | ||
|
||
// verify checkpoint is not published | ||
verify(mock, times(0)).publish(any()); | ||
closeShards(shard); | ||
} | ||
|
||
/** | ||
* creates a new initializing shard. The shard will be put in its proper path under the | ||
* current node id the shard is assigned to. | ||
* @param checkpointPublisher Segment Replication Checkpoint Publisher to publish checkpoint | ||
*/ | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we also reject checkpoints if the replica copy(where the checkpoint was sent to) is operating in primary mode.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
+1
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also on that note - we will want to cancel any ongoing replication events on both sides. I've added #4136 to cover this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is it also worth checking shardRouting here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added Logic to reject checkpoints if shard is in PrimaryMode in latest commit.