Skip to content

Commit

Permalink
Fix exception handling for global metadata upload (opensearch-project…
Browse files Browse the repository at this point in the history
…#10889)

Signed-off-by: Dhwanil Patel <dhwanip@amazon.com>
  • Loading branch information
dhwanilpatel authored Oct 25, 2023
1 parent b5299f1 commit a890e51
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -369,6 +369,8 @@ public ClusterMetadataManifest writeIncrementalMetadata(
private String writeGlobalMetadata(ClusterState clusterState) throws IOException {

AtomicReference<String> result = new AtomicReference<String>();
AtomicReference<Exception> exceptionReference = new AtomicReference<Exception>();

final BlobContainer globalMetadataContainer = globalMetadataContainer(
clusterState.getClusterName().value(),
clusterState.metadata().clusterUUID()
Expand All @@ -381,7 +383,7 @@ private String writeGlobalMetadata(ClusterState clusterState) throws IOException
LatchedActionListener completionListener = new LatchedActionListener<>(ActionListener.wrap(resp -> {
logger.trace(String.format(Locale.ROOT, "GlobalMetadata uploaded successfully."));
result.set(globalMetadataContainer.path().buildAsString() + globalMetadataFilename);
}, ex -> { throw new GlobalMetadataTransferException(ex.getMessage(), ex); }), latch);
}, ex -> { exceptionReference.set(ex); }), latch);

GLOBAL_METADATA_FORMAT.writeAsyncWithUrgentPriority(
clusterState.metadata(),
Expand All @@ -408,7 +410,9 @@ private String writeGlobalMetadata(ClusterState clusterState) throws IOException
Thread.currentThread().interrupt();
throw exception;
}

if (exceptionReference.get() != null) {
throw new GlobalMetadataTransferException(exceptionReference.get().getMessage(), exceptionReference.get());
}
return result.get();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,13 @@ public void testWriteFullMetadataFailureForGlobalMetadata() throws IOException {
ArgumentCaptor<ActionListener<Void>> actionListenerArgumentCaptor = ArgumentCaptor.forClass(ActionListener.class);

doAnswer((i) -> {
actionListenerArgumentCaptor.getValue().onFailure(new RuntimeException("Cannot upload to remote"));
// For async write action listener will be called from different thread, replicating same behaviour here.
new Thread(new Runnable() {
@Override
public void run() {
actionListenerArgumentCaptor.getValue().onFailure(new RuntimeException("Cannot upload to remote"));
}
}).start();
return null;
}).when(container).asyncBlobUpload(any(WriteContext.class), actionListenerArgumentCaptor.capture());

Expand Down

0 comments on commit a890e51

Please sign in to comment.