From 987cb02c03e43dcbfce023499f96e561104f6e15 Mon Sep 17 00:00:00 2001 From: Bukhtawar Khan Date: Mon, 5 Aug 2024 23:15:45 +0530 Subject: [PATCH] Simplify apply diff Signed-off-by: Bukhtawar Khan --- .../gateway/remote/RemoteClusterStateService.java | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) diff --git a/server/src/main/java/org/opensearch/gateway/remote/RemoteClusterStateService.java b/server/src/main/java/org/opensearch/gateway/remote/RemoteClusterStateService.java index 44d1ee1aa70f1..d84e68e83d310 100644 --- a/server/src/main/java/org/opensearch/gateway/remote/RemoteClusterStateService.java +++ b/server/src/main/java/org/opensearch/gateway/remote/RemoteClusterStateService.java @@ -345,7 +345,6 @@ public RemoteClusterStateManifestInfo writeIncrementalMetadata( final DiffableUtils.MapDiff> routingTableIncrementalDiff = remoteRoutingTableService.getIndicesRoutingMapDiff(previousClusterState.getRoutingTable(), clusterState.getRoutingTable()); - Map> indexRoutingTableDiffs = routingTableIncrementalDiff.getDiffs(); routingTableIncrementalDiff.getDiffs().forEach((k, v) -> indicesRoutingToUpload.add(clusterState.getRoutingTable().index(k))); routingTableIncrementalDiff.getUpserts().forEach((k, v) -> indicesRoutingToUpload.add(v)); @@ -1020,7 +1019,7 @@ ClusterState readClusterStateInParallel( Map clusterStateCustomToRead, boolean readIndexRoutingTableDiff, boolean includeEphemeral - ) throws IOException { + ) { int totalReadTasks = indicesToRead.size() + customToRead.size() + (readCoordinationMetadata ? 1 : 0) + (readSettingsMetadata ? 1 : 0) + (readTemplatesMetadata ? 1 : 0) + (readDiscoveryNodes ? 1 : 0) + (readClusterBlocks ? 1 : 0) @@ -1295,11 +1294,7 @@ ClusterState readClusterStateInParallel( ); RoutingTableIncrementalDiff routingTableDiff = readIndexRoutingTableDiffResults.get(); if (routingTableDiff != null) { - routingTableDiff.getIndicesRouting().getDiffs().forEach((key, diff) -> { - IndexRoutingTable previousIndexRoutingTable = indicesRouting.get(key); - IndexRoutingTable updatedTable = diff.apply(previousIndexRoutingTable); - indicesRouting.put(key, updatedTable); - }); + routingTableDiff.apply(previousState.getRoutingTable()); } clusterStateBuilder.routingTable(new RoutingTable(manifest.getRoutingTableVersion(), indicesRouting)); @@ -1360,8 +1355,7 @@ public ClusterState getClusterStateForManifest( } - public ClusterState getClusterStateUsingDiff(ClusterMetadataManifest manifest, ClusterState previousState, String localNodeId) - throws IOException { + public ClusterState getClusterStateUsingDiff(ClusterMetadataManifest manifest, ClusterState previousState, String localNodeId) { assert manifest.getDiffManifest() != null : "Diff manifest null which is required for downloading cluster state"; ClusterStateDiffManifest diff = manifest.getDiffManifest(); List updatedIndices = diff.getIndicesUpdated().stream().map(idx -> {