diff --git a/src/common/inc/tglobal.h b/src/common/inc/tglobal.h index f1fc5ca8087ddfca0f03c84d2e93c064aad761ce..7c30bd549b9af25bdd6b0ab7f18a1a8714513ff8 100644 --- a/src/common/inc/tglobal.h +++ b/src/common/inc/tglobal.h @@ -36,6 +36,7 @@ extern int8_t tsEnableVnodeBak; extern int8_t tsEnableTelemetryReporting; extern char tsEmail[]; extern char tsArbitrator[]; +extern int8_t tsArbOnline; // common extern int tsRpcTimer; diff --git a/src/common/src/tglobal.c b/src/common/src/tglobal.c index 8fa17f87511ca02759b5700dd59735a526da7fe9..0d96f18a2b3c0c01e52c5713a19c4eaf2a42b4fc 100644 --- a/src/common/src/tglobal.c +++ b/src/common/src/tglobal.c @@ -41,6 +41,7 @@ int32_t tsStatusInterval = 1; // second int32_t tsNumOfMnodes = 3; int8_t tsEnableVnodeBak = 1; int8_t tsEnableTelemetryReporting = 1; +int8_t tsArbOnline = 0; char tsEmail[TSDB_FQDN_LEN] = {0}; // common diff --git a/src/mnode/src/mnodeDnode.c b/src/mnode/src/mnodeDnode.c index 14d1fa5816ffc168463e0392e675e20cc783af7c..792e41dd5be3b2e0e0ce0fb1847126caf7dd3b94 100644 --- a/src/mnode/src/mnodeDnode.c +++ b/src/mnode/src/mnodeDnode.c @@ -810,6 +810,10 @@ static int32_t mnodeGetDnodeMeta(STableMetaMsg *pMeta, SShowObj *pShow, void *pC } pShow->numOfRows = mnodeGetDnodesNum(); + if (tsArbitrator[0] != 0) { + pShow->numOfRows++; + } + pShow->rowSize = pShow->offset[cols - 1] + pShow->bytes[cols - 1]; pShow->pIter = NULL; @@ -821,7 +825,7 @@ static int32_t mnodeGetDnodeMeta(STableMetaMsg *pMeta, SShowObj *pShow, void *pC static int32_t mnodeRetrieveDnodes(SShowObj *pShow, char *data, int32_t rows, void *pConn) { int32_t numOfRows = 0; int32_t cols = 0; - SDnodeObj *pDnode = NULL; + SDnodeObj *pDnode = NULL; char *pWrite; while (numOfRows < rows) { @@ -864,10 +868,49 @@ static int32_t mnodeRetrieveDnodes(SShowObj *pShow, char *data, int32_t rows, vo STR_TO_VARSTR(pWrite, offlineReason[pDnode->offlineReason]); cols++; - numOfRows++; + numOfRows++; mnodeDecDnodeRef(pDnode); } + if (tsArbitrator[0] != 0) { + cols = 0; + + pWrite = data + pShow->offset[cols] * rows + pShow->bytes[cols] * numOfRows; + *(int16_t *)pWrite = 0; + cols++; + + pWrite = data + pShow->offset[cols] * rows + pShow->bytes[cols] * numOfRows; + STR_WITH_MAXSIZE_TO_VARSTR(pWrite, tsArbitrator, pShow->bytes[cols]); + cols++; + + pWrite = data + pShow->offset[cols] * rows + pShow->bytes[cols] * numOfRows; + *(int16_t *)pWrite = 0; + cols++; + + pWrite = data + pShow->offset[cols] * rows + pShow->bytes[cols] * numOfRows; + *(int16_t *)pWrite = 0; + cols++; + + pWrite = data + pShow->offset[cols] * rows + pShow->bytes[cols] * numOfRows; + char *status = dnodeStatus[tsArbOnline > 0 ? TAOS_DN_STATUS_READY : TAOS_DN_STATUS_OFFLINE]; + STR_TO_VARSTR(pWrite, status); + cols++; + + pWrite = data + pShow->offset[cols] * rows + pShow->bytes[cols] * numOfRows; + STR_TO_VARSTR(pWrite, "arb"); + cols++; + + pWrite = data + pShow->offset[cols] * rows + pShow->bytes[cols] * numOfRows; + *(int64_t *)pWrite = 0; + cols++; + + pWrite = data + pShow->offset[cols] * rows + pShow->bytes[cols] * numOfRows; + STR_TO_VARSTR(pWrite, "-"); + cols++; + + numOfRows++; + } + mnodeVacuumResult(data, pShow->numOfColumns, numOfRows, rows, pShow); pShow->numOfReads += numOfRows; return numOfRows; diff --git a/src/sync/inc/syncInt.h b/src/sync/inc/syncInt.h index 47090cfa0cc6997a20c6803b8fc299f08e407bb5..eef687d64753bdecfddaf63759ba1d3bdd8fa2bd 100644 --- a/src/sync/inc/syncInt.h +++ b/src/sync/inc/syncInt.h @@ -87,6 +87,7 @@ typedef struct SsyncPeer { int32_t numOfRetrieves; // number of retrieves tried int32_t fileChanged; // a flag to indicate file is changed during retrieving process int32_t refCount; + int8_t isArb; int64_t rid; void * timer; void * pConn; diff --git a/src/sync/src/syncMain.c b/src/sync/src/syncMain.c index db100250a8570ec130f89856ce8fa55d493aeb13..118ec1b8b631189c383584f2ba59563744200ffa 100644 --- a/src/sync/src/syncMain.c +++ b/src/sync/src/syncMain.c @@ -475,7 +475,13 @@ static void syncAddArbitrator(SSyncNode *pNode) { } } - pNode->peerInfo[TAOS_SYNC_MAX_REPLICA] = syncAddPeer(pNode, &nodeInfo); + pPeer = syncAddPeer(pNode, &nodeInfo); + if (pPeer != NULL) { + pPeer->isArb = 1; + sInfo("%s, is added as arbitrator", pPeer->id); + } + + pNode->peerInfo[TAOS_SYNC_MAX_REPLICA] = pPeer; } static void syncFreeNode(void *param) { @@ -651,9 +657,14 @@ static void syncChooseMaster(SSyncNode *pNode) { // add arbitrator connection SSyncPeer *pArb = pNode->peerInfo[TAOS_SYNC_MAX_REPLICA]; - if (pArb && pArb->role != TAOS_SYNC_ROLE_OFFLINE) { - onlineNum++; - replica = pNode->replica + 1; + if (pArb) { + if (pArb->role != TAOS_SYNC_ROLE_OFFLINE) { + onlineNum++; + replica = pNode->replica + 1; + sDebug("vgId:%d, arb:%s is used while choose master", pNode->vgId, pArb->id); + } else { + sError("vgId:%d, arb:%s is not used while choose master for its offline", pNode->vgId, pArb->id); + } } if (index < 0 && onlineNum > replica / 2.0) { @@ -1118,6 +1129,7 @@ static void syncSetupPeerConnection(SSyncPeer *pPeer) { pPeer->peerFd = connFd; pPeer->role = TAOS_SYNC_ROLE_UNSYNCED; pPeer->pConn = syncAllocateTcpConn(tsTcpPool, pPeer->rid, connFd); + if (pPeer->isArb) tsArbOnline = 1; } else { sDebug("%s, failed to setup peer connection to server since %s, try later", pPeer->id, strerror(errno)); taosClose(connFd);