Use BackendStatus to show BE's infomation in show backends; (#3713)

The infomation is displayed in JSON format.For example:
{"lastTabletReportTime":"2020-05-28 15:29:01"}
This commit is contained in:
WingC
2020-06-05 22:37:48 -05:00
committed by GitHub
parent 3b6a781862
commit a7bf006b51
5 changed files with 37 additions and 6 deletions

View File

@ -42,6 +42,7 @@ Explain:
9. Total Capacity represents total disk space. Total Capacity = AvailCapacity + DataUsedCapacity + other non-user data files take up space.
10. UsedPct represents the percentage of disk usage.
11. ErrMsg is used to display error messages when a heartbeat fails.
12. Status is used to display some Status information about BE in JSON format, including the last time that BE reported it's tablet.
## keyword
SHOW, BACKENDS

View File

@ -42,6 +42,7 @@ under the License.
9. TotalCapacity 表示总磁盘空间。TotalCapacity = AvailCapacity + DataUsedCapacity + 其他非用户数据文件占用空间。
10. UsedPct 表示磁盘已使用量百分比。
11. ErrMsg 用于显示心跳失败时的错误信息。
12. Status 用于以 JSON 格式显示BE的一些状态信息, 目前包括最后一次BE汇报其tablet的时间信息。
## keyword
SHOW, BACKENDS

View File

@ -17,6 +17,7 @@
package org.apache.doris.common.proc;
import com.google.gson.Gson;
import org.apache.doris.alter.DecommissionBackendJob.DecommissionType;
import org.apache.doris.catalog.Catalog;
import org.apache.doris.cluster.Cluster;
@ -51,7 +52,7 @@ public class BackendsProcDir implements ProcDirInterface {
.add("BePort").add("HttpPort").add("BrpcPort").add("LastStartTime").add("LastHeartbeat").add("Alive")
.add("SystemDecommissioned").add("ClusterDecommissioned").add("TabletNum")
.add("DataUsedCapacity").add("AvailCapacity").add("TotalCapacity").add("UsedPct")
.add("MaxDiskUsedPct").add("ErrMsg").add("Version")
.add("MaxDiskUsedPct").add("ErrMsg").add("Version").add("Status")
.build();
public static final int IP_INDEX = 2;
@ -167,6 +168,7 @@ public class BackendsProcDir implements ProcDirInterface {
backendInfo.add(backend.getHeartbeatErrMsg());
backendInfo.add(backend.getVersion());
backendInfo.add(new Gson().toJson(backend.getBackendStatus()));
comparableBackendInfos.add(backendInfo);
}

View File

@ -37,12 +37,14 @@ import org.apache.doris.common.Config;
import org.apache.doris.common.MetaNotFoundException;
import org.apache.doris.common.Pair;
import org.apache.doris.common.util.Daemon;
import org.apache.doris.common.util.TimeUtils;
import org.apache.doris.metric.GaugeMetric;
import org.apache.doris.metric.Metric.MetricUnit;
import org.apache.doris.metric.MetricRepo;
import org.apache.doris.persist.BackendTabletsInfo;
import org.apache.doris.persist.ReplicaPersistInfo;
import org.apache.doris.system.Backend;
import org.apache.doris.system.Backend.BackendStatus;
import org.apache.doris.system.SystemInfoService;
import org.apache.doris.task.AgentBatchTask;
import org.apache.doris.task.AgentTask;
@ -309,7 +311,14 @@ public class ReportHandler extends Daemon {
// 10. send set tablet in memory to be
handleSetTabletInMemory(backendId, backendTablets);
final SystemInfoService currentSystemInfo = Catalog.getCurrentSystemInfo();
Backend reportBackend = currentSystemInfo.getBackend(backendId);
if (reportBackend != null) {
BackendStatus backendStatus = reportBackend.getBackendStatus();
backendStatus.lastSuccessReportTabletsTime = TimeUtils.longToTimeString(start);
}
long end = System.currentTimeMillis();
LOG.info("tablet report from backend[{}] cost: {} ms", backendId, (end - start));
}

View File

@ -94,6 +94,9 @@ public class Backend implements Writable {
// this field is set by tablet report, and just for metric monitor, no need to persist.
private AtomicLong tabletMaxCompactionScore = new AtomicLong(0);
// additional backendStatus information for BE, display in JSON format
private BackendStatus backendStatus = new BackendStatus();
public Backend() {
this.host = "";
this.version = "";
@ -105,9 +108,9 @@ public class Backend implements Writable {
this.bePort = new AtomicInteger();
this.httpPort = new AtomicInteger();
this.beRpcPort = new AtomicInteger();
this.disksRef = new AtomicReference<ImmutableMap<String, DiskInfo>>(ImmutableMap.<String, DiskInfo> of());
this.disksRef = new AtomicReference<>(ImmutableMap.of());
this.ownerClusterName = new AtomicReference<String>("");
this.ownerClusterName = new AtomicReference<>("");
this.backendState = new AtomicInteger(BackendState.free.ordinal());
this.decommissionType = new AtomicInteger(DecommissionType.SystemDecommission.ordinal());
@ -123,12 +126,12 @@ public class Backend implements Writable {
this.beRpcPort = new AtomicInteger(-1);
this.lastUpdateMs = new AtomicLong(-1L);
this.lastStartTime = new AtomicLong(-1L);
this.disksRef = new AtomicReference<ImmutableMap<String, DiskInfo>>(ImmutableMap.<String, DiskInfo> of());
this.disksRef = new AtomicReference<>(ImmutableMap.of());
this.isAlive = new AtomicBoolean(false);
this.isDecommissioned = new AtomicBoolean(false);
this.ownerClusterName = new AtomicReference<String>("");
this.ownerClusterName = new AtomicReference<>("");
this.backendState = new AtomicInteger(BackendState.free.ordinal());
this.decommissionType = new AtomicInteger(DecommissionType.SystemDecommission.ordinal());
}
@ -262,6 +265,10 @@ public class Backend implements Writable {
this.disksRef.set(disks);
}
public BackendStatus getBackendStatus() {
return backendStatus;
}
/**
* backend belong to some cluster
*
@ -631,5 +638,16 @@ public class Backend implements Writable {
public long getTabletMaxCompactionScore() {
return tabletMaxCompactionScore.get();
}
/**
* Note: This class must be a POJO in order to display in JSON format
* Add additional information in the class to show in `show backends`
* if just change new added backendStatus, you can do like following
* BackendStatus status = Backend.getBackendStatus();
* status.newItem = xxx;
*/
public class BackendStatus {
public String lastSuccessReportTabletsTime = "N/A";
}
}