Merge branch '3.0' into feature/tq
This commit is contained in:
commit
2f8d26dd0b
|
@ -1,9 +0,0 @@
|
|||
# See here for image contents: https://github.com/microsoft/vscode-dev-containers/tree/v0.209.3/containers/cpp/.devcontainer/base.Dockerfile
|
||||
|
||||
# [Choice] Debian / Ubuntu version (use Debian 11/9, Ubuntu 18.04/21.04 on local arm64/Apple Silicon): debian-11, debian-10, debian-9, ubuntu-21.04, ubuntu-20.04, ubuntu-18.04
|
||||
ARG VARIANT="bullseye"
|
||||
FROM mcr.microsoft.com/vscode/devcontainers/cpp:0-${VARIANT}
|
||||
|
||||
# [Optional] Uncomment this section to install additional packages.
|
||||
# RUN apt-get update && export DEBIAN_FRONTEND=noninteractive \
|
||||
# && apt-get -y install --no-install-recommends <your-package-list-here>
|
|
@ -1,32 +0,0 @@
|
|||
// For format details, see https://aka.ms/devcontainer.json. For config options, see the README at:
|
||||
// https://github.com/microsoft/vscode-dev-containers/tree/v0.209.3/containers/cpp
|
||||
{
|
||||
"name": "C++",
|
||||
"build": {
|
||||
"dockerfile": "Dockerfile",
|
||||
// Update 'VARIANT' to pick an Debian / Ubuntu OS version: debian-11, debian-10, debian-9, ubuntu-21.04, ubuntu-20.04, ubuntu-18.04
|
||||
// Use Debian 11, Debian 9, Ubuntu 18.04 or Ubuntu 21.04 on local arm64/Apple Silicon
|
||||
"args": { "VARIANT": "ubuntu-21.04" }
|
||||
},
|
||||
"runArgs": ["--cap-add=SYS_PTRACE", "--security-opt", "seccomp=unconfined"],
|
||||
|
||||
// Set *default* container specific settings.json values on container create.
|
||||
"settings": {},
|
||||
|
||||
// Add the IDs of extensions you want installed when the container is created.
|
||||
"extensions": [
|
||||
"ms-vscode.cpptools",
|
||||
"ms-vscode.cmake-tools",
|
||||
"austin.code-gnu-global",
|
||||
"visualstudioexptteam.vscodeintel"
|
||||
],
|
||||
|
||||
// Use 'forwardPorts' to make a list of ports inside the container available locally.
|
||||
// "forwardPorts": [],
|
||||
|
||||
// Use 'postCreateCommand' to run commands after the container is created.
|
||||
// "postCreateCommand": "gcc -v",
|
||||
|
||||
// Comment out connect as root instead. More info: https://aka.ms/vscode-remote/containers/non-root.
|
||||
"remoteUser": "vscode"
|
||||
}
|
|
@ -73,10 +73,12 @@ typedef struct taosField {
|
|||
#define DLL_EXPORT
|
||||
#endif
|
||||
|
||||
DLL_EXPORT int taos_init();
|
||||
typedef void (*__taos_async_fn_t)(void *param, TAOS_RES *, int code);
|
||||
|
||||
DLL_EXPORT void taos_cleanup(void);
|
||||
DLL_EXPORT int taos_options(TSDB_OPTION option, const void *arg, ...);
|
||||
DLL_EXPORT TAOS *taos_connect(const char *ip, const char *user, const char *pass, const char *db, uint16_t port);
|
||||
DLL_EXPORT TAOS *taos_connect_l(const char *ip, int ipLen, const char *user, int userLen, const char *pass, int passLen, const char *db, int dbLen, uint16_t port);
|
||||
DLL_EXPORT TAOS *taos_connect_auth(const char *ip, const char *user, const char *auth, const char *db, uint16_t port);
|
||||
DLL_EXPORT void taos_close(TAOS *taos);
|
||||
|
||||
|
@ -154,14 +156,14 @@ DLL_EXPORT int* taos_fetch_lengths(TAOS_RES *res);
|
|||
// TAOS_RES *taos_list_dbs(TAOS *mysql, const char *wild);
|
||||
|
||||
// TODO: the return value should be `const`
|
||||
DLL_EXPORT char *taos_get_server_info(TAOS *taos);
|
||||
DLL_EXPORT char *taos_get_client_info();
|
||||
DLL_EXPORT char *taos_errstr(TAOS_RES *tres);
|
||||
DLL_EXPORT const char *taos_get_server_info(TAOS *taos);
|
||||
DLL_EXPORT const char *taos_get_client_info();
|
||||
DLL_EXPORT const char *taos_errstr(TAOS_RES *tres);
|
||||
|
||||
DLL_EXPORT int taos_errno(TAOS_RES *tres);
|
||||
|
||||
DLL_EXPORT void taos_query_a(TAOS *taos, const char *sql, void (*fp)(void *param, TAOS_RES *, int code), void *param);
|
||||
DLL_EXPORT void taos_fetch_rows_a(TAOS_RES *res, void (*fp)(void *param, TAOS_RES *, int numOfRows), void *param);
|
||||
DLL_EXPORT void taos_query_a(TAOS *taos, const char *sql, __taos_async_fn_t fp, void *param);
|
||||
DLL_EXPORT void taos_fetch_rows_a(TAOS_RES *res, __taos_async_fn_t fp, void *param);
|
||||
|
||||
typedef void (*TAOS_SUBSCRIBE_CALLBACK)(TAOS_SUB* tsub, TAOS_RES *res, void* param, int code);
|
||||
DLL_EXPORT TAOS_SUB *taos_subscribe(TAOS* taos, int restart, const char* topic, const char *sql, TAOS_SUBSCRIBE_CALLBACK fp, void *param, int interval);
|
||||
|
|
|
@ -77,7 +77,7 @@ TAOS_DEFINE_MESSAGE_TYPE( TSDB_MSG_TYPE_DROP_FUNCTION, "drop-function" )
|
|||
TAOS_DEFINE_MESSAGE_TYPE( TSDB_MSG_TYPE_CREATE_STB, "create-stb" )
|
||||
TAOS_DEFINE_MESSAGE_TYPE( TSDB_MSG_TYPE_ALTER_STB, "alter-stb" )
|
||||
TAOS_DEFINE_MESSAGE_TYPE( TSDB_MSG_TYPE_DROP_STB, "drop-stb" )
|
||||
TAOS_DEFINE_MESSAGE_TYPE( TSDB_MSG_TYPE_STB_VGROUP, "stb-vgroup" )
|
||||
TAOS_DEFINE_MESSAGE_TYPE( TSDB_MSG_TYPE_VGROUP_LIST, "vgroup-list" )
|
||||
TAOS_DEFINE_MESSAGE_TYPE( TSDB_MSG_TYPE_KILL_QUERY, "kill-query" )
|
||||
TAOS_DEFINE_MESSAGE_TYPE( TSDB_MSG_TYPE_KILL_STREAM, "kill-stream" )
|
||||
TAOS_DEFINE_MESSAGE_TYPE( TSDB_MSG_TYPE_KILL_CONN, "kill-conn" )
|
||||
|
@ -168,8 +168,8 @@ typedef enum _mgmt_table {
|
|||
TSDB_MGMT_TABLE_SCORES,
|
||||
TSDB_MGMT_TABLE_GRANTS,
|
||||
TSDB_MGMT_TABLE_VNODES,
|
||||
TSDB_MGMT_TABLE_STREAMTABLES,
|
||||
TSDB_MGMT_TABLE_CLUSTER,
|
||||
TSDB_MGMT_TABLE_STREAMTABLES,
|
||||
TSDB_MGMT_TABLE_TP,
|
||||
TSDB_MGMT_TABLE_FUNCTION,
|
||||
TSDB_MGMT_TABLE_MAX,
|
||||
|
@ -214,6 +214,18 @@ typedef enum _mgmt_table {
|
|||
|
||||
extern char *taosMsg[];
|
||||
|
||||
typedef struct SBuildTableMetaInput {
|
||||
int32_t vgId;
|
||||
char *tableFullName;
|
||||
} SBuildTableMetaInput;
|
||||
|
||||
typedef struct SBuildUseDBInput {
|
||||
char db[TSDB_TABLE_FNAME_LEN];
|
||||
int32_t vgroupVersion;
|
||||
int32_t dbGroupVersion;
|
||||
} SBuildUseDBInput;
|
||||
|
||||
|
||||
#pragma pack(push, 1)
|
||||
|
||||
// null-terminated string instead of char array to avoid too many memory consumption in case of more than 1M tableMeta
|
||||
|
@ -358,6 +370,7 @@ typedef struct {
|
|||
int32_t pid;
|
||||
char app[TSDB_APP_NAME_LEN];
|
||||
char db[TSDB_DB_NAME_LEN];
|
||||
int64_t startTime;
|
||||
} SConnectMsg;
|
||||
|
||||
typedef struct SEpSet {
|
||||
|
@ -368,34 +381,35 @@ typedef struct SEpSet {
|
|||
} SEpSet;
|
||||
|
||||
typedef struct {
|
||||
int32_t acctId;
|
||||
int32_t clusterId;
|
||||
int32_t connId;
|
||||
int8_t superAuth;
|
||||
int8_t readAuth;
|
||||
int8_t writeAuth;
|
||||
int8_t reserved[5];
|
||||
SEpSet epSet;
|
||||
int32_t acctId;
|
||||
uint32_t clusterId;
|
||||
int32_t connId;
|
||||
int8_t superUser;
|
||||
int8_t reserved[5];
|
||||
SEpSet epSet;
|
||||
} SConnectRsp;
|
||||
|
||||
typedef struct {
|
||||
char user[TSDB_USER_LEN];
|
||||
char pass[TSDB_KEY_LEN];
|
||||
char pass[TSDB_PASSWORD_LEN];
|
||||
int32_t maxUsers;
|
||||
int32_t maxDbs;
|
||||
int32_t maxTimeSeries;
|
||||
int32_t maxStreams;
|
||||
int64_t maxStorage; // In unit of GB
|
||||
int32_t accessState; // Configured only by command
|
||||
int64_t maxStorage; // In unit of GB
|
||||
int32_t reserve[8];
|
||||
} SCreateAcctMsg, SAlterAcctMsg;
|
||||
|
||||
typedef struct {
|
||||
char user[TSDB_USER_LEN];
|
||||
char user[TSDB_USER_LEN];
|
||||
int32_t reserve[8];
|
||||
} SDropUserMsg, SDropAcctMsg;
|
||||
|
||||
typedef struct {
|
||||
char user[TSDB_USER_LEN];
|
||||
char pass[TSDB_KEY_LEN];
|
||||
char user[TSDB_USER_LEN];
|
||||
char pass[TSDB_PASSWORD_LEN];
|
||||
int32_t reserve[8];
|
||||
} SCreateUserMsg, SAlterUserMsg;
|
||||
|
||||
typedef struct {
|
||||
|
@ -613,6 +627,8 @@ typedef struct {
|
|||
typedef struct {
|
||||
char db[TSDB_TABLE_FNAME_LEN];
|
||||
int8_t ignoreNotExists;
|
||||
int32_t vgroupVersion;
|
||||
int32_t dbGroupVersion;
|
||||
int32_t reserve[8];
|
||||
} SUseDbMsg;
|
||||
|
||||
|
@ -774,9 +790,8 @@ typedef struct {
|
|||
} SStbInfoMsg;
|
||||
|
||||
typedef struct {
|
||||
SMsgHead msgHead;
|
||||
char tableFname[TSDB_TABLE_FNAME_LEN];
|
||||
int8_t createFlag;
|
||||
char tags[];
|
||||
} STableInfoMsg;
|
||||
|
||||
typedef struct {
|
||||
|
@ -791,6 +806,18 @@ typedef struct SSTableVgroupMsg {
|
|||
int32_t numOfTables;
|
||||
} SSTableVgroupMsg, SSTableVgroupRspMsg;
|
||||
|
||||
typedef struct SVgroupInfo {
|
||||
int32_t vgId;
|
||||
int8_t numOfEps;
|
||||
SEpAddrMsg epAddr[TSDB_MAX_REPLICA];
|
||||
} SVgroupInfo;
|
||||
|
||||
typedef struct SVgroupListRspMsg {
|
||||
int32_t vgroupNum;
|
||||
int32_t vgroupVersion;
|
||||
SVgroupInfo vgroupInfo[];
|
||||
} SVgroupListRspMsg;
|
||||
|
||||
typedef struct {
|
||||
int32_t vgId;
|
||||
int8_t numOfEps;
|
||||
|
@ -835,6 +862,19 @@ typedef struct {
|
|||
char *data;
|
||||
} STagData;
|
||||
|
||||
typedef struct {
|
||||
int32_t vgroupNum;
|
||||
int32_t vgroupVersion;
|
||||
char db[TSDB_TABLE_FNAME_LEN];
|
||||
int32_t dbVgroupVersion;
|
||||
int32_t dbVgroupNum;
|
||||
int32_t dbHashRange;
|
||||
SVgroupInfo vgroupInfo[];
|
||||
//int32_t vgIdList[];
|
||||
} SUseDbRspMsg;
|
||||
|
||||
|
||||
|
||||
/*
|
||||
* sql: show tables like '%a_%'
|
||||
* payload is the query condition, e.g., '%a_%'
|
||||
|
@ -859,16 +899,19 @@ typedef struct SShowRsp {
|
|||
} SShowRsp;
|
||||
|
||||
typedef struct {
|
||||
char ep[TSDB_EP_LEN]; // end point, hostname:port
|
||||
char ep[TSDB_EP_LEN]; // end point, hostname:port
|
||||
int32_t reserve[8];
|
||||
} SCreateDnodeMsg;
|
||||
|
||||
typedef struct {
|
||||
int32_t dnodeId;
|
||||
int32_t reserve[8];
|
||||
} SDropDnodeMsg;
|
||||
|
||||
typedef struct {
|
||||
int32_t dnodeId;
|
||||
char config[TSDB_DNODE_CONFIG_LEN];
|
||||
int32_t reserve[8];
|
||||
} SCfgDnodeMsg;
|
||||
|
||||
typedef struct {
|
||||
|
@ -961,8 +1004,8 @@ typedef struct {
|
|||
char user[TSDB_USER_LEN];
|
||||
char spi;
|
||||
char encrypt;
|
||||
char secret[TSDB_KEY_LEN];
|
||||
char ckey[TSDB_KEY_LEN];
|
||||
char secret[TSDB_PASSWORD_LEN];
|
||||
char ckey[TSDB_PASSWORD_LEN];
|
||||
} SAuthMsg, SAuthRsp;
|
||||
|
||||
typedef struct {
|
||||
|
|
|
@ -0,0 +1,17 @@
|
|||
#ifndef TDENGINE_TEP_H
|
||||
#define TDENGINE_TEP_H
|
||||
|
||||
#include "os.h"
|
||||
#include "taosmsg.h"
|
||||
|
||||
typedef struct SCorEpSet {
|
||||
int32_t version;
|
||||
SEpSet epSet;
|
||||
} SCorEpSet;
|
||||
|
||||
int taosGetFqdnPortFromEp(const char *ep, char *fqdn, uint16_t *port);
|
||||
bool isEpsetEqual(const SEpSet *s1, const SEpSet *s2);
|
||||
|
||||
void updateEpSet_s(SCorEpSet *pEpSet, SEpSet *pNewEpSet);
|
||||
|
||||
#endif // TDENGINE_TEP_H
|
|
@ -81,8 +81,6 @@ extern int64_t tsMaxRetentWindow;
|
|||
// db parameters in client
|
||||
extern int32_t tsCacheBlockSize;
|
||||
extern int32_t tsBlocksPerVnode;
|
||||
extern int32_t tsMinTablePerVnode;
|
||||
extern int32_t tsMaxTablePerVnode;
|
||||
extern int32_t tsTableIncStepPerVnode;
|
||||
extern int32_t tsMaxVgroupsPerDb;
|
||||
extern int16_t tsDaysPerFile;
|
||||
|
@ -113,16 +111,8 @@ extern int8_t tsEnableSlaveQuery;
|
|||
extern int8_t tsEnableAdjustMaster;
|
||||
|
||||
// restful
|
||||
extern int8_t tsEnableHttpModule;
|
||||
extern int32_t tsRestRowLimit;
|
||||
extern uint16_t tsHttpPort;
|
||||
extern int32_t tsHttpCacheSessions;
|
||||
extern int32_t tsHttpSessionExpire;
|
||||
extern int32_t tsHttpMaxThreads;
|
||||
extern int8_t tsHttpEnableCompress;
|
||||
extern int8_t tsHttpEnableRecordSql;
|
||||
extern int8_t tsTelegrafUseFieldNum;
|
||||
extern int8_t tsHttpDbNameMandatory;
|
||||
|
||||
// mqtt
|
||||
extern int8_t tsEnableMqttModule;
|
||||
|
@ -144,7 +134,6 @@ extern int8_t tsEnableStream;
|
|||
|
||||
// internal
|
||||
extern int8_t tsPrintAuth;
|
||||
extern int8_t tscEmbedded;
|
||||
extern char tsVnodeDir[];
|
||||
extern char tsMnodeDir[];
|
||||
extern int64_t tsTickPerDay[3];
|
||||
|
@ -193,7 +182,7 @@ extern SDiskCfg tsDiskCfg[];
|
|||
#define NEEDTO_COMPRESSS_MSG(size) (tsCompressMsgSize != -1 && (size) > tsCompressMsgSize)
|
||||
|
||||
void taosInitGlobalCfg();
|
||||
int32_t taosCheckGlobalCfg();
|
||||
int32_t taosCheckAndPrintCfg();
|
||||
int32_t taosCfgDynamicOptions(char *msg);
|
||||
bool taosCheckBalanceCfgOptions(const char *option, int32_t *vnodeId, int32_t *dnodeId);
|
||||
void taosAddDataDir(int index, char *v1, int level, int primary);
|
||||
|
|
|
@ -99,7 +99,7 @@ extern "C" {
|
|||
sdbFreeRaw(pRaw); \
|
||||
return NULL; \
|
||||
} \
|
||||
dataPos += sizeof(int16_t); \
|
||||
dataPos += sizeof(int16_t); \
|
||||
}
|
||||
|
||||
#define SDB_SET_INT8(pRaw, dataPos, val) \
|
||||
|
@ -144,9 +144,10 @@ typedef struct SSdbRow SSdbRow;
|
|||
typedef enum { SDB_KEY_BINARY = 1, SDB_KEY_INT32 = 2, SDB_KEY_INT64 = 3 } EKeyType;
|
||||
typedef enum {
|
||||
SDB_STATUS_CREATING = 1,
|
||||
SDB_STATUS_READY = 2,
|
||||
SDB_STATUS_UPDATING = 2,
|
||||
SDB_STATUS_DROPPING = 3,
|
||||
SDB_STATUS_DROPPED = 4
|
||||
SDB_STATUS_READY = 4,
|
||||
SDB_STATUS_DROPPED = 5
|
||||
} ESdbStatus;
|
||||
|
||||
typedef enum {
|
||||
|
@ -174,67 +175,19 @@ typedef SSdbRow *(*SdbDecodeFp)(SSdbRaw *pRaw);
|
|||
typedef SSdbRaw *(*SdbEncodeFp)(void *pObj);
|
||||
|
||||
typedef struct {
|
||||
/**
|
||||
* @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.
|
||||
*
|
||||
*/
|
||||
ESdbType sdbType;
|
||||
EKeyType keyType;
|
||||
SdbDeployFp deployFp;
|
||||
|
||||
/**
|
||||
* @brief Encode one row of the table into rawdata.
|
||||
*
|
||||
*/
|
||||
SdbEncodeFp encodeFp;
|
||||
|
||||
/**
|
||||
* @brief Decode one row of the table from rawdata.
|
||||
*
|
||||
*/
|
||||
SdbDecodeFp decodeFp;
|
||||
|
||||
/**
|
||||
* @brief The callback function when insert a row to sdb.
|
||||
*
|
||||
*/
|
||||
SdbInsertFp insertFp;
|
||||
|
||||
/**
|
||||
* @brief The callback function when undate a row in sdb.
|
||||
*
|
||||
*/
|
||||
SdbUpdateFp updateFp;
|
||||
|
||||
/**
|
||||
* @brief The callback function when delete a row from sdb.
|
||||
*
|
||||
*/
|
||||
SdbDeleteFp deleteFp;
|
||||
} SSdbTable;
|
||||
|
||||
typedef struct SSdbOpt {
|
||||
/**
|
||||
* @brief The path of the sdb file.
|
||||
*
|
||||
*/
|
||||
const char *path;
|
||||
|
||||
/**
|
||||
* @brief The mnode object.
|
||||
*
|
||||
*/
|
||||
SMnode *pMnode;
|
||||
SMnode *pMnode;
|
||||
} SSdbOpt;
|
||||
|
||||
/**
|
||||
|
@ -342,6 +295,15 @@ void sdbCancelFetch(SSdb *pSdb, void *pIter);
|
|||
*/
|
||||
int32_t sdbGetSize(SSdb *pSdb, ESdbType type);
|
||||
|
||||
/**
|
||||
* @brief Get the max id of the table, keyType of table should be INT32
|
||||
*
|
||||
* @param pSdb The sdb object.
|
||||
* @param pIter The type of the table.
|
||||
* @record int32_t The max id of the table
|
||||
*/
|
||||
int32_t sdbGetMaxId(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);
|
||||
|
|
|
@ -21,15 +21,14 @@ extern "C" {
|
|||
#endif
|
||||
|
||||
// TYPES EXPOSED
|
||||
typedef struct STsdb STsdb;
|
||||
typedef struct STsdbCfg STsdbCfg;
|
||||
typedef struct STsdbMemAllocator STsdbMemAllocator;
|
||||
typedef struct STsdb STsdb;
|
||||
typedef struct STsdbCfg STsdbCfg;
|
||||
|
||||
// STsdb
|
||||
STsdb *tsdbOpen(const char *path, const STsdbCfg *);
|
||||
STsdb *tsdbOpen(const char *path, const STsdbCfg *pTsdbCfg);
|
||||
void tsdbClose(STsdb *);
|
||||
void tsdbRemove(const char *path);
|
||||
int tsdbInsertData(STsdb *pTsdb, void *pData, int len);
|
||||
int tsdbInsertData(STsdb *pTsdb, SSubmitMsg *pMsg);
|
||||
|
||||
// STsdbCfg
|
||||
int tsdbOptionsInit(STsdbCfg *);
|
||||
|
@ -41,7 +40,6 @@ struct STsdbCfg {
|
|||
uint32_t keep0;
|
||||
uint32_t keep1;
|
||||
uint32_t keep2;
|
||||
/* TODO */
|
||||
};
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
|
|
@ -68,9 +68,11 @@ typedef struct SVnodeCfg {
|
|||
/**
|
||||
* @brief Initialize the vnode module
|
||||
*
|
||||
* @param nthreads number of commit threads. 0 for no threads and
|
||||
* a schedule queue should be given (TODO)
|
||||
* @return int 0 for success and -1 for failure
|
||||
*/
|
||||
int vnodeInit();
|
||||
int vnodeInit(uint16_t nthreads);
|
||||
|
||||
/**
|
||||
* @brief clear a vnode
|
||||
|
|
|
@ -27,19 +27,20 @@ extern "C" {
|
|||
#include "transport.h"
|
||||
#include "common.h"
|
||||
#include "taosmsg.h"
|
||||
#include "query.h"
|
||||
|
||||
struct SCatalog;
|
||||
|
||||
typedef struct SMetaReq {
|
||||
char clusterId[TSDB_CLUSTER_ID_LEN];
|
||||
typedef struct SCatalogReq {
|
||||
char clusterId[TSDB_CLUSTER_ID_LEN]; //????
|
||||
SArray *pTableName; // table full name
|
||||
SArray *pUdf; // udf name
|
||||
bool qNodeEpset; // valid qnode
|
||||
} SMetaReq;
|
||||
bool qNodeRequired; // valid qnode
|
||||
} SCatalogReq;
|
||||
|
||||
typedef struct SMetaData {
|
||||
SArray *pTableMeta; // tableMeta
|
||||
SArray *pVgroupInfo; // vgroupInfo list
|
||||
SArray *pTableMeta; // STableMeta array
|
||||
SArray *pVgroupInfo; // SVgroupInfo list
|
||||
SArray *pUdfList; // udf info list
|
||||
SEpSet *pEpSet; // qnode epset list
|
||||
} SMetaData;
|
||||
|
@ -78,32 +79,71 @@ typedef struct STableMeta {
|
|||
SSchema schema[];
|
||||
} STableMeta;
|
||||
|
||||
typedef struct SCatalogCfg {
|
||||
|
||||
} SCatalogCfg;
|
||||
|
||||
int32_t catalogInit(SCatalogCfg *cfg);
|
||||
|
||||
/**
|
||||
* Catalog service object, which is utilized to hold tableMeta (meta/vgroupInfo/udfInfo) at the client-side.
|
||||
* There is ONLY one SCatalog object for one process space, and this function returns a singleton.
|
||||
* @param pMgmtEps
|
||||
* @param clusterId
|
||||
* @return
|
||||
*/
|
||||
struct SCatalog* getCatalogHandle(const SEpSet* pMgmtEps);
|
||||
int32_t catalogGetHandle(const char *clusterId, struct SCatalog** catalogHandle);
|
||||
|
||||
|
||||
|
||||
int32_t catalogGetVgroupVersion(struct SCatalog* pCatalog, int32_t* version);
|
||||
int32_t catalogGetVgroup(struct SCatalog* pCatalog, void *pRpc, const SEpSet* pMgmtEps, SArray** pVgroupList);
|
||||
int32_t catalogUpdateVgroup(struct SCatalog* pCatalog, SVgroupListInfo* pVgroup);
|
||||
|
||||
|
||||
|
||||
int32_t catalogGetDBVgroupVersion(struct SCatalog* pCatalog, const char* dbName, int32_t* version);
|
||||
int32_t catalogGetDBVgroup(struct SCatalog* pCatalog, void *pRpc, const SEpSet* pMgmtEps, const char* dbName, int32_t forceUpdate, SDBVgroupInfo** dbInfo);
|
||||
int32_t catalogUpdateDBVgroup(struct SCatalog* pCatalog, const char* dbName, SDBVgroupInfo* dbInfo);
|
||||
|
||||
|
||||
int32_t catalogGetTableMeta(struct SCatalog* pCatalog, void *pRpc, const SEpSet* pMgmtEps, const char* pTableName, STableMeta* pTableMeta);
|
||||
int32_t catalogRenewTableMeta(struct SCatalog* pCatalog, void *pRpc, const SEpSet* pMgmtEps, const STableMeta* pTableMeta);
|
||||
int32_t catalogRenewAndGetTableMeta(struct SCatalog* pCatalog, void *pRpc, const SEpSet* pMgmtEps, const STableMeta* pTableMeta, STableMeta* pNewTableMeta);
|
||||
|
||||
|
||||
/**
|
||||
* get table's vgroup list.
|
||||
* @param clusterId
|
||||
* @pVgroupList - array of SVgroupInfo
|
||||
* @return
|
||||
*/
|
||||
int32_t catalogGetTableVgroup(struct SCatalog* pCatalog, void *pRpc, const SEpSet* pMgmtEps, const char* pTableName, SArray* pVgroupList);
|
||||
|
||||
|
||||
/**
|
||||
* Get the required meta data from mnode.
|
||||
* Note that this is a synchronized API and is also thread-safety.
|
||||
* @param pCatalog
|
||||
* @param pMgmtEps
|
||||
* @param pMetaReq
|
||||
* @param pMetaData
|
||||
* @return
|
||||
*/
|
||||
int32_t catalogGetMetaData(struct SCatalog* pCatalog, const SMetaReq* pMetaReq, SMetaData* pMetaData);
|
||||
int32_t catalogGetAllMeta(struct SCatalog* pCatalog, const SEpSet* pMgmtEps, const SCatalogReq* pReq, SMetaData* pRsp);
|
||||
|
||||
|
||||
int32_t catalogGetQnodeList(struct SCatalog* pCatalog, const SEpSet* pMgmtEps, SEpSet* pQnodeEpSet);
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Destroy catalog service handle
|
||||
* Destroy catalog and relase all resources
|
||||
* @param pCatalog
|
||||
*/
|
||||
void destroyCatalog(struct SCatalog* pCatalog);
|
||||
void catalogDestroy(void);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /*_TD_CATALOG_H_*/
|
||||
#endif /*_TD_CATALOG_H_*/
|
||||
|
|
|
@ -22,6 +22,7 @@ extern "C" {
|
|||
|
||||
#define QUERY_TYPE_MERGE 1
|
||||
#define QUERY_TYPE_PARTIAL 2
|
||||
#define QUERY_TYPE_SCAN 3
|
||||
|
||||
enum OPERATOR_TYPE_E {
|
||||
OP_TableScan = 1,
|
||||
|
@ -54,90 +55,37 @@ enum OPERATOR_TYPE_E {
|
|||
|
||||
struct SEpSet;
|
||||
struct SQueryPlanNode;
|
||||
struct SQueryDistPlanNode;
|
||||
struct SPhyNode;
|
||||
struct SQueryStmtInfo;
|
||||
|
||||
typedef struct SSubquery {
|
||||
int64_t queryId; // the subquery id created by qnode
|
||||
int32_t type; // QUERY_TYPE_MERGE|QUERY_TYPE_PARTIAL
|
||||
int32_t level; // the execution level of current subquery, starting from 0.
|
||||
SArray *pUpstream; // the upstream,from which to fetch the result
|
||||
struct SQueryDistPlanNode *pNode; // physical plan of current subquery
|
||||
} SSubquery;
|
||||
|
||||
typedef struct SQueryJob {
|
||||
SArray **pSubqueries;
|
||||
int32_t numOfLevels;
|
||||
int32_t currentLevel;
|
||||
} SQueryJob;
|
||||
typedef struct SSubplan {
|
||||
int32_t type; // QUERY_TYPE_MERGE|QUERY_TYPE_PARTIAL|QUERY_TYPE_SCAN
|
||||
SArray *pDatasource; // the datasource subplan,from which to fetch the result
|
||||
struct SPhyNode *pNode; // physical plan of current subplan
|
||||
} SSubplan;
|
||||
|
||||
typedef struct SQueryDag {
|
||||
SArray **pSubplans;
|
||||
} SQueryDag;
|
||||
|
||||
/**
|
||||
* Optimize the query execution plan, currently not implement yet.
|
||||
* @param pQueryNode
|
||||
* @return
|
||||
* Create the physical plan for the query, according to the AST.
|
||||
*/
|
||||
int32_t qOptimizeQueryPlan(struct SQueryPlanNode* pQueryNode);
|
||||
int32_t qCreateQueryDag(const struct SQueryStmtInfo* pQueryInfo, struct SEpSet* pQnode, struct SQueryDag** pDag);
|
||||
|
||||
int32_t qExplainQuery(const struct SQueryStmtInfo* pQueryInfo, struct SEpSet* pQnode, char** str);
|
||||
|
||||
/**
|
||||
* Create the query plan according to the bound AST, which is in the form of pQueryInfo
|
||||
* @param pQueryInfo
|
||||
* @param pQueryNode
|
||||
* @return
|
||||
* Convert to subplan to string for the scheduler to send to the executor
|
||||
*/
|
||||
int32_t qCreateQueryPlan(const struct SQueryStmtInfo* pQueryInfo, struct SQueryPlanNode** pQueryNode);
|
||||
|
||||
/**
|
||||
* Convert the query plan to string, in order to display it in the shell.
|
||||
* @param pQueryNode
|
||||
* @return
|
||||
*/
|
||||
int32_t qQueryPlanToString(struct SQueryPlanNode* pQueryNode, char** str);
|
||||
|
||||
/**
|
||||
* Restore the SQL statement according to the logic query plan.
|
||||
* @param pQueryNode
|
||||
* @param sql
|
||||
* @return
|
||||
*/
|
||||
int32_t qQueryPlanToSql(struct SQueryPlanNode* pQueryNode, char** sql);
|
||||
|
||||
/**
|
||||
* Create the physical plan for the query, according to the logic plan.
|
||||
* @param pQueryNode
|
||||
* @param pPhyNode
|
||||
* @return
|
||||
*/
|
||||
int32_t qCreatePhysicalPlan(struct SQueryPlanNode* pQueryNode, struct SEpSet* pQnode, struct SQueryDistPlanNode *pPhyNode);
|
||||
|
||||
/**
|
||||
* Convert to physical plan to string to enable to print it out in the shell.
|
||||
* @param pPhyNode
|
||||
* @param str
|
||||
* @return
|
||||
*/
|
||||
int32_t qPhyPlanToString(struct SQueryDistPlanNode *pPhyNode, char** str);
|
||||
|
||||
/**
|
||||
* Destroy the query plan object.
|
||||
* @return
|
||||
*/
|
||||
void* qDestroyQueryPlan(struct SQueryPlanNode* pQueryNode);
|
||||
int32_t qSubPlanToString(struct SSubplan *pPhyNode, char** str);
|
||||
|
||||
/**
|
||||
* Destroy the physical plan.
|
||||
* @param pQueryPhyNode
|
||||
* @return
|
||||
*/
|
||||
void* qDestroyQueryPhyPlan(struct SQueryDistPlanNode* pQueryPhyNode);
|
||||
|
||||
/**
|
||||
* Create the query job from the physical execution plan
|
||||
* @param pPhyNode
|
||||
* @param pJob
|
||||
* @return
|
||||
*/
|
||||
int32_t qCreateQueryJob(const struct SQueryDistPlanNode* pPhyNode, struct SQueryJob** pJob);
|
||||
void* qDestroyQueryDag(struct SQueryDag* pDag);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
|
|
@ -0,0 +1,48 @@
|
|||
/*
|
||||
* 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_QUERY_H_
|
||||
#define _TD_QUERY_H_
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include "tarray.h"
|
||||
|
||||
typedef SVgroupListRspMsg SVgroupListInfo;
|
||||
|
||||
typedef struct SDBVgroupInfo {
|
||||
int32_t vgroupVersion;
|
||||
SArray *vgId;
|
||||
int32_t hashRange;
|
||||
} SDBVgroupInfo;
|
||||
|
||||
typedef struct SUseDbOutput {
|
||||
SVgroupListInfo *vgroupList;
|
||||
char db[TSDB_TABLE_FNAME_LEN];
|
||||
SDBVgroupInfo *dbVgroup;
|
||||
} SUseDbOutput;
|
||||
|
||||
|
||||
extern int32_t (*queryBuildMsg[TSDB_MSG_TYPE_MAX])(void* input, char **msg, int32_t msgSize, int32_t *msgLen);
|
||||
extern int32_t (*queryProcessMsgRsp[TSDB_MSG_TYPE_MAX])(void* output, char *msg, int32_t msgSize);
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /*_TD_QUERY_H_*/
|
|
@ -20,7 +20,42 @@
|
|||
extern "C" {
|
||||
#endif
|
||||
|
||||
struct SQueryJob;
|
||||
typedef struct SQueryProfileSummary {
|
||||
int64_t startTs; // Object created and added into the message queue
|
||||
int64_t endTs; // the timestamp when the task is completed
|
||||
int64_t cputime; // total cpu cost, not execute elapsed time
|
||||
|
||||
int64_t loadRemoteDataDuration; // remote io time
|
||||
int64_t loadNativeDataDuration; // native disk io time
|
||||
|
||||
uint64_t loadNativeData; // blocks + SMA + header files
|
||||
uint64_t loadRemoteData; // remote data acquired by exchange operator.
|
||||
|
||||
uint64_t waitDuration; // the time to waiting to be scheduled in queue does matter, so we need to record it
|
||||
int64_t addQTs; // the time to be added into the message queue, used to calculate the waiting duration in queue.
|
||||
|
||||
uint64_t totalRows;
|
||||
uint64_t loadRows;
|
||||
uint32_t totalBlocks;
|
||||
uint32_t loadBlocks;
|
||||
uint32_t loadBlockAgg;
|
||||
uint32_t skipBlocks;
|
||||
uint64_t resultSize; // generated result size in Kb.
|
||||
} SQueryProfileSummary;
|
||||
|
||||
typedef struct SQueryTask {
|
||||
uint64_t queryId; // query id
|
||||
uint64_t taskId; // task id
|
||||
char *pSubplan; // operator tree
|
||||
uint64_t status; // task status
|
||||
SQueryProfileSummary summary; // task execution summary
|
||||
void *pOutputHandle; // result buffer handle, to temporarily keep the output result for next stage
|
||||
} SQueryTask;
|
||||
|
||||
typedef struct SQueryJob {
|
||||
SArray **pSubtasks;
|
||||
// todo
|
||||
} SQueryJob;
|
||||
|
||||
/**
|
||||
* Process the query job, generated according to the query physical plan.
|
||||
|
|
|
@ -29,11 +29,6 @@ extern "C" {
|
|||
|
||||
extern int tsRpcHeadSize;
|
||||
|
||||
typedef struct SRpcCorEpSet {
|
||||
int32_t version;
|
||||
SEpSet epSet;
|
||||
} SRpcCorEpSet;
|
||||
|
||||
typedef struct SRpcConnInfo {
|
||||
uint32_t clientIp;
|
||||
uint16_t clientPort;
|
||||
|
|
|
@ -23,8 +23,8 @@ extern "C" {
|
|||
#define tfree(x) \
|
||||
do { \
|
||||
if (x) { \
|
||||
free((void *)x); \
|
||||
x = 0; \
|
||||
free((void *)(x)); \
|
||||
(x) = 0; \
|
||||
} \
|
||||
} while (0)
|
||||
|
||||
|
|
|
@ -57,7 +57,7 @@ int64_t taosGetPthreadId(pthread_t thread);
|
|||
void taosResetPthread(pthread_t* thread);
|
||||
bool taosComparePthread(pthread_t first, pthread_t second);
|
||||
int32_t taosGetPId();
|
||||
int32_t taosGetCurrentAPPName(char* name, int32_t* len);
|
||||
int32_t taosGetAppName(char* name, int32_t* len);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
|
|
@ -117,72 +117,93 @@ int32_t* taosGetErrno();
|
|||
#define TSDB_CODE_TSC_INVALID_JSON TAOS_DEF_ERROR_CODE(0, 0x0221) //"Invalid JSON format")
|
||||
#define TSDB_CODE_TSC_INVALID_JSON_TYPE TAOS_DEF_ERROR_CODE(0, 0x0222) //"Invalid JSON data type")
|
||||
#define TSDB_CODE_TSC_VALUE_OUT_OF_RANGE TAOS_DEF_ERROR_CODE(0, 0x0223) //"Value out of range")
|
||||
#define TSDB_CODE_TSC_INVALID_INPUT TAOS_DEF_ERROR_CODE(0, 0X0224) //"Invalid tsc input")
|
||||
|
||||
// mnode
|
||||
#define TSDB_CODE_MND_MSG_NOT_PROCESSED TAOS_DEF_ERROR_CODE(0, 0x0300)
|
||||
#define TSDB_CODE_MND_ACTION_IN_PROGRESS TAOS_DEF_ERROR_CODE(0, 0x0301)
|
||||
#define TSDB_CODE_MND_ACTION_NEED_REPROCESSED TAOS_DEF_ERROR_CODE(0, 0x0302)
|
||||
#define TSDB_CODE_MND_NO_RIGHTS TAOS_DEF_ERROR_CODE(0, 0x0303)
|
||||
#define TSDB_CODE_MND_INVALID_OPTIONS TAOS_DEF_ERROR_CODE(0, 0x0304)
|
||||
#define TSDB_CODE_MND_INVALID_CONNECTION TAOS_DEF_ERROR_CODE(0, 0x0305)
|
||||
#define TSDB_CODE_MND_INVALID_MSG_VERSION TAOS_DEF_ERROR_CODE(0, 0x0306)
|
||||
#define TSDB_CODE_MND_INVALID_MSG_LEN TAOS_DEF_ERROR_CODE(0, 0x0307)
|
||||
#define TSDB_CODE_MND_INVALID_MSG_TYPE TAOS_DEF_ERROR_CODE(0, 0x0308)
|
||||
#define TSDB_CODE_MND_TOO_MANY_SHELL_CONNS TAOS_DEF_ERROR_CODE(0, 0x0309)
|
||||
#define TSDB_CODE_MND_INVALID_SHOWOBJ TAOS_DEF_ERROR_CODE(0, 0x030B)
|
||||
#define TSDB_CODE_MND_INVALID_QUERY_ID TAOS_DEF_ERROR_CODE(0, 0x030C)
|
||||
#define TSDB_CODE_MND_INVALID_STREAM_ID TAOS_DEF_ERROR_CODE(0, 0x030D)
|
||||
#define TSDB_CODE_MND_INVALID_CONN_ID TAOS_DEF_ERROR_CODE(0, 0x030E)
|
||||
#define TSDB_CODE_MND_MNODE_IS_RUNNING TAOS_DEF_ERROR_CODE(0, 0x0310)
|
||||
#define TSDB_CODE_MND_FAILED_TO_CONFIG_SYNC TAOS_DEF_ERROR_CODE(0, 0x0311)
|
||||
#define TSDB_CODE_MND_FAILED_TO_START_SYNC TAOS_DEF_ERROR_CODE(0, 0x0312)
|
||||
#define TSDB_CODE_MND_FAILED_TO_CREATE_DIR TAOS_DEF_ERROR_CODE(0, 0x0313)
|
||||
#define TSDB_CODE_MND_FAILED_TO_INIT_STEP TAOS_DEF_ERROR_CODE(0, 0x0314)
|
||||
// mnode-common
|
||||
#define TSDB_CODE_MND_NOT_READY TAOS_DEF_ERROR_CODE(0, 0x0300)
|
||||
#define TSDB_CODE_MND_MSG_NOT_PROCESSED TAOS_DEF_ERROR_CODE(0, 0x0301)
|
||||
#define TSDB_CODE_MND_ACTION_IN_PROGRESS TAOS_DEF_ERROR_CODE(0, 0x0302)
|
||||
#define TSDB_CODE_MND_ACTION_NEED_REPROCESSED TAOS_DEF_ERROR_CODE(0, 0x0303)
|
||||
#define TSDB_CODE_MND_NO_RIGHTS TAOS_DEF_ERROR_CODE(0, 0x0304)
|
||||
#define TSDB_CODE_MND_INVALID_OPTIONS TAOS_DEF_ERROR_CODE(0, 0x0305)
|
||||
#define TSDB_CODE_MND_INVALID_CONNECTION TAOS_DEF_ERROR_CODE(0, 0x0306)
|
||||
#define TSDB_CODE_MND_INVALID_MSG_VERSION TAOS_DEF_ERROR_CODE(0, 0x0307)
|
||||
#define TSDB_CODE_MND_INVALID_MSG_LEN TAOS_DEF_ERROR_CODE(0, 0x0308)
|
||||
#define TSDB_CODE_MND_INVALID_MSG_TYPE TAOS_DEF_ERROR_CODE(0, 0x0309)
|
||||
#define TSDB_CODE_MND_TOO_MANY_SHELL_CONNS TAOS_DEF_ERROR_CODE(0, 0x030A)
|
||||
|
||||
#define TSDB_CODE_SDB_APP_ERROR TAOS_DEF_ERROR_CODE(0, 0x0320)
|
||||
#define TSDB_CODE_SDB_OBJ_ALREADY_THERE TAOS_DEF_ERROR_CODE(0, 0x0321)
|
||||
#define TSDB_CODE_SDB_OBJ_NOT_THERE TAOS_DEF_ERROR_CODE(0, 0x0322)
|
||||
#define TSDB_CODE_SDB_OBJ_CREATING TAOS_DEF_ERROR_CODE(0, 0x0323)
|
||||
#define TSDB_CODE_SDB_OBJ_DROPPING TAOS_DEF_ERROR_CODE(0, 0x0324)
|
||||
#define TSDB_CODE_SDB_INVALID_TABLE_TYPE TAOS_DEF_ERROR_CODE(0, 0x0325)
|
||||
#define TSDB_CODE_SDB_INVALID_KEY_TYPE TAOS_DEF_ERROR_CODE(0, 0x0326)
|
||||
#define TSDB_CODE_SDB_INVALID_ACTION_TYPE TAOS_DEF_ERROR_CODE(0, 0x0327)
|
||||
#define TSDB_CODE_SDB_INVALID_STATUS_TYPE TAOS_DEF_ERROR_CODE(0, 0x0328)
|
||||
#define TSDB_CODE_SDB_INVALID_DATA_VER TAOS_DEF_ERROR_CODE(0, 0x0329)
|
||||
#define TSDB_CODE_SDB_INVALID_DATA_LEN TAOS_DEF_ERROR_CODE(0, 0x032A)
|
||||
#define TSDB_CODE_SDB_INVALID_DATA_CONTENT TAOS_DEF_ERROR_CODE(0, 0x032B)
|
||||
// mnode-show
|
||||
#define TSDB_CODE_MND_INVALID_SHOWOBJ TAOS_DEF_ERROR_CODE(0, 0x0310)
|
||||
|
||||
// mnode-profile
|
||||
#define TSDB_CODE_MND_INVALID_QUERY_ID TAOS_DEF_ERROR_CODE(0, 0x0320)
|
||||
#define TSDB_CODE_MND_INVALID_STREAM_ID TAOS_DEF_ERROR_CODE(0, 0x0321)
|
||||
#define TSDB_CODE_MND_INVALID_CONN_ID TAOS_DEF_ERROR_CODE(0, 0x0322)
|
||||
#define TSDB_CODE_MND_MNODE_IS_RUNNING TAOS_DEF_ERROR_CODE(0, 0x0323)
|
||||
#define TSDB_CODE_MND_FAILED_TO_CONFIG_SYNC TAOS_DEF_ERROR_CODE(0, 0x0324)
|
||||
#define TSDB_CODE_MND_FAILED_TO_START_SYNC TAOS_DEF_ERROR_CODE(0, 0x0325)
|
||||
#define TSDB_CODE_MND_FAILED_TO_CREATE_DIR TAOS_DEF_ERROR_CODE(0, 0x0326)
|
||||
#define TSDB_CODE_MND_FAILED_TO_INIT_STEP TAOS_DEF_ERROR_CODE(0, 0x0327)
|
||||
|
||||
// mnode-sdb
|
||||
#define TSDB_CODE_SDB_APP_ERROR TAOS_DEF_ERROR_CODE(0, 0x0330)
|
||||
#define TSDB_CODE_SDB_OBJ_ALREADY_THERE TAOS_DEF_ERROR_CODE(0, 0x0331)
|
||||
#define TSDB_CODE_SDB_OBJ_NOT_THERE TAOS_DEF_ERROR_CODE(0, 0x0332)
|
||||
#define TSDB_CODE_SDB_OBJ_CREATING TAOS_DEF_ERROR_CODE(0, 0x0333)
|
||||
#define TSDB_CODE_SDB_OBJ_DROPPING TAOS_DEF_ERROR_CODE(0, 0x0334)
|
||||
#define TSDB_CODE_SDB_INVALID_TABLE_TYPE TAOS_DEF_ERROR_CODE(0, 0x0335)
|
||||
#define TSDB_CODE_SDB_INVALID_KEY_TYPE TAOS_DEF_ERROR_CODE(0, 0x0336)
|
||||
#define TSDB_CODE_SDB_INVALID_ACTION_TYPE TAOS_DEF_ERROR_CODE(0, 0x0337)
|
||||
#define TSDB_CODE_SDB_INVALID_STATUS_TYPE TAOS_DEF_ERROR_CODE(0, 0x0338)
|
||||
#define TSDB_CODE_SDB_INVALID_DATA_VER TAOS_DEF_ERROR_CODE(0, 0x0339)
|
||||
#define TSDB_CODE_SDB_INVALID_DATA_LEN TAOS_DEF_ERROR_CODE(0, 0x033A)
|
||||
#define TSDB_CODE_SDB_INVALID_DATA_CONTENT TAOS_DEF_ERROR_CODE(0, 0x033B)
|
||||
|
||||
// mnode-dnode
|
||||
#define TSDB_CODE_MND_DNODE_ALREADY_EXIST TAOS_DEF_ERROR_CODE(0, 0x0330)
|
||||
#define TSDB_CODE_MND_DNODE_NOT_EXIST TAOS_DEF_ERROR_CODE(0, 0x0331)
|
||||
#define TSDB_CODE_MND_NO_ENOUGH_DNODES TAOS_DEF_ERROR_CODE(0, 0x0332)
|
||||
#define TSDB_CODE_MND_INVALID_CLUSTER_CFG TAOS_DEF_ERROR_CODE(0, 0x0333)
|
||||
#define TSDB_CODE_MND_INVALID_CLUSTER_ID TAOS_DEF_ERROR_CODE(0, 0x0334)
|
||||
#define TSDB_CODE_MND_INVALID_DNODE_CFG TAOS_DEF_ERROR_CODE(0, 0x0335)
|
||||
#define TSDB_CODE_MND_INVALID_DNODE_EP TAOS_DEF_ERROR_CODE(0, 0x0336)
|
||||
#define TSDB_CODE_MND_INVALID_DNODE_ID TAOS_DEF_ERROR_CODE(0, 0x0337)
|
||||
#define TSDB_CODE_MND_DNODE_ALREADY_EXIST TAOS_DEF_ERROR_CODE(0, 0x0340)
|
||||
#define TSDB_CODE_MND_DNODE_NOT_EXIST TAOS_DEF_ERROR_CODE(0, 0x0341)
|
||||
#define TSDB_CODE_MND_TOO_MANY_DNODES TAOS_DEF_ERROR_CODE(0, 0x0342)
|
||||
#define TSDB_CODE_MND_NO_ENOUGH_DNODES TAOS_DEF_ERROR_CODE(0, 0x0343)
|
||||
#define TSDB_CODE_MND_INVALID_CLUSTER_CFG TAOS_DEF_ERROR_CODE(0, 0x0344)
|
||||
#define TSDB_CODE_MND_INVALID_CLUSTER_ID TAOS_DEF_ERROR_CODE(0, 0x0345)
|
||||
#define TSDB_CODE_MND_INVALID_DNODE_CFG TAOS_DEF_ERROR_CODE(0, 0x0346)
|
||||
#define TSDB_CODE_MND_INVALID_DNODE_EP TAOS_DEF_ERROR_CODE(0, 0x0347)
|
||||
#define TSDB_CODE_MND_INVALID_DNODE_ID TAOS_DEF_ERROR_CODE(0, 0x0348)
|
||||
|
||||
// mnode-vgroup
|
||||
#define TSDB_CODE_MND_VGROUP_NOT_EXIST TAOS_DEF_ERROR_CODE(0, 0x0332) //"VGroup does not exist")
|
||||
#define TSDB_CODE_MND_VGROUP_NOT_IN_DNODE TAOS_DEF_ERROR_CODE(0, 0x0338) //"Vgroup not in dnode")
|
||||
#define TSDB_CODE_MND_VGROUP_ALREADY_IN_DNODE TAOS_DEF_ERROR_CODE(0, 0x0339) //"Vgroup already in dnode")
|
||||
#define TSDB_CODE_MND_NOT_READY TAOS_DEF_ERROR_CODE(0, 0x033C) //"Cluster not ready")
|
||||
// mnode-mnode
|
||||
#define TSDB_CODE_MND_MNODE_ALREADY_EXIST TAOS_DEF_ERROR_CODE(0, 0x0350)
|
||||
#define TSDB_CODE_MND_MNODE_NOT_EXIST TAOS_DEF_ERROR_CODE(0, 0x0351)
|
||||
#define TSDB_CODE_MND_TOO_MANY_MNODES TAOS_DEF_ERROR_CODE(0, 0x0352)
|
||||
|
||||
// mnode-acct
|
||||
#define TSDB_CODE_MND_ACCT_ALREADY_EXIST TAOS_DEF_ERROR_CODE(0, 0x0340) //"Account already exists")
|
||||
#define TSDB_CODE_MND_ACCT_NOT_EXIST TAOS_DEF_ERROR_CODE(0, 0x0341) //"Invalid account")
|
||||
#define TSDB_CODE_MND_INVALID_ACCT_OPTION TAOS_DEF_ERROR_CODE(0, 0x0342) //"Invalid account options")
|
||||
#define TSDB_CODE_MND_ACCT_EXPIRED TAOS_DEF_ERROR_CODE(0, 0x0343) //"Account authorization has expired")
|
||||
#define TSDB_CODE_MND_ACCT_ALREADY_EXIST TAOS_DEF_ERROR_CODE(0, 0x0360)
|
||||
#define TSDB_CODE_MND_ACCT_NOT_EXIST TAOS_DEF_ERROR_CODE(0, 0x0361)
|
||||
#define TSDB_CODE_MND_TOO_MANY_ACCTS TAOS_DEF_ERROR_CODE(0, 0x0362)
|
||||
#define TSDB_CODE_MND_INVALID_ACCT_OPTION TAOS_DEF_ERROR_CODE(0, 0x0363)
|
||||
#define TSDB_CODE_MND_ACCT_EXPIRED TAOS_DEF_ERROR_CODE(0, 0x0364)
|
||||
|
||||
#define TSDB_CODE_MND_USER_ALREADY_EXIST TAOS_DEF_ERROR_CODE(0, 0x0350) //"User already exists")
|
||||
#define TSDB_CODE_MND_USER_NOT_EXIST TAOS_DEF_ERROR_CODE(0, 0x0351) //"Invalid user")
|
||||
#define TSDB_CODE_MND_INVALID_USER_FORMAT TAOS_DEF_ERROR_CODE(0, 0x0352) //"Invalid user format")
|
||||
#define TSDB_CODE_MND_INVALID_PASS_FORMAT TAOS_DEF_ERROR_CODE(0, 0x0353) //"Invalid password format")
|
||||
#define TSDB_CODE_MND_NO_USER_FROM_CONN TAOS_DEF_ERROR_CODE(0, 0x0354) //"Can not get user from conn")
|
||||
#define TSDB_CODE_MND_TOO_MANY_USERS TAOS_DEF_ERROR_CODE(0, 0x0355) //"Too many users")
|
||||
// mnode-user
|
||||
#define TSDB_CODE_MND_USER_ALREADY_EXIST TAOS_DEF_ERROR_CODE(0, 0x0370)
|
||||
#define TSDB_CODE_MND_USER_NOT_EXIST TAOS_DEF_ERROR_CODE(0, 0x0371)
|
||||
#define TSDB_CODE_MND_TOO_MANY_USERS TAOS_DEF_ERROR_CODE(0, 0x0372)
|
||||
#define TSDB_CODE_MND_INVALID_USER_FORMAT TAOS_DEF_ERROR_CODE(0, 0x0373)
|
||||
#define TSDB_CODE_MND_INVALID_PASS_FORMAT TAOS_DEF_ERROR_CODE(0, 0x0374)
|
||||
#define TSDB_CODE_MND_NO_USER_FROM_CONN TAOS_DEF_ERROR_CODE(0, 0x0375)
|
||||
|
||||
#define TSDB_CODE_MND_MNODE_ALREADY_EXIST TAOS_DEF_ERROR_CODE(0, 0x0348) //"Mnode already exists")
|
||||
#define TSDB_CODE_MND_MNODE_NOT_EXIST TAOS_DEF_ERROR_CODE(0, 0x0349) //"Mnode not there")
|
||||
// mnode-db
|
||||
#define TSDB_CODE_MND_DB_ALREADY_EXIST TAOS_DEF_ERROR_CODE(0, 0x0380)
|
||||
#define TSDB_CODE_MND_DB_NOT_EXIST TAOS_DEF_ERROR_CODE(0, 0x0381)
|
||||
#define TSDB_CODE_MND_TOO_MANY_DATABASES TAOS_DEF_ERROR_CODE(0, 0x0382)
|
||||
#define TSDB_CODE_MND_DB_NOT_SELECTED TAOS_DEF_ERROR_CODE(0, 0x0383)
|
||||
#define TSDB_CODE_MND_INVALID_DB TAOS_DEF_ERROR_CODE(0, 0x0384)
|
||||
#define TSDB_CODE_MND_INVALID_DB_OPTION TAOS_DEF_ERROR_CODE(0, 0x0385)
|
||||
#define TSDB_CODE_MND_INVALID_DB_ACCT TAOS_DEF_ERROR_CODE(0, 0x0386)
|
||||
#define TSDB_CODE_MND_DB_OPTION_UNCHANGED TAOS_DEF_ERROR_CODE(0, 0x0387)
|
||||
|
||||
// mnode-vgroup
|
||||
#define TSDB_CODE_MND_VGROUP_NOT_EXIST TAOS_DEF_ERROR_CODE(0, 0x0390)
|
||||
#define TSDB_CODE_MND_VGROUP_NOT_IN_DNODE TAOS_DEF_ERROR_CODE(0, 0x0391)
|
||||
#define TSDB_CODE_MND_VGROUP_ALREADY_IN_DNODE TAOS_DEF_ERROR_CODE(0, 0x0392)
|
||||
|
||||
// mnode-stable
|
||||
#define TSDB_CODE_MND_STB_NOT_EXIST TAOS_DEF_ERROR_CODE(0, 0x0360)
|
||||
|
@ -223,30 +244,6 @@ int32_t* taosGetErrno();
|
|||
#define TSDB_CODE_MND_INVALID_TAG_LENGTH TAOS_DEF_ERROR_CODE(0, 0x0376) //"invalid tag length")
|
||||
#define TSDB_CODE_MND_INVALID_COLUMN_LENGTH TAOS_DEF_ERROR_CODE(0, 0x0377) //"invalid column length")
|
||||
|
||||
#define TSDB_CODE_MND_DB_NOT_SELECTED TAOS_DEF_ERROR_CODE(0, 0x0380)
|
||||
#define TSDB_CODE_MND_DB_NOT_EXIST TAOS_DEF_ERROR_CODE(0, 0x0381)
|
||||
#define TSDB_CODE_MND_DB_ALREADY_EXIST TAOS_DEF_ERROR_CODE(0, 0x0381)
|
||||
#define TSDB_CODE_MND_INVALID_DB TAOS_DEF_ERROR_CODE(0, 0x0383)
|
||||
#define TSDB_CODE_MND_INVALID_DB_OPTION TAOS_DEF_ERROR_CODE(0, 0x0382)
|
||||
#define TSDB_CODE_MND_INVALID_DB_CACHE_SIZE TAOS_DEF_ERROR_CODE(0, 0x0383)
|
||||
#define TSDB_CODE_MND_INVALID_DB_TOTAL_BLOCKS TAOS_DEF_ERROR_CODE(0, 0x0383)
|
||||
#define TSDB_CODE_MND_INVALID_DB_DAYS TAOS_DEF_ERROR_CODE(0, 0x0383)
|
||||
#define TSDB_CODE_MND_INVALID_DB_KEEP0 TAOS_DEF_ERROR_CODE(0, 0x0383)
|
||||
#define TSDB_CODE_MND_INVALID_DB_KEEP1 TAOS_DEF_ERROR_CODE(0, 0x0383)
|
||||
#define TSDB_CODE_MND_INVALID_DB_KEEP2 TAOS_DEF_ERROR_CODE(0, 0x0383)
|
||||
#define TSDB_CODE_MND_INVALID_DB_MIN_ROWS TAOS_DEF_ERROR_CODE(0, 0x0383)
|
||||
#define TSDB_CODE_MND_INVALID_DB_MAX_ROWS TAOS_DEF_ERROR_CODE(0, 0x0383)
|
||||
#define TSDB_CODE_MND_INVALID_DB_COMMIT_TIME TAOS_DEF_ERROR_CODE(0, 0x0383)
|
||||
#define TSDB_CODE_MND_INVALID_DB_FSYNC_PERIOD TAOS_DEF_ERROR_CODE(0, 0x0383)
|
||||
#define TSDB_CODE_MND_INVALID_DB_WAL_LEVEL TAOS_DEF_ERROR_CODE(0, 0x0383)
|
||||
#define TSDB_CODE_MND_INVALID_DB_PRECISION TAOS_DEF_ERROR_CODE(0, 0x0383)
|
||||
#define TSDB_CODE_MND_INVALID_DB_COMP TAOS_DEF_ERROR_CODE(0, 0x0383)
|
||||
#define TSDB_CODE_MND_INVALID_DB_REPLICA TAOS_DEF_ERROR_CODE(0, 0x0383)
|
||||
#define TSDB_CODE_MND_INVALID_DB_QUORUM TAOS_DEF_ERROR_CODE(0, 0x0383)
|
||||
#define TSDB_CODE_MND_INVALID_DB_UPDATE TAOS_DEF_ERROR_CODE(0, 0x0383)
|
||||
#define TSDB_CODE_MND_INVALID_DB_CACHE_LAST TAOS_DEF_ERROR_CODE(0, 0x0383)
|
||||
#define TSDB_CODE_MND_DB_OPTION_UNCHANGED TAOS_DEF_ERROR_CODE(0, 0x0383)
|
||||
#define TSDB_CODE_MND_TOO_MANY_DATABASES TAOS_DEF_ERROR_CODE(0, 0x0385) //"Too many databases for account")
|
||||
|
||||
// dnode
|
||||
#define TSDB_CODE_DND_ACTION_IN_PROGRESS TAOS_DEF_ERROR_CODE(0, 0x0400)
|
||||
|
@ -501,6 +498,13 @@ int32_t* taosGetErrno();
|
|||
// monitor
|
||||
#define TSDB_CODE_MON_CONNECTION_INVALID TAOS_DEF_ERROR_CODE(0, 0x2300) //"monitor invalid monitor db connection")
|
||||
|
||||
// catalog
|
||||
#define TSDB_CODE_CTG_INTERNAL_ERROR TAOS_DEF_ERROR_CODE(0, 0x2400) //catalog interval error
|
||||
#define TSDB_CODE_CTG_INVALID_INPUT TAOS_DEF_ERROR_CODE(0, 0x2401) //invalid catalog input parameters
|
||||
#define TSDB_CODE_CTG_NOT_READY TAOS_DEF_ERROR_CODE(0, 0x2402) //catalog is not ready
|
||||
#define TSDB_CODE_CTG_MEM_ERROR TAOS_DEF_ERROR_CODE(0, 0x2403) //catalog memory error
|
||||
#define TSDB_CODE_CTG_SYS_ERROR TAOS_DEF_ERROR_CODE(0, 0x2404) //catalog system error
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
|
|
@ -20,7 +20,7 @@
|
|||
extern "C" {
|
||||
#endif
|
||||
|
||||
#define TSDB_CFG_MAX_NUM 123
|
||||
#define TSDB_CFG_MAX_NUM 115
|
||||
#define TSDB_CFG_PRINT_LEN 23
|
||||
#define TSDB_CFG_OPTION_LEN 24
|
||||
#define TSDB_CFG_VALUE_LEN 41
|
||||
|
@ -83,11 +83,11 @@ extern int32_t tsGlobalConfigNum;
|
|||
extern char * tsCfgStatusStr[];
|
||||
|
||||
void taosReadGlobalLogCfg();
|
||||
int32_t taosReadGlobalCfg();
|
||||
void taosPrintGlobalCfg();
|
||||
int32_t taosReadCfgFromFile();
|
||||
void taosPrintCfg();
|
||||
void taosDumpGlobalCfg();
|
||||
|
||||
void taosInitConfigOption(SGlobalCfg cfg);
|
||||
void taosAddConfigOption(SGlobalCfg cfg);
|
||||
SGlobalCfg *taosGetConfigOption(const char *option);
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
|
|
@ -25,7 +25,9 @@ extern "C" {
|
|||
#define TSDB__packed
|
||||
|
||||
#define TSKEY int64_t
|
||||
#define TSKEY_INITIAL_VAL INT64_MIN
|
||||
#define TSKEY_MIN INT64_MIN
|
||||
#define TSKEY_MAX (INT64_MAX - 1)
|
||||
#define TSKEY_INITIAL_VAL TSKEY_MIN
|
||||
|
||||
// Bytes for each type.
|
||||
extern const int32_t TYPE_BYTES[15];
|
||||
|
@ -161,7 +163,7 @@ do { \
|
|||
|
||||
#define TSDB_NODE_NAME_LEN 64
|
||||
#define TSDB_TABLE_NAME_LEN 193 // it is a null-terminated string
|
||||
#define TSDB_DB_NAME_LEN 33
|
||||
#define TSDB_DB_NAME_LEN 65
|
||||
#define TSDB_FULL_DB_NAME_LEN (TSDB_ACCT_ID_LEN + TSDB_DB_NAME_LEN)
|
||||
|
||||
#define TSDB_FUNC_NAME_LEN 65
|
||||
|
@ -193,7 +195,7 @@ do { \
|
|||
#define TSDB_MAX_TAG_CONDITIONS 1024
|
||||
|
||||
#define TSDB_AUTH_LEN 16
|
||||
#define TSDB_KEY_LEN 16
|
||||
#define TSDB_PASSWORD_LEN 32
|
||||
#define TSDB_VERSION_LEN 12
|
||||
#define TSDB_LABEL_LEN 8
|
||||
|
||||
|
@ -209,6 +211,7 @@ do { \
|
|||
#define TSDB_STEP_NAME_LEN 32
|
||||
#define TSDB_STEP_DESC_LEN 128
|
||||
|
||||
#define TSDB_ERROR_MSG_LEN 1024
|
||||
#define TSDB_DNODE_CONFIG_LEN 128
|
||||
|
||||
#define TSDB_MQTT_HOSTNAME_LEN 64
|
||||
|
|
|
@ -58,8 +58,8 @@ extern "C" {
|
|||
// Double linked list
|
||||
#define TD_DLIST_NODE(TYPE) \
|
||||
struct { \
|
||||
TYPE *dl_prev_; \
|
||||
TYPE *dl_next_; \
|
||||
struct TYPE *dl_prev_; \
|
||||
struct TYPE *dl_next_; \
|
||||
}
|
||||
|
||||
#define TD_DLIST(TYPE) \
|
||||
|
|
|
@ -45,6 +45,8 @@ extern int32_t sDebugFlag;
|
|||
extern int32_t tsdbDebugFlag;
|
||||
extern int32_t cqDebugFlag;
|
||||
extern int32_t debugFlag;
|
||||
extern int32_t ctgDebugFlag;
|
||||
|
||||
|
||||
#define DEBUG_FATAL 1U
|
||||
#define DEBUG_ERROR DEBUG_FATAL
|
||||
|
|
|
@ -29,13 +29,11 @@ extern "C" {
|
|||
#define TD_MOD_UNCLEARD 0
|
||||
#define TD_MOD_CLEARD 1
|
||||
|
||||
#define TD_DEF_MOD_INIT_FLAG(MOD) static int8_t MOD##InitFlag = TD_MOD_UNINITIALIZED
|
||||
#define TD_DEF_MOD_CLEAR_FLAG(MOD) static int8_t MOD##ClearFlag = TD_MOD_UNCLEARD
|
||||
typedef int8_t td_mode_flag_t;
|
||||
|
||||
#define TD_CHECK_AND_SET_MODE_INIT(MOD) \
|
||||
atomic_val_compare_exchange_8(&(MOD##InitFlag), TD_MOD_UNINITIALIZED, TD_MOD_INITIALIZED)
|
||||
#define TD_CHECK_AND_SET_MODE_INIT(FLAG) atomic_val_compare_exchange_8((FLAG), TD_MOD_UNINITIALIZED, TD_MOD_INITIALIZED)
|
||||
|
||||
#define TD_CHECK_AND_SET_MOD_CLEAR(MOD) atomic_val_compare_exchange_8(&(MOD##ClearFlag), TD_MOD_UNCLEARD, TD_MOD_CLEARD)
|
||||
#define TD_CHECK_AND_SET_MOD_CLEAR(FLAG) atomic_val_compare_exchange_8((FLAG), TD_MOD_UNCLEARD, TD_MOD_CLEARD)
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
|
|
@ -45,14 +45,25 @@ char *taosIpStr(uint32_t ipInt);
|
|||
uint32_t ip2uint(const char *const ip_addr);
|
||||
void taosIp2String(uint32_t ip, char *str);
|
||||
void taosIpPort2String(uint32_t ip, uint16_t port, char *str);
|
||||
int32_t taosGetFqdnPortFromEp(const char *ep, char *fqdn, uint16_t *port);
|
||||
|
||||
static FORCE_INLINE void taosEncryptPass(uint8_t *inBuf, size_t inLen, char *target) {
|
||||
T_MD5_CTX context;
|
||||
tMD5Init(&context);
|
||||
tMD5Update(&context, inBuf, (unsigned int)inLen);
|
||||
tMD5Final(&context);
|
||||
memcpy(target, context.digest, TSDB_KEY_LEN);
|
||||
memcpy(target, context.digest, tListLen(context.digest));
|
||||
}
|
||||
|
||||
static FORCE_INLINE void taosEncryptPass_c(uint8_t *inBuf, size_t len, char *target) {
|
||||
T_MD5_CTX context;
|
||||
tMD5Init(&context);
|
||||
tMD5Update(&context, inBuf, (unsigned int)len);
|
||||
tMD5Final(&context);
|
||||
|
||||
sprintf(target, "%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x", context.digest[0], context.digest[1], context.digest[2],
|
||||
context.digest[3], context.digest[4], context.digest[5], context.digest[6], context.digest[7],
|
||||
context.digest[8], context.digest[9], context.digest[10], context.digest[11], context.digest[12],
|
||||
context.digest[13], context.digest[14], context.digest[15]);
|
||||
}
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
|
|
@ -2,9 +2,14 @@ aux_source_directory(src CLIENT_SRC)
|
|||
add_library(taos ${CLIENT_SRC})
|
||||
target_include_directories(
|
||||
taos
|
||||
PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/inc"
|
||||
PUBLIC "${CMAKE_SOURCE_DIR}/include/client"
|
||||
PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/inc"
|
||||
)
|
||||
target_link_libraries(
|
||||
taos
|
||||
PRIVATE common
|
||||
INTERFACE api
|
||||
PRIVATE os util common transport parser
|
||||
)
|
||||
|
||||
ADD_SUBDIRECTORY(test)
|
|
@ -0,0 +1,146 @@
|
|||
/*
|
||||
* 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 TDENGINE_CLIENTINT_H
|
||||
#define TDENGINE_CLIENTINT_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include "taos.h"
|
||||
#include "taosmsg.h"
|
||||
#include "thash.h"
|
||||
#include "tlist.h"
|
||||
#include "trpc.h"
|
||||
#include "tdef.h"
|
||||
#include "tmsgtype.h"
|
||||
#include "tep.h"
|
||||
|
||||
typedef struct SQueryExecMetric {
|
||||
int64_t start; // start timestamp
|
||||
int64_t parsed; // start to parse
|
||||
int64_t send; // start to send to server
|
||||
int64_t rsp; // receive response from server
|
||||
} SQueryExecMetric;
|
||||
|
||||
typedef struct SInstanceActivity {
|
||||
uint64_t numOfInsertsReq;
|
||||
uint64_t numOfInsertRows;
|
||||
uint64_t insertElapsedTime;
|
||||
uint64_t insertBytes; // submit to tsdb since launched.
|
||||
|
||||
uint64_t fetchBytes;
|
||||
uint64_t queryElapsedTime;
|
||||
uint64_t numOfSlowQueries;
|
||||
uint64_t totalRequests;
|
||||
uint64_t currentRequests; // the number of SRequestObj
|
||||
} SInstanceActivity;
|
||||
|
||||
typedef struct SHeartBeatInfo {
|
||||
void *pTimer; // timer, used to send request msg to mnode
|
||||
} SHeartBeatInfo;
|
||||
|
||||
typedef struct SAppInstInfo {
|
||||
int64_t numOfConns;
|
||||
SCorEpSet mgmtEp;
|
||||
SInstanceActivity summary;
|
||||
SList *pConnList; // STscObj linked list
|
||||
uint32_t clusterId;
|
||||
void *pTransporter;
|
||||
} SAppInstInfo;
|
||||
|
||||
typedef struct SAppInfo {
|
||||
int64_t startTime;
|
||||
char appName[TSDB_APP_NAME_LEN];
|
||||
char *ep;
|
||||
int32_t pid;
|
||||
int32_t numOfThreads;
|
||||
SHeartBeatInfo hb;
|
||||
SHashObj *pInstMap;
|
||||
} SAppInfo;
|
||||
|
||||
typedef struct STscObj {
|
||||
char user[TSDB_USER_LEN];
|
||||
char pass[TSDB_PASSWORD_LEN];
|
||||
char acctId[TSDB_ACCT_ID_LEN];
|
||||
char db[TSDB_ACCT_ID_LEN + TSDB_DB_NAME_LEN];
|
||||
uint32_t connId;
|
||||
uint64_t id; // ref ID returned by taosAddRef
|
||||
// struct SSqlObj *sqlList;
|
||||
void *pTransporter;
|
||||
pthread_mutex_t mutex; // used to protect the operation on db
|
||||
int32_t numOfReqs; // number of sqlObj from this tscObj
|
||||
SAppInstInfo *pAppInfo;
|
||||
} STscObj;
|
||||
|
||||
typedef struct SReqBody {
|
||||
tsem_t rspSem; // not used now
|
||||
void* fp;
|
||||
void* param;
|
||||
} SRequestBody;
|
||||
|
||||
typedef struct SRequestObj {
|
||||
uint64_t requestId;
|
||||
int32_t type; // request type
|
||||
STscObj *pTscObj;
|
||||
SQueryExecMetric metric;
|
||||
char *sqlstr; // sql string
|
||||
SRequestBody body;
|
||||
int64_t self;
|
||||
char *msgBuf;
|
||||
int32_t code;
|
||||
void *pInfo; // sql parse info, generated by parser module
|
||||
} SRequestObj;
|
||||
|
||||
typedef struct SRequestMsgBody {
|
||||
int32_t msgType;
|
||||
void *pData;
|
||||
int32_t msgLen;
|
||||
uint64_t requestId;
|
||||
uint64_t requestObjRefId;
|
||||
} SRequestMsgBody;
|
||||
|
||||
extern SAppInfo appInfo;
|
||||
extern int32_t tscReqRef;
|
||||
extern void *tscQhandle;
|
||||
extern int32_t tscConnRef;
|
||||
|
||||
extern int (*tscBuildMsg[TSDB_SQL_MAX])(SRequestObj *pRequest, SRequestMsgBody *pMsg);
|
||||
extern int (*handleRequestRspFp[TSDB_SQL_MAX])(SRequestObj *pRequest, const char* pMsg, int32_t msgLen);
|
||||
|
||||
int taos_init();
|
||||
|
||||
void* createTscObj(const char* user, const char* auth, const char *ip, uint32_t port, SAppInstInfo* pAppInfo);
|
||||
void destroyTscObj(void*pObj);
|
||||
|
||||
void* createRequest(STscObj* pObj, __taos_async_fn_t fp, void* param, int32_t type);
|
||||
void destroyRequest(SRequestObj* pRequest);
|
||||
|
||||
TAOS *taos_connect_internal(const char *ip, const char *user, const char *pass, const char *auth, const char *db, uint16_t port);
|
||||
|
||||
void taos_init_imp(void);
|
||||
int taos_options_imp(TSDB_OPTION option, const char *str);
|
||||
|
||||
void* openTransporter(const char *user, const char *auth);
|
||||
|
||||
void processMsgFromServer(void* parent, SRpcMsg* pMsg, SEpSet* pEpSet);
|
||||
void initMsgHandleFp();
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif // TDENGINE_CLIENTINT_H
|
|
@ -0,0 +1,37 @@
|
|||
/*
|
||||
* 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 TDENGINE_TSCLOG_H
|
||||
#define TDENGINE_TSCLOG_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include "tlog.h"
|
||||
|
||||
#define tscFatal(...) do { if (cDebugFlag & DEBUG_FATAL) { taosPrintLog("TSC FATAL ", cDebugFlag, __VA_ARGS__); }} while(0)
|
||||
#define tscError(...) do { if (cDebugFlag & DEBUG_ERROR) { taosPrintLog("TSC ERROR ", cDebugFlag, __VA_ARGS__); }} while(0)
|
||||
#define tscWarn(...) do { if (cDebugFlag & DEBUG_WARN) { taosPrintLog("TSC WARN ", cDebugFlag, __VA_ARGS__); }} while(0)
|
||||
#define tscInfo(...) do { if (cDebugFlag & DEBUG_INFO) { taosPrintLog("TSC ", cDebugFlag, __VA_ARGS__); }} while(0)
|
||||
#define tscDebug(...) do { if (cDebugFlag & DEBUG_DEBUG) { taosPrintLog("TSC ", cDebugFlag, __VA_ARGS__); }} while(0)
|
||||
#define tscTrace(...) do { if (cDebugFlag & DEBUG_TRACE) { taosPrintLog("TSC ", cDebugFlag, __VA_ARGS__); }} while(0)
|
||||
#define tscDebugL(...) do { if (cDebugFlag & DEBUG_DEBUG) { taosPrintLongString("TSC ", cDebugFlag, __VA_ARGS__); }} while(0)
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
|
@ -13,11 +13,51 @@
|
|||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
//#include "taos.h"
|
||||
#include "os.h"
|
||||
#include "tdef.h"
|
||||
#include "tglobal.h"
|
||||
#include "clientInt.h"
|
||||
#include "tscLog.h"
|
||||
|
||||
//TAOS_RES *taos_query(TAOS *taos, const char *sql) {
|
||||
//
|
||||
//}
|
||||
TAOS *taos_connect(const char *ip, const char *user, const char *pass, const char *db, uint16_t port) {
|
||||
int32_t p = (port != 0)? port:tsServerPort;
|
||||
|
||||
tscDebug("try to connect to %s:%u, user:%s db:%s", ip, p, user, db);
|
||||
if (user == NULL) {
|
||||
user = TSDB_DEFAULT_USER;
|
||||
}
|
||||
|
||||
if (pass == NULL) {
|
||||
pass = TSDB_DEFAULT_PASS;
|
||||
}
|
||||
|
||||
return taos_connect_internal(ip, user, pass, NULL, db, p);
|
||||
}
|
||||
|
||||
TAOS *taos_connect_auth(const char *ip, const char *user, const char *auth, const char *db, uint16_t port) {
|
||||
tscDebug("try to connect to %s:%u by auth, user:%s db:%s", ip, port, user, db);
|
||||
if (user == NULL) {
|
||||
user = TSDB_DEFAULT_USER;
|
||||
}
|
||||
|
||||
if (auth == NULL) {
|
||||
tscError("No auth info is given, failed to connect to server");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return taos_connect_internal(ip, user, NULL, auth, db, port);
|
||||
}
|
||||
|
||||
TAOS *taos_connect_l(const char *ip, int ipLen, const char *user, int userLen, const char *pass, int passLen, const char *db, int dbLen, uint16_t port) {
|
||||
char ipStr[TSDB_EP_LEN] = {0};
|
||||
char dbStr[TSDB_DB_NAME_LEN] = {0};
|
||||
char userStr[TSDB_USER_LEN] = {0};
|
||||
char passStr[TSDB_PASSWORD_LEN] = {0};
|
||||
|
||||
strncpy(ipStr, ip, MIN(TSDB_EP_LEN - 1, ipLen));
|
||||
strncpy(userStr, user, MIN(TSDB_USER_LEN - 1, userLen));
|
||||
strncpy(passStr, pass, MIN(TSDB_PASSWORD_LEN - 1, passLen));
|
||||
strncpy(dbStr, db, MIN(TSDB_DB_NAME_LEN - 1, dbLen));
|
||||
return taos_connect(ipStr, userStr, passStr, dbStr, port);
|
||||
}
|
||||
|
||||
int taos_init() { return 0; }
|
||||
void taos_cleanup(void) {}
|
||||
|
|
|
@ -0,0 +1,283 @@
|
|||
#include <tpagedfile.h>
|
||||
#include "clientInt.h"
|
||||
#include "tdef.h"
|
||||
#include "tep.h"
|
||||
#include "tglobal.h"
|
||||
#include "tmsgtype.h"
|
||||
#include "tref.h"
|
||||
#include "tscLog.h"
|
||||
|
||||
static int32_t initEpSetFromCfg(const char *firstEp, const char *secondEp, SCorEpSet *pEpSet);
|
||||
static int32_t buildConnectMsg(SRequestObj *pRequest, SRequestMsgBody* pMsgBody);
|
||||
static void destroyConnectMsg(SRequestMsgBody* pMsgBody);
|
||||
|
||||
static int32_t sendMsgToServer(void *pTransporter, SEpSet* epSet, const SRequestMsgBody *pBody, int64_t* pTransporterId);
|
||||
|
||||
static bool stringLengthCheck(const char* str, size_t maxsize) {
|
||||
if (str == NULL) {
|
||||
return false;
|
||||
}
|
||||
|
||||
size_t len = strlen(str);
|
||||
if (len <= 0 || len > maxsize) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
static bool validateUserName(const char* user) {
|
||||
return stringLengthCheck(user, TSDB_USER_LEN - 1);
|
||||
}
|
||||
|
||||
static bool validatePassword(const char* passwd) {
|
||||
return stringLengthCheck(passwd, TSDB_PASSWORD_LEN - 1);
|
||||
}
|
||||
|
||||
static bool validateDbName(const char* db) {
|
||||
return stringLengthCheck(db, TSDB_DB_NAME_LEN - 1);
|
||||
}
|
||||
|
||||
static char* getClusterKey(const char* user, const char* auth, const char* ip, int32_t port) {
|
||||
char key[512] = {0};
|
||||
snprintf(key, sizeof(key), "%s:%s:%s:%d", user, auth, ip, port);
|
||||
return strdup(key);
|
||||
}
|
||||
|
||||
static STscObj* taosConnectImpl(const char *ip, const char *user, const char *auth, const char *db, uint16_t port, __taos_async_fn_t fp, void *param, SAppInstInfo* pAppInfo);
|
||||
|
||||
TAOS *taos_connect_internal(const char *ip, const char *user, const char *pass, const char *auth, const char *db, uint16_t port) {
|
||||
if (taos_init() != TSDB_CODE_SUCCESS) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (!validateUserName(user)) {
|
||||
terrno = TSDB_CODE_TSC_INVALID_USER_LENGTH;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
char tmp[TSDB_DB_NAME_LEN] = {0};
|
||||
if (db != NULL) {
|
||||
if(!validateDbName(db)) {
|
||||
terrno = TSDB_CODE_TSC_INVALID_DB_LENGTH;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
tstrncpy(tmp, db, sizeof(tmp));
|
||||
strdequote(tmp);
|
||||
}
|
||||
|
||||
char secretEncrypt[32] = {0};
|
||||
if (auth == NULL) {
|
||||
if (!validatePassword(pass)) {
|
||||
terrno = TSDB_CODE_TSC_INVALID_PASS_LENGTH;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
taosEncryptPass_c((uint8_t *)pass, strlen(pass), secretEncrypt);
|
||||
} else {
|
||||
tstrncpy(secretEncrypt, auth, tListLen(secretEncrypt));
|
||||
}
|
||||
|
||||
SCorEpSet epSet = {0};
|
||||
if (ip) {
|
||||
if (initEpSetFromCfg(ip, NULL, &epSet) < 0) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (port) {
|
||||
epSet.epSet.port[0] = port;
|
||||
}
|
||||
} else {
|
||||
if (initEpSetFromCfg(tsFirst, tsSecond, &epSet) < 0) {
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
char* key = getClusterKey(user, secretEncrypt, ip, port);
|
||||
|
||||
SAppInstInfo* pInst = taosHashGet(appInfo.pInstMap, key, strlen(key));
|
||||
if (pInst == NULL) {
|
||||
pInst = calloc(1, sizeof(struct SAppInstInfo));
|
||||
|
||||
pInst->mgmtEp = epSet;
|
||||
pInst->pTransporter = openTransporter(user, secretEncrypt);
|
||||
|
||||
taosHashPut(appInfo.pInstMap, key, strlen(key), &pInst, POINTER_BYTES);
|
||||
}
|
||||
|
||||
return taosConnectImpl(ip, user, &secretEncrypt[0], db, port, NULL, NULL, pInst);
|
||||
}
|
||||
|
||||
int initEpSetFromCfg(const char *firstEp, const char *secondEp, SCorEpSet *pEpSet) {
|
||||
pEpSet->version = 0;
|
||||
|
||||
// init mgmt ip set
|
||||
SEpSet *mgmtEpSet = &(pEpSet->epSet);
|
||||
mgmtEpSet->numOfEps = 0;
|
||||
mgmtEpSet->inUse = 0;
|
||||
|
||||
if (firstEp && firstEp[0] != 0) {
|
||||
if (strlen(firstEp) >= TSDB_EP_LEN) {
|
||||
terrno = TSDB_CODE_TSC_INVALID_FQDN;
|
||||
return -1;
|
||||
}
|
||||
|
||||
taosGetFqdnPortFromEp(firstEp, mgmtEpSet->fqdn[0], &(mgmtEpSet->port[0]));
|
||||
mgmtEpSet->numOfEps++;
|
||||
}
|
||||
|
||||
if (secondEp && secondEp[0] != 0) {
|
||||
if (strlen(secondEp) >= TSDB_EP_LEN) {
|
||||
terrno = TSDB_CODE_TSC_INVALID_FQDN;
|
||||
return -1;
|
||||
}
|
||||
|
||||
taosGetFqdnPortFromEp(secondEp, mgmtEpSet->fqdn[mgmtEpSet->numOfEps], &(mgmtEpSet->port[mgmtEpSet->numOfEps]));
|
||||
mgmtEpSet->numOfEps++;
|
||||
}
|
||||
|
||||
if (mgmtEpSet->numOfEps == 0) {
|
||||
terrno = TSDB_CODE_TSC_INVALID_FQDN;
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
STscObj* taosConnectImpl(const char *ip, const char *user, const char *auth, const char *db, uint16_t port, __taos_async_fn_t fp, void *param, SAppInstInfo* pAppInfo) {
|
||||
STscObj *pTscObj = createTscObj(user, auth, ip, port, pAppInfo);
|
||||
if (NULL == pTscObj) {
|
||||
terrno = TSDB_CODE_TSC_OUT_OF_MEMORY;
|
||||
return pTscObj;
|
||||
}
|
||||
|
||||
SRequestObj *pRequest = createRequest(pTscObj, fp, param, TSDB_SQL_CONNECT);
|
||||
if (pRequest == NULL) {
|
||||
destroyTscObj(pTscObj);
|
||||
terrno = TSDB_CODE_TSC_OUT_OF_MEMORY;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
SRequestMsgBody body = {0};
|
||||
buildConnectMsg(pRequest, &body);
|
||||
|
||||
int64_t transporterId = 0;
|
||||
sendMsgToServer(pTscObj->pTransporter, &pTscObj->pAppInfo->mgmtEp.epSet, &body, &transporterId);
|
||||
|
||||
tsem_wait(&pRequest->body.rspSem);
|
||||
destroyConnectMsg(&body);
|
||||
|
||||
if (pRequest->code != TSDB_CODE_SUCCESS) {
|
||||
const char *errorMsg = (pRequest->code == TSDB_CODE_RPC_FQDN_ERROR) ? taos_errstr(pRequest) : tstrerror(terrno);
|
||||
printf("failed to connect to server, reason: %s\n\n", errorMsg);
|
||||
|
||||
destroyRequest(pRequest);
|
||||
taos_close(pTscObj);
|
||||
pTscObj = NULL;
|
||||
} else {
|
||||
tscDebug("0x%"PRIx64" connection is opening, connId:%d, dnodeConn:%p", pTscObj->id, pTscObj->connId, pTscObj->pTransporter);
|
||||
destroyRequest(pRequest);
|
||||
}
|
||||
|
||||
return pTscObj;
|
||||
}
|
||||
|
||||
static int32_t buildConnectMsg(SRequestObj *pRequest, SRequestMsgBody* pMsgBody) {
|
||||
pMsgBody->msgType = TSDB_MSG_TYPE_CONNECT;
|
||||
pMsgBody->msgLen = sizeof(SConnectMsg);
|
||||
pMsgBody->requestObjRefId = pRequest->self;
|
||||
|
||||
SConnectMsg *pConnect = calloc(1, sizeof(SConnectMsg));
|
||||
if (pConnect == NULL) {
|
||||
terrno = TSDB_CODE_TSC_OUT_OF_MEMORY;
|
||||
return -1;
|
||||
}
|
||||
|
||||
// TODO refactor full_name
|
||||
char *db; // ugly code to move the space
|
||||
|
||||
STscObj *pObj = pRequest->pTscObj;
|
||||
pthread_mutex_lock(&pObj->mutex);
|
||||
db = strstr(pObj->db, TS_PATH_DELIMITER);
|
||||
|
||||
db = (db == NULL) ? pObj->db : db + 1;
|
||||
tstrncpy(pConnect->db, db, sizeof(pConnect->db));
|
||||
pthread_mutex_unlock(&pObj->mutex);
|
||||
|
||||
pConnect->pid = htonl(appInfo.pid);
|
||||
pConnect->startTime = htobe64(appInfo.startTime);
|
||||
tstrncpy(pConnect->app, appInfo.appName, tListLen(pConnect->app));
|
||||
|
||||
pMsgBody->pData = pConnect;
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void destroyConnectMsg(SRequestMsgBody* pMsgBody) {
|
||||
assert(pMsgBody != NULL);
|
||||
tfree(pMsgBody->pData);
|
||||
}
|
||||
|
||||
int32_t sendMsgToServer(void *pTransporter, SEpSet* epSet, const SRequestMsgBody *pBody, int64_t* pTransporterId) {
|
||||
char *pMsg = rpcMallocCont(pBody->msgLen);
|
||||
if (NULL == pMsg) {
|
||||
tscError("0x%"PRIx64" msg:%s malloc failed", pBody->requestId, taosMsg[pBody->msgType]);
|
||||
terrno = TSDB_CODE_TSC_OUT_OF_MEMORY;
|
||||
return -1;
|
||||
}
|
||||
|
||||
memcpy(pMsg, pBody->pData, pBody->msgLen);
|
||||
SRpcMsg rpcMsg = {
|
||||
.msgType = pBody->msgType,
|
||||
.pCont = pMsg,
|
||||
.contLen = pBody->msgLen,
|
||||
.ahandle = (void*) pBody->requestObjRefId,
|
||||
.handle = NULL,
|
||||
.code = 0
|
||||
};
|
||||
|
||||
rpcSendRequest(pTransporter, epSet, &rpcMsg, pTransporterId);
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
void processMsgFromServer(void* parent, SRpcMsg* pMsg, SEpSet* pEpSet) {
|
||||
int64_t requestRefId = (int64_t)pMsg->ahandle;
|
||||
|
||||
SRequestObj *pRequest = (SRequestObj *)taosAcquireRef(tscReqRef, requestRefId);
|
||||
if (pRequest == NULL) {
|
||||
rpcFreeCont(pMsg->pCont);
|
||||
return;
|
||||
}
|
||||
|
||||
assert(pRequest->self == requestRefId);
|
||||
pRequest->metric.rsp = taosGetTimestampMs();
|
||||
|
||||
pRequest->code = pMsg->code;
|
||||
|
||||
STscObj *pTscObj = pRequest->pTscObj;
|
||||
if (pEpSet) {
|
||||
if (!isEpsetEqual(&pTscObj->pAppInfo->mgmtEp.epSet, pEpSet)) {
|
||||
updateEpSet_s(&pTscObj->pAppInfo->mgmtEp, pEpSet);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* There is not response callback function for submit response.
|
||||
* The actual inserted number of points is the first number.
|
||||
*/
|
||||
if (pMsg->code == TSDB_CODE_SUCCESS) {
|
||||
tscDebug("0x%" PRIx64 " message:%s, code:%s rspLen:%d, elapsed:%"PRId64 " ms", pRequest->requestId, taosMsg[pMsg->msgType],
|
||||
tstrerror(pMsg->code), pMsg->contLen, pRequest->metric.rsp - pRequest->metric.start);
|
||||
if (handleRequestRspFp[pRequest->type]) {
|
||||
pMsg->code = (*handleRequestRspFp[pRequest->type])(pRequest, pMsg->pCont, pMsg->contLen);
|
||||
}
|
||||
} else {
|
||||
tscError("0x%" PRIx64 " SQL cmd:%s, code:%s rspLen:%d", pRequest->requestId, taosMsg[pMsg->msgType],
|
||||
tstrerror(pMsg->code), pMsg->contLen);
|
||||
}
|
||||
|
||||
taosReleaseRef(tscReqRef, requestRefId);
|
||||
rpcFreeCont(pMsg->pCont);
|
||||
|
||||
sem_post(&pRequest->body.rspSem);
|
||||
}
|
File diff suppressed because it is too large
Load Diff
|
@ -0,0 +1,85 @@
|
|||
#include "clientInt.h"
|
||||
#include "trpc.h"
|
||||
#include "os.h"
|
||||
#include "taosmsg.h"
|
||||
#include "tcache.h"
|
||||
#include "tconfig.h"
|
||||
#include "tglobal.h"
|
||||
#include "tnote.h"
|
||||
#include "tref.h"
|
||||
#include "tscLog.h"
|
||||
#include "tsched.h"
|
||||
#include "ttime.h"
|
||||
#include "ttimezone.h"
|
||||
|
||||
#define TSC_VAR_NOT_RELEASE 1
|
||||
#define TSC_VAR_RELEASED 0
|
||||
|
||||
static int32_t sentinel = TSC_VAR_NOT_RELEASE;
|
||||
static pthread_once_t tscinit = PTHREAD_ONCE_INIT;
|
||||
|
||||
extern int32_t tscInitRes;
|
||||
|
||||
int taos_options(TSDB_OPTION option, const void *arg, ...) {
|
||||
static int32_t lock = 0;
|
||||
|
||||
for (int i = 1; atomic_val_compare_exchange_32(&lock, 0, 1) != 0; ++i) {
|
||||
if (i % 1000 == 0) {
|
||||
tscInfo("haven't acquire lock after spin %d times.", i);
|
||||
sched_yield();
|
||||
}
|
||||
}
|
||||
|
||||
int ret = taos_options_imp(option, (const char*)arg);
|
||||
|
||||
atomic_store_32(&lock, 0);
|
||||
return ret;
|
||||
}
|
||||
|
||||
int taos_init() {
|
||||
pthread_once(&tscinit, taos_init_imp);
|
||||
return tscInitRes;
|
||||
}
|
||||
|
||||
// this function may be called by user or system, or by both simultaneously.
|
||||
void taos_cleanup(void) {
|
||||
tscDebug("start to cleanup client environment");
|
||||
|
||||
if (atomic_val_compare_exchange_32(&sentinel, TSC_VAR_NOT_RELEASE, TSC_VAR_RELEASED) != TSC_VAR_NOT_RELEASE) {
|
||||
return;
|
||||
}
|
||||
|
||||
int32_t id = tscReqRef;
|
||||
tscReqRef = -1;
|
||||
taosCloseRef(id);
|
||||
|
||||
void* p = tscQhandle;
|
||||
tscQhandle = NULL;
|
||||
taosCleanUpScheduler(p);
|
||||
|
||||
id = tscConnRef;
|
||||
tscConnRef = -1;
|
||||
taosCloseRef(id);
|
||||
|
||||
rpcCleanup();
|
||||
taosCloseLog();
|
||||
}
|
||||
|
||||
void taos_close(TAOS* taos) {
|
||||
if (taos == NULL) {
|
||||
return;
|
||||
}
|
||||
|
||||
STscObj *pTscObj = (STscObj *)taos;
|
||||
tscDebug("0x%"PRIx64" try to close connection, numOfReq:%d", pTscObj->id, pTscObj->numOfReqs);
|
||||
|
||||
taosRemoveRef(tscConnRef, pTscObj->id);
|
||||
}
|
||||
|
||||
const char *taos_errstr(TAOS_RES *res) {
|
||||
|
||||
}
|
||||
|
||||
void taos_free_result(TAOS_RES *res) {
|
||||
|
||||
}
|
|
@ -0,0 +1,471 @@
|
|||
/*
|
||||
* 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/>.
|
||||
*/
|
||||
|
||||
#include "os.h"
|
||||
#include "taosmsg.h"
|
||||
#include "tcache.h"
|
||||
#include "tconfig.h"
|
||||
#include "tglobal.h"
|
||||
#include "tnote.h"
|
||||
#include "tref.h"
|
||||
#include "tscLog.h"
|
||||
#include "tsched.h"
|
||||
#include "ttime.h"
|
||||
#include "trpc.h"
|
||||
#include "ttimezone.h"
|
||||
#include "clientInt.h"
|
||||
|
||||
#define TSC_VAR_NOT_RELEASE 1
|
||||
#define TSC_VAR_RELEASED 0
|
||||
|
||||
SAppInfo appInfo;
|
||||
int32_t tscReqRef = -1;
|
||||
int32_t tscConnRef = -1;
|
||||
void *tscQhandle = NULL;
|
||||
|
||||
int32_t tsNumOfThreads = 1;
|
||||
volatile int32_t tscInitRes = 0;
|
||||
|
||||
static void registerRequest(SRequestObj* pRequest) {
|
||||
STscObj *pTscObj = (STscObj *)taosAcquireRef(tscConnRef, pRequest->pTscObj->id);
|
||||
assert(pTscObj != NULL);
|
||||
|
||||
// connection has been released already, abort creating request.
|
||||
pRequest->self = taosAddRef(tscReqRef, pRequest);
|
||||
|
||||
int32_t num = atomic_add_fetch_32(&pTscObj->numOfReqs, 1);
|
||||
|
||||
if (pTscObj->pAppInfo) {
|
||||
SInstanceActivity *pActivity = &pTscObj->pAppInfo->summary;
|
||||
|
||||
int32_t total = atomic_add_fetch_32(&pActivity->totalRequests, 1);
|
||||
int32_t currentInst = atomic_add_fetch_32(&pActivity->currentRequests, 1);
|
||||
tscDebug("0x%" PRIx64 " new Request from connObj:0x%" PRIx64 ", current:%d, app current:%d, total:%d", pRequest->self,
|
||||
pRequest->pTscObj->id, num, currentInst, total);
|
||||
}
|
||||
}
|
||||
|
||||
static void deregisterRequest(SRequestObj* pRequest) {
|
||||
assert(pRequest != NULL);
|
||||
|
||||
STscObj* pTscObj = pRequest->pTscObj;
|
||||
SInstanceActivity* pActivity = &pTscObj->pAppInfo->summary;
|
||||
|
||||
int32_t currentInst = atomic_sub_fetch_32(&pActivity->currentRequests, 1);
|
||||
int32_t num = atomic_sub_fetch_32(&pTscObj->numOfReqs, 1);
|
||||
|
||||
tscDebug("0x%"PRIx64" free Request from connObj: 0x%"PRIx64", current:%d, app current:%d", pRequest->self, pTscObj->id, num, currentInst);
|
||||
taosReleaseRef(tscConnRef, pTscObj->id);
|
||||
}
|
||||
|
||||
static void tscInitLogFile() {
|
||||
taosReadGlobalLogCfg();
|
||||
if (mkdir(tsLogDir, 0755) != 0 && errno != EEXIST) {
|
||||
printf("failed to create log dir:%s\n", tsLogDir);
|
||||
}
|
||||
|
||||
const char *defaultLogFileNamePrefix = "taoslog";
|
||||
const int32_t maxLogFileNum = 10;
|
||||
|
||||
char temp[128] = {0};
|
||||
sprintf(temp, "%s/%s", tsLogDir, defaultLogFileNamePrefix);
|
||||
if (taosInitLog(temp, tsNumOfLogLines, maxLogFileNum) < 0) {
|
||||
printf("failed to open log file in directory:%s\n", tsLogDir);
|
||||
}
|
||||
}
|
||||
|
||||
void closeTransporter(STscObj* pTscObj) {
|
||||
if (pTscObj == NULL || pTscObj->pTransporter == NULL) {
|
||||
return;
|
||||
}
|
||||
|
||||
tscDebug("free transporter:%p in connObj: 0x%"PRIx64, pTscObj->pTransporter, pTscObj->id);
|
||||
rpcClose(pTscObj->pTransporter);
|
||||
pTscObj->pTransporter = NULL;
|
||||
}
|
||||
|
||||
// TODO refactor
|
||||
void* openTransporter(const char *user, const char *auth) {
|
||||
SRpcInit rpcInit;
|
||||
memset(&rpcInit, 0, sizeof(rpcInit));
|
||||
rpcInit.localPort = 0;
|
||||
rpcInit.label = "TSC";
|
||||
rpcInit.numOfThreads = tsNumOfThreads;
|
||||
rpcInit.cfp = processMsgFromServer;
|
||||
rpcInit.sessions = tsMaxConnections;
|
||||
rpcInit.connType = TAOS_CONN_CLIENT;
|
||||
rpcInit.user = (char *)user;
|
||||
rpcInit.idleTime = tsShellActivityTimer * 1000;
|
||||
rpcInit.ckey = "key";
|
||||
// rpcInit.spi = 1;
|
||||
rpcInit.secret = (char *)auth;
|
||||
|
||||
void* pDnodeConn = rpcOpen(&rpcInit);
|
||||
if (pDnodeConn == NULL) {
|
||||
tscError("failed to init connection to server");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return pDnodeConn;
|
||||
}
|
||||
|
||||
void destroyTscObj(void *pObj) {
|
||||
STscObj *pTscObj = pObj;
|
||||
|
||||
atomic_sub_fetch_64(&pTscObj->pAppInfo->numOfConns, 1);
|
||||
tscDebug("connObj 0x%"PRIx64" destroyed, totalConn:%"PRId64, pTscObj->id, pTscObj->pAppInfo->numOfConns);
|
||||
|
||||
closeTransporter(pTscObj);
|
||||
pthread_mutex_destroy(&pTscObj->mutex);
|
||||
tfree(pTscObj);
|
||||
}
|
||||
|
||||
void* createTscObj(const char* user, const char* auth, const char *ip, uint32_t port, SAppInstInfo* pAppInfo) {
|
||||
STscObj *pObj = (STscObj *)calloc(1, sizeof(STscObj));
|
||||
if (NULL == pObj) {
|
||||
terrno = TSDB_CODE_TSC_OUT_OF_MEMORY;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
pObj->pAppInfo = pAppInfo;
|
||||
if (pAppInfo != NULL) {
|
||||
pObj->pTransporter = pAppInfo->pTransporter;
|
||||
}
|
||||
|
||||
tstrncpy(pObj->user, user, sizeof(pObj->user));
|
||||
memcpy(pObj->pass, auth, TSDB_PASSWORD_LEN);
|
||||
|
||||
pthread_mutex_init(&pObj->mutex, NULL);
|
||||
pObj->id = taosAddRef(tscConnRef, pObj);
|
||||
|
||||
tscDebug("connObj created, 0x%"PRIx64, pObj->id);
|
||||
return pObj;
|
||||
}
|
||||
|
||||
void* createRequest(STscObj* pObj, __taos_async_fn_t fp, void* param, int32_t type) {
|
||||
assert(pObj != NULL);
|
||||
|
||||
SRequestObj *pRequest = (SRequestObj *)calloc(1, sizeof(SRequestObj));
|
||||
if (NULL == pRequest) {
|
||||
terrno = TSDB_CODE_TSC_OUT_OF_MEMORY;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
// TODO generated request uuid
|
||||
pRequest->requestId = 0;
|
||||
|
||||
pRequest->metric.start = taosGetTimestampMs();
|
||||
|
||||
pRequest->type = type;
|
||||
pRequest->pTscObj = pObj;
|
||||
pRequest->body.fp = fp;
|
||||
pRequest->body.param = param;
|
||||
tsem_init(&pRequest->body.rspSem, 0, 0);
|
||||
|
||||
registerRequest(pRequest);
|
||||
return pRequest;
|
||||
}
|
||||
|
||||
static void doDestroyRequest(void* p) {
|
||||
assert(p != NULL);
|
||||
SRequestObj* pRequest = (SRequestObj*)p;
|
||||
|
||||
assert(RID_VALID(pRequest->self));
|
||||
|
||||
tfree(pRequest->msgBuf);
|
||||
tfree(pRequest->sqlstr);
|
||||
tfree(pRequest->pInfo);
|
||||
|
||||
deregisterRequest(pRequest);
|
||||
tfree(pRequest);
|
||||
}
|
||||
|
||||
void destroyRequest(SRequestObj* pRequest) {
|
||||
if (pRequest == NULL) {
|
||||
return;
|
||||
}
|
||||
|
||||
taosReleaseRef(tscReqRef, pRequest->self);
|
||||
}
|
||||
|
||||
void taos_init_imp(void) {
|
||||
// In the APIs of other program language, taos_cleanup is not available yet.
|
||||
// So, to make sure taos_cleanup will be invoked to clean up the allocated resource to suppress the valgrind warning.
|
||||
atexit(taos_cleanup);
|
||||
|
||||
errno = TSDB_CODE_SUCCESS;
|
||||
srand(taosGetTimestampSec());
|
||||
|
||||
deltaToUtcInitOnce();
|
||||
taosInitGlobalCfg();
|
||||
taosReadCfgFromFile();
|
||||
|
||||
tscInitLogFile();
|
||||
if (taosCheckAndPrintCfg()) {
|
||||
tscInitRes = -1;
|
||||
return;
|
||||
}
|
||||
|
||||
taosInitNotes();
|
||||
initMsgHandleFp();
|
||||
|
||||
rpcInit();
|
||||
|
||||
tscDebug("starting to initialize TAOS driver, local ep: %s", tsLocalEp);
|
||||
|
||||
taosSetCoreDump(true);
|
||||
|
||||
double factor = 4.0;
|
||||
int32_t numOfThreads = MAX((int)(tsNumOfCores * tsNumOfThreadsPerCore / factor), 2);
|
||||
|
||||
int32_t queueSize = tsMaxConnections * 2;
|
||||
tscQhandle = taosInitScheduler(queueSize, numOfThreads, "tsc");
|
||||
if (NULL == tscQhandle) {
|
||||
tscError("failed to init task queue");
|
||||
tscInitRes = -1;
|
||||
return;
|
||||
}
|
||||
|
||||
tscDebug("client task queue is initialized, numOfThreads: %d", numOfThreads);
|
||||
tscConnRef = taosOpenRef(200, destroyTscObj);
|
||||
tscReqRef = taosOpenRef(40960, doDestroyRequest);
|
||||
|
||||
taosGetAppName(appInfo.appName, NULL);
|
||||
appInfo.pid = taosGetPId();
|
||||
appInfo.startTime = taosGetTimestampMs();
|
||||
appInfo.pInstMap = taosHashInit(4, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BINARY), true, HASH_ENTRY_LOCK);
|
||||
|
||||
tscDebug("client is initialized successfully");
|
||||
}
|
||||
|
||||
int taos_options_imp(TSDB_OPTION option, const char *str) {
|
||||
SGlobalCfg *cfg = NULL;
|
||||
|
||||
switch (option) {
|
||||
case TSDB_OPTION_CONFIGDIR:
|
||||
cfg = taosGetConfigOption("configDir");
|
||||
assert(cfg != NULL);
|
||||
|
||||
if (cfg->cfgStatus <= TAOS_CFG_CSTATUS_OPTION) {
|
||||
tstrncpy(configDir, str, TSDB_FILENAME_LEN);
|
||||
cfg->cfgStatus = TAOS_CFG_CSTATUS_OPTION;
|
||||
tscInfo("set config file directory:%s", str);
|
||||
} else {
|
||||
tscWarn("config option:%s, input value:%s, is configured by %s, use %s", cfg->option, str, tsCfgStatusStr[cfg->cfgStatus], (char *)cfg->ptr);
|
||||
}
|
||||
break;
|
||||
|
||||
case TSDB_OPTION_SHELL_ACTIVITY_TIMER:
|
||||
cfg = taosGetConfigOption("shellActivityTimer");
|
||||
assert(cfg != NULL);
|
||||
|
||||
if (cfg->cfgStatus <= TAOS_CFG_CSTATUS_OPTION) {
|
||||
tsShellActivityTimer = atoi(str);
|
||||
if (tsShellActivityTimer < 1) tsShellActivityTimer = 1;
|
||||
if (tsShellActivityTimer > 3600) tsShellActivityTimer = 3600;
|
||||
cfg->cfgStatus = TAOS_CFG_CSTATUS_OPTION;
|
||||
tscInfo("set shellActivityTimer:%d", tsShellActivityTimer);
|
||||
} else {
|
||||
tscWarn("config option:%s, input value:%s, is configured by %s, use %d", cfg->option, str, tsCfgStatusStr[cfg->cfgStatus], *(int32_t *)cfg->ptr);
|
||||
}
|
||||
break;
|
||||
|
||||
case TSDB_OPTION_LOCALE: { // set locale
|
||||
cfg = taosGetConfigOption("locale");
|
||||
assert(cfg != NULL);
|
||||
|
||||
size_t len = strlen(str);
|
||||
if (len == 0 || len > TSDB_LOCALE_LEN) {
|
||||
tscInfo("Invalid locale:%s, use default", str);
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (cfg->cfgStatus <= TAOS_CFG_CSTATUS_OPTION) {
|
||||
char sep = '.';
|
||||
|
||||
if (strlen(tsLocale) == 0) { // locale does not set yet
|
||||
char* defaultLocale = setlocale(LC_CTYPE, "");
|
||||
|
||||
// The locale of the current OS does not be set correctly, so the default locale cannot be acquired.
|
||||
// The launch of current system will abort soon.
|
||||
if (defaultLocale == NULL) {
|
||||
tscError("failed to get default locale, please set the correct locale in current OS");
|
||||
return -1;
|
||||
}
|
||||
|
||||
tstrncpy(tsLocale, defaultLocale, TSDB_LOCALE_LEN);
|
||||
}
|
||||
|
||||
// set the user specified locale
|
||||
char *locale = setlocale(LC_CTYPE, str);
|
||||
|
||||
if (locale != NULL) { // failed to set the user specified locale
|
||||
tscInfo("locale set, prev locale:%s, new locale:%s", tsLocale, locale);
|
||||
cfg->cfgStatus = TAOS_CFG_CSTATUS_OPTION;
|
||||
} else { // set the user specified locale failed, use default LC_CTYPE as current locale
|
||||
locale = setlocale(LC_CTYPE, tsLocale);
|
||||
tscInfo("failed to set locale:%s, current locale:%s", str, tsLocale);
|
||||
}
|
||||
|
||||
tstrncpy(tsLocale, locale, TSDB_LOCALE_LEN);
|
||||
|
||||
char *charset = strrchr(tsLocale, sep);
|
||||
if (charset != NULL) {
|
||||
charset += 1;
|
||||
|
||||
charset = taosCharsetReplace(charset);
|
||||
|
||||
if (taosValidateEncodec(charset)) {
|
||||
if (strlen(tsCharset) == 0) {
|
||||
tscInfo("charset set:%s", charset);
|
||||
} else {
|
||||
tscInfo("charset changed from %s to %s", tsCharset, charset);
|
||||
}
|
||||
|
||||
tstrncpy(tsCharset, charset, TSDB_LOCALE_LEN);
|
||||
cfg->cfgStatus = TAOS_CFG_CSTATUS_OPTION;
|
||||
|
||||
} else {
|
||||
tscInfo("charset:%s is not valid in locale, charset remains:%s", charset, tsCharset);
|
||||
}
|
||||
|
||||
free(charset);
|
||||
} else { // it may be windows system
|
||||
tscInfo("charset remains:%s", tsCharset);
|
||||
}
|
||||
} else {
|
||||
tscWarn("config option:%s, input value:%s, is configured by %s, use %s", cfg->option, str, tsCfgStatusStr[cfg->cfgStatus], (char *)cfg->ptr);
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
case TSDB_OPTION_CHARSET: {
|
||||
/* set charset will override the value of charset, assigned during system locale changed */
|
||||
cfg = taosGetConfigOption("charset");
|
||||
assert(cfg != NULL);
|
||||
|
||||
size_t len = strlen(str);
|
||||
if (len == 0 || len > TSDB_LOCALE_LEN) {
|
||||
tscInfo("failed to set charset:%s", str);
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (cfg->cfgStatus <= TAOS_CFG_CSTATUS_OPTION) {
|
||||
if (taosValidateEncodec(str)) {
|
||||
if (strlen(tsCharset) == 0) {
|
||||
tscInfo("charset is set:%s", str);
|
||||
} else {
|
||||
tscInfo("charset changed from %s to %s", tsCharset, str);
|
||||
}
|
||||
|
||||
tstrncpy(tsCharset, str, TSDB_LOCALE_LEN);
|
||||
cfg->cfgStatus = TAOS_CFG_CSTATUS_OPTION;
|
||||
} else {
|
||||
tscInfo("charset:%s not valid", str);
|
||||
}
|
||||
} else {
|
||||
tscWarn("config option:%s, input value:%s, is configured by %s, use %s", cfg->option, str, tsCfgStatusStr[cfg->cfgStatus], (char *)cfg->ptr);
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
case TSDB_OPTION_TIMEZONE:
|
||||
cfg = taosGetConfigOption("timezone");
|
||||
assert(cfg != NULL);
|
||||
|
||||
if (cfg->cfgStatus <= TAOS_CFG_CSTATUS_OPTION) {
|
||||
tstrncpy(tsTimezone, str, TSDB_TIMEZONE_LEN);
|
||||
tsSetTimeZone();
|
||||
cfg->cfgStatus = TAOS_CFG_CSTATUS_OPTION;
|
||||
tscDebug("timezone set:%s, input:%s by taos_options", tsTimezone, str);
|
||||
} else {
|
||||
tscWarn("config option:%s, input value:%s, is configured by %s, use %s", cfg->option, str, tsCfgStatusStr[cfg->cfgStatus], (char *)cfg->ptr);
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
// TODO return the correct error code to client in the format for taos_errstr()
|
||||
tscError("Invalid option %d", option);
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
#if 0
|
||||
#include "cJSON.h"
|
||||
static setConfRet taos_set_config_imp(const char *config){
|
||||
setConfRet ret = {SET_CONF_RET_SUCC, {0}};
|
||||
static bool setConfFlag = false;
|
||||
if (setConfFlag) {
|
||||
ret.retCode = SET_CONF_RET_ERR_ONLY_ONCE;
|
||||
strcpy(ret.retMsg, "configuration can only set once");
|
||||
return ret;
|
||||
}
|
||||
taosInitGlobalCfg();
|
||||
cJSON *root = cJSON_Parse(config);
|
||||
if (root == NULL){
|
||||
ret.retCode = SET_CONF_RET_ERR_JSON_PARSE;
|
||||
strcpy(ret.retMsg, "parse json error");
|
||||
return ret;
|
||||
}
|
||||
|
||||
int size = cJSON_GetArraySize(root);
|
||||
if(!cJSON_IsObject(root) || size == 0) {
|
||||
ret.retCode = SET_CONF_RET_ERR_JSON_INVALID;
|
||||
strcpy(ret.retMsg, "json content is invalid, must be not empty object");
|
||||
return ret;
|
||||
}
|
||||
|
||||
if(size >= 1000) {
|
||||
ret.retCode = SET_CONF_RET_ERR_TOO_LONG;
|
||||
strcpy(ret.retMsg, "json object size is too long");
|
||||
return ret;
|
||||
}
|
||||
|
||||
for(int i = 0; i < size; i++){
|
||||
cJSON *item = cJSON_GetArrayItem(root, i);
|
||||
if(!item) {
|
||||
ret.retCode = SET_CONF_RET_ERR_INNER;
|
||||
strcpy(ret.retMsg, "inner error");
|
||||
return ret;
|
||||
}
|
||||
if(!taosReadConfigOption(item->string, item->valuestring, NULL, NULL, TAOS_CFG_CSTATUS_OPTION, TSDB_CFG_CTYPE_B_CLIENT)){
|
||||
ret.retCode = SET_CONF_RET_ERR_PART;
|
||||
if (strlen(ret.retMsg) == 0){
|
||||
snprintf(ret.retMsg, RET_MSG_LENGTH, "part error|%s", item->string);
|
||||
}else{
|
||||
int tmp = RET_MSG_LENGTH - 1 - (int)strlen(ret.retMsg);
|
||||
size_t leftSize = tmp >= 0 ? tmp : 0;
|
||||
strncat(ret.retMsg, "|", leftSize);
|
||||
tmp = RET_MSG_LENGTH - 1 - (int)strlen(ret.retMsg);
|
||||
leftSize = tmp >= 0 ? tmp : 0;
|
||||
strncat(ret.retMsg, item->string, leftSize);
|
||||
}
|
||||
}
|
||||
}
|
||||
cJSON_Delete(root);
|
||||
setConfFlag = true;
|
||||
return ret;
|
||||
}
|
||||
|
||||
setConfRet taos_set_config(const char *config){
|
||||
pthread_mutex_lock(&setConfMutex);
|
||||
setConfRet ret = taos_set_config_imp(config);
|
||||
pthread_mutex_unlock(&setConfMutex);
|
||||
return ret;
|
||||
}
|
||||
#endif
|
|
@ -0,0 +1,18 @@
|
|||
|
||||
MESSAGE(STATUS "build parser unit test")
|
||||
|
||||
# GoogleTest requires at least C++11
|
||||
SET(CMAKE_CXX_STANDARD 11)
|
||||
AUX_SOURCE_DIRECTORY(${CMAKE_CURRENT_SOURCE_DIR} SOURCE_LIST)
|
||||
|
||||
ADD_EXECUTABLE(clientTest ${SOURCE_LIST})
|
||||
TARGET_LINK_LIBRARIES(
|
||||
clientTest
|
||||
PUBLIC os util common transport gtest taos
|
||||
)
|
||||
|
||||
TARGET_INCLUDE_DIRECTORIES(
|
||||
clientTest
|
||||
PUBLIC "${CMAKE_SOURCE_DIR}/include/libs/client/"
|
||||
PRIVATE "${CMAKE_SOURCE_DIR}/source/libs/client/inc"
|
||||
)
|
|
@ -0,0 +1,40 @@
|
|||
/*
|
||||
* 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/>.
|
||||
*/
|
||||
|
||||
#include <gtest/gtest.h>
|
||||
#include <iostream>
|
||||
#include "tglobal.h"
|
||||
#pragma GCC diagnostic ignored "-Wwrite-strings"
|
||||
|
||||
#pragma GCC diagnostic ignored "-Wunused-function"
|
||||
#pragma GCC diagnostic ignored "-Wunused-variable"
|
||||
#pragma GCC diagnostic ignored "-Wsign-compare"
|
||||
|
||||
#include "taos.h"
|
||||
|
||||
namespace {
|
||||
} // namespace
|
||||
|
||||
int main(int argc, char** argv) {
|
||||
testing::InitGoogleTest(&argc, argv);
|
||||
return RUN_ALL_TESTS();
|
||||
}
|
||||
|
||||
TEST(testCase, driverInit_Test) {
|
||||
TAOS* pConn = taos_connect("ubuntu", "root", "taosdata", NULL, 0);
|
||||
assert(pConn != NULL);
|
||||
|
||||
taos_close(pConn);
|
||||
}
|
|
@ -20,8 +20,11 @@
|
|||
extern "C" {
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /*_TD_COMMON_INT_H_*/
|
||||
#endif /*_TD_COMMON_INT_H_*/
|
||||
|
|
|
@ -16,3 +16,5 @@
|
|||
#define TAOS_MESSAGE_C
|
||||
|
||||
#include "taosmsg.h"
|
||||
|
||||
|
|
@ -0,0 +1,41 @@
|
|||
#include "tep.h"
|
||||
#include "tglobal.h"
|
||||
#include "tlockfree.h"
|
||||
|
||||
int taosGetFqdnPortFromEp(const char *ep, char *fqdn, uint16_t *port) {
|
||||
*port = 0;
|
||||
strcpy(fqdn, ep);
|
||||
|
||||
char *temp = strchr(fqdn, ':');
|
||||
if (temp) {
|
||||
*temp = 0;
|
||||
*port = atoi(temp+1);
|
||||
}
|
||||
|
||||
if (*port == 0) {
|
||||
*port = tsServerPort;
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
bool isEpsetEqual(const SEpSet *s1, const SEpSet *s2) {
|
||||
if (s1->numOfEps != s2->numOfEps || s1->inUse != s2->inUse) {
|
||||
return false;
|
||||
}
|
||||
|
||||
for (int32_t i = 0; i < s1->numOfEps; i++) {
|
||||
if (s1->port[i] != s2->port[i]
|
||||
|| strncmp(s1->fqdn[i], s2->fqdn[i], TSDB_FQDN_LEN) != 0)
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
void updateEpSet_s(SCorEpSet *pEpSet, SEpSet *pNewEpSet) {
|
||||
taosCorBeginWrite(&pEpSet->version);
|
||||
pEpSet->epSet = *pNewEpSet;
|
||||
taosCorEndWrite(&pEpSet->version);
|
||||
}
|
||||
|
File diff suppressed because it is too large
Load Diff
|
@ -112,12 +112,12 @@ int dmnReadConfig(const char *path) {
|
|||
return -1;
|
||||
}
|
||||
|
||||
if (taosReadGlobalCfg() != 0) {
|
||||
if (taosReadCfgFromFile() != 0) {
|
||||
uError("failed to read global config");
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (taosCheckGlobalCfg() != 0) {
|
||||
if (taosCheckAndPrintCfg() != 0) {
|
||||
uError("failed to check global config");
|
||||
return -1;
|
||||
}
|
||||
|
|
|
@ -17,6 +17,7 @@
|
|||
#include "dndDnode.h"
|
||||
#include "dndTransport.h"
|
||||
#include "dndVnodes.h"
|
||||
#include "tep.h"
|
||||
|
||||
int32_t dndGetDnodeId(SDnode *pDnode) {
|
||||
SDnodeMgmt *pMgmt = &pDnode->dmgmt;
|
||||
|
|
|
@ -72,7 +72,7 @@ static void dndInitMsgFp(STransMgmt *pMgmt) {
|
|||
pMgmt->msgFp[TSDB_MSG_TYPE_CREATE_STB] = dndProcessMnodeWriteMsg;
|
||||
pMgmt->msgFp[TSDB_MSG_TYPE_ALTER_STB] = dndProcessMnodeWriteMsg;
|
||||
pMgmt->msgFp[TSDB_MSG_TYPE_DROP_STB] = dndProcessMnodeWriteMsg;
|
||||
pMgmt->msgFp[TSDB_MSG_TYPE_STB_VGROUP] = dndProcessMnodeReadMsg;
|
||||
pMgmt->msgFp[TSDB_MSG_TYPE_VGROUP_LIST] = dndProcessMnodeReadMsg;
|
||||
pMgmt->msgFp[TSDB_MSG_TYPE_KILL_QUERY] = dndProcessMnodeWriteMsg;
|
||||
pMgmt->msgFp[TSDB_MSG_TYPE_KILL_STREAM] = dndProcessMnodeWriteMsg;
|
||||
pMgmt->msgFp[TSDB_MSG_TYPE_KILL_CONN] = dndProcessMnodeWriteMsg;
|
||||
|
@ -235,18 +235,18 @@ static void dndSendMsgToMnodeRecv(SDnode *pDnode, SRpcMsg *pRpcMsg, SRpcMsg *pRp
|
|||
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};
|
||||
char pass[TSDB_PASSWORD_LEN] = {0};
|
||||
taosEncryptPass((uint8_t *)(INTERNAL_SECRET), strlen(INTERNAL_SECRET), pass);
|
||||
memcpy(secret, pass, TSDB_KEY_LEN);
|
||||
memcpy(secret, pass, TSDB_PASSWORD_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};
|
||||
char pass[TSDB_PASSWORD_LEN] = {0};
|
||||
taosEncryptPass((uint8_t *)(TSDB_NETTEST_USER), strlen(TSDB_NETTEST_USER), pass);
|
||||
memcpy(secret, pass, TSDB_KEY_LEN);
|
||||
memcpy(secret, pass, TSDB_PASSWORD_LEN);
|
||||
*spi = 0;
|
||||
*encrypt = 0;
|
||||
*ckey = 0;
|
||||
|
@ -288,8 +288,8 @@ static int32_t dndRetrieveUserAuthInfo(void *parent, char *user, char *spi, char
|
|||
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);
|
||||
memcpy(secret, pRsp->secret, TSDB_PASSWORD_LEN);
|
||||
memcpy(ckey, pRsp->ckey, TSDB_PASSWORD_LEN);
|
||||
*spi = pRsp->spi;
|
||||
*encrypt = pRsp->encrypt;
|
||||
dDebug("user:%s, success to get user auth from other mnodes", user);
|
||||
|
@ -368,4 +368,4 @@ void dndSendMsgToMnode(SDnode *pDnode, SRpcMsg *pMsg) {
|
|||
SEpSet epSet = {0};
|
||||
dndGetMnodeEpSet(pDnode, &epSet);
|
||||
dndSendMsgToDnode(pDnode, &epSet, pMsg);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,6 +1,19 @@
|
|||
# add_subdirectory(acct)
|
||||
|
||||
add_subdirectory(acct)
|
||||
# add_subdirectory(auth)
|
||||
# add_subdirectory(balance)
|
||||
# add_subdirectory(cluster)
|
||||
add_subdirectory(db)
|
||||
add_subdirectory(dnode)
|
||||
# add_subdirectory(func)
|
||||
# add_subdirectory(mnode)
|
||||
# add_subdirectory(profile)
|
||||
# add_subdirectory(show)
|
||||
# add_subdirectory(stb)
|
||||
# add_subdirectory(sync)
|
||||
# add_subdirectory(telem)
|
||||
# add_subdirectory(trans)
|
||||
add_subdirectory(user)
|
||||
# add_subdirectory(vgroup)
|
||||
|
||||
# add_subdirectory(common)
|
||||
|
|
|
@ -1,20 +1,20 @@
|
|||
add_executable(dndTestAcct "")
|
||||
add_executable(dnode_test_acct "")
|
||||
|
||||
target_sources(dndTestAcct
|
||||
target_sources(dnode_test_acct
|
||||
PRIVATE
|
||||
"acct.cpp"
|
||||
"../sut/deploy.cpp"
|
||||
)
|
||||
|
||||
target_link_libraries(
|
||||
dndTestAcct
|
||||
dnode_test_acct
|
||||
PUBLIC dnode
|
||||
PUBLIC util
|
||||
PUBLIC os
|
||||
PUBLIC gtest_main
|
||||
)
|
||||
|
||||
target_include_directories(dndTestAcct
|
||||
target_include_directories(dnode_test_acct
|
||||
PUBLIC
|
||||
"${CMAKE_SOURCE_DIR}/include/server/dnode/mgmt"
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/../../inc"
|
||||
|
@ -24,6 +24,6 @@ target_include_directories(dndTestAcct
|
|||
enable_testing()
|
||||
|
||||
add_test(
|
||||
NAME dndTestAcct
|
||||
COMMAND dndTestAcct
|
||||
NAME dnode_test_acct
|
||||
COMMAND dnode_test_acct
|
||||
)
|
||||
|
|
|
@ -17,24 +17,27 @@
|
|||
|
||||
class DndTestAcct : public ::testing::Test {
|
||||
protected:
|
||||
void SetUp() override {}
|
||||
void TearDown() override {}
|
||||
static SServer* CreateServer(const char* path, const char* fqdn, uint16_t port, const char* firstEp) {
|
||||
SServer* pServer = createServer(path, fqdn, port, firstEp);
|
||||
ASSERT(pServer);
|
||||
return pServer;
|
||||
}
|
||||
|
||||
static void SetUpTestSuite() {
|
||||
const char* user = "root";
|
||||
const char* pass = "taosdata";
|
||||
const char* path = "/tmp/dndTestAcct";
|
||||
const char* fqdn = "localhost";
|
||||
uint16_t port = 9520;
|
||||
initLog("/tmp/tdlog");
|
||||
|
||||
pServer = createServer(path, fqdn, port);
|
||||
ASSERT(pServer);
|
||||
pClient = createClient(user, pass, fqdn, port);
|
||||
const char* fqdn = "localhost";
|
||||
const char* firstEp = "localhost:9012";
|
||||
pServer = CreateServer("/tmp/dnode_test_user", fqdn, 9012, firstEp);
|
||||
pClient = createClient("root", "taosdata", fqdn, 9012);
|
||||
taosMsleep(300);
|
||||
}
|
||||
|
||||
static void TearDownTestSuite() {
|
||||
stopServer(pServer);
|
||||
dropClient(pClient);
|
||||
pServer = NULL;
|
||||
pClient = NULL;
|
||||
}
|
||||
|
||||
static SServer* pServer;
|
||||
|
|
|
@ -0,0 +1,29 @@
|
|||
add_executable(dnode_test_db "")
|
||||
|
||||
target_sources(dnode_test_db
|
||||
PRIVATE
|
||||
"db.cpp"
|
||||
"../sut/deploy.cpp"
|
||||
)
|
||||
|
||||
target_link_libraries(
|
||||
dnode_test_db
|
||||
PUBLIC dnode
|
||||
PUBLIC util
|
||||
PUBLIC os
|
||||
PUBLIC gtest_main
|
||||
)
|
||||
|
||||
target_include_directories(dnode_test_db
|
||||
PUBLIC
|
||||
"${CMAKE_SOURCE_DIR}/include/server/dnode/mgmt"
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/../../inc"
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/../sut"
|
||||
)
|
||||
|
||||
enable_testing()
|
||||
|
||||
add_test(
|
||||
NAME dnode_test_db
|
||||
COMMAND dnode_test_db
|
||||
)
|
|
@ -0,0 +1,355 @@
|
|||
/*
|
||||
* 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/>.
|
||||
*/
|
||||
|
||||
#include "deploy.h"
|
||||
|
||||
class DndTestDb : public ::testing::Test {
|
||||
protected:
|
||||
static SServer* CreateServer(const char* path, const char* fqdn, uint16_t port, const char* firstEp) {
|
||||
SServer* pServer = createServer(path, fqdn, port, firstEp);
|
||||
ASSERT(pServer);
|
||||
return pServer;
|
||||
}
|
||||
|
||||
static void SetUpTestSuite() {
|
||||
initLog("/tmp/tdlog");
|
||||
|
||||
const char* fqdn = "localhost";
|
||||
const char* firstEp = "localhost:9040";
|
||||
pServer = CreateServer("/tmp/dnode_test_db", fqdn, 9040, firstEp);
|
||||
pClient = createClient("root", "taosdata", fqdn, 9040);
|
||||
taosMsleep(300);
|
||||
}
|
||||
|
||||
static void TearDownTestSuite() {
|
||||
stopServer(pServer);
|
||||
dropClient(pClient);
|
||||
pServer = NULL;
|
||||
pClient = NULL;
|
||||
}
|
||||
|
||||
static SServer* pServer;
|
||||
static SClient* pClient;
|
||||
static int32_t connId;
|
||||
|
||||
public:
|
||||
void SetUp() override {}
|
||||
void TearDown() override {}
|
||||
|
||||
void SendTheCheckShowMetaMsg(int8_t showType, const char* showName, int32_t columns) {
|
||||
SShowMsg* pShow = (SShowMsg*)rpcMallocCont(sizeof(SShowMsg));
|
||||
pShow->type = showType;
|
||||
strcpy(pShow->db, "");
|
||||
|
||||
SRpcMsg showRpcMsg = {0};
|
||||
showRpcMsg.pCont = pShow;
|
||||
showRpcMsg.contLen = sizeof(SShowMsg);
|
||||
showRpcMsg.msgType = TSDB_MSG_TYPE_SHOW;
|
||||
|
||||
sendMsg(pClient, &showRpcMsg);
|
||||
ASSERT_NE(pClient->pRsp, nullptr);
|
||||
ASSERT_EQ(pClient->pRsp->code, 0);
|
||||
ASSERT_NE(pClient->pRsp->pCont, nullptr);
|
||||
|
||||
SShowRsp* pShowRsp = (SShowRsp*)pClient->pRsp->pCont;
|
||||
ASSERT_NE(pShowRsp, nullptr);
|
||||
pShowRsp->showId = htonl(pShowRsp->showId);
|
||||
pMeta = &pShowRsp->tableMeta;
|
||||
pMeta->numOfTags = htons(pMeta->numOfTags);
|
||||
pMeta->numOfColumns = htons(pMeta->numOfColumns);
|
||||
pMeta->sversion = htons(pMeta->sversion);
|
||||
pMeta->tversion = htons(pMeta->tversion);
|
||||
pMeta->tuid = htobe64(pMeta->tuid);
|
||||
pMeta->suid = htobe64(pMeta->suid);
|
||||
|
||||
showId = pShowRsp->showId;
|
||||
|
||||
EXPECT_NE(pShowRsp->showId, 0);
|
||||
EXPECT_STREQ(pMeta->tbFname, showName);
|
||||
EXPECT_EQ(pMeta->numOfTags, 0);
|
||||
EXPECT_EQ(pMeta->numOfColumns, columns);
|
||||
EXPECT_EQ(pMeta->precision, 0);
|
||||
EXPECT_EQ(pMeta->tableType, 0);
|
||||
EXPECT_EQ(pMeta->update, 0);
|
||||
EXPECT_EQ(pMeta->sversion, 0);
|
||||
EXPECT_EQ(pMeta->tversion, 0);
|
||||
EXPECT_EQ(pMeta->tuid, 0);
|
||||
EXPECT_EQ(pMeta->suid, 0);
|
||||
}
|
||||
|
||||
void CheckSchema(int32_t index, int8_t type, int32_t bytes, const char* name) {
|
||||
SSchema* pSchema = &pMeta->pSchema[index];
|
||||
pSchema->bytes = htons(pSchema->bytes);
|
||||
EXPECT_EQ(pSchema->colId, 0);
|
||||
EXPECT_EQ(pSchema->type, type);
|
||||
EXPECT_EQ(pSchema->bytes, bytes);
|
||||
EXPECT_STREQ(pSchema->name, name);
|
||||
}
|
||||
|
||||
void SendThenCheckShowRetrieveMsg(int32_t rows) {
|
||||
SRetrieveTableMsg* pRetrieve = (SRetrieveTableMsg*)rpcMallocCont(sizeof(SRetrieveTableMsg));
|
||||
pRetrieve->showId = htonl(showId);
|
||||
pRetrieve->free = 0;
|
||||
|
||||
SRpcMsg retrieveRpcMsg = {0};
|
||||
retrieveRpcMsg.pCont = pRetrieve;
|
||||
retrieveRpcMsg.contLen = sizeof(SRetrieveTableMsg);
|
||||
retrieveRpcMsg.msgType = TSDB_MSG_TYPE_SHOW_RETRIEVE;
|
||||
|
||||
sendMsg(pClient, &retrieveRpcMsg);
|
||||
|
||||
ASSERT_NE(pClient->pRsp, nullptr);
|
||||
ASSERT_EQ(pClient->pRsp->code, 0);
|
||||
ASSERT_NE(pClient->pRsp->pCont, nullptr);
|
||||
|
||||
pRetrieveRsp = (SRetrieveTableRsp*)pClient->pRsp->pCont;
|
||||
ASSERT_NE(pRetrieveRsp, nullptr);
|
||||
pRetrieveRsp->numOfRows = htonl(pRetrieveRsp->numOfRows);
|
||||
pRetrieveRsp->offset = htobe64(pRetrieveRsp->offset);
|
||||
pRetrieveRsp->useconds = htobe64(pRetrieveRsp->useconds);
|
||||
pRetrieveRsp->compLen = htonl(pRetrieveRsp->compLen);
|
||||
|
||||
EXPECT_EQ(pRetrieveRsp->numOfRows, rows);
|
||||
EXPECT_EQ(pRetrieveRsp->offset, 0);
|
||||
EXPECT_EQ(pRetrieveRsp->useconds, 0);
|
||||
// EXPECT_EQ(pRetrieveRsp->completed, completed);
|
||||
EXPECT_EQ(pRetrieveRsp->precision, TSDB_TIME_PRECISION_MILLI);
|
||||
EXPECT_EQ(pRetrieveRsp->compressed, 0);
|
||||
EXPECT_EQ(pRetrieveRsp->reserved, 0);
|
||||
EXPECT_EQ(pRetrieveRsp->compLen, 0);
|
||||
|
||||
pData = pRetrieveRsp->data;
|
||||
pos = 0;
|
||||
}
|
||||
|
||||
void CheckInt8(int8_t val) {
|
||||
int8_t data = *((int8_t*)(pData + pos));
|
||||
pos += sizeof(int8_t);
|
||||
EXPECT_EQ(data, val);
|
||||
}
|
||||
|
||||
void CheckInt16(int16_t val) {
|
||||
int16_t data = *((int16_t*)(pData + pos));
|
||||
pos += sizeof(int16_t);
|
||||
EXPECT_EQ(data, val);
|
||||
}
|
||||
|
||||
void CheckInt32(int32_t val) {
|
||||
int32_t data = *((int32_t*)(pData + pos));
|
||||
pos += sizeof(int32_t);
|
||||
EXPECT_EQ(data, val);
|
||||
}
|
||||
|
||||
void CheckInt64(int64_t val) {
|
||||
int64_t data = *((int64_t*)(pData + pos));
|
||||
pos += sizeof(int64_t);
|
||||
EXPECT_EQ(data, val);
|
||||
}
|
||||
|
||||
void CheckTimestamp() {
|
||||
int64_t data = *((int64_t*)(pData + pos));
|
||||
pos += sizeof(int64_t);
|
||||
EXPECT_GT(data, 0);
|
||||
}
|
||||
|
||||
void CheckBinary(const char* val, int32_t len) {
|
||||
pos += sizeof(VarDataLenT);
|
||||
char* data = (char*)(pData + pos);
|
||||
pos += len;
|
||||
EXPECT_STREQ(data, val);
|
||||
}
|
||||
|
||||
int32_t showId;
|
||||
STableMetaMsg* pMeta;
|
||||
SRetrieveTableRsp* pRetrieveRsp;
|
||||
char* pData;
|
||||
int32_t pos;
|
||||
};
|
||||
|
||||
SServer* DndTestDb::pServer;
|
||||
SClient* DndTestDb::pClient;
|
||||
int32_t DndTestDb::connId;
|
||||
|
||||
TEST_F(DndTestDb, 01_ShowDb) {
|
||||
SendTheCheckShowMetaMsg(TSDB_MGMT_TABLE_DB, "show databases", 16);
|
||||
CheckSchema(0, TSDB_DATA_TYPE_BINARY, TSDB_DB_NAME_LEN - 1 + VARSTR_HEADER_SIZE, "name");
|
||||
CheckSchema(1, TSDB_DATA_TYPE_TIMESTAMP, 8, "create time");
|
||||
CheckSchema(2, TSDB_DATA_TYPE_SMALLINT, 2, "replica");
|
||||
CheckSchema(3, TSDB_DATA_TYPE_SMALLINT, 2, "quorum");
|
||||
CheckSchema(4, TSDB_DATA_TYPE_SMALLINT, 2, "days");
|
||||
CheckSchema(5, TSDB_DATA_TYPE_BINARY, 24 + VARSTR_HEADER_SIZE, "keep0,keep1,keep2");
|
||||
CheckSchema(6, TSDB_DATA_TYPE_INT, 4, "cache(MB)");
|
||||
CheckSchema(7, TSDB_DATA_TYPE_INT, 4, "blocks");
|
||||
CheckSchema(8, TSDB_DATA_TYPE_INT, 4, "minrows");
|
||||
CheckSchema(9, TSDB_DATA_TYPE_INT, 4, "maxrows");
|
||||
CheckSchema(10, TSDB_DATA_TYPE_TINYINT, 1, "wallevel");
|
||||
CheckSchema(11, TSDB_DATA_TYPE_INT, 4, "fsync");
|
||||
CheckSchema(12, TSDB_DATA_TYPE_TINYINT, 1, "comp");
|
||||
CheckSchema(13, TSDB_DATA_TYPE_TINYINT, 1, "cachelast");
|
||||
CheckSchema(14, TSDB_DATA_TYPE_BINARY, 3 + VARSTR_HEADER_SIZE, "precision");
|
||||
CheckSchema(15, TSDB_DATA_TYPE_TINYINT, 1, "update");
|
||||
|
||||
SendThenCheckShowRetrieveMsg(0);
|
||||
}
|
||||
|
||||
TEST_F(DndTestDb, 02_CreateDb) {
|
||||
{
|
||||
SCreateDbMsg* pReq = (SCreateDbMsg*)rpcMallocCont(sizeof(SCreateDbMsg));
|
||||
strcpy(pReq->db, "1.d1");
|
||||
pReq->cacheBlockSize = htonl(16);
|
||||
pReq->totalBlocks = htonl(10);
|
||||
pReq->daysPerFile = htonl(10);
|
||||
pReq->daysToKeep0 = htonl(3650);
|
||||
pReq->daysToKeep1 = htonl(3650);
|
||||
pReq->daysToKeep2 = htonl(3650);
|
||||
pReq->minRowsPerFileBlock = htonl(100);
|
||||
pReq->maxRowsPerFileBlock = htonl(4096);
|
||||
pReq->commitTime = htonl(3600);
|
||||
pReq->fsyncPeriod = htonl(3000);
|
||||
pReq->walLevel = 1;
|
||||
pReq->precision = 0;
|
||||
pReq->compression = 2;
|
||||
pReq->replications = 1;
|
||||
pReq->quorum = 1;
|
||||
pReq->update = 0;
|
||||
pReq->cacheLastRow = 0;
|
||||
pReq->ignoreExist = 1;
|
||||
|
||||
SRpcMsg rpcMsg = {0};
|
||||
rpcMsg.pCont = pReq;
|
||||
rpcMsg.contLen = sizeof(SCreateDbMsg);
|
||||
rpcMsg.msgType = TSDB_MSG_TYPE_CREATE_DB;
|
||||
|
||||
sendMsg(pClient, &rpcMsg);
|
||||
SRpcMsg* pMsg = pClient->pRsp;
|
||||
ASSERT_NE(pMsg, nullptr);
|
||||
ASSERT_EQ(pMsg->code, 0);
|
||||
}
|
||||
|
||||
SendTheCheckShowMetaMsg(TSDB_MGMT_TABLE_DB, "show databases", 16);
|
||||
SendThenCheckShowRetrieveMsg(1);
|
||||
CheckBinary("d1", TSDB_DB_NAME_LEN - 1);
|
||||
CheckTimestamp();
|
||||
CheckInt16(1); // replica
|
||||
CheckInt16(1); // quorum
|
||||
CheckInt16(10); // days
|
||||
CheckBinary("3650,3650,3650", 24); // days
|
||||
CheckInt32(16); // cache
|
||||
CheckInt32(10); // blocks
|
||||
CheckInt32(100); // minrows
|
||||
CheckInt32(4096); // maxrows
|
||||
CheckInt8(1); // wallevel
|
||||
CheckInt32(3000); // fsync
|
||||
CheckInt8(2); // comp
|
||||
CheckInt8(0); // cachelast
|
||||
CheckBinary("ms", 3); // precision
|
||||
CheckInt8(0); // update
|
||||
}
|
||||
|
||||
TEST_F(DndTestDb, 03_AlterDb) {
|
||||
{
|
||||
SAlterDbMsg* pReq = (SAlterDbMsg*)rpcMallocCont(sizeof(SAlterDbMsg));
|
||||
strcpy(pReq->db, "1.d1");
|
||||
pReq->totalBlocks = htonl(12);
|
||||
pReq->daysToKeep0 = htonl(300);
|
||||
pReq->daysToKeep1 = htonl(400);
|
||||
pReq->daysToKeep2 = htonl(500);
|
||||
pReq->fsyncPeriod = htonl(4000);
|
||||
pReq->walLevel = 2;
|
||||
pReq->quorum = 2;
|
||||
pReq->cacheLastRow = 1;
|
||||
|
||||
SRpcMsg rpcMsg = {0};
|
||||
rpcMsg.pCont = pReq;
|
||||
rpcMsg.contLen = sizeof(SAlterDbMsg);
|
||||
rpcMsg.msgType = TSDB_MSG_TYPE_ALTER_DB;
|
||||
|
||||
sendMsg(pClient, &rpcMsg);
|
||||
SRpcMsg* pMsg = pClient->pRsp;
|
||||
ASSERT_NE(pMsg, nullptr);
|
||||
ASSERT_EQ(pMsg->code, 0);
|
||||
}
|
||||
|
||||
SendTheCheckShowMetaMsg(TSDB_MGMT_TABLE_DB, "show databases", 16);
|
||||
SendThenCheckShowRetrieveMsg(1);
|
||||
CheckBinary("d1", TSDB_DB_NAME_LEN - 1);
|
||||
CheckTimestamp();
|
||||
CheckInt16(1); // replica
|
||||
CheckInt16(2); // quorum
|
||||
CheckInt16(10); // days
|
||||
CheckBinary("300,400,500", 24); // days
|
||||
CheckInt32(16); // cache
|
||||
CheckInt32(12); // blocks
|
||||
CheckInt32(100); // minrows
|
||||
CheckInt32(4096); // maxrows
|
||||
CheckInt8(2); // wallevel
|
||||
CheckInt32(4000); // fsync
|
||||
CheckInt8(2); // comp
|
||||
CheckInt8(1); // cachelast
|
||||
CheckBinary("ms", 3); // precision
|
||||
CheckInt8(0); // update
|
||||
}
|
||||
|
||||
TEST_F(DndTestDb, 04_RestartDnode) {
|
||||
stopServer(pServer);
|
||||
pServer = NULL;
|
||||
|
||||
uInfo("start all server");
|
||||
|
||||
const char* fqdn = "localhost";
|
||||
const char* firstEp = "localhost:9040";
|
||||
pServer = startServer("/tmp/dnode_test_db", fqdn, 9040, firstEp);
|
||||
|
||||
uInfo("all server is running");
|
||||
|
||||
SendTheCheckShowMetaMsg(TSDB_MGMT_TABLE_DB, "show databases", 16);
|
||||
SendThenCheckShowRetrieveMsg(1);
|
||||
CheckBinary("d1", TSDB_DB_NAME_LEN - 1);
|
||||
CheckTimestamp();
|
||||
CheckInt16(1); // replica
|
||||
CheckInt16(2); // quorum
|
||||
CheckInt16(10); // days
|
||||
CheckBinary("300,400,500", 24); // days
|
||||
CheckInt32(16); // cache
|
||||
CheckInt32(12); // blocks
|
||||
CheckInt32(100); // minrows
|
||||
CheckInt32(4096); // maxrows
|
||||
CheckInt8(2); // wallevel
|
||||
CheckInt32(4000); // fsync
|
||||
CheckInt8(2); // comp
|
||||
CheckInt8(1); // cachelast
|
||||
CheckBinary("ms", 3); // precision
|
||||
CheckInt8(0); // update
|
||||
}
|
||||
|
||||
TEST_F(DndTestDb, 05_DropDb) {
|
||||
{
|
||||
SDropDbMsg* pReq = (SDropDbMsg*)rpcMallocCont(sizeof(SAlterDbMsg));
|
||||
strcpy(pReq->db, "1.d1");
|
||||
|
||||
SRpcMsg rpcMsg = {0};
|
||||
rpcMsg.pCont = pReq;
|
||||
rpcMsg.contLen = sizeof(SDropDbMsg);
|
||||
rpcMsg.msgType = TSDB_MSG_TYPE_DROP_DB;
|
||||
|
||||
sendMsg(pClient, &rpcMsg);
|
||||
SRpcMsg* pMsg = pClient->pRsp;
|
||||
ASSERT_NE(pMsg, nullptr);
|
||||
ASSERT_EQ(pMsg->code, 0);
|
||||
}
|
||||
|
||||
SendTheCheckShowMetaMsg(TSDB_MGMT_TABLE_DB, "show databases", 16);
|
||||
SendThenCheckShowRetrieveMsg(0);
|
||||
}
|
|
@ -1,20 +1,20 @@
|
|||
add_executable(dndTestDnode "")
|
||||
add_executable(dnode_test_dnode "")
|
||||
|
||||
target_sources(dndTestDnode
|
||||
target_sources(dnode_test_dnode
|
||||
PRIVATE
|
||||
"dnode.cpp"
|
||||
"../sut/deploy.cpp"
|
||||
)
|
||||
|
||||
target_link_libraries(
|
||||
dndTestDnode
|
||||
dnode_test_dnode
|
||||
PUBLIC dnode
|
||||
PUBLIC util
|
||||
PUBLIC os
|
||||
PUBLIC gtest_main
|
||||
)
|
||||
|
||||
target_include_directories(dndTestDnode
|
||||
target_include_directories(dnode_test_dnode
|
||||
PUBLIC
|
||||
"${CMAKE_SOURCE_DIR}/include/server/dnode/mgmt"
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/../../inc"
|
||||
|
@ -24,6 +24,6 @@ target_include_directories(dndTestDnode
|
|||
enable_testing()
|
||||
|
||||
add_test(
|
||||
NAME dndTestDnode
|
||||
COMMAND dndTestDnode
|
||||
NAME dnode_test_dnode
|
||||
COMMAND dnode_test_dnode
|
||||
)
|
||||
|
|
|
@ -24,16 +24,16 @@ class DndTestDnode : public ::testing::Test {
|
|||
}
|
||||
|
||||
static void SetUpTestSuite() {
|
||||
initLog("/tmp/dndTestDnode");
|
||||
initLog("/tmp/tdlog");
|
||||
|
||||
const char* fqdn = "localhost";
|
||||
const char* firstEp = "localhost:9521";
|
||||
pServer1 = CreateServer("/tmp/dndTestDnode1", fqdn, 9521, firstEp);
|
||||
pServer2 = CreateServer("/tmp/dndTestDnode2", fqdn, 9522, firstEp);
|
||||
pServer3 = CreateServer("/tmp/dndTestDnode3", fqdn, 9523, firstEp);
|
||||
pServer4 = CreateServer("/tmp/dndTestDnode4", fqdn, 9524, firstEp);
|
||||
pServer5 = CreateServer("/tmp/dndTestDnode5", fqdn, 9525, firstEp);
|
||||
pClient = createClient("root", "taosdata", fqdn, 9521);
|
||||
const char* firstEp = "localhost:9041";
|
||||
pServer1 = CreateServer("/tmp/dnode_test_dnode1", fqdn, 9041, firstEp);
|
||||
pServer2 = CreateServer("/tmp/dnode_test_dnode2", fqdn, 9042, firstEp);
|
||||
pServer3 = CreateServer("/tmp/dnode_test_dnode3", fqdn, 9043, firstEp);
|
||||
pServer4 = CreateServer("/tmp/dnode_test_dnode4", fqdn, 9044, firstEp);
|
||||
pServer5 = CreateServer("/tmp/dnode_test_dnode5", fqdn, 9045, firstEp);
|
||||
pClient = createClient("root", "taosdata", fqdn, 9041);
|
||||
taosMsleep(300);
|
||||
}
|
||||
|
||||
|
@ -188,7 +188,7 @@ SServer* DndTestDnode::pServer4;
|
|||
SServer* DndTestDnode::pServer5;
|
||||
SClient* DndTestDnode::pClient;
|
||||
|
||||
TEST_F(DndTestDnode, ShowDnode) {
|
||||
TEST_F(DndTestDnode, 01_ShowDnode) {
|
||||
SendTheCheckShowMetaMsg(TSDB_MGMT_TABLE_DNODE, "show dnodes", 7);
|
||||
CheckSchema(0, TSDB_DATA_TYPE_SMALLINT, 2, "id");
|
||||
CheckSchema(1, TSDB_DATA_TYPE_BINARY, TSDB_EP_LEN + VARSTR_HEADER_SIZE, "end point");
|
||||
|
@ -200,7 +200,7 @@ TEST_F(DndTestDnode, ShowDnode) {
|
|||
|
||||
SendThenCheckShowRetrieveMsg(1);
|
||||
CheckInt16(1);
|
||||
CheckBinary("localhost:9521", TSDB_EP_LEN);
|
||||
CheckBinary("localhost:9041", TSDB_EP_LEN);
|
||||
CheckInt16(0);
|
||||
CheckInt16(1);
|
||||
CheckBinary("ready", 10);
|
||||
|
@ -208,7 +208,7 @@ TEST_F(DndTestDnode, ShowDnode) {
|
|||
CheckBinary("", 24);
|
||||
}
|
||||
|
||||
TEST_F(DndTestDnode, ConfigDnode_01) {
|
||||
TEST_F(DndTestDnode, 02_ConfigDnode) {
|
||||
SCfgDnodeMsg* pReq = (SCfgDnodeMsg*)rpcMallocCont(sizeof(SCfgDnodeMsg));
|
||||
pReq->dnodeId = htonl(1);
|
||||
strcpy(pReq->config, "ddebugflag 131");
|
||||
|
@ -224,9 +224,9 @@ TEST_F(DndTestDnode, ConfigDnode_01) {
|
|||
ASSERT_EQ(pMsg->code, 0);
|
||||
}
|
||||
|
||||
TEST_F(DndTestDnode, CreateDnode_01) {
|
||||
TEST_F(DndTestDnode, 03_CreateDnode) {
|
||||
SCreateDnodeMsg* pReq = (SCreateDnodeMsg*)rpcMallocCont(sizeof(SCreateDnodeMsg));
|
||||
strcpy(pReq->ep, "localhost:9522");
|
||||
strcpy(pReq->ep, "localhost:9042");
|
||||
|
||||
SRpcMsg rpcMsg = {0};
|
||||
rpcMsg.pCont = pReq;
|
||||
|
@ -243,8 +243,8 @@ TEST_F(DndTestDnode, CreateDnode_01) {
|
|||
SendThenCheckShowRetrieveMsg(2);
|
||||
CheckInt16(1);
|
||||
CheckInt16(2);
|
||||
CheckBinary("localhost:9521", TSDB_EP_LEN);
|
||||
CheckBinary("localhost:9522", TSDB_EP_LEN);
|
||||
CheckBinary("localhost:9041", TSDB_EP_LEN);
|
||||
CheckBinary("localhost:9042", TSDB_EP_LEN);
|
||||
CheckInt16(0);
|
||||
CheckInt16(0);
|
||||
CheckInt16(1);
|
||||
|
@ -257,7 +257,7 @@ TEST_F(DndTestDnode, CreateDnode_01) {
|
|||
CheckBinary("", 24);
|
||||
}
|
||||
|
||||
TEST_F(DndTestDnode, DropDnode_01) {
|
||||
TEST_F(DndTestDnode, 04_DropDnode) {
|
||||
SDropDnodeMsg* pReq = (SDropDnodeMsg*)rpcMallocCont(sizeof(SDropDnodeMsg));
|
||||
pReq->dnodeId = htonl(2);
|
||||
|
||||
|
@ -274,7 +274,7 @@ TEST_F(DndTestDnode, DropDnode_01) {
|
|||
SendTheCheckShowMetaMsg(TSDB_MGMT_TABLE_DNODE, "show dnodes", 7);
|
||||
SendThenCheckShowRetrieveMsg(1);
|
||||
CheckInt16(1);
|
||||
CheckBinary("localhost:9521", TSDB_EP_LEN);
|
||||
CheckBinary("localhost:9041", TSDB_EP_LEN);
|
||||
CheckInt16(0);
|
||||
CheckInt16(1);
|
||||
CheckBinary("ready", 10);
|
||||
|
@ -282,10 +282,10 @@ TEST_F(DndTestDnode, DropDnode_01) {
|
|||
CheckBinary("", 24);
|
||||
}
|
||||
|
||||
TEST_F(DndTestDnode, CreateDnode_02) {
|
||||
TEST_F(DndTestDnode, 05_CreateDnode) {
|
||||
{
|
||||
SCreateDnodeMsg* pReq = (SCreateDnodeMsg*)rpcMallocCont(sizeof(SCreateDnodeMsg));
|
||||
strcpy(pReq->ep, "localhost:9523");
|
||||
strcpy(pReq->ep, "localhost:9043");
|
||||
|
||||
SRpcMsg rpcMsg = {0};
|
||||
rpcMsg.pCont = pReq;
|
||||
|
@ -300,7 +300,7 @@ TEST_F(DndTestDnode, CreateDnode_02) {
|
|||
|
||||
{
|
||||
SCreateDnodeMsg* pReq = (SCreateDnodeMsg*)rpcMallocCont(sizeof(SCreateDnodeMsg));
|
||||
strcpy(pReq->ep, "localhost:9524");
|
||||
strcpy(pReq->ep, "localhost:9044");
|
||||
|
||||
SRpcMsg rpcMsg = {0};
|
||||
rpcMsg.pCont = pReq;
|
||||
|
@ -315,7 +315,7 @@ TEST_F(DndTestDnode, CreateDnode_02) {
|
|||
|
||||
{
|
||||
SCreateDnodeMsg* pReq = (SCreateDnodeMsg*)rpcMallocCont(sizeof(SCreateDnodeMsg));
|
||||
strcpy(pReq->ep, "localhost:9525");
|
||||
strcpy(pReq->ep, "localhost:9045");
|
||||
|
||||
SRpcMsg rpcMsg = {0};
|
||||
rpcMsg.pCont = pReq;
|
||||
|
@ -335,10 +335,10 @@ TEST_F(DndTestDnode, CreateDnode_02) {
|
|||
CheckInt16(3);
|
||||
CheckInt16(4);
|
||||
CheckInt16(5);
|
||||
CheckBinary("localhost:9521", TSDB_EP_LEN);
|
||||
CheckBinary("localhost:9523", TSDB_EP_LEN);
|
||||
CheckBinary("localhost:9524", TSDB_EP_LEN);
|
||||
CheckBinary("localhost:9525", TSDB_EP_LEN);
|
||||
CheckBinary("localhost:9041", TSDB_EP_LEN);
|
||||
CheckBinary("localhost:9043", TSDB_EP_LEN);
|
||||
CheckBinary("localhost:9044", TSDB_EP_LEN);
|
||||
CheckBinary("localhost:9045", TSDB_EP_LEN);
|
||||
CheckInt16(0);
|
||||
CheckInt16(0);
|
||||
CheckInt16(0);
|
||||
|
@ -361,7 +361,7 @@ TEST_F(DndTestDnode, CreateDnode_02) {
|
|||
CheckBinary("", 24);
|
||||
}
|
||||
|
||||
TEST_F(DndTestDnode, RestartDnode_01) {
|
||||
TEST_F(DndTestDnode, 06_RestartDnode) {
|
||||
uInfo("stop all server");
|
||||
stopServer(pServer1);
|
||||
stopServer(pServer2);
|
||||
|
@ -377,43 +377,43 @@ TEST_F(DndTestDnode, RestartDnode_01) {
|
|||
uInfo("start all server");
|
||||
|
||||
const char* fqdn = "localhost";
|
||||
const char* firstEp = "localhost:9521";
|
||||
pServer1 = startServer("/tmp/dndTestDnode1", fqdn, 9521, firstEp);
|
||||
// pServer1 = startServer("/tmp/dndTestDnode3", fqdn, 9523, firstEp);
|
||||
// pServer1 = startServer("/tmp/dndTestDnode4", fqdn, 9524, firstEp);
|
||||
// pServer1 = startServer("/tmp/dndTestDnode5", fqdn, 9525, firstEp);
|
||||
const char* firstEp = "localhost:9041";
|
||||
pServer1 = startServer("/tmp/dnode_test_dnode1", fqdn, 9041, firstEp);
|
||||
pServer3 = startServer("/tmp/dnode_test_dnode3", fqdn, 9043, firstEp);
|
||||
pServer4 = startServer("/tmp/dnode_test_dnode4", fqdn, 9044, firstEp);
|
||||
pServer5 = startServer("/tmp/dnode_test_dnode5", fqdn, 9045, firstEp);
|
||||
|
||||
uInfo("all server is running");
|
||||
|
||||
// taosMsleep(1300);
|
||||
// SendTheCheckShowMetaMsg(TSDB_MGMT_TABLE_DNODE, "show dnodes", 7);
|
||||
// SendThenCheckShowRetrieveMsg(4);
|
||||
// CheckInt16(1);
|
||||
// CheckInt16(3);
|
||||
// CheckInt16(4);
|
||||
// CheckInt16(5);
|
||||
// CheckBinary("localhost:9521", TSDB_EP_LEN);
|
||||
// CheckBinary("localhost:9523", TSDB_EP_LEN);
|
||||
// CheckBinary("localhost:9524", TSDB_EP_LEN);
|
||||
// CheckBinary("localhost:9525", TSDB_EP_LEN);
|
||||
// CheckInt16(0);
|
||||
// CheckInt16(0);
|
||||
// CheckInt16(0);
|
||||
// CheckInt16(0);
|
||||
// CheckInt16(1);
|
||||
// CheckInt16(1);
|
||||
// CheckInt16(1);
|
||||
// CheckInt16(1);
|
||||
// CheckBinary("ready", 10);
|
||||
// CheckBinary("ready", 10);
|
||||
// CheckBinary("ready", 10);
|
||||
// CheckBinary("ready", 10);
|
||||
// CheckTimestamp();
|
||||
// CheckTimestamp();
|
||||
// CheckTimestamp();
|
||||
// CheckTimestamp();
|
||||
// CheckBinary("", 24);
|
||||
// CheckBinary("", 24);
|
||||
// CheckBinary("", 24);
|
||||
// CheckBinary("", 24);
|
||||
taosMsleep(1300);
|
||||
SendTheCheckShowMetaMsg(TSDB_MGMT_TABLE_DNODE, "show dnodes", 7);
|
||||
SendThenCheckShowRetrieveMsg(4);
|
||||
CheckInt16(1);
|
||||
CheckInt16(3);
|
||||
CheckInt16(4);
|
||||
CheckInt16(5);
|
||||
CheckBinary("localhost:9041", TSDB_EP_LEN);
|
||||
CheckBinary("localhost:9043", TSDB_EP_LEN);
|
||||
CheckBinary("localhost:9044", TSDB_EP_LEN);
|
||||
CheckBinary("localhost:9045", TSDB_EP_LEN);
|
||||
CheckInt16(0);
|
||||
CheckInt16(0);
|
||||
CheckInt16(0);
|
||||
CheckInt16(0);
|
||||
CheckInt16(1);
|
||||
CheckInt16(1);
|
||||
CheckInt16(1);
|
||||
CheckInt16(1);
|
||||
CheckBinary("ready", 10);
|
||||
CheckBinary("ready", 10);
|
||||
CheckBinary("ready", 10);
|
||||
CheckBinary("ready", 10);
|
||||
CheckTimestamp();
|
||||
CheckTimestamp();
|
||||
CheckTimestamp();
|
||||
CheckTimestamp();
|
||||
CheckBinary("", 24);
|
||||
CheckBinary("", 24);
|
||||
CheckBinary("", 24);
|
||||
CheckBinary("", 24);
|
||||
}
|
||||
|
|
|
@ -18,7 +18,7 @@
|
|||
void initLog(const char* path) {
|
||||
dDebugFlag = 143;
|
||||
vDebugFlag = 0;
|
||||
mDebugFlag = 143;
|
||||
mDebugFlag = 207;
|
||||
cDebugFlag = 0;
|
||||
jniDebugFlag = 0;
|
||||
tmrDebugFlag = 0;
|
||||
|
@ -120,7 +120,7 @@ SClient* createClient(const char* user, const char* pass, const char* fqdn, uint
|
|||
SClient* pClient = (SClient*)calloc(1, sizeof(SClient));
|
||||
ASSERT(pClient);
|
||||
|
||||
char secretEncrypt[32] = {0};
|
||||
char secretEncrypt[TSDB_PASSWORD_LEN] = {0};
|
||||
taosEncryptPass((uint8_t*)pass, strlen(pass), secretEncrypt);
|
||||
|
||||
SRpcInit rpcInit;
|
||||
|
|
|
@ -1,20 +1,20 @@
|
|||
add_executable(dndTestUser "")
|
||||
add_executable(dnode_test_user "")
|
||||
|
||||
target_sources(dndTestUser
|
||||
target_sources(dnode_test_user
|
||||
PRIVATE
|
||||
"user.cpp"
|
||||
"../sut/deploy.cpp"
|
||||
)
|
||||
|
||||
target_link_libraries(
|
||||
dndTestUser
|
||||
dnode_test_user
|
||||
PUBLIC dnode
|
||||
PUBLIC util
|
||||
PUBLIC os
|
||||
PUBLIC gtest_main
|
||||
)
|
||||
|
||||
target_include_directories(dndTestUser
|
||||
target_include_directories(dnode_test_user
|
||||
PUBLIC
|
||||
"${CMAKE_SOURCE_DIR}/include/server/dnode/mgmt"
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/../../inc"
|
||||
|
@ -24,6 +24,6 @@ target_include_directories(dndTestUser
|
|||
enable_testing()
|
||||
|
||||
add_test(
|
||||
NAME dndTestUser
|
||||
COMMAND dndTestUser
|
||||
NAME dnode_test_user
|
||||
COMMAND dnode_test_user
|
||||
)
|
||||
|
|
|
@ -24,12 +24,12 @@ class DndTestUser : public ::testing::Test {
|
|||
}
|
||||
|
||||
static void SetUpTestSuite() {
|
||||
initLog("/tmp/dndTestUser");
|
||||
initLog("/tmp/tdlog");
|
||||
|
||||
const char* fqdn = "localhost";
|
||||
const char* firstEp = "localhost:9530";
|
||||
pServer = CreateServer("/tmp/dndTestUser", fqdn, 9530, firstEp);
|
||||
pClient = createClient("root", "taosdata", fqdn, 9530);
|
||||
const char* firstEp = "localhost:9140";
|
||||
pServer = CreateServer("/tmp/dnode_test_user", fqdn, 9140, firstEp);
|
||||
pClient = createClient("root", "taosdata", fqdn, 9140);
|
||||
taosMsleep(300);
|
||||
}
|
||||
|
||||
|
@ -170,7 +170,7 @@ SServer* DndTestUser::pServer;
|
|||
SClient* DndTestUser::pClient;
|
||||
int32_t DndTestUser::connId;
|
||||
|
||||
TEST_F(DndTestUser, ShowUser) {
|
||||
TEST_F(DndTestUser, 01_ShowUser) {
|
||||
SendTheCheckShowMetaMsg(TSDB_MGMT_TABLE_USER, "show users", 4);
|
||||
CheckSchema(0, TSDB_DATA_TYPE_BINARY, TSDB_USER_LEN + VARSTR_HEADER_SIZE, "name");
|
||||
CheckSchema(1, TSDB_DATA_TYPE_BINARY, 10 + VARSTR_HEADER_SIZE, "privilege");
|
||||
|
@ -184,7 +184,7 @@ TEST_F(DndTestUser, ShowUser) {
|
|||
CheckBinary("root", TSDB_USER_LEN);
|
||||
}
|
||||
|
||||
TEST_F(DndTestUser, CreateUser_01) {
|
||||
TEST_F(DndTestUser, 02_CreateUser) {
|
||||
{
|
||||
SCreateUserMsg* pReq = (SCreateUserMsg*)rpcMallocCont(sizeof(SCreateUserMsg));
|
||||
strcpy(pReq->user, "u1");
|
||||
|
@ -233,7 +233,7 @@ TEST_F(DndTestUser, CreateUser_01) {
|
|||
CheckBinary("root", TSDB_USER_LEN);
|
||||
}
|
||||
|
||||
TEST_F(DndTestUser, AlterUser_01) {
|
||||
TEST_F(DndTestUser, 03_AlterUser) {
|
||||
SAlterUserMsg* pReq = (SAlterUserMsg*)rpcMallocCont(sizeof(SAlterUserMsg));
|
||||
strcpy(pReq->user, "u1");
|
||||
strcpy(pReq->pass, "p2");
|
||||
|
@ -264,7 +264,7 @@ TEST_F(DndTestUser, AlterUser_01) {
|
|||
CheckBinary("root", TSDB_USER_LEN);
|
||||
}
|
||||
|
||||
TEST_F(DndTestUser, DropUser_01) {
|
||||
TEST_F(DndTestUser, 04_DropUser) {
|
||||
SDropUserMsg* pReq = (SDropUserMsg*)rpcMallocCont(sizeof(SDropUserMsg));
|
||||
strcpy(pReq->user, "u1");
|
||||
|
||||
|
@ -290,15 +290,15 @@ TEST_F(DndTestUser, DropUser_01) {
|
|||
CheckBinary("root", TSDB_USER_LEN);
|
||||
}
|
||||
|
||||
TEST_F(DndTestUser, RestartDnode) {
|
||||
TEST_F(DndTestUser, 05_RestartDnode) {
|
||||
stopServer(pServer);
|
||||
pServer = NULL;
|
||||
|
||||
uInfo("start all server");
|
||||
|
||||
const char* fqdn = "localhost";
|
||||
const char* firstEp = "localhost:9530";
|
||||
pServer = startServer("/tmp/dndTestUser", fqdn, 9530, firstEp);
|
||||
const char* firstEp = "localhost:9140";
|
||||
pServer = startServer("/tmp/dnode_test_user", fqdn, 9140, firstEp);
|
||||
|
||||
uInfo("all server is running");
|
||||
|
||||
|
|
|
@ -17,14 +17,16 @@
|
|||
#define _TD_MND_DEF_H_
|
||||
|
||||
#include "os.h"
|
||||
|
||||
#include "cJSON.h"
|
||||
#include "sync.h"
|
||||
#include "taosmsg.h"
|
||||
#include "thash.h"
|
||||
#include "tlog.h"
|
||||
#include "trpc.h"
|
||||
#include "ttimer.h"
|
||||
#include "thash.h"
|
||||
#include "cJSON.h"
|
||||
|
||||
#include "mnode.h"
|
||||
#include "sync.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
|
@ -41,11 +43,8 @@ extern int32_t mDebugFlag;
|
|||
#define mTrace(...) { if (mDebugFlag & DEBUG_TRACE) { taosPrintLog("MND ", mDebugFlag, __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 SFuncObj SFuncObj;
|
||||
typedef struct SOperObj SOperObj;
|
||||
|
@ -73,7 +72,8 @@ typedef enum {
|
|||
TRN_STAGE_EXECUTE = 2,
|
||||
TRN_STAGE_COMMIT = 3,
|
||||
TRN_STAGE_ROLLBACK = 4,
|
||||
TRN_STAGE_RETRY = 5
|
||||
TRN_STAGE_RETRY = 5,
|
||||
TRN_STAGE_OVER = 6,
|
||||
} ETrnStage;
|
||||
|
||||
typedef enum { TRN_POLICY_ROLLBACK = 1, TRN_POLICY_RETRY = 2 } ETrnPolicy;
|
||||
|
@ -103,7 +103,6 @@ typedef struct STrans {
|
|||
int32_t id;
|
||||
ETrnStage stage;
|
||||
ETrnPolicy policy;
|
||||
SMnode *pMnode;
|
||||
void *rpcHandle;
|
||||
SArray *redoLogs;
|
||||
SArray *undoLogs;
|
||||
|
@ -119,7 +118,7 @@ typedef struct SClusterObj {
|
|||
int64_t updateTime;
|
||||
} SClusterObj;
|
||||
|
||||
typedef struct SDnodeObj {
|
||||
typedef struct {
|
||||
int32_t id;
|
||||
int64_t createdTime;
|
||||
int64_t updateTime;
|
||||
|
@ -178,15 +177,13 @@ typedef struct SAcctObj {
|
|||
SAcctInfo info;
|
||||
} SAcctObj;
|
||||
|
||||
typedef struct SUserObj {
|
||||
typedef struct {
|
||||
char user[TSDB_USER_LEN];
|
||||
char pass[TSDB_KEY_LEN];
|
||||
char pass[TSDB_PASSWORD_LEN];
|
||||
char acct[TSDB_USER_LEN];
|
||||
int64_t createdTime;
|
||||
int64_t updateTime;
|
||||
int8_t superAuth;
|
||||
int8_t readAuth;
|
||||
int8_t writeAuth;
|
||||
int8_t superUser;
|
||||
int32_t acctId;
|
||||
SHashObj *prohibitDbHash;
|
||||
} SUserObj;
|
||||
|
@ -211,7 +208,7 @@ typedef struct {
|
|||
int8_t cacheLastRow;
|
||||
} SDbCfg;
|
||||
|
||||
typedef struct SDbObj {
|
||||
typedef struct {
|
||||
char name[TSDB_FULL_DB_NAME_LEN];
|
||||
char acct[TSDB_USER_LEN];
|
||||
int64_t createdTime;
|
||||
|
@ -306,6 +303,7 @@ typedef struct SMnodeMsg {
|
|||
|
||||
typedef struct {
|
||||
int32_t id;
|
||||
int32_t code;
|
||||
void *rpcHandle;
|
||||
} STransMsg;
|
||||
|
||||
|
|
|
@ -27,7 +27,7 @@ void mndCleanupShow(SMnode *pMnode);
|
|||
void mndAddShowMetaHandle(SMnode *pMnode, EShowType showType, ShowMetaFp fp);
|
||||
void mndAddShowRetrieveHandle(SMnode *pMnode, EShowType showType, ShowRetrieveFp fp);
|
||||
void mndAddShowFreeIterHandle(SMnode *pMnode, EShowType msgType, ShowFreeIterFp fp);
|
||||
void mnodeVacuumResult(char *data, int32_t numOfCols, int32_t rows, int32_t capacity, SShowObj *pShow);
|
||||
void mndVacuumResult(char *data, int32_t numOfCols, int32_t rows, int32_t capacity, SShowObj *pShow);
|
||||
char *mndShowStr(int32_t showType);
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
|
|
@ -25,7 +25,7 @@ extern "C" {
|
|||
int32_t mndInitSync(SMnode *pMnode);
|
||||
void mndCleanupSync(SMnode *pMnode);
|
||||
bool mndIsMaster(SMnode *pMnode);
|
||||
int32_t mndSyncPropose(SMnode *pMnode, SSdbRaw *pRaw, STransMsg *pMsg);
|
||||
int32_t mndSyncPropose(SMnode *pMnode, SSdbRaw *pRaw);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
|
|
@ -32,10 +32,10 @@ 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 mndTransPrepare(SMnode *pMnode, STrans *pTrans);
|
||||
void mndTransApply(SMnode *pMnode, SSdbRaw *pRaw, STransMsg *pMsg, int32_t code);
|
||||
int32_t mndTransExecute(SSdb *pSdb, int32_t tranId);
|
||||
char *mndTransStageStr(ETrnStage stage);
|
||||
char *mndTransPolicyStr(ETrnPolicy policy);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
|
|
@ -19,12 +19,12 @@
|
|||
|
||||
#define SDB_ACCT_VER 1
|
||||
|
||||
static int32_t mnodeCreateDefaultAcct(SMnode *pMnode);
|
||||
static SSdbRaw *mnodeAcctActionEncode(SAcctObj *pAcct);
|
||||
static SSdbRow *mnodeAcctActionDecode(SSdbRaw *pRaw);
|
||||
static int32_t mnodeAcctActionInsert(SSdb *pSdb, SAcctObj *pAcct);
|
||||
static int32_t mnodeAcctActionDelete(SSdb *pSdb, SAcctObj *pAcct);
|
||||
static int32_t mnodeAcctActionUpdate(SSdb *pSdb, SAcctObj *pOldAcct, SAcctObj *pNewAcct);
|
||||
static int32_t mndCreateDefaultAcct(SMnode *pMnode);
|
||||
static SSdbRaw *mndAcctActionEncode(SAcctObj *pAcct);
|
||||
static SSdbRow *mndAcctActionDecode(SSdbRaw *pRaw);
|
||||
static int32_t mndAcctActionInsert(SSdb *pSdb, SAcctObj *pAcct);
|
||||
static int32_t mndAcctActionDelete(SSdb *pSdb, SAcctObj *pAcct);
|
||||
static int32_t mndAcctActionUpdate(SSdb *pSdb, SAcctObj *pOldAcct, SAcctObj *pNewAcct);
|
||||
static int32_t mndProcessCreateAcctMsg(SMnodeMsg *pMnodeMsg);
|
||||
static int32_t mndProcessAlterAcctMsg(SMnodeMsg *pMnodeMsg);
|
||||
static int32_t mndProcessDropAcctMsg(SMnodeMsg *pMnodeMsg);
|
||||
|
@ -32,12 +32,12 @@ static int32_t mndProcessDropAcctMsg(SMnodeMsg *pMnodeMsg);
|
|||
int32_t mndInitAcct(SMnode *pMnode) {
|
||||
SSdbTable table = {.sdbType = SDB_ACCT,
|
||||
.keyType = SDB_KEY_BINARY,
|
||||
.deployFp = mnodeCreateDefaultAcct,
|
||||
.encodeFp = (SdbEncodeFp)mnodeAcctActionEncode,
|
||||
.decodeFp = (SdbDecodeFp)mnodeAcctActionDecode,
|
||||
.insertFp = (SdbInsertFp)mnodeAcctActionInsert,
|
||||
.updateFp = (SdbUpdateFp)mnodeAcctActionUpdate,
|
||||
.deleteFp = (SdbDeleteFp)mnodeAcctActionDelete};
|
||||
.deployFp = mndCreateDefaultAcct,
|
||||
.encodeFp = (SdbEncodeFp)mndAcctActionEncode,
|
||||
.decodeFp = (SdbDecodeFp)mndAcctActionDecode,
|
||||
.insertFp = (SdbInsertFp)mndAcctActionInsert,
|
||||
.updateFp = (SdbUpdateFp)mndAcctActionUpdate,
|
||||
.deleteFp = (SdbDeleteFp)mndAcctActionDelete};
|
||||
|
||||
mndSetMsgHandle(pMnode, TSDB_MSG_TYPE_CREATE_ACCT, mndProcessCreateAcctMsg);
|
||||
mndSetMsgHandle(pMnode, TSDB_MSG_TYPE_ALTER_ACCT, mndProcessAlterAcctMsg);
|
||||
|
@ -48,7 +48,7 @@ int32_t mndInitAcct(SMnode *pMnode) {
|
|||
|
||||
void mndCleanupAcct(SMnode *pMnode) {}
|
||||
|
||||
static int32_t mnodeCreateDefaultAcct(SMnode *pMnode) {
|
||||
static int32_t mndCreateDefaultAcct(SMnode *pMnode) {
|
||||
SAcctObj acctObj = {0};
|
||||
tstrncpy(acctObj.acct, TSDB_DEFAULT_USER, TSDB_USER_LEN);
|
||||
acctObj.createdTime = taosGetTimestampMs();
|
||||
|
@ -61,7 +61,7 @@ static int32_t mnodeCreateDefaultAcct(SMnode *pMnode) {
|
|||
.maxStorage = INT64_MAX,
|
||||
.accessState = TSDB_VN_ALL_ACCCESS};
|
||||
|
||||
SSdbRaw *pRaw = mnodeAcctActionEncode(&acctObj);
|
||||
SSdbRaw *pRaw = mndAcctActionEncode(&acctObj);
|
||||
if (pRaw == NULL) return -1;
|
||||
sdbSetRawStatus(pRaw, SDB_STATUS_READY);
|
||||
|
||||
|
@ -69,7 +69,7 @@ static int32_t mnodeCreateDefaultAcct(SMnode *pMnode) {
|
|||
return sdbWrite(pMnode->pSdb, pRaw);
|
||||
}
|
||||
|
||||
static SSdbRaw *mnodeAcctActionEncode(SAcctObj *pAcct) {
|
||||
static SSdbRaw *mndAcctActionEncode(SAcctObj *pAcct) {
|
||||
SSdbRaw *pRaw = sdbAllocRaw(SDB_ACCT, SDB_ACCT_VER, sizeof(SAcctObj));
|
||||
if (pRaw == NULL) return NULL;
|
||||
|
||||
|
@ -90,7 +90,7 @@ static SSdbRaw *mnodeAcctActionEncode(SAcctObj *pAcct) {
|
|||
return pRaw;
|
||||
}
|
||||
|
||||
static SSdbRow *mnodeAcctActionDecode(SSdbRaw *pRaw) {
|
||||
static SSdbRow *mndAcctActionDecode(SSdbRaw *pRaw) {
|
||||
int8_t sver = 0;
|
||||
if (sdbGetRawSoftVer(pRaw, &sver) != 0) return NULL;
|
||||
|
||||
|
@ -120,18 +120,18 @@ static SSdbRow *mnodeAcctActionDecode(SSdbRaw *pRaw) {
|
|||
return pRow;
|
||||
}
|
||||
|
||||
static int32_t mnodeAcctActionInsert(SSdb *pSdb, SAcctObj *pAcct) {
|
||||
static int32_t mndAcctActionInsert(SSdb *pSdb, SAcctObj *pAcct) {
|
||||
mTrace("acct:%s, perform insert action", pAcct->acct);
|
||||
memset(&pAcct->info, 0, sizeof(SAcctInfo));
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int32_t mnodeAcctActionDelete(SSdb *pSdb, SAcctObj *pAcct) {
|
||||
static int32_t mndAcctActionDelete(SSdb *pSdb, SAcctObj *pAcct) {
|
||||
mTrace("acct:%s, perform delete action", pAcct->acct);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int32_t mnodeAcctActionUpdate(SSdb *pSdb, SAcctObj *pOldAcct, SAcctObj *pNewAcct) {
|
||||
static int32_t mndAcctActionUpdate(SSdb *pSdb, SAcctObj *pOldAcct, SAcctObj *pNewAcct) {
|
||||
mTrace("acct:%s, perform update action", pOldAcct->acct);
|
||||
|
||||
memcpy(pOldAcct->acct, pNewAcct->acct, TSDB_USER_LEN);
|
||||
|
|
|
@ -203,7 +203,7 @@ static int32_t mndRetrieveClusters(SMnodeMsg *pMsg, SShowObj *pShow, char *data,
|
|||
numOfRows++;
|
||||
}
|
||||
|
||||
mnodeVacuumResult(data, pShow->numOfColumns, numOfRows, rows, pShow);
|
||||
mndVacuumResult(data, pShow->numOfColumns, numOfRows, rows, pShow);
|
||||
pShow->numOfReads += numOfRows;
|
||||
return numOfRows;
|
||||
}
|
||||
|
|
|
@ -65,7 +65,7 @@ int32_t mndInitDb(SMnode *pMnode) {
|
|||
void mndCleanupDb(SMnode *pMnode) {}
|
||||
|
||||
static SSdbRaw *mndDbActionEncode(SDbObj *pDb) {
|
||||
SSdbRaw *pRaw = sdbAllocRaw(SDB_DB, TSDB_DB_VER_NUM, sizeof(SDbObj));
|
||||
SSdbRaw *pRaw = sdbAllocRaw(SDB_DB, TSDB_DB_VER_NUM, sizeof(SDbObj) + TSDB_DB_RESERVE_SIZE);
|
||||
if (pRaw == NULL) return NULL;
|
||||
|
||||
int32_t dataPos = 0;
|
||||
|
@ -151,7 +151,8 @@ static int32_t mndDbActionDelete(SSdb *pSdb, SDbObj *pDb) {
|
|||
|
||||
static int32_t mndDbActionUpdate(SSdb *pSdb, SDbObj *pOldDb, SDbObj *pNewDb) {
|
||||
mTrace("db:%s, perform update action", pOldDb->name);
|
||||
memcpy(pOldDb, pNewDb, sizeof(SDbObj));
|
||||
pOldDb->updateTime = pNewDb->createdTime;
|
||||
memcpy(&pOldDb->cfg, &pNewDb->cfg, sizeof(SDbCfg));
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -165,109 +166,146 @@ void mndReleaseDb(SMnode *pMnode, SDbObj *pDb) {
|
|||
sdbRelease(pSdb, pDb);
|
||||
}
|
||||
|
||||
static int32_t mndCheckDbCfg(SMnode *pMnode, SDbCfg *pCfg) {
|
||||
static int32_t mndCheckDbName(char *dbName, SUserObj *pUser) {
|
||||
char *pos = strstr(dbName, TS_PATH_DELIMITER);
|
||||
if (pos == NULL) {
|
||||
terrno = TSDB_CODE_MND_INVALID_DB;
|
||||
return -1;
|
||||
}
|
||||
|
||||
int32_t acctId = atoi(dbName);
|
||||
if (acctId != pUser->acctId) {
|
||||
terrno = TSDB_CODE_MND_INVALID_DB_ACCT;
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int32_t mndCheckDbCfg(SMnode *pMnode, SDbCfg *pCfg, char *errMsg, int32_t len) {
|
||||
if (pCfg->cacheBlockSize < TSDB_MIN_CACHE_BLOCK_SIZE || pCfg->cacheBlockSize > TSDB_MAX_CACHE_BLOCK_SIZE) {
|
||||
terrno = TSDB_CODE_MND_INVALID_DB_CACHE_SIZE;
|
||||
terrno = TSDB_CODE_MND_INVALID_DB_OPTION;
|
||||
tstrncpy(errMsg, "Invalid database cache block size option", len);
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (pCfg->totalBlocks < TSDB_MIN_TOTAL_BLOCKS || pCfg->totalBlocks > TSDB_MAX_TOTAL_BLOCKS) {
|
||||
terrno = TSDB_CODE_MND_INVALID_DB_TOTAL_BLOCKS;
|
||||
terrno = TSDB_CODE_MND_INVALID_DB_OPTION;
|
||||
tstrncpy(errMsg, "Invalid database total blocks option", len);
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (pCfg->daysPerFile < TSDB_MIN_DAYS_PER_FILE || pCfg->daysPerFile > TSDB_MAX_DAYS_PER_FILE) {
|
||||
terrno = TSDB_CODE_MND_INVALID_DB_DAYS;
|
||||
terrno = TSDB_CODE_MND_INVALID_DB_OPTION;
|
||||
tstrncpy(errMsg, "Invalid database days option", len);
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (pCfg->daysToKeep0 < pCfg->daysPerFile) {
|
||||
terrno = TSDB_CODE_MND_INVALID_DB_KEEP0;
|
||||
terrno = TSDB_CODE_MND_INVALID_DB_OPTION;
|
||||
tstrncpy(errMsg, "Invalid database days option", len);
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (pCfg->daysToKeep0 < TSDB_MIN_KEEP || pCfg->daysToKeep0 > TSDB_MAX_KEEP || pCfg->daysToKeep0 > pCfg->daysToKeep1) {
|
||||
terrno = TSDB_CODE_MND_INVALID_DB_KEEP0;
|
||||
terrno = TSDB_CODE_MND_INVALID_DB_OPTION;
|
||||
tstrncpy(errMsg, "Invalid database keep0 option", len);
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (pCfg->daysToKeep1 < TSDB_MIN_KEEP || pCfg->daysToKeep1 > TSDB_MAX_KEEP || pCfg->daysToKeep1 > pCfg->daysToKeep2) {
|
||||
terrno = TSDB_CODE_MND_INVALID_DB_KEEP1;
|
||||
terrno = TSDB_CODE_MND_INVALID_DB_OPTION;
|
||||
tstrncpy(errMsg, "Invalid database keep1 option", len);
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (pCfg->daysToKeep2 < TSDB_MIN_KEEP || pCfg->daysToKeep2 > TSDB_MAX_KEEP) {
|
||||
terrno = TSDB_CODE_MND_INVALID_DB_KEEP1;
|
||||
terrno = TSDB_CODE_MND_INVALID_DB_OPTION;
|
||||
tstrncpy(errMsg, "Invalid database keep2 option", len);
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (pCfg->minRowsPerFileBlock < TSDB_MIN_MIN_ROW_FBLOCK || pCfg->minRowsPerFileBlock > TSDB_MAX_MIN_ROW_FBLOCK) {
|
||||
terrno = TSDB_CODE_MND_INVALID_DB_MIN_ROWS;
|
||||
terrno = TSDB_CODE_MND_INVALID_DB_OPTION;
|
||||
tstrncpy(errMsg, "Invalid database minrows option", len);
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (pCfg->maxRowsPerFileBlock < TSDB_MIN_MAX_ROW_FBLOCK || pCfg->maxRowsPerFileBlock > TSDB_MAX_MAX_ROW_FBLOCK) {
|
||||
terrno = TSDB_CODE_MND_INVALID_DB_MAX_ROWS;
|
||||
terrno = TSDB_CODE_MND_INVALID_DB_OPTION;
|
||||
tstrncpy(errMsg, "Invalid database maxrows option", len);
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (pCfg->minRowsPerFileBlock > pCfg->maxRowsPerFileBlock) {
|
||||
terrno = TSDB_CODE_MND_INVALID_DB_MIN_ROWS;
|
||||
terrno = TSDB_CODE_MND_INVALID_DB_OPTION;
|
||||
tstrncpy(errMsg, "Invalid database minrows option", len);
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (pCfg->commitTime < TSDB_MIN_COMMIT_TIME || pCfg->commitTime > TSDB_MAX_COMMIT_TIME) {
|
||||
terrno = TSDB_CODE_MND_INVALID_DB_COMMIT_TIME;
|
||||
terrno = TSDB_CODE_MND_INVALID_DB_OPTION;
|
||||
tstrncpy(errMsg, "Invalid database commit option", len);
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (pCfg->fsyncPeriod < TSDB_MIN_FSYNC_PERIOD || pCfg->fsyncPeriod > TSDB_MAX_FSYNC_PERIOD) {
|
||||
terrno = TSDB_CODE_MND_INVALID_DB_FSYNC_PERIOD;
|
||||
terrno = TSDB_CODE_MND_INVALID_DB_OPTION;
|
||||
tstrncpy(errMsg, "Invalid database fsync option", len);
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (pCfg->walLevel < TSDB_MIN_WAL_LEVEL || pCfg->walLevel > TSDB_MAX_WAL_LEVEL) {
|
||||
terrno = TSDB_CODE_MND_INVALID_DB_WAL_LEVEL;
|
||||
terrno = TSDB_CODE_MND_INVALID_DB_OPTION;
|
||||
tstrncpy(errMsg, "Invalid database wal level option", len);
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (pCfg->precision < TSDB_MIN_PRECISION && pCfg->precision > TSDB_MAX_PRECISION) {
|
||||
terrno = TSDB_CODE_MND_INVALID_DB_PRECISION;
|
||||
terrno = TSDB_CODE_MND_INVALID_DB_OPTION;
|
||||
tstrncpy(errMsg, "Invalid precision option", len);
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (pCfg->compression < TSDB_MIN_COMP_LEVEL || pCfg->compression > TSDB_MAX_COMP_LEVEL) {
|
||||
terrno = TSDB_CODE_MND_INVALID_DB_COMP;
|
||||
terrno = TSDB_CODE_MND_INVALID_DB_OPTION;
|
||||
tstrncpy(errMsg, "Invalid database compression option", len);
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (pCfg->replications < TSDB_MIN_DB_REPLICA_OPTION || pCfg->replications > TSDB_MAX_DB_REPLICA_OPTION) {
|
||||
terrno = TSDB_CODE_MND_INVALID_DB_REPLICA;
|
||||
terrno = TSDB_CODE_MND_INVALID_DB_OPTION;
|
||||
tstrncpy(errMsg, "Invalid database replication option", len);
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (pCfg->replications > mndGetDnodeSize(pMnode)) {
|
||||
terrno = TSDB_CODE_MND_INVALID_DB_REPLICA;
|
||||
terrno = TSDB_CODE_MND_INVALID_DB_OPTION;
|
||||
tstrncpy(errMsg, "Invalid database replication option", len);
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (pCfg->quorum < TSDB_MIN_DB_QUORUM_OPTION || pCfg->quorum > TSDB_MAX_DB_QUORUM_OPTION) {
|
||||
terrno = TSDB_CODE_MND_INVALID_DB_QUORUM;
|
||||
terrno = TSDB_CODE_MND_INVALID_DB_OPTION;
|
||||
tstrncpy(errMsg, "Invalid database quorum option", len);
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (pCfg->quorum > pCfg->replications) {
|
||||
terrno = TSDB_CODE_MND_INVALID_DB_QUORUM;
|
||||
terrno = TSDB_CODE_MND_INVALID_DB_OPTION;
|
||||
tstrncpy(errMsg, "Invalid database quorum option", len);
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (pCfg->update < TSDB_MIN_DB_UPDATE || pCfg->update > TSDB_MAX_DB_UPDATE) {
|
||||
terrno = TSDB_CODE_MND_INVALID_DB_UPDATE;
|
||||
terrno = TSDB_CODE_MND_INVALID_DB_OPTION;
|
||||
tstrncpy(errMsg, "Invalid database update option", len);
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (pCfg->cacheLastRow < TSDB_MIN_DB_CACHE_LAST_ROW || pCfg->cacheLastRow > TSDB_MAX_DB_CACHE_LAST_ROW) {
|
||||
terrno = TSDB_CODE_MND_INVALID_DB_CACHE_LAST;
|
||||
terrno = TSDB_CODE_MND_INVALID_DB_OPTION;
|
||||
tstrncpy(errMsg, "Invalid database cachelast option", len);
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
@ -294,13 +332,13 @@ static void mndSetDefaultDbCfg(SDbCfg *pCfg) {
|
|||
if (pCfg->cacheLastRow < 0) pCfg->cacheLastRow = TSDB_DEFAULT_CACHE_LAST_ROW;
|
||||
}
|
||||
|
||||
static int32_t mndCreateDb(SMnode *pMnode, SMnodeMsg *pMsg, SCreateDbMsg *pCreate, char *acct) {
|
||||
static int32_t mndCreateDb(SMnode *pMnode, SMnodeMsg *pMsg, SCreateDbMsg *pCreate, SUserObj *pUser) {
|
||||
SDbObj dbObj = {0};
|
||||
tstrncpy(dbObj.name, pCreate->db, TSDB_FULL_DB_NAME_LEN);
|
||||
tstrncpy(dbObj.acct, acct, TSDB_USER_LEN);
|
||||
tstrncpy(dbObj.acct, pUser->acct, TSDB_USER_LEN);
|
||||
dbObj.createdTime = taosGetTimestampMs();
|
||||
dbObj.updateTime = dbObj.createdTime;
|
||||
dbObj.uid = 1234;
|
||||
dbObj.uid = mndGenerateUid(dbObj.name, TSDB_FULL_DB_NAME_LEN);
|
||||
dbObj.cfg = (SDbCfg){.cacheBlockSize = pCreate->cacheBlockSize,
|
||||
.totalBlocks = pCreate->totalBlocks,
|
||||
.daysPerFile = pCreate->daysPerFile,
|
||||
|
@ -321,7 +359,13 @@ static int32_t mndCreateDb(SMnode *pMnode, SMnodeMsg *pMsg, SCreateDbMsg *pCreat
|
|||
|
||||
mndSetDefaultDbCfg(&dbObj.cfg);
|
||||
|
||||
if (mndCheckDbCfg(pMnode, &dbObj.cfg) != 0) {
|
||||
if (mndCheckDbName(dbObj.name, pUser) != 0) {
|
||||
mError("db:%s, failed to create since %s", pCreate->db, terrstr());
|
||||
return -1;
|
||||
}
|
||||
|
||||
char errMsg[TSDB_ERROR_MSG_LEN] = {0};
|
||||
if (mndCheckDbCfg(pMnode, &dbObj.cfg, errMsg, TSDB_ERROR_MSG_LEN) != 0) {
|
||||
mError("db:%s, failed to create since %s", pCreate->db, terrstr());
|
||||
return -1;
|
||||
}
|
||||
|
@ -357,7 +401,7 @@ static int32_t mndCreateDb(SMnode *pMnode, SMnodeMsg *pMsg, SCreateDbMsg *pCreat
|
|||
}
|
||||
sdbSetRawStatus(pCommitRaw, SDB_STATUS_READY);
|
||||
|
||||
if (mndTransPrepare(pTrans) != 0) {
|
||||
if (mndTransPrepare(pMnode, pTrans) != 0) {
|
||||
mError("trans:%d, failed to prepare since %s", pTrans->id, terrstr());
|
||||
mndTransDrop(pTrans);
|
||||
return -1;
|
||||
|
@ -403,11 +447,10 @@ static int32_t mndProcessCreateDbMsg(SMnodeMsg *pMsg) {
|
|||
return -1;
|
||||
}
|
||||
|
||||
int32_t code = mndCreateDb(pMnode, pMsg, pCreate, pOperUser->acct);
|
||||
int32_t code = mndCreateDb(pMnode, pMsg, pCreate, pOperUser);
|
||||
mndReleaseUser(pMnode, pOperUser);
|
||||
|
||||
if (code != 0) {
|
||||
terrno = code;
|
||||
mError("db:%s, failed to create since %s", pCreate->db, terrstr());
|
||||
return -1;
|
||||
}
|
||||
|
@ -415,7 +458,7 @@ static int32_t mndProcessCreateDbMsg(SMnodeMsg *pMsg) {
|
|||
return TSDB_CODE_MND_ACTION_IN_PROGRESS;
|
||||
}
|
||||
|
||||
static int32_t mnodeSetDbCfgFromAlterDbMsg(SDbObj *pDb, SAlterDbMsg *pAlter) {
|
||||
static int32_t mndSetDbCfgFromAlterDbMsg(SDbObj *pDb, SAlterDbMsg *pAlter) {
|
||||
bool changed = false;
|
||||
|
||||
if (pAlter->totalBlocks >= 0 && pAlter->totalBlocks != pDb->cfg.totalBlocks) {
|
||||
|
@ -491,7 +534,7 @@ static int32_t mndUpdateDb(SMnode *pMnode, SMnodeMsg *pMsg, SDbObj *pOldDb, SDbO
|
|||
}
|
||||
sdbSetRawStatus(pUndoRaw, SDB_STATUS_READY);
|
||||
|
||||
if (mndTransPrepare(pTrans) != 0) {
|
||||
if (mndTransPrepare(pMnode, pTrans) != 0) {
|
||||
mError("trans:%d, failed to prepare since %s", pTrans->id, terrstr());
|
||||
mndTransDrop(pTrans);
|
||||
return -1;
|
||||
|
@ -521,7 +564,7 @@ static int32_t mndProcessAlterDbMsg(SMnodeMsg *pMsg) {
|
|||
SDbObj dbObj = {0};
|
||||
memcpy(&dbObj, pDb, sizeof(SDbObj));
|
||||
|
||||
int32_t code = mnodeSetDbCfgFromAlterDbMsg(&dbObj, pAlter);
|
||||
int32_t code = mndSetDbCfgFromAlterDbMsg(&dbObj, pAlter);
|
||||
if (code != 0) {
|
||||
mndReleaseDb(pMnode, pDb);
|
||||
mError("db:%s, failed to alter since %s", pAlter->db, tstrerror(code));
|
||||
|
@ -571,7 +614,7 @@ static int32_t mndDropDb(SMnode *pMnode, SMnodeMsg *pMsg, SDbObj *pDb) {
|
|||
}
|
||||
sdbSetRawStatus(pCommitRaw, SDB_STATUS_DROPPED);
|
||||
|
||||
if (mndTransPrepare(pTrans) != 0) {
|
||||
if (mndTransPrepare(pMnode, pTrans) != 0) {
|
||||
mError("trans:%d, failed to prepare since %s", pTrans->id, terrstr());
|
||||
mndTransDrop(pTrans);
|
||||
return -1;
|
||||
|
@ -603,7 +646,6 @@ static int32_t mndProcessDropDbMsg(SMnodeMsg *pMsg) {
|
|||
mndReleaseDb(pMnode, pDb);
|
||||
|
||||
if (code != 0) {
|
||||
terrno = code;
|
||||
mError("db:%s, failed to drop since %s", pDrop->db, terrstr());
|
||||
return code;
|
||||
}
|
||||
|
@ -772,10 +814,14 @@ static int32_t mndGetDbMeta(SMnodeMsg *pMsg, SShowObj *pShow, STableMetaMsg *pMe
|
|||
return 0;
|
||||
}
|
||||
|
||||
char *mnodeGetDbStr(char *src) {
|
||||
char *mnGetDbStr(char *src) {
|
||||
char *pos = strstr(src, TS_PATH_DELIMITER);
|
||||
if (pos != NULL) ++pos;
|
||||
|
||||
if (pos == NULL) {
|
||||
return src;
|
||||
}
|
||||
|
||||
return pos;
|
||||
}
|
||||
|
||||
|
@ -794,7 +840,7 @@ static int32_t mndRetrieveDbs(SMnodeMsg *pMsg, SShowObj *pShow, char *data, int3
|
|||
cols = 0;
|
||||
|
||||
pWrite = data + pShow->offset[cols] * rows + pShow->bytes[cols] * numOfRows;
|
||||
char *name = mnodeGetDbStr(pDb->name);
|
||||
char *name = mnGetDbStr(pDb->name);
|
||||
if (name != NULL) {
|
||||
STR_WITH_MAXSIZE_TO_VARSTR(pWrite, name, pShow->bytes[cols]);
|
||||
} else {
|
||||
|
@ -887,7 +933,7 @@ static int32_t mndRetrieveDbs(SMnodeMsg *pMsg, SShowObj *pShow, char *data, int3
|
|||
sdbRelease(pSdb, pDb);
|
||||
}
|
||||
|
||||
mnodeVacuumResult(data, pShow->numOfColumns, numOfRows, rows, pShow);
|
||||
mndVacuumResult(data, pShow->numOfColumns, numOfRows, rows, pShow);
|
||||
pShow->numOfReads += numOfRows;
|
||||
|
||||
return numOfRows;
|
||||
|
|
|
@ -19,7 +19,7 @@
|
|||
#include "mndShow.h"
|
||||
#include "mndTrans.h"
|
||||
#include "ttime.h"
|
||||
#include "tutil.h"
|
||||
#include "tep.h"
|
||||
|
||||
#define TSDB_DNODE_VER 1
|
||||
#define TSDB_DNODE_RESERVE_SIZE 64
|
||||
|
@ -27,8 +27,6 @@
|
|||
#define TSDB_CONIIG_VALUE_LEN 48
|
||||
#define TSDB_CONFIG_NUMBER 8
|
||||
|
||||
static int32_t id = 2;
|
||||
|
||||
static const char *offlineReason[] = {
|
||||
"",
|
||||
"status msg timeout",
|
||||
|
@ -110,7 +108,7 @@ static int32_t mndCreateDefaultDnode(SMnode *pMnode) {
|
|||
}
|
||||
|
||||
static SSdbRaw *mndDnodeActionEncode(SDnodeObj *pDnode) {
|
||||
SSdbRaw *pRaw = sdbAllocRaw(SDB_DNODE, TSDB_DNODE_VER, sizeof(SDnodeObj));
|
||||
SSdbRaw *pRaw = sdbAllocRaw(SDB_DNODE, TSDB_DNODE_VER, sizeof(SDnodeObj) + TSDB_DNODE_RESERVE_SIZE);
|
||||
if (pRaw == NULL) return NULL;
|
||||
|
||||
int32_t dataPos = 0;
|
||||
|
@ -177,6 +175,7 @@ static int32_t mndDnodeActionDelete(SSdb *pSdb, SDnodeObj *pDnode) {
|
|||
|
||||
static int32_t mndDnodeActionUpdate(SSdb *pSdb, SDnodeObj *pOldDnode, SDnodeObj *pNewDnode) {
|
||||
mTrace("dnode:%d, perform update action", pOldDnode->id);
|
||||
pOldDnode->updateTime = pNewDnode->updateTime;
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -389,7 +388,7 @@ static int32_t mndProcessStatusMsg(SMnodeMsg *pMsg) {
|
|||
|
||||
static int32_t mndCreateDnode(SMnode *pMnode, SMnodeMsg *pMsg, SCreateDnodeMsg *pCreate) {
|
||||
SDnodeObj dnodeObj = {0};
|
||||
dnodeObj.id = id++;
|
||||
dnodeObj.id = sdbGetMaxId(pMnode->pSdb, SDB_DNODE);
|
||||
dnodeObj.createdTime = taosGetTimestampMs();
|
||||
dnodeObj.updateTime = dnodeObj.createdTime;
|
||||
taosGetFqdnPortFromEp(pCreate->ep, dnodeObj.fqdn, &dnodeObj.port);
|
||||
|
@ -413,25 +412,9 @@ static int32_t mndCreateDnode(SMnode *pMnode, SMnodeMsg *pMsg, SCreateDnodeMsg *
|
|||
mndTransDrop(pTrans);
|
||||
return -1;
|
||||
}
|
||||
sdbSetRawStatus(pRedoRaw, SDB_STATUS_CREATING);
|
||||
sdbSetRawStatus(pRedoRaw, SDB_STATUS_READY);
|
||||
|
||||
SSdbRaw *pUndoRaw = mndDnodeActionEncode(&dnodeObj);
|
||||
if (pUndoRaw == NULL || mndTransAppendUndolog(pTrans, pUndoRaw) != 0) {
|
||||
mError("trans:%d, failed to append undo log since %s", pTrans->id, terrstr());
|
||||
mndTransDrop(pTrans);
|
||||
return -1;
|
||||
}
|
||||
sdbSetRawStatus(pUndoRaw, SDB_STATUS_DROPPED);
|
||||
|
||||
SSdbRaw *pCommitRaw = mndDnodeActionEncode(&dnodeObj);
|
||||
if (pCommitRaw == NULL || mndTransAppendCommitlog(pTrans, pCommitRaw) != 0) {
|
||||
mError("trans:%d, failed to append commit log since %s", pTrans->id, terrstr());
|
||||
mndTransDrop(pTrans);
|
||||
return -1;
|
||||
}
|
||||
sdbSetRawStatus(pCommitRaw, SDB_STATUS_READY);
|
||||
|
||||
if (mndTransPrepare(pTrans) != 0) {
|
||||
if (mndTransPrepare(pMnode, pTrans) != 0) {
|
||||
mError("trans:%d, failed to prepare since %s", pTrans->id, terrstr());
|
||||
mndTransDrop(pTrans);
|
||||
return -1;
|
||||
|
@ -485,25 +468,9 @@ static int32_t mndDropDnode(SMnode *pMnode, SMnodeMsg *pMsg, SDnodeObj *pDnode)
|
|||
mndTransDrop(pTrans);
|
||||
return -1;
|
||||
}
|
||||
sdbSetRawStatus(pRedoRaw, SDB_STATUS_DROPPING);
|
||||
sdbSetRawStatus(pRedoRaw, SDB_STATUS_DROPPED);
|
||||
|
||||
SSdbRaw *pUndoRaw = mndDnodeActionEncode(pDnode);
|
||||
if (pUndoRaw == NULL || mndTransAppendUndolog(pTrans, pUndoRaw) != 0) {
|
||||
mError("trans:%d, failed to append undo log since %s", pTrans->id, terrstr());
|
||||
mndTransDrop(pTrans);
|
||||
return -1;
|
||||
}
|
||||
sdbSetRawStatus(pUndoRaw, SDB_STATUS_READY);
|
||||
|
||||
SSdbRaw *pCommitRaw = mndDnodeActionEncode(pDnode);
|
||||
if (pCommitRaw == NULL || mndTransAppendCommitlog(pTrans, pCommitRaw) != 0) {
|
||||
mError("trans:%d, failed to append commit log since %s", pTrans->id, terrstr());
|
||||
mndTransDrop(pTrans);
|
||||
return -1;
|
||||
}
|
||||
sdbSetRawStatus(pCommitRaw, SDB_STATUS_DROPPED);
|
||||
|
||||
if (mndTransPrepare(pTrans) != 0) {
|
||||
if (mndTransPrepare(pMnode, pTrans) != 0) {
|
||||
mError("trans:%d, failed to prepare since %s", pTrans->id, terrstr());
|
||||
mndTransDrop(pTrans);
|
||||
return -1;
|
||||
|
@ -645,7 +612,7 @@ static int32_t mndRetrieveConfigs(SMnodeMsg *pMsg, SShowObj *pShow, char *data,
|
|||
cols++;
|
||||
}
|
||||
|
||||
mnodeVacuumResult(data, pShow->numOfColumns, numOfRows, rows, pShow);
|
||||
mndVacuumResult(data, pShow->numOfColumns, numOfRows, rows, pShow);
|
||||
pShow->numOfReads += numOfRows;
|
||||
return numOfRows;
|
||||
}
|
||||
|
@ -767,7 +734,7 @@ static int32_t mndRetrieveDnodes(SMnodeMsg *pMsg, SShowObj *pShow, char *data, i
|
|||
sdbRelease(pSdb, pDnode);
|
||||
}
|
||||
|
||||
mnodeVacuumResult(data, pShow->numOfColumns, numOfRows, rows, pShow);
|
||||
mndVacuumResult(data, pShow->numOfColumns, numOfRows, rows, pShow);
|
||||
pShow->numOfReads += numOfRows;
|
||||
|
||||
return numOfRows;
|
||||
|
|
|
@ -183,7 +183,7 @@ static int32_t mndCreateFunc(SMnode *pMnode, SMnodeMsg *pMsg, SCreateFuncMsg *pC
|
|||
}
|
||||
sdbSetRawStatus(pCommitRaw, SDB_STATUS_READY);
|
||||
|
||||
if (mndTransPrepare(pTrans) != 0) {
|
||||
if (mndTransPrepare(pMnode, pTrans) != 0) {
|
||||
mError("trans:%d, failed to prepare since %s", pTrans->id, terrstr());
|
||||
mndTransDrop(pTrans);
|
||||
return -1;
|
||||
|
@ -226,7 +226,7 @@ static int32_t mndDropFunc(SMnode *pMnode, SMnodeMsg *pMsg, SFuncObj *pFunc) {
|
|||
}
|
||||
sdbSetRawStatus(pCommitRaw, SDB_STATUS_DROPPED);
|
||||
|
||||
if (mndTransPrepare(pTrans) != 0) {
|
||||
if (mndTransPrepare(pMnode, pTrans) != 0) {
|
||||
mError("trans:%d, failed to prepare since %s", pTrans->id, terrstr());
|
||||
mndTransDrop(pTrans);
|
||||
return -1;
|
||||
|
@ -500,7 +500,7 @@ static int32_t mndRetrieveFuncs(SMnodeMsg *pMsg, SShowObj *pShow, char *data, in
|
|||
sdbRelease(pSdb, pFunc);
|
||||
}
|
||||
|
||||
mnodeVacuumResult(data, pShow->numOfColumns, numOfRows, rows, pShow);
|
||||
mndVacuumResult(data, pShow->numOfColumns, numOfRows, rows, pShow);
|
||||
pShow->numOfReads += numOfRows;
|
||||
return numOfRows;
|
||||
}
|
||||
|
|
|
@ -238,7 +238,7 @@ static int32_t mndCreateMnode(SMnode *pMnode, SMnodeMsg *pMsg, SCreateMnodeMsg *
|
|||
}
|
||||
sdbSetRawStatus(pCommitRaw, SDB_STATUS_READY);
|
||||
|
||||
if (mndTransPrepare(pTrans) != 0) {
|
||||
if (mndTransPrepare(pMnode, pTrans) != 0) {
|
||||
mError("trans:%d, failed to prepare since %s", pTrans->id, terrstr());
|
||||
mndTransDrop(pTrans);
|
||||
return -1;
|
||||
|
@ -313,7 +313,7 @@ static int32_t mndDropMnode(SMnode *pMnode, SMnodeMsg *pMsg, SMnodeObj *pMnodeOb
|
|||
}
|
||||
sdbSetRawStatus(pCommitRaw, SDB_STATUS_DROPPED);
|
||||
|
||||
if (mndTransPrepare(pTrans) != 0) {
|
||||
if (mndTransPrepare(pMnode, pTrans) != 0) {
|
||||
mError("trans:%d, failed to prepare since %s", pTrans->id, terrstr());
|
||||
mndTransDrop(pTrans);
|
||||
return -1;
|
||||
|
@ -457,7 +457,7 @@ static int32_t mndRetrieveMnodes(SMnodeMsg *pMsg, SShowObj *pShow, char *data, i
|
|||
sdbRelease(pSdb, pMnodeObj);
|
||||
}
|
||||
|
||||
mnodeVacuumResult(data, pShow->numOfColumns, numOfRows, rows, pShow);
|
||||
mndVacuumResult(data, pShow->numOfColumns, numOfRows, rows, pShow);
|
||||
pShow->numOfReads += numOfRows;
|
||||
|
||||
return numOfRows;
|
||||
|
|
|
@ -29,6 +29,7 @@ typedef struct {
|
|||
char user[TSDB_USER_LEN];
|
||||
char app[TSDB_APP_NAME_LEN]; // app name that invokes taosc
|
||||
int32_t pid; // pid of app that invokes taosc
|
||||
int64_t appStartTime; // app start time
|
||||
int32_t id;
|
||||
int8_t killed;
|
||||
int8_t align;
|
||||
|
@ -44,7 +45,7 @@ typedef struct {
|
|||
SQueryDesc *pQueries;
|
||||
} SConnObj;
|
||||
|
||||
static SConnObj *mndCreateConn(SMnode *pMnode, char *user, uint32_t ip, uint16_t port, int32_t pid, const char *app);
|
||||
static SConnObj *mndCreateConn(SMnode *pMnode, char *user, uint32_t ip, uint16_t port, int32_t pid, const char *app, int64_t startTime);
|
||||
static void mndFreeConn(SConnObj *pConn);
|
||||
static SConnObj *mndAcquireConn(SMnode *pMnode, int32_t connId);
|
||||
static void mndReleaseConn(SMnode *pMnode, SConnObj *pConn);
|
||||
|
@ -102,13 +103,14 @@ void mndCleanupProfile(SMnode *pMnode) {
|
|||
}
|
||||
}
|
||||
|
||||
static SConnObj *mndCreateConn(SMnode *pMnode, char *user, uint32_t ip, uint16_t port, int32_t pid, const char *app) {
|
||||
static SConnObj *mndCreateConn(SMnode *pMnode, char *user, uint32_t ip, uint16_t port, int32_t pid, const char *app, int64_t startTime) {
|
||||
SProfileMgmt *pMgmt = &pMnode->profileMgmt;
|
||||
|
||||
int32_t connId = atomic_add_fetch_32(&pMgmt->connId, 1);
|
||||
if (connId == 0) atomic_add_fetch_32(&pMgmt->connId, 1);
|
||||
|
||||
SConnObj connObj = {.pid = pid,
|
||||
.appStartTime = startTime,
|
||||
.id = connId,
|
||||
.killed = 0,
|
||||
.port = port,
|
||||
|
@ -195,6 +197,7 @@ static int32_t mndProcessConnectMsg(SMnodeMsg *pMsg) {
|
|||
SMnode *pMnode = pMsg->pMnode;
|
||||
SConnectMsg *pReq = pMsg->rpcMsg.pCont;
|
||||
pReq->pid = htonl(pReq->pid);
|
||||
pReq->startTime = htobe64(pReq->startTime);
|
||||
|
||||
SRpcConnInfo info = {0};
|
||||
if (rpcGetConnInfo(pMsg->rpcMsg.handle, &info) != 0) {
|
||||
|
@ -216,7 +219,7 @@ static int32_t mndProcessConnectMsg(SMnodeMsg *pMsg) {
|
|||
mndReleaseDb(pMnode, pDb);
|
||||
}
|
||||
|
||||
SConnObj *pConn = mndCreateConn(pMnode, info.user, info.clientIp, info.clientPort, pReq->pid, pReq->app);
|
||||
SConnObj *pConn = mndCreateConn(pMnode, info.user, info.clientIp, info.clientPort, pReq->pid, pReq->app, pReq->startTime);
|
||||
if (pConn == NULL) {
|
||||
mError("user:%s, failed to login from %s while create connection since %s", pMsg->user, ip, terrstr());
|
||||
return -1;
|
||||
|
@ -233,9 +236,7 @@ static int32_t mndProcessConnectMsg(SMnodeMsg *pMsg) {
|
|||
SUserObj *pUser = mndAcquireUser(pMnode, pMsg->user);
|
||||
if (pUser != NULL) {
|
||||
pRsp->acctId = htonl(pUser->acctId);
|
||||
pRsp->superAuth = pUser->superAuth;
|
||||
pRsp->readAuth = pUser->readAuth;
|
||||
pRsp->writeAuth = pUser->writeAuth;
|
||||
pRsp->superUser = pUser->superUser;
|
||||
mndReleaseUser(pMnode, pUser);
|
||||
}
|
||||
|
||||
|
@ -246,11 +247,12 @@ static int32_t mndProcessConnectMsg(SMnodeMsg *pMsg) {
|
|||
|
||||
pMsg->contLen = sizeof(SConnectRsp);
|
||||
pMsg->pCont = pRsp;
|
||||
mDebug("user:%s, login from %s, conn:%d", info.user, ip, pConn->id);
|
||||
|
||||
mDebug("user:%s, login from %s, conn:%d, app:%s", info.user, ip, pConn->id, pReq->app);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int32_t mnodeSaveQueryStreamList(SConnObj *pConn, SHeartBeatMsg *pMsg) {
|
||||
static int32_t mndSaveQueryStreamList(SConnObj *pConn, SHeartBeatMsg *pMsg) {
|
||||
pConn->numOfQueries = 0;
|
||||
pConn->numOfStreams = 0;
|
||||
int32_t numOfQueries = htonl(pMsg->numOfQueries);
|
||||
|
@ -301,7 +303,7 @@ static int32_t mndProcessHeartBeatMsg(SMnodeMsg *pMsg) {
|
|||
|
||||
SConnObj *pConn = mndAcquireConn(pMnode, pReq->connId);
|
||||
if (pConn == NULL) {
|
||||
pConn = mndCreateConn(pMnode, info.user, info.clientIp, info.clientPort, pReq->pid, pReq->app);
|
||||
pConn = mndCreateConn(pMnode, info.user, info.clientIp, info.clientPort, pReq->pid, pReq->app, 0);
|
||||
if (pConn == NULL) {
|
||||
mError("user:%s, conn:%d is freed and failed to create new conn since %s", pMsg->user, pReq->connId, terrstr());
|
||||
return -1;
|
||||
|
@ -336,7 +338,7 @@ static int32_t mndProcessHeartBeatMsg(SMnodeMsg *pMsg) {
|
|||
return -1;
|
||||
}
|
||||
|
||||
mnodeSaveQueryStreamList(pConn, pReq);
|
||||
mndSaveQueryStreamList(pConn, pReq);
|
||||
if (pConn->killed != 0) {
|
||||
pRsp->killConnection = 1;
|
||||
}
|
||||
|
@ -368,7 +370,7 @@ static int32_t mndProcessKillQueryMsg(SMnodeMsg *pMsg) {
|
|||
|
||||
SUserObj *pUser = mndAcquireUser(pMnode, pMsg->user);
|
||||
if (pUser == NULL) return 0;
|
||||
if (!pUser->superAuth) {
|
||||
if (!pUser->superUser) {
|
||||
mndReleaseUser(pMnode, pUser);
|
||||
terrno = TSDB_CODE_MND_NO_RIGHTS;
|
||||
return -1;
|
||||
|
@ -399,7 +401,7 @@ static int32_t mndProcessKillStreamMsg(SMnodeMsg *pMsg) {
|
|||
|
||||
SUserObj *pUser = mndAcquireUser(pMnode, pMsg->user);
|
||||
if (pUser == NULL) return 0;
|
||||
if (!pUser->superAuth) {
|
||||
if (!pUser->superUser) {
|
||||
mndReleaseUser(pMnode, pUser);
|
||||
terrno = TSDB_CODE_MND_NO_RIGHTS;
|
||||
return -1;
|
||||
|
@ -430,7 +432,7 @@ static int32_t mndProcessKillConnectionMsg(SMnodeMsg *pMsg) {
|
|||
|
||||
SUserObj *pUser = mndAcquireUser(pMnode, pMsg->user);
|
||||
if (pUser == NULL) return 0;
|
||||
if (!pUser->superAuth) {
|
||||
if (!pUser->superUser) {
|
||||
mndReleaseUser(pMnode, pUser);
|
||||
terrno = TSDB_CODE_MND_NO_RIGHTS;
|
||||
return -1;
|
||||
|
@ -459,7 +461,7 @@ static int32_t mndGetConnsMeta(SMnodeMsg *pMsg, SShowObj *pShow, STableMetaMsg *
|
|||
|
||||
SUserObj *pUser = mndAcquireUser(pMnode, pMsg->user);
|
||||
if (pUser == NULL) return 0;
|
||||
if (!pUser->superAuth) {
|
||||
if (!pUser->superUser) {
|
||||
mndReleaseUser(pMnode, pUser);
|
||||
terrno = TSDB_CODE_MND_NO_RIGHTS;
|
||||
return -1;
|
||||
|
@ -587,7 +589,7 @@ static int32_t mndGetQueryMeta(SMnodeMsg *pMsg, SShowObj *pShow, STableMetaMsg *
|
|||
|
||||
SUserObj *pUser = mndAcquireUser(pMnode, pMsg->user);
|
||||
if (pUser == NULL) return 0;
|
||||
if (!pUser->superAuth) {
|
||||
if (!pUser->superUser) {
|
||||
mndReleaseUser(pMnode, pUser);
|
||||
terrno = TSDB_CODE_MND_NO_RIGHTS;
|
||||
return -1;
|
||||
|
@ -803,7 +805,7 @@ static int32_t mndGetStreamMeta(SMnodeMsg *pMsg, SShowObj *pShow, STableMetaMsg
|
|||
|
||||
SUserObj *pUser = mndAcquireUser(pMnode, pMsg->user);
|
||||
if (pUser == NULL) return 0;
|
||||
if (!pUser->superAuth) {
|
||||
if (!pUser->superUser) {
|
||||
mndReleaseUser(pMnode, pUser);
|
||||
terrno = TSDB_CODE_MND_NO_RIGHTS;
|
||||
return -1;
|
||||
|
|
|
@ -296,6 +296,8 @@ char *mndShowStr(int32_t showType) {
|
|||
return "show streamtables";
|
||||
case TSDB_MGMT_TABLE_TP:
|
||||
return "show topics";
|
||||
case TSDB_MGMT_TABLE_FUNCTION:
|
||||
return "show functions";
|
||||
default:
|
||||
return "undefined";
|
||||
}
|
||||
|
@ -308,7 +310,7 @@ static bool mndCheckRetrieveFinished(SShowObj *pShow) {
|
|||
return false;
|
||||
}
|
||||
|
||||
void mnodeVacuumResult(char *data, int32_t numOfCols, int32_t rows, int32_t capacity, SShowObj *pShow) {
|
||||
void mndVacuumResult(char *data, int32_t numOfCols, int32_t rows, int32_t capacity, SShowObj *pShow) {
|
||||
if (rows < capacity) {
|
||||
for (int32_t i = 0; i < numOfCols; ++i) {
|
||||
memmove(data + pShow->offset[i] * rows, data + pShow->offset[i] * capacity, pShow->bytes[i] * rows);
|
||||
|
|
|
@ -285,7 +285,7 @@ static int32_t mndCreateStb(SMnode *pMnode, SMnodeMsg *pMsg, SCreateStbMsg *pCre
|
|||
}
|
||||
sdbSetRawStatus(pCommitRaw, SDB_STATUS_READY);
|
||||
|
||||
if (mndTransPrepare(pTrans) != 0) {
|
||||
if (mndTransPrepare(pMnode, pTrans) != 0) {
|
||||
mError("trans:%d, failed to prepare since %s", pTrans->id, terrstr());
|
||||
mndTransDrop(pTrans);
|
||||
return -1;
|
||||
|
@ -433,7 +433,7 @@ static int32_t mndDropStb(SMnode *pMnode, SMnodeMsg *pMsg, SStbObj *pStb) {
|
|||
}
|
||||
sdbSetRawStatus(pCommitRaw, SDB_STATUS_DROPPED);
|
||||
|
||||
if (mndTransPrepare(pTrans) != 0) {
|
||||
if (mndTransPrepare(pMnode, pTrans) != 0) {
|
||||
mError("trans:%d, failed to prepare since %s", pTrans->id, terrstr());
|
||||
mndTransDrop(pTrans);
|
||||
return -1;
|
||||
|
@ -605,7 +605,7 @@ static int32_t mndGetStbMeta(SMnodeMsg *pMsg, SShowObj *pShow, STableMetaMsg *pM
|
|||
return 0;
|
||||
}
|
||||
|
||||
static void mnodeExtractTableName(char *tableId, char *name) {
|
||||
static void mndExtractTableName(char *tableId, char *name) {
|
||||
int pos = -1;
|
||||
int num = 0;
|
||||
for (pos = 0; tableId[pos] != 0; ++pos) {
|
||||
|
@ -665,7 +665,7 @@ static int32_t mndRetrieveStb(SMnodeMsg *pMsg, SShowObj *pShow, char *data, int3
|
|||
}
|
||||
|
||||
pShow->numOfReads += numOfRows;
|
||||
mnodeVacuumResult(data, pShow->numOfColumns, numOfRows, rows, pShow);
|
||||
mndVacuumResult(data, pShow->numOfColumns, numOfRows, rows, pShow);
|
||||
return numOfRows;
|
||||
}
|
||||
|
||||
|
|
|
@ -21,16 +21,16 @@
|
|||
int32_t mndInitSync(SMnode *pMnode) { return 0; }
|
||||
void mndCleanupSync(SMnode *pMnode) {}
|
||||
|
||||
int32_t mndSyncPropose(SMnode *pMnode, SSdbRaw *pRaw, STransMsg *pMsg) {
|
||||
int32_t mndSyncPropose(SMnode *pMnode, SSdbRaw *pRaw) {
|
||||
int32_t code = 0;
|
||||
|
||||
int32_t len = sdbGetRawTotalSize(pRaw);
|
||||
SSdbRaw *pReceived = calloc(1, len);
|
||||
memcpy(pReceived, pRaw, len);
|
||||
mDebug("trans:%d, data:%p recv from sync, code:0x%x pMsg:%p", pMsg->id, pReceived, code & 0xFFFF, pMsg);
|
||||
// int32_t len = sdbGetRawTotalSize(pRaw);
|
||||
// SSdbRaw *pReceived = calloc(1, len);
|
||||
// memcpy(pReceived, pRaw, len);
|
||||
// mDebug("trans:%d, data:%p recv from sync, code:0x%x pMsg:%p", pMsg->id, pReceived, code & 0xFFFF, pMsg);
|
||||
|
||||
mndTransApply(pMnode, pReceived, pMsg, code);
|
||||
return 0;
|
||||
// mndTransApply(pMnode, pReceived, code);
|
||||
return code;
|
||||
}
|
||||
|
||||
bool mndIsMaster(SMnode *pMnode) { return true; }
|
|
@ -17,8 +17,9 @@
|
|||
#include "mndTrans.h"
|
||||
#include "mndSync.h"
|
||||
|
||||
#define SDB_TRANS_VER 1
|
||||
#define TRN_DEFAULT_ARRAY_SIZE 8
|
||||
#define TSDB_TRANS_VER 1
|
||||
#define TSDB_TRN_ARRAY_SIZE 8
|
||||
#define TSDB_TRN_RESERVE_SIZE 64
|
||||
|
||||
static SSdbRaw *mndTransActionEncode(STrans *pTrans);
|
||||
static SSdbRow *mndTransActionDecode(SSdbRaw *pRaw);
|
||||
|
@ -26,6 +27,22 @@ static int32_t mndTransActionInsert(SSdb *pSdb, STrans *pTrans);
|
|||
static int32_t mndTransActionUpdate(SSdb *pSdb, STrans *OldTrans, STrans *pOldTrans);
|
||||
static int32_t mndTransActionDelete(SSdb *pSdb, STrans *pTrans);
|
||||
|
||||
static void mndTransSetRpcHandle(STrans *pTrans, void *rpcHandle);
|
||||
static void mndTransSendRpcRsp(STrans *pTrans, int32_t code);
|
||||
static int32_t mndTransAppendArray(SArray *pArray, SSdbRaw *pRaw);
|
||||
static void mndTransDropArray(SArray *pArray);
|
||||
static int32_t mndTransExecuteArray(SMnode *pMnode, SArray *pArray);
|
||||
static int32_t mndTransExecuteRedoLogs(SMnode *pMnode, STrans *pTrans);
|
||||
static int32_t mndTransExecuteUndoLogs(SMnode *pMnode, STrans *pTrans);
|
||||
static int32_t mndTransExecuteCommitLogs(SMnode *pMnode, STrans *pTrans);
|
||||
static int32_t mndTransExecuteRedoActions(SMnode *pMnode, STrans *pTrans);
|
||||
static int32_t mndTransExecuteUndoActions(SMnode *pMnode, STrans *pTrans);
|
||||
static int32_t mndTransPerformPrepareStage(SMnode *pMnode, STrans *pTrans);
|
||||
static int32_t mndTransPerformExecuteStage(SMnode *pMnode, STrans *pTrans);
|
||||
static int32_t mndTransPerformCommitStage(SMnode *pMnode, STrans *pTrans);
|
||||
static int32_t mndTransPerformRollbackStage(SMnode *pMnode, STrans *pTrans);
|
||||
static void mndTransExecute(SMnode *pMnode, STrans *pTrans);
|
||||
|
||||
int32_t mndInitTrans(SMnode *pMnode) {
|
||||
SSdbTable table = {.sdbType = SDB_TRANS,
|
||||
.keyType = SDB_KEY_INT32,
|
||||
|
@ -41,7 +58,7 @@ int32_t mndInitTrans(SMnode *pMnode) {
|
|||
void mndCleanupTrans(SMnode *pMnode) {}
|
||||
|
||||
static SSdbRaw *mndTransActionEncode(STrans *pTrans) {
|
||||
int32_t rawDataLen = 16 * sizeof(int32_t);
|
||||
int32_t rawDataLen = 16 * sizeof(int32_t) + TSDB_TRN_RESERVE_SIZE;
|
||||
int32_t redoLogNum = taosArrayGetSize(pTrans->redoLogs);
|
||||
int32_t undoLogNum = taosArrayGetSize(pTrans->undoLogs);
|
||||
int32_t commitLogNum = taosArrayGetSize(pTrans->commitLogs);
|
||||
|
@ -63,7 +80,7 @@ static SSdbRaw *mndTransActionEncode(STrans *pTrans) {
|
|||
rawDataLen += sdbGetRawTotalSize(pTmp);
|
||||
}
|
||||
|
||||
SSdbRaw *pRaw = sdbAllocRaw(SDB_TRANS, SDB_TRANS_VER, rawDataLen);
|
||||
SSdbRaw *pRaw = sdbAllocRaw(SDB_TRANS, TSDB_TRANS_VER, rawDataLen);
|
||||
if (pRaw == NULL) {
|
||||
mError("trans:%d, failed to alloc raw since %s", pTrans->id, terrstr());
|
||||
return NULL;
|
||||
|
@ -71,7 +88,6 @@ static SSdbRaw *mndTransActionEncode(STrans *pTrans) {
|
|||
|
||||
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)
|
||||
|
@ -100,6 +116,8 @@ static SSdbRaw *mndTransActionEncode(STrans *pTrans) {
|
|||
SDB_SET_BINARY(pRaw, dataPos, (void *)pTmp, len)
|
||||
}
|
||||
|
||||
SDB_SET_RESERVE(pRaw, dataPos, TSDB_TRN_RESERVE_SIZE)
|
||||
SDB_SET_DATALEN(pRaw, dataPos);
|
||||
mTrace("trans:%d, encode to raw:%p, len:%d", pTrans->id, pRaw, dataPos);
|
||||
return pRaw;
|
||||
}
|
||||
|
@ -113,7 +131,7 @@ static SSdbRow *mndTransActionDecode(SSdbRaw *pRaw) {
|
|||
return NULL;
|
||||
}
|
||||
|
||||
if (sver != SDB_TRANS_VER) {
|
||||
if (sver != TSDB_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;
|
||||
|
@ -126,11 +144,11 @@ static SSdbRow *mndTransActionDecode(SSdbRaw *pRaw) {
|
|||
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 *));
|
||||
pTrans->redoLogs = taosArrayInit(TSDB_TRN_ARRAY_SIZE, sizeof(void *));
|
||||
pTrans->undoLogs = taosArrayInit(TSDB_TRN_ARRAY_SIZE, sizeof(void *));
|
||||
pTrans->commitLogs = taosArrayInit(TSDB_TRN_ARRAY_SIZE, sizeof(void *));
|
||||
pTrans->redoActions = taosArrayInit(TSDB_TRN_ARRAY_SIZE, sizeof(void *));
|
||||
pTrans->undoActions = taosArrayInit(TSDB_TRN_ARRAY_SIZE, sizeof(void *));
|
||||
|
||||
if (pTrans->redoLogs == NULL || pTrans->undoLogs == NULL || pTrans->commitLogs == NULL ||
|
||||
pTrans->redoActions == NULL || pTrans->undoActions == NULL) {
|
||||
|
@ -147,7 +165,6 @@ static SSdbRow *mndTransActionDecode(SSdbRaw *pRaw) {
|
|||
|
||||
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)
|
||||
|
@ -197,6 +214,8 @@ static SSdbRow *mndTransActionDecode(SSdbRaw *pRaw) {
|
|||
}
|
||||
}
|
||||
|
||||
SDB_GET_RESERVE(pRaw, pRow, dataPos, TSDB_TRN_RESERVE_SIZE)
|
||||
|
||||
TRANS_DECODE_OVER:
|
||||
if (code != 0) {
|
||||
mError("trans:%d, failed to parse from raw:%p since %s", pTrans->id, pRaw, tstrerror(errno));
|
||||
|
@ -210,62 +229,65 @@ TRANS_DECODE_OVER:
|
|||
}
|
||||
|
||||
static int32_t mndTransActionInsert(SSdb *pSdb, STrans *pTrans) {
|
||||
mTrace("trans:%d, perform insert action, stage:%d", pTrans->id, pTrans->stage);
|
||||
|
||||
SArray *pArray = pTrans->redoLogs;
|
||||
int32_t arraySize = taosArrayGetSize(pArray);
|
||||
|
||||
for (int32_t i = 0; i < arraySize; ++i) {
|
||||
SSdbRaw *pRaw = taosArrayGetP(pArray, i);
|
||||
int32_t code = sdbWrite(pSdb, pRaw);
|
||||
if (code != 0) {
|
||||
mError("trans:%d, failed to write raw:%p to sdb since %s", pTrans->id, pRaw, terrstr());
|
||||
return code;
|
||||
}
|
||||
}
|
||||
pTrans->stage = TRN_STAGE_PREPARE;
|
||||
mTrace("trans:%d, perform insert action, stage:%s", pTrans->id, mndTransStageStr(pTrans->stage));
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int32_t mndTransActionDelete(SSdb *pSdb, STrans *pTrans) {
|
||||
mTrace("trans:%d, perform delete action, stage:%d", pTrans->id, pTrans->stage);
|
||||
mTrace("trans:%d, perform delete action, stage:%s", pTrans->id, mndTransStageStr(pTrans->stage));
|
||||
|
||||
SArray *pArray = pTrans->undoLogs;
|
||||
int32_t arraySize = taosArrayGetSize(pArray);
|
||||
|
||||
for (int32_t i = 0; i < arraySize; ++i) {
|
||||
SSdbRaw *pRaw = taosArrayGetP(pArray, i);
|
||||
int32_t code = sdbWrite(pSdb, pRaw);
|
||||
if (code != 0) {
|
||||
mError("trans:%d, failed to write raw:%p to sdb since %s", pTrans->id, pRaw, terrstr());
|
||||
return code;
|
||||
}
|
||||
}
|
||||
mndTransDropArray(pTrans->redoLogs);
|
||||
mndTransDropArray(pTrans->undoLogs);
|
||||
mndTransDropArray(pTrans->commitLogs);
|
||||
mndTransDropArray(pTrans->redoActions);
|
||||
mndTransDropArray(pTrans->undoActions);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int32_t mndTransActionUpdate(SSdb *pSdb, STrans *pOldTrans, STrans *pNewTrans) {
|
||||
mTrace("trans:%d, perform update action, stage:%d", pOldTrans->id, pNewTrans->stage);
|
||||
|
||||
SArray *pArray = pOldTrans->commitLogs;
|
||||
int32_t arraySize = taosArrayGetSize(pArray);
|
||||
|
||||
for (int32_t i = 0; i < arraySize; ++i) {
|
||||
SSdbRaw *pRaw = taosArrayGetP(pArray, i);
|
||||
int32_t code = sdbWrite(pSdb, pRaw);
|
||||
if (code != 0) {
|
||||
mError("trans:%d, failed to write raw:%p to sdb since %s", pOldTrans->id, pRaw, terrstr());
|
||||
return code;
|
||||
}
|
||||
}
|
||||
|
||||
mTrace("trans:%d, perform update action, stage:%s", pOldTrans->id, mndTransStageStr(pNewTrans->stage));
|
||||
pOldTrans->stage = pNewTrans->stage;
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int32_t trnGenerateTransId() {
|
||||
static int32_t tmp = 0;
|
||||
return ++tmp;
|
||||
STrans *mndAcquireTrans(SMnode *pMnode, int32_t transId) {
|
||||
SSdb *pSdb = pMnode->pSdb;
|
||||
return sdbAcquire(pSdb, SDB_TRANS, &transId);
|
||||
}
|
||||
|
||||
void mndReleaseTrans(SMnode *pMnode, STrans *pTrans) {
|
||||
SSdb *pSdb = pMnode->pSdb;
|
||||
sdbRelease(pSdb, pTrans);
|
||||
}
|
||||
|
||||
char *mndTransStageStr(ETrnStage stage) {
|
||||
switch (stage) {
|
||||
case TRN_STAGE_PREPARE:
|
||||
return "prepare";
|
||||
case TRN_STAGE_EXECUTE:
|
||||
return "execute";
|
||||
case TRN_STAGE_COMMIT:
|
||||
return "commit";
|
||||
case TRN_STAGE_ROLLBACK:
|
||||
return "rollback";
|
||||
case TRN_STAGE_RETRY:
|
||||
return "retry";
|
||||
default:
|
||||
return "undefined";
|
||||
}
|
||||
}
|
||||
|
||||
char *mndTransPolicyStr(ETrnPolicy policy) {
|
||||
switch (policy) {
|
||||
case TRN_POLICY_ROLLBACK:
|
||||
return "prepare";
|
||||
case TRN_POLICY_RETRY:
|
||||
return "retry";
|
||||
default:
|
||||
return "undefined";
|
||||
}
|
||||
}
|
||||
|
||||
STrans *mndTransCreate(SMnode *pMnode, ETrnPolicy policy, void *rpcHandle) {
|
||||
|
@ -276,16 +298,15 @@ STrans *mndTransCreate(SMnode *pMnode, ETrnPolicy policy, void *rpcHandle) {
|
|||
return NULL;
|
||||
}
|
||||
|
||||
pTrans->id = trnGenerateTransId();
|
||||
pTrans->id = sdbGetMaxId(pMnode->pSdb, SDB_TRANS);
|
||||
pTrans->stage = TRN_STAGE_PREPARE;
|
||||
pTrans->policy = policy;
|
||||
pTrans->pMnode = pMnode;
|
||||
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 *));
|
||||
pTrans->redoLogs = taosArrayInit(TSDB_TRN_ARRAY_SIZE, sizeof(void *));
|
||||
pTrans->undoLogs = taosArrayInit(TSDB_TRN_ARRAY_SIZE, sizeof(void *));
|
||||
pTrans->commitLogs = taosArrayInit(TSDB_TRN_ARRAY_SIZE, sizeof(void *));
|
||||
pTrans->redoActions = taosArrayInit(TSDB_TRN_ARRAY_SIZE, sizeof(void *));
|
||||
pTrans->undoActions = taosArrayInit(TSDB_TRN_ARRAY_SIZE, sizeof(void *));
|
||||
|
||||
if (pTrans->redoLogs == NULL || pTrans->undoLogs == NULL || pTrans->commitLogs == NULL ||
|
||||
pTrans->redoActions == NULL || pTrans->undoActions == NULL) {
|
||||
|
@ -298,7 +319,7 @@ STrans *mndTransCreate(SMnode *pMnode, ETrnPolicy policy, void *rpcHandle) {
|
|||
return pTrans;
|
||||
}
|
||||
|
||||
static void trnDropArray(SArray *pArray) {
|
||||
static void mndTransDropArray(SArray *pArray) {
|
||||
for (int32_t i = 0; i < pArray->size; ++i) {
|
||||
SSdbRaw *pRaw = taosArrayGetP(pArray, i);
|
||||
tfree(pRaw);
|
||||
|
@ -308,17 +329,17 @@ static void trnDropArray(SArray *pArray) {
|
|||
}
|
||||
|
||||
void mndTransDrop(STrans *pTrans) {
|
||||
trnDropArray(pTrans->redoLogs);
|
||||
trnDropArray(pTrans->undoLogs);
|
||||
trnDropArray(pTrans->commitLogs);
|
||||
trnDropArray(pTrans->redoActions);
|
||||
trnDropArray(pTrans->undoActions);
|
||||
mndTransDropArray(pTrans->redoLogs);
|
||||
mndTransDropArray(pTrans->undoLogs);
|
||||
mndTransDropArray(pTrans->commitLogs);
|
||||
mndTransDropArray(pTrans->redoActions);
|
||||
mndTransDropArray(pTrans->undoActions);
|
||||
|
||||
mDebug("trans:%d, data:%p is dropped", pTrans->id, pTrans);
|
||||
tfree(pTrans);
|
||||
}
|
||||
|
||||
void mndTransSetRpcHandle(STrans *pTrans, void *rpcHandle) {
|
||||
static void mndTransSetRpcHandle(STrans *pTrans, void *rpcHandle) {
|
||||
pTrans->rpcHandle = rpcHandle;
|
||||
mTrace("trans:%d, set rpc handle:%p", pTrans->id, rpcHandle);
|
||||
}
|
||||
|
@ -340,19 +361,19 @@ static int32_t mndTransAppendArray(SArray *pArray, SSdbRaw *pRaw) {
|
|||
|
||||
int32_t mndTransAppendRedolog(STrans *pTrans, SSdbRaw *pRaw) {
|
||||
int32_t code = mndTransAppendArray(pTrans->redoLogs, pRaw);
|
||||
mTrace("trans:%d, raw:%p append to redo logs, code:%d", pTrans->id, pRaw, code);
|
||||
mTrace("trans:%d, raw:%p append to redo logs, code:0x%x", pTrans->id, pRaw, code);
|
||||
return code;
|
||||
}
|
||||
|
||||
int32_t mndTransAppendUndolog(STrans *pTrans, SSdbRaw *pRaw) {
|
||||
int32_t code = mndTransAppendArray(pTrans->undoLogs, pRaw);
|
||||
mTrace("trans:%d, raw:%p append to undo logs, code:%d", pTrans->id, pRaw, code);
|
||||
mTrace("trans:%d, raw:%p append to undo logs, code:0x%x", pTrans->id, pRaw, code);
|
||||
return code;
|
||||
}
|
||||
|
||||
int32_t mndTransAppendCommitlog(STrans *pTrans, SSdbRaw *pRaw) {
|
||||
int32_t code = mndTransAppendArray(pTrans->commitLogs, pRaw);
|
||||
mTrace("trans:%d, raw:%p append to commit logs, code:%d", pTrans->id, pRaw, code);
|
||||
mTrace("trans:%d, raw:%p append to commit logs, code:0x%x", pTrans->id, pRaw, code);
|
||||
return code;
|
||||
}
|
||||
|
||||
|
@ -368,7 +389,7 @@ int32_t mndTransAppendUndoAction(STrans *pTrans, SEpSet *pEpSet, void *pMsg) {
|
|||
return code;
|
||||
}
|
||||
|
||||
int32_t mndTransPrepare(STrans *pTrans) {
|
||||
int32_t mndTransPrepare(SMnode *pMnode, STrans *pTrans) {
|
||||
mDebug("trans:%d, prepare transaction", pTrans->id);
|
||||
|
||||
SSdbRaw *pRaw = mndTransActionEncode(pTrans);
|
||||
|
@ -376,180 +397,295 @@ int32_t mndTransPrepare(STrans *pTrans) {
|
|||
mError("trans:%d, failed to decode trans since %s", pTrans->id, terrstr());
|
||||
return -1;
|
||||
}
|
||||
sdbSetRawStatus(pRaw, SDB_STATUS_CREATING);
|
||||
sdbSetRawStatus(pRaw, SDB_STATUS_READY);
|
||||
|
||||
if (sdbWriteNotFree(pTrans->pMnode->pSdb, pRaw) != 0) {
|
||||
mError("trans:%d, failed to write trans since %s", pTrans->id, terrstr());
|
||||
return -1;
|
||||
}
|
||||
|
||||
STransMsg *pMsg = calloc(1, sizeof(STransMsg));
|
||||
pMsg->id = pTrans->id;
|
||||
pMsg->rpcHandle = pTrans->rpcHandle;
|
||||
|
||||
mDebug("trans:%d, start sync, RPC:%p pMsg:%p", pTrans->id, pTrans->rpcHandle, pMsg);
|
||||
if (mndSyncPropose(pTrans->pMnode, pRaw, pMsg) != 0) {
|
||||
mTrace("trans:%d, start sync", pTrans->id);
|
||||
int32_t code = mndSyncPropose(pMnode, pRaw);
|
||||
if (code != 0) {
|
||||
mError("trans:%d, failed to sync since %s", pTrans->id, terrstr());
|
||||
free(pMsg);
|
||||
sdbFreeRaw(pRaw);
|
||||
return -1;
|
||||
}
|
||||
|
||||
sdbFreeRaw(pRaw);
|
||||
mTrace("trans:%d, sync finished", pTrans->id);
|
||||
|
||||
code = sdbWrite(pMnode->pSdb, pRaw);
|
||||
if (code != 0) {
|
||||
mError("trans:%d, failed to write sdb since %s", pTrans->id, terrstr());
|
||||
return -1;
|
||||
}
|
||||
|
||||
STrans *pNewTrans = mndAcquireTrans(pMnode, pTrans->id);
|
||||
if (pNewTrans == NULL) {
|
||||
mError("trans:%d, failed to ready from sdb since %s", pTrans->id, terrstr());
|
||||
return -1;
|
||||
}
|
||||
|
||||
mDebug("trans:%d, prepare finished", pNewTrans->id);
|
||||
pNewTrans->rpcHandle = pTrans->rpcHandle;
|
||||
mndTransExecute(pMnode, pNewTrans);
|
||||
mndReleaseTrans(pMnode, pNewTrans);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void trnSendRpcRsp(STransMsg *pMsg, int32_t code) {
|
||||
mDebug("trans:%d, send rpc rsp, RPC:%p code:0x%x pMsg:%p", pMsg->id, pMsg->rpcHandle, code & 0xFFFF, pMsg);
|
||||
if (pMsg->rpcHandle != NULL) {
|
||||
SRpcMsg rspMsg = {.handle = pMsg->rpcHandle, .code = code};
|
||||
rpcSendResponse(&rspMsg);
|
||||
int32_t mndTransCommit(SMnode *pMnode, STrans *pTrans) {
|
||||
mDebug("trans:%d, commit transaction", pTrans->id);
|
||||
|
||||
SSdbRaw *pRaw = mndTransActionEncode(pTrans);
|
||||
if (pRaw == NULL) {
|
||||
mError("trans:%d, failed to decode trans since %s", pTrans->id, terrstr());
|
||||
return -1;
|
||||
}
|
||||
sdbSetRawStatus(pRaw, SDB_STATUS_DROPPED);
|
||||
|
||||
if (taosArrayGetSize(pTrans->commitLogs) != 0) {
|
||||
mTrace("trans:%d, start sync", pTrans->id);
|
||||
int32_t code = mndSyncPropose(pMnode, pRaw);
|
||||
if (code != 0) {
|
||||
mError("trans:%d, failed to sync since %s", pTrans->id, terrstr());
|
||||
sdbFreeRaw(pRaw);
|
||||
return -1;
|
||||
}
|
||||
|
||||
mTrace("trans:%d, sync finished", pTrans->id);
|
||||
code = sdbWrite(pMnode->pSdb, pRaw);
|
||||
if (code != 0) {
|
||||
mError("trans:%d, failed to write sdb since %s", pTrans->id, terrstr());
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
free(pMsg);
|
||||
mDebug("trans:%d, commit finished", pTrans->id);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int32_t mndTransRollback(SMnode *pMnode, STrans *pTrans) {
|
||||
mDebug("trans:%d, rollback transaction", pTrans->id);
|
||||
|
||||
SSdbRaw *pRaw = mndTransActionEncode(pTrans);
|
||||
if (pRaw == NULL) {
|
||||
mError("trans:%d, failed to decode trans since %s", pTrans->id, terrstr());
|
||||
return -1;
|
||||
}
|
||||
sdbSetRawStatus(pRaw, SDB_STATUS_DROPPED);
|
||||
|
||||
mTrace("trans:%d, start sync", pTrans->id);
|
||||
int32_t code = mndSyncPropose(pMnode, pRaw);
|
||||
if (code != 0) {
|
||||
mError("trans:%d, failed to sync since %s", pTrans->id, terrstr());
|
||||
sdbFreeRaw(pRaw);
|
||||
return -1;
|
||||
}
|
||||
|
||||
mTrace("trans:%d, sync finished", pTrans->id);
|
||||
code = sdbWrite(pMnode->pSdb, pRaw);
|
||||
if (code != 0) {
|
||||
mError("trans:%d, failed to write sdb since %s", pTrans->id, terrstr());
|
||||
return -1;
|
||||
}
|
||||
|
||||
mDebug("trans:%d, rollback finished", pTrans->id);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void mndTransSendRpcRsp(STrans *pTrans, int32_t code) {
|
||||
if (code == TSDB_CODE_MND_ACTION_IN_PROGRESS) return;
|
||||
mDebug("trans:%d, send rpc rsp, RPC:%p code:0x%x", pTrans->id, pTrans->rpcHandle, code & 0xFFFF);
|
||||
|
||||
if (pTrans->rpcHandle != NULL) {
|
||||
SRpcMsg rspMsg = {.handle = pTrans->rpcHandle, .code = code};
|
||||
rpcSendResponse(&rspMsg);
|
||||
}
|
||||
}
|
||||
|
||||
void mndTransApply(SMnode *pMnode, SSdbRaw *pRaw, STransMsg *pMsg, int32_t code) {
|
||||
if (code == 0) {
|
||||
mDebug("trans:%d, commit transaction", pMsg->id);
|
||||
sdbSetRawStatus(pRaw, SDB_STATUS_READY);
|
||||
if (sdbWrite(pMnode->pSdb, pRaw) != 0) {
|
||||
code = terrno;
|
||||
mError("trans:%d, failed to write sdb while commit since %s", pMsg->id, terrstr());
|
||||
}
|
||||
trnSendRpcRsp(pMsg, code);
|
||||
} else {
|
||||
mDebug("trans:%d, rollback transaction", pMsg->id);
|
||||
sdbSetRawStatus(pRaw, SDB_STATUS_DROPPED);
|
||||
if (sdbWrite(pMnode->pSdb, pRaw) != 0) {
|
||||
mError("trans:%d, failed to write sdb while rollback since %s", pMsg->id, terrstr());
|
||||
}
|
||||
trnSendRpcRsp(pMsg, code);
|
||||
}
|
||||
// todo
|
||||
}
|
||||
|
||||
static int32_t trnExecuteArray(SMnode *pMnode, SArray *pArray) {
|
||||
for (int32_t i = 0; i < pArray->size; ++i) {
|
||||
static int32_t mndTransExecuteArray(SMnode *pMnode, SArray *pArray) {
|
||||
SSdb *pSdb = pMnode->pSdb;
|
||||
int32_t arraySize = taosArrayGetSize(pArray);
|
||||
|
||||
for (int32_t i = 0; i < arraySize; ++i) {
|
||||
SSdbRaw *pRaw = taosArrayGetP(pArray, i);
|
||||
if (sdbWrite(pMnode->pSdb, pRaw) != 0) {
|
||||
return -1;
|
||||
int32_t code = sdbWriteNotFree(pSdb, pRaw);
|
||||
if (code != 0) {
|
||||
return code;
|
||||
}
|
||||
}
|
||||
|
||||
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 mndTransExecuteRedoLogs(SMnode *pMnode, STrans *pTrans) {
|
||||
int32_t code = 0;
|
||||
if (taosArrayGetSize(pTrans->redoLogs) != 0) {
|
||||
code = mndTransExecuteArray(pMnode, pTrans->redoLogs);
|
||||
if (code != 0) {
|
||||
mError("trans:%d, failed to execute redo logs since %s", pTrans->id, terrstr())
|
||||
} else {
|
||||
mTrace("trans:%d, execute redo logs finished", pTrans->id)
|
||||
}
|
||||
}
|
||||
|
||||
return code;
|
||||
}
|
||||
|
||||
static int32_t trnPerformExecuteStage(STrans *pTrans) {
|
||||
int32_t code = trnExecuteRedoActions(pTrans);
|
||||
static int32_t mndTransExecuteUndoLogs(SMnode *pMnode, STrans *pTrans) {
|
||||
int32_t code = 0;
|
||||
if (taosArrayGetSize(pTrans->undoLogs) != 0) {
|
||||
code = mndTransExecuteArray(pMnode, pTrans->undoLogs);
|
||||
if (code != 0) {
|
||||
mError("trans:%d, failed to execute undo logs since %s", pTrans->id, terrstr())
|
||||
} else {
|
||||
mTrace("trans:%d, execute undo logs finished", pTrans->id)
|
||||
}
|
||||
}
|
||||
|
||||
return code;
|
||||
}
|
||||
|
||||
static int32_t mndTransExecuteCommitLogs(SMnode *pMnode, STrans *pTrans) {
|
||||
int32_t code = 0;
|
||||
if (taosArrayGetSize(pTrans->commitLogs) != 0) {
|
||||
code = mndTransExecuteArray(pMnode, pTrans->commitLogs);
|
||||
if (code != 0) {
|
||||
mError("trans:%d, failed to execute commit logs since %s", pTrans->id, terrstr())
|
||||
} else {
|
||||
mTrace("trans:%d, execute commit logs finished", pTrans->id)
|
||||
}
|
||||
}
|
||||
|
||||
return code;
|
||||
}
|
||||
|
||||
static int32_t mndTransExecuteRedoActions(SMnode *pMnode, STrans *pTrans) {
|
||||
if (taosArrayGetSize(pTrans->redoActions) != 0) {
|
||||
mTrace("trans:%d, execute redo actions finished", pTrans->id);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int32_t mndTransExecuteUndoActions(SMnode *pMnode, STrans *pTrans) {
|
||||
if (taosArrayGetSize(pTrans->undoActions) != 0) {
|
||||
mTrace("trans:%d, execute undo actions finished", pTrans->id);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int32_t mndTransPerformPrepareStage(SMnode *pMnode, STrans *pTrans) {
|
||||
int32_t code = mndTransExecuteRedoLogs(pMnode, pTrans);
|
||||
|
||||
if (code == 0) {
|
||||
pTrans->stage = TRN_STAGE_EXECUTE;
|
||||
mTrace("trans:%d, stage from prepare to execute", pTrans->id);
|
||||
} else {
|
||||
pTrans->stage = TRN_STAGE_ROLLBACK;
|
||||
mError("trans:%d, stage from prepare to rollback since %s", pTrans->id, terrstr());
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int32_t mndTransPerformExecuteStage(SMnode *pMnode, STrans *pTrans) {
|
||||
int32_t code = mndTransExecuteRedoActions(pMnode, pTrans);
|
||||
|
||||
if (code == 0) {
|
||||
pTrans->stage = TRN_STAGE_COMMIT;
|
||||
return 0;
|
||||
mTrace("trans:%d, stage from execute to commit", pTrans->id);
|
||||
} else if (code == TSDB_CODE_MND_ACTION_IN_PROGRESS) {
|
||||
return -1;
|
||||
mTrace("trans:%d, stage keep on execute since %s", pTrans->id, terrstr(code));
|
||||
return code;
|
||||
} else {
|
||||
if (pTrans->policy == TRN_POLICY_RETRY) {
|
||||
pTrans->stage = TRN_STAGE_RETRY;
|
||||
} else {
|
||||
if (pTrans->policy == TRN_POLICY_ROLLBACK) {
|
||||
pTrans->stage = TRN_STAGE_ROLLBACK;
|
||||
mError("trans:%d, stage from execute to rollback since %s", pTrans->id, terrstr());
|
||||
} else {
|
||||
pTrans->stage = TRN_STAGE_RETRY;
|
||||
mError("trans:%d, stage from execute to retry since %s", pTrans->id, terrstr());
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int32_t trnPerformCommitStage(STrans *pTrans) {
|
||||
if (trnExecuteCommitLogs(pTrans) == 0) {
|
||||
pTrans->stage = TRN_STAGE_EXECUTE;
|
||||
return 0;
|
||||
static int32_t mndTransPerformCommitStage(SMnode *pMnode, STrans *pTrans) {
|
||||
int32_t code = mndTransExecuteCommitLogs(pMnode, pTrans);
|
||||
|
||||
if (code == 0) {
|
||||
pTrans->stage = TRN_STAGE_OVER;
|
||||
mTrace("trans:%d, commit stage finished", pTrans->id);
|
||||
} else {
|
||||
if (pTrans->policy == TRN_POLICY_ROLLBACK) {
|
||||
pTrans->stage = TRN_STAGE_ROLLBACK;
|
||||
mError("trans:%d, stage from commit to rollback since %s", pTrans->id, terrstr());
|
||||
} else {
|
||||
pTrans->stage = TRN_STAGE_RETRY;
|
||||
mError("trans:%d, stage from commit to retry since %s", pTrans->id, terrstr());
|
||||
}
|
||||
}
|
||||
|
||||
return code;
|
||||
}
|
||||
|
||||
static int32_t mndTransPerformRollbackStage(SMnode *pMnode, STrans *pTrans) {
|
||||
int32_t code = mndTransExecuteUndoActions(pMnode, pTrans);
|
||||
|
||||
if (code == 0) {
|
||||
mTrace("trans:%d, rollbacked", pTrans->id);
|
||||
} else {
|
||||
pTrans->stage = TRN_STAGE_ROLLBACK;
|
||||
return -1;
|
||||
mError("trans:%d, stage keep on rollback since %s", pTrans->id, terrstr());
|
||||
}
|
||||
|
||||
return code;
|
||||
}
|
||||
|
||||
static int32_t trnPerformRollbackStage(STrans *pTrans) {
|
||||
if (trnExecuteCommitLogs(pTrans) == 0) {
|
||||
pTrans->stage = TRN_STAGE_EXECUTE;
|
||||
return 0;
|
||||
static int32_t mndTransPerformRetryStage(SMnode *pMnode, STrans *pTrans) {
|
||||
int32_t code = mndTransExecuteRedoActions(pMnode, pTrans);
|
||||
|
||||
if (code == 0) {
|
||||
pTrans->stage = TRN_STAGE_COMMIT;
|
||||
mTrace("trans:%d, stage from retry to commit", pTrans->id);
|
||||
} else {
|
||||
pTrans->stage = TRN_STAGE_ROLLBACK;
|
||||
return -1;
|
||||
pTrans->stage = TRN_STAGE_RETRY;
|
||||
mError("trans:%d, stage keep on retry since %s", pTrans->id, terrstr());
|
||||
}
|
||||
|
||||
return code;
|
||||
}
|
||||
|
||||
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) {
|
||||
static void mndTransExecute(SMnode *pMnode, STrans *pTrans) {
|
||||
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;
|
||||
while (code == 0) {
|
||||
switch (pTrans->stage) {
|
||||
case TRN_STAGE_PREPARE:
|
||||
code = mndTransPerformPrepareStage(pMnode, pTrans);
|
||||
break;
|
||||
case TRN_STAGE_EXECUTE:
|
||||
code = mndTransPerformExecuteStage(pMnode, pTrans);
|
||||
break;
|
||||
case TRN_STAGE_COMMIT:
|
||||
code = mndTransCommit(pMnode, pTrans);
|
||||
if (code == 0) {
|
||||
code = mndTransPerformCommitStage(pMnode, pTrans);
|
||||
}
|
||||
break;
|
||||
case TRN_STAGE_ROLLBACK:
|
||||
code = mndTransPerformRollbackStage(pMnode, pTrans);
|
||||
if (code == 0) {
|
||||
code = mndTransRollback(pMnode, pTrans);
|
||||
}
|
||||
break;
|
||||
case TRN_STAGE_RETRY:
|
||||
code = mndTransPerformRetryStage(pMnode, pTrans);
|
||||
break;
|
||||
default:
|
||||
mndTransSendRpcRsp(pTrans, 0);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
mndTransSendRpcRsp(pTrans, code);
|
||||
}
|
||||
|
|
|
@ -20,7 +20,8 @@
|
|||
#include "mndTrans.h"
|
||||
#include "tkey.h"
|
||||
|
||||
#define SDB_USER_VER 1
|
||||
#define TSDB_USER_VER 1
|
||||
#define TSDB_USER_RESERVE_SIZE 64
|
||||
|
||||
static int32_t mndCreateDefaultUsers(SMnode *pMnode);
|
||||
static SSdbRaw *mndUserActionEncode(SUserObj *pUser);
|
||||
|
@ -65,11 +66,9 @@ static int32_t mndCreateDefaultUser(SMnode *pMnode, char *acct, char *user, char
|
|||
taosEncryptPass((uint8_t *)pass, strlen(pass), userObj.pass);
|
||||
userObj.createdTime = taosGetTimestampMs();
|
||||
userObj.updateTime = userObj.createdTime;
|
||||
userObj.readAuth = 1;
|
||||
userObj.writeAuth = 1;
|
||||
|
||||
if (strcmp(user, TSDB_DEFAULT_USER) == 0) {
|
||||
userObj.superAuth = 1;
|
||||
userObj.superUser = 1;
|
||||
}
|
||||
|
||||
SSdbRaw *pRaw = mndUserActionEncode(&userObj);
|
||||
|
@ -89,24 +88,23 @@ static int32_t mndCreateDefaultUsers(SMnode *pMnode) {
|
|||
if (mndCreateDefaultUser(pMnode, TSDB_DEFAULT_USER, "_" TSDB_DEFAULT_USER, TSDB_DEFAULT_PASS) != 0) {
|
||||
return -1;
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static SSdbRaw *mndUserActionEncode(SUserObj *pUser) {
|
||||
SSdbRaw *pRaw = sdbAllocRaw(SDB_USER, SDB_USER_VER, sizeof(SUserObj));
|
||||
SSdbRaw *pRaw = sdbAllocRaw(SDB_USER, TSDB_USER_VER, sizeof(SUserObj) + TSDB_USER_RESERVE_SIZE);
|
||||
if (pRaw == NULL) return NULL;
|
||||
|
||||
int32_t dataPos = 0;
|
||||
SDB_SET_BINARY(pRaw, dataPos, pUser->user, TSDB_USER_LEN)
|
||||
SDB_SET_BINARY(pRaw, dataPos, pUser->pass, TSDB_KEY_LEN)
|
||||
SDB_SET_BINARY(pRaw, dataPos, pUser->pass, TSDB_PASSWORD_LEN)
|
||||
SDB_SET_BINARY(pRaw, dataPos, pUser->acct, TSDB_USER_LEN)
|
||||
SDB_SET_INT64(pRaw, dataPos, pUser->createdTime)
|
||||
SDB_SET_INT64(pRaw, dataPos, pUser->updateTime)
|
||||
SDB_SET_INT8(pRaw, dataPos, pUser->superAuth)
|
||||
SDB_SET_INT8(pRaw, dataPos, pUser->readAuth)
|
||||
SDB_SET_INT8(pRaw, dataPos, pUser->writeAuth)
|
||||
SDB_SET_INT8(pRaw, dataPos, pUser->superUser)
|
||||
SDB_SET_RESERVE(pRaw, dataPos, TSDB_USER_RESERVE_SIZE)
|
||||
SDB_SET_DATALEN(pRaw, dataPos);
|
||||
|
||||
return pRaw;
|
||||
|
@ -116,7 +114,7 @@ static SSdbRow *mndUserActionDecode(SSdbRaw *pRaw) {
|
|||
int8_t sver = 0;
|
||||
if (sdbGetRawSoftVer(pRaw, &sver) != 0) return NULL;
|
||||
|
||||
if (sver != SDB_USER_VER) {
|
||||
if (sver != TSDB_USER_VER) {
|
||||
mError("failed to decode user since %s", terrstr());
|
||||
terrno = TSDB_CODE_SDB_INVALID_DATA_VER;
|
||||
return NULL;
|
||||
|
@ -128,13 +126,12 @@ static SSdbRow *mndUserActionDecode(SSdbRaw *pRaw) {
|
|||
|
||||
int32_t dataPos = 0;
|
||||
SDB_GET_BINARY(pRaw, pRow, dataPos, pUser->user, TSDB_USER_LEN)
|
||||
SDB_GET_BINARY(pRaw, pRow, dataPos, pUser->pass, TSDB_KEY_LEN)
|
||||
SDB_GET_BINARY(pRaw, pRow, dataPos, pUser->pass, TSDB_PASSWORD_LEN)
|
||||
SDB_GET_BINARY(pRaw, pRow, dataPos, pUser->acct, TSDB_USER_LEN)
|
||||
SDB_GET_INT64(pRaw, pRow, dataPos, &pUser->createdTime)
|
||||
SDB_GET_INT64(pRaw, pRow, dataPos, &pUser->updateTime)
|
||||
SDB_GET_INT8(pRaw, pRow, dataPos, &pUser->superAuth)
|
||||
SDB_GET_INT8(pRaw, pRow, dataPos, &pUser->readAuth)
|
||||
SDB_GET_INT8(pRaw, pRow, dataPos, &pUser->writeAuth)
|
||||
SDB_GET_INT8(pRaw, pRow, dataPos, &pUser->superUser)
|
||||
SDB_GET_RESERVE(pRaw, pRow, dataPos, TSDB_USER_RESERVE_SIZE)
|
||||
|
||||
return pRow;
|
||||
}
|
||||
|
@ -172,14 +169,8 @@ static int32_t mndUserActionDelete(SSdb *pSdb, SUserObj *pUser) {
|
|||
|
||||
static int32_t mndUserActionUpdate(SSdb *pSdb, SUserObj *pOldUser, SUserObj *pNewUser) {
|
||||
mTrace("user:%s, perform update action", pOldUser->user);
|
||||
memcpy(pOldUser->user, pNewUser->user, TSDB_USER_LEN);
|
||||
memcpy(pOldUser->pass, pNewUser->pass, TSDB_KEY_LEN);
|
||||
memcpy(pOldUser->acct, pNewUser->acct, TSDB_USER_LEN);
|
||||
pOldUser->createdTime = pNewUser->createdTime;
|
||||
memcpy(pOldUser->pass, pNewUser->pass, TSDB_PASSWORD_LEN);
|
||||
pOldUser->updateTime = pNewUser->updateTime;
|
||||
pOldUser->superAuth = pNewUser->superAuth;
|
||||
pOldUser->readAuth = pNewUser->readAuth;
|
||||
pOldUser->writeAuth = pNewUser->writeAuth;
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -200,9 +191,7 @@ static int32_t mndCreateUser(SMnode *pMnode, char *acct, char *user, char *pass,
|
|||
taosEncryptPass((uint8_t *)pass, strlen(pass), userObj.pass);
|
||||
userObj.createdTime = taosGetTimestampMs();
|
||||
userObj.updateTime = userObj.createdTime;
|
||||
userObj.superAuth = 0;
|
||||
userObj.readAuth = 1;
|
||||
userObj.writeAuth = 1;
|
||||
userObj.superUser = 0;
|
||||
|
||||
STrans *pTrans = mndTransCreate(pMnode, TRN_POLICY_ROLLBACK, pMsg->rpcMsg.handle);
|
||||
if (pTrans == NULL) {
|
||||
|
@ -217,101 +206,9 @@ static int32_t mndCreateUser(SMnode *pMnode, char *acct, char *user, char *pass,
|
|||
mndTransDrop(pTrans);
|
||||
return -1;
|
||||
}
|
||||
sdbSetRawStatus(pRedoRaw, SDB_STATUS_CREATING);
|
||||
|
||||
SSdbRaw *pUndoRaw = mndUserActionEncode(&userObj);
|
||||
if (pUndoRaw == NULL || mndTransAppendUndolog(pTrans, pUndoRaw) != 0) {
|
||||
mError("trans:%d, failed to append undo log since %s", pTrans->id, terrstr());
|
||||
mndTransDrop(pTrans);
|
||||
return -1;
|
||||
}
|
||||
sdbSetRawStatus(pUndoRaw, SDB_STATUS_DROPPED);
|
||||
|
||||
SSdbRaw *pCommitRaw = mndUserActionEncode(&userObj);
|
||||
if (pCommitRaw == NULL || mndTransAppendCommitlog(pTrans, pCommitRaw) != 0) {
|
||||
mError("trans:%d, failed to append commit log since %s", pTrans->id, terrstr());
|
||||
mndTransDrop(pTrans);
|
||||
return -1;
|
||||
}
|
||||
sdbSetRawStatus(pCommitRaw, SDB_STATUS_READY);
|
||||
|
||||
if (mndTransPrepare(pTrans) != 0) {
|
||||
mError("trans:%d, failed to prepare since %s", pTrans->id, terrstr());
|
||||
mndTransDrop(pTrans);
|
||||
return -1;
|
||||
}
|
||||
|
||||
mndTransDrop(pTrans);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int32_t mndUpdateUser(SMnode *pMnode, SUserObj *pOldUser, SUserObj *pNewUser, SMnodeMsg *pMsg) {
|
||||
STrans *pTrans = mndTransCreate(pMnode, TRN_POLICY_ROLLBACK, pMsg->rpcMsg.handle);
|
||||
if (pTrans == NULL) {
|
||||
mError("user:%s, failed to update since %s", pOldUser->user, terrstr());
|
||||
return -1;
|
||||
}
|
||||
mDebug("trans:%d, used to update user:%s", pTrans->id, pOldUser->user);
|
||||
|
||||
SSdbRaw *pRedoRaw = mndUserActionEncode(pNewUser);
|
||||
if (pRedoRaw == NULL || mndTransAppendRedolog(pTrans, pRedoRaw) != 0) {
|
||||
mError("trans:%d, failed to append redo log since %s", pTrans->id, terrstr());
|
||||
mndTransDrop(pTrans);
|
||||
return -1;
|
||||
}
|
||||
sdbSetRawStatus(pRedoRaw, SDB_STATUS_READY);
|
||||
|
||||
SSdbRaw *pUndoRaw = mndUserActionEncode(pOldUser);
|
||||
if (pUndoRaw == NULL || mndTransAppendUndolog(pTrans, pUndoRaw) != 0) {
|
||||
mError("trans:%d, failed to append undo log since %s", pTrans->id, terrstr());
|
||||
mndTransDrop(pTrans);
|
||||
return -1;
|
||||
}
|
||||
sdbSetRawStatus(pUndoRaw, SDB_STATUS_READY);
|
||||
|
||||
if (mndTransPrepare(pTrans) != 0) {
|
||||
mError("trans:%d, failed to prepare since %s", pTrans->id, terrstr());
|
||||
mndTransDrop(pTrans);
|
||||
return -1;
|
||||
}
|
||||
|
||||
mndTransDrop(pTrans);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int32_t mndDropUser(SMnode *pMnode, SMnodeMsg *pMsg, SUserObj *pUser) {
|
||||
STrans *pTrans = mndTransCreate(pMnode, TRN_POLICY_ROLLBACK, pMsg->rpcMsg.handle);
|
||||
if (pTrans == NULL) {
|
||||
mError("user:%s, failed to drop since %s", pUser->user, terrstr());
|
||||
return -1;
|
||||
}
|
||||
mDebug("trans:%d, used to drop user:%s", pTrans->id, pUser->user);
|
||||
|
||||
SSdbRaw *pRedoRaw = mndUserActionEncode(pUser);
|
||||
if (pRedoRaw == NULL || mndTransAppendRedolog(pTrans, pRedoRaw) != 0) {
|
||||
mError("trans:%d, failed to append redo log since %s", pTrans->id, terrstr());
|
||||
mndTransDrop(pTrans);
|
||||
return -1;
|
||||
}
|
||||
sdbSetRawStatus(pRedoRaw, SDB_STATUS_DROPPING);
|
||||
|
||||
SSdbRaw *pUndoRaw = mndUserActionEncode(pUser);
|
||||
if (pUndoRaw == NULL || mndTransAppendUndolog(pTrans, pUndoRaw) != 0) {
|
||||
mError("trans:%d, failed to append undo log since %s", pTrans->id, terrstr());
|
||||
mndTransDrop(pTrans);
|
||||
return -1;
|
||||
}
|
||||
sdbSetRawStatus(pUndoRaw, SDB_STATUS_READY);
|
||||
|
||||
SSdbRaw *pCommitRaw = mndUserActionEncode(pUser);
|
||||
if (pCommitRaw == NULL || mndTransAppendCommitlog(pTrans, pCommitRaw) != 0) {
|
||||
mError("trans:%d, failed to append commit log since %s", pTrans->id, terrstr());
|
||||
mndTransDrop(pTrans);
|
||||
return -1;
|
||||
}
|
||||
sdbSetRawStatus(pCommitRaw, SDB_STATUS_DROPPED);
|
||||
|
||||
if (mndTransPrepare(pTrans) != 0) {
|
||||
if (mndTransPrepare(pMnode, pTrans) != 0) {
|
||||
mError("trans:%d, failed to prepare since %s", pTrans->id, terrstr());
|
||||
mndTransDrop(pTrans);
|
||||
return -1;
|
||||
|
@ -365,6 +262,32 @@ static int32_t mndProcessCreateUserMsg(SMnodeMsg *pMsg) {
|
|||
return TSDB_CODE_MND_ACTION_IN_PROGRESS;
|
||||
}
|
||||
|
||||
static int32_t mndUpdateUser(SMnode *pMnode, SUserObj *pOldUser, SUserObj *pNewUser, SMnodeMsg *pMsg) {
|
||||
STrans *pTrans = mndTransCreate(pMnode, TRN_POLICY_ROLLBACK, pMsg->rpcMsg.handle);
|
||||
if (pTrans == NULL) {
|
||||
mError("user:%s, failed to update since %s", pOldUser->user, terrstr());
|
||||
return -1;
|
||||
}
|
||||
mDebug("trans:%d, used to update user:%s", pTrans->id, pOldUser->user);
|
||||
|
||||
SSdbRaw *pRedoRaw = mndUserActionEncode(pNewUser);
|
||||
if (pRedoRaw == NULL || mndTransAppendRedolog(pTrans, pRedoRaw) != 0) {
|
||||
mError("trans:%d, failed to append redo log since %s", pTrans->id, terrstr());
|
||||
mndTransDrop(pTrans);
|
||||
return -1;
|
||||
}
|
||||
sdbSetRawStatus(pRedoRaw, SDB_STATUS_READY);
|
||||
|
||||
if (mndTransPrepare(pMnode, pTrans) != 0) {
|
||||
mError("trans:%d, failed to prepare since %s", pTrans->id, terrstr());
|
||||
mndTransDrop(pTrans);
|
||||
return -1;
|
||||
}
|
||||
|
||||
mndTransDrop(pTrans);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int32_t mndProcessAlterUserMsg(SMnodeMsg *pMsg) {
|
||||
SMnode *pMnode = pMsg->pMnode;
|
||||
SAlterUserMsg *pAlter = pMsg->rpcMsg.pCont;
|
||||
|
@ -401,6 +324,7 @@ static int32_t mndProcessAlterUserMsg(SMnodeMsg *pMsg) {
|
|||
memcpy(&newUser, pUser, sizeof(SUserObj));
|
||||
memset(pUser->pass, 0, sizeof(pUser->pass));
|
||||
taosEncryptPass((uint8_t *)pAlter->pass, strlen(pAlter->pass), pUser->pass);
|
||||
newUser.updateTime = taosGetTimestampMs();
|
||||
|
||||
int32_t code = mndUpdateUser(pMnode, pUser, &newUser, pMsg);
|
||||
sdbRelease(pMnode->pSdb, pOperUser);
|
||||
|
@ -413,6 +337,32 @@ static int32_t mndProcessAlterUserMsg(SMnodeMsg *pMsg) {
|
|||
return TSDB_CODE_MND_ACTION_IN_PROGRESS;
|
||||
}
|
||||
|
||||
static int32_t mndDropUser(SMnode *pMnode, SMnodeMsg *pMsg, SUserObj *pUser) {
|
||||
STrans *pTrans = mndTransCreate(pMnode, TRN_POLICY_ROLLBACK, pMsg->rpcMsg.handle);
|
||||
if (pTrans == NULL) {
|
||||
mError("user:%s, failed to drop since %s", pUser->user, terrstr());
|
||||
return -1;
|
||||
}
|
||||
mDebug("trans:%d, used to drop user:%s", pTrans->id, pUser->user);
|
||||
|
||||
SSdbRaw *pRedoRaw = mndUserActionEncode(pUser);
|
||||
if (pRedoRaw == NULL || mndTransAppendRedolog(pTrans, pRedoRaw) != 0) {
|
||||
mError("trans:%d, failed to append redo log since %s", pTrans->id, terrstr());
|
||||
mndTransDrop(pTrans);
|
||||
return -1;
|
||||
}
|
||||
sdbSetRawStatus(pRedoRaw, SDB_STATUS_DROPPED);
|
||||
|
||||
if (mndTransPrepare(pMnode, pTrans) != 0) {
|
||||
mError("trans:%d, failed to prepare since %s", pTrans->id, terrstr());
|
||||
mndTransDrop(pTrans);
|
||||
return -1;
|
||||
}
|
||||
|
||||
mndTransDrop(pTrans);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int32_t mndProcessDropUserMsg(SMnodeMsg *pMsg) {
|
||||
SMnode *pMnode = pMsg->pMnode;
|
||||
SDropUserMsg *pDrop = pMsg->rpcMsg.pCont;
|
||||
|
@ -515,7 +465,7 @@ static int32_t mndRetrieveUsers(SMnodeMsg *pMsg, SShowObj *pShow, char *data, in
|
|||
cols++;
|
||||
|
||||
pWrite = data + pShow->offset[cols] * rows + pShow->bytes[cols] * numOfRows;
|
||||
if (pUser->superAuth) {
|
||||
if (pUser->superUser) {
|
||||
const char *src = "super";
|
||||
STR_WITH_SIZE_TO_VARSTR(pWrite, src, strlen(src));
|
||||
} else {
|
||||
|
@ -536,7 +486,7 @@ static int32_t mndRetrieveUsers(SMnodeMsg *pMsg, SShowObj *pShow, char *data, in
|
|||
sdbRelease(pSdb, pUser);
|
||||
}
|
||||
|
||||
mnodeVacuumResult(data, pShow->numOfColumns, numOfRows, rows, pShow);
|
||||
mndVacuumResult(data, pShow->numOfColumns, numOfRows, rows, pShow);
|
||||
pShow->numOfReads += numOfRows;
|
||||
return numOfRows;
|
||||
}
|
||||
|
|
|
@ -284,7 +284,7 @@ static int32_t mndRetrieveVgroups(SMnodeMsg *pMsg, SShowObj *pShow, char *data,
|
|||
numOfRows++;
|
||||
}
|
||||
|
||||
mnodeVacuumResult(data, pShow->numOfColumns, numOfRows, rows, pShow);
|
||||
mndVacuumResult(data, pShow->numOfColumns, numOfRows, rows, pShow);
|
||||
pShow->numOfReads += numOfRows;
|
||||
return numOfRows;
|
||||
}
|
||||
|
@ -374,7 +374,7 @@ static int32_t mndRetrieveVnodes(SMnodeMsg *pMsg, SShowObj *pShow, char *data, i
|
|||
sdbRelease(pSdb, pVgroup);
|
||||
}
|
||||
|
||||
mnodeVacuumResult(data, pShow->numOfColumns, numOfRows, rows, pShow);
|
||||
mndVacuumResult(data, pShow->numOfColumns, numOfRows, rows, pShow);
|
||||
pShow->numOfReads += numOfRows;
|
||||
return numOfRows;
|
||||
}
|
||||
|
|
|
@ -69,7 +69,7 @@ static void mndCleanupTimer(SMnode *pMnode) {
|
|||
}
|
||||
}
|
||||
|
||||
static int32_t mnodeCreateDir(SMnode *pMnode, const char *path) {
|
||||
static int32_t mndCreateDir(SMnode *pMnode, const char *path) {
|
||||
pMnode->path = strdup(path);
|
||||
if (pMnode->path == NULL) {
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
|
@ -245,7 +245,7 @@ SMnode *mndOpen(const char *path, const SMnodeOpt *pOption) {
|
|||
return NULL;
|
||||
}
|
||||
|
||||
int32_t code = mnodeCreateDir(pMnode, path);
|
||||
int32_t code = mndCreateDir(pMnode, path);
|
||||
if (code != 0) {
|
||||
code = terrno;
|
||||
mError("failed to open mnode since %s", terrstr());
|
||||
|
|
|
@ -59,6 +59,7 @@ typedef struct SSdb {
|
|||
char *tmpDir;
|
||||
int64_t lastCommitVer;
|
||||
int64_t curVer;
|
||||
int32_t maxId[SDB_MAX];
|
||||
EKeyType keyTypes[SDB_MAX];
|
||||
SHashObj *hashObjs[SDB_MAX];
|
||||
SRWLatch locks[SDB_MAX];
|
||||
|
|
|
@ -127,6 +127,7 @@ int32_t sdbSetTable(SSdb *pSdb, SSdbTable table) {
|
|||
return -1;
|
||||
}
|
||||
|
||||
pSdb->maxId[sdbType] = 0;
|
||||
pSdb->hashObjs[sdbType] = hash;
|
||||
taosInitRWLatch(&pSdb->locks[sdbType]);
|
||||
mDebug("sdb table:%d is initialized", sdbType);
|
||||
|
|
|
@ -72,6 +72,10 @@ static int32_t sdbInsertRow(SSdb *pSdb, SHashObj *hash, SSdbRaw *pRaw, SSdbRow *
|
|||
|
||||
taosWUnLockLatch(pLock);
|
||||
|
||||
if (pSdb->keyTypes[pRow->type] == SDB_KEY_INT32) {
|
||||
pSdb->maxId[pRow->type] = MAX(pSdb->maxId[pRow->type], *((int32_t *)pRow->pObj));
|
||||
}
|
||||
|
||||
SdbInsertFp insertFp = pSdb->insertFps[pRow->type];
|
||||
if (insertFp != NULL) {
|
||||
code = (*insertFp)(pSdb, pRow->pObj);
|
||||
|
@ -132,11 +136,6 @@ static int32_t sdbDeleteRow(SSdb *pSdb, SHashObj *hash, SSdbRaw *pRaw, SSdbRow *
|
|||
taosHashRemove(hash, pOldRow->pObj, keySize);
|
||||
taosWUnLockLatch(pLock);
|
||||
|
||||
SdbDeleteFp deleteFp = pSdb->deleteFps[pOldRow->type];
|
||||
if (deleteFp != NULL) {
|
||||
code = (*deleteFp)(pSdb, pOldRow->pObj);
|
||||
}
|
||||
|
||||
sdbRelease(pSdb, pOldRow->pObj);
|
||||
sdbFreeRow(pRow);
|
||||
return code;
|
||||
|
@ -161,6 +160,7 @@ int32_t sdbWriteNotFree(SSdb *pSdb, SSdbRaw *pRaw) {
|
|||
case SDB_STATUS_CREATING:
|
||||
code = sdbInsertRow(pSdb, hash, pRaw, pRow, keySize);
|
||||
break;
|
||||
case SDB_STATUS_UPDATING:
|
||||
case SDB_STATUS_READY:
|
||||
case SDB_STATUS_DROPPING:
|
||||
code = sdbUpdateRow(pSdb, hash, pRaw, pRow, keySize);
|
||||
|
@ -228,6 +228,11 @@ void sdbRelease(SSdb *pSdb, void *pObj) {
|
|||
|
||||
int32_t ref = atomic_sub_fetch_32(&pRow->refCount, 1);
|
||||
if (ref <= 0 && pRow->status == SDB_STATUS_DROPPED) {
|
||||
SdbDeleteFp deleteFp = pSdb->deleteFps[pRow->type];
|
||||
if (deleteFp != NULL) {
|
||||
(*deleteFp)(pSdb, pRow->pObj);
|
||||
}
|
||||
|
||||
sdbFreeRow(pRow);
|
||||
}
|
||||
|
||||
|
@ -289,3 +294,28 @@ int32_t sdbGetSize(SSdb *pSdb, ESdbType type) {
|
|||
|
||||
return size;
|
||||
}
|
||||
|
||||
int32_t sdbGetMaxId(SSdb *pSdb, ESdbType type) {
|
||||
SHashObj *hash = sdbGetHash(pSdb, type);
|
||||
if (hash == NULL) return -1;
|
||||
|
||||
if (pSdb->keyTypes[type] != SDB_KEY_INT32) return -1;
|
||||
|
||||
int32_t maxId = 0;
|
||||
|
||||
SRWLatch *pLock = &pSdb->locks[type];
|
||||
taosRLockLatch(pLock);
|
||||
|
||||
SSdbRow **ppRow = taosHashIterate(hash, NULL);
|
||||
while (ppRow != NULL) {
|
||||
SSdbRow *pRow = *ppRow;
|
||||
int32_t id = *(int32_t *)pRow->pObj;
|
||||
maxId = MAX(id, maxId);
|
||||
ppRow = taosHashIterate(hash, ppRow);
|
||||
}
|
||||
|
||||
taosRUnLockLatch(pLock);
|
||||
|
||||
maxId = MAX(maxId, pSdb->maxId[type]);
|
||||
return maxId + 1;
|
||||
}
|
||||
|
|
|
@ -27,6 +27,8 @@ typedef struct SVBufPool SVBufPool;
|
|||
|
||||
int vnodeOpenBufPool(SVnode *pVnode);
|
||||
void vnodeCloseBufPool(SVnode *pVnode);
|
||||
int vnodeBufPoolSwitch(SVnode *pVnode);
|
||||
int vnodeBufPoolRecycle(SVnode *pVnode);
|
||||
void *vnodeMalloc(SVnode *pVnode, uint64_t size);
|
||||
bool vnodeBufPoolIsFull(SVnode *pVnode);
|
||||
|
||||
|
|
|
@ -24,6 +24,7 @@ extern "C" {
|
|||
|
||||
#define vnodeShouldCommit vnodeBufPoolIsFull
|
||||
int vnodeAsyncCommit(SVnode *pVnode);
|
||||
int vnodeCommit(void *arg);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
|
|
@ -21,9 +21,11 @@
|
|||
#include "tcoding.h"
|
||||
#include "tdlist.h"
|
||||
#include "tlockfree.h"
|
||||
#include "tmacro.h"
|
||||
#include "wal.h"
|
||||
|
||||
#include "vnode.h"
|
||||
|
||||
#include "vnodeBufferPool.h"
|
||||
#include "vnodeCfg.h"
|
||||
#include "vnodeCommit.h"
|
||||
|
@ -37,6 +39,27 @@
|
|||
extern "C" {
|
||||
#endif
|
||||
|
||||
typedef struct SVnodeTask {
|
||||
TD_DLIST_NODE(SVnodeTask);
|
||||
void* arg;
|
||||
int (*execute)(void*);
|
||||
} SVnodeTask;
|
||||
|
||||
typedef struct SVnodeMgr {
|
||||
td_mode_flag_t vnodeInitFlag;
|
||||
td_mode_flag_t vnodeClearFlag;
|
||||
// For commit
|
||||
bool stop;
|
||||
uint16_t nthreads;
|
||||
pthread_t* threads;
|
||||
pthread_mutex_t mutex;
|
||||
pthread_cond_t hasTask;
|
||||
TD_DLIST(SVnodeTask) queue;
|
||||
// For vnode Mgmt
|
||||
} SVnodeMgr;
|
||||
|
||||
extern SVnodeMgr vnodeMgr;
|
||||
|
||||
struct SVnode {
|
||||
char* path;
|
||||
SVnodeCfg config;
|
||||
|
@ -50,6 +73,8 @@ struct SVnode {
|
|||
SVnodeFS* pFs;
|
||||
};
|
||||
|
||||
int vnodeScheduleTask(SVnodeTask* task);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
|
|
@ -33,6 +33,7 @@ struct SVArenaNode {
|
|||
};
|
||||
|
||||
struct SVMemAllocator {
|
||||
T_REF_DECLARE()
|
||||
TD_DLIST_NODE(SVMemAllocator);
|
||||
uint64_t capacity;
|
||||
uint64_t ssize;
|
||||
|
|
|
@ -19,6 +19,8 @@
|
|||
#define VNODE_BUF_POOL_SHARDS 3
|
||||
|
||||
struct SVBufPool {
|
||||
pthread_mutex_t mutex;
|
||||
pthread_cond_t hasFree;
|
||||
TD_DLIST(SVMemAllocator) free;
|
||||
TD_DLIST(SVMemAllocator) incycle;
|
||||
SVMemAllocator *inuse;
|
||||
|
@ -28,7 +30,6 @@ struct SVBufPool {
|
|||
|
||||
int vnodeOpenBufPool(SVnode *pVnode) {
|
||||
uint64_t capacity;
|
||||
// EVMemAllocatorT type = E_V_ARENA_ALLOCATOR;
|
||||
|
||||
if ((pVnode->pBufPool = (SVBufPool *)calloc(1, sizeof(SVBufPool))) == NULL) {
|
||||
/* TODO */
|
||||
|
@ -79,6 +80,27 @@ void vnodeCloseBufPool(SVnode *pVnode) {
|
|||
}
|
||||
}
|
||||
|
||||
int vnodeBufPoolSwitch(SVnode *pVnode) {
|
||||
SVMemAllocator *pvma = pVnode->pBufPool->inuse;
|
||||
|
||||
pVnode->pBufPool->inuse = NULL;
|
||||
|
||||
tDListAppend(&(pVnode->pBufPool->incycle), pvma);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int vnodeBufPoolRecycle(SVnode *pVnode) {
|
||||
SVBufPool * pBufPool = pVnode->pBufPool;
|
||||
SVMemAllocator *pvma = TD_DLIST_HEAD(&(pBufPool->incycle));
|
||||
ASSERT(pvma != NULL);
|
||||
|
||||
tDListPop(&(pBufPool->incycle), pvma);
|
||||
vmaReset(pvma);
|
||||
tDListAppend(&(pBufPool->free), pvma);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void *vnodeMalloc(SVnode *pVnode, uint64_t size) {
|
||||
SVBufPool *pBufPool = pVnode->pBufPool;
|
||||
|
||||
|
@ -89,6 +111,8 @@ void *vnodeMalloc(SVnode *pVnode, uint64_t size) {
|
|||
if (pBufPool->inuse) {
|
||||
tDListPop(&(pBufPool->free), pBufPool->inuse);
|
||||
break;
|
||||
} else {
|
||||
// tsem_wait(&(pBufPool->hasFree));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -15,7 +15,8 @@
|
|||
|
||||
#include "vnodeDef.h"
|
||||
|
||||
const SVnodeCfg defaultVnodeOptions = {.wsize = 16 * 1024 * 1024, .walCfg = {.level = TAOS_WAL_WRITE}}; /* TODO */
|
||||
const SVnodeCfg defaultVnodeOptions = {
|
||||
.wsize = 96 * 1024 * 1024, .ssize = 1 * 1024 * 1024, .lsize = 1024, .walCfg = {.level = TAOS_WAL_WRITE}}; /* TODO */
|
||||
|
||||
void vnodeOptionsInit(SVnodeCfg *pVnodeOptions) { /* TODO */
|
||||
vnodeOptionsCopy(pVnodeOptions, &defaultVnodeOptions);
|
||||
|
|
|
@ -19,28 +19,21 @@ static int vnodeStartCommit(SVnode *pVnode);
|
|||
static int vnodeEndCommit(SVnode *pVnode);
|
||||
|
||||
int vnodeAsyncCommit(SVnode *pVnode) {
|
||||
#if 0
|
||||
if (vnodeStartCommit(pVnode) < 0) {
|
||||
// TODO
|
||||
}
|
||||
vnodeBufPoolSwitch(pVnode);
|
||||
SVnodeTask *pTask = (SVnodeTask *)malloc(sizeof(*pTask));
|
||||
|
||||
if (tqCommit(pVnode->pTQ) < 0) {
|
||||
// TODO
|
||||
}
|
||||
pTask->execute = vnodeCommit; // TODO
|
||||
pTask->arg = pVnode; // TODO
|
||||
|
||||
if (metaCommit(pVnode->pMeta) < 0) {
|
||||
// TODO
|
||||
}
|
||||
vnodeScheduleTask(pTask);
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (tsdbCommit(pVnode->pTsdb) < 0) {
|
||||
// TODO
|
||||
}
|
||||
int vnodeCommit(void *arg) {
|
||||
SVnode *pVnode = (SVnode *)arg;
|
||||
|
||||
if (vnodeEndCommit(pVnode) < 0) {
|
||||
// TODO
|
||||
}
|
||||
|
||||
#endif
|
||||
vnodeBufPoolRecycle(pVnode);
|
||||
// TODO
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
|
@ -13,7 +13,6 @@
|
|||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "tmacro.h"
|
||||
#include "vnodeDef.h"
|
||||
|
||||
static SVnode *vnodeNew(const char *path, const SVnodeCfg *pVnodeCfg);
|
||||
|
@ -21,29 +20,6 @@ static void vnodeFree(SVnode *pVnode);
|
|||
static int vnodeOpenImpl(SVnode *pVnode);
|
||||
static void vnodeCloseImpl(SVnode *pVnode);
|
||||
|
||||
TD_DEF_MOD_INIT_FLAG(vnode);
|
||||
TD_DEF_MOD_CLEAR_FLAG(vnode);
|
||||
|
||||
int vnodeInit() {
|
||||
if (TD_CHECK_AND_SET_MODE_INIT(vnode) == TD_MOD_INITIALIZED) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (walInit() < 0) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void vnodeClear() {
|
||||
if (TD_CHECK_AND_SET_MOD_CLEAR(vnode) == TD_MOD_CLEARD) {
|
||||
return;
|
||||
}
|
||||
|
||||
walCleanUp();
|
||||
}
|
||||
|
||||
SVnode *vnodeOpen(const char *path, const SVnodeCfg *pVnodeCfg) {
|
||||
SVnode *pVnode = NULL;
|
||||
|
||||
|
|
|
@ -0,0 +1,115 @@
|
|||
/*
|
||||
* 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/>.
|
||||
*/
|
||||
|
||||
#include "vnodeDef.h"
|
||||
|
||||
SVnodeMgr vnodeMgr = {.vnodeInitFlag = TD_MOD_UNINITIALIZED, .vnodeClearFlag = TD_MOD_UNCLEARD, .stop = false};
|
||||
|
||||
static void* loop(void* arg);
|
||||
|
||||
int vnodeInit(uint16_t nthreads) {
|
||||
if (TD_CHECK_AND_SET_MODE_INIT(&(vnodeMgr.vnodeInitFlag)) == TD_MOD_INITIALIZED) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
// Start commit handers
|
||||
if (nthreads > 0) {
|
||||
vnodeMgr.nthreads = nthreads;
|
||||
vnodeMgr.threads = (pthread_t*)calloc(nthreads, sizeof(pthread_t));
|
||||
if (vnodeMgr.threads == NULL) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
pthread_mutex_init(&(vnodeMgr.mutex), NULL);
|
||||
pthread_cond_init(&(vnodeMgr.hasTask), NULL);
|
||||
tDListInit(&(vnodeMgr.queue));
|
||||
|
||||
for (uint16_t i = 0; i < nthreads; i++) {
|
||||
pthread_create(&(vnodeMgr.threads[i]), NULL, loop, NULL);
|
||||
}
|
||||
} else {
|
||||
// TODO: if no commit thread is set, then another mechanism should be
|
||||
// given. Otherwise, it is a false.
|
||||
ASSERT(0);
|
||||
}
|
||||
|
||||
if (walInit() < 0) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void vnodeClear() {
|
||||
if (TD_CHECK_AND_SET_MOD_CLEAR(&(vnodeMgr.vnodeClearFlag)) == TD_MOD_CLEARD) {
|
||||
return;
|
||||
}
|
||||
|
||||
walCleanUp();
|
||||
|
||||
// Stop commit handler
|
||||
pthread_mutex_lock(&(vnodeMgr.mutex));
|
||||
vnodeMgr.stop = true;
|
||||
pthread_cond_broadcast(&(vnodeMgr.hasTask));
|
||||
pthread_mutex_unlock(&(vnodeMgr.mutex));
|
||||
|
||||
for (uint16_t i = 0; i < vnodeMgr.nthreads; i++) {
|
||||
pthread_join(vnodeMgr.threads[i], NULL);
|
||||
}
|
||||
|
||||
tfree(vnodeMgr.threads);
|
||||
pthread_cond_destroy(&(vnodeMgr.hasTask));
|
||||
pthread_mutex_destroy(&(vnodeMgr.mutex));
|
||||
}
|
||||
|
||||
int vnodeScheduleTask(SVnodeTask* pTask) {
|
||||
pthread_mutex_lock(&(vnodeMgr.mutex));
|
||||
|
||||
tDListAppend(&(vnodeMgr.queue), pTask);
|
||||
|
||||
pthread_cond_signal(&(vnodeMgr.hasTask));
|
||||
|
||||
pthread_mutex_unlock(&(vnodeMgr.mutex));
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* ------------------------ STATIC METHODS ------------------------ */
|
||||
static void* loop(void* arg) {
|
||||
SVnodeTask* pTask;
|
||||
for (;;) {
|
||||
pthread_mutex_lock(&(vnodeMgr.mutex));
|
||||
for (;;) {
|
||||
pTask = TD_DLIST_HEAD(&(vnodeMgr.queue));
|
||||
if (pTask == NULL) {
|
||||
if (vnodeMgr.stop) {
|
||||
pthread_mutex_unlock(&(vnodeMgr.mutex));
|
||||
return NULL;
|
||||
} else {
|
||||
pthread_cond_wait(&(vnodeMgr.hasTask), &(vnodeMgr.mutex));
|
||||
}
|
||||
} else {
|
||||
tDListPop(&(vnodeMgr.queue), pTask);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
pthread_mutex_unlock(&(vnodeMgr.mutex));
|
||||
|
||||
(*(pTask->execute))(pTask->arg);
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
|
@ -72,7 +72,9 @@ int vnodeProcessWMsgs(SVnode *pVnode, SArray *pMsgs) {
|
|||
}
|
||||
break;
|
||||
case TSDB_MSG_TYPE_SUBMIT:
|
||||
/* code */
|
||||
if (tsdbInsertData(pVnode->pTsdb, (SSubmitMsg *)ptr) < 0) {
|
||||
// TODO: handle error
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
|
|
|
@ -92,7 +92,9 @@ TEST(vnodeApiTest, test_create_table_encode_and_decode_function) {
|
|||
#endif
|
||||
|
||||
TEST(vnodeApiTest, vnodeOpen_vnodeClose_test) {
|
||||
GTEST_ASSERT_GE(vnodeInit(), 0);
|
||||
vnodeDestroy("vnode1");
|
||||
|
||||
GTEST_ASSERT_GE(vnodeInit(2), 0);
|
||||
|
||||
// Create and open a vnode
|
||||
SVnode *pVnode = vnodeOpen("vnode1", NULL);
|
||||
|
|
|
@ -17,6 +17,10 @@
|
|||
#define _TD_TSDB_DEF_H_
|
||||
|
||||
#include "mallocator.h"
|
||||
#include "taosmsg.h"
|
||||
#include "tdlist.h"
|
||||
#include "thash.h"
|
||||
#include "tskiplist.h"
|
||||
|
||||
#include "tsdb.h"
|
||||
#include "tsdbMemTable.h"
|
||||
|
@ -29,6 +33,8 @@ extern "C" {
|
|||
struct STsdb {
|
||||
char * path;
|
||||
STsdbCfg options;
|
||||
STsdbMemTable * mem;
|
||||
STsdbMemTable * imem;
|
||||
SMemAllocatorFactory *pmaf;
|
||||
};
|
||||
|
||||
|
|
|
@ -22,10 +22,11 @@
|
|||
extern "C" {
|
||||
#endif
|
||||
|
||||
typedef struct SMemTable {
|
||||
/* TODO */
|
||||
SMemAllocator *pma;
|
||||
} SMemTable;
|
||||
typedef struct STsdbMemTable STsdbMemTable;
|
||||
|
||||
STsdbMemTable *tsdbNewMemTable(SMemAllocatorFactory *pMAF);
|
||||
void tsdbFreeMemTable(SMemAllocatorFactory *pMAF, STsdbMemTable *pMemTable);
|
||||
int tsdbInsertDataToMemTable(STsdbMemTable *pMemTable, SSubmitMsg *pMsg);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
|
|
@ -13,11 +13,9 @@
|
|||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef _TD_TSDB_COMMIT_QUEUE_H_
|
||||
#define _TD_TSDB_COMMIT_QUEUE_H_
|
||||
#include "tsdbDef.h"
|
||||
|
||||
typedef enum { COMMIT_REQ, COMPACT_REQ,COMMIT_CONFIG_REQ } TSDB_REQ_T;
|
||||
|
||||
int tsdbScheduleCommit(STsdbRepo *pRepo, TSDB_REQ_T req);
|
||||
|
||||
#endif /* _TD_TSDB_COMMIT_QUEUE_H_ */
|
||||
int tsdbCommit(STsdb *pTsdb) {
|
||||
// TODO
|
||||
return 0;
|
||||
}
|
|
@ -11,4 +11,84 @@
|
|||
*
|
||||
* 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/>.
|
||||
*/
|
||||
*/
|
||||
|
||||
#include "tsdbDef.h"
|
||||
|
||||
#if 1
|
||||
typedef struct STbData {
|
||||
TD_SLIST_NODE(STbData);
|
||||
SSubmitMsg *pMsg;
|
||||
} STbData;
|
||||
#else
|
||||
typedef struct STbData {
|
||||
TD_SLIST_NODE(STbData);
|
||||
uint64_t uid; // TODO: change here as tb_uid_t
|
||||
TSKEY keyMin;
|
||||
TSKEY keyMax;
|
||||
uint64_t nRows;
|
||||
SSkipList *pData; // Here need a container, may not use the SL
|
||||
T_REF_DECLARE()
|
||||
} STbData;
|
||||
#endif
|
||||
|
||||
struct STsdbMemTable {
|
||||
T_REF_DECLARE()
|
||||
SRWLatch latch;
|
||||
TSKEY keyMin;
|
||||
TSKEY keyMax;
|
||||
uint64_t nRow;
|
||||
SMemAllocator *pMA;
|
||||
// Container
|
||||
TD_SLIST(STbData) list;
|
||||
};
|
||||
|
||||
STsdbMemTable *tsdbNewMemTable(SMemAllocatorFactory *pMAF) {
|
||||
STsdbMemTable *pMemTable;
|
||||
SMemAllocator *pMA;
|
||||
|
||||
pMA = (*pMAF->create)(pMAF);
|
||||
ASSERT(pMA != NULL);
|
||||
|
||||
pMemTable = (STsdbMemTable *)((*pMA->malloc)(pMA, sizeof(*pMemTable)));
|
||||
if (pMemTable == NULL) {
|
||||
(*pMAF->destroy)(pMAF, pMA);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
T_REF_INIT_VAL(pMemTable, 1);
|
||||
taosInitRWLatch(&(pMemTable->latch));
|
||||
pMemTable->keyMin = TSKEY_MAX;
|
||||
pMemTable->keyMax = TSKEY_MIN;
|
||||
pMemTable->nRow = 0;
|
||||
pMemTable->pMA = pMA;
|
||||
tSListInit(&(pMemTable->list));
|
||||
|
||||
// TODO
|
||||
return pMemTable;
|
||||
}
|
||||
|
||||
void tsdbFreeMemTable(SMemAllocatorFactory *pMAF, STsdbMemTable *pMemTable) {
|
||||
SMemAllocator *pMA = pMemTable->pMA;
|
||||
|
||||
if (pMA->free) {
|
||||
// TODO
|
||||
ASSERT(0);
|
||||
}
|
||||
|
||||
(*pMAF->destroy)(pMAF, pMA);
|
||||
}
|
||||
|
||||
int tsdbInsertDataToMemTable(STsdbMemTable *pMemTable, SSubmitMsg *pMsg) {
|
||||
SMemAllocator *pMA = pMemTable->pMA;
|
||||
STbData * pTbData = (STbData *)((*pMA->malloc)(pMA, sizeof(*pTbData)));
|
||||
if (pTbData == NULL) {
|
||||
// TODO
|
||||
}
|
||||
|
||||
tSListPush(&(pMemTable->list), pTbData);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* ------------------------ STATIC METHODS ------------------------ */
|
|
@ -0,0 +1,25 @@
|
|||
/*
|
||||
* 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/>.
|
||||
*/
|
||||
|
||||
#include "tsdbDef.h"
|
||||
|
||||
int tsdbInsertData(STsdb *pTsdb, SSubmitMsg *pMsg) {
|
||||
// Check if mem is there. If not, create one.
|
||||
pTsdb->mem = tsdbNewMemTable(pTsdb->pmaf);
|
||||
if (pTsdb->mem == NULL) {
|
||||
return -1;
|
||||
}
|
||||
return tsdbInsertDataToMemTable(pTsdb->mem, pMsg);
|
||||
}
|
|
@ -9,4 +9,5 @@ add_subdirectory(cache)
|
|||
add_subdirectory(catalog)
|
||||
add_subdirectory(executor)
|
||||
add_subdirectory(planner)
|
||||
add_subdirectory(function)
|
||||
add_subdirectory(function)
|
||||
add_subdirectory(query)
|
||||
|
|
|
@ -8,5 +8,5 @@ target_include_directories(
|
|||
|
||||
target_link_libraries(
|
||||
catalog
|
||||
PRIVATE os util common transport
|
||||
)
|
||||
PRIVATE os util common transport query
|
||||
)
|
||||
|
|
|
@ -21,14 +21,59 @@ extern "C" {
|
|||
#endif
|
||||
|
||||
#include "catalog.h"
|
||||
#include "common.h"
|
||||
#include "tlog.h"
|
||||
|
||||
#define CTG_DEFAULT_CLUSTER_NUMBER 6
|
||||
#define CTG_DEFAULT_VGROUP_NUMBER 100
|
||||
#define CTG_DEFAULT_DB_NUMBER 20
|
||||
|
||||
#define CTG_DEFAULT_INVALID_VERSION (-1)
|
||||
|
||||
typedef struct SVgroupListCache {
|
||||
int32_t vgroupVersion;
|
||||
SHashObj *cache; // key:vgId, value:SVgroupInfo*
|
||||
SArray *arrayCache; // SVgroupInfo
|
||||
} SVgroupListCache;
|
||||
|
||||
typedef struct SDBVgroupCache {
|
||||
SHashObj *cache; //key:dbname, value:SDBVgroupInfo
|
||||
} SDBVgroupCache;
|
||||
|
||||
typedef struct STableMetaCache {
|
||||
SHashObj *cache; //key:fulltablename, value:STableMeta
|
||||
} STableMetaCache;
|
||||
|
||||
typedef struct SCatalog {
|
||||
void *pMsgSender; // used to send messsage to mnode to fetch necessary metadata
|
||||
SHashObj *pData; // items cached for each cluster, the hash key is the cluster-id, returned by mgmt node
|
||||
SVgroupListCache vgroupCache;
|
||||
SDBVgroupCache dbCache;
|
||||
STableMetaCache tableCache;
|
||||
} SCatalog;
|
||||
|
||||
typedef struct SCatalogMgmt {
|
||||
void *pMsgSender; // used to send messsage to mnode to fetch necessary metadata
|
||||
SHashObj *pCluster; // items cached for each cluster, the hash key is the cluster-id got from mgmt node
|
||||
} SCatalogMgmt;
|
||||
|
||||
|
||||
extern int32_t ctgDebugFlag;
|
||||
|
||||
#define ctgFatal(...) do { if (ctgDebugFlag & DEBUG_FATAL) { taosPrintLog("CTG FATAL ", ctgDebugFlag, __VA_ARGS__); }} while(0)
|
||||
#define ctgError(...) do { if (ctgDebugFlag & DEBUG_ERROR) { taosPrintLog("CTG ERROR ", ctgDebugFlag, __VA_ARGS__); }} while(0)
|
||||
#define ctgWarn(...) do { if (ctgDebugFlag & DEBUG_WARN) { taosPrintLog("CTG WARN ", ctgDebugFlag, __VA_ARGS__); }} while(0)
|
||||
#define ctgInfo(...) do { if (ctgDebugFlag & DEBUG_INFO) { taosPrintLog("CTG ", ctgDebugFlag, __VA_ARGS__); }} while(0)
|
||||
#define ctgDebug(...) do { if (ctgDebugFlag & DEBUG_DEBUG) { taosPrintLog("CTG ", ctgDebugFlag, __VA_ARGS__); }} while(0)
|
||||
#define ctgTrace(...) do { if (ctgDebugFlag & DEBUG_TRACE) { taosPrintLog("CTG ", ctgDebugFlag, __VA_ARGS__); }} while(0)
|
||||
#define ctgDebugL(...) do { if (ctgDebugFlag & DEBUG_DEBUG) { taosPrintLongString("CTG ", ctgDebugFlag, __VA_ARGS__); }} while(0)
|
||||
|
||||
|
||||
#define CTG_ERR_RET(c) do { int32_t _code = c; if (_code != TSDB_CODE_SUCCESS) { return _code; } } while (0)
|
||||
#define CTG_ERR_LRET(c,...) do { int32_t _code = c; if (_code != TSDB_CODE_SUCCESS) { ctgError(__VA_ARGS__); return _code; } } while (0)
|
||||
#define CTG_ERR_JRET(c) do { code = c; if (code != TSDB_CODE_SUCCESS) { goto _return; } } while (0)
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /*_TD_CATALOG_INT_H_*/
|
||||
#endif /*_TD_CATALOG_INT_H_*/
|
||||
|
|
|
@ -14,11 +14,429 @@
|
|||
*/
|
||||
|
||||
#include "catalogInt.h"
|
||||
#include "trpc.h"
|
||||
#include "query.h"
|
||||
|
||||
struct SCatalog* getCatalogHandle(const SEpSet* pMgmtEps) {
|
||||
return (struct SCatalog*) 0x1;
|
||||
SCatalogMgmt ctgMgmt = {0};
|
||||
|
||||
int32_t ctgGetVgroupFromMnode(struct SCatalog* pCatalog, void *pRpc, const SEpSet* pMgmtEps, SVgroupListInfo** pVgroup) {
|
||||
char *msg = NULL;
|
||||
SEpSet *pVnodeEpSet = NULL;
|
||||
int32_t msgLen = 0;
|
||||
|
||||
int32_t code = queryBuildMsg[TSDB_MSG_TYPE_VGROUP_LIST](NULL, &msg, 0, &msgLen);
|
||||
if (code) {
|
||||
return code;
|
||||
}
|
||||
|
||||
SRpcMsg rpcMsg = {
|
||||
.msgType = TSDB_MSG_TYPE_VGROUP_LIST,
|
||||
.pCont = msg,
|
||||
.contLen = msgLen,
|
||||
};
|
||||
|
||||
SRpcMsg rpcRsp = {0};
|
||||
|
||||
rpcSendRecv(pRpc, (SEpSet*)pMgmtEps, &rpcMsg, &rpcRsp);
|
||||
|
||||
code = queryProcessMsgRsp[TSDB_MSG_TYPE_VGROUP_LIST](pVgroup, rpcRsp.pCont, rpcRsp.contLen);
|
||||
if (code) {
|
||||
return code;
|
||||
}
|
||||
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
int32_t catalogGetMetaData(struct SCatalog* pCatalog, const SMetaReq* pMetaReq, SMetaData* pMetaData) {
|
||||
int32_t ctgGetVgroupFromCache(SCatalog* pCatalog, SArray** pVgroupList, int32_t* exist) {
|
||||
if (NULL == pCatalog->vgroupCache.arrayCache || pCatalog->vgroupCache.vgroupVersion < 0) {
|
||||
*exist = 0;
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
if (pVgroupList) {
|
||||
*pVgroupList = taosArrayDup(pCatalog->vgroupCache.arrayCache);
|
||||
}
|
||||
|
||||
*exist = 1;
|
||||
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
int32_t ctgGetDBVgroupFromCache(SCatalog* pCatalog, const char *dbName, SDBVgroupInfo **dbInfo, int32_t *exist) {
|
||||
if (NULL == pCatalog->dbCache.cache) {
|
||||
*exist = 0;
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
SDBVgroupInfo *info = taosHashGet(pCatalog->dbCache.cache, dbName, strlen(dbName));
|
||||
|
||||
if (NULL == info || info->vgroupVersion < pCatalog->vgroupCache.vgroupVersion) {
|
||||
*exist = 0;
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
if (dbInfo) {
|
||||
*dbInfo = calloc(1, sizeof(**dbInfo));
|
||||
if (NULL == *dbInfo) {
|
||||
ctgError("calloc size[%d] failed", (int32_t)sizeof(**dbInfo));
|
||||
return TSDB_CODE_CTG_MEM_ERROR;
|
||||
}
|
||||
|
||||
(*dbInfo)->vgId = taosArrayDup(info->vgId);
|
||||
if (NULL == (*dbInfo)->vgId) {
|
||||
ctgError("taos array duplicate failed");
|
||||
tfree(*dbInfo);
|
||||
return TSDB_CODE_CTG_MEM_ERROR;
|
||||
}
|
||||
|
||||
(*dbInfo)->vgroupVersion = info->vgroupVersion;
|
||||
(*dbInfo)->hashRange = info->hashRange;
|
||||
}
|
||||
|
||||
*exist = 1;
|
||||
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
|
||||
int32_t ctgGetDBVgroupFromMnode(struct SCatalog* pCatalog, void *pRpc, const SEpSet* pMgmtEps, SBuildUseDBInput *input, SUseDbOutput *out) {
|
||||
char *msg = NULL;
|
||||
SEpSet *pVnodeEpSet = NULL;
|
||||
int32_t msgLen = 0;
|
||||
|
||||
int32_t code = queryBuildMsg[TSDB_MSG_TYPE_USE_DB](input, &msg, 0, &msgLen);
|
||||
if (code) {
|
||||
return code;
|
||||
}
|
||||
|
||||
SRpcMsg rpcMsg = {
|
||||
.msgType = TSDB_MSG_TYPE_USE_DB,
|
||||
.pCont = msg,
|
||||
.contLen = msgLen,
|
||||
};
|
||||
|
||||
SRpcMsg rpcRsp = {0};
|
||||
|
||||
rpcSendRecv(pRpc, (SEpSet*)pMgmtEps, &rpcMsg, &rpcRsp);
|
||||
|
||||
code = queryProcessMsgRsp[TSDB_MSG_TYPE_USE_DB](out, rpcRsp.pCont, rpcRsp.contLen);
|
||||
if (code) {
|
||||
return code;
|
||||
}
|
||||
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
int32_t catalogInit(SCatalogCfg *cfg) {
|
||||
ctgMgmt.pCluster = taosHashInit(CTG_DEFAULT_CLUSTER_NUMBER, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BINARY), true, HASH_ENTRY_LOCK);
|
||||
if (NULL == ctgMgmt.pCluster) {
|
||||
CTG_ERR_LRET(TSDB_CODE_CTG_INTERNAL_ERROR, "init %d cluster cache failed", CTG_DEFAULT_CLUSTER_NUMBER);
|
||||
}
|
||||
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
int32_t catalogGetHandle(const char *clusterId, struct SCatalog** catalogHandle) {
|
||||
if (NULL == clusterId || NULL == catalogHandle) {
|
||||
return TSDB_CODE_CTG_INVALID_INPUT;
|
||||
}
|
||||
|
||||
if (NULL == ctgMgmt.pCluster) {
|
||||
ctgError("cluster cache are not ready");
|
||||
return TSDB_CODE_CTG_NOT_READY;
|
||||
}
|
||||
|
||||
size_t clen = strlen(clusterId);
|
||||
SCatalog *clusterCtg = (SCatalog *)taosHashGet(ctgMgmt.pCluster, clusterId, clen);
|
||||
|
||||
if (clusterCtg) {
|
||||
*catalogHandle = clusterCtg;
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
clusterCtg = calloc(1, sizeof(*clusterCtg));
|
||||
if (NULL == clusterCtg) {
|
||||
ctgError("calloc %d failed", (int32_t)sizeof(*clusterCtg));
|
||||
return TSDB_CODE_CTG_MEM_ERROR;
|
||||
}
|
||||
|
||||
clusterCtg->vgroupCache.vgroupVersion = CTG_DEFAULT_INVALID_VERSION;
|
||||
|
||||
if (taosHashPut(ctgMgmt.pCluster, clusterId, clen, &clusterCtg, POINTER_BYTES)) {
|
||||
ctgError("put cluster %s cache to hash failed", clusterId);
|
||||
tfree(clusterCtg);
|
||||
return TSDB_CODE_CTG_INTERNAL_ERROR;
|
||||
}
|
||||
|
||||
*catalogHandle = clusterCtg;
|
||||
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
int32_t catalogGetVgroupVersion(struct SCatalog* pCatalog, int32_t* version) {
|
||||
if (NULL == pCatalog || NULL == version) {
|
||||
return TSDB_CODE_CTG_INVALID_INPUT;
|
||||
}
|
||||
|
||||
*version = pCatalog->vgroupCache.vgroupVersion;
|
||||
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
|
||||
int32_t catalogUpdateVgroup(struct SCatalog* pCatalog, SVgroupListInfo* pVgroup) {
|
||||
if (NULL == pVgroup) {
|
||||
ctgError("no valid vgroup list info to update");
|
||||
return TSDB_CODE_CTG_INTERNAL_ERROR;
|
||||
}
|
||||
|
||||
if (pVgroup->vgroupVersion < 0) {
|
||||
ctgError("vgroup version[%d] is invalid", pVgroup->vgroupVersion);
|
||||
return TSDB_CODE_CTG_INVALID_INPUT;
|
||||
}
|
||||
|
||||
|
||||
if (NULL == pCatalog->vgroupCache.arrayCache) {
|
||||
pCatalog->vgroupCache.arrayCache = taosArrayInit(pVgroup->vgroupNum, sizeof(pVgroup->vgroupInfo[0]));
|
||||
if (NULL == pCatalog->vgroupCache.arrayCache) {
|
||||
ctgError("init array[%d] for cluster cache failed", pVgroup->vgroupNum);
|
||||
return TSDB_CODE_CTG_MEM_ERROR;
|
||||
}
|
||||
} else {
|
||||
taosArrayClear(pCatalog->vgroupCache.arrayCache);
|
||||
}
|
||||
|
||||
if (NULL == pCatalog->vgroupCache.cache) {
|
||||
pCatalog->vgroupCache.cache = taosHashInit(CTG_DEFAULT_VGROUP_NUMBER, taosGetDefaultHashFunction(TSDB_DATA_TYPE_INT), true, HASH_ENTRY_LOCK);
|
||||
if (NULL == pCatalog->vgroupCache.cache) {
|
||||
ctgError("init hash[%d] for cluster cache failed", CTG_DEFAULT_VGROUP_NUMBER);
|
||||
return TSDB_CODE_CTG_MEM_ERROR;
|
||||
}
|
||||
} else {
|
||||
taosHashClear(pCatalog->vgroupCache.cache);
|
||||
}
|
||||
|
||||
SVgroupInfo *vInfo = NULL;
|
||||
for (int32_t i = 0; i < pVgroup->vgroupNum; ++i) {
|
||||
vInfo = taosArrayPush(pCatalog->vgroupCache.arrayCache, &pVgroup->vgroupInfo[i]);
|
||||
if (NULL == vInfo) {
|
||||
ctgError("push to vgroup array cache failed");
|
||||
goto error_exit;
|
||||
}
|
||||
|
||||
if (taosHashPut(pCatalog->vgroupCache.cache, &pVgroup->vgroupInfo[i].vgId, sizeof(pVgroup->vgroupInfo[i].vgId), &vInfo, POINTER_BYTES) != 0) {
|
||||
ctgError("push to vgroup hash cache failed");
|
||||
goto error_exit;
|
||||
}
|
||||
}
|
||||
|
||||
pCatalog->vgroupCache.vgroupVersion = pVgroup->vgroupVersion;
|
||||
|
||||
return TSDB_CODE_SUCCESS;
|
||||
|
||||
error_exit:
|
||||
if (pCatalog->vgroupCache.arrayCache) {
|
||||
taosArrayDestroy(pCatalog->vgroupCache.arrayCache);
|
||||
pCatalog->vgroupCache.arrayCache = NULL;
|
||||
}
|
||||
|
||||
if (pCatalog->vgroupCache.cache) {
|
||||
taosHashCleanup(pCatalog->vgroupCache.cache);
|
||||
pCatalog->vgroupCache.cache = NULL;
|
||||
}
|
||||
|
||||
pCatalog->vgroupCache.vgroupVersion = CTG_DEFAULT_INVALID_VERSION;
|
||||
|
||||
return TSDB_CODE_CTG_INTERNAL_ERROR;
|
||||
}
|
||||
|
||||
|
||||
int32_t catalogGetVgroup(SCatalog* pCatalog, void *pRpc, const SEpSet* pMgmtEps, SArray** pVgroupList) {
|
||||
if (NULL == pCatalog || NULL == pMgmtEps || NULL == pRpc) {
|
||||
return TSDB_CODE_CTG_INVALID_INPUT;
|
||||
}
|
||||
|
||||
int32_t exist = 0;
|
||||
|
||||
CTG_ERR_RET(ctgGetVgroupFromCache(pCatalog, pVgroupList, &exist));
|
||||
|
||||
if (exist) {
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
SVgroupListInfo *pVgroup = NULL;
|
||||
|
||||
CTG_ERR_RET(ctgGetVgroupFromMnode(pCatalog, pRpc, pMgmtEps, &pVgroup));
|
||||
|
||||
CTG_ERR_RET(catalogUpdateVgroup(pCatalog, pVgroup));
|
||||
|
||||
if (pVgroupList) {
|
||||
CTG_ERR_RET(ctgGetVgroupFromCache(pCatalog, pVgroupList, &exist));
|
||||
}
|
||||
|
||||
if (0 == exist) {
|
||||
ctgError("catalog fetched but get from cache failed");
|
||||
return TSDB_CODE_CTG_INTERNAL_ERROR;
|
||||
}
|
||||
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
int32_t catalogGetDBVgroupVersion(struct SCatalog* pCatalog, const char* dbName, int32_t* version) {
|
||||
if (NULL == pCatalog || NULL == dbName || NULL == version) {
|
||||
return TSDB_CODE_CTG_INVALID_INPUT;
|
||||
}
|
||||
|
||||
if (NULL == pCatalog->dbCache.cache) {
|
||||
*version = CTG_DEFAULT_INVALID_VERSION;
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
SDBVgroupInfo * dbInfo = taosHashGet(pCatalog->dbCache.cache, dbName, strlen(dbName));
|
||||
if (NULL == dbInfo) {
|
||||
*version = CTG_DEFAULT_INVALID_VERSION;
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
*version = dbInfo->vgroupVersion;
|
||||
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
int32_t catalogUpdateDBVgroup(struct SCatalog* pCatalog, const char* dbName, SDBVgroupInfo* dbInfo) {
|
||||
if (NULL == pCatalog || NULL == dbName || NULL == dbInfo) {
|
||||
return TSDB_CODE_CTG_INVALID_INPUT;
|
||||
}
|
||||
|
||||
if (dbInfo->vgroupVersion < 0) {
|
||||
if (pCatalog->dbCache.cache) {
|
||||
taosHashRemove(pCatalog->dbCache.cache, dbName, strlen(dbName));
|
||||
}
|
||||
|
||||
ctgWarn("remove db [%s] from cache", dbName);
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
if (NULL == pCatalog->dbCache.cache) {
|
||||
pCatalog->dbCache.cache = taosHashInit(CTG_DEFAULT_DB_NUMBER, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BINARY), true, HASH_ENTRY_LOCK);
|
||||
if (NULL == pCatalog->dbCache.cache) {
|
||||
ctgError("init hash[%d] for db cache failed", CTG_DEFAULT_DB_NUMBER);
|
||||
return TSDB_CODE_CTG_MEM_ERROR;
|
||||
}
|
||||
}
|
||||
|
||||
if (taosHashPut(pCatalog->dbCache.cache, dbName, strlen(dbName), dbInfo, sizeof(*dbInfo)) != 0) {
|
||||
ctgError("push to vgroup hash cache failed");
|
||||
return TSDB_CODE_CTG_MEM_ERROR;
|
||||
}
|
||||
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
int32_t catalogGetDBVgroup(struct SCatalog* pCatalog, void *pRpc, const SEpSet* pMgmtEps, const char* dbName, int32_t forceUpdate, SDBVgroupInfo** dbInfo) {
|
||||
if (NULL == pCatalog || NULL == dbName || NULL == pRpc || NULL == pMgmtEps) {
|
||||
return TSDB_CODE_CTG_INVALID_INPUT;
|
||||
}
|
||||
|
||||
int32_t exist = 0;
|
||||
int32_t code = 0;
|
||||
|
||||
if (0 == forceUpdate) {
|
||||
CTG_ERR_RET(ctgGetDBVgroupFromCache(pCatalog, dbName, dbInfo, &exist));
|
||||
|
||||
if (exist) {
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
}
|
||||
|
||||
SUseDbOutput DbOut = {0};
|
||||
SBuildUseDBInput input = {0};
|
||||
|
||||
strncpy(input.db, dbName, sizeof(input.db));
|
||||
input.db[sizeof(input.db) - 1] = 0;
|
||||
input.vgroupVersion = pCatalog->vgroupCache.vgroupVersion;
|
||||
input.dbGroupVersion = CTG_DEFAULT_INVALID_VERSION;
|
||||
|
||||
CTG_ERR_RET(ctgGetDBVgroupFromMnode(pCatalog, pRpc, pMgmtEps, &input, &DbOut));
|
||||
|
||||
if (DbOut.vgroupList) {
|
||||
CTG_ERR_JRET(catalogUpdateVgroup(pCatalog, DbOut.vgroupList));
|
||||
}
|
||||
|
||||
if (DbOut.dbVgroup) {
|
||||
CTG_ERR_JRET(catalogUpdateDBVgroup(pCatalog, dbName, DbOut.dbVgroup));
|
||||
}
|
||||
|
||||
if (dbInfo) {
|
||||
*dbInfo = DbOut.dbVgroup;
|
||||
DbOut.dbVgroup = NULL;
|
||||
}
|
||||
|
||||
_return:
|
||||
tfree(DbOut.dbVgroup);
|
||||
tfree(DbOut.vgroupList);
|
||||
|
||||
return code;
|
||||
}
|
||||
|
||||
|
||||
|
||||
int32_t catalogGetTableMetaFromMnode(struct SCatalog* pCatalog, void *pRpc, const SEpSet* pMgmtEps, const char* pTableName, const STagData* tagData, STableMeta* pTableMeta) {
|
||||
if (NULL == pCatalog || NULL == pMgmtEps || NULL == pTableName || NULL == pTableMeta) {
|
||||
return TSDB_CODE_CTG_INVALID_INPUT;
|
||||
}
|
||||
|
||||
SBuildTableMetaInput bInput = {0};
|
||||
char *msg = NULL;
|
||||
SEpSet *pVnodeEpSet = NULL;
|
||||
int32_t msgLen = 0;
|
||||
|
||||
int32_t code = queryBuildMsg[TSDB_MSG_TYPE_TABLE_META](&bInput, &msg, 0, &msgLen);
|
||||
if (code) {
|
||||
return code;
|
||||
}
|
||||
|
||||
SRpcMsg rpcMsg = {
|
||||
.msgType = TSDB_MSG_TYPE_TABLE_META,
|
||||
.pCont = msg,
|
||||
.contLen = msgLen,
|
||||
};
|
||||
|
||||
SRpcMsg rpcRsp = {0};
|
||||
|
||||
rpcSendRecv(pRpc, (SEpSet*)pMgmtEps, &rpcMsg, &rpcRsp);
|
||||
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
int32_t catalogGetTableMeta(struct SCatalog* pCatalog, void *pRpc, const SEpSet* pMgmtEps, const char* pTableName, STableMeta* pTableMeta) {
|
||||
|
||||
}
|
||||
|
||||
|
||||
int32_t catalogGetAllMeta(struct SCatalog* pCatalog, const SEpSet* pMgmtEps, const SCatalogReq* pReq, SMetaData* pRsp) {
|
||||
if (NULL == pCatalog || NULL == pMgmtEps || NULL == pReq || NULL == pRsp) {
|
||||
return TSDB_CODE_CTG_INVALID_INPUT;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void catalogDestroy(void) {
|
||||
if (ctgMgmt.pCluster) {
|
||||
taosHashCleanup(ctgMgmt.pCluster); //TBD
|
||||
ctgMgmt.pCluster = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -20,6 +20,8 @@ extern "C" {
|
|||
#endif
|
||||
|
||||
#include "index_fst_util.h"
|
||||
|
||||
|
||||
typedef struct AutomationCtx AutomationCtx;
|
||||
|
||||
typedef enum AutomationType {
|
||||
|
@ -38,18 +40,30 @@ typedef struct Complement {
|
|||
// automation
|
||||
typedef struct AutomationCtx {
|
||||
AutomationType type;
|
||||
void *data;
|
||||
void *stdata;
|
||||
char *data;
|
||||
} AutomationCtx;
|
||||
|
||||
|
||||
|
||||
typedef enum ValueType { FST_INT, FST_CHAR, FST_ARRAY} ValueType;
|
||||
typedef enum StartWithStateKind { Done, Running } StartWithStateKind;
|
||||
|
||||
typedef struct StartWithStateValue {
|
||||
StartWithStateKind kind;
|
||||
void *value;
|
||||
ValueType type;
|
||||
union {
|
||||
int val;
|
||||
char *ptr;
|
||||
SArray *arr;
|
||||
// add more type
|
||||
} ;
|
||||
} StartWithStateValue;
|
||||
|
||||
StartWithStateValue *startWithStateValueCreate(StartWithStateKind kind, ValueType ty, void *val);
|
||||
StartWithStateValue *startWithStateValueDump(StartWithStateValue *sv);
|
||||
void startWithStateValueDestroy(void *sv);
|
||||
|
||||
|
||||
typedef struct AutomationFunc {
|
||||
void* (*start)(AutomationCtx *ctx) ;
|
||||
bool (*isMatch)(AutomationCtx *ctx, void *);
|
||||
|
@ -59,7 +73,7 @@ typedef struct AutomationFunc {
|
|||
void* (*acceptEof)(AutomationCtx *ct, void *state);
|
||||
} AutomationFunc;
|
||||
|
||||
AutomationCtx *automCtxCreate(void *data, AutomationType type);
|
||||
AutomationCtx *automCtxCreate(void *data, AutomationType atype);
|
||||
void automCtxDestroy(AutomationCtx *ctx);
|
||||
|
||||
extern AutomationFunc automFuncs[];
|
||||
|
|
|
@ -17,6 +17,7 @@
|
|||
#include "tcoding.h"
|
||||
#include "tchecksum.h"
|
||||
#include "indexInt.h"
|
||||
#include "index_fst_automation.h"
|
||||
|
||||
|
||||
static void fstPackDeltaIn(FstCountingWriter *wrt, CompiledAddr nodeAddr, CompiledAddr transAddr, uint8_t nBytes) {
|
||||
|
@ -1322,6 +1323,7 @@ StreamWithStateResult *streamWithStateNextWith(StreamWithState *sws, StreamCallb
|
|||
return swsResultCreate(&s, output, callback(start));
|
||||
}
|
||||
}
|
||||
SArray *nodes = taosArrayInit(8, sizeof(FstNode *));
|
||||
while (taosArrayGetSize(sws->stack) > 0) {
|
||||
StreamState *p = (StreamState *)taosArrayPop(sws->stack);
|
||||
if (p->trans >= FST_NODE_LEN(p->node) || automFuncs[aut->type].canMatch(aut, p->autState)) {
|
||||
|
@ -1337,8 +1339,8 @@ StreamWithStateResult *streamWithStateNextWith(StreamWithState *sws, StreamCallb
|
|||
void* nextState = automFuncs[aut->type].accept(aut, p->autState, trn.inp);
|
||||
void* tState = callback(nextState);
|
||||
bool isMatch = automFuncs[aut->type].isMatch(aut, nextState);
|
||||
//bool isMatch = sws->aut->isMatch(nextState);
|
||||
FstNode *nextNode = fstGetNode(sws->fst, trn.addr);
|
||||
taosArrayPush(nodes, &nextNode);
|
||||
taosArrayPush(sws->inp, &(trn.inp));
|
||||
|
||||
if (FST_NODE_IS_FINAL(nextNode)) {
|
||||
|
@ -1354,26 +1356,35 @@ StreamWithStateResult *streamWithStateNextWith(StreamWithState *sws, StreamCallb
|
|||
StreamState s2 = {.node = nextNode, .trans = 0, .out = {.null = false, .out = out}, .autState = nextState};
|
||||
taosArrayPush(sws->stack, &s2);
|
||||
|
||||
uint8_t *buf = (uint8_t *)malloc(taosArrayGetSize(sws->inp) * sizeof(uint8_t));
|
||||
for (uint32_t i = 0; i < taosArrayGetSize(sws->inp); i++) {
|
||||
uint8_t *t = (uint8_t *)taosArrayGet(sws->inp, i);
|
||||
buf[i] = *t;
|
||||
|
||||
size_t isz = taosArrayGetSize(sws->inp);
|
||||
uint8_t *buf = (uint8_t *)malloc(isz * sizeof(uint8_t));
|
||||
for (uint32_t i = 0; i < isz; i++) {
|
||||
buf[i] = *(uint8_t *)taosArrayGet(sws->inp, i);
|
||||
}
|
||||
FstSlice slice = fstSliceCreate(buf, taosArrayGetSize(sws->inp));
|
||||
if (fstBoundWithDataExceededBy(sws->endAt, &slice)) {
|
||||
taosArrayDestroyEx(sws->stack, streamStateDestroy);
|
||||
sws->stack = (SArray *)taosArrayInit(256, sizeof(StreamState));
|
||||
free(buf);
|
||||
fstSliceDestroy(&slice);
|
||||
return NULL;
|
||||
}
|
||||
if (FST_NODE_IS_FINAL(nextNode) && isMatch) {
|
||||
FstOutput fOutput = {.null = false, .out = out + FST_NODE_FINAL_OUTPUT(nextNode)};
|
||||
StreamWithStateResult *result = swsResultCreate(&slice, fOutput , tState);
|
||||
StreamWithStateResult *result = swsResultCreate(&slice, fOutput, tState);
|
||||
free(buf);
|
||||
fstSliceDestroy(&slice);
|
||||
return result;
|
||||
}
|
||||
free(buf);
|
||||
fstSliceDestroy(&slice);
|
||||
}
|
||||
for (size_t i = 0; i < taosArrayGetSize(nodes); i++) {
|
||||
FstNode** node = (FstNode **)taosArrayGet(nodes, i);
|
||||
fstNodeDestroy(*node);
|
||||
}
|
||||
taosArrayDestroy(nodes);
|
||||
return NULL;
|
||||
|
||||
}
|
||||
|
@ -1392,6 +1403,7 @@ void swsResultDestroy(StreamWithStateResult *result) {
|
|||
if (NULL == result) { return; }
|
||||
|
||||
fstSliceDestroy(&result->data);
|
||||
startWithStateValueDestroy(result->state);
|
||||
free(result);
|
||||
}
|
||||
|
||||
|
|
|
@ -16,21 +16,81 @@
|
|||
#include "index_fst_automation.h"
|
||||
|
||||
|
||||
StartWithStateValue *startWithStateValueCreate(StartWithStateKind kind, ValueType ty, void *val) {
|
||||
StartWithStateValue *nsv = calloc(1, sizeof(StartWithStateValue));
|
||||
if (nsv == NULL) { return NULL; }
|
||||
|
||||
nsv->kind = kind;
|
||||
nsv->type = ty;
|
||||
if (ty == FST_INT) {
|
||||
nsv->val = *(int *)val;
|
||||
} else if (ty == FST_CHAR) {
|
||||
size_t len = strlen((char *)val);
|
||||
nsv->ptr = (char *)calloc(1, len + 1);
|
||||
memcpy(nsv->ptr, val, len);
|
||||
} else if (ty == FST_ARRAY) {
|
||||
//TODO,
|
||||
//nsv->arr = taosArrayFromList()
|
||||
}
|
||||
return nsv;
|
||||
}
|
||||
void startWithStateValueDestroy(void *val) {
|
||||
StartWithStateValue *sv = (StartWithStateValue *)val;
|
||||
if (sv == NULL) { return; }
|
||||
|
||||
if (sv->type == FST_INT) {
|
||||
//
|
||||
} else if (sv->type == FST_CHAR) {
|
||||
free(sv->ptr);
|
||||
} else if (sv->type == FST_ARRAY) {
|
||||
taosArrayDestroy(sv->arr);
|
||||
}
|
||||
free(sv);
|
||||
}
|
||||
StartWithStateValue *startWithStateValueDump(StartWithStateValue *sv) {
|
||||
StartWithStateValue *nsv = calloc(1, sizeof(StartWithStateValue));
|
||||
if (nsv == NULL) { return NULL; }
|
||||
|
||||
nsv->kind = sv->kind;
|
||||
nsv->type= sv->type;
|
||||
if (nsv->type == FST_INT) {
|
||||
nsv->val = sv->val;
|
||||
} else if (nsv->type == FST_CHAR) {
|
||||
size_t len = strlen(sv->ptr);
|
||||
nsv->ptr = (char *)calloc(1, len + 1);
|
||||
memcpy(nsv->ptr, sv->ptr, len);
|
||||
} else if (nsv->type == FST_ARRAY) {
|
||||
}
|
||||
return nsv;
|
||||
}
|
||||
|
||||
|
||||
// prefix query, impl later
|
||||
|
||||
static void* prefixStart(AutomationCtx *ctx) {
|
||||
StartWithStateValue *data = (StartWithStateValue *)(ctx->data);
|
||||
return data;
|
||||
return startWithStateValueDump(data);
|
||||
};
|
||||
static bool prefixIsMatch(AutomationCtx *ctx, void *data) {
|
||||
return true;
|
||||
static bool prefixIsMatch(AutomationCtx *ctx, void *sv) {
|
||||
StartWithStateValue* ssv = (StartWithStateValue *)sv;
|
||||
return ssv->val == strlen(ctx->data);
|
||||
}
|
||||
static bool prefixCanMatch(AutomationCtx *ctx, void *data) {
|
||||
return true;
|
||||
static bool prefixCanMatch(AutomationCtx *ctx, void *sv) {
|
||||
StartWithStateValue* ssv = (StartWithStateValue *)sv;
|
||||
return ssv->val >= 0;
|
||||
}
|
||||
static bool prefixWillAlwaysMatch(AutomationCtx *ctx, void *state) {
|
||||
return true;
|
||||
}
|
||||
static void* prefixAccept(AutomationCtx *ctx, void *state, uint8_t byte) {
|
||||
StartWithStateValue* ssv = (StartWithStateValue *)state;
|
||||
if (ssv == NULL || ctx == NULL) {return NULL;}
|
||||
|
||||
char *data = ctx->data;
|
||||
if ((strlen(data) > ssv->val) && data[ssv->val] == byte) {
|
||||
int val = ssv->val + 1;
|
||||
return startWithStateValueCreate(Running, FST_INT, &val);
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
static void* prefixAcceptEof(AutomationCtx *ctx, void *state) {
|
||||
|
@ -79,28 +139,33 @@ AutomationFunc automFuncs[] = {{
|
|||
// add more search type
|
||||
};
|
||||
|
||||
AutomationCtx* automCtxCreate(void *data, AutomationType type) {
|
||||
AutomationCtx* automCtxCreate(void *data,AutomationType atype) {
|
||||
AutomationCtx *ctx = calloc(1, sizeof(AutomationCtx));
|
||||
if (ctx == NULL) { return NULL; }
|
||||
|
||||
if (type == AUTOMATION_PREFIX) {
|
||||
StartWithStateValue *swsv = (StartWithStateValue *)calloc(1, sizeof(StartWithStateValue));
|
||||
swsv->kind = Done;
|
||||
swsv->value = NULL;
|
||||
ctx->data = (void *)swsv;
|
||||
} else if (type == AUTMMATION_MATCH) {
|
||||
StartWithStateValue *sv = NULL;
|
||||
if (atype == AUTOMATION_PREFIX) {
|
||||
sv = startWithStateValueCreate(Running, FST_INT, 0);
|
||||
ctx->stdata = (void *)sv;
|
||||
} else if (atype == AUTMMATION_MATCH) {
|
||||
|
||||
} else {
|
||||
// add more search type
|
||||
}
|
||||
|
||||
ctx->type = type;
|
||||
char* src = (char *)data;
|
||||
size_t len = strlen(src);
|
||||
char* dst = (char *)malloc(len * sizeof(char) + 1);
|
||||
memcpy(dst, src, len);
|
||||
dst[len] = 0;
|
||||
|
||||
ctx->data = dst;
|
||||
ctx->type = atype;
|
||||
ctx->stdata = (void *)sv;
|
||||
return ctx;
|
||||
}
|
||||
void automCtxDestroy(AutomationCtx *ctx) {
|
||||
if (ctx->type == AUTOMATION_PREFIX) {
|
||||
free(ctx->data);
|
||||
} else if (ctx->type == AUTMMATION_MATCH) {
|
||||
}
|
||||
startWithStateValueDestroy(ctx->stdata);
|
||||
free(ctx->data);
|
||||
free(ctx);
|
||||
}
|
||||
|
|
|
@ -8,7 +8,7 @@ target_include_directories(
|
|||
|
||||
target_link_libraries(
|
||||
parser
|
||||
PRIVATE os util common catalog function transport
|
||||
PRIVATE os util common catalog function transport query
|
||||
)
|
||||
|
||||
ADD_SUBDIRECTORY(test)
|
||||
ADD_SUBDIRECTORY(test)
|
||||
|
|
|
@ -79,13 +79,13 @@ int32_t checkForInvalidExpr(SQueryStmtInfo* pQueryInfo, SMsgBuf* pMsgBuf);
|
|||
* @param msgBufLen
|
||||
* @return
|
||||
*/
|
||||
int32_t qParserExtractRequestedMetaInfo(const SSqlInfo* pSqlInfo, SMetaReq* pMetaInfo, char* msg, int32_t msgBufLen);
|
||||
int32_t qParserExtractRequestedMetaInfo(const SSqlInfo* pSqlInfo, SCatalogReq* pMetaInfo, char* msg, int32_t msgBufLen);
|
||||
|
||||
/**
|
||||
* Destroy the meta data request structure.
|
||||
* @param pMetaInfo
|
||||
*/
|
||||
void qParserClearupMetaRequestInfo(SMetaReq* pMetaInfo);
|
||||
void qParserClearupMetaRequestInfo(SCatalogReq* pMetaInfo);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
|
|
@ -4077,18 +4077,18 @@ int32_t qParserValidateSqlNode(struct SCatalog* pCatalog, SSqlInfo* pInfo, SQuer
|
|||
}
|
||||
#endif
|
||||
|
||||
SMetaReq req = {0};
|
||||
SCatalogReq req = {0};
|
||||
SMetaData data = {0};
|
||||
|
||||
// TODO: check if the qnode info has been cached already
|
||||
req.qNodeEpset = true;
|
||||
req.qNodeRequired = true;
|
||||
code = qParserExtractRequestedMetaInfo(pInfo, &req, msgBuf, msgBufLen);
|
||||
if (code != TSDB_CODE_SUCCESS) {
|
||||
return code;
|
||||
}
|
||||
|
||||
// load the meta data from catalog
|
||||
code = catalogGetMetaData(pCatalog, &req, &data);
|
||||
code = catalogGetAllMeta(pCatalog, NULL, &req, &data);
|
||||
if (code != TSDB_CODE_SUCCESS) {
|
||||
return code;
|
||||
}
|
||||
|
|
|
@ -178,15 +178,15 @@ static int32_t buildTableName(SInsertParseContext* pCxt, SToken* pStname, SArray
|
|||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
static int32_t buildMetaReq(SInsertParseContext* pCxt, SToken* pStname, SMetaReq* pMetaReq) {
|
||||
static int32_t buildMetaReq(SInsertParseContext* pCxt, SToken* pStname, SCatalogReq* pMetaReq) {
|
||||
pMetaReq->pTableName = taosArrayInit(4, sizeof(SName));
|
||||
return buildTableName(pCxt, pStname, pMetaReq->pTableName);
|
||||
}
|
||||
|
||||
static int32_t getTableMeta(SInsertParseContext* pCxt, SToken* pTname) {
|
||||
SMetaReq req;
|
||||
SCatalogReq req;
|
||||
CHECK_CODE(buildMetaReq(pCxt, pTname, &req));
|
||||
CHECK_CODE(catalogGetMetaData(pCxt->pCatalog, &req, &pCxt->meta));
|
||||
CHECK_CODE(catalogGetTableMeta(pCxt->pCatalog, NULL, NULL, NULL, &pCxt->meta)); //TODO
|
||||
pCxt->pTableMeta = (STableMeta*)taosArrayGetP(pCxt->meta.pTableMeta, 0);
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
@ -861,13 +861,15 @@ int32_t parseInsertSql(SParseContext* pContext, SInsertStmtInfo** pInfo) {
|
|||
.pComCxt = pContext,
|
||||
.pSql = pContext->pSql,
|
||||
.msg = {.buf = pContext->pMsg, .len = pContext->msgLen},
|
||||
.pCatalog = getCatalogHandle(pContext->pEpSet),
|
||||
.pCatalog = NULL,
|
||||
.pTableMeta = NULL,
|
||||
.pTableBlockHashObj = taosHashInit(128, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BIGINT), true, false),
|
||||
.totalNum = 0,
|
||||
.pOutput = *pInfo
|
||||
};
|
||||
|
||||
CHECK_CODE(catalogGetHandle(NULL, &context.pCatalog)); //TODO
|
||||
|
||||
if (NULL == context.pTableBlockHashObj) {
|
||||
return TSDB_CODE_TSC_OUT_OF_MEMORY;
|
||||
}
|
||||
|
|
|
@ -43,7 +43,12 @@ int32_t qParseQuerySql(const char* pStr, size_t length, struct SQueryStmtInfo**
|
|||
return TSDB_CODE_TSC_SQL_SYNTAX_ERROR;
|
||||
}
|
||||
|
||||
struct SCatalog* pCatalog = getCatalogHandle(NULL);
|
||||
struct SCatalog* pCatalog = NULL;
|
||||
int32_t code = catalogGetHandle(NULL, &pCatalog);
|
||||
if (code) {
|
||||
return code;
|
||||
}
|
||||
|
||||
return qParserValidateSqlNode(pCatalog, &info, *pQueryInfo, id, msg, msgLen);
|
||||
}
|
||||
|
||||
|
@ -132,7 +137,7 @@ static void freePtrElem(void* p) {
|
|||
tfree(*(char**)p);
|
||||
}
|
||||
|
||||
int32_t qParserExtractRequestedMetaInfo(const SSqlInfo* pSqlInfo, SMetaReq* pMetaInfo, char* msg, int32_t msgBufLen) {
|
||||
int32_t qParserExtractRequestedMetaInfo(const SSqlInfo* pSqlInfo, SCatalogReq* pMetaInfo, char* msg, int32_t msgBufLen) {
|
||||
int32_t code = TSDB_CODE_SUCCESS;
|
||||
SMsgBuf msgBuf = {.buf = msg, .len = msgBufLen};
|
||||
|
||||
|
@ -189,7 +194,7 @@ int32_t qParserExtractRequestedMetaInfo(const SSqlInfo* pSqlInfo, SMetaReq* pMet
|
|||
return code;
|
||||
}
|
||||
|
||||
void qParserClearupMetaRequestInfo(SMetaReq* pMetaReq) {
|
||||
void qParserClearupMetaRequestInfo(SCatalogReq* pMetaReq) {
|
||||
if (pMetaReq == NULL) {
|
||||
return;
|
||||
}
|
||||
|
|
|
@ -1448,23 +1448,6 @@ void* vgroupInfoClear(SVgroupsInfo *vgroupList) {
|
|||
return NULL;
|
||||
}
|
||||
|
||||
char* serializeTagData(STagData* pTagData, char* pMsg) {
|
||||
int32_t n = (int32_t) strlen(pTagData->name);
|
||||
*(int32_t*) pMsg = htonl(n);
|
||||
pMsg += sizeof(n);
|
||||
|
||||
memcpy(pMsg, pTagData->name, n);
|
||||
pMsg += n;
|
||||
|
||||
*(int32_t*)pMsg = htonl(pTagData->dataLen);
|
||||
pMsg += sizeof(int32_t);
|
||||
|
||||
memcpy(pMsg, pTagData->data, pTagData->dataLen);
|
||||
pMsg += pTagData->dataLen;
|
||||
|
||||
return pMsg;
|
||||
}
|
||||
|
||||
int32_t copyTagData(STagData* dst, const STagData* src) {
|
||||
dst->dataLen = src->dataLen;
|
||||
tstrncpy(dst->name, src->name, tListLen(dst->name));
|
||||
|
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue