-
Notifications
You must be signed in to change notification settings - Fork 2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Enhance CheckpointState to support no-op replication (#5282)
* CheckpointState enhanced to support no-op replication Signed-off-by: Ashish Singh <[email protected]> Co-authored-by: Bukhtawar Khan<[email protected]>
- Loading branch information
Showing
18 changed files
with
1,541 additions
and
91 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
25 changes: 25 additions & 0 deletions
25
server/src/main/java/org/opensearch/action/support/replication/FanoutReplicationProxy.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
/* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
* | ||
* The OpenSearch Contributors require contributions made to | ||
* this file be licensed under the Apache-2.0 license or a | ||
* compatible open source license. | ||
*/ | ||
|
||
package org.opensearch.action.support.replication; | ||
|
||
import org.opensearch.cluster.routing.ShardRouting; | ||
|
||
/** | ||
* This implementation of {@link ReplicationProxy} fans out the replication request to current shard routing if | ||
* it is not the primary and has replication mode as {@link ReplicationMode#FULL_REPLICATION}. | ||
* | ||
* @opensearch.internal | ||
*/ | ||
public class FanoutReplicationProxy<ReplicaRequest> extends ReplicationProxy<ReplicaRequest> { | ||
|
||
@Override | ||
ReplicationMode determineReplicationMode(ShardRouting shardRouting, ShardRouting primaryRouting) { | ||
return shardRouting.isSameAllocation(primaryRouting) == false ? ReplicationMode.FULL_REPLICATION : ReplicationMode.NO_REPLICATION; | ||
} | ||
} |
32 changes: 32 additions & 0 deletions
32
server/src/main/java/org/opensearch/action/support/replication/ReplicationMode.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
/* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
* | ||
* The OpenSearch Contributors require contributions made to | ||
* this file be licensed under the Apache-2.0 license or a | ||
* compatible open source license. | ||
*/ | ||
|
||
package org.opensearch.action.support.replication; | ||
|
||
/** | ||
* The type of replication used for inter-node replication. | ||
* | ||
* @opensearch.internal | ||
*/ | ||
public enum ReplicationMode { | ||
/** | ||
* In this mode, a {@code TransportReplicationAction} is fanned out to underlying concerned shard and is replicated logically. | ||
* In short, this mode would replicate the {@link ReplicationRequest} to | ||
* the replica shard along with primary term validation. | ||
*/ | ||
FULL_REPLICATION, | ||
/** | ||
* In this mode, a {@code TransportReplicationAction} is fanned out to underlying concerned shard and used for | ||
* primary term validation only. The request is not replicated logically. | ||
*/ | ||
PRIMARY_TERM_VALIDATION, | ||
/** | ||
* In this mode, a {@code TransportReplicationAction} does not fan out to the underlying concerned shard. | ||
*/ | ||
NO_REPLICATION; | ||
} |
44 changes: 44 additions & 0 deletions
44
...er/src/main/java/org/opensearch/action/support/replication/ReplicationModeAwareProxy.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
/* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
* | ||
* The OpenSearch Contributors require contributions made to | ||
* this file be licensed under the Apache-2.0 license or a | ||
* compatible open source license. | ||
*/ | ||
|
||
package org.opensearch.action.support.replication; | ||
|
||
import org.opensearch.cluster.routing.ShardRouting; | ||
|
||
import java.util.Objects; | ||
|
||
/** | ||
* This implementation of {@link ReplicationProxy} fans out the replication request to current shard routing basis | ||
* the shard routing's replication mode and replication override policy. | ||
* | ||
* @opensearch.internal | ||
*/ | ||
public class ReplicationModeAwareProxy<ReplicaRequest> extends ReplicationProxy<ReplicaRequest> { | ||
|
||
private final ReplicationMode replicationModeOverride; | ||
|
||
public ReplicationModeAwareProxy(ReplicationMode replicationModeOverride) { | ||
assert Objects.nonNull(replicationModeOverride); | ||
this.replicationModeOverride = replicationModeOverride; | ||
} | ||
|
||
@Override | ||
ReplicationMode determineReplicationMode(ShardRouting shardRouting, ShardRouting primaryRouting) { | ||
|
||
// If the current routing is the primary, then it does not need to be replicated | ||
if (shardRouting.isSameAllocation(primaryRouting)) { | ||
return ReplicationMode.NO_REPLICATION; | ||
} | ||
|
||
if (primaryRouting.relocating() && shardRouting.isSameAllocation(primaryRouting.getTargetRelocatingShard())) { | ||
return ReplicationMode.FULL_REPLICATION; | ||
} | ||
|
||
return replicationModeOverride; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
51 changes: 51 additions & 0 deletions
51
server/src/main/java/org/opensearch/action/support/replication/ReplicationProxy.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
/* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
* | ||
* The OpenSearch Contributors require contributions made to | ||
* this file be licensed under the Apache-2.0 license or a | ||
* compatible open source license. | ||
*/ | ||
|
||
package org.opensearch.action.support.replication; | ||
|
||
import org.opensearch.cluster.routing.ShardRouting; | ||
|
||
import java.util.function.Consumer; | ||
|
||
/** | ||
* Used for performing any replication operation on replicas. Depending on the implementation, the replication call | ||
* can fanout or stops here. | ||
* | ||
* @opensearch.internal | ||
*/ | ||
public abstract class ReplicationProxy<ReplicaRequest> { | ||
|
||
/** | ||
* Depending on the actual implementation and the passed {@link ReplicationMode}, the replication | ||
* mode is determined using which the replication request is performed on the replica or not. | ||
* | ||
* @param proxyRequest replication proxy request | ||
* @param originalPerformOnReplicaConsumer original performOnReplica method passed as consumer | ||
*/ | ||
public void performOnReplicaProxy( | ||
ReplicationProxyRequest<ReplicaRequest> proxyRequest, | ||
Consumer<ReplicationProxyRequest<ReplicaRequest>> originalPerformOnReplicaConsumer | ||
) { | ||
ReplicationMode replicationMode = determineReplicationMode(proxyRequest.getShardRouting(), proxyRequest.getPrimaryRouting()); | ||
// If the replication modes are 1. Logical replication or 2. Primary term validation, we let the call get performed on the | ||
// replica shard. | ||
if (replicationMode == ReplicationMode.FULL_REPLICATION || replicationMode == ReplicationMode.PRIMARY_TERM_VALIDATION) { | ||
originalPerformOnReplicaConsumer.accept(proxyRequest); | ||
} | ||
} | ||
|
||
/** | ||
* Determines what is the replication mode basis the constructor arguments of the implementation and the current | ||
* replication mode aware shard routing. | ||
* | ||
* @param shardRouting replication mode aware ShardRouting | ||
* @param primaryRouting primary ShardRouting | ||
* @return the determined replication mode. | ||
*/ | ||
abstract ReplicationMode determineReplicationMode(final ShardRouting shardRouting, final ShardRouting primaryRouting); | ||
} |
29 changes: 29 additions & 0 deletions
29
server/src/main/java/org/opensearch/action/support/replication/ReplicationProxyFactory.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
/* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
* | ||
* The OpenSearch Contributors require contributions made to | ||
* this file be licensed under the Apache-2.0 license or a | ||
* compatible open source license. | ||
*/ | ||
|
||
package org.opensearch.action.support.replication; | ||
|
||
import org.opensearch.index.shard.IndexShard; | ||
|
||
/** | ||
* Factory that returns the {@link ReplicationProxy} instance basis the {@link ReplicationMode}. | ||
* | ||
* @opensearch.internal | ||
*/ | ||
public class ReplicationProxyFactory { | ||
|
||
public static <ReplicaRequest> ReplicationProxy<ReplicaRequest> create( | ||
final IndexShard indexShard, | ||
final ReplicationMode replicationModeOverride | ||
) { | ||
if (indexShard.isRemoteTranslogEnabled()) { | ||
return new ReplicationModeAwareProxy<>(replicationModeOverride); | ||
} | ||
return new FanoutReplicationProxy<>(); | ||
} | ||
} |
Oops, something went wrong.