未验证 提交 8357859a 编写于 作者: D dapan1121 提交者: GitHub

Merge pull request #7178 from taosdata/feature/td-5806

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