shishkovilja commented on code in PR #12574:
URL: https://github.com/apache/ignite/pull/12574#discussion_r2694296672


##########
modules/core/src/main/java/org/apache/ignite/spi/discovery/tcp/TcpDiscoveryIoSession.java:
##########
@@ -192,37 +194,26 @@ <T> T readMessage() throws IgniteCheckedException, 
IOException {
                 if (read == -1)
                     throw new EOFException("Connection closed before message 
was fully read.");
 
-                if (msgBuf.position() > 0) {
-                    msgBuf.limit(msgBuf.position() + read);
-
-                    // We've stored an unprocessed tail before.
-                    msgBuf.rewind();
-                }
-                else
-                    msgBuf.limit(read);
+                msgBuf.limit(read);
 
                 finished = msgSer.readFrom(msg, msgReader);
 
-                // We rely on the fact that Discovery only sends next message 
upon receiving a receipt for the previous one.
+                // Server Discovery only sends next message to next Server 
upon receiving a receipt for the previous one.
                 // This behaviour guarantees that we never read a next message 
from the buffer right after the end of
-                // the previous message.
-                assert msgBuf.remaining() == 0 || !finished : "Some data was 
read from the socket but left unprocessed.";
-
-                if (finished)
-                    break;
+                // the previous message. But it is not guaranteed with Client 
Discovery where messages aren't acknowledged.
+                // Thus, we have to keep the uprocessed bytes read from the 
socket. It won't return them again.
+                if (msgBuf.remaining() > 0) {
+                    byte[] unprocessedReadTail = new byte[msgBuf.remaining()];
 
-                // We must keep the uprocessed bytes read from the socket. It 
won't return them again.
-                byte[] unprocessedTail = null;
+                    msgBuf.get(unprocessedReadTail, 0, msgBuf.remaining());
 
-                if (msgBuf.remaining() > 0) {
-                    unprocessedTail = new byte[msgBuf.remaining()];
-                    msgBuf.get(unprocessedTail, 0, msgBuf.remaining());
+                    in.acceptPrefixBuffer(unprocessedReadTail);
                 }
 
-                msgBuf.clear();
+                if (finished)
+                    break;
 
-                if (unprocessedTail != null)
-                    msgBuf.put(unprocessedTail);
+                msgBuf.clear();

Review Comment:
   Can be moved to start of cycle. Also, we can remove clearing of buffer just 
before cycle (line 189 now)



-- 
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]

Reply via email to