>From Murtadha Hubail <[email protected]>: Murtadha Hubail has submitted this change. ( https://asterix-gerrit.ics.uci.edu/c/asterixdb/+/11843 )
Change subject: [NO ISSUE][REP] Account for SSL socket data transfer behavior ...................................................................... [NO ISSUE][REP] Account for SSL socket data transfer behavior - user model changes: no - storage format changes: no - interface changes: no Details: - Account for the fact that a call to an SSLSocketChannel read operation can return 0 read bytes even in a blocking socket due to incomplete SSL packet. Change-Id: I0e1e69cba7336e0cfca5def870ab16334ce8c19f Reviewed-on: https://asterix-gerrit.ics.uci.edu/c/asterixdb/+/11064 Integration-Tests: Jenkins <[email protected]> Tested-by: Jenkins <[email protected]> Reviewed-by: Murtadha Hubail <[email protected]> Reviewed-by: Ali Alsuliman <[email protected]> (cherry picked from commit 94b1306e380dc923a964abf60900d55e545a4e4f) Reviewed-on: https://asterix-gerrit.ics.uci.edu/c/asterixdb/+/11843 --- M asterixdb/asterix-replication/src/main/java/org/apache/asterix/replication/management/NetworkingUtil.java 1 file changed, 26 insertions(+), 14 deletions(-) Approvals: Murtadha Hubail: Looks good to me, but someone else must approve Ali Alsuliman: Looks good to me, approved Jenkins: Verified; Verified Anon. E. Moose #1000171: diff --git a/asterixdb/asterix-replication/src/main/java/org/apache/asterix/replication/management/NetworkingUtil.java b/asterixdb/asterix-replication/src/main/java/org/apache/asterix/replication/management/NetworkingUtil.java index d572ba2..7f6439c 100644 --- a/asterixdb/asterix-replication/src/main/java/org/apache/asterix/replication/management/NetworkingUtil.java +++ b/asterixdb/asterix-replication/src/main/java/org/apache/asterix/replication/management/NetworkingUtil.java @@ -34,9 +34,13 @@ import org.apache.hyracks.api.comm.NetworkAddress; import org.apache.hyracks.api.network.ISocketChannel; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; public class NetworkingUtil { + private static final Logger LOGGER = LogManager.getLogger(); + private NetworkingUtil() { throw new AssertionError("This util class should not be initialized."); } @@ -56,25 +60,33 @@ public static void sendFile(FileChannel fileChannel, ISocketChannel socketChannel) throws IOException { long pos = 0; - long fileSize = fileChannel.size(); - long remainingBytes = fileSize; - long transferredBytes = 0; - - while ((transferredBytes += fileChannel.transferTo(pos, remainingBytes, socketChannel)) < fileSize) { - pos += transferredBytes; - remainingBytes -= transferredBytes; + long remainingBytes = fileChannel.size(); + try { + while (remainingBytes > 0) { + long sentBytes = fileChannel.transferTo(pos, remainingBytes, socketChannel); + pos += sentBytes; + remainingBytes -= sentBytes; + } + socketChannel.getSocketChannel().socket().getOutputStream().flush(); + } catch (Exception e) { + LOGGER.info("failed to send file; file size {}, pos {}, remainingBytes {}", fileChannel.size(), pos, + remainingBytes); } - socketChannel.getSocketChannel().socket().getOutputStream().flush(); } public static void downloadFile(FileChannel fileChannel, ISocketChannel socketChannel) throws IOException { + long remainingBytes = fileChannel.size(); long pos = 0; - long fileSize = fileChannel.size(); - long count = fileSize; - long numTransferred = 0; - while ((numTransferred += fileChannel.transferFrom(socketChannel, pos, count)) < fileSize) { - pos += numTransferred; - count -= numTransferred; + try { + while (remainingBytes > 0) { + long readBytes = fileChannel.transferFrom(socketChannel, pos, remainingBytes); + pos += readBytes; + remainingBytes -= readBytes; + } + } catch (Exception e) { + LOGGER.info("failed to download file; file size {}, pos {}, remainingBytes {}", fileChannel.size(), pos, + remainingBytes); + throw e; } } -- To view, visit https://asterix-gerrit.ics.uci.edu/c/asterixdb/+/11843 To unsubscribe, or for help writing mail filters, visit https://asterix-gerrit.ics.uci.edu/settings Gerrit-Project: asterixdb Gerrit-Branch: mad-hatter Gerrit-Change-Id: I0e1e69cba7336e0cfca5def870ab16334ce8c19f Gerrit-Change-Number: 11843 Gerrit-PatchSet: 5 Gerrit-Owner: Murtadha Hubail <[email protected]> Gerrit-Reviewer: Ali Alsuliman <[email protected]> Gerrit-Reviewer: Anon. E. Moose #1000171 Gerrit-Reviewer: Jenkins <[email protected]> Gerrit-Reviewer: Murtadha Hubail <[email protected]> Gerrit-MessageType: merged
