fix multiple polling
This commit is contained in:
commit
01cac6b06e
|
@ -2,11 +2,7 @@ aux_source_directory(src TMQ_DEMO_SRC)
|
||||||
|
|
||||||
add_executable(tmq ${TMQ_DEMO_SRC})
|
add_executable(tmq ${TMQ_DEMO_SRC})
|
||||||
target_link_libraries(
|
target_link_libraries(
|
||||||
tmq
|
tmq taos
|
||||||
PUBLIC taos
|
|
||||||
#PUBLIC util
|
|
||||||
#PUBLIC common
|
|
||||||
#PUBLIC os
|
|
||||||
)
|
)
|
||||||
target_include_directories(
|
target_include_directories(
|
||||||
tmq
|
tmq
|
||||||
|
|
|
@ -51,6 +51,10 @@ typedef enum {
|
||||||
} ECheckItemType;
|
} ECheckItemType;
|
||||||
|
|
||||||
typedef enum { TD_ROW_DISCARD_UPDATE = 0, TD_ROW_OVERWRITE_UPDATE = 1, TD_ROW_PARTIAL_UPDATE = 2 } TDUpdateConfig;
|
typedef enum { TD_ROW_DISCARD_UPDATE = 0, TD_ROW_OVERWRITE_UPDATE = 1, TD_ROW_PARTIAL_UPDATE = 2 } TDUpdateConfig;
|
||||||
|
typedef enum {
|
||||||
|
TSDB_STATIS_OK = 0, // statis part exist and load successfully
|
||||||
|
TSDB_STATIS_NONE = 1, // statis part not exist
|
||||||
|
} ETsdbStatisStatus;
|
||||||
|
|
||||||
extern char *qtypeStr[];
|
extern char *qtypeStr[];
|
||||||
|
|
||||||
|
|
|
@ -25,24 +25,6 @@
|
||||||
extern "C" {
|
extern "C" {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// typedef struct STimeWindow {
|
|
||||||
// TSKEY skey;
|
|
||||||
// TSKEY ekey;
|
|
||||||
// } STimeWindow;
|
|
||||||
|
|
||||||
// typedef struct {
|
|
||||||
// int32_t dataLen;
|
|
||||||
// char name[TSDB_TABLE_FNAME_LEN];
|
|
||||||
// char *data;
|
|
||||||
// } STagData;
|
|
||||||
|
|
||||||
// typedef struct SSchema {
|
|
||||||
// uint8_t type;
|
|
||||||
// char name[TSDB_COL_NAME_LEN];
|
|
||||||
// int16_t colId;
|
|
||||||
// int16_t bytes;
|
|
||||||
// } SSchema;
|
|
||||||
|
|
||||||
enum {
|
enum {
|
||||||
TMQ_CONF__RESET_OFFSET__LATEST = -1,
|
TMQ_CONF__RESET_OFFSET__LATEST = -1,
|
||||||
TMQ_CONF__RESET_OFFSET__EARLIEAST = -2,
|
TMQ_CONF__RESET_OFFSET__EARLIEAST = -2,
|
||||||
|
|
|
@ -52,6 +52,13 @@ extern bool tsEnableSlaveQuery;
|
||||||
extern bool tsPrintAuth;
|
extern bool tsPrintAuth;
|
||||||
extern int64_t tsTickPerDay[3];
|
extern int64_t tsTickPerDay[3];
|
||||||
|
|
||||||
|
// monitor
|
||||||
|
extern bool tsEnableMonitor;
|
||||||
|
extern int32_t tsMonitorInterval;
|
||||||
|
extern char tsMonitorFqdn[];
|
||||||
|
extern uint16_t tsMonitorPort;
|
||||||
|
extern int32_t tsMonitorMaxLogs;
|
||||||
|
|
||||||
// query buffer management
|
// query buffer management
|
||||||
extern int32_t tsQueryBufferSize; // maximum allowed usage buffer size in MB for each data node during query processing
|
extern int32_t tsQueryBufferSize; // maximum allowed usage buffer size in MB for each data node during query processing
|
||||||
extern int64_t tsQueryBufferSizeBytes; // maximum allowed usage buffer size in byte for each data node
|
extern int64_t tsQueryBufferSizeBytes; // maximum allowed usage buffer size in byte for each data node
|
||||||
|
|
|
@ -167,6 +167,7 @@ typedef struct {
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
char db[TSDB_DB_FNAME_LEN];
|
char db[TSDB_DB_FNAME_LEN];
|
||||||
|
int64_t dbId;
|
||||||
int32_t vgVersion;
|
int32_t vgVersion;
|
||||||
} SBuildUseDBInput;
|
} SBuildUseDBInput;
|
||||||
|
|
||||||
|
@ -563,6 +564,7 @@ int32_t tDeserializeSDropDbRsp(void* buf, int32_t bufLen, SDropDbRsp* pRsp);
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
char db[TSDB_DB_FNAME_LEN];
|
char db[TSDB_DB_FNAME_LEN];
|
||||||
|
int64_t dbId;
|
||||||
int32_t vgVersion;
|
int32_t vgVersion;
|
||||||
} SUseDbReq;
|
} SUseDbReq;
|
||||||
|
|
||||||
|
@ -737,6 +739,9 @@ typedef struct {
|
||||||
int32_t maxRows;
|
int32_t maxRows;
|
||||||
int32_t commitTime;
|
int32_t commitTime;
|
||||||
int32_t fsyncPeriod;
|
int32_t fsyncPeriod;
|
||||||
|
uint32_t hashBegin;
|
||||||
|
uint32_t hashEnd;
|
||||||
|
int8_t hashMethod;
|
||||||
int8_t walLevel;
|
int8_t walLevel;
|
||||||
int8_t precision;
|
int8_t precision;
|
||||||
int8_t compression;
|
int8_t compression;
|
||||||
|
@ -747,6 +752,7 @@ typedef struct {
|
||||||
int8_t selfIndex;
|
int8_t selfIndex;
|
||||||
int8_t streamMode;
|
int8_t streamMode;
|
||||||
SReplica replicas[TSDB_MAX_REPLICA];
|
SReplica replicas[TSDB_MAX_REPLICA];
|
||||||
|
|
||||||
} SCreateVnodeReq, SAlterVnodeReq;
|
} SCreateVnodeReq, SAlterVnodeReq;
|
||||||
|
|
||||||
int32_t tSerializeSCreateVnodeReq(void* buf, int32_t bufLen, SCreateVnodeReq* pReq);
|
int32_t tSerializeSCreateVnodeReq(void* buf, int32_t bufLen, SCreateVnodeReq* pReq);
|
||||||
|
|
|
@ -52,6 +52,8 @@ void deltaToUtcInitOnce();
|
||||||
|
|
||||||
int64_t convertTimePrecision(int64_t time, int32_t fromPrecision, int32_t toPrecision);
|
int64_t convertTimePrecision(int64_t time, int32_t fromPrecision, int32_t toPrecision);
|
||||||
|
|
||||||
|
void taosFormatUtcTime(char *buf, int32_t bufLen, int64_t time, int32_t precision);
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -16,6 +16,8 @@
|
||||||
#ifndef _TD_MND_H_
|
#ifndef _TD_MND_H_
|
||||||
#define _TD_MND_H_
|
#define _TD_MND_H_
|
||||||
|
|
||||||
|
#include "monitor.h"
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
extern "C" {
|
extern "C" {
|
||||||
#endif
|
#endif
|
||||||
|
@ -30,20 +32,6 @@ typedef int32_t (*PutReqToMWriteQFp)(SDnode *pDnode, struct SRpcMsg *rpcMsg);
|
||||||
typedef int32_t (*PutReqToMReadQFp)(SDnode *pDnode, struct SRpcMsg *rpcMsg);
|
typedef int32_t (*PutReqToMReadQFp)(SDnode *pDnode, struct SRpcMsg *rpcMsg);
|
||||||
typedef void (*SendRedirectRspFp)(SDnode *pDnode, struct SRpcMsg *rpcMsg);
|
typedef void (*SendRedirectRspFp)(SDnode *pDnode, struct SRpcMsg *rpcMsg);
|
||||||
|
|
||||||
typedef struct SMnodeLoad {
|
|
||||||
int64_t numOfDnode;
|
|
||||||
int64_t numOfMnode;
|
|
||||||
int64_t numOfVgroup;
|
|
||||||
int64_t numOfDatabase;
|
|
||||||
int64_t numOfSuperTable;
|
|
||||||
int64_t numOfChildTable;
|
|
||||||
int64_t numOfNormalTable;
|
|
||||||
int64_t numOfColumn;
|
|
||||||
int64_t totalPoints;
|
|
||||||
int64_t totalStorage;
|
|
||||||
int64_t compStorage;
|
|
||||||
} SMnodeLoad;
|
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
int32_t dnodeId;
|
int32_t dnodeId;
|
||||||
int64_t clusterId;
|
int64_t clusterId;
|
||||||
|
@ -92,13 +80,16 @@ int32_t mndAlter(SMnode *pMnode, const SMnodeOpt *pOption);
|
||||||
void mndDestroy(const char *path);
|
void mndDestroy(const char *path);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Get mnode statistics info.
|
* @brief Get mnode monitor info.
|
||||||
*
|
*
|
||||||
* @param pMnode The mnode object.
|
* @param pMnode The mnode object.
|
||||||
* @param pLoad Statistics of the mnode.
|
* @param pClusterInfo
|
||||||
|
* @param pVgroupInfo
|
||||||
|
* @param pGrantInfo
|
||||||
* @return int32_t 0 for success, -1 for failure.
|
* @return int32_t 0 for success, -1 for failure.
|
||||||
*/
|
*/
|
||||||
int32_t mndGetLoad(SMnode *pMnode, SMnodeLoad *pLoad);
|
int32_t mndGetMonitorInfo(SMnode *pMnode, SMonClusterInfo *pClusterInfo, SMonVgroupInfo *pVgroupInfo,
|
||||||
|
SMonGrantInfo *pGrantInfo);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Get user authentication info.
|
* @brief Get user authentication info.
|
||||||
|
|
|
@ -95,7 +95,7 @@ int32_t catalogGetHandle(uint64_t clusterId, SCatalog** catalogHandle);
|
||||||
*/
|
*/
|
||||||
void catalogFreeHandle(SCatalog* pCatalog);
|
void catalogFreeHandle(SCatalog* pCatalog);
|
||||||
|
|
||||||
int32_t catalogGetDBVgVersion(SCatalog* pCatalog, const char* dbName, int32_t* version);
|
int32_t catalogGetDBVgVersion(SCatalog* pCtg, const char* dbFName, int32_t* version, int64_t* dbId);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get a DB's all vgroup info.
|
* Get a DB's all vgroup info.
|
||||||
|
|
|
@ -89,25 +89,6 @@ int32_t qExecTask(qTaskInfo_t tinfo, SSDataBlock** pRes, uint64_t *useconds);
|
||||||
*/
|
*/
|
||||||
int32_t qRetrieveQueryResultInfo(qTaskInfo_t tinfo, bool* buildRes, void* pRspContext);
|
int32_t qRetrieveQueryResultInfo(qTaskInfo_t tinfo, bool* buildRes, void* pRspContext);
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
* Retrieve the actual results to fill the response message payload.
|
|
||||||
* Note that this function must be executed after qRetrieveQueryResultInfo is invoked.
|
|
||||||
*
|
|
||||||
* @param tinfo tinfo object
|
|
||||||
* @param pRsp response message
|
|
||||||
* @param contLen payload length
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
//int32_t qDumpRetrieveResult(qTaskInfo_t tinfo, SRetrieveTableRsp** pRsp, int32_t* contLen, bool* continueExec);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* return the transporter context (RPC)
|
|
||||||
* @param tinfo
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
void* qGetResultRetrieveMsg(qTaskInfo_t tinfo);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* kill the ongoing query and free the query handle and corresponding resources automatically
|
* kill the ongoing query and free the query handle and corresponding resources automatically
|
||||||
* @param tinfo qhandle
|
* @param tinfo qhandle
|
||||||
|
|
|
@ -29,6 +29,12 @@ typedef struct SIndexOpts SIndexOpts;
|
||||||
typedef struct SIndexMultiTermQuery SIndexMultiTermQuery;
|
typedef struct SIndexMultiTermQuery SIndexMultiTermQuery;
|
||||||
typedef struct SArray SIndexMultiTerm;
|
typedef struct SArray SIndexMultiTerm;
|
||||||
|
|
||||||
|
typedef struct SIndex SIndexJson;
|
||||||
|
typedef struct SIndexTerm SIndexJsonTerm;
|
||||||
|
typedef struct SIndexOpts SIndexJsonOpts;
|
||||||
|
typedef struct SIndexMultiTermQuery SIndexJsonMultiTermQuery;
|
||||||
|
typedef struct SArray SIndexJsonMultiTerm;
|
||||||
|
|
||||||
typedef enum {
|
typedef enum {
|
||||||
ADD_VALUE, // add index colume value
|
ADD_VALUE, // add index colume value
|
||||||
DEL_VALUE, // delete index column value
|
DEL_VALUE, // delete index column value
|
||||||
|
@ -39,24 +45,108 @@ typedef enum {
|
||||||
} SIndexOperOnColumn;
|
} SIndexOperOnColumn;
|
||||||
|
|
||||||
typedef enum { MUST = 0, SHOULD = 1, NOT = 2 } EIndexOperatorType;
|
typedef enum { MUST = 0, SHOULD = 1, NOT = 2 } EIndexOperatorType;
|
||||||
typedef enum { QUERY_TERM = 0, QUERY_PREFIX = 1, QUERY_SUFFIX = 2, QUERY_REGEX = 3 } EIndexQueryType;
|
typedef enum { QUERY_TERM = 0, QUERY_PREFIX = 1, QUERY_SUFFIX = 2, QUERY_REGEX = 3, QUERY_RANGE = 4 } EIndexQueryType;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* @param: oper
|
* create multi query
|
||||||
*
|
* @param oper (input, relation between querys)
|
||||||
*/
|
*/
|
||||||
SIndexMultiTermQuery* indexMultiTermQueryCreate(EIndexOperatorType oper);
|
SIndexMultiTermQuery* indexMultiTermQueryCreate(EIndexOperatorType oper);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* destroy multi query
|
||||||
|
* @param pQuery (input, multi-query-object to be destory)
|
||||||
|
*/
|
||||||
|
|
||||||
void indexMultiTermQueryDestroy(SIndexMultiTermQuery* pQuery);
|
void indexMultiTermQueryDestroy(SIndexMultiTermQuery* pQuery);
|
||||||
|
/*
|
||||||
|
* add query to multi query
|
||||||
|
* @param pQuery (input, multi-query-object)
|
||||||
|
* @param term (input, single query term)
|
||||||
|
* @param type (input, single query type)
|
||||||
|
* @return error code
|
||||||
|
*/
|
||||||
int indexMultiTermQueryAdd(SIndexMultiTermQuery* pQuery, SIndexTerm* term, EIndexQueryType type);
|
int indexMultiTermQueryAdd(SIndexMultiTermQuery* pQuery, SIndexTerm* term, EIndexQueryType type);
|
||||||
/*
|
/*
|
||||||
* @param:
|
* open index
|
||||||
* @param:
|
* @param opt (input, index opt)
|
||||||
|
* @param path (input, index path)
|
||||||
|
* @param index (output, index object)
|
||||||
|
* @return error code
|
||||||
*/
|
*/
|
||||||
int indexOpen(SIndexOpts* opt, const char* path, SIndex** index);
|
int indexOpen(SIndexOpts* opt, const char* path, SIndex** index);
|
||||||
|
/*
|
||||||
|
* close index
|
||||||
|
* @param index (input, index to be closed)
|
||||||
|
* @return error code
|
||||||
|
*/
|
||||||
void indexClose(SIndex* index);
|
void indexClose(SIndex* index);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* insert terms into index
|
||||||
|
* @param index (input, index object)
|
||||||
|
* @param term (input, terms inserted into index)
|
||||||
|
* @param uid (input, uid of terms)
|
||||||
|
* @return error code
|
||||||
|
*/
|
||||||
int indexPut(SIndex* index, SIndexMultiTerm* terms, uint64_t uid);
|
int indexPut(SIndex* index, SIndexMultiTerm* terms, uint64_t uid);
|
||||||
|
/*
|
||||||
|
* delete terms that meet query condition
|
||||||
|
* @param index (input, index object)
|
||||||
|
* @param query (input, condition query to deleted)
|
||||||
|
* @return error code
|
||||||
|
*/
|
||||||
|
|
||||||
int indexDelete(SIndex* index, SIndexMultiTermQuery* query);
|
int indexDelete(SIndex* index, SIndexMultiTermQuery* query);
|
||||||
|
/*
|
||||||
|
* search index
|
||||||
|
* @param index (input, index object)
|
||||||
|
* @param query (input, multi query condition)
|
||||||
|
* @param result(output, query result)
|
||||||
|
* @return error code
|
||||||
|
*/
|
||||||
int indexSearch(SIndex* index, SIndexMultiTermQuery* query, SArray* result);
|
int indexSearch(SIndex* index, SIndexMultiTermQuery* query, SArray* result);
|
||||||
|
/*
|
||||||
|
* rebuild index
|
||||||
|
* @param index (input, index object)
|
||||||
|
* @parma opt (input, rebuild index opts)
|
||||||
|
* @return error code
|
||||||
|
*/
|
||||||
int indexRebuild(SIndex* index, SIndexOpts* opt);
|
int indexRebuild(SIndex* index, SIndexOpts* opt);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* open index
|
||||||
|
* @param opt (input,index json opt)
|
||||||
|
* @param path (input, index json path)
|
||||||
|
* @param index (output, index json object)
|
||||||
|
* @return error code
|
||||||
|
*/
|
||||||
|
int tIndexJsonOpen(SIndexJsonOpts* opts, const char* path, SIndexJson** index);
|
||||||
|
/*
|
||||||
|
* close index
|
||||||
|
* @param index (input, index to be closed)
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
|
||||||
|
void tIndexJsonClose(SIndexJson* index);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* insert terms into index
|
||||||
|
* @param index (input, index object)
|
||||||
|
* @param term (input, terms inserted into index)
|
||||||
|
* @param uid (input, uid of terms)
|
||||||
|
* @return error code
|
||||||
|
*/
|
||||||
|
int tIndexJsonPut(SIndexJson* index, SIndexJsonMultiTerm* terms, uint64_t uid);
|
||||||
|
/*
|
||||||
|
* search index
|
||||||
|
* @param index (input, index object)
|
||||||
|
* @param query (input, multi query condition)
|
||||||
|
* @param result(output, query result)
|
||||||
|
* @return error code
|
||||||
|
*/
|
||||||
|
|
||||||
|
int tIndexJsonSearch(SIndexJson* index, SIndexJsonMultiTermQuery* query, SArray* result);
|
||||||
/*
|
/*
|
||||||
* @param
|
* @param
|
||||||
* @param
|
* @param
|
||||||
|
|
|
@ -0,0 +1,156 @@
|
||||||
|
/*
|
||||||
|
* 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_MONITOR_H_
|
||||||
|
#define _TD_MONITOR_H_
|
||||||
|
|
||||||
|
#include "tarray.h"
|
||||||
|
#include "tdef.h"
|
||||||
|
#include "tlog.h"
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#define MON_STATUS_LEN 8
|
||||||
|
#define MON_ROLE_LEN 9
|
||||||
|
#define MON_VER_LEN 12
|
||||||
|
#define MON_LOG_LEN 1024
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
int32_t dnode_id;
|
||||||
|
char dnode_ep[TSDB_EP_LEN];
|
||||||
|
} SMonBasicInfo;
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
int32_t dnode_id;
|
||||||
|
char dnode_ep[TSDB_EP_LEN];
|
||||||
|
char status[MON_STATUS_LEN];
|
||||||
|
} SMonDnodeDesc;
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
int32_t mnode_id;
|
||||||
|
char mnode_ep[TSDB_EP_LEN];
|
||||||
|
char role[MON_ROLE_LEN];
|
||||||
|
} SMonMnodeDesc;
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
char first_ep[TSDB_EP_LEN];
|
||||||
|
int32_t first_ep_dnode_id;
|
||||||
|
char version[MON_VER_LEN];
|
||||||
|
float master_uptime; // day
|
||||||
|
int32_t monitor_interval; // sec
|
||||||
|
int32_t vgroups_total;
|
||||||
|
int32_t vgroups_alive;
|
||||||
|
int32_t vnodes_total;
|
||||||
|
int32_t vnodes_alive;
|
||||||
|
int32_t connections_total;
|
||||||
|
SArray *dnodes; // array of SMonDnodeDesc
|
||||||
|
SArray *mnodes; // array of SMonMnodeDesc
|
||||||
|
} SMonClusterInfo;
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
int32_t dnode_id;
|
||||||
|
char vnode_role[MON_ROLE_LEN];
|
||||||
|
} SMonVnodeDesc;
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
int32_t vgroup_id;
|
||||||
|
char database_name[TSDB_DB_NAME_LEN];
|
||||||
|
int32_t tables_num;
|
||||||
|
char status[MON_STATUS_LEN];
|
||||||
|
SMonVnodeDesc vnodes[TSDB_MAX_REPLICA];
|
||||||
|
} SMonVgroupDesc;
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
SArray *vgroups; // array of SMonVgroupDesc
|
||||||
|
} SMonVgroupInfo;
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
int32_t expire_time;
|
||||||
|
int32_t timeseries_used;
|
||||||
|
int32_t timeseries_total;
|
||||||
|
} SMonGrantInfo;
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
float uptime; // day
|
||||||
|
float cpu_engine;
|
||||||
|
float cpu_system;
|
||||||
|
float cpu_cores;
|
||||||
|
int64_t mem_engine; // KB
|
||||||
|
int64_t mem_system; // KB
|
||||||
|
int64_t mem_total; // KB
|
||||||
|
float disk_engine; // GB
|
||||||
|
float disk_used; // GB
|
||||||
|
float disk_total; // GB
|
||||||
|
int64_t net_in;
|
||||||
|
int64_t net_out;
|
||||||
|
float io_read;
|
||||||
|
float io_write;
|
||||||
|
float io_read_disk;
|
||||||
|
float io_write_disk;
|
||||||
|
int32_t req_select;
|
||||||
|
float req_select_rate;
|
||||||
|
int32_t req_insert;
|
||||||
|
int32_t req_insert_success;
|
||||||
|
float req_insert_rate;
|
||||||
|
int32_t req_insert_batch;
|
||||||
|
int32_t req_insert_batch_success;
|
||||||
|
float req_insert_batch_rate;
|
||||||
|
int32_t errors;
|
||||||
|
int32_t vnodes_num;
|
||||||
|
int32_t masters;
|
||||||
|
int8_t has_mnode;
|
||||||
|
} SMonDnodeInfo;
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
char name[TSDB_FILENAME_LEN];
|
||||||
|
int8_t level;
|
||||||
|
SDiskSize size;
|
||||||
|
} SMonDiskDesc;
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
SArray *datadirs; // array of SMonDiskDesc
|
||||||
|
SMonDiskDesc logdir;
|
||||||
|
SMonDiskDesc tempdir;
|
||||||
|
} SMonDiskInfo;
|
||||||
|
|
||||||
|
typedef struct SMonInfo SMonInfo;
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
const char *server;
|
||||||
|
uint16_t port;
|
||||||
|
int32_t maxLogs;
|
||||||
|
} SMonCfg;
|
||||||
|
|
||||||
|
int32_t monInit(const SMonCfg *pCfg);
|
||||||
|
void monCleanup();
|
||||||
|
void monRecordLog(int64_t ts, ELogLevel level, const char *content);
|
||||||
|
|
||||||
|
SMonInfo *monCreateMonitorInfo();
|
||||||
|
void monSetBasicInfo(SMonInfo *pMonitor, SMonBasicInfo *pInfo);
|
||||||
|
void monSetClusterInfo(SMonInfo *pMonitor, SMonClusterInfo *pInfo);
|
||||||
|
void monSetVgroupInfo(SMonInfo *pMonitor, SMonVgroupInfo *pInfo);
|
||||||
|
void monSetGrantInfo(SMonInfo *pMonitor, SMonGrantInfo *pInfo);
|
||||||
|
void monSetDnodeInfo(SMonInfo *pMonitor, SMonDnodeInfo *pInfo);
|
||||||
|
void monSetDiskInfo(SMonInfo *pMonitor, SMonDiskInfo *pInfo);
|
||||||
|
void monSendReport(SMonInfo *pMonitor);
|
||||||
|
void monCleanupMonitorInfo(SMonInfo *pMonitor);
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif /*_TD_MONITOR_H_*/
|
|
@ -156,6 +156,8 @@ int32_t taosAsyncExec(__async_exec_fn_t execFn, void* execParam, int32_t* code);
|
||||||
*/
|
*/
|
||||||
int32_t asyncSendMsgToServer(void *pTransporter, SEpSet* epSet, int64_t* pTransporterId, const SMsgSendInfo* pInfo);
|
int32_t asyncSendMsgToServer(void *pTransporter, SEpSet* epSet, int64_t* pTransporterId, const SMsgSendInfo* pInfo);
|
||||||
|
|
||||||
|
int32_t queryBuildUseDbOutput(SUseDbOutput *pOut, SUseDbRsp *usedbRsp);
|
||||||
|
|
||||||
void initQueryModuleMsgHandle();
|
void initQueryModuleMsgHandle();
|
||||||
|
|
||||||
const SSchema* tGetTbnameColumnSchema();
|
const SSchema* tGetTbnameColumnSchema();
|
||||||
|
@ -166,20 +168,18 @@ int32_t queryCreateTableMetaFromMsg(STableMetaRsp* msg, bool isSuperTable, STabl
|
||||||
extern int32_t (*queryBuildMsg[TDMT_MAX])(void* input, char **msg, int32_t msgSize, int32_t *msgLen);
|
extern int32_t (*queryBuildMsg[TDMT_MAX])(void* input, char **msg, int32_t msgSize, int32_t *msgLen);
|
||||||
extern int32_t (*queryProcessMsgRsp[TDMT_MAX])(void* output, char *msg, int32_t msgSize);
|
extern int32_t (*queryProcessMsgRsp[TDMT_MAX])(void* output, char *msg, int32_t msgSize);
|
||||||
|
|
||||||
|
|
||||||
#define SET_META_TYPE_NULL(t) (t) = META_TYPE_NULL_TABLE
|
#define SET_META_TYPE_NULL(t) (t) = META_TYPE_NULL_TABLE
|
||||||
#define SET_META_TYPE_CTABLE(t) (t) = META_TYPE_CTABLE
|
#define SET_META_TYPE_CTABLE(t) (t) = META_TYPE_CTABLE
|
||||||
#define SET_META_TYPE_TABLE(t) (t) = META_TYPE_TABLE
|
#define SET_META_TYPE_TABLE(t) (t) = META_TYPE_TABLE
|
||||||
#define SET_META_TYPE_BOTH_TABLE(t) (t) = META_TYPE_BOTH_TABLE
|
#define SET_META_TYPE_BOTH_TABLE(t) (t) = META_TYPE_BOTH_TABLE
|
||||||
|
|
||||||
#define qFatal(...) do { if (qDebugFlag & DEBUG_FATAL) { taosPrintLog("QRY FATAL ", qDebugFlag, __VA_ARGS__); }} while(0)
|
#define qFatal(...) do { if (qDebugFlag & DEBUG_FATAL) { taosPrintLog("QRY FATAL ", DEBUG_FATAL, qDebugFlag, __VA_ARGS__); }} while(0)
|
||||||
#define qError(...) do { if (qDebugFlag & DEBUG_ERROR) { taosPrintLog("QRY ERROR ", qDebugFlag, __VA_ARGS__); }} while(0)
|
#define qError(...) do { if (qDebugFlag & DEBUG_ERROR) { taosPrintLog("QRY ERROR ", DEBUG_ERROR, qDebugFlag, __VA_ARGS__); }} while(0)
|
||||||
#define qWarn(...) do { if (qDebugFlag & DEBUG_WARN) { taosPrintLog("QRY WARN ", qDebugFlag, __VA_ARGS__); }} while(0)
|
#define qWarn(...) do { if (qDebugFlag & DEBUG_WARN) { taosPrintLog("QRY WARN ", DEBUG_WARN, qDebugFlag, __VA_ARGS__); }} while(0)
|
||||||
#define qInfo(...) do { if (qDebugFlag & DEBUG_INFO) { taosPrintLog("QRY ", qDebugFlag, __VA_ARGS__); }} while(0)
|
#define qInfo(...) do { if (qDebugFlag & DEBUG_INFO) { taosPrintLog("QRY ", DEBUG_INFO, qDebugFlag, __VA_ARGS__); }} while(0)
|
||||||
#define qDebug(...) do { if (qDebugFlag & DEBUG_DEBUG) { taosPrintLog("QRY ", qDebugFlag, __VA_ARGS__); }} while(0)
|
#define qDebug(...) do { if (qDebugFlag & DEBUG_DEBUG) { taosPrintLog("QRY ", DEBUG_DEBUG, qDebugFlag, __VA_ARGS__); }} while(0)
|
||||||
#define qTrace(...) do { if (qDebugFlag & DEBUG_TRACE) { taosPrintLog("QRY ", qDebugFlag, __VA_ARGS__); }} while(0)
|
#define qTrace(...) do { if (qDebugFlag & DEBUG_TRACE) { taosPrintLog("QRY ", DEBUG_TRACE, qDebugFlag, __VA_ARGS__); }} while(0)
|
||||||
#define qDebugL(...) do { if (qDebugFlag & DEBUG_DEBUG) { taosPrintLongString("QRY ", qDebugFlag, __VA_ARGS__); }} while(0)
|
#define qDebugL(...) do { if (qDebugFlag & DEBUG_DEBUG) { taosPrintLongString("QRY ", DEBUG_DEBUG, qDebugFlag, __VA_ARGS__); }} while(0)
|
||||||
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,10 +19,12 @@
|
||||||
extern "C" {
|
extern "C" {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#include "tcommon.h"
|
||||||
|
#include "nodes.h"
|
||||||
|
|
||||||
typedef struct SFilterInfo SFilterInfo;
|
typedef struct SFilterInfo SFilterInfo;
|
||||||
typedef int32_t (*filer_get_col_from_id)(void *, int32_t, void **);
|
typedef int32_t (*filer_get_col_from_id)(void *, int32_t, void **);
|
||||||
|
|
||||||
|
|
||||||
enum {
|
enum {
|
||||||
FLT_OPTION_NO_REWRITE = 1,
|
FLT_OPTION_NO_REWRITE = 1,
|
||||||
FLT_OPTION_TIMESTAMP = 2,
|
FLT_OPTION_TIMESTAMP = 2,
|
||||||
|
@ -34,7 +36,6 @@ typedef struct SFilterColumnParam{
|
||||||
SArray* pDataBlock;
|
SArray* pDataBlock;
|
||||||
} SFilterColumnParam;
|
} SFilterColumnParam;
|
||||||
|
|
||||||
|
|
||||||
extern int32_t filterInitFromNode(SNode *pNode, SFilterInfo **pinfo, uint32_t options);
|
extern int32_t filterInitFromNode(SNode *pNode, SFilterInfo **pinfo, uint32_t options);
|
||||||
extern bool filterExecute(SFilterInfo *info, SSDataBlock *pSrc, int8_t** p, SColumnDataAgg *statis, int16_t numOfCols);
|
extern bool filterExecute(SFilterInfo *info, SSDataBlock *pSrc, int8_t** p, SColumnDataAgg *statis, int16_t numOfCols);
|
||||||
extern int32_t filterSetDataFromSlotId(SFilterInfo *info, void *param);
|
extern int32_t filterSetDataFromSlotId(SFilterInfo *info, void *param);
|
||||||
|
|
|
@ -23,8 +23,6 @@ extern "C" {
|
||||||
#include "catalog.h"
|
#include "catalog.h"
|
||||||
#include "planner.h"
|
#include "planner.h"
|
||||||
|
|
||||||
struct SSchJob;
|
|
||||||
|
|
||||||
typedef struct SSchedulerCfg {
|
typedef struct SSchedulerCfg {
|
||||||
uint32_t maxJobNum;
|
uint32_t maxJobNum;
|
||||||
} SSchedulerCfg;
|
} SSchedulerCfg;
|
||||||
|
@ -72,7 +70,7 @@ int32_t schedulerInit(SSchedulerCfg *cfg);
|
||||||
* @param nodeList Qnode/Vnode address list, element is SQueryNodeAddr
|
* @param nodeList Qnode/Vnode address list, element is SQueryNodeAddr
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
int32_t schedulerExecJob(void *transport, SArray *nodeList, SQueryDag* pDag, struct SSchJob** pJob, const char* sql, SQueryResult *pRes);
|
int32_t schedulerExecJob(void *transport, SArray *nodeList, SQueryDag* pDag, int64_t *pJob, const char* sql, SQueryResult *pRes);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Process the query job, generated according to the query physical plan.
|
* Process the query job, generated according to the query physical plan.
|
||||||
|
@ -80,7 +78,7 @@ int32_t schedulerExecJob(void *transport, SArray *nodeList, SQueryDag* pDag, str
|
||||||
* @param pNodeList Qnode/Vnode address list, element is SQueryNodeAddr
|
* @param pNodeList Qnode/Vnode address list, element is SQueryNodeAddr
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
int32_t schedulerAsyncExecJob(void *transport, SArray *pNodeList, SQueryDag* pDag, const char* sql, struct SSchJob** pJob);
|
int32_t schedulerAsyncExecJob(void *transport, SArray *pNodeList, SQueryDag* pDag, const char* sql, int64_t *pJob);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Fetch query result from the remote query executor
|
* Fetch query result from the remote query executor
|
||||||
|
@ -88,7 +86,7 @@ int32_t schedulerAsyncExecJob(void *transport, SArray *pNodeList, SQueryDag* pDa
|
||||||
* @param data
|
* @param data
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
int32_t schedulerFetchRows(struct SSchJob *pJob, void **data);
|
int32_t schedulerFetchRows(int64_t job, void **data);
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -102,7 +100,7 @@ int32_t schedulerFetchRows(struct SSchJob *pJob, void **data);
|
||||||
* Free the query job
|
* Free the query job
|
||||||
* @param pJob
|
* @param pJob
|
||||||
*/
|
*/
|
||||||
void schedulerFreeJob(void *pJob);
|
void schedulerFreeJob(int64_t job);
|
||||||
|
|
||||||
void schedulerDestroy(void);
|
void schedulerDestroy(void);
|
||||||
|
|
||||||
|
|
|
@ -21,7 +21,7 @@ extern "C" {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include <tep.h>
|
#include <tdatablock.h>
|
||||||
#include "taosdef.h"
|
#include "taosdef.h"
|
||||||
#include "trpc.h"
|
#include "trpc.h"
|
||||||
|
|
||||||
|
@ -69,15 +69,15 @@ typedef struct SSyncFSM {
|
||||||
|
|
||||||
// when value in pBuf finish a raft flow, FpCommitCb is called, code indicates the result
|
// when value in pBuf finish a raft flow, FpCommitCb is called, code indicates the result
|
||||||
// user can do something according to the code and isWeak. for example, write data into tsdb
|
// user can do something according to the code and isWeak. for example, write data into tsdb
|
||||||
void (*FpCommitCb)(struct SSyncFSM* pFsm, const SSyncBuffer* pBuf, SyncIndex index, bool isWeak, int32_t code);
|
void (*FpCommitCb)(struct SSyncFSM* pFsm, const SRpcMsg* pBuf, SyncIndex index, bool isWeak, int32_t code);
|
||||||
|
|
||||||
// when value in pBuf has been written into local log store, FpPreCommitCb is called, code indicates the result
|
// when value in pBuf has been written into local log store, FpPreCommitCb is called, code indicates the result
|
||||||
// user can do something according to the code and isWeak. for example, write data into tsdb
|
// user can do something according to the code and isWeak. for example, write data into tsdb
|
||||||
void (*FpPreCommitCb)(struct SSyncFSM* pFsm, const SSyncBuffer* pBuf, SyncIndex index, bool isWeak, int32_t code);
|
void (*FpPreCommitCb)(struct SSyncFSM* pFsm, const SRpcMsg* pBuf, SyncIndex index, bool isWeak, int32_t code);
|
||||||
|
|
||||||
// when log entry is updated by a new one, FpRollBackCb is called
|
// when log entry is updated by a new one, FpRollBackCb is called
|
||||||
// user can do something to roll back. for example, delete data from tsdb, or just ignore it
|
// user can do something to roll back. for example, delete data from tsdb, or just ignore it
|
||||||
void (*FpRollBackCb)(struct SSyncFSM* pFsm, const SSyncBuffer* pBuf, SyncIndex index, bool isWeak, int32_t code);
|
void (*FpRollBackCb)(struct SSyncFSM* pFsm, const SRpcMsg* pBuf, SyncIndex index, bool isWeak, int32_t code);
|
||||||
|
|
||||||
// user should implement this function, use "data" to take snapshot into "snapshot"
|
// user should implement this function, use "data" to take snapshot into "snapshot"
|
||||||
int32_t (*FpTakeSnapshot)(SSnapshot* snapshot);
|
int32_t (*FpTakeSnapshot)(SSnapshot* snapshot);
|
||||||
|
@ -93,10 +93,10 @@ typedef struct SSyncLogStore {
|
||||||
void* data;
|
void* data;
|
||||||
|
|
||||||
// append one log entry
|
// append one log entry
|
||||||
int32_t (*appendEntry)(struct SSyncLogStore* pLogStore, SSyncBuffer* pBuf);
|
int32_t (*appendEntry)(struct SSyncLogStore* pLogStore, SRpcMsg* pBuf);
|
||||||
|
|
||||||
// get one log entry, user need to free pBuf->data
|
// get one log entry, user need to free pBuf->data
|
||||||
int32_t (*getEntry)(struct SSyncLogStore* pLogStore, SyncIndex index, SSyncBuffer* pBuf);
|
int32_t (*getEntry)(struct SSyncLogStore* pLogStore, SyncIndex index, SRpcMsg* pBuf);
|
||||||
|
|
||||||
// update log store commit index with "index"
|
// update log store commit index with "index"
|
||||||
int32_t (*updateCommitIndex)(struct SSyncLogStore* pLogStore, SyncIndex index);
|
int32_t (*updateCommitIndex)(struct SSyncLogStore* pLogStore, SyncIndex index);
|
||||||
|
@ -135,7 +135,9 @@ typedef struct SSyncInfo {
|
||||||
SSyncCfg syncCfg;
|
SSyncCfg syncCfg;
|
||||||
char path[TSDB_FILENAME_LEN];
|
char path[TSDB_FILENAME_LEN];
|
||||||
SSyncFSM* pFsm;
|
SSyncFSM* pFsm;
|
||||||
int32_t (*FpSendMsg)(void* handle, const SEpSet* pEpSet, SRpcMsg* pMsg);
|
|
||||||
|
void* rpcClient;
|
||||||
|
int32_t (*FpSendMsg)(void* rpcClient, const SEpSet* pEpSet, SRpcMsg* pMsg);
|
||||||
|
|
||||||
} SSyncInfo;
|
} SSyncInfo;
|
||||||
|
|
||||||
|
@ -149,8 +151,8 @@ int64_t syncStart(const SSyncInfo* pSyncInfo);
|
||||||
void syncStop(int64_t rid);
|
void syncStop(int64_t rid);
|
||||||
int32_t syncReconfig(int64_t rid, const SSyncCfg* pSyncCfg);
|
int32_t syncReconfig(int64_t rid, const SSyncCfg* pSyncCfg);
|
||||||
|
|
||||||
// int32_t syncForwardToPeer(int64_t rid, const SRpcMsg* pBuf, bool isWeak);
|
int32_t syncForwardToPeer(int64_t rid, const SRpcMsg* pBuf, bool isWeak);
|
||||||
int32_t syncForwardToPeer(int64_t rid, const SSyncBuffer* pBuf, bool isWeak);
|
// int32_t syncForwardToPeer(int64_t rid, const SSyncBuffer* pBuf, bool isWeak);
|
||||||
|
|
||||||
ESyncState syncGetMyRole(int64_t rid);
|
ESyncState syncGetMyRole(int64_t rid);
|
||||||
void syncGetNodesRole(int64_t rid, SNodesRole* pNodeRole);
|
void syncGetNodesRole(int64_t rid, SNodesRole* pNodeRole);
|
||||||
|
|
|
@ -17,6 +17,7 @@
|
||||||
#define _TD_TFS_H_
|
#define _TD_TFS_H_
|
||||||
|
|
||||||
#include "tdef.h"
|
#include "tdef.h"
|
||||||
|
#include "monitor.h"
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
extern "C" {
|
extern "C" {
|
||||||
|
@ -237,6 +238,14 @@ const STfsFile *tfsReaddir(STfsDir *pDir);
|
||||||
*/
|
*/
|
||||||
void tfsClosedir(STfsDir *pDir);
|
void tfsClosedir(STfsDir *pDir);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Get disk info of tfs.
|
||||||
|
*
|
||||||
|
* @param pTfs The fs object.
|
||||||
|
* @param pInfo The info object.
|
||||||
|
*/
|
||||||
|
int32_t tfsGetMonitorInfo(STfs *pTfs, SMonDiskInfo *pInfo);
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -24,42 +24,40 @@
|
||||||
extern "C" {
|
extern "C" {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
extern int32_t wDebugFlag;
|
|
||||||
|
|
||||||
#define wFatal(...) \
|
#define wFatal(...) \
|
||||||
{ \
|
{ \
|
||||||
if (wDebugFlag & DEBUG_FATAL) { \
|
if (wDebugFlag & DEBUG_FATAL) { \
|
||||||
taosPrintLog("WAL FATAL ", 255, __VA_ARGS__); \
|
taosPrintLog("WAL FATAL ", DEBUG_FATAL, 255, __VA_ARGS__); \
|
||||||
} \
|
} \
|
||||||
}
|
}
|
||||||
#define wError(...) \
|
#define wError(...) \
|
||||||
{ \
|
{ \
|
||||||
if (wDebugFlag & DEBUG_ERROR) { \
|
if (wDebugFlag & DEBUG_ERROR) { \
|
||||||
taosPrintLog("WAL ERROR ", 255, __VA_ARGS__); \
|
taosPrintLog("WAL ERROR ", DEBUG_ERROR, 255, __VA_ARGS__); \
|
||||||
} \
|
} \
|
||||||
}
|
}
|
||||||
#define wWarn(...) \
|
#define wWarn(...) \
|
||||||
{ \
|
{ \
|
||||||
if (wDebugFlag & DEBUG_WARN) { \
|
if (wDebugFlag & DEBUG_WARN) { \
|
||||||
taosPrintLog("WAL WARN ", 255, __VA_ARGS__); \
|
taosPrintLog("WAL WARN ", DEBUG_WARN, 255, __VA_ARGS__); \
|
||||||
} \
|
} \
|
||||||
}
|
}
|
||||||
#define wInfo(...) \
|
#define wInfo(...) \
|
||||||
{ \
|
{ \
|
||||||
if (wDebugFlag & DEBUG_INFO) { \
|
if (wDebugFlag & DEBUG_INFO) { \
|
||||||
taosPrintLog("WAL ", 255, __VA_ARGS__); \
|
taosPrintLog("WAL ", DEBUG_INFO, 255, __VA_ARGS__); \
|
||||||
} \
|
} \
|
||||||
}
|
}
|
||||||
#define wDebug(...) \
|
#define wDebug(...) \
|
||||||
{ \
|
{ \
|
||||||
if (wDebugFlag & DEBUG_DEBUG) { \
|
if (wDebugFlag & DEBUG_DEBUG) { \
|
||||||
taosPrintLog("WAL ", wDebugFlag, __VA_ARGS__); \
|
taosPrintLog("WAL ", DEBUG_DEBUG, wDebugFlag, __VA_ARGS__); \
|
||||||
} \
|
} \
|
||||||
}
|
}
|
||||||
#define wTrace(...) \
|
#define wTrace(...) \
|
||||||
{ \
|
{ \
|
||||||
if (wDebugFlag & DEBUG_TRACE) { \
|
if (wDebugFlag & DEBUG_TRACE) { \
|
||||||
taosPrintLog("WAL ", wDebugFlag, __VA_ARGS__); \
|
taosPrintLog("WAL ", DEBUG_TRACE, wDebugFlag, __VA_ARGS__); \
|
||||||
} \
|
} \
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -44,6 +44,7 @@ extern "C" {
|
||||||
#include <sys/stat.h>
|
#include <sys/stat.h>
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
#include <sys/utsname.h>
|
#include <sys/utsname.h>
|
||||||
|
#include <sys/param.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include <wchar.h>
|
#include <wchar.h>
|
||||||
#include <wctype.h>
|
#include <wctype.h>
|
||||||
|
|
|
@ -21,11 +21,12 @@ extern "C" {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
void taosRemoveDir(const char *dirname);
|
void taosRemoveDir(const char *dirname);
|
||||||
int32_t taosDirExist(char *dirname);
|
bool taosDirExist(char *dirname);
|
||||||
int32_t taosMkDir(const char *dirname);
|
int32_t taosMkDir(const char *dirname);
|
||||||
void taosRemoveOldFiles(const char *dirname, int32_t keepDays);
|
void taosRemoveOldFiles(const char *dirname, int32_t keepDays);
|
||||||
int32_t taosExpandDir(const char *dirname, char *outname, int32_t maxlen);
|
int32_t taosExpandDir(const char *dirname, char *outname, int32_t maxlen);
|
||||||
int32_t taosRealPath(char *dirname, int32_t maxlen);
|
int32_t taosRealPath(char *dirname, int32_t maxlen);
|
||||||
|
bool taosIsDir(const char *dirname);
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
|
|
|
@ -28,11 +28,11 @@ extern char tsCharset[];
|
||||||
extern char tsLocale[];
|
extern char tsLocale[];
|
||||||
extern int8_t tsDaylight;
|
extern int8_t tsDaylight;
|
||||||
extern bool tsEnableCoreFile;
|
extern bool tsEnableCoreFile;
|
||||||
extern int64_t tsPageSize;
|
extern int64_t tsPageSizeKB;
|
||||||
extern int64_t tsOpenMax;
|
extern int64_t tsOpenMax;
|
||||||
extern int64_t tsStreamMax;
|
extern int64_t tsStreamMax;
|
||||||
extern int32_t tsNumOfCores;
|
extern float tsNumOfCores;
|
||||||
extern int32_t tsTotalMemoryMB;
|
extern int64_t tsTotalMemoryKB;
|
||||||
|
|
||||||
extern char configDir[];
|
extern char configDir[];
|
||||||
extern char tsDataDir[];
|
extern char tsDataDir[];
|
||||||
|
|
|
@ -22,11 +22,18 @@ extern "C" {
|
||||||
|
|
||||||
#include "osSocket.h"
|
#include "osSocket.h"
|
||||||
|
|
||||||
|
// If the error is in a third-party library, place this header file under the third-party library header file.
|
||||||
#ifndef ALLOW_FORBID_FUNC
|
#ifndef ALLOW_FORBID_FUNC
|
||||||
#define open OPEN_FUNC_TAOS_FORBID
|
#define open OPEN_FUNC_TAOS_FORBID
|
||||||
#define fopen FOPEN_FUNC_TAOS_FORBID
|
#define fopen FOPEN_FUNC_TAOS_FORBID
|
||||||
// #define close CLOSE_FUNC_TAOS_FORBID
|
#define access ACCESS_FUNC_TAOS_FORBID
|
||||||
// #define fclose FCLOSE_FUNC_TAOS_FORBID
|
#define stat STAT_FUNC_TAOS_FORBID
|
||||||
|
#define lstat LSTAT_FUNC_TAOS_FORBID
|
||||||
|
#define fstat FSTAT_FUNC_TAOS_FORBID
|
||||||
|
#define close CLOSE_FUNC_TAOS_FORBID
|
||||||
|
#define fclose FCLOSE_FUNC_TAOS_FORBID
|
||||||
|
#define fsync FSYNC_FUNC_TAOS_FORBID
|
||||||
|
// #define fflush FFLUSH_FUNC_TAOS_FORBID
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifndef PATH_MAX
|
#ifndef PATH_MAX
|
||||||
|
@ -43,7 +50,13 @@ typedef struct TdFile *TdFilePtr;
|
||||||
#define TD_FILE_TEXT 0x0020
|
#define TD_FILE_TEXT 0x0020
|
||||||
#define TD_FILE_AUTO_DEL 0x0040
|
#define TD_FILE_AUTO_DEL 0x0040
|
||||||
#define TD_FILE_EXCL 0x0080
|
#define TD_FILE_EXCL 0x0080
|
||||||
#define TD_FILE_STREAM 0x0100 // Only support taosFprintfFile, taosGetLineFile, taosGetLineFile, taosEOFFile
|
#define TD_FILE_STREAM 0x0100 // Only support taosFprintfFile, taosGetLineFile, taosEOFFile
|
||||||
|
TdFilePtr taosOpenFile(const char *path,int32_t tdFileOptions);
|
||||||
|
|
||||||
|
#define TD_FILE_ACCESS_EXIST_OK 0x1
|
||||||
|
#define TD_FILE_ACCESS_READ_OK 0x2
|
||||||
|
#define TD_FILE_ACCESS_WRITE_OK 0x4
|
||||||
|
bool taosCheckAccessFile(const char *pathname, int mode);
|
||||||
|
|
||||||
int32_t taosLockFile(TdFilePtr pFile);
|
int32_t taosLockFile(TdFilePtr pFile);
|
||||||
int32_t taosUnLockFile(TdFilePtr pFile);
|
int32_t taosUnLockFile(TdFilePtr pFile);
|
||||||
|
@ -51,9 +64,9 @@ int32_t taosUnLockFile(TdFilePtr pFile);
|
||||||
int32_t taosUmaskFile(int32_t maskVal);
|
int32_t taosUmaskFile(int32_t maskVal);
|
||||||
|
|
||||||
int32_t taosStatFile(const char *path, int64_t *size, int32_t *mtime);
|
int32_t taosStatFile(const char *path, int64_t *size, int32_t *mtime);
|
||||||
|
int32_t taosDevInoFile(const char *path, int64_t *stDev, int64_t *stIno);
|
||||||
int32_t taosFStatFile(TdFilePtr pFile, int64_t *size, int32_t *mtime);
|
int32_t taosFStatFile(TdFilePtr pFile, int64_t *size, int32_t *mtime);
|
||||||
|
bool taosCheckExistFile(const char *pathname);
|
||||||
TdFilePtr taosOpenFile(const char *path,int32_t tdFileOptions);
|
|
||||||
|
|
||||||
int64_t taosLSeekFile(TdFilePtr pFile, int64_t offset, int32_t whence);
|
int64_t taosLSeekFile(TdFilePtr pFile, int64_t offset, int32_t whence);
|
||||||
int32_t taosFtruncateFile(TdFilePtr pFile, int64_t length);
|
int32_t taosFtruncateFile(TdFilePtr pFile, int64_t length);
|
||||||
|
@ -70,6 +83,7 @@ int64_t taosCloseFile(TdFilePtr *ppFile);
|
||||||
|
|
||||||
int32_t taosRenameFile(const char *oldName, const char *newName);
|
int32_t taosRenameFile(const char *oldName, const char *newName);
|
||||||
int64_t taosCopyFile(const char *from, const char *to);
|
int64_t taosCopyFile(const char *from, const char *to);
|
||||||
|
int32_t taosRemoveFile(const char *path);
|
||||||
|
|
||||||
void taosGetTmpfilePath(const char *inputTmpDir, const char *fileNamePrefix, char *dstPath);
|
void taosGetTmpfilePath(const char *inputTmpDir, const char *fileNamePrefix, char *dstPath);
|
||||||
|
|
||||||
|
@ -79,7 +93,7 @@ int64_t taosFSendFile(TdFilePtr pFileOut, TdFilePtr pFileIn, int64_t *offset, in
|
||||||
void *taosMmapReadOnlyFile(TdFilePtr pFile, int64_t length);
|
void *taosMmapReadOnlyFile(TdFilePtr pFile, int64_t length);
|
||||||
bool taosValidFile(TdFilePtr pFile);
|
bool taosValidFile(TdFilePtr pFile);
|
||||||
|
|
||||||
int taosGetErrorFile(TdFilePtr pFile);
|
int32_t taosGetErrorFile(TdFilePtr pFile);
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
|
|
|
@ -33,21 +33,25 @@ typedef struct {
|
||||||
SDiskSize size;
|
SDiskSize size;
|
||||||
} SDiskSpace;
|
} SDiskSpace;
|
||||||
|
|
||||||
int32_t taosGetDiskSize(char *dataDir, SDiskSize *diskSize);
|
|
||||||
int32_t taosGetCpuCores();
|
|
||||||
void taosGetSystemInfo();
|
void taosGetSystemInfo();
|
||||||
bool taosReadProcIO(int64_t *rchars, int64_t *wchars);
|
int32_t taosGetEmail(char *email, int32_t maxLen);
|
||||||
bool taosGetProcIO(float *readKB, float *writeKB);
|
int32_t taosGetOsReleaseName(char *releaseName, int32_t maxLen);
|
||||||
bool taosGetCardInfo(int64_t *bytes, int64_t *rbytes, int64_t *tbytes);
|
int32_t taosGetCpuInfo(char *cpuModel, int32_t maxLen, float *numOfCores);
|
||||||
bool taosGetBandSpeed(float *bandSpeedKb);
|
int32_t taosGetCpuCores(float *numOfCores);
|
||||||
void taosGetDisk();
|
int32_t taosGetCpuUsage(float *cpu_system, float *cpu_engine);
|
||||||
bool taosGetCpuUsage(float *sysCpuUsage, float *procCpuUsage);
|
int32_t taosGetTotalMemory(int64_t *totalKB);
|
||||||
bool taosGetProcMemory(float *memoryUsedMB);
|
int32_t taosGetProcMemory(int64_t *usedKB);
|
||||||
bool taosGetSysMemory(float *memoryUsedMB);
|
int32_t taosGetSysMemory(int64_t *usedKB);
|
||||||
int taosSystem(const char *cmd);
|
int32_t taosGetDiskSize(char *dataDir, SDiskSize *diskSize);
|
||||||
|
int32_t taosReadProcIO(int64_t *rchars, int64_t *wchars);
|
||||||
|
int32_t taosGetProcIO(float *readKB, float *writeKB);
|
||||||
|
int32_t taosGetCardInfo(int64_t *bytes, int64_t *rbytes, int64_t *tbytes);
|
||||||
|
int32_t taosGetBandSpeed(float *bandSpeedKb);
|
||||||
|
|
||||||
|
int32_t taosSystem(const char *cmd);
|
||||||
void taosKillSystem();
|
void taosKillSystem();
|
||||||
int32_t taosGetSystemUUID(char *uid, int32_t uidlen);
|
int32_t taosGetSystemUUID(char *uid, int32_t uidlen);
|
||||||
char * taosGetCmdlineByPID(int pid);
|
char *taosGetCmdlineByPID(int32_t pid);
|
||||||
void taosSetCoreDump(bool enable);
|
void taosSetCoreDump(bool enable);
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
|
|
|
@ -40,55 +40,9 @@ typedef struct SCacheStatis {
|
||||||
int64_t refreshCount;
|
int64_t refreshCount;
|
||||||
} SCacheStatis;
|
} SCacheStatis;
|
||||||
|
|
||||||
struct STrashElem;
|
typedef struct SCacheObj SCacheObj;
|
||||||
|
typedef struct SCacheIter SCacheIter;
|
||||||
typedef struct SCacheDataNode {
|
typedef struct STrashElem STrashElem;
|
||||||
uint64_t addedTime; // the added time when this element is added or updated into cache
|
|
||||||
uint64_t lifespan; // life duration when this element should be remove from cache
|
|
||||||
uint64_t expireTime; // expire time
|
|
||||||
uint64_t signature;
|
|
||||||
struct STrashElem *pTNodeHeader; // point to trash node head
|
|
||||||
uint16_t keySize : 15; // max key size: 32kb
|
|
||||||
bool inTrashcan : 1; // denote if it is in trash or not
|
|
||||||
uint32_t size; // allocated size for current SCacheDataNode
|
|
||||||
T_REF_DECLARE()
|
|
||||||
char *key;
|
|
||||||
char data[];
|
|
||||||
} SCacheDataNode;
|
|
||||||
|
|
||||||
typedef struct STrashElem {
|
|
||||||
struct STrashElem *prev;
|
|
||||||
struct STrashElem *next;
|
|
||||||
SCacheDataNode *pData;
|
|
||||||
} STrashElem;
|
|
||||||
|
|
||||||
/*
|
|
||||||
* to accommodate the old data which has the same key value of new one in hashList
|
|
||||||
* when an new node is put into cache, if an existed one with the same key:
|
|
||||||
* 1. if the old one does not be referenced, update it.
|
|
||||||
* 2. otherwise, move the old one to pTrash, addedTime the new one.
|
|
||||||
*
|
|
||||||
* when the node in pTrash does not be referenced, it will be release at the expired expiredTime
|
|
||||||
*/
|
|
||||||
typedef struct {
|
|
||||||
int64_t totalSize; // total allocated buffer in this hash table, SCacheObj is not included.
|
|
||||||
int64_t refreshTime;
|
|
||||||
STrashElem *pTrash;
|
|
||||||
char *name;
|
|
||||||
SCacheStatis statistics;
|
|
||||||
SHashObj *pHashTable;
|
|
||||||
__cache_free_fn_t freeFp;
|
|
||||||
uint32_t numOfElemsInTrash; // number of element in trash
|
|
||||||
uint8_t deleting; // set the deleting flag to stop refreshing ASAP.
|
|
||||||
pthread_t refreshWorker;
|
|
||||||
bool extendLifespan; // auto extend life span when one item is accessed.
|
|
||||||
int64_t checkTick; // tick used to record the check times of the refresh threads
|
|
||||||
#if defined(LINUX)
|
|
||||||
pthread_rwlock_t lock;
|
|
||||||
#else
|
|
||||||
pthread_mutex_t lock;
|
|
||||||
#endif
|
|
||||||
} SCacheObj;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* initialize the cache object
|
* initialize the cache object
|
||||||
|
@ -141,7 +95,7 @@ void *taosCacheAcquireByData(SCacheObj *pCacheObj, void *data);
|
||||||
* @param data
|
* @param data
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
void *taosCacheTransfer(SCacheObj *pCacheObj, void **data);
|
void *taosCacheTransferData(SCacheObj *pCacheObj, void **data);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* remove data in cache, the data will not be removed immediately.
|
* remove data in cache, the data will not be removed immediately.
|
||||||
|
@ -152,6 +106,13 @@ void *taosCacheTransfer(SCacheObj *pCacheObj, void **data);
|
||||||
*/
|
*/
|
||||||
void taosCacheRelease(SCacheObj *pCacheObj, void **data, bool _remove);
|
void taosCacheRelease(SCacheObj *pCacheObj, void **data, bool _remove);
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @param pCacheObj
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
size_t taosCacheGetNumOfObj(const SCacheObj* pCacheObj);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* move all data node into trash, clear node in trash can if it is not referenced by any clients
|
* move all data node into trash, clear node in trash can if it is not referenced by any clients
|
||||||
* @param handle
|
* @param handle
|
||||||
|
@ -184,6 +145,12 @@ void taosCacheRefresh(SCacheObj *pCacheObj, __cache_trav_fn_t fp, void *param1);
|
||||||
*/
|
*/
|
||||||
void taosStopCacheRefreshWorker();
|
void taosStopCacheRefreshWorker();
|
||||||
|
|
||||||
|
SCacheIter* taosCacheCreateIter(const SCacheObj* pCacheObj);
|
||||||
|
bool taosCacheIterNext(SCacheIter* pIter);
|
||||||
|
void* taosCacheIterGetData(const SCacheIter* pIter, size_t* dataLen);
|
||||||
|
void* taosCacheIterGetKey(const SCacheIter* pIter, size_t* keyLen);
|
||||||
|
void taosCacheDestroyIter(SCacheIter* pIter);
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -82,7 +82,7 @@ typedef struct SConfig {
|
||||||
|
|
||||||
SConfig *cfgInit();
|
SConfig *cfgInit();
|
||||||
int32_t cfgLoad(SConfig *pCfg, ECfgSrcType cfgType, const char *sourceStr);
|
int32_t cfgLoad(SConfig *pCfg, ECfgSrcType cfgType, const char *sourceStr);
|
||||||
int32_t cfgLoadArray(SConfig *pCfg, SArray *pArgs); // SConfigPair
|
int32_t cfgLoadFromArray(SConfig *pCfg, SArray *pArgs); // SConfigPair
|
||||||
void cfgCleanup(SConfig *pCfg);
|
void cfgCleanup(SConfig *pCfg);
|
||||||
|
|
||||||
int32_t cfgGetSize(SConfig *pCfg);
|
int32_t cfgGetSize(SConfig *pCfg);
|
||||||
|
|
|
@ -28,12 +28,8 @@ typedef int32_t (*_equal_fn_t)(const void *, const void *, size_t len);
|
||||||
typedef void (*_hash_before_fn_t)(void *);
|
typedef void (*_hash_before_fn_t)(void *);
|
||||||
typedef void (*_hash_free_fn_t)(void *);
|
typedef void (*_hash_free_fn_t)(void *);
|
||||||
|
|
||||||
#define HASH_MAX_CAPACITY (1024 * 1024 * 16)
|
#define HASH_KEY_ALREADY_EXISTS (-2)
|
||||||
#define HASH_DEFAULT_LOAD_FACTOR (0.75)
|
#define HASH_NODE_EXIST(code) (code == HASH_KEY_ALREADY_EXISTS)
|
||||||
|
|
||||||
#define HASH_INDEX(v, c) ((v) & ((c)-1))
|
|
||||||
|
|
||||||
#define HASH_NODE_EXIST(code) (code == -2)
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* murmur hash algorithm
|
* murmur hash algorithm
|
||||||
|
@ -54,49 +50,15 @@ uint32_t taosIntHash_32(const char *key, uint32_t len);
|
||||||
uint32_t taosIntHash_64(const char *key, uint32_t len);
|
uint32_t taosIntHash_64(const char *key, uint32_t len);
|
||||||
|
|
||||||
_hash_fn_t taosGetDefaultHashFunction(int32_t type);
|
_hash_fn_t taosGetDefaultHashFunction(int32_t type);
|
||||||
|
|
||||||
_equal_fn_t taosGetDefaultEqualFunction(int32_t type);
|
_equal_fn_t taosGetDefaultEqualFunction(int32_t type);
|
||||||
|
|
||||||
typedef struct SHashNode {
|
|
||||||
struct SHashNode *next;
|
|
||||||
uint32_t hashVal; // the hash value of key
|
|
||||||
uint32_t dataLen; // length of data
|
|
||||||
uint32_t keyLen; // length of the key
|
|
||||||
uint16_t count; // reference count
|
|
||||||
int8_t removed; // flag to indicate removed
|
|
||||||
char data[];
|
|
||||||
} SHashNode;
|
|
||||||
|
|
||||||
#define GET_HASH_NODE_KEY(_n) ((char *)(_n) + sizeof(SHashNode) + (_n)->dataLen)
|
|
||||||
#define GET_HASH_NODE_DATA(_n) ((char *)(_n) + sizeof(SHashNode))
|
|
||||||
#define GET_HASH_PNODE(_n) ((SHashNode *)((char *)(_n) - sizeof(SHashNode)))
|
|
||||||
|
|
||||||
typedef enum SHashLockTypeE {
|
typedef enum SHashLockTypeE {
|
||||||
HASH_NO_LOCK = 0,
|
HASH_NO_LOCK = 0,
|
||||||
HASH_ENTRY_LOCK = 1,
|
HASH_ENTRY_LOCK = 1,
|
||||||
} SHashLockTypeE;
|
} SHashLockTypeE;
|
||||||
|
|
||||||
typedef struct SHashEntry {
|
typedef struct SHashNode SHashNode;
|
||||||
int32_t num; // number of elements in current entry
|
typedef struct SHashObj SHashObj;
|
||||||
SRWLatch latch; // entry latch
|
|
||||||
SHashNode *next;
|
|
||||||
} SHashEntry;
|
|
||||||
|
|
||||||
typedef struct SHashObj {
|
|
||||||
SHashEntry **hashList;
|
|
||||||
uint32_t capacity; // number of slots
|
|
||||||
uint32_t size; // number of elements in hash table
|
|
||||||
|
|
||||||
_hash_fn_t hashFp; // hash function
|
|
||||||
_hash_free_fn_t freeFp; // hash node free callback function
|
|
||||||
_equal_fn_t equalFp; // equal function
|
|
||||||
_hash_before_fn_t callbackFp; // function invoked before return the value to caller
|
|
||||||
|
|
||||||
SRWLatch lock; // read-write spin lock
|
|
||||||
SHashLockTypeE type; // lock type
|
|
||||||
bool enableUpdate; // enable update
|
|
||||||
SArray *pMemBlock; // memory block allocated for SHashEntry
|
|
||||||
} SHashObj;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* init the hash table
|
* init the hash table
|
||||||
|
@ -126,8 +88,6 @@ int32_t taosHashGetSize(const SHashObj *pHashObj);
|
||||||
*/
|
*/
|
||||||
int32_t taosHashPut(SHashObj *pHashObj, const void *key, size_t keyLen, void *data, size_t size);
|
int32_t taosHashPut(SHashObj *pHashObj, const void *key, size_t keyLen, void *data, size_t size);
|
||||||
|
|
||||||
int32_t taosHashPutExt(SHashObj *pHashObj, const void *key, size_t keyLen, void *data, size_t size, bool *newAdded);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* return the payload data with the specified key
|
* return the payload data with the specified key
|
||||||
*
|
*
|
||||||
|
@ -146,17 +106,18 @@ void *taosHashGet(SHashObj *pHashObj, const void *key, size_t keyLen);
|
||||||
* @param destBuf
|
* @param destBuf
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
void *taosHashGetClone(SHashObj *pHashObj, const void *key, size_t keyLen, void *destBuf);
|
int32_t taosHashGetDup(SHashObj *pHashObj, const void *key, size_t keyLen, void *destBuf);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Clone the result to interval allocated buffer
|
*
|
||||||
* @param pHashObj
|
* @param pHashObj
|
||||||
* @param key
|
* @param key
|
||||||
* @param keyLen
|
* @param keyLen
|
||||||
* @param destBuf
|
* @param destBuf
|
||||||
|
* @param size
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
void *taosHashGetCloneExt(SHashObj *pHashObj, const void *key, size_t keyLen, void (*fp)(void *), void **d, size_t *sz);
|
int32_t taosHashGetDup_m(SHashObj* pHashObj, const void* key, size_t keyLen, void** destBuf, int32_t* size);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* remove item with the specified key
|
* remove item with the specified key
|
||||||
|
@ -210,34 +171,10 @@ void taosHashCancelIterate(SHashObj *pHashObj, void *p);
|
||||||
/**
|
/**
|
||||||
* Get the corresponding key information for a given data in hash table
|
* Get the corresponding key information for a given data in hash table
|
||||||
* @param data
|
* @param data
|
||||||
|
* @param keyLen
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
int32_t taosHashGetKey(void *data, void **key, size_t *keyLen);
|
void *taosHashGetKey(void *data, size_t* keyLen);
|
||||||
|
|
||||||
/**
|
|
||||||
* Get the corresponding key information for a given data in hash table, using memcpy
|
|
||||||
* @param data
|
|
||||||
* @param dst
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
static FORCE_INLINE int32_t taosHashCopyKey(void *data, void *dst) {
|
|
||||||
if (NULL == data || NULL == dst) {
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
SHashNode *node = GET_HASH_PNODE(data);
|
|
||||||
void *key = GET_HASH_NODE_KEY(node);
|
|
||||||
memcpy(dst, key, node->keyLen);
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get the corresponding data length for a given data in hash table
|
|
||||||
* @param data
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
int32_t taosHashGetDataLen(void *data);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* return the payload data with the specified key(reference number added)
|
* return the payload data with the specified key(reference number added)
|
||||||
|
@ -258,8 +195,20 @@ void *taosHashAcquire(SHashObj *pHashObj, const void *key, size_t keyLen);
|
||||||
*/
|
*/
|
||||||
void taosHashRelease(SHashObj *pHashObj, void *p);
|
void taosHashRelease(SHashObj *pHashObj, void *p);
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @param pHashObj
|
||||||
|
* @param fp
|
||||||
|
*/
|
||||||
void taosHashSetEqualFp(SHashObj *pHashObj, _equal_fn_t fp);
|
void taosHashSetEqualFp(SHashObj *pHashObj, _equal_fn_t fp);
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @param pHashObj
|
||||||
|
* @param fp
|
||||||
|
*/
|
||||||
|
void taosHashSetFreeFp(SHashObj *pHashObj, _hash_free_fn_t fp);
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -0,0 +1,31 @@
|
||||||
|
/*
|
||||||
|
* 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_UTIL_HTTP_H_
|
||||||
|
#define _TD_UTIL_HTTP_H_
|
||||||
|
|
||||||
|
#include "os.h"
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
|
int32_t taosSendHttpReport(const char* server, uint16_t port, const char* pCont, int32_t contLen);
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif /*_TD_UTIL_UTIL_H_*/
|
|
@ -22,9 +22,29 @@
|
||||||
extern "C" {
|
extern "C" {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
typedef enum {
|
||||||
|
DEBUG_FATAL = 1,
|
||||||
|
DEBUG_ERROR = 1,
|
||||||
|
DEBUG_WARN = 2,
|
||||||
|
DEBUG_INFO = 2,
|
||||||
|
DEBUG_DEBUG = 4,
|
||||||
|
DEBUG_TRACE = 8,
|
||||||
|
DEBUG_DUMP = 16,
|
||||||
|
DEBUG_SCREEN = 64,
|
||||||
|
DEBUG_FILE = 128
|
||||||
|
} ELogLevel;
|
||||||
|
|
||||||
|
typedef void (*LogFp)(int64_t ts, ELogLevel level, const char *content);
|
||||||
|
|
||||||
|
extern bool tsLogEmbedded;
|
||||||
extern bool tsAsyncLog;
|
extern bool tsAsyncLog;
|
||||||
extern int32_t tsNumOfLogLines;
|
extern int32_t tsNumOfLogLines;
|
||||||
extern int32_t tsLogKeepDays;
|
extern int32_t tsLogKeepDays;
|
||||||
|
extern LogFp tsLogFp;
|
||||||
|
extern int64_t tsNumOfErrorLogs;
|
||||||
|
extern int64_t tsNumOfInfoLogs;
|
||||||
|
extern int64_t tsNumOfDebugLogs;
|
||||||
|
extern int64_t tsNumOfTraceLogs;
|
||||||
extern int32_t dDebugFlag;
|
extern int32_t dDebugFlag;
|
||||||
extern int32_t vDebugFlag;
|
extern int32_t vDebugFlag;
|
||||||
extern int32_t mDebugFlag;
|
extern int32_t mDebugFlag;
|
||||||
|
@ -40,45 +60,33 @@ extern int32_t tsdbDebugFlag;
|
||||||
extern int32_t tqDebugFlag;
|
extern int32_t tqDebugFlag;
|
||||||
extern int32_t fsDebugFlag;
|
extern int32_t fsDebugFlag;
|
||||||
|
|
||||||
#define DEBUG_FATAL 1U
|
|
||||||
#define DEBUG_ERROR DEBUG_FATAL
|
|
||||||
#define DEBUG_WARN 2U
|
|
||||||
#define DEBUG_INFO DEBUG_WARN
|
|
||||||
#define DEBUG_DEBUG 4U
|
|
||||||
#define DEBUG_TRACE 8U
|
|
||||||
#define DEBUG_DUMP 16U
|
|
||||||
#define DEBUG_SCREEN 64U
|
|
||||||
#define DEBUG_FILE 128U
|
|
||||||
|
|
||||||
int32_t taosInitLog(const char *logName, int32_t maxFiles);
|
int32_t taosInitLog(const char *logName, int32_t maxFiles);
|
||||||
void taosCloseLog();
|
void taosCloseLog();
|
||||||
void taosResetLog();
|
void taosResetLog();
|
||||||
void taosSetAllDebugFlag(int32_t flag);
|
void taosSetAllDebugFlag(int32_t flag);
|
||||||
void taosDumpData(uint8_t *msg, int32_t len);
|
void taosDumpData(uint8_t *msg, int32_t len);
|
||||||
|
|
||||||
void taosPrintLog(const char *flags, int32_t dflag, const char *format, ...)
|
void taosPrintLog(const char *flags, ELogLevel level, int32_t dflag, const char *format, ...)
|
||||||
#ifdef __GNUC__
|
#ifdef __GNUC__
|
||||||
__attribute__((format(printf, 3, 4)))
|
__attribute__((format(printf, 4, 5)))
|
||||||
#endif
|
#endif
|
||||||
;
|
;
|
||||||
|
|
||||||
void taosPrintLongString(const char *flags, int32_t dflag, const char *format, ...)
|
void taosPrintLongString(const char *flags, ELogLevel level, int32_t dflag, const char *format, ...)
|
||||||
#ifdef __GNUC__
|
#ifdef __GNUC__
|
||||||
__attribute__((format(printf, 3, 4)))
|
__attribute__((format(printf, 4, 5)))
|
||||||
#endif
|
#endif
|
||||||
;
|
;
|
||||||
|
|
||||||
extern int8_t tscEmbeddedInUtil;
|
#define uFatal(...) { if (uDebugFlag & DEBUG_FATAL) { taosPrintLog("UTL FATAL", DEBUG_FATAL, tsLogEmbedded ? 255 : uDebugFlag, __VA_ARGS__); }}
|
||||||
|
#define uError(...) { if (uDebugFlag & DEBUG_ERROR) { taosPrintLog("UTL ERROR ", DEBUG_ERROR, tsLogEmbedded ? 255 : uDebugFlag, __VA_ARGS__); }}
|
||||||
|
#define uWarn(...) { if (uDebugFlag & DEBUG_WARN) { taosPrintLog("UTL WARN ", DEBUG_WARN, tsLogEmbedded ? 255 : uDebugFlag, __VA_ARGS__); }}
|
||||||
|
#define uInfo(...) { if (uDebugFlag & DEBUG_INFO) { taosPrintLog("UTL ", DEBUG_INFO, tsLogEmbedded ? 255 : uDebugFlag, __VA_ARGS__); }}
|
||||||
|
#define uDebug(...) { if (uDebugFlag & DEBUG_DEBUG) { taosPrintLog("UTL ", DEBUG_DEBUG, uDebugFlag, __VA_ARGS__); }}
|
||||||
|
#define uTrace(...) { if (uDebugFlag & DEBUG_TRACE) { taosPrintLog("UTL ", DEBUG_TRACE, uDebugFlag, __VA_ARGS__); }}
|
||||||
|
|
||||||
#define uFatal(...) { if (uDebugFlag & DEBUG_FATAL) { taosPrintLog("UTL FATAL", tscEmbeddedInUtil ? 255 : uDebugFlag, __VA_ARGS__); }}
|
#define pError(...) { taosPrintLog("APP ERROR ", DEBUG_ERROR, 255, __VA_ARGS__); }
|
||||||
#define uError(...) { if (uDebugFlag & DEBUG_ERROR) { taosPrintLog("UTL ERROR ", tscEmbeddedInUtil ? 255 : uDebugFlag, __VA_ARGS__); }}
|
#define pPrint(...) { taosPrintLog("APP ", DEBUG_INFO, 255, __VA_ARGS__); }
|
||||||
#define uWarn(...) { if (uDebugFlag & DEBUG_WARN) { taosPrintLog("UTL WARN ", tscEmbeddedInUtil ? 255 : uDebugFlag, __VA_ARGS__); }}
|
|
||||||
#define uInfo(...) { if (uDebugFlag & DEBUG_INFO) { taosPrintLog("UTL ", tscEmbeddedInUtil ? 255 : uDebugFlag, __VA_ARGS__); }}
|
|
||||||
#define uDebug(...) { if (uDebugFlag & DEBUG_DEBUG) { taosPrintLog("UTL ", uDebugFlag, __VA_ARGS__); }}
|
|
||||||
#define uTrace(...) { if (uDebugFlag & DEBUG_TRACE) { taosPrintLog("UTL ", uDebugFlag, __VA_ARGS__); }}
|
|
||||||
|
|
||||||
#define pError(...) { taosPrintLog("APP ERROR ", 255, __VA_ARGS__); }
|
|
||||||
#define pPrint(...) { taosPrintLog("APP ", 255, __VA_ARGS__); }
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
|
|
|
@ -53,7 +53,7 @@ typedef struct SDiskbasedBufStatis {
|
||||||
* @param handle
|
* @param handle
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
int32_t createDiskbasedBuf(SDiskbasedBuf** pBuf, int32_t pagesize, int32_t inMemBufSize, uint64_t qId, const char* dir);
|
int32_t createDiskbasedBuf(SDiskbasedBuf** pBuf, int32_t pagesize, int32_t inMemBufSize, const char* id, const char* dir);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
|
|
|
@ -24,8 +24,8 @@ extern "C" {
|
||||||
#include "query.h"
|
#include "query.h"
|
||||||
#include "taos.h"
|
#include "taos.h"
|
||||||
#include "tcommon.h"
|
#include "tcommon.h"
|
||||||
|
#include "tdatablock.h"
|
||||||
#include "tdef.h"
|
#include "tdef.h"
|
||||||
#include "tep.h"
|
|
||||||
#include "thash.h"
|
#include "thash.h"
|
||||||
#include "tlist.h"
|
#include "tlist.h"
|
||||||
#include "tmsg.h"
|
#include "tmsg.h"
|
||||||
|
@ -167,7 +167,7 @@ typedef struct SRequestSendRecvBody {
|
||||||
void* fp;
|
void* fp;
|
||||||
SShowReqInfo showInfo; // todo this attribute will be removed after the query framework being completed.
|
SShowReqInfo showInfo; // todo this attribute will be removed after the query framework being completed.
|
||||||
SDataBuf requestMsg;
|
SDataBuf requestMsg;
|
||||||
struct SSchJob* pQueryJob; // query job, created according to sql query DAG.
|
int64_t queryJob; // query job, created according to sql query DAG.
|
||||||
struct SQueryDag* pDag; // the query dag, generated according to the sql statement.
|
struct SQueryDag* pDag; // the query dag, generated according to the sql statement.
|
||||||
SReqResultInfo resInfo;
|
SReqResultInfo resInfo;
|
||||||
} SRequestSendRecvBody;
|
} SRequestSendRecvBody;
|
||||||
|
|
|
@ -22,13 +22,13 @@ extern "C" {
|
||||||
|
|
||||||
#include "tlog.h"
|
#include "tlog.h"
|
||||||
|
|
||||||
#define tscFatal(...) do { if (cDebugFlag & DEBUG_FATAL) { taosPrintLog("TSC FATAL ", cDebugFlag, __VA_ARGS__); }} while(0)
|
#define tscFatal(...) do { if (cDebugFlag & DEBUG_FATAL) { taosPrintLog("TSC FATAL ", DEBUG_FATAL, cDebugFlag, __VA_ARGS__); }} while(0)
|
||||||
#define tscError(...) do { if (cDebugFlag & DEBUG_ERROR) { taosPrintLog("TSC ERROR ", cDebugFlag, __VA_ARGS__); }} while(0)
|
#define tscError(...) do { if (cDebugFlag & DEBUG_ERROR) { taosPrintLog("TSC ERROR ", DEBUG_ERROR, cDebugFlag, __VA_ARGS__); }} while(0)
|
||||||
#define tscWarn(...) do { if (cDebugFlag & DEBUG_WARN) { taosPrintLog("TSC WARN ", cDebugFlag, __VA_ARGS__); }} while(0)
|
#define tscWarn(...) do { if (cDebugFlag & DEBUG_WARN) { taosPrintLog("TSC WARN ", DEBUG_WARN, cDebugFlag, __VA_ARGS__); }} while(0)
|
||||||
#define tscInfo(...) do { if (cDebugFlag & DEBUG_INFO) { taosPrintLog("TSC ", cDebugFlag, __VA_ARGS__); }} while(0)
|
#define tscInfo(...) do { if (cDebugFlag & DEBUG_INFO) { taosPrintLog("TSC ", DEBUG_INFO, cDebugFlag, __VA_ARGS__); }} while(0)
|
||||||
#define tscDebug(...) do { if (cDebugFlag & DEBUG_DEBUG) { taosPrintLog("TSC ", cDebugFlag, __VA_ARGS__); }} while(0)
|
#define tscDebug(...) do { if (cDebugFlag & DEBUG_DEBUG) { taosPrintLog("TSC ", DEBUG_DEBUG, cDebugFlag, __VA_ARGS__); }} while(0)
|
||||||
#define tscTrace(...) do { if (cDebugFlag & DEBUG_TRACE) { taosPrintLog("TSC ", cDebugFlag, __VA_ARGS__); }} while(0)
|
#define tscTrace(...) do { if (cDebugFlag & DEBUG_TRACE) { taosPrintLog("TSC ", DEBUG_TRACE, cDebugFlag, __VA_ARGS__); }} while(0)
|
||||||
#define tscDebugL(...) do { if (cDebugFlag & DEBUG_DEBUG) { taosPrintLongString("TSC ", cDebugFlag, __VA_ARGS__); }} while(0)
|
#define tscDebugL(...) do { if (cDebugFlag & DEBUG_DEBUG) { taosPrintLongString("TSC ", DEBUG_DEBUG, cDebugFlag, __VA_ARGS__); }} while(0)
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
|
|
|
@ -480,7 +480,8 @@ SAppHbMgr *appHbMgrInit(SAppInstInfo *pAppInstInfo, char *key) {
|
||||||
free(pAppHbMgr);
|
free(pAppHbMgr);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
pAppHbMgr->activeInfo->freeFp = tFreeClientHbReq;
|
|
||||||
|
taosHashSetFreeFp(pAppHbMgr->activeInfo, tFreeClientHbReq);
|
||||||
// init getInfoFunc
|
// init getInfoFunc
|
||||||
pAppHbMgr->connInfo = taosHashInit(64, hbKeyHashFunc, 1, HASH_ENTRY_LOCK);
|
pAppHbMgr->connInfo = taosHashInit(64, hbKeyHashFunc, 1, HASH_ENTRY_LOCK);
|
||||||
|
|
||||||
|
|
|
@ -4,8 +4,8 @@
|
||||||
#include "parser.h"
|
#include "parser.h"
|
||||||
#include "planner.h"
|
#include "planner.h"
|
||||||
#include "scheduler.h"
|
#include "scheduler.h"
|
||||||
|
#include "tdatablock.h"
|
||||||
#include "tdef.h"
|
#include "tdef.h"
|
||||||
#include "tep.h"
|
|
||||||
#include "tglobal.h"
|
#include "tglobal.h"
|
||||||
#include "tmsgtype.h"
|
#include "tmsgtype.h"
|
||||||
#include "tpagedbuf.h"
|
#include "tpagedbuf.h"
|
||||||
|
@ -227,10 +227,10 @@ void setResSchemaInfo(SReqResultInfo* pResInfo, const SSchema* pSchema, int32_t
|
||||||
int32_t scheduleQuery(SRequestObj* pRequest, SQueryDag* pDag, SArray* pNodeList) {
|
int32_t scheduleQuery(SRequestObj* pRequest, SQueryDag* pDag, SArray* pNodeList) {
|
||||||
void* pTransporter = pRequest->pTscObj->pAppInfo->pTransporter;
|
void* pTransporter = pRequest->pTscObj->pAppInfo->pTransporter;
|
||||||
SQueryResult res = {.code = 0, .numOfRows = 0, .msgSize = ERROR_MSG_BUF_DEFAULT_SIZE, .msg = pRequest->msgBuf};
|
SQueryResult res = {.code = 0, .numOfRows = 0, .msgSize = ERROR_MSG_BUF_DEFAULT_SIZE, .msg = pRequest->msgBuf};
|
||||||
int32_t code = schedulerExecJob(pTransporter, pNodeList, pDag, &pRequest->body.pQueryJob, pRequest->sqlstr, &res);
|
int32_t code = schedulerExecJob(pTransporter, pNodeList, pDag, &pRequest->body.queryJob, pRequest->sqlstr, &res);
|
||||||
if (code != TSDB_CODE_SUCCESS) {
|
if (code != TSDB_CODE_SUCCESS) {
|
||||||
if (pRequest->body.pQueryJob != NULL) {
|
if (pRequest->body.queryJob != 0) {
|
||||||
schedulerFreeJob(pRequest->body.pQueryJob);
|
schedulerFreeJob(pRequest->body.queryJob);
|
||||||
}
|
}
|
||||||
|
|
||||||
pRequest->code = code;
|
pRequest->code = code;
|
||||||
|
@ -240,8 +240,8 @@ int32_t scheduleQuery(SRequestObj* pRequest, SQueryDag* pDag, SArray* pNodeList)
|
||||||
if (TSDB_SQL_INSERT == pRequest->type || TSDB_SQL_CREATE_TABLE == pRequest->type) {
|
if (TSDB_SQL_INSERT == pRequest->type || TSDB_SQL_CREATE_TABLE == pRequest->type) {
|
||||||
pRequest->body.resInfo.numOfRows = res.numOfRows;
|
pRequest->body.resInfo.numOfRows = res.numOfRows;
|
||||||
|
|
||||||
if (pRequest->body.pQueryJob != NULL) {
|
if (pRequest->body.queryJob != 0) {
|
||||||
schedulerFreeJob(pRequest->body.pQueryJob);
|
schedulerFreeJob(pRequest->body.queryJob);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -435,11 +435,7 @@ void processMsgFromServer(void* parent, SRpcMsg* pMsg, SEpSet* pEpSet) {
|
||||||
taosReleaseRef(clientReqRefPool, pSendInfo->requestObjRefId);
|
taosReleaseRef(clientReqRefPool, pSendInfo->requestObjRefId);
|
||||||
}
|
}
|
||||||
|
|
||||||
SDataBuf buf = {
|
SDataBuf buf = {.len = pMsg->contLen, .pData = NULL, .handle = pMsg->handle};
|
||||||
.len = pMsg->contLen,
|
|
||||||
.pData = NULL,
|
|
||||||
.handle = pMsg->handle,
|
|
||||||
};
|
|
||||||
|
|
||||||
if (pMsg->contLen > 0) {
|
if (pMsg->contLen > 0) {
|
||||||
buf.pData = calloc(1, pMsg->contLen);
|
buf.pData = calloc(1, pMsg->contLen);
|
||||||
|
@ -498,7 +494,7 @@ void* doFetchRow(SRequestObj* pRequest) {
|
||||||
}
|
}
|
||||||
|
|
||||||
SReqResultInfo* pResInfo = &pRequest->body.resInfo;
|
SReqResultInfo* pResInfo = &pRequest->body.resInfo;
|
||||||
int32_t code = schedulerFetchRows(pRequest->body.pQueryJob, (void**)&pResInfo->pData);
|
int32_t code = schedulerFetchRows(pRequest->body.queryJob, (void**)&pResInfo->pData);
|
||||||
if (code != TSDB_CODE_SUCCESS) {
|
if (code != TSDB_CODE_SUCCESS) {
|
||||||
pRequest->code = code;
|
pRequest->code = code;
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
|
@ -13,12 +13,13 @@
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "catalog.h"
|
|
||||||
#include "clientInt.h"
|
|
||||||
#include "clientLog.h"
|
|
||||||
#include "os.h"
|
#include "os.h"
|
||||||
#include "tdef.h"
|
#include "tdef.h"
|
||||||
#include "tname.h"
|
#include "tname.h"
|
||||||
|
#include "clientInt.h"
|
||||||
|
#include "clientLog.h"
|
||||||
|
#include "catalog.h"
|
||||||
|
#include "query.h"
|
||||||
|
|
||||||
int32_t (*handleRequestRspFp[TDMT_MAX])(void*, const SDataBuf* pMsg, int32_t code);
|
int32_t (*handleRequestRspFp[TDMT_MAX])(void*, const SDataBuf* pMsg, int32_t code);
|
||||||
|
|
||||||
|
@ -103,7 +104,6 @@ SMsgSendInfo* buildMsgInfoImpl(SRequestObj* pRequest) {
|
||||||
} else {
|
} else {
|
||||||
SVShowTablesFetchReq* pFetchMsg = calloc(1, sizeof(SVShowTablesFetchReq));
|
SVShowTablesFetchReq* pFetchMsg = calloc(1, sizeof(SVShowTablesFetchReq));
|
||||||
if (pFetchMsg == NULL) {
|
if (pFetchMsg == NULL) {
|
||||||
free(pMsgSendInfo);
|
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -119,9 +119,7 @@ SMsgSendInfo* buildMsgInfoImpl(SRequestObj* pRequest) {
|
||||||
pMsgSendInfo->msgInfo = pRequest->body.requestMsg;
|
pMsgSendInfo->msgInfo = pRequest->body.requestMsg;
|
||||||
}
|
}
|
||||||
|
|
||||||
pMsgSendInfo->fp = (handleRequestRspFp[TMSG_INDEX(pRequest->type)] == NULL)
|
pMsgSendInfo->fp = (handleRequestRspFp[TMSG_INDEX(pRequest->type)] == NULL)? genericRspCallback:handleRequestRspFp[TMSG_INDEX(pRequest->type)];
|
||||||
? genericRspCallback
|
|
||||||
: handleRequestRspFp[TMSG_INDEX(pRequest->type)];
|
|
||||||
return pMsgSendInfo;
|
return pMsgSendInfo;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -246,6 +244,23 @@ int32_t processCreateDbRsp(void* param, const SDataBuf* pMsg, int32_t code) {
|
||||||
int32_t processUseDbRsp(void* param, const SDataBuf* pMsg, int32_t code) {
|
int32_t processUseDbRsp(void* param, const SDataBuf* pMsg, int32_t code) {
|
||||||
SRequestObj* pRequest = param;
|
SRequestObj* pRequest = param;
|
||||||
|
|
||||||
|
if (TSDB_CODE_MND_DB_NOT_EXIST == code) {
|
||||||
|
SUseDbRsp usedbRsp = {0};
|
||||||
|
tDeserializeSUseDbRsp(pMsg->pData, pMsg->len, &usedbRsp);
|
||||||
|
struct SCatalog *pCatalog = NULL;
|
||||||
|
|
||||||
|
if (usedbRsp.vgVersion >= 0) {
|
||||||
|
int32_t code = catalogGetHandle(pRequest->pTscObj->pAppInfo->clusterId, &pCatalog);
|
||||||
|
if (code != TSDB_CODE_SUCCESS) {
|
||||||
|
tscWarn("catalogGetHandle failed, clusterId:%"PRIx64", error:%s", pRequest->pTscObj->pAppInfo->clusterId, tstrerror(code));
|
||||||
|
} else {
|
||||||
|
catalogRemoveDB(pCatalog, usedbRsp.db, usedbRsp.uid);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
tFreeSUsedbRsp(&usedbRsp);
|
||||||
|
}
|
||||||
|
|
||||||
if (code != TSDB_CODE_SUCCESS) {
|
if (code != TSDB_CODE_SUCCESS) {
|
||||||
free(pMsg->pData);
|
free(pMsg->pData);
|
||||||
setErrno(pRequest, code);
|
setErrno(pRequest, code);
|
||||||
|
@ -259,6 +274,26 @@ int32_t processUseDbRsp(void* param, const SDataBuf* pMsg, int32_t code) {
|
||||||
SName name = {0};
|
SName name = {0};
|
||||||
tNameFromString(&name, usedbRsp.db, T_NAME_ACCT|T_NAME_DB);
|
tNameFromString(&name, usedbRsp.db, T_NAME_ACCT|T_NAME_DB);
|
||||||
|
|
||||||
|
SUseDbOutput output = {0};
|
||||||
|
code = queryBuildUseDbOutput(&output, &usedbRsp);
|
||||||
|
|
||||||
|
if (code != 0) {
|
||||||
|
terrno = code;
|
||||||
|
if (output.dbVgroup) taosHashCleanup(output.dbVgroup->vgHash);
|
||||||
|
tfree(output.dbVgroup);
|
||||||
|
|
||||||
|
tscError("failed to build use db output since %s", terrstr());
|
||||||
|
} else {
|
||||||
|
struct SCatalog *pCatalog = NULL;
|
||||||
|
|
||||||
|
int32_t code = catalogGetHandle(pRequest->pTscObj->pAppInfo->clusterId, &pCatalog);
|
||||||
|
if (code != TSDB_CODE_SUCCESS) {
|
||||||
|
tscWarn("catalogGetHandle failed, clusterId:%"PRIx64", error:%s", pRequest->pTscObj->pAppInfo->clusterId, tstrerror(code));
|
||||||
|
} else {
|
||||||
|
catalogUpdateDBVgInfo(pCatalog, output.db, output.dbId, output.dbVgroup);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
tFreeSUsedbRsp(&usedbRsp);
|
tFreeSUsedbRsp(&usedbRsp);
|
||||||
|
|
||||||
char db[TSDB_DB_NAME_LEN] = {0};
|
char db[TSDB_DB_NAME_LEN] = {0};
|
||||||
|
|
|
@ -20,8 +20,8 @@
|
||||||
#include "parser.h"
|
#include "parser.h"
|
||||||
#include "planner.h"
|
#include "planner.h"
|
||||||
#include "scheduler.h"
|
#include "scheduler.h"
|
||||||
|
#include "tdatablock.h"
|
||||||
#include "tdef.h"
|
#include "tdef.h"
|
||||||
#include "tep.h"
|
|
||||||
#include "tglobal.h"
|
#include "tglobal.h"
|
||||||
#include "tmsgtype.h"
|
#include "tmsgtype.h"
|
||||||
#include "tpagedbuf.h"
|
#include "tpagedbuf.h"
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
aux_source_directory(src COMMON_SRC)
|
aux_source_directory(src COMMON_SRC)
|
||||||
add_library(common ${COMMON_SRC})
|
add_library(common STATIC ${COMMON_SRC})
|
||||||
target_include_directories(
|
target_include_directories(
|
||||||
common
|
common
|
||||||
PUBLIC "${CMAKE_SOURCE_DIR}/include/common"
|
PUBLIC "${CMAKE_SOURCE_DIR}/include/common"
|
||||||
|
|
|
@ -14,7 +14,7 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#define _DEFAULT_SOURCE
|
#define _DEFAULT_SOURCE
|
||||||
#include "tep.h"
|
#include "tdatablock.h"
|
||||||
#include "tcompare.h"
|
#include "tcompare.h"
|
||||||
#include "tglobal.h"
|
#include "tglobal.h"
|
||||||
|
|
|
@ -17,7 +17,7 @@
|
||||||
#include "tglobal.h"
|
#include "tglobal.h"
|
||||||
#include "tcompare.h"
|
#include "tcompare.h"
|
||||||
#include "tconfig.h"
|
#include "tconfig.h"
|
||||||
#include "tep.h"
|
#include "tdatablock.h"
|
||||||
#include "tlog.h"
|
#include "tlog.h"
|
||||||
|
|
||||||
SConfig *tsCfg = NULL;
|
SConfig *tsCfg = NULL;
|
||||||
|
@ -46,6 +46,13 @@ int32_t tsMaxBinaryDisplayWidth = 30;
|
||||||
bool tsEnableSlaveQuery = 1;
|
bool tsEnableSlaveQuery = 1;
|
||||||
bool tsPrintAuth = 0;
|
bool tsPrintAuth = 0;
|
||||||
|
|
||||||
|
// monitor
|
||||||
|
bool tsEnableMonitor = 1;
|
||||||
|
int32_t tsMonitorInterval = 5;
|
||||||
|
char tsMonitorFqdn[TSDB_FQDN_LEN] = {0};
|
||||||
|
uint16_t tsMonitorPort = 6043;
|
||||||
|
int32_t tsMonitorMaxLogs = 100;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* denote if the server needs to compress response message at the application layer to client, including query rsp,
|
* denote if the server needs to compress response message at the application layer to client, including query rsp,
|
||||||
* metricmeta rsp, and multi-meter query rsp message body. The client compress the submit message to server.
|
* metricmeta rsp, and multi-meter query rsp message body. The client compress the submit message to server.
|
||||||
|
@ -148,23 +155,42 @@ static void taosAddDataDir(int32_t index, char *v1, int32_t level, int32_t prima
|
||||||
uTrace("dataDir:%s, level:%d primary:%d is configured", v1, level, primary);
|
uTrace("dataDir:%s, level:%d primary:%d is configured", v1, level, primary);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void taosSetTfsCfg(SConfig *pCfg) {
|
static int32_t taosSetTfsCfg(SConfig *pCfg) {
|
||||||
SConfigItem *pItem = cfgGetItem(pCfg, "dataDir");
|
SConfigItem *pItem = cfgGetItem(pCfg, "dataDir");
|
||||||
if (pItem == NULL) return;
|
memset(tsDataDir, 0, PATH_MAX);
|
||||||
|
|
||||||
int32_t size = taosArrayGetSize(pItem->array);
|
int32_t size = taosArrayGetSize(pItem->array);
|
||||||
if (size <= 0) {
|
if (size <= 0) {
|
||||||
tsDiskCfgNum = 1;
|
tsDiskCfgNum = 1;
|
||||||
taosAddDataDir(0, pItem->str, 0, 1);
|
taosAddDataDir(0, pItem->str, 0, 1);
|
||||||
|
tstrncpy(tsDataDir, pItem->str, PATH_MAX);
|
||||||
|
if (taosMkDir(tsDataDir) != 0) {
|
||||||
|
uError("failed to create dataDir:%s since %s", tsDataDir, terrstr());
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
tsDiskCfgNum = size < TFS_MAX_DISKS ? size : TFS_MAX_DISKS;
|
tsDiskCfgNum = size < TFS_MAX_DISKS ? size : TFS_MAX_DISKS;
|
||||||
for (int32_t index = 0; index < tsDiskCfgNum; ++index) {
|
for (int32_t index = 0; index < tsDiskCfgNum; ++index) {
|
||||||
SDiskCfg *pCfg = taosArrayGet(pItem->array, index);
|
SDiskCfg *pCfg = taosArrayGet(pItem->array, index);
|
||||||
memcpy(&tsDiskCfg[index], pCfg, sizeof(SDiskCfg));
|
memcpy(&tsDiskCfg[index], pCfg, sizeof(SDiskCfg));
|
||||||
|
if (pCfg->level == 0 && pCfg->primary == 1) {
|
||||||
|
tstrncpy(tsDataDir, pCfg->dir, PATH_MAX);
|
||||||
|
}
|
||||||
|
if (taosMkDir(pCfg->dir) != 0) {
|
||||||
|
uError("failed to create tfsDir:%s since %s", tsDataDir, terrstr());
|
||||||
|
return -1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (tsDataDir[0] == 0) {
|
||||||
|
uError("datadir not set");
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
struct SConfig *taosGetCfg() {
|
struct SConfig *taosGetCfg() {
|
||||||
return tsCfg;
|
return tsCfg;
|
||||||
}
|
}
|
||||||
|
@ -177,24 +203,24 @@ static int32_t taosLoadCfg(SConfig *pCfg, const char *inputCfgDir, const char *e
|
||||||
snprintf(cfgFile, sizeof(cfgFile), "%s" TD_DIRSEP "taos.cfg", cfgDir);
|
snprintf(cfgFile, sizeof(cfgFile), "%s" TD_DIRSEP "taos.cfg", cfgDir);
|
||||||
|
|
||||||
if (cfgLoad(pCfg, CFG_STYPE_APOLLO_URL, apolloUrl) != 0) {
|
if (cfgLoad(pCfg, CFG_STYPE_APOLLO_URL, apolloUrl) != 0) {
|
||||||
uError("failed to load from apollo url:%s since %s\n", apolloUrl, terrstr());
|
uError("failed to load from apollo url:%s since %s", apolloUrl, terrstr());
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (cfgLoad(pCfg, CFG_STYPE_CFG_FILE, cfgFile) != 0) {
|
|
||||||
if (cfgLoad(pCfg, CFG_STYPE_CFG_FILE, cfgDir) != 0) {
|
if (cfgLoad(pCfg, CFG_STYPE_CFG_FILE, cfgDir) != 0) {
|
||||||
uError("failed to load from config file:%s since %s\n", cfgFile, terrstr());
|
if (cfgLoad(pCfg, CFG_STYPE_CFG_FILE, cfgFile) != 0) {
|
||||||
return -1;
|
uError("failed to load from config file:%s since %s", cfgFile, terrstr());
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (cfgLoad(pCfg, CFG_STYPE_ENV_FILE, envFile) != 0) {
|
if (cfgLoad(pCfg, CFG_STYPE_ENV_FILE, envFile) != 0) {
|
||||||
uError("failed to load from env file:%s since %s\n", envFile, terrstr());
|
uError("failed to load from env file:%s since %s", envFile, terrstr());
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (cfgLoad(pCfg, CFG_STYPE_ENV_VAR, NULL) != 0) {
|
if (cfgLoad(pCfg, CFG_STYPE_ENV_VAR, NULL) != 0) {
|
||||||
uError("failed to load from global env variables since %s\n", terrstr());
|
uError("failed to load from global env variables since %s", terrstr());
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -271,12 +297,12 @@ static int32_t taosAddSystemCfg(SConfig *pCfg) {
|
||||||
if (cfgAddTimezone(pCfg, "timezone", tsTimezone) != 0) return -1;
|
if (cfgAddTimezone(pCfg, "timezone", tsTimezone) != 0) return -1;
|
||||||
if (cfgAddLocale(pCfg, "locale", tsLocale) != 0) return -1;
|
if (cfgAddLocale(pCfg, "locale", tsLocale) != 0) return -1;
|
||||||
if (cfgAddCharset(pCfg, "charset", tsCharset) != 0) return -1;
|
if (cfgAddCharset(pCfg, "charset", tsCharset) != 0) return -1;
|
||||||
if (cfgAddBool(pCfg, "enableCoreFile", 0, 1) != 0) return -1;
|
if (cfgAddBool(pCfg, "enableCoreFile", 1, 1) != 0) return -1;
|
||||||
if (cfgAddInt32(pCfg, "numOfCores", tsNumOfCores, 1, 100000, 1) != 0) return -1;
|
if (cfgAddFloat(pCfg, "numOfCores", tsNumOfCores, 0, 100000, 1) != 0) return -1;
|
||||||
if (cfgAddInt32(pCfg, "pageSize(KB)", tsPageSize, 0, INT64_MAX, 1) != 0) return -1;
|
|
||||||
if (cfgAddInt64(pCfg, "openMax", tsOpenMax, 0, INT64_MAX, 1) != 0) return -1;
|
if (cfgAddInt64(pCfg, "openMax", tsOpenMax, 0, INT64_MAX, 1) != 0) return -1;
|
||||||
if (cfgAddInt64(pCfg, "streamMax", tsStreamMax, 0, INT64_MAX, 1) != 0) return -1;
|
if (cfgAddInt64(pCfg, "streamMax", tsStreamMax, 0, INT64_MAX, 1) != 0) return -1;
|
||||||
if (cfgAddInt32(pCfg, "totalMemory(MB)", tsTotalMemoryMB, 0, INT32_MAX, 1) != 0) return -1;
|
if (cfgAddInt32(pCfg, "pageSize(KB)", tsPageSizeKB, 0, INT64_MAX, 1) != 0) return -1;
|
||||||
|
if (cfgAddInt64(pCfg, "totalMemory(KB)", tsTotalMemoryKB, 0, INT64_MAX, 1) != 0) return -1;
|
||||||
if (cfgAddString(pCfg, "os sysname", info.sysname, 1) != 0) return -1;
|
if (cfgAddString(pCfg, "os sysname", info.sysname, 1) != 0) return -1;
|
||||||
if (cfgAddString(pCfg, "os nodename", info.nodename, 1) != 0) return -1;
|
if (cfgAddString(pCfg, "os nodename", info.nodename, 1) != 0) return -1;
|
||||||
if (cfgAddString(pCfg, "os release", info.release, 1) != 0) return -1;
|
if (cfgAddString(pCfg, "os release", info.release, 1) != 0) return -1;
|
||||||
|
@ -314,6 +340,13 @@ static int32_t taosAddServerCfg(SConfig *pCfg) {
|
||||||
if (cfgAddBool(pCfg, "printAuth", tsPrintAuth, 0) != 0) return -1;
|
if (cfgAddBool(pCfg, "printAuth", tsPrintAuth, 0) != 0) return -1;
|
||||||
if (cfgAddBool(pCfg, "slaveQuery", tsEnableSlaveQuery, 0) != 0) return -1;
|
if (cfgAddBool(pCfg, "slaveQuery", tsEnableSlaveQuery, 0) != 0) return -1;
|
||||||
if (cfgAddBool(pCfg, "deadLockKillQuery", tsDeadLockKillQuery, 0) != 0) return -1;
|
if (cfgAddBool(pCfg, "deadLockKillQuery", tsDeadLockKillQuery, 0) != 0) return -1;
|
||||||
|
|
||||||
|
if (cfgAddBool(pCfg, "monitor", tsEnableMonitor, 0) != 0) return -1;
|
||||||
|
if (cfgAddInt32(pCfg, "monitorInterval", tsMonitorInterval, 1, 360000, 0) != 0) return -1;
|
||||||
|
if (cfgAddString(pCfg, "monitorFqdn", tsMonitorFqdn, 0) != 0) return -1;
|
||||||
|
if (cfgAddInt32(pCfg, "monitorPort", tsMonitorPort, 1, 65056, 0) != 0) return -1;
|
||||||
|
if (cfgAddInt32(pCfg, "monitorMaxLogs", tsMonitorMaxLogs, 1, 1000000, 0) != 0) return -1;
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -344,8 +377,8 @@ static void taosSetServerLogCfg(SConfig *pCfg) {
|
||||||
fsDebugFlag = cfgGetItem(pCfg, "fsDebugFlag")->i32;
|
fsDebugFlag = cfgGetItem(pCfg, "fsDebugFlag")->i32;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void taosSetClientCfg(SConfig *pCfg) {
|
static int32_t taosSetClientCfg(SConfig *pCfg) {
|
||||||
tstrncpy(tsLocalFqdn, cfgGetItem(pCfg, "fqdn")->str, TSDB_EP_LEN);
|
tstrncpy(tsLocalFqdn, cfgGetItem(pCfg, "fqdn")->str, TSDB_FQDN_LEN);
|
||||||
tsServerPort = (uint16_t)cfgGetItem(pCfg, "serverPort")->i32;
|
tsServerPort = (uint16_t)cfgGetItem(pCfg, "serverPort")->i32;
|
||||||
snprintf(tsLocalEp, sizeof(tsLocalEp), "%s:%u", tsLocalFqdn, tsServerPort);
|
snprintf(tsLocalEp, sizeof(tsLocalEp), "%s:%u", tsLocalFqdn, tsServerPort);
|
||||||
|
|
||||||
|
@ -361,9 +394,13 @@ static void taosSetClientCfg(SConfig *pCfg) {
|
||||||
snprintf(tsSecond, sizeof(tsSecond), "%s:%u", secondEp.fqdn, secondEp.port);
|
snprintf(tsSecond, sizeof(tsSecond), "%s:%u", secondEp.fqdn, secondEp.port);
|
||||||
cfgSetItem(pCfg, "secondEp", tsSecond, pSecondpItem->stype);
|
cfgSetItem(pCfg, "secondEp", tsSecond, pSecondpItem->stype);
|
||||||
|
|
||||||
tstrncpy(tsLogDir, cfgGetItem(pCfg, "tempDir")->str, PATH_MAX);
|
tstrncpy(tsTempDir, cfgGetItem(pCfg, "tempDir")->str, PATH_MAX);
|
||||||
taosExpandDir(tsLogDir, tsLogDir, PATH_MAX);
|
taosExpandDir(tsTempDir, tsTempDir, PATH_MAX);
|
||||||
tsTempSpace.reserved = cfgGetItem(pCfg, "minimalTempDirGB")->fval;
|
tsTempSpace.reserved = cfgGetItem(pCfg, "minimalTempDirGB")->fval;
|
||||||
|
if (taosMkDir(tsTempDir) != 0) {
|
||||||
|
uError("failed to create tempDir:%s since %s", tsTempDir, terrstr());
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
tsNumOfThreadsPerCore = cfgGetItem(pCfg, "maxTmrCtrl")->fval;
|
tsNumOfThreadsPerCore = cfgGetItem(pCfg, "maxTmrCtrl")->fval;
|
||||||
tsMaxTmrCtrl = cfgGetItem(pCfg, "maxTmrCtrl")->i32;
|
tsMaxTmrCtrl = cfgGetItem(pCfg, "maxTmrCtrl")->i32;
|
||||||
|
@ -378,6 +415,8 @@ static void taosSetClientCfg(SConfig *pCfg) {
|
||||||
tsMaxNumOfOrderedResults = cfgGetItem(pCfg, "maxNumOfOrderedRes")->i32;
|
tsMaxNumOfOrderedResults = cfgGetItem(pCfg, "maxNumOfOrderedRes")->i32;
|
||||||
tsKeepOriginalColumnName = cfgGetItem(pCfg, "keepColumnName")->bval;
|
tsKeepOriginalColumnName = cfgGetItem(pCfg, "keepColumnName")->bval;
|
||||||
tsMaxBinaryDisplayWidth = cfgGetItem(pCfg, "maxBinaryDisplayWidth")->i32;
|
tsMaxBinaryDisplayWidth = cfgGetItem(pCfg, "maxBinaryDisplayWidth")->i32;
|
||||||
|
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void taosSetSystemCfg(SConfig *pCfg) {
|
static void taosSetSystemCfg(SConfig *pCfg) {
|
||||||
|
@ -390,10 +429,6 @@ static void taosSetSystemCfg(SConfig *pCfg) {
|
||||||
const char *charset = cfgGetItem(pCfg, "charset")->str;
|
const char *charset = cfgGetItem(pCfg, "charset")->str;
|
||||||
taosSetSystemLocale(locale, charset);
|
taosSetSystemLocale(locale, charset);
|
||||||
|
|
||||||
if (tsNumOfCores <= 1) {
|
|
||||||
tsNumOfCores = 2;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool enableCore = cfgGetItem(pCfg, "enableCoreFile")->bval;
|
bool enableCore = cfgGetItem(pCfg, "enableCoreFile")->bval;
|
||||||
taosSetConsoleEcho(enableCore);
|
taosSetConsoleEcho(enableCore);
|
||||||
|
|
||||||
|
@ -401,11 +436,8 @@ static void taosSetSystemCfg(SConfig *pCfg) {
|
||||||
tsVersion = 30000000;
|
tsVersion = 30000000;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void taosSetServerCfg(SConfig *pCfg) {
|
static int32_t taosSetServerCfg(SConfig *pCfg) {
|
||||||
tstrncpy(tsDataDir, cfgGetItem(pCfg, "dataDir")->str, PATH_MAX);
|
tsDataSpace.reserved = cfgGetItem(pCfg, "minimalDataDirGB")->fval;
|
||||||
taosExpandDir(tsDataDir, tsDataDir, PATH_MAX);
|
|
||||||
|
|
||||||
tsTempSpace.reserved = cfgGetItem(pCfg, "minimalDataDirGB")->fval;
|
|
||||||
tsNumOfCommitThreads = cfgGetItem(pCfg, "numOfCommitThreads")->i32;
|
tsNumOfCommitThreads = cfgGetItem(pCfg, "numOfCommitThreads")->i32;
|
||||||
tsRatioOfQueryCores = cfgGetItem(pCfg, "ratioOfQueryCores")->fval;
|
tsRatioOfQueryCores = cfgGetItem(pCfg, "ratioOfQueryCores")->fval;
|
||||||
tsMaxNumOfDistinctResults = cfgGetItem(pCfg, "maxNumOfDistinctRes")->i32;
|
tsMaxNumOfDistinctResults = cfgGetItem(pCfg, "maxNumOfDistinctRes")->i32;
|
||||||
|
@ -425,9 +457,17 @@ static void taosSetServerCfg(SConfig *pCfg) {
|
||||||
tsEnableSlaveQuery = cfgGetItem(pCfg, "slaveQuery")->bval;
|
tsEnableSlaveQuery = cfgGetItem(pCfg, "slaveQuery")->bval;
|
||||||
tsDeadLockKillQuery = cfgGetItem(pCfg, "deadLockKillQuery")->bval;
|
tsDeadLockKillQuery = cfgGetItem(pCfg, "deadLockKillQuery")->bval;
|
||||||
|
|
||||||
|
tsEnableMonitor = cfgGetItem(pCfg, "monitor")->bval;
|
||||||
|
tsMonitorInterval = cfgGetItem(pCfg, "monitorInterval")->i32;
|
||||||
|
tstrncpy(tsMonitorFqdn, cfgGetItem(pCfg, "monitorFqdn")->str, TSDB_FQDN_LEN);
|
||||||
|
tsMonitorPort = (uint16_t)cfgGetItem(pCfg, "monitorPort")->i32;
|
||||||
|
tsMonitorMaxLogs = cfgGetItem(pCfg, "monitorMaxLogs")->i32;
|
||||||
|
|
||||||
if (tsQueryBufferSize >= 0) {
|
if (tsQueryBufferSize >= 0) {
|
||||||
tsQueryBufferSizeBytes = tsQueryBufferSize * 1048576UL;
|
tsQueryBufferSizeBytes = tsQueryBufferSize * 1048576UL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t taosCreateLog(const char *logname, int32_t logFileNum, const char *cfgDir, const char *envFile,
|
int32_t taosCreateLog(const char *logname, int32_t logFileNum, const char *cfgDir, const char *envFile,
|
||||||
|
@ -438,8 +478,10 @@ int32_t taosCreateLog(const char *logname, int32_t logFileNum, const char *cfgDi
|
||||||
if (pCfg == NULL) return -1;
|
if (pCfg == NULL) return -1;
|
||||||
|
|
||||||
if (tsc) {
|
if (tsc) {
|
||||||
|
tsLogEmbedded = 0;
|
||||||
if (taosAddClientLogCfg(pCfg) != 0) return -1;
|
if (taosAddClientLogCfg(pCfg) != 0) return -1;
|
||||||
} else {
|
} else {
|
||||||
|
tsLogEmbedded = 1;
|
||||||
if (taosAddClientLogCfg(pCfg) != 0) return -1;
|
if (taosAddClientLogCfg(pCfg) != 0) return -1;
|
||||||
if (taosAddServerLogCfg(pCfg) != 0) return -1;
|
if (taosAddServerLogCfg(pCfg) != 0) return -1;
|
||||||
}
|
}
|
||||||
|
@ -450,7 +492,7 @@ int32_t taosCreateLog(const char *logname, int32_t logFileNum, const char *cfgDi
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (cfgLoadArray(pCfg, pArgs) != 0) {
|
if (cfgLoadFromArray(pCfg, pArgs) != 0) {
|
||||||
uError("failed to load cfg from array since %s", terrstr());
|
uError("failed to load cfg from array since %s", terrstr());
|
||||||
cfgCleanup(pCfg);
|
cfgCleanup(pCfg);
|
||||||
return -1;
|
return -1;
|
||||||
|
@ -465,8 +507,14 @@ int32_t taosCreateLog(const char *logname, int32_t logFileNum, const char *cfgDi
|
||||||
|
|
||||||
taosSetAllDebugFlag(cfgGetItem(pCfg, "debugFlag")->i32);
|
taosSetAllDebugFlag(cfgGetItem(pCfg, "debugFlag")->i32);
|
||||||
|
|
||||||
|
if (taosMkDir(tsLogDir) != 0) {
|
||||||
|
uError("failed to create dir:%s since %s", tsLogDir, terrstr());
|
||||||
|
cfgCleanup(pCfg);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
if (taosInitLog(logname, logFileNum) != 0) {
|
if (taosInitLog(logname, logFileNum) != 0) {
|
||||||
printf("failed to init log file since %s\n", terrstr());
|
uError("failed to init log file since %s", terrstr());
|
||||||
cfgCleanup(pCfg);
|
cfgCleanup(pCfg);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
@ -480,8 +528,8 @@ int32_t taosInitCfg(const char *cfgDir, const char *envFile, const char *apolloU
|
||||||
tsCfg = cfgInit();
|
tsCfg = cfgInit();
|
||||||
|
|
||||||
if (tsc) {
|
if (tsc) {
|
||||||
if (taosAddClientLogCfg(tsCfg) != 0) return -1;
|
|
||||||
if (taosAddClientCfg(tsCfg) != 0) return -1;
|
if (taosAddClientCfg(tsCfg) != 0) return -1;
|
||||||
|
if (taosAddClientLogCfg(tsCfg) != 0) return -1;
|
||||||
} else {
|
} else {
|
||||||
if (taosAddClientCfg(tsCfg) != 0) return -1;
|
if (taosAddClientCfg(tsCfg) != 0) return -1;
|
||||||
if (taosAddServerCfg(tsCfg) != 0) return -1;
|
if (taosAddServerCfg(tsCfg) != 0) return -1;
|
||||||
|
@ -497,18 +545,18 @@ int32_t taosInitCfg(const char *cfgDir, const char *envFile, const char *apolloU
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (cfgLoadArray(tsCfg, pArgs) != 0) {
|
if (cfgLoadFromArray(tsCfg, pArgs) != 0) {
|
||||||
uError("failed to load cfg from array since %s", terrstr());
|
uError("failed to load cfg from array since %s", terrstr());
|
||||||
cfgCleanup(tsCfg);
|
cfgCleanup(tsCfg);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (tsc) {
|
if (tsc) {
|
||||||
taosSetClientCfg(tsCfg);
|
if (taosSetClientCfg(tsCfg)) return -1;
|
||||||
} else {
|
} else {
|
||||||
taosSetClientCfg(tsCfg);
|
if (taosSetClientCfg(tsCfg)) return -1;
|
||||||
taosSetServerCfg(tsCfg);
|
if (taosSetServerCfg(tsCfg)) return -1;
|
||||||
taosSetTfsCfg(tsCfg);
|
if (taosSetTfsCfg(tsCfg) != 0) return -1;
|
||||||
}
|
}
|
||||||
taosSetSystemCfg(tsCfg);
|
taosSetSystemCfg(tsCfg);
|
||||||
|
|
||||||
|
|
|
@ -1421,6 +1421,7 @@ int32_t tSerializeSUseDbReq(void *buf, int32_t bufLen, SUseDbReq *pReq) {
|
||||||
|
|
||||||
if (tStartEncode(&encoder) < 0) return -1;
|
if (tStartEncode(&encoder) < 0) return -1;
|
||||||
if (tEncodeCStr(&encoder, pReq->db) < 0) return -1;
|
if (tEncodeCStr(&encoder, pReq->db) < 0) return -1;
|
||||||
|
if (tEncodeI64(&encoder, pReq->dbId) < 0) return -1;
|
||||||
if (tEncodeI32(&encoder, pReq->vgVersion) < 0) return -1;
|
if (tEncodeI32(&encoder, pReq->vgVersion) < 0) return -1;
|
||||||
tEndEncode(&encoder);
|
tEndEncode(&encoder);
|
||||||
|
|
||||||
|
@ -1435,6 +1436,7 @@ int32_t tDeserializeSUseDbReq(void *buf, int32_t bufLen, SUseDbReq *pReq) {
|
||||||
|
|
||||||
if (tStartDecode(&decoder) < 0) return -1;
|
if (tStartDecode(&decoder) < 0) return -1;
|
||||||
if (tDecodeCStrTo(&decoder, pReq->db) < 0) return -1;
|
if (tDecodeCStrTo(&decoder, pReq->db) < 0) return -1;
|
||||||
|
if (tDecodeI64(&decoder, &pReq->dbId) < 0) return -1;
|
||||||
if (tDecodeI32(&decoder, &pReq->vgVersion) < 0) return -1;
|
if (tDecodeI32(&decoder, &pReq->vgVersion) < 0) return -1;
|
||||||
tEndDecode(&decoder);
|
tEndDecode(&decoder);
|
||||||
|
|
||||||
|
@ -2110,6 +2112,9 @@ int32_t tSerializeSCreateVnodeReq(void *buf, int32_t bufLen, SCreateVnodeReq *pR
|
||||||
if (tEncodeI32(&encoder, pReq->maxRows) < 0) return -1;
|
if (tEncodeI32(&encoder, pReq->maxRows) < 0) return -1;
|
||||||
if (tEncodeI32(&encoder, pReq->commitTime) < 0) return -1;
|
if (tEncodeI32(&encoder, pReq->commitTime) < 0) return -1;
|
||||||
if (tEncodeI32(&encoder, pReq->fsyncPeriod) < 0) return -1;
|
if (tEncodeI32(&encoder, pReq->fsyncPeriod) < 0) return -1;
|
||||||
|
if (tEncodeU32(&encoder, pReq->hashBegin) < 0) return -1;
|
||||||
|
if (tEncodeU32(&encoder, pReq->hashEnd) < 0) return -1;
|
||||||
|
if (tEncodeI8(&encoder, pReq->hashMethod) < 0) return -1;
|
||||||
if (tEncodeI8(&encoder, pReq->walLevel) < 0) return -1;
|
if (tEncodeI8(&encoder, pReq->walLevel) < 0) return -1;
|
||||||
if (tEncodeI8(&encoder, pReq->precision) < 0) return -1;
|
if (tEncodeI8(&encoder, pReq->precision) < 0) return -1;
|
||||||
if (tEncodeI8(&encoder, pReq->compression) < 0) return -1;
|
if (tEncodeI8(&encoder, pReq->compression) < 0) return -1;
|
||||||
|
@ -2150,6 +2155,9 @@ int32_t tDeserializeSCreateVnodeReq(void *buf, int32_t bufLen, SCreateVnodeReq *
|
||||||
if (tDecodeI32(&decoder, &pReq->maxRows) < 0) return -1;
|
if (tDecodeI32(&decoder, &pReq->maxRows) < 0) return -1;
|
||||||
if (tDecodeI32(&decoder, &pReq->commitTime) < 0) return -1;
|
if (tDecodeI32(&decoder, &pReq->commitTime) < 0) return -1;
|
||||||
if (tDecodeI32(&decoder, &pReq->fsyncPeriod) < 0) return -1;
|
if (tDecodeI32(&decoder, &pReq->fsyncPeriod) < 0) return -1;
|
||||||
|
if (tDecodeU32(&decoder, &pReq->hashBegin) < 0) return -1;
|
||||||
|
if (tDecodeU32(&decoder, &pReq->hashEnd) < 0) return -1;
|
||||||
|
if (tDecodeI8(&decoder, &pReq->hashMethod) < 0) return -1;
|
||||||
if (tDecodeI8(&decoder, &pReq->walLevel) < 0) return -1;
|
if (tDecodeI8(&decoder, &pReq->walLevel) < 0) return -1;
|
||||||
if (tDecodeI8(&decoder, &pReq->precision) < 0) return -1;
|
if (tDecodeI8(&decoder, &pReq->precision) < 0) return -1;
|
||||||
if (tDecodeI8(&decoder, &pReq->compression) < 0) return -1;
|
if (tDecodeI8(&decoder, &pReq->compression) < 0) return -1;
|
||||||
|
|
|
@ -22,6 +22,7 @@ bool tscValidateTableNameLength(size_t len) {
|
||||||
return len < TSDB_TABLE_NAME_LEN;
|
return len < TSDB_TABLE_NAME_LEN;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if 0
|
||||||
// TODO refactor
|
// TODO refactor
|
||||||
SColumnFilterInfo* tFilterInfoDup(const SColumnFilterInfo* src, int32_t numOfFilters) {
|
SColumnFilterInfo* tFilterInfoDup(const SColumnFilterInfo* src, int32_t numOfFilters) {
|
||||||
if (numOfFilters == 0 || src == NULL) {
|
if (numOfFilters == 0 || src == NULL) {
|
||||||
|
@ -46,7 +47,7 @@ SColumnFilterInfo* tFilterInfoDup(const SColumnFilterInfo* src, int32_t numOfFil
|
||||||
|
|
||||||
return pFilter;
|
return pFilter;
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
#if 0
|
#if 0
|
||||||
int64_t taosGetIntervalStartTimestamp(int64_t startTime, int64_t slidingTime, int64_t intervalTime, char timeUnit, int16_t precision) {
|
int64_t taosGetIntervalStartTimestamp(int64_t startTime, int64_t slidingTime, int64_t intervalTime, char timeUnit, int16_t precision) {
|
||||||
if (slidingTime == 0) {
|
if (slidingTime == 0) {
|
||||||
|
|
|
@ -627,3 +627,50 @@ const char* fmtts(int64_t ts) {
|
||||||
|
|
||||||
return buf;
|
return buf;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void taosFormatUtcTime(char* buf, int32_t bufLen, int64_t t, int32_t precision) {
|
||||||
|
char ts[40] = {0};
|
||||||
|
struct tm* ptm;
|
||||||
|
|
||||||
|
int32_t fractionLen;
|
||||||
|
char* format = NULL;
|
||||||
|
time_t quot = 0;
|
||||||
|
long mod = 0;
|
||||||
|
|
||||||
|
switch (precision) {
|
||||||
|
case TSDB_TIME_PRECISION_MILLI: {
|
||||||
|
quot = t / 1000;
|
||||||
|
fractionLen = 5;
|
||||||
|
format = ".%03" PRId64;
|
||||||
|
mod = t % 1000;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
case TSDB_TIME_PRECISION_MICRO: {
|
||||||
|
quot = t / 1000000;
|
||||||
|
fractionLen = 8;
|
||||||
|
format = ".%06" PRId64;
|
||||||
|
mod = t % 1000000;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
case TSDB_TIME_PRECISION_NANO: {
|
||||||
|
quot = t / 1000000000;
|
||||||
|
fractionLen = 11;
|
||||||
|
format = ".%09" PRId64;
|
||||||
|
mod = t % 1000000000;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
default:
|
||||||
|
fractionLen = 0;
|
||||||
|
assert(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
ptm = localtime(");
|
||||||
|
int32_t length = (int32_t)strftime(ts, 40, "%Y-%m-%dT%H:%M:%S", ptm);
|
||||||
|
length += snprintf(ts + length, fractionLen, format, mod);
|
||||||
|
length += (int32_t)strftime(ts + length, 40 - length, "%z", ptm);
|
||||||
|
|
||||||
|
tstrncpy(buf, ts, bufLen);
|
||||||
|
}
|
|
@ -46,7 +46,7 @@ STSBuf* tsBufCreate(bool autoDelete, int32_t order) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!autoDelete) {
|
if (!autoDelete) {
|
||||||
remove(pTSBuf->path);
|
taosRemoveFile(pTSBuf->path);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (NULL == allocResForTSBuf(pTSBuf)) {
|
if (NULL == allocResForTSBuf(pTSBuf)) {
|
||||||
|
@ -178,7 +178,7 @@ void* tsBufDestroy(STSBuf* pTSBuf) {
|
||||||
|
|
||||||
if (pTSBuf->autoDelete) {
|
if (pTSBuf->autoDelete) {
|
||||||
// ("tsBuf %p destroyed, delete tmp file:%s", pTSBuf, pTSBuf->path);
|
// ("tsBuf %p destroyed, delete tmp file:%s", pTSBuf, pTSBuf->path);
|
||||||
remove(pTSBuf->path);
|
taosRemoveFile(pTSBuf->path);
|
||||||
} else {
|
} else {
|
||||||
// tscDebug("tsBuf %p destroyed, tmp file:%s, remains", pTSBuf, pTSBuf->path);
|
// tscDebug("tsBuf %p destroyed, tmp file:%s, remains", pTSBuf, pTSBuf->path);
|
||||||
}
|
}
|
||||||
|
|
|
@ -49,8 +49,8 @@ const int32_t TYPE_BYTES[15] = {
|
||||||
} \
|
} \
|
||||||
} while (0)
|
} while (0)
|
||||||
|
|
||||||
static void getStatics_bool(const void *pData, int32_t numOfRow, int64_t *min, int64_t *max,
|
static void getStatics_bool(const void *pData, int32_t numOfRow, int64_t *min, int64_t *max, int64_t *sum,
|
||||||
int64_t *sum, int16_t *minIndex, int16_t *maxIndex, int16_t *numOfNull) {
|
int16_t *minIndex, int16_t *maxIndex, int16_t *numOfNull) {
|
||||||
int8_t *data = (int8_t *)pData;
|
int8_t *data = (int8_t *)pData;
|
||||||
*min = INT64_MAX;
|
*min = INT64_MAX;
|
||||||
*max = INT64_MIN;
|
*max = INT64_MIN;
|
||||||
|
@ -133,7 +133,6 @@ static void getStatics_i16(const void *pData, int32_t numOfRow, int64_t *min, in
|
||||||
|
|
||||||
DO_STATICS(*sum, *min, *max, *minIndex, *maxIndex, data, i);
|
DO_STATICS(*sum, *min, *max, *minIndex, *maxIndex, data, i);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void getStatics_u16(const void *pData, int32_t numOfRow, int64_t *min, int64_t *max, int64_t *sum,
|
static void getStatics_u16(const void *pData, int32_t numOfRow, int64_t *min, int64_t *max, int64_t *sum,
|
||||||
|
@ -182,8 +181,8 @@ static void getStatics_i32(const void *pData, int32_t numOfRow, int64_t *min, in
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void getStatics_u32(const void *pData, int32_t numOfRow, int64_t *min, int64_t *max,
|
static void getStatics_u32(const void *pData, int32_t numOfRow, int64_t *min, int64_t *max, int64_t *sum,
|
||||||
int64_t *sum, int16_t *minIndex, int16_t *maxIndex, int16_t *numOfNull) {
|
int16_t *minIndex, int16_t *maxIndex, int16_t *numOfNull) {
|
||||||
uint32_t *data = (uint32_t *)pData;
|
uint32_t *data = (uint32_t *)pData;
|
||||||
uint64_t _min = UINT64_MAX;
|
uint64_t _min = UINT64_MAX;
|
||||||
uint64_t _max = 0;
|
uint64_t _max = 0;
|
||||||
|
@ -208,8 +207,8 @@ static void getStatics_u32(const void *pData, int32_t numOfRow, int64_t *min, in
|
||||||
*sum = _sum;
|
*sum = _sum;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void getStatics_i64(const void *pData, int32_t numOfRow, int64_t *min, int64_t *max,
|
static void getStatics_i64(const void *pData, int32_t numOfRow, int64_t *min, int64_t *max, int64_t *sum,
|
||||||
int64_t *sum, int16_t *minIndex, int16_t *maxIndex, int16_t *numOfNull) {
|
int16_t *minIndex, int16_t *maxIndex, int16_t *numOfNull) {
|
||||||
int64_t *data = (int64_t *)pData;
|
int64_t *data = (int64_t *)pData;
|
||||||
*min = INT64_MAX;
|
*min = INT64_MAX;
|
||||||
*max = INT64_MIN;
|
*max = INT64_MIN;
|
||||||
|
@ -228,8 +227,8 @@ static void getStatics_i64(const void *pData, int32_t numOfRow, int64_t *min, in
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void getStatics_u64(const void *pData, int32_t numOfRow, int64_t *min, int64_t *max,
|
static void getStatics_u64(const void *pData, int32_t numOfRow, int64_t *min, int64_t *max, int64_t *sum,
|
||||||
int64_t *sum, int16_t *minIndex, int16_t *maxIndex, int16_t *numOfNull) {
|
int16_t *minIndex, int16_t *maxIndex, int16_t *numOfNull) {
|
||||||
uint64_t *data = (uint64_t *)pData;
|
uint64_t *data = (uint64_t *)pData;
|
||||||
uint64_t _min = UINT64_MAX;
|
uint64_t _min = UINT64_MAX;
|
||||||
uint64_t _max = 0;
|
uint64_t _max = 0;
|
||||||
|
@ -254,8 +253,8 @@ static void getStatics_u64(const void *pData, int32_t numOfRow, int64_t *min, in
|
||||||
*sum = _sum;
|
*sum = _sum;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void getStatics_f(const void *pData, int32_t numOfRow, int64_t *min, int64_t *max,
|
static void getStatics_f(const void *pData, int32_t numOfRow, int64_t *min, int64_t *max, int64_t *sum,
|
||||||
int64_t *sum, int16_t *minIndex, int16_t *maxIndex, int16_t *numOfNull) {
|
int16_t *minIndex, int16_t *maxIndex, int16_t *numOfNull) {
|
||||||
float *data = (float *)pData;
|
float *data = (float *)pData;
|
||||||
float fmin = FLT_MAX;
|
float fmin = FLT_MAX;
|
||||||
float fmax = -FLT_MAX;
|
float fmax = -FLT_MAX;
|
||||||
|
@ -290,8 +289,8 @@ static void getStatics_f(const void *pData, int32_t numOfRow, int64_t *min, int6
|
||||||
SET_DOUBLE_VAL(min, fmin);
|
SET_DOUBLE_VAL(min, fmin);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void getStatics_d(const void *pData, int32_t numOfRow, int64_t *min, int64_t *max,
|
static void getStatics_d(const void *pData, int32_t numOfRow, int64_t *min, int64_t *max, int64_t *sum,
|
||||||
int64_t *sum, int16_t *minIndex, int16_t *maxIndex, int16_t *numOfNull) {
|
int16_t *minIndex, int16_t *maxIndex, int16_t *numOfNull) {
|
||||||
double *data = (double *)pData;
|
double *data = (double *)pData;
|
||||||
double dmin = DBL_MAX;
|
double dmin = DBL_MAX;
|
||||||
double dmax = -DBL_MAX;
|
double dmax = -DBL_MAX;
|
||||||
|
@ -326,8 +325,8 @@ static void getStatics_d(const void *pData, int32_t numOfRow, int64_t *min, int6
|
||||||
SET_DOUBLE_PTR(min, &dmin);
|
SET_DOUBLE_PTR(min, &dmin);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void getStatics_bin(const void *pData, int32_t numOfRow, int64_t *min, int64_t *max,
|
static void getStatics_bin(const void *pData, int32_t numOfRow, int64_t *min, int64_t *max, int64_t *sum,
|
||||||
int64_t *sum, int16_t *minIndex, int16_t *maxIndex, int16_t *numOfNull) {
|
int16_t *minIndex, int16_t *maxIndex, int16_t *numOfNull) {
|
||||||
const char *data = pData;
|
const char *data = pData;
|
||||||
assert(numOfRow <= INT16_MAX);
|
assert(numOfRow <= INT16_MAX);
|
||||||
|
|
||||||
|
@ -346,8 +345,8 @@ static void getStatics_bin(const void *pData, int32_t numOfRow, int64_t *min, in
|
||||||
*maxIndex = 0;
|
*maxIndex = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void getStatics_nchr(const void *pData, int32_t numOfRow, int64_t *min, int64_t *max,
|
static void getStatics_nchr(const void *pData, int32_t numOfRow, int64_t *min, int64_t *max, int64_t *sum,
|
||||||
int64_t *sum, int16_t *minIndex, int16_t *maxIndex, int16_t *numOfNull) {
|
int16_t *minIndex, int16_t *maxIndex, int16_t *numOfNull) {
|
||||||
const char *data = pData;
|
const char *data = pData;
|
||||||
assert(numOfRow <= INT16_MAX);
|
assert(numOfRow <= INT16_MAX);
|
||||||
|
|
||||||
|
@ -369,19 +368,26 @@ static void getStatics_nchr(const void *pData, int32_t numOfRow, int64_t *min, i
|
||||||
tDataTypeDescriptor tDataTypes[15] = {
|
tDataTypeDescriptor tDataTypes[15] = {
|
||||||
{TSDB_DATA_TYPE_NULL, 6, 1, "NOTYPE", 0, 0, NULL, NULL, NULL},
|
{TSDB_DATA_TYPE_NULL, 6, 1, "NOTYPE", 0, 0, NULL, NULL, NULL},
|
||||||
{TSDB_DATA_TYPE_BOOL, 4, CHAR_BYTES, "BOOL", false, true, tsCompressBool, tsDecompressBool, getStatics_bool},
|
{TSDB_DATA_TYPE_BOOL, 4, CHAR_BYTES, "BOOL", false, true, tsCompressBool, tsDecompressBool, getStatics_bool},
|
||||||
{TSDB_DATA_TYPE_TINYINT, 7, CHAR_BYTES, "TINYINT", INT8_MIN, INT8_MAX, tsCompressTinyint, tsDecompressTinyint, getStatics_i8},
|
{TSDB_DATA_TYPE_TINYINT, 7, CHAR_BYTES, "TINYINT", INT8_MIN, INT8_MAX, tsCompressTinyint, tsDecompressTinyint,
|
||||||
{TSDB_DATA_TYPE_SMALLINT, 8, SHORT_BYTES, "SMALLINT", INT16_MIN, INT16_MAX, tsCompressSmallint, tsDecompressSmallint, getStatics_i16},
|
getStatics_i8},
|
||||||
|
{TSDB_DATA_TYPE_SMALLINT, 8, SHORT_BYTES, "SMALLINT", INT16_MIN, INT16_MAX, tsCompressSmallint,
|
||||||
|
tsDecompressSmallint, getStatics_i16},
|
||||||
{TSDB_DATA_TYPE_INT, 3, INT_BYTES, "INT", INT32_MIN, INT32_MAX, tsCompressInt, tsDecompressInt, getStatics_i32},
|
{TSDB_DATA_TYPE_INT, 3, INT_BYTES, "INT", INT32_MIN, INT32_MAX, tsCompressInt, tsDecompressInt, getStatics_i32},
|
||||||
{TSDB_DATA_TYPE_BIGINT, 6, LONG_BYTES, "BIGINT", INT64_MIN, INT64_MAX, tsCompressBigint, tsDecompressBigint, getStatics_i64},
|
{TSDB_DATA_TYPE_BIGINT, 6, LONG_BYTES, "BIGINT", INT64_MIN, INT64_MAX, tsCompressBigint, tsDecompressBigint,
|
||||||
|
getStatics_i64},
|
||||||
{TSDB_DATA_TYPE_FLOAT, 5, FLOAT_BYTES, "FLOAT", 0, 0, tsCompressFloat, tsDecompressFloat, getStatics_f},
|
{TSDB_DATA_TYPE_FLOAT, 5, FLOAT_BYTES, "FLOAT", 0, 0, tsCompressFloat, tsDecompressFloat, getStatics_f},
|
||||||
{TSDB_DATA_TYPE_DOUBLE, 6, DOUBLE_BYTES, "DOUBLE", 0, 0, tsCompressDouble, tsDecompressDouble, getStatics_d},
|
{TSDB_DATA_TYPE_DOUBLE, 6, DOUBLE_BYTES, "DOUBLE", 0, 0, tsCompressDouble, tsDecompressDouble, getStatics_d},
|
||||||
{TSDB_DATA_TYPE_BINARY, 6, 0, "BINARY", 0, 0, tsCompressString, tsDecompressString, getStatics_bin},
|
{TSDB_DATA_TYPE_BINARY, 6, 0, "BINARY", 0, 0, tsCompressString, tsDecompressString, getStatics_bin},
|
||||||
{TSDB_DATA_TYPE_TIMESTAMP, 9, LONG_BYTES, "TIMESTAMP", INT64_MIN, INT64_MAX, tsCompressTimestamp, tsDecompressTimestamp, getStatics_i64},
|
{TSDB_DATA_TYPE_TIMESTAMP, 9, LONG_BYTES, "TIMESTAMP", INT64_MIN, INT64_MAX, tsCompressTimestamp,
|
||||||
|
tsDecompressTimestamp, getStatics_i64},
|
||||||
{TSDB_DATA_TYPE_NCHAR, 5, 8, "NCHAR", 0, 0, tsCompressString, tsDecompressString, getStatics_nchr},
|
{TSDB_DATA_TYPE_NCHAR, 5, 8, "NCHAR", 0, 0, tsCompressString, tsDecompressString, getStatics_nchr},
|
||||||
{TSDB_DATA_TYPE_UTINYINT, 16, CHAR_BYTES, "TINYINT UNSIGNED", 0, UINT8_MAX, tsCompressTinyint, tsDecompressTinyint, getStatics_u8},
|
{TSDB_DATA_TYPE_UTINYINT, 16, CHAR_BYTES, "TINYINT UNSIGNED", 0, UINT8_MAX, tsCompressTinyint, tsDecompressTinyint,
|
||||||
{TSDB_DATA_TYPE_USMALLINT, 17, SHORT_BYTES, "SMALLINT UNSIGNED", 0, UINT16_MAX, tsCompressSmallint, tsDecompressSmallint, getStatics_u16},
|
getStatics_u8},
|
||||||
|
{TSDB_DATA_TYPE_USMALLINT, 17, SHORT_BYTES, "SMALLINT UNSIGNED", 0, UINT16_MAX, tsCompressSmallint,
|
||||||
|
tsDecompressSmallint, getStatics_u16},
|
||||||
{TSDB_DATA_TYPE_UINT, 12, INT_BYTES, "INT UNSIGNED", 0, UINT32_MAX, tsCompressInt, tsDecompressInt, getStatics_u32},
|
{TSDB_DATA_TYPE_UINT, 12, INT_BYTES, "INT UNSIGNED", 0, UINT32_MAX, tsCompressInt, tsDecompressInt, getStatics_u32},
|
||||||
{TSDB_DATA_TYPE_UBIGINT, 15, LONG_BYTES, "BIGINT UNSIGNED", 0, UINT64_MAX, tsCompressBigint, tsDecompressBigint, getStatics_u64},
|
{TSDB_DATA_TYPE_UBIGINT, 15, LONG_BYTES, "BIGINT UNSIGNED", 0, UINT64_MAX, tsCompressBigint, tsDecompressBigint,
|
||||||
|
getStatics_u64},
|
||||||
};
|
};
|
||||||
|
|
||||||
char tTokenTypeSwitcher[13] = {
|
char tTokenTypeSwitcher[13] = {
|
||||||
|
@ -425,9 +431,7 @@ FORCE_INLINE void* getDataMax(int32_t type) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool isValidDataType(int32_t type) {
|
bool isValidDataType(int32_t type) { return type >= TSDB_DATA_TYPE_NULL && type <= TSDB_DATA_TYPE_UBIGINT; }
|
||||||
return type >= TSDB_DATA_TYPE_NULL && type <= TSDB_DATA_TYPE_UBIGINT;
|
|
||||||
}
|
|
||||||
|
|
||||||
void setVardataNull(void *val, int32_t type) {
|
void setVardataNull(void *val, int32_t type) {
|
||||||
if (type == TSDB_DATA_TYPE_BINARY) {
|
if (type == TSDB_DATA_TYPE_BINARY) {
|
||||||
|
@ -533,9 +537,8 @@ static SBinaryNullT nullBinary = {1, TSDB_DATA_BINARY_NULL};
|
||||||
static SNCharNullT nullNchar = {4, TSDB_DATA_NCHAR_NULL};
|
static SNCharNullT nullNchar = {4, TSDB_DATA_NCHAR_NULL};
|
||||||
|
|
||||||
static const void *nullValues[] = {
|
static const void *nullValues[] = {
|
||||||
&nullBool, &nullTinyInt, &nullSmallInt, &nullInt, &nullBigInt,
|
&nullBool, &nullTinyInt, &nullSmallInt, &nullInt, &nullBigInt, &nullFloat, &nullDouble,
|
||||||
&nullFloat, &nullDouble, &nullBinary, &nullBigInt, &nullNchar,
|
&nullBinary, &nullBigInt, &nullNchar, &nullTinyIntu, &nullSmallIntu, &nullIntu, &nullBigIntu,
|
||||||
&nullTinyIntu, &nullSmallIntu, &nullIntu, &nullBigIntu,
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const void *getNullValue(int32_t type) {
|
const void *getNullValue(int32_t type) {
|
||||||
|
|
|
@ -263,7 +263,6 @@ void taosVariantAssign(SVariant *pDst, const SVariant *pSrc) {
|
||||||
memcpy(pDst->pz, pSrc->pz, pSrc->nLen);
|
memcpy(pDst->pz, pSrc->pz, pSrc->nLen);
|
||||||
pDst->nLen = pSrc->nLen;
|
pDst->nLen = pSrc->nLen;
|
||||||
return;
|
return;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (IS_NUMERIC_TYPE(pSrc->nType) || (pSrc->nType == TSDB_DATA_TYPE_BOOL)) {
|
if (IS_NUMERIC_TYPE(pSrc->nType) || (pSrc->nType == TSDB_DATA_TYPE_BOOL)) {
|
||||||
|
@ -507,7 +506,8 @@ static FORCE_INLINE int32_t convertToDouble(char *pStr, int32_t len, double *val
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static FORCE_INLINE int32_t convertToInteger(SVariant *pVariant, int64_t *result, int32_t type, bool issigned, bool releaseVariantPtr, bool *converted) {
|
static FORCE_INLINE int32_t convertToInteger(SVariant *pVariant, int64_t *result, int32_t type, bool issigned,
|
||||||
|
bool releaseVariantPtr, bool *converted) {
|
||||||
if (pVariant->nType == TSDB_DATA_TYPE_NULL) {
|
if (pVariant->nType == TSDB_DATA_TYPE_NULL) {
|
||||||
setNull((char *)result, type, tDataTypes[type].bytes);
|
setNull((char *)result, type, tDataTypes[type].bytes);
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -665,7 +665,8 @@ static int32_t convertToBool(SVariant *pVariant, int64_t *pDest) {
|
||||||
* transfer data from variant serve as the implicit data conversion: from input sql string pVariant->nType
|
* transfer data from variant serve as the implicit data conversion: from input sql string pVariant->nType
|
||||||
* to column type defined in schema
|
* to column type defined in schema
|
||||||
*/
|
*/
|
||||||
int32_t tVariantDumpEx(SVariant *pVariant, char *payload, int16_t type, bool includeLengthPrefix, bool *converted, char *extInfo) {
|
int32_t tVariantDumpEx(SVariant *pVariant, char *payload, int16_t type, bool includeLengthPrefix, bool *converted,
|
||||||
|
char *extInfo) {
|
||||||
if (converted) {
|
if (converted) {
|
||||||
*converted = false;
|
*converted = false;
|
||||||
}
|
}
|
||||||
|
@ -782,7 +783,8 @@ int32_t tVariantDumpEx(SVariant *pVariant, char *payload, int16_t type, bool inc
|
||||||
}
|
}
|
||||||
SET_FLOAT_VAL(payload, value);
|
SET_FLOAT_VAL(payload, value);
|
||||||
}
|
}
|
||||||
} else if (pVariant->nType == TSDB_DATA_TYPE_BOOL || IS_SIGNED_NUMERIC_TYPE(pVariant->nType) || IS_UNSIGNED_NUMERIC_TYPE(pVariant->nType)) {
|
} else if (pVariant->nType == TSDB_DATA_TYPE_BOOL || IS_SIGNED_NUMERIC_TYPE(pVariant->nType) ||
|
||||||
|
IS_UNSIGNED_NUMERIC_TYPE(pVariant->nType)) {
|
||||||
if (converted) {
|
if (converted) {
|
||||||
*converted = true;
|
*converted = true;
|
||||||
}
|
}
|
||||||
|
@ -831,7 +833,8 @@ int32_t tVariantDumpEx(SVariant *pVariant, char *payload, int16_t type, bool inc
|
||||||
|
|
||||||
SET_DOUBLE_VAL(payload, value);
|
SET_DOUBLE_VAL(payload, value);
|
||||||
}
|
}
|
||||||
} else if (pVariant->nType == TSDB_DATA_TYPE_BOOL || IS_SIGNED_NUMERIC_TYPE(pVariant->nType) || IS_UNSIGNED_NUMERIC_TYPE(pVariant->nType)) {
|
} else if (pVariant->nType == TSDB_DATA_TYPE_BOOL || IS_SIGNED_NUMERIC_TYPE(pVariant->nType) ||
|
||||||
|
IS_UNSIGNED_NUMERIC_TYPE(pVariant->nType)) {
|
||||||
SET_DOUBLE_VAL(payload, pVariant->i);
|
SET_DOUBLE_VAL(payload, pVariant->i);
|
||||||
} else if (IS_FLOAT_TYPE(pVariant->nType)) {
|
} else if (IS_FLOAT_TYPE(pVariant->nType)) {
|
||||||
SET_DOUBLE_VAL(payload, pVariant->d);
|
SET_DOUBLE_VAL(payload, pVariant->d);
|
||||||
|
|
|
@ -1,6 +1,4 @@
|
||||||
#include "tcommon.h"
|
|
||||||
#include <gtest/gtest.h>
|
#include <gtest/gtest.h>
|
||||||
#include <tep.h>
|
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
|
||||||
#pragma GCC diagnostic push
|
#pragma GCC diagnostic push
|
||||||
|
@ -10,6 +8,9 @@
|
||||||
#pragma GCC diagnostic ignored "-Wsign-compare"
|
#pragma GCC diagnostic ignored "-Wsign-compare"
|
||||||
#include "os.h"
|
#include "os.h"
|
||||||
|
|
||||||
|
#include "tcommon.h"
|
||||||
|
#include "tdatablock.h"
|
||||||
|
#include "tcommon.h"
|
||||||
#include "taos.h"
|
#include "taos.h"
|
||||||
#include "tvariant.h"
|
#include "tvariant.h"
|
||||||
#include "tdef.h"
|
#include "tdef.h"
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
|
||||||
#include "gtest/gtest.h"
|
#include <gtest/gtest.h>
|
||||||
|
|
||||||
#include "tmsg.h"
|
#include "tmsg.h"
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
aux_source_directory(src BNODE_SRC)
|
aux_source_directory(src BNODE_SRC)
|
||||||
add_library(bnode ${BNODE_SRC})
|
add_library(bnode STATIC ${BNODE_SRC})
|
||||||
target_include_directories(
|
target_include_directories(
|
||||||
bnode
|
bnode
|
||||||
PUBLIC "${CMAKE_SOURCE_DIR}/include/dnode/bnode"
|
PUBLIC "${CMAKE_SOURCE_DIR}/include/dnode/bnode"
|
||||||
|
|
|
@ -6,4 +6,4 @@ target_include_directories(
|
||||||
PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/inc"
|
PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/inc"
|
||||||
)
|
)
|
||||||
|
|
||||||
target_link_libraries(taosd dnode util os)
|
target_link_libraries(taosd dnode)
|
||||||
|
|
|
@ -1,17 +1,7 @@
|
||||||
aux_source_directory(src DNODE_SRC)
|
aux_source_directory(src DNODE_SRC)
|
||||||
add_library(dnode STATIC ${DNODE_SRC})
|
add_library(dnode STATIC ${DNODE_SRC})
|
||||||
target_link_libraries(
|
target_link_libraries(
|
||||||
dnode
|
dnode cjson mnode vnode qnode snode bnode wal sync taos tfs monitor
|
||||||
PUBLIC cjson
|
|
||||||
PUBLIC mnode
|
|
||||||
PUBLIC vnode
|
|
||||||
PUBLIC qnode
|
|
||||||
PUBLIC snode
|
|
||||||
PUBLIC bnode
|
|
||||||
PUBLIC wal
|
|
||||||
PUBLIC sync
|
|
||||||
PUBLIC taos
|
|
||||||
PUBLIC tfs
|
|
||||||
)
|
)
|
||||||
target_include_directories(
|
target_include_directories(
|
||||||
dnode
|
dnode
|
||||||
|
|
|
@ -137,6 +137,8 @@ typedef struct SDnode {
|
||||||
SStartupReq startup;
|
SStartupReq startup;
|
||||||
} SDnode;
|
} SDnode;
|
||||||
|
|
||||||
|
int32_t dndGetMonitorDiskInfo(SDnode *pDnode, SMonDiskInfo *pInfo);
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -23,9 +23,11 @@ extern "C" {
|
||||||
#include "os.h"
|
#include "os.h"
|
||||||
|
|
||||||
#include "cJSON.h"
|
#include "cJSON.h"
|
||||||
|
#include "monitor.h"
|
||||||
#include "tcache.h"
|
#include "tcache.h"
|
||||||
#include "tcrc32c.h"
|
#include "tcrc32c.h"
|
||||||
#include "tep.h"
|
#include "tdatablock.h"
|
||||||
|
#include "tglobal.h"
|
||||||
#include "thash.h"
|
#include "thash.h"
|
||||||
#include "tlockfree.h"
|
#include "tlockfree.h"
|
||||||
#include "tlog.h"
|
#include "tlog.h"
|
||||||
|
@ -35,7 +37,6 @@ extern "C" {
|
||||||
#include "tthread.h"
|
#include "tthread.h"
|
||||||
#include "ttime.h"
|
#include "ttime.h"
|
||||||
#include "tworker.h"
|
#include "tworker.h"
|
||||||
#include "tglobal.h"
|
|
||||||
|
|
||||||
#include "dnode.h"
|
#include "dnode.h"
|
||||||
|
|
||||||
|
@ -46,14 +47,12 @@ extern "C" {
|
||||||
#include "vnode.h"
|
#include "vnode.h"
|
||||||
#include "tfs.h"
|
#include "tfs.h"
|
||||||
|
|
||||||
extern int32_t dDebugFlag;
|
#define dFatal(...) { if (dDebugFlag & DEBUG_FATAL) { taosPrintLog("DND FATAL ", DEBUG_FATAL, 255, __VA_ARGS__); }}
|
||||||
|
#define dError(...) { if (dDebugFlag & DEBUG_ERROR) { taosPrintLog("DND ERROR ", DEBUG_ERROR, 255, __VA_ARGS__); }}
|
||||||
#define dFatal(...) { if (dDebugFlag & DEBUG_FATAL) { taosPrintLog("DND FATAL ", 255, __VA_ARGS__); }}
|
#define dWarn(...) { if (dDebugFlag & DEBUG_WARN) { taosPrintLog("DND WARN ", DEBUG_WARN, 255, __VA_ARGS__); }}
|
||||||
#define dError(...) { if (dDebugFlag & DEBUG_ERROR) { taosPrintLog("DND ERROR ", 255, __VA_ARGS__); }}
|
#define dInfo(...) { if (dDebugFlag & DEBUG_INFO) { taosPrintLog("DND ", DEBUG_INFO, 255, __VA_ARGS__); }}
|
||||||
#define dWarn(...) { if (dDebugFlag & DEBUG_WARN) { taosPrintLog("DND WARN ", 255, __VA_ARGS__); }}
|
#define dDebug(...) { if (dDebugFlag & DEBUG_DEBUG) { taosPrintLog("DND ", DEBUG_DEBUG, dDebugFlag, __VA_ARGS__); }}
|
||||||
#define dInfo(...) { if (dDebugFlag & DEBUG_INFO) { taosPrintLog("DND ", 255, __VA_ARGS__); }}
|
#define dTrace(...) { if (dDebugFlag & DEBUG_TRACE) { taosPrintLog("DND ", DEBUG_TRACE, dDebugFlag, __VA_ARGS__); }}
|
||||||
#define dDebug(...) { if (dDebugFlag & DEBUG_DEBUG) { taosPrintLog("DND ", dDebugFlag, __VA_ARGS__); }}
|
|
||||||
#define dTrace(...) { if (dDebugFlag & DEBUG_TRACE) { taosPrintLog("DND ", dDebugFlag, __VA_ARGS__); }}
|
|
||||||
|
|
||||||
typedef enum { DND_STAT_INIT, DND_STAT_RUNNING, DND_STAT_STOPPED } EStat;
|
typedef enum { DND_STAT_INIT, DND_STAT_RUNNING, DND_STAT_STOPPED } EStat;
|
||||||
typedef enum { DND_WORKER_SINGLE, DND_WORKER_MULTI } EWorkerType;
|
typedef enum { DND_WORKER_SINGLE, DND_WORKER_MULTI } EWorkerType;
|
||||||
|
|
|
@ -32,6 +32,10 @@ int32_t dndProcessCreateMnodeReq(SDnode *pDnode, SRpcMsg *pRpcMsg);
|
||||||
int32_t dndProcessAlterMnodeReq(SDnode *pDnode, SRpcMsg *pRpcMsg);
|
int32_t dndProcessAlterMnodeReq(SDnode *pDnode, SRpcMsg *pRpcMsg);
|
||||||
int32_t dndProcessDropMnodeReq(SDnode *pDnode, SRpcMsg *pRpcMsg);
|
int32_t dndProcessDropMnodeReq(SDnode *pDnode, SRpcMsg *pRpcMsg);
|
||||||
|
|
||||||
|
int32_t dndGetMnodeMonitorInfo(SDnode *pDnode, SMonClusterInfo *pClusterInfo, SMonVgroupInfo *pVgroupInfo,
|
||||||
|
SMonGrantInfo *pGrantInfo);
|
||||||
|
int8_t dndIsMnode(SDnode *pDnode);
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -21,6 +21,7 @@
|
||||||
#include "dndSnode.h"
|
#include "dndSnode.h"
|
||||||
#include "dndTransport.h"
|
#include "dndTransport.h"
|
||||||
#include "dndVnodes.h"
|
#include "dndVnodes.h"
|
||||||
|
#include "monitor.h"
|
||||||
#include "sync.h"
|
#include "sync.h"
|
||||||
#include "tfs.h"
|
#include "tfs.h"
|
||||||
#include "wal.h"
|
#include "wal.h"
|
||||||
|
@ -140,7 +141,7 @@ static int32_t dndInitDir(SDnode *pDnode, SDnodeObjCfg *pCfg) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void dndCloseImp(SDnode *pDnode) {
|
static void dndCloseDir(SDnode *pDnode) {
|
||||||
tfree(pDnode->dir.mnode);
|
tfree(pDnode->dir.mnode);
|
||||||
tfree(pDnode->dir.vnodes);
|
tfree(pDnode->dir.vnodes);
|
||||||
tfree(pDnode->dir.dnode);
|
tfree(pDnode->dir.dnode);
|
||||||
|
@ -260,7 +261,7 @@ void dndClose(SDnode *pDnode) {
|
||||||
dndCleanupMgmt(pDnode);
|
dndCleanupMgmt(pDnode);
|
||||||
tfsClose(pDnode->pTfs);
|
tfsClose(pDnode->pTfs);
|
||||||
|
|
||||||
dndCloseImp(pDnode);
|
dndCloseDir(pDnode);
|
||||||
free(pDnode);
|
free(pDnode);
|
||||||
dInfo("dnode object is closed, data:%p", pDnode);
|
dInfo("dnode object is closed, data:%p", pDnode);
|
||||||
}
|
}
|
||||||
|
@ -289,11 +290,7 @@ int32_t dndInit() {
|
||||||
}
|
}
|
||||||
|
|
||||||
SVnodeOpt vnodeOpt = {
|
SVnodeOpt vnodeOpt = {
|
||||||
.sver = tsVersion,
|
.nthreads = tsNumOfCommitThreads, .putReqToVQueryQFp = dndPutReqToVQueryQ, .sendReqToDnodeFp = dndSendReqToDnode};
|
||||||
.nthreads = tsNumOfCommitThreads,
|
|
||||||
.putReqToVQueryQFp = dndPutReqToVQueryQ,
|
|
||||||
.sendReqToDnodeFp = dndSendReqToDnode
|
|
||||||
};
|
|
||||||
|
|
||||||
if (vnodeInit(&vnodeOpt) != 0) {
|
if (vnodeInit(&vnodeOpt) != 0) {
|
||||||
dError("failed to init vnode since %s", terrstr());
|
dError("failed to init vnode since %s", terrstr());
|
||||||
|
@ -301,6 +298,13 @@ int32_t dndInit() {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
SMonCfg monCfg = {.maxLogs = tsMonitorMaxLogs, .port = tsMonitorPort, .server = tsMonitorFqdn};
|
||||||
|
if (monInit(&monCfg) != 0) {
|
||||||
|
dError("failed to init monitor since %s", terrstr());
|
||||||
|
dndCleanup();
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
dInfo("dnode env is initialized");
|
dInfo("dnode env is initialized");
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -314,19 +318,17 @@ void dndCleanup() {
|
||||||
walCleanUp();
|
walCleanUp();
|
||||||
vnodeCleanup();
|
vnodeCleanup();
|
||||||
rpcCleanup();
|
rpcCleanup();
|
||||||
|
monCleanup();
|
||||||
|
|
||||||
taosStopCacheRefreshWorker();
|
taosStopCacheRefreshWorker();
|
||||||
dInfo("dnode env is cleaned up");
|
dInfo("dnode env is cleaned up");
|
||||||
}
|
}
|
||||||
|
|
||||||
// OTHER FUNCTIONS ===================================
|
int32_t dndGetMonitorDiskInfo(SDnode *pDnode, SMonDiskInfo *pInfo) {
|
||||||
void taosGetDisk() {
|
tstrncpy(pInfo->logdir.name, tsLogDir, sizeof(pInfo->logdir.name));
|
||||||
#if 0
|
pInfo->logdir.size = tsLogSpace.size;
|
||||||
const double unit = 1024 * 1024 * 1024;
|
tstrncpy(pInfo->tempdir.name, tsTempDir, sizeof(pInfo->tempdir.name));
|
||||||
|
pInfo->tempdir.size = tsTempSpace.size;
|
||||||
|
|
||||||
SDiskSize diskSize = tfsGetSize(pTfs);
|
return tfsGetMonitorInfo(pDnode->pTfs, pInfo);
|
||||||
|
|
||||||
tfsUpdateSize(&fsMeta);
|
|
||||||
|
|
||||||
#endif
|
|
||||||
}
|
}
|
|
@ -22,6 +22,7 @@
|
||||||
#include "dndTransport.h"
|
#include "dndTransport.h"
|
||||||
#include "dndVnodes.h"
|
#include "dndVnodes.h"
|
||||||
#include "dndWorker.h"
|
#include "dndWorker.h"
|
||||||
|
#include "monitor.h"
|
||||||
|
|
||||||
static void dndProcessMgmtQueue(SDnode *pDnode, SRpcMsg *pMsg);
|
static void dndProcessMgmtQueue(SDnode *pDnode, SRpcMsg *pMsg);
|
||||||
|
|
||||||
|
@ -473,19 +474,104 @@ void dndProcessStartupReq(SDnode *pDnode, SRpcMsg *pReq) {
|
||||||
rpcSendResponse(&rpcRsp);
|
rpcSendResponse(&rpcRsp);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void dndGetMonitorBasicInfo(SDnode *pDnode, SMonBasicInfo *pInfo) {
|
||||||
|
pInfo->dnode_id = dndGetDnodeId(pDnode);
|
||||||
|
tstrncpy(pInfo->dnode_ep, tsLocalEp, TSDB_EP_LEN);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void dndGetMonitorDnodeInfo(SDnode *pDnode, SMonDnodeInfo *pInfo) {
|
||||||
|
pInfo->uptime = (taosGetTimestampMs() - pDnode->dmgmt.rebootTime) / (86400000.0f);
|
||||||
|
taosGetCpuUsage(&pInfo->cpu_engine, &pInfo->cpu_system);
|
||||||
|
pInfo->cpu_cores = tsNumOfCores;
|
||||||
|
taosGetProcMemory(&pInfo->mem_engine);
|
||||||
|
taosGetSysMemory(&pInfo->mem_system);
|
||||||
|
pInfo->mem_total = tsTotalMemoryKB;
|
||||||
|
pInfo->disk_engine = 0;
|
||||||
|
pInfo->disk_used = tsDataSpace.size.used / (1024 * 1024 * 1024.0);
|
||||||
|
pInfo->disk_total = tsDataSpace.size.avail / (1024 * 1024 * 1024.0);
|
||||||
|
taosGetCardInfo(NULL, &pInfo->net_in, &pInfo->net_out);
|
||||||
|
taosGetProcIO(&pInfo->io_read, &pInfo->io_write);
|
||||||
|
pInfo->io_read_disk = 0;
|
||||||
|
pInfo->io_write_disk = 0;
|
||||||
|
pInfo->req_select = 0;
|
||||||
|
pInfo->req_select_rate = 0;
|
||||||
|
pInfo->req_insert = 0;
|
||||||
|
pInfo->req_insert_success = 0;
|
||||||
|
pInfo->req_insert_rate = 0;
|
||||||
|
pInfo->req_insert_batch = 0;
|
||||||
|
pInfo->req_insert_batch_success = 0;
|
||||||
|
pInfo->req_insert_batch_rate = 0;
|
||||||
|
pInfo->errors = 0;
|
||||||
|
pInfo->vnodes_num = 0;
|
||||||
|
pInfo->masters = 0;
|
||||||
|
pInfo->has_mnode = dndIsMnode(pDnode);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void dndSendMonitorReport(SDnode *pDnode) {
|
||||||
|
if (!tsEnableMonitor || tsMonitorFqdn[0] == 0 || tsMonitorPort == 0) return;
|
||||||
|
dTrace("pDnode:%p, send monitor report to %s:%u", pDnode, tsMonitorFqdn, tsMonitorPort);
|
||||||
|
|
||||||
|
SMonInfo *pMonitor = monCreateMonitorInfo();
|
||||||
|
if (pMonitor == NULL) return;
|
||||||
|
|
||||||
|
SMonBasicInfo basicInfo = {0};
|
||||||
|
dndGetMonitorBasicInfo(pDnode, &basicInfo);
|
||||||
|
monSetBasicInfo(pMonitor, &basicInfo);
|
||||||
|
|
||||||
|
SMonClusterInfo clusterInfo = {0};
|
||||||
|
SMonVgroupInfo vgroupInfo = {0};
|
||||||
|
SMonGrantInfo grantInfo = {0};
|
||||||
|
if (dndGetMnodeMonitorInfo(pDnode, &clusterInfo, &vgroupInfo, &grantInfo) == 0) {
|
||||||
|
monSetClusterInfo(pMonitor, &clusterInfo);
|
||||||
|
monSetVgroupInfo(pMonitor, &vgroupInfo);
|
||||||
|
monSetGrantInfo(pMonitor, &grantInfo);
|
||||||
|
}
|
||||||
|
|
||||||
|
SMonDnodeInfo dnodeInfo = {0};
|
||||||
|
dndGetMonitorDnodeInfo(pDnode, &dnodeInfo);
|
||||||
|
monSetDnodeInfo(pMonitor, &dnodeInfo);
|
||||||
|
|
||||||
|
SMonDiskInfo diskInfo = {0};
|
||||||
|
if (dndGetMonitorDiskInfo(pDnode, &diskInfo) == 0) {
|
||||||
|
monSetDiskInfo(pMonitor, &diskInfo);
|
||||||
|
}
|
||||||
|
|
||||||
|
taosArrayDestroy(clusterInfo.dnodes);
|
||||||
|
taosArrayDestroy(clusterInfo.mnodes);
|
||||||
|
taosArrayDestroy(vgroupInfo.vgroups);
|
||||||
|
taosArrayDestroy(diskInfo.datadirs);
|
||||||
|
|
||||||
|
monSendReport(pMonitor);
|
||||||
|
monCleanupMonitorInfo(pMonitor);
|
||||||
|
}
|
||||||
|
|
||||||
static void *dnodeThreadRoutine(void *param) {
|
static void *dnodeThreadRoutine(void *param) {
|
||||||
SDnode *pDnode = param;
|
SDnode *pDnode = param;
|
||||||
SDnodeMgmt *pMgmt = &pDnode->dmgmt;
|
SDnodeMgmt *pMgmt = &pDnode->dmgmt;
|
||||||
int32_t ms = tsStatusInterval * 1000;
|
int64_t lastStatusTime = taosGetTimestampMs();
|
||||||
|
int64_t lastMonitorTime = lastStatusTime;
|
||||||
|
|
||||||
setThreadName("dnode-hb");
|
setThreadName("dnode-hb");
|
||||||
|
|
||||||
while (true) {
|
while (true) {
|
||||||
pthread_testcancel();
|
pthread_testcancel();
|
||||||
taosMsleep(ms);
|
taosMsleep(200);
|
||||||
|
if (dndGetStat(pDnode) != DND_STAT_RUNNING || pMgmt->dropped) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
if (dndGetStat(pDnode) == DND_STAT_RUNNING && !pMgmt->statusSent && !pMgmt->dropped) {
|
int64_t curTime = taosGetTimestampMs();
|
||||||
|
|
||||||
|
float statusInterval = (curTime - lastStatusTime) / 1000.0f;
|
||||||
|
if (statusInterval >= tsStatusInterval && !pMgmt->statusSent) {
|
||||||
dndSendStatusReq(pDnode);
|
dndSendStatusReq(pDnode);
|
||||||
|
lastStatusTime = curTime;
|
||||||
|
}
|
||||||
|
|
||||||
|
float monitorInterval = (curTime - lastMonitorTime) / 1000.0f;
|
||||||
|
if (monitorInterval >= tsMonitorInterval) {
|
||||||
|
dndSendMonitorReport(pDnode);
|
||||||
|
lastMonitorTime = curTime;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -630,3 +630,20 @@ int32_t dndGetUserAuthFromMnode(SDnode *pDnode, char *user, char *spi, char *enc
|
||||||
dTrace("user:%s, retrieve auth spi:%d encrypt:%d", user, *spi, *encrypt);
|
dTrace("user:%s, retrieve auth spi:%d encrypt:%d", user, *spi, *encrypt);
|
||||||
return code;
|
return code;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int32_t dndGetMnodeMonitorInfo(SDnode *pDnode, SMonClusterInfo *pClusterInfo, SMonVgroupInfo *pVgroupInfo,
|
||||||
|
SMonGrantInfo *pGrantInfo) {
|
||||||
|
SMnode *pMnode = dndAcquireMnode(pDnode);
|
||||||
|
if (pMnode == NULL) return -1;
|
||||||
|
|
||||||
|
int32_t code = mndGetMonitorInfo(pMnode, pClusterInfo, pVgroupInfo, pGrantInfo);
|
||||||
|
dndReleaseMnode(pDnode, pMnode);
|
||||||
|
return code;
|
||||||
|
}
|
||||||
|
|
||||||
|
int8_t dndIsMnode(SDnode *pDnode) {
|
||||||
|
SMnode *pMnode = dndAcquireMnode(pDnode);
|
||||||
|
if (pMnode == NULL) return 0;
|
||||||
|
dndReleaseMnode(pDnode, pMnode);
|
||||||
|
return 1;
|
||||||
|
}
|
|
@ -85,7 +85,7 @@ static SVnodeObj *dndAcquireVnode(SDnode *pDnode, int32_t vgId) {
|
||||||
int32_t refCount = 0;
|
int32_t refCount = 0;
|
||||||
|
|
||||||
taosRLockLatch(&pMgmt->latch);
|
taosRLockLatch(&pMgmt->latch);
|
||||||
taosHashGetClone(pMgmt->hash, &vgId, sizeof(int32_t), (void *)&pVnode);
|
taosHashGetDup(pMgmt->hash, &vgId, sizeof(int32_t), (void *)&pVnode);
|
||||||
if (pVnode == NULL) {
|
if (pVnode == NULL) {
|
||||||
terrno = TSDB_CODE_VND_INVALID_VGROUP_ID;
|
terrno = TSDB_CODE_VND_INVALID_VGROUP_ID;
|
||||||
} else {
|
} else {
|
||||||
|
@ -523,6 +523,9 @@ static void dndGenerateVnodeCfg(SCreateVnodeReq *pCreate, SVnodeCfg *pCfg) {
|
||||||
pCfg->walCfg.rollPeriod = 128;
|
pCfg->walCfg.rollPeriod = 128;
|
||||||
pCfg->walCfg.segSize = 128;
|
pCfg->walCfg.segSize = 128;
|
||||||
pCfg->walCfg.vgId = pCreate->vgId;
|
pCfg->walCfg.vgId = pCreate->vgId;
|
||||||
|
pCfg->hashBegin = pCreate->hashBegin;
|
||||||
|
pCfg->hashEnd = pCreate->hashEnd;
|
||||||
|
pCfg->hashMethod = pCreate->hashMethod;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void dndGenerateWrapperCfg(SDnode *pDnode, SCreateVnodeReq *pCreate, SWrapperCfg *pCfg) {
|
static void dndGenerateWrapperCfg(SDnode *pDnode, SCreateVnodeReq *pCreate, SWrapperCfg *pCfg) {
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
aux_source_directory(src SUT_SRC)
|
aux_source_directory(src SUT_SRC)
|
||||||
add_library(sut STATIC ${SUT_SRC})
|
add_library(sut STATIC STATIC ${SUT_SRC})
|
||||||
target_link_libraries(
|
target_link_libraries(
|
||||||
sut
|
sut
|
||||||
PUBLIC dnode
|
PUBLIC dnode
|
||||||
|
|
|
@ -14,7 +14,7 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "sut.h"
|
#include "sut.h"
|
||||||
#include "tep.h"
|
#include "tdatablock.h"
|
||||||
|
|
||||||
static void processClientRsp(void* parent, SRpcMsg* pRsp, SEpSet* pEpSet) {
|
static void processClientRsp(void* parent, SRpcMsg* pRsp, SEpSet* pEpSet) {
|
||||||
TestClient* client = (TestClient*)parent;
|
TestClient* client = (TestClient*)parent;
|
||||||
|
|
|
@ -28,7 +28,7 @@ void Testbase::InitLog(const char* path) {
|
||||||
wDebugFlag = 0;
|
wDebugFlag = 0;
|
||||||
sDebugFlag = 0;
|
sDebugFlag = 0;
|
||||||
tsdbDebugFlag = 0;
|
tsdbDebugFlag = 0;
|
||||||
tscEmbeddedInUtil = 1;
|
tsLogEmbedded = 1;
|
||||||
tsAsyncLog = 0;
|
tsAsyncLog = 0;
|
||||||
|
|
||||||
taosRemoveDir(path);
|
taosRemoveDir(path);
|
||||||
|
|
|
@ -1,18 +1,12 @@
|
||||||
aux_source_directory(src MNODE_SRC)
|
aux_source_directory(src MNODE_SRC)
|
||||||
add_library(mnode ${MNODE_SRC})
|
add_library(mnode STATIC ${MNODE_SRC})
|
||||||
target_include_directories(
|
target_include_directories(
|
||||||
mnode
|
mnode
|
||||||
PUBLIC "${CMAKE_SOURCE_DIR}/include/dnode/mnode"
|
PUBLIC "${CMAKE_SOURCE_DIR}/include/dnode/mnode"
|
||||||
PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/inc"
|
PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/inc"
|
||||||
)
|
)
|
||||||
target_link_libraries(
|
target_link_libraries(
|
||||||
mnode
|
mnode scheduler sdb wal transport cjson sync monitor
|
||||||
PRIVATE scheduler
|
|
||||||
PRIVATE sdb
|
|
||||||
PRIVATE wal
|
|
||||||
PRIVATE transport
|
|
||||||
PRIVATE cjson
|
|
||||||
PRIVATE sync
|
|
||||||
)
|
)
|
||||||
|
|
||||||
if(${BUILD_TEST})
|
if(${BUILD_TEST})
|
||||||
|
|
|
@ -34,46 +34,6 @@
|
||||||
extern "C" {
|
extern "C" {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
extern int32_t mDebugFlag;
|
|
||||||
|
|
||||||
// mnode log function
|
|
||||||
#define mFatal(...) \
|
|
||||||
{ \
|
|
||||||
if (mDebugFlag & DEBUG_FATAL) { \
|
|
||||||
taosPrintLog("MND FATAL ", 255, __VA_ARGS__); \
|
|
||||||
} \
|
|
||||||
}
|
|
||||||
#define mError(...) \
|
|
||||||
{ \
|
|
||||||
if (mDebugFlag & DEBUG_ERROR) { \
|
|
||||||
taosPrintLog("MND ERROR ", 255, __VA_ARGS__); \
|
|
||||||
} \
|
|
||||||
}
|
|
||||||
#define mWarn(...) \
|
|
||||||
{ \
|
|
||||||
if (mDebugFlag & DEBUG_WARN) { \
|
|
||||||
taosPrintLog("MND WARN ", 255, __VA_ARGS__); \
|
|
||||||
} \
|
|
||||||
}
|
|
||||||
#define mInfo(...) \
|
|
||||||
{ \
|
|
||||||
if (mDebugFlag & DEBUG_INFO) { \
|
|
||||||
taosPrintLog("MND ", 255, __VA_ARGS__); \
|
|
||||||
} \
|
|
||||||
}
|
|
||||||
#define mDebug(...) \
|
|
||||||
{ \
|
|
||||||
if (mDebugFlag & DEBUG_DEBUG) { \
|
|
||||||
taosPrintLog("MND ", mDebugFlag, __VA_ARGS__); \
|
|
||||||
} \
|
|
||||||
}
|
|
||||||
#define mTrace(...) \
|
|
||||||
{ \
|
|
||||||
if (mDebugFlag & DEBUG_TRACE) { \
|
|
||||||
taosPrintLog("MND ", mDebugFlag, __VA_ARGS__); \
|
|
||||||
} \
|
|
||||||
}
|
|
||||||
|
|
||||||
typedef enum {
|
typedef enum {
|
||||||
MND_AUTH_ACCT_START = 0,
|
MND_AUTH_ACCT_START = 0,
|
||||||
MND_AUTH_ACCT_USER,
|
MND_AUTH_ACCT_USER,
|
||||||
|
|
|
@ -20,17 +20,24 @@
|
||||||
|
|
||||||
#include "sdb.h"
|
#include "sdb.h"
|
||||||
#include "tcache.h"
|
#include "tcache.h"
|
||||||
#include "tep.h"
|
#include "tdatablock.h"
|
||||||
|
#include "tglobal.h"
|
||||||
#include "tqueue.h"
|
#include "tqueue.h"
|
||||||
#include "ttime.h"
|
#include "ttime.h"
|
||||||
#include "wal.h"
|
|
||||||
#include "version.h"
|
#include "version.h"
|
||||||
#include "tglobal.h"
|
#include "wal.h"
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
extern "C" {
|
extern "C" {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#define mFatal(...) { if (mDebugFlag & DEBUG_FATAL) { taosPrintLog("MND FATAL ", DEBUG_FATAL, 255, __VA_ARGS__); }}
|
||||||
|
#define mError(...) { if (mDebugFlag & DEBUG_ERROR) { taosPrintLog("MND ERROR ", DEBUG_ERROR, 255, __VA_ARGS__); }}
|
||||||
|
#define mWarn(...) { if (mDebugFlag & DEBUG_WARN) { taosPrintLog("MND WARN ", DEBUG_WARN, 255, __VA_ARGS__); }}
|
||||||
|
#define mInfo(...) { if (mDebugFlag & DEBUG_INFO) { taosPrintLog("MND ", DEBUG_INFO, 255, __VA_ARGS__); }}
|
||||||
|
#define mDebug(...) { if (mDebugFlag & DEBUG_DEBUG) { taosPrintLog("MND ", DEBUG_DEBUG, mDebugFlag, __VA_ARGS__); }}
|
||||||
|
#define mTrace(...) { if (mDebugFlag & DEBUG_TRACE) { taosPrintLog("MND ", DEBUG_TRACE, mDebugFlag, __VA_ARGS__); }}
|
||||||
|
|
||||||
typedef int32_t (*MndMsgFp)(SMnodeMsg *pMsg);
|
typedef int32_t (*MndMsgFp)(SMnodeMsg *pMsg);
|
||||||
typedef int32_t (*MndInitFp)(SMnode *pMnode);
|
typedef int32_t (*MndInitFp)(SMnode *pMnode);
|
||||||
typedef void (*MndCleanupFp)(SMnode *pMnode);
|
typedef void (*MndCleanupFp)(SMnode *pMnode);
|
||||||
|
@ -38,6 +45,20 @@ typedef int32_t (*ShowMetaFp)(SMnodeMsg *pMsg, SShowObj *pShow, STableMetaRsp *p
|
||||||
typedef int32_t (*ShowRetrieveFp)(SMnodeMsg *pMsg, SShowObj *pShow, char *data, int32_t rows);
|
typedef int32_t (*ShowRetrieveFp)(SMnodeMsg *pMsg, SShowObj *pShow, char *data, int32_t rows);
|
||||||
typedef void (*ShowFreeIterFp)(SMnode *pMnode, void *pIter);
|
typedef void (*ShowFreeIterFp)(SMnode *pMnode, void *pIter);
|
||||||
|
|
||||||
|
typedef struct SMnodeLoad {
|
||||||
|
int64_t numOfDnode;
|
||||||
|
int64_t numOfMnode;
|
||||||
|
int64_t numOfVgroup;
|
||||||
|
int64_t numOfDatabase;
|
||||||
|
int64_t numOfSuperTable;
|
||||||
|
int64_t numOfChildTable;
|
||||||
|
int64_t numOfNormalTable;
|
||||||
|
int64_t numOfColumn;
|
||||||
|
int64_t totalPoints;
|
||||||
|
int64_t totalStorage;
|
||||||
|
int64_t compStorage;
|
||||||
|
} SMnodeLoad;
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
const char *name;
|
const char *name;
|
||||||
MndInitFp initFp;
|
MndInitFp initFp;
|
||||||
|
@ -71,6 +92,11 @@ typedef struct {
|
||||||
ESyncState state;
|
ESyncState state;
|
||||||
} SSyncMgmt;
|
} SSyncMgmt;
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
int64_t expireTimeMS;
|
||||||
|
int64_t timeseriesAllowed;
|
||||||
|
} SGrantInfo;
|
||||||
|
|
||||||
typedef struct SMnode {
|
typedef struct SMnode {
|
||||||
int32_t dnodeId;
|
int32_t dnodeId;
|
||||||
int64_t clusterId;
|
int64_t clusterId;
|
||||||
|
@ -91,6 +117,7 @@ typedef struct SMnode {
|
||||||
STelemMgmt telemMgmt;
|
STelemMgmt telemMgmt;
|
||||||
SSyncMgmt syncMgmt;
|
SSyncMgmt syncMgmt;
|
||||||
SHashObj *infosMeta;
|
SHashObj *infosMeta;
|
||||||
|
SGrantInfo grant;
|
||||||
MndMsgFp msgFp[TDMT_MAX];
|
MndMsgFp msgFp[TDMT_MAX];
|
||||||
SendReqToDnodeFp sendReqToDnodeFp;
|
SendReqToDnodeFp sendReqToDnodeFp;
|
||||||
SendReqToMnodeFp sendReqToMnodeFp;
|
SendReqToMnodeFp sendReqToMnodeFp;
|
||||||
|
@ -106,6 +133,8 @@ void mndSetMsgHandle(SMnode *pMnode, tmsg_t msgType, MndMsgFp fp);
|
||||||
|
|
||||||
uint64_t mndGenerateUid(char *name, int32_t len);
|
uint64_t mndGenerateUid(char *name, int32_t len);
|
||||||
|
|
||||||
|
void mndGetLoad(SMnode *pMnode, SMnodeLoad *pLoad);
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -24,6 +24,7 @@ extern "C" {
|
||||||
|
|
||||||
int32_t mndInitProfile(SMnode *pMnode);
|
int32_t mndInitProfile(SMnode *pMnode);
|
||||||
void mndCleanupProfile(SMnode *pMnode);
|
void mndCleanupProfile(SMnode *pMnode);
|
||||||
|
int32_t mndGetNumOfConnections(SMnode *pMnode);
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
|
|
|
@ -940,13 +940,18 @@ static int32_t mndProcessUseDbReq(SMnodeMsg *pReq) {
|
||||||
char *p = strchr(usedbReq.db, '.');
|
char *p = strchr(usedbReq.db, '.');
|
||||||
if (p && 0 == strcmp(p + 1, TSDB_INFORMATION_SCHEMA_DB)) {
|
if (p && 0 == strcmp(p + 1, TSDB_INFORMATION_SCHEMA_DB)) {
|
||||||
memcpy(usedbRsp.db, usedbReq.db, TSDB_DB_FNAME_LEN);
|
memcpy(usedbRsp.db, usedbReq.db, TSDB_DB_FNAME_LEN);
|
||||||
|
code = 0;
|
||||||
} else {
|
} else {
|
||||||
pDb = mndAcquireDb(pMnode, usedbReq.db);
|
pDb = mndAcquireDb(pMnode, usedbReq.db);
|
||||||
if (pDb == NULL) {
|
if (pDb == NULL) {
|
||||||
terrno = TSDB_CODE_MND_DB_NOT_EXIST;
|
terrno = TSDB_CODE_MND_DB_NOT_EXIST;
|
||||||
goto USE_DB_OVER;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
memcpy(usedbRsp.db, usedbReq.db, TSDB_DB_FNAME_LEN);
|
||||||
|
usedbRsp.uid = usedbReq.dbId;
|
||||||
|
usedbRsp.vgVersion = usedbReq.vgVersion;
|
||||||
|
|
||||||
|
mError("db:%s, failed to process use db req since %s", usedbReq.db, terrstr());
|
||||||
|
} else {
|
||||||
pUser = mndAcquireUser(pMnode, pReq->user);
|
pUser = mndAcquireUser(pMnode, pReq->user);
|
||||||
if (pUser == NULL) {
|
if (pUser == NULL) {
|
||||||
goto USE_DB_OVER;
|
goto USE_DB_OVER;
|
||||||
|
@ -962,7 +967,7 @@ static int32_t mndProcessUseDbReq(SMnodeMsg *pReq) {
|
||||||
goto USE_DB_OVER;
|
goto USE_DB_OVER;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (usedbReq.vgVersion < pDb->vgVersion) {
|
if (usedbReq.vgVersion < pDb->vgVersion || usedbReq.dbId != pDb->uid) {
|
||||||
mndBuildDBVgroupInfo(pDb, pMnode, usedbRsp.pVgroupInfos);
|
mndBuildDBVgroupInfo(pDb, pMnode, usedbRsp.pVgroupInfos);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -971,12 +976,15 @@ static int32_t mndProcessUseDbReq(SMnodeMsg *pReq) {
|
||||||
usedbRsp.vgVersion = pDb->vgVersion;
|
usedbRsp.vgVersion = pDb->vgVersion;
|
||||||
usedbRsp.vgNum = taosArrayGetSize(usedbRsp.pVgroupInfos);
|
usedbRsp.vgNum = taosArrayGetSize(usedbRsp.pVgroupInfos);
|
||||||
usedbRsp.hashMethod = pDb->hashMethod;
|
usedbRsp.hashMethod = pDb->hashMethod;
|
||||||
|
code = 0;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t contLen = tSerializeSUseDbRsp(NULL, 0, &usedbRsp);
|
int32_t contLen = tSerializeSUseDbRsp(NULL, 0, &usedbRsp);
|
||||||
void *pRsp = rpcMallocCont(contLen);
|
void *pRsp = rpcMallocCont(contLen);
|
||||||
if (pRsp == NULL) {
|
if (pRsp == NULL) {
|
||||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||||
|
code = -1;
|
||||||
goto USE_DB_OVER;
|
goto USE_DB_OVER;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -984,7 +992,6 @@ static int32_t mndProcessUseDbReq(SMnodeMsg *pReq) {
|
||||||
|
|
||||||
pReq->pCont = pRsp;
|
pReq->pCont = pRsp;
|
||||||
pReq->contLen = contLen;
|
pReq->contLen = contLen;
|
||||||
code = 0;
|
|
||||||
|
|
||||||
USE_DB_OVER:
|
USE_DB_OVER:
|
||||||
if (code != 0) {
|
if (code != 0) {
|
||||||
|
|
|
@ -99,11 +99,15 @@ void mndUpdateMnodeRole(SMnode *pMnode) {
|
||||||
pIter = sdbFetch(pSdb, SDB_MNODE, pIter, (void **)&pObj);
|
pIter = sdbFetch(pSdb, SDB_MNODE, pIter, (void **)&pObj);
|
||||||
if (pIter == NULL) break;
|
if (pIter == NULL) break;
|
||||||
|
|
||||||
|
ESyncState lastRole = pObj->role;
|
||||||
if (pObj->id == 1) {
|
if (pObj->id == 1) {
|
||||||
pObj->role = TAOS_SYNC_STATE_LEADER;
|
pObj->role = TAOS_SYNC_STATE_LEADER;
|
||||||
} else {
|
} else {
|
||||||
pObj->role = TAOS_SYNC_STATE_CANDIDATE;
|
pObj->role = TAOS_SYNC_STATE_CANDIDATE;
|
||||||
}
|
}
|
||||||
|
if (pObj->role != lastRole) {
|
||||||
|
pObj->roleTime = taosGetTimestampMs();
|
||||||
|
}
|
||||||
|
|
||||||
sdbRelease(pSdb, pObj);
|
sdbRelease(pSdb, pObj);
|
||||||
}
|
}
|
||||||
|
|
|
@ -48,7 +48,7 @@ static SConnObj *mndCreateConn(SMnode *pMnode, SRpcConnInfo *pInfo, int32_t pid,
|
||||||
static void mndFreeConn(SConnObj *pConn);
|
static void mndFreeConn(SConnObj *pConn);
|
||||||
static SConnObj *mndAcquireConn(SMnode *pMnode, int32_t connId);
|
static SConnObj *mndAcquireConn(SMnode *pMnode, int32_t connId);
|
||||||
static void mndReleaseConn(SMnode *pMnode, SConnObj *pConn);
|
static void mndReleaseConn(SMnode *pMnode, SConnObj *pConn);
|
||||||
static void *mndGetNextConn(SMnode *pMnode, void *pIter, SConnObj **pConn);
|
static void *mndGetNextConn(SMnode *pMnode, SCacheIter *pIter);
|
||||||
static void mndCancelGetNextConn(SMnode *pMnode, void *pIter);
|
static void mndCancelGetNextConn(SMnode *pMnode, void *pIter);
|
||||||
static int32_t mndProcessHeartBeatReq(SMnodeMsg *pReq);
|
static int32_t mndProcessHeartBeatReq(SMnodeMsg *pReq);
|
||||||
static int32_t mndProcessConnectReq(SMnodeMsg *pReq);
|
static int32_t mndProcessConnectReq(SMnodeMsg *pReq);
|
||||||
|
@ -158,27 +158,23 @@ static void mndReleaseConn(SMnode *pMnode, SConnObj *pConn) {
|
||||||
taosCacheRelease(pMgmt->cache, (void **)&pConn, false);
|
taosCacheRelease(pMgmt->cache, (void **)&pConn, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void *mndGetNextConn(SMnode *pMnode, void *pIter, SConnObj **pConn) {
|
void *mndGetNextConn(SMnode *pMnode, SCacheIter *pIter) {
|
||||||
SProfileMgmt *pMgmt = &pMnode->profileMgmt;
|
SConnObj* pConn = NULL;
|
||||||
|
bool hasNext = taosCacheIterNext(pIter);
|
||||||
*pConn = NULL;
|
if (hasNext) {
|
||||||
|
size_t dataLen = 0;
|
||||||
pIter = taosHashIterate(pMgmt->cache->pHashTable, pIter);
|
pConn = taosCacheIterGetData(pIter, &dataLen);
|
||||||
if (pIter == NULL) return NULL;
|
} else {
|
||||||
|
taosCacheDestroyIter(pIter);
|
||||||
SCacheDataNode **pNode = pIter;
|
|
||||||
if (pNode == NULL || *pNode == NULL) {
|
|
||||||
taosHashCancelIterate(pMgmt->cache->pHashTable, pIter);
|
|
||||||
return NULL;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
*pConn = (SConnObj *)((*pNode)->data);
|
return pConn;
|
||||||
return pIter;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void mndCancelGetNextConn(SMnode *pMnode, void *pIter) {
|
static void mndCancelGetNextConn(SMnode *pMnode, void *pIter) {
|
||||||
SProfileMgmt *pMgmt = &pMnode->profileMgmt;
|
if (pIter != NULL) {
|
||||||
taosHashCancelIterate(pMgmt->cache->pHashTable, pIter);
|
taosCacheDestroyIter(pIter);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static int32_t mndProcessConnectReq(SMnodeMsg *pReq) {
|
static int32_t mndProcessConnectReq(SMnodeMsg *pReq) {
|
||||||
|
@ -376,8 +372,8 @@ static int32_t mndProcessHeartBeatReq(SMnodeMsg *pReq) {
|
||||||
int32_t rspLen = 0;
|
int32_t rspLen = 0;
|
||||||
mndValidateDbInfo(pMnode, kv->value, kv->valueLen / sizeof(SDbVgVersion), &rspMsg, &rspLen);
|
mndValidateDbInfo(pMnode, kv->value, kv->valueLen / sizeof(SDbVgVersion), &rspMsg, &rspLen);
|
||||||
if (rspMsg && rspLen > 0) {
|
if (rspMsg && rspLen > 0) {
|
||||||
SKv kv = {.key = HEARTBEAT_KEY_DBINFO, .valueLen = rspLen, .value = rspMsg};
|
SKv kv1 = {.key = HEARTBEAT_KEY_DBINFO, .valueLen = rspLen, .value = rspMsg};
|
||||||
taosArrayPush(hbRsp.info, &kv);
|
taosArrayPush(hbRsp.info, &kv1);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -386,8 +382,8 @@ static int32_t mndProcessHeartBeatReq(SMnodeMsg *pReq) {
|
||||||
int32_t rspLen = 0;
|
int32_t rspLen = 0;
|
||||||
mndValidateStbInfo(pMnode, kv->value, kv->valueLen / sizeof(SSTableMetaVersion), &rspMsg, &rspLen);
|
mndValidateStbInfo(pMnode, kv->value, kv->valueLen / sizeof(SSTableMetaVersion), &rspMsg, &rspLen);
|
||||||
if (rspMsg && rspLen > 0) {
|
if (rspMsg && rspLen > 0) {
|
||||||
SKv kv = {.key = HEARTBEAT_KEY_STBINFO, .valueLen = rspLen, .value = rspMsg};
|
SKv kv1 = {.key = HEARTBEAT_KEY_STBINFO, .valueLen = rspLen, .value = rspMsg};
|
||||||
taosArrayPush(hbRsp.info, &kv);
|
taosArrayPush(hbRsp.info, &kv1);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -638,7 +634,7 @@ static int32_t mndGetConnsMeta(SMnodeMsg *pReq, SShowObj *pShow, STableMetaRsp *
|
||||||
pShow->offset[i] = pShow->offset[i - 1] + pShow->bytes[i - 1];
|
pShow->offset[i] = pShow->offset[i - 1] + pShow->bytes[i - 1];
|
||||||
}
|
}
|
||||||
|
|
||||||
pShow->numOfRows = taosHashGetSize(pMgmt->cache->pHashTable);
|
pShow->numOfRows = taosCacheGetNumOfObj(pMgmt->cache);
|
||||||
pShow->rowSize = pShow->offset[cols - 1] + pShow->bytes[cols - 1];
|
pShow->rowSize = pShow->offset[cols - 1] + pShow->bytes[cols - 1];
|
||||||
strcpy(pMeta->tbName, mndShowStr(pShow->type));
|
strcpy(pMeta->tbName, mndShowStr(pShow->type));
|
||||||
|
|
||||||
|
@ -653,8 +649,13 @@ static int32_t mndRetrieveConns(SMnodeMsg *pReq, SShowObj *pShow, char *data, in
|
||||||
char *pWrite;
|
char *pWrite;
|
||||||
char ipStr[TSDB_IPv4ADDR_LEN + 6];
|
char ipStr[TSDB_IPv4ADDR_LEN + 6];
|
||||||
|
|
||||||
|
if (pShow->pIter == NULL) {
|
||||||
|
SProfileMgmt *pMgmt = &pMnode->profileMgmt;
|
||||||
|
pShow->pIter = taosCacheCreateIter(pMgmt->cache);
|
||||||
|
}
|
||||||
|
|
||||||
while (numOfRows < rows) {
|
while (numOfRows < rows) {
|
||||||
pShow->pIter = mndGetNextConn(pMnode, pShow->pIter, &pConn);
|
pConn = mndGetNextConn(pMnode, pShow->pIter);
|
||||||
if (pConn == NULL) break;
|
if (pConn == NULL) break;
|
||||||
|
|
||||||
cols = 0;
|
cols = 0;
|
||||||
|
@ -823,19 +824,24 @@ static int32_t mndRetrieveQueries(SMnodeMsg *pReq, SShowObj *pShow, char *data,
|
||||||
void *pIter;
|
void *pIter;
|
||||||
char str[TSDB_IPv4ADDR_LEN + 6] = {0};
|
char str[TSDB_IPv4ADDR_LEN + 6] = {0};
|
||||||
|
|
||||||
|
if (pShow->pIter == NULL) {
|
||||||
|
SProfileMgmt *pMgmt = &pMnode->profileMgmt;
|
||||||
|
pShow->pIter = taosCacheCreateIter(pMgmt->cache);
|
||||||
|
}
|
||||||
|
|
||||||
while (numOfRows < rows) {
|
while (numOfRows < rows) {
|
||||||
pIter = mndGetNextConn(pMnode, pShow->pIter, &pConn);
|
pConn = mndGetNextConn(pMnode, pShow->pIter);
|
||||||
if (pConn == NULL) {
|
if (pConn == NULL) {
|
||||||
pShow->pIter = pIter;
|
pShow->pIter = NULL;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (numOfRows + pConn->numOfQueries >= rows) {
|
if (numOfRows + pConn->numOfQueries >= rows) {
|
||||||
mndCancelGetNextConn(pMnode, pIter);
|
taosCacheDestroyIter(pShow->pIter);
|
||||||
|
pShow->pIter = NULL;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
pShow->pIter = pIter;
|
|
||||||
for (int32_t i = 0; i < pConn->numOfQueries; ++i) {
|
for (int32_t i = 0; i < pConn->numOfQueries; ++i) {
|
||||||
SQueryDesc *pDesc = pConn->pQueries + i;
|
SQueryDesc *pDesc = pConn->pQueries + i;
|
||||||
cols = 0;
|
cols = 0;
|
||||||
|
@ -913,6 +919,12 @@ static int32_t mndRetrieveQueries(SMnodeMsg *pReq, SShowObj *pShow, char *data,
|
||||||
}
|
}
|
||||||
|
|
||||||
static void mndCancelGetNextQuery(SMnode *pMnode, void *pIter) {
|
static void mndCancelGetNextQuery(SMnode *pMnode, void *pIter) {
|
||||||
SProfileMgmt *pMgmt = &pMnode->profileMgmt;
|
if (pIter != NULL) {
|
||||||
taosHashCancelIterate(pMgmt->cache->pHashTable, pIter);
|
taosCacheDestroyIter(pIter);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
int32_t mndGetNumOfConnections(SMnode *pMnode) {
|
||||||
|
SProfileMgmt *pMgmt = &pMnode->profileMgmt;
|
||||||
|
return taosCacheGetNumOfObj(pMgmt->cache);
|
||||||
}
|
}
|
|
@ -18,227 +18,65 @@
|
||||||
#include "mndCluster.h"
|
#include "mndCluster.h"
|
||||||
#include "mndSync.h"
|
#include "mndSync.h"
|
||||||
#include "tbuffer.h"
|
#include "tbuffer.h"
|
||||||
#include "tversion.h"
|
#include "thttp.h"
|
||||||
|
#include "tjson.h"
|
||||||
|
|
||||||
#define TELEMETRY_SERVER "telemetry.taosdata.com"
|
#define TELEMETRY_SERVER "telemetry.taosdata.com"
|
||||||
#define TELEMETRY_PORT 80
|
#define TELEMETRY_PORT 80
|
||||||
#define REPORT_INTERVAL 86400
|
|
||||||
|
|
||||||
static void mndBeginObject(SBufferWriter* bw) { tbufWriteChar(bw, '{'); }
|
static void mndBuildRuntimeInfo(SMnode* pMnode, SJson* pJson) {
|
||||||
|
|
||||||
static void mndCloseObject(SBufferWriter* bw) {
|
|
||||||
size_t len = tbufTell(bw);
|
|
||||||
if (tbufGetData(bw, false)[len - 1] == ',') {
|
|
||||||
tbufWriteCharAt(bw, len - 1, '}');
|
|
||||||
} else {
|
|
||||||
tbufWriteChar(bw, '}');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static void mndWriteString(SBufferWriter* bw, const char* str) {
|
|
||||||
tbufWriteChar(bw, '"');
|
|
||||||
tbufWrite(bw, str, strlen(str));
|
|
||||||
tbufWriteChar(bw, '"');
|
|
||||||
}
|
|
||||||
|
|
||||||
static void mndAddIntField(SBufferWriter* bw, const char* k, int64_t v) {
|
|
||||||
mndWriteString(bw, k);
|
|
||||||
tbufWriteChar(bw, ':');
|
|
||||||
char buf[32] = {0};
|
|
||||||
sprintf(buf, "%" PRId64, v);
|
|
||||||
tbufWrite(bw, buf, strlen(buf));
|
|
||||||
tbufWriteChar(bw, ',');
|
|
||||||
}
|
|
||||||
|
|
||||||
static void mndAddStringField(SBufferWriter* bw, const char* k, const char* v) {
|
|
||||||
mndWriteString(bw, k);
|
|
||||||
tbufWriteChar(bw, ':');
|
|
||||||
mndWriteString(bw, v);
|
|
||||||
tbufWriteChar(bw, ',');
|
|
||||||
}
|
|
||||||
|
|
||||||
static void mndAddCpuInfo(SMnode* pMnode, SBufferWriter* bw) {
|
|
||||||
char* line = NULL;
|
|
||||||
size_t size = 0;
|
|
||||||
int32_t done = 0;
|
|
||||||
|
|
||||||
// FILE* fp = fopen("/proc/cpuinfo", "r");
|
|
||||||
TdFilePtr pFile = taosOpenFile("/proc/cpuinfo", TD_FILE_READ | TD_FILE_STREAM);
|
|
||||||
if (pFile == NULL) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
while (done != 3 && (size = taosGetLineFile(pFile, &line)) != -1) {
|
|
||||||
line[size - 1] = '\0';
|
|
||||||
if (((done & 1) == 0) && strncmp(line, "model name", 10) == 0) {
|
|
||||||
const char* v = strchr(line, ':') + 2;
|
|
||||||
mndAddStringField(bw, "cpuModel", v);
|
|
||||||
done |= 1;
|
|
||||||
} else if (((done & 2) == 0) && strncmp(line, "cpu cores", 9) == 0) {
|
|
||||||
const char* v = strchr(line, ':') + 2;
|
|
||||||
mndWriteString(bw, "numOfCpu");
|
|
||||||
tbufWriteChar(bw, ':');
|
|
||||||
tbufWrite(bw, v, strlen(v));
|
|
||||||
tbufWriteChar(bw, ',');
|
|
||||||
done |= 2;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if(line != NULL) free(line);
|
|
||||||
taosCloseFile(&pFile);
|
|
||||||
}
|
|
||||||
|
|
||||||
static void mndAddOsInfo(SMnode* pMnode, SBufferWriter* bw) {
|
|
||||||
char* line = NULL;
|
|
||||||
size_t size = 0;
|
|
||||||
|
|
||||||
// FILE* fp = fopen("/etc/os-release", "r");
|
|
||||||
TdFilePtr pFile = taosOpenFile("/etc/os-release", TD_FILE_READ | TD_FILE_STREAM);
|
|
||||||
if (pFile == NULL) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
while ((size = taosGetLineFile(pFile, &line)) != -1) {
|
|
||||||
line[size - 1] = '\0';
|
|
||||||
if (strncmp(line, "PRETTY_NAME", 11) == 0) {
|
|
||||||
const char* p = strchr(line, '=') + 1;
|
|
||||||
if (*p == '"') {
|
|
||||||
p++;
|
|
||||||
line[size - 2] = 0;
|
|
||||||
}
|
|
||||||
mndAddStringField(bw, "os", p);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if(line != NULL) free(line);
|
|
||||||
taosCloseFile(&pFile);
|
|
||||||
}
|
|
||||||
|
|
||||||
static void mndAddMemoryInfo(SMnode* pMnode, SBufferWriter* bw) {
|
|
||||||
char* line = NULL;
|
|
||||||
size_t size = 0;
|
|
||||||
|
|
||||||
// FILE* fp = fopen("/proc/meminfo", "r");
|
|
||||||
TdFilePtr pFile = taosOpenFile("/proc/meminfo", TD_FILE_READ | TD_FILE_STREAM);
|
|
||||||
if (pFile == NULL) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
while ((size = taosGetLineFile(pFile, &line)) != -1) {
|
|
||||||
line[size - 1] = '\0';
|
|
||||||
if (strncmp(line, "MemTotal", 8) == 0) {
|
|
||||||
const char* p = strchr(line, ':') + 1;
|
|
||||||
while (*p == ' ') p++;
|
|
||||||
mndAddStringField(bw, "memory", p);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if(line != NULL) free(line);
|
|
||||||
taosCloseFile(&pFile);
|
|
||||||
}
|
|
||||||
|
|
||||||
static void mndAddVersionInfo(SMnode* pMnode, SBufferWriter* bw) {
|
|
||||||
STelemMgmt* pMgmt = &pMnode->telemMgmt;
|
|
||||||
mndAddStringField(bw, "version", version);
|
|
||||||
mndAddStringField(bw, "buildInfo", buildinfo);
|
|
||||||
mndAddStringField(bw, "gitInfo", gitinfo);
|
|
||||||
mndAddStringField(bw, "email", pMgmt->email);
|
|
||||||
}
|
|
||||||
|
|
||||||
static void mndAddRuntimeInfo(SMnode* pMnode, SBufferWriter* bw) {
|
|
||||||
SMnodeLoad load = {0};
|
SMnodeLoad load = {0};
|
||||||
if (mndGetLoad(pMnode, &load) != 0) {
|
mndGetLoad(pMnode, &load);
|
||||||
return;
|
|
||||||
|
tjsonAddDoubleToObject(pJson, "numOfDnode", load.numOfDnode);
|
||||||
|
tjsonAddDoubleToObject(pJson, "numOfMnode", load.numOfMnode);
|
||||||
|
tjsonAddDoubleToObject(pJson, "numOfVgroup", load.numOfVgroup);
|
||||||
|
tjsonAddDoubleToObject(pJson, "numOfDatabase", load.numOfDatabase);
|
||||||
|
tjsonAddDoubleToObject(pJson, "numOfSuperTable", load.numOfSuperTable);
|
||||||
|
tjsonAddDoubleToObject(pJson, "numOfChildTable", load.numOfChildTable);
|
||||||
|
tjsonAddDoubleToObject(pJson, "numOfColumn", load.numOfColumn);
|
||||||
|
tjsonAddDoubleToObject(pJson, "numOfPoint", load.totalPoints);
|
||||||
|
tjsonAddDoubleToObject(pJson, "totalStorage", load.totalStorage);
|
||||||
|
tjsonAddDoubleToObject(pJson, "compStorage", load.compStorage);
|
||||||
}
|
}
|
||||||
|
|
||||||
mndAddIntField(bw, "numOfDnode", load.numOfDnode);
|
static char* mndBuildTelemetryReport(SMnode* pMnode) {
|
||||||
mndAddIntField(bw, "numOfMnode", load.numOfMnode);
|
char tmp[4096] = {0};
|
||||||
mndAddIntField(bw, "numOfVgroup", load.numOfVgroup);
|
|
||||||
mndAddIntField(bw, "numOfDatabase", load.numOfDatabase);
|
|
||||||
mndAddIntField(bw, "numOfSuperTable", load.numOfSuperTable);
|
|
||||||
mndAddIntField(bw, "numOfChildTable", load.numOfChildTable);
|
|
||||||
mndAddIntField(bw, "numOfColumn", load.numOfColumn);
|
|
||||||
mndAddIntField(bw, "numOfPoint", load.totalPoints);
|
|
||||||
mndAddIntField(bw, "totalStorage", load.totalStorage);
|
|
||||||
mndAddIntField(bw, "compStorage", load.compStorage);
|
|
||||||
}
|
|
||||||
|
|
||||||
static void mndSendTelemetryReport(SMnode* pMnode) {
|
|
||||||
STelemMgmt* pMgmt = &pMnode->telemMgmt;
|
STelemMgmt* pMgmt = &pMnode->telemMgmt;
|
||||||
SBufferWriter bw = tbufInitWriter(NULL, false);
|
|
||||||
int32_t code = -1;
|
SJson* pJson = tjsonCreateObject();
|
||||||
char buf[128] = {0};
|
if (pJson == NULL) return NULL;
|
||||||
SOCKET fd = 0;
|
|
||||||
|
|
||||||
char clusterName[64] = {0};
|
char clusterName[64] = {0};
|
||||||
if (mndGetClusterName(pMnode, clusterName, sizeof(clusterName)) != 0) {
|
mndGetClusterName(pMnode, clusterName, sizeof(clusterName));
|
||||||
goto SEND_OVER;
|
tjsonAddStringToObject(pJson, "instanceId", clusterName);
|
||||||
|
tjsonAddDoubleToObject(pJson, "reportVersion", 1);
|
||||||
|
|
||||||
|
if (taosGetOsReleaseName(tmp, sizeof(tmp)) == 0) {
|
||||||
|
tjsonAddStringToObject(pJson, "os", tmp);
|
||||||
}
|
}
|
||||||
|
|
||||||
mndBeginObject(&bw);
|
float numOfCores = 0;
|
||||||
mndAddStringField(&bw, "instanceId", clusterName);
|
if (taosGetCpuInfo(tmp, sizeof(tmp), &numOfCores) == 0) {
|
||||||
mndAddIntField(&bw, "reportVersion", 1);
|
tjsonAddStringToObject(pJson, "cpuModel", tmp);
|
||||||
mndAddOsInfo(pMnode, &bw);
|
tjsonAddDoubleToObject(pJson, "numOfCpu", numOfCores);
|
||||||
mndAddCpuInfo(pMnode, &bw);
|
} else {
|
||||||
mndAddMemoryInfo(pMnode, &bw);
|
tjsonAddDoubleToObject(pJson, "numOfCpu", tsNumOfCores);
|
||||||
mndAddVersionInfo(pMnode, &bw);
|
|
||||||
mndAddRuntimeInfo(pMnode, &bw);
|
|
||||||
mndCloseObject(&bw);
|
|
||||||
|
|
||||||
uint32_t ip = taosGetIpv4FromFqdn(TELEMETRY_SERVER);
|
|
||||||
if (ip == 0xffffffff) {
|
|
||||||
terrno = TAOS_SYSTEM_ERROR(errno);
|
|
||||||
mError("failed to get ip of %s since :%s", TELEMETRY_SERVER, terrstr());
|
|
||||||
goto SEND_OVER;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fd = taosOpenTcpClientSocket(ip, TELEMETRY_PORT, 0);
|
snprintf(tmp, sizeof(tmp), "%" PRId64 " kB", tsTotalMemoryKB);
|
||||||
if (fd < 0) {
|
tjsonAddStringToObject(pJson, "memory", tmp);
|
||||||
terrno = TAOS_SYSTEM_ERROR(errno);
|
|
||||||
mError("failed to create socket to %s:%d since:%s", TELEMETRY_SERVER, TELEMETRY_PORT, terrstr());
|
|
||||||
goto SEND_OVER;
|
|
||||||
}
|
|
||||||
|
|
||||||
const char* header =
|
tjsonAddStringToObject(pJson, "version", version);
|
||||||
"POST /report HTTP/1.1\n"
|
tjsonAddStringToObject(pJson, "buildInfo", buildinfo);
|
||||||
"Host: " TELEMETRY_SERVER
|
tjsonAddStringToObject(pJson, "gitInfo", gitinfo);
|
||||||
"\n"
|
tjsonAddStringToObject(pJson, "email", pMgmt->email);
|
||||||
"Content-Type: application/json\n"
|
|
||||||
"Content-Length: ";
|
|
||||||
if (taosWriteSocket(fd, (void*)header, (int32_t)strlen(header)) < 0) {
|
|
||||||
goto SEND_OVER;
|
|
||||||
}
|
|
||||||
|
|
||||||
int32_t contLen = (int32_t)(tbufTell(&bw));
|
mndBuildRuntimeInfo(pMnode, pJson);
|
||||||
sprintf(buf, "%d\n\n", contLen);
|
|
||||||
if (taosWriteSocket(fd, buf, (int32_t)strlen(buf)) < 0) {
|
|
||||||
goto SEND_OVER;
|
|
||||||
}
|
|
||||||
|
|
||||||
const char* pCont = tbufGetData(&bw, false);
|
char* pCont = tjsonToString(pJson);
|
||||||
if (taosWriteSocket(fd, (void*)pCont, contLen) < 0) {
|
tjsonDelete(pJson);
|
||||||
goto SEND_OVER;
|
return pCont;
|
||||||
}
|
|
||||||
|
|
||||||
// read something to avoid nginx error 499
|
|
||||||
if (taosReadSocket(fd, buf, 10) < 0) {
|
|
||||||
terrno = TAOS_SYSTEM_ERROR(errno);
|
|
||||||
mError("failed to receive response since %s", terrstr());
|
|
||||||
goto SEND_OVER;
|
|
||||||
}
|
|
||||||
|
|
||||||
mInfo("send telemetry to %s:%d, len:%d content: %s", TELEMETRY_SERVER, TELEMETRY_PORT, contLen, pCont);
|
|
||||||
code = 0;
|
|
||||||
|
|
||||||
SEND_OVER:
|
|
||||||
tbufCloseWriter(&bw);
|
|
||||||
taosCloseSocket(fd);
|
|
||||||
|
|
||||||
if (code != 0) {
|
|
||||||
mError("failed to send telemetry to %s:%d since %s", TELEMETRY_SERVER, TELEMETRY_PORT, terrstr());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static int32_t mndProcessTelemTimer(SMnodeMsg* pReq) {
|
static int32_t mndProcessTelemTimer(SMnodeMsg* pReq) {
|
||||||
|
@ -247,33 +85,23 @@ static int32_t mndProcessTelemTimer(SMnodeMsg* pReq) {
|
||||||
if (!pMgmt->enable) return 0;
|
if (!pMgmt->enable) return 0;
|
||||||
|
|
||||||
taosWLockLatch(&pMgmt->lock);
|
taosWLockLatch(&pMgmt->lock);
|
||||||
mndSendTelemetryReport(pMnode);
|
char* pCont = mndBuildTelemetryReport(pMnode);
|
||||||
|
if (pCont != NULL) {
|
||||||
|
taosSendHttpReport(TELEMETRY_SERVER, TELEMETRY_PORT, pCont, strlen(pCont));
|
||||||
|
free(pCont);
|
||||||
|
}
|
||||||
taosWUnLockLatch(&pMgmt->lock);
|
taosWUnLockLatch(&pMgmt->lock);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void mndGetEmail(SMnode* pMnode, char* filepath) {
|
|
||||||
STelemMgmt* pMgmt = &pMnode->telemMgmt;
|
|
||||||
|
|
||||||
TdFilePtr pFile = taosOpenFile(filepath, TD_FILE_READ);
|
|
||||||
if (pFile == NULL) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (taosReadFile(pFile, (void*)pMgmt->email, TSDB_FQDN_LEN) < 0) {
|
|
||||||
mError("failed to read %d bytes from file %s since %s", TSDB_FQDN_LEN, filepath, strerror(errno));
|
|
||||||
}
|
|
||||||
|
|
||||||
taosCloseFile(&pFile);
|
|
||||||
}
|
|
||||||
|
|
||||||
int32_t mndInitTelem(SMnode* pMnode) {
|
int32_t mndInitTelem(SMnode* pMnode) {
|
||||||
STelemMgmt* pMgmt = &pMnode->telemMgmt;
|
STelemMgmt* pMgmt = &pMnode->telemMgmt;
|
||||||
pMgmt->enable = tsEnableTelemetryReporting;
|
|
||||||
taosInitRWLatch(&pMgmt->lock);
|
|
||||||
mndGetEmail(pMnode, "/usr/local/taos/email");
|
|
||||||
|
|
||||||
|
taosInitRWLatch(&pMgmt->lock);
|
||||||
|
pMgmt->enable = tsEnableTelemetryReporting;
|
||||||
|
taosGetEmail(pMgmt->email, sizeof(pMgmt->email));
|
||||||
mndSetMsgHandle(pMnode, TDMT_MND_TELEM_TIMER, mndProcessTelemTimer);
|
mndSetMsgHandle(pMnode, TDMT_MND_TELEM_TIMER, mndProcessTelemTimer);
|
||||||
|
|
||||||
mDebug("mnode telemetry is initialized");
|
mDebug("mnode telemetry is initialized");
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
|
@ -215,6 +215,9 @@ void *mndBuildCreateVnodeReq(SMnode *pMnode, SDnodeObj *pDnode, SDbObj *pDb, SVg
|
||||||
createReq.replica = pVgroup->replica;
|
createReq.replica = pVgroup->replica;
|
||||||
createReq.selfIndex = -1;
|
createReq.selfIndex = -1;
|
||||||
createReq.streamMode = pVgroup->streamMode;
|
createReq.streamMode = pVgroup->streamMode;
|
||||||
|
createReq.hashBegin = pVgroup->hashBegin;
|
||||||
|
createReq.hashEnd = pVgroup->hashEnd;
|
||||||
|
createReq.hashMethod = pDb->hashMethod;
|
||||||
|
|
||||||
for (int32_t v = 0; v < pVgroup->replica; ++v) {
|
for (int32_t v = 0; v < pVgroup->replica; ++v) {
|
||||||
SReplica *pReplica = &createReq.replicas[v];
|
SReplica *pReplica = &createReq.replicas[v];
|
||||||
|
|
|
@ -22,6 +22,7 @@
|
||||||
#include "mndDb.h"
|
#include "mndDb.h"
|
||||||
#include "mndDnode.h"
|
#include "mndDnode.h"
|
||||||
#include "mndFunc.h"
|
#include "mndFunc.h"
|
||||||
|
#include "mndInfoSchema.h"
|
||||||
#include "mndMnode.h"
|
#include "mndMnode.h"
|
||||||
#include "mndOffset.h"
|
#include "mndOffset.h"
|
||||||
#include "mndProfile.h"
|
#include "mndProfile.h"
|
||||||
|
@ -36,7 +37,6 @@
|
||||||
#include "mndTrans.h"
|
#include "mndTrans.h"
|
||||||
#include "mndUser.h"
|
#include "mndUser.h"
|
||||||
#include "mndVgroup.h"
|
#include "mndVgroup.h"
|
||||||
#include "mndInfoSchema.h"
|
|
||||||
|
|
||||||
#define MQ_TIMER_MS 3000
|
#define MQ_TIMER_MS 3000
|
||||||
#define TRNAS_TIMER_MS 6000
|
#define TRNAS_TIMER_MS 6000
|
||||||
|
@ -359,6 +359,7 @@ SMnode *mndOpen(const char *path, const SMnodeOpt *pOption) {
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
mndUpdateMnodeRole(pMnode);
|
||||||
mDebug("mnode open successfully ");
|
mDebug("mnode open successfully ");
|
||||||
return pMnode;
|
return pMnode;
|
||||||
}
|
}
|
||||||
|
@ -385,21 +386,6 @@ void mndDestroy(const char *path) {
|
||||||
mDebug("mnode is destroyed");
|
mDebug("mnode is destroyed");
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t mndGetLoad(SMnode *pMnode, SMnodeLoad *pLoad) {
|
|
||||||
pLoad->numOfDnode = 0;
|
|
||||||
pLoad->numOfMnode = 0;
|
|
||||||
pLoad->numOfVgroup = 0;
|
|
||||||
pLoad->numOfDatabase = 0;
|
|
||||||
pLoad->numOfSuperTable = 0;
|
|
||||||
pLoad->numOfChildTable = 0;
|
|
||||||
pLoad->numOfColumn = 0;
|
|
||||||
pLoad->totalPoints = 0;
|
|
||||||
pLoad->totalStorage = 0;
|
|
||||||
pLoad->compStorage = 0;
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
SMnodeMsg *mndInitMsg(SMnode *pMnode, SRpcMsg *pRpcMsg) {
|
SMnodeMsg *mndInitMsg(SMnode *pMnode, SRpcMsg *pRpcMsg) {
|
||||||
SMnodeMsg *pMsg = taosAllocateQitem(sizeof(SMnodeMsg));
|
SMnodeMsg *pMsg = taosAllocateQitem(sizeof(SMnodeMsg));
|
||||||
if (pMsg == NULL) {
|
if (pMsg == NULL) {
|
||||||
|
@ -489,7 +475,7 @@ PROCESS_RPC_END:
|
||||||
if (code == TSDB_CODE_APP_NOT_READY) {
|
if (code == TSDB_CODE_APP_NOT_READY) {
|
||||||
mndSendRedirectRsp(pMnode, &pMsg->rpcMsg);
|
mndSendRedirectRsp(pMnode, &pMsg->rpcMsg);
|
||||||
} else if (code != 0) {
|
} else if (code != 0) {
|
||||||
SRpcMsg rpcRsp = {.handle = pMsg->rpcMsg.handle, .code = code};
|
SRpcMsg rpcRsp = {.handle = pMsg->rpcMsg.handle, .contLen = pMsg->contLen, .pCont = pMsg->pCont, .code = code};
|
||||||
rpcSendResponse(&rpcRsp);
|
rpcSendResponse(&rpcRsp);
|
||||||
} else {
|
} else {
|
||||||
SRpcMsg rpcRsp = {.handle = pMsg->rpcMsg.handle, .contLen = pMsg->contLen, .pCont = pMsg->pCont};
|
SRpcMsg rpcRsp = {.handle = pMsg->rpcMsg.handle, .contLen = pMsg->contLen, .pCont = pMsg->pCont};
|
||||||
|
@ -505,7 +491,6 @@ void mndSetMsgHandle(SMnode *pMnode, tmsg_t msgType, MndMsgFp fp) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// Note: uid 0 is reserved
|
// Note: uid 0 is reserved
|
||||||
uint64_t mndGenerateUid(char *name, int32_t len) {
|
uint64_t mndGenerateUid(char *name, int32_t len) {
|
||||||
int32_t hashval = MurmurHash3_32(name, len);
|
int32_t hashval = MurmurHash3_32(name, len);
|
||||||
|
@ -519,3 +504,131 @@ uint64_t mndGenerateUid(char *name, int32_t len) {
|
||||||
}
|
}
|
||||||
} while (true);
|
} while (true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void mndGetLoad(SMnode *pMnode, SMnodeLoad *pLoad) {
|
||||||
|
memset(pLoad, 0, sizeof(SMnodeLoad));
|
||||||
|
|
||||||
|
SSdb *pSdb = pMnode->pSdb;
|
||||||
|
pLoad->numOfDnode = sdbGetSize(pSdb, SDB_DNODE);
|
||||||
|
pLoad->numOfMnode = sdbGetSize(pSdb, SDB_MNODE);
|
||||||
|
pLoad->numOfVgroup = sdbGetSize(pSdb, SDB_VGROUP);
|
||||||
|
pLoad->numOfDatabase = sdbGetSize(pSdb, SDB_DB);
|
||||||
|
pLoad->numOfSuperTable = sdbGetSize(pSdb, SDB_STB);
|
||||||
|
|
||||||
|
void *pIter = NULL;
|
||||||
|
while (1) {
|
||||||
|
SVgObj *pVgroup = NULL;
|
||||||
|
pIter = sdbFetch(pSdb, SDB_VGROUP, pIter, (void **)&pVgroup);
|
||||||
|
if (pIter == NULL) break;
|
||||||
|
|
||||||
|
pLoad->numOfChildTable += pVgroup->numOfTables;
|
||||||
|
pLoad->numOfColumn += pVgroup->numOfTimeSeries;
|
||||||
|
pLoad->totalPoints += pVgroup->pointsWritten;
|
||||||
|
pLoad->totalStorage += pVgroup->totalStorage;
|
||||||
|
pLoad->compStorage += pVgroup->compStorage;
|
||||||
|
|
||||||
|
sdbRelease(pSdb, pVgroup);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
int32_t mndGetMonitorInfo(SMnode *pMnode, SMonClusterInfo *pClusterInfo, SMonVgroupInfo *pVgroupInfo,
|
||||||
|
SMonGrantInfo *pGrantInfo) {
|
||||||
|
if (!mndIsMaster(pMnode)) return -1;
|
||||||
|
|
||||||
|
SSdb *pSdb = pMnode->pSdb;
|
||||||
|
int64_t ms = taosGetTimestampMs();
|
||||||
|
|
||||||
|
pClusterInfo->dnodes = taosArrayInit(sdbGetSize(pSdb, SDB_DNODE), sizeof(SMonDnodeDesc));
|
||||||
|
pClusterInfo->mnodes = taosArrayInit(sdbGetSize(pSdb, SDB_MNODE), sizeof(SMonMnodeDesc));
|
||||||
|
pVgroupInfo->vgroups = taosArrayInit(sdbGetSize(pSdb, SDB_VGROUP), sizeof(SMonVgroupDesc));
|
||||||
|
if (pClusterInfo->dnodes == NULL || pClusterInfo->mnodes == NULL || pVgroupInfo->vgroups == NULL) {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
// cluster info
|
||||||
|
tstrncpy(pClusterInfo->version, version, sizeof(pClusterInfo->version));
|
||||||
|
pClusterInfo->monitor_interval = tsMonitorInterval;
|
||||||
|
pClusterInfo->connections_total = mndGetNumOfConnections(pMnode);
|
||||||
|
|
||||||
|
void *pIter = NULL;
|
||||||
|
while (1) {
|
||||||
|
SDnodeObj *pObj = NULL;
|
||||||
|
pIter = sdbFetch(pSdb, SDB_DNODE, pIter, (void **)&pObj);
|
||||||
|
if (pIter == NULL) break;
|
||||||
|
|
||||||
|
SMonDnodeDesc desc = {0};
|
||||||
|
desc.dnode_id = pObj->id;
|
||||||
|
tstrncpy(desc.dnode_ep, pObj->ep, sizeof(desc.dnode_ep));
|
||||||
|
if (mndIsDnodeOnline(pMnode, pObj, ms)) {
|
||||||
|
tstrncpy(desc.status, "ready", sizeof(desc.status));
|
||||||
|
} else {
|
||||||
|
tstrncpy(desc.status, "offline", sizeof(desc.status));
|
||||||
|
}
|
||||||
|
taosArrayPush(pClusterInfo->dnodes, &desc);
|
||||||
|
sdbRelease(pSdb, pObj);
|
||||||
|
}
|
||||||
|
|
||||||
|
pIter = NULL;
|
||||||
|
while (1) {
|
||||||
|
SMnodeObj *pObj = NULL;
|
||||||
|
pIter = sdbFetch(pSdb, SDB_MNODE, pIter, (void **)&pObj);
|
||||||
|
if (pIter == NULL) break;
|
||||||
|
|
||||||
|
SMonMnodeDesc desc = {0};
|
||||||
|
desc.mnode_id = pObj->id;
|
||||||
|
tstrncpy(desc.mnode_ep, pObj->pDnode->ep, sizeof(desc.mnode_ep));
|
||||||
|
tstrncpy(desc.role, mndGetRoleStr(pObj->role), sizeof(desc.role));
|
||||||
|
taosArrayPush(pClusterInfo->mnodes, &desc);
|
||||||
|
sdbRelease(pSdb, pObj);
|
||||||
|
|
||||||
|
if (pObj->role == TAOS_SYNC_STATE_LEADER) {
|
||||||
|
pClusterInfo->first_ep_dnode_id = pObj->id;
|
||||||
|
tstrncpy(pClusterInfo->first_ep, pObj->pDnode->ep, sizeof(pClusterInfo->first_ep));
|
||||||
|
pClusterInfo->master_uptime = (ms - pObj->roleTime) / (86400000.0f);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// vgroup info
|
||||||
|
pIter = NULL;
|
||||||
|
while (1) {
|
||||||
|
SVgObj *pVgroup = NULL;
|
||||||
|
pIter = sdbFetch(pSdb, SDB_VGROUP, pIter, (void **)&pVgroup);
|
||||||
|
if (pIter == NULL) break;
|
||||||
|
|
||||||
|
pClusterInfo->vgroups_total++;
|
||||||
|
|
||||||
|
SMonVgroupDesc desc = {0};
|
||||||
|
desc.vgroup_id = pVgroup->vgId;
|
||||||
|
strncpy(desc.database_name, pVgroup->dbName, sizeof(desc.database_name));
|
||||||
|
desc.tables_num = pVgroup->numOfTables;
|
||||||
|
pGrantInfo->timeseries_used += pVgroup->numOfTimeSeries;
|
||||||
|
tstrncpy(desc.status, "unsynced", sizeof(desc.status));
|
||||||
|
for (int32_t i = 0; i < pVgroup->replica; ++i) {
|
||||||
|
SVnodeGid *pVgid = &pVgroup->vnodeGid[i];
|
||||||
|
SMonVnodeDesc *pVnDesc = &desc.vnodes[i];
|
||||||
|
pVnDesc->dnode_id = pVgid->dnodeId;
|
||||||
|
tstrncpy(pVnDesc->vnode_role, mndGetRoleStr(pVgid->role), sizeof(pVnDesc->vnode_role));
|
||||||
|
if (pVgid->role == TAOS_SYNC_STATE_LEADER) {
|
||||||
|
tstrncpy(desc.status, "ready", sizeof(desc.status));
|
||||||
|
pClusterInfo->vgroups_alive++;
|
||||||
|
}
|
||||||
|
if (pVgid->role == TAOS_SYNC_STATE_LEADER || pVgid->role == TAOS_SYNC_STATE_CANDIDATE) {
|
||||||
|
pClusterInfo->vnodes_alive++;
|
||||||
|
}
|
||||||
|
pClusterInfo->vnodes_total++;
|
||||||
|
}
|
||||||
|
|
||||||
|
taosArrayPush(pVgroupInfo->vgroups, &desc);
|
||||||
|
sdbRelease(pSdb, pVgroup);
|
||||||
|
}
|
||||||
|
|
||||||
|
// grant info
|
||||||
|
pGrantInfo->expire_time = (pMnode->grant.expireTimeMS - ms) / 86400000.0f;
|
||||||
|
pGrantInfo->timeseries_total = pMnode->grant.timeseriesAllowed;
|
||||||
|
if (pMnode->grant.expireTimeMS == 0) {
|
||||||
|
pGrantInfo->expire_time = INT32_MAX;
|
||||||
|
pGrantInfo->timeseries_total = INT32_MAX;
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
|
@ -1,13 +1,10 @@
|
||||||
aux_source_directory(src MNODE_SRC)
|
aux_source_directory(src MNODE_SRC)
|
||||||
add_library(sdb ${MNODE_SRC})
|
add_library(sdb STATIC ${MNODE_SRC})
|
||||||
target_include_directories(
|
target_include_directories(
|
||||||
sdb
|
sdb
|
||||||
PUBLIC "${CMAKE_SOURCE_DIR}/include/dnode/mnode/sdb"
|
PUBLIC "${CMAKE_SOURCE_DIR}/include/dnode/mnode/sdb"
|
||||||
PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/inc"
|
PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/inc"
|
||||||
)
|
)
|
||||||
target_link_libraries(
|
target_link_libraries(
|
||||||
sdb
|
sdb os common util
|
||||||
PRIVATE os
|
|
||||||
PRIVATE common
|
|
||||||
PRIVATE util
|
|
||||||
)
|
)
|
|
@ -28,12 +28,12 @@
|
||||||
extern "C" {
|
extern "C" {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#define mFatal(...) { if (mDebugFlag & DEBUG_FATAL) { taosPrintLog("MND FATAL ", 255, __VA_ARGS__); }}
|
#define mFatal(...) { if (mDebugFlag & DEBUG_FATAL) { taosPrintLog("MND FATAL ", DEBUG_FATAL, 255, __VA_ARGS__); }}
|
||||||
#define mError(...) { if (mDebugFlag & DEBUG_ERROR) { taosPrintLog("MND ERROR ", 255, __VA_ARGS__); }}
|
#define mError(...) { if (mDebugFlag & DEBUG_ERROR) { taosPrintLog("MND ERROR ", DEBUG_ERROR, 255, __VA_ARGS__); }}
|
||||||
#define mWarn(...) { if (mDebugFlag & DEBUG_WARN) { taosPrintLog("MND WARN ", 255, __VA_ARGS__); }}
|
#define mWarn(...) { if (mDebugFlag & DEBUG_WARN) { taosPrintLog("MND WARN ", DEBUG_WARN, 255, __VA_ARGS__); }}
|
||||||
#define mInfo(...) { if (mDebugFlag & DEBUG_INFO) { taosPrintLog("MND ", 255, __VA_ARGS__); }}
|
#define mInfo(...) { if (mDebugFlag & DEBUG_INFO) { taosPrintLog("MND ", DEBUG_INFO, 255, __VA_ARGS__); }}
|
||||||
#define mDebug(...) { if (mDebugFlag & DEBUG_DEBUG) { taosPrintLog("MND ", mDebugFlag, __VA_ARGS__); }}
|
#define mDebug(...) { if (mDebugFlag & DEBUG_DEBUG) { taosPrintLog("MND ", DEBUG_DEBUG, mDebugFlag, __VA_ARGS__); }}
|
||||||
#define mTrace(...) { if (mDebugFlag & DEBUG_TRACE) { taosPrintLog("MND ", mDebugFlag, __VA_ARGS__); }}
|
#define mTrace(...) { if (mDebugFlag & DEBUG_TRACE) { taosPrintLog("MND ", DEBUG_TRACE, mDebugFlag, __VA_ARGS__); }}
|
||||||
|
|
||||||
#define SDB_MAX_SIZE (32 * 1024)
|
#define SDB_MAX_SIZE (32 * 1024)
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
aux_source_directory(src QNODE_SRC)
|
aux_source_directory(src QNODE_SRC)
|
||||||
add_library(qnode ${QNODE_SRC})
|
add_library(qnode STATIC ${QNODE_SRC})
|
||||||
target_include_directories(
|
target_include_directories(
|
||||||
qnode
|
qnode
|
||||||
PUBLIC "${CMAKE_SOURCE_DIR}/include/dnode/qnode"
|
PUBLIC "${CMAKE_SOURCE_DIR}/include/dnode/qnode"
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
aux_source_directory(src SNODE_SRC)
|
aux_source_directory(src SNODE_SRC)
|
||||||
add_library(snode ${SNODE_SRC})
|
add_library(snode STATIC ${SNODE_SRC})
|
||||||
target_include_directories(
|
target_include_directories(
|
||||||
snode
|
snode
|
||||||
PUBLIC "${CMAKE_SOURCE_DIR}/include/dnode/snode"
|
PUBLIC "${CMAKE_SOURCE_DIR}/include/dnode/snode"
|
||||||
|
|
|
@ -27,12 +27,12 @@ extern "C" {
|
||||||
|
|
||||||
typedef struct SDataStatis {
|
typedef struct SDataStatis {
|
||||||
int16_t colId;
|
int16_t colId;
|
||||||
int64_t sum;
|
|
||||||
int64_t max;
|
|
||||||
int64_t min;
|
|
||||||
int16_t maxIndex;
|
int16_t maxIndex;
|
||||||
int16_t minIndex;
|
int16_t minIndex;
|
||||||
int16_t numOfNull;
|
int16_t numOfNull;
|
||||||
|
int64_t sum;
|
||||||
|
int64_t max;
|
||||||
|
int64_t min;
|
||||||
} SDataStatis;
|
} SDataStatis;
|
||||||
|
|
||||||
typedef struct STable {
|
typedef struct STable {
|
||||||
|
@ -53,6 +53,8 @@ typedef struct STsdb STsdb;
|
||||||
|
|
||||||
typedef struct STsdbCfg {
|
typedef struct STsdbCfg {
|
||||||
int8_t precision;
|
int8_t precision;
|
||||||
|
int8_t update;
|
||||||
|
int8_t compression;
|
||||||
uint64_t lruCacheSize;
|
uint64_t lruCacheSize;
|
||||||
int32_t daysPerFile;
|
int32_t daysPerFile;
|
||||||
int32_t minRowsPerFileBlock;
|
int32_t minRowsPerFileBlock;
|
||||||
|
@ -60,8 +62,6 @@ typedef struct STsdbCfg {
|
||||||
int32_t keep;
|
int32_t keep;
|
||||||
int32_t keep1;
|
int32_t keep1;
|
||||||
int32_t keep2;
|
int32_t keep2;
|
||||||
int8_t update;
|
|
||||||
int8_t compression;
|
|
||||||
} STsdbCfg;
|
} STsdbCfg;
|
||||||
|
|
||||||
// query condition to build multi-table data block iterator
|
// query condition to build multi-table data block iterator
|
||||||
|
|
|
@ -57,13 +57,12 @@ typedef struct {
|
||||||
SMetaCfg metaCfg;
|
SMetaCfg metaCfg;
|
||||||
STqCfg tqCfg;
|
STqCfg tqCfg;
|
||||||
SWalCfg walCfg;
|
SWalCfg walCfg;
|
||||||
|
uint32_t hashBegin;
|
||||||
|
uint32_t hashEnd;
|
||||||
|
int8_t hashMethod;
|
||||||
} SVnodeCfg;
|
} SVnodeCfg;
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
int32_t sver;
|
|
||||||
const char *timezone;
|
|
||||||
const char *locale;
|
|
||||||
const char *charset;
|
|
||||||
uint16_t nthreads; // number of commit threads. 0 for no threads and a schedule queue should be given (TODO)
|
uint16_t nthreads; // number of commit threads. 0 for no threads and a schedule queue should be given (TODO)
|
||||||
PutReqToVQueryQFp putReqToVQueryQFp;
|
PutReqToVQueryQFp putReqToVQueryQFp;
|
||||||
SendReqToDnodeFp sendReqToDnodeFp;
|
SendReqToDnodeFp sendReqToDnodeFp;
|
||||||
|
|
|
@ -25,42 +25,40 @@
|
||||||
extern "C" {
|
extern "C" {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
extern int32_t tqDebugFlag;
|
|
||||||
|
|
||||||
#define tqFatal(...) \
|
#define tqFatal(...) \
|
||||||
{ \
|
{ \
|
||||||
if (tqDebugFlag & DEBUG_FATAL) { \
|
if (tqDebugFlag & DEBUG_FATAL) { \
|
||||||
taosPrintLog("TQ FATAL ", 255, __VA_ARGS__); \
|
taosPrintLog("TQ FATAL ", DEBUG_FATAL, 255, __VA_ARGS__); \
|
||||||
} \
|
} \
|
||||||
}
|
}
|
||||||
#define tqError(...) \
|
#define tqError(...) \
|
||||||
{ \
|
{ \
|
||||||
if (tqDebugFlag & DEBUG_ERROR) { \
|
if (tqDebugFlag & DEBUG_ERROR) { \
|
||||||
taosPrintLog("TQ ERROR ", 255, __VA_ARGS__); \
|
taosPrintLog("TQ ERROR ", DEBUG_ERROR, 255, __VA_ARGS__); \
|
||||||
} \
|
} \
|
||||||
}
|
}
|
||||||
#define tqWarn(...) \
|
#define tqWarn(...) \
|
||||||
{ \
|
{ \
|
||||||
if (tqDebugFlag & DEBUG_WARN) { \
|
if (tqDebugFlag & DEBUG_WARN) { \
|
||||||
taosPrintLog("TQ WARN ", 255, __VA_ARGS__); \
|
taosPrintLog("TQ WARN ", DEBUG_WARN, 255, __VA_ARGS__); \
|
||||||
} \
|
} \
|
||||||
}
|
}
|
||||||
#define tqInfo(...) \
|
#define tqInfo(...) \
|
||||||
{ \
|
{ \
|
||||||
if (tqDebugFlag & DEBUG_INFO) { \
|
if (tqDebugFlag & DEBUG_INFO) { \
|
||||||
taosPrintLog("TQ ", 255, __VA_ARGS__); \
|
taosPrintLog("TQ ", DEBUG_INFO, 255, __VA_ARGS__); \
|
||||||
} \
|
} \
|
||||||
}
|
}
|
||||||
#define tqDebug(...) \
|
#define tqDebug(...) \
|
||||||
{ \
|
{ \
|
||||||
if (tqDebugFlag & DEBUG_DEBUG) { \
|
if (tqDebugFlag & DEBUG_DEBUG) { \
|
||||||
taosPrintLog("TQ ", tqDebugFlag, __VA_ARGS__); \
|
taosPrintLog("TQ ", DEBUG_DEBUG, tqDebugFlag, __VA_ARGS__); \
|
||||||
} \
|
} \
|
||||||
}
|
}
|
||||||
#define tqTrace(...) \
|
#define tqTrace(...) \
|
||||||
{ \
|
{ \
|
||||||
if (tqDebugFlag & DEBUG_TRACE) { \
|
if (tqDebugFlag & DEBUG_TRACE) { \
|
||||||
taosPrintLog("TQ ", tqDebugFlag, __VA_ARGS__); \
|
taosPrintLog("TQ ", DEBUG_TRACE, tqDebugFlag, __VA_ARGS__); \
|
||||||
} \
|
} \
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -18,8 +18,6 @@
|
||||||
|
|
||||||
#include "tsdbFile.h"
|
#include "tsdbFile.h"
|
||||||
|
|
||||||
#define TSDB_FS_VERSION 0
|
|
||||||
|
|
||||||
// ================== TSDB global config
|
// ================== TSDB global config
|
||||||
extern bool tsdbForceKeepFile;
|
extern bool tsdbForceKeepFile;
|
||||||
|
|
||||||
|
|
|
@ -44,7 +44,37 @@
|
||||||
#define TSDB_FILE_IS_OK(tf) (TSDB_FILE_STATE(tf) == TSDB_FILE_STATE_OK)
|
#define TSDB_FILE_IS_OK(tf) (TSDB_FILE_STATE(tf) == TSDB_FILE_STATE_OK)
|
||||||
#define TSDB_FILE_IS_BAD(tf) (TSDB_FILE_STATE(tf) == TSDB_FILE_STATE_BAD)
|
#define TSDB_FILE_IS_BAD(tf) (TSDB_FILE_STATE(tf) == TSDB_FILE_STATE_BAD)
|
||||||
|
|
||||||
typedef enum { TSDB_FILE_HEAD = 0, TSDB_FILE_DATA, TSDB_FILE_LAST, TSDB_FILE_MAX, TSDB_FILE_META } TSDB_FILE_T;
|
typedef enum {
|
||||||
|
TSDB_FILE_HEAD = 0, // .head
|
||||||
|
TSDB_FILE_DATA, // .data
|
||||||
|
TSDB_FILE_LAST, // .last
|
||||||
|
TSDB_FILE_SMAD, // .smad(Block-wise SMA)
|
||||||
|
TSDB_FILE_SMAL, // .smal(Block-wise SMA)
|
||||||
|
TSDB_FILE_MAX, //
|
||||||
|
TSDB_FILE_META, // meta
|
||||||
|
TSDB_FILE_TSMA, // .tsma.${sma_index_name}, Time-range-wise SMA
|
||||||
|
TSDB_FILE_RSMA, // .rsma.${sma_index_name}, Time-range-wise Rollup SMA
|
||||||
|
} TSDB_FILE_T;
|
||||||
|
|
||||||
|
typedef enum {
|
||||||
|
TSDB_FS_VER_0 = 0,
|
||||||
|
TSDB_FS_VER_MAX,
|
||||||
|
} ETsdbFsVer;
|
||||||
|
|
||||||
|
#define TSDB_LATEST_FVER TSDB_FS_VER_0 // latest version for DFile
|
||||||
|
#define TSDB_LATEST_SFS_VER TSDB_FS_VER_0 // latest version for 'current' file
|
||||||
|
|
||||||
|
static FORCE_INLINE uint32_t tsdbGetDFSVersion(TSDB_FILE_T fType) { // latest version for DFile
|
||||||
|
switch (fType) {
|
||||||
|
case TSDB_FILE_HEAD: // .head
|
||||||
|
case TSDB_FILE_DATA: // .data
|
||||||
|
case TSDB_FILE_LAST: // .last
|
||||||
|
case TSDB_FILE_SMAD: // .smad(Block-wise SMA)
|
||||||
|
case TSDB_FILE_SMAL: // .smal(Block-wise SMA)
|
||||||
|
default:
|
||||||
|
return TSDB_LATEST_FVER;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#if 0
|
#if 0
|
||||||
// =============== SMFile
|
// =============== SMFile
|
||||||
|
@ -169,6 +199,7 @@ static FORCE_INLINE int64_t tsdbReadMFile(SMFile* pMFile, void* buf, int64_t nby
|
||||||
// =============== SDFile
|
// =============== SDFile
|
||||||
typedef struct {
|
typedef struct {
|
||||||
uint32_t magic;
|
uint32_t magic;
|
||||||
|
uint32_t fver;
|
||||||
uint32_t len;
|
uint32_t len;
|
||||||
uint32_t totalBlocks;
|
uint32_t totalBlocks;
|
||||||
uint32_t totalSubBlocks;
|
uint32_t totalSubBlocks;
|
||||||
|
@ -188,7 +219,7 @@ void tsdbInitDFile(STsdb *pRepo, SDFile* pDFile, SDiskID did, int fid, uint32_t
|
||||||
void tsdbInitDFileEx(SDFile* pDFile, SDFile* pODFile);
|
void tsdbInitDFileEx(SDFile* pDFile, SDFile* pODFile);
|
||||||
int tsdbEncodeSDFile(void** buf, SDFile* pDFile);
|
int tsdbEncodeSDFile(void** buf, SDFile* pDFile);
|
||||||
void* tsdbDecodeSDFile(STsdb *pRepo, void* buf, SDFile* pDFile);
|
void* tsdbDecodeSDFile(STsdb *pRepo, void* buf, SDFile* pDFile);
|
||||||
int tsdbCreateDFile(STsdb *pRepo, SDFile* pDFile, bool updateHeader);
|
int tsdbCreateDFile(STsdb *pRepo, SDFile* pDFile, bool updateHeader, TSDB_FILE_T fType);
|
||||||
int tsdbUpdateDFileHeader(SDFile* pDFile);
|
int tsdbUpdateDFileHeader(SDFile* pDFile);
|
||||||
int tsdbLoadDFileHeader(SDFile* pDFile, SDFInfo* pInfo);
|
int tsdbLoadDFileHeader(SDFile* pDFile, SDFInfo* pInfo);
|
||||||
int tsdbParseDFilename(const char* fname, int* vid, int* fid, TSDB_FILE_T* ftype, uint32_t* version);
|
int tsdbParseDFilename(const char* fname, int* vid, int* fid, TSDB_FILE_T* ftype, uint32_t* version);
|
||||||
|
@ -293,11 +324,17 @@ static FORCE_INLINE int tsdbCopyDFile(SDFile* pSrc, SDFile* pDest) {
|
||||||
// =============== SDFileSet
|
// =============== SDFileSet
|
||||||
typedef struct {
|
typedef struct {
|
||||||
int fid;
|
int fid;
|
||||||
int state;
|
int8_t state; // -128~127
|
||||||
|
uint8_t ver; // 0~255, DFileSet version
|
||||||
|
uint16_t reserve;
|
||||||
SDFile files[TSDB_FILE_MAX];
|
SDFile files[TSDB_FILE_MAX];
|
||||||
} SDFileSet;
|
} SDFileSet;
|
||||||
|
|
||||||
|
#define TSDB_LATEST_FSET_VER 0
|
||||||
|
|
||||||
#define TSDB_FSET_FID(s) ((s)->fid)
|
#define TSDB_FSET_FID(s) ((s)->fid)
|
||||||
|
#define TSDB_FSET_STATE(s) ((s)->state)
|
||||||
|
#define TSDB_FSET_VER(s) ((s)->ver)
|
||||||
#define TSDB_DFILE_IN_SET(s, t) ((s)->files + (t))
|
#define TSDB_DFILE_IN_SET(s, t) ((s)->files + (t))
|
||||||
#define TSDB_FSET_LEVEL(s) TSDB_FILE_LEVEL(TSDB_DFILE_IN_SET(s, 0))
|
#define TSDB_FSET_LEVEL(s) TSDB_FILE_LEVEL(TSDB_DFILE_IN_SET(s, 0))
|
||||||
#define TSDB_FSET_ID(s) TSDB_FILE_ID(TSDB_DFILE_IN_SET(s, 0))
|
#define TSDB_FSET_ID(s) TSDB_FILE_ID(TSDB_DFILE_IN_SET(s, 0))
|
||||||
|
|
|
@ -20,11 +20,11 @@
|
||||||
|
|
||||||
extern int32_t tsdbDebugFlag;
|
extern int32_t tsdbDebugFlag;
|
||||||
|
|
||||||
#define tsdbFatal(...) do { if (tsdbDebugFlag & DEBUG_FATAL) { taosPrintLog("TDB FATAL ", 255, __VA_ARGS__); }} while(0)
|
#define tsdbFatal(...) do { if (tsdbDebugFlag & DEBUG_FATAL) { taosPrintLog("TDB FATAL ", DEBUG_FATAL, 255, __VA_ARGS__); }} while(0)
|
||||||
#define tsdbError(...) do { if (tsdbDebugFlag & DEBUG_ERROR) { taosPrintLog("TDB ERROR ", 255, __VA_ARGS__); }} while(0)
|
#define tsdbError(...) do { if (tsdbDebugFlag & DEBUG_ERROR) { taosPrintLog("TDB ERROR ", DEBUG_ERROR, 255, __VA_ARGS__); }} while(0)
|
||||||
#define tsdbWarn(...) do { if (tsdbDebugFlag & DEBUG_WARN) { taosPrintLog("TDB WARN ", 255, __VA_ARGS__); }} while(0)
|
#define tsdbWarn(...) do { if (tsdbDebugFlag & DEBUG_WARN) { taosPrintLog("TDB WARN ", DEBUG_WARN, 255, __VA_ARGS__); }} while(0)
|
||||||
#define tsdbInfo(...) do { if (tsdbDebugFlag & DEBUG_INFO) { taosPrintLog("TDB ", 255, __VA_ARGS__); }} while(0)
|
#define tsdbInfo(...) do { if (tsdbDebugFlag & DEBUG_INFO) { taosPrintLog("TDB ", DEBUG_INFO, 255, __VA_ARGS__); }} while(0)
|
||||||
#define tsdbDebug(...) do { if (tsdbDebugFlag & DEBUG_DEBUG) { taosPrintLog("TDB ", tsdbDebugFlag, __VA_ARGS__); }} while(0)
|
#define tsdbDebug(...) do { if (tsdbDebugFlag & DEBUG_DEBUG) { taosPrintLog("TDB ", DEBUG_DEBUG, tsdbDebugFlag, __VA_ARGS__); }} while(0)
|
||||||
#define tsdbTrace(...) do { if (tsdbDebugFlag & DEBUG_TRACE) { taosPrintLog("TDB ", tsdbDebugFlag, __VA_ARGS__); }} while(0)
|
#define tsdbTrace(...) do { if (tsdbDebugFlag & DEBUG_TRACE) { taosPrintLog("TDB ", DEBUG_TRACE, tsdbDebugFlag, __VA_ARGS__); }} while(0)
|
||||||
|
|
||||||
#endif /* _TD_TSDB_LOG_H_ */
|
#endif /* _TD_TSDB_LOG_H_ */
|
|
@ -36,6 +36,7 @@ typedef struct {
|
||||||
TSKEY maxKey;
|
TSKEY maxKey;
|
||||||
} SBlockIdx;
|
} SBlockIdx;
|
||||||
|
|
||||||
|
#ifdef TD_REFACTOR_3
|
||||||
typedef struct {
|
typedef struct {
|
||||||
int64_t last : 1;
|
int64_t last : 1;
|
||||||
int64_t offset : 63;
|
int64_t offset : 63;
|
||||||
|
@ -49,22 +50,35 @@ typedef struct {
|
||||||
TSKEY keyLast;
|
TSKEY keyLast;
|
||||||
} SBlock;
|
} SBlock;
|
||||||
|
|
||||||
|
#else
|
||||||
|
|
||||||
|
typedef enum {
|
||||||
|
TSDB_SBLK_VER_0 = 0,
|
||||||
|
TSDB_SBLK_VER_MAX,
|
||||||
|
} ESBlockVer;
|
||||||
|
|
||||||
|
#define SBlockVerLatest TSDB_SBLK_VER_0
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
int64_t last : 1;
|
uint8_t last : 1;
|
||||||
int64_t offset : 63;
|
uint8_t blkVer : 7;
|
||||||
int32_t algorithm : 8;
|
|
||||||
int32_t numOfRows : 24;
|
|
||||||
uint8_t reserve0;
|
|
||||||
uint8_t numOfSubBlocks;
|
uint8_t numOfSubBlocks;
|
||||||
int16_t numOfCols; // not including timestamp column
|
int16_t numOfCols; // not including timestamp column
|
||||||
uint32_t len : 32; // data block length
|
uint32_t len; // data block length
|
||||||
uint32_t keyLen : 24; // key column length, keyOffset = offset+sizeof(SBlockData)+sizeof(SBlockCol)*numOfCols
|
uint32_t keyLen : 24; // key column length, keyOffset = offset+sizeof(SBlockData)+sizeof(SBlockCol)*numOfCols
|
||||||
uint32_t reserve1 : 8;
|
uint32_t reserve : 8;
|
||||||
uint64_t blkVer : 8;
|
int32_t algorithm : 8;
|
||||||
uint64_t aggrOffset : 56;
|
int32_t numOfRows : 24;
|
||||||
|
int64_t offset;
|
||||||
|
uint64_t aggrStat : 1;
|
||||||
|
uint64_t aggrOffset : 63;
|
||||||
TSKEY keyFirst;
|
TSKEY keyFirst;
|
||||||
TSKEY keyLast;
|
TSKEY keyLast;
|
||||||
} SBlock_3;
|
} SBlockV0;
|
||||||
|
|
||||||
|
#define SBlock SBlockV0 // latest SBlock definition
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
int32_t delimiter; // For recovery usage
|
int32_t delimiter; // For recovery usage
|
||||||
|
@ -73,6 +87,7 @@ typedef struct {
|
||||||
SBlock blocks[];
|
SBlock blocks[];
|
||||||
} SBlockInfo;
|
} SBlockInfo;
|
||||||
|
|
||||||
|
#ifdef TD_REFACTOR_3
|
||||||
typedef struct {
|
typedef struct {
|
||||||
int16_t colId;
|
int16_t colId;
|
||||||
uint16_t bitmap : 1; // 0: has bitmap if has NULL/NORM rows, 1: no bitmap if all rows are NORM
|
uint16_t bitmap : 1; // 0: has bitmap if has NULL/NORM rows, 1: no bitmap if all rows are NORM
|
||||||
|
@ -89,17 +104,50 @@ typedef struct {
|
||||||
uint8_t offsetH;
|
uint8_t offsetH;
|
||||||
char padding[1];
|
char padding[1];
|
||||||
} SBlockCol;
|
} SBlockCol;
|
||||||
|
#else
|
||||||
|
typedef struct {
|
||||||
|
int16_t colId;
|
||||||
|
uint8_t bitmap : 1; // 0: has bitmap if has NULL/NORM rows, 1: no bitmap if all rows are NORM
|
||||||
|
uint8_t reserve : 7;
|
||||||
|
uint8_t type;
|
||||||
|
int32_t len;
|
||||||
|
uint32_t offset;
|
||||||
|
} SBlockColV0;
|
||||||
|
|
||||||
|
#define SBlockCol SBlockColV0 // latest SBlockCol definition
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
int16_t colId;
|
||||||
|
int16_t maxIndex;
|
||||||
|
int16_t minIndex;
|
||||||
|
int16_t numOfNull;
|
||||||
|
int64_t sum;
|
||||||
|
int64_t max;
|
||||||
|
int64_t min;
|
||||||
|
} SAggrBlkColV0;
|
||||||
|
|
||||||
|
#define SAggrBlkCol SAggrBlkColV0 // latest SAggrBlkCol definition
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
// Code here just for back-ward compatibility
|
// Code here just for back-ward compatibility
|
||||||
static FORCE_INLINE void tsdbSetBlockColOffset(SBlockCol *pBlockCol, uint32_t offset) {
|
static FORCE_INLINE void tsdbSetBlockColOffset(SBlockCol *pBlockCol, uint32_t offset) {
|
||||||
|
#ifdef TD_REFACTOR_3
|
||||||
pBlockCol->offset = offset & ((((uint32_t)1) << 24) - 1);
|
pBlockCol->offset = offset & ((((uint32_t)1) << 24) - 1);
|
||||||
pBlockCol->offsetH = (uint8_t)(offset >> 24);
|
pBlockCol->offsetH = (uint8_t)(offset >> 24);
|
||||||
|
#else
|
||||||
|
pBlockCol->offset = offset;
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
static FORCE_INLINE uint32_t tsdbGetBlockColOffset(SBlockCol *pBlockCol) {
|
static FORCE_INLINE uint32_t tsdbGetBlockColOffset(SBlockCol *pBlockCol) {
|
||||||
|
#ifdef TD_REFACTOR_3
|
||||||
uint32_t offset1 = pBlockCol->offset;
|
uint32_t offset1 = pBlockCol->offset;
|
||||||
uint32_t offset2 = pBlockCol->offsetH;
|
uint32_t offset2 = pBlockCol->offsetH;
|
||||||
return (offset1 | (offset2 << 24));
|
return (offset1 | (offset2 << 24));
|
||||||
|
#else
|
||||||
|
return pBlockCol->offset;
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
|
@ -109,6 +157,8 @@ typedef struct {
|
||||||
SBlockCol cols[];
|
SBlockCol cols[];
|
||||||
} SBlockData;
|
} SBlockData;
|
||||||
|
|
||||||
|
typedef void SAggrBlkData; // SBlockCol cols[];
|
||||||
|
|
||||||
struct SReadH {
|
struct SReadH {
|
||||||
STsdb * pRepo;
|
STsdb * pRepo;
|
||||||
SDFileSet rSet; // FSET to read
|
SDFileSet rSet; // FSET to read
|
||||||
|
@ -118,9 +168,11 @@ struct SReadH {
|
||||||
int cidx;
|
int cidx;
|
||||||
SBlockInfo * pBlkInfo;
|
SBlockInfo * pBlkInfo;
|
||||||
SBlockData * pBlkData; // Block info
|
SBlockData * pBlkData; // Block info
|
||||||
|
SAggrBlkData *pAggrBlkData; // Aggregate Block info
|
||||||
SDataCols * pDCols[2];
|
SDataCols * pDCols[2];
|
||||||
void * pBuf; // buffer
|
void * pBuf; // buffer
|
||||||
void * pCBuf; // compression buffer
|
void * pCBuf; // compression buffer
|
||||||
|
void * pExBuf; // extra buffer
|
||||||
};
|
};
|
||||||
|
|
||||||
#define TSDB_READ_REPO(rh) ((rh)->pRepo)
|
#define TSDB_READ_REPO(rh) ((rh)->pRepo)
|
||||||
|
@ -130,10 +182,32 @@ struct SReadH {
|
||||||
#define TSDB_READ_HEAD_FILE(rh) TSDB_DFILE_IN_SET(TSDB_READ_FSET(rh), TSDB_FILE_HEAD)
|
#define TSDB_READ_HEAD_FILE(rh) TSDB_DFILE_IN_SET(TSDB_READ_FSET(rh), TSDB_FILE_HEAD)
|
||||||
#define TSDB_READ_DATA_FILE(rh) TSDB_DFILE_IN_SET(TSDB_READ_FSET(rh), TSDB_FILE_DATA)
|
#define TSDB_READ_DATA_FILE(rh) TSDB_DFILE_IN_SET(TSDB_READ_FSET(rh), TSDB_FILE_DATA)
|
||||||
#define TSDB_READ_LAST_FILE(rh) TSDB_DFILE_IN_SET(TSDB_READ_FSET(rh), TSDB_FILE_LAST)
|
#define TSDB_READ_LAST_FILE(rh) TSDB_DFILE_IN_SET(TSDB_READ_FSET(rh), TSDB_FILE_LAST)
|
||||||
|
#define TSDB_READ_SMAD_FILE(rh) TSDB_DFILE_IN_SET(TSDB_READ_FSET(rh), TSDB_FILE_SMAD)
|
||||||
|
#define TSDB_READ_SMAL_FILE(rh) TSDB_DFILE_IN_SET(TSDB_READ_FSET(rh), TSDB_FILE_SMAL)
|
||||||
#define TSDB_READ_BUF(rh) ((rh)->pBuf)
|
#define TSDB_READ_BUF(rh) ((rh)->pBuf)
|
||||||
#define TSDB_READ_COMP_BUF(rh) ((rh)->pCBuf)
|
#define TSDB_READ_COMP_BUF(rh) ((rh)->pCBuf)
|
||||||
|
#define TSDB_READ_EXBUF(rh) ((rh)->pExBuf)
|
||||||
|
|
||||||
#define TSDB_BLOCK_STATIS_SIZE(ncols) (sizeof(SBlockData) + sizeof(SBlockCol) * (ncols) + sizeof(TSCKSUM))
|
#define TSDB_BLOCK_STATIS_SIZE(ncols, blkVer) \
|
||||||
|
(sizeof(SBlockData) + sizeof(SBlockColV##blkVer) * (ncols) + sizeof(TSCKSUM))
|
||||||
|
|
||||||
|
static FORCE_INLINE size_t tsdbBlockStatisSize(int nCols, uint32_t blkVer) {
|
||||||
|
switch (blkVer) {
|
||||||
|
case TSDB_SBLK_VER_0:
|
||||||
|
default:
|
||||||
|
return TSDB_BLOCK_STATIS_SIZE(nCols, 0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#define TSDB_BLOCK_AGGR_SIZE(ncols, blkVer) (sizeof(SAggrBlkColV##blkVer) * (ncols) + sizeof(TSCKSUM))
|
||||||
|
|
||||||
|
static FORCE_INLINE size_t tsdbBlockAggrSize(int nCols, uint32_t blkVer) {
|
||||||
|
switch (blkVer) {
|
||||||
|
case TSDB_SBLK_VER_0:
|
||||||
|
default:
|
||||||
|
return TSDB_BLOCK_AGGR_SIZE(nCols, 0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
int tsdbInitReadH(SReadH *pReadh, STsdb *pRepo);
|
int tsdbInitReadH(SReadH *pReadh, STsdb *pRepo);
|
||||||
void tsdbDestroyReadH(SReadH *pReadh);
|
void tsdbDestroyReadH(SReadH *pReadh);
|
||||||
|
@ -147,7 +221,7 @@ int tsdbLoadBlockDataCols(SReadH *pReadh, SBlock *pBlock, SBlockInfo *pBlkInfo
|
||||||
int tsdbLoadBlockStatis(SReadH *pReadh, SBlock *pBlock);
|
int tsdbLoadBlockStatis(SReadH *pReadh, SBlock *pBlock);
|
||||||
int tsdbEncodeSBlockIdx(void **buf, SBlockIdx *pIdx);
|
int tsdbEncodeSBlockIdx(void **buf, SBlockIdx *pIdx);
|
||||||
void *tsdbDecodeSBlockIdx(void *buf, SBlockIdx *pIdx);
|
void *tsdbDecodeSBlockIdx(void *buf, SBlockIdx *pIdx);
|
||||||
void tsdbGetBlockStatis(SReadH *pReadh, SDataStatis *pStatis, int numOfCols);
|
void tsdbGetBlockStatis(SReadH *pReadh, SDataStatis *pStatis, int numOfCols, SBlock *pBlock);
|
||||||
|
|
||||||
static FORCE_INLINE int tsdbMakeRoom(void **ppBuf, size_t size) {
|
static FORCE_INLINE int tsdbMakeRoom(void **ppBuf, size_t size) {
|
||||||
void * pBuf = *ppBuf;
|
void * pBuf = *ppBuf;
|
||||||
|
|
|
@ -88,43 +88,40 @@ int vnodeScheduleTask(SVnodeTask* task);
|
||||||
int32_t vnodePutReqToVQueryQ(SVnode* pVnode, struct SRpcMsg* pReq);
|
int32_t vnodePutReqToVQueryQ(SVnode* pVnode, struct SRpcMsg* pReq);
|
||||||
void vnodeSendReqToDnode(SVnode* pVnode, struct SEpSet* epSet, struct SRpcMsg* pReq);
|
void vnodeSendReqToDnode(SVnode* pVnode, struct SEpSet* epSet, struct SRpcMsg* pReq);
|
||||||
|
|
||||||
// For Log
|
|
||||||
extern int32_t vDebugFlag;
|
|
||||||
|
|
||||||
#define vFatal(...) \
|
#define vFatal(...) \
|
||||||
do { \
|
do { \
|
||||||
if (vDebugFlag & DEBUG_FATAL) { \
|
if (vDebugFlag & DEBUG_FATAL) { \
|
||||||
taosPrintLog("VND FATAL ", 255, __VA_ARGS__); \
|
taosPrintLog("VND FATAL ", DEBUG_FATAL, 255, __VA_ARGS__); \
|
||||||
} \
|
} \
|
||||||
} while (0)
|
} while (0)
|
||||||
#define vError(...) \
|
#define vError(...) \
|
||||||
do { \
|
do { \
|
||||||
if (vDebugFlag & DEBUG_ERROR) { \
|
if (vDebugFlag & DEBUG_ERROR) { \
|
||||||
taosPrintLog("VND ERROR ", 255, __VA_ARGS__); \
|
taosPrintLog("VND ERROR ", DEBUG_ERROR, 255, __VA_ARGS__); \
|
||||||
} \
|
} \
|
||||||
} while (0)
|
} while (0)
|
||||||
#define vWarn(...) \
|
#define vWarn(...) \
|
||||||
do { \
|
do { \
|
||||||
if (vDebugFlag & DEBUG_WARN) { \
|
if (vDebugFlag & DEBUG_WARN) { \
|
||||||
taosPrintLog("VND WARN ", 255, __VA_ARGS__); \
|
taosPrintLog("VND WARN ", DEBUG_WARN, 255, __VA_ARGS__); \
|
||||||
} \
|
} \
|
||||||
} while (0)
|
} while (0)
|
||||||
#define vInfo(...) \
|
#define vInfo(...) \
|
||||||
do { \
|
do { \
|
||||||
if (vDebugFlag & DEBUG_INFO) { \
|
if (vDebugFlag & DEBUG_INFO) { \
|
||||||
taosPrintLog("VND ", 255, __VA_ARGS__); \
|
taosPrintLog("VND ", DEBUG_INFO, 255, __VA_ARGS__); \
|
||||||
} \
|
} \
|
||||||
} while (0)
|
} while (0)
|
||||||
#define vDebug(...) \
|
#define vDebug(...) \
|
||||||
do { \
|
do { \
|
||||||
if (vDebugFlag & DEBUG_DEBUG) { \
|
if (vDebugFlag & DEBUG_DEBUG) { \
|
||||||
taosPrintLog("VND ", tsdbDebugFlag, __VA_ARGS__); \
|
taosPrintLog("VND ", DEBUG_DEBUG, tsdbDebugFlag, __VA_ARGS__); \
|
||||||
} \
|
} \
|
||||||
} while (0)
|
} while (0)
|
||||||
#define vTrace(...) \
|
#define vTrace(...) \
|
||||||
do { \
|
do { \
|
||||||
if (vDebugFlag & DEBUG_TRACE) { \
|
if (vDebugFlag & DEBUG_TRACE) { \
|
||||||
taosPrintLog("VND ", tsdbDebugFlag, __VA_ARGS__); \
|
taosPrintLog("VND ", DEBUG_TRACE, tsdbDebugFlag, __VA_ARGS__); \
|
||||||
} \
|
} \
|
||||||
} while (0)
|
} while (0)
|
||||||
|
|
||||||
|
|
|
@ -90,7 +90,7 @@ STqMetaStore* tqStoreOpen(STQ* pTq, const char* path, FTqSerialize serializer, F
|
||||||
char name[pathLen + 10];
|
char name[pathLen + 10];
|
||||||
|
|
||||||
strcpy(name, path);
|
strcpy(name, path);
|
||||||
if (taosDirExist(name) != 0 && taosMkDir(name) != 0) {
|
if (!taosDirExist(name) && taosMkDir(name) != 0) {
|
||||||
terrno = TSDB_CODE_TQ_FAILED_TO_CREATE_DIR;
|
terrno = TSDB_CODE_TQ_FAILED_TO_CREATE_DIR;
|
||||||
tqError("failed to create dir:%s since %s ", name, terrstr());
|
tqError("failed to create dir:%s since %s ", name, terrstr());
|
||||||
}
|
}
|
||||||
|
|
|
@ -50,8 +50,11 @@ typedef struct {
|
||||||
#define TSDB_COMMIT_HEAD_FILE(ch) TSDB_DFILE_IN_SET(TSDB_COMMIT_WRITE_FSET(ch), TSDB_FILE_HEAD)
|
#define TSDB_COMMIT_HEAD_FILE(ch) TSDB_DFILE_IN_SET(TSDB_COMMIT_WRITE_FSET(ch), TSDB_FILE_HEAD)
|
||||||
#define TSDB_COMMIT_DATA_FILE(ch) TSDB_DFILE_IN_SET(TSDB_COMMIT_WRITE_FSET(ch), TSDB_FILE_DATA)
|
#define TSDB_COMMIT_DATA_FILE(ch) TSDB_DFILE_IN_SET(TSDB_COMMIT_WRITE_FSET(ch), TSDB_FILE_DATA)
|
||||||
#define TSDB_COMMIT_LAST_FILE(ch) TSDB_DFILE_IN_SET(TSDB_COMMIT_WRITE_FSET(ch), TSDB_FILE_LAST)
|
#define TSDB_COMMIT_LAST_FILE(ch) TSDB_DFILE_IN_SET(TSDB_COMMIT_WRITE_FSET(ch), TSDB_FILE_LAST)
|
||||||
|
#define TSDB_COMMIT_SMAD_FILE(ch) TSDB_DFILE_IN_SET(TSDB_COMMIT_WRITE_FSET(ch), TSDB_FILE_SMAD)
|
||||||
|
#define TSDB_COMMIT_SMAL_FILE(ch) TSDB_DFILE_IN_SET(TSDB_COMMIT_WRITE_FSET(ch), TSDB_FILE_SMAL)
|
||||||
#define TSDB_COMMIT_BUF(ch) TSDB_READ_BUF(&((ch)->readh))
|
#define TSDB_COMMIT_BUF(ch) TSDB_READ_BUF(&((ch)->readh))
|
||||||
#define TSDB_COMMIT_COMP_BUF(ch) TSDB_READ_COMP_BUF(&((ch)->readh))
|
#define TSDB_COMMIT_COMP_BUF(ch) TSDB_READ_COMP_BUF(&((ch)->readh))
|
||||||
|
#define TSDB_COMMIT_EXBUF(ch) TSDB_READ_EXBUF(&((ch)->readh))
|
||||||
#define TSDB_COMMIT_DEFAULT_ROWS(ch) TSDB_DEFAULT_BLOCK_ROWS(TSDB_COMMIT_REPO(ch)->config.maxRowsPerFileBlock)
|
#define TSDB_COMMIT_DEFAULT_ROWS(ch) TSDB_DEFAULT_BLOCK_ROWS(TSDB_COMMIT_REPO(ch)->config.maxRowsPerFileBlock)
|
||||||
#define TSDB_COMMIT_TXN_VERSION(ch) FS_TXN_VERSION(REPO_FS(TSDB_COMMIT_REPO(ch)))
|
#define TSDB_COMMIT_TXN_VERSION(ch) FS_TXN_VERSION(REPO_FS(TSDB_COMMIT_REPO(ch)))
|
||||||
|
|
||||||
|
@ -509,7 +512,7 @@ static int tsdbSetAndOpenCommitFile(SCommitH *pCommith, SDFileSet *pSet, int fid
|
||||||
// TSDB_FILE_HEAD
|
// TSDB_FILE_HEAD
|
||||||
SDFile *pWHeadf = TSDB_COMMIT_HEAD_FILE(pCommith);
|
SDFile *pWHeadf = TSDB_COMMIT_HEAD_FILE(pCommith);
|
||||||
tsdbInitDFile(pRepo, pWHeadf, did, fid, FS_TXN_VERSION(REPO_FS(pRepo)), TSDB_FILE_HEAD);
|
tsdbInitDFile(pRepo, pWHeadf, did, fid, FS_TXN_VERSION(REPO_FS(pRepo)), TSDB_FILE_HEAD);
|
||||||
if (tsdbCreateDFile(pRepo, pWHeadf, true) < 0) {
|
if (tsdbCreateDFile(pRepo, pWHeadf, true, TSDB_FILE_HEAD) < 0) {
|
||||||
tsdbError("vgId:%d failed to create file %s to commit since %s", REPO_ID(pRepo), TSDB_FILE_FULL_NAME(pWHeadf),
|
tsdbError("vgId:%d failed to create file %s to commit since %s", REPO_ID(pRepo), TSDB_FILE_FULL_NAME(pWHeadf),
|
||||||
tstrerror(terrno));
|
tstrerror(terrno));
|
||||||
|
|
||||||
|
@ -560,7 +563,7 @@ static int tsdbSetAndOpenCommitFile(SCommitH *pCommith, SDFileSet *pSet, int fid
|
||||||
tsdbInitDFile(pRepo, pWLastf, did, fid, FS_TXN_VERSION(REPO_FS(pRepo)), TSDB_FILE_LAST);
|
tsdbInitDFile(pRepo, pWLastf, did, fid, FS_TXN_VERSION(REPO_FS(pRepo)), TSDB_FILE_LAST);
|
||||||
pCommith->isLFileSame = false;
|
pCommith->isLFileSame = false;
|
||||||
|
|
||||||
if (tsdbCreateDFile(pRepo, pWLastf, true) < 0) {
|
if (tsdbCreateDFile(pRepo, pWLastf, true, TSDB_FILE_LAST) < 0) {
|
||||||
tsdbError("vgId:%d failed to create file %s to commit since %s", REPO_ID(pRepo), TSDB_FILE_FULL_NAME(pWLastf),
|
tsdbError("vgId:%d failed to create file %s to commit since %s", REPO_ID(pRepo), TSDB_FILE_FULL_NAME(pWLastf),
|
||||||
tstrerror(terrno));
|
tstrerror(terrno));
|
||||||
|
|
||||||
|
@ -572,6 +575,74 @@ static int tsdbSetAndOpenCommitFile(SCommitH *pCommith, SDFileSet *pSet, int fid
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TSDB_FILE_SMAD
|
||||||
|
SDFile *pRSmadF = TSDB_READ_SMAD_FILE(&(pCommith->readh));
|
||||||
|
SDFile *pWSmadF = TSDB_COMMIT_SMAD_FILE(pCommith);
|
||||||
|
|
||||||
|
if (!taosCheckExistFile(TSDB_FILE_FULL_NAME(pRSmadF))) {
|
||||||
|
tsdbDebug("vgId:%d create data file %s as not exist", REPO_ID(pRepo), TSDB_FILE_FULL_NAME(pRSmadF));
|
||||||
|
tsdbInitDFile(pRepo, pWSmadF, did, fid, FS_TXN_VERSION(REPO_FS(pRepo)), TSDB_FILE_SMAD);
|
||||||
|
|
||||||
|
if (tsdbCreateDFile(pRepo, pWSmadF, true, TSDB_FILE_SMAD) < 0) {
|
||||||
|
tsdbError("vgId:%d failed to create file %s to commit since %s", REPO_ID(pRepo), TSDB_FILE_FULL_NAME(pWSmadF),
|
||||||
|
tstrerror(terrno));
|
||||||
|
|
||||||
|
tsdbCloseDFileSet(pWSet);
|
||||||
|
(void)tsdbRemoveDFile(pWHeadf);
|
||||||
|
if (pCommith->isRFileSet) {
|
||||||
|
tsdbCloseAndUnsetFSet(&(pCommith->readh));
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
tsdbInitDFileEx(pWSmadF, pRSmadF);
|
||||||
|
if (tsdbOpenDFile(pWSmadF, O_RDWR) < 0) {
|
||||||
|
tsdbError("vgId:%d failed to open file %s to commit since %s", REPO_ID(pRepo), TSDB_FILE_FULL_NAME(pWSmadF),
|
||||||
|
tstrerror(terrno));
|
||||||
|
|
||||||
|
tsdbCloseDFileSet(pWSet);
|
||||||
|
tsdbRemoveDFile(pWHeadf);
|
||||||
|
if (pCommith->isRFileSet) {
|
||||||
|
tsdbCloseAndUnsetFSet(&(pCommith->readh));
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// TSDB_FILE_SMAL
|
||||||
|
SDFile *pRSmalF = TSDB_READ_SMAL_FILE(&(pCommith->readh));
|
||||||
|
SDFile *pWSmalF = TSDB_COMMIT_SMAL_FILE(pCommith);
|
||||||
|
|
||||||
|
if ((pCommith->isLFileSame) && taosCheckExistFile(TSDB_FILE_FULL_NAME(pRSmalF))) {
|
||||||
|
tsdbInitDFileEx(pWSmalF, pRSmalF);
|
||||||
|
if (tsdbOpenDFile(pWSmalF, O_RDWR) < 0) {
|
||||||
|
tsdbError("vgId:%d failed to open file %s to commit since %s", REPO_ID(pRepo), TSDB_FILE_FULL_NAME(pWSmalF),
|
||||||
|
tstrerror(terrno));
|
||||||
|
|
||||||
|
tsdbCloseDFileSet(pWSet);
|
||||||
|
tsdbRemoveDFile(pWHeadf);
|
||||||
|
if (pCommith->isRFileSet) {
|
||||||
|
tsdbCloseAndUnsetFSet(&(pCommith->readh));
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
tsdbDebug("vgId:%d create data file %s as not exist", REPO_ID(pRepo), TSDB_FILE_FULL_NAME(pRSmalF));
|
||||||
|
tsdbInitDFile(pRepo, pWSmalF, did, fid, FS_TXN_VERSION(REPO_FS(pRepo)), TSDB_FILE_SMAL);
|
||||||
|
|
||||||
|
if (tsdbCreateDFile(pRepo, pWSmalF, true, TSDB_FILE_SMAL) < 0) {
|
||||||
|
tsdbError("vgId:%d failed to create file %s to commit since %s", REPO_ID(pRepo), TSDB_FILE_FULL_NAME(pWSmalF),
|
||||||
|
tstrerror(terrno));
|
||||||
|
|
||||||
|
tsdbCloseDFileSet(pWSet);
|
||||||
|
(void)tsdbRemoveDFile(pWHeadf);
|
||||||
|
if (pCommith->isRFileSet) {
|
||||||
|
tsdbCloseAndUnsetFSet(&(pCommith->readh));
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -983,7 +1054,7 @@ int tsdbWriteBlockIdx(SDFile *pHeadf, SArray *pIdxA, void **ppBuf) {
|
||||||
// pfs->metaCacheComp = NULL;
|
// pfs->metaCacheComp = NULL;
|
||||||
// } else {
|
// } else {
|
||||||
// // remove meta.tmp file
|
// // remove meta.tmp file
|
||||||
// remove(mf.f.aname);
|
// taosRemoveFile(mf.f.aname);
|
||||||
// taosHashCleanup(pfs->metaCacheComp);
|
// taosHashCleanup(pfs->metaCacheComp);
|
||||||
// pfs->metaCacheComp = NULL;
|
// pfs->metaCacheComp = NULL;
|
||||||
// }
|
// }
|
||||||
|
@ -1131,41 +1202,57 @@ static int tsdbComparKeyBlock(const void *arg1, const void *arg2) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int tsdbWriteBlockImpl(STsdb *pRepo, STable *pTable, SDFile *pDFile, SDataCols *pDataCols, SBlock *pBlock, bool isLast,
|
int tsdbWriteBlockImpl(STsdb *pRepo, STable *pTable, SDFile *pDFile, SDFile *pDFileAggr, SDataCols *pDataCols,
|
||||||
bool isSuper, void **ppBuf, void **ppCBuf) {
|
SBlock *pBlock, bool isLast, bool isSuper, void **ppBuf, void **ppCBuf, void **ppExBuf) {
|
||||||
STsdbCfg * pCfg = REPO_CFG(pRepo);
|
STsdbCfg * pCfg = REPO_CFG(pRepo);
|
||||||
SBlockData *pBlockData;
|
SBlockData * pBlockData = NULL;
|
||||||
int64_t offset = 0;
|
SAggrBlkData *pAggrBlkData = NULL;
|
||||||
|
int64_t offset = 0, offsetAggr = 0;
|
||||||
int rowsToWrite = pDataCols->numOfRows;
|
int rowsToWrite = pDataCols->numOfRows;
|
||||||
|
|
||||||
ASSERT(rowsToWrite > 0 && rowsToWrite <= pCfg->maxRowsPerFileBlock);
|
ASSERT(rowsToWrite > 0 && rowsToWrite <= pCfg->maxRowsPerFileBlock);
|
||||||
ASSERT((!isLast) || rowsToWrite < pCfg->minRowsPerFileBlock);
|
ASSERT((!isLast) || rowsToWrite < pCfg->minRowsPerFileBlock);
|
||||||
|
|
||||||
// Make buffer space
|
// Make buffer space
|
||||||
if (tsdbMakeRoom(ppBuf, TSDB_BLOCK_STATIS_SIZE(pDataCols->numOfCols)) < 0) {
|
if (tsdbMakeRoom(ppBuf, tsdbBlockStatisSize(pDataCols->numOfCols, SBlockVerLatest)) < 0) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
pBlockData = (SBlockData *)(*ppBuf);
|
pBlockData = (SBlockData *)(*ppBuf);
|
||||||
|
|
||||||
|
if (tsdbMakeRoom(ppExBuf, tsdbBlockAggrSize(pDataCols->numOfCols, SBlockVerLatest)) < 0) {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
pAggrBlkData = (SAggrBlkData *)(*ppExBuf);
|
||||||
|
|
||||||
// Get # of cols not all NULL(not including key column)
|
// Get # of cols not all NULL(not including key column)
|
||||||
int nColsNotAllNull = 0;
|
int nColsNotAllNull = 0;
|
||||||
for (int ncol = 1; ncol < pDataCols->numOfCols; ncol++) { // ncol from 1, we skip the timestamp column
|
for (int ncol = 1; ncol < pDataCols->numOfCols; ++ncol) { // ncol from 1, we skip the timestamp column
|
||||||
SDataCol * pDataCol = pDataCols->cols + ncol;
|
SDataCol * pDataCol = pDataCols->cols + ncol;
|
||||||
SBlockCol * pBlockCol = pBlockData->cols + nColsNotAllNull;
|
SBlockCol * pBlockCol = pBlockData->cols + nColsNotAllNull;
|
||||||
|
SAggrBlkCol *pAggrBlkCol = (SAggrBlkCol *)pAggrBlkData + nColsNotAllNull;
|
||||||
|
|
||||||
if (isAllRowsNull(pDataCol)) { // all data to commit are NULL, just ignore it
|
if (isAllRowsNull(pDataCol)) { // all data to commit are NULL, just ignore it
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
memset(pBlockCol, 0, sizeof(*pBlockCol));
|
memset(pBlockCol, 0, sizeof(*pBlockCol));
|
||||||
|
memset(pAggrBlkCol, 0, sizeof(*pAggrBlkCol));
|
||||||
|
|
||||||
pBlockCol->colId = pDataCol->colId;
|
pBlockCol->colId = pDataCol->colId;
|
||||||
pBlockCol->type = pDataCol->type;
|
pBlockCol->type = pDataCol->type;
|
||||||
|
pAggrBlkCol->colId = pDataCol->colId;
|
||||||
|
|
||||||
if (tDataTypes[pDataCol->type].statisFunc) {
|
if (tDataTypes[pDataCol->type].statisFunc) {
|
||||||
|
#if 0
|
||||||
(*tDataTypes[pDataCol->type].statisFunc)(pDataCol->pData, rowsToWrite, &(pBlockCol->min), &(pBlockCol->max),
|
(*tDataTypes[pDataCol->type].statisFunc)(pDataCol->pData, rowsToWrite, &(pBlockCol->min), &(pBlockCol->max),
|
||||||
&(pBlockCol->sum), &(pBlockCol->minIndex), &(pBlockCol->maxIndex),
|
&(pBlockCol->sum), &(pBlockCol->minIndex), &(pBlockCol->maxIndex),
|
||||||
&(pBlockCol->numOfNull));
|
&(pBlockCol->numOfNull));
|
||||||
if (pBlockCol->numOfNull == 0) {
|
#endif
|
||||||
|
(*tDataTypes[pDataCol->type].statisFunc)(pDataCol->pData, rowsToWrite, &(pAggrBlkCol->min), &(pAggrBlkCol->max),
|
||||||
|
&(pAggrBlkCol->sum), &(pAggrBlkCol->minIndex), &(pAggrBlkCol->maxIndex),
|
||||||
|
&(pAggrBlkCol->numOfNull));
|
||||||
|
|
||||||
|
if (pAggrBlkCol->numOfNull == 0) {
|
||||||
TD_SET_COL_ROWS_NORM(pBlockCol);
|
TD_SET_COL_ROWS_NORM(pBlockCol);
|
||||||
} else {
|
} else {
|
||||||
TD_SET_COL_ROWS_MISC(pBlockCol);
|
TD_SET_COL_ROWS_MISC(pBlockCol);
|
||||||
|
@ -1181,13 +1268,14 @@ int tsdbWriteBlockImpl(STsdb *pRepo, STable *pTable, SDFile *pDFile, SDataCols *
|
||||||
// Compress the data if neccessary
|
// Compress the data if neccessary
|
||||||
int tcol = 0; // counter of not all NULL and written columns
|
int tcol = 0; // counter of not all NULL and written columns
|
||||||
uint32_t toffset = 0;
|
uint32_t toffset = 0;
|
||||||
int32_t tsize = TSDB_BLOCK_STATIS_SIZE(nColsNotAllNull);
|
int32_t tsize = (int32_t)tsdbBlockStatisSize(nColsNotAllNull, SBlockVerLatest);
|
||||||
int32_t lsize = tsize;
|
int32_t lsize = tsize;
|
||||||
|
uint32_t tsizeAggr = (uint32_t)tsdbBlockAggrSize(nColsNotAllNull, SBlockVerLatest);
|
||||||
int32_t keyLen = 0;
|
int32_t keyLen = 0;
|
||||||
int32_t nBitmaps = (int32_t)TD_BITMAP_BYTES(rowsToWrite);
|
int32_t nBitmaps = (int32_t)TD_BITMAP_BYTES(rowsToWrite);
|
||||||
int32_t tBitmaps = 0;
|
int32_t tBitmaps = 0;
|
||||||
|
|
||||||
for (int ncol = 0; ncol < pDataCols->numOfCols; ncol++) {
|
for (int ncol = 0; ncol < pDataCols->numOfCols; ++ncol) {
|
||||||
// All not NULL columns finish
|
// All not NULL columns finish
|
||||||
if (ncol != 0 && tcol >= nColsNotAllNull) break;
|
if (ncol != 0 && tcol >= nColsNotAllNull) break;
|
||||||
|
|
||||||
|
@ -1248,7 +1336,7 @@ int tsdbWriteBlockImpl(STsdb *pRepo, STable *pTable, SDFile *pDFile, SDataCols *
|
||||||
if (ncol != 0) {
|
if (ncol != 0) {
|
||||||
tsdbSetBlockColOffset(pBlockCol, toffset);
|
tsdbSetBlockColOffset(pBlockCol, toffset);
|
||||||
pBlockCol->len = flen;
|
pBlockCol->len = flen;
|
||||||
tcol++;
|
++tcol;
|
||||||
} else {
|
} else {
|
||||||
keyLen = flen;
|
keyLen = flen;
|
||||||
}
|
}
|
||||||
|
@ -1269,6 +1357,18 @@ int tsdbWriteBlockImpl(STsdb *pRepo, STable *pTable, SDFile *pDFile, SDataCols *
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
uint32_t aggrStatus = nColsNotAllNull > 0 ? 1 : 0;
|
||||||
|
if (aggrStatus > 0) {
|
||||||
|
|
||||||
|
taosCalcChecksumAppend(0, (uint8_t *)pAggrBlkData, tsizeAggr);
|
||||||
|
tsdbUpdateDFileMagic(pDFileAggr, POINTER_SHIFT(pAggrBlkData, tsizeAggr - sizeof(TSCKSUM)));
|
||||||
|
|
||||||
|
// Write the whole block to file
|
||||||
|
if (tsdbAppendDFile(pDFileAggr, (void *)pAggrBlkData, tsizeAggr, &offsetAggr) < tsizeAggr) {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Update pBlock membership vairables
|
// Update pBlock membership vairables
|
||||||
pBlock->last = isLast;
|
pBlock->last = isLast;
|
||||||
pBlock->offset = offset;
|
pBlock->offset = offset;
|
||||||
|
@ -1280,6 +1380,9 @@ int tsdbWriteBlockImpl(STsdb *pRepo, STable *pTable, SDFile *pDFile, SDataCols *
|
||||||
pBlock->numOfCols = nColsNotAllNull;
|
pBlock->numOfCols = nColsNotAllNull;
|
||||||
pBlock->keyFirst = dataColsKeyFirst(pDataCols);
|
pBlock->keyFirst = dataColsKeyFirst(pDataCols);
|
||||||
pBlock->keyLast = dataColsKeyLast(pDataCols);
|
pBlock->keyLast = dataColsKeyLast(pDataCols);
|
||||||
|
pBlock->aggrStat = aggrStatus;
|
||||||
|
pBlock->blkVer = SBlockVerLatest;
|
||||||
|
pBlock->aggrOffset = (uint64_t)offsetAggr;
|
||||||
|
|
||||||
tsdbDebug("vgId:%d uid:%" PRId64 " a block of data is written to file %s, offset %" PRId64
|
tsdbDebug("vgId:%d uid:%" PRId64 " a block of data is written to file %s, offset %" PRId64
|
||||||
" numOfRows %d len %d numOfCols %" PRId16 " keyFirst %" PRId64 " keyLast %" PRId64,
|
" numOfRows %d len %d numOfCols %" PRId16 " keyFirst %" PRId64 " keyLast %" PRId64,
|
||||||
|
@ -1291,9 +1394,10 @@ int tsdbWriteBlockImpl(STsdb *pRepo, STable *pTable, SDFile *pDFile, SDataCols *
|
||||||
|
|
||||||
static int tsdbWriteBlock(SCommitH *pCommith, SDFile *pDFile, SDataCols *pDataCols, SBlock *pBlock, bool isLast,
|
static int tsdbWriteBlock(SCommitH *pCommith, SDFile *pDFile, SDataCols *pDataCols, SBlock *pBlock, bool isLast,
|
||||||
bool isSuper) {
|
bool isSuper) {
|
||||||
return tsdbWriteBlockImpl(TSDB_COMMIT_REPO(pCommith), TSDB_COMMIT_TABLE(pCommith), pDFile, pDataCols, pBlock, isLast,
|
return tsdbWriteBlockImpl(TSDB_COMMIT_REPO(pCommith), TSDB_COMMIT_TABLE(pCommith), pDFile,
|
||||||
isSuper, (void **)(&(TSDB_COMMIT_BUF(pCommith))),
|
isLast ? TSDB_COMMIT_SMAL_FILE(pCommith) : TSDB_COMMIT_SMAD_FILE(pCommith), pDataCols,
|
||||||
(void **)(&(TSDB_COMMIT_COMP_BUF(pCommith))));
|
pBlock, isLast, isSuper, (void **)(&(TSDB_COMMIT_BUF(pCommith))),
|
||||||
|
(void **)(&(TSDB_COMMIT_COMP_BUF(pCommith))), (void **)(&(TSDB_COMMIT_EXBUF(pCommith))));
|
||||||
}
|
}
|
||||||
|
|
||||||
static int tsdbWriteBlockInfo(SCommitH *pCommih) {
|
static int tsdbWriteBlockInfo(SCommitH *pCommih) {
|
||||||
|
|
|
@ -38,6 +38,8 @@ typedef struct {
|
||||||
#define TSDB_COMPACT_HEAD_FILE(pComph) TSDB_DFILE_IN_SET(TSDB_COMPACT_WSET(pComph), TSDB_FILE_HEAD)
|
#define TSDB_COMPACT_HEAD_FILE(pComph) TSDB_DFILE_IN_SET(TSDB_COMPACT_WSET(pComph), TSDB_FILE_HEAD)
|
||||||
#define TSDB_COMPACT_DATA_FILE(pComph) TSDB_DFILE_IN_SET(TSDB_COMPACT_WSET(pComph), TSDB_FILE_DATA)
|
#define TSDB_COMPACT_DATA_FILE(pComph) TSDB_DFILE_IN_SET(TSDB_COMPACT_WSET(pComph), TSDB_FILE_DATA)
|
||||||
#define TSDB_COMPACT_LAST_FILE(pComph) TSDB_DFILE_IN_SET(TSDB_COMPACT_WSET(pComph), TSDB_FILE_LAST)
|
#define TSDB_COMPACT_LAST_FILE(pComph) TSDB_DFILE_IN_SET(TSDB_COMPACT_WSET(pComph), TSDB_FILE_LAST)
|
||||||
|
#define TSDB_COMPACT_SMAD_FILE(pComph) TSDB_DFILE_IN_SET(TSDB_COMPACT_WSET(pComph), TSDB_FILE_SMAD)
|
||||||
|
#define TSDB_COMPACT_SMAL_FILE(pComph) TSDB_DFILE_IN_SET(TSDB_COMPACT_WSET(pComph), TSDB_FILE_SMAL)
|
||||||
#define TSDB_COMPACT_BUF(pComph) TSDB_READ_BUF(&((pComph)->readh))
|
#define TSDB_COMPACT_BUF(pComph) TSDB_READ_BUF(&((pComph)->readh))
|
||||||
#define TSDB_COMPACT_COMP_BUF(pComph) TSDB_READ_COMP_BUF(&((pComph)->readh))
|
#define TSDB_COMPACT_COMP_BUF(pComph) TSDB_READ_COMP_BUF(&((pComph)->readh))
|
||||||
|
|
||||||
|
|
|
@ -314,7 +314,7 @@ int tsdbOpenFS(STsdb *pRepo) {
|
||||||
tsdbGetTxnFname(pRepo, TSDB_TXN_CURR_FILE, current);
|
tsdbGetTxnFname(pRepo, TSDB_TXN_CURR_FILE, current);
|
||||||
|
|
||||||
tsdbGetRtnSnap(pRepo, &pRepo->rtn);
|
tsdbGetRtnSnap(pRepo, &pRepo->rtn);
|
||||||
if (access(current, F_OK) == 0) {
|
if (taosCheckExistFile(current)) {
|
||||||
if (tsdbOpenFSFromCurrent(pRepo) < 0) {
|
if (tsdbOpenFSFromCurrent(pRepo) < 0) {
|
||||||
tsdbError("vgId:%d failed to open FS since %s", REPO_ID(pRepo), tstrerror(terrno));
|
tsdbError("vgId:%d failed to open FS since %s", REPO_ID(pRepo), tstrerror(terrno));
|
||||||
return -1;
|
return -1;
|
||||||
|
@ -422,7 +422,7 @@ static int tsdbSaveFSStatus(STsdb *pRepo, SFSStatus *pStatus) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
fsheader.version = TSDB_FS_VERSION;
|
fsheader.version = TSDB_LATEST_SFS_VER;
|
||||||
if (taosArrayGetSize(pStatus->df) == 0) {
|
if (taosArrayGetSize(pStatus->df) == 0) {
|
||||||
fsheader.len = 0;
|
fsheader.len = 0;
|
||||||
} else {
|
} else {
|
||||||
|
@ -439,7 +439,7 @@ static int tsdbSaveFSStatus(STsdb *pRepo, SFSStatus *pStatus) {
|
||||||
if (taosWriteFile(pFile, hbuf, TSDB_FILE_HEAD_SIZE) < TSDB_FILE_HEAD_SIZE) {
|
if (taosWriteFile(pFile, hbuf, TSDB_FILE_HEAD_SIZE) < TSDB_FILE_HEAD_SIZE) {
|
||||||
terrno = TAOS_SYSTEM_ERROR(errno);
|
terrno = TAOS_SYSTEM_ERROR(errno);
|
||||||
taosCloseFile(&pFile);
|
taosCloseFile(&pFile);
|
||||||
remove(tfname);
|
taosRemoveFile(tfname);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -447,7 +447,7 @@ static int tsdbSaveFSStatus(STsdb *pRepo, SFSStatus *pStatus) {
|
||||||
if (fsheader.len > 0) {
|
if (fsheader.len > 0) {
|
||||||
if (tsdbMakeRoom(&(pBuf), fsheader.len) < 0) {
|
if (tsdbMakeRoom(&(pBuf), fsheader.len) < 0) {
|
||||||
taosCloseFile(&pFile);
|
taosCloseFile(&pFile);
|
||||||
remove(tfname);
|
taosRemoveFile(tfname);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -458,7 +458,7 @@ static int tsdbSaveFSStatus(STsdb *pRepo, SFSStatus *pStatus) {
|
||||||
if (taosWriteFile(pFile, pBuf, fsheader.len) < fsheader.len) {
|
if (taosWriteFile(pFile, pBuf, fsheader.len) < fsheader.len) {
|
||||||
terrno = TAOS_SYSTEM_ERROR(errno);
|
terrno = TAOS_SYSTEM_ERROR(errno);
|
||||||
taosCloseFile(&pFile);
|
taosCloseFile(&pFile);
|
||||||
(void)remove(tfname);
|
(void)taosRemoveFile(tfname);
|
||||||
taosTZfree(pBuf);
|
taosTZfree(pBuf);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
@ -468,7 +468,7 @@ static int tsdbSaveFSStatus(STsdb *pRepo, SFSStatus *pStatus) {
|
||||||
if (taosFsyncFile(pFile) < 0) {
|
if (taosFsyncFile(pFile) < 0) {
|
||||||
terrno = TAOS_SYSTEM_ERROR(errno);
|
terrno = TAOS_SYSTEM_ERROR(errno);
|
||||||
taosCloseFile(&pFile);
|
taosCloseFile(&pFile);
|
||||||
remove(tfname);
|
taosRemoveFile(tfname);
|
||||||
taosTZfree(pBuf);
|
taosTZfree(pBuf);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
@ -697,7 +697,7 @@ static int tsdbOpenFSFromCurrent(STsdb *pRepo) {
|
||||||
ptr = tsdbDecodeFSHeader(ptr, &fsheader);
|
ptr = tsdbDecodeFSHeader(ptr, &fsheader);
|
||||||
ptr = tsdbDecodeFSMeta(ptr, &(pStatus->meta));
|
ptr = tsdbDecodeFSMeta(ptr, &(pStatus->meta));
|
||||||
|
|
||||||
if (fsheader.version != TSDB_FS_VERSION) {
|
if (fsheader.version != TSDB_LATEST_SFS_VER) {
|
||||||
// TODO: handle file version change
|
// TODO: handle file version change
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -19,8 +19,12 @@ static const char *TSDB_FNAME_SUFFIX[] = {
|
||||||
"head", // TSDB_FILE_HEAD
|
"head", // TSDB_FILE_HEAD
|
||||||
"data", // TSDB_FILE_DATA
|
"data", // TSDB_FILE_DATA
|
||||||
"last", // TSDB_FILE_LAST
|
"last", // TSDB_FILE_LAST
|
||||||
|
"smad", // TSDB_FILE_SMAD
|
||||||
|
"smal", // TSDB_FILE_SMAL
|
||||||
"", // TSDB_FILE_MAX
|
"", // TSDB_FILE_MAX
|
||||||
"meta", // TSDB_FILE_META
|
"meta", // TSDB_FILE_META
|
||||||
|
"tsma", // TSDB_FILE_TSMA
|
||||||
|
"rsma", // TSDB_FILE_RSMA
|
||||||
};
|
};
|
||||||
|
|
||||||
static void tsdbGetFilename(int vid, int fid, uint32_t ver, TSDB_FILE_T ftype, char *fname);
|
static void tsdbGetFilename(int vid, int fid, uint32_t ver, TSDB_FILE_T ftype, char *fname);
|
||||||
|
@ -304,6 +308,7 @@ void tsdbInitDFile(STsdb *pRepo, SDFile *pDFile, SDiskID did, int fid, uint32_t
|
||||||
|
|
||||||
memset(&(pDFile->info), 0, sizeof(pDFile->info));
|
memset(&(pDFile->info), 0, sizeof(pDFile->info));
|
||||||
pDFile->info.magic = TSDB_FILE_INIT_MAGIC;
|
pDFile->info.magic = TSDB_FILE_INIT_MAGIC;
|
||||||
|
pDFile->info.fver = tsdbGetDFSVersion(ftype);
|
||||||
|
|
||||||
tsdbGetFilename(pRepo->vgId, fid, ver, ftype, fname);
|
tsdbGetFilename(pRepo->vgId, fid, ver, ftype, fname);
|
||||||
tfsInitFile(pRepo->pTfs, &(pDFile->f), did, fname);
|
tfsInitFile(pRepo->pTfs, &(pDFile->f), did, fname);
|
||||||
|
@ -341,7 +346,7 @@ static int tsdbEncodeSDFileEx(void **buf, SDFile *pDFile) {
|
||||||
}
|
}
|
||||||
|
|
||||||
static void *tsdbDecodeSDFileEx(void *buf, SDFile *pDFile) {
|
static void *tsdbDecodeSDFileEx(void *buf, SDFile *pDFile) {
|
||||||
char *aname;
|
char *aname = NULL;
|
||||||
|
|
||||||
buf = tsdbDecodeDFInfo(buf, &(pDFile->info));
|
buf = tsdbDecodeDFInfo(buf, &(pDFile->info));
|
||||||
buf = taosDecodeString(buf, &aname);
|
buf = taosDecodeString(buf, &aname);
|
||||||
|
@ -352,7 +357,7 @@ static void *tsdbDecodeSDFileEx(void *buf, SDFile *pDFile) {
|
||||||
return buf;
|
return buf;
|
||||||
}
|
}
|
||||||
|
|
||||||
int tsdbCreateDFile(STsdb *pRepo, SDFile *pDFile, bool updateHeader) {
|
int tsdbCreateDFile(STsdb *pRepo, SDFile *pDFile, bool updateHeader, TSDB_FILE_T fType) {
|
||||||
ASSERT(pDFile->info.size == 0 && pDFile->info.magic == TSDB_FILE_INIT_MAGIC);
|
ASSERT(pDFile->info.size == 0 && pDFile->info.magic == TSDB_FILE_INIT_MAGIC);
|
||||||
|
|
||||||
pDFile->pFile = taosOpenFile(TSDB_FILE_FULL_NAME(pDFile), TD_FILE_CTEATE | TD_FILE_WRITE | TD_FILE_TRUNC);
|
pDFile->pFile = taosOpenFile(TSDB_FILE_FULL_NAME(pDFile), TD_FILE_CTEATE | TD_FILE_WRITE | TD_FILE_TRUNC);
|
||||||
|
@ -382,6 +387,7 @@ int tsdbCreateDFile(STsdb *pRepo, SDFile *pDFile, bool updateHeader) {
|
||||||
}
|
}
|
||||||
|
|
||||||
pDFile->info.size += TSDB_FILE_HEAD_SIZE;
|
pDFile->info.size += TSDB_FILE_HEAD_SIZE;
|
||||||
|
pDFile->info.fver = tsdbGetDFSVersion(fType);
|
||||||
|
|
||||||
if (tsdbUpdateDFileHeader(pDFile) < 0) {
|
if (tsdbUpdateDFileHeader(pDFile) < 0) {
|
||||||
tsdbCloseDFile(pDFile);
|
tsdbCloseDFile(pDFile);
|
||||||
|
@ -437,25 +443,24 @@ int tsdbLoadDFileHeader(SDFile *pDFile, SDFInfo *pInfo) {
|
||||||
}
|
}
|
||||||
|
|
||||||
static int tsdbScanAndTryFixDFile(STsdb *pRepo, SDFile *pDFile) {
|
static int tsdbScanAndTryFixDFile(STsdb *pRepo, SDFile *pDFile) {
|
||||||
struct stat dfstat;
|
|
||||||
SDFile df;
|
SDFile df;
|
||||||
|
|
||||||
tsdbInitDFileEx(&df, pDFile);
|
tsdbInitDFileEx(&df, pDFile);
|
||||||
|
|
||||||
if (access(TSDB_FILE_FULL_NAME(pDFile), F_OK) != 0) {
|
if (!taosCheckExistFile(TSDB_FILE_FULL_NAME(pDFile))) {
|
||||||
tsdbError("vgId:%d data file %s not exit, report to upper layer to fix it", REPO_ID(pRepo),
|
tsdbError("vgId:%d data file %s not exit, report to upper layer to fix it", REPO_ID(pRepo),
|
||||||
TSDB_FILE_FULL_NAME(pDFile));
|
TSDB_FILE_FULL_NAME(pDFile));
|
||||||
// pRepo->state |= TSDB_STATE_BAD_DATA;
|
// pRepo->state |= TSDB_STATE_BAD_DATA;
|
||||||
TSDB_FILE_SET_STATE(pDFile, TSDB_FILE_STATE_BAD);
|
TSDB_FILE_SET_STATE(pDFile, TSDB_FILE_STATE_BAD);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
int64_t file_size = 0;
|
||||||
if (stat(TSDB_FILE_FULL_NAME(&df), &dfstat) < 0) {
|
if (taosStatFile(TSDB_FILE_FULL_NAME(&df), &file_size, NULL) < 0) {
|
||||||
terrno = TAOS_SYSTEM_ERROR(errno);
|
terrno = TAOS_SYSTEM_ERROR(errno);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (pDFile->info.size < dfstat.st_size) {
|
if (pDFile->info.size < file_size) {
|
||||||
// if (tsdbOpenDFile(&df, O_WRONLY) < 0) {
|
// if (tsdbOpenDFile(&df, O_WRONLY) < 0) {
|
||||||
if (tsdbOpenDFile(&df, TD_FILE_WRITE) < 0) {
|
if (tsdbOpenDFile(&df, TD_FILE_WRITE) < 0) {
|
||||||
return -1;
|
return -1;
|
||||||
|
@ -474,10 +479,10 @@ static int tsdbScanAndTryFixDFile(STsdb *pRepo, SDFile *pDFile) {
|
||||||
|
|
||||||
tsdbCloseDFile(&df);
|
tsdbCloseDFile(&df);
|
||||||
tsdbInfo("vgId:%d file %s is truncated from %" PRId64 " to %" PRId64, REPO_ID(pRepo), TSDB_FILE_FULL_NAME(pDFile),
|
tsdbInfo("vgId:%d file %s is truncated from %" PRId64 " to %" PRId64, REPO_ID(pRepo), TSDB_FILE_FULL_NAME(pDFile),
|
||||||
dfstat.st_size, pDFile->info.size);
|
file_size, pDFile->info.size);
|
||||||
} else if (pDFile->info.size > dfstat.st_size) {
|
} else if (pDFile->info.size > file_size) {
|
||||||
tsdbError("vgId:%d data file %s has wrong size %" PRId64 " expected %" PRId64 ", report to upper layer to fix it",
|
tsdbError("vgId:%d data file %s has wrong size %" PRId64 " expected %" PRId64 ", report to upper layer to fix it",
|
||||||
REPO_ID(pRepo), TSDB_FILE_FULL_NAME(pDFile), dfstat.st_size, pDFile->info.size);
|
REPO_ID(pRepo), TSDB_FILE_FULL_NAME(pDFile), file_size, pDFile->info.size);
|
||||||
// pRepo->state |= TSDB_STATE_BAD_DATA;
|
// pRepo->state |= TSDB_STATE_BAD_DATA;
|
||||||
TSDB_FILE_SET_STATE(pDFile, TSDB_FILE_STATE_BAD);
|
TSDB_FILE_SET_STATE(pDFile, TSDB_FILE_STATE_BAD);
|
||||||
terrno = TSDB_CODE_TDB_FILE_CORRUPTED;
|
terrno = TSDB_CODE_TDB_FILE_CORRUPTED;
|
||||||
|
@ -493,6 +498,7 @@ static int tsdbEncodeDFInfo(void **buf, SDFInfo *pInfo) {
|
||||||
int tlen = 0;
|
int tlen = 0;
|
||||||
|
|
||||||
tlen += taosEncodeFixedU32(buf, pInfo->magic);
|
tlen += taosEncodeFixedU32(buf, pInfo->magic);
|
||||||
|
tlen += taosEncodeFixedU32(buf, pInfo->fver);
|
||||||
tlen += taosEncodeFixedU32(buf, pInfo->len);
|
tlen += taosEncodeFixedU32(buf, pInfo->len);
|
||||||
tlen += taosEncodeFixedU32(buf, pInfo->totalBlocks);
|
tlen += taosEncodeFixedU32(buf, pInfo->totalBlocks);
|
||||||
tlen += taosEncodeFixedU32(buf, pInfo->totalSubBlocks);
|
tlen += taosEncodeFixedU32(buf, pInfo->totalSubBlocks);
|
||||||
|
@ -505,6 +511,7 @@ static int tsdbEncodeDFInfo(void **buf, SDFInfo *pInfo) {
|
||||||
|
|
||||||
static void *tsdbDecodeDFInfo(void *buf, SDFInfo *pInfo) {
|
static void *tsdbDecodeDFInfo(void *buf, SDFInfo *pInfo) {
|
||||||
buf = taosDecodeFixedU32(buf, &(pInfo->magic));
|
buf = taosDecodeFixedU32(buf, &(pInfo->magic));
|
||||||
|
buf = taosDecodeFixedU32(buf, &(pInfo->fver));
|
||||||
buf = taosDecodeFixedU32(buf, &(pInfo->len));
|
buf = taosDecodeFixedU32(buf, &(pInfo->len));
|
||||||
buf = taosDecodeFixedU32(buf, &(pInfo->totalBlocks));
|
buf = taosDecodeFixedU32(buf, &(pInfo->totalBlocks));
|
||||||
buf = taosDecodeFixedU32(buf, &(pInfo->totalSubBlocks));
|
buf = taosDecodeFixedU32(buf, &(pInfo->totalSubBlocks));
|
||||||
|
@ -562,8 +569,10 @@ static int tsdbRollBackDFile(SDFile *pDFile) {
|
||||||
|
|
||||||
// ============== Operations on SDFileSet
|
// ============== Operations on SDFileSet
|
||||||
void tsdbInitDFileSet(STsdb *pRepo, SDFileSet *pSet, SDiskID did, int fid, uint32_t ver) {
|
void tsdbInitDFileSet(STsdb *pRepo, SDFileSet *pSet, SDiskID did, int fid, uint32_t ver) {
|
||||||
pSet->fid = fid;
|
TSDB_FSET_FID(pSet) = fid;
|
||||||
pSet->state = 0;
|
TSDB_FSET_VER(pSet) = TSDB_LATEST_FSET_VER;
|
||||||
|
TSDB_FSET_STATE(pSet) = 0;
|
||||||
|
pSet->reserve = 0;
|
||||||
|
|
||||||
for (TSDB_FILE_T ftype = 0; ftype < TSDB_FILE_MAX; ftype++) {
|
for (TSDB_FILE_T ftype = 0; ftype < TSDB_FILE_MAX; ftype++) {
|
||||||
SDFile *pDFile = TSDB_DFILE_IN_SET(pSet, ftype);
|
SDFile *pDFile = TSDB_DFILE_IN_SET(pSet, ftype);
|
||||||
|
@ -572,7 +581,7 @@ void tsdbInitDFileSet(STsdb *pRepo, SDFileSet *pSet, SDiskID did, int fid, uint3
|
||||||
}
|
}
|
||||||
|
|
||||||
void tsdbInitDFileSetEx(SDFileSet *pSet, SDFileSet *pOSet) {
|
void tsdbInitDFileSetEx(SDFileSet *pSet, SDFileSet *pOSet) {
|
||||||
pSet->fid = pOSet->fid;
|
TSDB_FSET_FID(pSet) = TSDB_FSET_FID(pOSet);
|
||||||
for (TSDB_FILE_T ftype = 0; ftype < TSDB_FILE_MAX; ftype++) {
|
for (TSDB_FILE_T ftype = 0; ftype < TSDB_FILE_MAX; ftype++) {
|
||||||
tsdbInitDFileEx(TSDB_DFILE_IN_SET(pSet, ftype), TSDB_DFILE_IN_SET(pOSet, ftype));
|
tsdbInitDFileEx(TSDB_DFILE_IN_SET(pSet, ftype), TSDB_DFILE_IN_SET(pOSet, ftype));
|
||||||
}
|
}
|
||||||
|
@ -581,7 +590,10 @@ void tsdbInitDFileSetEx(SDFileSet *pSet, SDFileSet *pOSet) {
|
||||||
int tsdbEncodeDFileSet(void **buf, SDFileSet *pSet) {
|
int tsdbEncodeDFileSet(void **buf, SDFileSet *pSet) {
|
||||||
int tlen = 0;
|
int tlen = 0;
|
||||||
|
|
||||||
tlen += taosEncodeFixedI32(buf, pSet->fid);
|
tlen += taosEncodeFixedI32(buf, TSDB_FSET_FID(pSet));
|
||||||
|
// state not included
|
||||||
|
tlen += taosEncodeFixedU8(buf, TSDB_FSET_VER(pSet));
|
||||||
|
tlen += taosEncodeFixedU16(buf, pSet->reserve);
|
||||||
for (TSDB_FILE_T ftype = 0; ftype < TSDB_FILE_MAX; ftype++) {
|
for (TSDB_FILE_T ftype = 0; ftype < TSDB_FILE_MAX; ftype++) {
|
||||||
tlen += tsdbEncodeSDFile(buf, TSDB_DFILE_IN_SET(pSet, ftype));
|
tlen += tsdbEncodeSDFile(buf, TSDB_DFILE_IN_SET(pSet, ftype));
|
||||||
}
|
}
|
||||||
|
@ -590,11 +602,11 @@ int tsdbEncodeDFileSet(void **buf, SDFileSet *pSet) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void *tsdbDecodeDFileSet(STsdb *pRepo, void *buf, SDFileSet *pSet) {
|
void *tsdbDecodeDFileSet(STsdb *pRepo, void *buf, SDFileSet *pSet) {
|
||||||
int32_t fid;
|
buf = taosDecodeFixedI32(buf, &(TSDB_FSET_FID(pSet)));
|
||||||
|
TSDB_FSET_STATE(pSet) = 0;
|
||||||
|
buf = taosDecodeFixedU8(buf, &(TSDB_FSET_VER(pSet)));
|
||||||
|
buf = taosDecodeFixedU16(buf, &(pSet->reserve));
|
||||||
|
|
||||||
buf = taosDecodeFixedI32(buf, &(fid));
|
|
||||||
pSet->state = 0;
|
|
||||||
pSet->fid = fid;
|
|
||||||
for (TSDB_FILE_T ftype = 0; ftype < TSDB_FILE_MAX; ftype++) {
|
for (TSDB_FILE_T ftype = 0; ftype < TSDB_FILE_MAX; ftype++) {
|
||||||
buf = tsdbDecodeSDFile(pRepo, buf, TSDB_DFILE_IN_SET(pSet, ftype));
|
buf = tsdbDecodeSDFile(pRepo, buf, TSDB_DFILE_IN_SET(pSet, ftype));
|
||||||
}
|
}
|
||||||
|
@ -604,7 +616,9 @@ void *tsdbDecodeDFileSet(STsdb *pRepo, void *buf, SDFileSet *pSet) {
|
||||||
int tsdbEncodeDFileSetEx(void **buf, SDFileSet *pSet) {
|
int tsdbEncodeDFileSetEx(void **buf, SDFileSet *pSet) {
|
||||||
int tlen = 0;
|
int tlen = 0;
|
||||||
|
|
||||||
tlen += taosEncodeFixedI32(buf, pSet->fid);
|
tlen += taosEncodeFixedI32(buf, TSDB_FSET_FID(pSet));
|
||||||
|
tlen += taosEncodeFixedU8(buf, TSDB_FSET_VER(pSet));
|
||||||
|
tlen += taosEncodeFixedU16(buf, pSet->reserve);
|
||||||
for (TSDB_FILE_T ftype = 0; ftype < TSDB_FILE_MAX; ftype++) {
|
for (TSDB_FILE_T ftype = 0; ftype < TSDB_FILE_MAX; ftype++) {
|
||||||
tlen += tsdbEncodeSDFileEx(buf, TSDB_DFILE_IN_SET(pSet, ftype));
|
tlen += tsdbEncodeSDFileEx(buf, TSDB_DFILE_IN_SET(pSet, ftype));
|
||||||
}
|
}
|
||||||
|
@ -613,10 +627,10 @@ int tsdbEncodeDFileSetEx(void **buf, SDFileSet *pSet) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void *tsdbDecodeDFileSetEx(void *buf, SDFileSet *pSet) {
|
void *tsdbDecodeDFileSetEx(void *buf, SDFileSet *pSet) {
|
||||||
int32_t fid;
|
buf = taosDecodeFixedI32(buf, &(TSDB_FSET_FID(pSet)));
|
||||||
|
buf = taosDecodeFixedU8(buf, &(TSDB_FSET_VER(pSet)));
|
||||||
|
buf = taosDecodeFixedU16(buf, &(pSet->reserve));
|
||||||
|
|
||||||
buf = taosDecodeFixedI32(buf, &(fid));
|
|
||||||
pSet->fid = fid;
|
|
||||||
for (TSDB_FILE_T ftype = 0; ftype < TSDB_FILE_MAX; ftype++) {
|
for (TSDB_FILE_T ftype = 0; ftype < TSDB_FILE_MAX; ftype++) {
|
||||||
buf = tsdbDecodeSDFileEx(buf, TSDB_DFILE_IN_SET(pSet, ftype));
|
buf = tsdbDecodeSDFileEx(buf, TSDB_DFILE_IN_SET(pSet, ftype));
|
||||||
}
|
}
|
||||||
|
@ -637,7 +651,7 @@ int tsdbApplyDFileSetChange(SDFileSet *from, SDFileSet *to) {
|
||||||
|
|
||||||
int tsdbCreateDFileSet(STsdb *pRepo, SDFileSet *pSet, bool updateHeader) {
|
int tsdbCreateDFileSet(STsdb *pRepo, SDFileSet *pSet, bool updateHeader) {
|
||||||
for (TSDB_FILE_T ftype = 0; ftype < TSDB_FILE_MAX; ftype++) {
|
for (TSDB_FILE_T ftype = 0; ftype < TSDB_FILE_MAX; ftype++) {
|
||||||
if (tsdbCreateDFile(pRepo, TSDB_DFILE_IN_SET(pSet, ftype), updateHeader) < 0) {
|
if (tsdbCreateDFile(pRepo, TSDB_DFILE_IN_SET(pSet, ftype), updateHeader, ftype) < 0) {
|
||||||
tsdbCloseDFileSet(pSet);
|
tsdbCloseDFileSet(pSet);
|
||||||
tsdbRemoveDFileSet(pSet);
|
tsdbRemoveDFileSet(pSet);
|
||||||
return -1;
|
return -1;
|
||||||
|
|
|
@ -821,10 +821,11 @@ static int tsdbRestoreLastColumns(STsdbRepo *pRepo, STable *pTable, SReadH* pRea
|
||||||
|
|
||||||
// file block with sub-blocks has no statistics data
|
// file block with sub-blocks has no statistics data
|
||||||
if (pBlock->numOfSubBlocks <= 1) {
|
if (pBlock->numOfSubBlocks <= 1) {
|
||||||
tsdbLoadBlockStatis(pReadh, pBlock);
|
if (tsdbLoadBlockStatis(pReadh, pBlock) == TSDB_STATIS_OK) {
|
||||||
tsdbGetBlockStatis(pReadh, pBlockStatis, (int)numColumns);
|
tsdbGetBlockStatis(pReadh, pBlockStatis, (int)numColumns, pBlock);
|
||||||
loadStatisData = true;
|
loadStatisData = true;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
for (int16_t i = 0; i < numColumns && numColumns > pTable->restoreColumnNum; ++i) {
|
for (int16_t i = 0; i < numColumns && numColumns > pTable->restoreColumnNum; ++i) {
|
||||||
STColumn *pCol = schemaColAt(pSchema, i);
|
STColumn *pCol = schemaColAt(pSchema, i);
|
||||||
|
|
|
@ -3276,8 +3276,12 @@ int32_t tsdbRetrieveDataBlockStatisInfo(tsdbReaderT* pTsdbReadHandle, SDataStati
|
||||||
}
|
}
|
||||||
|
|
||||||
int64_t stime = taosGetTimestampUs();
|
int64_t stime = taosGetTimestampUs();
|
||||||
if (tsdbLoadBlockStatis(&pHandle->rhelper, pBlockInfo->compBlock) < 0) {
|
int statisStatus = tsdbLoadBlockStatis(&pHandle->rhelper, pBlockInfo->compBlock);
|
||||||
|
if (statisStatus < TSDB_STATIS_OK) {
|
||||||
return terrno;
|
return terrno;
|
||||||
|
} else if (statisStatus > TSDB_STATIS_OK) {
|
||||||
|
*pBlockStatis = NULL;
|
||||||
|
return TSDB_CODE_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
int16_t* colIds = pHandle->defaultLoadColumn->pData;
|
int16_t* colIds = pHandle->defaultLoadColumn->pData;
|
||||||
|
@ -3288,7 +3292,7 @@ int32_t tsdbRetrieveDataBlockStatisInfo(tsdbReaderT* pTsdbReadHandle, SDataStati
|
||||||
pHandle->statis[i].colId = colIds[i];
|
pHandle->statis[i].colId = colIds[i];
|
||||||
}
|
}
|
||||||
|
|
||||||
tsdbGetBlockStatis(&pHandle->rhelper, pHandle->statis, (int)numOfCols);
|
tsdbGetBlockStatis(&pHandle->rhelper, pHandle->statis, (int)numOfCols, pBlockInfo->compBlock);
|
||||||
|
|
||||||
// always load the first primary timestamp column data
|
// always load the first primary timestamp column data
|
||||||
SDataStatis* pPrimaryColStatis = &pHandle->statis[0];
|
SDataStatis* pPrimaryColStatis = &pHandle->statis[0];
|
||||||
|
|
|
@ -19,6 +19,7 @@
|
||||||
|
|
||||||
static void tsdbResetReadTable(SReadH *pReadh);
|
static void tsdbResetReadTable(SReadH *pReadh);
|
||||||
static void tsdbResetReadFile(SReadH *pReadh);
|
static void tsdbResetReadFile(SReadH *pReadh);
|
||||||
|
static int tsdbLoadBlockOffset(SReadH *pReadh, SBlock *pBlock);
|
||||||
static int tsdbLoadBlockDataImpl(SReadH *pReadh, SBlock *pBlock, SDataCols *pDataCols);
|
static int tsdbLoadBlockDataImpl(SReadH *pReadh, SBlock *pBlock, SDataCols *pDataCols);
|
||||||
static int tsdbCheckAndDecodeColumnData(SDataCol *pDataCol, void *content, int32_t len, int8_t comp, int numOfRows,
|
static int tsdbCheckAndDecodeColumnData(SDataCol *pDataCol, void *content, int32_t len, int8_t comp, int numOfRows,
|
||||||
int numOfBitmaps, int lenOfBitmaps, int maxPoints, char *buffer,
|
int numOfBitmaps, int lenOfBitmaps, int maxPoints, char *buffer,
|
||||||
|
@ -63,10 +64,12 @@ int tsdbInitReadH(SReadH *pReadh, STsdb *pRepo) {
|
||||||
void tsdbDestroyReadH(SReadH *pReadh) {
|
void tsdbDestroyReadH(SReadH *pReadh) {
|
||||||
if (pReadh == NULL) return;
|
if (pReadh == NULL) return;
|
||||||
|
|
||||||
|
pReadh->pExBuf = taosTZfree(pReadh->pExBuf);
|
||||||
pReadh->pCBuf = taosTZfree(pReadh->pCBuf);
|
pReadh->pCBuf = taosTZfree(pReadh->pCBuf);
|
||||||
pReadh->pBuf = taosTZfree(pReadh->pBuf);
|
pReadh->pBuf = taosTZfree(pReadh->pBuf);
|
||||||
pReadh->pDCols[0] = tdFreeDataCols(pReadh->pDCols[0]);
|
pReadh->pDCols[0] = tdFreeDataCols(pReadh->pDCols[0]);
|
||||||
pReadh->pDCols[1] = tdFreeDataCols(pReadh->pDCols[1]);
|
pReadh->pDCols[1] = tdFreeDataCols(pReadh->pDCols[1]);
|
||||||
|
pReadh->pAggrBlkData = taosTZfree(pReadh->pAggrBlkData);
|
||||||
pReadh->pBlkData = taosTZfree(pReadh->pBlkData);
|
pReadh->pBlkData = taosTZfree(pReadh->pBlkData);
|
||||||
pReadh->pBlkInfo = taosTZfree(pReadh->pBlkInfo);
|
pReadh->pBlkInfo = taosTZfree(pReadh->pBlkInfo);
|
||||||
pReadh->cidx = 0;
|
pReadh->cidx = 0;
|
||||||
|
@ -305,15 +308,58 @@ int tsdbLoadBlockDataCols(SReadH *pReadh, SBlock *pBlock, SBlockInfo *pBlkInfo,
|
||||||
int tsdbLoadBlockStatis(SReadH *pReadh, SBlock *pBlock) {
|
int tsdbLoadBlockStatis(SReadH *pReadh, SBlock *pBlock) {
|
||||||
ASSERT(pBlock->numOfSubBlocks <= 1);
|
ASSERT(pBlock->numOfSubBlocks <= 1);
|
||||||
|
|
||||||
SDFile *pDFile = (pBlock->last) ? TSDB_READ_LAST_FILE(pReadh) : TSDB_READ_DATA_FILE(pReadh);
|
if (!pBlock->aggrStat) {
|
||||||
|
return TSDB_STATIS_NONE;
|
||||||
|
}
|
||||||
|
|
||||||
|
SDFile *pDFileAggr = pBlock->last ? TSDB_READ_SMAL_FILE(pReadh) : TSDB_READ_SMAD_FILE(pReadh);
|
||||||
|
|
||||||
|
if (tsdbSeekDFile(pDFileAggr, pBlock->aggrOffset, SEEK_SET) < 0) {
|
||||||
|
tsdbError("vgId:%d failed to load block aggr part while seek file %s to offset %" PRIu64 " since %s",
|
||||||
|
TSDB_READ_REPO_ID(pReadh), TSDB_FILE_FULL_NAME(pDFileAggr), (uint64_t)pBlock->aggrOffset,
|
||||||
|
tstrerror(terrno));
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
size_t sizeAggr = tsdbBlockAggrSize(pBlock->numOfCols, (uint32_t)pBlock->blkVer);
|
||||||
|
if (tsdbMakeRoom((void **)(&(pReadh->pAggrBlkData)), sizeAggr) < 0) return -1;
|
||||||
|
|
||||||
|
int64_t nreadAggr = tsdbReadDFile(pDFileAggr, (void *)(pReadh->pAggrBlkData), sizeAggr);
|
||||||
|
if (nreadAggr < 0) {
|
||||||
|
tsdbError("vgId:%d failed to load block aggr part while read file %s since %s, offset:%" PRIu64 " len :%" PRIzu,
|
||||||
|
TSDB_READ_REPO_ID(pReadh), TSDB_FILE_FULL_NAME(pDFileAggr), tstrerror(terrno),
|
||||||
|
(uint64_t)pBlock->aggrOffset, sizeAggr);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (nreadAggr < sizeAggr) {
|
||||||
|
terrno = TSDB_CODE_TDB_FILE_CORRUPTED;
|
||||||
|
tsdbError("vgId:%d block aggr part in file %s is corrupted, offset:%" PRIu64 " expected bytes:%" PRIzu
|
||||||
|
" read bytes: %" PRId64,
|
||||||
|
TSDB_READ_REPO_ID(pReadh), TSDB_FILE_FULL_NAME(pDFileAggr), (uint64_t)pBlock->aggrOffset, sizeAggr,
|
||||||
|
nreadAggr);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!taosCheckChecksumWhole((uint8_t *)(pReadh->pAggrBlkData), (uint32_t)sizeAggr)) {
|
||||||
|
terrno = TSDB_CODE_TDB_FILE_CORRUPTED;
|
||||||
|
tsdbError("vgId:%d block aggr part in file %s is corrupted since wrong checksum, offset:%" PRIu64 " len :%" PRIzu,
|
||||||
|
TSDB_READ_REPO_ID(pReadh), TSDB_FILE_FULL_NAME(pDFileAggr), (uint64_t)pBlock->aggrOffset, sizeAggr);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int tsdbLoadBlockOffset(SReadH *pReadh, SBlock *pBlock) {
|
||||||
|
ASSERT(pBlock->numOfSubBlocks <= 1);
|
||||||
|
SDFile *pDFile = (pBlock->last) ? TSDB_READ_LAST_FILE(pReadh) : TSDB_READ_DATA_FILE(pReadh);
|
||||||
if (tsdbSeekDFile(pDFile, pBlock->offset, SEEK_SET) < 0) {
|
if (tsdbSeekDFile(pDFile, pBlock->offset, SEEK_SET) < 0) {
|
||||||
tsdbError("vgId:%d failed to load block statis part while seek file %s to offset %" PRId64 " since %s",
|
tsdbError("vgId:%d failed to load block statis part while seek file %s to offset %" PRId64 " since %s",
|
||||||
TSDB_READ_REPO_ID(pReadh), TSDB_FILE_FULL_NAME(pDFile), (int64_t)pBlock->offset, tstrerror(terrno));
|
TSDB_READ_REPO_ID(pReadh), TSDB_FILE_FULL_NAME(pDFile), (int64_t)pBlock->offset, tstrerror(terrno));
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t size = TSDB_BLOCK_STATIS_SIZE(pBlock->numOfCols);
|
size_t size = tsdbBlockStatisSize(pBlock->numOfCols, (uint32_t)pBlock->blkVer);
|
||||||
if (tsdbMakeRoom((void **)(&(pReadh->pBlkData)), size) < 0) return -1;
|
if (tsdbMakeRoom((void **)(&(pReadh->pBlkData)), size) < 0) return -1;
|
||||||
|
|
||||||
int64_t nread = tsdbReadDFile(pDFile, (void *)(pReadh->pBlkData), size);
|
int64_t nread = tsdbReadDFile(pDFile, (void *)(pReadh->pBlkData), size);
|
||||||
|
@ -337,7 +383,6 @@ int tsdbLoadBlockStatis(SReadH *pReadh, SBlock *pBlock) {
|
||||||
TSDB_READ_REPO_ID(pReadh), TSDB_FILE_FULL_NAME(pDFile), (int64_t)pBlock->offset, size);
|
TSDB_READ_REPO_ID(pReadh), TSDB_FILE_FULL_NAME(pDFile), (int64_t)pBlock->offset, size);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -375,13 +420,14 @@ void *tsdbDecodeSBlockIdx(void *buf, SBlockIdx *pIdx) {
|
||||||
return buf;
|
return buf;
|
||||||
}
|
}
|
||||||
|
|
||||||
void tsdbGetBlockStatis(SReadH *pReadh, SDataStatis *pStatis, int numOfCols) {
|
void tsdbGetBlockStatis(SReadH *pReadh, SDataStatis *pStatis, int numOfCols, SBlock *pBlock) {
|
||||||
|
#ifdef TD_REFACTOR_3
|
||||||
SBlockData *pBlockData = pReadh->pBlkData;
|
SBlockData *pBlockData = pReadh->pBlkData;
|
||||||
|
|
||||||
for (int i = 0, j = 0; i < numOfCols;) {
|
for (int i = 0, j = 0; i < numOfCols;) {
|
||||||
if (j >= pBlockData->numOfCols) {
|
if (j >= pBlockData->numOfCols) {
|
||||||
pStatis[i].numOfNull = -1;
|
pStatis[i].numOfNull = -1;
|
||||||
i++;
|
++i;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -392,15 +438,45 @@ void tsdbGetBlockStatis(SReadH *pReadh, SDataStatis *pStatis, int numOfCols) {
|
||||||
pStatis[i].maxIndex = pBlockData->cols[j].maxIndex;
|
pStatis[i].maxIndex = pBlockData->cols[j].maxIndex;
|
||||||
pStatis[i].minIndex = pBlockData->cols[j].minIndex;
|
pStatis[i].minIndex = pBlockData->cols[j].minIndex;
|
||||||
pStatis[i].numOfNull = pBlockData->cols[j].numOfNull;
|
pStatis[i].numOfNull = pBlockData->cols[j].numOfNull;
|
||||||
i++;
|
++i;
|
||||||
j++;
|
++j;
|
||||||
} else if (pStatis[i].colId < pBlockData->cols[j].colId) {
|
} else if (pStatis[i].colId < pBlockData->cols[j].colId) {
|
||||||
pStatis[i].numOfNull = -1;
|
pStatis[i].numOfNull = -1;
|
||||||
i++;
|
++i;
|
||||||
} else {
|
} else {
|
||||||
j++;
|
++j;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
#else
|
||||||
|
if (pBlock->aggrStat) {
|
||||||
|
SAggrBlkData *pAggrBlkData = pReadh->pAggrBlkData;
|
||||||
|
|
||||||
|
for (int i = 0, j = 0; i < numOfCols;) {
|
||||||
|
if (j >= pBlock->numOfCols) {
|
||||||
|
pStatis[i].numOfNull = -1;
|
||||||
|
++i;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
SAggrBlkCol *pAggrBlkCol = ((SAggrBlkCol *)(pAggrBlkData)) + j;
|
||||||
|
if (pStatis[i].colId == pAggrBlkCol->colId) {
|
||||||
|
pStatis[i].sum = pAggrBlkCol->sum;
|
||||||
|
pStatis[i].max = pAggrBlkCol->max;
|
||||||
|
pStatis[i].min = pAggrBlkCol->min;
|
||||||
|
pStatis[i].maxIndex = pAggrBlkCol->maxIndex;
|
||||||
|
pStatis[i].minIndex = pAggrBlkCol->minIndex;
|
||||||
|
pStatis[i].numOfNull = pAggrBlkCol->numOfNull;
|
||||||
|
++i;
|
||||||
|
++j;
|
||||||
|
} else if (pStatis[i].colId < pAggrBlkCol->colId) {
|
||||||
|
pStatis[i].numOfNull = -1;
|
||||||
|
++i;
|
||||||
|
} else {
|
||||||
|
++j;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
static void tsdbResetReadTable(SReadH *pReadh) {
|
static void tsdbResetReadTable(SReadH *pReadh) {
|
||||||
|
@ -449,7 +525,7 @@ static int tsdbLoadBlockDataImpl(SReadH *pReadh, SBlock *pBlock, SDataCols *pDat
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t tsize = TSDB_BLOCK_STATIS_SIZE(pBlock->numOfCols);
|
int32_t tsize = (int32_t)tsdbBlockStatisSize(pBlock->numOfCols, (uint32_t)pBlock->blkVer);
|
||||||
if (!taosCheckChecksumWhole((uint8_t *)TSDB_READ_BUF(pReadh), tsize)) {
|
if (!taosCheckChecksumWhole((uint8_t *)TSDB_READ_BUF(pReadh), tsize)) {
|
||||||
terrno = TSDB_CODE_TDB_FILE_CORRUPTED;
|
terrno = TSDB_CODE_TDB_FILE_CORRUPTED;
|
||||||
tsdbError("vgId:%d block statis part in file %s is corrupted since wrong checksum, offset:%" PRId64 " len :%d",
|
tsdbError("vgId:%d block statis part in file %s is corrupted since wrong checksum, offset:%" PRId64 " len :%d",
|
||||||
|
@ -592,7 +668,7 @@ static int tsdbLoadBlockDataColsImpl(SReadH *pReadh, SBlock *pBlock, SDataCols *
|
||||||
tdResetDataCols(pDataCols);
|
tdResetDataCols(pDataCols);
|
||||||
|
|
||||||
// If only load timestamp column, no need to load SBlockData part
|
// If only load timestamp column, no need to load SBlockData part
|
||||||
if (numOfColIds > 1 && tsdbLoadBlockStatis(pReadh, pBlock) < 0) return -1;
|
if (numOfColIds > 1 && tsdbLoadBlockOffset(pReadh, pBlock) < 0) return -1;
|
||||||
|
|
||||||
pDataCols->numOfRows = pBlock->numOfRows;
|
pDataCols->numOfRows = pBlock->numOfRows;
|
||||||
|
|
||||||
|
@ -686,7 +762,8 @@ static int tsdbLoadColData(SReadH *pReadh, SDFile *pDFile, SBlock *pBlock, SBloc
|
||||||
if (tsdbMakeRoom((void **)(&TSDB_READ_BUF(pReadh)), pBlockCol->len) < 0) return -1;
|
if (tsdbMakeRoom((void **)(&TSDB_READ_BUF(pReadh)), pBlockCol->len) < 0) return -1;
|
||||||
if (tsdbMakeRoom((void **)(&TSDB_READ_COMP_BUF(pReadh)), tsize) < 0) return -1;
|
if (tsdbMakeRoom((void **)(&TSDB_READ_COMP_BUF(pReadh)), tsize) < 0) return -1;
|
||||||
|
|
||||||
int64_t offset = pBlock->offset + TSDB_BLOCK_STATIS_SIZE(pBlock->numOfCols) + tsdbGetBlockColOffset(pBlockCol);
|
int64_t offset = pBlock->offset + tsdbBlockStatisSize(pBlock->numOfCols, (uint32_t)pBlock->blkVer) +
|
||||||
|
tsdbGetBlockColOffset(pBlockCol);
|
||||||
if (tsdbSeekDFile(pDFile, offset, SEEK_SET) < 0) {
|
if (tsdbSeekDFile(pDFile, offset, SEEK_SET) < 0) {
|
||||||
tsdbError("vgId:%d failed to load block column data while seek file %s to offset %" PRId64 " since %s",
|
tsdbError("vgId:%d failed to load block column data while seek file %s to offset %" PRId64 " since %s",
|
||||||
TSDB_READ_REPO_ID(pReadh), TSDB_FILE_FULL_NAME(pDFile), offset, tstrerror(terrno));
|
TSDB_READ_REPO_ID(pReadh), TSDB_FILE_FULL_NAME(pDFile), offset, tstrerror(terrno));
|
||||||
|
|
|
@ -30,6 +30,9 @@ SVnode *vnodeOpen(const char *path, const SVnodeCfg *pVnodeCfg) {
|
||||||
cfg.pDnode = pVnodeCfg->pDnode;
|
cfg.pDnode = pVnodeCfg->pDnode;
|
||||||
cfg.pTfs = pVnodeCfg->pTfs;
|
cfg.pTfs = pVnodeCfg->pTfs;
|
||||||
cfg.dbId = pVnodeCfg->dbId;
|
cfg.dbId = pVnodeCfg->dbId;
|
||||||
|
cfg.hashBegin = pVnodeCfg->hashBegin;
|
||||||
|
cfg.hashEnd = pVnodeCfg->hashEnd;
|
||||||
|
cfg.hashMethod = pVnodeCfg->hashMethod;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Validate options
|
// Validate options
|
||||||
|
|
|
@ -1,4 +1,3 @@
|
||||||
add_definitions("-D ALLOW_FORBID_FUNC")
|
|
||||||
add_subdirectory(transport)
|
add_subdirectory(transport)
|
||||||
add_subdirectory(sync)
|
add_subdirectory(sync)
|
||||||
add_subdirectory(tdb)
|
add_subdirectory(tdb)
|
||||||
|
@ -14,5 +13,6 @@ add_subdirectory(function)
|
||||||
add_subdirectory(qcom)
|
add_subdirectory(qcom)
|
||||||
add_subdirectory(qworker)
|
add_subdirectory(qworker)
|
||||||
add_subdirectory(tfs)
|
add_subdirectory(tfs)
|
||||||
|
add_subdirectory(monitor)
|
||||||
add_subdirectory(nodes)
|
add_subdirectory(nodes)
|
||||||
add_subdirectory(scalar)
|
add_subdirectory(scalar)
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
aux_source_directory(src CACHE_SRC)
|
aux_source_directory(src CACHE_SRC)
|
||||||
add_library(cache ${CACHE_SRC})
|
add_library(cache STATIC ${CACHE_SRC})
|
||||||
target_include_directories(
|
target_include_directories(
|
||||||
cache
|
cache
|
||||||
PUBLIC "${CMAKE_SOURCE_DIR}/include/libs/cache"
|
PUBLIC "${CMAKE_SOURCE_DIR}/include/libs/cache"
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
aux_source_directory(src CATALOG_SRC)
|
aux_source_directory(src CATALOG_SRC)
|
||||||
add_library(catalog ${CATALOG_SRC})
|
add_library(catalog STATIC ${CATALOG_SRC})
|
||||||
target_include_directories(
|
target_include_directories(
|
||||||
catalog
|
catalog
|
||||||
PUBLIC "${CMAKE_SOURCE_DIR}/include/libs/catalog"
|
PUBLIC "${CMAKE_SOURCE_DIR}/include/libs/catalog"
|
||||||
|
|
|
@ -60,6 +60,7 @@ typedef struct SCtgDebug {
|
||||||
bool lockDebug;
|
bool lockDebug;
|
||||||
bool cacheDebug;
|
bool cacheDebug;
|
||||||
bool apiDebug;
|
bool apiDebug;
|
||||||
|
bool metaDebug;
|
||||||
uint32_t showCachePeriodSec;
|
uint32_t showCachePeriodSec;
|
||||||
} SCtgDebug;
|
} SCtgDebug;
|
||||||
|
|
||||||
|
@ -119,6 +120,10 @@ typedef struct SCatalogStat {
|
||||||
SCtgCacheStat cache;
|
SCtgCacheStat cache;
|
||||||
} SCatalogStat;
|
} SCatalogStat;
|
||||||
|
|
||||||
|
typedef struct SCtgUpdateMsgHeader {
|
||||||
|
SCatalog* pCtg;
|
||||||
|
} SCtgUpdateMsgHeader;
|
||||||
|
|
||||||
typedef struct SCtgUpdateVgMsg {
|
typedef struct SCtgUpdateVgMsg {
|
||||||
SCatalog* pCtg;
|
SCatalog* pCtg;
|
||||||
char dbFName[TSDB_DB_FNAME_LEN];
|
char dbFName[TSDB_DB_FNAME_LEN];
|
||||||
|
@ -145,6 +150,14 @@ typedef struct SCtgRemoveStbMsg {
|
||||||
uint64_t suid;
|
uint64_t suid;
|
||||||
} SCtgRemoveStbMsg;
|
} SCtgRemoveStbMsg;
|
||||||
|
|
||||||
|
typedef struct SCtgRemoveTblMsg {
|
||||||
|
SCatalog* pCtg;
|
||||||
|
char dbFName[TSDB_DB_FNAME_LEN];
|
||||||
|
char tbName[TSDB_TABLE_NAME_LEN];
|
||||||
|
uint64_t dbId;
|
||||||
|
} SCtgRemoveTblMsg;
|
||||||
|
|
||||||
|
|
||||||
typedef struct SCtgMetaAction {
|
typedef struct SCtgMetaAction {
|
||||||
int32_t act;
|
int32_t act;
|
||||||
void *data;
|
void *data;
|
||||||
|
@ -193,15 +206,17 @@ typedef struct SCtgAction {
|
||||||
#define CTG_FLAG_NOT_STB 0x2
|
#define CTG_FLAG_NOT_STB 0x2
|
||||||
#define CTG_FLAG_UNKNOWN_STB 0x4
|
#define CTG_FLAG_UNKNOWN_STB 0x4
|
||||||
#define CTG_FLAG_INF_DB 0x8
|
#define CTG_FLAG_INF_DB 0x8
|
||||||
|
#define CTG_FLAG_FORCE_UPDATE 0x10
|
||||||
|
|
||||||
#define CTG_IS_STB(_flag) ((_flag) & CTG_FLAG_STB)
|
#define CTG_FLAG_IS_STB(_flag) ((_flag) & CTG_FLAG_STB)
|
||||||
#define CTG_IS_NOT_STB(_flag) ((_flag) & CTG_FLAG_NOT_STB)
|
#define CTG_FLAG_IS_NOT_STB(_flag) ((_flag) & CTG_FLAG_NOT_STB)
|
||||||
#define CTG_IS_UNKNOWN_STB(_flag) ((_flag) & CTG_FLAG_UNKNOWN_STB)
|
#define CTG_FLAG_IS_UNKNOWN_STB(_flag) ((_flag) & CTG_FLAG_UNKNOWN_STB)
|
||||||
#define CTG_IS_INF_DB(_flag) ((_flag) & CTG_FLAG_INF_DB)
|
#define CTG_FLAG_IS_INF_DB(_flag) ((_flag) & CTG_FLAG_INF_DB)
|
||||||
#define CTG_SET_INF_DB(_flag) ((_flag) |= CTG_FLAG_INF_DB)
|
#define CTG_FLAG_IS_FORCE_UPDATE(_flag) ((_flag) & CTG_FLAG_FORCE_UPDATE)
|
||||||
#define CTG_SET_STB(_flag, tbType) do { (_flag) |= ((tbType) == TSDB_SUPER_TABLE) ? CTG_FLAG_STB : ((tbType) > TSDB_SUPER_TABLE ? CTG_FLAG_NOT_STB : CTG_FLAG_UNKNOWN_STB); } while (0)
|
#define CTG_FLAG_SET_INF_DB(_flag) ((_flag) |= CTG_FLAG_INF_DB)
|
||||||
#define CTG_GEN_STB_FLAG(_isStb) ((_isStb) == 1) ? CTG_FLAG_STB : ((_isStb) == 0 ? CTG_FLAG_NOT_STB : CTG_FLAG_UNKNOWN_STB)
|
#define CTG_FLAG_SET_STB(_flag, tbType) do { (_flag) |= ((tbType) == TSDB_SUPER_TABLE) ? CTG_FLAG_STB : ((tbType) > TSDB_SUPER_TABLE ? CTG_FLAG_NOT_STB : CTG_FLAG_UNKNOWN_STB); } while (0)
|
||||||
#define CTG_TBTYPE_MATCH(_flag, tbType) (CTG_IS_UNKNOWN_STB(_flag) || (CTG_IS_STB(_flag) && (tbType) == TSDB_SUPER_TABLE) || (CTG_IS_NOT_STB(_flag) && (tbType) != TSDB_SUPER_TABLE))
|
#define CTG_FLAG_MAKE_STB(_isStb) (((_isStb) == 1) ? CTG_FLAG_STB : ((_isStb) == 0 ? CTG_FLAG_NOT_STB : CTG_FLAG_UNKNOWN_STB))
|
||||||
|
#define CTG_FLAG_MATCH_STB(_flag, tbType) (CTG_FLAG_IS_UNKNOWN_STB(_flag) || (CTG_FLAG_IS_STB(_flag) && (tbType) == TSDB_SUPER_TABLE) || (CTG_FLAG_IS_NOT_STB(_flag) && (tbType) != TSDB_SUPER_TABLE))
|
||||||
|
|
||||||
#define CTG_IS_INF_DBNAME(_dbname) ((*(_dbname) == 'i') && (0 == strcmp(_dbname, TSDB_INFORMATION_SCHEMA_DB)))
|
#define CTG_IS_INF_DBNAME(_dbname) ((*(_dbname) == 'i') && (0 == strcmp(_dbname, TSDB_INFORMATION_SCHEMA_DB)))
|
||||||
|
|
||||||
|
|
|
@ -72,6 +72,12 @@ int32_t ctgDbgEnableDebug(char *option) {
|
||||||
return TSDB_CODE_SUCCESS;
|
return TSDB_CODE_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (0 == strcasecmp(option, "meta")) {
|
||||||
|
gCTGDebug.metaDebug = true;
|
||||||
|
qDebug("api debug enabled");
|
||||||
|
return TSDB_CODE_SUCCESS;
|
||||||
|
}
|
||||||
|
|
||||||
qError("invalid debug option:%s", option);
|
qError("invalid debug option:%s", option);
|
||||||
|
|
||||||
return TSDB_CODE_CTG_INTERNAL_ERROR;
|
return TSDB_CODE_CTG_INTERNAL_ERROR;
|
||||||
|
@ -148,9 +154,30 @@ int32_t ctgDbgGetClusterCacheNum(SCatalog* pCtg, int32_t type) {
|
||||||
return num;
|
return num;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ctgDbgShowTableMeta(SCatalog* pCtg, const char *tbName, STableMeta* p) {
|
||||||
|
if (!gCTGDebug.metaDebug) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
void ctgDbgShowDBCache(SHashObj *dbHash) {
|
STableComInfo *c = &p->tableInfo;
|
||||||
if (NULL == dbHash) {
|
|
||||||
|
if (TSDB_CHILD_TABLE == p->tableType) {
|
||||||
|
ctgDebug("table [%s] meta: type:%d, vgId:%d, uid:%" PRIx64 ",suid:%" PRIx64, tbName, p->tableType, p->vgId, p->uid, p->suid);
|
||||||
|
return;
|
||||||
|
} else {
|
||||||
|
ctgDebug("table [%s] meta: type:%d, vgId:%d, uid:%" PRIx64 ",suid:%" PRIx64 ",sv:%d, tv:%d, tagNum:%d, precision:%d, colNum:%d, rowSize:%d",
|
||||||
|
tbName, p->tableType, p->vgId, p->uid, p->suid, p->sversion, p->tversion, c->numOfTags, c->precision, c->numOfColumns, c->rowSize);
|
||||||
|
}
|
||||||
|
|
||||||
|
int32_t colNum = c->numOfColumns + c->numOfTags;
|
||||||
|
for (int32_t i = 0; i < colNum; ++i) {
|
||||||
|
SSchema *s = &p->schema[i];
|
||||||
|
ctgDebug("[%d] name:%s, type:%d, colId:%d, bytes:%d", i, s->name, s->type, s->colId, s->bytes);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void ctgDbgShowDBCache(SCatalog* pCtg, SHashObj *dbHash) {
|
||||||
|
if (NULL == dbHash || !gCTGDebug.cacheDebug) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -163,9 +190,24 @@ void ctgDbgShowDBCache(SHashObj *dbHash) {
|
||||||
|
|
||||||
dbCache = (SCtgDBCache *)pIter;
|
dbCache = (SCtgDBCache *)pIter;
|
||||||
|
|
||||||
taosHashGetKey(dbCache, (void **)&dbFName, &len);
|
taosHashGetKey((void **)&dbFName, &len);
|
||||||
|
|
||||||
CTG_CACHE_DEBUG("** %dth db [%.*s][%"PRIx64"] **", i, (int32_t)len, dbFName, dbCache->dbId);
|
int32_t metaNum = dbCache->tbCache.metaCache ? taosHashGetSize(dbCache->tbCache.metaCache) : 0;
|
||||||
|
int32_t stbNum = dbCache->tbCache.stbCache ? taosHashGetSize(dbCache->tbCache.stbCache) : 0;
|
||||||
|
int32_t vgVersion = CTG_DEFAULT_INVALID_VERSION;
|
||||||
|
int32_t hashMethod = -1;
|
||||||
|
int32_t vgNum = 0;
|
||||||
|
|
||||||
|
if (dbCache->vgInfo) {
|
||||||
|
vgVersion = dbCache->vgInfo->vgVersion;
|
||||||
|
hashMethod = dbCache->vgInfo->hashMethod;
|
||||||
|
if (dbCache->vgInfo->vgHash) {
|
||||||
|
vgNum = taosHashGetSize(dbCache->vgInfo->vgHash);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
ctgDebug("[%d] db [%.*s][%"PRIx64"] %s: metaNum:%d, stbNum:%d, vgVersion:%d, hashMethod:%d, vgNum:%d",
|
||||||
|
i, (int32_t)len, dbFName, dbCache->dbId, dbCache->deleted?"deleted":"", metaNum, stbNum, vgVersion, hashMethod, vgNum);
|
||||||
|
|
||||||
pIter = taosHashIterate(dbHash, pIter);
|
pIter = taosHashIterate(dbHash, pIter);
|
||||||
}
|
}
|
||||||
|
@ -175,15 +217,15 @@ void ctgDbgShowDBCache(SHashObj *dbHash) {
|
||||||
|
|
||||||
|
|
||||||
void ctgDbgShowClusterCache(SCatalog* pCtg) {
|
void ctgDbgShowClusterCache(SCatalog* pCtg) {
|
||||||
if (NULL == pCtg) {
|
if (!gCTGDebug.cacheDebug || NULL == pCtg) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
CTG_CACHE_DEBUG("## cluster %"PRIx64" %p cache Info ##", pCtg->clusterId, pCtg);
|
ctgDebug("## cluster %"PRIx64" %p cache Info ##", pCtg->clusterId, pCtg);
|
||||||
CTG_CACHE_DEBUG("db:%d meta:%d stb:%d dbRent:%d stbRent:%d", ctgDbgGetClusterCacheNum(pCtg, CTG_DBG_DB_NUM), ctgDbgGetClusterCacheNum(pCtg, CTG_DBG_META_NUM),
|
ctgDebug("db:%d meta:%d stb:%d dbRent:%d stbRent:%d", ctgDbgGetClusterCacheNum(pCtg, CTG_DBG_DB_NUM), ctgDbgGetClusterCacheNum(pCtg, CTG_DBG_META_NUM),
|
||||||
ctgDbgGetClusterCacheNum(pCtg, CTG_DBG_STB_NUM), ctgDbgGetClusterCacheNum(pCtg, CTG_DBG_DB_RENT_NUM), ctgDbgGetClusterCacheNum(pCtg, CTG_DBG_STB_RENT_NUM));
|
ctgDbgGetClusterCacheNum(pCtg, CTG_DBG_STB_NUM), ctgDbgGetClusterCacheNum(pCtg, CTG_DBG_DB_RENT_NUM), ctgDbgGetClusterCacheNum(pCtg, CTG_DBG_STB_RENT_NUM));
|
||||||
|
|
||||||
ctgDbgShowDBCache(pCtg->dbCache);
|
ctgDbgShowDBCache(pCtg, pCtg->dbCache);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -242,6 +284,94 @@ void ctgFreeMetaRent(SCtgRentMgmt *mgmt) {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
int32_t ctgPushRmDBMsgInQueue(SCatalog* pCtg, const char *dbFName, int64_t dbId) {
|
||||||
|
int32_t code = 0;
|
||||||
|
SCtgMetaAction action= {.act = CTG_ACT_REMOVE_DB};
|
||||||
|
SCtgRemoveDBMsg *msg = malloc(sizeof(SCtgRemoveDBMsg));
|
||||||
|
if (NULL == msg) {
|
||||||
|
ctgError("malloc %d failed", (int32_t)sizeof(SCtgRemoveDBMsg));
|
||||||
|
CTG_ERR_RET(TSDB_CODE_CTG_MEM_ERROR);
|
||||||
|
}
|
||||||
|
|
||||||
|
msg->pCtg = pCtg;
|
||||||
|
strncpy(msg->dbFName, dbFName, sizeof(msg->dbFName));
|
||||||
|
msg->dbId = dbId;
|
||||||
|
|
||||||
|
action.data = msg;
|
||||||
|
|
||||||
|
CTG_ERR_JRET(ctgPushAction(&action));
|
||||||
|
|
||||||
|
ctgDebug("action [%s] added into queue", gCtgAction[action.act].name);
|
||||||
|
|
||||||
|
return TSDB_CODE_SUCCESS;
|
||||||
|
|
||||||
|
_return:
|
||||||
|
|
||||||
|
tfree(action.data);
|
||||||
|
CTG_RET(code);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
int32_t ctgPushRmStbMsgInQueue(SCatalog* pCtg, const char *dbFName, int64_t dbId, const char *stbName, uint64_t suid) {
|
||||||
|
int32_t code = 0;
|
||||||
|
SCtgMetaAction action= {.act = CTG_ACT_REMOVE_STB};
|
||||||
|
SCtgRemoveStbMsg *msg = malloc(sizeof(SCtgRemoveStbMsg));
|
||||||
|
if (NULL == msg) {
|
||||||
|
ctgError("malloc %d failed", (int32_t)sizeof(SCtgRemoveStbMsg));
|
||||||
|
CTG_ERR_RET(TSDB_CODE_CTG_MEM_ERROR);
|
||||||
|
}
|
||||||
|
|
||||||
|
msg->pCtg = pCtg;
|
||||||
|
strncpy(msg->dbFName, dbFName, sizeof(msg->dbFName));
|
||||||
|
strncpy(msg->stbName, stbName, sizeof(msg->stbName));
|
||||||
|
msg->dbId = dbId;
|
||||||
|
msg->suid = suid;
|
||||||
|
|
||||||
|
action.data = msg;
|
||||||
|
|
||||||
|
CTG_ERR_JRET(ctgPushAction(&action));
|
||||||
|
|
||||||
|
ctgDebug("action [%s] added into queue", gCtgAction[action.act].name);
|
||||||
|
|
||||||
|
return TSDB_CODE_SUCCESS;
|
||||||
|
|
||||||
|
_return:
|
||||||
|
|
||||||
|
tfree(action.data);
|
||||||
|
CTG_RET(code);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
int32_t ctgPushRmTblMsgInQueue(SCatalog* pCtg, const char *dbFName, int64_t dbId, const char *tbName) {
|
||||||
|
int32_t code = 0;
|
||||||
|
SCtgMetaAction action= {.act = CTG_ACT_REMOVE_TBL};
|
||||||
|
SCtgRemoveTblMsg *msg = malloc(sizeof(SCtgRemoveTblMsg));
|
||||||
|
if (NULL == msg) {
|
||||||
|
ctgError("malloc %d failed", (int32_t)sizeof(SCtgRemoveTblMsg));
|
||||||
|
CTG_ERR_RET(TSDB_CODE_CTG_MEM_ERROR);
|
||||||
|
}
|
||||||
|
|
||||||
|
msg->pCtg = pCtg;
|
||||||
|
strncpy(msg->dbFName, dbFName, sizeof(msg->dbFName));
|
||||||
|
strncpy(msg->tbName, tbName, sizeof(msg->tbName));
|
||||||
|
msg->dbId = dbId;
|
||||||
|
|
||||||
|
action.data = msg;
|
||||||
|
|
||||||
|
CTG_ERR_JRET(ctgPushAction(&action));
|
||||||
|
|
||||||
|
ctgDebug("action [%s] added into queue", gCtgAction[action.act].name);
|
||||||
|
|
||||||
|
return TSDB_CODE_SUCCESS;
|
||||||
|
|
||||||
|
_return:
|
||||||
|
|
||||||
|
tfree(action.data);
|
||||||
|
CTG_RET(code);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void ctgFreeTableMetaCache(SCtgTbMetaCache *cache) {
|
void ctgFreeTableMetaCache(SCtgTbMetaCache *cache) {
|
||||||
CTG_LOCK(CTG_WRITE, &cache->stbLock);
|
CTG_LOCK(CTG_WRITE, &cache->stbLock);
|
||||||
if (cache->stbCache) {
|
if (cache->stbCache) {
|
||||||
|
@ -452,12 +582,7 @@ int32_t ctgGetDBVgInfoFromMnode(SCatalog* pCtg, void *pRpc, const SEpSet* pMgmtE
|
||||||
|
|
||||||
rpcSendRecv(pRpc, (SEpSet*)pMgmtEps, &rpcMsg, &rpcRsp);
|
rpcSendRecv(pRpc, (SEpSet*)pMgmtEps, &rpcMsg, &rpcRsp);
|
||||||
if (TSDB_CODE_SUCCESS != rpcRsp.code) {
|
if (TSDB_CODE_SUCCESS != rpcRsp.code) {
|
||||||
if (CTG_DB_NOT_EXIST(rpcRsp.code)) {
|
ctgError("error rsp for use db, error:%s, db:%s", tstrerror(rpcRsp.code), input->db);
|
||||||
ctgDebug("db not exist in mnode, dbFName:%s", input->db);
|
|
||||||
return rpcRsp.code;
|
|
||||||
}
|
|
||||||
|
|
||||||
ctgError("error rsp for use db, code:%s, db:%s", tstrerror(rpcRsp.code), input->db);
|
|
||||||
CTG_ERR_RET(rpcRsp.code);
|
CTG_ERR_RET(rpcRsp.code);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -509,7 +634,7 @@ int32_t ctgIsTableMetaExistInCache(SCatalog* pCtg, char *dbFName, char* tbName,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int32_t ctgGetTableMetaFromCache(SCatalog* pCtg, const SName* pTableName, STableMeta** pTableMeta, int32_t *exist, int32_t flag) {
|
int32_t ctgGetTableMetaFromCache(SCatalog* pCtg, const SName* pTableName, STableMeta** pTableMeta, int32_t *exist, int32_t flag, uint64_t *dbId) {
|
||||||
if (NULL == pCtg->dbCache) {
|
if (NULL == pCtg->dbCache) {
|
||||||
*exist = 0;
|
*exist = 0;
|
||||||
ctgWarn("empty tbmeta cache, tbName:%s", pTableName->tname);
|
ctgWarn("empty tbmeta cache, tbName:%s", pTableName->tname);
|
||||||
|
@ -517,7 +642,7 @@ int32_t ctgGetTableMetaFromCache(SCatalog* pCtg, const SName* pTableName, STable
|
||||||
}
|
}
|
||||||
|
|
||||||
char dbFName[TSDB_DB_FNAME_LEN] = {0};
|
char dbFName[TSDB_DB_FNAME_LEN] = {0};
|
||||||
if (CTG_IS_INF_DB(flag)) {
|
if (CTG_FLAG_IS_INF_DB(flag)) {
|
||||||
strcpy(dbFName, pTableName->dbname);
|
strcpy(dbFName, pTableName->dbname);
|
||||||
} else {
|
} else {
|
||||||
tNameGetFullDbName(pTableName, dbFName);
|
tNameGetFullDbName(pTableName, dbFName);
|
||||||
|
@ -532,9 +657,9 @@ int32_t ctgGetTableMetaFromCache(SCatalog* pCtg, const SName* pTableName, STable
|
||||||
return TSDB_CODE_SUCCESS;
|
return TSDB_CODE_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t sz = 0;
|
int32_t sz = 0;
|
||||||
CTG_LOCK(CTG_READ, &dbCache->tbCache.metaLock);
|
CTG_LOCK(CTG_READ, &dbCache->tbCache.metaLock);
|
||||||
STableMeta *tbMeta = taosHashGetCloneExt(dbCache->tbCache.metaCache, pTableName->tname, strlen(pTableName->tname), NULL, (void **)pTableMeta, &sz);
|
int32_t code = taosHashGetDup_m(dbCache->tbCache.metaCache, pTableName->tname, strlen(pTableName->tname), (void **)pTableMeta, &sz);
|
||||||
CTG_UNLOCK(CTG_READ, &dbCache->tbCache.metaLock);
|
CTG_UNLOCK(CTG_READ, &dbCache->tbCache.metaLock);
|
||||||
|
|
||||||
if (NULL == *pTableMeta) {
|
if (NULL == *pTableMeta) {
|
||||||
|
@ -545,8 +670,11 @@ int32_t ctgGetTableMetaFromCache(SCatalog* pCtg, const SName* pTableName, STable
|
||||||
}
|
}
|
||||||
|
|
||||||
*exist = 1;
|
*exist = 1;
|
||||||
|
if (dbId) {
|
||||||
|
*dbId = dbCache->dbId;
|
||||||
|
}
|
||||||
|
|
||||||
tbMeta = *pTableMeta;
|
STableMeta* tbMeta = *pTableMeta;
|
||||||
|
|
||||||
if (tbMeta->tableType != TSDB_CHILD_TABLE) {
|
if (tbMeta->tableType != TSDB_CHILD_TABLE) {
|
||||||
ctgReleaseDBCache(pCtg, dbCache);
|
ctgReleaseDBCache(pCtg, dbCache);
|
||||||
|
@ -601,7 +729,7 @@ int32_t ctgGetTableTypeFromCache(SCatalog* pCtg, const SName* pTableName, int32_
|
||||||
}
|
}
|
||||||
|
|
||||||
char dbFName[TSDB_DB_FNAME_LEN] = {0};
|
char dbFName[TSDB_DB_FNAME_LEN] = {0};
|
||||||
if (CTG_IS_INF_DB(flag)) {
|
if (CTG_FLAG_IS_INF_DB(flag)) {
|
||||||
strcpy(dbFName, pTableName->dbname);
|
strcpy(dbFName, pTableName->dbname);
|
||||||
} else {
|
} else {
|
||||||
tNameGetFullDbName(pTableName, dbFName);
|
tNameGetFullDbName(pTableName, dbFName);
|
||||||
|
@ -948,7 +1076,7 @@ _return:
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t ctgMetaRentRemove(SCtgRentMgmt *mgmt, int64_t id, __compar_fn_t compare) {
|
int32_t ctgMetaRentRemove(SCtgRentMgmt *mgmt, int64_t id, __compar_fn_t compare) {
|
||||||
int16_t widx = abs(id % mgmt->slotNum);
|
int16_t widx = labs(id % mgmt->slotNum);
|
||||||
|
|
||||||
SCtgRentSlot *slot = &mgmt->slots[widx];
|
SCtgRentSlot *slot = &mgmt->slots[widx];
|
||||||
int32_t code = 0;
|
int32_t code = 0;
|
||||||
|
@ -1110,7 +1238,7 @@ void ctgRemoveStbRent(SCatalog* pCtg, SCtgTbMetaCache *cache) {
|
||||||
void *pIter = taosHashIterate(cache->stbCache, NULL);
|
void *pIter = taosHashIterate(cache->stbCache, NULL);
|
||||||
while (pIter) {
|
while (pIter) {
|
||||||
uint64_t *suid = NULL;
|
uint64_t *suid = NULL;
|
||||||
taosHashGetKey(pIter, (void **)&suid, NULL);
|
suid = taosHashGetKey(pIter, NULL);
|
||||||
|
|
||||||
if (TSDB_CODE_SUCCESS == ctgMetaRentRemove(&pCtg->stbRent, *suid, ctgStbVersionCompare)) {
|
if (TSDB_CODE_SUCCESS == ctgMetaRentRemove(&pCtg->stbRent, *suid, ctgStbVersionCompare)) {
|
||||||
ctgDebug("stb removed from rent, suid:%"PRIx64, *suid);
|
ctgDebug("stb removed from rent, suid:%"PRIx64, *suid);
|
||||||
|
@ -1259,9 +1387,9 @@ int32_t ctgUpdateTblMeta(SCatalog *pCtg, SCtgDBCache *dbCache, char *dbFName, ui
|
||||||
STableMeta *orig = taosHashGet(tbCache->metaCache, tbName, strlen(tbName));
|
STableMeta *orig = taosHashGet(tbCache->metaCache, tbName, strlen(tbName));
|
||||||
if (orig) {
|
if (orig) {
|
||||||
origType = orig->tableType;
|
origType = orig->tableType;
|
||||||
origSuid = orig->suid;
|
|
||||||
|
|
||||||
if (origType == TSDB_SUPER_TABLE && ((!isStb) || origSuid != meta->suid)) {
|
if (origType == TSDB_SUPER_TABLE) {
|
||||||
|
if ((!isStb) || orig->suid != meta->suid) {
|
||||||
CTG_LOCK(CTG_WRITE, &tbCache->stbLock);
|
CTG_LOCK(CTG_WRITE, &tbCache->stbLock);
|
||||||
if (taosHashRemove(tbCache->stbCache, &orig->suid, sizeof(orig->suid))) {
|
if (taosHashRemove(tbCache->stbCache, &orig->suid, sizeof(orig->suid))) {
|
||||||
ctgError("stb not exist in stbCache, dbFName:%s, stb:%s, suid:%"PRIx64, dbFName, tbName, orig->suid);
|
ctgError("stb not exist in stbCache, dbFName:%s, stb:%s, suid:%"PRIx64, dbFName, tbName, orig->suid);
|
||||||
|
@ -1272,6 +1400,9 @@ int32_t ctgUpdateTblMeta(SCatalog *pCtg, SCtgDBCache *dbCache, char *dbFName, ui
|
||||||
|
|
||||||
ctgMetaRentRemove(&pCtg->stbRent, orig->suid, ctgStbVersionCompare);
|
ctgMetaRentRemove(&pCtg->stbRent, orig->suid, ctgStbVersionCompare);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
origSuid = orig->suid;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isStb) {
|
if (isStb) {
|
||||||
|
@ -1289,13 +1420,14 @@ int32_t ctgUpdateTblMeta(SCatalog *pCtg, SCtgDBCache *dbCache, char *dbFName, ui
|
||||||
}
|
}
|
||||||
|
|
||||||
ctgDebug("tbmeta updated to cache, dbFName:%s, tbName:%s, tbType:%d", dbFName, tbName, meta->tableType);
|
ctgDebug("tbmeta updated to cache, dbFName:%s, tbName:%s, tbType:%d", dbFName, tbName, meta->tableType);
|
||||||
|
ctgDbgShowTableMeta(pCtg, tbName, meta);
|
||||||
|
|
||||||
if (!isStb) {
|
if (!isStb) {
|
||||||
CTG_UNLOCK(CTG_READ, &tbCache->metaLock);
|
CTG_UNLOCK(CTG_READ, &tbCache->metaLock);
|
||||||
return TSDB_CODE_SUCCESS;
|
return TSDB_CODE_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isStb && origSuid == meta->suid) {
|
if (origType == TSDB_SUPER_TABLE && origSuid == meta->suid) {
|
||||||
CTG_UNLOCK(CTG_WRITE, &tbCache->stbLock);
|
CTG_UNLOCK(CTG_WRITE, &tbCache->stbLock);
|
||||||
CTG_UNLOCK(CTG_READ, &tbCache->metaLock);
|
CTG_UNLOCK(CTG_READ, &tbCache->metaLock);
|
||||||
return TSDB_CODE_SUCCESS;
|
return TSDB_CODE_SUCCESS;
|
||||||
|
@ -1305,7 +1437,7 @@ int32_t ctgUpdateTblMeta(SCatalog *pCtg, SCtgDBCache *dbCache, char *dbFName, ui
|
||||||
if (taosHashPut(tbCache->stbCache, &meta->suid, sizeof(meta->suid), &tbMeta, POINTER_BYTES) != 0) {
|
if (taosHashPut(tbCache->stbCache, &meta->suid, sizeof(meta->suid), &tbMeta, POINTER_BYTES) != 0) {
|
||||||
CTG_UNLOCK(CTG_WRITE, &tbCache->stbLock);
|
CTG_UNLOCK(CTG_WRITE, &tbCache->stbLock);
|
||||||
CTG_UNLOCK(CTG_READ, &tbCache->metaLock);
|
CTG_UNLOCK(CTG_READ, &tbCache->metaLock);
|
||||||
ctgError("taosHashPutExt stable to stable cache failed, suid:%"PRIx64, meta->suid);
|
ctgError("taosHashPut stable to stable cache failed, suid:%"PRIx64, meta->suid);
|
||||||
CTG_ERR_RET(TSDB_CODE_CTG_MEM_ERROR);
|
CTG_ERR_RET(TSDB_CODE_CTG_MEM_ERROR);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1343,7 +1475,7 @@ int32_t ctgCloneVgInfo(SDBVgInfo *src, SDBVgInfo **dst) {
|
||||||
int32_t *vgId = NULL;
|
int32_t *vgId = NULL;
|
||||||
void *pIter = taosHashIterate(src->vgHash, NULL);
|
void *pIter = taosHashIterate(src->vgHash, NULL);
|
||||||
while (pIter) {
|
while (pIter) {
|
||||||
taosHashGetKey(pIter, (void **)&vgId, NULL);
|
vgId = taosHashGetKey(pIter, NULL);
|
||||||
|
|
||||||
if (taosHashPut((*dst)->vgHash, (void *)vgId, sizeof(int32_t), pIter, sizeof(SVgroupInfo))) {
|
if (taosHashPut((*dst)->vgHash, (void *)vgId, sizeof(int32_t), pIter, sizeof(SVgroupInfo))) {
|
||||||
qError("taosHashPut failed, hashSize:%d", (int32_t)hashSize);
|
qError("taosHashPut failed, hashSize:%d", (int32_t)hashSize);
|
||||||
|
@ -1365,20 +1497,33 @@ int32_t ctgCloneVgInfo(SDBVgInfo *src, SDBVgInfo **dst) {
|
||||||
int32_t ctgGetDBVgInfo(SCatalog* pCtg, void *pRpc, const SEpSet* pMgmtEps, const char* dbFName, bool forceUpdate, SCtgDBCache** dbCache, SDBVgInfo **pInfo) {
|
int32_t ctgGetDBVgInfo(SCatalog* pCtg, void *pRpc, const SEpSet* pMgmtEps, const char* dbFName, bool forceUpdate, SCtgDBCache** dbCache, SDBVgInfo **pInfo) {
|
||||||
bool inCache = false;
|
bool inCache = false;
|
||||||
int32_t code = 0;
|
int32_t code = 0;
|
||||||
if (!forceUpdate) {
|
|
||||||
CTG_ERR_RET(ctgAcquireVgInfoFromCache(pCtg, dbFName, dbCache, &inCache));
|
CTG_ERR_RET(ctgAcquireVgInfoFromCache(pCtg, dbFName, dbCache, &inCache));
|
||||||
if (inCache) {
|
|
||||||
|
if (inCache && !forceUpdate) {
|
||||||
return TSDB_CODE_SUCCESS;
|
return TSDB_CODE_SUCCESS;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
SUseDbOutput DbOut = {0};
|
SUseDbOutput DbOut = {0};
|
||||||
SBuildUseDBInput input = {0};
|
SBuildUseDBInput input = {0};
|
||||||
|
|
||||||
tstrncpy(input.db, dbFName, tListLen(input.db));
|
tstrncpy(input.db, dbFName, tListLen(input.db));
|
||||||
|
if (inCache) {
|
||||||
|
input.dbId = (*dbCache)->dbId;
|
||||||
|
input.vgVersion = (*dbCache)->vgInfo->vgVersion;
|
||||||
|
} else {
|
||||||
input.vgVersion = CTG_DEFAULT_INVALID_VERSION;
|
input.vgVersion = CTG_DEFAULT_INVALID_VERSION;
|
||||||
|
}
|
||||||
|
|
||||||
CTG_ERR_RET(ctgGetDBVgInfoFromMnode(pCtg, pRpc, pMgmtEps, &input, &DbOut));
|
code = ctgGetDBVgInfoFromMnode(pCtg, pRpc, pMgmtEps, &input, &DbOut);
|
||||||
|
if (code) {
|
||||||
|
if (CTG_DB_NOT_EXIST(code) && input.vgVersion > CTG_DEFAULT_INVALID_VERSION) {
|
||||||
|
ctgDebug("db no longer exist, dbFName:%s, dbId:%" PRIx64, input.db, input.dbId);
|
||||||
|
ctgPushRmDBMsgInQueue(pCtg, input.db, input.dbId);
|
||||||
|
}
|
||||||
|
|
||||||
|
CTG_ERR_RET(code);
|
||||||
|
}
|
||||||
|
|
||||||
CTG_ERR_JRET(ctgCloneVgInfo(DbOut.dbVgroup, pInfo));
|
CTG_ERR_JRET(ctgCloneVgInfo(DbOut.dbVgroup, pInfo));
|
||||||
|
|
||||||
|
@ -1448,7 +1593,7 @@ int32_t ctgRefreshTblMeta(SCatalog* pCtg, void *pTrans, const SEpSet* pMgmtEps,
|
||||||
SVgroupInfo vgroupInfo = {0};
|
SVgroupInfo vgroupInfo = {0};
|
||||||
int32_t code = 0;
|
int32_t code = 0;
|
||||||
|
|
||||||
if (!CTG_IS_INF_DB(flag)) {
|
if (!CTG_FLAG_IS_INF_DB(flag)) {
|
||||||
CTG_ERR_RET(catalogGetTableHashVgroup(pCtg, pTrans, pMgmtEps, pTableName, &vgroupInfo));
|
CTG_ERR_RET(catalogGetTableHashVgroup(pCtg, pTrans, pMgmtEps, pTableName, &vgroupInfo));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1460,11 +1605,11 @@ int32_t ctgRefreshTblMeta(SCatalog* pCtg, void *pTrans, const SEpSet* pMgmtEps,
|
||||||
CTG_ERR_RET(TSDB_CODE_CTG_MEM_ERROR);
|
CTG_ERR_RET(TSDB_CODE_CTG_MEM_ERROR);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (CTG_IS_INF_DB(flag)) {
|
if (CTG_FLAG_IS_INF_DB(flag)) {
|
||||||
ctgDebug("will refresh tbmeta, supposed in information_schema, tbName:%s", tNameGetTableName(pTableName));
|
ctgDebug("will refresh tbmeta, supposed in information_schema, tbName:%s", tNameGetTableName(pTableName));
|
||||||
|
|
||||||
CTG_ERR_JRET(ctgGetTableMetaFromMnodeImpl(pCtg, pTrans, pMgmtEps, (char *)pTableName->dbname, (char *)pTableName->tname, output));
|
CTG_ERR_JRET(ctgGetTableMetaFromMnodeImpl(pCtg, pTrans, pMgmtEps, (char *)pTableName->dbname, (char *)pTableName->tname, output));
|
||||||
} else if (CTG_IS_STB(flag)) {
|
} else if (CTG_FLAG_IS_STB(flag)) {
|
||||||
ctgDebug("will refresh tbmeta, supposed to be stb, tbName:%s", tNameGetTableName(pTableName));
|
ctgDebug("will refresh tbmeta, supposed to be stb, tbName:%s", tNameGetTableName(pTableName));
|
||||||
|
|
||||||
// if get from mnode failed, will not try vnode
|
// if get from mnode failed, will not try vnode
|
||||||
|
@ -1480,14 +1625,17 @@ int32_t ctgRefreshTblMeta(SCatalog* pCtg, void *pTrans, const SEpSet* pMgmtEps,
|
||||||
CTG_ERR_JRET(ctgGetTableMetaFromVnode(pCtg, pTrans, pMgmtEps, pTableName, &vgroupInfo, output));
|
CTG_ERR_JRET(ctgGetTableMetaFromVnode(pCtg, pTrans, pMgmtEps, pTableName, &vgroupInfo, output));
|
||||||
|
|
||||||
if (CTG_IS_META_TABLE(output->metaType) && TSDB_SUPER_TABLE == output->tbMeta->tableType) {
|
if (CTG_IS_META_TABLE(output->metaType) && TSDB_SUPER_TABLE == output->tbMeta->tableType) {
|
||||||
ctgDebug("will continue to refresh tbmeta since got stb, tbName:%s, metaType:%d", tNameGetTableName(pTableName), output->metaType);
|
ctgDebug("will continue to refresh tbmeta since got stb, tbName:%s", tNameGetTableName(pTableName));
|
||||||
|
|
||||||
tfree(output->tbMeta);
|
tfree(output->tbMeta);
|
||||||
|
|
||||||
CTG_ERR_JRET(ctgGetTableMetaFromMnodeImpl(pCtg, pTrans, pMgmtEps, output->dbFName, output->tbName, output));
|
CTG_ERR_JRET(ctgGetTableMetaFromMnodeImpl(pCtg, pTrans, pMgmtEps, output->dbFName, output->tbName, output));
|
||||||
} else if (CTG_IS_META_BOTH(output->metaType)) {
|
} else if (CTG_IS_META_BOTH(output->metaType)) {
|
||||||
int32_t exist = 0;
|
int32_t exist = 0;
|
||||||
|
if (!CTG_FLAG_IS_FORCE_UPDATE(flag)) {
|
||||||
CTG_ERR_JRET(ctgIsTableMetaExistInCache(pCtg, output->dbFName, output->tbName, &exist));
|
CTG_ERR_JRET(ctgIsTableMetaExistInCache(pCtg, output->dbFName, output->tbName, &exist));
|
||||||
|
}
|
||||||
|
|
||||||
if (0 == exist) {
|
if (0 == exist) {
|
||||||
CTG_ERR_JRET(ctgGetTableMetaFromMnodeImpl(pCtg, pTrans, pMgmtEps, output->dbFName, output->tbName, &moutput));
|
CTG_ERR_JRET(ctgGetTableMetaFromMnodeImpl(pCtg, pTrans, pMgmtEps, output->dbFName, output->tbName, &moutput));
|
||||||
|
|
||||||
|
@ -1548,35 +1696,40 @@ _return:
|
||||||
CTG_RET(code);
|
CTG_RET(code);
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t ctgGetTableMeta(SCatalog* pCtg, void *pRpc, const SEpSet* pMgmtEps, const SName* pTableName, bool forceUpdate, STableMeta** pTableMeta, int32_t flag) {
|
int32_t ctgGetTableMeta(SCatalog* pCtg, void *pRpc, const SEpSet* pMgmtEps, const SName* pTableName, STableMeta** pTableMeta, int32_t flag) {
|
||||||
if (NULL == pCtg || NULL == pRpc || NULL == pMgmtEps || NULL == pTableName || NULL == pTableMeta) {
|
if (NULL == pCtg || NULL == pRpc || NULL == pMgmtEps || NULL == pTableName || NULL == pTableMeta) {
|
||||||
CTG_ERR_RET(TSDB_CODE_CTG_INVALID_INPUT);
|
CTG_ERR_RET(TSDB_CODE_CTG_INVALID_INPUT);
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t exist = 0;
|
int32_t exist = 0;
|
||||||
int32_t code = 0;
|
int32_t code = 0;
|
||||||
|
uint64_t dbId = 0;
|
||||||
|
uint64_t suid = 0;
|
||||||
|
STableMetaOutput *output = NULL;
|
||||||
|
|
||||||
if (CTG_IS_INF_DBNAME(pTableName->dbname)) {
|
if (CTG_IS_INF_DBNAME(pTableName->dbname)) {
|
||||||
CTG_SET_INF_DB(flag);
|
CTG_FLAG_SET_INF_DB(flag);
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((!forceUpdate) || (CTG_IS_INF_DB(flag))) {
|
CTG_ERR_RET(ctgGetTableMetaFromCache(pCtg, pTableName, pTableMeta, &exist, flag, &dbId));
|
||||||
CTG_ERR_RET(ctgGetTableMetaFromCache(pCtg, pTableName, pTableMeta, &exist, flag));
|
|
||||||
|
|
||||||
if (exist && CTG_TBTYPE_MATCH(flag, (*pTableMeta)->tableType)) {
|
|
||||||
return TSDB_CODE_SUCCESS;
|
|
||||||
}
|
|
||||||
|
|
||||||
tfree(*pTableMeta);
|
|
||||||
} else if (CTG_IS_UNKNOWN_STB(flag)) {
|
|
||||||
int32_t tbType = 0;
|
int32_t tbType = 0;
|
||||||
|
|
||||||
CTG_ERR_RET(ctgGetTableTypeFromCache(pCtg, pTableName, &tbType, flag));
|
if (exist) {
|
||||||
|
if (CTG_FLAG_MATCH_STB(flag, (*pTableMeta)->tableType) && ((!CTG_FLAG_IS_FORCE_UPDATE(flag)) || (CTG_FLAG_IS_INF_DB(flag)))) {
|
||||||
CTG_SET_STB(flag, tbType);
|
goto _return;
|
||||||
|
}
|
||||||
|
|
||||||
|
tbType = (*pTableMeta)->tableType;
|
||||||
|
suid = (*pTableMeta)->suid;
|
||||||
|
|
||||||
|
tfree(*pTableMeta);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (CTG_FLAG_IS_UNKNOWN_STB(flag)) {
|
||||||
|
CTG_FLAG_SET_STB(flag, tbType);
|
||||||
}
|
}
|
||||||
|
|
||||||
STableMetaOutput *output = NULL;
|
|
||||||
|
|
||||||
while (true) {
|
while (true) {
|
||||||
CTG_ERR_JRET(ctgRefreshTblMeta(pCtg, pRpc, pMgmtEps, pTableName, flag, &output));
|
CTG_ERR_JRET(ctgRefreshTblMeta(pCtg, pRpc, pMgmtEps, pTableName, flag, &output));
|
||||||
|
@ -1604,7 +1757,7 @@ int32_t ctgGetTableMeta(SCatalog* pCtg, void *pRpc, const SEpSet* pMgmtEps, cons
|
||||||
SName stbName = *pTableName;
|
SName stbName = *pTableName;
|
||||||
strcpy(stbName.tname, output->tbName);
|
strcpy(stbName.tname, output->tbName);
|
||||||
|
|
||||||
CTG_ERR_JRET(ctgGetTableMetaFromCache(pCtg, &stbName, pTableMeta, &exist, flag));
|
CTG_ERR_JRET(ctgGetTableMetaFromCache(pCtg, &stbName, pTableMeta, &exist, flag, NULL));
|
||||||
if (0 == exist) {
|
if (0 == exist) {
|
||||||
ctgDebug("stb no longer exist, dbFName:%s, tbName:%s", output->dbFName, pTableName->tname);
|
ctgDebug("stb no longer exist, dbFName:%s, tbName:%s", output->dbFName, pTableName->tname);
|
||||||
continue;
|
continue;
|
||||||
|
@ -1617,10 +1770,26 @@ int32_t ctgGetTableMeta(SCatalog* pCtg, void *pRpc, const SEpSet* pMgmtEps, cons
|
||||||
|
|
||||||
_return:
|
_return:
|
||||||
|
|
||||||
|
if (CTG_TABLE_NOT_EXIST(code) && exist) {
|
||||||
|
char dbFName[TSDB_DB_FNAME_LEN] = {0};
|
||||||
|
if (CTG_FLAG_IS_INF_DB(flag)) {
|
||||||
|
strcpy(dbFName, pTableName->dbname);
|
||||||
|
} else {
|
||||||
|
tNameGetFullDbName(pTableName, dbFName);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (TSDB_SUPER_TABLE == tbType) {
|
||||||
|
ctgPushRmStbMsgInQueue(pCtg, dbFName, dbId, pTableName->tname, suid);
|
||||||
|
} else {
|
||||||
|
ctgPushRmTblMsgInQueue(pCtg, dbFName, dbId, pTableName->tname);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
tfree(output);
|
tfree(output);
|
||||||
|
|
||||||
if (*pTableMeta) {
|
if (*pTableMeta) {
|
||||||
ctgDebug("tbmeta returned, tbName:%s, tbType:%d", pTableName->tname, (*pTableMeta)->tableType);
|
ctgDebug("tbmeta returned, tbName:%s, tbType:%d", pTableName->tname, (*pTableMeta)->tableType);
|
||||||
|
ctgDbgShowTableMeta(pCtg, pTableName->tname, *pTableMeta);
|
||||||
}
|
}
|
||||||
|
|
||||||
CTG_RET(code);
|
CTG_RET(code);
|
||||||
|
@ -1636,7 +1805,7 @@ int32_t ctgActUpdateVg(SCtgMetaAction *action) {
|
||||||
|
|
||||||
_return:
|
_return:
|
||||||
|
|
||||||
tfree(msg->dbInfo);
|
ctgFreeVgInfo(msg->dbInfo);
|
||||||
tfree(msg);
|
tfree(msg);
|
||||||
|
|
||||||
CTG_RET(code);
|
CTG_RET(code);
|
||||||
|
@ -1722,7 +1891,6 @@ _return:
|
||||||
int32_t ctgActRemoveStb(SCtgMetaAction *action) {
|
int32_t ctgActRemoveStb(SCtgMetaAction *action) {
|
||||||
int32_t code = 0;
|
int32_t code = 0;
|
||||||
SCtgRemoveStbMsg *msg = action->data;
|
SCtgRemoveStbMsg *msg = action->data;
|
||||||
bool removed = false;
|
|
||||||
SCatalog* pCtg = msg->pCtg;
|
SCatalog* pCtg = msg->pCtg;
|
||||||
|
|
||||||
SCtgDBCache *dbCache = NULL;
|
SCtgDBCache *dbCache = NULL;
|
||||||
|
@ -1768,9 +1936,37 @@ _return:
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t ctgActRemoveTbl(SCtgMetaAction *action) {
|
int32_t ctgActRemoveTbl(SCtgMetaAction *action) {
|
||||||
|
int32_t code = 0;
|
||||||
|
SCtgRemoveTblMsg *msg = action->data;
|
||||||
|
SCatalog* pCtg = msg->pCtg;
|
||||||
|
|
||||||
|
SCtgDBCache *dbCache = NULL;
|
||||||
|
ctgGetDBCache(pCtg, msg->dbFName, &dbCache);
|
||||||
|
if (NULL == dbCache) {
|
||||||
|
return TSDB_CODE_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (dbCache->dbId != msg->dbId) {
|
||||||
|
ctgDebug("dbId already modified, dbFName:%s, current:%"PRIx64", dbId:%"PRIx64", tbName:%s", msg->dbFName, dbCache->dbId, msg->dbId, msg->tbName);
|
||||||
|
return TSDB_CODE_SUCCESS;
|
||||||
|
}
|
||||||
|
|
||||||
|
CTG_LOCK(CTG_READ, &dbCache->tbCache.metaLock);
|
||||||
|
if (taosHashRemove(dbCache->tbCache.metaCache, msg->tbName, strlen(msg->tbName))) {
|
||||||
|
CTG_UNLOCK(CTG_READ, &dbCache->tbCache.metaLock);
|
||||||
|
ctgError("stb not exist in cache, dbFName:%s, tbName:%s", msg->dbFName, msg->tbName);
|
||||||
|
CTG_ERR_RET(TSDB_CODE_CTG_INTERNAL_ERROR);
|
||||||
|
}
|
||||||
|
CTG_UNLOCK(CTG_READ, &dbCache->tbCache.metaLock);
|
||||||
|
|
||||||
|
ctgInfo("table removed from cache, dbFName:%s, tbName:%s", msg->dbFName, msg->tbName);
|
||||||
|
|
||||||
|
_return:
|
||||||
|
|
||||||
|
tfree(msg);
|
||||||
|
|
||||||
|
CTG_RET(code);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void* ctgUpdateThreadFunc(void* param) {
|
void* ctgUpdateThreadFunc(void* param) {
|
||||||
|
@ -1789,12 +1985,15 @@ void* ctgUpdateThreadFunc(void* param) {
|
||||||
|
|
||||||
SCtgMetaAction *action = NULL;
|
SCtgMetaAction *action = NULL;
|
||||||
ctgPopAction(&action);
|
ctgPopAction(&action);
|
||||||
|
SCatalog *pCtg = ((SCtgUpdateMsgHeader *)action->data)->pCtg;
|
||||||
|
|
||||||
qDebug("process %s action", gCtgAction[action->act].name);
|
ctgDebug("process [%s] action", gCtgAction[action->act].name);
|
||||||
|
|
||||||
(*gCtgAction[action->act].func)(action);
|
(*gCtgAction[action->act].func)(action);
|
||||||
|
|
||||||
CTG_STAT_ADD(gCtgMgmt.stat.runtime.qDoneNum);
|
CTG_STAT_ADD(gCtgMgmt.stat.runtime.qDoneNum);
|
||||||
|
|
||||||
|
ctgDbgShowClusterCache(pCtg);
|
||||||
}
|
}
|
||||||
|
|
||||||
CTG_UNLOCK(CTG_READ, &gCtgMgmt.lock);
|
CTG_UNLOCK(CTG_READ, &gCtgMgmt.lock);
|
||||||
|
@ -1964,10 +2163,10 @@ void catalogFreeHandle(SCatalog* pCtg) {
|
||||||
ctgInfo("handle freed, culsterId:%"PRIx64, clusterId);
|
ctgInfo("handle freed, culsterId:%"PRIx64, clusterId);
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t catalogGetDBVgVersion(SCatalog* pCtg, const char* dbFName, int32_t* version) {
|
int32_t catalogGetDBVgVersion(SCatalog* pCtg, const char* dbFName, int32_t* version, int64_t* dbId) {
|
||||||
CTG_API_ENTER();
|
CTG_API_ENTER();
|
||||||
|
|
||||||
if (NULL == pCtg || NULL == dbFName || NULL == version) {
|
if (NULL == pCtg || NULL == dbFName || NULL == version || NULL == dbId) {
|
||||||
CTG_API_LEAVE(TSDB_CODE_CTG_INVALID_INPUT);
|
CTG_API_LEAVE(TSDB_CODE_CTG_INVALID_INPUT);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1994,6 +2193,7 @@ int32_t catalogGetDBVgVersion(SCatalog* pCtg, const char* dbFName, int32_t* vers
|
||||||
}
|
}
|
||||||
|
|
||||||
*version = dbCache->vgInfo->vgVersion;
|
*version = dbCache->vgInfo->vgVersion;
|
||||||
|
*dbId = dbCache->dbId;
|
||||||
|
|
||||||
ctgReleaseVgInfo(dbCache);
|
ctgReleaseVgInfo(dbCache);
|
||||||
ctgReleaseDBCache(pCtg, dbCache);
|
ctgReleaseDBCache(pCtg, dbCache);
|
||||||
|
@ -2063,22 +2263,20 @@ int32_t catalogUpdateDBVgInfo(SCatalog* pCtg, const char* dbFName, uint64_t dbId
|
||||||
strncpy(msg->dbFName, dbFName, sizeof(msg->dbFName));
|
strncpy(msg->dbFName, dbFName, sizeof(msg->dbFName));
|
||||||
msg->dbId = dbId;
|
msg->dbId = dbId;
|
||||||
msg->dbInfo = dbInfo;
|
msg->dbInfo = dbInfo;
|
||||||
dbInfo = NULL;
|
|
||||||
|
|
||||||
action.data = msg;
|
action.data = msg;
|
||||||
|
|
||||||
CTG_ERR_JRET(ctgPushAction(&action));
|
CTG_ERR_JRET(ctgPushAction(&action));
|
||||||
|
|
||||||
|
dbInfo = NULL;
|
||||||
|
|
||||||
ctgDebug("action [%s] added into queue", gCtgAction[action.act].name);
|
ctgDebug("action [%s] added into queue", gCtgAction[action.act].name);
|
||||||
|
|
||||||
CTG_API_LEAVE(code);
|
CTG_API_LEAVE(code);
|
||||||
|
|
||||||
_return:
|
_return:
|
||||||
|
|
||||||
if (dbInfo) {
|
ctgFreeVgInfo(dbInfo);
|
||||||
taosHashCleanup(dbInfo->vgHash);
|
|
||||||
tfree(dbInfo);
|
|
||||||
}
|
|
||||||
|
|
||||||
tfree(msg);
|
tfree(msg);
|
||||||
|
|
||||||
|
@ -2099,29 +2297,12 @@ int32_t catalogRemoveDB(SCatalog* pCtg, const char* dbFName, uint64_t dbId) {
|
||||||
CTG_API_LEAVE(TSDB_CODE_SUCCESS);
|
CTG_API_LEAVE(TSDB_CODE_SUCCESS);
|
||||||
}
|
}
|
||||||
|
|
||||||
SCtgMetaAction action= {.act = CTG_ACT_REMOVE_DB};
|
CTG_ERR_JRET(ctgPushRmDBMsgInQueue(pCtg, dbFName, dbId));
|
||||||
SCtgRemoveDBMsg *msg = malloc(sizeof(SCtgRemoveDBMsg));
|
|
||||||
if (NULL == msg) {
|
|
||||||
ctgError("malloc %d failed", (int32_t)sizeof(SCtgRemoveDBMsg));
|
|
||||||
CTG_API_LEAVE(TSDB_CODE_CTG_MEM_ERROR);
|
|
||||||
}
|
|
||||||
|
|
||||||
msg->pCtg = pCtg;
|
|
||||||
strncpy(msg->dbFName, dbFName, sizeof(msg->dbFName));
|
|
||||||
msg->dbId = dbId;
|
|
||||||
|
|
||||||
action.data = msg;
|
|
||||||
|
|
||||||
CTG_ERR_JRET(ctgPushAction(&action));
|
|
||||||
|
|
||||||
ctgDebug("action [%s] added into queue", gCtgAction[action.act].name);
|
|
||||||
|
|
||||||
CTG_API_LEAVE(TSDB_CODE_SUCCESS);
|
CTG_API_LEAVE(TSDB_CODE_SUCCESS);
|
||||||
|
|
||||||
_return:
|
_return:
|
||||||
|
|
||||||
tfree(action.data);
|
|
||||||
|
|
||||||
CTG_API_LEAVE(code);
|
CTG_API_LEAVE(code);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2138,31 +2319,12 @@ int32_t catalogRemoveStbMeta(SCatalog* pCtg, const char* dbFName, uint64_t dbId,
|
||||||
CTG_API_LEAVE(TSDB_CODE_SUCCESS);
|
CTG_API_LEAVE(TSDB_CODE_SUCCESS);
|
||||||
}
|
}
|
||||||
|
|
||||||
SCtgMetaAction action= {.act = CTG_ACT_REMOVE_STB};
|
CTG_ERR_JRET(ctgPushRmStbMsgInQueue(pCtg, dbFName, dbId, stbName, suid));
|
||||||
SCtgRemoveStbMsg *msg = malloc(sizeof(SCtgRemoveStbMsg));
|
|
||||||
if (NULL == msg) {
|
|
||||||
ctgError("malloc %d failed", (int32_t)sizeof(SCtgRemoveStbMsg));
|
|
||||||
CTG_API_LEAVE(TSDB_CODE_CTG_MEM_ERROR);
|
|
||||||
}
|
|
||||||
|
|
||||||
msg->pCtg = pCtg;
|
|
||||||
strncpy(msg->dbFName, dbFName, sizeof(msg->dbFName));
|
|
||||||
strncpy(msg->stbName, stbName, sizeof(msg->stbName));
|
|
||||||
msg->dbId = dbId;
|
|
||||||
msg->suid = suid;
|
|
||||||
|
|
||||||
action.data = msg;
|
|
||||||
|
|
||||||
CTG_ERR_JRET(ctgPushAction(&action));
|
|
||||||
|
|
||||||
ctgDebug("action [%s] added into queue", gCtgAction[action.act].name);
|
|
||||||
|
|
||||||
CTG_API_LEAVE(TSDB_CODE_SUCCESS);
|
CTG_API_LEAVE(TSDB_CODE_SUCCESS);
|
||||||
|
|
||||||
_return:
|
_return:
|
||||||
|
|
||||||
tfree(action.data);
|
|
||||||
|
|
||||||
CTG_API_LEAVE(code);
|
CTG_API_LEAVE(code);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2170,13 +2332,13 @@ _return:
|
||||||
int32_t catalogGetTableMeta(SCatalog* pCtg, void *pTrans, const SEpSet* pMgmtEps, const SName* pTableName, STableMeta** pTableMeta) {
|
int32_t catalogGetTableMeta(SCatalog* pCtg, void *pTrans, const SEpSet* pMgmtEps, const SName* pTableName, STableMeta** pTableMeta) {
|
||||||
CTG_API_ENTER();
|
CTG_API_ENTER();
|
||||||
|
|
||||||
CTG_API_LEAVE(ctgGetTableMeta(pCtg, pTrans, pMgmtEps, pTableName, false, pTableMeta, CTG_FLAG_UNKNOWN_STB));
|
CTG_API_LEAVE(ctgGetTableMeta(pCtg, pTrans, pMgmtEps, pTableName, pTableMeta, CTG_FLAG_UNKNOWN_STB));
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t catalogGetSTableMeta(SCatalog* pCtg, void * pTrans, const SEpSet* pMgmtEps, const SName* pTableName, STableMeta** pTableMeta) {
|
int32_t catalogGetSTableMeta(SCatalog* pCtg, void * pTrans, const SEpSet* pMgmtEps, const SName* pTableName, STableMeta** pTableMeta) {
|
||||||
CTG_API_ENTER();
|
CTG_API_ENTER();
|
||||||
|
|
||||||
CTG_API_LEAVE(ctgGetTableMeta(pCtg, pTrans, pMgmtEps, pTableName, false, pTableMeta, CTG_FLAG_STB));
|
CTG_API_LEAVE(ctgGetTableMeta(pCtg, pTrans, pMgmtEps, pTableName, pTableMeta, CTG_FLAG_STB));
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t catalogUpdateSTableMeta(SCatalog* pCtg, STableMetaRsp *rspMsg) {
|
int32_t catalogUpdateSTableMeta(SCatalog* pCtg, STableMetaRsp *rspMsg) {
|
||||||
|
@ -2238,13 +2400,13 @@ int32_t catalogRefreshTableMeta(SCatalog* pCtg, void *pTrans, const SEpSet* pMgm
|
||||||
CTG_API_LEAVE(TSDB_CODE_CTG_INVALID_INPUT);
|
CTG_API_LEAVE(TSDB_CODE_CTG_INVALID_INPUT);
|
||||||
}
|
}
|
||||||
|
|
||||||
CTG_API_LEAVE(ctgRefreshTblMeta(pCtg, pTrans, pMgmtEps, pTableName, CTG_GEN_STB_FLAG(isSTable), NULL));
|
CTG_API_LEAVE(ctgRefreshTblMeta(pCtg, pTrans, pMgmtEps, pTableName, CTG_FLAG_FORCE_UPDATE | CTG_FLAG_MAKE_STB(isSTable), NULL));
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t catalogRefreshGetTableMeta(SCatalog* pCtg, void *pTrans, const SEpSet* pMgmtEps, const SName* pTableName, STableMeta** pTableMeta, int32_t isSTable) {
|
int32_t catalogRefreshGetTableMeta(SCatalog* pCtg, void *pTrans, const SEpSet* pMgmtEps, const SName* pTableName, STableMeta** pTableMeta, int32_t isSTable) {
|
||||||
CTG_API_ENTER();
|
CTG_API_ENTER();
|
||||||
|
|
||||||
CTG_API_LEAVE(ctgGetTableMeta(pCtg, pTrans, pMgmtEps, pTableName, true, pTableMeta, CTG_GEN_STB_FLAG(isSTable)));
|
CTG_API_LEAVE(ctgGetTableMeta(pCtg, pTrans, pMgmtEps, pTableName, pTableMeta, CTG_FLAG_FORCE_UPDATE | CTG_FLAG_MAKE_STB(isSTable)));
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t catalogGetTableDistVgInfo(SCatalog* pCtg, void *pRpc, const SEpSet* pMgmtEps, const SName* pTableName, SArray** pVgList) {
|
int32_t catalogGetTableDistVgInfo(SCatalog* pCtg, void *pRpc, const SEpSet* pMgmtEps, const SName* pTableName, SArray** pVgList) {
|
||||||
|
@ -2268,7 +2430,7 @@ int32_t catalogGetTableDistVgInfo(SCatalog* pCtg, void *pRpc, const SEpSet* pMgm
|
||||||
|
|
||||||
*pVgList = NULL;
|
*pVgList = NULL;
|
||||||
|
|
||||||
CTG_ERR_JRET(ctgGetTableMeta(pCtg, pRpc, pMgmtEps, pTableName, false, &tbMeta, CTG_FLAG_UNKNOWN_STB));
|
CTG_ERR_JRET(ctgGetTableMeta(pCtg, pRpc, pMgmtEps, pTableName, &tbMeta, CTG_FLAG_UNKNOWN_STB));
|
||||||
|
|
||||||
char db[TSDB_DB_FNAME_LEN] = {0};
|
char db[TSDB_DB_FNAME_LEN] = {0};
|
||||||
tNameGetFullDbName(pTableName, db);
|
tNameGetFullDbName(pTableName, db);
|
||||||
|
@ -2296,7 +2458,7 @@ int32_t catalogGetTableDistVgInfo(SCatalog* pCtg, void *pRpc, const SEpSet* pMgm
|
||||||
CTG_ERR_JRET(ctgGenerateVgList(pCtg, vgHash, pVgList));
|
CTG_ERR_JRET(ctgGenerateVgList(pCtg, vgHash, pVgList));
|
||||||
} else {
|
} else {
|
||||||
int32_t vgId = tbMeta->vgId;
|
int32_t vgId = tbMeta->vgId;
|
||||||
if (NULL == taosHashGetClone(vgHash, &vgId, sizeof(vgId), &vgroupInfo)) {
|
if (taosHashGetDup(vgHash, &vgId, sizeof(vgId), &vgroupInfo) != 0) {
|
||||||
ctgError("table's vgId not found in vgroup list, vgId:%d, tbName:%s", vgId, tNameGetTableName(pTableName));
|
ctgError("table's vgId not found in vgroup list, vgId:%d, tbName:%s", vgId, tNameGetTableName(pTableName));
|
||||||
CTG_ERR_JRET(TSDB_CODE_CTG_INTERNAL_ERROR);
|
CTG_ERR_JRET(TSDB_CODE_CTG_INTERNAL_ERROR);
|
||||||
}
|
}
|
||||||
|
@ -2400,7 +2562,7 @@ int32_t catalogGetAllMeta(SCatalog* pCtg, void *pTrans, const SEpSet* pMgmtEps,
|
||||||
SName *name = taosArrayGet(pReq->pTableName, i);
|
SName *name = taosArrayGet(pReq->pTableName, i);
|
||||||
STableMeta *pTableMeta = NULL;
|
STableMeta *pTableMeta = NULL;
|
||||||
|
|
||||||
CTG_ERR_JRET(ctgGetTableMeta(pCtg, pTrans, pMgmtEps, name, false, &pTableMeta, CTG_FLAG_UNKNOWN_STB));
|
CTG_ERR_JRET(ctgGetTableMeta(pCtg, pTrans, pMgmtEps, name, &pTableMeta, CTG_FLAG_UNKNOWN_STB));
|
||||||
|
|
||||||
if (NULL == taosArrayPush(pRsp->pTableMeta, &pTableMeta)) {
|
if (NULL == taosArrayPush(pRsp->pTableMeta, &pTableMeta)) {
|
||||||
ctgError("taosArrayPush failed, idx:%d", i);
|
ctgError("taosArrayPush failed, idx:%d", i);
|
||||||
|
|
|
@ -14,9 +14,7 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <gtest/gtest.h>
|
#include <gtest/gtest.h>
|
||||||
#include <tglobal.h>
|
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include "os.h"
|
|
||||||
|
|
||||||
#pragma GCC diagnostic push
|
#pragma GCC diagnostic push
|
||||||
#pragma GCC diagnostic ignored "-Wwrite-strings"
|
#pragma GCC diagnostic ignored "-Wwrite-strings"
|
||||||
|
@ -24,21 +22,23 @@
|
||||||
#pragma GCC diagnostic ignored "-Wunused-variable"
|
#pragma GCC diagnostic ignored "-Wunused-variable"
|
||||||
#pragma GCC diagnostic ignored "-Wsign-compare"
|
#pragma GCC diagnostic ignored "-Wsign-compare"
|
||||||
#pragma GCC diagnostic ignored "-Wformat"
|
#pragma GCC diagnostic ignored "-Wformat"
|
||||||
|
#include <addr_any.h>
|
||||||
|
|
||||||
#include "addr_any.h"
|
#include "os.h"
|
||||||
|
#include "tglobal.h"
|
||||||
#include "catalog.h"
|
#include "catalog.h"
|
||||||
|
#include "catalogInt.h"
|
||||||
#include "stub.h"
|
#include "stub.h"
|
||||||
#include "taos.h"
|
#include "taos.h"
|
||||||
|
#include "tdatablock.h"
|
||||||
#include "tdef.h"
|
#include "tdef.h"
|
||||||
#include "tep.h"
|
|
||||||
#include "trpc.h"
|
#include "trpc.h"
|
||||||
#include "tvariant.h"
|
#include "tvariant.h"
|
||||||
#include "catalogInt.h"
|
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
|
|
||||||
extern "C" int32_t ctgGetTableMetaFromCache(struct SCatalog *pCatalog, const SName *pTableName, STableMeta **pTableMeta,
|
extern "C" int32_t ctgGetTableMetaFromCache(struct SCatalog *pCatalog, const SName *pTableName, STableMeta **pTableMeta,
|
||||||
int32_t *exist, int32_t flag);
|
int32_t *exist, int32_t flag, uint64_t *dbId);
|
||||||
extern "C" int32_t ctgDbgGetClusterCacheNum(struct SCatalog* pCatalog, int32_t type);
|
extern "C" int32_t ctgDbgGetClusterCacheNum(struct SCatalog* pCatalog, int32_t type);
|
||||||
extern "C" int32_t ctgActUpdateTbl(SCtgMetaAction *action);
|
extern "C" int32_t ctgActUpdateTbl(SCtgMetaAction *action);
|
||||||
extern "C" int32_t ctgDbgEnableDebug(char *option);
|
extern "C" int32_t ctgDbgEnableDebug(char *option);
|
||||||
|
@ -57,12 +57,14 @@ enum {
|
||||||
CTGT_RSP_CTBMETA,
|
CTGT_RSP_CTBMETA,
|
||||||
CTGT_RSP_STBMETA,
|
CTGT_RSP_STBMETA,
|
||||||
CTGT_RSP_MSTBMETA,
|
CTGT_RSP_MSTBMETA,
|
||||||
|
CTGT_RSP_TBMETA_NOT_EXIST,
|
||||||
};
|
};
|
||||||
|
|
||||||
bool ctgTestStop = false;
|
bool ctgTestStop = false;
|
||||||
bool ctgTestEnableSleep = false;
|
bool ctgTestEnableSleep = false;
|
||||||
|
bool ctgTestEnableLog = true;
|
||||||
bool ctgTestDeadLoop = false;
|
bool ctgTestDeadLoop = false;
|
||||||
int32_t ctgTestPrintNum = 200000;
|
int32_t ctgTestPrintNum = 10000;
|
||||||
int32_t ctgTestMTRunSec = 5;
|
int32_t ctgTestMTRunSec = 5;
|
||||||
|
|
||||||
int32_t ctgTestCurrentVgVersion = 0;
|
int32_t ctgTestCurrentVgVersion = 0;
|
||||||
|
@ -74,14 +76,18 @@ int32_t ctgTestSVersion = 1;
|
||||||
int32_t ctgTestTVersion = 1;
|
int32_t ctgTestTVersion = 1;
|
||||||
int32_t ctgTestSuid = 2;
|
int32_t ctgTestSuid = 2;
|
||||||
uint64_t ctgTestDbId = 33;
|
uint64_t ctgTestDbId = 33;
|
||||||
|
uint64_t ctgTestNormalTblUid = 1;
|
||||||
|
|
||||||
uint64_t ctgTestClusterId = 0x1;
|
uint64_t ctgTestClusterId = 0x1;
|
||||||
char *ctgTestDbname = "1.db1";
|
char *ctgTestDbname = "1.db1";
|
||||||
char *ctgTestTablename = "table1";
|
char *ctgTestTablename = "table1";
|
||||||
char *ctgTestCTablename = "ctable1";
|
char *ctgTestCTablename = "ctable1";
|
||||||
char *ctgTestSTablename = "stable1";
|
char *ctgTestSTablename = "stable1";
|
||||||
|
char *ctgTestCurrentCTableName = NULL;
|
||||||
|
char *ctgTestCurrentTableName = NULL;
|
||||||
|
char *ctgTestCurrentSTableName = NULL;
|
||||||
|
|
||||||
int32_t ctgTestRspFunc[10] = {0};
|
int32_t ctgTestRspFunc[100] = {0};
|
||||||
int32_t ctgTestRspIdx = 0;
|
int32_t ctgTestRspIdx = 0;
|
||||||
|
|
||||||
void sendCreateDbMsg(void *shandle, SEpSet *pEpSet) {
|
void sendCreateDbMsg(void *shandle, SEpSet *pEpSet) {
|
||||||
|
@ -123,13 +129,20 @@ void sendCreateDbMsg(void *shandle, SEpSet *pEpSet) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void ctgTestInitLogFile() {
|
void ctgTestInitLogFile() {
|
||||||
|
if (!ctgTestEnableLog) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
const char *defaultLogFileNamePrefix = "taoslog";
|
const char *defaultLogFileNamePrefix = "taoslog";
|
||||||
const int32_t maxLogFileNum = 10;
|
const int32_t maxLogFileNum = 10;
|
||||||
|
|
||||||
tsAsyncLog = 0;
|
tsAsyncLog = 0;
|
||||||
qDebugFlag = 159;
|
qDebugFlag = 159;
|
||||||
|
strcpy(tsLogDir, "/var/log/taos");
|
||||||
|
|
||||||
ctgDbgEnableDebug("api");
|
ctgDbgEnableDebug("api");
|
||||||
|
ctgDbgEnableDebug("meta");
|
||||||
|
ctgDbgEnableDebug("cache");
|
||||||
|
|
||||||
if (taosInitLog(defaultLogFileNamePrefix, maxLogFileNum) < 0) {
|
if (taosInitLog(defaultLogFileNamePrefix, maxLogFileNum) < 0) {
|
||||||
printf("failed to open log file in directory:%s\n", tsLogDir);
|
printf("failed to open log file in directory:%s\n", tsLogDir);
|
||||||
|
@ -320,7 +333,7 @@ void ctgTestRspTableMeta(void *shandle, SEpSet *pEpSet, SRpcMsg *pMsg, SRpcMsg *
|
||||||
metaRsp.sversion = ctgTestSVersion;
|
metaRsp.sversion = ctgTestSVersion;
|
||||||
metaRsp.tversion = ctgTestTVersion;
|
metaRsp.tversion = ctgTestTVersion;
|
||||||
metaRsp.suid = 0;
|
metaRsp.suid = 0;
|
||||||
metaRsp.tuid = 0x0000000000000001;
|
metaRsp.tuid = ctgTestNormalTblUid++;
|
||||||
metaRsp.vgId = 8;
|
metaRsp.vgId = 8;
|
||||||
metaRsp.pSchemas = (SSchema *)malloc((metaRsp.numOfTags + metaRsp.numOfColumns) * sizeof(SSchema));
|
metaRsp.pSchemas = (SSchema *)malloc((metaRsp.numOfTags + metaRsp.numOfColumns) * sizeof(SSchema));
|
||||||
|
|
||||||
|
@ -348,10 +361,15 @@ void ctgTestRspTableMeta(void *shandle, SEpSet *pEpSet, SRpcMsg *pMsg, SRpcMsg *
|
||||||
tFreeSTableMetaRsp(&metaRsp);
|
tFreeSTableMetaRsp(&metaRsp);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ctgTestRspTableMetaNotExist(void *shandle, SEpSet *pEpSet, SRpcMsg *pMsg, SRpcMsg *pRsp) {
|
||||||
|
pRsp->code = CTG_ERR_CODE_TABLE_NOT_EXIST;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void ctgTestRspCTableMeta(void *shandle, SEpSet *pEpSet, SRpcMsg *pMsg, SRpcMsg *pRsp) {
|
void ctgTestRspCTableMeta(void *shandle, SEpSet *pEpSet, SRpcMsg *pMsg, SRpcMsg *pRsp) {
|
||||||
STableMetaRsp metaRsp = {0};
|
STableMetaRsp metaRsp = {0};
|
||||||
strcpy(metaRsp.dbFName, ctgTestDbname);
|
strcpy(metaRsp.dbFName, ctgTestDbname);
|
||||||
strcpy(metaRsp.tbName, ctgTestCTablename);
|
strcpy(metaRsp.tbName, ctgTestCurrentCTableName ? ctgTestCurrentCTableName : ctgTestCTablename);
|
||||||
strcpy(metaRsp.stbName, ctgTestSTablename);
|
strcpy(metaRsp.stbName, ctgTestSTablename);
|
||||||
metaRsp.numOfTags = ctgTestTagNum;
|
metaRsp.numOfTags = ctgTestTagNum;
|
||||||
metaRsp.numOfColumns = ctgTestColNum;
|
metaRsp.numOfColumns = ctgTestColNum;
|
||||||
|
@ -398,7 +416,7 @@ void ctgTestRspCTableMeta(void *shandle, SEpSet *pEpSet, SRpcMsg *pMsg, SRpcMsg
|
||||||
void ctgTestRspSTableMeta(void *shandle, SEpSet *pEpSet, SRpcMsg *pMsg, SRpcMsg *pRsp) {
|
void ctgTestRspSTableMeta(void *shandle, SEpSet *pEpSet, SRpcMsg *pMsg, SRpcMsg *pRsp) {
|
||||||
STableMetaRsp metaRsp = {0};
|
STableMetaRsp metaRsp = {0};
|
||||||
strcpy(metaRsp.dbFName, ctgTestDbname);
|
strcpy(metaRsp.dbFName, ctgTestDbname);
|
||||||
strcpy(metaRsp.tbName, ctgTestSTablename);
|
strcpy(metaRsp.tbName, ctgTestCurrentSTableName ? ctgTestCurrentSTableName : ctgTestSTablename);
|
||||||
strcpy(metaRsp.stbName, ctgTestSTablename);
|
strcpy(metaRsp.stbName, ctgTestSTablename);
|
||||||
metaRsp.numOfTags = ctgTestTagNum;
|
metaRsp.numOfTags = ctgTestTagNum;
|
||||||
metaRsp.numOfColumns = ctgTestColNum;
|
metaRsp.numOfColumns = ctgTestColNum;
|
||||||
|
@ -408,7 +426,7 @@ void ctgTestRspSTableMeta(void *shandle, SEpSet *pEpSet, SRpcMsg *pMsg, SRpcMsg
|
||||||
metaRsp.sversion = ctgTestSVersion;
|
metaRsp.sversion = ctgTestSVersion;
|
||||||
metaRsp.tversion = ctgTestTVersion;
|
metaRsp.tversion = ctgTestTVersion;
|
||||||
metaRsp.suid = ctgTestSuid;
|
metaRsp.suid = ctgTestSuid;
|
||||||
metaRsp.tuid = ctgTestSuid;
|
metaRsp.tuid = ctgTestSuid++;
|
||||||
metaRsp.vgId = 0;
|
metaRsp.vgId = 0;
|
||||||
metaRsp.pSchemas = (SSchema *)malloc((metaRsp.numOfTags + metaRsp.numOfColumns) * sizeof(SSchema));
|
metaRsp.pSchemas = (SSchema *)malloc((metaRsp.numOfTags + metaRsp.numOfColumns) * sizeof(SSchema));
|
||||||
|
|
||||||
|
@ -510,6 +528,9 @@ void ctgTestRspByIdx(void *shandle, SEpSet *pEpSet, SRpcMsg *pMsg, SRpcMsg *pRsp
|
||||||
case CTGT_RSP_MSTBMETA:
|
case CTGT_RSP_MSTBMETA:
|
||||||
ctgTestRspMultiSTableMeta(shandle, pEpSet, pMsg, pRsp);
|
ctgTestRspMultiSTableMeta(shandle, pEpSet, pMsg, pRsp);
|
||||||
break;
|
break;
|
||||||
|
case CTGT_RSP_TBMETA_NOT_EXIST:
|
||||||
|
ctgTestRspTableMetaNotExist(shandle, pEpSet, pMsg, pRsp);
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -772,7 +793,7 @@ void *ctgTestGetCtableMetaThread(void *param) {
|
||||||
strcpy(cn.tname, ctgTestCTablename);
|
strcpy(cn.tname, ctgTestCTablename);
|
||||||
|
|
||||||
while (!ctgTestStop) {
|
while (!ctgTestStop) {
|
||||||
code = ctgGetTableMetaFromCache(pCtg, &cn, &tbMeta, &exist, 0);
|
code = ctgGetTableMetaFromCache(pCtg, &cn, &tbMeta, &exist, 0, NULL);
|
||||||
if (code || 0 == exist) {
|
if (code || 0 == exist) {
|
||||||
assert(0);
|
assert(0);
|
||||||
}
|
}
|
||||||
|
@ -827,7 +848,7 @@ void *ctgTestSetCtableMetaThread(void *param) {
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
#if 0
|
#if 1
|
||||||
|
|
||||||
|
|
||||||
TEST(tableMeta, normalTable) {
|
TEST(tableMeta, normalTable) {
|
||||||
|
@ -859,7 +880,7 @@ TEST(tableMeta, normalTable) {
|
||||||
ASSERT_EQ(vgInfo.epset.numOfEps, 3);
|
ASSERT_EQ(vgInfo.epset.numOfEps, 3);
|
||||||
|
|
||||||
while (0 == ctgDbgGetClusterCacheNum(pCtg, CTG_DBG_DB_NUM)) {
|
while (0 == ctgDbgGetClusterCacheNum(pCtg, CTG_DBG_DB_NUM)) {
|
||||||
usleep(10000);
|
usleep(50000);
|
||||||
}
|
}
|
||||||
|
|
||||||
ctgTestSetRspTableMeta();
|
ctgTestSetRspTableMeta();
|
||||||
|
@ -869,6 +890,7 @@ TEST(tableMeta, normalTable) {
|
||||||
ASSERT_EQ(code, 0);
|
ASSERT_EQ(code, 0);
|
||||||
ASSERT_EQ(tableMeta->vgId, 8);
|
ASSERT_EQ(tableMeta->vgId, 8);
|
||||||
ASSERT_EQ(tableMeta->tableType, TSDB_NORMAL_TABLE);
|
ASSERT_EQ(tableMeta->tableType, TSDB_NORMAL_TABLE);
|
||||||
|
ASSERT_EQ(tableMeta->uid, ctgTestNormalTblUid - 1);
|
||||||
ASSERT_EQ(tableMeta->sversion, ctgTestSVersion);
|
ASSERT_EQ(tableMeta->sversion, ctgTestSVersion);
|
||||||
ASSERT_EQ(tableMeta->tversion, ctgTestTVersion);
|
ASSERT_EQ(tableMeta->tversion, ctgTestTVersion);
|
||||||
ASSERT_EQ(tableMeta->tableInfo.numOfColumns, ctgTestColNum);
|
ASSERT_EQ(tableMeta->tableInfo.numOfColumns, ctgTestColNum);
|
||||||
|
@ -879,7 +901,7 @@ TEST(tableMeta, normalTable) {
|
||||||
while (true) {
|
while (true) {
|
||||||
uint32_t n = ctgDbgGetClusterCacheNum(pCtg, CTG_DBG_META_NUM);
|
uint32_t n = ctgDbgGetClusterCacheNum(pCtg, CTG_DBG_META_NUM);
|
||||||
if (0 == n) {
|
if (0 == n) {
|
||||||
usleep(10000);
|
usleep(50000);
|
||||||
} else {
|
} else {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -974,7 +996,7 @@ TEST(tableMeta, childTableCase) {
|
||||||
while (true) {
|
while (true) {
|
||||||
uint32_t n = ctgDbgGetClusterCacheNum(pCtg, CTG_DBG_META_NUM);
|
uint32_t n = ctgDbgGetClusterCacheNum(pCtg, CTG_DBG_META_NUM);
|
||||||
if (0 == n) {
|
if (0 == n) {
|
||||||
usleep(10000);
|
usleep(50000);
|
||||||
} else {
|
} else {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -993,7 +1015,7 @@ TEST(tableMeta, childTableCase) {
|
||||||
ASSERT_EQ(tableMeta->tableInfo.precision, 1);
|
ASSERT_EQ(tableMeta->tableInfo.precision, 1);
|
||||||
ASSERT_EQ(tableMeta->tableInfo.rowSize, 12);
|
ASSERT_EQ(tableMeta->tableInfo.rowSize, 12);
|
||||||
|
|
||||||
tableMeta = NULL;
|
tfree(tableMeta);
|
||||||
|
|
||||||
strcpy(n.tname, ctgTestSTablename);
|
strcpy(n.tname, ctgTestSTablename);
|
||||||
code = catalogGetTableMeta(pCtg, mockPointer, (const SEpSet *)mockPointer, &n, &tableMeta);
|
code = catalogGetTableMeta(pCtg, mockPointer, (const SEpSet *)mockPointer, &n, &tableMeta);
|
||||||
|
@ -1073,8 +1095,8 @@ TEST(tableMeta, superTableCase) {
|
||||||
ASSERT_EQ(tableMeta->tableType, TSDB_SUPER_TABLE);
|
ASSERT_EQ(tableMeta->tableType, TSDB_SUPER_TABLE);
|
||||||
ASSERT_EQ(tableMeta->sversion, ctgTestSVersion);
|
ASSERT_EQ(tableMeta->sversion, ctgTestSVersion);
|
||||||
ASSERT_EQ(tableMeta->tversion, ctgTestTVersion);
|
ASSERT_EQ(tableMeta->tversion, ctgTestTVersion);
|
||||||
ASSERT_EQ(tableMeta->uid, ctgTestSuid);
|
ASSERT_EQ(tableMeta->uid, ctgTestSuid - 1);
|
||||||
ASSERT_EQ(tableMeta->suid, ctgTestSuid);
|
ASSERT_EQ(tableMeta->suid, ctgTestSuid - 1);
|
||||||
ASSERT_EQ(tableMeta->tableInfo.numOfColumns, ctgTestColNum);
|
ASSERT_EQ(tableMeta->tableInfo.numOfColumns, ctgTestColNum);
|
||||||
ASSERT_EQ(tableMeta->tableInfo.numOfTags, ctgTestTagNum);
|
ASSERT_EQ(tableMeta->tableInfo.numOfTags, ctgTestTagNum);
|
||||||
ASSERT_EQ(tableMeta->tableInfo.precision, 1);
|
ASSERT_EQ(tableMeta->tableInfo.precision, 1);
|
||||||
|
@ -1083,7 +1105,7 @@ TEST(tableMeta, superTableCase) {
|
||||||
while (true) {
|
while (true) {
|
||||||
uint32_t n = ctgDbgGetClusterCacheNum(pCtg, CTG_DBG_META_NUM);
|
uint32_t n = ctgDbgGetClusterCacheNum(pCtg, CTG_DBG_META_NUM);
|
||||||
if (0 == n) {
|
if (0 == n) {
|
||||||
usleep(10000);
|
usleep(50000);
|
||||||
} else {
|
} else {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -1110,7 +1132,7 @@ TEST(tableMeta, superTableCase) {
|
||||||
while (true) {
|
while (true) {
|
||||||
uint32_t n = ctgDbgGetClusterCacheNum(pCtg, CTG_DBG_META_NUM);
|
uint32_t n = ctgDbgGetClusterCacheNum(pCtg, CTG_DBG_META_NUM);
|
||||||
if (2 != n) {
|
if (2 != n) {
|
||||||
usleep(10000);
|
usleep(50000);
|
||||||
} else {
|
} else {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -1198,8 +1220,8 @@ TEST(tableMeta, rmStbMeta) {
|
||||||
ASSERT_EQ(tableMeta->tableType, TSDB_SUPER_TABLE);
|
ASSERT_EQ(tableMeta->tableType, TSDB_SUPER_TABLE);
|
||||||
ASSERT_EQ(tableMeta->sversion, ctgTestSVersion);
|
ASSERT_EQ(tableMeta->sversion, ctgTestSVersion);
|
||||||
ASSERT_EQ(tableMeta->tversion, ctgTestTVersion);
|
ASSERT_EQ(tableMeta->tversion, ctgTestTVersion);
|
||||||
ASSERT_EQ(tableMeta->uid, ctgTestSuid);
|
ASSERT_EQ(tableMeta->uid, ctgTestSuid - 1);
|
||||||
ASSERT_EQ(tableMeta->suid, ctgTestSuid);
|
ASSERT_EQ(tableMeta->suid, ctgTestSuid - 1);
|
||||||
ASSERT_EQ(tableMeta->tableInfo.numOfColumns, ctgTestColNum);
|
ASSERT_EQ(tableMeta->tableInfo.numOfColumns, ctgTestColNum);
|
||||||
ASSERT_EQ(tableMeta->tableInfo.numOfTags, ctgTestTagNum);
|
ASSERT_EQ(tableMeta->tableInfo.numOfTags, ctgTestTagNum);
|
||||||
ASSERT_EQ(tableMeta->tableInfo.precision, 1);
|
ASSERT_EQ(tableMeta->tableInfo.precision, 1);
|
||||||
|
@ -1208,21 +1230,21 @@ TEST(tableMeta, rmStbMeta) {
|
||||||
while (true) {
|
while (true) {
|
||||||
uint32_t n = ctgDbgGetClusterCacheNum(pCtg, CTG_DBG_META_NUM);
|
uint32_t n = ctgDbgGetClusterCacheNum(pCtg, CTG_DBG_META_NUM);
|
||||||
if (0 == n) {
|
if (0 == n) {
|
||||||
usleep(10000);
|
usleep(50000);
|
||||||
} else {
|
} else {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
code = catalogRemoveStbMeta(pCtg, "1.db1", ctgTestDbId, ctgTestSTablename, ctgTestSuid);
|
code = catalogRemoveStbMeta(pCtg, "1.db1", ctgTestDbId, ctgTestSTablename, ctgTestSuid - 1);
|
||||||
ASSERT_EQ(code, 0);
|
ASSERT_EQ(code, 0);
|
||||||
|
|
||||||
while (true) {
|
while (true) {
|
||||||
int32_t n = ctgDbgGetClusterCacheNum(pCtg, CTG_DBG_META_NUM);
|
int32_t n = ctgDbgGetClusterCacheNum(pCtg, CTG_DBG_META_NUM);
|
||||||
int32_t m = ctgDbgGetClusterCacheNum(pCtg, CTG_DBG_STB_RENT_NUM);
|
int32_t m = ctgDbgGetClusterCacheNum(pCtg, CTG_DBG_STB_RENT_NUM);
|
||||||
if (n || m) {
|
if (n || m) {
|
||||||
usleep(10000);
|
usleep(50000);
|
||||||
} else {
|
} else {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -1268,8 +1290,8 @@ TEST(tableMeta, updateStbMeta) {
|
||||||
ASSERT_EQ(tableMeta->tableType, TSDB_SUPER_TABLE);
|
ASSERT_EQ(tableMeta->tableType, TSDB_SUPER_TABLE);
|
||||||
ASSERT_EQ(tableMeta->sversion, ctgTestSVersion);
|
ASSERT_EQ(tableMeta->sversion, ctgTestSVersion);
|
||||||
ASSERT_EQ(tableMeta->tversion, ctgTestTVersion);
|
ASSERT_EQ(tableMeta->tversion, ctgTestTVersion);
|
||||||
ASSERT_EQ(tableMeta->uid, ctgTestSuid);
|
ASSERT_EQ(tableMeta->uid, ctgTestSuid - 1);
|
||||||
ASSERT_EQ(tableMeta->suid, ctgTestSuid);
|
ASSERT_EQ(tableMeta->suid, ctgTestSuid - 1);
|
||||||
ASSERT_EQ(tableMeta->tableInfo.numOfColumns, ctgTestColNum);
|
ASSERT_EQ(tableMeta->tableInfo.numOfColumns, ctgTestColNum);
|
||||||
ASSERT_EQ(tableMeta->tableInfo.numOfTags, ctgTestTagNum);
|
ASSERT_EQ(tableMeta->tableInfo.numOfTags, ctgTestTagNum);
|
||||||
ASSERT_EQ(tableMeta->tableInfo.precision, 1);
|
ASSERT_EQ(tableMeta->tableInfo.precision, 1);
|
||||||
|
@ -1278,7 +1300,7 @@ TEST(tableMeta, updateStbMeta) {
|
||||||
while (true) {
|
while (true) {
|
||||||
uint32_t n = ctgDbgGetClusterCacheNum(pCtg, CTG_DBG_META_NUM);
|
uint32_t n = ctgDbgGetClusterCacheNum(pCtg, CTG_DBG_META_NUM);
|
||||||
if (0 == n) {
|
if (0 == n) {
|
||||||
usleep(10000);
|
usleep(50000);
|
||||||
} else {
|
} else {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -1298,7 +1320,7 @@ TEST(tableMeta, updateStbMeta) {
|
||||||
uint64_t n = 0;
|
uint64_t n = 0;
|
||||||
ctgDbgGetStatNum("runtime.qDoneNum", (void *)&n);
|
ctgDbgGetStatNum("runtime.qDoneNum", (void *)&n);
|
||||||
if (n != 3) {
|
if (n != 3) {
|
||||||
usleep(10000);
|
usleep(50000);
|
||||||
} else {
|
} else {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -1329,6 +1351,499 @@ TEST(tableMeta, updateStbMeta) {
|
||||||
memset(&gCtgMgmt.stat, 0, sizeof(gCtgMgmt.stat));
|
memset(&gCtgMgmt.stat, 0, sizeof(gCtgMgmt.stat));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TEST(refreshGetMeta, normal2normal) {
|
||||||
|
struct SCatalog *pCtg = NULL;
|
||||||
|
void *mockPointer = (void *)0x1;
|
||||||
|
SVgroupInfo vgInfo = {0};
|
||||||
|
SArray *vgList = NULL;
|
||||||
|
|
||||||
|
ctgTestInitLogFile();
|
||||||
|
|
||||||
|
memset(ctgTestRspFunc, 0, sizeof(ctgTestRspFunc));
|
||||||
|
ctgTestRspIdx = 0;
|
||||||
|
ctgTestRspFunc[0] = CTGT_RSP_VGINFO;
|
||||||
|
ctgTestRspFunc[1] = CTGT_RSP_TBMETA;
|
||||||
|
ctgTestRspFunc[2] = CTGT_RSP_TBMETA;
|
||||||
|
|
||||||
|
ctgTestSetRspByIdx();
|
||||||
|
|
||||||
|
initQueryModuleMsgHandle();
|
||||||
|
|
||||||
|
int32_t code = catalogInit(NULL);
|
||||||
|
ASSERT_EQ(code, 0);
|
||||||
|
|
||||||
|
// sendCreateDbMsg(pConn->pTransporter, &pConn->pAppInfo->mgmtEp.epSet);
|
||||||
|
|
||||||
|
code = catalogGetHandle(ctgTestClusterId, &pCtg);
|
||||||
|
ASSERT_EQ(code, 0);
|
||||||
|
|
||||||
|
SName n = {.type = TSDB_TABLE_NAME_T, .acctId = 1};
|
||||||
|
strcpy(n.dbname, "db1");
|
||||||
|
strcpy(n.tname, ctgTestTablename);
|
||||||
|
|
||||||
|
code = catalogGetTableHashVgroup(pCtg, mockPointer, (const SEpSet *)mockPointer, &n, &vgInfo);
|
||||||
|
ASSERT_EQ(code, 0);
|
||||||
|
ASSERT_EQ(vgInfo.vgId, 8);
|
||||||
|
ASSERT_EQ(vgInfo.epset.numOfEps, 3);
|
||||||
|
|
||||||
|
while (true) {
|
||||||
|
uint64_t n = 0;
|
||||||
|
ctgDbgGetStatNum("runtime.qDoneNum", (void *)&n);
|
||||||
|
if (n > 0) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
usleep(50000);
|
||||||
|
}
|
||||||
|
|
||||||
|
STableMeta *tableMeta = NULL;
|
||||||
|
code = catalogGetTableMeta(pCtg, mockPointer, (const SEpSet *)mockPointer, &n, &tableMeta);
|
||||||
|
ASSERT_EQ(code, 0);
|
||||||
|
ASSERT_EQ(tableMeta->vgId, 8);
|
||||||
|
ASSERT_EQ(tableMeta->tableType, TSDB_NORMAL_TABLE);
|
||||||
|
ASSERT_EQ(tableMeta->uid, ctgTestNormalTblUid - 1);
|
||||||
|
ASSERT_EQ(tableMeta->sversion, ctgTestSVersion);
|
||||||
|
ASSERT_EQ(tableMeta->tversion, ctgTestTVersion);
|
||||||
|
ASSERT_EQ(tableMeta->tableInfo.numOfColumns, ctgTestColNum);
|
||||||
|
ASSERT_EQ(tableMeta->tableInfo.numOfTags, 0);
|
||||||
|
ASSERT_EQ(tableMeta->tableInfo.precision, 1);
|
||||||
|
ASSERT_EQ(tableMeta->tableInfo.rowSize, 12);
|
||||||
|
tfree(tableMeta);
|
||||||
|
|
||||||
|
while (0 == ctgDbgGetClusterCacheNum(pCtg, CTG_DBG_META_NUM)) {
|
||||||
|
usleep(50000);
|
||||||
|
}
|
||||||
|
|
||||||
|
code = catalogRefreshGetTableMeta(pCtg, mockPointer, (const SEpSet *)mockPointer, &n, &tableMeta, 0);
|
||||||
|
ASSERT_EQ(code, 0);
|
||||||
|
ASSERT_EQ(tableMeta->vgId, 8);
|
||||||
|
ASSERT_EQ(tableMeta->tableType, TSDB_NORMAL_TABLE);
|
||||||
|
ASSERT_EQ(tableMeta->uid, ctgTestNormalTblUid - 1);
|
||||||
|
ASSERT_EQ(tableMeta->sversion, ctgTestSVersion);
|
||||||
|
ASSERT_EQ(tableMeta->tversion, ctgTestTVersion);
|
||||||
|
ASSERT_EQ(tableMeta->tableInfo.numOfColumns, ctgTestColNum);
|
||||||
|
ASSERT_EQ(tableMeta->tableInfo.numOfTags, 0);
|
||||||
|
ASSERT_EQ(tableMeta->tableInfo.precision, 1);
|
||||||
|
ASSERT_EQ(tableMeta->tableInfo.rowSize, 12);
|
||||||
|
tfree(tableMeta);
|
||||||
|
|
||||||
|
catalogDestroy();
|
||||||
|
memset(&gCtgMgmt, 0, sizeof(gCtgMgmt));
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST(refreshGetMeta, normal2notexist) {
|
||||||
|
struct SCatalog *pCtg = NULL;
|
||||||
|
void *mockPointer = (void *)0x1;
|
||||||
|
SVgroupInfo vgInfo = {0};
|
||||||
|
SArray *vgList = NULL;
|
||||||
|
|
||||||
|
ctgTestInitLogFile();
|
||||||
|
|
||||||
|
memset(ctgTestRspFunc, 0, sizeof(ctgTestRspFunc));
|
||||||
|
ctgTestRspIdx = 0;
|
||||||
|
ctgTestRspFunc[0] = CTGT_RSP_VGINFO;
|
||||||
|
ctgTestRspFunc[1] = CTGT_RSP_TBMETA;
|
||||||
|
ctgTestRspFunc[2] = CTGT_RSP_TBMETA_NOT_EXIST;
|
||||||
|
|
||||||
|
ctgTestSetRspByIdx();
|
||||||
|
|
||||||
|
initQueryModuleMsgHandle();
|
||||||
|
|
||||||
|
int32_t code = catalogInit(NULL);
|
||||||
|
ASSERT_EQ(code, 0);
|
||||||
|
|
||||||
|
// sendCreateDbMsg(pConn->pTransporter, &pConn->pAppInfo->mgmtEp.epSet);
|
||||||
|
|
||||||
|
code = catalogGetHandle(ctgTestClusterId, &pCtg);
|
||||||
|
ASSERT_EQ(code, 0);
|
||||||
|
|
||||||
|
SName n = {.type = TSDB_TABLE_NAME_T, .acctId = 1};
|
||||||
|
strcpy(n.dbname, "db1");
|
||||||
|
strcpy(n.tname, ctgTestTablename);
|
||||||
|
|
||||||
|
code = catalogGetTableHashVgroup(pCtg, mockPointer, (const SEpSet *)mockPointer, &n, &vgInfo);
|
||||||
|
ASSERT_EQ(code, 0);
|
||||||
|
ASSERT_EQ(vgInfo.vgId, 8);
|
||||||
|
ASSERT_EQ(vgInfo.epset.numOfEps, 3);
|
||||||
|
|
||||||
|
while (true) {
|
||||||
|
uint64_t n = 0;
|
||||||
|
ctgDbgGetStatNum("runtime.qDoneNum", (void *)&n);
|
||||||
|
if (n > 0) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
usleep(50000);
|
||||||
|
}
|
||||||
|
|
||||||
|
STableMeta *tableMeta = NULL;
|
||||||
|
code = catalogGetTableMeta(pCtg, mockPointer, (const SEpSet *)mockPointer, &n, &tableMeta);
|
||||||
|
ASSERT_EQ(code, 0);
|
||||||
|
ASSERT_EQ(tableMeta->vgId, 8);
|
||||||
|
ASSERT_EQ(tableMeta->tableType, TSDB_NORMAL_TABLE);
|
||||||
|
ASSERT_EQ(tableMeta->uid, ctgTestNormalTblUid - 1);
|
||||||
|
ASSERT_EQ(tableMeta->sversion, ctgTestSVersion);
|
||||||
|
ASSERT_EQ(tableMeta->tversion, ctgTestTVersion);
|
||||||
|
ASSERT_EQ(tableMeta->tableInfo.numOfColumns, ctgTestColNum);
|
||||||
|
ASSERT_EQ(tableMeta->tableInfo.numOfTags, 0);
|
||||||
|
ASSERT_EQ(tableMeta->tableInfo.precision, 1);
|
||||||
|
ASSERT_EQ(tableMeta->tableInfo.rowSize, 12);
|
||||||
|
tfree(tableMeta);
|
||||||
|
|
||||||
|
while (0 == ctgDbgGetClusterCacheNum(pCtg, CTG_DBG_META_NUM)) {
|
||||||
|
usleep(50000);
|
||||||
|
}
|
||||||
|
|
||||||
|
code = catalogRefreshGetTableMeta(pCtg, mockPointer, (const SEpSet *)mockPointer, &n, &tableMeta, 0);
|
||||||
|
ASSERT_EQ(code, CTG_ERR_CODE_TABLE_NOT_EXIST);
|
||||||
|
ASSERT_TRUE(tableMeta == NULL);
|
||||||
|
|
||||||
|
catalogDestroy();
|
||||||
|
memset(&gCtgMgmt, 0, sizeof(gCtgMgmt));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
TEST(refreshGetMeta, normal2child) {
|
||||||
|
struct SCatalog *pCtg = NULL;
|
||||||
|
void *mockPointer = (void *)0x1;
|
||||||
|
SVgroupInfo vgInfo = {0};
|
||||||
|
SArray *vgList = NULL;
|
||||||
|
|
||||||
|
ctgTestInitLogFile();
|
||||||
|
|
||||||
|
memset(ctgTestRspFunc, 0, sizeof(ctgTestRspFunc));
|
||||||
|
ctgTestRspIdx = 0;
|
||||||
|
ctgTestRspFunc[0] = CTGT_RSP_VGINFO;
|
||||||
|
ctgTestRspFunc[1] = CTGT_RSP_TBMETA;
|
||||||
|
ctgTestRspFunc[2] = CTGT_RSP_CTBMETA;
|
||||||
|
ctgTestRspFunc[3] = CTGT_RSP_STBMETA;
|
||||||
|
|
||||||
|
ctgTestSetRspByIdx();
|
||||||
|
|
||||||
|
initQueryModuleMsgHandle();
|
||||||
|
|
||||||
|
int32_t code = catalogInit(NULL);
|
||||||
|
ASSERT_EQ(code, 0);
|
||||||
|
|
||||||
|
// sendCreateDbMsg(pConn->pTransporter, &pConn->pAppInfo->mgmtEp.epSet);
|
||||||
|
|
||||||
|
code = catalogGetHandle(ctgTestClusterId, &pCtg);
|
||||||
|
ASSERT_EQ(code, 0);
|
||||||
|
|
||||||
|
SName n = {.type = TSDB_TABLE_NAME_T, .acctId = 1};
|
||||||
|
strcpy(n.dbname, "db1");
|
||||||
|
strcpy(n.tname, ctgTestTablename);
|
||||||
|
ctgTestCurrentCTableName = ctgTestTablename;
|
||||||
|
ctgTestCurrentSTableName = ctgTestSTablename;
|
||||||
|
|
||||||
|
code = catalogGetTableHashVgroup(pCtg, mockPointer, (const SEpSet *)mockPointer, &n, &vgInfo);
|
||||||
|
ASSERT_EQ(code, 0);
|
||||||
|
ASSERT_EQ(vgInfo.vgId, 8);
|
||||||
|
ASSERT_EQ(vgInfo.epset.numOfEps, 3);
|
||||||
|
|
||||||
|
while (true) {
|
||||||
|
uint64_t n = 0;
|
||||||
|
ctgDbgGetStatNum("runtime.qDoneNum", (void *)&n);
|
||||||
|
if (n > 0) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
usleep(50000);
|
||||||
|
}
|
||||||
|
|
||||||
|
STableMeta *tableMeta = NULL;
|
||||||
|
code = catalogGetTableMeta(pCtg, mockPointer, (const SEpSet *)mockPointer, &n, &tableMeta);
|
||||||
|
ASSERT_EQ(code, 0);
|
||||||
|
ASSERT_EQ(tableMeta->vgId, 8);
|
||||||
|
ASSERT_EQ(tableMeta->tableType, TSDB_NORMAL_TABLE);
|
||||||
|
ASSERT_EQ(tableMeta->uid, ctgTestNormalTblUid - 1);
|
||||||
|
ASSERT_EQ(tableMeta->sversion, ctgTestSVersion);
|
||||||
|
ASSERT_EQ(tableMeta->tversion, ctgTestTVersion);
|
||||||
|
ASSERT_EQ(tableMeta->tableInfo.numOfColumns, ctgTestColNum);
|
||||||
|
ASSERT_EQ(tableMeta->tableInfo.numOfTags, 0);
|
||||||
|
ASSERT_EQ(tableMeta->tableInfo.precision, 1);
|
||||||
|
ASSERT_EQ(tableMeta->tableInfo.rowSize, 12);
|
||||||
|
tfree(tableMeta);
|
||||||
|
|
||||||
|
while (0 == ctgDbgGetClusterCacheNum(pCtg, CTG_DBG_META_NUM)) {
|
||||||
|
usleep(50000);
|
||||||
|
}
|
||||||
|
|
||||||
|
code = catalogRefreshGetTableMeta(pCtg, mockPointer, (const SEpSet *)mockPointer, &n, &tableMeta, 0);
|
||||||
|
ASSERT_EQ(code, 0);
|
||||||
|
ASSERT_EQ(tableMeta->vgId, 9);
|
||||||
|
ASSERT_EQ(tableMeta->tableType, TSDB_CHILD_TABLE);
|
||||||
|
ASSERT_EQ(tableMeta->sversion, ctgTestSVersion);
|
||||||
|
ASSERT_EQ(tableMeta->tversion, ctgTestTVersion);
|
||||||
|
ASSERT_EQ(tableMeta->tableInfo.numOfColumns, ctgTestColNum);
|
||||||
|
ASSERT_EQ(tableMeta->tableInfo.numOfTags, ctgTestTagNum);
|
||||||
|
ASSERT_EQ(tableMeta->tableInfo.precision, 1);
|
||||||
|
ASSERT_EQ(tableMeta->tableInfo.rowSize, 12);
|
||||||
|
tfree(tableMeta);
|
||||||
|
|
||||||
|
catalogDestroy();
|
||||||
|
memset(&gCtgMgmt, 0, sizeof(gCtgMgmt));
|
||||||
|
ctgTestCurrentCTableName = NULL;
|
||||||
|
ctgTestCurrentSTableName = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST(refreshGetMeta, stable2child) {
|
||||||
|
struct SCatalog *pCtg = NULL;
|
||||||
|
void *mockPointer = (void *)0x1;
|
||||||
|
SVgroupInfo vgInfo = {0};
|
||||||
|
SArray *vgList = NULL;
|
||||||
|
|
||||||
|
ctgTestInitLogFile();
|
||||||
|
|
||||||
|
memset(ctgTestRspFunc, 0, sizeof(ctgTestRspFunc));
|
||||||
|
ctgTestRspIdx = 0;
|
||||||
|
ctgTestRspFunc[0] = CTGT_RSP_VGINFO;
|
||||||
|
ctgTestRspFunc[1] = CTGT_RSP_STBMETA;
|
||||||
|
ctgTestRspFunc[2] = CTGT_RSP_STBMETA;
|
||||||
|
ctgTestRspFunc[3] = CTGT_RSP_CTBMETA;
|
||||||
|
ctgTestRspFunc[4] = CTGT_RSP_STBMETA;
|
||||||
|
|
||||||
|
ctgTestSetRspByIdx();
|
||||||
|
|
||||||
|
initQueryModuleMsgHandle();
|
||||||
|
|
||||||
|
int32_t code = catalogInit(NULL);
|
||||||
|
ASSERT_EQ(code, 0);
|
||||||
|
|
||||||
|
// sendCreateDbMsg(pConn->pTransporter, &pConn->pAppInfo->mgmtEp.epSet);
|
||||||
|
|
||||||
|
code = catalogGetHandle(ctgTestClusterId, &pCtg);
|
||||||
|
ASSERT_EQ(code, 0);
|
||||||
|
|
||||||
|
SName n = {.type = TSDB_TABLE_NAME_T, .acctId = 1};
|
||||||
|
strcpy(n.dbname, "db1");
|
||||||
|
strcpy(n.tname, ctgTestTablename);
|
||||||
|
ctgTestCurrentSTableName = ctgTestTablename;
|
||||||
|
ctgTestCurrentCTableName = ctgTestTablename;
|
||||||
|
|
||||||
|
code = catalogGetTableHashVgroup(pCtg, mockPointer, (const SEpSet *)mockPointer, &n, &vgInfo);
|
||||||
|
ASSERT_EQ(code, 0);
|
||||||
|
ASSERT_EQ(vgInfo.vgId, 8);
|
||||||
|
ASSERT_EQ(vgInfo.epset.numOfEps, 3);
|
||||||
|
|
||||||
|
while (true) {
|
||||||
|
uint64_t n = 0;
|
||||||
|
ctgDbgGetStatNum("runtime.qDoneNum", (void *)&n);
|
||||||
|
if (n > 0) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
usleep(50000);
|
||||||
|
}
|
||||||
|
|
||||||
|
STableMeta *tableMeta = NULL;
|
||||||
|
code = catalogGetTableMeta(pCtg, mockPointer, (const SEpSet *)mockPointer, &n, &tableMeta);
|
||||||
|
ASSERT_EQ(code, 0);
|
||||||
|
ASSERT_EQ(tableMeta->vgId, 0);
|
||||||
|
ASSERT_EQ(tableMeta->tableType, TSDB_SUPER_TABLE);
|
||||||
|
ASSERT_EQ(tableMeta->sversion, ctgTestSVersion);
|
||||||
|
ASSERT_EQ(tableMeta->tversion, ctgTestTVersion);
|
||||||
|
ASSERT_EQ(tableMeta->uid, ctgTestSuid - 1);
|
||||||
|
ASSERT_EQ(tableMeta->suid, ctgTestSuid - 1);
|
||||||
|
ASSERT_EQ(tableMeta->tableInfo.numOfColumns, ctgTestColNum);
|
||||||
|
ASSERT_EQ(tableMeta->tableInfo.numOfTags, ctgTestTagNum);
|
||||||
|
ASSERT_EQ(tableMeta->tableInfo.precision, 1);
|
||||||
|
ASSERT_EQ(tableMeta->tableInfo.rowSize, 12);
|
||||||
|
tfree(tableMeta);
|
||||||
|
|
||||||
|
while (0 == ctgDbgGetClusterCacheNum(pCtg, CTG_DBG_META_NUM)) {
|
||||||
|
usleep(50000);
|
||||||
|
}
|
||||||
|
|
||||||
|
ctgTestCurrentSTableName = ctgTestSTablename;
|
||||||
|
code = catalogRefreshGetTableMeta(pCtg, mockPointer, (const SEpSet *)mockPointer, &n, &tableMeta, 0);
|
||||||
|
ASSERT_EQ(code, 0);
|
||||||
|
ASSERT_EQ(tableMeta->vgId, 9);
|
||||||
|
ASSERT_EQ(tableMeta->tableType, TSDB_CHILD_TABLE);
|
||||||
|
ASSERT_EQ(tableMeta->sversion, ctgTestSVersion);
|
||||||
|
ASSERT_EQ(tableMeta->tversion, ctgTestTVersion);
|
||||||
|
ASSERT_EQ(tableMeta->tableInfo.numOfColumns, ctgTestColNum);
|
||||||
|
ASSERT_EQ(tableMeta->tableInfo.numOfTags, ctgTestTagNum);
|
||||||
|
ASSERT_EQ(tableMeta->tableInfo.precision, 1);
|
||||||
|
ASSERT_EQ(tableMeta->tableInfo.rowSize, 12);
|
||||||
|
tfree(tableMeta);
|
||||||
|
|
||||||
|
catalogDestroy();
|
||||||
|
memset(&gCtgMgmt, 0, sizeof(gCtgMgmt));
|
||||||
|
ctgTestCurrentCTableName = NULL;
|
||||||
|
ctgTestCurrentSTableName = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST(refreshGetMeta, stable2stable) {
|
||||||
|
struct SCatalog *pCtg = NULL;
|
||||||
|
void *mockPointer = (void *)0x1;
|
||||||
|
SVgroupInfo vgInfo = {0};
|
||||||
|
SArray *vgList = NULL;
|
||||||
|
|
||||||
|
ctgTestInitLogFile();
|
||||||
|
|
||||||
|
memset(ctgTestRspFunc, 0, sizeof(ctgTestRspFunc));
|
||||||
|
ctgTestRspIdx = 0;
|
||||||
|
ctgTestRspFunc[0] = CTGT_RSP_VGINFO;
|
||||||
|
ctgTestRspFunc[1] = CTGT_RSP_STBMETA;
|
||||||
|
ctgTestRspFunc[2] = CTGT_RSP_STBMETA;
|
||||||
|
ctgTestRspFunc[3] = CTGT_RSP_STBMETA;
|
||||||
|
ctgTestRspFunc[4] = CTGT_RSP_STBMETA;
|
||||||
|
|
||||||
|
ctgTestSetRspByIdx();
|
||||||
|
|
||||||
|
initQueryModuleMsgHandle();
|
||||||
|
|
||||||
|
int32_t code = catalogInit(NULL);
|
||||||
|
ASSERT_EQ(code, 0);
|
||||||
|
|
||||||
|
// sendCreateDbMsg(pConn->pTransporter, &pConn->pAppInfo->mgmtEp.epSet);
|
||||||
|
|
||||||
|
code = catalogGetHandle(ctgTestClusterId, &pCtg);
|
||||||
|
ASSERT_EQ(code, 0);
|
||||||
|
|
||||||
|
SName n = {.type = TSDB_TABLE_NAME_T, .acctId = 1};
|
||||||
|
strcpy(n.dbname, "db1");
|
||||||
|
strcpy(n.tname, ctgTestTablename);
|
||||||
|
ctgTestCurrentSTableName = ctgTestTablename;
|
||||||
|
|
||||||
|
code = catalogGetTableHashVgroup(pCtg, mockPointer, (const SEpSet *)mockPointer, &n, &vgInfo);
|
||||||
|
ASSERT_EQ(code, 0);
|
||||||
|
ASSERT_EQ(vgInfo.vgId, 8);
|
||||||
|
ASSERT_EQ(vgInfo.epset.numOfEps, 3);
|
||||||
|
|
||||||
|
while (true) {
|
||||||
|
uint64_t n = 0;
|
||||||
|
ctgDbgGetStatNum("runtime.qDoneNum", (void *)&n);
|
||||||
|
if (n > 0) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
usleep(50000);
|
||||||
|
}
|
||||||
|
|
||||||
|
STableMeta *tableMeta = NULL;
|
||||||
|
code = catalogGetTableMeta(pCtg, mockPointer, (const SEpSet *)mockPointer, &n, &tableMeta);
|
||||||
|
ASSERT_EQ(code, 0);
|
||||||
|
ASSERT_EQ(tableMeta->vgId, 0);
|
||||||
|
ASSERT_EQ(tableMeta->tableType, TSDB_SUPER_TABLE);
|
||||||
|
ASSERT_EQ(tableMeta->sversion, ctgTestSVersion);
|
||||||
|
ASSERT_EQ(tableMeta->tversion, ctgTestTVersion);
|
||||||
|
ASSERT_EQ(tableMeta->uid, ctgTestSuid - 1);
|
||||||
|
ASSERT_EQ(tableMeta->suid, ctgTestSuid - 1);
|
||||||
|
ASSERT_EQ(tableMeta->tableInfo.numOfColumns, ctgTestColNum);
|
||||||
|
ASSERT_EQ(tableMeta->tableInfo.numOfTags, ctgTestTagNum);
|
||||||
|
ASSERT_EQ(tableMeta->tableInfo.precision, 1);
|
||||||
|
ASSERT_EQ(tableMeta->tableInfo.rowSize, 12);
|
||||||
|
tfree(tableMeta);
|
||||||
|
|
||||||
|
while (0 == ctgDbgGetClusterCacheNum(pCtg, CTG_DBG_META_NUM)) {
|
||||||
|
usleep(50000);
|
||||||
|
}
|
||||||
|
|
||||||
|
code = catalogRefreshGetTableMeta(pCtg, mockPointer, (const SEpSet *)mockPointer, &n, &tableMeta, 0);
|
||||||
|
ASSERT_EQ(code, 0);
|
||||||
|
ASSERT_EQ(tableMeta->vgId, 0);
|
||||||
|
ASSERT_EQ(tableMeta->tableType, TSDB_SUPER_TABLE);
|
||||||
|
ASSERT_EQ(tableMeta->sversion, ctgTestSVersion);
|
||||||
|
ASSERT_EQ(tableMeta->tversion, ctgTestTVersion);
|
||||||
|
ASSERT_EQ(tableMeta->uid, ctgTestSuid - 1);
|
||||||
|
ASSERT_EQ(tableMeta->suid, ctgTestSuid - 1);
|
||||||
|
ASSERT_EQ(tableMeta->tableInfo.numOfColumns, ctgTestColNum);
|
||||||
|
ASSERT_EQ(tableMeta->tableInfo.numOfTags, ctgTestTagNum);
|
||||||
|
ASSERT_EQ(tableMeta->tableInfo.precision, 1);
|
||||||
|
ASSERT_EQ(tableMeta->tableInfo.rowSize, 12);
|
||||||
|
tfree(tableMeta);
|
||||||
|
|
||||||
|
catalogDestroy();
|
||||||
|
memset(&gCtgMgmt, 0, sizeof(gCtgMgmt));
|
||||||
|
ctgTestCurrentCTableName = NULL;
|
||||||
|
ctgTestCurrentSTableName = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
TEST(refreshGetMeta, child2stable) {
|
||||||
|
struct SCatalog *pCtg = NULL;
|
||||||
|
void *mockPointer = (void *)0x1;
|
||||||
|
SVgroupInfo vgInfo = {0};
|
||||||
|
SArray *vgList = NULL;
|
||||||
|
|
||||||
|
ctgTestInitLogFile();
|
||||||
|
|
||||||
|
memset(ctgTestRspFunc, 0, sizeof(ctgTestRspFunc));
|
||||||
|
ctgTestRspIdx = 0;
|
||||||
|
ctgTestRspFunc[0] = CTGT_RSP_VGINFO;
|
||||||
|
ctgTestRspFunc[1] = CTGT_RSP_CTBMETA;
|
||||||
|
ctgTestRspFunc[2] = CTGT_RSP_STBMETA;
|
||||||
|
ctgTestRspFunc[3] = CTGT_RSP_STBMETA;
|
||||||
|
ctgTestRspFunc[4] = CTGT_RSP_STBMETA;
|
||||||
|
|
||||||
|
ctgTestSetRspByIdx();
|
||||||
|
|
||||||
|
initQueryModuleMsgHandle();
|
||||||
|
|
||||||
|
int32_t code = catalogInit(NULL);
|
||||||
|
ASSERT_EQ(code, 0);
|
||||||
|
|
||||||
|
// sendCreateDbMsg(pConn->pTransporter, &pConn->pAppInfo->mgmtEp.epSet);
|
||||||
|
|
||||||
|
code = catalogGetHandle(ctgTestClusterId, &pCtg);
|
||||||
|
ASSERT_EQ(code, 0);
|
||||||
|
|
||||||
|
SName n = {.type = TSDB_TABLE_NAME_T, .acctId = 1};
|
||||||
|
strcpy(n.dbname, "db1");
|
||||||
|
strcpy(n.tname, ctgTestTablename);
|
||||||
|
ctgTestCurrentCTableName = ctgTestTablename;
|
||||||
|
ctgTestCurrentSTableName = ctgTestSTablename;
|
||||||
|
|
||||||
|
code = catalogGetTableHashVgroup(pCtg, mockPointer, (const SEpSet *)mockPointer, &n, &vgInfo);
|
||||||
|
ASSERT_EQ(code, 0);
|
||||||
|
ASSERT_EQ(vgInfo.vgId, 8);
|
||||||
|
ASSERT_EQ(vgInfo.epset.numOfEps, 3);
|
||||||
|
|
||||||
|
while (true) {
|
||||||
|
uint64_t n = 0;
|
||||||
|
ctgDbgGetStatNum("runtime.qDoneNum", (void *)&n);
|
||||||
|
if (n > 0) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
usleep(50000);
|
||||||
|
}
|
||||||
|
|
||||||
|
STableMeta *tableMeta = NULL;
|
||||||
|
code = catalogGetTableMeta(pCtg, mockPointer, (const SEpSet *)mockPointer, &n, &tableMeta);
|
||||||
|
ASSERT_EQ(code, 0);
|
||||||
|
ASSERT_EQ(tableMeta->vgId, 9);
|
||||||
|
ASSERT_EQ(tableMeta->tableType, TSDB_CHILD_TABLE);
|
||||||
|
ASSERT_EQ(tableMeta->sversion, ctgTestSVersion);
|
||||||
|
ASSERT_EQ(tableMeta->tversion, ctgTestTVersion);
|
||||||
|
ASSERT_EQ(tableMeta->tableInfo.numOfColumns, ctgTestColNum);
|
||||||
|
ASSERT_EQ(tableMeta->tableInfo.numOfTags, ctgTestTagNum);
|
||||||
|
ASSERT_EQ(tableMeta->tableInfo.precision, 1);
|
||||||
|
ASSERT_EQ(tableMeta->tableInfo.rowSize, 12);
|
||||||
|
tfree(tableMeta);
|
||||||
|
|
||||||
|
while (2 != ctgDbgGetClusterCacheNum(pCtg, CTG_DBG_META_NUM)) {
|
||||||
|
usleep(50000);
|
||||||
|
}
|
||||||
|
|
||||||
|
ctgTestCurrentSTableName = ctgTestTablename;
|
||||||
|
code = catalogRefreshGetTableMeta(pCtg, mockPointer, (const SEpSet *)mockPointer, &n, &tableMeta, 0);
|
||||||
|
ASSERT_EQ(code, 0);
|
||||||
|
ASSERT_EQ(tableMeta->vgId, 0);
|
||||||
|
ASSERT_EQ(tableMeta->tableType, TSDB_SUPER_TABLE);
|
||||||
|
ASSERT_EQ(tableMeta->sversion, ctgTestSVersion);
|
||||||
|
ASSERT_EQ(tableMeta->tversion, ctgTestTVersion);
|
||||||
|
ASSERT_EQ(tableMeta->uid, ctgTestSuid - 1);
|
||||||
|
ASSERT_EQ(tableMeta->suid, ctgTestSuid - 1);
|
||||||
|
ASSERT_EQ(tableMeta->tableInfo.numOfColumns, ctgTestColNum);
|
||||||
|
ASSERT_EQ(tableMeta->tableInfo.numOfTags, ctgTestTagNum);
|
||||||
|
ASSERT_EQ(tableMeta->tableInfo.precision, 1);
|
||||||
|
ASSERT_EQ(tableMeta->tableInfo.rowSize, 12);
|
||||||
|
tfree(tableMeta);
|
||||||
|
|
||||||
|
catalogDestroy();
|
||||||
|
memset(&gCtgMgmt, 0, sizeof(gCtgMgmt));
|
||||||
|
ctgTestCurrentCTableName = NULL;
|
||||||
|
ctgTestCurrentSTableName = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
TEST(tableDistVgroup, normalTable) {
|
TEST(tableDistVgroup, normalTable) {
|
||||||
struct SCatalog *pCtg = NULL;
|
struct SCatalog *pCtg = NULL;
|
||||||
void *mockPointer = (void *)0x1;
|
void *mockPointer = (void *)0x1;
|
||||||
|
@ -1498,10 +2013,14 @@ TEST(dbVgroup, getSetDbVgroupCase) {
|
||||||
ASSERT_EQ(code, 0);
|
ASSERT_EQ(code, 0);
|
||||||
ASSERT_EQ(taosArrayGetSize((const SArray *)vgList), ctgTestVgNum);
|
ASSERT_EQ(taosArrayGetSize((const SArray *)vgList), ctgTestVgNum);
|
||||||
|
|
||||||
while (0 == ctgDbgGetClusterCacheNum(pCtg, CTG_DBG_DB_NUM)) {
|
while (true) {
|
||||||
usleep(10000);
|
uint64_t n = 0;
|
||||||
|
ctgDbgGetStatNum("runtime.qDoneNum", (void *)&n);
|
||||||
|
if (n > 0) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
usleep(50000);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
code = catalogGetTableHashVgroup(pCtg, mockPointer, (const SEpSet *)mockPointer, &n, &vgInfo);
|
code = catalogGetTableHashVgroup(pCtg, mockPointer, (const SEpSet *)mockPointer, &n, &vgInfo);
|
||||||
ASSERT_EQ(code, 0);
|
ASSERT_EQ(code, 0);
|
||||||
|
@ -1524,7 +2043,7 @@ TEST(dbVgroup, getSetDbVgroupCase) {
|
||||||
uint64_t n = 0;
|
uint64_t n = 0;
|
||||||
ctgDbgGetStatNum("runtime.qDoneNum", (void *)&n);
|
ctgDbgGetStatNum("runtime.qDoneNum", (void *)&n);
|
||||||
if (n != 3) {
|
if (n != 3) {
|
||||||
usleep(10000);
|
usleep(50000);
|
||||||
} else {
|
} else {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -1748,7 +2267,7 @@ TEST(rentTest, allRent) {
|
||||||
ASSERT_EQ(tableMeta->tableInfo.rowSize, 12);
|
ASSERT_EQ(tableMeta->tableInfo.rowSize, 12);
|
||||||
|
|
||||||
while (ctgDbgGetClusterCacheNum(pCtg, CTG_DBG_META_NUM) < i) {
|
while (ctgDbgGetClusterCacheNum(pCtg, CTG_DBG_META_NUM) < i) {
|
||||||
usleep(10000);
|
usleep(50000);
|
||||||
}
|
}
|
||||||
|
|
||||||
code = catalogGetExpiredDBs(pCtg, &dbs, &num);
|
code = catalogGetExpiredDBs(pCtg, &dbs, &num);
|
||||||
|
|
|
@ -68,7 +68,7 @@ typedef struct SResultRow {
|
||||||
} SResultRow;
|
} SResultRow;
|
||||||
|
|
||||||
typedef struct SResultRowInfo {
|
typedef struct SResultRowInfo {
|
||||||
SResultRow *pCurResult; // current active result row info
|
SList* pRows;
|
||||||
SResultRow** pResult; // result list
|
SResultRow** pResult; // result list
|
||||||
// int16_t type:8; // data type for hash key
|
// int16_t type:8; // data type for hash key
|
||||||
int32_t size; // number of result set
|
int32_t size; // number of result set
|
||||||
|
|
|
@ -15,12 +15,12 @@
|
||||||
#ifndef TDENGINE_EXECUTORIMPL_H
|
#ifndef TDENGINE_EXECUTORIMPL_H
|
||||||
#define TDENGINE_EXECUTORIMPL_H
|
#define TDENGINE_EXECUTORIMPL_H
|
||||||
|
|
||||||
#include "tsort.h"
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
extern "C" {
|
extern "C" {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include "os.h"
|
#include "os.h"
|
||||||
|
#include "tsort.h"
|
||||||
#include "tcommon.h"
|
#include "tcommon.h"
|
||||||
#include "tlosertree.h"
|
#include "tlosertree.h"
|
||||||
#include "ttszip.h"
|
#include "ttszip.h"
|
||||||
|
@ -157,6 +157,13 @@ typedef struct STaskCostInfo {
|
||||||
SHashObj* operatorProfResults; // map<operator_type, SQueryProfEvent>
|
SHashObj* operatorProfResults; // map<operator_type, SQueryProfEvent>
|
||||||
} STaskCostInfo;
|
} STaskCostInfo;
|
||||||
|
|
||||||
|
typedef struct SOperatorCostInfo {
|
||||||
|
uint64_t openCost;
|
||||||
|
uint64_t execCost;
|
||||||
|
uint64_t totalRows;
|
||||||
|
uint64_t totalBytes;
|
||||||
|
} SOperatorCostInfo;
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
int64_t vgroupLimit;
|
int64_t vgroupLimit;
|
||||||
int64_t ts;
|
int64_t ts;
|
||||||
|
@ -233,9 +240,9 @@ typedef struct STaskAttr {
|
||||||
SArray* pUdfInfo; // no need to free
|
SArray* pUdfInfo; // no need to free
|
||||||
} STaskAttr;
|
} STaskAttr;
|
||||||
|
|
||||||
typedef int32_t (*__optr_prepare_fn_t)(void* param);
|
typedef int32_t (*__optr_open_fn_t)(void* param);
|
||||||
typedef SSDataBlock* (*__operator_fn_t)(void* param, bool* newgroup);
|
typedef SSDataBlock* (*__optr_fn_t)(void* param, bool* newgroup);
|
||||||
typedef void (*__optr_cleanup_fn_t)(void* param, int32_t num);
|
typedef void (*__optr_close_fn_t)(void* param, int32_t num);
|
||||||
|
|
||||||
struct SOperatorInfo;
|
struct SOperatorInfo;
|
||||||
|
|
||||||
|
@ -318,9 +325,9 @@ typedef struct SOperatorInfo {
|
||||||
|
|
||||||
struct SOperatorInfo** pDownstream; // downstram pointer list
|
struct SOperatorInfo** pDownstream; // downstram pointer list
|
||||||
int32_t numOfDownstream; // number of downstream. The value is always ONE expect for join operator
|
int32_t numOfDownstream; // number of downstream. The value is always ONE expect for join operator
|
||||||
__optr_prepare_fn_t prepareFn;
|
__optr_open_fn_t openFn;
|
||||||
__operator_fn_t exec;
|
__optr_fn_t nextDataFn;
|
||||||
__optr_cleanup_fn_t cleanupFn;
|
__optr_close_fn_t closeFn;
|
||||||
} SOperatorInfo;
|
} SOperatorInfo;
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
|
@ -479,9 +486,6 @@ typedef struct SAggOperatorInfo {
|
||||||
|
|
||||||
typedef struct SProjectOperatorInfo {
|
typedef struct SProjectOperatorInfo {
|
||||||
SOptrBasicInfo binfo;
|
SOptrBasicInfo binfo;
|
||||||
int32_t bufCapacity;
|
|
||||||
uint32_t seed;
|
|
||||||
|
|
||||||
SSDataBlock* existDataBlock;
|
SSDataBlock* existDataBlock;
|
||||||
} SProjectOperatorInfo;
|
} SProjectOperatorInfo;
|
||||||
|
|
||||||
|
@ -615,10 +619,10 @@ SOperatorInfo* createTableScanOperatorInfo(void* pTsdbReadHandle, int32_t order,
|
||||||
SOperatorInfo* createTableSeqScanOperatorInfo(void* pTsdbReadHandle, STaskRuntimeEnv* pRuntimeEnv);
|
SOperatorInfo* createTableSeqScanOperatorInfo(void* pTsdbReadHandle, STaskRuntimeEnv* pRuntimeEnv);
|
||||||
SOperatorInfo* createAggregateOperatorInfo(SOperatorInfo* downstream, SArray* pExprInfo, SExecTaskInfo* pTaskInfo, const STableGroupInfo* pTableGroupInfo);
|
SOperatorInfo* createAggregateOperatorInfo(SOperatorInfo* downstream, SArray* pExprInfo, SExecTaskInfo* pTaskInfo, const STableGroupInfo* pTableGroupInfo);
|
||||||
SOperatorInfo* createMultiTableAggOperatorInfo(SOperatorInfo* downstream, SArray* pExprInfo, SExecTaskInfo* pTaskInfo, const STableGroupInfo* pTableGroupInfo);
|
SOperatorInfo* createMultiTableAggOperatorInfo(SOperatorInfo* downstream, SArray* pExprInfo, SExecTaskInfo* pTaskInfo, const STableGroupInfo* pTableGroupInfo);
|
||||||
SOperatorInfo* createProjectOperatorInfo(STaskRuntimeEnv* pRuntimeEnv, SOperatorInfo* downstream, SExprInfo* pExpr,
|
SOperatorInfo* createProjectOperatorInfo(SOperatorInfo* downstream, SArray* pExprInfo, SExecTaskInfo* pTaskInfo);
|
||||||
int32_t numOfOutput);
|
|
||||||
SOperatorInfo* createLimitOperatorInfo(STaskRuntimeEnv* pRuntimeEnv, SOperatorInfo* downstream);
|
SOperatorInfo* createLimitOperatorInfo(STaskRuntimeEnv* pRuntimeEnv, SOperatorInfo* downstream);
|
||||||
SOperatorInfo* createIntervalOperatorInfo(SOperatorInfo* downstream, SArray* pExprInfo, SExecTaskInfo* pTaskInfo);
|
SOperatorInfo* createIntervalOperatorInfo(SOperatorInfo* downstream, SArray* pExprInfo, SInterval* pInterval, SExecTaskInfo* pTaskInfo);
|
||||||
|
|
||||||
SOperatorInfo* createAllTimeIntervalOperatorInfo(STaskRuntimeEnv* pRuntimeEnv, SOperatorInfo* downstream,
|
SOperatorInfo* createAllTimeIntervalOperatorInfo(STaskRuntimeEnv* pRuntimeEnv, SOperatorInfo* downstream,
|
||||||
SExprInfo* pExpr, int32_t numOfOutput);
|
SExprInfo* pExpr, int32_t numOfOutput);
|
||||||
|
@ -654,8 +658,6 @@ SOperatorInfo* createJoinOperatorInfo(SOperatorInfo** pdownstream, int32_t numOf
|
||||||
SOperatorInfo* createOrderOperatorInfo(SOperatorInfo* downstream, SArray* pExprInfo, SArray* pOrderVal, SExecTaskInfo* pTaskInfo);
|
SOperatorInfo* createOrderOperatorInfo(SOperatorInfo* downstream, SArray* pExprInfo, SArray* pOrderVal, SExecTaskInfo* pTaskInfo);
|
||||||
SOperatorInfo* createSortedMergeOperatorInfo(SOperatorInfo** downstream, int32_t numOfDownstream, SArray* pExprInfo, SArray* pOrderVal, SArray* pGroupInfo, SExecTaskInfo* pTaskInfo);
|
SOperatorInfo* createSortedMergeOperatorInfo(SOperatorInfo** downstream, int32_t numOfDownstream, SArray* pExprInfo, SArray* pOrderVal, SArray* pGroupInfo, SExecTaskInfo* pTaskInfo);
|
||||||
|
|
||||||
// SSDataBlock* doGlobalAggregate(void* param, bool* newgroup);
|
|
||||||
// SSDataBlock* doMultiwayMergeSort(void* param, bool* newgroup);
|
|
||||||
// SSDataBlock* doSLimit(void* param, bool* newgroup);
|
// SSDataBlock* doSLimit(void* param, bool* newgroup);
|
||||||
|
|
||||||
// int32_t doCreateFilterInfo(SColumnInfo* pCols, int32_t numOfCols, int32_t numOfFilterCols, SSingleColumnFilterInfo** pFilterInfo, uint64_t qId);
|
// int32_t doCreateFilterInfo(SColumnInfo* pCols, int32_t numOfCols, int32_t numOfFilterCols, SSingleColumnFilterInfo** pFilterInfo, uint64_t qId);
|
||||||
|
|
|
@ -0,0 +1,104 @@
|
||||||
|
/*
|
||||||
|
* 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_TSIMPLEHASH_H
|
||||||
|
#define TDENGINE_TSIMPLEHASH_H
|
||||||
|
|
||||||
|
#include "tarray.h"
|
||||||
|
#include "tlockfree.h"
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
|
typedef uint32_t (*_hash_fn_t)(const char *, uint32_t);
|
||||||
|
typedef int32_t (*_equal_fn_t)(const void *, const void *, size_t len);
|
||||||
|
typedef void (*_hash_free_fn_t)(void *);
|
||||||
|
|
||||||
|
typedef struct SSHashObj SSHashObj;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* init the hash table
|
||||||
|
*
|
||||||
|
* @param capacity initial capacity of the hash table
|
||||||
|
* @param fn hash function to generate the hash value
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
SSHashObj *tSimpleHashInit(size_t capacity, _hash_fn_t fn, size_t keyLen, size_t dataLen);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* return the size of hash table
|
||||||
|
* @param pHashObj
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
int32_t tSimpleHashGetSize(const SSHashObj *pHashObj);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* put element into hash table, if the element with the same key exists, update it
|
||||||
|
* @param pHashObj
|
||||||
|
* @param key
|
||||||
|
* @param data
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
int32_t tSimpleHashPut(SSHashObj *pHashObj, const void *key, const void *data);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* return the payload data with the specified key
|
||||||
|
*
|
||||||
|
* @param pHashObj
|
||||||
|
* @param key
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
void *tSimpleHashGet(SSHashObj *pHashObj, const void *key);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* remove item with the specified key
|
||||||
|
* @param pHashObj
|
||||||
|
* @param key
|
||||||
|
* @param keyLen
|
||||||
|
*/
|
||||||
|
int32_t tSimpleHashRemove(SSHashObj *pHashObj, const void *key);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Clear the hash table.
|
||||||
|
* @param pHashObj
|
||||||
|
*/
|
||||||
|
void tSimpleHashClear(SSHashObj *pHashObj);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Clean up hash table and release all allocated resources.
|
||||||
|
* @param handle
|
||||||
|
*/
|
||||||
|
void tSimpleHashCleanup(SSHashObj *pHashObj);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the hash table size
|
||||||
|
* @param pHashObj
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
size_t tSimpleHashGetMemSize(const SSHashObj *pHashObj);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the corresponding key information for a given data in hash table
|
||||||
|
* @param data
|
||||||
|
* @param keyLen
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
void *tSimpleHashGetKey(const SSHashObj* pHashObj, void *data, size_t* keyLen);
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
#endif // TDENGINE_TSIMPLEHASH_H
|
|
@ -158,7 +158,7 @@ int32_t qExecTask(qTaskInfo_t tinfo, SSDataBlock** pRes, uint64_t *useconds) {
|
||||||
int64_t st = 0;
|
int64_t st = 0;
|
||||||
|
|
||||||
st = taosGetTimestampUs();
|
st = taosGetTimestampUs();
|
||||||
*pRes = pTaskInfo->pRoot->exec(pTaskInfo->pRoot, &newgroup);
|
*pRes = pTaskInfo->pRoot->nextDataFn(pTaskInfo->pRoot, &newgroup);
|
||||||
|
|
||||||
uint64_t el = (taosGetTimestampUs() - st);
|
uint64_t el = (taosGetTimestampUs() - st);
|
||||||
pTaskInfo->cost.elapsedTime += el;
|
pTaskInfo->cost.elapsedTime += el;
|
||||||
|
@ -179,13 +179,6 @@ int32_t qExecTask(qTaskInfo_t tinfo, SSDataBlock** pRes, uint64_t *useconds) {
|
||||||
return pTaskInfo->code;
|
return pTaskInfo->code;
|
||||||
}
|
}
|
||||||
|
|
||||||
void* qGetResultRetrieveMsg(qTaskInfo_t qinfo) {
|
|
||||||
SQInfo* pQInfo = (SQInfo*) qinfo;
|
|
||||||
assert(pQInfo != NULL);
|
|
||||||
|
|
||||||
return pQInfo->rspContext;
|
|
||||||
}
|
|
||||||
|
|
||||||
int32_t qKillTask(qTaskInfo_t qinfo) {
|
int32_t qKillTask(qTaskInfo_t qinfo) {
|
||||||
SExecTaskInfo *pTaskInfo = (SExecTaskInfo *)qinfo;
|
SExecTaskInfo *pTaskInfo = (SExecTaskInfo *)qinfo;
|
||||||
|
|
||||||
|
@ -221,7 +214,7 @@ int32_t qAsyncKillTask(qTaskInfo_t qinfo) {
|
||||||
int32_t qIsTaskCompleted(qTaskInfo_t qinfo) {
|
int32_t qIsTaskCompleted(qTaskInfo_t qinfo) {
|
||||||
SExecTaskInfo *pTaskInfo = (SExecTaskInfo *)qinfo;
|
SExecTaskInfo *pTaskInfo = (SExecTaskInfo *)qinfo;
|
||||||
|
|
||||||
if (pTaskInfo == NULL /*|| !isValidQInfo(pTaskInfo)*/) {
|
if (pTaskInfo == NULL) {
|
||||||
return TSDB_CODE_QRY_INVALID_QHANDLE;
|
return TSDB_CODE_QRY_INVALID_QHANDLE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -235,33 +228,3 @@ void qDestroyTask(qTaskInfo_t qTaskHandle) {
|
||||||
queryCostStatis(pTaskInfo); // print the query cost summary
|
queryCostStatis(pTaskInfo); // print the query cost summary
|
||||||
doDestroyTask(pTaskInfo);
|
doDestroyTask(pTaskInfo);
|
||||||
}
|
}
|
||||||
|
|
||||||
#if 0
|
|
||||||
//kill by qid
|
|
||||||
int32_t qKillQueryByQId(void* pMgmt, int64_t qId, int32_t waitMs, int32_t waitCount) {
|
|
||||||
int32_t error = TSDB_CODE_SUCCESS;
|
|
||||||
void** handle = qAcquireTask(pMgmt, qId);
|
|
||||||
if(handle == NULL) return terrno;
|
|
||||||
|
|
||||||
SQInfo* pQInfo = (SQInfo*)(*handle);
|
|
||||||
if (pQInfo == NULL || !isValidQInfo(pQInfo)) {
|
|
||||||
return TSDB_CODE_QRY_INVALID_QHANDLE;
|
|
||||||
}
|
|
||||||
qWarn("%s be killed(no memory commit).", pQInfo->qId);
|
|
||||||
setTaskKilled(pQInfo);
|
|
||||||
|
|
||||||
// wait query stop
|
|
||||||
int32_t loop = 0;
|
|
||||||
while (pQInfo->owner != 0) {
|
|
||||||
taosMsleep(waitMs);
|
|
||||||
if(loop++ > waitCount){
|
|
||||||
error = TSDB_CODE_FAILED;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
qReleaseTask(pMgmt, (void **)&handle, true);
|
|
||||||
return error;
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif
|
|
||||||
|
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue