From 2d1e940dd169a9fdc287ae7af619a98bc250891e Mon Sep 17 00:00:00 2001 From: waittting <491771532@qq.com> Date: Tue, 5 Jul 2022 10:50:38 +0800 Subject: [PATCH 1/4] When hb status not ok alse need sync to follower --- fe/fe-core/src/main/java/com/starrocks/catalog/FsBroker.java | 2 +- fe/fe-core/src/main/java/com/starrocks/system/ComputeNode.java | 3 +-- fe/fe-core/src/main/java/com/starrocks/system/Frontend.java | 2 +- 3 files changed, 3 insertions(+), 4 deletions(-) diff --git a/fe/fe-core/src/main/java/com/starrocks/catalog/FsBroker.java b/fe/fe-core/src/main/java/com/starrocks/catalog/FsBroker.java index 69dba4a75855e..b928168c9a088 100644 --- a/fe/fe-core/src/main/java/com/starrocks/catalog/FsBroker.java +++ b/fe/fe-core/src/main/java/com/starrocks/catalog/FsBroker.java @@ -82,10 +82,10 @@ public boolean handleHbResponse(BrokerHbResponse hbResponse) { } else { if (isAlive) { isAlive = false; - isChanged = true; } heartbeatErrMsg = hbResponse.getMsg() == null ? "Unknown error" : hbResponse.getMsg(); } + isChanged = true; } return isChanged; diff --git a/fe/fe-core/src/main/java/com/starrocks/system/ComputeNode.java b/fe/fe-core/src/main/java/com/starrocks/system/ComputeNode.java index dde566ac16952..2b4a15ba36f65 100644 --- a/fe/fe-core/src/main/java/com/starrocks/system/ComputeNode.java +++ b/fe/fe-core/src/main/java/com/starrocks/system/ComputeNode.java @@ -401,13 +401,12 @@ public boolean handleHbResponse(BackendHbResponse hbResponse) { this.heartbeatRetryTimes++; } else { if (isAlive.compareAndSet(true, false)) { - isChanged = true; LOG.info("{} is dead,", this.toString()); } - heartbeatErrMsg = hbResponse.getMsg() == null ? "Unknown error" : hbResponse.getMsg(); lastMissingHeartbeatTime = System.currentTimeMillis(); } + isChanged = true; } return isChanged; diff --git a/fe/fe-core/src/main/java/com/starrocks/system/Frontend.java b/fe/fe-core/src/main/java/com/starrocks/system/Frontend.java index 1f41725642180..a3c72873696ce 100644 --- a/fe/fe-core/src/main/java/com/starrocks/system/Frontend.java +++ b/fe/fe-core/src/main/java/com/starrocks/system/Frontend.java @@ -147,10 +147,10 @@ public boolean handleHbResponse(FrontendHbResponse hbResponse, boolean isReplay) } else { if (isAlive) { isAlive = false; - isChanged = true; } heartbeatErrMsg = hbResponse.getMsg() == null ? "Unknown error" : hbResponse.getMsg(); } + isChanged = true; } return isChanged; } From d0f34217b6a893a5f524d0b02e91b48e6eb3b13f Mon Sep 17 00:00:00 2001 From: waittting <491771532@qq.com> Date: Tue, 5 Jul 2022 16:26:04 +0800 Subject: [PATCH 2/4] Add case --- .../com/starrocks/system/ComputeNodeTest.java | 21 +++++++++++++++++++ .../com/starrocks/system/FrontendTest.java | 9 ++++++++ 2 files changed, 30 insertions(+) create mode 100644 fe/fe-core/src/test/java/com/starrocks/system/ComputeNodeTest.java diff --git a/fe/fe-core/src/test/java/com/starrocks/system/ComputeNodeTest.java b/fe/fe-core/src/test/java/com/starrocks/system/ComputeNodeTest.java new file mode 100644 index 0000000000000..3fe78a1349589 --- /dev/null +++ b/fe/fe-core/src/test/java/com/starrocks/system/ComputeNodeTest.java @@ -0,0 +1,21 @@ +// This file is licensed under the Elastic License 2.0. Copyright 2021-present, StarRocks Limited. +package com.starrocks.system; + +import org.junit.Assert; +import org.junit.Test; + +import com.starrocks.system.HeartbeatResponse.HbStatus; + +public class ComputeNodeTest { + + @Test + public void testHbStatusBadNeedSync() { + + BackendHbResponse hbResponse = new BackendHbResponse(); + hbResponse.status = HbStatus.BAD; + + ComputeNode node = new ComputeNode(); + boolean needSync = node.handleHbResponse(hbResponse); + Assert.assertTrue(needSync); + } +} diff --git a/fe/fe-core/src/test/java/com/starrocks/system/FrontendTest.java b/fe/fe-core/src/test/java/com/starrocks/system/FrontendTest.java index caf893d7a24c3..9a4c0c837cd94 100644 --- a/fe/fe-core/src/test/java/com/starrocks/system/FrontendTest.java +++ b/fe/fe-core/src/test/java/com/starrocks/system/FrontendTest.java @@ -16,4 +16,13 @@ public void testFeUpdate() { Assert.assertEquals("modifiedHost", fe.getHost()); Assert.assertTrue(fe.getEditLogPort() == 2110); } + + @Test + public void testHbStatusBadNeedSync() { + FrontendHbResponse hbResponse = new FrontendHbResponse("BAD", ""); + + Frontend fe = new Frontend(FrontendNodeType.FOLLOWER, "name", "testHost", 1110); + boolean needSync = fe.handleHbResponse(hbResponse, true); + Assert.assertTrue(needSync); + } } From 65b4533a6b628959eb1e58128dc64bba275ddc9b Mon Sep 17 00:00:00 2001 From: waittting <491771532@qq.com> Date: Wed, 13 Jul 2022 15:51:21 +0800 Subject: [PATCH 3/4] Add more comments --- fe/fe-core/src/main/java/com/starrocks/catalog/FsBroker.java | 5 +++++ .../src/main/java/com/starrocks/system/ComputeNode.java | 5 +++++ fe/fe-core/src/main/java/com/starrocks/system/Frontend.java | 5 +++++ 3 files changed, 15 insertions(+) diff --git a/fe/fe-core/src/main/java/com/starrocks/catalog/FsBroker.java b/fe/fe-core/src/main/java/com/starrocks/catalog/FsBroker.java index b928168c9a088..9434947c4ff3e 100644 --- a/fe/fe-core/src/main/java/com/starrocks/catalog/FsBroker.java +++ b/fe/fe-core/src/main/java/com/starrocks/catalog/FsBroker.java @@ -85,6 +85,11 @@ public boolean handleHbResponse(BrokerHbResponse hbResponse) { } heartbeatErrMsg = hbResponse.getMsg() == null ? "Unknown error" : hbResponse.getMsg(); } + // When master received hb info status not ok, the hb info also need to be synced to follower. + // Otherwise, the failed heartbeat information will not be synchronized to the follower. + // Since the failed heartbeat info also modifies fe's memory, (this.heartbeatRetryTimes++;) + // if it is not synchronized to the follower, + // this will cause the master and follower's metadata to be inconsistent isChanged = true; } diff --git a/fe/fe-core/src/main/java/com/starrocks/system/ComputeNode.java b/fe/fe-core/src/main/java/com/starrocks/system/ComputeNode.java index 2b4a15ba36f65..3a7d5e1003907 100644 --- a/fe/fe-core/src/main/java/com/starrocks/system/ComputeNode.java +++ b/fe/fe-core/src/main/java/com/starrocks/system/ComputeNode.java @@ -406,6 +406,11 @@ public boolean handleHbResponse(BackendHbResponse hbResponse) { heartbeatErrMsg = hbResponse.getMsg() == null ? "Unknown error" : hbResponse.getMsg(); lastMissingHeartbeatTime = System.currentTimeMillis(); } + // When master received hb info status not ok, the hb info also need to be synced to follower. + // Otherwise, the failed heartbeat information will not be synchronized to the follower. + // Since the failed heartbeat info also modifies fe's memory, (this.heartbeatRetryTimes++;) + // if it is not synchronized to the follower, + // this will cause the master and follower's metadata to be inconsistent isChanged = true; } diff --git a/fe/fe-core/src/main/java/com/starrocks/system/Frontend.java b/fe/fe-core/src/main/java/com/starrocks/system/Frontend.java index a3c72873696ce..0c30949cf459a 100644 --- a/fe/fe-core/src/main/java/com/starrocks/system/Frontend.java +++ b/fe/fe-core/src/main/java/com/starrocks/system/Frontend.java @@ -150,6 +150,11 @@ public boolean handleHbResponse(FrontendHbResponse hbResponse, boolean isReplay) } heartbeatErrMsg = hbResponse.getMsg() == null ? "Unknown error" : hbResponse.getMsg(); } + // When master received hb info status not ok, the hb info also need to be synced to follower. + // Otherwise, the failed heartbeat information will not be synchronized to the follower. + // Since the failed heartbeat info also modifies fe's memory, (this.heartbeatRetryTimes++;) + // if it is not synchronized to the follower, + // this will cause the master and follower's metadata to be inconsistent isChanged = true; } return isChanged; From dd289ca259bed65107619f2ccec363e3094d7aff Mon Sep 17 00:00:00 2001 From: waittting <491771532@qq.com> Date: Mon, 18 Jul 2022 09:34:06 +0800 Subject: [PATCH 4/4] Modify comments --- .../src/main/java/com/starrocks/catalog/FsBroker.java | 8 ++++---- .../src/main/java/com/starrocks/system/ComputeNode.java | 8 ++++---- .../src/main/java/com/starrocks/system/Frontend.java | 8 ++++---- 3 files changed, 12 insertions(+), 12 deletions(-) diff --git a/fe/fe-core/src/main/java/com/starrocks/catalog/FsBroker.java b/fe/fe-core/src/main/java/com/starrocks/catalog/FsBroker.java index 9434947c4ff3e..ecb726aad98b3 100644 --- a/fe/fe-core/src/main/java/com/starrocks/catalog/FsBroker.java +++ b/fe/fe-core/src/main/java/com/starrocks/catalog/FsBroker.java @@ -85,11 +85,11 @@ public boolean handleHbResponse(BrokerHbResponse hbResponse) { } heartbeatErrMsg = hbResponse.getMsg() == null ? "Unknown error" : hbResponse.getMsg(); } - // When master received hb info status not ok, the hb info also need to be synced to follower. - // Otherwise, the failed heartbeat information will not be synchronized to the follower. + // When the master receives an error heartbeat info which status not ok, + // this heartbeat info also need to be synced to follower. // Since the failed heartbeat info also modifies fe's memory, (this.heartbeatRetryTimes++;) - // if it is not synchronized to the follower, - // this will cause the master and follower's metadata to be inconsistent + // if this heartbeat is not synchronized to the follower, + // that will cause the Follower and master’s memory to be inconsistent isChanged = true; } diff --git a/fe/fe-core/src/main/java/com/starrocks/system/ComputeNode.java b/fe/fe-core/src/main/java/com/starrocks/system/ComputeNode.java index 3a7d5e1003907..bcf065a46a6f5 100644 --- a/fe/fe-core/src/main/java/com/starrocks/system/ComputeNode.java +++ b/fe/fe-core/src/main/java/com/starrocks/system/ComputeNode.java @@ -406,11 +406,11 @@ public boolean handleHbResponse(BackendHbResponse hbResponse) { heartbeatErrMsg = hbResponse.getMsg() == null ? "Unknown error" : hbResponse.getMsg(); lastMissingHeartbeatTime = System.currentTimeMillis(); } - // When master received hb info status not ok, the hb info also need to be synced to follower. - // Otherwise, the failed heartbeat information will not be synchronized to the follower. + // When the master receives an error heartbeat info which status not ok, + // this heartbeat info also need to be synced to follower. // Since the failed heartbeat info also modifies fe's memory, (this.heartbeatRetryTimes++;) - // if it is not synchronized to the follower, - // this will cause the master and follower's metadata to be inconsistent + // if this heartbeat is not synchronized to the follower, + // that will cause the Follower and master’s memory to be inconsistent isChanged = true; } diff --git a/fe/fe-core/src/main/java/com/starrocks/system/Frontend.java b/fe/fe-core/src/main/java/com/starrocks/system/Frontend.java index 0c30949cf459a..1182fcfb45b73 100644 --- a/fe/fe-core/src/main/java/com/starrocks/system/Frontend.java +++ b/fe/fe-core/src/main/java/com/starrocks/system/Frontend.java @@ -150,11 +150,11 @@ public boolean handleHbResponse(FrontendHbResponse hbResponse, boolean isReplay) } heartbeatErrMsg = hbResponse.getMsg() == null ? "Unknown error" : hbResponse.getMsg(); } - // When master received hb info status not ok, the hb info also need to be synced to follower. - // Otherwise, the failed heartbeat information will not be synchronized to the follower. + // When the master receives an error heartbeat info which status not ok, + // this heartbeat info also need to be synced to follower. // Since the failed heartbeat info also modifies fe's memory, (this.heartbeatRetryTimes++;) - // if it is not synchronized to the follower, - // this will cause the master and follower's metadata to be inconsistent + // if this heartbeat is not synchronized to the follower, + // that will cause the Follower and master’s memory to be inconsistent isChanged = true; } return isChanged;