mxsm commented on code in PR #5182: URL: https://github.com/apache/rocketmq/pull/5182#discussion_r980635426
########## 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: Hi @Oliverwqcwrw this Method handle handshake and transfer data. ``` if (diff >= AutoSwitchHAConnection.TRANSFER_HEADER_SIZE + bodySize || diff >= AutoSwitchHAConnection.HANDSHAKE_HEADER_SIZE + bodySize) ``` So this condition requires judging both cases: handshake and transfer message. And `diff >= AutoSwitchHAConnection.TRANSFER_HEADER_SIZE + bodySize` must condition in front of `diff >= AutoSwitchHAConnection.HANDSHAKE_HEADER_SIZE + bodySize` IMO, this condition can not remove one of 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: dev-unsubscr...@rocketmq.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org