Skip to content
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

Fix exception handling for global metadata upload #10889

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -364,6 +364,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 @@ -376,7 +378,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.writeAsync(
clusterState.metadata(),
Expand All @@ -403,7 +405,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() {
dhwanilpatel marked this conversation as resolved.
Show resolved Hide resolved
@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
Loading