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

Refactoring of Segment Replication classes #2468

Conversation

kartg
Copy link
Member

@kartg kartg commented Mar 14, 2022

Description

Incremental refactoring of Segment Replication classes to centralize common functionality between seg-rep and recovery code. These are mostly modeled as Replication* parent classes with Recovery* and SegmentReplication* child classes.

There is much more refactoring that can be done above this, but the work in these commits is a time-boxed effort.

Issues Resolved

[List any issues this PR will resolve]

Check List

  • New functionality includes testing.
    • All tests pass
  • New functionality has been documented.
    • New functionality has javadoc added
  • Commits are signed per the DCO using --signoff

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.
For more information on following Developer Certificate of Origin and signing off your commits, please check here.

Since this class wraps two subclasses of RefCounted, and has the same shutdown hook for both (decRef), I've made the functionality of the class less generic to increase code convergence.

Signed-off-by: Kartik Ganesh <gkart@amazon.com>
Parent class names are currently temporary placeholders. They will renamed in a separate commit to avoid a convoluted commit diff.

A large part of duplicate functionality in the two *Target classes has been moved into the parent class. The two *Listeners are also very similar and now implement a common interface. The usec-ase specific methods in the listeners will eventually be replaced by their generic equivalents. Finally, the State parent class is currently a placeholder and will soon hold more logic.

Some other parts of the code were also changed to make call patterns more streamlined.

Signed-off-by: Kartik Ganesh <gkart@amazon.com>
Signed-off-by: Kartik Ganesh <gkart@amazon.com>
The existing ReplicationTarget has been renamed to SegmentReplicationTarget. Alongside this change, unnecessary wrapper methods have been removed and replaced with more direct invocations.

Signed-off-by: Kartik Ganesh <gkart@amazon.com>
The ReplicationListener class has been renamed to SegmentReplicationListener, and the parent class now takes the more-generic ReplicationListener name. The inner classes in IndicesClusterStateService have also been renamed to ShardRouting* to reflect their purpose.

Signed-off-by: Kartik Ganesh <gkart@amazon.com>
This class is currently across both recovery and segment replication. It has two dependent inner classes - RecoveryFilesDetails and FileDetail - which have been moved from RecoveryState to be inner classes in RecoveryIndex

Signed-off-by: Kartik Ganesh <gkart@amazon.com>
A small amount of common members and logic from its subclasses has been moved into the parent class. The original ReplicationState child class has been renamed SegmentReplicationState.

Signed-off-by: Kartik Ganesh <gkart@amazon.com>
@kartg kartg requested a review from a team as a code owner March 14, 2022 23:35
@opensearch-ci-bot
Copy link
Collaborator

Can one of the admins verify this patch?

@opensearch-ci-bot
Copy link
Collaborator

❌   Gradle Check failure 065798f
Log 3368

Reports 3368

@@ -748,7 +748,7 @@ private static DiscoveryNode findSourceNodeForPeerRecovery(
return sourceNode;
}

private class ReplicationListener implements SegmentReplicationReplicaService.ReplicationListener {
private class ShardRoutingReplicationListener implements SegmentReplicationReplicaService.SegmentReplicationListener {
Copy link
Member

Choose a reason for hiding this comment

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

This was me being quick and dirty with the POC - I don't think we need a separate listener type for segrep. I think we could extract PeerRecoveryTargetService.RecoveryListener and use it for segrep with a common exception type. We will still need to perform the same actions that RecoveryListener now performs on success (publishing shardStarted) and failure (failing and removing the shard).

Copy link
Member Author

Choose a reason for hiding this comment

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

Understood. I'll punt this to a future refactor

@@ -35,7 +35,7 @@
import org.apache.logging.log4j.Logger;
Copy link
Member

Choose a reason for hiding this comment

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

Should we also rename this class to SegmentReplicationCollection?

Copy link
Member Author

Choose a reason for hiding this comment

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

I haven't yet touched the Collection classes so i'd like to leave this as-is for now. In a follow up refactor, we can rename this appropriately after synergizing functionality with the Recovery equivalent

This is in response to PR feedback, and helps avoid a verbose get() method by introducing the generic at the class level.

Signed-off-by: Kartik Ganesh <gkart@amazon.com>
@opensearch-ci-bot
Copy link
Collaborator

❌   Gradle Check failure 9988089
Log 3424

Reports 3424

Copy link
Member

@mch2 mch2 left a comment

Choose a reason for hiding this comment

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

lgtm, thanks!

@kartg kartg merged commit 74e04b5 into opensearch-project:feature/segment-replication Mar 16, 2022
@kartg kartg mentioned this pull request Mar 17, 2022
31 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants