Show fe commit hash on proc (#4943)

Show FE's commit has in SHOW PROC "/frontends" result.
This commit is contained in:
ccoffline
2020-11-28 09:50:48 +08:00
committed by GitHub
parent 0493eb172f
commit 3b56b601fb
8 changed files with 61 additions and 15 deletions

View File

@ -44,7 +44,7 @@ public class FrontendsProcNode implements ProcNodeInterface {
public static final ImmutableList<String> TITLE_NAMES = new ImmutableList.Builder<String>()
.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 class FrontendsProcNode implements ProcNodeInterface {
info.add(fe.getHeartbeatErrMsg());
info.add(fe.getVersion());
infos.add(info);
}
}

View File

@ -29,6 +29,7 @@ import com.google.common.base.Strings;
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 class BootstrapFinishAction extends RestBaseAction {
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 class BootstrapFinishAction extends RestBaseAction {
private long replayedJournalId = 0;
private int queryPort = 0;
private int rpcPort = 0;
private String version = "";
public BootstrapResult() {
super();
@ -141,6 +145,14 @@ public class BootstrapFinishAction extends RestBaseAction {
return rpcPort;
}
public String getVersion() {
return version;
}
public void setVersion(String version) {
this.version = version;
}
@Override
public String toJson() {
Gson gson = new Gson();

View File

@ -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";

View File

@ -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 class Frontend implements Writable {
public String getHost() {
return this.host;
}
public String getVersion() {
return version;
}
public String getNodeName() {
return nodeName;
@ -103,6 +108,7 @@ public class Frontend implements Writable {
boolean isChanged = false;
if (hbResponse.getStatus() == HbStatus.OK) {
isAlive = true;
version = hbResponse.getVersion();
queryPort = hbResponse.getQueryPort();
rpcPort = hbResponse.getRpcPort();
replayedJournalId = hbResponse.getReplayedJournalId();

View File

@ -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 class FrontendHbResponse extends HeartbeatResponse implements Writable {
this.rpcPort = rpcPort;
this.replayedJournalId = replayedJournalId;
this.hbTime = hbTime;
this.version = version;
}
public FrontendHbResponse(String name, String errMsg) {
@ -72,6 +74,10 @@ public class FrontendHbResponse extends HeartbeatResponse implements Writable {
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 class FrontendHbResponse extends HeartbeatResponse implements Writable {
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);

View File

@ -23,6 +23,7 @@ import org.apache.doris.common.ClientPool;
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 @@ public class HeartbeatMgr extends MasterDaemon {
// 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 @@ public class HeartbeatMgr extends MasterDaemon {
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 class HeartbeatMgr extends MasterDaemon {
// 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 class HeartbeatMgr extends MasterDaemon {
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 class HeartbeatMgr extends MasterDaemon {
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);

View File

@ -70,12 +70,23 @@ public class HeartbeatMgrTest {
public void testFrontendHbHandler() {
new MockUp<Util>() {
@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 class HeartbeatMgrTest {
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 class HeartbeatMgrTest {
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());
}