Skip to content

Conversation

bcully
Copy link
Contributor

@bcully bcully commented Jan 31, 2025

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.

@bcully bcully added the WIP label Jan 31, 2025
@bcully bcully force-pushed the ES-10565 branch 6 times, most recently from 2b8d7f0 to 308092b Compare February 13, 2025 00:04
@bcully bcully added >non-issue :Distributed Indexing/Distributed A catch all label for anything in the Distributed Indexing Area. Please avoid if you can. and removed WIP labels Feb 13, 2025
@bcully bcully marked this pull request as ready for review February 13, 2025 15:37
@elasticsearchmachine elasticsearchmachine added the Team:Distributed Indexing Meta label for Distributed Indexing team label Feb 13, 2025
@elasticsearchmachine
Copy link
Collaborator

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.
Copy link
Contributor

@Tim-Brooks Tim-Brooks left a 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.

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.
Copy link
Contributor

@henningandersen henningandersen left a 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.

assert target == TargetShardState.DONE : "can only move source shard to DONE when all targets are DONE";
}

sourceShards[shardNum] = sourceShardState;
Copy link
Contributor

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.

Copy link
Contributor Author

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.

Copy link
Contributor Author

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;
Copy link
Contributor

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

will do.

Copy link
Contributor Author

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) {
Copy link
Contributor

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.

Copy link
Contributor Author

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done in 0e69a76

Copy link
Contributor

@Tim-Brooks Tim-Brooks left a 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.

Copy link
Contributor

@ankikuma ankikuma left a comment

Choose a reason for hiding this comment

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

Looks good Brendan!

@bcully bcully merged commit 08b16eb into elastic:main Mar 11, 2025
17 checks passed
@bcully bcully deleted the ES-10565 branch March 11, 2025 00:28
georgewallace pushed a commit to georgewallace/elasticsearch that referenced this pull request Mar 11, 2025
* 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.
albertzaharovits pushed a commit to albertzaharovits/elasticsearch that referenced this pull request Mar 13, 2025
* 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.
jfreden pushed a commit to jfreden/elasticsearch that referenced this pull request Mar 13, 2025
* 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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

:Distributed Indexing/Distributed A catch all label for anything in the Distributed Indexing Area. Please avoid if you can. >non-issue Team:Distributed Indexing Meta label for Distributed Indexing team v9.1.0

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants