Merge branch '3.0' into feature/vnode
This commit is contained in:
commit
81ebcd8bf5
|
@ -13,8 +13,8 @@
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef _TD_MNODE_H_
|
#ifndef _TD_MND_H_
|
||||||
#define _TD_MNODE_H_
|
#define _TD_MND_H_
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
extern "C" {
|
extern "C" {
|
||||||
|
@ -30,28 +30,132 @@ typedef void (*SendRedirectMsgFp)(SDnode *pDnode, struct SRpcMsg *rpcMsg);
|
||||||
typedef int32_t (*PutMsgToMnodeQFp)(SDnode *pDnode, SMnodeMsg *pMsg);
|
typedef int32_t (*PutMsgToMnodeQFp)(SDnode *pDnode, SMnodeMsg *pMsg);
|
||||||
|
|
||||||
typedef struct SMnodeLoad {
|
typedef struct SMnodeLoad {
|
||||||
|
/**
|
||||||
|
* @brief the number of dnodes in cluster.
|
||||||
|
*
|
||||||
|
*/
|
||||||
int64_t numOfDnode;
|
int64_t numOfDnode;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief the number of mnodes in cluster.
|
||||||
|
*
|
||||||
|
*/
|
||||||
int64_t numOfMnode;
|
int64_t numOfMnode;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief the number of vgroups in cluster.
|
||||||
|
*
|
||||||
|
*/
|
||||||
int64_t numOfVgroup;
|
int64_t numOfVgroup;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief the number of databases in cluster.
|
||||||
|
*
|
||||||
|
*/
|
||||||
int64_t numOfDatabase;
|
int64_t numOfDatabase;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief the number of super tables in cluster.
|
||||||
|
*
|
||||||
|
*/
|
||||||
int64_t numOfSuperTable;
|
int64_t numOfSuperTable;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief the number of child tables in cluster.
|
||||||
|
*
|
||||||
|
*/
|
||||||
int64_t numOfChildTable;
|
int64_t numOfChildTable;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief the number of normal tables in cluster.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
int64_t numOfNormalTable;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief the number of numOfTimeseries in cluster.
|
||||||
|
*
|
||||||
|
*/
|
||||||
int64_t numOfColumn;
|
int64_t numOfColumn;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief total points written in cluster.
|
||||||
|
*
|
||||||
|
*/
|
||||||
int64_t totalPoints;
|
int64_t totalPoints;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief total storage in cluster.
|
||||||
|
*
|
||||||
|
*/
|
||||||
int64_t totalStorage;
|
int64_t totalStorage;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief total compressed storage in cluster.
|
||||||
|
*
|
||||||
|
*/
|
||||||
int64_t compStorage;
|
int64_t compStorage;
|
||||||
} SMnodeLoad;
|
} SMnodeLoad;
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
int32_t dnodeId;
|
/**
|
||||||
int64_t clusterId;
|
* @brief dnodeId of this mnode.
|
||||||
int8_t replica;
|
*
|
||||||
int8_t selfIndex;
|
*/
|
||||||
SReplica replicas[TSDB_MAX_REPLICA];
|
int32_t dnodeId;
|
||||||
struct SDnode *pDnode;
|
|
||||||
PutMsgToMnodeQFp putMsgToApplyMsgFp;
|
/**
|
||||||
SendMsgToDnodeFp sendMsgToDnodeFp;
|
* @brief clusterId of this mnode.
|
||||||
SendMsgToMnodeFp sendMsgToMnodeFp;
|
*
|
||||||
|
*/
|
||||||
|
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;
|
SendRedirectMsgFp sendRedirectMsgFp;
|
||||||
} SMnodeOpt;
|
} SMnodeOpt;
|
||||||
|
|
||||||
|
@ -59,119 +163,115 @@ typedef struct {
|
||||||
/**
|
/**
|
||||||
* @brief Open a mnode.
|
* @brief Open a mnode.
|
||||||
*
|
*
|
||||||
* @param path Path of the mnode
|
* @param path Path of the mnode.
|
||||||
* @param pOption Option of the mnode
|
* @param pOption Option of the mnode.
|
||||||
* @return SMnode* The mnode object
|
* @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 pMnode The mnode object to close.
|
||||||
* @param pOption Options of the mnode
|
* @param pOption Options of the mnode.
|
||||||
* @return int32_t 0 for success, -1 for failure
|
* @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.
|
* @brief Drop a mnode.
|
||||||
*
|
*
|
||||||
* @param path Path of the 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.
|
* @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 user
|
||||||
* @param spi
|
* @param spi
|
||||||
* @param encrypt
|
* @param encrypt
|
||||||
* @param secret
|
* @param secret
|
||||||
* @param ckey
|
* @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 pMnode The mnode object.
|
||||||
* @param pMsg The request rpc msg
|
* @param pMsg The request rpc msg.
|
||||||
* @return int32_t The created mnode 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 pMsg The request msg.
|
||||||
* @param code The error code
|
* @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.
|
||||||
* @param pMsg The request msg
|
* @return int32_t 0 for success, -1 for failure.
|
||||||
* @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.
|
||||||
* @param pMsg The request msg
|
* @return int32_t 0 for success, -1 for failure.
|
||||||
* @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.
|
||||||
* @param pMsg The request msg
|
* @return int32_t 0 for success, -1 for failure.
|
||||||
* @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.
|
||||||
* @param pMsg The request msg
|
* @return int32_t 0 for success, -1 for failure.
|
||||||
* @return int32_t 0 for success, -1 for failure
|
|
||||||
*/
|
*/
|
||||||
void mnodeProcessApplyMsg(SMnode *pMnode, SMnodeMsg *pMsg);
|
void mndProcessApplyMsg(SMnodeMsg *pMsg);
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#endif /*_TD_MNODE_H_*/
|
#endif /*_TD_MND_H_*/
|
||||||
|
|
|
@ -114,56 +114,181 @@ typedef enum {
|
||||||
SDB_START = 0,
|
SDB_START = 0,
|
||||||
SDB_TRANS = 1,
|
SDB_TRANS = 1,
|
||||||
SDB_CLUSTER = 2,
|
SDB_CLUSTER = 2,
|
||||||
SDB_DNODE = 3,
|
SDB_MNODE = 3,
|
||||||
SDB_MNODE = 4,
|
SDB_DNODE = 4,
|
||||||
SDB_USER = 5,
|
SDB_USER = 5,
|
||||||
SDB_AUTH = 6,
|
SDB_AUTH = 6,
|
||||||
SDB_ACCT = 7,
|
SDB_ACCT = 7,
|
||||||
SDB_DB = 8,
|
|
||||||
SDB_VGROUP = 9,
|
SDB_VGROUP = 9,
|
||||||
SDB_STABLE = 10,
|
SDB_STABLE = 9,
|
||||||
|
SDB_DB = 10,
|
||||||
SDB_FUNC = 11,
|
SDB_FUNC = 11,
|
||||||
SDB_MAX = 12
|
SDB_MAX = 12
|
||||||
} ESdbType;
|
} ESdbType;
|
||||||
|
|
||||||
typedef int32_t (*SdbInsertFp)(void *pObj);
|
typedef struct SSdb SSdb;
|
||||||
typedef int32_t (*SdbUpdateFp)(void *pSrcObj, void *pDstObj);
|
typedef int32_t (*SdbInsertFp)(SSdb *pSdb, void *pObj);
|
||||||
typedef int32_t (*SdbDeleteFp)(void *pObj);
|
typedef int32_t (*SdbUpdateFp)(SSdb *pSdb, void *pSrcObj, void *pDstObj);
|
||||||
typedef int32_t (*SdbDeployFp)();
|
typedef int32_t (*SdbDeleteFp)(SSdb *pSdb, void *pObj);
|
||||||
|
typedef int32_t (*SdbDeployFp)(SSdb *pSdb);
|
||||||
typedef SSdbRow *(*SdbDecodeFp)(SSdbRaw *pRaw);
|
typedef SSdbRow *(*SdbDecodeFp)(SSdbRaw *pRaw);
|
||||||
typedef SSdbRaw *(*SdbEncodeFp)(void *pObj);
|
typedef SSdbRaw *(*SdbEncodeFp)(void *pObj);
|
||||||
|
|
||||||
typedef struct {
|
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;
|
SdbDeployFp deployFp;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Encode one row of the table into rawdata.
|
||||||
|
*
|
||||||
|
*/
|
||||||
SdbEncodeFp encodeFp;
|
SdbEncodeFp encodeFp;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Decode one row of the table from rawdata.
|
||||||
|
*
|
||||||
|
*/
|
||||||
SdbDecodeFp decodeFp;
|
SdbDecodeFp decodeFp;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief The callback function when insert a row to sdb.
|
||||||
|
*
|
||||||
|
*/
|
||||||
SdbInsertFp insertFp;
|
SdbInsertFp insertFp;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief The callback function when undate a row in sdb.
|
||||||
|
*
|
||||||
|
*/
|
||||||
SdbUpdateFp updateFp;
|
SdbUpdateFp updateFp;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief The callback function when delete a row from sdb.
|
||||||
|
*
|
||||||
|
*/
|
||||||
SdbDeleteFp deleteFp;
|
SdbDeleteFp deleteFp;
|
||||||
} SSdbTable;
|
} SSdbTable;
|
||||||
|
|
||||||
typedef struct SSdb SSdb;
|
typedef struct SSdbOpt {
|
||||||
|
/**
|
||||||
|
* @brief The path of the sdb file.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
const char *path;
|
||||||
|
} SSdbOpt;
|
||||||
|
|
||||||
int32_t sdbInit();
|
/**
|
||||||
void sdbCleanup();
|
* @brief Initialize and start the sdb.
|
||||||
void sdbSetTable(SSdbTable table);
|
*
|
||||||
|
* @param pOption Option of the sdb.
|
||||||
|
* @return SSdb* The sdb object.
|
||||||
|
*/
|
||||||
|
SSdb *sdbInit(SSdbOpt *pOption);
|
||||||
|
|
||||||
int32_t sdbOpen();
|
/**
|
||||||
void sdbClose();
|
* @brief Stop and cleanup the sdb.
|
||||||
int32_t sdbWrite(SSdbRaw *pRaw);
|
*
|
||||||
|
* @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);
|
* @brief Set the initial rows of sdb.
|
||||||
void *sdbFetch(ESdbType sdb, void *pIter, void **ppObj);
|
*
|
||||||
void sdbCancelFetch(void *pIter);
|
* @param pSdb The sdb object.
|
||||||
int32_t sdbGetSize(ESdbType sdb);
|
* @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);
|
void sdbFreeRaw(SSdbRaw *pRaw);
|
||||||
int32_t sdbSetRawInt8(SSdbRaw *pRaw, int32_t dataPos, int8_t val);
|
int32_t sdbSetRawInt8(SSdbRaw *pRaw, int32_t dataPos, int8_t val);
|
||||||
int32_t sdbSetRawInt32(SSdbRaw *pRaw, int32_t dataPos, int32_t val);
|
int32_t sdbSetRawInt32(SSdbRaw *pRaw, int32_t dataPos, int32_t val);
|
||||||
|
|
|
@ -12,5 +12,5 @@ target_link_libraries(
|
||||||
target_include_directories(
|
target_include_directories(
|
||||||
dnode
|
dnode
|
||||||
PUBLIC "${CMAKE_SOURCE_DIR}/include/dnode/mgmt"
|
PUBLIC "${CMAKE_SOURCE_DIR}/include/dnode/mgmt"
|
||||||
private "${CMAKE_CURRENT_SOURCE_DIR}/inc"
|
PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/inc"
|
||||||
)
|
)
|
||||||
|
|
|
@ -18,32 +18,27 @@
|
||||||
#include "dndTransport.h"
|
#include "dndTransport.h"
|
||||||
#include "dndVnodes.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) {
|
int32_t dndGetDnodeId(SDnode *pDnode) {
|
||||||
dndRLockDnode(pDnode);
|
SDnodeMgmt *pMgmt = &pDnode->dmgmt;
|
||||||
int32_t dnodeId = pDnode->dmgmt.dnodeId;
|
taosRLockLatch(&pMgmt->latch);
|
||||||
dndRUnLockDnode(pDnode);
|
int32_t dnodeId = pMgmt->dnodeId;
|
||||||
|
taosRUnLockLatch(&pMgmt->latch);
|
||||||
return dnodeId;
|
return dnodeId;
|
||||||
}
|
}
|
||||||
|
|
||||||
int64_t dndGetClusterId(SDnode *pDnode) {
|
int64_t dndGetClusterId(SDnode *pDnode) {
|
||||||
dndRLockDnode(pDnode);
|
SDnodeMgmt *pMgmt = &pDnode->dmgmt;
|
||||||
int64_t clusterId = pDnode->dmgmt.clusterId;
|
taosRLockLatch(&pMgmt->latch);
|
||||||
dndRUnLockDnode(pDnode);
|
int64_t clusterId = pMgmt->clusterId;
|
||||||
|
taosRUnLockLatch(&pMgmt->latch);
|
||||||
return clusterId;
|
return clusterId;
|
||||||
}
|
}
|
||||||
|
|
||||||
void dndGetDnodeEp(SDnode *pDnode, int32_t dnodeId, char *pEp, char *pFqdn, uint16_t *pPort) {
|
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 (pDnodeEp != NULL) {
|
||||||
if (pPort != NULL) {
|
if (pPort != NULL) {
|
||||||
*pPort = pDnodeEp->port;
|
*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) {
|
void dndGetMnodeEpSet(SDnode *pDnode, SEpSet *pEpSet) {
|
||||||
dndRLockDnode(pDnode);
|
SDnodeMgmt *pMgmt = &pDnode->dmgmt;
|
||||||
*pEpSet = pDnode->dmgmt.mnodeEpSet;
|
taosRLockLatch(&pMgmt->latch);
|
||||||
dndRUnLockDnode(pDnode);
|
*pEpSet = pMgmt->mnodeEpSet;
|
||||||
|
taosRUnLockLatch(&pMgmt->latch);
|
||||||
}
|
}
|
||||||
|
|
||||||
void dndSendRedirectMsg(SDnode *pDnode, SRpcMsg *pMsg) {
|
void dndSendRedirectMsg(SDnode *pDnode, SRpcMsg *pMsg) {
|
||||||
|
@ -87,14 +83,15 @@ void dndSendRedirectMsg(SDnode *pDnode, SRpcMsg *pMsg) {
|
||||||
static void dndUpdateMnodeEpSet(SDnode *pDnode, SEpSet *pEpSet) {
|
static void dndUpdateMnodeEpSet(SDnode *pDnode, SEpSet *pEpSet) {
|
||||||
dInfo("mnode is changed, num:%d inUse:%d", pEpSet->numOfEps, pEpSet->inUse);
|
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) {
|
for (int32_t i = 0; i < pEpSet->numOfEps; ++i) {
|
||||||
dInfo("mnode index:%d %s:%u", i, pEpSet->fqdn[i], pEpSet->port[i]);
|
dInfo("mnode index:%d %s:%u", i, pEpSet->fqdn[i], pEpSet->port[i]);
|
||||||
}
|
}
|
||||||
|
|
||||||
dndWUnLockDnode(pDnode);
|
taosWUnLockLatch(&pMgmt->latch);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void dndPrintDnodes(SDnode *pDnode) {
|
static void dndPrintDnodes(SDnode *pDnode) {
|
||||||
|
@ -124,12 +121,14 @@ static void dndResetDnodes(SDnode *pDnode, SDnodeEps *pDnodeEps) {
|
||||||
}
|
}
|
||||||
|
|
||||||
pMgmt->mnodeEpSet.inUse = 0;
|
pMgmt->mnodeEpSet.inUse = 0;
|
||||||
|
pMgmt->mnodeEpSet.numOfEps = 0;
|
||||||
|
|
||||||
int32_t mIndex = 0;
|
int32_t mIndex = 0;
|
||||||
for (int32_t i = 0; i < pMgmt->dnodeEps->num; i++) {
|
for (int32_t i = 0; i < pMgmt->dnodeEps->num; i++) {
|
||||||
SDnodeEp *pDnodeEp = &pMgmt->dnodeEps->eps[i];
|
SDnodeEp *pDnodeEp = &pMgmt->dnodeEps->eps[i];
|
||||||
if (!pDnodeEp->isMnode) continue;
|
if (!pDnodeEp->isMnode) continue;
|
||||||
if (mIndex >= TSDB_MAX_REPLICA) continue;
|
if (mIndex >= TSDB_MAX_REPLICA) continue;
|
||||||
|
pMgmt->mnodeEpSet.numOfEps++;
|
||||||
strcpy(pMgmt->mnodeEpSet.fqdn[mIndex], pDnodeEp->fqdn);
|
strcpy(pMgmt->mnodeEpSet.fqdn[mIndex], pDnodeEp->fqdn);
|
||||||
pMgmt->mnodeEpSet.port[mIndex] = pDnodeEp->port;
|
pMgmt->mnodeEpSet.port[mIndex] = pDnodeEp->port;
|
||||||
mIndex++;
|
mIndex++;
|
||||||
|
@ -145,16 +144,18 @@ static void dndResetDnodes(SDnode *pDnode, SDnodeEps *pDnodeEps) {
|
||||||
|
|
||||||
static bool dndIsEpChanged(SDnode *pDnode, int32_t dnodeId, char *pEp) {
|
static bool dndIsEpChanged(SDnode *pDnode, int32_t dnodeId, char *pEp) {
|
||||||
bool changed = false;
|
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) {
|
if (pDnodeEp != NULL) {
|
||||||
char epstr[TSDB_EP_LEN + 1];
|
char epstr[TSDB_EP_LEN + 1];
|
||||||
snprintf(epstr, TSDB_EP_LEN, "%s:%u", pDnodeEp->fqdn, pDnodeEp->port);
|
snprintf(epstr, TSDB_EP_LEN, "%s:%u", pDnodeEp->fqdn, pDnodeEp->port);
|
||||||
changed = strcmp(pEp, epstr) != 0;
|
changed = strcmp(pEp, epstr) != 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
dndRUnLockDnode(pDnode);
|
taosRUnLockLatch(&pMgmt->latch);
|
||||||
return changed;
|
return changed;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -280,6 +281,7 @@ PRASE_DNODE_OVER:
|
||||||
if (pMgmt->dnodeEps == NULL) {
|
if (pMgmt->dnodeEps == NULL) {
|
||||||
pMgmt->dnodeEps = calloc(1, sizeof(SDnodeEps) + sizeof(SDnodeEp));
|
pMgmt->dnodeEps = calloc(1, sizeof(SDnodeEps) + sizeof(SDnodeEp));
|
||||||
pMgmt->dnodeEps->num = 1;
|
pMgmt->dnodeEps->num = 1;
|
||||||
|
pMgmt->dnodeEps->eps[0].isMnode = 1;
|
||||||
pMgmt->dnodeEps->eps[0].port = pDnode->opt.serverPort;
|
pMgmt->dnodeEps->eps[0].port = pDnode->opt.serverPort;
|
||||||
tstrncpy(pMgmt->dnodeEps->eps[0].fqdn, pDnode->opt.localFqdn, TSDB_FQDN_LEN);
|
tstrncpy(pMgmt->dnodeEps->eps[0].fqdn, pDnode->opt.localFqdn, TSDB_FQDN_LEN);
|
||||||
}
|
}
|
||||||
|
@ -342,11 +344,14 @@ static void dndSendStatusMsg(SDnode *pDnode) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
dndRLockDnode(pDnode);
|
bool changed = false;
|
||||||
|
|
||||||
|
SDnodeMgmt *pMgmt = &pDnode->dmgmt;
|
||||||
|
taosRLockLatch(&pMgmt->latch);
|
||||||
pStatus->sversion = htonl(pDnode->opt.sver);
|
pStatus->sversion = htonl(pDnode->opt.sver);
|
||||||
pStatus->dnodeId = htonl(pDnode->dmgmt.dnodeId);
|
pStatus->dnodeId = htonl(pMgmt->dnodeId);
|
||||||
pStatus->clusterId = htobe64(pDnode->dmgmt.clusterId);
|
pStatus->clusterId = htobe64(pMgmt->clusterId);
|
||||||
pStatus->rebootTime = htonl(pDnode->dmgmt.rebootTime);
|
pStatus->rebootTime = htonl(pMgmt->rebootTime);
|
||||||
pStatus->numOfCores = htonl(pDnode->opt.numOfCores);
|
pStatus->numOfCores = htonl(pDnode->opt.numOfCores);
|
||||||
tstrncpy(pStatus->dnodeEp, pDnode->opt.localEp, TSDB_EP_LEN);
|
tstrncpy(pStatus->dnodeEp, pDnode->opt.localEp, TSDB_EP_LEN);
|
||||||
pStatus->clusterCfg.statusInterval = htonl(pDnode->opt.statusInterval);
|
pStatus->clusterCfg.statusInterval = htonl(pDnode->opt.statusInterval);
|
||||||
|
@ -356,7 +361,7 @@ static void dndSendStatusMsg(SDnode *pDnode) {
|
||||||
pStatus->clusterCfg.checkTime = 0;
|
pStatus->clusterCfg.checkTime = 0;
|
||||||
char timestr[32] = "1970-01-01 00:00:00.00";
|
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);
|
(void)taosParseTime(timestr, &pStatus->clusterCfg.checkTime, (int32_t)strlen(timestr), TSDB_TIME_PRECISION_MILLI, 0);
|
||||||
dndRUnLockDnode(pDnode);
|
taosRUnLockLatch(&pMgmt->latch);
|
||||||
|
|
||||||
dndGetVnodeLoads(pDnode, &pStatus->vnodeLoads);
|
dndGetVnodeLoads(pDnode, &pStatus->vnodeLoads);
|
||||||
contLen = sizeof(SStatusMsg) + pStatus->vnodeLoads.num * sizeof(SVnodeLoad);
|
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) {
|
if (pMgmt->dnodeId == 0 || pMgmt->dropped != pCfg->dropped) {
|
||||||
dInfo("set dnodeId:%d clusterId:%" PRId64 " dropped:%d", pCfg->dnodeId, pCfg->clusterId, 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->dnodeId = pCfg->dnodeId;
|
||||||
pMgmt->clusterId = pCfg->clusterId;
|
pMgmt->clusterId = pCfg->clusterId;
|
||||||
pMgmt->dropped = pCfg->dropped;
|
pMgmt->dropped = pCfg->dropped;
|
||||||
(void)dndWriteDnodes(pDnode);
|
(void)dndWriteDnodes(pDnode);
|
||||||
dndWUnLockDnode(pDnode);
|
taosWUnLockLatch(&pMgmt->latch);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void dndUpdateDnodeEps(SDnode *pDnode, SDnodeEps *pDnodeEps) {
|
static void dndUpdateDnodeEps(SDnode *pDnode, SDnodeEps *pDnodeEps) {
|
||||||
if (pDnodeEps == NULL || pDnodeEps->num <= 0) return;
|
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);
|
dndResetDnodes(pDnode, pDnodeEps);
|
||||||
dndWriteDnodes(pDnode);
|
dndWriteDnodes(pDnode);
|
||||||
} else {
|
} else {
|
||||||
int32_t size = pDnodeEps->num * sizeof(SDnodeEp) + sizeof(SDnodeEps);
|
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);
|
dndResetDnodes(pDnode, pDnodeEps);
|
||||||
dndWriteDnodes(pDnode);
|
dndWriteDnodes(pDnode);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
dndWUnLockDnode(pDnode);
|
taosWUnLockLatch(&pMgmt->latch);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void dndProcessStatusRsp(SDnode *pDnode, SRpcMsg *pMsg, SEpSet *pEpSet) {
|
static void dndProcessStatusRsp(SDnode *pDnode, SRpcMsg *pMsg, SEpSet *pEpSet) {
|
||||||
|
@ -458,7 +464,7 @@ static void *dnodeThreadRoutine(void *param) {
|
||||||
pthread_testcancel();
|
pthread_testcancel();
|
||||||
|
|
||||||
if (dndGetStat(pDnode) == DND_STAT_RUNNING) {
|
if (dndGetStat(pDnode) == DND_STAT_RUNNING) {
|
||||||
dndSendStatusMsg(pDnode);
|
// dndSendStatusMsg(pDnode);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -512,7 +518,7 @@ void dndCleanupDnode(SDnode *pDnode) {
|
||||||
pMgmt->threadId = NULL;
|
pMgmt->threadId = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
dndWLockDnode(pDnode);
|
taosWLockLatch(&pMgmt->latch);
|
||||||
|
|
||||||
if (pMgmt->dnodeEps != NULL) {
|
if (pMgmt->dnodeEps != NULL) {
|
||||||
free(pMgmt->dnodeEps);
|
free(pMgmt->dnodeEps);
|
||||||
|
@ -529,7 +535,7 @@ void dndCleanupDnode(SDnode *pDnode) {
|
||||||
pMgmt->file = NULL;
|
pMgmt->file = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
dndWUnLockDnode(pDnode);
|
taosWUnLockLatch(&pMgmt->latch);
|
||||||
dInfo("dnode-dnode is cleaned up");
|
dInfo("dnode-dnode is cleaned up");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -80,7 +80,9 @@ static SMnode *dndAcquireMnode(SDnode *pDnode) {
|
||||||
}
|
}
|
||||||
taosRUnLockLatch(&pMgmt->latch);
|
taosRUnLockLatch(&pMgmt->latch);
|
||||||
|
|
||||||
dTrace("acquire mnode, refCount:%d", refCount);
|
if (pMnode != NULL) {
|
||||||
|
dTrace("acquire mnode, refCount:%d", refCount);
|
||||||
|
}
|
||||||
return pMnode;
|
return pMnode;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -94,7 +96,9 @@ static void dndReleaseMnode(SDnode *pDnode, SMnode *pMnode) {
|
||||||
}
|
}
|
||||||
taosRUnLockLatch(&pMgmt->latch);
|
taosRUnLockLatch(&pMgmt->latch);
|
||||||
|
|
||||||
dTrace("release mnode, refCount:%d", refCount);
|
if (pMnode != NULL) {
|
||||||
|
dTrace("release mnode, refCount:%d", refCount);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static int32_t dndReadMnodeFile(SDnode *pDnode) {
|
static int32_t dndReadMnodeFile(SDnode *pDnode) {
|
||||||
|
@ -360,13 +364,13 @@ static int32_t dndBuildMnodeOptionFromMsg(SDnode *pDnode, SMnodeOpt *pOption, SC
|
||||||
|
|
||||||
pOption->replica = pMsg->replica;
|
pOption->replica = pMsg->replica;
|
||||||
pOption->selfIndex = -1;
|
pOption->selfIndex = -1;
|
||||||
for (int32_t index = 0; index < pMsg->replica; ++index) {
|
for (int32_t i = 0; i < pMsg->replica; ++i) {
|
||||||
SReplica *pReplica = &pOption->replicas[index];
|
SReplica *pReplica = &pOption->replicas[i];
|
||||||
pReplica->id = pMsg->replicas[index].id;
|
pReplica->id = pMsg->replicas[i].id;
|
||||||
pReplica->port = pMsg->replicas[index].port;
|
pReplica->port = pMsg->replicas[i].port;
|
||||||
tstrncpy(pReplica->fqdn, pMsg->replicas[index].fqdn, TSDB_FQDN_LEN);
|
tstrncpy(pReplica->fqdn, pMsg->replicas[i].fqdn, TSDB_FQDN_LEN);
|
||||||
if (pReplica->id == pOption->dnodeId) {
|
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;
|
return code;
|
||||||
}
|
}
|
||||||
|
|
||||||
SMnode *pMnode = mnodeOpen(pDnode->dir.mnode, pOption);
|
SMnode *pMnode = mndOpen(pDnode->dir.mnode, pOption);
|
||||||
if (pMnode == NULL) {
|
if (pMnode == NULL) {
|
||||||
dError("failed to open mnode since %s", terrstr());
|
dError("failed to open mnode since %s", terrstr());
|
||||||
code = terrno;
|
code = terrno;
|
||||||
|
@ -405,8 +409,8 @@ static int32_t dndOpenMnode(SDnode *pDnode, SMnodeOpt *pOption) {
|
||||||
dError("failed to write mnode file since %s", terrstr());
|
dError("failed to write mnode file since %s", terrstr());
|
||||||
code = terrno;
|
code = terrno;
|
||||||
dndStopMnodeWorker(pDnode);
|
dndStopMnodeWorker(pDnode);
|
||||||
mnodeClose(pMnode);
|
mndClose(pMnode);
|
||||||
mnodeDestroy(pDnode->dir.mnode);
|
mndDestroy(pDnode->dir.mnode);
|
||||||
terrno = code;
|
terrno = code;
|
||||||
return code;
|
return code;
|
||||||
}
|
}
|
||||||
|
@ -428,7 +432,7 @@ static int32_t dndAlterMnode(SDnode *pDnode, SMnodeOpt *pOption) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (mnodeAlter(pMnode, pOption) != 0) {
|
if (mndAlter(pMnode, pOption) != 0) {
|
||||||
dError("failed to alter mnode since %s", terrstr());
|
dError("failed to alter mnode since %s", terrstr());
|
||||||
dndReleaseMnode(pDnode, pMnode);
|
dndReleaseMnode(pDnode, pMnode);
|
||||||
return -1;
|
return -1;
|
||||||
|
@ -463,8 +467,8 @@ static int32_t dndDropMnode(SDnode *pDnode) {
|
||||||
|
|
||||||
dndStopMnodeWorker(pDnode);
|
dndStopMnodeWorker(pDnode);
|
||||||
dndWriteMnodeFile(pDnode);
|
dndWriteMnodeFile(pDnode);
|
||||||
mnodeClose(pMnode);
|
mndClose(pMnode);
|
||||||
mnodeDestroy(pDnode->dir.mnode);
|
mndDestroy(pDnode->dir.mnode);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -491,6 +495,7 @@ static int32_t dndProcessCreateMnodeReq(SDnode *pDnode, SRpcMsg *pRpcMsg) {
|
||||||
if (dndBuildMnodeOptionFromMsg(pDnode, &option, pMsg) != 0) {
|
if (dndBuildMnodeOptionFromMsg(pDnode, &option, pMsg) != 0) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
return dndOpenMnode(pDnode, &option);
|
return dndOpenMnode(pDnode, &option);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -550,13 +555,13 @@ static void dndProcessMnodeReadQueue(SDnode *pDnode, SMnodeMsg *pMsg) {
|
||||||
|
|
||||||
SMnode *pMnode = dndAcquireMnode(pDnode);
|
SMnode *pMnode = dndAcquireMnode(pDnode);
|
||||||
if (pMnode != NULL) {
|
if (pMnode != NULL) {
|
||||||
mnodeProcessReadMsg(pMnode, pMsg);
|
mndProcessReadMsg(pMsg);
|
||||||
dndReleaseMnode(pDnode, pMnode);
|
dndReleaseMnode(pDnode, pMnode);
|
||||||
} else {
|
} else {
|
||||||
mnodeSendRsp(pMsg, terrno);
|
mndSendRsp(pMsg, terrno);
|
||||||
}
|
}
|
||||||
|
|
||||||
mnodeCleanupMsg(pMsg);
|
mndCleanupMsg(pMsg);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void dndProcessMnodeWriteQueue(SDnode *pDnode, SMnodeMsg *pMsg) {
|
static void dndProcessMnodeWriteQueue(SDnode *pDnode, SMnodeMsg *pMsg) {
|
||||||
|
@ -564,13 +569,13 @@ static void dndProcessMnodeWriteQueue(SDnode *pDnode, SMnodeMsg *pMsg) {
|
||||||
|
|
||||||
SMnode *pMnode = dndAcquireMnode(pDnode);
|
SMnode *pMnode = dndAcquireMnode(pDnode);
|
||||||
if (pMnode != NULL) {
|
if (pMnode != NULL) {
|
||||||
mnodeProcessWriteMsg(pMnode, pMsg);
|
mndProcessWriteMsg(pMsg);
|
||||||
dndReleaseMnode(pDnode, pMnode);
|
dndReleaseMnode(pDnode, pMnode);
|
||||||
} else {
|
} else {
|
||||||
mnodeSendRsp(pMsg, terrno);
|
mndSendRsp(pMsg, terrno);
|
||||||
}
|
}
|
||||||
|
|
||||||
mnodeCleanupMsg(pMsg);
|
mndCleanupMsg(pMsg);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void dndProcessMnodeApplyQueue(SDnode *pDnode, SMnodeMsg *pMsg) {
|
static void dndProcessMnodeApplyQueue(SDnode *pDnode, SMnodeMsg *pMsg) {
|
||||||
|
@ -578,13 +583,13 @@ static void dndProcessMnodeApplyQueue(SDnode *pDnode, SMnodeMsg *pMsg) {
|
||||||
|
|
||||||
SMnode *pMnode = dndAcquireMnode(pDnode);
|
SMnode *pMnode = dndAcquireMnode(pDnode);
|
||||||
if (pMnode != NULL) {
|
if (pMnode != NULL) {
|
||||||
mnodeProcessApplyMsg(pMnode, pMsg);
|
mndProcessApplyMsg(pMsg);
|
||||||
dndReleaseMnode(pDnode, pMnode);
|
dndReleaseMnode(pDnode, pMnode);
|
||||||
} else {
|
} else {
|
||||||
mnodeSendRsp(pMsg, terrno);
|
mndSendRsp(pMsg, terrno);
|
||||||
}
|
}
|
||||||
|
|
||||||
mnodeCleanupMsg(pMsg);
|
mndCleanupMsg(pMsg);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void dndProcessMnodeSyncQueue(SDnode *pDnode, SMnodeMsg *pMsg) {
|
static void dndProcessMnodeSyncQueue(SDnode *pDnode, SMnodeMsg *pMsg) {
|
||||||
|
@ -592,26 +597,26 @@ static void dndProcessMnodeSyncQueue(SDnode *pDnode, SMnodeMsg *pMsg) {
|
||||||
|
|
||||||
SMnode *pMnode = dndAcquireMnode(pDnode);
|
SMnode *pMnode = dndAcquireMnode(pDnode);
|
||||||
if (pMnode != NULL) {
|
if (pMnode != NULL) {
|
||||||
mnodeProcessSyncMsg(pMnode, pMsg);
|
mndProcessSyncMsg(pMsg);
|
||||||
dndReleaseMnode(pDnode, pMnode);
|
dndReleaseMnode(pDnode, pMnode);
|
||||||
} else {
|
} else {
|
||||||
mnodeSendRsp(pMsg, terrno);
|
mndSendRsp(pMsg, terrno);
|
||||||
}
|
}
|
||||||
|
|
||||||
mnodeCleanupMsg(pMsg);
|
mndCleanupMsg(pMsg);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int32_t dndWriteMnodeMsgToQueue(SMnode *pMnode, taos_queue pQueue, SRpcMsg *pRpcMsg) {
|
static int32_t dndWriteMnodeMsgToQueue(SMnode *pMnode, taos_queue pQueue, SRpcMsg *pRpcMsg) {
|
||||||
assert(pQueue);
|
assert(pQueue);
|
||||||
|
|
||||||
SMnodeMsg *pMsg = mnodeInitMsg(pMnode, pRpcMsg);
|
SMnodeMsg *pMsg = mndInitMsg(pMnode, pRpcMsg);
|
||||||
if (pMsg == NULL) {
|
if (pMsg == NULL) {
|
||||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (taosWriteQitem(pQueue, pMsg) != 0) {
|
if (taosWriteQitem(pQueue, pMsg) != 0) {
|
||||||
mnodeCleanupMsg(pMsg);
|
mndCleanupMsg(pMsg);
|
||||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
@ -683,7 +688,7 @@ static int32_t dndPutMsgIntoMnodeApplyQueue(SDnode *pDnode, SMnodeMsg *pMsg) {
|
||||||
|
|
||||||
static int32_t dndAllocMnodeMgmtQueue(SDnode *pDnode) {
|
static int32_t dndAllocMnodeMgmtQueue(SDnode *pDnode) {
|
||||||
SMnodeMgmt *pMgmt = &pDnode->mmgmt;
|
SMnodeMgmt *pMgmt = &pDnode->mmgmt;
|
||||||
pMgmt->pMgmtQ = tWorkerAllocQueue(&pMgmt->mgmtPool, NULL, (FProcessItem)dndProcessMnodeMgmtQueue);
|
pMgmt->pMgmtQ = tWorkerAllocQueue(&pMgmt->mgmtPool, pDnode, (FProcessItem)dndProcessMnodeMgmtQueue);
|
||||||
if (pMgmt->pMgmtQ == NULL) {
|
if (pMgmt->pMgmtQ == NULL) {
|
||||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||||
return -1;
|
return -1;
|
||||||
|
@ -708,18 +713,19 @@ static int32_t dndInitMnodeMgmtWorker(SDnode *pDnode) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
dDebug("mnode mgmt worker is initialized");
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void dndCleanupMnodeMgmtWorker(SDnode *pDnode) {
|
static void dndCleanupMnodeMgmtWorker(SDnode *pDnode) {
|
||||||
SMnodeMgmt *pMgmt = &pDnode->mmgmt;
|
SMnodeMgmt *pMgmt = &pDnode->mmgmt;
|
||||||
tWorkerCleanup(&pMgmt->mgmtPool);
|
tWorkerCleanup(&pMgmt->mgmtPool);
|
||||||
dDebug("mnode mgmt worker is stopped");
|
dDebug("mnode mgmt worker is closed");
|
||||||
}
|
}
|
||||||
|
|
||||||
static int32_t dndAllocMnodeReadQueue(SDnode *pDnode) {
|
static int32_t dndAllocMnodeReadQueue(SDnode *pDnode) {
|
||||||
SMnodeMgmt *pMgmt = &pDnode->mmgmt;
|
SMnodeMgmt *pMgmt = &pDnode->mmgmt;
|
||||||
pMgmt->pReadQ = tWorkerAllocQueue(&pMgmt->readPool, NULL, (FProcessItem)dndProcessMnodeReadQueue);
|
pMgmt->pReadQ = tWorkerAllocQueue(&pMgmt->readPool, pDnode, (FProcessItem)dndProcessMnodeReadQueue);
|
||||||
if (pMgmt->pReadQ == NULL) {
|
if (pMgmt->pReadQ == NULL) {
|
||||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||||
return -1;
|
return -1;
|
||||||
|
@ -745,18 +751,19 @@ static int32_t dndInitMnodeReadWorker(SDnode *pDnode) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
dDebug("mnode read worker is initialized");
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void dndCleanupMnodeReadWorker(SDnode *pDnode) {
|
static void dndCleanupMnodeReadWorker(SDnode *pDnode) {
|
||||||
SMnodeMgmt *pMgmt = &pDnode->mmgmt;
|
SMnodeMgmt *pMgmt = &pDnode->mmgmt;
|
||||||
tWorkerCleanup(&pMgmt->readPool);
|
tWorkerCleanup(&pMgmt->readPool);
|
||||||
dDebug("mnode read worker is stopped");
|
dDebug("mnode read worker is closed");
|
||||||
}
|
}
|
||||||
|
|
||||||
static int32_t dndAllocMnodeWriteQueue(SDnode *pDnode) {
|
static int32_t dndAllocMnodeWriteQueue(SDnode *pDnode) {
|
||||||
SMnodeMgmt *pMgmt = &pDnode->mmgmt;
|
SMnodeMgmt *pMgmt = &pDnode->mmgmt;
|
||||||
pMgmt->pWriteQ = tWorkerAllocQueue(&pMgmt->writePool, NULL, (FProcessItem)dndProcessMnodeWriteQueue);
|
pMgmt->pWriteQ = tWorkerAllocQueue(&pMgmt->writePool, pDnode, (FProcessItem)dndProcessMnodeWriteQueue);
|
||||||
if (pMgmt->pWriteQ == NULL) {
|
if (pMgmt->pWriteQ == NULL) {
|
||||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||||
return -1;
|
return -1;
|
||||||
|
@ -773,7 +780,7 @@ static void dndFreeMnodeWriteQueue(SDnode *pDnode) {
|
||||||
|
|
||||||
static int32_t dndAllocMnodeApplyQueue(SDnode *pDnode) {
|
static int32_t dndAllocMnodeApplyQueue(SDnode *pDnode) {
|
||||||
SMnodeMgmt *pMgmt = &pDnode->mmgmt;
|
SMnodeMgmt *pMgmt = &pDnode->mmgmt;
|
||||||
pMgmt->pApplyQ = tWorkerAllocQueue(&pMgmt->writePool, NULL, (FProcessItem)dndProcessMnodeApplyQueue);
|
pMgmt->pApplyQ = tWorkerAllocQueue(&pMgmt->writePool, pDnode, (FProcessItem)dndProcessMnodeApplyQueue);
|
||||||
if (pMgmt->pApplyQ == NULL) {
|
if (pMgmt->pApplyQ == NULL) {
|
||||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||||
return -1;
|
return -1;
|
||||||
|
@ -799,18 +806,19 @@ static int32_t dndInitMnodeWriteWorker(SDnode *pDnode) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
dDebug("mnode write worker is initialized");
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void dndCleanupMnodeWriteWorker(SDnode *pDnode) {
|
static void dndCleanupMnodeWriteWorker(SDnode *pDnode) {
|
||||||
SMnodeMgmt *pMgmt = &pDnode->mmgmt;
|
SMnodeMgmt *pMgmt = &pDnode->mmgmt;
|
||||||
tWorkerCleanup(&pMgmt->writePool);
|
tWorkerCleanup(&pMgmt->writePool);
|
||||||
dDebug("mnode write worker is stopped");
|
dDebug("mnode write worker is closed");
|
||||||
}
|
}
|
||||||
|
|
||||||
static int32_t dndAllocMnodeSyncQueue(SDnode *pDnode) {
|
static int32_t dndAllocMnodeSyncQueue(SDnode *pDnode) {
|
||||||
SMnodeMgmt *pMgmt = &pDnode->mmgmt;
|
SMnodeMgmt *pMgmt = &pDnode->mmgmt;
|
||||||
pMgmt->pSyncQ = tWorkerAllocQueue(&pMgmt->syncPool, NULL, (FProcessItem)dndProcessMnodeSyncQueue);
|
pMgmt->pSyncQ = tWorkerAllocQueue(&pMgmt->syncPool, pDnode, (FProcessItem)dndProcessMnodeSyncQueue);
|
||||||
if (pMgmt->pSyncQ == NULL) {
|
if (pMgmt->pSyncQ == NULL) {
|
||||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||||
return -1;
|
return -1;
|
||||||
|
@ -836,13 +844,14 @@ static int32_t dndInitMnodeSyncWorker(SDnode *pDnode) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
dDebug("mnode sync worker is initialized");
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void dndCleanupMnodeSyncWorker(SDnode *pDnode) {
|
static void dndCleanupMnodeSyncWorker(SDnode *pDnode) {
|
||||||
SMnodeMgmt *pMgmt = &pDnode->mmgmt;
|
SMnodeMgmt *pMgmt = &pDnode->mmgmt;
|
||||||
tWorkerCleanup(&pMgmt->syncPool);
|
tWorkerCleanup(&pMgmt->syncPool);
|
||||||
dDebug("mnode sync worker is stopped");
|
dDebug("mnode sync worker is closed");
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t dndInitMnode(SDnode *pDnode) {
|
int32_t dndInitMnode(SDnode *pDnode) {
|
||||||
|
@ -869,7 +878,7 @@ int32_t dndInitMnode(SDnode *pDnode) {
|
||||||
|
|
||||||
if (pMgmt->dropped) {
|
if (pMgmt->dropped) {
|
||||||
dInfo("mnode has been deployed and needs to be deleted");
|
dInfo("mnode has been deployed and needs to be deleted");
|
||||||
mnodeDestroy(pDnode->dir.mnode);
|
mndDestroy(pDnode->dir.mnode);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -912,7 +921,7 @@ int32_t dndGetUserAuthFromMnode(SDnode *pDnode, char *user, char *spi, char *enc
|
||||||
return -1;
|
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);
|
dndReleaseMnode(pDnode, pMnode);
|
||||||
return code;
|
return code;
|
||||||
}
|
}
|
||||||
|
|
|
@ -187,6 +187,7 @@ static void dndProcessRequest(void *param, SRpcMsg *pMsg, SEpSet *pEpSet) {
|
||||||
|
|
||||||
int32_t msgType = pMsg->msgType;
|
int32_t msgType = pMsg->msgType;
|
||||||
if (msgType == TSDB_MSG_TYPE_NETWORK_TEST) {
|
if (msgType == TSDB_MSG_TYPE_NETWORK_TEST) {
|
||||||
|
dTrace("RPC %p, network test req will be processed", pMsg->handle);
|
||||||
dndProcessDnodeReq(pDnode, pMsg, pEpSet);
|
dndProcessDnodeReq(pDnode, pMsg, pEpSet);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -206,6 +207,7 @@ static void dndProcessRequest(void *param, SRpcMsg *pMsg, SEpSet *pEpSet) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (pMsg->pCont == NULL) {
|
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};
|
SRpcMsg rspMsg = {.handle = pMsg->handle, .code = TSDB_CODE_DND_INVALID_MSG_LEN};
|
||||||
rpcSendResponse(&rspMsg);
|
rpcSendResponse(&rspMsg);
|
||||||
return;
|
return;
|
||||||
|
@ -259,12 +261,12 @@ static int32_t dndRetrieveUserAuthInfo(void *parent, char *user, char *spi, char
|
||||||
SDnode *pDnode = parent;
|
SDnode *pDnode = parent;
|
||||||
|
|
||||||
if (dndAuthInternalMsg(parent, user, spi, encrypt, secret, ckey) == 0) {
|
if (dndAuthInternalMsg(parent, user, spi, encrypt, secret, ckey) == 0) {
|
||||||
dTrace("get internal auth success");
|
// dTrace("get internal auth success");
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (dndGetUserAuthFromMnode(pDnode, user, spi, encrypt, secret, ckey) == 0) {
|
if (dndGetUserAuthFromMnode(pDnode, user, spi, encrypt, secret, ckey) == 0) {
|
||||||
dTrace("get auth from internal mnode");
|
// dTrace("get auth from internal mnode");
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -273,7 +275,7 @@ static int32_t dndRetrieveUserAuthInfo(void *parent, char *user, char *spi, char
|
||||||
return -1;
|
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));
|
SAuthMsg *pMsg = rpcMallocCont(sizeof(SAuthMsg));
|
||||||
tstrncpy(pMsg->user, user, TSDB_USER_LEN);
|
tstrncpy(pMsg->user, user, TSDB_USER_LEN);
|
||||||
|
|
|
@ -26,7 +26,7 @@
|
||||||
EStat dndGetStat(SDnode *pDnode) { return pDnode->stat; }
|
EStat dndGetStat(SDnode *pDnode) { return pDnode->stat; }
|
||||||
|
|
||||||
void dndSetStat(SDnode *pDnode, EStat 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;
|
pDnode->stat = stat;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -214,8 +214,7 @@ void dndCleanup(SDnode *pDnode) {
|
||||||
dndCleanupDnode(pDnode);
|
dndCleanupDnode(pDnode);
|
||||||
walCleanUp();
|
walCleanUp();
|
||||||
rpcCleanup();
|
rpcCleanup();
|
||||||
|
|
||||||
dInfo("TDengine is cleaned up successfully");
|
|
||||||
dndCleanupEnv(pDnode);
|
dndCleanupEnv(pDnode);
|
||||||
free(pDnode);
|
free(pDnode);
|
||||||
|
dInfo("TDengine is cleaned up successfully");
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,11 +3,11 @@ add_library(mnode ${MNODE_SRC})
|
||||||
target_include_directories(
|
target_include_directories(
|
||||||
mnode
|
mnode
|
||||||
PUBLIC "${CMAKE_SOURCE_DIR}/include/dnode/mnode"
|
PUBLIC "${CMAKE_SOURCE_DIR}/include/dnode/mnode"
|
||||||
private "${CMAKE_CURRENT_SOURCE_DIR}/inc"
|
PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/inc"
|
||||||
)
|
)
|
||||||
target_link_libraries(
|
target_link_libraries(
|
||||||
mnode
|
mnode
|
||||||
PRIVATE sdb
|
PRIVATE sdb
|
||||||
PUBLIC transport
|
PRIVATE transport
|
||||||
PUBLIC cjson
|
PRIVATE cjson
|
||||||
)
|
)
|
|
@ -13,20 +13,20 @@
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef _TD_MNODE_ACCT_H_
|
#ifndef _TD_MND_ACCT_H_
|
||||||
#define _TD_MNODE_ACCT_H_
|
#define _TD_MND_ACCT_H_
|
||||||
|
|
||||||
#include "mnodeInt.h"
|
#include "mndInt.h"
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
extern "C" {
|
extern "C" {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
int32_t mnodeInitAcct();
|
int32_t mndInitAcct(SMnode *pMnode);
|
||||||
void mnodeCleanupAcct();
|
void mndCleanupAcct(SMnode *pMnode);
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#endif /*_TD_MNODE_ACCT_H_*/
|
#endif /*_TD_MND_ACCT_H_*/
|
|
@ -13,20 +13,20 @@
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef _TD_MNODE_AUTH_H_
|
#ifndef _TD_MND_AUTH_H_
|
||||||
#define _TD_MNODE_AUTH_H_
|
#define _TD_MND_AUTH_H_
|
||||||
|
|
||||||
#include "mnodeInt.h"
|
#include "mndInt.h"
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
extern "C" {
|
extern "C" {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
int32_t mnodeInitAuth();
|
int32_t mndInitAuth(SMnode *pMnode);
|
||||||
void mnodeCleanupAuth();
|
void mndCleanupAuth(SMnode *pMnode);
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#endif /*_TD_MNODE_AUTH_H_*/
|
#endif /*_TD_MND_AUTH_H_*/
|
|
@ -0,0 +1,32 @@
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com>
|
||||||
|
*
|
||||||
|
* 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 <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#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_*/
|
|
@ -0,0 +1,32 @@
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com>
|
||||||
|
*
|
||||||
|
* 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 <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#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_*/
|
|
@ -0,0 +1,32 @@
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com>
|
||||||
|
*
|
||||||
|
* 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 <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#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_*/
|
|
@ -13,8 +13,8 @@
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef _TD_MNODE_DEF_H_
|
#ifndef _TD_MND_DEF_H_
|
||||||
#define _TD_MNODE_DEF_H_
|
#define _TD_MND_DEF_H_
|
||||||
|
|
||||||
#include "os.h"
|
#include "os.h"
|
||||||
#include "taosmsg.h"
|
#include "taosmsg.h"
|
||||||
|
@ -39,42 +39,34 @@ extern int32_t mDebugFlag;
|
||||||
#define mDebug(...) { if (mDebugFlag & DEBUG_DEBUG) { taosPrintLog("MND ", mDebugFlag, __VA_ARGS__); }}
|
#define mDebug(...) { if (mDebugFlag & DEBUG_DEBUG) { taosPrintLog("MND ", mDebugFlag, __VA_ARGS__); }}
|
||||||
#define mTrace(...) { if (mDebugFlag & DEBUG_TRACE) { 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__) }
|
typedef struct SClusterObj SClusterObj;
|
||||||
// #define mLWarn(...) { monSaveLog(1, __VA_ARGS__); mWarn(__VA_ARGS__) }
|
typedef struct SDnodeObj SDnodeObj;
|
||||||
// #define mLInfo(...) { monSaveLog(0, __VA_ARGS__); mInfo(__VA_ARGS__) }
|
typedef struct SMnodeObj SMnodeObj;
|
||||||
|
typedef struct SAcctObj SAcctObj;
|
||||||
#define mLError(...) {mError(__VA_ARGS__) }
|
typedef struct SUserObj SUserObj;
|
||||||
#define mLWarn(...) {mWarn(__VA_ARGS__) }
|
typedef struct SDbObj SDbObj;
|
||||||
#define mLInfo(...) {mInfo(__VA_ARGS__) }
|
typedef struct SVgObj SVgObj;
|
||||||
|
typedef struct SSTableObj SSTableObj;
|
||||||
typedef struct SClusterObj SClusterObj;
|
typedef struct SFuncObj SFuncObj;
|
||||||
typedef struct SDnodeObj SDnodeObj;
|
typedef struct SOperObj SOperObj;
|
||||||
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 {
|
typedef enum {
|
||||||
MN_AUTH_ACCT_START = 0,
|
MND_AUTH_ACCT_START = 0,
|
||||||
MN_AUTH_ACCT_USER,
|
MND_AUTH_ACCT_USER,
|
||||||
MN_AUTH_ACCT_DNODE,
|
MND_AUTH_ACCT_DNODE,
|
||||||
MN_AUTH_ACCT_MNODE,
|
MND_AUTH_ACCT_MNODE,
|
||||||
MN_AUTH_ACCT_DB,
|
MND_AUTH_ACCT_DB,
|
||||||
MN_AUTH_ACCT_TABLE,
|
MND_AUTH_ACCT_TABLE,
|
||||||
MN_AUTH_ACCT_MAX
|
MND_AUTH_ACCT_MAX
|
||||||
} EMnAuthAcct;
|
} EAuthAcct;
|
||||||
|
|
||||||
typedef enum {
|
typedef enum {
|
||||||
MN_AUTH_OP_START = 0,
|
MND_AUTH_OP_START = 0,
|
||||||
MN_AUTH_OP_CREATE_USER,
|
MND_AUTH_OP_CREATE_USER,
|
||||||
MN_AUTH_OP_ALTER_USER,
|
MND_AUTH_OP_ALTER_USER,
|
||||||
MN_AUTH_OP_DROP_USER,
|
MND_AUTH_OP_DROP_USER,
|
||||||
MN_AUTH_MAX
|
MND_AUTH_MAX
|
||||||
} EMnAuthOp;
|
} EAuthOp;
|
||||||
|
|
||||||
typedef enum {
|
typedef enum {
|
||||||
TRN_STAGE_PREPARE = 1,
|
TRN_STAGE_PREPARE = 1,
|
||||||
|
@ -86,11 +78,11 @@ typedef enum {
|
||||||
|
|
||||||
typedef enum { TRN_POLICY_ROLLBACK = 1, TRN_POLICY_RETRY = 2 } ETrnPolicy;
|
typedef enum { TRN_POLICY_ROLLBACK = 1, TRN_POLICY_RETRY = 2 } ETrnPolicy;
|
||||||
|
|
||||||
|
|
||||||
typedef struct STrans {
|
typedef struct STrans {
|
||||||
int32_t id;
|
int32_t id;
|
||||||
ETrnStage stage;
|
ETrnStage stage;
|
||||||
ETrnPolicy policy;
|
ETrnPolicy policy;
|
||||||
|
SMnode *pMnode;
|
||||||
void *rpcHandle;
|
void *rpcHandle;
|
||||||
SArray *redoLogs;
|
SArray *redoLogs;
|
||||||
SArray *undoLogs;
|
SArray *undoLogs;
|
||||||
|
@ -99,7 +91,6 @@ typedef struct STrans {
|
||||||
SArray *undoActions;
|
SArray *undoActions;
|
||||||
} STrans;
|
} STrans;
|
||||||
|
|
||||||
|
|
||||||
typedef struct SClusterObj {
|
typedef struct SClusterObj {
|
||||||
int64_t id;
|
int64_t id;
|
||||||
char uid[TSDB_CLUSTER_ID_LEN];
|
char uid[TSDB_CLUSTER_ID_LEN];
|
||||||
|
@ -202,6 +193,7 @@ typedef struct SDbObj {
|
||||||
int64_t createdTime;
|
int64_t createdTime;
|
||||||
int64_t updateTime;
|
int64_t updateTime;
|
||||||
SDbCfg cfg;
|
SDbCfg cfg;
|
||||||
|
int64_t uid;
|
||||||
int8_t status;
|
int8_t status;
|
||||||
int32_t numOfVgroups;
|
int32_t numOfVgroups;
|
||||||
int32_t numOfTables;
|
int32_t numOfTables;
|
||||||
|
@ -240,13 +232,13 @@ typedef struct SVgObj {
|
||||||
} SVgObj;
|
} SVgObj;
|
||||||
|
|
||||||
typedef struct SSTableObj {
|
typedef struct SSTableObj {
|
||||||
char tableId[TSDB_TABLE_NAME_LEN];
|
char tableId[TSDB_TABLE_NAME_LEN];
|
||||||
uint64_t uid;
|
uint64_t uid;
|
||||||
int64_t createdTime;
|
int64_t createdTime;
|
||||||
int64_t updateTime;
|
int64_t updateTime;
|
||||||
int32_t numOfColumns; // used by normal table
|
int32_t numOfColumns; // used by normal table
|
||||||
int32_t numOfTags;
|
int32_t numOfTags;
|
||||||
SSchema * schema;
|
SSchema *schema;
|
||||||
} SSTableObj;
|
} SSTableObj;
|
||||||
|
|
||||||
typedef struct SFuncObj {
|
typedef struct SFuncObj {
|
||||||
|
@ -284,25 +276,26 @@ typedef struct {
|
||||||
typedef struct {
|
typedef struct {
|
||||||
int32_t len;
|
int32_t len;
|
||||||
void *rsp;
|
void *rsp;
|
||||||
} SMnRsp;
|
} SMnodeRsp;
|
||||||
|
|
||||||
typedef struct SMnodeMsg {
|
typedef struct SMnodeMsg {
|
||||||
|
SMnode *pMnode;
|
||||||
void (*fp)(SMnodeMsg *pMsg, int32_t code);
|
void (*fp)(SMnodeMsg *pMsg, int32_t code);
|
||||||
SRpcConnInfo conn;
|
SRpcConnInfo conn;
|
||||||
SUserObj *pUser;
|
SUserObj *pUser;
|
||||||
int16_t received;
|
int16_t received;
|
||||||
int16_t successed;
|
int16_t successed;
|
||||||
int16_t expected;
|
int16_t expected;
|
||||||
int16_t retry;
|
int16_t retry;
|
||||||
int32_t code;
|
int32_t code;
|
||||||
int64_t createdTime;
|
int64_t createdTime;
|
||||||
SMnRsp rpcRsp;
|
SMnodeRsp rpcRsp;
|
||||||
SRpcMsg rpcMsg;
|
SRpcMsg rpcMsg;
|
||||||
char pCont[];
|
char pCont[];
|
||||||
} SMnodeMsg;
|
} SMnodeMsg;
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#endif /*_TD_MNODE_DEF_H_*/
|
#endif /*_TD_MND_DEF_H_*/
|
|
@ -0,0 +1,32 @@
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com>
|
||||||
|
*
|
||||||
|
* 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 <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#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_*/
|
|
@ -13,20 +13,20 @@
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef _TD_MNODE_BALANCE_H_
|
#ifndef _TD_MND_FUNC_H_
|
||||||
#define _TD_MNODE_BALANCE_H_
|
#define _TD_MND_FUNC_H_
|
||||||
|
|
||||||
#include "mnodeInt.h"
|
#include "mndInt.h"
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
extern "C" {
|
extern "C" {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
int32_t mnodeInitBalance();
|
int32_t mndInitFunc(SMnode *pMnode);
|
||||||
void mnodeCleanupBalance();
|
void mndCleanupFunc(SMnode *pMnode);
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#endif /*_TD_MNODE_BALANCE_H_*/
|
#endif /*_TD_MND_FUNC_H_*/
|
|
@ -13,28 +13,26 @@
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef _TD_MNODE_INT_H_
|
#ifndef _TD_MND_INT_H_
|
||||||
#define _TD_MNODE_INT_H_
|
#define _TD_MND_INT_H_
|
||||||
|
|
||||||
#include "mnodeDef.h"
|
#include "mndDef.h"
|
||||||
#include "sdb.h"
|
#include "sdb.h"
|
||||||
#include "tstep.h"
|
#include "tqueue.h"
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
extern "C" {
|
extern "C" {
|
||||||
#endif
|
#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 {
|
typedef struct {
|
||||||
int32_t dnodeId;
|
const char *name;
|
||||||
int64_t clusterId;
|
MndInitFp initFp;
|
||||||
tmr_h timer;
|
MndCleanupFp cleanupFp;
|
||||||
SSteps *pInitSteps;
|
} SMnodeStep;
|
||||||
SSteps *pStartSteps;
|
|
||||||
SMnodeOpt para;
|
|
||||||
MnodeRpcFp msgFp[TSDB_MSG_TYPE_MAX];
|
|
||||||
} SMnodeBak;
|
|
||||||
|
|
||||||
typedef struct SMnode {
|
typedef struct SMnode {
|
||||||
int32_t dnodeId;
|
int32_t dnodeId;
|
||||||
|
@ -43,29 +41,28 @@ typedef struct SMnode {
|
||||||
int8_t selfIndex;
|
int8_t selfIndex;
|
||||||
SReplica replicas[TSDB_MAX_REPLICA];
|
SReplica replicas[TSDB_MAX_REPLICA];
|
||||||
tmr_h timer;
|
tmr_h timer;
|
||||||
SSteps *pInitSteps;
|
char *path;
|
||||||
SSteps *pStartSteps;
|
SSdb *pSdb;
|
||||||
struct SSdb *pSdb;
|
SDnode *pDnode;
|
||||||
struct SDnode *pServer;
|
SArray *pSteps;
|
||||||
MnodeRpcFp msgFp[TSDB_MSG_TYPE_MAX];
|
MndMsgFp msgFp[TSDB_MSG_TYPE_MAX];
|
||||||
PutMsgToMnodeQFp putMsgToApplyMsgFp;
|
|
||||||
SendMsgToDnodeFp sendMsgToDnodeFp;
|
SendMsgToDnodeFp sendMsgToDnodeFp;
|
||||||
SendMsgToMnodeFp sendMsgToMnodeFp;
|
SendMsgToMnodeFp sendMsgToMnodeFp;
|
||||||
SendRedirectMsgFp sendRedirectMsgFp;
|
SendRedirectMsgFp sendRedirectMsgFp;
|
||||||
|
PutMsgToMnodeQFp putMsgToApplyMsgFp;
|
||||||
} SMnode;
|
} SMnode;
|
||||||
|
|
||||||
tmr_h mnodeGetTimer();
|
tmr_h mndGetTimer(SMnode *pMnode);
|
||||||
int32_t mnodeGetDnodeId();
|
int32_t mndGetDnodeId(SMnode *pMnode);
|
||||||
int64_t mnodeGetClusterId();
|
int64_t mndGetClusterId(SMnode *pMnode);
|
||||||
|
|
||||||
void mnodeSendMsgToDnode(SMnode *pMnode, struct SEpSet *epSet, struct SRpcMsg *rpcMsg);
|
void mndSendMsgToDnode(SMnode *pMnode, SEpSet *pEpSet, SRpcMsg *rpcMsg);
|
||||||
void mnodeSendMsgToMnode(SMnode *pMnode, struct SRpcMsg *rpcMsg);
|
void mndSendMsgToMnode(SMnode *pMnode, SRpcMsg *pMsg);
|
||||||
void mnodeSendRedirectMsg(SMnode *pMnode, struct SRpcMsg *rpcMsg, bool forShell);
|
void mndSendRedirectMsg(SMnode *pMnode, SRpcMsg *pMsg);
|
||||||
|
void mndSetMsgHandle(SMnode *pMnode, int32_t msgType, MndMsgFp fp);
|
||||||
void mnodeSetMsgFp(int32_t msgType, MnodeRpcFp fp);
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#endif /*_TD_MNODE_INT_H_*/
|
#endif /*_TD_MND_INT_H_*/
|
|
@ -0,0 +1,34 @@
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com>
|
||||||
|
*
|
||||||
|
* 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 <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#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_*/
|
|
@ -13,18 +13,18 @@
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef _TD_MNODE_OPER_H_
|
#ifndef _TD_MND_OPER_H_
|
||||||
#define _TD_MNODE_OPER_H_
|
#define _TD_MND_OPER_H_
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
extern "C" {
|
extern "C" {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
int32_t mnodeInitOper();
|
int32_t mndInitOper(SMnode *pMnode);
|
||||||
void mnodeCleanupOper();
|
void mndCleanupOper(SMnode *pMnode);
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#endif /*_TD_MNODE_OPER_H_*/
|
#endif /*_TD_MND_OPER_H_*/
|
|
@ -0,0 +1,32 @@
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com>
|
||||||
|
*
|
||||||
|
* 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 <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#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_*/
|
|
@ -13,20 +13,20 @@
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef _TD_MNODE_CLUSTER_H_
|
#ifndef _TD_MND_SHOW_H_
|
||||||
#define _TD_MNODE_CLUSTER_H_
|
#define _TD_MND_SHOW_H_
|
||||||
|
|
||||||
#include "mnodeInt.h"
|
#include "mndInt.h"
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
extern "C" {
|
extern "C" {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
int32_t mnodeInitCluster();
|
int32_t mndInitShow(SMnode *pMnode);
|
||||||
void mnodeCleanupCluster();
|
void mndCleanupShow(SMnode *pMnode);
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#endif /*_TD_MNODE_CLUSTER_H_*/
|
#endif /*_TD_MND_SHOW_H_*/
|
|
@ -0,0 +1,32 @@
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com>
|
||||||
|
*
|
||||||
|
* 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 <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#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_*/
|
|
@ -0,0 +1,34 @@
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com>
|
||||||
|
*
|
||||||
|
* 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 <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#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_*/
|
|
@ -13,19 +13,19 @@
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef _TD_MNODE_TELEMETRY_H_
|
#ifndef _TD_MND_TELEMETRY_H_
|
||||||
#define _TD_MNODE_TELEMETRY_H_
|
#define _TD_MND_TELEMETRY_H_
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
extern "C" {
|
extern "C" {
|
||||||
#endif
|
#endif
|
||||||
#include "mnodeInt.h"
|
#include "mndInt.h"
|
||||||
|
|
||||||
int32_t mnodeInitTelem();
|
int32_t mndInitTelem(SMnode *pMnode);
|
||||||
void mnodeCleanupTelem();
|
void mndCleanupTelem(SMnode *pMnode);
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#endif /*_TD_MNODE_TELEMETRY_H_*/
|
#endif /*_TD_MND_TELEMETRY_H_*/
|
|
@ -0,0 +1,47 @@
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com>
|
||||||
|
*
|
||||||
|
* 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 <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#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_*/
|
|
@ -0,0 +1,32 @@
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com>
|
||||||
|
*
|
||||||
|
* 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 <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#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_*/
|
|
@ -0,0 +1,32 @@
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com>
|
||||||
|
*
|
||||||
|
* 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 <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#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_*/
|
|
@ -1,32 +0,0 @@
|
||||||
/*
|
|
||||||
* Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com>
|
|
||||||
*
|
|
||||||
* 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 <http://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#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_*/
|
|
|
@ -1,32 +0,0 @@
|
||||||
/*
|
|
||||||
* Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com>
|
|
||||||
*
|
|
||||||
* 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 <http://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#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_*/
|
|
|
@ -1,32 +0,0 @@
|
||||||
/*
|
|
||||||
* Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com>
|
|
||||||
*
|
|
||||||
* 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 <http://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#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_*/
|
|
|
@ -1,34 +0,0 @@
|
||||||
/*
|
|
||||||
* Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com>
|
|
||||||
*
|
|
||||||
* 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 <http://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#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_*/
|
|
|
@ -1,32 +0,0 @@
|
||||||
/*
|
|
||||||
* Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com>
|
|
||||||
*
|
|
||||||
* 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 <http://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#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_*/
|
|
|
@ -1,32 +0,0 @@
|
||||||
/*
|
|
||||||
* Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com>
|
|
||||||
*
|
|
||||||
* 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 <http://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#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_*/
|
|
|
@ -1,32 +0,0 @@
|
||||||
/*
|
|
||||||
* Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com>
|
|
||||||
*
|
|
||||||
* 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 <http://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#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_*/
|
|
|
@ -1,35 +0,0 @@
|
||||||
/*
|
|
||||||
* Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com>
|
|
||||||
*
|
|
||||||
* 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 <http://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#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_*/
|
|
|
@ -1,47 +0,0 @@
|
||||||
/*
|
|
||||||
* Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com>
|
|
||||||
*
|
|
||||||
* 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 <http://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#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_*/
|
|
|
@ -1,32 +0,0 @@
|
||||||
/*
|
|
||||||
* Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com>
|
|
||||||
*
|
|
||||||
* 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 <http://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#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_*/
|
|
|
@ -1,32 +0,0 @@
|
||||||
/*
|
|
||||||
* Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com>
|
|
||||||
*
|
|
||||||
* 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 <http://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#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_*/
|
|
|
@ -14,7 +14,7 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#define _DEFAULT_SOURCE
|
#define _DEFAULT_SOURCE
|
||||||
#include "mnodeInt.h"
|
#include "mndInt.h"
|
||||||
|
|
||||||
#define SDB_ACCT_VER 1
|
#define SDB_ACCT_VER 1
|
||||||
|
|
||||||
|
@ -48,10 +48,10 @@ static SSdbRow *mnodeAcctActionDecode(SSdbRaw *pRaw) {
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
SSdbRow *pRow = sdbAllocRow(sizeof(SAcctObj));
|
SSdbRow *pRow = sdbAllocRow(sizeof(SAcctObj));
|
||||||
SAcctObj *pAcct = sdbGetRowObj(pRow);
|
SAcctObj *pAcct = sdbGetRowObj(pRow);
|
||||||
if (pAcct == NULL) return NULL;
|
if (pAcct == NULL) return NULL;
|
||||||
|
|
||||||
int32_t dataPos = 0;
|
int32_t dataPos = 0;
|
||||||
SDB_GET_BINARY(pRaw, pRow, dataPos, pAcct->acct, TSDB_USER_LEN)
|
SDB_GET_BINARY(pRaw, pRow, dataPos, pAcct->acct, TSDB_USER_LEN)
|
||||||
SDB_GET_INT64(pRaw, pRow, dataPos, &pAcct->createdTime)
|
SDB_GET_INT64(pRaw, pRow, dataPos, &pAcct->createdTime)
|
||||||
|
@ -68,18 +68,18 @@ static SSdbRow *mnodeAcctActionDecode(SSdbRaw *pRaw) {
|
||||||
return pRow;
|
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;
|
SAcctObj tObj;
|
||||||
int32_t len = (int32_t)((int8_t *)&tObj.info - (int8_t *)&tObj);
|
int32_t len = (int32_t)((int8_t *)&tObj.info - (int8_t *)&tObj);
|
||||||
memcpy(pDstAcct, pSrcAcct, len);
|
memcpy(pDstAcct, pSrcAcct, len);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int32_t mnodeCreateDefaultAcct() {
|
static int32_t mnodeCreateDefaultAcct(SSdb *pSdb) {
|
||||||
int32_t code = 0;
|
int32_t code = 0;
|
||||||
|
|
||||||
SAcctObj acctObj = {0};
|
SAcctObj acctObj = {0};
|
||||||
|
@ -98,21 +98,20 @@ static int32_t mnodeCreateDefaultAcct() {
|
||||||
if (pRaw == NULL) return -1;
|
if (pRaw == NULL) return -1;
|
||||||
sdbSetRawStatus(pRaw, SDB_STATUS_READY);
|
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,
|
SSdbTable table = {.sdbType = SDB_ACCT,
|
||||||
.keyType = SDB_KEY_BINARY,
|
.keyType = SDB_KEY_BINARY,
|
||||||
.deployFp = (SdbDeployFp)mnodeCreateDefaultAcct,
|
.deployFp = mnodeCreateDefaultAcct,
|
||||||
.encodeFp = (SdbEncodeFp)mnodeAcctActionEncode,
|
.encodeFp = (SdbEncodeFp)mnodeAcctActionEncode,
|
||||||
.decodeFp = (SdbDecodeFp)mnodeAcctActionDecode,
|
.decodeFp = (SdbDecodeFp)mnodeAcctActionDecode,
|
||||||
.insertFp = (SdbInsertFp)mnodeAcctActionInsert,
|
.insertFp = (SdbInsertFp)mnodeAcctActionInsert,
|
||||||
.updateFp = (SdbUpdateFp)mnodeAcctActionUpdate,
|
.updateFp = (SdbUpdateFp)mnodeAcctActionUpdate,
|
||||||
.deleteFp = (SdbDeleteFp)mnodeAcctActionDelete};
|
.deleteFp = (SdbDeleteFp)mnodeAcctActionDelete};
|
||||||
sdbSetTable(table);
|
|
||||||
|
|
||||||
return 0;
|
return sdbSetTable(pMnode->pSdb, table);
|
||||||
}
|
}
|
||||||
|
|
||||||
void mnodeCleanupAcct() {}
|
void mndCleanupAcct(SMnode *pMnode) {}
|
|
@ -15,11 +15,11 @@
|
||||||
|
|
||||||
#define _DEFAULT_SOURCE
|
#define _DEFAULT_SOURCE
|
||||||
#include "os.h"
|
#include "os.h"
|
||||||
#include "mnodeAuth.h"
|
#include "mndAuth.h"
|
||||||
|
|
||||||
int32_t mnodeInitAuth() { return 0; }
|
int32_t mndInitAuth(SMnode *pMnode) { return 0; }
|
||||||
void mnodeCleanupAuth() {}
|
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;
|
return 0;
|
||||||
}
|
}
|
|
@ -0,0 +1,21 @@
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com>
|
||||||
|
*
|
||||||
|
* 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 <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#define _DEFAULT_SOURCE
|
||||||
|
#include "os.h"
|
||||||
|
#include "mndInt.h"
|
||||||
|
|
||||||
|
int32_t mndInitBalance(SMnode *pMnode) { return 0; }
|
||||||
|
void mndCleanupBalance(SMnode *pMnode) {}
|
|
@ -0,0 +1,21 @@
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com>
|
||||||
|
*
|
||||||
|
* 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 <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#define _DEFAULT_SOURCE
|
||||||
|
#include "os.h"
|
||||||
|
#include "mndInt.h"
|
||||||
|
|
||||||
|
int32_t mndInitCluster(SMnode *pMnode) { return 0; }
|
||||||
|
void mndCleanupCluster(SMnode *pMnode) {}
|
|
@ -15,7 +15,7 @@
|
||||||
|
|
||||||
#define _DEFAULT_SOURCE
|
#define _DEFAULT_SOURCE
|
||||||
#include "os.h"
|
#include "os.h"
|
||||||
#include "mnodeInt.h"
|
#include "mndInt.h"
|
||||||
|
|
||||||
int32_t mnodeInitDnode() { return 0; }
|
int32_t mndInitDb(SMnode *pMnode) { return 0; }
|
||||||
void mnodeCleanupDnode() {}
|
void mndCleanupDb(SMnode *pMnode) {}
|
|
@ -0,0 +1,21 @@
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com>
|
||||||
|
*
|
||||||
|
* 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 <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#define _DEFAULT_SOURCE
|
||||||
|
#include "os.h"
|
||||||
|
#include "mndInt.h"
|
||||||
|
|
||||||
|
int32_t mndInitDnode(SMnode *pMnode) { return 0; }
|
||||||
|
void mndCleanupDnode(SMnode *pMnode) {}
|
|
@ -15,7 +15,7 @@
|
||||||
|
|
||||||
#define _DEFAULT_SOURCE
|
#define _DEFAULT_SOURCE
|
||||||
#include "os.h"
|
#include "os.h"
|
||||||
#include "mnodeInt.h"
|
#include "mndInt.h"
|
||||||
|
|
||||||
int32_t mnodeInitBalance() { return 0; }
|
int32_t mndInitFunc(SMnode *pMnode) { return 0; }
|
||||||
void mnodeCleanupBalance() {}
|
void mndCleanupFunc(SMnode *pMnode) {}
|
|
@ -15,10 +15,10 @@
|
||||||
|
|
||||||
#define _DEFAULT_SOURCE
|
#define _DEFAULT_SOURCE
|
||||||
#include "os.h"
|
#include "os.h"
|
||||||
#include "mnodeInt.h"
|
#include "mndInt.h"
|
||||||
|
|
||||||
int32_t mnodeInitMnode() { return 0; }
|
int32_t mndInitMnode(SMnode *pMnode) { return 0; }
|
||||||
void mnodeCleanupMnode() {}
|
void mndCleanupMnode(SMnode *pMnode) {}
|
||||||
|
|
||||||
void mnodeGetMnodeEpSetForPeer(SEpSet *epSet, bool redirect) {}
|
void mndGetMnodeEpSetForPeer(SEpSet *epSet, bool redirect) {}
|
||||||
void mnodeGetMnodeEpSetForShell(SEpSet *epSet, bool redirect) {}
|
void mndGetMnodeEpSetForShell(SEpSet *epSet, bool redirect) {}
|
|
@ -15,7 +15,7 @@
|
||||||
|
|
||||||
#define _DEFAULT_SOURCE
|
#define _DEFAULT_SOURCE
|
||||||
#include "os.h"
|
#include "os.h"
|
||||||
#include "mnodeInt.h"
|
#include "mndInt.h"
|
||||||
|
|
||||||
int32_t mnodeInitCluster() { return 0; }
|
int32_t mndInitOper(SMnode *pMnode) { return 0; }
|
||||||
void mnodeCleanupCluster() {}
|
void mndCleanupOper(SMnode *pMnode) {}
|
|
@ -0,0 +1,21 @@
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com>
|
||||||
|
*
|
||||||
|
* 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 <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#define _DEFAULT_SOURCE
|
||||||
|
#include "os.h"
|
||||||
|
#include "mndInt.h"
|
||||||
|
|
||||||
|
int32_t mndInitProfile(SMnode *pMnode) { return 0; }
|
||||||
|
void mndCleanupProfile(SMnode *pMnode) {}
|
|
@ -15,7 +15,7 @@
|
||||||
|
|
||||||
#define _DEFAULT_SOURCE
|
#define _DEFAULT_SOURCE
|
||||||
#include "os.h"
|
#include "os.h"
|
||||||
#include "mnodeInt.h"
|
#include "mndInt.h"
|
||||||
|
|
||||||
int32_t mnodeInitDb() { return 0; }
|
int32_t mndInitShow(SMnode *pMnode) { return 0; }
|
||||||
void mnodeCleanupDb() {}
|
void mndCleanupShow(SMnode *pMnode) {}
|
|
@ -0,0 +1,21 @@
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com>
|
||||||
|
*
|
||||||
|
* 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 <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#define _DEFAULT_SOURCE
|
||||||
|
#include "os.h"
|
||||||
|
#include "mndInt.h"
|
||||||
|
|
||||||
|
int32_t mndInitStable(SMnode *pMnode) { return 0; }
|
||||||
|
void mndCleanupStable(SMnode *pMnode) {}
|
|
@ -15,16 +15,16 @@
|
||||||
|
|
||||||
#define _DEFAULT_SOURCE
|
#define _DEFAULT_SOURCE
|
||||||
#include "os.h"
|
#include "os.h"
|
||||||
#include "mnodeInt.h"
|
#include "mndInt.h"
|
||||||
#include "mnodeTrans.h"
|
#include "mndTrans.h"
|
||||||
|
|
||||||
int32_t mnodeInitSync() { return 0; }
|
int32_t mndInitSync(SMnode *pMnode) { return 0; }
|
||||||
void mnodeCleanUpSync() {}
|
void mndCleanupSync(SMnode *pMnode) {}
|
||||||
|
|
||||||
int32_t mnodeSyncPropose(SSdbRaw *pRaw, void *pData) {
|
int32_t mndSyncPropose(SMnode *pMnode, SSdbRaw *pRaw, void *pData) {
|
||||||
trnApply(pData, pData, 0);
|
mndTransApply(pMnode, pData, pData, 0);
|
||||||
free(pData);
|
free(pData);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool mnodeIsMaster() { return true; }
|
bool mndIsMaster(SMnode *pMnode) { return true; }
|
|
@ -14,10 +14,10 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#define _DEFAULT_SOURCE
|
#define _DEFAULT_SOURCE
|
||||||
#include "mnodeTelem.h"
|
#include "mndTelem.h"
|
||||||
#include "tbuffer.h"
|
#include "tbuffer.h"
|
||||||
#include "tglobal.h"
|
#include "tglobal.h"
|
||||||
#include "mnodeSync.h"
|
#include "mndSync.h"
|
||||||
|
|
||||||
#define TELEMETRY_SERVER "telemetry.taosdata.com"
|
#define TELEMETRY_SERVER "telemetry.taosdata.com"
|
||||||
#define TELEMETRY_PORT 80
|
#define TELEMETRY_PORT 80
|
||||||
|
@ -36,9 +36,9 @@ static struct {
|
||||||
char email[TSDB_FQDN_LEN];
|
char email[TSDB_FQDN_LEN];
|
||||||
} tsTelem;
|
} 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);
|
size_t len = tbufTell(bw);
|
||||||
if (tbufGetData(bw, false)[len - 1] == ',') {
|
if (tbufGetData(bw, false)[len - 1] == ',') {
|
||||||
tbufWriteCharAt(bw, len - 1, '}');
|
tbufWriteCharAt(bw, len - 1, '}');
|
||||||
|
@ -64,14 +64,14 @@ static void closeArray(SBufferWriter* bw) {
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
static void mnodeWriteString(SBufferWriter* bw, const char* str) {
|
static void mndWriteString(SBufferWriter* bw, const char* str) {
|
||||||
tbufWriteChar(bw, '"');
|
tbufWriteChar(bw, '"');
|
||||||
tbufWrite(bw, str, strlen(str));
|
tbufWrite(bw, str, strlen(str));
|
||||||
tbufWriteChar(bw, '"');
|
tbufWriteChar(bw, '"');
|
||||||
}
|
}
|
||||||
|
|
||||||
static void mnodeAddIntField(SBufferWriter* bw, const char* k, int64_t v) {
|
static void mndAddIntField(SBufferWriter* bw, const char* k, int64_t v) {
|
||||||
mnodeWriteString(bw, k);
|
mndWriteString(bw, k);
|
||||||
tbufWriteChar(bw, ':');
|
tbufWriteChar(bw, ':');
|
||||||
char buf[32];
|
char buf[32];
|
||||||
sprintf(buf, "%" PRId64, v);
|
sprintf(buf, "%" PRId64, v);
|
||||||
|
@ -79,14 +79,14 @@ static void mnodeAddIntField(SBufferWriter* bw, const char* k, int64_t v) {
|
||||||
tbufWriteChar(bw, ',');
|
tbufWriteChar(bw, ',');
|
||||||
}
|
}
|
||||||
|
|
||||||
static void mnodeAddStringField(SBufferWriter* bw, const char* k, const char* v) {
|
static void mndAddStringField(SBufferWriter* bw, const char* k, const char* v) {
|
||||||
mnodeWriteString(bw, k);
|
mndWriteString(bw, k);
|
||||||
tbufWriteChar(bw, ':');
|
tbufWriteChar(bw, ':');
|
||||||
mnodeWriteString(bw, v);
|
mndWriteString(bw, v);
|
||||||
tbufWriteChar(bw, ',');
|
tbufWriteChar(bw, ',');
|
||||||
}
|
}
|
||||||
|
|
||||||
static void mnodeAddCpuInfo(SBufferWriter* bw) {
|
static void mndAddCpuInfo(SBufferWriter* bw) {
|
||||||
char* line = NULL;
|
char* line = NULL;
|
||||||
size_t size = 0;
|
size_t size = 0;
|
||||||
int32_t done = 0;
|
int32_t done = 0;
|
||||||
|
@ -100,11 +100,11 @@ static void mnodeAddCpuInfo(SBufferWriter* bw) {
|
||||||
line[size - 1] = '\0';
|
line[size - 1] = '\0';
|
||||||
if (((done & 1) == 0) && strncmp(line, "model name", 10) == 0) {
|
if (((done & 1) == 0) && strncmp(line, "model name", 10) == 0) {
|
||||||
const char* v = strchr(line, ':') + 2;
|
const char* v = strchr(line, ':') + 2;
|
||||||
mnodeAddStringField(bw, "cpuModel", v);
|
mndAddStringField(bw, "cpuModel", v);
|
||||||
done |= 1;
|
done |= 1;
|
||||||
} else if (((done & 2) == 0) && strncmp(line, "cpu cores", 9) == 0) {
|
} else if (((done & 2) == 0) && strncmp(line, "cpu cores", 9) == 0) {
|
||||||
const char* v = strchr(line, ':') + 2;
|
const char* v = strchr(line, ':') + 2;
|
||||||
mnodeWriteString(bw, "numOfCpu");
|
mndWriteString(bw, "numOfCpu");
|
||||||
tbufWriteChar(bw, ':');
|
tbufWriteChar(bw, ':');
|
||||||
tbufWrite(bw, v, strlen(v));
|
tbufWrite(bw, v, strlen(v));
|
||||||
tbufWriteChar(bw, ',');
|
tbufWriteChar(bw, ',');
|
||||||
|
@ -116,7 +116,7 @@ static void mnodeAddCpuInfo(SBufferWriter* bw) {
|
||||||
fclose(fp);
|
fclose(fp);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void mnodeAddOsInfo(SBufferWriter* bw) {
|
static void mndAddOsInfo(SBufferWriter* bw) {
|
||||||
char* line = NULL;
|
char* line = NULL;
|
||||||
size_t size = 0;
|
size_t size = 0;
|
||||||
|
|
||||||
|
@ -133,7 +133,7 @@ static void mnodeAddOsInfo(SBufferWriter* bw) {
|
||||||
p++;
|
p++;
|
||||||
line[size - 2] = 0;
|
line[size - 2] = 0;
|
||||||
}
|
}
|
||||||
mnodeAddStringField(bw, "os", p);
|
mndAddStringField(bw, "os", p);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -142,7 +142,7 @@ static void mnodeAddOsInfo(SBufferWriter* bw) {
|
||||||
fclose(fp);
|
fclose(fp);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void mnodeAddMemoryInfo(SBufferWriter* bw) {
|
static void mndAddMemoryInfo(SBufferWriter* bw) {
|
||||||
char* line = NULL;
|
char* line = NULL;
|
||||||
size_t size = 0;
|
size_t size = 0;
|
||||||
|
|
||||||
|
@ -156,7 +156,7 @@ static void mnodeAddMemoryInfo(SBufferWriter* bw) {
|
||||||
if (strncmp(line, "MemTotal", 8) == 0) {
|
if (strncmp(line, "MemTotal", 8) == 0) {
|
||||||
const char* p = strchr(line, ':') + 1;
|
const char* p = strchr(line, ':') + 1;
|
||||||
while (*p == ' ') p++;
|
while (*p == ' ') p++;
|
||||||
mnodeAddStringField(bw, "memory", p);
|
mndAddStringField(bw, "memory", p);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -165,32 +165,32 @@ static void mnodeAddMemoryInfo(SBufferWriter* bw) {
|
||||||
fclose(fp);
|
fclose(fp);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void mnodeAddVersionInfo(SBufferWriter* bw) {
|
static void mndAddVersionInfo(SBufferWriter* bw) {
|
||||||
mnodeAddStringField(bw, "version", version);
|
mndAddStringField(bw, "version", version);
|
||||||
mnodeAddStringField(bw, "buildInfo", buildinfo);
|
mndAddStringField(bw, "buildInfo", buildinfo);
|
||||||
mnodeAddStringField(bw, "gitInfo", gitinfo);
|
mndAddStringField(bw, "gitInfo", gitinfo);
|
||||||
mnodeAddStringField(bw, "email", tsTelem.email);
|
mndAddStringField(bw, "email", tsTelem.email);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void mnodeAddRuntimeInfo(SBufferWriter* bw) {
|
static void mndAddRuntimeInfo(SBufferWriter* bw) {
|
||||||
SMnodeLoad load = {0};
|
SMnodeLoad load = {0};
|
||||||
if (mnodeGetLoad(NULL, &load) != 0) {
|
if (mndGetLoad(NULL, &load) != 0) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
mnodeAddIntField(bw, "numOfDnode", load.numOfDnode);
|
mndAddIntField(bw, "numOfDnode", load.numOfDnode);
|
||||||
mnodeAddIntField(bw, "numOfMnode", load.numOfMnode);
|
mndAddIntField(bw, "numOfMnode", load.numOfMnode);
|
||||||
mnodeAddIntField(bw, "numOfVgroup", load.numOfVgroup);
|
mndAddIntField(bw, "numOfVgroup", load.numOfVgroup);
|
||||||
mnodeAddIntField(bw, "numOfDatabase", load.numOfDatabase);
|
mndAddIntField(bw, "numOfDatabase", load.numOfDatabase);
|
||||||
mnodeAddIntField(bw, "numOfSuperTable", load.numOfSuperTable);
|
mndAddIntField(bw, "numOfSuperTable", load.numOfSuperTable);
|
||||||
mnodeAddIntField(bw, "numOfChildTable", load.numOfChildTable);
|
mndAddIntField(bw, "numOfChildTable", load.numOfChildTable);
|
||||||
mnodeAddIntField(bw, "numOfColumn", load.numOfColumn);
|
mndAddIntField(bw, "numOfColumn", load.numOfColumn);
|
||||||
mnodeAddIntField(bw, "numOfPoint", load.totalPoints);
|
mndAddIntField(bw, "numOfPoint", load.totalPoints);
|
||||||
mnodeAddIntField(bw, "totalStorage", load.totalStorage);
|
mndAddIntField(bw, "totalStorage", load.totalStorage);
|
||||||
mnodeAddIntField(bw, "compStorage", load.compStorage);
|
mndAddIntField(bw, "compStorage", load.compStorage);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void mnodeSendTelemetryReport() {
|
static void mndSendTelemetryReport() {
|
||||||
char buf[128] = {0};
|
char buf[128] = {0};
|
||||||
uint32_t ip = taosGetIpv4FromFqdn(TELEMETRY_SERVER);
|
uint32_t ip = taosGetIpv4FromFqdn(TELEMETRY_SERVER);
|
||||||
if (ip == 0xffffffff) {
|
if (ip == 0xffffffff) {
|
||||||
|
@ -203,20 +203,20 @@ static void mnodeSendTelemetryReport() {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
int64_t clusterId = mnodeGetClusterId();
|
int64_t clusterId = mndGetClusterId(NULL);
|
||||||
char clusterIdStr[20] = {0};
|
char clusterIdStr[20] = {0};
|
||||||
snprintf(clusterIdStr, sizeof(clusterIdStr), "%" PRId64, clusterId);
|
snprintf(clusterIdStr, sizeof(clusterIdStr), "%" PRId64, clusterId);
|
||||||
|
|
||||||
SBufferWriter bw = tbufInitWriter(NULL, false);
|
SBufferWriter bw = tbufInitWriter(NULL, false);
|
||||||
mnodeBeginObject(&bw);
|
mndBeginObject(&bw);
|
||||||
mnodeAddStringField(&bw, "instanceId", clusterIdStr);
|
mndAddStringField(&bw, "instanceId", clusterIdStr);
|
||||||
mnodeAddIntField(&bw, "reportVersion", 1);
|
mndAddIntField(&bw, "reportVersion", 1);
|
||||||
mnodeAddOsInfo(&bw);
|
mndAddOsInfo(&bw);
|
||||||
mnodeAddCpuInfo(&bw);
|
mndAddCpuInfo(&bw);
|
||||||
mnodeAddMemoryInfo(&bw);
|
mndAddMemoryInfo(&bw);
|
||||||
mnodeAddVersionInfo(&bw);
|
mndAddVersionInfo(&bw);
|
||||||
mnodeAddRuntimeInfo(&bw);
|
mndAddRuntimeInfo(&bw);
|
||||||
mnodeCloseObject(&bw);
|
mndCloseObject(&bw);
|
||||||
|
|
||||||
const char* header =
|
const char* header =
|
||||||
"POST /report HTTP/1.1\n"
|
"POST /report HTTP/1.1\n"
|
||||||
|
@ -240,12 +240,12 @@ static void mnodeSendTelemetryReport() {
|
||||||
taosCloseSocket(fd);
|
taosCloseSocket(fd);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void* mnodeTelemThreadFp(void* param) {
|
static void* mndTelemThreadFp(void* param) {
|
||||||
struct timespec end = {0};
|
struct timespec end = {0};
|
||||||
clock_gettime(CLOCK_REALTIME, &end);
|
clock_gettime(CLOCK_REALTIME, &end);
|
||||||
end.tv_sec += 300; // wait 5 minutes before send first report
|
end.tv_sec += 300; // wait 5 minutes before send first report
|
||||||
|
|
||||||
setThreadName("mnode-telem");
|
setThreadName("mnd-telem");
|
||||||
|
|
||||||
while (!tsTelem.exit) {
|
while (!tsTelem.exit) {
|
||||||
int32_t r = 0;
|
int32_t r = 0;
|
||||||
|
@ -256,8 +256,8 @@ static void* mnodeTelemThreadFp(void* param) {
|
||||||
if (r == 0) break;
|
if (r == 0) break;
|
||||||
if (r != ETIMEDOUT) continue;
|
if (r != ETIMEDOUT) continue;
|
||||||
|
|
||||||
if (mnodeIsMaster()) {
|
if (mndIsMaster(NULL)) {
|
||||||
mnodeSendTelemetryReport();
|
mndSendTelemetryReport();
|
||||||
}
|
}
|
||||||
end.tv_sec += REPORT_INTERVAL;
|
end.tv_sec += REPORT_INTERVAL;
|
||||||
}
|
}
|
||||||
|
@ -265,7 +265,7 @@ static void* mnodeTelemThreadFp(void* param) {
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void mnodeGetEmail(char* filepath) {
|
static void mndGetEmail(char* filepath) {
|
||||||
int32_t fd = taosOpenFileRead(filepath);
|
int32_t fd = taosOpenFileRead(filepath);
|
||||||
if (fd < 0) {
|
if (fd < 0) {
|
||||||
return;
|
return;
|
||||||
|
@ -278,7 +278,7 @@ static void mnodeGetEmail(char* filepath) {
|
||||||
taosCloseFile(fd);
|
taosCloseFile(fd);
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t mnodeInitTelem() {
|
int32_t mndInitTelem(SMnode *pMnode) {
|
||||||
tsTelem.enable = tsEnableTelemetryReporting;
|
tsTelem.enable = tsEnableTelemetryReporting;
|
||||||
if (!tsTelem.enable) return 0;
|
if (!tsTelem.enable) return 0;
|
||||||
|
|
||||||
|
@ -287,23 +287,23 @@ int32_t mnodeInitTelem() {
|
||||||
pthread_cond_init(&tsTelem.cond, NULL);
|
pthread_cond_init(&tsTelem.cond, NULL);
|
||||||
tsTelem.email[0] = 0;
|
tsTelem.email[0] = 0;
|
||||||
|
|
||||||
mnodeGetEmail("/usr/local/taos/email");
|
mndGetEmail("/usr/local/taos/email");
|
||||||
|
|
||||||
pthread_attr_t attr;
|
pthread_attr_t attr;
|
||||||
pthread_attr_init(&attr);
|
pthread_attr_init(&attr);
|
||||||
pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_JOINABLE);
|
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);
|
pthread_attr_destroy(&attr);
|
||||||
if (code != 0) {
|
if (code != 0) {
|
||||||
mTrace("failed to create telemetry thread since :%s", strerror(code));
|
mTrace("failed to create telemetry thread since :%s", strerror(code));
|
||||||
}
|
}
|
||||||
|
|
||||||
mInfo("mnode telemetry is initialized");
|
mInfo("mnd telemetry is initialized");
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void mnodeCleanupTelem() {
|
void mndCleanupTelem(SMnode *pMnode) {
|
||||||
if (!tsTelem.enable) return;
|
if (!tsTelem.enable) return;
|
||||||
|
|
||||||
if (taosCheckPthreadValid(tsTelem.thread)) {
|
if (taosCheckPthreadValid(tsTelem.thread)) {
|
|
@ -14,13 +14,13 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#define _DEFAULT_SOURCE
|
#define _DEFAULT_SOURCE
|
||||||
#include "mnodeTrans.h"
|
#include "mndTrans.h"
|
||||||
#include "trpc.h"
|
#include "trpc.h"
|
||||||
|
|
||||||
#define SDB_TRANS_VER 1
|
#define SDB_TRANS_VER 1
|
||||||
#define TRN_DEFAULT_ARRAY_SIZE 8
|
#define TRN_DEFAULT_ARRAY_SIZE 8
|
||||||
|
|
||||||
SSdbRaw *trnActionEncode(STrans *pTrans) {
|
SSdbRaw *mndTransActionEncode(STrans *pTrans) {
|
||||||
int32_t rawDataLen = 10 * sizeof(int32_t);
|
int32_t rawDataLen = 10 * sizeof(int32_t);
|
||||||
int32_t redoLogNum = taosArrayGetSize(pTrans->redoLogs);
|
int32_t redoLogNum = taosArrayGetSize(pTrans->redoLogs);
|
||||||
int32_t undoLogNum = taosArrayGetSize(pTrans->undoLogs);
|
int32_t undoLogNum = taosArrayGetSize(pTrans->undoLogs);
|
||||||
|
@ -28,18 +28,18 @@ SSdbRaw *trnActionEncode(STrans *pTrans) {
|
||||||
int32_t redoActionNum = taosArrayGetSize(pTrans->redoActions);
|
int32_t redoActionNum = taosArrayGetSize(pTrans->redoActions);
|
||||||
int32_t undoActionNum = taosArrayGetSize(pTrans->undoActions);
|
int32_t undoActionNum = taosArrayGetSize(pTrans->undoActions);
|
||||||
|
|
||||||
for (int32_t index = 0; index < redoLogNum; ++index) {
|
for (int32_t i = 0; i < redoLogNum; ++i) {
|
||||||
SSdbRaw *pTmp = taosArrayGet(pTrans->redoLogs, index);
|
SSdbRaw *pTmp = taosArrayGet(pTrans->redoLogs, i);
|
||||||
rawDataLen += sdbGetRawTotalSize(pTmp);
|
rawDataLen += sdbGetRawTotalSize(pTmp);
|
||||||
}
|
}
|
||||||
|
|
||||||
for (int32_t index = 0; index < undoLogNum; ++index) {
|
for (int32_t i = 0; i < undoLogNum; ++i) {
|
||||||
SSdbRaw *pTmp = taosArrayGet(pTrans->undoLogs, index);
|
SSdbRaw *pTmp = taosArrayGet(pTrans->undoLogs, i);
|
||||||
rawDataLen += sdbGetRawTotalSize(pTmp);
|
rawDataLen += sdbGetRawTotalSize(pTmp);
|
||||||
}
|
}
|
||||||
|
|
||||||
for (int32_t index = 0; index < commitLogNum; ++index) {
|
for (int32_t i = 0; i < commitLogNum; ++i) {
|
||||||
SSdbRaw *pTmp = taosArrayGet(pTrans->commitLogs, index);
|
SSdbRaw *pTmp = taosArrayGet(pTrans->commitLogs, i);
|
||||||
rawDataLen += sdbGetRawTotalSize(pTmp);
|
rawDataLen += sdbGetRawTotalSize(pTmp);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -59,22 +59,22 @@ SSdbRaw *trnActionEncode(STrans *pTrans) {
|
||||||
SDB_SET_INT32(pRaw, dataPos, redoActionNum)
|
SDB_SET_INT32(pRaw, dataPos, redoActionNum)
|
||||||
SDB_SET_INT32(pRaw, dataPos, undoActionNum)
|
SDB_SET_INT32(pRaw, dataPos, undoActionNum)
|
||||||
|
|
||||||
for (int32_t index = 0; index < redoLogNum; ++index) {
|
for (int32_t i = 0; i < redoLogNum; ++i) {
|
||||||
SSdbRaw *pTmp = taosArrayGet(pTrans->redoLogs, index);
|
SSdbRaw *pTmp = taosArrayGet(pTrans->redoLogs, i);
|
||||||
int32_t len = sdbGetRawTotalSize(pTmp);
|
int32_t len = sdbGetRawTotalSize(pTmp);
|
||||||
SDB_SET_INT32(pRaw, dataPos, len)
|
SDB_SET_INT32(pRaw, dataPos, len)
|
||||||
SDB_SET_BINARY(pRaw, dataPos, (void *)pTmp, len)
|
SDB_SET_BINARY(pRaw, dataPos, (void *)pTmp, len)
|
||||||
}
|
}
|
||||||
|
|
||||||
for (int32_t index = 0; index < undoLogNum; ++index) {
|
for (int32_t i = 0; i < undoLogNum; ++i) {
|
||||||
SSdbRaw *pTmp = taosArrayGet(pTrans->undoLogs, index);
|
SSdbRaw *pTmp = taosArrayGet(pTrans->undoLogs, i);
|
||||||
int32_t len = sdbGetRawTotalSize(pTmp);
|
int32_t len = sdbGetRawTotalSize(pTmp);
|
||||||
SDB_SET_INT32(pRaw, dataPos, len)
|
SDB_SET_INT32(pRaw, dataPos, len)
|
||||||
SDB_SET_BINARY(pRaw, dataPos, (void *)pTmp, len)
|
SDB_SET_BINARY(pRaw, dataPos, (void *)pTmp, len)
|
||||||
}
|
}
|
||||||
|
|
||||||
for (int32_t index = 0; index < commitLogNum; ++index) {
|
for (int32_t i = 0; i < commitLogNum; ++i) {
|
||||||
SSdbRaw *pTmp = taosArrayGet(pTrans->commitLogs, index);
|
SSdbRaw *pTmp = taosArrayGet(pTrans->commitLogs, i);
|
||||||
int32_t len = sdbGetRawTotalSize(pTmp);
|
int32_t len = sdbGetRawTotalSize(pTmp);
|
||||||
SDB_SET_INT32(pRaw, dataPos, len)
|
SDB_SET_INT32(pRaw, dataPos, len)
|
||||||
SDB_SET_BINARY(pRaw, dataPos, (void *)pTmp, len)
|
SDB_SET_BINARY(pRaw, dataPos, (void *)pTmp, len)
|
||||||
|
@ -84,7 +84,7 @@ SSdbRaw *trnActionEncode(STrans *pTrans) {
|
||||||
return pRaw;
|
return pRaw;
|
||||||
}
|
}
|
||||||
|
|
||||||
SSdbRow *trnActionDecode(SSdbRaw *pRaw) {
|
SSdbRow *mndTransActionDecode(SSdbRaw *pRaw) {
|
||||||
int8_t sver = 0;
|
int8_t sver = 0;
|
||||||
if (sdbGetRawSoftVer(pRaw, &sver) != 0) {
|
if (sdbGetRawSoftVer(pRaw, &sver) != 0) {
|
||||||
mError("failed to get soft ver from raw:%p since %s", pRaw, terrstr());
|
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)
|
SDB_GET_INT32(pRaw, pRow, dataPos, &undoActionNum)
|
||||||
|
|
||||||
int32_t code = 0;
|
int32_t code = 0;
|
||||||
for (int32_t index = 0; index < redoLogNum; ++index) {
|
for (int32_t i = 0; i < redoLogNum; ++i) {
|
||||||
int32_t dataLen = 0;
|
int32_t dataLen = 0;
|
||||||
SDB_GET_INT32(pRaw, pRow, dataPos, &dataLen)
|
SDB_GET_INT32(pRaw, pRow, dataPos, &dataLen)
|
||||||
|
|
||||||
|
@ -150,7 +150,7 @@ SSdbRow *trnActionDecode(SSdbRaw *pRaw) {
|
||||||
if (code != 0) {
|
if (code != 0) {
|
||||||
terrno = code;
|
terrno = code;
|
||||||
mError("trn:%d, failed to parse from raw:%p since %s", pTrans->id, pRaw, terrstr());
|
mError("trn:%d, failed to parse from raw:%p since %s", pTrans->id, pRaw, terrstr());
|
||||||
trnDrop(pTrans);
|
mndTransDrop(pTrans);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -158,13 +158,13 @@ SSdbRow *trnActionDecode(SSdbRaw *pRaw) {
|
||||||
return pRow;
|
return pRow;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int32_t trnActionInsert(STrans *pTrans) {
|
static int32_t mndTransActionInsert(SSdb *pSdb, STrans *pTrans) {
|
||||||
SArray *pArray = pTrans->redoLogs;
|
SArray *pArray = pTrans->redoLogs;
|
||||||
int32_t arraySize = taosArrayGetSize(pArray);
|
int32_t arraySize = taosArrayGetSize(pArray);
|
||||||
|
|
||||||
for (int32_t index = 0; index < arraySize; ++index) {
|
for (int32_t i = 0; i < arraySize; ++i) {
|
||||||
SSdbRaw *pRaw = taosArrayGet(pArray, index);
|
SSdbRaw *pRaw = taosArrayGet(pArray, i);
|
||||||
int32_t code = sdbWrite(pRaw);
|
int32_t code = sdbWrite(pSdb, pRaw);
|
||||||
if (code != 0) {
|
if (code != 0) {
|
||||||
mError("trn:%d, failed to write raw:%p to sdb since %s", pTrans->id, pRaw, terrstr());
|
mError("trn:%d, failed to write raw:%p to sdb since %s", pTrans->id, pRaw, terrstr());
|
||||||
return code;
|
return code;
|
||||||
|
@ -175,13 +175,13 @@ static int32_t trnActionInsert(STrans *pTrans) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int32_t trnActionDelete(STrans *pTrans) {
|
static int32_t mndTransActionDelete(SSdb *pSdb, STrans *pTrans) {
|
||||||
SArray *pArray = pTrans->redoLogs;
|
SArray *pArray = pTrans->redoLogs;
|
||||||
int32_t arraySize = taosArrayGetSize(pArray);
|
int32_t arraySize = taosArrayGetSize(pArray);
|
||||||
|
|
||||||
for (int32_t index = 0; index < arraySize; ++index) {
|
for (int32_t i = 0; i < arraySize; ++i) {
|
||||||
SSdbRaw *pRaw = taosArrayGet(pArray, index);
|
SSdbRaw *pRaw = taosArrayGet(pArray, i);
|
||||||
int32_t code = sdbWrite(pRaw);
|
int32_t code = sdbWrite(pSdb, pRaw);
|
||||||
if (code != 0) {
|
if (code != 0) {
|
||||||
mError("trn:%d, failed to write raw:%p to sdb since %s", pTrans->id, pRaw, terrstr());
|
mError("trn:%d, failed to write raw:%p to sdb since %s", pTrans->id, pRaw, terrstr());
|
||||||
return code;
|
return code;
|
||||||
|
@ -192,14 +192,14 @@ static int32_t trnActionDelete(STrans *pTrans) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int32_t trnActionUpdate(STrans *pTrans, STrans *pDstTrans) {
|
static int32_t mndTransActionUpdate(SSdb *pSdb, STrans *pTrans, STrans *pDstTrans) {
|
||||||
assert(true);
|
assert(true);
|
||||||
SArray *pArray = pTrans->redoLogs;
|
SArray *pArray = pTrans->redoLogs;
|
||||||
int32_t arraySize = taosArrayGetSize(pArray);
|
int32_t arraySize = taosArrayGetSize(pArray);
|
||||||
|
|
||||||
for (int32_t index = 0; index < arraySize; ++index) {
|
for (int32_t i = 0; i < arraySize; ++i) {
|
||||||
SSdbRaw *pRaw = taosArrayGet(pArray, index);
|
SSdbRaw *pRaw = taosArrayGet(pArray, i);
|
||||||
int32_t code = sdbWrite(pRaw);
|
int32_t code = sdbWrite(pSdb, pRaw);
|
||||||
if (code != 0) {
|
if (code != 0) {
|
||||||
mError("trn:%d, failed to write raw:%p to sdb since %s", pTrans->id, pRaw, terrstr());
|
mError("trn:%d, failed to write raw:%p to sdb since %s", pTrans->id, pRaw, terrstr());
|
||||||
return code;
|
return code;
|
||||||
|
@ -213,7 +213,7 @@ static int32_t trnActionUpdate(STrans *pTrans, STrans *pDstTrans) {
|
||||||
|
|
||||||
static int32_t trnGenerateTransId() { return 1; }
|
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));
|
STrans *pTrans = calloc(1, sizeof(STrans));
|
||||||
if (pTrans == NULL) {
|
if (pTrans == NULL) {
|
||||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||||
|
@ -243,15 +243,15 @@ STrans *trnCreate(ETrnPolicy policy, void *rpcHandle) {
|
||||||
}
|
}
|
||||||
|
|
||||||
static void trnDropArray(SArray *pArray) {
|
static void trnDropArray(SArray *pArray) {
|
||||||
for (int32_t index = 0; index < pArray->size; ++index) {
|
for (int32_t i = 0; i < pArray->size; ++i) {
|
||||||
SSdbRaw *pRaw = taosArrayGet(pArray, index);
|
SSdbRaw *pRaw = taosArrayGet(pArray, i);
|
||||||
tfree(pRaw);
|
tfree(pRaw);
|
||||||
}
|
}
|
||||||
|
|
||||||
taosArrayDestroy(pArray);
|
taosArrayDestroy(pArray);
|
||||||
}
|
}
|
||||||
|
|
||||||
void trnDrop(STrans *pTrans) {
|
void mndTransDrop(STrans *pTrans) {
|
||||||
trnDropArray(pTrans->redoLogs);
|
trnDropArray(pTrans->redoLogs);
|
||||||
trnDropArray(pTrans->undoLogs);
|
trnDropArray(pTrans->undoLogs);
|
||||||
trnDropArray(pTrans->commitLogs);
|
trnDropArray(pTrans->commitLogs);
|
||||||
|
@ -262,12 +262,12 @@ void trnDrop(STrans *pTrans) {
|
||||||
tfree(pTrans);
|
tfree(pTrans);
|
||||||
}
|
}
|
||||||
|
|
||||||
void trnSetRpcHandle(STrans *pTrans, void *rpcHandle) {
|
void mndTransSetRpcHandle(STrans *pTrans, void *rpcHandle) {
|
||||||
pTrans->rpcHandle = rpcHandle;
|
pTrans->rpcHandle = rpcHandle;
|
||||||
mTrace("trn:%d, set rpc handle:%p", pTrans->id, 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) {
|
if (pArray == NULL || pRaw == NULL) {
|
||||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||||
return -1;
|
return -1;
|
||||||
|
@ -282,64 +282,61 @@ static int32_t trnAppendArray(SArray *pArray, SSdbRaw *pRaw) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t trnAppendRedoLog(STrans *pTrans, SSdbRaw *pRaw) {
|
int32_t mndTransAppendRedolog(STrans *pTrans, SSdbRaw *pRaw) {
|
||||||
int32_t code = trnAppendArray(pTrans->redoLogs, pRaw);
|
int32_t code = mndTransAppendArray(pTrans->redoLogs, pRaw);
|
||||||
mTrace("trn:%d, raw:%p append to redo logs, code:%d", pTrans->id, pRaw, code);
|
mTrace("trn:%d, raw:%p append to redo logs, code:%d", pTrans->id, pRaw, code);
|
||||||
return code;
|
return code;
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t trnAppendUndoLog(STrans *pTrans, SSdbRaw *pRaw) {
|
int32_t mndTransAppendUndolog(STrans *pTrans, SSdbRaw *pRaw) {
|
||||||
int32_t code = trnAppendArray(pTrans->undoLogs, pRaw);
|
int32_t code = mndTransAppendArray(pTrans->undoLogs, pRaw);
|
||||||
mTrace("trn:%d, raw:%p append to undo logs, code:%d", pTrans->id, pRaw, code);
|
mTrace("trn:%d, raw:%p append to undo logs, code:%d", pTrans->id, pRaw, code);
|
||||||
return code;
|
return code;
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t trnAppendCommitLog(STrans *pTrans, SSdbRaw *pRaw) {
|
int32_t mndTransAppendCommitlog(STrans *pTrans, SSdbRaw *pRaw) {
|
||||||
int32_t code = trnAppendArray(pTrans->commitLogs, pRaw);
|
int32_t code = mndTransAppendArray(pTrans->commitLogs, pRaw);
|
||||||
mTrace("trn:%d, raw:%p append to commit logs, code:%d", pTrans->id, pRaw, code);
|
mTrace("trn:%d, raw:%p append to commit logs, code:%d", pTrans->id, pRaw, code);
|
||||||
return code;
|
return code;
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t trnAppendRedoAction(STrans *pTrans, SEpSet *pEpSet, void *pMsg) {
|
int32_t mndTransAppendRedoAction(STrans *pTrans, SEpSet *pEpSet, void *pMsg) {
|
||||||
int32_t code = trnAppendArray(pTrans->redoActions, pMsg);
|
int32_t code = mndTransAppendArray(pTrans->redoActions, pMsg);
|
||||||
mTrace("trn:%d, msg:%p append to redo actions", pTrans->id, pMsg);
|
mTrace("trn:%d, msg:%p append to redo actions", pTrans->id, pMsg);
|
||||||
return code;
|
return code;
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t trnAppendUndoAction(STrans *pTrans, SEpSet *pEpSet, void *pMsg) {
|
int32_t mndTransAppendUndoAction(STrans *pTrans, SEpSet *pEpSet, void *pMsg) {
|
||||||
int32_t code = trnAppendArray(pTrans->undoActions, pMsg);
|
int32_t code = mndTransAppendArray(pTrans->undoActions, pMsg);
|
||||||
mTrace("trn:%d, msg:%p append to undo actions", pTrans->id, pMsg);
|
mTrace("trn:%d, msg:%p append to undo actions", pTrans->id, pMsg);
|
||||||
return code;
|
return code;
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t mnodeInitTrans() {
|
int32_t mndInitTrans(SMnode *pMnode) {
|
||||||
SSdbTable table = {.sdbType = SDB_TRANS,
|
SSdbTable table = {.sdbType = SDB_TRANS,
|
||||||
.keyType = SDB_KEY_INT32,
|
.keyType = SDB_KEY_INT32,
|
||||||
.encodeFp = (SdbEncodeFp)trnActionEncode,
|
.encodeFp = (SdbEncodeFp)mndTransActionEncode,
|
||||||
.decodeFp = (SdbDecodeFp)trnActionDecode,
|
.decodeFp = (SdbDecodeFp)mndTransActionDecode,
|
||||||
.insertFp = (SdbInsertFp)trnActionInsert,
|
.insertFp = (SdbInsertFp)mndTransActionInsert,
|
||||||
.updateFp = (SdbUpdateFp)trnActionUpdate,
|
.updateFp = (SdbUpdateFp)mndTransActionUpdate,
|
||||||
.deleteFp = (SdbDeleteFp)trnActionDelete};
|
.deleteFp = (SdbDeleteFp)mndTransActionDelete};
|
||||||
sdbSetTable(table);
|
|
||||||
|
|
||||||
mInfo("trn module is initialized");
|
return sdbSetTable(pMnode->pSdb, table);
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void mnodeCleanupTrans() { mInfo("trn module is cleaned up"); }
|
void mndCleanupTrans(SMnode *pMnode) {}
|
||||||
|
|
||||||
|
int32_t mndTransPrepare(STrans *pTrans, int32_t (*syncfp)(SSdbRaw *pRaw, void *pData)) {
|
||||||
int32_t trnPrepare(STrans *pTrans, int32_t (*syncfp)(SSdbRaw *pRaw, void *pData)) {
|
|
||||||
if (syncfp == NULL) return -1;
|
if (syncfp == NULL) return -1;
|
||||||
|
|
||||||
SSdbRaw *pRaw = trnActionEncode(pTrans);
|
SSdbRaw *pRaw = mndTransActionEncode(pTrans);
|
||||||
if (pRaw == NULL) {
|
if (pRaw == NULL) {
|
||||||
mError("trn:%d, failed to decode trans since %s", pTrans->id, terrstr());
|
mError("trn:%d, failed to decode trans since %s", pTrans->id, terrstr());
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
sdbSetRawStatus(pRaw, SDB_STATUS_CREATING);
|
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());
|
mError("trn:%d, failed to write trans since %s", pTrans->id, terrstr());
|
||||||
return -1;
|
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) {
|
if (code != 0) {
|
||||||
trnSendRpcRsp(pData, terrno);
|
trnSendRpcRsp(pData, terrno);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (sdbWrite(pData) != 0) {
|
if (sdbWrite(pMnode->pSdb, pData) != 0) {
|
||||||
code = terrno;
|
code = terrno;
|
||||||
trnSendRpcRsp(pData, code);
|
trnSendRpcRsp(pData, code);
|
||||||
terrno = code;
|
terrno = code;
|
||||||
|
@ -375,10 +372,10 @@ int32_t trnApply(SSdbRaw *pRaw, void *pData, int32_t code) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int32_t trnExecuteArray(SArray *pArray) {
|
static int32_t trnExecuteArray(SMnode *pMnode, SArray *pArray) {
|
||||||
for (int32_t index = 0; index < pArray->size; ++index) {
|
for (int32_t i = 0; i < pArray->size; ++i) {
|
||||||
SSdbRaw *pRaw = taosArrayGetP(pArray, index);
|
SSdbRaw *pRaw = taosArrayGetP(pArray, i);
|
||||||
if (sdbWrite(pRaw) != 0) {
|
if (sdbWrite(pMnode->pSdb, pRaw) != 0) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -386,15 +383,15 @@ static int32_t trnExecuteArray(SArray *pArray) {
|
||||||
return 0;
|
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) {
|
static int32_t trnPerformPrepareStage(STrans *pTrans) {
|
||||||
if (trnExecuteRedoLogs(pTrans) == 0) {
|
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;
|
int32_t code = 0;
|
||||||
|
|
||||||
STrans *pTrans = sdbAcquire(SDB_TRANS, &tranId);
|
STrans *pTrans = sdbAcquire(pSdb, SDB_TRANS, &tranId);
|
||||||
if (pTrans == NULL) {
|
if (pTrans == NULL) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (pTrans->stage == TRN_STAGE_PREPARE) {
|
if (pTrans->stage == TRN_STAGE_PREPARE) {
|
||||||
if (trnPerformPrepareStage(pTrans) != 0) {
|
if (trnPerformPrepareStage(pTrans) != 0) {
|
||||||
sdbRelease(pTrans);
|
sdbRelease(pSdb, pTrans);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (pTrans->stage == TRN_STAGE_EXECUTE) {
|
if (pTrans->stage == TRN_STAGE_EXECUTE) {
|
||||||
if (trnPerformExecuteStage(pTrans) != 0) {
|
if (trnPerformExecuteStage(pTrans) != 0) {
|
||||||
sdbRelease(pTrans);
|
sdbRelease(pSdb, pTrans);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (pTrans->stage == TRN_STAGE_COMMIT) {
|
if (pTrans->stage == TRN_STAGE_COMMIT) {
|
||||||
if (trnPerformCommitStage(pTrans) != 0) {
|
if (trnPerformCommitStage(pTrans) != 0) {
|
||||||
sdbRelease(pTrans);
|
sdbRelease(pSdb, pTrans);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (pTrans->stage == TRN_STAGE_ROLLBACK) {
|
if (pTrans->stage == TRN_STAGE_ROLLBACK) {
|
||||||
if (trnPerformRollbackStage(pTrans) != 0) {
|
if (trnPerformRollbackStage(pTrans) != 0) {
|
||||||
sdbRelease(pTrans);
|
sdbRelease(pSdb, pTrans);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (pTrans->stage == TRN_STAGE_RETRY) {
|
if (pTrans->stage == TRN_STAGE_RETRY) {
|
||||||
if (trnPerformRetryStage(pTrans) != 0) {
|
if (trnPerformRetryStage(pTrans) != 0) {
|
||||||
sdbRelease(pTrans);
|
sdbRelease(pSdb, pTrans);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
sdbRelease(pTrans);
|
sdbRelease(pSdb, pTrans);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
|
@ -14,15 +14,13 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#define _DEFAULT_SOURCE
|
#define _DEFAULT_SOURCE
|
||||||
#include "mnodeSync.h"
|
#include "mndSync.h"
|
||||||
#include "os.h"
|
|
||||||
#include "tglobal.h"
|
|
||||||
#include "tkey.h"
|
#include "tkey.h"
|
||||||
#include "mnodeTrans.h"
|
#include "mndTrans.h"
|
||||||
|
|
||||||
#define SDB_USER_VER 1
|
#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));
|
SSdbRaw *pRaw = sdbAllocRaw(SDB_USER, SDB_USER_VER, sizeof(SAcctObj));
|
||||||
if (pRaw == NULL) return NULL;
|
if (pRaw == NULL) return NULL;
|
||||||
|
|
||||||
|
@ -38,7 +36,7 @@ static SSdbRaw *mnodeUserActionEncode(SUserObj *pUser) {
|
||||||
return pRaw;
|
return pRaw;
|
||||||
}
|
}
|
||||||
|
|
||||||
static SSdbRow *mnodeUserActionDecode(SSdbRaw *pRaw) {
|
static SSdbRow *mndUserActionDecode(SSdbRaw *pRaw) {
|
||||||
int8_t sver = 0;
|
int8_t sver = 0;
|
||||||
if (sdbGetRawSoftVer(pRaw, &sver) != 0) return NULL;
|
if (sdbGetRawSoftVer(pRaw, &sver) != 0) return NULL;
|
||||||
|
|
||||||
|
@ -62,14 +60,14 @@ static SSdbRow *mnodeUserActionDecode(SSdbRaw *pRaw) {
|
||||||
return pRow;
|
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);
|
pUser->prohibitDbHash = taosHashInit(8, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BINARY), true, HASH_ENTRY_LOCK);
|
||||||
if (pUser->prohibitDbHash == NULL) {
|
if (pUser->prohibitDbHash == NULL) {
|
||||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
pUser->pAcct = sdbAcquire(SDB_ACCT, pUser->acct);
|
pUser->pAcct = sdbAcquire(pSdb, SDB_ACCT, pUser->acct);
|
||||||
if (pUser->pAcct == NULL) {
|
if (pUser->pAcct == NULL) {
|
||||||
terrno = TSDB_CODE_MND_ACCT_NOT_EXIST;
|
terrno = TSDB_CODE_MND_ACCT_NOT_EXIST;
|
||||||
return -1;
|
return -1;
|
||||||
|
@ -78,28 +76,28 @@ static int32_t mnodeUserActionInsert(SUserObj *pUser) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int32_t mnodeUserActionDelete(SUserObj *pUser) {
|
static int32_t mndUserActionDelete(SSdb *pSdb, SUserObj *pUser) {
|
||||||
if (pUser->prohibitDbHash) {
|
if (pUser->prohibitDbHash) {
|
||||||
taosHashCleanup(pUser->prohibitDbHash);
|
taosHashCleanup(pUser->prohibitDbHash);
|
||||||
pUser->prohibitDbHash = NULL;
|
pUser->prohibitDbHash = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (pUser->acct != NULL) {
|
if (pUser->acct != NULL) {
|
||||||
sdbRelease(pUser->pAcct);
|
sdbRelease(pSdb, pUser->pAcct);
|
||||||
pUser->pAcct = NULL;
|
pUser->pAcct = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int32_t mnodeUserActionUpdate(SUserObj *pSrcUser, SUserObj *pDstUser) {
|
static int32_t mndUserActionUpdate(SSdb *pSdb, SUserObj *pSrcUser, SUserObj *pDstUser) {
|
||||||
SUserObj tObj;
|
SUserObj tObj;
|
||||||
int32_t len = (int32_t)((int8_t *)tObj.prohibitDbHash - (int8_t *)&tObj);
|
int32_t len = (int32_t)((int8_t *)tObj.prohibitDbHash - (int8_t *)&tObj);
|
||||||
memcpy(pDstUser, pSrcUser, len);
|
memcpy(pDstUser, pSrcUser, len);
|
||||||
return 0;
|
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};
|
SUserObj userObj = {0};
|
||||||
tstrncpy(userObj.user, user, TSDB_USER_LEN);
|
tstrncpy(userObj.user, user, TSDB_USER_LEN);
|
||||||
tstrncpy(userObj.acct, acct, 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;
|
userObj.rootAuth = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
SSdbRaw *pRaw = mnodeUserActionEncode(&userObj);
|
SSdbRaw *pRaw = mndUserActionEncode(&userObj);
|
||||||
if (pRaw == NULL) return -1;
|
if (pRaw == NULL) return -1;
|
||||||
sdbSetRawStatus(pRaw, SDB_STATUS_READY);
|
sdbSetRawStatus(pRaw, SDB_STATUS_READY);
|
||||||
|
|
||||||
return sdbWrite(pRaw);
|
return sdbWrite(pSdb, pRaw);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int32_t mnodeCreateDefaultUsers() {
|
static int32_t mndCreateDefaultUsers(SSdb *pSdb) {
|
||||||
if (mnodeCreateDefaultUser(TSDB_DEFAULT_USER, TSDB_DEFAULT_USER, TSDB_DEFAULT_PASS) != 0) {
|
if (mndCreateDefaultUser(pSdb, TSDB_DEFAULT_USER, TSDB_DEFAULT_USER, TSDB_DEFAULT_PASS) != 0) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (mnodeCreateDefaultUser(TSDB_DEFAULT_USER, "monitor", tsInternalPass) != 0) {
|
if (mndCreateDefaultUser(pSdb, TSDB_DEFAULT_USER, "_" TSDB_DEFAULT_USER, TSDB_DEFAULT_PASS) != 0) {
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (mnodeCreateDefaultUser(TSDB_DEFAULT_USER, "_" TSDB_DEFAULT_USER, tsInternalPass) != 0) {
|
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
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};
|
SUserObj userObj = {0};
|
||||||
tstrncpy(userObj.user, user, TSDB_USER_LEN);
|
tstrncpy(userObj.user, user, TSDB_USER_LEN);
|
||||||
tstrncpy(userObj.acct, acct, 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.updateTime = userObj.createdTime;
|
||||||
userObj.rootAuth = 0;
|
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;
|
if (pTrans == NULL) return -1;
|
||||||
|
|
||||||
SSdbRaw *pRedoRaw = mnodeUserActionEncode(&userObj);
|
SSdbRaw *pRedoRaw = mndUserActionEncode(&userObj);
|
||||||
if (pRedoRaw == NULL || trnAppendRedoLog(pTrans, pRedoRaw) != 0) {
|
if (pRedoRaw == NULL || mndTransAppendRedolog(pTrans, pRedoRaw) != 0) {
|
||||||
mError("failed to append redo log since %s", terrstr());
|
mError("failed to append redo log since %s", terrstr());
|
||||||
trnDrop(pTrans);
|
mndTransDrop(pTrans);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
sdbSetRawStatus(pRedoRaw, SDB_STATUS_CREATING);
|
sdbSetRawStatus(pRedoRaw, SDB_STATUS_CREATING);
|
||||||
|
|
||||||
SSdbRaw *pUndoRaw = mnodeUserActionEncode(&userObj);
|
SSdbRaw *pUndoRaw = mndUserActionEncode(&userObj);
|
||||||
if (pUndoRaw == NULL || trnAppendUndoLog(pTrans, pUndoRaw) != 0) {
|
if (pUndoRaw == NULL || mndTransAppendUndolog(pTrans, pUndoRaw) != 0) {
|
||||||
mError("failed to append undo log since %s", terrstr());
|
mError("failed to append undo log since %s", terrstr());
|
||||||
trnDrop(pTrans);
|
mndTransDrop(pTrans);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
sdbSetRawStatus(pUndoRaw, SDB_STATUS_DROPPED);
|
sdbSetRawStatus(pUndoRaw, SDB_STATUS_DROPPED);
|
||||||
|
|
||||||
SSdbRaw *pCommitRaw = mnodeUserActionEncode(&userObj);
|
SSdbRaw *pCommitRaw = mndUserActionEncode(&userObj);
|
||||||
if (pCommitRaw == NULL || trnAppendCommitLog(pTrans, pCommitRaw) != 0) {
|
if (pCommitRaw == NULL || mndTransAppendCommitlog(pTrans, pCommitRaw) != 0) {
|
||||||
mError("failed to append commit log since %s", terrstr());
|
mError("failed to append commit log since %s", terrstr());
|
||||||
trnDrop(pTrans);
|
mndTransDrop(pTrans);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
sdbSetRawStatus(pCommitRaw, SDB_STATUS_READY);
|
sdbSetRawStatus(pCommitRaw, SDB_STATUS_READY);
|
||||||
|
|
||||||
if (trnPrepare(pTrans, mnodeSyncPropose) != 0) {
|
if (mndTransPrepare(pTrans, mndSyncPropose) != 0) {
|
||||||
trnDrop(pTrans);
|
mndTransDrop(pTrans);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
trnDrop(pTrans);
|
mndTransDrop(pTrans);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int32_t mnodeProcessCreateUserMsg(SMnodeMsg *pMsg) {
|
static int32_t mndProcessCreateUserMsg(SMnode *pMnode, SMnodeMsg *pMsg) {
|
||||||
SCreateUserMsg *pCreate = pMsg->rpcMsg.pCont;
|
SCreateUserMsg *pCreate = pMsg->rpcMsg.pCont;
|
||||||
|
|
||||||
if (pCreate->user[0] == 0) {
|
if (pCreate->user[0] == 0) {
|
||||||
|
@ -194,23 +188,23 @@ static int32_t mnodeProcessCreateUserMsg(SMnodeMsg *pMsg) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
SUserObj *pUser = sdbAcquire(SDB_USER, pCreate->user);
|
SUserObj *pUser = sdbAcquire(pMnode->pSdb, SDB_USER, pCreate->user);
|
||||||
if (pUser != NULL) {
|
if (pUser != NULL) {
|
||||||
sdbRelease(pUser);
|
sdbRelease(pMnode->pSdb, pUser);
|
||||||
terrno = TSDB_CODE_MND_USER_ALREADY_EXIST;
|
terrno = TSDB_CODE_MND_USER_ALREADY_EXIST;
|
||||||
mError("user:%s, failed to create since %s", pCreate->user, terrstr());
|
mError("user:%s, failed to create since %s", pCreate->user, terrstr());
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
SUserObj *pOperUser = sdbAcquire(SDB_USER, pMsg->conn.user);
|
SUserObj *pOperUser = sdbAcquire(pMnode->pSdb, SDB_USER, pMsg->conn.user);
|
||||||
if (pOperUser == NULL) {
|
if (pOperUser == NULL) {
|
||||||
terrno = TSDB_CODE_MND_NO_USER_FROM_CONN;
|
terrno = TSDB_CODE_MND_NO_USER_FROM_CONN;
|
||||||
mError("user:%s, failed to create since %s", pCreate->user, terrstr());
|
mError("user:%s, failed to create since %s", pCreate->user, terrstr());
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t code = mnodeCreateUser(pOperUser->acct, pCreate->user, pCreate->pass, pMsg);
|
int32_t code = mndCreateUser(pMnode, pOperUser->acct, pCreate->user, pCreate->pass, pMsg);
|
||||||
sdbRelease(pOperUser);
|
sdbRelease(pMnode->pSdb, pOperUser);
|
||||||
|
|
||||||
if (code != 0) {
|
if (code != 0) {
|
||||||
mError("user:%s, failed to create since %s", pCreate->user, terrstr());
|
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;
|
return TSDB_CODE_MND_ACTION_IN_PROGRESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t mnodeInitUser() {
|
int32_t mndInitUser(SMnode *pMnode) {
|
||||||
SSdbTable table = {.sdbType = SDB_USER,
|
SSdbTable table = {.sdbType = SDB_USER,
|
||||||
.keyType = SDB_KEY_BINARY,
|
.keyType = SDB_KEY_BINARY,
|
||||||
.deployFp = (SdbDeployFp)mnodeCreateDefaultUsers,
|
.deployFp = (SdbDeployFp)mndCreateDefaultUsers,
|
||||||
.encodeFp = (SdbEncodeFp)mnodeUserActionEncode,
|
.encodeFp = (SdbEncodeFp)mndUserActionEncode,
|
||||||
.decodeFp = (SdbDecodeFp)mnodeUserActionDecode,
|
.decodeFp = (SdbDecodeFp)mndUserActionDecode,
|
||||||
.insertFp = (SdbInsertFp)mnodeUserActionInsert,
|
.insertFp = (SdbInsertFp)mndUserActionInsert,
|
||||||
.updateFp = (SdbUpdateFp)mnodeUserActionUpdate,
|
.updateFp = (SdbUpdateFp)mndUserActionUpdate,
|
||||||
.deleteFp = (SdbDeleteFp)mnodeUserActionDelete};
|
.deleteFp = (SdbDeleteFp)mndUserActionDelete};
|
||||||
sdbSetTable(table);
|
|
||||||
|
|
||||||
mnodeSetMsgFp(TSDB_MSG_TYPE_CREATE_USER, mnodeProcessCreateUserMsg);
|
mndSetMsgHandle(pMnode, TSDB_MSG_TYPE_CREATE_USER, mndProcessCreateUserMsg);
|
||||||
|
|
||||||
return 0;
|
return sdbSetTable(pMnode->pSdb, table);
|
||||||
}
|
}
|
||||||
|
|
||||||
void mnodeCleanupUser() {}
|
void mndCleanupUser(SMnode *pMnode) {}
|
|
@ -0,0 +1,21 @@
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com>
|
||||||
|
*
|
||||||
|
* 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 <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#define _DEFAULT_SOURCE
|
||||||
|
#include "os.h"
|
||||||
|
#include "mndInt.h"
|
||||||
|
|
||||||
|
int32_t mndInitVgroup(SMnode *pMnode) { return 0; }
|
||||||
|
void mndCleanupVgroup(SMnode *pMnode) {}
|
|
@ -14,83 +14,225 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#define _DEFAULT_SOURCE
|
#define _DEFAULT_SOURCE
|
||||||
#include "os.h"
|
#include "mndAcct.h"
|
||||||
#include "tglobal.h"
|
#include "mndAuth.h"
|
||||||
#include "tqueue.h"
|
#include "mndBalance.h"
|
||||||
#include "mnodeAcct.h"
|
#include "mndCluster.h"
|
||||||
#include "mnodeAuth.h"
|
#include "mndDb.h"
|
||||||
#include "mnodeBalance.h"
|
#include "mndDnode.h"
|
||||||
#include "mnodeCluster.h"
|
#include "mndFunc.h"
|
||||||
#include "mnodeDb.h"
|
#include "mndMnode.h"
|
||||||
#include "mnodeDnode.h"
|
#include "mndOper.h"
|
||||||
#include "mnodeFunc.h"
|
#include "mndProfile.h"
|
||||||
#include "mnodeMnode.h"
|
#include "mndShow.h"
|
||||||
#include "mnodeOper.h"
|
#include "mndStable.h"
|
||||||
#include "mnodeProfile.h"
|
#include "mndSync.h"
|
||||||
#include "mnodeShow.h"
|
#include "mndTelem.h"
|
||||||
#include "mnodeStable.h"
|
#include "mndTrans.h"
|
||||||
#include "mnodeSync.h"
|
#include "mndUser.h"
|
||||||
#include "mnodeTelem.h"
|
#include "mndVgroup.h"
|
||||||
#include "mnodeTrans.h"
|
|
||||||
#include "mnodeUser.h"
|
|
||||||
#include "mnodeVgroup.h"
|
|
||||||
|
|
||||||
SMnodeBak tsMint = {0};
|
int32_t mndGetDnodeId(SMnode *pMnode) {
|
||||||
|
if (pMnode != NULL) {
|
||||||
int32_t mnodeGetDnodeId() { return tsMint.para.dnodeId; }
|
return pMnode->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");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
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 -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void mnodeCleanupTimer() {
|
static void mndCleanupTimer(SMnode *pMnode) {
|
||||||
if (tsMint.timer != NULL) {
|
if (pMnode->timer != NULL) {
|
||||||
taosTmrCleanUp(tsMint.timer);
|
taosTmrCleanUp(pMnode->timer);
|
||||||
tsMint.timer = NULL;
|
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->dnodeId = pOption->dnodeId;
|
||||||
pMnode->clusterId = pOption->clusterId;
|
pMnode->clusterId = pOption->clusterId;
|
||||||
pMnode->replica = pOption->replica;
|
pMnode->replica = pOption->replica;
|
||||||
pMnode->selfIndex = pOption->selfIndex;
|
pMnode->selfIndex = pOption->selfIndex;
|
||||||
memcpy(&pMnode->replicas, pOption->replicas, sizeof(SReplica) * TSDB_MAX_REPLICA);
|
memcpy(&pMnode->replicas, pOption->replicas, sizeof(SReplica) * TSDB_MAX_REPLICA);
|
||||||
pMnode->pServer = pOption->pDnode;
|
pMnode->pDnode = pOption->pDnode;
|
||||||
pMnode->putMsgToApplyMsgFp = pOption->putMsgToApplyMsgFp;
|
pMnode->putMsgToApplyMsgFp = pOption->putMsgToApplyMsgFp;
|
||||||
pMnode->sendMsgToDnodeFp = pOption->sendMsgToDnodeFp;
|
pMnode->sendMsgToDnodeFp = pOption->sendMsgToDnodeFp;
|
||||||
pMnode->sendMsgToMnodeFp = pOption->sendMsgToMnodeFp;
|
pMnode->sendMsgToMnodeFp = pOption->sendMsgToMnodeFp;
|
||||||
pMnode->sendRedirectMsgFp = pOption->sendRedirectMsgFp;
|
pMnode->sendRedirectMsgFp = pOption->sendRedirectMsgFp;
|
||||||
|
|
||||||
if (pMnode->sendMsgToDnodeFp == NULL || pMnode->sendMsgToMnodeFp == NULL || pMnode->sendRedirectMsgFp == NULL ||
|
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;
|
terrno = TSDB_CODE_MND_APP_ERROR;
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
@ -98,88 +240,98 @@ static int32_t mnodeSetOptions(SMnode *pMnode, const SMnodeOpt *pOption) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int32_t mnodeAllocInitSteps() {
|
SMnode *mndOpen(const char *path, const SMnodeOpt *pOption) {
|
||||||
struct SSteps *steps = taosStepInit(16, NULL);
|
mDebug("start to open mnode in %s", path);
|
||||||
if (steps == NULL) return -1;
|
|
||||||
|
|
||||||
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));
|
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);
|
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;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (mnodeAllocInitSteps() != 0) {
|
int32_t code = mnodeCreateDir(pMnode, path);
|
||||||
mError("failed to alloc init steps since %s", terrstr());
|
if (mnodeCreateDir(pMnode, path) != 0) {
|
||||||
|
mError("failed to open mnode since %s", tstrerror(code));
|
||||||
|
mndClose(pMnode);
|
||||||
|
terrno = code;
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (mnodeAllocStartSteps() != 0) {
|
code = mndSetOptions(pMnode, pOption);
|
||||||
mError("failed to alloc start steps since %s", terrstr());
|
if (code != 0) {
|
||||||
|
mError("failed to open mnode since %s", tstrerror(code));
|
||||||
|
mndClose(pMnode);
|
||||||
|
terrno = code;
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
taosStepExec(tsMint.pInitSteps);
|
code = mndInitSteps(pMnode);
|
||||||
|
if (code != 0) {
|
||||||
if (tsMint.para.dnodeId <= 0 && tsMint.para.clusterId <= 0) {
|
mError("failed to open mnode since %s", tstrerror(code));
|
||||||
if (sdbDeploy() != 0) {
|
mndClose(pMnode);
|
||||||
mError("failed to deploy sdb since %s", terrstr());
|
terrno = code;
|
||||||
return NULL;
|
return NULL;
|
||||||
} else {
|
|
||||||
mInfo("mnode is deployed");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
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;
|
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));
|
SMnodeMsg *pMsg = taosAllocateQitem(sizeof(SMnodeMsg));
|
||||||
if (pMsg == NULL) {
|
if (pMsg == NULL) {
|
||||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||||
|
@ -187,7 +339,7 @@ SMnodeMsg *mnodeInitMsg(SMnode *pMnode, SRpcMsg *pRpcMsg) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (rpcGetConnInfo(pRpcMsg->handle, &pMsg->conn) != 0) {
|
if (rpcGetConnInfo(pRpcMsg->handle, &pMsg->conn) != 0) {
|
||||||
mnodeCleanupMsg(pMsg);
|
mndCleanupMsg(pMsg);
|
||||||
mError("can not get user from conn:%p", pMsg->rpcMsg.handle);
|
mError("can not get user from conn:%p", pMsg->rpcMsg.handle);
|
||||||
terrno = TSDB_CODE_MND_NO_USER_FROM_CONN;
|
terrno = TSDB_CODE_MND_NO_USER_FROM_CONN;
|
||||||
return NULL;
|
return NULL;
|
||||||
|
@ -199,181 +351,72 @@ SMnodeMsg *mnodeInitMsg(SMnode *pMnode, SRpcMsg *pRpcMsg) {
|
||||||
return pMsg;
|
return pMsg;
|
||||||
}
|
}
|
||||||
|
|
||||||
void mnodeCleanupMsg(SMnodeMsg *pMsg) {
|
void mndCleanupMsg(SMnodeMsg *pMsg) {
|
||||||
if (pMsg->pUser != NULL) {
|
if (pMsg->pUser != NULL) {
|
||||||
sdbRelease(pMsg->pUser);
|
sdbRelease(pMsg->pMnode->pSdb, pMsg->pUser);
|
||||||
}
|
}
|
||||||
|
|
||||||
taosFreeQitem(pMsg);
|
taosFreeQitem(pMsg);
|
||||||
}
|
}
|
||||||
|
|
||||||
void mnodeSendRsp(SMnodeMsg *pMsg, int32_t code) {}
|
void mndSendRsp(SMnodeMsg *pMsg, int32_t code) {}
|
||||||
|
|
||||||
static void mnodeProcessRpcMsg(SMnodeMsg *pMsg) {
|
static void mndProcessRpcMsg(SMnodeMsg *pMsg) {
|
||||||
if (!mnodeIsMaster()) {
|
SMnode *pMnode = pMsg->pMnode;
|
||||||
mnodeSendRedirectMsg(NULL, &pMsg->rpcMsg, true);
|
int32_t code = 0;
|
||||||
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) {
|
|
||||||
int32_t msgType = pMsg->rpcMsg.msgType;
|
int32_t msgType = pMsg->rpcMsg.msgType;
|
||||||
void *ahandle = pMsg->rpcMsg.ahandle;
|
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]);
|
mError("msg:%p, app:%p type:%s content is null", pMsg, ahandle, taosMsg[msgType]);
|
||||||
code = TSDB_CODE_MND_INVALID_MSG_LEN;
|
code = TSDB_CODE_MND_INVALID_MSG_LEN;
|
||||||
goto PROCESS_WRITE_REQ_END;
|
goto PROCESS_RPC_END;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!mnodeIsMaster()) {
|
MndMsgFp fp = pMnode->msgFp[msgType];
|
||||||
SMnRsp *rpcRsp = &pMsg->rpcRsp;
|
if (fp == NULL) {
|
||||||
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) {
|
|
||||||
mError("msg:%p, app:%p type:%s not processed", pMsg, ahandle, taosMsg[msgType]);
|
mError("msg:%p, app:%p type:%s not processed", pMsg, ahandle, taosMsg[msgType]);
|
||||||
code = TSDB_CODE_MND_MSG_NOT_PROCESSED;
|
code = TSDB_CODE_MSG_NOT_PROCESSED;
|
||||||
goto PROCESS_WRITE_REQ_END;
|
goto PROCESS_RPC_END;
|
||||||
}
|
}
|
||||||
|
|
||||||
code = (*tsMworker.writeMsgFp[msgType])(pMsg);
|
code = (*fp)(pMnode, pMsg);
|
||||||
|
if (code != 0) {
|
||||||
PROCESS_WRITE_REQ_END:
|
code = terrno;
|
||||||
mnodeSendRsp(pMsg, code);
|
mError("msg:%p, app:%p type:%s failed to process since %s", pMsg, ahandle, taosMsg[msgType], terrstr());
|
||||||
}
|
goto PROCESS_RPC_END;
|
||||||
|
|
||||||
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;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!mnodeIsMaster()) {
|
PROCESS_RPC_END:
|
||||||
SMnRsp *rpcRsp = &pMsg->rpcRsp;
|
if (isReq) {
|
||||||
SEpSet *epSet = rpcMallocCont(sizeof(SEpSet));
|
if (code == TSDB_CODE_APP_NOT_READY) {
|
||||||
if (!epSet) {
|
mndSendRedirectMsg(pMnode, &pMsg->rpcMsg);
|
||||||
code = TSDB_CODE_OUT_OF_MEMORY;
|
} else if (code != 0) {
|
||||||
goto PROCESS_READ_REQ_END;
|
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) {
|
mndCleanupMsg(pMsg);
|
||||||
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);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void mnodeProcessPeerReq(SMnodeMsg *pMsg, void *unused) {
|
void mndSetMsgHandle(SMnode *pMnode, int32_t msgType, MndMsgFp fp) {
|
||||||
int32_t msgType = pMsg->rpcMsg.msgType;
|
if (msgType >= 0 && msgType < TSDB_MSG_TYPE_MAX) {
|
||||||
void *ahandle = pMsg->rpcMsg.ahandle;
|
pMnode->msgFp[msgType] = fp;
|
||||||
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;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
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) {
|
void mndProcessReadMsg(SMnodeMsg *pMsg) { mndProcessRpcMsg(pMsg); }
|
||||||
int32_t msgType = pMsg->rpcMsg.msgType;
|
|
||||||
SRpcMsg *pRpcMsg = &pMsg->rpcMsg;
|
|
||||||
|
|
||||||
if (!mnodeIsMaster()) {
|
void mndProcessWriteMsg(SMnodeMsg *pMsg) { mndProcessRpcMsg(pMsg); }
|
||||||
mError("msg:%p, ahandle:%p type:%s not processed for not master", pRpcMsg, pRpcMsg->ahandle, taosMsg[msgType]);
|
|
||||||
mnodeCleanupMsg2(pMsg);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (tsMworker.peerRspFp[msgType]) {
|
void mndProcessSyncMsg(SMnodeMsg *pMsg) { mndProcessRpcMsg(pMsg); }
|
||||||
(*tsMworker.peerRspFp[msgType])(pRpcMsg);
|
|
||||||
} else {
|
|
||||||
mError("msg:%p, ahandle:%p type:%s is not processed", pRpcMsg, pRpcMsg->ahandle, taosMsg[msgType]);
|
|
||||||
}
|
|
||||||
|
|
||||||
mnodeCleanupMsg2(pMsg);
|
void mndProcessApplyMsg(SMnodeMsg *pMsg) {}
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
|
@ -1,21 +0,0 @@
|
||||||
/*
|
|
||||||
* Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com>
|
|
||||||
*
|
|
||||||
* 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 <http://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#define _DEFAULT_SOURCE
|
|
||||||
#include "os.h"
|
|
||||||
#include "mnodeInt.h"
|
|
||||||
|
|
||||||
int32_t mnodeInitFunc() { return 0; }
|
|
||||||
void mnodeCleanupFunc() {}
|
|
|
@ -1,21 +0,0 @@
|
||||||
/*
|
|
||||||
* Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com>
|
|
||||||
*
|
|
||||||
* 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 <http://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#define _DEFAULT_SOURCE
|
|
||||||
#include "os.h"
|
|
||||||
#include "mnodeInt.h"
|
|
||||||
|
|
||||||
int32_t mnodeInitOper() { return 0; }
|
|
||||||
void mnodeCleanupOper() {}
|
|
|
@ -1,21 +0,0 @@
|
||||||
/*
|
|
||||||
* Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com>
|
|
||||||
*
|
|
||||||
* 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 <http://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#define _DEFAULT_SOURCE
|
|
||||||
#include "os.h"
|
|
||||||
#include "mnodeInt.h"
|
|
||||||
|
|
||||||
int32_t mnodeInitProfile() { return 0; }
|
|
||||||
void mnodeCleanupProfile() {}
|
|
|
@ -1,21 +0,0 @@
|
||||||
/*
|
|
||||||
* Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com>
|
|
||||||
*
|
|
||||||
* 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 <http://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#define _DEFAULT_SOURCE
|
|
||||||
#include "os.h"
|
|
||||||
#include "mnodeInt.h"
|
|
||||||
|
|
||||||
int32_t mnodeInitShow() { return 0; }
|
|
||||||
void mnodeCleanUpShow() {}
|
|
|
@ -1,21 +0,0 @@
|
||||||
/*
|
|
||||||
* Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com>
|
|
||||||
*
|
|
||||||
* 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 <http://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#define _DEFAULT_SOURCE
|
|
||||||
#include "os.h"
|
|
||||||
#include "mnodeInt.h"
|
|
||||||
|
|
||||||
int32_t mnodeInitStable() { return 0; }
|
|
||||||
void mnodeCleanupStable() {}
|
|
|
@ -1,21 +0,0 @@
|
||||||
/*
|
|
||||||
* Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com>
|
|
||||||
*
|
|
||||||
* 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 <http://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#define _DEFAULT_SOURCE
|
|
||||||
#include "os.h"
|
|
||||||
#include "mnodeInt.h"
|
|
||||||
|
|
||||||
int32_t mnodeInitVgroup() { return 0; }
|
|
||||||
void mnodeCleanupVgroup() {}
|
|
|
@ -3,7 +3,7 @@ add_library(sdb ${MNODE_SRC})
|
||||||
target_include_directories(
|
target_include_directories(
|
||||||
sdb
|
sdb
|
||||||
PUBLIC "${CMAKE_SOURCE_DIR}/include/dnode/mnode/sdb"
|
PUBLIC "${CMAKE_SOURCE_DIR}/include/dnode/mnode/sdb"
|
||||||
private "${CMAKE_CURRENT_SOURCE_DIR}/inc"
|
PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/inc"
|
||||||
)
|
)
|
||||||
target_link_libraries(
|
target_link_libraries(
|
||||||
sdb
|
sdb
|
||||||
|
|
|
@ -37,7 +37,7 @@ extern "C" {
|
||||||
#define SDB_MAX_SIZE (32 * 1024)
|
#define SDB_MAX_SIZE (32 * 1024)
|
||||||
|
|
||||||
typedef struct SSdbRaw {
|
typedef struct SSdbRaw {
|
||||||
int8_t sdb;
|
int8_t type;
|
||||||
int8_t sver;
|
int8_t sver;
|
||||||
int8_t status;
|
int8_t status;
|
||||||
int8_t reserved;
|
int8_t reserved;
|
||||||
|
@ -46,7 +46,7 @@ typedef struct SSdbRaw {
|
||||||
} SSdbRaw;
|
} SSdbRaw;
|
||||||
|
|
||||||
typedef struct SSdbRow {
|
typedef struct SSdbRow {
|
||||||
ESdbType sdb;
|
ESdbType type;
|
||||||
ESdbStatus status;
|
ESdbStatus status;
|
||||||
int32_t refCount;
|
int32_t refCount;
|
||||||
char pObj[];
|
char pObj[];
|
||||||
|
@ -69,9 +69,8 @@ typedef struct SSdb {
|
||||||
SdbDecodeFp decodeFps[SDB_MAX];
|
SdbDecodeFp decodeFps[SDB_MAX];
|
||||||
} SSdb;
|
} SSdb;
|
||||||
|
|
||||||
extern SSdb tsSdb;
|
int32_t sdbWriteFile(SSdb *pSdb);
|
||||||
|
int32_t sdbWriteRaw(SSdb *pSdb, SSdbRaw *pRaw);
|
||||||
int32_t sdbWriteImp(SSdbRaw *pRaw);
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
|
|
|
@ -15,31 +15,86 @@
|
||||||
|
|
||||||
#define _DEFAULT_SOURCE
|
#define _DEFAULT_SOURCE
|
||||||
#include "sdbInt.h"
|
#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];
|
char path[PATH_MAX + 100];
|
||||||
|
snprintf(path, PATH_MAX + 100, "%s", pOption->path);
|
||||||
snprintf(path, PATH_MAX + 100, "%s%scur%s", tsMnodeDir, TD_DIRSEP, TD_DIRSEP);
|
pSdb->currDir = strdup(path);
|
||||||
tsSdb.currDir = strdup(path);
|
snprintf(path, PATH_MAX + 100, "%s%ssync", pOption->path, TD_DIRSEP);
|
||||||
|
pSdb->syncDir = strdup(path);
|
||||||
snprintf(path, PATH_MAX + 100, "%s%ssync%s", tsMnodeDir, TD_DIRSEP, TD_DIRSEP);
|
snprintf(path, PATH_MAX + 100, "%s%stmp", pOption->path, TD_DIRSEP);
|
||||||
tsSdb.syncDir = strdup(path);
|
pSdb->tmpDir = strdup(path);
|
||||||
|
if (pSdb->currDir == NULL || pSdb->currDir == NULL || pSdb->currDir == NULL) {
|
||||||
snprintf(path, PATH_MAX + 100, "%s%stmp%s", tsMnodeDir, TD_DIRSEP, TD_DIRSEP);
|
sdbCleanup(pSdb);
|
||||||
tsSdb.tmpDir = strdup(path);
|
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||||
|
mError("failed to init sdb since %s", terrstr());
|
||||||
if (tsSdb.currDir == NULL || tsSdb.currDir == NULL || tsSdb.currDir == NULL) {
|
return NULL;
|
||||||
return TSDB_CODE_OUT_OF_MEMORY;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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) {
|
for (int32_t i = 0; i < SDB_MAX; ++i) {
|
||||||
int32_t type;
|
int32_t type;
|
||||||
if (tsSdb.keyTypes[i] == SDB_KEY_INT32) {
|
if (pSdb->keyTypes[i] == SDB_KEY_INT32) {
|
||||||
type = TSDB_DATA_TYPE_INT;
|
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;
|
type = TSDB_DATA_TYPE_BIGINT;
|
||||||
} else {
|
} else {
|
||||||
type = TSDB_DATA_TYPE_BINARY;
|
type = TSDB_DATA_TYPE_BINARY;
|
||||||
|
@ -47,45 +102,13 @@ int32_t sdbInit() {
|
||||||
|
|
||||||
SHashObj *hash = taosHashInit(64, taosGetDefaultHashFunction(type), true, HASH_NO_LOCK);
|
SHashObj *hash = taosHashInit(64, taosGetDefaultHashFunction(type), true, HASH_NO_LOCK);
|
||||||
if (hash == NULL) {
|
if (hash == NULL) {
|
||||||
return TSDB_CODE_OUT_OF_MEMORY;
|
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||||
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
tsSdb.hashObjs[i] = hash;
|
pSdb->hashObjs[i] = hash;
|
||||||
taosInitRWLatch(&tsSdb.locks[i]);
|
taosInitRWLatch(&pSdb->locks[i]);
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
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;
|
|
||||||
}
|
}
|
|
@ -15,71 +15,71 @@
|
||||||
|
|
||||||
#define _DEFAULT_SOURCE
|
#define _DEFAULT_SOURCE
|
||||||
#include "sdbInt.h"
|
#include "sdbInt.h"
|
||||||
#include "tglobal.h"
|
|
||||||
#include "tchecksum.h"
|
#include "tchecksum.h"
|
||||||
|
|
||||||
static int32_t sdbCreateDir() {
|
static int32_t sdbCreateDir(SSdb *pSdb) {
|
||||||
mDebug("start to create mnode at %s", tsMnodeDir);
|
if (taosMkDir(pSdb->currDir) != 0) {
|
||||||
|
|
||||||
if (taosMkDir(tsSdb.currDir) != 0) {
|
|
||||||
terrno = TAOS_SYSTEM_ERROR(errno);
|
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;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (taosMkDir(tsSdb.syncDir) != 0) {
|
if (taosMkDir(pSdb->syncDir) != 0) {
|
||||||
terrno = TAOS_SYSTEM_ERROR(errno);
|
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;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (taosMkDir(tsSdb.tmpDir) != 0) {
|
if (taosMkDir(pSdb->tmpDir) != 0) {
|
||||||
terrno = TAOS_SYSTEM_ERROR(errno);
|
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 -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int32_t sdbRunDeployFp() {
|
static int32_t sdbRunDeployFp(SSdb *pSdb) {
|
||||||
mDebug("start to run deploy functions");
|
mDebug("start to deploy sdb");
|
||||||
|
|
||||||
for (int32_t i = SDB_MAX - 1; i > SDB_START; --i) {
|
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 == NULL) continue;
|
||||||
if ((*fp)() != 0) {
|
|
||||||
|
if ((*fp)(pSdb) != 0) {
|
||||||
mError("failed to deploy sdb:%d since %s", i, terrstr());
|
mError("failed to deploy sdb:%d since %s", i, terrstr());
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
mDebug("end of run deploy functions");
|
mDebug("sdb deploy successfully");
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int32_t sdbReadDataFile() {
|
int32_t sdbReadFile(SSdb *pSdb) {
|
||||||
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;
|
|
||||||
}
|
|
||||||
|
|
||||||
int64_t offset = 0;
|
int64_t offset = 0;
|
||||||
int32_t code = 0;
|
int32_t code = 0;
|
||||||
int32_t readLen = 0;
|
int32_t readLen = 0;
|
||||||
int64_t ret = 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) {
|
while (1) {
|
||||||
readLen = sizeof(SSdbRaw);
|
readLen = sizeof(SSdbRaw);
|
||||||
ret = taosReadFile(fd, pRaw, readLen);
|
ret = taosReadFile(fd, pRaw, readLen);
|
||||||
|
@ -118,7 +118,7 @@ static int32_t sdbReadDataFile() {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
code = sdbWriteImp(pRaw);
|
code = sdbWriteRaw(pSdb, pRaw);
|
||||||
if (code != 0) {
|
if (code != 0) {
|
||||||
mError("failed to read file:%s since %s", file, terrstr());
|
mError("failed to read file:%s since %s", file, terrstr());
|
||||||
goto PARSE_SDB_DATA_ERROR;
|
goto PARSE_SDB_DATA_ERROR;
|
||||||
|
@ -130,13 +130,18 @@ static int32_t sdbReadDataFile() {
|
||||||
PARSE_SDB_DATA_ERROR:
|
PARSE_SDB_DATA_ERROR:
|
||||||
taosCloseFile(fd);
|
taosCloseFile(fd);
|
||||||
sdbFreeRaw(pRaw);
|
sdbFreeRaw(pRaw);
|
||||||
|
|
||||||
terrno = code;
|
terrno = code;
|
||||||
return code;
|
return code;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int32_t sdbWriteDataFile() {
|
int32_t sdbWriteFile(SSdb *pSdb) {
|
||||||
|
int32_t code = 0;
|
||||||
|
|
||||||
char tmpfile[PATH_MAX] = {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);
|
FileFd fd = taosOpenFileCreateWrite(tmpfile);
|
||||||
if (fd <= 0) {
|
if (fd <= 0) {
|
||||||
|
@ -145,14 +150,12 @@ static int32_t sdbWriteDataFile() {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t code = 0;
|
|
||||||
|
|
||||||
for (int32_t i = SDB_MAX - 1; i > SDB_START; --i) {
|
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;
|
if (encodeFp == NULL) continue;
|
||||||
|
|
||||||
SHashObj *hash = tsSdb.hashObjs[i];
|
SHashObj *hash = pSdb->hashObjs[i];
|
||||||
SRWLatch *pLock = &tsSdb.locks[i];
|
SRWLatch *pLock = &pSdb->locks[i];
|
||||||
taosWLockLatch(pLock);
|
taosWLockLatch(pLock);
|
||||||
|
|
||||||
SSdbRow **ppRow = taosHashIterate(hash, NULL);
|
SSdbRow **ppRow = taosHashIterate(hash, NULL);
|
||||||
|
@ -192,68 +195,44 @@ static int32_t sdbWriteDataFile() {
|
||||||
|
|
||||||
if (code == 0) {
|
if (code == 0) {
|
||||||
code = taosFsyncFile(fd);
|
code = taosFsyncFile(fd);
|
||||||
|
if (code != 0) {
|
||||||
|
code = TAOS_SYSTEM_ERROR(errno);
|
||||||
|
mError("failed to write file:%s since %s", tmpfile, tstrerror(code));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
taosCloseFile(fd);
|
taosCloseFile(fd);
|
||||||
|
|
||||||
if (code == 0) {
|
if (code == 0) {
|
||||||
char curfile[PATH_MAX] = {0};
|
|
||||||
snprintf(curfile, sizeof(curfile), "%ssdb.data", tsSdb.currDir);
|
|
||||||
code = taosRenameFile(tmpfile, curfile);
|
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) {
|
if (code != 0) {
|
||||||
terrno = code;
|
mError("failed to write file:%s since %s", curfile, tstrerror(code));
|
||||||
mError("failed to write sdb file since %s", terrstr());
|
|
||||||
} else {
|
} else {
|
||||||
mDebug("write sdb file successfully");
|
mDebug("write file:%s successfully", curfile);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
terrno = code;
|
||||||
return code;
|
return code;
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t sdbOpen() {
|
int32_t sdbDeploy(SSdb *pSdb) {
|
||||||
mDebug("start to read mnode file");
|
if (sdbCreateDir(pSdb) != 0) {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
if (sdbReadDataFile() != 0) {
|
if (sdbRunDeployFp(pSdb) != 0) {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (sdbWriteFile(pSdb) != 0) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
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);
|
|
||||||
}
|
|
||||||
|
|
|
@ -15,15 +15,14 @@
|
||||||
|
|
||||||
#define _DEFAULT_SOURCE
|
#define _DEFAULT_SOURCE
|
||||||
#include "sdbInt.h"
|
#include "sdbInt.h"
|
||||||
#include "tglobal.h"
|
|
||||||
|
|
||||||
static SHashObj *sdbGetHash(int32_t sdb) {
|
static SHashObj *sdbGetHash(SSdb *pSdb, int32_t type) {
|
||||||
if (sdb >= SDB_MAX || sdb <= SDB_START) {
|
if (type >= SDB_MAX || type <= SDB_START) {
|
||||||
terrno = TSDB_CODE_SDB_INVALID_TABLE_TYPE;
|
terrno = TSDB_CODE_SDB_INVALID_TABLE_TYPE;
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
SHashObj *hash = tsSdb.hashObjs[sdb];
|
SHashObj *hash = pSdb->hashObjs[type];
|
||||||
if (hash == NULL) {
|
if (hash == NULL) {
|
||||||
terrno = TSDB_CODE_SDB_APP_ERROR;
|
terrno = TSDB_CODE_SDB_APP_ERROR;
|
||||||
return NULL;
|
return NULL;
|
||||||
|
@ -32,9 +31,9 @@ static SHashObj *sdbGetHash(int32_t sdb) {
|
||||||
return hash;
|
return hash;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int32_t sdbGetkeySize(ESdbType sdb, void *pKey) {
|
static int32_t sdbGetkeySize(SSdb *pSdb, ESdbType type, void *pKey) {
|
||||||
int32_t keySize;
|
int32_t keySize;
|
||||||
EKeyType keyType = tsSdb.keyTypes[sdb];
|
EKeyType keyType = pSdb->keyTypes[type];
|
||||||
|
|
||||||
if (keyType == SDB_KEY_INT32) {
|
if (keyType == SDB_KEY_INT32) {
|
||||||
keySize = sizeof(int32_t);
|
keySize = sizeof(int32_t);
|
||||||
|
@ -47,77 +46,81 @@ static int32_t sdbGetkeySize(ESdbType sdb, void *pKey) {
|
||||||
return keySize;
|
return keySize;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int32_t sdbInsertRow(SHashObj *hash, SSdbRaw *pRaw, SSdbRow *pRow, int32_t keySize) {
|
static int32_t sdbInsertRow(SSdb *pSdb, SHashObj *hash, SSdbRaw *pRaw, SSdbRow *pRow, int32_t keySize) {
|
||||||
SRWLatch *pLock = &tsSdb.locks[pRow->sdb];
|
int32_t code = 0;
|
||||||
|
|
||||||
|
SRWLatch *pLock = &pSdb->locks[pRow->type];
|
||||||
taosWLockLatch(pLock);
|
taosWLockLatch(pLock);
|
||||||
|
|
||||||
SSdbRow *pDstRow = taosHashGet(hash, pRow->pObj, keySize);
|
SSdbRow *pDstRow = taosHashGet(hash, pRow->pObj, keySize);
|
||||||
if (pDstRow != NULL) {
|
if (pDstRow != NULL) {
|
||||||
terrno = TSDB_CODE_SDB_OBJ_ALREADY_THERE;
|
|
||||||
taosWUnLockLatch(pLock);
|
taosWUnLockLatch(pLock);
|
||||||
sdbFreeRow(pRow);
|
sdbFreeRow(pRow);
|
||||||
return -1;
|
return TSDB_CODE_SDB_OBJ_ALREADY_THERE;
|
||||||
}
|
}
|
||||||
|
|
||||||
pRow->refCount = 1;
|
pRow->refCount = 1;
|
||||||
pRow->status = pRaw->status;
|
pRow->status = pRaw->status;
|
||||||
|
|
||||||
if (taosHashPut(hash, pRow->pObj, keySize, &pRow, sizeof(void *)) != 0) {
|
if (taosHashPut(hash, pRow->pObj, keySize, &pRow, sizeof(void *)) != 0) {
|
||||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
|
||||||
taosWUnLockLatch(pLock);
|
taosWUnLockLatch(pLock);
|
||||||
sdbFreeRow(pRow);
|
sdbFreeRow(pRow);
|
||||||
return -1;
|
return TSDB_CODE_SDB_OBJ_ALREADY_THERE;
|
||||||
}
|
}
|
||||||
|
|
||||||
taosWUnLockLatch(pLock);
|
taosWUnLockLatch(pLock);
|
||||||
|
|
||||||
SdbInsertFp insertFp = tsSdb.insertFps[pRow->sdb];
|
SdbInsertFp insertFp = pSdb->insertFps[pRow->type];
|
||||||
if (insertFp != NULL) {
|
if (insertFp != NULL) {
|
||||||
if ((*insertFp)(pRow->pObj) != 0) {
|
code = (*insertFp)(pSdb, pRow->pObj);
|
||||||
|
if (code != 0) {
|
||||||
taosWLockLatch(pLock);
|
taosWLockLatch(pLock);
|
||||||
taosHashRemove(hash, pRow->pObj, keySize);
|
taosHashRemove(hash, pRow->pObj, keySize);
|
||||||
taosWUnLockLatch(pLock);
|
taosWUnLockLatch(pLock);
|
||||||
sdbFreeRow(pRow);
|
sdbFreeRow(pRow);
|
||||||
return -1;
|
return code;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int32_t sdbUpdateRow(SHashObj *hash, SSdbRaw *pRaw, SSdbRow *pRow, int32_t keySize) {
|
static int32_t sdbUpdateRow(SSdb *pSdb, SHashObj *hash, SSdbRaw *pRaw, SSdbRow *pRow, int32_t keySize) {
|
||||||
SRWLatch *pLock = &tsSdb.locks[pRow->sdb];
|
int32_t code = 0;
|
||||||
|
|
||||||
|
SRWLatch *pLock = &pSdb->locks[pRow->type];
|
||||||
taosRLockLatch(pLock);
|
taosRLockLatch(pLock);
|
||||||
|
|
||||||
SSdbRow **ppDstRow = taosHashGet(hash, pRow->pObj, keySize);
|
SSdbRow **ppDstRow = taosHashGet(hash, pRow->pObj, keySize);
|
||||||
if (ppDstRow == NULL || *ppDstRow == NULL) {
|
if (ppDstRow == NULL || *ppDstRow == NULL) {
|
||||||
taosRUnLockLatch(pLock);
|
taosRUnLockLatch(pLock);
|
||||||
return sdbInsertRow(hash, pRaw, pRow, keySize);
|
return sdbInsertRow(pSdb, hash, pRaw, pRow, keySize);
|
||||||
}
|
}
|
||||||
SSdbRow *pDstRow = *ppDstRow;
|
SSdbRow *pDstRow = *ppDstRow;
|
||||||
|
|
||||||
pRow->status = pRaw->status;
|
pRow->status = pRaw->status;
|
||||||
taosRUnLockLatch(pLock);
|
taosRUnLockLatch(pLock);
|
||||||
|
|
||||||
SdbUpdateFp updateFp = tsSdb.updateFps[pRow->sdb];
|
SdbUpdateFp updateFp = pSdb->updateFps[pRow->type];
|
||||||
if (updateFp != NULL) {
|
if (updateFp != NULL) {
|
||||||
(*updateFp)(pRow->pObj, pDstRow->pObj);
|
code = (*updateFp)(pSdb, pRow->pObj, pDstRow->pObj);
|
||||||
}
|
}
|
||||||
|
|
||||||
sdbFreeRow(pRow);
|
sdbFreeRow(pRow);
|
||||||
return 0;
|
return code;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int32_t sdbDeleteRow(SHashObj *hash, SSdbRaw *pRaw, SSdbRow *pRow, int32_t keySize) {
|
static int32_t sdbDeleteRow(SSdb *pSdb, SHashObj *hash, SSdbRaw *pRaw, SSdbRow *pRow, int32_t keySize) {
|
||||||
SRWLatch *pLock = &tsSdb.locks[pRow->sdb];
|
int32_t code = 0;
|
||||||
|
|
||||||
|
SRWLatch *pLock = &pSdb->locks[pRow->type];
|
||||||
taosWLockLatch(pLock);
|
taosWLockLatch(pLock);
|
||||||
|
|
||||||
SSdbRow **ppDstRow = taosHashGet(hash, pRow->pObj, keySize);
|
SSdbRow **ppDstRow = taosHashGet(hash, pRow->pObj, keySize);
|
||||||
if (ppDstRow == NULL || *ppDstRow == NULL) {
|
if (ppDstRow == NULL || *ppDstRow == NULL) {
|
||||||
terrno = TSDB_CODE_SDB_OBJ_NOT_THERE;
|
|
||||||
taosWUnLockLatch(pLock);
|
taosWUnLockLatch(pLock);
|
||||||
sdbFreeRow(pRow);
|
sdbFreeRow(pRow);
|
||||||
return -1;
|
return TSDB_CODE_SDB_OBJ_NOT_THERE;
|
||||||
}
|
}
|
||||||
SSdbRow *pDstRow = *ppDstRow;
|
SSdbRow *pDstRow = *ppDstRow;
|
||||||
|
|
||||||
|
@ -125,71 +128,67 @@ static int32_t sdbDeleteRow(SHashObj *hash, SSdbRaw *pRaw, SSdbRow *pRow, int32_
|
||||||
taosHashRemove(hash, pDstRow->pObj, keySize);
|
taosHashRemove(hash, pDstRow->pObj, keySize);
|
||||||
taosWUnLockLatch(pLock);
|
taosWUnLockLatch(pLock);
|
||||||
|
|
||||||
SdbDeleteFp deleteFp = tsSdb.deleteFps[pDstRow->sdb];
|
SdbDeleteFp deleteFp = pSdb->deleteFps[pDstRow->type];
|
||||||
if (deleteFp != NULL) {
|
if (deleteFp != NULL) {
|
||||||
(void)(*deleteFp)(pDstRow->pObj);
|
code = (*deleteFp)(pSdb, pDstRow->pObj);
|
||||||
}
|
}
|
||||||
|
|
||||||
sdbRelease(pDstRow->pObj);
|
sdbRelease(pSdb, pDstRow->pObj);
|
||||||
sdbFreeRow(pRow);
|
sdbFreeRow(pRow);
|
||||||
return 0;
|
return code;
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t sdbWriteImp(SSdbRaw *pRaw) {
|
int32_t sdbWriteRaw(SSdb *pSdb, SSdbRaw *pRaw) {
|
||||||
SHashObj *hash = sdbGetHash(pRaw->sdb);
|
SHashObj *hash = sdbGetHash(pSdb, pRaw->type);
|
||||||
if (hash == NULL) return -1;
|
if (hash == NULL) return terrno;
|
||||||
|
|
||||||
SdbDecodeFp decodeFp = tsSdb.decodeFps[pRaw->sdb];
|
SdbDecodeFp decodeFp = pSdb->decodeFps[pRaw->type];
|
||||||
SSdbRow *pRow = (*decodeFp)(pRaw);
|
SSdbRow *pRow = (*decodeFp)(pRaw);
|
||||||
if (pRow == NULL) {
|
if (pRow == NULL) {
|
||||||
terrno = TSDB_CODE_SDB_INVALID_DATA_CONTENT;
|
return terrno;
|
||||||
return -1;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pRow->sdb = pRaw->sdb;
|
pRow->type = pRaw->type;
|
||||||
|
|
||||||
int32_t keySize = sdbGetkeySize(pRow->sdb, pRow->pObj);
|
int32_t keySize = sdbGetkeySize(pSdb, pRow->type, pRow->pObj);
|
||||||
int32_t code = -1;
|
int32_t code = TSDB_CODE_SDB_INVALID_ACTION_TYPE;
|
||||||
|
|
||||||
switch (pRaw->status) {
|
switch (pRaw->status) {
|
||||||
case SDB_STATUS_CREATING:
|
case SDB_STATUS_CREATING:
|
||||||
code = sdbInsertRow(hash, pRaw, pRow, keySize);
|
code = sdbInsertRow(pSdb, hash, pRaw, pRow, keySize);
|
||||||
break;
|
break;
|
||||||
case SDB_STATUS_READY:
|
case SDB_STATUS_READY:
|
||||||
case SDB_STATUS_DROPPING:
|
case SDB_STATUS_DROPPING:
|
||||||
code = sdbUpdateRow(hash, pRaw, pRow, keySize);
|
code = sdbUpdateRow(pSdb, hash, pRaw, pRow, keySize);
|
||||||
break;
|
break;
|
||||||
case SDB_STATUS_DROPPED:
|
case SDB_STATUS_DROPPED:
|
||||||
code = sdbDeleteRow(hash, pRaw, pRow, keySize);
|
code = sdbDeleteRow(pSdb, hash, pRaw, pRow, keySize);
|
||||||
break;
|
|
||||||
default:
|
|
||||||
terrno = TSDB_CODE_SDB_INVALID_ACTION_TYPE;
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
return code;
|
return code;
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t sdbWrite(SSdbRaw *pRaw) {
|
int32_t sdbWrite(SSdb *pSdb, SSdbRaw *pRaw) {
|
||||||
int32_t code = sdbWriteImp(pRaw);
|
int32_t code = sdbWriteRaw(pSdb, pRaw);
|
||||||
sdbFreeRaw(pRaw);
|
sdbFreeRaw(pRaw);
|
||||||
return code;
|
return code;
|
||||||
}
|
}
|
||||||
|
|
||||||
void *sdbAcquire(ESdbType sdb, void *pKey) {
|
void *sdbAcquire(SSdb *pSdb, ESdbType type, void *pKey) {
|
||||||
SHashObj *hash = sdbGetHash(sdb);
|
SHashObj *hash = sdbGetHash(pSdb, type);
|
||||||
if (hash == NULL) return NULL;
|
if (hash == NULL) return NULL;
|
||||||
|
|
||||||
void *pRet = 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);
|
taosRLockLatch(pLock);
|
||||||
|
|
||||||
SSdbRow **ppRow = taosHashGet(hash, pKey, keySize);
|
SSdbRow **ppRow = taosHashGet(hash, pKey, keySize);
|
||||||
if (ppRow == NULL || *ppRow == NULL) {
|
if (ppRow == NULL || *ppRow == NULL) {
|
||||||
terrno = TSDB_CODE_SDB_OBJ_NOT_THERE;
|
|
||||||
taosRUnLockLatch(pLock);
|
taosRUnLockLatch(pLock);
|
||||||
|
terrno = TSDB_CODE_SDB_OBJ_NOT_THERE;
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -214,13 +213,13 @@ void *sdbAcquire(ESdbType sdb, void *pKey) {
|
||||||
return pRet;
|
return pRet;
|
||||||
}
|
}
|
||||||
|
|
||||||
void sdbRelease(void *pObj) {
|
void sdbRelease(SSdb *pSdb, void *pObj) {
|
||||||
if (pObj == NULL) return;
|
if (pObj == NULL) return;
|
||||||
|
|
||||||
SSdbRow *pRow = (SSdbRow *)((char *)pObj - sizeof(SSdbRow));
|
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);
|
taosRLockLatch(pLock);
|
||||||
|
|
||||||
int32_t ref = atomic_sub_fetch_32(&pRow->refCount, 1);
|
int32_t ref = atomic_sub_fetch_32(&pRow->refCount, 1);
|
||||||
|
@ -231,11 +230,11 @@ void sdbRelease(void *pObj) {
|
||||||
taosRUnLockLatch(pLock);
|
taosRUnLockLatch(pLock);
|
||||||
}
|
}
|
||||||
|
|
||||||
void *sdbFetch(ESdbType sdb, void *pIter, void **ppObj) {
|
void *sdbFetch(SSdb *pSdb, ESdbType type, void *pIter, void **ppObj) {
|
||||||
SHashObj *hash = sdbGetHash(sdb);
|
SHashObj *hash = sdbGetHash(pSdb, type);
|
||||||
if (hash == NULL) return NULL;
|
if (hash == NULL) return NULL;
|
||||||
|
|
||||||
SRWLatch *pLock = &tsSdb.locks[sdb];
|
SRWLatch *pLock = &pSdb->locks[type];
|
||||||
taosRLockLatch(pLock);
|
taosRLockLatch(pLock);
|
||||||
|
|
||||||
SSdbRow **ppRow = taosHashIterate(hash, ppRow);
|
SSdbRow **ppRow = taosHashIterate(hash, ppRow);
|
||||||
|
@ -255,23 +254,23 @@ void *sdbFetch(ESdbType sdb, void *pIter, void **ppObj) {
|
||||||
return ppRow;
|
return ppRow;
|
||||||
}
|
}
|
||||||
|
|
||||||
void sdbCancelFetch(void *pIter) {
|
void sdbCancelFetch(SSdb *pSdb, void *pIter) {
|
||||||
if (pIter == NULL) return;
|
if (pIter == NULL) return;
|
||||||
SSdbRow *pRow = *(SSdbRow **)pIter;
|
SSdbRow *pRow = *(SSdbRow **)pIter;
|
||||||
SHashObj *hash = sdbGetHash(pRow->sdb);
|
SHashObj *hash = sdbGetHash(pSdb, pRow->type);
|
||||||
if (hash == NULL) return;
|
if (hash == NULL) return;
|
||||||
|
|
||||||
SRWLatch *pLock = &tsSdb.locks[pRow->sdb];
|
SRWLatch *pLock = &pSdb->locks[pRow->type];
|
||||||
taosRLockLatch(pLock);
|
taosRLockLatch(pLock);
|
||||||
taosHashCancelIterate(hash, pIter);
|
taosHashCancelIterate(hash, pIter);
|
||||||
taosRUnLockLatch(pLock);
|
taosRUnLockLatch(pLock);
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t sdbGetSize(ESdbType sdb) {
|
int32_t sdbGetSize(SSdb *pSdb, ESdbType type) {
|
||||||
SHashObj *hash = sdbGetHash(sdb);
|
SHashObj *hash = sdbGetHash(pSdb, type);
|
||||||
if (hash == NULL) return 0;
|
if (hash == NULL) return 0;
|
||||||
|
|
||||||
SRWLatch *pLock = &tsSdb.locks[sdb];
|
SRWLatch *pLock = &pSdb->locks[type];
|
||||||
taosRLockLatch(pLock);
|
taosRLockLatch(pLock);
|
||||||
int32_t size = taosHashGetSize(hash);
|
int32_t size = taosHashGetSize(hash);
|
||||||
taosRUnLockLatch(pLock);
|
taosRUnLockLatch(pLock);
|
||||||
|
|
|
@ -16,14 +16,14 @@
|
||||||
#define _DEFAULT_SOURCE
|
#define _DEFAULT_SOURCE
|
||||||
#include "sdbInt.h"
|
#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));
|
SSdbRaw *pRaw = calloc(1, dataLen + sizeof(SSdbRaw));
|
||||||
if (pRaw == NULL) {
|
if (pRaw == NULL) {
|
||||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
pRaw->sdb = sdb;
|
pRaw->type = type;
|
||||||
pRaw->sver = sver;
|
pRaw->sver = sver;
|
||||||
pRaw->dataLen = dataLen;
|
pRaw->dataLen = dataLen;
|
||||||
return pRaw;
|
return pRaw;
|
||||||
|
|
|
@ -35,4 +35,4 @@ void *sdbGetRowObj(SSdbRow *pRow) {
|
||||||
return pRow->pObj;
|
return pRow->pObj;
|
||||||
}
|
}
|
||||||
|
|
||||||
void sdbFreeRow(SSdbRow *pRow) { free(pRow); }
|
void sdbFreeRow(SSdbRow *pRow) { tfree(pRow); }
|
||||||
|
|
|
@ -21,6 +21,7 @@
|
||||||
#include "index_fst_util.h"
|
#include "index_fst_util.h"
|
||||||
#include "index_fst_registry.h"
|
#include "index_fst_registry.h"
|
||||||
#include "index_fst_counting_writer.h"
|
#include "index_fst_counting_writer.h"
|
||||||
|
#include "index_fst_automation.h"
|
||||||
|
|
||||||
|
|
||||||
typedef struct FstNode FstNode;
|
typedef struct FstNode FstNode;
|
||||||
|
@ -34,11 +35,28 @@ typedef struct FstRange {
|
||||||
|
|
||||||
|
|
||||||
typedef enum { OneTransNext, OneTrans, AnyTrans, EmptyFinal} State;
|
typedef enum { OneTransNext, OneTrans, AnyTrans, EmptyFinal} State;
|
||||||
typedef enum { Included, Excluded, Unbounded} FstBound;
|
|
||||||
|
|
||||||
typedef enum {Ordered, OutOfOrdered, DuplicateKey} OrderType;
|
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);
|
bool fstGet(Fst *fst, FstSlice *b, Output *out);
|
||||||
FstNode* fstGetNode(Fst *fst, CompiledAddr);
|
FstNode* fstGetNode(Fst *fst, CompiledAddr);
|
||||||
|
FstNode* fstGetRoot(Fst *fst);
|
||||||
FstType fstGetType(Fst *fst);
|
FstType fstGetType(Fst *fst);
|
||||||
CompiledAddr fstGetRootAddr(Fst *fst);
|
CompiledAddr fstGetRootAddr(Fst *fst);
|
||||||
|
|
||||||
Output fstEmptyFinalOutput(Fst *fst, bool *null);
|
Output fstEmptyFinalOutput(Fst *fst, bool *null);
|
||||||
bool fstVerify(Fst *fst);
|
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; // <StreamState>
|
||||||
|
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
|
#endif
|
||||||
|
|
|
@ -15,7 +15,7 @@
|
||||||
#ifndef __INDEX_FST_AUTAOMATION_H__
|
#ifndef __INDEX_FST_AUTAOMATION_H__
|
||||||
#define __INDEX_FST_AUTAOMATION_H__
|
#define __INDEX_FST_AUTAOMATION_H__
|
||||||
|
|
||||||
struct AutomationCtx;
|
typedef struct AutomationCtx AutomationCtx;
|
||||||
|
|
||||||
typedef struct StartWith {
|
typedef struct StartWith {
|
||||||
AutomationCtx *autoSelf;
|
AutomationCtx *autoSelf;
|
||||||
|
@ -23,20 +23,25 @@ typedef struct StartWith {
|
||||||
|
|
||||||
typedef struct Complement {
|
typedef struct Complement {
|
||||||
AutomationCtx *autoSelf;
|
AutomationCtx *autoSelf;
|
||||||
|
|
||||||
} Complement;
|
} Complement;
|
||||||
|
|
||||||
// automation
|
// automation
|
||||||
typedef struct AutomationCtx {
|
typedef struct AutomationCtx {
|
||||||
|
// automation interface
|
||||||
void *data;
|
void *data;
|
||||||
} AutomationCtx;
|
} AutomationCtx;
|
||||||
|
|
||||||
// automation interface
|
typedef struct Automation {
|
||||||
void (*start)(AutomationCtx *ctx);
|
void* (*start)() ;
|
||||||
bool (*isMatch)(AutomationCtx *ctx);
|
bool (*isMatch)();
|
||||||
bool (*canMatch)(AutomationCtx *ctx, void *data);
|
bool (*canMatch)(void *data);
|
||||||
bool (*willAlwaysMatch)(AutomationCtx *ctx, void *state);
|
bool (*willAlwaysMatch)(void *state);
|
||||||
void* (*accpet)(AutomationCtx *ctx, void *state, uint8_t byte);
|
void* (*accpet)(void *state, uint8_t byte);
|
||||||
void* (*accpetEof)(AutomationCtx *ctx, *state);
|
void* (*accpetEof)(void *state);
|
||||||
|
void *data;
|
||||||
|
} Automation;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -41,7 +41,7 @@ FstBuilderNode *fstBuilderNodeClone(FstBuilderNode *src);
|
||||||
|
|
||||||
void fstBuilderNodeCloneFrom(FstBuilderNode *dst, 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);
|
void fstBuilderNodeDestroy(FstBuilderNode *node);
|
||||||
|
|
||||||
|
|
|
@ -733,6 +733,11 @@ bool fstNodeCompile(FstNode *node, void *w, CompiledAddr lastAddr, CompiledAddr
|
||||||
return true;
|
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 *fstBuilderCreate(void *w, FstType ty) {
|
||||||
FstBuilder *b = malloc(sizeof(FstBuilder));
|
FstBuilder *b = malloc(sizeof(FstBuilder));
|
||||||
|
@ -985,15 +990,39 @@ void fstDestroy(Fst *fst) {
|
||||||
}
|
}
|
||||||
|
|
||||||
bool fstGet(Fst *fst, FstSlice *b, Output *out) {
|
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;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
FstNode *fstGetRoot(Fst *fst) {
|
||||||
|
CompiledAddr root = fstGetRootAddr(fst);
|
||||||
|
return fstGetNode(fst, root);
|
||||||
|
}
|
||||||
FstNode* fstGetNode(Fst *fst, CompiledAddr addr) {
|
FstNode* fstGetNode(Fst *fst, CompiledAddr addr) {
|
||||||
if (fst->root != NULL) {
|
if (fst->root != NULL) {
|
||||||
return fst->root;
|
return fst->root;
|
||||||
}
|
}
|
||||||
fst->root = fstNodeCreate(fst->meta->version, addr, fst->data);
|
fst->root = fstNodeCreate(fst->meta->version, addr, fst->data);
|
||||||
|
|
||||||
return fst->root;
|
return fst->root;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -1016,15 +1045,168 @@ Output fstEmptyFinalOutput(Fst *fst, bool *null) {
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
bool fstVerify(Fst *fst) {
|
bool fstVerify(Fst *fst) {
|
||||||
uint32_t checkSum = fst->meta->checkSum;
|
uint32_t checkSum = fst->meta->checkSum;
|
||||||
FstSlice *data = fst->data;
|
FstSlice *data = fst->data;
|
||||||
TSCKSUM initSum = 0;
|
TSCKSUM initSum = 0;
|
||||||
if (taosCheckChecksumWhole(data->data, data->dLen)) {
|
if (!taosCheckChecksumWhole(data->data, data->dLen)) {
|
||||||
return false;
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -59,26 +59,27 @@ void fstBuilderNodeCloneFrom(FstBuilderNode *dst, FstBuilderNode *src) {
|
||||||
src->trans = NULL;
|
src->trans = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool fstBuilderNodeCompileTo(FstBuilderNode *b, FstCountingWriter *wrt, CompiledAddr lastAddr, CompiledAddr startAddr) {
|
//bool fstBuilderNodeCompileTo(FstBuilderNode *b, FstCountingWriter *wrt, CompiledAddr lastAddr, CompiledAddr startAddr) {
|
||||||
size_t sz = taosArrayGetSize(b->trans);
|
|
||||||
assert(sz < 256);
|
//size_t sz = taosArrayGetSize(b->trans);
|
||||||
if (FST_BUILDER_NODE_IS_FINAL(b)
|
//assert(sz < 256);
|
||||||
&& FST_BUILDER_NODE_TRANS_ISEMPTY(b)
|
//if (FST_BUILDER_NODE_IS_FINAL(b)
|
||||||
&& FST_BUILDER_NODE_FINALOUTPUT_ISZERO(b)) {
|
// && FST_BUILDER_NODE_TRANS_ISEMPTY(b)
|
||||||
return true;
|
// && FST_BUILDER_NODE_FINALOUTPUT_ISZERO(b)) {
|
||||||
} else if (sz != 1 || b->isFinal) {
|
// return true;
|
||||||
// AnyTrans->Compile(w, addr, node);
|
//} else if (sz != 1 || b->isFinal) {
|
||||||
} else {
|
// // AnyTrans->Compile(w, addr, node);
|
||||||
FstTransition *tran = taosArrayGet(b->trans, 0);
|
//} else {
|
||||||
if (tran->addr == lastAddr && tran->out == 0) {
|
// FstTransition *tran = taosArrayGet(b->trans, 0);
|
||||||
//OneTransNext::compile(w, lastAddr, tran->inp);
|
// if (tran->addr == lastAddr && tran->out == 0) {
|
||||||
return true;
|
// //OneTransNext::compile(w, lastAddr, tran->inp);
|
||||||
} else {
|
// return true;
|
||||||
//OneTrans::Compile(w, lastAddr, *tran);
|
// } else {
|
||||||
return true;
|
// //OneTrans::Compile(w, lastAddr, *tran);
|
||||||
}
|
// return true;
|
||||||
}
|
// }
|
||||||
return true;
|
//}
|
||||||
}
|
//return true;
|
||||||
|
//}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -95,6 +95,7 @@ FstSlice fstSliceCreate(uint8_t *data, uint64_t dLen) {
|
||||||
FstSlice slice = {.data = data, .dLen = dLen, .start = 0, .end = dLen - 1};
|
FstSlice slice = {.data = data, .dLen = dLen, .start = 0, .end = dLen - 1};
|
||||||
return slice;
|
return slice;
|
||||||
}
|
}
|
||||||
|
// just shallow copy
|
||||||
FstSlice fstSliceCopy(FstSlice *slice, int32_t start, int32_t end) {
|
FstSlice fstSliceCopy(FstSlice *slice, int32_t start, int32_t end) {
|
||||||
FstSlice t;
|
FstSlice t;
|
||||||
if (start >= slice->dLen || end >= slice->dLen || start > end) {
|
if (start >= slice->dLen || end >= slice->dLen || start > end) {
|
||||||
|
|
Loading…
Reference in New Issue