Merge branch 'develop3' into v3
This commit is contained in:
commit
60a0da9767
|
@ -672,16 +672,16 @@ typedef struct {
|
|||
} SDnodeCfg;
|
||||
|
||||
typedef struct {
|
||||
int32_t dnodeId;
|
||||
int32_t id;
|
||||
int8_t isMnode;
|
||||
int8_t reserved;
|
||||
uint16_t dnodePort;
|
||||
char dnodeFqdn[TSDB_FQDN_LEN];
|
||||
uint16_t port;
|
||||
char fqdn[TSDB_FQDN_LEN];
|
||||
} SDnodeEp;
|
||||
|
||||
typedef struct {
|
||||
int32_t dnodeNum;
|
||||
SDnodeEp dnodeEps[];
|
||||
int32_t num;
|
||||
SDnodeEp eps[];
|
||||
} SDnodeEps;
|
||||
|
||||
typedef struct {
|
||||
|
@ -820,9 +820,9 @@ typedef struct {
|
|||
} SCreateDnodeMsg, SDropDnodeMsg;
|
||||
|
||||
typedef struct {
|
||||
int32_t dnodeId;
|
||||
int8_t replica;
|
||||
int8_t reserved[3];
|
||||
int32_t dnodeId;
|
||||
int8_t replica;
|
||||
int8_t reserved[3];
|
||||
SReplica replicas[TSDB_MAX_REPLICA];
|
||||
} SCreateMnodeMsg, SAlterMnodeMsg, SDropMnodeMsg;
|
||||
|
||||
|
|
|
@ -28,10 +28,6 @@ extern char tsSecond[];
|
|||
extern char tsLocalFqdn[];
|
||||
extern char tsLocalEp[];
|
||||
extern uint16_t tsServerPort;
|
||||
extern uint16_t tsDnodeShellPort;
|
||||
extern uint16_t tsDnodeDnodePort;
|
||||
extern uint16_t tsSyncPort;
|
||||
extern uint16_t tsArbitratorPort;
|
||||
extern int32_t tsStatusInterval;
|
||||
extern int32_t tsNumOfMnodes;
|
||||
extern int8_t tsEnableVnodeBak;
|
||||
|
|
|
@ -0,0 +1,140 @@
|
|||
/*
|
||||
* 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_DNODE_H_
|
||||
#define _TD_DNODE_H_
|
||||
|
||||
#include "tdef.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* ------------------------ TYPES EXPOSED ------------------------ */
|
||||
typedef struct SDnode SDnode;
|
||||
|
||||
typedef struct {
|
||||
/**
|
||||
* @brief software version of the program.
|
||||
*
|
||||
*/
|
||||
int32_t sver;
|
||||
|
||||
/**
|
||||
* @brief num of CPU cores.
|
||||
*
|
||||
*/
|
||||
int32_t numOfCores;
|
||||
|
||||
/**
|
||||
* @brief number of threads per CPU core.
|
||||
*
|
||||
*/
|
||||
float numOfThreadsPerCore;
|
||||
|
||||
/**
|
||||
* @brief the proportion of total CPU cores available for query processing.
|
||||
*
|
||||
*/
|
||||
float ratioOfQueryCores;
|
||||
|
||||
/**
|
||||
* @brief max number of connections allowed in dnode.
|
||||
*
|
||||
*/
|
||||
int32_t maxShellConns;
|
||||
|
||||
/**
|
||||
* @brief time interval of heart beat from shell to dnode, seconds.
|
||||
*
|
||||
*/
|
||||
int32_t shellActivityTimer;
|
||||
|
||||
/**
|
||||
* @brief time interval of dnode status reporting to mnode, seconds, for cluster only.
|
||||
*
|
||||
*/
|
||||
int32_t statusInterval;
|
||||
|
||||
/**
|
||||
* @brief first port number for the connection (12 continuous UDP/TCP port number are used).
|
||||
*
|
||||
*/
|
||||
uint16_t serverPort;
|
||||
|
||||
/**
|
||||
* @brief data file's directory.
|
||||
*
|
||||
*/
|
||||
char dataDir[TSDB_FILENAME_LEN];
|
||||
|
||||
/**
|
||||
* @brief local endpoint.
|
||||
*
|
||||
*/
|
||||
char localEp[TSDB_EP_LEN];
|
||||
|
||||
/**
|
||||
* @brieflocal fully qualified domain name (FQDN).
|
||||
*
|
||||
*/
|
||||
char localFqdn[TSDB_FQDN_LEN];
|
||||
|
||||
/**
|
||||
* @brief first fully qualified domain name (FQDN) for TDengine system.
|
||||
*
|
||||
*/
|
||||
char firstEp[TSDB_EP_LEN];
|
||||
|
||||
/**
|
||||
* @brief system time zone.
|
||||
*
|
||||
*/
|
||||
char timezone[TSDB_TIMEZONE_LEN];
|
||||
|
||||
/**
|
||||
* @brief system locale.
|
||||
*
|
||||
*/
|
||||
char locale[TSDB_LOCALE_LEN];
|
||||
|
||||
/**
|
||||
* @briefdefault system charset.
|
||||
*
|
||||
*/
|
||||
char charset[TSDB_LOCALE_LEN];
|
||||
} SDnodeOpt;
|
||||
|
||||
/* ------------------------ SDnode ------------------------ */
|
||||
/**
|
||||
* @brief Initialize and start the dnode.
|
||||
*
|
||||
* @param pOption Option of the dnode.
|
||||
* @return SDnode* The dnode object.
|
||||
*/
|
||||
SDnode *dndInit(SDnodeOpt *pOption);
|
||||
|
||||
/**
|
||||
* @brief Stop and cleanup the dnode.
|
||||
*
|
||||
* @param pDnode The dnode object to close.
|
||||
*/
|
||||
void dndCleanup(SDnode *pDnode);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /*_TD_DNODE_H_*/
|
|
@ -13,63 +13,265 @@
|
|||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef _TD_MNODE_H_
|
||||
#define _TD_MNODE_H_
|
||||
#ifndef _TD_MND_H_
|
||||
#define _TD_MND_H_
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
typedef enum { MN_MSG_TYPE_WRITE = 1, MN_MSG_TYPE_APPLY, MN_MSG_TYPE_SYNC, MN_MSG_TYPE_READ } EMnMsgType;
|
||||
|
||||
/* ------------------------ TYPES EXPOSED ------------------------ */
|
||||
typedef struct SDnode SDnode;
|
||||
typedef struct SMnode SMnode;
|
||||
typedef struct SMnodeMsg SMnodeMsg;
|
||||
typedef void (*SendMsgToDnodeFp)(SDnode *pDnode, struct SEpSet *epSet, struct SRpcMsg *rpcMsg);
|
||||
typedef void (*SendMsgToMnodeFp)(SDnode *pDnode, struct SRpcMsg *rpcMsg);
|
||||
typedef void (*SendRedirectMsgFp)(SDnode *pDnode, struct SRpcMsg *rpcMsg);
|
||||
typedef int32_t (*PutMsgToMnodeQFp)(SDnode *pDnode, SMnodeMsg *pMsg);
|
||||
|
||||
typedef struct {
|
||||
int8_t replica;
|
||||
int8_t selfIndex;
|
||||
SReplica replicas[TSDB_MAX_REPLICA];
|
||||
} SMnodeCfg;
|
||||
|
||||
typedef struct {
|
||||
typedef struct SMnodeLoad {
|
||||
/**
|
||||
* @brief the number of dnodes in cluster.
|
||||
*
|
||||
*/
|
||||
int64_t numOfDnode;
|
||||
|
||||
/**
|
||||
* @brief the number of mnodes in cluster.
|
||||
*
|
||||
*/
|
||||
int64_t numOfMnode;
|
||||
|
||||
/**
|
||||
* @brief the number of vgroups in cluster.
|
||||
*
|
||||
*/
|
||||
int64_t numOfVgroup;
|
||||
|
||||
/**
|
||||
* @brief the number of databases in cluster.
|
||||
*
|
||||
*/
|
||||
int64_t numOfDatabase;
|
||||
|
||||
/**
|
||||
* @brief the number of super tables in cluster.
|
||||
*
|
||||
*/
|
||||
int64_t numOfSuperTable;
|
||||
|
||||
/**
|
||||
* @brief the number of child tables in cluster.
|
||||
*
|
||||
*/
|
||||
int64_t numOfChildTable;
|
||||
|
||||
/**
|
||||
* @brief the number of normal tables in cluster.
|
||||
*
|
||||
*/
|
||||
int64_t numOfNormalTable;
|
||||
|
||||
/**
|
||||
* @brief the number of numOfTimeseries in cluster.
|
||||
*
|
||||
*/
|
||||
int64_t numOfColumn;
|
||||
|
||||
/**
|
||||
* @brief total points written in cluster.
|
||||
*
|
||||
*/
|
||||
int64_t totalPoints;
|
||||
|
||||
/**
|
||||
* @brief total storage in cluster.
|
||||
*
|
||||
*/
|
||||
int64_t totalStorage;
|
||||
|
||||
/**
|
||||
* @brief total compressed storage in cluster.
|
||||
*
|
||||
*/
|
||||
int64_t compStorage;
|
||||
} SMnodeLoad;
|
||||
|
||||
typedef struct {
|
||||
/**
|
||||
* @brief dnodeId of this mnode.
|
||||
*
|
||||
*/
|
||||
int32_t dnodeId;
|
||||
|
||||
/**
|
||||
* @brief clusterId of this mnode.
|
||||
*
|
||||
*/
|
||||
int64_t clusterId;
|
||||
void (*SendMsgToDnode)(struct SEpSet *epSet, struct SRpcMsg *rpcMsg);
|
||||
void (*SendMsgToMnode)(struct SRpcMsg *rpcMsg);
|
||||
void (*SendRedirectMsg)(struct SRpcMsg *rpcMsg, bool forShell);
|
||||
int32_t (*PutMsgIntoApplyQueue)(SMnodeMsg *pMsg);
|
||||
} SMnodePara;
|
||||
|
||||
int32_t mnodeInit(SMnodePara para);
|
||||
void mnodeCleanup();
|
||||
/**
|
||||
* @brief replica num of this mnode.
|
||||
*
|
||||
*/
|
||||
int8_t replica;
|
||||
|
||||
int32_t mnodeDeploy(SMnodeCfg *pCfg);
|
||||
void mnodeUnDeploy();
|
||||
int32_t mnodeStart(SMnodeCfg *pCfg);
|
||||
int32_t mnodeAlter(SMnodeCfg *pCfg);
|
||||
void mnodeStop();
|
||||
/**
|
||||
* @brief self index in the array of replicas.
|
||||
*
|
||||
*/
|
||||
int8_t selfIndex;
|
||||
|
||||
int32_t mnodeGetLoad(SMnodeLoad *pLoad);
|
||||
int32_t mnodeRetriveAuth(char *user, char *spi, char *encrypt, char *secret, char *ckey);
|
||||
/**
|
||||
* @brief detail replica information of this mnode.
|
||||
*
|
||||
*/
|
||||
SReplica replicas[TSDB_MAX_REPLICA];
|
||||
|
||||
SMnodeMsg *mnodeInitMsg(SRpcMsg *pRpcMsg);
|
||||
void mnodeCleanupMsg(SMnodeMsg *pMsg);
|
||||
void mnodeProcessMsg(SMnodeMsg *pMsg, EMnMsgType msgType);
|
||||
/**
|
||||
* @brief the parent dnode of this mnode.
|
||||
*
|
||||
*/
|
||||
SDnode *pDnode;
|
||||
|
||||
/**
|
||||
* @brief put apply msg to the write queue in dnode.
|
||||
*
|
||||
*/
|
||||
PutMsgToMnodeQFp putMsgToApplyMsgFp;
|
||||
|
||||
/**
|
||||
* @brief the callback function while send msg to dnode.
|
||||
*
|
||||
*/
|
||||
SendMsgToDnodeFp sendMsgToDnodeFp;
|
||||
|
||||
/**
|
||||
* @brief the callback function while send msg to mnode.
|
||||
*
|
||||
*/
|
||||
SendMsgToMnodeFp sendMsgToMnodeFp;
|
||||
|
||||
/**
|
||||
* @brief the callback function while send redirect msg to clients or peers.
|
||||
*
|
||||
*/
|
||||
SendRedirectMsgFp sendRedirectMsgFp;
|
||||
} SMnodeOpt;
|
||||
|
||||
/* ------------------------ SMnode ------------------------ */
|
||||
/**
|
||||
* @brief Open a mnode.
|
||||
*
|
||||
* @param path Path of the mnode.
|
||||
* @param pOption Option of the mnode.
|
||||
* @return SMnode* The mnode object.
|
||||
*/
|
||||
SMnode *mndOpen(const char *path, const SMnodeOpt *pOption);
|
||||
|
||||
/**
|
||||
* @brief Close a mnode.
|
||||
*
|
||||
* @param pMnode The mnode object to close.
|
||||
*/
|
||||
void mndClose(SMnode *pMnode);
|
||||
|
||||
/**
|
||||
* @brief Close a mnode.
|
||||
*
|
||||
* @param pMnode The mnode object to close.
|
||||
* @param pOption Options of the mnode.
|
||||
* @return int32_t 0 for success, -1 for failure.
|
||||
*/
|
||||
int32_t mndAlter(SMnode *pMnode, const SMnodeOpt *pOption);
|
||||
|
||||
/**
|
||||
* @brief Drop a mnode.
|
||||
*
|
||||
* @param path Path of the mnode.
|
||||
*/
|
||||
void mndDestroy(const char *path);
|
||||
|
||||
/**
|
||||
* @brief Get mnode statistics info.
|
||||
*
|
||||
* @param pMnode The mnode object.
|
||||
* @param pLoad Statistics of the mnode.
|
||||
* @return int32_t 0 for success, -1 for failure.
|
||||
*/
|
||||
int32_t mndGetLoad(SMnode *pMnode, SMnodeLoad *pLoad);
|
||||
|
||||
/**
|
||||
* @brief Get user authentication info.
|
||||
*
|
||||
* @param pMnode The mnode object.
|
||||
* @param user
|
||||
* @param spi
|
||||
* @param encrypt
|
||||
* @param secret
|
||||
* @param ckey
|
||||
* @return int32_t 0 for success, -1 for failure.
|
||||
*/
|
||||
int32_t mndRetriveAuth(SMnode *pMnode, char *user, char *spi, char *encrypt, char *secret, char *ckey);
|
||||
|
||||
/**
|
||||
* @brief Initialize mnode msg.
|
||||
*
|
||||
* @param pMnode The mnode object.
|
||||
* @param pMsg The request rpc msg.
|
||||
* @return int32_t The created mnode msg.
|
||||
*/
|
||||
SMnodeMsg *mndInitMsg(SMnode *pMnode, SRpcMsg *pRpcMsg);
|
||||
|
||||
/**
|
||||
* @brief Cleanup mnode msg.
|
||||
*
|
||||
* @param pMsg The request msg.
|
||||
*/
|
||||
void mndCleanupMsg(SMnodeMsg *pMsg);
|
||||
|
||||
/**
|
||||
* @brief Cleanup mnode msg.
|
||||
*
|
||||
* @param pMsg The request msg.
|
||||
* @param code The error code.
|
||||
*/
|
||||
void mndSendRsp(SMnodeMsg *pMsg, int32_t code);
|
||||
|
||||
/**
|
||||
* @brief Process the read request.
|
||||
*
|
||||
* @param pMsg The request msg.
|
||||
* @return int32_t 0 for success, -1 for failure.
|
||||
*/
|
||||
void mndProcessReadMsg(SMnodeMsg *pMsg);
|
||||
|
||||
/**
|
||||
* @brief Process the write request.
|
||||
*
|
||||
* @param pMsg The request msg.
|
||||
* @return int32_t 0 for success, -1 for failure.
|
||||
*/
|
||||
void mndProcessWriteMsg(SMnodeMsg *pMsg);
|
||||
|
||||
/**
|
||||
* @brief Process the sync request.
|
||||
*
|
||||
* @param pMsg The request msg.
|
||||
* @return int32_t 0 for success, -1 for failure.
|
||||
*/
|
||||
void mndProcessSyncMsg(SMnodeMsg *pMsg);
|
||||
|
||||
/**
|
||||
* @brief Process the apply request.
|
||||
*
|
||||
* @param pMsg The request msg.
|
||||
* @return int32_t 0 for success, -1 for failure.
|
||||
*/
|
||||
void mndProcessApplyMsg(SMnodeMsg *pMsg);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /*_TD_MNODE_H_*/
|
||||
#endif /*_TD_MND_H_*/
|
||||
|
|
|
@ -56,39 +56,39 @@ extern "C" {
|
|||
dataPos += valLen; \
|
||||
}
|
||||
|
||||
#define SDB_SET_INT64(pData, dataPos, val) \
|
||||
#define SDB_SET_INT64(pRaw, dataPos, val) \
|
||||
{ \
|
||||
if (sdbSetRawInt64(pRaw, dataPos, val) != 0) { \
|
||||
sdbFreeRaw(pRaw); \
|
||||
sdbFreeRaw(pRaw); \
|
||||
return NULL; \
|
||||
}; \
|
||||
} \
|
||||
dataPos += sizeof(int64_t); \
|
||||
}
|
||||
|
||||
#define SDB_SET_INT32(pData, dataPos, val) \
|
||||
#define SDB_SET_INT32(pRaw, dataPos, val) \
|
||||
{ \
|
||||
if (sdbSetRawInt32(pRaw, dataPos, val) != 0) { \
|
||||
sdbFreeRaw(pRaw); \
|
||||
sdbFreeRaw(pRaw); \
|
||||
return NULL; \
|
||||
}; \
|
||||
} \
|
||||
dataPos += sizeof(int32_t); \
|
||||
}
|
||||
|
||||
#define SDB_SET_INT8(pData, dataPos, val) \
|
||||
#define SDB_SET_INT8(pRaw, dataPos, val) \
|
||||
{ \
|
||||
if (sdbSetRawInt8(pRaw, dataPos, val) != 0) { \
|
||||
sdbFreeRaw(pRaw); \
|
||||
sdbFreeRaw(pRaw); \
|
||||
return NULL; \
|
||||
}; \
|
||||
} \
|
||||
dataPos += sizeof(int8_t); \
|
||||
}
|
||||
|
||||
#define SDB_SET_BINARY(pRaw, dataPos, val, valLen) \
|
||||
{ \
|
||||
if (sdbSetRawBinary(pRaw, dataPos, val, valLen) != 0) { \
|
||||
sdbFreeRaw(pRaw); \
|
||||
sdbFreeRaw(pRaw); \
|
||||
return NULL; \
|
||||
}; \
|
||||
} \
|
||||
dataPos += valLen; \
|
||||
}
|
||||
|
||||
|
@ -97,7 +97,7 @@ extern "C" {
|
|||
if (sdbSetRawDataLen(pRaw, dataLen) != 0) { \
|
||||
sdbFreeRaw(pRaw); \
|
||||
return NULL; \
|
||||
}; \
|
||||
} \
|
||||
}
|
||||
|
||||
typedef struct SSdbRaw SSdbRaw;
|
||||
|
@ -114,54 +114,181 @@ typedef enum {
|
|||
SDB_START = 0,
|
||||
SDB_TRANS = 1,
|
||||
SDB_CLUSTER = 2,
|
||||
SDB_DNODE = 3,
|
||||
SDB_MNODE = 4,
|
||||
SDB_MNODE = 3,
|
||||
SDB_DNODE = 4,
|
||||
SDB_USER = 5,
|
||||
SDB_AUTH = 6,
|
||||
SDB_ACCT = 7,
|
||||
SDB_DB = 8,
|
||||
SDB_VGROUP = 9,
|
||||
SDB_STABLE = 10,
|
||||
SDB_STABLE = 9,
|
||||
SDB_DB = 10,
|
||||
SDB_FUNC = 11,
|
||||
SDB_MAX = 12
|
||||
} ESdbType;
|
||||
|
||||
typedef int32_t (*SdbInsertFp)(void *pObj);
|
||||
typedef int32_t (*SdbUpdateFp)(void *pSrcObj, void *pDstObj);
|
||||
typedef int32_t (*SdbDeleteFp)(void *pObj);
|
||||
typedef int32_t (*SdbDeployFp)();
|
||||
typedef struct SSdb SSdb;
|
||||
typedef int32_t (*SdbInsertFp)(SSdb *pSdb, void *pObj);
|
||||
typedef int32_t (*SdbUpdateFp)(SSdb *pSdb, void *pSrcObj, void *pDstObj);
|
||||
typedef int32_t (*SdbDeleteFp)(SSdb *pSdb, void *pObj);
|
||||
typedef int32_t (*SdbDeployFp)(SSdb *pSdb);
|
||||
typedef SSdbRow *(*SdbDecodeFp)(SSdbRaw *pRaw);
|
||||
typedef SSdbRaw *(*SdbEncodeFp)(void *pObj);
|
||||
|
||||
typedef struct {
|
||||
ESdbType sdbType;
|
||||
EKeyType keyType;
|
||||
/**
|
||||
* @brief The sdb type of the table.
|
||||
*
|
||||
*/
|
||||
ESdbType sdbType;
|
||||
|
||||
/**
|
||||
* @brief The key type of the table.
|
||||
*
|
||||
*/
|
||||
EKeyType keyType;
|
||||
|
||||
/**
|
||||
* @brief The callback function when the table is first deployed.
|
||||
*
|
||||
*/
|
||||
SdbDeployFp deployFp;
|
||||
|
||||
/**
|
||||
* @brief Encode one row of the table into rawdata.
|
||||
*
|
||||
*/
|
||||
SdbEncodeFp encodeFp;
|
||||
|
||||
/**
|
||||
* @brief Decode one row of the table from rawdata.
|
||||
*
|
||||
*/
|
||||
SdbDecodeFp decodeFp;
|
||||
|
||||
/**
|
||||
* @brief The callback function when insert a row to sdb.
|
||||
*
|
||||
*/
|
||||
SdbInsertFp insertFp;
|
||||
|
||||
/**
|
||||
* @brief The callback function when undate a row in sdb.
|
||||
*
|
||||
*/
|
||||
SdbUpdateFp updateFp;
|
||||
|
||||
/**
|
||||
* @brief The callback function when delete a row from sdb.
|
||||
*
|
||||
*/
|
||||
SdbDeleteFp deleteFp;
|
||||
} SSdbTable;
|
||||
|
||||
int32_t sdbInit();
|
||||
void sdbCleanup();
|
||||
void sdbSetTable(SSdbTable table);
|
||||
typedef struct SSdbOpt {
|
||||
/**
|
||||
* @brief The path of the sdb file.
|
||||
*
|
||||
*/
|
||||
const char *path;
|
||||
} SSdbOpt;
|
||||
|
||||
int32_t sdbOpen();
|
||||
void sdbClose();
|
||||
int32_t sdbWrite(SSdbRaw *pRaw);
|
||||
/**
|
||||
* @brief Initialize and start the sdb.
|
||||
*
|
||||
* @param pOption Option of the sdb.
|
||||
* @return SSdb* The sdb object.
|
||||
*/
|
||||
SSdb *sdbInit(SSdbOpt *pOption);
|
||||
|
||||
int32_t sdbDeploy();
|
||||
void sdbUnDeploy();
|
||||
/**
|
||||
* @brief Stop and cleanup the sdb.
|
||||
*
|
||||
* @param pSdb The sdb object to close.
|
||||
*/
|
||||
void sdbCleanup(SSdb *pSdb);
|
||||
|
||||
void *sdbAcquire(ESdbType sdb, void *pKey);
|
||||
void sdbRelease(void *pObj);
|
||||
void *sdbFetch(ESdbType sdb, void *pIter, void **ppObj);
|
||||
void sdbCancelFetch(void *pIter);
|
||||
int32_t sdbGetSize(ESdbType sdb);
|
||||
/**
|
||||
* @brief Set the 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);
|
||||
|
||||
SSdbRaw *sdbAllocRaw(ESdbType sdb, int8_t sver, int32_t dataLen);
|
||||
/**
|
||||
* @brief Set the initial rows of sdb.
|
||||
*
|
||||
* @param pSdb The sdb object.
|
||||
* @return int32_t 0 for success, -1 for failure.
|
||||
*/
|
||||
int32_t sdbDeploy(SSdb *pSdb);
|
||||
|
||||
/**
|
||||
* @brief Load sdb from file.
|
||||
*
|
||||
* @param pSdb The sdb object.
|
||||
* @return int32_t 0 for success, -1 for failure.
|
||||
*/
|
||||
int32_t sdbReadFile(SSdb *pSdb);
|
||||
|
||||
/**
|
||||
* @brief Parse and write raw data to sdb.
|
||||
*
|
||||
* @param pSdb The sdb object.
|
||||
* @param pRaw The raw data.
|
||||
* @return int32_t 0 for success, -1 for failure.
|
||||
*/
|
||||
int32_t sdbWrite(SSdb *pSdb, SSdbRaw *pRaw);
|
||||
|
||||
/**
|
||||
* @brief Acquire a row from sdb
|
||||
*
|
||||
* @param pSdb The sdb object.
|
||||
* @param type The type of the row.
|
||||
* @param pKey The key value of the row.
|
||||
* @return void* The object of the row.
|
||||
*/
|
||||
void *sdbAcquire(SSdb *pSdb, ESdbType type, void *pKey);
|
||||
|
||||
/**
|
||||
* @brief Release a row from sdb.
|
||||
*
|
||||
* @param pSdb The sdb object.
|
||||
* @param pObj The object of the row.
|
||||
*/
|
||||
void sdbRelease(SSdb *pSdb, void *pObj);
|
||||
|
||||
/**
|
||||
* @brief Traverse a sdb table
|
||||
*
|
||||
* @param pSdb The sdb object.
|
||||
* @param type The type of the table.
|
||||
* @param type The initial iterator of the table.
|
||||
* @param pObj The object of the row just fetched.
|
||||
* @return void* The next iterator of the table.
|
||||
*/
|
||||
void *sdbFetch(SSdb *pSdb, ESdbType type, void *pIter, void **ppObj);
|
||||
|
||||
/**
|
||||
* @brief Cancel a traversal
|
||||
*
|
||||
* @param pSdb The sdb object.
|
||||
* @param pIter The iterator of the table.
|
||||
* @param type The initial iterator of table.
|
||||
*/
|
||||
void sdbCancelFetch(SSdb *pSdb, void *pIter);
|
||||
|
||||
/**
|
||||
* @brief Get the number of rows in the table
|
||||
*
|
||||
* @param pSdb The sdb object.
|
||||
* @param pIter The type of the table.
|
||||
* @record int32_t The number of rows in the table
|
||||
*/
|
||||
int32_t sdbGetSize(SSdb *pSdb, ESdbType type);
|
||||
|
||||
SSdbRaw *sdbAllocRaw(ESdbType type, int8_t sver, int32_t dataLen);
|
||||
void sdbFreeRaw(SSdbRaw *pRaw);
|
||||
int32_t sdbSetRawInt8(SSdbRaw *pRaw, int32_t dataPos, int8_t val);
|
||||
int32_t sdbSetRawInt32(SSdbRaw *pRaw, int32_t dataPos, int32_t val);
|
||||
|
|
|
@ -1,49 +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_H_
|
||||
#define _TD_TRANSACTION_H_
|
||||
|
||||
#include "sdb.h"
|
||||
#include "taosmsg.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
typedef struct STrans STrans;
|
||||
typedef enum { TRN_POLICY_ROLLBACK = 1, TRN_POLICY_RETRY = 2 } ETrnPolicy;
|
||||
|
||||
int32_t trnInit();
|
||||
void trnCleanup();
|
||||
|
||||
STrans *trnCreate(ETrnPolicy);
|
||||
void trnDrop(STrans *pTrans);
|
||||
void trnSetRpcHandle(STrans *pTrans, void *rpcHandle);
|
||||
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);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /*_TD_TRANSACTION_H_*/
|
|
@ -109,11 +109,10 @@ typedef struct TqTopicVhandle {
|
|||
|
||||
#define TQ_BUFFER_SIZE 8
|
||||
|
||||
// TODO: define a serializer and deserializer
|
||||
typedef struct TqBufferItem {
|
||||
int64_t offset;
|
||||
// executors are identical but not concurrent
|
||||
// so it must be a copy in each item
|
||||
// so there must be a copy in each item
|
||||
void* executor;
|
||||
int64_t size;
|
||||
void* content;
|
||||
|
@ -156,23 +155,111 @@ typedef struct TqQueryMsg {
|
|||
|
||||
typedef struct TqLogReader {
|
||||
void* logHandle;
|
||||
int32_t (*walRead)(void* logHandle, void** data, int64_t ver);
|
||||
int64_t (*walGetFirstVer)(void* logHandle);
|
||||
int64_t (*walGetSnapshotVer)(void* logHandle);
|
||||
int64_t (*walGetLastVer)(void* logHandle);
|
||||
int32_t (*logRead)(void* logHandle, void** data, int64_t ver);
|
||||
int64_t (*logGetFirstVer)(void* logHandle);
|
||||
int64_t (*logGetSnapshotVer)(void* logHandle);
|
||||
int64_t (*logGetLastVer)(void* logHandle);
|
||||
} TqLogReader;
|
||||
|
||||
typedef struct TqConfig {
|
||||
// TODO
|
||||
} TqConfig;
|
||||
|
||||
typedef struct TqMemRef {
|
||||
SMemAllocatorFactory *pAlloctorFactory;
|
||||
SMemAllocator *pAllocator;
|
||||
} TqMemRef;
|
||||
|
||||
typedef struct TqSerializedHead {
|
||||
int16_t ver;
|
||||
int16_t action;
|
||||
int32_t checksum;
|
||||
int64_t ssize;
|
||||
char content[];
|
||||
} TqSerializedHead;
|
||||
|
||||
typedef int (*TqSerializeFun)(const void* pObj, TqSerializedHead** ppHead);
|
||||
typedef const void* (*TqDeserializeFun)(const TqSerializedHead* pHead, void** ppObj);
|
||||
typedef void (*TqDeleteFun)(void*);
|
||||
|
||||
#define TQ_BUCKET_MASK 0xFF
|
||||
#define TQ_BUCKET_SIZE 256
|
||||
|
||||
#define TQ_PAGE_SIZE 4096
|
||||
//key + offset + size
|
||||
#define TQ_IDX_SIZE 24
|
||||
//4096 / 24
|
||||
#define TQ_MAX_IDX_ONE_PAGE 170
|
||||
//24 * 170
|
||||
#define TQ_IDX_PAGE_BODY_SIZE 4080
|
||||
//4096 - 4080
|
||||
#define TQ_IDX_PAGE_HEAD_SIZE 16
|
||||
|
||||
#define TQ_ACTION_CONST 0
|
||||
#define TQ_ACTION_INUSE 1
|
||||
#define TQ_ACTION_INUSE_CONT 2
|
||||
#define TQ_ACTION_INTXN 3
|
||||
|
||||
#define TQ_SVER 0
|
||||
|
||||
//TODO: inplace mode is not implemented
|
||||
#define TQ_UPDATE_INPLACE 0
|
||||
#define TQ_UPDATE_APPEND 1
|
||||
|
||||
#define TQ_DUP_INTXN_REWRITE 0
|
||||
#define TQ_DUP_INTXN_REJECT 2
|
||||
|
||||
static inline bool TqUpdateAppend(int32_t tqConfigFlag) {
|
||||
return tqConfigFlag & TQ_UPDATE_APPEND;
|
||||
}
|
||||
|
||||
static inline bool TqDupIntxnReject(int32_t tqConfigFlag) {
|
||||
return tqConfigFlag & TQ_DUP_INTXN_REJECT;
|
||||
}
|
||||
|
||||
static const int8_t TQ_CONST_DELETE = TQ_ACTION_CONST;
|
||||
#define TQ_DELETE_TOKEN (void*)&TQ_CONST_DELETE
|
||||
|
||||
typedef struct TqMetaHandle {
|
||||
int64_t key;
|
||||
int64_t offset;
|
||||
int64_t serializedSize;
|
||||
void* valueInUse;
|
||||
void* valueInTxn;
|
||||
} TqMetaHandle;
|
||||
|
||||
typedef struct TqMetaList {
|
||||
TqMetaHandle handle;
|
||||
struct TqMetaList* next;
|
||||
//struct TqMetaList* inTxnPrev;
|
||||
//struct TqMetaList* inTxnNext;
|
||||
struct TqMetaList* unpersistPrev;
|
||||
struct TqMetaList* unpersistNext;
|
||||
} TqMetaList;
|
||||
|
||||
typedef struct TqMetaStore {
|
||||
TqMetaList* bucket[TQ_BUCKET_SIZE];
|
||||
//a table head
|
||||
TqMetaList* unpersistHead;
|
||||
//TODO:temporaral use, to be replaced by unified tfile
|
||||
int fileFd;
|
||||
//TODO:temporaral use, to be replaced by unified tfile
|
||||
int idxFd;
|
||||
char* dirPath;
|
||||
int32_t tqConfigFlag;
|
||||
TqSerializeFun pSerializer;
|
||||
TqDeserializeFun pDeserializer;
|
||||
TqDeleteFun pDeleter;
|
||||
} TqMetaStore;
|
||||
|
||||
typedef struct STQ {
|
||||
// the collection of group handle
|
||||
// the handle of kvstore
|
||||
const char* path;
|
||||
char* path;
|
||||
TqConfig* tqConfig;
|
||||
TqLogReader* tqLogReader;
|
||||
SMemAllocatorFactory* allocFac;
|
||||
TqMemRef tqMemRef;
|
||||
TqMetaStore* tqMeta;
|
||||
} STQ;
|
||||
|
||||
// open in each vnode
|
||||
|
@ -187,7 +274,7 @@ int tqConsume(STQ*, TmqConsumeReq*);
|
|||
|
||||
TqGroupHandle* tqGetGroupHandle(STQ*, int64_t cId);
|
||||
|
||||
int tqOpenTCGroup(STQ*, int64_t topicId, int64_t cgId, int64_t cId);
|
||||
TqGroupHandle* tqOpenTCGroup(STQ*, int64_t topicId, int64_t cgId, int64_t cId);
|
||||
int tqCloseTCGroup(STQ*, int64_t topicId, int64_t cgId, int64_t cId);
|
||||
int tqMoveOffsetToNext(TqGroupHandle*);
|
||||
int tqResetOffset(STQ*, int64_t topicId, int64_t cgId, int64_t offset);
|
||||
|
@ -195,18 +282,9 @@ int tqRegisterContext(TqGroupHandle*, void* ahandle);
|
|||
int tqLaunchQuery(TqGroupHandle*);
|
||||
int tqSendLaunchQuery(TqGroupHandle*);
|
||||
|
||||
int tqSerializeGroupHandle(TqGroupHandle* gHandle, void** ppBytes);
|
||||
void* tqSerializeListHandle(TqListHandle* listHandle, void* ptr);
|
||||
void* tqSerializeBufHandle(TqBufferHandle* bufHandle, void* ptr);
|
||||
void* tqSerializeBufItem(TqBufferItem* bufItem, void* ptr);
|
||||
int tqSerializeGroupHandle(const TqGroupHandle* gHandle, TqSerializedHead** ppHead);
|
||||
|
||||
const void* tqDeserializeGroupHandle(const void* pBytes, TqGroupHandle* ghandle);
|
||||
const void* tqDeserializeBufHandle(const void* pBytes, TqBufferHandle* bufHandle);
|
||||
const void* tqDeserializeBufItem(const void* pBytes, TqBufferItem* bufItem);
|
||||
|
||||
int tqGetGHandleSSize(const TqGroupHandle* gHandle);
|
||||
int tqBufHandleSSize();
|
||||
int tqBufItemSSize();
|
||||
const void* tqDeserializeGroupHandle(const TqSerializedHead* pHead, TqGroupHandle** gHandle);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
|
|
@ -184,21 +184,9 @@ typedef struct {
|
|||
SRpcMsg rpcMsg[];
|
||||
} SVnodeMsg;
|
||||
|
||||
typedef struct {
|
||||
void (*SendMsgToDnode)(SEpSet *pEpSet, SRpcMsg *pMsg);
|
||||
void (*SendMsgToMnode)(SRpcMsg *pMsg);
|
||||
int32_t (*PutMsgIntoApplyQueue)(int32_t vgId, SVnodeMsg *pMsg);
|
||||
} SVnodePara;
|
||||
|
||||
int32_t vnodeInit(SVnodePara);
|
||||
void vnodeCleanup();
|
||||
|
||||
int32_t vnodeAlter(SVnode *pVnode, const SVnodeCfg *pCfg);
|
||||
SVnode *vnodeCreate(int32_t vgId, const char *path, const SVnodeCfg *pCfg);
|
||||
void vnodeDrop(SVnode *pVnode);
|
||||
int32_t vnodeCompact(SVnode *pVnode);
|
||||
int32_t vnodeSync(SVnode *pVnode);
|
||||
|
||||
int32_t vnodeGetLoad(SVnode *pVnode, SVnodeLoad *pLoad);
|
||||
|
||||
SVnodeMsg *vnodeInitMsg(int32_t msgNum);
|
||||
|
|
|
@ -51,7 +51,7 @@ typedef struct SRpcMsg {
|
|||
} SRpcMsg;
|
||||
|
||||
typedef struct SRpcInit {
|
||||
uint16_t localPort; // local port
|
||||
uint16_t localPort; // local port
|
||||
char *label; // for debug purpose
|
||||
int numOfThreads; // number of threads to handle connections
|
||||
int sessions; // number of sessions allowed
|
||||
|
@ -66,10 +66,12 @@ typedef struct SRpcInit {
|
|||
char *ckey; // ciphering key
|
||||
|
||||
// call back to process incoming msg, code shall be ignored by server app
|
||||
void (*cfp)(SRpcMsg *, SEpSet *);
|
||||
void (*cfp)(void *parent, SRpcMsg *, SEpSet *);
|
||||
|
||||
// call back to retrieve the client auth info, for server app only
|
||||
int (*afp)(char *tableId, char *spi, char *encrypt, char *secret, char *ckey);
|
||||
// call back to retrieve the client auth info, for server app only
|
||||
int (*afp)(void *parent, char *tableId, char *spi, char *encrypt, char *secret, char *ckey);
|
||||
|
||||
void *parent;
|
||||
} SRpcInit;
|
||||
|
||||
int32_t rpcInit();
|
||||
|
|
|
@ -16,11 +16,21 @@
|
|||
#define _TD_WAL_H_
|
||||
|
||||
#include "os.h"
|
||||
|
||||
#include "tdef.h"
|
||||
#include "tlog.h"
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
extern int32_t wDebugFlag;
|
||||
|
||||
#define wFatal(...) { if (wDebugFlag & DEBUG_FATAL) { taosPrintLog("WAL FATAL ", 255, __VA_ARGS__); }}
|
||||
#define wError(...) { if (wDebugFlag & DEBUG_ERROR) { taosPrintLog("WAL ERROR ", 255, __VA_ARGS__); }}
|
||||
#define wWarn(...) { if (wDebugFlag & DEBUG_WARN) { taosPrintLog("WAL WARN ", 255, __VA_ARGS__); }}
|
||||
#define wInfo(...) { if (wDebugFlag & DEBUG_INFO) { taosPrintLog("WAL ", 255, __VA_ARGS__); }}
|
||||
#define wDebug(...) { if (wDebugFlag & DEBUG_DEBUG) { taosPrintLog("WAL ", wDebugFlag, __VA_ARGS__); }}
|
||||
#define wTrace(...) { if (wDebugFlag & DEBUG_TRACE) { taosPrintLog("WAL ", wDebugFlag, __VA_ARGS__); }}
|
||||
|
||||
typedef enum {
|
||||
TAOS_WAL_NOLOG = 0,
|
||||
TAOS_WAL_WRITE = 1,
|
||||
|
@ -28,9 +38,8 @@ typedef enum {
|
|||
} EWalType;
|
||||
|
||||
typedef struct {
|
||||
int8_t msgType;
|
||||
int8_t sver; // sver 2 for WAL SDataRow/SMemRow compatibility
|
||||
int8_t reserved[2];
|
||||
int8_t sver;
|
||||
int8_t reserved[3];
|
||||
int32_t len;
|
||||
int64_t version;
|
||||
uint32_t signature;
|
||||
|
@ -44,21 +53,63 @@ typedef struct {
|
|||
EWalType walLevel; // wal level
|
||||
} SWalCfg;
|
||||
|
||||
struct SWal;
|
||||
typedef struct SWal SWal; // WAL HANDLE
|
||||
typedef int32_t (*FWalWrite)(void *ahandle, void *pHead, int32_t qtype, void *pMsg);
|
||||
#define WAL_PREFIX "wal"
|
||||
#define WAL_LOG_SUFFIX "log"
|
||||
#define WAL_INDEX_SUFFIX "idx"
|
||||
#define WAL_PREFIX_LEN 3
|
||||
#define WAL_REFRESH_MS 1000
|
||||
#define WAL_MAX_SIZE (TSDB_MAX_WAL_SIZE + sizeof(SWalHead) + 16)
|
||||
#define WAL_SIGNATURE ((uint32_t)(0xFAFBFDFEUL))
|
||||
#define WAL_PATH_LEN (TSDB_FILENAME_LEN + 12)
|
||||
#define WAL_FILE_LEN (WAL_PATH_LEN + 32)
|
||||
//#define WAL_FILE_NUM 1 // 3
|
||||
|
||||
#define WAL_CUR_POS_READ_ONLY 1
|
||||
#define WAL_CUR_FILE_READ_ONLY 2
|
||||
|
||||
typedef struct SWal {
|
||||
// cfg
|
||||
int32_t vgId;
|
||||
int32_t fsyncPeriod; // millisecond
|
||||
EWalType level;
|
||||
//reference
|
||||
int64_t refId;
|
||||
//current tfd
|
||||
int64_t curLogTfd;
|
||||
int64_t curIdxTfd;
|
||||
//current version
|
||||
int64_t curVersion;
|
||||
int64_t curOffset;
|
||||
//current file version
|
||||
int64_t curFileFirstVersion;
|
||||
int64_t curFileLastVersion;
|
||||
//wal fileset version
|
||||
int64_t firstVersion;
|
||||
int64_t snapshotVersion;
|
||||
int64_t lastVersion;
|
||||
//fsync status
|
||||
int32_t fsyncSeq;
|
||||
//ctl
|
||||
int32_t curStatus;
|
||||
pthread_mutex_t mutex;
|
||||
//path
|
||||
char path[WAL_PATH_LEN];
|
||||
} SWal; // WAL HANDLE
|
||||
|
||||
typedef int32_t (*FWalWrite)(void *ahandle, void *pHead);
|
||||
|
||||
// module initialization
|
||||
int32_t walInit();
|
||||
void walCleanUp();
|
||||
|
||||
// handle open and ctl
|
||||
SWal *walOpen(char *path, SWalCfg *pCfg);
|
||||
SWal *walOpen(const char *path, SWalCfg *pCfg);
|
||||
void walStop(SWal *pWal);
|
||||
int32_t walAlter(SWal *, SWalCfg *pCfg);
|
||||
void walClose(SWal *);
|
||||
|
||||
// write
|
||||
// int64_t walWriteWithMsgType(SWal*, int8_t msgType, void* body, int32_t bodyLen);
|
||||
//int64_t walWriteWithMsgType(SWal*, int8_t msgType, void* body, int32_t bodyLen);
|
||||
int64_t walWrite(SWal *, int64_t index, void *body, int32_t bodyLen);
|
||||
int64_t walWriteBatch(SWal *, void **bodies, int32_t *bodyLen, int32_t batchSize);
|
||||
|
||||
|
@ -68,7 +119,8 @@ int32_t walCommit(SWal *, int64_t ver);
|
|||
// truncate after
|
||||
int32_t walRollback(SWal *, int64_t ver);
|
||||
// notify that previous log can be pruned safely
|
||||
int32_t walPrune(SWal *, int64_t ver);
|
||||
int32_t walTakeSnapshot(SWal *, int64_t ver);
|
||||
//int32_t walDataCorrupted(SWal*);
|
||||
|
||||
// read
|
||||
int32_t walRead(SWal *, SWalHead **, int64_t ver);
|
||||
|
@ -78,7 +130,11 @@ int32_t walReadWithFp(SWal *, FWalWrite writeFp, int64_t verStart, int32_t readN
|
|||
int64_t walGetFirstVer(SWal *);
|
||||
int64_t walGetSnapshotVer(SWal *);
|
||||
int64_t walGetLastVer(SWal *);
|
||||
// int32_t walDataCorrupted(SWal*);
|
||||
|
||||
//internal
|
||||
int32_t walGetNextFile(SWal *pWal, int64_t *nextFileId);
|
||||
int32_t walGetOldFile(SWal *pWal, int64_t curFileId, int32_t minDiff, int64_t *oldFileId);
|
||||
int32_t walGetNewFile(SWal *pWal, int64_t *newFileId);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
|
|
@ -46,6 +46,7 @@ extern "C" {
|
|||
#include <math.h>
|
||||
#include <sys/stat.h>
|
||||
#include <sys/types.h>
|
||||
#include <dirent.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include "osAtomic.h"
|
||||
|
|
|
@ -20,12 +20,12 @@
|
|||
extern "C" {
|
||||
#endif
|
||||
|
||||
void taosRemoveDir(const char *dirname);
|
||||
bool taosDirExist(char *dirname);
|
||||
bool taosMkDir(const char *dirname);
|
||||
void taosRemoveOldFiles(char *dirname, int32_t keepDays);
|
||||
bool taosExpandDir(char *dirname, char *outname, int32_t maxlen);
|
||||
bool taosRealPath(char *dirname, int32_t maxlen);
|
||||
void taosRemoveDir(const char *dirname);
|
||||
int32_t taosDirExist(char *dirname);
|
||||
int32_t taosMkDir(const char *dirname);
|
||||
void taosRemoveOldFiles(char *dirname, int32_t keepDays);
|
||||
int32_t taosExpandDir(char *dirname, char *outname, int32_t maxlen);
|
||||
int32_t taosRealPath(char *dirname, int32_t maxlen);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
|
|
@ -68,12 +68,13 @@ int32_t* taosGetErrno();
|
|||
#define TSDB_CODE_FILE_CORRUPTED TAOS_DEF_ERROR_CODE(0, 0x0106)
|
||||
#define TSDB_CODE_CHECKSUM_ERROR TAOS_DEF_ERROR_CODE(0, 0x0107)
|
||||
#define TSDB_CODE_INVALID_MSG TAOS_DEF_ERROR_CODE(0, 0x0108)
|
||||
#define TSDB_CODE_REF_NO_MEMORY TAOS_DEF_ERROR_CODE(0, 0x0109)
|
||||
#define TSDB_CODE_REF_FULL TAOS_DEF_ERROR_CODE(0, 0x010A)
|
||||
#define TSDB_CODE_REF_ID_REMOVED TAOS_DEF_ERROR_CODE(0, 0x010B)
|
||||
#define TSDB_CODE_REF_INVALID_ID TAOS_DEF_ERROR_CODE(0, 0x010C)
|
||||
#define TSDB_CODE_REF_ALREADY_EXIST TAOS_DEF_ERROR_CODE(0, 0x010D)
|
||||
#define TSDB_CODE_REF_NOT_EXIST TAOS_DEF_ERROR_CODE(0, 0x010E)
|
||||
#define TSDB_CODE_MSG_NOT_PROCESSED TAOS_DEF_ERROR_CODE(0, 0x0109)
|
||||
#define TSDB_CODE_REF_NO_MEMORY TAOS_DEF_ERROR_CODE(0, 0x0110)
|
||||
#define TSDB_CODE_REF_FULL TAOS_DEF_ERROR_CODE(0, 0x0111)
|
||||
#define TSDB_CODE_REF_ID_REMOVED TAOS_DEF_ERROR_CODE(0, 0x0112)
|
||||
#define TSDB_CODE_REF_INVALID_ID TAOS_DEF_ERROR_CODE(0, 0x0113)
|
||||
#define TSDB_CODE_REF_ALREADY_EXIST TAOS_DEF_ERROR_CODE(0, 0x0114)
|
||||
#define TSDB_CODE_REF_NOT_EXIST TAOS_DEF_ERROR_CODE(0, 0x0115)
|
||||
|
||||
//client
|
||||
#define TSDB_CODE_TSC_INVALID_OPERATION TAOS_DEF_ERROR_CODE(0, 0x0200) //"Invalid Operation")
|
||||
|
@ -223,20 +224,20 @@ int32_t* taosGetErrno();
|
|||
#define TSDB_CODE_MND_TOPIC_ALREADY_EXIST TAOS_DEF_ERROR_CODE(0, 0x0395) //"Topic already exists)
|
||||
|
||||
// dnode
|
||||
#define TSDB_CODE_DND_MSG_NOT_PROCESSED TAOS_DEF_ERROR_CODE(0, 0x0400) //"Message not processed")
|
||||
#define TSDB_CODE_DND_OUT_OF_MEMORY TAOS_DEF_ERROR_CODE(0, 0x0401) //"Dnode out of memory")
|
||||
#define TSDB_CODE_DND_MNODE_ID_NOT_MATCH_DNODE TAOS_DEF_ERROR_CODE(0, 0x0402) //"Mnode Id not match Dnode")
|
||||
#define TSDB_CODE_DND_MNODE_ALREADY_DEPLOYED TAOS_DEF_ERROR_CODE(0, 0x0403) //"Mnode already deployed")
|
||||
#define TSDB_CODE_DND_MNODE_NOT_DEPLOYED TAOS_DEF_ERROR_CODE(0, 0x0404) //"Mnode not deployed")
|
||||
#define TSDB_CODE_DND_READ_MNODE_FILE_ERROR TAOS_DEF_ERROR_CODE(0, 0x0405) //"Read mnode.json error")
|
||||
#define TSDB_CODE_DND_WRITE_MNODE_FILE_ERROR TAOS_DEF_ERROR_CODE(0, 0x0406) //"Write mnode.json error")
|
||||
#define TSDB_CODE_DND_NO_WRITE_ACCESS TAOS_DEF_ERROR_CODE(0, 0x0407) //"No permission for disk files in dnode")
|
||||
#define TSDB_CODE_DND_INVALID_MSG_LEN TAOS_DEF_ERROR_CODE(0, 0x0408) //"Invalid message length")
|
||||
#define TSDB_CODE_DND_ACTION_IN_PROGRESS TAOS_DEF_ERROR_CODE(0, 0x0409) //"Action in progress")
|
||||
#define TSDB_CODE_DND_TOO_MANY_VNODES TAOS_DEF_ERROR_CODE(0, 0x040A) //"Too many vnode directories")
|
||||
#define TSDB_CODE_DND_EXITING TAOS_DEF_ERROR_CODE(0, 0x040B) //"Dnode is exiting"
|
||||
#define TSDB_CODE_DND_PARSE_VNODE_FILE_ERROR TAOS_DEF_ERROR_CODE(0, 0x040C) //"Parse vnodes.json error")
|
||||
#define TSDB_CODE_DND_PARSE_DNODE_FILE_ERROR TAOS_DEF_ERROR_CODE(0, 0x040D) //"Parse dnodes.json error")
|
||||
#define TSDB_CODE_DND_ACTION_IN_PROGRESS TAOS_DEF_ERROR_CODE(0, 0x0400)
|
||||
#define TSDB_CODE_DND_EXITING TAOS_DEF_ERROR_CODE(0, 0x0401)
|
||||
#define TSDB_CODE_DND_INVALID_MSG_LEN TAOS_DEF_ERROR_CODE(0, 0x0402)
|
||||
#define TSDB_CODE_DND_DNODE_READ_FILE_ERROR TAOS_DEF_ERROR_CODE(0, 0x0410)
|
||||
#define TSDB_CODE_DND_DNODE_WRITE_FILE_ERROR TAOS_DEF_ERROR_CODE(0, 0x0411)
|
||||
#define TSDB_CODE_DND_MNODE_ALREADY_DEPLOYED TAOS_DEF_ERROR_CODE(0, 0x0420)
|
||||
#define TSDB_CODE_DND_MNODE_NOT_DEPLOYED TAOS_DEF_ERROR_CODE(0, 0x0421)
|
||||
#define TSDB_CODE_DND_MNODE_ID_INVALID TAOS_DEF_ERROR_CODE(0, 0x0422)
|
||||
#define TSDB_CODE_DND_MNODE_ID_NOT_FOUND TAOS_DEF_ERROR_CODE(0, 0x0423)
|
||||
#define TSDB_CODE_DND_MNODE_READ_FILE_ERROR TAOS_DEF_ERROR_CODE(0, 0x0424)
|
||||
#define TSDB_CODE_DND_MNODE_WRITE_FILE_ERROR TAOS_DEF_ERROR_CODE(0, 0x0425)
|
||||
#define TSDB_CODE_DND_VNODE_TOO_MANY_VNODES TAOS_DEF_ERROR_CODE(0, 0x0430)
|
||||
#define TSDB_CODE_DND_VNODE_READ_FILE_ERROR TAOS_DEF_ERROR_CODE(0, 0x0431)
|
||||
#define TSDB_CODE_DND_VNODE_WRITE_FILE_ERROR TAOS_DEF_ERROR_CODE(0, 0x0432)
|
||||
|
||||
// vnode
|
||||
#define TSDB_CODE_VND_ACTION_IN_PROGRESS TAOS_DEF_ERROR_CODE(0, 0x0500) //"Action in progress")
|
||||
|
|
|
@ -82,10 +82,10 @@ extern SGlobalCfg tsGlobalConfig[];
|
|||
extern int32_t tsGlobalConfigNum;
|
||||
extern char * tsCfgStatusStr[];
|
||||
|
||||
void taosReadGlobalLogCfg();
|
||||
bool taosReadGlobalCfg();
|
||||
void taosPrintGlobalCfg();
|
||||
void taosDumpGlobalCfg();
|
||||
void taosReadGlobalLogCfg();
|
||||
int32_t taosReadGlobalCfg();
|
||||
void taosPrintGlobalCfg();
|
||||
void taosDumpGlobalCfg();
|
||||
|
||||
void taosInitConfigOption(SGlobalCfg cfg);
|
||||
SGlobalCfg *taosGetConfigOption(const char *option);
|
||||
|
|
|
@ -358,12 +358,6 @@ do { \
|
|||
#define TSDB_DEFAULT_STABLES_HASH_SIZE 100
|
||||
#define TSDB_DEFAULT_CTABLES_HASH_SIZE 20000
|
||||
|
||||
#define TSDB_PORT_DNODESHELL 0
|
||||
#define TSDB_PORT_DNODEDNODE 5
|
||||
#define TSDB_PORT_SYNC 10
|
||||
#define TSDB_PORT_HTTP 11
|
||||
#define TSDB_PORT_ARBITRATOR 12
|
||||
|
||||
#define TSDB_MAX_WAL_SIZE (1024*1024*3)
|
||||
|
||||
#define TSDB_ARB_DUMMY_TIME 4765104000000 // 2121-01-01 00:00:00.000, :P
|
||||
|
|
|
@ -16,6 +16,8 @@
|
|||
#ifndef _TD_UTIL_LOG_H
|
||||
#define _TD_UTIL_LOG_H
|
||||
|
||||
#include "os.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
|
|
@ -38,9 +38,9 @@ extern SNoteObj tsHttpNote;
|
|||
extern SNoteObj tsTscNote;
|
||||
extern SNoteObj tsInfoNote;
|
||||
|
||||
void taosInitNotes();
|
||||
void taosNotePrint(SNoteObj* pNote, const char* const format, ...);
|
||||
void taosNotePrintBuffer(SNoteObj *pNote, char *buffer, int32_t len);
|
||||
int32_t taosInitNotes();
|
||||
void taosNotePrint(SNoteObj* pNote, const char* const format, ...);
|
||||
void taosNotePrintBuffer(SNoteObj* pNote, char* buffer, int32_t len);
|
||||
|
||||
#define nPrintHttp(...) \
|
||||
if (tsHttpEnableRecordSql) { \
|
||||
|
@ -53,7 +53,7 @@ void taosNotePrintBuffer(SNoteObj *pNote, char *buffer, int32_t len);
|
|||
}
|
||||
|
||||
#define nInfo(buffer, len) \
|
||||
if (tscEmbedded == 1) { \
|
||||
if (tscEmbeddedInUtil == 1) { \
|
||||
taosNotePrintBuffer(&tsInfoNote, buffer, len); \
|
||||
}
|
||||
|
||||
|
|
|
@ -22,10 +22,13 @@
|
|||
extern "C" {
|
||||
#endif
|
||||
|
||||
typedef struct SWorkerPool SWorkerPool;
|
||||
typedef struct SMWorkerPool SMWorkerPool;
|
||||
|
||||
typedef struct SWorker {
|
||||
int32_t id; // worker ID
|
||||
pthread_t thread; // thread
|
||||
struct SWorkerPool *pool;
|
||||
int32_t id; // worker ID
|
||||
pthread_t thread; // thread
|
||||
SWorkerPool *pool;
|
||||
} SWorker;
|
||||
|
||||
typedef struct SWorkerPool {
|
||||
|
@ -39,11 +42,11 @@ typedef struct SWorkerPool {
|
|||
} SWorkerPool;
|
||||
|
||||
typedef struct SMWorker {
|
||||
int32_t id; // worker id
|
||||
pthread_t thread; // thread
|
||||
taos_qall qall;
|
||||
taos_qset qset; // queue set
|
||||
struct SMWorkerPool *pool;
|
||||
int32_t id; // worker id
|
||||
pthread_t thread; // thread
|
||||
taos_qall qall;
|
||||
taos_qset qset; // queue set
|
||||
SMWorkerPool *pool;
|
||||
} SMWorker;
|
||||
|
||||
typedef struct SMWorkerPool {
|
||||
|
|
|
@ -20,20 +20,21 @@
|
|||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include "os.h"
|
||||
#include "tlog.h"
|
||||
|
||||
extern int32_t uDebugFlag;
|
||||
extern int8_t tscEmbedded;
|
||||
extern int8_t tscEmbeddedInUtil;
|
||||
|
||||
#define uFatal(...) { if (uDebugFlag & DEBUG_FATAL) { taosPrintLog("UTL FATAL", tscEmbedded ? 255 : uDebugFlag, __VA_ARGS__); }}
|
||||
#define uError(...) { if (uDebugFlag & DEBUG_ERROR) { taosPrintLog("UTL ERROR ", tscEmbedded ? 255 : uDebugFlag, __VA_ARGS__); }}
|
||||
#define uWarn(...) { if (uDebugFlag & DEBUG_WARN) { taosPrintLog("UTL WARN ", tscEmbedded ? 255 : uDebugFlag, __VA_ARGS__); }}
|
||||
#define uInfo(...) { if (uDebugFlag & DEBUG_INFO) { taosPrintLog("UTL ", tscEmbedded ? 255 : uDebugFlag, __VA_ARGS__); }}
|
||||
#define uFatal(...) { if (uDebugFlag & DEBUG_FATAL) { taosPrintLog("UTL FATAL", tscEmbeddedInUtil ? 255 : uDebugFlag, __VA_ARGS__); }}
|
||||
#define uError(...) { if (uDebugFlag & DEBUG_ERROR) { taosPrintLog("UTL ERROR ", tscEmbeddedInUtil ? 255 : uDebugFlag, __VA_ARGS__); }}
|
||||
#define uWarn(...) { if (uDebugFlag & DEBUG_WARN) { taosPrintLog("UTL WARN ", tscEmbeddedInUtil ? 255 : uDebugFlag, __VA_ARGS__); }}
|
||||
#define uInfo(...) { if (uDebugFlag & DEBUG_INFO) { taosPrintLog("UTL ", tscEmbeddedInUtil ? 255 : uDebugFlag, __VA_ARGS__); }}
|
||||
#define uDebug(...) { if (uDebugFlag & DEBUG_DEBUG) { taosPrintLog("UTL ", uDebugFlag, __VA_ARGS__); }}
|
||||
#define uTrace(...) { if (uDebugFlag & DEBUG_TRACE) { taosPrintLog("UTL ", uDebugFlag, __VA_ARGS__); }}
|
||||
|
||||
#define pError(...) { taosPrintLog("APP ERROR ", 255, __VA_ARGS__); }
|
||||
#define pPrint(...) { taosPrintLog("APP ", 255, __VA_ARGS__); }
|
||||
#define pError(...) { taosPrintLog("APP ERROR ", 255, __VA_ARGS__); }
|
||||
#define pPrint(...) { taosPrintLog("APP ", 255, __VA_ARGS__); }
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
|
|
@ -33,10 +33,6 @@ char tsArbitrator[TSDB_EP_LEN] = {0};
|
|||
char tsLocalFqdn[TSDB_FQDN_LEN] = {0};
|
||||
char tsLocalEp[TSDB_EP_LEN] = {0}; // Local End Point, hostname:port
|
||||
uint16_t tsServerPort = 6030;
|
||||
uint16_t tsDnodeShellPort = 6030; // udp[6035-6039] tcp[6035]
|
||||
uint16_t tsDnodeDnodePort = 6035; // udp/tcp
|
||||
uint16_t tsSyncPort = 6040;
|
||||
uint16_t tsArbitratorPort = 6042;
|
||||
int32_t tsStatusInterval = 1; // second
|
||||
int32_t tsNumOfMnodes = 1;
|
||||
int8_t tsEnableVnodeBak = 1;
|
||||
|
@ -1679,7 +1675,7 @@ int32_t taosCheckGlobalCfg() {
|
|||
|
||||
taosCheckDataDirCfg();
|
||||
|
||||
if (!taosDirExist(tsTempDir)) {
|
||||
if (taosDirExist(tsTempDir) != 0) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
@ -1726,11 +1722,6 @@ int32_t taosCheckGlobalCfg() {
|
|||
}
|
||||
}
|
||||
|
||||
tsDnodeShellPort = tsServerPort + TSDB_PORT_DNODESHELL; // udp[6035-6039] tcp[6035]
|
||||
tsDnodeDnodePort = tsServerPort + TSDB_PORT_DNODEDNODE; // udp/tcp
|
||||
tsSyncPort = tsServerPort + TSDB_PORT_SYNC;
|
||||
tsHttpPort = tsServerPort + TSDB_PORT_HTTP;
|
||||
|
||||
if (tsQueryBufferSize >= 0) {
|
||||
tsQueryBufferSizeBytes = tsQueryBufferSize * 1048576UL;
|
||||
}
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
add_subdirectory(mnode)
|
||||
add_subdirectory(vnode)
|
||||
add_subdirectory(qnode)
|
||||
add_subdirectory(mgmt)
|
||||
add_subdirectory(mgmt)
|
|
@ -1,16 +1,2 @@
|
|||
aux_source_directory(src DNODE_SRC)
|
||||
add_executable(taosd ${DNODE_SRC})
|
||||
target_link_libraries(
|
||||
taosd
|
||||
PUBLIC cjson
|
||||
PUBLIC mnode
|
||||
PUBLIC vnode
|
||||
PUBLIC wal
|
||||
PUBLIC sync
|
||||
PUBLIC taos
|
||||
)
|
||||
target_include_directories(
|
||||
taosd
|
||||
PUBLIC "${CMAKE_SOURCE_DIR}/include/dnode"
|
||||
private "${CMAKE_CURRENT_SOURCE_DIR}/inc"
|
||||
)
|
||||
add_subdirectory(daemon)
|
||||
add_subdirectory(impl)
|
|
@ -0,0 +1,8 @@
|
|||
aux_source_directory(src DAEMON_SRC)
|
||||
add_executable(taosd ${DAEMON_SRC})
|
||||
target_link_libraries(
|
||||
taosd
|
||||
PUBLIC dnode
|
||||
PUBLIC util
|
||||
PUBLIC os
|
||||
)
|
|
@ -0,0 +1,200 @@
|
|||
/*
|
||||
* 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 "dnode.h"
|
||||
#include "os.h"
|
||||
#include "tconfig.h"
|
||||
#include "tglobal.h"
|
||||
#include "tnote.h"
|
||||
#include "ulog.h"
|
||||
|
||||
static struct {
|
||||
bool stop;
|
||||
bool dumpConfig;
|
||||
bool generateGrant;
|
||||
bool printAuth;
|
||||
bool printVersion;
|
||||
char configDir[PATH_MAX];
|
||||
} global = {0};
|
||||
|
||||
void dmnSigintHandle(int signum, void *info, void *ctx) {
|
||||
uError("singal:%d is received", signum);
|
||||
global.stop = true;
|
||||
}
|
||||
|
||||
void dmnSetSignalHandle() {
|
||||
taosSetSignal(SIGTERM, dmnSigintHandle);
|
||||
taosSetSignal(SIGHUP, dmnSigintHandle);
|
||||
taosSetSignal(SIGINT, dmnSigintHandle);
|
||||
taosSetSignal(SIGABRT, dmnSigintHandle);
|
||||
taosSetSignal(SIGBREAK, dmnSigintHandle);
|
||||
}
|
||||
|
||||
int dmnParseOption(int argc, char const *argv[]) {
|
||||
tstrncpy(global.configDir, "/etc/taos", PATH_MAX);
|
||||
|
||||
for (int i = 1; i < argc; ++i) {
|
||||
if (strcmp(argv[i], "-c") == 0) {
|
||||
if (i < argc - 1) {
|
||||
if (strlen(argv[++i]) >= PATH_MAX) {
|
||||
printf("config file path overflow");
|
||||
return -1;
|
||||
}
|
||||
tstrncpy(global.configDir, argv[i], PATH_MAX);
|
||||
} else {
|
||||
printf("'-c' requires a parameter, default is %s\n", configDir);
|
||||
return -1;
|
||||
}
|
||||
} else if (strcmp(argv[i], "-C") == 0) {
|
||||
global.dumpConfig = true;
|
||||
} else if (strcmp(argv[i], "-k") == 0) {
|
||||
global.generateGrant = true;
|
||||
} else if (strcmp(argv[i], "-A") == 0) {
|
||||
global.printAuth = true;
|
||||
} else if (strcmp(argv[i], "-V") == 0) {
|
||||
global.printVersion = true;
|
||||
} else {
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void dmnGenerateGrant() {
|
||||
#if 0
|
||||
grantParseParameter();
|
||||
#endif
|
||||
}
|
||||
|
||||
void dmnPrintVersion() {
|
||||
#ifdef TD_ENTERPRISE
|
||||
char *releaseName = "enterprise";
|
||||
#else
|
||||
char *releaseName = "community";
|
||||
#endif
|
||||
printf("%s version: %s compatible_version: %s\n", releaseName, version, compatible_version);
|
||||
printf("gitinfo: %s\n", gitinfo);
|
||||
printf("gitinfoI: %s\n", gitinfoOfInternal);
|
||||
printf("builuInfo: %s\n", buildinfo);
|
||||
}
|
||||
|
||||
int dmnReadConfig(const char *path) {
|
||||
taosInitGlobalCfg();
|
||||
taosReadGlobalLogCfg();
|
||||
|
||||
if (taosMkDir(tsLogDir) != 0) {
|
||||
printf("failed to create dir: %s, reason: %s\n", tsLogDir, strerror(errno));
|
||||
return -1;
|
||||
}
|
||||
|
||||
char temp[PATH_MAX];
|
||||
snprintf(temp, PATH_MAX, "%s/taosdlog", tsLogDir);
|
||||
if (taosInitLog(temp, tsNumOfLogLines, 1) != 0) {
|
||||
printf("failed to init log file\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (taosInitNotes() != 0) {
|
||||
printf("failed to init log file\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (taosReadGlobalCfg() != 0) {
|
||||
uError("failed to read global config");
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (taosCheckGlobalCfg() != 0) {
|
||||
uError("failed to check global config");
|
||||
return -1;
|
||||
}
|
||||
|
||||
taosSetCoreDump(tsEnableCoreFile);
|
||||
return 0;
|
||||
}
|
||||
|
||||
void dmnDumpConfig() { taosDumpGlobalCfg(); }
|
||||
|
||||
void dmnWaitSignal() {
|
||||
dmnSetSignalHandle();
|
||||
while (!global.stop) {
|
||||
taosMsleep(100);
|
||||
}
|
||||
}
|
||||
|
||||
void dmnInitOption(SDnodeOpt *pOption) {
|
||||
pOption->sver = tsVersion;
|
||||
pOption->numOfCores = tsNumOfCores;
|
||||
pOption->numOfThreadsPerCore = tsNumOfThreadsPerCore;
|
||||
pOption->ratioOfQueryCores = tsRatioOfQueryCores;
|
||||
pOption->maxShellConns = tsMaxShellConns;
|
||||
pOption->shellActivityTimer = tsShellActivityTimer;
|
||||
pOption->statusInterval = tsStatusInterval;
|
||||
pOption->serverPort = tsServerPort;
|
||||
tstrncpy(pOption->dataDir, tsDataDir, TSDB_FILENAME_LEN);
|
||||
tstrncpy(pOption->localEp, tsLocalEp, TSDB_EP_LEN);
|
||||
tstrncpy(pOption->localFqdn, tsLocalFqdn, TSDB_FQDN_LEN);
|
||||
tstrncpy(pOption->firstEp, tsFirst, TSDB_EP_LEN);
|
||||
tstrncpy(pOption->timezone, tsTimezone, TSDB_TIMEZONE_LEN);
|
||||
tstrncpy(pOption->locale, tsLocale, TSDB_LOCALE_LEN);
|
||||
tstrncpy(pOption->charset, tsCharset, TSDB_LOCALE_LEN);
|
||||
}
|
||||
|
||||
int dmnRunDnode() {
|
||||
SDnodeOpt option = {0};
|
||||
dmnInitOption(&option);
|
||||
|
||||
SDnode *pDnode = dndInit(&option);
|
||||
if (pDnode == NULL) {
|
||||
uInfo("Failed to start TDengine, please check the log at %s", tsLogDir);
|
||||
return -1;
|
||||
}
|
||||
|
||||
uInfo("Started TDengine service successfully.");
|
||||
dmnWaitSignal();
|
||||
uInfo("TDengine is shut down!");
|
||||
|
||||
dndCleanup(pDnode);
|
||||
taosCloseLog();
|
||||
return 0;
|
||||
}
|
||||
|
||||
int main(int argc, char const *argv[]) {
|
||||
if (dmnParseOption(argc, argv) != 0) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (global.generateGrant) {
|
||||
dmnGenerateGrant();
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (global.printVersion) {
|
||||
dmnPrintVersion();
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (dmnReadConfig(global.configDir) != 0) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (global.dumpConfig) {
|
||||
dmnDumpConfig();
|
||||
return 0;
|
||||
}
|
||||
|
||||
return dmnRunDnode();
|
||||
}
|
|
@ -0,0 +1,16 @@
|
|||
aux_source_directory(src DNODE_SRC)
|
||||
add_library(dnode STATIC ${DNODE_SRC})
|
||||
target_link_libraries(
|
||||
dnode
|
||||
PUBLIC cjson
|
||||
PUBLIC mnode
|
||||
PUBLIC vnode
|
||||
PUBLIC wal
|
||||
PUBLIC sync
|
||||
PUBLIC taos
|
||||
)
|
||||
target_include_directories(
|
||||
dnode
|
||||
PUBLIC "${CMAKE_SOURCE_DIR}/include/dnode/mgmt"
|
||||
PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/inc"
|
||||
)
|
|
@ -13,27 +13,27 @@
|
|||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef _TD_DNODE_DNODE_H_
|
||||
#define _TD_DNODE_DNODE_H_
|
||||
#ifndef _TD_DND_DNODE_H_
|
||||
#define _TD_DND_DNODE_H_
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
#include "dnodeInt.h"
|
||||
#include "dndInt.h"
|
||||
|
||||
int32_t dnodeInitDnode();
|
||||
void dnodeCleanupDnode();
|
||||
void dnodeProcessDnodeMsg(SRpcMsg *pMsg, SEpSet *pEpSet);
|
||||
int32_t dndInitDnode(SDnode *pDnode);
|
||||
void dndCleanupDnode(SDnode *pDnode);
|
||||
void dndProcessDnodeReq(SDnode *pDnode, SRpcMsg *pMsg, SEpSet *pEpSet);
|
||||
void dndProcessDnodeRsp(SDnode *pDnode, SRpcMsg *pMsg, SEpSet *pEpSet);
|
||||
|
||||
int32_t dnodeGetDnodeId();
|
||||
int64_t dnodeGetClusterId();
|
||||
void dnodeGetDnodeEp(int32_t dnodeId, char *epstr, char *fqdn, uint16_t *port);
|
||||
void dnodeGetMnodeEpSetForPeer(SEpSet *epSet);
|
||||
void dnodeGetMnodeEpSetForShell(SEpSet *epSet);
|
||||
void dnodeSendRedirectMsg(SRpcMsg *rpcMsg, bool forShell);
|
||||
int32_t dndGetDnodeId(SDnode *pDnode);
|
||||
int64_t dndGetClusterId(SDnode *pDnode);
|
||||
void dndGetDnodeEp(SDnode *pDnode, int32_t dnodeId, char *pEp, char *pFqdn, uint16_t *pPort);
|
||||
void dndGetMnodeEpSet(SDnode *pDnode, SEpSet *pEpSet);
|
||||
void dndSendRedirectMsg(SDnode *pDnode, SRpcMsg *pMsg);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /*_TD_DNODE_DNODE_H_*/
|
||||
#endif /*_TD_DND_DNODE_H_*/
|
|
@ -0,0 +1,132 @@
|
|||
/*
|
||||
* 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_DND_INT_H_
|
||||
#define _TD_DND_INT_H_
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include "cJSON.h"
|
||||
#include "os.h"
|
||||
#include "taosmsg.h"
|
||||
#include "thash.h"
|
||||
#include "tlockfree.h"
|
||||
#include "tlog.h"
|
||||
#include "tqueue.h"
|
||||
#include "trpc.h"
|
||||
#include "tthread.h"
|
||||
#include "ttime.h"
|
||||
#include "tworker.h"
|
||||
|
||||
#include "dnode.h"
|
||||
#include "mnode.h"
|
||||
#include "vnode.h"
|
||||
|
||||
extern int32_t dDebugFlag;
|
||||
|
||||
#define dFatal(...) { if (dDebugFlag & DEBUG_FATAL) { taosPrintLog("DND FATAL ", 255, __VA_ARGS__); }}
|
||||
#define dError(...) { if (dDebugFlag & DEBUG_ERROR) { taosPrintLog("DND ERROR ", 255, __VA_ARGS__); }}
|
||||
#define dWarn(...) { if (dDebugFlag & DEBUG_WARN) { taosPrintLog("DND WARN ", 255, __VA_ARGS__); }}
|
||||
#define dInfo(...) { if (dDebugFlag & DEBUG_INFO) { taosPrintLog("DND ", 255, __VA_ARGS__); }}
|
||||
#define dDebug(...) { if (dDebugFlag & DEBUG_DEBUG) { taosPrintLog("DND ", dDebugFlag, __VA_ARGS__); }}
|
||||
#define dTrace(...) { if (dDebugFlag & DEBUG_TRACE) { taosPrintLog("DND ", dDebugFlag, __VA_ARGS__); }}
|
||||
|
||||
typedef enum { DND_STAT_INIT, DND_STAT_RUNNING, DND_STAT_STOPPED } EStat;
|
||||
typedef void (*DndMsgFp)(SDnode *pDnode, SRpcMsg *pMsg, SEpSet *pEps);
|
||||
|
||||
typedef struct {
|
||||
char *dnode;
|
||||
char *mnode;
|
||||
char *vnodes;
|
||||
} SDnodeDir;
|
||||
|
||||
typedef struct {
|
||||
int32_t dnodeId;
|
||||
int32_t dropped;
|
||||
uint32_t rebootTime;
|
||||
int64_t clusterId;
|
||||
SEpSet mnodeEpSet;
|
||||
char *file;
|
||||
SHashObj *dnodeHash;
|
||||
SDnodeEps *dnodeEps;
|
||||
pthread_t *threadId;
|
||||
SRWLatch latch;
|
||||
} SDnodeMgmt;
|
||||
|
||||
typedef struct {
|
||||
int32_t refCount;
|
||||
int8_t deployed;
|
||||
int8_t dropped;
|
||||
int8_t replica;
|
||||
int8_t selfIndex;
|
||||
SReplica replicas[TSDB_MAX_REPLICA];
|
||||
char *file;
|
||||
SMnode *pMnode;
|
||||
SRWLatch latch;
|
||||
taos_queue pReadQ;
|
||||
taos_queue pWriteQ;
|
||||
taos_queue pApplyQ;
|
||||
taos_queue pSyncQ;
|
||||
taos_queue pMgmtQ;
|
||||
SWorkerPool mgmtPool;
|
||||
SWorkerPool readPool;
|
||||
SWorkerPool writePool;
|
||||
SWorkerPool syncPool;
|
||||
} SMnodeMgmt;
|
||||
|
||||
typedef struct {
|
||||
SHashObj *hash;
|
||||
int32_t openVnodes;
|
||||
int32_t totalVnodes;
|
||||
SRWLatch latch;
|
||||
taos_queue pMgmtQ;
|
||||
SWorkerPool mgmtPool;
|
||||
SWorkerPool queryPool;
|
||||
SWorkerPool fetchPool;
|
||||
SMWorkerPool syncPool;
|
||||
SMWorkerPool writePool;
|
||||
} SVnodesMgmt;
|
||||
|
||||
typedef struct {
|
||||
void *serverRpc;
|
||||
void *clientRpc;
|
||||
DndMsgFp msgFp[TSDB_MSG_TYPE_MAX];
|
||||
} STransMgmt;
|
||||
|
||||
typedef struct SDnode {
|
||||
EStat stat;
|
||||
SDnodeOpt opt;
|
||||
SDnodeDir dir;
|
||||
SDnodeMgmt dmgmt;
|
||||
SMnodeMgmt mmgmt;
|
||||
SVnodesMgmt vmgmt;
|
||||
STransMgmt tmgmt;
|
||||
SStartupMsg startup;
|
||||
} SDnode;
|
||||
|
||||
EStat dndGetStat(SDnode *pDnode);
|
||||
void dndSetStat(SDnode *pDnode, EStat stat);
|
||||
char *dndStatStr(EStat stat);
|
||||
|
||||
void dndReportStartup(SDnode *pDnode, char *pName, char *pDesc);
|
||||
void dndGetStartup(SDnode *pDnode, SStartupMsg *pStartup);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /*_TD_DND_INT_H_*/
|
|
@ -13,26 +13,24 @@
|
|||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef _TD_DNODE_VNODES_H_
|
||||
#define _TD_DNODE_VNODES_H_
|
||||
#ifndef _TD_DND_MNODE_H_
|
||||
#define _TD_DND_MNODE_H_
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
#include "dnodeInt.h"
|
||||
#include "dndInt.h"
|
||||
|
||||
int32_t dnodeInitVnodes();
|
||||
void dnodeCleanupVnodes();
|
||||
void dnodeGetVnodeLoads(SVnodeLoads *pVloads);
|
||||
|
||||
void dnodeProcessVnodeMgmtMsg(SRpcMsg *pMsg, SEpSet *pEpSet);
|
||||
void dnodeProcessVnodeWriteMsg(SRpcMsg *pMsg, SEpSet *pEpSet);
|
||||
void dnodeProcessVnodeSyncMsg(SRpcMsg *pMsg, SEpSet *pEpSet);
|
||||
void dnodeProcessVnodeQueryMsg(SRpcMsg *pMsg, SEpSet *pEpSet);
|
||||
void dnodeProcessVnodeFetchMsg(SRpcMsg *pMsg, SEpSet *pEpSet);
|
||||
int32_t dndInitMnode(SDnode *pDnode);
|
||||
void dndCleanupMnode(SDnode *pDnode);
|
||||
int32_t dndGetUserAuthFromMnode(SDnode *pDnode, char *user, char *spi, char *encrypt, char *secret, char *ckey);
|
||||
void dndProcessMnodeMgmtMsg(SDnode *pDnode, SRpcMsg *pMsg, SEpSet *pEpSet);
|
||||
void dndProcessMnodeReadMsg(SDnode *pDnode, SRpcMsg *pMsg, SEpSet *pEpSet);
|
||||
void dndProcessMnodeWriteMsg(SDnode *pDnode, SRpcMsg *pMsg, SEpSet *pEpSet);
|
||||
void dndProcessMnodeSyncMsg(SDnode *pDnode, SRpcMsg *pMsg, SEpSet *pEpSet);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /*_TD_DNODE_VNODES_H_*/
|
||||
#endif /*_TD_DND_MNODE_H_*/
|
|
@ -13,21 +13,21 @@
|
|||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef _TD_DNODE_TRANSPORT_H_
|
||||
#define _TD_DNODE_TRANSPORT_H_
|
||||
#ifndef _TD_DND_TRANSPORT_H_
|
||||
#define _TD_DND_TRANSPORT_H_
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
#include "dnodeInt.h"
|
||||
#include "dndInt.h"
|
||||
|
||||
int32_t dnodeInitTrans();
|
||||
void dnodeCleanupTrans();
|
||||
void dnodeSendMsgToMnode(SRpcMsg *rpcMsg);
|
||||
void dnodeSendMsgToDnode(SEpSet *epSet, SRpcMsg *rpcMsg);
|
||||
int32_t dndInitTrans(SDnode *pDnode);
|
||||
void dndCleanupTrans(SDnode *pDnode);
|
||||
void dndSendMsgToMnode(SDnode *pDnode, SRpcMsg *pRpcMsg);
|
||||
void dndSendMsgToDnode(SDnode *pDnode, SEpSet *pEpSet, SRpcMsg *pRpcMsg);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /*_TD_DNODE_TRANSPORT_H_*/
|
||||
#endif /*_TD_DND_TRANSPORT_H_*/
|
|
@ -13,25 +13,25 @@
|
|||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef _TD_DNODE_MNODE_H_
|
||||
#define _TD_DNODE_MNODE_H_
|
||||
#ifndef _TD_DND_VNODES_H_
|
||||
#define _TD_DND_VNODES_H_
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
#include "dnodeInt.h"
|
||||
#include "dndInt.h"
|
||||
|
||||
int32_t dnodeInitMnode();
|
||||
void dnodeCleanupMnode();
|
||||
int32_t dnodeGetUserAuthFromMnode(char *user, char *spi, char *encrypt, char *secret, char *ckey);
|
||||
|
||||
void dnodeProcessMnodeMgmtMsg(SRpcMsg *pMsg, SEpSet *pEpSet);
|
||||
void dnodeProcessMnodeReadMsg(SRpcMsg *pMsg, SEpSet *pEpSet);
|
||||
void dnodeProcessMnodeWriteMsg(SRpcMsg *pMsg, SEpSet *pEpSet);
|
||||
void dnodeProcessMnodeSyncMsg(SRpcMsg *pMsg, SEpSet *pEpSet);
|
||||
int32_t dndInitVnodes(SDnode *pDnode);
|
||||
void dndCleanupVnodes(SDnode *pDnode);
|
||||
void dndGetVnodeLoads(SDnode *pDnode, SVnodeLoads *pVloads);
|
||||
void dndProcessVnodeMgmtMsg(SDnode *pDnode, SRpcMsg *pMsg, SEpSet *pEpSet);
|
||||
void dndProcessVnodeWriteMsg(SDnode *pDnode, SRpcMsg *pMsg, SEpSet *pEpSet);
|
||||
void dndProcessVnodeSyncMsg(SDnode *pDnode, SRpcMsg *pMsg, SEpSet *pEpSet);
|
||||
void dndProcessVnodeQueryMsg(SDnode *pDnode, SRpcMsg *pMsg, SEpSet *pEpSet);
|
||||
void dndProcessVnodeFetchMsg(SDnode *pDnode, SRpcMsg *pMsg, SEpSet *pEpSet);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /*_TD_DNODE_MNODE_H_*/
|
||||
#endif /*_TD_DND_VNODES_H_*/
|
|
@ -0,0 +1,572 @@
|
|||
/*
|
||||
* 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 "dndDnode.h"
|
||||
#include "dndTransport.h"
|
||||
#include "dndVnodes.h"
|
||||
|
||||
int32_t dndGetDnodeId(SDnode *pDnode) {
|
||||
SDnodeMgmt *pMgmt = &pDnode->dmgmt;
|
||||
taosRLockLatch(&pMgmt->latch);
|
||||
int32_t dnodeId = pMgmt->dnodeId;
|
||||
taosRUnLockLatch(&pMgmt->latch);
|
||||
return dnodeId;
|
||||
}
|
||||
|
||||
int64_t dndGetClusterId(SDnode *pDnode) {
|
||||
SDnodeMgmt *pMgmt = &pDnode->dmgmt;
|
||||
taosRLockLatch(&pMgmt->latch);
|
||||
int64_t clusterId = pMgmt->clusterId;
|
||||
taosRUnLockLatch(&pMgmt->latch);
|
||||
return clusterId;
|
||||
}
|
||||
|
||||
void dndGetDnodeEp(SDnode *pDnode, int32_t dnodeId, char *pEp, char *pFqdn, uint16_t *pPort) {
|
||||
SDnodeMgmt *pMgmt = &pDnode->dmgmt;
|
||||
taosRLockLatch(&pMgmt->latch);
|
||||
|
||||
SDnodeEp *pDnodeEp = taosHashGet(pMgmt->dnodeHash, &dnodeId, sizeof(int32_t));
|
||||
if (pDnodeEp != NULL) {
|
||||
if (pPort != NULL) {
|
||||
*pPort = pDnodeEp->port;
|
||||
}
|
||||
if (pFqdn != NULL) {
|
||||
tstrncpy(pFqdn, pDnodeEp->fqdn, TSDB_FQDN_LEN);
|
||||
}
|
||||
if (pEp != NULL) {
|
||||
snprintf(pEp, TSDB_EP_LEN, "%s:%u", pDnodeEp->fqdn, pDnodeEp->port);
|
||||
}
|
||||
}
|
||||
|
||||
taosRUnLockLatch(&pMgmt->latch);
|
||||
}
|
||||
|
||||
void dndGetMnodeEpSet(SDnode *pDnode, SEpSet *pEpSet) {
|
||||
SDnodeMgmt *pMgmt = &pDnode->dmgmt;
|
||||
taosRLockLatch(&pMgmt->latch);
|
||||
*pEpSet = pMgmt->mnodeEpSet;
|
||||
taosRUnLockLatch(&pMgmt->latch);
|
||||
}
|
||||
|
||||
void dndSendRedirectMsg(SDnode *pDnode, SRpcMsg *pMsg) {
|
||||
int32_t msgType = pMsg->msgType;
|
||||
|
||||
SEpSet epSet = {0};
|
||||
dndGetMnodeEpSet(pDnode, &epSet);
|
||||
|
||||
dDebug("RPC %p, msg:%s is redirected, num:%d inUse:%d", pMsg->handle, taosMsg[msgType], epSet.numOfEps, epSet.inUse);
|
||||
for (int32_t i = 0; i < epSet.numOfEps; ++i) {
|
||||
dDebug("mnode index:%d %s:%u", i, epSet.fqdn[i], epSet.port[i]);
|
||||
if (strcmp(epSet.fqdn[i], pDnode->opt.localFqdn) == 0 && epSet.port[i] == pDnode->opt.serverPort) {
|
||||
epSet.inUse = (i + 1) % epSet.numOfEps;
|
||||
}
|
||||
|
||||
epSet.port[i] = htons(epSet.port[i]);
|
||||
}
|
||||
|
||||
rpcSendRedirectRsp(pMsg->handle, &epSet);
|
||||
}
|
||||
|
||||
static void dndUpdateMnodeEpSet(SDnode *pDnode, SEpSet *pEpSet) {
|
||||
dInfo("mnode is changed, num:%d inUse:%d", pEpSet->numOfEps, pEpSet->inUse);
|
||||
|
||||
SDnodeMgmt *pMgmt = &pDnode->dmgmt;
|
||||
taosWLockLatch(&pMgmt->latch);
|
||||
|
||||
pMgmt->mnodeEpSet = *pEpSet;
|
||||
for (int32_t i = 0; i < pEpSet->numOfEps; ++i) {
|
||||
dInfo("mnode index:%d %s:%u", i, pEpSet->fqdn[i], pEpSet->port[i]);
|
||||
}
|
||||
|
||||
taosWUnLockLatch(&pMgmt->latch);
|
||||
}
|
||||
|
||||
static void dndPrintDnodes(SDnode *pDnode) {
|
||||
SDnodeMgmt *pMgmt = &pDnode->dmgmt;
|
||||
|
||||
dDebug("print dnode ep list, num:%d", pMgmt->dnodeEps->num);
|
||||
for (int32_t i = 0; i < pMgmt->dnodeEps->num; i++) {
|
||||
SDnodeEp *pEp = &pMgmt->dnodeEps->eps[i];
|
||||
dDebug("dnode:%d, fqdn:%s port:%u isMnode:%d", pEp->id, pEp->fqdn, pEp->port, pEp->isMnode);
|
||||
}
|
||||
}
|
||||
|
||||
static void dndResetDnodes(SDnode *pDnode, SDnodeEps *pDnodeEps) {
|
||||
SDnodeMgmt *pMgmt = &pDnode->dmgmt;
|
||||
|
||||
int32_t size = sizeof(SDnodeEps) + pDnodeEps->num * sizeof(SDnodeEp);
|
||||
if (pDnodeEps->num > pMgmt->dnodeEps->num) {
|
||||
SDnodeEps *tmp = calloc(1, size);
|
||||
if (tmp == NULL) return;
|
||||
|
||||
tfree(pMgmt->dnodeEps);
|
||||
pMgmt->dnodeEps = tmp;
|
||||
}
|
||||
|
||||
if (pMgmt->dnodeEps != pDnodeEps) {
|
||||
memcpy(pMgmt->dnodeEps, pDnodeEps, size);
|
||||
}
|
||||
|
||||
pMgmt->mnodeEpSet.inUse = 0;
|
||||
pMgmt->mnodeEpSet.numOfEps = 0;
|
||||
|
||||
int32_t mIndex = 0;
|
||||
for (int32_t i = 0; i < pMgmt->dnodeEps->num; i++) {
|
||||
SDnodeEp *pDnodeEp = &pMgmt->dnodeEps->eps[i];
|
||||
if (!pDnodeEp->isMnode) continue;
|
||||
if (mIndex >= TSDB_MAX_REPLICA) continue;
|
||||
pMgmt->mnodeEpSet.numOfEps++;
|
||||
strcpy(pMgmt->mnodeEpSet.fqdn[mIndex], pDnodeEp->fqdn);
|
||||
pMgmt->mnodeEpSet.port[mIndex] = pDnodeEp->port;
|
||||
mIndex++;
|
||||
}
|
||||
|
||||
for (int32_t i = 0; i < pMgmt->dnodeEps->num; ++i) {
|
||||
SDnodeEp *pDnodeEp = &pMgmt->dnodeEps->eps[i];
|
||||
taosHashPut(pMgmt->dnodeHash, &pDnodeEp->id, sizeof(int32_t), pDnodeEp, sizeof(SDnodeEp));
|
||||
}
|
||||
|
||||
dndPrintDnodes(pDnode);
|
||||
}
|
||||
|
||||
static bool dndIsEpChanged(SDnode *pDnode, int32_t dnodeId, char *pEp) {
|
||||
bool changed = false;
|
||||
|
||||
SDnodeMgmt *pMgmt = &pDnode->dmgmt;
|
||||
taosRLockLatch(&pMgmt->latch);
|
||||
|
||||
SDnodeEp *pDnodeEp = taosHashGet(pMgmt->dnodeHash, &dnodeId, sizeof(int32_t));
|
||||
if (pDnodeEp != NULL) {
|
||||
char epstr[TSDB_EP_LEN + 1];
|
||||
snprintf(epstr, TSDB_EP_LEN, "%s:%u", pDnodeEp->fqdn, pDnodeEp->port);
|
||||
changed = strcmp(pEp, epstr) != 0;
|
||||
}
|
||||
|
||||
taosRUnLockLatch(&pMgmt->latch);
|
||||
return changed;
|
||||
}
|
||||
|
||||
static int32_t dndReadDnodes(SDnode *pDnode) {
|
||||
SDnodeMgmt *pMgmt = &pDnode->dmgmt;
|
||||
|
||||
int32_t code = TSDB_CODE_DND_DNODE_READ_FILE_ERROR;
|
||||
int32_t len = 0;
|
||||
int32_t maxLen = 30000;
|
||||
char *content = calloc(1, maxLen + 1);
|
||||
cJSON *root = NULL;
|
||||
FILE *fp = NULL;
|
||||
|
||||
fp = fopen(pMgmt->file, "r");
|
||||
if (fp == NULL) {
|
||||
dDebug("file %s not exist", pMgmt->file);
|
||||
code = 0;
|
||||
goto PRASE_DNODE_OVER;
|
||||
}
|
||||
|
||||
len = (int32_t)fread(content, 1, maxLen, fp);
|
||||
if (len <= 0) {
|
||||
dError("failed to read %s since content is null", pMgmt->file);
|
||||
goto PRASE_DNODE_OVER;
|
||||
}
|
||||
|
||||
content[len] = 0;
|
||||
root = cJSON_Parse(content);
|
||||
if (root == NULL) {
|
||||
dError("failed to read %s since invalid json format", pMgmt->file);
|
||||
goto PRASE_DNODE_OVER;
|
||||
}
|
||||
|
||||
cJSON *dnodeId = cJSON_GetObjectItem(root, "dnodeId");
|
||||
if (!dnodeId || dnodeId->type != cJSON_String) {
|
||||
dError("failed to read %s since dnodeId not found", pMgmt->file);
|
||||
goto PRASE_DNODE_OVER;
|
||||
}
|
||||
pMgmt->dnodeId = atoi(dnodeId->valuestring);
|
||||
|
||||
cJSON *clusterId = cJSON_GetObjectItem(root, "clusterId");
|
||||
if (!clusterId || clusterId->type != cJSON_String) {
|
||||
dError("failed to read %s since clusterId not found", pMgmt->file);
|
||||
goto PRASE_DNODE_OVER;
|
||||
}
|
||||
pMgmt->clusterId = atoll(clusterId->valuestring);
|
||||
|
||||
cJSON *dropped = cJSON_GetObjectItem(root, "dropped");
|
||||
if (!dropped || dropped->type != cJSON_String) {
|
||||
dError("failed to read %s since dropped not found", pMgmt->file);
|
||||
goto PRASE_DNODE_OVER;
|
||||
}
|
||||
pMgmt->dropped = atoi(dropped->valuestring);
|
||||
|
||||
cJSON *dnodeInfos = cJSON_GetObjectItem(root, "dnodeInfos");
|
||||
if (!dnodeInfos || dnodeInfos->type != cJSON_Array) {
|
||||
dError("failed to read %s since dnodeInfos not found", pMgmt->file);
|
||||
goto PRASE_DNODE_OVER;
|
||||
}
|
||||
|
||||
int32_t dnodeInfosSize = cJSON_GetArraySize(dnodeInfos);
|
||||
if (dnodeInfosSize <= 0) {
|
||||
dError("failed to read %s since dnodeInfos size:%d invalid", pMgmt->file, dnodeInfosSize);
|
||||
goto PRASE_DNODE_OVER;
|
||||
}
|
||||
|
||||
pMgmt->dnodeEps = calloc(1, dnodeInfosSize * sizeof(SDnodeEp) + sizeof(SDnodeEps));
|
||||
if (pMgmt->dnodeEps == NULL) {
|
||||
dError("failed to calloc dnodeEpList since %s", strerror(errno));
|
||||
goto PRASE_DNODE_OVER;
|
||||
}
|
||||
pMgmt->dnodeEps->num = dnodeInfosSize;
|
||||
|
||||
for (int32_t i = 0; i < dnodeInfosSize; ++i) {
|
||||
cJSON *dnodeInfo = cJSON_GetArrayItem(dnodeInfos, i);
|
||||
if (dnodeInfo == NULL) break;
|
||||
|
||||
SDnodeEp *pDnodeEp = &pMgmt->dnodeEps->eps[i];
|
||||
|
||||
cJSON *dnodeId = cJSON_GetObjectItem(dnodeInfo, "dnodeId");
|
||||
if (!dnodeId || dnodeId->type != cJSON_String) {
|
||||
dError("failed to read %s, dnodeId not found", pMgmt->file);
|
||||
goto PRASE_DNODE_OVER;
|
||||
}
|
||||
pDnodeEp->id = atoi(dnodeId->valuestring);
|
||||
|
||||
cJSON *isMnode = cJSON_GetObjectItem(dnodeInfo, "isMnode");
|
||||
if (!isMnode || isMnode->type != cJSON_String) {
|
||||
dError("failed to read %s, isMnode not found", pMgmt->file);
|
||||
goto PRASE_DNODE_OVER;
|
||||
}
|
||||
pDnodeEp->isMnode = atoi(isMnode->valuestring);
|
||||
|
||||
cJSON *dnodeFqdn = cJSON_GetObjectItem(dnodeInfo, "dnodeFqdn");
|
||||
if (!dnodeFqdn || dnodeFqdn->type != cJSON_String || dnodeFqdn->valuestring == NULL) {
|
||||
dError("failed to read %s, dnodeFqdn not found", pMgmt->file);
|
||||
goto PRASE_DNODE_OVER;
|
||||
}
|
||||
tstrncpy(pDnodeEp->fqdn, dnodeFqdn->valuestring, TSDB_FQDN_LEN);
|
||||
|
||||
cJSON *dnodePort = cJSON_GetObjectItem(dnodeInfo, "dnodePort");
|
||||
if (!dnodePort || dnodePort->type != cJSON_String) {
|
||||
dError("failed to read %s, dnodePort not found", pMgmt->file);
|
||||
goto PRASE_DNODE_OVER;
|
||||
}
|
||||
pDnodeEp->port = atoi(dnodePort->valuestring);
|
||||
}
|
||||
|
||||
code = 0;
|
||||
dInfo("succcessed to read file %s", pMgmt->file);
|
||||
dndPrintDnodes(pDnode);
|
||||
|
||||
PRASE_DNODE_OVER:
|
||||
if (content != NULL) free(content);
|
||||
if (root != NULL) cJSON_Delete(root);
|
||||
if (fp != NULL) fclose(fp);
|
||||
|
||||
if (dndIsEpChanged(pDnode, pMgmt->dnodeId, pDnode->opt.localEp)) {
|
||||
dError("localEp %s different with %s and need reconfigured", pDnode->opt.localEp, pMgmt->file);
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (pMgmt->dnodeEps == NULL) {
|
||||
pMgmt->dnodeEps = calloc(1, sizeof(SDnodeEps) + sizeof(SDnodeEp));
|
||||
pMgmt->dnodeEps->num = 1;
|
||||
pMgmt->dnodeEps->eps[0].isMnode = 1;
|
||||
pMgmt->dnodeEps->eps[0].port = pDnode->opt.serverPort;
|
||||
tstrncpy(pMgmt->dnodeEps->eps[0].fqdn, pDnode->opt.localFqdn, TSDB_FQDN_LEN);
|
||||
}
|
||||
|
||||
dndResetDnodes(pDnode, pMgmt->dnodeEps);
|
||||
|
||||
terrno = 0;
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int32_t dndWriteDnodes(SDnode *pDnode) {
|
||||
SDnodeMgmt *pMgmt = &pDnode->dmgmt;
|
||||
|
||||
FILE *fp = fopen(pMgmt->file, "w");
|
||||
if (fp == NULL) {
|
||||
dError("failed to write %s since %s", pMgmt->file, strerror(errno));
|
||||
terrno = TAOS_SYSTEM_ERROR(errno);
|
||||
return -1;
|
||||
}
|
||||
|
||||
int32_t len = 0;
|
||||
int32_t maxLen = 30000;
|
||||
char *content = calloc(1, maxLen + 1);
|
||||
|
||||
len += snprintf(content + len, maxLen - len, "{\n");
|
||||
len += snprintf(content + len, maxLen - len, " \"dnodeId\": \"%d\",\n", pMgmt->dnodeId);
|
||||
len += snprintf(content + len, maxLen - len, " \"clusterId\": \"%" PRId64 "\",\n", pMgmt->clusterId);
|
||||
len += snprintf(content + len, maxLen - len, " \"dropped\": \"%d\",\n", pMgmt->dropped);
|
||||
len += snprintf(content + len, maxLen - len, " \"dnodeInfos\": [{\n");
|
||||
for (int32_t i = 0; i < pMgmt->dnodeEps->num; ++i) {
|
||||
SDnodeEp *pDnodeEp = &pMgmt->dnodeEps->eps[i];
|
||||
len += snprintf(content + len, maxLen - len, " \"dnodeId\": \"%d\",\n", pDnodeEp->id);
|
||||
len += snprintf(content + len, maxLen - len, " \"isMnode\": \"%d\",\n", pDnodeEp->isMnode);
|
||||
len += snprintf(content + len, maxLen - len, " \"dnodeFqdn\": \"%s\",\n", pDnodeEp->fqdn);
|
||||
len += snprintf(content + len, maxLen - len, " \"dnodePort\": \"%u\"\n", pDnodeEp->port);
|
||||
if (i < pMgmt->dnodeEps->num - 1) {
|
||||
len += snprintf(content + len, maxLen - len, " },{\n");
|
||||
} else {
|
||||
len += snprintf(content + len, maxLen - len, " }]\n");
|
||||
}
|
||||
}
|
||||
len += snprintf(content + len, maxLen - len, "}\n");
|
||||
|
||||
fwrite(content, 1, len, fp);
|
||||
taosFsyncFile(fileno(fp));
|
||||
fclose(fp);
|
||||
free(content);
|
||||
terrno = 0;
|
||||
|
||||
dInfo("successed to write %s", pMgmt->file);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void dndSendStatusMsg(SDnode *pDnode) {
|
||||
int32_t contLen = sizeof(SStatusMsg) + TSDB_MAX_VNODES * sizeof(SVnodeLoad);
|
||||
|
||||
SStatusMsg *pStatus = rpcMallocCont(contLen);
|
||||
if (pStatus == NULL) {
|
||||
dError("failed to malloc status message");
|
||||
return;
|
||||
}
|
||||
|
||||
bool changed = false;
|
||||
|
||||
SDnodeMgmt *pMgmt = &pDnode->dmgmt;
|
||||
taosRLockLatch(&pMgmt->latch);
|
||||
pStatus->sversion = htonl(pDnode->opt.sver);
|
||||
pStatus->dnodeId = htonl(pMgmt->dnodeId);
|
||||
pStatus->clusterId = htobe64(pMgmt->clusterId);
|
||||
pStatus->rebootTime = htonl(pMgmt->rebootTime);
|
||||
pStatus->numOfCores = htonl(pDnode->opt.numOfCores);
|
||||
tstrncpy(pStatus->dnodeEp, pDnode->opt.localEp, TSDB_EP_LEN);
|
||||
pStatus->clusterCfg.statusInterval = htonl(pDnode->opt.statusInterval);
|
||||
tstrncpy(pStatus->clusterCfg.timezone, pDnode->opt.timezone, TSDB_TIMEZONE_LEN);
|
||||
tstrncpy(pStatus->clusterCfg.locale, pDnode->opt.locale, TSDB_LOCALE_LEN);
|
||||
tstrncpy(pStatus->clusterCfg.charset, pDnode->opt.charset, TSDB_LOCALE_LEN);
|
||||
pStatus->clusterCfg.checkTime = 0;
|
||||
char timestr[32] = "1970-01-01 00:00:00.00";
|
||||
(void)taosParseTime(timestr, &pStatus->clusterCfg.checkTime, (int32_t)strlen(timestr), TSDB_TIME_PRECISION_MILLI, 0);
|
||||
taosRUnLockLatch(&pMgmt->latch);
|
||||
|
||||
dndGetVnodeLoads(pDnode, &pStatus->vnodeLoads);
|
||||
contLen = sizeof(SStatusMsg) + pStatus->vnodeLoads.num * sizeof(SVnodeLoad);
|
||||
|
||||
SRpcMsg rpcMsg = {.pCont = pStatus, .contLen = contLen, .msgType = TSDB_MSG_TYPE_STATUS};
|
||||
dndSendMsgToMnode(pDnode, &rpcMsg);
|
||||
}
|
||||
|
||||
static void dndUpdateDnodeCfg(SDnode *pDnode, SDnodeCfg *pCfg) {
|
||||
SDnodeMgmt *pMgmt = &pDnode->dmgmt;
|
||||
if (pMgmt->dnodeId == 0 || pMgmt->dropped != pCfg->dropped) {
|
||||
dInfo("set dnodeId:%d clusterId:%" PRId64 " dropped:%d", pCfg->dnodeId, pCfg->clusterId, pCfg->dropped);
|
||||
|
||||
taosWLockLatch(&pMgmt->latch);
|
||||
pMgmt->dnodeId = pCfg->dnodeId;
|
||||
pMgmt->clusterId = pCfg->clusterId;
|
||||
pMgmt->dropped = pCfg->dropped;
|
||||
(void)dndWriteDnodes(pDnode);
|
||||
taosWUnLockLatch(&pMgmt->latch);
|
||||
}
|
||||
}
|
||||
|
||||
static void dndUpdateDnodeEps(SDnode *pDnode, SDnodeEps *pDnodeEps) {
|
||||
if (pDnodeEps == NULL || pDnodeEps->num <= 0) return;
|
||||
|
||||
SDnodeMgmt *pMgmt = &pDnode->dmgmt;
|
||||
taosWLockLatch(&pMgmt->latch);
|
||||
|
||||
if (pDnodeEps->num != pMgmt->dnodeEps->num) {
|
||||
dndResetDnodes(pDnode, pDnodeEps);
|
||||
dndWriteDnodes(pDnode);
|
||||
} else {
|
||||
int32_t size = pDnodeEps->num * sizeof(SDnodeEp) + sizeof(SDnodeEps);
|
||||
if (memcmp(pMgmt->dnodeEps, pDnodeEps, size) != 0) {
|
||||
dndResetDnodes(pDnode, pDnodeEps);
|
||||
dndWriteDnodes(pDnode);
|
||||
}
|
||||
}
|
||||
|
||||
taosWUnLockLatch(&pMgmt->latch);
|
||||
}
|
||||
|
||||
static void dndProcessStatusRsp(SDnode *pDnode, SRpcMsg *pMsg, SEpSet *pEpSet) {
|
||||
if (pEpSet && pEpSet->numOfEps > 0) {
|
||||
dndUpdateMnodeEpSet(pDnode, pEpSet);
|
||||
}
|
||||
|
||||
if (pMsg->code != TSDB_CODE_SUCCESS) return;
|
||||
|
||||
SStatusRsp *pRsp = pMsg->pCont;
|
||||
SDnodeCfg *pCfg = &pRsp->dnodeCfg;
|
||||
pCfg->dnodeId = htonl(pCfg->dnodeId);
|
||||
pCfg->clusterId = htobe64(pCfg->clusterId);
|
||||
dndUpdateDnodeCfg(pDnode, pCfg);
|
||||
|
||||
if (pCfg->dropped) return;
|
||||
|
||||
SDnodeEps *pDnodeEps = &pRsp->dnodeEps;
|
||||
pDnodeEps->num = htonl(pDnodeEps->num);
|
||||
for (int32_t i = 0; i < pDnodeEps->num; ++i) {
|
||||
pDnodeEps->eps[i].id = htonl(pDnodeEps->eps[i].id);
|
||||
pDnodeEps->eps[i].port = htons(pDnodeEps->eps[i].port);
|
||||
}
|
||||
|
||||
dndUpdateDnodeEps(pDnode, pDnodeEps);
|
||||
}
|
||||
|
||||
static void dndProcessAuthRsp(SDnode *pDnode, SRpcMsg *pMsg, SEpSet *pEpSet) { assert(1); }
|
||||
|
||||
static void dndProcessGrantRsp(SDnode *pDnode, SRpcMsg *pMsg, SEpSet *pEpSet) { assert(1); }
|
||||
|
||||
static void dndProcessConfigDnodeReq(SDnode *pDnode, SRpcMsg *pMsg) {
|
||||
SCfgDnodeMsg *pCfg = pMsg->pCont;
|
||||
|
||||
int32_t code = TSDB_CODE_OPS_NOT_SUPPORT;
|
||||
SRpcMsg rspMsg = {.handle = pMsg->handle, .pCont = NULL, .contLen = 0, .code = code};
|
||||
rpcSendResponse(&rspMsg);
|
||||
rpcFreeCont(pMsg->pCont);
|
||||
}
|
||||
|
||||
static void dndProcessStartupReq(SDnode *pDnode, SRpcMsg *pMsg) {
|
||||
dInfo("startup msg is received");
|
||||
|
||||
SStartupMsg *pStartup = rpcMallocCont(sizeof(SStartupMsg));
|
||||
dndGetStartup(pDnode, pStartup);
|
||||
|
||||
dInfo("startup msg is sent, step:%s desc:%s finished:%d", pStartup->name, pStartup->desc, pStartup->finished);
|
||||
|
||||
SRpcMsg rpcRsp = {.handle = pMsg->handle, .pCont = pStartup, .contLen = sizeof(SStartupMsg)};
|
||||
rpcSendResponse(&rpcRsp);
|
||||
rpcFreeCont(pMsg->pCont);
|
||||
}
|
||||
|
||||
static void *dnodeThreadRoutine(void *param) {
|
||||
SDnode *pDnode = param;
|
||||
int32_t ms = pDnode->opt.statusInterval * 1000;
|
||||
|
||||
while (true) {
|
||||
taosMsleep(ms);
|
||||
pthread_testcancel();
|
||||
|
||||
if (dndGetStat(pDnode) == DND_STAT_RUNNING) {
|
||||
// dndSendStatusMsg(pDnode);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int32_t dndInitDnode(SDnode *pDnode) {
|
||||
SDnodeMgmt *pMgmt = &pDnode->dmgmt;
|
||||
|
||||
pMgmt->dnodeId = 0;
|
||||
pMgmt->rebootTime = taosGetTimestampSec();
|
||||
pMgmt->dropped = 0;
|
||||
pMgmt->clusterId = 0;
|
||||
|
||||
char path[PATH_MAX];
|
||||
snprintf(path, PATH_MAX, "%s/dnode.json", pDnode->dir.dnode);
|
||||
pMgmt->file = strdup(path);
|
||||
if (pMgmt->file == NULL) {
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
return -1;
|
||||
}
|
||||
|
||||
pMgmt->dnodeHash = taosHashInit(4, taosGetDefaultHashFunction(TSDB_DATA_TYPE_INT), true, HASH_NO_LOCK);
|
||||
if (pMgmt->dnodeHash == NULL) {
|
||||
dError("failed to init dnode hash");
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (dndReadDnodes(pDnode) != 0) {
|
||||
dError("failed to read file:%s since %s", pMgmt->file, terrstr());
|
||||
return -1;
|
||||
}
|
||||
|
||||
taosInitRWLatch(&pMgmt->latch);
|
||||
|
||||
pMgmt->threadId = taosCreateThread(dnodeThreadRoutine, pDnode);
|
||||
if (pMgmt->threadId == NULL) {
|
||||
dError("failed to init dnode thread");
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
return -1;
|
||||
}
|
||||
|
||||
dInfo("dnode-dnode is initialized");
|
||||
return 0;
|
||||
}
|
||||
|
||||
void dndCleanupDnode(SDnode *pDnode) {
|
||||
SDnodeMgmt *pMgmt = &pDnode->dmgmt;
|
||||
|
||||
if (pMgmt->threadId != NULL) {
|
||||
taosDestoryThread(pMgmt->threadId);
|
||||
pMgmt->threadId = NULL;
|
||||
}
|
||||
|
||||
taosWLockLatch(&pMgmt->latch);
|
||||
|
||||
if (pMgmt->dnodeEps != NULL) {
|
||||
free(pMgmt->dnodeEps);
|
||||
pMgmt->dnodeEps = NULL;
|
||||
}
|
||||
|
||||
if (pMgmt->dnodeHash != NULL) {
|
||||
taosHashCleanup(pMgmt->dnodeHash);
|
||||
pMgmt->dnodeHash = NULL;
|
||||
}
|
||||
|
||||
if (pMgmt->file != NULL) {
|
||||
free(pMgmt->file);
|
||||
pMgmt->file = NULL;
|
||||
}
|
||||
|
||||
taosWUnLockLatch(&pMgmt->latch);
|
||||
dInfo("dnode-dnode is cleaned up");
|
||||
}
|
||||
|
||||
void dndProcessDnodeReq(SDnode *pDnode, SRpcMsg *pMsg, SEpSet *pEpSet) {
|
||||
switch (pMsg->msgType) {
|
||||
case TSDB_MSG_TYPE_NETWORK_TEST:
|
||||
dndProcessStartupReq(pDnode, pMsg);
|
||||
break;
|
||||
case TSDB_MSG_TYPE_CONFIG_DNODE_IN:
|
||||
dndProcessConfigDnodeReq(pDnode, pMsg);
|
||||
break;
|
||||
default:
|
||||
dError("RPC %p, dnode req:%s not processed", pMsg->handle, taosMsg[pMsg->msgType]);
|
||||
SRpcMsg rspMsg = {.handle = pMsg->handle, .code = TSDB_CODE_MSG_NOT_PROCESSED};
|
||||
rpcSendResponse(&rspMsg);
|
||||
rpcFreeCont(pMsg->pCont);
|
||||
}
|
||||
}
|
||||
|
||||
void dndProcessDnodeRsp(SDnode *pDnode, SRpcMsg *pMsg, SEpSet *pEpSet) {
|
||||
switch (pMsg->msgType) {
|
||||
case TSDB_MSG_TYPE_STATUS_RSP:
|
||||
dndProcessStatusRsp(pDnode, pMsg, pEpSet);
|
||||
break;
|
||||
case TSDB_MSG_TYPE_AUTH_RSP:
|
||||
dndProcessAuthRsp(pDnode, pMsg, pEpSet);
|
||||
break;
|
||||
case TSDB_MSG_TYPE_GRANT_RSP:
|
||||
dndProcessGrantRsp(pDnode, pMsg, pEpSet);
|
||||
break;
|
||||
default:
|
||||
dError("RPC %p, dnode rsp:%s not processed", pMsg->handle, taosMsg[pMsg->msgType]);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,927 @@
|
|||
/*
|
||||
* 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 "dndMnode.h"
|
||||
#include "dndDnode.h"
|
||||
#include "dndTransport.h"
|
||||
|
||||
static int32_t dndInitMnodeReadWorker(SDnode *pDnode);
|
||||
static int32_t dndInitMnodeWriteWorker(SDnode *pDnode);
|
||||
static int32_t dndInitMnodeSyncWorker(SDnode *pDnode);
|
||||
static int32_t dndInitMnodeMgmtWorker(SDnode *pDnode);
|
||||
static void dndCleanupMnodeReadWorker(SDnode *pDnode);
|
||||
static void dndCleanupMnodeWriteWorker(SDnode *pDnode);
|
||||
static void dndCleanupMnodeSyncWorker(SDnode *pDnode);
|
||||
static void dndCleanupMnodeMgmtWorker(SDnode *pDnode);
|
||||
static int32_t dndAllocMnodeReadQueue(SDnode *pDnode);
|
||||
static int32_t dndAllocMnodeWriteQueue(SDnode *pDnode);
|
||||
static int32_t dndAllocMnodeApplyQueue(SDnode *pDnode);
|
||||
static int32_t dndAllocMnodeSyncQueue(SDnode *pDnode);
|
||||
static int32_t dndAllocMnodeMgmtQueue(SDnode *pDnode);
|
||||
static void dndFreeMnodeReadQueue(SDnode *pDnode);
|
||||
static void dndFreeMnodeWriteQueue(SDnode *pDnode);
|
||||
static void dndFreeMnodeApplyQueue(SDnode *pDnode);
|
||||
static void dndFreeMnodeSyncQueue(SDnode *pDnode);
|
||||
static void dndFreeMnodeMgmtQueue(SDnode *pDnode);
|
||||
|
||||
static void dndProcessMnodeReadQueue(SDnode *pDnode, SMnodeMsg *pMsg);
|
||||
static void dndProcessMnodeWriteQueue(SDnode *pDnode, SMnodeMsg *pMsg);
|
||||
static void dndProcessMnodeApplyQueue(SDnode *pDnode, SMnodeMsg *pMsg);
|
||||
static void dndProcessMnodeSyncQueue(SDnode *pDnode, SMnodeMsg *pMsg);
|
||||
static void dndProcessMnodeMgmtQueue(SDnode *pDnode, SRpcMsg *pMsg);
|
||||
static int32_t dndWriteMnodeMsgToQueue(SMnode *pMnode, taos_queue pQueue, SRpcMsg *pRpcMsg);
|
||||
void dndProcessMnodeReadMsg(SDnode *pDnode, SRpcMsg *pMsg, SEpSet *pEpSet);
|
||||
void dndProcessMnodeWriteMsg(SDnode *pDnode, SRpcMsg *pMsg, SEpSet *pEpSet);
|
||||
void dndProcessMnodeSyncMsg(SDnode *pDnode, SRpcMsg *pMsg, SEpSet *pEpSet);
|
||||
void dndProcessMnodeMgmtMsg(SDnode *pDnode, SRpcMsg *pMsg, SEpSet *pEpSet);
|
||||
static int32_t dndPutMsgIntoMnodeApplyQueue(SDnode *pDnode, SMnodeMsg *pMsg);
|
||||
|
||||
static int32_t dndStartMnodeWorker(SDnode *pDnode);
|
||||
static void dndStopMnodeWorker(SDnode *pDnode);
|
||||
|
||||
static SMnode *dndAcquireMnode(SDnode *pDnode);
|
||||
static void dndReleaseMnode(SDnode *pDnode, SMnode *pMnode);
|
||||
|
||||
static int32_t dndReadMnodeFile(SDnode *pDnode);
|
||||
static int32_t dndWriteMnodeFile(SDnode *pDnode);
|
||||
|
||||
static int32_t dndOpenMnode(SDnode *pDnode, SMnodeOpt *pOption);
|
||||
static int32_t dndAlterMnode(SDnode *pDnode, SMnodeOpt *pOption);
|
||||
static int32_t dndDropMnode(SDnode *pDnode);
|
||||
|
||||
static int32_t dndProcessCreateMnodeReq(SDnode *pDnode, SRpcMsg *pRpcMsg);
|
||||
static int32_t dndProcessAlterMnodeReq(SDnode *pDnode, SRpcMsg *pRpcMsg);
|
||||
static int32_t dndProcessDropMnodeReq(SDnode *pDnode, SRpcMsg *pRpcMsg);
|
||||
|
||||
static SMnode *dndAcquireMnode(SDnode *pDnode) {
|
||||
SMnodeMgmt *pMgmt = &pDnode->mmgmt;
|
||||
SMnode *pMnode = NULL;
|
||||
int32_t refCount = 0;
|
||||
|
||||
taosRLockLatch(&pMgmt->latch);
|
||||
if (pMgmt->deployed && !pMgmt->dropped) {
|
||||
refCount = atomic_add_fetch_32(&pMgmt->refCount, 1);
|
||||
pMnode = pMgmt->pMnode;
|
||||
} else {
|
||||
terrno = TSDB_CODE_DND_MNODE_NOT_DEPLOYED;
|
||||
}
|
||||
taosRUnLockLatch(&pMgmt->latch);
|
||||
|
||||
if (pMnode != NULL) {
|
||||
dTrace("acquire mnode, refCount:%d", refCount);
|
||||
}
|
||||
return pMnode;
|
||||
}
|
||||
|
||||
static void dndReleaseMnode(SDnode *pDnode, SMnode *pMnode) {
|
||||
SMnodeMgmt *pMgmt = &pDnode->mmgmt;
|
||||
int32_t refCount = 0;
|
||||
|
||||
taosRLockLatch(&pMgmt->latch);
|
||||
if (pMnode != NULL) {
|
||||
refCount = atomic_sub_fetch_32(&pMgmt->refCount, 1);
|
||||
}
|
||||
taosRUnLockLatch(&pMgmt->latch);
|
||||
|
||||
if (pMnode != NULL) {
|
||||
dTrace("release mnode, refCount:%d", refCount);
|
||||
}
|
||||
}
|
||||
|
||||
static int32_t dndReadMnodeFile(SDnode *pDnode) {
|
||||
SMnodeMgmt *pMgmt = &pDnode->mmgmt;
|
||||
int32_t code = TSDB_CODE_DND_MNODE_READ_FILE_ERROR;
|
||||
int32_t len = 0;
|
||||
int32_t maxLen = 4096;
|
||||
char *content = calloc(1, maxLen + 1);
|
||||
cJSON *root = NULL;
|
||||
|
||||
FILE *fp = fopen(pMgmt->file, "r");
|
||||
if (fp == NULL) {
|
||||
dDebug("file %s not exist", pMgmt->file);
|
||||
code = 0;
|
||||
goto PRASE_MNODE_OVER;
|
||||
}
|
||||
|
||||
len = (int32_t)fread(content, 1, maxLen, fp);
|
||||
if (len <= 0) {
|
||||
dError("failed to read %s since content is null", pMgmt->file);
|
||||
goto PRASE_MNODE_OVER;
|
||||
}
|
||||
|
||||
content[len] = 0;
|
||||
root = cJSON_Parse(content);
|
||||
if (root == NULL) {
|
||||
dError("failed to read %s since invalid json format", pMgmt->file);
|
||||
goto PRASE_MNODE_OVER;
|
||||
}
|
||||
|
||||
cJSON *deployed = cJSON_GetObjectItem(root, "deployed");
|
||||
if (!deployed || deployed->type != cJSON_String) {
|
||||
dError("failed to read %s since deployed not found", pMgmt->file);
|
||||
goto PRASE_MNODE_OVER;
|
||||
}
|
||||
pMgmt->deployed = atoi(deployed->valuestring);
|
||||
|
||||
cJSON *dropped = cJSON_GetObjectItem(root, "dropped");
|
||||
if (!dropped || dropped->type != cJSON_String) {
|
||||
dError("failed to read %s since dropped not found", pMgmt->file);
|
||||
goto PRASE_MNODE_OVER;
|
||||
}
|
||||
pMgmt->dropped = atoi(dropped->valuestring);
|
||||
|
||||
cJSON *nodes = cJSON_GetObjectItem(root, "nodes");
|
||||
if (!nodes || nodes->type != cJSON_Array) {
|
||||
dError("failed to read %s since nodes not found", pMgmt->file);
|
||||
goto PRASE_MNODE_OVER;
|
||||
}
|
||||
|
||||
pMgmt->replica = cJSON_GetArraySize(nodes);
|
||||
if (pMgmt->replica <= 0 || pMgmt->replica > TSDB_MAX_REPLICA) {
|
||||
dError("failed to read %s since nodes size %d invalid", pMgmt->file, pMgmt->replica);
|
||||
goto PRASE_MNODE_OVER;
|
||||
}
|
||||
|
||||
for (int32_t i = 0; i < pMgmt->replica; ++i) {
|
||||
cJSON *node = cJSON_GetArrayItem(nodes, i);
|
||||
if (node == NULL) break;
|
||||
|
||||
SReplica *pReplica = &pMgmt->replicas[i];
|
||||
|
||||
cJSON *id = cJSON_GetObjectItem(node, "id");
|
||||
if (!id || id->type != cJSON_String || id->valuestring == NULL) {
|
||||
dError("failed to read %s since id not found", pMgmt->file);
|
||||
goto PRASE_MNODE_OVER;
|
||||
}
|
||||
pReplica->id = atoi(id->valuestring);
|
||||
|
||||
cJSON *fqdn = cJSON_GetObjectItem(node, "fqdn");
|
||||
if (!fqdn || fqdn->type != cJSON_String || fqdn->valuestring == NULL) {
|
||||
dError("failed to read %s since fqdn not found", pMgmt->file);
|
||||
goto PRASE_MNODE_OVER;
|
||||
}
|
||||
tstrncpy(pReplica->fqdn, fqdn->valuestring, TSDB_FQDN_LEN);
|
||||
|
||||
cJSON *port = cJSON_GetObjectItem(node, "port");
|
||||
if (!port || port->type != cJSON_String || port->valuestring == NULL) {
|
||||
dError("failed to read %s since port not found", pMgmt->file);
|
||||
goto PRASE_MNODE_OVER;
|
||||
}
|
||||
pReplica->port = atoi(port->valuestring);
|
||||
}
|
||||
|
||||
code = 0;
|
||||
dInfo("succcessed to read file %s", pMgmt->file);
|
||||
|
||||
PRASE_MNODE_OVER:
|
||||
if (content != NULL) free(content);
|
||||
if (root != NULL) cJSON_Delete(root);
|
||||
if (fp != NULL) fclose(fp);
|
||||
|
||||
terrno = code;
|
||||
return code;
|
||||
}
|
||||
|
||||
static int32_t dndWriteMnodeFile(SDnode *pDnode) {
|
||||
SMnodeMgmt *pMgmt = &pDnode->mmgmt;
|
||||
|
||||
char file[PATH_MAX + 20] = {0};
|
||||
snprintf(file, sizeof(file), "%s.bak", pMgmt->file);
|
||||
|
||||
FILE *fp = fopen(file, "w");
|
||||
if (fp == NULL) {
|
||||
terrno = TSDB_CODE_DND_MNODE_WRITE_FILE_ERROR;
|
||||
dError("failed to write %s since %s", file, terrstr());
|
||||
return -1;
|
||||
}
|
||||
|
||||
int32_t len = 0;
|
||||
int32_t maxLen = 4096;
|
||||
char *content = calloc(1, maxLen + 1);
|
||||
|
||||
len += snprintf(content + len, maxLen - len, "{\n");
|
||||
len += snprintf(content + len, maxLen - len, " \"deployed\": \"%d\",\n", pMgmt->deployed);
|
||||
|
||||
len += snprintf(content + len, maxLen - len, " \"dropped\": \"%d\",\n", pMgmt->dropped);
|
||||
len += snprintf(content + len, maxLen - len, " \"nodes\": [{\n");
|
||||
for (int32_t i = 0; i < pMgmt->replica; ++i) {
|
||||
SReplica *pReplica = &pMgmt->replicas[i];
|
||||
len += snprintf(content + len, maxLen - len, " \"id\": \"%d\",\n", pReplica->id);
|
||||
len += snprintf(content + len, maxLen - len, " \"fqdn\": \"%s\",\n", pReplica->fqdn);
|
||||
len += snprintf(content + len, maxLen - len, " \"port\": \"%u\"\n", pReplica->port);
|
||||
if (i < pMgmt->replica - 1) {
|
||||
len += snprintf(content + len, maxLen - len, " },{\n");
|
||||
} else {
|
||||
len += snprintf(content + len, maxLen - len, " }]\n");
|
||||
}
|
||||
}
|
||||
len += snprintf(content + len, maxLen - len, "}\n");
|
||||
|
||||
fwrite(content, 1, len, fp);
|
||||
taosFsyncFile(fileno(fp));
|
||||
fclose(fp);
|
||||
free(content);
|
||||
|
||||
if (taosRenameFile(file, pMgmt->file) != 0) {
|
||||
terrno = TSDB_CODE_DND_MNODE_WRITE_FILE_ERROR;
|
||||
dError("failed to rename %s since %s", pMgmt->file, terrstr());
|
||||
return -1;
|
||||
}
|
||||
|
||||
dInfo("successed to write %s", pMgmt->file);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int32_t dndStartMnodeWorker(SDnode *pDnode) {
|
||||
if (dndInitMnodeReadWorker(pDnode) != 0) {
|
||||
dError("failed to start mnode read worker since %s", terrstr());
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (dndInitMnodeWriteWorker(pDnode) != 0) {
|
||||
dError("failed to start mnode write worker since %s", terrstr());
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (dndInitMnodeSyncWorker(pDnode) != 0) {
|
||||
dError("failed to start mnode sync worker since %s", terrstr());
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (dndAllocMnodeReadQueue(pDnode) != 0) {
|
||||
dError("failed to alloc mnode read queue since %s", terrstr());
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (dndAllocMnodeWriteQueue(pDnode) != 0) {
|
||||
dError("failed to alloc mnode write queue since %s", terrstr());
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (dndAllocMnodeApplyQueue(pDnode) != 0) {
|
||||
dError("failed to alloc mnode apply queue since %s", terrstr());
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (dndAllocMnodeSyncQueue(pDnode) != 0) {
|
||||
dError("failed to alloc mnode sync queue since %s", terrstr());
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void dndStopMnodeWorker(SDnode *pDnode) {
|
||||
SMnodeMgmt *pMgmt = &pDnode->mmgmt;
|
||||
|
||||
taosWLockLatch(&pMgmt->latch);
|
||||
pMgmt->deployed = 0;
|
||||
pMgmt->pMnode = NULL;
|
||||
taosWUnLockLatch(&pMgmt->latch);
|
||||
|
||||
while (pMgmt->refCount > 1) taosMsleep(10);
|
||||
while (!taosQueueEmpty(pMgmt->pReadQ)) taosMsleep(10);
|
||||
while (!taosQueueEmpty(pMgmt->pApplyQ)) taosMsleep(10);
|
||||
while (!taosQueueEmpty(pMgmt->pWriteQ)) taosMsleep(10);
|
||||
while (!taosQueueEmpty(pMgmt->pSyncQ)) taosMsleep(10);
|
||||
|
||||
dndCleanupMnodeReadWorker(pDnode);
|
||||
dndCleanupMnodeWriteWorker(pDnode);
|
||||
dndCleanupMnodeSyncWorker(pDnode);
|
||||
|
||||
dndFreeMnodeReadQueue(pDnode);
|
||||
dndFreeMnodeWriteQueue(pDnode);
|
||||
dndFreeMnodeApplyQueue(pDnode);
|
||||
dndFreeMnodeSyncQueue(pDnode);
|
||||
}
|
||||
|
||||
static bool dndNeedDeployMnode(SDnode *pDnode) {
|
||||
if (dndGetDnodeId(pDnode) > 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (dndGetClusterId(pDnode) > 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (strcmp(pDnode->opt.localEp, pDnode->opt.firstEp) != 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
static void dndInitMnodeOption(SDnode *pDnode, SMnodeOpt *pOption) {
|
||||
pOption->pDnode = pDnode;
|
||||
pOption->sendMsgToDnodeFp = dndSendMsgToDnode;
|
||||
pOption->sendMsgToMnodeFp = dndSendMsgToMnode;
|
||||
pOption->sendRedirectMsgFp = dndSendRedirectMsg;
|
||||
pOption->putMsgToApplyMsgFp = dndPutMsgIntoMnodeApplyQueue;
|
||||
pOption->dnodeId = dndGetDnodeId(pDnode);
|
||||
pOption->clusterId = dndGetClusterId(pDnode);
|
||||
}
|
||||
|
||||
static void dndBuildMnodeDeployOption(SDnode *pDnode, SMnodeOpt *pOption) {
|
||||
dndInitMnodeOption(pDnode, pOption);
|
||||
pOption->replica = 1;
|
||||
pOption->selfIndex = 0;
|
||||
SReplica *pReplica = &pOption->replicas[0];
|
||||
pReplica->id = 1;
|
||||
pReplica->port = pDnode->opt.serverPort;
|
||||
tstrncpy(pReplica->fqdn, pDnode->opt.localFqdn, TSDB_FQDN_LEN);
|
||||
|
||||
SMnodeMgmt *pMgmt = &pDnode->mmgmt;
|
||||
pMgmt->selfIndex = pOption->selfIndex;
|
||||
pMgmt->replica = pOption->replica;
|
||||
memcpy(&pMgmt->replicas, pOption->replicas, sizeof(SReplica) * TSDB_MAX_REPLICA);
|
||||
}
|
||||
|
||||
static void dndBuildMnodeOpenOption(SDnode *pDnode, SMnodeOpt *pOption) {
|
||||
dndInitMnodeOption(pDnode, pOption);
|
||||
SMnodeMgmt *pMgmt = &pDnode->mmgmt;
|
||||
pOption->selfIndex = pMgmt->selfIndex;
|
||||
pOption->replica = pMgmt->replica;
|
||||
memcpy(&pOption->replicas, pMgmt->replicas, sizeof(SReplica) * TSDB_MAX_REPLICA);
|
||||
}
|
||||
|
||||
static int32_t dndBuildMnodeOptionFromMsg(SDnode *pDnode, SMnodeOpt *pOption, SCreateMnodeMsg *pMsg) {
|
||||
dndInitMnodeOption(pDnode, pOption);
|
||||
pOption->dnodeId = dndGetDnodeId(pDnode);
|
||||
pOption->clusterId = dndGetClusterId(pDnode);
|
||||
|
||||
pOption->replica = pMsg->replica;
|
||||
pOption->selfIndex = -1;
|
||||
for (int32_t i = 0; i < pMsg->replica; ++i) {
|
||||
SReplica *pReplica = &pOption->replicas[i];
|
||||
pReplica->id = pMsg->replicas[i].id;
|
||||
pReplica->port = pMsg->replicas[i].port;
|
||||
tstrncpy(pReplica->fqdn, pMsg->replicas[i].fqdn, TSDB_FQDN_LEN);
|
||||
if (pReplica->id == pOption->dnodeId) {
|
||||
pOption->selfIndex = i;
|
||||
}
|
||||
}
|
||||
|
||||
if (pOption->selfIndex == -1) {
|
||||
terrno = TSDB_CODE_DND_MNODE_ID_NOT_FOUND;
|
||||
dError("failed to build mnode options since %s", terrstr());
|
||||
return -1;
|
||||
}
|
||||
|
||||
SMnodeMgmt *pMgmt = &pDnode->mmgmt;
|
||||
pMgmt->selfIndex = pOption->selfIndex;
|
||||
pMgmt->replica = pOption->replica;
|
||||
memcpy(&pMgmt->replicas, pOption->replicas, sizeof(SReplica) * TSDB_MAX_REPLICA);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int32_t dndOpenMnode(SDnode *pDnode, SMnodeOpt *pOption) {
|
||||
SMnodeMgmt *pMgmt = &pDnode->mmgmt;
|
||||
|
||||
int32_t code = dndStartMnodeWorker(pDnode);
|
||||
if (code != 0) {
|
||||
dError("failed to start mnode worker since %s", terrstr());
|
||||
return code;
|
||||
}
|
||||
|
||||
SMnode *pMnode = mndOpen(pDnode->dir.mnode, pOption);
|
||||
if (pMnode == NULL) {
|
||||
dError("failed to open mnode since %s", terrstr());
|
||||
code = terrno;
|
||||
dndStopMnodeWorker(pDnode);
|
||||
terrno = code;
|
||||
return code;
|
||||
}
|
||||
|
||||
if (dndWriteMnodeFile(pDnode) != 0) {
|
||||
dError("failed to write mnode file since %s", terrstr());
|
||||
code = terrno;
|
||||
dndStopMnodeWorker(pDnode);
|
||||
mndClose(pMnode);
|
||||
mndDestroy(pDnode->dir.mnode);
|
||||
terrno = code;
|
||||
return code;
|
||||
}
|
||||
|
||||
taosWLockLatch(&pMgmt->latch);
|
||||
pMgmt->pMnode = pMnode;
|
||||
pMgmt->deployed = 1;
|
||||
taosWUnLockLatch(&pMgmt->latch);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int32_t dndAlterMnode(SDnode *pDnode, SMnodeOpt *pOption) {
|
||||
SMnodeMgmt *pMgmt = &pDnode->mmgmt;
|
||||
|
||||
SMnode *pMnode = dndAcquireMnode(pDnode);
|
||||
if (pMnode == NULL) {
|
||||
dError("failed to alter mnode since %s", terrstr());
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (mndAlter(pMnode, pOption) != 0) {
|
||||
dError("failed to alter mnode since %s", terrstr());
|
||||
dndReleaseMnode(pDnode, pMnode);
|
||||
return -1;
|
||||
}
|
||||
|
||||
dndReleaseMnode(pDnode, pMnode);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int32_t dndDropMnode(SDnode *pDnode) {
|
||||
SMnodeMgmt *pMgmt = &pDnode->mmgmt;
|
||||
|
||||
SMnode *pMnode = dndAcquireMnode(pDnode);
|
||||
if (pMnode == NULL) {
|
||||
dError("failed to drop mnode since %s", terrstr());
|
||||
return -1;
|
||||
}
|
||||
|
||||
taosRLockLatch(&pMgmt->latch);
|
||||
pMgmt->dropped = 1;
|
||||
taosRUnLockLatch(&pMgmt->latch);
|
||||
|
||||
if (dndWriteMnodeFile(pDnode) != 0) {
|
||||
taosRLockLatch(&pMgmt->latch);
|
||||
pMgmt->dropped = 0;
|
||||
taosRUnLockLatch(&pMgmt->latch);
|
||||
|
||||
dndReleaseMnode(pDnode, pMnode);
|
||||
dError("failed to drop mnode since %s", terrstr());
|
||||
return -1;
|
||||
}
|
||||
|
||||
dndStopMnodeWorker(pDnode);
|
||||
dndWriteMnodeFile(pDnode);
|
||||
mndClose(pMnode);
|
||||
mndDestroy(pDnode->dir.mnode);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static SCreateMnodeMsg *dndParseCreateMnodeMsg(SRpcMsg *pRpcMsg) {
|
||||
SCreateMnodeMsg *pMsg = pRpcMsg->pCont;
|
||||
pMsg->dnodeId = htonl(pMsg->dnodeId);
|
||||
for (int32_t i = 0; i < pMsg->replica; ++i) {
|
||||
pMsg->replicas[i].id = htonl(pMsg->replicas[i].id);
|
||||
pMsg->replicas[i].port = htons(pMsg->replicas[i].port);
|
||||
}
|
||||
|
||||
return pMsg;
|
||||
}
|
||||
|
||||
static int32_t dndProcessCreateMnodeReq(SDnode *pDnode, SRpcMsg *pRpcMsg) {
|
||||
SCreateMnodeMsg *pMsg = dndParseCreateMnodeMsg(pRpcMsg->pCont);
|
||||
|
||||
if (pMsg->dnodeId != dndGetDnodeId(pDnode)) {
|
||||
terrno = TSDB_CODE_DND_MNODE_ID_INVALID;
|
||||
return -1;
|
||||
} else {
|
||||
SMnodeOpt option = {0};
|
||||
if (dndBuildMnodeOptionFromMsg(pDnode, &option, pMsg) != 0) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
return dndOpenMnode(pDnode, &option);
|
||||
}
|
||||
}
|
||||
|
||||
static int32_t dndProcessAlterMnodeReq(SDnode *pDnode, SRpcMsg *pRpcMsg) {
|
||||
SAlterMnodeMsg *pMsg = dndParseCreateMnodeMsg(pRpcMsg->pCont);
|
||||
|
||||
if (pMsg->dnodeId != dndGetDnodeId(pDnode)) {
|
||||
terrno = TSDB_CODE_DND_MNODE_ID_INVALID;
|
||||
return -1;
|
||||
} else {
|
||||
SMnodeOpt option = {0};
|
||||
if (dndBuildMnodeOptionFromMsg(pDnode, &option, pMsg) != 0) {
|
||||
return -1;
|
||||
}
|
||||
return dndAlterMnode(pDnode, &option);
|
||||
}
|
||||
}
|
||||
|
||||
static int32_t dndProcessDropMnodeReq(SDnode *pDnode, SRpcMsg *pRpcMsg) {
|
||||
SDropMnodeMsg *pMsg = dndParseCreateMnodeMsg(pRpcMsg->pCont);
|
||||
|
||||
if (pMsg->dnodeId != dndGetDnodeId(pDnode)) {
|
||||
terrno = TSDB_CODE_DND_MNODE_ID_INVALID;
|
||||
return -1;
|
||||
} else {
|
||||
return dndDropMnode(pDnode);
|
||||
}
|
||||
}
|
||||
|
||||
static void dndProcessMnodeMgmtQueue(SDnode *pDnode, SRpcMsg *pMsg) {
|
||||
int32_t code = 0;
|
||||
|
||||
switch (pMsg->msgType) {
|
||||
case TSDB_MSG_TYPE_CREATE_MNODE_IN:
|
||||
code = dndProcessCreateMnodeReq(pDnode, pMsg);
|
||||
break;
|
||||
case TSDB_MSG_TYPE_ALTER_MNODE_IN:
|
||||
code = dndProcessAlterMnodeReq(pDnode, pMsg);
|
||||
break;
|
||||
case TSDB_MSG_TYPE_DROP_MNODE_IN:
|
||||
code = dndProcessDropMnodeReq(pDnode, pMsg);
|
||||
break;
|
||||
default:
|
||||
code = TSDB_CODE_MSG_NOT_PROCESSED;
|
||||
break;
|
||||
}
|
||||
|
||||
SRpcMsg rsp = {.code = code, .handle = pMsg->handle};
|
||||
rpcSendResponse(&rsp);
|
||||
rpcFreeCont(pMsg->pCont);
|
||||
taosFreeQitem(pMsg);
|
||||
}
|
||||
|
||||
static void dndProcessMnodeReadQueue(SDnode *pDnode, SMnodeMsg *pMsg) {
|
||||
SMnodeMgmt *pMgmt = &pDnode->mmgmt;
|
||||
|
||||
SMnode *pMnode = dndAcquireMnode(pDnode);
|
||||
if (pMnode != NULL) {
|
||||
mndProcessReadMsg(pMsg);
|
||||
dndReleaseMnode(pDnode, pMnode);
|
||||
} else {
|
||||
mndSendRsp(pMsg, terrno);
|
||||
}
|
||||
|
||||
mndCleanupMsg(pMsg);
|
||||
}
|
||||
|
||||
static void dndProcessMnodeWriteQueue(SDnode *pDnode, SMnodeMsg *pMsg) {
|
||||
SMnodeMgmt *pMgmt = &pDnode->mmgmt;
|
||||
|
||||
SMnode *pMnode = dndAcquireMnode(pDnode);
|
||||
if (pMnode != NULL) {
|
||||
mndProcessWriteMsg(pMsg);
|
||||
dndReleaseMnode(pDnode, pMnode);
|
||||
} else {
|
||||
mndSendRsp(pMsg, terrno);
|
||||
}
|
||||
|
||||
mndCleanupMsg(pMsg);
|
||||
}
|
||||
|
||||
static void dndProcessMnodeApplyQueue(SDnode *pDnode, SMnodeMsg *pMsg) {
|
||||
SMnodeMgmt *pMgmt = &pDnode->mmgmt;
|
||||
|
||||
SMnode *pMnode = dndAcquireMnode(pDnode);
|
||||
if (pMnode != NULL) {
|
||||
mndProcessApplyMsg(pMsg);
|
||||
dndReleaseMnode(pDnode, pMnode);
|
||||
} else {
|
||||
mndSendRsp(pMsg, terrno);
|
||||
}
|
||||
|
||||
mndCleanupMsg(pMsg);
|
||||
}
|
||||
|
||||
static void dndProcessMnodeSyncQueue(SDnode *pDnode, SMnodeMsg *pMsg) {
|
||||
SMnodeMgmt *pMgmt = &pDnode->mmgmt;
|
||||
|
||||
SMnode *pMnode = dndAcquireMnode(pDnode);
|
||||
if (pMnode != NULL) {
|
||||
mndProcessSyncMsg(pMsg);
|
||||
dndReleaseMnode(pDnode, pMnode);
|
||||
} else {
|
||||
mndSendRsp(pMsg, terrno);
|
||||
}
|
||||
|
||||
mndCleanupMsg(pMsg);
|
||||
}
|
||||
|
||||
static int32_t dndWriteMnodeMsgToQueue(SMnode *pMnode, taos_queue pQueue, SRpcMsg *pRpcMsg) {
|
||||
assert(pQueue);
|
||||
|
||||
SMnodeMsg *pMsg = mndInitMsg(pMnode, pRpcMsg);
|
||||
if (pMsg == NULL) {
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (taosWriteQitem(pQueue, pMsg) != 0) {
|
||||
mndCleanupMsg(pMsg);
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void dndProcessMnodeMgmtMsg(SDnode *pDnode, SRpcMsg *pRpcMsg, SEpSet *pEpSet) {
|
||||
SMnodeMgmt *pMgmt = &pDnode->mmgmt;
|
||||
SMnode *pMnode = dndAcquireMnode(pDnode);
|
||||
|
||||
SRpcMsg *pMsg = taosAllocateQitem(sizeof(SRpcMsg));
|
||||
if (pMsg == NULL || taosWriteQitem(pMgmt->pMgmtQ, pMsg) != 0) {
|
||||
SRpcMsg rsp = {.handle = pRpcMsg->handle, .code = TSDB_CODE_OUT_OF_MEMORY};
|
||||
rpcSendResponse(&rsp);
|
||||
rpcFreeCont(pRpcMsg->pCont);
|
||||
taosFreeQitem(pMsg);
|
||||
}
|
||||
}
|
||||
|
||||
void dndProcessMnodeWriteMsg(SDnode *pDnode, SRpcMsg *pMsg, SEpSet *pEpSet) {
|
||||
SMnodeMgmt *pMgmt = &pDnode->mmgmt;
|
||||
SMnode *pMnode = dndAcquireMnode(pDnode);
|
||||
if (pMnode == NULL || dndWriteMnodeMsgToQueue(pMnode, pMgmt->pWriteQ, pMsg) != 0) {
|
||||
SRpcMsg rsp = {.handle = pMsg->handle, .code = terrno};
|
||||
rpcSendResponse(&rsp);
|
||||
rpcFreeCont(pMsg->pCont);
|
||||
}
|
||||
|
||||
dndReleaseMnode(pDnode, pMnode);
|
||||
}
|
||||
|
||||
void dndProcessMnodeSyncMsg(SDnode *pDnode, SRpcMsg *pMsg, SEpSet *pEpSet) {
|
||||
SMnodeMgmt *pMgmt = &pDnode->mmgmt;
|
||||
SMnode *pMnode = dndAcquireMnode(pDnode);
|
||||
if (pMnode == NULL || dndWriteMnodeMsgToQueue(pMnode, pMgmt->pSyncQ, pMsg) != 0) {
|
||||
SRpcMsg rsp = {.handle = pMsg->handle, .code = terrno};
|
||||
rpcSendResponse(&rsp);
|
||||
rpcFreeCont(pMsg->pCont);
|
||||
}
|
||||
|
||||
dndReleaseMnode(pDnode, pMnode);
|
||||
}
|
||||
|
||||
void dndProcessMnodeReadMsg(SDnode *pDnode, SRpcMsg *pMsg, SEpSet *pEpSet) {
|
||||
SMnodeMgmt *pMgmt = &pDnode->mmgmt;
|
||||
SMnode *pMnode = dndAcquireMnode(pDnode);
|
||||
if (pMnode == NULL || dndWriteMnodeMsgToQueue(pMnode, pMgmt->pSyncQ, pMsg) != 0) {
|
||||
SRpcMsg rsp = {.handle = pMsg->handle, .code = terrno};
|
||||
rpcSendResponse(&rsp);
|
||||
rpcFreeCont(pMsg->pCont);
|
||||
}
|
||||
|
||||
dndReleaseMnode(pDnode, pMnode);
|
||||
}
|
||||
|
||||
static int32_t dndPutMsgIntoMnodeApplyQueue(SDnode *pDnode, SMnodeMsg *pMsg) {
|
||||
SMnodeMgmt *pMgmt = &pDnode->mmgmt;
|
||||
|
||||
SMnode *pMnode = dndAcquireMnode(pDnode);
|
||||
if (pMnode == NULL) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
int32_t code = taosWriteQitem(pMgmt->pApplyQ, pMsg);
|
||||
dndReleaseMnode(pDnode, pMnode);
|
||||
return code;
|
||||
}
|
||||
|
||||
static int32_t dndAllocMnodeMgmtQueue(SDnode *pDnode) {
|
||||
SMnodeMgmt *pMgmt = &pDnode->mmgmt;
|
||||
pMgmt->pMgmtQ = tWorkerAllocQueue(&pMgmt->mgmtPool, pDnode, (FProcessItem)dndProcessMnodeMgmtQueue);
|
||||
if (pMgmt->pMgmtQ == NULL) {
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
return -1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void dndFreeMnodeMgmtQueue(SDnode *pDnode) {
|
||||
SMnodeMgmt *pMgmt = &pDnode->mmgmt;
|
||||
tWorkerFreeQueue(&pMgmt->mgmtPool, pMgmt->pMgmtQ);
|
||||
pMgmt->pMgmtQ = NULL;
|
||||
}
|
||||
|
||||
static int32_t dndInitMnodeMgmtWorker(SDnode *pDnode) {
|
||||
SMnodeMgmt *pMgmt = &pDnode->mmgmt;
|
||||
SWorkerPool *pPool = &pMgmt->mgmtPool;
|
||||
pPool->name = "mnode-mgmt";
|
||||
pPool->min = 1;
|
||||
pPool->max = 1;
|
||||
if (tWorkerInit(pPool) != 0) {
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
return -1;
|
||||
}
|
||||
|
||||
dDebug("mnode mgmt worker is initialized");
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void dndCleanupMnodeMgmtWorker(SDnode *pDnode) {
|
||||
SMnodeMgmt *pMgmt = &pDnode->mmgmt;
|
||||
tWorkerCleanup(&pMgmt->mgmtPool);
|
||||
dDebug("mnode mgmt worker is closed");
|
||||
}
|
||||
|
||||
static int32_t dndAllocMnodeReadQueue(SDnode *pDnode) {
|
||||
SMnodeMgmt *pMgmt = &pDnode->mmgmt;
|
||||
pMgmt->pReadQ = tWorkerAllocQueue(&pMgmt->readPool, pDnode, (FProcessItem)dndProcessMnodeReadQueue);
|
||||
if (pMgmt->pReadQ == NULL) {
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void dndFreeMnodeReadQueue(SDnode *pDnode) {
|
||||
SMnodeMgmt *pMgmt = &pDnode->mmgmt;
|
||||
tWorkerFreeQueue(&pMgmt->readPool, pMgmt->pReadQ);
|
||||
pMgmt->pReadQ = NULL;
|
||||
}
|
||||
|
||||
static int32_t dndInitMnodeReadWorker(SDnode *pDnode) {
|
||||
SMnodeMgmt *pMgmt = &pDnode->mmgmt;
|
||||
SWorkerPool *pPool = &pMgmt->readPool;
|
||||
pPool->name = "mnode-read";
|
||||
pPool->min = 0;
|
||||
pPool->max = 1;
|
||||
if (tWorkerInit(pPool) != 0) {
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
return -1;
|
||||
}
|
||||
|
||||
dDebug("mnode read worker is initialized");
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void dndCleanupMnodeReadWorker(SDnode *pDnode) {
|
||||
SMnodeMgmt *pMgmt = &pDnode->mmgmt;
|
||||
tWorkerCleanup(&pMgmt->readPool);
|
||||
dDebug("mnode read worker is closed");
|
||||
}
|
||||
|
||||
static int32_t dndAllocMnodeWriteQueue(SDnode *pDnode) {
|
||||
SMnodeMgmt *pMgmt = &pDnode->mmgmt;
|
||||
pMgmt->pWriteQ = tWorkerAllocQueue(&pMgmt->writePool, pDnode, (FProcessItem)dndProcessMnodeWriteQueue);
|
||||
if (pMgmt->pWriteQ == NULL) {
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void dndFreeMnodeWriteQueue(SDnode *pDnode) {
|
||||
SMnodeMgmt *pMgmt = &pDnode->mmgmt;
|
||||
tWorkerFreeQueue(&pMgmt->writePool, pMgmt->pWriteQ);
|
||||
pMgmt->pWriteQ = NULL;
|
||||
}
|
||||
|
||||
static int32_t dndAllocMnodeApplyQueue(SDnode *pDnode) {
|
||||
SMnodeMgmt *pMgmt = &pDnode->mmgmt;
|
||||
pMgmt->pApplyQ = tWorkerAllocQueue(&pMgmt->writePool, pDnode, (FProcessItem)dndProcessMnodeApplyQueue);
|
||||
if (pMgmt->pApplyQ == NULL) {
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void dndFreeMnodeApplyQueue(SDnode *pDnode) {
|
||||
SMnodeMgmt *pMgmt = &pDnode->mmgmt;
|
||||
tWorkerFreeQueue(&pMgmt->writePool, pMgmt->pApplyQ);
|
||||
pMgmt->pApplyQ = NULL;
|
||||
}
|
||||
|
||||
static int32_t dndInitMnodeWriteWorker(SDnode *pDnode) {
|
||||
SMnodeMgmt *pMgmt = &pDnode->mmgmt;
|
||||
SWorkerPool *pPool = &pMgmt->writePool;
|
||||
pPool->name = "mnode-write";
|
||||
pPool->min = 0;
|
||||
pPool->max = 1;
|
||||
if (tWorkerInit(pPool) != 0) {
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
return -1;
|
||||
}
|
||||
|
||||
dDebug("mnode write worker is initialized");
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void dndCleanupMnodeWriteWorker(SDnode *pDnode) {
|
||||
SMnodeMgmt *pMgmt = &pDnode->mmgmt;
|
||||
tWorkerCleanup(&pMgmt->writePool);
|
||||
dDebug("mnode write worker is closed");
|
||||
}
|
||||
|
||||
static int32_t dndAllocMnodeSyncQueue(SDnode *pDnode) {
|
||||
SMnodeMgmt *pMgmt = &pDnode->mmgmt;
|
||||
pMgmt->pSyncQ = tWorkerAllocQueue(&pMgmt->syncPool, pDnode, (FProcessItem)dndProcessMnodeSyncQueue);
|
||||
if (pMgmt->pSyncQ == NULL) {
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void dndFreeMnodeSyncQueue(SDnode *pDnode) {
|
||||
SMnodeMgmt *pMgmt = &pDnode->mmgmt;
|
||||
tWorkerFreeQueue(&pMgmt->syncPool, pMgmt->pSyncQ);
|
||||
pMgmt->pSyncQ = NULL;
|
||||
}
|
||||
|
||||
static int32_t dndInitMnodeSyncWorker(SDnode *pDnode) {
|
||||
SMnodeMgmt *pMgmt = &pDnode->mmgmt;
|
||||
SWorkerPool *pPool = &pMgmt->syncPool;
|
||||
pPool->name = "mnode-sync";
|
||||
pPool->min = 0;
|
||||
pPool->max = 1;
|
||||
if (tWorkerInit(pPool) != 0) {
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
return -1;
|
||||
}
|
||||
|
||||
dDebug("mnode sync worker is initialized");
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void dndCleanupMnodeSyncWorker(SDnode *pDnode) {
|
||||
SMnodeMgmt *pMgmt = &pDnode->mmgmt;
|
||||
tWorkerCleanup(&pMgmt->syncPool);
|
||||
dDebug("mnode sync worker is closed");
|
||||
}
|
||||
|
||||
int32_t dndInitMnode(SDnode *pDnode) {
|
||||
dInfo("dnode-mnode start to init");
|
||||
SMnodeMgmt *pMgmt = &pDnode->mmgmt;
|
||||
taosInitRWLatch(&pMgmt->latch);
|
||||
|
||||
if (dndInitMnodeMgmtWorker(pDnode) != 0) {
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
return -1;
|
||||
}
|
||||
|
||||
char path[PATH_MAX];
|
||||
snprintf(path, PATH_MAX, "%s/mnode.json", pDnode->dir.dnode);
|
||||
pMgmt->file = strdup(path);
|
||||
if (pMgmt->file == NULL) {
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (dndReadMnodeFile(pDnode) != 0) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (pMgmt->dropped) {
|
||||
dInfo("mnode has been deployed and needs to be deleted");
|
||||
mndDestroy(pDnode->dir.mnode);
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (!pMgmt->deployed) {
|
||||
bool needDeploy = dndNeedDeployMnode(pDnode);
|
||||
if (!needDeploy) {
|
||||
dDebug("mnode does not need to be deployed");
|
||||
return 0;
|
||||
}
|
||||
|
||||
dInfo("start to deploy mnode");
|
||||
SMnodeOpt option = {0};
|
||||
dndBuildMnodeDeployOption(pDnode, &option);
|
||||
return dndOpenMnode(pDnode, &option);
|
||||
} else {
|
||||
dInfo("start to open mnode");
|
||||
SMnodeOpt option = {0};
|
||||
dndBuildMnodeOpenOption(pDnode, &option);
|
||||
return dndOpenMnode(pDnode, &option);
|
||||
}
|
||||
}
|
||||
|
||||
void dndCleanupMnode(SDnode *pDnode) {
|
||||
SMnodeMgmt *pMgmt = &pDnode->mmgmt;
|
||||
|
||||
dInfo("dnode-mnode start to clean up");
|
||||
dndStopMnodeWorker(pDnode);
|
||||
dndCleanupMnodeMgmtWorker(pDnode);
|
||||
tfree(pMgmt->file);
|
||||
dInfo("dnode-mnode is cleaned up");
|
||||
}
|
||||
|
||||
int32_t dndGetUserAuthFromMnode(SDnode *pDnode, char *user, char *spi, char *encrypt, char *secret, char *ckey) {
|
||||
SMnodeMgmt *pMgmt = &pDnode->mmgmt;
|
||||
|
||||
SMnode *pMnode = dndAcquireMnode(pDnode);
|
||||
if (pMnode == NULL) {
|
||||
terrno = TSDB_CODE_APP_NOT_READY;
|
||||
dTrace("failed to get user auth since %s", terrstr());
|
||||
return -1;
|
||||
}
|
||||
|
||||
int32_t code = mndRetriveAuth(pMnode, user, spi, encrypt, secret, ckey);
|
||||
dndReleaseMnode(pDnode, pMnode);
|
||||
return code;
|
||||
}
|
|
@ -0,0 +1,372 @@
|
|||
/*
|
||||
* 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/>.
|
||||
*/
|
||||
|
||||
/* this file is mainly responsible for the communication between DNODEs. Each
|
||||
* dnode works as both server and client. Dnode may send status, grant, config
|
||||
* messages to mnode, mnode may send create/alter/drop table/vnode messages
|
||||
* to dnode. All theses messages are handled from here
|
||||
*/
|
||||
|
||||
#define _DEFAULT_SOURCE
|
||||
#include "dndTransport.h"
|
||||
#include "dndDnode.h"
|
||||
#include "dndMnode.h"
|
||||
#include "dndVnodes.h"
|
||||
|
||||
#define INTERNAL_USER "_internal"
|
||||
#define INTERNAL_CKEY "_key"
|
||||
#define INTERNAL_SECRET "_secret"
|
||||
|
||||
static void dndInitMsgFp(STransMgmt *pMgmt) {
|
||||
// msg from client to dnode
|
||||
pMgmt->msgFp[TSDB_MSG_TYPE_SUBMIT] = dndProcessVnodeWriteMsg;
|
||||
pMgmt->msgFp[TSDB_MSG_TYPE_QUERY] = dndProcessVnodeQueryMsg;
|
||||
pMgmt->msgFp[TSDB_MSG_TYPE_FETCH] = dndProcessVnodeFetchMsg;
|
||||
pMgmt->msgFp[TSDB_MSG_TYPE_CREATE_TABLE] = dndProcessVnodeWriteMsg;
|
||||
pMgmt->msgFp[TSDB_MSG_TYPE_DROP_TABLE] = dndProcessVnodeWriteMsg;
|
||||
pMgmt->msgFp[TSDB_MSG_TYPE_ALTER_TABLE] = dndProcessVnodeWriteMsg;
|
||||
pMgmt->msgFp[TSDB_MSG_TYPE_UPDATE_TAG_VAL] = dndProcessVnodeWriteMsg;
|
||||
pMgmt->msgFp[TSDB_MSG_TYPE_TABLE_META] = dndProcessVnodeQueryMsg;
|
||||
pMgmt->msgFp[TSDB_MSG_TYPE_TABLES_META] = dndProcessVnodeQueryMsg;
|
||||
pMgmt->msgFp[TSDB_MSG_TYPE_MQ_QUERY] = dndProcessVnodeQueryMsg;
|
||||
pMgmt->msgFp[TSDB_MSG_TYPE_MQ_CONSUME] = dndProcessVnodeQueryMsg;
|
||||
pMgmt->msgFp[TSDB_MSG_TYPE_MQ_CONNECT] = dndProcessVnodeWriteMsg;
|
||||
pMgmt->msgFp[TSDB_MSG_TYPE_MQ_DISCONNECT] = dndProcessVnodeWriteMsg;
|
||||
pMgmt->msgFp[TSDB_MSG_TYPE_MQ_ACK] = dndProcessVnodeWriteMsg;
|
||||
pMgmt->msgFp[TSDB_MSG_TYPE_MQ_RESET] = dndProcessVnodeWriteMsg;
|
||||
|
||||
// msg from client to mnode
|
||||
pMgmt->msgFp[TSDB_MSG_TYPE_CONNECT] = dndProcessMnodeReadMsg;
|
||||
pMgmt->msgFp[TSDB_MSG_TYPE_CREATE_ACCT] = dndProcessMnodeWriteMsg;
|
||||
pMgmt->msgFp[TSDB_MSG_TYPE_ALTER_ACCT] = dndProcessMnodeWriteMsg;
|
||||
pMgmt->msgFp[TSDB_MSG_TYPE_DROP_ACCT] = dndProcessMnodeWriteMsg;
|
||||
pMgmt->msgFp[TSDB_MSG_TYPE_CREATE_USER] = dndProcessMnodeWriteMsg;
|
||||
pMgmt->msgFp[TSDB_MSG_TYPE_ALTER_USER] = dndProcessMnodeWriteMsg;
|
||||
pMgmt->msgFp[TSDB_MSG_TYPE_DROP_USER] = dndProcessMnodeWriteMsg;
|
||||
pMgmt->msgFp[TSDB_MSG_TYPE_CREATE_DNODE] = dndProcessMnodeWriteMsg;
|
||||
pMgmt->msgFp[TSDB_MSG_TYPE_CONFIG_DNODE] = dndProcessMnodeWriteMsg;
|
||||
pMgmt->msgFp[TSDB_MSG_TYPE_DROP_DNODE] = dndProcessMnodeWriteMsg;
|
||||
pMgmt->msgFp[TSDB_MSG_TYPE_CREATE_DB] = dndProcessMnodeWriteMsg;
|
||||
pMgmt->msgFp[TSDB_MSG_TYPE_DROP_DB] = dndProcessMnodeWriteMsg;
|
||||
pMgmt->msgFp[TSDB_MSG_TYPE_USE_DB] = dndProcessMnodeWriteMsg;
|
||||
pMgmt->msgFp[TSDB_MSG_TYPE_ALTER_DB] = dndProcessMnodeWriteMsg;
|
||||
pMgmt->msgFp[TSDB_MSG_TYPE_SYNC_DB] = dndProcessMnodeWriteMsg;
|
||||
pMgmt->msgFp[TSDB_MSG_TYPE_CREATE_TOPIC] = dndProcessMnodeWriteMsg;
|
||||
pMgmt->msgFp[TSDB_MSG_TYPE_DROP_TOPIC] = dndProcessMnodeWriteMsg;
|
||||
pMgmt->msgFp[TSDB_MSG_TYPE_ALTER_TOPIC] = dndProcessMnodeWriteMsg;
|
||||
pMgmt->msgFp[TSDB_MSG_TYPE_CREATE_FUNCTION] = dndProcessMnodeWriteMsg;
|
||||
pMgmt->msgFp[TSDB_MSG_TYPE_ALTER_FUNCTION] = dndProcessMnodeWriteMsg;
|
||||
pMgmt->msgFp[TSDB_MSG_TYPE_DROP_FUNCTION] = dndProcessMnodeWriteMsg;
|
||||
pMgmt->msgFp[TSDB_MSG_TYPE_CREATE_STABLE] = dndProcessMnodeWriteMsg;
|
||||
pMgmt->msgFp[TSDB_MSG_TYPE_ALTER_STABLE] = dndProcessMnodeWriteMsg;
|
||||
pMgmt->msgFp[TSDB_MSG_TYPE_DROP_STABLE] = dndProcessMnodeWriteMsg;
|
||||
pMgmt->msgFp[TSDB_MSG_TYPE_STABLE_VGROUP] = dndProcessMnodeReadMsg;
|
||||
pMgmt->msgFp[TSDB_MSG_TYPE_KILL_QUERY] = dndProcessMnodeWriteMsg;
|
||||
pMgmt->msgFp[TSDB_MSG_TYPE_KILL_CONN] = dndProcessMnodeWriteMsg;
|
||||
pMgmt->msgFp[TSDB_MSG_TYPE_HEARTBEAT] = dndProcessMnodeReadMsg;
|
||||
pMgmt->msgFp[TSDB_MSG_TYPE_SHOW] = dndProcessMnodeReadMsg;
|
||||
pMgmt->msgFp[TSDB_MSG_TYPE_SHOW_RETRIEVE] = dndProcessMnodeReadMsg;
|
||||
pMgmt->msgFp[TSDB_MSG_TYPE_SHOW_RETRIEVE_FUNC] = dndProcessMnodeReadMsg;
|
||||
pMgmt->msgFp[TSDB_MSG_TYPE_COMPACT_VNODE] = dndProcessMnodeWriteMsg;
|
||||
|
||||
// message from client to dnode
|
||||
pMgmt->msgFp[TSDB_MSG_TYPE_NETWORK_TEST] = dndProcessDnodeReq;
|
||||
|
||||
// message from mnode to vnode
|
||||
pMgmt->msgFp[TSDB_MSG_TYPE_CREATE_STABLE_IN] = dndProcessVnodeWriteMsg;
|
||||
pMgmt->msgFp[TSDB_MSG_TYPE_CREATE_STABLE_IN_RSP] = dndProcessMnodeWriteMsg;
|
||||
pMgmt->msgFp[TSDB_MSG_TYPE_ALTER_STABLE_IN] = dndProcessVnodeWriteMsg;
|
||||
pMgmt->msgFp[TSDB_MSG_TYPE_ALTER_STABLE_IN_RSP] = dndProcessMnodeWriteMsg;
|
||||
pMgmt->msgFp[TSDB_MSG_TYPE_DROP_STABLE_IN] = dndProcessVnodeWriteMsg;
|
||||
pMgmt->msgFp[TSDB_MSG_TYPE_DROP_STABLE_IN_RSP] = dndProcessMnodeWriteMsg;
|
||||
|
||||
// message from mnode to dnode
|
||||
pMgmt->msgFp[TSDB_MSG_TYPE_CREATE_VNODE_IN] = dndProcessVnodeMgmtMsg;
|
||||
pMgmt->msgFp[TSDB_MSG_TYPE_CREATE_VNODE_IN_RSP] = dndProcessMnodeWriteMsg;
|
||||
pMgmt->msgFp[TSDB_MSG_TYPE_ALTER_VNODE_IN] = dndProcessVnodeMgmtMsg;
|
||||
pMgmt->msgFp[TSDB_MSG_TYPE_ALTER_VNODE_IN_RSP] = dndProcessMnodeWriteMsg;
|
||||
pMgmt->msgFp[TSDB_MSG_TYPE_DROP_VNODE_IN] = dndProcessVnodeMgmtMsg;
|
||||
pMgmt->msgFp[TSDB_MSG_TYPE_DROP_VNODE_IN_RSP] = dndProcessMnodeWriteMsg;
|
||||
pMgmt->msgFp[TSDB_MSG_TYPE_SYNC_VNODE_IN] = dndProcessVnodeMgmtMsg;
|
||||
pMgmt->msgFp[TSDB_MSG_TYPE_SYNC_VNODE_IN_RSP] = dndProcessMnodeWriteMsg;
|
||||
pMgmt->msgFp[TSDB_MSG_TYPE_AUTH_VNODE_IN] = dndProcessVnodeMgmtMsg;
|
||||
pMgmt->msgFp[TSDB_MSG_TYPE_AUTH_VNODE_IN_RSP] = dndProcessMnodeWriteMsg;
|
||||
pMgmt->msgFp[TSDB_MSG_TYPE_COMPACT_VNODE_IN] = dndProcessVnodeMgmtMsg;
|
||||
pMgmt->msgFp[TSDB_MSG_TYPE_COMPACT_VNODE_IN_RSP] = dndProcessMnodeWriteMsg;
|
||||
pMgmt->msgFp[TSDB_MSG_TYPE_CREATE_MNODE_IN] = dndProcessMnodeMgmtMsg;
|
||||
pMgmt->msgFp[TSDB_MSG_TYPE_CREATE_MNODE_IN_RSP] = dndProcessMnodeWriteMsg;
|
||||
pMgmt->msgFp[TSDB_MSG_TYPE_ALTER_MNODE_IN] = dndProcessMnodeMgmtMsg;
|
||||
pMgmt->msgFp[TSDB_MSG_TYPE_ALTER_MNODE_IN_RSP] = dndProcessMnodeWriteMsg;
|
||||
pMgmt->msgFp[TSDB_MSG_TYPE_DROP_MNODE_IN] = dndProcessMnodeMgmtMsg;
|
||||
pMgmt->msgFp[TSDB_MSG_TYPE_DROP_MNODE_IN_RSP] = dndProcessMnodeWriteMsg;
|
||||
pMgmt->msgFp[TSDB_MSG_TYPE_CONFIG_DNODE_IN] = dndProcessDnodeReq;
|
||||
pMgmt->msgFp[TSDB_MSG_TYPE_CONFIG_DNODE_IN_RSP] = dndProcessMnodeWriteMsg;
|
||||
|
||||
// message from dnode to mnode
|
||||
pMgmt->msgFp[TSDB_MSG_TYPE_AUTH] = dndProcessMnodeReadMsg;
|
||||
pMgmt->msgFp[TSDB_MSG_TYPE_AUTH_RSP] = dndProcessDnodeRsp;
|
||||
pMgmt->msgFp[TSDB_MSG_TYPE_GRANT] = dndProcessMnodeWriteMsg;
|
||||
pMgmt->msgFp[TSDB_MSG_TYPE_GRANT_RSP] = dndProcessDnodeRsp;
|
||||
pMgmt->msgFp[TSDB_MSG_TYPE_STATUS] = dndProcessMnodeWriteMsg;
|
||||
pMgmt->msgFp[TSDB_MSG_TYPE_STATUS_RSP] = dndProcessDnodeRsp;
|
||||
}
|
||||
|
||||
static void dndProcessResponse(void *parent, SRpcMsg *pMsg, SEpSet *pEpSet) {
|
||||
SDnode *pDnode = parent;
|
||||
STransMgmt *pMgmt = &pDnode->tmgmt;
|
||||
|
||||
int32_t msgType = pMsg->msgType;
|
||||
|
||||
if (dndGetStat(pDnode) == DND_STAT_STOPPED) {
|
||||
if (pMsg == NULL || pMsg->pCont == NULL) return;
|
||||
dTrace("RPC %p, rsp:%s is ignored since dnode is stopping", pMsg->handle, taosMsg[msgType]);
|
||||
rpcFreeCont(pMsg->pCont);
|
||||
return;
|
||||
}
|
||||
|
||||
DndMsgFp fp = pMgmt->msgFp[msgType];
|
||||
if (fp != NULL) {
|
||||
dTrace("RPC %p, rsp:%s will be processed, code:%s", pMsg->handle, taosMsg[msgType], tstrerror(pMsg->code));
|
||||
(*fp)(pDnode, pMsg, pEpSet);
|
||||
} else {
|
||||
dError("RPC %p, rsp:%s not processed", pMsg->handle, taosMsg[msgType]);
|
||||
rpcFreeCont(pMsg->pCont);
|
||||
}
|
||||
}
|
||||
|
||||
static int32_t dndInitClient(SDnode *pDnode) {
|
||||
STransMgmt *pMgmt = &pDnode->tmgmt;
|
||||
|
||||
SRpcInit rpcInit;
|
||||
memset(&rpcInit, 0, sizeof(rpcInit));
|
||||
rpcInit.label = "DND-C";
|
||||
rpcInit.numOfThreads = 1;
|
||||
rpcInit.cfp = dndProcessResponse;
|
||||
rpcInit.sessions = 8;
|
||||
rpcInit.connType = TAOS_CONN_CLIENT;
|
||||
rpcInit.idleTime = pDnode->opt.shellActivityTimer * 1000;
|
||||
rpcInit.user = INTERNAL_USER;
|
||||
rpcInit.ckey = INTERNAL_CKEY;
|
||||
rpcInit.secret = INTERNAL_SECRET;
|
||||
rpcInit.parent = pDnode;
|
||||
|
||||
pMgmt->clientRpc = rpcOpen(&rpcInit);
|
||||
if (pMgmt->clientRpc == NULL) {
|
||||
dError("failed to init rpc client");
|
||||
return -1;
|
||||
}
|
||||
|
||||
dDebug("dnode rpc client is initialized");
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void dndCleanupClient(SDnode *pDnode) {
|
||||
STransMgmt *pMgmt = &pDnode->tmgmt;
|
||||
if (pMgmt->clientRpc) {
|
||||
rpcClose(pMgmt->clientRpc);
|
||||
pMgmt->clientRpc = NULL;
|
||||
dDebug("dnode rpc client is closed");
|
||||
}
|
||||
}
|
||||
|
||||
static void dndProcessRequest(void *param, SRpcMsg *pMsg, SEpSet *pEpSet) {
|
||||
SDnode *pDnode = param;
|
||||
STransMgmt *pMgmt = &pDnode->tmgmt;
|
||||
|
||||
int32_t msgType = pMsg->msgType;
|
||||
if (msgType == TSDB_MSG_TYPE_NETWORK_TEST) {
|
||||
dTrace("RPC %p, network test req will be processed", pMsg->handle);
|
||||
dndProcessDnodeReq(pDnode, pMsg, pEpSet);
|
||||
return;
|
||||
}
|
||||
|
||||
if (dndGetStat(pDnode) == DND_STAT_STOPPED) {
|
||||
dError("RPC %p, req:%s is ignored since dnode exiting", pMsg->handle, taosMsg[msgType]);
|
||||
SRpcMsg rspMsg = {.handle = pMsg->handle, .code = TSDB_CODE_DND_EXITING};
|
||||
rpcSendResponse(&rspMsg);
|
||||
rpcFreeCont(pMsg->pCont);
|
||||
return;
|
||||
} else if (dndGetStat(pDnode) != DND_STAT_RUNNING) {
|
||||
dError("RPC %p, req:%s is ignored since dnode not running", pMsg->handle, taosMsg[msgType]);
|
||||
SRpcMsg rspMsg = {.handle = pMsg->handle, .code = TSDB_CODE_APP_NOT_READY};
|
||||
rpcSendResponse(&rspMsg);
|
||||
rpcFreeCont(pMsg->pCont);
|
||||
return;
|
||||
}
|
||||
|
||||
if (pMsg->pCont == NULL) {
|
||||
dTrace("RPC %p, req:%s not processed since content is null", pMsg->handle, taosMsg[msgType]);
|
||||
SRpcMsg rspMsg = {.handle = pMsg->handle, .code = TSDB_CODE_DND_INVALID_MSG_LEN};
|
||||
rpcSendResponse(&rspMsg);
|
||||
return;
|
||||
}
|
||||
|
||||
DndMsgFp fp = pMgmt->msgFp[msgType];
|
||||
if (fp != NULL) {
|
||||
dTrace("RPC %p, req:%s will be processed", pMsg->handle, taosMsg[msgType]);
|
||||
(*fp)(pDnode, pMsg, pEpSet);
|
||||
} else {
|
||||
dError("RPC %p, req:%s is not processed", pMsg->handle, taosMsg[msgType]);
|
||||
SRpcMsg rspMsg = {.handle = pMsg->handle, .code = TSDB_CODE_MSG_NOT_PROCESSED};
|
||||
rpcSendResponse(&rspMsg);
|
||||
rpcFreeCont(pMsg->pCont);
|
||||
}
|
||||
}
|
||||
|
||||
static void dndSendMsgToMnodeRecv(SDnode *pDnode, SRpcMsg *pRpcMsg, SRpcMsg *pRpcRsp) {
|
||||
STransMgmt *pMgmt = &pDnode->tmgmt;
|
||||
|
||||
SEpSet epSet = {0};
|
||||
dndGetMnodeEpSet(pDnode, &epSet);
|
||||
rpcSendRecv(pMgmt->clientRpc, &epSet, pRpcMsg, pRpcRsp);
|
||||
}
|
||||
|
||||
static int32_t dndAuthInternalMsg(SDnode *pDnode, char *user, char *spi, char *encrypt, char *secret, char *ckey) {
|
||||
if (strcmp(user, INTERNAL_USER) == 0) {
|
||||
// A simple temporary implementation
|
||||
char pass[32] = {0};
|
||||
taosEncryptPass((uint8_t *)(INTERNAL_SECRET), strlen(INTERNAL_SECRET), pass);
|
||||
memcpy(secret, pass, TSDB_KEY_LEN);
|
||||
*spi = 0;
|
||||
*encrypt = 0;
|
||||
*ckey = 0;
|
||||
return 0;
|
||||
} else if (strcmp(user, TSDB_NETTEST_USER) == 0) {
|
||||
// A simple temporary implementation
|
||||
char pass[32] = {0};
|
||||
taosEncryptPass((uint8_t *)(TSDB_NETTEST_USER), strlen(TSDB_NETTEST_USER), pass);
|
||||
memcpy(secret, pass, TSDB_KEY_LEN);
|
||||
*spi = 0;
|
||||
*encrypt = 0;
|
||||
*ckey = 0;
|
||||
return 0;
|
||||
} else {
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
static int32_t dndRetrieveUserAuthInfo(void *parent, char *user, char *spi, char *encrypt, char *secret, char *ckey) {
|
||||
SDnode *pDnode = parent;
|
||||
|
||||
if (dndAuthInternalMsg(parent, user, spi, encrypt, secret, ckey) == 0) {
|
||||
// dTrace("get internal auth success");
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (dndGetUserAuthFromMnode(pDnode, user, spi, encrypt, secret, ckey) == 0) {
|
||||
// dTrace("get auth from internal mnode");
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (terrno != TSDB_CODE_APP_NOT_READY) {
|
||||
dTrace("failed to get user auth from internal mnode since %s", terrstr());
|
||||
return -1;
|
||||
}
|
||||
|
||||
// dDebug("user:%s, send auth msg to other mnodes", user);
|
||||
|
||||
SAuthMsg *pMsg = rpcMallocCont(sizeof(SAuthMsg));
|
||||
tstrncpy(pMsg->user, user, TSDB_USER_LEN);
|
||||
|
||||
SRpcMsg rpcMsg = {.pCont = pMsg, .contLen = sizeof(SAuthMsg), .msgType = TSDB_MSG_TYPE_AUTH};
|
||||
SRpcMsg rpcRsp = {0};
|
||||
dndSendMsgToMnodeRecv(pDnode, &rpcMsg, &rpcRsp);
|
||||
|
||||
if (rpcRsp.code != 0) {
|
||||
terrno = rpcRsp.code;
|
||||
dError("user:%s, failed to get user auth from other mnodes since %s", user, terrstr());
|
||||
} else {
|
||||
SAuthRsp *pRsp = rpcRsp.pCont;
|
||||
memcpy(secret, pRsp->secret, TSDB_KEY_LEN);
|
||||
memcpy(ckey, pRsp->ckey, TSDB_KEY_LEN);
|
||||
*spi = pRsp->spi;
|
||||
*encrypt = pRsp->encrypt;
|
||||
dDebug("user:%s, success to get user auth from other mnodes", user);
|
||||
}
|
||||
|
||||
rpcFreeCont(rpcRsp.pCont);
|
||||
return rpcRsp.code;
|
||||
}
|
||||
|
||||
static int32_t dndInitServer(SDnode *pDnode) {
|
||||
STransMgmt *pMgmt = &pDnode->tmgmt;
|
||||
dndInitMsgFp(pMgmt);
|
||||
|
||||
int32_t numOfThreads = (int32_t)((pDnode->opt.numOfCores * pDnode->opt.numOfThreadsPerCore) / 2.0);
|
||||
if (numOfThreads < 1) {
|
||||
numOfThreads = 1;
|
||||
}
|
||||
|
||||
SRpcInit rpcInit;
|
||||
memset(&rpcInit, 0, sizeof(rpcInit));
|
||||
rpcInit.localPort = pDnode->opt.serverPort;
|
||||
rpcInit.label = "DND-S";
|
||||
rpcInit.numOfThreads = numOfThreads;
|
||||
rpcInit.cfp = dndProcessRequest;
|
||||
rpcInit.sessions = pDnode->opt.maxShellConns;
|
||||
rpcInit.connType = TAOS_CONN_SERVER;
|
||||
rpcInit.idleTime = pDnode->opt.shellActivityTimer * 1000;
|
||||
rpcInit.afp = dndRetrieveUserAuthInfo;
|
||||
rpcInit.parent = pDnode;
|
||||
|
||||
pMgmt->serverRpc = rpcOpen(&rpcInit);
|
||||
if (pMgmt->serverRpc == NULL) {
|
||||
dError("failed to init rpc server");
|
||||
return -1;
|
||||
}
|
||||
|
||||
dDebug("dnode rpc server is initialized");
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void dndCleanupServer(SDnode *pDnode) {
|
||||
STransMgmt *pMgmt = &pDnode->tmgmt;
|
||||
if (pMgmt->serverRpc) {
|
||||
rpcClose(pMgmt->serverRpc);
|
||||
pMgmt->serverRpc = NULL;
|
||||
dDebug("dnode rpc server is closed");
|
||||
}
|
||||
}
|
||||
|
||||
int32_t dndInitTrans(SDnode *pDnode) {
|
||||
if (dndInitClient(pDnode) != 0) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (dndInitServer(pDnode) != 0) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
dInfo("dnode-transport is initialized");
|
||||
return 0;
|
||||
}
|
||||
|
||||
void dndCleanupTrans(SDnode *pDnode) {
|
||||
dInfo("dnode-transport start to clean up");
|
||||
dndCleanupServer(pDnode);
|
||||
dndCleanupClient(pDnode);
|
||||
dInfo("dnode-transport is cleaned up");
|
||||
}
|
||||
|
||||
void dndSendMsgToDnode(SDnode *pDnode, SEpSet *pEpSet, SRpcMsg *pMsg) {
|
||||
STransMgmt *pMgmt = &pDnode->tmgmt;
|
||||
rpcSendRequest(pMgmt->clientRpc, pEpSet, pMsg, NULL);
|
||||
}
|
||||
|
||||
void dndSendMsgToMnode(SDnode *pDnode, SRpcMsg *pMsg) {
|
||||
SEpSet epSet = {0};
|
||||
dndGetMnodeEpSet(pDnode, &epSet);
|
||||
dndSendMsgToDnode(pDnode, &epSet, pMsg);
|
||||
}
|
File diff suppressed because it is too large
Load Diff
|
@ -0,0 +1,220 @@
|
|||
/*
|
||||
* 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 "dndDnode.h"
|
||||
#include "dndMnode.h"
|
||||
#include "dndTransport.h"
|
||||
#include "dndVnodes.h"
|
||||
#include "sync.h"
|
||||
#include "tcache.h"
|
||||
#include "tcrc32c.h"
|
||||
#include "wal.h"
|
||||
|
||||
EStat dndGetStat(SDnode *pDnode) { return pDnode->stat; }
|
||||
|
||||
void dndSetStat(SDnode *pDnode, EStat stat) {
|
||||
dDebug("dnode status set from %s to %s", dndStatStr(pDnode->stat), dndStatStr(stat));
|
||||
pDnode->stat = stat;
|
||||
}
|
||||
|
||||
char *dndStatStr(EStat stat) {
|
||||
switch (stat) {
|
||||
case DND_STAT_INIT:
|
||||
return "init";
|
||||
case DND_STAT_RUNNING:
|
||||
return "running";
|
||||
case DND_STAT_STOPPED:
|
||||
return "stopped";
|
||||
default:
|
||||
return "unknown";
|
||||
}
|
||||
}
|
||||
|
||||
void dndReportStartup(SDnode *pDnode, char *pName, char *pDesc) {
|
||||
SStartupMsg *pStartup = &pDnode->startup;
|
||||
tstrncpy(pStartup->name, pName, TSDB_STEP_NAME_LEN);
|
||||
tstrncpy(pStartup->desc, pDesc, TSDB_STEP_DESC_LEN);
|
||||
pStartup->finished = 0;
|
||||
}
|
||||
|
||||
void dndGetStartup(SDnode *pDnode, SStartupMsg *pStartup) {
|
||||
memcpy(pStartup, &pDnode->startup, sizeof(SStartupMsg));
|
||||
pStartup->finished = (dndGetStat(pDnode) == DND_STAT_RUNNING);
|
||||
}
|
||||
|
||||
static int32_t dndCheckRunning(char *dataDir) {
|
||||
char filepath[PATH_MAX] = {0};
|
||||
snprintf(filepath, sizeof(filepath), "%s/.running", dataDir);
|
||||
|
||||
FileFd fd = taosOpenFileCreateWriteTrunc(filepath);
|
||||
if (fd < 0) {
|
||||
dError("failed to lock file:%s since %s, quit", filepath, strerror(errno));
|
||||
terrno = TAOS_SYSTEM_ERROR(errno);
|
||||
return -1;
|
||||
}
|
||||
|
||||
int32_t ret = taosLockFile(fd);
|
||||
if (ret != 0) {
|
||||
dError("failed to lock file:%s since %s, quit", filepath, strerror(errno));
|
||||
terrno = TAOS_SYSTEM_ERROR(errno);
|
||||
taosCloseFile(fd);
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int32_t dndInitEnv(SDnode *pDnode, SDnodeOpt *pOption) {
|
||||
if (dndCheckRunning(pOption->dataDir) != 0) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
char path[PATH_MAX + 100];
|
||||
snprintf(path, sizeof(path), "%s%smnode", pOption->dataDir, TD_DIRSEP);
|
||||
pDnode->dir.mnode = tstrdup(path);
|
||||
|
||||
snprintf(path, sizeof(path), "%s%svnode", pOption->dataDir, TD_DIRSEP);
|
||||
pDnode->dir.vnodes = tstrdup(path);
|
||||
|
||||
snprintf(path, sizeof(path), "%s%sdnode", pOption->dataDir, TD_DIRSEP);
|
||||
pDnode->dir.dnode = tstrdup(path);
|
||||
|
||||
if (pDnode->dir.mnode == NULL || pDnode->dir.vnodes == NULL || pDnode->dir.dnode == NULL) {
|
||||
dError("failed to malloc dir object");
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (taosMkDir(pDnode->dir.dnode) != 0) {
|
||||
dError("failed to create dir:%s since %s", pDnode->dir.dnode, strerror(errno));
|
||||
terrno = TAOS_SYSTEM_ERROR(errno);
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (taosMkDir(pDnode->dir.mnode) != 0) {
|
||||
dError("failed to create dir:%s since %s", pDnode->dir.mnode, strerror(errno));
|
||||
terrno = TAOS_SYSTEM_ERROR(errno);
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (taosMkDir(pDnode->dir.vnodes) != 0) {
|
||||
dError("failed to create dir:%s since %s", pDnode->dir.vnodes, strerror(errno));
|
||||
terrno = TAOS_SYSTEM_ERROR(errno);
|
||||
return -1;
|
||||
}
|
||||
|
||||
memcpy(&pDnode->opt, pOption, sizeof(SDnodeOpt));
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void dndCleanupEnv(SDnode *pDnode) {
|
||||
if (pDnode->dir.mnode != NULL) {
|
||||
tfree(pDnode->dir.mnode);
|
||||
}
|
||||
|
||||
if (pDnode->dir.vnodes != NULL) {
|
||||
tfree(pDnode->dir.vnodes);
|
||||
}
|
||||
|
||||
if (pDnode->dir.dnode != NULL) {
|
||||
tfree(pDnode->dir.dnode);
|
||||
}
|
||||
|
||||
taosStopCacheRefreshWorker();
|
||||
}
|
||||
|
||||
SDnode *dndInit(SDnodeOpt *pOption) {
|
||||
taosIgnSIGPIPE();
|
||||
taosBlockSIGPIPE();
|
||||
taosResolveCRC();
|
||||
|
||||
SDnode *pDnode = calloc(1, sizeof(SDnode));
|
||||
if (pDnode == NULL) {
|
||||
dError("failed to create dnode object");
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
dInfo("start to initialize TDengine");
|
||||
dndSetStat(pDnode, DND_STAT_INIT);
|
||||
|
||||
if (dndInitEnv(pDnode, pOption) != 0) {
|
||||
dError("failed to init env");
|
||||
dndCleanup(pDnode);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (rpcInit() != 0) {
|
||||
dError("failed to init rpc env");
|
||||
dndCleanup(pDnode);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (walInit() != 0) {
|
||||
dError("failed to init wal env");
|
||||
dndCleanup(pDnode);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (dndInitDnode(pDnode) != 0) {
|
||||
dError("failed to init dnode");
|
||||
dndCleanup(pDnode);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (dndInitVnodes(pDnode) != 0) {
|
||||
dError("failed to init vnodes");
|
||||
dndCleanup(pDnode);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (dndInitMnode(pDnode) != 0) {
|
||||
dError("failed to init mnode");
|
||||
dndCleanup(pDnode);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (dndInitTrans(pDnode) != 0) {
|
||||
dError("failed to init transport");
|
||||
dndCleanup(pDnode);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
dndSetStat(pDnode, DND_STAT_RUNNING);
|
||||
dndReportStartup(pDnode, "TDengine", "initialized successfully");
|
||||
dInfo("TDengine is initialized successfully");
|
||||
|
||||
return pDnode;
|
||||
}
|
||||
|
||||
void dndCleanup(SDnode *pDnode) {
|
||||
if (dndGetStat(pDnode) == DND_STAT_STOPPED) {
|
||||
dError("dnode is shutting down");
|
||||
return;
|
||||
}
|
||||
|
||||
dInfo("start to cleanup TDengine");
|
||||
dndSetStat(pDnode, DND_STAT_STOPPED);
|
||||
dndCleanupTrans(pDnode);
|
||||
dndCleanupMnode(pDnode);
|
||||
dndCleanupVnodes(pDnode);
|
||||
dndCleanupDnode(pDnode);
|
||||
walCleanUp();
|
||||
rpcCleanup();
|
||||
dndCleanupEnv(pDnode);
|
||||
free(pDnode);
|
||||
dInfo("TDengine is cleaned up successfully");
|
||||
}
|
|
@ -1,54 +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_DNODE_INT_H_
|
||||
#define _TD_DNODE_INT_H_
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
#include "os.h"
|
||||
#include "taosmsg.h"
|
||||
#include "tglobal.h"
|
||||
#include "tlog.h"
|
||||
#include "trpc.h"
|
||||
|
||||
extern int32_t dDebugFlag;
|
||||
|
||||
#define dFatal(...) { if (dDebugFlag & DEBUG_FATAL) { taosPrintLog("DND FATAL ", 255, __VA_ARGS__); }}
|
||||
#define dError(...) { if (dDebugFlag & DEBUG_ERROR) { taosPrintLog("DND ERROR ", 255, __VA_ARGS__); }}
|
||||
#define dWarn(...) { if (dDebugFlag & DEBUG_WARN) { taosPrintLog("DND WARN ", 255, __VA_ARGS__); }}
|
||||
#define dInfo(...) { if (dDebugFlag & DEBUG_INFO) { taosPrintLog("DND ", 255, __VA_ARGS__); }}
|
||||
#define dDebug(...) { if (dDebugFlag & DEBUG_DEBUG) { taosPrintLog("DND ", dDebugFlag, __VA_ARGS__); }}
|
||||
#define dTrace(...) { if (dDebugFlag & DEBUG_TRACE) { taosPrintLog("DND ", dDebugFlag, __VA_ARGS__); }}
|
||||
|
||||
typedef enum { DN_RUN_STAT_INIT, DN_RUN_STAT_RUNNING, DN_RUN_STAT_STOPPED } EDnStat;
|
||||
typedef void (*MsgFp)(SRpcMsg *pMsg, SEpSet *pEpSet);
|
||||
|
||||
int32_t dnodeInit();
|
||||
void dnodeCleanup();
|
||||
|
||||
EDnStat dnodeGetRunStat();
|
||||
void dnodeSetRunStat();
|
||||
|
||||
void dnodeReportStartup(char *name, char *desc);
|
||||
void dnodeReportStartupFinished(char *name, char *desc);
|
||||
void dnodeGetStartup(SStartupMsg *);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /*_TD_DNODE_INT_H_*/
|
|
@ -1,46 +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 "dnodeInt.h"
|
||||
|
||||
static bool stop = false;
|
||||
static void sigintHandler(int32_t signum, void *info, void *ctx) { stop = true; }
|
||||
static void setSignalHandler() {
|
||||
taosSetSignal(SIGTERM, sigintHandler);
|
||||
taosSetSignal(SIGHUP, sigintHandler);
|
||||
taosSetSignal(SIGINT, sigintHandler);
|
||||
taosSetSignal(SIGABRT, sigintHandler);
|
||||
taosSetSignal(SIGBREAK, sigintHandler);
|
||||
}
|
||||
|
||||
int main(int argc, char const *argv[]) {
|
||||
setSignalHandler();
|
||||
|
||||
int32_t code = dnodeInit();
|
||||
if (code != 0) {
|
||||
dInfo("Failed to start TDengine, please check the log at:%s", tsLogDir);
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
while (!stop) {
|
||||
taosMsleep(100);
|
||||
}
|
||||
|
||||
dInfo("TDengine is shut down!");
|
||||
dnodeCleanup();
|
||||
|
||||
return 0;
|
||||
}
|
|
@ -1,560 +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 "dnodeDnode.h"
|
||||
#include "dnodeTransport.h"
|
||||
#include "dnodeVnodes.h"
|
||||
#include "cJSON.h"
|
||||
#include "thash.h"
|
||||
#include "tthread.h"
|
||||
#include "ttime.h"
|
||||
|
||||
static struct {
|
||||
int32_t dnodeId;
|
||||
int64_t clusterId;
|
||||
SDnodeEps *dnodeEps;
|
||||
SHashObj *dnodeHash;
|
||||
SEpSet mnodeEpSetForShell;
|
||||
SEpSet mnodeEpSetForPeer;
|
||||
char file[PATH_MAX + 20];
|
||||
uint32_t rebootTime;
|
||||
int8_t dropped;
|
||||
int8_t threadStop;
|
||||
pthread_t *threadId;
|
||||
pthread_mutex_t mutex;
|
||||
} tsDnode = {0};
|
||||
|
||||
int32_t dnodeGetDnodeId() {
|
||||
int32_t dnodeId = 0;
|
||||
pthread_mutex_lock(&tsDnode.mutex);
|
||||
dnodeId = tsDnode.dnodeId;
|
||||
pthread_mutex_unlock(&tsDnode.mutex);
|
||||
return dnodeId;
|
||||
}
|
||||
|
||||
int64_t dnodeGetClusterId() {
|
||||
int64_t clusterId = 0;
|
||||
pthread_mutex_lock(&tsDnode.mutex);
|
||||
clusterId = tsDnode.clusterId;
|
||||
pthread_mutex_unlock(&tsDnode.mutex);
|
||||
return clusterId;
|
||||
}
|
||||
|
||||
void dnodeGetDnodeEp(int32_t dnodeId, char *ep, char *fqdn, uint16_t *port) {
|
||||
pthread_mutex_lock(&tsDnode.mutex);
|
||||
|
||||
SDnodeEp *pEp = taosHashGet(tsDnode.dnodeHash, &dnodeId, sizeof(int32_t));
|
||||
if (pEp != NULL) {
|
||||
if (port) *port = pEp->dnodePort;
|
||||
if (fqdn) tstrncpy(fqdn, pEp->dnodeFqdn, TSDB_FQDN_LEN);
|
||||
if (ep) snprintf(ep, TSDB_EP_LEN, "%s:%u", pEp->dnodeFqdn, pEp->dnodePort);
|
||||
}
|
||||
|
||||
pthread_mutex_unlock(&tsDnode.mutex);
|
||||
}
|
||||
|
||||
void dnodeGetMnodeEpSetForPeer(SEpSet *pEpSet) {
|
||||
pthread_mutex_lock(&tsDnode.mutex);
|
||||
*pEpSet = tsDnode.mnodeEpSetForPeer;
|
||||
pthread_mutex_unlock(&tsDnode.mutex);
|
||||
}
|
||||
|
||||
void dnodeGetMnodeEpSetForShell(SEpSet *pEpSet) {
|
||||
pthread_mutex_lock(&tsDnode.mutex);
|
||||
*pEpSet = tsDnode.mnodeEpSetForShell;
|
||||
pthread_mutex_unlock(&tsDnode.mutex);
|
||||
}
|
||||
|
||||
void dnodeSendRedirectMsg(SRpcMsg *pMsg, bool forShell) {
|
||||
int32_t msgType = pMsg->msgType;
|
||||
|
||||
SEpSet epSet = {0};
|
||||
if (forShell) {
|
||||
dnodeGetMnodeEpSetForShell(&epSet);
|
||||
} else {
|
||||
dnodeGetMnodeEpSetForPeer(&epSet);
|
||||
}
|
||||
|
||||
dDebug("RPC %p, msg:%s is redirected, num:%d use:%d", pMsg->handle, taosMsg[msgType], epSet.numOfEps, epSet.inUse);
|
||||
|
||||
for (int32_t i = 0; i < epSet.numOfEps; ++i) {
|
||||
dDebug("mnode index:%d %s:%u", i, epSet.fqdn[i], epSet.port[i]);
|
||||
if (strcmp(epSet.fqdn[i], tsLocalFqdn) == 0) {
|
||||
if ((epSet.port[i] == tsServerPort + TSDB_PORT_DNODEDNODE && !forShell) ||
|
||||
(epSet.port[i] == tsServerPort && forShell)) {
|
||||
epSet.inUse = (i + 1) % epSet.numOfEps;
|
||||
dDebug("mnode index:%d %s:%d set inUse to %d", i, epSet.fqdn[i], epSet.port[i], epSet.inUse);
|
||||
}
|
||||
}
|
||||
|
||||
epSet.port[i] = htons(epSet.port[i]);
|
||||
}
|
||||
|
||||
rpcSendRedirectRsp(pMsg->handle, &epSet);
|
||||
}
|
||||
|
||||
static void dnodeUpdateMnodeEpSet(SEpSet *pEpSet) {
|
||||
if (pEpSet == NULL || pEpSet->numOfEps <= 0) {
|
||||
dError("mnode is changed, but content is invalid, discard it");
|
||||
return;
|
||||
} else {
|
||||
dInfo("mnode is changed, num:%d use:%d", pEpSet->numOfEps, pEpSet->inUse);
|
||||
}
|
||||
|
||||
pthread_mutex_lock(&tsDnode.mutex);
|
||||
|
||||
tsDnode.mnodeEpSetForPeer = *pEpSet;
|
||||
for (int32_t i = 0; i < pEpSet->numOfEps; ++i) {
|
||||
pEpSet->port[i] -= TSDB_PORT_DNODEDNODE;
|
||||
dInfo("mnode index:%d %s:%u", i, pEpSet->fqdn[i], pEpSet->port[i]);
|
||||
}
|
||||
tsDnode.mnodeEpSetForShell = *pEpSet;
|
||||
|
||||
pthread_mutex_unlock(&tsDnode.mutex);
|
||||
}
|
||||
|
||||
static void dnodePrintDnodes() {
|
||||
dDebug("print dnode endpoint list, num:%d", tsDnode.dnodeEps->dnodeNum);
|
||||
for (int32_t i = 0; i < tsDnode.dnodeEps->dnodeNum; i++) {
|
||||
SDnodeEp *ep = &tsDnode.dnodeEps->dnodeEps[i];
|
||||
dDebug("dnode:%d, fqdn:%s port:%u isMnode:%d", ep->dnodeId, ep->dnodeFqdn, ep->dnodePort, ep->isMnode);
|
||||
}
|
||||
}
|
||||
|
||||
static void dnodeResetDnodes(SDnodeEps *pEps) {
|
||||
assert(pEps != NULL);
|
||||
int32_t size = sizeof(SDnodeEps) + pEps->dnodeNum * sizeof(SDnodeEp);
|
||||
|
||||
if (pEps->dnodeNum > tsDnode.dnodeEps->dnodeNum) {
|
||||
SDnodeEps *tmp = calloc(1, size);
|
||||
if (tmp == NULL) return;
|
||||
|
||||
tfree(tsDnode.dnodeEps);
|
||||
tsDnode.dnodeEps = tmp;
|
||||
}
|
||||
|
||||
if (tsDnode.dnodeEps != pEps) {
|
||||
memcpy(tsDnode.dnodeEps, pEps, size);
|
||||
}
|
||||
|
||||
tsDnode.mnodeEpSetForPeer.inUse = 0;
|
||||
tsDnode.mnodeEpSetForShell.inUse = 0;
|
||||
|
||||
int32_t mIndex = 0;
|
||||
for (int32_t i = 0; i < tsDnode.dnodeEps->dnodeNum; i++) {
|
||||
SDnodeEp *ep = &tsDnode.dnodeEps->dnodeEps[i];
|
||||
if (!ep->isMnode) continue;
|
||||
if (mIndex >= TSDB_MAX_REPLICA) continue;
|
||||
strcpy(tsDnode.mnodeEpSetForShell.fqdn[mIndex], ep->dnodeFqdn);
|
||||
strcpy(tsDnode.mnodeEpSetForPeer.fqdn[mIndex], ep->dnodeFqdn);
|
||||
tsDnode.mnodeEpSetForShell.port[mIndex] = ep->dnodePort;
|
||||
tsDnode.mnodeEpSetForShell.port[mIndex] = ep->dnodePort + tsDnodeDnodePort;
|
||||
mIndex++;
|
||||
}
|
||||
|
||||
for (int32_t i = 0; i < tsDnode.dnodeEps->dnodeNum; ++i) {
|
||||
SDnodeEp *ep = &tsDnode.dnodeEps->dnodeEps[i];
|
||||
taosHashPut(tsDnode.dnodeHash, &ep->dnodeId, sizeof(int32_t), ep, sizeof(SDnodeEp));
|
||||
}
|
||||
|
||||
dnodePrintDnodes();
|
||||
}
|
||||
|
||||
static bool dnodeIsEpChanged(int32_t dnodeId, char *epStr) {
|
||||
bool changed = false;
|
||||
pthread_mutex_lock(&tsDnode.mutex);
|
||||
|
||||
SDnodeEp *pEp = taosHashGet(tsDnode.dnodeHash, &dnodeId, sizeof(int32_t));
|
||||
if (pEp != NULL) {
|
||||
char epSaved[TSDB_EP_LEN + 1];
|
||||
snprintf(epSaved, TSDB_EP_LEN, "%s:%u", pEp->dnodeFqdn, pEp->dnodePort);
|
||||
changed = strcmp(epStr, epSaved) != 0;
|
||||
}
|
||||
|
||||
pthread_mutex_unlock(&tsDnode.mutex);
|
||||
return changed;
|
||||
}
|
||||
|
||||
static int32_t dnodeReadDnodes() {
|
||||
int32_t len = 0;
|
||||
int32_t maxLen = 30000;
|
||||
char *content = calloc(1, maxLen + 1);
|
||||
cJSON *root = NULL;
|
||||
FILE *fp = NULL;
|
||||
|
||||
fp = fopen(tsDnode.file, "r");
|
||||
if (!fp) {
|
||||
dDebug("file %s not exist", tsDnode.file);
|
||||
goto PRASE_DNODE_OVER;
|
||||
}
|
||||
|
||||
len = (int32_t)fread(content, 1, maxLen, fp);
|
||||
if (len <= 0) {
|
||||
dError("failed to read %s since content is null", tsDnode.file);
|
||||
goto PRASE_DNODE_OVER;
|
||||
}
|
||||
|
||||
content[len] = 0;
|
||||
root = cJSON_Parse(content);
|
||||
if (root == NULL) {
|
||||
dError("failed to read %s since invalid json format", tsDnode.file);
|
||||
goto PRASE_DNODE_OVER;
|
||||
}
|
||||
|
||||
cJSON *dnodeId = cJSON_GetObjectItem(root, "dnodeId");
|
||||
if (!dnodeId || dnodeId->type != cJSON_String) {
|
||||
dError("failed to read %s since dnodeId not found", tsDnode.file);
|
||||
goto PRASE_DNODE_OVER;
|
||||
}
|
||||
tsDnode.dnodeId = atoi(dnodeId->valuestring);
|
||||
|
||||
cJSON *clusterId = cJSON_GetObjectItem(root, "clusterId");
|
||||
if (!clusterId || clusterId->type != cJSON_String) {
|
||||
dError("failed to read %s since clusterId not found", tsDnode.file);
|
||||
goto PRASE_DNODE_OVER;
|
||||
}
|
||||
tsDnode.clusterId = atoll(clusterId->valuestring);
|
||||
|
||||
cJSON *dropped = cJSON_GetObjectItem(root, "dropped");
|
||||
if (!dropped || dropped->type != cJSON_String) {
|
||||
dError("failed to read %s since dropped not found", tsDnode.file);
|
||||
goto PRASE_DNODE_OVER;
|
||||
}
|
||||
tsDnode.dropped = atoi(dropped->valuestring);
|
||||
|
||||
cJSON *dnodeInfos = cJSON_GetObjectItem(root, "dnodeInfos");
|
||||
if (!dnodeInfos || dnodeInfos->type != cJSON_Array) {
|
||||
dError("failed to read %s since dnodeInfos not found", tsDnode.file);
|
||||
goto PRASE_DNODE_OVER;
|
||||
}
|
||||
|
||||
int32_t dnodeInfosSize = cJSON_GetArraySize(dnodeInfos);
|
||||
if (dnodeInfosSize <= 0) {
|
||||
dError("failed to read %s since dnodeInfos size:%d invalid", tsDnode.file, dnodeInfosSize);
|
||||
goto PRASE_DNODE_OVER;
|
||||
}
|
||||
|
||||
tsDnode.dnodeEps = calloc(1, dnodeInfosSize * sizeof(SDnodeEp) + sizeof(SDnodeEps));
|
||||
if (tsDnode.dnodeEps == NULL) {
|
||||
dError("failed to calloc dnodeEpList since %s", strerror(errno));
|
||||
goto PRASE_DNODE_OVER;
|
||||
}
|
||||
tsDnode.dnodeEps->dnodeNum = dnodeInfosSize;
|
||||
|
||||
for (int32_t i = 0; i < dnodeInfosSize; ++i) {
|
||||
cJSON *dnodeInfo = cJSON_GetArrayItem(dnodeInfos, i);
|
||||
if (dnodeInfo == NULL) break;
|
||||
|
||||
SDnodeEp *pEp = &tsDnode.dnodeEps->dnodeEps[i];
|
||||
|
||||
cJSON *dnodeId = cJSON_GetObjectItem(dnodeInfo, "dnodeId");
|
||||
if (!dnodeId || dnodeId->type != cJSON_String) {
|
||||
dError("failed to read %s, dnodeId not found", tsDnode.file);
|
||||
goto PRASE_DNODE_OVER;
|
||||
}
|
||||
pEp->dnodeId = atoi(dnodeId->valuestring);
|
||||
|
||||
cJSON *isMnode = cJSON_GetObjectItem(dnodeInfo, "isMnode");
|
||||
if (!isMnode || isMnode->type != cJSON_String) {
|
||||
dError("failed to read %s, isMnode not found", tsDnode.file);
|
||||
goto PRASE_DNODE_OVER;
|
||||
}
|
||||
pEp->isMnode = atoi(isMnode->valuestring);
|
||||
|
||||
cJSON *dnodeFqdn = cJSON_GetObjectItem(dnodeInfo, "dnodeFqdn");
|
||||
if (!dnodeFqdn || dnodeFqdn->type != cJSON_String || dnodeFqdn->valuestring == NULL) {
|
||||
dError("failed to read %s, dnodeFqdn not found", tsDnode.file);
|
||||
goto PRASE_DNODE_OVER;
|
||||
}
|
||||
tstrncpy(pEp->dnodeFqdn, dnodeFqdn->valuestring, TSDB_FQDN_LEN);
|
||||
|
||||
cJSON *dnodePort = cJSON_GetObjectItem(dnodeInfo, "dnodePort");
|
||||
if (!dnodePort || dnodePort->type != cJSON_String) {
|
||||
dError("failed to read %s, dnodePort not found", tsDnode.file);
|
||||
goto PRASE_DNODE_OVER;
|
||||
}
|
||||
pEp->dnodePort = atoi(dnodePort->valuestring);
|
||||
}
|
||||
|
||||
dInfo("succcessed to read file %s", tsDnode.file);
|
||||
dnodePrintDnodes();
|
||||
|
||||
PRASE_DNODE_OVER:
|
||||
if (content != NULL) free(content);
|
||||
if (root != NULL) cJSON_Delete(root);
|
||||
if (fp != NULL) fclose(fp);
|
||||
|
||||
if (dnodeIsEpChanged(tsDnode.dnodeId, tsLocalEp)) {
|
||||
dError("localEp %s different with %s and need reconfigured", tsLocalEp, tsDnode.file);
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (tsDnode.dnodeEps == NULL) {
|
||||
tsDnode.dnodeEps = calloc(1, sizeof(SDnodeEps) + sizeof(SDnodeEp));
|
||||
tsDnode.dnodeEps->dnodeNum = 1;
|
||||
tsDnode.dnodeEps->dnodeEps[0].dnodePort = tsServerPort;
|
||||
tstrncpy(tsDnode.dnodeEps->dnodeEps[0].dnodeFqdn, tsLocalFqdn, TSDB_FQDN_LEN);
|
||||
}
|
||||
|
||||
dnodeResetDnodes(tsDnode.dnodeEps);
|
||||
|
||||
terrno = 0;
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int32_t dnodeWriteDnodes() {
|
||||
FILE *fp = fopen(tsDnode.file, "w");
|
||||
if (!fp) {
|
||||
dError("failed to write %s since %s", tsDnode.file, strerror(errno));
|
||||
return -1;
|
||||
}
|
||||
|
||||
int32_t len = 0;
|
||||
int32_t maxLen = 30000;
|
||||
char *content = calloc(1, maxLen + 1);
|
||||
|
||||
len += snprintf(content + len, maxLen - len, "{\n");
|
||||
len += snprintf(content + len, maxLen - len, " \"dnodeId\": \"%d\",\n", tsDnode.dnodeId);
|
||||
len += snprintf(content + len, maxLen - len, " \"clusterId\": \"%" PRId64 "\",\n", tsDnode.clusterId);
|
||||
len += snprintf(content + len, maxLen - len, " \"dropped\": \"%d\",\n", tsDnode.dropped);
|
||||
len += snprintf(content + len, maxLen - len, " \"dnodeInfos\": [{\n");
|
||||
for (int32_t i = 0; i < tsDnode.dnodeEps->dnodeNum; ++i) {
|
||||
SDnodeEp *ep = &tsDnode.dnodeEps->dnodeEps[i];
|
||||
len += snprintf(content + len, maxLen - len, " \"dnodeId\": \"%d\",\n", ep->dnodeId);
|
||||
len += snprintf(content + len, maxLen - len, " \"isMnode\": \"%d\",\n", ep->isMnode);
|
||||
len += snprintf(content + len, maxLen - len, " \"dnodeFqdn\": \"%s\",\n", ep->dnodeFqdn);
|
||||
len += snprintf(content + len, maxLen - len, " \"dnodePort\": \"%u\"\n", ep->dnodePort);
|
||||
if (i < tsDnode.dnodeEps->dnodeNum - 1) {
|
||||
len += snprintf(content + len, maxLen - len, " },{\n");
|
||||
} else {
|
||||
len += snprintf(content + len, maxLen - len, " }]\n");
|
||||
}
|
||||
}
|
||||
len += snprintf(content + len, maxLen - len, "}\n");
|
||||
|
||||
fwrite(content, 1, len, fp);
|
||||
taosFsyncFile(fileno(fp));
|
||||
fclose(fp);
|
||||
free(content);
|
||||
terrno = 0;
|
||||
|
||||
dInfo("successed to write %s", tsDnode.file);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void dnodeSendStatusMsg() {
|
||||
int32_t contLen = sizeof(SStatusMsg) + TSDB_MAX_VNODES * sizeof(SVnodeLoad);
|
||||
|
||||
SStatusMsg *pStatus = rpcMallocCont(contLen);
|
||||
if (pStatus == NULL) {
|
||||
dError("failed to malloc status message");
|
||||
return;
|
||||
}
|
||||
|
||||
pStatus->sversion = htonl(tsVersion);
|
||||
pStatus->dnodeId = htonl(dnodeGetDnodeId());
|
||||
pStatus->clusterId = htobe64(dnodeGetClusterId());
|
||||
pStatus->rebootTime = htonl(tsDnode.rebootTime);
|
||||
pStatus->numOfCores = htonl(tsNumOfCores);
|
||||
tstrncpy(pStatus->dnodeEp, tsLocalEp, TSDB_EP_LEN);
|
||||
|
||||
pStatus->clusterCfg.statusInterval = htonl(tsStatusInterval);
|
||||
pStatus->clusterCfg.checkTime = 0;
|
||||
tstrncpy(pStatus->clusterCfg.timezone, tsTimezone, TSDB_TIMEZONE_LEN);
|
||||
tstrncpy(pStatus->clusterCfg.locale, tsLocale, TSDB_LOCALE_LEN);
|
||||
tstrncpy(pStatus->clusterCfg.charset, tsCharset, TSDB_LOCALE_LEN);
|
||||
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);
|
||||
|
||||
dnodeGetVnodeLoads(&pStatus->vnodeLoads);
|
||||
contLen = sizeof(SStatusMsg) + pStatus->vnodeLoads.num * sizeof(SVnodeLoad);
|
||||
|
||||
SRpcMsg rpcMsg = {.pCont = pStatus, .contLen = contLen, .msgType = TSDB_MSG_TYPE_STATUS};
|
||||
dnodeSendMsgToMnode(&rpcMsg);
|
||||
}
|
||||
|
||||
static void dnodeUpdateCfg(SDnodeCfg *pCfg) {
|
||||
if (tsDnode.dnodeId == 0) return;
|
||||
if (tsDnode.dropped) return;
|
||||
|
||||
pthread_mutex_lock(&tsDnode.mutex);
|
||||
|
||||
tsDnode.dnodeId = pCfg->dnodeId;
|
||||
tsDnode.clusterId = pCfg->clusterId;
|
||||
tsDnode.dropped = pCfg->dropped;
|
||||
dInfo("dnodeId is set to %d, clusterId is set to %" PRId64, pCfg->dnodeId, pCfg->clusterId);
|
||||
|
||||
dnodeWriteDnodes();
|
||||
pthread_mutex_unlock(&tsDnode.mutex);
|
||||
}
|
||||
|
||||
static void dnodeUpdateDnodeEps(SDnodeEps *pEps) {
|
||||
if (pEps == NULL || pEps->dnodeNum <= 0) return;
|
||||
|
||||
pthread_mutex_lock(&tsDnode.mutex);
|
||||
|
||||
if (pEps->dnodeNum != tsDnode.dnodeEps->dnodeNum) {
|
||||
dnodeResetDnodes(pEps);
|
||||
dnodeWriteDnodes();
|
||||
} else {
|
||||
int32_t size = pEps->dnodeNum * sizeof(SDnodeEp) + sizeof(SDnodeEps);
|
||||
if (memcmp(tsDnode.dnodeEps, pEps, size) != 0) {
|
||||
dnodeResetDnodes(pEps);
|
||||
dnodeWriteDnodes();
|
||||
}
|
||||
}
|
||||
|
||||
pthread_mutex_unlock(&tsDnode.mutex);
|
||||
}
|
||||
|
||||
static void dnodeProcessStatusRsp(SRpcMsg *pMsg) {
|
||||
if (pMsg->code != TSDB_CODE_SUCCESS) return;
|
||||
|
||||
SStatusRsp *pStatusRsp = pMsg->pCont;
|
||||
|
||||
SDnodeCfg *pCfg = &pStatusRsp->dnodeCfg;
|
||||
pCfg->dnodeId = htonl(pCfg->dnodeId);
|
||||
pCfg->clusterId = htobe64(pCfg->clusterId);
|
||||
dnodeUpdateCfg(pCfg);
|
||||
|
||||
if (pCfg->dropped) return;
|
||||
|
||||
SDnodeEps *pEps = &pStatusRsp->dnodeEps;
|
||||
pEps->dnodeNum = htonl(pEps->dnodeNum);
|
||||
for (int32_t i = 0; i < pEps->dnodeNum; ++i) {
|
||||
pEps->dnodeEps[i].dnodeId = htonl(pEps->dnodeEps[i].dnodeId);
|
||||
pEps->dnodeEps[i].dnodePort = htons(pEps->dnodeEps[i].dnodePort);
|
||||
}
|
||||
|
||||
dnodeUpdateDnodeEps(pEps);
|
||||
}
|
||||
|
||||
static void dnodeProcessConfigDnodeReq(SRpcMsg *pMsg) {
|
||||
SCfgDnodeMsg *pCfg = pMsg->pCont;
|
||||
|
||||
int32_t code = taosCfgDynamicOptions(pCfg->config);
|
||||
SRpcMsg rspMsg = {.handle = pMsg->handle, .pCont = NULL, .contLen = 0, .code = code};
|
||||
rpcSendResponse(&rspMsg);
|
||||
rpcFreeCont(pMsg->pCont);
|
||||
}
|
||||
|
||||
static void dnodeProcessStartupReq(SRpcMsg *pMsg) {
|
||||
dInfo("startup msg is received, cont:%s", (char *)pMsg->pCont);
|
||||
|
||||
SStartupMsg *pStartup = rpcMallocCont(sizeof(SStartupMsg));
|
||||
dnodeGetStartup(pStartup);
|
||||
|
||||
dInfo("startup msg is sent, step:%s desc:%s finished:%d", pStartup->name, pStartup->desc, pStartup->finished);
|
||||
|
||||
SRpcMsg rpcRsp = {.handle = pMsg->handle, .pCont = pStartup, .contLen = sizeof(SStartupMsg)};
|
||||
rpcSendResponse(&rpcRsp);
|
||||
rpcFreeCont(pMsg->pCont);
|
||||
}
|
||||
|
||||
static void *dnodeThreadRoutine(void *param) {
|
||||
int32_t ms = tsStatusInterval * 1000;
|
||||
|
||||
while (!tsDnode.threadStop) {
|
||||
if (dnodeGetRunStat() != DN_RUN_STAT_RUNNING) {
|
||||
continue;
|
||||
} else {
|
||||
dnodeSendStatusMsg();
|
||||
}
|
||||
taosMsleep(ms);
|
||||
}
|
||||
}
|
||||
|
||||
int32_t dnodeInitDnode() {
|
||||
tsDnode.dnodeId = 0;
|
||||
tsDnode.clusterId = 0;
|
||||
tsDnode.dnodeEps = NULL;
|
||||
snprintf(tsDnode.file, sizeof(tsDnode.file), "%s/dnode.json", tsDnodeDir);
|
||||
tsDnode.rebootTime = taosGetTimestampSec();
|
||||
tsDnode.dropped = 0;
|
||||
pthread_mutex_init(&tsDnode.mutex, NULL);
|
||||
tsDnode.threadStop = false;
|
||||
|
||||
tsDnode.dnodeHash = taosHashInit(4, taosGetDefaultHashFunction(TSDB_DATA_TYPE_INT), true, HASH_ENTRY_LOCK);
|
||||
if (tsDnode.dnodeHash == NULL) {
|
||||
dError("failed to init dnode hash");
|
||||
return TSDB_CODE_DND_OUT_OF_MEMORY;
|
||||
}
|
||||
|
||||
tsDnode.threadId = taosCreateThread(dnodeThreadRoutine, NULL);
|
||||
if (tsDnode.threadId == NULL) {
|
||||
dError("failed to init dnode thread");
|
||||
return TSDB_CODE_DND_OUT_OF_MEMORY;
|
||||
}
|
||||
|
||||
int32_t code = dnodeReadDnodes();
|
||||
if (code != 0) {
|
||||
dError("failed to read file:%s since %s", tsDnode.file, tstrerror(code));
|
||||
return code;
|
||||
}
|
||||
|
||||
dInfo("dnode-dnode is initialized");
|
||||
return 0;
|
||||
}
|
||||
|
||||
void dnodeCleanupDnode() {
|
||||
if (tsDnode.threadId != NULL) {
|
||||
tsDnode.threadStop = true;
|
||||
taosDestoryThread(tsDnode.threadId);
|
||||
tsDnode.threadId = NULL;
|
||||
}
|
||||
|
||||
pthread_mutex_lock(&tsDnode.mutex);
|
||||
|
||||
if (tsDnode.dnodeEps != NULL) {
|
||||
free(tsDnode.dnodeEps);
|
||||
tsDnode.dnodeEps = NULL;
|
||||
}
|
||||
|
||||
if (tsDnode.dnodeHash) {
|
||||
taosHashCleanup(tsDnode.dnodeHash);
|
||||
tsDnode.dnodeHash = NULL;
|
||||
}
|
||||
|
||||
pthread_mutex_unlock(&tsDnode.mutex);
|
||||
pthread_mutex_destroy(&tsDnode.mutex);
|
||||
|
||||
dInfo("dnode-dnode is cleaned up");
|
||||
}
|
||||
|
||||
void dnodeProcessDnodeMsg(SRpcMsg *pMsg, SEpSet *pEpSet) {
|
||||
int32_t msgType = pMsg->msgType;
|
||||
|
||||
if (msgType == TSDB_MSG_TYPE_STATUS_RSP && pEpSet) {
|
||||
dnodeUpdateMnodeEpSet(pEpSet);
|
||||
}
|
||||
|
||||
switch (msgType) {
|
||||
case TSDB_MSG_TYPE_NETWORK_TEST:
|
||||
dnodeProcessStartupReq(pMsg);
|
||||
break;
|
||||
case TSDB_MSG_TYPE_CONFIG_DNODE_IN:
|
||||
dnodeProcessConfigDnodeReq(pMsg);
|
||||
break;
|
||||
case TSDB_MSG_TYPE_STATUS_RSP:
|
||||
dnodeProcessStatusRsp(pMsg);
|
||||
break;
|
||||
default:
|
||||
dError("RPC %p, %s not processed", pMsg->handle, taosMsg[msgType]);
|
||||
SRpcMsg rspMsg = {.handle = pMsg->handle, .code = TSDB_CODE_DND_MSG_NOT_PROCESSED};
|
||||
rpcSendResponse(&rspMsg);
|
||||
rpcFreeCont(pMsg->pCont);
|
||||
}
|
||||
}
|
|
@ -1,177 +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 "dnodeDnode.h"
|
||||
#include "dnodeMnode.h"
|
||||
#include "dnodeTransport.h"
|
||||
#include "dnodeVnodes.h"
|
||||
#include "sync.h"
|
||||
#include "tcache.h"
|
||||
#include "tconfig.h"
|
||||
#include "tnote.h"
|
||||
#include "tstep.h"
|
||||
#include "wal.h"
|
||||
|
||||
static struct {
|
||||
SStartupMsg startup;
|
||||
EDnStat runStat;
|
||||
SSteps *steps;
|
||||
} tsInt;
|
||||
|
||||
EDnStat dnodeGetRunStat() { return tsInt.runStat; }
|
||||
|
||||
void dnodeSetRunStat(EDnStat stat) { tsInt.runStat = stat; }
|
||||
|
||||
void dnodeReportStartup(char *name, char *desc) {
|
||||
SStartupMsg *pStartup = &tsInt.startup;
|
||||
tstrncpy(pStartup->name, name, strlen(pStartup->name));
|
||||
tstrncpy(pStartup->desc, desc, strlen(pStartup->desc));
|
||||
pStartup->finished = 0;
|
||||
}
|
||||
|
||||
void dnodeReportStartupFinished(char *name, char *desc) {
|
||||
SStartupMsg *pStartup = &tsInt.startup;
|
||||
tstrncpy(pStartup->name, name, strlen(pStartup->name));
|
||||
tstrncpy(pStartup->desc, desc, strlen(pStartup->desc));
|
||||
pStartup->finished = 1;
|
||||
}
|
||||
|
||||
void dnodeGetStartup(SStartupMsg *pStartup) { memcpy(pStartup, &tsInt.startup, sizeof(SStartupMsg)); }
|
||||
|
||||
static int32_t dnodeCheckRunning(char *dir) {
|
||||
char filepath[256] = {0};
|
||||
snprintf(filepath, sizeof(filepath), "%s/.running", dir);
|
||||
|
||||
FileFd fd = taosOpenFileCreateWriteTrunc(filepath);
|
||||
if (fd < 0) {
|
||||
dError("failed to open lock file:%s since %s, quit", filepath, strerror(errno));
|
||||
return -1;
|
||||
}
|
||||
|
||||
int32_t ret = taosLockFile(fd);
|
||||
if (ret != 0) {
|
||||
dError("failed to lock file:%s since %s, quit", filepath, strerror(errno));
|
||||
taosCloseFile(fd);
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int32_t dnodeInitDir() {
|
||||
sprintf(tsMnodeDir, "%s/mnode", tsDataDir);
|
||||
sprintf(tsVnodeDir, "%s/vnode", tsDataDir);
|
||||
sprintf(tsDnodeDir, "%s/dnode", tsDataDir);
|
||||
|
||||
if (!taosMkDir(tsDnodeDir)) {
|
||||
dError("failed to create dir:%s since %s", tsDnodeDir, strerror(errno));
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (!taosMkDir(tsMnodeDir)) {
|
||||
dError("failed to create dir:%s since %s", tsMnodeDir, strerror(errno));
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (!taosMkDir(tsVnodeDir)) {
|
||||
dError("failed to create dir:%s since %s", tsVnodeDir, strerror(errno));
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (dnodeCheckRunning(tsDnodeDir) != 0) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int32_t dnodeInitMain() {
|
||||
tsInt.runStat = DN_RUN_STAT_STOPPED;
|
||||
tscEmbedded = 1;
|
||||
taosIgnSIGPIPE();
|
||||
taosBlockSIGPIPE();
|
||||
taosResolveCRC();
|
||||
taosInitGlobalCfg();
|
||||
taosReadGlobalLogCfg();
|
||||
taosSetCoreDump(tsEnableCoreFile);
|
||||
|
||||
if (!taosMkDir(tsLogDir)) {
|
||||
printf("failed to create dir: %s, reason: %s\n", tsLogDir, strerror(errno));
|
||||
return -1;
|
||||
}
|
||||
|
||||
char temp[TSDB_FILENAME_LEN];
|
||||
sprintf(temp, "%s/taosdlog", tsLogDir);
|
||||
if (taosInitLog(temp, tsNumOfLogLines, 1) < 0) {
|
||||
printf("failed to init log file\n");
|
||||
}
|
||||
|
||||
if (!taosReadGlobalCfg()) {
|
||||
taosPrintGlobalCfg();
|
||||
dError("TDengine read global config failed");
|
||||
return -1;
|
||||
}
|
||||
|
||||
dInfo("start to initialize TDengine");
|
||||
|
||||
taosInitNotes();
|
||||
|
||||
if (taosCheckGlobalCfg() != 0) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
dnodeInitDir();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void dnodeCleanupMain() {
|
||||
taos_cleanup();
|
||||
taosCloseLog();
|
||||
taosStopCacheRefreshWorker();
|
||||
}
|
||||
|
||||
int32_t dnodeInit() {
|
||||
SSteps *steps = taosStepInit(10, dnodeReportStartup);
|
||||
if (steps == NULL) return -1;
|
||||
|
||||
taosStepAdd(steps, "dnode-main", dnodeInitMain, dnodeCleanupMain);
|
||||
taosStepAdd(steps, "dnode-rpc", rpcInit, rpcCleanup);
|
||||
taosStepAdd(steps, "dnode-tfs", NULL, NULL);
|
||||
taosStepAdd(steps, "dnode-wal", walInit, walCleanUp);
|
||||
//taosStepAdd(steps, "dnode-sync", syncInit, syncCleanUp);
|
||||
taosStepAdd(steps, "dnode-dnode", dnodeInitDnode, dnodeCleanupDnode);
|
||||
taosStepAdd(steps, "dnode-vnodes", dnodeInitVnodes, dnodeCleanupVnodes);
|
||||
taosStepAdd(steps, "dnode-mnode", dnodeInitMnode, dnodeCleanupMnode);
|
||||
taosStepAdd(steps, "dnode-trans", dnodeInitTrans, dnodeCleanupTrans);
|
||||
|
||||
tsInt.steps = steps;
|
||||
taosStepExec(tsInt.steps);
|
||||
|
||||
dnodeSetRunStat(DN_RUN_STAT_RUNNING);
|
||||
dnodeReportStartupFinished("TDengine", "initialized successfully");
|
||||
dInfo("TDengine is initialized successfully");
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void dnodeCleanup() {
|
||||
if (dnodeGetRunStat() != DN_RUN_STAT_STOPPED) {
|
||||
dnodeSetRunStat(DN_RUN_STAT_STOPPED);
|
||||
taosStepCleanup(tsInt.steps);
|
||||
tsInt.steps = NULL;
|
||||
}
|
||||
}
|
|
@ -1,592 +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 "dnodeMnode.h"
|
||||
#include "cJSON.h"
|
||||
#include "dnodeDnode.h"
|
||||
#include "dnodeTransport.h"
|
||||
#include "mnode.h"
|
||||
#include "tlockfree.h"
|
||||
#include "tqueue.h"
|
||||
#include "tstep.h"
|
||||
#include "tworker.h"
|
||||
|
||||
static struct {
|
||||
int32_t refCount;
|
||||
int8_t deployed;
|
||||
int8_t dropped;
|
||||
SWorkerPool mgmtPool;
|
||||
SWorkerPool readPool;
|
||||
SWorkerPool writePool;
|
||||
SWorkerPool syncPool;
|
||||
taos_queue pReadQ;
|
||||
taos_queue pWriteQ;
|
||||
taos_queue pApplyQ;
|
||||
taos_queue pSyncQ;
|
||||
taos_queue pMgmtQ;
|
||||
SSteps *pSteps;
|
||||
SRWLatch latch;
|
||||
} tsMnode = {0};
|
||||
|
||||
static int32_t dnodeAllocMnodeReadQueue();
|
||||
static void dnodeFreeMnodeReadQueue();
|
||||
static int32_t dnodeAllocMnodeWriteQueue();
|
||||
static void dnodeFreeMnodeWriteQueue();
|
||||
static int32_t dnodeAllocMnodeApplyQueue();
|
||||
static void dnodeFreeMnodeApplyQueue();
|
||||
static int32_t dnodeAllocMnodeSyncQueue();
|
||||
static void dnodeFreeMnodeSyncQueue();
|
||||
|
||||
static int32_t dnodeAcquireMnode() {
|
||||
taosRLockLatch(&tsMnode.latch);
|
||||
|
||||
int32_t code = tsMnode.deployed ? 0 : TSDB_CODE_DND_MNODE_NOT_DEPLOYED;
|
||||
if (code == 0) {
|
||||
atomic_add_fetch_32(&tsMnode.refCount, 1);
|
||||
}
|
||||
|
||||
taosRUnLockLatch(&tsMnode.latch);
|
||||
return code;
|
||||
}
|
||||
|
||||
static void dnodeReleaseMnode() { atomic_sub_fetch_32(&tsMnode.refCount, 1); }
|
||||
|
||||
static int32_t dnodeReadMnodeFile() {
|
||||
int32_t code = TSDB_CODE_DND_READ_MNODE_FILE_ERROR;
|
||||
int32_t len = 0;
|
||||
int32_t maxLen = 300;
|
||||
char *content = calloc(1, maxLen + 1);
|
||||
cJSON *root = NULL;
|
||||
FILE *fp = NULL;
|
||||
char file[PATH_MAX + 20] = {0};
|
||||
|
||||
snprintf(file, sizeof(file), "%s/mnode.json", tsDnodeDir);
|
||||
fp = fopen(file, "r");
|
||||
if (!fp) {
|
||||
dDebug("file %s not exist", file);
|
||||
code = 0;
|
||||
goto PRASE_MNODE_OVER;
|
||||
}
|
||||
|
||||
len = (int32_t)fread(content, 1, maxLen, fp);
|
||||
if (len <= 0) {
|
||||
dError("failed to read %s since content is null", file);
|
||||
goto PRASE_MNODE_OVER;
|
||||
}
|
||||
|
||||
content[len] = 0;
|
||||
root = cJSON_Parse(content);
|
||||
if (root == NULL) {
|
||||
dError("failed to read %s since invalid json format", file);
|
||||
goto PRASE_MNODE_OVER;
|
||||
}
|
||||
|
||||
cJSON *deployed = cJSON_GetObjectItem(root, "deployed");
|
||||
if (!deployed || deployed->type != cJSON_String) {
|
||||
dError("failed to read %s since deployed not found", file);
|
||||
goto PRASE_MNODE_OVER;
|
||||
}
|
||||
tsMnode.deployed = atoi(deployed->valuestring);
|
||||
|
||||
cJSON *dropped = cJSON_GetObjectItem(root, "dropped");
|
||||
if (!dropped || dropped->type != cJSON_String) {
|
||||
dError("failed to read %s since dropped not found", file);
|
||||
goto PRASE_MNODE_OVER;
|
||||
}
|
||||
tsMnode.dropped = atoi(dropped->valuestring);
|
||||
|
||||
code = 0;
|
||||
dInfo("succcessed to read file %s", file);
|
||||
|
||||
PRASE_MNODE_OVER:
|
||||
if (content != NULL) free(content);
|
||||
if (root != NULL) cJSON_Delete(root);
|
||||
if (fp != NULL) fclose(fp);
|
||||
|
||||
return code;
|
||||
}
|
||||
|
||||
static int32_t dnodeWriteMnodeFile() {
|
||||
char file[PATH_MAX + 20] = {0};
|
||||
char realfile[PATH_MAX + 20] = {0};
|
||||
snprintf(file, sizeof(file), "%s/mnode.json.bak", tsDnodeDir);
|
||||
snprintf(realfile, sizeof(realfile), "%s/mnode.json", tsDnodeDir);
|
||||
|
||||
FILE *fp = fopen(file, "w");
|
||||
if (!fp) {
|
||||
dError("failed to write %s since %s", file, strerror(errno));
|
||||
return TSDB_CODE_DND_WRITE_MNODE_FILE_ERROR;
|
||||
}
|
||||
|
||||
int32_t len = 0;
|
||||
int32_t maxLen = 300;
|
||||
char *content = calloc(1, maxLen + 1);
|
||||
|
||||
len += snprintf(content + len, maxLen - len, "{\n");
|
||||
len += snprintf(content + len, maxLen - len, " \"deployed\": \"%d\",\n", tsMnode.deployed);
|
||||
len += snprintf(content + len, maxLen - len, " \"dropped\": \"%d\"\n", tsMnode.dropped);
|
||||
len += snprintf(content + len, maxLen - len, "}\n");
|
||||
|
||||
fwrite(content, 1, len, fp);
|
||||
taosFsyncFile(fileno(fp));
|
||||
fclose(fp);
|
||||
free(content);
|
||||
|
||||
int32_t code = taosRenameFile(file, realfile);
|
||||
if (code != 0) {
|
||||
dError("failed to rename %s since %s", file, tstrerror(code));
|
||||
return TSDB_CODE_DND_WRITE_MNODE_FILE_ERROR;
|
||||
}
|
||||
|
||||
dInfo("successed to write %s", realfile);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int32_t dnodeStartMnode() {
|
||||
int32_t code = dnodeAllocMnodeReadQueue();
|
||||
if (code != 0) {
|
||||
return code;
|
||||
}
|
||||
|
||||
code = dnodeAllocMnodeWriteQueue();
|
||||
if (code != 0) {
|
||||
return code;
|
||||
}
|
||||
|
||||
code = dnodeAllocMnodeApplyQueue();
|
||||
if (code != 0) {
|
||||
return code;
|
||||
}
|
||||
|
||||
code = dnodeAllocMnodeSyncQueue();
|
||||
if (code != 0) {
|
||||
return code;
|
||||
}
|
||||
|
||||
taosWLockLatch(&tsMnode.latch);
|
||||
tsMnode.deployed = 1;
|
||||
taosWUnLockLatch(&tsMnode.latch);
|
||||
|
||||
return mnodeStart(NULL);
|
||||
}
|
||||
|
||||
static void dnodeStopMnode() {
|
||||
taosWLockLatch(&tsMnode.latch);
|
||||
tsMnode.deployed = 0;
|
||||
taosWUnLockLatch(&tsMnode.latch);
|
||||
|
||||
dnodeReleaseMnode();
|
||||
|
||||
while (tsMnode.refCount > 0) taosMsleep(10);
|
||||
while (!taosQueueEmpty(tsMnode.pReadQ)) taosMsleep(10);
|
||||
while (!taosQueueEmpty(tsMnode.pApplyQ)) taosMsleep(10);
|
||||
while (!taosQueueEmpty(tsMnode.pWriteQ)) taosMsleep(10);
|
||||
while (!taosQueueEmpty(tsMnode.pSyncQ)) taosMsleep(10);
|
||||
|
||||
dnodeFreeMnodeReadQueue();
|
||||
dnodeFreeMnodeWriteQueue();
|
||||
dnodeFreeMnodeApplyQueue();
|
||||
dnodeFreeMnodeSyncQueue();
|
||||
}
|
||||
|
||||
static int32_t dnodeUnDeployMnode() {
|
||||
tsMnode.dropped = 1;
|
||||
int32_t code = dnodeWriteMnodeFile();
|
||||
if (code != 0) {
|
||||
tsMnode.dropped = 0;
|
||||
dError("failed to undeploy mnode since %s", tstrerror(code));
|
||||
return code;
|
||||
}
|
||||
|
||||
dnodeStopMnode();
|
||||
mnodeUnDeploy();
|
||||
dnodeWriteMnodeFile();
|
||||
|
||||
return code;
|
||||
}
|
||||
|
||||
static int32_t dnodeDeployMnode(SMnodeCfg *pCfg) {
|
||||
int32_t code = mnodeDeploy(pCfg);
|
||||
if (code != 0) {
|
||||
dError("failed to deploy mnode since %s", tstrerror(code));
|
||||
return code;
|
||||
}
|
||||
|
||||
code = dnodeStartMnode();
|
||||
if (code != 0) {
|
||||
dnodeUnDeployMnode();
|
||||
dError("failed to deploy mnode since %s", tstrerror(code));
|
||||
return code;
|
||||
}
|
||||
|
||||
code = dnodeWriteMnodeFile();
|
||||
if (code != 0) {
|
||||
dnodeUnDeployMnode();
|
||||
dError("failed to deploy mnode since %s", tstrerror(code));
|
||||
return code;
|
||||
}
|
||||
|
||||
dInfo("deploy mnode success");
|
||||
return code;
|
||||
}
|
||||
|
||||
static int32_t dnodeAlterMnode(SMnodeCfg *pCfg) {
|
||||
int32_t code = dnodeAcquireMnode();
|
||||
if (code == 0) {
|
||||
code = mnodeAlter(pCfg);
|
||||
dnodeReleaseMnode();
|
||||
}
|
||||
return code;
|
||||
}
|
||||
|
||||
static SCreateMnodeMsg *dnodeParseCreateMnodeMsg(SRpcMsg *pRpcMsg) {
|
||||
SCreateMnodeMsg *pMsg = pRpcMsg->pCont;
|
||||
pMsg->dnodeId = htonl(pMsg->dnodeId);
|
||||
for (int32_t i = 0; i < pMsg->replica; ++i) {
|
||||
pMsg->replicas[i].port = htons(pMsg->replicas[i].port);
|
||||
}
|
||||
return pMsg;
|
||||
}
|
||||
|
||||
static int32_t dnodeProcessCreateMnodeReq(SRpcMsg *pRpcMsg) {
|
||||
SAlterMnodeMsg *pMsg = (SAlterMnodeMsg *)dnodeParseCreateMnodeMsg(pRpcMsg->pCont);
|
||||
|
||||
if (pMsg->dnodeId != dnodeGetDnodeId()) {
|
||||
return TSDB_CODE_DND_MNODE_ID_NOT_MATCH_DNODE;
|
||||
} else {
|
||||
SMnodeCfg cfg = {0};
|
||||
cfg.replica = pMsg->replica;
|
||||
memcpy(cfg.replicas, pMsg->replicas, sizeof(SReplica) * sizeof(TSDB_MAX_REPLICA));
|
||||
return dnodeDeployMnode(&cfg);
|
||||
}
|
||||
}
|
||||
|
||||
static int32_t dnodeProcessAlterMnodeReq(SRpcMsg *pRpcMsg) {
|
||||
SAlterMnodeMsg *pMsg = (SAlterMnodeMsg *)dnodeParseCreateMnodeMsg(pRpcMsg->pCont);
|
||||
if (pMsg->dnodeId != dnodeGetDnodeId()) {
|
||||
return TSDB_CODE_DND_MNODE_ID_NOT_MATCH_DNODE;
|
||||
} else {
|
||||
SMnodeCfg cfg = {0};
|
||||
cfg.replica = pMsg->replica;
|
||||
memcpy(cfg.replicas, pMsg->replicas, sizeof(SReplica) * sizeof(TSDB_MAX_REPLICA));
|
||||
return dnodeAlterMnode(&cfg);
|
||||
}
|
||||
}
|
||||
|
||||
static int32_t dnodeProcessDropMnodeReq(SRpcMsg *pMsg) {
|
||||
SAlterMnodeMsg *pCfg = pMsg->pCont;
|
||||
pCfg->dnodeId = htonl(pCfg->dnodeId);
|
||||
|
||||
if (pCfg->dnodeId != dnodeGetDnodeId()) {
|
||||
return TSDB_CODE_DND_MNODE_ID_NOT_MATCH_DNODE;
|
||||
} else {
|
||||
return dnodeUnDeployMnode();
|
||||
}
|
||||
}
|
||||
|
||||
static void dnodeProcessMnodeMgmtQueue(void *unused, SRpcMsg *pMsg) {
|
||||
int32_t code = 0;
|
||||
|
||||
switch (pMsg->msgType) {
|
||||
case TSDB_MSG_TYPE_CREATE_MNODE_IN:
|
||||
code = dnodeProcessCreateMnodeReq(pMsg);
|
||||
break;
|
||||
case TSDB_MSG_TYPE_ALTER_MNODE_IN:
|
||||
code = dnodeProcessAlterMnodeReq(pMsg);
|
||||
break;
|
||||
case TSDB_MSG_TYPE_DROP_MNODE_IN:
|
||||
code = dnodeProcessDropMnodeReq(pMsg);
|
||||
break;
|
||||
default:
|
||||
code = TSDB_CODE_DND_MSG_NOT_PROCESSED;
|
||||
break;
|
||||
}
|
||||
|
||||
SRpcMsg rsp = {.code = code, .handle = pMsg->handle};
|
||||
rpcSendResponse(&rsp);
|
||||
rpcFreeCont(pMsg->pCont);
|
||||
taosFreeQitem(pMsg);
|
||||
}
|
||||
|
||||
static void dnodeProcessMnodeReadQueue(void *unused, SMnodeMsg *pMsg) { mnodeProcessMsg(pMsg, MN_MSG_TYPE_READ); }
|
||||
|
||||
static void dnodeProcessMnodeWriteQueue(void *unused, SMnodeMsg *pMsg) { mnodeProcessMsg(pMsg, MN_MSG_TYPE_WRITE); }
|
||||
|
||||
static void dnodeProcessMnodeApplyQueue(void *unused, SMnodeMsg *pMsg) { mnodeProcessMsg(pMsg, MN_MSG_TYPE_APPLY); }
|
||||
|
||||
static void dnodeProcessMnodeSyncQueue(void *unused, SMnodeMsg *pMsg) { mnodeProcessMsg(pMsg, MN_MSG_TYPE_SYNC); }
|
||||
|
||||
static int32_t dnodeWriteMnodeMsgToQueue(taos_queue pQueue, SRpcMsg *pRpcMsg) {
|
||||
int32_t code = 0;
|
||||
|
||||
if (pQueue == NULL) {
|
||||
code = TSDB_CODE_DND_MSG_NOT_PROCESSED;
|
||||
} else {
|
||||
SMnodeMsg *pMsg = mnodeInitMsg(pRpcMsg);
|
||||
if (pMsg == NULL) {
|
||||
code = terrno;
|
||||
}
|
||||
}
|
||||
|
||||
if (code != TSDB_CODE_SUCCESS) {
|
||||
SRpcMsg rsp = {.handle = pRpcMsg->handle, .code = code};
|
||||
rpcSendResponse(&rsp);
|
||||
rpcFreeCont(pRpcMsg->pCont);
|
||||
}
|
||||
}
|
||||
|
||||
void dnodeProcessMnodeMgmtMsg(SRpcMsg *pMsg, SEpSet *pEpSet) { dnodeWriteMnodeMsgToQueue(tsMnode.pMgmtQ, pMsg); }
|
||||
|
||||
void dnodeProcessMnodeWriteMsg(SRpcMsg *pMsg, SEpSet *pEpSet) {
|
||||
if (dnodeAcquireMnode() == 0) {
|
||||
dnodeWriteMnodeMsgToQueue(tsMnode.pWriteQ, pMsg);
|
||||
dnodeReleaseMnode();
|
||||
} else {
|
||||
dnodeSendRedirectMsg(pMsg, 0);
|
||||
}
|
||||
}
|
||||
|
||||
void dnodeProcessMnodeSyncMsg(SRpcMsg *pMsg, SEpSet *pEpSet) {
|
||||
int32_t code = dnodeAcquireMnode();
|
||||
if (code == 0) {
|
||||
dnodeWriteMnodeMsgToQueue(tsMnode.pSyncQ, pMsg);
|
||||
dnodeReleaseMnode();
|
||||
} else {
|
||||
SRpcMsg rsp = {.handle = pMsg->handle, .code = code};
|
||||
rpcSendResponse(&rsp);
|
||||
rpcFreeCont(pMsg->pCont);
|
||||
}
|
||||
}
|
||||
|
||||
void dnodeProcessMnodeReadMsg(SRpcMsg *pMsg, SEpSet *pEpSet) {
|
||||
if (dnodeAcquireMnode() == 0) {
|
||||
dnodeWriteMnodeMsgToQueue(tsMnode.pReadQ, pMsg);
|
||||
dnodeReleaseMnode();
|
||||
} else {
|
||||
dnodeSendRedirectMsg(pMsg, 0);
|
||||
}
|
||||
}
|
||||
|
||||
static int32_t dnodePutMsgIntoMnodeApplyQueue(SMnodeMsg *pMsg) {
|
||||
int32_t code = dnodeAcquireMnode();
|
||||
if (code != 0) return code;
|
||||
|
||||
code = taosWriteQitem(tsMnode.pApplyQ, pMsg);
|
||||
dnodeReleaseMnode();
|
||||
return code;
|
||||
}
|
||||
|
||||
static int32_t dnodeAllocMnodeMgmtQueue() {
|
||||
tsMnode.pMgmtQ = tWorkerAllocQueue(&tsMnode.mgmtPool, NULL, (FProcessItem)dnodeProcessMnodeMgmtQueue);
|
||||
if (tsMnode.pMgmtQ == NULL) {
|
||||
return TSDB_CODE_DND_OUT_OF_MEMORY;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void dnodeFreeMnodeMgmtQueue() {
|
||||
tWorkerFreeQueue(&tsMnode.mgmtPool, tsMnode.pMgmtQ);
|
||||
tsMnode.pMgmtQ = NULL;
|
||||
}
|
||||
|
||||
static int32_t dnodeInitMnodeMgmtWorker() {
|
||||
SWorkerPool *pPool = &tsMnode.mgmtPool;
|
||||
pPool->name = "mnode-mgmt";
|
||||
pPool->min = 1;
|
||||
pPool->max = 1;
|
||||
return tWorkerInit(pPool);
|
||||
}
|
||||
|
||||
static void dnodeCleanupMnodeMgmtWorker() { tWorkerCleanup(&tsMnode.mgmtPool); }
|
||||
|
||||
static int32_t dnodeAllocMnodeReadQueue() {
|
||||
tsMnode.pReadQ = tWorkerAllocQueue(&tsMnode.readPool, NULL, (FProcessItem)dnodeProcessMnodeReadQueue);
|
||||
if (tsMnode.pReadQ == NULL) {
|
||||
return TSDB_CODE_DND_OUT_OF_MEMORY;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void dnodeFreeMnodeReadQueue() {
|
||||
tWorkerFreeQueue(&tsMnode.readPool, tsMnode.pReadQ);
|
||||
tsMnode.pReadQ = NULL;
|
||||
}
|
||||
|
||||
static int32_t dnodeInitMnodeReadWorker() {
|
||||
SWorkerPool *pPool = &tsMnode.readPool;
|
||||
pPool->name = "mnode-read";
|
||||
pPool->min = 0;
|
||||
pPool->max = 1;
|
||||
return tWorkerInit(pPool);
|
||||
}
|
||||
|
||||
static void dnodeCleanupMnodeReadWorker() { tWorkerCleanup(&tsMnode.readPool); }
|
||||
|
||||
static int32_t dnodeAllocMnodeWriteQueue() {
|
||||
tsMnode.pWriteQ = tWorkerAllocQueue(&tsMnode.writePool, NULL, (FProcessItem)dnodeProcessMnodeWriteQueue);
|
||||
if (tsMnode.pWriteQ == NULL) {
|
||||
return TSDB_CODE_DND_OUT_OF_MEMORY;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void dnodeFreeMnodeWriteQueue() {
|
||||
tWorkerFreeQueue(&tsMnode.writePool, tsMnode.pWriteQ);
|
||||
tsMnode.pWriteQ = NULL;
|
||||
}
|
||||
|
||||
static int32_t dnodeAllocMnodeApplyQueue() {
|
||||
tsMnode.pApplyQ = tWorkerAllocQueue(&tsMnode.writePool, NULL, (FProcessItem)dnodeProcessMnodeApplyQueue);
|
||||
if (tsMnode.pApplyQ == NULL) {
|
||||
return TSDB_CODE_DND_OUT_OF_MEMORY;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void dnodeFreeMnodeApplyQueue() {
|
||||
tWorkerFreeQueue(&tsMnode.writePool, tsMnode.pApplyQ);
|
||||
tsMnode.pApplyQ = NULL;
|
||||
}
|
||||
|
||||
static int32_t dnodeInitMnodeWriteWorker() {
|
||||
SWorkerPool *pPool = &tsMnode.writePool;
|
||||
pPool->name = "mnode-write";
|
||||
pPool->min = 0;
|
||||
pPool->max = 1;
|
||||
return tWorkerInit(pPool);
|
||||
}
|
||||
|
||||
static void dnodeCleanupMnodeWriteWorker() { tWorkerCleanup(&tsMnode.writePool); }
|
||||
|
||||
static int32_t dnodeAllocMnodeSyncQueue() {
|
||||
tsMnode.pSyncQ = tWorkerAllocQueue(&tsMnode.syncPool, NULL, (FProcessItem)dnodeProcessMnodeSyncQueue);
|
||||
if (tsMnode.pSyncQ == NULL) {
|
||||
return TSDB_CODE_DND_OUT_OF_MEMORY;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void dnodeFreeMnodeSyncQueue() {
|
||||
tWorkerFreeQueue(&tsMnode.syncPool, tsMnode.pSyncQ);
|
||||
tsMnode.pSyncQ = NULL;
|
||||
}
|
||||
|
||||
static int32_t dnodeInitMnodeSyncWorker() {
|
||||
SWorkerPool *pPool = &tsMnode.syncPool;
|
||||
pPool->name = "mnode-sync";
|
||||
pPool->min = 0;
|
||||
pPool->max = 1;
|
||||
return tWorkerInit(pPool);
|
||||
}
|
||||
|
||||
static void dnodeCleanupMnodeSyncWorker() { tWorkerCleanup(&tsMnode.syncPool); }
|
||||
|
||||
static int32_t dnodeInitMnodeModule() {
|
||||
taosInitRWLatch(&tsMnode.latch);
|
||||
|
||||
SMnodePara para;
|
||||
para.dnodeId = dnodeGetDnodeId();
|
||||
para.clusterId = dnodeGetClusterId();
|
||||
para.SendMsgToDnode = dnodeSendMsgToDnode;
|
||||
para.SendMsgToMnode = dnodeSendMsgToMnode;
|
||||
para.SendRedirectMsg = dnodeSendRedirectMsg;
|
||||
|
||||
return mnodeInit(para);
|
||||
}
|
||||
|
||||
static void dnodeCleanupMnodeModule() { mnodeCleanup(); }
|
||||
|
||||
static bool dnodeNeedDeployMnode() {
|
||||
if (dnodeGetDnodeId() > 0) return false;
|
||||
if (dnodeGetClusterId() > 0) return false;
|
||||
if (strcmp(tsFirst, tsLocalEp) != 0) return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
static int32_t dnodeOpenMnode() {
|
||||
int32_t code = dnodeReadMnodeFile();
|
||||
if (code != 0) {
|
||||
dError("failed to read open mnode since %s", tstrerror(code));
|
||||
return code;
|
||||
}
|
||||
|
||||
if (tsMnode.dropped) {
|
||||
dInfo("mnode already dropped, undeploy it");
|
||||
return dnodeUnDeployMnode();
|
||||
}
|
||||
|
||||
if (!tsMnode.deployed) {
|
||||
bool needDeploy = dnodeNeedDeployMnode();
|
||||
if (!needDeploy) return 0;
|
||||
|
||||
dInfo("start to deploy mnode");
|
||||
SMnodeCfg cfg = {.replica = 1};
|
||||
cfg.replicas[0].port = tsServerPort;
|
||||
tstrncpy(cfg.replicas[0].fqdn, tsLocalFqdn, TSDB_FQDN_LEN);
|
||||
code = dnodeDeployMnode(&cfg);
|
||||
} else {
|
||||
dInfo("start to open mnode");
|
||||
return dnodeStartMnode();
|
||||
}
|
||||
}
|
||||
|
||||
static void dnodeCloseMnode() {
|
||||
if (dnodeAcquireMnode() == 0) {
|
||||
dnodeStopMnode();
|
||||
}
|
||||
}
|
||||
|
||||
int32_t dnodeInitMnode() {
|
||||
dInfo("dnode-mnode start to init");
|
||||
|
||||
SSteps *pSteps = taosStepInit(6, dnodeReportStartup);
|
||||
taosStepAdd(pSteps, "dnode-mnode-env", dnodeInitMnodeModule, dnodeCleanupMnodeModule);
|
||||
taosStepAdd(pSteps, "dnode-mnode-mgmt", dnodeInitMnodeMgmtWorker, dnodeCleanupMnodeMgmtWorker);
|
||||
taosStepAdd(pSteps, "dnode-mnode-read", dnodeInitMnodeReadWorker, dnodeCleanupMnodeReadWorker);
|
||||
taosStepAdd(pSteps, "dnode-mnode-write", dnodeInitMnodeWriteWorker, dnodeCleanupMnodeWriteWorker);
|
||||
taosStepAdd(pSteps, "dnode-mnode-sync", dnodeInitMnodeSyncWorker, dnodeCleanupMnodeSyncWorker);
|
||||
taosStepAdd(pSteps, "dnode-mnode", dnodeOpenMnode, dnodeCloseMnode);
|
||||
|
||||
tsMnode.pSteps = pSteps;
|
||||
int32_t code = taosStepExec(pSteps);
|
||||
|
||||
if (code != 0) {
|
||||
dError("dnode-mnode init failed since %s", tstrerror(code));
|
||||
} else {
|
||||
dInfo("dnode-mnode is initialized");
|
||||
}
|
||||
}
|
||||
|
||||
void dnodeCleanupMnode() {
|
||||
if (tsMnode.pSteps == NULL) {
|
||||
dInfo("dnode-mnode start to clean up");
|
||||
taosStepCleanup(tsMnode.pSteps);
|
||||
tsMnode.pSteps = NULL;
|
||||
dInfo("dnode-mnode is cleaned up");
|
||||
}
|
||||
}
|
||||
|
||||
int32_t dnodeGetUserAuthFromMnode(char *user, char *spi, char *encrypt, char *secret, char *ckey) {
|
||||
int32_t code = dnodeAcquireMnode();
|
||||
if (code != 0) {
|
||||
dTrace("failed to get user auth since mnode not deployed");
|
||||
return code;
|
||||
}
|
||||
|
||||
code = mnodeRetriveAuth(user, spi, encrypt, secret, ckey);
|
||||
dnodeReleaseMnode();
|
||||
return code;
|
||||
}
|
|
@ -1,378 +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/>.
|
||||
*/
|
||||
|
||||
/* this file is mainly responsible for the communication between DNODEs. Each
|
||||
* dnode works as both server and client. Dnode may send status, grant, config
|
||||
* messages to mnode, mnode may send create/alter/drop table/vnode messages
|
||||
* to dnode. All theses messages are handled from here
|
||||
*/
|
||||
|
||||
#define _DEFAULT_SOURCE
|
||||
#include "dnodeTransport.h"
|
||||
#include "dnodeDnode.h"
|
||||
#include "dnodeMnode.h"
|
||||
#include "dnodeVnodes.h"
|
||||
|
||||
static struct {
|
||||
void *peerRpc;
|
||||
void *shellRpc;
|
||||
void *clientRpc;
|
||||
MsgFp msgFp[TSDB_MSG_TYPE_MAX];
|
||||
} tsTrans;
|
||||
|
||||
static void dnodeInitMsgFp() {
|
||||
// msg from client to dnode
|
||||
tsTrans.msgFp[TSDB_MSG_TYPE_SUBMIT] = dnodeProcessVnodeWriteMsg;
|
||||
tsTrans.msgFp[TSDB_MSG_TYPE_QUERY] = dnodeProcessVnodeQueryMsg;
|
||||
tsTrans.msgFp[TSDB_MSG_TYPE_FETCH] = dnodeProcessVnodeFetchMsg;
|
||||
tsTrans.msgFp[TSDB_MSG_TYPE_CREATE_TABLE] = dnodeProcessVnodeWriteMsg;
|
||||
tsTrans.msgFp[TSDB_MSG_TYPE_DROP_TABLE] = dnodeProcessVnodeWriteMsg;
|
||||
tsTrans.msgFp[TSDB_MSG_TYPE_ALTER_TABLE] = dnodeProcessVnodeWriteMsg;
|
||||
tsTrans.msgFp[TSDB_MSG_TYPE_UPDATE_TAG_VAL] = dnodeProcessVnodeWriteMsg;
|
||||
tsTrans.msgFp[TSDB_MSG_TYPE_TABLE_META] = dnodeProcessVnodeQueryMsg;
|
||||
tsTrans.msgFp[TSDB_MSG_TYPE_TABLES_META] = dnodeProcessVnodeQueryMsg;
|
||||
tsTrans.msgFp[TSDB_MSG_TYPE_MQ_QUERY] = dnodeProcessVnodeQueryMsg;
|
||||
tsTrans.msgFp[TSDB_MSG_TYPE_MQ_CONSUME] = dnodeProcessVnodeQueryMsg;
|
||||
tsTrans.msgFp[TSDB_MSG_TYPE_MQ_CONNECT] = dnodeProcessVnodeWriteMsg;
|
||||
tsTrans.msgFp[TSDB_MSG_TYPE_MQ_DISCONNECT] = dnodeProcessVnodeWriteMsg;
|
||||
tsTrans.msgFp[TSDB_MSG_TYPE_MQ_ACK] = dnodeProcessVnodeWriteMsg;
|
||||
tsTrans.msgFp[TSDB_MSG_TYPE_MQ_RESET] = dnodeProcessVnodeWriteMsg;
|
||||
|
||||
// msg from client to mnode
|
||||
tsTrans.msgFp[TSDB_MSG_TYPE_CONNECT] = dnodeProcessMnodeReadMsg;
|
||||
tsTrans.msgFp[TSDB_MSG_TYPE_CREATE_ACCT] = dnodeProcessMnodeWriteMsg;
|
||||
tsTrans.msgFp[TSDB_MSG_TYPE_ALTER_ACCT] = dnodeProcessMnodeWriteMsg;
|
||||
tsTrans.msgFp[TSDB_MSG_TYPE_DROP_ACCT] = dnodeProcessMnodeWriteMsg;
|
||||
tsTrans.msgFp[TSDB_MSG_TYPE_CREATE_USER] = dnodeProcessMnodeWriteMsg;
|
||||
tsTrans.msgFp[TSDB_MSG_TYPE_ALTER_USER] = dnodeProcessMnodeWriteMsg;
|
||||
tsTrans.msgFp[TSDB_MSG_TYPE_DROP_USER] = dnodeProcessMnodeWriteMsg;
|
||||
tsTrans.msgFp[TSDB_MSG_TYPE_CREATE_DNODE] = dnodeProcessMnodeWriteMsg;
|
||||
tsTrans.msgFp[TSDB_MSG_TYPE_CONFIG_DNODE] = dnodeProcessMnodeWriteMsg;
|
||||
tsTrans.msgFp[TSDB_MSG_TYPE_DROP_DNODE] = dnodeProcessMnodeWriteMsg;
|
||||
tsTrans.msgFp[TSDB_MSG_TYPE_CREATE_DB] = dnodeProcessMnodeWriteMsg;
|
||||
tsTrans.msgFp[TSDB_MSG_TYPE_DROP_DB] = dnodeProcessMnodeWriteMsg;
|
||||
tsTrans.msgFp[TSDB_MSG_TYPE_USE_DB] = dnodeProcessMnodeWriteMsg;
|
||||
tsTrans.msgFp[TSDB_MSG_TYPE_ALTER_DB] = dnodeProcessMnodeWriteMsg;
|
||||
tsTrans.msgFp[TSDB_MSG_TYPE_SYNC_DB] = dnodeProcessMnodeWriteMsg;
|
||||
tsTrans.msgFp[TSDB_MSG_TYPE_CREATE_TOPIC] = dnodeProcessMnodeWriteMsg;
|
||||
tsTrans.msgFp[TSDB_MSG_TYPE_DROP_TOPIC] = dnodeProcessMnodeWriteMsg;
|
||||
tsTrans.msgFp[TSDB_MSG_TYPE_ALTER_TOPIC] = dnodeProcessMnodeWriteMsg;
|
||||
tsTrans.msgFp[TSDB_MSG_TYPE_CREATE_FUNCTION] = dnodeProcessMnodeWriteMsg;
|
||||
tsTrans.msgFp[TSDB_MSG_TYPE_ALTER_FUNCTION] = dnodeProcessMnodeWriteMsg;
|
||||
tsTrans.msgFp[TSDB_MSG_TYPE_DROP_FUNCTION] = dnodeProcessMnodeWriteMsg;
|
||||
tsTrans.msgFp[TSDB_MSG_TYPE_CREATE_STABLE] = dnodeProcessMnodeWriteMsg;
|
||||
tsTrans.msgFp[TSDB_MSG_TYPE_ALTER_STABLE] = dnodeProcessMnodeWriteMsg;
|
||||
tsTrans.msgFp[TSDB_MSG_TYPE_DROP_STABLE] = dnodeProcessMnodeWriteMsg;
|
||||
tsTrans.msgFp[TSDB_MSG_TYPE_STABLE_VGROUP] = dnodeProcessMnodeReadMsg;
|
||||
tsTrans.msgFp[TSDB_MSG_TYPE_KILL_QUERY] = dnodeProcessMnodeWriteMsg;
|
||||
tsTrans.msgFp[TSDB_MSG_TYPE_KILL_CONN] = dnodeProcessMnodeWriteMsg;
|
||||
tsTrans.msgFp[TSDB_MSG_TYPE_HEARTBEAT] = dnodeProcessMnodeReadMsg;
|
||||
tsTrans.msgFp[TSDB_MSG_TYPE_SHOW] = dnodeProcessMnodeReadMsg;
|
||||
tsTrans.msgFp[TSDB_MSG_TYPE_SHOW_RETRIEVE] = dnodeProcessMnodeReadMsg;
|
||||
tsTrans.msgFp[TSDB_MSG_TYPE_SHOW_RETRIEVE_FUNC] = dnodeProcessMnodeReadMsg;
|
||||
tsTrans.msgFp[TSDB_MSG_TYPE_COMPACT_VNODE] = dnodeProcessMnodeWriteMsg;
|
||||
|
||||
// message from client to dnode
|
||||
tsTrans.msgFp[TSDB_MSG_TYPE_NETWORK_TEST] = dnodeProcessDnodeMsg;
|
||||
|
||||
// message from mnode to vnode
|
||||
tsTrans.msgFp[TSDB_MSG_TYPE_CREATE_STABLE_IN] = dnodeProcessVnodeWriteMsg;
|
||||
tsTrans.msgFp[TSDB_MSG_TYPE_CREATE_STABLE_IN_RSP] = dnodeProcessMnodeWriteMsg;
|
||||
tsTrans.msgFp[TSDB_MSG_TYPE_ALTER_STABLE_IN] = dnodeProcessVnodeWriteMsg;
|
||||
tsTrans.msgFp[TSDB_MSG_TYPE_ALTER_STABLE_IN_RSP] = dnodeProcessMnodeWriteMsg;
|
||||
tsTrans.msgFp[TSDB_MSG_TYPE_DROP_STABLE_IN] = dnodeProcessVnodeWriteMsg;
|
||||
tsTrans.msgFp[TSDB_MSG_TYPE_DROP_STABLE_IN] = dnodeProcessMnodeWriteMsg;
|
||||
|
||||
// message from mnode to dnode
|
||||
tsTrans.msgFp[TSDB_MSG_TYPE_CREATE_VNODE_IN] = dnodeProcessVnodeMgmtMsg;
|
||||
tsTrans.msgFp[TSDB_MSG_TYPE_CREATE_VNODE_IN_RSP] = dnodeProcessMnodeWriteMsg;
|
||||
tsTrans.msgFp[TSDB_MSG_TYPE_ALTER_VNODE_IN] = dnodeProcessVnodeMgmtMsg;
|
||||
tsTrans.msgFp[TSDB_MSG_TYPE_ALTER_VNODE_IN_RSP] = dnodeProcessMnodeWriteMsg;
|
||||
tsTrans.msgFp[TSDB_MSG_TYPE_DROP_VNODE_IN] = dnodeProcessVnodeMgmtMsg;
|
||||
tsTrans.msgFp[TSDB_MSG_TYPE_DROP_VNODE_IN_RSP] = dnodeProcessMnodeWriteMsg;
|
||||
tsTrans.msgFp[TSDB_MSG_TYPE_SYNC_VNODE_IN] = dnodeProcessVnodeMgmtMsg;
|
||||
tsTrans.msgFp[TSDB_MSG_TYPE_SYNC_VNODE_IN_RSP] = dnodeProcessMnodeWriteMsg;
|
||||
tsTrans.msgFp[TSDB_MSG_TYPE_AUTH_VNODE_IN] = dnodeProcessVnodeMgmtMsg;
|
||||
tsTrans.msgFp[TSDB_MSG_TYPE_AUTH_VNODE_IN_RSP] = dnodeProcessMnodeWriteMsg;
|
||||
tsTrans.msgFp[TSDB_MSG_TYPE_COMPACT_VNODE_IN] = dnodeProcessVnodeMgmtMsg;
|
||||
tsTrans.msgFp[TSDB_MSG_TYPE_COMPACT_VNODE_IN_RSP] = dnodeProcessMnodeWriteMsg;
|
||||
tsTrans.msgFp[TSDB_MSG_TYPE_CREATE_MNODE_IN] = dnodeProcessMnodeMgmtMsg;
|
||||
tsTrans.msgFp[TSDB_MSG_TYPE_CREATE_MNODE_IN_RSP] = dnodeProcessMnodeWriteMsg;
|
||||
tsTrans.msgFp[TSDB_MSG_TYPE_ALTER_MNODE_IN] = dnodeProcessMnodeMgmtMsg;
|
||||
tsTrans.msgFp[TSDB_MSG_TYPE_ALTER_MNODE_IN_RSP] = dnodeProcessMnodeWriteMsg;
|
||||
tsTrans.msgFp[TSDB_MSG_TYPE_DROP_MNODE_IN] = dnodeProcessMnodeMgmtMsg;
|
||||
tsTrans.msgFp[TSDB_MSG_TYPE_DROP_MNODE_IN_RSP] = dnodeProcessMnodeWriteMsg;
|
||||
tsTrans.msgFp[TSDB_MSG_TYPE_CONFIG_DNODE_IN] = dnodeProcessDnodeMsg;
|
||||
tsTrans.msgFp[TSDB_MSG_TYPE_CONFIG_DNODE_IN_RSP] = dnodeProcessMnodeWriteMsg;
|
||||
|
||||
// message from dnode to mnode
|
||||
tsTrans.msgFp[TSDB_MSG_TYPE_AUTH] = dnodeProcessMnodeReadMsg;
|
||||
tsTrans.msgFp[TSDB_MSG_TYPE_AUTH_RSP] = dnodeProcessDnodeMsg;
|
||||
tsTrans.msgFp[TSDB_MSG_TYPE_GRANT] = dnodeProcessMnodeWriteMsg;
|
||||
tsTrans.msgFp[TSDB_MSG_TYPE_GRANT_RSP] = dnodeProcessDnodeMsg;
|
||||
tsTrans.msgFp[TSDB_MSG_TYPE_STATUS] = dnodeProcessMnodeWriteMsg;
|
||||
tsTrans.msgFp[TSDB_MSG_TYPE_STATUS_RSP] = dnodeProcessDnodeMsg;
|
||||
}
|
||||
|
||||
static void dnodeProcessPeerReq(SRpcMsg *pMsg, SEpSet *pEpSet) {
|
||||
SRpcMsg rspMsg = {.handle = pMsg->handle};
|
||||
int32_t msgType = pMsg->msgType;
|
||||
|
||||
if (msgType == TSDB_MSG_TYPE_NETWORK_TEST) {
|
||||
dnodeProcessDnodeMsg(pMsg, pEpSet);
|
||||
return;
|
||||
}
|
||||
|
||||
if (dnodeGetRunStat() != DN_RUN_STAT_RUNNING) {
|
||||
rspMsg.code = TSDB_CODE_APP_NOT_READY;
|
||||
rpcSendResponse(&rspMsg);
|
||||
rpcFreeCont(pMsg->pCont);
|
||||
dTrace("RPC %p, peer req:%s is ignored since dnode not running", pMsg->handle, taosMsg[msgType]);
|
||||
return;
|
||||
}
|
||||
|
||||
if (pMsg->pCont == NULL) {
|
||||
rspMsg.code = TSDB_CODE_DND_INVALID_MSG_LEN;
|
||||
rpcSendResponse(&rspMsg);
|
||||
return;
|
||||
}
|
||||
|
||||
MsgFp fp = tsTrans.msgFp[msgType];
|
||||
if (fp != NULL) {
|
||||
dTrace("RPC %p, peer req:%s will be processed", pMsg->handle, taosMsg[msgType]);
|
||||
(*fp)(pMsg, pEpSet);
|
||||
} else {
|
||||
dError("RPC %p, peer req:%s not processed", pMsg->handle, taosMsg[msgType]);
|
||||
rspMsg.code = TSDB_CODE_DND_MSG_NOT_PROCESSED;
|
||||
rpcSendResponse(&rspMsg);
|
||||
rpcFreeCont(pMsg->pCont);
|
||||
}
|
||||
}
|
||||
|
||||
static int32_t dnodeInitPeerServer() {
|
||||
SRpcInit rpcInit;
|
||||
memset(&rpcInit, 0, sizeof(rpcInit));
|
||||
rpcInit.localPort = tsDnodeDnodePort;
|
||||
rpcInit.label = "DND-S";
|
||||
rpcInit.numOfThreads = 1;
|
||||
rpcInit.cfp = dnodeProcessPeerReq;
|
||||
rpcInit.sessions = TSDB_MAX_VNODES << 4;
|
||||
rpcInit.connType = TAOS_CONN_SERVER;
|
||||
rpcInit.idleTime = tsShellActivityTimer * 1000;
|
||||
|
||||
tsTrans.peerRpc = rpcOpen(&rpcInit);
|
||||
if (tsTrans.peerRpc == NULL) {
|
||||
dError("failed to init peer rpc server");
|
||||
return -1;
|
||||
}
|
||||
|
||||
dInfo("dnode peer rpc server is initialized");
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void dnodeCleanupPeerServer() {
|
||||
if (tsTrans.peerRpc) {
|
||||
rpcClose(tsTrans.peerRpc);
|
||||
tsTrans.peerRpc = NULL;
|
||||
dInfo("dnode peer server is closed");
|
||||
}
|
||||
}
|
||||
|
||||
static void dnodeProcessPeerRsp(SRpcMsg *pMsg, SEpSet *pEpSet) {
|
||||
int32_t msgType = pMsg->msgType;
|
||||
|
||||
if (dnodeGetRunStat() == DN_RUN_STAT_STOPPED) {
|
||||
if (pMsg == NULL || pMsg->pCont == NULL) return;
|
||||
dTrace("RPC %p, peer rsp:%s is ignored since dnode is stopping", pMsg->handle, taosMsg[msgType]);
|
||||
rpcFreeCont(pMsg->pCont);
|
||||
return;
|
||||
}
|
||||
|
||||
MsgFp fp = tsTrans.msgFp[msgType];
|
||||
if (fp != NULL) {
|
||||
dTrace("RPC %p, peer rsp:%s will be processed, code:%s", pMsg->handle, taosMsg[msgType], tstrerror(pMsg->code));
|
||||
(*fp)(pMsg, pEpSet);
|
||||
} else {
|
||||
dDebug("RPC %p, peer rsp:%s not processed", pMsg->handle, taosMsg[msgType]);
|
||||
}
|
||||
|
||||
rpcFreeCont(pMsg->pCont);
|
||||
}
|
||||
|
||||
static int32_t dnodeInitClient() {
|
||||
char secret[TSDB_KEY_LEN] = "secret";
|
||||
|
||||
SRpcInit rpcInit;
|
||||
memset(&rpcInit, 0, sizeof(rpcInit));
|
||||
rpcInit.label = "DND-C";
|
||||
rpcInit.numOfThreads = 1;
|
||||
rpcInit.cfp = dnodeProcessPeerRsp;
|
||||
rpcInit.sessions = TSDB_MAX_VNODES << 4;
|
||||
rpcInit.connType = TAOS_CONN_CLIENT;
|
||||
rpcInit.idleTime = tsShellActivityTimer * 1000;
|
||||
rpcInit.user = "t";
|
||||
rpcInit.ckey = "key";
|
||||
rpcInit.secret = secret;
|
||||
|
||||
tsTrans.clientRpc = rpcOpen(&rpcInit);
|
||||
if (tsTrans.clientRpc == NULL) {
|
||||
dError("failed to init peer rpc client");
|
||||
return -1;
|
||||
}
|
||||
|
||||
dInfo("dnode peer rpc client is initialized");
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void dnodeCleanupClient() {
|
||||
if (tsTrans.clientRpc) {
|
||||
rpcClose(tsTrans.clientRpc);
|
||||
tsTrans.clientRpc = NULL;
|
||||
dInfo("dnode peer rpc client is closed");
|
||||
}
|
||||
}
|
||||
|
||||
static void dnodeProcessShellReq(SRpcMsg *pMsg, SEpSet *pEpSet) {
|
||||
SRpcMsg rspMsg = {.handle = pMsg->handle};
|
||||
int32_t msgType = pMsg->msgType;
|
||||
|
||||
if (dnodeGetRunStat() == DN_RUN_STAT_STOPPED) {
|
||||
dError("RPC %p, shell req:%s is ignored since dnode exiting", pMsg->handle, taosMsg[msgType]);
|
||||
rspMsg.code = TSDB_CODE_DND_EXITING;
|
||||
rpcSendResponse(&rspMsg);
|
||||
rpcFreeCont(pMsg->pCont);
|
||||
return;
|
||||
} else if (dnodeGetRunStat() != DN_RUN_STAT_RUNNING) {
|
||||
dError("RPC %p, shell req:%s is ignored since dnode not running", pMsg->handle, taosMsg[msgType]);
|
||||
rspMsg.code = TSDB_CODE_APP_NOT_READY;
|
||||
rpcSendResponse(&rspMsg);
|
||||
rpcFreeCont(pMsg->pCont);
|
||||
return;
|
||||
}
|
||||
|
||||
if (pMsg->pCont == NULL) {
|
||||
rspMsg.code = TSDB_CODE_DND_INVALID_MSG_LEN;
|
||||
rpcSendResponse(&rspMsg);
|
||||
return;
|
||||
}
|
||||
|
||||
MsgFp fp = tsTrans.msgFp[msgType];
|
||||
if (fp != NULL) {
|
||||
dTrace("RPC %p, shell req:%s will be processed", pMsg->handle, taosMsg[msgType]);
|
||||
(*fp)(pMsg, pEpSet);
|
||||
} else {
|
||||
dError("RPC %p, shell req:%s is not processed", pMsg->handle, taosMsg[msgType]);
|
||||
rspMsg.code = TSDB_CODE_DND_MSG_NOT_PROCESSED;
|
||||
rpcSendResponse(&rspMsg);
|
||||
rpcFreeCont(pMsg->pCont);
|
||||
}
|
||||
}
|
||||
|
||||
static void dnodeSendMsgToMnodeRecv(SRpcMsg *rpcMsg, SRpcMsg *rpcRsp) {
|
||||
SEpSet epSet = {0};
|
||||
dnodeGetMnodeEpSetForPeer(&epSet);
|
||||
rpcSendRecv(tsTrans.clientRpc, &epSet, rpcMsg, rpcRsp);
|
||||
}
|
||||
|
||||
static int32_t dnodeRetrieveUserAuthInfo(char *user, char *spi, char *encrypt, char *secret, char *ckey) {
|
||||
int32_t code = dnodeGetUserAuthFromMnode(user, spi, encrypt, secret, ckey);
|
||||
if (code != TSDB_CODE_APP_NOT_READY) return code;
|
||||
|
||||
SAuthMsg *pMsg = rpcMallocCont(sizeof(SAuthMsg));
|
||||
tstrncpy(pMsg->user, user, sizeof(pMsg->user));
|
||||
|
||||
dDebug("user:%s, send auth msg to mnodes", user);
|
||||
SRpcMsg rpcMsg = {.pCont = pMsg, .contLen = sizeof(SAuthMsg), .msgType = TSDB_MSG_TYPE_AUTH};
|
||||
SRpcMsg rpcRsp = {0};
|
||||
dnodeSendMsgToMnodeRecv(&rpcMsg, &rpcRsp);
|
||||
|
||||
if (rpcRsp.code != 0) {
|
||||
dError("user:%s, auth msg received from mnodes, error:%s", user, tstrerror(rpcRsp.code));
|
||||
} else {
|
||||
dDebug("user:%s, auth msg received from mnodes", user);
|
||||
SAuthRsp *pRsp = rpcRsp.pCont;
|
||||
memcpy(secret, pRsp->secret, TSDB_KEY_LEN);
|
||||
memcpy(ckey, pRsp->ckey, TSDB_KEY_LEN);
|
||||
*spi = pRsp->spi;
|
||||
*encrypt = pRsp->encrypt;
|
||||
}
|
||||
|
||||
rpcFreeCont(rpcRsp.pCont);
|
||||
return rpcRsp.code;
|
||||
}
|
||||
|
||||
static int32_t dnodeInitShellServer() {
|
||||
int32_t numOfThreads = (int32_t)((tsNumOfCores * tsNumOfThreadsPerCore) / 2.0);
|
||||
if (numOfThreads < 1) {
|
||||
numOfThreads = 1;
|
||||
}
|
||||
|
||||
SRpcInit rpcInit;
|
||||
memset(&rpcInit, 0, sizeof(rpcInit));
|
||||
rpcInit.localPort = tsDnodeShellPort;
|
||||
rpcInit.label = "SHELL";
|
||||
rpcInit.numOfThreads = numOfThreads;
|
||||
rpcInit.cfp = dnodeProcessShellReq;
|
||||
rpcInit.sessions = tsMaxShellConns;
|
||||
rpcInit.connType = TAOS_CONN_SERVER;
|
||||
rpcInit.idleTime = tsShellActivityTimer * 1000;
|
||||
rpcInit.afp = dnodeRetrieveUserAuthInfo;
|
||||
|
||||
tsTrans.shellRpc = rpcOpen(&rpcInit);
|
||||
if (tsTrans.shellRpc == NULL) {
|
||||
dError("failed to init shell rpc server");
|
||||
return -1;
|
||||
}
|
||||
|
||||
dInfo("dnode shell rpc server is initialized");
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void dnodeCleanupShellServer() {
|
||||
if (tsTrans.shellRpc) {
|
||||
rpcClose(tsTrans.shellRpc);
|
||||
tsTrans.shellRpc = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
int32_t dnodeInitTrans() {
|
||||
if (dnodeInitClient() != 0) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (dnodeInitPeerServer() != 0) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (dnodeInitShellServer() != 0) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void dnodeCleanupTrans() {
|
||||
dnodeCleanupShellServer();
|
||||
dnodeCleanupPeerServer();
|
||||
dnodeCleanupClient();
|
||||
}
|
||||
|
||||
void dnodeSendMsgToDnode(SEpSet *epSet, SRpcMsg *rpcMsg) { rpcSendRequest(tsTrans.clientRpc, epSet, rpcMsg, NULL); }
|
||||
|
||||
void dnodeSendMsgToMnode(SRpcMsg *rpcMsg) {
|
||||
SEpSet epSet = {0};
|
||||
dnodeGetMnodeEpSetForPeer(&epSet);
|
||||
dnodeSendMsgToDnode(&epSet, rpcMsg);
|
||||
}
|
File diff suppressed because it is too large
Load Diff
|
@ -1,3 +1,2 @@
|
|||
add_subdirectory(impl)
|
||||
add_subdirectory(sdb)
|
||||
add_subdirectory(transaction)
|
||||
|
|
|
@ -3,12 +3,11 @@ add_library(mnode ${MNODE_SRC})
|
|||
target_include_directories(
|
||||
mnode
|
||||
PUBLIC "${CMAKE_SOURCE_DIR}/include/dnode/mnode"
|
||||
private "${CMAKE_CURRENT_SOURCE_DIR}/inc"
|
||||
PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/inc"
|
||||
)
|
||||
target_link_libraries(
|
||||
mnode
|
||||
PRIVATE sdb
|
||||
PRIVATE transaction
|
||||
PUBLIC transport
|
||||
PUBLIC cjson
|
||||
PRIVATE transport
|
||||
PRIVATE cjson
|
||||
)
|
|
@ -13,20 +13,20 @@
|
|||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef _TD_MNODE_ACCT_H_
|
||||
#define _TD_MNODE_ACCT_H_
|
||||
#ifndef _TD_MND_ACCT_H_
|
||||
#define _TD_MND_ACCT_H_
|
||||
|
||||
#include "mnodeInt.h"
|
||||
#include "mndInt.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
int32_t mnodeInitAcct();
|
||||
void mnodeCleanupAcct();
|
||||
int32_t mndInitAcct(SMnode *pMnode);
|
||||
void mndCleanupAcct(SMnode *pMnode);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /*_TD_MNODE_ACCT_H_*/
|
||||
#endif /*_TD_MND_ACCT_H_*/
|
|
@ -13,20 +13,20 @@
|
|||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef _TD_MNODE_AUTH_H_
|
||||
#define _TD_MNODE_AUTH_H_
|
||||
#ifndef _TD_MND_AUTH_H_
|
||||
#define _TD_MND_AUTH_H_
|
||||
|
||||
#include "mnodeInt.h"
|
||||
#include "mndInt.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
int32_t mnodeInitAuth();
|
||||
void mnodeCleanupAuth();
|
||||
int32_t mndInitAuth(SMnode *pMnode);
|
||||
void mndCleanupAuth(SMnode *pMnode);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /*_TD_MNODE_AUTH_H_*/
|
||||
#endif /*_TD_MND_AUTH_H_*/
|
|
@ -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/>.
|
||||
*/
|
||||
|
||||
#ifndef _TD_MNODE_DEF_H_
|
||||
#define _TD_MNODE_DEF_H_
|
||||
#ifndef _TD_MND_DEF_H_
|
||||
#define _TD_MND_DEF_H_
|
||||
|
||||
#include "os.h"
|
||||
#include "taosmsg.h"
|
||||
|
@ -39,44 +39,57 @@ extern int32_t mDebugFlag;
|
|||
#define mDebug(...) { if (mDebugFlag & DEBUG_DEBUG) { taosPrintLog("MND ", mDebugFlag, __VA_ARGS__); }}
|
||||
#define mTrace(...) { if (mDebugFlag & DEBUG_TRACE) { taosPrintLog("MND ", mDebugFlag, __VA_ARGS__); }}
|
||||
|
||||
// #define mLError(...) { monSaveLog(2, __VA_ARGS__); mError(__VA_ARGS__) }
|
||||
// #define mLWarn(...) { monSaveLog(1, __VA_ARGS__); mWarn(__VA_ARGS__) }
|
||||
// #define mLInfo(...) { monSaveLog(0, __VA_ARGS__); mInfo(__VA_ARGS__) }
|
||||
|
||||
#define mLError(...) {mError(__VA_ARGS__) }
|
||||
#define mLWarn(...) {mWarn(__VA_ARGS__) }
|
||||
#define mLInfo(...) {mInfo(__VA_ARGS__) }
|
||||
|
||||
typedef struct SClusterObj SClusterObj;
|
||||
typedef struct SDnodeObj SDnodeObj;
|
||||
typedef struct SMnodeObj SMnodeObj;
|
||||
typedef struct SAcctObj SAcctObj;
|
||||
typedef struct SUserObj SUserObj;
|
||||
typedef struct SDbObj SDbObj;
|
||||
typedef struct SVgObj SVgObj;
|
||||
typedef struct SSTableObj SSTableObj;
|
||||
typedef struct SFuncObj SFuncObj;
|
||||
typedef struct SOperObj SOperObj;
|
||||
typedef struct SClusterObj SClusterObj;
|
||||
typedef struct SDnodeObj SDnodeObj;
|
||||
typedef struct SMnodeObj SMnodeObj;
|
||||
typedef struct SAcctObj SAcctObj;
|
||||
typedef struct SUserObj SUserObj;
|
||||
typedef struct SDbObj SDbObj;
|
||||
typedef struct SVgObj SVgObj;
|
||||
typedef struct SSTableObj SSTableObj;
|
||||
typedef struct SFuncObj SFuncObj;
|
||||
typedef struct SOperObj SOperObj;
|
||||
|
||||
typedef enum {
|
||||
MN_AUTH_ACCT_START = 0,
|
||||
MN_AUTH_ACCT_USER,
|
||||
MN_AUTH_ACCT_DNODE,
|
||||
MN_AUTH_ACCT_MNODE,
|
||||
MN_AUTH_ACCT_DB,
|
||||
MN_AUTH_ACCT_TABLE,
|
||||
MN_AUTH_ACCT_MAX
|
||||
} EMnAuthAcct;
|
||||
MND_AUTH_ACCT_START = 0,
|
||||
MND_AUTH_ACCT_USER,
|
||||
MND_AUTH_ACCT_DNODE,
|
||||
MND_AUTH_ACCT_MNODE,
|
||||
MND_AUTH_ACCT_DB,
|
||||
MND_AUTH_ACCT_TABLE,
|
||||
MND_AUTH_ACCT_MAX
|
||||
} EAuthAcct;
|
||||
|
||||
typedef enum {
|
||||
MN_AUTH_OP_START = 0,
|
||||
MN_AUTH_OP_CREATE_USER,
|
||||
MN_AUTH_OP_ALTER_USER,
|
||||
MN_AUTH_OP_DROP_USER,
|
||||
MN_AUTH_MAX
|
||||
} EMnAuthOp;
|
||||
MND_AUTH_OP_START = 0,
|
||||
MND_AUTH_OP_CREATE_USER,
|
||||
MND_AUTH_OP_ALTER_USER,
|
||||
MND_AUTH_OP_DROP_USER,
|
||||
MND_AUTH_MAX
|
||||
} EAuthOp;
|
||||
|
||||
typedef enum {
|
||||
TRN_STAGE_PREPARE = 1,
|
||||
TRN_STAGE_EXECUTE = 2,
|
||||
TRN_STAGE_COMMIT = 3,
|
||||
TRN_STAGE_ROLLBACK = 4,
|
||||
TRN_STAGE_RETRY = 5
|
||||
} ETrnStage;
|
||||
|
||||
typedef enum { TRN_POLICY_ROLLBACK = 1, TRN_POLICY_RETRY = 2 } ETrnPolicy;
|
||||
|
||||
typedef struct STrans {
|
||||
int32_t id;
|
||||
ETrnStage stage;
|
||||
ETrnPolicy policy;
|
||||
SMnode *pMnode;
|
||||
void *rpcHandle;
|
||||
SArray *redoLogs;
|
||||
SArray *undoLogs;
|
||||
SArray *commitLogs;
|
||||
SArray *redoActions;
|
||||
SArray *undoActions;
|
||||
} STrans;
|
||||
|
||||
typedef struct SClusterObj {
|
||||
int64_t id;
|
||||
|
@ -180,6 +193,7 @@ typedef struct SDbObj {
|
|||
int64_t createdTime;
|
||||
int64_t updateTime;
|
||||
SDbCfg cfg;
|
||||
int64_t uid;
|
||||
int8_t status;
|
||||
int32_t numOfVgroups;
|
||||
int32_t numOfTables;
|
||||
|
@ -218,13 +232,13 @@ typedef struct SVgObj {
|
|||
} SVgObj;
|
||||
|
||||
typedef struct SSTableObj {
|
||||
char tableId[TSDB_TABLE_NAME_LEN];
|
||||
uint64_t uid;
|
||||
int64_t createdTime;
|
||||
int64_t updateTime;
|
||||
int32_t numOfColumns; // used by normal table
|
||||
int32_t numOfTags;
|
||||
SSchema * schema;
|
||||
char tableId[TSDB_TABLE_NAME_LEN];
|
||||
uint64_t uid;
|
||||
int64_t createdTime;
|
||||
int64_t updateTime;
|
||||
int32_t numOfColumns; // used by normal table
|
||||
int32_t numOfTags;
|
||||
SSchema *schema;
|
||||
} SSTableObj;
|
||||
|
||||
typedef struct SFuncObj {
|
||||
|
@ -262,25 +276,26 @@ typedef struct {
|
|||
typedef struct {
|
||||
int32_t len;
|
||||
void *rsp;
|
||||
} SMnRsp;
|
||||
} SMnodeRsp;
|
||||
|
||||
typedef struct SMnodeMsg {
|
||||
SMnode *pMnode;
|
||||
void (*fp)(SMnodeMsg *pMsg, int32_t code);
|
||||
SRpcConnInfo conn;
|
||||
SUserObj *pUser;
|
||||
int16_t received;
|
||||
int16_t successed;
|
||||
int16_t expected;
|
||||
int16_t retry;
|
||||
int32_t code;
|
||||
int64_t createdTime;
|
||||
SMnRsp rpcRsp;
|
||||
SRpcMsg rpcMsg;
|
||||
char pCont[];
|
||||
SUserObj *pUser;
|
||||
int16_t received;
|
||||
int16_t successed;
|
||||
int16_t expected;
|
||||
int16_t retry;
|
||||
int32_t code;
|
||||
int64_t createdTime;
|
||||
SMnodeRsp rpcRsp;
|
||||
SRpcMsg rpcMsg;
|
||||
char pCont[];
|
||||
} SMnodeMsg;
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /*_TD_MNODE_DEF_H_*/
|
||||
#endif /*_TD_MND_DEF_H_*/
|
|
@ -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/>.
|
||||
*/
|
||||
|
||||
#ifndef _TD_MNODE_CLUSTER_H_
|
||||
#define _TD_MNODE_CLUSTER_H_
|
||||
#ifndef _TD_MND_FUNC_H_
|
||||
#define _TD_MND_FUNC_H_
|
||||
|
||||
#include "mnodeInt.h"
|
||||
#include "mndInt.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
int32_t mnodeInitCluster();
|
||||
void mnodeCleanupCluster();
|
||||
int32_t mndInitFunc(SMnode *pMnode);
|
||||
void mndCleanupFunc(SMnode *pMnode);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /*_TD_MNODE_CLUSTER_H_*/
|
||||
#endif /*_TD_MND_FUNC_H_*/
|
|
@ -0,0 +1,68 @@
|
|||
/*
|
||||
* 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_INT_H_
|
||||
#define _TD_MND_INT_H_
|
||||
|
||||
#include "mndDef.h"
|
||||
#include "sdb.h"
|
||||
#include "tqueue.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
typedef int32_t (*MndMsgFp)(SMnode *pMnode, SMnodeMsg *pMsg);
|
||||
typedef int32_t (*MndInitFp)(SMnode *pMnode);
|
||||
typedef void (*MndCleanupFp)(SMnode *pMnode);
|
||||
|
||||
typedef struct {
|
||||
const char *name;
|
||||
MndInitFp initFp;
|
||||
MndCleanupFp cleanupFp;
|
||||
} SMnodeStep;
|
||||
|
||||
typedef struct SMnode {
|
||||
int32_t dnodeId;
|
||||
int64_t clusterId;
|
||||
int8_t replica;
|
||||
int8_t selfIndex;
|
||||
SReplica replicas[TSDB_MAX_REPLICA];
|
||||
tmr_h timer;
|
||||
char *path;
|
||||
SSdb *pSdb;
|
||||
SDnode *pDnode;
|
||||
SArray *pSteps;
|
||||
MndMsgFp msgFp[TSDB_MSG_TYPE_MAX];
|
||||
SendMsgToDnodeFp sendMsgToDnodeFp;
|
||||
SendMsgToMnodeFp sendMsgToMnodeFp;
|
||||
SendRedirectMsgFp sendRedirectMsgFp;
|
||||
PutMsgToMnodeQFp putMsgToApplyMsgFp;
|
||||
} SMnode;
|
||||
|
||||
tmr_h mndGetTimer(SMnode *pMnode);
|
||||
int32_t mndGetDnodeId(SMnode *pMnode);
|
||||
int64_t mndGetClusterId(SMnode *pMnode);
|
||||
|
||||
void mndSendMsgToDnode(SMnode *pMnode, SEpSet *pEpSet, SRpcMsg *rpcMsg);
|
||||
void mndSendMsgToMnode(SMnode *pMnode, SRpcMsg *pMsg);
|
||||
void mndSendRedirectMsg(SMnode *pMnode, SRpcMsg *pMsg);
|
||||
void mndSetMsgHandle(SMnode *pMnode, int32_t msgType, MndMsgFp fp);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /*_TD_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/>.
|
||||
*/
|
||||
|
||||
#ifndef _TD_MNODE_OPER_H_
|
||||
#define _TD_MNODE_OPER_H_
|
||||
#ifndef _TD_MND_OPER_H_
|
||||
#define _TD_MND_OPER_H_
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
int32_t mnodeInitOper();
|
||||
void mnodeCleanupOper();
|
||||
int32_t mndInitOper(SMnode *pMnode);
|
||||
void mndCleanupOper(SMnode *pMnode);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /*_TD_MNODE_OPER_H_*/
|
||||
#endif /*_TD_MND_OPER_H_*/
|
|
@ -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/>.
|
||||
*/
|
||||
|
||||
#ifndef _TD_MNODE_BALANCE_H_
|
||||
#define _TD_MNODE_BALANCE_H_
|
||||
#ifndef _TD_MND_SHOW_H_
|
||||
#define _TD_MND_SHOW_H_
|
||||
|
||||
#include "mnodeInt.h"
|
||||
#include "mndInt.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
int32_t mnodeInitBalance();
|
||||
void mnodeCleanupBalance();
|
||||
int32_t mndInitShow(SMnode *pMnode);
|
||||
void mndCleanupShow(SMnode *pMnode);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /*_TD_MNODE_BALANCE_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/>.
|
||||
*/
|
||||
|
||||
#ifndef _TD_MNODE_TELEMETRY_H_
|
||||
#define _TD_MNODE_TELEMETRY_H_
|
||||
#ifndef _TD_MND_TELEMETRY_H_
|
||||
#define _TD_MND_TELEMETRY_H_
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
#include "mnodeInt.h"
|
||||
#include "mndInt.h"
|
||||
|
||||
int32_t mnodeInitTelem();
|
||||
void mnodeCleanupTelem();
|
||||
int32_t mndInitTelem(SMnode *pMnode);
|
||||
void mndCleanupTelem(SMnode *pMnode);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /*_TD_MNODE_TELEMETRY_H_*/
|
||||
#endif /*_TD_MND_TELEMETRY_H_*/
|
|
@ -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,43 +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_INT_H_
|
||||
#define _TD_MNODE_INT_H_
|
||||
|
||||
#include "mnodeDef.h"
|
||||
#include "sdb.h"
|
||||
#include "trn.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
typedef void (*MnodeRpcFp)(SMnodeMsg *pMsg);
|
||||
|
||||
tmr_h mnodeGetTimer();
|
||||
int32_t mnodeGetDnodeId();
|
||||
int64_t mnodeGetClusterId();
|
||||
|
||||
void mnodeSendMsgToDnode(struct SEpSet *epSet, struct SRpcMsg *rpcMsg);
|
||||
void mnodeSendMsgToMnode(struct SRpcMsg *rpcMsg);
|
||||
void mnodeSendRedirectMsg(struct SRpcMsg *rpcMsg, bool forShell);
|
||||
|
||||
void mnodeSetMsgFp(int32_t msgType, MnodeRpcFp fp);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /*_TD_MNODE_INT_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,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
|
||||
#include "mnodeInt.h"
|
||||
#include "mndInt.h"
|
||||
|
||||
#define SDB_ACCT_VER 1
|
||||
|
||||
|
@ -48,10 +48,10 @@ static SSdbRow *mnodeAcctActionDecode(SSdbRaw *pRaw) {
|
|||
return NULL;
|
||||
}
|
||||
|
||||
SSdbRow *pRow = sdbAllocRow(sizeof(SAcctObj));
|
||||
SSdbRow *pRow = sdbAllocRow(sizeof(SAcctObj));
|
||||
SAcctObj *pAcct = sdbGetRowObj(pRow);
|
||||
if (pAcct == NULL) return NULL;
|
||||
|
||||
|
||||
int32_t dataPos = 0;
|
||||
SDB_GET_BINARY(pRaw, pRow, dataPos, pAcct->acct, TSDB_USER_LEN)
|
||||
SDB_GET_INT64(pRaw, pRow, dataPos, &pAcct->createdTime)
|
||||
|
@ -68,18 +68,18 @@ static SSdbRow *mnodeAcctActionDecode(SSdbRaw *pRaw) {
|
|||
return pRow;
|
||||
}
|
||||
|
||||
static int32_t mnodeAcctActionInsert(SAcctObj *pAcct) { return 0; }
|
||||
static int32_t mnodeAcctActionInsert(SSdb *pSdb, SAcctObj *pAcct) { return 0; }
|
||||
|
||||
static int32_t mnodeAcctActionDelete(SAcctObj *pAcct) { return 0; }
|
||||
static int32_t mnodeAcctActionDelete(SSdb *pSdb, SAcctObj *pAcct) { return 0; }
|
||||
|
||||
static int32_t mnodeAcctActionUpdate(SAcctObj *pSrcAcct, SAcctObj *pDstAcct) {
|
||||
static int32_t mnodeAcctActionUpdate(SSdb *pSdb, SAcctObj *pSrcAcct, SAcctObj *pDstAcct) {
|
||||
SAcctObj tObj;
|
||||
int32_t len = (int32_t)((int8_t *)&tObj.info - (int8_t *)&tObj);
|
||||
memcpy(pDstAcct, pSrcAcct, len);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int32_t mnodeCreateDefaultAcct() {
|
||||
static int32_t mnodeCreateDefaultAcct(SSdb *pSdb) {
|
||||
int32_t code = 0;
|
||||
|
||||
SAcctObj acctObj = {0};
|
||||
|
@ -98,21 +98,20 @@ static int32_t mnodeCreateDefaultAcct() {
|
|||
if (pRaw == NULL) return -1;
|
||||
sdbSetRawStatus(pRaw, SDB_STATUS_READY);
|
||||
|
||||
return sdbWrite(pRaw);
|
||||
return sdbWrite(pSdb, pRaw);
|
||||
}
|
||||
|
||||
int32_t mnodeInitAcct() {
|
||||
int32_t mndInitAcct(SMnode *pMnode) {
|
||||
SSdbTable table = {.sdbType = SDB_ACCT,
|
||||
.keyType = SDB_KEY_BINARY,
|
||||
.deployFp = (SdbDeployFp)mnodeCreateDefaultAcct,
|
||||
.deployFp = mnodeCreateDefaultAcct,
|
||||
.encodeFp = (SdbEncodeFp)mnodeAcctActionEncode,
|
||||
.decodeFp = (SdbDecodeFp)mnodeAcctActionDecode,
|
||||
.insertFp = (SdbInsertFp)mnodeAcctActionInsert,
|
||||
.updateFp = (SdbUpdateFp)mnodeAcctActionUpdate,
|
||||
.deleteFp = (SdbDeleteFp)mnodeAcctActionDelete};
|
||||
sdbSetTable(table);
|
||||
|
||||
return 0;
|
||||
return sdbSetTable(pMnode->pSdb, table);
|
||||
}
|
||||
|
||||
void mnodeCleanupAcct() {}
|
||||
void mndCleanupAcct(SMnode *pMnode) {}
|
|
@ -15,15 +15,11 @@
|
|||
|
||||
#define _DEFAULT_SOURCE
|
||||
#include "os.h"
|
||||
#include "mnodeInt.h"
|
||||
#include "mndAuth.h"
|
||||
|
||||
int32_t mnodeInitSync() { return 0; }
|
||||
void mnodeCleanUpSync() {}
|
||||
int32_t mndInitAuth(SMnode *pMnode) { return 0; }
|
||||
void mndCleanupAuth(SMnode *pMnode) {}
|
||||
|
||||
int32_t mnodeSyncPropose(SSdbRaw *pRaw, void *pData) {
|
||||
trnApply(pData, pData, 0);
|
||||
free(pData);
|
||||
int32_t mndRetriveAuth(SMnode *pMnode, char *user, char *spi, char *encrypt, char *secret, char *ckey) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
bool mnodeIsMaster() { return true; }
|
||||
}
|
|
@ -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
|
||||
#include "os.h"
|
||||
#include "mnodeInt.h"
|
||||
#include "mndInt.h"
|
||||
|
||||
int32_t mnodeInitBalance() { return 0; }
|
||||
void mnodeCleanupBalance() {}
|
||||
int32_t mndInitDb(SMnode *pMnode) { return 0; }
|
||||
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
|
||||
#include "os.h"
|
||||
#include "mnodeInt.h"
|
||||
#include "mndInt.h"
|
||||
|
||||
int32_t mnodeInitCluster() { return 0; }
|
||||
void mnodeCleanupCluster() {}
|
||||
int32_t mndInitFunc(SMnode *pMnode) { return 0; }
|
||||
void mndCleanupFunc(SMnode *pMnode) {}
|
|
@ -15,10 +15,10 @@
|
|||
|
||||
#define _DEFAULT_SOURCE
|
||||
#include "os.h"
|
||||
#include "mnodeInt.h"
|
||||
#include "mndInt.h"
|
||||
|
||||
int32_t mnodeInitMnode() { return 0; }
|
||||
void mnodeCleanupMnode() {}
|
||||
int32_t mndInitMnode(SMnode *pMnode) { return 0; }
|
||||
void mndCleanupMnode(SMnode *pMnode) {}
|
||||
|
||||
void mnodeGetMnodeEpSetForPeer(SEpSet *epSet, bool redirect) {}
|
||||
void mnodeGetMnodeEpSetForShell(SEpSet *epSet, bool redirect) {}
|
||||
void mndGetMnodeEpSetForPeer(SEpSet *epSet, bool redirect) {}
|
||||
void mndGetMnodeEpSetForShell(SEpSet *epSet, bool redirect) {}
|
|
@ -15,7 +15,7 @@
|
|||
|
||||
#define _DEFAULT_SOURCE
|
||||
#include "os.h"
|
||||
#include "mnodeInt.h"
|
||||
#include "mndInt.h"
|
||||
|
||||
int32_t mnodeInitDb() { return 0; }
|
||||
void mnodeCleanupDb() {}
|
||||
int32_t mndInitOper(SMnode *pMnode) { return 0; }
|
||||
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
|
||||
#include "os.h"
|
||||
#include "mnodeInt.h"
|
||||
#include "mndInt.h"
|
||||
|
||||
int32_t mnodeInitDnode() { return 0; }
|
||||
void mnodeCleanupDnode() {}
|
||||
int32_t mndInitShow(SMnode *pMnode) { return 0; }
|
||||
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) {}
|
|
@ -0,0 +1,30 @@
|
|||
/*
|
||||
* 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"
|
||||
#include "mndTrans.h"
|
||||
|
||||
int32_t mndInitSync(SMnode *pMnode) { return 0; }
|
||||
void mndCleanupSync(SMnode *pMnode) {}
|
||||
|
||||
int32_t mndSyncPropose(SMnode *pMnode, SSdbRaw *pRaw, void *pData) {
|
||||
mndTransApply(pMnode, pData, pData, 0);
|
||||
free(pData);
|
||||
return 0;
|
||||
}
|
||||
|
||||
bool mndIsMaster(SMnode *pMnode) { return true; }
|
|
@ -14,10 +14,10 @@
|
|||
*/
|
||||
|
||||
#define _DEFAULT_SOURCE
|
||||
#include "mnodeTelem.h"
|
||||
#include "mndTelem.h"
|
||||
#include "tbuffer.h"
|
||||
#include "tglobal.h"
|
||||
#include "mnodeSync.h"
|
||||
#include "mndSync.h"
|
||||
|
||||
#define TELEMETRY_SERVER "telemetry.taosdata.com"
|
||||
#define TELEMETRY_PORT 80
|
||||
|
@ -36,9 +36,9 @@ static struct {
|
|||
char email[TSDB_FQDN_LEN];
|
||||
} tsTelem;
|
||||
|
||||
static void mnodeBeginObject(SBufferWriter* bw) { tbufWriteChar(bw, '{'); }
|
||||
static void mndBeginObject(SBufferWriter* bw) { tbufWriteChar(bw, '{'); }
|
||||
|
||||
static void mnodeCloseObject(SBufferWriter* bw) {
|
||||
static void mndCloseObject(SBufferWriter* bw) {
|
||||
size_t len = tbufTell(bw);
|
||||
if (tbufGetData(bw, false)[len - 1] == ',') {
|
||||
tbufWriteCharAt(bw, len - 1, '}');
|
||||
|
@ -64,14 +64,14 @@ static void closeArray(SBufferWriter* bw) {
|
|||
}
|
||||
#endif
|
||||
|
||||
static void mnodeWriteString(SBufferWriter* bw, const char* str) {
|
||||
static void mndWriteString(SBufferWriter* bw, const char* str) {
|
||||
tbufWriteChar(bw, '"');
|
||||
tbufWrite(bw, str, strlen(str));
|
||||
tbufWriteChar(bw, '"');
|
||||
}
|
||||
|
||||
static void mnodeAddIntField(SBufferWriter* bw, const char* k, int64_t v) {
|
||||
mnodeWriteString(bw, k);
|
||||
static void mndAddIntField(SBufferWriter* bw, const char* k, int64_t v) {
|
||||
mndWriteString(bw, k);
|
||||
tbufWriteChar(bw, ':');
|
||||
char buf[32];
|
||||
sprintf(buf, "%" PRId64, v);
|
||||
|
@ -79,14 +79,14 @@ static void mnodeAddIntField(SBufferWriter* bw, const char* k, int64_t v) {
|
|||
tbufWriteChar(bw, ',');
|
||||
}
|
||||
|
||||
static void mnodeAddStringField(SBufferWriter* bw, const char* k, const char* v) {
|
||||
mnodeWriteString(bw, k);
|
||||
static void mndAddStringField(SBufferWriter* bw, const char* k, const char* v) {
|
||||
mndWriteString(bw, k);
|
||||
tbufWriteChar(bw, ':');
|
||||
mnodeWriteString(bw, v);
|
||||
mndWriteString(bw, v);
|
||||
tbufWriteChar(bw, ',');
|
||||
}
|
||||
|
||||
static void mnodeAddCpuInfo(SBufferWriter* bw) {
|
||||
static void mndAddCpuInfo(SBufferWriter* bw) {
|
||||
char* line = NULL;
|
||||
size_t size = 0;
|
||||
int32_t done = 0;
|
||||
|
@ -100,11 +100,11 @@ static void mnodeAddCpuInfo(SBufferWriter* bw) {
|
|||
line[size - 1] = '\0';
|
||||
if (((done & 1) == 0) && strncmp(line, "model name", 10) == 0) {
|
||||
const char* v = strchr(line, ':') + 2;
|
||||
mnodeAddStringField(bw, "cpuModel", v);
|
||||
mndAddStringField(bw, "cpuModel", v);
|
||||
done |= 1;
|
||||
} else if (((done & 2) == 0) && strncmp(line, "cpu cores", 9) == 0) {
|
||||
const char* v = strchr(line, ':') + 2;
|
||||
mnodeWriteString(bw, "numOfCpu");
|
||||
mndWriteString(bw, "numOfCpu");
|
||||
tbufWriteChar(bw, ':');
|
||||
tbufWrite(bw, v, strlen(v));
|
||||
tbufWriteChar(bw, ',');
|
||||
|
@ -116,7 +116,7 @@ static void mnodeAddCpuInfo(SBufferWriter* bw) {
|
|||
fclose(fp);
|
||||
}
|
||||
|
||||
static void mnodeAddOsInfo(SBufferWriter* bw) {
|
||||
static void mndAddOsInfo(SBufferWriter* bw) {
|
||||
char* line = NULL;
|
||||
size_t size = 0;
|
||||
|
||||
|
@ -133,7 +133,7 @@ static void mnodeAddOsInfo(SBufferWriter* bw) {
|
|||
p++;
|
||||
line[size - 2] = 0;
|
||||
}
|
||||
mnodeAddStringField(bw, "os", p);
|
||||
mndAddStringField(bw, "os", p);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@ -142,7 +142,7 @@ static void mnodeAddOsInfo(SBufferWriter* bw) {
|
|||
fclose(fp);
|
||||
}
|
||||
|
||||
static void mnodeAddMemoryInfo(SBufferWriter* bw) {
|
||||
static void mndAddMemoryInfo(SBufferWriter* bw) {
|
||||
char* line = NULL;
|
||||
size_t size = 0;
|
||||
|
||||
|
@ -156,7 +156,7 @@ static void mnodeAddMemoryInfo(SBufferWriter* bw) {
|
|||
if (strncmp(line, "MemTotal", 8) == 0) {
|
||||
const char* p = strchr(line, ':') + 1;
|
||||
while (*p == ' ') p++;
|
||||
mnodeAddStringField(bw, "memory", p);
|
||||
mndAddStringField(bw, "memory", p);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@ -165,32 +165,32 @@ static void mnodeAddMemoryInfo(SBufferWriter* bw) {
|
|||
fclose(fp);
|
||||
}
|
||||
|
||||
static void mnodeAddVersionInfo(SBufferWriter* bw) {
|
||||
mnodeAddStringField(bw, "version", version);
|
||||
mnodeAddStringField(bw, "buildInfo", buildinfo);
|
||||
mnodeAddStringField(bw, "gitInfo", gitinfo);
|
||||
mnodeAddStringField(bw, "email", tsTelem.email);
|
||||
static void mndAddVersionInfo(SBufferWriter* bw) {
|
||||
mndAddStringField(bw, "version", version);
|
||||
mndAddStringField(bw, "buildInfo", buildinfo);
|
||||
mndAddStringField(bw, "gitInfo", gitinfo);
|
||||
mndAddStringField(bw, "email", tsTelem.email);
|
||||
}
|
||||
|
||||
static void mnodeAddRuntimeInfo(SBufferWriter* bw) {
|
||||
static void mndAddRuntimeInfo(SBufferWriter* bw) {
|
||||
SMnodeLoad load = {0};
|
||||
if (mnodeGetLoad(&load) != 0) {
|
||||
if (mndGetLoad(NULL, &load) != 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
mnodeAddIntField(bw, "numOfDnode", load.numOfDnode);
|
||||
mnodeAddIntField(bw, "numOfMnode", load.numOfMnode);
|
||||
mnodeAddIntField(bw, "numOfVgroup", load.numOfVgroup);
|
||||
mnodeAddIntField(bw, "numOfDatabase", load.numOfDatabase);
|
||||
mnodeAddIntField(bw, "numOfSuperTable", load.numOfSuperTable);
|
||||
mnodeAddIntField(bw, "numOfChildTable", load.numOfChildTable);
|
||||
mnodeAddIntField(bw, "numOfColumn", load.numOfColumn);
|
||||
mnodeAddIntField(bw, "numOfPoint", load.totalPoints);
|
||||
mnodeAddIntField(bw, "totalStorage", load.totalStorage);
|
||||
mnodeAddIntField(bw, "compStorage", load.compStorage);
|
||||
mndAddIntField(bw, "numOfDnode", load.numOfDnode);
|
||||
mndAddIntField(bw, "numOfMnode", load.numOfMnode);
|
||||
mndAddIntField(bw, "numOfVgroup", load.numOfVgroup);
|
||||
mndAddIntField(bw, "numOfDatabase", load.numOfDatabase);
|
||||
mndAddIntField(bw, "numOfSuperTable", load.numOfSuperTable);
|
||||
mndAddIntField(bw, "numOfChildTable", load.numOfChildTable);
|
||||
mndAddIntField(bw, "numOfColumn", load.numOfColumn);
|
||||
mndAddIntField(bw, "numOfPoint", load.totalPoints);
|
||||
mndAddIntField(bw, "totalStorage", load.totalStorage);
|
||||
mndAddIntField(bw, "compStorage", load.compStorage);
|
||||
}
|
||||
|
||||
static void mnodeSendTelemetryReport() {
|
||||
static void mndSendTelemetryReport() {
|
||||
char buf[128] = {0};
|
||||
uint32_t ip = taosGetIpv4FromFqdn(TELEMETRY_SERVER);
|
||||
if (ip == 0xffffffff) {
|
||||
|
@ -203,20 +203,20 @@ static void mnodeSendTelemetryReport() {
|
|||
return;
|
||||
}
|
||||
|
||||
int64_t clusterId = mnodeGetClusterId();
|
||||
int64_t clusterId = mndGetClusterId(NULL);
|
||||
char clusterIdStr[20] = {0};
|
||||
snprintf(clusterIdStr, sizeof(clusterIdStr), "%" PRId64, clusterId);
|
||||
|
||||
SBufferWriter bw = tbufInitWriter(NULL, false);
|
||||
mnodeBeginObject(&bw);
|
||||
mnodeAddStringField(&bw, "instanceId", clusterIdStr);
|
||||
mnodeAddIntField(&bw, "reportVersion", 1);
|
||||
mnodeAddOsInfo(&bw);
|
||||
mnodeAddCpuInfo(&bw);
|
||||
mnodeAddMemoryInfo(&bw);
|
||||
mnodeAddVersionInfo(&bw);
|
||||
mnodeAddRuntimeInfo(&bw);
|
||||
mnodeCloseObject(&bw);
|
||||
mndBeginObject(&bw);
|
||||
mndAddStringField(&bw, "instanceId", clusterIdStr);
|
||||
mndAddIntField(&bw, "reportVersion", 1);
|
||||
mndAddOsInfo(&bw);
|
||||
mndAddCpuInfo(&bw);
|
||||
mndAddMemoryInfo(&bw);
|
||||
mndAddVersionInfo(&bw);
|
||||
mndAddRuntimeInfo(&bw);
|
||||
mndCloseObject(&bw);
|
||||
|
||||
const char* header =
|
||||
"POST /report HTTP/1.1\n"
|
||||
|
@ -240,12 +240,12 @@ static void mnodeSendTelemetryReport() {
|
|||
taosCloseSocket(fd);
|
||||
}
|
||||
|
||||
static void* mnodeTelemThreadFp(void* param) {
|
||||
static void* mndTelemThreadFp(void* param) {
|
||||
struct timespec end = {0};
|
||||
clock_gettime(CLOCK_REALTIME, &end);
|
||||
end.tv_sec += 300; // wait 5 minutes before send first report
|
||||
|
||||
setThreadName("mnode-telem");
|
||||
setThreadName("mnd-telem");
|
||||
|
||||
while (!tsTelem.exit) {
|
||||
int32_t r = 0;
|
||||
|
@ -256,8 +256,8 @@ static void* mnodeTelemThreadFp(void* param) {
|
|||
if (r == 0) break;
|
||||
if (r != ETIMEDOUT) continue;
|
||||
|
||||
if (mnodeIsMaster()) {
|
||||
mnodeSendTelemetryReport();
|
||||
if (mndIsMaster(NULL)) {
|
||||
mndSendTelemetryReport();
|
||||
}
|
||||
end.tv_sec += REPORT_INTERVAL;
|
||||
}
|
||||
|
@ -265,7 +265,7 @@ static void* mnodeTelemThreadFp(void* param) {
|
|||
return NULL;
|
||||
}
|
||||
|
||||
static void mnodeGetEmail(char* filepath) {
|
||||
static void mndGetEmail(char* filepath) {
|
||||
int32_t fd = taosOpenFileRead(filepath);
|
||||
if (fd < 0) {
|
||||
return;
|
||||
|
@ -278,7 +278,7 @@ static void mnodeGetEmail(char* filepath) {
|
|||
taosCloseFile(fd);
|
||||
}
|
||||
|
||||
int32_t mnodeInitTelem() {
|
||||
int32_t mndInitTelem(SMnode *pMnode) {
|
||||
tsTelem.enable = tsEnableTelemetryReporting;
|
||||
if (!tsTelem.enable) return 0;
|
||||
|
||||
|
@ -287,23 +287,23 @@ int32_t mnodeInitTelem() {
|
|||
pthread_cond_init(&tsTelem.cond, NULL);
|
||||
tsTelem.email[0] = 0;
|
||||
|
||||
mnodeGetEmail("/usr/local/taos/email");
|
||||
mndGetEmail("/usr/local/taos/email");
|
||||
|
||||
pthread_attr_t attr;
|
||||
pthread_attr_init(&attr);
|
||||
pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_JOINABLE);
|
||||
|
||||
int32_t code = pthread_create(&tsTelem.thread, &attr, mnodeTelemThreadFp, NULL);
|
||||
int32_t code = pthread_create(&tsTelem.thread, &attr, mndTelemThreadFp, NULL);
|
||||
pthread_attr_destroy(&attr);
|
||||
if (code != 0) {
|
||||
mTrace("failed to create telemetry thread since :%s", strerror(code));
|
||||
}
|
||||
|
||||
mInfo("mnode telemetry is initialized");
|
||||
mInfo("mnd telemetry is initialized");
|
||||
return 0;
|
||||
}
|
||||
|
||||
void mnodeCleanupTelem() {
|
||||
void mndCleanupTelem(SMnode *pMnode) {
|
||||
if (!tsTelem.enable) return;
|
||||
|
||||
if (taosCheckPthreadValid(tsTelem.thread)) {
|
|
@ -0,0 +1,499 @@
|
|||
/*
|
||||
* 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 "mndTrans.h"
|
||||
#include "trpc.h"
|
||||
|
||||
#define SDB_TRANS_VER 1
|
||||
#define TRN_DEFAULT_ARRAY_SIZE 8
|
||||
|
||||
SSdbRaw *mndTransActionEncode(STrans *pTrans) {
|
||||
int32_t rawDataLen = 10 * sizeof(int32_t);
|
||||
int32_t redoLogNum = taosArrayGetSize(pTrans->redoLogs);
|
||||
int32_t undoLogNum = taosArrayGetSize(pTrans->undoLogs);
|
||||
int32_t commitLogNum = taosArrayGetSize(pTrans->commitLogs);
|
||||
int32_t redoActionNum = taosArrayGetSize(pTrans->redoActions);
|
||||
int32_t undoActionNum = taosArrayGetSize(pTrans->undoActions);
|
||||
|
||||
for (int32_t i = 0; i < redoLogNum; ++i) {
|
||||
SSdbRaw *pTmp = taosArrayGet(pTrans->redoLogs, i);
|
||||
rawDataLen += sdbGetRawTotalSize(pTmp);
|
||||
}
|
||||
|
||||
for (int32_t i = 0; i < undoLogNum; ++i) {
|
||||
SSdbRaw *pTmp = taosArrayGet(pTrans->undoLogs, i);
|
||||
rawDataLen += sdbGetRawTotalSize(pTmp);
|
||||
}
|
||||
|
||||
for (int32_t i = 0; i < commitLogNum; ++i) {
|
||||
SSdbRaw *pTmp = taosArrayGet(pTrans->commitLogs, i);
|
||||
rawDataLen += sdbGetRawTotalSize(pTmp);
|
||||
}
|
||||
|
||||
SSdbRaw *pRaw = sdbAllocRaw(SDB_TRANS, SDB_TRANS_VER, rawDataLen);
|
||||
if (pRaw == NULL) {
|
||||
mError("trn:%d, failed to alloc raw since %s", pTrans->id, terrstr());
|
||||
return NULL;
|
||||
}
|
||||
|
||||
int32_t dataPos = 0;
|
||||
SDB_SET_INT32(pRaw, dataPos, pTrans->id)
|
||||
SDB_SET_INT8(pRaw, dataPos, pTrans->stage)
|
||||
SDB_SET_INT8(pRaw, dataPos, pTrans->policy)
|
||||
SDB_SET_INT32(pRaw, dataPos, redoLogNum)
|
||||
SDB_SET_INT32(pRaw, dataPos, undoLogNum)
|
||||
SDB_SET_INT32(pRaw, dataPos, commitLogNum)
|
||||
SDB_SET_INT32(pRaw, dataPos, redoActionNum)
|
||||
SDB_SET_INT32(pRaw, dataPos, undoActionNum)
|
||||
|
||||
for (int32_t i = 0; i < redoLogNum; ++i) {
|
||||
SSdbRaw *pTmp = taosArrayGet(pTrans->redoLogs, i);
|
||||
int32_t len = sdbGetRawTotalSize(pTmp);
|
||||
SDB_SET_INT32(pRaw, dataPos, len)
|
||||
SDB_SET_BINARY(pRaw, dataPos, (void *)pTmp, len)
|
||||
}
|
||||
|
||||
for (int32_t i = 0; i < undoLogNum; ++i) {
|
||||
SSdbRaw *pTmp = taosArrayGet(pTrans->undoLogs, i);
|
||||
int32_t len = sdbGetRawTotalSize(pTmp);
|
||||
SDB_SET_INT32(pRaw, dataPos, len)
|
||||
SDB_SET_BINARY(pRaw, dataPos, (void *)pTmp, len)
|
||||
}
|
||||
|
||||
for (int32_t i = 0; i < commitLogNum; ++i) {
|
||||
SSdbRaw *pTmp = taosArrayGet(pTrans->commitLogs, i);
|
||||
int32_t len = sdbGetRawTotalSize(pTmp);
|
||||
SDB_SET_INT32(pRaw, dataPos, len)
|
||||
SDB_SET_BINARY(pRaw, dataPos, (void *)pTmp, len)
|
||||
}
|
||||
|
||||
mDebug("trn:%d, is encoded as raw:%p, len:%d", pTrans->id, pRaw, dataPos);
|
||||
return pRaw;
|
||||
}
|
||||
|
||||
SSdbRow *mndTransActionDecode(SSdbRaw *pRaw) {
|
||||
int8_t sver = 0;
|
||||
if (sdbGetRawSoftVer(pRaw, &sver) != 0) {
|
||||
mError("failed to get soft ver from raw:%p since %s", pRaw, terrstr());
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (sver != SDB_TRANS_VER) {
|
||||
terrno = TSDB_CODE_SDB_INVALID_DATA_VER;
|
||||
mError("failed to get check soft ver from raw:%p since %s", pRaw, terrstr());
|
||||
return NULL;
|
||||
}
|
||||
|
||||
SSdbRow *pRow = sdbAllocRow(sizeof(STrans));
|
||||
STrans *pTrans = sdbGetRowObj(pRow);
|
||||
if (pTrans == NULL) {
|
||||
mError("failed to alloc trans from raw:%p since %s", pRaw, terrstr());
|
||||
return NULL;
|
||||
}
|
||||
|
||||
pTrans->redoLogs = taosArrayInit(TRN_DEFAULT_ARRAY_SIZE, sizeof(void *));
|
||||
pTrans->undoLogs = taosArrayInit(TRN_DEFAULT_ARRAY_SIZE, sizeof(void *));
|
||||
pTrans->commitLogs = taosArrayInit(TRN_DEFAULT_ARRAY_SIZE, sizeof(void *));
|
||||
pTrans->redoActions = taosArrayInit(TRN_DEFAULT_ARRAY_SIZE, sizeof(void *));
|
||||
pTrans->undoActions = taosArrayInit(TRN_DEFAULT_ARRAY_SIZE, sizeof(void *));
|
||||
|
||||
if (pTrans->redoLogs == NULL || pTrans->undoLogs == NULL || pTrans->commitLogs == NULL ||
|
||||
pTrans->redoActions == NULL || pTrans->undoActions == NULL) {
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
mDebug("trn:%d, failed to create array while parsed from raw:%p", pTrans->id, pRaw);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
int32_t redoLogNum = 0;
|
||||
int32_t undoLogNum = 0;
|
||||
int32_t commitLogNum = 0;
|
||||
int32_t redoActionNum = 0;
|
||||
int32_t undoActionNum = 0;
|
||||
|
||||
int32_t dataPos = 0;
|
||||
SDB_GET_INT32(pRaw, pRow, dataPos, &pTrans->id)
|
||||
SDB_GET_INT8(pRaw, pRow, dataPos, (int8_t *)&pTrans->stage)
|
||||
SDB_GET_INT8(pRaw, pRow, dataPos, (int8_t *)&pTrans->policy)
|
||||
SDB_GET_INT32(pRaw, pRow, dataPos, &redoLogNum)
|
||||
SDB_GET_INT32(pRaw, pRow, dataPos, &undoLogNum)
|
||||
SDB_GET_INT32(pRaw, pRow, dataPos, &commitLogNum)
|
||||
SDB_GET_INT32(pRaw, pRow, dataPos, &redoActionNum)
|
||||
SDB_GET_INT32(pRaw, pRow, dataPos, &undoActionNum)
|
||||
|
||||
int32_t code = 0;
|
||||
for (int32_t i = 0; i < redoLogNum; ++i) {
|
||||
int32_t dataLen = 0;
|
||||
SDB_GET_INT32(pRaw, pRow, dataPos, &dataLen)
|
||||
|
||||
char *pData = malloc(dataLen);
|
||||
SDB_GET_BINARY(pRaw, pRow, dataPos, pData, dataLen);
|
||||
void *ret = taosArrayPush(pTrans->redoLogs, pData);
|
||||
if (ret == NULL) {
|
||||
code = TSDB_CODE_OUT_OF_MEMORY;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (code != 0) {
|
||||
terrno = code;
|
||||
mError("trn:%d, failed to parse from raw:%p since %s", pTrans->id, pRaw, terrstr());
|
||||
mndTransDrop(pTrans);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
mDebug("trn:%d, is parsed from raw:%p", pTrans->id, pRaw);
|
||||
return pRow;
|
||||
}
|
||||
|
||||
static int32_t mndTransActionInsert(SSdb *pSdb, STrans *pTrans) {
|
||||
SArray *pArray = pTrans->redoLogs;
|
||||
int32_t arraySize = taosArrayGetSize(pArray);
|
||||
|
||||
for (int32_t i = 0; i < arraySize; ++i) {
|
||||
SSdbRaw *pRaw = taosArrayGet(pArray, i);
|
||||
int32_t code = sdbWrite(pSdb, pRaw);
|
||||
if (code != 0) {
|
||||
mError("trn:%d, failed to write raw:%p to sdb since %s", pTrans->id, pRaw, terrstr());
|
||||
return code;
|
||||
}
|
||||
}
|
||||
|
||||
mDebug("trn:%d, write to sdb", pTrans->id);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int32_t mndTransActionDelete(SSdb *pSdb, STrans *pTrans) {
|
||||
SArray *pArray = pTrans->redoLogs;
|
||||
int32_t arraySize = taosArrayGetSize(pArray);
|
||||
|
||||
for (int32_t i = 0; i < arraySize; ++i) {
|
||||
SSdbRaw *pRaw = taosArrayGet(pArray, i);
|
||||
int32_t code = sdbWrite(pSdb, pRaw);
|
||||
if (code != 0) {
|
||||
mError("trn:%d, failed to write raw:%p to sdb since %s", pTrans->id, pRaw, terrstr());
|
||||
return code;
|
||||
}
|
||||
}
|
||||
|
||||
mDebug("trn:%d, delete from sdb", pTrans->id);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int32_t mndTransActionUpdate(SSdb *pSdb, STrans *pTrans, STrans *pDstTrans) {
|
||||
assert(true);
|
||||
SArray *pArray = pTrans->redoLogs;
|
||||
int32_t arraySize = taosArrayGetSize(pArray);
|
||||
|
||||
for (int32_t i = 0; i < arraySize; ++i) {
|
||||
SSdbRaw *pRaw = taosArrayGet(pArray, i);
|
||||
int32_t code = sdbWrite(pSdb, pRaw);
|
||||
if (code != 0) {
|
||||
mError("trn:%d, failed to write raw:%p to sdb since %s", pTrans->id, pRaw, terrstr());
|
||||
return code;
|
||||
}
|
||||
}
|
||||
|
||||
pTrans->stage = pDstTrans->stage;
|
||||
mDebug("trn:%d, update in sdb", pTrans->id);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int32_t trnGenerateTransId() { return 1; }
|
||||
|
||||
STrans *mndTransCreate(SMnode *pMnode, ETrnPolicy policy, void *rpcHandle) {
|
||||
STrans *pTrans = calloc(1, sizeof(STrans));
|
||||
if (pTrans == NULL) {
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
mError("failed to create transaction since %s", terrstr());
|
||||
return NULL;
|
||||
}
|
||||
|
||||
pTrans->id = trnGenerateTransId();
|
||||
pTrans->stage = TRN_STAGE_PREPARE;
|
||||
pTrans->policy = policy;
|
||||
pTrans->rpcHandle = rpcHandle;
|
||||
pTrans->redoLogs = taosArrayInit(TRN_DEFAULT_ARRAY_SIZE, sizeof(void *));
|
||||
pTrans->undoLogs = taosArrayInit(TRN_DEFAULT_ARRAY_SIZE, sizeof(void *));
|
||||
pTrans->commitLogs = taosArrayInit(TRN_DEFAULT_ARRAY_SIZE, sizeof(void *));
|
||||
pTrans->redoActions = taosArrayInit(TRN_DEFAULT_ARRAY_SIZE, sizeof(void *));
|
||||
pTrans->undoActions = taosArrayInit(TRN_DEFAULT_ARRAY_SIZE, sizeof(void *));
|
||||
|
||||
if (pTrans->redoLogs == NULL || pTrans->undoLogs == NULL || pTrans->commitLogs == NULL ||
|
||||
pTrans->redoActions == NULL || pTrans->undoActions == NULL) {
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
mError("failed to create transaction since %s", terrstr());
|
||||
return NULL;
|
||||
}
|
||||
|
||||
mDebug("trn:%d, is created, %p", pTrans->id, pTrans);
|
||||
return pTrans;
|
||||
}
|
||||
|
||||
static void trnDropArray(SArray *pArray) {
|
||||
for (int32_t i = 0; i < pArray->size; ++i) {
|
||||
SSdbRaw *pRaw = taosArrayGet(pArray, i);
|
||||
tfree(pRaw);
|
||||
}
|
||||
|
||||
taosArrayDestroy(pArray);
|
||||
}
|
||||
|
||||
void mndTransDrop(STrans *pTrans) {
|
||||
trnDropArray(pTrans->redoLogs);
|
||||
trnDropArray(pTrans->undoLogs);
|
||||
trnDropArray(pTrans->commitLogs);
|
||||
trnDropArray(pTrans->redoActions);
|
||||
trnDropArray(pTrans->undoActions);
|
||||
|
||||
mDebug("trn:%d, is dropped, %p", pTrans->id, pTrans);
|
||||
tfree(pTrans);
|
||||
}
|
||||
|
||||
void mndTransSetRpcHandle(STrans *pTrans, void *rpcHandle) {
|
||||
pTrans->rpcHandle = rpcHandle;
|
||||
mTrace("trn:%d, set rpc handle:%p", pTrans->id, rpcHandle);
|
||||
}
|
||||
|
||||
static int32_t mndTransAppendArray(SArray *pArray, SSdbRaw *pRaw) {
|
||||
if (pArray == NULL || pRaw == NULL) {
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
return -1;
|
||||
}
|
||||
|
||||
void *ptr = taosArrayPush(pArray, pRaw);
|
||||
if (ptr == NULL) {
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int32_t mndTransAppendRedolog(STrans *pTrans, SSdbRaw *pRaw) {
|
||||
int32_t code = mndTransAppendArray(pTrans->redoLogs, pRaw);
|
||||
mTrace("trn:%d, raw:%p append to redo logs, code:%d", pTrans->id, pRaw, code);
|
||||
return code;
|
||||
}
|
||||
|
||||
int32_t mndTransAppendUndolog(STrans *pTrans, SSdbRaw *pRaw) {
|
||||
int32_t code = mndTransAppendArray(pTrans->undoLogs, pRaw);
|
||||
mTrace("trn:%d, raw:%p append to undo logs, code:%d", pTrans->id, pRaw, code);
|
||||
return code;
|
||||
}
|
||||
|
||||
int32_t mndTransAppendCommitlog(STrans *pTrans, SSdbRaw *pRaw) {
|
||||
int32_t code = mndTransAppendArray(pTrans->commitLogs, pRaw);
|
||||
mTrace("trn:%d, raw:%p append to commit logs, code:%d", pTrans->id, pRaw, code);
|
||||
return code;
|
||||
}
|
||||
|
||||
int32_t mndTransAppendRedoAction(STrans *pTrans, SEpSet *pEpSet, void *pMsg) {
|
||||
int32_t code = mndTransAppendArray(pTrans->redoActions, pMsg);
|
||||
mTrace("trn:%d, msg:%p append to redo actions", pTrans->id, pMsg);
|
||||
return code;
|
||||
}
|
||||
|
||||
int32_t mndTransAppendUndoAction(STrans *pTrans, SEpSet *pEpSet, void *pMsg) {
|
||||
int32_t code = mndTransAppendArray(pTrans->undoActions, pMsg);
|
||||
mTrace("trn:%d, msg:%p append to undo actions", pTrans->id, pMsg);
|
||||
return code;
|
||||
}
|
||||
|
||||
int32_t mndInitTrans(SMnode *pMnode) {
|
||||
SSdbTable table = {.sdbType = SDB_TRANS,
|
||||
.keyType = SDB_KEY_INT32,
|
||||
.encodeFp = (SdbEncodeFp)mndTransActionEncode,
|
||||
.decodeFp = (SdbDecodeFp)mndTransActionDecode,
|
||||
.insertFp = (SdbInsertFp)mndTransActionInsert,
|
||||
.updateFp = (SdbUpdateFp)mndTransActionUpdate,
|
||||
.deleteFp = (SdbDeleteFp)mndTransActionDelete};
|
||||
|
||||
return sdbSetTable(pMnode->pSdb, table);
|
||||
}
|
||||
|
||||
void mndCleanupTrans(SMnode *pMnode) {}
|
||||
|
||||
int32_t mndTransPrepare(STrans *pTrans, int32_t (*syncfp)(SSdbRaw *pRaw, void *pData)) {
|
||||
if (syncfp == NULL) return -1;
|
||||
|
||||
SSdbRaw *pRaw = mndTransActionEncode(pTrans);
|
||||
if (pRaw == NULL) {
|
||||
mError("trn:%d, failed to decode trans since %s", pTrans->id, terrstr());
|
||||
return -1;
|
||||
}
|
||||
sdbSetRawStatus(pRaw, SDB_STATUS_CREATING);
|
||||
|
||||
if (sdbWrite(pTrans->pMnode->pSdb, pRaw) != 0) {
|
||||
mError("trn:%d, failed to write trans since %s", pTrans->id, terrstr());
|
||||
return -1;
|
||||
}
|
||||
|
||||
if ((*syncfp)(pRaw, pTrans->rpcHandle) != 0) {
|
||||
mError("trn:%d, failed to sync trans since %s", pTrans->id, terrstr());
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void trnSendRpcRsp(void *rpcHandle, int32_t code) {
|
||||
if (rpcHandle != NULL) {
|
||||
SRpcMsg rspMsg = {.handle = rpcHandle, .code = terrno};
|
||||
rpcSendResponse(&rspMsg);
|
||||
}
|
||||
}
|
||||
|
||||
int32_t mndTransApply(SMnode *pMnode, SSdbRaw *pRaw, void *pData, int32_t code) {
|
||||
if (code != 0) {
|
||||
trnSendRpcRsp(pData, terrno);
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (sdbWrite(pMnode->pSdb, pData) != 0) {
|
||||
code = terrno;
|
||||
trnSendRpcRsp(pData, code);
|
||||
terrno = code;
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int32_t trnExecuteArray(SMnode *pMnode, SArray *pArray) {
|
||||
for (int32_t i = 0; i < pArray->size; ++i) {
|
||||
SSdbRaw *pRaw = taosArrayGetP(pArray, i);
|
||||
if (sdbWrite(pMnode->pSdb, pRaw) != 0) {
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int32_t trnExecuteRedoLogs(STrans *pTrans) { return trnExecuteArray(pTrans->pMnode, pTrans->redoLogs); }
|
||||
|
||||
static int32_t trnExecuteUndoLogs(STrans *pTrans) { return trnExecuteArray(pTrans->pMnode, pTrans->undoLogs); }
|
||||
|
||||
static int32_t trnExecuteCommitLogs(STrans *pTrans) { return trnExecuteArray(pTrans->pMnode, pTrans->commitLogs); }
|
||||
|
||||
static int32_t trnExecuteRedoActions(STrans *pTrans) { return trnExecuteArray(pTrans->pMnode, pTrans->redoActions); }
|
||||
|
||||
static int32_t trnExecuteUndoActions(STrans *pTrans) { return trnExecuteArray(pTrans->pMnode, pTrans->undoActions); }
|
||||
|
||||
static int32_t trnPerformPrepareStage(STrans *pTrans) {
|
||||
if (trnExecuteRedoLogs(pTrans) == 0) {
|
||||
pTrans->stage = TRN_STAGE_EXECUTE;
|
||||
return 0;
|
||||
} else {
|
||||
pTrans->stage = TRN_STAGE_ROLLBACK;
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
static int32_t trnPerformExecuteStage(STrans *pTrans) {
|
||||
int32_t code = trnExecuteRedoActions(pTrans);
|
||||
|
||||
if (code == 0) {
|
||||
pTrans->stage = TRN_STAGE_COMMIT;
|
||||
return 0;
|
||||
} else if (code == TSDB_CODE_MND_ACTION_IN_PROGRESS) {
|
||||
return -1;
|
||||
} else {
|
||||
if (pTrans->policy == TRN_POLICY_RETRY) {
|
||||
pTrans->stage = TRN_STAGE_RETRY;
|
||||
} else {
|
||||
pTrans->stage = TRN_STAGE_ROLLBACK;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
static int32_t trnPerformCommitStage(STrans *pTrans) {
|
||||
if (trnExecuteCommitLogs(pTrans) == 0) {
|
||||
pTrans->stage = TRN_STAGE_EXECUTE;
|
||||
return 0;
|
||||
} else {
|
||||
pTrans->stage = TRN_STAGE_ROLLBACK;
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
static int32_t trnPerformRollbackStage(STrans *pTrans) {
|
||||
if (trnExecuteCommitLogs(pTrans) == 0) {
|
||||
pTrans->stage = TRN_STAGE_EXECUTE;
|
||||
return 0;
|
||||
} else {
|
||||
pTrans->stage = TRN_STAGE_ROLLBACK;
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
static int32_t trnPerformRetryStage(STrans *pTrans) {
|
||||
if (trnExecuteCommitLogs(pTrans) == 0) {
|
||||
pTrans->stage = TRN_STAGE_EXECUTE;
|
||||
return 0;
|
||||
} else {
|
||||
pTrans->stage = TRN_STAGE_ROLLBACK;
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
int32_t mndTransExecute(SSdb *pSdb, int32_t tranId) {
|
||||
int32_t code = 0;
|
||||
|
||||
STrans *pTrans = sdbAcquire(pSdb, SDB_TRANS, &tranId);
|
||||
if (pTrans == NULL) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (pTrans->stage == TRN_STAGE_PREPARE) {
|
||||
if (trnPerformPrepareStage(pTrans) != 0) {
|
||||
sdbRelease(pSdb, pTrans);
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
if (pTrans->stage == TRN_STAGE_EXECUTE) {
|
||||
if (trnPerformExecuteStage(pTrans) != 0) {
|
||||
sdbRelease(pSdb, pTrans);
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
if (pTrans->stage == TRN_STAGE_COMMIT) {
|
||||
if (trnPerformCommitStage(pTrans) != 0) {
|
||||
sdbRelease(pSdb, pTrans);
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
if (pTrans->stage == TRN_STAGE_ROLLBACK) {
|
||||
if (trnPerformRollbackStage(pTrans) != 0) {
|
||||
sdbRelease(pSdb, pTrans);
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
if (pTrans->stage == TRN_STAGE_RETRY) {
|
||||
if (trnPerformRetryStage(pTrans) != 0) {
|
||||
sdbRelease(pSdb, pTrans);
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
sdbRelease(pSdb, pTrans);
|
||||
return 0;
|
||||
}
|
|
@ -14,14 +14,13 @@
|
|||
*/
|
||||
|
||||
#define _DEFAULT_SOURCE
|
||||
#include "mnodeSync.h"
|
||||
#include "os.h"
|
||||
#include "tglobal.h"
|
||||
#include "mndSync.h"
|
||||
#include "tkey.h"
|
||||
#include "mndTrans.h"
|
||||
|
||||
#define SDB_USER_VER 1
|
||||
|
||||
static SSdbRaw *mnodeUserActionEncode(SUserObj *pUser) {
|
||||
static SSdbRaw *mndUserActionEncode(SUserObj *pUser) {
|
||||
SSdbRaw *pRaw = sdbAllocRaw(SDB_USER, SDB_USER_VER, sizeof(SAcctObj));
|
||||
if (pRaw == NULL) return NULL;
|
||||
|
||||
|
@ -37,7 +36,7 @@ static SSdbRaw *mnodeUserActionEncode(SUserObj *pUser) {
|
|||
return pRaw;
|
||||
}
|
||||
|
||||
static SSdbRow *mnodeUserActionDecode(SSdbRaw *pRaw) {
|
||||
static SSdbRow *mndUserActionDecode(SSdbRaw *pRaw) {
|
||||
int8_t sver = 0;
|
||||
if (sdbGetRawSoftVer(pRaw, &sver) != 0) return NULL;
|
||||
|
||||
|
@ -61,14 +60,14 @@ static SSdbRow *mnodeUserActionDecode(SSdbRaw *pRaw) {
|
|||
return pRow;
|
||||
}
|
||||
|
||||
static int32_t mnodeUserActionInsert(SUserObj *pUser) {
|
||||
static int32_t mndUserActionInsert(SSdb *pSdb, SUserObj *pUser) {
|
||||
pUser->prohibitDbHash = taosHashInit(8, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BINARY), true, HASH_ENTRY_LOCK);
|
||||
if (pUser->prohibitDbHash == NULL) {
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
return -1;
|
||||
}
|
||||
|
||||
pUser->pAcct = sdbAcquire(SDB_ACCT, pUser->acct);
|
||||
pUser->pAcct = sdbAcquire(pSdb, SDB_ACCT, pUser->acct);
|
||||
if (pUser->pAcct == NULL) {
|
||||
terrno = TSDB_CODE_MND_ACCT_NOT_EXIST;
|
||||
return -1;
|
||||
|
@ -77,28 +76,28 @@ static int32_t mnodeUserActionInsert(SUserObj *pUser) {
|
|||
return 0;
|
||||
}
|
||||
|
||||
static int32_t mnodeUserActionDelete(SUserObj *pUser) {
|
||||
static int32_t mndUserActionDelete(SSdb *pSdb, SUserObj *pUser) {
|
||||
if (pUser->prohibitDbHash) {
|
||||
taosHashCleanup(pUser->prohibitDbHash);
|
||||
pUser->prohibitDbHash = NULL;
|
||||
}
|
||||
|
||||
if (pUser->acct != NULL) {
|
||||
sdbRelease(pUser->pAcct);
|
||||
sdbRelease(pSdb, pUser->pAcct);
|
||||
pUser->pAcct = NULL;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int32_t mnodeUserActionUpdate(SUserObj *pSrcUser, SUserObj *pDstUser) {
|
||||
static int32_t mndUserActionUpdate(SSdb *pSdb, SUserObj *pSrcUser, SUserObj *pDstUser) {
|
||||
SUserObj tObj;
|
||||
int32_t len = (int32_t)((int8_t *)tObj.prohibitDbHash - (int8_t *)&tObj);
|
||||
memcpy(pDstUser, pSrcUser, len);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int32_t mnodeCreateDefaultUser(char *acct, char *user, char *pass) {
|
||||
static int32_t mndCreateDefaultUser(SSdb *pSdb, char *acct, char *user, char *pass) {
|
||||
SUserObj userObj = {0};
|
||||
tstrncpy(userObj.user, user, TSDB_USER_LEN);
|
||||
tstrncpy(userObj.acct, acct, TSDB_USER_LEN);
|
||||
|
@ -110,30 +109,26 @@ static int32_t mnodeCreateDefaultUser(char *acct, char *user, char *pass) {
|
|||
userObj.rootAuth = 1;
|
||||
}
|
||||
|
||||
SSdbRaw *pRaw = mnodeUserActionEncode(&userObj);
|
||||
SSdbRaw *pRaw = mndUserActionEncode(&userObj);
|
||||
if (pRaw == NULL) return -1;
|
||||
sdbSetRawStatus(pRaw, SDB_STATUS_READY);
|
||||
|
||||
return sdbWrite(pRaw);
|
||||
return sdbWrite(pSdb, pRaw);
|
||||
}
|
||||
|
||||
static int32_t mnodeCreateDefaultUsers() {
|
||||
if (mnodeCreateDefaultUser(TSDB_DEFAULT_USER, TSDB_DEFAULT_USER, TSDB_DEFAULT_PASS) != 0) {
|
||||
static int32_t mndCreateDefaultUsers(SSdb *pSdb) {
|
||||
if (mndCreateDefaultUser(pSdb, TSDB_DEFAULT_USER, TSDB_DEFAULT_USER, TSDB_DEFAULT_PASS) != 0) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (mnodeCreateDefaultUser(TSDB_DEFAULT_USER, "monitor", tsInternalPass) != 0) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (mnodeCreateDefaultUser(TSDB_DEFAULT_USER, "_" TSDB_DEFAULT_USER, tsInternalPass) != 0) {
|
||||
if (mndCreateDefaultUser(pSdb, TSDB_DEFAULT_USER, "_" TSDB_DEFAULT_USER, TSDB_DEFAULT_PASS) != 0) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int32_t mnodeCreateUser(char *acct, char *user, char *pass, SMnodeMsg *pMsg) {
|
||||
static int32_t mndCreateUser(SMnode *pMnode, char *acct, char *user, char *pass, SMnodeMsg *pMsg) {
|
||||
SUserObj userObj = {0};
|
||||
tstrncpy(userObj.user, user, TSDB_USER_LEN);
|
||||
tstrncpy(userObj.acct, acct, TSDB_USER_LEN);
|
||||
|
@ -142,41 +137,43 @@ static int32_t mnodeCreateUser(char *acct, char *user, char *pass, SMnodeMsg *pM
|
|||
userObj.updateTime = userObj.createdTime;
|
||||
userObj.rootAuth = 0;
|
||||
|
||||
STrans *pTrans = trnCreate(TRN_POLICY_ROLLBACK);
|
||||
STrans *pTrans = mndTransCreate(pMnode, TRN_POLICY_ROLLBACK, pMsg->rpcMsg.handle);
|
||||
if (pTrans == NULL) return -1;
|
||||
trnSetRpcHandle(pTrans, pMsg->rpcMsg.handle);
|
||||
|
||||
SSdbRaw *pRedoRaw = mnodeUserActionEncode(&userObj);
|
||||
if (pRedoRaw == NULL || trnAppendRedoLog(pTrans, pRedoRaw) != 0) {
|
||||
trnDrop(pTrans);
|
||||
SSdbRaw *pRedoRaw = mndUserActionEncode(&userObj);
|
||||
if (pRedoRaw == NULL || mndTransAppendRedolog(pTrans, pRedoRaw) != 0) {
|
||||
mError("failed to append redo log since %s", terrstr());
|
||||
mndTransDrop(pTrans);
|
||||
return -1;
|
||||
}
|
||||
sdbSetRawStatus(pRedoRaw, SDB_STATUS_CREATING);
|
||||
|
||||
SSdbRaw *pUndoRaw = mnodeUserActionEncode(&userObj);
|
||||
if (pUndoRaw == NULL || trnAppendUndoLog(pTrans, pUndoRaw) != 0) {
|
||||
trnDrop(pTrans);
|
||||
SSdbRaw *pUndoRaw = mndUserActionEncode(&userObj);
|
||||
if (pUndoRaw == NULL || mndTransAppendUndolog(pTrans, pUndoRaw) != 0) {
|
||||
mError("failed to append undo log since %s", terrstr());
|
||||
mndTransDrop(pTrans);
|
||||
return -1;
|
||||
}
|
||||
sdbSetRawStatus(pUndoRaw, SDB_STATUS_DROPPED);
|
||||
|
||||
SSdbRaw *pCommitRaw = mnodeUserActionEncode(&userObj);
|
||||
if (pCommitRaw == NULL || trnAppendCommitLog(pTrans, pCommitRaw) != 0) {
|
||||
trnDrop(pTrans);
|
||||
SSdbRaw *pCommitRaw = mndUserActionEncode(&userObj);
|
||||
if (pCommitRaw == NULL || mndTransAppendCommitlog(pTrans, pCommitRaw) != 0) {
|
||||
mError("failed to append commit log since %s", terrstr());
|
||||
mndTransDrop(pTrans);
|
||||
return -1;
|
||||
}
|
||||
sdbSetRawStatus(pCommitRaw, SDB_STATUS_READY);
|
||||
|
||||
if (trnPrepare(pTrans, mnodeSyncPropose) != 0) {
|
||||
trnDrop(pTrans);
|
||||
if (mndTransPrepare(pTrans, mndSyncPropose) != 0) {
|
||||
mndTransDrop(pTrans);
|
||||
return -1;
|
||||
}
|
||||
|
||||
trnDrop(pTrans);
|
||||
mndTransDrop(pTrans);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int32_t mnodeProcessCreateUserMsg(SMnodeMsg *pMsg) {
|
||||
static int32_t mndProcessCreateUserMsg(SMnode *pMnode, SMnodeMsg *pMsg) {
|
||||
SCreateUserMsg *pCreate = pMsg->rpcMsg.pCont;
|
||||
|
||||
if (pCreate->user[0] == 0) {
|
||||
|
@ -191,23 +188,23 @@ static int32_t mnodeProcessCreateUserMsg(SMnodeMsg *pMsg) {
|
|||
return -1;
|
||||
}
|
||||
|
||||
SUserObj *pUser = sdbAcquire(SDB_USER, pCreate->user);
|
||||
SUserObj *pUser = sdbAcquire(pMnode->pSdb, SDB_USER, pCreate->user);
|
||||
if (pUser != NULL) {
|
||||
sdbRelease(pUser);
|
||||
sdbRelease(pMnode->pSdb, pUser);
|
||||
terrno = TSDB_CODE_MND_USER_ALREADY_EXIST;
|
||||
mError("user:%s, failed to create since %s", pCreate->user, terrstr());
|
||||
return -1;
|
||||
}
|
||||
|
||||
SUserObj *pOperUser = sdbAcquire(SDB_USER, pMsg->conn.user);
|
||||
SUserObj *pOperUser = sdbAcquire(pMnode->pSdb, SDB_USER, pMsg->conn.user);
|
||||
if (pOperUser == NULL) {
|
||||
terrno = TSDB_CODE_MND_NO_USER_FROM_CONN;
|
||||
mError("user:%s, failed to create since %s", pCreate->user, terrstr());
|
||||
return -1;
|
||||
}
|
||||
|
||||
int32_t code = mnodeCreateUser(pOperUser->acct, pCreate->user, pCreate->pass, pMsg);
|
||||
sdbRelease(pOperUser);
|
||||
int32_t code = mndCreateUser(pMnode, pOperUser->acct, pCreate->user, pCreate->pass, pMsg);
|
||||
sdbRelease(pMnode->pSdb, pOperUser);
|
||||
|
||||
if (code != 0) {
|
||||
mError("user:%s, failed to create since %s", pCreate->user, terrstr());
|
||||
|
@ -217,18 +214,19 @@ static int32_t mnodeProcessCreateUserMsg(SMnodeMsg *pMsg) {
|
|||
return TSDB_CODE_MND_ACTION_IN_PROGRESS;
|
||||
}
|
||||
|
||||
int32_t mnodeInitUser() {
|
||||
int32_t mndInitUser(SMnode *pMnode) {
|
||||
SSdbTable table = {.sdbType = SDB_USER,
|
||||
.keyType = SDB_KEY_BINARY,
|
||||
.deployFp = (SdbDeployFp)mnodeCreateDefaultUsers,
|
||||
.encodeFp = (SdbEncodeFp)mnodeUserActionEncode,
|
||||
.decodeFp = (SdbDecodeFp)mnodeUserActionDecode,
|
||||
.insertFp = (SdbInsertFp)mnodeUserActionInsert,
|
||||
.updateFp = (SdbUpdateFp)mnodeUserActionUpdate,
|
||||
.deleteFp = (SdbDeleteFp)mnodeUserActionDelete};
|
||||
sdbSetTable(table);
|
||||
.deployFp = (SdbDeployFp)mndCreateDefaultUsers,
|
||||
.encodeFp = (SdbEncodeFp)mndUserActionEncode,
|
||||
.decodeFp = (SdbDecodeFp)mndUserActionDecode,
|
||||
.insertFp = (SdbInsertFp)mndUserActionInsert,
|
||||
.updateFp = (SdbUpdateFp)mndUserActionUpdate,
|
||||
.deleteFp = (SdbDeleteFp)mndUserActionDelete};
|
||||
|
||||
return 0;
|
||||
mndSetMsgHandle(pMnode, TSDB_MSG_TYPE_CREATE_USER, mndProcessCreateUserMsg);
|
||||
|
||||
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,186 +14,324 @@
|
|||
*/
|
||||
|
||||
#define _DEFAULT_SOURCE
|
||||
#include "os.h"
|
||||
#include "tglobal.h"
|
||||
#include "tstep.h"
|
||||
#include "tqueue.h"
|
||||
#include "mnodeAcct.h"
|
||||
#include "mnodeAuth.h"
|
||||
#include "mnodeBalance.h"
|
||||
#include "mnodeCluster.h"
|
||||
#include "mnodeDb.h"
|
||||
#include "mnodeDnode.h"
|
||||
#include "mnodeFunc.h"
|
||||
#include "mnodeMnode.h"
|
||||
#include "mnodeOper.h"
|
||||
#include "mnodeProfile.h"
|
||||
#include "mnodeShow.h"
|
||||
#include "mnodeStable.h"
|
||||
#include "mnodeSync.h"
|
||||
#include "mnodeTelem.h"
|
||||
#include "mnodeUser.h"
|
||||
#include "mnodeVgroup.h"
|
||||
#include "mndAcct.h"
|
||||
#include "mndAuth.h"
|
||||
#include "mndBalance.h"
|
||||
#include "mndCluster.h"
|
||||
#include "mndDb.h"
|
||||
#include "mndDnode.h"
|
||||
#include "mndFunc.h"
|
||||
#include "mndMnode.h"
|
||||
#include "mndOper.h"
|
||||
#include "mndProfile.h"
|
||||
#include "mndShow.h"
|
||||
#include "mndStable.h"
|
||||
#include "mndSync.h"
|
||||
#include "mndTelem.h"
|
||||
#include "mndTrans.h"
|
||||
#include "mndUser.h"
|
||||
#include "mndVgroup.h"
|
||||
|
||||
static struct {
|
||||
int32_t dnodeId;
|
||||
int64_t clusterId;
|
||||
tmr_h timer;
|
||||
SSteps *pInitSteps;
|
||||
SSteps *pStartSteps;
|
||||
SMnodePara para;
|
||||
MnodeRpcFp msgFp[TSDB_MSG_TYPE_MAX];
|
||||
} tsMint;
|
||||
|
||||
int32_t mnodeGetDnodeId() { return tsMint.para.dnodeId; }
|
||||
|
||||
int64_t mnodeGetClusterId() { return tsMint.para.clusterId; }
|
||||
|
||||
void mnodeSendMsgToDnode(struct SEpSet *epSet, struct SRpcMsg *rpcMsg) { (*tsMint.para.SendMsgToDnode)(epSet, rpcMsg); }
|
||||
|
||||
void mnodeSendMsgToMnode(struct SRpcMsg *rpcMsg) { return (*tsMint.para.SendMsgToMnode)(rpcMsg); }
|
||||
|
||||
void mnodeSendRedirectMsg(struct SRpcMsg *rpcMsg, bool forShell) { (*tsMint.para.SendRedirectMsg)(rpcMsg, forShell); }
|
||||
|
||||
static int32_t mnodeInitTimer() {
|
||||
if (tsMint.timer == NULL) {
|
||||
tsMint.timer = taosTmrInit(tsMaxShellConns, 200, 3600000, "MND");
|
||||
int32_t mndGetDnodeId(SMnode *pMnode) {
|
||||
if (pMnode != NULL) {
|
||||
return pMnode->dnodeId;
|
||||
}
|
||||
|
||||
if (tsMint.timer == NULL) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
int64_t mndGetClusterId(SMnode *pMnode) {
|
||||
if (pMnode != NULL) {
|
||||
return pMnode->clusterId;
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
tmr_h mndGetTimer(SMnode *pMnode) {
|
||||
if (pMnode != NULL) {
|
||||
return pMnode->timer;
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void mndSendMsgToDnode(SMnode *pMnode, SEpSet *pEpSet, SRpcMsg *pMsg) {
|
||||
if (pMnode != NULL && pMnode->sendMsgToDnodeFp != NULL) {
|
||||
(*pMnode->sendMsgToDnodeFp)(pMnode->pDnode, pEpSet, pMsg);
|
||||
}
|
||||
}
|
||||
|
||||
void mndSendMsgToMnode(SMnode *pMnode, SRpcMsg *pMsg) {
|
||||
if (pMnode != NULL && pMnode->sendMsgToMnodeFp != NULL) {
|
||||
(*pMnode->sendMsgToMnodeFp)(pMnode->pDnode, pMsg);
|
||||
}
|
||||
}
|
||||
|
||||
void mndSendRedirectMsg(SMnode *pMnode, SRpcMsg *pMsg) {
|
||||
if (pMnode != NULL && pMnode->sendRedirectMsgFp != NULL) {
|
||||
(*pMnode->sendRedirectMsgFp)(pMnode->pDnode, pMsg);
|
||||
}
|
||||
}
|
||||
|
||||
static int32_t mndInitTimer(SMnode *pMnode) {
|
||||
if (pMnode->timer == NULL) {
|
||||
pMnode->timer = taosTmrInit(5000, 200, 3600000, "MND");
|
||||
}
|
||||
|
||||
if (pMnode->timer == NULL) {
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void mnodeCleanupTimer() {
|
||||
if (tsMint.timer != NULL) {
|
||||
taosTmrCleanUp(tsMint.timer);
|
||||
tsMint.timer = NULL;
|
||||
static void mndCleanupTimer(SMnode *pMnode) {
|
||||
if (pMnode->timer != NULL) {
|
||||
taosTmrCleanUp(pMnode->timer);
|
||||
pMnode->timer = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
tmr_h mnodeGetTimer() { return tsMint.timer; }
|
||||
|
||||
static int32_t mnodeSetPara(SMnodePara para) {
|
||||
tsMint.para = para;
|
||||
|
||||
if (tsMint.para.SendMsgToDnode == NULL) {
|
||||
terrno = TSDB_CODE_MND_APP_ERROR;
|
||||
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;
|
||||
}
|
||||
|
||||
if (tsMint.para.SendMsgToMnode == NULL) {
|
||||
terrno = TSDB_CODE_MND_APP_ERROR;
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (tsMint.para.SendRedirectMsg == NULL) {
|
||||
terrno = TSDB_CODE_MND_APP_ERROR;
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (tsMint.para.PutMsgIntoApplyQueue == NULL) {
|
||||
terrno = TSDB_CODE_MND_APP_ERROR;
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (tsMint.para.dnodeId < 0) {
|
||||
terrno = TSDB_CODE_MND_APP_ERROR;
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (tsMint.para.clusterId < 0) {
|
||||
terrno = TSDB_CODE_MND_APP_ERROR;
|
||||
if (taosMkDir(pMnode->path) != 0) {
|
||||
terrno = TAOS_SYSTEM_ERROR(errno);
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int32_t mnodeAllocInitSteps() {
|
||||
struct SSteps *steps = taosStepInit(16, NULL);
|
||||
if (steps == NULL) return -1;
|
||||
static int32_t mndInitSdb(SMnode *pMnode) {
|
||||
SSdbOpt opt = {0};
|
||||
opt.path = pMnode->path;
|
||||
|
||||
if (taosStepAdd(steps, "mnode-trans", trnInit, trnCleanup) != 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;
|
||||
pMnode->pSdb = sdbInit(&opt);
|
||||
if (pMnode->pSdb == NULL) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
tsMint.pInitSteps = steps;
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int32_t mnodeAllocStartSteps() {
|
||||
struct SSteps *steps = taosStepInit(8, NULL);
|
||||
if (steps == NULL) return -1;
|
||||
static int32_t mndDeploySdb(SMnode *pMnode) { return sdbDeploy(pMnode->pSdb); }
|
||||
static int32_t mndReadSdb(SMnode *pMnode) { return sdbReadFile(pMnode->pSdb); }
|
||||
|
||||
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);
|
||||
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;
|
||||
}
|
||||
|
||||
tsMint.pStartSteps = steps;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int32_t mnodeInit(SMnodePara para) {
|
||||
if (mnodeSetPara(para) != 0) {
|
||||
mError("failed to init mnode para since %s", terrstr());
|
||||
return -1;
|
||||
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;
|
||||
|
||||
if (mnodeAllocInitSteps() != 0) {
|
||||
mError("failed to alloc init steps since %s", terrstr());
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (mnodeAllocStartSteps() != 0) {
|
||||
mError("failed to alloc start steps since %s", terrstr());
|
||||
return -1;
|
||||
}
|
||||
|
||||
return taosStepExec(tsMint.pInitSteps);
|
||||
return 0;
|
||||
}
|
||||
|
||||
void mnodeCleanup() { taosStepCleanup(tsMint.pInitSteps); }
|
||||
static void mndCleanupSteps(SMnode *pMnode, int32_t pos) {
|
||||
if (pMnode->pSteps == NULL) return;
|
||||
|
||||
int32_t mnodeDeploy(SMnodeCfg *pCfg) {
|
||||
if (tsMint.para.dnodeId <= 0 && tsMint.para.clusterId <= 0) {
|
||||
if (sdbDeploy() != 0) {
|
||||
mError("failed to deploy sdb since %s", terrstr());
|
||||
return -1;
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
mDebug("mnode is deployed");
|
||||
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;
|
||||
}
|
||||
|
||||
void mnodeUnDeploy() { sdbUnDeploy(); }
|
||||
static int32_t mndSetOptions(SMnode *pMnode, const SMnodeOpt *pOption) {
|
||||
pMnode->dnodeId = pOption->dnodeId;
|
||||
pMnode->clusterId = pOption->clusterId;
|
||||
pMnode->replica = pOption->replica;
|
||||
pMnode->selfIndex = pOption->selfIndex;
|
||||
memcpy(&pMnode->replicas, pOption->replicas, sizeof(SReplica) * TSDB_MAX_REPLICA);
|
||||
pMnode->pDnode = pOption->pDnode;
|
||||
pMnode->putMsgToApplyMsgFp = pOption->putMsgToApplyMsgFp;
|
||||
pMnode->sendMsgToDnodeFp = pOption->sendMsgToDnodeFp;
|
||||
pMnode->sendMsgToMnodeFp = pOption->sendMsgToMnodeFp;
|
||||
pMnode->sendRedirectMsgFp = pOption->sendRedirectMsgFp;
|
||||
|
||||
int32_t mnodeStart(SMnodeCfg *pCfg) { return taosStepExec(tsMint.pStartSteps); }
|
||||
if (pMnode->sendMsgToDnodeFp == NULL || pMnode->sendMsgToMnodeFp == NULL || pMnode->sendRedirectMsgFp == NULL ||
|
||||
pMnode->putMsgToApplyMsgFp == NULL) {
|
||||
terrno = TSDB_CODE_MND_APP_ERROR;
|
||||
return -1;
|
||||
}
|
||||
|
||||
int32_t mnodeAlter(SMnodeCfg *pCfg) { return 0; }
|
||||
if (pMnode->dnodeId < 0 || pMnode->clusterId < 0) {
|
||||
terrno = TSDB_CODE_MND_APP_ERROR;
|
||||
return -1;
|
||||
}
|
||||
|
||||
void mnodeStop() { taosStepCleanup(tsMint.pStartSteps); }
|
||||
return 0;
|
||||
}
|
||||
|
||||
int32_t mnodeGetLoad(SMnodeLoad *pLoad) { return 0; }
|
||||
SMnode *mndOpen(const char *path, const SMnodeOpt *pOption) {
|
||||
mDebug("start to open mnode in %s", path);
|
||||
|
||||
SMnodeMsg *mnodeInitMsg(SRpcMsg *pRpcMsg) {
|
||||
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;
|
||||
}
|
||||
|
||||
pMnode->pSteps = taosArrayInit(24, sizeof(SMnodeStep));
|
||||
if (pMnode->pSteps == NULL) {
|
||||
free(pMnode);
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
mError("failed to open mnode since %s", terrstr());
|
||||
return NULL;
|
||||
}
|
||||
|
||||
int32_t code = mnodeCreateDir(pMnode, path);
|
||||
if (mnodeCreateDir(pMnode, path) != 0) {
|
||||
mError("failed to open mnode since %s", tstrerror(code));
|
||||
mndClose(pMnode);
|
||||
terrno = code;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
code = mndSetOptions(pMnode, pOption);
|
||||
if (code != 0) {
|
||||
mError("failed to open mnode since %s", tstrerror(code));
|
||||
mndClose(pMnode);
|
||||
terrno = code;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
code = mndInitSteps(pMnode);
|
||||
if (code != 0) {
|
||||
mError("failed to open mnode since %s", tstrerror(code));
|
||||
mndClose(pMnode);
|
||||
terrno = code;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
code = mndExecSteps(pMnode);
|
||||
if (code != 0) {
|
||||
mError("failed to open mnode since %s", tstrerror(code));
|
||||
mndClose(pMnode);
|
||||
terrno = code;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
mDebug("mnode open successfully ");
|
||||
return pMnode;
|
||||
}
|
||||
|
||||
void 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 mndAlter(SMnode *pMnode, const SMnodeOpt *pOption) {
|
||||
mDebug("start to alter mnode");
|
||||
mDebug("mnode is altered");
|
||||
return 0;
|
||||
}
|
||||
|
||||
void mndDestroy(const char *path) {
|
||||
mDebug("start to destroy mnode at %s", path);
|
||||
taosRemoveDir(path);
|
||||
mDebug("mnode is destroyed");
|
||||
}
|
||||
|
||||
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;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
SMnodeMsg *mndInitMsg(SMnode *pMnode, SRpcMsg *pRpcMsg) {
|
||||
SMnodeMsg *pMsg = taosAllocateQitem(sizeof(SMnodeMsg));
|
||||
if (pMsg == NULL) {
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
|
@ -201,7 +339,7 @@ SMnodeMsg *mnodeInitMsg(SRpcMsg *pRpcMsg) {
|
|||
}
|
||||
|
||||
if (rpcGetConnInfo(pRpcMsg->handle, &pMsg->conn) != 0) {
|
||||
mnodeCleanupMsg(pMsg);
|
||||
mndCleanupMsg(pMsg);
|
||||
mError("can not get user from conn:%p", pMsg->rpcMsg.handle);
|
||||
terrno = TSDB_CODE_MND_NO_USER_FROM_CONN;
|
||||
return NULL;
|
||||
|
@ -213,181 +351,72 @@ SMnodeMsg *mnodeInitMsg(SRpcMsg *pRpcMsg) {
|
|||
return pMsg;
|
||||
}
|
||||
|
||||
void mnodeCleanupMsg(SMnodeMsg *pMsg) {
|
||||
void mndCleanupMsg(SMnodeMsg *pMsg) {
|
||||
if (pMsg->pUser != NULL) {
|
||||
sdbRelease(pMsg->pUser);
|
||||
sdbRelease(pMsg->pMnode->pSdb, pMsg->pUser);
|
||||
}
|
||||
|
||||
taosFreeQitem(pMsg);
|
||||
}
|
||||
|
||||
static void mnodeProcessRpcMsg(SMnodeMsg *pMsg) {
|
||||
int32_t msgType = pMsg->rpcMsg.msgType;
|
||||
void mndSendRsp(SMnodeMsg *pMsg, int32_t code) {}
|
||||
|
||||
if (tsMint.msgFp[msgType] == NULL) {
|
||||
}
|
||||
|
||||
(*tsMint.msgFp[msgType])(pMsg);
|
||||
}
|
||||
|
||||
void mnodeSetMsgFp(int32_t msgType, MnodeRpcFp fp) {
|
||||
if (msgType > 0 || msgType < TSDB_MSG_TYPE_MAX) {
|
||||
tsMint.msgFp[msgType] = fp;
|
||||
}
|
||||
}
|
||||
|
||||
void mnodeProcessMsg(SMnodeMsg *pMsg, EMnMsgType msgType) {
|
||||
if (!mnodeIsMaster()) {
|
||||
mnodeSendRedirectMsg(&pMsg->rpcMsg, true);
|
||||
mnodeCleanupMsg(pMsg);
|
||||
return;
|
||||
}
|
||||
|
||||
switch (msgType) {
|
||||
case MN_MSG_TYPE_READ:
|
||||
case MN_MSG_TYPE_WRITE:
|
||||
case MN_MSG_TYPE_SYNC:
|
||||
mnodeProcessRpcMsg(pMsg);
|
||||
break;
|
||||
case MN_MSG_TYPE_APPLY:
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
#if 0
|
||||
|
||||
static void mnodeProcessWriteReq(SMnodeMsg *pMsg, void *unused) {
|
||||
static void mndProcessRpcMsg(SMnodeMsg *pMsg) {
|
||||
SMnode *pMnode = pMsg->pMnode;
|
||||
int32_t code = 0;
|
||||
int32_t msgType = pMsg->rpcMsg.msgType;
|
||||
void *ahandle = pMsg->rpcMsg.ahandle;
|
||||
int32_t code = 0;
|
||||
bool isReq = (msgType % 2 == 1);
|
||||
|
||||
if (pMsg->rpcMsg.pCont == NULL) {
|
||||
if (isReq && !mndIsMaster(pMnode)) {
|
||||
code = TSDB_CODE_APP_NOT_READY;
|
||||
goto PROCESS_RPC_END;
|
||||
}
|
||||
|
||||
if (isReq && pMsg->rpcMsg.pCont == NULL) {
|
||||
mError("msg:%p, app:%p type:%s content is null", pMsg, ahandle, taosMsg[msgType]);
|
||||
code = TSDB_CODE_MND_INVALID_MSG_LEN;
|
||||
goto PROCESS_WRITE_REQ_END;
|
||||
goto PROCESS_RPC_END;
|
||||
}
|
||||
|
||||
if (!mnodeIsMaster()) {
|
||||
SMnRsp *rpcRsp = &pMsg->rpcRsp;
|
||||
SEpSet *epSet = rpcMallocCont(sizeof(SEpSet));
|
||||
mnodeGetMnodeEpSetForShell(epSet, true);
|
||||
rpcRsp->rsp = epSet;
|
||||
rpcRsp->len = sizeof(SEpSet);
|
||||
|
||||
mDebug("msg:%p, app:%p type:%s in write queue, is redirected, numOfEps:%d inUse:%d", pMsg, ahandle,
|
||||
taosMsg[msgType], epSet->numOfEps, epSet->inUse);
|
||||
|
||||
code = TSDB_CODE_RPC_REDIRECT;
|
||||
goto PROCESS_WRITE_REQ_END;
|
||||
}
|
||||
|
||||
if (tsMworker.writeMsgFp[msgType] == NULL) {
|
||||
MndMsgFp fp = pMnode->msgFp[msgType];
|
||||
if (fp == NULL) {
|
||||
mError("msg:%p, app:%p type:%s not processed", pMsg, ahandle, taosMsg[msgType]);
|
||||
code = TSDB_CODE_MND_MSG_NOT_PROCESSED;
|
||||
goto PROCESS_WRITE_REQ_END;
|
||||
code = TSDB_CODE_MSG_NOT_PROCESSED;
|
||||
goto PROCESS_RPC_END;
|
||||
}
|
||||
|
||||
code = (*tsMworker.writeMsgFp[msgType])(pMsg);
|
||||
|
||||
PROCESS_WRITE_REQ_END:
|
||||
mnodeSendRsp(pMsg, code);
|
||||
}
|
||||
|
||||
static void mnodeProcessReadReq(SMnodeMsg *pMsg, void *unused) {
|
||||
int32_t msgType = pMsg->rpcMsg.msgType;
|
||||
void *ahandle = pMsg->rpcMsg.ahandle;
|
||||
int32_t code = 0;
|
||||
|
||||
if (pMsg->rpcMsg.pCont == NULL) {
|
||||
mError("msg:%p, app:%p type:%s in mread queue, content is null", pMsg, ahandle, taosMsg[msgType]);
|
||||
code = TSDB_CODE_MND_INVALID_MSG_LEN;
|
||||
goto PROCESS_READ_REQ_END;
|
||||
code = (*fp)(pMnode, pMsg);
|
||||
if (code != 0) {
|
||||
code = terrno;
|
||||
mError("msg:%p, app:%p type:%s failed to process since %s", pMsg, ahandle, taosMsg[msgType], terrstr());
|
||||
goto PROCESS_RPC_END;
|
||||
}
|
||||
|
||||
if (!mnodeIsMaster()) {
|
||||
SMnRsp *rpcRsp = &pMsg->rpcRsp;
|
||||
SEpSet *epSet = rpcMallocCont(sizeof(SEpSet));
|
||||
if (!epSet) {
|
||||
code = TSDB_CODE_OUT_OF_MEMORY;
|
||||
goto PROCESS_READ_REQ_END;
|
||||
PROCESS_RPC_END:
|
||||
if (isReq) {
|
||||
if (code == TSDB_CODE_APP_NOT_READY) {
|
||||
mndSendRedirectMsg(pMnode, &pMsg->rpcMsg);
|
||||
} else if (code != 0) {
|
||||
SRpcMsg rspMsg = {.handle = pMsg->rpcMsg.handle, .code = code};
|
||||
rpcSendResponse(&rspMsg);
|
||||
} else {
|
||||
}
|
||||
mnodeGetMnodeEpSetForShell(epSet, true);
|
||||
rpcRsp->rsp = epSet;
|
||||
rpcRsp->len = sizeof(SEpSet);
|
||||
|
||||
mDebug("msg:%p, app:%p type:%s in mread queue is redirected, numOfEps:%d inUse:%d", pMsg, ahandle, taosMsg[msgType],
|
||||
epSet->numOfEps, epSet->inUse);
|
||||
code = TSDB_CODE_RPC_REDIRECT;
|
||||
goto PROCESS_READ_REQ_END;
|
||||
}
|
||||
|
||||
if (tsMworker.readMsgFp[msgType] == NULL) {
|
||||
mError("msg:%p, app:%p type:%s in mread queue, not processed", pMsg, ahandle, taosMsg[msgType]);
|
||||
code = TSDB_CODE_MND_MSG_NOT_PROCESSED;
|
||||
goto PROCESS_READ_REQ_END;
|
||||
}
|
||||
|
||||
mTrace("msg:%p, app:%p type:%s will be processed in mread queue", pMsg, ahandle, taosMsg[msgType]);
|
||||
code = (*tsMworker.readMsgFp[msgType])(pMsg);
|
||||
|
||||
PROCESS_READ_REQ_END:
|
||||
mnodeSendRsp(pMsg, code);
|
||||
mndCleanupMsg(pMsg);
|
||||
}
|
||||
|
||||
static void mnodeProcessPeerReq(SMnodeMsg *pMsg, void *unused) {
|
||||
int32_t msgType = pMsg->rpcMsg.msgType;
|
||||
void *ahandle = pMsg->rpcMsg.ahandle;
|
||||
int32_t code = 0;
|
||||
|
||||
if (pMsg->rpcMsg.pCont == NULL) {
|
||||
mError("msg:%p, ahandle:%p type:%s in mpeer queue, content is null", pMsg, ahandle, taosMsg[msgType]);
|
||||
code = TSDB_CODE_MND_INVALID_MSG_LEN;
|
||||
goto PROCESS_PEER_REQ_END;
|
||||
void mndSetMsgHandle(SMnode *pMnode, int32_t msgType, MndMsgFp fp) {
|
||||
if (msgType >= 0 && msgType < TSDB_MSG_TYPE_MAX) {
|
||||
pMnode->msgFp[msgType] = fp;
|
||||
}
|
||||
|
||||
if (!mnodeIsMaster()) {
|
||||
SMnRsp *rpcRsp = &pMsg->rpcRsp;
|
||||
SEpSet *epSet = rpcMallocCont(sizeof(SEpSet));
|
||||
mnodeGetMnodeEpSetForPeer(epSet, true);
|
||||
rpcRsp->rsp = epSet;
|
||||
rpcRsp->len = sizeof(SEpSet);
|
||||
|
||||
mDebug("msg:%p, ahandle:%p type:%s in mpeer queue is redirected, numOfEps:%d inUse:%d", pMsg, ahandle,
|
||||
taosMsg[msgType], epSet->numOfEps, epSet->inUse);
|
||||
|
||||
code = TSDB_CODE_RPC_REDIRECT;
|
||||
goto PROCESS_PEER_REQ_END;
|
||||
}
|
||||
|
||||
if (tsMworker.peerReqFp[msgType] == NULL) {
|
||||
mError("msg:%p, ahandle:%p type:%s in mpeer queue, not processed", pMsg, ahandle, taosMsg[msgType]);
|
||||
code = TSDB_CODE_MND_MSG_NOT_PROCESSED;
|
||||
goto PROCESS_PEER_REQ_END;
|
||||
}
|
||||
|
||||
code = (*tsMworker.peerReqFp[msgType])(pMsg);
|
||||
|
||||
PROCESS_PEER_REQ_END:
|
||||
mnodeSendRsp(pMsg, code);
|
||||
}
|
||||
|
||||
static void mnodeProcessPeerRsp(SMnodeMsg *pMsg, void *unused) {
|
||||
int32_t msgType = pMsg->rpcMsg.msgType;
|
||||
SRpcMsg *pRpcMsg = &pMsg->rpcMsg;
|
||||
void mndProcessReadMsg(SMnodeMsg *pMsg) { mndProcessRpcMsg(pMsg); }
|
||||
|
||||
if (!mnodeIsMaster()) {
|
||||
mError("msg:%p, ahandle:%p type:%s not processed for not master", pRpcMsg, pRpcMsg->ahandle, taosMsg[msgType]);
|
||||
mnodeCleanupMsg2(pMsg);
|
||||
}
|
||||
void mndProcessWriteMsg(SMnodeMsg *pMsg) { mndProcessRpcMsg(pMsg); }
|
||||
|
||||
if (tsMworker.peerRspFp[msgType]) {
|
||||
(*tsMworker.peerRspFp[msgType])(pRpcMsg);
|
||||
} else {
|
||||
mError("msg:%p, ahandle:%p type:%s is not processed", pRpcMsg, pRpcMsg->ahandle, taosMsg[msgType]);
|
||||
}
|
||||
void mndProcessSyncMsg(SMnodeMsg *pMsg) { mndProcessRpcMsg(pMsg); }
|
||||
|
||||
mnodeCleanupMsg2(pMsg);
|
||||
}
|
||||
#endif
|
||||
void mndProcessApplyMsg(SMnodeMsg *pMsg) {}
|
||||
|
|
|
@ -1,36 +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 "mnodeAuth.h"
|
||||
|
||||
int32_t mnodeInitAuth() { return 0; }
|
||||
void mnodeCleanupAuth() {}
|
||||
|
||||
int32_t mnodeRetriveAuth(char *user, char *spi, char *encrypt, char *secret, char *ckey) {
|
||||
if (strcmp(user, TSDB_NETTEST_USER) == 0) {
|
||||
char pass[32] = {0};
|
||||
taosEncryptPass((uint8_t *)user, strlen(user), pass);
|
||||
*spi = 0;
|
||||
*encrypt = 0;
|
||||
*ckey = 0;
|
||||
memcpy(secret, pass, TSDB_KEY_LEN);
|
||||
mDebug("nettest user is authorized");
|
||||
return 0;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
|
@ -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(
|
||||
sdb
|
||||
PUBLIC "${CMAKE_SOURCE_DIR}/include/dnode/mnode/sdb"
|
||||
private "${CMAKE_CURRENT_SOURCE_DIR}/inc"
|
||||
PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/inc"
|
||||
)
|
||||
target_link_libraries(
|
||||
sdb
|
||||
|
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue