Skip to content

Conversation

@tvernum
Copy link
Contributor

@tvernum tvernum commented Mar 6, 2025

This migrates a number of calls of the form

metadata.getProject().getIndexSafe(index)

or

metadata.getProject().index(index)

to

metadata.indexMetadata(index)

or

metadata.findIndex(index)

This migrates a number of calls of the form

    metadata.getProject().getIndexSafe(index)

or

    metadata.getProject().index(index)

to

    metadata.indexMetadata(index)

or

    metadata.findIndex(index)
@tvernum tvernum added >refactoring :Distributed Coordination/Cluster Coordination Cluster formation and cluster state publication, including cluster membership and fault detection. v9.1.0 labels Mar 6, 2025
@tvernum tvernum requested a review from a team March 6, 2025 03:49
@elasticsearchmachine elasticsearchmachine added the Team:Distributed Coordination Meta label for Distributed Coordination team label Mar 6, 2025
@elasticsearchmachine
Copy link
Collaborator

Pinging @elastic/es-distributed-coordination (Team:Distributed Coordination)

Copy link
Contributor

@nielsbauman nielsbauman left a comment

Choose a reason for hiding this comment

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

Left one optional comment, other than that LGTM.

Comment on lines 234 to 236
for (ShardRouting shardRouting : routingNode) {
var indexMetadata = metadata.getProject().index(shardRouting.index());
var indexMetadata = metadata.indexMetadata(shardRouting.index());
var shardSize = clusterInfo.getShardSize(shardRouting, 0L);
assert indexMetadata != null;
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: in this case, I'd argue the assertion loses its value because a non-existent index (or project) would have already thrown an exception.

Copy link
Member

@ywangd ywangd left a comment

Choose a reason for hiding this comment

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

LGTM

Not for this PR: I wonder whether we should make these methods more consistent:

  1. ProjectMetadata#index
  2. ProjectMetadata#getIndexSafe
  3. Metadata#findIndex
  4. Metadata#indexMetadata

The issues I can see are:

  • Inconsistent naming style, e.g. getter vs builder pattern
  • Except 2, they aer not clear which ones are throwing on null value
  • 1 returns null while 3 returns Optional
  • 4 spells out the full indexMetadata despite the other 3 are also about index metadata

The result is that I have to check up their usages each time I need to use them or review a PR containing their usages. I think it would be great if they are renamed more consistently and more obviously.

@tvernum
Copy link
Contributor Author

tvernum commented Mar 7, 2025

Not for this PR: I wonder whether we should make these methods more consistent

It's come up before, and I think it makes sense. I'm not planning to tackle it, but it would be good for someone else to do so.

@tvernum tvernum enabled auto-merge (squash) March 7, 2025 05:00
@tvernum tvernum merged commit fb322dc into elastic:main Mar 7, 2025
17 checks passed
georgewallace pushed a commit to georgewallace/elasticsearch that referenced this pull request Mar 11, 2025
This migrates a number of calls of the form

    metadata.getProject().getIndexSafe(index)

or

    metadata.getProject().index(index)

to

    metadata.indexMetadata(index)

or

    metadata.findIndex(index)
costin pushed a commit to costin/elasticsearch that referenced this pull request Mar 15, 2025
This migrates a number of calls of the form

    metadata.getProject().getIndexSafe(index)

or

    metadata.getProject().index(index)

to

    metadata.indexMetadata(index)

or

    metadata.findIndex(index)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

:Distributed Coordination/Cluster Coordination Cluster formation and cluster state publication, including cluster membership and fault detection. >refactoring Team:Distributed Coordination Meta label for Distributed Coordination team v9.1.0

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants