This is an automated email from the ASF dual-hosted git repository.

morningman pushed a commit to branch branch-1.2-lts
in repository https://gitbox.apache.org/repos/asf/doris.git

commit 24e2d4747d78debe975d086b67cea016eb062cb7
Author: Mingyu Chen <morning...@163.com>
AuthorDate: Thu Apr 27 09:59:04 2023 +0800

    [fix](heartbeat) fix update BE last start time (#18962)
    
    Sometimes the LastStartTime info in show backends result is unchanged even 
if BE restart.
    This PR fix it
---
 be/src/agent/heartbeat_server.cpp                           |  2 +-
 .../src/main/java/org/apache/doris/system/Backend.java      | 11 ++++++++---
 .../java/org/apache/doris/system/BackendHbResponse.java     | 13 -------------
 .../src/main/java/org/apache/doris/system/HeartbeatMgr.java |  4 +---
 .../src/test/java/org/apache/doris/catalog/BackendTest.java |  6 +++---
 5 files changed, 13 insertions(+), 23 deletions(-)

diff --git a/be/src/agent/heartbeat_server.cpp 
b/be/src/agent/heartbeat_server.cpp
index 705f14ab9a..0cd55d5c83 100644
--- a/be/src/agent/heartbeat_server.cpp
+++ b/be/src/agent/heartbeat_server.cpp
@@ -48,7 +48,7 @@ void HeartbeatServer::heartbeat(THeartbeatResult& 
heartbeat_result,
                           << "host:" << master_info.network_address.hostname
                           << ", port:" << master_info.network_address.port
                           << ", cluster id:" << master_info.cluster_id
-                          << ", counter:" << google::COUNTER;
+                          << ", counter:" << google::COUNTER << ", BE start 
time: " << _be_epoch;
 
     // do heartbeat
     Status st = _heartbeat(master_info);
diff --git a/fe/fe-core/src/main/java/org/apache/doris/system/Backend.java 
b/fe/fe-core/src/main/java/org/apache/doris/system/Backend.java
index 7868b50dab..32e8da5d19 100644
--- a/fe/fe-core/src/main/java/org/apache/doris/system/Backend.java
+++ b/fe/fe-core/src/main/java/org/apache/doris/system/Backend.java
@@ -26,6 +26,7 @@ import org.apache.doris.common.FeConstants;
 import org.apache.doris.common.io.Text;
 import org.apache.doris.common.io.Writable;
 import org.apache.doris.common.util.PrintableMap;
+import org.apache.doris.common.util.TimeUtils;
 import org.apache.doris.persist.gson.GsonUtils;
 import org.apache.doris.resource.Tag;
 import org.apache.doris.system.HeartbeatResponse.HbStatus;
@@ -631,6 +632,7 @@ public class Backend implements Writable {
     @Override
     public String toString() {
         return "Backend [id=" + id + ", host=" + host + ", heartbeatPort=" + 
heartbeatPort + ", alive=" + isAlive.get()
+                + ", lastStartTime=" + 
TimeUtils.longToTimeString(lastStartTime)
                 + ", tags: " + tagMap + "]";
     }
 
@@ -705,12 +707,15 @@ public class Backend implements Writable {
             if (!isAlive.get()) {
                 isChanged = true;
                 this.lastStartTime = hbResponse.getBeStartTime();
-                LOG.info("{} is alive, last start time: {}", this.toString(), 
hbResponse.getBeStartTime());
+                LOG.info("{} is back to alive", this.toString());
                 this.isAlive.set(true);
-            } else if (this.lastStartTime <= 0) {
-                this.lastStartTime = hbResponse.getBeStartTime();
             }
 
+            if (this.lastStartTime != hbResponse.getBeStartTime() && 
hbResponse.getBeStartTime() > 0) {
+                LOG.info("{} update last start time to {}", this.toString(), 
hbResponse.getBeStartTime());
+                this.lastStartTime = hbResponse.getBeStartTime();
+                isChanged = true;
+            }
             heartbeatErrMsg = "";
             this.heartbeatFailureCounter = 0;
         } else {
diff --git 
a/fe/fe-core/src/main/java/org/apache/doris/system/BackendHbResponse.java 
b/fe/fe-core/src/main/java/org/apache/doris/system/BackendHbResponse.java
index 8d2bac33c4..ceb8832d7f 100644
--- a/fe/fe-core/src/main/java/org/apache/doris/system/BackendHbResponse.java
+++ b/fe/fe-core/src/main/java/org/apache/doris/system/BackendHbResponse.java
@@ -41,19 +41,6 @@ public class BackendHbResponse extends HeartbeatResponse 
implements Writable {
         super(HeartbeatResponse.Type.BACKEND);
     }
 
-    public BackendHbResponse(long beId, int bePort, int httpPort, int brpcPort,
-            long hbTime, long beStartTime, String version) {
-        super(HeartbeatResponse.Type.BACKEND);
-        this.beId = beId;
-        this.status = HbStatus.OK;
-        this.bePort = bePort;
-        this.httpPort = httpPort;
-        this.brpcPort = brpcPort;
-        this.hbTime = hbTime;
-        this.beStartTime = beStartTime;
-        this.version = version;
-    }
-
     public BackendHbResponse(long beId, int bePort, int httpPort, int brpcPort,
             long hbTime, long beStartTime, String version, String nodeRole) {
         super(HeartbeatResponse.Type.BACKEND);
diff --git a/fe/fe-core/src/main/java/org/apache/doris/system/HeartbeatMgr.java 
b/fe/fe-core/src/main/java/org/apache/doris/system/HeartbeatMgr.java
index 234ebf3eec..04378e1876 100644
--- a/fe/fe-core/src/main/java/org/apache/doris/system/HeartbeatMgr.java
+++ b/fe/fe-core/src/main/java/org/apache/doris/system/HeartbeatMgr.java
@@ -250,9 +250,7 @@ public class HeartbeatMgr extends MasterDaemon {
                     if (tBackendInfo.isSetVersion()) {
                         version = tBackendInfo.getVersion();
                     }
-                    long beStartTime = tBackendInfo.isSetBeStartTime()
-                            ? tBackendInfo.getBeStartTime() : 
System.currentTimeMillis();
-                    // backend.updateOnce(bePort, httpPort, beRpcPort, 
brpcPort);
+                    long beStartTime = tBackendInfo.getBeStartTime();
                     String nodeRole = Tag.VALUE_MIX;
                     if (tBackendInfo.isSetBeNodeRole()) {
                         nodeRole = tBackendInfo.getBeNodeRole();
diff --git a/fe/fe-core/src/test/java/org/apache/doris/catalog/BackendTest.java 
b/fe/fe-core/src/test/java/org/apache/doris/catalog/BackendTest.java
index 463eee0a09..18d6246b07 100644
--- a/fe/fe-core/src/test/java/org/apache/doris/catalog/BackendTest.java
+++ b/fe/fe-core/src/test/java/org/apache/doris/catalog/BackendTest.java
@@ -39,6 +39,7 @@ import java.util.HashMap;
 import java.util.LinkedList;
 import java.util.List;
 import java.util.Map;
+import java.util.UUID;
 
 public class BackendTest {
     private Backend backend;
@@ -116,7 +117,7 @@ public class BackendTest {
     @Test
     public void testSerialization() throws Exception {
         // Write 100 objects to file
-        Path path = Paths.get("./backendTest");
+        Path path = Paths.get("./backendTest" + UUID.randomUUID());
         Files.createFile(path);
         DataOutputStream dos = new 
DataOutputStream(Files.newOutputStream(path));
 
@@ -200,8 +201,7 @@ public class BackendTest {
         back2.setTagMap(tagMap);
         Assert.assertFalse(back1.equals(back2));
 
-        Assert.assertEquals("Backend [id=1, host=a, heartbeatPort=1, 
alive=true, tags: {location=default}]",
-                back1.toString());
+        Assert.assertTrue(back1.toString().contains("tags: 
{location=default}"));
         Assert.assertEquals("{\"compute\" : \"c1\", \"location\" : \"l1\"}", 
back2.getTagMapString());
 
         // 3. delete files


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscr...@doris.apache.org
For additional commands, e-mail: commits-h...@doris.apache.org

Reply via email to