-
Notifications
You must be signed in to change notification settings - Fork 25.6k
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
Changes from 1 commit
2adcb2d
fbe4b81
e02d5d5
bbda1f8
869a9e0
7dc1765
77f84f6
ad8c61b
07576e6
469cdd0
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -13,9 +13,11 @@ | |
| import org.elasticsearch.cluster.metadata.IndexGraveyard.IndexGraveyardDiff; | ||
| import org.elasticsearch.cluster.metadata.IndexMetadata; | ||
| import org.elasticsearch.cluster.metadata.Metadata; | ||
| import org.elasticsearch.cluster.metadata.ProjectId; | ||
| import org.elasticsearch.cluster.metadata.ProjectMetadata; | ||
| import org.elasticsearch.cluster.node.DiscoveryNodes; | ||
| import org.elasticsearch.cluster.routing.IndexRoutingTable; | ||
| import org.elasticsearch.common.util.set.Sets; | ||
| import org.elasticsearch.gateway.GatewayService; | ||
| import org.elasticsearch.index.Index; | ||
|
|
||
|
|
@@ -41,6 +43,8 @@ public class ClusterChangedEvent { | |
|
|
||
| private final DiscoveryNodes.Delta nodesDelta; | ||
|
|
||
| private final ProjectsDelta projectsDelta; | ||
|
|
||
| public ClusterChangedEvent(String source, ClusterState state, ClusterState previousState) { | ||
| Objects.requireNonNull(source, "source must not be null"); | ||
| Objects.requireNonNull(state, "state must not be null"); | ||
|
|
@@ -49,6 +53,7 @@ public ClusterChangedEvent(String source, ClusterState state, ClusterState previ | |
| this.state = state; | ||
| this.previousState = previousState; | ||
| this.nodesDelta = state.nodes().delta(previousState.nodes()); | ||
| this.projectsDelta = calculateProjectDelta(previousState.metadata(), state.metadata()); | ||
| } | ||
|
|
||
| /** | ||
|
|
@@ -237,6 +242,13 @@ public boolean nodesChanged() { | |
| return nodesRemoved() || nodesAdded(); | ||
| } | ||
|
|
||
| /** | ||
| * Returns the {@link ProjectsDelta} between the previous cluster state and the new cluster state. | ||
| */ | ||
| public ProjectsDelta projectDelta() { | ||
| return projectsDelta; | ||
| } | ||
|
|
||
| /** | ||
| * Determines whether or not the current cluster state represents an entirely | ||
| * new cluster, either when a node joins a cluster for the first time or when | ||
|
|
@@ -336,4 +348,26 @@ private List<Index> indicesDeletedFromTombstones() { | |
| .toList(); | ||
| } | ||
|
|
||
| private static ProjectsDelta calculateProjectDelta(Metadata previousMetadata, Metadata currentMetadata) { | ||
| if (previousMetadata.projects().size() == 1 | ||
| && previousMetadata.hasProject(ProjectId.DEFAULT) | ||
| && currentMetadata.projects().size() == 1 | ||
| && currentMetadata.hasProject(ProjectId.DEFAULT)) { | ||
| return EMPTY_PROJECT_DELTA; | ||
| } | ||
|
|
||
| return new ProjectsDelta( | ||
| Collections.unmodifiableSet(Sets.difference(currentMetadata.projects().keySet(), previousMetadata.projects().keySet())), | ||
| Collections.unmodifiableSet(Sets.difference(previousMetadata.projects().keySet(), currentMetadata.projects().keySet())) | ||
| ); | ||
|
||
|
|
||
| } | ||
|
|
||
| private static final ProjectsDelta EMPTY_PROJECT_DELTA = new ProjectsDelta(Set.of(), Set.of()); | ||
|
||
|
|
||
| public record ProjectsDelta(Set<ProjectId> added, Set<ProjectId> removed) { | ||
| public boolean isEmpty() { | ||
| return added.isEmpty() && removed.isEmpty(); | ||
| } | ||
| } | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.