-
Notifications
You must be signed in to change notification settings - Fork 25.7k
Resharding Add Flush and Refresh functionality #136880
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
Changes from all commits
840b91a
dfd2a30
3048e20
0093f1c
292c5ed
7dfe6fb
4bf8d9a
21e55aa
d4b186f
e5c65b7
ef01d6d
ea07083
fbcfa99
dd09b3b
952e670
adb8644
6cd99c7
ae72d00
9725853
3f1b722
7ff45aa
da76468
99ec802
3efd785
bc3d547
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 |
|---|---|---|
|
|
@@ -16,14 +16,18 @@ | |
| import org.elasticsearch.action.support.ActionFilters; | ||
| import org.elasticsearch.action.support.replication.BasicReplicationRequest; | ||
| import org.elasticsearch.action.support.replication.ReplicationOperation; | ||
| import org.elasticsearch.action.support.replication.ReplicationRequestSplitHelper; | ||
| import org.elasticsearch.action.support.replication.ReplicationResponse; | ||
| import org.elasticsearch.action.support.replication.TransportReplicationAction; | ||
| import org.elasticsearch.cluster.action.shard.ShardStateAction; | ||
| import org.elasticsearch.cluster.project.ProjectResolver; | ||
| import org.elasticsearch.cluster.routing.IndexShardRoutingTable; | ||
| import org.elasticsearch.cluster.service.ClusterService; | ||
| import org.elasticsearch.common.io.stream.StreamInput; | ||
| import org.elasticsearch.common.settings.Settings; | ||
| import org.elasticsearch.core.Tuple; | ||
| import org.elasticsearch.index.shard.IndexShard; | ||
| import org.elasticsearch.index.shard.ShardId; | ||
| import org.elasticsearch.indices.IndicesService; | ||
| import org.elasticsearch.injection.guice.Inject; | ||
| import org.elasticsearch.logging.LogManager; | ||
|
|
@@ -32,6 +36,7 @@ | |
| import org.elasticsearch.transport.TransportService; | ||
|
|
||
| import java.io.IOException; | ||
| import java.util.Map; | ||
| import java.util.concurrent.Executor; | ||
|
|
||
| public class TransportShardRefreshAction extends TransportReplicationAction< | ||
|
|
@@ -46,6 +51,7 @@ public class TransportShardRefreshAction extends TransportReplicationAction< | |
| public static final String SOURCE_API = "api"; | ||
|
|
||
| private final Executor refreshExecutor; | ||
| private final ProjectResolver projectResolver; | ||
|
|
||
| @Inject | ||
| public TransportShardRefreshAction( | ||
|
|
@@ -55,7 +61,8 @@ public TransportShardRefreshAction( | |
| IndicesService indicesService, | ||
| ThreadPool threadPool, | ||
| ShardStateAction shardStateAction, | ||
| ActionFilters actionFilters | ||
| ActionFilters actionFilters, | ||
| ProjectResolver projectResolver | ||
| ) { | ||
| super( | ||
| settings, | ||
|
|
@@ -73,6 +80,7 @@ public TransportShardRefreshAction( | |
| PrimaryActionExecution.RejectOnOverload, | ||
| ReplicaActionExecution.SubjectToCircuitBreaker | ||
| ); | ||
| this.projectResolver = projectResolver; | ||
| // registers the unpromotable version of shard refresh action | ||
| new TransportUnpromotableShardRefreshAction( | ||
| clusterService, | ||
|
|
@@ -104,6 +112,27 @@ protected void shardOperationOnPrimary( | |
| })); | ||
| } | ||
|
|
||
| // We are here because there was mismatch between the SplitShardCountSummary in the request | ||
|
Contributor
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. Should this comment be on the method in the super class?
Contributor
Author
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, that should make it more clear. |
||
| // and that on the primary shard node. We assume that the request is exactly 1 reshard split behind | ||
| // the current state. | ||
| @Override | ||
| protected Map<ShardId, BasicReplicationRequest> splitRequestOnPrimary(BasicReplicationRequest request) { | ||
| return ReplicationRequestSplitHelper.splitRequest( | ||
| request, | ||
| projectResolver.getProjectMetadata(clusterService.state()), | ||
| (targetShard, shardCountSummary) -> new BasicReplicationRequest(targetShard, shardCountSummary) | ||
| ); | ||
| } | ||
|
|
||
| @Override | ||
| protected Tuple<ReplicationResponse, Exception> combineSplitResponses( | ||
| BasicReplicationRequest originalRequest, | ||
| Map<ShardId, BasicReplicationRequest> splitRequests, | ||
| Map<ShardId, Tuple<ReplicationResponse, Exception>> responses | ||
| ) { | ||
| return ReplicationRequestSplitHelper.combineSplitResponses(originalRequest, splitRequests, responses); | ||
| } | ||
|
|
||
| @Override | ||
| protected void shardOperationOnReplica(ShardRefreshReplicaRequest request, IndexShard replica, ActionListener<ReplicaResult> listener) { | ||
| replica.externalRefresh(SOURCE_API, listener.safeMap(refreshResult -> { | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -403,11 +403,9 @@ private void executeBulkRequestsByShard( | |
| final List<BulkItemRequest> requests = entry.getValue(); | ||
|
|
||
| // Get effective shardCount for shardId and pass it on as parameter to new BulkShardRequest | ||
| var indexMetadata = project.index(shardId.getIndexName()); | ||
| SplitShardCountSummary reshardSplitShardCountSummary = SplitShardCountSummary.UNSET; | ||
| if (indexMetadata != null) { | ||
| reshardSplitShardCountSummary = SplitShardCountSummary.forIndexing(indexMetadata, shardId.getId()); | ||
| } | ||
| var indexMetadata = project.getIndexSafe(shardId.getIndex()); | ||
|
Contributor
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. Why do we need this?
Contributor
Author
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. This is to replace the commented code below. The indexMetadata cannot really be null at this point and we must have a valid SplitShardCountSummary to pass to the BulkShardRequest.
Contributor
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 remove the commented code before pushing?
Contributor
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. Does this change the behavior in any way? I can't really image it does but i want to check.
Contributor
Author
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. This is just to make sure we throw an assert if we do see null indexmetadata, which was not the case earlier. We never expected indexMetadata to be NULL in the first place so the behavior has not changed. I will remove commented code. |
||
| SplitShardCountSummary reshardSplitShardCountSummary = SplitShardCountSummary.forIndexing(indexMetadata, shardId.getId()); | ||
|
|
||
| BulkShardRequest bulkShardRequest = new BulkShardRequest( | ||
| shardId, | ||
| reshardSplitShardCountSummary, | ||
|
|
@@ -416,7 +414,7 @@ private void executeBulkRequestsByShard( | |
| bulkRequest.isSimulated() | ||
| ); | ||
|
|
||
| if (indexMetadata != null && indexMetadata.getInferenceFields().isEmpty() == false) { | ||
| if (indexMetadata.getInferenceFields().isEmpty() == false) { | ||
| bulkShardRequest.setInferenceFieldMap(indexMetadata.getInferenceFields()); | ||
| } | ||
| bulkShardRequest.waitForActiveShards(bulkRequest.waitForActiveShards()); | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -174,6 +174,7 @@ private void handleMultiGetOnUnpromotableShard( | |
| ShardId shardId = indexShard.shardId(); | ||
| if (request.refresh()) { | ||
| logger.trace("send refresh action for shard {}", shardId); | ||
| // TODO: Do we need to pass in shardCountSummary here ? | ||
|
Contributor
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. I guess we'd look at this while working on get? I think it's a stray todo in this PR though.
Contributor
Author
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. This is covered by ES-13508. Sorry should have mentioned it here. I think I have tickets for all the TODOs. |
||
| var refreshRequest = new BasicReplicationRequest(shardId); | ||
| refreshRequest.setParentTask(request.getParentTask()); | ||
| client.executeLocally( | ||
|
|
||
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.
This assumption will need to be revised in a follow up PR. I created ES-13413 for this.