提交 399a7d94 编写于 作者: S shenglian zhou

[TD-5806]<feature>:add role_time to show mnodes

上级 bc07960f
......@@ -80,6 +80,7 @@ typedef struct SMnodeObj {
int8_t updateEnd[4];
int32_t refCount;
int8_t role;
int64_t roleTime;
int8_t reserved2[3];
} SMnodeObj;
......
......@@ -122,6 +122,7 @@ static int32_t mnodeMnodeActionRestored() {
void *pIter = mnodeGetNextMnode(NULL, &pMnode);
if (pMnode != NULL) {
pMnode->role = TAOS_SYNC_ROLE_MASTER;
pMnode->roleTime = taosGetTimestampMs();
mnodeDecMnodeRef(pMnode);
}
mnodeCancelGetNextMnode(pIter);
......@@ -496,7 +497,13 @@ static int32_t mnodeGetMnodeMeta(STableMetaMsg *pMeta, SShowObj *pShow, void *pC
strcpy(pSchema[cols].name, "role");
pSchema[cols].bytes = htons(pShow->bytes[cols]);
cols++;
pShow->bytes[cols] = 8;
pSchema[cols].type = TSDB_DATA_TYPE_TIMESTAMP;
strcpy(pSchema[cols].name, "role_time");
pSchema[cols].bytes = htons(pShow->bytes[cols]);
cols++;
pShow->bytes[cols] = 8;
pSchema[cols].type = TSDB_DATA_TYPE_TIMESTAMP;
strcpy(pSchema[cols].name, "create_time");
......@@ -552,6 +559,10 @@ static int32_t mnodeRetrieveMnodes(SShowObj *pShow, char *data, int32_t rows, vo
STR_WITH_MAXSIZE_TO_VARSTR(pWrite, roles, pShow->bytes[cols]);
cols++;
pWrite = data + pShow->offset[cols] * rows + pShow->bytes[cols] * numOfRows;
*(int64_t *)pWrite = pMnode->roleTime;
cols++;
pWrite = data + pShow->offset[cols] * rows + pShow->bytes[cols] * numOfRows;
*(int64_t *)pWrite = pMnode->createdTime;
cols++;
......
......@@ -227,6 +227,7 @@ void sdbUpdateMnodeRoles() {
SMnodeObj *pMnode = mnodeGetMnode(roles.nodeId[i]);
if (pMnode != NULL) {
if (pMnode->role != roles.role[i]) {
pMnode->roleTime = taosGetTimestampMs();
bnNotify();
}
......
......@@ -16,6 +16,7 @@ from util.log import *
from util.cases import *
from util.sql import *
from datetime import timedelta
class TDTestCase:
def init(self, conn, logSql):
......@@ -41,6 +42,16 @@ class TDTestCase:
ret = tdSql.query('show mnodes')
tdSql.checkRows(1)
tdSql.checkData(0, 2, "master")
role_time = tdSql.getData(0, 3)
create_time = tdSql.getData(0, 4)
time_delta = timedelta(milliseconds=100)
if create_time-time_delta < role_time < create_time+time_delta:
tdLog.info("role_time {} and create_time {} expected within range".format(role_time, create_time))
else:
tdLog.exit("role_time {} and create_time {} not expected within range".format(role_time, create_time))
ret = tdSql.query('show vgroups')
tdSql.checkRows(0)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册