-
Notifications
You must be signed in to change notification settings - Fork 2k
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
[WIP] Scale to Zero with Reader/Writer Separation #16726
Closed
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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
48 changes: 48 additions & 0 deletions
48
...rc/main/java/org/opensearch/action/admin/indices/scaleToZero/NodePreScaleSyncRequest.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,48 @@ | ||
/* | ||
* 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.admin.indices.scaleToZero; | ||
|
||
import org.opensearch.core.common.io.stream.StreamInput; | ||
import org.opensearch.core.common.io.stream.StreamOutput; | ||
import org.opensearch.core.index.shard.ShardId; | ||
import org.opensearch.transport.TransportRequest; | ||
|
||
import java.io.IOException; | ||
import java.util.List; | ||
|
||
public class NodePreScaleSyncRequest extends TransportRequest { | ||
private final String index; | ||
private final List<ShardId> shardIds; | ||
|
||
public NodePreScaleSyncRequest(String index, List<ShardId> shardIds) { | ||
this.index = index; | ||
this.shardIds = shardIds; | ||
} | ||
|
||
public NodePreScaleSyncRequest(StreamInput in) throws IOException { | ||
super(in); | ||
this.index = in.readString(); | ||
this.shardIds = in.readList(ShardId::new); | ||
} | ||
|
||
@Override | ||
public void writeTo(StreamOutput out) throws IOException { | ||
super.writeTo(out); | ||
out.writeString(index); | ||
out.writeList(shardIds); | ||
} | ||
|
||
public String getIndex() { | ||
return index; | ||
} | ||
|
||
public List<ShardId> getShardIds() { | ||
return shardIds; | ||
} | ||
} |
46 changes: 46 additions & 0 deletions
46
...c/main/java/org/opensearch/action/admin/indices/scaleToZero/NodePreScaleSyncResponse.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,46 @@ | ||
/* | ||
* 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.admin.indices.scaleToZero; | ||
|
||
import org.opensearch.cluster.node.DiscoveryNode; | ||
import org.opensearch.core.common.io.stream.StreamInput; | ||
import org.opensearch.core.common.io.stream.StreamOutput; | ||
import org.opensearch.core.transport.TransportResponse; | ||
|
||
import java.io.IOException; | ||
import java.util.List; | ||
|
||
public class NodePreScaleSyncResponse extends TransportResponse { | ||
private final DiscoveryNode node; | ||
private final List<ShardPreScaleSyncResponse> shardResponses; | ||
|
||
public NodePreScaleSyncResponse(DiscoveryNode node, List<ShardPreScaleSyncResponse> shardResponses) { | ||
this.node = node; | ||
this.shardResponses = shardResponses; | ||
} | ||
|
||
public NodePreScaleSyncResponse(StreamInput in) throws IOException { | ||
node = new DiscoveryNode(in); | ||
shardResponses = in.readList(ShardPreScaleSyncResponse::new); | ||
} | ||
|
||
@Override | ||
public void writeTo(StreamOutput out) throws IOException { | ||
node.writeTo(out); | ||
out.writeList(shardResponses); | ||
} | ||
|
||
public DiscoveryNode getNode() { | ||
return node; | ||
} | ||
|
||
public List<ShardPreScaleSyncResponse> getShardResponses() { | ||
return shardResponses; | ||
} | ||
} |
20 changes: 20 additions & 0 deletions
20
server/src/main/java/org/opensearch/action/admin/indices/scaleToZero/PreScaleSyncAction.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,20 @@ | ||
/* | ||
* 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.admin.indices.scaleToZero; | ||
|
||
import org.opensearch.action.ActionType; | ||
|
||
public class PreScaleSyncAction extends ActionType<PreScaleSyncResponse> { | ||
public static final PreScaleSyncAction INSTANCE = new PreScaleSyncAction(); | ||
public static final String NAME = "indices:admin/settings/pre_scale_sync"; | ||
|
||
private PreScaleSyncAction() { | ||
super(NAME, PreScaleSyncResponse::new); | ||
} | ||
} |
44 changes: 44 additions & 0 deletions
44
...er/src/main/java/org/opensearch/action/admin/indices/scaleToZero/PreScaleSyncRequest.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.admin.indices.scaleToZero; | ||
|
||
import org.opensearch.action.ActionRequest; | ||
import org.opensearch.action.ActionRequestValidationException; | ||
import org.opensearch.core.common.io.stream.StreamInput; | ||
import org.opensearch.core.common.io.stream.StreamOutput; | ||
|
||
import java.io.IOException; | ||
|
||
public class PreScaleSyncRequest extends ActionRequest { | ||
private final String index; | ||
|
||
public PreScaleSyncRequest(String index) { | ||
this.index = index; | ||
} | ||
|
||
public PreScaleSyncRequest(StreamInput in) throws IOException { | ||
super(in); | ||
this.index = in.readString(); | ||
} | ||
|
||
@Override | ||
public void writeTo(StreamOutput out) throws IOException { | ||
super.writeTo(out); | ||
out.writeString(index); | ||
} | ||
|
||
public String getIndex() { | ||
return index; | ||
} | ||
|
||
@Override | ||
public ActionRequestValidationException validate() { | ||
return null; | ||
} | ||
} |
90 changes: 90 additions & 0 deletions
90
...r/src/main/java/org/opensearch/action/admin/indices/scaleToZero/PreScaleSyncResponse.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,90 @@ | ||
/* | ||
* 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.admin.indices.scaleToZero; | ||
|
||
import org.opensearch.core.action.ActionResponse; | ||
import org.opensearch.core.common.io.stream.StreamInput; | ||
import org.opensearch.core.common.io.stream.StreamOutput; | ||
import org.opensearch.core.xcontent.ToXContent; | ||
import org.opensearch.core.xcontent.XContentBuilder; | ||
|
||
import java.io.IOException; | ||
import java.util.ArrayList; | ||
import java.util.Collection; | ||
|
||
public class PreScaleSyncResponse extends ActionResponse implements ToXContent { | ||
private final Collection<NodePreScaleSyncResponse> nodeResponses; | ||
private final String failureReason; | ||
private final boolean hasFailures; | ||
|
||
public PreScaleSyncResponse(Collection<NodePreScaleSyncResponse> responses) { | ||
this.nodeResponses = responses; | ||
this.hasFailures = responses.stream() | ||
.anyMatch(r -> r.getShardResponses().stream().anyMatch(s -> s.hasUncommittedOperations() || s.needsSync())); | ||
this.failureReason = buildFailureReason(); | ||
} | ||
|
||
public PreScaleSyncResponse(StreamInput in) throws IOException { | ||
this.nodeResponses = in.readList(NodePreScaleSyncResponse::new); | ||
this.hasFailures = in.readBoolean(); | ||
this.failureReason = in.readOptionalString(); | ||
} | ||
|
||
@Override | ||
public void writeTo(StreamOutput out) throws IOException { | ||
out.writeList(new ArrayList<>(nodeResponses)); // Convert Collection to List | ||
out.writeBoolean(hasFailures); | ||
out.writeOptionalString(failureReason); | ||
} | ||
|
||
public boolean hasFailures() { | ||
return hasFailures; | ||
} | ||
|
||
public String getFailureReason() { | ||
return failureReason; | ||
} | ||
|
||
private String buildFailureReason() { | ||
if (!hasFailures) { | ||
return null; | ||
} | ||
StringBuilder reason = new StringBuilder(); | ||
for (NodePreScaleSyncResponse nodeResponse : nodeResponses) { | ||
for (ShardPreScaleSyncResponse shardResponse : nodeResponse.getShardResponses()) { | ||
if (shardResponse.hasUncommittedOperations() || shardResponse.needsSync()) { | ||
reason.append("Shard ") | ||
.append(shardResponse.getShardId()) | ||
.append(" on node ") | ||
.append(nodeResponse.getNode()) | ||
.append(": "); | ||
if (shardResponse.hasUncommittedOperations()) { | ||
reason.append("has uncommitted operations "); | ||
} | ||
if (shardResponse.needsSync()) { | ||
reason.append("needs sync "); | ||
} | ||
reason.append("; "); | ||
} | ||
} | ||
} | ||
return reason.toString(); | ||
} | ||
|
||
@Override | ||
public XContentBuilder toXContent(XContentBuilder builder, ToXContent.Params params) throws IOException { | ||
builder.startObject(); | ||
builder.field("has_failures", hasFailures); | ||
if (failureReason != null) { | ||
builder.field("failure_reason", failureReason); | ||
} | ||
builder.endObject(); | ||
return builder; | ||
} | ||
} |
53 changes: 53 additions & 0 deletions
53
.../main/java/org/opensearch/action/admin/indices/scaleToZero/ShardPreScaleSyncResponse.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,53 @@ | ||
/* | ||
* 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.admin.indices.scaleToZero; | ||
|
||
import org.opensearch.core.common.io.stream.StreamInput; | ||
import org.opensearch.core.common.io.stream.StreamOutput; | ||
import org.opensearch.core.common.io.stream.Writeable; | ||
import org.opensearch.core.index.shard.ShardId; | ||
|
||
import java.io.IOException; | ||
|
||
public class ShardPreScaleSyncResponse implements Writeable { | ||
private final ShardId shardId; | ||
private final boolean needsSync; | ||
private final int uncommittedOperations; | ||
|
||
public ShardPreScaleSyncResponse(ShardId shardId, boolean needsSync, int uncommittedOperations) { | ||
this.shardId = shardId; | ||
this.needsSync = needsSync; | ||
this.uncommittedOperations = uncommittedOperations; | ||
} | ||
|
||
public ShardPreScaleSyncResponse(StreamInput in) throws IOException { | ||
this.shardId = new ShardId(in); | ||
this.needsSync = in.readBoolean(); | ||
this.uncommittedOperations = in.readVInt(); | ||
} | ||
|
||
@Override | ||
public void writeTo(StreamOutput out) throws IOException { | ||
shardId.writeTo(out); | ||
out.writeBoolean(needsSync); | ||
out.writeVInt(uncommittedOperations); | ||
} | ||
|
||
public ShardId getShardId() { | ||
return shardId; | ||
} | ||
|
||
public boolean needsSync() { | ||
return needsSync; | ||
} | ||
|
||
public boolean hasUncommittedOperations() { | ||
return uncommittedOperations > 0; | ||
} | ||
} |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
I will remove these settings once I have the PR ready for review, these changes are to ensure I can test scale to zero implementation with remote store and read write split enabled.