-
Notifications
You must be signed in to change notification settings - Fork 25.6k
Introduce IndexReshardingMetadata #121360
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
Conversation
2b8d7f0
to
308092b
Compare
Pinging @elastic/es-distributed-indexing (Team:Distributed Indexing) |
This adds to IndexMetadata the persistent state we will need to track while a split is in progress. Nothing outside test code sets it yet, so it doesn't introduce any wire changes yet. Followups will consult this to make routing decisions and handle backward compatibility if the object is present in metadata.
server/src/main/java/org/elasticsearch/cluster/metadata/IndexReshardingMetadata.java
Outdated
Show resolved
Hide resolved
server/src/main/java/org/elasticsearch/cluster/metadata/IndexReshardingMetadata.java
Outdated
Show resolved
Hide resolved
server/src/main/java/org/elasticsearch/cluster/metadata/IndexReshardingMetadata.java
Outdated
Show resolved
Hide resolved
server/src/main/java/org/elasticsearch/cluster/metadata/IndexReshardingMetadata.java
Outdated
Show resolved
Hide resolved
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.
Looks pretty good to begin with. I'm glad you were able to implement the core serialization tests.
server/src/main/java/org/elasticsearch/cluster/metadata/IndexReshardingMetadata.java
Outdated
Show resolved
Hide resolved
server/src/main/java/org/elasticsearch/cluster/metadata/IndexReshardingMetadata.java
Outdated
Show resolved
Hide resolved
This refactors IndexReshardingMetadata to hold a sum type for persistent state that can be extended with new operations. For instance we will want to add a shrink operation in the future, or we may need to create a new version of split later. Making XContent support polymorphic data felt clunky - perhaps there is a different approach that I'm missing?
Previously it was using a discriminant field to control how to parse the rest of the metadata, which it then did by hand: { "operation": "split", ... } Now it uses a separate key for each kind of metadata, and uses ObjectParser's `declareExclusiveFieldSet` machinery to enforce that only one exists: { "split": { ... } } The down side is that the state field is no longer final, because we don't know which kind of state we have at construction time due to a limitation of the ConstructingObjectParser interface.
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.
Read through the non-test code, left a few comments, otherwise looks good.
server/src/main/java/org/elasticsearch/cluster/metadata/IndexReshardingMetadata.java
Outdated
Show resolved
Hide resolved
server/src/main/java/org/elasticsearch/cluster/metadata/IndexReshardingMetadata.java
Outdated
Show resolved
Hide resolved
server/src/main/java/org/elasticsearch/cluster/metadata/IndexReshardingMetadata.java
Outdated
Show resolved
Hide resolved
server/src/main/java/org/elasticsearch/cluster/metadata/IndexReshardingState.java
Outdated
Show resolved
Hide resolved
server/src/main/java/org/elasticsearch/cluster/metadata/IndexReshardingState.java
Show resolved
Hide resolved
server/src/main/java/org/elasticsearch/cluster/metadata/IndexReshardingState.java
Outdated
Show resolved
Hide resolved
assert target == TargetShardState.DONE : "can only move source shard to DONE when all targets are DONE"; | ||
} | ||
|
||
sourceShards[shardNum] = sourceShardState; |
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.
We should not mutate these objects. This is way too dangerous, since the index-metadata is expected to be immutable. Instead we should add a Builder
and use this to build a new IndexReshardingState
.
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.
Thanks, I agree this is worth doing now. I should admit that I haven't really put a lot of thought into the client API for this state yet, since I thought that would be easier to get right when we were building the consumers. I expect it to churn until we actually have the state machine built into the resharding process.
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.
Done in 0e69a76 (but the API is still just enough to support a unit test for the moment)
assert targetShardNum >= 0 && targetShardNum < targetShards.length : "target shardNum is out of bounds"; | ||
assert targetShards[targetShardNum].ordinal() + 1 == targetShardState.ordinal() : "invalid target shard state transition"; | ||
|
||
targetShards[targetShardNum] = targetShardState; |
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.
Similar to above, we should make this object immutable.
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.
will do.
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.
Done in 0e69a76
* @param shardNum a source shard index greater than or equal to 0 and less than the original shard count | ||
* @return an array of target shard states in order for the given shard | ||
*/ | ||
public TargetShardState[] getTargetStatesFor(int shardNum) { |
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 think we should either return a Collection of such states - or a Map<int, TargetShardState> to make the shard-id explicit.
I wonder if we even need to return this though or if we can add the methods needed to this class instead? Like the inProgress
method below, but related to a specific source shard.
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'll make this private and expose a targetsDone(int sourceShardIdx)
or similar instead for the unit test.
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.
Done in 0e69a76
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 looks fine to me with mostly minor comments.
server/src/main/java/org/elasticsearch/cluster/metadata/IndexReshardingMetadata.java
Outdated
Show resolved
Hide resolved
server/src/main/java/org/elasticsearch/cluster/metadata/IndexReshardingState.java
Show resolved
Hide resolved
Move constructors up; mark a toXContent @OverRide
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.
Looks good Brendan!
* Introduce IndexReshardingMetadata This adds to IndexMetadata the persistent state we will need to track while a split is in progress. Nothing outside test code sets it yet, so it doesn't introduce any wire changes yet. Followups will consult this to make routing decisions and handle backward compatibility if the object is present in metadata.
* Introduce IndexReshardingMetadata This adds to IndexMetadata the persistent state we will need to track while a split is in progress. Nothing outside test code sets it yet, so it doesn't introduce any wire changes yet. Followups will consult this to make routing decisions and handle backward compatibility if the object is present in metadata.
* Introduce IndexReshardingMetadata This adds to IndexMetadata the persistent state we will need to track while a split is in progress. Nothing outside test code sets it yet, so it doesn't introduce any wire changes yet. Followups will consult this to make routing decisions and handle backward compatibility if the object is present in metadata.
This adds to IndexMetadata the persistent state we will need to track while a split is in progress. Nothing outside test code sets it yet, so it doesn't introduce any wire changes yet.
Followups will consult this to make routing decisions and handle backward compatibility if the object is present in metadata.