Skip to content

Add projectsDelta method to ClusterChangedEvent #127697

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

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

ywangd
Copy link
Member

@ywangd ywangd commented May 5, 2025

Similar to nodesDelta, the projectsDelta provides a centrailzed method to tell the added and removed projects so that cluster listeners/appliers do not need to compute it individually.

Note the delta currently does not have updated. This needs to wait till we stop eagerly creating ProjectMetadata.Builder in Metadata.Builder.

Similar to nodesDelta, the projectsDelta provides a centrailzed method
to tell the added and removed projects so that cluster
listeners/appliers do not need to compute it individually.

Note the delta currently does not have updated. This needs to wait till
we stop eagerly creating ProjectMetadata.Builder in Metadata.Builder.
@ywangd ywangd added >non-issue :Distributed Coordination/Cluster Coordination Cluster formation and cluster state publication, including cluster membership and fault detection. v9.1.0 labels May 5, 2025
@ywangd ywangd requested review from pxsalehi and nielsbauman May 5, 2025 07:03
@elasticsearchmachine elasticsearchmachine added the Team:Distributed Coordination Meta label for Distributed Coordination team label May 5, 2025
@elasticsearchmachine
Copy link
Collaborator

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

@elasticsearchmachine elasticsearchmachine added the serverless-linked Added by automation, don't add manually label May 5, 2025
Comment on lines 359 to 362
return new ProjectsDelta(
Collections.unmodifiableSet(Sets.difference(currentMetadata.projects().keySet(), previousMetadata.projects().keySet())),
Collections.unmodifiableSet(Sets.difference(previousMetadata.projects().keySet(), currentMetadata.projects().keySet()))
);
Copy link
Contributor

Choose a reason for hiding this comment

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

I'd prefer to construct the set differences manually, as we can construct both with one loop if we do it manually. You'll probably think this is a premature optimization, but I think the cost of the optimization is low and it's one less thing to consider optimizing later on.

Copy link
Member

Choose a reason for hiding this comment

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

+1. Also can we simplify that logic for DEFAULT? It seems looping through them and skipping default project in the loop is more readable.

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 still want that shortcut logic for single-project mode to avoid any performance impact in stateful. This wouldn't have a big impact anyway, but every bit counts IMO.

Copy link
Member Author

@ywangd ywangd May 6, 2025

Choose a reason for hiding this comment

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

Updated in fbe4b81. It should be a little more efficient since due to less call to Set#contains and less set constructions. But it essentially still has two 2 loops, 1st to initialize the removed set and 2nd to populate the added set. Please let me know whether it works for you or if you have better ideas.

we still want that shortcut logic for single-project mode

Yeah. I kept that. We don't need to skip the default project in the main loop since it should never be added or removed. I added assertions for it.

Copy link
Member Author

Choose a reason for hiding this comment

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

The assertions caused some test failures because they can create unreleasitc cluster state without the default project. Pushed e02d5d5 for fix. Let's see if there are more issues.

Copy link
Contributor

Choose a reason for hiding this comment

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

Ah yeah I had something else in mind but I just realized that doesn't work. You're right, we're still essentially looping twice over the data. Then I think I'd prefer your initial solution... 😅 That uses less memory as we need to copy the whole key set here. In the end it's just going to come down to memory vs. runtime, I guess. I think I'd be leaning towards saving some memory to avoid some GC work, but the differences will be minimal, so I'd be fine either way I think.

I think we can also add a shortcut for previousMetadata == currentMetadata, to skip some cluster state updates.


}

private static final ProjectsDelta EMPTY_PROJECT_DELTA = new ProjectsDelta(Set.of(), Set.of());
Copy link
Member

Choose a reason for hiding this comment

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

nit: why not move this into the record?

Copy link
Member Author

Choose a reason for hiding this comment

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

Addressed in fbe4b81

Comment on lines 359 to 362
return new ProjectsDelta(
Collections.unmodifiableSet(Sets.difference(currentMetadata.projects().keySet(), previousMetadata.projects().keySet())),
Collections.unmodifiableSet(Sets.difference(previousMetadata.projects().keySet(), currentMetadata.projects().keySet()))
);
Copy link
Member

Choose a reason for hiding this comment

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

+1. Also can we simplify that logic for DEFAULT? It seems looping through them and skipping default project in the loop is more readable.

@ywangd ywangd requested a review from pxsalehi May 6, 2025 05:43
@ywangd ywangd requested a review from nielsbauman May 6, 2025 06:47
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. >non-issue serverless-linked Added by automation, don't add manually 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