diff --git a/include/dnode/mnode/mnode.h b/include/dnode/mnode/mnode.h
index 824eb24191..5066b881b5 100644
--- a/include/dnode/mnode/mnode.h
+++ b/include/dnode/mnode/mnode.h
@@ -13,8 +13,8 @@
* along with this program. If not, see .
*/
-#ifndef _TD_MNODE_H_
-#define _TD_MNODE_H_
+#ifndef _TD_MND_H_
+#define _TD_MND_H_
#ifdef __cplusplus
extern "C" {
@@ -30,28 +30,132 @@ typedef void (*SendRedirectMsgFp)(SDnode *pDnode, struct SRpcMsg *rpcMsg);
typedef int32_t (*PutMsgToMnodeQFp)(SDnode *pDnode, SMnodeMsg *pMsg);
typedef struct SMnodeLoad {
+ /**
+ * @brief the number of dnodes in cluster.
+ *
+ */
int64_t numOfDnode;
+
+ /**
+ * @brief the number of mnodes in cluster.
+ *
+ */
int64_t numOfMnode;
+
+ /**
+ * @brief the number of vgroups in cluster.
+ *
+ */
int64_t numOfVgroup;
+
+ /**
+ * @brief the number of databases in cluster.
+ *
+ */
int64_t numOfDatabase;
+
+ /**
+ * @brief the number of super tables in cluster.
+ *
+ */
int64_t numOfSuperTable;
+
+ /**
+ * @brief the number of child tables in cluster.
+ *
+ */
int64_t numOfChildTable;
+
+ /**
+ * @brief the number of normal tables in cluster.
+ *
+ */
+ int64_t numOfNormalTable;
+
+ /**
+ * @brief the number of numOfTimeseries in cluster.
+ *
+ */
int64_t numOfColumn;
+
+ /**
+ * @brief total points written in cluster.
+ *
+ */
int64_t totalPoints;
+
+ /**
+ * @brief total storage in cluster.
+ *
+ */
int64_t totalStorage;
+
+ /**
+ * @brief total compressed storage in cluster.
+ *
+ */
int64_t compStorage;
} SMnodeLoad;
typedef struct {
- int32_t dnodeId;
- int64_t clusterId;
- int8_t replica;
- int8_t selfIndex;
- SReplica replicas[TSDB_MAX_REPLICA];
- struct SDnode *pDnode;
- PutMsgToMnodeQFp putMsgToApplyMsgFp;
- SendMsgToDnodeFp sendMsgToDnodeFp;
- SendMsgToMnodeFp sendMsgToMnodeFp;
+ /**
+ * @brief dnodeId of this mnode.
+ *
+ */
+ int32_t dnodeId;
+
+ /**
+ * @brief clusterId of this mnode.
+ *
+ */
+ int64_t clusterId;
+
+ /**
+ * @brief replica num of this mnode.
+ *
+ */
+ int8_t replica;
+
+ /**
+ * @brief self index in the array of replicas.
+ *
+ */
+ int8_t selfIndex;
+
+ /**
+ * @brief detail replica information of this mnode.
+ *
+ */
+ SReplica replicas[TSDB_MAX_REPLICA];
+
+ /**
+ * @brief the parent dnode of this mnode.
+ *
+ */
+ SDnode *pDnode;
+
+ /**
+ * @brief put apply msg to the write queue in dnode.
+ *
+ */
+ PutMsgToMnodeQFp putMsgToApplyMsgFp;
+
+ /**
+ * @brief the callback function while send msg to dnode.
+ *
+ */
+ SendMsgToDnodeFp sendMsgToDnodeFp;
+
+ /**
+ * @brief the callback function while send msg to mnode.
+ *
+ */
+ SendMsgToMnodeFp sendMsgToMnodeFp;
+
+ /**
+ * @brief the callback function while send redirect msg to clients or peers.
+ *
+ */
SendRedirectMsgFp sendRedirectMsgFp;
} SMnodeOpt;
@@ -59,119 +163,115 @@ typedef struct {
/**
* @brief Open a mnode.
*
- * @param path Path of the mnode
- * @param pOption Option of the mnode
- * @return SMnode* The mnode object
+ * @param path Path of the mnode.
+ * @param pOption Option of the mnode.
+ * @return SMnode* The mnode object.
*/
-SMnode *mnodeOpen(const char *path, const SMnodeOpt *pOption);
+SMnode *mndOpen(const char *path, const SMnodeOpt *pOption);
/**
- * @brief Close a mnode
+ * @brief Close a mnode.
*
- * @param pMnode The mnode object to close
+ * @param pMnode The mnode object to close.
*/
-void mnodeClose(SMnode *pMnode);
+void mndClose(SMnode *pMnode);
/**
- * @brief Close a mnode
+ * @brief Close a mnode.
*
- * @param pMnode The mnode object to close
- * @param pOption Options of the mnode
- * @return int32_t 0 for success, -1 for failure
+ * @param pMnode The mnode object to close.
+ * @param pOption Options of the mnode.
+ * @return int32_t 0 for success, -1 for failure.
*/
-int32_t mnodeAlter(SMnode *pMnode, const SMnodeOpt *pOption);
+int32_t mndAlter(SMnode *pMnode, const SMnodeOpt *pOption);
/**
* @brief Drop a mnode.
*
* @param path Path of the mnode.
*/
-void mnodeDestroy(const char *path);
+void mndDestroy(const char *path);
/**
- * @brief Get mnode statistics info
+ * @brief Get mnode statistics info.
*
- * @param pMnode The mnode object
+ * @param pMnode The mnode object.
* @param pLoad Statistics of the mnode.
- * @return int32_t 0 for success, -1 for failure
+ * @return int32_t 0 for success, -1 for failure.
*/
-int32_t mnodeGetLoad(SMnode *pMnode, SMnodeLoad *pLoad);
+int32_t mndGetLoad(SMnode *pMnode, SMnodeLoad *pLoad);
/**
- * @brief Get user authentication info
+ * @brief Get user authentication info.
*
- * @param pMnode The mnode object
+ * @param pMnode The mnode object.
* @param user
* @param spi
* @param encrypt
* @param secret
* @param ckey
- * @return int32_t 0 for success, -1 for failure
+ * @return int32_t 0 for success, -1 for failure.
*/
-int32_t mnodeRetriveAuth(SMnode *pMnode, char *user, char *spi, char *encrypt, char *secret, char *ckey);
+int32_t mndRetriveAuth(SMnode *pMnode, char *user, char *spi, char *encrypt, char *secret, char *ckey);
/**
- * @brief Initialize mnode msg
+ * @brief Initialize mnode msg.
*
- * @param pMnode The mnode object
- * @param pMsg The request rpc msg
- * @return int32_t The created mnode msg
+ * @param pMnode The mnode object.
+ * @param pMsg The request rpc msg.
+ * @return int32_t The created mnode msg.
*/
-SMnodeMsg *mnodeInitMsg(SMnode *pMnode, SRpcMsg *pRpcMsg);
+SMnodeMsg *mndInitMsg(SMnode *pMnode, SRpcMsg *pRpcMsg);
/**
- * @brief Cleanup mnode msg
+ * @brief Cleanup mnode msg.
*
- * @param pMsg The request msg
+ * @param pMsg The request msg.
*/
-void mnodeCleanupMsg(SMnodeMsg *pMsg);
+void mndCleanupMsg(SMnodeMsg *pMsg);
/**
- * @brief Cleanup mnode msg
+ * @brief Cleanup mnode msg.
*
- * @param pMsg The request msg
- * @param code The error code
+ * @param pMsg The request msg.
+ * @param code The error code.
*/
-void mnodeSendRsp(SMnodeMsg *pMsg, int32_t code);
+void mndSendRsp(SMnodeMsg *pMsg, int32_t code);
/**
- * @brief Process the read request
+ * @brief Process the read request.
*
- * @param pMnode The mnode object
- * @param pMsg The request msg
- * @return int32_t 0 for success, -1 for failure
+ * @param pMsg The request msg.
+ * @return int32_t 0 for success, -1 for failure.
*/
-void mnodeProcessReadMsg(SMnode *pMnode, SMnodeMsg *pMsg);
+void mndProcessReadMsg(SMnodeMsg *pMsg);
/**
- * @brief Process the write request
+ * @brief Process the write request.
*
- * @param pMnode The mnode object
- * @param pMsg The request msg
- * @return int32_t 0 for success, -1 for failure
+ * @param pMsg The request msg.
+ * @return int32_t 0 for success, -1 for failure.
*/
-void mnodeProcessWriteMsg(SMnode *pMnode, SMnodeMsg *pMsg);
+void mndProcessWriteMsg(SMnodeMsg *pMsg);
/**
- * @brief Process the sync request
+ * @brief Process the sync request.
*
- * @param pMnode The mnode object
- * @param pMsg The request msg
- * @return int32_t 0 for success, -1 for failure
+ * @param pMsg The request msg.
+ * @return int32_t 0 for success, -1 for failure.
*/
-void mnodeProcessSyncMsg(SMnode *pMnode, SMnodeMsg *pMsg);
+void mndProcessSyncMsg(SMnodeMsg *pMsg);
/**
- * @brief Process the apply request
+ * @brief Process the apply request.
*
- * @param pMnode The mnode object
- * @param pMsg The request msg
- * @return int32_t 0 for success, -1 for failure
+ * @param pMsg The request msg.
+ * @return int32_t 0 for success, -1 for failure.
*/
-void mnodeProcessApplyMsg(SMnode *pMnode, SMnodeMsg *pMsg);
+void mndProcessApplyMsg(SMnodeMsg *pMsg);
#ifdef __cplusplus
}
#endif
-#endif /*_TD_MNODE_H_*/
+#endif /*_TD_MND_H_*/
diff --git a/include/dnode/mnode/sdb/sdb.h b/include/dnode/mnode/sdb/sdb.h
index 784672e0ec..3648af5fcb 100644
--- a/include/dnode/mnode/sdb/sdb.h
+++ b/include/dnode/mnode/sdb/sdb.h
@@ -114,56 +114,181 @@ typedef enum {
SDB_START = 0,
SDB_TRANS = 1,
SDB_CLUSTER = 2,
- SDB_DNODE = 3,
- SDB_MNODE = 4,
+ SDB_MNODE = 3,
+ SDB_DNODE = 4,
SDB_USER = 5,
SDB_AUTH = 6,
SDB_ACCT = 7,
- SDB_DB = 8,
SDB_VGROUP = 9,
- SDB_STABLE = 10,
+ SDB_STABLE = 9,
+ SDB_DB = 10,
SDB_FUNC = 11,
SDB_MAX = 12
} ESdbType;
-typedef int32_t (*SdbInsertFp)(void *pObj);
-typedef int32_t (*SdbUpdateFp)(void *pSrcObj, void *pDstObj);
-typedef int32_t (*SdbDeleteFp)(void *pObj);
-typedef int32_t (*SdbDeployFp)();
+typedef struct SSdb SSdb;
+typedef int32_t (*SdbInsertFp)(SSdb *pSdb, void *pObj);
+typedef int32_t (*SdbUpdateFp)(SSdb *pSdb, void *pSrcObj, void *pDstObj);
+typedef int32_t (*SdbDeleteFp)(SSdb *pSdb, void *pObj);
+typedef int32_t (*SdbDeployFp)(SSdb *pSdb);
typedef SSdbRow *(*SdbDecodeFp)(SSdbRaw *pRaw);
typedef SSdbRaw *(*SdbEncodeFp)(void *pObj);
typedef struct {
- ESdbType sdbType;
- EKeyType keyType;
+ /**
+ * @brief The sdb type of the table.
+ *
+ */
+ ESdbType sdbType;
+
+ /**
+ * @brief The key type of the table.
+ *
+ */
+ EKeyType keyType;
+
+ /**
+ * @brief The callback function when the table is first deployed.
+ *
+ */
SdbDeployFp deployFp;
+
+ /**
+ * @brief Encode one row of the table into rawdata.
+ *
+ */
SdbEncodeFp encodeFp;
+
+ /**
+ * @brief Decode one row of the table from rawdata.
+ *
+ */
SdbDecodeFp decodeFp;
+
+ /**
+ * @brief The callback function when insert a row to sdb.
+ *
+ */
SdbInsertFp insertFp;
+
+ /**
+ * @brief The callback function when undate a row in sdb.
+ *
+ */
SdbUpdateFp updateFp;
+
+ /**
+ * @brief The callback function when delete a row from sdb.
+ *
+ */
SdbDeleteFp deleteFp;
} SSdbTable;
-typedef struct SSdb SSdb;
+typedef struct SSdbOpt {
+ /**
+ * @brief The path of the sdb file.
+ *
+ */
+ const char *path;
+} SSdbOpt;
-int32_t sdbInit();
-void sdbCleanup();
-void sdbSetTable(SSdbTable table);
+/**
+ * @brief Initialize and start the sdb.
+ *
+ * @param pOption Option of the sdb.
+ * @return SSdb* The sdb object.
+ */
+SSdb *sdbInit(SSdbOpt *pOption);
-int32_t sdbOpen();
-void sdbClose();
-int32_t sdbWrite(SSdbRaw *pRaw);
+/**
+ * @brief Stop and cleanup the sdb.
+ *
+ * @param pSdb The sdb object to close.
+ */
+void sdbCleanup(SSdb *pSdb);
-int32_t sdbDeploy();
-void sdbUnDeploy();
+/**
+ * @brief Set the properties of sdb table.
+ *
+ * @param pSdb The sdb object.
+ * @param table The properties of the table.
+ * @return int32_t 0 for success, -1 for failure.
+ */
+int32_t sdbSetTable(SSdb *pSdb, SSdbTable table);
-void *sdbAcquire(ESdbType sdb, void *pKey);
-void sdbRelease(void *pObj);
-void *sdbFetch(ESdbType sdb, void *pIter, void **ppObj);
-void sdbCancelFetch(void *pIter);
-int32_t sdbGetSize(ESdbType sdb);
+/**
+ * @brief Set the initial rows of sdb.
+ *
+ * @param pSdb The sdb object.
+ * @return int32_t 0 for success, -1 for failure.
+ */
+int32_t sdbDeploy(SSdb *pSdb);
-SSdbRaw *sdbAllocRaw(ESdbType sdb, int8_t sver, int32_t dataLen);
+/**
+ * @brief Load sdb from file.
+ *
+ * @param pSdb The sdb object.
+ * @return int32_t 0 for success, -1 for failure.
+ */
+int32_t sdbReadFile(SSdb *pSdb);
+
+/**
+ * @brief Parse and write raw data to sdb.
+ *
+ * @param pSdb The sdb object.
+ * @param pRaw The raw data.
+ * @return int32_t 0 for success, -1 for failure.
+ */
+int32_t sdbWrite(SSdb *pSdb, SSdbRaw *pRaw);
+
+/**
+ * @brief Acquire a row from sdb
+ *
+ * @param pSdb The sdb object.
+ * @param type The type of the row.
+ * @param pKey The key value of the row.
+ * @return void* The object of the row.
+ */
+void *sdbAcquire(SSdb *pSdb, ESdbType type, void *pKey);
+
+/**
+ * @brief Release a row from sdb.
+ *
+ * @param pSdb The sdb object.
+ * @param pObj The object of the row.
+ */
+void sdbRelease(SSdb *pSdb, void *pObj);
+
+/**
+ * @brief Traverse a sdb table
+ *
+ * @param pSdb The sdb object.
+ * @param type The type of the table.
+ * @param type The initial iterator of the table.
+ * @param pObj The object of the row just fetched.
+ * @return void* The next iterator of the table.
+ */
+void *sdbFetch(SSdb *pSdb, ESdbType type, void *pIter, void **ppObj);
+
+/**
+ * @brief Cancel a traversal
+ *
+ * @param pSdb The sdb object.
+ * @param pIter The iterator of the table.
+ * @param type The initial iterator of table.
+ */
+void sdbCancelFetch(SSdb *pSdb, void *pIter);
+
+/**
+ * @brief Get the number of rows in the table
+ *
+ * @param pSdb The sdb object.
+ * @param pIter The type of the table.
+ * @record int32_t The number of rows in the table
+ */
+int32_t sdbGetSize(SSdb *pSdb, ESdbType type);
+
+SSdbRaw *sdbAllocRaw(ESdbType type, int8_t sver, int32_t dataLen);
void sdbFreeRaw(SSdbRaw *pRaw);
int32_t sdbSetRawInt8(SSdbRaw *pRaw, int32_t dataPos, int8_t val);
int32_t sdbSetRawInt32(SSdbRaw *pRaw, int32_t dataPos, int32_t val);
diff --git a/source/dnode/mgmt/impl/CMakeLists.txt b/source/dnode/mgmt/impl/CMakeLists.txt
index d0830484ed..3eadf24164 100644
--- a/source/dnode/mgmt/impl/CMakeLists.txt
+++ b/source/dnode/mgmt/impl/CMakeLists.txt
@@ -12,5 +12,5 @@ target_link_libraries(
target_include_directories(
dnode
PUBLIC "${CMAKE_SOURCE_DIR}/include/dnode/mgmt"
- private "${CMAKE_CURRENT_SOURCE_DIR}/inc"
+ PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/inc"
)
diff --git a/source/dnode/mgmt/impl/src/dndDnode.c b/source/dnode/mgmt/impl/src/dndDnode.c
index fa601a0d99..4265c8a3cd 100644
--- a/source/dnode/mgmt/impl/src/dndDnode.c
+++ b/source/dnode/mgmt/impl/src/dndDnode.c
@@ -18,32 +18,27 @@
#include "dndTransport.h"
#include "dndVnodes.h"
-static inline void dndRLockDnode(SDnode *pDnode) { taosRLockLatch(&pDnode->dmgmt.latch); }
-
-static inline void dndRUnLockDnode(SDnode *pDnode) { taosRUnLockLatch(&pDnode->dmgmt.latch); }
-
-static inline void dndWLockDnode(SDnode *pDnode) { taosWLockLatch(&pDnode->dmgmt.latch); }
-
-static inline void dndWUnLockDnode(SDnode *pDnode) { taosWUnLockLatch(&pDnode->dmgmt.latch); }
-
int32_t dndGetDnodeId(SDnode *pDnode) {
- dndRLockDnode(pDnode);
- int32_t dnodeId = pDnode->dmgmt.dnodeId;
- dndRUnLockDnode(pDnode);
+ SDnodeMgmt *pMgmt = &pDnode->dmgmt;
+ taosRLockLatch(&pMgmt->latch);
+ int32_t dnodeId = pMgmt->dnodeId;
+ taosRUnLockLatch(&pMgmt->latch);
return dnodeId;
}
int64_t dndGetClusterId(SDnode *pDnode) {
- dndRLockDnode(pDnode);
- int64_t clusterId = pDnode->dmgmt.clusterId;
- dndRUnLockDnode(pDnode);
+ SDnodeMgmt *pMgmt = &pDnode->dmgmt;
+ taosRLockLatch(&pMgmt->latch);
+ int64_t clusterId = pMgmt->clusterId;
+ taosRUnLockLatch(&pMgmt->latch);
return clusterId;
}
void dndGetDnodeEp(SDnode *pDnode, int32_t dnodeId, char *pEp, char *pFqdn, uint16_t *pPort) {
- dndRLockDnode(pDnode);
+ SDnodeMgmt *pMgmt = &pDnode->dmgmt;
+ taosRLockLatch(&pMgmt->latch);
- SDnodeEp *pDnodeEp = taosHashGet(pDnode->dmgmt.dnodeHash, &dnodeId, sizeof(int32_t));
+ SDnodeEp *pDnodeEp = taosHashGet(pMgmt->dnodeHash, &dnodeId, sizeof(int32_t));
if (pDnodeEp != NULL) {
if (pPort != NULL) {
*pPort = pDnodeEp->port;
@@ -56,13 +51,14 @@ void dndGetDnodeEp(SDnode *pDnode, int32_t dnodeId, char *pEp, char *pFqdn, uint
}
}
- dndRUnLockDnode(pDnode);
+ taosRUnLockLatch(&pMgmt->latch);
}
void dndGetMnodeEpSet(SDnode *pDnode, SEpSet *pEpSet) {
- dndRLockDnode(pDnode);
- *pEpSet = pDnode->dmgmt.mnodeEpSet;
- dndRUnLockDnode(pDnode);
+ SDnodeMgmt *pMgmt = &pDnode->dmgmt;
+ taosRLockLatch(&pMgmt->latch);
+ *pEpSet = pMgmt->mnodeEpSet;
+ taosRUnLockLatch(&pMgmt->latch);
}
void dndSendRedirectMsg(SDnode *pDnode, SRpcMsg *pMsg) {
@@ -87,14 +83,15 @@ void dndSendRedirectMsg(SDnode *pDnode, SRpcMsg *pMsg) {
static void dndUpdateMnodeEpSet(SDnode *pDnode, SEpSet *pEpSet) {
dInfo("mnode is changed, num:%d inUse:%d", pEpSet->numOfEps, pEpSet->inUse);
- dndWLockDnode(pDnode);
+ SDnodeMgmt *pMgmt = &pDnode->dmgmt;
+ taosWLockLatch(&pMgmt->latch);
- pDnode->dmgmt.mnodeEpSet = *pEpSet;
+ pMgmt->mnodeEpSet = *pEpSet;
for (int32_t i = 0; i < pEpSet->numOfEps; ++i) {
dInfo("mnode index:%d %s:%u", i, pEpSet->fqdn[i], pEpSet->port[i]);
}
- dndWUnLockDnode(pDnode);
+ taosWUnLockLatch(&pMgmt->latch);
}
static void dndPrintDnodes(SDnode *pDnode) {
@@ -124,12 +121,14 @@ static void dndResetDnodes(SDnode *pDnode, SDnodeEps *pDnodeEps) {
}
pMgmt->mnodeEpSet.inUse = 0;
+ pMgmt->mnodeEpSet.numOfEps = 0;
int32_t mIndex = 0;
for (int32_t i = 0; i < pMgmt->dnodeEps->num; i++) {
SDnodeEp *pDnodeEp = &pMgmt->dnodeEps->eps[i];
if (!pDnodeEp->isMnode) continue;
if (mIndex >= TSDB_MAX_REPLICA) continue;
+ pMgmt->mnodeEpSet.numOfEps++;
strcpy(pMgmt->mnodeEpSet.fqdn[mIndex], pDnodeEp->fqdn);
pMgmt->mnodeEpSet.port[mIndex] = pDnodeEp->port;
mIndex++;
@@ -145,16 +144,18 @@ static void dndResetDnodes(SDnode *pDnode, SDnodeEps *pDnodeEps) {
static bool dndIsEpChanged(SDnode *pDnode, int32_t dnodeId, char *pEp) {
bool changed = false;
- dndRLockDnode(pDnode);
- SDnodeEp *pDnodeEp = taosHashGet(pDnode->dmgmt.dnodeHash, &dnodeId, sizeof(int32_t));
+ SDnodeMgmt *pMgmt = &pDnode->dmgmt;
+ taosRLockLatch(&pMgmt->latch);
+
+ SDnodeEp *pDnodeEp = taosHashGet(pMgmt->dnodeHash, &dnodeId, sizeof(int32_t));
if (pDnodeEp != NULL) {
char epstr[TSDB_EP_LEN + 1];
snprintf(epstr, TSDB_EP_LEN, "%s:%u", pDnodeEp->fqdn, pDnodeEp->port);
changed = strcmp(pEp, epstr) != 0;
}
- dndRUnLockDnode(pDnode);
+ taosRUnLockLatch(&pMgmt->latch);
return changed;
}
@@ -280,6 +281,7 @@ PRASE_DNODE_OVER:
if (pMgmt->dnodeEps == NULL) {
pMgmt->dnodeEps = calloc(1, sizeof(SDnodeEps) + sizeof(SDnodeEp));
pMgmt->dnodeEps->num = 1;
+ pMgmt->dnodeEps->eps[0].isMnode = 1;
pMgmt->dnodeEps->eps[0].port = pDnode->opt.serverPort;
tstrncpy(pMgmt->dnodeEps->eps[0].fqdn, pDnode->opt.localFqdn, TSDB_FQDN_LEN);
}
@@ -342,11 +344,14 @@ static void dndSendStatusMsg(SDnode *pDnode) {
return;
}
- dndRLockDnode(pDnode);
+ bool changed = false;
+
+ SDnodeMgmt *pMgmt = &pDnode->dmgmt;
+ taosRLockLatch(&pMgmt->latch);
pStatus->sversion = htonl(pDnode->opt.sver);
- pStatus->dnodeId = htonl(pDnode->dmgmt.dnodeId);
- pStatus->clusterId = htobe64(pDnode->dmgmt.clusterId);
- pStatus->rebootTime = htonl(pDnode->dmgmt.rebootTime);
+ pStatus->dnodeId = htonl(pMgmt->dnodeId);
+ pStatus->clusterId = htobe64(pMgmt->clusterId);
+ pStatus->rebootTime = htonl(pMgmt->rebootTime);
pStatus->numOfCores = htonl(pDnode->opt.numOfCores);
tstrncpy(pStatus->dnodeEp, pDnode->opt.localEp, TSDB_EP_LEN);
pStatus->clusterCfg.statusInterval = htonl(pDnode->opt.statusInterval);
@@ -356,7 +361,7 @@ static void dndSendStatusMsg(SDnode *pDnode) {
pStatus->clusterCfg.checkTime = 0;
char timestr[32] = "1970-01-01 00:00:00.00";
(void)taosParseTime(timestr, &pStatus->clusterCfg.checkTime, (int32_t)strlen(timestr), TSDB_TIME_PRECISION_MILLI, 0);
- dndRUnLockDnode(pDnode);
+ taosRUnLockLatch(&pMgmt->latch);
dndGetVnodeLoads(pDnode, &pStatus->vnodeLoads);
contLen = sizeof(SStatusMsg) + pStatus->vnodeLoads.num * sizeof(SVnodeLoad);
@@ -370,32 +375,33 @@ static void dndUpdateDnodeCfg(SDnode *pDnode, SDnodeCfg *pCfg) {
if (pMgmt->dnodeId == 0 || pMgmt->dropped != pCfg->dropped) {
dInfo("set dnodeId:%d clusterId:%" PRId64 " dropped:%d", pCfg->dnodeId, pCfg->clusterId, pCfg->dropped);
- dndWLockDnode(pDnode);
+ taosWLockLatch(&pMgmt->latch);
pMgmt->dnodeId = pCfg->dnodeId;
pMgmt->clusterId = pCfg->clusterId;
pMgmt->dropped = pCfg->dropped;
(void)dndWriteDnodes(pDnode);
- dndWUnLockDnode(pDnode);
+ taosWUnLockLatch(&pMgmt->latch);
}
}
static void dndUpdateDnodeEps(SDnode *pDnode, SDnodeEps *pDnodeEps) {
if (pDnodeEps == NULL || pDnodeEps->num <= 0) return;
- dndWLockDnode(pDnode);
+ SDnodeMgmt *pMgmt = &pDnode->dmgmt;
+ taosWLockLatch(&pMgmt->latch);
- if (pDnodeEps->num != pDnode->dmgmt.dnodeEps->num) {
+ if (pDnodeEps->num != pMgmt->dnodeEps->num) {
dndResetDnodes(pDnode, pDnodeEps);
dndWriteDnodes(pDnode);
} else {
int32_t size = pDnodeEps->num * sizeof(SDnodeEp) + sizeof(SDnodeEps);
- if (memcmp(pDnode->dmgmt.dnodeEps, pDnodeEps, size) != 0) {
+ if (memcmp(pMgmt->dnodeEps, pDnodeEps, size) != 0) {
dndResetDnodes(pDnode, pDnodeEps);
dndWriteDnodes(pDnode);
}
}
- dndWUnLockDnode(pDnode);
+ taosWUnLockLatch(&pMgmt->latch);
}
static void dndProcessStatusRsp(SDnode *pDnode, SRpcMsg *pMsg, SEpSet *pEpSet) {
@@ -458,7 +464,7 @@ static void *dnodeThreadRoutine(void *param) {
pthread_testcancel();
if (dndGetStat(pDnode) == DND_STAT_RUNNING) {
- dndSendStatusMsg(pDnode);
+ // dndSendStatusMsg(pDnode);
}
}
}
@@ -512,7 +518,7 @@ void dndCleanupDnode(SDnode *pDnode) {
pMgmt->threadId = NULL;
}
- dndWLockDnode(pDnode);
+ taosWLockLatch(&pMgmt->latch);
if (pMgmt->dnodeEps != NULL) {
free(pMgmt->dnodeEps);
@@ -529,7 +535,7 @@ void dndCleanupDnode(SDnode *pDnode) {
pMgmt->file = NULL;
}
- dndWUnLockDnode(pDnode);
+ taosWUnLockLatch(&pMgmt->latch);
dInfo("dnode-dnode is cleaned up");
}
diff --git a/source/dnode/mgmt/impl/src/dndMnode.c b/source/dnode/mgmt/impl/src/dndMnode.c
index fe3accdd84..ca48642899 100644
--- a/source/dnode/mgmt/impl/src/dndMnode.c
+++ b/source/dnode/mgmt/impl/src/dndMnode.c
@@ -80,7 +80,9 @@ static SMnode *dndAcquireMnode(SDnode *pDnode) {
}
taosRUnLockLatch(&pMgmt->latch);
- dTrace("acquire mnode, refCount:%d", refCount);
+ if (pMnode != NULL) {
+ dTrace("acquire mnode, refCount:%d", refCount);
+ }
return pMnode;
}
@@ -94,7 +96,9 @@ static void dndReleaseMnode(SDnode *pDnode, SMnode *pMnode) {
}
taosRUnLockLatch(&pMgmt->latch);
- dTrace("release mnode, refCount:%d", refCount);
+ if (pMnode != NULL) {
+ dTrace("release mnode, refCount:%d", refCount);
+ }
}
static int32_t dndReadMnodeFile(SDnode *pDnode) {
@@ -360,13 +364,13 @@ static int32_t dndBuildMnodeOptionFromMsg(SDnode *pDnode, SMnodeOpt *pOption, SC
pOption->replica = pMsg->replica;
pOption->selfIndex = -1;
- for (int32_t index = 0; index < pMsg->replica; ++index) {
- SReplica *pReplica = &pOption->replicas[index];
- pReplica->id = pMsg->replicas[index].id;
- pReplica->port = pMsg->replicas[index].port;
- tstrncpy(pReplica->fqdn, pMsg->replicas[index].fqdn, TSDB_FQDN_LEN);
+ for (int32_t i = 0; i < pMsg->replica; ++i) {
+ SReplica *pReplica = &pOption->replicas[i];
+ pReplica->id = pMsg->replicas[i].id;
+ pReplica->port = pMsg->replicas[i].port;
+ tstrncpy(pReplica->fqdn, pMsg->replicas[i].fqdn, TSDB_FQDN_LEN);
if (pReplica->id == pOption->dnodeId) {
- pOption->selfIndex = index;
+ pOption->selfIndex = i;
}
}
@@ -392,7 +396,7 @@ static int32_t dndOpenMnode(SDnode *pDnode, SMnodeOpt *pOption) {
return code;
}
- SMnode *pMnode = mnodeOpen(pDnode->dir.mnode, pOption);
+ SMnode *pMnode = mndOpen(pDnode->dir.mnode, pOption);
if (pMnode == NULL) {
dError("failed to open mnode since %s", terrstr());
code = terrno;
@@ -405,8 +409,8 @@ static int32_t dndOpenMnode(SDnode *pDnode, SMnodeOpt *pOption) {
dError("failed to write mnode file since %s", terrstr());
code = terrno;
dndStopMnodeWorker(pDnode);
- mnodeClose(pMnode);
- mnodeDestroy(pDnode->dir.mnode);
+ mndClose(pMnode);
+ mndDestroy(pDnode->dir.mnode);
terrno = code;
return code;
}
@@ -428,7 +432,7 @@ static int32_t dndAlterMnode(SDnode *pDnode, SMnodeOpt *pOption) {
return -1;
}
- if (mnodeAlter(pMnode, pOption) != 0) {
+ if (mndAlter(pMnode, pOption) != 0) {
dError("failed to alter mnode since %s", terrstr());
dndReleaseMnode(pDnode, pMnode);
return -1;
@@ -463,8 +467,8 @@ static int32_t dndDropMnode(SDnode *pDnode) {
dndStopMnodeWorker(pDnode);
dndWriteMnodeFile(pDnode);
- mnodeClose(pMnode);
- mnodeDestroy(pDnode->dir.mnode);
+ mndClose(pMnode);
+ mndDestroy(pDnode->dir.mnode);
return 0;
}
@@ -491,6 +495,7 @@ static int32_t dndProcessCreateMnodeReq(SDnode *pDnode, SRpcMsg *pRpcMsg) {
if (dndBuildMnodeOptionFromMsg(pDnode, &option, pMsg) != 0) {
return -1;
}
+
return dndOpenMnode(pDnode, &option);
}
}
@@ -550,13 +555,13 @@ static void dndProcessMnodeReadQueue(SDnode *pDnode, SMnodeMsg *pMsg) {
SMnode *pMnode = dndAcquireMnode(pDnode);
if (pMnode != NULL) {
- mnodeProcessReadMsg(pMnode, pMsg);
+ mndProcessReadMsg(pMsg);
dndReleaseMnode(pDnode, pMnode);
} else {
- mnodeSendRsp(pMsg, terrno);
+ mndSendRsp(pMsg, terrno);
}
- mnodeCleanupMsg(pMsg);
+ mndCleanupMsg(pMsg);
}
static void dndProcessMnodeWriteQueue(SDnode *pDnode, SMnodeMsg *pMsg) {
@@ -564,13 +569,13 @@ static void dndProcessMnodeWriteQueue(SDnode *pDnode, SMnodeMsg *pMsg) {
SMnode *pMnode = dndAcquireMnode(pDnode);
if (pMnode != NULL) {
- mnodeProcessWriteMsg(pMnode, pMsg);
+ mndProcessWriteMsg(pMsg);
dndReleaseMnode(pDnode, pMnode);
} else {
- mnodeSendRsp(pMsg, terrno);
+ mndSendRsp(pMsg, terrno);
}
- mnodeCleanupMsg(pMsg);
+ mndCleanupMsg(pMsg);
}
static void dndProcessMnodeApplyQueue(SDnode *pDnode, SMnodeMsg *pMsg) {
@@ -578,13 +583,13 @@ static void dndProcessMnodeApplyQueue(SDnode *pDnode, SMnodeMsg *pMsg) {
SMnode *pMnode = dndAcquireMnode(pDnode);
if (pMnode != NULL) {
- mnodeProcessApplyMsg(pMnode, pMsg);
+ mndProcessApplyMsg(pMsg);
dndReleaseMnode(pDnode, pMnode);
} else {
- mnodeSendRsp(pMsg, terrno);
+ mndSendRsp(pMsg, terrno);
}
- mnodeCleanupMsg(pMsg);
+ mndCleanupMsg(pMsg);
}
static void dndProcessMnodeSyncQueue(SDnode *pDnode, SMnodeMsg *pMsg) {
@@ -592,26 +597,26 @@ static void dndProcessMnodeSyncQueue(SDnode *pDnode, SMnodeMsg *pMsg) {
SMnode *pMnode = dndAcquireMnode(pDnode);
if (pMnode != NULL) {
- mnodeProcessSyncMsg(pMnode, pMsg);
+ mndProcessSyncMsg(pMsg);
dndReleaseMnode(pDnode, pMnode);
} else {
- mnodeSendRsp(pMsg, terrno);
+ mndSendRsp(pMsg, terrno);
}
- mnodeCleanupMsg(pMsg);
+ mndCleanupMsg(pMsg);
}
static int32_t dndWriteMnodeMsgToQueue(SMnode *pMnode, taos_queue pQueue, SRpcMsg *pRpcMsg) {
assert(pQueue);
- SMnodeMsg *pMsg = mnodeInitMsg(pMnode, pRpcMsg);
+ SMnodeMsg *pMsg = mndInitMsg(pMnode, pRpcMsg);
if (pMsg == NULL) {
terrno = TSDB_CODE_OUT_OF_MEMORY;
return -1;
}
if (taosWriteQitem(pQueue, pMsg) != 0) {
- mnodeCleanupMsg(pMsg);
+ mndCleanupMsg(pMsg);
terrno = TSDB_CODE_OUT_OF_MEMORY;
return -1;
}
@@ -683,7 +688,7 @@ static int32_t dndPutMsgIntoMnodeApplyQueue(SDnode *pDnode, SMnodeMsg *pMsg) {
static int32_t dndAllocMnodeMgmtQueue(SDnode *pDnode) {
SMnodeMgmt *pMgmt = &pDnode->mmgmt;
- pMgmt->pMgmtQ = tWorkerAllocQueue(&pMgmt->mgmtPool, NULL, (FProcessItem)dndProcessMnodeMgmtQueue);
+ pMgmt->pMgmtQ = tWorkerAllocQueue(&pMgmt->mgmtPool, pDnode, (FProcessItem)dndProcessMnodeMgmtQueue);
if (pMgmt->pMgmtQ == NULL) {
terrno = TSDB_CODE_OUT_OF_MEMORY;
return -1;
@@ -708,18 +713,19 @@ static int32_t dndInitMnodeMgmtWorker(SDnode *pDnode) {
return -1;
}
+ dDebug("mnode mgmt worker is initialized");
return 0;
}
static void dndCleanupMnodeMgmtWorker(SDnode *pDnode) {
SMnodeMgmt *pMgmt = &pDnode->mmgmt;
tWorkerCleanup(&pMgmt->mgmtPool);
- dDebug("mnode mgmt worker is stopped");
+ dDebug("mnode mgmt worker is closed");
}
static int32_t dndAllocMnodeReadQueue(SDnode *pDnode) {
SMnodeMgmt *pMgmt = &pDnode->mmgmt;
- pMgmt->pReadQ = tWorkerAllocQueue(&pMgmt->readPool, NULL, (FProcessItem)dndProcessMnodeReadQueue);
+ pMgmt->pReadQ = tWorkerAllocQueue(&pMgmt->readPool, pDnode, (FProcessItem)dndProcessMnodeReadQueue);
if (pMgmt->pReadQ == NULL) {
terrno = TSDB_CODE_OUT_OF_MEMORY;
return -1;
@@ -745,18 +751,19 @@ static int32_t dndInitMnodeReadWorker(SDnode *pDnode) {
return -1;
}
+ dDebug("mnode read worker is initialized");
return 0;
}
static void dndCleanupMnodeReadWorker(SDnode *pDnode) {
SMnodeMgmt *pMgmt = &pDnode->mmgmt;
tWorkerCleanup(&pMgmt->readPool);
- dDebug("mnode read worker is stopped");
+ dDebug("mnode read worker is closed");
}
static int32_t dndAllocMnodeWriteQueue(SDnode *pDnode) {
SMnodeMgmt *pMgmt = &pDnode->mmgmt;
- pMgmt->pWriteQ = tWorkerAllocQueue(&pMgmt->writePool, NULL, (FProcessItem)dndProcessMnodeWriteQueue);
+ pMgmt->pWriteQ = tWorkerAllocQueue(&pMgmt->writePool, pDnode, (FProcessItem)dndProcessMnodeWriteQueue);
if (pMgmt->pWriteQ == NULL) {
terrno = TSDB_CODE_OUT_OF_MEMORY;
return -1;
@@ -773,7 +780,7 @@ static void dndFreeMnodeWriteQueue(SDnode *pDnode) {
static int32_t dndAllocMnodeApplyQueue(SDnode *pDnode) {
SMnodeMgmt *pMgmt = &pDnode->mmgmt;
- pMgmt->pApplyQ = tWorkerAllocQueue(&pMgmt->writePool, NULL, (FProcessItem)dndProcessMnodeApplyQueue);
+ pMgmt->pApplyQ = tWorkerAllocQueue(&pMgmt->writePool, pDnode, (FProcessItem)dndProcessMnodeApplyQueue);
if (pMgmt->pApplyQ == NULL) {
terrno = TSDB_CODE_OUT_OF_MEMORY;
return -1;
@@ -799,18 +806,19 @@ static int32_t dndInitMnodeWriteWorker(SDnode *pDnode) {
return -1;
}
+ dDebug("mnode write worker is initialized");
return 0;
}
static void dndCleanupMnodeWriteWorker(SDnode *pDnode) {
SMnodeMgmt *pMgmt = &pDnode->mmgmt;
tWorkerCleanup(&pMgmt->writePool);
- dDebug("mnode write worker is stopped");
+ dDebug("mnode write worker is closed");
}
static int32_t dndAllocMnodeSyncQueue(SDnode *pDnode) {
SMnodeMgmt *pMgmt = &pDnode->mmgmt;
- pMgmt->pSyncQ = tWorkerAllocQueue(&pMgmt->syncPool, NULL, (FProcessItem)dndProcessMnodeSyncQueue);
+ pMgmt->pSyncQ = tWorkerAllocQueue(&pMgmt->syncPool, pDnode, (FProcessItem)dndProcessMnodeSyncQueue);
if (pMgmt->pSyncQ == NULL) {
terrno = TSDB_CODE_OUT_OF_MEMORY;
return -1;
@@ -836,13 +844,14 @@ static int32_t dndInitMnodeSyncWorker(SDnode *pDnode) {
return -1;
}
+ dDebug("mnode sync worker is initialized");
return 0;
}
static void dndCleanupMnodeSyncWorker(SDnode *pDnode) {
SMnodeMgmt *pMgmt = &pDnode->mmgmt;
tWorkerCleanup(&pMgmt->syncPool);
- dDebug("mnode sync worker is stopped");
+ dDebug("mnode sync worker is closed");
}
int32_t dndInitMnode(SDnode *pDnode) {
@@ -869,7 +878,7 @@ int32_t dndInitMnode(SDnode *pDnode) {
if (pMgmt->dropped) {
dInfo("mnode has been deployed and needs to be deleted");
- mnodeDestroy(pDnode->dir.mnode);
+ mndDestroy(pDnode->dir.mnode);
return 0;
}
@@ -912,7 +921,7 @@ int32_t dndGetUserAuthFromMnode(SDnode *pDnode, char *user, char *spi, char *enc
return -1;
}
- int32_t code = mnodeRetriveAuth(pMnode, user, spi, encrypt, secret, ckey);
+ int32_t code = mndRetriveAuth(pMnode, user, spi, encrypt, secret, ckey);
dndReleaseMnode(pDnode, pMnode);
return code;
}
diff --git a/source/dnode/mgmt/impl/src/dndTransport.c b/source/dnode/mgmt/impl/src/dndTransport.c
index c3940cd3cc..eee2e36c0f 100644
--- a/source/dnode/mgmt/impl/src/dndTransport.c
+++ b/source/dnode/mgmt/impl/src/dndTransport.c
@@ -187,6 +187,7 @@ static void dndProcessRequest(void *param, SRpcMsg *pMsg, SEpSet *pEpSet) {
int32_t msgType = pMsg->msgType;
if (msgType == TSDB_MSG_TYPE_NETWORK_TEST) {
+ dTrace("RPC %p, network test req will be processed", pMsg->handle);
dndProcessDnodeReq(pDnode, pMsg, pEpSet);
return;
}
@@ -206,6 +207,7 @@ static void dndProcessRequest(void *param, SRpcMsg *pMsg, SEpSet *pEpSet) {
}
if (pMsg->pCont == NULL) {
+ dTrace("RPC %p, req:%s not processed since content is null", pMsg->handle, taosMsg[msgType]);
SRpcMsg rspMsg = {.handle = pMsg->handle, .code = TSDB_CODE_DND_INVALID_MSG_LEN};
rpcSendResponse(&rspMsg);
return;
@@ -259,12 +261,12 @@ static int32_t dndRetrieveUserAuthInfo(void *parent, char *user, char *spi, char
SDnode *pDnode = parent;
if (dndAuthInternalMsg(parent, user, spi, encrypt, secret, ckey) == 0) {
- dTrace("get internal auth success");
+ // dTrace("get internal auth success");
return 0;
}
if (dndGetUserAuthFromMnode(pDnode, user, spi, encrypt, secret, ckey) == 0) {
- dTrace("get auth from internal mnode");
+ // dTrace("get auth from internal mnode");
return 0;
}
@@ -273,7 +275,7 @@ static int32_t dndRetrieveUserAuthInfo(void *parent, char *user, char *spi, char
return -1;
}
- dDebug("user:%s, send auth msg to other mnodes", user);
+ // dDebug("user:%s, send auth msg to other mnodes", user);
SAuthMsg *pMsg = rpcMallocCont(sizeof(SAuthMsg));
tstrncpy(pMsg->user, user, TSDB_USER_LEN);
diff --git a/source/dnode/mgmt/impl/src/dnode.c b/source/dnode/mgmt/impl/src/dnode.c
index 23c9ee0ebf..1159bbb4c5 100644
--- a/source/dnode/mgmt/impl/src/dnode.c
+++ b/source/dnode/mgmt/impl/src/dnode.c
@@ -26,7 +26,7 @@
EStat dndGetStat(SDnode *pDnode) { return pDnode->stat; }
void dndSetStat(SDnode *pDnode, EStat stat) {
- dDebug("dnode stat set from %s to %s", dndStatStr(pDnode->stat), dndStatStr(stat));
+ dDebug("dnode status set from %s to %s", dndStatStr(pDnode->stat), dndStatStr(stat));
pDnode->stat = stat;
}
@@ -214,8 +214,7 @@ void dndCleanup(SDnode *pDnode) {
dndCleanupDnode(pDnode);
walCleanUp();
rpcCleanup();
-
- dInfo("TDengine is cleaned up successfully");
dndCleanupEnv(pDnode);
free(pDnode);
+ dInfo("TDengine is cleaned up successfully");
}
diff --git a/source/dnode/mnode/impl/CMakeLists.txt b/source/dnode/mnode/impl/CMakeLists.txt
index 49c9d54513..6fecb457c0 100644
--- a/source/dnode/mnode/impl/CMakeLists.txt
+++ b/source/dnode/mnode/impl/CMakeLists.txt
@@ -3,11 +3,11 @@ add_library(mnode ${MNODE_SRC})
target_include_directories(
mnode
PUBLIC "${CMAKE_SOURCE_DIR}/include/dnode/mnode"
- private "${CMAKE_CURRENT_SOURCE_DIR}/inc"
+ PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/inc"
)
target_link_libraries(
mnode
PRIVATE sdb
- PUBLIC transport
- PUBLIC cjson
+ PRIVATE transport
+ PRIVATE cjson
)
\ No newline at end of file
diff --git a/source/dnode/mnode/impl/inc/mnodeAcct.h b/source/dnode/mnode/impl/inc/mndAcct.h
similarity index 80%
rename from source/dnode/mnode/impl/inc/mnodeAcct.h
rename to source/dnode/mnode/impl/inc/mndAcct.h
index 9491410ddf..2073944cc1 100644
--- a/source/dnode/mnode/impl/inc/mnodeAcct.h
+++ b/source/dnode/mnode/impl/inc/mndAcct.h
@@ -13,20 +13,20 @@
* along with this program. If not, see .
*/
-#ifndef _TD_MNODE_ACCT_H_
-#define _TD_MNODE_ACCT_H_
+#ifndef _TD_MND_ACCT_H_
+#define _TD_MND_ACCT_H_
-#include "mnodeInt.h"
+#include "mndInt.h"
#ifdef __cplusplus
extern "C" {
#endif
-int32_t mnodeInitAcct();
-void mnodeCleanupAcct();
+int32_t mndInitAcct(SMnode *pMnode);
+void mndCleanupAcct(SMnode *pMnode);
#ifdef __cplusplus
}
#endif
-#endif /*_TD_MNODE_ACCT_H_*/
+#endif /*_TD_MND_ACCT_H_*/
diff --git a/source/dnode/mnode/impl/inc/mnodeAuth.h b/source/dnode/mnode/impl/inc/mndAuth.h
similarity index 80%
rename from source/dnode/mnode/impl/inc/mnodeAuth.h
rename to source/dnode/mnode/impl/inc/mndAuth.h
index fc828aca27..b426ce23cf 100644
--- a/source/dnode/mnode/impl/inc/mnodeAuth.h
+++ b/source/dnode/mnode/impl/inc/mndAuth.h
@@ -13,20 +13,20 @@
* along with this program. If not, see .
*/
-#ifndef _TD_MNODE_AUTH_H_
-#define _TD_MNODE_AUTH_H_
+#ifndef _TD_MND_AUTH_H_
+#define _TD_MND_AUTH_H_
-#include "mnodeInt.h"
+#include "mndInt.h"
#ifdef __cplusplus
extern "C" {
#endif
-int32_t mnodeInitAuth();
-void mnodeCleanupAuth();
+int32_t mndInitAuth(SMnode *pMnode);
+void mndCleanupAuth(SMnode *pMnode);
#ifdef __cplusplus
}
#endif
-#endif /*_TD_MNODE_AUTH_H_*/
+#endif /*_TD_MND_AUTH_H_*/
diff --git a/source/dnode/mnode/impl/inc/mndBalance.h b/source/dnode/mnode/impl/inc/mndBalance.h
new file mode 100644
index 0000000000..fa3679d033
--- /dev/null
+++ b/source/dnode/mnode/impl/inc/mndBalance.h
@@ -0,0 +1,32 @@
+/*
+ * Copyright (c) 2019 TAOS Data, Inc.
+ *
+ * This program is free software: you can use, redistribute, and/or modify
+ * it under the terms of the GNU Affero General Public License, version 3
+ * or later ("AGPL"), as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see .
+ */
+
+#ifndef _TD_MND_BALANCE_H_
+#define _TD_MND_BALANCE_H_
+
+#include "mndInt.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+int32_t mndInitBalance(SMnode *pMnode);
+void mndCleanupBalance(SMnode *pMnode);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /*_TD_MND_BALANCE_H_*/
diff --git a/source/dnode/mnode/impl/inc/mndCluster.h b/source/dnode/mnode/impl/inc/mndCluster.h
new file mode 100644
index 0000000000..efc1ada67d
--- /dev/null
+++ b/source/dnode/mnode/impl/inc/mndCluster.h
@@ -0,0 +1,32 @@
+/*
+ * Copyright (c) 2019 TAOS Data, Inc.
+ *
+ * This program is free software: you can use, redistribute, and/or modify
+ * it under the terms of the GNU Affero General Public License, version 3
+ * or later ("AGPL"), as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see .
+ */
+
+#ifndef _TD_MND_CLUSTER_H_
+#define _TD_MND_CLUSTER_H_
+
+#include "mndInt.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+int32_t mndInitCluster(SMnode *pMnode);
+void mndCleanupCluster(SMnode *pMnode);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /*_TD_MND_CLUSTER_H_*/
diff --git a/source/dnode/mnode/impl/inc/mndDb.h b/source/dnode/mnode/impl/inc/mndDb.h
new file mode 100644
index 0000000000..acccb62603
--- /dev/null
+++ b/source/dnode/mnode/impl/inc/mndDb.h
@@ -0,0 +1,32 @@
+/*
+ * Copyright (c) 2019 TAOS Data, Inc.
+ *
+ * This program is free software: you can use, redistribute, and/or modify
+ * it under the terms of the GNU Affero General Public License, version 3
+ * or later ("AGPL"), as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see .
+ */
+
+#ifndef _TD_MND_DATABASE_H_
+#define _TD_MND_DATABASE_H_
+
+#include "mndInt.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+int32_t mndInitDb(SMnode *pMnode);
+void mndCleanupDb(SMnode *pMnode);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /*_TD_MND_DATABASE_H_*/
diff --git a/source/dnode/mnode/impl/inc/mnodeDef.h b/source/dnode/mnode/impl/inc/mndDef.h
similarity index 80%
rename from source/dnode/mnode/impl/inc/mnodeDef.h
rename to source/dnode/mnode/impl/inc/mndDef.h
index ccdba13006..9b8c6eccc8 100644
--- a/source/dnode/mnode/impl/inc/mnodeDef.h
+++ b/source/dnode/mnode/impl/inc/mndDef.h
@@ -13,8 +13,8 @@
* along with this program. If not, see .
*/
-#ifndef _TD_MNODE_DEF_H_
-#define _TD_MNODE_DEF_H_
+#ifndef _TD_MND_DEF_H_
+#define _TD_MND_DEF_H_
#include "os.h"
#include "taosmsg.h"
@@ -39,42 +39,34 @@ extern int32_t mDebugFlag;
#define mDebug(...) { if (mDebugFlag & DEBUG_DEBUG) { taosPrintLog("MND ", mDebugFlag, __VA_ARGS__); }}
#define mTrace(...) { if (mDebugFlag & DEBUG_TRACE) { taosPrintLog("MND ", mDebugFlag, __VA_ARGS__); }}
-// #define mLError(...) { monSaveLog(2, __VA_ARGS__); mError(__VA_ARGS__) }
-// #define mLWarn(...) { monSaveLog(1, __VA_ARGS__); mWarn(__VA_ARGS__) }
-// #define mLInfo(...) { monSaveLog(0, __VA_ARGS__); mInfo(__VA_ARGS__) }
-
-#define mLError(...) {mError(__VA_ARGS__) }
-#define mLWarn(...) {mWarn(__VA_ARGS__) }
-#define mLInfo(...) {mInfo(__VA_ARGS__) }
-
-typedef struct SClusterObj SClusterObj;
-typedef struct SDnodeObj SDnodeObj;
-typedef struct SMnodeObj SMnodeObj;
-typedef struct SAcctObj SAcctObj;
-typedef struct SUserObj SUserObj;
-typedef struct SDbObj SDbObj;
-typedef struct SVgObj SVgObj;
-typedef struct SSTableObj SSTableObj;
-typedef struct SFuncObj SFuncObj;
-typedef struct SOperObj SOperObj;
+typedef struct SClusterObj SClusterObj;
+typedef struct SDnodeObj SDnodeObj;
+typedef struct SMnodeObj SMnodeObj;
+typedef struct SAcctObj SAcctObj;
+typedef struct SUserObj SUserObj;
+typedef struct SDbObj SDbObj;
+typedef struct SVgObj SVgObj;
+typedef struct SSTableObj SSTableObj;
+typedef struct SFuncObj SFuncObj;
+typedef struct SOperObj SOperObj;
typedef enum {
- MN_AUTH_ACCT_START = 0,
- MN_AUTH_ACCT_USER,
- MN_AUTH_ACCT_DNODE,
- MN_AUTH_ACCT_MNODE,
- MN_AUTH_ACCT_DB,
- MN_AUTH_ACCT_TABLE,
- MN_AUTH_ACCT_MAX
-} EMnAuthAcct;
+ MND_AUTH_ACCT_START = 0,
+ MND_AUTH_ACCT_USER,
+ MND_AUTH_ACCT_DNODE,
+ MND_AUTH_ACCT_MNODE,
+ MND_AUTH_ACCT_DB,
+ MND_AUTH_ACCT_TABLE,
+ MND_AUTH_ACCT_MAX
+} EAuthAcct;
typedef enum {
- MN_AUTH_OP_START = 0,
- MN_AUTH_OP_CREATE_USER,
- MN_AUTH_OP_ALTER_USER,
- MN_AUTH_OP_DROP_USER,
- MN_AUTH_MAX
-} EMnAuthOp;
+ MND_AUTH_OP_START = 0,
+ MND_AUTH_OP_CREATE_USER,
+ MND_AUTH_OP_ALTER_USER,
+ MND_AUTH_OP_DROP_USER,
+ MND_AUTH_MAX
+} EAuthOp;
typedef enum {
TRN_STAGE_PREPARE = 1,
@@ -86,11 +78,11 @@ typedef enum {
typedef enum { TRN_POLICY_ROLLBACK = 1, TRN_POLICY_RETRY = 2 } ETrnPolicy;
-
typedef struct STrans {
int32_t id;
ETrnStage stage;
ETrnPolicy policy;
+ SMnode *pMnode;
void *rpcHandle;
SArray *redoLogs;
SArray *undoLogs;
@@ -99,7 +91,6 @@ typedef struct STrans {
SArray *undoActions;
} STrans;
-
typedef struct SClusterObj {
int64_t id;
char uid[TSDB_CLUSTER_ID_LEN];
@@ -202,6 +193,7 @@ typedef struct SDbObj {
int64_t createdTime;
int64_t updateTime;
SDbCfg cfg;
+ int64_t uid;
int8_t status;
int32_t numOfVgroups;
int32_t numOfTables;
@@ -240,13 +232,13 @@ typedef struct SVgObj {
} SVgObj;
typedef struct SSTableObj {
- char tableId[TSDB_TABLE_NAME_LEN];
- uint64_t uid;
- int64_t createdTime;
- int64_t updateTime;
- int32_t numOfColumns; // used by normal table
- int32_t numOfTags;
- SSchema * schema;
+ char tableId[TSDB_TABLE_NAME_LEN];
+ uint64_t uid;
+ int64_t createdTime;
+ int64_t updateTime;
+ int32_t numOfColumns; // used by normal table
+ int32_t numOfTags;
+ SSchema *schema;
} SSTableObj;
typedef struct SFuncObj {
@@ -284,25 +276,26 @@ typedef struct {
typedef struct {
int32_t len;
void *rsp;
-} SMnRsp;
+} SMnodeRsp;
typedef struct SMnodeMsg {
+ SMnode *pMnode;
void (*fp)(SMnodeMsg *pMsg, int32_t code);
SRpcConnInfo conn;
- SUserObj *pUser;
- int16_t received;
- int16_t successed;
- int16_t expected;
- int16_t retry;
- int32_t code;
- int64_t createdTime;
- SMnRsp rpcRsp;
- SRpcMsg rpcMsg;
- char pCont[];
+ SUserObj *pUser;
+ int16_t received;
+ int16_t successed;
+ int16_t expected;
+ int16_t retry;
+ int32_t code;
+ int64_t createdTime;
+ SMnodeRsp rpcRsp;
+ SRpcMsg rpcMsg;
+ char pCont[];
} SMnodeMsg;
#ifdef __cplusplus
}
#endif
-#endif /*_TD_MNODE_DEF_H_*/
+#endif /*_TD_MND_DEF_H_*/
diff --git a/source/dnode/mnode/impl/inc/mndDnode.h b/source/dnode/mnode/impl/inc/mndDnode.h
new file mode 100644
index 0000000000..d7bfdba122
--- /dev/null
+++ b/source/dnode/mnode/impl/inc/mndDnode.h
@@ -0,0 +1,32 @@
+/*
+ * Copyright (c) 2019 TAOS Data, Inc.
+ *
+ * This program is free software: you can use, redistribute, and/or modify
+ * it under the terms of the GNU Affero General Public License, version 3
+ * or later ("AGPL"), as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see .
+ */
+
+#ifndef _TD_MND_DNODE_H_
+#define _TD_MND_DNODE_H_
+
+#include "mndInt.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+int32_t mndInitDnode(SMnode *pMnode);
+void mndCleanupDnode(SMnode *pMnode);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /*_TD_MND_DNODE_H_*/
diff --git a/source/dnode/mnode/impl/inc/mnodeBalance.h b/source/dnode/mnode/impl/inc/mndFunc.h
similarity index 80%
rename from source/dnode/mnode/impl/inc/mnodeBalance.h
rename to source/dnode/mnode/impl/inc/mndFunc.h
index c851d58c30..a531ef31a4 100644
--- a/source/dnode/mnode/impl/inc/mnodeBalance.h
+++ b/source/dnode/mnode/impl/inc/mndFunc.h
@@ -13,20 +13,20 @@
* along with this program. If not, see .
*/
-#ifndef _TD_MNODE_BALANCE_H_
-#define _TD_MNODE_BALANCE_H_
+#ifndef _TD_MND_FUNC_H_
+#define _TD_MND_FUNC_H_
-#include "mnodeInt.h"
+#include "mndInt.h"
#ifdef __cplusplus
extern "C" {
#endif
-int32_t mnodeInitBalance();
-void mnodeCleanupBalance();
+int32_t mndInitFunc(SMnode *pMnode);
+void mndCleanupFunc(SMnode *pMnode);
#ifdef __cplusplus
}
#endif
-#endif /*_TD_MNODE_BALANCE_H_*/
+#endif /*_TD_MND_FUNC_H_*/
diff --git a/source/dnode/mnode/impl/inc/mnodeInt.h b/source/dnode/mnode/impl/inc/mndInt.h
similarity index 54%
rename from source/dnode/mnode/impl/inc/mnodeInt.h
rename to source/dnode/mnode/impl/inc/mndInt.h
index 7f7f91a3af..2c7e597774 100644
--- a/source/dnode/mnode/impl/inc/mnodeInt.h
+++ b/source/dnode/mnode/impl/inc/mndInt.h
@@ -13,28 +13,26 @@
* along with this program. If not, see .
*/
-#ifndef _TD_MNODE_INT_H_
-#define _TD_MNODE_INT_H_
+#ifndef _TD_MND_INT_H_
+#define _TD_MND_INT_H_
-#include "mnodeDef.h"
+#include "mndDef.h"
#include "sdb.h"
-#include "tstep.h"
+#include "tqueue.h"
#ifdef __cplusplus
extern "C" {
#endif
-typedef int32_t (*MnodeRpcFp)(SMnodeMsg *pMsg);
+typedef int32_t (*MndMsgFp)(SMnode *pMnode, SMnodeMsg *pMsg);
+typedef int32_t (*MndInitFp)(SMnode *pMnode);
+typedef void (*MndCleanupFp)(SMnode *pMnode);
-typedef struct SMnodeBak {
- int32_t dnodeId;
- int64_t clusterId;
- tmr_h timer;
- SSteps *pInitSteps;
- SSteps *pStartSteps;
- SMnodeOpt para;
- MnodeRpcFp msgFp[TSDB_MSG_TYPE_MAX];
-} SMnodeBak;
+typedef struct {
+ const char *name;
+ MndInitFp initFp;
+ MndCleanupFp cleanupFp;
+} SMnodeStep;
typedef struct SMnode {
int32_t dnodeId;
@@ -43,29 +41,28 @@ typedef struct SMnode {
int8_t selfIndex;
SReplica replicas[TSDB_MAX_REPLICA];
tmr_h timer;
- SSteps *pInitSteps;
- SSteps *pStartSteps;
- struct SSdb *pSdb;
- struct SDnode *pServer;
- MnodeRpcFp msgFp[TSDB_MSG_TYPE_MAX];
- PutMsgToMnodeQFp putMsgToApplyMsgFp;
+ char *path;
+ SSdb *pSdb;
+ SDnode *pDnode;
+ SArray *pSteps;
+ MndMsgFp msgFp[TSDB_MSG_TYPE_MAX];
SendMsgToDnodeFp sendMsgToDnodeFp;
SendMsgToMnodeFp sendMsgToMnodeFp;
SendRedirectMsgFp sendRedirectMsgFp;
+ PutMsgToMnodeQFp putMsgToApplyMsgFp;
} SMnode;
-tmr_h mnodeGetTimer();
-int32_t mnodeGetDnodeId();
-int64_t mnodeGetClusterId();
+tmr_h mndGetTimer(SMnode *pMnode);
+int32_t mndGetDnodeId(SMnode *pMnode);
+int64_t mndGetClusterId(SMnode *pMnode);
-void mnodeSendMsgToDnode(SMnode *pMnode, struct SEpSet *epSet, struct SRpcMsg *rpcMsg);
-void mnodeSendMsgToMnode(SMnode *pMnode, struct SRpcMsg *rpcMsg);
-void mnodeSendRedirectMsg(SMnode *pMnode, struct SRpcMsg *rpcMsg, bool forShell);
-
-void mnodeSetMsgFp(int32_t msgType, MnodeRpcFp fp);
+void mndSendMsgToDnode(SMnode *pMnode, SEpSet *pEpSet, SRpcMsg *rpcMsg);
+void mndSendMsgToMnode(SMnode *pMnode, SRpcMsg *pMsg);
+void mndSendRedirectMsg(SMnode *pMnode, SRpcMsg *pMsg);
+void mndSetMsgHandle(SMnode *pMnode, int32_t msgType, MndMsgFp fp);
#ifdef __cplusplus
}
#endif
-#endif /*_TD_MNODE_INT_H_*/
+#endif /*_TD_MND_INT_H_*/
diff --git a/source/dnode/mnode/impl/inc/mndMnode.h b/source/dnode/mnode/impl/inc/mndMnode.h
new file mode 100644
index 0000000000..c57e1d42a5
--- /dev/null
+++ b/source/dnode/mnode/impl/inc/mndMnode.h
@@ -0,0 +1,34 @@
+/*
+ * Copyright (c) 2019 TAOS Data, Inc.
+ *
+ * This program is free software: you can use, redistribute, and/or modify
+ * it under the terms of the GNU Affero General Public License, version 3
+ * or later ("AGPL"), as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see .
+ */
+
+#ifndef _TD_MND_MNODE_H_
+#define _TD_MND_MNODE_H_
+
+#include "mndInt.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+int32_t mndInitMnode(SMnode *pMnode);
+void mndCleanupMnode(SMnode *pMnode);
+void mndGetMnodeEpSetForPeer(SEpSet *epSet, bool redirect);
+void mndGetMnodeEpSetForShell(SEpSet *epSet, bool redirect);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /*_TD_MND_MNODE_H_*/
diff --git a/source/dnode/mnode/impl/inc/mnodeOper.h b/source/dnode/mnode/impl/inc/mndOper.h
similarity index 82%
rename from source/dnode/mnode/impl/inc/mnodeOper.h
rename to source/dnode/mnode/impl/inc/mndOper.h
index 4392422b23..5ad5059a0f 100644
--- a/source/dnode/mnode/impl/inc/mnodeOper.h
+++ b/source/dnode/mnode/impl/inc/mndOper.h
@@ -13,18 +13,18 @@
* along with this program. If not, see .
*/
-#ifndef _TD_MNODE_OPER_H_
-#define _TD_MNODE_OPER_H_
+#ifndef _TD_MND_OPER_H_
+#define _TD_MND_OPER_H_
#ifdef __cplusplus
extern "C" {
#endif
-int32_t mnodeInitOper();
-void mnodeCleanupOper();
+int32_t mndInitOper(SMnode *pMnode);
+void mndCleanupOper(SMnode *pMnode);
#ifdef __cplusplus
}
#endif
-#endif /*_TD_MNODE_OPER_H_*/
+#endif /*_TD_MND_OPER_H_*/
diff --git a/source/dnode/mnode/impl/inc/mndProfile.h b/source/dnode/mnode/impl/inc/mndProfile.h
new file mode 100644
index 0000000000..df857be73e
--- /dev/null
+++ b/source/dnode/mnode/impl/inc/mndProfile.h
@@ -0,0 +1,32 @@
+/*
+ * Copyright (c) 2019 TAOS Data, Inc.
+ *
+ * This program is free software: you can use, redistribute, and/or modify
+ * it under the terms of the GNU Affero General Public License, version 3
+ * or later ("AGPL"), as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see .
+ */
+
+#ifndef _TD_MND_PROFILE_H_
+#define _TD_MND_PROFILE_H_
+
+#include "mndInt.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+int32_t mndInitProfile(SMnode *pMnode);
+void mndCleanupProfile(SMnode *pMnode);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /*_TD_MND_PROFILE_H_*/
diff --git a/source/dnode/mnode/impl/inc/mnodeCluster.h b/source/dnode/mnode/impl/inc/mndShow.h
similarity index 80%
rename from source/dnode/mnode/impl/inc/mnodeCluster.h
rename to source/dnode/mnode/impl/inc/mndShow.h
index 06001a7757..06c18cb029 100644
--- a/source/dnode/mnode/impl/inc/mnodeCluster.h
+++ b/source/dnode/mnode/impl/inc/mndShow.h
@@ -13,20 +13,20 @@
* along with this program. If not, see .
*/
-#ifndef _TD_MNODE_CLUSTER_H_
-#define _TD_MNODE_CLUSTER_H_
+#ifndef _TD_MND_SHOW_H_
+#define _TD_MND_SHOW_H_
-#include "mnodeInt.h"
+#include "mndInt.h"
#ifdef __cplusplus
extern "C" {
#endif
-int32_t mnodeInitCluster();
-void mnodeCleanupCluster();
+int32_t mndInitShow(SMnode *pMnode);
+void mndCleanupShow(SMnode *pMnode);
#ifdef __cplusplus
}
#endif
-#endif /*_TD_MNODE_CLUSTER_H_*/
+#endif /*_TD_MND_SHOW_H_*/
diff --git a/source/dnode/mnode/impl/inc/mndStable.h b/source/dnode/mnode/impl/inc/mndStable.h
new file mode 100644
index 0000000000..c7767a59e4
--- /dev/null
+++ b/source/dnode/mnode/impl/inc/mndStable.h
@@ -0,0 +1,32 @@
+/*
+ * Copyright (c) 2019 TAOS Data, Inc.
+ *
+ * This program is free software: you can use, redistribute, and/or modify
+ * it under the terms of the GNU Affero General Public License, version 3
+ * or later ("AGPL"), as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see .
+ */
+
+#ifndef _TD_MND_STABLE_H_
+#define _TD_MND_STABLE_H_
+
+#include "mndInt.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+int32_t mndInitStable(SMnode *pMnode);
+void mndCleanupStable(SMnode *pMnode);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /*_TD_MND_STABLE_H_*/
diff --git a/source/dnode/mnode/impl/inc/mndSync.h b/source/dnode/mnode/impl/inc/mndSync.h
new file mode 100644
index 0000000000..3e45b0adb1
--- /dev/null
+++ b/source/dnode/mnode/impl/inc/mndSync.h
@@ -0,0 +1,34 @@
+/*
+ * Copyright (c) 2019 TAOS Data, Inc.
+ *
+ * This program is free software: you can use, redistribute, and/or modify
+ * it under the terms of the GNU Affero General Public License, version 3
+ * or later ("AGPL"), as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see .
+ */
+
+#ifndef _TD_MND_SYNC_H_
+#define _TD_MND_SYNC_H_
+
+#include "mndInt.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+int32_t mndInitSync(SMnode *pMnode);
+void mndCleanupSync(SMnode *pMnode);
+bool mndIsMaster(SMnode *pMnode);
+int32_t mndSyncPropose(SSdbRaw *pRaw, void *pData);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /*_TD_MND_SYNC_H_*/
diff --git a/source/dnode/mnode/impl/inc/mnodeTelem.h b/source/dnode/mnode/impl/inc/mndTelem.h
similarity index 78%
rename from source/dnode/mnode/impl/inc/mnodeTelem.h
rename to source/dnode/mnode/impl/inc/mndTelem.h
index 9122775a31..4cbf0cdc77 100644
--- a/source/dnode/mnode/impl/inc/mnodeTelem.h
+++ b/source/dnode/mnode/impl/inc/mndTelem.h
@@ -13,19 +13,19 @@
* along with this program. If not, see .
*/
-#ifndef _TD_MNODE_TELEMETRY_H_
-#define _TD_MNODE_TELEMETRY_H_
+#ifndef _TD_MND_TELEMETRY_H_
+#define _TD_MND_TELEMETRY_H_
#ifdef __cplusplus
extern "C" {
#endif
-#include "mnodeInt.h"
+#include "mndInt.h"
-int32_t mnodeInitTelem();
-void mnodeCleanupTelem();
+int32_t mndInitTelem(SMnode *pMnode);
+void mndCleanupTelem(SMnode *pMnode);
#ifdef __cplusplus
}
#endif
-#endif /*_TD_MNODE_TELEMETRY_H_*/
+#endif /*_TD_MND_TELEMETRY_H_*/
diff --git a/source/dnode/mnode/impl/inc/mndTrans.h b/source/dnode/mnode/impl/inc/mndTrans.h
new file mode 100644
index 0000000000..745c0a0447
--- /dev/null
+++ b/source/dnode/mnode/impl/inc/mndTrans.h
@@ -0,0 +1,47 @@
+/*
+ * Copyright (c) 2019 TAOS Data, Inc.
+ *
+ * This program is free software: you can use, redistribute, and/or modify
+ * it under the terms of the GNU Affero General Public License, version 3
+ * or later ("AGPL"), as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see .
+ */
+
+#ifndef _TD_TRANSACTION_INT_H_
+#define _TD_TRANSACTION_INT_H_
+
+#include "mndInt.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+int32_t mndInitTrans(SMnode *pMnode);
+void mndCleanupTrans(SMnode *pMnode);
+
+STrans *mndTransCreate(SMnode *pMnode, ETrnPolicy policy, void *rpcHandle);
+void mndTransDrop(STrans *pTrans);
+int32_t mndTransAppendRedolog(STrans *pTrans, SSdbRaw *pRaw);
+int32_t mndTransAppendUndolog(STrans *pTrans, SSdbRaw *pRaw);
+int32_t mndTransAppendCommitlog(STrans *pTrans, SSdbRaw *pRaw);
+int32_t mndTransAppendRedoAction(STrans *pTrans, SEpSet *, void *pMsg);
+int32_t mndTransAppendUndoAction(STrans *pTrans, SEpSet *, void *pMsg);
+
+int32_t mndTransPrepare(STrans *pTrans, int32_t (*syncfp)(SSdbRaw *pRaw, void *pData));
+int32_t mndTransApply(SMnode *pMnode, SSdbRaw *pRaw, void *pData, int32_t code);
+int32_t mndTransExecute(SSdb *pSdb, int32_t tranId);
+
+SSdbRaw *mndTransActionEncode(STrans *pTrans);
+SSdbRow *mndTransActionDecode(SSdbRaw *pRaw);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /*_TD_TRANSACTION_INT_H_*/
diff --git a/source/dnode/mnode/impl/inc/mndUser.h b/source/dnode/mnode/impl/inc/mndUser.h
new file mode 100644
index 0000000000..ce570773bd
--- /dev/null
+++ b/source/dnode/mnode/impl/inc/mndUser.h
@@ -0,0 +1,32 @@
+/*
+ * Copyright (c) 2019 TAOS Data, Inc.
+ *
+ * This program is free software: you can use, redistribute, and/or modify
+ * it under the terms of the GNU Affero General Public License, version 3
+ * or later ("AGPL"), as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see .
+ */
+
+#ifndef _TD_MND_USER_H_
+#define _TD_MND_USER_H_
+
+#include "mndInt.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+int32_t mndInitUser(SMnode *pMnode);
+void mndCleanupUser(SMnode *pMnode);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /*_TD_MND_USER_H_*/
diff --git a/source/dnode/mnode/impl/inc/mndVgroup.h b/source/dnode/mnode/impl/inc/mndVgroup.h
new file mode 100644
index 0000000000..c75bdb5949
--- /dev/null
+++ b/source/dnode/mnode/impl/inc/mndVgroup.h
@@ -0,0 +1,32 @@
+/*
+ * Copyright (c) 2019 TAOS Data, Inc.
+ *
+ * This program is free software: you can use, redistribute, and/or modify
+ * it under the terms of the GNU Affero General Public License, version 3
+ * or later ("AGPL"), as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see .
+ */
+
+#ifndef _TD_MND_VGROUP_H_
+#define _TD_MND_VGROUP_H_
+
+#include "mndInt.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+int32_t mndInitVgroup(SMnode *pMnode);
+void mndCleanupVgroup(SMnode *pMnode);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /*_TD_MND_VGROUP_H_*/
diff --git a/source/dnode/mnode/impl/inc/mnodeDb.h b/source/dnode/mnode/impl/inc/mnodeDb.h
deleted file mode 100644
index ba16235348..0000000000
--- a/source/dnode/mnode/impl/inc/mnodeDb.h
+++ /dev/null
@@ -1,32 +0,0 @@
-/*
- * Copyright (c) 2019 TAOS Data, Inc.
- *
- * This program is free software: you can use, redistribute, and/or modify
- * it under the terms of the GNU Affero General Public License, version 3
- * or later ("AGPL"), as published by the Free Software Foundation.
- *
- * This program is distributed in the hope that it will be useful, but WITHOUT
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
- * FITNESS FOR A PARTICULAR PURPOSE.
- *
- * You should have received a copy of the GNU Affero General Public License
- * along with this program. If not, see .
- */
-
-#ifndef _TD_MNODE_DATABASE_H_
-#define _TD_MNODE_DATABASE_H_
-
-#include "mnodeInt.h"
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-int32_t mnodeInitDb();
-void mnodeCleanupDb();
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif /*_TD_MNODE_DATABASE_H_*/
diff --git a/source/dnode/mnode/impl/inc/mnodeDnode.h b/source/dnode/mnode/impl/inc/mnodeDnode.h
deleted file mode 100644
index ccbd359f38..0000000000
--- a/source/dnode/mnode/impl/inc/mnodeDnode.h
+++ /dev/null
@@ -1,32 +0,0 @@
-/*
- * Copyright (c) 2019 TAOS Data, Inc.
- *
- * This program is free software: you can use, redistribute, and/or modify
- * it under the terms of the GNU Affero General Public License, version 3
- * or later ("AGPL"), as published by the Free Software Foundation.
- *
- * This program is distributed in the hope that it will be useful, but WITHOUT
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
- * FITNESS FOR A PARTICULAR PURPOSE.
- *
- * You should have received a copy of the GNU Affero General Public License
- * along with this program. If not, see .
- */
-
-#ifndef _TD_MNODE_DNODE_H_
-#define _TD_MNODE_DNODE_H_
-
-#include "mnodeInt.h"
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-int32_t mnodeInitDnode();
-void mnodeCleanupDnode();
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif /*_TD_MNODE_DNODE_H_*/
diff --git a/source/dnode/mnode/impl/inc/mnodeFunc.h b/source/dnode/mnode/impl/inc/mnodeFunc.h
deleted file mode 100644
index 18154d1c00..0000000000
--- a/source/dnode/mnode/impl/inc/mnodeFunc.h
+++ /dev/null
@@ -1,32 +0,0 @@
-/*
- * Copyright (c) 2019 TAOS Data, Inc.
- *
- * This program is free software: you can use, redistribute, and/or modify
- * it under the terms of the GNU Affero General Public License, version 3
- * or later ("AGPL"), as published by the Free Software Foundation.
- *
- * This program is distributed in the hope that it will be useful, but WITHOUT
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
- * FITNESS FOR A PARTICULAR PURPOSE.
- *
- * You should have received a copy of the GNU Affero General Public License
- * along with this program. If not, see .
- */
-
-#ifndef _TD_MNODE_FUNC_H_
-#define _TD_MNODE_FUNC_H_
-
-#include "mnodeInt.h"
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-int32_t mnodeInitFunc();
-void mnodeCleanupFunc();
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif /*_TD_MNODE_FUNC_H_*/
diff --git a/source/dnode/mnode/impl/inc/mnodeMnode.h b/source/dnode/mnode/impl/inc/mnodeMnode.h
deleted file mode 100644
index 0c8069a917..0000000000
--- a/source/dnode/mnode/impl/inc/mnodeMnode.h
+++ /dev/null
@@ -1,34 +0,0 @@
-/*
- * Copyright (c) 2019 TAOS Data, Inc.
- *
- * This program is free software: you can use, redistribute, and/or modify
- * it under the terms of the GNU Affero General Public License, version 3
- * or later ("AGPL"), as published by the Free Software Foundation.
- *
- * This program is distributed in the hope that it will be useful, but WITHOUT
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
- * FITNESS FOR A PARTICULAR PURPOSE.
- *
- * You should have received a copy of the GNU Affero General Public License
- * along with this program. If not, see .
- */
-
-#ifndef _TD_MNODE_MNODE_H_
-#define _TD_MNODE_MNODE_H_
-
-#include "mnodeInt.h"
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-int32_t mnodeInitMnode();
-void mnodeCleanupMnode();
-void mnodeGetMnodeEpSetForPeer(SEpSet *epSet, bool redirect);
-void mnodeGetMnodeEpSetForShell(SEpSet *epSet, bool redirect);
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif /*_TD_MNODE_MNODE_H_*/
diff --git a/source/dnode/mnode/impl/inc/mnodeProfile.h b/source/dnode/mnode/impl/inc/mnodeProfile.h
deleted file mode 100644
index b3735a02a3..0000000000
--- a/source/dnode/mnode/impl/inc/mnodeProfile.h
+++ /dev/null
@@ -1,32 +0,0 @@
-/*
- * Copyright (c) 2019 TAOS Data, Inc.
- *
- * This program is free software: you can use, redistribute, and/or modify
- * it under the terms of the GNU Affero General Public License, version 3
- * or later ("AGPL"), as published by the Free Software Foundation.
- *
- * This program is distributed in the hope that it will be useful, but WITHOUT
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
- * FITNESS FOR A PARTICULAR PURPOSE.
- *
- * You should have received a copy of the GNU Affero General Public License
- * along with this program. If not, see .
- */
-
-#ifndef _TD_MNODE_PROFILE_H_
-#define _TD_MNODE_PROFILE_H_
-
-#include "mnodeInt.h"
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-int32_t mnodeInitProfile();
-void mnodeCleanupProfile();
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif /*_TD_MNODE_PROFILE_H_*/
diff --git a/source/dnode/mnode/impl/inc/mnodeShow.h b/source/dnode/mnode/impl/inc/mnodeShow.h
deleted file mode 100644
index 50beee2897..0000000000
--- a/source/dnode/mnode/impl/inc/mnodeShow.h
+++ /dev/null
@@ -1,32 +0,0 @@
-/*
- * Copyright (c) 2019 TAOS Data, Inc.
- *
- * This program is free software: you can use, redistribute, and/or modify
- * it under the terms of the GNU Affero General Public License, version 3
- * or later ("AGPL"), as published by the Free Software Foundation.
- *
- * This program is distributed in the hope that it will be useful, but WITHOUT
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
- * FITNESS FOR A PARTICULAR PURPOSE.
- *
- * You should have received a copy of the GNU Affero General Public License
- * along with this program. If not, see .
- */
-
-#ifndef _TD_MNODE_SHOW_H_
-#define _TD_MNODE_SHOW_H_
-
-#include "mnodeInt.h"
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-int32_t mnodeInitShow();
-void mnodeCleanUpShow();
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif /*_TD_MNODE_SHOW_H_*/
diff --git a/source/dnode/mnode/impl/inc/mnodeStable.h b/source/dnode/mnode/impl/inc/mnodeStable.h
deleted file mode 100644
index e81fa74d0f..0000000000
--- a/source/dnode/mnode/impl/inc/mnodeStable.h
+++ /dev/null
@@ -1,32 +0,0 @@
-/*
- * Copyright (c) 2019 TAOS Data, Inc.
- *
- * This program is free software: you can use, redistribute, and/or modify
- * it under the terms of the GNU Affero General Public License, version 3
- * or later ("AGPL"), as published by the Free Software Foundation.
- *
- * This program is distributed in the hope that it will be useful, but WITHOUT
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
- * FITNESS FOR A PARTICULAR PURPOSE.
- *
- * You should have received a copy of the GNU Affero General Public License
- * along with this program. If not, see .
- */
-
-#ifndef _TD_MNODE_STABLE_H_
-#define _TD_MNODE_STABLE_H_
-
-#include "mnodeInt.h"
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-int32_t mnodeInitStable();
-void mnodeCleanupStable();
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif /*_TD_MNODE_STABLE_H_*/
diff --git a/source/dnode/mnode/impl/inc/mnodeSync.h b/source/dnode/mnode/impl/inc/mnodeSync.h
deleted file mode 100644
index 380ad36e23..0000000000
--- a/source/dnode/mnode/impl/inc/mnodeSync.h
+++ /dev/null
@@ -1,35 +0,0 @@
-/*
- * Copyright (c) 2019 TAOS Data, Inc.
- *
- * This program is free software: you can use, redistribute, and/or modify
- * it under the terms of the GNU Affero General Public License, version 3
- * or later ("AGPL"), as published by the Free Software Foundation.
- *
- * This program is distributed in the hope that it will be useful, but WITHOUT
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
- * FITNESS FOR A PARTICULAR PURPOSE.
- *
- * You should have received a copy of the GNU Affero General Public License
- * along with this program. If not, see .
- */
-
-#ifndef _TD_MNODE_SYNC_H_
-#define _TD_MNODE_SYNC_H_
-
-#include "mnodeInt.h"
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-int32_t mnodeInitSync();
-void mnodeCleanUpSync();
-int32_t mnodeSyncPropose(SSdbRaw *pRaw, void *pData);
-
-bool mnodeIsMaster();
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif /*_TD_MNODE_SYNC_H_*/
diff --git a/source/dnode/mnode/impl/inc/mnodeTrans.h b/source/dnode/mnode/impl/inc/mnodeTrans.h
deleted file mode 100644
index 2abe101dfd..0000000000
--- a/source/dnode/mnode/impl/inc/mnodeTrans.h
+++ /dev/null
@@ -1,47 +0,0 @@
-/*
- * Copyright (c) 2019 TAOS Data, Inc.
- *
- * This program is free software: you can use, redistribute, and/or modify
- * it under the terms of the GNU Affero General Public License, version 3
- * or later ("AGPL"), as published by the Free Software Foundation.
- *
- * This program is distributed in the hope that it will be useful, but WITHOUT
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
- * FITNESS FOR A PARTICULAR PURPOSE.
- *
- * You should have received a copy of the GNU Affero General Public License
- * along with this program. If not, see .
- */
-
-#ifndef _TD_TRANSACTION_INT_H_
-#define _TD_TRANSACTION_INT_H_
-
-#include "mnodeInt.h"
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-int32_t mnodeInitTrans();
-void mnodeCleanupTrans();
-
-STrans *trnCreate(ETrnPolicy policy, void *rpcHandle);
-void trnDrop(STrans *pTrans);
-int32_t trnAppendRedoLog(STrans *pTrans, SSdbRaw *pRaw);
-int32_t trnAppendUndoLog(STrans *pTrans, SSdbRaw *pRaw);
-int32_t trnAppendCommitLog(STrans *pTrans, SSdbRaw *pRaw);
-int32_t trnAppendRedoAction(STrans *pTrans, SEpSet *, void *pMsg);
-int32_t trnAppendUndoAction(STrans *pTrans, SEpSet *, void *pMsg);
-
-int32_t trnPrepare(STrans *pTrans, int32_t (*syncfp)(SSdbRaw *pRaw, void *pData));
-int32_t trnApply(SSdbRaw *pRaw, void *pData, int32_t code);
-int32_t trnExecute(int32_t tranId);
-
-SSdbRaw *trnActionEncode(STrans *pTrans);
-SSdbRow *trnActionDecode(SSdbRaw *pRaw);
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif /*_TD_TRANSACTION_INT_H_*/
diff --git a/source/dnode/mnode/impl/inc/mnodeUser.h b/source/dnode/mnode/impl/inc/mnodeUser.h
deleted file mode 100644
index 144dd532d9..0000000000
--- a/source/dnode/mnode/impl/inc/mnodeUser.h
+++ /dev/null
@@ -1,32 +0,0 @@
-/*
- * Copyright (c) 2019 TAOS Data, Inc.
- *
- * This program is free software: you can use, redistribute, and/or modify
- * it under the terms of the GNU Affero General Public License, version 3
- * or later ("AGPL"), as published by the Free Software Foundation.
- *
- * This program is distributed in the hope that it will be useful, but WITHOUT
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
- * FITNESS FOR A PARTICULAR PURPOSE.
- *
- * You should have received a copy of the GNU Affero General Public License
- * along with this program. If not, see .
- */
-
-#ifndef _TD_MNODE_USER_H_
-#define _TD_MNODE_USER_H_
-
-#include "mnodeInt.h"
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-int32_t mnodeInitUser();
-void mnodeCleanupUser();
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif /*_TD_MNODE_USER_H_*/
diff --git a/source/dnode/mnode/impl/inc/mnodeVgroup.h b/source/dnode/mnode/impl/inc/mnodeVgroup.h
deleted file mode 100644
index ebd98bb798..0000000000
--- a/source/dnode/mnode/impl/inc/mnodeVgroup.h
+++ /dev/null
@@ -1,32 +0,0 @@
-/*
- * Copyright (c) 2019 TAOS Data, Inc.
- *
- * This program is free software: you can use, redistribute, and/or modify
- * it under the terms of the GNU Affero General Public License, version 3
- * or later ("AGPL"), as published by the Free Software Foundation.
- *
- * This program is distributed in the hope that it will be useful, but WITHOUT
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
- * FITNESS FOR A PARTICULAR PURPOSE.
- *
- * You should have received a copy of the GNU Affero General Public License
- * along with this program. If not, see .
- */
-
-#ifndef _TD_MNODE_VGROUP_H_
-#define _TD_MNODE_VGROUP_H_
-
-#include "mnodeInt.h"
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-int32_t mnodeInitVgroup();
-void mnodeCleanupVgroup();
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif /*_TD_MNODE_VGROUP_H_*/
diff --git a/source/dnode/mnode/impl/src/mnodeAcct.c b/source/dnode/mnode/impl/src/mndAcct.c
similarity index 86%
rename from source/dnode/mnode/impl/src/mnodeAcct.c
rename to source/dnode/mnode/impl/src/mndAcct.c
index 6f5c498ed2..dd91de1c95 100644
--- a/source/dnode/mnode/impl/src/mnodeAcct.c
+++ b/source/dnode/mnode/impl/src/mndAcct.c
@@ -14,7 +14,7 @@
*/
#define _DEFAULT_SOURCE
-#include "mnodeInt.h"
+#include "mndInt.h"
#define SDB_ACCT_VER 1
@@ -48,10 +48,10 @@ static SSdbRow *mnodeAcctActionDecode(SSdbRaw *pRaw) {
return NULL;
}
- SSdbRow *pRow = sdbAllocRow(sizeof(SAcctObj));
+ SSdbRow *pRow = sdbAllocRow(sizeof(SAcctObj));
SAcctObj *pAcct = sdbGetRowObj(pRow);
if (pAcct == NULL) return NULL;
-
+
int32_t dataPos = 0;
SDB_GET_BINARY(pRaw, pRow, dataPos, pAcct->acct, TSDB_USER_LEN)
SDB_GET_INT64(pRaw, pRow, dataPos, &pAcct->createdTime)
@@ -68,18 +68,18 @@ static SSdbRow *mnodeAcctActionDecode(SSdbRaw *pRaw) {
return pRow;
}
-static int32_t mnodeAcctActionInsert(SAcctObj *pAcct) { return 0; }
+static int32_t mnodeAcctActionInsert(SSdb *pSdb, SAcctObj *pAcct) { return 0; }
-static int32_t mnodeAcctActionDelete(SAcctObj *pAcct) { return 0; }
+static int32_t mnodeAcctActionDelete(SSdb *pSdb, SAcctObj *pAcct) { return 0; }
-static int32_t mnodeAcctActionUpdate(SAcctObj *pSrcAcct, SAcctObj *pDstAcct) {
+static int32_t mnodeAcctActionUpdate(SSdb *pSdb, SAcctObj *pSrcAcct, SAcctObj *pDstAcct) {
SAcctObj tObj;
int32_t len = (int32_t)((int8_t *)&tObj.info - (int8_t *)&tObj);
memcpy(pDstAcct, pSrcAcct, len);
return 0;
}
-static int32_t mnodeCreateDefaultAcct() {
+static int32_t mnodeCreateDefaultAcct(SSdb *pSdb) {
int32_t code = 0;
SAcctObj acctObj = {0};
@@ -98,21 +98,20 @@ static int32_t mnodeCreateDefaultAcct() {
if (pRaw == NULL) return -1;
sdbSetRawStatus(pRaw, SDB_STATUS_READY);
- return sdbWrite(pRaw);
+ return sdbWrite(pSdb, pRaw);
}
-int32_t mnodeInitAcct() {
+int32_t mndInitAcct(SMnode *pMnode) {
SSdbTable table = {.sdbType = SDB_ACCT,
.keyType = SDB_KEY_BINARY,
- .deployFp = (SdbDeployFp)mnodeCreateDefaultAcct,
+ .deployFp = mnodeCreateDefaultAcct,
.encodeFp = (SdbEncodeFp)mnodeAcctActionEncode,
.decodeFp = (SdbDecodeFp)mnodeAcctActionDecode,
.insertFp = (SdbInsertFp)mnodeAcctActionInsert,
.updateFp = (SdbUpdateFp)mnodeAcctActionUpdate,
.deleteFp = (SdbDeleteFp)mnodeAcctActionDelete};
- sdbSetTable(table);
- return 0;
+ return sdbSetTable(pMnode->pSdb, table);
}
-void mnodeCleanupAcct() {}
+void mndCleanupAcct(SMnode *pMnode) {}
diff --git a/source/dnode/mnode/impl/src/mnodeAuth.c b/source/dnode/mnode/impl/src/mndAuth.c
similarity index 75%
rename from source/dnode/mnode/impl/src/mnodeAuth.c
rename to source/dnode/mnode/impl/src/mndAuth.c
index f8e704d16d..bcefbfde21 100644
--- a/source/dnode/mnode/impl/src/mnodeAuth.c
+++ b/source/dnode/mnode/impl/src/mndAuth.c
@@ -15,11 +15,11 @@
#define _DEFAULT_SOURCE
#include "os.h"
-#include "mnodeAuth.h"
+#include "mndAuth.h"
-int32_t mnodeInitAuth() { return 0; }
-void mnodeCleanupAuth() {}
+int32_t mndInitAuth(SMnode *pMnode) { return 0; }
+void mndCleanupAuth(SMnode *pMnode) {}
-int32_t mnodeRetriveAuth(SMnode *pMnode, char *user, char *spi, char *encrypt, char *secret, char *ckey) {
+int32_t mndRetriveAuth(SMnode *pMnode, char *user, char *spi, char *encrypt, char *secret, char *ckey) {
return 0;
}
\ No newline at end of file
diff --git a/source/dnode/mnode/impl/src/mndBalance.c b/source/dnode/mnode/impl/src/mndBalance.c
new file mode 100644
index 0000000000..6ce89b96a3
--- /dev/null
+++ b/source/dnode/mnode/impl/src/mndBalance.c
@@ -0,0 +1,21 @@
+/*
+ * Copyright (c) 2019 TAOS Data, Inc.
+ *
+ * This program is free software: you can use, redistribute, and/or modify
+ * it under the terms of the GNU Affero General Public License, version 3
+ * or later ("AGPL"), as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see .
+ */
+
+#define _DEFAULT_SOURCE
+#include "os.h"
+#include "mndInt.h"
+
+int32_t mndInitBalance(SMnode *pMnode) { return 0; }
+void mndCleanupBalance(SMnode *pMnode) {}
\ No newline at end of file
diff --git a/source/dnode/mnode/impl/src/mndCluster.c b/source/dnode/mnode/impl/src/mndCluster.c
new file mode 100644
index 0000000000..98e9e70229
--- /dev/null
+++ b/source/dnode/mnode/impl/src/mndCluster.c
@@ -0,0 +1,21 @@
+/*
+ * Copyright (c) 2019 TAOS Data, Inc.
+ *
+ * This program is free software: you can use, redistribute, and/or modify
+ * it under the terms of the GNU Affero General Public License, version 3
+ * or later ("AGPL"), as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see .
+ */
+
+#define _DEFAULT_SOURCE
+#include "os.h"
+#include "mndInt.h"
+
+int32_t mndInitCluster(SMnode *pMnode) { return 0; }
+void mndCleanupCluster(SMnode *pMnode) {}
\ No newline at end of file
diff --git a/source/dnode/mnode/impl/src/mnodeDnode.c b/source/dnode/mnode/impl/src/mndDb.c
similarity index 86%
rename from source/dnode/mnode/impl/src/mnodeDnode.c
rename to source/dnode/mnode/impl/src/mndDb.c
index 36766f72a8..3a5a221677 100644
--- a/source/dnode/mnode/impl/src/mnodeDnode.c
+++ b/source/dnode/mnode/impl/src/mndDb.c
@@ -15,7 +15,7 @@
#define _DEFAULT_SOURCE
#include "os.h"
-#include "mnodeInt.h"
+#include "mndInt.h"
-int32_t mnodeInitDnode() { return 0; }
-void mnodeCleanupDnode() {}
\ No newline at end of file
+int32_t mndInitDb(SMnode *pMnode) { return 0; }
+void mndCleanupDb(SMnode *pMnode) {}
\ No newline at end of file
diff --git a/source/dnode/mnode/impl/src/mndDnode.c b/source/dnode/mnode/impl/src/mndDnode.c
new file mode 100644
index 0000000000..11f3dc1ee9
--- /dev/null
+++ b/source/dnode/mnode/impl/src/mndDnode.c
@@ -0,0 +1,21 @@
+/*
+ * Copyright (c) 2019 TAOS Data, Inc.
+ *
+ * This program is free software: you can use, redistribute, and/or modify
+ * it under the terms of the GNU Affero General Public License, version 3
+ * or later ("AGPL"), as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see .
+ */
+
+#define _DEFAULT_SOURCE
+#include "os.h"
+#include "mndInt.h"
+
+int32_t mndInitDnode(SMnode *pMnode) { return 0; }
+void mndCleanupDnode(SMnode *pMnode) {}
\ No newline at end of file
diff --git a/source/dnode/mnode/impl/src/mnodeBalance.c b/source/dnode/mnode/impl/src/mndFunc.c
similarity index 85%
rename from source/dnode/mnode/impl/src/mnodeBalance.c
rename to source/dnode/mnode/impl/src/mndFunc.c
index a9542ab457..d859da029f 100644
--- a/source/dnode/mnode/impl/src/mnodeBalance.c
+++ b/source/dnode/mnode/impl/src/mndFunc.c
@@ -15,7 +15,7 @@
#define _DEFAULT_SOURCE
#include "os.h"
-#include "mnodeInt.h"
+#include "mndInt.h"
-int32_t mnodeInitBalance() { return 0; }
-void mnodeCleanupBalance() {}
\ No newline at end of file
+int32_t mndInitFunc(SMnode *pMnode) { return 0; }
+void mndCleanupFunc(SMnode *pMnode) {}
\ No newline at end of file
diff --git a/source/dnode/mnode/impl/src/mnodeMnode.c b/source/dnode/mnode/impl/src/mndMnode.c
similarity index 73%
rename from source/dnode/mnode/impl/src/mnodeMnode.c
rename to source/dnode/mnode/impl/src/mndMnode.c
index 60e1627ad4..c2e05687c7 100644
--- a/source/dnode/mnode/impl/src/mnodeMnode.c
+++ b/source/dnode/mnode/impl/src/mndMnode.c
@@ -15,10 +15,10 @@
#define _DEFAULT_SOURCE
#include "os.h"
-#include "mnodeInt.h"
+#include "mndInt.h"
-int32_t mnodeInitMnode() { return 0; }
-void mnodeCleanupMnode() {}
+int32_t mndInitMnode(SMnode *pMnode) { return 0; }
+void mndCleanupMnode(SMnode *pMnode) {}
-void mnodeGetMnodeEpSetForPeer(SEpSet *epSet, bool redirect) {}
-void mnodeGetMnodeEpSetForShell(SEpSet *epSet, bool redirect) {}
\ No newline at end of file
+void mndGetMnodeEpSetForPeer(SEpSet *epSet, bool redirect) {}
+void mndGetMnodeEpSetForShell(SEpSet *epSet, bool redirect) {}
\ No newline at end of file
diff --git a/source/dnode/mnode/impl/src/mnodeCluster.c b/source/dnode/mnode/impl/src/mndOper.c
similarity index 85%
rename from source/dnode/mnode/impl/src/mnodeCluster.c
rename to source/dnode/mnode/impl/src/mndOper.c
index 8ce26270e2..4416a1fc2d 100644
--- a/source/dnode/mnode/impl/src/mnodeCluster.c
+++ b/source/dnode/mnode/impl/src/mndOper.c
@@ -15,7 +15,7 @@
#define _DEFAULT_SOURCE
#include "os.h"
-#include "mnodeInt.h"
+#include "mndInt.h"
-int32_t mnodeInitCluster() { return 0; }
-void mnodeCleanupCluster() {}
\ No newline at end of file
+int32_t mndInitOper(SMnode *pMnode) { return 0; }
+void mndCleanupOper(SMnode *pMnode) {}
\ No newline at end of file
diff --git a/source/dnode/mnode/impl/src/mndProfile.c b/source/dnode/mnode/impl/src/mndProfile.c
new file mode 100644
index 0000000000..845e50210a
--- /dev/null
+++ b/source/dnode/mnode/impl/src/mndProfile.c
@@ -0,0 +1,21 @@
+/*
+ * Copyright (c) 2019 TAOS Data, Inc.
+ *
+ * This program is free software: you can use, redistribute, and/or modify
+ * it under the terms of the GNU Affero General Public License, version 3
+ * or later ("AGPL"), as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see .
+ */
+
+#define _DEFAULT_SOURCE
+#include "os.h"
+#include "mndInt.h"
+
+int32_t mndInitProfile(SMnode *pMnode) { return 0; }
+void mndCleanupProfile(SMnode *pMnode) {}
\ No newline at end of file
diff --git a/source/dnode/mnode/impl/src/mnodeDb.c b/source/dnode/mnode/impl/src/mndShow.c
similarity index 85%
rename from source/dnode/mnode/impl/src/mnodeDb.c
rename to source/dnode/mnode/impl/src/mndShow.c
index da5e3e5542..9938e95a73 100644
--- a/source/dnode/mnode/impl/src/mnodeDb.c
+++ b/source/dnode/mnode/impl/src/mndShow.c
@@ -15,7 +15,7 @@
#define _DEFAULT_SOURCE
#include "os.h"
-#include "mnodeInt.h"
+#include "mndInt.h"
-int32_t mnodeInitDb() { return 0; }
-void mnodeCleanupDb() {}
\ No newline at end of file
+int32_t mndInitShow(SMnode *pMnode) { return 0; }
+void mndCleanupShow(SMnode *pMnode) {}
\ No newline at end of file
diff --git a/source/dnode/mnode/impl/src/mndStable.c b/source/dnode/mnode/impl/src/mndStable.c
new file mode 100644
index 0000000000..e54bb17451
--- /dev/null
+++ b/source/dnode/mnode/impl/src/mndStable.c
@@ -0,0 +1,21 @@
+/*
+ * Copyright (c) 2019 TAOS Data, Inc.
+ *
+ * This program is free software: you can use, redistribute, and/or modify
+ * it under the terms of the GNU Affero General Public License, version 3
+ * or later ("AGPL"), as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see .
+ */
+
+#define _DEFAULT_SOURCE
+#include "os.h"
+#include "mndInt.h"
+
+int32_t mndInitStable(SMnode *pMnode) { return 0; }
+void mndCleanupStable(SMnode *pMnode) {}
\ No newline at end of file
diff --git a/source/dnode/mnode/impl/src/mnodeSync.c b/source/dnode/mnode/impl/src/mndSync.c
similarity index 70%
rename from source/dnode/mnode/impl/src/mnodeSync.c
rename to source/dnode/mnode/impl/src/mndSync.c
index 6e4084ffa6..7231915311 100644
--- a/source/dnode/mnode/impl/src/mnodeSync.c
+++ b/source/dnode/mnode/impl/src/mndSync.c
@@ -15,16 +15,16 @@
#define _DEFAULT_SOURCE
#include "os.h"
-#include "mnodeInt.h"
-#include "mnodeTrans.h"
+#include "mndInt.h"
+#include "mndTrans.h"
-int32_t mnodeInitSync() { return 0; }
-void mnodeCleanUpSync() {}
+int32_t mndInitSync(SMnode *pMnode) { return 0; }
+void mndCleanupSync(SMnode *pMnode) {}
-int32_t mnodeSyncPropose(SSdbRaw *pRaw, void *pData) {
- trnApply(pData, pData, 0);
+int32_t mndSyncPropose(SMnode *pMnode, SSdbRaw *pRaw, void *pData) {
+ mndTransApply(pMnode, pData, pData, 0);
free(pData);
return 0;
}
-bool mnodeIsMaster() { return true; }
\ No newline at end of file
+bool mndIsMaster(SMnode *pMnode) { return true; }
\ No newline at end of file
diff --git a/source/dnode/mnode/impl/src/mnodeTelem.c b/source/dnode/mnode/impl/src/mndTelem.c
similarity index 71%
rename from source/dnode/mnode/impl/src/mnodeTelem.c
rename to source/dnode/mnode/impl/src/mndTelem.c
index 206b94a6c7..f7fafc7095 100644
--- a/source/dnode/mnode/impl/src/mnodeTelem.c
+++ b/source/dnode/mnode/impl/src/mndTelem.c
@@ -14,10 +14,10 @@
*/
#define _DEFAULT_SOURCE
-#include "mnodeTelem.h"
+#include "mndTelem.h"
#include "tbuffer.h"
#include "tglobal.h"
-#include "mnodeSync.h"
+#include "mndSync.h"
#define TELEMETRY_SERVER "telemetry.taosdata.com"
#define TELEMETRY_PORT 80
@@ -36,9 +36,9 @@ static struct {
char email[TSDB_FQDN_LEN];
} tsTelem;
-static void mnodeBeginObject(SBufferWriter* bw) { tbufWriteChar(bw, '{'); }
+static void mndBeginObject(SBufferWriter* bw) { tbufWriteChar(bw, '{'); }
-static void mnodeCloseObject(SBufferWriter* bw) {
+static void mndCloseObject(SBufferWriter* bw) {
size_t len = tbufTell(bw);
if (tbufGetData(bw, false)[len - 1] == ',') {
tbufWriteCharAt(bw, len - 1, '}');
@@ -64,14 +64,14 @@ static void closeArray(SBufferWriter* bw) {
}
#endif
-static void mnodeWriteString(SBufferWriter* bw, const char* str) {
+static void mndWriteString(SBufferWriter* bw, const char* str) {
tbufWriteChar(bw, '"');
tbufWrite(bw, str, strlen(str));
tbufWriteChar(bw, '"');
}
-static void mnodeAddIntField(SBufferWriter* bw, const char* k, int64_t v) {
- mnodeWriteString(bw, k);
+static void mndAddIntField(SBufferWriter* bw, const char* k, int64_t v) {
+ mndWriteString(bw, k);
tbufWriteChar(bw, ':');
char buf[32];
sprintf(buf, "%" PRId64, v);
@@ -79,14 +79,14 @@ static void mnodeAddIntField(SBufferWriter* bw, const char* k, int64_t v) {
tbufWriteChar(bw, ',');
}
-static void mnodeAddStringField(SBufferWriter* bw, const char* k, const char* v) {
- mnodeWriteString(bw, k);
+static void mndAddStringField(SBufferWriter* bw, const char* k, const char* v) {
+ mndWriteString(bw, k);
tbufWriteChar(bw, ':');
- mnodeWriteString(bw, v);
+ mndWriteString(bw, v);
tbufWriteChar(bw, ',');
}
-static void mnodeAddCpuInfo(SBufferWriter* bw) {
+static void mndAddCpuInfo(SBufferWriter* bw) {
char* line = NULL;
size_t size = 0;
int32_t done = 0;
@@ -100,11 +100,11 @@ static void mnodeAddCpuInfo(SBufferWriter* bw) {
line[size - 1] = '\0';
if (((done & 1) == 0) && strncmp(line, "model name", 10) == 0) {
const char* v = strchr(line, ':') + 2;
- mnodeAddStringField(bw, "cpuModel", v);
+ mndAddStringField(bw, "cpuModel", v);
done |= 1;
} else if (((done & 2) == 0) && strncmp(line, "cpu cores", 9) == 0) {
const char* v = strchr(line, ':') + 2;
- mnodeWriteString(bw, "numOfCpu");
+ mndWriteString(bw, "numOfCpu");
tbufWriteChar(bw, ':');
tbufWrite(bw, v, strlen(v));
tbufWriteChar(bw, ',');
@@ -116,7 +116,7 @@ static void mnodeAddCpuInfo(SBufferWriter* bw) {
fclose(fp);
}
-static void mnodeAddOsInfo(SBufferWriter* bw) {
+static void mndAddOsInfo(SBufferWriter* bw) {
char* line = NULL;
size_t size = 0;
@@ -133,7 +133,7 @@ static void mnodeAddOsInfo(SBufferWriter* bw) {
p++;
line[size - 2] = 0;
}
- mnodeAddStringField(bw, "os", p);
+ mndAddStringField(bw, "os", p);
break;
}
}
@@ -142,7 +142,7 @@ static void mnodeAddOsInfo(SBufferWriter* bw) {
fclose(fp);
}
-static void mnodeAddMemoryInfo(SBufferWriter* bw) {
+static void mndAddMemoryInfo(SBufferWriter* bw) {
char* line = NULL;
size_t size = 0;
@@ -156,7 +156,7 @@ static void mnodeAddMemoryInfo(SBufferWriter* bw) {
if (strncmp(line, "MemTotal", 8) == 0) {
const char* p = strchr(line, ':') + 1;
while (*p == ' ') p++;
- mnodeAddStringField(bw, "memory", p);
+ mndAddStringField(bw, "memory", p);
break;
}
}
@@ -165,32 +165,32 @@ static void mnodeAddMemoryInfo(SBufferWriter* bw) {
fclose(fp);
}
-static void mnodeAddVersionInfo(SBufferWriter* bw) {
- mnodeAddStringField(bw, "version", version);
- mnodeAddStringField(bw, "buildInfo", buildinfo);
- mnodeAddStringField(bw, "gitInfo", gitinfo);
- mnodeAddStringField(bw, "email", tsTelem.email);
+static void mndAddVersionInfo(SBufferWriter* bw) {
+ mndAddStringField(bw, "version", version);
+ mndAddStringField(bw, "buildInfo", buildinfo);
+ mndAddStringField(bw, "gitInfo", gitinfo);
+ mndAddStringField(bw, "email", tsTelem.email);
}
-static void mnodeAddRuntimeInfo(SBufferWriter* bw) {
+static void mndAddRuntimeInfo(SBufferWriter* bw) {
SMnodeLoad load = {0};
- if (mnodeGetLoad(NULL, &load) != 0) {
+ if (mndGetLoad(NULL, &load) != 0) {
return;
}
- mnodeAddIntField(bw, "numOfDnode", load.numOfDnode);
- mnodeAddIntField(bw, "numOfMnode", load.numOfMnode);
- mnodeAddIntField(bw, "numOfVgroup", load.numOfVgroup);
- mnodeAddIntField(bw, "numOfDatabase", load.numOfDatabase);
- mnodeAddIntField(bw, "numOfSuperTable", load.numOfSuperTable);
- mnodeAddIntField(bw, "numOfChildTable", load.numOfChildTable);
- mnodeAddIntField(bw, "numOfColumn", load.numOfColumn);
- mnodeAddIntField(bw, "numOfPoint", load.totalPoints);
- mnodeAddIntField(bw, "totalStorage", load.totalStorage);
- mnodeAddIntField(bw, "compStorage", load.compStorage);
+ mndAddIntField(bw, "numOfDnode", load.numOfDnode);
+ mndAddIntField(bw, "numOfMnode", load.numOfMnode);
+ mndAddIntField(bw, "numOfVgroup", load.numOfVgroup);
+ mndAddIntField(bw, "numOfDatabase", load.numOfDatabase);
+ mndAddIntField(bw, "numOfSuperTable", load.numOfSuperTable);
+ mndAddIntField(bw, "numOfChildTable", load.numOfChildTable);
+ mndAddIntField(bw, "numOfColumn", load.numOfColumn);
+ mndAddIntField(bw, "numOfPoint", load.totalPoints);
+ mndAddIntField(bw, "totalStorage", load.totalStorage);
+ mndAddIntField(bw, "compStorage", load.compStorage);
}
-static void mnodeSendTelemetryReport() {
+static void mndSendTelemetryReport() {
char buf[128] = {0};
uint32_t ip = taosGetIpv4FromFqdn(TELEMETRY_SERVER);
if (ip == 0xffffffff) {
@@ -203,20 +203,20 @@ static void mnodeSendTelemetryReport() {
return;
}
- int64_t clusterId = mnodeGetClusterId();
+ int64_t clusterId = mndGetClusterId(NULL);
char clusterIdStr[20] = {0};
snprintf(clusterIdStr, sizeof(clusterIdStr), "%" PRId64, clusterId);
SBufferWriter bw = tbufInitWriter(NULL, false);
- mnodeBeginObject(&bw);
- mnodeAddStringField(&bw, "instanceId", clusterIdStr);
- mnodeAddIntField(&bw, "reportVersion", 1);
- mnodeAddOsInfo(&bw);
- mnodeAddCpuInfo(&bw);
- mnodeAddMemoryInfo(&bw);
- mnodeAddVersionInfo(&bw);
- mnodeAddRuntimeInfo(&bw);
- mnodeCloseObject(&bw);
+ mndBeginObject(&bw);
+ mndAddStringField(&bw, "instanceId", clusterIdStr);
+ mndAddIntField(&bw, "reportVersion", 1);
+ mndAddOsInfo(&bw);
+ mndAddCpuInfo(&bw);
+ mndAddMemoryInfo(&bw);
+ mndAddVersionInfo(&bw);
+ mndAddRuntimeInfo(&bw);
+ mndCloseObject(&bw);
const char* header =
"POST /report HTTP/1.1\n"
@@ -240,12 +240,12 @@ static void mnodeSendTelemetryReport() {
taosCloseSocket(fd);
}
-static void* mnodeTelemThreadFp(void* param) {
+static void* mndTelemThreadFp(void* param) {
struct timespec end = {0};
clock_gettime(CLOCK_REALTIME, &end);
end.tv_sec += 300; // wait 5 minutes before send first report
- setThreadName("mnode-telem");
+ setThreadName("mnd-telem");
while (!tsTelem.exit) {
int32_t r = 0;
@@ -256,8 +256,8 @@ static void* mnodeTelemThreadFp(void* param) {
if (r == 0) break;
if (r != ETIMEDOUT) continue;
- if (mnodeIsMaster()) {
- mnodeSendTelemetryReport();
+ if (mndIsMaster(NULL)) {
+ mndSendTelemetryReport();
}
end.tv_sec += REPORT_INTERVAL;
}
@@ -265,7 +265,7 @@ static void* mnodeTelemThreadFp(void* param) {
return NULL;
}
-static void mnodeGetEmail(char* filepath) {
+static void mndGetEmail(char* filepath) {
int32_t fd = taosOpenFileRead(filepath);
if (fd < 0) {
return;
@@ -278,7 +278,7 @@ static void mnodeGetEmail(char* filepath) {
taosCloseFile(fd);
}
-int32_t mnodeInitTelem() {
+int32_t mndInitTelem(SMnode *pMnode) {
tsTelem.enable = tsEnableTelemetryReporting;
if (!tsTelem.enable) return 0;
@@ -287,23 +287,23 @@ int32_t mnodeInitTelem() {
pthread_cond_init(&tsTelem.cond, NULL);
tsTelem.email[0] = 0;
- mnodeGetEmail("/usr/local/taos/email");
+ mndGetEmail("/usr/local/taos/email");
pthread_attr_t attr;
pthread_attr_init(&attr);
pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_JOINABLE);
- int32_t code = pthread_create(&tsTelem.thread, &attr, mnodeTelemThreadFp, NULL);
+ int32_t code = pthread_create(&tsTelem.thread, &attr, mndTelemThreadFp, NULL);
pthread_attr_destroy(&attr);
if (code != 0) {
mTrace("failed to create telemetry thread since :%s", strerror(code));
}
- mInfo("mnode telemetry is initialized");
+ mInfo("mnd telemetry is initialized");
return 0;
}
-void mnodeCleanupTelem() {
+void mndCleanupTelem(SMnode *pMnode) {
if (!tsTelem.enable) return;
if (taosCheckPthreadValid(tsTelem.thread)) {
diff --git a/source/dnode/mnode/impl/src/mnodeTrans.c b/source/dnode/mnode/impl/src/mndTrans.c
similarity index 74%
rename from source/dnode/mnode/impl/src/mnodeTrans.c
rename to source/dnode/mnode/impl/src/mndTrans.c
index 4cd6bf7bdb..7eab16895c 100644
--- a/source/dnode/mnode/impl/src/mnodeTrans.c
+++ b/source/dnode/mnode/impl/src/mndTrans.c
@@ -14,13 +14,13 @@
*/
#define _DEFAULT_SOURCE
-#include "mnodeTrans.h"
+#include "mndTrans.h"
#include "trpc.h"
#define SDB_TRANS_VER 1
#define TRN_DEFAULT_ARRAY_SIZE 8
-SSdbRaw *trnActionEncode(STrans *pTrans) {
+SSdbRaw *mndTransActionEncode(STrans *pTrans) {
int32_t rawDataLen = 10 * sizeof(int32_t);
int32_t redoLogNum = taosArrayGetSize(pTrans->redoLogs);
int32_t undoLogNum = taosArrayGetSize(pTrans->undoLogs);
@@ -28,18 +28,18 @@ SSdbRaw *trnActionEncode(STrans *pTrans) {
int32_t redoActionNum = taosArrayGetSize(pTrans->redoActions);
int32_t undoActionNum = taosArrayGetSize(pTrans->undoActions);
- for (int32_t index = 0; index < redoLogNum; ++index) {
- SSdbRaw *pTmp = taosArrayGet(pTrans->redoLogs, index);
+ for (int32_t i = 0; i < redoLogNum; ++i) {
+ SSdbRaw *pTmp = taosArrayGet(pTrans->redoLogs, i);
rawDataLen += sdbGetRawTotalSize(pTmp);
}
- for (int32_t index = 0; index < undoLogNum; ++index) {
- SSdbRaw *pTmp = taosArrayGet(pTrans->undoLogs, index);
+ for (int32_t i = 0; i < undoLogNum; ++i) {
+ SSdbRaw *pTmp = taosArrayGet(pTrans->undoLogs, i);
rawDataLen += sdbGetRawTotalSize(pTmp);
}
- for (int32_t index = 0; index < commitLogNum; ++index) {
- SSdbRaw *pTmp = taosArrayGet(pTrans->commitLogs, index);
+ for (int32_t i = 0; i < commitLogNum; ++i) {
+ SSdbRaw *pTmp = taosArrayGet(pTrans->commitLogs, i);
rawDataLen += sdbGetRawTotalSize(pTmp);
}
@@ -59,22 +59,22 @@ SSdbRaw *trnActionEncode(STrans *pTrans) {
SDB_SET_INT32(pRaw, dataPos, redoActionNum)
SDB_SET_INT32(pRaw, dataPos, undoActionNum)
- for (int32_t index = 0; index < redoLogNum; ++index) {
- SSdbRaw *pTmp = taosArrayGet(pTrans->redoLogs, index);
+ for (int32_t i = 0; i < redoLogNum; ++i) {
+ SSdbRaw *pTmp = taosArrayGet(pTrans->redoLogs, i);
int32_t len = sdbGetRawTotalSize(pTmp);
SDB_SET_INT32(pRaw, dataPos, len)
SDB_SET_BINARY(pRaw, dataPos, (void *)pTmp, len)
}
- for (int32_t index = 0; index < undoLogNum; ++index) {
- SSdbRaw *pTmp = taosArrayGet(pTrans->undoLogs, index);
+ for (int32_t i = 0; i < undoLogNum; ++i) {
+ SSdbRaw *pTmp = taosArrayGet(pTrans->undoLogs, i);
int32_t len = sdbGetRawTotalSize(pTmp);
SDB_SET_INT32(pRaw, dataPos, len)
SDB_SET_BINARY(pRaw, dataPos, (void *)pTmp, len)
}
- for (int32_t index = 0; index < commitLogNum; ++index) {
- SSdbRaw *pTmp = taosArrayGet(pTrans->commitLogs, index);
+ for (int32_t i = 0; i < commitLogNum; ++i) {
+ SSdbRaw *pTmp = taosArrayGet(pTrans->commitLogs, i);
int32_t len = sdbGetRawTotalSize(pTmp);
SDB_SET_INT32(pRaw, dataPos, len)
SDB_SET_BINARY(pRaw, dataPos, (void *)pTmp, len)
@@ -84,7 +84,7 @@ SSdbRaw *trnActionEncode(STrans *pTrans) {
return pRaw;
}
-SSdbRow *trnActionDecode(SSdbRaw *pRaw) {
+SSdbRow *mndTransActionDecode(SSdbRaw *pRaw) {
int8_t sver = 0;
if (sdbGetRawSoftVer(pRaw, &sver) != 0) {
mError("failed to get soft ver from raw:%p since %s", pRaw, terrstr());
@@ -134,7 +134,7 @@ SSdbRow *trnActionDecode(SSdbRaw *pRaw) {
SDB_GET_INT32(pRaw, pRow, dataPos, &undoActionNum)
int32_t code = 0;
- for (int32_t index = 0; index < redoLogNum; ++index) {
+ for (int32_t i = 0; i < redoLogNum; ++i) {
int32_t dataLen = 0;
SDB_GET_INT32(pRaw, pRow, dataPos, &dataLen)
@@ -150,7 +150,7 @@ SSdbRow *trnActionDecode(SSdbRaw *pRaw) {
if (code != 0) {
terrno = code;
mError("trn:%d, failed to parse from raw:%p since %s", pTrans->id, pRaw, terrstr());
- trnDrop(pTrans);
+ mndTransDrop(pTrans);
return NULL;
}
@@ -158,13 +158,13 @@ SSdbRow *trnActionDecode(SSdbRaw *pRaw) {
return pRow;
}
-static int32_t trnActionInsert(STrans *pTrans) {
+static int32_t mndTransActionInsert(SSdb *pSdb, STrans *pTrans) {
SArray *pArray = pTrans->redoLogs;
int32_t arraySize = taosArrayGetSize(pArray);
- for (int32_t index = 0; index < arraySize; ++index) {
- SSdbRaw *pRaw = taosArrayGet(pArray, index);
- int32_t code = sdbWrite(pRaw);
+ for (int32_t i = 0; i < arraySize; ++i) {
+ SSdbRaw *pRaw = taosArrayGet(pArray, i);
+ int32_t code = sdbWrite(pSdb, pRaw);
if (code != 0) {
mError("trn:%d, failed to write raw:%p to sdb since %s", pTrans->id, pRaw, terrstr());
return code;
@@ -175,13 +175,13 @@ static int32_t trnActionInsert(STrans *pTrans) {
return 0;
}
-static int32_t trnActionDelete(STrans *pTrans) {
+static int32_t mndTransActionDelete(SSdb *pSdb, STrans *pTrans) {
SArray *pArray = pTrans->redoLogs;
int32_t arraySize = taosArrayGetSize(pArray);
- for (int32_t index = 0; index < arraySize; ++index) {
- SSdbRaw *pRaw = taosArrayGet(pArray, index);
- int32_t code = sdbWrite(pRaw);
+ for (int32_t i = 0; i < arraySize; ++i) {
+ SSdbRaw *pRaw = taosArrayGet(pArray, i);
+ int32_t code = sdbWrite(pSdb, pRaw);
if (code != 0) {
mError("trn:%d, failed to write raw:%p to sdb since %s", pTrans->id, pRaw, terrstr());
return code;
@@ -192,14 +192,14 @@ static int32_t trnActionDelete(STrans *pTrans) {
return 0;
}
-static int32_t trnActionUpdate(STrans *pTrans, STrans *pDstTrans) {
+static int32_t mndTransActionUpdate(SSdb *pSdb, STrans *pTrans, STrans *pDstTrans) {
assert(true);
SArray *pArray = pTrans->redoLogs;
int32_t arraySize = taosArrayGetSize(pArray);
- for (int32_t index = 0; index < arraySize; ++index) {
- SSdbRaw *pRaw = taosArrayGet(pArray, index);
- int32_t code = sdbWrite(pRaw);
+ for (int32_t i = 0; i < arraySize; ++i) {
+ SSdbRaw *pRaw = taosArrayGet(pArray, i);
+ int32_t code = sdbWrite(pSdb, pRaw);
if (code != 0) {
mError("trn:%d, failed to write raw:%p to sdb since %s", pTrans->id, pRaw, terrstr());
return code;
@@ -213,7 +213,7 @@ static int32_t trnActionUpdate(STrans *pTrans, STrans *pDstTrans) {
static int32_t trnGenerateTransId() { return 1; }
-STrans *trnCreate(ETrnPolicy policy, void *rpcHandle) {
+STrans *mndTransCreate(SMnode *pMnode, ETrnPolicy policy, void *rpcHandle) {
STrans *pTrans = calloc(1, sizeof(STrans));
if (pTrans == NULL) {
terrno = TSDB_CODE_OUT_OF_MEMORY;
@@ -243,15 +243,15 @@ STrans *trnCreate(ETrnPolicy policy, void *rpcHandle) {
}
static void trnDropArray(SArray *pArray) {
- for (int32_t index = 0; index < pArray->size; ++index) {
- SSdbRaw *pRaw = taosArrayGet(pArray, index);
+ for (int32_t i = 0; i < pArray->size; ++i) {
+ SSdbRaw *pRaw = taosArrayGet(pArray, i);
tfree(pRaw);
}
taosArrayDestroy(pArray);
}
-void trnDrop(STrans *pTrans) {
+void mndTransDrop(STrans *pTrans) {
trnDropArray(pTrans->redoLogs);
trnDropArray(pTrans->undoLogs);
trnDropArray(pTrans->commitLogs);
@@ -262,12 +262,12 @@ void trnDrop(STrans *pTrans) {
tfree(pTrans);
}
-void trnSetRpcHandle(STrans *pTrans, void *rpcHandle) {
+void mndTransSetRpcHandle(STrans *pTrans, void *rpcHandle) {
pTrans->rpcHandle = rpcHandle;
mTrace("trn:%d, set rpc handle:%p", pTrans->id, rpcHandle);
}
-static int32_t trnAppendArray(SArray *pArray, SSdbRaw *pRaw) {
+static int32_t mndTransAppendArray(SArray *pArray, SSdbRaw *pRaw) {
if (pArray == NULL || pRaw == NULL) {
terrno = TSDB_CODE_OUT_OF_MEMORY;
return -1;
@@ -282,64 +282,61 @@ static int32_t trnAppendArray(SArray *pArray, SSdbRaw *pRaw) {
return 0;
}
-int32_t trnAppendRedoLog(STrans *pTrans, SSdbRaw *pRaw) {
- int32_t code = trnAppendArray(pTrans->redoLogs, pRaw);
+int32_t mndTransAppendRedolog(STrans *pTrans, SSdbRaw *pRaw) {
+ int32_t code = mndTransAppendArray(pTrans->redoLogs, pRaw);
mTrace("trn:%d, raw:%p append to redo logs, code:%d", pTrans->id, pRaw, code);
return code;
}
-int32_t trnAppendUndoLog(STrans *pTrans, SSdbRaw *pRaw) {
- int32_t code = trnAppendArray(pTrans->undoLogs, pRaw);
+int32_t mndTransAppendUndolog(STrans *pTrans, SSdbRaw *pRaw) {
+ int32_t code = mndTransAppendArray(pTrans->undoLogs, pRaw);
mTrace("trn:%d, raw:%p append to undo logs, code:%d", pTrans->id, pRaw, code);
return code;
}
-int32_t trnAppendCommitLog(STrans *pTrans, SSdbRaw *pRaw) {
- int32_t code = trnAppendArray(pTrans->commitLogs, pRaw);
+int32_t mndTransAppendCommitlog(STrans *pTrans, SSdbRaw *pRaw) {
+ int32_t code = mndTransAppendArray(pTrans->commitLogs, pRaw);
mTrace("trn:%d, raw:%p append to commit logs, code:%d", pTrans->id, pRaw, code);
return code;
}
-int32_t trnAppendRedoAction(STrans *pTrans, SEpSet *pEpSet, void *pMsg) {
- int32_t code = trnAppendArray(pTrans->redoActions, pMsg);
+int32_t mndTransAppendRedoAction(STrans *pTrans, SEpSet *pEpSet, void *pMsg) {
+ int32_t code = mndTransAppendArray(pTrans->redoActions, pMsg);
mTrace("trn:%d, msg:%p append to redo actions", pTrans->id, pMsg);
return code;
}
-int32_t trnAppendUndoAction(STrans *pTrans, SEpSet *pEpSet, void *pMsg) {
- int32_t code = trnAppendArray(pTrans->undoActions, pMsg);
+int32_t mndTransAppendUndoAction(STrans *pTrans, SEpSet *pEpSet, void *pMsg) {
+ int32_t code = mndTransAppendArray(pTrans->undoActions, pMsg);
mTrace("trn:%d, msg:%p append to undo actions", pTrans->id, pMsg);
return code;
}
-int32_t mnodeInitTrans() {
+int32_t mndInitTrans(SMnode *pMnode) {
SSdbTable table = {.sdbType = SDB_TRANS,
.keyType = SDB_KEY_INT32,
- .encodeFp = (SdbEncodeFp)trnActionEncode,
- .decodeFp = (SdbDecodeFp)trnActionDecode,
- .insertFp = (SdbInsertFp)trnActionInsert,
- .updateFp = (SdbUpdateFp)trnActionUpdate,
- .deleteFp = (SdbDeleteFp)trnActionDelete};
- sdbSetTable(table);
+ .encodeFp = (SdbEncodeFp)mndTransActionEncode,
+ .decodeFp = (SdbDecodeFp)mndTransActionDecode,
+ .insertFp = (SdbInsertFp)mndTransActionInsert,
+ .updateFp = (SdbUpdateFp)mndTransActionUpdate,
+ .deleteFp = (SdbDeleteFp)mndTransActionDelete};
- mInfo("trn module is initialized");
- return 0;
+ return sdbSetTable(pMnode->pSdb, table);
}
-void mnodeCleanupTrans() { mInfo("trn module is cleaned up"); }
+void mndCleanupTrans(SMnode *pMnode) {}
-
-int32_t trnPrepare(STrans *pTrans, int32_t (*syncfp)(SSdbRaw *pRaw, void *pData)) {
+int32_t mndTransPrepare(STrans *pTrans, int32_t (*syncfp)(SSdbRaw *pRaw, void *pData)) {
if (syncfp == NULL) return -1;
- SSdbRaw *pRaw = trnActionEncode(pTrans);
+ SSdbRaw *pRaw = mndTransActionEncode(pTrans);
if (pRaw == NULL) {
mError("trn:%d, failed to decode trans since %s", pTrans->id, terrstr());
return -1;
}
sdbSetRawStatus(pRaw, SDB_STATUS_CREATING);
- if (sdbWrite(pRaw) != 0) {
+ if (sdbWrite(pTrans->pMnode->pSdb, pRaw) != 0) {
mError("trn:%d, failed to write trans since %s", pTrans->id, terrstr());
return -1;
}
@@ -359,13 +356,13 @@ static void trnSendRpcRsp(void *rpcHandle, int32_t code) {
}
}
-int32_t trnApply(SSdbRaw *pRaw, void *pData, int32_t code) {
+int32_t mndTransApply(SMnode *pMnode, SSdbRaw *pRaw, void *pData, int32_t code) {
if (code != 0) {
trnSendRpcRsp(pData, terrno);
return 0;
}
- if (sdbWrite(pData) != 0) {
+ if (sdbWrite(pMnode->pSdb, pData) != 0) {
code = terrno;
trnSendRpcRsp(pData, code);
terrno = code;
@@ -375,10 +372,10 @@ int32_t trnApply(SSdbRaw *pRaw, void *pData, int32_t code) {
return 0;
}
-static int32_t trnExecuteArray(SArray *pArray) {
- for (int32_t index = 0; index < pArray->size; ++index) {
- SSdbRaw *pRaw = taosArrayGetP(pArray, index);
- if (sdbWrite(pRaw) != 0) {
+static int32_t trnExecuteArray(SMnode *pMnode, SArray *pArray) {
+ for (int32_t i = 0; i < pArray->size; ++i) {
+ SSdbRaw *pRaw = taosArrayGetP(pArray, i);
+ if (sdbWrite(pMnode->pSdb, pRaw) != 0) {
return -1;
}
}
@@ -386,15 +383,15 @@ static int32_t trnExecuteArray(SArray *pArray) {
return 0;
}
-static int32_t trnExecuteRedoLogs(STrans *pTrans) { return trnExecuteArray(pTrans->redoLogs); }
+static int32_t trnExecuteRedoLogs(STrans *pTrans) { return trnExecuteArray(pTrans->pMnode, pTrans->redoLogs); }
-static int32_t trnExecuteUndoLogs(STrans *pTrans) { return trnExecuteArray(pTrans->undoLogs); }
+static int32_t trnExecuteUndoLogs(STrans *pTrans) { return trnExecuteArray(pTrans->pMnode, pTrans->undoLogs); }
-static int32_t trnExecuteCommitLogs(STrans *pTrans) { return trnExecuteArray(pTrans->commitLogs); }
+static int32_t trnExecuteCommitLogs(STrans *pTrans) { return trnExecuteArray(pTrans->pMnode, pTrans->commitLogs); }
-static int32_t trnExecuteRedoActions(STrans *pTrans) { return trnExecuteArray(pTrans->redoActions); }
+static int32_t trnExecuteRedoActions(STrans *pTrans) { return trnExecuteArray(pTrans->pMnode, pTrans->redoActions); }
-static int32_t trnExecuteUndoActions(STrans *pTrans) { return trnExecuteArray(pTrans->undoActions); }
+static int32_t trnExecuteUndoActions(STrans *pTrans) { return trnExecuteArray(pTrans->pMnode, pTrans->undoActions); }
static int32_t trnPerformPrepareStage(STrans *pTrans) {
if (trnExecuteRedoLogs(pTrans) == 0) {
@@ -454,49 +451,49 @@ static int32_t trnPerformRetryStage(STrans *pTrans) {
}
}
-int32_t trnExecute(int32_t tranId) {
+int32_t mndTransExecute(SSdb *pSdb, int32_t tranId) {
int32_t code = 0;
- STrans *pTrans = sdbAcquire(SDB_TRANS, &tranId);
+ STrans *pTrans = sdbAcquire(pSdb, SDB_TRANS, &tranId);
if (pTrans == NULL) {
return -1;
}
if (pTrans->stage == TRN_STAGE_PREPARE) {
if (trnPerformPrepareStage(pTrans) != 0) {
- sdbRelease(pTrans);
+ sdbRelease(pSdb, pTrans);
return -1;
}
}
if (pTrans->stage == TRN_STAGE_EXECUTE) {
if (trnPerformExecuteStage(pTrans) != 0) {
- sdbRelease(pTrans);
+ sdbRelease(pSdb, pTrans);
return -1;
}
}
if (pTrans->stage == TRN_STAGE_COMMIT) {
if (trnPerformCommitStage(pTrans) != 0) {
- sdbRelease(pTrans);
+ sdbRelease(pSdb, pTrans);
return -1;
}
}
if (pTrans->stage == TRN_STAGE_ROLLBACK) {
if (trnPerformRollbackStage(pTrans) != 0) {
- sdbRelease(pTrans);
+ sdbRelease(pSdb, pTrans);
return -1;
}
}
if (pTrans->stage == TRN_STAGE_RETRY) {
if (trnPerformRetryStage(pTrans) != 0) {
- sdbRelease(pTrans);
+ sdbRelease(pSdb, pTrans);
return -1;
}
}
- sdbRelease(pTrans);
+ sdbRelease(pSdb, pTrans);
return 0;
}
\ No newline at end of file
diff --git a/source/dnode/mnode/impl/src/mnodeUser.c b/source/dnode/mnode/impl/src/mndUser.c
similarity index 64%
rename from source/dnode/mnode/impl/src/mnodeUser.c
rename to source/dnode/mnode/impl/src/mndUser.c
index b8e5706484..d63e3662e0 100644
--- a/source/dnode/mnode/impl/src/mnodeUser.c
+++ b/source/dnode/mnode/impl/src/mndUser.c
@@ -14,15 +14,13 @@
*/
#define _DEFAULT_SOURCE
-#include "mnodeSync.h"
-#include "os.h"
-#include "tglobal.h"
+#include "mndSync.h"
#include "tkey.h"
-#include "mnodeTrans.h"
+#include "mndTrans.h"
#define SDB_USER_VER 1
-static SSdbRaw *mnodeUserActionEncode(SUserObj *pUser) {
+static SSdbRaw *mndUserActionEncode(SUserObj *pUser) {
SSdbRaw *pRaw = sdbAllocRaw(SDB_USER, SDB_USER_VER, sizeof(SAcctObj));
if (pRaw == NULL) return NULL;
@@ -38,7 +36,7 @@ static SSdbRaw *mnodeUserActionEncode(SUserObj *pUser) {
return pRaw;
}
-static SSdbRow *mnodeUserActionDecode(SSdbRaw *pRaw) {
+static SSdbRow *mndUserActionDecode(SSdbRaw *pRaw) {
int8_t sver = 0;
if (sdbGetRawSoftVer(pRaw, &sver) != 0) return NULL;
@@ -62,14 +60,14 @@ static SSdbRow *mnodeUserActionDecode(SSdbRaw *pRaw) {
return pRow;
}
-static int32_t mnodeUserActionInsert(SUserObj *pUser) {
+static int32_t mndUserActionInsert(SSdb *pSdb, SUserObj *pUser) {
pUser->prohibitDbHash = taosHashInit(8, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BINARY), true, HASH_ENTRY_LOCK);
if (pUser->prohibitDbHash == NULL) {
terrno = TSDB_CODE_OUT_OF_MEMORY;
return -1;
}
- pUser->pAcct = sdbAcquire(SDB_ACCT, pUser->acct);
+ pUser->pAcct = sdbAcquire(pSdb, SDB_ACCT, pUser->acct);
if (pUser->pAcct == NULL) {
terrno = TSDB_CODE_MND_ACCT_NOT_EXIST;
return -1;
@@ -78,28 +76,28 @@ static int32_t mnodeUserActionInsert(SUserObj *pUser) {
return 0;
}
-static int32_t mnodeUserActionDelete(SUserObj *pUser) {
+static int32_t mndUserActionDelete(SSdb *pSdb, SUserObj *pUser) {
if (pUser->prohibitDbHash) {
taosHashCleanup(pUser->prohibitDbHash);
pUser->prohibitDbHash = NULL;
}
if (pUser->acct != NULL) {
- sdbRelease(pUser->pAcct);
+ sdbRelease(pSdb, pUser->pAcct);
pUser->pAcct = NULL;
}
return 0;
}
-static int32_t mnodeUserActionUpdate(SUserObj *pSrcUser, SUserObj *pDstUser) {
+static int32_t mndUserActionUpdate(SSdb *pSdb, SUserObj *pSrcUser, SUserObj *pDstUser) {
SUserObj tObj;
int32_t len = (int32_t)((int8_t *)tObj.prohibitDbHash - (int8_t *)&tObj);
memcpy(pDstUser, pSrcUser, len);
return 0;
}
-static int32_t mnodeCreateDefaultUser(char *acct, char *user, char *pass) {
+static int32_t mndCreateDefaultUser(SSdb *pSdb, char *acct, char *user, char *pass) {
SUserObj userObj = {0};
tstrncpy(userObj.user, user, TSDB_USER_LEN);
tstrncpy(userObj.acct, acct, TSDB_USER_LEN);
@@ -111,30 +109,26 @@ static int32_t mnodeCreateDefaultUser(char *acct, char *user, char *pass) {
userObj.rootAuth = 1;
}
- SSdbRaw *pRaw = mnodeUserActionEncode(&userObj);
+ SSdbRaw *pRaw = mndUserActionEncode(&userObj);
if (pRaw == NULL) return -1;
sdbSetRawStatus(pRaw, SDB_STATUS_READY);
- return sdbWrite(pRaw);
+ return sdbWrite(pSdb, pRaw);
}
-static int32_t mnodeCreateDefaultUsers() {
- if (mnodeCreateDefaultUser(TSDB_DEFAULT_USER, TSDB_DEFAULT_USER, TSDB_DEFAULT_PASS) != 0) {
+static int32_t mndCreateDefaultUsers(SSdb *pSdb) {
+ if (mndCreateDefaultUser(pSdb, TSDB_DEFAULT_USER, TSDB_DEFAULT_USER, TSDB_DEFAULT_PASS) != 0) {
return -1;
}
- if (mnodeCreateDefaultUser(TSDB_DEFAULT_USER, "monitor", tsInternalPass) != 0) {
- return -1;
- }
-
- if (mnodeCreateDefaultUser(TSDB_DEFAULT_USER, "_" TSDB_DEFAULT_USER, tsInternalPass) != 0) {
+ if (mndCreateDefaultUser(pSdb, TSDB_DEFAULT_USER, "_" TSDB_DEFAULT_USER, TSDB_DEFAULT_PASS) != 0) {
return -1;
}
return 0;
}
-static int32_t mnodeCreateUser(char *acct, char *user, char *pass, SMnodeMsg *pMsg) {
+static int32_t mndCreateUser(SMnode *pMnode, char *acct, char *user, char *pass, SMnodeMsg *pMsg) {
SUserObj userObj = {0};
tstrncpy(userObj.user, user, TSDB_USER_LEN);
tstrncpy(userObj.acct, acct, TSDB_USER_LEN);
@@ -143,43 +137,43 @@ static int32_t mnodeCreateUser(char *acct, char *user, char *pass, SMnodeMsg *pM
userObj.updateTime = userObj.createdTime;
userObj.rootAuth = 0;
- STrans *pTrans = trnCreate(TRN_POLICY_ROLLBACK, pMsg->rpcMsg.handle);
+ STrans *pTrans = mndTransCreate(pMnode, TRN_POLICY_ROLLBACK, pMsg->rpcMsg.handle);
if (pTrans == NULL) return -1;
- SSdbRaw *pRedoRaw = mnodeUserActionEncode(&userObj);
- if (pRedoRaw == NULL || trnAppendRedoLog(pTrans, pRedoRaw) != 0) {
+ SSdbRaw *pRedoRaw = mndUserActionEncode(&userObj);
+ if (pRedoRaw == NULL || mndTransAppendRedolog(pTrans, pRedoRaw) != 0) {
mError("failed to append redo log since %s", terrstr());
- trnDrop(pTrans);
+ mndTransDrop(pTrans);
return -1;
}
sdbSetRawStatus(pRedoRaw, SDB_STATUS_CREATING);
- SSdbRaw *pUndoRaw = mnodeUserActionEncode(&userObj);
- if (pUndoRaw == NULL || trnAppendUndoLog(pTrans, pUndoRaw) != 0) {
+ SSdbRaw *pUndoRaw = mndUserActionEncode(&userObj);
+ if (pUndoRaw == NULL || mndTransAppendUndolog(pTrans, pUndoRaw) != 0) {
mError("failed to append undo log since %s", terrstr());
- trnDrop(pTrans);
+ mndTransDrop(pTrans);
return -1;
}
sdbSetRawStatus(pUndoRaw, SDB_STATUS_DROPPED);
- SSdbRaw *pCommitRaw = mnodeUserActionEncode(&userObj);
- if (pCommitRaw == NULL || trnAppendCommitLog(pTrans, pCommitRaw) != 0) {
+ SSdbRaw *pCommitRaw = mndUserActionEncode(&userObj);
+ if (pCommitRaw == NULL || mndTransAppendCommitlog(pTrans, pCommitRaw) != 0) {
mError("failed to append commit log since %s", terrstr());
- trnDrop(pTrans);
+ mndTransDrop(pTrans);
return -1;
}
sdbSetRawStatus(pCommitRaw, SDB_STATUS_READY);
- if (trnPrepare(pTrans, mnodeSyncPropose) != 0) {
- trnDrop(pTrans);
+ if (mndTransPrepare(pTrans, mndSyncPropose) != 0) {
+ mndTransDrop(pTrans);
return -1;
}
- trnDrop(pTrans);
+ mndTransDrop(pTrans);
return 0;
}
-static int32_t mnodeProcessCreateUserMsg(SMnodeMsg *pMsg) {
+static int32_t mndProcessCreateUserMsg(SMnode *pMnode, SMnodeMsg *pMsg) {
SCreateUserMsg *pCreate = pMsg->rpcMsg.pCont;
if (pCreate->user[0] == 0) {
@@ -194,23 +188,23 @@ static int32_t mnodeProcessCreateUserMsg(SMnodeMsg *pMsg) {
return -1;
}
- SUserObj *pUser = sdbAcquire(SDB_USER, pCreate->user);
+ SUserObj *pUser = sdbAcquire(pMnode->pSdb, SDB_USER, pCreate->user);
if (pUser != NULL) {
- sdbRelease(pUser);
+ sdbRelease(pMnode->pSdb, pUser);
terrno = TSDB_CODE_MND_USER_ALREADY_EXIST;
mError("user:%s, failed to create since %s", pCreate->user, terrstr());
return -1;
}
- SUserObj *pOperUser = sdbAcquire(SDB_USER, pMsg->conn.user);
+ SUserObj *pOperUser = sdbAcquire(pMnode->pSdb, SDB_USER, pMsg->conn.user);
if (pOperUser == NULL) {
terrno = TSDB_CODE_MND_NO_USER_FROM_CONN;
mError("user:%s, failed to create since %s", pCreate->user, terrstr());
return -1;
}
- int32_t code = mnodeCreateUser(pOperUser->acct, pCreate->user, pCreate->pass, pMsg);
- sdbRelease(pOperUser);
+ int32_t code = mndCreateUser(pMnode, pOperUser->acct, pCreate->user, pCreate->pass, pMsg);
+ sdbRelease(pMnode->pSdb, pOperUser);
if (code != 0) {
mError("user:%s, failed to create since %s", pCreate->user, terrstr());
@@ -220,20 +214,19 @@ static int32_t mnodeProcessCreateUserMsg(SMnodeMsg *pMsg) {
return TSDB_CODE_MND_ACTION_IN_PROGRESS;
}
-int32_t mnodeInitUser() {
+int32_t mndInitUser(SMnode *pMnode) {
SSdbTable table = {.sdbType = SDB_USER,
.keyType = SDB_KEY_BINARY,
- .deployFp = (SdbDeployFp)mnodeCreateDefaultUsers,
- .encodeFp = (SdbEncodeFp)mnodeUserActionEncode,
- .decodeFp = (SdbDecodeFp)mnodeUserActionDecode,
- .insertFp = (SdbInsertFp)mnodeUserActionInsert,
- .updateFp = (SdbUpdateFp)mnodeUserActionUpdate,
- .deleteFp = (SdbDeleteFp)mnodeUserActionDelete};
- sdbSetTable(table);
+ .deployFp = (SdbDeployFp)mndCreateDefaultUsers,
+ .encodeFp = (SdbEncodeFp)mndUserActionEncode,
+ .decodeFp = (SdbDecodeFp)mndUserActionDecode,
+ .insertFp = (SdbInsertFp)mndUserActionInsert,
+ .updateFp = (SdbUpdateFp)mndUserActionUpdate,
+ .deleteFp = (SdbDeleteFp)mndUserActionDelete};
- mnodeSetMsgFp(TSDB_MSG_TYPE_CREATE_USER, mnodeProcessCreateUserMsg);
+ mndSetMsgHandle(pMnode, TSDB_MSG_TYPE_CREATE_USER, mndProcessCreateUserMsg);
- return 0;
+ return sdbSetTable(pMnode->pSdb, table);
}
-void mnodeCleanupUser() {}
\ No newline at end of file
+void mndCleanupUser(SMnode *pMnode) {}
\ No newline at end of file
diff --git a/source/dnode/mnode/impl/src/mndVgroup.c b/source/dnode/mnode/impl/src/mndVgroup.c
new file mode 100644
index 0000000000..b98468b63e
--- /dev/null
+++ b/source/dnode/mnode/impl/src/mndVgroup.c
@@ -0,0 +1,21 @@
+/*
+ * Copyright (c) 2019 TAOS Data, Inc.
+ *
+ * This program is free software: you can use, redistribute, and/or modify
+ * it under the terms of the GNU Affero General Public License, version 3
+ * or later ("AGPL"), as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see .
+ */
+
+#define _DEFAULT_SOURCE
+#include "os.h"
+#include "mndInt.h"
+
+int32_t mndInitVgroup(SMnode *pMnode) { return 0; }
+void mndCleanupVgroup(SMnode *pMnode) {}
\ No newline at end of file
diff --git a/source/dnode/mnode/impl/src/mnode.c b/source/dnode/mnode/impl/src/mnode.c
index 8fc5de588f..bc2ed92197 100644
--- a/source/dnode/mnode/impl/src/mnode.c
+++ b/source/dnode/mnode/impl/src/mnode.c
@@ -14,83 +14,225 @@
*/
#define _DEFAULT_SOURCE
-#include "os.h"
-#include "tglobal.h"
-#include "tqueue.h"
-#include "mnodeAcct.h"
-#include "mnodeAuth.h"
-#include "mnodeBalance.h"
-#include "mnodeCluster.h"
-#include "mnodeDb.h"
-#include "mnodeDnode.h"
-#include "mnodeFunc.h"
-#include "mnodeMnode.h"
-#include "mnodeOper.h"
-#include "mnodeProfile.h"
-#include "mnodeShow.h"
-#include "mnodeStable.h"
-#include "mnodeSync.h"
-#include "mnodeTelem.h"
-#include "mnodeTrans.h"
-#include "mnodeUser.h"
-#include "mnodeVgroup.h"
+#include "mndAcct.h"
+#include "mndAuth.h"
+#include "mndBalance.h"
+#include "mndCluster.h"
+#include "mndDb.h"
+#include "mndDnode.h"
+#include "mndFunc.h"
+#include "mndMnode.h"
+#include "mndOper.h"
+#include "mndProfile.h"
+#include "mndShow.h"
+#include "mndStable.h"
+#include "mndSync.h"
+#include "mndTelem.h"
+#include "mndTrans.h"
+#include "mndUser.h"
+#include "mndVgroup.h"
-SMnodeBak tsMint = {0};
-
-int32_t mnodeGetDnodeId() { return tsMint.para.dnodeId; }
-
-int64_t mnodeGetClusterId() { return tsMint.para.clusterId; }
-
-void mnodeSendMsgToDnode(SMnode *pMnode, struct SEpSet *epSet, struct SRpcMsg *rpcMsg) {
- assert(pMnode);
- (*pMnode->sendMsgToDnodeFp)(pMnode->pServer, epSet, rpcMsg);
-}
-
-void mnodeSendMsgToMnode(SMnode *pMnode, struct SRpcMsg *rpcMsg) {
- assert(pMnode);
- (*pMnode->sendMsgToMnodeFp)(pMnode->pServer, rpcMsg);
-}
-
-void mnodeSendRedirectMsg(SMnode *pMnode, struct SRpcMsg *rpcMsg, bool forShell) {
- assert(pMnode);
- (*pMnode->sendRedirectMsgFp)(pMnode->pServer, rpcMsg);
-}
-
-static int32_t mnodeInitTimer() {
- if (tsMint.timer == NULL) {
- tsMint.timer = taosTmrInit(tsMaxShellConns, 200, 3600000, "MND");
+int32_t mndGetDnodeId(SMnode *pMnode) {
+ if (pMnode != NULL) {
+ return pMnode->dnodeId;
}
- if (tsMint.timer == NULL) {
+ return -1;
+}
+
+int64_t mndGetClusterId(SMnode *pMnode) {
+ if (pMnode != NULL) {
+ return pMnode->clusterId;
+ }
+
+ return -1;
+}
+
+tmr_h mndGetTimer(SMnode *pMnode) {
+ if (pMnode != NULL) {
+ return pMnode->timer;
+ }
+
+ return NULL;
+}
+
+void mndSendMsgToDnode(SMnode *pMnode, SEpSet *pEpSet, SRpcMsg *pMsg) {
+ if (pMnode != NULL && pMnode->sendMsgToDnodeFp != NULL) {
+ (*pMnode->sendMsgToDnodeFp)(pMnode->pDnode, pEpSet, pMsg);
+ }
+}
+
+void mndSendMsgToMnode(SMnode *pMnode, SRpcMsg *pMsg) {
+ if (pMnode != NULL && pMnode->sendMsgToMnodeFp != NULL) {
+ (*pMnode->sendMsgToMnodeFp)(pMnode->pDnode, pMsg);
+ }
+}
+
+void mndSendRedirectMsg(SMnode *pMnode, SRpcMsg *pMsg) {
+ if (pMnode != NULL && pMnode->sendRedirectMsgFp != NULL) {
+ (*pMnode->sendRedirectMsgFp)(pMnode->pDnode, pMsg);
+ }
+}
+
+static int32_t mndInitTimer(SMnode *pMnode) {
+ if (pMnode->timer == NULL) {
+ pMnode->timer = taosTmrInit(5000, 200, 3600000, "MND");
+ }
+
+ if (pMnode->timer == NULL) {
+ terrno = TSDB_CODE_OUT_OF_MEMORY;
return -1;
}
return 0;
}
-static void mnodeCleanupTimer() {
- if (tsMint.timer != NULL) {
- taosTmrCleanUp(tsMint.timer);
- tsMint.timer = NULL;
+static void mndCleanupTimer(SMnode *pMnode) {
+ if (pMnode->timer != NULL) {
+ taosTmrCleanUp(pMnode->timer);
+ pMnode->timer = NULL;
}
}
-tmr_h mnodeGetTimer() { return tsMint.timer; }
+static int32_t mnodeCreateDir(SMnode *pMnode, const char *path) {
+ pMnode->path = strdup(path);
+ if (pMnode->path == NULL) {
+ terrno = TSDB_CODE_OUT_OF_MEMORY;
+ return -1;
+ }
-static int32_t mnodeSetOptions(SMnode *pMnode, const SMnodeOpt *pOption) {
+ if (taosMkDir(pMnode->path) != 0) {
+ terrno = TAOS_SYSTEM_ERROR(errno);
+ return -1;
+ }
+
+ return 0;
+}
+
+static int32_t mndInitSdb(SMnode *pMnode) {
+ SSdbOpt opt = {0};
+ opt.path = pMnode->path;
+
+ pMnode->pSdb = sdbInit(&opt);
+ if (pMnode->pSdb == NULL) {
+ return -1;
+ }
+
+ return 0;
+}
+
+static int32_t mndDeploySdb(SMnode *pMnode) { return sdbDeploy(pMnode->pSdb); }
+static int32_t mndReadSdb(SMnode *pMnode) { return sdbReadFile(pMnode->pSdb); }
+
+static void mndCleanupSdb(SMnode *pMnode) {
+ if (pMnode->pSdb) {
+ sdbCleanup(pMnode->pSdb);
+ pMnode->pSdb = NULL;
+ }
+}
+
+static int32_t mndAllocStep(SMnode *pMnode, char *name, MndInitFp initFp, MndCleanupFp cleanupFp) {
+ SMnodeStep step = {0};
+ step.name = name;
+ step.initFp = initFp;
+ step.cleanupFp = cleanupFp;
+ if (taosArrayPush(pMnode->pSteps, &step) == NULL) {
+ terrno = TSDB_CODE_OUT_OF_MEMORY;
+ return -1;
+ }
+
+ return 0;
+}
+
+static int32_t mndInitSteps(SMnode *pMnode) {
+ if (mndAllocStep(pMnode, "mnode-sdb", mndInitSdb, mndCleanupSdb) != 0) return -1;
+ if (mndAllocStep(pMnode, "mnode-trans", mndInitTrans, mndCleanupTrans) != 0) return -1;
+ if (mndAllocStep(pMnode, "mnode-cluster", mndInitCluster, mndCleanupCluster) != 0) return -1;
+ if (mndAllocStep(pMnode, "mnode-dnode", mndInitDnode, mndCleanupDnode) != 0) return -1;
+ if (mndAllocStep(pMnode, "mnode-mnode", mndInitMnode, mndCleanupMnode) != 0) return -1;
+ if (mndAllocStep(pMnode, "mnode-acct", mndInitAcct, mndCleanupAcct) != 0) return -1;
+ if (mndAllocStep(pMnode, "mnode-auth", mndInitAuth, mndCleanupAuth) != 0) return -1;
+ if (mndAllocStep(pMnode, "mnode-user", mndInitUser, mndCleanupUser) != 0) return -1;
+ if (mndAllocStep(pMnode, "mnode-db", mndInitDb, mndCleanupDb) != 0) return -1;
+ if (mndAllocStep(pMnode, "mnode-vgroup", mndInitVgroup, mndCleanupVgroup) != 0) return -1;
+ if (mndAllocStep(pMnode, "mnode-stable", mndInitStable, mndCleanupStable) != 0) return -1;
+ if (mndAllocStep(pMnode, "mnode-func", mndInitFunc, mndCleanupFunc) != 0) return -1;
+ if (pMnode->clusterId <= 0) {
+ if (mndAllocStep(pMnode, "mnode-sdb-deploy", mndDeploySdb, NULL) != 0) return -1;
+ } else {
+ if (mndAllocStep(pMnode, "mnode-sdb-read", mndReadSdb, NULL) != 0) return -1;
+ }
+ if (mndAllocStep(pMnode, "mnode-timer", mndInitTimer, NULL) != 0) return -1;
+ if (mndAllocStep(pMnode, "mnode-balance", mndInitBalance, mndCleanupBalance) != 0) return -1;
+ if (mndAllocStep(pMnode, "mnode-profile", mndInitProfile, mndCleanupProfile) != 0) return -1;
+ if (mndAllocStep(pMnode, "mnode-show", mndInitShow, mndCleanupShow) != 0) return -1;
+ if (mndAllocStep(pMnode, "mnode-sync", mndInitSync, mndCleanupSync) != 0) return -1;
+ if (mndAllocStep(pMnode, "mnode-telem", mndInitTelem, mndCleanupTelem) != 0) return -1;
+ if (mndAllocStep(pMnode, "mnode-timer", NULL, mndCleanupTimer) != 0) return -1;
+
+ return 0;
+}
+
+static void mndCleanupSteps(SMnode *pMnode, int32_t pos) {
+ if (pMnode->pSteps == NULL) return;
+
+ if (pos == -1) {
+ pos = taosArrayGetSize(pMnode->pSteps);
+ }
+
+ for (int32_t s = pos; s >= 0; s--) {
+ SMnodeStep *pStep = taosArrayGet(pMnode->pSteps, pos);
+ mDebug("step:%s will cleanup", pStep->name);
+ if (pStep->cleanupFp != NULL) {
+ (*pStep->cleanupFp)(pMnode);
+ }
+ }
+
+ taosArrayClear(pMnode->pSteps);
+ pMnode->pSteps = NULL;
+}
+
+static int32_t mndExecSteps(SMnode *pMnode) {
+ int32_t size = taosArrayGetSize(pMnode->pSteps);
+ for (int32_t pos = 0; pos < size; pos++) {
+ SMnodeStep *pStep = taosArrayGet(pMnode->pSteps, pos);
+ if (pStep->initFp == NULL) continue;
+
+ // (*pMnode->reportProgress)(pStep->name, "start initialize");
+
+ if ((*pStep->initFp)(pMnode) != 0) {
+ mError("step:%s exec failed since %s, start to cleanup", pStep->name, terrstr());
+ mndCleanupSteps(pMnode, pos);
+ return -1;
+ } else {
+ mDebug("step:%s is initialized", pStep->name);
+ }
+
+ // (*pMnode->reportProgress)(pStep->name, "initialize completed");
+ }
+
+ return 0;
+}
+
+static int32_t mndSetOptions(SMnode *pMnode, const SMnodeOpt *pOption) {
pMnode->dnodeId = pOption->dnodeId;
pMnode->clusterId = pOption->clusterId;
pMnode->replica = pOption->replica;
pMnode->selfIndex = pOption->selfIndex;
memcpy(&pMnode->replicas, pOption->replicas, sizeof(SReplica) * TSDB_MAX_REPLICA);
- pMnode->pServer = pOption->pDnode;
+ pMnode->pDnode = pOption->pDnode;
pMnode->putMsgToApplyMsgFp = pOption->putMsgToApplyMsgFp;
pMnode->sendMsgToDnodeFp = pOption->sendMsgToDnodeFp;
pMnode->sendMsgToMnodeFp = pOption->sendMsgToMnodeFp;
pMnode->sendRedirectMsgFp = pOption->sendRedirectMsgFp;
if (pMnode->sendMsgToDnodeFp == NULL || pMnode->sendMsgToMnodeFp == NULL || pMnode->sendRedirectMsgFp == NULL ||
- pMnode->putMsgToApplyMsgFp == NULL || pMnode->dnodeId < 0 || pMnode->clusterId < 0) {
+ pMnode->putMsgToApplyMsgFp == NULL) {
+ terrno = TSDB_CODE_MND_APP_ERROR;
+ return -1;
+ }
+
+ if (pMnode->dnodeId < 0 || pMnode->clusterId < 0) {
terrno = TSDB_CODE_MND_APP_ERROR;
return -1;
}
@@ -98,88 +240,98 @@ static int32_t mnodeSetOptions(SMnode *pMnode, const SMnodeOpt *pOption) {
return 0;
}
-static int32_t mnodeAllocInitSteps() {
- struct SSteps *steps = taosStepInit(16, NULL);
- if (steps == NULL) return -1;
+SMnode *mndOpen(const char *path, const SMnodeOpt *pOption) {
+ mDebug("start to open mnode in %s", path);
- if (taosStepAdd(steps, "mnode-trans", mnodeInitTrans, mnodeCleanupTrans) != 0) return -1;
- if (taosStepAdd(steps, "mnode-cluster", mnodeInitCluster, mnodeCleanupCluster) != 0) return -1;
- if (taosStepAdd(steps, "mnode-dnode", mnodeInitDnode, mnodeCleanupDnode) != 0) return -1;
- if (taosStepAdd(steps, "mnode-mnode", mnodeInitMnode, mnodeCleanupMnode) != 0) return -1;
- if (taosStepAdd(steps, "mnode-acct", mnodeInitAcct, mnodeCleanupAcct) != 0) return -1;
- if (taosStepAdd(steps, "mnode-auth", mnodeInitAuth, mnodeCleanupAuth) != 0) return -1;
- if (taosStepAdd(steps, "mnode-user", mnodeInitUser, mnodeCleanupUser) != 0) return -1;
- if (taosStepAdd(steps, "mnode-db", mnodeInitDb, mnodeCleanupDb) != 0) return -1;
- if (taosStepAdd(steps, "mnode-vgroup", mnodeInitVgroup, mnodeCleanupVgroup) != 0) return -1;
- if (taosStepAdd(steps, "mnode-stable", mnodeInitStable, mnodeCleanupStable) != 0) return -1;
- if (taosStepAdd(steps, "mnode-func", mnodeInitFunc, mnodeCleanupFunc) != 0) return -1;
- if (taosStepAdd(steps, "mnode-sdb", sdbInit, sdbCleanup) != 0) return -1;
-
- tsMint.pInitSteps = steps;
- return 0;
-}
-
-static int32_t mnodeAllocStartSteps() {
- struct SSteps *steps = taosStepInit(8, NULL);
- if (steps == NULL) return -1;
-
- taosStepAdd(steps, "mnode-timer", mnodeInitTimer, NULL);
- taosStepAdd(steps, "mnode-sdb-file", sdbOpen, sdbClose);
- taosStepAdd(steps, "mnode-balance", mnodeInitBalance, mnodeCleanupBalance);
- taosStepAdd(steps, "mnode-profile", mnodeInitProfile, mnodeCleanupProfile);
- taosStepAdd(steps, "mnode-show", mnodeInitShow, mnodeCleanUpShow);
- taosStepAdd(steps, "mnode-sync", mnodeInitSync, mnodeCleanUpSync);
- taosStepAdd(steps, "mnode-telem", mnodeInitTelem, mnodeCleanupTelem);
- taosStepAdd(steps, "mnode-timer", NULL, mnodeCleanupTimer);
-
- tsMint.pStartSteps = steps;
- return 0;
-}
-
-SMnode *mnodeOpen(const char *path, const SMnodeOpt *pOption) {
SMnode *pMnode = calloc(1, sizeof(SMnode));
+ if (pMnode == NULL) {
+ terrno = TSDB_CODE_OUT_OF_MEMORY;
+ mError("failed to open mnode since %s", terrstr());
+ return NULL;
+ }
- if (mnodeSetOptions(pMnode, pOption) != 0) {
+ pMnode->pSteps = taosArrayInit(24, sizeof(SMnodeStep));
+ if (pMnode->pSteps == NULL) {
free(pMnode);
- mError("failed to init mnode options since %s", terrstr());
+ terrno = TSDB_CODE_OUT_OF_MEMORY;
+ mError("failed to open mnode since %s", terrstr());
return NULL;
}
- if (mnodeAllocInitSteps() != 0) {
- mError("failed to alloc init steps since %s", terrstr());
+ int32_t code = mnodeCreateDir(pMnode, path);
+ if (mnodeCreateDir(pMnode, path) != 0) {
+ mError("failed to open mnode since %s", tstrerror(code));
+ mndClose(pMnode);
+ terrno = code;
return NULL;
}
- if (mnodeAllocStartSteps() != 0) {
- mError("failed to alloc start steps since %s", terrstr());
+ code = mndSetOptions(pMnode, pOption);
+ if (code != 0) {
+ mError("failed to open mnode since %s", tstrerror(code));
+ mndClose(pMnode);
+ terrno = code;
return NULL;
}
- taosStepExec(tsMint.pInitSteps);
-
- if (tsMint.para.dnodeId <= 0 && tsMint.para.clusterId <= 0) {
- if (sdbDeploy() != 0) {
- mError("failed to deploy sdb since %s", terrstr());
- return NULL;
- } else {
- mInfo("mnode is deployed");
- }
+ code = mndInitSteps(pMnode);
+ if (code != 0) {
+ mError("failed to open mnode since %s", tstrerror(code));
+ mndClose(pMnode);
+ terrno = code;
+ return NULL;
}
- taosStepExec(tsMint.pStartSteps);
+ code = mndExecSteps(pMnode);
+ if (code != 0) {
+ mError("failed to open mnode since %s", tstrerror(code));
+ mndClose(pMnode);
+ terrno = code;
+ return NULL;
+ }
+ mDebug("mnode open successfully ");
return pMnode;
}
-void mnodeClose(SMnode *pMnode) { free(pMnode); }
+void mndClose(SMnode *pMnode) {
+ if (pMnode != NULL) {
+ mDebug("start to close mnode");
+ mndCleanupSteps(pMnode, -1);
+ tfree(pMnode->path);
+ tfree(pMnode);
+ mDebug("mnode is closed");
+ }
+}
-int32_t mnodeAlter(SMnode *pMnode, const SMnodeOpt *pOption) { return 0; }
+int32_t mndAlter(SMnode *pMnode, const SMnodeOpt *pOption) {
+ mDebug("start to alter mnode");
+ mDebug("mnode is altered");
+ return 0;
+}
-void mnodeDestroy(const char *path) { sdbUnDeploy(); }
+void mndDestroy(const char *path) {
+ mDebug("start to destroy mnode at %s", path);
+ taosRemoveDir(path);
+ mDebug("mnode is destroyed");
+}
-int32_t mnodeGetLoad(SMnode *pMnode, SMnodeLoad *pLoad) { return 0; }
+int32_t mndGetLoad(SMnode *pMnode, SMnodeLoad *pLoad) {
+ pLoad->numOfDnode = 0;
+ pLoad->numOfMnode = 0;
+ pLoad->numOfVgroup = 0;
+ pLoad->numOfDatabase = 0;
+ pLoad->numOfSuperTable = 0;
+ pLoad->numOfChildTable = 0;
+ pLoad->numOfColumn = 0;
+ pLoad->totalPoints = 0;
+ pLoad->totalStorage = 0;
+ pLoad->compStorage = 0;
-SMnodeMsg *mnodeInitMsg(SMnode *pMnode, SRpcMsg *pRpcMsg) {
+ return 0;
+}
+
+SMnodeMsg *mndInitMsg(SMnode *pMnode, SRpcMsg *pRpcMsg) {
SMnodeMsg *pMsg = taosAllocateQitem(sizeof(SMnodeMsg));
if (pMsg == NULL) {
terrno = TSDB_CODE_OUT_OF_MEMORY;
@@ -187,7 +339,7 @@ SMnodeMsg *mnodeInitMsg(SMnode *pMnode, SRpcMsg *pRpcMsg) {
}
if (rpcGetConnInfo(pRpcMsg->handle, &pMsg->conn) != 0) {
- mnodeCleanupMsg(pMsg);
+ mndCleanupMsg(pMsg);
mError("can not get user from conn:%p", pMsg->rpcMsg.handle);
terrno = TSDB_CODE_MND_NO_USER_FROM_CONN;
return NULL;
@@ -199,181 +351,72 @@ SMnodeMsg *mnodeInitMsg(SMnode *pMnode, SRpcMsg *pRpcMsg) {
return pMsg;
}
-void mnodeCleanupMsg(SMnodeMsg *pMsg) {
+void mndCleanupMsg(SMnodeMsg *pMsg) {
if (pMsg->pUser != NULL) {
- sdbRelease(pMsg->pUser);
+ sdbRelease(pMsg->pMnode->pSdb, pMsg->pUser);
}
taosFreeQitem(pMsg);
}
-void mnodeSendRsp(SMnodeMsg *pMsg, int32_t code) {}
+void mndSendRsp(SMnodeMsg *pMsg, int32_t code) {}
-static void mnodeProcessRpcMsg(SMnodeMsg *pMsg) {
- if (!mnodeIsMaster()) {
- mnodeSendRedirectMsg(NULL, &pMsg->rpcMsg, true);
- mnodeCleanupMsg(pMsg);
- return;
- }
-
- int32_t msgType = pMsg->rpcMsg.msgType;
-
- MnodeRpcFp fp = tsMint.msgFp[msgType];
- if (fp == NULL) {
- }
-
- int32_t code = (fp)(pMsg);
- if (code != 0) {
- assert(code);
- }
-}
-
-void mnodeSetMsgFp(int32_t msgType, MnodeRpcFp fp) {
- if (msgType > 0 || msgType < TSDB_MSG_TYPE_MAX) {
- tsMint.msgFp[msgType] = fp;
- }
-}
-
-void mnodeProcessReadMsg(SMnode *pMnode, SMnodeMsg *pMsg) { mnodeProcessRpcMsg(pMsg); }
-
-void mnodeProcessWriteMsg(SMnode *pMnode, SMnodeMsg *pMsg) { mnodeProcessRpcMsg(pMsg); }
-
-void mnodeProcessSyncMsg(SMnode *pMnode, SMnodeMsg *pMsg) { mnodeProcessRpcMsg(pMsg); }
-
-void mnodeProcessApplyMsg(SMnode *pMnode, SMnodeMsg *pMsg) {}
-
-#if 0
-
-static void mnodeProcessWriteReq(SMnodeMsg *pMsg, void *unused) {
+static void mndProcessRpcMsg(SMnodeMsg *pMsg) {
+ SMnode *pMnode = pMsg->pMnode;
+ int32_t code = 0;
int32_t msgType = pMsg->rpcMsg.msgType;
void *ahandle = pMsg->rpcMsg.ahandle;
- int32_t code = 0;
+ bool isReq = (msgType % 2 == 1);
- if (pMsg->rpcMsg.pCont == NULL) {
+ if (isReq && !mndIsMaster(pMnode)) {
+ code = TSDB_CODE_APP_NOT_READY;
+ goto PROCESS_RPC_END;
+ }
+
+ if (isReq && pMsg->rpcMsg.pCont == NULL) {
mError("msg:%p, app:%p type:%s content is null", pMsg, ahandle, taosMsg[msgType]);
code = TSDB_CODE_MND_INVALID_MSG_LEN;
- goto PROCESS_WRITE_REQ_END;
+ goto PROCESS_RPC_END;
}
- if (!mnodeIsMaster()) {
- SMnRsp *rpcRsp = &pMsg->rpcRsp;
- SEpSet *epSet = rpcMallocCont(sizeof(SEpSet));
- mnodeGetMnodeEpSetForShell(epSet, true);
- rpcRsp->rsp = epSet;
- rpcRsp->len = sizeof(SEpSet);
-
- mDebug("msg:%p, app:%p type:%s in write queue, is redirected, numOfEps:%d inUse:%d", pMsg, ahandle,
- taosMsg[msgType], epSet->numOfEps, epSet->inUse);
-
- code = TSDB_CODE_RPC_REDIRECT;
- goto PROCESS_WRITE_REQ_END;
- }
-
- if (tsMworker.writeMsgFp[msgType] == NULL) {
+ MndMsgFp fp = pMnode->msgFp[msgType];
+ if (fp == NULL) {
mError("msg:%p, app:%p type:%s not processed", pMsg, ahandle, taosMsg[msgType]);
- code = TSDB_CODE_MND_MSG_NOT_PROCESSED;
- goto PROCESS_WRITE_REQ_END;
+ code = TSDB_CODE_MSG_NOT_PROCESSED;
+ goto PROCESS_RPC_END;
}
- code = (*tsMworker.writeMsgFp[msgType])(pMsg);
-
-PROCESS_WRITE_REQ_END:
- mnodeSendRsp(pMsg, code);
-}
-
-static void mnodeProcessReadReq(SMnodeMsg *pMsg, void *unused) {
- int32_t msgType = pMsg->rpcMsg.msgType;
- void *ahandle = pMsg->rpcMsg.ahandle;
- int32_t code = 0;
-
- if (pMsg->rpcMsg.pCont == NULL) {
- mError("msg:%p, app:%p type:%s in mread queue, content is null", pMsg, ahandle, taosMsg[msgType]);
- code = TSDB_CODE_MND_INVALID_MSG_LEN;
- goto PROCESS_READ_REQ_END;
+ code = (*fp)(pMnode, pMsg);
+ if (code != 0) {
+ code = terrno;
+ mError("msg:%p, app:%p type:%s failed to process since %s", pMsg, ahandle, taosMsg[msgType], terrstr());
+ goto PROCESS_RPC_END;
}
- if (!mnodeIsMaster()) {
- SMnRsp *rpcRsp = &pMsg->rpcRsp;
- SEpSet *epSet = rpcMallocCont(sizeof(SEpSet));
- if (!epSet) {
- code = TSDB_CODE_OUT_OF_MEMORY;
- goto PROCESS_READ_REQ_END;
+PROCESS_RPC_END:
+ if (isReq) {
+ if (code == TSDB_CODE_APP_NOT_READY) {
+ mndSendRedirectMsg(pMnode, &pMsg->rpcMsg);
+ } else if (code != 0) {
+ SRpcMsg rspMsg = {.handle = pMsg->rpcMsg.handle, .code = code};
+ rpcSendResponse(&rspMsg);
+ } else {
}
- mnodeGetMnodeEpSetForShell(epSet, true);
- rpcRsp->rsp = epSet;
- rpcRsp->len = sizeof(SEpSet);
-
- mDebug("msg:%p, app:%p type:%s in mread queue is redirected, numOfEps:%d inUse:%d", pMsg, ahandle, taosMsg[msgType],
- epSet->numOfEps, epSet->inUse);
- code = TSDB_CODE_RPC_REDIRECT;
- goto PROCESS_READ_REQ_END;
}
- if (tsMworker.readMsgFp[msgType] == NULL) {
- mError("msg:%p, app:%p type:%s in mread queue, not processed", pMsg, ahandle, taosMsg[msgType]);
- code = TSDB_CODE_MND_MSG_NOT_PROCESSED;
- goto PROCESS_READ_REQ_END;
- }
-
- mTrace("msg:%p, app:%p type:%s will be processed in mread queue", pMsg, ahandle, taosMsg[msgType]);
- code = (*tsMworker.readMsgFp[msgType])(pMsg);
-
-PROCESS_READ_REQ_END:
- mnodeSendRsp(pMsg, code);
+ mndCleanupMsg(pMsg);
}
-static void mnodeProcessPeerReq(SMnodeMsg *pMsg, void *unused) {
- int32_t msgType = pMsg->rpcMsg.msgType;
- void *ahandle = pMsg->rpcMsg.ahandle;
- int32_t code = 0;
-
- if (pMsg->rpcMsg.pCont == NULL) {
- mError("msg:%p, ahandle:%p type:%s in mpeer queue, content is null", pMsg, ahandle, taosMsg[msgType]);
- code = TSDB_CODE_MND_INVALID_MSG_LEN;
- goto PROCESS_PEER_REQ_END;
+void mndSetMsgHandle(SMnode *pMnode, int32_t msgType, MndMsgFp fp) {
+ if (msgType >= 0 && msgType < TSDB_MSG_TYPE_MAX) {
+ pMnode->msgFp[msgType] = fp;
}
-
- if (!mnodeIsMaster()) {
- SMnRsp *rpcRsp = &pMsg->rpcRsp;
- SEpSet *epSet = rpcMallocCont(sizeof(SEpSet));
- mnodeGetMnodeEpSetForPeer(epSet, true);
- rpcRsp->rsp = epSet;
- rpcRsp->len = sizeof(SEpSet);
-
- mDebug("msg:%p, ahandle:%p type:%s in mpeer queue is redirected, numOfEps:%d inUse:%d", pMsg, ahandle,
- taosMsg[msgType], epSet->numOfEps, epSet->inUse);
-
- code = TSDB_CODE_RPC_REDIRECT;
- goto PROCESS_PEER_REQ_END;
- }
-
- if (tsMworker.peerReqFp[msgType] == NULL) {
- mError("msg:%p, ahandle:%p type:%s in mpeer queue, not processed", pMsg, ahandle, taosMsg[msgType]);
- code = TSDB_CODE_MND_MSG_NOT_PROCESSED;
- goto PROCESS_PEER_REQ_END;
- }
-
- code = (*tsMworker.peerReqFp[msgType])(pMsg);
-
-PROCESS_PEER_REQ_END:
- mnodeSendRsp(pMsg, code);
}
-static void mnodeProcessPeerRsp(SMnodeMsg *pMsg, void *unused) {
- int32_t msgType = pMsg->rpcMsg.msgType;
- SRpcMsg *pRpcMsg = &pMsg->rpcMsg;
+void mndProcessReadMsg(SMnodeMsg *pMsg) { mndProcessRpcMsg(pMsg); }
- if (!mnodeIsMaster()) {
- mError("msg:%p, ahandle:%p type:%s not processed for not master", pRpcMsg, pRpcMsg->ahandle, taosMsg[msgType]);
- mnodeCleanupMsg2(pMsg);
- }
+void mndProcessWriteMsg(SMnodeMsg *pMsg) { mndProcessRpcMsg(pMsg); }
- if (tsMworker.peerRspFp[msgType]) {
- (*tsMworker.peerRspFp[msgType])(pRpcMsg);
- } else {
- mError("msg:%p, ahandle:%p type:%s is not processed", pRpcMsg, pRpcMsg->ahandle, taosMsg[msgType]);
- }
+void mndProcessSyncMsg(SMnodeMsg *pMsg) { mndProcessRpcMsg(pMsg); }
- mnodeCleanupMsg2(pMsg);
-}
-#endif
\ No newline at end of file
+void mndProcessApplyMsg(SMnodeMsg *pMsg) {}
diff --git a/source/dnode/mnode/impl/src/mnodeFunc.c b/source/dnode/mnode/impl/src/mnodeFunc.c
deleted file mode 100644
index 2d8628c2be..0000000000
--- a/source/dnode/mnode/impl/src/mnodeFunc.c
+++ /dev/null
@@ -1,21 +0,0 @@
-/*
- * Copyright (c) 2019 TAOS Data, Inc.
- *
- * This program is free software: you can use, redistribute, and/or modify
- * it under the terms of the GNU Affero General Public License, version 3
- * or later ("AGPL"), as published by the Free Software Foundation.
- *
- * This program is distributed in the hope that it will be useful, but WITHOUT
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
- * FITNESS FOR A PARTICULAR PURPOSE.
- *
- * You should have received a copy of the GNU Affero General Public License
- * along with this program. If not, see .
- */
-
-#define _DEFAULT_SOURCE
-#include "os.h"
-#include "mnodeInt.h"
-
-int32_t mnodeInitFunc() { return 0; }
-void mnodeCleanupFunc() {}
\ No newline at end of file
diff --git a/source/dnode/mnode/impl/src/mnodeOper.c b/source/dnode/mnode/impl/src/mnodeOper.c
deleted file mode 100644
index 35f4db0261..0000000000
--- a/source/dnode/mnode/impl/src/mnodeOper.c
+++ /dev/null
@@ -1,21 +0,0 @@
-/*
- * Copyright (c) 2019 TAOS Data, Inc.
- *
- * This program is free software: you can use, redistribute, and/or modify
- * it under the terms of the GNU Affero General Public License, version 3
- * or later ("AGPL"), as published by the Free Software Foundation.
- *
- * This program is distributed in the hope that it will be useful, but WITHOUT
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
- * FITNESS FOR A PARTICULAR PURPOSE.
- *
- * You should have received a copy of the GNU Affero General Public License
- * along with this program. If not, see .
- */
-
-#define _DEFAULT_SOURCE
-#include "os.h"
-#include "mnodeInt.h"
-
-int32_t mnodeInitOper() { return 0; }
-void mnodeCleanupOper() {}
\ No newline at end of file
diff --git a/source/dnode/mnode/impl/src/mnodeProfile.c b/source/dnode/mnode/impl/src/mnodeProfile.c
deleted file mode 100644
index 9cf9e184cf..0000000000
--- a/source/dnode/mnode/impl/src/mnodeProfile.c
+++ /dev/null
@@ -1,21 +0,0 @@
-/*
- * Copyright (c) 2019 TAOS Data, Inc.
- *
- * This program is free software: you can use, redistribute, and/or modify
- * it under the terms of the GNU Affero General Public License, version 3
- * or later ("AGPL"), as published by the Free Software Foundation.
- *
- * This program is distributed in the hope that it will be useful, but WITHOUT
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
- * FITNESS FOR A PARTICULAR PURPOSE.
- *
- * You should have received a copy of the GNU Affero General Public License
- * along with this program. If not, see .
- */
-
-#define _DEFAULT_SOURCE
-#include "os.h"
-#include "mnodeInt.h"
-
-int32_t mnodeInitProfile() { return 0; }
-void mnodeCleanupProfile() {}
\ No newline at end of file
diff --git a/source/dnode/mnode/impl/src/mnodeShow.c b/source/dnode/mnode/impl/src/mnodeShow.c
deleted file mode 100644
index 9918ad28e0..0000000000
--- a/source/dnode/mnode/impl/src/mnodeShow.c
+++ /dev/null
@@ -1,21 +0,0 @@
-/*
- * Copyright (c) 2019 TAOS Data, Inc.
- *
- * This program is free software: you can use, redistribute, and/or modify
- * it under the terms of the GNU Affero General Public License, version 3
- * or later ("AGPL"), as published by the Free Software Foundation.
- *
- * This program is distributed in the hope that it will be useful, but WITHOUT
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
- * FITNESS FOR A PARTICULAR PURPOSE.
- *
- * You should have received a copy of the GNU Affero General Public License
- * along with this program. If not, see .
- */
-
-#define _DEFAULT_SOURCE
-#include "os.h"
-#include "mnodeInt.h"
-
-int32_t mnodeInitShow() { return 0; }
-void mnodeCleanUpShow() {}
\ No newline at end of file
diff --git a/source/dnode/mnode/impl/src/mnodeStable.c b/source/dnode/mnode/impl/src/mnodeStable.c
deleted file mode 100644
index 87e887a11b..0000000000
--- a/source/dnode/mnode/impl/src/mnodeStable.c
+++ /dev/null
@@ -1,21 +0,0 @@
-/*
- * Copyright (c) 2019 TAOS Data, Inc.
- *
- * This program is free software: you can use, redistribute, and/or modify
- * it under the terms of the GNU Affero General Public License, version 3
- * or later ("AGPL"), as published by the Free Software Foundation.
- *
- * This program is distributed in the hope that it will be useful, but WITHOUT
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
- * FITNESS FOR A PARTICULAR PURPOSE.
- *
- * You should have received a copy of the GNU Affero General Public License
- * along with this program. If not, see .
- */
-
-#define _DEFAULT_SOURCE
-#include "os.h"
-#include "mnodeInt.h"
-
-int32_t mnodeInitStable() { return 0; }
-void mnodeCleanupStable() {}
\ No newline at end of file
diff --git a/source/dnode/mnode/impl/src/mnodeVgroup.c b/source/dnode/mnode/impl/src/mnodeVgroup.c
deleted file mode 100644
index 6f9df1f69f..0000000000
--- a/source/dnode/mnode/impl/src/mnodeVgroup.c
+++ /dev/null
@@ -1,21 +0,0 @@
-/*
- * Copyright (c) 2019 TAOS Data, Inc.
- *
- * This program is free software: you can use, redistribute, and/or modify
- * it under the terms of the GNU Affero General Public License, version 3
- * or later ("AGPL"), as published by the Free Software Foundation.
- *
- * This program is distributed in the hope that it will be useful, but WITHOUT
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
- * FITNESS FOR A PARTICULAR PURPOSE.
- *
- * You should have received a copy of the GNU Affero General Public License
- * along with this program. If not, see .
- */
-
-#define _DEFAULT_SOURCE
-#include "os.h"
-#include "mnodeInt.h"
-
-int32_t mnodeInitVgroup() { return 0; }
-void mnodeCleanupVgroup() {}
\ No newline at end of file
diff --git a/source/dnode/mnode/sdb/CMakeLists.txt b/source/dnode/mnode/sdb/CMakeLists.txt
index c5a0b7299a..b6620f8be4 100644
--- a/source/dnode/mnode/sdb/CMakeLists.txt
+++ b/source/dnode/mnode/sdb/CMakeLists.txt
@@ -3,7 +3,7 @@ add_library(sdb ${MNODE_SRC})
target_include_directories(
sdb
PUBLIC "${CMAKE_SOURCE_DIR}/include/dnode/mnode/sdb"
- private "${CMAKE_CURRENT_SOURCE_DIR}/inc"
+ PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/inc"
)
target_link_libraries(
sdb
diff --git a/source/dnode/mnode/sdb/inc/sdbInt.h b/source/dnode/mnode/sdb/inc/sdbInt.h
index 2b3c577ba9..6162617568 100644
--- a/source/dnode/mnode/sdb/inc/sdbInt.h
+++ b/source/dnode/mnode/sdb/inc/sdbInt.h
@@ -37,7 +37,7 @@ extern "C" {
#define SDB_MAX_SIZE (32 * 1024)
typedef struct SSdbRaw {
- int8_t sdb;
+ int8_t type;
int8_t sver;
int8_t status;
int8_t reserved;
@@ -46,7 +46,7 @@ typedef struct SSdbRaw {
} SSdbRaw;
typedef struct SSdbRow {
- ESdbType sdb;
+ ESdbType type;
ESdbStatus status;
int32_t refCount;
char pObj[];
@@ -69,9 +69,8 @@ typedef struct SSdb {
SdbDecodeFp decodeFps[SDB_MAX];
} SSdb;
-extern SSdb tsSdb;
-
-int32_t sdbWriteImp(SSdbRaw *pRaw);
+int32_t sdbWriteFile(SSdb *pSdb);
+int32_t sdbWriteRaw(SSdb *pSdb, SSdbRaw *pRaw);
#ifdef __cplusplus
}
diff --git a/source/dnode/mnode/sdb/src/sdb.c b/source/dnode/mnode/sdb/src/sdb.c
index 83496f3794..4f1267498c 100644
--- a/source/dnode/mnode/sdb/src/sdb.c
+++ b/source/dnode/mnode/sdb/src/sdb.c
@@ -15,31 +15,86 @@
#define _DEFAULT_SOURCE
#include "sdbInt.h"
-#include "tglobal.h"
-SSdb tsSdb = {0};
+SSdb *sdbInit(SSdbOpt *pOption) {
+ mDebug("start to init sdb in %s", pOption->path);
+
+ SSdb *pSdb = calloc(1, sizeof(SSdb));
+ if (pSdb == NULL) {
+ terrno = TSDB_CODE_OUT_OF_MEMORY;
+ mError("failed to init sdb since %s", terrstr());
+ return NULL;
+ }
-int32_t sdbInit() {
char path[PATH_MAX + 100];
-
- snprintf(path, PATH_MAX + 100, "%s%scur%s", tsMnodeDir, TD_DIRSEP, TD_DIRSEP);
- tsSdb.currDir = strdup(path);
-
- snprintf(path, PATH_MAX + 100, "%s%ssync%s", tsMnodeDir, TD_DIRSEP, TD_DIRSEP);
- tsSdb.syncDir = strdup(path);
-
- snprintf(path, PATH_MAX + 100, "%s%stmp%s", tsMnodeDir, TD_DIRSEP, TD_DIRSEP);
- tsSdb.tmpDir = strdup(path);
-
- if (tsSdb.currDir == NULL || tsSdb.currDir == NULL || tsSdb.currDir == NULL) {
- return TSDB_CODE_OUT_OF_MEMORY;
+ snprintf(path, PATH_MAX + 100, "%s", pOption->path);
+ pSdb->currDir = strdup(path);
+ snprintf(path, PATH_MAX + 100, "%s%ssync", pOption->path, TD_DIRSEP);
+ pSdb->syncDir = strdup(path);
+ snprintf(path, PATH_MAX + 100, "%s%stmp", pOption->path, TD_DIRSEP);
+ pSdb->tmpDir = strdup(path);
+ if (pSdb->currDir == NULL || pSdb->currDir == NULL || pSdb->currDir == NULL) {
+ sdbCleanup(pSdb);
+ terrno = TSDB_CODE_OUT_OF_MEMORY;
+ mError("failed to init sdb since %s", terrstr());
+ return NULL;
}
+ for (int32_t i = 0; i < SDB_MAX; ++i) {
+ taosInitRWLatch(&pSdb->locks[i]);
+ }
+
+ mDebug("sdb init successfully");
+ return pSdb;
+}
+
+void sdbCleanup(SSdb *pSdb) {
+ mDebug("start to cleanup sdb");
+
+ if (pSdb->curVer != pSdb->lastCommitVer) {
+ mDebug("write sdb file for curVer:% " PRId64 " and lastVer:%" PRId64, pSdb->curVer, pSdb->lastCommitVer);
+ sdbWriteFile(pSdb);
+ }
+
+ if (pSdb->currDir != NULL) {
+ tfree(pSdb->currDir);
+ }
+
+ if (pSdb->syncDir != NULL) {
+ tfree(pSdb->syncDir);
+ }
+
+ if (pSdb->tmpDir != NULL) {
+ tfree(pSdb->tmpDir);
+ }
+
+ for (int32_t i = 0; i < SDB_MAX; ++i) {
+ SHashObj *hash = pSdb->hashObjs[i];
+ if (hash != NULL) {
+ taosHashClear(hash);
+ taosHashCleanup(hash);
+ }
+ pSdb->hashObjs[i] = NULL;
+ }
+
+ mDebug("sdb is cleaned up");
+}
+
+int32_t sdbSetTable(SSdb *pSdb, SSdbTable table) {
+ ESdbType sdb = table.sdbType;
+ pSdb->keyTypes[sdb] = table.keyType;
+ pSdb->insertFps[sdb] = table.insertFp;
+ pSdb->updateFps[sdb] = table.updateFp;
+ pSdb->deleteFps[sdb] = table.deleteFp;
+ pSdb->deployFps[sdb] = table.deployFp;
+ pSdb->encodeFps[sdb] = table.encodeFp;
+ pSdb->decodeFps[sdb] = table.decodeFp;
+
for (int32_t i = 0; i < SDB_MAX; ++i) {
int32_t type;
- if (tsSdb.keyTypes[i] == SDB_KEY_INT32) {
+ if (pSdb->keyTypes[i] == SDB_KEY_INT32) {
type = TSDB_DATA_TYPE_INT;
- } else if (tsSdb.keyTypes[i] == SDB_KEY_INT64) {
+ } else if (pSdb->keyTypes[i] == SDB_KEY_INT64) {
type = TSDB_DATA_TYPE_BIGINT;
} else {
type = TSDB_DATA_TYPE_BINARY;
@@ -47,45 +102,13 @@ int32_t sdbInit() {
SHashObj *hash = taosHashInit(64, taosGetDefaultHashFunction(type), true, HASH_NO_LOCK);
if (hash == NULL) {
- return TSDB_CODE_OUT_OF_MEMORY;
+ terrno = TSDB_CODE_OUT_OF_MEMORY;
+ return -1;
}
- tsSdb.hashObjs[i] = hash;
- taosInitRWLatch(&tsSdb.locks[i]);
+ pSdb->hashObjs[i] = hash;
+ taosInitRWLatch(&pSdb->locks[i]);
}
return 0;
-}
-
-void sdbCleanup() {
- if (tsSdb.currDir != NULL) {
- tfree(tsSdb.currDir);
- }
-
- if (tsSdb.syncDir != NULL) {
- tfree(tsSdb.syncDir);
- }
-
- if (tsSdb.tmpDir != NULL) {
- tfree(tsSdb.tmpDir);
- }
-
- for (int32_t i = 0; i < SDB_MAX; ++i) {
- SHashObj *hash = tsSdb.hashObjs[i];
- if (hash != NULL) {
- taosHashCleanup(hash);
- }
- tsSdb.hashObjs[i] = NULL;
- }
-}
-
-void sdbSetTable(SSdbTable table) {
- ESdbType sdb = table.sdbType;
- tsSdb.keyTypes[sdb] = table.keyType;
- tsSdb.insertFps[sdb] = table.insertFp;
- tsSdb.updateFps[sdb] = table.updateFp;
- tsSdb.deleteFps[sdb] = table.deleteFp;
- tsSdb.deployFps[sdb] = table.deployFp;
- tsSdb.encodeFps[sdb] = table.encodeFp;
- tsSdb.decodeFps[sdb] = table.decodeFp;
}
\ No newline at end of file
diff --git a/source/dnode/mnode/sdb/src/sdbFile.c b/source/dnode/mnode/sdb/src/sdbFile.c
index d77ec6ef8f..37fcdc19ef 100644
--- a/source/dnode/mnode/sdb/src/sdbFile.c
+++ b/source/dnode/mnode/sdb/src/sdbFile.c
@@ -15,71 +15,71 @@
#define _DEFAULT_SOURCE
#include "sdbInt.h"
-#include "tglobal.h"
#include "tchecksum.h"
-static int32_t sdbCreateDir() {
- mDebug("start to create mnode at %s", tsMnodeDir);
-
- if (taosMkDir(tsSdb.currDir) != 0) {
+static int32_t sdbCreateDir(SSdb *pSdb) {
+ if (taosMkDir(pSdb->currDir) != 0) {
terrno = TAOS_SYSTEM_ERROR(errno);
- mError("failed to create dir:%s since %s", tsSdb.currDir, terrstr());
+ mError("failed to create dir:%s since %s", pSdb->currDir, terrstr());
return -1;
}
- if (taosMkDir(tsSdb.syncDir) != 0) {
+ if (taosMkDir(pSdb->syncDir) != 0) {
terrno = TAOS_SYSTEM_ERROR(errno);
- mError("failed to create dir:%s since %s", tsSdb.syncDir, terrstr());
+ mError("failed to create dir:%s since %s", pSdb->syncDir, terrstr());
return -1;
}
- if (taosMkDir(tsSdb.tmpDir) != 0) {
+ if (taosMkDir(pSdb->tmpDir) != 0) {
terrno = TAOS_SYSTEM_ERROR(errno);
- mError("failed to create dir:%s since %s", tsSdb.tmpDir, terrstr());
+ mError("failed to create dir:%s since %s", pSdb->tmpDir, terrstr());
return -1;
}
return 0;
}
-static int32_t sdbRunDeployFp() {
- mDebug("start to run deploy functions");
+static int32_t sdbRunDeployFp(SSdb *pSdb) {
+ mDebug("start to deploy sdb");
for (int32_t i = SDB_MAX - 1; i > SDB_START; --i) {
- SdbDeployFp fp = tsSdb.deployFps[i];
+ SdbDeployFp fp = pSdb->deployFps[i];
if (fp == NULL) continue;
- if ((*fp)() != 0) {
+
+ if ((*fp)(pSdb) != 0) {
mError("failed to deploy sdb:%d since %s", i, terrstr());
return -1;
}
}
- mDebug("end of run deploy functions");
+ mDebug("sdb deploy successfully");
return 0;
}
-static int32_t sdbReadDataFile() {
- SSdbRaw *pRaw = malloc(SDB_MAX_SIZE);
- if (pRaw == NULL) {
- terrno = TSDB_CODE_OUT_OF_MEMORY;
- return -1;
- }
-
- char file[PATH_MAX] = {0};
- snprintf(file, sizeof(file), "%ssdb.data", tsSdb.currDir);
- FileFd fd = taosOpenFileRead(file);
- if (fd <= 0) {
- free(pRaw);
- terrno = TAOS_SYSTEM_ERROR(errno);
- mError("failed to open file:%s for read since %s", file, terrstr());
- return -1;
- }
-
+int32_t sdbReadFile(SSdb *pSdb) {
int64_t offset = 0;
int32_t code = 0;
int32_t readLen = 0;
int64_t ret = 0;
+ SSdbRaw *pRaw = malloc(SDB_MAX_SIZE);
+ if (pRaw == NULL) {
+ terrno = TSDB_CODE_OUT_OF_MEMORY;
+ mError("failed read file since %s", terrstr());
+ return -1;
+ }
+
+ char file[PATH_MAX] = {0};
+ snprintf(file, sizeof(file), "%s%ssdb.data", pSdb->currDir, TD_DIRSEP);
+
+ FileFd fd = taosOpenFileRead(file);
+ if (fd <= 0) {
+ free(pRaw);
+ terrno = TAOS_SYSTEM_ERROR(errno);
+ mError("failed to read file:%s since %s", file, terrstr());
+ return -1;
+ }
+
while (1) {
readLen = sizeof(SSdbRaw);
ret = taosReadFile(fd, pRaw, readLen);
@@ -118,7 +118,7 @@ static int32_t sdbReadDataFile() {
break;
}
- code = sdbWriteImp(pRaw);
+ code = sdbWriteRaw(pSdb, pRaw);
if (code != 0) {
mError("failed to read file:%s since %s", file, terrstr());
goto PARSE_SDB_DATA_ERROR;
@@ -130,13 +130,18 @@ static int32_t sdbReadDataFile() {
PARSE_SDB_DATA_ERROR:
taosCloseFile(fd);
sdbFreeRaw(pRaw);
+
terrno = code;
return code;
}
-static int32_t sdbWriteDataFile() {
+int32_t sdbWriteFile(SSdb *pSdb) {
+ int32_t code = 0;
+
char tmpfile[PATH_MAX] = {0};
- snprintf(tmpfile, sizeof(tmpfile), "%ssdb.data", tsSdb.tmpDir);
+ snprintf(tmpfile, sizeof(tmpfile), "%s%ssdb.data", pSdb->tmpDir, TD_DIRSEP);
+ char curfile[PATH_MAX] = {0};
+ snprintf(curfile, sizeof(curfile), "%s%ssdb.data", pSdb->currDir, TD_DIRSEP);
FileFd fd = taosOpenFileCreateWrite(tmpfile);
if (fd <= 0) {
@@ -145,14 +150,12 @@ static int32_t sdbWriteDataFile() {
return -1;
}
- int32_t code = 0;
-
for (int32_t i = SDB_MAX - 1; i > SDB_START; --i) {
- SdbEncodeFp encodeFp = tsSdb.encodeFps[i];
+ SdbEncodeFp encodeFp = pSdb->encodeFps[i];
if (encodeFp == NULL) continue;
- SHashObj *hash = tsSdb.hashObjs[i];
- SRWLatch *pLock = &tsSdb.locks[i];
+ SHashObj *hash = pSdb->hashObjs[i];
+ SRWLatch *pLock = &pSdb->locks[i];
taosWLockLatch(pLock);
SSdbRow **ppRow = taosHashIterate(hash, NULL);
@@ -192,68 +195,44 @@ static int32_t sdbWriteDataFile() {
if (code == 0) {
code = taosFsyncFile(fd);
+ if (code != 0) {
+ code = TAOS_SYSTEM_ERROR(errno);
+ mError("failed to write file:%s since %s", tmpfile, tstrerror(code));
+ }
}
taosCloseFile(fd);
if (code == 0) {
- char curfile[PATH_MAX] = {0};
- snprintf(curfile, sizeof(curfile), "%ssdb.data", tsSdb.currDir);
code = taosRenameFile(tmpfile, curfile);
+ if (code != 0) {
+ code = TAOS_SYSTEM_ERROR(errno);
+ mError("failed to write file:%s since %s", curfile, tstrerror(code));
+ }
}
if (code != 0) {
- terrno = code;
- mError("failed to write sdb file since %s", terrstr());
+ mError("failed to write file:%s since %s", curfile, tstrerror(code));
} else {
- mDebug("write sdb file successfully");
+ mDebug("write file:%s successfully", curfile);
}
+ terrno = code;
return code;
}
-int32_t sdbOpen() {
- mDebug("start to read mnode file");
+int32_t sdbDeploy(SSdb *pSdb) {
+ if (sdbCreateDir(pSdb) != 0) {
+ return -1;
+ }
- if (sdbReadDataFile() != 0) {
+ if (sdbRunDeployFp(pSdb) != 0) {
+ return -1;
+ }
+
+ if (sdbWriteFile(pSdb) != 0) {
return -1;
}
return 0;
}
-
-void sdbClose() {
- if (tsSdb.curVer != tsSdb.lastCommitVer) {
- mDebug("start to write mnode file");
- sdbWriteDataFile();
- }
-
- for (int32_t i = 0; i < SDB_MAX; ++i) {
- SHashObj *hash = tsSdb.hashObjs[i];
- if (hash != NULL) {
- taosHashClear(hash);
- }
- }
-}
-
-int32_t sdbDeploy() {
- if (sdbCreateDir() != 0) {
- return -1;
- }
-
- if (sdbRunDeployFp() != 0) {
- return -1;
- }
-
- if (sdbWriteDataFile() != 0) {
- return -1;
- }
-
- sdbClose();
- return 0;
-}
-
-void sdbUnDeploy() {
- mDebug("start to undeploy mnode");
- taosRemoveDir(tsMnodeDir);
-}
diff --git a/source/dnode/mnode/sdb/src/sdbHash.c b/source/dnode/mnode/sdb/src/sdbHash.c
index 9c19e7f1a2..0db5c0beb6 100644
--- a/source/dnode/mnode/sdb/src/sdbHash.c
+++ b/source/dnode/mnode/sdb/src/sdbHash.c
@@ -15,15 +15,14 @@
#define _DEFAULT_SOURCE
#include "sdbInt.h"
-#include "tglobal.h"
-static SHashObj *sdbGetHash(int32_t sdb) {
- if (sdb >= SDB_MAX || sdb <= SDB_START) {
+static SHashObj *sdbGetHash(SSdb *pSdb, int32_t type) {
+ if (type >= SDB_MAX || type <= SDB_START) {
terrno = TSDB_CODE_SDB_INVALID_TABLE_TYPE;
return NULL;
}
- SHashObj *hash = tsSdb.hashObjs[sdb];
+ SHashObj *hash = pSdb->hashObjs[type];
if (hash == NULL) {
terrno = TSDB_CODE_SDB_APP_ERROR;
return NULL;
@@ -32,9 +31,9 @@ static SHashObj *sdbGetHash(int32_t sdb) {
return hash;
}
-static int32_t sdbGetkeySize(ESdbType sdb, void *pKey) {
+static int32_t sdbGetkeySize(SSdb *pSdb, ESdbType type, void *pKey) {
int32_t keySize;
- EKeyType keyType = tsSdb.keyTypes[sdb];
+ EKeyType keyType = pSdb->keyTypes[type];
if (keyType == SDB_KEY_INT32) {
keySize = sizeof(int32_t);
@@ -47,77 +46,81 @@ static int32_t sdbGetkeySize(ESdbType sdb, void *pKey) {
return keySize;
}
-static int32_t sdbInsertRow(SHashObj *hash, SSdbRaw *pRaw, SSdbRow *pRow, int32_t keySize) {
- SRWLatch *pLock = &tsSdb.locks[pRow->sdb];
+static int32_t sdbInsertRow(SSdb *pSdb, SHashObj *hash, SSdbRaw *pRaw, SSdbRow *pRow, int32_t keySize) {
+ int32_t code = 0;
+
+ SRWLatch *pLock = &pSdb->locks[pRow->type];
taosWLockLatch(pLock);
SSdbRow *pDstRow = taosHashGet(hash, pRow->pObj, keySize);
if (pDstRow != NULL) {
- terrno = TSDB_CODE_SDB_OBJ_ALREADY_THERE;
taosWUnLockLatch(pLock);
sdbFreeRow(pRow);
- return -1;
+ return TSDB_CODE_SDB_OBJ_ALREADY_THERE;
}
pRow->refCount = 1;
pRow->status = pRaw->status;
if (taosHashPut(hash, pRow->pObj, keySize, &pRow, sizeof(void *)) != 0) {
- terrno = TSDB_CODE_OUT_OF_MEMORY;
taosWUnLockLatch(pLock);
sdbFreeRow(pRow);
- return -1;
+ return TSDB_CODE_SDB_OBJ_ALREADY_THERE;
}
taosWUnLockLatch(pLock);
- SdbInsertFp insertFp = tsSdb.insertFps[pRow->sdb];
+ SdbInsertFp insertFp = pSdb->insertFps[pRow->type];
if (insertFp != NULL) {
- if ((*insertFp)(pRow->pObj) != 0) {
+ code = (*insertFp)(pSdb, pRow->pObj);
+ if (code != 0) {
taosWLockLatch(pLock);
taosHashRemove(hash, pRow->pObj, keySize);
taosWUnLockLatch(pLock);
sdbFreeRow(pRow);
- return -1;
+ return code;
}
}
return 0;
}
-static int32_t sdbUpdateRow(SHashObj *hash, SSdbRaw *pRaw, SSdbRow *pRow, int32_t keySize) {
- SRWLatch *pLock = &tsSdb.locks[pRow->sdb];
+static int32_t sdbUpdateRow(SSdb *pSdb, SHashObj *hash, SSdbRaw *pRaw, SSdbRow *pRow, int32_t keySize) {
+ int32_t code = 0;
+
+ SRWLatch *pLock = &pSdb->locks[pRow->type];
taosRLockLatch(pLock);
SSdbRow **ppDstRow = taosHashGet(hash, pRow->pObj, keySize);
if (ppDstRow == NULL || *ppDstRow == NULL) {
taosRUnLockLatch(pLock);
- return sdbInsertRow(hash, pRaw, pRow, keySize);
+ return sdbInsertRow(pSdb, hash, pRaw, pRow, keySize);
}
SSdbRow *pDstRow = *ppDstRow;
pRow->status = pRaw->status;
taosRUnLockLatch(pLock);
- SdbUpdateFp updateFp = tsSdb.updateFps[pRow->sdb];
+ SdbUpdateFp updateFp = pSdb->updateFps[pRow->type];
if (updateFp != NULL) {
- (*updateFp)(pRow->pObj, pDstRow->pObj);
+ code = (*updateFp)(pSdb, pRow->pObj, pDstRow->pObj);
}
sdbFreeRow(pRow);
- return 0;
+ return code;
}
-static int32_t sdbDeleteRow(SHashObj *hash, SSdbRaw *pRaw, SSdbRow *pRow, int32_t keySize) {
- SRWLatch *pLock = &tsSdb.locks[pRow->sdb];
+static int32_t sdbDeleteRow(SSdb *pSdb, SHashObj *hash, SSdbRaw *pRaw, SSdbRow *pRow, int32_t keySize) {
+ int32_t code = 0;
+
+ SRWLatch *pLock = &pSdb->locks[pRow->type];
taosWLockLatch(pLock);
SSdbRow **ppDstRow = taosHashGet(hash, pRow->pObj, keySize);
if (ppDstRow == NULL || *ppDstRow == NULL) {
- terrno = TSDB_CODE_SDB_OBJ_NOT_THERE;
taosWUnLockLatch(pLock);
sdbFreeRow(pRow);
- return -1;
+ return TSDB_CODE_SDB_OBJ_NOT_THERE;
}
SSdbRow *pDstRow = *ppDstRow;
@@ -125,71 +128,67 @@ static int32_t sdbDeleteRow(SHashObj *hash, SSdbRaw *pRaw, SSdbRow *pRow, int32_
taosHashRemove(hash, pDstRow->pObj, keySize);
taosWUnLockLatch(pLock);
- SdbDeleteFp deleteFp = tsSdb.deleteFps[pDstRow->sdb];
+ SdbDeleteFp deleteFp = pSdb->deleteFps[pDstRow->type];
if (deleteFp != NULL) {
- (void)(*deleteFp)(pDstRow->pObj);
+ code = (*deleteFp)(pSdb, pDstRow->pObj);
}
- sdbRelease(pDstRow->pObj);
+ sdbRelease(pSdb, pDstRow->pObj);
sdbFreeRow(pRow);
- return 0;
+ return code;
}
-int32_t sdbWriteImp(SSdbRaw *pRaw) {
- SHashObj *hash = sdbGetHash(pRaw->sdb);
- if (hash == NULL) return -1;
+int32_t sdbWriteRaw(SSdb *pSdb, SSdbRaw *pRaw) {
+ SHashObj *hash = sdbGetHash(pSdb, pRaw->type);
+ if (hash == NULL) return terrno;
- SdbDecodeFp decodeFp = tsSdb.decodeFps[pRaw->sdb];
+ SdbDecodeFp decodeFp = pSdb->decodeFps[pRaw->type];
SSdbRow *pRow = (*decodeFp)(pRaw);
if (pRow == NULL) {
- terrno = TSDB_CODE_SDB_INVALID_DATA_CONTENT;
- return -1;
+ return terrno;
}
- pRow->sdb = pRaw->sdb;
+ pRow->type = pRaw->type;
- int32_t keySize = sdbGetkeySize(pRow->sdb, pRow->pObj);
- int32_t code = -1;
+ int32_t keySize = sdbGetkeySize(pSdb, pRow->type, pRow->pObj);
+ int32_t code = TSDB_CODE_SDB_INVALID_ACTION_TYPE;
switch (pRaw->status) {
case SDB_STATUS_CREATING:
- code = sdbInsertRow(hash, pRaw, pRow, keySize);
+ code = sdbInsertRow(pSdb, hash, pRaw, pRow, keySize);
break;
case SDB_STATUS_READY:
case SDB_STATUS_DROPPING:
- code = sdbUpdateRow(hash, pRaw, pRow, keySize);
+ code = sdbUpdateRow(pSdb, hash, pRaw, pRow, keySize);
break;
case SDB_STATUS_DROPPED:
- code = sdbDeleteRow(hash, pRaw, pRow, keySize);
- break;
- default:
- terrno = TSDB_CODE_SDB_INVALID_ACTION_TYPE;
+ code = sdbDeleteRow(pSdb, hash, pRaw, pRow, keySize);
break;
}
return code;
}
-int32_t sdbWrite(SSdbRaw *pRaw) {
- int32_t code = sdbWriteImp(pRaw);
+int32_t sdbWrite(SSdb *pSdb, SSdbRaw *pRaw) {
+ int32_t code = sdbWriteRaw(pSdb, pRaw);
sdbFreeRaw(pRaw);
return code;
}
-void *sdbAcquire(ESdbType sdb, void *pKey) {
- SHashObj *hash = sdbGetHash(sdb);
+void *sdbAcquire(SSdb *pSdb, ESdbType type, void *pKey) {
+ SHashObj *hash = sdbGetHash(pSdb, type);
if (hash == NULL) return NULL;
void *pRet = NULL;
- int32_t keySize = sdbGetkeySize(sdb, pKey);
+ int32_t keySize = sdbGetkeySize(pSdb, type, pKey);
- SRWLatch *pLock = &tsSdb.locks[sdb];
+ SRWLatch *pLock = &pSdb->locks[type];
taosRLockLatch(pLock);
SSdbRow **ppRow = taosHashGet(hash, pKey, keySize);
if (ppRow == NULL || *ppRow == NULL) {
- terrno = TSDB_CODE_SDB_OBJ_NOT_THERE;
taosRUnLockLatch(pLock);
+ terrno = TSDB_CODE_SDB_OBJ_NOT_THERE;
return NULL;
}
@@ -214,13 +213,13 @@ void *sdbAcquire(ESdbType sdb, void *pKey) {
return pRet;
}
-void sdbRelease(void *pObj) {
+void sdbRelease(SSdb *pSdb, void *pObj) {
if (pObj == NULL) return;
SSdbRow *pRow = (SSdbRow *)((char *)pObj - sizeof(SSdbRow));
- if (pRow->sdb >= SDB_MAX || pRow->sdb <= SDB_START) return;
+ if (pRow->type >= SDB_MAX || pRow->type <= SDB_START) return;
- SRWLatch *pLock = &tsSdb.locks[pRow->sdb];
+ SRWLatch *pLock = &pSdb->locks[pRow->type];
taosRLockLatch(pLock);
int32_t ref = atomic_sub_fetch_32(&pRow->refCount, 1);
@@ -231,11 +230,11 @@ void sdbRelease(void *pObj) {
taosRUnLockLatch(pLock);
}
-void *sdbFetch(ESdbType sdb, void *pIter, void **ppObj) {
- SHashObj *hash = sdbGetHash(sdb);
+void *sdbFetch(SSdb *pSdb, ESdbType type, void *pIter, void **ppObj) {
+ SHashObj *hash = sdbGetHash(pSdb, type);
if (hash == NULL) return NULL;
- SRWLatch *pLock = &tsSdb.locks[sdb];
+ SRWLatch *pLock = &pSdb->locks[type];
taosRLockLatch(pLock);
SSdbRow **ppRow = taosHashIterate(hash, ppRow);
@@ -255,23 +254,23 @@ void *sdbFetch(ESdbType sdb, void *pIter, void **ppObj) {
return ppRow;
}
-void sdbCancelFetch(void *pIter) {
+void sdbCancelFetch(SSdb *pSdb, void *pIter) {
if (pIter == NULL) return;
SSdbRow *pRow = *(SSdbRow **)pIter;
- SHashObj *hash = sdbGetHash(pRow->sdb);
+ SHashObj *hash = sdbGetHash(pSdb, pRow->type);
if (hash == NULL) return;
- SRWLatch *pLock = &tsSdb.locks[pRow->sdb];
+ SRWLatch *pLock = &pSdb->locks[pRow->type];
taosRLockLatch(pLock);
taosHashCancelIterate(hash, pIter);
taosRUnLockLatch(pLock);
}
-int32_t sdbGetSize(ESdbType sdb) {
- SHashObj *hash = sdbGetHash(sdb);
+int32_t sdbGetSize(SSdb *pSdb, ESdbType type) {
+ SHashObj *hash = sdbGetHash(pSdb, type);
if (hash == NULL) return 0;
- SRWLatch *pLock = &tsSdb.locks[sdb];
+ SRWLatch *pLock = &pSdb->locks[type];
taosRLockLatch(pLock);
int32_t size = taosHashGetSize(hash);
taosRUnLockLatch(pLock);
diff --git a/source/dnode/mnode/sdb/src/sdbRaw.c b/source/dnode/mnode/sdb/src/sdbRaw.c
index 68a0abc859..2abff74168 100644
--- a/source/dnode/mnode/sdb/src/sdbRaw.c
+++ b/source/dnode/mnode/sdb/src/sdbRaw.c
@@ -16,14 +16,14 @@
#define _DEFAULT_SOURCE
#include "sdbInt.h"
-SSdbRaw *sdbAllocRaw(ESdbType sdb, int8_t sver, int32_t dataLen) {
+SSdbRaw *sdbAllocRaw(ESdbType type, int8_t sver, int32_t dataLen) {
SSdbRaw *pRaw = calloc(1, dataLen + sizeof(SSdbRaw));
if (pRaw == NULL) {
terrno = TSDB_CODE_OUT_OF_MEMORY;
return NULL;
}
- pRaw->sdb = sdb;
+ pRaw->type = type;
pRaw->sver = sver;
pRaw->dataLen = dataLen;
return pRaw;
diff --git a/source/dnode/mnode/sdb/src/sdbRow.c b/source/dnode/mnode/sdb/src/sdbRow.c
index 68a0faa7b9..ec1dcf39e6 100644
--- a/source/dnode/mnode/sdb/src/sdbRow.c
+++ b/source/dnode/mnode/sdb/src/sdbRow.c
@@ -35,4 +35,4 @@ void *sdbGetRowObj(SSdbRow *pRow) {
return pRow->pObj;
}
-void sdbFreeRow(SSdbRow *pRow) { free(pRow); }
+void sdbFreeRow(SSdbRow *pRow) { tfree(pRow); }
diff --git a/source/libs/index/inc/index_fst.h b/source/libs/index/inc/index_fst.h
index 37feb79ac8..35858bb789 100644
--- a/source/libs/index/inc/index_fst.h
+++ b/source/libs/index/inc/index_fst.h
@@ -21,6 +21,7 @@
#include "index_fst_util.h"
#include "index_fst_registry.h"
#include "index_fst_counting_writer.h"
+#include "index_fst_automation.h"
typedef struct FstNode FstNode;
@@ -34,11 +35,28 @@ typedef struct FstRange {
typedef enum { OneTransNext, OneTrans, AnyTrans, EmptyFinal} State;
-typedef enum { Included, Excluded, Unbounded} FstBound;
typedef enum {Ordered, OutOfOrdered, DuplicateKey} OrderType;
+typedef enum { Included, Excluded, Unbounded} FstBound;
+typedef struct FstBoundWithData {
+ FstSlice data;
+ FstBound type;
+} FstBoundWithData;
+
+FstBoundWithData* fstBoundStateCreate(FstBound type, FstSlice *data);
+bool fstBoundWithDataExceededBy(FstBoundWithData *bound, FstSlice *slice);
+bool fstBoundWithDataIsEmpty(FstBoundWithData *bound);
+bool fstBoundWithDataIsIncluded(FstBoundWithData *bound);
+
+
+typedef struct FstOutput {
+ bool null;
+ Output out;
+} FstOutput;
+
+
/*
*
@@ -251,8 +269,40 @@ void fstDestroy(Fst *fst);
bool fstGet(Fst *fst, FstSlice *b, Output *out);
FstNode* fstGetNode(Fst *fst, CompiledAddr);
+FstNode* fstGetRoot(Fst *fst);
FstType fstGetType(Fst *fst);
CompiledAddr fstGetRootAddr(Fst *fst);
+
Output fstEmptyFinalOutput(Fst *fst, bool *null);
bool fstVerify(Fst *fst);
+
+
+//refactor this function
+bool fstBuilderNodeCompileTo(FstBuilderNode *b, FstCountingWriter *wrt, CompiledAddr lastAddr, CompiledAddr startAddr);
+
+
+
+
+
+typedef struct StreamState {
+ FstNode *node;
+ uint64_t trans;
+ FstOutput out;
+ void *autState;
+} StreamState;
+
+typedef struct StreamWithState {
+ Fst *fst;
+ Automation *aut;
+ SArray *inp;
+ FstOutput emptyOutput;
+ SArray *stack; //
+ FstBoundWithData *endAt;
+} StreamWithState ;
+
+typedef void* (*StreamCallback)(void *);
+StreamWithState *streamWithStateCreate(Fst *fst, Automation *automation, FstBoundWithData *min, FstBoundWithData *max) ;
+void streamWithStateDestroy(StreamWithState *sws);
+bool streamWithStateSeekMin(StreamWithState *sws, FstBoundWithData *min);
+void *streamWithStateNextWith(StreamWithState *sws, StreamCallback callback);
#endif
diff --git a/source/libs/index/inc/index_fst_automation.h b/source/libs/index/inc/index_fst_automation.h
index 7ad9a500cc..63243a0189 100644
--- a/source/libs/index/inc/index_fst_automation.h
+++ b/source/libs/index/inc/index_fst_automation.h
@@ -15,7 +15,7 @@
#ifndef __INDEX_FST_AUTAOMATION_H__
#define __INDEX_FST_AUTAOMATION_H__
-struct AutomationCtx;
+typedef struct AutomationCtx AutomationCtx;
typedef struct StartWith {
AutomationCtx *autoSelf;
@@ -23,20 +23,25 @@ typedef struct StartWith {
typedef struct Complement {
AutomationCtx *autoSelf;
+
} Complement;
// automation
typedef struct AutomationCtx {
+// automation interface
void *data;
} AutomationCtx;
-// automation interface
-void (*start)(AutomationCtx *ctx);
-bool (*isMatch)(AutomationCtx *ctx);
-bool (*canMatch)(AutomationCtx *ctx, void *data);
-bool (*willAlwaysMatch)(AutomationCtx *ctx, void *state);
-void* (*accpet)(AutomationCtx *ctx, void *state, uint8_t byte);
-void* (*accpetEof)(AutomationCtx *ctx, *state);
+typedef struct Automation {
+ void* (*start)() ;
+ bool (*isMatch)();
+ bool (*canMatch)(void *data);
+ bool (*willAlwaysMatch)(void *state);
+ void* (*accpet)(void *state, uint8_t byte);
+ void* (*accpetEof)(void *state);
+ void *data;
+} Automation;
+
#endif
diff --git a/source/libs/index/inc/index_fst_node.h b/source/libs/index/inc/index_fst_node.h
index ddd7e1f450..0645aa1158 100644
--- a/source/libs/index/inc/index_fst_node.h
+++ b/source/libs/index/inc/index_fst_node.h
@@ -41,7 +41,7 @@ FstBuilderNode *fstBuilderNodeClone(FstBuilderNode *src);
void fstBuilderNodeCloneFrom(FstBuilderNode *dst, FstBuilderNode *src);
-bool fstBuilderNodeCompileTo(FstBuilderNode *b, FstCountingWriter *wrt, CompiledAddr lastAddr, CompiledAddr startAddr);
+//bool fstBuilderNodeCompileTo(FstBuilderNode *b, FstCountingWriter *wrt, CompiledAddr lastAddr, CompiledAddr startAddr);
void fstBuilderNodeDestroy(FstBuilderNode *node);
diff --git a/source/libs/index/src/index_fst.c b/source/libs/index/src/index_fst.c
index 6c1ea8cfeb..6c777e704e 100644
--- a/source/libs/index/src/index_fst.c
+++ b/source/libs/index/src/index_fst.c
@@ -733,6 +733,11 @@ bool fstNodeCompile(FstNode *node, void *w, CompiledAddr lastAddr, CompiledAddr
return true;
}
+bool fstBuilderNodeCompileTo(FstBuilderNode *b, FstCountingWriter *wrt, CompiledAddr lastAddr, CompiledAddr startAddr) {
+ return fstNodeCompile(NULL, wrt, lastAddr, startAddr, b);
+}
+
+
FstBuilder *fstBuilderCreate(void *w, FstType ty) {
FstBuilder *b = malloc(sizeof(FstBuilder));
@@ -985,15 +990,39 @@ void fstDestroy(Fst *fst) {
}
bool fstGet(Fst *fst, FstSlice *b, Output *out) {
-
+ FstNode *root = fstGetRoot(fst);
+ Output tOut = 0;
+ for (uint32_t i = 0; i < b->dLen; i++) {
+ uint8_t inp = b->data[i];
+ Output res = 0;
+ bool null = fstNodeFindInput(root, inp, &res);
+ if (null) { return false; }
+
+ FstTransition trn;
+ fstNodeGetTransitionAt(root, res, &trn);
+ tOut += trn.out;
+ root = fstGetNode(fst, trn.addr);
+ }
+ if (!FST_NODE_IS_FINAL(root)) {
+ return false;
+ } else {
+ tOut = tOut + FST_NODE_FINAL_OUTPUT(root);
+ }
+ *out = tOut;
+
return false;
}
+FstNode *fstGetRoot(Fst *fst) {
+ CompiledAddr root = fstGetRootAddr(fst);
+ return fstGetNode(fst, root);
+}
FstNode* fstGetNode(Fst *fst, CompiledAddr addr) {
if (fst->root != NULL) {
return fst->root;
}
fst->root = fstNodeCreate(fst->meta->version, addr, fst->data);
+
return fst->root;
}
@@ -1016,15 +1045,168 @@ Output fstEmptyFinalOutput(Fst *fst, bool *null) {
return res;
}
-
bool fstVerify(Fst *fst) {
uint32_t checkSum = fst->meta->checkSum;
FstSlice *data = fst->data;
TSCKSUM initSum = 0;
- if (taosCheckChecksumWhole(data->data, data->dLen)) {
+ if (!taosCheckChecksumWhole(data->data, data->dLen)) {
return false;
}
+ return true;
+}
+
+// data bound function
+FstBoundWithData* fstBoundStateCreate(FstBound type, FstSlice *data) {
+ FstBoundWithData *b = calloc(1, sizeof(FstBoundWithData));
+ if (b == NULL) { return NULL; }
+ b->type = type;
+ b->data = fstSliceCopy(data, data->start, data->end);
+ return b;
+}
+
+bool fstBoundWithDataExceededBy(FstBoundWithData *bound, FstSlice *slice) {
+ int comp = fstSliceCompare(slice, &bound->data);
+ if (bound->type == Included) {
+ return comp > 0 ? true : false;
+ } else if (bound->type == Excluded) {
+ return comp >= 0 ? true : false;
+ } else {
+ return true;
+ }
+}
+bool fstBoundWithDataIsEmpty(FstBoundWithData *bound) {
+ if (bound->type == Unbounded) {
+ return true;
+ } else {
+ return fstSliceEmpty(&bound->data);
+ }
}
+bool fstBoundWithDataIsIncluded(FstBoundWithData *bound) {
+ return bound->type == Included ? true : false;
+}
+
+void fstBoundDestroy(FstBoundWithData *bound) {
+ free(bound);
+}
+
+StreamWithState *streamWithStateCreate(Fst *fst, Automation *automation, FstBoundWithData *min, FstBoundWithData *max) {
+ StreamWithState *sws = calloc(1, sizeof(StreamWithState));
+ if (sws == NULL) { return NULL; }
+
+ sws->fst = fst;
+ sws->aut = automation;
+ sws->inp = (SArray *)taosArrayInit(256, sizeof(uint8_t));
+
+ sws->emptyOutput.null = false;
+ sws->emptyOutput.out = 0;
+
+ sws->stack = (SArray *)taosArrayInit(256, sizeof(StreamState));
+ sws->endAt = max;
+ streamWithStateSeekMin(sws, min);
+
+ return sws;
+}
+void streamWithStateDestroy(StreamWithState *sws) {
+ if (sws == NULL) { return; }
+
+ taosArrayDestroy(sws->inp);
+ taosArrayDestroy(sws->stack);
+
+ free(sws);
+}
+
+bool streamWithStateSeekMin(StreamWithState *sws, FstBoundWithData *min) {
+ if (fstBoundWithDataIsEmpty(min)) {
+ if (fstBoundWithDataIsIncluded(min)) {
+ sws->emptyOutput.out = fstEmptyFinalOutput(sws->fst, &(sws->emptyOutput.null));
+ }
+ StreamState s = {.node = fstGetRoot(sws->fst),
+ .trans = 0,
+ .out = {.null = false, .out = 0},
+ .autState = sws->aut->start()}; // auto.start callback
+ taosArrayPush(sws->stack, &s);
+ return true;
+ }
+ FstSlice *key = NULL;
+ bool inclusize = false;;
+
+ if (min->type == Included) {
+ key = &min->data;
+ inclusize = true;
+ } else if (min->type == Excluded) {
+ key = &min->data;
+ } else {
+ return false;
+ }
+
+ FstNode *node = fstGetRoot(sws->fst);
+ Output out = 0;
+ void* autState = sws->aut->start();
+
+ for (uint32_t i = 0; i < key->dLen; i++) {
+ uint8_t b = key->data[i];
+ uint64_t res = 0;
+ bool null = fstNodeFindInput(node, b, &res);
+ if (null == false) {
+ FstTransition trn;
+ fstNodeGetTransitionAt(node, res, &trn);
+ void *preState = autState;
+ autState = sws->aut->accpet(preState, b);
+ taosArrayPush(sws->inp, &b);
+ StreamState s = {.node = node,
+ .trans = res + 1,
+ .out = {.null = false, .out = out},
+ .autState = preState};
+ taosArrayPush(sws->stack, &s);
+ out += trn.out;
+ node = fstGetNode(sws->fst, trn.addr);
+ } else {
+
+ // This is a little tricky. We're in this case if the
+ // given bound is not a prefix of any key in the FST.
+ // Since this is a minimum bound, we need to find the
+ // first transition in this node that proceeds the current
+ // input byte.
+ FstTransitions *trans = fstNodeTransitions(node);
+ uint64_t i = 0;
+ for (i = trans->range.start; i < trans->range.end; i++) {
+ FstTransition trn;
+ if (fstNodeGetTransitionAt(node, i, &trn) && trn.inp > b) {
+ break;
+ }
+ }
+
+ StreamState s = {.node = node,
+ .trans = i,
+ .out = {.null = false, .out = out},
+ .autState = autState};
+ taosArrayPush(sws->stack, &s);
+ return true;
+ }
+ }
+ uint32_t sz = taosArrayGetSize(sws->stack);
+ if (sz != 0) {
+ StreamState *s = taosArrayGet(sws->stack, sz - 1);
+ if (inclusize) {
+ s->trans -= 1;
+ taosArrayPop(sws->inp);
+ } else {
+ FstNode *n = s->node;
+ uint64_t trans = s->trans;
+ FstTransition trn;
+ fstNodeGetTransitionAt(n, trans - 1, &trn);
+ StreamState s = {.node = fstGetNode(sws->fst, trn.addr),
+ .trans= 0,
+ .out = {.null = false, .out = out},
+ .autState = autState};
+ taosArrayPush(sws->stack, &s);
+ return true;
+ }
+ return false;
+ }
+}
+
+
diff --git a/source/libs/index/src/index_fst_node.c b/source/libs/index/src/index_fst_node.c
index 5452f9cb89..b33b8e4428 100644
--- a/source/libs/index/src/index_fst_node.c
+++ b/source/libs/index/src/index_fst_node.c
@@ -59,26 +59,27 @@ void fstBuilderNodeCloneFrom(FstBuilderNode *dst, FstBuilderNode *src) {
src->trans = NULL;
}
-bool fstBuilderNodeCompileTo(FstBuilderNode *b, FstCountingWriter *wrt, CompiledAddr lastAddr, CompiledAddr startAddr) {
- size_t sz = taosArrayGetSize(b->trans);
- assert(sz < 256);
- if (FST_BUILDER_NODE_IS_FINAL(b)
- && FST_BUILDER_NODE_TRANS_ISEMPTY(b)
- && FST_BUILDER_NODE_FINALOUTPUT_ISZERO(b)) {
- return true;
- } else if (sz != 1 || b->isFinal) {
- // AnyTrans->Compile(w, addr, node);
- } else {
- FstTransition *tran = taosArrayGet(b->trans, 0);
- if (tran->addr == lastAddr && tran->out == 0) {
- //OneTransNext::compile(w, lastAddr, tran->inp);
- return true;
- } else {
- //OneTrans::Compile(w, lastAddr, *tran);
- return true;
- }
- }
- return true;
-}
+//bool fstBuilderNodeCompileTo(FstBuilderNode *b, FstCountingWriter *wrt, CompiledAddr lastAddr, CompiledAddr startAddr) {
+
+ //size_t sz = taosArrayGetSize(b->trans);
+ //assert(sz < 256);
+ //if (FST_BUILDER_NODE_IS_FINAL(b)
+ // && FST_BUILDER_NODE_TRANS_ISEMPTY(b)
+ // && FST_BUILDER_NODE_FINALOUTPUT_ISZERO(b)) {
+ // return true;
+ //} else if (sz != 1 || b->isFinal) {
+ // // AnyTrans->Compile(w, addr, node);
+ //} else {
+ // FstTransition *tran = taosArrayGet(b->trans, 0);
+ // if (tran->addr == lastAddr && tran->out == 0) {
+ // //OneTransNext::compile(w, lastAddr, tran->inp);
+ // return true;
+ // } else {
+ // //OneTrans::Compile(w, lastAddr, *tran);
+ // return true;
+ // }
+ //}
+ //return true;
+//}
diff --git a/source/libs/index/src/index_fst_util.c b/source/libs/index/src/index_fst_util.c
index 94bf650acd..952c710676 100644
--- a/source/libs/index/src/index_fst_util.c
+++ b/source/libs/index/src/index_fst_util.c
@@ -95,6 +95,7 @@ FstSlice fstSliceCreate(uint8_t *data, uint64_t dLen) {
FstSlice slice = {.data = data, .dLen = dLen, .start = 0, .end = dLen - 1};
return slice;
}
+// just shallow copy
FstSlice fstSliceCopy(FstSlice *slice, int32_t start, int32_t end) {
FstSlice t;
if (start >= slice->dLen || end >= slice->dLen || start > end) {