提交 84261149 编写于 作者: S Shengliang Guan

refactor: multi process mode

上级 b7b18e47
......@@ -74,19 +74,9 @@ void dmSendStatusReq(SDnodeMgmt *pMgmt) {
SMonVloadInfo vinfo = {0};
dmGetVnodeLoads(pMgmt, &vinfo);
req.pVloads = vinfo.pVloads;
pMgmt->pData->unsyncedVgId = 0;
pMgmt->pData->vndState = TAOS_SYNC_STATE_LEADER;
for (int32_t i = 0; i < taosArrayGetSize(req.pVloads); ++i) {
SVnodeLoad *pLoad = taosArrayGet(req.pVloads, i);
if (pLoad->syncState != TAOS_SYNC_STATE_LEADER && pLoad->syncState != TAOS_SYNC_STATE_FOLLOWER) {
pMgmt->pData->unsyncedVgId = pLoad->vgId;
pMgmt->pData->vndState = pLoad->syncState;
}
}
SMonMloadInfo minfo = {0};
dmGetMnodeLoads(pMgmt, &minfo);
pMgmt->pData->mndState = minfo.load.syncState;
int32_t contLen = tSerializeSStatusReq(NULL, 0, &req);
void *pHead = rpcMallocCont(contLen);
......
......@@ -41,30 +41,13 @@ static int32_t dmOpenMgmt(SMgmtInputOpt *pInput, SMgmtOutputOpt *pOutput) {
}
pMgmt->pDnode = pInput->pDnode;
pMgmt->pData = pInput->pData;
pMgmt->msgCb = pInput->msgCb;
pMgmt->path = pInput->path;
pMgmt->name = pInput->name;
pMgmt->processCreateNodeFp = pInput->processCreateNodeFp;
pMgmt->processDropNodeFp = pInput->processDropNodeFp;
pMgmt->isNodeRequiredFp = pInput->isNodeRequiredFp;
taosInitRWLatch(&pMgmt->pData->latch);
pMgmt->pData->dnodeHash = taosHashInit(4, taosGetDefaultHashFunction(TSDB_DATA_TYPE_INT), true, HASH_NO_LOCK);
if (pMgmt->pData->dnodeHash == NULL) {
dError("failed to init dnode hash");
terrno = TSDB_CODE_OUT_OF_MEMORY;
return -1;
}
if (dmReadEps(pMgmt->pData) != 0) {
dError("failed to read file since %s", terrstr());
return -1;
}
if (pMgmt->pData->dropped) {
dError("dnode will not start since its already dropped");
return -1;
}
if (dmStartWorker(pMgmt) != 0) {
return -1;
......@@ -82,19 +65,7 @@ static int32_t dmOpenMgmt(SMgmtInputOpt *pInput, SMgmtOutputOpt *pOutput) {
static void dmCloseMgmt(SDnodeMgmt *pMgmt) {
dInfo("dnode-mgmt start to clean up");
dmStopWorker(pMgmt);
taosWLockLatch(&pMgmt->pData->latch);
if (pMgmt->pData->dnodeEps != NULL) {
taosArrayDestroy(pMgmt->pData->dnodeEps);
pMgmt->pData->dnodeEps = NULL;
}
if (pMgmt->pData->dnodeHash != NULL) {
taosHashCleanup(pMgmt->pData->dnodeHash);
pMgmt->pData->dnodeHash = NULL;
}
taosWUnLockLatch(&pMgmt->pData->latch);
taosMemoryFree(pMgmt);
dInfo("dnode-mgmt is cleaned up");
}
......
......@@ -53,28 +53,48 @@ static int32_t dmInitVars(SDnode *pDnode, const SDnodeOpt *pOption) {
dInfo("dnode will run in child-process mode, node:%s", pWrapper->name);
}
pDnode->data.dnodeId = 0;
pDnode->data.clusterId = 0;
pDnode->data.dnodeVer = 0;
pDnode->data.updateTime = 0;
pDnode->data.rebootTime = taosGetTimestampMs();
pDnode->data.dropped = 0;
pDnode->data.localEp = strdup(pOption->localEp);
pDnode->data.localFqdn = strdup(pOption->localFqdn);
pDnode->data.firstEp = strdup(pOption->firstEp);
pDnode->data.secondEp = strdup(pOption->secondEp);
pDnode->data.serverPort = pOption->serverPort;
pDnode->data.supportVnodes = pOption->numOfSupportVnodes;
pDnode->data.numOfDisks = pOption->numOfDisks;
pDnode->data.disks = pOption->disks;
pDnode->data.dataDir = strdup(pOption->dataDir);
if (pDnode->data.dataDir == NULL || pDnode->data.localEp == NULL || pDnode->data.localFqdn == NULL ||
pDnode->data.firstEp == NULL || pDnode->data.secondEp == NULL) {
SDnodeData *pData = &pDnode->data;
pData->dnodeId = 0;
pData->clusterId = 0;
pData->dnodeVer = 0;
pData->updateTime = 0;
pData->rebootTime = taosGetTimestampMs();
pData->dropped = 0;
pData->stopped = 0;
pData->localEp = strdup(pOption->localEp);
pData->localFqdn = strdup(pOption->localFqdn);
pData->firstEp = strdup(pOption->firstEp);
pData->secondEp = strdup(pOption->secondEp);
pData->supportVnodes = pOption->numOfSupportVnodes;
pData->serverPort = pOption->serverPort;
pData->numOfDisks = pOption->numOfDisks;
pData->disks = pOption->disks;
pData->dataDir = strdup(pOption->dataDir);
if (pData->dataDir == NULL || pData->localEp == NULL || pData->localFqdn == NULL ||
pData->firstEp == NULL || pData->secondEp == NULL) {
terrno = TSDB_CODE_OUT_OF_MEMORY;
return -1;
}
pData->dnodeHash = taosHashInit(4, taosGetDefaultHashFunction(TSDB_DATA_TYPE_INT), true, HASH_NO_LOCK);
if (pData->dnodeHash == NULL) {
dError("failed to init dnode hash");
terrno = TSDB_CODE_OUT_OF_MEMORY;
return -1;
}
if (dmReadEps(pData) != 0) {
dError("failed to read file since %s", terrstr());
return -1;
}
if (pData->dropped) {
dError("dnode will not start since its already dropped");
return -1;
}
taosInitRWLatch(&pData->latch);
taosThreadMutexInit(&pDnode->mutex, NULL);
return 0;
}
......@@ -90,11 +110,23 @@ static void dmClearVars(SDnode *pDnode) {
pDnode->lockfile = NULL;
}
taosMemoryFreeClear(pDnode->data.localEp);
taosMemoryFreeClear(pDnode->data.localFqdn);
taosMemoryFreeClear(pDnode->data.firstEp);
taosMemoryFreeClear(pDnode->data.secondEp);
taosMemoryFreeClear(pDnode->data.dataDir);
SDnodeData *pData = &pDnode->data;
taosWLockLatch(&pData->latch);
if (pData->dnodeEps != NULL) {
taosArrayDestroy(pData->dnodeEps);
pData->dnodeEps = NULL;
}
if (pData->dnodeHash != NULL) {
taosHashCleanup(pData->dnodeHash);
pData->dnodeHash = NULL;
}
taosWUnLockLatch(&pData->latch);
taosMemoryFreeClear(pData->localEp);
taosMemoryFreeClear(pData->localFqdn);
taosMemoryFreeClear(pData->firstEp);
taosMemoryFreeClear(pData->secondEp);
taosMemoryFreeClear(pData->dataDir);
taosThreadMutexDestroy(&pDnode->mutex);
memset(&pDnode->mutex, 0, sizeof(pDnode->mutex));
......@@ -163,7 +195,7 @@ SDnode *dmCreate(const SDnodeOpt *pOption) {
goto _OVER;
}
if (OnlyInSingleProc(pDnode->ptype) && InParentProc(pDnode->ptype)) {
if (OnlyInSingleProc(pDnode->ptype) || InParentProc(pDnode->ptype)) {
pDnode->lockfile = dmCheckRunning(pOption->dataDir);
if (pDnode->lockfile == NULL) {
goto _OVER;
......
......@@ -90,9 +90,6 @@ typedef struct {
int64_t dnodeVer;
int64_t updateTime;
int64_t rebootTime;
int32_t unsyncedVgId;
ESyncState vndState;
ESyncState mndState;
bool dropped;
bool stopped;
SEpSet mnodeEps;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册