Skip to content

Commit 1154086

Browse files
authored
Cache ProjectMetadata and RoutingTable in ProjectState (#128802)
We cache these fields in the constructor to avoid doing duplicate map lookups.
1 parent c3a1c57 commit 1154086

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

server/src/main/java/org/elasticsearch/cluster/ProjectState.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,24 +24,28 @@ public final class ProjectState {
2424

2525
private final ClusterState cluster;
2626
private final ProjectId project;
27+
private final ProjectMetadata projectMetadata;
28+
private final RoutingTable routingTable;
2729

2830
ProjectState(ClusterState clusterState, ProjectId projectId) {
2931
assert clusterState.metadata().hasProject(projectId)
3032
: "project-id [" + projectId + "] not found in " + clusterState.metadata().projects().keySet();
3133
this.cluster = clusterState;
3234
this.project = projectId;
35+
this.projectMetadata = clusterState.metadata().getProject(projectId);
36+
this.routingTable = clusterState.routingTable(projectId);
3337
}
3438

3539
public ProjectId projectId() {
3640
return this.project;
3741
}
3842

3943
public ProjectMetadata metadata() {
40-
return cluster().metadata().getProject(projectId());
44+
return projectMetadata;
4145
}
4246

4347
public RoutingTable routingTable() {
44-
return cluster().routingTable(projectId());
48+
return routingTable;
4549
}
4650

4751
public ClusterState cluster() {

0 commit comments

Comments
 (0)