Skip to content

[WIP] Add index UUID invariant check in routing node #132443

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

Draft
wants to merge 9 commits into
base: main
Choose a base branch
from

Conversation

gmarouli
Copy link
Contributor

@gmarouli gmarouli commented Aug 5, 2025

In an effort to explore the possibility of atomic index renames, we introduced an invariant to the routing node to ensure that the unique uuids we encounter match the ones the shards are associated with.

This invariant check triggered a lot of test failures because a lot of tests fallback to _na_ as index UUID and they do not set unique UUID. In this PR:

  • We update these tests to create unique uuids
  • We replace the string literal _na_ with the constant when it refers to an index UUID so it's easier to track it.

@gmarouli gmarouli requested review from dakrone and nielsbauman August 5, 2025 16:21
@gmarouli gmarouli added >test Issues or PRs that are addressing/adding tests :Data Management/Indices APIs APIs to create and manage indices and templates labels Aug 5, 2025
@elasticsearchmachine elasticsearchmachine added the serverless-linked Added by automation, don't add manually label Aug 5, 2025
@@ -73,6 +78,7 @@ private RoutingNode(RoutingNode original) {
this.initializingShards = new LinkedHashSet<>(original.initializingShards);
this.startedShards = new LinkedHashSet<>(original.startedShards);
this.shardsByIndex = Maps.copyOf(original.shardsByIndex, HashSet::new);
this.indexUuids = original.shardsByIndex.keySet().stream().map(Index::getUUID).collect(Collectors.toSet());
Copy link
Contributor

Choose a reason for hiding this comment

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

Thinking out loud: I am worried this will have a noticeable performance impact. It looks like we construct this at least on every routing allocation (code path starts here). I am worried that we have to loop over all the indices on that node again (we're also doing that on the line above). Perhaps we could combine this line with the one above and create one loop that fills both sets?

I think the memory overhead of the Set is not that bad, as it's only the set itself that we hold in memory - the UUID strings themselves are already elsewhere on the heap. What do you think?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That is a good point, what we can do is to run it in the invariant loop. This will make it slower for tests but it won't affect production code that runs without the assertions

Copy link
Contributor

Choose a reason for hiding this comment

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

This is exactly what I had in mind, thanks!

Copy link
Contributor

Choose a reason for hiding this comment

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

Ah, I just now noticed that we also use this field here:

} else if (localRoutingNode == null || localRoutingNode.hasIndex(index.getUUID()) == false) {

(on our WIP branch for the rename). We'll have to keep an eye out to see if we still need that, to determine whether we need this field after all.

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.

I scanned through all the changes and they LGTM, but there are obviously a lot of changes, so I'm also partially relying on a passing CI here.

@gmarouli gmarouli requested a review from nielsbauman August 6, 2025 12:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
:Data Management/Indices APIs APIs to create and manage indices and templates serverless-linked Added by automation, don't add manually >test Issues or PRs that are addressing/adding tests v9.2.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants