From 65a04a2d7a4fbf43c04803ecd455e315bf7d85ec Mon Sep 17 00:00:00 2001 From: Arpit Bandejiya Date: Mon, 3 Jun 2024 16:10:23 +0530 Subject: [PATCH] refactoring in remote routing table service Signed-off-by: Arpit Bandejiya --- .../remote/RemoteRoutingTableService.java | 23 ++----------------- .../remote/RemoteClusterStateService.java | 8 +++---- 2 files changed, 6 insertions(+), 25 deletions(-) diff --git a/server/src/main/java/org/opensearch/cluster/routing/remote/RemoteRoutingTableService.java b/server/src/main/java/org/opensearch/cluster/routing/remote/RemoteRoutingTableService.java index 8dbcc7a5bad9f..81cf94f640163 100644 --- a/server/src/main/java/org/opensearch/cluster/routing/remote/RemoteRoutingTableService.java +++ b/server/src/main/java/org/opensearch/cluster/routing/remote/RemoteRoutingTableService.java @@ -237,7 +237,7 @@ private String getIndexRoutingFileName() { public CheckedRunnable getAsyncIndexMetadataReadAction( String uploadedFilename, Index index, - LatchedActionListener latchedActionListener) { + LatchedActionListener latchedActionListener) { int idx = uploadedFilename.lastIndexOf("/"); String blobFileName = uploadedFilename.substring(idx+1); BlobContainer blobContainer = blobStoreRepository.blobStore().blobContainer( BlobPath.cleanPath().add(uploadedFilename.substring(0,idx))); @@ -246,7 +246,7 @@ public CheckedRunnable getAsyncIndexMetadataReadAction( blobContainer, blobFileName, threadPool.executor(ThreadPool.Names.GENERIC), - ActionListener.wrap(response -> latchedActionListener.onResponse(new RemoteIndexRoutingResult(index.getName(), response.readIndexRoutingTable(index))), latchedActionListener::onFailure) + ActionListener.wrap(response -> latchedActionListener.onResponse(response.readIndexRoutingTable(index)), latchedActionListener::onFailure) ); } @@ -255,7 +255,6 @@ public void readAsync(BlobContainer blobContainer, String name, ExecutorService try { listener.onResponse(read(blobContainer, name)); } catch (Exception e) { - logger.error("routing table download failed : ", e); listener.onFailure(e); } }); @@ -307,22 +306,4 @@ public void start() { blobStoreRepository = (BlobStoreRepository) repository; } - public static class RemoteIndexRoutingResult { - String indexName; - IndexRoutingTable indexRoutingTable; - - public RemoteIndexRoutingResult(String indexName, IndexRoutingTable indexRoutingTable) { - this.indexName = indexName; - this.indexRoutingTable = indexRoutingTable; - } - - public String getIndexName() { - return indexName; - } - - public IndexRoutingTable getIndexRoutingTable() { - return indexRoutingTable; - } - } - } 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 7f5828eee7b29..c835fe83b3e06 100644 --- a/server/src/main/java/org/opensearch/gateway/remote/RemoteClusterStateService.java +++ b/server/src/main/java/org/opensearch/gateway/remote/RemoteClusterStateService.java @@ -985,7 +985,7 @@ private ClusterState readClusterStateInParallel( CountDownLatch latch = new CountDownLatch(totalReadTasks); List> asyncMetadataReadActions = new ArrayList<>(); List readResults = new ArrayList<>(); - List readIndexRoutingTableResults = new ArrayList<>(); + List readIndexRoutingTableResults = new ArrayList<>(); List exceptionList = Collections.synchronizedList(new ArrayList<>(totalReadTasks)); LatchedActionListener listener = new LatchedActionListener<>( @@ -1012,7 +1012,7 @@ private ClusterState readClusterStateInParallel( ); } - LatchedActionListener routingTableLatchedActionListener = new LatchedActionListener<>( + LatchedActionListener routingTableLatchedActionListener = new LatchedActionListener<>( ActionListener.wrap( response -> { logger.debug("Successfully read cluster state component from remote"); @@ -1187,8 +1187,8 @@ private ClusterState readClusterStateInParallel( } }); - readIndexRoutingTableResults.forEach(remoteIndexRoutingResult -> { - indicesRouting.put(remoteIndexRoutingResult.getIndexName(), remoteIndexRoutingResult.getIndexRoutingTable()); + readIndexRoutingTableResults.forEach(indexRoutingTable -> { + indicesRouting.put(indexRoutingTable.getIndex().getName(), indexRoutingTable); }); metadataBuilder.indices(indexMetadataMap);