Oliverwqcwrw commented on code in PR #5182:
URL: https://github.com/apache/rocketmq/pull/5182#discussion_r980646537


##########
store/src/main/java/org/apache/rocketmq/store/ha/autoswitch/AutoSwitchHAClient.java:
##########
@@ -444,27 +444,32 @@ protected boolean processReadResult(ByteBuffer 
byteBufferRead) {
             try {
                 while (true) {
                     int diff = byteBufferRead.position() - 
AutoSwitchHAClient.this.processPosition;
-                    if (diff >= AutoSwitchHAConnection.MSG_HEADER_SIZE) {
-                        int processPosition = 
AutoSwitchHAClient.this.processPosition;
-                        int masterState = 
byteBufferRead.getInt(processPosition + AutoSwitchHAConnection.MSG_HEADER_SIZE 
- 36);
-                        int bodySize = byteBufferRead.getInt(processPosition + 
AutoSwitchHAConnection.MSG_HEADER_SIZE - 32);
-                        long masterOffset = 
byteBufferRead.getLong(processPosition + AutoSwitchHAConnection.MSG_HEADER_SIZE 
- 28);
-                        int masterEpoch = 
byteBufferRead.getInt(processPosition + AutoSwitchHAConnection.MSG_HEADER_SIZE 
- 20);
-                        long masterEpochStartOffset = 
byteBufferRead.getLong(processPosition + AutoSwitchHAConnection.MSG_HEADER_SIZE 
- 16);
-                        long confirmOffset = 
byteBufferRead.getLong(processPosition + AutoSwitchHAConnection.MSG_HEADER_SIZE 
- 8);
-
+                    if (diff >= AutoSwitchHAConnection.HANDSHAKE_HEADER_SIZE) {
+                        final int processPosition = 
AutoSwitchHAClient.this.processPosition;
+                        int masterState = 
byteBufferRead.getInt(processPosition + 
AutoSwitchHAConnection.HANDSHAKE_HEADER_SIZE - 20);
+                        int bodySize = byteBufferRead.getInt(processPosition + 
AutoSwitchHAConnection.HANDSHAKE_HEADER_SIZE - 16);
+                        long masterOffset = 
byteBufferRead.getLong(processPosition + 
AutoSwitchHAConnection.HANDSHAKE_HEADER_SIZE - 12);
+                        int masterEpoch = 
byteBufferRead.getInt(processPosition + 
AutoSwitchHAConnection.HANDSHAKE_HEADER_SIZE - 4);
+                        long masterEpochStartOffset = 0;
+                        long confirmOffset = 0;
+                        // if master send transfer header data, set 
masterEpochStartOffset and confirmOffset value.
+                        if (masterState == 
HAConnectionState.TRANSFER.ordinal() && diff >= 
AutoSwitchHAConnection.TRANSFER_HEADER_SIZE) {
+                            masterEpochStartOffset = 
byteBufferRead.getLong(processPosition + 
AutoSwitchHAConnection.TRANSFER_HEADER_SIZE - 16);
+                            confirmOffset = 
byteBufferRead.getLong(processPosition + 
AutoSwitchHAConnection.TRANSFER_HEADER_SIZE - 8);
+                        }
                         if (masterState != 
AutoSwitchHAClient.this.currentState.ordinal()) {
-                            AutoSwitchHAClient.this.processPosition += 
AutoSwitchHAConnection.MSG_HEADER_SIZE + bodySize;
+                            int headerSize = masterState == 
HAConnectionState.TRANSFER.ordinal() ? 
AutoSwitchHAConnection.TRANSFER_HEADER_SIZE : 
AutoSwitchHAConnection.HANDSHAKE_HEADER_SIZE;
+                            AutoSwitchHAClient.this.processPosition += 
headerSize + bodySize;
                             AutoSwitchHAClient.this.waitForRunning(1);
                             LOGGER.error("State not matched, masterState:{}, 
slaveState:{}, bodySize:{}, offset:{}, masterEpoch:{}, 
masterEpochStartOffset:{}, confirmOffset:{}",
                                 masterState, 
AutoSwitchHAClient.this.currentState, bodySize, masterOffset, masterEpoch, 
masterEpochStartOffset, confirmOffset);
-                            return true;
+                            return false;
                         }
 
-                        if (diff >= (AutoSwitchHAConnection.MSG_HEADER_SIZE + 
bodySize)) {
+                        if (diff >= 
AutoSwitchHAConnection.TRANSFER_HEADER_SIZE + bodySize || diff >= 
AutoSwitchHAConnection.HANDSHAKE_HEADER_SIZE + bodySize) {

Review Comment:
   get it, If this condition is not added, `currentState` may be `TRANSFER`, 
but diff is less than `TRANSFER_HEADER_SIZE + body size`



-- 
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: dev-unsubscr...@rocketmq.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org

Reply via email to