Flaugh24 commented on code in PR #2390:
URL: https://github.com/apache/ignite-3/pull/2390#discussion_r1296114167
##########
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:
I would prefer to keep empty lists restricted to avoid confusion until we
really need support for this. Right now we are going to transfer only
deployment units. It's impossible to have a deployment unit without any files.
--
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]