ibessonov commented on code in PR #2390:
URL: https://github.com/apache/ignite-3/pull/2390#discussion_r1298179454
##########
modules/file-transfer/src/main/java/org/apache/ignite/internal/network/file/FileTransferServiceImpl.java:
##########
@@ -390,75 +414,64 @@ public CompletableFuture<List<Path>> download(String
sourceNodeConsistentId, Ide
.identifier(identifier)
.build();
- try {
- Path directory = createTransferDirectory(transferId);
-
- CompletableFuture<List<Path>> downloadedFiles =
fileReceiver.registerTransfer(
- sourceNodeConsistentId,
- transferId,
- directory
- )
- .thenApply(ignored -> {
- try {
- IgniteUtils.deleteIfExists(targetDir);
-
- Files.move(directory, targetDir,
StandardCopyOption.REPLACE_EXISTING, StandardCopyOption.ATOMIC_MOVE);
-
- try (Stream<Path> stream = Files.list(targetDir)) {
- return stream.collect(Collectors.toList());
- }
- } catch (IOException e) {
- throw new FileTransferException("Failed to move
downloaded files to target directory", e);
- }
- })
- .whenComplete((v, e) -> {
- if (e != null) {
- LOG.error("Failed to download files. Identifier:
{}", identifier, e);
- }
-
- IgniteUtils.deleteIfExists(directory);
- });
-
- return messagingService.invoke(sourceNodeConsistentId,
FILE_TRANSFER_CHANNEL, downloadRequest, responseTimeout)
- .thenApply(FileDownloadResponse.class::cast)
- .whenCompleteAsync((response, e) -> {
- if (e != null) {
- fileReceiver.cancelTransfer(transferId, e);
- } else if (response.error() != null) {
- fileReceiver.cancelTransfer(transferId,
buildException(response.error()));
- } else {
- fileReceiver.receiveFileHeaders(transferId,
response.headers());
- }
- }, executorService)
- .thenCompose(v -> downloadedFiles);
- } catch (Exception e) {
- return failedFuture(e);
- }
+ CompletableFuture<List<Path>> downloadedFiles = new
CompletableFuture<List<Path>>()
+ .whenComplete((v, e) ->
transferIdToConsumer.remove(transferId));
+
+ transferIdToConsumer.put(transferId, new
DownloadRequestConsumer(downloadedFiles, targetDir));
+
+ messagingService.invoke(sourceNodeConsistentId, FILE_TRANSFER_CHANNEL,
downloadRequest, responseTimeout)
+ .thenApply(FileDownloadResponse.class::cast)
+ .whenComplete((response, e) -> {
+ if (e != null) {
+ downloadedFiles.completeExceptionally(e);
+ } else if (response.error() != null) {
+
downloadedFiles.completeExceptionally(toException(response.error()));
+ }
+ });
+
+ return downloadedFiles;
}
@Override
public CompletableFuture<Void> upload(String targetNodeConsistentId,
Identifier identifier) {
return getFileProvider(identifier).files(identifier)
- .thenCompose(files -> {
- FileUploadRequest message =
messageFactory.fileUploadRequest()
- .identifier(identifier)
- .headers(fromPaths(messageFactory, files))
- .build();
+ .thenCompose(files ->
transferFilesToNode(targetNodeConsistentId, UUID.randomUUID(), identifier,
files));
+ }
+
+ private CompletableFuture<Void> transferFilesToNode(
+ String targetNodeConsistentId,
+ UUID transferId,
+ Identifier identifier,
+ List<Path> paths
+ ) {
+ if (paths.isEmpty()) {
+ return failedFuture(new FileTransferException("No files to
upload"));
Review Comment:
What error will a user see in this case? If it's an error message in a
server log, then it's a problem. If it's an exception message in his
application, then I'm fine with it
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]