From bf8c5b791f1072d109044c15271ace494580b41c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=BF=9F=E6=88=90?= Date: Tue, 24 Nov 2020 16:36:10 +0800 Subject: [PATCH] show fe commit hash on proc --- .../doris/common/proc/FrontendsProcNode.java | 4 ++- .../http/rest/BootstrapFinishAction.java | 12 +++++++++ .../org/apache/doris/qe/GlobalVariable.java | 3 ++- .../org/apache/doris/system/Frontend.java | 6 +++++ .../doris/system/FrontendHbResponse.java | 9 ++++++- .../org/apache/doris/system/HeartbeatMgr.java | 14 ++++++---- .../apache/doris/system/HeartbeatMgrTest.java | 26 ++++++++++++++----- gensrc/script/gen_build_version.sh | 2 ++ 8 files changed, 61 insertions(+), 15 deletions(-) diff --git a/fe/fe-core/src/main/java/org/apache/doris/common/proc/FrontendsProcNode.java b/fe/fe-core/src/main/java/org/apache/doris/common/proc/FrontendsProcNode.java index 6d12be312f7d4c..dd2277edd47a71 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/common/proc/FrontendsProcNode.java +++ b/fe/fe-core/src/main/java/org/apache/doris/common/proc/FrontendsProcNode.java @@ -44,7 +44,7 @@ public class FrontendsProcNode implements ProcNodeInterface { public static final ImmutableList TITLE_NAMES = new ImmutableList.Builder() .add("Name").add("IP").add("HostName").add("EditLogPort").add("HttpPort").add("QueryPort").add("RpcPort") .add("Role").add("IsMaster").add("ClusterId").add("Join").add("Alive") - .add("ReplayedJournalId").add("LastHeartbeat").add("IsHelper").add("ErrMsg") + .add("ReplayedJournalId").add("LastHeartbeat").add("IsHelper").add("ErrMsg").add("Version") .build(); public static final int HOSTNAME_INDEX = 2; @@ -126,6 +126,8 @@ public static void getFrontendsInfo(Catalog catalog, List> infos) { info.add(fe.getHeartbeatErrMsg()); + info.add(fe.getVersion()); + infos.add(info); } } diff --git a/fe/fe-core/src/main/java/org/apache/doris/http/rest/BootstrapFinishAction.java b/fe/fe-core/src/main/java/org/apache/doris/http/rest/BootstrapFinishAction.java index eee998c1c2d123..7af15429eec000 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/http/rest/BootstrapFinishAction.java +++ b/fe/fe-core/src/main/java/org/apache/doris/http/rest/BootstrapFinishAction.java @@ -29,6 +29,7 @@ import com.google.gson.Gson; import io.netty.handler.codec.http.HttpMethod; +import org.apache.doris.common.Version; /* * fe_host:fe_http_port/api/bootstrap @@ -43,6 +44,7 @@ public class BootstrapFinishAction extends RestBaseAction { public static final String REPLAYED_JOURNAL_ID = "replayedJournalId"; public static final String QUERY_PORT = "queryPort"; public static final String RPC_PORT = "rpcPort"; + public static final String VERSION = "version"; public BootstrapFinishAction(ActionController controller) { super(controller); @@ -92,6 +94,7 @@ public void execute(BaseRequest request, BaseResponse response) throws DdlExcept result.setMaxReplayedJournal(replayedJournalId); result.setQueryPort(Config.query_port); result.setRpcPort(Config.rpc_port); + result.setVersion(Version.DORIS_BUILD_VERSION + "-" + Version.DORIS_BUILD_SHORT_HASH); } } } else { @@ -108,6 +111,7 @@ public static class BootstrapResult extends RestBaseResult { private long replayedJournalId = 0; private int queryPort = 0; private int rpcPort = 0; + private String version = ""; public BootstrapResult() { super(); @@ -141,6 +145,14 @@ public int getRpcPort() { return rpcPort; } + public String getVersion() { + return version; + } + + public void setVersion(String version) { + this.version = version; + } + @Override public String toJson() { Gson gson = new Gson(); diff --git a/fe/fe-core/src/main/java/org/apache/doris/qe/GlobalVariable.java b/fe/fe-core/src/main/java/org/apache/doris/qe/GlobalVariable.java index 0739d983e665f6..a6767ea9af7033 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/qe/GlobalVariable.java +++ b/fe/fe-core/src/main/java/org/apache/doris/qe/GlobalVariable.java @@ -43,7 +43,8 @@ public final class GlobalVariable { public static final String PERFORMANCE_SCHEMA = "performance_schema"; @VariableMgr.VarAttr(name = VERSION_COMMENT, flag = VariableMgr.READ_ONLY) - public static String versionComment = "Doris version " + Version.DORIS_BUILD_VERSION; + public static String versionComment = "Doris version " + + Version.DORIS_BUILD_VERSION + "-" + Version.DORIS_BUILD_SHORT_HASH; @VariableMgr.VarAttr(name = VERSION, flag = VariableMgr.READ_ONLY) public static String version = "5.1.0"; diff --git a/fe/fe-core/src/main/java/org/apache/doris/system/Frontend.java b/fe/fe-core/src/main/java/org/apache/doris/system/Frontend.java index 7ba7c1072eacd1..f0172d642e6066 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/system/Frontend.java +++ b/fe/fe-core/src/main/java/org/apache/doris/system/Frontend.java @@ -33,6 +33,7 @@ public class Frontend implements Writable { private String nodeName; private String host; private int editLogPort; + private String version; private int queryPort; private int rpcPort; @@ -60,6 +61,10 @@ public FrontendNodeType getRole() { public String getHost() { return this.host; } + + public String getVersion() { + return version; + } public String getNodeName() { return nodeName; @@ -103,6 +108,7 @@ public boolean handleHbResponse(FrontendHbResponse hbResponse) { boolean isChanged = false; if (hbResponse.getStatus() == HbStatus.OK) { isAlive = true; + version = hbResponse.getVersion(); queryPort = hbResponse.getQueryPort(); rpcPort = hbResponse.getRpcPort(); replayedJournalId = hbResponse.getReplayedJournalId(); diff --git a/fe/fe-core/src/main/java/org/apache/doris/system/FrontendHbResponse.java b/fe/fe-core/src/main/java/org/apache/doris/system/FrontendHbResponse.java index d22b4f901ee590..f9b6dbd9cf4f26 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/system/FrontendHbResponse.java +++ b/fe/fe-core/src/main/java/org/apache/doris/system/FrontendHbResponse.java @@ -34,12 +34,13 @@ public class FrontendHbResponse extends HeartbeatResponse implements Writable { private int queryPort; private int rpcPort; private long replayedJournalId; + private String version; public FrontendHbResponse() { super(HeartbeatResponse.Type.FRONTEND); } - public FrontendHbResponse(String name, int queryPort, int rpcPort, long replayedJournalId, long hbTime) { + public FrontendHbResponse(String name, int queryPort, int rpcPort, long replayedJournalId, long hbTime, String version) { super(HeartbeatResponse.Type.FRONTEND); this.status = HbStatus.OK; this.name = name; @@ -47,6 +48,7 @@ public FrontendHbResponse(String name, int queryPort, int rpcPort, long replayed this.rpcPort = rpcPort; this.replayedJournalId = replayedJournalId; this.hbTime = hbTime; + this.version = version; } public FrontendHbResponse(String name, String errMsg) { @@ -72,6 +74,10 @@ public long getReplayedJournalId() { return replayedJournalId; } + public String getVersion() { + return version; + } + public static FrontendHbResponse read(DataInput in) throws IOException { FrontendHbResponse result = new FrontendHbResponse(); result.readFields(in); @@ -101,6 +107,7 @@ public String toString() { StringBuilder sb = new StringBuilder(); sb.append(super.toString()); sb.append(", name: ").append(name); + sb.append(", version: ").append(version); sb.append(", queryPort: ").append(queryPort); sb.append(", rpcPort: ").append(rpcPort); sb.append(", replayedJournalId: ").append(replayedJournalId); 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 cb63632034a874..cd5da57c8af496 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 @@ -23,6 +23,7 @@ import org.apache.doris.common.Config; import org.apache.doris.common.FeConstants; import org.apache.doris.common.ThreadPoolManager; +import org.apache.doris.common.Version; import org.apache.doris.common.util.MasterDaemon; import org.apache.doris.common.util.Util; import org.apache.doris.http.rest.BootstrapFinishAction; @@ -153,7 +154,7 @@ protected void runAfterCatalogReady() { // we also add a 'mocked' master Frontends heartbeat response to synchronize master info to other Frontends. hbPackage.addHbResponse(new FrontendHbResponse(masterFeNodeName, Config.query_port, Config.rpc_port, Catalog.getCurrentCatalog().getEditLog().getMaxJournalId(), - System.currentTimeMillis())); + System.currentTimeMillis(), Version.DORIS_BUILD_VERSION + "-" + Version.DORIS_BUILD_SHORT_HASH)); // write edit log Catalog.getCurrentCatalog().getEditLog().logHeartbeat(hbPackage); @@ -190,7 +191,7 @@ private boolean handleHbResponse(HeartbeatResponse response, boolean isReplay) { FsBroker broker = Catalog.getCurrentCatalog().getBrokerMgr().getBroker( hbResponse.getName(), hbResponse.getHost(), hbResponse.getPort()); if (broker != null) { - boolean isChanged = broker.handleHbResponse(hbResponse); + boolean isChanged = broker.handleHbResponse(hbResponse); if (hbResponse.getStatus() != HbStatus.OK) { // invalid all connections cached in ClientPool ClientPool.brokerPool.clearPool(new TNetworkAddress(broker.ip, broker.port)); @@ -281,7 +282,8 @@ public HeartbeatResponse call() { // heartbeat to self if (Catalog.getCurrentCatalog().isReady()) { return new FrontendHbResponse(fe.getNodeName(), Config.query_port, Config.rpc_port, - Catalog.getCurrentCatalog().getReplayedJournalId(), System.currentTimeMillis()); + Catalog.getCurrentCatalog().getReplayedJournalId(), System.currentTimeMillis(), + Version.DORIS_BUILD_VERSION + "-" + Version.DORIS_BUILD_SHORT_HASH); } else { return new FrontendHbResponse(fe.getNodeName(), "not ready"); } @@ -310,8 +312,9 @@ public HeartbeatResponse call() { long replayedJournalId = root.getLong(BootstrapFinishAction.REPLAYED_JOURNAL_ID); int queryPort = root.getInt(BootstrapFinishAction.QUERY_PORT); int rpcPort = root.getInt(BootstrapFinishAction.RPC_PORT); + String version = root.getString(BootstrapFinishAction.VERSION); return new FrontendHbResponse(fe.getNodeName(), queryPort, rpcPort, replayedJournalId, - System.currentTimeMillis()); + System.currentTimeMillis(), version == null ? "unknown" : version); } } else if (root.has("code")) { // new return @@ -323,8 +326,9 @@ public HeartbeatResponse call() { long replayedJournalId = dataObj.getLong(BootstrapFinishAction.REPLAYED_JOURNAL_ID); int queryPort = dataObj.getInt(BootstrapFinishAction.QUERY_PORT); int rpcPort = dataObj.getInt(BootstrapFinishAction.RPC_PORT); + // TODO(wb) support new return for version here return new FrontendHbResponse(fe.getNodeName(), queryPort, rpcPort, replayedJournalId, - System.currentTimeMillis()); + System.currentTimeMillis(), "unknown"); } } else { throw new Exception("invalid return value: " + result); diff --git a/fe/fe-core/src/test/java/org/apache/doris/system/HeartbeatMgrTest.java b/fe/fe-core/src/test/java/org/apache/doris/system/HeartbeatMgrTest.java index fc8a1debcd1f7a..bb2aaa010e76ae 100644 --- a/fe/fe-core/src/test/java/org/apache/doris/system/HeartbeatMgrTest.java +++ b/fe/fe-core/src/test/java/org/apache/doris/system/HeartbeatMgrTest.java @@ -70,12 +70,23 @@ public void setUp() { public void testFrontendHbHandler() { new MockUp() { @Mock - public String getResultForUrl(String urlStr, String encodedAuthInfo, int connectTimeoutMs, - int readTimeoutMs) { + public String getResultForUrl(String urlStr, String encodedAuthInfo, + int connectTimeoutMs, int readTimeoutMs) { + if (urlStr.contains("192.168.1.1")) { - return "{\"replayedJournalId\":191224,\"queryPort\":9131,\"rpcPort\":9121,\"status\":\"OK\",\"msg\":\"Success\"}"; + return "{\"replayedJournalId\":191224," + + "\"queryPort\":9131," + + "\"rpcPort\":9121," + + "\"status\":\"OK\"," + + "\"msg\":\"Success\"," + + "\"version\":\"test\"}"; } else { - return "{\"replayedJournalId\":0,\"queryPort\":0,\"rpcPort\":0,\"status\":\"FAILED\",\"msg\":\"not ready\"}"; + return "{\"replayedJournalId\":0," + + "\"queryPort\":0," + + "\"rpcPort\":0," + + "\"status\":\"FAILED\"," + + "\"msg\":\"not ready\"," + + "\"version\":\"unknown\"}"; } } }; @@ -83,13 +94,14 @@ public String getResultForUrl(String urlStr, String encodedAuthInfo, int connect Frontend fe = new Frontend(FrontendNodeType.FOLLOWER, "test", "192.168.1.1", 9010); FrontendHeartbeatHandler handler = new FrontendHeartbeatHandler(fe, 12345, "abcd"); HeartbeatResponse response = handler.call(); - + Assert.assertTrue(response instanceof FrontendHbResponse); FrontendHbResponse hbResponse = (FrontendHbResponse) response; Assert.assertEquals(191224, hbResponse.getReplayedJournalId()); - Assert.assertEquals(9121, hbResponse.getRpcPort()); Assert.assertEquals(9131, hbResponse.getQueryPort()); + Assert.assertEquals(9121, hbResponse.getRpcPort()); Assert.assertEquals(HbStatus.OK, hbResponse.getStatus()); + Assert.assertEquals("test", hbResponse.getVersion()); Frontend fe2 = new Frontend(FrontendNodeType.FOLLOWER, "test2", "192.168.1.2", 9010); handler = new FrontendHeartbeatHandler(fe2, 12345, "abcd"); @@ -98,8 +110,8 @@ public String getResultForUrl(String urlStr, String encodedAuthInfo, int connect Assert.assertTrue(response instanceof FrontendHbResponse); hbResponse = (FrontendHbResponse) response; Assert.assertEquals(0, hbResponse.getReplayedJournalId()); - Assert.assertEquals(0, hbResponse.getRpcPort()); Assert.assertEquals(0, hbResponse.getQueryPort()); + Assert.assertEquals(0, hbResponse.getRpcPort()); Assert.assertEquals(HbStatus.BAD, hbResponse.getStatus()); } diff --git a/gensrc/script/gen_build_version.sh b/gensrc/script/gen_build_version.sh index 1cf5420bff3829..0b39001636dc2a 100755 --- a/gensrc/script/gen_build_version.sh +++ b/gensrc/script/gen_build_version.sh @@ -121,6 +121,7 @@ public class Version { public static final String DORIS_BUILD_VERSION = "${build_version}"; public static final String DORIS_BUILD_HASH = "${build_hash}"; + public static final String DORIS_BUILD_SHORT_HASH = "${build_short_hash}"; public static final String DORIS_BUILD_TIME = "${build_time}"; public static final String DORIS_BUILD_INFO = "${build_info}"; public static final String DORIS_JAVA_COMPILE_VERSION = "${java_version_str}"; @@ -128,6 +129,7 @@ public class Version { public static void main(String[] args) { System.out.println("doris_build_version: " + DORIS_BUILD_VERSION); System.out.println("doris_build_hash: " + DORIS_BUILD_HASH); + System.out.println("doris_build_short_hash: " + DORIS_BUILD_SHORT_HASH); System.out.println("doris_build_time: " + DORIS_BUILD_TIME); System.out.println("doris_build_info: " + DORIS_BUILD_INFO); System.out.println("doris_java_compile_version: " + DORIS_JAVA_COMPILE_VERSION);