From 53774be0cadc03d31a4188c2a113afa97480b1ba Mon Sep 17 00:00:00 2001 From: Shengliang Guan Date: Wed, 14 Oct 2020 22:41:17 +0800 Subject: [PATCH 01/13] add debug info for sync module --- src/sync/inc/syncInt.h | 3 +++ src/sync/src/syncMain.c | 44 +++++++++++++++++++++++++++++++---------- 2 files changed, 37 insertions(+), 10 deletions(-) diff --git a/src/sync/inc/syncInt.h b/src/sync/inc/syncInt.h index f681810646..96f1629f72 100644 --- a/src/sync/inc/syncInt.h +++ b/src/sync/inc/syncInt.h @@ -65,6 +65,9 @@ typedef struct { typedef struct { int8_t role; int8_t ack; + int8_t type; + int8_t reserved[3]; + uint16_t tranId; uint64_t version; SPeerStatus peersStatus[]; } SPeersStatus; diff --git a/src/sync/src/syncMain.c b/src/sync/src/syncMain.c index ef635e6efc..9c4397e2a0 100644 --- a/src/sync/src/syncMain.c +++ b/src/sync/src/syncMain.c @@ -48,7 +48,7 @@ static void * vgIdHash; static void syncProcessSyncRequest(char *pMsg, SSyncPeer *pPeer); static void syncRecoverFromMaster(SSyncPeer *pPeer); static void syncCheckPeerConnection(void *param, void *tmrId); -static void syncSendPeersStatusMsgToPeer(SSyncPeer *pPeer, char ack); +static void syncSendPeersStatusMsgToPeer(SSyncPeer *pPeer, char ack, int8_t type, uint16_t tranId); static void syncProcessBrokenLink(void *param); static int syncProcessPeerMsg(void *param, void *buffer); static void syncProcessIncommingConnection(int connFd, uint32_t sourceIp); @@ -71,6 +71,28 @@ char* syncRole[] = { "master" }; +typedef enum { + SYNC_STATUS_BROADCAST, + SYNC_STATUS_BROADCAST_RSP, + SYNC_STATUS_SETUP_CONN, + SYNC_STATUS_SETUP_CONN_RSP, + SYNC_STATUS_EXCHANGE_DATA, + SYNC_STATUS_EXCHANGE_DATA_RSP +} ESyncStatusType; + +char *statusType[] = { + "broadcast", + "broadcast-rsp", + "setup-conn", + "setup-conn-rsp", + "exchange-data", + "exchange-data-rsp" +}; + +uint16_t syncGenTranId() { + return taosRand() & 0XFFFF; +} + int32_t syncInit() { SPoolInfo info; @@ -539,7 +561,7 @@ void syncBroadcastStatus(SSyncNode *pNode) { for (int i = 0; i < pNode->replica; ++i) { if (i == pNode->selfIndex) continue; pPeer = pNode->peerInfo[i]; - syncSendPeersStatusMsgToPeer(pPeer, 1); + syncSendPeersStatusMsgToPeer(pPeer, 1, SYNC_STATUS_BROADCAST, syncGenTranId()); } } @@ -894,14 +916,14 @@ static void syncProcessPeersStatusMsg(char *cont, SSyncPeer *pPeer) { SSyncNode * pNode = pPeer->pSyncNode; SPeersStatus *pPeersStatus = (SPeersStatus *)cont; - sDebug("%s, status msg is received, self:%s ver:%" PRIu64 " peer:%s ver:%" PRIu64 ", ack:%d", pPeer->id, - syncRole[nodeRole], nodeVersion, syncRole[pPeersStatus->role], pPeersStatus->version, pPeersStatus->ack); + sDebug("%s, status msg is received, self:%s ver:%" PRIu64 " peer:%s ver:%" PRIu64 ", ack:%d tranId:%u type:%s", pPeer->id, + syncRole[nodeRole], nodeVersion, syncRole[pPeersStatus->role], pPeersStatus->version, pPeersStatus->ack, pPeersStatus->tranId, statusType[pPeersStatus->type]); pPeer->version = pPeersStatus->version; syncCheckRole(pPeer, pPeersStatus->peersStatus, pPeersStatus->role); if (pPeersStatus->ack) { - syncSendPeersStatusMsgToPeer(pPeer, 0); + syncSendPeersStatusMsgToPeer(pPeer, 0, pPeersStatus->type + 1, pPeersStatus->tranId); } } @@ -958,7 +980,7 @@ static int syncProcessPeerMsg(void *param, void *buffer) { #define statusMsgLen sizeof(SSyncHead) + sizeof(SPeersStatus) + sizeof(SPeerStatus) * TAOS_SYNC_MAX_REPLICA -static void syncSendPeersStatusMsgToPeer(SSyncPeer *pPeer, char ack) { +static void syncSendPeersStatusMsgToPeer(SSyncPeer *pPeer, char ack, int8_t type, uint16_t tranId) { SSyncNode *pNode = pPeer->pSyncNode; char msg[statusMsgLen] = {0}; @@ -973,6 +995,8 @@ static void syncSendPeersStatusMsgToPeer(SSyncPeer *pPeer, char ack) { pPeersStatus->version = nodeVersion; pPeersStatus->role = nodeRole; pPeersStatus->ack = ack; + pPeersStatus->type = type; + pPeersStatus->tranId = tranId; for (int i = 0; i < pNode->replica; ++i) { pPeersStatus->peersStatus[i].role = pNode->peerInfo[i]->role; @@ -981,8 +1005,8 @@ static void syncSendPeersStatusMsgToPeer(SSyncPeer *pPeer, char ack) { int retLen = write(pPeer->peerFd, msg, statusMsgLen); if (retLen == statusMsgLen) { - sDebug("%s, status msg is sent, self:%s ver:%" PRIu64 ", ack:%d", pPeer->id, syncRole[pPeersStatus->role], - pPeersStatus->version, pPeersStatus->ack); + sDebug("%s, status msg is sent, self:%s ver:%" PRIu64 ", ack:%d tranId:%u type:%s", pPeer->id, syncRole[pPeersStatus->role], + pPeersStatus->version, pPeersStatus->ack, pPeersStatus->tranId, statusType[pPeersStatus->type]); } else { sDebug("%s, failed to send status msg, restart", pPeer->id); syncRestartConnection(pPeer); @@ -997,7 +1021,7 @@ static void syncSetupPeerConnection(SSyncPeer *pPeer) { taosTmrStopA(&pPeer->timer); if (pPeer->peerFd >= 0) { sDebug("%s, send role version to peer", pPeer->id); - syncSendPeersStatusMsgToPeer(pPeer, 1); + syncSendPeersStatusMsgToPeer(pPeer, 1, SYNC_STATUS_SETUP_CONN, syncGenTranId()); return; } @@ -1110,7 +1134,7 @@ static void syncProcessIncommingConnection(int connFd, uint32_t sourceIp) { pPeer->pConn = taosAllocateTcpConn(tsTcpPool, pPeer, connFd); syncAddPeerRef(pPeer); sDebug("%s, ready to exchange data", pPeer->id); - syncSendPeersStatusMsgToPeer(pPeer, 1); + syncSendPeersStatusMsgToPeer(pPeer, 1, SYNC_STATUS_EXCHANGE_DATA, syncGenTranId()); } } From 9d6e37762319eea1425cb83cb8cdbb6c82149e2f Mon Sep 17 00:00:00 2001 From: Shengliang Guan Date: Wed, 18 Nov 2020 14:25:16 +0800 Subject: [PATCH 02/13] TD-1898 --- src/mnode/src/mnodeSdb.c | 130 ++++++++++++++++++------------------ src/sync/inc/syncInt.h | 2 +- src/sync/src/syncMain.c | 31 +++++---- src/sync/src/syncRestore.c | 2 +- src/sync/src/syncRetrieve.c | 2 +- src/wal/src/walWrite.c | 4 +- 6 files changed, 86 insertions(+), 85 deletions(-) diff --git a/src/mnode/src/mnodeSdb.c b/src/mnode/src/mnodeSdb.c index 003ecd0d24..9c11fa80e8 100644 --- a/src/mnode/src/mnodeSdb.c +++ b/src/mnode/src/mnodeSdb.c @@ -166,7 +166,7 @@ static char *sdbGetKeyStr(SSdbTable *pTable, void *key) { } } -static char *sdbGetKeyStrFromObj(SSdbTable *pTable, void *key) { +static char *sdbGetObjStr(SSdbTable *pTable, void *key) { return sdbGetKeyStr(pTable, sdbGetObjKey(pTable, key)); } @@ -176,18 +176,18 @@ static void *sdbGetTableFromId(int32_t tableId) { static int32_t sdbInitWal() { SWalCfg walCfg = {.vgId = 1, .walLevel = TAOS_WAL_FSYNC, .keep = TAOS_WAL_KEEP, .fsyncPeriod = 0}; - char temp[TSDB_FILENAME_LEN]; + char temp[TSDB_FILENAME_LEN] = {0}; sprintf(temp, "%s/wal", tsMnodeDir); tsSdbObj.wal = walOpen(temp, &walCfg); if (tsSdbObj.wal == NULL) { - sdbError("failed to open sdb wal in %s", tsMnodeDir); + sdbError("vgId:1, failed to open wal in %s", tsMnodeDir); return -1; } - sdbInfo("open sdb wal for restore"); + sdbInfo("vgId:1, open wal for restore"); int code = walRestore(tsSdbObj.wal, NULL, sdbWrite); if (code != TSDB_CODE_SUCCESS) { - sdbError("failed to open wal for restore, reason:%s", tstrerror(code)); + sdbError("vgId:1, failed to open wal for restore since %s", tstrerror(code)); return -1; } return 0; @@ -205,10 +205,10 @@ static void sdbRestoreTables() { totalRows += pTable->numOfRows; numOfTables++; - sdbDebug("table:%s, is restored, numOfRows:%" PRId64, pTable->tableName, pTable->numOfRows); + sdbDebug("vgId:1, sdb:%s is restored, rows:%" PRId64, pTable->tableName, pTable->numOfRows); } - sdbInfo("sdb is restored, ver:%" PRId64 " totalRows:%d numOfTables:%d", tsSdbObj.version, totalRows, numOfTables); + sdbInfo("vgId:1, sdb is restored, mver:%" PRIu64 " rows:%d tables:%d", tsSdbObj.version, totalRows, numOfTables); } void sdbUpdateMnodeRoles() { @@ -217,12 +217,12 @@ void sdbUpdateMnodeRoles() { SNodesRole roles = {0}; syncGetNodesRole(tsSdbObj.sync, &roles); - sdbInfo("update mnodes sync roles, total:%d", tsSdbObj.cfg.replica); + sdbInfo("vgId:1, update mnodes roles, replica:%d", tsSdbObj.cfg.replica); for (int32_t i = 0; i < tsSdbObj.cfg.replica; ++i) { SMnodeObj *pMnode = mnodeGetMnode(roles.nodeId[i]); if (pMnode != NULL) { pMnode->role = roles.role[i]; - sdbInfo("mnode:%d, role:%s", pMnode->mnodeId, mnodeGetMnodeRoleStr(pMnode->role)); + sdbInfo("vgId:1, mnode:%d, role:%s", pMnode->mnodeId, mnodeGetMnodeRoleStr(pMnode->role)); if (pMnode->mnodeId == dnodeGetDnodeId()) tsSdbObj.role = pMnode->role; mnodeDecMnodeRef(pMnode); } @@ -242,7 +242,7 @@ static int32_t sdbGetWalInfo(void *ahandle, char *fileName, int64_t *fileId) { } static void sdbNotifyRole(void *ahandle, int8_t role) { - sdbInfo("mnode role changed from %s to %s", mnodeGetMnodeRoleStr(tsSdbObj.role), mnodeGetMnodeRoleStr(role)); + sdbInfo("vgId:1, mnode role changed from %s to %s", mnodeGetMnodeRoleStr(tsSdbObj.role), mnodeGetMnodeRoleStr(role)); if (role == TAOS_SYNC_ROLE_MASTER && tsSdbObj.role != TAOS_SYNC_ROLE_MASTER) { balanceReset(); @@ -262,24 +262,21 @@ static void sdbConfirmForward(void *ahandle, void *param, int32_t code) { int32_t processedCount = atomic_add_fetch_32(&pOper->processedCount, 1); if (processedCount <= 1) { if (pMsg != NULL) { - sdbDebug("app:%p:%p, waiting for confirm this operation, count:%d result:%s", pMsg->rpcMsg.ahandle, pMsg, - processedCount, tstrerror(code)); + sdbDebug("vgId:1, msg:%p waiting for confirm, count:%d code:%x", pMsg, processedCount, code); } return; } if (pMsg != NULL) { - sdbDebug("app:%p:%p, is confirmed and will do callback func, result:%s", pMsg->rpcMsg.ahandle, pMsg, - tstrerror(code)); + sdbDebug("vgId:1, msg:%p is confirmed, code:%x", pMsg, code); } // failed to forward, need revert insert if (pOper->retCode != TSDB_CODE_SUCCESS) { SWalHead *pHead = (void *)pOper + sizeof(SSdbOper) + SDB_SYNC_HACK; int32_t action = pHead->msgType % 10; - sdbError("table:%s record:%p:%s ver:%" PRIu64 ", action:%d failed to foward reason:%s", - ((SSdbTable *)pOper->table)->tableName, pOper->pObj, sdbGetKeyStr(pOper->table, pHead->cont), - pHead->version, action, tstrerror(pOper->retCode)); + sdbError("vgId:1, key:%p:%s hver:%" PRIu64 " action:%d, failed to foward since %s", pOper->pObj, + sdbGetKeyStr(pOper->table, pHead->cont), pHead->version, action, tstrerror(pOper->retCode)); if (action == SDB_ACTION_INSERT) { // It's better to create a table in two stages, create it first and then set it success //sdbDeleteHash(pOper->table, pOper); @@ -314,11 +311,11 @@ void sdbUpdateAsync() { void sdbUpdateSync(void *pMnodes) { SMnodeInfos *mnodes = pMnodes; if (!mnodeIsRunning()) { - mDebug("mnode not start yet, update sync config later"); + mDebug("vgId:1, mnode not start yet, update sync config later"); return; } - mDebug("update sync config in sync module, mnodes:%p", pMnodes); + mDebug("vgId:1, update sync config in sync module, mnodes:%p", pMnodes); SSyncCfg syncCfg = {0}; int32_t index = 0; @@ -344,7 +341,7 @@ void sdbUpdateSync(void *pMnodes) { } sdbFreeIter(pIter); syncCfg.replica = index; - mDebug("mnodes info not input, use infos in sdb, numOfMnodes:%d", syncCfg.replica); + mDebug("vgId:1, mnodes info not input, use infos in sdb, numOfMnodes:%d", syncCfg.replica); } else { for (index = 0; index < mnodes->mnodeNum; ++index) { SMnodeInfo *node = &mnodes->mnodeInfos[index]; @@ -353,7 +350,7 @@ void sdbUpdateSync(void *pMnodes) { syncCfg.nodeInfo[index].nodePort += TSDB_PORT_SYNC; } syncCfg.replica = index; - mDebug("mnodes info input, numOfMnodes:%d", syncCfg.replica); + mDebug("vgId:1, mnodes info input, numOfMnodes:%d", syncCfg.replica); } syncCfg.quorum = (syncCfg.replica == 1) ? 1 : 2; @@ -367,18 +364,19 @@ void sdbUpdateSync(void *pMnodes) { } if (!hasThisDnode) { - sdbDebug("update sync config, this dnode not exist"); + sdbDebug("vgId:1, update sync config, this dnode not exist"); return; } if (memcmp(&syncCfg, &tsSdbObj.cfg, sizeof(SSyncCfg)) == 0) { - sdbDebug("update sync config, info not changed"); + sdbDebug("vgId:1, update sync config, info not changed"); return; } - sdbInfo("work as mnode, replica:%d", syncCfg.replica); + sdbInfo("vgId:1, work as mnode, replica:%d", syncCfg.replica); for (int32_t i = 0; i < syncCfg.replica; ++i) { - sdbInfo("mnode:%d, %s:%d", syncCfg.nodeInfo[i].nodeId, syncCfg.nodeInfo[i].nodeFqdn, syncCfg.nodeInfo[i].nodePort); + sdbInfo("vgId:1, mnode:%d, %s:%d", syncCfg.nodeInfo[i].nodeId, syncCfg.nodeInfo[i].nodeFqdn, + syncCfg.nodeInfo[i].nodePort); } SSyncInfo syncInfo = {0}; @@ -427,9 +425,9 @@ void sdbCleanUp() { if (tsSdbObj.status != SDB_STATUS_SERVING) return; tsSdbObj.status = SDB_STATUS_CLOSING; - + sdbCleanupWriteWorker(); - sdbDebug("sdb will be closed, ver:%" PRId64, tsSdbObj.version); + sdbDebug("vgId:1, sdb will be closed, mver:%" PRIu64, tsSdbObj.version); if (tsSdbObj.sync) { syncStop(tsSdbObj.sync); @@ -450,7 +448,7 @@ void sdbIncRef(void *handle, void *pObj) { SSdbTable *pTable = handle; int32_t * pRefCount = (int32_t *)(pObj + pTable->refCountPos); int32_t refCount = atomic_add_fetch_32(pRefCount, 1); - sdbTrace("add ref to table:%s record:%p:%s:%d", pTable->tableName, pObj, sdbGetKeyStrFromObj(pTable, pObj), refCount); + sdbTrace("vgId:1, sdb:%s, inc ref to key:%p:%s:%d", pTable->tableName, pObj, sdbGetObjStr(pTable, pObj), refCount); } void sdbDecRef(void *handle, void *pObj) { @@ -459,11 +457,11 @@ void sdbDecRef(void *handle, void *pObj) { SSdbTable *pTable = handle; int32_t * pRefCount = (int32_t *)(pObj + pTable->refCountPos); int32_t refCount = atomic_sub_fetch_32(pRefCount, 1); - sdbTrace("def ref of table:%s record:%p:%s:%d", pTable->tableName, pObj, sdbGetKeyStrFromObj(pTable, pObj), refCount); + sdbTrace("vgId:1, sdb:%s, dec ref to key:%p:%s:%d", pTable->tableName, pObj, sdbGetObjStr(pTable, pObj), refCount); int32_t *updateEnd = pObj + pTable->refCountPos - 4; if (refCount <= 0 && *updateEnd) { - sdbTrace("table:%s, record:%p:%s:%d is destroyed", pTable->tableName, pObj, sdbGetKeyStrFromObj(pTable, pObj), refCount); + sdbTrace("vgId:1, sdb:%s, key:%p:%s:%d destroyed", pTable->tableName, pObj, sdbGetObjStr(pTable, pObj), refCount); SSdbOper oper = {.pObj = pObj}; (*pTable->destroyFp)(&oper); } @@ -523,13 +521,13 @@ static int32_t sdbInsertHash(SSdbTable *pTable, SSdbOper *pOper) { atomic_add_fetch_32(&pTable->autoIndex, 1); } - sdbDebug("table:%s, insert record:%s to hash, rowSize:%d numOfRows:%" PRId64 ", msg:%p", pTable->tableName, - sdbGetKeyStrFromObj(pTable, pOper->pObj), pOper->rowSize, pTable->numOfRows, pOper->pMsg); + sdbDebug("vgId:1, sdb:%s, insert key:%s to hash, rowSize:%d rows:%" PRId64 ", msg:%p", pTable->tableName, + sdbGetObjStr(pTable, pOper->pObj), pOper->rowSize, pTable->numOfRows, pOper->pMsg); int32_t code = (*pTable->insertFp)(pOper); if (code != TSDB_CODE_SUCCESS) { - sdbError("table:%s, failed to insert record:%s to hash, remove it", pTable->tableName, - sdbGetKeyStrFromObj(pTable, pOper->pObj)); + sdbError("vgId:1, sdb:%s, failed to insert key:%s to hash, remove it", pTable->tableName, + sdbGetObjStr(pTable, pOper->pObj)); sdbDeleteHash(pTable, pOper); } @@ -540,8 +538,8 @@ static int32_t sdbDeleteHash(SSdbTable *pTable, SSdbOper *pOper) { int32_t *updateEnd = pOper->pObj + pTable->refCountPos - 4; bool set = atomic_val_compare_exchange_32(updateEnd, 0, 1) == 0; if (!set) { - sdbError("table:%s, failed to delete record:%s from hash, for it already removed", pTable->tableName, - sdbGetKeyStrFromObj(pTable, pOper->pObj)); + sdbError("vgId:1, sdb:%s, failed to delete key:%s from hash, for it already removed", pTable->tableName, + sdbGetObjStr(pTable, pOper->pObj)); return TSDB_CODE_MND_SDB_OBJ_NOT_THERE; } @@ -558,9 +556,9 @@ static int32_t sdbDeleteHash(SSdbTable *pTable, SSdbOper *pOper) { pthread_mutex_unlock(&pTable->mutex); atomic_sub_fetch_32(&pTable->numOfRows, 1); - - sdbDebug("table:%s, delete record:%s from hash, numOfRows:%" PRId64 ", msg:%p", pTable->tableName, - sdbGetKeyStrFromObj(pTable, pOper->pObj), pTable->numOfRows, pOper->pMsg); + + sdbDebug("vgId:1, sdb:%s, delete key:%s from hash, numOfRows:%" PRId64 ", msg:%p", pTable->tableName, + sdbGetObjStr(pTable, pOper->pObj), pTable->numOfRows, pOper->pMsg); sdbDecRef(pTable, pOper->pObj); @@ -568,8 +566,8 @@ static int32_t sdbDeleteHash(SSdbTable *pTable, SSdbOper *pOper) { } static int32_t sdbUpdateHash(SSdbTable *pTable, SSdbOper *pOper) { - sdbDebug("table:%s, update record:%s in hash, numOfRows:%" PRId64 ", msg:%p", pTable->tableName, - sdbGetKeyStrFromObj(pTable, pOper->pObj), pTable->numOfRows, pOper->pMsg); + sdbDebug("vgId:1, sdb:%s, update key:%s in hash, numOfRows:%" PRId64 ", msg:%p", pTable->tableName, + sdbGetObjStr(pTable, pOper->pObj), pTable->numOfRows, pOper->pMsg); (*pTable->updateFp)(pOper); return TSDB_CODE_SUCCESS; @@ -594,12 +592,12 @@ static int sdbWrite(void *param, void *data, int32_t type, void *pMsg) { // for data from WAL or forward, version may be smaller if (pHead->version <= tsSdbObj.version) { pthread_mutex_unlock(&tsSdbObj.mutex); - sdbDebug("table:%s, failed to restore %s record:%s from source(%d), ver:%" PRId64 " too large, sdb ver:%" PRId64, + sdbDebug("vgId:1, sdb:%s, failed to restore %s key:%s from source(%d), hver:%" PRIu64 " too large, mver:%" PRIu64, pTable->tableName, sdbGetActionStr(action), sdbGetKeyStr(pTable, pHead->cont), type, pHead->version, tsSdbObj.version); return TSDB_CODE_SUCCESS; } else if (pHead->version != tsSdbObj.version + 1) { pthread_mutex_unlock(&tsSdbObj.mutex); - sdbError("table:%s, failed to restore %s record:%s from source(%d), ver:%" PRId64 " too large, sdb ver:%" PRId64, + sdbError("vgId:1, sdb:%s, failed to restore %s key:%s from source(%d), hver:%" PRIu64 " too large, mver:%" PRIu64, pTable->tableName, sdbGetActionStr(action), sdbGetKeyStr(pTable, pHead->cont), type, pHead->version, tsSdbObj.version); return TSDB_CODE_SYN_INVALID_VERSION; } else { @@ -623,19 +621,19 @@ static int sdbWrite(void *param, void *data, int32_t type, void *pMsg) { if (syncCode <= 0) pOper->processedCount = 1; if (syncCode < 0) { - sdbError("table:%s, failed to forward request, result:%s action:%s record:%s ver:%" PRId64 ", msg:%p", pTable->tableName, + sdbError("vgId:1, sdb:%s, failed to forward req since %s action:%s key:%s hver:%" PRIu64 ", msg:%p", pTable->tableName, tstrerror(syncCode), sdbGetActionStr(action), sdbGetKeyStr(pTable, pHead->cont), pHead->version, pOper->pMsg); } else if (syncCode > 0) { - sdbDebug("table:%s, forward request is sent, action:%s record:%s ver:%" PRId64 ", msg:%p", pTable->tableName, + sdbDebug("vgId:1, sdb:%s, forward req is sent, action:%s key:%s hver:%" PRIu64 ", msg:%p", pTable->tableName, sdbGetActionStr(action), sdbGetKeyStr(pTable, pHead->cont), pHead->version, pOper->pMsg); } else { - sdbTrace("table:%s, no need to send fwd request, action:%s record:%s ver:%" PRId64 ", msg:%p", pTable->tableName, + sdbTrace("vgId:1, sdb:%s, no need to send fwd req, action:%s key:%s hver:%" PRIu64 ", msg:%p", pTable->tableName, sdbGetActionStr(action), sdbGetKeyStr(pTable, pHead->cont), pHead->version, pOper->pMsg); } return syncCode; } - sdbDebug("table:%s, record from wal/fwd is disposed, action:%s record:%s ver:%" PRId64, pTable->tableName, + sdbDebug("vgId:1, sdb:%s, record from wal/fwd is disposed, action:%s key:%s hver:%" PRIu64, pTable->tableName, sdbGetActionStr(action), sdbGetKeyStr(pTable, pHead->cont), pHead->version); // even it is WAL/FWD, it shall be called to update version in sync @@ -649,7 +647,7 @@ static int sdbWrite(void *param, void *data, int32_t type, void *pMsg) { } else if (action == SDB_ACTION_DELETE) { void *pRow = sdbGetRowMeta(pTable, pHead->cont); if (pRow == NULL) { - sdbDebug("table:%s, object:%s not exist in hash, ignore delete action", pTable->tableName, + sdbDebug("vgId:1, sdb:%s, object:%s not exist in hash, ignore delete action", pTable->tableName, sdbGetKeyStr(pTable, pHead->cont)); return TSDB_CODE_SUCCESS; } @@ -658,7 +656,7 @@ static int sdbWrite(void *param, void *data, int32_t type, void *pMsg) { } else if (action == SDB_ACTION_UPDATE) { void *pRow = sdbGetRowMeta(pTable, pHead->cont); if (pRow == NULL) { - sdbDebug("table:%s, object:%s not exist in hash, ignore update action", pTable->tableName, + sdbDebug("vgId:1, sdb:%s, object:%s not exist in hash, ignore update action", pTable->tableName, sdbGetKeyStr(pTable, pHead->cont)); return TSDB_CODE_SUCCESS; } @@ -675,8 +673,8 @@ int32_t sdbInsertRow(SSdbOper *pOper) { if (pTable == NULL) return TSDB_CODE_MND_SDB_INVALID_TABLE_TYPE; if (sdbGetRowFromObj(pTable, pOper->pObj)) { - sdbError("table:%s, failed to insert record:%s, already exist", pTable->tableName, - sdbGetKeyStrFromObj(pTable, pOper->pObj)); + sdbError("vgId:1, sdb:%s, failed to insert key:%s, already exist", pTable->tableName, + sdbGetObjStr(pTable, pOper->pObj)); sdbDecRef(pTable, pOper->pObj); return TSDB_CODE_MND_SDB_OBJ_ALREADY_THERE; } @@ -692,7 +690,7 @@ int32_t sdbInsertRow(SSdbOper *pOper) { int32_t code = sdbInsertHash(pTable, pOper); if (code != TSDB_CODE_SUCCESS) { - sdbError("table:%s, failed to insert into hash", pTable->tableName); + sdbError("vgId:1, sdb:%s, failed to insert into hash", pTable->tableName); return code; } @@ -727,8 +725,8 @@ int32_t sdbInsertRowImp(SSdbOper *pOper) { memcpy(pNewOper, pOper, sizeof(SSdbOper)); if (pNewOper->pMsg != NULL) { - sdbDebug("app:%p:%p, table:%s record:%p:%s, insert action is add to sdb queue", pNewOper->pMsg->rpcMsg.ahandle, - pNewOper->pMsg, pTable->tableName, pOper->pObj, sdbGetKeyStrFromObj(pTable, pOper->pObj)); + sdbDebug("vgId:1, ahandle:%p msg:%p, sdb:%s key:%p:%s, insert action is add to sdb queue", pNewOper->pMsg->rpcMsg.ahandle, + pNewOper->pMsg, pTable->tableName, pOper->pObj, sdbGetObjStr(pTable, pOper->pObj)); } sdbIncRef(pNewOper->table, pNewOper->pObj); @@ -751,7 +749,7 @@ int32_t sdbDeleteRow(SSdbOper *pOper) { void *pRow = sdbGetRowMetaFromObj(pTable, pOper->pObj); if (pRow == NULL) { - sdbDebug("table:%s, record is not there, delete failed", pTable->tableName); + sdbDebug("vgId:1, sdb:%s, record is not there, delete failed", pTable->tableName); return TSDB_CODE_MND_SDB_OBJ_NOT_THERE; } @@ -759,7 +757,7 @@ int32_t sdbDeleteRow(SSdbOper *pOper) { int32_t code = sdbDeleteHash(pTable, pOper); if (code != TSDB_CODE_SUCCESS) { - sdbError("table:%s, failed to delete from hash", pTable->tableName); + sdbError("vgId:1, sdb:%s, failed to delete from hash", pTable->tableName); sdbDecRef(pTable, pOper->pObj); return code; } @@ -795,8 +793,8 @@ int32_t sdbDeleteRowImp(SSdbOper *pOper) { memcpy(pNewOper, pOper, sizeof(SSdbOper)); if (pNewOper->pMsg != NULL) { - sdbDebug("app:%p:%p, table:%s record:%p:%s, delete action is add to sdb queue", pNewOper->pMsg->rpcMsg.ahandle, - pNewOper->pMsg, pTable->tableName, pOper->pObj, sdbGetKeyStrFromObj(pTable, pOper->pObj)); + sdbDebug("vgId:1, ahandle:%p msg:%p, sdb:%s key:%p:%s, delete action is add to sdb queue", pNewOper->pMsg->rpcMsg.ahandle, + pNewOper->pMsg, pTable->tableName, pOper->pObj, sdbGetObjStr(pTable, pOper->pObj)); } taosWriteQitem(tsSdbWriteQueue, TAOS_QTYPE_RPC, pNewOper); @@ -810,13 +808,13 @@ int32_t sdbUpdateRow(SSdbOper *pOper) { void *pRow = sdbGetRowMetaFromObj(pTable, pOper->pObj); if (pRow == NULL) { - sdbDebug("table:%s, record is not there, update failed", pTable->tableName); + sdbDebug("vgId:1, sdb:%s, record is not there, update failed", pTable->tableName); return TSDB_CODE_MND_SDB_OBJ_NOT_THERE; } int32_t code = sdbUpdateHash(pTable, pOper); if (code != TSDB_CODE_SUCCESS) { - sdbError("table:%s, failed to update hash", pTable->tableName); + sdbError("vgId:1, sdb:%s, failed to update hash", pTable->tableName); return code; } @@ -850,8 +848,8 @@ int32_t sdbUpdateRowImp(SSdbOper *pOper) { memcpy(pNewOper, pOper, sizeof(SSdbOper)); if (pNewOper->pMsg != NULL) { - sdbDebug("app:%p:%p, table:%s record:%p:%s, update action is add to sdb queue", pNewOper->pMsg->rpcMsg.ahandle, - pNewOper->pMsg, pTable->tableName, pOper->pObj, sdbGetKeyStrFromObj(pTable, pOper->pObj)); + sdbDebug("vgId:1, ahandle:%p msg:%p, sdb:%s key:%p:%s, update action is add to sdb queue", pNewOper->pMsg->rpcMsg.ahandle, + pNewOper->pMsg, pTable->tableName, pOper->pObj, sdbGetObjStr(pTable, pOper->pObj)); } sdbIncRef(pNewOper->table, pNewOper->pObj); @@ -948,7 +946,7 @@ void sdbCloseTable(void *handle) { taosHashCleanup(pTable->iHandle); pthread_mutex_destroy(&pTable->mutex); - sdbDebug("table:%s, is closed, numOfTables:%d", pTable->tableName, tsSdbObj.numOfTables); + sdbDebug("vgId:1, sdb:%s, is closed, numOfTables:%d", pTable->tableName, tsSdbObj.numOfTables); free(pTable); } @@ -964,7 +962,7 @@ int32_t sdbInitWriteWorker() { sdbAllocWriteQueue(); - mInfo("sdb write is opened"); + mInfo("vgId:1, sdb write is opened"); return 0; } @@ -986,7 +984,7 @@ void sdbCleanupWriteWorker() { sdbFreeWritequeue(); tfree(tsSdbPool.writeWorker); - mInfo("sdb write is closed"); + mInfo("vgId:1, sdb write is closed"); } int32_t sdbAllocWriteQueue() { @@ -1072,7 +1070,7 @@ static void *sdbWorkerFp(void *param) { pOper->processedCount = 1; pHead = (void *)pOper + sizeof(SSdbOper) + SDB_SYNC_HACK; if (pOper->pMsg != NULL) { - sdbDebug("app:%p:%p, table:%s record:%p:%s ver:%" PRIu64 ", will be processed in sdb queue", + sdbDebug("vgId:1, ahandle:%p msg:%p, sdb:%s key:%p:%s hver:%" PRIu64 ", will be processed in sdb queue", pOper->pMsg->rpcMsg.ahandle, pOper->pMsg, ((SSdbTable *)pOper->table)->tableName, pOper->pObj, sdbGetKeyStr(pOper->table, pHead->cont), pHead->version); } diff --git a/src/sync/inc/syncInt.h b/src/sync/inc/syncInt.h index 7156a2d08a..309d5b1a75 100644 --- a/src/sync/inc/syncInt.h +++ b/src/sync/inc/syncInt.h @@ -106,7 +106,7 @@ typedef struct { int8_t nacks; int8_t confirmed; int32_t code; - uint64_t time; + int64_t time; } SFwdInfo; typedef struct { diff --git a/src/sync/src/syncMain.c b/src/sync/src/syncMain.c index 6ff04aad64..5c56e90af6 100644 --- a/src/sync/src/syncMain.c +++ b/src/sync/src/syncMain.c @@ -689,7 +689,7 @@ static void syncCheckRole(SSyncPeer *pPeer, SPeerStatus peersStatus[], int8_t ne if (pMaster) { // master is there pNode->pMaster = pMaster; - sDebug("%s, it is the master, ver:%" PRIu64, pMaster->id, pMaster->version); + sDebug("%s, it is the master, sver:%" PRIu64, pMaster->id, pMaster->version); if (syncValidateMaster(pPeer) < 0) return; @@ -697,7 +697,7 @@ static void syncCheckRole(SSyncPeer *pPeer, SPeerStatus peersStatus[], int8_t ne if (nodeVersion < pMaster->version) { syncRequired = 1; } else { - sInfo("%s is master, work as slave, ver:%" PRIu64, pMaster->id, pMaster->version); + sInfo("%s is master, work as slave, sver:%" PRIu64, pMaster->id, pMaster->version); nodeRole = TAOS_SYNC_ROLE_SLAVE; (*pNode->notifyRole)(pNode->ahandle, nodeRole); } @@ -854,7 +854,7 @@ static void syncProcessFwdResponse(char *cont, SSyncPeer *pPeer) { SSyncFwds *pSyncFwds = pNode->pSyncFwds; SFwdInfo * pFwdInfo; - sDebug("%s, forward-rsp is received, code:%x ver:%" PRIu64, pPeer->id, pFwdRsp->code, pFwdRsp->version); + sDebug("%s, forward-rsp is received, code:%x hver:%" PRIu64, pPeer->id, pFwdRsp->code, pFwdRsp->version); SFwdInfo *pFirst = pSyncFwds->fwdInfo + pSyncFwds->first; if (pFirst->version <= pFwdRsp->version && pSyncFwds->fwds > 0) { @@ -891,7 +891,7 @@ static void syncProcessPeersStatusMsg(char *cont, SSyncPeer *pPeer) { SSyncNode * pNode = pPeer->pSyncNode; SPeersStatus *pPeersStatus = (SPeersStatus *)cont; - sDebug("%s, status msg is received, self:%s ver:%" PRIu64 " peer:%s ver:%" PRIu64 ", ack:%d", pPeer->id, + sDebug("%s, status msg is received, self:%s sver:%" PRIu64 " peer:%s sver:%" PRIu64 ", ack:%d", pPeer->id, syncRole[nodeRole], nodeVersion, syncRole[pPeersStatus->role], pPeersStatus->version, pPeersStatus->ack); pPeer->version = pPeersStatus->version; @@ -979,7 +979,7 @@ static void syncSendPeersStatusMsgToPeer(SSyncPeer *pPeer, char ack) { int32_t retLen = write(pPeer->peerFd, msg, statusMsgLen); if (retLen == statusMsgLen) { - sDebug("%s, status msg is sent, self:%s ver:%" PRIu64 ", ack:%d", pPeer->id, syncRole[pPeersStatus->role], + sDebug("%s, status msg is sent, self:%s sver:%" PRIu64 ", ack:%d", pPeer->id, syncRole[pPeersStatus->role], pPeersStatus->version, pPeersStatus->ack); } else { sDebug("%s, failed to send status msg, restart", pPeer->id); @@ -1154,7 +1154,7 @@ static void syncSaveFwdInfo(SSyncNode *pNode, uint64_t version, void *mhandle) { pFwdInfo->time = time; pSyncFwds->fwds++; - sDebug("vgId:%d, fwd info is saved, ver:%" PRIu64 " fwds:%d ", pNode->vgId, version, pSyncFwds->fwds); + sDebug("vgId:%d, fwd info is saved, hver:%" PRIu64 " fwds:%d ", pNode->vgId, version, pSyncFwds->fwds); } static void syncRemoveConfirmedFwdInfo(SSyncNode *pNode) { @@ -1168,7 +1168,7 @@ static void syncRemoveConfirmedFwdInfo(SSyncNode *pNode) { pSyncFwds->first = (pSyncFwds->first + 1) % tsMaxFwdInfo; pSyncFwds->fwds--; if (pSyncFwds->fwds == 0) pSyncFwds->first = pSyncFwds->last; - // sDebug("vgId:%d, fwd info is removed, ver:%d, fwds:%d", + // sDebug("vgId:%d, fwd info is removed, hver:%d, fwds:%d", // pNode->vgId, pFwdInfo->version, pSyncFwds->fwds); memset(pFwdInfo, 0, sizeof(SFwdInfo)); } @@ -1191,7 +1191,7 @@ static void syncProcessFwdAck(SSyncNode *pNode, SFwdInfo *pFwdInfo, int32_t code } if (confirm && pFwdInfo->confirmed == 0) { - sDebug("vgId:%d, forward is confirmed, ver:%" PRIu64 " code:%x", pNode->vgId, pFwdInfo->version, pFwdInfo->code); + sDebug("vgId:%d, forward is confirmed, hver:%" PRIu64 " code:%x", pNode->vgId, pFwdInfo->version, pFwdInfo->code); (*pNode->confirmForward)(pNode->ahandle, pFwdInfo->mhandle, pFwdInfo->code); pFwdInfo->confirmed = 1; } @@ -1204,14 +1204,17 @@ static void syncMonitorFwdInfos(void *param, void *tmrId) { SSyncFwds *pSyncFwds = pNode->pSyncFwds; - if (pSyncFwds) {; - uint64_t time = taosGetTimestampMs(); + if (pSyncFwds) { + int64_t time = taosGetTimestampMs(); if (pSyncFwds->fwds > 0) { pthread_mutex_lock(&(pNode->mutex)); for (int32_t i = 0; i < pSyncFwds->fwds; ++i) { SFwdInfo *pFwdInfo = pSyncFwds->fwdInfo + (pSyncFwds->first + i) % tsMaxFwdInfo; - if (time - pFwdInfo->time < 2000) break; + if (ABS(time - pFwdInfo->time) < 2000) break; + + sDebug("vgId:%d, forward info expired, hver:%" PRIu64 " curtime:%" PRIu64 " savetime:%" PRIu64, pNode->vgId, + pFwdInfo->version, time, pFwdInfo->time); syncProcessFwdAck(pNode, pFwdInfo, TSDB_CODE_RPC_NETWORK_UNAVAIL); } @@ -1234,7 +1237,7 @@ static int32_t syncForwardToPeerImpl(SSyncNode *pNode, void *data, void *mhandle if (pWalHead->version > nodeVersion + 1) { - sError("vgId:%d, hver:%" PRIu64 ", inconsistent with ver:%" PRIu64, pNode->vgId, pWalHead->version, nodeVersion); + sError("vgId:%d, hver:%" PRIu64 ", inconsistent with sver:%" PRIu64, pNode->vgId, pWalHead->version, nodeVersion); if (nodeRole == TAOS_SYNC_ROLE_SLAVE) { sInfo("vgId:%d, restart connection", pNode->vgId); for (int32_t i = 0; i < pNode->replica; ++i) { @@ -1277,9 +1280,9 @@ static int32_t syncForwardToPeerImpl(SSyncNode *pNode, void *data, void *mhandle int32_t retLen = write(pPeer->peerFd, pSyncHead, fwdLen); if (retLen == fwdLen) { - sDebug("%s, forward is sent, ver:%" PRIu64 " contLen:%d", pPeer->id, pWalHead->version, pWalHead->len); + sDebug("%s, forward is sent, hver:%" PRIu64 " contLen:%d", pPeer->id, pWalHead->version, pWalHead->len); } else { - sError("%s, failed to forward, ver:%" PRIu64 " retLen:%d", pPeer->id, pWalHead->version, retLen); + sError("%s, failed to forward, hver:%" PRIu64 " retLen:%d", pPeer->id, pWalHead->version, retLen); syncRestartConnection(pPeer); } } diff --git a/src/sync/src/syncRestore.c b/src/sync/src/syncRestore.c index 5d7b9eac9b..33bd96ebb3 100644 --- a/src/sync/src/syncRestore.c +++ b/src/sync/src/syncRestore.c @@ -214,7 +214,7 @@ int32_t syncSaveIntoBuffer(SSyncPeer *pPeer, SWalHead *pHead) { memcpy(pRecv->offset, pHead, len); pRecv->offset += len; pRecv->forwards++; - sDebug("%s, fwd is saved into queue, ver:%" PRIu64 " fwds:%d", pPeer->id, pHead->version, pRecv->forwards); + sDebug("%s, fwd is saved into queue, hver:%" PRIu64 " fwds:%d", pPeer->id, pHead->version, pRecv->forwards); } else { sError("%s, buffer size:%d is too small", pPeer->id, pRecv->bufferSize); pRecv->code = -1; // set error code diff --git a/src/sync/src/syncRetrieve.c b/src/sync/src/syncRetrieve.c index 21151f1199..52d1bded31 100644 --- a/src/sync/src/syncRetrieve.c +++ b/src/sync/src/syncRetrieve.c @@ -268,7 +268,7 @@ static int32_t syncRetrieveLastWal(SSyncPeer *pPeer, char *name, uint64_t fversi break; } - sDebug("%s, last wal is forwarded, ver:%" PRIu64, pPeer->id, pHead->version); + sDebug("%s, last wal is forwarded, hver:%" PRIu64, pPeer->id, pHead->version); int32_t ret = taosWriteMsg(pPeer->syncFd, pHead, wsize); if (ret != wsize) break; pPeer->sversion = pHead->version; diff --git a/src/wal/src/walWrite.c b/src/wal/src/walWrite.c index 72464d4309..36b3dba165 100644 --- a/src/wal/src/walWrite.c +++ b/src/wal/src/walWrite.c @@ -144,9 +144,9 @@ void walFsync(void *handle, bool forceFsync) { if (pWal == NULL || pWal->fd < 0) return; if (forceFsync || (pWal->level == TAOS_WAL_FSYNC && pWal->fsyncPeriod == 0)) { - wTrace("vgId:%d, file:%s, do fsync", pWal->vgId, pWal->name); + wTrace("vgId:%d, fileId:%" PRId64 ", do fsync", pWal->vgId, pWal->fileId); if (fsync(pWal->fd) < 0) { - wError("vgId:%d, file:%s, fsync failed since %s", pWal->vgId, pWal->name, strerror(errno)); + wError("vgId:%d, fileId:%" PRId64 ", fsync failed since %s", pWal->vgId, pWal->fileId, strerror(errno)); } } } From f38b218247c7466b2c4e5b708dffa7460c2a1c51 Mon Sep 17 00:00:00 2001 From: Shengliang Guan Date: Wed, 18 Nov 2020 14:45:00 +0800 Subject: [PATCH 03/13] TD-2046 --- src/mnode/inc/mnodeSdb.h | 26 +- src/mnode/src/mnodeAcct.c | 28 +-- src/mnode/src/mnodeCluster.c | 28 +-- src/mnode/src/mnodeDb.c | 36 +-- src/mnode/src/mnodeDnode.c | 32 +-- src/mnode/src/mnodeMnode.c | 32 +-- src/mnode/src/mnodeSdb.c | 396 +++++++++++++++--------------- src/mnode/src/mnodeTable.c | 102 ++++---- src/mnode/src/mnodeUser.c | 34 +-- src/mnode/src/mnodeVgroup.c | 48 ++-- src/plugins/http/inc/httpInt.h | 2 +- src/plugins/http/src/httpHandle.c | 4 +- 12 files changed, 384 insertions(+), 384 deletions(-) diff --git a/src/mnode/inc/mnodeSdb.h b/src/mnode/inc/mnodeSdb.h index f4854f69a0..938a8a40fd 100644 --- a/src/mnode/inc/mnodeSdb.h +++ b/src/mnode/inc/mnodeSdb.h @@ -47,7 +47,7 @@ typedef enum { SDB_OPER_LOCAL } ESdbOper; -typedef struct SSdbOper { +typedef struct SSWriteMsg { ESdbOper type; int32_t rowSize; int32_t retCode; // for callback in sdb queue @@ -58,7 +58,7 @@ typedef struct SSdbOper { void * pObj; void * rowData; struct SMnodeMsg *pMsg; -} SSdbOper; +} SSWriteMsg; typedef struct { char *tableName; @@ -67,13 +67,13 @@ typedef struct { int32_t refCountPos; ESdbTable tableId; ESdbKey keyType; - int32_t (*insertFp)(SSdbOper *pOper); - int32_t (*deleteFp)(SSdbOper *pOper); - int32_t (*updateFp)(SSdbOper *pOper); - int32_t (*encodeFp)(SSdbOper *pOper); - int32_t (*decodeFp)(SSdbOper *pDesc); - int32_t (*destroyFp)(SSdbOper *pDesc); - int32_t (*restoredFp)(); + int32_t (*fpInsert)(SSWriteMsg *pWrite); + int32_t (*fpDelete)(SSWriteMsg *pWrite); + int32_t (*fpUpdate)(SSWriteMsg *pWrite); + int32_t (*fpEncode)(SSWriteMsg *pWrite); + int32_t (*fpDecode)(SSWriteMsg *pWrite); + int32_t (*fpDestroy)(SSWriteMsg *pWrite); + int32_t (*fpDestored)(); } SSdbTableDesc; int32_t sdbInit(); @@ -84,10 +84,10 @@ bool sdbIsMaster(); bool sdbIsServing(); void sdbUpdateMnodeRoles(); -int32_t sdbInsertRow(SSdbOper *pOper); -int32_t sdbDeleteRow(SSdbOper *pOper); -int32_t sdbUpdateRow(SSdbOper *pOper); -int32_t sdbInsertRowImp(SSdbOper *pOper); +int32_t sdbInsertRow(SSWriteMsg *pWrite); +int32_t sdbDeleteRow(SSWriteMsg *pWrite); +int32_t sdbUpdateRow(SSWriteMsg *pWrite); +int32_t sdbInsertRowImp(SSWriteMsg *pWrite); void *sdbGetRow(void *handle, void *key); void *sdbFetchRow(void *handle, void *pIter, void **ppRow); diff --git a/src/mnode/src/mnodeAcct.c b/src/mnode/src/mnodeAcct.c index 365cf656de..c6d366ebb3 100644 --- a/src/mnode/src/mnodeAcct.c +++ b/src/mnode/src/mnodeAcct.c @@ -31,14 +31,14 @@ void * tsAcctSdb = NULL; static int32_t tsAcctUpdateSize; static int32_t mnodeCreateRootAcct(); -static int32_t mnodeAcctActionDestroy(SSdbOper *pOper) { +static int32_t mnodeAcctActionDestroy(SSWriteMsg *pOper) { SAcctObj *pAcct = pOper->pObj; pthread_mutex_destroy(&pAcct->mutex); tfree(pOper->pObj); return TSDB_CODE_SUCCESS; } -static int32_t mnodeAcctActionInsert(SSdbOper *pOper) { +static int32_t mnodeAcctActionInsert(SSWriteMsg *pOper) { SAcctObj *pAcct = pOper->pObj; memset(&pAcct->acctInfo, 0, sizeof(SAcctInfo)); pAcct->acctInfo.accessState = TSDB_VN_ALL_ACCCESS; @@ -46,14 +46,14 @@ static int32_t mnodeAcctActionInsert(SSdbOper *pOper) { return TSDB_CODE_SUCCESS; } -static int32_t mnodeAcctActionDelete(SSdbOper *pOper) { +static int32_t mnodeAcctActionDelete(SSWriteMsg *pOper) { SAcctObj *pAcct = pOper->pObj; mnodeDropAllUsers(pAcct); mnodeDropAllDbs(pAcct); return TSDB_CODE_SUCCESS; } -static int32_t mnodeAcctActionUpdate(SSdbOper *pOper) { +static int32_t mnodeAcctActionUpdate(SSWriteMsg *pOper) { SAcctObj *pAcct = pOper->pObj; SAcctObj *pSaved = mnodeGetAcct(pAcct->user); if (pAcct != pSaved) { @@ -64,14 +64,14 @@ static int32_t mnodeAcctActionUpdate(SSdbOper *pOper) { return TSDB_CODE_SUCCESS; } -static int32_t mnodeAcctActionEncode(SSdbOper *pOper) { +static int32_t mnodeAcctActionEncode(SSWriteMsg *pOper) { SAcctObj *pAcct = pOper->pObj; memcpy(pOper->rowData, pAcct, tsAcctUpdateSize); pOper->rowSize = tsAcctUpdateSize; return TSDB_CODE_SUCCESS; } -static int32_t mnodeAcctActionDecode(SSdbOper *pOper) { +static int32_t mnodeAcctActionDecode(SSWriteMsg *pOper) { SAcctObj *pAcct = (SAcctObj *) calloc(1, sizeof(SAcctObj)); if (pAcct == NULL) return TSDB_CODE_MND_OUT_OF_MEMORY; @@ -106,13 +106,13 @@ int32_t mnodeInitAccts() { .maxRowSize = tsAcctUpdateSize, .refCountPos = (int8_t *)(&tObj.refCount) - (int8_t *)&tObj, .keyType = SDB_KEY_STRING, - .insertFp = mnodeAcctActionInsert, - .deleteFp = mnodeAcctActionDelete, - .updateFp = mnodeAcctActionUpdate, - .encodeFp = mnodeAcctActionEncode, - .decodeFp = mnodeAcctActionDecode, - .destroyFp = mnodeAcctActionDestroy, - .restoredFp = mnodeAcctActionRestored + .fpInsert = mnodeAcctActionInsert, + .fpDelete = mnodeAcctActionDelete, + .fpUpdate = mnodeAcctActionUpdate, + .fpEncode = mnodeAcctActionEncode, + .fpDecode = mnodeAcctActionDecode, + .fpDestroy = mnodeAcctActionDestroy, + .fpDestored = mnodeAcctActionRestored }; tsAcctSdb = sdbOpenTable(&tableDesc); @@ -226,7 +226,7 @@ static int32_t mnodeCreateRootAcct() { pAcct->acctId = sdbGetId(tsAcctSdb); pAcct->createdTime = taosGetTimestampMs(); - SSdbOper oper = { + SSWriteMsg oper = { .type = SDB_OPER_GLOBAL, .table = tsAcctSdb, .pObj = pAcct, diff --git a/src/mnode/src/mnodeCluster.c b/src/mnode/src/mnodeCluster.c index 98587cf53d..3b2b668a1f 100644 --- a/src/mnode/src/mnodeCluster.c +++ b/src/mnode/src/mnodeCluster.c @@ -32,31 +32,31 @@ static int32_t mnodeCreateCluster(); static int32_t mnodeGetClusterMeta(STableMetaMsg *pMeta, SShowObj *pShow, void *pConn); static int32_t mnodeRetrieveClusters(SShowObj *pShow, char *data, int32_t rows, void *pConn); -static int32_t mnodeClusterActionDestroy(SSdbOper *pOper) { +static int32_t mnodeClusterActionDestroy(SSWriteMsg *pOper) { tfree(pOper->pObj); return TSDB_CODE_SUCCESS; } -static int32_t mnodeClusterActionInsert(SSdbOper *pOper) { +static int32_t mnodeClusterActionInsert(SSWriteMsg *pOper) { return TSDB_CODE_SUCCESS; } -static int32_t mnodeClusterActionDelete(SSdbOper *pOper) { +static int32_t mnodeClusterActionDelete(SSWriteMsg *pOper) { return TSDB_CODE_SUCCESS; } -static int32_t mnodeClusterActionUpdate(SSdbOper *pOper) { +static int32_t mnodeClusterActionUpdate(SSWriteMsg *pOper) { return TSDB_CODE_SUCCESS; } -static int32_t mnodeClusterActionEncode(SSdbOper *pOper) { +static int32_t mnodeClusterActionEncode(SSWriteMsg *pOper) { SClusterObj *pCluster = pOper->pObj; memcpy(pOper->rowData, pCluster, tsClusterUpdateSize); pOper->rowSize = tsClusterUpdateSize; return TSDB_CODE_SUCCESS; } -static int32_t mnodeClusterActionDecode(SSdbOper *pOper) { +static int32_t mnodeClusterActionDecode(SSWriteMsg *pOper) { SClusterObj *pCluster = (SClusterObj *) calloc(1, sizeof(SClusterObj)); if (pCluster == NULL) return TSDB_CODE_MND_OUT_OF_MEMORY; @@ -91,13 +91,13 @@ int32_t mnodeInitCluster() { .maxRowSize = tsClusterUpdateSize, .refCountPos = (int8_t *)(&tObj.refCount) - (int8_t *)&tObj, .keyType = SDB_KEY_STRING, - .insertFp = mnodeClusterActionInsert, - .deleteFp = mnodeClusterActionDelete, - .updateFp = mnodeClusterActionUpdate, - .encodeFp = mnodeClusterActionEncode, - .decodeFp = mnodeClusterActionDecode, - .destroyFp = mnodeClusterActionDestroy, - .restoredFp = mnodeClusterActionRestored + .fpInsert = mnodeClusterActionInsert, + .fpDelete = mnodeClusterActionDelete, + .fpUpdate = mnodeClusterActionUpdate, + .fpEncode = mnodeClusterActionEncode, + .fpDecode = mnodeClusterActionDecode, + .fpDestroy = mnodeClusterActionDestroy, + .fpDestored = mnodeClusterActionRestored }; tsClusterSdb = sdbOpenTable(&tableDesc); @@ -145,7 +145,7 @@ static int32_t mnodeCreateCluster() { mDebug("uid is %s", pCluster->uid); } - SSdbOper oper = { + SSWriteMsg oper = { .type = SDB_OPER_GLOBAL, .table = tsClusterSdb, .pObj = pCluster, diff --git a/src/mnode/src/mnodeDb.c b/src/mnode/src/mnodeDb.c index 3b3a21aeb1..403213c22f 100644 --- a/src/mnode/src/mnodeDb.c +++ b/src/mnode/src/mnodeDb.c @@ -56,7 +56,7 @@ static void mnodeDestroyDb(SDbObj *pDb) { tfree(pDb); } -static int32_t mnodeDbActionDestroy(SSdbOper *pOper) { +static int32_t mnodeDbActionDestroy(SSWriteMsg *pOper) { mnodeDestroyDb(pOper->pObj); return TSDB_CODE_SUCCESS; } @@ -65,7 +65,7 @@ int64_t mnodeGetDbNum() { return sdbGetNumOfRows(tsDbSdb); } -static int32_t mnodeDbActionInsert(SSdbOper *pOper) { +static int32_t mnodeDbActionInsert(SSWriteMsg *pOper) { SDbObj *pDb = pOper->pObj; SAcctObj *pAcct = mnodeGetAcct(pDb->acct); @@ -91,7 +91,7 @@ static int32_t mnodeDbActionInsert(SSdbOper *pOper) { return TSDB_CODE_SUCCESS; } -static int32_t mnodeDbActionDelete(SSdbOper *pOper) { +static int32_t mnodeDbActionDelete(SSWriteMsg *pOper) { SDbObj *pDb = pOper->pObj; SAcctObj *pAcct = mnodeGetAcct(pDb->acct); @@ -107,7 +107,7 @@ static int32_t mnodeDbActionDelete(SSdbOper *pOper) { return TSDB_CODE_SUCCESS; } -static int32_t mnodeDbActionUpdate(SSdbOper *pOper) { +static int32_t mnodeDbActionUpdate(SSWriteMsg *pOper) { SDbObj *pNew = pOper->pObj; SDbObj *pDb = mnodeGetDb(pNew->name); if (pDb != NULL && pNew != pDb) { @@ -120,14 +120,14 @@ static int32_t mnodeDbActionUpdate(SSdbOper *pOper) { return TSDB_CODE_SUCCESS; } -static int32_t mnodeDbActionEncode(SSdbOper *pOper) { +static int32_t mnodeDbActionEncode(SSWriteMsg *pOper) { SDbObj *pDb = pOper->pObj; memcpy(pOper->rowData, pDb, tsDbUpdateSize); pOper->rowSize = tsDbUpdateSize; return TSDB_CODE_SUCCESS; } -static int32_t mnodeDbActionDecode(SSdbOper *pOper) { +static int32_t mnodeDbActionDecode(SSWriteMsg *pOper) { SDbObj *pDb = (SDbObj *) calloc(1, sizeof(SDbObj)); if (pDb == NULL) return TSDB_CODE_MND_OUT_OF_MEMORY; @@ -151,13 +151,13 @@ int32_t mnodeInitDbs() { .maxRowSize = tsDbUpdateSize, .refCountPos = (int8_t *)(&tObj.refCount) - (int8_t *)&tObj, .keyType = SDB_KEY_STRING, - .insertFp = mnodeDbActionInsert, - .deleteFp = mnodeDbActionDelete, - .updateFp = mnodeDbActionUpdate, - .encodeFp = mnodeDbActionEncode, - .decodeFp = mnodeDbActionDecode, - .destroyFp = mnodeDbActionDestroy, - .restoredFp = mnodeDbActionRestored + .fpInsert = mnodeDbActionInsert, + .fpDelete = mnodeDbActionDelete, + .fpUpdate = mnodeDbActionUpdate, + .fpEncode = mnodeDbActionEncode, + .fpDecode = mnodeDbActionDecode, + .fpDestroy = mnodeDbActionDestroy, + .fpDestored = mnodeDbActionRestored }; tsDbSdb = sdbOpenTable(&tableDesc); @@ -412,7 +412,7 @@ static int32_t mnodeCreateDb(SAcctObj *pAcct, SCreateDbMsg *pCreate, SMnodeMsg * pMsg->pDb = pDb; mnodeIncDbRef(pDb); - SSdbOper oper = { + SSWriteMsg oper = { .type = SDB_OPER_GLOBAL, .table = tsDbSdb, .pObj = pDb, @@ -807,7 +807,7 @@ static int32_t mnodeSetDbDropping(SDbObj *pDb) { if (pDb->status) return TSDB_CODE_SUCCESS; pDb->status = true; - SSdbOper oper = { + SSWriteMsg oper = { .type = SDB_OPER_GLOBAL, .table = tsDbSdb, .pObj = pDb @@ -1019,7 +1019,7 @@ static int32_t mnodeAlterDb(SDbObj *pDb, SAlterDbMsg *pAlter, void *pMsg) { if (memcmp(&newCfg, &pDb->cfg, sizeof(SDbCfg)) != 0) { pDb->cfg = newCfg; pDb->cfgVersion++; - SSdbOper oper = { + SSWriteMsg oper = { .type = SDB_OPER_GLOBAL, .table = tsDbSdb, .pObj = pDb, @@ -1071,7 +1071,7 @@ static int32_t mnodeDropDb(SMnodeMsg *pMsg) { SDbObj *pDb = pMsg->pDb; mInfo("db:%s, drop db from sdb", pDb->name); - SSdbOper oper = { + SSWriteMsg oper = { .type = SDB_OPER_GLOBAL, .table = tsDbSdb, .pObj = pDb, @@ -1134,7 +1134,7 @@ void mnodeDropAllDbs(SAcctObj *pAcct) { if (pDb->pAcct == pAcct) { mInfo("db:%s, drop db from sdb for acct:%s is dropped", pDb->name, pAcct->user); - SSdbOper oper = { + SSWriteMsg oper = { .type = SDB_OPER_LOCAL, .table = tsDbSdb, .pObj = pDb diff --git a/src/mnode/src/mnodeDnode.c b/src/mnode/src/mnodeDnode.c index 7e34e08373..0dd43fef89 100644 --- a/src/mnode/src/mnodeDnode.c +++ b/src/mnode/src/mnodeDnode.c @@ -87,12 +87,12 @@ static char* offlineReason[] = { "unknown", }; -static int32_t mnodeDnodeActionDestroy(SSdbOper *pOper) { +static int32_t mnodeDnodeActionDestroy(SSWriteMsg *pOper) { tfree(pOper->pObj); return TSDB_CODE_SUCCESS; } -static int32_t mnodeDnodeActionInsert(SSdbOper *pOper) { +static int32_t mnodeDnodeActionInsert(SSWriteMsg *pOper) { SDnodeObj *pDnode = pOper->pObj; if (pDnode->status != TAOS_DN_STATUS_DROPPING) { pDnode->status = TAOS_DN_STATUS_OFFLINE; @@ -107,7 +107,7 @@ static int32_t mnodeDnodeActionInsert(SSdbOper *pOper) { return TSDB_CODE_SUCCESS; } -static int32_t mnodeDnodeActionDelete(SSdbOper *pOper) { +static int32_t mnodeDnodeActionDelete(SSWriteMsg *pOper) { SDnodeObj *pDnode = pOper->pObj; #ifndef _SYNC @@ -121,7 +121,7 @@ static int32_t mnodeDnodeActionDelete(SSdbOper *pOper) { return TSDB_CODE_SUCCESS; } -static int32_t mnodeDnodeActionUpdate(SSdbOper *pOper) { +static int32_t mnodeDnodeActionUpdate(SSWriteMsg *pOper) { SDnodeObj *pNew = pOper->pObj; SDnodeObj *pDnode = mnodeGetDnode(pNew->dnodeId); if (pDnode != NULL && pNew != pDnode) { @@ -134,14 +134,14 @@ static int32_t mnodeDnodeActionUpdate(SSdbOper *pOper) { return TSDB_CODE_SUCCESS; } -static int32_t mnodeDnodeActionEncode(SSdbOper *pOper) { +static int32_t mnodeDnodeActionEncode(SSWriteMsg *pOper) { SDnodeObj *pDnode = pOper->pObj; memcpy(pOper->rowData, pDnode, tsDnodeUpdateSize); pOper->rowSize = tsDnodeUpdateSize; return TSDB_CODE_SUCCESS; } -static int32_t mnodeDnodeActionDecode(SSdbOper *pOper) { +static int32_t mnodeDnodeActionDecode(SSWriteMsg *pOper) { SDnodeObj *pDnode = (SDnodeObj *) calloc(1, sizeof(SDnodeObj)); if (pDnode == NULL) return TSDB_CODE_MND_OUT_OF_MEMORY; @@ -178,13 +178,13 @@ int32_t mnodeInitDnodes() { .maxRowSize = tsDnodeUpdateSize, .refCountPos = (int8_t *)(&tObj.refCount) - (int8_t *)&tObj, .keyType = SDB_KEY_AUTO, - .insertFp = mnodeDnodeActionInsert, - .deleteFp = mnodeDnodeActionDelete, - .updateFp = mnodeDnodeActionUpdate, - .encodeFp = mnodeDnodeActionEncode, - .decodeFp = mnodeDnodeActionDecode, - .destroyFp = mnodeDnodeActionDestroy, - .restoredFp = mnodeDnodeActionRestored + .fpInsert = mnodeDnodeActionInsert, + .fpDelete = mnodeDnodeActionDelete, + .fpUpdate = mnodeDnodeActionUpdate, + .fpEncode = mnodeDnodeActionEncode, + .fpDecode = mnodeDnodeActionDecode, + .fpDestroy = mnodeDnodeActionDestroy, + .fpDestored = mnodeDnodeActionRestored }; tsDnodeSdb = sdbOpenTable(&tableDesc); @@ -296,7 +296,7 @@ void mnodeDecDnodeRef(SDnodeObj *pDnode) { } void mnodeUpdateDnode(SDnodeObj *pDnode) { - SSdbOper oper = { + SSWriteMsg oper = { .type = SDB_OPER_GLOBAL, .table = tsDnodeSdb, .pObj = pDnode @@ -644,7 +644,7 @@ static int32_t mnodeCreateDnode(char *ep, SMnodeMsg *pMsg) { tstrncpy(pDnode->dnodeEp, ep, TSDB_EP_LEN); taosGetFqdnPortFromEp(ep, pDnode->dnodeFqdn, &pDnode->dnodePort); - SSdbOper oper = { + SSWriteMsg oper = { .type = SDB_OPER_GLOBAL, .table = tsDnodeSdb, .pObj = pDnode, @@ -665,7 +665,7 @@ static int32_t mnodeCreateDnode(char *ep, SMnodeMsg *pMsg) { } int32_t mnodeDropDnode(SDnodeObj *pDnode, void *pMsg) { - SSdbOper oper = { + SSWriteMsg oper = { .type = SDB_OPER_GLOBAL, .table = tsDnodeSdb, .pObj = pDnode, diff --git a/src/mnode/src/mnodeMnode.c b/src/mnode/src/mnodeMnode.c index 092f246c13..bf9033c5cd 100644 --- a/src/mnode/src/mnodeMnode.c +++ b/src/mnode/src/mnodeMnode.c @@ -58,12 +58,12 @@ static int32_t mnodeRetrieveMnodes(SShowObj *pShow, char *data, int32_t rows, vo #define mnodeMnodeDestroyLock() pthread_mutex_destroy(&tsMnodeLock) #endif -static int32_t mnodeMnodeActionDestroy(SSdbOper *pOper) { +static int32_t mnodeMnodeActionDestroy(SSWriteMsg *pOper) { tfree(pOper->pObj); return TSDB_CODE_SUCCESS; } -static int32_t mnodeMnodeActionInsert(SSdbOper *pOper) { +static int32_t mnodeMnodeActionInsert(SSWriteMsg *pOper) { SMnodeObj *pMnode = pOper->pObj; SDnodeObj *pDnode = mnodeGetDnode(pMnode->mnodeId); if (pDnode == NULL) return TSDB_CODE_MND_DNODE_NOT_EXIST; @@ -76,7 +76,7 @@ static int32_t mnodeMnodeActionInsert(SSdbOper *pOper) { return TSDB_CODE_SUCCESS; } -static int32_t mnodeMnodeActionDelete(SSdbOper *pOper) { +static int32_t mnodeMnodeActionDelete(SSWriteMsg *pOper) { SMnodeObj *pMnode = pOper->pObj; SDnodeObj *pDnode = mnodeGetDnode(pMnode->mnodeId); @@ -88,7 +88,7 @@ static int32_t mnodeMnodeActionDelete(SSdbOper *pOper) { return TSDB_CODE_SUCCESS; } -static int32_t mnodeMnodeActionUpdate(SSdbOper *pOper) { +static int32_t mnodeMnodeActionUpdate(SSWriteMsg *pOper) { SMnodeObj *pMnode = pOper->pObj; SMnodeObj *pSaved = mnodeGetMnode(pMnode->mnodeId); if (pMnode != pSaved) { @@ -99,14 +99,14 @@ static int32_t mnodeMnodeActionUpdate(SSdbOper *pOper) { return TSDB_CODE_SUCCESS; } -static int32_t mnodeMnodeActionEncode(SSdbOper *pOper) { +static int32_t mnodeMnodeActionEncode(SSWriteMsg *pOper) { SMnodeObj *pMnode = pOper->pObj; memcpy(pOper->rowData, pMnode, tsMnodeUpdateSize); pOper->rowSize = tsMnodeUpdateSize; return TSDB_CODE_SUCCESS; } -static int32_t mnodeMnodeActionDecode(SSdbOper *pOper) { +static int32_t mnodeMnodeActionDecode(SSWriteMsg *pOper) { SMnodeObj *pMnode = calloc(1, sizeof(SMnodeObj)); if (pMnode == NULL) return TSDB_CODE_MND_OUT_OF_MEMORY; @@ -144,13 +144,13 @@ int32_t mnodeInitMnodes() { .maxRowSize = tsMnodeUpdateSize, .refCountPos = (int8_t *)(&tObj.refCount) - (int8_t *)&tObj, .keyType = SDB_KEY_INT, - .insertFp = mnodeMnodeActionInsert, - .deleteFp = mnodeMnodeActionDelete, - .updateFp = mnodeMnodeActionUpdate, - .encodeFp = mnodeMnodeActionEncode, - .decodeFp = mnodeMnodeActionDecode, - .destroyFp = mnodeMnodeActionDestroy, - .restoredFp = mnodeMnodeActionRestored + .fpInsert = mnodeMnodeActionInsert, + .fpDelete = mnodeMnodeActionDelete, + .fpUpdate = mnodeMnodeActionUpdate, + .fpEncode = mnodeMnodeActionEncode, + .fpDecode = mnodeMnodeActionDecode, + .fpDestroy = mnodeMnodeActionDestroy, + .fpDestored = mnodeMnodeActionRestored }; tsMnodeSdb = sdbOpenTable(&tableDesc); @@ -329,7 +329,7 @@ void mnodeCreateMnode(int32_t dnodeId, char *dnodeEp, bool needConfirm) { pMnode->mnodeId = dnodeId; pMnode->createdTime = taosGetTimestampMs(); - SSdbOper oper = { + SSWriteMsg oper = { .type = SDB_OPER_GLOBAL, .table = tsMnodeSdb, .pObj = pMnode, @@ -356,7 +356,7 @@ void mnodeCreateMnode(int32_t dnodeId, char *dnodeEp, bool needConfirm) { void mnodeDropMnodeLocal(int32_t dnodeId) { SMnodeObj *pMnode = mnodeGetMnode(dnodeId); if (pMnode != NULL) { - SSdbOper oper = {.type = SDB_OPER_LOCAL, .table = tsMnodeSdb, .pObj = pMnode}; + SSWriteMsg oper = {.type = SDB_OPER_LOCAL, .table = tsMnodeSdb, .pObj = pMnode}; sdbDeleteRow(&oper); mnodeDecMnodeRef(pMnode); } @@ -371,7 +371,7 @@ int32_t mnodeDropMnode(int32_t dnodeId) { return TSDB_CODE_MND_DNODE_NOT_EXIST; } - SSdbOper oper = { + SSWriteMsg oper = { .type = SDB_OPER_GLOBAL, .table = tsMnodeSdb, .pObj = pMnode diff --git a/src/mnode/src/mnodeSdb.c b/src/mnode/src/mnodeSdb.c index 9c11fa80e8..59812068d4 100644 --- a/src/mnode/src/mnodeSdb.c +++ b/src/mnode/src/mnodeSdb.c @@ -48,7 +48,7 @@ typedef enum { SDB_STATUS_CLOSING } ESdbStatus; -typedef struct _SSdbTable { +typedef struct SSdbTable { char tableName[SDB_TABLE_LEN]; ESdbTable tableId; ESdbKey keyType; @@ -58,13 +58,13 @@ typedef struct _SSdbTable { int32_t autoIndex; int64_t numOfRows; void * iHandle; - int32_t (*insertFp)(SSdbOper *pDesc); - int32_t (*deleteFp)(SSdbOper *pOper); - int32_t (*updateFp)(SSdbOper *pOper); - int32_t (*decodeFp)(SSdbOper *pOper); - int32_t (*encodeFp)(SSdbOper *pOper); - int32_t (*destroyFp)(SSdbOper *pOper); - int32_t (*restoredFp)(); + int32_t (*fpInsert)(SSWriteMsg *pWrite); + int32_t (*fpDelete)(SSWriteMsg *pWrite); + int32_t (*fpUpdate)(SSWriteMsg *pWrite); + int32_t (*fpDecode)(SSWriteMsg *pWrite); + int32_t (*fpEncode)(SSWriteMsg *pWrite); + int32_t (*fpDestroy)(SSWriteMsg *pWrite); + int32_t (*fpDestored)(); pthread_mutex_t mutex; } SSdbTable; @@ -83,33 +83,33 @@ typedef struct { typedef struct { pthread_t thread; int32_t workerId; -} SSdbWriteWorker; +} SSWriteWorker; typedef struct { int32_t num; - SSdbWriteWorker *writeWorker; -} SSdbWriteWorkerPool; + SSWriteWorker *worker; +} SSWriteWorkerPool; extern void * tsMnodeTmr; -static void * tsUpdateSyncTmr; +static void * tsSdbTmr; static SSdbObject tsSdbObj = {0}; -static taos_qset tsSdbWriteQset; -static taos_qall tsSdbWriteQall; -static taos_queue tsSdbWriteQueue; -static SSdbWriteWorkerPool tsSdbPool; +static taos_qset tsSdbWQset; +static taos_qall tsSdbWQall; +static taos_queue tsSdbWQueue; +static SSWriteWorkerPool tsSdbPool; -static int32_t sdbWrite(void *param, void *data, int32_t type, void *pMsg); +static int32_t sdbWrite(void *wparam, void *data, int32_t type, void *pMsg); static int32_t sdbWriteToQueue(void *param, void *data, int32_t type, void *pMsg); static void * sdbWorkerFp(void *param); static int32_t sdbInitWriteWorker(); static void sdbCleanupWriteWorker(); static int32_t sdbAllocWriteQueue(); static void sdbFreeWritequeue(); -static int32_t sdbUpdateRowImp(SSdbOper *pOper); -static int32_t sdbDeleteRowImp(SSdbOper *pOper); -static int32_t sdbInsertHash(SSdbTable *pTable, SSdbOper *pOper); -static int32_t sdbUpdateHash(SSdbTable *pTable, SSdbOper *pOper); -static int32_t sdbDeleteHash(SSdbTable *pTable, SSdbOper *pOper); +static int32_t sdbUpdateRowImp(SSWriteMsg *pWrite); +static int32_t sdbDeleteRowImp(SSWriteMsg *pWrite); +static int32_t sdbInsertHash(SSdbTable *pTable, SSWriteMsg *pWrite); +static int32_t sdbUpdateHash(SSdbTable *pTable, SSWriteMsg *pWrite); +static int32_t sdbDeleteHash(SSdbTable *pTable, SSWriteMsg *pWrite); int32_t sdbGetId(void *handle) { return ((SSdbTable *)handle)->autoIndex; @@ -199,8 +199,8 @@ static void sdbRestoreTables() { for (int32_t tableId = 0; tableId < SDB_TABLE_MAX; ++tableId) { SSdbTable *pTable = sdbGetTableFromId(tableId); if (pTable == NULL) continue; - if (pTable->restoredFp) { - (*pTable->restoredFp)(); + if (pTable->fpDestored) { + (*pTable->fpDestored)(); } totalRows += pTable->numOfRows; @@ -255,11 +255,11 @@ static void sdbNotifyRole(void *ahandle, int8_t role) { FORCE_INLINE static void sdbConfirmForward(void *ahandle, void *param, int32_t code) { assert(param); - SSdbOper * pOper = param; - SMnodeMsg *pMsg = pOper->pMsg; - if (code <= 0) pOper->retCode = code; + SSWriteMsg * pWrite = param; + SMnodeMsg *pMsg = pWrite->pMsg; + if (code <= 0) pWrite->retCode = code; - int32_t processedCount = atomic_add_fetch_32(&pOper->processedCount, 1); + int32_t processedCount = atomic_add_fetch_32(&pWrite->processedCount, 1); if (processedCount <= 1) { if (pMsg != NULL) { sdbDebug("vgId:1, msg:%p waiting for confirm, count:%d code:%x", pMsg, processedCount, code); @@ -272,40 +272,40 @@ static void sdbConfirmForward(void *ahandle, void *param, int32_t code) { } // failed to forward, need revert insert - if (pOper->retCode != TSDB_CODE_SUCCESS) { - SWalHead *pHead = (void *)pOper + sizeof(SSdbOper) + SDB_SYNC_HACK; + if (pWrite->retCode != TSDB_CODE_SUCCESS) { + SWalHead *pHead = (void *)pWrite + sizeof(SSWriteMsg) + SDB_SYNC_HACK; int32_t action = pHead->msgType % 10; - sdbError("vgId:1, key:%p:%s hver:%" PRIu64 " action:%d, failed to foward since %s", pOper->pObj, - sdbGetKeyStr(pOper->table, pHead->cont), pHead->version, action, tstrerror(pOper->retCode)); + sdbError("vgId:1, key:%p:%s hver:%" PRIu64 " action:%d, failed to foward since %s", pWrite->pObj, + sdbGetKeyStr(pWrite->table, pHead->cont), pHead->version, action, tstrerror(pWrite->retCode)); if (action == SDB_ACTION_INSERT) { // It's better to create a table in two stages, create it first and then set it success - //sdbDeleteHash(pOper->table, pOper); - SSdbOper oper = { + //sdbDeleteHash(pWrite->table, pWrite); + SSWriteMsg oper = { .type = SDB_OPER_GLOBAL, - .table = pOper->table, - .pObj = pOper->pObj + .table = pWrite->table, + .pObj = pWrite->pObj }; sdbDeleteRow(&oper); } } - if (pOper->writeCb != NULL) { - pOper->retCode = (*pOper->writeCb)(pMsg, pOper->retCode); + if (pWrite->writeCb != NULL) { + pWrite->retCode = (*pWrite->writeCb)(pMsg, pWrite->retCode); } - dnodeSendRpcMWriteRsp(pMsg, pOper->retCode); + dnodeSendRpcMWriteRsp(pMsg, pWrite->retCode); // if ahandle, means this func is called by sdb write if (ahandle == NULL) { - sdbDecRef(pOper->table, pOper->pObj); + sdbDecRef(pWrite->table, pWrite->pObj); } - taosFreeQitem(pOper); + taosFreeQitem(pWrite); } static void sdbUpdateSyncTmrFp(void *param, void *tmrId) { sdbUpdateSync(NULL); } void sdbUpdateAsync() { - taosTmrReset(sdbUpdateSyncTmrFp, 200, NULL, tsMnodeTmr, &tsUpdateSyncTmr); + taosTmrReset(sdbUpdateSyncTmrFp, 200, NULL, tsMnodeTmr, &tsSdbTmr); } void sdbUpdateSync(void *pMnodes) { @@ -462,8 +462,8 @@ void sdbDecRef(void *handle, void *pObj) { int32_t *updateEnd = pObj + pTable->refCountPos - 4; if (refCount <= 0 && *updateEnd) { sdbTrace("vgId:1, sdb:%s, key:%p:%s:%d destroyed", pTable->tableName, pObj, sdbGetObjStr(pTable, pObj), refCount); - SSdbOper oper = {.pObj = pObj}; - (*pTable->destroyFp)(&oper); + SSWriteMsg oper = {.pObj = pObj}; + (*pTable->fpDestroy)(&oper); } } @@ -500,8 +500,8 @@ static void *sdbGetRowFromObj(SSdbTable *pTable, void *key) { return sdbGetRow(pTable, sdbGetObjKey(pTable, key)); } -static int32_t sdbInsertHash(SSdbTable *pTable, SSdbOper *pOper) { - void * key = sdbGetObjKey(pTable, pOper->pObj); +static int32_t sdbInsertHash(SSdbTable *pTable, SSWriteMsg *pWrite) { + void * key = sdbGetObjKey(pTable, pWrite->pObj); int32_t keySize = sizeof(int32_t); if (pTable->keyType == SDB_KEY_STRING || pTable->keyType == SDB_KEY_VAR_STRING) { @@ -509,43 +509,43 @@ static int32_t sdbInsertHash(SSdbTable *pTable, SSdbOper *pOper) { } pthread_mutex_lock(&pTable->mutex); - taosHashPut(pTable->iHandle, key, keySize, &pOper->pObj, sizeof(int64_t)); + taosHashPut(pTable->iHandle, key, keySize, &pWrite->pObj, sizeof(int64_t)); pthread_mutex_unlock(&pTable->mutex); - sdbIncRef(pTable, pOper->pObj); + sdbIncRef(pTable, pWrite->pObj); atomic_add_fetch_32(&pTable->numOfRows, 1); if (pTable->keyType == SDB_KEY_AUTO) { - pTable->autoIndex = MAX(pTable->autoIndex, *((uint32_t *)pOper->pObj)); + pTable->autoIndex = MAX(pTable->autoIndex, *((uint32_t *)pWrite->pObj)); } else { atomic_add_fetch_32(&pTable->autoIndex, 1); } sdbDebug("vgId:1, sdb:%s, insert key:%s to hash, rowSize:%d rows:%" PRId64 ", msg:%p", pTable->tableName, - sdbGetObjStr(pTable, pOper->pObj), pOper->rowSize, pTable->numOfRows, pOper->pMsg); + sdbGetObjStr(pTable, pWrite->pObj), pWrite->rowSize, pTable->numOfRows, pWrite->pMsg); - int32_t code = (*pTable->insertFp)(pOper); + int32_t code = (*pTable->fpInsert)(pWrite); if (code != TSDB_CODE_SUCCESS) { sdbError("vgId:1, sdb:%s, failed to insert key:%s to hash, remove it", pTable->tableName, - sdbGetObjStr(pTable, pOper->pObj)); - sdbDeleteHash(pTable, pOper); + sdbGetObjStr(pTable, pWrite->pObj)); + sdbDeleteHash(pTable, pWrite); } return TSDB_CODE_SUCCESS; } -static int32_t sdbDeleteHash(SSdbTable *pTable, SSdbOper *pOper) { - int32_t *updateEnd = pOper->pObj + pTable->refCountPos - 4; +static int32_t sdbDeleteHash(SSdbTable *pTable, SSWriteMsg *pWrite) { + int32_t *updateEnd = pWrite->pObj + pTable->refCountPos - 4; bool set = atomic_val_compare_exchange_32(updateEnd, 0, 1) == 0; if (!set) { sdbError("vgId:1, sdb:%s, failed to delete key:%s from hash, for it already removed", pTable->tableName, - sdbGetObjStr(pTable, pOper->pObj)); + sdbGetObjStr(pTable, pWrite->pObj)); return TSDB_CODE_MND_SDB_OBJ_NOT_THERE; } - (*pTable->deleteFp)(pOper); + (*pTable->fpDelete)(pWrite); - void * key = sdbGetObjKey(pTable, pOper->pObj); + void * key = sdbGetObjKey(pTable, pWrite->pObj); int32_t keySize = sizeof(int32_t); if (pTable->keyType == SDB_KEY_STRING || pTable->keyType == SDB_KEY_VAR_STRING) { keySize = strlen((char *)key); @@ -558,23 +558,23 @@ static int32_t sdbDeleteHash(SSdbTable *pTable, SSdbOper *pOper) { atomic_sub_fetch_32(&pTable->numOfRows, 1); sdbDebug("vgId:1, sdb:%s, delete key:%s from hash, numOfRows:%" PRId64 ", msg:%p", pTable->tableName, - sdbGetObjStr(pTable, pOper->pObj), pTable->numOfRows, pOper->pMsg); + sdbGetObjStr(pTable, pWrite->pObj), pTable->numOfRows, pWrite->pMsg); - sdbDecRef(pTable, pOper->pObj); + sdbDecRef(pTable, pWrite->pObj); return TSDB_CODE_SUCCESS; } -static int32_t sdbUpdateHash(SSdbTable *pTable, SSdbOper *pOper) { +static int32_t sdbUpdateHash(SSdbTable *pTable, SSWriteMsg *pWrite) { sdbDebug("vgId:1, sdb:%s, update key:%s in hash, numOfRows:%" PRId64 ", msg:%p", pTable->tableName, - sdbGetObjStr(pTable, pOper->pObj), pTable->numOfRows, pOper->pMsg); + sdbGetObjStr(pTable, pWrite->pObj), pTable->numOfRows, pWrite->pMsg); - (*pTable->updateFp)(pOper); + (*pTable->fpUpdate)(pWrite); return TSDB_CODE_SUCCESS; } static int sdbWrite(void *param, void *data, int32_t type, void *pMsg) { - SSdbOper *pOper = param; + SSWriteMsg *pWrite = param; SWalHead *pHead = data; int32_t tableId = pHead->msgType / 10; int32_t action = pHead->msgType % 10; @@ -614,21 +614,21 @@ static int sdbWrite(void *param, void *data, int32_t type, void *pMsg) { pthread_mutex_unlock(&tsSdbObj.mutex); // from app, oper is created - if (pOper != NULL) { + if (pWrite != NULL) { // forward to peers - pOper->processedCount = 0; - int32_t syncCode = syncForwardToPeer(tsSdbObj.sync, pHead, pOper, TAOS_QTYPE_RPC); - if (syncCode <= 0) pOper->processedCount = 1; + pWrite->processedCount = 0; + int32_t syncCode = syncForwardToPeer(tsSdbObj.sync, pHead, pWrite, TAOS_QTYPE_RPC); + if (syncCode <= 0) pWrite->processedCount = 1; if (syncCode < 0) { sdbError("vgId:1, sdb:%s, failed to forward req since %s action:%s key:%s hver:%" PRIu64 ", msg:%p", pTable->tableName, - tstrerror(syncCode), sdbGetActionStr(action), sdbGetKeyStr(pTable, pHead->cont), pHead->version, pOper->pMsg); + tstrerror(syncCode), sdbGetActionStr(action), sdbGetKeyStr(pTable, pHead->cont), pHead->version, pWrite->pMsg); } else if (syncCode > 0) { sdbDebug("vgId:1, sdb:%s, forward req is sent, action:%s key:%s hver:%" PRIu64 ", msg:%p", pTable->tableName, - sdbGetActionStr(action), sdbGetKeyStr(pTable, pHead->cont), pHead->version, pOper->pMsg); + sdbGetActionStr(action), sdbGetKeyStr(pTable, pHead->cont), pHead->version, pWrite->pMsg); } else { sdbTrace("vgId:1, sdb:%s, no need to send fwd req, action:%s key:%s hver:%" PRIu64 ", msg:%p", pTable->tableName, - sdbGetActionStr(action), sdbGetKeyStr(pTable, pHead->cont), pHead->version, pOper->pMsg); + sdbGetActionStr(action), sdbGetKeyStr(pTable, pHead->cont), pHead->version, pWrite->pMsg); } return syncCode; } @@ -637,12 +637,12 @@ static int sdbWrite(void *param, void *data, int32_t type, void *pMsg) { sdbGetActionStr(action), sdbGetKeyStr(pTable, pHead->cont), pHead->version); // even it is WAL/FWD, it shall be called to update version in sync - syncForwardToPeer(tsSdbObj.sync, pHead, pOper, TAOS_QTYPE_RPC); + syncForwardToPeer(tsSdbObj.sync, pHead, pWrite, TAOS_QTYPE_RPC); // from wal or forward msg, oper not created, should add into hash if (action == SDB_ACTION_INSERT) { - SSdbOper oper = {.rowSize = pHead->len, .rowData = pHead->cont, .table = pTable}; - code = (*pTable->decodeFp)(&oper); + SSWriteMsg oper = {.rowSize = pHead->len, .rowData = pHead->cont, .table = pTable}; + code = (*pTable->fpDecode)(&oper); return sdbInsertHash(pTable, &oper); } else if (action == SDB_ACTION_DELETE) { void *pRow = sdbGetRowMeta(pTable, pHead->cont); @@ -651,7 +651,7 @@ static int sdbWrite(void *param, void *data, int32_t type, void *pMsg) { sdbGetKeyStr(pTable, pHead->cont)); return TSDB_CODE_SUCCESS; } - SSdbOper oper = {.table = pTable, .pObj = pRow}; + SSWriteMsg oper = {.table = pTable, .pObj = pRow}; return sdbDeleteHash(pTable, &oper); } else if (action == SDB_ACTION_UPDATE) { void *pRow = sdbGetRowMeta(pTable, pHead->cont); @@ -660,77 +660,77 @@ static int sdbWrite(void *param, void *data, int32_t type, void *pMsg) { sdbGetKeyStr(pTable, pHead->cont)); return TSDB_CODE_SUCCESS; } - SSdbOper oper = {.rowSize = pHead->len, .rowData = pHead->cont, .table = pTable}; - code = (*pTable->decodeFp)(&oper); + SSWriteMsg oper = {.rowSize = pHead->len, .rowData = pHead->cont, .table = pTable}; + code = (*pTable->fpDecode)(&oper); return sdbUpdateHash(pTable, &oper); } else { return TSDB_CODE_MND_INVALID_MSG_TYPE; } } -int32_t sdbInsertRow(SSdbOper *pOper) { - SSdbTable *pTable = (SSdbTable *)pOper->table; +int32_t sdbInsertRow(SSWriteMsg *pWrite) { + SSdbTable *pTable = (SSdbTable *)pWrite->table; if (pTable == NULL) return TSDB_CODE_MND_SDB_INVALID_TABLE_TYPE; - if (sdbGetRowFromObj(pTable, pOper->pObj)) { + if (sdbGetRowFromObj(pTable, pWrite->pObj)) { sdbError("vgId:1, sdb:%s, failed to insert key:%s, already exist", pTable->tableName, - sdbGetObjStr(pTable, pOper->pObj)); - sdbDecRef(pTable, pOper->pObj); + sdbGetObjStr(pTable, pWrite->pObj)); + sdbDecRef(pTable, pWrite->pObj); return TSDB_CODE_MND_SDB_OBJ_ALREADY_THERE; } if (pTable->keyType == SDB_KEY_AUTO) { - *((uint32_t *)pOper->pObj) = atomic_add_fetch_32(&pTable->autoIndex, 1); + *((uint32_t *)pWrite->pObj) = atomic_add_fetch_32(&pTable->autoIndex, 1); // let vgId increase from 2 if (pTable->autoIndex == 1 && strcmp(pTable->tableName, "vgroups") == 0) { - *((uint32_t *)pOper->pObj) = atomic_add_fetch_32(&pTable->autoIndex, 1); + *((uint32_t *)pWrite->pObj) = atomic_add_fetch_32(&pTable->autoIndex, 1); } } - int32_t code = sdbInsertHash(pTable, pOper); + int32_t code = sdbInsertHash(pTable, pWrite); if (code != TSDB_CODE_SUCCESS) { sdbError("vgId:1, sdb:%s, failed to insert into hash", pTable->tableName); return code; } // just insert data into memory - if (pOper->type != SDB_OPER_GLOBAL) { + if (pWrite->type != SDB_OPER_GLOBAL) { return TSDB_CODE_SUCCESS; } - if (pOper->reqFp) { - return (*pOper->reqFp)(pOper->pMsg); + if (pWrite->reqFp) { + return (*pWrite->reqFp)(pWrite->pMsg); } else { - return sdbInsertRowImp(pOper); + return sdbInsertRowImp(pWrite); } } -int32_t sdbInsertRowImp(SSdbOper *pOper) { - SSdbTable *pTable = (SSdbTable *)pOper->table; +int32_t sdbInsertRowImp(SSWriteMsg *pWrite) { + SSdbTable *pTable = (SSdbTable *)pWrite->table; if (pTable == NULL) return TSDB_CODE_MND_SDB_INVALID_TABLE_TYPE; - int32_t size = sizeof(SSdbOper) + sizeof(SWalHead) + pTable->maxRowSize + SDB_SYNC_HACK; - SSdbOper *pNewOper = taosAllocateQitem(size); + int32_t size = sizeof(SSWriteMsg) + sizeof(SWalHead) + pTable->maxRowSize + SDB_SYNC_HACK; + SSWriteMsg *pNewOper = taosAllocateQitem(size); - SWalHead *pHead = (void *)pNewOper + sizeof(SSdbOper) + SDB_SYNC_HACK; + SWalHead *pHead = (void *)pNewOper + sizeof(SSWriteMsg) + SDB_SYNC_HACK; pHead->version = 0; - pHead->len = pOper->rowSize; + pHead->len = pWrite->rowSize; pHead->msgType = pTable->tableId * 10 + SDB_ACTION_INSERT; - pOper->rowData = pHead->cont; - (*pTable->encodeFp)(pOper); - pHead->len = pOper->rowSize; + pWrite->rowData = pHead->cont; + (*pTable->fpEncode)(pWrite); + pHead->len = pWrite->rowSize; - memcpy(pNewOper, pOper, sizeof(SSdbOper)); + memcpy(pNewOper, pWrite, sizeof(SSWriteMsg)); if (pNewOper->pMsg != NULL) { sdbDebug("vgId:1, ahandle:%p msg:%p, sdb:%s key:%p:%s, insert action is add to sdb queue", pNewOper->pMsg->rpcMsg.ahandle, - pNewOper->pMsg, pTable->tableName, pOper->pObj, sdbGetObjStr(pTable, pOper->pObj)); + pNewOper->pMsg, pTable->tableName, pWrite->pObj, sdbGetObjStr(pTable, pWrite->pObj)); } sdbIncRef(pNewOper->table, pNewOper->pObj); - taosWriteQitem(tsSdbWriteQueue, TAOS_QTYPE_RPC, pNewOper); + taosWriteQitem(tsSdbWQueue, TAOS_QTYPE_RPC, pNewOper); return TSDB_CODE_MND_ACTION_IN_PROGRESS; } @@ -743,117 +743,117 @@ bool sdbCheckRowDeleted(void *pTableInput, void *pRow) { return atomic_val_compare_exchange_32(updateEnd, 1, 1) == 1; } -int32_t sdbDeleteRow(SSdbOper *pOper) { - SSdbTable *pTable = (SSdbTable *)pOper->table; +int32_t sdbDeleteRow(SSWriteMsg *pWrite) { + SSdbTable *pTable = (SSdbTable *)pWrite->table; if (pTable == NULL) return TSDB_CODE_MND_SDB_INVALID_TABLE_TYPE; - void *pRow = sdbGetRowMetaFromObj(pTable, pOper->pObj); + void *pRow = sdbGetRowMetaFromObj(pTable, pWrite->pObj); if (pRow == NULL) { sdbDebug("vgId:1, sdb:%s, record is not there, delete failed", pTable->tableName); return TSDB_CODE_MND_SDB_OBJ_NOT_THERE; } - sdbIncRef(pTable, pOper->pObj); + sdbIncRef(pTable, pWrite->pObj); - int32_t code = sdbDeleteHash(pTable, pOper); + int32_t code = sdbDeleteHash(pTable, pWrite); if (code != TSDB_CODE_SUCCESS) { sdbError("vgId:1, sdb:%s, failed to delete from hash", pTable->tableName); - sdbDecRef(pTable, pOper->pObj); + sdbDecRef(pTable, pWrite->pObj); return code; } // just delete data from memory - if (pOper->type != SDB_OPER_GLOBAL) { - sdbDecRef(pTable, pOper->pObj); + if (pWrite->type != SDB_OPER_GLOBAL) { + sdbDecRef(pTable, pWrite->pObj); return TSDB_CODE_SUCCESS; } - if (pOper->reqFp) { - return (*pOper->reqFp)(pOper->pMsg); + if (pWrite->reqFp) { + return (*pWrite->reqFp)(pWrite->pMsg); } else { - return sdbDeleteRowImp(pOper); + return sdbDeleteRowImp(pWrite); } } -int32_t sdbDeleteRowImp(SSdbOper *pOper) { - SSdbTable *pTable = (SSdbTable *)pOper->table; +int32_t sdbDeleteRowImp(SSWriteMsg *pWrite) { + SSdbTable *pTable = (SSdbTable *)pWrite->table; if (pTable == NULL) return TSDB_CODE_MND_SDB_INVALID_TABLE_TYPE; - int32_t size = sizeof(SSdbOper) + sizeof(SWalHead) + pTable->maxRowSize + SDB_SYNC_HACK; - SSdbOper *pNewOper = taosAllocateQitem(size); + int32_t size = sizeof(SSWriteMsg) + sizeof(SWalHead) + pTable->maxRowSize + SDB_SYNC_HACK; + SSWriteMsg *pNewOper = taosAllocateQitem(size); - SWalHead *pHead = (void *)pNewOper + sizeof(SSdbOper) + SDB_SYNC_HACK; + SWalHead *pHead = (void *)pNewOper + sizeof(SSWriteMsg) + SDB_SYNC_HACK; pHead->version = 0; pHead->msgType = pTable->tableId * 10 + SDB_ACTION_DELETE; - pOper->rowData = pHead->cont; - (*pTable->encodeFp)(pOper); - pHead->len = pOper->rowSize; + pWrite->rowData = pHead->cont; + (*pTable->fpEncode)(pWrite); + pHead->len = pWrite->rowSize; - memcpy(pNewOper, pOper, sizeof(SSdbOper)); + memcpy(pNewOper, pWrite, sizeof(SSWriteMsg)); if (pNewOper->pMsg != NULL) { sdbDebug("vgId:1, ahandle:%p msg:%p, sdb:%s key:%p:%s, delete action is add to sdb queue", pNewOper->pMsg->rpcMsg.ahandle, - pNewOper->pMsg, pTable->tableName, pOper->pObj, sdbGetObjStr(pTable, pOper->pObj)); + pNewOper->pMsg, pTable->tableName, pWrite->pObj, sdbGetObjStr(pTable, pWrite->pObj)); } - taosWriteQitem(tsSdbWriteQueue, TAOS_QTYPE_RPC, pNewOper); + taosWriteQitem(tsSdbWQueue, TAOS_QTYPE_RPC, pNewOper); return TSDB_CODE_MND_ACTION_IN_PROGRESS; } -int32_t sdbUpdateRow(SSdbOper *pOper) { - SSdbTable *pTable = (SSdbTable *)pOper->table; +int32_t sdbUpdateRow(SSWriteMsg *pWrite) { + SSdbTable *pTable = (SSdbTable *)pWrite->table; if (pTable == NULL) return TSDB_CODE_MND_SDB_INVALID_TABLE_TYPE; - void *pRow = sdbGetRowMetaFromObj(pTable, pOper->pObj); + void *pRow = sdbGetRowMetaFromObj(pTable, pWrite->pObj); if (pRow == NULL) { sdbDebug("vgId:1, sdb:%s, record is not there, update failed", pTable->tableName); return TSDB_CODE_MND_SDB_OBJ_NOT_THERE; } - int32_t code = sdbUpdateHash(pTable, pOper); + int32_t code = sdbUpdateHash(pTable, pWrite); if (code != TSDB_CODE_SUCCESS) { sdbError("vgId:1, sdb:%s, failed to update hash", pTable->tableName); return code; } // just update data in memory - if (pOper->type != SDB_OPER_GLOBAL) { + if (pWrite->type != SDB_OPER_GLOBAL) { return TSDB_CODE_SUCCESS; } - if (pOper->reqFp) { - return (*pOper->reqFp)(pOper->pMsg); + if (pWrite->reqFp) { + return (*pWrite->reqFp)(pWrite->pMsg); } else { - return sdbUpdateRowImp(pOper); + return sdbUpdateRowImp(pWrite); } } -int32_t sdbUpdateRowImp(SSdbOper *pOper) { - SSdbTable *pTable = (SSdbTable *)pOper->table; +int32_t sdbUpdateRowImp(SSWriteMsg *pWrite) { + SSdbTable *pTable = (SSdbTable *)pWrite->table; if (pTable == NULL) return TSDB_CODE_MND_SDB_INVALID_TABLE_TYPE; - int32_t size = sizeof(SSdbOper) + sizeof(SWalHead) + pTable->maxRowSize + SDB_SYNC_HACK; - SSdbOper *pNewOper = taosAllocateQitem(size); + int32_t size = sizeof(SSWriteMsg) + sizeof(SWalHead) + pTable->maxRowSize + SDB_SYNC_HACK; + SSWriteMsg *pNewOper = taosAllocateQitem(size); - SWalHead *pHead = (void *)pNewOper + sizeof(SSdbOper) + SDB_SYNC_HACK; + SWalHead *pHead = (void *)pNewOper + sizeof(SSWriteMsg) + SDB_SYNC_HACK; pHead->version = 0; pHead->msgType = pTable->tableId * 10 + SDB_ACTION_UPDATE; - pOper->rowData = pHead->cont; - (*pTable->encodeFp)(pOper); - pHead->len = pOper->rowSize; + pWrite->rowData = pHead->cont; + (*pTable->fpEncode)(pWrite); + pHead->len = pWrite->rowSize; - memcpy(pNewOper, pOper, sizeof(SSdbOper)); + memcpy(pNewOper, pWrite, sizeof(SSWriteMsg)); if (pNewOper->pMsg != NULL) { sdbDebug("vgId:1, ahandle:%p msg:%p, sdb:%s key:%p:%s, update action is add to sdb queue", pNewOper->pMsg->rpcMsg.ahandle, - pNewOper->pMsg, pTable->tableName, pOper->pObj, sdbGetObjStr(pTable, pOper->pObj)); + pNewOper->pMsg, pTable->tableName, pWrite->pObj, sdbGetObjStr(pTable, pWrite->pObj)); } sdbIncRef(pNewOper->table, pNewOper->pObj); - taosWriteQitem(tsSdbWriteQueue, TAOS_QTYPE_RPC, pNewOper); + taosWriteQitem(tsSdbWQueue, TAOS_QTYPE_RPC, pNewOper); return TSDB_CODE_MND_ACTION_IN_PROGRESS; } @@ -903,13 +903,13 @@ void *sdbOpenTable(SSdbTableDesc *pDesc) { pTable->hashSessions = pDesc->hashSessions; pTable->maxRowSize = pDesc->maxRowSize; pTable->refCountPos = pDesc->refCountPos; - pTable->insertFp = pDesc->insertFp; - pTable->deleteFp = pDesc->deleteFp; - pTable->updateFp = pDesc->updateFp; - pTable->encodeFp = pDesc->encodeFp; - pTable->decodeFp = pDesc->decodeFp; - pTable->destroyFp = pDesc->destroyFp; - pTable->restoredFp = pDesc->restoredFp; + pTable->fpInsert = pDesc->fpInsert; + pTable->fpDelete = pDesc->fpDelete; + pTable->fpUpdate = pDesc->fpUpdate; + pTable->fpEncode = pDesc->fpEncode; + pTable->fpDecode = pDesc->fpDecode; + pTable->fpDestroy = pDesc->fpDestroy; + pTable->fpDestored = pDesc->fpDestored; _hash_fn_t hashFp = taosGetDefaultHashFunction(TSDB_DATA_TYPE_INT); if (pTable->keyType == SDB_KEY_STRING || pTable->keyType == SDB_KEY_VAR_STRING) { @@ -934,12 +934,12 @@ void sdbCloseTable(void *handle) { void **ppRow = taosHashIterGet(pIter); if (ppRow == NULL) continue; - SSdbOper oper = { + SSWriteMsg oper = { .pObj = *ppRow, .table = pTable, }; - (*pTable->destroyFp)(&oper); + (*pTable->fpDestroy)(&oper); } taosHashDestroyIter(pIter); @@ -952,11 +952,11 @@ void sdbCloseTable(void *handle) { int32_t sdbInitWriteWorker() { tsSdbPool.num = 1; - tsSdbPool.writeWorker = (SSdbWriteWorker *)calloc(sizeof(SSdbWriteWorker), tsSdbPool.num); + tsSdbPool.worker = (SSWriteWorker *)calloc(sizeof(SSWriteWorker), tsSdbPool.num); - if (tsSdbPool.writeWorker == NULL) return -1; + if (tsSdbPool.worker == NULL) return -1; for (int32_t i = 0; i < tsSdbPool.num; ++i) { - SSdbWriteWorker *pWorker = tsSdbPool.writeWorker + i; + SSWriteWorker *pWorker = tsSdbPool.worker + i; pWorker->workerId = i; } @@ -968,45 +968,45 @@ int32_t sdbInitWriteWorker() { void sdbCleanupWriteWorker() { for (int32_t i = 0; i < tsSdbPool.num; ++i) { - SSdbWriteWorker *pWorker = tsSdbPool.writeWorker + i; + SSWriteWorker *pWorker = tsSdbPool.worker + i; if (pWorker->thread) { - taosQsetThreadResume(tsSdbWriteQset); + taosQsetThreadResume(tsSdbWQset); } } for (int32_t i = 0; i < tsSdbPool.num; ++i) { - SSdbWriteWorker *pWorker = tsSdbPool.writeWorker + i; + SSWriteWorker *pWorker = tsSdbPool.worker + i; if (pWorker->thread) { pthread_join(pWorker->thread, NULL); } } sdbFreeWritequeue(); - tfree(tsSdbPool.writeWorker); + tfree(tsSdbPool.worker); mInfo("vgId:1, sdb write is closed"); } int32_t sdbAllocWriteQueue() { - tsSdbWriteQueue = taosOpenQueue(); - if (tsSdbWriteQueue == NULL) return TSDB_CODE_MND_OUT_OF_MEMORY; + tsSdbWQueue = taosOpenQueue(); + if (tsSdbWQueue == NULL) return TSDB_CODE_MND_OUT_OF_MEMORY; - tsSdbWriteQset = taosOpenQset(); - if (tsSdbWriteQset == NULL) { - taosCloseQueue(tsSdbWriteQueue); + tsSdbWQset = taosOpenQset(); + if (tsSdbWQset == NULL) { + taosCloseQueue(tsSdbWQueue); return TSDB_CODE_MND_OUT_OF_MEMORY; } - taosAddIntoQset(tsSdbWriteQset, tsSdbWriteQueue, NULL); + taosAddIntoQset(tsSdbWQset, tsSdbWQueue, NULL); - tsSdbWriteQall = taosAllocateQall(); - if (tsSdbWriteQall == NULL) { - taosCloseQset(tsSdbWriteQset); - taosCloseQueue(tsSdbWriteQueue); + tsSdbWQall = taosAllocateQall(); + if (tsSdbWQall == NULL) { + taosCloseQset(tsSdbWQset); + taosCloseQueue(tsSdbWQueue); return TSDB_CODE_MND_OUT_OF_MEMORY; } for (int32_t i = 0; i < tsSdbPool.num; ++i) { - SSdbWriteWorker *pWorker = tsSdbPool.writeWorker + i; + SSWriteWorker *pWorker = tsSdbPool.worker + i; pWorker->workerId = i; pthread_attr_t thAttr; @@ -1015,9 +1015,9 @@ int32_t sdbAllocWriteQueue() { if (pthread_create(&pWorker->thread, &thAttr, sdbWorkerFp, pWorker) != 0) { mError("failed to create thread to process sdb write queue, reason:%s", strerror(errno)); - taosFreeQall(tsSdbWriteQall); - taosCloseQset(tsSdbWriteQset); - taosCloseQueue(tsSdbWriteQueue); + taosFreeQall(tsSdbWQall); + taosCloseQset(tsSdbWQset); + taosCloseQueue(tsSdbWQueue); return TSDB_CODE_MND_OUT_OF_MEMORY; } @@ -1025,17 +1025,17 @@ int32_t sdbAllocWriteQueue() { mDebug("sdb write worker:%d is launched, total:%d", pWorker->workerId, tsSdbPool.num); } - mDebug("sdb write queue:%p is allocated", tsSdbWriteQueue); + mDebug("sdb write queue:%p is allocated", tsSdbWQueue); return TSDB_CODE_SUCCESS; } void sdbFreeWritequeue() { - taosCloseQueue(tsSdbWriteQueue); - taosFreeQall(tsSdbWriteQall); - taosCloseQset(tsSdbWriteQset); - tsSdbWriteQall = NULL; - tsSdbWriteQset = NULL; - tsSdbWriteQueue = NULL; + taosCloseQueue(tsSdbWQueue); + taosFreeQall(tsSdbWQall); + taosCloseQset(tsSdbWQset); + tsSdbWQall = NULL; + tsSdbWQset = NULL; + tsSdbWQueue = NULL; } int32_t sdbWriteToQueue(void *param, void *data, int32_t qtype, void *pMsg) { @@ -1044,45 +1044,45 @@ int32_t sdbWriteToQueue(void *param, void *data, int32_t qtype, void *pMsg) { SWalHead *pWal = taosAllocateQitem(size); memcpy(pWal, pHead, size); - taosWriteQitem(tsSdbWriteQueue, qtype, pWal); + taosWriteQitem(tsSdbWQueue, qtype, pWal); return 0; } static void *sdbWorkerFp(void *param) { SWalHead *pHead; - SSdbOper *pOper; + SSWriteMsg *pWrite; int32_t type; int32_t numOfMsgs; void * item; void * unUsed; while (1) { - numOfMsgs = taosReadAllQitemsFromQset(tsSdbWriteQset, tsSdbWriteQall, &unUsed); + numOfMsgs = taosReadAllQitemsFromQset(tsSdbWQset, tsSdbWQall, &unUsed); if (numOfMsgs == 0) { - sdbDebug("qset:%p, sdb got no message from qset, exiting", tsSdbWriteQset); + sdbDebug("qset:%p, sdb got no message from qset, exiting", tsSdbWQset); break; } for (int32_t i = 0; i < numOfMsgs; ++i) { - taosGetQitem(tsSdbWriteQall, &type, &item); + taosGetQitem(tsSdbWQall, &type, &item); if (type == TAOS_QTYPE_RPC) { - pOper = (SSdbOper *)item; - pOper->processedCount = 1; - pHead = (void *)pOper + sizeof(SSdbOper) + SDB_SYNC_HACK; - if (pOper->pMsg != NULL) { + pWrite = (SSWriteMsg *)item; + pWrite->processedCount = 1; + pHead = (void *)pWrite + sizeof(SSWriteMsg) + SDB_SYNC_HACK; + if (pWrite->pMsg != NULL) { sdbDebug("vgId:1, ahandle:%p msg:%p, sdb:%s key:%p:%s hver:%" PRIu64 ", will be processed in sdb queue", - pOper->pMsg->rpcMsg.ahandle, pOper->pMsg, ((SSdbTable *)pOper->table)->tableName, pOper->pObj, - sdbGetKeyStr(pOper->table, pHead->cont), pHead->version); + pWrite->pMsg->rpcMsg.ahandle, pWrite->pMsg, ((SSdbTable *)pWrite->table)->tableName, pWrite->pObj, + sdbGetKeyStr(pWrite->table, pHead->cont), pHead->version); } } else { pHead = (SWalHead *)item; - pOper = NULL; + pWrite = NULL; } - int32_t code = sdbWrite(pOper, pHead, type, NULL); + int32_t code = sdbWrite(pWrite, pHead, type, NULL); if (code > 0) code = 0; - if (pOper) { - pOper->retCode = code; + if (pWrite) { + pWrite->retCode = code; } else { pHead->len = code; // hackway } @@ -1091,13 +1091,13 @@ static void *sdbWorkerFp(void *param) { walFsync(tsSdbObj.wal, true); // browse all items, and process them one by one - taosResetQitems(tsSdbWriteQall); + taosResetQitems(tsSdbWQall); for (int32_t i = 0; i < numOfMsgs; ++i) { - taosGetQitem(tsSdbWriteQall, &type, &item); + taosGetQitem(tsSdbWQall, &type, &item); if (type == TAOS_QTYPE_RPC) { - pOper = (SSdbOper *)item; - sdbConfirmForward(NULL, pOper, pOper->retCode); + pWrite = (SSWriteMsg *)item; + sdbConfirmForward(NULL, pWrite, pWrite->retCode); } else if (type == TAOS_QTYPE_FWD) { pHead = (SWalHead *)item; syncConfirmForward(tsSdbObj.sync, pHead->version, pHead->len); diff --git a/src/mnode/src/mnodeTable.c b/src/mnode/src/mnodeTable.c index 2b5e6455c0..d3ba149f39 100644 --- a/src/mnode/src/mnodeTable.c +++ b/src/mnode/src/mnodeTable.c @@ -99,12 +99,12 @@ static void mnodeDestroyChildTable(SCTableObj *pTable) { tfree(pTable); } -static int32_t mnodeChildTableActionDestroy(SSdbOper *pOper) { +static int32_t mnodeChildTableActionDestroy(SSWriteMsg *pOper) { mnodeDestroyChildTable(pOper->pObj); return TSDB_CODE_SUCCESS; } -static int32_t mnodeChildTableActionInsert(SSdbOper *pOper) { +static int32_t mnodeChildTableActionInsert(SSWriteMsg *pOper) { SCTableObj *pTable = pOper->pObj; SVgObj *pVgroup = mnodeGetVgroup(pTable->vgId); @@ -153,7 +153,7 @@ static int32_t mnodeChildTableActionInsert(SSdbOper *pOper) { return TSDB_CODE_SUCCESS; } -static int32_t mnodeChildTableActionDelete(SSdbOper *pOper) { +static int32_t mnodeChildTableActionDelete(SSWriteMsg *pOper) { SCTableObj *pTable = pOper->pObj; if (pTable->vgId == 0) { return TSDB_CODE_MND_VGROUP_NOT_EXIST; @@ -189,7 +189,7 @@ static int32_t mnodeChildTableActionDelete(SSdbOper *pOper) { return TSDB_CODE_SUCCESS; } -static int32_t mnodeChildTableActionUpdate(SSdbOper *pOper) { +static int32_t mnodeChildTableActionUpdate(SSWriteMsg *pOper) { SCTableObj *pNew = pOper->pObj; SCTableObj *pTable = mnodeGetChildTable(pNew->info.tableId); if (pTable != pNew) { @@ -216,7 +216,7 @@ static int32_t mnodeChildTableActionUpdate(SSdbOper *pOper) { return TSDB_CODE_SUCCESS; } -static int32_t mnodeChildTableActionEncode(SSdbOper *pOper) { +static int32_t mnodeChildTableActionEncode(SSWriteMsg *pOper) { SCTableObj *pTable = pOper->pObj; assert(pTable != NULL && pOper->rowData != NULL); @@ -246,7 +246,7 @@ static int32_t mnodeChildTableActionEncode(SSdbOper *pOper) { return TSDB_CODE_SUCCESS; } -static int32_t mnodeChildTableActionDecode(SSdbOper *pOper) { +static int32_t mnodeChildTableActionDecode(SSWriteMsg *pOper) { assert(pOper->rowData != NULL); SCTableObj *pTable = calloc(1, sizeof(SCTableObj)); if (pTable == NULL) return TSDB_CODE_MND_OUT_OF_MEMORY; @@ -297,7 +297,7 @@ static int32_t mnodeChildTableActionRestored() { SDbObj *pDb = mnodeGetDbByTableId(pTable->info.tableId); if (pDb == NULL || pDb->status != TSDB_DB_STATUS_READY) { mError("ctable:%s, failed to get db or db in dropping, discard it", pTable->info.tableId); - SSdbOper desc = {.type = SDB_OPER_LOCAL, .pObj = pTable, .table = tsChildTableSdb}; + SSWriteMsg desc = {.type = SDB_OPER_LOCAL, .pObj = pTable, .table = tsChildTableSdb}; sdbDeleteRow(&desc); mnodeDecTableRef(pTable); mnodeDecDbRef(pDb); @@ -309,7 +309,7 @@ static int32_t mnodeChildTableActionRestored() { if (pVgroup == NULL) { mError("ctable:%s, failed to get vgId:%d tid:%d, discard it", pTable->info.tableId, pTable->vgId, pTable->tid); pTable->vgId = 0; - SSdbOper desc = {.type = SDB_OPER_LOCAL, .pObj = pTable, .table = tsChildTableSdb}; + SSWriteMsg desc = {.type = SDB_OPER_LOCAL, .pObj = pTable, .table = tsChildTableSdb}; sdbDeleteRow(&desc); mnodeDecTableRef(pTable); continue; @@ -320,7 +320,7 @@ static int32_t mnodeChildTableActionRestored() { mError("ctable:%s, db:%s not match with vgId:%d db:%s sid:%d, discard it", pTable->info.tableId, pDb->name, pTable->vgId, pVgroup->dbName, pTable->tid); pTable->vgId = 0; - SSdbOper desc = {.type = SDB_OPER_LOCAL, .pObj = pTable, .table = tsChildTableSdb}; + SSWriteMsg desc = {.type = SDB_OPER_LOCAL, .pObj = pTable, .table = tsChildTableSdb}; sdbDeleteRow(&desc); mnodeDecTableRef(pTable); continue; @@ -331,7 +331,7 @@ static int32_t mnodeChildTableActionRestored() { if (pSuperTable == NULL) { mError("ctable:%s, stable:%" PRIu64 " not exist", pTable->info.tableId, pTable->suid); pTable->vgId = 0; - SSdbOper desc = {.type = SDB_OPER_LOCAL, .pObj = pTable, .table = tsChildTableSdb}; + SSWriteMsg desc = {.type = SDB_OPER_LOCAL, .pObj = pTable, .table = tsChildTableSdb}; sdbDeleteRow(&desc); mnodeDecTableRef(pTable); continue; @@ -358,13 +358,13 @@ static int32_t mnodeInitChildTables() { .maxRowSize = sizeof(SCTableObj) + sizeof(SSchema) * (TSDB_MAX_TAGS + TSDB_MAX_COLUMNS + 16) + TSDB_TABLE_FNAME_LEN + TSDB_CQ_SQL_SIZE, .refCountPos = (int8_t *)(&tObj.refCount) - (int8_t *)&tObj, .keyType = SDB_KEY_VAR_STRING, - .insertFp = mnodeChildTableActionInsert, - .deleteFp = mnodeChildTableActionDelete, - .updateFp = mnodeChildTableActionUpdate, - .encodeFp = mnodeChildTableActionEncode, - .decodeFp = mnodeChildTableActionDecode, - .destroyFp = mnodeChildTableActionDestroy, - .restoredFp = mnodeChildTableActionRestored + .fpInsert = mnodeChildTableActionInsert, + .fpDelete = mnodeChildTableActionDelete, + .fpUpdate = mnodeChildTableActionUpdate, + .fpEncode = mnodeChildTableActionEncode, + .fpDecode = mnodeChildTableActionDecode, + .fpDestroy = mnodeChildTableActionDestroy, + .fpDestored = mnodeChildTableActionRestored }; tsChildTableSdb = sdbOpenTable(&tableDesc); @@ -430,12 +430,12 @@ static void mnodeDestroySuperTable(SSTableObj *pStable) { tfree(pStable); } -static int32_t mnodeSuperTableActionDestroy(SSdbOper *pOper) { +static int32_t mnodeSuperTableActionDestroy(SSWriteMsg *pOper) { mnodeDestroySuperTable(pOper->pObj); return TSDB_CODE_SUCCESS; } -static int32_t mnodeSuperTableActionInsert(SSdbOper *pOper) { +static int32_t mnodeSuperTableActionInsert(SSWriteMsg *pOper) { SSTableObj *pStable = pOper->pObj; SDbObj *pDb = mnodeGetDbByTableId(pStable->info.tableId); if (pDb != NULL && pDb->status == TSDB_DB_STATUS_READY) { @@ -446,7 +446,7 @@ static int32_t mnodeSuperTableActionInsert(SSdbOper *pOper) { return TSDB_CODE_SUCCESS; } -static int32_t mnodeSuperTableActionDelete(SSdbOper *pOper) { +static int32_t mnodeSuperTableActionDelete(SSWriteMsg *pOper) { SSTableObj *pStable = pOper->pObj; SDbObj *pDb = mnodeGetDbByTableId(pStable->info.tableId); if (pDb != NULL) { @@ -458,7 +458,7 @@ static int32_t mnodeSuperTableActionDelete(SSdbOper *pOper) { return TSDB_CODE_SUCCESS; } -static int32_t mnodeSuperTableActionUpdate(SSdbOper *pOper) { +static int32_t mnodeSuperTableActionUpdate(SSWriteMsg *pOper) { SSTableObj *pNew = pOper->pObj; SSTableObj *pTable = mnodeGetSuperTable(pNew->info.tableId); if (pTable != NULL && pTable != pNew) { @@ -483,7 +483,7 @@ static int32_t mnodeSuperTableActionUpdate(SSdbOper *pOper) { return TSDB_CODE_SUCCESS; } -static int32_t mnodeSuperTableActionEncode(SSdbOper *pOper) { +static int32_t mnodeSuperTableActionEncode(SSWriteMsg *pOper) { SSTableObj *pStable = pOper->pObj; assert(pOper->pObj != NULL && pOper->rowData != NULL); @@ -506,7 +506,7 @@ static int32_t mnodeSuperTableActionEncode(SSdbOper *pOper) { return TSDB_CODE_SUCCESS; } -static int32_t mnodeSuperTableActionDecode(SSdbOper *pOper) { +static int32_t mnodeSuperTableActionDecode(SSWriteMsg *pOper) { assert(pOper->rowData != NULL); SSTableObj *pStable = (SSTableObj *) calloc(1, sizeof(SSTableObj)); if (pStable == NULL) return TSDB_CODE_MND_OUT_OF_MEMORY; @@ -551,13 +551,13 @@ static int32_t mnodeInitSuperTables() { .maxRowSize = sizeof(SSTableObj) + sizeof(SSchema) * (TSDB_MAX_TAGS + TSDB_MAX_COLUMNS + 16) + TSDB_TABLE_FNAME_LEN, .refCountPos = (int8_t *)(&tObj.refCount) - (int8_t *)&tObj, .keyType = SDB_KEY_VAR_STRING, - .insertFp = mnodeSuperTableActionInsert, - .deleteFp = mnodeSuperTableActionDelete, - .updateFp = mnodeSuperTableActionUpdate, - .encodeFp = mnodeSuperTableActionEncode, - .decodeFp = mnodeSuperTableActionDecode, - .destroyFp = mnodeSuperTableActionDestroy, - .restoredFp = mnodeSuperTableActionRestored + .fpInsert = mnodeSuperTableActionInsert, + .fpDelete = mnodeSuperTableActionDelete, + .fpUpdate = mnodeSuperTableActionUpdate, + .fpEncode = mnodeSuperTableActionEncode, + .fpDecode = mnodeSuperTableActionDecode, + .fpDestroy = mnodeSuperTableActionDestroy, + .fpDestored = mnodeSuperTableActionRestored }; tsSuperTableSdb = sdbOpenTable(&tableDesc); @@ -828,7 +828,7 @@ static int32_t mnodeCreateSuperTableCb(SMnodeMsg *pMsg, int32_t code) { } else { mError("app:%p:%p, stable:%s, failed to create in sdb, reason:%s", pMsg->rpcMsg.ahandle, pMsg, pTable->info.tableId, tstrerror(code)); - SSdbOper desc = {.type = SDB_OPER_GLOBAL, .pObj = pTable, .table = tsSuperTableSdb}; + SSWriteMsg desc = {.type = SDB_OPER_GLOBAL, .pObj = pTable, .table = tsSuperTableSdb}; sdbDeleteRow(&desc); } @@ -878,7 +878,7 @@ static int32_t mnodeProcessCreateSuperTableMsg(SMnodeMsg *pMsg) { pMsg->pTable = (STableObj *)pStable; mnodeIncTableRef(pMsg->pTable); - SSdbOper oper = { + SSWriteMsg oper = { .type = SDB_OPER_GLOBAL, .table = tsSuperTableSdb, .pObj = pStable, @@ -937,7 +937,7 @@ static int32_t mnodeProcessDropSuperTableMsg(SMnodeMsg *pMsg) { mnodeDropAllChildTablesInStable(pStable); } - SSdbOper oper = { + SSWriteMsg oper = { .type = SDB_OPER_GLOBAL, .table = tsSuperTableSdb, .pObj = pStable, @@ -1010,7 +1010,7 @@ static int32_t mnodeAddSuperTableTag(SMnodeMsg *pMsg, SSchema schema[], int32_t mInfo("app:%p:%p, stable %s, start to add tag %s", pMsg->rpcMsg.ahandle, pMsg, pStable->info.tableId, schema[0].name); - SSdbOper oper = { + SSWriteMsg oper = { .type = SDB_OPER_GLOBAL, .table = tsSuperTableSdb, .pObj = pStable, @@ -1044,7 +1044,7 @@ static int32_t mnodeDropSuperTableTag(SMnodeMsg *pMsg, char *tagName) { mInfo("app:%p:%p, stable %s, start to drop tag %s", pMsg->rpcMsg.ahandle, pMsg, pStable->info.tableId, tagName); - SSdbOper oper = { + SSWriteMsg oper = { .type = SDB_OPER_GLOBAL, .table = tsSuperTableSdb, .pObj = pStable, @@ -1088,7 +1088,7 @@ static int32_t mnodeModifySuperTableTagName(SMnodeMsg *pMsg, char *oldTagName, c mInfo("app:%p:%p, stable %s, start to modify tag %s to %s", pMsg->rpcMsg.ahandle, pMsg, pStable->info.tableId, oldTagName, newTagName); - SSdbOper oper = { + SSWriteMsg oper = { .type = SDB_OPER_GLOBAL, .table = tsSuperTableSdb, .pObj = pStable, @@ -1162,7 +1162,7 @@ static int32_t mnodeAddSuperTableColumn(SMnodeMsg *pMsg, SSchema schema[], int32 mInfo("app:%p:%p, stable %s, start to add column", pMsg->rpcMsg.ahandle, pMsg, pStable->info.tableId); - SSdbOper oper = { + SSWriteMsg oper = { .type = SDB_OPER_GLOBAL, .table = tsSuperTableSdb, .pObj = pStable, @@ -1207,7 +1207,7 @@ static int32_t mnodeDropSuperTableColumn(SMnodeMsg *pMsg, char *colName) { mInfo("app:%p:%p, stable %s, start to delete column", pMsg->rpcMsg.ahandle, pMsg, pStable->info.tableId); - SSdbOper oper = { + SSWriteMsg oper = { .type = SDB_OPER_GLOBAL, .table = tsSuperTableSdb, .pObj = pStable, @@ -1251,7 +1251,7 @@ static int32_t mnodeChangeSuperTableColumn(SMnodeMsg *pMsg, char *oldName, char mInfo("app:%p:%p, stable %s, start to modify column %s to %s", pMsg->rpcMsg.ahandle, pMsg, pStable->info.tableId, oldName, newName); - SSdbOper oper = { + SSWriteMsg oper = { .type = SDB_OPER_GLOBAL, .table = tsSuperTableSdb, .pObj = pStable, @@ -1417,7 +1417,7 @@ void mnodeDropAllSuperTables(SDbObj *pDropDb) { if (pTable == NULL) break; if (strncmp(prefix, pTable->info.tableId, prefixLen) == 0) { - SSdbOper oper = { + SSWriteMsg oper = { .type = SDB_OPER_LOCAL, .table = tsSuperTableSdb, .pObj = pTable, @@ -1694,7 +1694,7 @@ static int32_t mnodeDoCreateChildTableCb(SMnodeMsg *pMsg, int32_t code) { } else { mError("app:%p:%p, table:%s, failed to create table sid:%d, uid:%" PRIu64 ", reason:%s", pMsg->rpcMsg.ahandle, pMsg, pTable->info.tableId, pTable->tid, pTable->uid, tstrerror(code)); - SSdbOper desc = {.type = SDB_OPER_GLOBAL, .pObj = pTable, .table = tsChildTableSdb}; + SSWriteMsg desc = {.type = SDB_OPER_GLOBAL, .pObj = pTable, .table = tsChildTableSdb}; sdbDeleteRow(&desc); return code; } @@ -1780,7 +1780,7 @@ static int32_t mnodeDoCreateChildTable(SMnodeMsg *pMsg, int32_t tid) { pMsg->pTable = (STableObj *)pTable; mnodeIncTableRef(pMsg->pTable); - SSdbOper desc = { + SSWriteMsg desc = { .type = SDB_OPER_GLOBAL, .pObj = pTable, .table = tsChildTableSdb, @@ -1901,7 +1901,7 @@ static int32_t mnodeProcessDropChildTableMsg(SMnodeMsg *pMsg) { return TSDB_CODE_MND_APP_ERROR; } - SSdbOper oper = { + SSWriteMsg oper = { .type = SDB_OPER_GLOBAL, .table = tsChildTableSdb, .pObj = pTable, @@ -2005,7 +2005,7 @@ static int32_t mnodeAddNormalTableColumn(SMnodeMsg *pMsg, SSchema schema[], int3 mInfo("app:%p:%p, ctable %s, start to add column", pMsg->rpcMsg.ahandle, pMsg, pTable->info.tableId); - SSdbOper oper = { + SSWriteMsg oper = { .type = SDB_OPER_GLOBAL, .table = tsChildTableSdb, .pObj = pTable, @@ -2038,7 +2038,7 @@ static int32_t mnodeDropNormalTableColumn(SMnodeMsg *pMsg, char *colName) { mInfo("app:%p:%p, ctable %s, start to drop column %s", pMsg->rpcMsg.ahandle, pMsg, pTable->info.tableId, colName); - SSdbOper oper = { + SSWriteMsg oper = { .type = SDB_OPER_GLOBAL, .table = tsChildTableSdb, .pObj = pTable, @@ -2075,7 +2075,7 @@ static int32_t mnodeChangeNormalTableColumn(SMnodeMsg *pMsg, char *oldName, char mInfo("app:%p:%p, ctable %s, start to modify column %s to %s", pMsg->rpcMsg.ahandle, pMsg, pTable->info.tableId, oldName, newName); - SSdbOper oper = { + SSWriteMsg oper = { .type = SDB_OPER_GLOBAL, .table = tsChildTableSdb, .pObj = pTable, @@ -2218,7 +2218,7 @@ void mnodeDropAllChildTablesInVgroups(SVgObj *pVgroup) { if (pTable == NULL) break; if (pTable->vgId == pVgroup->vgId) { - SSdbOper oper = { + SSWriteMsg oper = { .type = SDB_OPER_LOCAL, .table = tsChildTableSdb, .pObj = pTable, @@ -2251,7 +2251,7 @@ void mnodeDropAllChildTables(SDbObj *pDropDb) { if (pTable == NULL) break; if (strncmp(prefix, pTable->info.tableId, prefixLen) == 0) { - SSdbOper oper = { + SSWriteMsg oper = { .type = SDB_OPER_LOCAL, .table = tsChildTableSdb, .pObj = pTable, @@ -2280,7 +2280,7 @@ static void mnodeDropAllChildTablesInStable(SSTableObj *pStable) { if (pTable == NULL) break; if (pTable->superTable == pStable) { - SSdbOper oper = { + SSWriteMsg oper = { .type = SDB_OPER_LOCAL, .table = tsChildTableSdb, .pObj = pTable, @@ -2410,7 +2410,7 @@ static void mnodeProcessCreateChildTableRsp(SRpcMsg *rpcMsg) { } if (rpcMsg->code == TSDB_CODE_SUCCESS || rpcMsg->code == TSDB_CODE_TDB_TABLE_ALREADY_EXIST) { - SSdbOper desc = { + SSWriteMsg desc = { .type = SDB_OPER_GLOBAL, .pObj = pTable, .table = tsChildTableSdb, @@ -2440,7 +2440,7 @@ static void mnodeProcessCreateChildTableRsp(SRpcMsg *rpcMsg) { mnodeMsg->rpcMsg.ahandle, mnodeMsg, pTable->info.tableId, pTable->vgId, pTable->tid, pTable->uid, tstrerror(rpcMsg->code), mnodeMsg->rpcMsg.handle, mnodeMsg->incomingTs, sec, mnodeMsg->retry); - SSdbOper oper = {.type = SDB_OPER_GLOBAL, .table = tsChildTableSdb, .pObj = pTable}; + SSWriteMsg oper = {.type = SDB_OPER_GLOBAL, .table = tsChildTableSdb, .pObj = pTable}; sdbDeleteRow(&oper); if (rpcMsg->code == TSDB_CODE_APP_NOT_READY) { diff --git a/src/mnode/src/mnodeUser.c b/src/mnode/src/mnodeUser.c index cd02d5a935..edd0839b0c 100644 --- a/src/mnode/src/mnodeUser.c +++ b/src/mnode/src/mnodeUser.c @@ -42,12 +42,12 @@ static int32_t mnodeProcessAlterUserMsg(SMnodeMsg *pMsg); static int32_t mnodeProcessDropUserMsg(SMnodeMsg *pMsg); static int32_t mnodeProcessAuthMsg(SMnodeMsg *pMsg); -static int32_t mnodeUserActionDestroy(SSdbOper *pOper) { +static int32_t mnodeUserActionDestroy(SSWriteMsg *pOper) { tfree(pOper->pObj); return TSDB_CODE_SUCCESS; } -static int32_t mnodeUserActionInsert(SSdbOper *pOper) { +static int32_t mnodeUserActionInsert(SSWriteMsg *pOper) { SUserObj *pUser = pOper->pObj; SAcctObj *pAcct = mnodeGetAcct(pUser->acct); @@ -62,7 +62,7 @@ static int32_t mnodeUserActionInsert(SSdbOper *pOper) { return TSDB_CODE_SUCCESS; } -static int32_t mnodeUserActionDelete(SSdbOper *pOper) { +static int32_t mnodeUserActionDelete(SSWriteMsg *pOper) { SUserObj *pUser = pOper->pObj; SAcctObj *pAcct = mnodeGetAcct(pUser->acct); @@ -74,7 +74,7 @@ static int32_t mnodeUserActionDelete(SSdbOper *pOper) { return TSDB_CODE_SUCCESS; } -static int32_t mnodeUserActionUpdate(SSdbOper *pOper) { +static int32_t mnodeUserActionUpdate(SSWriteMsg *pOper) { SUserObj *pUser = pOper->pObj; SUserObj *pSaved = mnodeGetUser(pUser->user); if (pUser != pSaved) { @@ -85,14 +85,14 @@ static int32_t mnodeUserActionUpdate(SSdbOper *pOper) { return TSDB_CODE_SUCCESS; } -static int32_t mnodeUserActionEncode(SSdbOper *pOper) { +static int32_t mnodeUserActionEncode(SSWriteMsg *pOper) { SUserObj *pUser = pOper->pObj; memcpy(pOper->rowData, pUser, tsUserUpdateSize); pOper->rowSize = tsUserUpdateSize; return TSDB_CODE_SUCCESS; } -static int32_t mnodeUserActionDecode(SSdbOper *pOper) { +static int32_t mnodeUserActionDecode(SSWriteMsg *pOper) { SUserObj *pUser = (SUserObj *)calloc(1, sizeof(SUserObj)); if (pUser == NULL) return TSDB_CODE_MND_OUT_OF_MEMORY; @@ -157,13 +157,13 @@ int32_t mnodeInitUsers() { .maxRowSize = tsUserUpdateSize, .refCountPos = (int8_t *)(&tObj.refCount) - (int8_t *)&tObj, .keyType = SDB_KEY_STRING, - .insertFp = mnodeUserActionInsert, - .deleteFp = mnodeUserActionDelete, - .updateFp = mnodeUserActionUpdate, - .encodeFp = mnodeUserActionEncode, - .decodeFp = mnodeUserActionDecode, - .destroyFp = mnodeUserActionDestroy, - .restoredFp = mnodeUserActionRestored + .fpInsert = mnodeUserActionInsert, + .fpDelete = mnodeUserActionDelete, + .fpUpdate = mnodeUserActionUpdate, + .fpEncode = mnodeUserActionEncode, + .fpDecode = mnodeUserActionDecode, + .fpDestroy = mnodeUserActionDestroy, + .fpDestored = mnodeUserActionRestored }; tsUserSdb = sdbOpenTable(&tableDesc); @@ -205,7 +205,7 @@ void mnodeDecUserRef(SUserObj *pUser) { } static int32_t mnodeUpdateUser(SUserObj *pUser, void *pMsg) { - SSdbOper oper = { + SSWriteMsg oper = { .type = SDB_OPER_GLOBAL, .table = tsUserSdb, .pObj = pUser, @@ -259,7 +259,7 @@ int32_t mnodeCreateUser(SAcctObj *pAcct, char *name, char *pass, void *pMsg) { pUser->superAuth = 1; } - SSdbOper oper = { + SSWriteMsg oper = { .type = SDB_OPER_GLOBAL, .table = tsUserSdb, .pObj = pUser, @@ -279,7 +279,7 @@ int32_t mnodeCreateUser(SAcctObj *pAcct, char *name, char *pass, void *pMsg) { } static int32_t mnodeDropUser(SUserObj *pUser, void *pMsg) { - SSdbOper oper = { + SSWriteMsg oper = { .type = SDB_OPER_GLOBAL, .table = tsUserSdb, .pObj = pUser, @@ -562,7 +562,7 @@ void mnodeDropAllUsers(SAcctObj *pAcct) { if (pUser == NULL) break; if (strncmp(pUser->acct, pAcct->user, acctNameLen) == 0) { - SSdbOper oper = { + SSWriteMsg oper = { .type = SDB_OPER_LOCAL, .table = tsUserSdb, .pObj = pUser, diff --git a/src/mnode/src/mnodeVgroup.c b/src/mnode/src/mnodeVgroup.c index 9e398e94f1..da0ed1cd36 100644 --- a/src/mnode/src/mnodeVgroup.c +++ b/src/mnode/src/mnodeVgroup.c @@ -72,12 +72,12 @@ static void mnodeDestroyVgroup(SVgObj *pVgroup) { tfree(pVgroup); } -static int32_t mnodeVgroupActionDestroy(SSdbOper *pOper) { +static int32_t mnodeVgroupActionDestroy(SSWriteMsg *pOper) { mnodeDestroyVgroup(pOper->pObj); return TSDB_CODE_SUCCESS; } -static int32_t mnodeVgroupActionInsert(SSdbOper *pOper) { +static int32_t mnodeVgroupActionInsert(SSWriteMsg *pOper) { SVgObj *pVgroup = pOper->pObj; // refer to db @@ -115,7 +115,7 @@ static int32_t mnodeVgroupActionInsert(SSdbOper *pOper) { return TSDB_CODE_SUCCESS; } -static int32_t mnodeVgroupActionDelete(SSdbOper *pOper) { +static int32_t mnodeVgroupActionDelete(SSWriteMsg *pOper) { SVgObj *pVgroup = pOper->pObj; if (pVgroup->pDb == NULL) { @@ -137,7 +137,7 @@ static int32_t mnodeVgroupActionDelete(SSdbOper *pOper) { return TSDB_CODE_SUCCESS; } -static int32_t mnodeVgroupActionUpdate(SSdbOper *pOper) { +static int32_t mnodeVgroupActionUpdate(SSWriteMsg *pOper) { SVgObj *pNew = pOper->pObj; SVgObj *pVgroup = mnodeGetVgroup(pNew->vgId); @@ -176,7 +176,7 @@ static int32_t mnodeVgroupActionUpdate(SSdbOper *pOper) { return TSDB_CODE_SUCCESS; } -static int32_t mnodeVgroupActionEncode(SSdbOper *pOper) { +static int32_t mnodeVgroupActionEncode(SSWriteMsg *pOper) { SVgObj *pVgroup = pOper->pObj; memcpy(pOper->rowData, pVgroup, tsVgUpdateSize); SVgObj *pTmpVgroup = pOper->rowData; @@ -189,7 +189,7 @@ static int32_t mnodeVgroupActionEncode(SSdbOper *pOper) { return TSDB_CODE_SUCCESS; } -static int32_t mnodeVgroupActionDecode(SSdbOper *pOper) { +static int32_t mnodeVgroupActionDecode(SSWriteMsg *pOper) { SVgObj *pVgroup = (SVgObj *) calloc(1, sizeof(SVgObj)); if (pVgroup == NULL) return TSDB_CODE_MND_OUT_OF_MEMORY; @@ -213,13 +213,13 @@ int32_t mnodeInitVgroups() { .maxRowSize = tsVgUpdateSize, .refCountPos = (int8_t *)(&tObj.refCount) - (int8_t *)&tObj, .keyType = SDB_KEY_AUTO, - .insertFp = mnodeVgroupActionInsert, - .deleteFp = mnodeVgroupActionDelete, - .updateFp = mnodeVgroupActionUpdate, - .encodeFp = mnodeVgroupActionEncode, - .decodeFp = mnodeVgroupActionDecode, - .destroyFp = mnodeVgroupActionDestroy, - .restoredFp = mnodeVgroupActionRestored, + .fpInsert = mnodeVgroupActionInsert, + .fpDelete = mnodeVgroupActionDelete, + .fpUpdate = mnodeVgroupActionUpdate, + .fpEncode = mnodeVgroupActionEncode, + .fpDecode = mnodeVgroupActionDecode, + .fpDestroy = mnodeVgroupActionDestroy, + .fpDestored = mnodeVgroupActionRestored, }; tsVgroupSdb = sdbOpenTable(&tableDesc); @@ -253,7 +253,7 @@ SVgObj *mnodeGetVgroup(int32_t vgId) { } void mnodeUpdateVgroup(SVgObj *pVgroup) { - SSdbOper oper = { + SSWriteMsg oper = { .type = SDB_OPER_GLOBAL, .table = tsVgroupSdb, .pObj = pVgroup @@ -519,14 +519,14 @@ static int32_t mnodeCreateVgroupCb(SMnodeMsg *pMsg, int32_t code) { if (code != TSDB_CODE_SUCCESS) { mError("app:%p:%p, vgId:%d, failed to create in sdb, reason:%s", pMsg->rpcMsg.ahandle, pMsg, pVgroup->vgId, tstrerror(code)); - SSdbOper desc = {.type = SDB_OPER_GLOBAL, .pObj = pVgroup, .table = tsVgroupSdb}; + SSWriteMsg desc = {.type = SDB_OPER_GLOBAL, .pObj = pVgroup, .table = tsVgroupSdb}; sdbDeleteRow(&desc); return code; } else { mInfo("app:%p:%p, vgId:%d, is created in sdb, db:%s replica:%d", pMsg->rpcMsg.ahandle, pMsg, pVgroup->vgId, pDb->name, pVgroup->numOfVnodes); pVgroup->status = TAOS_VG_STATUS_READY; - SSdbOper desc = {.type = SDB_OPER_GLOBAL, .pObj = pVgroup, .table = tsVgroupSdb}; + SSWriteMsg desc = {.type = SDB_OPER_GLOBAL, .pObj = pVgroup, .table = tsVgroupSdb}; (void)sdbUpdateRow(&desc); dnodeReprocessMWriteMsg(pMsg); @@ -535,7 +535,7 @@ static int32_t mnodeCreateVgroupCb(SMnodeMsg *pMsg, int32_t code) { // mInfo("app:%p:%p, vgId:%d, is created in sdb, db:%s replica:%d", pMsg->rpcMsg.ahandle, pMsg, pVgroup->vgId, // pDb->name, pVgroup->numOfVnodes); // pVgroup->status = TAOS_VG_STATUS_READY; - // SSdbOper desc = {.type = SDB_OPER_GLOBAL, .pObj = pVgroup, .table = tsVgroupSdb}; + // SSWriteMsg desc = {.type = SDB_OPER_GLOBAL, .pObj = pVgroup, .table = tsVgroupSdb}; // (void)sdbUpdateRow(&desc); // dnodeReprocessMWriteMsg(pMsg); // return TSDB_CODE_MND_ACTION_IN_PROGRESS; @@ -571,7 +571,7 @@ int32_t mnodeCreateVgroup(SMnodeMsg *pMsg) { pMsg->pVgroup = pVgroup; mnodeIncVgroupRef(pVgroup); - SSdbOper oper = { + SSWriteMsg oper = { .type = SDB_OPER_GLOBAL, .table = tsVgroupSdb, .pObj = pVgroup, @@ -595,7 +595,7 @@ void mnodeDropVgroup(SVgObj *pVgroup, void *ahandle) { } else { mDebug("vgId:%d, replica:%d is deleting from sdb", pVgroup->vgId, pVgroup->numOfVnodes); mnodeSendDropVgroupMsg(pVgroup, NULL); - SSdbOper oper = { + SSWriteMsg oper = { .type = SDB_OPER_GLOBAL, .table = tsVgroupSdb, .pObj = pVgroup @@ -957,7 +957,7 @@ static void mnodeProcessCreateVnodeRsp(SRpcMsg *rpcMsg) { if (mnodeMsg->received != mnodeMsg->expected) return; if (mnodeMsg->received == mnodeMsg->successed) { - SSdbOper oper = { + SSWriteMsg oper = { .type = SDB_OPER_GLOBAL, .table = tsVgroupSdb, .pObj = pVgroup, @@ -973,7 +973,7 @@ static void mnodeProcessCreateVnodeRsp(SRpcMsg *rpcMsg) { dnodeSendRpcMWriteRsp(mnodeMsg, code); } } else { - SSdbOper oper = { + SSWriteMsg oper = { .type = SDB_OPER_GLOBAL, .table = tsVgroupSdb, .pObj = pVgroup @@ -1031,7 +1031,7 @@ static void mnodeProcessDropVnodeRsp(SRpcMsg *rpcMsg) { if (mnodeMsg->received != mnodeMsg->expected) return; - SSdbOper oper = { + SSWriteMsg oper = { .type = SDB_OPER_GLOBAL, .table = tsVgroupSdb, .pObj = pVgroup @@ -1084,7 +1084,7 @@ void mnodeDropAllDnodeVgroups(SDnodeObj *pDropDnode) { if (pVgroup->vnodeGid[0].dnodeId == pDropDnode->dnodeId) { mnodeDropAllChildTablesInVgroups(pVgroup); - SSdbOper oper = { + SSWriteMsg oper = { .type = SDB_OPER_LOCAL, .table = tsVgroupSdb, .pObj = pVgroup, @@ -1135,7 +1135,7 @@ void mnodeDropAllDbVgroups(SDbObj *pDropDb) { if (pVgroup == NULL) break; if (pVgroup->pDb == pDropDb) { - SSdbOper oper = { + SSWriteMsg oper = { .type = SDB_OPER_LOCAL, .table = tsVgroupSdb, .pObj = pVgroup, diff --git a/src/plugins/http/inc/httpInt.h b/src/plugins/http/inc/httpInt.h index affc0e838e..ebdfabf310 100644 --- a/src/plugins/http/inc/httpInt.h +++ b/src/plugins/http/inc/httpInt.h @@ -118,7 +118,7 @@ typedef struct { typedef struct { char *module; - bool (*decodeFp)(struct HttpContext *pContext); + bool (*fpDecode)(struct HttpContext *pContext); } HttpDecodeMethod; typedef struct { diff --git a/src/plugins/http/src/httpHandle.c b/src/plugins/http/src/httpHandle.c index b50217cfc4..7c56507514 100644 --- a/src/plugins/http/src/httpHandle.c +++ b/src/plugins/http/src/httpHandle.c @@ -21,11 +21,11 @@ #include "httpHandle.h" bool httpDecodeRequest(HttpContext* pContext) { - if (pContext->decodeMethod->decodeFp == NULL) { + if (pContext->decodeMethod->fpDecode == NULL) { return false; } - return (*pContext->decodeMethod->decodeFp)(pContext); + return (*pContext->decodeMethod->fpDecode)(pContext); } /** From 97e41cdf8db6ea95a94cb13ae3fbd610fdf01bb1 Mon Sep 17 00:00:00 2001 From: Shengliang Guan Date: Wed, 18 Nov 2020 15:39:57 +0800 Subject: [PATCH 04/13] TD-2046 --- src/mnode/inc/mnodeSdb.h | 52 +++--- src/mnode/src/mnodeAcct.c | 42 ++--- src/mnode/src/mnodeCluster.c | 34 ++-- src/mnode/src/mnodeDb.c | 100 +++++------ src/mnode/src/mnodeDnode.c | 66 +++---- src/mnode/src/mnodeMnode.c | 58 +++--- src/mnode/src/mnodeSdb.c | 199 ++++++++++----------- src/mnode/src/mnodeTable.c | 334 +++++++++++++++++------------------ src/mnode/src/mnodeUser.c | 78 ++++---- src/mnode/src/mnodeVgroup.c | 130 +++++++------- tests/script/sh/deploy.sh | 28 +-- 11 files changed, 562 insertions(+), 559 deletions(-) diff --git a/src/mnode/inc/mnodeSdb.h b/src/mnode/inc/mnodeSdb.h index 938a8a40fd..0b0933c08a 100644 --- a/src/mnode/inc/mnodeSdb.h +++ b/src/mnode/inc/mnodeSdb.h @@ -20,7 +20,9 @@ extern "C" { #endif -struct SMnodeMsg; +#include "mnode.h" + +struct SSdbTable; typedef enum { SDB_TABLE_CLUSTER = 0, @@ -36,35 +38,35 @@ typedef enum { } ESdbTable; typedef enum { - SDB_KEY_STRING, - SDB_KEY_INT, - SDB_KEY_AUTO, - SDB_KEY_VAR_STRING, + SDB_KEY_STRING = 0, + SDB_KEY_INT = 1, + SDB_KEY_AUTO = 2, + SDB_KEY_VAR_STRING = 3, } ESdbKey; typedef enum { - SDB_OPER_GLOBAL, - SDB_OPER_LOCAL + SDB_OPER_GLOBAL = 0, + SDB_OPER_LOCAL = 1 } ESdbOper; typedef struct SSWriteMsg { ESdbOper type; + int32_t processedCount; // for sync fwd callback + int32_t retCode; // for callback in sdb queue int32_t rowSize; - int32_t retCode; // for callback in sdb queue - int32_t processedCount; // for sync fwd callback - int32_t (*reqFp)(struct SMnodeMsg *pMsg); - int32_t (*writeCb)(struct SMnodeMsg *pMsg, int32_t code); - void * table; - void * pObj; void * rowData; - struct SMnodeMsg *pMsg; + int32_t (*fpReq)(SMnodeMsg *pMsg); + int32_t (*fpWrite)(SMnodeMsg *pMsg, int32_t code); + void * pObj; + SMnodeMsg *pMsg; + struct SSdbTable *pTable; } SSWriteMsg; typedef struct { - char *tableName; - int32_t hashSessions; - int32_t maxRowSize; - int32_t refCountPos; + char * tableName; + int32_t hashSessions; + int32_t maxRowSize; + int32_t refCountPos; ESdbTable tableId; ESdbKey keyType; int32_t (*fpInsert)(SSWriteMsg *pWrite); @@ -89,15 +91,15 @@ int32_t sdbDeleteRow(SSWriteMsg *pWrite); int32_t sdbUpdateRow(SSWriteMsg *pWrite); int32_t sdbInsertRowImp(SSWriteMsg *pWrite); -void *sdbGetRow(void *handle, void *key); -void *sdbFetchRow(void *handle, void *pIter, void **ppRow); +void *sdbGetRow(void *pTable, void *key); +void *sdbFetchRow(void *pTable, void *pIter, void **ppRow); void sdbFreeIter(void *pIter); -void sdbIncRef(void *thandle, void *pRow); -void sdbDecRef(void *thandle, void *pRow); -int64_t sdbGetNumOfRows(void *handle); -int32_t sdbGetId(void *handle); +void sdbIncRef(void *pTable, void *pRow); +void sdbDecRef(void *pTable, void *pRow); +int64_t sdbGetNumOfRows(void *pTable); +int32_t sdbGetId(void *pTable); uint64_t sdbGetVersion(); -bool sdbCheckRowDeleted(void *thandle, void *pRow); +bool sdbCheckRowDeleted(void *pTable, void *pRow); #ifdef __cplusplus } diff --git a/src/mnode/src/mnodeAcct.c b/src/mnode/src/mnodeAcct.c index c6d366ebb3..697ff1d5a1 100644 --- a/src/mnode/src/mnodeAcct.c +++ b/src/mnode/src/mnodeAcct.c @@ -31,30 +31,30 @@ void * tsAcctSdb = NULL; static int32_t tsAcctUpdateSize; static int32_t mnodeCreateRootAcct(); -static int32_t mnodeAcctActionDestroy(SSWriteMsg *pOper) { - SAcctObj *pAcct = pOper->pObj; +static int32_t mnodeAcctActionDestroy(SSWriteMsg *pWMsg) { + SAcctObj *pAcct = pWMsg->pObj; pthread_mutex_destroy(&pAcct->mutex); - tfree(pOper->pObj); + tfree(pWMsg->pObj); return TSDB_CODE_SUCCESS; } -static int32_t mnodeAcctActionInsert(SSWriteMsg *pOper) { - SAcctObj *pAcct = pOper->pObj; +static int32_t mnodeAcctActionInsert(SSWriteMsg *pWMsg) { + SAcctObj *pAcct = pWMsg->pObj; memset(&pAcct->acctInfo, 0, sizeof(SAcctInfo)); pAcct->acctInfo.accessState = TSDB_VN_ALL_ACCCESS; pthread_mutex_init(&pAcct->mutex, NULL); return TSDB_CODE_SUCCESS; } -static int32_t mnodeAcctActionDelete(SSWriteMsg *pOper) { - SAcctObj *pAcct = pOper->pObj; +static int32_t mnodeAcctActionDelete(SSWriteMsg *pWMsg) { + SAcctObj *pAcct = pWMsg->pObj; mnodeDropAllUsers(pAcct); mnodeDropAllDbs(pAcct); return TSDB_CODE_SUCCESS; } -static int32_t mnodeAcctActionUpdate(SSWriteMsg *pOper) { - SAcctObj *pAcct = pOper->pObj; +static int32_t mnodeAcctActionUpdate(SSWriteMsg *pWMsg) { + SAcctObj *pAcct = pWMsg->pObj; SAcctObj *pSaved = mnodeGetAcct(pAcct->user); if (pAcct != pSaved) { memcpy(pSaved, pAcct, tsAcctUpdateSize); @@ -64,19 +64,19 @@ static int32_t mnodeAcctActionUpdate(SSWriteMsg *pOper) { return TSDB_CODE_SUCCESS; } -static int32_t mnodeAcctActionEncode(SSWriteMsg *pOper) { - SAcctObj *pAcct = pOper->pObj; - memcpy(pOper->rowData, pAcct, tsAcctUpdateSize); - pOper->rowSize = tsAcctUpdateSize; +static int32_t mnodeAcctActionEncode(SSWriteMsg *pWMsg) { + SAcctObj *pAcct = pWMsg->pObj; + memcpy(pWMsg->rowData, pAcct, tsAcctUpdateSize); + pWMsg->rowSize = tsAcctUpdateSize; return TSDB_CODE_SUCCESS; } -static int32_t mnodeAcctActionDecode(SSWriteMsg *pOper) { +static int32_t mnodeAcctActionDecode(SSWriteMsg *pWMsg) { SAcctObj *pAcct = (SAcctObj *) calloc(1, sizeof(SAcctObj)); if (pAcct == NULL) return TSDB_CODE_MND_OUT_OF_MEMORY; - memcpy(pAcct, pOper->rowData, tsAcctUpdateSize); - pOper->pObj = pAcct; + memcpy(pAcct, pWMsg->rowData, tsAcctUpdateSize); + pWMsg->pObj = pAcct; return TSDB_CODE_SUCCESS; } @@ -226,13 +226,13 @@ static int32_t mnodeCreateRootAcct() { pAcct->acctId = sdbGetId(tsAcctSdb); pAcct->createdTime = taosGetTimestampMs(); - SSWriteMsg oper = { - .type = SDB_OPER_GLOBAL, - .table = tsAcctSdb, - .pObj = pAcct, + SSWriteMsg wmsg = { + .type = SDB_OPER_GLOBAL, + .pTable = tsAcctSdb, + .pObj = pAcct, }; - return sdbInsertRow(&oper); + return sdbInsertRow(&wmsg); } #ifndef _ACCT diff --git a/src/mnode/src/mnodeCluster.c b/src/mnode/src/mnodeCluster.c index 3b2b668a1f..c94c833270 100644 --- a/src/mnode/src/mnodeCluster.c +++ b/src/mnode/src/mnodeCluster.c @@ -32,36 +32,36 @@ static int32_t mnodeCreateCluster(); static int32_t mnodeGetClusterMeta(STableMetaMsg *pMeta, SShowObj *pShow, void *pConn); static int32_t mnodeRetrieveClusters(SShowObj *pShow, char *data, int32_t rows, void *pConn); -static int32_t mnodeClusterActionDestroy(SSWriteMsg *pOper) { - tfree(pOper->pObj); +static int32_t mnodeClusterActionDestroy(SSWriteMsg *pWMsg) { + tfree(pWMsg->pObj); return TSDB_CODE_SUCCESS; } -static int32_t mnodeClusterActionInsert(SSWriteMsg *pOper) { +static int32_t mnodeClusterActionInsert(SSWriteMsg *pWMsg) { return TSDB_CODE_SUCCESS; } -static int32_t mnodeClusterActionDelete(SSWriteMsg *pOper) { +static int32_t mnodeClusterActionDelete(SSWriteMsg *pWMsg) { return TSDB_CODE_SUCCESS; } -static int32_t mnodeClusterActionUpdate(SSWriteMsg *pOper) { +static int32_t mnodeClusterActionUpdate(SSWriteMsg *pWMsg) { return TSDB_CODE_SUCCESS; } -static int32_t mnodeClusterActionEncode(SSWriteMsg *pOper) { - SClusterObj *pCluster = pOper->pObj; - memcpy(pOper->rowData, pCluster, tsClusterUpdateSize); - pOper->rowSize = tsClusterUpdateSize; +static int32_t mnodeClusterActionEncode(SSWriteMsg *pWMsg) { + SClusterObj *pCluster = pWMsg->pObj; + memcpy(pWMsg->rowData, pCluster, tsClusterUpdateSize); + pWMsg->rowSize = tsClusterUpdateSize; return TSDB_CODE_SUCCESS; } -static int32_t mnodeClusterActionDecode(SSWriteMsg *pOper) { +static int32_t mnodeClusterActionDecode(SSWriteMsg *pWMsg) { SClusterObj *pCluster = (SClusterObj *) calloc(1, sizeof(SClusterObj)); if (pCluster == NULL) return TSDB_CODE_MND_OUT_OF_MEMORY; - memcpy(pCluster, pOper->rowData, tsClusterUpdateSize); - pOper->pObj = pCluster; + memcpy(pCluster, pWMsg->rowData, tsClusterUpdateSize); + pWMsg->pObj = pCluster; return TSDB_CODE_SUCCESS; } @@ -145,13 +145,13 @@ static int32_t mnodeCreateCluster() { mDebug("uid is %s", pCluster->uid); } - SSWriteMsg oper = { - .type = SDB_OPER_GLOBAL, - .table = tsClusterSdb, - .pObj = pCluster, + SSWriteMsg wmsg = { + .type = SDB_OPER_GLOBAL, + .pTable = tsClusterSdb, + .pObj = pCluster, }; - return sdbInsertRow(&oper); + return sdbInsertRow(&wmsg); } const char* mnodeGetClusterId() { diff --git a/src/mnode/src/mnodeDb.c b/src/mnode/src/mnodeDb.c index 403213c22f..3c2bfbb834 100644 --- a/src/mnode/src/mnodeDb.c +++ b/src/mnode/src/mnodeDb.c @@ -56,8 +56,8 @@ static void mnodeDestroyDb(SDbObj *pDb) { tfree(pDb); } -static int32_t mnodeDbActionDestroy(SSWriteMsg *pOper) { - mnodeDestroyDb(pOper->pObj); +static int32_t mnodeDbActionDestroy(SSWriteMsg *pWMsg) { + mnodeDestroyDb(pWMsg->pObj); return TSDB_CODE_SUCCESS; } @@ -65,8 +65,8 @@ int64_t mnodeGetDbNum() { return sdbGetNumOfRows(tsDbSdb); } -static int32_t mnodeDbActionInsert(SSWriteMsg *pOper) { - SDbObj *pDb = pOper->pObj; +static int32_t mnodeDbActionInsert(SSWriteMsg *pWMsg) { + SDbObj *pDb = pWMsg->pObj; SAcctObj *pAcct = mnodeGetAcct(pDb->acct); pthread_mutex_init(&pDb->mutex, NULL); @@ -91,8 +91,8 @@ static int32_t mnodeDbActionInsert(SSWriteMsg *pOper) { return TSDB_CODE_SUCCESS; } -static int32_t mnodeDbActionDelete(SSWriteMsg *pOper) { - SDbObj *pDb = pOper->pObj; +static int32_t mnodeDbActionDelete(SSWriteMsg *pWMsg) { + SDbObj *pDb = pWMsg->pObj; SAcctObj *pAcct = mnodeGetAcct(pDb->acct); mnodeDropAllChildTables(pDb); @@ -107,11 +107,11 @@ static int32_t mnodeDbActionDelete(SSWriteMsg *pOper) { return TSDB_CODE_SUCCESS; } -static int32_t mnodeDbActionUpdate(SSWriteMsg *pOper) { - SDbObj *pNew = pOper->pObj; +static int32_t mnodeDbActionUpdate(SSWriteMsg *pWMsg) { + SDbObj *pNew = pWMsg->pObj; SDbObj *pDb = mnodeGetDb(pNew->name); if (pDb != NULL && pNew != pDb) { - memcpy(pDb, pNew, pOper->rowSize); + memcpy(pDb, pNew, pWMsg->rowSize); free(pNew->vgList); free(pNew); } @@ -120,19 +120,19 @@ static int32_t mnodeDbActionUpdate(SSWriteMsg *pOper) { return TSDB_CODE_SUCCESS; } -static int32_t mnodeDbActionEncode(SSWriteMsg *pOper) { - SDbObj *pDb = pOper->pObj; - memcpy(pOper->rowData, pDb, tsDbUpdateSize); - pOper->rowSize = tsDbUpdateSize; +static int32_t mnodeDbActionEncode(SSWriteMsg *pWMsg) { + SDbObj *pDb = pWMsg->pObj; + memcpy(pWMsg->rowData, pDb, tsDbUpdateSize); + pWMsg->rowSize = tsDbUpdateSize; return TSDB_CODE_SUCCESS; } -static int32_t mnodeDbActionDecode(SSWriteMsg *pOper) { +static int32_t mnodeDbActionDecode(SSWriteMsg *pWMsg) { SDbObj *pDb = (SDbObj *) calloc(1, sizeof(SDbObj)); if (pDb == NULL) return TSDB_CODE_MND_OUT_OF_MEMORY; - memcpy(pDb, pOper->rowData, tsDbUpdateSize); - pOper->pObj = pDb; + memcpy(pDb, pWMsg->rowData, tsDbUpdateSize); + pWMsg->pObj = pDb; return TSDB_CODE_SUCCESS; } @@ -412,16 +412,16 @@ static int32_t mnodeCreateDb(SAcctObj *pAcct, SCreateDbMsg *pCreate, SMnodeMsg * pMsg->pDb = pDb; mnodeIncDbRef(pDb); - SSWriteMsg oper = { - .type = SDB_OPER_GLOBAL, - .table = tsDbSdb, - .pObj = pDb, - .rowSize = sizeof(SDbObj), - .pMsg = pMsg, - .writeCb = mnodeCreateDbCb + SSWriteMsg wmsg = { + .type = SDB_OPER_GLOBAL, + .pTable = tsDbSdb, + .pObj = pDb, + .rowSize = sizeof(SDbObj), + .pMsg = pMsg, + .fpWrite = mnodeCreateDbCb }; - code = sdbInsertRow(&oper); + code = sdbInsertRow(&wmsg); if (code != TSDB_CODE_SUCCESS && code != TSDB_CODE_MND_ACTION_IN_PROGRESS) { mError("db:%s, failed to create, reason:%s", pDb->name, tstrerror(code)); pMsg->pDb = NULL; @@ -440,8 +440,8 @@ bool mnodeCheckIsMonitorDB(char *db, char *monitordb) { } #if 0 -void mnodePrintVgroups(SDbObj *pDb, char *oper) { - mInfo("db:%s, vgroup link from head, oper:%s", pDb->name, oper); +void mnodePrintVgroups(SDbObj *pDb, char *wmsg) { + mInfo("db:%s, vgroup link from head, wmsg:%s", pDb->name, wmsg); SVgObj *pVgroup = pDb->pHead; while (pVgroup != NULL) { mInfo("vgId:%d", pVgroup->vgId); @@ -807,13 +807,13 @@ static int32_t mnodeSetDbDropping(SDbObj *pDb) { if (pDb->status) return TSDB_CODE_SUCCESS; pDb->status = true; - SSWriteMsg oper = { - .type = SDB_OPER_GLOBAL, - .table = tsDbSdb, - .pObj = pDb + SSWriteMsg wmsg = { + .type = SDB_OPER_GLOBAL, + .pTable = tsDbSdb, + .pObj = pDb }; - int32_t code = sdbUpdateRow(&oper); + int32_t code = sdbUpdateRow(&wmsg); if (code != TSDB_CODE_SUCCESS && code != TSDB_CODE_MND_ACTION_IN_PROGRESS) { mError("db:%s, failed to set dropping state, reason:%s", pDb->name, tstrerror(code)); } @@ -1019,15 +1019,15 @@ static int32_t mnodeAlterDb(SDbObj *pDb, SAlterDbMsg *pAlter, void *pMsg) { if (memcmp(&newCfg, &pDb->cfg, sizeof(SDbCfg)) != 0) { pDb->cfg = newCfg; pDb->cfgVersion++; - SSWriteMsg oper = { - .type = SDB_OPER_GLOBAL, - .table = tsDbSdb, - .pObj = pDb, - .pMsg = pMsg, - .writeCb = mnodeAlterDbCb + SSWriteMsg wmsg = { + .type = SDB_OPER_GLOBAL, + .pTable = tsDbSdb, + .pObj = pDb, + .pMsg = pMsg, + .fpWrite = mnodeAlterDbCb }; - code = sdbUpdateRow(&oper); + code = sdbUpdateRow(&wmsg); if (code != TSDB_CODE_SUCCESS && code != TSDB_CODE_MND_ACTION_IN_PROGRESS) { mError("db:%s, failed to alter, reason:%s", pDb->name, tstrerror(code)); } @@ -1071,15 +1071,15 @@ static int32_t mnodeDropDb(SMnodeMsg *pMsg) { SDbObj *pDb = pMsg->pDb; mInfo("db:%s, drop db from sdb", pDb->name); - SSWriteMsg oper = { - .type = SDB_OPER_GLOBAL, - .table = tsDbSdb, - .pObj = pDb, - .pMsg = pMsg, - .writeCb = mnodeDropDbCb + SSWriteMsg wmsg = { + .type = SDB_OPER_GLOBAL, + .pTable = tsDbSdb, + .pObj = pDb, + .pMsg = pMsg, + .fpWrite = mnodeDropDbCb }; - int32_t code = sdbDeleteRow(&oper); + int32_t code = sdbDeleteRow(&wmsg); if (code != TSDB_CODE_SUCCESS && code != TSDB_CODE_MND_ACTION_IN_PROGRESS) { mError("db:%s, failed to drop, reason:%s", pDb->name, tstrerror(code)); } @@ -1134,13 +1134,13 @@ void mnodeDropAllDbs(SAcctObj *pAcct) { if (pDb->pAcct == pAcct) { mInfo("db:%s, drop db from sdb for acct:%s is dropped", pDb->name, pAcct->user); - SSWriteMsg oper = { - .type = SDB_OPER_LOCAL, - .table = tsDbSdb, - .pObj = pDb + SSWriteMsg wmsg = { + .type = SDB_OPER_LOCAL, + .pTable = tsDbSdb, + .pObj = pDb }; - sdbDeleteRow(&oper); + sdbDeleteRow(&wmsg); numOfDbs++; } mnodeDecDbRef(pDb); diff --git a/src/mnode/src/mnodeDnode.c b/src/mnode/src/mnodeDnode.c index 0dd43fef89..617499967e 100644 --- a/src/mnode/src/mnodeDnode.c +++ b/src/mnode/src/mnodeDnode.c @@ -87,13 +87,13 @@ static char* offlineReason[] = { "unknown", }; -static int32_t mnodeDnodeActionDestroy(SSWriteMsg *pOper) { - tfree(pOper->pObj); +static int32_t mnodeDnodeActionDestroy(SSWriteMsg *pWMsg) { + tfree(pWMsg->pObj); return TSDB_CODE_SUCCESS; } -static int32_t mnodeDnodeActionInsert(SSWriteMsg *pOper) { - SDnodeObj *pDnode = pOper->pObj; +static int32_t mnodeDnodeActionInsert(SSWriteMsg *pWMsg) { + SDnodeObj *pDnode = pWMsg->pObj; if (pDnode->status != TAOS_DN_STATUS_DROPPING) { pDnode->status = TAOS_DN_STATUS_OFFLINE; pDnode->lastAccess = tsAccessSquence; @@ -107,8 +107,8 @@ static int32_t mnodeDnodeActionInsert(SSWriteMsg *pOper) { return TSDB_CODE_SUCCESS; } -static int32_t mnodeDnodeActionDelete(SSWriteMsg *pOper) { - SDnodeObj *pDnode = pOper->pObj; +static int32_t mnodeDnodeActionDelete(SSWriteMsg *pWMsg) { + SDnodeObj *pDnode = pWMsg->pObj; #ifndef _SYNC mnodeDropAllDnodeVgroups(pDnode); @@ -121,11 +121,11 @@ static int32_t mnodeDnodeActionDelete(SSWriteMsg *pOper) { return TSDB_CODE_SUCCESS; } -static int32_t mnodeDnodeActionUpdate(SSWriteMsg *pOper) { - SDnodeObj *pNew = pOper->pObj; +static int32_t mnodeDnodeActionUpdate(SSWriteMsg *pWMsg) { + SDnodeObj *pNew = pWMsg->pObj; SDnodeObj *pDnode = mnodeGetDnode(pNew->dnodeId); if (pDnode != NULL && pNew != pDnode) { - memcpy(pDnode, pNew, pOper->rowSize); + memcpy(pDnode, pNew, pWMsg->rowSize); free(pNew); } mnodeDecDnodeRef(pDnode); @@ -134,19 +134,19 @@ static int32_t mnodeDnodeActionUpdate(SSWriteMsg *pOper) { return TSDB_CODE_SUCCESS; } -static int32_t mnodeDnodeActionEncode(SSWriteMsg *pOper) { - SDnodeObj *pDnode = pOper->pObj; - memcpy(pOper->rowData, pDnode, tsDnodeUpdateSize); - pOper->rowSize = tsDnodeUpdateSize; +static int32_t mnodeDnodeActionEncode(SSWriteMsg *pWMsg) { + SDnodeObj *pDnode = pWMsg->pObj; + memcpy(pWMsg->rowData, pDnode, tsDnodeUpdateSize); + pWMsg->rowSize = tsDnodeUpdateSize; return TSDB_CODE_SUCCESS; } -static int32_t mnodeDnodeActionDecode(SSWriteMsg *pOper) { +static int32_t mnodeDnodeActionDecode(SSWriteMsg *pWMsg) { SDnodeObj *pDnode = (SDnodeObj *) calloc(1, sizeof(SDnodeObj)); if (pDnode == NULL) return TSDB_CODE_MND_OUT_OF_MEMORY; - memcpy(pDnode, pOper->rowData, tsDnodeUpdateSize); - pOper->pObj = pDnode; + memcpy(pDnode, pWMsg->rowData, tsDnodeUpdateSize); + pWMsg->pObj = pDnode; return TSDB_CODE_SUCCESS; } @@ -296,13 +296,13 @@ void mnodeDecDnodeRef(SDnodeObj *pDnode) { } void mnodeUpdateDnode(SDnodeObj *pDnode) { - SSWriteMsg oper = { - .type = SDB_OPER_GLOBAL, - .table = tsDnodeSdb, - .pObj = pDnode + SSWriteMsg wmsg = { + .type = SDB_OPER_GLOBAL, + .pTable = tsDnodeSdb, + .pObj = pDnode }; - int32_t code = sdbUpdateRow(&oper); + int32_t code = sdbUpdateRow(&wmsg); if (code != TSDB_CODE_SUCCESS && code != TSDB_CODE_MND_ACTION_IN_PROGRESS) { mError("dnodeId:%d, failed update", pDnode->dnodeId); } @@ -644,15 +644,15 @@ static int32_t mnodeCreateDnode(char *ep, SMnodeMsg *pMsg) { tstrncpy(pDnode->dnodeEp, ep, TSDB_EP_LEN); taosGetFqdnPortFromEp(ep, pDnode->dnodeFqdn, &pDnode->dnodePort); - SSWriteMsg oper = { - .type = SDB_OPER_GLOBAL, - .table = tsDnodeSdb, - .pObj = pDnode, + SSWriteMsg wmsg = { + .type = SDB_OPER_GLOBAL, + .pTable = tsDnodeSdb, + .pObj = pDnode, .rowSize = sizeof(SDnodeObj), - .pMsg = pMsg + .pMsg = pMsg }; - int32_t code = sdbInsertRow(&oper); + int32_t code = sdbInsertRow(&wmsg); if (code != TSDB_CODE_SUCCESS && code != TSDB_CODE_MND_ACTION_IN_PROGRESS) { int dnodeId = pDnode->dnodeId; tfree(pDnode); @@ -665,14 +665,14 @@ static int32_t mnodeCreateDnode(char *ep, SMnodeMsg *pMsg) { } int32_t mnodeDropDnode(SDnodeObj *pDnode, void *pMsg) { - SSWriteMsg oper = { - .type = SDB_OPER_GLOBAL, - .table = tsDnodeSdb, - .pObj = pDnode, - .pMsg = pMsg + SSWriteMsg wmsg = { + .type = SDB_OPER_GLOBAL, + .pTable = tsDnodeSdb, + .pObj = pDnode, + .pMsg = pMsg }; - int32_t code = sdbDeleteRow(&oper); + int32_t code = sdbDeleteRow(&wmsg); if (code != TSDB_CODE_SUCCESS && code != TSDB_CODE_MND_ACTION_IN_PROGRESS) { mError("dnode:%d, failed to drop from cluster, result:%s", pDnode->dnodeId, tstrerror(code)); } else { diff --git a/src/mnode/src/mnodeMnode.c b/src/mnode/src/mnodeMnode.c index bf9033c5cd..37915319e5 100644 --- a/src/mnode/src/mnodeMnode.c +++ b/src/mnode/src/mnodeMnode.c @@ -58,13 +58,13 @@ static int32_t mnodeRetrieveMnodes(SShowObj *pShow, char *data, int32_t rows, vo #define mnodeMnodeDestroyLock() pthread_mutex_destroy(&tsMnodeLock) #endif -static int32_t mnodeMnodeActionDestroy(SSWriteMsg *pOper) { - tfree(pOper->pObj); +static int32_t mnodeMnodeActionDestroy(SSWriteMsg *pWMsg) { + tfree(pWMsg->pObj); return TSDB_CODE_SUCCESS; } -static int32_t mnodeMnodeActionInsert(SSWriteMsg *pOper) { - SMnodeObj *pMnode = pOper->pObj; +static int32_t mnodeMnodeActionInsert(SSWriteMsg *pWMsg) { + SMnodeObj *pMnode = pWMsg->pObj; SDnodeObj *pDnode = mnodeGetDnode(pMnode->mnodeId); if (pDnode == NULL) return TSDB_CODE_MND_DNODE_NOT_EXIST; @@ -76,8 +76,8 @@ static int32_t mnodeMnodeActionInsert(SSWriteMsg *pOper) { return TSDB_CODE_SUCCESS; } -static int32_t mnodeMnodeActionDelete(SSWriteMsg *pOper) { - SMnodeObj *pMnode = pOper->pObj; +static int32_t mnodeMnodeActionDelete(SSWriteMsg *pWMsg) { + SMnodeObj *pMnode = pWMsg->pObj; SDnodeObj *pDnode = mnodeGetDnode(pMnode->mnodeId); if (pDnode == NULL) return TSDB_CODE_MND_DNODE_NOT_EXIST; @@ -88,30 +88,30 @@ static int32_t mnodeMnodeActionDelete(SSWriteMsg *pOper) { return TSDB_CODE_SUCCESS; } -static int32_t mnodeMnodeActionUpdate(SSWriteMsg *pOper) { - SMnodeObj *pMnode = pOper->pObj; +static int32_t mnodeMnodeActionUpdate(SSWriteMsg *pWMsg) { + SMnodeObj *pMnode = pWMsg->pObj; SMnodeObj *pSaved = mnodeGetMnode(pMnode->mnodeId); if (pMnode != pSaved) { - memcpy(pSaved, pMnode, pOper->rowSize); + memcpy(pSaved, pMnode, pWMsg->rowSize); free(pMnode); } mnodeDecMnodeRef(pSaved); return TSDB_CODE_SUCCESS; } -static int32_t mnodeMnodeActionEncode(SSWriteMsg *pOper) { - SMnodeObj *pMnode = pOper->pObj; - memcpy(pOper->rowData, pMnode, tsMnodeUpdateSize); - pOper->rowSize = tsMnodeUpdateSize; +static int32_t mnodeMnodeActionEncode(SSWriteMsg *pWMsg) { + SMnodeObj *pMnode = pWMsg->pObj; + memcpy(pWMsg->rowData, pMnode, tsMnodeUpdateSize); + pWMsg->rowSize = tsMnodeUpdateSize; return TSDB_CODE_SUCCESS; } -static int32_t mnodeMnodeActionDecode(SSWriteMsg *pOper) { +static int32_t mnodeMnodeActionDecode(SSWriteMsg *pWMsg) { SMnodeObj *pMnode = calloc(1, sizeof(SMnodeObj)); if (pMnode == NULL) return TSDB_CODE_MND_OUT_OF_MEMORY; - memcpy(pMnode, pOper->rowData, tsMnodeUpdateSize); - pOper->pObj = pMnode; + memcpy(pMnode, pWMsg->rowData, tsMnodeUpdateSize); + pWMsg->pObj = pMnode; return TSDB_CODE_SUCCESS; } @@ -329,11 +329,11 @@ void mnodeCreateMnode(int32_t dnodeId, char *dnodeEp, bool needConfirm) { pMnode->mnodeId = dnodeId; pMnode->createdTime = taosGetTimestampMs(); - SSWriteMsg oper = { - .type = SDB_OPER_GLOBAL, - .table = tsMnodeSdb, - .pObj = pMnode, - .writeCb = mnodeCreateMnodeCb + SSWriteMsg wmsg = { + .type = SDB_OPER_GLOBAL, + .pTable = tsMnodeSdb, + .pObj = pMnode, + .fpWrite = mnodeCreateMnodeCb }; int32_t code = TSDB_CODE_SUCCESS; @@ -346,7 +346,7 @@ void mnodeCreateMnode(int32_t dnodeId, char *dnodeEp, bool needConfirm) { return; } - code = sdbInsertRow(&oper); + code = sdbInsertRow(&wmsg); if (code != TSDB_CODE_SUCCESS && code != TSDB_CODE_MND_ACTION_IN_PROGRESS) { mError("dnode:%d, failed to create mnode, ep:%s reason:%s", dnodeId, dnodeEp, tstrerror(code)); tfree(pMnode); @@ -356,8 +356,8 @@ void mnodeCreateMnode(int32_t dnodeId, char *dnodeEp, bool needConfirm) { void mnodeDropMnodeLocal(int32_t dnodeId) { SMnodeObj *pMnode = mnodeGetMnode(dnodeId); if (pMnode != NULL) { - SSWriteMsg oper = {.type = SDB_OPER_LOCAL, .table = tsMnodeSdb, .pObj = pMnode}; - sdbDeleteRow(&oper); + SSWriteMsg wmsg = {.type = SDB_OPER_LOCAL, .pTable = tsMnodeSdb, .pObj = pMnode}; + sdbDeleteRow(&wmsg); mnodeDecMnodeRef(pMnode); } @@ -371,13 +371,13 @@ int32_t mnodeDropMnode(int32_t dnodeId) { return TSDB_CODE_MND_DNODE_NOT_EXIST; } - SSWriteMsg oper = { - .type = SDB_OPER_GLOBAL, - .table = tsMnodeSdb, - .pObj = pMnode + SSWriteMsg wmsg = { + .type = SDB_OPER_GLOBAL, + .pTable = tsMnodeSdb, + .pObj = pMnode }; - int32_t code = sdbDeleteRow(&oper); + int32_t code = sdbDeleteRow(&wmsg); sdbDecRef(tsMnodeSdb, pMnode); diff --git a/src/mnode/src/mnodeSdb.c b/src/mnode/src/mnodeSdb.c index 59812068d4..034ff870c5 100644 --- a/src/mnode/src/mnodeSdb.c +++ b/src/mnode/src/mnodeSdb.c @@ -83,12 +83,12 @@ typedef struct { typedef struct { pthread_t thread; int32_t workerId; -} SSWriteWorker; +} SSdbWorker; typedef struct { int32_t num; - SSWriteWorker *worker; -} SSWriteWorkerPool; + SSdbWorker *worker; +} SSdbWorkerPool; extern void * tsMnodeTmr; static void * tsSdbTmr; @@ -96,27 +96,28 @@ static SSdbObject tsSdbObj = {0}; static taos_qset tsSdbWQset; static taos_qall tsSdbWQall; static taos_queue tsSdbWQueue; -static SSWriteWorkerPool tsSdbPool; +static SSdbWorkerPool tsSdbPool; -static int32_t sdbWrite(void *wparam, void *data, int32_t type, void *pMsg); -static int32_t sdbWriteToQueue(void *param, void *data, int32_t type, void *pMsg); -static void * sdbWorkerFp(void *param); -static int32_t sdbInitWriteWorker(); -static void sdbCleanupWriteWorker(); -static int32_t sdbAllocWriteQueue(); -static void sdbFreeWritequeue(); +static int32_t sdbWrite(void *pWrite, void *pHead, int32_t qtype, void *unused); +static int32_t sdbWriteToQueue(void *pWrite, void *pHead, int32_t qtype, void *unused); +static void * sdbWorkerFp(void *pWorker); +static int32_t sdbInitWorker(); +static void sdbCleanupWorker(); +static int32_t sdbAllocQueue(); +static void sdbFreeQueue(); +extern int32_t sdbInsertRowImp(SSWriteMsg *pWrite); static int32_t sdbUpdateRowImp(SSWriteMsg *pWrite); static int32_t sdbDeleteRowImp(SSWriteMsg *pWrite); static int32_t sdbInsertHash(SSdbTable *pTable, SSWriteMsg *pWrite); static int32_t sdbUpdateHash(SSdbTable *pTable, SSWriteMsg *pWrite); static int32_t sdbDeleteHash(SSdbTable *pTable, SSWriteMsg *pWrite); -int32_t sdbGetId(void *handle) { - return ((SSdbTable *)handle)->autoIndex; +int32_t sdbGetId(void *pTable) { + return ((SSdbTable *)pTable)->autoIndex; } -int64_t sdbGetNumOfRows(void *handle) { - return ((SSdbTable *)handle)->numOfRows; +int64_t sdbGetNumOfRows(void *pTable) { + return ((SSdbTable *)pTable)->numOfRows; } uint64_t sdbGetVersion() { @@ -276,27 +277,27 @@ static void sdbConfirmForward(void *ahandle, void *param, int32_t code) { SWalHead *pHead = (void *)pWrite + sizeof(SSWriteMsg) + SDB_SYNC_HACK; int32_t action = pHead->msgType % 10; sdbError("vgId:1, key:%p:%s hver:%" PRIu64 " action:%d, failed to foward since %s", pWrite->pObj, - sdbGetKeyStr(pWrite->table, pHead->cont), pHead->version, action, tstrerror(pWrite->retCode)); + sdbGetKeyStr(pWrite->pTable, pHead->cont), pHead->version, action, tstrerror(pWrite->retCode)); if (action == SDB_ACTION_INSERT) { // It's better to create a table in two stages, create it first and then set it success - //sdbDeleteHash(pWrite->table, pWrite); - SSWriteMsg oper = { - .type = SDB_OPER_GLOBAL, - .table = pWrite->table, - .pObj = pWrite->pObj + //sdbDeleteHash(pWrite->pTable, pWrite); + SSWriteMsg wmsg = { + .type = SDB_OPER_GLOBAL, + .pTable = pWrite->pTable, + .pObj = pWrite->pObj }; - sdbDeleteRow(&oper); + sdbDeleteRow(&wmsg); } } - if (pWrite->writeCb != NULL) { - pWrite->retCode = (*pWrite->writeCb)(pMsg, pWrite->retCode); + if (pWrite->fpWrite != NULL) { + pWrite->retCode = (*pWrite->fpWrite)(pMsg, pWrite->retCode); } dnodeSendRpcMWriteRsp(pMsg, pWrite->retCode); // if ahandle, means this func is called by sdb write if (ahandle == NULL) { - sdbDecRef(pWrite->table, pWrite->pObj); + sdbDecRef(pWrite->pTable, pWrite->pObj); } taosFreeQitem(pWrite); @@ -403,7 +404,7 @@ void sdbUpdateSync(void *pMnodes) { int32_t sdbInit() { pthread_mutex_init(&tsSdbObj.mutex, NULL); - if (sdbInitWriteWorker() != 0) { + if (sdbInitWorker() != 0) { return -1; } @@ -426,7 +427,7 @@ void sdbCleanUp() { tsSdbObj.status = SDB_STATUS_CLOSING; - sdbCleanupWriteWorker(); + sdbCleanupWorker(); sdbDebug("vgId:1, sdb will be closed, mver:%" PRIu64, tsSdbObj.version); if (tsSdbObj.sync) { @@ -442,19 +443,19 @@ void sdbCleanUp() { pthread_mutex_destroy(&tsSdbObj.mutex); } -void sdbIncRef(void *handle, void *pObj) { - if (pObj == NULL || handle == NULL) return; +void sdbIncRef(void *tparam, void *pObj) { + if (pObj == NULL || tparam == NULL) return; - SSdbTable *pTable = handle; + SSdbTable *pTable = tparam; int32_t * pRefCount = (int32_t *)(pObj + pTable->refCountPos); int32_t refCount = atomic_add_fetch_32(pRefCount, 1); sdbTrace("vgId:1, sdb:%s, inc ref to key:%p:%s:%d", pTable->tableName, pObj, sdbGetObjStr(pTable, pObj), refCount); } -void sdbDecRef(void *handle, void *pObj) { - if (pObj == NULL || handle == NULL) return; +void sdbDecRef(void *tparam, void *pObj) { + if (pObj == NULL || tparam == NULL) return; - SSdbTable *pTable = handle; + SSdbTable *pTable = tparam; int32_t * pRefCount = (int32_t *)(pObj + pTable->refCountPos); int32_t refCount = atomic_sub_fetch_32(pRefCount, 1); sdbTrace("vgId:1, sdb:%s, dec ref to key:%p:%s:%d", pTable->tableName, pObj, sdbGetObjStr(pTable, pObj), refCount); @@ -462,8 +463,8 @@ void sdbDecRef(void *handle, void *pObj) { int32_t *updateEnd = pObj + pTable->refCountPos - 4; if (refCount <= 0 && *updateEnd) { sdbTrace("vgId:1, sdb:%s, key:%p:%s:%d destroyed", pTable->tableName, pObj, sdbGetObjStr(pTable, pObj), refCount); - SSWriteMsg oper = {.pObj = pObj}; - (*pTable->fpDestroy)(&oper); + SSWriteMsg wmsg = {.pObj = pObj}; + (*pTable->fpDestroy)(&wmsg); } } @@ -485,12 +486,12 @@ static void *sdbGetRowMetaFromObj(SSdbTable *pTable, void *key) { return sdbGetRowMeta(pTable, sdbGetObjKey(pTable, key)); } -void *sdbGetRow(void *handle, void *key) { - SSdbTable *pTable = handle; +void *sdbGetRow(void *tparam, void *key) { + SSdbTable *pTable = tparam; pthread_mutex_lock(&pTable->mutex); - void *pRow = sdbGetRowMeta(handle, key); - if (pRow) sdbIncRef(handle, pRow); + void *pRow = sdbGetRowMeta(pTable, key); + if (pRow) sdbIncRef(pTable, pRow); pthread_mutex_unlock(&pTable->mutex); return pRow; @@ -573,9 +574,9 @@ static int32_t sdbUpdateHash(SSdbTable *pTable, SSWriteMsg *pWrite) { return TSDB_CODE_SUCCESS; } -static int sdbWrite(void *param, void *data, int32_t type, void *pMsg) { - SSWriteMsg *pWrite = param; - SWalHead *pHead = data; +static int sdbWrite(void *wparam, void *hparam, int32_t qtype, void *unused) { + SSWriteMsg *pWrite = wparam; + SWalHead *pHead = hparam; int32_t tableId = pHead->msgType / 10; int32_t action = pHead->msgType % 10; @@ -593,12 +594,12 @@ static int sdbWrite(void *param, void *data, int32_t type, void *pMsg) { if (pHead->version <= tsSdbObj.version) { pthread_mutex_unlock(&tsSdbObj.mutex); sdbDebug("vgId:1, sdb:%s, failed to restore %s key:%s from source(%d), hver:%" PRIu64 " too large, mver:%" PRIu64, - pTable->tableName, sdbGetActionStr(action), sdbGetKeyStr(pTable, pHead->cont), type, pHead->version, tsSdbObj.version); + pTable->tableName, sdbGetActionStr(action), sdbGetKeyStr(pTable, pHead->cont), qtype, pHead->version, tsSdbObj.version); return TSDB_CODE_SUCCESS; } else if (pHead->version != tsSdbObj.version + 1) { pthread_mutex_unlock(&tsSdbObj.mutex); sdbError("vgId:1, sdb:%s, failed to restore %s key:%s from source(%d), hver:%" PRIu64 " too large, mver:%" PRIu64, - pTable->tableName, sdbGetActionStr(action), sdbGetKeyStr(pTable, pHead->cont), type, pHead->version, tsSdbObj.version); + pTable->tableName, sdbGetActionStr(action), sdbGetKeyStr(pTable, pHead->cont), qtype, pHead->version, tsSdbObj.version); return TSDB_CODE_SYN_INVALID_VERSION; } else { tsSdbObj.version = pHead->version; @@ -613,7 +614,7 @@ static int sdbWrite(void *param, void *data, int32_t type, void *pMsg) { pthread_mutex_unlock(&tsSdbObj.mutex); - // from app, oper is created + // from app, wmsg is created if (pWrite != NULL) { // forward to peers pWrite->processedCount = 0; @@ -639,11 +640,11 @@ static int sdbWrite(void *param, void *data, int32_t type, void *pMsg) { // even it is WAL/FWD, it shall be called to update version in sync syncForwardToPeer(tsSdbObj.sync, pHead, pWrite, TAOS_QTYPE_RPC); - // from wal or forward msg, oper not created, should add into hash + // from wal or forward msg, wmsg not created, should add into hash if (action == SDB_ACTION_INSERT) { - SSWriteMsg oper = {.rowSize = pHead->len, .rowData = pHead->cont, .table = pTable}; - code = (*pTable->fpDecode)(&oper); - return sdbInsertHash(pTable, &oper); + SSWriteMsg wmsg = {.rowSize = pHead->len, .rowData = pHead->cont, .pTable = pTable}; + code = (*pTable->fpDecode)(&wmsg); + return sdbInsertHash(pTable, &wmsg); } else if (action == SDB_ACTION_DELETE) { void *pRow = sdbGetRowMeta(pTable, pHead->cont); if (pRow == NULL) { @@ -651,8 +652,8 @@ static int sdbWrite(void *param, void *data, int32_t type, void *pMsg) { sdbGetKeyStr(pTable, pHead->cont)); return TSDB_CODE_SUCCESS; } - SSWriteMsg oper = {.table = pTable, .pObj = pRow}; - return sdbDeleteHash(pTable, &oper); + SSWriteMsg wmsg = {.pTable = pTable, .pObj = pRow}; + return sdbDeleteHash(pTable, &wmsg); } else if (action == SDB_ACTION_UPDATE) { void *pRow = sdbGetRowMeta(pTable, pHead->cont); if (pRow == NULL) { @@ -660,16 +661,16 @@ static int sdbWrite(void *param, void *data, int32_t type, void *pMsg) { sdbGetKeyStr(pTable, pHead->cont)); return TSDB_CODE_SUCCESS; } - SSWriteMsg oper = {.rowSize = pHead->len, .rowData = pHead->cont, .table = pTable}; - code = (*pTable->fpDecode)(&oper); - return sdbUpdateHash(pTable, &oper); + SSWriteMsg wmsg = {.rowSize = pHead->len, .rowData = pHead->cont, .pTable = pTable}; + code = (*pTable->fpDecode)(&wmsg); + return sdbUpdateHash(pTable, &wmsg); } else { return TSDB_CODE_MND_INVALID_MSG_TYPE; } } int32_t sdbInsertRow(SSWriteMsg *pWrite) { - SSdbTable *pTable = (SSdbTable *)pWrite->table; + SSdbTable *pTable = pWrite->pTable; if (pTable == NULL) return TSDB_CODE_MND_SDB_INVALID_TABLE_TYPE; if (sdbGetRowFromObj(pTable, pWrite->pObj)) { @@ -699,15 +700,15 @@ int32_t sdbInsertRow(SSWriteMsg *pWrite) { return TSDB_CODE_SUCCESS; } - if (pWrite->reqFp) { - return (*pWrite->reqFp)(pWrite->pMsg); + if (pWrite->fpReq) { + return (*pWrite->fpReq)(pWrite->pMsg); } else { return sdbInsertRowImp(pWrite); } } int32_t sdbInsertRowImp(SSWriteMsg *pWrite) { - SSdbTable *pTable = (SSdbTable *)pWrite->table; + SSdbTable *pTable = pWrite->pTable; if (pTable == NULL) return TSDB_CODE_MND_SDB_INVALID_TABLE_TYPE; int32_t size = sizeof(SSWriteMsg) + sizeof(SWalHead) + pTable->maxRowSize + SDB_SYNC_HACK; @@ -729,14 +730,14 @@ int32_t sdbInsertRowImp(SSWriteMsg *pWrite) { pNewOper->pMsg, pTable->tableName, pWrite->pObj, sdbGetObjStr(pTable, pWrite->pObj)); } - sdbIncRef(pNewOper->table, pNewOper->pObj); + sdbIncRef(pNewOper->pTable, pNewOper->pObj); taosWriteQitem(tsSdbWQueue, TAOS_QTYPE_RPC, pNewOper); return TSDB_CODE_MND_ACTION_IN_PROGRESS; } -bool sdbCheckRowDeleted(void *pTableInput, void *pRow) { - SSdbTable *pTable = pTableInput; +bool sdbCheckRowDeleted(void *tparam, void *pRow) { + SSdbTable *pTable = tparam; if (pTable == NULL) return false; int32_t *updateEnd = pRow + pTable->refCountPos - 4; @@ -744,7 +745,7 @@ bool sdbCheckRowDeleted(void *pTableInput, void *pRow) { } int32_t sdbDeleteRow(SSWriteMsg *pWrite) { - SSdbTable *pTable = (SSdbTable *)pWrite->table; + SSdbTable *pTable = pWrite->pTable; if (pTable == NULL) return TSDB_CODE_MND_SDB_INVALID_TABLE_TYPE; void *pRow = sdbGetRowMetaFromObj(pTable, pWrite->pObj); @@ -768,15 +769,15 @@ int32_t sdbDeleteRow(SSWriteMsg *pWrite) { return TSDB_CODE_SUCCESS; } - if (pWrite->reqFp) { - return (*pWrite->reqFp)(pWrite->pMsg); + if (pWrite->fpReq) { + return (*pWrite->fpReq)(pWrite->pMsg); } else { return sdbDeleteRowImp(pWrite); } } int32_t sdbDeleteRowImp(SSWriteMsg *pWrite) { - SSdbTable *pTable = (SSdbTable *)pWrite->table; + SSdbTable *pTable = pWrite->pTable; if (pTable == NULL) return TSDB_CODE_MND_SDB_INVALID_TABLE_TYPE; int32_t size = sizeof(SSWriteMsg) + sizeof(SWalHead) + pTable->maxRowSize + SDB_SYNC_HACK; @@ -803,7 +804,7 @@ int32_t sdbDeleteRowImp(SSWriteMsg *pWrite) { } int32_t sdbUpdateRow(SSWriteMsg *pWrite) { - SSdbTable *pTable = (SSdbTable *)pWrite->table; + SSdbTable *pTable = pWrite->pTable; if (pTable == NULL) return TSDB_CODE_MND_SDB_INVALID_TABLE_TYPE; void *pRow = sdbGetRowMetaFromObj(pTable, pWrite->pObj); @@ -823,15 +824,15 @@ int32_t sdbUpdateRow(SSWriteMsg *pWrite) { return TSDB_CODE_SUCCESS; } - if (pWrite->reqFp) { - return (*pWrite->reqFp)(pWrite->pMsg); + if (pWrite->fpReq) { + return (*pWrite->fpReq)(pWrite->pMsg); } else { return sdbUpdateRowImp(pWrite); } } int32_t sdbUpdateRowImp(SSWriteMsg *pWrite) { - SSdbTable *pTable = (SSdbTable *)pWrite->table; + SSdbTable *pTable = pWrite->pTable; if (pTable == NULL) return TSDB_CODE_MND_SDB_INVALID_TABLE_TYPE; int32_t size = sizeof(SSWriteMsg) + sizeof(SWalHead) + pTable->maxRowSize + SDB_SYNC_HACK; @@ -852,14 +853,14 @@ int32_t sdbUpdateRowImp(SSWriteMsg *pWrite) { pNewOper->pMsg, pTable->tableName, pWrite->pObj, sdbGetObjStr(pTable, pWrite->pObj)); } - sdbIncRef(pNewOper->table, pNewOper->pObj); + sdbIncRef(pNewOper->pTable, pNewOper->pObj); taosWriteQitem(tsSdbWQueue, TAOS_QTYPE_RPC, pNewOper); return TSDB_CODE_MND_ACTION_IN_PROGRESS; } -void *sdbFetchRow(void *handle, void *pNode, void **ppRow) { - SSdbTable *pTable = (SSdbTable *)handle; +void *sdbFetchRow(void *tparam, void *pNode, void **ppRow) { + SSdbTable *pTable = tparam; *ppRow = NULL; if (pTable == NULL) return NULL; @@ -880,7 +881,7 @@ void *sdbFetchRow(void *handle, void *pNode, void **ppRow) { } *ppRow = *ppMetaRow; - sdbIncRef(handle, *ppMetaRow); + sdbIncRef(pTable, *ppMetaRow); return pIter; } @@ -934,12 +935,12 @@ void sdbCloseTable(void *handle) { void **ppRow = taosHashIterGet(pIter); if (ppRow == NULL) continue; - SSWriteMsg oper = { + SSWriteMsg wmsg = { .pObj = *ppRow, - .table = pTable, + .pTable = pTable, }; - (*pTable->fpDestroy)(&oper); + (*pTable->fpDestroy)(&wmsg); } taosHashDestroyIter(pIter); @@ -950,44 +951,44 @@ void sdbCloseTable(void *handle) { free(pTable); } -int32_t sdbInitWriteWorker() { +int32_t sdbInitWorker() { tsSdbPool.num = 1; - tsSdbPool.worker = (SSWriteWorker *)calloc(sizeof(SSWriteWorker), tsSdbPool.num); + tsSdbPool.worker = calloc(sizeof(SSdbWorker), tsSdbPool.num); if (tsSdbPool.worker == NULL) return -1; for (int32_t i = 0; i < tsSdbPool.num; ++i) { - SSWriteWorker *pWorker = tsSdbPool.worker + i; + SSdbWorker *pWorker = tsSdbPool.worker + i; pWorker->workerId = i; } - sdbAllocWriteQueue(); + sdbAllocQueue(); mInfo("vgId:1, sdb write is opened"); return 0; } -void sdbCleanupWriteWorker() { +void sdbCleanupWorker() { for (int32_t i = 0; i < tsSdbPool.num; ++i) { - SSWriteWorker *pWorker = tsSdbPool.worker + i; + SSdbWorker *pWorker = tsSdbPool.worker + i; if (pWorker->thread) { taosQsetThreadResume(tsSdbWQset); } } for (int32_t i = 0; i < tsSdbPool.num; ++i) { - SSWriteWorker *pWorker = tsSdbPool.worker + i; + SSdbWorker *pWorker = tsSdbPool.worker + i; if (pWorker->thread) { pthread_join(pWorker->thread, NULL); } } - sdbFreeWritequeue(); + sdbFreeQueue(); tfree(tsSdbPool.worker); mInfo("vgId:1, sdb write is closed"); } -int32_t sdbAllocWriteQueue() { +int32_t sdbAllocQueue() { tsSdbWQueue = taosOpenQueue(); if (tsSdbWQueue == NULL) return TSDB_CODE_MND_OUT_OF_MEMORY; @@ -1006,7 +1007,7 @@ int32_t sdbAllocWriteQueue() { } for (int32_t i = 0; i < tsSdbPool.num; ++i) { - SSWriteWorker *pWorker = tsSdbPool.worker + i; + SSdbWorker *pWorker = tsSdbPool.worker + i; pWorker->workerId = i; pthread_attr_t thAttr; @@ -1029,7 +1030,7 @@ int32_t sdbAllocWriteQueue() { return TSDB_CODE_SUCCESS; } -void sdbFreeWritequeue() { +void sdbFreeQueue() { taosCloseQueue(tsSdbWQueue); taosFreeQall(tsSdbWQall); taosCloseQset(tsSdbWQset); @@ -1038,8 +1039,8 @@ void sdbFreeWritequeue() { tsSdbWQueue = NULL; } -int32_t sdbWriteToQueue(void *param, void *data, int32_t qtype, void *pMsg) { - SWalHead *pHead = data; +int32_t sdbWriteToQueue(void *wparam, void *hparam, int32_t qtype, void *unsed) { + SWalHead *pHead = hparam; int32_t size = sizeof(SWalHead) + pHead->len; SWalHead *pWal = taosAllocateQitem(size); memcpy(pWal, pHead, size); @@ -1048,10 +1049,10 @@ int32_t sdbWriteToQueue(void *param, void *data, int32_t qtype, void *pMsg) { return 0; } -static void *sdbWorkerFp(void *param) { +static void *sdbWorkerFp(void *pWorker) { SWalHead *pHead; SSWriteMsg *pWrite; - int32_t type; + int32_t qtype; int32_t numOfMsgs; void * item; void * unUsed; @@ -1064,22 +1065,22 @@ static void *sdbWorkerFp(void *param) { } for (int32_t i = 0; i < numOfMsgs; ++i) { - taosGetQitem(tsSdbWQall, &type, &item); - if (type == TAOS_QTYPE_RPC) { + taosGetQitem(tsSdbWQall, &qtype, &item); + if (qtype == TAOS_QTYPE_RPC) { pWrite = (SSWriteMsg *)item; pWrite->processedCount = 1; pHead = (void *)pWrite + sizeof(SSWriteMsg) + SDB_SYNC_HACK; if (pWrite->pMsg != NULL) { sdbDebug("vgId:1, ahandle:%p msg:%p, sdb:%s key:%p:%s hver:%" PRIu64 ", will be processed in sdb queue", - pWrite->pMsg->rpcMsg.ahandle, pWrite->pMsg, ((SSdbTable *)pWrite->table)->tableName, pWrite->pObj, - sdbGetKeyStr(pWrite->table, pHead->cont), pHead->version); + pWrite->pMsg->rpcMsg.ahandle, pWrite->pMsg, pWrite->pTable->tableName, pWrite->pObj, + sdbGetKeyStr(pWrite->pTable, pHead->cont), pHead->version); } } else { pHead = (SWalHead *)item; pWrite = NULL; } - int32_t code = sdbWrite(pWrite, pHead, type, NULL); + int32_t code = sdbWrite(pWrite, pHead, qtype, NULL); if (code > 0) code = 0; if (pWrite) { pWrite->retCode = code; @@ -1093,12 +1094,12 @@ static void *sdbWorkerFp(void *param) { // browse all items, and process them one by one taosResetQitems(tsSdbWQall); for (int32_t i = 0; i < numOfMsgs; ++i) { - taosGetQitem(tsSdbWQall, &type, &item); + taosGetQitem(tsSdbWQall, &qtype, &item); - if (type == TAOS_QTYPE_RPC) { + if (qtype == TAOS_QTYPE_RPC) { pWrite = (SSWriteMsg *)item; sdbConfirmForward(NULL, pWrite, pWrite->retCode); - } else if (type == TAOS_QTYPE_FWD) { + } else if (qtype == TAOS_QTYPE_FWD) { pHead = (SWalHead *)item; syncConfirmForward(tsSdbObj.sync, pHead->version, pHead->len); taosFreeQitem(item); diff --git a/src/mnode/src/mnodeTable.c b/src/mnode/src/mnodeTable.c index d3ba149f39..1ba476cf2a 100644 --- a/src/mnode/src/mnodeTable.c +++ b/src/mnode/src/mnodeTable.c @@ -99,13 +99,13 @@ static void mnodeDestroyChildTable(SCTableObj *pTable) { tfree(pTable); } -static int32_t mnodeChildTableActionDestroy(SSWriteMsg *pOper) { - mnodeDestroyChildTable(pOper->pObj); +static int32_t mnodeChildTableActionDestroy(SSWriteMsg *pWMsg) { + mnodeDestroyChildTable(pWMsg->pObj); return TSDB_CODE_SUCCESS; } -static int32_t mnodeChildTableActionInsert(SSWriteMsg *pOper) { - SCTableObj *pTable = pOper->pObj; +static int32_t mnodeChildTableActionInsert(SSWriteMsg *pWMsg) { + SCTableObj *pTable = pWMsg->pObj; SVgObj *pVgroup = mnodeGetVgroup(pTable->vgId); if (pVgroup == NULL) { @@ -153,8 +153,8 @@ static int32_t mnodeChildTableActionInsert(SSWriteMsg *pOper) { return TSDB_CODE_SUCCESS; } -static int32_t mnodeChildTableActionDelete(SSWriteMsg *pOper) { - SCTableObj *pTable = pOper->pObj; +static int32_t mnodeChildTableActionDelete(SSWriteMsg *pWMsg) { + SCTableObj *pTable = pWMsg->pObj; if (pTable->vgId == 0) { return TSDB_CODE_MND_VGROUP_NOT_EXIST; } @@ -189,8 +189,8 @@ static int32_t mnodeChildTableActionDelete(SSWriteMsg *pOper) { return TSDB_CODE_SUCCESS; } -static int32_t mnodeChildTableActionUpdate(SSWriteMsg *pOper) { - SCTableObj *pNew = pOper->pObj; +static int32_t mnodeChildTableActionUpdate(SSWriteMsg *pWMsg) { + SCTableObj *pNew = pWMsg->pObj; SCTableObj *pTable = mnodeGetChildTable(pNew->info.tableId); if (pTable != pNew) { void *oldTableId = pTable->info.tableId; @@ -216,50 +216,50 @@ static int32_t mnodeChildTableActionUpdate(SSWriteMsg *pOper) { return TSDB_CODE_SUCCESS; } -static int32_t mnodeChildTableActionEncode(SSWriteMsg *pOper) { - SCTableObj *pTable = pOper->pObj; - assert(pTable != NULL && pOper->rowData != NULL); +static int32_t mnodeChildTableActionEncode(SSWriteMsg *pWMsg) { + SCTableObj *pTable = pWMsg->pObj; + assert(pTable != NULL && pWMsg->rowData != NULL); int32_t len = strlen(pTable->info.tableId); if (len >= TSDB_TABLE_FNAME_LEN) return TSDB_CODE_MND_INVALID_TABLE_ID; - memcpy(pOper->rowData, pTable->info.tableId, len); - memset(pOper->rowData + len, 0, 1); + memcpy(pWMsg->rowData, pTable->info.tableId, len); + memset(pWMsg->rowData + len, 0, 1); len++; - memcpy(pOper->rowData + len, (char*)pTable + sizeof(char *), tsChildTableUpdateSize); + memcpy(pWMsg->rowData + len, (char*)pTable + sizeof(char *), tsChildTableUpdateSize); len += tsChildTableUpdateSize; if (pTable->info.type != TSDB_CHILD_TABLE) { int32_t schemaSize = pTable->numOfColumns * sizeof(SSchema); - memcpy(pOper->rowData + len, pTable->schema, schemaSize); + memcpy(pWMsg->rowData + len, pTable->schema, schemaSize); len += schemaSize; if (pTable->sqlLen != 0) { - memcpy(pOper->rowData + len, pTable->sql, pTable->sqlLen); + memcpy(pWMsg->rowData + len, pTable->sql, pTable->sqlLen); len += pTable->sqlLen; } } - pOper->rowSize = len; + pWMsg->rowSize = len; return TSDB_CODE_SUCCESS; } -static int32_t mnodeChildTableActionDecode(SSWriteMsg *pOper) { - assert(pOper->rowData != NULL); +static int32_t mnodeChildTableActionDecode(SSWriteMsg *pWMsg) { + assert(pWMsg->rowData != NULL); SCTableObj *pTable = calloc(1, sizeof(SCTableObj)); if (pTable == NULL) return TSDB_CODE_MND_OUT_OF_MEMORY; - int32_t len = strlen(pOper->rowData); + int32_t len = strlen(pWMsg->rowData); if (len >= TSDB_TABLE_FNAME_LEN) { free(pTable); return TSDB_CODE_MND_INVALID_TABLE_ID; } - pTable->info.tableId = strdup(pOper->rowData); + pTable->info.tableId = strdup(pWMsg->rowData); len++; - memcpy((char*)pTable + sizeof(char *), pOper->rowData + len, tsChildTableUpdateSize); + memcpy((char*)pTable + sizeof(char *), pWMsg->rowData + len, tsChildTableUpdateSize); len += tsChildTableUpdateSize; if (pTable->info.type != TSDB_CHILD_TABLE) { @@ -269,7 +269,7 @@ static int32_t mnodeChildTableActionDecode(SSWriteMsg *pOper) { mnodeDestroyChildTable(pTable); return TSDB_CODE_MND_INVALID_TABLE_TYPE; } - memcpy(pTable->schema, pOper->rowData + len, schemaSize); + memcpy(pTable->schema, pWMsg->rowData + len, schemaSize); len += schemaSize; if (pTable->sqlLen != 0) { @@ -278,11 +278,11 @@ static int32_t mnodeChildTableActionDecode(SSWriteMsg *pOper) { mnodeDestroyChildTable(pTable); return TSDB_CODE_MND_OUT_OF_MEMORY; } - memcpy(pTable->sql, pOper->rowData + len, pTable->sqlLen); + memcpy(pTable->sql, pWMsg->rowData + len, pTable->sqlLen); } } - pOper->pObj = pTable; + pWMsg->pObj = pTable; return TSDB_CODE_SUCCESS; } @@ -297,7 +297,7 @@ static int32_t mnodeChildTableActionRestored() { SDbObj *pDb = mnodeGetDbByTableId(pTable->info.tableId); if (pDb == NULL || pDb->status != TSDB_DB_STATUS_READY) { mError("ctable:%s, failed to get db or db in dropping, discard it", pTable->info.tableId); - SSWriteMsg desc = {.type = SDB_OPER_LOCAL, .pObj = pTable, .table = tsChildTableSdb}; + SSWriteMsg desc = {.type = SDB_OPER_LOCAL, .pObj = pTable, .pTable = tsChildTableSdb}; sdbDeleteRow(&desc); mnodeDecTableRef(pTable); mnodeDecDbRef(pDb); @@ -309,7 +309,7 @@ static int32_t mnodeChildTableActionRestored() { if (pVgroup == NULL) { mError("ctable:%s, failed to get vgId:%d tid:%d, discard it", pTable->info.tableId, pTable->vgId, pTable->tid); pTable->vgId = 0; - SSWriteMsg desc = {.type = SDB_OPER_LOCAL, .pObj = pTable, .table = tsChildTableSdb}; + SSWriteMsg desc = {.type = SDB_OPER_LOCAL, .pObj = pTable, .pTable = tsChildTableSdb}; sdbDeleteRow(&desc); mnodeDecTableRef(pTable); continue; @@ -320,7 +320,7 @@ static int32_t mnodeChildTableActionRestored() { mError("ctable:%s, db:%s not match with vgId:%d db:%s sid:%d, discard it", pTable->info.tableId, pDb->name, pTable->vgId, pVgroup->dbName, pTable->tid); pTable->vgId = 0; - SSWriteMsg desc = {.type = SDB_OPER_LOCAL, .pObj = pTable, .table = tsChildTableSdb}; + SSWriteMsg desc = {.type = SDB_OPER_LOCAL, .pObj = pTable, .pTable = tsChildTableSdb}; sdbDeleteRow(&desc); mnodeDecTableRef(pTable); continue; @@ -331,7 +331,7 @@ static int32_t mnodeChildTableActionRestored() { if (pSuperTable == NULL) { mError("ctable:%s, stable:%" PRIu64 " not exist", pTable->info.tableId, pTable->suid); pTable->vgId = 0; - SSWriteMsg desc = {.type = SDB_OPER_LOCAL, .pObj = pTable, .table = tsChildTableSdb}; + SSWriteMsg desc = {.type = SDB_OPER_LOCAL, .pObj = pTable, .pTable = tsChildTableSdb}; sdbDeleteRow(&desc); mnodeDecTableRef(pTable); continue; @@ -430,13 +430,13 @@ static void mnodeDestroySuperTable(SSTableObj *pStable) { tfree(pStable); } -static int32_t mnodeSuperTableActionDestroy(SSWriteMsg *pOper) { - mnodeDestroySuperTable(pOper->pObj); +static int32_t mnodeSuperTableActionDestroy(SSWriteMsg *pWMsg) { + mnodeDestroySuperTable(pWMsg->pObj); return TSDB_CODE_SUCCESS; } -static int32_t mnodeSuperTableActionInsert(SSWriteMsg *pOper) { - SSTableObj *pStable = pOper->pObj; +static int32_t mnodeSuperTableActionInsert(SSWriteMsg *pWMsg) { + SSTableObj *pStable = pWMsg->pObj; SDbObj *pDb = mnodeGetDbByTableId(pStable->info.tableId); if (pDb != NULL && pDb->status == TSDB_DB_STATUS_READY) { mnodeAddSuperTableIntoDb(pDb); @@ -446,8 +446,8 @@ static int32_t mnodeSuperTableActionInsert(SSWriteMsg *pOper) { return TSDB_CODE_SUCCESS; } -static int32_t mnodeSuperTableActionDelete(SSWriteMsg *pOper) { - SSTableObj *pStable = pOper->pObj; +static int32_t mnodeSuperTableActionDelete(SSWriteMsg *pWMsg) { + SSTableObj *pStable = pWMsg->pObj; SDbObj *pDb = mnodeGetDbByTableId(pStable->info.tableId); if (pDb != NULL) { mnodeRemoveSuperTableFromDb(pDb); @@ -458,8 +458,8 @@ static int32_t mnodeSuperTableActionDelete(SSWriteMsg *pOper) { return TSDB_CODE_SUCCESS; } -static int32_t mnodeSuperTableActionUpdate(SSWriteMsg *pOper) { - SSTableObj *pNew = pOper->pObj; +static int32_t mnodeSuperTableActionUpdate(SSWriteMsg *pWMsg) { + SSTableObj *pNew = pWMsg->pObj; SSTableObj *pTable = mnodeGetSuperTable(pNew->info.tableId); if (pTable != NULL && pTable != pNew) { void *oldTableId = pTable->info.tableId; @@ -483,43 +483,43 @@ static int32_t mnodeSuperTableActionUpdate(SSWriteMsg *pOper) { return TSDB_CODE_SUCCESS; } -static int32_t mnodeSuperTableActionEncode(SSWriteMsg *pOper) { - SSTableObj *pStable = pOper->pObj; - assert(pOper->pObj != NULL && pOper->rowData != NULL); +static int32_t mnodeSuperTableActionEncode(SSWriteMsg *pWMsg) { + SSTableObj *pStable = pWMsg->pObj; + assert(pWMsg->pObj != NULL && pWMsg->rowData != NULL); int32_t len = strlen(pStable->info.tableId); if (len >= TSDB_TABLE_FNAME_LEN) len = TSDB_CODE_MND_INVALID_TABLE_ID; - memcpy(pOper->rowData, pStable->info.tableId, len); - memset(pOper->rowData + len, 0, 1); + memcpy(pWMsg->rowData, pStable->info.tableId, len); + memset(pWMsg->rowData + len, 0, 1); len++; - memcpy(pOper->rowData + len, (char*)pStable + sizeof(char *), tsSuperTableUpdateSize); + memcpy(pWMsg->rowData + len, (char*)pStable + sizeof(char *), tsSuperTableUpdateSize); len += tsSuperTableUpdateSize; int32_t schemaSize = sizeof(SSchema) * (pStable->numOfColumns + pStable->numOfTags); - memcpy(pOper->rowData + len, pStable->schema, schemaSize); + memcpy(pWMsg->rowData + len, pStable->schema, schemaSize); len += schemaSize; - pOper->rowSize = len; + pWMsg->rowSize = len; return TSDB_CODE_SUCCESS; } -static int32_t mnodeSuperTableActionDecode(SSWriteMsg *pOper) { - assert(pOper->rowData != NULL); +static int32_t mnodeSuperTableActionDecode(SSWriteMsg *pWMsg) { + assert(pWMsg->rowData != NULL); SSTableObj *pStable = (SSTableObj *) calloc(1, sizeof(SSTableObj)); if (pStable == NULL) return TSDB_CODE_MND_OUT_OF_MEMORY; - int32_t len = strlen(pOper->rowData); + int32_t len = strlen(pWMsg->rowData); if (len >= TSDB_TABLE_FNAME_LEN){ free(pStable); return TSDB_CODE_MND_INVALID_TABLE_ID; } - pStable->info.tableId = strdup(pOper->rowData); + pStable->info.tableId = strdup(pWMsg->rowData); len++; - memcpy((char*)pStable + sizeof(char *), pOper->rowData + len, tsSuperTableUpdateSize); + memcpy((char*)pStable + sizeof(char *), pWMsg->rowData + len, tsSuperTableUpdateSize); len += tsSuperTableUpdateSize; int32_t schemaSize = sizeof(SSchema) * (pStable->numOfColumns + pStable->numOfTags); @@ -529,9 +529,9 @@ static int32_t mnodeSuperTableActionDecode(SSWriteMsg *pOper) { return TSDB_CODE_MND_NOT_SUPER_TABLE; } - memcpy(pStable->schema, pOper->rowData + len, schemaSize); + memcpy(pStable->schema, pWMsg->rowData + len, schemaSize); - pOper->pObj = pStable; + pWMsg->pObj = pStable; return TSDB_CODE_SUCCESS; } @@ -828,7 +828,7 @@ static int32_t mnodeCreateSuperTableCb(SMnodeMsg *pMsg, int32_t code) { } else { mError("app:%p:%p, stable:%s, failed to create in sdb, reason:%s", pMsg->rpcMsg.ahandle, pMsg, pTable->info.tableId, tstrerror(code)); - SSWriteMsg desc = {.type = SDB_OPER_GLOBAL, .pObj = pTable, .table = tsSuperTableSdb}; + SSWriteMsg desc = {.type = SDB_OPER_GLOBAL, .pObj = pTable, .pTable = tsSuperTableSdb}; sdbDeleteRow(&desc); } @@ -878,16 +878,16 @@ static int32_t mnodeProcessCreateSuperTableMsg(SMnodeMsg *pMsg) { pMsg->pTable = (STableObj *)pStable; mnodeIncTableRef(pMsg->pTable); - SSWriteMsg oper = { + SSWriteMsg wmsg = { .type = SDB_OPER_GLOBAL, - .table = tsSuperTableSdb, + .pTable = tsSuperTableSdb, .pObj = pStable, .rowSize = sizeof(SSTableObj) + schemaSize, .pMsg = pMsg, - .writeCb = mnodeCreateSuperTableCb + .fpWrite = mnodeCreateSuperTableCb }; - int32_t code = sdbInsertRow(&oper); + int32_t code = sdbInsertRow(&wmsg); if (code != TSDB_CODE_SUCCESS && code != TSDB_CODE_MND_ACTION_IN_PROGRESS) { mnodeDestroySuperTable(pStable); pMsg->pTable = NULL; @@ -937,15 +937,15 @@ static int32_t mnodeProcessDropSuperTableMsg(SMnodeMsg *pMsg) { mnodeDropAllChildTablesInStable(pStable); } - SSWriteMsg oper = { - .type = SDB_OPER_GLOBAL, - .table = tsSuperTableSdb, - .pObj = pStable, - .pMsg = pMsg, - .writeCb = mnodeDropSuperTableCb + SSWriteMsg wmsg = { + .type = SDB_OPER_GLOBAL, + .pTable = tsSuperTableSdb, + .pObj = pStable, + .pMsg = pMsg, + .fpWrite = mnodeDropSuperTableCb }; - int32_t code = sdbDeleteRow(&oper); + int32_t code = sdbDeleteRow(&wmsg); if (code != TSDB_CODE_SUCCESS && code != TSDB_CODE_MND_ACTION_IN_PROGRESS) { mError("app:%p:%p, table:%s, failed to drop, reason:%s", pMsg->rpcMsg.ahandle, pMsg, pStable->info.tableId, tstrerror(code)); @@ -1010,15 +1010,15 @@ static int32_t mnodeAddSuperTableTag(SMnodeMsg *pMsg, SSchema schema[], int32_t mInfo("app:%p:%p, stable %s, start to add tag %s", pMsg->rpcMsg.ahandle, pMsg, pStable->info.tableId, schema[0].name); - SSWriteMsg oper = { - .type = SDB_OPER_GLOBAL, - .table = tsSuperTableSdb, - .pObj = pStable, - .pMsg = pMsg, - .writeCb = mnodeAddSuperTableTagCb + SSWriteMsg wmsg = { + .type = SDB_OPER_GLOBAL, + .pTable = tsSuperTableSdb, + .pObj = pStable, + .pMsg = pMsg, + .fpWrite = mnodeAddSuperTableTagCb }; - return sdbUpdateRow(&oper); + return sdbUpdateRow(&wmsg); } static int32_t mnodeDropSuperTableTagCb(SMnodeMsg *pMsg, int32_t code) { @@ -1044,15 +1044,15 @@ static int32_t mnodeDropSuperTableTag(SMnodeMsg *pMsg, char *tagName) { mInfo("app:%p:%p, stable %s, start to drop tag %s", pMsg->rpcMsg.ahandle, pMsg, pStable->info.tableId, tagName); - SSWriteMsg oper = { - .type = SDB_OPER_GLOBAL, - .table = tsSuperTableSdb, - .pObj = pStable, - .pMsg = pMsg, - .writeCb = mnodeDropSuperTableTagCb + SSWriteMsg wmsg = { + .type = SDB_OPER_GLOBAL, + .pTable = tsSuperTableSdb, + .pObj = pStable, + .pMsg = pMsg, + .fpWrite = mnodeDropSuperTableTagCb }; - return sdbUpdateRow(&oper); + return sdbUpdateRow(&wmsg); } static int32_t mnodeModifySuperTableTagNameCb(SMnodeMsg *pMsg, int32_t code) { @@ -1088,15 +1088,15 @@ static int32_t mnodeModifySuperTableTagName(SMnodeMsg *pMsg, char *oldTagName, c mInfo("app:%p:%p, stable %s, start to modify tag %s to %s", pMsg->rpcMsg.ahandle, pMsg, pStable->info.tableId, oldTagName, newTagName); - SSWriteMsg oper = { - .type = SDB_OPER_GLOBAL, - .table = tsSuperTableSdb, - .pObj = pStable, - .pMsg = pMsg, - .writeCb = mnodeModifySuperTableTagNameCb + SSWriteMsg wmsg = { + .type = SDB_OPER_GLOBAL, + .pTable = tsSuperTableSdb, + .pObj = pStable, + .pMsg = pMsg, + .fpWrite = mnodeModifySuperTableTagNameCb }; - return sdbUpdateRow(&oper); + return sdbUpdateRow(&wmsg); } static int32_t mnodeFindSuperTableColumnIndex(SSTableObj *pStable, char *colName) { @@ -1162,15 +1162,15 @@ static int32_t mnodeAddSuperTableColumn(SMnodeMsg *pMsg, SSchema schema[], int32 mInfo("app:%p:%p, stable %s, start to add column", pMsg->rpcMsg.ahandle, pMsg, pStable->info.tableId); - SSWriteMsg oper = { - .type = SDB_OPER_GLOBAL, - .table = tsSuperTableSdb, - .pObj = pStable, - .pMsg = pMsg, - .writeCb = mnodeAddSuperTableColumnCb + SSWriteMsg wmsg = { + .type = SDB_OPER_GLOBAL, + .pTable = tsSuperTableSdb, + .pObj = pStable, + .pMsg = pMsg, + .fpWrite = mnodeAddSuperTableColumnCb }; - return sdbUpdateRow(&oper); + return sdbUpdateRow(&wmsg); } static int32_t mnodeDropSuperTableColumnCb(SMnodeMsg *pMsg, int32_t code) { @@ -1207,15 +1207,15 @@ static int32_t mnodeDropSuperTableColumn(SMnodeMsg *pMsg, char *colName) { mInfo("app:%p:%p, stable %s, start to delete column", pMsg->rpcMsg.ahandle, pMsg, pStable->info.tableId); - SSWriteMsg oper = { - .type = SDB_OPER_GLOBAL, - .table = tsSuperTableSdb, - .pObj = pStable, - .pMsg = pMsg, - .writeCb = mnodeDropSuperTableColumnCb + SSWriteMsg wmsg = { + .type = SDB_OPER_GLOBAL, + .pTable = tsSuperTableSdb, + .pObj = pStable, + .pMsg = pMsg, + .fpWrite = mnodeDropSuperTableColumnCb }; - return sdbUpdateRow(&oper); + return sdbUpdateRow(&wmsg); } static int32_t mnodeChangeSuperTableColumnCb(SMnodeMsg *pMsg, int32_t code) { @@ -1251,15 +1251,15 @@ static int32_t mnodeChangeSuperTableColumn(SMnodeMsg *pMsg, char *oldName, char mInfo("app:%p:%p, stable %s, start to modify column %s to %s", pMsg->rpcMsg.ahandle, pMsg, pStable->info.tableId, oldName, newName); - SSWriteMsg oper = { - .type = SDB_OPER_GLOBAL, - .table = tsSuperTableSdb, - .pObj = pStable, - .pMsg = pMsg, - .writeCb = mnodeChangeSuperTableColumnCb + SSWriteMsg wmsg = { + .type = SDB_OPER_GLOBAL, + .pTable = tsSuperTableSdb, + .pObj = pStable, + .pMsg = pMsg, + .fpWrite = mnodeChangeSuperTableColumnCb }; - return sdbUpdateRow(&oper); + return sdbUpdateRow(&wmsg); } // show super tables @@ -1417,12 +1417,12 @@ void mnodeDropAllSuperTables(SDbObj *pDropDb) { if (pTable == NULL) break; if (strncmp(prefix, pTable->info.tableId, prefixLen) == 0) { - SSWriteMsg oper = { - .type = SDB_OPER_LOCAL, - .table = tsSuperTableSdb, - .pObj = pTable, + SSWriteMsg wmsg = { + .type = SDB_OPER_LOCAL, + .pTable = tsSuperTableSdb, + .pObj = pTable, }; - sdbDeleteRow(&oper); + sdbDeleteRow(&wmsg); numOfTables ++; } @@ -1694,7 +1694,7 @@ static int32_t mnodeDoCreateChildTableCb(SMnodeMsg *pMsg, int32_t code) { } else { mError("app:%p:%p, table:%s, failed to create table sid:%d, uid:%" PRIu64 ", reason:%s", pMsg->rpcMsg.ahandle, pMsg, pTable->info.tableId, pTable->tid, pTable->uid, tstrerror(code)); - SSWriteMsg desc = {.type = SDB_OPER_GLOBAL, .pObj = pTable, .table = tsChildTableSdb}; + SSWriteMsg desc = {.type = SDB_OPER_GLOBAL, .pObj = pTable, .pTable = tsChildTableSdb}; sdbDeleteRow(&desc); return code; } @@ -1781,11 +1781,11 @@ static int32_t mnodeDoCreateChildTable(SMnodeMsg *pMsg, int32_t tid) { mnodeIncTableRef(pMsg->pTable); SSWriteMsg desc = { - .type = SDB_OPER_GLOBAL, - .pObj = pTable, - .table = tsChildTableSdb, - .pMsg = pMsg, - .reqFp = mnodeDoCreateChildTableFp + .type = SDB_OPER_GLOBAL, + .pObj = pTable, + .pTable = tsChildTableSdb, + .pMsg = pMsg, + .fpReq = mnodeDoCreateChildTableFp }; int32_t code = sdbInsertRow(&desc); @@ -1901,15 +1901,15 @@ static int32_t mnodeProcessDropChildTableMsg(SMnodeMsg *pMsg) { return TSDB_CODE_MND_APP_ERROR; } - SSWriteMsg oper = { - .type = SDB_OPER_GLOBAL, - .table = tsChildTableSdb, - .pObj = pTable, - .pMsg = pMsg, - .writeCb = mnodeDropChildTableCb + SSWriteMsg wmsg = { + .type = SDB_OPER_GLOBAL, + .pTable = tsChildTableSdb, + .pObj = pTable, + .pMsg = pMsg, + .fpWrite = mnodeDropChildTableCb }; - int32_t code = sdbDeleteRow(&oper); + int32_t code = sdbDeleteRow(&wmsg); if (code != TSDB_CODE_SUCCESS && code != TSDB_CODE_MND_ACTION_IN_PROGRESS) { mError("app:%p:%p, ctable:%s, failed to drop, reason:%s", pMsg->rpcMsg.ahandle, pMsg, pTable->info.tableId, tstrerror(code)); @@ -2005,15 +2005,15 @@ static int32_t mnodeAddNormalTableColumn(SMnodeMsg *pMsg, SSchema schema[], int3 mInfo("app:%p:%p, ctable %s, start to add column", pMsg->rpcMsg.ahandle, pMsg, pTable->info.tableId); - SSWriteMsg oper = { - .type = SDB_OPER_GLOBAL, - .table = tsChildTableSdb, - .pObj = pTable, - .pMsg = pMsg, - .writeCb = mnodeAlterNormalTableColumnCb + SSWriteMsg wmsg = { + .type = SDB_OPER_GLOBAL, + .pTable = tsChildTableSdb, + .pObj = pTable, + .pMsg = pMsg, + .fpWrite = mnodeAlterNormalTableColumnCb }; - return sdbUpdateRow(&oper); + return sdbUpdateRow(&wmsg); } static int32_t mnodeDropNormalTableColumn(SMnodeMsg *pMsg, char *colName) { @@ -2038,15 +2038,15 @@ static int32_t mnodeDropNormalTableColumn(SMnodeMsg *pMsg, char *colName) { mInfo("app:%p:%p, ctable %s, start to drop column %s", pMsg->rpcMsg.ahandle, pMsg, pTable->info.tableId, colName); - SSWriteMsg oper = { - .type = SDB_OPER_GLOBAL, - .table = tsChildTableSdb, - .pObj = pTable, - .pMsg = pMsg, - .writeCb = mnodeAlterNormalTableColumnCb + SSWriteMsg wmsg = { + .type = SDB_OPER_GLOBAL, + .pTable = tsChildTableSdb, + .pObj = pTable, + .pMsg = pMsg, + .fpWrite = mnodeAlterNormalTableColumnCb }; - return sdbUpdateRow(&oper); + return sdbUpdateRow(&wmsg); } static int32_t mnodeChangeNormalTableColumn(SMnodeMsg *pMsg, char *oldName, char *newName) { @@ -2075,15 +2075,15 @@ static int32_t mnodeChangeNormalTableColumn(SMnodeMsg *pMsg, char *oldName, char mInfo("app:%p:%p, ctable %s, start to modify column %s to %s", pMsg->rpcMsg.ahandle, pMsg, pTable->info.tableId, oldName, newName); - SSWriteMsg oper = { - .type = SDB_OPER_GLOBAL, - .table = tsChildTableSdb, - .pObj = pTable, - .pMsg = pMsg, - .writeCb = mnodeAlterNormalTableColumnCb + SSWriteMsg wmsg = { + .type = SDB_OPER_GLOBAL, + .pTable = tsChildTableSdb, + .pObj = pTable, + .pMsg = pMsg, + .fpWrite = mnodeAlterNormalTableColumnCb }; - return sdbUpdateRow(&oper); + return sdbUpdateRow(&wmsg); } static int32_t mnodeSetSchemaFromNormalTable(SSchema *pSchema, SCTableObj *pTable) { @@ -2218,12 +2218,12 @@ void mnodeDropAllChildTablesInVgroups(SVgObj *pVgroup) { if (pTable == NULL) break; if (pTable->vgId == pVgroup->vgId) { - SSWriteMsg oper = { - .type = SDB_OPER_LOCAL, - .table = tsChildTableSdb, - .pObj = pTable, + SSWriteMsg wmsg = { + .type = SDB_OPER_LOCAL, + .pTable = tsChildTableSdb, + .pObj = pTable, }; - sdbDeleteRow(&oper); + sdbDeleteRow(&wmsg); numOfTables++; } mnodeDecTableRef(pTable); @@ -2251,12 +2251,12 @@ void mnodeDropAllChildTables(SDbObj *pDropDb) { if (pTable == NULL) break; if (strncmp(prefix, pTable->info.tableId, prefixLen) == 0) { - SSWriteMsg oper = { - .type = SDB_OPER_LOCAL, - .table = tsChildTableSdb, - .pObj = pTable, + SSWriteMsg wmsg = { + .type = SDB_OPER_LOCAL, + .pTable = tsChildTableSdb, + .pObj = pTable, }; - sdbDeleteRow(&oper); + sdbDeleteRow(&wmsg); numOfTables++; } mnodeDecTableRef(pTable); @@ -2280,12 +2280,12 @@ static void mnodeDropAllChildTablesInStable(SSTableObj *pStable) { if (pTable == NULL) break; if (pTable->superTable == pStable) { - SSWriteMsg oper = { - .type = SDB_OPER_LOCAL, - .table = tsChildTableSdb, - .pObj = pTable, + SSWriteMsg wmsg = { + .type = SDB_OPER_LOCAL, + .pTable = tsChildTableSdb, + .pObj = pTable, }; - sdbDeleteRow(&oper); + sdbDeleteRow(&wmsg); numOfTables++; } @@ -2411,11 +2411,11 @@ static void mnodeProcessCreateChildTableRsp(SRpcMsg *rpcMsg) { if (rpcMsg->code == TSDB_CODE_SUCCESS || rpcMsg->code == TSDB_CODE_TDB_TABLE_ALREADY_EXIST) { SSWriteMsg desc = { - .type = SDB_OPER_GLOBAL, - .pObj = pTable, - .table = tsChildTableSdb, - .pMsg = mnodeMsg, - .writeCb = mnodeDoCreateChildTableCb + .type = SDB_OPER_GLOBAL, + .pObj = pTable, + .pTable = tsChildTableSdb, + .pMsg = mnodeMsg, + .fpWrite = mnodeDoCreateChildTableCb }; int32_t code = sdbInsertRowImp(&desc); @@ -2440,8 +2440,8 @@ static void mnodeProcessCreateChildTableRsp(SRpcMsg *rpcMsg) { mnodeMsg->rpcMsg.ahandle, mnodeMsg, pTable->info.tableId, pTable->vgId, pTable->tid, pTable->uid, tstrerror(rpcMsg->code), mnodeMsg->rpcMsg.handle, mnodeMsg->incomingTs, sec, mnodeMsg->retry); - SSWriteMsg oper = {.type = SDB_OPER_GLOBAL, .table = tsChildTableSdb, .pObj = pTable}; - sdbDeleteRow(&oper); + SSWriteMsg wmsg = {.type = SDB_OPER_GLOBAL, .pTable = tsChildTableSdb, .pObj = pTable}; + sdbDeleteRow(&wmsg); if (rpcMsg->code == TSDB_CODE_APP_NOT_READY) { //Avoid retry again in client diff --git a/src/mnode/src/mnodeUser.c b/src/mnode/src/mnodeUser.c index edd0839b0c..95d5befa5a 100644 --- a/src/mnode/src/mnodeUser.c +++ b/src/mnode/src/mnodeUser.c @@ -42,13 +42,13 @@ static int32_t mnodeProcessAlterUserMsg(SMnodeMsg *pMsg); static int32_t mnodeProcessDropUserMsg(SMnodeMsg *pMsg); static int32_t mnodeProcessAuthMsg(SMnodeMsg *pMsg); -static int32_t mnodeUserActionDestroy(SSWriteMsg *pOper) { - tfree(pOper->pObj); +static int32_t mnodeUserActionDestroy(SSWriteMsg *pWMsg) { + tfree(pWMsg->pObj); return TSDB_CODE_SUCCESS; } -static int32_t mnodeUserActionInsert(SSWriteMsg *pOper) { - SUserObj *pUser = pOper->pObj; +static int32_t mnodeUserActionInsert(SSWriteMsg *pWMsg) { + SUserObj *pUser = pWMsg->pObj; SAcctObj *pAcct = mnodeGetAcct(pUser->acct); if (pAcct != NULL) { @@ -62,8 +62,8 @@ static int32_t mnodeUserActionInsert(SSWriteMsg *pOper) { return TSDB_CODE_SUCCESS; } -static int32_t mnodeUserActionDelete(SSWriteMsg *pOper) { - SUserObj *pUser = pOper->pObj; +static int32_t mnodeUserActionDelete(SSWriteMsg *pWMsg) { + SUserObj *pUser = pWMsg->pObj; SAcctObj *pAcct = mnodeGetAcct(pUser->acct); if (pAcct != NULL) { @@ -74,8 +74,8 @@ static int32_t mnodeUserActionDelete(SSWriteMsg *pOper) { return TSDB_CODE_SUCCESS; } -static int32_t mnodeUserActionUpdate(SSWriteMsg *pOper) { - SUserObj *pUser = pOper->pObj; +static int32_t mnodeUserActionUpdate(SSWriteMsg *pWMsg) { + SUserObj *pUser = pWMsg->pObj; SUserObj *pSaved = mnodeGetUser(pUser->user); if (pUser != pSaved) { memcpy(pSaved, pUser, tsUserUpdateSize); @@ -85,19 +85,19 @@ static int32_t mnodeUserActionUpdate(SSWriteMsg *pOper) { return TSDB_CODE_SUCCESS; } -static int32_t mnodeUserActionEncode(SSWriteMsg *pOper) { - SUserObj *pUser = pOper->pObj; - memcpy(pOper->rowData, pUser, tsUserUpdateSize); - pOper->rowSize = tsUserUpdateSize; +static int32_t mnodeUserActionEncode(SSWriteMsg *pWMsg) { + SUserObj *pUser = pWMsg->pObj; + memcpy(pWMsg->rowData, pUser, tsUserUpdateSize); + pWMsg->rowSize = tsUserUpdateSize; return TSDB_CODE_SUCCESS; } -static int32_t mnodeUserActionDecode(SSWriteMsg *pOper) { +static int32_t mnodeUserActionDecode(SSWriteMsg *pWMsg) { SUserObj *pUser = (SUserObj *)calloc(1, sizeof(SUserObj)); if (pUser == NULL) return TSDB_CODE_MND_OUT_OF_MEMORY; - memcpy(pUser, pOper->rowData, tsUserUpdateSize); - pOper->pObj = pUser; + memcpy(pUser, pWMsg->rowData, tsUserUpdateSize); + pWMsg->pObj = pUser; return TSDB_CODE_SUCCESS; } @@ -205,14 +205,14 @@ void mnodeDecUserRef(SUserObj *pUser) { } static int32_t mnodeUpdateUser(SUserObj *pUser, void *pMsg) { - SSWriteMsg oper = { - .type = SDB_OPER_GLOBAL, - .table = tsUserSdb, - .pObj = pUser, - .pMsg = pMsg + SSWriteMsg wmsg = { + .type = SDB_OPER_GLOBAL, + .pTable = tsUserSdb, + .pObj = pUser, + .pMsg = pMsg }; - int32_t code = sdbUpdateRow(&oper); + int32_t code = sdbUpdateRow(&wmsg); if (code != TSDB_CODE_SUCCESS && code != TSDB_CODE_MND_ACTION_IN_PROGRESS) { mError("user:%s, failed to alter by %s, reason:%s", pUser->user, mnodeGetUserFromMsg(pMsg), tstrerror(code)); } else { @@ -259,15 +259,15 @@ int32_t mnodeCreateUser(SAcctObj *pAcct, char *name, char *pass, void *pMsg) { pUser->superAuth = 1; } - SSWriteMsg oper = { - .type = SDB_OPER_GLOBAL, - .table = tsUserSdb, - .pObj = pUser, - .rowSize = sizeof(SUserObj), - .pMsg = pMsg + SSWriteMsg wmsg = { + .type = SDB_OPER_GLOBAL, + .pTable = tsUserSdb, + .pObj = pUser, + .rowSize = sizeof(SUserObj), + .pMsg = pMsg }; - code = sdbInsertRow(&oper); + code = sdbInsertRow(&wmsg); if (code != TSDB_CODE_SUCCESS && code != TSDB_CODE_MND_ACTION_IN_PROGRESS) { mError("user:%s, failed to create by %s, reason:%s", pUser->user, mnodeGetUserFromMsg(pMsg), tstrerror(code)); tfree(pUser); @@ -279,14 +279,14 @@ int32_t mnodeCreateUser(SAcctObj *pAcct, char *name, char *pass, void *pMsg) { } static int32_t mnodeDropUser(SUserObj *pUser, void *pMsg) { - SSWriteMsg oper = { - .type = SDB_OPER_GLOBAL, - .table = tsUserSdb, - .pObj = pUser, - .pMsg = pMsg + SSWriteMsg wmsg = { + .type = SDB_OPER_GLOBAL, + .pTable = tsUserSdb, + .pObj = pUser, + .pMsg = pMsg }; - int32_t code = sdbDeleteRow(&oper); + int32_t code = sdbDeleteRow(&wmsg); if (code != TSDB_CODE_SUCCESS && code != TSDB_CODE_MND_ACTION_IN_PROGRESS) { mError("user:%s, failed to drop by %s, reason:%s", pUser->user, mnodeGetUserFromMsg(pMsg), tstrerror(code)); } else { @@ -562,12 +562,12 @@ void mnodeDropAllUsers(SAcctObj *pAcct) { if (pUser == NULL) break; if (strncmp(pUser->acct, pAcct->user, acctNameLen) == 0) { - SSWriteMsg oper = { - .type = SDB_OPER_LOCAL, - .table = tsUserSdb, - .pObj = pUser, + SSWriteMsg wmsg = { + .type = SDB_OPER_LOCAL, + .pTable = tsUserSdb, + .pObj = pUser, }; - sdbDeleteRow(&oper); + sdbDeleteRow(&wmsg); numOfUsers++; } diff --git a/src/mnode/src/mnodeVgroup.c b/src/mnode/src/mnodeVgroup.c index da0ed1cd36..5a99dfbfa3 100644 --- a/src/mnode/src/mnodeVgroup.c +++ b/src/mnode/src/mnodeVgroup.c @@ -72,13 +72,13 @@ static void mnodeDestroyVgroup(SVgObj *pVgroup) { tfree(pVgroup); } -static int32_t mnodeVgroupActionDestroy(SSWriteMsg *pOper) { - mnodeDestroyVgroup(pOper->pObj); +static int32_t mnodeVgroupActionDestroy(SSWriteMsg *pWMsg) { + mnodeDestroyVgroup(pWMsg->pObj); return TSDB_CODE_SUCCESS; } -static int32_t mnodeVgroupActionInsert(SSWriteMsg *pOper) { - SVgObj *pVgroup = pOper->pObj; +static int32_t mnodeVgroupActionInsert(SSWriteMsg *pWMsg) { + SVgObj *pVgroup = pWMsg->pObj; // refer to db SDbObj *pDb = mnodeGetDb(pVgroup->dbName); @@ -115,8 +115,8 @@ static int32_t mnodeVgroupActionInsert(SSWriteMsg *pOper) { return TSDB_CODE_SUCCESS; } -static int32_t mnodeVgroupActionDelete(SSWriteMsg *pOper) { - SVgObj *pVgroup = pOper->pObj; +static int32_t mnodeVgroupActionDelete(SSWriteMsg *pWMsg) { + SVgObj *pVgroup = pWMsg->pObj; if (pVgroup->pDb == NULL) { mError("vgId:%d, db:%s is not exist while insert into hash", pVgroup->vgId, pVgroup->dbName); @@ -137,8 +137,8 @@ static int32_t mnodeVgroupActionDelete(SSWriteMsg *pOper) { return TSDB_CODE_SUCCESS; } -static int32_t mnodeVgroupActionUpdate(SSWriteMsg *pOper) { - SVgObj *pNew = pOper->pObj; +static int32_t mnodeVgroupActionUpdate(SSWriteMsg *pWMsg) { + SVgObj *pNew = pWMsg->pObj; SVgObj *pVgroup = mnodeGetVgroup(pNew->vgId); if (pVgroup != pNew) { @@ -176,25 +176,25 @@ static int32_t mnodeVgroupActionUpdate(SSWriteMsg *pOper) { return TSDB_CODE_SUCCESS; } -static int32_t mnodeVgroupActionEncode(SSWriteMsg *pOper) { - SVgObj *pVgroup = pOper->pObj; - memcpy(pOper->rowData, pVgroup, tsVgUpdateSize); - SVgObj *pTmpVgroup = pOper->rowData; +static int32_t mnodeVgroupActionEncode(SSWriteMsg *pWMsg) { + SVgObj *pVgroup = pWMsg->pObj; + memcpy(pWMsg->rowData, pVgroup, tsVgUpdateSize); + SVgObj *pTmpVgroup = pWMsg->rowData; for (int32_t i = 0; i < TSDB_MAX_REPLICA; ++i) { pTmpVgroup->vnodeGid[i].pDnode = NULL; pTmpVgroup->vnodeGid[i].role = 0; } - pOper->rowSize = tsVgUpdateSize; + pWMsg->rowSize = tsVgUpdateSize; return TSDB_CODE_SUCCESS; } -static int32_t mnodeVgroupActionDecode(SSWriteMsg *pOper) { +static int32_t mnodeVgroupActionDecode(SSWriteMsg *pWMsg) { SVgObj *pVgroup = (SVgObj *) calloc(1, sizeof(SVgObj)); if (pVgroup == NULL) return TSDB_CODE_MND_OUT_OF_MEMORY; - memcpy(pVgroup, pOper->rowData, tsVgUpdateSize); - pOper->pObj = pVgroup; + memcpy(pVgroup, pWMsg->rowData, tsVgUpdateSize); + pWMsg->pObj = pVgroup; return TSDB_CODE_SUCCESS; } @@ -253,13 +253,13 @@ SVgObj *mnodeGetVgroup(int32_t vgId) { } void mnodeUpdateVgroup(SVgObj *pVgroup) { - SSWriteMsg oper = { - .type = SDB_OPER_GLOBAL, - .table = tsVgroupSdb, - .pObj = pVgroup + SSWriteMsg wmsg = { + .type = SDB_OPER_GLOBAL, + .pTable = tsVgroupSdb, + .pObj = pVgroup }; - int32_t code = sdbUpdateRow(&oper); + int32_t code = sdbUpdateRow(&wmsg); if (code != TSDB_CODE_SUCCESS && code != TSDB_CODE_MND_ACTION_IN_PROGRESS) { mError("vgId:%d, failed to update vgroup", pVgroup->vgId); } @@ -519,14 +519,14 @@ static int32_t mnodeCreateVgroupCb(SMnodeMsg *pMsg, int32_t code) { if (code != TSDB_CODE_SUCCESS) { mError("app:%p:%p, vgId:%d, failed to create in sdb, reason:%s", pMsg->rpcMsg.ahandle, pMsg, pVgroup->vgId, tstrerror(code)); - SSWriteMsg desc = {.type = SDB_OPER_GLOBAL, .pObj = pVgroup, .table = tsVgroupSdb}; + SSWriteMsg desc = {.type = SDB_OPER_GLOBAL, .pObj = pVgroup, .pTable = tsVgroupSdb}; sdbDeleteRow(&desc); return code; } else { mInfo("app:%p:%p, vgId:%d, is created in sdb, db:%s replica:%d", pMsg->rpcMsg.ahandle, pMsg, pVgroup->vgId, pDb->name, pVgroup->numOfVnodes); pVgroup->status = TAOS_VG_STATUS_READY; - SSWriteMsg desc = {.type = SDB_OPER_GLOBAL, .pObj = pVgroup, .table = tsVgroupSdb}; + SSWriteMsg desc = {.type = SDB_OPER_GLOBAL, .pObj = pVgroup, .pTable = tsVgroupSdb}; (void)sdbUpdateRow(&desc); dnodeReprocessMWriteMsg(pMsg); @@ -535,7 +535,7 @@ static int32_t mnodeCreateVgroupCb(SMnodeMsg *pMsg, int32_t code) { // mInfo("app:%p:%p, vgId:%d, is created in sdb, db:%s replica:%d", pMsg->rpcMsg.ahandle, pMsg, pVgroup->vgId, // pDb->name, pVgroup->numOfVnodes); // pVgroup->status = TAOS_VG_STATUS_READY; - // SSWriteMsg desc = {.type = SDB_OPER_GLOBAL, .pObj = pVgroup, .table = tsVgroupSdb}; + // SSWriteMsg desc = {.type = SDB_OPER_GLOBAL, .pObj = pVgroup, .pTable = tsVgroupSdb}; // (void)sdbUpdateRow(&desc); // dnodeReprocessMWriteMsg(pMsg); // return TSDB_CODE_MND_ACTION_IN_PROGRESS; @@ -571,16 +571,16 @@ int32_t mnodeCreateVgroup(SMnodeMsg *pMsg) { pMsg->pVgroup = pVgroup; mnodeIncVgroupRef(pVgroup); - SSWriteMsg oper = { - .type = SDB_OPER_GLOBAL, - .table = tsVgroupSdb, - .pObj = pVgroup, - .rowSize = sizeof(SVgObj), - .pMsg = pMsg, - .reqFp = mnodeCreateVgroupFp + SSWriteMsg wmsg = { + .type = SDB_OPER_GLOBAL, + .pTable = tsVgroupSdb, + .pObj = pVgroup, + .rowSize = sizeof(SVgObj), + .pMsg = pMsg, + .fpReq = mnodeCreateVgroupFp }; - code = sdbInsertRow(&oper); + code = sdbInsertRow(&wmsg); if (code != TSDB_CODE_SUCCESS && code != TSDB_CODE_MND_ACTION_IN_PROGRESS) { pMsg->pVgroup = NULL; mnodeDestroyVgroup(pVgroup); @@ -595,12 +595,12 @@ void mnodeDropVgroup(SVgObj *pVgroup, void *ahandle) { } else { mDebug("vgId:%d, replica:%d is deleting from sdb", pVgroup->vgId, pVgroup->numOfVnodes); mnodeSendDropVgroupMsg(pVgroup, NULL); - SSWriteMsg oper = { - .type = SDB_OPER_GLOBAL, - .table = tsVgroupSdb, - .pObj = pVgroup + SSWriteMsg wmsg = { + .type = SDB_OPER_GLOBAL, + .pTable = tsVgroupSdb, + .pObj = pVgroup }; - sdbDeleteRow(&oper); + sdbDeleteRow(&wmsg); } } @@ -957,28 +957,28 @@ static void mnodeProcessCreateVnodeRsp(SRpcMsg *rpcMsg) { if (mnodeMsg->received != mnodeMsg->expected) return; if (mnodeMsg->received == mnodeMsg->successed) { - SSWriteMsg oper = { - .type = SDB_OPER_GLOBAL, - .table = tsVgroupSdb, - .pObj = pVgroup, - .rowSize = sizeof(SVgObj), - .pMsg = mnodeMsg, - .writeCb = mnodeCreateVgroupCb + SSWriteMsg wmsg = { + .type = SDB_OPER_GLOBAL, + .pTable = tsVgroupSdb, + .pObj = pVgroup, + .rowSize = sizeof(SVgObj), + .pMsg = mnodeMsg, + .fpWrite = mnodeCreateVgroupCb }; - int32_t code = sdbInsertRowImp(&oper); + int32_t code = sdbInsertRowImp(&wmsg); if (code != TSDB_CODE_SUCCESS && code != TSDB_CODE_MND_ACTION_IN_PROGRESS) { mnodeMsg->pVgroup = NULL; mnodeDestroyVgroup(pVgroup); dnodeSendRpcMWriteRsp(mnodeMsg, code); } } else { - SSWriteMsg oper = { - .type = SDB_OPER_GLOBAL, - .table = tsVgroupSdb, - .pObj = pVgroup + SSWriteMsg wmsg = { + .type = SDB_OPER_GLOBAL, + .pTable = tsVgroupSdb, + .pObj = pVgroup }; - sdbDeleteRow(&oper); + sdbDeleteRow(&wmsg); dnodeSendRpcMWriteRsp(mnodeMsg, mnodeMsg->code); } } @@ -1031,12 +1031,12 @@ static void mnodeProcessDropVnodeRsp(SRpcMsg *rpcMsg) { if (mnodeMsg->received != mnodeMsg->expected) return; - SSWriteMsg oper = { - .type = SDB_OPER_GLOBAL, - .table = tsVgroupSdb, - .pObj = pVgroup + SSWriteMsg wmsg = { + .type = SDB_OPER_GLOBAL, + .pTable = tsVgroupSdb, + .pObj = pVgroup }; - int32_t code = sdbDeleteRow(&oper); + int32_t code = sdbDeleteRow(&wmsg); if (code != 0) { code = TSDB_CODE_MND_SDB_ERROR; } @@ -1084,12 +1084,12 @@ void mnodeDropAllDnodeVgroups(SDnodeObj *pDropDnode) { if (pVgroup->vnodeGid[0].dnodeId == pDropDnode->dnodeId) { mnodeDropAllChildTablesInVgroups(pVgroup); - SSWriteMsg oper = { - .type = SDB_OPER_LOCAL, - .table = tsVgroupSdb, - .pObj = pVgroup, + SSWriteMsg wmsg = { + .type = SDB_OPER_LOCAL, + .pTable = tsVgroupSdb, + .pObj = pVgroup, }; - sdbDeleteRow(&oper); + sdbDeleteRow(&wmsg); numOfVgroups++; } mnodeDecVgroupRef(pVgroup); @@ -1135,12 +1135,12 @@ void mnodeDropAllDbVgroups(SDbObj *pDropDb) { if (pVgroup == NULL) break; if (pVgroup->pDb == pDropDb) { - SSWriteMsg oper = { - .type = SDB_OPER_LOCAL, - .table = tsVgroupSdb, - .pObj = pVgroup, + SSWriteMsg wmsg = { + .type = SDB_OPER_LOCAL, + .pTable = tsVgroupSdb, + .pObj = pVgroup, }; - sdbDeleteRow(&oper); + sdbDeleteRow(&wmsg); numOfVgroups++; } diff --git a/tests/script/sh/deploy.sh b/tests/script/sh/deploy.sh index e26778e86b..591d7749ea 100755 --- a/tests/script/sh/deploy.sh +++ b/tests/script/sh/deploy.sh @@ -113,22 +113,22 @@ echo "logDir $LOG_DIR" >> $TAOS_CFG echo "debugFlag 0" >> $TAOS_CFG echo "mDebugFlag 143" >> $TAOS_CFG echo "sdbDebugFlag 143" >> $TAOS_CFG -echo "dDebugFlag 143" >> $TAOS_CFG -echo "vDebugFlag 143" >> $TAOS_CFG -echo "tsdbDebugFlag 143" >> $TAOS_CFG -echo "cDebugFlag 143" >> $TAOS_CFG -echo "jnidebugFlag 143" >> $TAOS_CFG -echo "odbcdebugFlag 143" >> $TAOS_CFG -echo "httpDebugFlag 143" >> $TAOS_CFG -echo "monitorDebugFlag 143" >> $TAOS_CFG -echo "mqttDebugFlag 143" >> $TAOS_CFG -echo "qdebugFlag 143" >> $TAOS_CFG -echo "rpcDebugFlag 143" >> $TAOS_CFG +echo "dDebugFlag 131" >> $TAOS_CFG +echo "vDebugFlag 131" >> $TAOS_CFG +echo "tsdbDebugFlag 131" >> $TAOS_CFG +echo "cDebugFlag 131" >> $TAOS_CFG +echo "jnidebugFlag 131" >> $TAOS_CFG +echo "odbcdebugFlag 131" >> $TAOS_CFG +echo "httpDebugFlag 131" >> $TAOS_CFG +echo "monitorDebugFlag 131" >> $TAOS_CFG +echo "mqttDebugFlag 131" >> $TAOS_CFG +echo "qdebugFlag 131" >> $TAOS_CFG +echo "rpcDebugFlag 131" >> $TAOS_CFG echo "tmrDebugFlag 131" >> $TAOS_CFG -echo "udebugFlag 143" >> $TAOS_CFG +echo "udebugFlag 131" >> $TAOS_CFG echo "sdebugFlag 143" >> $TAOS_CFG echo "wdebugFlag 143" >> $TAOS_CFG -echo "cqdebugFlag 143" >> $TAOS_CFG +echo "cqdebugFlag 131" >> $TAOS_CFG echo "monitor 0" >> $TAOS_CFG echo "monitorInterval 1" >> $TAOS_CFG echo "http 0" >> $TAOS_CFG @@ -140,7 +140,7 @@ echo "clog 2" >> $TAOS_CFG #echo "cache 1" >> $TAOS_CFG echo "days 10" >> $TAOS_CFG echo "statusInterval 1" >> $TAOS_CFG -echo "maxVgroupsPerDb 4" >> $TAOS_CFG +echo "maxVgroupsPerDb 10" >> $TAOS_CFG echo "minTablesPerVnode 4" >> $TAOS_CFG echo "maxTablesPerVnode 1000" >> $TAOS_CFG echo "tableIncStepPerVnode 10000" >> $TAOS_CFG From 98ec34b40dcf563ab5c3797dd232562332d29f4d Mon Sep 17 00:00:00 2001 From: Shengliang Guan Date: Wed, 18 Nov 2020 16:06:06 +0800 Subject: [PATCH 05/13] TD-2046 --- src/mnode/inc/mnodeSdb.h | 4 +- src/mnode/src/mnodeAcct.c | 18 +-- src/mnode/src/mnodeCluster.c | 10 +- src/mnode/src/mnodeDb.c | 24 ++-- src/mnode/src/mnodeDnode.c | 22 ++-- src/mnode/src/mnodeMnode.c | 26 ++-- src/mnode/src/mnodeSdb.c | 228 +++++++++++++++++------------------ src/mnode/src/mnodeTable.c | 80 ++++++------ src/mnode/src/mnodeUser.c | 22 ++-- src/mnode/src/mnodeVgroup.c | 38 +++--- 10 files changed, 234 insertions(+), 238 deletions(-) diff --git a/src/mnode/inc/mnodeSdb.h b/src/mnode/inc/mnodeSdb.h index 0b0933c08a..7169e14f03 100644 --- a/src/mnode/inc/mnodeSdb.h +++ b/src/mnode/inc/mnodeSdb.h @@ -57,7 +57,7 @@ typedef struct SSWriteMsg { void * rowData; int32_t (*fpReq)(SMnodeMsg *pMsg); int32_t (*fpWrite)(SMnodeMsg *pMsg, int32_t code); - void * pObj; + void * pRow; SMnodeMsg *pMsg; struct SSdbTable *pTable; } SSWriteMsg; @@ -75,7 +75,7 @@ typedef struct { int32_t (*fpEncode)(SSWriteMsg *pWrite); int32_t (*fpDecode)(SSWriteMsg *pWrite); int32_t (*fpDestroy)(SSWriteMsg *pWrite); - int32_t (*fpDestored)(); + int32_t (*fpRestored)(); } SSdbTableDesc; int32_t sdbInit(); diff --git a/src/mnode/src/mnodeAcct.c b/src/mnode/src/mnodeAcct.c index 697ff1d5a1..b12c200507 100644 --- a/src/mnode/src/mnodeAcct.c +++ b/src/mnode/src/mnodeAcct.c @@ -32,14 +32,14 @@ static int32_t tsAcctUpdateSize; static int32_t mnodeCreateRootAcct(); static int32_t mnodeAcctActionDestroy(SSWriteMsg *pWMsg) { - SAcctObj *pAcct = pWMsg->pObj; + SAcctObj *pAcct = pWMsg->pRow; pthread_mutex_destroy(&pAcct->mutex); - tfree(pWMsg->pObj); + tfree(pWMsg->pRow); return TSDB_CODE_SUCCESS; } static int32_t mnodeAcctActionInsert(SSWriteMsg *pWMsg) { - SAcctObj *pAcct = pWMsg->pObj; + SAcctObj *pAcct = pWMsg->pRow; memset(&pAcct->acctInfo, 0, sizeof(SAcctInfo)); pAcct->acctInfo.accessState = TSDB_VN_ALL_ACCCESS; pthread_mutex_init(&pAcct->mutex, NULL); @@ -47,14 +47,14 @@ static int32_t mnodeAcctActionInsert(SSWriteMsg *pWMsg) { } static int32_t mnodeAcctActionDelete(SSWriteMsg *pWMsg) { - SAcctObj *pAcct = pWMsg->pObj; + SAcctObj *pAcct = pWMsg->pRow; mnodeDropAllUsers(pAcct); mnodeDropAllDbs(pAcct); return TSDB_CODE_SUCCESS; } static int32_t mnodeAcctActionUpdate(SSWriteMsg *pWMsg) { - SAcctObj *pAcct = pWMsg->pObj; + SAcctObj *pAcct = pWMsg->pRow; SAcctObj *pSaved = mnodeGetAcct(pAcct->user); if (pAcct != pSaved) { memcpy(pSaved, pAcct, tsAcctUpdateSize); @@ -65,7 +65,7 @@ static int32_t mnodeAcctActionUpdate(SSWriteMsg *pWMsg) { } static int32_t mnodeAcctActionEncode(SSWriteMsg *pWMsg) { - SAcctObj *pAcct = pWMsg->pObj; + SAcctObj *pAcct = pWMsg->pRow; memcpy(pWMsg->rowData, pAcct, tsAcctUpdateSize); pWMsg->rowSize = tsAcctUpdateSize; return TSDB_CODE_SUCCESS; @@ -76,7 +76,7 @@ static int32_t mnodeAcctActionDecode(SSWriteMsg *pWMsg) { if (pAcct == NULL) return TSDB_CODE_MND_OUT_OF_MEMORY; memcpy(pAcct, pWMsg->rowData, tsAcctUpdateSize); - pWMsg->pObj = pAcct; + pWMsg->pRow = pAcct; return TSDB_CODE_SUCCESS; } @@ -112,7 +112,7 @@ int32_t mnodeInitAccts() { .fpEncode = mnodeAcctActionEncode, .fpDecode = mnodeAcctActionDecode, .fpDestroy = mnodeAcctActionDestroy, - .fpDestored = mnodeAcctActionRestored + .fpRestored = mnodeAcctActionRestored }; tsAcctSdb = sdbOpenTable(&tableDesc); @@ -229,7 +229,7 @@ static int32_t mnodeCreateRootAcct() { SSWriteMsg wmsg = { .type = SDB_OPER_GLOBAL, .pTable = tsAcctSdb, - .pObj = pAcct, + .pRow = pAcct, }; return sdbInsertRow(&wmsg); diff --git a/src/mnode/src/mnodeCluster.c b/src/mnode/src/mnodeCluster.c index c94c833270..f9182704b0 100644 --- a/src/mnode/src/mnodeCluster.c +++ b/src/mnode/src/mnodeCluster.c @@ -33,7 +33,7 @@ static int32_t mnodeGetClusterMeta(STableMetaMsg *pMeta, SShowObj *pShow, void * static int32_t mnodeRetrieveClusters(SShowObj *pShow, char *data, int32_t rows, void *pConn); static int32_t mnodeClusterActionDestroy(SSWriteMsg *pWMsg) { - tfree(pWMsg->pObj); + tfree(pWMsg->pRow); return TSDB_CODE_SUCCESS; } @@ -50,7 +50,7 @@ static int32_t mnodeClusterActionUpdate(SSWriteMsg *pWMsg) { } static int32_t mnodeClusterActionEncode(SSWriteMsg *pWMsg) { - SClusterObj *pCluster = pWMsg->pObj; + SClusterObj *pCluster = pWMsg->pRow; memcpy(pWMsg->rowData, pCluster, tsClusterUpdateSize); pWMsg->rowSize = tsClusterUpdateSize; return TSDB_CODE_SUCCESS; @@ -61,7 +61,7 @@ static int32_t mnodeClusterActionDecode(SSWriteMsg *pWMsg) { if (pCluster == NULL) return TSDB_CODE_MND_OUT_OF_MEMORY; memcpy(pCluster, pWMsg->rowData, tsClusterUpdateSize); - pWMsg->pObj = pCluster; + pWMsg->pRow = pCluster; return TSDB_CODE_SUCCESS; } @@ -97,7 +97,7 @@ int32_t mnodeInitCluster() { .fpEncode = mnodeClusterActionEncode, .fpDecode = mnodeClusterActionDecode, .fpDestroy = mnodeClusterActionDestroy, - .fpDestored = mnodeClusterActionRestored + .fpRestored = mnodeClusterActionRestored }; tsClusterSdb = sdbOpenTable(&tableDesc); @@ -148,7 +148,7 @@ static int32_t mnodeCreateCluster() { SSWriteMsg wmsg = { .type = SDB_OPER_GLOBAL, .pTable = tsClusterSdb, - .pObj = pCluster, + .pRow = pCluster, }; return sdbInsertRow(&wmsg); diff --git a/src/mnode/src/mnodeDb.c b/src/mnode/src/mnodeDb.c index 3c2bfbb834..9696df155a 100644 --- a/src/mnode/src/mnodeDb.c +++ b/src/mnode/src/mnodeDb.c @@ -57,7 +57,7 @@ static void mnodeDestroyDb(SDbObj *pDb) { } static int32_t mnodeDbActionDestroy(SSWriteMsg *pWMsg) { - mnodeDestroyDb(pWMsg->pObj); + mnodeDestroyDb(pWMsg->pRow); return TSDB_CODE_SUCCESS; } @@ -66,7 +66,7 @@ int64_t mnodeGetDbNum() { } static int32_t mnodeDbActionInsert(SSWriteMsg *pWMsg) { - SDbObj *pDb = pWMsg->pObj; + SDbObj *pDb = pWMsg->pRow; SAcctObj *pAcct = mnodeGetAcct(pDb->acct); pthread_mutex_init(&pDb->mutex, NULL); @@ -92,7 +92,7 @@ static int32_t mnodeDbActionInsert(SSWriteMsg *pWMsg) { } static int32_t mnodeDbActionDelete(SSWriteMsg *pWMsg) { - SDbObj *pDb = pWMsg->pObj; + SDbObj *pDb = pWMsg->pRow; SAcctObj *pAcct = mnodeGetAcct(pDb->acct); mnodeDropAllChildTables(pDb); @@ -108,7 +108,7 @@ static int32_t mnodeDbActionDelete(SSWriteMsg *pWMsg) { } static int32_t mnodeDbActionUpdate(SSWriteMsg *pWMsg) { - SDbObj *pNew = pWMsg->pObj; + SDbObj *pNew = pWMsg->pRow; SDbObj *pDb = mnodeGetDb(pNew->name); if (pDb != NULL && pNew != pDb) { memcpy(pDb, pNew, pWMsg->rowSize); @@ -121,7 +121,7 @@ static int32_t mnodeDbActionUpdate(SSWriteMsg *pWMsg) { } static int32_t mnodeDbActionEncode(SSWriteMsg *pWMsg) { - SDbObj *pDb = pWMsg->pObj; + SDbObj *pDb = pWMsg->pRow; memcpy(pWMsg->rowData, pDb, tsDbUpdateSize); pWMsg->rowSize = tsDbUpdateSize; return TSDB_CODE_SUCCESS; @@ -132,7 +132,7 @@ static int32_t mnodeDbActionDecode(SSWriteMsg *pWMsg) { if (pDb == NULL) return TSDB_CODE_MND_OUT_OF_MEMORY; memcpy(pDb, pWMsg->rowData, tsDbUpdateSize); - pWMsg->pObj = pDb; + pWMsg->pRow = pDb; return TSDB_CODE_SUCCESS; } @@ -157,7 +157,7 @@ int32_t mnodeInitDbs() { .fpEncode = mnodeDbActionEncode, .fpDecode = mnodeDbActionDecode, .fpDestroy = mnodeDbActionDestroy, - .fpDestored = mnodeDbActionRestored + .fpRestored = mnodeDbActionRestored }; tsDbSdb = sdbOpenTable(&tableDesc); @@ -415,7 +415,7 @@ static int32_t mnodeCreateDb(SAcctObj *pAcct, SCreateDbMsg *pCreate, SMnodeMsg * SSWriteMsg wmsg = { .type = SDB_OPER_GLOBAL, .pTable = tsDbSdb, - .pObj = pDb, + .pRow = pDb, .rowSize = sizeof(SDbObj), .pMsg = pMsg, .fpWrite = mnodeCreateDbCb @@ -810,7 +810,7 @@ static int32_t mnodeSetDbDropping(SDbObj *pDb) { SSWriteMsg wmsg = { .type = SDB_OPER_GLOBAL, .pTable = tsDbSdb, - .pObj = pDb + .pRow = pDb }; int32_t code = sdbUpdateRow(&wmsg); @@ -1022,7 +1022,7 @@ static int32_t mnodeAlterDb(SDbObj *pDb, SAlterDbMsg *pAlter, void *pMsg) { SSWriteMsg wmsg = { .type = SDB_OPER_GLOBAL, .pTable = tsDbSdb, - .pObj = pDb, + .pRow = pDb, .pMsg = pMsg, .fpWrite = mnodeAlterDbCb }; @@ -1074,7 +1074,7 @@ static int32_t mnodeDropDb(SMnodeMsg *pMsg) { SSWriteMsg wmsg = { .type = SDB_OPER_GLOBAL, .pTable = tsDbSdb, - .pObj = pDb, + .pRow = pDb, .pMsg = pMsg, .fpWrite = mnodeDropDbCb }; @@ -1137,7 +1137,7 @@ void mnodeDropAllDbs(SAcctObj *pAcct) { SSWriteMsg wmsg = { .type = SDB_OPER_LOCAL, .pTable = tsDbSdb, - .pObj = pDb + .pRow = pDb }; sdbDeleteRow(&wmsg); diff --git a/src/mnode/src/mnodeDnode.c b/src/mnode/src/mnodeDnode.c index 617499967e..99cc44ba7d 100644 --- a/src/mnode/src/mnodeDnode.c +++ b/src/mnode/src/mnodeDnode.c @@ -88,12 +88,12 @@ static char* offlineReason[] = { }; static int32_t mnodeDnodeActionDestroy(SSWriteMsg *pWMsg) { - tfree(pWMsg->pObj); + tfree(pWMsg->pRow); return TSDB_CODE_SUCCESS; } static int32_t mnodeDnodeActionInsert(SSWriteMsg *pWMsg) { - SDnodeObj *pDnode = pWMsg->pObj; + SDnodeObj *pDnode = pWMsg->pRow; if (pDnode->status != TAOS_DN_STATUS_DROPPING) { pDnode->status = TAOS_DN_STATUS_OFFLINE; pDnode->lastAccess = tsAccessSquence; @@ -108,7 +108,7 @@ static int32_t mnodeDnodeActionInsert(SSWriteMsg *pWMsg) { } static int32_t mnodeDnodeActionDelete(SSWriteMsg *pWMsg) { - SDnodeObj *pDnode = pWMsg->pObj; + SDnodeObj *pDnode = pWMsg->pRow; #ifndef _SYNC mnodeDropAllDnodeVgroups(pDnode); @@ -122,7 +122,7 @@ static int32_t mnodeDnodeActionDelete(SSWriteMsg *pWMsg) { } static int32_t mnodeDnodeActionUpdate(SSWriteMsg *pWMsg) { - SDnodeObj *pNew = pWMsg->pObj; + SDnodeObj *pNew = pWMsg->pRow; SDnodeObj *pDnode = mnodeGetDnode(pNew->dnodeId); if (pDnode != NULL && pNew != pDnode) { memcpy(pDnode, pNew, pWMsg->rowSize); @@ -135,7 +135,7 @@ static int32_t mnodeDnodeActionUpdate(SSWriteMsg *pWMsg) { } static int32_t mnodeDnodeActionEncode(SSWriteMsg *pWMsg) { - SDnodeObj *pDnode = pWMsg->pObj; + SDnodeObj *pDnode = pWMsg->pRow; memcpy(pWMsg->rowData, pDnode, tsDnodeUpdateSize); pWMsg->rowSize = tsDnodeUpdateSize; return TSDB_CODE_SUCCESS; @@ -146,7 +146,7 @@ static int32_t mnodeDnodeActionDecode(SSWriteMsg *pWMsg) { if (pDnode == NULL) return TSDB_CODE_MND_OUT_OF_MEMORY; memcpy(pDnode, pWMsg->rowData, tsDnodeUpdateSize); - pWMsg->pObj = pDnode; + pWMsg->pRow = pDnode; return TSDB_CODE_SUCCESS; } @@ -184,7 +184,7 @@ int32_t mnodeInitDnodes() { .fpEncode = mnodeDnodeActionEncode, .fpDecode = mnodeDnodeActionDecode, .fpDestroy = mnodeDnodeActionDestroy, - .fpDestored = mnodeDnodeActionRestored + .fpRestored = mnodeDnodeActionRestored }; tsDnodeSdb = sdbOpenTable(&tableDesc); @@ -299,7 +299,7 @@ void mnodeUpdateDnode(SDnodeObj *pDnode) { SSWriteMsg wmsg = { .type = SDB_OPER_GLOBAL, .pTable = tsDnodeSdb, - .pObj = pDnode + .pRow = pDnode }; int32_t code = sdbUpdateRow(&wmsg); @@ -647,7 +647,7 @@ static int32_t mnodeCreateDnode(char *ep, SMnodeMsg *pMsg) { SSWriteMsg wmsg = { .type = SDB_OPER_GLOBAL, .pTable = tsDnodeSdb, - .pObj = pDnode, + .pRow = pDnode, .rowSize = sizeof(SDnodeObj), .pMsg = pMsg }; @@ -668,7 +668,7 @@ int32_t mnodeDropDnode(SDnodeObj *pDnode, void *pMsg) { SSWriteMsg wmsg = { .type = SDB_OPER_GLOBAL, .pTable = tsDnodeSdb, - .pObj = pDnode, + .pRow = pDnode, .pMsg = pMsg }; @@ -1141,7 +1141,7 @@ static int32_t mnodeRetrieveVnodes(SShowObj *pShow, char *data, int32_t rows, vo cols++; pWrite = data + pShow->offset[cols] * rows + pShow->bytes[cols] * numOfRows; - strcpy(pWrite, mnodeGetMnodeRoleStr(pVgid->role)); + strcpy(pWrite, syncRole[pVgid->role]); cols++; } } diff --git a/src/mnode/src/mnodeMnode.c b/src/mnode/src/mnodeMnode.c index 37915319e5..33925960be 100644 --- a/src/mnode/src/mnodeMnode.c +++ b/src/mnode/src/mnodeMnode.c @@ -59,12 +59,12 @@ static int32_t mnodeRetrieveMnodes(SShowObj *pShow, char *data, int32_t rows, vo #endif static int32_t mnodeMnodeActionDestroy(SSWriteMsg *pWMsg) { - tfree(pWMsg->pObj); + tfree(pWMsg->pRow); return TSDB_CODE_SUCCESS; } static int32_t mnodeMnodeActionInsert(SSWriteMsg *pWMsg) { - SMnodeObj *pMnode = pWMsg->pObj; + SMnodeObj *pMnode = pWMsg->pRow; SDnodeObj *pDnode = mnodeGetDnode(pMnode->mnodeId); if (pDnode == NULL) return TSDB_CODE_MND_DNODE_NOT_EXIST; @@ -77,7 +77,7 @@ static int32_t mnodeMnodeActionInsert(SSWriteMsg *pWMsg) { } static int32_t mnodeMnodeActionDelete(SSWriteMsg *pWMsg) { - SMnodeObj *pMnode = pWMsg->pObj; + SMnodeObj *pMnode = pWMsg->pRow; SDnodeObj *pDnode = mnodeGetDnode(pMnode->mnodeId); if (pDnode == NULL) return TSDB_CODE_MND_DNODE_NOT_EXIST; @@ -89,7 +89,7 @@ static int32_t mnodeMnodeActionDelete(SSWriteMsg *pWMsg) { } static int32_t mnodeMnodeActionUpdate(SSWriteMsg *pWMsg) { - SMnodeObj *pMnode = pWMsg->pObj; + SMnodeObj *pMnode = pWMsg->pRow; SMnodeObj *pSaved = mnodeGetMnode(pMnode->mnodeId); if (pMnode != pSaved) { memcpy(pSaved, pMnode, pWMsg->rowSize); @@ -100,7 +100,7 @@ static int32_t mnodeMnodeActionUpdate(SSWriteMsg *pWMsg) { } static int32_t mnodeMnodeActionEncode(SSWriteMsg *pWMsg) { - SMnodeObj *pMnode = pWMsg->pObj; + SMnodeObj *pMnode = pWMsg->pRow; memcpy(pWMsg->rowData, pMnode, tsMnodeUpdateSize); pWMsg->rowSize = tsMnodeUpdateSize; return TSDB_CODE_SUCCESS; @@ -111,7 +111,7 @@ static int32_t mnodeMnodeActionDecode(SSWriteMsg *pWMsg) { if (pMnode == NULL) return TSDB_CODE_MND_OUT_OF_MEMORY; memcpy(pMnode, pWMsg->rowData, tsMnodeUpdateSize); - pWMsg->pObj = pMnode; + pWMsg->pRow = pMnode; return TSDB_CODE_SUCCESS; } @@ -150,7 +150,7 @@ int32_t mnodeInitMnodes() { .fpEncode = mnodeMnodeActionEncode, .fpDecode = mnodeMnodeActionDecode, .fpDestroy = mnodeMnodeActionDestroy, - .fpDestored = mnodeMnodeActionRestored + .fpRestored = mnodeMnodeActionRestored }; tsMnodeSdb = sdbOpenTable(&tableDesc); @@ -192,10 +192,6 @@ void *mnodeGetNextMnode(void *pIter, SMnodeObj **pMnode) { return sdbFetchRow(tsMnodeSdb, pIter, (void **)pMnode); } -char *mnodeGetMnodeRoleStr(int32_t role) { - return syncRole[role]; -} - void mnodeUpdateMnodeEpSet() { mInfo("update mnodes epSet, numOfEps:%d ", mnodeGetMnodesNum()); @@ -332,7 +328,7 @@ void mnodeCreateMnode(int32_t dnodeId, char *dnodeEp, bool needConfirm) { SSWriteMsg wmsg = { .type = SDB_OPER_GLOBAL, .pTable = tsMnodeSdb, - .pObj = pMnode, + .pRow = pMnode, .fpWrite = mnodeCreateMnodeCb }; @@ -356,7 +352,7 @@ void mnodeCreateMnode(int32_t dnodeId, char *dnodeEp, bool needConfirm) { void mnodeDropMnodeLocal(int32_t dnodeId) { SMnodeObj *pMnode = mnodeGetMnode(dnodeId); if (pMnode != NULL) { - SSWriteMsg wmsg = {.type = SDB_OPER_LOCAL, .pTable = tsMnodeSdb, .pObj = pMnode}; + SSWriteMsg wmsg = {.type = SDB_OPER_LOCAL, .pTable = tsMnodeSdb, .pRow = pMnode}; sdbDeleteRow(&wmsg); mnodeDecMnodeRef(pMnode); } @@ -374,7 +370,7 @@ int32_t mnodeDropMnode(int32_t dnodeId) { SSWriteMsg wmsg = { .type = SDB_OPER_GLOBAL, .pTable = tsMnodeSdb, - .pObj = pMnode + .pRow = pMnode }; int32_t code = sdbDeleteRow(&wmsg); @@ -469,7 +465,7 @@ static int32_t mnodeRetrieveMnodes(SShowObj *pShow, char *data, int32_t rows, vo cols++; pWrite = data + pShow->offset[cols] * rows + pShow->bytes[cols] * numOfRows; - char* roles = mnodeGetMnodeRoleStr(pMnode->role); + char* roles = syncRole[pMnode->role]; STR_WITH_MAXSIZE_TO_VARSTR(pWrite, roles, pShow->bytes[cols]); cols++; diff --git a/src/mnode/src/mnodeSdb.c b/src/mnode/src/mnodeSdb.c index 034ff870c5..8056833cdb 100644 --- a/src/mnode/src/mnodeSdb.c +++ b/src/mnode/src/mnodeSdb.c @@ -37,15 +37,15 @@ #define SDB_SYNC_HACK 16 typedef enum { - SDB_ACTION_INSERT, - SDB_ACTION_DELETE, - SDB_ACTION_UPDATE + SDB_ACTION_INSERT = 0, + SDB_ACTION_DELETE = 1, + SDB_ACTION_UPDATE = 2 } ESdbAction; typedef enum { - SDB_STATUS_OFFLINE, - SDB_STATUS_SERVING, - SDB_STATUS_CLOSING + SDB_STATUS_OFFLINE = 0, + SDB_STATUS_SERVING = 1, + SDB_STATUS_CLOSING = 2 } ESdbStatus; typedef struct SSdbTable { @@ -64,7 +64,7 @@ typedef struct SSdbTable { int32_t (*fpDecode)(SSWriteMsg *pWrite); int32_t (*fpEncode)(SSWriteMsg *pWrite); int32_t (*fpDestroy)(SSWriteMsg *pWrite); - int32_t (*fpDestored)(); + int32_t (*fpRestored)(); pthread_mutex_t mutex; } SSdbTable; @@ -78,7 +78,7 @@ typedef struct { int32_t numOfTables; SSdbTable *tableList[SDB_TABLE_MAX]; pthread_mutex_t mutex; -} SSdbObject; +} SSdbMgmt; typedef struct { pthread_t thread; @@ -92,7 +92,7 @@ typedef struct { extern void * tsMnodeTmr; static void * tsSdbTmr; -static SSdbObject tsSdbObj = {0}; +static SSdbMgmt tsSdbMgmt = {0}; static taos_qset tsSdbWQset; static taos_qall tsSdbWQall; static taos_queue tsSdbWQueue; @@ -121,15 +121,15 @@ int64_t sdbGetNumOfRows(void *pTable) { } uint64_t sdbGetVersion() { - return tsSdbObj.version; + return tsSdbMgmt.version; } bool sdbIsMaster() { - return tsSdbObj.role == TAOS_SYNC_ROLE_MASTER; + return tsSdbMgmt.role == TAOS_SYNC_ROLE_MASTER; } bool sdbIsServing() { - return tsSdbObj.status == SDB_STATUS_SERVING; + return tsSdbMgmt.status == SDB_STATUS_SERVING; } static void *sdbGetObjKey(SSdbTable *pTable, void *key) { @@ -172,21 +172,21 @@ static char *sdbGetObjStr(SSdbTable *pTable, void *key) { } static void *sdbGetTableFromId(int32_t tableId) { - return tsSdbObj.tableList[tableId]; + return tsSdbMgmt.tableList[tableId]; } static int32_t sdbInitWal() { SWalCfg walCfg = {.vgId = 1, .walLevel = TAOS_WAL_FSYNC, .keep = TAOS_WAL_KEEP, .fsyncPeriod = 0}; char temp[TSDB_FILENAME_LEN] = {0}; sprintf(temp, "%s/wal", tsMnodeDir); - tsSdbObj.wal = walOpen(temp, &walCfg); - if (tsSdbObj.wal == NULL) { + tsSdbMgmt.wal = walOpen(temp, &walCfg); + if (tsSdbMgmt.wal == NULL) { sdbError("vgId:1, failed to open wal in %s", tsMnodeDir); return -1; } sdbInfo("vgId:1, open wal for restore"); - int code = walRestore(tsSdbObj.wal, NULL, sdbWrite); + int code = walRestore(tsSdbMgmt.wal, NULL, sdbWrite); if (code != TSDB_CODE_SUCCESS) { sdbError("vgId:1, failed to open wal for restore since %s", tstrerror(code)); return -1; @@ -200,8 +200,8 @@ static void sdbRestoreTables() { for (int32_t tableId = 0; tableId < SDB_TABLE_MAX; ++tableId) { SSdbTable *pTable = sdbGetTableFromId(tableId); if (pTable == NULL) continue; - if (pTable->fpDestored) { - (*pTable->fpDestored)(); + if (pTable->fpRestored) { + (*pTable->fpRestored)(); } totalRows += pTable->numOfRows; @@ -209,22 +209,22 @@ static void sdbRestoreTables() { sdbDebug("vgId:1, sdb:%s is restored, rows:%" PRId64, pTable->tableName, pTable->numOfRows); } - sdbInfo("vgId:1, sdb is restored, mver:%" PRIu64 " rows:%d tables:%d", tsSdbObj.version, totalRows, numOfTables); + sdbInfo("vgId:1, sdb is restored, mver:%" PRIu64 " rows:%d tables:%d", tsSdbMgmt.version, totalRows, numOfTables); } void sdbUpdateMnodeRoles() { - if (tsSdbObj.sync <= 0) return; + if (tsSdbMgmt.sync <= 0) return; SNodesRole roles = {0}; - syncGetNodesRole(tsSdbObj.sync, &roles); + syncGetNodesRole(tsSdbMgmt.sync, &roles); - sdbInfo("vgId:1, update mnodes roles, replica:%d", tsSdbObj.cfg.replica); - for (int32_t i = 0; i < tsSdbObj.cfg.replica; ++i) { + sdbInfo("vgId:1, update mnodes role, replica:%d", tsSdbMgmt.cfg.replica); + for (int32_t i = 0; i < tsSdbMgmt.cfg.replica; ++i) { SMnodeObj *pMnode = mnodeGetMnode(roles.nodeId[i]); if (pMnode != NULL) { pMnode->role = roles.role[i]; - sdbInfo("vgId:1, mnode:%d, role:%s", pMnode->mnodeId, mnodeGetMnodeRoleStr(pMnode->role)); - if (pMnode->mnodeId == dnodeGetDnodeId()) tsSdbObj.role = pMnode->role; + sdbInfo("vgId:1, mnode:%d, role:%s", pMnode->mnodeId, syncRole[pMnode->role]); + if (pMnode->mnodeId == dnodeGetDnodeId()) tsSdbMgmt.role = pMnode->role; mnodeDecMnodeRef(pMnode); } } @@ -239,16 +239,16 @@ static uint32_t sdbGetFileInfo(void *ahandle, char *name, uint32_t *index, uint3 } static int32_t sdbGetWalInfo(void *ahandle, char *fileName, int64_t *fileId) { - return walGetWalFile(tsSdbObj.wal, fileName, fileId); + return walGetWalFile(tsSdbMgmt.wal, fileName, fileId); } static void sdbNotifyRole(void *ahandle, int8_t role) { - sdbInfo("vgId:1, mnode role changed from %s to %s", mnodeGetMnodeRoleStr(tsSdbObj.role), mnodeGetMnodeRoleStr(role)); + sdbInfo("vgId:1, mnode role changed from %s to %s", syncRole[tsSdbMgmt.role], syncRole[role]); - if (role == TAOS_SYNC_ROLE_MASTER && tsSdbObj.role != TAOS_SYNC_ROLE_MASTER) { + if (role == TAOS_SYNC_ROLE_MASTER && tsSdbMgmt.role != TAOS_SYNC_ROLE_MASTER) { balanceReset(); } - tsSdbObj.role = role; + tsSdbMgmt.role = role; sdbUpdateMnodeRoles(); } @@ -276,7 +276,7 @@ static void sdbConfirmForward(void *ahandle, void *param, int32_t code) { if (pWrite->retCode != TSDB_CODE_SUCCESS) { SWalHead *pHead = (void *)pWrite + sizeof(SSWriteMsg) + SDB_SYNC_HACK; int32_t action = pHead->msgType % 10; - sdbError("vgId:1, key:%p:%s hver:%" PRIu64 " action:%d, failed to foward since %s", pWrite->pObj, + sdbError("vgId:1, key:%p:%s hver:%" PRIu64 " action:%d, failed to foward since %s", pWrite->pRow, sdbGetKeyStr(pWrite->pTable, pHead->cont), pHead->version, action, tstrerror(pWrite->retCode)); if (action == SDB_ACTION_INSERT) { // It's better to create a table in two stages, create it first and then set it success @@ -284,7 +284,7 @@ static void sdbConfirmForward(void *ahandle, void *param, int32_t code) { SSWriteMsg wmsg = { .type = SDB_OPER_GLOBAL, .pTable = pWrite->pTable, - .pObj = pWrite->pObj + .pRow = pWrite->pRow }; sdbDeleteRow(&wmsg); } @@ -297,7 +297,7 @@ static void sdbConfirmForward(void *ahandle, void *param, int32_t code) { // if ahandle, means this func is called by sdb write if (ahandle == NULL) { - sdbDecRef(pWrite->pTable, pWrite->pObj); + sdbDecRef(pWrite->pTable, pWrite->pRow); } taosFreeQitem(pWrite); @@ -369,7 +369,7 @@ void sdbUpdateSync(void *pMnodes) { return; } - if (memcmp(&syncCfg, &tsSdbObj.cfg, sizeof(SSyncCfg)) == 0) { + if (memcmp(&syncCfg, &tsSdbMgmt.cfg, sizeof(SSyncCfg)) == 0) { sdbDebug("vgId:1, update sync config, info not changed"); return; } @@ -391,18 +391,18 @@ void sdbUpdateSync(void *pMnodes) { syncInfo.writeToCache = sdbWriteToQueue; syncInfo.confirmForward = sdbConfirmForward; syncInfo.notifyRole = sdbNotifyRole; - tsSdbObj.cfg = syncCfg; + tsSdbMgmt.cfg = syncCfg; - if (tsSdbObj.sync) { - syncReconfig(tsSdbObj.sync, &syncCfg); + if (tsSdbMgmt.sync) { + syncReconfig(tsSdbMgmt.sync, &syncCfg); } else { - tsSdbObj.sync = syncStart(&syncInfo); + tsSdbMgmt.sync = syncStart(&syncInfo); } sdbUpdateMnodeRoles(); } int32_t sdbInit() { - pthread_mutex_init(&tsSdbObj.mutex, NULL); + pthread_mutex_init(&tsSdbMgmt.mutex, NULL); if (sdbInitWorker() != 0) { return -1; @@ -415,55 +415,55 @@ int32_t sdbInit() { sdbRestoreTables(); if (mnodeGetMnodesNum() == 1) { - tsSdbObj.role = TAOS_SYNC_ROLE_MASTER; + tsSdbMgmt.role = TAOS_SYNC_ROLE_MASTER; } - tsSdbObj.status = SDB_STATUS_SERVING; + tsSdbMgmt.status = SDB_STATUS_SERVING; return TSDB_CODE_SUCCESS; } void sdbCleanUp() { - if (tsSdbObj.status != SDB_STATUS_SERVING) return; + if (tsSdbMgmt.status != SDB_STATUS_SERVING) return; - tsSdbObj.status = SDB_STATUS_CLOSING; + tsSdbMgmt.status = SDB_STATUS_CLOSING; sdbCleanupWorker(); - sdbDebug("vgId:1, sdb will be closed, mver:%" PRIu64, tsSdbObj.version); + sdbDebug("vgId:1, sdb will be closed, mver:%" PRIu64, tsSdbMgmt.version); - if (tsSdbObj.sync) { - syncStop(tsSdbObj.sync); - tsSdbObj.sync = -1; + if (tsSdbMgmt.sync) { + syncStop(tsSdbMgmt.sync); + tsSdbMgmt.sync = -1; } - if (tsSdbObj.wal) { - walClose(tsSdbObj.wal); - tsSdbObj.wal = NULL; + if (tsSdbMgmt.wal) { + walClose(tsSdbMgmt.wal); + tsSdbMgmt.wal = NULL; } - pthread_mutex_destroy(&tsSdbObj.mutex); + pthread_mutex_destroy(&tsSdbMgmt.mutex); } -void sdbIncRef(void *tparam, void *pObj) { - if (pObj == NULL || tparam == NULL) return; +void sdbIncRef(void *tparam, void *pRow) { + if (pRow == NULL || tparam == NULL) return; SSdbTable *pTable = tparam; - int32_t * pRefCount = (int32_t *)(pObj + pTable->refCountPos); + int32_t * pRefCount = (int32_t *)(pRow + pTable->refCountPos); int32_t refCount = atomic_add_fetch_32(pRefCount, 1); - sdbTrace("vgId:1, sdb:%s, inc ref to key:%p:%s:%d", pTable->tableName, pObj, sdbGetObjStr(pTable, pObj), refCount); + sdbTrace("vgId:1, sdb:%s, inc ref to key:%p:%s:%d", pTable->tableName, pRow, sdbGetObjStr(pTable, pRow), refCount); } -void sdbDecRef(void *tparam, void *pObj) { - if (pObj == NULL || tparam == NULL) return; +void sdbDecRef(void *tparam, void *pRow) { + if (pRow == NULL || tparam == NULL) return; SSdbTable *pTable = tparam; - int32_t * pRefCount = (int32_t *)(pObj + pTable->refCountPos); + int32_t * pRefCount = (int32_t *)(pRow + pTable->refCountPos); int32_t refCount = atomic_sub_fetch_32(pRefCount, 1); - sdbTrace("vgId:1, sdb:%s, dec ref to key:%p:%s:%d", pTable->tableName, pObj, sdbGetObjStr(pTable, pObj), refCount); + sdbTrace("vgId:1, sdb:%s, dec ref to key:%p:%s:%d", pTable->tableName, pRow, sdbGetObjStr(pTable, pRow), refCount); - int32_t *updateEnd = pObj + pTable->refCountPos - 4; + int32_t *updateEnd = pRow + pTable->refCountPos - 4; if (refCount <= 0 && *updateEnd) { - sdbTrace("vgId:1, sdb:%s, key:%p:%s:%d destroyed", pTable->tableName, pObj, sdbGetObjStr(pTable, pObj), refCount); - SSWriteMsg wmsg = {.pObj = pObj}; + sdbTrace("vgId:1, sdb:%s, key:%p:%s:%d destroyed", pTable->tableName, pRow, sdbGetObjStr(pTable, pRow), refCount); + SSWriteMsg wmsg = {.pRow = pRow}; (*pTable->fpDestroy)(&wmsg); } } @@ -502,7 +502,7 @@ static void *sdbGetRowFromObj(SSdbTable *pTable, void *key) { } static int32_t sdbInsertHash(SSdbTable *pTable, SSWriteMsg *pWrite) { - void * key = sdbGetObjKey(pTable, pWrite->pObj); + void * key = sdbGetObjKey(pTable, pWrite->pRow); int32_t keySize = sizeof(int32_t); if (pTable->keyType == SDB_KEY_STRING || pTable->keyType == SDB_KEY_VAR_STRING) { @@ -510,25 +510,25 @@ static int32_t sdbInsertHash(SSdbTable *pTable, SSWriteMsg *pWrite) { } pthread_mutex_lock(&pTable->mutex); - taosHashPut(pTable->iHandle, key, keySize, &pWrite->pObj, sizeof(int64_t)); + taosHashPut(pTable->iHandle, key, keySize, &pWrite->pRow, sizeof(int64_t)); pthread_mutex_unlock(&pTable->mutex); - sdbIncRef(pTable, pWrite->pObj); + sdbIncRef(pTable, pWrite->pRow); atomic_add_fetch_32(&pTable->numOfRows, 1); if (pTable->keyType == SDB_KEY_AUTO) { - pTable->autoIndex = MAX(pTable->autoIndex, *((uint32_t *)pWrite->pObj)); + pTable->autoIndex = MAX(pTable->autoIndex, *((uint32_t *)pWrite->pRow)); } else { atomic_add_fetch_32(&pTable->autoIndex, 1); } sdbDebug("vgId:1, sdb:%s, insert key:%s to hash, rowSize:%d rows:%" PRId64 ", msg:%p", pTable->tableName, - sdbGetObjStr(pTable, pWrite->pObj), pWrite->rowSize, pTable->numOfRows, pWrite->pMsg); + sdbGetObjStr(pTable, pWrite->pRow), pWrite->rowSize, pTable->numOfRows, pWrite->pMsg); int32_t code = (*pTable->fpInsert)(pWrite); if (code != TSDB_CODE_SUCCESS) { sdbError("vgId:1, sdb:%s, failed to insert key:%s to hash, remove it", pTable->tableName, - sdbGetObjStr(pTable, pWrite->pObj)); + sdbGetObjStr(pTable, pWrite->pRow)); sdbDeleteHash(pTable, pWrite); } @@ -536,17 +536,17 @@ static int32_t sdbInsertHash(SSdbTable *pTable, SSWriteMsg *pWrite) { } static int32_t sdbDeleteHash(SSdbTable *pTable, SSWriteMsg *pWrite) { - int32_t *updateEnd = pWrite->pObj + pTable->refCountPos - 4; + int32_t *updateEnd = pWrite->pRow + pTable->refCountPos - 4; bool set = atomic_val_compare_exchange_32(updateEnd, 0, 1) == 0; if (!set) { sdbError("vgId:1, sdb:%s, failed to delete key:%s from hash, for it already removed", pTable->tableName, - sdbGetObjStr(pTable, pWrite->pObj)); + sdbGetObjStr(pTable, pWrite->pRow)); return TSDB_CODE_MND_SDB_OBJ_NOT_THERE; } (*pTable->fpDelete)(pWrite); - void * key = sdbGetObjKey(pTable, pWrite->pObj); + void * key = sdbGetObjKey(pTable, pWrite->pRow); int32_t keySize = sizeof(int32_t); if (pTable->keyType == SDB_KEY_STRING || pTable->keyType == SDB_KEY_VAR_STRING) { keySize = strlen((char *)key); @@ -559,16 +559,16 @@ static int32_t sdbDeleteHash(SSdbTable *pTable, SSWriteMsg *pWrite) { atomic_sub_fetch_32(&pTable->numOfRows, 1); sdbDebug("vgId:1, sdb:%s, delete key:%s from hash, numOfRows:%" PRId64 ", msg:%p", pTable->tableName, - sdbGetObjStr(pTable, pWrite->pObj), pTable->numOfRows, pWrite->pMsg); + sdbGetObjStr(pTable, pWrite->pRow), pTable->numOfRows, pWrite->pMsg); - sdbDecRef(pTable, pWrite->pObj); + sdbDecRef(pTable, pWrite->pRow); return TSDB_CODE_SUCCESS; } static int32_t sdbUpdateHash(SSdbTable *pTable, SSWriteMsg *pWrite) { sdbDebug("vgId:1, sdb:%s, update key:%s in hash, numOfRows:%" PRId64 ", msg:%p", pTable->tableName, - sdbGetObjStr(pTable, pWrite->pObj), pTable->numOfRows, pWrite->pMsg); + sdbGetObjStr(pTable, pWrite->pRow), pTable->numOfRows, pWrite->pMsg); (*pTable->fpUpdate)(pWrite); return TSDB_CODE_SUCCESS; @@ -583,42 +583,42 @@ static int sdbWrite(void *wparam, void *hparam, int32_t qtype, void *unused) { SSdbTable *pTable = sdbGetTableFromId(tableId); assert(pTable != NULL); - pthread_mutex_lock(&tsSdbObj.mutex); + pthread_mutex_lock(&tsSdbMgmt.mutex); if (pHead->version == 0) { // assign version - tsSdbObj.version++; - pHead->version = tsSdbObj.version; + tsSdbMgmt.version++; + pHead->version = tsSdbMgmt.version; } else { // for data from WAL or forward, version may be smaller - if (pHead->version <= tsSdbObj.version) { - pthread_mutex_unlock(&tsSdbObj.mutex); + if (pHead->version <= tsSdbMgmt.version) { + pthread_mutex_unlock(&tsSdbMgmt.mutex); sdbDebug("vgId:1, sdb:%s, failed to restore %s key:%s from source(%d), hver:%" PRIu64 " too large, mver:%" PRIu64, - pTable->tableName, sdbGetActionStr(action), sdbGetKeyStr(pTable, pHead->cont), qtype, pHead->version, tsSdbObj.version); + pTable->tableName, sdbGetActionStr(action), sdbGetKeyStr(pTable, pHead->cont), qtype, pHead->version, tsSdbMgmt.version); return TSDB_CODE_SUCCESS; - } else if (pHead->version != tsSdbObj.version + 1) { - pthread_mutex_unlock(&tsSdbObj.mutex); + } else if (pHead->version != tsSdbMgmt.version + 1) { + pthread_mutex_unlock(&tsSdbMgmt.mutex); sdbError("vgId:1, sdb:%s, failed to restore %s key:%s from source(%d), hver:%" PRIu64 " too large, mver:%" PRIu64, - pTable->tableName, sdbGetActionStr(action), sdbGetKeyStr(pTable, pHead->cont), qtype, pHead->version, tsSdbObj.version); + pTable->tableName, sdbGetActionStr(action), sdbGetKeyStr(pTable, pHead->cont), qtype, pHead->version, tsSdbMgmt.version); return TSDB_CODE_SYN_INVALID_VERSION; } else { - tsSdbObj.version = pHead->version; + tsSdbMgmt.version = pHead->version; } } - int32_t code = walWrite(tsSdbObj.wal, pHead); + int32_t code = walWrite(tsSdbMgmt.wal, pHead); if (code < 0) { - pthread_mutex_unlock(&tsSdbObj.mutex); + pthread_mutex_unlock(&tsSdbMgmt.mutex); return code; } - pthread_mutex_unlock(&tsSdbObj.mutex); + pthread_mutex_unlock(&tsSdbMgmt.mutex); // from app, wmsg is created if (pWrite != NULL) { // forward to peers pWrite->processedCount = 0; - int32_t syncCode = syncForwardToPeer(tsSdbObj.sync, pHead, pWrite, TAOS_QTYPE_RPC); + int32_t syncCode = syncForwardToPeer(tsSdbMgmt.sync, pHead, pWrite, TAOS_QTYPE_RPC); if (syncCode <= 0) pWrite->processedCount = 1; if (syncCode < 0) { @@ -638,7 +638,7 @@ static int sdbWrite(void *wparam, void *hparam, int32_t qtype, void *unused) { sdbGetActionStr(action), sdbGetKeyStr(pTable, pHead->cont), pHead->version); // even it is WAL/FWD, it shall be called to update version in sync - syncForwardToPeer(tsSdbObj.sync, pHead, pWrite, TAOS_QTYPE_RPC); + syncForwardToPeer(tsSdbMgmt.sync, pHead, pWrite, TAOS_QTYPE_RPC); // from wal or forward msg, wmsg not created, should add into hash if (action == SDB_ACTION_INSERT) { @@ -652,7 +652,7 @@ static int sdbWrite(void *wparam, void *hparam, int32_t qtype, void *unused) { sdbGetKeyStr(pTable, pHead->cont)); return TSDB_CODE_SUCCESS; } - SSWriteMsg wmsg = {.pTable = pTable, .pObj = pRow}; + SSWriteMsg wmsg = {.pTable = pTable, .pRow = pRow}; return sdbDeleteHash(pTable, &wmsg); } else if (action == SDB_ACTION_UPDATE) { void *pRow = sdbGetRowMeta(pTable, pHead->cont); @@ -673,19 +673,19 @@ int32_t sdbInsertRow(SSWriteMsg *pWrite) { SSdbTable *pTable = pWrite->pTable; if (pTable == NULL) return TSDB_CODE_MND_SDB_INVALID_TABLE_TYPE; - if (sdbGetRowFromObj(pTable, pWrite->pObj)) { + if (sdbGetRowFromObj(pTable, pWrite->pRow)) { sdbError("vgId:1, sdb:%s, failed to insert key:%s, already exist", pTable->tableName, - sdbGetObjStr(pTable, pWrite->pObj)); - sdbDecRef(pTable, pWrite->pObj); + sdbGetObjStr(pTable, pWrite->pRow)); + sdbDecRef(pTable, pWrite->pRow); return TSDB_CODE_MND_SDB_OBJ_ALREADY_THERE; } if (pTable->keyType == SDB_KEY_AUTO) { - *((uint32_t *)pWrite->pObj) = atomic_add_fetch_32(&pTable->autoIndex, 1); + *((uint32_t *)pWrite->pRow) = atomic_add_fetch_32(&pTable->autoIndex, 1); // let vgId increase from 2 if (pTable->autoIndex == 1 && strcmp(pTable->tableName, "vgroups") == 0) { - *((uint32_t *)pWrite->pObj) = atomic_add_fetch_32(&pTable->autoIndex, 1); + *((uint32_t *)pWrite->pRow) = atomic_add_fetch_32(&pTable->autoIndex, 1); } } @@ -727,10 +727,10 @@ int32_t sdbInsertRowImp(SSWriteMsg *pWrite) { if (pNewOper->pMsg != NULL) { sdbDebug("vgId:1, ahandle:%p msg:%p, sdb:%s key:%p:%s, insert action is add to sdb queue", pNewOper->pMsg->rpcMsg.ahandle, - pNewOper->pMsg, pTable->tableName, pWrite->pObj, sdbGetObjStr(pTable, pWrite->pObj)); + pNewOper->pMsg, pTable->tableName, pWrite->pRow, sdbGetObjStr(pTable, pWrite->pRow)); } - sdbIncRef(pNewOper->pTable, pNewOper->pObj); + sdbIncRef(pNewOper->pTable, pNewOper->pRow); taosWriteQitem(tsSdbWQueue, TAOS_QTYPE_RPC, pNewOper); return TSDB_CODE_MND_ACTION_IN_PROGRESS; @@ -748,24 +748,24 @@ int32_t sdbDeleteRow(SSWriteMsg *pWrite) { SSdbTable *pTable = pWrite->pTable; if (pTable == NULL) return TSDB_CODE_MND_SDB_INVALID_TABLE_TYPE; - void *pRow = sdbGetRowMetaFromObj(pTable, pWrite->pObj); + void *pRow = sdbGetRowMetaFromObj(pTable, pWrite->pRow); if (pRow == NULL) { sdbDebug("vgId:1, sdb:%s, record is not there, delete failed", pTable->tableName); return TSDB_CODE_MND_SDB_OBJ_NOT_THERE; } - sdbIncRef(pTable, pWrite->pObj); + sdbIncRef(pTable, pWrite->pRow); int32_t code = sdbDeleteHash(pTable, pWrite); if (code != TSDB_CODE_SUCCESS) { sdbError("vgId:1, sdb:%s, failed to delete from hash", pTable->tableName); - sdbDecRef(pTable, pWrite->pObj); + sdbDecRef(pTable, pWrite->pRow); return code; } // just delete data from memory if (pWrite->type != SDB_OPER_GLOBAL) { - sdbDecRef(pTable, pWrite->pObj); + sdbDecRef(pTable, pWrite->pRow); return TSDB_CODE_SUCCESS; } @@ -795,7 +795,7 @@ int32_t sdbDeleteRowImp(SSWriteMsg *pWrite) { if (pNewOper->pMsg != NULL) { sdbDebug("vgId:1, ahandle:%p msg:%p, sdb:%s key:%p:%s, delete action is add to sdb queue", pNewOper->pMsg->rpcMsg.ahandle, - pNewOper->pMsg, pTable->tableName, pWrite->pObj, sdbGetObjStr(pTable, pWrite->pObj)); + pNewOper->pMsg, pTable->tableName, pWrite->pRow, sdbGetObjStr(pTable, pWrite->pRow)); } taosWriteQitem(tsSdbWQueue, TAOS_QTYPE_RPC, pNewOper); @@ -807,7 +807,7 @@ int32_t sdbUpdateRow(SSWriteMsg *pWrite) { SSdbTable *pTable = pWrite->pTable; if (pTable == NULL) return TSDB_CODE_MND_SDB_INVALID_TABLE_TYPE; - void *pRow = sdbGetRowMetaFromObj(pTable, pWrite->pObj); + void *pRow = sdbGetRowMetaFromObj(pTable, pWrite->pRow); if (pRow == NULL) { sdbDebug("vgId:1, sdb:%s, record is not there, update failed", pTable->tableName); return TSDB_CODE_MND_SDB_OBJ_NOT_THERE; @@ -850,10 +850,10 @@ int32_t sdbUpdateRowImp(SSWriteMsg *pWrite) { if (pNewOper->pMsg != NULL) { sdbDebug("vgId:1, ahandle:%p msg:%p, sdb:%s key:%p:%s, update action is add to sdb queue", pNewOper->pMsg->rpcMsg.ahandle, - pNewOper->pMsg, pTable->tableName, pWrite->pObj, sdbGetObjStr(pTable, pWrite->pObj)); + pNewOper->pMsg, pTable->tableName, pWrite->pRow, sdbGetObjStr(pTable, pWrite->pRow)); } - sdbIncRef(pNewOper->pTable, pNewOper->pObj); + sdbIncRef(pNewOper->pTable, pNewOper->pRow); taosWriteQitem(tsSdbWQueue, TAOS_QTYPE_RPC, pNewOper); return TSDB_CODE_MND_ACTION_IN_PROGRESS; @@ -910,7 +910,7 @@ void *sdbOpenTable(SSdbTableDesc *pDesc) { pTable->fpEncode = pDesc->fpEncode; pTable->fpDecode = pDesc->fpDecode; pTable->fpDestroy = pDesc->fpDestroy; - pTable->fpDestored = pDesc->fpDestored; + pTable->fpRestored = pDesc->fpRestored; _hash_fn_t hashFp = taosGetDefaultHashFunction(TSDB_DATA_TYPE_INT); if (pTable->keyType == SDB_KEY_STRING || pTable->keyType == SDB_KEY_VAR_STRING) { @@ -918,8 +918,8 @@ void *sdbOpenTable(SSdbTableDesc *pDesc) { } pTable->iHandle = taosHashInit(pTable->hashSessions, hashFp, true, true); - tsSdbObj.numOfTables++; - tsSdbObj.tableList[pTable->tableId] = pTable; + tsSdbMgmt.numOfTables++; + tsSdbMgmt.tableList[pTable->tableId] = pTable; return pTable; } @@ -927,8 +927,8 @@ void sdbCloseTable(void *handle) { SSdbTable *pTable = (SSdbTable *)handle; if (pTable == NULL) return; - tsSdbObj.numOfTables--; - tsSdbObj.tableList[pTable->tableId] = NULL; + tsSdbMgmt.numOfTables--; + tsSdbMgmt.tableList[pTable->tableId] = NULL; SHashMutableIterator *pIter = taosHashCreateIter(pTable->iHandle); while (taosHashIterNext(pIter)) { @@ -936,7 +936,7 @@ void sdbCloseTable(void *handle) { if (ppRow == NULL) continue; SSWriteMsg wmsg = { - .pObj = *ppRow, + .pRow = *ppRow, .pTable = pTable, }; @@ -947,7 +947,7 @@ void sdbCloseTable(void *handle) { taosHashCleanup(pTable->iHandle); pthread_mutex_destroy(&pTable->mutex); - sdbDebug("vgId:1, sdb:%s, is closed, numOfTables:%d", pTable->tableName, tsSdbObj.numOfTables); + sdbDebug("vgId:1, sdb:%s, is closed, numOfTables:%d", pTable->tableName, tsSdbMgmt.numOfTables); free(pTable); } @@ -1072,7 +1072,7 @@ static void *sdbWorkerFp(void *pWorker) { pHead = (void *)pWrite + sizeof(SSWriteMsg) + SDB_SYNC_HACK; if (pWrite->pMsg != NULL) { sdbDebug("vgId:1, ahandle:%p msg:%p, sdb:%s key:%p:%s hver:%" PRIu64 ", will be processed in sdb queue", - pWrite->pMsg->rpcMsg.ahandle, pWrite->pMsg, pWrite->pTable->tableName, pWrite->pObj, + pWrite->pMsg->rpcMsg.ahandle, pWrite->pMsg, pWrite->pTable->tableName, pWrite->pRow, sdbGetKeyStr(pWrite->pTable, pHead->cont), pHead->version); } } else { @@ -1089,7 +1089,7 @@ static void *sdbWorkerFp(void *pWorker) { } } - walFsync(tsSdbObj.wal, true); + walFsync(tsSdbMgmt.wal, true); // browse all items, and process them one by one taosResetQitems(tsSdbWQall); @@ -1101,7 +1101,7 @@ static void *sdbWorkerFp(void *pWorker) { sdbConfirmForward(NULL, pWrite, pWrite->retCode); } else if (qtype == TAOS_QTYPE_FWD) { pHead = (SWalHead *)item; - syncConfirmForward(tsSdbObj.sync, pHead->version, pHead->len); + syncConfirmForward(tsSdbMgmt.sync, pHead->version, pHead->len); taosFreeQitem(item); } else { taosFreeQitem(item); diff --git a/src/mnode/src/mnodeTable.c b/src/mnode/src/mnodeTable.c index 1ba476cf2a..fc441bf524 100644 --- a/src/mnode/src/mnodeTable.c +++ b/src/mnode/src/mnodeTable.c @@ -100,12 +100,12 @@ static void mnodeDestroyChildTable(SCTableObj *pTable) { } static int32_t mnodeChildTableActionDestroy(SSWriteMsg *pWMsg) { - mnodeDestroyChildTable(pWMsg->pObj); + mnodeDestroyChildTable(pWMsg->pRow); return TSDB_CODE_SUCCESS; } static int32_t mnodeChildTableActionInsert(SSWriteMsg *pWMsg) { - SCTableObj *pTable = pWMsg->pObj; + SCTableObj *pTable = pWMsg->pRow; SVgObj *pVgroup = mnodeGetVgroup(pTable->vgId); if (pVgroup == NULL) { @@ -154,7 +154,7 @@ static int32_t mnodeChildTableActionInsert(SSWriteMsg *pWMsg) { } static int32_t mnodeChildTableActionDelete(SSWriteMsg *pWMsg) { - SCTableObj *pTable = pWMsg->pObj; + SCTableObj *pTable = pWMsg->pRow; if (pTable->vgId == 0) { return TSDB_CODE_MND_VGROUP_NOT_EXIST; } @@ -190,7 +190,7 @@ static int32_t mnodeChildTableActionDelete(SSWriteMsg *pWMsg) { } static int32_t mnodeChildTableActionUpdate(SSWriteMsg *pWMsg) { - SCTableObj *pNew = pWMsg->pObj; + SCTableObj *pNew = pWMsg->pRow; SCTableObj *pTable = mnodeGetChildTable(pNew->info.tableId); if (pTable != pNew) { void *oldTableId = pTable->info.tableId; @@ -217,7 +217,7 @@ static int32_t mnodeChildTableActionUpdate(SSWriteMsg *pWMsg) { } static int32_t mnodeChildTableActionEncode(SSWriteMsg *pWMsg) { - SCTableObj *pTable = pWMsg->pObj; + SCTableObj *pTable = pWMsg->pRow; assert(pTable != NULL && pWMsg->rowData != NULL); int32_t len = strlen(pTable->info.tableId); @@ -282,7 +282,7 @@ static int32_t mnodeChildTableActionDecode(SSWriteMsg *pWMsg) { } } - pWMsg->pObj = pTable; + pWMsg->pRow = pTable; return TSDB_CODE_SUCCESS; } @@ -297,7 +297,7 @@ static int32_t mnodeChildTableActionRestored() { SDbObj *pDb = mnodeGetDbByTableId(pTable->info.tableId); if (pDb == NULL || pDb->status != TSDB_DB_STATUS_READY) { mError("ctable:%s, failed to get db or db in dropping, discard it", pTable->info.tableId); - SSWriteMsg desc = {.type = SDB_OPER_LOCAL, .pObj = pTable, .pTable = tsChildTableSdb}; + SSWriteMsg desc = {.type = SDB_OPER_LOCAL, .pRow = pTable, .pTable = tsChildTableSdb}; sdbDeleteRow(&desc); mnodeDecTableRef(pTable); mnodeDecDbRef(pDb); @@ -309,7 +309,7 @@ static int32_t mnodeChildTableActionRestored() { if (pVgroup == NULL) { mError("ctable:%s, failed to get vgId:%d tid:%d, discard it", pTable->info.tableId, pTable->vgId, pTable->tid); pTable->vgId = 0; - SSWriteMsg desc = {.type = SDB_OPER_LOCAL, .pObj = pTable, .pTable = tsChildTableSdb}; + SSWriteMsg desc = {.type = SDB_OPER_LOCAL, .pRow = pTable, .pTable = tsChildTableSdb}; sdbDeleteRow(&desc); mnodeDecTableRef(pTable); continue; @@ -320,7 +320,7 @@ static int32_t mnodeChildTableActionRestored() { mError("ctable:%s, db:%s not match with vgId:%d db:%s sid:%d, discard it", pTable->info.tableId, pDb->name, pTable->vgId, pVgroup->dbName, pTable->tid); pTable->vgId = 0; - SSWriteMsg desc = {.type = SDB_OPER_LOCAL, .pObj = pTable, .pTable = tsChildTableSdb}; + SSWriteMsg desc = {.type = SDB_OPER_LOCAL, .pRow = pTable, .pTable = tsChildTableSdb}; sdbDeleteRow(&desc); mnodeDecTableRef(pTable); continue; @@ -331,7 +331,7 @@ static int32_t mnodeChildTableActionRestored() { if (pSuperTable == NULL) { mError("ctable:%s, stable:%" PRIu64 " not exist", pTable->info.tableId, pTable->suid); pTable->vgId = 0; - SSWriteMsg desc = {.type = SDB_OPER_LOCAL, .pObj = pTable, .pTable = tsChildTableSdb}; + SSWriteMsg desc = {.type = SDB_OPER_LOCAL, .pRow = pTable, .pTable = tsChildTableSdb}; sdbDeleteRow(&desc); mnodeDecTableRef(pTable); continue; @@ -364,7 +364,7 @@ static int32_t mnodeInitChildTables() { .fpEncode = mnodeChildTableActionEncode, .fpDecode = mnodeChildTableActionDecode, .fpDestroy = mnodeChildTableActionDestroy, - .fpDestored = mnodeChildTableActionRestored + .fpRestored = mnodeChildTableActionRestored }; tsChildTableSdb = sdbOpenTable(&tableDesc); @@ -431,12 +431,12 @@ static void mnodeDestroySuperTable(SSTableObj *pStable) { } static int32_t mnodeSuperTableActionDestroy(SSWriteMsg *pWMsg) { - mnodeDestroySuperTable(pWMsg->pObj); + mnodeDestroySuperTable(pWMsg->pRow); return TSDB_CODE_SUCCESS; } static int32_t mnodeSuperTableActionInsert(SSWriteMsg *pWMsg) { - SSTableObj *pStable = pWMsg->pObj; + SSTableObj *pStable = pWMsg->pRow; SDbObj *pDb = mnodeGetDbByTableId(pStable->info.tableId); if (pDb != NULL && pDb->status == TSDB_DB_STATUS_READY) { mnodeAddSuperTableIntoDb(pDb); @@ -447,7 +447,7 @@ static int32_t mnodeSuperTableActionInsert(SSWriteMsg *pWMsg) { } static int32_t mnodeSuperTableActionDelete(SSWriteMsg *pWMsg) { - SSTableObj *pStable = pWMsg->pObj; + SSTableObj *pStable = pWMsg->pRow; SDbObj *pDb = mnodeGetDbByTableId(pStable->info.tableId); if (pDb != NULL) { mnodeRemoveSuperTableFromDb(pDb); @@ -459,7 +459,7 @@ static int32_t mnodeSuperTableActionDelete(SSWriteMsg *pWMsg) { } static int32_t mnodeSuperTableActionUpdate(SSWriteMsg *pWMsg) { - SSTableObj *pNew = pWMsg->pObj; + SSTableObj *pNew = pWMsg->pRow; SSTableObj *pTable = mnodeGetSuperTable(pNew->info.tableId); if (pTable != NULL && pTable != pNew) { void *oldTableId = pTable->info.tableId; @@ -484,8 +484,8 @@ static int32_t mnodeSuperTableActionUpdate(SSWriteMsg *pWMsg) { } static int32_t mnodeSuperTableActionEncode(SSWriteMsg *pWMsg) { - SSTableObj *pStable = pWMsg->pObj; - assert(pWMsg->pObj != NULL && pWMsg->rowData != NULL); + SSTableObj *pStable = pWMsg->pRow; + assert(pWMsg->pRow != NULL && pWMsg->rowData != NULL); int32_t len = strlen(pStable->info.tableId); if (len >= TSDB_TABLE_FNAME_LEN) len = TSDB_CODE_MND_INVALID_TABLE_ID; @@ -531,7 +531,7 @@ static int32_t mnodeSuperTableActionDecode(SSWriteMsg *pWMsg) { memcpy(pStable->schema, pWMsg->rowData + len, schemaSize); - pWMsg->pObj = pStable; + pWMsg->pRow = pStable; return TSDB_CODE_SUCCESS; } @@ -557,7 +557,7 @@ static int32_t mnodeInitSuperTables() { .fpEncode = mnodeSuperTableActionEncode, .fpDecode = mnodeSuperTableActionDecode, .fpDestroy = mnodeSuperTableActionDestroy, - .fpDestored = mnodeSuperTableActionRestored + .fpRestored = mnodeSuperTableActionRestored }; tsSuperTableSdb = sdbOpenTable(&tableDesc); @@ -828,7 +828,7 @@ static int32_t mnodeCreateSuperTableCb(SMnodeMsg *pMsg, int32_t code) { } else { mError("app:%p:%p, stable:%s, failed to create in sdb, reason:%s", pMsg->rpcMsg.ahandle, pMsg, pTable->info.tableId, tstrerror(code)); - SSWriteMsg desc = {.type = SDB_OPER_GLOBAL, .pObj = pTable, .pTable = tsSuperTableSdb}; + SSWriteMsg desc = {.type = SDB_OPER_GLOBAL, .pRow = pTable, .pTable = tsSuperTableSdb}; sdbDeleteRow(&desc); } @@ -881,7 +881,7 @@ static int32_t mnodeProcessCreateSuperTableMsg(SMnodeMsg *pMsg) { SSWriteMsg wmsg = { .type = SDB_OPER_GLOBAL, .pTable = tsSuperTableSdb, - .pObj = pStable, + .pRow = pStable, .rowSize = sizeof(SSTableObj) + schemaSize, .pMsg = pMsg, .fpWrite = mnodeCreateSuperTableCb @@ -940,7 +940,7 @@ static int32_t mnodeProcessDropSuperTableMsg(SMnodeMsg *pMsg) { SSWriteMsg wmsg = { .type = SDB_OPER_GLOBAL, .pTable = tsSuperTableSdb, - .pObj = pStable, + .pRow = pStable, .pMsg = pMsg, .fpWrite = mnodeDropSuperTableCb }; @@ -1013,7 +1013,7 @@ static int32_t mnodeAddSuperTableTag(SMnodeMsg *pMsg, SSchema schema[], int32_t SSWriteMsg wmsg = { .type = SDB_OPER_GLOBAL, .pTable = tsSuperTableSdb, - .pObj = pStable, + .pRow = pStable, .pMsg = pMsg, .fpWrite = mnodeAddSuperTableTagCb }; @@ -1047,7 +1047,7 @@ static int32_t mnodeDropSuperTableTag(SMnodeMsg *pMsg, char *tagName) { SSWriteMsg wmsg = { .type = SDB_OPER_GLOBAL, .pTable = tsSuperTableSdb, - .pObj = pStable, + .pRow = pStable, .pMsg = pMsg, .fpWrite = mnodeDropSuperTableTagCb }; @@ -1091,7 +1091,7 @@ static int32_t mnodeModifySuperTableTagName(SMnodeMsg *pMsg, char *oldTagName, c SSWriteMsg wmsg = { .type = SDB_OPER_GLOBAL, .pTable = tsSuperTableSdb, - .pObj = pStable, + .pRow = pStable, .pMsg = pMsg, .fpWrite = mnodeModifySuperTableTagNameCb }; @@ -1165,7 +1165,7 @@ static int32_t mnodeAddSuperTableColumn(SMnodeMsg *pMsg, SSchema schema[], int32 SSWriteMsg wmsg = { .type = SDB_OPER_GLOBAL, .pTable = tsSuperTableSdb, - .pObj = pStable, + .pRow = pStable, .pMsg = pMsg, .fpWrite = mnodeAddSuperTableColumnCb }; @@ -1210,7 +1210,7 @@ static int32_t mnodeDropSuperTableColumn(SMnodeMsg *pMsg, char *colName) { SSWriteMsg wmsg = { .type = SDB_OPER_GLOBAL, .pTable = tsSuperTableSdb, - .pObj = pStable, + .pRow = pStable, .pMsg = pMsg, .fpWrite = mnodeDropSuperTableColumnCb }; @@ -1254,7 +1254,7 @@ static int32_t mnodeChangeSuperTableColumn(SMnodeMsg *pMsg, char *oldName, char SSWriteMsg wmsg = { .type = SDB_OPER_GLOBAL, .pTable = tsSuperTableSdb, - .pObj = pStable, + .pRow = pStable, .pMsg = pMsg, .fpWrite = mnodeChangeSuperTableColumnCb }; @@ -1420,7 +1420,7 @@ void mnodeDropAllSuperTables(SDbObj *pDropDb) { SSWriteMsg wmsg = { .type = SDB_OPER_LOCAL, .pTable = tsSuperTableSdb, - .pObj = pTable, + .pRow = pTable, }; sdbDeleteRow(&wmsg); numOfTables ++; @@ -1694,7 +1694,7 @@ static int32_t mnodeDoCreateChildTableCb(SMnodeMsg *pMsg, int32_t code) { } else { mError("app:%p:%p, table:%s, failed to create table sid:%d, uid:%" PRIu64 ", reason:%s", pMsg->rpcMsg.ahandle, pMsg, pTable->info.tableId, pTable->tid, pTable->uid, tstrerror(code)); - SSWriteMsg desc = {.type = SDB_OPER_GLOBAL, .pObj = pTable, .pTable = tsChildTableSdb}; + SSWriteMsg desc = {.type = SDB_OPER_GLOBAL, .pRow = pTable, .pTable = tsChildTableSdb}; sdbDeleteRow(&desc); return code; } @@ -1782,7 +1782,7 @@ static int32_t mnodeDoCreateChildTable(SMnodeMsg *pMsg, int32_t tid) { SSWriteMsg desc = { .type = SDB_OPER_GLOBAL, - .pObj = pTable, + .pRow = pTable, .pTable = tsChildTableSdb, .pMsg = pMsg, .fpReq = mnodeDoCreateChildTableFp @@ -1904,7 +1904,7 @@ static int32_t mnodeProcessDropChildTableMsg(SMnodeMsg *pMsg) { SSWriteMsg wmsg = { .type = SDB_OPER_GLOBAL, .pTable = tsChildTableSdb, - .pObj = pTable, + .pRow = pTable, .pMsg = pMsg, .fpWrite = mnodeDropChildTableCb }; @@ -2008,7 +2008,7 @@ static int32_t mnodeAddNormalTableColumn(SMnodeMsg *pMsg, SSchema schema[], int3 SSWriteMsg wmsg = { .type = SDB_OPER_GLOBAL, .pTable = tsChildTableSdb, - .pObj = pTable, + .pRow = pTable, .pMsg = pMsg, .fpWrite = mnodeAlterNormalTableColumnCb }; @@ -2041,7 +2041,7 @@ static int32_t mnodeDropNormalTableColumn(SMnodeMsg *pMsg, char *colName) { SSWriteMsg wmsg = { .type = SDB_OPER_GLOBAL, .pTable = tsChildTableSdb, - .pObj = pTable, + .pRow = pTable, .pMsg = pMsg, .fpWrite = mnodeAlterNormalTableColumnCb }; @@ -2078,7 +2078,7 @@ static int32_t mnodeChangeNormalTableColumn(SMnodeMsg *pMsg, char *oldName, char SSWriteMsg wmsg = { .type = SDB_OPER_GLOBAL, .pTable = tsChildTableSdb, - .pObj = pTable, + .pRow = pTable, .pMsg = pMsg, .fpWrite = mnodeAlterNormalTableColumnCb }; @@ -2221,7 +2221,7 @@ void mnodeDropAllChildTablesInVgroups(SVgObj *pVgroup) { SSWriteMsg wmsg = { .type = SDB_OPER_LOCAL, .pTable = tsChildTableSdb, - .pObj = pTable, + .pRow = pTable, }; sdbDeleteRow(&wmsg); numOfTables++; @@ -2254,7 +2254,7 @@ void mnodeDropAllChildTables(SDbObj *pDropDb) { SSWriteMsg wmsg = { .type = SDB_OPER_LOCAL, .pTable = tsChildTableSdb, - .pObj = pTable, + .pRow = pTable, }; sdbDeleteRow(&wmsg); numOfTables++; @@ -2283,7 +2283,7 @@ static void mnodeDropAllChildTablesInStable(SSTableObj *pStable) { SSWriteMsg wmsg = { .type = SDB_OPER_LOCAL, .pTable = tsChildTableSdb, - .pObj = pTable, + .pRow = pTable, }; sdbDeleteRow(&wmsg); numOfTables++; @@ -2412,7 +2412,7 @@ static void mnodeProcessCreateChildTableRsp(SRpcMsg *rpcMsg) { if (rpcMsg->code == TSDB_CODE_SUCCESS || rpcMsg->code == TSDB_CODE_TDB_TABLE_ALREADY_EXIST) { SSWriteMsg desc = { .type = SDB_OPER_GLOBAL, - .pObj = pTable, + .pRow = pTable, .pTable = tsChildTableSdb, .pMsg = mnodeMsg, .fpWrite = mnodeDoCreateChildTableCb @@ -2440,7 +2440,7 @@ static void mnodeProcessCreateChildTableRsp(SRpcMsg *rpcMsg) { mnodeMsg->rpcMsg.ahandle, mnodeMsg, pTable->info.tableId, pTable->vgId, pTable->tid, pTable->uid, tstrerror(rpcMsg->code), mnodeMsg->rpcMsg.handle, mnodeMsg->incomingTs, sec, mnodeMsg->retry); - SSWriteMsg wmsg = {.type = SDB_OPER_GLOBAL, .pTable = tsChildTableSdb, .pObj = pTable}; + SSWriteMsg wmsg = {.type = SDB_OPER_GLOBAL, .pTable = tsChildTableSdb, .pRow = pTable}; sdbDeleteRow(&wmsg); if (rpcMsg->code == TSDB_CODE_APP_NOT_READY) { diff --git a/src/mnode/src/mnodeUser.c b/src/mnode/src/mnodeUser.c index 95d5befa5a..edb15fb778 100644 --- a/src/mnode/src/mnodeUser.c +++ b/src/mnode/src/mnodeUser.c @@ -43,12 +43,12 @@ static int32_t mnodeProcessDropUserMsg(SMnodeMsg *pMsg); static int32_t mnodeProcessAuthMsg(SMnodeMsg *pMsg); static int32_t mnodeUserActionDestroy(SSWriteMsg *pWMsg) { - tfree(pWMsg->pObj); + tfree(pWMsg->pRow); return TSDB_CODE_SUCCESS; } static int32_t mnodeUserActionInsert(SSWriteMsg *pWMsg) { - SUserObj *pUser = pWMsg->pObj; + SUserObj *pUser = pWMsg->pRow; SAcctObj *pAcct = mnodeGetAcct(pUser->acct); if (pAcct != NULL) { @@ -63,7 +63,7 @@ static int32_t mnodeUserActionInsert(SSWriteMsg *pWMsg) { } static int32_t mnodeUserActionDelete(SSWriteMsg *pWMsg) { - SUserObj *pUser = pWMsg->pObj; + SUserObj *pUser = pWMsg->pRow; SAcctObj *pAcct = mnodeGetAcct(pUser->acct); if (pAcct != NULL) { @@ -75,7 +75,7 @@ static int32_t mnodeUserActionDelete(SSWriteMsg *pWMsg) { } static int32_t mnodeUserActionUpdate(SSWriteMsg *pWMsg) { - SUserObj *pUser = pWMsg->pObj; + SUserObj *pUser = pWMsg->pRow; SUserObj *pSaved = mnodeGetUser(pUser->user); if (pUser != pSaved) { memcpy(pSaved, pUser, tsUserUpdateSize); @@ -86,7 +86,7 @@ static int32_t mnodeUserActionUpdate(SSWriteMsg *pWMsg) { } static int32_t mnodeUserActionEncode(SSWriteMsg *pWMsg) { - SUserObj *pUser = pWMsg->pObj; + SUserObj *pUser = pWMsg->pRow; memcpy(pWMsg->rowData, pUser, tsUserUpdateSize); pWMsg->rowSize = tsUserUpdateSize; return TSDB_CODE_SUCCESS; @@ -97,7 +97,7 @@ static int32_t mnodeUserActionDecode(SSWriteMsg *pWMsg) { if (pUser == NULL) return TSDB_CODE_MND_OUT_OF_MEMORY; memcpy(pUser, pWMsg->rowData, tsUserUpdateSize); - pWMsg->pObj = pUser; + pWMsg->pRow = pUser; return TSDB_CODE_SUCCESS; } @@ -163,7 +163,7 @@ int32_t mnodeInitUsers() { .fpEncode = mnodeUserActionEncode, .fpDecode = mnodeUserActionDecode, .fpDestroy = mnodeUserActionDestroy, - .fpDestored = mnodeUserActionRestored + .fpRestored = mnodeUserActionRestored }; tsUserSdb = sdbOpenTable(&tableDesc); @@ -208,7 +208,7 @@ static int32_t mnodeUpdateUser(SUserObj *pUser, void *pMsg) { SSWriteMsg wmsg = { .type = SDB_OPER_GLOBAL, .pTable = tsUserSdb, - .pObj = pUser, + .pRow = pUser, .pMsg = pMsg }; @@ -262,7 +262,7 @@ int32_t mnodeCreateUser(SAcctObj *pAcct, char *name, char *pass, void *pMsg) { SSWriteMsg wmsg = { .type = SDB_OPER_GLOBAL, .pTable = tsUserSdb, - .pObj = pUser, + .pRow = pUser, .rowSize = sizeof(SUserObj), .pMsg = pMsg }; @@ -282,7 +282,7 @@ static int32_t mnodeDropUser(SUserObj *pUser, void *pMsg) { SSWriteMsg wmsg = { .type = SDB_OPER_GLOBAL, .pTable = tsUserSdb, - .pObj = pUser, + .pRow = pUser, .pMsg = pMsg }; @@ -565,7 +565,7 @@ void mnodeDropAllUsers(SAcctObj *pAcct) { SSWriteMsg wmsg = { .type = SDB_OPER_LOCAL, .pTable = tsUserSdb, - .pObj = pUser, + .pRow = pUser, }; sdbDeleteRow(&wmsg); numOfUsers++; diff --git a/src/mnode/src/mnodeVgroup.c b/src/mnode/src/mnodeVgroup.c index 5a99dfbfa3..9da96a8acf 100644 --- a/src/mnode/src/mnodeVgroup.c +++ b/src/mnode/src/mnodeVgroup.c @@ -73,12 +73,12 @@ static void mnodeDestroyVgroup(SVgObj *pVgroup) { } static int32_t mnodeVgroupActionDestroy(SSWriteMsg *pWMsg) { - mnodeDestroyVgroup(pWMsg->pObj); + mnodeDestroyVgroup(pWMsg->pRow); return TSDB_CODE_SUCCESS; } static int32_t mnodeVgroupActionInsert(SSWriteMsg *pWMsg) { - SVgObj *pVgroup = pWMsg->pObj; + SVgObj *pVgroup = pWMsg->pRow; // refer to db SDbObj *pDb = mnodeGetDb(pVgroup->dbName); @@ -116,7 +116,7 @@ static int32_t mnodeVgroupActionInsert(SSWriteMsg *pWMsg) { } static int32_t mnodeVgroupActionDelete(SSWriteMsg *pWMsg) { - SVgObj *pVgroup = pWMsg->pObj; + SVgObj *pVgroup = pWMsg->pRow; if (pVgroup->pDb == NULL) { mError("vgId:%d, db:%s is not exist while insert into hash", pVgroup->vgId, pVgroup->dbName); @@ -138,7 +138,7 @@ static int32_t mnodeVgroupActionDelete(SSWriteMsg *pWMsg) { } static int32_t mnodeVgroupActionUpdate(SSWriteMsg *pWMsg) { - SVgObj *pNew = pWMsg->pObj; + SVgObj *pNew = pWMsg->pRow; SVgObj *pVgroup = mnodeGetVgroup(pNew->vgId); if (pVgroup != pNew) { @@ -177,7 +177,7 @@ static int32_t mnodeVgroupActionUpdate(SSWriteMsg *pWMsg) { } static int32_t mnodeVgroupActionEncode(SSWriteMsg *pWMsg) { - SVgObj *pVgroup = pWMsg->pObj; + SVgObj *pVgroup = pWMsg->pRow; memcpy(pWMsg->rowData, pVgroup, tsVgUpdateSize); SVgObj *pTmpVgroup = pWMsg->rowData; for (int32_t i = 0; i < TSDB_MAX_REPLICA; ++i) { @@ -194,7 +194,7 @@ static int32_t mnodeVgroupActionDecode(SSWriteMsg *pWMsg) { if (pVgroup == NULL) return TSDB_CODE_MND_OUT_OF_MEMORY; memcpy(pVgroup, pWMsg->rowData, tsVgUpdateSize); - pWMsg->pObj = pVgroup; + pWMsg->pRow = pVgroup; return TSDB_CODE_SUCCESS; } @@ -219,7 +219,7 @@ int32_t mnodeInitVgroups() { .fpEncode = mnodeVgroupActionEncode, .fpDecode = mnodeVgroupActionDecode, .fpDestroy = mnodeVgroupActionDestroy, - .fpDestored = mnodeVgroupActionRestored, + .fpRestored = mnodeVgroupActionRestored, }; tsVgroupSdb = sdbOpenTable(&tableDesc); @@ -256,7 +256,7 @@ void mnodeUpdateVgroup(SVgObj *pVgroup) { SSWriteMsg wmsg = { .type = SDB_OPER_GLOBAL, .pTable = tsVgroupSdb, - .pObj = pVgroup + .pRow = pVgroup }; int32_t code = sdbUpdateRow(&wmsg); @@ -519,14 +519,14 @@ static int32_t mnodeCreateVgroupCb(SMnodeMsg *pMsg, int32_t code) { if (code != TSDB_CODE_SUCCESS) { mError("app:%p:%p, vgId:%d, failed to create in sdb, reason:%s", pMsg->rpcMsg.ahandle, pMsg, pVgroup->vgId, tstrerror(code)); - SSWriteMsg desc = {.type = SDB_OPER_GLOBAL, .pObj = pVgroup, .pTable = tsVgroupSdb}; + SSWriteMsg desc = {.type = SDB_OPER_GLOBAL, .pRow = pVgroup, .pTable = tsVgroupSdb}; sdbDeleteRow(&desc); return code; } else { mInfo("app:%p:%p, vgId:%d, is created in sdb, db:%s replica:%d", pMsg->rpcMsg.ahandle, pMsg, pVgroup->vgId, pDb->name, pVgroup->numOfVnodes); pVgroup->status = TAOS_VG_STATUS_READY; - SSWriteMsg desc = {.type = SDB_OPER_GLOBAL, .pObj = pVgroup, .pTable = tsVgroupSdb}; + SSWriteMsg desc = {.type = SDB_OPER_GLOBAL, .pRow = pVgroup, .pTable = tsVgroupSdb}; (void)sdbUpdateRow(&desc); dnodeReprocessMWriteMsg(pMsg); @@ -535,7 +535,7 @@ static int32_t mnodeCreateVgroupCb(SMnodeMsg *pMsg, int32_t code) { // mInfo("app:%p:%p, vgId:%d, is created in sdb, db:%s replica:%d", pMsg->rpcMsg.ahandle, pMsg, pVgroup->vgId, // pDb->name, pVgroup->numOfVnodes); // pVgroup->status = TAOS_VG_STATUS_READY; - // SSWriteMsg desc = {.type = SDB_OPER_GLOBAL, .pObj = pVgroup, .pTable = tsVgroupSdb}; + // SSWriteMsg desc = {.type = SDB_OPER_GLOBAL, .pRow = pVgroup, .pTable = tsVgroupSdb}; // (void)sdbUpdateRow(&desc); // dnodeReprocessMWriteMsg(pMsg); // return TSDB_CODE_MND_ACTION_IN_PROGRESS; @@ -574,7 +574,7 @@ int32_t mnodeCreateVgroup(SMnodeMsg *pMsg) { SSWriteMsg wmsg = { .type = SDB_OPER_GLOBAL, .pTable = tsVgroupSdb, - .pObj = pVgroup, + .pRow = pVgroup, .rowSize = sizeof(SVgObj), .pMsg = pMsg, .fpReq = mnodeCreateVgroupFp @@ -598,7 +598,7 @@ void mnodeDropVgroup(SVgObj *pVgroup, void *ahandle) { SSWriteMsg wmsg = { .type = SDB_OPER_GLOBAL, .pTable = tsVgroupSdb, - .pObj = pVgroup + .pRow = pVgroup }; sdbDeleteRow(&wmsg); } @@ -770,7 +770,7 @@ static int32_t mnodeRetrieveVgroups(SShowObj *pShow, char *data, int32_t rows, v SDnodeObj * pDnode = pVgroup->vnodeGid[i].pDnode; const char *role = "NULL"; if (pDnode != NULL) { - role = mnodeGetMnodeRoleStr(pVgroup->vnodeGid[i].role); + role = syncRole[pVgroup->vnodeGid[i].role]; } pWrite = data + pShow->offset[cols] * rows + pShow->bytes[cols] * numOfRows; @@ -960,7 +960,7 @@ static void mnodeProcessCreateVnodeRsp(SRpcMsg *rpcMsg) { SSWriteMsg wmsg = { .type = SDB_OPER_GLOBAL, .pTable = tsVgroupSdb, - .pObj = pVgroup, + .pRow = pVgroup, .rowSize = sizeof(SVgObj), .pMsg = mnodeMsg, .fpWrite = mnodeCreateVgroupCb @@ -976,7 +976,7 @@ static void mnodeProcessCreateVnodeRsp(SRpcMsg *rpcMsg) { SSWriteMsg wmsg = { .type = SDB_OPER_GLOBAL, .pTable = tsVgroupSdb, - .pObj = pVgroup + .pRow = pVgroup }; sdbDeleteRow(&wmsg); dnodeSendRpcMWriteRsp(mnodeMsg, mnodeMsg->code); @@ -1034,7 +1034,7 @@ static void mnodeProcessDropVnodeRsp(SRpcMsg *rpcMsg) { SSWriteMsg wmsg = { .type = SDB_OPER_GLOBAL, .pTable = tsVgroupSdb, - .pObj = pVgroup + .pRow = pVgroup }; int32_t code = sdbDeleteRow(&wmsg); if (code != 0) { @@ -1087,7 +1087,7 @@ void mnodeDropAllDnodeVgroups(SDnodeObj *pDropDnode) { SSWriteMsg wmsg = { .type = SDB_OPER_LOCAL, .pTable = tsVgroupSdb, - .pObj = pVgroup, + .pRow = pVgroup, }; sdbDeleteRow(&wmsg); numOfVgroups++; @@ -1138,7 +1138,7 @@ void mnodeDropAllDbVgroups(SDbObj *pDropDb) { SSWriteMsg wmsg = { .type = SDB_OPER_LOCAL, .pTable = tsVgroupSdb, - .pObj = pVgroup, + .pRow = pVgroup, }; sdbDeleteRow(&wmsg); numOfVgroups++; From c1e1dd642764c81187357f081d0c69116a42c591 Mon Sep 17 00:00:00 2001 From: Shengliang Guan Date: Wed, 18 Nov 2020 17:05:06 +0800 Subject: [PATCH 06/13] TD-2045 --- src/mnode/inc/mnodeSdb.h | 4 +- src/mnode/src/mnodeDb.c | 6 +- src/mnode/src/mnodeMnode.c | 2 +- src/mnode/src/mnodeSdb.c | 142 +++++++++++++++++------------------- src/mnode/src/mnodeTable.c | 122 +++++++++++++++---------------- src/mnode/src/mnodeVgroup.c | 12 +-- 6 files changed, 139 insertions(+), 149 deletions(-) diff --git a/src/mnode/inc/mnodeSdb.h b/src/mnode/inc/mnodeSdb.h index 7169e14f03..fb23e252c0 100644 --- a/src/mnode/inc/mnodeSdb.h +++ b/src/mnode/inc/mnodeSdb.h @@ -52,11 +52,11 @@ typedef enum { typedef struct SSWriteMsg { ESdbOper type; int32_t processedCount; // for sync fwd callback - int32_t retCode; // for callback in sdb queue + int32_t code; // for callback in sdb queue int32_t rowSize; void * rowData; int32_t (*fpReq)(SMnodeMsg *pMsg); - int32_t (*fpWrite)(SMnodeMsg *pMsg, int32_t code); + int32_t (*fpRsp)(SMnodeMsg *pMsg, int32_t code); void * pRow; SMnodeMsg *pMsg; struct SSdbTable *pTable; diff --git a/src/mnode/src/mnodeDb.c b/src/mnode/src/mnodeDb.c index 9696df155a..6590ff0490 100644 --- a/src/mnode/src/mnodeDb.c +++ b/src/mnode/src/mnodeDb.c @@ -418,7 +418,7 @@ static int32_t mnodeCreateDb(SAcctObj *pAcct, SCreateDbMsg *pCreate, SMnodeMsg * .pRow = pDb, .rowSize = sizeof(SDbObj), .pMsg = pMsg, - .fpWrite = mnodeCreateDbCb + .fpRsp = mnodeCreateDbCb }; code = sdbInsertRow(&wmsg); @@ -1024,7 +1024,7 @@ static int32_t mnodeAlterDb(SDbObj *pDb, SAlterDbMsg *pAlter, void *pMsg) { .pTable = tsDbSdb, .pRow = pDb, .pMsg = pMsg, - .fpWrite = mnodeAlterDbCb + .fpRsp = mnodeAlterDbCb }; code = sdbUpdateRow(&wmsg); @@ -1076,7 +1076,7 @@ static int32_t mnodeDropDb(SMnodeMsg *pMsg) { .pTable = tsDbSdb, .pRow = pDb, .pMsg = pMsg, - .fpWrite = mnodeDropDbCb + .fpRsp = mnodeDropDbCb }; int32_t code = sdbDeleteRow(&wmsg); diff --git a/src/mnode/src/mnodeMnode.c b/src/mnode/src/mnodeMnode.c index 33925960be..20e70c1af7 100644 --- a/src/mnode/src/mnodeMnode.c +++ b/src/mnode/src/mnodeMnode.c @@ -329,7 +329,7 @@ void mnodeCreateMnode(int32_t dnodeId, char *dnodeEp, bool needConfirm) { .type = SDB_OPER_GLOBAL, .pTable = tsMnodeSdb, .pRow = pMnode, - .fpWrite = mnodeCreateMnodeCb + .fpRsp = mnodeCreateMnodeCb }; int32_t code = TSDB_CODE_SUCCESS; diff --git a/src/mnode/src/mnodeSdb.c b/src/mnode/src/mnodeSdb.c index 8056833cdb..850da1f0c3 100644 --- a/src/mnode/src/mnodeSdb.c +++ b/src/mnode/src/mnodeSdb.c @@ -48,6 +48,13 @@ typedef enum { SDB_STATUS_CLOSING = 2 } ESdbStatus; +char *actStr[] = { + "insert", + "delete", + "update", + "invalid" +}; + typedef struct SSdbTable { char tableName[SDB_TABLE_LEN]; ESdbTable tableId; @@ -140,18 +147,6 @@ static void *sdbGetObjKey(SSdbTable *pTable, void *key) { return key; } -static char *sdbGetActionStr(int32_t action) { - switch (action) { - case SDB_ACTION_INSERT: - return "insert"; - case SDB_ACTION_DELETE: - return "delete"; - case SDB_ACTION_UPDATE: - return "update"; - } - return "invalid"; -} - static char *sdbGetKeyStr(SSdbTable *pTable, void *key) { static char str[16]; switch (pTable->keyType) { @@ -167,7 +162,7 @@ static char *sdbGetKeyStr(SSdbTable *pTable, void *key) { } } -static char *sdbGetObjStr(SSdbTable *pTable, void *key) { +static char *sdbGetRowStr(SSdbTable *pTable, void *key) { return sdbGetKeyStr(pTable, sdbGetObjKey(pTable, key)); } @@ -254,33 +249,28 @@ static void sdbNotifyRole(void *ahandle, int8_t role) { } FORCE_INLINE -static void sdbConfirmForward(void *ahandle, void *param, int32_t code) { - assert(param); - SSWriteMsg * pWrite = param; - SMnodeMsg *pMsg = pWrite->pMsg; - if (code <= 0) pWrite->retCode = code; +static void sdbConfirmForward(void *ahandle, void *wparam, int32_t code) { + if (wparam == NULL) return; + SSWriteMsg *pWrite = wparam; + SMnodeMsg * pMsg = pWrite->pMsg; - int32_t processedCount = atomic_add_fetch_32(&pWrite->processedCount, 1); - if (processedCount <= 1) { - if (pMsg != NULL) { - sdbDebug("vgId:1, msg:%p waiting for confirm, count:%d code:%x", pMsg, processedCount, code); - } + if (code <= 0) pWrite->code = code; + int32_t count = atomic_add_fetch_32(&pWrite->processedCount, 1); + if (count <= 1) { + if (pMsg != NULL) sdbTrace("vgId:1, msg:%p waiting for confirm, count:%d code:%x", pMsg, count, code); return; - } - - if (pMsg != NULL) { - sdbDebug("vgId:1, msg:%p is confirmed, code:%x", pMsg, code); + } else { + if (pMsg != NULL) sdbTrace("vgId:1, msg:%p is confirmed, code:%x", pMsg, code); } // failed to forward, need revert insert - if (pWrite->retCode != TSDB_CODE_SUCCESS) { - SWalHead *pHead = (void *)pWrite + sizeof(SSWriteMsg) + SDB_SYNC_HACK; + if (pWrite->code != TSDB_CODE_SUCCESS) { + SWalHead *pHead = (SWalHead *)((char *)pWrite + sizeof(SSWriteMsg) + SDB_SYNC_HACK); int32_t action = pHead->msgType % 10; - sdbError("vgId:1, key:%p:%s hver:%" PRIu64 " action:%d, failed to foward since %s", pWrite->pRow, - sdbGetKeyStr(pWrite->pTable, pHead->cont), pHead->version, action, tstrerror(pWrite->retCode)); + sdbError("vgId:1, row:%p:%s hver:%" PRIu64 " action:%s, failed to foward since %s", pWrite->pRow, + sdbGetKeyStr(pWrite->pTable, pHead->cont), pHead->version, actStr[action], tstrerror(pWrite->code)); if (action == SDB_ACTION_INSERT) { // It's better to create a table in two stages, create it first and then set it success - //sdbDeleteHash(pWrite->pTable, pWrite); SSWriteMsg wmsg = { .type = SDB_OPER_GLOBAL, .pTable = pWrite->pTable, @@ -290,10 +280,10 @@ static void sdbConfirmForward(void *ahandle, void *param, int32_t code) { } } - if (pWrite->fpWrite != NULL) { - pWrite->retCode = (*pWrite->fpWrite)(pMsg, pWrite->retCode); + if (pWrite->fpRsp != NULL) { + pWrite->code = (*pWrite->fpRsp)(pMsg, pWrite->code); } - dnodeSendRpcMWriteRsp(pMsg, pWrite->retCode); + dnodeSendRpcMWriteRsp(pMsg, pWrite->code); // if ahandle, means this func is called by sdb write if (ahandle == NULL) { @@ -449,7 +439,7 @@ void sdbIncRef(void *tparam, void *pRow) { SSdbTable *pTable = tparam; int32_t * pRefCount = (int32_t *)(pRow + pTable->refCountPos); int32_t refCount = atomic_add_fetch_32(pRefCount, 1); - sdbTrace("vgId:1, sdb:%s, inc ref to key:%p:%s:%d", pTable->tableName, pRow, sdbGetObjStr(pTable, pRow), refCount); + sdbTrace("vgId:1, sdb:%s, inc ref to row:%p:%s:%d", pTable->tableName, pRow, sdbGetRowStr(pTable, pRow), refCount); } void sdbDecRef(void *tparam, void *pRow) { @@ -458,11 +448,11 @@ void sdbDecRef(void *tparam, void *pRow) { SSdbTable *pTable = tparam; int32_t * pRefCount = (int32_t *)(pRow + pTable->refCountPos); int32_t refCount = atomic_sub_fetch_32(pRefCount, 1); - sdbTrace("vgId:1, sdb:%s, dec ref to key:%p:%s:%d", pTable->tableName, pRow, sdbGetObjStr(pTable, pRow), refCount); + sdbTrace("vgId:1, sdb:%s, dec ref to row:%p:%s:%d", pTable->tableName, pRow, sdbGetRowStr(pTable, pRow), refCount); int32_t *updateEnd = pRow + pTable->refCountPos - 4; if (refCount <= 0 && *updateEnd) { - sdbTrace("vgId:1, sdb:%s, key:%p:%s:%d destroyed", pTable->tableName, pRow, sdbGetObjStr(pTable, pRow), refCount); + sdbTrace("vgId:1, sdb:%s, row:%p:%s:%d destroyed", pTable->tableName, pRow, sdbGetRowStr(pTable, pRow), refCount); SSWriteMsg wmsg = {.pRow = pRow}; (*pTable->fpDestroy)(&wmsg); } @@ -523,12 +513,12 @@ static int32_t sdbInsertHash(SSdbTable *pTable, SSWriteMsg *pWrite) { } sdbDebug("vgId:1, sdb:%s, insert key:%s to hash, rowSize:%d rows:%" PRId64 ", msg:%p", pTable->tableName, - sdbGetObjStr(pTable, pWrite->pRow), pWrite->rowSize, pTable->numOfRows, pWrite->pMsg); + sdbGetRowStr(pTable, pWrite->pRow), pWrite->rowSize, pTable->numOfRows, pWrite->pMsg); int32_t code = (*pTable->fpInsert)(pWrite); if (code != TSDB_CODE_SUCCESS) { sdbError("vgId:1, sdb:%s, failed to insert key:%s to hash, remove it", pTable->tableName, - sdbGetObjStr(pTable, pWrite->pRow)); + sdbGetRowStr(pTable, pWrite->pRow)); sdbDeleteHash(pTable, pWrite); } @@ -540,7 +530,7 @@ static int32_t sdbDeleteHash(SSdbTable *pTable, SSWriteMsg *pWrite) { bool set = atomic_val_compare_exchange_32(updateEnd, 0, 1) == 0; if (!set) { sdbError("vgId:1, sdb:%s, failed to delete key:%s from hash, for it already removed", pTable->tableName, - sdbGetObjStr(pTable, pWrite->pRow)); + sdbGetRowStr(pTable, pWrite->pRow)); return TSDB_CODE_MND_SDB_OBJ_NOT_THERE; } @@ -559,7 +549,7 @@ static int32_t sdbDeleteHash(SSdbTable *pTable, SSWriteMsg *pWrite) { atomic_sub_fetch_32(&pTable->numOfRows, 1); sdbDebug("vgId:1, sdb:%s, delete key:%s from hash, numOfRows:%" PRId64 ", msg:%p", pTable->tableName, - sdbGetObjStr(pTable, pWrite->pRow), pTable->numOfRows, pWrite->pMsg); + sdbGetRowStr(pTable, pWrite->pRow), pTable->numOfRows, pWrite->pMsg); sdbDecRef(pTable, pWrite->pRow); @@ -568,7 +558,7 @@ static int32_t sdbDeleteHash(SSdbTable *pTable, SSWriteMsg *pWrite) { static int32_t sdbUpdateHash(SSdbTable *pTable, SSWriteMsg *pWrite) { sdbDebug("vgId:1, sdb:%s, update key:%s in hash, numOfRows:%" PRId64 ", msg:%p", pTable->tableName, - sdbGetObjStr(pTable, pWrite->pRow), pTable->numOfRows, pWrite->pMsg); + sdbGetRowStr(pTable, pWrite->pRow), pTable->numOfRows, pWrite->pMsg); (*pTable->fpUpdate)(pWrite); return TSDB_CODE_SUCCESS; @@ -594,12 +584,12 @@ static int sdbWrite(void *wparam, void *hparam, int32_t qtype, void *unused) { if (pHead->version <= tsSdbMgmt.version) { pthread_mutex_unlock(&tsSdbMgmt.mutex); sdbDebug("vgId:1, sdb:%s, failed to restore %s key:%s from source(%d), hver:%" PRIu64 " too large, mver:%" PRIu64, - pTable->tableName, sdbGetActionStr(action), sdbGetKeyStr(pTable, pHead->cont), qtype, pHead->version, tsSdbMgmt.version); + pTable->tableName, actStr[action], sdbGetKeyStr(pTable, pHead->cont), qtype, pHead->version, tsSdbMgmt.version); return TSDB_CODE_SUCCESS; } else if (pHead->version != tsSdbMgmt.version + 1) { pthread_mutex_unlock(&tsSdbMgmt.mutex); sdbError("vgId:1, sdb:%s, failed to restore %s key:%s from source(%d), hver:%" PRIu64 " too large, mver:%" PRIu64, - pTable->tableName, sdbGetActionStr(action), sdbGetKeyStr(pTable, pHead->cont), qtype, pHead->version, tsSdbMgmt.version); + pTable->tableName, actStr[action], sdbGetKeyStr(pTable, pHead->cont), qtype, pHead->version, tsSdbMgmt.version); return TSDB_CODE_SYN_INVALID_VERSION; } else { tsSdbMgmt.version = pHead->version; @@ -623,19 +613,19 @@ static int sdbWrite(void *wparam, void *hparam, int32_t qtype, void *unused) { if (syncCode < 0) { sdbError("vgId:1, sdb:%s, failed to forward req since %s action:%s key:%s hver:%" PRIu64 ", msg:%p", pTable->tableName, - tstrerror(syncCode), sdbGetActionStr(action), sdbGetKeyStr(pTable, pHead->cont), pHead->version, pWrite->pMsg); + tstrerror(syncCode), actStr[action], sdbGetKeyStr(pTable, pHead->cont), pHead->version, pWrite->pMsg); } else if (syncCode > 0) { sdbDebug("vgId:1, sdb:%s, forward req is sent, action:%s key:%s hver:%" PRIu64 ", msg:%p", pTable->tableName, - sdbGetActionStr(action), sdbGetKeyStr(pTable, pHead->cont), pHead->version, pWrite->pMsg); + actStr[action], sdbGetKeyStr(pTable, pHead->cont), pHead->version, pWrite->pMsg); } else { sdbTrace("vgId:1, sdb:%s, no need to send fwd req, action:%s key:%s hver:%" PRIu64 ", msg:%p", pTable->tableName, - sdbGetActionStr(action), sdbGetKeyStr(pTable, pHead->cont), pHead->version, pWrite->pMsg); + actStr[action], sdbGetKeyStr(pTable, pHead->cont), pHead->version, pWrite->pMsg); } return syncCode; } sdbDebug("vgId:1, sdb:%s, record from wal/fwd is disposed, action:%s key:%s hver:%" PRIu64, pTable->tableName, - sdbGetActionStr(action), sdbGetKeyStr(pTable, pHead->cont), pHead->version); + actStr[action], sdbGetKeyStr(pTable, pHead->cont), pHead->version); // even it is WAL/FWD, it shall be called to update version in sync syncForwardToPeer(tsSdbMgmt.sync, pHead, pWrite, TAOS_QTYPE_RPC); @@ -675,7 +665,7 @@ int32_t sdbInsertRow(SSWriteMsg *pWrite) { if (sdbGetRowFromObj(pTable, pWrite->pRow)) { sdbError("vgId:1, sdb:%s, failed to insert key:%s, already exist", pTable->tableName, - sdbGetObjStr(pTable, pWrite->pRow)); + sdbGetRowStr(pTable, pWrite->pRow)); sdbDecRef(pTable, pWrite->pRow); return TSDB_CODE_MND_SDB_OBJ_ALREADY_THERE; } @@ -712,9 +702,9 @@ int32_t sdbInsertRowImp(SSWriteMsg *pWrite) { if (pTable == NULL) return TSDB_CODE_MND_SDB_INVALID_TABLE_TYPE; int32_t size = sizeof(SSWriteMsg) + sizeof(SWalHead) + pTable->maxRowSize + SDB_SYNC_HACK; - SSWriteMsg *pNewOper = taosAllocateQitem(size); + SSWriteMsg *pNewWrite = taosAllocateQitem(size); - SWalHead *pHead = (void *)pNewOper + sizeof(SSWriteMsg) + SDB_SYNC_HACK; + SWalHead *pHead = (SWalHead *)((char *)pNewWrite + sizeof(SSWriteMsg) + SDB_SYNC_HACK); pHead->version = 0; pHead->len = pWrite->rowSize; pHead->msgType = pTable->tableId * 10 + SDB_ACTION_INSERT; @@ -723,15 +713,15 @@ int32_t sdbInsertRowImp(SSWriteMsg *pWrite) { (*pTable->fpEncode)(pWrite); pHead->len = pWrite->rowSize; - memcpy(pNewOper, pWrite, sizeof(SSWriteMsg)); + memcpy(pNewWrite, pWrite, sizeof(SSWriteMsg)); - if (pNewOper->pMsg != NULL) { - sdbDebug("vgId:1, ahandle:%p msg:%p, sdb:%s key:%p:%s, insert action is add to sdb queue", pNewOper->pMsg->rpcMsg.ahandle, - pNewOper->pMsg, pTable->tableName, pWrite->pRow, sdbGetObjStr(pTable, pWrite->pRow)); + if (pNewWrite->pMsg != NULL) { + sdbDebug("vgId:1, ahandle:%p msg:%p, sdb:%s row:%p:%s, insert action is add to sdb queue", pNewWrite->pMsg->rpcMsg.ahandle, + pNewWrite->pMsg, pTable->tableName, pWrite->pRow, sdbGetRowStr(pTable, pWrite->pRow)); } - sdbIncRef(pNewOper->pTable, pNewOper->pRow); - taosWriteQitem(tsSdbWQueue, TAOS_QTYPE_RPC, pNewOper); + sdbIncRef(pNewWrite->pTable, pNewWrite->pRow); + taosWriteQitem(tsSdbWQueue, TAOS_QTYPE_RPC, pNewWrite); return TSDB_CODE_MND_ACTION_IN_PROGRESS; } @@ -781,9 +771,9 @@ int32_t sdbDeleteRowImp(SSWriteMsg *pWrite) { if (pTable == NULL) return TSDB_CODE_MND_SDB_INVALID_TABLE_TYPE; int32_t size = sizeof(SSWriteMsg) + sizeof(SWalHead) + pTable->maxRowSize + SDB_SYNC_HACK; - SSWriteMsg *pNewOper = taosAllocateQitem(size); + SSWriteMsg *pNewWrite = taosAllocateQitem(size); - SWalHead *pHead = (void *)pNewOper + sizeof(SSWriteMsg) + SDB_SYNC_HACK; + SWalHead *pHead = (SWalHead *)((void *)pNewWrite + sizeof(SSWriteMsg) + SDB_SYNC_HACK); pHead->version = 0; pHead->msgType = pTable->tableId * 10 + SDB_ACTION_DELETE; @@ -791,14 +781,14 @@ int32_t sdbDeleteRowImp(SSWriteMsg *pWrite) { (*pTable->fpEncode)(pWrite); pHead->len = pWrite->rowSize; - memcpy(pNewOper, pWrite, sizeof(SSWriteMsg)); + memcpy(pNewWrite, pWrite, sizeof(SSWriteMsg)); - if (pNewOper->pMsg != NULL) { - sdbDebug("vgId:1, ahandle:%p msg:%p, sdb:%s key:%p:%s, delete action is add to sdb queue", pNewOper->pMsg->rpcMsg.ahandle, - pNewOper->pMsg, pTable->tableName, pWrite->pRow, sdbGetObjStr(pTable, pWrite->pRow)); + if (pNewWrite->pMsg != NULL) { + sdbDebug("vgId:1, ahandle:%p msg:%p, sdb:%s row:%p:%s, delete action is add to sdb queue", pNewWrite->pMsg->rpcMsg.ahandle, + pNewWrite->pMsg, pTable->tableName, pWrite->pRow, sdbGetRowStr(pTable, pWrite->pRow)); } - taosWriteQitem(tsSdbWQueue, TAOS_QTYPE_RPC, pNewOper); + taosWriteQitem(tsSdbWQueue, TAOS_QTYPE_RPC, pNewWrite); return TSDB_CODE_MND_ACTION_IN_PROGRESS; } @@ -836,9 +826,9 @@ int32_t sdbUpdateRowImp(SSWriteMsg *pWrite) { if (pTable == NULL) return TSDB_CODE_MND_SDB_INVALID_TABLE_TYPE; int32_t size = sizeof(SSWriteMsg) + sizeof(SWalHead) + pTable->maxRowSize + SDB_SYNC_HACK; - SSWriteMsg *pNewOper = taosAllocateQitem(size); + SSWriteMsg *pNewWrite = taosAllocateQitem(size); - SWalHead *pHead = (void *)pNewOper + sizeof(SSWriteMsg) + SDB_SYNC_HACK; + SWalHead *pHead = (SWalHead *)((void *)pNewWrite + sizeof(SSWriteMsg) + SDB_SYNC_HACK); pHead->version = 0; pHead->msgType = pTable->tableId * 10 + SDB_ACTION_UPDATE; @@ -846,15 +836,15 @@ int32_t sdbUpdateRowImp(SSWriteMsg *pWrite) { (*pTable->fpEncode)(pWrite); pHead->len = pWrite->rowSize; - memcpy(pNewOper, pWrite, sizeof(SSWriteMsg)); + memcpy(pNewWrite, pWrite, sizeof(SSWriteMsg)); - if (pNewOper->pMsg != NULL) { - sdbDebug("vgId:1, ahandle:%p msg:%p, sdb:%s key:%p:%s, update action is add to sdb queue", pNewOper->pMsg->rpcMsg.ahandle, - pNewOper->pMsg, pTable->tableName, pWrite->pRow, sdbGetObjStr(pTable, pWrite->pRow)); + if (pNewWrite->pMsg != NULL) { + sdbDebug("vgId:1, ahandle:%p msg:%p, sdb:%s row:%p:%s, update action is add to sdb queue", pNewWrite->pMsg->rpcMsg.ahandle, + pNewWrite->pMsg, pTable->tableName, pWrite->pRow, sdbGetRowStr(pTable, pWrite->pRow)); } - sdbIncRef(pNewOper->pTable, pNewOper->pRow); - taosWriteQitem(tsSdbWQueue, TAOS_QTYPE_RPC, pNewOper); + sdbIncRef(pNewWrite->pTable, pNewWrite->pRow); + taosWriteQitem(tsSdbWQueue, TAOS_QTYPE_RPC, pNewWrite); return TSDB_CODE_MND_ACTION_IN_PROGRESS; } @@ -1071,7 +1061,7 @@ static void *sdbWorkerFp(void *pWorker) { pWrite->processedCount = 1; pHead = (void *)pWrite + sizeof(SSWriteMsg) + SDB_SYNC_HACK; if (pWrite->pMsg != NULL) { - sdbDebug("vgId:1, ahandle:%p msg:%p, sdb:%s key:%p:%s hver:%" PRIu64 ", will be processed in sdb queue", + sdbDebug("vgId:1, ahandle:%p msg:%p, sdb:%s row:%p:%s hver:%" PRIu64 ", will be processed in sdb queue", pWrite->pMsg->rpcMsg.ahandle, pWrite->pMsg, pWrite->pTable->tableName, pWrite->pRow, sdbGetKeyStr(pWrite->pTable, pHead->cont), pHead->version); } @@ -1083,7 +1073,7 @@ static void *sdbWorkerFp(void *pWorker) { int32_t code = sdbWrite(pWrite, pHead, qtype, NULL); if (code > 0) code = 0; if (pWrite) { - pWrite->retCode = code; + pWrite->code = code; } else { pHead->len = code; // hackway } @@ -1098,7 +1088,7 @@ static void *sdbWorkerFp(void *pWorker) { if (qtype == TAOS_QTYPE_RPC) { pWrite = (SSWriteMsg *)item; - sdbConfirmForward(NULL, pWrite, pWrite->retCode); + sdbConfirmForward(NULL, pWrite, pWrite->code); } else if (qtype == TAOS_QTYPE_FWD) { pHead = (SWalHead *)item; syncConfirmForward(tsSdbMgmt.sync, pHead->version, pHead->len); diff --git a/src/mnode/src/mnodeTable.c b/src/mnode/src/mnodeTable.c index fc441bf524..ce9f652330 100644 --- a/src/mnode/src/mnodeTable.c +++ b/src/mnode/src/mnodeTable.c @@ -879,12 +879,12 @@ static int32_t mnodeProcessCreateSuperTableMsg(SMnodeMsg *pMsg) { mnodeIncTableRef(pMsg->pTable); SSWriteMsg wmsg = { - .type = SDB_OPER_GLOBAL, - .pTable = tsSuperTableSdb, - .pRow = pStable, + .type = SDB_OPER_GLOBAL, + .pTable = tsSuperTableSdb, + .pRow = pStable, .rowSize = sizeof(SSTableObj) + schemaSize, - .pMsg = pMsg, - .fpWrite = mnodeCreateSuperTableCb + .pMsg = pMsg, + .fpRsp = mnodeCreateSuperTableCb }; int32_t code = sdbInsertRow(&wmsg); @@ -942,7 +942,7 @@ static int32_t mnodeProcessDropSuperTableMsg(SMnodeMsg *pMsg) { .pTable = tsSuperTableSdb, .pRow = pStable, .pMsg = pMsg, - .fpWrite = mnodeDropSuperTableCb + .fpRsp = mnodeDropSuperTableCb }; int32_t code = sdbDeleteRow(&wmsg); @@ -1011,11 +1011,11 @@ static int32_t mnodeAddSuperTableTag(SMnodeMsg *pMsg, SSchema schema[], int32_t schema[0].name); SSWriteMsg wmsg = { - .type = SDB_OPER_GLOBAL, - .pTable = tsSuperTableSdb, - .pRow = pStable, - .pMsg = pMsg, - .fpWrite = mnodeAddSuperTableTagCb + .type = SDB_OPER_GLOBAL, + .pTable = tsSuperTableSdb, + .pRow = pStable, + .pMsg = pMsg, + .fpRsp = mnodeAddSuperTableTagCb }; return sdbUpdateRow(&wmsg); @@ -1045,11 +1045,11 @@ static int32_t mnodeDropSuperTableTag(SMnodeMsg *pMsg, char *tagName) { mInfo("app:%p:%p, stable %s, start to drop tag %s", pMsg->rpcMsg.ahandle, pMsg, pStable->info.tableId, tagName); SSWriteMsg wmsg = { - .type = SDB_OPER_GLOBAL, - .pTable = tsSuperTableSdb, - .pRow = pStable, - .pMsg = pMsg, - .fpWrite = mnodeDropSuperTableTagCb + .type = SDB_OPER_GLOBAL, + .pTable = tsSuperTableSdb, + .pRow = pStable, + .pMsg = pMsg, + .fpRsp = mnodeDropSuperTableTagCb }; return sdbUpdateRow(&wmsg); @@ -1089,11 +1089,11 @@ static int32_t mnodeModifySuperTableTagName(SMnodeMsg *pMsg, char *oldTagName, c oldTagName, newTagName); SSWriteMsg wmsg = { - .type = SDB_OPER_GLOBAL, - .pTable = tsSuperTableSdb, - .pRow = pStable, - .pMsg = pMsg, - .fpWrite = mnodeModifySuperTableTagNameCb + .type = SDB_OPER_GLOBAL, + .pTable = tsSuperTableSdb, + .pRow = pStable, + .pMsg = pMsg, + .fpRsp = mnodeModifySuperTableTagNameCb }; return sdbUpdateRow(&wmsg); @@ -1163,11 +1163,11 @@ static int32_t mnodeAddSuperTableColumn(SMnodeMsg *pMsg, SSchema schema[], int32 mInfo("app:%p:%p, stable %s, start to add column", pMsg->rpcMsg.ahandle, pMsg, pStable->info.tableId); SSWriteMsg wmsg = { - .type = SDB_OPER_GLOBAL, - .pTable = tsSuperTableSdb, - .pRow = pStable, - .pMsg = pMsg, - .fpWrite = mnodeAddSuperTableColumnCb + .type = SDB_OPER_GLOBAL, + .pTable = tsSuperTableSdb, + .pRow = pStable, + .pMsg = pMsg, + .fpRsp = mnodeAddSuperTableColumnCb }; return sdbUpdateRow(&wmsg); @@ -1208,11 +1208,11 @@ static int32_t mnodeDropSuperTableColumn(SMnodeMsg *pMsg, char *colName) { mInfo("app:%p:%p, stable %s, start to delete column", pMsg->rpcMsg.ahandle, pMsg, pStable->info.tableId); SSWriteMsg wmsg = { - .type = SDB_OPER_GLOBAL, - .pTable = tsSuperTableSdb, - .pRow = pStable, - .pMsg = pMsg, - .fpWrite = mnodeDropSuperTableColumnCb + .type = SDB_OPER_GLOBAL, + .pTable = tsSuperTableSdb, + .pRow = pStable, + .pMsg = pMsg, + .fpRsp = mnodeDropSuperTableColumnCb }; return sdbUpdateRow(&wmsg); @@ -1252,11 +1252,11 @@ static int32_t mnodeChangeSuperTableColumn(SMnodeMsg *pMsg, char *oldName, char oldName, newName); SSWriteMsg wmsg = { - .type = SDB_OPER_GLOBAL, - .pTable = tsSuperTableSdb, - .pRow = pStable, - .pMsg = pMsg, - .fpWrite = mnodeChangeSuperTableColumnCb + .type = SDB_OPER_GLOBAL, + .pTable = tsSuperTableSdb, + .pRow = pStable, + .pMsg = pMsg, + .fpRsp = mnodeChangeSuperTableColumnCb }; return sdbUpdateRow(&wmsg); @@ -1902,11 +1902,11 @@ static int32_t mnodeProcessDropChildTableMsg(SMnodeMsg *pMsg) { } SSWriteMsg wmsg = { - .type = SDB_OPER_GLOBAL, - .pTable = tsChildTableSdb, - .pRow = pTable, - .pMsg = pMsg, - .fpWrite = mnodeDropChildTableCb + .type = SDB_OPER_GLOBAL, + .pTable = tsChildTableSdb, + .pRow = pTable, + .pMsg = pMsg, + .fpRsp = mnodeDropChildTableCb }; int32_t code = sdbDeleteRow(&wmsg); @@ -2006,11 +2006,11 @@ static int32_t mnodeAddNormalTableColumn(SMnodeMsg *pMsg, SSchema schema[], int3 mInfo("app:%p:%p, ctable %s, start to add column", pMsg->rpcMsg.ahandle, pMsg, pTable->info.tableId); SSWriteMsg wmsg = { - .type = SDB_OPER_GLOBAL, - .pTable = tsChildTableSdb, - .pRow = pTable, - .pMsg = pMsg, - .fpWrite = mnodeAlterNormalTableColumnCb + .type = SDB_OPER_GLOBAL, + .pTable = tsChildTableSdb, + .pRow = pTable, + .pMsg = pMsg, + .fpRsp = mnodeAlterNormalTableColumnCb }; return sdbUpdateRow(&wmsg); @@ -2039,11 +2039,11 @@ static int32_t mnodeDropNormalTableColumn(SMnodeMsg *pMsg, char *colName) { mInfo("app:%p:%p, ctable %s, start to drop column %s", pMsg->rpcMsg.ahandle, pMsg, pTable->info.tableId, colName); SSWriteMsg wmsg = { - .type = SDB_OPER_GLOBAL, - .pTable = tsChildTableSdb, - .pRow = pTable, - .pMsg = pMsg, - .fpWrite = mnodeAlterNormalTableColumnCb + .type = SDB_OPER_GLOBAL, + .pTable = tsChildTableSdb, + .pRow = pTable, + .pMsg = pMsg, + .fpRsp = mnodeAlterNormalTableColumnCb }; return sdbUpdateRow(&wmsg); @@ -2076,11 +2076,11 @@ static int32_t mnodeChangeNormalTableColumn(SMnodeMsg *pMsg, char *oldName, char oldName, newName); SSWriteMsg wmsg = { - .type = SDB_OPER_GLOBAL, - .pTable = tsChildTableSdb, - .pRow = pTable, - .pMsg = pMsg, - .fpWrite = mnodeAlterNormalTableColumnCb + .type = SDB_OPER_GLOBAL, + .pTable = tsChildTableSdb, + .pRow = pTable, + .pMsg = pMsg, + .fpRsp = mnodeAlterNormalTableColumnCb }; return sdbUpdateRow(&wmsg); @@ -2411,11 +2411,11 @@ static void mnodeProcessCreateChildTableRsp(SRpcMsg *rpcMsg) { if (rpcMsg->code == TSDB_CODE_SUCCESS || rpcMsg->code == TSDB_CODE_TDB_TABLE_ALREADY_EXIST) { SSWriteMsg desc = { - .type = SDB_OPER_GLOBAL, - .pRow = pTable, - .pTable = tsChildTableSdb, - .pMsg = mnodeMsg, - .fpWrite = mnodeDoCreateChildTableCb + .type = SDB_OPER_GLOBAL, + .pRow = pTable, + .pTable = tsChildTableSdb, + .pMsg = mnodeMsg, + .fpRsp = mnodeDoCreateChildTableCb }; int32_t code = sdbInsertRowImp(&desc); diff --git a/src/mnode/src/mnodeVgroup.c b/src/mnode/src/mnodeVgroup.c index 9da96a8acf..c12d2057f8 100644 --- a/src/mnode/src/mnodeVgroup.c +++ b/src/mnode/src/mnodeVgroup.c @@ -958,12 +958,12 @@ static void mnodeProcessCreateVnodeRsp(SRpcMsg *rpcMsg) { if (mnodeMsg->received == mnodeMsg->successed) { SSWriteMsg wmsg = { - .type = SDB_OPER_GLOBAL, - .pTable = tsVgroupSdb, - .pRow = pVgroup, - .rowSize = sizeof(SVgObj), - .pMsg = mnodeMsg, - .fpWrite = mnodeCreateVgroupCb + .type = SDB_OPER_GLOBAL, + .pTable = tsVgroupSdb, + .pRow = pVgroup, + .rowSize = sizeof(SVgObj), + .pMsg = mnodeMsg, + .fpRsp = mnodeCreateVgroupCb }; int32_t code = sdbInsertRowImp(&wmsg); From cf5bcc4b585c4971f39629e663ac9c3d7837cd56 Mon Sep 17 00:00:00 2001 From: Shengliang Guan Date: Wed, 18 Nov 2020 17:55:57 +0800 Subject: [PATCH 07/13] TD-2046 --- src/mnode/inc/mnodeSdb.h | 4 +- src/mnode/src/mnodeAcct.c | 12 ++-- src/mnode/src/mnodeCluster.c | 12 ++-- src/mnode/src/mnodeDb.c | 8 +-- src/mnode/src/mnodeDnode.c | 8 +-- src/mnode/src/mnodeMnode.c | 8 +-- src/mnode/src/mnodeSdb.c | 109 ++++++++++++++++++----------------- src/mnode/src/mnodeTable.c | 8 +-- src/mnode/src/mnodeUser.c | 12 ++-- src/mnode/src/mnodeVgroup.c | 8 +-- 10 files changed, 95 insertions(+), 94 deletions(-) diff --git a/src/mnode/inc/mnodeSdb.h b/src/mnode/inc/mnodeSdb.h index fb23e252c0..04fee5f6d5 100644 --- a/src/mnode/inc/mnodeSdb.h +++ b/src/mnode/inc/mnodeSdb.h @@ -63,11 +63,11 @@ typedef struct SSWriteMsg { } SSWriteMsg; typedef struct { - char * tableName; + char * name; int32_t hashSessions; int32_t maxRowSize; int32_t refCountPos; - ESdbTable tableId; + ESdbTable id; ESdbKey keyType; int32_t (*fpInsert)(SSWriteMsg *pWrite); int32_t (*fpDelete)(SSWriteMsg *pWrite); diff --git a/src/mnode/src/mnodeAcct.c b/src/mnode/src/mnodeAcct.c index b12c200507..48af408c99 100644 --- a/src/mnode/src/mnodeAcct.c +++ b/src/mnode/src/mnodeAcct.c @@ -99,9 +99,9 @@ int32_t mnodeInitAccts() { SAcctObj tObj; tsAcctUpdateSize = (int8_t *)tObj.updateEnd - (int8_t *)&tObj; - SSdbTableDesc tableDesc = { - .tableId = SDB_TABLE_ACCOUNT, - .tableName = "accounts", + SSdbTableDesc desc = { + .id = SDB_TABLE_ACCOUNT, + .name = "accounts", .hashSessions = TSDB_DEFAULT_ACCOUNTS_HASH_SIZE, .maxRowSize = tsAcctUpdateSize, .refCountPos = (int8_t *)(&tObj.refCount) - (int8_t *)&tObj, @@ -115,13 +115,13 @@ int32_t mnodeInitAccts() { .fpRestored = mnodeAcctActionRestored }; - tsAcctSdb = sdbOpenTable(&tableDesc); + tsAcctSdb = sdbOpenTable(&desc); if (tsAcctSdb == NULL) { - mError("table:%s, failed to create hash", tableDesc.tableName); + mError("table:%s, failed to create hash", desc.name); return -1; } - mDebug("table:%s, hash is created", tableDesc.tableName); + mDebug("table:%s, hash is created", desc.name); return TSDB_CODE_SUCCESS; } diff --git a/src/mnode/src/mnodeCluster.c b/src/mnode/src/mnodeCluster.c index f9182704b0..ff84b7ac3f 100644 --- a/src/mnode/src/mnodeCluster.c +++ b/src/mnode/src/mnodeCluster.c @@ -84,9 +84,9 @@ int32_t mnodeInitCluster() { SClusterObj tObj; tsClusterUpdateSize = (int8_t *)tObj.updateEnd - (int8_t *)&tObj; - SSdbTableDesc tableDesc = { - .tableId = SDB_TABLE_CLUSTER, - .tableName = "cluster", + SSdbTableDesc desc = { + .id = SDB_TABLE_CLUSTER, + .name = "cluster", .hashSessions = TSDB_DEFAULT_CLUSTER_HASH_SIZE, .maxRowSize = tsClusterUpdateSize, .refCountPos = (int8_t *)(&tObj.refCount) - (int8_t *)&tObj, @@ -100,16 +100,16 @@ int32_t mnodeInitCluster() { .fpRestored = mnodeClusterActionRestored }; - tsClusterSdb = sdbOpenTable(&tableDesc); + tsClusterSdb = sdbOpenTable(&desc); if (tsClusterSdb == NULL) { - mError("table:%s, failed to create hash", tableDesc.tableName); + mError("table:%s, failed to create hash", desc.name); return -1; } mnodeAddShowMetaHandle(TSDB_MGMT_TABLE_CLUSTER, mnodeGetClusterMeta); mnodeAddShowRetrieveHandle(TSDB_MGMT_TABLE_CLUSTER, mnodeRetrieveClusters); - mDebug("table:%s, hash is created", tableDesc.tableName); + mDebug("table:%s, hash is created", desc.name); return TSDB_CODE_SUCCESS; } diff --git a/src/mnode/src/mnodeDb.c b/src/mnode/src/mnodeDb.c index 6590ff0490..96658ac73c 100644 --- a/src/mnode/src/mnodeDb.c +++ b/src/mnode/src/mnodeDb.c @@ -144,9 +144,9 @@ int32_t mnodeInitDbs() { SDbObj tObj; tsDbUpdateSize = (int8_t *)tObj.updateEnd - (int8_t *)&tObj; - SSdbTableDesc tableDesc = { - .tableId = SDB_TABLE_DB, - .tableName = "dbs", + SSdbTableDesc desc = { + .id = SDB_TABLE_DB, + .name = "dbs", .hashSessions = TSDB_DEFAULT_DBS_HASH_SIZE, .maxRowSize = tsDbUpdateSize, .refCountPos = (int8_t *)(&tObj.refCount) - (int8_t *)&tObj, @@ -160,7 +160,7 @@ int32_t mnodeInitDbs() { .fpRestored = mnodeDbActionRestored }; - tsDbSdb = sdbOpenTable(&tableDesc); + tsDbSdb = sdbOpenTable(&desc); if (tsDbSdb == NULL) { mError("failed to init db data"); return -1; diff --git a/src/mnode/src/mnodeDnode.c b/src/mnode/src/mnodeDnode.c index 99cc44ba7d..7b52747951 100644 --- a/src/mnode/src/mnodeDnode.c +++ b/src/mnode/src/mnodeDnode.c @@ -171,9 +171,9 @@ int32_t mnodeInitDnodes() { tsDnodeUpdateSize = (int8_t *)tObj.updateEnd - (int8_t *)&tObj; pthread_mutex_init(&tsDnodeEpsMutex, NULL); - SSdbTableDesc tableDesc = { - .tableId = SDB_TABLE_DNODE, - .tableName = "dnodes", + SSdbTableDesc desc = { + .id = SDB_TABLE_DNODE, + .name = "dnodes", .hashSessions = TSDB_DEFAULT_DNODES_HASH_SIZE, .maxRowSize = tsDnodeUpdateSize, .refCountPos = (int8_t *)(&tObj.refCount) - (int8_t *)&tObj, @@ -187,7 +187,7 @@ int32_t mnodeInitDnodes() { .fpRestored = mnodeDnodeActionRestored }; - tsDnodeSdb = sdbOpenTable(&tableDesc); + tsDnodeSdb = sdbOpenTable(&desc); if (tsDnodeSdb == NULL) { mError("failed to init dnodes data"); return -1; diff --git a/src/mnode/src/mnodeMnode.c b/src/mnode/src/mnodeMnode.c index 20e70c1af7..a97aef61e9 100644 --- a/src/mnode/src/mnodeMnode.c +++ b/src/mnode/src/mnodeMnode.c @@ -137,9 +137,9 @@ int32_t mnodeInitMnodes() { SMnodeObj tObj; tsMnodeUpdateSize = (int8_t *)tObj.updateEnd - (int8_t *)&tObj; - SSdbTableDesc tableDesc = { - .tableId = SDB_TABLE_MNODE, - .tableName = "mnodes", + SSdbTableDesc desc = { + .id = SDB_TABLE_MNODE, + .name = "mnodes", .hashSessions = TSDB_DEFAULT_MNODES_HASH_SIZE, .maxRowSize = tsMnodeUpdateSize, .refCountPos = (int8_t *)(&tObj.refCount) - (int8_t *)&tObj, @@ -153,7 +153,7 @@ int32_t mnodeInitMnodes() { .fpRestored = mnodeMnodeActionRestored }; - tsMnodeSdb = sdbOpenTable(&tableDesc); + tsMnodeSdb = sdbOpenTable(&desc); if (tsMnodeSdb == NULL) { mError("failed to init mnodes data"); return -1; diff --git a/src/mnode/src/mnodeSdb.c b/src/mnode/src/mnodeSdb.c index 850da1f0c3..12cf5757b3 100644 --- a/src/mnode/src/mnodeSdb.c +++ b/src/mnode/src/mnodeSdb.c @@ -56,8 +56,8 @@ char *actStr[] = { }; typedef struct SSdbTable { - char tableName[SDB_TABLE_LEN]; - ESdbTable tableId; + char name[SDB_TABLE_LEN]; + ESdbTable id; ESdbKey keyType; int32_t hashSessions; int32_t maxRowSize; @@ -201,7 +201,7 @@ static void sdbRestoreTables() { totalRows += pTable->numOfRows; numOfTables++; - sdbDebug("vgId:1, sdb:%s is restored, rows:%" PRId64, pTable->tableName, pTable->numOfRows); + sdbDebug("vgId:1, sdb:%s is restored, rows:%" PRId64, pTable->name, pTable->numOfRows); } sdbInfo("vgId:1, sdb is restored, mver:%" PRIu64 " rows:%d tables:%d", tsSdbMgmt.version, totalRows, numOfTables); @@ -248,6 +248,21 @@ static void sdbNotifyRole(void *ahandle, int8_t role) { sdbUpdateMnodeRoles(); } +// failed to forward, need revert insert +static void sdbHandleFailedConfirm(SSWriteMsg *pWrite) { + SWalHead *pHead = (SWalHead *)((char *)pWrite + sizeof(SSWriteMsg) + SDB_SYNC_HACK); + int32_t action = pHead->msgType % 10; + + sdbError("vgId:1, row:%p:%s hver:%" PRIu64 " action:%s, failed to foward since %s", pWrite->pRow, + sdbGetKeyStr(pWrite->pTable, pHead->cont), pHead->version, actStr[action], tstrerror(pWrite->code)); + + // It's better to create a table in two stages, create it first and then set it success + if (action == SDB_ACTION_INSERT) { + SSWriteMsg wmsg = {.type = SDB_OPER_GLOBAL, .pTable = pWrite->pTable, .pRow = pWrite->pRow}; + sdbDeleteRow(&wmsg); + } +} + FORCE_INLINE static void sdbConfirmForward(void *ahandle, void *wparam, int32_t code) { if (wparam == NULL) return; @@ -263,26 +278,12 @@ static void sdbConfirmForward(void *ahandle, void *wparam, int32_t code) { if (pMsg != NULL) sdbTrace("vgId:1, msg:%p is confirmed, code:%x", pMsg, code); } - // failed to forward, need revert insert - if (pWrite->code != TSDB_CODE_SUCCESS) { - SWalHead *pHead = (SWalHead *)((char *)pWrite + sizeof(SSWriteMsg) + SDB_SYNC_HACK); - int32_t action = pHead->msgType % 10; - sdbError("vgId:1, row:%p:%s hver:%" PRIu64 " action:%s, failed to foward since %s", pWrite->pRow, - sdbGetKeyStr(pWrite->pTable, pHead->cont), pHead->version, actStr[action], tstrerror(pWrite->code)); - if (action == SDB_ACTION_INSERT) { - // It's better to create a table in two stages, create it first and then set it success - SSWriteMsg wmsg = { - .type = SDB_OPER_GLOBAL, - .pTable = pWrite->pTable, - .pRow = pWrite->pRow - }; - sdbDeleteRow(&wmsg); - } - } + if (pWrite->code != TSDB_CODE_SUCCESS) sdbHandleFailedConfirm(pWrite); if (pWrite->fpRsp != NULL) { pWrite->code = (*pWrite->fpRsp)(pMsg, pWrite->code); } + dnodeSendRpcMWriteRsp(pMsg, pWrite->code); // if ahandle, means this func is called by sdb write @@ -439,7 +440,7 @@ void sdbIncRef(void *tparam, void *pRow) { SSdbTable *pTable = tparam; int32_t * pRefCount = (int32_t *)(pRow + pTable->refCountPos); int32_t refCount = atomic_add_fetch_32(pRefCount, 1); - sdbTrace("vgId:1, sdb:%s, inc ref to row:%p:%s:%d", pTable->tableName, pRow, sdbGetRowStr(pTable, pRow), refCount); + sdbTrace("vgId:1, sdb:%s, inc ref to row:%p:%s:%d", pTable->name, pRow, sdbGetRowStr(pTable, pRow), refCount); } void sdbDecRef(void *tparam, void *pRow) { @@ -448,11 +449,11 @@ void sdbDecRef(void *tparam, void *pRow) { SSdbTable *pTable = tparam; int32_t * pRefCount = (int32_t *)(pRow + pTable->refCountPos); int32_t refCount = atomic_sub_fetch_32(pRefCount, 1); - sdbTrace("vgId:1, sdb:%s, dec ref to row:%p:%s:%d", pTable->tableName, pRow, sdbGetRowStr(pTable, pRow), refCount); + sdbTrace("vgId:1, sdb:%s, dec ref to row:%p:%s:%d", pTable->name, pRow, sdbGetRowStr(pTable, pRow), refCount); int32_t *updateEnd = pRow + pTable->refCountPos - 4; if (refCount <= 0 && *updateEnd) { - sdbTrace("vgId:1, sdb:%s, row:%p:%s:%d destroyed", pTable->tableName, pRow, sdbGetRowStr(pTable, pRow), refCount); + sdbTrace("vgId:1, sdb:%s, row:%p:%s:%d destroyed", pTable->name, pRow, sdbGetRowStr(pTable, pRow), refCount); SSWriteMsg wmsg = {.pRow = pRow}; (*pTable->fpDestroy)(&wmsg); } @@ -512,12 +513,12 @@ static int32_t sdbInsertHash(SSdbTable *pTable, SSWriteMsg *pWrite) { atomic_add_fetch_32(&pTable->autoIndex, 1); } - sdbDebug("vgId:1, sdb:%s, insert key:%s to hash, rowSize:%d rows:%" PRId64 ", msg:%p", pTable->tableName, + sdbDebug("vgId:1, sdb:%s, insert key:%s to hash, rowSize:%d rows:%" PRId64 ", msg:%p", pTable->name, sdbGetRowStr(pTable, pWrite->pRow), pWrite->rowSize, pTable->numOfRows, pWrite->pMsg); int32_t code = (*pTable->fpInsert)(pWrite); if (code != TSDB_CODE_SUCCESS) { - sdbError("vgId:1, sdb:%s, failed to insert key:%s to hash, remove it", pTable->tableName, + sdbError("vgId:1, sdb:%s, failed to insert key:%s to hash, remove it", pTable->name, sdbGetRowStr(pTable, pWrite->pRow)); sdbDeleteHash(pTable, pWrite); } @@ -529,7 +530,7 @@ static int32_t sdbDeleteHash(SSdbTable *pTable, SSWriteMsg *pWrite) { int32_t *updateEnd = pWrite->pRow + pTable->refCountPos - 4; bool set = atomic_val_compare_exchange_32(updateEnd, 0, 1) == 0; if (!set) { - sdbError("vgId:1, sdb:%s, failed to delete key:%s from hash, for it already removed", pTable->tableName, + sdbError("vgId:1, sdb:%s, failed to delete key:%s from hash, for it already removed", pTable->name, sdbGetRowStr(pTable, pWrite->pRow)); return TSDB_CODE_MND_SDB_OBJ_NOT_THERE; } @@ -548,7 +549,7 @@ static int32_t sdbDeleteHash(SSdbTable *pTable, SSWriteMsg *pWrite) { atomic_sub_fetch_32(&pTable->numOfRows, 1); - sdbDebug("vgId:1, sdb:%s, delete key:%s from hash, numOfRows:%" PRId64 ", msg:%p", pTable->tableName, + sdbDebug("vgId:1, sdb:%s, delete key:%s from hash, numOfRows:%" PRId64 ", msg:%p", pTable->name, sdbGetRowStr(pTable, pWrite->pRow), pTable->numOfRows, pWrite->pMsg); sdbDecRef(pTable, pWrite->pRow); @@ -557,7 +558,7 @@ static int32_t sdbDeleteHash(SSdbTable *pTable, SSWriteMsg *pWrite) { } static int32_t sdbUpdateHash(SSdbTable *pTable, SSWriteMsg *pWrite) { - sdbDebug("vgId:1, sdb:%s, update key:%s in hash, numOfRows:%" PRId64 ", msg:%p", pTable->tableName, + sdbDebug("vgId:1, sdb:%s, update key:%s in hash, numOfRows:%" PRId64 ", msg:%p", pTable->name, sdbGetRowStr(pTable, pWrite->pRow), pTable->numOfRows, pWrite->pMsg); (*pTable->fpUpdate)(pWrite); @@ -584,12 +585,12 @@ static int sdbWrite(void *wparam, void *hparam, int32_t qtype, void *unused) { if (pHead->version <= tsSdbMgmt.version) { pthread_mutex_unlock(&tsSdbMgmt.mutex); sdbDebug("vgId:1, sdb:%s, failed to restore %s key:%s from source(%d), hver:%" PRIu64 " too large, mver:%" PRIu64, - pTable->tableName, actStr[action], sdbGetKeyStr(pTable, pHead->cont), qtype, pHead->version, tsSdbMgmt.version); + pTable->name, actStr[action], sdbGetKeyStr(pTable, pHead->cont), qtype, pHead->version, tsSdbMgmt.version); return TSDB_CODE_SUCCESS; } else if (pHead->version != tsSdbMgmt.version + 1) { pthread_mutex_unlock(&tsSdbMgmt.mutex); sdbError("vgId:1, sdb:%s, failed to restore %s key:%s from source(%d), hver:%" PRIu64 " too large, mver:%" PRIu64, - pTable->tableName, actStr[action], sdbGetKeyStr(pTable, pHead->cont), qtype, pHead->version, tsSdbMgmt.version); + pTable->name, actStr[action], sdbGetKeyStr(pTable, pHead->cont), qtype, pHead->version, tsSdbMgmt.version); return TSDB_CODE_SYN_INVALID_VERSION; } else { tsSdbMgmt.version = pHead->version; @@ -612,19 +613,19 @@ static int sdbWrite(void *wparam, void *hparam, int32_t qtype, void *unused) { if (syncCode <= 0) pWrite->processedCount = 1; if (syncCode < 0) { - sdbError("vgId:1, sdb:%s, failed to forward req since %s action:%s key:%s hver:%" PRIu64 ", msg:%p", pTable->tableName, + sdbError("vgId:1, sdb:%s, failed to forward req since %s action:%s key:%s hver:%" PRIu64 ", msg:%p", pTable->name, tstrerror(syncCode), actStr[action], sdbGetKeyStr(pTable, pHead->cont), pHead->version, pWrite->pMsg); } else if (syncCode > 0) { - sdbDebug("vgId:1, sdb:%s, forward req is sent, action:%s key:%s hver:%" PRIu64 ", msg:%p", pTable->tableName, + sdbDebug("vgId:1, sdb:%s, forward req is sent, action:%s key:%s hver:%" PRIu64 ", msg:%p", pTable->name, actStr[action], sdbGetKeyStr(pTable, pHead->cont), pHead->version, pWrite->pMsg); } else { - sdbTrace("vgId:1, sdb:%s, no need to send fwd req, action:%s key:%s hver:%" PRIu64 ", msg:%p", pTable->tableName, + sdbTrace("vgId:1, sdb:%s, no need to send fwd req, action:%s key:%s hver:%" PRIu64 ", msg:%p", pTable->name, actStr[action], sdbGetKeyStr(pTable, pHead->cont), pHead->version, pWrite->pMsg); } return syncCode; } - sdbDebug("vgId:1, sdb:%s, record from wal/fwd is disposed, action:%s key:%s hver:%" PRIu64, pTable->tableName, + sdbDebug("vgId:1, sdb:%s, record from wal/fwd is disposed, action:%s key:%s hver:%" PRIu64, pTable->name, actStr[action], sdbGetKeyStr(pTable, pHead->cont), pHead->version); // even it is WAL/FWD, it shall be called to update version in sync @@ -638,7 +639,7 @@ static int sdbWrite(void *wparam, void *hparam, int32_t qtype, void *unused) { } else if (action == SDB_ACTION_DELETE) { void *pRow = sdbGetRowMeta(pTable, pHead->cont); if (pRow == NULL) { - sdbDebug("vgId:1, sdb:%s, object:%s not exist in hash, ignore delete action", pTable->tableName, + sdbDebug("vgId:1, sdb:%s, object:%s not exist in hash, ignore delete action", pTable->name, sdbGetKeyStr(pTable, pHead->cont)); return TSDB_CODE_SUCCESS; } @@ -647,7 +648,7 @@ static int sdbWrite(void *wparam, void *hparam, int32_t qtype, void *unused) { } else if (action == SDB_ACTION_UPDATE) { void *pRow = sdbGetRowMeta(pTable, pHead->cont); if (pRow == NULL) { - sdbDebug("vgId:1, sdb:%s, object:%s not exist in hash, ignore update action", pTable->tableName, + sdbDebug("vgId:1, sdb:%s, object:%s not exist in hash, ignore update action", pTable->name, sdbGetKeyStr(pTable, pHead->cont)); return TSDB_CODE_SUCCESS; } @@ -664,7 +665,7 @@ int32_t sdbInsertRow(SSWriteMsg *pWrite) { if (pTable == NULL) return TSDB_CODE_MND_SDB_INVALID_TABLE_TYPE; if (sdbGetRowFromObj(pTable, pWrite->pRow)) { - sdbError("vgId:1, sdb:%s, failed to insert key:%s, already exist", pTable->tableName, + sdbError("vgId:1, sdb:%s, failed to insert key:%s since it already exist", pTable->name, sdbGetRowStr(pTable, pWrite->pRow)); sdbDecRef(pTable, pWrite->pRow); return TSDB_CODE_MND_SDB_OBJ_ALREADY_THERE; @@ -674,14 +675,14 @@ int32_t sdbInsertRow(SSWriteMsg *pWrite) { *((uint32_t *)pWrite->pRow) = atomic_add_fetch_32(&pTable->autoIndex, 1); // let vgId increase from 2 - if (pTable->autoIndex == 1 && strcmp(pTable->tableName, "vgroups") == 0) { + if (pTable->autoIndex == 1 && strcmp(pTable->name, "vgroups") == 0) { *((uint32_t *)pWrite->pRow) = atomic_add_fetch_32(&pTable->autoIndex, 1); } } int32_t code = sdbInsertHash(pTable, pWrite); if (code != TSDB_CODE_SUCCESS) { - sdbError("vgId:1, sdb:%s, failed to insert into hash", pTable->tableName); + sdbError("vgId:1, sdb:%s, failed to insert into hash", pTable->name); return code; } @@ -707,7 +708,7 @@ int32_t sdbInsertRowImp(SSWriteMsg *pWrite) { SWalHead *pHead = (SWalHead *)((char *)pNewWrite + sizeof(SSWriteMsg) + SDB_SYNC_HACK); pHead->version = 0; pHead->len = pWrite->rowSize; - pHead->msgType = pTable->tableId * 10 + SDB_ACTION_INSERT; + pHead->msgType = pTable->id * 10 + SDB_ACTION_INSERT; pWrite->rowData = pHead->cont; (*pTable->fpEncode)(pWrite); @@ -717,7 +718,7 @@ int32_t sdbInsertRowImp(SSWriteMsg *pWrite) { if (pNewWrite->pMsg != NULL) { sdbDebug("vgId:1, ahandle:%p msg:%p, sdb:%s row:%p:%s, insert action is add to sdb queue", pNewWrite->pMsg->rpcMsg.ahandle, - pNewWrite->pMsg, pTable->tableName, pWrite->pRow, sdbGetRowStr(pTable, pWrite->pRow)); + pNewWrite->pMsg, pTable->name, pWrite->pRow, sdbGetRowStr(pTable, pWrite->pRow)); } sdbIncRef(pNewWrite->pTable, pNewWrite->pRow); @@ -740,7 +741,7 @@ int32_t sdbDeleteRow(SSWriteMsg *pWrite) { void *pRow = sdbGetRowMetaFromObj(pTable, pWrite->pRow); if (pRow == NULL) { - sdbDebug("vgId:1, sdb:%s, record is not there, delete failed", pTable->tableName); + sdbDebug("vgId:1, sdb:%s, record is not there, delete failed", pTable->name); return TSDB_CODE_MND_SDB_OBJ_NOT_THERE; } @@ -748,7 +749,7 @@ int32_t sdbDeleteRow(SSWriteMsg *pWrite) { int32_t code = sdbDeleteHash(pTable, pWrite); if (code != TSDB_CODE_SUCCESS) { - sdbError("vgId:1, sdb:%s, failed to delete from hash", pTable->tableName); + sdbError("vgId:1, sdb:%s, failed to delete from hash", pTable->name); sdbDecRef(pTable, pWrite->pRow); return code; } @@ -775,7 +776,7 @@ int32_t sdbDeleteRowImp(SSWriteMsg *pWrite) { SWalHead *pHead = (SWalHead *)((void *)pNewWrite + sizeof(SSWriteMsg) + SDB_SYNC_HACK); pHead->version = 0; - pHead->msgType = pTable->tableId * 10 + SDB_ACTION_DELETE; + pHead->msgType = pTable->id * 10 + SDB_ACTION_DELETE; pWrite->rowData = pHead->cont; (*pTable->fpEncode)(pWrite); @@ -785,7 +786,7 @@ int32_t sdbDeleteRowImp(SSWriteMsg *pWrite) { if (pNewWrite->pMsg != NULL) { sdbDebug("vgId:1, ahandle:%p msg:%p, sdb:%s row:%p:%s, delete action is add to sdb queue", pNewWrite->pMsg->rpcMsg.ahandle, - pNewWrite->pMsg, pTable->tableName, pWrite->pRow, sdbGetRowStr(pTable, pWrite->pRow)); + pNewWrite->pMsg, pTable->name, pWrite->pRow, sdbGetRowStr(pTable, pWrite->pRow)); } taosWriteQitem(tsSdbWQueue, TAOS_QTYPE_RPC, pNewWrite); @@ -799,13 +800,13 @@ int32_t sdbUpdateRow(SSWriteMsg *pWrite) { void *pRow = sdbGetRowMetaFromObj(pTable, pWrite->pRow); if (pRow == NULL) { - sdbDebug("vgId:1, sdb:%s, record is not there, update failed", pTable->tableName); + sdbDebug("vgId:1, sdb:%s, record is not there, update failed", pTable->name); return TSDB_CODE_MND_SDB_OBJ_NOT_THERE; } int32_t code = sdbUpdateHash(pTable, pWrite); if (code != TSDB_CODE_SUCCESS) { - sdbError("vgId:1, sdb:%s, failed to update hash", pTable->tableName); + sdbError("vgId:1, sdb:%s, failed to update hash", pTable->name); return code; } @@ -830,7 +831,7 @@ int32_t sdbUpdateRowImp(SSWriteMsg *pWrite) { SWalHead *pHead = (SWalHead *)((void *)pNewWrite + sizeof(SSWriteMsg) + SDB_SYNC_HACK); pHead->version = 0; - pHead->msgType = pTable->tableId * 10 + SDB_ACTION_UPDATE; + pHead->msgType = pTable->id * 10 + SDB_ACTION_UPDATE; pWrite->rowData = pHead->cont; (*pTable->fpEncode)(pWrite); @@ -840,7 +841,7 @@ int32_t sdbUpdateRowImp(SSWriteMsg *pWrite) { if (pNewWrite->pMsg != NULL) { sdbDebug("vgId:1, ahandle:%p msg:%p, sdb:%s row:%p:%s, update action is add to sdb queue", pNewWrite->pMsg->rpcMsg.ahandle, - pNewWrite->pMsg, pTable->tableName, pWrite->pRow, sdbGetRowStr(pTable, pWrite->pRow)); + pNewWrite->pMsg, pTable->name, pWrite->pRow, sdbGetRowStr(pTable, pWrite->pRow)); } sdbIncRef(pNewWrite->pTable, pNewWrite->pRow); @@ -888,9 +889,9 @@ void *sdbOpenTable(SSdbTableDesc *pDesc) { if (pTable == NULL) return NULL; pthread_mutex_init(&pTable->mutex, NULL); - tstrncpy(pTable->tableName, pDesc->tableName, SDB_TABLE_LEN); + tstrncpy(pTable->name, pDesc->name, SDB_TABLE_LEN); pTable->keyType = pDesc->keyType; - pTable->tableId = pDesc->tableId; + pTable->id = pDesc->id; pTable->hashSessions = pDesc->hashSessions; pTable->maxRowSize = pDesc->maxRowSize; pTable->refCountPos = pDesc->refCountPos; @@ -909,7 +910,7 @@ void *sdbOpenTable(SSdbTableDesc *pDesc) { pTable->iHandle = taosHashInit(pTable->hashSessions, hashFp, true, true); tsSdbMgmt.numOfTables++; - tsSdbMgmt.tableList[pTable->tableId] = pTable; + tsSdbMgmt.tableList[pTable->id] = pTable; return pTable; } @@ -918,7 +919,7 @@ void sdbCloseTable(void *handle) { if (pTable == NULL) return; tsSdbMgmt.numOfTables--; - tsSdbMgmt.tableList[pTable->tableId] = NULL; + tsSdbMgmt.tableList[pTable->id] = NULL; SHashMutableIterator *pIter = taosHashCreateIter(pTable->iHandle); while (taosHashIterNext(pIter)) { @@ -937,7 +938,7 @@ void sdbCloseTable(void *handle) { taosHashCleanup(pTable->iHandle); pthread_mutex_destroy(&pTable->mutex); - sdbDebug("vgId:1, sdb:%s, is closed, numOfTables:%d", pTable->tableName, tsSdbMgmt.numOfTables); + sdbDebug("vgId:1, sdb:%s, is closed, numOfTables:%d", pTable->name, tsSdbMgmt.numOfTables); free(pTable); } @@ -1062,7 +1063,7 @@ static void *sdbWorkerFp(void *pWorker) { pHead = (void *)pWrite + sizeof(SSWriteMsg) + SDB_SYNC_HACK; if (pWrite->pMsg != NULL) { sdbDebug("vgId:1, ahandle:%p msg:%p, sdb:%s row:%p:%s hver:%" PRIu64 ", will be processed in sdb queue", - pWrite->pMsg->rpcMsg.ahandle, pWrite->pMsg, pWrite->pTable->tableName, pWrite->pRow, + pWrite->pMsg->rpcMsg.ahandle, pWrite->pMsg, pWrite->pTable->name, pWrite->pRow, sdbGetKeyStr(pWrite->pTable, pHead->cont), pHead->version); } } else { diff --git a/src/mnode/src/mnodeTable.c b/src/mnode/src/mnodeTable.c index ce9f652330..a90b573576 100644 --- a/src/mnode/src/mnodeTable.c +++ b/src/mnode/src/mnodeTable.c @@ -352,8 +352,8 @@ static int32_t mnodeInitChildTables() { tsChildTableUpdateSize = (int8_t *)tObj.updateEnd - (int8_t *)&tObj.info.type; SSdbTableDesc tableDesc = { - .tableId = SDB_TABLE_CTABLE, - .tableName = "ctables", + .id = SDB_TABLE_CTABLE, + .name = "ctables", .hashSessions = TSDB_DEFAULT_CTABLES_HASH_SIZE, .maxRowSize = sizeof(SCTableObj) + sizeof(SSchema) * (TSDB_MAX_TAGS + TSDB_MAX_COLUMNS + 16) + TSDB_TABLE_FNAME_LEN + TSDB_CQ_SQL_SIZE, .refCountPos = (int8_t *)(&tObj.refCount) - (int8_t *)&tObj, @@ -545,8 +545,8 @@ static int32_t mnodeInitSuperTables() { tsSuperTableUpdateSize = (int8_t *)tObj.updateEnd - (int8_t *)&tObj.info.type; SSdbTableDesc tableDesc = { - .tableId = SDB_TABLE_STABLE, - .tableName = "stables", + .id = SDB_TABLE_STABLE, + .name = "stables", .hashSessions = TSDB_DEFAULT_STABLES_HASH_SIZE, .maxRowSize = sizeof(SSTableObj) + sizeof(SSchema) * (TSDB_MAX_TAGS + TSDB_MAX_COLUMNS + 16) + TSDB_TABLE_FNAME_LEN, .refCountPos = (int8_t *)(&tObj.refCount) - (int8_t *)&tObj, diff --git a/src/mnode/src/mnodeUser.c b/src/mnode/src/mnodeUser.c index edb15fb778..9de14dbfd1 100644 --- a/src/mnode/src/mnodeUser.c +++ b/src/mnode/src/mnodeUser.c @@ -150,9 +150,9 @@ int32_t mnodeInitUsers() { SUserObj tObj; tsUserUpdateSize = (int8_t *)tObj.updateEnd - (int8_t *)&tObj; - SSdbTableDesc tableDesc = { - .tableId = SDB_TABLE_USER, - .tableName = "users", + SSdbTableDesc desc = { + .id = SDB_TABLE_USER, + .name = "users", .hashSessions = TSDB_DEFAULT_USERS_HASH_SIZE, .maxRowSize = tsUserUpdateSize, .refCountPos = (int8_t *)(&tObj.refCount) - (int8_t *)&tObj, @@ -166,9 +166,9 @@ int32_t mnodeInitUsers() { .fpRestored = mnodeUserActionRestored }; - tsUserSdb = sdbOpenTable(&tableDesc); + tsUserSdb = sdbOpenTable(&desc); if (tsUserSdb == NULL) { - mError("table:%s, failed to create hash", tableDesc.tableName); + mError("table:%s, failed to create hash", desc.name); return -1; } @@ -179,7 +179,7 @@ int32_t mnodeInitUsers() { mnodeAddShowRetrieveHandle(TSDB_MGMT_TABLE_USER, mnodeRetrieveUsers); mnodeAddPeerMsgHandle(TSDB_MSG_TYPE_DM_AUTH, mnodeProcessAuthMsg); - mDebug("table:%s, hash is created", tableDesc.tableName); + mDebug("table:%s, hash is created", desc.name); return 0; } diff --git a/src/mnode/src/mnodeVgroup.c b/src/mnode/src/mnodeVgroup.c index c12d2057f8..2f0caea57a 100644 --- a/src/mnode/src/mnodeVgroup.c +++ b/src/mnode/src/mnodeVgroup.c @@ -206,9 +206,9 @@ int32_t mnodeInitVgroups() { SVgObj tObj; tsVgUpdateSize = (int8_t *)tObj.updateEnd - (int8_t *)&tObj; - SSdbTableDesc tableDesc = { - .tableId = SDB_TABLE_VGROUP, - .tableName = "vgroups", + SSdbTableDesc desc = { + .id = SDB_TABLE_VGROUP, + .name = "vgroups", .hashSessions = TSDB_DEFAULT_VGROUPS_HASH_SIZE, .maxRowSize = tsVgUpdateSize, .refCountPos = (int8_t *)(&tObj.refCount) - (int8_t *)&tObj, @@ -222,7 +222,7 @@ int32_t mnodeInitVgroups() { .fpRestored = mnodeVgroupActionRestored, }; - tsVgroupSdb = sdbOpenTable(&tableDesc); + tsVgroupSdb = sdbOpenTable(&desc); if (tsVgroupSdb == NULL) { mError("failed to init vgroups data"); return -1; From 2171bf7a15dfcc9e96520b72df80d99aac804a8a Mon Sep 17 00:00:00 2001 From: Shengliang Guan Date: Thu, 19 Nov 2020 08:39:16 +0000 Subject: [PATCH 08/13] TD-2157 --- src/sync/src/syncMain.c | 100 ++++++++++++++++++------------------- src/sync/src/syncRestore.c | 5 +- src/sync/src/taosTcpPool.c | 2 +- 3 files changed, 54 insertions(+), 53 deletions(-) diff --git a/src/sync/src/syncMain.c b/src/sync/src/syncMain.c index 895b1cd098..10ed9f6c27 100644 --- a/src/sync/src/syncMain.c +++ b/src/sync/src/syncMain.c @@ -341,12 +341,10 @@ int32_t syncReconfig(int64_t rid, const SSyncCfg *pNewCfg) { pthread_mutex_unlock(&(pNode->mutex)); - sInfo("vgId:%d, %d replicas are configured, quorum:%d role:%s", pNode->vgId, pNode->replica, pNode->quorum, - syncRole[nodeRole]); + sInfo("vgId:%d, %d replicas are configured, quorum:%d", pNode->vgId, pNode->replica, pNode->quorum); syncBroadcastStatus(pNode); taosReleaseRef(tsSyncRefId, rid); - return 0; } @@ -378,7 +376,7 @@ void syncConfirmForward(int64_t rid, uint64_t version, int32_t code) { pFwdRsp->code = code; int32_t msgLen = sizeof(SSyncHead) + sizeof(SFwdRsp); - int32_t retLen = write(pPeer->peerFd, msg, msgLen); + int32_t retLen = taosWriteMsg(pPeer->peerFd, msg, msgLen); if (retLen == msgLen) { sDebug("%s, forward-rsp is sent, code:%x hver:%" PRIu64, pPeer->id, code, version); @@ -391,6 +389,7 @@ void syncConfirmForward(int64_t rid, uint64_t version, int32_t code) { taosReleaseRef(tsSyncRefId, rid); } +#if 0 void syncRecover(int64_t rid) { SSyncPeer *pPeer; @@ -417,6 +416,7 @@ void syncRecover(int64_t rid) { taosReleaseRef(tsSyncRefId, rid); } +#endif int32_t syncGetNodesRole(int64_t rid, SNodesRole *pNodesRole) { SSyncNode *pNode = taosAcquireRef(tsSyncRefId, rid); @@ -532,7 +532,7 @@ static SSyncPeer *syncAddPeer(SSyncNode *pNode, const SNodeInfo *pInfo) { if (pPeer->nodeId == 0 || (ret > 0) || (ret == 0 && pPeer->port > tsSyncPort)) { int32_t checkMs = 100 + (pNode->vgId * 10) % 100; if (pNode->vgId > 1) checkMs = tsStatusInterval * 1000 + checkMs; - sDebug("%s, start to check peer connection after %d ms", pPeer->id, checkMs); + sDebug("%s, check peer connection after %d ms", pPeer->id, checkMs); taosTmrReset(syncCheckPeerConnection, checkMs, pPeer, tsSyncTmrCtrl, &pPeer->timer); } @@ -566,8 +566,6 @@ static void syncChooseMaster(SSyncNode *pNode) { int32_t index = -1; int32_t replica = pNode->replica; - sDebug("vgId:%d, choose master", pNode->vgId); - for (int32_t i = 0; i < pNode->replica; ++i) { if (pNode->peerInfo[i]->role != TAOS_SYNC_ROLE_OFFLINE) { onlineNum++; @@ -633,11 +631,11 @@ static void syncChooseMaster(SSyncNode *pNode) { static SSyncPeer *syncCheckMaster(SSyncNode *pNode) { int32_t onlineNum = 0; - int32_t index = -1; + int32_t masterIndex = -1; int32_t replica = pNode->replica; - for (int32_t i = 0; i < pNode->replica; ++i) { - if (pNode->peerInfo[i]->role != TAOS_SYNC_ROLE_OFFLINE) { + for (int32_t index = 0; index < pNode->replica; ++index) { + if (pNode->peerInfo[index]->role != TAOS_SYNC_ROLE_OFFLINE) { onlineNum++; } } @@ -652,18 +650,17 @@ static SSyncPeer *syncCheckMaster(SSyncNode *pNode) { if (onlineNum <= replica * 0.5) { if (nodeRole != TAOS_SYNC_ROLE_UNSYNCED) { nodeRole = TAOS_SYNC_ROLE_UNSYNCED; - // pNode->peerInfo[pNode->selfIndex]->role = nodeRole; (*pNode->notifyRole)(pNode->ahandle, nodeRole); - sInfo("vgId:%d, change to unsynced state, online:%d replica:%d", pNode->vgId, onlineNum, replica); + sInfo("vgId:%d, self change to unsynced state, online:%d replica:%d", pNode->vgId, onlineNum, replica); } } else { - for (int32_t i = 0; i < pNode->replica; ++i) { - SSyncPeer *pTemp = pNode->peerInfo[i]; + for (int32_t index = 0; index < pNode->replica; ++index) { + SSyncPeer *pTemp = pNode->peerInfo[index]; if (pTemp->role != TAOS_SYNC_ROLE_MASTER) continue; - if (index < 0) { - index = i; + if (masterIndex < 0) { + masterIndex = index; } else { // multiple masters, it shall not happen - if (i == pNode->selfIndex) { + if (masterIndex == pNode->selfIndex) { sError("%s, peer is master, work as slave instead", pTemp->id); nodeRole = TAOS_SYNC_ROLE_SLAVE; (*pNode->notifyRole)(pNode->ahandle, nodeRole); @@ -672,77 +669,80 @@ static SSyncPeer *syncCheckMaster(SSyncNode *pNode) { } } - SSyncPeer *pMaster = (index >= 0) ? pNode->peerInfo[index] : NULL; + SSyncPeer *pMaster = (masterIndex >= 0) ? pNode->peerInfo[masterIndex] : NULL; return pMaster; } static int32_t syncValidateMaster(SSyncPeer *pPeer) { SSyncNode *pNode = pPeer->pSyncNode; - int32_t code = 0; + int32_t code = 0; if (nodeRole == TAOS_SYNC_ROLE_MASTER && nodeVersion < pPeer->version) { - sDebug("%s, slave has higher version, restart all connections!!!", pPeer->id); + sDebug("%s, peer has higher sver:%" PRIu64 ", restart all peer connections", pPeer->id, pPeer->version); nodeRole = TAOS_SYNC_ROLE_UNSYNCED; (*pNode->notifyRole)(pNode->ahandle, nodeRole); code = -1; - for (int32_t i = 0; i < pNode->replica; ++i) { - if (i == pNode->selfIndex) continue; - syncRestartPeer(pNode->peerInfo[i]); + for (int32_t index = 0; index < pNode->replica; ++index) { + if (index == pNode->selfIndex) continue; + syncRestartPeer(pNode->peerInfo[index]); } } return code; } -static void syncCheckRole(SSyncPeer *pPeer, SPeerStatus peersStatus[], int8_t newRole) { +static void syncCheckRole(SSyncPeer *pPeer, SPeerStatus* peersStatus, int8_t newPeerRole) { SSyncNode *pNode = pPeer->pSyncNode; - int8_t peerOldRole = pPeer->role; - int8_t selfOldRole = nodeRole; - int8_t i, syncRequired = 0; + int8_t oldPeerRole = pPeer->role; + int8_t oldSelfRole = nodeRole; + int8_t syncRequired = 0; - // pNode->peerInfo[pNode->selfIndex]->version = nodeVersion; - pPeer->role = newRole; - - sDebug("%s, own role:%s, new peer role:%s", pPeer->id, syncRole[nodeRole], syncRole[pPeer->role]); + pPeer->role = newPeerRole; + sTrace("%s, peer role:%s change to %s", pPeer->id, syncRole[oldPeerRole], syncRole[newPeerRole]); SSyncPeer *pMaster = syncCheckMaster(pNode); if (pMaster) { // master is there pNode->pMaster = pMaster; - sDebug("%s, it is the master, sver:%" PRIu64, pMaster->id, pMaster->version); + sTrace("%s, it is the master, sver:%" PRIu64, pMaster->id, pMaster->version); if (syncValidateMaster(pPeer) < 0) return; if (nodeRole == TAOS_SYNC_ROLE_UNSYNCED) { if (nodeVersion < pMaster->version) { + sTrace("%s, is master, sync required, self sver:%" PRIu64, pMaster->id, nodeVersion); syncRequired = 1; } else { - sInfo("%s is master, work as slave, sver:%" PRIu64, pMaster->id, pMaster->version); + sInfo("%s, is master, work as slave, self sver:%" PRIu64, pMaster->id, nodeVersion); nodeRole = TAOS_SYNC_ROLE_SLAVE; (*pNode->notifyRole)(pNode->ahandle, nodeRole); } } else if (nodeRole == TAOS_SYNC_ROLE_SLAVE && pMaster == pPeer) { - // nodeVersion = pMaster->version; + sTrace("%s, is master, continue work as slave, self sver:%" PRIu64, pMaster->id, nodeVersion); } } else { // master not there, if all peer's state and version are consistent, choose the master int32_t consistent = 0; - if (peersStatus) { - for (i = 0; i < pNode->replica; ++i) { - SSyncPeer *pTemp = pNode->peerInfo[i]; - if (pTemp->role != peersStatus[i].role) break; - if ((pTemp->role != TAOS_SYNC_ROLE_OFFLINE) && (pTemp->version != peersStatus[i].version)) break; + int32_t index = 0; + if (peersStatus != NULL) { + for (index = 0; index < pNode->replica; ++index) { + SSyncPeer *pTemp = pNode->peerInfo[index]; + if (pTemp->role != peersStatus[index].role) break; + if ((pTemp->role != TAOS_SYNC_ROLE_OFFLINE) && (pTemp->version != peersStatus[index].version)) break; } - if (i >= pNode->replica) consistent = 1; + if (index >= pNode->replica) consistent = 1; } else { if (pNode->replica == 2) consistent = 1; } if (consistent) { + sTrace("vgId:%d, choose master", pNode->vgId); syncChooseMaster(pNode); + } else { + sTrace("vgId:%d, version inconsistent, cannot choose master", pNode->vgId); } } @@ -750,7 +750,8 @@ static void syncCheckRole(SSyncPeer *pPeer, SPeerStatus peersStatus[], int8_t ne syncRecoverFromMaster(pMaster); } - if (peerOldRole != newRole || nodeRole != selfOldRole) { + if (oldPeerRole != newPeerRole || nodeRole != oldSelfRole) { + sDebug("vgId:%d, roles changed, broadcast status", pNode->vgId); syncBroadcastStatus(pNode); } @@ -760,7 +761,7 @@ static void syncCheckRole(SSyncPeer *pPeer, SPeerStatus peersStatus[], int8_t ne } static void syncRestartPeer(SSyncPeer *pPeer) { - sDebug("%s, restart connection", pPeer->id); + sDebug("%s, restart peer connection", pPeer->id); syncClosePeerConn(pPeer); @@ -768,6 +769,7 @@ static void syncRestartPeer(SSyncPeer *pPeer) { int32_t ret = strcmp(pPeer->fqdn, tsNodeFqdn); if (ret > 0 || (ret == 0 && pPeer->port > tsSyncPort)) { + sDebug("%s, check peer connection in 1000 ms", pPeer->id); taosTmrReset(syncCheckPeerConnection, tsSyncTimer * 1000, pPeer, tsSyncTmrCtrl, &pPeer->timer); } } @@ -862,7 +864,7 @@ static void syncRecoverFromMaster(SSyncPeer *pPeer) { firstPkt.port = tsSyncPort; taosTmrReset(syncNotStarted, tsSyncTimer * 1000, pPeer, tsSyncTmrCtrl, &pPeer->timer); - if (write(pPeer->peerFd, &firstPkt, sizeof(firstPkt)) != sizeof(firstPkt)) { + if (taosWriteMsg(pPeer->peerFd, &firstPkt, sizeof(firstPkt)) != sizeof(firstPkt)) { sError("%s, failed to send sync-req to peer", pPeer->id); } else { nodeSStatus = TAOS_SYNC_STATUS_START; @@ -1001,7 +1003,7 @@ static void syncSendPeersStatusMsgToPeer(SSyncPeer *pPeer, char ack, int8_t type pPeersStatus->peersStatus[i].version = pNode->peerInfo[i]->version; } - int32_t retLen = write(pPeer->peerFd, msg, statusMsgLen); + int32_t retLen = taosWriteMsg(pPeer->peerFd, msg, statusMsgLen); if (retLen == statusMsgLen) { sDebug("%s, status msg is sent, self:%s sver:%" PRIu64 ", ack:%d tranId:%u type:%s", pPeer->id, syncRole[pPeersStatus->role], pPeersStatus->version, pPeersStatus->ack, pPeersStatus->tranId, statusType[pPeersStatus->type]); @@ -1009,8 +1011,6 @@ static void syncSendPeersStatusMsgToPeer(SSyncPeer *pPeer, char ack, int8_t type sDebug("%s, failed to send status msg, restart", pPeer->id); syncRestartConnection(pPeer); } - - return; } static void syncSetupPeerConnection(SSyncPeer *pPeer) { @@ -1025,7 +1025,7 @@ static void syncSetupPeerConnection(SSyncPeer *pPeer) { int32_t connFd = taosOpenTcpClientSocket(pPeer->ip, pPeer->port, 0); if (connFd < 0) { - sDebug("%s, failed to open tcp socket(%s)", pPeer->id, strerror(errno)); + sDebug("%s, failed to open tcp socket since %s", pPeer->id, strerror(errno)); taosTmrReset(syncCheckPeerConnection, tsSyncTimer * 1000, pPeer, tsSyncTmrCtrl, &pPeer->timer); return; } @@ -1038,15 +1038,15 @@ static void syncSetupPeerConnection(SSyncPeer *pPeer) { firstPkt.port = tsSyncPort; firstPkt.sourceId = pNode->vgId; // tell arbitrator its vgId - if (write(connFd, &firstPkt, sizeof(firstPkt)) == sizeof(firstPkt)) { + if (taosWriteMsg(connFd, &firstPkt, sizeof(firstPkt)) == sizeof(firstPkt)) { sDebug("%s, connection to peer server is setup", pPeer->id); pPeer->peerFd = connFd; pPeer->role = TAOS_SYNC_ROLE_UNSYNCED; pPeer->pConn = taosAllocateTcpConn(tsTcpPool, pPeer, connFd); syncAddPeerRef(pPeer); } else { - sDebug("try later"); - close(connFd); + sDebug("%s, failed to setup peer connection to server since %s, try later", pPeer->id, strerror(errno)); + taosClose(connFd); taosTmrReset(syncCheckPeerConnection, tsSyncTimer * 1000, pPeer, tsSyncTmrCtrl, &pPeer->timer); } } diff --git a/src/sync/src/syncRestore.c b/src/sync/src/syncRestore.c index 33bd96ebb3..393b6b09b1 100644 --- a/src/sync/src/syncRestore.c +++ b/src/sync/src/syncRestore.c @@ -291,7 +291,7 @@ static int32_t syncRestoreDataStepByStep(SSyncPeer *pPeer) { } void *syncRestoreData(void *param) { - SSyncPeer *pPeer = (SSyncPeer *)param; + SSyncPeer *pPeer = param; SSyncNode *pNode = pPeer->pSyncNode; taosBlockSIGPIPE(); @@ -300,7 +300,8 @@ void *syncRestoreData(void *param) { (*pNode->notifyRole)(pNode->ahandle, TAOS_SYNC_ROLE_SYNCING); if (syncOpenRecvBuffer(pNode) < 0) { - sError("%s, failed to allocate recv buffer", pPeer->id); + sError("%s, failed to allocate recv buffer, restart connection", pPeer->id); + syncRestartConnection(pPeer); } else { if (syncRestoreDataStepByStep(pPeer) == 0) { sInfo("%s, it is synced successfully", pPeer->id); diff --git a/src/sync/src/taosTcpPool.c b/src/sync/src/taosTcpPool.c index 875528e66b..d1d9815f4a 100644 --- a/src/sync/src/taosTcpPool.c +++ b/src/sync/src/taosTcpPool.c @@ -150,7 +150,7 @@ void *taosAllocateTcpConn(void *param, void *pPeer, int32_t connFd) { } void taosFreeTcpConn(void *param) { - SConnObj * pConn = (SConnObj *)param; + SConnObj * pConn = param; SThreadObj *pThread = pConn->pThread; sDebug("%p TCP connection will be closed, fd:%d", pThread, pConn->fd); From a82d594a81b9efb54153921193f6b66e565a7250 Mon Sep 17 00:00:00 2001 From: Shengliang Guan Date: Thu, 19 Nov 2020 09:48:48 +0000 Subject: [PATCH 09/13] TD-2157 --- src/inc/tsync.h | 18 ++++++------- src/sync/inc/syncInt.h | 30 ++++++++++++--------- src/sync/src/syncMain.c | 59 +++++++++++++++++++++++++++++++---------- 3 files changed, 71 insertions(+), 36 deletions(-) diff --git a/src/inc/tsync.h b/src/inc/tsync.h index d57433eba9..967b254992 100644 --- a/src/inc/tsync.h +++ b/src/inc/tsync.h @@ -24,18 +24,18 @@ extern "C" { #define TAOS_SYNC_MAX_INDEX 0x7FFFFFFF typedef enum _TAOS_SYNC_ROLE { - TAOS_SYNC_ROLE_OFFLINE, - TAOS_SYNC_ROLE_UNSYNCED, - TAOS_SYNC_ROLE_SYNCING, - TAOS_SYNC_ROLE_SLAVE, - TAOS_SYNC_ROLE_MASTER, + TAOS_SYNC_ROLE_OFFLINE = 0, + TAOS_SYNC_ROLE_UNSYNCED = 1, + TAOS_SYNC_ROLE_SYNCING = 2, + TAOS_SYNC_ROLE_SLAVE = 3, + TAOS_SYNC_ROLE_MASTER = 4 } ESyncRole; typedef enum _TAOS_SYNC_STATUS { - TAOS_SYNC_STATUS_INIT, - TAOS_SYNC_STATUS_START, - TAOS_SYNC_STATUS_FILE, - TAOS_SYNC_STATUS_CACHE, + TAOS_SYNC_STATUS_INIT = 0, + TAOS_SYNC_STATUS_START = 1, + TAOS_SYNC_STATUS_FILE = 2, + TAOS_SYNC_STATUS_CACHE = 3 } ESyncStatus; typedef struct { diff --git a/src/sync/inc/syncInt.h b/src/sync/inc/syncInt.h index 666a90c3cb..7d846ebc80 100644 --- a/src/sync/inc/syncInt.h +++ b/src/sync/inc/syncInt.h @@ -27,16 +27,20 @@ extern "C" { #define sDebug(...) { if (sDebugFlag & DEBUG_DEBUG) { taosPrintLog("SYN ", sDebugFlag, __VA_ARGS__); }} #define sTrace(...) { if (sDebugFlag & DEBUG_TRACE) { taosPrintLog("SYN ", sDebugFlag, __VA_ARGS__); }} -#define TAOS_SMSG_SYNC_DATA 1 -#define TAOS_SMSG_FORWARD 2 -#define TAOS_SMSG_FORWARD_RSP 3 -#define TAOS_SMSG_SYNC_REQ 4 -#define TAOS_SMSG_SYNC_RSP 5 -#define TAOS_SMSG_SYNC_MUST 6 -#define TAOS_SMSG_STATUS 7 +typedef enum { + TAOS_SMSG_SYNC_DATA = 1, + TAOS_SMSG_FORWARD = 2, + TAOS_SMSG_FORWARD_RSP = 3, + TAOS_SMSG_SYNC_REQ = 4, + TAOS_SMSG_SYNC_RSP = 5, + TAOS_SMSG_SYNC_MUST = 6, + TAOS_SMSG_STATUS = 7 +} ESyncMsgType; #define SYNC_MAX_SIZE (TSDB_MAX_WAL_SIZE + sizeof(SWalHead) + sizeof(SSyncHead) + 16) #define SYNC_RECV_BUFFER_SIZE (5*1024*1024) +#define SYNC_FWD_TIMER 300 +#define SYNC_ROLE_TIMER 10000 #define nodeRole pNode->peerInfo[pNode->selfIndex]->role #define nodeVersion pNode->peerInfo[pNode->selfIndex]->version @@ -123,12 +127,12 @@ typedef struct SsyncPeer { int32_t nodeId; uint32_t ip; uint16_t port; + int8_t role; + int8_t sstatus; // sync status char fqdn[TSDB_FQDN_LEN]; // peer ip string char id[TSDB_EP_LEN + 32]; // peer vgId + end point - int8_t role; - int8_t sstatus; // sync status uint64_t version; - uint64_t sversion; // track the peer version in retrieve process + uint64_t sversion; // track the peer version in retrieve process int32_t syncFd; int32_t peerFd; // forward FD int32_t numOfRetrieves; // number of retrieves tried @@ -138,7 +142,7 @@ typedef struct SsyncPeer { int32_t notifyFd; int32_t watchNum; int32_t *watchFd; - int8_t refCount; // reference count + int32_t refCount; // reference count struct SSyncNode *pSyncNode; } SSyncPeer; @@ -146,16 +150,16 @@ typedef struct SSyncNode { char path[TSDB_FILENAME_LEN]; int8_t replica; int8_t quorum; + int8_t selfIndex; uint32_t vgId; int64_t rid; void *ahandle; - int8_t selfIndex; SSyncPeer *peerInfo[TAOS_SYNC_MAX_REPLICA+1]; // extra one for arbitrator SSyncPeer *pMaster; - int8_t refCount; SRecvBuffer *pRecv; SSyncFwds *pSyncFwds; // saved forward info if quorum >1 void *pFwdTimer; + void *pRoleTimer; FGetFileInfo getFileInfo; FGetWalInfo getWalInfo; FWriteToCache writeToCache; diff --git a/src/sync/src/syncMain.c b/src/sync/src/syncMain.c index 10ed9f6c27..e7086626d6 100644 --- a/src/sync/src/syncMain.c +++ b/src/sync/src/syncMain.c @@ -59,6 +59,7 @@ static void syncAddArbitrator(SSyncNode *pNode); static void syncFreeNode(void *); static void syncRemoveConfirmedFwdInfo(SSyncNode *pNode); static void syncMonitorFwdInfos(void *param, void *tmrId); +static void syncMonitorNodeRole(void *param, void *tmrId); static void syncProcessFwdAck(SSyncNode *pNode, SFwdInfo *pFwdInfo, int32_t code); static void syncSaveFwdInfo(SSyncNode *pNode, uint64_t version, void *mhandle); static void syncRestartPeer(SSyncPeer *pPeer); @@ -79,7 +80,9 @@ typedef enum { SYNC_STATUS_SETUP_CONN, SYNC_STATUS_SETUP_CONN_RSP, SYNC_STATUS_EXCHANGE_DATA, - SYNC_STATUS_EXCHANGE_DATA_RSP + SYNC_STATUS_EXCHANGE_DATA_RSP, + SYNC_STATUS_CHECK_ROLE, + SYNC_STATUS_CHECK_ROLE_RSP } ESyncStatusType; char *statusType[] = { @@ -88,7 +91,9 @@ char *statusType[] = { "setup-conn", "setup-conn-rsp", "exchange-data", - "exchange-data-rsp" + "exchange-data-rsp", + "check-role", + "check-role-rsp" }; uint16_t syncGenTranId() { @@ -233,9 +238,16 @@ int64_t syncStart(const SSyncInfo *pInfo) { return -1; } - pNode->pFwdTimer = taosTmrStart(syncMonitorFwdInfos, 300, (void *)pNode->rid, tsSyncTmrCtrl); + pNode->pFwdTimer = taosTmrStart(syncMonitorFwdInfos, SYNC_FWD_TIMER, (void *)pNode->rid, tsSyncTmrCtrl); if (pNode->pFwdTimer == NULL) { - sError("vgId:%d, failed to allocate timer", pNode->vgId); + sError("vgId:%d, failed to allocate fwd timer", pNode->vgId); + syncStop(pNode->rid); + return -1; + } + + pNode->pRoleTimer = taosTmrStart(syncMonitorNodeRole, SYNC_ROLE_TIMER, (void *)pNode->rid, tsSyncTmrCtrl); + if (pNode->pRoleTimer == NULL) { + sError("vgId:%d, failed to allocate role timer", pNode->vgId); syncStop(pNode->rid); return -1; } @@ -262,6 +274,7 @@ void syncStop(int64_t rid) { if (tsVgIdHash) taosHashRemove(tsVgIdHash, (const char *)&pNode->vgId, sizeof(int32_t)); if (pNode->pFwdTimer) taosTmrStop(pNode->pFwdTimer); + if (pNode->pRoleTimer) taosTmrStop(pNode->pRoleTimer); for (int32_t i = 0; i < pNode->replica; ++i) { pPeer = pNode->peerInfo[i]; @@ -471,10 +484,10 @@ static void syncFreeNode(void *param) { tfree(pNode); } -void syncAddPeerRef(SSyncPeer *pPeer) { atomic_add_fetch_8(&pPeer->refCount, 1); } +void syncAddPeerRef(SSyncPeer *pPeer) { atomic_add_fetch_32(&pPeer->refCount, 1); } int32_t syncDecPeerRef(SSyncPeer *pPeer) { - if (atomic_sub_fetch_8(&pPeer->refCount, 1) == 0) { + if (atomic_sub_fetch_32(&pPeer->refCount, 1) == 0) { taosReleaseRef(tsSyncRefId, pPeer->pSyncNode->rid); sDebug("%s, resource is freed", pPeer->id); @@ -699,20 +712,20 @@ static void syncCheckRole(SSyncPeer *pPeer, SPeerStatus* peersStatus, int8_t new int8_t syncRequired = 0; pPeer->role = newPeerRole; - sTrace("%s, peer role:%s change to %s", pPeer->id, syncRole[oldPeerRole], syncRole[newPeerRole]); + sDebug("%s, peer role:%s change to %s", pPeer->id, syncRole[oldPeerRole], syncRole[newPeerRole]); SSyncPeer *pMaster = syncCheckMaster(pNode); if (pMaster) { // master is there pNode->pMaster = pMaster; - sTrace("%s, it is the master, sver:%" PRIu64, pMaster->id, pMaster->version); + sDebug("%s, it is the master, sver:%" PRIu64, pMaster->id, pMaster->version); if (syncValidateMaster(pPeer) < 0) return; if (nodeRole == TAOS_SYNC_ROLE_UNSYNCED) { if (nodeVersion < pMaster->version) { - sTrace("%s, is master, sync required, self sver:%" PRIu64, pMaster->id, nodeVersion); + sDebug("%s, is master, sync required, self sver:%" PRIu64, pMaster->id, nodeVersion); syncRequired = 1; } else { sInfo("%s, is master, work as slave, self sver:%" PRIu64, pMaster->id, nodeVersion); @@ -720,7 +733,7 @@ static void syncCheckRole(SSyncPeer *pPeer, SPeerStatus* peersStatus, int8_t new (*pNode->notifyRole)(pNode->ahandle, nodeRole); } } else if (nodeRole == TAOS_SYNC_ROLE_SLAVE && pMaster == pPeer) { - sTrace("%s, is master, continue work as slave, self sver:%" PRIu64, pMaster->id, nodeVersion); + sDebug("%s, is master, continue work as slave, self sver:%" PRIu64, pMaster->id, nodeVersion); } } else { // master not there, if all peer's state and version are consistent, choose the master @@ -739,10 +752,10 @@ static void syncCheckRole(SSyncPeer *pPeer, SPeerStatus* peersStatus, int8_t new } if (consistent) { - sTrace("vgId:%d, choose master", pNode->vgId); + sDebug("vgId:%d, choose master", pNode->vgId); syncChooseMaster(pNode); } else { - sTrace("vgId:%d, version inconsistent, cannot choose master", pNode->vgId); + sDebug("vgId:%d, version inconsistent, cannot choose master", pNode->vgId); } } @@ -1221,8 +1234,26 @@ static void syncProcessFwdAck(SSyncNode *pNode, SFwdInfo *pFwdInfo, int32_t code } } +static void syncMonitorNodeRole(void *param, void *tmrId) { + int64_t rid = (int64_t)param; + SSyncNode *pNode = taosAcquireRef(tsSyncRefId, rid); + if (pNode == NULL) return; + + for (int32_t index = 0; index < pNode->replica; index++) { + if (index == pNode->selfIndex) continue; + + SSyncPeer *pPeer = pNode->peerInfo[index]; + if (pPeer->role <= TAOS_SYNC_ROLE_UNSYNCED || nodeRole <= TAOS_SYNC_ROLE_UNSYNCED) { + syncSendPeersStatusMsgToPeer(pPeer, 1, SYNC_STATUS_CHECK_ROLE, syncGenTranId()); + } + } + + pNode->pRoleTimer = taosTmrStart(syncMonitorNodeRole, SYNC_ROLE_TIMER, (void *)pNode->rid, tsSyncTmrCtrl); + taosReleaseRef(tsSyncRefId, rid); +} + static void syncMonitorFwdInfos(void *param, void *tmrId) { - int64_t rid = (int64_t) param; + int64_t rid = (int64_t)param; SSyncNode *pNode = taosAcquireRef(tsSyncRefId, rid); if (pNode == NULL) return; @@ -1246,7 +1277,7 @@ static void syncMonitorFwdInfos(void *param, void *tmrId) { pthread_mutex_unlock(&(pNode->mutex)); } - pNode->pFwdTimer = taosTmrStart(syncMonitorFwdInfos, 300, (void *)pNode->rid, tsSyncTmrCtrl); + pNode->pFwdTimer = taosTmrStart(syncMonitorFwdInfos, SYNC_FWD_TIMER, (void *)pNode->rid, tsSyncTmrCtrl); } taosReleaseRef(tsSyncRefId, rid); From 5029e7da3f45b072d452f32dff8caf6cd730382c Mon Sep 17 00:00:00 2001 From: Shengliang Guan Date: Thu, 19 Nov 2020 09:53:34 +0000 Subject: [PATCH 10/13] TD-2153 --- src/sync/src/syncMain.c | 8 ++++---- src/sync/src/syncRestore.c | 10 +++++++++- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/src/sync/src/syncMain.c b/src/sync/src/syncMain.c index e7086626d6..2ca77fa404 100644 --- a/src/sync/src/syncMain.c +++ b/src/sync/src/syncMain.c @@ -172,7 +172,7 @@ void syncCleanUp() { int64_t syncStart(const SSyncInfo *pInfo) { const SSyncCfg *pCfg = &pInfo->syncCfg; - SSyncNode *pNode = (SSyncNode *)calloc(sizeof(SSyncNode), 1); + SSyncNode *pNode = calloc(sizeof(SSyncNode), 1); if (pNode == NULL) { sError("no memory to allocate syncNode"); terrno = TAOS_SYSTEM_ERROR(errno); @@ -207,8 +207,8 @@ int64_t syncStart(const SSyncInfo *pInfo) { const SNodeInfo *pNodeInfo = pCfg->nodeInfo + i; pNode->peerInfo[i] = syncAddPeer(pNode, pNodeInfo); if (pNode->peerInfo[i] == NULL) { - sError("vgId:%d, node:%d fqdn:%s port:%u is not configured, stop taosd", pNode->vgId, pNodeInfo->nodeId, pNodeInfo->nodeFqdn, - pNodeInfo->nodePort); + sError("vgId:%d, node:%d fqdn:%s port:%u is not configured, stop taosd", pNode->vgId, pNodeInfo->nodeId, + pNodeInfo->nodeFqdn, pNodeInfo->nodePort); syncStop(pNode->rid); exit(1); } @@ -419,7 +419,7 @@ void syncRecover(int64_t rid) { pthread_mutex_lock(&(pNode->mutex)); for (int32_t i = 0; i < pNode->replica; ++i) { - pPeer = (SSyncPeer *)pNode->peerInfo[i]; + pPeer = pNode->peerInfo[i]; if (pPeer->peerFd >= 0) { syncRestartConnection(pPeer); } diff --git a/src/sync/src/syncRestore.c b/src/sync/src/syncRestore.c index 393b6b09b1..d3dbe3a32d 100644 --- a/src/sync/src/syncRestore.c +++ b/src/sync/src/syncRestore.c @@ -140,6 +140,7 @@ static int32_t syncRestoreWal(SSyncPeer *pPeer) { if (buffer == NULL) return -1; SWalHead *pHead = (SWalHead *)buffer; + uint64_t lastVer = 0; while (1) { ret = taosReadMsg(pPeer->syncFd, pHead, sizeof(SWalHead)); @@ -153,7 +154,14 @@ static int32_t syncRestoreWal(SSyncPeer *pPeer) { ret = taosReadMsg(pPeer->syncFd, pHead->cont, pHead->len); if (ret < 0) break; - sDebug("%s, restore a record, qtype:wal hver:%" PRIu64, pPeer->id, pHead->version); + sDebug("%s, restore a record, qtype:wal len:%d hver:%" PRIu64, pPeer->id, pHead->len, pHead->version); + + if (lastVer != 0 && lastVer == pHead->version) { + sError("%s, failed to restore record, same hver:%" PRIu64 ", wal sync failed" PRIu64, pPeer->id, lastVer); + break; + } + lastVer = pHead->version; + (*pNode->writeToCache)(pNode->ahandle, pHead, TAOS_QTYPE_WAL, NULL); } From 976d8653bb3791923a5c6ac1ca3d827c6e2d8a12 Mon Sep 17 00:00:00 2001 From: Shengliang Guan Date: Thu, 19 Nov 2020 09:57:57 +0000 Subject: [PATCH 11/13] TD-2153 --- src/sync/src/syncRetrieve.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/sync/src/syncRetrieve.c b/src/sync/src/syncRetrieve.c index 52d1bded31..03f5a7bd94 100644 --- a/src/sync/src/syncRetrieve.c +++ b/src/sync/src/syncRetrieve.c @@ -418,7 +418,7 @@ static int32_t syncRetrieveWal(SSyncPeer *pPeer) { } if (code == 0) { - sDebug("%s, wal retrieve is finished", pPeer->id); + sInfo("%s, wal retrieve is finished", pPeer->id); pPeer->sstatus = TAOS_SYNC_STATUS_CACHE; SWalHead walHead; memset(&walHead, 0, sizeof(walHead)); @@ -447,7 +447,7 @@ static int32_t syncRetrieveDataStepByStep(SSyncPeer *pPeer) { pPeer->sversion = 0; pPeer->sstatus = TAOS_SYNC_STATUS_FILE; - sDebug("%s, start to retrieve file", pPeer->id); + sInfo("%s, start to retrieve file", pPeer->id); if (syncRetrieveFile(pPeer) < 0) { sError("%s, failed to retrieve file", pPeer->id); return -1; @@ -456,7 +456,7 @@ static int32_t syncRetrieveDataStepByStep(SSyncPeer *pPeer) { // if no files are synced, there must be wal to sync, sversion must be larger than one if (pPeer->sversion == 0) pPeer->sversion = 1; - sDebug("%s, start to retrieve wal", pPeer->id); + sInfo("%s, start to retrieve wal", pPeer->id); if (syncRetrieveWal(pPeer) < 0) { sError("%s, failed to retrieve wal", pPeer->id); return -1; @@ -478,7 +478,7 @@ void *syncRetrieveData(void *param) { sInfo("%s, sync tcp is setup", pPeer->id); if (syncRetrieveDataStepByStep(pPeer) == 0) { - sDebug("%s, sync retrieve process is successful", pPeer->id); + sInfo("%s, sync retrieve process is successful", pPeer->id); } else { sError("%s, failed to retrieve data, restart connection", pPeer->id); syncRestartConnection(pPeer); From 566b749cc5198a07eb13eef2a0374a9aa5d84c6c Mon Sep 17 00:00:00 2001 From: Shengliang Guan Date: Fri, 20 Nov 2020 12:32:42 +0800 Subject: [PATCH 12/13] TD-2046 --- src/mnode/inc/mnodeSdb.h | 5 +- src/mnode/src/mnodeSdb.c | 256 ++++++++++++++---------------------- src/mnode/src/mnodeTable.c | 2 +- src/mnode/src/mnodeVgroup.c | 2 +- src/sync/src/syncRestore.c | 2 +- tests/script/sh/deploy.sh | 36 ++--- 6 files changed, 125 insertions(+), 178 deletions(-) diff --git a/src/mnode/inc/mnodeSdb.h b/src/mnode/inc/mnodeSdb.h index 04fee5f6d5..965baf7c0d 100644 --- a/src/mnode/inc/mnodeSdb.h +++ b/src/mnode/inc/mnodeSdb.h @@ -21,6 +21,7 @@ extern "C" { #endif #include "mnode.h" +#include "twal.h" struct SSdbTable; @@ -60,6 +61,8 @@ typedef struct SSWriteMsg { void * pRow; SMnodeMsg *pMsg; struct SSdbTable *pTable; + char reserveForSync[16]; + SWalHead pHead[]; } SSWriteMsg; typedef struct { @@ -89,7 +92,7 @@ void sdbUpdateMnodeRoles(); int32_t sdbInsertRow(SSWriteMsg *pWrite); int32_t sdbDeleteRow(SSWriteMsg *pWrite); int32_t sdbUpdateRow(SSWriteMsg *pWrite); -int32_t sdbInsertRowImp(SSWriteMsg *pWrite); +int32_t sdbInsertRowToQueue(SSWriteMsg *pWrite); void *sdbGetRow(void *pTable, void *key); void *sdbFetchRow(void *pTable, void *pIter, void **ppRow); diff --git a/src/mnode/src/mnodeSdb.c b/src/mnode/src/mnodeSdb.c index 12cf5757b3..15e638d436 100644 --- a/src/mnode/src/mnodeSdb.c +++ b/src/mnode/src/mnodeSdb.c @@ -34,7 +34,7 @@ #include "mnodeSdb.h" #define SDB_TABLE_LEN 12 -#define SDB_SYNC_HACK 16 +#define MAX_QUEUED_MSG_NUM 10000 typedef enum { SDB_ACTION_INSERT = 0, @@ -82,6 +82,7 @@ typedef struct { int64_t sync; void * wal; SSyncCfg cfg; + int32_t queuedMsg; int32_t numOfTables; SSdbTable *tableList[SDB_TABLE_MAX]; pthread_mutex_t mutex; @@ -105,16 +106,14 @@ static taos_qall tsSdbWQall; static taos_queue tsSdbWQueue; static SSdbWorkerPool tsSdbPool; -static int32_t sdbWrite(void *pWrite, void *pHead, int32_t qtype, void *unused); -static int32_t sdbWriteToQueue(void *pWrite, void *pHead, int32_t qtype, void *unused); +static int32_t sdbProcessWrite(void *pWrite, void *pHead, int32_t qtype, void *unused); +static int32_t sdbWriteWalToQueue(void *vparam, void *pHead, int32_t qtype, void *rparam); +static int32_t sdbWriteRowToQueue(SSWriteMsg *pInputWrite, int32_t action); static void * sdbWorkerFp(void *pWorker); static int32_t sdbInitWorker(); static void sdbCleanupWorker(); static int32_t sdbAllocQueue(); static void sdbFreeQueue(); -extern int32_t sdbInsertRowImp(SSWriteMsg *pWrite); -static int32_t sdbUpdateRowImp(SSWriteMsg *pWrite); -static int32_t sdbDeleteRowImp(SSWriteMsg *pWrite); static int32_t sdbInsertHash(SSdbTable *pTable, SSWriteMsg *pWrite); static int32_t sdbUpdateHash(SSdbTable *pTable, SSWriteMsg *pWrite); static int32_t sdbDeleteHash(SSdbTable *pTable, SSWriteMsg *pWrite); @@ -181,7 +180,7 @@ static int32_t sdbInitWal() { } sdbInfo("vgId:1, open wal for restore"); - int code = walRestore(tsSdbMgmt.wal, NULL, sdbWrite); + int32_t code = walRestore(tsSdbMgmt.wal, NULL, sdbProcessWrite); if (code != TSDB_CODE_SUCCESS) { sdbError("vgId:1, failed to open wal for restore since %s", tstrerror(code)); return -1; @@ -250,7 +249,7 @@ static void sdbNotifyRole(void *ahandle, int8_t role) { // failed to forward, need revert insert static void sdbHandleFailedConfirm(SSWriteMsg *pWrite) { - SWalHead *pHead = (SWalHead *)((char *)pWrite + sizeof(SSWriteMsg) + SDB_SYNC_HACK); + SWalHead *pHead = pWrite->pHead; int32_t action = pHead->msgType % 10; sdbError("vgId:1, row:%p:%s hver:%" PRIu64 " action:%s, failed to foward since %s", pWrite->pRow, @@ -285,13 +284,6 @@ static void sdbConfirmForward(void *ahandle, void *wparam, int32_t code) { } dnodeSendRpcMWriteRsp(pMsg, pWrite->code); - - // if ahandle, means this func is called by sdb write - if (ahandle == NULL) { - sdbDecRef(pWrite->pTable, pWrite->pRow); - } - - taosFreeQitem(pWrite); } static void sdbUpdateSyncTmrFp(void *param, void *tmrId) { sdbUpdateSync(NULL); } @@ -379,7 +371,7 @@ void sdbUpdateSync(void *pMnodes) { syncInfo.ahandle = NULL; syncInfo.getWalInfo = sdbGetWalInfo; syncInfo.getFileInfo = sdbGetFileInfo; - syncInfo.writeToCache = sdbWriteToQueue; + syncInfo.writeToCache = sdbWriteWalToQueue; syncInfo.confirmForward = sdbConfirmForward; syncInfo.notifyRole = sdbNotifyRole; tsSdbMgmt.cfg = syncCfg; @@ -389,6 +381,7 @@ void sdbUpdateSync(void *pMnodes) { } else { tsSdbMgmt.sync = syncStart(&syncInfo); } + sdbUpdateMnodeRoles(); } @@ -565,7 +558,7 @@ static int32_t sdbUpdateHash(SSdbTable *pTable, SSWriteMsg *pWrite) { return TSDB_CODE_SUCCESS; } -static int sdbWrite(void *wparam, void *hparam, int32_t qtype, void *unused) { +static int sdbProcessWrite(void *wparam, void *hparam, int32_t qtype, void *unused) { SSWriteMsg *pWrite = wparam; SWalHead *pHead = hparam; int32_t tableId = pHead->msgType / 10; @@ -665,8 +658,7 @@ int32_t sdbInsertRow(SSWriteMsg *pWrite) { if (pTable == NULL) return TSDB_CODE_MND_SDB_INVALID_TABLE_TYPE; if (sdbGetRowFromObj(pTable, pWrite->pRow)) { - sdbError("vgId:1, sdb:%s, failed to insert key:%s since it already exist", pTable->name, - sdbGetRowStr(pTable, pWrite->pRow)); + sdbError("vgId:1, sdb:%s, failed to insert:%s since it exist", pTable->name, sdbGetRowStr(pTable, pWrite->pRow)); sdbDecRef(pTable, pWrite->pRow); return TSDB_CODE_MND_SDB_OBJ_ALREADY_THERE; } @@ -675,14 +667,14 @@ int32_t sdbInsertRow(SSWriteMsg *pWrite) { *((uint32_t *)pWrite->pRow) = atomic_add_fetch_32(&pTable->autoIndex, 1); // let vgId increase from 2 - if (pTable->autoIndex == 1 && strcmp(pTable->name, "vgroups") == 0) { + if (pTable->autoIndex == 1 && pTable->id == SDB_TABLE_VGROUP) { *((uint32_t *)pWrite->pRow) = atomic_add_fetch_32(&pTable->autoIndex, 1); } } int32_t code = sdbInsertHash(pTable, pWrite); if (code != TSDB_CODE_SUCCESS) { - sdbError("vgId:1, sdb:%s, failed to insert into hash", pTable->name); + sdbError("vgId:1, sdb:%s, failed to insert:%s into hash", pTable->name, sdbGetRowStr(pTable, pWrite->pRow)); return code; } @@ -694,39 +686,10 @@ int32_t sdbInsertRow(SSWriteMsg *pWrite) { if (pWrite->fpReq) { return (*pWrite->fpReq)(pWrite->pMsg); } else { - return sdbInsertRowImp(pWrite); + return sdbWriteRowToQueue(pWrite, SDB_ACTION_INSERT); } } -int32_t sdbInsertRowImp(SSWriteMsg *pWrite) { - SSdbTable *pTable = pWrite->pTable; - if (pTable == NULL) return TSDB_CODE_MND_SDB_INVALID_TABLE_TYPE; - - int32_t size = sizeof(SSWriteMsg) + sizeof(SWalHead) + pTable->maxRowSize + SDB_SYNC_HACK; - SSWriteMsg *pNewWrite = taosAllocateQitem(size); - - SWalHead *pHead = (SWalHead *)((char *)pNewWrite + sizeof(SSWriteMsg) + SDB_SYNC_HACK); - pHead->version = 0; - pHead->len = pWrite->rowSize; - pHead->msgType = pTable->id * 10 + SDB_ACTION_INSERT; - - pWrite->rowData = pHead->cont; - (*pTable->fpEncode)(pWrite); - pHead->len = pWrite->rowSize; - - memcpy(pNewWrite, pWrite, sizeof(SSWriteMsg)); - - if (pNewWrite->pMsg != NULL) { - sdbDebug("vgId:1, ahandle:%p msg:%p, sdb:%s row:%p:%s, insert action is add to sdb queue", pNewWrite->pMsg->rpcMsg.ahandle, - pNewWrite->pMsg, pTable->name, pWrite->pRow, sdbGetRowStr(pTable, pWrite->pRow)); - } - - sdbIncRef(pNewWrite->pTable, pNewWrite->pRow); - taosWriteQitem(tsSdbWQueue, TAOS_QTYPE_RPC, pNewWrite); - - return TSDB_CODE_MND_ACTION_IN_PROGRESS; -} - bool sdbCheckRowDeleted(void *tparam, void *pRow) { SSdbTable *pTable = tparam; if (pTable == NULL) return false; @@ -745,55 +708,24 @@ int32_t sdbDeleteRow(SSWriteMsg *pWrite) { return TSDB_CODE_MND_SDB_OBJ_NOT_THERE; } - sdbIncRef(pTable, pWrite->pRow); - int32_t code = sdbDeleteHash(pTable, pWrite); if (code != TSDB_CODE_SUCCESS) { sdbError("vgId:1, sdb:%s, failed to delete from hash", pTable->name); - sdbDecRef(pTable, pWrite->pRow); return code; } // just delete data from memory if (pWrite->type != SDB_OPER_GLOBAL) { - sdbDecRef(pTable, pWrite->pRow); return TSDB_CODE_SUCCESS; } if (pWrite->fpReq) { return (*pWrite->fpReq)(pWrite->pMsg); } else { - return sdbDeleteRowImp(pWrite); + return sdbWriteRowToQueue(pWrite, SDB_ACTION_DELETE); } } -int32_t sdbDeleteRowImp(SSWriteMsg *pWrite) { - SSdbTable *pTable = pWrite->pTable; - if (pTable == NULL) return TSDB_CODE_MND_SDB_INVALID_TABLE_TYPE; - - int32_t size = sizeof(SSWriteMsg) + sizeof(SWalHead) + pTable->maxRowSize + SDB_SYNC_HACK; - SSWriteMsg *pNewWrite = taosAllocateQitem(size); - - SWalHead *pHead = (SWalHead *)((void *)pNewWrite + sizeof(SSWriteMsg) + SDB_SYNC_HACK); - pHead->version = 0; - pHead->msgType = pTable->id * 10 + SDB_ACTION_DELETE; - - pWrite->rowData = pHead->cont; - (*pTable->fpEncode)(pWrite); - pHead->len = pWrite->rowSize; - - memcpy(pNewWrite, pWrite, sizeof(SSWriteMsg)); - - if (pNewWrite->pMsg != NULL) { - sdbDebug("vgId:1, ahandle:%p msg:%p, sdb:%s row:%p:%s, delete action is add to sdb queue", pNewWrite->pMsg->rpcMsg.ahandle, - pNewWrite->pMsg, pTable->name, pWrite->pRow, sdbGetRowStr(pTable, pWrite->pRow)); - } - - taosWriteQitem(tsSdbWQueue, TAOS_QTYPE_RPC, pNewWrite); - - return TSDB_CODE_MND_ACTION_IN_PROGRESS; -} - int32_t sdbUpdateRow(SSWriteMsg *pWrite) { SSdbTable *pTable = pWrite->pTable; if (pTable == NULL) return TSDB_CODE_MND_SDB_INVALID_TABLE_TYPE; @@ -818,38 +750,10 @@ int32_t sdbUpdateRow(SSWriteMsg *pWrite) { if (pWrite->fpReq) { return (*pWrite->fpReq)(pWrite->pMsg); } else { - return sdbUpdateRowImp(pWrite); + return sdbWriteRowToQueue(pWrite, SDB_ACTION_UPDATE); } } -int32_t sdbUpdateRowImp(SSWriteMsg *pWrite) { - SSdbTable *pTable = pWrite->pTable; - if (pTable == NULL) return TSDB_CODE_MND_SDB_INVALID_TABLE_TYPE; - - int32_t size = sizeof(SSWriteMsg) + sizeof(SWalHead) + pTable->maxRowSize + SDB_SYNC_HACK; - SSWriteMsg *pNewWrite = taosAllocateQitem(size); - - SWalHead *pHead = (SWalHead *)((void *)pNewWrite + sizeof(SSWriteMsg) + SDB_SYNC_HACK); - pHead->version = 0; - pHead->msgType = pTable->id * 10 + SDB_ACTION_UPDATE; - - pWrite->rowData = pHead->cont; - (*pTable->fpEncode)(pWrite); - pHead->len = pWrite->rowSize; - - memcpy(pNewWrite, pWrite, sizeof(SSWriteMsg)); - - if (pNewWrite->pMsg != NULL) { - sdbDebug("vgId:1, ahandle:%p msg:%p, sdb:%s row:%p:%s, update action is add to sdb queue", pNewWrite->pMsg->rpcMsg.ahandle, - pNewWrite->pMsg, pTable->name, pWrite->pRow, sdbGetRowStr(pTable, pWrite->pRow)); - } - - sdbIncRef(pNewWrite->pTable, pNewWrite->pRow); - taosWriteQitem(tsSdbWQueue, TAOS_QTYPE_RPC, pNewWrite); - - return TSDB_CODE_MND_ACTION_IN_PROGRESS; -} - void *sdbFetchRow(void *tparam, void *pNode, void **ppRow) { SSdbTable *pTable = tparam; *ppRow = NULL; @@ -942,7 +846,7 @@ void sdbCloseTable(void *handle) { free(pTable); } -int32_t sdbInitWorker() { +static int32_t sdbInitWorker() { tsSdbPool.num = 1; tsSdbPool.worker = calloc(sizeof(SSdbWorker), tsSdbPool.num); @@ -958,7 +862,7 @@ int32_t sdbInitWorker() { return 0; } -void sdbCleanupWorker() { +static void sdbCleanupWorker() { for (int32_t i = 0; i < tsSdbPool.num; ++i) { SSdbWorker *pWorker = tsSdbPool.worker + i; if (pWorker->thread) { @@ -979,7 +883,7 @@ void sdbCleanupWorker() { mInfo("vgId:1, sdb write is closed"); } -int32_t sdbAllocQueue() { +static int32_t sdbAllocQueue() { tsSdbWQueue = taosOpenQueue(); if (tsSdbWQueue == NULL) return TSDB_CODE_MND_OUT_OF_MEMORY; @@ -1021,7 +925,7 @@ int32_t sdbAllocQueue() { return TSDB_CODE_SUCCESS; } -void sdbFreeQueue() { +static void sdbFreeQueue() { taosCloseQueue(tsSdbWQueue); taosFreeQall(tsSdbWQall); taosCloseQset(tsSdbWQset); @@ -1030,54 +934,96 @@ void sdbFreeQueue() { tsSdbWQueue = NULL; } -int32_t sdbWriteToQueue(void *wparam, void *hparam, int32_t qtype, void *unsed) { - SWalHead *pHead = hparam; - int32_t size = sizeof(SWalHead) + pHead->len; - SWalHead *pWal = taosAllocateQitem(size); - memcpy(pWal, pHead, size); +static int32_t sdbWriteToQueue(SSWriteMsg *pWrite, int32_t qtype) { + SWalHead *pHead = pWrite->pHead; - taosWriteQitem(tsSdbWQueue, qtype, pWal); - return 0; + if (pHead->len > TSDB_MAX_WAL_SIZE) { + sdbError("vgId:1, wal len:%d exceeds limit, hver:%" PRIu64, pHead->len, pHead->version); + taosFreeQitem(pWrite); + return TSDB_CODE_WAL_SIZE_LIMIT; + } + + int32_t queued = atomic_add_fetch_32(&tsSdbMgmt.queuedMsg, 1); + if (queued > MAX_QUEUED_MSG_NUM) { + sdbDebug("vgId:1, too many msg:%d in sdb queue, flow control", queued); + taosMsleep(1); + } + + sdbIncRef(pWrite->pTable, pWrite->pRow); + + sdbTrace("vgId:1, msg:%p write into to sdb queue", pWrite->pMsg); + taosWriteQitem(tsSdbWQueue, qtype, pWrite); + + return TSDB_CODE_MND_ACTION_IN_PROGRESS; } +static void sdbFreeFromQueue(SSWriteMsg *pWrite) { + int32_t queued = atomic_sub_fetch_32(&tsSdbMgmt.queuedMsg, 1); + sdbTrace("vgId:1, msg:%p free from sdb queue, queued:%d", pWrite->pMsg, queued); + + sdbDecRef(pWrite->pTable, pWrite->pRow); + taosFreeQitem(pWrite); +} + +static int32_t sdbWriteWalToQueue(void *vparam, void *wparam, int32_t qtype, void *rparam) { + SWalHead *pHead = wparam; + + int32_t size = sizeof(SSWriteMsg) + sizeof(SWalHead) + pHead->len; + SSWriteMsg *pWrite = taosAllocateQitem(size); + if (pWrite == NULL) { + return TSDB_CODE_VND_OUT_OF_MEMORY; + } + + return sdbWriteToQueue(pWrite, qtype); +} + +static int32_t sdbWriteRowToQueue(SSWriteMsg *pInputWrite, int32_t action) { + SSdbTable *pTable = pInputWrite->pTable; + if (pTable == NULL) return TSDB_CODE_MND_SDB_INVALID_TABLE_TYPE; + + int32_t size = sizeof(SSWriteMsg) + sizeof(SWalHead) + pTable->maxRowSize; + SSWriteMsg *pWrite = taosAllocateQitem(size); + if (pWrite == NULL) { + return TSDB_CODE_VND_OUT_OF_MEMORY; + } + + memcpy(pWrite, pInputWrite, sizeof(SSWriteMsg)); + pWrite->processedCount = 1; + + SWalHead *pHead = pWrite->pHead; + pWrite->rowData = pHead->cont; + (*pTable->fpEncode)(pWrite); + + pHead->len = pWrite->rowSize; + pHead->version = 0; + pHead->msgType = pTable->id * 10 + action; + + return sdbWriteToQueue(pWrite, TAOS_QTYPE_RPC); +} + +int32_t sdbInsertRowToQueue(SSWriteMsg *pWrite) { return sdbWriteRowToQueue(pWrite, SDB_ACTION_INSERT); } + static void *sdbWorkerFp(void *pWorker) { - SWalHead *pHead; SSWriteMsg *pWrite; - int32_t qtype; - int32_t numOfMsgs; - void * item; - void * unUsed; + int32_t qtype; + void * unUsed; while (1) { - numOfMsgs = taosReadAllQitemsFromQset(tsSdbWQset, tsSdbWQall, &unUsed); + int32_t numOfMsgs = taosReadAllQitemsFromQset(tsSdbWQset, tsSdbWQall, &unUsed); if (numOfMsgs == 0) { sdbDebug("qset:%p, sdb got no message from qset, exiting", tsSdbWQset); break; } for (int32_t i = 0; i < numOfMsgs; ++i) { - taosGetQitem(tsSdbWQall, &qtype, &item); - if (qtype == TAOS_QTYPE_RPC) { - pWrite = (SSWriteMsg *)item; - pWrite->processedCount = 1; - pHead = (void *)pWrite + sizeof(SSWriteMsg) + SDB_SYNC_HACK; - if (pWrite->pMsg != NULL) { - sdbDebug("vgId:1, ahandle:%p msg:%p, sdb:%s row:%p:%s hver:%" PRIu64 ", will be processed in sdb queue", - pWrite->pMsg->rpcMsg.ahandle, pWrite->pMsg, pWrite->pTable->name, pWrite->pRow, - sdbGetKeyStr(pWrite->pTable, pHead->cont), pHead->version); - } - } else { - pHead = (SWalHead *)item; - pWrite = NULL; - } + taosGetQitem(tsSdbWQall, &qtype, (void **)&pWrite); + sdbTrace("vgId:1, msg:%p, row:%p hver:%" PRIu64 ", will be processed in sdb queue", pWrite->pMsg, pWrite->pRow, + pWrite->pHead->version); - int32_t code = sdbWrite(pWrite, pHead, qtype, NULL); - if (code > 0) code = 0; - if (pWrite) { - pWrite->code = code; - } else { - pHead->len = code; // hackway - } + pWrite->code = sdbProcessWrite((qtype == TAOS_QTYPE_RPC) ? pWrite : NULL, pWrite->pHead, qtype, NULL); + if (pWrite->code > 0) pWrite->code = 0; + + sdbTrace("vgId:1, msg:%p is processed in sdb queue, code:%x", pWrite->pMsg, pWrite->code); } walFsync(tsSdbMgmt.wal, true); @@ -1085,18 +1031,16 @@ static void *sdbWorkerFp(void *pWorker) { // browse all items, and process them one by one taosResetQitems(tsSdbWQall); for (int32_t i = 0; i < numOfMsgs; ++i) { - taosGetQitem(tsSdbWQall, &qtype, &item); + taosGetQitem(tsSdbWQall, &qtype, (void **)&pWrite); if (qtype == TAOS_QTYPE_RPC) { - pWrite = (SSWriteMsg *)item; sdbConfirmForward(NULL, pWrite, pWrite->code); } else if (qtype == TAOS_QTYPE_FWD) { - pHead = (SWalHead *)item; - syncConfirmForward(tsSdbMgmt.sync, pHead->version, pHead->len); - taosFreeQitem(item); + syncConfirmForward(tsSdbMgmt.sync, pWrite->pHead->version, pWrite->code); } else { - taosFreeQitem(item); } + + sdbFreeFromQueue(pWrite); } } diff --git a/src/mnode/src/mnodeTable.c b/src/mnode/src/mnodeTable.c index a90b573576..587c766e44 100644 --- a/src/mnode/src/mnodeTable.c +++ b/src/mnode/src/mnodeTable.c @@ -2418,7 +2418,7 @@ static void mnodeProcessCreateChildTableRsp(SRpcMsg *rpcMsg) { .fpRsp = mnodeDoCreateChildTableCb }; - int32_t code = sdbInsertRowImp(&desc); + int32_t code = sdbInsertRowToQueue(&desc); if (code != TSDB_CODE_SUCCESS && code != TSDB_CODE_MND_ACTION_IN_PROGRESS) { mnodeMsg->pTable = NULL; mnodeDestroyChildTable(pTable); diff --git a/src/mnode/src/mnodeVgroup.c b/src/mnode/src/mnodeVgroup.c index 2f0caea57a..2eb11e1def 100644 --- a/src/mnode/src/mnodeVgroup.c +++ b/src/mnode/src/mnodeVgroup.c @@ -966,7 +966,7 @@ static void mnodeProcessCreateVnodeRsp(SRpcMsg *rpcMsg) { .fpRsp = mnodeCreateVgroupCb }; - int32_t code = sdbInsertRowImp(&wmsg); + int32_t code = sdbInsertRowToQueue(&wmsg); if (code != TSDB_CODE_SUCCESS && code != TSDB_CODE_MND_ACTION_IN_PROGRESS) { mnodeMsg->pVgroup = NULL; mnodeDestroyVgroup(pVgroup); diff --git a/src/sync/src/syncRestore.c b/src/sync/src/syncRestore.c index d3dbe3a32d..e7901e6eb8 100644 --- a/src/sync/src/syncRestore.c +++ b/src/sync/src/syncRestore.c @@ -156,7 +156,7 @@ static int32_t syncRestoreWal(SSyncPeer *pPeer) { sDebug("%s, restore a record, qtype:wal len:%d hver:%" PRIu64, pPeer->id, pHead->len, pHead->version); - if (lastVer != 0 && lastVer == pHead->version) { + if (lastVer == pHead->version) { sError("%s, failed to restore record, same hver:%" PRIu64 ", wal sync failed" PRIu64, pPeer->id, lastVer); break; } diff --git a/tests/script/sh/deploy.sh b/tests/script/sh/deploy.sh index 591d7749ea..8fccb1442f 100755 --- a/tests/script/sh/deploy.sh +++ b/tests/script/sh/deploy.sh @@ -111,24 +111,24 @@ echo "serverPort ${NODE}" >> $TAOS_CFG echo "dataDir $DATA_DIR" >> $TAOS_CFG echo "logDir $LOG_DIR" >> $TAOS_CFG echo "debugFlag 0" >> $TAOS_CFG -echo "mDebugFlag 143" >> $TAOS_CFG -echo "sdbDebugFlag 143" >> $TAOS_CFG -echo "dDebugFlag 131" >> $TAOS_CFG -echo "vDebugFlag 131" >> $TAOS_CFG -echo "tsdbDebugFlag 131" >> $TAOS_CFG -echo "cDebugFlag 131" >> $TAOS_CFG -echo "jnidebugFlag 131" >> $TAOS_CFG -echo "odbcdebugFlag 131" >> $TAOS_CFG -echo "httpDebugFlag 131" >> $TAOS_CFG -echo "monitorDebugFlag 131" >> $TAOS_CFG -echo "mqttDebugFlag 131" >> $TAOS_CFG -echo "qdebugFlag 131" >> $TAOS_CFG -echo "rpcDebugFlag 131" >> $TAOS_CFG +echo "mDebugFlag 135" >> $TAOS_CFG +echo "sdbDebugFlag 135" >> $TAOS_CFG +echo "dDebugFlag 135" >> $TAOS_CFG +echo "vDebugFlag 135" >> $TAOS_CFG +echo "tsdbDebugFlag 135" >> $TAOS_CFG +echo "cDebugFlag 135" >> $TAOS_CFG +echo "jnidebugFlag 135" >> $TAOS_CFG +echo "odbcdebugFlag 135" >> $TAOS_CFG +echo "httpDebugFlag 135" >> $TAOS_CFG +echo "monitorDebugFlag 135" >> $TAOS_CFG +echo "mqttDebugFlag 135" >> $TAOS_CFG +echo "qdebugFlag 135" >> $TAOS_CFG +echo "rpcDebugFlag 135" >> $TAOS_CFG echo "tmrDebugFlag 131" >> $TAOS_CFG -echo "udebugFlag 131" >> $TAOS_CFG -echo "sdebugFlag 143" >> $TAOS_CFG -echo "wdebugFlag 143" >> $TAOS_CFG -echo "cqdebugFlag 131" >> $TAOS_CFG +echo "udebugFlag 135" >> $TAOS_CFG +echo "sdebugFlag 135" >> $TAOS_CFG +echo "wdebugFlag 135" >> $TAOS_CFG +echo "cqdebugFlag 135" >> $TAOS_CFG echo "monitor 0" >> $TAOS_CFG echo "monitorInterval 1" >> $TAOS_CFG echo "http 0" >> $TAOS_CFG @@ -140,7 +140,7 @@ echo "clog 2" >> $TAOS_CFG #echo "cache 1" >> $TAOS_CFG echo "days 10" >> $TAOS_CFG echo "statusInterval 1" >> $TAOS_CFG -echo "maxVgroupsPerDb 10" >> $TAOS_CFG +echo "maxVgroupsPerDb 4" >> $TAOS_CFG echo "minTablesPerVnode 4" >> $TAOS_CFG echo "maxTablesPerVnode 1000" >> $TAOS_CFG echo "tableIncStepPerVnode 10000" >> $TAOS_CFG From f323186f78eba56a531049bae8a69888fe6111b0 Mon Sep 17 00:00:00 2001 From: Shengliang Guan Date: Fri, 20 Nov 2020 13:48:05 +0800 Subject: [PATCH 13/13] TD-2046 --- src/mnode/inc/mnodeSdb.h | 46 +++--- src/mnode/src/mnodeAcct.c | 41 +++-- src/mnode/src/mnodeCluster.c | 30 ++-- src/mnode/src/mnodeDb.c | 66 ++++---- src/mnode/src/mnodeDnode.c | 50 +++--- src/mnode/src/mnodeMnode.c | 48 +++--- src/mnode/src/mnodeSdb.c | 286 +++++++++++++++++------------------ src/mnode/src/mnodeTable.c | 216 +++++++++++++------------- src/mnode/src/mnodeUser.c | 54 +++---- src/mnode/src/mnodeVgroup.c | 86 +++++------ 10 files changed, 460 insertions(+), 463 deletions(-) diff --git a/src/mnode/inc/mnodeSdb.h b/src/mnode/inc/mnodeSdb.h index 965baf7c0d..29d8cf1207 100644 --- a/src/mnode/inc/mnodeSdb.h +++ b/src/mnode/inc/mnodeSdb.h @@ -23,8 +23,6 @@ extern "C" { #include "mnode.h" #include "twal.h" -struct SSdbTable; - typedef enum { SDB_TABLE_CLUSTER = 0, SDB_TABLE_DNODE = 1, @@ -50,20 +48,20 @@ typedef enum { SDB_OPER_LOCAL = 1 } ESdbOper; -typedef struct SSWriteMsg { - ESdbOper type; - int32_t processedCount; // for sync fwd callback - int32_t code; // for callback in sdb queue - int32_t rowSize; - void * rowData; +typedef struct SSdbRow { + ESdbOper type; + int32_t processedCount; // for sync fwd callback + int32_t code; // for callback in sdb queue + int32_t rowSize; + void * rowData; + void * pObj; + void * pTable; + SMnodeMsg *pMsg; int32_t (*fpReq)(SMnodeMsg *pMsg); int32_t (*fpRsp)(SMnodeMsg *pMsg, int32_t code); - void * pRow; - SMnodeMsg *pMsg; - struct SSdbTable *pTable; - char reserveForSync[16]; - SWalHead pHead[]; -} SSWriteMsg; + char reserveForSync[16]; + SWalHead pHead[]; +} SSdbRow; typedef struct { char * name; @@ -72,12 +70,12 @@ typedef struct { int32_t refCountPos; ESdbTable id; ESdbKey keyType; - int32_t (*fpInsert)(SSWriteMsg *pWrite); - int32_t (*fpDelete)(SSWriteMsg *pWrite); - int32_t (*fpUpdate)(SSWriteMsg *pWrite); - int32_t (*fpEncode)(SSWriteMsg *pWrite); - int32_t (*fpDecode)(SSWriteMsg *pWrite); - int32_t (*fpDestroy)(SSWriteMsg *pWrite); + int32_t (*fpInsert)(SSdbRow *pRow); + int32_t (*fpDelete)(SSdbRow *pRow); + int32_t (*fpUpdate)(SSdbRow *pRow); + int32_t (*fpEncode)(SSdbRow *pRow); + int32_t (*fpDecode)(SSdbRow *pRow); + int32_t (*fpDestroy)(SSdbRow *pRow); int32_t (*fpRestored)(); } SSdbTableDesc; @@ -89,10 +87,10 @@ bool sdbIsMaster(); bool sdbIsServing(); void sdbUpdateMnodeRoles(); -int32_t sdbInsertRow(SSWriteMsg *pWrite); -int32_t sdbDeleteRow(SSWriteMsg *pWrite); -int32_t sdbUpdateRow(SSWriteMsg *pWrite); -int32_t sdbInsertRowToQueue(SSWriteMsg *pWrite); +int32_t sdbInsertRow(SSdbRow *pRow); +int32_t sdbDeleteRow(SSdbRow *pRow); +int32_t sdbUpdateRow(SSdbRow *pRow); +int32_t sdbInsertRowToQueue(SSdbRow *pRow); void *sdbGetRow(void *pTable, void *key); void *sdbFetchRow(void *pTable, void *pIter, void **ppRow); diff --git a/src/mnode/src/mnodeAcct.c b/src/mnode/src/mnodeAcct.c index 48af408c99..9fff2f0229 100644 --- a/src/mnode/src/mnodeAcct.c +++ b/src/mnode/src/mnodeAcct.c @@ -16,6 +16,7 @@ #define _DEFAULT_SOURCE #include "os.h" #include "taoserror.h" +#include "tglobal.h" #include "dnode.h" #include "mnodeDef.h" #include "mnodeInt.h" @@ -25,36 +26,34 @@ #include "mnodeUser.h" #include "mnodeVgroup.h" -#include "tglobal.h" - void * tsAcctSdb = NULL; static int32_t tsAcctUpdateSize; static int32_t mnodeCreateRootAcct(); -static int32_t mnodeAcctActionDestroy(SSWriteMsg *pWMsg) { - SAcctObj *pAcct = pWMsg->pRow; +static int32_t mnodeAcctActionDestroy(SSdbRow *pRow) { + SAcctObj *pAcct = pRow->pObj; pthread_mutex_destroy(&pAcct->mutex); - tfree(pWMsg->pRow); + tfree(pRow->pObj); return TSDB_CODE_SUCCESS; } -static int32_t mnodeAcctActionInsert(SSWriteMsg *pWMsg) { - SAcctObj *pAcct = pWMsg->pRow; +static int32_t mnodeAcctActionInsert(SSdbRow *pRow) { + SAcctObj *pAcct = pRow->pObj; memset(&pAcct->acctInfo, 0, sizeof(SAcctInfo)); pAcct->acctInfo.accessState = TSDB_VN_ALL_ACCCESS; pthread_mutex_init(&pAcct->mutex, NULL); return TSDB_CODE_SUCCESS; } -static int32_t mnodeAcctActionDelete(SSWriteMsg *pWMsg) { - SAcctObj *pAcct = pWMsg->pRow; +static int32_t mnodeAcctActionDelete(SSdbRow *pRow) { + SAcctObj *pAcct = pRow->pObj; mnodeDropAllUsers(pAcct); mnodeDropAllDbs(pAcct); return TSDB_CODE_SUCCESS; } -static int32_t mnodeAcctActionUpdate(SSWriteMsg *pWMsg) { - SAcctObj *pAcct = pWMsg->pRow; +static int32_t mnodeAcctActionUpdate(SSdbRow *pRow) { + SAcctObj *pAcct = pRow->pObj; SAcctObj *pSaved = mnodeGetAcct(pAcct->user); if (pAcct != pSaved) { memcpy(pSaved, pAcct, tsAcctUpdateSize); @@ -64,19 +63,19 @@ static int32_t mnodeAcctActionUpdate(SSWriteMsg *pWMsg) { return TSDB_CODE_SUCCESS; } -static int32_t mnodeAcctActionEncode(SSWriteMsg *pWMsg) { - SAcctObj *pAcct = pWMsg->pRow; - memcpy(pWMsg->rowData, pAcct, tsAcctUpdateSize); - pWMsg->rowSize = tsAcctUpdateSize; +static int32_t mnodeAcctActionEncode(SSdbRow *pRow) { + SAcctObj *pAcct = pRow->pObj; + memcpy(pRow->rowData, pAcct, tsAcctUpdateSize); + pRow->rowSize = tsAcctUpdateSize; return TSDB_CODE_SUCCESS; } -static int32_t mnodeAcctActionDecode(SSWriteMsg *pWMsg) { +static int32_t mnodeAcctActionDecode(SSdbRow *pRow) { SAcctObj *pAcct = (SAcctObj *) calloc(1, sizeof(SAcctObj)); if (pAcct == NULL) return TSDB_CODE_MND_OUT_OF_MEMORY; - memcpy(pAcct, pWMsg->rowData, tsAcctUpdateSize); - pWMsg->pRow = pAcct; + memcpy(pAcct, pRow->rowData, tsAcctUpdateSize); + pRow->pObj = pAcct; return TSDB_CODE_SUCCESS; } @@ -226,13 +225,13 @@ static int32_t mnodeCreateRootAcct() { pAcct->acctId = sdbGetId(tsAcctSdb); pAcct->createdTime = taosGetTimestampMs(); - SSWriteMsg wmsg = { + SSdbRow row = { .type = SDB_OPER_GLOBAL, .pTable = tsAcctSdb, - .pRow = pAcct, + .pObj = pAcct, }; - return sdbInsertRow(&wmsg); + return sdbInsertRow(&row); } #ifndef _ACCT diff --git a/src/mnode/src/mnodeCluster.c b/src/mnode/src/mnodeCluster.c index ff84b7ac3f..5be67e4ad9 100644 --- a/src/mnode/src/mnodeCluster.c +++ b/src/mnode/src/mnodeCluster.c @@ -32,36 +32,36 @@ static int32_t mnodeCreateCluster(); static int32_t mnodeGetClusterMeta(STableMetaMsg *pMeta, SShowObj *pShow, void *pConn); static int32_t mnodeRetrieveClusters(SShowObj *pShow, char *data, int32_t rows, void *pConn); -static int32_t mnodeClusterActionDestroy(SSWriteMsg *pWMsg) { - tfree(pWMsg->pRow); +static int32_t mnodeClusterActionDestroy(SSdbRow *pRow) { + tfree(pRow->pObj); return TSDB_CODE_SUCCESS; } -static int32_t mnodeClusterActionInsert(SSWriteMsg *pWMsg) { +static int32_t mnodeClusterActionInsert(SSdbRow *pRow) { return TSDB_CODE_SUCCESS; } -static int32_t mnodeClusterActionDelete(SSWriteMsg *pWMsg) { +static int32_t mnodeClusterActionDelete(SSdbRow *pRow) { return TSDB_CODE_SUCCESS; } -static int32_t mnodeClusterActionUpdate(SSWriteMsg *pWMsg) { +static int32_t mnodeClusterActionUpdate(SSdbRow *pRow) { return TSDB_CODE_SUCCESS; } -static int32_t mnodeClusterActionEncode(SSWriteMsg *pWMsg) { - SClusterObj *pCluster = pWMsg->pRow; - memcpy(pWMsg->rowData, pCluster, tsClusterUpdateSize); - pWMsg->rowSize = tsClusterUpdateSize; +static int32_t mnodeClusterActionEncode(SSdbRow *pRow) { + SClusterObj *pCluster = pRow->pObj; + memcpy(pRow->rowData, pCluster, tsClusterUpdateSize); + pRow->rowSize = tsClusterUpdateSize; return TSDB_CODE_SUCCESS; } -static int32_t mnodeClusterActionDecode(SSWriteMsg *pWMsg) { +static int32_t mnodeClusterActionDecode(SSdbRow *pRow) { SClusterObj *pCluster = (SClusterObj *) calloc(1, sizeof(SClusterObj)); if (pCluster == NULL) return TSDB_CODE_MND_OUT_OF_MEMORY; - memcpy(pCluster, pWMsg->rowData, tsClusterUpdateSize); - pWMsg->pRow = pCluster; + memcpy(pCluster, pRow->rowData, tsClusterUpdateSize); + pRow->pObj = pCluster; return TSDB_CODE_SUCCESS; } @@ -145,13 +145,13 @@ static int32_t mnodeCreateCluster() { mDebug("uid is %s", pCluster->uid); } - SSWriteMsg wmsg = { + SSdbRow row = { .type = SDB_OPER_GLOBAL, .pTable = tsClusterSdb, - .pRow = pCluster, + .pObj = pCluster, }; - return sdbInsertRow(&wmsg); + return sdbInsertRow(&row); } const char* mnodeGetClusterId() { diff --git a/src/mnode/src/mnodeDb.c b/src/mnode/src/mnodeDb.c index 96658ac73c..d121208447 100644 --- a/src/mnode/src/mnodeDb.c +++ b/src/mnode/src/mnodeDb.c @@ -56,8 +56,8 @@ static void mnodeDestroyDb(SDbObj *pDb) { tfree(pDb); } -static int32_t mnodeDbActionDestroy(SSWriteMsg *pWMsg) { - mnodeDestroyDb(pWMsg->pRow); +static int32_t mnodeDbActionDestroy(SSdbRow *pRow) { + mnodeDestroyDb(pRow->pObj); return TSDB_CODE_SUCCESS; } @@ -65,8 +65,8 @@ int64_t mnodeGetDbNum() { return sdbGetNumOfRows(tsDbSdb); } -static int32_t mnodeDbActionInsert(SSWriteMsg *pWMsg) { - SDbObj *pDb = pWMsg->pRow; +static int32_t mnodeDbActionInsert(SSdbRow *pRow) { + SDbObj *pDb = pRow->pObj; SAcctObj *pAcct = mnodeGetAcct(pDb->acct); pthread_mutex_init(&pDb->mutex, NULL); @@ -91,8 +91,8 @@ static int32_t mnodeDbActionInsert(SSWriteMsg *pWMsg) { return TSDB_CODE_SUCCESS; } -static int32_t mnodeDbActionDelete(SSWriteMsg *pWMsg) { - SDbObj *pDb = pWMsg->pRow; +static int32_t mnodeDbActionDelete(SSdbRow *pRow) { + SDbObj *pDb = pRow->pObj; SAcctObj *pAcct = mnodeGetAcct(pDb->acct); mnodeDropAllChildTables(pDb); @@ -107,11 +107,11 @@ static int32_t mnodeDbActionDelete(SSWriteMsg *pWMsg) { return TSDB_CODE_SUCCESS; } -static int32_t mnodeDbActionUpdate(SSWriteMsg *pWMsg) { - SDbObj *pNew = pWMsg->pRow; +static int32_t mnodeDbActionUpdate(SSdbRow *pRow) { + SDbObj *pNew = pRow->pObj; SDbObj *pDb = mnodeGetDb(pNew->name); if (pDb != NULL && pNew != pDb) { - memcpy(pDb, pNew, pWMsg->rowSize); + memcpy(pDb, pNew, pRow->rowSize); free(pNew->vgList); free(pNew); } @@ -120,19 +120,19 @@ static int32_t mnodeDbActionUpdate(SSWriteMsg *pWMsg) { return TSDB_CODE_SUCCESS; } -static int32_t mnodeDbActionEncode(SSWriteMsg *pWMsg) { - SDbObj *pDb = pWMsg->pRow; - memcpy(pWMsg->rowData, pDb, tsDbUpdateSize); - pWMsg->rowSize = tsDbUpdateSize; +static int32_t mnodeDbActionEncode(SSdbRow *pRow) { + SDbObj *pDb = pRow->pObj; + memcpy(pRow->rowData, pDb, tsDbUpdateSize); + pRow->rowSize = tsDbUpdateSize; return TSDB_CODE_SUCCESS; } -static int32_t mnodeDbActionDecode(SSWriteMsg *pWMsg) { +static int32_t mnodeDbActionDecode(SSdbRow *pRow) { SDbObj *pDb = (SDbObj *) calloc(1, sizeof(SDbObj)); if (pDb == NULL) return TSDB_CODE_MND_OUT_OF_MEMORY; - memcpy(pDb, pWMsg->rowData, tsDbUpdateSize); - pWMsg->pRow = pDb; + memcpy(pDb, pRow->rowData, tsDbUpdateSize); + pRow->pObj = pDb; return TSDB_CODE_SUCCESS; } @@ -412,16 +412,16 @@ static int32_t mnodeCreateDb(SAcctObj *pAcct, SCreateDbMsg *pCreate, SMnodeMsg * pMsg->pDb = pDb; mnodeIncDbRef(pDb); - SSWriteMsg wmsg = { + SSdbRow row = { .type = SDB_OPER_GLOBAL, .pTable = tsDbSdb, - .pRow = pDb, + .pObj = pDb, .rowSize = sizeof(SDbObj), .pMsg = pMsg, .fpRsp = mnodeCreateDbCb }; - code = sdbInsertRow(&wmsg); + code = sdbInsertRow(&row); if (code != TSDB_CODE_SUCCESS && code != TSDB_CODE_MND_ACTION_IN_PROGRESS) { mError("db:%s, failed to create, reason:%s", pDb->name, tstrerror(code)); pMsg->pDb = NULL; @@ -440,8 +440,8 @@ bool mnodeCheckIsMonitorDB(char *db, char *monitordb) { } #if 0 -void mnodePrintVgroups(SDbObj *pDb, char *wmsg) { - mInfo("db:%s, vgroup link from head, wmsg:%s", pDb->name, wmsg); +void mnodePrintVgroups(SDbObj *pDb, char *row) { + mInfo("db:%s, vgroup link from head, row:%s", pDb->name, row); SVgObj *pVgroup = pDb->pHead; while (pVgroup != NULL) { mInfo("vgId:%d", pVgroup->vgId); @@ -807,13 +807,13 @@ static int32_t mnodeSetDbDropping(SDbObj *pDb) { if (pDb->status) return TSDB_CODE_SUCCESS; pDb->status = true; - SSWriteMsg wmsg = { + SSdbRow row = { .type = SDB_OPER_GLOBAL, .pTable = tsDbSdb, - .pRow = pDb + .pObj = pDb }; - int32_t code = sdbUpdateRow(&wmsg); + int32_t code = sdbUpdateRow(&row); if (code != TSDB_CODE_SUCCESS && code != TSDB_CODE_MND_ACTION_IN_PROGRESS) { mError("db:%s, failed to set dropping state, reason:%s", pDb->name, tstrerror(code)); } @@ -1019,15 +1019,15 @@ static int32_t mnodeAlterDb(SDbObj *pDb, SAlterDbMsg *pAlter, void *pMsg) { if (memcmp(&newCfg, &pDb->cfg, sizeof(SDbCfg)) != 0) { pDb->cfg = newCfg; pDb->cfgVersion++; - SSWriteMsg wmsg = { + SSdbRow row = { .type = SDB_OPER_GLOBAL, .pTable = tsDbSdb, - .pRow = pDb, + .pObj = pDb, .pMsg = pMsg, .fpRsp = mnodeAlterDbCb }; - code = sdbUpdateRow(&wmsg); + code = sdbUpdateRow(&row); if (code != TSDB_CODE_SUCCESS && code != TSDB_CODE_MND_ACTION_IN_PROGRESS) { mError("db:%s, failed to alter, reason:%s", pDb->name, tstrerror(code)); } @@ -1071,15 +1071,15 @@ static int32_t mnodeDropDb(SMnodeMsg *pMsg) { SDbObj *pDb = pMsg->pDb; mInfo("db:%s, drop db from sdb", pDb->name); - SSWriteMsg wmsg = { + SSdbRow row = { .type = SDB_OPER_GLOBAL, .pTable = tsDbSdb, - .pRow = pDb, + .pObj = pDb, .pMsg = pMsg, .fpRsp = mnodeDropDbCb }; - int32_t code = sdbDeleteRow(&wmsg); + int32_t code = sdbDeleteRow(&row); if (code != TSDB_CODE_SUCCESS && code != TSDB_CODE_MND_ACTION_IN_PROGRESS) { mError("db:%s, failed to drop, reason:%s", pDb->name, tstrerror(code)); } @@ -1134,13 +1134,13 @@ void mnodeDropAllDbs(SAcctObj *pAcct) { if (pDb->pAcct == pAcct) { mInfo("db:%s, drop db from sdb for acct:%s is dropped", pDb->name, pAcct->user); - SSWriteMsg wmsg = { + SSdbRow row = { .type = SDB_OPER_LOCAL, .pTable = tsDbSdb, - .pRow = pDb + .pObj = pDb }; - sdbDeleteRow(&wmsg); + sdbDeleteRow(&row); numOfDbs++; } mnodeDecDbRef(pDb); diff --git a/src/mnode/src/mnodeDnode.c b/src/mnode/src/mnodeDnode.c index 7b52747951..f76533c760 100644 --- a/src/mnode/src/mnodeDnode.c +++ b/src/mnode/src/mnodeDnode.c @@ -87,13 +87,13 @@ static char* offlineReason[] = { "unknown", }; -static int32_t mnodeDnodeActionDestroy(SSWriteMsg *pWMsg) { - tfree(pWMsg->pRow); +static int32_t mnodeDnodeActionDestroy(SSdbRow *pRow) { + tfree(pRow->pObj); return TSDB_CODE_SUCCESS; } -static int32_t mnodeDnodeActionInsert(SSWriteMsg *pWMsg) { - SDnodeObj *pDnode = pWMsg->pRow; +static int32_t mnodeDnodeActionInsert(SSdbRow *pRow) { + SDnodeObj *pDnode = pRow->pObj; if (pDnode->status != TAOS_DN_STATUS_DROPPING) { pDnode->status = TAOS_DN_STATUS_OFFLINE; pDnode->lastAccess = tsAccessSquence; @@ -107,8 +107,8 @@ static int32_t mnodeDnodeActionInsert(SSWriteMsg *pWMsg) { return TSDB_CODE_SUCCESS; } -static int32_t mnodeDnodeActionDelete(SSWriteMsg *pWMsg) { - SDnodeObj *pDnode = pWMsg->pRow; +static int32_t mnodeDnodeActionDelete(SSdbRow *pRow) { + SDnodeObj *pDnode = pRow->pObj; #ifndef _SYNC mnodeDropAllDnodeVgroups(pDnode); @@ -121,11 +121,11 @@ static int32_t mnodeDnodeActionDelete(SSWriteMsg *pWMsg) { return TSDB_CODE_SUCCESS; } -static int32_t mnodeDnodeActionUpdate(SSWriteMsg *pWMsg) { - SDnodeObj *pNew = pWMsg->pRow; +static int32_t mnodeDnodeActionUpdate(SSdbRow *pRow) { + SDnodeObj *pNew = pRow->pObj; SDnodeObj *pDnode = mnodeGetDnode(pNew->dnodeId); if (pDnode != NULL && pNew != pDnode) { - memcpy(pDnode, pNew, pWMsg->rowSize); + memcpy(pDnode, pNew, pRow->rowSize); free(pNew); } mnodeDecDnodeRef(pDnode); @@ -134,19 +134,19 @@ static int32_t mnodeDnodeActionUpdate(SSWriteMsg *pWMsg) { return TSDB_CODE_SUCCESS; } -static int32_t mnodeDnodeActionEncode(SSWriteMsg *pWMsg) { - SDnodeObj *pDnode = pWMsg->pRow; - memcpy(pWMsg->rowData, pDnode, tsDnodeUpdateSize); - pWMsg->rowSize = tsDnodeUpdateSize; +static int32_t mnodeDnodeActionEncode(SSdbRow *pRow) { + SDnodeObj *pDnode = pRow->pObj; + memcpy(pRow->rowData, pDnode, tsDnodeUpdateSize); + pRow->rowSize = tsDnodeUpdateSize; return TSDB_CODE_SUCCESS; } -static int32_t mnodeDnodeActionDecode(SSWriteMsg *pWMsg) { +static int32_t mnodeDnodeActionDecode(SSdbRow *pRow) { SDnodeObj *pDnode = (SDnodeObj *) calloc(1, sizeof(SDnodeObj)); if (pDnode == NULL) return TSDB_CODE_MND_OUT_OF_MEMORY; - memcpy(pDnode, pWMsg->rowData, tsDnodeUpdateSize); - pWMsg->pRow = pDnode; + memcpy(pDnode, pRow->rowData, tsDnodeUpdateSize); + pRow->pObj = pDnode; return TSDB_CODE_SUCCESS; } @@ -296,13 +296,13 @@ void mnodeDecDnodeRef(SDnodeObj *pDnode) { } void mnodeUpdateDnode(SDnodeObj *pDnode) { - SSWriteMsg wmsg = { + SSdbRow row = { .type = SDB_OPER_GLOBAL, .pTable = tsDnodeSdb, - .pRow = pDnode + .pObj = pDnode }; - int32_t code = sdbUpdateRow(&wmsg); + int32_t code = sdbUpdateRow(&row); if (code != TSDB_CODE_SUCCESS && code != TSDB_CODE_MND_ACTION_IN_PROGRESS) { mError("dnodeId:%d, failed update", pDnode->dnodeId); } @@ -644,15 +644,15 @@ static int32_t mnodeCreateDnode(char *ep, SMnodeMsg *pMsg) { tstrncpy(pDnode->dnodeEp, ep, TSDB_EP_LEN); taosGetFqdnPortFromEp(ep, pDnode->dnodeFqdn, &pDnode->dnodePort); - SSWriteMsg wmsg = { + SSdbRow row = { .type = SDB_OPER_GLOBAL, .pTable = tsDnodeSdb, - .pRow = pDnode, + .pObj = pDnode, .rowSize = sizeof(SDnodeObj), .pMsg = pMsg }; - int32_t code = sdbInsertRow(&wmsg); + int32_t code = sdbInsertRow(&row); if (code != TSDB_CODE_SUCCESS && code != TSDB_CODE_MND_ACTION_IN_PROGRESS) { int dnodeId = pDnode->dnodeId; tfree(pDnode); @@ -665,14 +665,14 @@ static int32_t mnodeCreateDnode(char *ep, SMnodeMsg *pMsg) { } int32_t mnodeDropDnode(SDnodeObj *pDnode, void *pMsg) { - SSWriteMsg wmsg = { + SSdbRow row = { .type = SDB_OPER_GLOBAL, .pTable = tsDnodeSdb, - .pRow = pDnode, + .pObj = pDnode, .pMsg = pMsg }; - int32_t code = sdbDeleteRow(&wmsg); + int32_t code = sdbDeleteRow(&row); if (code != TSDB_CODE_SUCCESS && code != TSDB_CODE_MND_ACTION_IN_PROGRESS) { mError("dnode:%d, failed to drop from cluster, result:%s", pDnode->dnodeId, tstrerror(code)); } else { diff --git a/src/mnode/src/mnodeMnode.c b/src/mnode/src/mnodeMnode.c index a97aef61e9..205bfda4b9 100644 --- a/src/mnode/src/mnodeMnode.c +++ b/src/mnode/src/mnodeMnode.c @@ -58,13 +58,13 @@ static int32_t mnodeRetrieveMnodes(SShowObj *pShow, char *data, int32_t rows, vo #define mnodeMnodeDestroyLock() pthread_mutex_destroy(&tsMnodeLock) #endif -static int32_t mnodeMnodeActionDestroy(SSWriteMsg *pWMsg) { - tfree(pWMsg->pRow); +static int32_t mnodeMnodeActionDestroy(SSdbRow *pRow) { + tfree(pRow->pObj); return TSDB_CODE_SUCCESS; } -static int32_t mnodeMnodeActionInsert(SSWriteMsg *pWMsg) { - SMnodeObj *pMnode = pWMsg->pRow; +static int32_t mnodeMnodeActionInsert(SSdbRow *pRow) { + SMnodeObj *pMnode = pRow->pObj; SDnodeObj *pDnode = mnodeGetDnode(pMnode->mnodeId); if (pDnode == NULL) return TSDB_CODE_MND_DNODE_NOT_EXIST; @@ -76,8 +76,8 @@ static int32_t mnodeMnodeActionInsert(SSWriteMsg *pWMsg) { return TSDB_CODE_SUCCESS; } -static int32_t mnodeMnodeActionDelete(SSWriteMsg *pWMsg) { - SMnodeObj *pMnode = pWMsg->pRow; +static int32_t mnodeMnodeActionDelete(SSdbRow *pRow) { + SMnodeObj *pMnode = pRow->pObj; SDnodeObj *pDnode = mnodeGetDnode(pMnode->mnodeId); if (pDnode == NULL) return TSDB_CODE_MND_DNODE_NOT_EXIST; @@ -88,30 +88,30 @@ static int32_t mnodeMnodeActionDelete(SSWriteMsg *pWMsg) { return TSDB_CODE_SUCCESS; } -static int32_t mnodeMnodeActionUpdate(SSWriteMsg *pWMsg) { - SMnodeObj *pMnode = pWMsg->pRow; +static int32_t mnodeMnodeActionUpdate(SSdbRow *pRow) { + SMnodeObj *pMnode = pRow->pObj; SMnodeObj *pSaved = mnodeGetMnode(pMnode->mnodeId); if (pMnode != pSaved) { - memcpy(pSaved, pMnode, pWMsg->rowSize); + memcpy(pSaved, pMnode, pRow->rowSize); free(pMnode); } mnodeDecMnodeRef(pSaved); return TSDB_CODE_SUCCESS; } -static int32_t mnodeMnodeActionEncode(SSWriteMsg *pWMsg) { - SMnodeObj *pMnode = pWMsg->pRow; - memcpy(pWMsg->rowData, pMnode, tsMnodeUpdateSize); - pWMsg->rowSize = tsMnodeUpdateSize; +static int32_t mnodeMnodeActionEncode(SSdbRow *pRow) { + SMnodeObj *pMnode = pRow->pObj; + memcpy(pRow->rowData, pMnode, tsMnodeUpdateSize); + pRow->rowSize = tsMnodeUpdateSize; return TSDB_CODE_SUCCESS; } -static int32_t mnodeMnodeActionDecode(SSWriteMsg *pWMsg) { +static int32_t mnodeMnodeActionDecode(SSdbRow *pRow) { SMnodeObj *pMnode = calloc(1, sizeof(SMnodeObj)); if (pMnode == NULL) return TSDB_CODE_MND_OUT_OF_MEMORY; - memcpy(pMnode, pWMsg->rowData, tsMnodeUpdateSize); - pWMsg->pRow = pMnode; + memcpy(pMnode, pRow->rowData, tsMnodeUpdateSize); + pRow->pObj = pMnode; return TSDB_CODE_SUCCESS; } @@ -325,10 +325,10 @@ void mnodeCreateMnode(int32_t dnodeId, char *dnodeEp, bool needConfirm) { pMnode->mnodeId = dnodeId; pMnode->createdTime = taosGetTimestampMs(); - SSWriteMsg wmsg = { + SSdbRow row = { .type = SDB_OPER_GLOBAL, .pTable = tsMnodeSdb, - .pRow = pMnode, + .pObj = pMnode, .fpRsp = mnodeCreateMnodeCb }; @@ -342,7 +342,7 @@ void mnodeCreateMnode(int32_t dnodeId, char *dnodeEp, bool needConfirm) { return; } - code = sdbInsertRow(&wmsg); + code = sdbInsertRow(&row); if (code != TSDB_CODE_SUCCESS && code != TSDB_CODE_MND_ACTION_IN_PROGRESS) { mError("dnode:%d, failed to create mnode, ep:%s reason:%s", dnodeId, dnodeEp, tstrerror(code)); tfree(pMnode); @@ -352,8 +352,8 @@ void mnodeCreateMnode(int32_t dnodeId, char *dnodeEp, bool needConfirm) { void mnodeDropMnodeLocal(int32_t dnodeId) { SMnodeObj *pMnode = mnodeGetMnode(dnodeId); if (pMnode != NULL) { - SSWriteMsg wmsg = {.type = SDB_OPER_LOCAL, .pTable = tsMnodeSdb, .pRow = pMnode}; - sdbDeleteRow(&wmsg); + SSdbRow row = {.type = SDB_OPER_LOCAL, .pTable = tsMnodeSdb, .pObj = pMnode}; + sdbDeleteRow(&row); mnodeDecMnodeRef(pMnode); } @@ -367,13 +367,13 @@ int32_t mnodeDropMnode(int32_t dnodeId) { return TSDB_CODE_MND_DNODE_NOT_EXIST; } - SSWriteMsg wmsg = { + SSdbRow row = { .type = SDB_OPER_GLOBAL, .pTable = tsMnodeSdb, - .pRow = pMnode + .pObj = pMnode }; - int32_t code = sdbDeleteRow(&wmsg); + int32_t code = sdbDeleteRow(&row); sdbDecRef(tsMnodeSdb, pMnode); diff --git a/src/mnode/src/mnodeSdb.c b/src/mnode/src/mnodeSdb.c index 15e638d436..a79eec16aa 100644 --- a/src/mnode/src/mnodeSdb.c +++ b/src/mnode/src/mnodeSdb.c @@ -65,12 +65,12 @@ typedef struct SSdbTable { int32_t autoIndex; int64_t numOfRows; void * iHandle; - int32_t (*fpInsert)(SSWriteMsg *pWrite); - int32_t (*fpDelete)(SSWriteMsg *pWrite); - int32_t (*fpUpdate)(SSWriteMsg *pWrite); - int32_t (*fpDecode)(SSWriteMsg *pWrite); - int32_t (*fpEncode)(SSWriteMsg *pWrite); - int32_t (*fpDestroy)(SSWriteMsg *pWrite); + int32_t (*fpInsert)(SSdbRow *pRow); + int32_t (*fpDelete)(SSdbRow *pRow); + int32_t (*fpUpdate)(SSdbRow *pRow); + int32_t (*fpDecode)(SSdbRow *pRow); + int32_t (*fpEncode)(SSdbRow *pRow); + int32_t (*fpDestroy)(SSdbRow *pRow); int32_t (*fpRestored)(); pthread_mutex_t mutex; } SSdbTable; @@ -106,17 +106,17 @@ static taos_qall tsSdbWQall; static taos_queue tsSdbWQueue; static SSdbWorkerPool tsSdbPool; -static int32_t sdbProcessWrite(void *pWrite, void *pHead, int32_t qtype, void *unused); +static int32_t sdbProcessWrite(void *pRow, void *pHead, int32_t qtype, void *unused); static int32_t sdbWriteWalToQueue(void *vparam, void *pHead, int32_t qtype, void *rparam); -static int32_t sdbWriteRowToQueue(SSWriteMsg *pInputWrite, int32_t action); +static int32_t sdbWriteRowToQueue(SSdbRow *pRow, int32_t action); static void * sdbWorkerFp(void *pWorker); static int32_t sdbInitWorker(); static void sdbCleanupWorker(); static int32_t sdbAllocQueue(); static void sdbFreeQueue(); -static int32_t sdbInsertHash(SSdbTable *pTable, SSWriteMsg *pWrite); -static int32_t sdbUpdateHash(SSdbTable *pTable, SSWriteMsg *pWrite); -static int32_t sdbDeleteHash(SSdbTable *pTable, SSWriteMsg *pWrite); +static int32_t sdbInsertHash(SSdbTable *pTable, SSdbRow *pRow); +static int32_t sdbUpdateHash(SSdbTable *pTable, SSdbRow *pRow); +static int32_t sdbDeleteHash(SSdbTable *pTable, SSdbRow *pRow); int32_t sdbGetId(void *pTable) { return ((SSdbTable *)pTable)->autoIndex; @@ -248,28 +248,28 @@ static void sdbNotifyRole(void *ahandle, int8_t role) { } // failed to forward, need revert insert -static void sdbHandleFailedConfirm(SSWriteMsg *pWrite) { - SWalHead *pHead = pWrite->pHead; +static void sdbHandleFailedConfirm(SSdbRow *pRow) { + SWalHead *pHead = pRow->pHead; int32_t action = pHead->msgType % 10; - sdbError("vgId:1, row:%p:%s hver:%" PRIu64 " action:%s, failed to foward since %s", pWrite->pRow, - sdbGetKeyStr(pWrite->pTable, pHead->cont), pHead->version, actStr[action], tstrerror(pWrite->code)); + sdbError("vgId:1, row:%p:%s hver:%" PRIu64 " action:%s, failed to foward since %s", pRow->pObj, + sdbGetKeyStr(pRow->pTable, pHead->cont), pHead->version, actStr[action], tstrerror(pRow->code)); // It's better to create a table in two stages, create it first and then set it success if (action == SDB_ACTION_INSERT) { - SSWriteMsg wmsg = {.type = SDB_OPER_GLOBAL, .pTable = pWrite->pTable, .pRow = pWrite->pRow}; - sdbDeleteRow(&wmsg); + SSdbRow row = {.type = SDB_OPER_GLOBAL, .pTable = pRow->pTable, .pObj = pRow->pObj}; + sdbDeleteRow(&row); } } FORCE_INLINE static void sdbConfirmForward(void *ahandle, void *wparam, int32_t code) { if (wparam == NULL) return; - SSWriteMsg *pWrite = wparam; - SMnodeMsg * pMsg = pWrite->pMsg; + SSdbRow *pRow = wparam; + SMnodeMsg * pMsg = pRow->pMsg; - if (code <= 0) pWrite->code = code; - int32_t count = atomic_add_fetch_32(&pWrite->processedCount, 1); + if (code <= 0) pRow->code = code; + int32_t count = atomic_add_fetch_32(&pRow->processedCount, 1); if (count <= 1) { if (pMsg != NULL) sdbTrace("vgId:1, msg:%p waiting for confirm, count:%d code:%x", pMsg, count, code); return; @@ -277,13 +277,13 @@ static void sdbConfirmForward(void *ahandle, void *wparam, int32_t code) { if (pMsg != NULL) sdbTrace("vgId:1, msg:%p is confirmed, code:%x", pMsg, code); } - if (pWrite->code != TSDB_CODE_SUCCESS) sdbHandleFailedConfirm(pWrite); + if (pRow->code != TSDB_CODE_SUCCESS) sdbHandleFailedConfirm(pRow); - if (pWrite->fpRsp != NULL) { - pWrite->code = (*pWrite->fpRsp)(pMsg, pWrite->code); + if (pRow->fpRsp != NULL) { + pRow->code = (*pRow->fpRsp)(pMsg, pRow->code); } - dnodeSendRpcMWriteRsp(pMsg, pWrite->code); + dnodeSendRpcMWriteRsp(pMsg, pRow->code); } static void sdbUpdateSyncTmrFp(void *param, void *tmrId) { sdbUpdateSync(NULL); } @@ -447,8 +447,8 @@ void sdbDecRef(void *tparam, void *pRow) { int32_t *updateEnd = pRow + pTable->refCountPos - 4; if (refCount <= 0 && *updateEnd) { sdbTrace("vgId:1, sdb:%s, row:%p:%s:%d destroyed", pTable->name, pRow, sdbGetRowStr(pTable, pRow), refCount); - SSWriteMsg wmsg = {.pRow = pRow}; - (*pTable->fpDestroy)(&wmsg); + SSdbRow row = {.pObj = pRow}; + (*pTable->fpDestroy)(&row); } } @@ -485,8 +485,8 @@ static void *sdbGetRowFromObj(SSdbTable *pTable, void *key) { return sdbGetRow(pTable, sdbGetObjKey(pTable, key)); } -static int32_t sdbInsertHash(SSdbTable *pTable, SSWriteMsg *pWrite) { - void * key = sdbGetObjKey(pTable, pWrite->pRow); +static int32_t sdbInsertHash(SSdbTable *pTable, SSdbRow *pRow) { + void * key = sdbGetObjKey(pTable, pRow->pObj); int32_t keySize = sizeof(int32_t); if (pTable->keyType == SDB_KEY_STRING || pTable->keyType == SDB_KEY_VAR_STRING) { @@ -494,43 +494,43 @@ static int32_t sdbInsertHash(SSdbTable *pTable, SSWriteMsg *pWrite) { } pthread_mutex_lock(&pTable->mutex); - taosHashPut(pTable->iHandle, key, keySize, &pWrite->pRow, sizeof(int64_t)); + taosHashPut(pTable->iHandle, key, keySize, &pRow->pObj, sizeof(int64_t)); pthread_mutex_unlock(&pTable->mutex); - sdbIncRef(pTable, pWrite->pRow); + sdbIncRef(pTable, pRow->pObj); atomic_add_fetch_32(&pTable->numOfRows, 1); if (pTable->keyType == SDB_KEY_AUTO) { - pTable->autoIndex = MAX(pTable->autoIndex, *((uint32_t *)pWrite->pRow)); + pTable->autoIndex = MAX(pTable->autoIndex, *((uint32_t *)pRow->pObj)); } else { atomic_add_fetch_32(&pTable->autoIndex, 1); } sdbDebug("vgId:1, sdb:%s, insert key:%s to hash, rowSize:%d rows:%" PRId64 ", msg:%p", pTable->name, - sdbGetRowStr(pTable, pWrite->pRow), pWrite->rowSize, pTable->numOfRows, pWrite->pMsg); + sdbGetRowStr(pTable, pRow->pObj), pRow->rowSize, pTable->numOfRows, pRow->pMsg); - int32_t code = (*pTable->fpInsert)(pWrite); + int32_t code = (*pTable->fpInsert)(pRow); if (code != TSDB_CODE_SUCCESS) { sdbError("vgId:1, sdb:%s, failed to insert key:%s to hash, remove it", pTable->name, - sdbGetRowStr(pTable, pWrite->pRow)); - sdbDeleteHash(pTable, pWrite); + sdbGetRowStr(pTable, pRow->pObj)); + sdbDeleteHash(pTable, pRow); } return TSDB_CODE_SUCCESS; } -static int32_t sdbDeleteHash(SSdbTable *pTable, SSWriteMsg *pWrite) { - int32_t *updateEnd = pWrite->pRow + pTable->refCountPos - 4; +static int32_t sdbDeleteHash(SSdbTable *pTable, SSdbRow *pRow) { + int32_t *updateEnd = pRow->pObj + pTable->refCountPos - 4; bool set = atomic_val_compare_exchange_32(updateEnd, 0, 1) == 0; if (!set) { sdbError("vgId:1, sdb:%s, failed to delete key:%s from hash, for it already removed", pTable->name, - sdbGetRowStr(pTable, pWrite->pRow)); + sdbGetRowStr(pTable, pRow->pObj)); return TSDB_CODE_MND_SDB_OBJ_NOT_THERE; } - (*pTable->fpDelete)(pWrite); + (*pTable->fpDelete)(pRow); - void * key = sdbGetObjKey(pTable, pWrite->pRow); + void * key = sdbGetObjKey(pTable, pRow->pObj); int32_t keySize = sizeof(int32_t); if (pTable->keyType == SDB_KEY_STRING || pTable->keyType == SDB_KEY_VAR_STRING) { keySize = strlen((char *)key); @@ -543,23 +543,23 @@ static int32_t sdbDeleteHash(SSdbTable *pTable, SSWriteMsg *pWrite) { atomic_sub_fetch_32(&pTable->numOfRows, 1); sdbDebug("vgId:1, sdb:%s, delete key:%s from hash, numOfRows:%" PRId64 ", msg:%p", pTable->name, - sdbGetRowStr(pTable, pWrite->pRow), pTable->numOfRows, pWrite->pMsg); + sdbGetRowStr(pTable, pRow->pObj), pTable->numOfRows, pRow->pMsg); - sdbDecRef(pTable, pWrite->pRow); + sdbDecRef(pTable, pRow->pObj); return TSDB_CODE_SUCCESS; } -static int32_t sdbUpdateHash(SSdbTable *pTable, SSWriteMsg *pWrite) { +static int32_t sdbUpdateHash(SSdbTable *pTable, SSdbRow *pRow) { sdbDebug("vgId:1, sdb:%s, update key:%s in hash, numOfRows:%" PRId64 ", msg:%p", pTable->name, - sdbGetRowStr(pTable, pWrite->pRow), pTable->numOfRows, pWrite->pMsg); + sdbGetRowStr(pTable, pRow->pObj), pTable->numOfRows, pRow->pMsg); - (*pTable->fpUpdate)(pWrite); + (*pTable->fpUpdate)(pRow); return TSDB_CODE_SUCCESS; } static int sdbProcessWrite(void *wparam, void *hparam, int32_t qtype, void *unused) { - SSWriteMsg *pWrite = wparam; + SSdbRow *pRow = wparam; SWalHead *pHead = hparam; int32_t tableId = pHead->msgType / 10; int32_t action = pHead->msgType % 10; @@ -598,22 +598,22 @@ static int sdbProcessWrite(void *wparam, void *hparam, int32_t qtype, void *unus pthread_mutex_unlock(&tsSdbMgmt.mutex); - // from app, wmsg is created - if (pWrite != NULL) { + // from app, row is created + if (pRow != NULL) { // forward to peers - pWrite->processedCount = 0; - int32_t syncCode = syncForwardToPeer(tsSdbMgmt.sync, pHead, pWrite, TAOS_QTYPE_RPC); - if (syncCode <= 0) pWrite->processedCount = 1; + pRow->processedCount = 0; + int32_t syncCode = syncForwardToPeer(tsSdbMgmt.sync, pHead, pRow, TAOS_QTYPE_RPC); + if (syncCode <= 0) pRow->processedCount = 1; if (syncCode < 0) { sdbError("vgId:1, sdb:%s, failed to forward req since %s action:%s key:%s hver:%" PRIu64 ", msg:%p", pTable->name, - tstrerror(syncCode), actStr[action], sdbGetKeyStr(pTable, pHead->cont), pHead->version, pWrite->pMsg); + tstrerror(syncCode), actStr[action], sdbGetKeyStr(pTable, pHead->cont), pHead->version, pRow->pMsg); } else if (syncCode > 0) { sdbDebug("vgId:1, sdb:%s, forward req is sent, action:%s key:%s hver:%" PRIu64 ", msg:%p", pTable->name, - actStr[action], sdbGetKeyStr(pTable, pHead->cont), pHead->version, pWrite->pMsg); + actStr[action], sdbGetKeyStr(pTable, pHead->cont), pHead->version, pRow->pMsg); } else { sdbTrace("vgId:1, sdb:%s, no need to send fwd req, action:%s key:%s hver:%" PRIu64 ", msg:%p", pTable->name, - actStr[action], sdbGetKeyStr(pTable, pHead->cont), pHead->version, pWrite->pMsg); + actStr[action], sdbGetKeyStr(pTable, pHead->cont), pHead->version, pRow->pMsg); } return syncCode; } @@ -622,71 +622,71 @@ static int sdbProcessWrite(void *wparam, void *hparam, int32_t qtype, void *unus actStr[action], sdbGetKeyStr(pTable, pHead->cont), pHead->version); // even it is WAL/FWD, it shall be called to update version in sync - syncForwardToPeer(tsSdbMgmt.sync, pHead, pWrite, TAOS_QTYPE_RPC); + syncForwardToPeer(tsSdbMgmt.sync, pHead, pRow, TAOS_QTYPE_RPC); - // from wal or forward msg, wmsg not created, should add into hash + // from wal or forward msg, row not created, should add into hash if (action == SDB_ACTION_INSERT) { - SSWriteMsg wmsg = {.rowSize = pHead->len, .rowData = pHead->cont, .pTable = pTable}; - code = (*pTable->fpDecode)(&wmsg); - return sdbInsertHash(pTable, &wmsg); + SSdbRow row = {.rowSize = pHead->len, .rowData = pHead->cont, .pTable = pTable}; + code = (*pTable->fpDecode)(&row); + return sdbInsertHash(pTable, &row); } else if (action == SDB_ACTION_DELETE) { - void *pRow = sdbGetRowMeta(pTable, pHead->cont); - if (pRow == NULL) { + void *pObj = sdbGetRowMeta(pTable, pHead->cont); + if (pObj == NULL) { sdbDebug("vgId:1, sdb:%s, object:%s not exist in hash, ignore delete action", pTable->name, sdbGetKeyStr(pTable, pHead->cont)); return TSDB_CODE_SUCCESS; } - SSWriteMsg wmsg = {.pTable = pTable, .pRow = pRow}; - return sdbDeleteHash(pTable, &wmsg); + SSdbRow row = {.pTable = pTable, .pObj = pObj}; + return sdbDeleteHash(pTable, &row); } else if (action == SDB_ACTION_UPDATE) { - void *pRow = sdbGetRowMeta(pTable, pHead->cont); - if (pRow == NULL) { + void *pObj = sdbGetRowMeta(pTable, pHead->cont); + if (pObj == NULL) { sdbDebug("vgId:1, sdb:%s, object:%s not exist in hash, ignore update action", pTable->name, sdbGetKeyStr(pTable, pHead->cont)); return TSDB_CODE_SUCCESS; } - SSWriteMsg wmsg = {.rowSize = pHead->len, .rowData = pHead->cont, .pTable = pTable}; - code = (*pTable->fpDecode)(&wmsg); - return sdbUpdateHash(pTable, &wmsg); + SSdbRow row = {.rowSize = pHead->len, .rowData = pHead->cont, .pTable = pTable}; + code = (*pTable->fpDecode)(&row); + return sdbUpdateHash(pTable, &row); } else { return TSDB_CODE_MND_INVALID_MSG_TYPE; } } -int32_t sdbInsertRow(SSWriteMsg *pWrite) { - SSdbTable *pTable = pWrite->pTable; +int32_t sdbInsertRow(SSdbRow *pRow) { + SSdbTable *pTable = pRow->pTable; if (pTable == NULL) return TSDB_CODE_MND_SDB_INVALID_TABLE_TYPE; - if (sdbGetRowFromObj(pTable, pWrite->pRow)) { - sdbError("vgId:1, sdb:%s, failed to insert:%s since it exist", pTable->name, sdbGetRowStr(pTable, pWrite->pRow)); - sdbDecRef(pTable, pWrite->pRow); + if (sdbGetRowFromObj(pTable, pRow->pObj)) { + sdbError("vgId:1, sdb:%s, failed to insert:%s since it exist", pTable->name, sdbGetRowStr(pTable, pRow->pObj)); + sdbDecRef(pTable, pRow->pObj); return TSDB_CODE_MND_SDB_OBJ_ALREADY_THERE; } if (pTable->keyType == SDB_KEY_AUTO) { - *((uint32_t *)pWrite->pRow) = atomic_add_fetch_32(&pTable->autoIndex, 1); + *((uint32_t *)pRow->pObj) = atomic_add_fetch_32(&pTable->autoIndex, 1); // let vgId increase from 2 if (pTable->autoIndex == 1 && pTable->id == SDB_TABLE_VGROUP) { - *((uint32_t *)pWrite->pRow) = atomic_add_fetch_32(&pTable->autoIndex, 1); + *((uint32_t *)pRow->pObj) = atomic_add_fetch_32(&pTable->autoIndex, 1); } } - int32_t code = sdbInsertHash(pTable, pWrite); + int32_t code = sdbInsertHash(pTable, pRow); if (code != TSDB_CODE_SUCCESS) { - sdbError("vgId:1, sdb:%s, failed to insert:%s into hash", pTable->name, sdbGetRowStr(pTable, pWrite->pRow)); + sdbError("vgId:1, sdb:%s, failed to insert:%s into hash", pTable->name, sdbGetRowStr(pTable, pRow->pObj)); return code; } // just insert data into memory - if (pWrite->type != SDB_OPER_GLOBAL) { + if (pRow->type != SDB_OPER_GLOBAL) { return TSDB_CODE_SUCCESS; } - if (pWrite->fpReq) { - return (*pWrite->fpReq)(pWrite->pMsg); + if (pRow->fpReq) { + return (*pRow->fpReq)(pRow->pMsg); } else { - return sdbWriteRowToQueue(pWrite, SDB_ACTION_INSERT); + return sdbWriteRowToQueue(pRow, SDB_ACTION_INSERT); } } @@ -698,59 +698,59 @@ bool sdbCheckRowDeleted(void *tparam, void *pRow) { return atomic_val_compare_exchange_32(updateEnd, 1, 1) == 1; } -int32_t sdbDeleteRow(SSWriteMsg *pWrite) { - SSdbTable *pTable = pWrite->pTable; +int32_t sdbDeleteRow(SSdbRow *pRow) { + SSdbTable *pTable = pRow->pTable; if (pTable == NULL) return TSDB_CODE_MND_SDB_INVALID_TABLE_TYPE; - void *pRow = sdbGetRowMetaFromObj(pTable, pWrite->pRow); - if (pRow == NULL) { + void *pObj = sdbGetRowMetaFromObj(pTable, pRow->pObj); + if (pObj == NULL) { sdbDebug("vgId:1, sdb:%s, record is not there, delete failed", pTable->name); return TSDB_CODE_MND_SDB_OBJ_NOT_THERE; } - int32_t code = sdbDeleteHash(pTable, pWrite); + int32_t code = sdbDeleteHash(pTable, pRow); if (code != TSDB_CODE_SUCCESS) { sdbError("vgId:1, sdb:%s, failed to delete from hash", pTable->name); return code; } // just delete data from memory - if (pWrite->type != SDB_OPER_GLOBAL) { + if (pRow->type != SDB_OPER_GLOBAL) { return TSDB_CODE_SUCCESS; } - if (pWrite->fpReq) { - return (*pWrite->fpReq)(pWrite->pMsg); + if (pRow->fpReq) { + return (*pRow->fpReq)(pRow->pMsg); } else { - return sdbWriteRowToQueue(pWrite, SDB_ACTION_DELETE); + return sdbWriteRowToQueue(pRow, SDB_ACTION_DELETE); } } -int32_t sdbUpdateRow(SSWriteMsg *pWrite) { - SSdbTable *pTable = pWrite->pTable; +int32_t sdbUpdateRow(SSdbRow *pRow) { + SSdbTable *pTable = pRow->pTable; if (pTable == NULL) return TSDB_CODE_MND_SDB_INVALID_TABLE_TYPE; - void *pRow = sdbGetRowMetaFromObj(pTable, pWrite->pRow); - if (pRow == NULL) { + void *pObj = sdbGetRowMetaFromObj(pTable, pRow->pObj); + if (pObj == NULL) { sdbDebug("vgId:1, sdb:%s, record is not there, update failed", pTable->name); return TSDB_CODE_MND_SDB_OBJ_NOT_THERE; } - int32_t code = sdbUpdateHash(pTable, pWrite); + int32_t code = sdbUpdateHash(pTable, pRow); if (code != TSDB_CODE_SUCCESS) { sdbError("vgId:1, sdb:%s, failed to update hash", pTable->name); return code; } // just update data in memory - if (pWrite->type != SDB_OPER_GLOBAL) { + if (pRow->type != SDB_OPER_GLOBAL) { return TSDB_CODE_SUCCESS; } - if (pWrite->fpReq) { - return (*pWrite->fpReq)(pWrite->pMsg); + if (pRow->fpReq) { + return (*pRow->fpReq)(pRow->pMsg); } else { - return sdbWriteRowToQueue(pWrite, SDB_ACTION_UPDATE); + return sdbWriteRowToQueue(pRow, SDB_ACTION_UPDATE); } } @@ -830,12 +830,12 @@ void sdbCloseTable(void *handle) { void **ppRow = taosHashIterGet(pIter); if (ppRow == NULL) continue; - SSWriteMsg wmsg = { - .pRow = *ppRow, + SSdbRow row = { + .pObj = *ppRow, .pTable = pTable, }; - (*pTable->fpDestroy)(&wmsg); + (*pTable->fpDestroy)(&row); } taosHashDestroyIter(pIter); @@ -934,12 +934,12 @@ static void sdbFreeQueue() { tsSdbWQueue = NULL; } -static int32_t sdbWriteToQueue(SSWriteMsg *pWrite, int32_t qtype) { - SWalHead *pHead = pWrite->pHead; +static int32_t sdbWriteToQueue(SSdbRow *pRow, int32_t qtype) { + SWalHead *pHead = pRow->pHead; if (pHead->len > TSDB_MAX_WAL_SIZE) { sdbError("vgId:1, wal len:%d exceeds limit, hver:%" PRIu64, pHead->len, pHead->version); - taosFreeQitem(pWrite); + taosFreeQitem(pRow); return TSDB_CODE_WAL_SIZE_LIMIT; } @@ -949,64 +949,64 @@ static int32_t sdbWriteToQueue(SSWriteMsg *pWrite, int32_t qtype) { taosMsleep(1); } - sdbIncRef(pWrite->pTable, pWrite->pRow); + sdbIncRef(pRow->pTable, pRow->pObj); - sdbTrace("vgId:1, msg:%p write into to sdb queue", pWrite->pMsg); - taosWriteQitem(tsSdbWQueue, qtype, pWrite); + sdbTrace("vgId:1, msg:%p write into to sdb queue", pRow->pMsg); + taosWriteQitem(tsSdbWQueue, qtype, pRow); return TSDB_CODE_MND_ACTION_IN_PROGRESS; } -static void sdbFreeFromQueue(SSWriteMsg *pWrite) { +static void sdbFreeFromQueue(SSdbRow *pRow) { int32_t queued = atomic_sub_fetch_32(&tsSdbMgmt.queuedMsg, 1); - sdbTrace("vgId:1, msg:%p free from sdb queue, queued:%d", pWrite->pMsg, queued); + sdbTrace("vgId:1, msg:%p free from sdb queue, queued:%d", pRow->pMsg, queued); - sdbDecRef(pWrite->pTable, pWrite->pRow); - taosFreeQitem(pWrite); + sdbDecRef(pRow->pTable, pRow->pObj); + taosFreeQitem(pRow); } static int32_t sdbWriteWalToQueue(void *vparam, void *wparam, int32_t qtype, void *rparam) { SWalHead *pHead = wparam; - int32_t size = sizeof(SSWriteMsg) + sizeof(SWalHead) + pHead->len; - SSWriteMsg *pWrite = taosAllocateQitem(size); - if (pWrite == NULL) { + int32_t size = sizeof(SSdbRow) + sizeof(SWalHead) + pHead->len; + SSdbRow *pRow = taosAllocateQitem(size); + if (pRow == NULL) { return TSDB_CODE_VND_OUT_OF_MEMORY; } - return sdbWriteToQueue(pWrite, qtype); + return sdbWriteToQueue(pRow, qtype); } -static int32_t sdbWriteRowToQueue(SSWriteMsg *pInputWrite, int32_t action) { - SSdbTable *pTable = pInputWrite->pTable; +static int32_t sdbWriteRowToQueue(SSdbRow *pInputRow, int32_t action) { + SSdbTable *pTable = pInputRow->pTable; if (pTable == NULL) return TSDB_CODE_MND_SDB_INVALID_TABLE_TYPE; - int32_t size = sizeof(SSWriteMsg) + sizeof(SWalHead) + pTable->maxRowSize; - SSWriteMsg *pWrite = taosAllocateQitem(size); - if (pWrite == NULL) { + int32_t size = sizeof(SSdbRow) + sizeof(SWalHead) + pTable->maxRowSize; + SSdbRow *pRow = taosAllocateQitem(size); + if (pRow == NULL) { return TSDB_CODE_VND_OUT_OF_MEMORY; } - memcpy(pWrite, pInputWrite, sizeof(SSWriteMsg)); - pWrite->processedCount = 1; + memcpy(pRow, pInputRow, sizeof(SSdbRow)); + pRow->processedCount = 1; - SWalHead *pHead = pWrite->pHead; - pWrite->rowData = pHead->cont; - (*pTable->fpEncode)(pWrite); + SWalHead *pHead = pRow->pHead; + pRow->rowData = pHead->cont; + (*pTable->fpEncode)(pRow); - pHead->len = pWrite->rowSize; + pHead->len = pRow->rowSize; pHead->version = 0; pHead->msgType = pTable->id * 10 + action; - return sdbWriteToQueue(pWrite, TAOS_QTYPE_RPC); + return sdbWriteToQueue(pRow, TAOS_QTYPE_RPC); } -int32_t sdbInsertRowToQueue(SSWriteMsg *pWrite) { return sdbWriteRowToQueue(pWrite, SDB_ACTION_INSERT); } +int32_t sdbInsertRowToQueue(SSdbRow *pRow) { return sdbWriteRowToQueue(pRow, SDB_ACTION_INSERT); } static void *sdbWorkerFp(void *pWorker) { - SSWriteMsg *pWrite; - int32_t qtype; - void * unUsed; + SSdbRow *pRow; + int32_t qtype; + void * unUsed; while (1) { int32_t numOfMsgs = taosReadAllQitemsFromQset(tsSdbWQset, tsSdbWQall, &unUsed); @@ -1016,14 +1016,14 @@ static void *sdbWorkerFp(void *pWorker) { } for (int32_t i = 0; i < numOfMsgs; ++i) { - taosGetQitem(tsSdbWQall, &qtype, (void **)&pWrite); - sdbTrace("vgId:1, msg:%p, row:%p hver:%" PRIu64 ", will be processed in sdb queue", pWrite->pMsg, pWrite->pRow, - pWrite->pHead->version); + taosGetQitem(tsSdbWQall, &qtype, (void **)&pRow); + sdbTrace("vgId:1, msg:%p, row:%p hver:%" PRIu64 ", will be processed in sdb queue", pRow->pMsg, pRow->pObj, + pRow->pHead->version); - pWrite->code = sdbProcessWrite((qtype == TAOS_QTYPE_RPC) ? pWrite : NULL, pWrite->pHead, qtype, NULL); - if (pWrite->code > 0) pWrite->code = 0; + pRow->code = sdbProcessWrite((qtype == TAOS_QTYPE_RPC) ? pRow : NULL, pRow->pHead, qtype, NULL); + if (pRow->code > 0) pRow->code = 0; - sdbTrace("vgId:1, msg:%p is processed in sdb queue, code:%x", pWrite->pMsg, pWrite->code); + sdbTrace("vgId:1, msg:%p is processed in sdb queue, code:%x", pRow->pMsg, pRow->code); } walFsync(tsSdbMgmt.wal, true); @@ -1031,16 +1031,16 @@ static void *sdbWorkerFp(void *pWorker) { // browse all items, and process them one by one taosResetQitems(tsSdbWQall); for (int32_t i = 0; i < numOfMsgs; ++i) { - taosGetQitem(tsSdbWQall, &qtype, (void **)&pWrite); + taosGetQitem(tsSdbWQall, &qtype, (void **)&pRow); if (qtype == TAOS_QTYPE_RPC) { - sdbConfirmForward(NULL, pWrite, pWrite->code); + sdbConfirmForward(NULL, pRow, pRow->code); } else if (qtype == TAOS_QTYPE_FWD) { - syncConfirmForward(tsSdbMgmt.sync, pWrite->pHead->version, pWrite->code); + syncConfirmForward(tsSdbMgmt.sync, pRow->pHead->version, pRow->code); } else { } - sdbFreeFromQueue(pWrite); + sdbFreeFromQueue(pRow); } } diff --git a/src/mnode/src/mnodeTable.c b/src/mnode/src/mnodeTable.c index 587c766e44..29957f8ec0 100644 --- a/src/mnode/src/mnodeTable.c +++ b/src/mnode/src/mnodeTable.c @@ -99,13 +99,13 @@ static void mnodeDestroyChildTable(SCTableObj *pTable) { tfree(pTable); } -static int32_t mnodeChildTableActionDestroy(SSWriteMsg *pWMsg) { - mnodeDestroyChildTable(pWMsg->pRow); +static int32_t mnodeChildTableActionDestroy(SSdbRow *pRow) { + mnodeDestroyChildTable(pRow->pObj); return TSDB_CODE_SUCCESS; } -static int32_t mnodeChildTableActionInsert(SSWriteMsg *pWMsg) { - SCTableObj *pTable = pWMsg->pRow; +static int32_t mnodeChildTableActionInsert(SSdbRow *pRow) { + SCTableObj *pTable = pRow->pObj; SVgObj *pVgroup = mnodeGetVgroup(pTable->vgId); if (pVgroup == NULL) { @@ -153,8 +153,8 @@ static int32_t mnodeChildTableActionInsert(SSWriteMsg *pWMsg) { return TSDB_CODE_SUCCESS; } -static int32_t mnodeChildTableActionDelete(SSWriteMsg *pWMsg) { - SCTableObj *pTable = pWMsg->pRow; +static int32_t mnodeChildTableActionDelete(SSdbRow *pRow) { + SCTableObj *pTable = pRow->pObj; if (pTable->vgId == 0) { return TSDB_CODE_MND_VGROUP_NOT_EXIST; } @@ -189,8 +189,8 @@ static int32_t mnodeChildTableActionDelete(SSWriteMsg *pWMsg) { return TSDB_CODE_SUCCESS; } -static int32_t mnodeChildTableActionUpdate(SSWriteMsg *pWMsg) { - SCTableObj *pNew = pWMsg->pRow; +static int32_t mnodeChildTableActionUpdate(SSdbRow *pRow) { + SCTableObj *pNew = pRow->pObj; SCTableObj *pTable = mnodeGetChildTable(pNew->info.tableId); if (pTable != pNew) { void *oldTableId = pTable->info.tableId; @@ -216,50 +216,50 @@ static int32_t mnodeChildTableActionUpdate(SSWriteMsg *pWMsg) { return TSDB_CODE_SUCCESS; } -static int32_t mnodeChildTableActionEncode(SSWriteMsg *pWMsg) { - SCTableObj *pTable = pWMsg->pRow; - assert(pTable != NULL && pWMsg->rowData != NULL); +static int32_t mnodeChildTableActionEncode(SSdbRow *pRow) { + SCTableObj *pTable = pRow->pObj; + assert(pTable != NULL && pRow->rowData != NULL); int32_t len = strlen(pTable->info.tableId); if (len >= TSDB_TABLE_FNAME_LEN) return TSDB_CODE_MND_INVALID_TABLE_ID; - memcpy(pWMsg->rowData, pTable->info.tableId, len); - memset(pWMsg->rowData + len, 0, 1); + memcpy(pRow->rowData, pTable->info.tableId, len); + memset(pRow->rowData + len, 0, 1); len++; - memcpy(pWMsg->rowData + len, (char*)pTable + sizeof(char *), tsChildTableUpdateSize); + memcpy(pRow->rowData + len, (char*)pTable + sizeof(char *), tsChildTableUpdateSize); len += tsChildTableUpdateSize; if (pTable->info.type != TSDB_CHILD_TABLE) { int32_t schemaSize = pTable->numOfColumns * sizeof(SSchema); - memcpy(pWMsg->rowData + len, pTable->schema, schemaSize); + memcpy(pRow->rowData + len, pTable->schema, schemaSize); len += schemaSize; if (pTable->sqlLen != 0) { - memcpy(pWMsg->rowData + len, pTable->sql, pTable->sqlLen); + memcpy(pRow->rowData + len, pTable->sql, pTable->sqlLen); len += pTable->sqlLen; } } - pWMsg->rowSize = len; + pRow->rowSize = len; return TSDB_CODE_SUCCESS; } -static int32_t mnodeChildTableActionDecode(SSWriteMsg *pWMsg) { - assert(pWMsg->rowData != NULL); +static int32_t mnodeChildTableActionDecode(SSdbRow *pRow) { + assert(pRow->rowData != NULL); SCTableObj *pTable = calloc(1, sizeof(SCTableObj)); if (pTable == NULL) return TSDB_CODE_MND_OUT_OF_MEMORY; - int32_t len = strlen(pWMsg->rowData); + int32_t len = strlen(pRow->rowData); if (len >= TSDB_TABLE_FNAME_LEN) { free(pTable); return TSDB_CODE_MND_INVALID_TABLE_ID; } - pTable->info.tableId = strdup(pWMsg->rowData); + pTable->info.tableId = strdup(pRow->rowData); len++; - memcpy((char*)pTable + sizeof(char *), pWMsg->rowData + len, tsChildTableUpdateSize); + memcpy((char*)pTable + sizeof(char *), pRow->rowData + len, tsChildTableUpdateSize); len += tsChildTableUpdateSize; if (pTable->info.type != TSDB_CHILD_TABLE) { @@ -269,7 +269,7 @@ static int32_t mnodeChildTableActionDecode(SSWriteMsg *pWMsg) { mnodeDestroyChildTable(pTable); return TSDB_CODE_MND_INVALID_TABLE_TYPE; } - memcpy(pTable->schema, pWMsg->rowData + len, schemaSize); + memcpy(pTable->schema, pRow->rowData + len, schemaSize); len += schemaSize; if (pTable->sqlLen != 0) { @@ -278,11 +278,11 @@ static int32_t mnodeChildTableActionDecode(SSWriteMsg *pWMsg) { mnodeDestroyChildTable(pTable); return TSDB_CODE_MND_OUT_OF_MEMORY; } - memcpy(pTable->sql, pWMsg->rowData + len, pTable->sqlLen); + memcpy(pTable->sql, pRow->rowData + len, pTable->sqlLen); } } - pWMsg->pRow = pTable; + pRow->pObj = pTable; return TSDB_CODE_SUCCESS; } @@ -297,7 +297,7 @@ static int32_t mnodeChildTableActionRestored() { SDbObj *pDb = mnodeGetDbByTableId(pTable->info.tableId); if (pDb == NULL || pDb->status != TSDB_DB_STATUS_READY) { mError("ctable:%s, failed to get db or db in dropping, discard it", pTable->info.tableId); - SSWriteMsg desc = {.type = SDB_OPER_LOCAL, .pRow = pTable, .pTable = tsChildTableSdb}; + SSdbRow desc = {.type = SDB_OPER_LOCAL, .pObj = pTable, .pTable = tsChildTableSdb}; sdbDeleteRow(&desc); mnodeDecTableRef(pTable); mnodeDecDbRef(pDb); @@ -309,7 +309,7 @@ static int32_t mnodeChildTableActionRestored() { if (pVgroup == NULL) { mError("ctable:%s, failed to get vgId:%d tid:%d, discard it", pTable->info.tableId, pTable->vgId, pTable->tid); pTable->vgId = 0; - SSWriteMsg desc = {.type = SDB_OPER_LOCAL, .pRow = pTable, .pTable = tsChildTableSdb}; + SSdbRow desc = {.type = SDB_OPER_LOCAL, .pObj = pTable, .pTable = tsChildTableSdb}; sdbDeleteRow(&desc); mnodeDecTableRef(pTable); continue; @@ -320,7 +320,7 @@ static int32_t mnodeChildTableActionRestored() { mError("ctable:%s, db:%s not match with vgId:%d db:%s sid:%d, discard it", pTable->info.tableId, pDb->name, pTable->vgId, pVgroup->dbName, pTable->tid); pTable->vgId = 0; - SSWriteMsg desc = {.type = SDB_OPER_LOCAL, .pRow = pTable, .pTable = tsChildTableSdb}; + SSdbRow desc = {.type = SDB_OPER_LOCAL, .pObj = pTable, .pTable = tsChildTableSdb}; sdbDeleteRow(&desc); mnodeDecTableRef(pTable); continue; @@ -331,7 +331,7 @@ static int32_t mnodeChildTableActionRestored() { if (pSuperTable == NULL) { mError("ctable:%s, stable:%" PRIu64 " not exist", pTable->info.tableId, pTable->suid); pTable->vgId = 0; - SSWriteMsg desc = {.type = SDB_OPER_LOCAL, .pRow = pTable, .pTable = tsChildTableSdb}; + SSdbRow desc = {.type = SDB_OPER_LOCAL, .pObj = pTable, .pTable = tsChildTableSdb}; sdbDeleteRow(&desc); mnodeDecTableRef(pTable); continue; @@ -430,13 +430,13 @@ static void mnodeDestroySuperTable(SSTableObj *pStable) { tfree(pStable); } -static int32_t mnodeSuperTableActionDestroy(SSWriteMsg *pWMsg) { - mnodeDestroySuperTable(pWMsg->pRow); +static int32_t mnodeSuperTableActionDestroy(SSdbRow *pRow) { + mnodeDestroySuperTable(pRow->pObj); return TSDB_CODE_SUCCESS; } -static int32_t mnodeSuperTableActionInsert(SSWriteMsg *pWMsg) { - SSTableObj *pStable = pWMsg->pRow; +static int32_t mnodeSuperTableActionInsert(SSdbRow *pRow) { + SSTableObj *pStable = pRow->pObj; SDbObj *pDb = mnodeGetDbByTableId(pStable->info.tableId); if (pDb != NULL && pDb->status == TSDB_DB_STATUS_READY) { mnodeAddSuperTableIntoDb(pDb); @@ -446,8 +446,8 @@ static int32_t mnodeSuperTableActionInsert(SSWriteMsg *pWMsg) { return TSDB_CODE_SUCCESS; } -static int32_t mnodeSuperTableActionDelete(SSWriteMsg *pWMsg) { - SSTableObj *pStable = pWMsg->pRow; +static int32_t mnodeSuperTableActionDelete(SSdbRow *pRow) { + SSTableObj *pStable = pRow->pObj; SDbObj *pDb = mnodeGetDbByTableId(pStable->info.tableId); if (pDb != NULL) { mnodeRemoveSuperTableFromDb(pDb); @@ -458,8 +458,8 @@ static int32_t mnodeSuperTableActionDelete(SSWriteMsg *pWMsg) { return TSDB_CODE_SUCCESS; } -static int32_t mnodeSuperTableActionUpdate(SSWriteMsg *pWMsg) { - SSTableObj *pNew = pWMsg->pRow; +static int32_t mnodeSuperTableActionUpdate(SSdbRow *pRow) { + SSTableObj *pNew = pRow->pObj; SSTableObj *pTable = mnodeGetSuperTable(pNew->info.tableId); if (pTable != NULL && pTable != pNew) { void *oldTableId = pTable->info.tableId; @@ -483,43 +483,43 @@ static int32_t mnodeSuperTableActionUpdate(SSWriteMsg *pWMsg) { return TSDB_CODE_SUCCESS; } -static int32_t mnodeSuperTableActionEncode(SSWriteMsg *pWMsg) { - SSTableObj *pStable = pWMsg->pRow; - assert(pWMsg->pRow != NULL && pWMsg->rowData != NULL); +static int32_t mnodeSuperTableActionEncode(SSdbRow *pRow) { + SSTableObj *pStable = pRow->pObj; + assert(pRow->pObj != NULL && pRow->rowData != NULL); int32_t len = strlen(pStable->info.tableId); if (len >= TSDB_TABLE_FNAME_LEN) len = TSDB_CODE_MND_INVALID_TABLE_ID; - memcpy(pWMsg->rowData, pStable->info.tableId, len); - memset(pWMsg->rowData + len, 0, 1); + memcpy(pRow->rowData, pStable->info.tableId, len); + memset(pRow->rowData + len, 0, 1); len++; - memcpy(pWMsg->rowData + len, (char*)pStable + sizeof(char *), tsSuperTableUpdateSize); + memcpy(pRow->rowData + len, (char*)pStable + sizeof(char *), tsSuperTableUpdateSize); len += tsSuperTableUpdateSize; int32_t schemaSize = sizeof(SSchema) * (pStable->numOfColumns + pStable->numOfTags); - memcpy(pWMsg->rowData + len, pStable->schema, schemaSize); + memcpy(pRow->rowData + len, pStable->schema, schemaSize); len += schemaSize; - pWMsg->rowSize = len; + pRow->rowSize = len; return TSDB_CODE_SUCCESS; } -static int32_t mnodeSuperTableActionDecode(SSWriteMsg *pWMsg) { - assert(pWMsg->rowData != NULL); +static int32_t mnodeSuperTableActionDecode(SSdbRow *pRow) { + assert(pRow->rowData != NULL); SSTableObj *pStable = (SSTableObj *) calloc(1, sizeof(SSTableObj)); if (pStable == NULL) return TSDB_CODE_MND_OUT_OF_MEMORY; - int32_t len = strlen(pWMsg->rowData); + int32_t len = strlen(pRow->rowData); if (len >= TSDB_TABLE_FNAME_LEN){ free(pStable); return TSDB_CODE_MND_INVALID_TABLE_ID; } - pStable->info.tableId = strdup(pWMsg->rowData); + pStable->info.tableId = strdup(pRow->rowData); len++; - memcpy((char*)pStable + sizeof(char *), pWMsg->rowData + len, tsSuperTableUpdateSize); + memcpy((char*)pStable + sizeof(char *), pRow->rowData + len, tsSuperTableUpdateSize); len += tsSuperTableUpdateSize; int32_t schemaSize = sizeof(SSchema) * (pStable->numOfColumns + pStable->numOfTags); @@ -529,9 +529,9 @@ static int32_t mnodeSuperTableActionDecode(SSWriteMsg *pWMsg) { return TSDB_CODE_MND_NOT_SUPER_TABLE; } - memcpy(pStable->schema, pWMsg->rowData + len, schemaSize); + memcpy(pStable->schema, pRow->rowData + len, schemaSize); - pWMsg->pRow = pStable; + pRow->pObj = pStable; return TSDB_CODE_SUCCESS; } @@ -828,7 +828,7 @@ static int32_t mnodeCreateSuperTableCb(SMnodeMsg *pMsg, int32_t code) { } else { mError("app:%p:%p, stable:%s, failed to create in sdb, reason:%s", pMsg->rpcMsg.ahandle, pMsg, pTable->info.tableId, tstrerror(code)); - SSWriteMsg desc = {.type = SDB_OPER_GLOBAL, .pRow = pTable, .pTable = tsSuperTableSdb}; + SSdbRow desc = {.type = SDB_OPER_GLOBAL, .pObj = pTable, .pTable = tsSuperTableSdb}; sdbDeleteRow(&desc); } @@ -878,16 +878,16 @@ static int32_t mnodeProcessCreateSuperTableMsg(SMnodeMsg *pMsg) { pMsg->pTable = (STableObj *)pStable; mnodeIncTableRef(pMsg->pTable); - SSWriteMsg wmsg = { + SSdbRow row = { .type = SDB_OPER_GLOBAL, .pTable = tsSuperTableSdb, - .pRow = pStable, + .pObj = pStable, .rowSize = sizeof(SSTableObj) + schemaSize, .pMsg = pMsg, .fpRsp = mnodeCreateSuperTableCb }; - int32_t code = sdbInsertRow(&wmsg); + int32_t code = sdbInsertRow(&row); if (code != TSDB_CODE_SUCCESS && code != TSDB_CODE_MND_ACTION_IN_PROGRESS) { mnodeDestroySuperTable(pStable); pMsg->pTable = NULL; @@ -937,15 +937,15 @@ static int32_t mnodeProcessDropSuperTableMsg(SMnodeMsg *pMsg) { mnodeDropAllChildTablesInStable(pStable); } - SSWriteMsg wmsg = { + SSdbRow row = { .type = SDB_OPER_GLOBAL, .pTable = tsSuperTableSdb, - .pRow = pStable, + .pObj = pStable, .pMsg = pMsg, .fpRsp = mnodeDropSuperTableCb }; - int32_t code = sdbDeleteRow(&wmsg); + int32_t code = sdbDeleteRow(&row); if (code != TSDB_CODE_SUCCESS && code != TSDB_CODE_MND_ACTION_IN_PROGRESS) { mError("app:%p:%p, table:%s, failed to drop, reason:%s", pMsg->rpcMsg.ahandle, pMsg, pStable->info.tableId, tstrerror(code)); @@ -1010,15 +1010,15 @@ static int32_t mnodeAddSuperTableTag(SMnodeMsg *pMsg, SSchema schema[], int32_t mInfo("app:%p:%p, stable %s, start to add tag %s", pMsg->rpcMsg.ahandle, pMsg, pStable->info.tableId, schema[0].name); - SSWriteMsg wmsg = { + SSdbRow row = { .type = SDB_OPER_GLOBAL, .pTable = tsSuperTableSdb, - .pRow = pStable, + .pObj = pStable, .pMsg = pMsg, .fpRsp = mnodeAddSuperTableTagCb }; - return sdbUpdateRow(&wmsg); + return sdbUpdateRow(&row); } static int32_t mnodeDropSuperTableTagCb(SMnodeMsg *pMsg, int32_t code) { @@ -1044,15 +1044,15 @@ static int32_t mnodeDropSuperTableTag(SMnodeMsg *pMsg, char *tagName) { mInfo("app:%p:%p, stable %s, start to drop tag %s", pMsg->rpcMsg.ahandle, pMsg, pStable->info.tableId, tagName); - SSWriteMsg wmsg = { + SSdbRow row = { .type = SDB_OPER_GLOBAL, .pTable = tsSuperTableSdb, - .pRow = pStable, + .pObj = pStable, .pMsg = pMsg, .fpRsp = mnodeDropSuperTableTagCb }; - return sdbUpdateRow(&wmsg); + return sdbUpdateRow(&row); } static int32_t mnodeModifySuperTableTagNameCb(SMnodeMsg *pMsg, int32_t code) { @@ -1088,15 +1088,15 @@ static int32_t mnodeModifySuperTableTagName(SMnodeMsg *pMsg, char *oldTagName, c mInfo("app:%p:%p, stable %s, start to modify tag %s to %s", pMsg->rpcMsg.ahandle, pMsg, pStable->info.tableId, oldTagName, newTagName); - SSWriteMsg wmsg = { + SSdbRow row = { .type = SDB_OPER_GLOBAL, .pTable = tsSuperTableSdb, - .pRow = pStable, + .pObj = pStable, .pMsg = pMsg, .fpRsp = mnodeModifySuperTableTagNameCb }; - return sdbUpdateRow(&wmsg); + return sdbUpdateRow(&row); } static int32_t mnodeFindSuperTableColumnIndex(SSTableObj *pStable, char *colName) { @@ -1162,15 +1162,15 @@ static int32_t mnodeAddSuperTableColumn(SMnodeMsg *pMsg, SSchema schema[], int32 mInfo("app:%p:%p, stable %s, start to add column", pMsg->rpcMsg.ahandle, pMsg, pStable->info.tableId); - SSWriteMsg wmsg = { + SSdbRow row = { .type = SDB_OPER_GLOBAL, .pTable = tsSuperTableSdb, - .pRow = pStable, + .pObj = pStable, .pMsg = pMsg, .fpRsp = mnodeAddSuperTableColumnCb }; - return sdbUpdateRow(&wmsg); + return sdbUpdateRow(&row); } static int32_t mnodeDropSuperTableColumnCb(SMnodeMsg *pMsg, int32_t code) { @@ -1207,15 +1207,15 @@ static int32_t mnodeDropSuperTableColumn(SMnodeMsg *pMsg, char *colName) { mInfo("app:%p:%p, stable %s, start to delete column", pMsg->rpcMsg.ahandle, pMsg, pStable->info.tableId); - SSWriteMsg wmsg = { + SSdbRow row = { .type = SDB_OPER_GLOBAL, .pTable = tsSuperTableSdb, - .pRow = pStable, + .pObj = pStable, .pMsg = pMsg, .fpRsp = mnodeDropSuperTableColumnCb }; - return sdbUpdateRow(&wmsg); + return sdbUpdateRow(&row); } static int32_t mnodeChangeSuperTableColumnCb(SMnodeMsg *pMsg, int32_t code) { @@ -1251,15 +1251,15 @@ static int32_t mnodeChangeSuperTableColumn(SMnodeMsg *pMsg, char *oldName, char mInfo("app:%p:%p, stable %s, start to modify column %s to %s", pMsg->rpcMsg.ahandle, pMsg, pStable->info.tableId, oldName, newName); - SSWriteMsg wmsg = { + SSdbRow row = { .type = SDB_OPER_GLOBAL, .pTable = tsSuperTableSdb, - .pRow = pStable, + .pObj = pStable, .pMsg = pMsg, .fpRsp = mnodeChangeSuperTableColumnCb }; - return sdbUpdateRow(&wmsg); + return sdbUpdateRow(&row); } // show super tables @@ -1417,12 +1417,12 @@ void mnodeDropAllSuperTables(SDbObj *pDropDb) { if (pTable == NULL) break; if (strncmp(prefix, pTable->info.tableId, prefixLen) == 0) { - SSWriteMsg wmsg = { + SSdbRow row = { .type = SDB_OPER_LOCAL, .pTable = tsSuperTableSdb, - .pRow = pTable, + .pObj = pTable, }; - sdbDeleteRow(&wmsg); + sdbDeleteRow(&row); numOfTables ++; } @@ -1694,7 +1694,7 @@ static int32_t mnodeDoCreateChildTableCb(SMnodeMsg *pMsg, int32_t code) { } else { mError("app:%p:%p, table:%s, failed to create table sid:%d, uid:%" PRIu64 ", reason:%s", pMsg->rpcMsg.ahandle, pMsg, pTable->info.tableId, pTable->tid, pTable->uid, tstrerror(code)); - SSWriteMsg desc = {.type = SDB_OPER_GLOBAL, .pRow = pTable, .pTable = tsChildTableSdb}; + SSdbRow desc = {.type = SDB_OPER_GLOBAL, .pObj = pTable, .pTable = tsChildTableSdb}; sdbDeleteRow(&desc); return code; } @@ -1780,9 +1780,9 @@ static int32_t mnodeDoCreateChildTable(SMnodeMsg *pMsg, int32_t tid) { pMsg->pTable = (STableObj *)pTable; mnodeIncTableRef(pMsg->pTable); - SSWriteMsg desc = { + SSdbRow desc = { .type = SDB_OPER_GLOBAL, - .pRow = pTable, + .pObj = pTable, .pTable = tsChildTableSdb, .pMsg = pMsg, .fpReq = mnodeDoCreateChildTableFp @@ -1901,15 +1901,15 @@ static int32_t mnodeProcessDropChildTableMsg(SMnodeMsg *pMsg) { return TSDB_CODE_MND_APP_ERROR; } - SSWriteMsg wmsg = { + SSdbRow row = { .type = SDB_OPER_GLOBAL, .pTable = tsChildTableSdb, - .pRow = pTable, + .pObj = pTable, .pMsg = pMsg, .fpRsp = mnodeDropChildTableCb }; - int32_t code = sdbDeleteRow(&wmsg); + int32_t code = sdbDeleteRow(&row); if (code != TSDB_CODE_SUCCESS && code != TSDB_CODE_MND_ACTION_IN_PROGRESS) { mError("app:%p:%p, ctable:%s, failed to drop, reason:%s", pMsg->rpcMsg.ahandle, pMsg, pTable->info.tableId, tstrerror(code)); @@ -2005,15 +2005,15 @@ static int32_t mnodeAddNormalTableColumn(SMnodeMsg *pMsg, SSchema schema[], int3 mInfo("app:%p:%p, ctable %s, start to add column", pMsg->rpcMsg.ahandle, pMsg, pTable->info.tableId); - SSWriteMsg wmsg = { + SSdbRow row = { .type = SDB_OPER_GLOBAL, .pTable = tsChildTableSdb, - .pRow = pTable, + .pObj = pTable, .pMsg = pMsg, .fpRsp = mnodeAlterNormalTableColumnCb }; - return sdbUpdateRow(&wmsg); + return sdbUpdateRow(&row); } static int32_t mnodeDropNormalTableColumn(SMnodeMsg *pMsg, char *colName) { @@ -2038,15 +2038,15 @@ static int32_t mnodeDropNormalTableColumn(SMnodeMsg *pMsg, char *colName) { mInfo("app:%p:%p, ctable %s, start to drop column %s", pMsg->rpcMsg.ahandle, pMsg, pTable->info.tableId, colName); - SSWriteMsg wmsg = { + SSdbRow row = { .type = SDB_OPER_GLOBAL, .pTable = tsChildTableSdb, - .pRow = pTable, + .pObj = pTable, .pMsg = pMsg, .fpRsp = mnodeAlterNormalTableColumnCb }; - return sdbUpdateRow(&wmsg); + return sdbUpdateRow(&row); } static int32_t mnodeChangeNormalTableColumn(SMnodeMsg *pMsg, char *oldName, char *newName) { @@ -2075,15 +2075,15 @@ static int32_t mnodeChangeNormalTableColumn(SMnodeMsg *pMsg, char *oldName, char mInfo("app:%p:%p, ctable %s, start to modify column %s to %s", pMsg->rpcMsg.ahandle, pMsg, pTable->info.tableId, oldName, newName); - SSWriteMsg wmsg = { + SSdbRow row = { .type = SDB_OPER_GLOBAL, .pTable = tsChildTableSdb, - .pRow = pTable, + .pObj = pTable, .pMsg = pMsg, .fpRsp = mnodeAlterNormalTableColumnCb }; - return sdbUpdateRow(&wmsg); + return sdbUpdateRow(&row); } static int32_t mnodeSetSchemaFromNormalTable(SSchema *pSchema, SCTableObj *pTable) { @@ -2218,12 +2218,12 @@ void mnodeDropAllChildTablesInVgroups(SVgObj *pVgroup) { if (pTable == NULL) break; if (pTable->vgId == pVgroup->vgId) { - SSWriteMsg wmsg = { + SSdbRow row = { .type = SDB_OPER_LOCAL, .pTable = tsChildTableSdb, - .pRow = pTable, + .pObj = pTable, }; - sdbDeleteRow(&wmsg); + sdbDeleteRow(&row); numOfTables++; } mnodeDecTableRef(pTable); @@ -2251,12 +2251,12 @@ void mnodeDropAllChildTables(SDbObj *pDropDb) { if (pTable == NULL) break; if (strncmp(prefix, pTable->info.tableId, prefixLen) == 0) { - SSWriteMsg wmsg = { + SSdbRow row = { .type = SDB_OPER_LOCAL, .pTable = tsChildTableSdb, - .pRow = pTable, + .pObj = pTable, }; - sdbDeleteRow(&wmsg); + sdbDeleteRow(&row); numOfTables++; } mnodeDecTableRef(pTable); @@ -2280,12 +2280,12 @@ static void mnodeDropAllChildTablesInStable(SSTableObj *pStable) { if (pTable == NULL) break; if (pTable->superTable == pStable) { - SSWriteMsg wmsg = { + SSdbRow row = { .type = SDB_OPER_LOCAL, .pTable = tsChildTableSdb, - .pRow = pTable, + .pObj = pTable, }; - sdbDeleteRow(&wmsg); + sdbDeleteRow(&row); numOfTables++; } @@ -2410,9 +2410,9 @@ static void mnodeProcessCreateChildTableRsp(SRpcMsg *rpcMsg) { } if (rpcMsg->code == TSDB_CODE_SUCCESS || rpcMsg->code == TSDB_CODE_TDB_TABLE_ALREADY_EXIST) { - SSWriteMsg desc = { + SSdbRow desc = { .type = SDB_OPER_GLOBAL, - .pRow = pTable, + .pObj = pTable, .pTable = tsChildTableSdb, .pMsg = mnodeMsg, .fpRsp = mnodeDoCreateChildTableCb @@ -2440,8 +2440,8 @@ static void mnodeProcessCreateChildTableRsp(SRpcMsg *rpcMsg) { mnodeMsg->rpcMsg.ahandle, mnodeMsg, pTable->info.tableId, pTable->vgId, pTable->tid, pTable->uid, tstrerror(rpcMsg->code), mnodeMsg->rpcMsg.handle, mnodeMsg->incomingTs, sec, mnodeMsg->retry); - SSWriteMsg wmsg = {.type = SDB_OPER_GLOBAL, .pTable = tsChildTableSdb, .pRow = pTable}; - sdbDeleteRow(&wmsg); + SSdbRow row = {.type = SDB_OPER_GLOBAL, .pTable = tsChildTableSdb, .pObj = pTable}; + sdbDeleteRow(&row); if (rpcMsg->code == TSDB_CODE_APP_NOT_READY) { //Avoid retry again in client diff --git a/src/mnode/src/mnodeUser.c b/src/mnode/src/mnodeUser.c index 9de14dbfd1..dc76d92eb8 100644 --- a/src/mnode/src/mnodeUser.c +++ b/src/mnode/src/mnodeUser.c @@ -42,13 +42,13 @@ static int32_t mnodeProcessAlterUserMsg(SMnodeMsg *pMsg); static int32_t mnodeProcessDropUserMsg(SMnodeMsg *pMsg); static int32_t mnodeProcessAuthMsg(SMnodeMsg *pMsg); -static int32_t mnodeUserActionDestroy(SSWriteMsg *pWMsg) { - tfree(pWMsg->pRow); +static int32_t mnodeUserActionDestroy(SSdbRow *pRow) { + tfree(pRow->pObj); return TSDB_CODE_SUCCESS; } -static int32_t mnodeUserActionInsert(SSWriteMsg *pWMsg) { - SUserObj *pUser = pWMsg->pRow; +static int32_t mnodeUserActionInsert(SSdbRow *pRow) { + SUserObj *pUser = pRow->pObj; SAcctObj *pAcct = mnodeGetAcct(pUser->acct); if (pAcct != NULL) { @@ -62,8 +62,8 @@ static int32_t mnodeUserActionInsert(SSWriteMsg *pWMsg) { return TSDB_CODE_SUCCESS; } -static int32_t mnodeUserActionDelete(SSWriteMsg *pWMsg) { - SUserObj *pUser = pWMsg->pRow; +static int32_t mnodeUserActionDelete(SSdbRow *pRow) { + SUserObj *pUser = pRow->pObj; SAcctObj *pAcct = mnodeGetAcct(pUser->acct); if (pAcct != NULL) { @@ -74,8 +74,8 @@ static int32_t mnodeUserActionDelete(SSWriteMsg *pWMsg) { return TSDB_CODE_SUCCESS; } -static int32_t mnodeUserActionUpdate(SSWriteMsg *pWMsg) { - SUserObj *pUser = pWMsg->pRow; +static int32_t mnodeUserActionUpdate(SSdbRow *pRow) { + SUserObj *pUser = pRow->pObj; SUserObj *pSaved = mnodeGetUser(pUser->user); if (pUser != pSaved) { memcpy(pSaved, pUser, tsUserUpdateSize); @@ -85,19 +85,19 @@ static int32_t mnodeUserActionUpdate(SSWriteMsg *pWMsg) { return TSDB_CODE_SUCCESS; } -static int32_t mnodeUserActionEncode(SSWriteMsg *pWMsg) { - SUserObj *pUser = pWMsg->pRow; - memcpy(pWMsg->rowData, pUser, tsUserUpdateSize); - pWMsg->rowSize = tsUserUpdateSize; +static int32_t mnodeUserActionEncode(SSdbRow *pRow) { + SUserObj *pUser = pRow->pObj; + memcpy(pRow->rowData, pUser, tsUserUpdateSize); + pRow->rowSize = tsUserUpdateSize; return TSDB_CODE_SUCCESS; } -static int32_t mnodeUserActionDecode(SSWriteMsg *pWMsg) { +static int32_t mnodeUserActionDecode(SSdbRow *pRow) { SUserObj *pUser = (SUserObj *)calloc(1, sizeof(SUserObj)); if (pUser == NULL) return TSDB_CODE_MND_OUT_OF_MEMORY; - memcpy(pUser, pWMsg->rowData, tsUserUpdateSize); - pWMsg->pRow = pUser; + memcpy(pUser, pRow->rowData, tsUserUpdateSize); + pRow->pObj = pUser; return TSDB_CODE_SUCCESS; } @@ -205,14 +205,14 @@ void mnodeDecUserRef(SUserObj *pUser) { } static int32_t mnodeUpdateUser(SUserObj *pUser, void *pMsg) { - SSWriteMsg wmsg = { + SSdbRow row = { .type = SDB_OPER_GLOBAL, .pTable = tsUserSdb, - .pRow = pUser, + .pObj = pUser, .pMsg = pMsg }; - int32_t code = sdbUpdateRow(&wmsg); + int32_t code = sdbUpdateRow(&row); if (code != TSDB_CODE_SUCCESS && code != TSDB_CODE_MND_ACTION_IN_PROGRESS) { mError("user:%s, failed to alter by %s, reason:%s", pUser->user, mnodeGetUserFromMsg(pMsg), tstrerror(code)); } else { @@ -259,15 +259,15 @@ int32_t mnodeCreateUser(SAcctObj *pAcct, char *name, char *pass, void *pMsg) { pUser->superAuth = 1; } - SSWriteMsg wmsg = { + SSdbRow row = { .type = SDB_OPER_GLOBAL, .pTable = tsUserSdb, - .pRow = pUser, + .pObj = pUser, .rowSize = sizeof(SUserObj), .pMsg = pMsg }; - code = sdbInsertRow(&wmsg); + code = sdbInsertRow(&row); if (code != TSDB_CODE_SUCCESS && code != TSDB_CODE_MND_ACTION_IN_PROGRESS) { mError("user:%s, failed to create by %s, reason:%s", pUser->user, mnodeGetUserFromMsg(pMsg), tstrerror(code)); tfree(pUser); @@ -279,14 +279,14 @@ int32_t mnodeCreateUser(SAcctObj *pAcct, char *name, char *pass, void *pMsg) { } static int32_t mnodeDropUser(SUserObj *pUser, void *pMsg) { - SSWriteMsg wmsg = { + SSdbRow row = { .type = SDB_OPER_GLOBAL, .pTable = tsUserSdb, - .pRow = pUser, + .pObj = pUser, .pMsg = pMsg }; - int32_t code = sdbDeleteRow(&wmsg); + int32_t code = sdbDeleteRow(&row); if (code != TSDB_CODE_SUCCESS && code != TSDB_CODE_MND_ACTION_IN_PROGRESS) { mError("user:%s, failed to drop by %s, reason:%s", pUser->user, mnodeGetUserFromMsg(pMsg), tstrerror(code)); } else { @@ -562,12 +562,12 @@ void mnodeDropAllUsers(SAcctObj *pAcct) { if (pUser == NULL) break; if (strncmp(pUser->acct, pAcct->user, acctNameLen) == 0) { - SSWriteMsg wmsg = { + SSdbRow row = { .type = SDB_OPER_LOCAL, .pTable = tsUserSdb, - .pRow = pUser, + .pObj = pUser, }; - sdbDeleteRow(&wmsg); + sdbDeleteRow(&row); numOfUsers++; } diff --git a/src/mnode/src/mnodeVgroup.c b/src/mnode/src/mnodeVgroup.c index 2eb11e1def..16e5a601e3 100644 --- a/src/mnode/src/mnodeVgroup.c +++ b/src/mnode/src/mnodeVgroup.c @@ -72,13 +72,13 @@ static void mnodeDestroyVgroup(SVgObj *pVgroup) { tfree(pVgroup); } -static int32_t mnodeVgroupActionDestroy(SSWriteMsg *pWMsg) { - mnodeDestroyVgroup(pWMsg->pRow); +static int32_t mnodeVgroupActionDestroy(SSdbRow *pRow) { + mnodeDestroyVgroup(pRow->pObj); return TSDB_CODE_SUCCESS; } -static int32_t mnodeVgroupActionInsert(SSWriteMsg *pWMsg) { - SVgObj *pVgroup = pWMsg->pRow; +static int32_t mnodeVgroupActionInsert(SSdbRow *pRow) { + SVgObj *pVgroup = pRow->pObj; // refer to db SDbObj *pDb = mnodeGetDb(pVgroup->dbName); @@ -115,8 +115,8 @@ static int32_t mnodeVgroupActionInsert(SSWriteMsg *pWMsg) { return TSDB_CODE_SUCCESS; } -static int32_t mnodeVgroupActionDelete(SSWriteMsg *pWMsg) { - SVgObj *pVgroup = pWMsg->pRow; +static int32_t mnodeVgroupActionDelete(SSdbRow *pRow) { + SVgObj *pVgroup = pRow->pObj; if (pVgroup->pDb == NULL) { mError("vgId:%d, db:%s is not exist while insert into hash", pVgroup->vgId, pVgroup->dbName); @@ -137,8 +137,8 @@ static int32_t mnodeVgroupActionDelete(SSWriteMsg *pWMsg) { return TSDB_CODE_SUCCESS; } -static int32_t mnodeVgroupActionUpdate(SSWriteMsg *pWMsg) { - SVgObj *pNew = pWMsg->pRow; +static int32_t mnodeVgroupActionUpdate(SSdbRow *pRow) { + SVgObj *pNew = pRow->pObj; SVgObj *pVgroup = mnodeGetVgroup(pNew->vgId); if (pVgroup != pNew) { @@ -176,25 +176,25 @@ static int32_t mnodeVgroupActionUpdate(SSWriteMsg *pWMsg) { return TSDB_CODE_SUCCESS; } -static int32_t mnodeVgroupActionEncode(SSWriteMsg *pWMsg) { - SVgObj *pVgroup = pWMsg->pRow; - memcpy(pWMsg->rowData, pVgroup, tsVgUpdateSize); - SVgObj *pTmpVgroup = pWMsg->rowData; +static int32_t mnodeVgroupActionEncode(SSdbRow *pRow) { + SVgObj *pVgroup = pRow->pObj; + memcpy(pRow->rowData, pVgroup, tsVgUpdateSize); + SVgObj *pTmpVgroup = pRow->rowData; for (int32_t i = 0; i < TSDB_MAX_REPLICA; ++i) { pTmpVgroup->vnodeGid[i].pDnode = NULL; pTmpVgroup->vnodeGid[i].role = 0; } - pWMsg->rowSize = tsVgUpdateSize; + pRow->rowSize = tsVgUpdateSize; return TSDB_CODE_SUCCESS; } -static int32_t mnodeVgroupActionDecode(SSWriteMsg *pWMsg) { +static int32_t mnodeVgroupActionDecode(SSdbRow *pRow) { SVgObj *pVgroup = (SVgObj *) calloc(1, sizeof(SVgObj)); if (pVgroup == NULL) return TSDB_CODE_MND_OUT_OF_MEMORY; - memcpy(pVgroup, pWMsg->rowData, tsVgUpdateSize); - pWMsg->pRow = pVgroup; + memcpy(pVgroup, pRow->rowData, tsVgUpdateSize); + pRow->pObj = pVgroup; return TSDB_CODE_SUCCESS; } @@ -253,13 +253,13 @@ SVgObj *mnodeGetVgroup(int32_t vgId) { } void mnodeUpdateVgroup(SVgObj *pVgroup) { - SSWriteMsg wmsg = { + SSdbRow row = { .type = SDB_OPER_GLOBAL, .pTable = tsVgroupSdb, - .pRow = pVgroup + .pObj = pVgroup }; - int32_t code = sdbUpdateRow(&wmsg); + int32_t code = sdbUpdateRow(&row); if (code != TSDB_CODE_SUCCESS && code != TSDB_CODE_MND_ACTION_IN_PROGRESS) { mError("vgId:%d, failed to update vgroup", pVgroup->vgId); } @@ -519,14 +519,14 @@ static int32_t mnodeCreateVgroupCb(SMnodeMsg *pMsg, int32_t code) { if (code != TSDB_CODE_SUCCESS) { mError("app:%p:%p, vgId:%d, failed to create in sdb, reason:%s", pMsg->rpcMsg.ahandle, pMsg, pVgroup->vgId, tstrerror(code)); - SSWriteMsg desc = {.type = SDB_OPER_GLOBAL, .pRow = pVgroup, .pTable = tsVgroupSdb}; + SSdbRow desc = {.type = SDB_OPER_GLOBAL, .pObj = pVgroup, .pTable = tsVgroupSdb}; sdbDeleteRow(&desc); return code; } else { mInfo("app:%p:%p, vgId:%d, is created in sdb, db:%s replica:%d", pMsg->rpcMsg.ahandle, pMsg, pVgroup->vgId, pDb->name, pVgroup->numOfVnodes); pVgroup->status = TAOS_VG_STATUS_READY; - SSWriteMsg desc = {.type = SDB_OPER_GLOBAL, .pRow = pVgroup, .pTable = tsVgroupSdb}; + SSdbRow desc = {.type = SDB_OPER_GLOBAL, .pObj = pVgroup, .pTable = tsVgroupSdb}; (void)sdbUpdateRow(&desc); dnodeReprocessMWriteMsg(pMsg); @@ -535,7 +535,7 @@ static int32_t mnodeCreateVgroupCb(SMnodeMsg *pMsg, int32_t code) { // mInfo("app:%p:%p, vgId:%d, is created in sdb, db:%s replica:%d", pMsg->rpcMsg.ahandle, pMsg, pVgroup->vgId, // pDb->name, pVgroup->numOfVnodes); // pVgroup->status = TAOS_VG_STATUS_READY; - // SSWriteMsg desc = {.type = SDB_OPER_GLOBAL, .pRow = pVgroup, .pTable = tsVgroupSdb}; + // SSdbRow desc = {.type = SDB_OPER_GLOBAL, .pObj = pVgroup, .pTable = tsVgroupSdb}; // (void)sdbUpdateRow(&desc); // dnodeReprocessMWriteMsg(pMsg); // return TSDB_CODE_MND_ACTION_IN_PROGRESS; @@ -571,16 +571,16 @@ int32_t mnodeCreateVgroup(SMnodeMsg *pMsg) { pMsg->pVgroup = pVgroup; mnodeIncVgroupRef(pVgroup); - SSWriteMsg wmsg = { + SSdbRow row = { .type = SDB_OPER_GLOBAL, .pTable = tsVgroupSdb, - .pRow = pVgroup, + .pObj = pVgroup, .rowSize = sizeof(SVgObj), .pMsg = pMsg, .fpReq = mnodeCreateVgroupFp }; - code = sdbInsertRow(&wmsg); + code = sdbInsertRow(&row); if (code != TSDB_CODE_SUCCESS && code != TSDB_CODE_MND_ACTION_IN_PROGRESS) { pMsg->pVgroup = NULL; mnodeDestroyVgroup(pVgroup); @@ -595,12 +595,12 @@ void mnodeDropVgroup(SVgObj *pVgroup, void *ahandle) { } else { mDebug("vgId:%d, replica:%d is deleting from sdb", pVgroup->vgId, pVgroup->numOfVnodes); mnodeSendDropVgroupMsg(pVgroup, NULL); - SSWriteMsg wmsg = { + SSdbRow row = { .type = SDB_OPER_GLOBAL, .pTable = tsVgroupSdb, - .pRow = pVgroup + .pObj = pVgroup }; - sdbDeleteRow(&wmsg); + sdbDeleteRow(&row); } } @@ -957,28 +957,28 @@ static void mnodeProcessCreateVnodeRsp(SRpcMsg *rpcMsg) { if (mnodeMsg->received != mnodeMsg->expected) return; if (mnodeMsg->received == mnodeMsg->successed) { - SSWriteMsg wmsg = { + SSdbRow row = { .type = SDB_OPER_GLOBAL, .pTable = tsVgroupSdb, - .pRow = pVgroup, + .pObj = pVgroup, .rowSize = sizeof(SVgObj), .pMsg = mnodeMsg, .fpRsp = mnodeCreateVgroupCb }; - int32_t code = sdbInsertRowToQueue(&wmsg); + int32_t code = sdbInsertRowToQueue(&row); if (code != TSDB_CODE_SUCCESS && code != TSDB_CODE_MND_ACTION_IN_PROGRESS) { mnodeMsg->pVgroup = NULL; mnodeDestroyVgroup(pVgroup); dnodeSendRpcMWriteRsp(mnodeMsg, code); } } else { - SSWriteMsg wmsg = { + SSdbRow row = { .type = SDB_OPER_GLOBAL, .pTable = tsVgroupSdb, - .pRow = pVgroup + .pObj = pVgroup }; - sdbDeleteRow(&wmsg); + sdbDeleteRow(&row); dnodeSendRpcMWriteRsp(mnodeMsg, mnodeMsg->code); } } @@ -1031,12 +1031,12 @@ static void mnodeProcessDropVnodeRsp(SRpcMsg *rpcMsg) { if (mnodeMsg->received != mnodeMsg->expected) return; - SSWriteMsg wmsg = { + SSdbRow row = { .type = SDB_OPER_GLOBAL, .pTable = tsVgroupSdb, - .pRow = pVgroup + .pObj = pVgroup }; - int32_t code = sdbDeleteRow(&wmsg); + int32_t code = sdbDeleteRow(&row); if (code != 0) { code = TSDB_CODE_MND_SDB_ERROR; } @@ -1084,12 +1084,12 @@ void mnodeDropAllDnodeVgroups(SDnodeObj *pDropDnode) { if (pVgroup->vnodeGid[0].dnodeId == pDropDnode->dnodeId) { mnodeDropAllChildTablesInVgroups(pVgroup); - SSWriteMsg wmsg = { + SSdbRow row = { .type = SDB_OPER_LOCAL, .pTable = tsVgroupSdb, - .pRow = pVgroup, + .pObj = pVgroup, }; - sdbDeleteRow(&wmsg); + sdbDeleteRow(&row); numOfVgroups++; } mnodeDecVgroupRef(pVgroup); @@ -1135,12 +1135,12 @@ void mnodeDropAllDbVgroups(SDbObj *pDropDb) { if (pVgroup == NULL) break; if (pVgroup->pDb == pDropDb) { - SSWriteMsg wmsg = { + SSdbRow row = { .type = SDB_OPER_LOCAL, .pTable = tsVgroupSdb, - .pRow = pVgroup, + .pObj = pVgroup, }; - sdbDeleteRow(&wmsg); + sdbDeleteRow(&row); numOfVgroups++; }