RongtongJin commented on code in PR #4367:
URL: https://github.com/apache/rocketmq/pull/4367#discussion_r881571351
##########
store/src/main/java/org/apache/rocketmq/store/ha/autoswitch/AutoSwitchHAConnection.java:
##########
@@ -277,28 +286,32 @@ protected boolean processReadResult(ByteBuffer
byteBufferRead) {
switch (slaveState) {
case HANDSHAKE:
if (diff >=
AutoSwitchHAClient.HANDSHAKE_HEADER_SIZE) {
+ final int headerSize =
AutoSwitchHAClient.HANDSHAKE_HEADER_SIZE;
Review Comment:
好像没必要定义一个本地变量
##########
store/src/main/java/org/apache/rocketmq/store/ha/autoswitch/AutoSwitchHAConnection.java:
##########
@@ -277,28 +286,32 @@ protected boolean processReadResult(ByteBuffer
byteBufferRead) {
switch (slaveState) {
case HANDSHAKE:
if (diff >=
AutoSwitchHAClient.HANDSHAKE_HEADER_SIZE) {
+ final int headerSize =
AutoSwitchHAClient.HANDSHAKE_HEADER_SIZE;
isSlaveSendHandshake = true;
- // Flag(SyncFromLastFile)
- long syncFromLastFileFlag =
byteBufferRead.getInt(readPosition + 4);
- if (syncFromLastFileFlag ==
AutoSwitchHAClient.SYNC_FROM_LAST_FILE) {
+ // Flag(isSyncFromLastFile)
+ short syncFromLastFileFlag =
byteBufferRead.getShort(readPosition + headerSize - 8);
+ if (syncFromLastFileFlag == 1) {
AutoSwitchHAConnection.this.isSyncFromLastFile = true;
- LOGGER.info("Slave request sync from
lastFile");
}
- // SlaveId
- AutoSwitchHAConnection.this.slaveId =
byteBufferRead.getLong(readPosition + 8);
+ // Flag(isAsyncLearner role)
+ short isAsyncLearner =
byteBufferRead.getShort(readPosition + headerSize - 6);
+ if (isAsyncLearner == 1) {
+
AutoSwitchHAConnection.this.isAsyncLearner = true;
+ }
// AddressLength
- int addressLength =
byteBufferRead.getInt(readPosition + 16);
- // Address
- if (diff >=
AutoSwitchHAClient.HANDSHAKE_HEADER_SIZE + addressLength) {
- final byte[] addressData = new
byte[addressLength];
- byteBufferRead.position(readPosition +
20);
- byteBufferRead.get(addressData);
-
AutoSwitchHAConnection.this.slaveAddress = new String(addressData);
- } else {
-
AutoSwitchHAConnection.this.slaveAddress = "";
+ int addressLength =
byteBufferRead.getInt(readPosition + headerSize - 4);
+ if (diff <
AutoSwitchHAClient.HANDSHAKE_HEADER_SIZE + addressLength) {
+ break;
}
Review Comment:
这个应该在最上面判断。不然上面白计算了
--
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]