Merge branch '3.0' into feature/TD-11274-3.0
This commit is contained in:
commit
79def727b5
|
@ -26,7 +26,7 @@ public class LineProtocolExample {
|
|||
|
||||
private static void createDatabase(Connection conn) throws SQLException {
|
||||
try (Statement stmt = conn.createStatement()) {
|
||||
// the default precision is ms (microsecond), but we use us(microsecond) here.
|
||||
// the default precision is ms (millisecond), but we use us(microsecond) here.
|
||||
stmt.execute("CREATE DATABASE IF NOT EXISTS test PRECISION 'us'");
|
||||
stmt.execute("USE test");
|
||||
}
|
||||
|
|
|
@ -164,6 +164,7 @@ DLL_EXPORT TAOS_RES *taos_query(TAOS *taos, const char *sql);
|
|||
DLL_EXPORT TAOS_ROW taos_fetch_row(TAOS_RES *res);
|
||||
DLL_EXPORT int taos_result_precision(TAOS_RES *res); // get the time precision of result
|
||||
DLL_EXPORT void taos_free_result(TAOS_RES *res);
|
||||
DLL_EXPORT void taos_kill_query(TAOS *taos);
|
||||
DLL_EXPORT int taos_field_count(TAOS_RES *res);
|
||||
DLL_EXPORT int taos_num_fields(TAOS_RES *res);
|
||||
DLL_EXPORT int taos_affected_rows(TAOS_RES *res);
|
||||
|
|
|
@ -216,51 +216,55 @@
|
|||
#define TK_NOW 198
|
||||
#define TK_TODAY 199
|
||||
#define TK_TIMEZONE 200
|
||||
#define TK_COUNT 201
|
||||
#define TK_LAST_ROW 202
|
||||
#define TK_BETWEEN 203
|
||||
#define TK_IS 204
|
||||
#define TK_NK_LT 205
|
||||
#define TK_NK_GT 206
|
||||
#define TK_NK_LE 207
|
||||
#define TK_NK_GE 208
|
||||
#define TK_NK_NE 209
|
||||
#define TK_MATCH 210
|
||||
#define TK_NMATCH 211
|
||||
#define TK_CONTAINS 212
|
||||
#define TK_JOIN 213
|
||||
#define TK_INNER 214
|
||||
#define TK_SELECT 215
|
||||
#define TK_DISTINCT 216
|
||||
#define TK_WHERE 217
|
||||
#define TK_PARTITION 218
|
||||
#define TK_BY 219
|
||||
#define TK_SESSION 220
|
||||
#define TK_STATE_WINDOW 221
|
||||
#define TK_SLIDING 222
|
||||
#define TK_FILL 223
|
||||
#define TK_VALUE 224
|
||||
#define TK_NONE 225
|
||||
#define TK_PREV 226
|
||||
#define TK_LINEAR 227
|
||||
#define TK_NEXT 228
|
||||
#define TK_HAVING 229
|
||||
#define TK_RANGE 230
|
||||
#define TK_EVERY 231
|
||||
#define TK_ORDER 232
|
||||
#define TK_SLIMIT 233
|
||||
#define TK_SOFFSET 234
|
||||
#define TK_LIMIT 235
|
||||
#define TK_OFFSET 236
|
||||
#define TK_ASC 237
|
||||
#define TK_NULLS 238
|
||||
#define TK_ID 239
|
||||
#define TK_NK_BITNOT 240
|
||||
#define TK_INSERT 241
|
||||
#define TK_VALUES 242
|
||||
#define TK_IMPORT 243
|
||||
#define TK_NK_SEMI 244
|
||||
#define TK_FILE 245
|
||||
#define TK_CLIENT_VERSION 201
|
||||
#define TK_SERVER_VERSION 202
|
||||
#define TK_SERVER_STATUS 203
|
||||
#define TK_CURRENT_USER 204
|
||||
#define TK_COUNT 205
|
||||
#define TK_LAST_ROW 206
|
||||
#define TK_BETWEEN 207
|
||||
#define TK_IS 208
|
||||
#define TK_NK_LT 209
|
||||
#define TK_NK_GT 210
|
||||
#define TK_NK_LE 211
|
||||
#define TK_NK_GE 212
|
||||
#define TK_NK_NE 213
|
||||
#define TK_MATCH 214
|
||||
#define TK_NMATCH 215
|
||||
#define TK_CONTAINS 216
|
||||
#define TK_JOIN 217
|
||||
#define TK_INNER 218
|
||||
#define TK_SELECT 219
|
||||
#define TK_DISTINCT 220
|
||||
#define TK_WHERE 221
|
||||
#define TK_PARTITION 222
|
||||
#define TK_BY 223
|
||||
#define TK_SESSION 224
|
||||
#define TK_STATE_WINDOW 225
|
||||
#define TK_SLIDING 226
|
||||
#define TK_FILL 227
|
||||
#define TK_VALUE 228
|
||||
#define TK_NONE 229
|
||||
#define TK_PREV 230
|
||||
#define TK_LINEAR 231
|
||||
#define TK_NEXT 232
|
||||
#define TK_HAVING 233
|
||||
#define TK_RANGE 234
|
||||
#define TK_EVERY 235
|
||||
#define TK_ORDER 236
|
||||
#define TK_SLIMIT 237
|
||||
#define TK_SOFFSET 238
|
||||
#define TK_LIMIT 239
|
||||
#define TK_OFFSET 240
|
||||
#define TK_ASC 241
|
||||
#define TK_NULLS 242
|
||||
#define TK_ID 243
|
||||
#define TK_NK_BITNOT 244
|
||||
#define TK_INSERT 245
|
||||
#define TK_VALUES 246
|
||||
#define TK_IMPORT 247
|
||||
#define TK_NK_SEMI 248
|
||||
#define TK_FILE 249
|
||||
|
||||
#define TK_NK_SPACE 300
|
||||
#define TK_NK_COMMENT 301
|
||||
|
|
|
@ -147,14 +147,6 @@ int32_t catalogInit(SCatalogCfg* cfg);
|
|||
*/
|
||||
int32_t catalogGetHandle(uint64_t clusterId, SCatalog** catalogHandle);
|
||||
|
||||
/**
|
||||
* Free a cluster's all catalog info, usually it's not necessary, until the application is closing.
|
||||
* no current or future usage should be guaranteed by application
|
||||
* @param pCatalog (input, NO more usage)
|
||||
* @return error code
|
||||
*/
|
||||
void catalogFreeHandle(SCatalog* pCatalog);
|
||||
|
||||
int32_t catalogGetDBVgVersion(SCatalog* pCtg, const char* dbFName, int32_t* version, int64_t* dbId, int32_t* tableNum);
|
||||
|
||||
/**
|
||||
|
|
|
@ -36,7 +36,6 @@ typedef struct SReadHandle {
|
|||
void* vnode;
|
||||
void* mnd;
|
||||
SMsgCb* pMsgCb;
|
||||
// int8_t initTsdbReader;
|
||||
} SReadHandle;
|
||||
|
||||
enum {
|
||||
|
@ -140,12 +139,6 @@ int32_t qKillTask(qTaskInfo_t tinfo);
|
|||
*/
|
||||
int32_t qAsyncKillTask(qTaskInfo_t tinfo);
|
||||
|
||||
/**
|
||||
* return whether query is completed or not
|
||||
* @param tinfo
|
||||
* @return
|
||||
*/
|
||||
int32_t qIsTaskCompleted(qTaskInfo_t tinfo);
|
||||
|
||||
/**
|
||||
* destroy query info structure
|
||||
|
@ -176,6 +169,15 @@ int32_t qSerializeTaskStatus(qTaskInfo_t tinfo, char** pOutput, int32_t* len);
|
|||
|
||||
int32_t qDeserializeTaskStatus(qTaskInfo_t tinfo, const char* pInput, int32_t len);
|
||||
|
||||
/**
|
||||
* return the scan info, in the form of tuple of two items, including table uid and current timestamp
|
||||
* @param tinfo
|
||||
* @param uid
|
||||
* @param ts
|
||||
* @return
|
||||
*/
|
||||
int32_t qGetStreamScanStatus(qTaskInfo_t tinfo, uint64_t* uid, int64_t* ts);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
|
|
@ -105,7 +105,7 @@ typedef enum EFunctionType {
|
|||
// system function
|
||||
FUNCTION_TYPE_DATABASE = 3000,
|
||||
FUNCTION_TYPE_CLIENT_VERSION,
|
||||
FUNCTION_TYPE_SERVER_SERSION,
|
||||
FUNCTION_TYPE_SERVER_VERSION,
|
||||
FUNCTION_TYPE_SERVER_STATUS,
|
||||
FUNCTION_TYPE_CURRENT_USER,
|
||||
FUNCTION_TYPE_USER,
|
||||
|
@ -193,6 +193,7 @@ bool fmIsForbidGroupByFunc(int32_t funcId);
|
|||
bool fmIsIntervalInterpoFunc(int32_t funcId);
|
||||
bool fmIsInterpFunc(int32_t funcId);
|
||||
bool fmIsLastRowFunc(int32_t funcId);
|
||||
bool fmIsSystemInfoFunc(int32_t funcId);
|
||||
|
||||
int32_t fmGetDistMethod(const SFunctionNode* pFunc, SFunctionNode** pPartialFunc, SFunctionNode** pMergeFunc);
|
||||
|
||||
|
|
|
@ -89,6 +89,7 @@ typedef struct SValueNode {
|
|||
bool isDuration;
|
||||
bool translate;
|
||||
bool notReserved;
|
||||
bool isNull;
|
||||
int16_t placeholderNo;
|
||||
union {
|
||||
bool b;
|
||||
|
|
|
@ -48,7 +48,7 @@ int32_t qCreateQueryPlan(SPlanContext* pCxt, SQueryPlan** pPlan, SArray* pExecNo
|
|||
// @pSource one execution location of this group of datasource subplans
|
||||
int32_t qSetSubplanExecutionNode(SSubplan* pSubplan, int32_t groupId, SDownstreamSourceNode* pSource);
|
||||
|
||||
int32_t qClearSubplanExecutionNode(SSubplan* pSubplan, int32_t groupId);
|
||||
void qClearSubplanExecutionNode(SSubplan* pSubplan);
|
||||
|
||||
// Convert to subplan to string for the scheduler to send to the executor
|
||||
int32_t qSubPlanToString(const SSubplan* pSubplan, char** pStr, int32_t* pLen);
|
||||
|
|
|
@ -69,18 +69,20 @@ typedef struct SSchdFetchParam {
|
|||
int32_t* code;
|
||||
} SSchdFetchParam;
|
||||
|
||||
typedef void (*schedulerExecCallback)(SQueryResult* pResult, void* param, int32_t code);
|
||||
typedef void (*schedulerFetchCallback)(void* pResult, void* param, int32_t code);
|
||||
typedef void (*schedulerExecFp)(SQueryResult* pResult, void* param, int32_t code);
|
||||
typedef void (*schedulerFetchFp)(void* pResult, void* param, int32_t code);
|
||||
typedef bool (*schedulerChkKillFp)(void* param);
|
||||
|
||||
typedef struct SSchedulerReq {
|
||||
bool *reqKilled;
|
||||
SRequestConnInfo *pConn;
|
||||
SArray *pNodeList;
|
||||
SQueryPlan *pDag;
|
||||
const char *sql;
|
||||
int64_t startTs;
|
||||
schedulerExecCallback fp;
|
||||
void* cbParam;
|
||||
schedulerExecFp execFp;
|
||||
void* execParam;
|
||||
schedulerChkKillFp chkKillFp;
|
||||
void* chkKillParam;
|
||||
} SSchedulerReq;
|
||||
|
||||
|
||||
|
@ -110,7 +112,7 @@ int32_t schedulerExecJob(SSchedulerReq *pReq, int64_t *pJob, SQueryResult *pRes)
|
|||
*/
|
||||
int32_t schedulerFetchRows(int64_t job, void **data);
|
||||
|
||||
void schedulerAsyncFetchRows(int64_t job, schedulerFetchCallback fp, void* param);
|
||||
void schedulerAsyncFetchRows(int64_t job, schedulerFetchFp fp, void* param);
|
||||
|
||||
int32_t schedulerGetTasksStatus(int64_t job, SArray *pSub);
|
||||
|
||||
|
|
|
@ -324,6 +324,23 @@ void syncAppendEntriesPrint2(char* s, const SyncAppendEntries* pMsg);
|
|||
void syncAppendEntriesLog(const SyncAppendEntries* pMsg);
|
||||
void syncAppendEntriesLog2(char* s, const SyncAppendEntries* pMsg);
|
||||
|
||||
// ---------------------------------------------
|
||||
typedef struct SyncAppendEntriesBatch {
|
||||
uint32_t bytes;
|
||||
int32_t vgId;
|
||||
uint32_t msgType;
|
||||
SRaftId srcId;
|
||||
SRaftId destId;
|
||||
// private data
|
||||
SyncTerm term;
|
||||
SyncIndex prevLogIndex;
|
||||
SyncTerm prevLogTerm;
|
||||
SyncIndex commitIndex;
|
||||
SyncTerm privateTerm;
|
||||
uint32_t dataLen;
|
||||
char data[];
|
||||
} SyncAppendEntriesBatch;
|
||||
|
||||
// ---------------------------------------------
|
||||
typedef struct SyncAppendEntriesReply {
|
||||
uint32_t bytes;
|
||||
|
|
|
@ -45,7 +45,7 @@ typedef struct SRpcHandleInfo {
|
|||
int32_t noResp; // has response or not(default 0, 0: resp, 1: no resp);
|
||||
int32_t persistHandle; // persist handle or not
|
||||
STraceId traceId;
|
||||
// int64_t traceId;
|
||||
int8_t hasEpSet;
|
||||
|
||||
// app info
|
||||
void *ahandle; // app handle set by client
|
||||
|
@ -123,7 +123,7 @@ void * rpcReallocCont(void *ptr, int32_t contLen);
|
|||
void rpcSendRequest(void *thandle, const SEpSet *pEpSet, SRpcMsg *pMsg, int64_t *rid);
|
||||
void rpcSendResponse(const SRpcMsg *pMsg);
|
||||
void rpcRegisterBrokenLinkArg(SRpcMsg *msg);
|
||||
void rpcReleaseHandle(void *handle, int8_t type); // just release client conn to rpc instance, no close sock
|
||||
void rpcReleaseHandle(void *handle, int8_t type); // just release conn to rpc instance, no close sock
|
||||
|
||||
// These functions will not be called in the child process
|
||||
void rpcSendRedirectRsp(void *pConn, const SEpSet *pEpSet);
|
||||
|
|
|
@ -466,11 +466,11 @@ int32_t* taosGetErrno();
|
|||
#define TSDB_CODE_CTG_INTERNAL_ERROR TAOS_DEF_ERROR_CODE(0, 0x2400)
|
||||
#define TSDB_CODE_CTG_INVALID_INPUT TAOS_DEF_ERROR_CODE(0, 0x2401)
|
||||
#define TSDB_CODE_CTG_NOT_READY TAOS_DEF_ERROR_CODE(0, 0x2402)
|
||||
#define TSDB_CODE_CTG_MEM_ERROR TAOS_DEF_ERROR_CODE(0, 0x2403)
|
||||
#define TSDB_CODE_CTG_SYS_ERROR TAOS_DEF_ERROR_CODE(0, 0x2404)
|
||||
#define TSDB_CODE_CTG_DB_DROPPED TAOS_DEF_ERROR_CODE(0, 0x2405)
|
||||
#define TSDB_CODE_CTG_OUT_OF_SERVICE TAOS_DEF_ERROR_CODE(0, 0x2406)
|
||||
#define TSDB_CODE_CTG_VG_META_MISMATCH TAOS_DEF_ERROR_CODE(0, 0x2407)
|
||||
#define TSDB_CODE_CTG_SYS_ERROR TAOS_DEF_ERROR_CODE(0, 0x2403)
|
||||
#define TSDB_CODE_CTG_DB_DROPPED TAOS_DEF_ERROR_CODE(0, 0x2404)
|
||||
#define TSDB_CODE_CTG_OUT_OF_SERVICE TAOS_DEF_ERROR_CODE(0, 0x2405)
|
||||
#define TSDB_CODE_CTG_VG_META_MISMATCH TAOS_DEF_ERROR_CODE(0, 0x2406)
|
||||
#define TSDB_CODE_CTG_EXIT TAOS_DEF_ERROR_CODE(0, 0x2407)
|
||||
|
||||
//scheduler&qworker
|
||||
#define TSDB_CODE_SCH_STATUS_ERROR TAOS_DEF_ERROR_CODE(0, 0x2501)
|
||||
|
|
|
@ -181,15 +181,9 @@ cd "${curr_dir}"
|
|||
|
||||
# 2. cmake executable file
|
||||
compile_dir="${top_dir}/debug"
|
||||
if [ -d ${compile_dir} ]; then
|
||||
${csudo}rm -rf ${compile_dir}
|
||||
fi
|
||||
${csudo}rm -rf ${compile_dir}
|
||||
|
||||
if [ "$osType" != "Darwin" ]; then
|
||||
${csudo}mkdir -p ${compile_dir}
|
||||
else
|
||||
mkdir -p ${compile_dir}
|
||||
fi
|
||||
mkdir -p ${compile_dir}
|
||||
cd ${compile_dir}
|
||||
|
||||
if [[ "$allocator" == "jemalloc" ]]; then
|
||||
|
@ -255,9 +249,9 @@ if [ "$osType" != "Darwin" ]; then
|
|||
echo "====do deb package for the ubuntu system===="
|
||||
output_dir="${top_dir}/debs"
|
||||
if [ -d ${output_dir} ]; then
|
||||
${csudo}rm -rf ${output_dir}
|
||||
rm -rf ${output_dir}
|
||||
fi
|
||||
${csudo}mkdir -p ${output_dir}
|
||||
mkdir -p ${output_dir}
|
||||
cd ${script_dir}/deb
|
||||
${csudo}./makedeb.sh ${compile_dir} ${output_dir} ${verNumber} ${cpuType} ${osType} ${verMode} ${verType}
|
||||
|
||||
|
@ -280,9 +274,9 @@ if [ "$osType" != "Darwin" ]; then
|
|||
echo "====do rpm package for the centos system===="
|
||||
output_dir="${top_dir}/rpms"
|
||||
if [ -d ${output_dir} ]; then
|
||||
${csudo}rm -rf ${output_dir}
|
||||
rm -rf ${output_dir}
|
||||
fi
|
||||
${csudo}mkdir -p ${output_dir}
|
||||
mkdir -p ${output_dir}
|
||||
cd ${script_dir}/rpm
|
||||
${csudo}./makerpm.sh ${compile_dir} ${output_dir} ${verNumber} ${cpuType} ${osType} ${verMode} ${verType}
|
||||
|
||||
|
|
|
@ -118,6 +118,7 @@ struct SAppInstInfo {
|
|||
uint64_t clusterId;
|
||||
void* pTransporter;
|
||||
SAppHbMgr* pAppHbMgr;
|
||||
char* instKey;
|
||||
};
|
||||
|
||||
typedef struct SAppInfo {
|
||||
|
@ -139,7 +140,7 @@ typedef struct STscObj {
|
|||
int8_t connType;
|
||||
int32_t acctId;
|
||||
uint32_t connId;
|
||||
TAOS* id; // ref ID returned by taosAddRef
|
||||
int64_t id; // ref ID returned by taosAddRef
|
||||
TdThreadMutex mutex; // used to protect the operation on db
|
||||
int32_t numOfReqs; // number of sqlObj bound to this connection
|
||||
SAppInstInfo* pAppInfo;
|
||||
|
@ -183,7 +184,7 @@ typedef struct SRequestSendRecvBody {
|
|||
void* param;
|
||||
SDataBuf requestMsg;
|
||||
int64_t queryJob; // query job, created according to sql query DAG.
|
||||
struct SQueryPlan* pDag; // the query dag, generated according to the sql statement.
|
||||
int32_t subplanNum;
|
||||
SReqResultInfo resInfo;
|
||||
} SRequestSendRecvBody;
|
||||
|
||||
|
@ -300,6 +301,8 @@ void* createRequest(STscObj* pObj, int32_t type);
|
|||
void destroyRequest(SRequestObj* pRequest);
|
||||
SRequestObj* acquireRequest(int64_t rid);
|
||||
int32_t releaseRequest(int64_t rid);
|
||||
int32_t removeRequest(int64_t rid);
|
||||
void doDestroyRequest(void *p);
|
||||
|
||||
char* getDbOfConnection(STscObj* pObj);
|
||||
void setConnectionDB(STscObj* pTscObj, const char* db);
|
||||
|
@ -334,6 +337,8 @@ int hbHandleRsp(SClientHbBatchRsp* hbRsp);
|
|||
// cluster level
|
||||
SAppHbMgr* appHbMgrInit(SAppInstInfo* pAppInstInfo, char* key);
|
||||
void appHbMgrCleanup(void);
|
||||
void hbRemoveAppHbMrg(SAppHbMgr **pAppHbMgr);
|
||||
void closeAllRequests(SHashObj *pRequests);
|
||||
|
||||
// conn level
|
||||
int hbRegisterConn(SAppHbMgr* pAppHbMgr, int64_t tscRefId, int64_t clusterId, int8_t connType);
|
||||
|
|
|
@ -37,10 +37,12 @@ int32_t clientConnRefPool = -1;
|
|||
static TdThreadOnce tscinit = PTHREAD_ONCE_INIT;
|
||||
volatile int32_t tscInitRes = 0;
|
||||
|
||||
static void registerRequest(SRequestObj *pRequest) {
|
||||
STscObj *pTscObj = acquireTscObj(*(int64_t *)pRequest->pTscObj->id);
|
||||
|
||||
assert(pTscObj != NULL);
|
||||
static int32_t registerRequest(SRequestObj *pRequest) {
|
||||
STscObj *pTscObj = acquireTscObj(pRequest->pTscObj->id);
|
||||
if (NULL == pTscObj) {
|
||||
terrno = TSDB_CODE_TSC_DISCONNECTED;
|
||||
return terrno;
|
||||
}
|
||||
|
||||
// connection has been released already, abort creating request.
|
||||
pRequest->self = taosAddRef(clientReqRefPool, pRequest);
|
||||
|
@ -54,8 +56,10 @@ static void registerRequest(SRequestObj *pRequest) {
|
|||
int32_t currentInst = atomic_add_fetch_64((int64_t *)&pSummary->currentRequests, 1);
|
||||
tscDebug("0x%" PRIx64 " new Request from connObj:0x%" PRIx64
|
||||
", current:%d, app current:%d, total:%d, reqId:0x%" PRIx64,
|
||||
pRequest->self, *(int64_t *)pRequest->pTscObj->id, num, currentInst, total, pRequest->requestId);
|
||||
pRequest->self, pRequest->pTscObj->id, num, currentInst, total, pRequest->requestId);
|
||||
}
|
||||
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
static void deregisterRequest(SRequestObj *pRequest) {
|
||||
|
@ -70,26 +74,23 @@ static void deregisterRequest(SRequestObj *pRequest) {
|
|||
int64_t duration = taosGetTimestampUs() - pRequest->metric.start;
|
||||
tscDebug("0x%" PRIx64 " free Request from connObj: 0x%" PRIx64 ", reqId:0x%" PRIx64 " elapsed:%" PRIu64
|
||||
" ms, current:%d, app current:%d",
|
||||
pRequest->self, *(int64_t *)pTscObj->id, pRequest->requestId, duration / 1000, num, currentInst);
|
||||
releaseTscObj(*(int64_t *)pTscObj->id);
|
||||
pRequest->self, pTscObj->id, pRequest->requestId, duration / 1000, num, currentInst);
|
||||
releaseTscObj(pTscObj->id);
|
||||
}
|
||||
|
||||
// todo close the transporter properly
|
||||
void closeTransporter(STscObj *pTscObj) {
|
||||
if (pTscObj == NULL || pTscObj->pAppInfo->pTransporter == NULL) {
|
||||
void closeTransporter(SAppInstInfo *pAppInfo) {
|
||||
if (pAppInfo == NULL || pAppInfo->pTransporter == NULL) {
|
||||
return;
|
||||
}
|
||||
|
||||
tscDebug("free transporter:%p in connObj: 0x%" PRIx64, pTscObj->pAppInfo->pTransporter, *(int64_t *)pTscObj->id);
|
||||
rpcClose(pTscObj->pAppInfo->pTransporter);
|
||||
tscDebug("free transporter:%p in app inst %p", pAppInfo->pTransporter, pAppInfo);
|
||||
rpcClose(pAppInfo->pTransporter);
|
||||
}
|
||||
|
||||
static bool clientRpcRfp(int32_t code, tmsg_t msgType) {
|
||||
if (code == TSDB_CODE_RPC_REDIRECT || code == TSDB_CODE_RPC_NETWORK_UNAVAIL || code == TSDB_CODE_NODE_NOT_DEPLOYED ||
|
||||
code == TSDB_CODE_SYN_NOT_LEADER || code == TSDB_CODE_APP_NOT_READY) {
|
||||
if (msgType == TDMT_VND_QUERY || msgType == TDMT_VND_FETCH) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
|
@ -123,26 +124,46 @@ void closeAllRequests(SHashObj *pRequests) {
|
|||
while (pIter != NULL) {
|
||||
int64_t *rid = pIter;
|
||||
|
||||
releaseRequest(*rid);
|
||||
removeRequest(*rid);
|
||||
|
||||
pIter = taosHashIterate(pRequests, pIter);
|
||||
}
|
||||
}
|
||||
|
||||
void destroyAppInst(SAppInstInfo *pAppInfo) {
|
||||
tscDebug("destroy app inst mgr %p", pAppInfo);
|
||||
|
||||
taosThreadMutexLock(&appInfo.mutex);
|
||||
|
||||
hbRemoveAppHbMrg(&pAppInfo->pAppHbMgr);
|
||||
taosHashRemove(appInfo.pInstMap, pAppInfo->instKey, strlen(pAppInfo->instKey));
|
||||
|
||||
taosThreadMutexUnlock(&appInfo.mutex);
|
||||
|
||||
taosMemoryFreeClear(pAppInfo->instKey);
|
||||
closeTransporter(pAppInfo);
|
||||
|
||||
taosThreadMutexLock(&pAppInfo->qnodeMutex);
|
||||
taosArrayDestroy(pAppInfo->pQnodeList);
|
||||
taosThreadMutexUnlock(&pAppInfo->qnodeMutex);
|
||||
|
||||
taosMemoryFree(pAppInfo);
|
||||
}
|
||||
|
||||
void destroyTscObj(void *pObj) {
|
||||
STscObj *pTscObj = pObj;
|
||||
|
||||
SClientHbKey connKey = {.tscRid = *(int64_t *)pTscObj->id, .connType = pTscObj->connType};
|
||||
SClientHbKey connKey = {.tscRid = pTscObj->id, .connType = pTscObj->connType};
|
||||
hbDeregisterConn(pTscObj->pAppInfo->pAppHbMgr, connKey);
|
||||
int64_t connNum = atomic_sub_fetch_64(&pTscObj->pAppInfo->numOfConns, 1);
|
||||
closeAllRequests(pTscObj->pRequests);
|
||||
schedulerStopQueryHb(pTscObj->pAppInfo->pTransporter);
|
||||
if (0 == connNum) {
|
||||
// TODO
|
||||
// closeTransporter(pTscObj);
|
||||
}
|
||||
tscDebug("connObj 0x%" PRIx64 " destroyed, totalConn:%" PRId64, *(int64_t *)pTscObj->id,
|
||||
tscDebug("connObj 0x%" PRIx64 " p:%p destroyed, remain inst totalConn:%" PRId64, pTscObj->id, pTscObj,
|
||||
pTscObj->pAppInfo->numOfConns);
|
||||
|
||||
if (0 == connNum) {
|
||||
destroyAppInst(pTscObj->pAppInfo);
|
||||
}
|
||||
taosThreadMutexDestroy(&pTscObj->mutex);
|
||||
taosMemoryFreeClear(pTscObj);
|
||||
}
|
||||
|
@ -171,11 +192,12 @@ void *createTscObj(const char *user, const char *auth, const char *db, int32_t c
|
|||
}
|
||||
|
||||
taosThreadMutexInit(&pObj->mutex, NULL);
|
||||
pObj->id = taosMemoryMalloc(sizeof(int64_t));
|
||||
*(int64_t *)pObj->id = taosAddRef(clientConnRefPool, pObj);
|
||||
pObj->id = taosAddRef(clientConnRefPool, pObj);
|
||||
pObj->schemalessType = 1;
|
||||
|
||||
tscDebug("connObj created, 0x%" PRIx64, *(int64_t *)pObj->id);
|
||||
atomic_add_fetch_64(&pObj->pAppInfo->numOfConns, 1);
|
||||
|
||||
tscDebug("connObj created, 0x%" PRIx64 ",p:%p", pObj->id, pObj);
|
||||
return pObj;
|
||||
}
|
||||
|
||||
|
@ -205,7 +227,10 @@ void *createRequest(STscObj *pObj, int32_t type) {
|
|||
pRequest->msgBufLen = ERROR_MSG_BUF_DEFAULT_SIZE;
|
||||
tsem_init(&pRequest->body.rspSem, 0, 0);
|
||||
|
||||
registerRequest(pRequest);
|
||||
if (registerRequest(pRequest)) {
|
||||
doDestroyRequest(pRequest);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return pRequest;
|
||||
}
|
||||
|
@ -227,12 +252,16 @@ void doFreeReqResultInfo(SReqResultInfo *pResInfo) {
|
|||
}
|
||||
}
|
||||
|
||||
static void doDestroyRequest(void *p) {
|
||||
SRequestObj *acquireRequest(int64_t rid) { return (SRequestObj *)taosAcquireRef(clientReqRefPool, rid); }
|
||||
|
||||
int32_t releaseRequest(int64_t rid) { return taosReleaseRef(clientReqRefPool, rid); }
|
||||
|
||||
int32_t removeRequest(int64_t rid) { return taosRemoveRef(clientReqRefPool, rid); }
|
||||
|
||||
void doDestroyRequest(void *p) {
|
||||
assert(p != NULL);
|
||||
SRequestObj *pRequest = (SRequestObj *)p;
|
||||
|
||||
assert(RID_VALID(pRequest->self));
|
||||
|
||||
taosHashRemove(pRequest->pTscObj->pRequests, &pRequest->self, sizeof(pRequest->self));
|
||||
|
||||
if (pRequest->body.queryJob != 0) {
|
||||
|
@ -244,14 +273,15 @@ static void doDestroyRequest(void *p) {
|
|||
taosMemoryFreeClear(pRequest->pDb);
|
||||
|
||||
doFreeReqResultInfo(&pRequest->body.resInfo);
|
||||
qDestroyQueryPlan(pRequest->body.pDag);
|
||||
|
||||
taosArrayDestroy(pRequest->tableList);
|
||||
taosArrayDestroy(pRequest->dbList);
|
||||
|
||||
destroyQueryExecRes(&pRequest->body.resInfo.execRes);
|
||||
|
||||
if (pRequest->self) {
|
||||
deregisterRequest(pRequest);
|
||||
}
|
||||
taosMemoryFreeClear(pRequest);
|
||||
}
|
||||
|
||||
|
@ -260,13 +290,9 @@ void destroyRequest(SRequestObj *pRequest) {
|
|||
return;
|
||||
}
|
||||
|
||||
taosRemoveRef(clientReqRefPool, pRequest->self);
|
||||
removeRequest(pRequest->self);
|
||||
}
|
||||
|
||||
SRequestObj *acquireRequest(int64_t rid) { return (SRequestObj *)taosAcquireRef(clientReqRefPool, rid); }
|
||||
|
||||
int32_t releaseRequest(int64_t rid) { return taosReleaseRef(clientReqRefPool, rid); }
|
||||
|
||||
void taos_init_imp(void) {
|
||||
// In the APIs of other program language, taos_cleanup is not available yet.
|
||||
// So, to make sure taos_cleanup will be invoked to clean up the allocated resource to suppress the valgrind warning.
|
||||
|
|
|
@ -66,25 +66,31 @@ static int32_t hbProcessDBInfoRsp(void *value, int32_t valueLen, struct SCatalog
|
|||
if (rsp->vgVersion < 0) {
|
||||
code = catalogRemoveDB(pCatalog, rsp->db, rsp->uid);
|
||||
} else {
|
||||
SDBVgInfo vgInfo = {0};
|
||||
vgInfo.vgVersion = rsp->vgVersion;
|
||||
vgInfo.hashMethod = rsp->hashMethod;
|
||||
vgInfo.vgHash = taosHashInit(rsp->vgNum, taosGetDefaultHashFunction(TSDB_DATA_TYPE_INT), true, HASH_ENTRY_LOCK);
|
||||
if (NULL == vgInfo.vgHash) {
|
||||
SDBVgInfo *vgInfo = taosMemoryCalloc(1, sizeof(SDBVgInfo));
|
||||
if (NULL == vgInfo) {
|
||||
return TSDB_CODE_TSC_OUT_OF_MEMORY;
|
||||
}
|
||||
|
||||
vgInfo->vgVersion = rsp->vgVersion;
|
||||
vgInfo->hashMethod = rsp->hashMethod;
|
||||
vgInfo->vgHash = taosHashInit(rsp->vgNum, taosGetDefaultHashFunction(TSDB_DATA_TYPE_INT), true, HASH_ENTRY_LOCK);
|
||||
if (NULL == vgInfo->vgHash) {
|
||||
taosMemoryFree(vgInfo);
|
||||
tscError("hash init[%d] failed", rsp->vgNum);
|
||||
return TSDB_CODE_TSC_OUT_OF_MEMORY;
|
||||
}
|
||||
|
||||
for (int32_t j = 0; j < rsp->vgNum; ++j) {
|
||||
SVgroupInfo *pInfo = taosArrayGet(rsp->pVgroupInfos, j);
|
||||
if (taosHashPut(vgInfo.vgHash, &pInfo->vgId, sizeof(int32_t), pInfo, sizeof(SVgroupInfo)) != 0) {
|
||||
if (taosHashPut(vgInfo->vgHash, &pInfo->vgId, sizeof(int32_t), pInfo, sizeof(SVgroupInfo)) != 0) {
|
||||
tscError("hash push failed, errno:%d", errno);
|
||||
taosHashCleanup(vgInfo.vgHash);
|
||||
taosHashCleanup(vgInfo->vgHash);
|
||||
taosMemoryFree(vgInfo);
|
||||
return TSDB_CODE_TSC_OUT_OF_MEMORY;
|
||||
}
|
||||
}
|
||||
|
||||
catalogUpdateDBVgInfo(pCatalog, rsp->db, rsp->uid, &vgInfo);
|
||||
catalogUpdateDBVgInfo(pCatalog, rsp->db, rsp->uid, vgInfo);
|
||||
}
|
||||
|
||||
if (code) {
|
||||
|
@ -269,8 +275,11 @@ static int32_t hbAsyncCallBack(void *param, const SDataBuf *pMsg, int32_t code)
|
|||
|
||||
int32_t rspNum = taosArrayGetSize(pRsp.rsps);
|
||||
|
||||
taosThreadMutexLock(&appInfo.mutex);
|
||||
|
||||
SAppInstInfo **pInst = taosHashGet(appInfo.pInstMap, key, strlen(key));
|
||||
if (pInst == NULL || NULL == *pInst) {
|
||||
taosThreadMutexUnlock(&appInfo.mutex);
|
||||
tscError("cluster not exist, key:%s", key);
|
||||
taosMemoryFreeClear(param);
|
||||
tFreeClientHbBatchRsp(&pRsp);
|
||||
|
@ -294,6 +303,8 @@ static int32_t hbAsyncCallBack(void *param, const SDataBuf *pMsg, int32_t code)
|
|||
}
|
||||
}
|
||||
|
||||
taosThreadMutexUnlock(&appInfo.mutex);
|
||||
|
||||
tFreeClientHbBatchRsp(&pRsp);
|
||||
|
||||
return code;
|
||||
|
@ -320,7 +331,7 @@ int32_t hbBuildQueryDesc(SQueryHbReqBasic *hbBasic, STscObj *pObj) {
|
|||
desc.reqRid = pRequest->self;
|
||||
desc.stableQuery = pRequest->stableQuery;
|
||||
taosGetFqdn(desc.fqdn);
|
||||
desc.subPlanNum = pRequest->body.pDag ? pRequest->body.pDag->numOfSubplans : 0;
|
||||
desc.subPlanNum = pRequest->body.subplanNum;
|
||||
|
||||
if (desc.subPlanNum) {
|
||||
desc.subDesc = taosArrayInit(desc.subPlanNum, sizeof(SQuerySubDesc));
|
||||
|
@ -790,11 +801,7 @@ SAppHbMgr *appHbMgrInit(SAppInstInfo *pAppInstInfo, char *key) {
|
|||
return pAppHbMgr;
|
||||
}
|
||||
|
||||
void appHbMgrCleanup(void) {
|
||||
int sz = taosArrayGetSize(clientHbMgr.appHbMgrs);
|
||||
for (int i = 0; i < sz; i++) {
|
||||
SAppHbMgr *pTarget = taosArrayGetP(clientHbMgr.appHbMgrs, i);
|
||||
|
||||
void hbFreeAppHbMgr(SAppHbMgr *pTarget) {
|
||||
void *pIter = taosHashIterate(pTarget->activeInfo, NULL);
|
||||
while (pIter != NULL) {
|
||||
SClientHbReq *pOneReq = pIter;
|
||||
|
@ -806,6 +813,28 @@ void appHbMgrCleanup(void) {
|
|||
|
||||
taosMemoryFree(pTarget->key);
|
||||
taosMemoryFree(pTarget);
|
||||
}
|
||||
|
||||
void hbRemoveAppHbMrg(SAppHbMgr **pAppHbMgr) {
|
||||
taosThreadMutexLock(&clientHbMgr.lock);
|
||||
int32_t mgrSize = taosArrayGetSize(clientHbMgr.appHbMgrs);
|
||||
for (int32_t i = 0; i < mgrSize; ++i) {
|
||||
SAppHbMgr *pItem = taosArrayGetP(clientHbMgr.appHbMgrs, i);
|
||||
if (pItem == *pAppHbMgr) {
|
||||
hbFreeAppHbMgr(*pAppHbMgr);
|
||||
*pAppHbMgr = NULL;
|
||||
taosArrayRemove(clientHbMgr.appHbMgrs, i);
|
||||
break;
|
||||
}
|
||||
}
|
||||
taosThreadMutexUnlock(&clientHbMgr.lock);
|
||||
}
|
||||
|
||||
void appHbMgrCleanup(void) {
|
||||
int sz = taosArrayGetSize(clientHbMgr.appHbMgrs);
|
||||
for (int i = 0; i < sz; i++) {
|
||||
SAppHbMgr *pTarget = taosArrayGetP(clientHbMgr.appHbMgrs, i);
|
||||
hbFreeAppHbMgr(pTarget);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -55,6 +55,18 @@ static char* getClusterKey(const char* user, const char* auth, const char* ip, i
|
|||
return strdup(key);
|
||||
}
|
||||
|
||||
bool chkRequestKilled(void* param) {
|
||||
bool killed = false;
|
||||
SRequestObj* pRequest = acquireRequest((int64_t)param);
|
||||
if (NULL == pRequest || pRequest->killed) {
|
||||
killed = true;
|
||||
}
|
||||
|
||||
releaseRequest((int64_t)param);
|
||||
|
||||
return killed;
|
||||
}
|
||||
|
||||
static STscObj* taosConnectImpl(const char* user, const char* auth, const char* db, __taos_async_fn_t fp, void* param,
|
||||
SAppInstInfo* pAppInfo, int connType);
|
||||
|
||||
|
@ -122,6 +134,9 @@ STscObj* taos_connect_internal(const char* ip, const char* user, const char* pas
|
|||
p->pTransporter = openTransporter(user, secretEncrypt, tsNumOfCores);
|
||||
p->pAppHbMgr = appHbMgrInit(p, key);
|
||||
taosHashPut(appInfo.pInstMap, key, strlen(key), &p, POINTER_BYTES);
|
||||
p->instKey = key;
|
||||
key = NULL;
|
||||
tscDebug("new app inst mgr %p, user:%s, ip:%s, port:%d", p, user, ip, port);
|
||||
|
||||
pInst = &p;
|
||||
}
|
||||
|
@ -609,58 +624,6 @@ _return:
|
|||
return code;
|
||||
}
|
||||
|
||||
int32_t scheduleAsyncQuery(SRequestObj* pRequest, SQueryPlan* pDag, SArray* pNodeList) {
|
||||
tsem_init(&schdRspSem, 0, 0);
|
||||
|
||||
SQueryResult res = {.code = 0, .numOfRows = 0};
|
||||
SRequestConnInfo conn = {.pTrans = pRequest->pTscObj->pAppInfo->pTransporter,
|
||||
.requestId = pRequest->requestId,
|
||||
.requestObjRefId = pRequest->self};
|
||||
SSchedulerReq req = {.pConn = &conn,
|
||||
.pNodeList = pNodeList,
|
||||
.pDag = pDag,
|
||||
.sql = pRequest->sqlstr,
|
||||
.startTs = pRequest->metric.start,
|
||||
.fp = schdExecCallback,
|
||||
.cbParam = &res};
|
||||
|
||||
int32_t code = schedulerAsyncExecJob(&req, &pRequest->body.queryJob);
|
||||
|
||||
pRequest->body.resInfo.execRes = res.res;
|
||||
|
||||
while (true) {
|
||||
if (code != TSDB_CODE_SUCCESS) {
|
||||
if (pRequest->body.queryJob != 0) {
|
||||
schedulerFreeJob(pRequest->body.queryJob, 0);
|
||||
}
|
||||
|
||||
pRequest->code = code;
|
||||
terrno = code;
|
||||
return pRequest->code;
|
||||
} else {
|
||||
tsem_wait(&schdRspSem);
|
||||
|
||||
if (res.code) {
|
||||
code = res.code;
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (TDMT_VND_SUBMIT == pRequest->type || TDMT_VND_CREATE_TABLE == pRequest->type) {
|
||||
pRequest->body.resInfo.numOfRows = res.numOfRows;
|
||||
|
||||
if (pRequest->body.queryJob != 0) {
|
||||
schedulerFreeJob(pRequest->body.queryJob, 0);
|
||||
}
|
||||
}
|
||||
|
||||
pRequest->code = res.code;
|
||||
terrno = res.code;
|
||||
return pRequest->code;
|
||||
}
|
||||
|
||||
int32_t scheduleQuery(SRequestObj* pRequest, SQueryPlan* pDag, SArray* pNodeList) {
|
||||
void* pTransporter = pRequest->pTscObj->pAppInfo->pTransporter;
|
||||
|
||||
|
@ -673,9 +636,10 @@ int32_t scheduleQuery(SRequestObj* pRequest, SQueryPlan* pDag, SArray* pNodeList
|
|||
.pDag = pDag,
|
||||
.sql = pRequest->sqlstr,
|
||||
.startTs = pRequest->metric.start,
|
||||
.fp = NULL,
|
||||
.cbParam = NULL,
|
||||
.reqKilled = &pRequest->killed};
|
||||
.execFp = NULL,
|
||||
.execParam = NULL,
|
||||
.chkKillFp = chkRequestKilled,
|
||||
.chkKillParam = (void*)pRequest->self};
|
||||
|
||||
int32_t code = schedulerExecJob(&req, &pRequest->body.queryJob, &res);
|
||||
pRequest->body.resInfo.execRes = res.res;
|
||||
|
@ -875,14 +839,18 @@ SRequestObj* launchQueryImpl(SRequestObj* pRequest, SQuery* pQuery, bool keepQue
|
|||
break;
|
||||
case QUERY_EXEC_MODE_SCHEDULE: {
|
||||
SArray* pMnodeList = taosArrayInit(4, sizeof(SQueryNodeLoad));
|
||||
code = getPlan(pRequest, pQuery, &pRequest->body.pDag, pMnodeList);
|
||||
if (TSDB_CODE_SUCCESS == code && !pRequest->validateOnly) {
|
||||
SQueryPlan* pDag = NULL;
|
||||
code = getPlan(pRequest, pQuery, &pDag, pMnodeList);
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
pRequest->body.subplanNum = pDag->numOfSubplans;
|
||||
if (!pRequest->validateOnly) {
|
||||
SArray* pNodeList = NULL;
|
||||
buildSyncExecNodeList(pRequest, &pNodeList, pMnodeList);
|
||||
|
||||
code = scheduleQuery(pRequest, pRequest->body.pDag, pNodeList);
|
||||
code = scheduleQuery(pRequest, pDag, pNodeList);
|
||||
taosArrayDestroy(pNodeList);
|
||||
}
|
||||
}
|
||||
taosArrayDestroy(pMnodeList);
|
||||
break;
|
||||
}
|
||||
|
@ -959,10 +927,13 @@ void launchAsyncQuery(SRequestObj* pRequest, SQuery* pQuery, SMetaData* pResultM
|
|||
.pUser = pRequest->pTscObj->user};
|
||||
|
||||
SAppInstInfo* pAppInfo = getAppInfo(pRequest);
|
||||
code = qCreateQueryPlan(&cxt, &pRequest->body.pDag, pMnodeList);
|
||||
SQueryPlan* pDag = NULL;
|
||||
code = qCreateQueryPlan(&cxt, &pDag, pMnodeList);
|
||||
if (code) {
|
||||
tscError("0x%" PRIx64 " failed to create query plan, code:%s 0x%" PRIx64, pRequest->self, tstrerror(code),
|
||||
pRequest->requestId);
|
||||
} else {
|
||||
pRequest->body.subplanNum = pDag->numOfSubplans;
|
||||
}
|
||||
|
||||
if (TSDB_CODE_SUCCESS == code && !pRequest->validateOnly) {
|
||||
|
@ -973,12 +944,13 @@ void launchAsyncQuery(SRequestObj* pRequest, SQuery* pQuery, SMetaData* pResultM
|
|||
.pTrans = pAppInfo->pTransporter, .requestId = pRequest->requestId, .requestObjRefId = pRequest->self};
|
||||
SSchedulerReq req = {.pConn = &conn,
|
||||
.pNodeList = pNodeList,
|
||||
.pDag = pRequest->body.pDag,
|
||||
.pDag = pDag,
|
||||
.sql = pRequest->sqlstr,
|
||||
.startTs = pRequest->metric.start,
|
||||
.fp = schedulerExecCb,
|
||||
.cbParam = pRequest,
|
||||
.reqKilled = &pRequest->killed};
|
||||
.execFp = schedulerExecCb,
|
||||
.execParam = pRequest,
|
||||
.chkKillFp = chkRequestKilled,
|
||||
.chkKillParam = (void*)pRequest->self};
|
||||
code = schedulerAsyncExecJob(&req, &pRequest->body.queryJob);
|
||||
taosArrayDestroy(pNodeList);
|
||||
} else {
|
||||
|
@ -1163,7 +1135,7 @@ STscObj* taosConnectImpl(const char* user, const char* auth, const char* db, __t
|
|||
taos_close_internal(pTscObj);
|
||||
pTscObj = NULL;
|
||||
} else {
|
||||
tscDebug("0x%" PRIx64 " connection is opening, connId:%u, dnodeConn:%p, reqId:0x%" PRIx64, *(int64_t*)pTscObj->id,
|
||||
tscDebug("0x%" PRIx64 " connection is opening, connId:%u, dnodeConn:%p, reqId:0x%" PRIx64, pTscObj->id,
|
||||
pTscObj->connId, pTscObj->pAppInfo->pTransporter, pRequest->requestId);
|
||||
destroyRequest(pRequest);
|
||||
}
|
||||
|
@ -1326,7 +1298,9 @@ TAOS* taos_connect_auth(const char* ip, const char* user, const char* auth, cons
|
|||
|
||||
STscObj* pObj = taos_connect_internal(ip, user, NULL, auth, db, port, CONN_TYPE__QUERY);
|
||||
if (pObj) {
|
||||
return pObj->id;
|
||||
int64_t* rid = taosMemoryCalloc(1, sizeof(int64_t));
|
||||
*rid = pObj->id;
|
||||
return (TAOS*)rid;
|
||||
}
|
||||
|
||||
return NULL;
|
||||
|
@ -2001,17 +1975,26 @@ void syncCatalogFn(SMetaData* pResult, void* param, int32_t code) {
|
|||
void syncQueryFn(void* param, void* res, int32_t code) {
|
||||
SSyncQueryParam* pParam = param;
|
||||
pParam->pRequest = res;
|
||||
if (pParam->pRequest) {
|
||||
pParam->pRequest->code = code;
|
||||
}
|
||||
|
||||
tsem_post(&pParam->sem);
|
||||
}
|
||||
|
||||
void taosAsyncQueryImpl(TAOS* taos, const char* sql, __taos_async_fn_t fp, void* param, bool validateOnly) {
|
||||
STscObj* pTscObj = acquireTscObj(*(int64_t*)taos);
|
||||
if (NULL == taos) {
|
||||
terrno = TSDB_CODE_TSC_DISCONNECTED;
|
||||
fp(param, NULL, terrno);
|
||||
return;
|
||||
}
|
||||
|
||||
int64_t rid = *(int64_t*)taos;
|
||||
STscObj* pTscObj = acquireTscObj(rid);
|
||||
if (pTscObj == NULL || sql == NULL || NULL == fp) {
|
||||
terrno = TSDB_CODE_INVALID_PARA;
|
||||
if (pTscObj) {
|
||||
releaseTscObj(*(int64_t*)taos);
|
||||
releaseTscObj(rid);
|
||||
} else {
|
||||
terrno = TSDB_CODE_TSC_DISCONNECTED;
|
||||
}
|
||||
|
@ -2023,6 +2006,7 @@ void taosAsyncQueryImpl(TAOS* taos, const char* sql, __taos_async_fn_t fp, void*
|
|||
if (sqlLen > (size_t)TSDB_MAX_ALLOWED_SQL_LEN) {
|
||||
tscError("sql string exceeds max length:%d", TSDB_MAX_ALLOWED_SQL_LEN);
|
||||
terrno = TSDB_CODE_TSC_EXCEED_SQL_LIMIT;
|
||||
releaseTscObj(rid);
|
||||
|
||||
fp(param, NULL, terrno);
|
||||
return;
|
||||
|
@ -2032,6 +2016,7 @@ void taosAsyncQueryImpl(TAOS* taos, const char* sql, __taos_async_fn_t fp, void*
|
|||
int32_t code = buildRequest(pTscObj, sql, sqlLen, &pRequest);
|
||||
if (code != TSDB_CODE_SUCCESS) {
|
||||
terrno = code;
|
||||
releaseTscObj(rid);
|
||||
fp(param, NULL, terrno);
|
||||
return;
|
||||
}
|
||||
|
@ -2040,6 +2025,7 @@ void taosAsyncQueryImpl(TAOS* taos, const char* sql, __taos_async_fn_t fp, void*
|
|||
pRequest->body.queryFp = fp;
|
||||
pRequest->body.param = param;
|
||||
doAsyncQuery(pRequest, false);
|
||||
releaseTscObj(rid);
|
||||
}
|
||||
|
||||
TAOS_RES* taosQueryImpl(TAOS* taos, const char* sql, bool validateOnly) {
|
||||
|
@ -2048,7 +2034,8 @@ TAOS_RES* taosQueryImpl(TAOS* taos, const char* sql, bool validateOnly) {
|
|||
return NULL;
|
||||
}
|
||||
|
||||
STscObj* pTscObj = acquireTscObj(*(int64_t*)taos);
|
||||
int64_t rid = *(int64_t*)taos;
|
||||
STscObj* pTscObj = acquireTscObj(rid);
|
||||
if (pTscObj == NULL || sql == NULL) {
|
||||
terrno = TSDB_CODE_TSC_DISCONNECTED;
|
||||
return NULL;
|
||||
|
@ -2058,16 +2045,16 @@ TAOS_RES* taosQueryImpl(TAOS* taos, const char* sql, bool validateOnly) {
|
|||
SSyncQueryParam* param = taosMemoryCalloc(1, sizeof(SSyncQueryParam));
|
||||
tsem_init(¶m->sem, 0, 0);
|
||||
|
||||
taosAsyncQueryImpl(taos, sql, syncQueryFn, param, validateOnly);
|
||||
taosAsyncQueryImpl((TAOS*)&rid, sql, syncQueryFn, param, validateOnly);
|
||||
tsem_wait(¶m->sem);
|
||||
|
||||
releaseTscObj(*(int64_t*)taos);
|
||||
releaseTscObj(rid);
|
||||
|
||||
return param->pRequest;
|
||||
#else
|
||||
size_t sqlLen = strlen(sql);
|
||||
if (sqlLen > (size_t)TSDB_MAX_ALLOWED_SQL_LEN) {
|
||||
releaseTscObj(*(int64_t*)taos);
|
||||
releaseTscObj(rid);
|
||||
tscError("sql string exceeds max length:%d", TSDB_MAX_ALLOWED_SQL_LEN);
|
||||
terrno = TSDB_CODE_TSC_EXCEED_SQL_LIMIT;
|
||||
return NULL;
|
||||
|
@ -2075,7 +2062,7 @@ TAOS_RES* taosQueryImpl(TAOS* taos, const char* sql, bool validateOnly) {
|
|||
|
||||
TAOS_RES* pRes = execQuery(pTscObj, sql, sqlLen, validateOnly);
|
||||
|
||||
releaseTscObj(*(int64_t*)taos);
|
||||
releaseTscObj(rid);
|
||||
|
||||
return pRes;
|
||||
#endif
|
||||
|
|
|
@ -106,7 +106,9 @@ TAOS *taos_connect(const char *ip, const char *user, const char *pass, const cha
|
|||
|
||||
STscObj *pObj = taos_connect_internal(ip, user, pass, NULL, db, port, CONN_TYPE__QUERY);
|
||||
if (pObj) {
|
||||
return pObj->id;
|
||||
int64_t *rid = taosMemoryCalloc(1, sizeof(int64_t));
|
||||
*rid = pObj->id;
|
||||
return (TAOS*)rid;
|
||||
}
|
||||
|
||||
return NULL;
|
||||
|
@ -118,9 +120,9 @@ void taos_close_internal(void *taos) {
|
|||
}
|
||||
|
||||
STscObj *pTscObj = (STscObj *)taos;
|
||||
tscDebug("0x%" PRIx64 " try to close connection, numOfReq:%d", *(int64_t *)pTscObj->id, pTscObj->numOfReqs);
|
||||
tscDebug("0x%" PRIx64 " try to close connection, numOfReq:%d", pTscObj->id, pTscObj->numOfReqs);
|
||||
|
||||
taosRemoveRef(clientConnRefPool, *(int64_t *)pTscObj->id);
|
||||
taosRemoveRef(clientConnRefPool, pTscObj->id);
|
||||
}
|
||||
|
||||
void taos_close(TAOS *taos) {
|
||||
|
@ -192,6 +194,17 @@ void taos_free_result(TAOS_RES *res) {
|
|||
}
|
||||
}
|
||||
|
||||
void taos_kill_query(TAOS *taos) {
|
||||
if (NULL == taos) {
|
||||
return;
|
||||
}
|
||||
int64_t rid = *(int64_t*)taos;
|
||||
|
||||
STscObj* pTscObj = acquireTscObj(rid);
|
||||
closeAllRequests(pTscObj->pRequests);
|
||||
releaseTscObj(rid);
|
||||
}
|
||||
|
||||
int taos_field_count(TAOS_RES *res) {
|
||||
if (res == NULL || TD_RES_TMQ_META(res)) {
|
||||
return 0;
|
||||
|
@ -727,6 +740,8 @@ int32_t createParseContext(const SRequestObj *pRequest, SParseContext **pCxt) {
|
|||
.schemalessType = pTscObj->schemalessType,
|
||||
.isSuperUser = (0 == strcmp(pTscObj->user, TSDB_DEFAULT_USER)),
|
||||
.async = true,
|
||||
.svrVer = pTscObj->sVer,
|
||||
.nodeOffline = (pTscObj->pAppInfo->onlineDnodes < pTscObj->pAppInfo->totalDnodes)
|
||||
};
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
@ -893,6 +908,12 @@ void taos_unsubscribe(TAOS_SUB *tsub, int keepProgress) {
|
|||
}
|
||||
|
||||
int taos_load_table_info(TAOS *taos, const char *tableNameList) {
|
||||
if (NULL == taos) {
|
||||
terrno = TSDB_CODE_TSC_DISCONNECTED;
|
||||
return terrno;
|
||||
}
|
||||
|
||||
int64_t rid = *(int64_t*)taos;
|
||||
const int32_t MAX_TABLE_NAME_LENGTH = 12 * 1024 * 1024; // 12MB list
|
||||
int32_t code = 0;
|
||||
SRequestObj *pRequest = NULL;
|
||||
|
@ -910,7 +931,7 @@ int taos_load_table_info(TAOS *taos, const char *tableNameList) {
|
|||
return TSDB_CODE_TSC_INVALID_OPERATION;
|
||||
}
|
||||
|
||||
STscObj *pTscObj = acquireTscObj(*(int64_t *)taos);
|
||||
STscObj *pTscObj = acquireTscObj(rid);
|
||||
if (pTscObj == NULL) {
|
||||
terrno = TSDB_CODE_TSC_DISCONNECTED;
|
||||
return terrno;
|
||||
|
@ -955,7 +976,7 @@ _return:
|
|||
taosArrayDestroy(catalogReq.pTableMeta);
|
||||
destroyRequest(pRequest);
|
||||
|
||||
releaseTscObj(*(int64_t *)taos);
|
||||
releaseTscObj(rid);
|
||||
|
||||
return code;
|
||||
}
|
||||
|
|
|
@ -77,7 +77,7 @@ int32_t processConnectRsp(void* param, const SDataBuf* pMsg, int32_t code) {
|
|||
|
||||
for (int32_t i = 0; i < connectRsp.epSet.numOfEps; ++i) {
|
||||
tscDebug("0x%" PRIx64 " epSet.fqdn[%d]:%s port:%d, connObj:0x%" PRIx64, pRequest->requestId, i,
|
||||
connectRsp.epSet.eps[i].fqdn, connectRsp.epSet.eps[i].port, *(int64_t*)pTscObj->id);
|
||||
connectRsp.epSet.eps[i].fqdn, connectRsp.epSet.eps[i].port, pTscObj->id);
|
||||
}
|
||||
|
||||
pTscObj->connId = connectRsp.connId;
|
||||
|
@ -87,11 +87,10 @@ int32_t processConnectRsp(void* param, const SDataBuf* pMsg, int32_t code) {
|
|||
|
||||
// update the appInstInfo
|
||||
pTscObj->pAppInfo->clusterId = connectRsp.clusterId;
|
||||
atomic_add_fetch_64(&pTscObj->pAppInfo->numOfConns, 1);
|
||||
|
||||
pTscObj->connType = connectRsp.connType;
|
||||
|
||||
hbRegisterConn(pTscObj->pAppInfo->pAppHbMgr, *(int64_t*)pTscObj->id, connectRsp.clusterId, connectRsp.connType);
|
||||
hbRegisterConn(pTscObj->pAppInfo->pAppHbMgr, pTscObj->id, connectRsp.clusterId, connectRsp.connType);
|
||||
|
||||
// pRequest->body.resInfo.pRspMsg = pMsg->pData;
|
||||
tscDebug("0x%" PRIx64 " clusterId:%" PRId64 ", totalConn:%" PRId64, pRequest->requestId, connectRsp.clusterId,
|
||||
|
|
|
@ -309,7 +309,7 @@ static int32_t smlApplySchemaAction(SSmlHandle *info, SSchemaAction *action) {
|
|||
case SCHEMA_ACTION_ADD_COLUMN: {
|
||||
int n = sprintf(result, "alter stable `%s` add column ", action->alterSTable.sTableName);
|
||||
smlBuildColumnDescription(action->alterSTable.field, result + n, capacity - n, &outBytes);
|
||||
TAOS_RES *res = taos_query(info->taos->id, result); // TODO async doAsyncQuery
|
||||
TAOS_RES *res = taos_query((TAOS*)&info->taos->id, result); // TODO async doAsyncQuery
|
||||
code = taos_errno(res);
|
||||
const char *errStr = taos_errstr(res);
|
||||
if (code != TSDB_CODE_SUCCESS) {
|
||||
|
@ -323,7 +323,7 @@ static int32_t smlApplySchemaAction(SSmlHandle *info, SSchemaAction *action) {
|
|||
case SCHEMA_ACTION_ADD_TAG: {
|
||||
int n = sprintf(result, "alter stable `%s` add tag ", action->alterSTable.sTableName);
|
||||
smlBuildColumnDescription(action->alterSTable.field, result + n, capacity - n, &outBytes);
|
||||
TAOS_RES *res = taos_query(info->taos->id, result); // TODO async doAsyncQuery
|
||||
TAOS_RES *res = taos_query((TAOS*)&info->taos->id, result); // TODO async doAsyncQuery
|
||||
code = taos_errno(res);
|
||||
const char *errStr = taos_errstr(res);
|
||||
if (code != TSDB_CODE_SUCCESS) {
|
||||
|
@ -337,7 +337,7 @@ static int32_t smlApplySchemaAction(SSmlHandle *info, SSchemaAction *action) {
|
|||
case SCHEMA_ACTION_CHANGE_COLUMN_SIZE: {
|
||||
int n = sprintf(result, "alter stable `%s` modify column ", action->alterSTable.sTableName);
|
||||
smlBuildColumnDescription(action->alterSTable.field, result + n, capacity - n, &outBytes);
|
||||
TAOS_RES *res = taos_query(info->taos->id, result); // TODO async doAsyncQuery
|
||||
TAOS_RES *res = taos_query((TAOS*)&info->taos->id, result); // TODO async doAsyncQuery
|
||||
code = taos_errno(res);
|
||||
if (code != TSDB_CODE_SUCCESS) {
|
||||
uError("SML:0x%" PRIx64 " apply schema action. error : %s", info->id, taos_errstr(res));
|
||||
|
@ -350,7 +350,7 @@ static int32_t smlApplySchemaAction(SSmlHandle *info, SSchemaAction *action) {
|
|||
case SCHEMA_ACTION_CHANGE_TAG_SIZE: {
|
||||
int n = sprintf(result, "alter stable `%s` modify tag ", action->alterSTable.sTableName);
|
||||
smlBuildColumnDescription(action->alterSTable.field, result + n, capacity - n, &outBytes);
|
||||
TAOS_RES *res = taos_query(info->taos->id, result); // TODO async doAsyncQuery
|
||||
TAOS_RES *res = taos_query((TAOS*)&info->taos->id, result); // TODO async doAsyncQuery
|
||||
code = taos_errno(res);
|
||||
if (code != TSDB_CODE_SUCCESS) {
|
||||
uError("SML:0x%" PRIx64 " apply schema action. error : %s", info->id, taos_errstr(res));
|
||||
|
@ -405,7 +405,7 @@ static int32_t smlApplySchemaAction(SSmlHandle *info, SSchemaAction *action) {
|
|||
pos--;
|
||||
++freeBytes;
|
||||
outBytes = snprintf(pos, freeBytes, ")");
|
||||
TAOS_RES *res = taos_query(info->taos->id, result);
|
||||
TAOS_RES *res = taos_query((TAOS*)&info->taos->id, result);
|
||||
code = taos_errno(res);
|
||||
if (code != TSDB_CODE_SUCCESS) {
|
||||
uError("SML:0x%" PRIx64 " apply schema action. error : %s", info->id, taos_errstr(res));
|
||||
|
@ -2436,7 +2436,13 @@ static void smlInsertCallback(void *param, void *res, int32_t code) {
|
|||
*/
|
||||
|
||||
TAOS_RES* taos_schemaless_insert(TAOS* taos, char* lines[], int numLines, int protocol, int precision) {
|
||||
STscObj* pTscObj = acquireTscObj(*(int64_t*)taos);
|
||||
if (NULL == taos) {
|
||||
terrno = TSDB_CODE_TSC_DISCONNECTED;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
int64_t rid = *(int64_t*)taos;
|
||||
STscObj* pTscObj = acquireTscObj(rid);
|
||||
if (NULL == pTscObj) {
|
||||
terrno = TSDB_CODE_TSC_DISCONNECTED;
|
||||
uError("SML:taos_schemaless_insert invalid taos");
|
||||
|
@ -2445,7 +2451,7 @@ TAOS_RES* taos_schemaless_insert(TAOS* taos, char* lines[], int numLines, int pr
|
|||
|
||||
SRequestObj* request = (SRequestObj*)createRequest(pTscObj, TSDB_SQL_INSERT);
|
||||
if(!request){
|
||||
releaseTscObj(*(int64_t*)taos);
|
||||
releaseTscObj(rid);
|
||||
uError("SML:taos_schemaless_insert error request is null");
|
||||
return NULL;
|
||||
}
|
||||
|
@ -2533,6 +2539,6 @@ end:
|
|||
// ((STscObj *)taos)->schemalessType = 0;
|
||||
pTscObj->schemalessType = 1;
|
||||
uDebug("resultend:%s", request->msgBuf);
|
||||
releaseTscObj(*(int64_t*)taos);
|
||||
releaseTscObj(rid);
|
||||
return (TAOS_RES*)request;
|
||||
}
|
||||
|
|
|
@ -1662,8 +1662,8 @@ char* dumpBlockData(SSDataBlock* pDataBlock, const char* flag, char** pDataBuf)
|
|||
int32_t colNum = taosArrayGetSize(pDataBlock->pDataBlock);
|
||||
int32_t rows = pDataBlock->info.rows;
|
||||
int32_t len = 0;
|
||||
len += snprintf(dumpBuf + len, size - len, "\n%s |block type %d |child id %d|\n", flag,
|
||||
(int32_t)pDataBlock->info.type, pDataBlock->info.childId);
|
||||
len += snprintf(dumpBuf + len, size - len, "\n%s |block type %d |child id %d|group id %lu|\n", flag,
|
||||
(int32_t)pDataBlock->info.type, pDataBlock->info.childId, pDataBlock->info.groupId);
|
||||
for (int32_t j = 0; j < rows; j++) {
|
||||
len += snprintf(dumpBuf + len, size - len, "%s |", flag);
|
||||
for (int32_t k = 0; k < colNum; k++) {
|
||||
|
|
|
@ -621,8 +621,8 @@ int32_t tDeserializeSMCreateStbReq(void *buf, int32_t bufLen, SMCreateStbReq *pR
|
|||
if (NULL == pReq->pFuncs) return -1;
|
||||
}
|
||||
for (int32_t i = 0; i < numOfFuncs; ++i) {
|
||||
char *pFunc = NULL;
|
||||
if (tDecodeCStrAlloc(&decoder, &pFunc) < 0) return -1;
|
||||
char pFunc[TSDB_FUNC_NAME_LEN] = {0};
|
||||
if (tDecodeCStrTo(&decoder, pFunc) < 0) return -1;
|
||||
if (taosArrayPush(pReq->pFuncs, pFunc) == NULL) {
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
return -1;
|
||||
|
@ -2300,7 +2300,6 @@ int32_t tDeserializeSServerVerRsp(void *buf, int32_t bufLen, SServerVerRsp *pRsp
|
|||
return 0;
|
||||
}
|
||||
|
||||
|
||||
int32_t tSerializeSQnodeListRsp(void *buf, int32_t bufLen, SQnodeListRsp *pRsp) {
|
||||
SEncoder encoder = {0};
|
||||
tEncoderInit(&encoder, buf, bufLen);
|
||||
|
@ -2387,7 +2386,6 @@ int32_t tDeserializeSDnodeListRsp(void *buf, int32_t bufLen, SDnodeListRsp *pRsp
|
|||
|
||||
void tFreeSDnodeListRsp(SDnodeListRsp *pRsp) { taosArrayDestroy(pRsp->dnodeList); }
|
||||
|
||||
|
||||
int32_t tSerializeSCompactDbReq(void *buf, int32_t bufLen, SCompactDbReq *pReq) {
|
||||
SEncoder encoder = {0};
|
||||
tEncoderInit(&encoder, buf, bufLen);
|
||||
|
@ -2909,20 +2907,19 @@ int32_t tDeserializeSShowVariablesReq(void *buf, int32_t bufLen, SShowVariablesR
|
|||
return 0;
|
||||
}
|
||||
|
||||
int32_t tEncodeSVariablesInfo(SEncoder* pEncoder, SVariablesInfo* pInfo) {
|
||||
int32_t tEncodeSVariablesInfo(SEncoder *pEncoder, SVariablesInfo *pInfo) {
|
||||
if (tEncodeCStr(pEncoder, pInfo->name) < 0) return -1;
|
||||
if (tEncodeCStr(pEncoder, pInfo->value) < 0) return -1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int32_t tDecodeSVariablesInfo(SDecoder* pDecoder, SVariablesInfo* pInfo) {
|
||||
int32_t tDecodeSVariablesInfo(SDecoder *pDecoder, SVariablesInfo *pInfo) {
|
||||
if (tDecodeCStrTo(pDecoder, pInfo->name) < 0) return -1;
|
||||
if (tDecodeCStrTo(pDecoder, pInfo->value) < 0) return -1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
int32_t tSerializeSShowVariablesRsp(void* buf, int32_t bufLen, SShowVariablesRsp* pRsp) {
|
||||
int32_t tSerializeSShowVariablesRsp(void *buf, int32_t bufLen, SShowVariablesRsp *pRsp) {
|
||||
SEncoder encoder = {0};
|
||||
tEncoderInit(&encoder, buf, bufLen);
|
||||
|
||||
|
@ -2930,7 +2927,7 @@ int32_t tSerializeSShowVariablesRsp(void* buf, int32_t bufLen, SShowVariablesRsp
|
|||
int32_t varNum = taosArrayGetSize(pRsp->variables);
|
||||
if (tEncodeI32(&encoder, varNum) < 0) return -1;
|
||||
for (int32_t i = 0; i < varNum; ++i) {
|
||||
SVariablesInfo* pInfo = taosArrayGet(pRsp->variables, i);
|
||||
SVariablesInfo *pInfo = taosArrayGet(pRsp->variables, i);
|
||||
if (tEncodeSVariablesInfo(&encoder, pInfo) < 0) return -1;
|
||||
}
|
||||
tEndEncode(&encoder);
|
||||
|
@ -2940,7 +2937,7 @@ int32_t tSerializeSShowVariablesRsp(void* buf, int32_t bufLen, SShowVariablesRsp
|
|||
return tlen;
|
||||
}
|
||||
|
||||
int32_t tDeserializeSShowVariablesRsp(void* buf, int32_t bufLen, SShowVariablesRsp* pRsp) {
|
||||
int32_t tDeserializeSShowVariablesRsp(void *buf, int32_t bufLen, SShowVariablesRsp *pRsp) {
|
||||
SDecoder decoder = {0};
|
||||
tDecoderInit(&decoder, buf, bufLen);
|
||||
|
||||
|
@ -2962,7 +2959,7 @@ int32_t tDeserializeSShowVariablesRsp(void* buf, int32_t bufLen, SShowVariablesR
|
|||
return 0;
|
||||
}
|
||||
|
||||
void tFreeSShowVariablesRsp(SShowVariablesRsp* pRsp) {
|
||||
void tFreeSShowVariablesRsp(SShowVariablesRsp *pRsp) {
|
||||
if (NULL == pRsp) {
|
||||
return;
|
||||
}
|
||||
|
|
|
@ -107,13 +107,7 @@ static void vmProcessSyncQueue(SQueueInfo *pInfo, STaosQall *qall, int32_t numOf
|
|||
const STraceId *trace = &pMsg->info.traceId;
|
||||
dGTrace("vgId:%d, msg:%p get from vnode-sync queue", pVnode->vgId, pMsg);
|
||||
|
||||
int32_t code = vnodeProcessSyncReq(pVnode->pImpl, pMsg, NULL);
|
||||
if (code != 0) {
|
||||
if (terrno != 0) code = terrno;
|
||||
dGError("vgId:%d, msg:%p failed to sync since %s", pVnode->vgId, pMsg, terrstr());
|
||||
vmSendRsp(pMsg, code);
|
||||
}
|
||||
|
||||
int32_t code = vnodeProcessSyncReq(pVnode->pImpl, pMsg, NULL); // no response here
|
||||
dGTrace("vgId:%d, msg:%p is freed, code:0x%x", pVnode->vgId, pMsg, code);
|
||||
rpcFreeCont(pMsg->pCont);
|
||||
taosFreeQitem(pMsg);
|
||||
|
|
|
@ -251,9 +251,6 @@ static inline void dmReleaseHandle(SRpcHandleInfo *pHandle, int8_t type) {
|
|||
static bool rpcRfp(int32_t code, tmsg_t msgType) {
|
||||
if (code == TSDB_CODE_RPC_REDIRECT || code == TSDB_CODE_RPC_NETWORK_UNAVAIL || code == TSDB_CODE_NODE_NOT_DEPLOYED ||
|
||||
code == TSDB_CODE_SYN_NOT_LEADER || code == TSDB_CODE_APP_NOT_READY) {
|
||||
if (msgType == TDMT_VND_QUERY || msgType == TDMT_VND_FETCH) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
|
@ -264,7 +261,7 @@ int32_t dmInitClient(SDnode *pDnode) {
|
|||
SDnodeTrans *pTrans = &pDnode->trans;
|
||||
|
||||
SRpcInit rpcInit = {0};
|
||||
rpcInit.label = "DND";
|
||||
rpcInit.label = "DND-C";
|
||||
rpcInit.numOfThreads = 1;
|
||||
rpcInit.cfp = (RpcCfp)dmProcessRpcMsg;
|
||||
rpcInit.sessions = 1024;
|
||||
|
@ -298,7 +295,7 @@ int32_t dmInitServer(SDnode *pDnode) {
|
|||
SRpcInit rpcInit = {0};
|
||||
strncpy(rpcInit.localFqdn, tsLocalFqdn, strlen(tsLocalFqdn));
|
||||
rpcInit.localPort = tsServerPort;
|
||||
rpcInit.label = "DND";
|
||||
rpcInit.label = "DND-S";
|
||||
rpcInit.numOfThreads = tsNumOfRpcThreads;
|
||||
rpcInit.cfp = (RpcCfp)dmProcessRpcMsg;
|
||||
rpcInit.sessions = tsMaxShellConns;
|
||||
|
|
|
@ -527,6 +527,11 @@ int32_t mndProcessSyncMsg(SRpcMsg *pMsg) {
|
|||
|
||||
static int32_t mndCheckMnodeState(SRpcMsg *pMsg) {
|
||||
if (!IsReq(pMsg)) return 0;
|
||||
if (pMsg->msgType == TDMT_VND_QUERY || pMsg->msgType == TDMT_VND_QUERY_CONTINUE ||
|
||||
pMsg->msgType == TDMT_VND_QUERY_HEARTBEAT || pMsg->msgType == TDMT_VND_FETCH ||
|
||||
pMsg->msgType == TDMT_VND_DROP_TASK) {
|
||||
return 0;
|
||||
}
|
||||
if (mndAcquireRpcRef(pMsg->info.node) == 0) return 0;
|
||||
if (pMsg->msgType == TDMT_MND_MQ_TIMER || pMsg->msgType == TDMT_MND_TELEM_TIMER ||
|
||||
pMsg->msgType == TDMT_MND_TRANS_TIMER || pMsg->msgType == TDMT_MND_TTL_TIMER) {
|
||||
|
|
|
@ -136,7 +136,7 @@ int32_t vnodeProcessWriteReq(SVnode *pVnode, SRpcMsg *pMsg, int64_t version, SRp
|
|||
if (vnodeProcessDropTbReq(pVnode, version, pReq, len, pRsp) < 0) goto _err;
|
||||
break;
|
||||
case TDMT_VND_DROP_TTL_TABLE:
|
||||
if (vnodeProcessDropTtlTbReq(pVnode, version, pReq, len, pRsp) < 0) goto _err;
|
||||
//if (vnodeProcessDropTtlTbReq(pVnode, version, pReq, len, pRsp) < 0) goto _err;
|
||||
break;
|
||||
case TDMT_VND_CREATE_SMA: {
|
||||
if (vnodeProcessCreateTSmaReq(pVnode, version, pReq, len, pRsp) < 0) goto _err;
|
||||
|
|
|
@ -73,7 +73,7 @@ static int32_t vnodeSetStandBy(SVnode *pVnode) {
|
|||
vInfo("vgId:%d, set standby success", TD_VID(pVnode));
|
||||
return 0;
|
||||
} else {
|
||||
vError("vgId:%d, failed to set standby since %s", TD_VID(pVnode), terrstr());
|
||||
vError("vgId:%d, failed to set standby after leader transfer since %s", TD_VID(pVnode), terrstr());
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -205,6 +205,7 @@ typedef struct SCtgJob {
|
|||
SArray* pTasks;
|
||||
int32_t taskDone;
|
||||
SMetaData jobRes;
|
||||
int32_t jobResCode;
|
||||
int32_t taskIdx;
|
||||
SRWLatch taskLock;
|
||||
|
||||
|
@ -284,24 +285,26 @@ typedef struct SCtgApiStat {
|
|||
} SCtgApiStat;
|
||||
|
||||
typedef struct SCtgRuntimeStat {
|
||||
uint64_t qNum;
|
||||
uint64_t qDoneNum;
|
||||
uint64_t numOfOpAbort;
|
||||
uint64_t numOfOpEnqueue;
|
||||
uint64_t numOfOpDequeue;
|
||||
} SCtgRuntimeStat;
|
||||
|
||||
typedef struct SCtgCacheStat {
|
||||
uint64_t clusterNum;
|
||||
uint64_t dbNum;
|
||||
uint64_t tblNum;
|
||||
uint64_t stblNum;
|
||||
uint64_t userNum;
|
||||
uint64_t vgHitNum;
|
||||
uint64_t vgMissNum;
|
||||
uint64_t tbMetaHitNum;
|
||||
uint64_t tbMetaMissNum;
|
||||
uint64_t tbIndexHitNum;
|
||||
uint64_t tbIndexMissNum;
|
||||
uint64_t userHitNum;
|
||||
uint64_t userMissNum;
|
||||
uint64_t numOfCluster;
|
||||
uint64_t numOfDb;
|
||||
uint64_t numOfTbl;
|
||||
uint64_t numOfStb;
|
||||
uint64_t numOfUser;
|
||||
uint64_t numOfVgHit;
|
||||
uint64_t numOfVgMiss;
|
||||
uint64_t numOfMetaHit;
|
||||
uint64_t numOfMetaMiss;
|
||||
uint64_t numOfIndexHit;
|
||||
uint64_t numOfIndexMiss;
|
||||
uint64_t numOfUserHit;
|
||||
uint64_t numOfUserMiss;
|
||||
uint64_t numOfClear;
|
||||
} SCtgCacheStat;
|
||||
|
||||
typedef struct SCatalogStat {
|
||||
|
@ -371,6 +374,7 @@ typedef struct SCtgDropTbIndexMsg {
|
|||
|
||||
typedef struct SCtgClearCacheMsg {
|
||||
SCatalog* pCtg;
|
||||
bool freeCtg;
|
||||
} SCtgClearCacheMsg;
|
||||
|
||||
typedef struct SCtgUpdateEpsetMsg {
|
||||
|
@ -385,6 +389,7 @@ typedef struct SCtgCacheOperation {
|
|||
void *data;
|
||||
bool syncOp;
|
||||
tsem_t rspSem;
|
||||
bool stopQueue;
|
||||
} SCtgCacheOperation;
|
||||
|
||||
typedef struct SCtgQNode {
|
||||
|
@ -394,6 +399,7 @@ typedef struct SCtgQNode {
|
|||
|
||||
typedef struct SCtgQueue {
|
||||
SRWLatch qlock;
|
||||
bool stopQueue;
|
||||
SCtgQNode *head;
|
||||
SCtgQNode *tail;
|
||||
tsem_t reqSem;
|
||||
|
@ -513,8 +519,35 @@ typedef struct SCtgOperation {
|
|||
#define CTG_RET(c) do { int32_t _code = c; if (_code != TSDB_CODE_SUCCESS) { terrno = _code; } return _code; } while (0)
|
||||
#define CTG_ERR_JRET(c) do { code = c; if (code != TSDB_CODE_SUCCESS) { terrno = code; goto _return; } } while (0)
|
||||
|
||||
#define CTG_API_LEAVE(c) do { int32_t __code = c; CTG_UNLOCK(CTG_READ, &gCtgMgmt.lock); CTG_API_DEBUG("CTG API leave %s", __FUNCTION__); CTG_RET(__code); } while (0)
|
||||
#define CTG_API_ENTER() do { CTG_API_DEBUG("CTG API enter %s", __FUNCTION__); CTG_LOCK(CTG_READ, &gCtgMgmt.lock); if (atomic_load_8((int8_t*)&gCtgMgmt.exit)) { CTG_API_LEAVE(TSDB_CODE_CTG_OUT_OF_SERVICE); } } while (0)
|
||||
#define CTG_API_LEAVE(c) do { \
|
||||
int32_t __code = c; \
|
||||
CTG_UNLOCK(CTG_READ, &gCtgMgmt.lock); \
|
||||
CTG_API_DEBUG("CTG API leave %s", __FUNCTION__); \
|
||||
CTG_RET(__code); \
|
||||
} while (0)
|
||||
|
||||
#define CTG_API_ENTER() do { \
|
||||
CTG_API_DEBUG("CTG API enter %s", __FUNCTION__); \
|
||||
CTG_LOCK(CTG_READ, &gCtgMgmt.lock); \
|
||||
if (atomic_load_8((int8_t*)&gCtgMgmt.exit)) { \
|
||||
CTG_API_LEAVE(TSDB_CODE_CTG_OUT_OF_SERVICE); \
|
||||
} \
|
||||
} while (0)
|
||||
|
||||
|
||||
#define CTG_API_LEAVE_NOLOCK(c) do { \
|
||||
int32_t __code = c; \
|
||||
CTG_API_DEBUG("CTG API leave %s", __FUNCTION__); \
|
||||
CTG_RET(__code); \
|
||||
} while (0)
|
||||
|
||||
#define CTG_API_ENTER_NOLOCK() do { \
|
||||
CTG_API_DEBUG("CTG API enter %s", __FUNCTION__); \
|
||||
if (atomic_load_8((int8_t*)&gCtgMgmt.exit)) { \
|
||||
CTG_API_LEAVE_NOLOCK(TSDB_CODE_CTG_OUT_OF_SERVICE); \
|
||||
} \
|
||||
} while (0)
|
||||
|
||||
|
||||
void ctgdShowTableMeta(SCatalog* pCtg, const char *tbName, STableMeta* p);
|
||||
void ctgdShowClusterCache(SCatalog* pCtg);
|
||||
|
@ -547,7 +580,7 @@ int32_t ctgUpdateTbMetaEnqueue(SCatalog* pCtg, STableMetaOutput *output, bool sy
|
|||
int32_t ctgUpdateUserEnqueue(SCatalog* pCtg, SGetUserAuthRsp *pAuth, bool syncReq);
|
||||
int32_t ctgUpdateVgEpsetEnqueue(SCatalog* pCtg, char *dbFName, int32_t vgId, SEpSet* pEpSet);
|
||||
int32_t ctgUpdateTbIndexEnqueue(SCatalog* pCtg, STableIndex **pIndex, bool syncOp);
|
||||
int32_t ctgClearCacheEnqueue(SCatalog* pCtg, bool syncOp);
|
||||
int32_t ctgClearCacheEnqueue(SCatalog* pCtg, bool freeCtg, bool stopQueue, bool syncOp);
|
||||
int32_t ctgMetaRentInit(SCtgRentMgmt *mgmt, uint32_t rentSec, int8_t type);
|
||||
int32_t ctgMetaRentAdd(SCtgRentMgmt *mgmt, void *meta, int64_t id, int32_t size);
|
||||
int32_t ctgMetaRentGet(SCtgRentMgmt *mgmt, void **res, uint32_t *num, int32_t size);
|
||||
|
@ -582,17 +615,18 @@ int32_t ctgGetTableCfgFromVnode(SCatalog* pCtg, SRequestConnInfo *pConn, const S
|
|||
int32_t ctgGetTableCfgFromMnode(SCatalog* pCtg, SRequestConnInfo *pConn, const SName* pTableName, STableCfg **out, SCtgTask* pTask);
|
||||
int32_t ctgGetSvrVerFromMnode(SCatalog* pCtg, SRequestConnInfo *pConn, char **out, SCtgTask* pTask);
|
||||
|
||||
int32_t ctgInitJob(SCatalog* pCtg, SRequestConnInfo *pConn, SCtgJob** job, const SCatalogReq* pReq, catalogCallback fp, void* param, int32_t* taskNum);
|
||||
int32_t ctgInitJob(SCatalog* pCtg, SRequestConnInfo *pConn, SCtgJob** job, const SCatalogReq* pReq, catalogCallback fp, void* param);
|
||||
int32_t ctgLaunchJob(SCtgJob *pJob);
|
||||
int32_t ctgMakeAsyncRes(SCtgJob *pJob);
|
||||
int32_t ctgLaunchSubTask(SCtgTask *pTask, CTG_TASK_TYPE type, ctgSubTaskCbFp fp, void* param);
|
||||
int32_t ctgGetTbCfgCb(SCtgTask *pTask);
|
||||
void ctgFreeHandle(SCatalog* pCatalog);
|
||||
|
||||
int32_t ctgCloneVgInfo(SDBVgInfo *src, SDBVgInfo **dst);
|
||||
int32_t ctgCloneMetaOutput(STableMetaOutput *output, STableMetaOutput **pOutput);
|
||||
int32_t ctgGenerateVgList(SCatalog *pCtg, SHashObj *vgHash, SArray** pList);
|
||||
void ctgFreeJob(void* job);
|
||||
void ctgFreeHandle(SCatalog* pCtg);
|
||||
void ctgFreeHandleImpl(SCatalog* pCtg);
|
||||
void ctgFreeVgInfo(SDBVgInfo *vgInfo);
|
||||
int32_t ctgGetVgInfoFromHashValue(SCatalog *pCtg, SDBVgInfo *dbInfo, const SName *pTableName, SVgroupInfo *pVgroup);
|
||||
void ctgResetTbMetaTask(SCtgTask* pTask);
|
||||
|
@ -608,6 +642,8 @@ int32_t ctgUpdateSendTargetInfo(SMsgSendInfo *pMsgSendInfo, int32_t msgType, SCt
|
|||
int32_t ctgCloneTableIndex(SArray* pIndex, SArray** pRes);
|
||||
void ctgFreeSTableIndex(void *info);
|
||||
void ctgClearSubTaskRes(SCtgSubRes *pRes);
|
||||
void ctgFreeQNode(SCtgQNode *node);
|
||||
void ctgClearHandle(SCatalog* pCtg);
|
||||
|
||||
|
||||
extern SCatalogMgmt gCtgMgmt;
|
||||
|
|
|
@ -99,7 +99,7 @@ int32_t ctgRefreshTbMeta(SCatalog* pCtg, SRequestConnInfo *pConn, SCtgTbMetaCtx*
|
|||
STableMetaOutput* output = taosMemoryCalloc(1, sizeof(STableMetaOutput));
|
||||
if (NULL == output) {
|
||||
ctgError("malloc %d failed", (int32_t)sizeof(STableMetaOutput));
|
||||
CTG_ERR_RET(TSDB_CODE_CTG_MEM_ERROR);
|
||||
CTG_ERR_RET(TSDB_CODE_OUT_OF_MEMORY);
|
||||
}
|
||||
|
||||
if (CTG_FLAG_IS_SYS_DB(ctx->flag)) {
|
||||
|
@ -264,7 +264,7 @@ int32_t ctgUpdateTbMeta(SCatalog* pCtg, STableMetaRsp* rspMsg, bool syncOp) {
|
|||
STableMetaOutput* output = taosMemoryCalloc(1, sizeof(STableMetaOutput));
|
||||
if (NULL == output) {
|
||||
ctgError("malloc %d failed", (int32_t)sizeof(STableMetaOutput));
|
||||
CTG_ERR_RET(TSDB_CODE_CTG_MEM_ERROR);
|
||||
CTG_ERR_RET(TSDB_CODE_OUT_OF_MEMORY);
|
||||
}
|
||||
|
||||
int32_t code = 0;
|
||||
|
@ -442,7 +442,7 @@ int32_t ctgGetTbDistVgInfo(SCatalog* pCtg, SRequestConnInfo *pConn, SName* pTabl
|
|||
vgList = taosArrayInit(1, sizeof(SVgroupInfo));
|
||||
if (NULL == vgList) {
|
||||
ctgError("taosArrayInit %d failed", (int32_t)sizeof(SVgroupInfo));
|
||||
CTG_ERR_JRET(TSDB_CODE_CTG_MEM_ERROR);
|
||||
CTG_ERR_JRET(TSDB_CODE_OUT_OF_MEMORY);
|
||||
}
|
||||
|
||||
if (NULL == taosArrayPush(vgList, &vgroupInfo)) {
|
||||
|
@ -548,9 +548,11 @@ int32_t catalogGetHandle(uint64_t clusterId, SCatalog** catalogHandle) {
|
|||
CTG_ERR_RET(TSDB_CODE_CTG_INVALID_INPUT);
|
||||
}
|
||||
|
||||
CTG_API_ENTER();
|
||||
|
||||
if (NULL == gCtgMgmt.pCluster) {
|
||||
qError("catalog cluster cache are not ready, clusterId:0x%" PRIx64, clusterId);
|
||||
CTG_ERR_RET(TSDB_CODE_CTG_NOT_READY);
|
||||
CTG_API_LEAVE(TSDB_CODE_CTG_NOT_READY);
|
||||
}
|
||||
|
||||
int32_t code = 0;
|
||||
|
@ -562,13 +564,13 @@ int32_t catalogGetHandle(uint64_t clusterId, SCatalog** catalogHandle) {
|
|||
if (ctg && (*ctg)) {
|
||||
*catalogHandle = *ctg;
|
||||
qDebug("got catalog handle from cache, clusterId:0x%" PRIx64 ", CTG:%p", clusterId, *ctg);
|
||||
return TSDB_CODE_SUCCESS;
|
||||
CTG_API_LEAVE(TSDB_CODE_SUCCESS);
|
||||
}
|
||||
|
||||
clusterCtg = taosMemoryCalloc(1, sizeof(SCatalog));
|
||||
if (NULL == clusterCtg) {
|
||||
qError("calloc %d failed", (int32_t)sizeof(SCatalog));
|
||||
CTG_ERR_RET(TSDB_CODE_CTG_MEM_ERROR);
|
||||
CTG_API_LEAVE(TSDB_CODE_OUT_OF_MEMORY);
|
||||
}
|
||||
|
||||
clusterCtg->clusterId = clusterId;
|
||||
|
@ -580,13 +582,19 @@ int32_t catalogGetHandle(uint64_t clusterId, SCatalog** catalogHandle) {
|
|||
false, HASH_ENTRY_LOCK);
|
||||
if (NULL == clusterCtg->dbCache) {
|
||||
qError("taosHashInit %d dbCache failed", CTG_DEFAULT_CACHE_DB_NUMBER);
|
||||
CTG_ERR_JRET(TSDB_CODE_CTG_MEM_ERROR);
|
||||
CTG_ERR_JRET(TSDB_CODE_OUT_OF_MEMORY);
|
||||
}
|
||||
|
||||
clusterCtg->userCache = taosHashInit(gCtgMgmt.cfg.maxUserCacheNum, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BINARY), false, HASH_ENTRY_LOCK);
|
||||
if (NULL == clusterCtg->userCache) {
|
||||
qError("taosHashInit %d user cache failed", gCtgMgmt.cfg.maxUserCacheNum);
|
||||
CTG_ERR_JRET(TSDB_CODE_OUT_OF_MEMORY);
|
||||
}
|
||||
|
||||
code = taosHashPut(gCtgMgmt.pCluster, &clusterId, sizeof(clusterId), &clusterCtg, POINTER_BYTES);
|
||||
if (code) {
|
||||
if (HASH_NODE_EXIST(code)) {
|
||||
ctgFreeHandle(clusterCtg);
|
||||
ctgFreeHandleImpl(clusterCtg);
|
||||
continue;
|
||||
}
|
||||
|
||||
|
@ -601,34 +609,15 @@ int32_t catalogGetHandle(uint64_t clusterId, SCatalog** catalogHandle) {
|
|||
|
||||
*catalogHandle = clusterCtg;
|
||||
|
||||
CTG_CACHE_STAT_INC(clusterNum, 1);
|
||||
CTG_CACHE_STAT_INC(numOfCluster, 1);
|
||||
|
||||
return TSDB_CODE_SUCCESS;
|
||||
CTG_API_LEAVE(TSDB_CODE_SUCCESS);
|
||||
|
||||
_return:
|
||||
|
||||
ctgFreeHandle(clusterCtg);
|
||||
ctgFreeHandleImpl(clusterCtg);
|
||||
|
||||
CTG_RET(code);
|
||||
}
|
||||
|
||||
void catalogFreeHandle(SCatalog* pCtg) {
|
||||
if (NULL == pCtg) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (taosHashRemove(gCtgMgmt.pCluster, &pCtg->clusterId, sizeof(pCtg->clusterId))) {
|
||||
ctgWarn("taosHashRemove from cluster failed, may already be freed, clusterId:0x%" PRIx64, pCtg->clusterId);
|
||||
return;
|
||||
}
|
||||
|
||||
CTG_CACHE_STAT_DEC(clusterNum, 1);
|
||||
|
||||
uint64_t clusterId = pCtg->clusterId;
|
||||
|
||||
ctgFreeHandle(pCtg);
|
||||
|
||||
ctgInfo("handle freed, culsterId:0x%" PRIx64, clusterId);
|
||||
CTG_API_LEAVE(code);
|
||||
}
|
||||
|
||||
int32_t catalogGetDBVgVersion(SCatalog* pCtg, const char* dbFName, int32_t* version, int64_t* dbId, int32_t* tableNum) {
|
||||
|
@ -1008,7 +997,7 @@ int32_t catalogGetAllMeta(SCatalog* pCtg, SRequestConnInfo *pConn, const SCatalo
|
|||
pRsp->pTableMeta = taosArrayInit(tbNum, POINTER_BYTES);
|
||||
if (NULL == pRsp->pTableMeta) {
|
||||
ctgError("taosArrayInit %d failed", tbNum);
|
||||
CTG_ERR_JRET(TSDB_CODE_CTG_MEM_ERROR);
|
||||
CTG_ERR_JRET(TSDB_CODE_OUT_OF_MEMORY);
|
||||
}
|
||||
|
||||
for (int32_t i = 0; i < tbNum; ++i) {
|
||||
|
@ -1023,7 +1012,7 @@ int32_t catalogGetAllMeta(SCatalog* pCtg, SRequestConnInfo *pConn, const SCatalo
|
|||
if (NULL == taosArrayPush(pRsp->pTableMeta, &pTableMeta)) {
|
||||
ctgError("taosArrayPush failed, idx:%d", i);
|
||||
taosMemoryFreeClear(pTableMeta);
|
||||
CTG_ERR_JRET(TSDB_CODE_CTG_MEM_ERROR);
|
||||
CTG_ERR_JRET(TSDB_CODE_OUT_OF_MEMORY);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1058,14 +1047,9 @@ int32_t catalogAsyncGetAllMeta(SCatalog* pCtg, SRequestConnInfo *pConn, const SC
|
|||
CTG_API_LEAVE(TSDB_CODE_CTG_INVALID_INPUT);
|
||||
}
|
||||
|
||||
int32_t code = 0, taskNum = 0;
|
||||
int32_t code = 0;
|
||||
SCtgJob *pJob = NULL;
|
||||
CTG_ERR_JRET(ctgInitJob(pCtg, pConn, &pJob, pReq, fp, param, &taskNum));
|
||||
if (taskNum <= 0) {
|
||||
SMetaData* pMetaData = taosMemoryCalloc(1, sizeof(SMetaData));
|
||||
fp(pMetaData, param, TSDB_CODE_SUCCESS);
|
||||
CTG_API_LEAVE(TSDB_CODE_SUCCESS);
|
||||
}
|
||||
CTG_ERR_JRET(ctgInitJob(pCtg, pConn, &pJob, pReq, fp, param));
|
||||
|
||||
CTG_ERR_JRET(ctgLaunchJob(pJob));
|
||||
|
||||
|
@ -1073,6 +1057,7 @@ int32_t catalogAsyncGetAllMeta(SCatalog* pCtg, SRequestConnInfo *pConn, const SC
|
|||
// *jobId = pJob->refId;
|
||||
|
||||
_return:
|
||||
|
||||
if (pJob) {
|
||||
taosReleaseRef(gCtgMgmt.jobPool, pJob->refId);
|
||||
|
||||
|
@ -1142,13 +1127,15 @@ int32_t catalogGetExpiredUsers(SCatalog* pCtg, SUserAuthVersion** users, uint32_
|
|||
}
|
||||
|
||||
*num = taosHashGetSize(pCtg->userCache);
|
||||
if (*num > 0) {
|
||||
if (*num <= 0) {
|
||||
CTG_API_LEAVE(TSDB_CODE_SUCCESS);
|
||||
}
|
||||
|
||||
*users = taosMemoryCalloc(*num, sizeof(SUserAuthVersion));
|
||||
if (NULL == *users) {
|
||||
ctgError("calloc %d userAuthVersion failed", *num);
|
||||
CTG_API_LEAVE(TSDB_CODE_OUT_OF_MEMORY);
|
||||
}
|
||||
}
|
||||
|
||||
uint32_t i = 0;
|
||||
SCtgUserAuth* pAuth = taosHashIterate(pCtg->userCache, NULL);
|
||||
|
@ -1159,6 +1146,11 @@ int32_t catalogGetExpiredUsers(SCatalog* pCtg, SUserAuthVersion** users, uint32_
|
|||
(*users)[i].user[len] = 0;
|
||||
(*users)[i].version = pAuth->version;
|
||||
++i;
|
||||
if (i >= *num) {
|
||||
taosHashCancelIterate(pCtg->userCache, pAuth);
|
||||
break;
|
||||
}
|
||||
|
||||
pAuth = taosHashIterate(pCtg->userCache, pAuth);
|
||||
}
|
||||
|
||||
|
@ -1274,19 +1266,19 @@ int32_t catalogUpdateUserAuthInfo(SCatalog* pCtg, SGetUserAuthRsp* pAuth) {
|
|||
}
|
||||
|
||||
int32_t catalogClearCache(void) {
|
||||
CTG_API_ENTER();
|
||||
CTG_API_ENTER_NOLOCK();
|
||||
|
||||
qInfo("start to clear catalog cache");
|
||||
|
||||
if (NULL == gCtgMgmt.pCluster || atomic_load_8((int8_t*)&gCtgMgmt.exit)) {
|
||||
CTG_API_LEAVE(TSDB_CODE_SUCCESS);
|
||||
CTG_API_LEAVE_NOLOCK(TSDB_CODE_SUCCESS);
|
||||
}
|
||||
|
||||
int32_t code = ctgClearCacheEnqueue(NULL, true);
|
||||
int32_t code = ctgClearCacheEnqueue(NULL, false, false, true);
|
||||
|
||||
qInfo("clear catalog cache end, code: %s", tstrerror(code));
|
||||
|
||||
CTG_API_LEAVE(code);
|
||||
CTG_API_LEAVE_NOLOCK(code);
|
||||
}
|
||||
|
||||
|
||||
|
@ -1299,32 +1291,12 @@ void catalogDestroy(void) {
|
|||
|
||||
atomic_store_8((int8_t*)&gCtgMgmt.exit, true);
|
||||
|
||||
if (tsem_post(&gCtgMgmt.queue.reqSem)) {
|
||||
qError("tsem_post failed, error:%s", tstrerror(TAOS_SYSTEM_ERROR(errno)));
|
||||
}
|
||||
|
||||
while (CTG_IS_LOCKED(&gCtgMgmt.lock)) {
|
||||
taosUsleep(1);
|
||||
}
|
||||
|
||||
CTG_LOCK(CTG_WRITE, &gCtgMgmt.lock);
|
||||
|
||||
SCatalog* pCtg = NULL;
|
||||
void* pIter = taosHashIterate(gCtgMgmt.pCluster, NULL);
|
||||
while (pIter) {
|
||||
pCtg = *(SCatalog**)pIter;
|
||||
|
||||
if (pCtg) {
|
||||
catalogFreeHandle(pCtg);
|
||||
}
|
||||
|
||||
pIter = taosHashIterate(gCtgMgmt.pCluster, pIter);
|
||||
if (!taosCheckCurrentInDll()) {
|
||||
ctgClearCacheEnqueue(NULL, true, true, true);
|
||||
}
|
||||
|
||||
taosHashCleanup(gCtgMgmt.pCluster);
|
||||
gCtgMgmt.pCluster = NULL;
|
||||
|
||||
if (CTG_IS_LOCKED(&gCtgMgmt.lock) == TD_RWLATCH_WRITE_FLAG_COPY) CTG_UNLOCK(CTG_WRITE, &gCtgMgmt.lock);
|
||||
|
||||
qInfo("catalog destroyed");
|
||||
}
|
||||
|
|
|
@ -427,7 +427,7 @@ int32_t ctgInitTask(SCtgJob *pJob, CTG_TASK_TYPE type, void* param, int32_t *tas
|
|||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
int32_t ctgInitJob(SCatalog* pCtg, SRequestConnInfo *pConn, SCtgJob** job, const SCatalogReq* pReq, catalogCallback fp, void* param, int32_t* taskNum) {
|
||||
int32_t ctgInitJob(SCatalog* pCtg, SRequestConnInfo *pConn, SCtgJob** job, const SCatalogReq* pReq, catalogCallback fp, void* param) {
|
||||
int32_t code = 0;
|
||||
int32_t tbMetaNum = (int32_t)taosArrayGetSize(pReq->pTableMeta);
|
||||
int32_t dbVgNum = (int32_t)taosArrayGetSize(pReq->pDbVgroup);
|
||||
|
@ -443,11 +443,7 @@ int32_t ctgInitJob(SCatalog* pCtg, SRequestConnInfo *pConn, SCtgJob** job, const
|
|||
int32_t tbIndexNum = (int32_t)taosArrayGetSize(pReq->pTableIndex);
|
||||
int32_t tbCfgNum = (int32_t)taosArrayGetSize(pReq->pTableCfg);
|
||||
|
||||
*taskNum = tbMetaNum + dbVgNum + udfNum + tbHashNum + qnodeNum + dnodeNum + svrVerNum + dbCfgNum + indexNum + userNum + dbInfoNum + tbIndexNum + tbCfgNum;
|
||||
if (*taskNum <= 0) {
|
||||
ctgDebug("Empty input for job, no need to retrieve meta, reqId:0x%" PRIx64, pConn->requestId);
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
int32_t taskNum = tbMetaNum + dbVgNum + udfNum + tbHashNum + qnodeNum + dnodeNum + svrVerNum + dbCfgNum + indexNum + userNum + dbInfoNum + tbIndexNum + tbCfgNum;
|
||||
|
||||
*job = taosMemoryCalloc(1, sizeof(SCtgJob));
|
||||
if (NULL == *job) {
|
||||
|
@ -477,15 +473,15 @@ int32_t ctgInitJob(SCatalog* pCtg, SRequestConnInfo *pConn, SCtgJob** job, const
|
|||
pJob->tbCfgNum = tbCfgNum;
|
||||
pJob->svrVerNum = svrVerNum;
|
||||
|
||||
pJob->pTasks = taosArrayInit(*taskNum, sizeof(SCtgTask));
|
||||
pJob->pTasks = taosArrayInit(taskNum, sizeof(SCtgTask));
|
||||
|
||||
if (NULL == pJob->pTasks) {
|
||||
ctgError("taosArrayInit %d tasks failed", *taskNum);
|
||||
ctgError("taosArrayInit %d tasks failed", taskNum);
|
||||
CTG_ERR_JRET(TSDB_CODE_OUT_OF_MEMORY);
|
||||
}
|
||||
|
||||
if (pReq->forceUpdate) {
|
||||
CTG_ERR_JRET(ctgHandleForceUpdate(pCtg, *taskNum, pJob, pReq));
|
||||
if (pReq->forceUpdate && taskNum) {
|
||||
CTG_ERR_JRET(ctgHandleForceUpdate(pCtg, taskNum, pJob, pReq));
|
||||
}
|
||||
|
||||
for (int32_t i = 0; i < dbVgNum; ++i) {
|
||||
|
@ -558,11 +554,12 @@ int32_t ctgInitJob(SCatalog* pCtg, SRequestConnInfo *pConn, SCtgJob** job, const
|
|||
|
||||
taosAcquireRef(gCtgMgmt.jobPool, pJob->refId);
|
||||
|
||||
qDebug("QID:0x%" PRIx64 ", jobId: 0x%" PRIx64 " initialized, task num %d, forceUpdate %d", pJob->queryId, pJob->refId, *taskNum, pReq->forceUpdate);
|
||||
qDebug("QID:0x%" PRIx64 ", jobId: 0x%" PRIx64 " initialized, task num %d, forceUpdate %d", pJob->queryId, pJob->refId, taskNum, pReq->forceUpdate);
|
||||
return TSDB_CODE_SUCCESS;
|
||||
|
||||
|
||||
_return:
|
||||
|
||||
taosMemoryFreeClear(*job);
|
||||
CTG_RET(code);
|
||||
}
|
||||
|
@ -763,7 +760,7 @@ int32_t ctgDumpSvrVer(SCtgTask* pTask) {
|
|||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
int32_t ctgInvokeSubCb(SCtgTask *pTask) {
|
||||
int32_t ctgCallSubCb(SCtgTask *pTask) {
|
||||
int32_t code = 0;
|
||||
|
||||
CTG_LOCK(CTG_WRITE, &pTask->lock);
|
||||
|
@ -790,6 +787,15 @@ _return:
|
|||
CTG_RET(code);
|
||||
}
|
||||
|
||||
int32_t ctgCallUserCb(void* param) {
|
||||
SCtgJob* pJob = (SCtgJob*)param;
|
||||
|
||||
(*pJob->userFp)(&pJob->jobRes, pJob->userParam, pJob->jobResCode);
|
||||
|
||||
taosRemoveRef(gCtgMgmt.jobPool, pJob->refId);
|
||||
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
int32_t ctgHandleTaskEnd(SCtgTask* pTask, int32_t rspCode) {
|
||||
SCtgJob* pJob = pTask->pJob;
|
||||
|
@ -804,7 +810,7 @@ int32_t ctgHandleTaskEnd(SCtgTask* pTask, int32_t rspCode) {
|
|||
pTask->code = rspCode;
|
||||
pTask->status = CTG_TASK_DONE;
|
||||
|
||||
ctgInvokeSubCb(pTask);
|
||||
ctgCallSubCb(pTask);
|
||||
|
||||
int32_t taskDone = atomic_add_fetch_32(&pJob->taskDone, 1);
|
||||
if (taskDone < taosArrayGetSize(pJob->pTasks)) {
|
||||
|
@ -818,9 +824,12 @@ _return:
|
|||
|
||||
qDebug("QID:0x%" PRIx64 " ctg call user callback with rsp %s", pJob->queryId, tstrerror(code));
|
||||
|
||||
(*pJob->userFp)(&pJob->jobRes, pJob->userParam, code);
|
||||
pJob->jobResCode = code;
|
||||
|
||||
taosRemoveRef(gCtgMgmt.jobPool, pJob->refId);
|
||||
//taosSsleep(2);
|
||||
//qDebug("QID:0x%" PRIx64 " ctg after sleep", pJob->queryId);
|
||||
|
||||
taosAsyncExec(ctgCallUserCb, pJob, NULL);
|
||||
|
||||
CTG_RET(code);
|
||||
}
|
||||
|
@ -1697,6 +1706,12 @@ int32_t ctgLaunchJob(SCtgJob *pJob) {
|
|||
pTask->status = CTG_TASK_LAUNCHED;
|
||||
}
|
||||
|
||||
if (taskNum <= 0) {
|
||||
qDebug("QID:0x%" PRIx64 " ctg call user callback with rsp %s", pJob->queryId, tstrerror(pJob->jobResCode));
|
||||
|
||||
taosAsyncExec(ctgCallUserCb, pJob, NULL);
|
||||
}
|
||||
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
|
|
|
@ -214,7 +214,7 @@ int32_t ctgAcquireVgInfoFromCache(SCatalog* pCtg, const char *dbFName, SCtgDBCac
|
|||
|
||||
*pCache = dbCache;
|
||||
|
||||
CTG_CACHE_STAT_INC(vgHitNum, 1);
|
||||
CTG_CACHE_STAT_INC(numOfVgHit, 1);
|
||||
|
||||
ctgDebug("Got db vgInfo from cache, dbFName:%s", dbFName);
|
||||
|
||||
|
@ -228,7 +228,7 @@ _return:
|
|||
|
||||
*pCache = NULL;
|
||||
|
||||
CTG_CACHE_STAT_INC(vgMissNum, 1);
|
||||
CTG_CACHE_STAT_INC(numOfVgMiss, 1);
|
||||
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
@ -260,7 +260,7 @@ int32_t ctgAcquireTbMetaFromCache(SCatalog* pCtg, char *dbFName, char* tbName, S
|
|||
|
||||
ctgDebug("tb %s meta got in cache, dbFName:%s", tbName, dbFName);
|
||||
|
||||
CTG_CACHE_STAT_INC(tbMetaHitNum, 1);
|
||||
CTG_CACHE_STAT_INC(numOfMetaHit, 1);
|
||||
|
||||
return TSDB_CODE_SUCCESS;
|
||||
|
||||
|
@ -268,7 +268,7 @@ _return:
|
|||
|
||||
ctgReleaseTbMetaToCache(pCtg, dbCache, pCache);
|
||||
|
||||
CTG_CACHE_STAT_INC(tbMetaMissNum, 1);
|
||||
CTG_CACHE_STAT_INC(numOfMetaMiss, 1);
|
||||
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
@ -307,7 +307,7 @@ int32_t ctgAcquireStbMetaFromCache(SCatalog* pCtg, char *dbFName, uint64_t suid,
|
|||
|
||||
ctgDebug("stb 0x%" PRIx64 " meta got in cache, dbFName:%s", suid, dbFName);
|
||||
|
||||
CTG_CACHE_STAT_INC(tbMetaHitNum, 1);
|
||||
CTG_CACHE_STAT_INC(numOfMetaHit, 1);
|
||||
|
||||
return TSDB_CODE_SUCCESS;
|
||||
|
||||
|
@ -315,7 +315,7 @@ _return:
|
|||
|
||||
ctgReleaseTbMetaToCache(pCtg, dbCache, pCache);
|
||||
|
||||
CTG_CACHE_STAT_INC(tbMetaMissNum, 1);
|
||||
CTG_CACHE_STAT_INC(numOfMetaMiss, 1);
|
||||
|
||||
*pDb = NULL;
|
||||
*pTb = NULL;
|
||||
|
@ -351,7 +351,7 @@ int32_t ctgAcquireTbIndexFromCache(SCatalog* pCtg, char *dbFName, char* tbName,
|
|||
|
||||
ctgDebug("tb %s index got in cache, dbFName:%s", tbName, dbFName);
|
||||
|
||||
CTG_CACHE_STAT_INC(tbIndexHitNum, 1);
|
||||
CTG_CACHE_STAT_INC(numOfIndexHit, 1);
|
||||
|
||||
return TSDB_CODE_SUCCESS;
|
||||
|
||||
|
@ -359,7 +359,7 @@ _return:
|
|||
|
||||
ctgReleaseTbIndexToCache(pCtg, dbCache, pCache);
|
||||
|
||||
CTG_CACHE_STAT_INC(tbIndexMissNum, 1);
|
||||
CTG_CACHE_STAT_INC(numOfIndexMiss, 1);
|
||||
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
@ -455,7 +455,7 @@ int32_t ctgReadTbMetaFromCache(SCatalog* pCtg, SCtgTbMetaCtx* ctx, STableMeta**
|
|||
*pTableMeta = taosMemoryRealloc(*pTableMeta, metaSize);
|
||||
if (NULL == *pTableMeta) {
|
||||
ctgReleaseTbMetaToCache(pCtg, dbCache, tbCache);
|
||||
CTG_ERR_JRET(TSDB_CODE_CTG_MEM_ERROR);
|
||||
CTG_ERR_JRET(TSDB_CODE_OUT_OF_MEMORY);
|
||||
}
|
||||
|
||||
memcpy(&(*pTableMeta)->sversion, &stbMeta->sversion, metaSize - sizeof(SCTableMeta));
|
||||
|
@ -583,11 +583,6 @@ _return:
|
|||
}
|
||||
|
||||
int32_t ctgChkAuthFromCache(SCatalog* pCtg, char* user, char* dbFName, AUTH_TYPE type, bool *inCache, bool *pass) {
|
||||
if (NULL == pCtg->userCache) {
|
||||
ctgDebug("empty user auth cache, user:%s", user);
|
||||
goto _return;
|
||||
}
|
||||
|
||||
SCtgUserAuth *pUser = (SCtgUserAuth *)taosHashGet(pCtg->userCache, user, strlen(user));
|
||||
if (NULL == pUser) {
|
||||
ctgDebug("user not in cache, user:%s", user);
|
||||
|
@ -597,7 +592,7 @@ int32_t ctgChkAuthFromCache(SCatalog* pCtg, char* user, char* dbFName, AUTH_TYPE
|
|||
*inCache = true;
|
||||
|
||||
ctgDebug("Got user from cache, user:%s", user);
|
||||
CTG_CACHE_STAT_INC(userHitNum, 1);
|
||||
CTG_CACHE_STAT_INC(numOfUserHit, 1);
|
||||
|
||||
if (pUser->superUser) {
|
||||
*pass = true;
|
||||
|
@ -626,7 +621,7 @@ int32_t ctgChkAuthFromCache(SCatalog* pCtg, char* user, char* dbFName, AUTH_TYPE
|
|||
_return:
|
||||
|
||||
*inCache = false;
|
||||
CTG_CACHE_STAT_INC(userMissNum, 1);
|
||||
CTG_CACHE_STAT_INC(numOfUserMiss, 1);
|
||||
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
@ -649,7 +644,7 @@ int32_t ctgEnqueue(SCatalog* pCtg, SCtgCacheOperation *operation) {
|
|||
SCtgQNode *node = taosMemoryCalloc(1, sizeof(SCtgQNode));
|
||||
if (NULL == node) {
|
||||
qError("calloc %d failed", (int32_t)sizeof(SCtgQNode));
|
||||
CTG_RET(TSDB_CODE_CTG_MEM_ERROR);
|
||||
CTG_RET(TSDB_CODE_OUT_OF_MEMORY);
|
||||
}
|
||||
|
||||
if (operation->syncOp) {
|
||||
|
@ -659,12 +654,18 @@ int32_t ctgEnqueue(SCatalog* pCtg, SCtgCacheOperation *operation) {
|
|||
node->op = operation;
|
||||
|
||||
CTG_LOCK(CTG_WRITE, &gCtgMgmt.queue.qlock);
|
||||
if (gCtgMgmt.queue.stopQueue) {
|
||||
ctgFreeQNode(node);
|
||||
CTG_UNLOCK(CTG_WRITE, &gCtgMgmt.queue.qlock);
|
||||
CTG_RET(TSDB_CODE_CTG_EXIT);
|
||||
}
|
||||
gCtgMgmt.queue.stopQueue = operation->stopQueue;
|
||||
gCtgMgmt.queue.tail->next = node;
|
||||
gCtgMgmt.queue.tail = node;
|
||||
CTG_UNLOCK(CTG_WRITE, &gCtgMgmt.queue.qlock);
|
||||
|
||||
CTG_QUEUE_INC();
|
||||
CTG_RT_STAT_INC(qNum, 1);
|
||||
CTG_RT_STAT_INC(numOfOpEnqueue, 1);
|
||||
|
||||
tsem_post(&gCtgMgmt.queue.reqSem);
|
||||
|
||||
|
@ -687,7 +688,7 @@ int32_t ctgDropDbCacheEnqueue(SCatalog* pCtg, const char *dbFName, int64_t dbId)
|
|||
SCtgDropDBMsg *msg = taosMemoryMalloc(sizeof(SCtgDropDBMsg));
|
||||
if (NULL == msg) {
|
||||
ctgError("malloc %d failed", (int32_t)sizeof(SCtgDropDBMsg));
|
||||
CTG_ERR_RET(TSDB_CODE_CTG_MEM_ERROR);
|
||||
CTG_ERR_RET(TSDB_CODE_OUT_OF_MEMORY);
|
||||
}
|
||||
|
||||
char *p = strchr(dbFName, '.');
|
||||
|
@ -720,7 +721,7 @@ int32_t ctgDropDbVgroupEnqueue(SCatalog* pCtg, const char *dbFName, bool syncOp)
|
|||
SCtgDropDbVgroupMsg *msg = taosMemoryMalloc(sizeof(SCtgDropDbVgroupMsg));
|
||||
if (NULL == msg) {
|
||||
ctgError("malloc %d failed", (int32_t)sizeof(SCtgDropDbVgroupMsg));
|
||||
CTG_ERR_RET(TSDB_CODE_CTG_MEM_ERROR);
|
||||
CTG_ERR_RET(TSDB_CODE_OUT_OF_MEMORY);
|
||||
}
|
||||
|
||||
char *p = strchr(dbFName, '.');
|
||||
|
@ -754,7 +755,7 @@ int32_t ctgDropStbMetaEnqueue(SCatalog* pCtg, const char *dbFName, int64_t dbId,
|
|||
SCtgDropStbMetaMsg *msg = taosMemoryMalloc(sizeof(SCtgDropStbMetaMsg));
|
||||
if (NULL == msg) {
|
||||
ctgError("malloc %d failed", (int32_t)sizeof(SCtgDropStbMetaMsg));
|
||||
CTG_ERR_RET(TSDB_CODE_CTG_MEM_ERROR);
|
||||
CTG_ERR_RET(TSDB_CODE_OUT_OF_MEMORY);
|
||||
}
|
||||
|
||||
msg->pCtg = pCtg;
|
||||
|
@ -786,7 +787,7 @@ int32_t ctgDropTbMetaEnqueue(SCatalog* pCtg, const char *dbFName, int64_t dbId,
|
|||
SCtgDropTblMetaMsg *msg = taosMemoryMalloc(sizeof(SCtgDropTblMetaMsg));
|
||||
if (NULL == msg) {
|
||||
ctgError("malloc %d failed", (int32_t)sizeof(SCtgDropTblMetaMsg));
|
||||
CTG_ERR_RET(TSDB_CODE_CTG_MEM_ERROR);
|
||||
CTG_ERR_RET(TSDB_CODE_OUT_OF_MEMORY);
|
||||
}
|
||||
|
||||
msg->pCtg = pCtg;
|
||||
|
@ -816,7 +817,7 @@ int32_t ctgUpdateVgroupEnqueue(SCatalog* pCtg, const char *dbFName, int64_t dbId
|
|||
if (NULL == msg) {
|
||||
ctgError("malloc %d failed", (int32_t)sizeof(SCtgUpdateVgMsg));
|
||||
ctgFreeVgInfo(dbInfo);
|
||||
CTG_ERR_RET(TSDB_CODE_CTG_MEM_ERROR);
|
||||
CTG_ERR_RET(TSDB_CODE_OUT_OF_MEMORY);
|
||||
}
|
||||
|
||||
char *p = strchr(dbFName, '.');
|
||||
|
@ -851,7 +852,7 @@ int32_t ctgUpdateTbMetaEnqueue(SCatalog* pCtg, STableMetaOutput *output, bool sy
|
|||
SCtgUpdateTbMetaMsg *msg = taosMemoryMalloc(sizeof(SCtgUpdateTbMetaMsg));
|
||||
if (NULL == msg) {
|
||||
ctgError("malloc %d failed", (int32_t)sizeof(SCtgUpdateTbMetaMsg));
|
||||
CTG_ERR_RET(TSDB_CODE_CTG_MEM_ERROR);
|
||||
CTG_ERR_RET(TSDB_CODE_OUT_OF_MEMORY);
|
||||
}
|
||||
|
||||
char *p = strchr(output->dbFName, '.');
|
||||
|
@ -883,7 +884,7 @@ int32_t ctgUpdateVgEpsetEnqueue(SCatalog* pCtg, char *dbFName, int32_t vgId, SEp
|
|||
SCtgUpdateEpsetMsg *msg = taosMemoryMalloc(sizeof(SCtgUpdateEpsetMsg));
|
||||
if (NULL == msg) {
|
||||
ctgError("malloc %d failed", (int32_t)sizeof(SCtgUpdateEpsetMsg));
|
||||
CTG_ERR_RET(TSDB_CODE_CTG_MEM_ERROR);
|
||||
CTG_ERR_RET(TSDB_CODE_OUT_OF_MEMORY);
|
||||
}
|
||||
|
||||
msg->pCtg = pCtg;
|
||||
|
@ -915,7 +916,7 @@ int32_t ctgUpdateUserEnqueue(SCatalog* pCtg, SGetUserAuthRsp *pAuth, bool syncOp
|
|||
SCtgUpdateUserMsg *msg = taosMemoryMalloc(sizeof(SCtgUpdateUserMsg));
|
||||
if (NULL == msg) {
|
||||
ctgError("malloc %d failed", (int32_t)sizeof(SCtgUpdateUserMsg));
|
||||
CTG_ERR_RET(TSDB_CODE_CTG_MEM_ERROR);
|
||||
CTG_ERR_RET(TSDB_CODE_OUT_OF_MEMORY);
|
||||
}
|
||||
|
||||
msg->pCtg = pCtg;
|
||||
|
@ -944,7 +945,7 @@ int32_t ctgUpdateTbIndexEnqueue(SCatalog* pCtg, STableIndex **pIndex, bool syncO
|
|||
SCtgUpdateTbIndexMsg *msg = taosMemoryMalloc(sizeof(SCtgUpdateTbIndexMsg));
|
||||
if (NULL == msg) {
|
||||
ctgError("malloc %d failed", (int32_t)sizeof(SCtgUpdateTbIndexMsg));
|
||||
CTG_ERR_JRET(TSDB_CODE_CTG_MEM_ERROR);
|
||||
CTG_ERR_JRET(TSDB_CODE_OUT_OF_MEMORY);
|
||||
}
|
||||
|
||||
msg->pCtg = pCtg;
|
||||
|
@ -975,7 +976,7 @@ int32_t ctgDropTbIndexEnqueue(SCatalog* pCtg, SName* pName, bool syncOp) {
|
|||
SCtgDropTbIndexMsg *msg = taosMemoryMalloc(sizeof(SCtgDropTbIndexMsg));
|
||||
if (NULL == msg) {
|
||||
ctgError("malloc %d failed", (int32_t)sizeof(SCtgDropTbIndexMsg));
|
||||
CTG_ERR_RET(TSDB_CODE_CTG_MEM_ERROR);
|
||||
CTG_ERR_RET(TSDB_CODE_OUT_OF_MEMORY);
|
||||
}
|
||||
|
||||
msg->pCtg = pCtg;
|
||||
|
@ -996,19 +997,21 @@ _return:
|
|||
}
|
||||
|
||||
|
||||
int32_t ctgClearCacheEnqueue(SCatalog* pCtg, bool syncOp) {
|
||||
int32_t ctgClearCacheEnqueue(SCatalog* pCtg, bool freeCtg, bool stopQueue, bool syncOp) {
|
||||
int32_t code = 0;
|
||||
SCtgCacheOperation *op = taosMemoryCalloc(1, sizeof(SCtgCacheOperation));
|
||||
op->opId = CTG_OP_CLEAR_CACHE;
|
||||
op->syncOp = syncOp;
|
||||
op->stopQueue = stopQueue;
|
||||
|
||||
SCtgClearCacheMsg *msg = taosMemoryMalloc(sizeof(SCtgClearCacheMsg));
|
||||
if (NULL == msg) {
|
||||
ctgError("malloc %d failed", (int32_t)sizeof(SCtgClearCacheMsg));
|
||||
CTG_ERR_RET(TSDB_CODE_CTG_MEM_ERROR);
|
||||
CTG_ERR_RET(TSDB_CODE_OUT_OF_MEMORY);
|
||||
}
|
||||
|
||||
msg->pCtg = pCtg;
|
||||
msg->freeCtg = freeCtg;
|
||||
op->data = msg;
|
||||
|
||||
CTG_ERR_JRET(ctgEnqueue(pCtg, op));
|
||||
|
@ -1033,7 +1036,7 @@ int32_t ctgMetaRentInit(SCtgRentMgmt *mgmt, uint32_t rentSec, int8_t type) {
|
|||
mgmt->slots = taosMemoryCalloc(1, msgSize);
|
||||
if (NULL == mgmt->slots) {
|
||||
qError("calloc %d failed", (int32_t)msgSize);
|
||||
CTG_ERR_RET(TSDB_CODE_CTG_MEM_ERROR);
|
||||
CTG_ERR_RET(TSDB_CODE_OUT_OF_MEMORY);
|
||||
}
|
||||
|
||||
qDebug("meta rent initialized, type:%d, slotNum:%d", type, mgmt->slotNum);
|
||||
|
@ -1053,13 +1056,13 @@ int32_t ctgMetaRentAdd(SCtgRentMgmt *mgmt, void *meta, int64_t id, int32_t size)
|
|||
slot->meta = taosArrayInit(CTG_DEFAULT_RENT_SLOT_SIZE, size);
|
||||
if (NULL == slot->meta) {
|
||||
qError("taosArrayInit %d failed, id:0x%"PRIx64", slot idx:%d, type:%d", CTG_DEFAULT_RENT_SLOT_SIZE, id, widx, mgmt->type);
|
||||
CTG_ERR_JRET(TSDB_CODE_CTG_MEM_ERROR);
|
||||
CTG_ERR_JRET(TSDB_CODE_OUT_OF_MEMORY);
|
||||
}
|
||||
}
|
||||
|
||||
if (NULL == taosArrayPush(slot->meta, meta)) {
|
||||
qError("taosArrayPush meta to rent failed, id:0x%"PRIx64", slot idx:%d, type:%d", id, widx, mgmt->type);
|
||||
CTG_ERR_JRET(TSDB_CODE_CTG_MEM_ERROR);
|
||||
CTG_ERR_JRET(TSDB_CODE_OUT_OF_MEMORY);
|
||||
}
|
||||
|
||||
slot->needSort = true;
|
||||
|
@ -1080,7 +1083,7 @@ int32_t ctgMetaRentUpdate(SCtgRentMgmt *mgmt, void *meta, int64_t id, int32_t si
|
|||
|
||||
CTG_LOCK(CTG_WRITE, &slot->lock);
|
||||
if (NULL == slot->meta) {
|
||||
qError("empty meta slot, id:0x%"PRIx64", slot idx:%d, type:%d", id, widx, mgmt->type);
|
||||
qDebug("empty meta slot, id:0x%"PRIx64", slot idx:%d, type:%d", id, widx, mgmt->type);
|
||||
CTG_ERR_JRET(TSDB_CODE_CTG_INTERNAL_ERROR);
|
||||
}
|
||||
|
||||
|
@ -1177,7 +1180,7 @@ int32_t ctgMetaRentGetImpl(SCtgRentMgmt *mgmt, void **res, uint32_t *num, int32_
|
|||
*res = taosMemoryMalloc(msize);
|
||||
if (NULL == *res) {
|
||||
qError("malloc %d failed", (int32_t)msize);
|
||||
CTG_ERR_JRET(TSDB_CODE_CTG_MEM_ERROR);
|
||||
CTG_ERR_JRET(TSDB_CODE_OUT_OF_MEMORY);
|
||||
}
|
||||
|
||||
void *meta = taosArrayGet(slot->meta, 0);
|
||||
|
@ -1227,13 +1230,13 @@ int32_t ctgAddNewDBCache(SCatalog *pCtg, const char *dbFName, uint64_t dbId) {
|
|||
newDBCache.tbCache = taosHashInit(gCtgMgmt.cfg.maxTblCacheNum, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BINARY), true, HASH_ENTRY_LOCK);
|
||||
if (NULL == newDBCache.tbCache) {
|
||||
ctgError("taosHashInit %d metaCache failed", gCtgMgmt.cfg.maxTblCacheNum);
|
||||
CTG_ERR_RET(TSDB_CODE_CTG_MEM_ERROR);
|
||||
CTG_ERR_RET(TSDB_CODE_OUT_OF_MEMORY);
|
||||
}
|
||||
|
||||
newDBCache.stbCache = taosHashInit(gCtgMgmt.cfg.maxTblCacheNum, taosGetDefaultHashFunction(TSDB_DATA_TYPE_UBIGINT), true, HASH_ENTRY_LOCK);
|
||||
if (NULL == newDBCache.stbCache) {
|
||||
ctgError("taosHashInit %d stbCache failed", gCtgMgmt.cfg.maxTblCacheNum);
|
||||
CTG_ERR_JRET(TSDB_CODE_CTG_MEM_ERROR);
|
||||
CTG_ERR_JRET(TSDB_CODE_OUT_OF_MEMORY);
|
||||
}
|
||||
|
||||
code = taosHashPut(pCtg->dbCache, dbFName, strlen(dbFName), &newDBCache, sizeof(SCtgDBCache));
|
||||
|
@ -1244,10 +1247,10 @@ int32_t ctgAddNewDBCache(SCatalog *pCtg, const char *dbFName, uint64_t dbId) {
|
|||
}
|
||||
|
||||
ctgError("taosHashPut db to cache failed, dbFName:%s", dbFName);
|
||||
CTG_ERR_JRET(TSDB_CODE_CTG_MEM_ERROR);
|
||||
CTG_ERR_JRET(TSDB_CODE_OUT_OF_MEMORY);
|
||||
}
|
||||
|
||||
CTG_CACHE_STAT_INC(dbNum, 1);
|
||||
CTG_CACHE_STAT_INC(numOfDb, 1);
|
||||
|
||||
SDbVgVersion vgVersion = {.dbId = newDBCache.dbId, .vgVersion = -1};
|
||||
strncpy(vgVersion.dbFName, dbFName, sizeof(vgVersion.dbFName));
|
||||
|
@ -1308,7 +1311,7 @@ int32_t ctgRemoveDBFromCache(SCatalog* pCtg, SCtgDBCache *dbCache, const char* d
|
|||
CTG_ERR_RET(TSDB_CODE_CTG_DB_DROPPED);
|
||||
}
|
||||
|
||||
CTG_CACHE_STAT_DEC(dbNum, 1);
|
||||
CTG_CACHE_STAT_DEC(numOfDb, 1);
|
||||
ctgInfo("db removed from cache, dbFName:%s, dbId:0x%"PRIx64, dbFName, dbId);
|
||||
|
||||
return TSDB_CODE_SUCCESS;
|
||||
|
@ -1405,7 +1408,7 @@ int32_t ctgWriteTbMetaToCache(SCatalog *pCtg, SCtgDBCache *dbCache, char *dbFNam
|
|||
if (taosHashRemove(dbCache->stbCache, &orig->suid, sizeof(orig->suid))) {
|
||||
ctgError("stb not exist in stbCache, dbFName:%s, stb:%s, suid:0x%"PRIx64, dbFName, tbName, orig->suid);
|
||||
} else {
|
||||
CTG_CACHE_STAT_DEC(stblNum, 1);
|
||||
CTG_CACHE_STAT_DEC(numOfStb, 1);
|
||||
ctgDebug("stb removed from stbCache, dbFName:%s, stb:%s, suid:0x%"PRIx64, dbFName, tbName, orig->suid);
|
||||
}
|
||||
|
||||
|
@ -1419,7 +1422,7 @@ int32_t ctgWriteTbMetaToCache(SCatalog *pCtg, SCtgDBCache *dbCache, char *dbFNam
|
|||
if (taosHashPut(dbCache->tbCache, tbName, strlen(tbName), &cache, sizeof(SCtgTbCache)) != 0) {
|
||||
taosMemoryFree(meta);
|
||||
ctgError("taosHashPut new tbCache failed, dbFName:%s, tbName:%s, tbType:%d", dbFName, tbName, meta->tableType);
|
||||
CTG_ERR_RET(TSDB_CODE_CTG_MEM_ERROR);
|
||||
CTG_ERR_RET(TSDB_CODE_OUT_OF_MEMORY);
|
||||
}
|
||||
|
||||
pCache = taosHashGet(dbCache->tbCache, tbName, strlen(tbName));
|
||||
|
@ -1429,7 +1432,7 @@ int32_t ctgWriteTbMetaToCache(SCatalog *pCtg, SCtgDBCache *dbCache, char *dbFNam
|
|||
}
|
||||
|
||||
if (NULL == orig) {
|
||||
CTG_CACHE_STAT_INC(tblNum, 1);
|
||||
CTG_CACHE_STAT_INC(numOfTbl, 1);
|
||||
}
|
||||
|
||||
ctgDebug("tbmeta updated to cache, dbFName:%s, tbName:%s, tbType:%d", dbFName, tbName, meta->tableType);
|
||||
|
@ -1441,10 +1444,10 @@ int32_t ctgWriteTbMetaToCache(SCatalog *pCtg, SCtgDBCache *dbCache, char *dbFNam
|
|||
|
||||
if (origSuid != meta->suid && taosHashPut(dbCache->stbCache, &meta->suid, sizeof(meta->suid), tbName, strlen(tbName) + 1) != 0) {
|
||||
ctgError("taosHashPut to stable cache failed, suid:0x%"PRIx64, meta->suid);
|
||||
CTG_ERR_RET(TSDB_CODE_CTG_MEM_ERROR);
|
||||
CTG_ERR_RET(TSDB_CODE_OUT_OF_MEMORY);
|
||||
}
|
||||
|
||||
CTG_CACHE_STAT_INC(stblNum, 1);
|
||||
CTG_CACHE_STAT_INC(numOfStb, 1);
|
||||
|
||||
ctgDebug("stb 0x%" PRIx64 " updated to cache, dbFName:%s, tbName:%s, tbType:%d", meta->suid, dbFName, tbName, meta->tableType);
|
||||
|
||||
|
@ -1472,7 +1475,7 @@ int32_t ctgWriteTbIndexToCache(SCatalog *pCtg, SCtgDBCache *dbCache, char* dbFNa
|
|||
ctgFreeSTableIndex(*index);
|
||||
taosMemoryFreeClear(*index);
|
||||
ctgError("taosHashPut new tbCache failed, tbName:%s", tbName);
|
||||
CTG_ERR_RET(TSDB_CODE_CTG_MEM_ERROR);
|
||||
CTG_ERR_RET(TSDB_CODE_OUT_OF_MEMORY);
|
||||
}
|
||||
|
||||
*index = NULL;
|
||||
|
@ -1520,6 +1523,39 @@ _return:
|
|||
CTG_RET(code);
|
||||
}
|
||||
|
||||
void ctgClearAllInstance(void) {
|
||||
SCatalog* pCtg = NULL;
|
||||
|
||||
void* pIter = taosHashIterate(gCtgMgmt.pCluster, NULL);
|
||||
while (pIter) {
|
||||
pCtg = *(SCatalog**)pIter;
|
||||
|
||||
if (pCtg) {
|
||||
ctgClearHandle(pCtg);
|
||||
}
|
||||
|
||||
pIter = taosHashIterate(gCtgMgmt.pCluster, pIter);
|
||||
}
|
||||
}
|
||||
|
||||
void ctgFreeAllInstance(void) {
|
||||
SCatalog* pCtg = NULL;
|
||||
|
||||
void* pIter = taosHashIterate(gCtgMgmt.pCluster, NULL);
|
||||
while (pIter) {
|
||||
pCtg = *(SCatalog**)pIter;
|
||||
|
||||
if (pCtg) {
|
||||
ctgFreeHandle(pCtg);
|
||||
}
|
||||
|
||||
pIter = taosHashIterate(gCtgMgmt.pCluster, pIter);
|
||||
}
|
||||
|
||||
taosHashClear(gCtgMgmt.pCluster);
|
||||
}
|
||||
|
||||
|
||||
int32_t ctgOpUpdateVgroup(SCtgCacheOperation *operation) {
|
||||
int32_t code = 0;
|
||||
SCtgUpdateVgMsg *msg = operation->data;
|
||||
|
@ -1528,27 +1564,27 @@ int32_t ctgOpUpdateVgroup(SCtgCacheOperation *operation) {
|
|||
SCatalog* pCtg = msg->pCtg;
|
||||
|
||||
if (NULL == dbInfo->vgHash) {
|
||||
return TSDB_CODE_SUCCESS;
|
||||
goto _return;
|
||||
}
|
||||
|
||||
if (dbInfo->vgVersion < 0 || taosHashGetSize(dbInfo->vgHash) <= 0) {
|
||||
ctgError("invalid db vgInfo, dbFName:%s, vgHash:%p, vgVersion:%d, vgHashSize:%d",
|
||||
dbFName, dbInfo->vgHash, dbInfo->vgVersion, taosHashGetSize(dbInfo->vgHash));
|
||||
CTG_ERR_RET(TSDB_CODE_CTG_MEM_ERROR);
|
||||
CTG_ERR_JRET(TSDB_CODE_APP_ERROR);
|
||||
}
|
||||
|
||||
bool newAdded = false;
|
||||
SDbVgVersion vgVersion = {.dbId = msg->dbId, .vgVersion = dbInfo->vgVersion, .numOfTable = dbInfo->numOfTable};
|
||||
|
||||
SCtgDBCache *dbCache = NULL;
|
||||
CTG_ERR_RET(ctgGetAddDBCache(msg->pCtg, dbFName, msg->dbId, &dbCache));
|
||||
CTG_ERR_JRET(ctgGetAddDBCache(msg->pCtg, dbFName, msg->dbId, &dbCache));
|
||||
if (NULL == dbCache) {
|
||||
ctgInfo("conflict db update, ignore this update, dbFName:%s, dbId:0x%"PRIx64, dbFName, msg->dbId);
|
||||
CTG_ERR_RET(TSDB_CODE_CTG_INTERNAL_ERROR);
|
||||
CTG_ERR_JRET(TSDB_CODE_CTG_INTERNAL_ERROR);
|
||||
}
|
||||
|
||||
SCtgVgCache *vgCache = &dbCache->vgCache;
|
||||
CTG_ERR_RET(ctgWLockVgInfo(msg->pCtg, dbCache));
|
||||
CTG_ERR_JRET(ctgWLockVgInfo(msg->pCtg, dbCache));
|
||||
|
||||
if (vgCache->vgInfo) {
|
||||
SDBVgInfo *vgInfo = vgCache->vgInfo;
|
||||
|
@ -1557,14 +1593,14 @@ int32_t ctgOpUpdateVgroup(SCtgCacheOperation *operation) {
|
|||
ctgDebug("db vgVer is old, dbFName:%s, vgVer:%d, curVer:%d", dbFName, dbInfo->vgVersion, vgInfo->vgVersion);
|
||||
ctgWUnlockVgInfo(dbCache);
|
||||
|
||||
return TSDB_CODE_SUCCESS;
|
||||
goto _return;
|
||||
}
|
||||
|
||||
if (dbInfo->vgVersion == vgInfo->vgVersion && dbInfo->numOfTable == vgInfo->numOfTable) {
|
||||
ctgDebug("no new db vgVer or numOfTable, dbFName:%s, vgVer:%d, numOfTable:%d", dbFName, dbInfo->vgVersion, dbInfo->numOfTable);
|
||||
ctgWUnlockVgInfo(dbCache);
|
||||
|
||||
return TSDB_CODE_SUCCESS;
|
||||
goto _return;
|
||||
}
|
||||
|
||||
ctgFreeVgInfo(vgInfo);
|
||||
|
@ -1714,13 +1750,13 @@ int32_t ctgOpDropStbMeta(SCtgCacheOperation *operation) {
|
|||
if (taosHashRemove(dbCache->stbCache, &msg->suid, sizeof(msg->suid))) {
|
||||
ctgDebug("stb not exist in stbCache, may be removed, dbFName:%s, stb:%s, suid:0x%"PRIx64, msg->dbFName, msg->stbName, msg->suid);
|
||||
} else {
|
||||
CTG_CACHE_STAT_DEC(stblNum, 1);
|
||||
CTG_CACHE_STAT_DEC(numOfStb, 1);
|
||||
}
|
||||
|
||||
if (taosHashRemove(dbCache->tbCache, msg->stbName, strlen(msg->stbName))) {
|
||||
ctgError("stb not exist in cache, dbFName:%s, stb:%s, suid:0x%"PRIx64, msg->dbFName, msg->stbName, msg->suid);
|
||||
} else {
|
||||
CTG_CACHE_STAT_DEC(tblNum, 1);
|
||||
CTG_CACHE_STAT_DEC(numOfTbl, 1);
|
||||
}
|
||||
|
||||
ctgInfo("stb removed from cache, dbFName:%s, stbName:%s, suid:0x%"PRIx64, msg->dbFName, msg->stbName, msg->suid);
|
||||
|
@ -1756,7 +1792,7 @@ int32_t ctgOpDropTbMeta(SCtgCacheOperation *operation) {
|
|||
ctgError("tb %s not exist in cache, dbFName:%s", msg->tbName, msg->dbFName);
|
||||
CTG_ERR_JRET(TSDB_CODE_CTG_INTERNAL_ERROR);
|
||||
} else {
|
||||
CTG_CACHE_STAT_DEC(tblNum, 1);
|
||||
CTG_CACHE_STAT_DEC(numOfTbl, 1);
|
||||
}
|
||||
|
||||
ctgDebug("table %s removed from cache, dbFName:%s", msg->tbName, msg->dbFName);
|
||||
|
@ -1773,14 +1809,6 @@ int32_t ctgOpUpdateUser(SCtgCacheOperation *operation) {
|
|||
SCtgUpdateUserMsg *msg = operation->data;
|
||||
SCatalog* pCtg = msg->pCtg;
|
||||
|
||||
if (NULL == pCtg->userCache) {
|
||||
pCtg->userCache = taosHashInit(gCtgMgmt.cfg.maxUserCacheNum, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BINARY), false, HASH_ENTRY_LOCK);
|
||||
if (NULL == pCtg->userCache) {
|
||||
ctgError("taosHashInit %d user cache failed", gCtgMgmt.cfg.maxUserCacheNum);
|
||||
CTG_ERR_JRET(TSDB_CODE_OUT_OF_MEMORY);
|
||||
}
|
||||
}
|
||||
|
||||
SCtgUserAuth *pUser = (SCtgUserAuth *)taosHashGet(pCtg->userCache, msg->userAuth.user, strlen(msg->userAuth.user));
|
||||
if (NULL == pUser) {
|
||||
SCtgUserAuth userAuth = {0};
|
||||
|
@ -1937,49 +1965,59 @@ int32_t ctgOpClearCache(SCtgCacheOperation *operation) {
|
|||
SCtgClearCacheMsg *msg = operation->data;
|
||||
SCatalog* pCtg = msg->pCtg;
|
||||
|
||||
CTG_LOCK(CTG_WRITE, &gCtgMgmt.lock);
|
||||
|
||||
if (pCtg) {
|
||||
catalogFreeHandle(pCtg);
|
||||
if (msg->freeCtg) {
|
||||
ctgFreeHandle(pCtg);
|
||||
} else {
|
||||
ctgClearHandle(pCtg);
|
||||
}
|
||||
|
||||
goto _return;
|
||||
}
|
||||
|
||||
void* pIter = taosHashIterate(gCtgMgmt.pCluster, NULL);
|
||||
while (pIter) {
|
||||
pCtg = *(SCatalog**)pIter;
|
||||
|
||||
if (pCtg) {
|
||||
catalogFreeHandle(pCtg);
|
||||
if (msg->freeCtg) {
|
||||
ctgFreeAllInstance();
|
||||
} else {
|
||||
ctgClearAllInstance();
|
||||
}
|
||||
|
||||
pIter = taosHashIterate(gCtgMgmt.pCluster, pIter);
|
||||
}
|
||||
|
||||
taosHashClear(gCtgMgmt.pCluster);
|
||||
|
||||
_return:
|
||||
|
||||
CTG_UNLOCK(CTG_WRITE, &gCtgMgmt.lock);
|
||||
|
||||
taosMemoryFreeClear(msg);
|
||||
|
||||
CTG_RET(code);
|
||||
}
|
||||
|
||||
|
||||
void ctgUpdateThreadUnexpectedStopped(void) {
|
||||
if (!atomic_load_8((int8_t*)&gCtgMgmt.exit) && CTG_IS_LOCKED(&gCtgMgmt.lock) > 0) CTG_UNLOCK(CTG_READ, &gCtgMgmt.lock);
|
||||
}
|
||||
|
||||
void ctgCleanupCacheQueue(void) {
|
||||
SCtgQNode *node = NULL;
|
||||
SCtgQNode *nodeNext = NULL;
|
||||
SCtgCacheOperation *op = NULL;
|
||||
bool stopQueue = false;
|
||||
|
||||
while (true) {
|
||||
node = gCtgMgmt.queue.head->next;
|
||||
while (node) {
|
||||
if (node->op) {
|
||||
taosMemoryFree(node->op->data);
|
||||
if (node->op->syncOp) {
|
||||
tsem_post(&node->op->rspSem);
|
||||
op = node->op;
|
||||
if (op->stopQueue) {
|
||||
SCatalog *pCtg = ((SCtgUpdateMsgHeader *)op->data)->pCtg;
|
||||
ctgDebug("process [%s] operation", gCtgCacheOperation[op->opId].name);
|
||||
(*gCtgCacheOperation[op->opId].func)(op);
|
||||
stopQueue = true;
|
||||
CTG_RT_STAT_INC(numOfOpDequeue, 1);
|
||||
} else {
|
||||
taosMemoryFree(node->op);
|
||||
taosMemoryFree(op->data);
|
||||
CTG_RT_STAT_INC(numOfOpAbort, 1);
|
||||
}
|
||||
|
||||
if (op->syncOp) {
|
||||
tsem_post(&op->rspSem);
|
||||
} else {
|
||||
taosMemoryFree(op);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1989,7 +2027,7 @@ void ctgCleanupCacheQueue(void) {
|
|||
node = nodeNext;
|
||||
}
|
||||
|
||||
if (CTG_IS_LOCKED(&gCtgMgmt.lock)) {
|
||||
if (!stopQueue) {
|
||||
taosUsleep(1);
|
||||
} else {
|
||||
break;
|
||||
|
@ -2002,14 +2040,8 @@ void ctgCleanupCacheQueue(void) {
|
|||
|
||||
void* ctgUpdateThreadFunc(void* param) {
|
||||
setThreadName("catalog");
|
||||
#ifdef WINDOWS
|
||||
if (taosCheckCurrentInDll()) {
|
||||
atexit(ctgUpdateThreadUnexpectedStopped);
|
||||
}
|
||||
#endif
|
||||
qInfo("catalog update thread started");
|
||||
|
||||
CTG_LOCK(CTG_READ, &gCtgMgmt.lock);
|
||||
qInfo("catalog update thread started");
|
||||
|
||||
while (true) {
|
||||
if (tsem_wait(&gCtgMgmt.queue.reqSem)) {
|
||||
|
@ -2017,7 +2049,6 @@ void* ctgUpdateThreadFunc(void* param) {
|
|||
}
|
||||
|
||||
if (atomic_load_8((int8_t*)&gCtgMgmt.exit)) {
|
||||
CTG_UNLOCK(CTG_READ, &gCtgMgmt.lock);
|
||||
ctgCleanupCacheQueue();
|
||||
break;
|
||||
}
|
||||
|
@ -2034,7 +2065,7 @@ void* ctgUpdateThreadFunc(void* param) {
|
|||
tsem_post(&operation->rspSem);
|
||||
}
|
||||
|
||||
CTG_RT_STAT_INC(qDoneNum, 1);
|
||||
CTG_RT_STAT_INC(numOfOpDequeue, 1);
|
||||
|
||||
ctgdShowCacheInfo();
|
||||
ctgdShowClusterCache(pCtg);
|
||||
|
|
|
@ -19,7 +19,7 @@
|
|||
#include "catalogInt.h"
|
||||
|
||||
extern SCatalogMgmt gCtgMgmt;
|
||||
SCtgDebug gCTGDebug = {.cacheEnable = true};
|
||||
SCtgDebug gCTGDebug = {0};
|
||||
|
||||
void ctgdUserCallback(SMetaData* pResult, void* param, int32_t code) {
|
||||
ASSERT(*(int32_t*)param == 1);
|
||||
|
@ -255,8 +255,8 @@ int32_t ctgdEnableDebug(char *option) {
|
|||
}
|
||||
|
||||
int32_t ctgdGetStatNum(char *option, void *res) {
|
||||
if (0 == strcasecmp(option, "runtime.qDoneNum")) {
|
||||
*(uint64_t *)res = atomic_load_64(&gCtgMgmt.stat.runtime.qDoneNum);
|
||||
if (0 == strcasecmp(option, "runtime.numOfOpDequeue")) {
|
||||
*(uint64_t *)res = atomic_load_64(&gCtgMgmt.stat.runtime.numOfOpDequeue);
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
|
|
|
@ -52,6 +52,10 @@ char *ctgTaskTypeStr(CTG_TASK_TYPE type) {
|
|||
}
|
||||
}
|
||||
|
||||
void ctgFreeQNode(SCtgQNode *node) {
|
||||
//TODO
|
||||
}
|
||||
|
||||
void ctgFreeSTableIndex(void *info) {
|
||||
if (NULL == info) {
|
||||
return;
|
||||
|
@ -141,10 +145,10 @@ void ctgFreeStbMetaCache(SCtgDBCache *dbCache) {
|
|||
return;
|
||||
}
|
||||
|
||||
int32_t stblNum = taosHashGetSize(dbCache->stbCache);
|
||||
int32_t stbNum = taosHashGetSize(dbCache->stbCache);
|
||||
taosHashCleanup(dbCache->stbCache);
|
||||
dbCache->stbCache = NULL;
|
||||
CTG_CACHE_STAT_DEC(stblNum, stblNum);
|
||||
CTG_CACHE_STAT_DEC(numOfStb, stbNum);
|
||||
}
|
||||
|
||||
void ctgFreeTbCacheImpl(SCtgTbCache *pCache) {
|
||||
|
@ -168,7 +172,7 @@ void ctgFreeTbCache(SCtgDBCache *dbCache) {
|
|||
}
|
||||
taosHashCleanup(dbCache->tbCache);
|
||||
dbCache->tbCache = NULL;
|
||||
CTG_CACHE_STAT_DEC(tblNum, tblNum);
|
||||
CTG_CACHE_STAT_DEC(numOfTbl, tblNum);
|
||||
}
|
||||
|
||||
void ctgFreeVgInfo(SDBVgInfo *vgInfo) {
|
||||
|
@ -198,46 +202,109 @@ void ctgFreeDbCache(SCtgDBCache *dbCache) {
|
|||
ctgFreeTbCache(dbCache);
|
||||
}
|
||||
|
||||
void ctgFreeInstDbCache(SHashObj* pDbCache) {
|
||||
if (NULL == pDbCache) {
|
||||
return;
|
||||
}
|
||||
|
||||
void ctgFreeHandle(SCatalog* pCtg) {
|
||||
ctgFreeMetaRent(&pCtg->dbRent);
|
||||
ctgFreeMetaRent(&pCtg->stbRent);
|
||||
int32_t dbNum = taosHashGetSize(pDbCache);
|
||||
|
||||
if (pCtg->dbCache) {
|
||||
int32_t dbNum = taosHashGetSize(pCtg->dbCache);
|
||||
|
||||
void *pIter = taosHashIterate(pCtg->dbCache, NULL);
|
||||
void *pIter = taosHashIterate(pDbCache, NULL);
|
||||
while (pIter) {
|
||||
SCtgDBCache *dbCache = pIter;
|
||||
atomic_store_8(&dbCache->deleted, 1);
|
||||
ctgFreeDbCache(dbCache);
|
||||
|
||||
pIter = taosHashIterate(pCtg->dbCache, pIter);
|
||||
pIter = taosHashIterate(pDbCache, pIter);
|
||||
}
|
||||
|
||||
taosHashCleanup(pCtg->dbCache);
|
||||
CTG_CACHE_STAT_DEC(dbNum, dbNum);
|
||||
taosHashCleanup(pDbCache);
|
||||
|
||||
CTG_CACHE_STAT_DEC(numOfDb, dbNum);
|
||||
}
|
||||
|
||||
void ctgFreeInstUserCache(SHashObj* pUserCache) {
|
||||
if (NULL == pUserCache) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (pCtg->userCache) {
|
||||
int32_t userNum = taosHashGetSize(pCtg->userCache);
|
||||
int32_t userNum = taosHashGetSize(pUserCache);
|
||||
|
||||
void *pIter = taosHashIterate(pCtg->userCache, NULL);
|
||||
void *pIter = taosHashIterate(pUserCache, NULL);
|
||||
while (pIter) {
|
||||
SCtgUserAuth *userCache = pIter;
|
||||
ctgFreeSCtgUserAuth(userCache);
|
||||
|
||||
pIter = taosHashIterate(pCtg->userCache, pIter);
|
||||
pIter = taosHashIterate(pUserCache, pIter);
|
||||
}
|
||||
|
||||
taosHashCleanup(pCtg->userCache);
|
||||
CTG_CACHE_STAT_DEC(userNum, userNum);
|
||||
}
|
||||
taosHashCleanup(pUserCache);
|
||||
|
||||
CTG_CACHE_STAT_DEC(numOfUser, userNum);
|
||||
}
|
||||
|
||||
void ctgFreeHandleImpl(SCatalog* pCtg) {
|
||||
ctgFreeMetaRent(&pCtg->dbRent);
|
||||
ctgFreeMetaRent(&pCtg->stbRent);
|
||||
|
||||
ctgFreeInstDbCache(pCtg->dbCache);
|
||||
ctgFreeInstUserCache(pCtg->userCache);
|
||||
|
||||
taosMemoryFree(pCtg);
|
||||
}
|
||||
|
||||
|
||||
void ctgFreeHandle(SCatalog* pCtg) {
|
||||
if (NULL == pCtg) {
|
||||
return;
|
||||
}
|
||||
|
||||
uint64_t clusterId = pCtg->clusterId;
|
||||
|
||||
ctgFreeMetaRent(&pCtg->dbRent);
|
||||
ctgFreeMetaRent(&pCtg->stbRent);
|
||||
|
||||
ctgFreeInstDbCache(pCtg->dbCache);
|
||||
ctgFreeInstUserCache(pCtg->userCache);
|
||||
|
||||
CTG_CACHE_STAT_DEC(numOfCluster, 1);
|
||||
|
||||
taosMemoryFree(pCtg);
|
||||
|
||||
ctgInfo("handle freed, culsterId:0x%" PRIx64, clusterId);
|
||||
}
|
||||
|
||||
void ctgClearHandle(SCatalog* pCtg) {
|
||||
if (NULL == pCtg) {
|
||||
return;
|
||||
}
|
||||
|
||||
uint64_t clusterId = pCtg->clusterId;
|
||||
|
||||
ctgFreeMetaRent(&pCtg->dbRent);
|
||||
ctgFreeMetaRent(&pCtg->stbRent);
|
||||
|
||||
ctgFreeInstDbCache(pCtg->dbCache);
|
||||
ctgFreeInstUserCache(pCtg->userCache);
|
||||
|
||||
ctgMetaRentInit(&pCtg->dbRent, gCtgMgmt.cfg.dbRentSec, CTG_RENT_DB);
|
||||
ctgMetaRentInit(&pCtg->stbRent, gCtgMgmt.cfg.stbRentSec, CTG_RENT_STABLE);
|
||||
|
||||
pCtg->dbCache = taosHashInit(gCtgMgmt.cfg.maxDBCacheNum, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BINARY), false, HASH_ENTRY_LOCK);
|
||||
if (NULL == pCtg->dbCache) {
|
||||
qError("taosHashInit %d dbCache failed", CTG_DEFAULT_CACHE_DB_NUMBER);
|
||||
}
|
||||
|
||||
pCtg->userCache = taosHashInit(gCtgMgmt.cfg.maxUserCacheNum, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BINARY), false, HASH_ENTRY_LOCK);
|
||||
if (NULL == pCtg->userCache) {
|
||||
ctgError("taosHashInit %d user cache failed", gCtgMgmt.cfg.maxUserCacheNum);
|
||||
}
|
||||
|
||||
CTG_CACHE_STAT_INC(numOfClear, 1);
|
||||
|
||||
ctgInfo("handle cleared, culsterId:0x%" PRIx64, clusterId);
|
||||
}
|
||||
|
||||
void ctgFreeSUseDbOutput(SUseDbOutput* pOutput) {
|
||||
if (NULL == pOutput) {
|
||||
return;
|
||||
|
@ -590,7 +657,7 @@ int32_t ctgGenerateVgList(SCatalog *pCtg, SHashObj *vgHash, SArray** pList) {
|
|||
vgList = taosArrayInit(vgNum, sizeof(SVgroupInfo));
|
||||
if (NULL == vgList) {
|
||||
ctgError("taosArrayInit failed, num:%d", vgNum);
|
||||
CTG_ERR_RET(TSDB_CODE_CTG_MEM_ERROR);
|
||||
CTG_ERR_RET(TSDB_CODE_OUT_OF_MEMORY);
|
||||
}
|
||||
|
||||
void *pIter = taosHashIterate(vgHash, NULL);
|
||||
|
@ -600,7 +667,7 @@ int32_t ctgGenerateVgList(SCatalog *pCtg, SHashObj *vgHash, SArray** pList) {
|
|||
if (NULL == taosArrayPush(vgList, vgInfo)) {
|
||||
ctgError("taosArrayPush failed, vgId:%d", vgInfo->vgId);
|
||||
taosHashCancelIterate(vgHash, pIter);
|
||||
CTG_ERR_JRET(TSDB_CODE_CTG_MEM_ERROR);
|
||||
CTG_ERR_JRET(TSDB_CODE_OUT_OF_MEMORY);
|
||||
}
|
||||
|
||||
pIter = taosHashIterate(vgHash, pIter);
|
||||
|
@ -717,7 +784,7 @@ int32_t ctgCloneVgInfo(SDBVgInfo *src, SDBVgInfo **dst) {
|
|||
*dst = taosMemoryMalloc(sizeof(SDBVgInfo));
|
||||
if (NULL == *dst) {
|
||||
qError("malloc %d failed", (int32_t)sizeof(SDBVgInfo));
|
||||
CTG_ERR_RET(TSDB_CODE_CTG_MEM_ERROR);
|
||||
CTG_ERR_RET(TSDB_CODE_OUT_OF_MEMORY);
|
||||
}
|
||||
|
||||
memcpy(*dst, src, sizeof(SDBVgInfo));
|
||||
|
@ -727,7 +794,7 @@ int32_t ctgCloneVgInfo(SDBVgInfo *src, SDBVgInfo **dst) {
|
|||
if (NULL == (*dst)->vgHash) {
|
||||
qError("taosHashInit %d failed", (int32_t)hashSize);
|
||||
taosMemoryFreeClear(*dst);
|
||||
CTG_ERR_RET(TSDB_CODE_CTG_MEM_ERROR);
|
||||
CTG_ERR_RET(TSDB_CODE_OUT_OF_MEMORY);
|
||||
}
|
||||
|
||||
int32_t *vgId = NULL;
|
||||
|
@ -740,7 +807,7 @@ int32_t ctgCloneVgInfo(SDBVgInfo *src, SDBVgInfo **dst) {
|
|||
taosHashCancelIterate(src->vgHash, pIter);
|
||||
taosHashCleanup((*dst)->vgHash);
|
||||
taosMemoryFreeClear(*dst);
|
||||
CTG_ERR_RET(TSDB_CODE_CTG_MEM_ERROR);
|
||||
CTG_ERR_RET(TSDB_CODE_OUT_OF_MEMORY);
|
||||
}
|
||||
|
||||
pIter = taosHashIterate(src->vgHash, pIter);
|
||||
|
@ -756,7 +823,7 @@ int32_t ctgCloneMetaOutput(STableMetaOutput *output, STableMetaOutput **pOutput)
|
|||
*pOutput = taosMemoryMalloc(sizeof(STableMetaOutput));
|
||||
if (NULL == *pOutput) {
|
||||
qError("malloc %d failed", (int32_t)sizeof(STableMetaOutput));
|
||||
CTG_ERR_RET(TSDB_CODE_CTG_MEM_ERROR);
|
||||
CTG_ERR_RET(TSDB_CODE_OUT_OF_MEMORY);
|
||||
}
|
||||
|
||||
memcpy(*pOutput, output, sizeof(STableMetaOutput));
|
||||
|
@ -767,7 +834,7 @@ int32_t ctgCloneMetaOutput(STableMetaOutput *output, STableMetaOutput **pOutput)
|
|||
if (NULL == (*pOutput)->tbMeta) {
|
||||
qError("malloc %d failed", (int32_t)sizeof(STableMetaOutput));
|
||||
taosMemoryFreeClear(*pOutput);
|
||||
CTG_ERR_RET(TSDB_CODE_CTG_MEM_ERROR);
|
||||
CTG_ERR_RET(TSDB_CODE_OUT_OF_MEMORY);
|
||||
}
|
||||
|
||||
memcpy((*pOutput)->tbMeta, output->tbMeta, metaSize);
|
||||
|
|
|
@ -1386,7 +1386,7 @@ TEST(tableMeta, updateStbMeta) {
|
|||
|
||||
while (true) {
|
||||
uint64_t n = 0;
|
||||
ctgdGetStatNum("runtime.qDoneNum", (void *)&n);
|
||||
ctgdGetStatNum("runtime.numOfOpDequeue", (void *)&n);
|
||||
if (n != 3) {
|
||||
taosMsleep(50);
|
||||
} else {
|
||||
|
@ -1456,7 +1456,7 @@ TEST(refreshGetMeta, normal2normal) {
|
|||
|
||||
while (true) {
|
||||
uint64_t n = 0;
|
||||
ctgdGetStatNum("runtime.qDoneNum", (void *)&n);
|
||||
ctgdGetStatNum("runtime.numOfOpDequeue", (void *)&n);
|
||||
if (n > 0) {
|
||||
break;
|
||||
}
|
||||
|
@ -1535,7 +1535,7 @@ TEST(refreshGetMeta, normal2notexist) {
|
|||
|
||||
while (true) {
|
||||
uint64_t n = 0;
|
||||
ctgdGetStatNum("runtime.qDoneNum", (void *)&n);
|
||||
ctgdGetStatNum("runtime.numOfOpDequeue", (void *)&n);
|
||||
if (n > 0) {
|
||||
break;
|
||||
}
|
||||
|
@ -1609,7 +1609,7 @@ TEST(refreshGetMeta, normal2child) {
|
|||
|
||||
while (true) {
|
||||
uint64_t n = 0;
|
||||
ctgdGetStatNum("runtime.qDoneNum", (void *)&n);
|
||||
ctgdGetStatNum("runtime.numOfOpDequeue", (void *)&n);
|
||||
if (n > 0) {
|
||||
break;
|
||||
}
|
||||
|
@ -1693,7 +1693,7 @@ TEST(refreshGetMeta, stable2child) {
|
|||
|
||||
while (true) {
|
||||
uint64_t n = 0;
|
||||
ctgdGetStatNum("runtime.qDoneNum", (void *)&n);
|
||||
ctgdGetStatNum("runtime.numOfOpDequeue", (void *)&n);
|
||||
if (n > 0) {
|
||||
break;
|
||||
}
|
||||
|
@ -1778,7 +1778,7 @@ TEST(refreshGetMeta, stable2stable) {
|
|||
|
||||
while (true) {
|
||||
uint64_t n = 0;
|
||||
ctgdGetStatNum("runtime.qDoneNum", (void *)&n);
|
||||
ctgdGetStatNum("runtime.numOfOpDequeue", (void *)&n);
|
||||
if (n > 0) {
|
||||
break;
|
||||
}
|
||||
|
@ -1866,7 +1866,7 @@ TEST(refreshGetMeta, child2stable) {
|
|||
|
||||
while (true) {
|
||||
uint64_t n = 0;
|
||||
ctgdGetStatNum("runtime.qDoneNum", (void *)&n);
|
||||
ctgdGetStatNum("runtime.numOfOpDequeue", (void *)&n);
|
||||
if (n > 0) {
|
||||
break;
|
||||
}
|
||||
|
@ -2083,7 +2083,7 @@ TEST(dbVgroup, getSetDbVgroupCase) {
|
|||
|
||||
while (true) {
|
||||
uint64_t n = 0;
|
||||
ctgdGetStatNum("runtime.qDoneNum", (void *)&n);
|
||||
ctgdGetStatNum("runtime.numOfOpDequeue", (void *)&n);
|
||||
if (n > 0) {
|
||||
break;
|
||||
}
|
||||
|
@ -2109,7 +2109,7 @@ TEST(dbVgroup, getSetDbVgroupCase) {
|
|||
|
||||
while (true) {
|
||||
uint64_t n = 0;
|
||||
ctgdGetStatNum("runtime.qDoneNum", (void *)&n);
|
||||
ctgdGetStatNum("runtime.numOfOpDequeue", (void *)&n);
|
||||
if (n != 3) {
|
||||
taosMsleep(50);
|
||||
} else {
|
||||
|
|
|
@ -18,7 +18,31 @@
|
|||
#include "tdatablock.h"
|
||||
#include "tglobal.h"
|
||||
|
||||
extern SConfig *tsCfg;
|
||||
extern SConfig* tsCfg;
|
||||
|
||||
static int32_t buildRetrieveTableRsp(SSDataBlock* pBlock, int32_t numOfCols, SRetrieveTableRsp** pRsp) {
|
||||
size_t rspSize = sizeof(SRetrieveTableRsp) + blockGetEncodeSize(pBlock);
|
||||
*pRsp = taosMemoryCalloc(1, rspSize);
|
||||
if (NULL == *pRsp) {
|
||||
return TSDB_CODE_OUT_OF_MEMORY;
|
||||
}
|
||||
|
||||
(*pRsp)->useconds = 0;
|
||||
(*pRsp)->completed = 1;
|
||||
(*pRsp)->precision = 0;
|
||||
(*pRsp)->compressed = 0;
|
||||
(*pRsp)->compLen = 0;
|
||||
(*pRsp)->numOfRows = htonl(pBlock->info.rows);
|
||||
(*pRsp)->numOfCols = htonl(numOfCols);
|
||||
|
||||
int32_t len = 0;
|
||||
blockCompressEncode(pBlock, (*pRsp)->data, &len, numOfCols, false);
|
||||
ASSERT(len == rspSize - sizeof(SRetrieveTableRsp));
|
||||
|
||||
blockDataDestroy(pBlock);
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
static int32_t getSchemaBytes(const SSchema* pSchema) {
|
||||
switch (pSchema->type) {
|
||||
case TSDB_DATA_TYPE_BINARY:
|
||||
|
@ -89,31 +113,11 @@ static int32_t execDescribe(SNode* pStmt, SRetrieveTableRsp** pRsp) {
|
|||
SSDataBlock* pBlock = buildDescResultDataBlock();
|
||||
setDescResultIntoDataBlock(pBlock, numOfRows, pDesc->pMeta);
|
||||
|
||||
size_t rspSize = sizeof(SRetrieveTableRsp) + blockGetEncodeSize(pBlock);
|
||||
*pRsp = taosMemoryCalloc(1, rspSize);
|
||||
if (NULL == *pRsp) {
|
||||
return TSDB_CODE_OUT_OF_MEMORY;
|
||||
}
|
||||
|
||||
(*pRsp)->useconds = 0;
|
||||
(*pRsp)->completed = 1;
|
||||
(*pRsp)->precision = 0;
|
||||
(*pRsp)->compressed = 0;
|
||||
(*pRsp)->compLen = 0;
|
||||
(*pRsp)->numOfRows = htonl(numOfRows);
|
||||
(*pRsp)->numOfCols = htonl(DESCRIBE_RESULT_COLS);
|
||||
|
||||
int32_t len = 0;
|
||||
blockCompressEncode(pBlock, (*pRsp)->data, &len, DESCRIBE_RESULT_COLS, false);
|
||||
ASSERT(len == rspSize - sizeof(SRetrieveTableRsp));
|
||||
|
||||
blockDataDestroy(pBlock);
|
||||
return TSDB_CODE_SUCCESS;
|
||||
return buildRetrieveTableRsp(pBlock, DESCRIBE_RESULT_COLS, pRsp);
|
||||
}
|
||||
|
||||
static int32_t execResetQueryCache() { return catalogClearCache(); }
|
||||
|
||||
|
||||
static SSDataBlock* buildCreateDBResultDataBlock() {
|
||||
SSDataBlock* pBlock = createDataBlock();
|
||||
SColumnInfoData infoData = createColumnInfoData(TSDB_DATA_TYPE_VARCHAR, SHOW_CREATE_DB_RESULT_COLS, 1);
|
||||
|
@ -149,14 +153,14 @@ int64_t getValOfDiffPrecision(int8_t unit, int64_t val) {
|
|||
return v;
|
||||
}
|
||||
|
||||
char *buildRetension(SArray *pRetension) {
|
||||
char* buildRetension(SArray* pRetension) {
|
||||
size_t size = taosArrayGetSize(pRetension);
|
||||
if (size == 0) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
char *p1 = taosMemoryCalloc(1, 100);
|
||||
SRetention *p = taosArrayGet(pRetension, 0);
|
||||
char* p1 = taosMemoryCalloc(1, 100);
|
||||
SRetention* p = taosArrayGet(pRetension, 0);
|
||||
|
||||
int32_t len = 0;
|
||||
|
||||
|
@ -185,8 +189,7 @@ char *buildRetension(SArray *pRetension) {
|
|||
return p1;
|
||||
}
|
||||
|
||||
|
||||
static void setCreateDBResultIntoDataBlock(SSDataBlock* pBlock, char *dbFName, SDbCfgInfo* pCfg) {
|
||||
static void setCreateDBResultIntoDataBlock(SSDataBlock* pBlock, char* dbFName, SDbCfgInfo* pCfg) {
|
||||
blockDataEnsureCapacity(pBlock, 1);
|
||||
pBlock->info.rows = 1;
|
||||
|
||||
|
@ -198,7 +201,7 @@ static void setCreateDBResultIntoDataBlock(SSDataBlock* pBlock, char *dbFName, S
|
|||
SColumnInfoData* pCol2 = taosArrayGet(pBlock->pDataBlock, 1);
|
||||
char buf2[SHOW_CREATE_DB_RESULT_FIELD2_LEN] = {0};
|
||||
int32_t len = 0;
|
||||
char *prec = NULL;
|
||||
char* prec = NULL;
|
||||
switch (pCfg->precision) {
|
||||
case TSDB_TIME_PRECISION_MILLI:
|
||||
prec = TSDB_TIME_PRECISION_MILLI_STR;
|
||||
|
@ -214,14 +217,15 @@ static void setCreateDBResultIntoDataBlock(SSDataBlock* pBlock, char *dbFName, S
|
|||
break;
|
||||
}
|
||||
|
||||
char *retentions = buildRetension(pCfg->pRetensions);
|
||||
char* retentions = buildRetension(pCfg->pRetensions);
|
||||
|
||||
len += sprintf(buf2 + VARSTR_HEADER_SIZE, "CREATE DATABASE `%s` BUFFER %d CACHELAST %d COMP %d DURATION %dm "
|
||||
len += sprintf(buf2 + VARSTR_HEADER_SIZE,
|
||||
"CREATE DATABASE `%s` BUFFER %d CACHELAST %d COMP %d DURATION %dm "
|
||||
"FSYNC %d MAXROWS %d MINROWS %d KEEP %dm,%dm,%dm PAGES %d PAGESIZE %d PRECISION '%s' REPLICA %d "
|
||||
"STRICT %d WAL %d VGROUPS %d SINGLE_STABLE %d",
|
||||
dbFName, pCfg->buffer, pCfg->cacheLastRow, pCfg->compression, pCfg->daysPerFile,
|
||||
pCfg->fsyncPeriod, pCfg->maxRows, pCfg->minRows, pCfg->daysToKeep0, pCfg->daysToKeep1, pCfg->daysToKeep2,
|
||||
pCfg->pages, pCfg->pageSize, prec, pCfg->replications, pCfg->strict, pCfg->walLevel, pCfg->numOfVgroups,
|
||||
dbFName, pCfg->buffer, pCfg->cacheLastRow, pCfg->compression, pCfg->daysPerFile, pCfg->fsyncPeriod,
|
||||
pCfg->maxRows, pCfg->minRows, pCfg->daysToKeep0, pCfg->daysToKeep1, pCfg->daysToKeep2, pCfg->pages,
|
||||
pCfg->pageSize, prec, pCfg->replications, pCfg->strict, pCfg->walLevel, pCfg->numOfVgroups,
|
||||
1 == pCfg->numOfStables);
|
||||
|
||||
if (retentions) {
|
||||
|
@ -234,31 +238,10 @@ static void setCreateDBResultIntoDataBlock(SSDataBlock* pBlock, char *dbFName, S
|
|||
colDataAppend(pCol2, 0, buf2, false);
|
||||
}
|
||||
|
||||
|
||||
static int32_t execShowCreateDatabase(SShowCreateDatabaseStmt* pStmt, SRetrieveTableRsp** pRsp) {
|
||||
SSDataBlock* pBlock = buildCreateDBResultDataBlock();
|
||||
setCreateDBResultIntoDataBlock(pBlock, pStmt->dbName, pStmt->pCfg);
|
||||
|
||||
size_t rspSize = sizeof(SRetrieveTableRsp) + blockGetEncodeSize(pBlock);
|
||||
*pRsp = taosMemoryCalloc(1, rspSize);
|
||||
if (NULL == *pRsp) {
|
||||
return TSDB_CODE_OUT_OF_MEMORY;
|
||||
}
|
||||
|
||||
(*pRsp)->useconds = 0;
|
||||
(*pRsp)->completed = 1;
|
||||
(*pRsp)->precision = 0;
|
||||
(*pRsp)->compressed = 0;
|
||||
(*pRsp)->compLen = 0;
|
||||
(*pRsp)->numOfRows = htonl(1);
|
||||
(*pRsp)->numOfCols = htonl(SHOW_CREATE_DB_RESULT_COLS);
|
||||
|
||||
int32_t len = 0;
|
||||
blockCompressEncode(pBlock, (*pRsp)->data, &len, SHOW_CREATE_DB_RESULT_COLS, false);
|
||||
ASSERT(len == rspSize - sizeof(SRetrieveTableRsp));
|
||||
|
||||
blockDataDestroy(pBlock);
|
||||
return TSDB_CODE_SUCCESS;
|
||||
return buildRetrieveTableRsp(pBlock, SHOW_CREATE_DB_RESULT_COLS, pRsp);
|
||||
}
|
||||
|
||||
static SSDataBlock* buildCreateTbResultDataBlock() {
|
||||
|
@ -281,7 +264,7 @@ void appendColumnFields(char* buf, int32_t* len, STableCfg* pCfg) {
|
|||
if (TSDB_DATA_TYPE_VARCHAR == pSchema->type) {
|
||||
sprintf(type + strlen(type), "(%d)", (int32_t)(pSchema->bytes - VARSTR_HEADER_SIZE));
|
||||
} else if (TSDB_DATA_TYPE_NCHAR == pSchema->type) {
|
||||
sprintf(type + strlen(type), "(%d)", (int32_t)((pSchema->bytes - VARSTR_HEADER_SIZE)/TSDB_NCHAR_SIZE));
|
||||
sprintf(type + strlen(type), "(%d)", (int32_t)((pSchema->bytes - VARSTR_HEADER_SIZE) / TSDB_NCHAR_SIZE));
|
||||
}
|
||||
|
||||
*len += sprintf(buf + VARSTR_HEADER_SIZE + *len, "%s`%s` %s", ((i > 0) ? ", " : ""), pSchema->name, type);
|
||||
|
@ -296,14 +279,13 @@ void appendTagFields(char* buf, int32_t* len, STableCfg* pCfg) {
|
|||
if (TSDB_DATA_TYPE_VARCHAR == pSchema->type) {
|
||||
sprintf(type + strlen(type), "(%d)", (int32_t)(pSchema->bytes - VARSTR_HEADER_SIZE));
|
||||
} else if (TSDB_DATA_TYPE_NCHAR == pSchema->type) {
|
||||
sprintf(type + strlen(type), "(%d)", (int32_t)((pSchema->bytes - VARSTR_HEADER_SIZE)/TSDB_NCHAR_SIZE));
|
||||
sprintf(type + strlen(type), "(%d)", (int32_t)((pSchema->bytes - VARSTR_HEADER_SIZE) / TSDB_NCHAR_SIZE));
|
||||
}
|
||||
|
||||
*len += sprintf(buf + VARSTR_HEADER_SIZE + *len, "%s`%s` %s", ((i > 0) ? ", " : ""), pSchema->name, type);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void appendTagNameFields(char* buf, int32_t* len, STableCfg* pCfg) {
|
||||
for (int32_t i = 0; i < pCfg->numOfTags; ++i) {
|
||||
SSchema* pSchema = pCfg->pSchemas + pCfg->numOfColumns + i;
|
||||
|
@ -311,13 +293,12 @@ void appendTagNameFields(char* buf, int32_t* len, STableCfg* pCfg) {
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
int32_t appendTagValues(char* buf, int32_t* len, STableCfg* pCfg) {
|
||||
SArray *pTagVals = NULL;
|
||||
STag *pTag = (STag*)pCfg->pTags;
|
||||
SArray* pTagVals = NULL;
|
||||
STag* pTag = (STag*)pCfg->pTags;
|
||||
|
||||
if (pCfg->pTags && pTag->flags & TD_TAG_JSON) {
|
||||
char *pJson = parseTagDatatoJson(pTag);
|
||||
char* pJson = parseTagDatatoJson(pTag);
|
||||
if (pJson) {
|
||||
*len += sprintf(buf + VARSTR_HEADER_SIZE + *len, "%s", pJson);
|
||||
taosMemoryFree(pJson);
|
||||
|
@ -326,7 +307,7 @@ int32_t appendTagValues(char* buf, int32_t* len, STableCfg* pCfg) {
|
|||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
int32_t code = tTagToValArray((const STag *)pCfg->pTags, &pTagVals);
|
||||
int32_t code = tTagToValArray((const STag*)pCfg->pTags, &pTagVals);
|
||||
if (code) {
|
||||
return code;
|
||||
}
|
||||
|
@ -345,7 +326,7 @@ int32_t appendTagValues(char* buf, int32_t* len, STableCfg* pCfg) {
|
|||
continue;
|
||||
}
|
||||
|
||||
STagVal *pTagVal = (STagVal *)taosArrayGet(pTagVals, j);
|
||||
STagVal* pTagVal = (STagVal*)taosArrayGet(pTagVals, j);
|
||||
if (pSchema->colId > pTagVal->cid) {
|
||||
qError("tag value and column mismatch, schemaId:%d, valId:%d", pSchema->colId, pTagVal->cid);
|
||||
taosArrayDestroy(pTagVals);
|
||||
|
@ -365,7 +346,6 @@ int32_t appendTagValues(char* buf, int32_t* len, STableCfg* pCfg) {
|
|||
*len += sprintf(buf + VARSTR_HEADER_SIZE + *len, "NULL");
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
if (type == TSDB_DATA_TYPE_BINARY) {
|
||||
if (pTagVal->nData > 0) {
|
||||
|
@ -436,7 +416,7 @@ void appendTableOptions(char* buf, int32_t* len, STableCfg* pCfg) {
|
|||
}
|
||||
}
|
||||
|
||||
static int32_t setCreateTBResultIntoDataBlock(SSDataBlock* pBlock, char *tbName, STableCfg* pCfg) {
|
||||
static int32_t setCreateTBResultIntoDataBlock(SSDataBlock* pBlock, char* tbName, STableCfg* pCfg) {
|
||||
int32_t code = 0;
|
||||
blockDataEnsureCapacity(pBlock, 1);
|
||||
pBlock->info.rows = 1;
|
||||
|
@ -480,34 +460,13 @@ static int32_t setCreateTBResultIntoDataBlock(SSDataBlock* pBlock, char *tbName,
|
|||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
static int32_t execShowCreateTable(SShowCreateTableStmt* pStmt, SRetrieveTableRsp** pRsp) {
|
||||
SSDataBlock* pBlock = buildCreateTbResultDataBlock();
|
||||
int32_t code = setCreateTBResultIntoDataBlock(pBlock, pStmt->tableName, pStmt->pCfg);
|
||||
if (code) {
|
||||
return code;
|
||||
}
|
||||
|
||||
size_t rspSize = sizeof(SRetrieveTableRsp) + blockGetEncodeSize(pBlock);
|
||||
*pRsp = taosMemoryCalloc(1, rspSize);
|
||||
if (NULL == *pRsp) {
|
||||
return TSDB_CODE_OUT_OF_MEMORY;
|
||||
}
|
||||
|
||||
(*pRsp)->useconds = 0;
|
||||
(*pRsp)->completed = 1;
|
||||
(*pRsp)->precision = 0;
|
||||
(*pRsp)->compressed = 0;
|
||||
(*pRsp)->compLen = 0;
|
||||
(*pRsp)->numOfRows = htonl(1);
|
||||
(*pRsp)->numOfCols = htonl(SHOW_CREATE_TB_RESULT_COLS);
|
||||
|
||||
int32_t len = 0;
|
||||
blockCompressEncode(pBlock, (*pRsp)->data, &len, SHOW_CREATE_TB_RESULT_COLS, false);
|
||||
ASSERT(len == rspSize - sizeof(SRetrieveTableRsp));
|
||||
|
||||
blockDataDestroy(pBlock);
|
||||
return TSDB_CODE_SUCCESS;
|
||||
return buildRetrieveTableRsp(pBlock, SHOW_CREATE_TB_RESULT_COLS, pRsp);
|
||||
}
|
||||
|
||||
static int32_t execShowCreateSTable(SShowCreateTableStmt* pStmt, SRetrieveTableRsp** pRsp) {
|
||||
|
@ -551,18 +510,17 @@ static SSDataBlock* buildLocalVariablesResultDataBlock() {
|
|||
return pBlock;
|
||||
}
|
||||
|
||||
|
||||
int32_t setLocalVariablesResultIntoDataBlock(SSDataBlock* pBlock) {
|
||||
int32_t numOfCfg = taosArrayGetSize(tsCfg->array);
|
||||
int32_t numOfRows = 0;
|
||||
blockDataEnsureCapacity(pBlock, numOfCfg);
|
||||
|
||||
for (int32_t i = 0, c = 0; i < numOfCfg; ++i, c = 0) {
|
||||
SConfigItem *pItem = taosArrayGet(tsCfg->array, i);
|
||||
SConfigItem* pItem = taosArrayGet(tsCfg->array, i);
|
||||
|
||||
char name[TSDB_CONFIG_OPTION_LEN + VARSTR_HEADER_SIZE] = {0};
|
||||
STR_WITH_MAXSIZE_TO_VARSTR(name, pItem->name, TSDB_CONFIG_OPTION_LEN + VARSTR_HEADER_SIZE);
|
||||
SColumnInfoData *pColInfo = taosArrayGet(pBlock->pDataBlock, c++);
|
||||
SColumnInfoData* pColInfo = taosArrayGet(pBlock->pDataBlock, c++);
|
||||
colDataAppend(pColInfo, i, name, false);
|
||||
|
||||
char value[TSDB_CONFIG_VALUE_LEN + VARSTR_HEADER_SIZE] = {0};
|
||||
|
@ -575,42 +533,70 @@ int32_t setLocalVariablesResultIntoDataBlock(SSDataBlock* pBlock) {
|
|||
numOfRows++;
|
||||
}
|
||||
|
||||
|
||||
pBlock->info.rows = numOfRows;
|
||||
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
static int32_t execShowLocalVariables(SRetrieveTableRsp** pRsp) {
|
||||
SSDataBlock* pBlock = buildLocalVariablesResultDataBlock();
|
||||
int32_t code = setLocalVariablesResultIntoDataBlock(pBlock);
|
||||
if (code) {
|
||||
return code;
|
||||
}
|
||||
return buildRetrieveTableRsp(pBlock, SHOW_LOCAL_VARIABLES_RESULT_COLS, pRsp);
|
||||
}
|
||||
|
||||
size_t rspSize = sizeof(SRetrieveTableRsp) + blockGetEncodeSize(pBlock);
|
||||
*pRsp = taosMemoryCalloc(1, rspSize);
|
||||
if (NULL == *pRsp) {
|
||||
static int32_t createSelectResultDataBlock(SNodeList* pProjects, SSDataBlock** pOutput) {
|
||||
SSDataBlock* pBlock = taosMemoryCalloc(1, sizeof(SSDataBlock));
|
||||
if (NULL == pBlock) {
|
||||
return TSDB_CODE_OUT_OF_MEMORY;
|
||||
}
|
||||
|
||||
(*pRsp)->useconds = 0;
|
||||
(*pRsp)->completed = 1;
|
||||
(*pRsp)->precision = 0;
|
||||
(*pRsp)->compressed = 0;
|
||||
(*pRsp)->compLen = 0;
|
||||
(*pRsp)->numOfRows = htonl(pBlock->info.rows);
|
||||
(*pRsp)->numOfCols = htonl(SHOW_LOCAL_VARIABLES_RESULT_COLS);
|
||||
pBlock->pDataBlock = taosArrayInit(LIST_LENGTH(pProjects), sizeof(SColumnInfoData));
|
||||
|
||||
int32_t len = 0;
|
||||
blockCompressEncode(pBlock, (*pRsp)->data, &len, SHOW_LOCAL_VARIABLES_RESULT_COLS, false);
|
||||
ASSERT(len == rspSize - sizeof(SRetrieveTableRsp));
|
||||
|
||||
blockDataDestroy(pBlock);
|
||||
SNode* pProj = NULL;
|
||||
FOREACH(pProj, pProjects) {
|
||||
SColumnInfoData infoData = {0};
|
||||
infoData.info.type = ((SExprNode*)pProj)->resType.type;
|
||||
infoData.info.bytes = ((SExprNode*)pProj)->resType.bytes;
|
||||
taosArrayPush(pBlock->pDataBlock, &infoData);
|
||||
}
|
||||
*pOutput = pBlock;
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
int32_t buildSelectResultDataBlock(SNodeList* pProjects, SSDataBlock* pBlock) {
|
||||
int32_t numOfCols = LIST_LENGTH(pProjects);
|
||||
blockDataEnsureCapacity(pBlock, 1);
|
||||
|
||||
int32_t index = 0;
|
||||
SNode* pProj = NULL;
|
||||
FOREACH(pProj, pProjects) {
|
||||
if (((SValueNode*)pProj)->isNull) {
|
||||
colDataAppend(taosArrayGet(pBlock->pDataBlock, index++), 0, NULL, true);
|
||||
} else {
|
||||
colDataAppend(taosArrayGet(pBlock->pDataBlock, index++), 0, nodesGetValueFromNode((SValueNode*)pProj), false);
|
||||
}
|
||||
}
|
||||
|
||||
pBlock->info.rows = 1;
|
||||
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
static int32_t execSelectWithoutFrom(SSelectStmt* pSelect, SRetrieveTableRsp** pRsp) {
|
||||
SSDataBlock* pBlock = NULL;
|
||||
int32_t code = createSelectResultDataBlock(pSelect->pProjectionList, &pBlock);
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
code = buildSelectResultDataBlock(pSelect->pProjectionList, pBlock);
|
||||
}
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
code = buildRetrieveTableRsp(pBlock, LIST_LENGTH(pSelect->pProjectionList), pRsp);
|
||||
}
|
||||
return code;
|
||||
}
|
||||
|
||||
int32_t qExecCommand(SNode* pStmt, SRetrieveTableRsp** pRsp) {
|
||||
switch (nodeType(pStmt)) {
|
||||
case QUERY_NODE_DESCRIBE_STMT:
|
||||
|
@ -627,6 +613,8 @@ int32_t qExecCommand(SNode* pStmt, SRetrieveTableRsp** pRsp) {
|
|||
return execAlterLocal((SAlterLocalStmt*)pStmt);
|
||||
case QUERY_NODE_SHOW_LOCAL_VARIABLES_STMT:
|
||||
return execShowLocalVariables(pRsp);
|
||||
case QUERY_NODE_SELECT_STMT:
|
||||
return execSelectWithoutFrom((SSelectStmt*)pStmt, pRsp);
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
|
|
@ -253,18 +253,15 @@ typedef struct STableScanInfo {
|
|||
SReadHandle readHandle;
|
||||
|
||||
SFileBlockLoadRecorder readRecorder;
|
||||
int64_t numOfRows;
|
||||
SScanInfo scanInfo;
|
||||
int32_t scanTimes;
|
||||
SNode* pFilterNode; // filter info, which is push down by optimizer
|
||||
SqlFunctionCtx* pCtx; // which belongs to the direct upstream operator operator query context
|
||||
SResultRowInfo* pResultRowInfo;
|
||||
int32_t* rowEntryInfoOffset;
|
||||
SExprInfo* pExpr;
|
||||
SqlFunctionCtx* pCtx; // which belongs to the direct upstream operator operator query context,todo: remove this by using SExprSup
|
||||
int32_t* rowEntryInfoOffset; // todo: remove this by using SExprSup
|
||||
SExprInfo* pExpr;// todo: remove this by using SExprSup
|
||||
|
||||
SSDataBlock* pResBlock;
|
||||
SArray* pColMatchInfo;
|
||||
int32_t numOfOutput;
|
||||
|
||||
SExprSupp pseudoSup;
|
||||
SQueryTableDataCond cond;
|
||||
int32_t scanFlag; // table scan flag to denote if it is a repeat/reverse/main scan
|
||||
|
@ -275,8 +272,13 @@ typedef struct STableScanInfo {
|
|||
int32_t curTWinIdx;
|
||||
|
||||
int32_t currentGroupId;
|
||||
uint64_t queryId;
|
||||
uint64_t taskId;
|
||||
uint64_t queryId; // todo remove it
|
||||
uint64_t taskId; // todo remove it
|
||||
|
||||
struct {
|
||||
uint64_t uid;
|
||||
int64_t t;
|
||||
} scanStatus;
|
||||
} STableScanInfo;
|
||||
|
||||
typedef struct STagScanInfo {
|
||||
|
@ -321,31 +323,31 @@ typedef struct SessionWindowSupporter {
|
|||
} SessionWindowSupporter;
|
||||
|
||||
typedef struct SStreamBlockScanInfo {
|
||||
uint64_t tableUid; // queried super table uid
|
||||
SExprInfo* pPseudoExpr;
|
||||
int32_t numOfPseudoExpr;
|
||||
int32_t primaryTsIndex; // primary time stamp slot id
|
||||
SReadHandle readHandle;
|
||||
SInterval interval; // if the upstream is an interval operator, the interval info is also kept here.
|
||||
SArray* pColMatchInfo; //
|
||||
SNode* pCondition;
|
||||
|
||||
SArray* pBlockLists; // multiple SSDatablock.
|
||||
SSDataBlock* pRes; // result SSDataBlock
|
||||
SSDataBlock* pUpdateRes; // update SSDataBlock
|
||||
int32_t updateResIndex;
|
||||
int32_t blockType; // current block type
|
||||
int32_t validBlockIndex; // Is current data has returned?
|
||||
SColumnInfo* pCols; // the output column info
|
||||
uint64_t numOfExec; // execution times
|
||||
void* streamBlockReader;// stream block reader handle
|
||||
SArray* pColMatchInfo; //
|
||||
SNode* pCondition;
|
||||
|
||||
int32_t tsArrayIndex;
|
||||
SArray* tsArray;
|
||||
uint64_t groupId;
|
||||
SUpdateInfo* pUpdateInfo;
|
||||
|
||||
SExprInfo* pPseudoExpr;
|
||||
int32_t numOfPseudoExpr;
|
||||
|
||||
int32_t primaryTsIndex; // primary time stamp slot id
|
||||
SReadHandle readHandle;
|
||||
uint64_t tableUid; // queried super table uid
|
||||
EStreamScanMode scanMode;
|
||||
SOperatorInfo* pSnapshotReadOp;
|
||||
SInterval interval; // if the upstream is an interval operator, the interval info is also kept here.
|
||||
SArray* childIds;
|
||||
SessionWindowSupporter sessionSup;
|
||||
bool assignBlockUid; // assign block uid to groupId, temporarily used for generating rollup SMA.
|
||||
|
@ -416,6 +418,7 @@ typedef struct SIntervalAggOperatorInfo {
|
|||
STimeWindowAggSupp twAggSup;
|
||||
bool invertible;
|
||||
SArray* pPrevValues; // SArray<SGroupKeys> used to keep the previous not null value for interpolation.
|
||||
bool ignoreCloseWindow;
|
||||
} SIntervalAggOperatorInfo;
|
||||
|
||||
typedef struct SStreamFinalIntervalOperatorInfo {
|
||||
|
@ -437,6 +440,7 @@ typedef struct SStreamFinalIntervalOperatorInfo {
|
|||
SArray* pPullWins; // SPullWindowInfo
|
||||
int32_t pullIndex;
|
||||
SSDataBlock* pPullDataRes;
|
||||
bool ignoreCloseWindow;
|
||||
} SStreamFinalIntervalOperatorInfo;
|
||||
|
||||
typedef struct SAggOperatorInfo {
|
||||
|
@ -574,6 +578,7 @@ typedef struct SStreamSessionAggOperatorInfo {
|
|||
SArray* pChildren; // cache for children's result; final stream operator
|
||||
SPhysiNode* pPhyNode; // create new child
|
||||
bool isFinal;
|
||||
bool ignoreCloseWindow;
|
||||
} SStreamSessionAggOperatorInfo;
|
||||
|
||||
typedef struct STimeSliceOperatorInfo {
|
||||
|
@ -617,6 +622,7 @@ typedef struct SStreamStateAggOperatorInfo {
|
|||
void* pDelIterator;
|
||||
SArray* pScanWindow;
|
||||
SArray* pChildren; // cache for children's result;
|
||||
bool ignoreCloseWindow;
|
||||
} SStreamStateAggOperatorInfo;
|
||||
|
||||
typedef struct SSortedMergeOperatorInfo {
|
||||
|
@ -683,7 +689,7 @@ int32_t appendDownstream(SOperatorInfo* p, SOperatorInfo** pDownstream, int32_t
|
|||
void initBasicInfo(SOptrBasicInfo* pInfo, SSDataBlock* pBlock);
|
||||
void cleanupBasicInfo(SOptrBasicInfo* pInfo);
|
||||
int32_t initExprSupp(SExprSupp* pSup, SExprInfo* pExprInfo, int32_t numOfExpr);
|
||||
void cleanupExprSup(SExprSupp* pSup);
|
||||
void cleanupExprSupp(SExprSupp* pSup);
|
||||
int32_t initAggInfo(SExprSupp *pSup, SAggSupporter* pAggSup, SExprInfo* pExprInfo, int32_t numOfCols, size_t keyBufSize,
|
||||
const char* pkey);
|
||||
void initResultSizeInfo(SOperatorInfo* pOperator, int32_t numOfRows);
|
||||
|
@ -707,7 +713,7 @@ void destroyBasicOperatorInfo(void* param, int32_t numOfOutput);
|
|||
void appendOneRowToDataBlock(SSDataBlock* pBlock, STupleHandle* pTupleHandle);
|
||||
void setTbNameColData(void* pMeta, const SSDataBlock* pBlock, SColumnInfoData* pColInfoData, int32_t functionId);
|
||||
|
||||
void cleanupExecSupp(SExprSupp* pSupp);
|
||||
int32_t doGetScanStatus(SOperatorInfo* pOperator, uint64_t* uid, int64_t* ts);
|
||||
|
||||
SSDataBlock* loadNextDataBlock(void* param);
|
||||
|
||||
|
|
|
@ -191,16 +191,6 @@ int32_t qAsyncKillTask(qTaskInfo_t qinfo) {
|
|||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
int32_t qIsTaskCompleted(qTaskInfo_t qinfo) {
|
||||
SExecTaskInfo* pTaskInfo = (SExecTaskInfo*)qinfo;
|
||||
|
||||
if (pTaskInfo == NULL) {
|
||||
return TSDB_CODE_QRY_INVALID_QHANDLE;
|
||||
}
|
||||
|
||||
return isTaskKilled(pTaskInfo);
|
||||
}
|
||||
|
||||
void qDestroyTask(qTaskInfo_t qTaskHandle) {
|
||||
SExecTaskInfo* pTaskInfo = (SExecTaskInfo*)qTaskHandle;
|
||||
qDebug("%s execTask completed, numOfRows:%" PRId64, GET_TASKID(pTaskInfo), pTaskInfo->pRoot->resultInfo.totalRows);
|
||||
|
@ -242,3 +232,10 @@ int32_t qDeserializeTaskStatus(qTaskInfo_t tinfo, const char* pInput, int32_t le
|
|||
}
|
||||
|
||||
|
||||
int32_t qGetStreamScanStatus(qTaskInfo_t tinfo, uint64_t* uid, int64_t* ts) {
|
||||
SExecTaskInfo* pTaskInfo = (SExecTaskInfo*) tinfo;
|
||||
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -1033,7 +1033,7 @@ static uint32_t doFilterByBlockTimeWindow(STableScanInfo* pTableScanInfo, SSData
|
|||
SqlFunctionCtx* pCtx = pTableScanInfo->pCtx;
|
||||
uint32_t status = BLK_DATA_NOT_LOAD;
|
||||
|
||||
int32_t numOfOutput = pTableScanInfo->numOfOutput;
|
||||
int32_t numOfOutput = 0;//pTableScanInfo->numOfOutput;
|
||||
for (int32_t i = 0; i < numOfOutput; ++i) {
|
||||
int32_t functionId = pCtx[i].functionId;
|
||||
int32_t colId = pTableScanInfo->pExpr[i].base.pParam[0].pCol->colId;
|
||||
|
@ -2821,6 +2821,24 @@ int32_t getTableScanInfo(SOperatorInfo* pOperator, int32_t* order, int32_t* scan
|
|||
}
|
||||
}
|
||||
|
||||
int32_t doGetScanStatus(SOperatorInfo* pOperator, uint64_t* uid, int64_t* ts) {
|
||||
int32_t type = pOperator->operatorType;
|
||||
if (type == QUERY_NODE_PHYSICAL_PLAN_STREAM_SCAN) {
|
||||
SStreamBlockScanInfo* pScanInfo = pOperator->info;
|
||||
STableScanInfo* pSnapShotScanInfo = pScanInfo->pSnapshotReadOp->info;
|
||||
*uid = pSnapShotScanInfo->scanStatus.uid;
|
||||
*ts = pSnapShotScanInfo->scanStatus.t;
|
||||
} else {
|
||||
if (pOperator->pDownstream[0] == NULL) {
|
||||
return TSDB_CODE_INVALID_PARA;
|
||||
} else {
|
||||
doGetScanStatus(pOperator->pDownstream[0], uid, ts);
|
||||
}
|
||||
}
|
||||
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
// this is a blocking operator
|
||||
static int32_t doOpenAggregateOptr(SOperatorInfo* pOperator) {
|
||||
if (OPTR_IS_OPENED(pOperator)) {
|
||||
|
@ -3543,7 +3561,7 @@ static void destroyProjectOperatorInfo(void* param, int32_t numOfOutput) {
|
|||
taosArrayDestroy(pInfo->pPseudoColInfo);
|
||||
}
|
||||
|
||||
void cleanupExecSupp(SExprSupp* pSupp) {
|
||||
void cleanupExprSupp(SExprSupp* pSupp) {
|
||||
destroySqlFunctionCtx(pSupp->pCtx, pSupp->numOfExprs);
|
||||
destroyExprInfo(pSupp->pExprInfo, pSupp->numOfExprs);
|
||||
|
||||
|
@ -3556,7 +3574,7 @@ static void destroyIndefinitOperatorInfo(void* param, int32_t numOfOutput) {
|
|||
|
||||
taosArrayDestroy(pInfo->pPseudoColInfo);
|
||||
cleanupAggSup(&pInfo->aggSup);
|
||||
cleanupExecSupp(&pInfo->scalarSup);
|
||||
cleanupExprSupp(&pInfo->scalarSup);
|
||||
}
|
||||
|
||||
void destroyExchangeOperatorInfo(void* param, int32_t numOfOutput) {
|
||||
|
|
|
@ -37,7 +37,7 @@ static void destroyGroupOperatorInfo(void* param, int32_t numOfOutput) {
|
|||
taosMemoryFreeClear(pInfo->keyBuf);
|
||||
taosArrayDestroy(pInfo->pGroupCols);
|
||||
taosArrayDestroy(pInfo->pGroupColVals);
|
||||
cleanupExecSupp(&pInfo->scalarSup);
|
||||
cleanupExprSupp(&pInfo->scalarSup);
|
||||
}
|
||||
|
||||
static int32_t initGroupOptrInfo(SArray** pGroupColVals, int32_t* keyLen, char** keyBuf, const SArray* pGroupColList) {
|
||||
|
@ -701,7 +701,7 @@ static void destroyPartitionOperatorInfo(void* param, int32_t numOfOutput) {
|
|||
taosHashCleanup(pInfo->pGroupSet);
|
||||
taosMemoryFree(pInfo->columnOffset);
|
||||
|
||||
cleanupExecSupp(&pInfo->scalarSup);
|
||||
cleanupExprSupp(&pInfo->scalarSup);
|
||||
}
|
||||
|
||||
SOperatorInfo* createPartitionOperatorInfo(SOperatorInfo* downstream, SPartitionPhysiNode* pPartNode, SExecTaskInfo* pTaskInfo) {
|
||||
|
|
|
@ -13,6 +13,7 @@
|
|||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <executorimpl.h>
|
||||
#include <vnode.h>
|
||||
#include "filter.h"
|
||||
#include "function.h"
|
||||
|
@ -413,6 +414,11 @@ static SSDataBlock* doTableScanImpl(SOperatorInfo* pOperator) {
|
|||
pTableScanInfo->readRecorder.elapsedTime += (taosGetTimestampUs() - st) / 1000.0;
|
||||
|
||||
pOperator->cost.totalCost = pTableScanInfo->readRecorder.elapsedTime;
|
||||
|
||||
// todo refactor
|
||||
pTableScanInfo->scanStatus.uid = pBlock->info.uid;
|
||||
pTableScanInfo->scanStatus.t = pBlock->info.window.ekey;
|
||||
|
||||
return pBlock;
|
||||
}
|
||||
return NULL;
|
||||
|
@ -459,7 +465,7 @@ static SSDataBlock* doTableScanGroup(SOperatorInfo* pOperator) {
|
|||
int32_t total = pTableScanInfo->scanInfo.numOfAsc + pTableScanInfo->scanInfo.numOfDesc;
|
||||
if (pTableScanInfo->scanTimes < total) {
|
||||
if (pTableScanInfo->cond.order == TSDB_ORDER_ASC) {
|
||||
prepareForDescendingScan(pTableScanInfo, pTableScanInfo->pCtx, pTableScanInfo->numOfOutput);
|
||||
prepareForDescendingScan(pTableScanInfo, pTableScanInfo->pCtx, 0);
|
||||
tsdbResetReadHandle(pTableScanInfo->dataReader, &pTableScanInfo->cond, 0);
|
||||
pTableScanInfo->curTWinIdx = 0;
|
||||
}
|
||||
|
|
|
@ -813,6 +813,16 @@ static void removeResults(SArray* pWins, SArray* pUpdated) {
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
bool isOverdue(TSKEY ts, STimeWindowAggSupp* pSup) {
|
||||
ASSERT(pSup->maxTs == INT64_MIN || pSup->maxTs > 0);
|
||||
return pSup->maxTs != INT64_MIN && ts < pSup->maxTs - pSup->waterMark;
|
||||
}
|
||||
|
||||
bool isCloseWindow(STimeWindow* pWin, STimeWindowAggSupp* pSup) {
|
||||
return isOverdue(pWin->ekey, pSup);
|
||||
}
|
||||
|
||||
static void hashIntervalAgg(SOperatorInfo* pOperatorInfo, SResultRowInfo* pResultRowInfo, SSDataBlock* pBlock,
|
||||
int32_t scanFlag, SArray* pUpdated) {
|
||||
SIntervalAggOperatorInfo* pInfo = (SIntervalAggOperatorInfo*)pOperatorInfo->info;
|
||||
|
@ -830,15 +840,16 @@ static void hashIntervalAgg(SOperatorInfo* pOperatorInfo, SResultRowInfo* pResul
|
|||
|
||||
STimeWindow win = getActiveTimeWindow(pInfo->aggSup.pResultBuf, pResultRowInfo, ts, &pInfo->interval,
|
||||
pInfo->interval.precision, &pInfo->win);
|
||||
|
||||
int32_t ret = setTimeWindowOutputBuf(pResultRowInfo, &win, (scanFlag == MAIN_SCAN), &pResult, tableGroupId,
|
||||
int32_t ret = TSDB_CODE_SUCCESS;
|
||||
if (!pInfo->ignoreCloseWindow || !isCloseWindow(&win, &pInfo->twAggSup)) {
|
||||
ret = setTimeWindowOutputBuf(pResultRowInfo, &win, (scanFlag == MAIN_SCAN), &pResult, tableGroupId,
|
||||
pSup->pCtx, numOfOutput, pSup->rowEntryInfoOffset, &pInfo->aggSup, pTaskInfo);
|
||||
if (ret != TSDB_CODE_SUCCESS || pResult == NULL) {
|
||||
longjmp(pTaskInfo->env, TSDB_CODE_QRY_OUT_OF_MEMORY);
|
||||
}
|
||||
|
||||
if (pInfo->execModel == OPTR_EXEC_MODEL_STREAM) {
|
||||
if (pInfo->twAggSup.calTrigger == STREAM_TRIGGER_AT_ONCE) {
|
||||
if (pInfo->execModel == OPTR_EXEC_MODEL_STREAM &&
|
||||
pInfo->twAggSup.calTrigger == STREAM_TRIGGER_AT_ONCE) {
|
||||
saveResultRow(pResult, tableGroupId, pUpdated);
|
||||
}
|
||||
}
|
||||
|
@ -864,9 +875,11 @@ static void hashIntervalAgg(SOperatorInfo* pOperatorInfo, SResultRowInfo* pResul
|
|||
doWindowBorderInterpolation(pInfo, pBlock, pResult, &win, startPos, forwardRows, pSup);
|
||||
}
|
||||
|
||||
if (!pInfo->ignoreCloseWindow || !isCloseWindow(&win, &pInfo->twAggSup)) {
|
||||
updateTimeWindowInfo(&pInfo->twAggSup.timeWindowData, &win, true);
|
||||
doApplyFunctions(pTaskInfo, pSup->pCtx, &win, &pInfo->twAggSup.timeWindowData, startPos, forwardRows, tsCols,
|
||||
pBlock->info.rows, numOfOutput, pInfo->order);
|
||||
}
|
||||
|
||||
doCloseWindow(pResultRowInfo, pInfo, pResult);
|
||||
|
||||
|
@ -877,6 +890,12 @@ static void hashIntervalAgg(SOperatorInfo* pOperatorInfo, SResultRowInfo* pResul
|
|||
if (startPos < 0) {
|
||||
break;
|
||||
}
|
||||
if (pInfo->ignoreCloseWindow && isCloseWindow(&nextWin, &pInfo->twAggSup)) {
|
||||
ekey = ascScan ? nextWin.ekey : nextWin.skey;
|
||||
forwardRows =
|
||||
getNumOfRowsInTimeWindow(&pBlock->info, tsCols, startPos, ekey, binarySearchForKey, NULL, pInfo->order);
|
||||
continue;
|
||||
}
|
||||
|
||||
// null data, failed to allocate more memory buffer
|
||||
int32_t code = setTimeWindowOutputBuf(pResultRowInfo, &nextWin, (scanFlag == MAIN_SCAN), &pResult, tableGroupId,
|
||||
|
@ -885,11 +904,10 @@ static void hashIntervalAgg(SOperatorInfo* pOperatorInfo, SResultRowInfo* pResul
|
|||
longjmp(pTaskInfo->env, TSDB_CODE_QRY_OUT_OF_MEMORY);
|
||||
}
|
||||
|
||||
if (pInfo->execModel == OPTR_EXEC_MODEL_STREAM) {
|
||||
if (pInfo->twAggSup.calTrigger == STREAM_TRIGGER_AT_ONCE) {
|
||||
if (pInfo->execModel == OPTR_EXEC_MODEL_STREAM &&
|
||||
pInfo->twAggSup.calTrigger == STREAM_TRIGGER_AT_ONCE) {
|
||||
saveResultRow(pResult, tableGroupId, pUpdated);
|
||||
}
|
||||
}
|
||||
|
||||
ekey = ascScan ? nextWin.ekey : nextWin.skey;
|
||||
forwardRows =
|
||||
|
@ -1292,11 +1310,6 @@ static int32_t getAllIntervalWindow(SHashObj* pHashMap, SArray* resWins) {
|
|||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
bool isCloseWindow(STimeWindow* pWin, STimeWindowAggSupp* pSup) {
|
||||
ASSERT(pSup->maxTs == INT64_MIN || pSup->maxTs > 0);
|
||||
return pSup->maxTs != INT64_MIN && pWin->ekey < pSup->maxTs - pSup->waterMark;
|
||||
}
|
||||
|
||||
static int32_t closeIntervalWindow(SHashObj* pHashMap, STimeWindowAggSupp* pSup,
|
||||
SInterval* pInterval, SHashObj* pPullDataMap, SArray* closeWins) {
|
||||
void* pIte = NULL;
|
||||
|
@ -1411,7 +1424,7 @@ static SSDataBlock* doStreamIntervalAgg(SOperatorInfo* pOperator) {
|
|||
doBuildResultDatablock(pOperator, &pInfo->binfo, &pInfo->groupResInfo, pInfo->aggSup.pResultBuf);
|
||||
|
||||
pOperator->status = OP_RES_TO_RETURN;
|
||||
|
||||
printDataBlock(pInfo->binfo.pRes, "single interval");
|
||||
return pInfo->binfo.pRes->info.rows == 0 ? NULL : pInfo->binfo.pRes;
|
||||
}
|
||||
|
||||
|
@ -1521,6 +1534,7 @@ SOperatorInfo* createIntervalOperatorInfo(SOperatorInfo* downstream, SExprInfo*
|
|||
pInfo->interval = *pInterval;
|
||||
pInfo->execModel = pTaskInfo->execModel;
|
||||
pInfo->twAggSup = *pTwAggSupp;
|
||||
pInfo->ignoreCloseWindow = false;
|
||||
|
||||
if (pPhyNode->window.pExprs != NULL) {
|
||||
int32_t numOfScalar = 0;
|
||||
|
@ -2276,7 +2290,15 @@ static void doHashInterval(SOperatorInfo* pOperatorInfo, SSDataBlock* pSDataBloc
|
|||
STimeWindow nextWin = getActiveTimeWindow(pInfo->aggSup.pResultBuf, pResultRowInfo, ts, &pInfo->interval,
|
||||
pInfo->interval.precision, NULL);
|
||||
while (1) {
|
||||
if (IS_FINAL_OP(pInfo) && isCloseWindow(&nextWin, &pInfo->twAggSup) && pInfo->pChildren) {
|
||||
bool isClosed = isCloseWindow(&nextWin, &pInfo->twAggSup);
|
||||
if (pInfo->ignoreCloseWindow && isClosed) {
|
||||
startPos = getNexWindowPos(&pInfo->interval, &pSDataBlock->info, tsCols, startPos, nextWin.ekey, &nextWin);
|
||||
if (startPos < 0) {
|
||||
break;
|
||||
}
|
||||
continue;
|
||||
}
|
||||
if (IS_FINAL_OP(pInfo) && isClosed && pInfo->pChildren) {
|
||||
bool ignore = true;
|
||||
SWinRes winRes = {.ts = nextWin.skey, .groupId = tableGroupId,};
|
||||
void* chIds = taosHashGet(pInfo->pPullDataMap, &winRes, sizeof(SWinRes));
|
||||
|
@ -2684,6 +2706,7 @@ SOperatorInfo* createStreamFinalIntervalOperatorInfo(SOperatorInfo* downstream,
|
|||
_hash_fn_t hashFn = taosGetDefaultHashFunction(TSDB_DATA_TYPE_BINARY);
|
||||
pInfo->pPullDataMap = taosHashInit(64, hashFn, false, HASH_NO_LOCK);
|
||||
pInfo->pPullDataRes = createPullDataBlock();
|
||||
pInfo->ignoreCloseWindow = false;
|
||||
|
||||
pOperator->operatorType = pPhyNode->type;
|
||||
pOperator->blocking = true;
|
||||
|
@ -2830,6 +2853,7 @@ SOperatorInfo* createStreamSessionAggOperatorInfo(SOperatorInfo* downstream, SPh
|
|||
pInfo->pChildren = NULL;
|
||||
pInfo->isFinal = false;
|
||||
pInfo->pPhyNode = pPhyNode;
|
||||
pInfo->ignoreCloseWindow = false;
|
||||
|
||||
pOperator->name = "StreamSessionWindowAggOperator";
|
||||
pOperator->operatorType = QUERY_NODE_PHYSICAL_PLAN_STREAM_SESSION;
|
||||
|
@ -3007,6 +3031,9 @@ static int32_t doOneWindowAggImpl(int32_t tsColId, SOptrBasicInfo* pBinfo, SStre
|
|||
updateTimeWindowInfo(pTimeWindowData, &pCurWin->win, false);
|
||||
doApplyFunctions(pTaskInfo, pSup->pCtx, &pCurWin->win, pTimeWindowData, startIndex, winRows, tsCols,
|
||||
pSDataBlock->info.rows, numOutput, TSDB_ORDER_ASC);
|
||||
SFilePage* bufPage = getBufPage(pAggSup->pResultBuf, pCurWin->pos.pageId);
|
||||
setBufPageDirty(bufPage, true);
|
||||
releaseBufPage(pAggSup->pResultBuf, bufPage);
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
|
@ -3063,7 +3090,13 @@ void compactTimeWindow(SStreamSessionAggOperatorInfo* pInfo, int32_t startIndex,
|
|||
pWinInfo->isOutput = false;
|
||||
}
|
||||
taosArrayRemove(pInfo->streamAggSup.pCurWins, i);
|
||||
SFilePage* tmpPage = getBufPage(pInfo->streamAggSup.pResultBuf, pWinInfo->pos.pageId);
|
||||
releaseBufPage(pInfo->streamAggSup.pResultBuf, tmpPage);
|
||||
}
|
||||
SFilePage* bufPage = getBufPage(pInfo->streamAggSup.pResultBuf, pCurWin->pos.pageId);
|
||||
ASSERT(num > 0);
|
||||
setBufPageDirty(bufPage, true);
|
||||
releaseBufPage(pInfo->streamAggSup.pResultBuf, bufPage);
|
||||
}
|
||||
|
||||
static void doStreamSessionAggImpl(SOperatorInfo* pOperator, SSDataBlock* pSDataBlock, SHashObj* pStUpdated,
|
||||
|
@ -3083,7 +3116,7 @@ static void doStreamSessionAggImpl(SOperatorInfo* pOperator, SSDataBlock* pSData
|
|||
SResultRow* pResult = NULL;
|
||||
int32_t winRows = 0;
|
||||
|
||||
if (pSDataBlock->pDataBlock != NULL) {
|
||||
ASSERT(pSDataBlock->pDataBlock);
|
||||
SColumnInfoData* pStartTsCol = taosArrayGet(pSDataBlock->pDataBlock, pInfo->primaryTsIndex);
|
||||
startTsCols = (int64_t*)pStartTsCol->pData;
|
||||
SColumnInfoData* pEndTsCol = NULL;
|
||||
|
@ -3093,12 +3126,13 @@ static void doStreamSessionAggImpl(SOperatorInfo* pOperator, SSDataBlock* pSData
|
|||
pEndTsCol = taosArrayGet(pSDataBlock->pDataBlock, pInfo->primaryTsIndex);
|
||||
}
|
||||
endTsCols = (int64_t*)pEndTsCol->pData;
|
||||
} else {
|
||||
return;
|
||||
}
|
||||
|
||||
SStreamAggSupporter* pAggSup = &pInfo->streamAggSup;
|
||||
for (int32_t i = 0; i < pSDataBlock->info.rows;) {
|
||||
if (pInfo->ignoreCloseWindow && isOverdue(endTsCols[i], &pInfo->twAggSup)) {
|
||||
i++;
|
||||
continue;
|
||||
}
|
||||
int32_t winIndex = 0;
|
||||
SResultWindowInfo* pCurWin = getSessionTimeWindow(pAggSup, startTsCols[i], endTsCols[i], groupId, gap, &winIndex);
|
||||
winRows =
|
||||
|
@ -3205,17 +3239,24 @@ static void rebuildTimeWindow(SStreamSessionAggOperatorInfo* pInfo, SArray* pWin
|
|||
index = 0;
|
||||
}
|
||||
for (int32_t k = index; k < chWinSize; k++) {
|
||||
SResultWindowInfo* pcw = taosArrayGet(pChWins, k);
|
||||
if (pParentWin->win.skey <= pcw->win.skey && pcw->win.ekey <= pParentWin->win.ekey) {
|
||||
SResultWindowInfo* pChWin = taosArrayGet(pChWins, k);
|
||||
if (pParentWin->win.skey <= pChWin->win.skey && pChWin->win.ekey <= pParentWin->win.ekey) {
|
||||
SResultRow* pChResult = NULL;
|
||||
setWindowOutputBuf(pcw, &pChResult, pChild->exprSupp.pCtx, groupId, numOfOutput,
|
||||
setWindowOutputBuf(pChWin, &pChResult, pChild->exprSupp.pCtx, groupId, numOfOutput,
|
||||
pChild->exprSupp.rowEntryInfoOffset, &pChInfo->streamAggSup, pTaskInfo);
|
||||
compactFunctions(pSup->pCtx, pChild->exprSupp.pCtx, numOfOutput, pTaskInfo);
|
||||
SFilePage* bufPage = getBufPage(pInfo->streamAggSup.pResultBuf, pChWin->pos.pageId);
|
||||
setBufPageDirty(bufPage, true);
|
||||
releaseBufPage(pInfo->streamAggSup.pResultBuf, bufPage);
|
||||
continue;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
SFilePage* bufPage = getBufPage(pInfo->streamAggSup.pResultBuf, pParentWin->pos.pageId);
|
||||
ASSERT(size > 0);
|
||||
setBufPageDirty(bufPage, true);
|
||||
releaseBufPage(pInfo->streamAggSup.pResultBuf, bufPage);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -3234,7 +3275,7 @@ int32_t closeSessionWindow(SHashObj* pHashMap, STimeWindowAggSupp* pTwSup, SArra
|
|||
for (int32_t i = 0; i < size; i++) {
|
||||
void* pWin = taosArrayGet(pWins, i);
|
||||
SResultWindowInfo* pSeWin = fn(pWin);
|
||||
if (pSeWin->win.ekey < pTwSup->maxTs - pTwSup->waterMark) {
|
||||
if (isCloseWindow(&pSeWin->win, pTwSup)) {
|
||||
if (!pSeWin->isClosed) {
|
||||
pSeWin->isClosed = true;
|
||||
if (pTwSup->calTrigger == STREAM_TRIGGER_WINDOW_CLOSE) {
|
||||
|
@ -3745,6 +3786,10 @@ static void doStreamStateAggImpl(SOperatorInfo* pOperator, SSDataBlock* pSDataBl
|
|||
SStreamAggSupporter* pAggSup = &pInfo->streamAggSup;
|
||||
SColumnInfoData* pKeyColInfo = taosArrayGet(pSDataBlock->pDataBlock, pInfo->stateCol.slotId);
|
||||
for (int32_t i = 0; i < pSDataBlock->info.rows; i += winRows) {
|
||||
if (pInfo->ignoreCloseWindow && isOverdue(tsCols[i], &pInfo->twAggSup)) {
|
||||
i++;
|
||||
continue;
|
||||
}
|
||||
char* pKeyData = colDataGetData(pKeyColInfo, i);
|
||||
int32_t winIndex = 0;
|
||||
bool allEqual = true;
|
||||
|
@ -3895,6 +3940,7 @@ SOperatorInfo* createStreamStateAggOperatorInfo(SOperatorInfo* downstream, SPhys
|
|||
pInfo->pDelRes->info.type = STREAM_DELETE;
|
||||
blockDataEnsureCapacity(pInfo->pDelRes, 64);
|
||||
pInfo->pChildren = NULL;
|
||||
pInfo->ignoreCloseWindow = false;
|
||||
|
||||
pOperator->name = "StreamStateAggOperator";
|
||||
pOperator->operatorType = QUERY_NODE_PHYSICAL_PLAN_STREAM_STATE;
|
||||
|
|
|
@ -46,6 +46,7 @@ extern "C" {
|
|||
#define FUNC_MGT_FORBID_STREAM_FUNC FUNC_MGT_FUNC_CLASSIFICATION_MASK(17)
|
||||
#define FUNC_MGT_FORBID_WINDOW_FUNC FUNC_MGT_FUNC_CLASSIFICATION_MASK(18)
|
||||
#define FUNC_MGT_FORBID_GROUP_BY_FUNC FUNC_MGT_FUNC_CLASSIFICATION_MASK(19)
|
||||
#define FUNC_MGT_SYSTEM_INFO_FUNC FUNC_MGT_FUNC_CLASSIFICATION_MASK(20)
|
||||
|
||||
#define FUNC_MGT_TEST_MASK(val, mask) (((val) & (mask)) != 0)
|
||||
|
||||
|
|
|
@ -1379,6 +1379,20 @@ static bool validateTimezoneFormat(const SValueNode* pVal) {
|
|||
return true;
|
||||
}
|
||||
|
||||
void static addDbPrecisonParam(SNodeList* pList, uint8_t precision) {
|
||||
SValueNode* pVal = (SValueNode*)nodesMakeNode(QUERY_NODE_VALUE);
|
||||
pVal->literal = NULL;
|
||||
pVal->isDuration = false;
|
||||
pVal->translate = true;
|
||||
pVal->node.resType.type = TSDB_DATA_TYPE_TINYINT;
|
||||
pVal->node.resType.bytes = tDataTypes[TSDB_DATA_TYPE_TINYINT].bytes;
|
||||
pVal->node.resType.precision = precision;
|
||||
pVal->datum.i = (int64_t)precision;
|
||||
pVal->typeData = (int64_t)precision;
|
||||
|
||||
nodesListAppend(pList, (SNode*)pVal);
|
||||
}
|
||||
|
||||
void static addTimezoneParam(SNodeList* pList) {
|
||||
char buf[6] = {0};
|
||||
time_t t = taosTime(NULL);
|
||||
|
@ -1462,6 +1476,10 @@ static int32_t translateTimeTruncate(SFunctionNode* pFunc, char* pErrBuf, int32_
|
|||
return invaildFuncParaTypeErrMsg(pErrBuf, len, pFunc->functionName);
|
||||
}
|
||||
|
||||
//add database precision as param
|
||||
uint8_t dbPrec = pFunc->node.resType.precision;
|
||||
addDbPrecisonParam(pFunc->pParameterList, dbPrec);
|
||||
|
||||
pFunc->node.resType =
|
||||
(SDataType){.bytes = tDataTypes[TSDB_DATA_TYPE_TIMESTAMP].bytes, .type = TSDB_DATA_TYPE_TIMESTAMP};
|
||||
return TSDB_CODE_SUCCESS;
|
||||
|
@ -1486,6 +1504,10 @@ static int32_t translateTimeDiff(SFunctionNode* pFunc, char* pErrBuf, int32_t le
|
|||
}
|
||||
}
|
||||
|
||||
//add database precision as param
|
||||
uint8_t dbPrec = pFunc->node.resType.precision;
|
||||
addDbPrecisonParam(pFunc->pParameterList, dbPrec);
|
||||
|
||||
pFunc->node.resType = (SDataType){.bytes = tDataTypes[TSDB_DATA_TYPE_BIGINT].bytes, .type = TSDB_DATA_TYPE_BIGINT};
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
@ -1539,6 +1561,36 @@ static int32_t translateGroupKey(SFunctionNode* pFunc, char* pErrBuf, int32_t le
|
|||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
static int32_t translateDatabaseFunc(SFunctionNode* pFunc, char* pErrBuf, int32_t len) {
|
||||
pFunc->node.resType = (SDataType){.bytes = TSDB_DB_NAME_LEN, .type = TSDB_DATA_TYPE_VARCHAR};
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
static int32_t translateClientVersionFunc(SFunctionNode* pFunc, char* pErrBuf, int32_t len) {
|
||||
pFunc->node.resType = (SDataType){.bytes = TSDB_VERSION_LEN, .type = TSDB_DATA_TYPE_VARCHAR};
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
static int32_t translateServerVersionFunc(SFunctionNode* pFunc, char* pErrBuf, int32_t len) {
|
||||
pFunc->node.resType = (SDataType){.bytes = TSDB_VERSION_LEN, .type = TSDB_DATA_TYPE_VARCHAR};
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
static int32_t translateServerStatusFunc(SFunctionNode* pFunc, char* pErrBuf, int32_t len) {
|
||||
pFunc->node.resType = (SDataType){.bytes = tDataTypes[TSDB_DATA_TYPE_INT].bytes, .type = TSDB_DATA_TYPE_INT};
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
static int32_t translateCurrentUserFunc(SFunctionNode* pFunc, char* pErrBuf, int32_t len) {
|
||||
pFunc->node.resType = (SDataType){.bytes = TSDB_USER_LEN, .type = TSDB_DATA_TYPE_VARCHAR};
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
static int32_t translateUserFunc(SFunctionNode* pFunc, char* pErrBuf, int32_t len) {
|
||||
pFunc->node.resType = (SDataType){.bytes = TSDB_USER_LEN, .type = TSDB_DATA_TYPE_VARCHAR};
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
// clang-format off
|
||||
const SBuiltinFuncDefinition funcMgtBuiltins[] = {
|
||||
{
|
||||
|
@ -1904,7 +1956,7 @@ const SBuiltinFuncDefinition funcMgtBuiltins[] = {
|
|||
{
|
||||
.name = "_first_partial",
|
||||
.type = FUNCTION_TYPE_FIRST_PARTIAL,
|
||||
.classification = FUNC_MGT_AGG_FUNC | FUNC_MGT_MULTI_RES_FUNC | FUNC_MGT_TIMELINE_FUNC,
|
||||
.classification = FUNC_MGT_AGG_FUNC | FUNC_MGT_SELECT_FUNC | FUNC_MGT_MULTI_RES_FUNC | FUNC_MGT_TIMELINE_FUNC,
|
||||
.translateFunc = translateFirstLastPartial,
|
||||
.getEnvFunc = getFirstLastFuncEnv,
|
||||
.initFunc = functionSetup,
|
||||
|
@ -1915,7 +1967,7 @@ const SBuiltinFuncDefinition funcMgtBuiltins[] = {
|
|||
{
|
||||
.name = "_first_merge",
|
||||
.type = FUNCTION_TYPE_FIRST_MERGE,
|
||||
.classification = FUNC_MGT_AGG_FUNC | FUNC_MGT_MULTI_RES_FUNC | FUNC_MGT_TIMELINE_FUNC,
|
||||
.classification = FUNC_MGT_AGG_FUNC | FUNC_MGT_SELECT_FUNC | FUNC_MGT_MULTI_RES_FUNC | FUNC_MGT_TIMELINE_FUNC,
|
||||
.translateFunc = translateFirstLastMerge,
|
||||
.getEnvFunc = getFirstLastFuncEnv,
|
||||
.initFunc = functionSetup,
|
||||
|
@ -1939,7 +1991,7 @@ const SBuiltinFuncDefinition funcMgtBuiltins[] = {
|
|||
{
|
||||
.name = "_last_partial",
|
||||
.type = FUNCTION_TYPE_LAST_PARTIAL,
|
||||
.classification = FUNC_MGT_AGG_FUNC | FUNC_MGT_MULTI_RES_FUNC | FUNC_MGT_TIMELINE_FUNC,
|
||||
.classification = FUNC_MGT_AGG_FUNC | FUNC_MGT_SELECT_FUNC | FUNC_MGT_MULTI_RES_FUNC | FUNC_MGT_TIMELINE_FUNC,
|
||||
.translateFunc = translateFirstLastPartial,
|
||||
.getEnvFunc = getFirstLastFuncEnv,
|
||||
.initFunc = functionSetup,
|
||||
|
@ -1950,7 +2002,7 @@ const SBuiltinFuncDefinition funcMgtBuiltins[] = {
|
|||
{
|
||||
.name = "_last_merge",
|
||||
.type = FUNCTION_TYPE_LAST_MERGE,
|
||||
.classification = FUNC_MGT_AGG_FUNC | FUNC_MGT_MULTI_RES_FUNC | FUNC_MGT_TIMELINE_FUNC,
|
||||
.classification = FUNC_MGT_AGG_FUNC | FUNC_MGT_SELECT_FUNC | FUNC_MGT_MULTI_RES_FUNC | FUNC_MGT_TIMELINE_FUNC,
|
||||
.translateFunc = translateFirstLastMerge,
|
||||
.getEnvFunc = getFirstLastFuncEnv,
|
||||
.initFunc = functionSetup,
|
||||
|
@ -2546,6 +2598,42 @@ const SBuiltinFuncDefinition funcMgtBuiltins[] = {
|
|||
.pPartialFunc = "_group_key",
|
||||
.pMergeFunc = "_group_key"
|
||||
},
|
||||
{
|
||||
.name = "database",
|
||||
.type = FUNCTION_TYPE_DATABASE,
|
||||
.classification = FUNC_MGT_SYSTEM_INFO_FUNC | FUNC_MGT_SCALAR_FUNC,
|
||||
.translateFunc = translateDatabaseFunc,
|
||||
},
|
||||
{
|
||||
.name = "client_version",
|
||||
.type = FUNCTION_TYPE_CLIENT_VERSION,
|
||||
.classification = FUNC_MGT_SYSTEM_INFO_FUNC | FUNC_MGT_SCALAR_FUNC,
|
||||
.translateFunc = translateClientVersionFunc,
|
||||
},
|
||||
{
|
||||
.name = "server_version",
|
||||
.type = FUNCTION_TYPE_SERVER_VERSION,
|
||||
.classification = FUNC_MGT_SYSTEM_INFO_FUNC | FUNC_MGT_SCALAR_FUNC,
|
||||
.translateFunc = translateServerVersionFunc,
|
||||
},
|
||||
{
|
||||
.name = "server_status",
|
||||
.type = FUNCTION_TYPE_SERVER_STATUS,
|
||||
.classification = FUNC_MGT_SYSTEM_INFO_FUNC | FUNC_MGT_SCALAR_FUNC,
|
||||
.translateFunc = translateServerStatusFunc,
|
||||
},
|
||||
{
|
||||
.name = "current_user",
|
||||
.type = FUNCTION_TYPE_CURRENT_USER,
|
||||
.classification = FUNC_MGT_SYSTEM_INFO_FUNC | FUNC_MGT_SCALAR_FUNC,
|
||||
.translateFunc = translateCurrentUserFunc,
|
||||
},
|
||||
{
|
||||
.name = "user",
|
||||
.type = FUNCTION_TYPE_USER,
|
||||
.classification = FUNC_MGT_SYSTEM_INFO_FUNC | FUNC_MGT_SCALAR_FUNC,
|
||||
.translateFunc = translateUserFunc,
|
||||
},
|
||||
};
|
||||
// clang-format on
|
||||
|
||||
|
|
|
@ -2409,11 +2409,11 @@ int32_t apercentileCombine(SqlFunctionCtx* pDestCtx, SqlFunctionCtx* pSourceCtx)
|
|||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
int32_t getFirstLastInfoSize(int32_t resBytes) { return sizeof(SFirstLastRes) + resBytes + sizeof(int64_t); }
|
||||
int32_t getFirstLastInfoSize(int32_t resBytes) { return sizeof(SFirstLastRes) + resBytes + sizeof(int64_t) + sizeof(STuplePos); }
|
||||
|
||||
bool getFirstLastFuncEnv(SFunctionNode* pFunc, SFuncExecEnv* pEnv) {
|
||||
SColumnNode* pNode = (SColumnNode*)nodesListGetNode(pFunc->pParameterList, 0);
|
||||
pEnv->calcMemSize = sizeof(SFirstLastRes) + pNode->node.resType.bytes + sizeof(int64_t);
|
||||
pEnv->calcMemSize = getFirstLastInfoSize(pNode->node.resType.bytes);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -2491,9 +2491,17 @@ int32_t firstFunction(SqlFunctionCtx* pCtx) {
|
|||
}
|
||||
memcpy(pInfo->buf, data, bytes);
|
||||
*(TSKEY*)(pInfo->buf + bytes) = cts;
|
||||
//handle selectivity
|
||||
if (pCtx->subsidiaries.num > 0) {
|
||||
STuplePos* pTuplePos = (STuplePos*)(pInfo->buf + bytes + sizeof(TSKEY));
|
||||
if (!pInfo->hasResult) {
|
||||
saveTupleData(pCtx, i, pCtx->pSrcBlock, pTuplePos);
|
||||
} else {
|
||||
copyTupleData(pCtx, i, pCtx->pSrcBlock, pTuplePos);
|
||||
}
|
||||
}
|
||||
pInfo->hasResult = true;
|
||||
// DO_UPDATE_TAG_COLUMNS(pCtx, ts);
|
||||
|
||||
//DO_UPDATE_TAG_COLUMNS(pCtx, ts);
|
||||
pResInfo->numOfRes = 1;
|
||||
break;
|
||||
}
|
||||
|
@ -2525,8 +2533,17 @@ int32_t firstFunction(SqlFunctionCtx* pCtx) {
|
|||
}
|
||||
memcpy(pInfo->buf, data, bytes);
|
||||
*(TSKEY*)(pInfo->buf + bytes) = cts;
|
||||
//handle selectivity
|
||||
if (pCtx->subsidiaries.num > 0) {
|
||||
STuplePos* pTuplePos = (STuplePos*)(pInfo->buf + bytes + sizeof(TSKEY));
|
||||
if (!pInfo->hasResult) {
|
||||
saveTupleData(pCtx, i, pCtx->pSrcBlock, pTuplePos);
|
||||
} else {
|
||||
copyTupleData(pCtx, i, pCtx->pSrcBlock, pTuplePos);
|
||||
}
|
||||
}
|
||||
pInfo->hasResult = true;
|
||||
// DO_UPDATE_TAG_COLUMNS(pCtx, ts);
|
||||
//DO_UPDATE_TAG_COLUMNS(pCtx, ts);
|
||||
pResInfo->numOfRes = 1;
|
||||
break;
|
||||
}
|
||||
|
@ -2580,8 +2597,17 @@ int32_t lastFunction(SqlFunctionCtx* pCtx) {
|
|||
}
|
||||
memcpy(pInfo->buf, data, bytes);
|
||||
*(TSKEY*)(pInfo->buf + bytes) = cts;
|
||||
// DO_UPDATE_TAG_COLUMNS(pCtx, ts);
|
||||
//handle selectivity
|
||||
if (pCtx->subsidiaries.num > 0) {
|
||||
STuplePos* pTuplePos = (STuplePos*)(pInfo->buf + bytes + sizeof(TSKEY));
|
||||
if (!pInfo->hasResult) {
|
||||
saveTupleData(pCtx, i, pCtx->pSrcBlock, pTuplePos);
|
||||
} else {
|
||||
copyTupleData(pCtx, i, pCtx->pSrcBlock, pTuplePos);
|
||||
}
|
||||
}
|
||||
pInfo->hasResult = true;
|
||||
//DO_UPDATE_TAG_COLUMNS(pCtx, ts);
|
||||
pResInfo->numOfRes = 1;
|
||||
}
|
||||
break;
|
||||
|
@ -2603,9 +2629,18 @@ int32_t lastFunction(SqlFunctionCtx* pCtx) {
|
|||
}
|
||||
memcpy(pInfo->buf, data, bytes);
|
||||
*(TSKEY*)(pInfo->buf + bytes) = cts;
|
||||
//handle selectivity
|
||||
if (pCtx->subsidiaries.num > 0) {
|
||||
STuplePos* pTuplePos = (STuplePos*)(pInfo->buf + bytes + sizeof(TSKEY));
|
||||
if (!pInfo->hasResult) {
|
||||
saveTupleData(pCtx, i, pCtx->pSrcBlock, pTuplePos);
|
||||
} else {
|
||||
copyTupleData(pCtx, i, pCtx->pSrcBlock, pTuplePos);
|
||||
}
|
||||
}
|
||||
pInfo->hasResult = true;
|
||||
pResInfo->numOfRes = 1;
|
||||
// DO_UPDATE_TAG_COLUMNS(pCtx, ts);
|
||||
//DO_UPDATE_TAG_COLUMNS(pCtx, ts);
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
@ -2615,7 +2650,10 @@ int32_t lastFunction(SqlFunctionCtx* pCtx) {
|
|||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
static void firstLastTransferInfo(SFirstLastRes* pInput, SFirstLastRes* pOutput, bool isFirst) {
|
||||
static void firstLastTransferInfo(SqlFunctionCtx* pCtx, SFirstLastRes* pInput, SFirstLastRes* pOutput, bool isFirst) {
|
||||
SInputColumnInfoData* pColInfo = &pCtx->input;
|
||||
int32_t start = pColInfo->startRowIndex;
|
||||
|
||||
pOutput->bytes = pInput->bytes;
|
||||
TSKEY* tsIn = (TSKEY*)(pInput->buf + pInput->bytes);
|
||||
TSKEY* tsOut = (TSKEY*)(pOutput->buf + pInput->bytes);
|
||||
|
@ -2632,7 +2670,17 @@ static void firstLastTransferInfo(SFirstLastRes* pInput, SFirstLastRes* pOutput,
|
|||
}
|
||||
*tsOut = *tsIn;
|
||||
memcpy(pOutput->buf, pInput->buf, pOutput->bytes);
|
||||
//handle selectivity
|
||||
STuplePos* pTuplePos = (STuplePos*)(pOutput->buf + pOutput->bytes + sizeof(TSKEY));
|
||||
if (pCtx->subsidiaries.num > 0) {
|
||||
if (!pOutput->hasResult) {
|
||||
saveTupleData(pCtx, start, pCtx->pSrcBlock, pTuplePos);
|
||||
} else {
|
||||
copyTupleData(pCtx, start, pCtx->pSrcBlock, pTuplePos);
|
||||
}
|
||||
}
|
||||
pOutput->hasResult = true;
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -2647,7 +2695,7 @@ static int32_t firstLastFunctionMergeImpl(SqlFunctionCtx* pCtx, bool isFirstQuer
|
|||
char* data = colDataGetData(pCol, start);
|
||||
SFirstLastRes* pInputInfo = (SFirstLastRes*)varDataVal(data);
|
||||
|
||||
firstLastTransferInfo(pInputInfo, pInfo, isFirstQuery);
|
||||
firstLastTransferInfo(pCtx, pInputInfo, pInfo, isFirstQuery);
|
||||
|
||||
int32_t numOfElems = pInputInfo->hasResult ? 1 : 0;
|
||||
|
||||
|
@ -2669,6 +2717,9 @@ int32_t firstLastFinalize(SqlFunctionCtx* pCtx, SSDataBlock* pBlock) {
|
|||
|
||||
SFirstLastRes* pRes = GET_ROWCELL_INTERBUF(pResInfo);
|
||||
colDataAppend(pCol, pBlock->info.rows, pRes->buf, pResInfo->isNullRes);
|
||||
//handle selectivity
|
||||
STuplePos* pTuplePos = (STuplePos*)(pRes->buf + pRes->bytes + sizeof(TSKEY));
|
||||
setSelectivityValue(pCtx, pBlock, pTuplePos, pBlock->info.rows);
|
||||
|
||||
return pResInfo->numOfRes;
|
||||
}
|
||||
|
@ -2687,6 +2738,9 @@ int32_t firstLastPartialFinalize(SqlFunctionCtx* pCtx, SSDataBlock* pBlock) {
|
|||
SColumnInfoData* pCol = taosArrayGet(pBlock->pDataBlock, slotId);
|
||||
|
||||
colDataAppend(pCol, pBlock->info.rows, res, false);
|
||||
//handle selectivity
|
||||
STuplePos* pTuplePos = (STuplePos*)(pRes->buf + pRes->bytes + sizeof(TSKEY));
|
||||
setSelectivityValue(pCtx, pBlock, pTuplePos, pBlock->info.rows);
|
||||
|
||||
taosMemoryFree(res);
|
||||
return 1;
|
||||
|
@ -3043,7 +3097,9 @@ void doAddIntoResult(SqlFunctionCtx* pCtx, void* pData, int32_t rowIndex, SSData
|
|||
pItem->uid = uid;
|
||||
|
||||
// save the data of this tuple
|
||||
if (pCtx->subsidiaries.num > 0) {
|
||||
saveTupleData(pCtx, rowIndex, pSrcBlock, &pItem->tuplePos);
|
||||
}
|
||||
|
||||
// allocate the buffer and keep the data of this row into the new allocated buffer
|
||||
pEntryInfo->numOfRes++;
|
||||
|
@ -3062,7 +3118,10 @@ void doAddIntoResult(SqlFunctionCtx* pCtx, void* pData, int32_t rowIndex, SSData
|
|||
pItem->uid = uid;
|
||||
|
||||
// save the data of this tuple by over writing the old data
|
||||
if (pCtx->subsidiaries.num > 0) {
|
||||
copyTupleData(pCtx, rowIndex, pSrcBlock, &pItem->tuplePos);
|
||||
}
|
||||
|
||||
taosheapadjust((void*)pItems, sizeof(STopBotResItem), 0, pEntryInfo->numOfRes - 1, (const void*)&type,
|
||||
topBotResComparFn, NULL, !isTopQuery);
|
||||
}
|
||||
|
@ -5466,7 +5525,7 @@ int32_t groupKeyFunction(SqlFunctionCtx* pCtx) {
|
|||
|
||||
int32_t startIndex = pInput->startRowIndex;
|
||||
|
||||
//escape rest of data blocks to avoid first entry be overwritten.
|
||||
//escape rest of data blocks to avoid first entry to be overwritten.
|
||||
if (pInfo->hasResult) {
|
||||
goto _group_key_over;
|
||||
}
|
||||
|
|
|
@ -179,6 +179,8 @@ bool fmIsForbidWindowFunc(int32_t funcId) { return isSpecificClassifyFunc(funcId
|
|||
|
||||
bool fmIsForbidGroupByFunc(int32_t funcId) { return isSpecificClassifyFunc(funcId, FUNC_MGT_FORBID_GROUP_BY_FUNC); }
|
||||
|
||||
bool fmIsSystemInfoFunc(int32_t funcId) { return isSpecificClassifyFunc(funcId, FUNC_MGT_SYSTEM_INFO_FUNC); }
|
||||
|
||||
bool fmIsInterpFunc(int32_t funcId) {
|
||||
if (funcId < 0 || funcId >= funcMgtBuiltinsNum) {
|
||||
return false;
|
||||
|
|
|
@ -685,6 +685,12 @@ literal_func(A) ::= NOW(B).
|
|||
noarg_func(A) ::= NOW(B). { A = B; }
|
||||
noarg_func(A) ::= TODAY(B). { A = B; }
|
||||
noarg_func(A) ::= TIMEZONE(B). { A = B; }
|
||||
noarg_func(A) ::= DATABASE(B). { A = B; }
|
||||
noarg_func(A) ::= CLIENT_VERSION(B). { A = B; }
|
||||
noarg_func(A) ::= SERVER_VERSION(B). { A = B; }
|
||||
noarg_func(A) ::= SERVER_STATUS(B). { A = B; }
|
||||
noarg_func(A) ::= CURRENT_USER(B). { A = B; }
|
||||
noarg_func(A) ::= USER(B). { A = B; }
|
||||
|
||||
%type star_func { SToken }
|
||||
%destructor star_func { }
|
||||
|
|
|
@ -67,6 +67,13 @@ typedef struct SInsertParseContext {
|
|||
SParseMetaCache* pMetaCache;
|
||||
} SInsertParseContext;
|
||||
|
||||
typedef struct SInsertParseSyntaxCxt {
|
||||
SParseContext* pComCxt;
|
||||
char* pSql;
|
||||
SMsgBuf msg;
|
||||
SParseMetaCache* pMetaCache;
|
||||
} SInsertParseSyntaxCxt;
|
||||
|
||||
typedef int32_t (*_row_append_fn_t)(SMsgBuf* pMsgBuf, const void* value, int32_t len, void* param);
|
||||
|
||||
static uint8_t TRUE_VALUE = (uint8_t)TSDB_TRUE;
|
||||
|
@ -1098,11 +1105,24 @@ static int32_t storeTableMeta(SInsertParseContext* pCxt, SHashObj* pHash, SName*
|
|||
return taosHashPut(pHash, pName, len, &pBackup, POINTER_BYTES);
|
||||
}
|
||||
|
||||
static int32_t skipUsingClause(SInsertParseSyntaxCxt* pCxt);
|
||||
|
||||
// pSql -> stb_name [(tag1_name, ...)] TAGS (tag1_value, ...)
|
||||
static int32_t ignoreAutoCreateTableClause(SInsertParseContext* pCxt) {
|
||||
SToken sToken;
|
||||
NEXT_TOKEN(pCxt->pSql, sToken);
|
||||
SInsertParseSyntaxCxt cxt = {.pComCxt = pCxt->pComCxt, .pSql = pCxt->pSql, .msg = pCxt->msg, .pMetaCache = NULL};
|
||||
int32_t code = skipUsingClause(&cxt);
|
||||
pCxt->pSql = cxt.pSql;
|
||||
return code;
|
||||
}
|
||||
|
||||
// pSql -> stb_name [(tag1_name, ...)] TAGS (tag1_value, ...)
|
||||
static int32_t parseUsingClause(SInsertParseContext* pCxt, SName* name, char* tbFName) {
|
||||
int32_t len = strlen(tbFName);
|
||||
STableMeta** pMeta = taosHashGet(pCxt->pSubTableHashObj, tbFName, len);
|
||||
if (NULL != pMeta) {
|
||||
CHECK_CODE(ignoreAutoCreateTableClause(pCxt));
|
||||
return cloneTableMeta(*pMeta, &pCxt->pTableMeta);
|
||||
}
|
||||
|
||||
|
@ -1522,13 +1542,6 @@ int32_t parseInsertSql(SParseContext* pContext, SQuery** pQuery, SParseMetaCache
|
|||
return code;
|
||||
}
|
||||
|
||||
typedef struct SInsertParseSyntaxCxt {
|
||||
SParseContext* pComCxt;
|
||||
char* pSql;
|
||||
SMsgBuf msg;
|
||||
SParseMetaCache* pMetaCache;
|
||||
} SInsertParseSyntaxCxt;
|
||||
|
||||
static int32_t skipParentheses(SInsertParseSyntaxCxt* pCxt) {
|
||||
SToken sToken;
|
||||
int32_t expectRightParenthesis = 1;
|
||||
|
@ -1757,7 +1770,7 @@ int32_t qBindStmtTagsValue(void* pBlock, void* boundTags, int64_t suid, char* tN
|
|||
}
|
||||
|
||||
int32_t code = TSDB_CODE_SUCCESS;
|
||||
SSchema* pSchema = pDataBlock->pTableMeta->schema;
|
||||
SSchema* pSchema = getTableTagSchema(pDataBlock->pTableMeta);
|
||||
|
||||
bool isJson = false;
|
||||
STag* pTag = NULL;
|
||||
|
|
|
@ -54,6 +54,7 @@ static SKeyword keywordTable[] = {
|
|||
{"CACHE", TK_CACHE},
|
||||
{"CACHELAST", TK_CACHELAST},
|
||||
{"CAST", TK_CAST},
|
||||
{"CLIENT_VERSION", TK_CLIENT_VERSION},
|
||||
{"CLUSTER", TK_CLUSTER},
|
||||
{"COLUMN", TK_COLUMN},
|
||||
{"COMMENT", TK_COMMENT},
|
||||
|
@ -64,9 +65,10 @@ static SKeyword keywordTable[] = {
|
|||
{"CONNECTIONS", TK_CONNECTIONS},
|
||||
{"CONSUMER", TK_CONSUMER},
|
||||
{"CONSUMERS", TK_CONSUMERS},
|
||||
{"CONTAINS", TK_CONTAINS},
|
||||
{"COUNT", TK_COUNT},
|
||||
{"CREATE", TK_CREATE},
|
||||
{"CONTAINS", TK_CONTAINS},
|
||||
{"CURRENT_USER", TK_CURRENT_USER},
|
||||
{"DATABASE", TK_DATABASE},
|
||||
{"DATABASES", TK_DATABASES},
|
||||
{"DBS", TK_DBS},
|
||||
|
@ -169,6 +171,8 @@ static SKeyword keywordTable[] = {
|
|||
{"SCHEMALESS", TK_SCHEMALESS},
|
||||
{"SCORES", TK_SCORES},
|
||||
{"SELECT", TK_SELECT},
|
||||
{"SERVER_STATUS", TK_SERVER_STATUS},
|
||||
{"SERVER_VERSION", TK_SERVER_VERSION},
|
||||
{"SESSION", TK_SESSION},
|
||||
{"SET", TK_SET},
|
||||
{"SHOW", TK_SHOW},
|
||||
|
|
|
@ -35,8 +35,7 @@ typedef struct STranslateContext {
|
|||
SArray* pNsLevel; // element is SArray*, the element of this subarray is STableNode*
|
||||
int32_t currLevel;
|
||||
ESqlClause currClause;
|
||||
SSelectStmt* pCurrSelectStmt;
|
||||
SSetOperator* pCurrSetOperator;
|
||||
SNode* pCurrStmt;
|
||||
SCmdMsgInfo* pCmdMsg;
|
||||
SHashObj* pDbs;
|
||||
SHashObj* pTables;
|
||||
|
@ -397,6 +396,34 @@ static void destroyTranslateContext(STranslateContext* pCxt) {
|
|||
taosHashCleanup(pCxt->pTables);
|
||||
}
|
||||
|
||||
static bool isSelectStmt(SNode* pCurrStmt) {
|
||||
return NULL != pCurrStmt && QUERY_NODE_SELECT_STMT == nodeType(pCurrStmt);
|
||||
}
|
||||
|
||||
static bool isSetOperator(SNode* pCurrStmt) {
|
||||
return NULL != pCurrStmt && QUERY_NODE_SET_OPERATOR == nodeType(pCurrStmt);
|
||||
}
|
||||
|
||||
static SNodeList* getProjectListFromCurrStmt(SNode* pCurrStmt) {
|
||||
if (isSelectStmt(pCurrStmt)) {
|
||||
return ((SSelectStmt*)pCurrStmt)->pProjectionList;
|
||||
}
|
||||
if (isSetOperator(pCurrStmt)) {
|
||||
return ((SSetOperator*)pCurrStmt)->pProjectionList;
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static uint8_t getPrecisionFromCurrStmt(SNode* pCurrStmt, uint8_t defaultVal) {
|
||||
if (isSelectStmt(pCurrStmt)) {
|
||||
return ((SSelectStmt*)pCurrStmt)->precision;
|
||||
}
|
||||
if (isSetOperator(pCurrStmt)) {
|
||||
return ((SSetOperator*)pCurrStmt)->precision;
|
||||
}
|
||||
return defaultVal;
|
||||
}
|
||||
|
||||
static bool isAliasColumn(const SNode* pNode) {
|
||||
return (QUERY_NODE_COLUMN == nodeType(pNode) && ('\0' == ((SColumnNode*)pNode)->tableAlias[0]));
|
||||
}
|
||||
|
@ -426,7 +453,8 @@ static bool isVectorFunc(const SNode* pNode) {
|
|||
}
|
||||
|
||||
static bool isDistinctOrderBy(STranslateContext* pCxt) {
|
||||
return (SQL_CLAUSE_ORDER_BY == pCxt->currClause && pCxt->pCurrSelectStmt->isDistinct);
|
||||
return (SQL_CLAUSE_ORDER_BY == pCxt->currClause && isSelectStmt(pCxt->pCurrStmt) &&
|
||||
((SSelectStmt*)pCxt->pCurrStmt)->isDistinct);
|
||||
}
|
||||
|
||||
static bool belongTable(const char* currentDb, const SColumnNode* pCol, const STableNode* pTable) {
|
||||
|
@ -646,7 +674,7 @@ static EDealRes translateColumnWithoutPrefix(STranslateContext* pCxt, SColumnNod
|
|||
}
|
||||
if (!found) {
|
||||
if (isInternalPk) {
|
||||
if (NULL != pCxt->pCurrSelectStmt && NULL != pCxt->pCurrSelectStmt->pWindow) {
|
||||
if (isSelectStmt(pCxt->pCurrStmt) && NULL != ((SSelectStmt*)pCxt->pCurrStmt)->pWindow) {
|
||||
return generateDealNodeErrMsg(pCxt, TSDB_CODE_PAR_NOT_ALLOWED_WIN_QUERY);
|
||||
}
|
||||
return generateDealNodeErrMsg(pCxt, TSDB_CODE_PAR_INVALID_INTERNAL_PK);
|
||||
|
@ -657,18 +685,8 @@ static EDealRes translateColumnWithoutPrefix(STranslateContext* pCxt, SColumnNod
|
|||
return DEAL_RES_CONTINUE;
|
||||
}
|
||||
|
||||
static SNodeList* getProjectListFromCxt(STranslateContext* pCxt) {
|
||||
if (NULL != pCxt->pCurrSelectStmt) {
|
||||
return pCxt->pCurrSelectStmt->pProjectionList;
|
||||
} else if (NULL != pCxt->pCurrSetOperator) {
|
||||
return pCxt->pCurrSetOperator->pProjectionList;
|
||||
} else {
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
static EDealRes translateColumnUseAlias(STranslateContext* pCxt, SColumnNode** pCol, bool* pFound) {
|
||||
SNodeList* pProjectionList = getProjectListFromCxt(pCxt);
|
||||
SNodeList* pProjectionList = getProjectListFromCurrStmt(pCxt->pCurrStmt);
|
||||
SNode* pNode;
|
||||
FOREACH(pNode, pProjectionList) {
|
||||
SExprNode* pExpr = (SExprNode*)pNode;
|
||||
|
@ -690,7 +708,7 @@ static EDealRes translateColumnUseAlias(STranslateContext* pCxt, SColumnNode** p
|
|||
}
|
||||
|
||||
static EDealRes translateColumn(STranslateContext* pCxt, SColumnNode** pCol) {
|
||||
if (NULL != pCxt->pCurrSelectStmt && NULL == pCxt->pCurrSelectStmt->pFromTable) {
|
||||
if (isSelectStmt(pCxt->pCurrStmt) && NULL == ((SSelectStmt*)pCxt->pCurrStmt)->pFromTable) {
|
||||
return generateDealNodeErrMsg(pCxt, TSDB_CODE_PAR_INVALID_COLUMN, (*pCol)->colName);
|
||||
}
|
||||
|
||||
|
@ -708,7 +726,7 @@ static EDealRes translateColumn(STranslateContext* pCxt, SColumnNode** pCol) {
|
|||
res = translateColumnUseAlias(pCxt, pCol, &found);
|
||||
}
|
||||
if (DEAL_RES_ERROR != res && !found) {
|
||||
if (NULL != pCxt->pCurrSetOperator) {
|
||||
if (isSetOperator(pCxt->pCurrStmt)) {
|
||||
res = generateDealNodeErrMsg(pCxt, TSDB_CODE_PAR_INVALID_COLUMN, (*pCol)->colName);
|
||||
} else {
|
||||
res = translateColumnWithoutPrefix(pCxt, pCol);
|
||||
|
@ -760,9 +778,9 @@ static int32_t parseBoolFromValueNode(STranslateContext* pCxt, SValueNode* pVal)
|
|||
}
|
||||
|
||||
static EDealRes translateValueImpl(STranslateContext* pCxt, SValueNode* pVal, SDataType targetDt) {
|
||||
uint8_t precision = (NULL != pCxt->pCurrSelectStmt ? pCxt->pCurrSelectStmt->precision : targetDt.precision);
|
||||
uint8_t precision = getPrecisionFromCurrStmt(pCxt->pCurrStmt, targetDt.precision);
|
||||
pVal->node.resType.precision = precision;
|
||||
if (pVal->placeholderNo > 0) {
|
||||
if (pVal->placeholderNo > 0 || pVal->isNull) {
|
||||
return DEAL_RES_CONTINUE;
|
||||
}
|
||||
if (pVal->isDuration) {
|
||||
|
@ -1102,6 +1120,8 @@ static bool hasInvalidFuncNesting(SNodeList* pParameterList) {
|
|||
}
|
||||
|
||||
static int32_t getFuncInfo(STranslateContext* pCxt, SFunctionNode* pFunc) {
|
||||
// the time precision of the function execution environment
|
||||
pFunc->node.resType.precision = getPrecisionFromCurrStmt(pCxt->pCurrStmt, TSDB_TIME_PRECISION_MILLI);
|
||||
int32_t code = fmGetFuncInfo(pFunc, pCxt->msgBuf.buf, pCxt->msgBuf.len);
|
||||
if (TSDB_CODE_FUNC_NOT_BUILTIN_FUNTION == code) {
|
||||
code = getUdfInfo(pCxt, pFunc);
|
||||
|
@ -1119,7 +1139,7 @@ static int32_t translateAggFunc(STranslateContext* pCxt, SFunctionNode* pFunc) {
|
|||
if (hasInvalidFuncNesting(pFunc->pParameterList)) {
|
||||
return generateSyntaxErrMsg(&pCxt->msgBuf, TSDB_CODE_PAR_AGG_FUNC_NESTING);
|
||||
}
|
||||
if (NULL != pCxt->pCurrSelectStmt && pCxt->pCurrSelectStmt->hasIndefiniteRowsFunc) {
|
||||
if (isSelectStmt(pCxt->pCurrStmt) && ((SSelectStmt*)pCxt->pCurrStmt)->hasIndefiniteRowsFunc) {
|
||||
return generateSyntaxErrMsg(&pCxt->msgBuf, TSDB_CODE_PAR_NOT_ALLOWED_FUNC);
|
||||
}
|
||||
|
||||
|
@ -1134,7 +1154,8 @@ static int32_t translateScanPseudoColumnFunc(STranslateContext* pCxt, SFunctionN
|
|||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
if (0 == LIST_LENGTH(pFunc->pParameterList)) {
|
||||
if (QUERY_NODE_REAL_TABLE != nodeType(pCxt->pCurrSelectStmt->pFromTable)) {
|
||||
if (!isSelectStmt(pCxt->pCurrStmt) ||
|
||||
QUERY_NODE_REAL_TABLE != nodeType(((SSelectStmt*)pCxt->pCurrStmt)->pFromTable)) {
|
||||
return generateSyntaxErrMsg(&pCxt->msgBuf, TSDB_CODE_PAR_INVALID_TBNAME);
|
||||
}
|
||||
} else {
|
||||
|
@ -1152,8 +1173,8 @@ static int32_t translateIndefiniteRowsFunc(STranslateContext* pCxt, SFunctionNod
|
|||
if (!fmIsIndefiniteRowsFunc(pFunc->funcId)) {
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
if (SQL_CLAUSE_SELECT != pCxt->currClause || pCxt->pCurrSelectStmt->hasIndefiniteRowsFunc ||
|
||||
pCxt->pCurrSelectStmt->hasAggFuncs) {
|
||||
if (!isSelectStmt(pCxt->pCurrStmt) || SQL_CLAUSE_SELECT != pCxt->currClause ||
|
||||
((SSelectStmt*)pCxt->pCurrStmt)->hasIndefiniteRowsFunc || ((SSelectStmt*)pCxt->pCurrStmt)->hasAggFuncs) {
|
||||
return generateSyntaxErrMsg(&pCxt->msgBuf, TSDB_CODE_PAR_NOT_ALLOWED_FUNC);
|
||||
}
|
||||
if (hasInvalidFuncNesting(pFunc->pParameterList)) {
|
||||
|
@ -1162,13 +1183,20 @@ static int32_t translateIndefiniteRowsFunc(STranslateContext* pCxt, SFunctionNod
|
|||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
static bool hasFillClause(SNode* pCurrStmt) {
|
||||
if (!isSelectStmt(pCurrStmt)) {
|
||||
return false;
|
||||
}
|
||||
SSelectStmt* pSelect = (SSelectStmt*)pCurrStmt;
|
||||
return NULL != pSelect->pWindow && QUERY_NODE_INTERVAL_WINDOW == nodeType(pSelect->pWindow) &&
|
||||
NULL != ((SIntervalWindowNode*)pSelect->pWindow)->pFill;
|
||||
}
|
||||
|
||||
static int32_t translateForbidFillFunc(STranslateContext* pCxt, SFunctionNode* pFunc) {
|
||||
if (!fmIsForbidFillFunc(pFunc->funcId)) {
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
if (NULL != pCxt->pCurrSelectStmt->pWindow &&
|
||||
QUERY_NODE_INTERVAL_WINDOW == nodeType(pCxt->pCurrSelectStmt->pWindow) &&
|
||||
NULL != ((SIntervalWindowNode*)pCxt->pCurrSelectStmt->pWindow)->pFill) {
|
||||
if (hasFillClause(pCxt->pCurrStmt)) {
|
||||
return generateSyntaxErrMsg(&pCxt->msgBuf, TSDB_CODE_PAR_FILL_NOT_ALLOWED_FUNC, pFunc->functionName);
|
||||
}
|
||||
return TSDB_CODE_SUCCESS;
|
||||
|
@ -1178,7 +1206,7 @@ static int32_t translateWindowPseudoColumnFunc(STranslateContext* pCxt, SFunctio
|
|||
if (!fmIsWindowPseudoColumnFunc(pFunc->funcId)) {
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
if (NULL == pCxt->pCurrSelectStmt->pWindow) {
|
||||
if (!isSelectStmt(pCxt->pCurrStmt) || NULL == ((SSelectStmt*)pCxt->pCurrStmt)->pWindow) {
|
||||
return generateSyntaxErrMsg(&pCxt->msgBuf, TSDB_CODE_PAR_INVALID_WINDOW_PC);
|
||||
}
|
||||
return TSDB_CODE_SUCCESS;
|
||||
|
@ -1188,7 +1216,7 @@ static int32_t translateForbidWindowFunc(STranslateContext* pCxt, SFunctionNode*
|
|||
if (!fmIsForbidWindowFunc(pFunc->funcId)) {
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
if (NULL != pCxt->pCurrSelectStmt->pWindow) {
|
||||
if (isSelectStmt(pCxt->pCurrStmt) && NULL != ((SSelectStmt*)pCxt->pCurrStmt)->pWindow) {
|
||||
return generateSyntaxErrMsg(&pCxt->msgBuf, TSDB_CODE_PAR_WINDOW_NOT_ALLOWED_FUNC, pFunc->functionName);
|
||||
}
|
||||
return TSDB_CODE_SUCCESS;
|
||||
|
@ -1208,14 +1236,15 @@ static int32_t translateForbidGroupByFunc(STranslateContext* pCxt, SFunctionNode
|
|||
if (!fmIsForbidGroupByFunc(pFunc->funcId)) {
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
if (NULL != pCxt->pCurrSelectStmt->pGroupByList) {
|
||||
if (isSelectStmt(pCxt->pCurrStmt) && NULL != ((SSelectStmt*)pCxt->pCurrStmt)->pGroupByList) {
|
||||
return generateSyntaxErrMsg(&pCxt->msgBuf, TSDB_CODE_PAR_GROUP_BY_NOT_ALLOWED_FUNC, pFunc->functionName);
|
||||
}
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
static void setFuncClassification(SSelectStmt* pSelect, SFunctionNode* pFunc) {
|
||||
if (NULL != pSelect) {
|
||||
static void setFuncClassification(SNode* pCurrStmt, SFunctionNode* pFunc) {
|
||||
if (NULL != pCurrStmt && QUERY_NODE_SELECT_STMT == nodeType(pCurrStmt)) {
|
||||
SSelectStmt* pSelect = (SSelectStmt*)pCurrStmt;
|
||||
pSelect->hasAggFuncs = pSelect->hasAggFuncs ? true : fmIsAggFunc(pFunc->funcId);
|
||||
pSelect->hasRepeatScanFuncs = pSelect->hasRepeatScanFuncs ? true : fmIsRepeatScanFunc(pFunc->funcId);
|
||||
pSelect->hasIndefiniteRowsFunc = pSelect->hasIndefiniteRowsFunc ? true : fmIsIndefiniteRowsFunc(pFunc->funcId);
|
||||
|
@ -1226,41 +1255,138 @@ static void setFuncClassification(SSelectStmt* pSelect, SFunctionNode* pFunc) {
|
|||
}
|
||||
}
|
||||
|
||||
static EDealRes translateFunction(STranslateContext* pCxt, SFunctionNode* pFunc) {
|
||||
static int32_t rewriteSystemInfoFuncImpl(STranslateContext* pCxt, char* pLiteral, SNode** pNode) {
|
||||
SValueNode* pVal = (SValueNode*)nodesMakeNode(QUERY_NODE_VALUE);
|
||||
if (NULL == pVal) {
|
||||
return TSDB_CODE_OUT_OF_MEMORY;
|
||||
}
|
||||
strcpy(pVal->node.aliasName, ((SExprNode*)*pNode)->aliasName);
|
||||
pVal->node.resType = ((SExprNode*)*pNode)->resType;
|
||||
if (NULL == pLiteral) {
|
||||
pVal->isNull = true;
|
||||
} else {
|
||||
pVal->literal = pLiteral;
|
||||
}
|
||||
if (DEAL_RES_ERROR != translateValue(pCxt, pVal)) {
|
||||
*pNode = (SNode*)pVal;
|
||||
} else {
|
||||
nodesDestroyNode((SNode*)pVal);
|
||||
}
|
||||
return pCxt->errCode;
|
||||
}
|
||||
|
||||
static int32_t rewriteDatabaseFunc(STranslateContext* pCxt, SNode** pNode) {
|
||||
char* pCurrDb = NULL;
|
||||
if (NULL != pCxt->pParseCxt->db) {
|
||||
pCurrDb = taosMemoryStrDup((void*)pCxt->pParseCxt->db);
|
||||
if (NULL == pCurrDb) {
|
||||
return TSDB_CODE_OUT_OF_MEMORY;
|
||||
}
|
||||
}
|
||||
return rewriteSystemInfoFuncImpl(pCxt, pCurrDb, pNode);
|
||||
}
|
||||
|
||||
static int32_t rewriteClentVersionFunc(STranslateContext* pCxt, SNode** pNode) {
|
||||
char* pVer = taosMemoryStrDup((void*)version);
|
||||
if (NULL == pVer) {
|
||||
return TSDB_CODE_OUT_OF_MEMORY;
|
||||
}
|
||||
return rewriteSystemInfoFuncImpl(pCxt, pVer, pNode);
|
||||
}
|
||||
|
||||
static int32_t rewriteServerVersionFunc(STranslateContext* pCxt, SNode** pNode) {
|
||||
char* pVer = taosMemoryStrDup((void*)pCxt->pParseCxt->svrVer);
|
||||
if (NULL == pVer) {
|
||||
return TSDB_CODE_OUT_OF_MEMORY;
|
||||
}
|
||||
return rewriteSystemInfoFuncImpl(pCxt, pVer, pNode);
|
||||
}
|
||||
|
||||
static int32_t rewriteServerStatusFunc(STranslateContext* pCxt, SNode** pNode) {
|
||||
if (pCxt->pParseCxt->nodeOffline) {
|
||||
return TSDB_CODE_RPC_NETWORK_UNAVAIL;
|
||||
}
|
||||
char* pStatus = taosMemoryStrDup((void*)"1");
|
||||
return rewriteSystemInfoFuncImpl(pCxt, pStatus, pNode);
|
||||
}
|
||||
|
||||
static int32_t rewriteUserFunc(STranslateContext* pCxt, SNode** pNode) {
|
||||
char userConn[TSDB_USER_LEN + 1 + TSDB_FQDN_LEN] = {0}; // format 'user@host'
|
||||
int32_t len = snprintf(userConn, sizeof(userConn), "%s@", pCxt->pParseCxt->pUser);
|
||||
taosGetFqdn(userConn + len);
|
||||
char* pUserConn = taosMemoryStrDup((void*)userConn);
|
||||
if (NULL == pUserConn) {
|
||||
return TSDB_CODE_OUT_OF_MEMORY;
|
||||
}
|
||||
return rewriteSystemInfoFuncImpl(pCxt, pUserConn, pNode);
|
||||
}
|
||||
|
||||
static int32_t rewriteSystemInfoFunc(STranslateContext* pCxt, SNode** pNode) {
|
||||
switch (((SFunctionNode*)*pNode)->funcType) {
|
||||
case FUNCTION_TYPE_DATABASE:
|
||||
return rewriteDatabaseFunc(pCxt, pNode);
|
||||
case FUNCTION_TYPE_CLIENT_VERSION:
|
||||
return rewriteClentVersionFunc(pCxt, pNode);
|
||||
case FUNCTION_TYPE_SERVER_VERSION:
|
||||
return rewriteServerVersionFunc(pCxt, pNode);
|
||||
case FUNCTION_TYPE_SERVER_STATUS:
|
||||
return rewriteServerStatusFunc(pCxt, pNode);
|
||||
case FUNCTION_TYPE_CURRENT_USER:
|
||||
case FUNCTION_TYPE_USER:
|
||||
return rewriteUserFunc(pCxt, pNode);
|
||||
default:
|
||||
break;
|
||||
}
|
||||
return TSDB_CODE_PAR_INTERNAL_ERROR;
|
||||
}
|
||||
|
||||
static int32_t translateNoramlFunction(STranslateContext* pCxt, SFunctionNode* pFunc) {
|
||||
int32_t code = translateAggFunc(pCxt, pFunc);
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
code = translateScanPseudoColumnFunc(pCxt, pFunc);
|
||||
}
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
code = translateIndefiniteRowsFunc(pCxt, pFunc);
|
||||
}
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
code = translateForbidFillFunc(pCxt, pFunc);
|
||||
}
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
code = translateWindowPseudoColumnFunc(pCxt, pFunc);
|
||||
}
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
code = translateForbidWindowFunc(pCxt, pFunc);
|
||||
}
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
code = translateForbidStreamFunc(pCxt, pFunc);
|
||||
}
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
code = translateForbidGroupByFunc(pCxt, pFunc);
|
||||
}
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
setFuncClassification(pCxt->pCurrStmt, pFunc);
|
||||
}
|
||||
return code;
|
||||
}
|
||||
|
||||
static int32_t translateFunctionImpl(STranslateContext* pCxt, SFunctionNode** pFunc) {
|
||||
if (fmIsSystemInfoFunc((*pFunc)->funcId)) {
|
||||
return rewriteSystemInfoFunc(pCxt, (SNode**)pFunc);
|
||||
}
|
||||
return translateNoramlFunction(pCxt, *pFunc);
|
||||
}
|
||||
|
||||
static EDealRes translateFunction(STranslateContext* pCxt, SFunctionNode** pFunc) {
|
||||
SNode* pParam = NULL;
|
||||
FOREACH(pParam, pFunc->pParameterList) {
|
||||
FOREACH(pParam, (*pFunc)->pParameterList) {
|
||||
if (isMultiResFunc(pParam)) {
|
||||
return generateDealNodeErrMsg(pCxt, TSDB_CODE_PAR_WRONG_VALUE_TYPE, ((SExprNode*)pParam)->aliasName);
|
||||
}
|
||||
}
|
||||
|
||||
pCxt->errCode = getFuncInfo(pCxt, pFunc);
|
||||
pCxt->errCode = getFuncInfo(pCxt, *pFunc);
|
||||
if (TSDB_CODE_SUCCESS == pCxt->errCode) {
|
||||
pCxt->errCode = translateAggFunc(pCxt, pFunc);
|
||||
}
|
||||
if (TSDB_CODE_SUCCESS == pCxt->errCode) {
|
||||
pCxt->errCode = translateScanPseudoColumnFunc(pCxt, pFunc);
|
||||
}
|
||||
if (TSDB_CODE_SUCCESS == pCxt->errCode) {
|
||||
pCxt->errCode = translateIndefiniteRowsFunc(pCxt, pFunc);
|
||||
}
|
||||
if (TSDB_CODE_SUCCESS == pCxt->errCode) {
|
||||
pCxt->errCode = translateForbidFillFunc(pCxt, pFunc);
|
||||
}
|
||||
if (TSDB_CODE_SUCCESS == pCxt->errCode) {
|
||||
pCxt->errCode = translateWindowPseudoColumnFunc(pCxt, pFunc);
|
||||
}
|
||||
if (TSDB_CODE_SUCCESS == pCxt->errCode) {
|
||||
pCxt->errCode = translateForbidWindowFunc(pCxt, pFunc);
|
||||
}
|
||||
if (TSDB_CODE_SUCCESS == pCxt->errCode) {
|
||||
pCxt->errCode = translateForbidStreamFunc(pCxt, pFunc);
|
||||
}
|
||||
if (TSDB_CODE_SUCCESS == pCxt->errCode) {
|
||||
pCxt->errCode = translateForbidGroupByFunc(pCxt, pFunc);
|
||||
}
|
||||
if (TSDB_CODE_SUCCESS == pCxt->errCode) {
|
||||
setFuncClassification(pCxt->pCurrSelectStmt, pFunc);
|
||||
pCxt->errCode = translateFunctionImpl(pCxt, pFunc);
|
||||
}
|
||||
return TSDB_CODE_SUCCESS == pCxt->errCode ? DEAL_RES_CONTINUE : DEAL_RES_ERROR;
|
||||
}
|
||||
|
@ -1285,7 +1411,7 @@ static EDealRes doTranslateExpr(SNode** pNode, void* pContext) {
|
|||
case QUERY_NODE_OPERATOR:
|
||||
return translateOperator(pCxt, (SOperatorNode**)pNode);
|
||||
case QUERY_NODE_FUNCTION:
|
||||
return translateFunction(pCxt, (SFunctionNode*)*pNode);
|
||||
return translateFunction(pCxt, (SFunctionNode**)pNode);
|
||||
case QUERY_NODE_LOGIC_CONDITION:
|
||||
return translateLogicCond(pCxt, (SLogicConditionNode*)*pNode);
|
||||
case QUERY_NODE_TEMP_TABLE:
|
||||
|
@ -1308,9 +1434,9 @@ static int32_t translateExprList(STranslateContext* pCxt, SNodeList* pList) {
|
|||
|
||||
static SNodeList* getGroupByList(STranslateContext* pCxt) {
|
||||
if (isDistinctOrderBy(pCxt)) {
|
||||
return pCxt->pCurrSelectStmt->pProjectionList;
|
||||
return ((SSelectStmt*)pCxt->pCurrStmt)->pProjectionList;
|
||||
}
|
||||
return pCxt->pCurrSelectStmt->pGroupByList;
|
||||
return ((SSelectStmt*)pCxt->pCurrStmt)->pGroupByList;
|
||||
}
|
||||
|
||||
static SNode* getGroupByNode(SNode* pNode) {
|
||||
|
@ -1348,7 +1474,7 @@ static EDealRes rewriteColToSelectValFunc(STranslateContext* pCxt, SNode** pNode
|
|||
}
|
||||
if (TSDB_CODE_SUCCESS == pCxt->errCode) {
|
||||
*pNode = (SNode*)pFunc;
|
||||
pCxt->pCurrSelectStmt->hasSelectValFunc = true;
|
||||
((SSelectStmt*)pCxt->pCurrStmt)->hasSelectValFunc = true;
|
||||
} else {
|
||||
nodesDestroyNode((SNode*)pFunc);
|
||||
}
|
||||
|
@ -1378,7 +1504,7 @@ static EDealRes doCheckExprForGroupBy(SNode** pNode, void* pContext) {
|
|||
}
|
||||
}
|
||||
SNode* pPartKey = NULL;
|
||||
FOREACH(pPartKey, pCxt->pTranslateCxt->pCurrSelectStmt->pPartitionByList) {
|
||||
FOREACH(pPartKey, ((SSelectStmt*)pCxt->pTranslateCxt->pCurrStmt)->pPartitionByList) {
|
||||
if (nodesEqualNode(pPartKey, *pNode)) {
|
||||
return DEAL_RES_IGNORE_CHILD;
|
||||
}
|
||||
|
@ -1463,7 +1589,7 @@ static EDealRes doCheckAggColCoexist(SNode* pNode, void* pContext) {
|
|||
return DEAL_RES_IGNORE_CHILD;
|
||||
}
|
||||
SNode* pPartKey = NULL;
|
||||
FOREACH(pPartKey, pCxt->pTranslateCxt->pCurrSelectStmt->pPartitionByList) {
|
||||
FOREACH(pPartKey, ((SSelectStmt*)pCxt->pTranslateCxt->pCurrStmt)->pPartitionByList) {
|
||||
if (nodesEqualNode(pPartKey, pNode)) {
|
||||
return DEAL_RES_IGNORE_CHILD;
|
||||
}
|
||||
|
@ -1627,7 +1753,8 @@ static uint8_t getStmtPrecision(SNode* pStmt) {
|
|||
|
||||
static bool stmtIsSingleTable(SNode* pStmt) {
|
||||
if (QUERY_NODE_SELECT_STMT == nodeType(pStmt)) {
|
||||
return ((STableNode*)((SSelectStmt*)pStmt)->pFromTable)->singleTable;
|
||||
SSelectStmt* pSelect = (SSelectStmt*)pStmt;
|
||||
return NULL == pSelect->pFromTable || ((STableNode*)pSelect->pFromTable)->singleTable;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
@ -1655,8 +1782,8 @@ static int32_t setTableIndex(STranslateContext* pCxt, SName* pName, SRealTableNo
|
|||
if (pCxt->createStream || QUERY_SMA_OPTIMIZE_DISABLE == tsQuerySmaOptimize) {
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
if (NULL != pCxt->pCurrSelectStmt && NULL != pCxt->pCurrSelectStmt->pWindow &&
|
||||
QUERY_NODE_INTERVAL_WINDOW == nodeType(pCxt->pCurrSelectStmt->pWindow)) {
|
||||
if (isSelectStmt(pCxt->pCurrStmt) && NULL != ((SSelectStmt*)pCxt->pCurrStmt)->pWindow &&
|
||||
QUERY_NODE_INTERVAL_WINDOW == nodeType(((SSelectStmt*)pCxt->pCurrStmt)->pWindow)) {
|
||||
return getTableIndex(pCxt, pName, &pRealTable->pSmaIndexes);
|
||||
}
|
||||
return TSDB_CODE_SUCCESS;
|
||||
|
@ -2369,7 +2496,7 @@ static EDealRes rewriteSeletcValueFunc(STranslateContext* pCxt, SNode** pNode) {
|
|||
nodesDestroyNode(*pNode);
|
||||
*pNode = (SNode*)pFirst;
|
||||
pCxt->errCode = fmGetFuncInfo(pFirst, pCxt->msgBuf.buf, pCxt->msgBuf.len);
|
||||
pCxt->pCurrSelectStmt->hasAggFuncs = true;
|
||||
((SSelectStmt*)pCxt->pCurrStmt)->hasAggFuncs = true;
|
||||
return TSDB_CODE_SUCCESS == pCxt->errCode ? DEAL_RES_IGNORE_CHILD : DEAL_RES_ERROR;
|
||||
}
|
||||
|
||||
|
@ -2408,13 +2535,13 @@ static int32_t replaceOrderByAlias(STranslateContext* pCxt, SNodeList* pProjecti
|
|||
}
|
||||
|
||||
static int32_t translateSelectWithoutFrom(STranslateContext* pCxt, SSelectStmt* pSelect) {
|
||||
pCxt->pCurrSelectStmt = pSelect;
|
||||
pCxt->pCurrStmt = (SNode*)pSelect;
|
||||
pCxt->currClause = SQL_CLAUSE_SELECT;
|
||||
return translateExprList(pCxt, pSelect->pProjectionList);
|
||||
}
|
||||
|
||||
static int32_t translateSelectFrom(STranslateContext* pCxt, SSelectStmt* pSelect) {
|
||||
pCxt->pCurrSelectStmt = pSelect;
|
||||
pCxt->pCurrStmt = (SNode*)pSelect;
|
||||
int32_t code = translateFrom(pCxt, pSelect->pFromTable);
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
pSelect->precision = ((STableNode*)pSelect->pFromTable)->precision;
|
||||
|
@ -2538,8 +2665,7 @@ static int32_t translateSetOperOrderBy(STranslateContext* pCxt, SSetOperator* pS
|
|||
if (TSDB_CODE_SUCCESS == code) {
|
||||
if (other) {
|
||||
pCxt->currClause = SQL_CLAUSE_ORDER_BY;
|
||||
pCxt->pCurrSelectStmt = NULL;
|
||||
pCxt->pCurrSetOperator = pSetOperator;
|
||||
pCxt->pCurrStmt = (SNode*)pSetOperator;
|
||||
code = translateExprList(pCxt, pSetOperator->pOrderByList);
|
||||
}
|
||||
}
|
||||
|
@ -4420,11 +4546,11 @@ static int32_t translateQuery(STranslateContext* pCxt, SNode* pNode) {
|
|||
static int32_t translateSubquery(STranslateContext* pCxt, SNode* pNode) {
|
||||
++(pCxt->currLevel);
|
||||
ESqlClause currClause = pCxt->currClause;
|
||||
SSelectStmt* pCurrStmt = pCxt->pCurrSelectStmt;
|
||||
SNode* pCurrStmt = pCxt->pCurrStmt;
|
||||
int32_t code = translateQuery(pCxt, pNode);
|
||||
--(pCxt->currLevel);
|
||||
pCxt->currClause = currClause;
|
||||
pCxt->pCurrSelectStmt = pCurrStmt;
|
||||
pCxt->pCurrStmt = pCurrStmt;
|
||||
return code;
|
||||
}
|
||||
|
||||
|
@ -5876,6 +6002,11 @@ static int32_t setRefreshMate(STranslateContext* pCxt, SQuery* pQuery) {
|
|||
static int32_t setQuery(STranslateContext* pCxt, SQuery* pQuery) {
|
||||
switch (nodeType(pQuery->pRoot)) {
|
||||
case QUERY_NODE_SELECT_STMT:
|
||||
if (NULL == ((SSelectStmt*)pQuery->pRoot)->pFromTable) {
|
||||
pQuery->execMode = QUERY_EXEC_MODE_LOCAL;
|
||||
pQuery->haveResultSet = true;
|
||||
break;
|
||||
}
|
||||
case QUERY_NODE_SET_OPERATOR:
|
||||
case QUERY_NODE_EXPLAIN_STMT:
|
||||
pQuery->execMode = QUERY_EXEC_MODE_SCHEDULE;
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -265,6 +265,11 @@ TEST_F(InsertTest, autoCreateTableTest) {
|
|||
"insert into st1s1 using st1 (tag1, tag2) tags(1, 'wxy') values (now, 1, \"beijing\")"
|
||||
"(now+1s, 2, \"shanghai\")(now+2s, 3, \"guangzhou\")");
|
||||
ASSERT_EQ(runAsync(), TSDB_CODE_SUCCESS);
|
||||
|
||||
bind(
|
||||
"insert into st1s1 using st1 tags(1, 'wxy', now) values (now, 1, \"beijing\")"
|
||||
"st1s1 using st1 tags(1, 'wxy', now) values (now+1s, 2, \"shanghai\")");
|
||||
ASSERT_EQ(run(), TSDB_CODE_SUCCESS);
|
||||
}
|
||||
|
||||
TEST_F(InsertTest, toleranceTest) {
|
||||
|
|
|
@ -423,6 +423,18 @@ TEST_F(ParserSelectTest, withoutFrom) {
|
|||
useDb("root", "test");
|
||||
|
||||
run("SELECT 1");
|
||||
|
||||
run("SELECT DATABASE()");
|
||||
|
||||
run("SELECT CLIENT_VERSION()");
|
||||
|
||||
run("SELECT SERVER_VERSION()");
|
||||
|
||||
run("SELECT SERVER_STATUS()");
|
||||
|
||||
run("SELECT CURRENT_USER()");
|
||||
|
||||
run("SELECT USER()");
|
||||
}
|
||||
|
||||
} // namespace ParserTest
|
||||
|
|
|
@ -203,6 +203,7 @@ class ParserTestBaseImpl {
|
|||
pCxt->pMsg = stmtEnv_.msgBuf_.data();
|
||||
pCxt->msgLen = stmtEnv_.msgBuf_.max_size();
|
||||
pCxt->async = async;
|
||||
pCxt->svrVer = "3.0.0.0";
|
||||
}
|
||||
|
||||
void doParse(SParseContext* pCxt, SQuery** pQuery) {
|
||||
|
|
|
@ -276,7 +276,8 @@ static int32_t pushDownCondOptAppendCond(SNode** pCond, SNode** pAdditionalCond)
|
|||
}
|
||||
|
||||
int32_t code = TSDB_CODE_SUCCESS;
|
||||
if (QUERY_NODE_LOGIC_CONDITION == nodeType(*pCond)) {
|
||||
if (QUERY_NODE_LOGIC_CONDITION == nodeType(*pCond) &&
|
||||
LOGIC_COND_TYPE_AND == ((SLogicConditionNode*)*pCond)->condType) {
|
||||
code = nodesListAppend(((SLogicConditionNode*)*pCond)->pParameterList, *pAdditionalCond);
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
*pAdditionalCond = NULL;
|
||||
|
@ -1083,6 +1084,11 @@ static int32_t partTagsOptRebuildTbanme(SNodeList* pPartKeys) {
|
|||
return code;
|
||||
}
|
||||
|
||||
// todo refact: just to mask compilation warnings
|
||||
static void partTagsSetAlias(char* pAlias, int32_t len, const char* pTableAlias, const char* pColName) {
|
||||
snprintf(pAlias, len, "%s.%s", pTableAlias, pColName);
|
||||
}
|
||||
|
||||
static SNode* partTagsCreateWrapperFunc(const char* pFuncName, SNode* pNode) {
|
||||
SFunctionNode* pFunc = (SFunctionNode*)nodesMakeNode(QUERY_NODE_FUNCTION);
|
||||
if (NULL == pFunc) {
|
||||
|
@ -1092,7 +1098,7 @@ static SNode* partTagsCreateWrapperFunc(const char* pFuncName, SNode* pNode) {
|
|||
strcpy(pFunc->functionName, pFuncName);
|
||||
if (QUERY_NODE_COLUMN == nodeType(pNode)) {
|
||||
SColumnNode* pCol = (SColumnNode*)pNode;
|
||||
sprintf(pFunc->node.aliasName, "%s.%s", pCol->tableAlias, pCol->colName);
|
||||
partTagsSetAlias(pFunc->node.aliasName, sizeof(pFunc->node.aliasName), pCol->tableAlias, pCol->colName);
|
||||
} else {
|
||||
strcpy(pFunc->node.aliasName, ((SExprNode*)pNode)->aliasName);
|
||||
}
|
||||
|
@ -1464,9 +1470,9 @@ static SNode* rewriteUniqueOptCreateFirstFunc(SFunctionNode* pSelectValue, SNode
|
|||
|
||||
strcpy(pFunc->functionName, "first");
|
||||
if (NULL != pSelectValue) {
|
||||
sprintf(pFunc->node.aliasName, "%s", pSelectValue->node.aliasName);
|
||||
strcpy(pFunc->node.aliasName, pSelectValue->node.aliasName);
|
||||
} else {
|
||||
sprintf(pFunc->node.aliasName, "%s.%p", pFunc->functionName, pFunc);
|
||||
snprintf(pFunc->node.aliasName, sizeof(pFunc->node.aliasName), "%s.%p", pFunc->functionName, pFunc);
|
||||
}
|
||||
int32_t code = nodesListMakeStrictAppend(&pFunc->pParameterList, nodesCloneNode(pCol));
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
|
|
|
@ -85,11 +85,23 @@ int32_t qSetSubplanExecutionNode(SSubplan* subplan, int32_t groupId, SDownstream
|
|||
return setSubplanExecutionNode(subplan->pNode, groupId, pSource);
|
||||
}
|
||||
|
||||
int32_t qClearSubplanExecutionNode(SSubplan* pSubplan, int32_t groupId) {
|
||||
// todo
|
||||
return TSDB_CODE_FAILED;
|
||||
static void clearSubplanExecutionNode(SPhysiNode* pNode) {
|
||||
if (QUERY_NODE_PHYSICAL_PLAN_EXCHANGE == nodeType(pNode)) {
|
||||
SExchangePhysiNode* pExchange = (SExchangePhysiNode*)pNode;
|
||||
NODES_DESTORY_LIST(pExchange->pSrcEndPoints);
|
||||
} else if (QUERY_NODE_PHYSICAL_PLAN_MERGE == nodeType(pNode)) {
|
||||
SMergePhysiNode* pMerge = (SMergePhysiNode*)pNode;
|
||||
pMerge->numOfChannels = LIST_LENGTH(pMerge->node.pChildren);
|
||||
SNode* pChild = NULL;
|
||||
FOREACH(pChild, pMerge->node.pChildren) { NODES_DESTORY_LIST(((SExchangePhysiNode*)pChild)->pSrcEndPoints); }
|
||||
}
|
||||
|
||||
SNode* pChild = NULL;
|
||||
FOREACH(pChild, pNode->pChildren) { clearSubplanExecutionNode((SPhysiNode*)pChild); }
|
||||
}
|
||||
|
||||
void qClearSubplanExecutionNode(SSubplan* pSubplan) { clearSubplanExecutionNode(pSubplan->pNode); }
|
||||
|
||||
int32_t qSubPlanToString(const SSubplan* pSubplan, char** pStr, int32_t* pLen) {
|
||||
if (SUBPLAN_TYPE_MODIFY == pSubplan->subplanType && NULL == pSubplan->pNode) {
|
||||
SDataInserterNode* insert = (SDataInserterNode*)pSubplan->pDataSink;
|
||||
|
|
|
@ -310,6 +310,7 @@ class PlannerTestBaseImpl {
|
|||
cxt.sqlLen = stmtEnv_.sql_.length();
|
||||
cxt.pMsg = stmtEnv_.msgBuf_.data();
|
||||
cxt.msgLen = stmtEnv_.msgBuf_.max_size();
|
||||
cxt.svrVer = "3.0.0.0";
|
||||
|
||||
DO_WITH_THROW(qParseSql, &cxt, pQuery);
|
||||
if (prepare) {
|
||||
|
|
|
@ -420,7 +420,7 @@ int32_t cloneDbVgInfo(SDBVgInfo* pSrc, SDBVgInfo** pDst) {
|
|||
taosHashCancelIterate(pSrc->vgHash, pIter);
|
||||
taosHashCleanup((*pDst)->vgHash);
|
||||
taosMemoryFreeClear(*pDst);
|
||||
return TSDB_CODE_CTG_MEM_ERROR;
|
||||
return TSDB_CODE_OUT_OF_MEMORY;
|
||||
}
|
||||
|
||||
pIter = taosHashIterate(pSrc->vgHash, pIter);
|
||||
|
|
|
@ -936,6 +936,25 @@ EDealRes sclCalcWalker(SNode* pNode, void* pContext) {
|
|||
return DEAL_RES_ERROR;
|
||||
}
|
||||
|
||||
int32_t sclExtendResRows(SScalarParam *pDst, SScalarParam *pSrc, SArray *pBlockList) {
|
||||
SSDataBlock* pb = taosArrayGetP(pBlockList, 0);
|
||||
SScalarParam *pLeft = taosMemoryCalloc(1, sizeof(SScalarParam));
|
||||
if (NULL == pLeft) {
|
||||
sclError("calloc %d failed", (int32_t)sizeof(SScalarParam));
|
||||
SCL_ERR_RET(TSDB_CODE_QRY_OUT_OF_MEMORY);
|
||||
}
|
||||
|
||||
pLeft->numOfRows = pb->info.rows;
|
||||
colInfoDataEnsureCapacity(pDst->columnData, pb->info.rows);
|
||||
|
||||
_bin_scalar_fn_t OperatorFn = getBinScalarOperatorFn(OP_TYPE_ASSIGN);
|
||||
OperatorFn(pLeft, pSrc, pDst, TSDB_ORDER_ASC);
|
||||
|
||||
taosMemoryFree(pLeft);
|
||||
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
int32_t scalarCalculateConstants(SNode *pNode, SNode **pRes) {
|
||||
if (NULL == pNode) {
|
||||
SCL_ERR_RET(TSDB_CODE_QRY_INVALID_INPUT);
|
||||
|
@ -983,9 +1002,14 @@ int32_t scalarCalculate(SNode *pNode, SArray *pBlockList, SScalarParam *pDst) {
|
|||
SCL_ERR_JRET(TSDB_CODE_QRY_APP_ERROR);
|
||||
}
|
||||
|
||||
if (1 == res->numOfRows) {
|
||||
SCL_ERR_JRET(sclExtendResRows(pDst, res, pBlockList));
|
||||
} else {
|
||||
colInfoDataEnsureCapacity(pDst->columnData, res->numOfRows);
|
||||
colDataAssign(pDst->columnData, res->columnData, res->numOfRows, NULL);
|
||||
pDst->numOfRows = res->numOfRows;
|
||||
}
|
||||
|
||||
taosHashRemove(ctx.pRes, (void *)&pNode, POINTER_BYTES);
|
||||
}
|
||||
|
||||
|
|
|
@ -1192,10 +1192,10 @@ int32_t toJsonFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam *pOu
|
|||
|
||||
int32_t timeTruncateFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam *pOutput) {
|
||||
int32_t type = GET_PARAM_TYPE(&pInput[0]);
|
||||
int32_t timePrec = GET_PARAM_PRECISON(&pInput[0]);
|
||||
|
||||
int64_t timeUnit, timeVal = 0;
|
||||
int64_t timeUnit, timePrec, timeVal = 0;
|
||||
GET_TYPED_DATA(timeUnit, int64_t, GET_PARAM_TYPE(&pInput[1]), pInput[1].columnData->pData);
|
||||
GET_TYPED_DATA(timePrec, int64_t, GET_PARAM_TYPE(&pInput[2]), pInput[2].columnData->pData);
|
||||
|
||||
int64_t factor = (timePrec == TSDB_TIME_PRECISION_MILLI) ? 1000 :
|
||||
(timePrec == TSDB_TIME_PRECISION_MICRO ? 1000000 : 1000000000);
|
||||
|
@ -1380,10 +1380,12 @@ int32_t timeTruncateFunction(SScalarParam *pInput, int32_t inputNum, SScalarPara
|
|||
}
|
||||
|
||||
int32_t timeDiffFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam *pOutput) {
|
||||
int32_t timePrec = GET_PARAM_PRECISON(&pInput[0]);
|
||||
int64_t timeUnit = -1, timeVal[2] = {0};
|
||||
if (inputNum == 3) {
|
||||
int64_t timeUnit = -1, timePrec, timeVal[2] = {0};
|
||||
if (inputNum == 4) {
|
||||
GET_TYPED_DATA(timeUnit, int64_t, GET_PARAM_TYPE(&pInput[2]), pInput[2].columnData->pData);
|
||||
GET_TYPED_DATA(timePrec, int64_t, GET_PARAM_TYPE(&pInput[3]), pInput[3].columnData->pData);
|
||||
} else {
|
||||
GET_TYPED_DATA(timePrec, int64_t, GET_PARAM_TYPE(&pInput[2]), pInput[2].columnData->pData);
|
||||
}
|
||||
|
||||
int32_t numOfRows = 0;
|
||||
|
|
|
@ -99,8 +99,8 @@ typedef struct SSchStat {
|
|||
typedef struct SSchResInfo {
|
||||
SQueryResult* queryRes;
|
||||
void** fetchRes;
|
||||
schedulerExecCallback execFp;
|
||||
schedulerFetchCallback fetchFp;
|
||||
schedulerExecFp execFp;
|
||||
schedulerFetchFp fetchFp;
|
||||
void* userParam;
|
||||
} SSchResInfo;
|
||||
|
||||
|
@ -212,15 +212,13 @@ typedef struct SSchJob {
|
|||
SRequestConnInfo conn;
|
||||
SArray *nodeList; // qnode/vnode list, SArray<SQueryNodeLoad>
|
||||
SArray *levels; // starting from 0. SArray<SSchLevel>
|
||||
SNodeList *subPlans; // subplan pointer copied from DAG, no need to free it in scheduler
|
||||
SQueryPlan *pDag;
|
||||
|
||||
SArray *dataSrcTasks; // SArray<SQueryTask*>
|
||||
int32_t levelIdx;
|
||||
SEpSet dataSrcEps;
|
||||
SHashObj *taskList;
|
||||
SHashObj *execTasks; // executing tasks, key:taskid, value:SQueryTask*
|
||||
SHashObj *succTasks; // succeed tasks, key:taskid, value:SQueryTask*
|
||||
SHashObj *failTasks; // failed tasks, key:taskid, value:SQueryTask*
|
||||
SHashObj *execTasks; // executing and executed tasks, key:taskid, value:SQueryTask*
|
||||
SHashObj *flowCtrl; // key is ep, element is SSchFlowControl
|
||||
|
||||
SExplainCtx *explainCtx;
|
||||
|
@ -228,7 +226,8 @@ typedef struct SSchJob {
|
|||
SQueryNodeAddr resNode;
|
||||
tsem_t rspSem;
|
||||
SSchOpStatus opStatus;
|
||||
bool *reqKilled;
|
||||
schedulerChkKillFp chkKillFp;
|
||||
void* chkKillParam;
|
||||
SSchTask *fetchTask;
|
||||
int32_t errCode;
|
||||
SRWLatch resLock;
|
||||
|
@ -368,7 +367,7 @@ void schFreeRpcCtxVal(const void *arg);
|
|||
int32_t schMakeBrokenLinkVal(SSchJob *pJob, SSchTask *pTask, SRpcBrokenlinkVal *brokenVal, bool isHb);
|
||||
int32_t schAppendTaskExecNode(SSchJob *pJob, SSchTask *pTask, SQueryNodeAddr *addr, int32_t execIdx);
|
||||
int32_t schExecStaticExplainJob(SSchedulerReq *pReq, int64_t *job, bool sync);
|
||||
int32_t schExecJobImpl(SSchedulerReq *pReq, int64_t *job, SQueryResult* pRes, bool sync);
|
||||
int32_t schExecJobImpl(SSchedulerReq *pReq, SSchJob *pJob, bool sync);
|
||||
int32_t schUpdateJobStatus(SSchJob *pJob, int8_t newStatus);
|
||||
int32_t schCancelJob(SSchJob *pJob);
|
||||
int32_t schProcessOnJobDropped(SSchJob *pJob, int32_t errCode);
|
||||
|
@ -383,6 +382,8 @@ int32_t schProcessOnTaskStatusRsp(SQueryNodeEpId* pEpId, SArray* pStatusList);
|
|||
void schFreeSMsgSendInfo(SMsgSendInfo *msgSendInfo);
|
||||
char* schGetOpStr(SCH_OP_TYPE type);
|
||||
int32_t schBeginOperation(SSchJob *pJob, SCH_OP_TYPE type, bool sync);
|
||||
int32_t schInitJob(SSchedulerReq *pReq, SSchJob **pSchJob);
|
||||
int32_t schSetJobQueryRes(SSchJob* pJob, SQueryResult* pRes);
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
|
|
@ -42,7 +42,7 @@ int32_t schInitTask(SSchJob *pJob, SSchTask *pTask, SSubplan *pPlan, SSchLevel *
|
|||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
int32_t schInitJob(SSchedulerReq *pReq, SSchJob **pSchJob, SQueryResult* pRes, bool syncSchedule) {
|
||||
int32_t schInitJob(SSchedulerReq *pReq, SSchJob **pSchJob) {
|
||||
int32_t code = 0;
|
||||
int64_t refId = -1;
|
||||
SSchJob *pJob = taosMemoryCalloc(1, sizeof(SSchJob));
|
||||
|
@ -54,12 +54,15 @@ int32_t schInitJob(SSchedulerReq *pReq, SSchJob **pSchJob, SQueryResult* pRes, b
|
|||
pJob->attr.explainMode = pReq->pDag->explainInfo.mode;
|
||||
pJob->conn = *pReq->pConn;
|
||||
pJob->sql = pReq->sql;
|
||||
pJob->reqKilled = pReq->reqKilled;
|
||||
pJob->userRes.queryRes = pRes;
|
||||
pJob->userRes.execFp = pReq->fp;
|
||||
pJob->userRes.userParam = pReq->cbParam;
|
||||
pJob->pDag = pReq->pDag;
|
||||
pJob->chkKillFp = pReq->chkKillFp;
|
||||
pJob->chkKillParam = pReq->chkKillParam;
|
||||
pJob->userRes.execFp = pReq->execFp;
|
||||
pJob->userRes.userParam = pReq->execParam;
|
||||
|
||||
if (pReq->pNodeList != NULL) {
|
||||
if (pReq->pNodeList == NULL || taosArrayGetSize(pReq->pNodeList) <= 0) {
|
||||
qDebug("QID:0x%" PRIx64 " input exec nodeList is empty", pReq->pDag->queryId);
|
||||
} else {
|
||||
pJob->nodeList = taosArrayDup(pReq->pNodeList);
|
||||
}
|
||||
|
||||
|
@ -83,20 +86,6 @@ int32_t schInitJob(SSchedulerReq *pReq, SSchJob **pSchJob, SQueryResult* pRes, b
|
|||
SCH_ERR_JRET(TSDB_CODE_QRY_OUT_OF_MEMORY);
|
||||
}
|
||||
|
||||
pJob->succTasks =
|
||||
taosHashInit(pReq->pDag->numOfSubplans, taosGetDefaultHashFunction(TSDB_DATA_TYPE_UBIGINT), false, HASH_ENTRY_LOCK);
|
||||
if (NULL == pJob->succTasks) {
|
||||
SCH_JOB_ELOG("taosHashInit %d succTasks failed", pReq->pDag->numOfSubplans);
|
||||
SCH_ERR_JRET(TSDB_CODE_QRY_OUT_OF_MEMORY);
|
||||
}
|
||||
|
||||
pJob->failTasks =
|
||||
taosHashInit(pReq->pDag->numOfSubplans, taosGetDefaultHashFunction(TSDB_DATA_TYPE_UBIGINT), false, HASH_ENTRY_LOCK);
|
||||
if (NULL == pJob->failTasks) {
|
||||
SCH_JOB_ELOG("taosHashInit %d failTasks failed", pReq->pDag->numOfSubplans);
|
||||
SCH_ERR_JRET(TSDB_CODE_QRY_OUT_OF_MEMORY);
|
||||
}
|
||||
|
||||
tsem_init(&pJob->rspSem, 0, 0);
|
||||
|
||||
refId = taosAddRef(schMgmt.jobRef, pJob);
|
||||
|
@ -194,7 +183,7 @@ FORCE_INLINE bool schJobNeedToStop(SSchJob *pJob, int8_t *pStatus) {
|
|||
*pStatus = status;
|
||||
}
|
||||
|
||||
if (*pJob->reqKilled) {
|
||||
if ((*pJob->chkKillFp)(pJob->chkKillParam)) {
|
||||
schUpdateJobStatus(pJob, JOB_TASK_STATUS_DROPPING);
|
||||
schUpdateJobErrCode(pJob, TSDB_CODE_TSC_QUERY_KILLED);
|
||||
|
||||
|
@ -547,8 +536,6 @@ int32_t schValidateAndBuildJob(SQueryPlan *pDag, SSchJob *pJob) {
|
|||
pJob->levelNum = levelNum;
|
||||
pJob->levelIdx = levelNum - 1;
|
||||
|
||||
pJob->subPlans = pDag->pSubplans;
|
||||
|
||||
SSchLevel level = {0};
|
||||
SNodeListNode *plans = NULL;
|
||||
int32_t taskNum = 0;
|
||||
|
@ -724,6 +711,7 @@ int32_t schPushTaskToExecList(SSchJob *pJob, SSchTask *pTask) {
|
|||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
/*
|
||||
int32_t schMoveTaskToSuccList(SSchJob *pJob, SSchTask *pTask, bool *moved) {
|
||||
if (0 != taosHashRemove(pJob->execTasks, &pTask->taskId, sizeof(pTask->taskId))) {
|
||||
SCH_TASK_WLOG("remove task from execTask list failed, may not exist, status:%s", SCH_GET_TASK_STATUS_STR(pTask));
|
||||
|
@ -801,6 +789,7 @@ int32_t schMoveTaskToExecList(SSchJob *pJob, SSchTask *pTask, bool *moved) {
|
|||
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
*/
|
||||
|
||||
int32_t schTaskCheckSetRetry(SSchJob *pJob, SSchTask *pTask, int32_t errCode, bool *needRetry) {
|
||||
int8_t status = 0;
|
||||
|
@ -1047,9 +1036,7 @@ int32_t schProcessOnTaskFailure(SSchJob *pJob, SSchTask *pTask, int32_t errCode)
|
|||
if (!needRetry) {
|
||||
SCH_TASK_ELOG("task failed and no more retry, code:%s", tstrerror(errCode));
|
||||
|
||||
if (SCH_GET_TASK_STATUS(pTask) == JOB_TASK_STATUS_EXECUTING) {
|
||||
SCH_ERR_JRET(schMoveTaskToFailList(pJob, pTask, &moved));
|
||||
} else {
|
||||
if (SCH_GET_TASK_STATUS(pTask) != JOB_TASK_STATUS_EXECUTING) {
|
||||
SCH_TASK_ELOG("task not in executing list, status:%s", SCH_GET_TASK_STATUS_STR(pTask));
|
||||
SCH_ERR_JRET(TSDB_CODE_SCH_STATUS_ERROR);
|
||||
}
|
||||
|
@ -1115,8 +1102,6 @@ int32_t schProcessOnTaskSuccess(SSchJob *pJob, SSchTask *pTask) {
|
|||
|
||||
SCH_LOG_TASK_END_TS(pTask);
|
||||
|
||||
SCH_ERR_JRET(schMoveTaskToSuccList(pJob, pTask, &moved));
|
||||
|
||||
SCH_SET_TASK_STATUS(pTask, JOB_TASK_STATUS_PARTIAL_SUCCEED);
|
||||
|
||||
SCH_ERR_JRET(schRecordTaskSucceedNode(pJob, pTask));
|
||||
|
@ -1150,8 +1135,6 @@ int32_t schProcessOnTaskSuccess(SSchJob *pJob, SSchTask *pTask) {
|
|||
|
||||
pJob->fetchTask = pTask;
|
||||
|
||||
SCH_ERR_JRET(schMoveTaskToExecList(pJob, pTask, &moved));
|
||||
|
||||
SCH_RET(schProcessOnJobPartialSuccess(pJob));
|
||||
}
|
||||
|
||||
|
@ -1466,8 +1449,8 @@ void schDropTaskInHashList(SSchJob *pJob, SHashObj *list) {
|
|||
|
||||
void schDropJobAllTasks(SSchJob *pJob) {
|
||||
schDropTaskInHashList(pJob, pJob->execTasks);
|
||||
schDropTaskInHashList(pJob, pJob->succTasks);
|
||||
schDropTaskInHashList(pJob, pJob->failTasks);
|
||||
// schDropTaskInHashList(pJob, pJob->succTasks);
|
||||
// schDropTaskInHashList(pJob, pJob->failTasks);
|
||||
}
|
||||
|
||||
int32_t schCancelJob(SSchJob *pJob) {
|
||||
|
@ -1491,8 +1474,6 @@ void schFreeJobImpl(void *job) {
|
|||
|
||||
schDropJobAllTasks(pJob);
|
||||
|
||||
pJob->subPlans = NULL; // it is a reference to pDag->pSubplans
|
||||
|
||||
int32_t numOfLevels = taosArrayGetSize(pJob->levels);
|
||||
for (int32_t i = 0; i < numOfLevels; ++i) {
|
||||
SSchLevel *pLevel = taosArrayGet(pJob->levels, i);
|
||||
|
@ -1509,8 +1490,8 @@ void schFreeJobImpl(void *job) {
|
|||
schFreeFlowCtrl(pJob);
|
||||
|
||||
taosHashCleanup(pJob->execTasks);
|
||||
taosHashCleanup(pJob->failTasks);
|
||||
taosHashCleanup(pJob->succTasks);
|
||||
// taosHashCleanup(pJob->failTasks);
|
||||
// taosHashCleanup(pJob->succTasks);
|
||||
taosHashCleanup(pJob->taskList);
|
||||
|
||||
taosArrayDestroy(pJob->levels);
|
||||
|
@ -1521,6 +1502,8 @@ void schFreeJobImpl(void *job) {
|
|||
|
||||
destroyQueryExecRes(&pJob->execRes);
|
||||
|
||||
qDestroyQueryPlan(pJob->pDag);
|
||||
|
||||
taosMemoryFreeClear(pJob->userRes.queryRes);
|
||||
taosMemoryFreeClear(pJob->resData);
|
||||
taosMemoryFree(pJob);
|
||||
|
@ -1533,88 +1516,11 @@ void schFreeJobImpl(void *job) {
|
|||
}
|
||||
}
|
||||
|
||||
int32_t schExecJobImpl(SSchedulerReq *pReq, int64_t *job, SQueryResult* pRes, bool sync) {
|
||||
if (pReq->pNodeList == NULL || taosArrayGetSize(pReq->pNodeList) <= 0) {
|
||||
qDebug("QID:0x%" PRIx64 " input exec nodeList is empty", pReq->pDag->queryId);
|
||||
}
|
||||
|
||||
int32_t code = 0;
|
||||
SSchJob *pJob = NULL;
|
||||
SCH_ERR_JRET(schInitJob(pReq, &pJob, pRes, sync));
|
||||
|
||||
qDebug("QID:0x%" PRIx64 " sch job refId 0x%"PRIx64 " started", pReq->pDag->queryId, pJob->refId);
|
||||
*job = pJob->refId;
|
||||
|
||||
SCH_ERR_JRET(schBeginOperation(pJob, SCH_OP_EXEC, sync));
|
||||
|
||||
code = schLaunchJob(pJob);
|
||||
|
||||
if (sync) {
|
||||
SCH_JOB_DLOG("will wait for rsp now, job status:%s", SCH_GET_JOB_STATUS_STR(pJob));
|
||||
tsem_wait(&pJob->rspSem);
|
||||
|
||||
schEndOperation(pJob);
|
||||
} else if (code) {
|
||||
schPostJobRes(pJob, SCH_OP_EXEC);
|
||||
}
|
||||
|
||||
SCH_JOB_DLOG("job exec done, job status:%s, jobId:0x%" PRIx64, SCH_GET_JOB_STATUS_STR(pJob), pJob->refId);
|
||||
|
||||
schReleaseJob(pJob->refId);
|
||||
|
||||
SCH_RET(code);
|
||||
|
||||
_return:
|
||||
|
||||
if (!sync) {
|
||||
pReq->fp(NULL, pReq->cbParam, code);
|
||||
}
|
||||
|
||||
schReleaseJob(pJob->refId);
|
||||
|
||||
SCH_RET(code);
|
||||
}
|
||||
|
||||
int32_t schExecJob(SSchedulerReq *pReq, int64_t *pJob, SQueryResult *pRes) {
|
||||
int32_t code = 0;
|
||||
|
||||
*pJob = 0;
|
||||
|
||||
if (EXPLAIN_MODE_STATIC == pReq->pDag->explainInfo.mode) {
|
||||
SCH_ERR_JRET(schExecStaticExplainJob(pReq, pJob, true));
|
||||
} else {
|
||||
SCH_ERR_JRET(schExecJobImpl(pReq, pJob, NULL, true));
|
||||
}
|
||||
|
||||
_return:
|
||||
|
||||
if (*pJob) {
|
||||
SSchJob *job = schAcquireJob(*pJob);
|
||||
schSetJobQueryRes(job, pRes);
|
||||
schReleaseJob(*pJob);
|
||||
}
|
||||
|
||||
return code;
|
||||
}
|
||||
|
||||
int32_t schAsyncExecJob(SSchedulerReq *pReq, int64_t *pJob) {
|
||||
int32_t code = 0;
|
||||
|
||||
*pJob = 0;
|
||||
|
||||
if (EXPLAIN_MODE_STATIC == pReq->pDag->explainInfo.mode) {
|
||||
SCH_RET(schExecStaticExplainJob(pReq, pJob, false));
|
||||
}
|
||||
|
||||
SCH_ERR_RET(schExecJobImpl(pReq, pJob, NULL, false));
|
||||
|
||||
return code;
|
||||
}
|
||||
|
||||
int32_t schExecStaticExplainJob(SSchedulerReq *pReq, int64_t *job, bool sync) {
|
||||
int32_t schLaunchStaticExplainJob(SSchedulerReq *pReq, SSchJob *pJob, bool sync) {
|
||||
qDebug("QID:0x%" PRIx64 " job started", pReq->pDag->queryId);
|
||||
|
||||
int32_t code = 0;
|
||||
/*
|
||||
SSchJob *pJob = taosMemoryCalloc(1, sizeof(SSchJob));
|
||||
if (NULL == pJob) {
|
||||
qError("QID:0x%" PRIx64 " calloc %d failed", pReq->pDag->queryId, (int32_t)sizeof(SSchJob));
|
||||
|
@ -1625,10 +1531,10 @@ int32_t schExecStaticExplainJob(SSchedulerReq *pReq, int64_t *job, bool sync) {
|
|||
|
||||
pJob->sql = pReq->sql;
|
||||
pJob->reqKilled = pReq->reqKilled;
|
||||
pJob->pDag = pReq->pDag;
|
||||
pJob->attr.queryJob = true;
|
||||
pJob->attr.explainMode = pReq->pDag->explainInfo.mode;
|
||||
pJob->queryId = pReq->pDag->queryId;
|
||||
pJob->subPlans = pReq->pDag->pSubplans;
|
||||
pJob->userRes.execFp = pReq->fp;
|
||||
pJob->userRes.userParam = pReq->cbParam;
|
||||
|
||||
|
@ -1637,11 +1543,14 @@ int32_t schExecStaticExplainJob(SSchedulerReq *pReq, int64_t *job, bool sync) {
|
|||
code = schBeginOperation(pJob, SCH_OP_EXEC, sync);
|
||||
if (code) {
|
||||
pReq->fp(NULL, pReq->cbParam, code);
|
||||
schFreeJobImpl(pJob);
|
||||
SCH_ERR_RET(code);
|
||||
}
|
||||
*/
|
||||
|
||||
SCH_ERR_JRET(qExecStaticExplain(pReq->pDag, (SRetrieveTableRsp **)&pJob->resData));
|
||||
|
||||
/*
|
||||
int64_t refId = taosAddRef(schMgmt.jobRef, pJob);
|
||||
if (refId < 0) {
|
||||
SCH_JOB_ELOG("taosAddRef job failed, error:%s", tstrerror(terrno));
|
||||
|
@ -1656,10 +1565,10 @@ int32_t schExecStaticExplainJob(SSchedulerReq *pReq, int64_t *job, bool sync) {
|
|||
pJob->refId = refId;
|
||||
|
||||
SCH_JOB_DLOG("job refId:0x%" PRIx64, pJob->refId);
|
||||
*/
|
||||
|
||||
pJob->status = JOB_TASK_STATUS_PARTIAL_SUCCEED;
|
||||
|
||||
*job = pJob->refId;
|
||||
SCH_JOB_DLOG("job exec done, job status:%s", SCH_GET_JOB_STATUS_STR(pJob));
|
||||
|
||||
if (!sync) {
|
||||
|
@ -1668,7 +1577,7 @@ int32_t schExecStaticExplainJob(SSchedulerReq *pReq, int64_t *job, bool sync) {
|
|||
schEndOperation(pJob);
|
||||
}
|
||||
|
||||
schReleaseJob(pJob->refId);
|
||||
// schReleaseJob(pJob->refId);
|
||||
|
||||
SCH_RET(code);
|
||||
|
||||
|
@ -1676,7 +1585,7 @@ _return:
|
|||
|
||||
schEndOperation(pJob);
|
||||
if (!sync) {
|
||||
pReq->fp(NULL, pReq->cbParam, code);
|
||||
pReq->execFp(NULL, pReq->execParam, code);
|
||||
}
|
||||
|
||||
schFreeJobImpl(pJob);
|
||||
|
@ -1715,3 +1624,39 @@ int32_t schAsyncFetchRows(SSchJob *pJob) {
|
|||
}
|
||||
|
||||
|
||||
int32_t schExecJobImpl(SSchedulerReq *pReq, SSchJob *pJob, bool sync) {
|
||||
int32_t code = 0;
|
||||
|
||||
qDebug("QID:0x%" PRIx64 " sch job refId 0x%"PRIx64 " started", pReq->pDag->queryId, pJob->refId);
|
||||
|
||||
SCH_ERR_JRET(schBeginOperation(pJob, SCH_OP_EXEC, sync));
|
||||
|
||||
if (EXPLAIN_MODE_STATIC == pReq->pDag->explainInfo.mode) {
|
||||
code = schLaunchStaticExplainJob(pReq, pJob, sync);
|
||||
} else {
|
||||
code = schLaunchJob(pJob);
|
||||
if (sync) {
|
||||
SCH_JOB_DLOG("will wait for rsp now, job status:%s", SCH_GET_JOB_STATUS_STR(pJob));
|
||||
tsem_wait(&pJob->rspSem);
|
||||
|
||||
schEndOperation(pJob);
|
||||
} else if (code) {
|
||||
schPostJobRes(pJob, SCH_OP_EXEC);
|
||||
}
|
||||
}
|
||||
|
||||
SCH_JOB_DLOG("job exec done, job status:%s, jobId:0x%" PRIx64, SCH_GET_JOB_STATUS_STR(pJob), pJob->refId);
|
||||
|
||||
SCH_RET(code);
|
||||
|
||||
_return:
|
||||
|
||||
if (!sync) {
|
||||
pReq->execFp(NULL, pReq->execParam, code);
|
||||
}
|
||||
|
||||
SCH_RET(code);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -67,33 +67,53 @@ int32_t schedulerInit(SSchedulerCfg *cfg) {
|
|||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
int32_t schedulerExecJob(SSchedulerReq *pReq, int64_t *pJob, SQueryResult *pRes) {
|
||||
int32_t schedulerExecJob(SSchedulerReq *pReq, int64_t *pJobId, SQueryResult *pRes) {
|
||||
qDebug("scheduler sync exec job start");
|
||||
|
||||
if (NULL == pReq || NULL == pJob || NULL == pRes) {
|
||||
SCH_ERR_RET(TSDB_CODE_QRY_INVALID_INPUT);
|
||||
}
|
||||
|
||||
SCH_RET(schExecJob(pReq, pJob, pRes));
|
||||
}
|
||||
|
||||
int32_t schedulerAsyncExecJob(SSchedulerReq *pReq, int64_t *pJob) {
|
||||
qDebug("scheduler async exec job start");
|
||||
|
||||
int32_t code = 0;
|
||||
if (NULL == pReq || NULL == pJob) {
|
||||
SCH_ERR_JRET(TSDB_CODE_QRY_INVALID_INPUT);
|
||||
}
|
||||
SSchJob *pJob = NULL;
|
||||
SCH_ERR_JRET(schInitJob(pReq, &pJob));
|
||||
|
||||
schAsyncExecJob(pReq, pJob);
|
||||
*pJobId = pJob->refId;
|
||||
|
||||
SCH_ERR_JRET(schExecJobImpl(pReq, pJob, true));
|
||||
|
||||
_return:
|
||||
|
||||
if (code != TSDB_CODE_SUCCESS) {
|
||||
pReq->fp(NULL, pReq->cbParam, code);
|
||||
if (code && NULL == pJob) {
|
||||
qDestroyQueryPlan(pReq->pDag);
|
||||
}
|
||||
|
||||
SCH_RET(code);
|
||||
if (pJob) {
|
||||
schSetJobQueryRes(pJob, pRes);
|
||||
schReleaseJob(pJob->refId);
|
||||
}
|
||||
|
||||
return code;
|
||||
}
|
||||
|
||||
int32_t schedulerAsyncExecJob(SSchedulerReq *pReq, int64_t *pJobId) {
|
||||
qDebug("scheduler async exec job start");
|
||||
|
||||
int32_t code = 0;
|
||||
SSchJob *pJob = NULL;
|
||||
SCH_ERR_JRET(schInitJob(pReq, &pJob));
|
||||
|
||||
*pJobId = pJob->refId;
|
||||
|
||||
SCH_ERR_JRET(schExecJobImpl(pReq, pJob, false));
|
||||
|
||||
_return:
|
||||
|
||||
if (code && NULL == pJob) {
|
||||
qDestroyQueryPlan(pReq->pDag);
|
||||
}
|
||||
|
||||
if (pJob) {
|
||||
schReleaseJob(pJob->refId);
|
||||
}
|
||||
|
||||
return code;
|
||||
}
|
||||
|
||||
int32_t schedulerFetchRows(int64_t job, void **pData) {
|
||||
|
@ -120,7 +140,7 @@ int32_t schedulerFetchRows(int64_t job, void **pData) {
|
|||
SCH_RET(code);
|
||||
}
|
||||
|
||||
void schedulerAsyncFetchRows(int64_t job, schedulerFetchCallback fp, void* param) {
|
||||
void schedulerAsyncFetchRows(int64_t job, schedulerFetchFp fp, void* param) {
|
||||
qDebug("scheduler async fetch rows start");
|
||||
|
||||
int32_t code = 0;
|
||||
|
|
|
@ -511,8 +511,8 @@ void* schtRunJobThread(void *aa) {
|
|||
req.pNodeList = qnodeList;
|
||||
req.pDag = &dag;
|
||||
req.sql = "select * from tb";
|
||||
req.fp = schtQueryCb;
|
||||
req.cbParam = &queryDone;
|
||||
req.execFp = schtQueryCb;
|
||||
req.execParam = &queryDone;
|
||||
|
||||
code = schedulerAsyncExecJob(&req, &queryJobRefId);
|
||||
assert(code == 0);
|
||||
|
@ -663,8 +663,8 @@ TEST(queryTest, normalCase) {
|
|||
req.pNodeList = qnodeList;
|
||||
req.pDag = &dag;
|
||||
req.sql = "select * from tb";
|
||||
req.fp = schtQueryCb;
|
||||
req.cbParam = &queryDone;
|
||||
req.execFp = schtQueryCb;
|
||||
req.execParam = &queryDone;
|
||||
|
||||
code = schedulerAsyncExecJob(&req, &job);
|
||||
ASSERT_EQ(code, 0);
|
||||
|
@ -767,8 +767,8 @@ TEST(queryTest, readyFirstCase) {
|
|||
req.pNodeList = qnodeList;
|
||||
req.pDag = &dag;
|
||||
req.sql = "select * from tb";
|
||||
req.fp = schtQueryCb;
|
||||
req.cbParam = &queryDone;
|
||||
req.execFp = schtQueryCb;
|
||||
req.execParam = &queryDone;
|
||||
code = schedulerAsyncExecJob(&req, &job);
|
||||
ASSERT_EQ(code, 0);
|
||||
|
||||
|
@ -874,8 +874,8 @@ TEST(queryTest, flowCtrlCase) {
|
|||
req.pNodeList = qnodeList;
|
||||
req.pDag = &dag;
|
||||
req.sql = "select * from tb";
|
||||
req.fp = schtQueryCb;
|
||||
req.cbParam = &queryDone;
|
||||
req.execFp = schtQueryCb;
|
||||
req.execParam = &queryDone;
|
||||
|
||||
code = schedulerAsyncExecJob(&req, &job);
|
||||
ASSERT_EQ(code, 0);
|
||||
|
@ -987,8 +987,8 @@ TEST(insertTest, normalCase) {
|
|||
req.pNodeList = qnodeList;
|
||||
req.pDag = &dag;
|
||||
req.sql = "insert into tb values(now,1)";
|
||||
req.fp = schtQueryCb;
|
||||
req.cbParam = NULL;
|
||||
req.execFp = schtQueryCb;
|
||||
req.execParam = NULL;
|
||||
|
||||
code = schedulerExecJob(&req, &insertJobRefId, &res);
|
||||
ASSERT_EQ(code, 0);
|
||||
|
|
|
@ -221,7 +221,6 @@ void syncNodeVoteForSelf(SSyncNode* pSyncNode);
|
|||
|
||||
// snapshot --------------
|
||||
bool syncNodeHasSnapshot(SSyncNode* pSyncNode);
|
||||
bool syncNodeIsIndexInSnapshot(SSyncNode* pSyncNode, SyncIndex index);
|
||||
|
||||
SyncIndex syncNodeGetLastIndex(SSyncNode* pSyncNode);
|
||||
SyncTerm syncNodeGetLastTerm(SSyncNode* pSyncNode);
|
||||
|
|
|
@ -860,7 +860,9 @@ int32_t syncNodeOnAppendEntriesSnapshotCb(SSyncNode* ths, SyncAppendEntries* pMs
|
|||
}
|
||||
|
||||
code = ths->pLogStore->syncLogAppendEntry(ths->pLogStore, pAppendEntry);
|
||||
ASSERT(code == 0);
|
||||
if (code != 0) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
// pre commit
|
||||
code = syncNodePreCommit(ths, pAppendEntry);
|
||||
|
@ -971,7 +973,9 @@ int32_t syncNodeOnAppendEntriesSnapshotCb(SSyncNode* ths, SyncAppendEntries* pMs
|
|||
ASSERT(pAppendEntry != NULL);
|
||||
|
||||
code = ths->pLogStore->syncLogAppendEntry(ths->pLogStore, pAppendEntry);
|
||||
ASSERT(code == 0);
|
||||
if (code != 0) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
// pre commit
|
||||
code = syncNodePreCommit(ths, pAppendEntry);
|
||||
|
|
|
@ -75,7 +75,11 @@ int32_t syncNodeElect(SSyncNode* pSyncNode) {
|
|||
if (pSyncNode->state == TAOS_SYNC_STATE_FOLLOWER) {
|
||||
syncNodeFollower2Candidate(pSyncNode);
|
||||
}
|
||||
ASSERT(pSyncNode->state == TAOS_SYNC_STATE_CANDIDATE);
|
||||
|
||||
if (pSyncNode->state != TAOS_SYNC_STATE_CANDIDATE) {
|
||||
syncNodeErrorLog(pSyncNode, "not candidate, can not elect");
|
||||
return -1;
|
||||
}
|
||||
|
||||
// start election
|
||||
raftStoreNextTerm(pSyncNode->pRaftStore);
|
||||
|
|
|
@ -1923,6 +1923,8 @@ void syncNodeVoteForSelf(SSyncNode* pSyncNode) {
|
|||
}
|
||||
|
||||
// snapshot --------------
|
||||
|
||||
// return if has a snapshot
|
||||
bool syncNodeHasSnapshot(SSyncNode* pSyncNode) {
|
||||
bool ret = false;
|
||||
SSnapshot snapshot = {.data = NULL, .lastApplyIndex = -1, .lastApplyTerm = 0, .lastConfigIndex = -1};
|
||||
|
@ -1935,21 +1937,10 @@ bool syncNodeHasSnapshot(SSyncNode* pSyncNode) {
|
|||
return ret;
|
||||
}
|
||||
|
||||
#if 0
|
||||
bool syncNodeIsIndexInSnapshot(SSyncNode* pSyncNode, SyncIndex index) {
|
||||
ASSERT(syncNodeHasSnapshot(pSyncNode));
|
||||
ASSERT(pSyncNode->pFsm->FpGetSnapshotInfo != NULL);
|
||||
ASSERT(index >= SYNC_INDEX_BEGIN);
|
||||
|
||||
SSnapshot snapshot;
|
||||
pSyncNode->pFsm->FpGetSnapshotInfo(pSyncNode->pFsm, &snapshot);
|
||||
bool b = (index <= snapshot.lastApplyIndex);
|
||||
return b;
|
||||
}
|
||||
#endif
|
||||
|
||||
// return max(logLastIndex, snapshotLastIndex)
|
||||
// if no snapshot and log, return -1
|
||||
SyncIndex syncNodeGetLastIndex(SSyncNode* pSyncNode) {
|
||||
SSnapshot snapshot = {.data = NULL, .lastApplyIndex = -1, .lastApplyTerm = 0};
|
||||
SSnapshot snapshot = {.data = NULL, .lastApplyIndex = -1, .lastApplyTerm = 0, .lastConfigIndex = -1};
|
||||
if (pSyncNode->pFsm->FpGetSnapshotInfo != NULL) {
|
||||
pSyncNode->pFsm->FpGetSnapshotInfo(pSyncNode->pFsm, &snapshot);
|
||||
}
|
||||
|
@ -1959,6 +1950,8 @@ SyncIndex syncNodeGetLastIndex(SSyncNode* pSyncNode) {
|
|||
return lastIndex;
|
||||
}
|
||||
|
||||
// return the last term of snapshot and log
|
||||
// if error, return SYNC_TERM_INVALID (by syncLogLastTerm)
|
||||
SyncTerm syncNodeGetLastTerm(SSyncNode* pSyncNode) {
|
||||
SyncTerm lastTerm = 0;
|
||||
if (syncNodeHasSnapshot(pSyncNode)) {
|
||||
|
@ -1990,11 +1983,14 @@ int32_t syncNodeGetLastIndexTerm(SSyncNode* pSyncNode, SyncIndex* pLastIndex, Sy
|
|||
return 0;
|
||||
}
|
||||
|
||||
// return append-entries first try index
|
||||
SyncIndex syncNodeSyncStartIndex(SSyncNode* pSyncNode) {
|
||||
SyncIndex syncStartIndex = syncNodeGetLastIndex(pSyncNode) + 1;
|
||||
return syncStartIndex;
|
||||
}
|
||||
|
||||
// if index > 0, return index - 1
|
||||
// else, return -1
|
||||
SyncIndex syncNodeGetPreIndex(SSyncNode* pSyncNode, SyncIndex index) {
|
||||
SyncIndex preIndex = index - 1;
|
||||
if (preIndex < SYNC_INDEX_INVALID) {
|
||||
|
@ -2004,21 +2000,10 @@ SyncIndex syncNodeGetPreIndex(SSyncNode* pSyncNode, SyncIndex index) {
|
|||
return preIndex;
|
||||
}
|
||||
|
||||
/*
|
||||
SyncIndex syncNodeGetPreIndex(SSyncNode* pSyncNode, SyncIndex index) {
|
||||
ASSERT(index >= SYNC_INDEX_BEGIN);
|
||||
|
||||
SyncIndex syncStartIndex = syncNodeSyncStartIndex(pSyncNode);
|
||||
if (index > syncStartIndex) {
|
||||
syncNodeLog3("syncNodeGetPreIndex", pSyncNode);
|
||||
ASSERT(0);
|
||||
}
|
||||
|
||||
SyncIndex preIndex = index - 1;
|
||||
return preIndex;
|
||||
}
|
||||
*/
|
||||
|
||||
// if index < 0, return SYNC_TERM_INVALID
|
||||
// if index == 0, return 0
|
||||
// if index > 0, return preTerm
|
||||
// if error, return SYNC_TERM_INVALID
|
||||
SyncTerm syncNodeGetPreTerm(SSyncNode* pSyncNode, SyncIndex index) {
|
||||
if (index < SYNC_INDEX_BEGIN) {
|
||||
return SYNC_TERM_INVALID;
|
||||
|
@ -2056,112 +2041,6 @@ SyncTerm syncNodeGetPreTerm(SSyncNode* pSyncNode, SyncIndex index) {
|
|||
return SYNC_TERM_INVALID;
|
||||
}
|
||||
|
||||
#if 0
|
||||
SyncTerm syncNodeGetPreTerm(SSyncNode* pSyncNode, SyncIndex index) {
|
||||
ASSERT(index >= SYNC_INDEX_BEGIN);
|
||||
|
||||
SyncIndex syncStartIndex = syncNodeSyncStartIndex(pSyncNode);
|
||||
if (index > syncStartIndex) {
|
||||
syncNodeLog3("syncNodeGetPreTerm", pSyncNode);
|
||||
ASSERT(0);
|
||||
}
|
||||
|
||||
if (index == SYNC_INDEX_BEGIN) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
SyncTerm preTerm = 0;
|
||||
SyncIndex preIndex = index - 1;
|
||||
SSyncRaftEntry* pPreEntry = NULL;
|
||||
int32_t code = pSyncNode->pLogStore->syncLogGetEntry(pSyncNode->pLogStore, preIndex, &pPreEntry);
|
||||
if (code == 0) {
|
||||
ASSERT(pPreEntry != NULL);
|
||||
preTerm = pPreEntry->term;
|
||||
taosMemoryFree(pPreEntry);
|
||||
return preTerm;
|
||||
} else {
|
||||
if (terrno == TSDB_CODE_WAL_LOG_NOT_EXIST) {
|
||||
SSnapshot snapshot = {.data = NULL, .lastApplyIndex = -1, .lastApplyTerm = 0, .lastConfigIndex = -1};
|
||||
if (pSyncNode->pFsm->FpGetSnapshotInfo != NULL) {
|
||||
pSyncNode->pFsm->FpGetSnapshotInfo(pSyncNode->pFsm, &snapshot);
|
||||
if (snapshot.lastApplyIndex == preIndex) {
|
||||
return snapshot.lastApplyTerm;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
ASSERT(0);
|
||||
return -1;
|
||||
}
|
||||
#endif
|
||||
|
||||
#if 0
|
||||
SyncTerm syncNodeGetPreTerm(SSyncNode* pSyncNode, SyncIndex index) {
|
||||
ASSERT(index >= SYNC_INDEX_BEGIN);
|
||||
|
||||
SyncIndex syncStartIndex = syncNodeSyncStartIndex(pSyncNode);
|
||||
if (index > syncStartIndex) {
|
||||
syncNodeLog3("syncNodeGetPreTerm", pSyncNode);
|
||||
ASSERT(0);
|
||||
}
|
||||
|
||||
if (index == SYNC_INDEX_BEGIN) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
SyncTerm preTerm = 0;
|
||||
if (syncNodeHasSnapshot(pSyncNode)) {
|
||||
// has snapshot
|
||||
SSnapshot snapshot = {.data = NULL, .lastApplyIndex = -1, .lastApplyTerm = 0, .lastConfigIndex = -1};
|
||||
if (pSyncNode->pFsm->FpGetSnapshotInfo != NULL) {
|
||||
pSyncNode->pFsm->FpGetSnapshotInfo(pSyncNode->pFsm, &snapshot);
|
||||
}
|
||||
|
||||
if (index > snapshot.lastApplyIndex + 1) {
|
||||
// should be log preTerm
|
||||
SSyncRaftEntry* pPreEntry = NULL;
|
||||
int32_t code = pSyncNode->pLogStore->syncLogGetEntry(pSyncNode->pLogStore, index - 1, &pPreEntry);
|
||||
ASSERT(code == 0);
|
||||
ASSERT(pPreEntry != NULL);
|
||||
|
||||
preTerm = pPreEntry->term;
|
||||
taosMemoryFree(pPreEntry);
|
||||
|
||||
} else if (index == snapshot.lastApplyIndex + 1) {
|
||||
preTerm = snapshot.lastApplyTerm;
|
||||
|
||||
} else {
|
||||
// maybe snapshot change
|
||||
sError("sync get pre term, bad scene. index:%ld", index);
|
||||
logStoreLog2("sync get pre term, bad scene", pSyncNode->pLogStore);
|
||||
|
||||
SSyncRaftEntry* pPreEntry = NULL;
|
||||
int32_t code = pSyncNode->pLogStore->syncLogGetEntry(pSyncNode->pLogStore, index - 1, &pPreEntry);
|
||||
ASSERT(code == 0);
|
||||
ASSERT(pPreEntry != NULL);
|
||||
|
||||
preTerm = pPreEntry->term;
|
||||
taosMemoryFree(pPreEntry);
|
||||
}
|
||||
|
||||
} else {
|
||||
// no snapshot
|
||||
ASSERT(index > SYNC_INDEX_BEGIN);
|
||||
|
||||
SSyncRaftEntry* pPreEntry = NULL;
|
||||
int32_t code = pSyncNode->pLogStore->syncLogGetEntry(pSyncNode->pLogStore, index - 1, &pPreEntry);
|
||||
ASSERT(code == 0);
|
||||
ASSERT(pPreEntry != NULL);
|
||||
|
||||
preTerm = pPreEntry->term;
|
||||
taosMemoryFree(pPreEntry);
|
||||
}
|
||||
|
||||
return preTerm;
|
||||
}
|
||||
#endif
|
||||
|
||||
// get pre index and term of "index"
|
||||
int32_t syncNodeGetPreIndexTerm(SSyncNode* pSyncNode, SyncIndex index, SyncIndex* pPreIndex, SyncTerm* pPreTerm) {
|
||||
*pPreIndex = syncNodeGetPreIndex(pSyncNode, index);
|
||||
|
@ -2351,8 +2230,8 @@ static int32_t syncNodeAppendNoop(SSyncNode* ths) {
|
|||
ASSERT(pEntry != NULL);
|
||||
|
||||
if (ths->state == TAOS_SYNC_STATE_LEADER) {
|
||||
// ths->pLogStore->appendEntry(ths->pLogStore, pEntry);
|
||||
ths->pLogStore->syncLogAppendEntry(ths->pLogStore, pEntry);
|
||||
int32_t code = ths->pLogStore->syncLogAppendEntry(ths->pLogStore, pEntry);
|
||||
ASSERT(code == 0);
|
||||
syncNodeReplicate(ths);
|
||||
}
|
||||
|
||||
|
@ -2406,6 +2285,7 @@ int32_t syncNodeOnPingReplyCb(SSyncNode* ths, SyncPingReply* pMsg) {
|
|||
//
|
||||
int32_t syncNodeOnClientRequestCb(SSyncNode* ths, SyncClientRequest* pMsg, SyncIndex* pRetIndex) {
|
||||
int32_t ret = 0;
|
||||
int32_t code = 0;
|
||||
syncClientRequestLog2("==syncNodeOnClientRequestCb==", pMsg);
|
||||
|
||||
SyncIndex index = ths->pLogStore->syncLogWriteIndex(ths->pLogStore);
|
||||
|
@ -2414,18 +2294,24 @@ int32_t syncNodeOnClientRequestCb(SSyncNode* ths, SyncClientRequest* pMsg, SyncI
|
|||
ASSERT(pEntry != NULL);
|
||||
|
||||
if (ths->state == TAOS_SYNC_STATE_LEADER) {
|
||||
// ths->pLogStore->appendEntry(ths->pLogStore, pEntry);
|
||||
ths->pLogStore->syncLogAppendEntry(ths->pLogStore, pEntry);
|
||||
// append entry
|
||||
code = ths->pLogStore->syncLogAppendEntry(ths->pLogStore, pEntry);
|
||||
if (code != 0) {
|
||||
// del resp mgr, call FpCommitCb
|
||||
ASSERT(0);
|
||||
return -1;
|
||||
}
|
||||
|
||||
// start replicate right now!
|
||||
// if mulit replica, start replicate right now
|
||||
if (ths->replicaNum > 1) {
|
||||
syncNodeReplicate(ths);
|
||||
}
|
||||
|
||||
// pre commit
|
||||
SRpcMsg rpcMsg;
|
||||
syncEntry2OriginalRpc(pEntry, &rpcMsg);
|
||||
|
||||
if (ths->pFsm != NULL) {
|
||||
// if (ths->pFsm->FpPreCommitCb != NULL && pEntry->originalRpcType != TDMT_SYNC_NOOP) {
|
||||
if (ths->pFsm->FpPreCommitCb != NULL && syncUtilUserPreCommit(pEntry->originalRpcType)) {
|
||||
SFsmCbMeta cbMeta = {0};
|
||||
cbMeta.index = pEntry->index;
|
||||
|
@ -2439,8 +2325,10 @@ int32_t syncNodeOnClientRequestCb(SSyncNode* ths, SyncClientRequest* pMsg, SyncI
|
|||
}
|
||||
rpcFreeCont(rpcMsg.pCont);
|
||||
|
||||
// only myself, maybe commit
|
||||
// if only myself, maybe commit right now
|
||||
if (ths->replicaNum == 1) {
|
||||
syncMaybeAdvanceCommitIndex(ths);
|
||||
}
|
||||
|
||||
} else {
|
||||
// pre commit
|
||||
|
@ -2448,7 +2336,6 @@ int32_t syncNodeOnClientRequestCb(SSyncNode* ths, SyncClientRequest* pMsg, SyncI
|
|||
syncEntry2OriginalRpc(pEntry, &rpcMsg);
|
||||
|
||||
if (ths->pFsm != NULL) {
|
||||
// if (ths->pFsm->FpPreCommitCb != NULL && pEntry->originalRpcType != TDMT_SYNC_NOOP) {
|
||||
if (ths->pFsm->FpPreCommitCb != NULL && syncUtilUserPreCommit(pEntry->originalRpcType)) {
|
||||
SFsmCbMeta cbMeta = {0};
|
||||
cbMeta.index = pEntry->index;
|
||||
|
|
|
@ -101,7 +101,7 @@ cJSON *syncCfg2Json(SSyncCfg *pSyncCfg) {
|
|||
|
||||
char *syncCfg2Str(SSyncCfg *pSyncCfg) {
|
||||
cJSON *pJson = syncCfg2Json(pSyncCfg);
|
||||
char * serialized = cJSON_Print(pJson);
|
||||
char *serialized = cJSON_Print(pJson);
|
||||
cJSON_Delete(pJson);
|
||||
return serialized;
|
||||
}
|
||||
|
@ -109,7 +109,7 @@ char *syncCfg2Str(SSyncCfg *pSyncCfg) {
|
|||
char *syncCfg2SimpleStr(SSyncCfg *pSyncCfg) {
|
||||
if (pSyncCfg != NULL) {
|
||||
int32_t len = 512;
|
||||
char * s = taosMemoryMalloc(len);
|
||||
char *s = taosMemoryMalloc(len);
|
||||
memset(s, 0, len);
|
||||
|
||||
snprintf(s, len, "{replica-num:%d, my-index:%d, ", pSyncCfg->replicaNum, pSyncCfg->myIndex);
|
||||
|
@ -205,7 +205,7 @@ cJSON *raftCfg2Json(SRaftCfg *pRaftCfg) {
|
|||
|
||||
char *raftCfg2Str(SRaftCfg *pRaftCfg) {
|
||||
cJSON *pJson = raftCfg2Json(pRaftCfg);
|
||||
char * serialized = cJSON_Print(pJson);
|
||||
char *serialized = cJSON_Print(pJson);
|
||||
cJSON_Delete(pJson);
|
||||
return serialized;
|
||||
}
|
||||
|
@ -214,7 +214,16 @@ int32_t raftCfgCreateFile(SSyncCfg *pCfg, SRaftCfgMeta meta, const char *path) {
|
|||
ASSERT(pCfg != NULL);
|
||||
|
||||
TdFilePtr pFile = taosOpenFile(path, TD_FILE_CREATE | TD_FILE_WRITE);
|
||||
ASSERT(pFile != NULL);
|
||||
if (pFile == NULL) {
|
||||
int32_t err = terrno;
|
||||
const char *errStr = tstrerror(err);
|
||||
int32_t sysErr = errno;
|
||||
const char *sysErrStr = strerror(errno);
|
||||
sError("create raft cfg file error, err:%d %X, msg:%s, syserr:%d, sysmsg:%s", err, err, errStr, sysErr, sysErrStr);
|
||||
ASSERT(0);
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
SRaftCfg raftCfg;
|
||||
raftCfg.cfg = *pCfg;
|
||||
|
@ -271,7 +280,7 @@ int32_t raftCfgFromJson(const cJSON *pRoot, SRaftCfg *pRaftCfg) {
|
|||
(pRaftCfg->configIndexArr)[i] = atoll(pIndex->valuestring);
|
||||
}
|
||||
|
||||
cJSON * pJsonSyncCfg = cJSON_GetObjectItem(pJson, "SSyncCfg");
|
||||
cJSON *pJsonSyncCfg = cJSON_GetObjectItem(pJson, "SSyncCfg");
|
||||
int32_t code = syncCfgFromJson(pJsonSyncCfg, &(pRaftCfg->cfg));
|
||||
ASSERT(code == 0);
|
||||
|
||||
|
|
|
@ -17,24 +17,27 @@
|
|||
#include "syncRaftCfg.h"
|
||||
#include "syncRaftStore.h"
|
||||
|
||||
// refactor, log[0 .. n] ==> log[m .. n]
|
||||
//-------------------------------
|
||||
// log[m .. n]
|
||||
|
||||
// public function
|
||||
static int32_t raftLogRestoreFromSnapshot(struct SSyncLogStore* pLogStore, SyncIndex snapshotIndex);
|
||||
// static int32_t raftLogSetBeginIndex(struct SSyncLogStore* pLogStore, SyncIndex beginIndex);
|
||||
static SyncIndex raftLogBeginIndex(struct SSyncLogStore* pLogStore);
|
||||
static SyncIndex raftLogEndIndex(struct SSyncLogStore* pLogStore);
|
||||
static SyncIndex raftLogWriteIndex(struct SSyncLogStore* pLogStore);
|
||||
static bool raftLogIsEmpty(struct SSyncLogStore* pLogStore);
|
||||
static int32_t raftLogEntryCount(struct SSyncLogStore* pLogStore);
|
||||
|
||||
static SyncIndex raftLogLastIndex(struct SSyncLogStore* pLogStore);
|
||||
static SyncTerm raftLogLastTerm(struct SSyncLogStore* pLogStore);
|
||||
static int32_t raftLogAppendEntry(struct SSyncLogStore* pLogStore, SSyncRaftEntry* pEntry);
|
||||
static int32_t raftLogGetEntry(struct SSyncLogStore* pLogStore, SyncIndex index, SSyncRaftEntry** ppEntry);
|
||||
static int32_t raftLogTruncate(struct SSyncLogStore* pLogStore, SyncIndex fromIndex);
|
||||
|
||||
// private function
|
||||
static int32_t raftLogGetLastEntry(SSyncLogStore* pLogStore, SSyncRaftEntry** ppLastEntry);
|
||||
|
||||
//-------------------------------
|
||||
// log[0 .. n]
|
||||
static SSyncRaftEntry* logStoreGetLastEntry(SSyncLogStore* pLogStore);
|
||||
static SyncIndex logStoreLastIndex(SSyncLogStore* pLogStore);
|
||||
static SyncTerm logStoreLastTerm(SSyncLogStore* pLogStore);
|
||||
|
@ -44,28 +47,86 @@ static int32_t logStoreTruncate(SSyncLogStore* pLogStore, SyncIndex from
|
|||
static int32_t logStoreUpdateCommitIndex(SSyncLogStore* pLogStore, SyncIndex index);
|
||||
static SyncIndex logStoreGetCommitIndex(SSyncLogStore* pLogStore);
|
||||
|
||||
// refactor, log[0 .. n] ==> log[m .. n]
|
||||
/*
|
||||
static int32_t raftLogSetBeginIndex(struct SSyncLogStore* pLogStore, SyncIndex beginIndex) {
|
||||
// if beginIndex == 0, donot need call this funciton
|
||||
ASSERT(beginIndex > 0);
|
||||
//-------------------------------
|
||||
SSyncLogStore* logStoreCreate(SSyncNode* pSyncNode) {
|
||||
SSyncLogStore* pLogStore = taosMemoryMalloc(sizeof(SSyncLogStore));
|
||||
ASSERT(pLogStore != NULL);
|
||||
|
||||
pLogStore->data = taosMemoryMalloc(sizeof(SSyncLogStoreData));
|
||||
ASSERT(pLogStore->data != NULL);
|
||||
|
||||
SSyncLogStoreData* pData = pLogStore->data;
|
||||
SWal* pWal = pData->pWal;
|
||||
sTrace("vgId:%d, reset wal begin index:%ld", pData->pSyncNode->vgId, beginIndex);
|
||||
pData->pSyncNode = pSyncNode;
|
||||
pData->pWal = pSyncNode->pWal;
|
||||
ASSERT(pData->pWal != NULL);
|
||||
|
||||
pData->beginIndex = beginIndex;
|
||||
walRestoreFromSnapshot(pWal, beginIndex - 1);
|
||||
return 0;
|
||||
taosThreadMutexInit(&(pData->mutex), NULL);
|
||||
pData->pWalHandle = walOpenReadHandle(pData->pWal);
|
||||
ASSERT(pData->pWalHandle != NULL);
|
||||
|
||||
pLogStore->appendEntry = logStoreAppendEntry;
|
||||
pLogStore->getEntry = logStoreGetEntry;
|
||||
pLogStore->truncate = logStoreTruncate;
|
||||
pLogStore->getLastIndex = logStoreLastIndex;
|
||||
pLogStore->getLastTerm = logStoreLastTerm;
|
||||
pLogStore->updateCommitIndex = logStoreUpdateCommitIndex;
|
||||
pLogStore->getCommitIndex = logStoreGetCommitIndex;
|
||||
|
||||
pLogStore->syncLogRestoreFromSnapshot = raftLogRestoreFromSnapshot;
|
||||
pLogStore->syncLogBeginIndex = raftLogBeginIndex;
|
||||
pLogStore->syncLogEndIndex = raftLogEndIndex;
|
||||
pLogStore->syncLogIsEmpty = raftLogIsEmpty;
|
||||
pLogStore->syncLogEntryCount = raftLogEntryCount;
|
||||
pLogStore->syncLogLastIndex = raftLogLastIndex;
|
||||
pLogStore->syncLogLastTerm = raftLogLastTerm;
|
||||
pLogStore->syncLogAppendEntry = raftLogAppendEntry;
|
||||
pLogStore->syncLogGetEntry = raftLogGetEntry;
|
||||
pLogStore->syncLogTruncate = raftLogTruncate;
|
||||
pLogStore->syncLogWriteIndex = raftLogWriteIndex;
|
||||
|
||||
return pLogStore;
|
||||
}
|
||||
*/
|
||||
|
||||
void logStoreDestory(SSyncLogStore* pLogStore) {
|
||||
if (pLogStore != NULL) {
|
||||
SSyncLogStoreData* pData = pLogStore->data;
|
||||
|
||||
taosThreadMutexLock(&(pData->mutex));
|
||||
if (pData->pWalHandle != NULL) {
|
||||
walCloseReadHandle(pData->pWalHandle);
|
||||
pData->pWalHandle = NULL;
|
||||
}
|
||||
taosThreadMutexUnlock(&(pData->mutex));
|
||||
taosThreadMutexDestroy(&(pData->mutex));
|
||||
|
||||
taosMemoryFree(pLogStore->data);
|
||||
taosMemoryFree(pLogStore);
|
||||
}
|
||||
}
|
||||
|
||||
//-------------------------------
|
||||
// log[m .. n]
|
||||
static int32_t raftLogRestoreFromSnapshot(struct SSyncLogStore* pLogStore, SyncIndex snapshotIndex) {
|
||||
ASSERT(snapshotIndex >= 0);
|
||||
|
||||
SSyncLogStoreData* pData = pLogStore->data;
|
||||
SWal* pWal = pData->pWal;
|
||||
walRestoreFromSnapshot(pWal, snapshotIndex);
|
||||
int32_t code = walRestoreFromSnapshot(pWal, snapshotIndex);
|
||||
if (code != 0) {
|
||||
int32_t err = terrno;
|
||||
const char* errStr = tstrerror(err);
|
||||
int32_t sysErr = errno;
|
||||
const char* sysErrStr = strerror(errno);
|
||||
|
||||
char logBuf[128];
|
||||
snprintf(logBuf, sizeof(logBuf),
|
||||
"wal restore from snapshot error, index:%ld, err:%d %X, msg:%s, syserr:%d, sysmsg:%s", snapshotIndex, err,
|
||||
err, errStr, sysErr, sysErrStr);
|
||||
syncNodeErrorLog(pData->pSyncNode, logBuf);
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -91,18 +152,6 @@ static int32_t raftLogEntryCount(struct SSyncLogStore* pLogStore) {
|
|||
return count > 0 ? count : 0;
|
||||
}
|
||||
|
||||
#if 0
|
||||
static bool raftLogInRange(struct SSyncLogStore* pLogStore, SyncIndex index) {
|
||||
SyncIndex beginIndex = raftLogBeginIndex(pLogStore);
|
||||
SyncIndex endIndex = raftLogEndIndex(pLogStore);
|
||||
if (index >= beginIndex && index <= endIndex) {
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
static SyncIndex raftLogLastIndex(struct SSyncLogStore* pLogStore) {
|
||||
SyncIndex lastIndex;
|
||||
SSyncLogStoreData* pData = pLogStore->data;
|
||||
|
@ -119,6 +168,9 @@ static SyncIndex raftLogWriteIndex(struct SSyncLogStore* pLogStore) {
|
|||
return lastVer + 1;
|
||||
}
|
||||
|
||||
// if success, return last term
|
||||
// if not log, return 0
|
||||
// if error, return SYNC_TERM_INVALID
|
||||
static SyncTerm raftLogLastTerm(struct SSyncLogStore* pLogStore) {
|
||||
SSyncLogStoreData* pData = pLogStore->data;
|
||||
SWal* pWal = pData->pWal;
|
||||
|
@ -127,34 +179,18 @@ static SyncTerm raftLogLastTerm(struct SSyncLogStore* pLogStore) {
|
|||
} else {
|
||||
SSyncRaftEntry* pLastEntry;
|
||||
int32_t code = raftLogGetLastEntry(pLogStore, &pLastEntry);
|
||||
ASSERT(code == 0);
|
||||
ASSERT(pLastEntry != NULL);
|
||||
|
||||
if (code == 0 && pLastEntry != NULL) {
|
||||
SyncTerm lastTerm = pLastEntry->term;
|
||||
taosMemoryFree(pLastEntry);
|
||||
return lastTerm;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
static SyncTerm raftLogLastTerm(struct SSyncLogStore* pLogStore) {
|
||||
SyncTerm lastTerm = 0;
|
||||
if (raftLogEntryCount(pLogStore) == 0) {
|
||||
lastTerm = 0;
|
||||
} else {
|
||||
SSyncRaftEntry* pLastEntry;
|
||||
int32_t code = raftLogGetLastEntry(pLogStore, &pLastEntry);
|
||||
ASSERT(code == 0);
|
||||
if (pLastEntry != NULL) {
|
||||
lastTerm = pLastEntry->term;
|
||||
taosMemoryFree(pLastEntry);
|
||||
return SYNC_TERM_INVALID;
|
||||
}
|
||||
}
|
||||
return lastTerm;
|
||||
|
||||
// can not be here!
|
||||
return SYNC_TERM_INVALID;
|
||||
}
|
||||
*/
|
||||
|
||||
static int32_t raftLogAppendEntry(struct SSyncLogStore* pLogStore, SSyncRaftEntry* pEntry) {
|
||||
SSyncLogStoreData* pData = pLogStore->data;
|
||||
|
@ -187,63 +223,21 @@ static int32_t raftLogAppendEntry(struct SSyncLogStore* pLogStore, SSyncRaftEntr
|
|||
ASSERT(0);
|
||||
}
|
||||
|
||||
walFsync(pWal, true);
|
||||
// walFsync(pWal, true);
|
||||
|
||||
do {
|
||||
char eventLog[128];
|
||||
snprintf(eventLog, sizeof(eventLog), "write index:%ld, type:%s,%d, type2:%s,%d", pEntry->index,
|
||||
TMSG_INFO(pEntry->msgType), pEntry->msgType, TMSG_INFO(pEntry->originalRpcType), pEntry->originalRpcType);
|
||||
syncNodeEventLog(pData->pSyncNode, eventLog);
|
||||
} while (0);
|
||||
|
||||
return code;
|
||||
}
|
||||
|
||||
#if 0
|
||||
static int32_t raftLogGetEntry(struct SSyncLogStore* pLogStore, SyncIndex index, SSyncRaftEntry** ppEntry) {
|
||||
SSyncLogStoreData* pData = pLogStore->data;
|
||||
SWal* pWal = pData->pWal;
|
||||
int32_t code;
|
||||
|
||||
*ppEntry = NULL;
|
||||
if (raftLogInRange(pLogStore, index)) {
|
||||
SWalReadHandle* pWalHandle = walOpenReadHandle(pWal);
|
||||
ASSERT(pWalHandle != NULL);
|
||||
|
||||
code = walReadWithHandle(pWalHandle, index);
|
||||
if (code != 0) {
|
||||
int32_t err = terrno;
|
||||
const char* errStr = tstrerror(err);
|
||||
int32_t linuxErr = errno;
|
||||
const char* linuxErrMsg = strerror(errno);
|
||||
sError("raftLogGetEntry error, err:%d %X, msg:%s, linuxErr:%d, linuxErrMsg:%s", err, err, errStr, linuxErr,
|
||||
linuxErrMsg);
|
||||
ASSERT(0);
|
||||
walCloseReadHandle(pWalHandle);
|
||||
return code;
|
||||
}
|
||||
|
||||
*ppEntry = syncEntryBuild(pWalHandle->pHead->head.bodyLen);
|
||||
ASSERT(*ppEntry != NULL);
|
||||
(*ppEntry)->msgType = TDMT_SYNC_CLIENT_REQUEST;
|
||||
(*ppEntry)->originalRpcType = pWalHandle->pHead->head.msgType;
|
||||
(*ppEntry)->seqNum = pWalHandle->pHead->head.syncMeta.seqNum;
|
||||
(*ppEntry)->isWeak = pWalHandle->pHead->head.syncMeta.isWeek;
|
||||
(*ppEntry)->term = pWalHandle->pHead->head.syncMeta.term;
|
||||
(*ppEntry)->index = index;
|
||||
ASSERT((*ppEntry)->dataLen == pWalHandle->pHead->head.bodyLen);
|
||||
memcpy((*ppEntry)->data, pWalHandle->pHead->head.body, pWalHandle->pHead->head.bodyLen);
|
||||
|
||||
// need to hold, do not new every time!!
|
||||
walCloseReadHandle(pWalHandle);
|
||||
|
||||
} else {
|
||||
// index not in range
|
||||
code = 0;
|
||||
}
|
||||
|
||||
return code;
|
||||
}
|
||||
#endif
|
||||
|
||||
// entry found, return 0
|
||||
// entry not found, return -1, terrno = TSDB_CODE_WAL_LOG_NOT_EXIST
|
||||
// other error, return -1
|
||||
static int32_t raftLogGetEntry(struct SSyncLogStore* pLogStore, SyncIndex index, SSyncRaftEntry** ppEntry) {
|
||||
SSyncLogStoreData* pData = pLogStore->data;
|
||||
SWal* pWal = pData->pWal;
|
||||
|
@ -254,6 +248,7 @@ static int32_t raftLogGetEntry(struct SSyncLogStore* pLogStore, SyncIndex index,
|
|||
// SWalReadHandle* pWalHandle = walOpenReadHandle(pWal);
|
||||
SWalReadHandle* pWalHandle = pData->pWalHandle;
|
||||
if (pWalHandle == NULL) {
|
||||
terrno = TSDB_CODE_SYN_INTERNAL_ERROR;
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
@ -325,6 +320,9 @@ static int32_t raftLogTruncate(struct SSyncLogStore* pLogStore, SyncIndex fromIn
|
|||
return code;
|
||||
}
|
||||
|
||||
// entry found, return 0
|
||||
// entry not found, return -1, terrno = TSDB_CODE_WAL_LOG_NOT_EXIST
|
||||
// other error, return -1
|
||||
static int32_t raftLogGetLastEntry(SSyncLogStore* pLogStore, SSyncRaftEntry** ppLastEntry) {
|
||||
SSyncLogStoreData* pData = pLogStore->data;
|
||||
SWal* pWal = pData->pWal;
|
||||
|
@ -336,6 +334,7 @@ static int32_t raftLogGetLastEntry(SSyncLogStore* pLogStore, SSyncRaftEntry** pp
|
|||
return -1;
|
||||
} else {
|
||||
SyncIndex lastIndex = raftLogLastIndex(pLogStore);
|
||||
ASSERT(lastIndex >= SYNC_INDEX_BEGIN);
|
||||
int32_t code = raftLogGetEntry(pLogStore, lastIndex, ppLastEntry);
|
||||
return code;
|
||||
}
|
||||
|
@ -343,91 +342,8 @@ static int32_t raftLogGetLastEntry(SSyncLogStore* pLogStore, SSyncRaftEntry** pp
|
|||
return -1;
|
||||
}
|
||||
|
||||
/*
|
||||
static int32_t raftLogGetLastEntry(SSyncLogStore* pLogStore, SSyncRaftEntry** ppLastEntry) {
|
||||
*ppLastEntry = NULL;
|
||||
if (raftLogEntryCount(pLogStore) == 0) {
|
||||
return 0;
|
||||
}
|
||||
SyncIndex lastIndex = raftLogLastIndex(pLogStore);
|
||||
int32_t code = raftLogGetEntry(pLogStore, lastIndex, ppLastEntry);
|
||||
return code;
|
||||
}
|
||||
*/
|
||||
|
||||
//-------------------------------
|
||||
SSyncLogStore* logStoreCreate(SSyncNode* pSyncNode) {
|
||||
SSyncLogStore* pLogStore = taosMemoryMalloc(sizeof(SSyncLogStore));
|
||||
ASSERT(pLogStore != NULL);
|
||||
|
||||
pLogStore->data = taosMemoryMalloc(sizeof(SSyncLogStoreData));
|
||||
ASSERT(pLogStore->data != NULL);
|
||||
|
||||
SSyncLogStoreData* pData = pLogStore->data;
|
||||
pData->pSyncNode = pSyncNode;
|
||||
pData->pWal = pSyncNode->pWal;
|
||||
ASSERT(pData->pWal != NULL);
|
||||
|
||||
taosThreadMutexInit(&(pData->mutex), NULL);
|
||||
pData->pWalHandle = walOpenReadHandle(pData->pWal);
|
||||
ASSERT(pData->pWalHandle != NULL);
|
||||
|
||||
/*
|
||||
SyncIndex firstVer = walGetFirstVer(pData->pWal);
|
||||
SyncIndex lastVer = walGetLastVer(pData->pWal);
|
||||
if (firstVer >= 0) {
|
||||
pData->beginIndex = firstVer;
|
||||
} else if (firstVer == -1) {
|
||||
pData->beginIndex = lastVer + 1;
|
||||
} else {
|
||||
ASSERT(0);
|
||||
}
|
||||
*/
|
||||
|
||||
pLogStore->appendEntry = logStoreAppendEntry;
|
||||
pLogStore->getEntry = logStoreGetEntry;
|
||||
pLogStore->truncate = logStoreTruncate;
|
||||
pLogStore->getLastIndex = logStoreLastIndex;
|
||||
pLogStore->getLastTerm = logStoreLastTerm;
|
||||
pLogStore->updateCommitIndex = logStoreUpdateCommitIndex;
|
||||
pLogStore->getCommitIndex = logStoreGetCommitIndex;
|
||||
|
||||
// pLogStore->syncLogSetBeginIndex = raftLogSetBeginIndex;
|
||||
pLogStore->syncLogRestoreFromSnapshot = raftLogRestoreFromSnapshot;
|
||||
pLogStore->syncLogBeginIndex = raftLogBeginIndex;
|
||||
pLogStore->syncLogEndIndex = raftLogEndIndex;
|
||||
pLogStore->syncLogIsEmpty = raftLogIsEmpty;
|
||||
pLogStore->syncLogEntryCount = raftLogEntryCount;
|
||||
pLogStore->syncLogLastIndex = raftLogLastIndex;
|
||||
pLogStore->syncLogLastTerm = raftLogLastTerm;
|
||||
pLogStore->syncLogAppendEntry = raftLogAppendEntry;
|
||||
pLogStore->syncLogGetEntry = raftLogGetEntry;
|
||||
pLogStore->syncLogTruncate = raftLogTruncate;
|
||||
pLogStore->syncLogWriteIndex = raftLogWriteIndex;
|
||||
|
||||
// pLogStore->syncLogInRange = raftLogInRange;
|
||||
|
||||
return pLogStore;
|
||||
}
|
||||
|
||||
void logStoreDestory(SSyncLogStore* pLogStore) {
|
||||
if (pLogStore != NULL) {
|
||||
SSyncLogStoreData* pData = pLogStore->data;
|
||||
|
||||
taosThreadMutexLock(&(pData->mutex));
|
||||
if (pData->pWalHandle != NULL) {
|
||||
walCloseReadHandle(pData->pWalHandle);
|
||||
pData->pWalHandle = NULL;
|
||||
}
|
||||
taosThreadMutexUnlock(&(pData->mutex));
|
||||
taosThreadMutexDestroy(&(pData->mutex));
|
||||
|
||||
taosMemoryFree(pLogStore->data);
|
||||
taosMemoryFree(pLogStore);
|
||||
}
|
||||
}
|
||||
|
||||
//-------------------------------
|
||||
// log[0 .. n]
|
||||
int32_t logStoreAppendEntry(SSyncLogStore* pLogStore, SSyncRaftEntry* pEntry) {
|
||||
SSyncLogStoreData* pData = pLogStore->data;
|
||||
SWal* pWal = pData->pWal;
|
||||
|
@ -455,7 +371,7 @@ int32_t logStoreAppendEntry(SSyncLogStore* pLogStore, SSyncRaftEntry* pEntry) {
|
|||
ASSERT(0);
|
||||
}
|
||||
|
||||
walFsync(pWal, true);
|
||||
// walFsync(pWal, true);
|
||||
|
||||
char eventLog[128];
|
||||
snprintf(eventLog, sizeof(eventLog), "old write index:%ld, type:%s,%d, type2:%s,%d", pEntry->index,
|
||||
|
@ -593,55 +509,6 @@ SSyncRaftEntry* logStoreGetLastEntry(SSyncLogStore* pLogStore) {
|
|||
return pEntry;
|
||||
}
|
||||
|
||||
/*
|
||||
cJSON* logStore2Json(SSyncLogStore* pLogStore) {
|
||||
char u64buf[128] = {0};
|
||||
SSyncLogStoreData* pData = (SSyncLogStoreData*)pLogStore->data;
|
||||
cJSON* pRoot = cJSON_CreateObject();
|
||||
|
||||
if (pData != NULL && pData->pWal != NULL) {
|
||||
snprintf(u64buf, sizeof(u64buf), "%p", pData->pSyncNode);
|
||||
cJSON_AddStringToObject(pRoot, "pSyncNode", u64buf);
|
||||
snprintf(u64buf, sizeof(u64buf), "%p", pData->pWal);
|
||||
cJSON_AddStringToObject(pRoot, "pWal", u64buf);
|
||||
|
||||
snprintf(u64buf, sizeof(u64buf), "%ld", pData->beginIndex);
|
||||
cJSON_AddStringToObject(pRoot, "beginIndex", u64buf);
|
||||
|
||||
SyncIndex endIndex = raftLogEndIndex(pLogStore);
|
||||
snprintf(u64buf, sizeof(u64buf), "%ld", endIndex);
|
||||
cJSON_AddStringToObject(pRoot, "endIndex", u64buf);
|
||||
|
||||
int32_t count = raftLogEntryCount(pLogStore);
|
||||
cJSON_AddNumberToObject(pRoot, "entryCount", count);
|
||||
|
||||
snprintf(u64buf, sizeof(u64buf), "%ld", raftLogWriteIndex(pLogStore));
|
||||
cJSON_AddStringToObject(pRoot, "WriteIndex", u64buf);
|
||||
|
||||
snprintf(u64buf, sizeof(u64buf), "%d", raftLogIsEmpty(pLogStore));
|
||||
cJSON_AddStringToObject(pRoot, "IsEmpty", u64buf);
|
||||
|
||||
snprintf(u64buf, sizeof(u64buf), "%ld", raftLogLastIndex(pLogStore));
|
||||
cJSON_AddStringToObject(pRoot, "LastIndex", u64buf);
|
||||
snprintf(u64buf, sizeof(u64buf), "%lu", raftLogLastTerm(pLogStore));
|
||||
cJSON_AddStringToObject(pRoot, "LastTerm", u64buf);
|
||||
|
||||
cJSON* pEntries = cJSON_CreateArray();
|
||||
cJSON_AddItemToObject(pRoot, "pEntries", pEntries);
|
||||
|
||||
for (SyncIndex i = pData->beginIndex; i <= endIndex; ++i) {
|
||||
SSyncRaftEntry* pEntry = logStoreGetEntry(pLogStore, i);
|
||||
cJSON_AddItemToArray(pEntries, syncEntry2Json(pEntry));
|
||||
syncEntryDestory(pEntry);
|
||||
}
|
||||
}
|
||||
|
||||
cJSON* pJson = cJSON_CreateObject();
|
||||
cJSON_AddItemToObject(pJson, "SSyncLogStore", pRoot);
|
||||
return pJson;
|
||||
}
|
||||
*/
|
||||
|
||||
cJSON* logStore2Json(SSyncLogStore* pLogStore) {
|
||||
char u64buf[128] = {0};
|
||||
SSyncLogStoreData* pData = (SSyncLogStoreData*)pLogStore->data;
|
||||
|
|
|
@ -156,6 +156,10 @@ static bool syncNodeOnRequestVoteLogOK(SSyncNode* pSyncNode, SyncRequestVote* pM
|
|||
SyncTerm myLastTerm = syncNodeGetLastTerm(pSyncNode);
|
||||
SyncIndex myLastIndex = syncNodeGetLastIndex(pSyncNode);
|
||||
|
||||
if (myLastTerm == SYNC_TERM_INVALID) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (pMsg->lastLogTerm > myLastTerm) {
|
||||
return true;
|
||||
}
|
||||
|
|
|
@ -508,31 +508,50 @@ void snapshotReceiverStop(SSyncSnapshotReceiver *pReceiver) {
|
|||
} while (0);
|
||||
}
|
||||
|
||||
static void snapshotReceiverFinish(SSyncSnapshotReceiver *pReceiver, SyncSnapshotSend *pMsg) {
|
||||
static int32_t snapshotReceiverFinish(SSyncSnapshotReceiver *pReceiver, SyncSnapshotSend *pMsg) {
|
||||
ASSERT(pMsg->seq == SYNC_SNAPSHOT_SEQ_END);
|
||||
|
||||
if (pReceiver->pWriter != NULL) {
|
||||
int32_t code = 0;
|
||||
if (pReceiver->pWriter != NULL) {
|
||||
// write data
|
||||
if (pMsg->dataLen > 0) {
|
||||
code = pReceiver->pSyncNode->pFsm->FpSnapshotDoWrite(pReceiver->pSyncNode->pFsm, pReceiver->pWriter, pMsg->data,
|
||||
pMsg->dataLen);
|
||||
ASSERT(code == 0);
|
||||
if (code != 0) {
|
||||
syncNodeErrorLog(pReceiver->pSyncNode, "snapshot write error");
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
code = pReceiver->pSyncNode->pFsm->FpSnapshotStopWrite(pReceiver->pSyncNode->pFsm, pReceiver->pWriter, true);
|
||||
ASSERT(code == 0);
|
||||
pReceiver->pWriter = NULL;
|
||||
// reset wal
|
||||
code =
|
||||
pReceiver->pSyncNode->pLogStore->syncLogRestoreFromSnapshot(pReceiver->pSyncNode->pLogStore, pMsg->lastIndex);
|
||||
if (code != 0) {
|
||||
syncNodeErrorLog(pReceiver->pSyncNode, "wal restore from snapshot error");
|
||||
return -1;
|
||||
}
|
||||
|
||||
pReceiver->ack = SYNC_SNAPSHOT_SEQ_END;
|
||||
|
||||
// update commit index
|
||||
if (pReceiver->snapshot.lastApplyIndex > pReceiver->pSyncNode->commitIndex) {
|
||||
pReceiver->pSyncNode->commitIndex = pReceiver->snapshot.lastApplyIndex;
|
||||
}
|
||||
|
||||
// reset wal
|
||||
pReceiver->pSyncNode->pLogStore->syncLogRestoreFromSnapshot(pReceiver->pSyncNode->pLogStore, pMsg->lastIndex);
|
||||
// stop writer
|
||||
code = pReceiver->pSyncNode->pFsm->FpSnapshotStopWrite(pReceiver->pSyncNode->pFsm, pReceiver->pWriter, true);
|
||||
if (code != 0) {
|
||||
syncNodeErrorLog(pReceiver->pSyncNode, "snapshot stop writer true error");
|
||||
ASSERT(0);
|
||||
return -1;
|
||||
}
|
||||
pReceiver->pWriter = NULL;
|
||||
|
||||
// update progress
|
||||
pReceiver->ack = SYNC_SNAPSHOT_SEQ_END;
|
||||
|
||||
} else {
|
||||
syncNodeErrorLog(pReceiver->pSyncNode, "snapshot stop writer true error");
|
||||
return -1;
|
||||
}
|
||||
|
||||
// event log
|
||||
do {
|
||||
|
@ -542,6 +561,8 @@ static void snapshotReceiverFinish(SSyncSnapshotReceiver *pReceiver, SyncSnapsho
|
|||
syncNodeEventLog(pReceiver->pSyncNode, eventLog);
|
||||
taosMemoryFree(eventLog);
|
||||
} while (0);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void snapshotReceiverGotData(SSyncSnapshotReceiver *pReceiver, SyncSnapshotSend *pMsg) {
|
||||
|
@ -642,6 +663,7 @@ int32_t syncNodeOnSnapshotSendCb(SSyncNode *pSyncNode, SyncSnapshotSend *pMsg) {
|
|||
// get receiver
|
||||
SSyncSnapshotReceiver *pReceiver = pSyncNode->pNewNodeReceiver;
|
||||
bool needRsp = false;
|
||||
int32_t code = 0;
|
||||
|
||||
// state, term, seq/ack
|
||||
if (pSyncNode->state == TAOS_SYNC_STATE_FOLLOWER) {
|
||||
|
@ -653,8 +675,10 @@ int32_t syncNodeOnSnapshotSendCb(SSyncNode *pSyncNode, SyncSnapshotSend *pMsg) {
|
|||
|
||||
} else if (pMsg->seq == SYNC_SNAPSHOT_SEQ_END) {
|
||||
// end, finish FSM
|
||||
snapshotReceiverFinish(pReceiver, pMsg);
|
||||
code = snapshotReceiverFinish(pReceiver, pMsg);
|
||||
if (code == 0) {
|
||||
snapshotReceiverStop(pReceiver);
|
||||
}
|
||||
needRsp = true;
|
||||
|
||||
// maybe update lastconfig
|
||||
|
@ -772,6 +796,7 @@ int32_t syncNodeOnSnapshotRspCb(SSyncNode *pSyncNode, SyncSnapshotRsp *pMsg) {
|
|||
snapshotReSend(pSender);
|
||||
|
||||
} else {
|
||||
// error log
|
||||
do {
|
||||
char logBuf[96];
|
||||
snprintf(logBuf, sizeof(logBuf), "snapshot sender recv error ack:%d, my seq:%d", pMsg->ack, pSender->seq);
|
||||
|
|
|
@ -148,6 +148,7 @@ typedef struct {
|
|||
char release : 2;
|
||||
char secured : 2;
|
||||
char spi : 2;
|
||||
char hasEpSet : 2; // contain epset or not, 0(default): no epset, 1: contain epset
|
||||
|
||||
char user[TSDB_UNI_LEN];
|
||||
STraceId traceId;
|
||||
|
@ -252,7 +253,7 @@ int transAsyncSend(SAsyncPool* pool, queue* mq);
|
|||
do { \
|
||||
if (id > 0) { \
|
||||
tTrace("handle step1"); \
|
||||
SExHandle* exh2 = transAcquireExHandle(refMgt, id); \
|
||||
SExHandle* exh2 = transAcquireExHandle(id); \
|
||||
if (exh2 == NULL || id != exh2->refId) { \
|
||||
tTrace("handle %p except, may already freed, ignore msg, ref1: %" PRIu64 ", ref2 : %" PRIu64 "", exh1, \
|
||||
exh2 ? exh2->refId : 0, id); \
|
||||
|
@ -260,7 +261,7 @@ int transAsyncSend(SAsyncPool* pool, queue* mq);
|
|||
} \
|
||||
} else if (id == 0) { \
|
||||
tTrace("handle step2"); \
|
||||
SExHandle* exh2 = transAcquireExHandle(refMgt, id); \
|
||||
SExHandle* exh2 = transAcquireExHandle(id); \
|
||||
if (exh2 == NULL || id == exh2->refId) { \
|
||||
tTrace("handle %p except, may already freed, ignore msg, ref1: %" PRIu64 ", ref2 : %" PRIu64 "", exh1, id, \
|
||||
exh2 ? exh2->refId : 0); \
|
||||
|
@ -273,6 +274,7 @@ int transAsyncSend(SAsyncPool* pool, queue* mq);
|
|||
goto _return2; \
|
||||
} \
|
||||
} while (0)
|
||||
|
||||
int transInitBuffer(SConnBuffer* buf);
|
||||
int transClearBuffer(SConnBuffer* buf);
|
||||
int transDestroyBuffer(SConnBuffer* buf);
|
||||
|
@ -294,7 +296,6 @@ void transSendRequest(void* shandle, const SEpSet* pEpSet, STransMsg* pMsg, STra
|
|||
void transSendRecv(void* shandle, const SEpSet* pEpSet, STransMsg* pMsg, STransMsg* pRsp);
|
||||
void transSendResponse(const STransMsg* msg);
|
||||
void transRegisterMsg(const STransMsg* msg);
|
||||
int transGetConnInfo(void* thandle, STransHandleInfo* pInfo);
|
||||
void transSetDefaultAddr(void* shandle, const char* ip, const char* fqdn);
|
||||
|
||||
void* transInitServer(uint32_t ip, uint32_t port, char* label, int numOfThreads, void* fp, void* shandle);
|
||||
|
@ -378,25 +379,24 @@ typedef struct SDelayQueue {
|
|||
} SDelayQueue;
|
||||
|
||||
int transDQCreate(uv_loop_t* loop, SDelayQueue** queue);
|
||||
|
||||
void transDQDestroy(SDelayQueue* queue);
|
||||
|
||||
int transDQSched(SDelayQueue* queue, void (*func)(void* arg), void* arg, uint64_t timeoutMs);
|
||||
|
||||
// void transPrintEpSet(SEpSet* pEpSet);
|
||||
bool transEpSetIsEqual(SEpSet* a, SEpSet* b);
|
||||
/*
|
||||
* init global func
|
||||
*/
|
||||
void transThreadOnce();
|
||||
|
||||
void transInitEnv();
|
||||
void transInit();
|
||||
void transCleanup();
|
||||
|
||||
int32_t transOpenExHandleMgt(int size);
|
||||
void transCloseExHandleMgt(int32_t mgt);
|
||||
int64_t transAddExHandle(int32_t mgt, void* p);
|
||||
int32_t transRemoveExHandle(int32_t mgt, int64_t refId);
|
||||
SExHandle* transAcquireExHandle(int32_t mgt, int64_t refId);
|
||||
int32_t transReleaseExHandle(int32_t mgt, int64_t refId);
|
||||
void transCloseExHandleMgt();
|
||||
int64_t transAddExHandle(void* p);
|
||||
int32_t transRemoveExHandle(int64_t refId);
|
||||
SExHandle* transAcquireExHandle(int64_t refId);
|
||||
int32_t transReleaseExHandle(int64_t refId);
|
||||
void transDestoryExHandle(void* handle);
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
|
|
@ -36,7 +36,7 @@ static int32_t transValidLocalFqdn(const char* localFqdn, uint32_t* ip) {
|
|||
return 0;
|
||||
}
|
||||
void* rpcOpen(const SRpcInit* pInit) {
|
||||
transInitEnv();
|
||||
rpcInit();
|
||||
|
||||
SRpcInfo* pRpc = taosMemoryCalloc(1, sizeof(SRpcInfo));
|
||||
if (pRpc == NULL) {
|
||||
|
@ -82,8 +82,8 @@ void rpcClose(void* arg) {
|
|||
tInfo("start to close rpc");
|
||||
SRpcInfo* pRpc = (SRpcInfo*)arg;
|
||||
(*taosCloseHandle[pRpc->connType])(pRpc->tcphandle);
|
||||
transCloseExHandleMgt(pRpc->refMgt);
|
||||
taosMemoryFree(pRpc);
|
||||
tInfo("finish to close rpc");
|
||||
|
||||
return;
|
||||
}
|
||||
|
@ -141,7 +141,9 @@ void rpcSendRecv(void* shandle, SEpSet* pEpSet, SRpcMsg* pMsg, SRpcMsg* pRsp) {
|
|||
}
|
||||
|
||||
void rpcSendResponse(const SRpcMsg* pMsg) { transSendResponse(pMsg); }
|
||||
int32_t rpcGetConnInfo(void* thandle, SRpcConnInfo* pInfo) { return transGetConnInfo((void*)thandle, pInfo); }
|
||||
|
||||
int32_t rpcGetConnInfo(void* thandle, SRpcConnInfo* pInfo) { return 0; }
|
||||
|
||||
|
||||
void rpcRefHandle(void* handle, int8_t type) {
|
||||
assert(type == TAOS_CONN_SERVER || type == TAOS_CONN_CLIENT);
|
||||
|
@ -165,11 +167,11 @@ void rpcSetDefaultAddr(void* thandle, const char* ip, const char* fqdn) {
|
|||
}
|
||||
|
||||
int32_t rpcInit() {
|
||||
// impl later
|
||||
transInit();
|
||||
return 0;
|
||||
}
|
||||
void rpcCleanup(void) {
|
||||
// impl later
|
||||
transCleanup();
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
|
@ -15,9 +15,6 @@
|
|||
#ifdef USE_UV
|
||||
#include "transComm.h"
|
||||
|
||||
static int32_t transSCliInst = 0;
|
||||
static int32_t refMgt = 0;
|
||||
|
||||
typedef struct SCliConn {
|
||||
T_REF_DECLARE()
|
||||
uv_connect_t connReq;
|
||||
|
@ -312,6 +309,7 @@ void cliHandleResp(SCliConn* conn) {
|
|||
transMsg.msgType = pHead->msgType;
|
||||
transMsg.info.ahandle = NULL;
|
||||
transMsg.info.traceId = pHead->traceId;
|
||||
transMsg.info.hasEpSet = pHead->hasEpSet;
|
||||
|
||||
SCliMsg* pMsg = NULL;
|
||||
STransConnCtx* pCtx = NULL;
|
||||
|
@ -319,8 +317,9 @@ void cliHandleResp(SCliConn* conn) {
|
|||
|
||||
if (CONN_NO_PERSIST_BY_APP(conn)) {
|
||||
pMsg = transQueuePop(&conn->cliMsgs);
|
||||
pCtx = pMsg->ctx;
|
||||
transMsg.info.ahandle = pCtx->ahandle;
|
||||
|
||||
pCtx = pMsg ? pMsg->ctx : NULL;
|
||||
transMsg.info.ahandle = pCtx ? pCtx->ahandle : NULL;
|
||||
tDebug("%s conn %p get ahandle %p, persist: 0", CONN_GET_INST_LABEL(conn), conn, transMsg.info.ahandle);
|
||||
} else {
|
||||
uint64_t ahandle = (uint64_t)pHead->ahandle;
|
||||
|
@ -467,7 +466,6 @@ void* destroyConnPool(void* pool) {
|
|||
while (connList != NULL) {
|
||||
while (!QUEUE_IS_EMPTY(&connList->conn)) {
|
||||
queue* h = QUEUE_HEAD(&connList->conn);
|
||||
// QUEUE_REMOVE(h);
|
||||
SCliConn* c = QUEUE_DATA(h, SCliConn, conn);
|
||||
cliDestroyConn(c, true);
|
||||
}
|
||||
|
@ -503,12 +501,13 @@ static SCliConn* getConnFromPool(void* pool, char* ip, uint32_t port) {
|
|||
}
|
||||
static void allocConnRef(SCliConn* conn, bool update) {
|
||||
if (update) {
|
||||
transRemoveExHandle(refMgt, conn->refId);
|
||||
transRemoveExHandle(conn->refId);
|
||||
conn->refId = -1;
|
||||
}
|
||||
SExHandle* exh = taosMemoryCalloc(1, sizeof(SExHandle));
|
||||
exh->handle = conn;
|
||||
exh->pThrd = conn->hostThrd;
|
||||
exh->refId = transAddExHandle(refMgt, exh);
|
||||
exh->refId = transAddExHandle(exh);
|
||||
conn->refId = exh->refId;
|
||||
}
|
||||
static void addConnToPool(void* pool, SCliConn* conn) {
|
||||
|
@ -602,14 +601,26 @@ static void cliDestroyConn(SCliConn* conn, bool clear) {
|
|||
tTrace("%s conn %p remove from conn pool", CONN_GET_INST_LABEL(conn), conn);
|
||||
QUEUE_REMOVE(&conn->conn);
|
||||
QUEUE_INIT(&conn->conn);
|
||||
transRemoveExHandle(refMgt, conn->refId);
|
||||
transRemoveExHandle(conn->refId);
|
||||
conn->refId = -1;
|
||||
|
||||
if (clear) {
|
||||
if (!uv_is_closing((uv_handle_t*)conn->stream)) {
|
||||
uv_close((uv_handle_t*)conn->stream, cliDestroy);
|
||||
} else {
|
||||
cliDestroy((uv_handle_t*)conn->stream);
|
||||
}
|
||||
}
|
||||
}
|
||||
static void cliDestroy(uv_handle_t* handle) {
|
||||
if (uv_handle_get_type(handle) != UV_TCP || handle->data == NULL) {
|
||||
return;
|
||||
}
|
||||
|
||||
SCliConn* conn = handle->data;
|
||||
transRemoveExHandle(conn->refId);
|
||||
taosMemoryFree(conn->ip);
|
||||
conn->stream->data = NULL;
|
||||
taosMemoryFree(conn->stream);
|
||||
transCtxCleanup(&conn->ctx);
|
||||
transQueueDestroy(&conn->cliMsgs);
|
||||
|
@ -735,7 +746,7 @@ static void cliHandleQuit(SCliMsg* pMsg, SCliThrd* pThrd) {
|
|||
}
|
||||
static void cliHandleRelease(SCliMsg* pMsg, SCliThrd* pThrd) {
|
||||
int64_t refId = (int64_t)(pMsg->msg.info.handle);
|
||||
SExHandle* exh = transAcquireExHandle(refMgt, refId);
|
||||
SExHandle* exh = transAcquireExHandle(refId);
|
||||
if (exh == NULL) {
|
||||
tDebug("%" PRId64 " already release", refId);
|
||||
}
|
||||
|
@ -761,7 +772,7 @@ SCliConn* cliGetConn(SCliMsg* pMsg, SCliThrd* pThrd, bool* ignore) {
|
|||
SCliConn* conn = NULL;
|
||||
int64_t refId = (int64_t)(pMsg->msg.info.handle);
|
||||
if (refId != 0) {
|
||||
SExHandle* exh = transAcquireExHandle(refMgt, refId);
|
||||
SExHandle* exh = transAcquireExHandle(refId);
|
||||
if (exh == NULL) {
|
||||
*ignore = true;
|
||||
destroyCmsg(pMsg);
|
||||
|
@ -769,7 +780,7 @@ SCliConn* cliGetConn(SCliMsg* pMsg, SCliThrd* pThrd, bool* ignore) {
|
|||
// assert(0);
|
||||
} else {
|
||||
conn = exh->handle;
|
||||
transReleaseExHandle(refMgt, refId);
|
||||
transReleaseExHandle(refId);
|
||||
}
|
||||
return conn;
|
||||
};
|
||||
|
@ -899,10 +910,6 @@ void* transInitClient(uint32_t ip, uint32_t port, char* label, int numOfThreads,
|
|||
}
|
||||
cli->pThreadObj[i] = pThrd;
|
||||
}
|
||||
int ref = atomic_add_fetch_32(&transSCliInst, 1);
|
||||
if (ref == 1) {
|
||||
refMgt = transOpenExHandleMgt(50000);
|
||||
}
|
||||
|
||||
return cli;
|
||||
}
|
||||
|
@ -971,7 +978,7 @@ void cliSendQuit(SCliThrd* thrd) {
|
|||
}
|
||||
void cliWalkCb(uv_handle_t* handle, void* arg) {
|
||||
if (!uv_is_closing(handle)) {
|
||||
uv_close(handle, NULL);
|
||||
uv_close(handle, cliDestroy);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1014,6 +1021,23 @@ void cliCompareAndSwap(int8_t* val, int8_t exp, int8_t newVal) {
|
|||
*val = newVal;
|
||||
}
|
||||
}
|
||||
|
||||
bool cliTryToExtractEpSet(STransMsg* pResp, SEpSet* dst) {
|
||||
if (pResp == NULL || pResp->info.hasEpSet == 0) {
|
||||
return false;
|
||||
}
|
||||
tDeserializeSEpSet(pResp->pCont, pResp->contLen, dst);
|
||||
int32_t tlen = tSerializeSEpSet(NULL, 0, dst);
|
||||
|
||||
int32_t bufLen = pResp->contLen - tlen;
|
||||
char* buf = rpcMallocCont(bufLen);
|
||||
|
||||
memcpy(buf, (char*)pResp->pCont + tlen, bufLen);
|
||||
|
||||
pResp->pCont = buf;
|
||||
pResp->contLen = bufLen;
|
||||
return true;
|
||||
}
|
||||
int cliAppCb(SCliConn* pConn, STransMsg* pResp, SCliMsg* pMsg) {
|
||||
SCliThrd* pThrd = pConn->hostThrd;
|
||||
STrans* pTransInst = pThrd->pTransInst;
|
||||
|
@ -1058,6 +1082,12 @@ int cliAppCb(SCliConn* pConn, STransMsg* pResp, SCliMsg* pMsg) {
|
|||
}
|
||||
|
||||
STraceId* trace = &pResp->info.traceId;
|
||||
|
||||
if (cliTryToExtractEpSet(pResp, &pCtx->epSet)) {
|
||||
char tbuf[256] = {0};
|
||||
EPSET_DEBUG_STR(&pCtx->epSet, tbuf);
|
||||
tGTrace("%s conn %p extract epset from msg", CONN_GET_INST_LABEL(pConn), pConn);
|
||||
}
|
||||
if (pCtx->pSem != NULL) {
|
||||
tGTrace("%s conn %p(sync) handle resp", CONN_GET_INST_LABEL(pConn), pConn);
|
||||
if (pCtx->pRsp == NULL) {
|
||||
|
@ -1086,10 +1116,6 @@ void transCloseClient(void* arg) {
|
|||
}
|
||||
taosMemoryFree(cli->pThreadObj);
|
||||
taosMemoryFree(cli);
|
||||
int ref = atomic_sub_fetch_32(&transSCliInst, 1);
|
||||
if (ref == 0) {
|
||||
transCloseExHandleMgt(refMgt);
|
||||
}
|
||||
}
|
||||
void transRefCliHandle(void* handle) {
|
||||
if (handle == NULL) {
|
||||
|
@ -1111,12 +1137,12 @@ void transUnrefCliHandle(void* handle) {
|
|||
}
|
||||
SCliThrd* transGetWorkThrdFromHandle(int64_t handle) {
|
||||
SCliThrd* pThrd = NULL;
|
||||
SExHandle* exh = transAcquireExHandle(refMgt, handle);
|
||||
SExHandle* exh = transAcquireExHandle(handle);
|
||||
if (exh == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
pThrd = exh->pThrd;
|
||||
transReleaseExHandle(refMgt, handle);
|
||||
transReleaseExHandle(handle);
|
||||
return pThrd;
|
||||
}
|
||||
SCliThrd* transGetWorkThrd(STrans* trans, int64_t handle) {
|
||||
|
|
|
@ -16,7 +16,9 @@
|
|||
|
||||
#include "transComm.h"
|
||||
|
||||
// static TdThreadOnce transModuleInit = PTHREAD_ONCE_INIT;
|
||||
static TdThreadOnce transModuleInit = PTHREAD_ONCE_INIT;
|
||||
|
||||
static int32_t refMgt;
|
||||
|
||||
int transAuthenticateMsg(void* pMsg, int msgLen, void* pAuth, void* pKey) {
|
||||
T_MD5_CTX context;
|
||||
|
@ -478,35 +480,47 @@ bool transEpSetIsEqual(SEpSet* a, SEpSet* b) {
|
|||
return true;
|
||||
}
|
||||
|
||||
void transInitEnv() {
|
||||
//
|
||||
static void transInitEnv() {
|
||||
refMgt = transOpenExHandleMgt(50000);
|
||||
uv_os_setenv("UV_TCP_SINGLE_ACCEPT", "1");
|
||||
}
|
||||
static void transDestroyEnv() {
|
||||
// close ref
|
||||
transCloseExHandleMgt(refMgt);
|
||||
}
|
||||
void transInit() {
|
||||
// init env
|
||||
taosThreadOnce(&transModuleInit, transInitEnv);
|
||||
}
|
||||
void transCleanup() {
|
||||
// clean env
|
||||
transDestroyEnv();
|
||||
}
|
||||
int32_t transOpenExHandleMgt(int size) {
|
||||
// added into once later
|
||||
return taosOpenRef(size, transDestoryExHandle);
|
||||
}
|
||||
void transCloseExHandleMgt(int32_t mgt) {
|
||||
void transCloseExHandleMgt() {
|
||||
// close ref
|
||||
taosCloseRef(mgt);
|
||||
taosCloseRef(refMgt);
|
||||
}
|
||||
int64_t transAddExHandle(int32_t mgt, void* p) {
|
||||
int64_t transAddExHandle(void* p) {
|
||||
// acquire extern handle
|
||||
return taosAddRef(mgt, p);
|
||||
return taosAddRef(refMgt, p);
|
||||
}
|
||||
int32_t transRemoveExHandle(int32_t mgt, int64_t refId) {
|
||||
int32_t transRemoveExHandle(int64_t refId) {
|
||||
// acquire extern handle
|
||||
return taosRemoveRef(mgt, refId);
|
||||
return taosRemoveRef(refMgt, refId);
|
||||
}
|
||||
|
||||
SExHandle* transAcquireExHandle(int32_t mgt, int64_t refId) {
|
||||
SExHandle* transAcquireExHandle(int64_t refId) {
|
||||
// acquire extern handle
|
||||
return (SExHandle*)taosAcquireRef(mgt, refId);
|
||||
return (SExHandle*)taosAcquireRef(refMgt, refId);
|
||||
}
|
||||
|
||||
int32_t transReleaseExHandle(int32_t mgt, int64_t refId) {
|
||||
int32_t transReleaseExHandle(int64_t refId) {
|
||||
// release extern handle
|
||||
return taosReleaseRef(mgt, refId);
|
||||
return taosReleaseRef(refMgt, refId);
|
||||
}
|
||||
void transDestoryExHandle(void* handle) {
|
||||
if (handle == NULL) {
|
||||
|
|
|
@ -20,8 +20,6 @@
|
|||
static TdThreadOnce transModuleInit = PTHREAD_ONCE_INIT;
|
||||
|
||||
static char* notify = "a";
|
||||
static int32_t tranSSvrInst = 0;
|
||||
static int32_t refMgt = 0;
|
||||
|
||||
typedef struct {
|
||||
int notifyCount; //
|
||||
|
@ -142,16 +140,6 @@ static void uvHandleRegister(SSvrMsg* msg, SWorkThrd* thrd);
|
|||
static void (*transAsyncHandle[])(SSvrMsg* msg, SWorkThrd* thrd) = {uvHandleResp, uvHandleQuit, uvHandleRelease,
|
||||
uvHandleRegister, NULL};
|
||||
|
||||
static int32_t exHandlesMgt;
|
||||
|
||||
// void uvInitEnv();
|
||||
// void uvOpenExHandleMgt(int size);
|
||||
// void uvCloseExHandleMgt();
|
||||
// int64_t uvAddExHandle(void* p);
|
||||
// int32_t uvRemoveExHandle(int64_t refId);
|
||||
// int32_t uvReleaseExHandle(int64_t refId);
|
||||
// void uvDestoryExHandle(void* handle);
|
||||
// SExHandle* uvAcquireExHandle(int64_t refId);
|
||||
|
||||
static void uvDestroyConn(uv_handle_t* handle);
|
||||
|
||||
|
@ -274,7 +262,7 @@ static void uvHandleReq(SSvrConn* pConn) {
|
|||
// 2. once send out data, cli conn released to conn pool immediately
|
||||
// 3. not mixed with persist
|
||||
transMsg.info.ahandle = (void*)pHead->ahandle;
|
||||
transMsg.info.handle = (void*)transAcquireExHandle(refMgt, pConn->refId);
|
||||
transMsg.info.handle = (void*)transAcquireExHandle(pConn->refId);
|
||||
transMsg.info.refId = pConn->refId;
|
||||
transMsg.info.traceId = pHead->traceId;
|
||||
|
||||
|
@ -292,7 +280,7 @@ static void uvHandleReq(SSvrConn* pConn) {
|
|||
pConnInfo->clientPort = ntohs(pConn->addr.sin_port);
|
||||
tstrncpy(pConnInfo->user, pConn->user, sizeof(pConnInfo->user));
|
||||
|
||||
transReleaseExHandle(refMgt, pConn->refId);
|
||||
transReleaseExHandle(pConn->refId);
|
||||
|
||||
STrans* pTransInst = pConn->pTransInst;
|
||||
(*pTransInst->cfp)(pTransInst->parent, &transMsg, NULL);
|
||||
|
@ -345,21 +333,12 @@ void uvOnTimeoutCb(uv_timer_t* handle) {
|
|||
|
||||
void uvOnSendCb(uv_write_t* req, int status) {
|
||||
SSvrConn* conn = req->data;
|
||||
// transClearBuffer(&conn->readBuf);
|
||||
if (status == 0) {
|
||||
tTrace("conn %p data already was written on stream", conn);
|
||||
if (!transQueueEmpty(&conn->srvMsgs)) {
|
||||
SSvrMsg* msg = transQueuePop(&conn->srvMsgs);
|
||||
// if (msg->type == Release && conn->status != ConnNormal) {
|
||||
// conn->status = ConnNormal;
|
||||
// transUnrefSrvHandle(conn);
|
||||
// reallocConnRef(conn);
|
||||
// destroySmsg(msg);
|
||||
// transQueueClear(&conn->srvMsgs);
|
||||
// return;
|
||||
//}
|
||||
destroySmsg(msg);
|
||||
// send second data, just use for push
|
||||
// send cached data
|
||||
if (!transQueueEmpty(&conn->srvMsgs)) {
|
||||
msg = (SSvrMsg*)transQueueGet(&conn->srvMsgs, 0);
|
||||
if (msg->type == Register && conn->status == ConnAcquire) {
|
||||
|
@ -383,6 +362,7 @@ void uvOnSendCb(uv_write_t* req, int status) {
|
|||
}
|
||||
}
|
||||
}
|
||||
transUnrefSrvHandle(conn);
|
||||
} else {
|
||||
tError("conn %p failed to write data, %s", conn, uv_err_name(status));
|
||||
conn->broken = true;
|
||||
|
@ -396,7 +376,6 @@ static void uvOnPipeWriteCb(uv_write_t* req, int status) {
|
|||
tError("fail to dispatch conn to work thread");
|
||||
}
|
||||
uv_close((uv_handle_t*)req->data, uvFreeCb);
|
||||
// taosMemoryFree(req->data);
|
||||
taosMemoryFree(req);
|
||||
}
|
||||
|
||||
|
@ -410,6 +389,7 @@ static void uvPrepareSendData(SSvrMsg* smsg, uv_buf_t* wb) {
|
|||
STransMsgHead* pHead = transHeadFromCont(pMsg->pCont);
|
||||
pHead->ahandle = (uint64_t)pMsg->info.ahandle;
|
||||
pHead->traceId = pMsg->info.traceId;
|
||||
pHead->hasEpSet = pMsg->info.hasEpSet;
|
||||
|
||||
if (pConn->status == ConnNormal) {
|
||||
pHead->msgType = pConn->inType + 1;
|
||||
|
@ -422,6 +402,7 @@ static void uvPrepareSendData(SSvrMsg* smsg, uv_buf_t* wb) {
|
|||
transUnrefSrvHandle(pConn);
|
||||
} else {
|
||||
pHead->msgType = pMsg->msgType;
|
||||
// set up resp msg type
|
||||
if (pHead->msgType == 0 && transMsgLenFromCont(pMsg->contLen) == sizeof(STransMsgHead))
|
||||
pHead->msgType = pConn->inType + 1;
|
||||
}
|
||||
|
@ -444,11 +425,15 @@ static void uvPrepareSendData(SSvrMsg* smsg, uv_buf_t* wb) {
|
|||
}
|
||||
|
||||
static void uvStartSendRespInternal(SSvrMsg* smsg) {
|
||||
SSvrConn* pConn = smsg->pConn;
|
||||
if (pConn->broken) {
|
||||
return;
|
||||
}
|
||||
|
||||
uv_buf_t wb;
|
||||
uvPrepareSendData(smsg, &wb);
|
||||
|
||||
SSvrConn* pConn = smsg->pConn;
|
||||
// uv_timer_stop(&pConn->pTimer);
|
||||
transRefSrvHandle(pConn);
|
||||
uv_write(&pConn->pWriter, (uv_stream_t*)pConn->pTcp, &wb, 1, uvOnSendCb);
|
||||
}
|
||||
static void uvStartSendResp(SSvrMsg* smsg) {
|
||||
|
@ -523,15 +508,15 @@ void uvWorkerAsyncCb(uv_async_t* handle) {
|
|||
|
||||
SExHandle* exh1 = transMsg.info.handle;
|
||||
int64_t refId = transMsg.info.refId;
|
||||
SExHandle* exh2 = transAcquireExHandle(refMgt, refId);
|
||||
SExHandle* exh2 = transAcquireExHandle(refId);
|
||||
if (exh2 == NULL || exh1 != exh2) {
|
||||
tTrace("handle except msg %p, ignore it", exh1);
|
||||
transReleaseExHandle(refMgt, refId);
|
||||
transReleaseExHandle(refId);
|
||||
destroySmsg(msg);
|
||||
continue;
|
||||
}
|
||||
msg->pConn = exh1->handle;
|
||||
transReleaseExHandle(refMgt, refId);
|
||||
transReleaseExHandle(refId);
|
||||
(*transAsyncHandle[msg->type])(msg, pThrd);
|
||||
}
|
||||
}
|
||||
|
@ -773,8 +758,8 @@ static SSvrConn* createConn(void* hThrd) {
|
|||
SExHandle* exh = taosMemoryMalloc(sizeof(SExHandle));
|
||||
exh->handle = pConn;
|
||||
exh->pThrd = pThrd;
|
||||
exh->refId = transAddExHandle(refMgt, exh);
|
||||
transAcquireExHandle(refMgt, exh->refId);
|
||||
exh->refId = transAddExHandle(exh);
|
||||
transAcquireExHandle(exh->refId);
|
||||
|
||||
pConn->refId = exh->refId;
|
||||
transRefSrvHandle(pConn);
|
||||
|
@ -789,11 +774,12 @@ static void destroyConn(SSvrConn* conn, bool clear) {
|
|||
|
||||
transDestroyBuffer(&conn->readBuf);
|
||||
if (clear) {
|
||||
if (!uv_is_closing((uv_handle_t*)conn->pTcp)) {
|
||||
tTrace("conn %p to be destroyed", conn);
|
||||
// uv_shutdown_t* req = taosMemoryMalloc(sizeof(uv_shutdown_t));
|
||||
uv_close((uv_handle_t*)conn->pTcp, uvDestroyConn);
|
||||
// uv_close(conn->pTcp)
|
||||
// uv_shutdown(req, (uv_stream_t*)conn->pTcp, uvShutDownCb);
|
||||
} else {
|
||||
uvDestroyConn((uv_handle_t*)conn->pTcp);
|
||||
}
|
||||
}
|
||||
}
|
||||
static void destroyConnRegArg(SSvrConn* conn) {
|
||||
|
@ -803,14 +789,14 @@ static void destroyConnRegArg(SSvrConn* conn) {
|
|||
}
|
||||
}
|
||||
static int reallocConnRef(SSvrConn* conn) {
|
||||
transReleaseExHandle(refMgt, conn->refId);
|
||||
transRemoveExHandle(refMgt, conn->refId);
|
||||
transReleaseExHandle(conn->refId);
|
||||
transRemoveExHandle(conn->refId);
|
||||
// avoid app continue to send msg on invalid handle
|
||||
SExHandle* exh = taosMemoryMalloc(sizeof(SExHandle));
|
||||
exh->handle = conn;
|
||||
exh->pThrd = conn->hostThrd;
|
||||
exh->refId = transAddExHandle(refMgt, exh);
|
||||
transAcquireExHandle(refMgt, exh->refId);
|
||||
exh->refId = transAddExHandle(exh);
|
||||
transAcquireExHandle(exh->refId);
|
||||
conn->refId = exh->refId;
|
||||
|
||||
return 0;
|
||||
|
@ -822,11 +808,10 @@ static void uvDestroyConn(uv_handle_t* handle) {
|
|||
}
|
||||
SWorkThrd* thrd = conn->hostThrd;
|
||||
|
||||
transReleaseExHandle(refMgt, conn->refId);
|
||||
transRemoveExHandle(refMgt, conn->refId);
|
||||
transReleaseExHandle(conn->refId);
|
||||
transRemoveExHandle(conn->refId);
|
||||
|
||||
tDebug("%s conn %p destroy", transLabel(thrd->pTransInst), conn);
|
||||
// uv_timer_stop(&conn->pTimer);
|
||||
transQueueDestroy(&conn->srvMsgs);
|
||||
|
||||
QUEUE_REMOVE(&conn->queue);
|
||||
|
@ -871,12 +856,6 @@ void* transInitServer(uint32_t ip, uint32_t port, char* label, int numOfThreads,
|
|||
srv->port = port;
|
||||
uv_loop_init(srv->loop);
|
||||
|
||||
// taosThreadOnce(&transModuleInit, uvInitEnv);
|
||||
int ref = atomic_add_fetch_32(&tranSSvrInst, 1);
|
||||
if (ref == 1) {
|
||||
refMgt = transOpenExHandleMgt(50000);
|
||||
}
|
||||
|
||||
assert(0 == uv_pipe_init(srv->loop, &srv->pipeListen, 0));
|
||||
#ifdef WINDOWS
|
||||
char pipeName[64];
|
||||
|
@ -1028,11 +1007,6 @@ void transCloseServer(void* arg) {
|
|||
taosMemoryFree(srv->pipe);
|
||||
|
||||
taosMemoryFree(srv);
|
||||
|
||||
int ref = atomic_sub_fetch_32(&tranSSvrInst, 1);
|
||||
if (ref == 0) {
|
||||
transCloseExHandleMgt(refMgt);
|
||||
}
|
||||
}
|
||||
|
||||
void transRefSrvHandle(void* handle) {
|
||||
|
@ -1071,11 +1045,11 @@ void transReleaseSrvHandle(void* handle) {
|
|||
|
||||
tTrace("%s conn %p start to release", transLabel(pThrd->pTransInst), exh->handle);
|
||||
transAsyncSend(pThrd->asyncPool, &m->q);
|
||||
transReleaseExHandle(refMgt, refId);
|
||||
transReleaseExHandle(refId);
|
||||
return;
|
||||
_return1:
|
||||
tTrace("handle %p failed to send to release handle", exh);
|
||||
transReleaseExHandle(refMgt, refId);
|
||||
transReleaseExHandle(refId);
|
||||
return;
|
||||
_return2:
|
||||
tTrace("handle %p failed to send to release handle", exh);
|
||||
|
@ -1100,12 +1074,12 @@ void transSendResponse(const STransMsg* msg) {
|
|||
STraceId* trace = (STraceId*)&msg->info.traceId;
|
||||
tGTrace("conn %p start to send resp (1/2)", exh->handle);
|
||||
transAsyncSend(pThrd->asyncPool, &m->q);
|
||||
transReleaseExHandle(refMgt, refId);
|
||||
transReleaseExHandle(refId);
|
||||
return;
|
||||
_return1:
|
||||
tTrace("handle %p failed to send resp", exh);
|
||||
rpcFreeCont(msg->pCont);
|
||||
transReleaseExHandle(refMgt, refId);
|
||||
transReleaseExHandle(refId);
|
||||
return;
|
||||
_return2:
|
||||
tTrace("handle %p failed to send resp", exh);
|
||||
|
@ -1129,19 +1103,17 @@ void transRegisterMsg(const STransMsg* msg) {
|
|||
|
||||
tTrace("%s conn %p start to register brokenlink callback", transLabel(pThrd->pTransInst), exh->handle);
|
||||
transAsyncSend(pThrd->asyncPool, &m->q);
|
||||
transReleaseExHandle(refMgt, refId);
|
||||
transReleaseExHandle(refId);
|
||||
return;
|
||||
|
||||
_return1:
|
||||
tTrace("handle %p failed to register brokenlink", exh);
|
||||
rpcFreeCont(msg->pCont);
|
||||
transReleaseExHandle(refMgt, refId);
|
||||
transReleaseExHandle(refId);
|
||||
return;
|
||||
_return2:
|
||||
tTrace("handle %p failed to register brokenlink", exh);
|
||||
rpcFreeCont(msg->pCont);
|
||||
}
|
||||
|
||||
int transGetConnInfo(void* thandle, STransHandleInfo* pConnInfo) { return -1; }
|
||||
|
||||
#endif
|
||||
|
|
|
@ -925,10 +925,24 @@ uint32_t taosGetIpv4FromFqdn(const char *fqdn) {
|
|||
}
|
||||
|
||||
int32_t taosGetFqdn(char *fqdn) {
|
||||
#ifdef WINDOWS
|
||||
// Initialize Winsock
|
||||
WSADATA wsaData;
|
||||
int iResult;
|
||||
iResult = WSAStartup(MAKEWORD(2, 2), &wsaData);
|
||||
if (iResult != 0) {
|
||||
// printf("WSAStartup failed: %d\n", iResult);
|
||||
return 1;
|
||||
}
|
||||
#endif
|
||||
char hostname[1024];
|
||||
hostname[1023] = '\0';
|
||||
if (gethostname(hostname, 1023) == -1) {
|
||||
// printf("failed to get hostname, reason:%s", strerror(errno));
|
||||
#ifdef WINDOWS
|
||||
printf("failed to get hostname, reason:%s", strerror(WSAGetLastError()));
|
||||
#else
|
||||
printf("failed to get hostname, reason:%s", strerror(errno));
|
||||
#endif
|
||||
assert(0);
|
||||
return -1;
|
||||
}
|
||||
|
|
|
@ -453,11 +453,12 @@ TAOS_DEFINE_ERROR(TSDB_CODE_FS_NO_VALID_DISK, "tfs no valid disk")
|
|||
TAOS_DEFINE_ERROR(TSDB_CODE_CTG_INTERNAL_ERROR, "catalog internal error")
|
||||
TAOS_DEFINE_ERROR(TSDB_CODE_CTG_INVALID_INPUT, "invalid catalog input parameters")
|
||||
TAOS_DEFINE_ERROR(TSDB_CODE_CTG_NOT_READY, "catalog is not ready")
|
||||
TAOS_DEFINE_ERROR(TSDB_CODE_CTG_MEM_ERROR, "catalog memory error")
|
||||
TAOS_DEFINE_ERROR(TSDB_CODE_OUT_OF_MEMORY, "catalog memory error")
|
||||
TAOS_DEFINE_ERROR(TSDB_CODE_CTG_SYS_ERROR, "catalog system error")
|
||||
TAOS_DEFINE_ERROR(TSDB_CODE_CTG_DB_DROPPED, "Database is dropped")
|
||||
TAOS_DEFINE_ERROR(TSDB_CODE_CTG_OUT_OF_SERVICE, "catalog is out of service")
|
||||
TAOS_DEFINE_ERROR(TSDB_CODE_CTG_VG_META_MISMATCH, "table meta and vgroup mismatch")
|
||||
TAOS_DEFINE_ERROR(TSDB_CODE_CTG_EXIT, "catalog exit")
|
||||
|
||||
//scheduler
|
||||
TAOS_DEFINE_ERROR(TSDB_CODE_SCH_STATUS_ERROR, "scheduler status error")
|
||||
|
|
|
@ -0,0 +1,13 @@
|
|||
#!/bin/bash
|
||||
for i in {1..100}
|
||||
do
|
||||
echo $i
|
||||
python3 ./test.py -f query/nestedQuery/nestedQuery_datacheck.py >>log 2>&1
|
||||
if [ $? -eq 0 ]
|
||||
then
|
||||
echo success
|
||||
else
|
||||
echo failed
|
||||
break
|
||||
fi
|
||||
done
|
|
@ -915,7 +915,7 @@ int32_t prepareInsertData(BindData *data) {
|
|||
data->colNum = 0;
|
||||
data->colTypes = taosMemoryCalloc(30, sizeof(int32_t));
|
||||
data->sql = taosMemoryCalloc(1, 1024);
|
||||
data->pBind = taosMemoryCalloc((allRowNum/gCurCase->bindRowNum)*gCurCase->bindColNum, sizeof(TAOS_MULTI_BIND));
|
||||
data->pBind = taosMemoryCalloc((int32_t)(allRowNum/gCurCase->bindRowNum)*gCurCase->bindColNum, sizeof(TAOS_MULTI_BIND));
|
||||
data->pTags = taosMemoryCalloc(gCurCase->tblNum*gCurCase->bindTagNum, sizeof(TAOS_MULTI_BIND));
|
||||
data->tsData = taosMemoryMalloc(allRowNum * sizeof(int64_t));
|
||||
data->boolData = taosMemoryMalloc(allRowNum * sizeof(bool));
|
||||
|
@ -932,7 +932,7 @@ int32_t prepareInsertData(BindData *data) {
|
|||
data->binaryData = taosMemoryMalloc(allRowNum * gVarCharSize);
|
||||
data->binaryLen = taosMemoryMalloc(allRowNum * sizeof(int32_t));
|
||||
if (gCurCase->bindNullNum) {
|
||||
data->isNull = taosMemoryCalloc(allRowNum, sizeof(char));
|
||||
data->isNull = taosMemoryCalloc((int32_t)allRowNum, sizeof(char));
|
||||
}
|
||||
|
||||
for (int32_t i = 0; i < allRowNum; ++i) {
|
||||
|
@ -950,7 +950,7 @@ int32_t prepareInsertData(BindData *data) {
|
|||
data->doubleData[i] = (double)(i+1);
|
||||
memset(data->binaryData + gVarCharSize * i, 'a'+i%26, gVarCharLen);
|
||||
if (gCurCase->bindNullNum) {
|
||||
data->isNull[i] = i % 2;
|
||||
data->isNull[i] = (char)(i % 2);
|
||||
}
|
||||
data->binaryLen[i] = gVarCharLen;
|
||||
}
|
||||
|
@ -979,7 +979,7 @@ int32_t prepareQueryCondData(BindData *data, int32_t tblIdx) {
|
|||
data->colNum = 0;
|
||||
data->colTypes = taosMemoryCalloc(30, sizeof(int32_t));
|
||||
data->sql = taosMemoryCalloc(1, 1024);
|
||||
data->pBind = taosMemoryCalloc(bindNum*gCurCase->bindColNum, sizeof(TAOS_MULTI_BIND));
|
||||
data->pBind = taosMemoryCalloc((int32_t)bindNum*gCurCase->bindColNum, sizeof(TAOS_MULTI_BIND));
|
||||
data->tsData = taosMemoryMalloc(bindNum * sizeof(int64_t));
|
||||
data->boolData = taosMemoryMalloc(bindNum * sizeof(bool));
|
||||
data->tinyData = taosMemoryMalloc(bindNum * sizeof(int8_t));
|
||||
|
@ -995,7 +995,7 @@ int32_t prepareQueryCondData(BindData *data, int32_t tblIdx) {
|
|||
data->binaryData = taosMemoryMalloc(bindNum * gVarCharSize);
|
||||
data->binaryLen = taosMemoryMalloc(bindNum * sizeof(int32_t));
|
||||
if (gCurCase->bindNullNum) {
|
||||
data->isNull = taosMemoryCalloc(bindNum, sizeof(char));
|
||||
data->isNull = taosMemoryCalloc((int32_t)bindNum, sizeof(char));
|
||||
}
|
||||
|
||||
for (int32_t i = 0; i < bindNum; ++i) {
|
||||
|
@ -1013,7 +1013,7 @@ int32_t prepareQueryCondData(BindData *data, int32_t tblIdx) {
|
|||
data->doubleData[i] = (double)(tblIdx*gCurCase->rowNum + rand() % gCurCase->rowNum);
|
||||
memset(data->binaryData + gVarCharSize * i, 'a'+i%26, gVarCharLen);
|
||||
if (gCurCase->bindNullNum) {
|
||||
data->isNull[i] = i % 2;
|
||||
data->isNull[i] = (char)(i % 2);
|
||||
}
|
||||
data->binaryLen[i] = gVarCharLen;
|
||||
}
|
||||
|
@ -1036,7 +1036,7 @@ int32_t prepareQueryMiscData(BindData *data, int32_t tblIdx) {
|
|||
data->colNum = 0;
|
||||
data->colTypes = taosMemoryCalloc(30, sizeof(int32_t));
|
||||
data->sql = taosMemoryCalloc(1, 1024);
|
||||
data->pBind = taosMemoryCalloc(bindNum*gCurCase->bindColNum, sizeof(TAOS_MULTI_BIND));
|
||||
data->pBind = taosMemoryCalloc((int32_t)bindNum*gCurCase->bindColNum, sizeof(TAOS_MULTI_BIND));
|
||||
data->tsData = taosMemoryMalloc(bindNum * sizeof(int64_t));
|
||||
data->boolData = taosMemoryMalloc(bindNum * sizeof(bool));
|
||||
data->tinyData = taosMemoryMalloc(bindNum * sizeof(int8_t));
|
||||
|
@ -1052,7 +1052,7 @@ int32_t prepareQueryMiscData(BindData *data, int32_t tblIdx) {
|
|||
data->binaryData = taosMemoryMalloc(bindNum * gVarCharSize);
|
||||
data->binaryLen = taosMemoryMalloc(bindNum * sizeof(int32_t));
|
||||
if (gCurCase->bindNullNum) {
|
||||
data->isNull = taosMemoryCalloc(bindNum, sizeof(char));
|
||||
data->isNull = taosMemoryCalloc((int32_t)bindNum, sizeof(char));
|
||||
}
|
||||
|
||||
for (int32_t i = 0; i < bindNum; ++i) {
|
||||
|
@ -1070,7 +1070,7 @@ int32_t prepareQueryMiscData(BindData *data, int32_t tblIdx) {
|
|||
data->doubleData[i] = (double)(tblIdx*gCurCase->rowNum + rand() % gCurCase->rowNum);
|
||||
memset(data->binaryData + gVarCharSize * i, 'a'+i%26, gVarCharLen);
|
||||
if (gCurCase->bindNullNum) {
|
||||
data->isNull[i] = i % 2;
|
||||
data->isNull[i] = (char)(i % 2);
|
||||
}
|
||||
data->binaryLen[i] = gVarCharLen;
|
||||
}
|
||||
|
@ -1279,7 +1279,7 @@ void bpCheckQueryResult(TAOS_STMT *stmt, TAOS *taos, char *stmtSql, TAOS_MULTI_B
|
|||
}
|
||||
|
||||
memcpy(&sql[len], p, (int64_t)s - (int64_t)p);
|
||||
len += (int64_t)s - (int64_t)p;
|
||||
len += (int32_t)((int64_t)s - (int64_t)p);
|
||||
|
||||
if (bind[i].is_null && bind[i].is_null[0]) {
|
||||
bpAppendValueString(sql, TSDB_DATA_TYPE_NULL, NULL, 0, &len);
|
||||
|
@ -2669,7 +2669,7 @@ int main(int argc, char *argv[])
|
|||
{
|
||||
TAOS *taos = NULL;
|
||||
|
||||
srand(time(NULL));
|
||||
srand((unsigned int)time(NULL));
|
||||
|
||||
// connect to server
|
||||
if (argc < 2) {
|
||||
|
|
|
@ -12,6 +12,7 @@ all: $(TARGET)
|
|||
|
||||
exe:
|
||||
gcc $(CFLAGS) ./batchprepare.c -o $(ROOT)batchprepare $(LFLAGS)
|
||||
gcc $(CFLAGS) ./stopquery.c -o $(ROOT)stopquery $(LFLAGS)
|
||||
|
||||
clean:
|
||||
rm $(ROOT)batchprepare
|
||||
|
|
|
@ -0,0 +1,434 @@
|
|||
/*
|
||||
* 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/>.
|
||||
*/
|
||||
|
||||
// TAOS asynchronous API example
|
||||
// this example opens multiple tables, insert/retrieve multiple tables
|
||||
// it is used by TAOS internally for one performance testing
|
||||
// to compiple: gcc -o asyncdemo asyncdemo.c -ltaos
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <sys/time.h>
|
||||
#include <unistd.h>
|
||||
#include <string.h>
|
||||
#include <pthread.h>
|
||||
#include "taos.h"
|
||||
|
||||
|
||||
int points = 5;
|
||||
int numOfTables = 3;
|
||||
int tablesInsertProcessed = 0;
|
||||
int tablesSelectProcessed = 0;
|
||||
int64_t st, et;
|
||||
|
||||
char hostName[128];
|
||||
char dbName[128];
|
||||
char tbName[128];
|
||||
int32_t runTimes = 10000;
|
||||
|
||||
typedef struct {
|
||||
int id;
|
||||
TAOS *taos;
|
||||
char name[16];
|
||||
time_t timeStamp;
|
||||
int value;
|
||||
int rowsInserted;
|
||||
int rowsTried;
|
||||
int rowsRetrieved;
|
||||
} STable;
|
||||
|
||||
typedef struct SSP_CB_PARAM {
|
||||
TAOS *taos;
|
||||
bool fetch;
|
||||
int32_t *end;
|
||||
} SSP_CB_PARAM;
|
||||
|
||||
#define CASE_ENTER() do { printf("enter case %s\n", __FUNCTION__); } while (0)
|
||||
#define CASE_LEAVE() do { printf("leave case %s, runTimes %d\n", __FUNCTION__, runTimes); } while (0)
|
||||
|
||||
static void sqExecSQL(TAOS *taos, char *command) {
|
||||
int i;
|
||||
int32_t code = -1;
|
||||
|
||||
TAOS_RES *pSql = taos_query(taos, command);
|
||||
code = taos_errno(pSql);
|
||||
if (code != 0) {
|
||||
fprintf(stderr, "Failed to run %s, reason: %s\n", command, taos_errstr(pSql));
|
||||
taos_free_result(pSql);
|
||||
taos_close(taos);
|
||||
taos_cleanup();
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
taos_free_result(pSql);
|
||||
}
|
||||
|
||||
static void sqExecSQLE(TAOS *taos, char *command) {
|
||||
int i;
|
||||
int32_t code = -1;
|
||||
|
||||
TAOS_RES *pSql = taos_query(taos, command);
|
||||
|
||||
taos_free_result(pSql);
|
||||
}
|
||||
|
||||
|
||||
void sqExit(char* prefix, const char* errMsg) {
|
||||
fprintf(stderr, "%s error: %s\n", prefix, errMsg);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
void sqStopFetchCb(void *param, TAOS_RES *pRes, int numOfRows) {
|
||||
SSP_CB_PARAM *qParam = (SSP_CB_PARAM *)param;
|
||||
taos_stop_query(pRes);
|
||||
taos_free_result(pRes);
|
||||
|
||||
*qParam->end = 1;
|
||||
}
|
||||
|
||||
void sqStopQueryCb(void *param, TAOS_RES *pRes, int code) {
|
||||
SSP_CB_PARAM *qParam = (SSP_CB_PARAM *)param;
|
||||
if (code == 0 && pRes) {
|
||||
if (qParam->fetch) {
|
||||
taos_fetch_rows_a(pRes, sqStopFetchCb, param);
|
||||
} else {
|
||||
taos_stop_query(pRes);
|
||||
taos_free_result(pRes);
|
||||
*qParam->end = 1;
|
||||
}
|
||||
} else {
|
||||
sqExit("select", taos_errstr(pRes));
|
||||
}
|
||||
}
|
||||
|
||||
void sqFreeFetchCb(void *param, TAOS_RES *pRes, int numOfRows) {
|
||||
SSP_CB_PARAM *qParam = (SSP_CB_PARAM *)param;
|
||||
taos_free_result(pRes);
|
||||
|
||||
*qParam->end = 1;
|
||||
}
|
||||
|
||||
void sqFreeQueryCb(void *param, TAOS_RES *pRes, int code) {
|
||||
SSP_CB_PARAM *qParam = (SSP_CB_PARAM *)param;
|
||||
if (code == 0 && pRes) {
|
||||
if (qParam->fetch) {
|
||||
taos_fetch_rows_a(pRes, sqFreeFetchCb, param);
|
||||
} else {
|
||||
taos_free_result(pRes);
|
||||
*qParam->end = 1;
|
||||
}
|
||||
} else {
|
||||
sqExit("select", taos_errstr(pRes));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void sqCloseFetchCb(void *param, TAOS_RES *pRes, int numOfRows) {
|
||||
SSP_CB_PARAM *qParam = (SSP_CB_PARAM *)param;
|
||||
taos_close(qParam->taos);
|
||||
|
||||
*qParam->end = 1;
|
||||
}
|
||||
|
||||
void sqCloseQueryCb(void *param, TAOS_RES *pRes, int code) {
|
||||
SSP_CB_PARAM *qParam = (SSP_CB_PARAM *)param;
|
||||
if (code == 0 && pRes) {
|
||||
if (qParam->fetch) {
|
||||
taos_fetch_rows_a(pRes, sqFreeFetchCb, param);
|
||||
} else {
|
||||
taos_close(qParam->taos);
|
||||
*qParam->end = 1;
|
||||
}
|
||||
} else {
|
||||
sqExit("select", taos_errstr(pRes));
|
||||
}
|
||||
}
|
||||
|
||||
int sqSyncStopQuery(bool fetch) {
|
||||
CASE_ENTER();
|
||||
for (int32_t i = 0; i < runTimes; ++i) {
|
||||
char sql[1024] = {0};
|
||||
int32_t code = 0;
|
||||
TAOS *taos = taos_connect(hostName, "root", "taosdata", NULL, 0);
|
||||
if (taos == NULL) sqExit("taos_connect", taos_errstr(NULL));
|
||||
|
||||
sprintf(sql, "reset query cache");
|
||||
sqExecSQL(taos, sql);
|
||||
|
||||
sprintf(sql, "use %s", dbName);
|
||||
sqExecSQL(taos, sql);
|
||||
|
||||
sprintf(sql, "select * from %s", tbName);
|
||||
TAOS_RES* pRes = taos_query(taos, sql);
|
||||
code = taos_errno(pRes);
|
||||
if (code) {
|
||||
sqExit("taos_query", taos_errstr(pRes));
|
||||
}
|
||||
|
||||
if (fetch) {
|
||||
taos_fetch_row(pRes);
|
||||
}
|
||||
|
||||
taos_stop_query(pRes);
|
||||
taos_free_result(pRes);
|
||||
|
||||
taos_close(taos);
|
||||
}
|
||||
CASE_LEAVE();
|
||||
}
|
||||
|
||||
int sqAsyncStopQuery(bool fetch) {
|
||||
CASE_ENTER();
|
||||
for (int32_t i = 0; i < runTimes; ++i) {
|
||||
char sql[1024] = {0};
|
||||
int32_t code = 0;
|
||||
TAOS *taos = taos_connect(hostName, "root", "taosdata", NULL, 0);
|
||||
if (taos == NULL) sqExit("taos_connect", taos_errstr(NULL));
|
||||
|
||||
sprintf(sql, "reset query cache");
|
||||
sqExecSQL(taos, sql);
|
||||
|
||||
sprintf(sql, "use %s", dbName);
|
||||
sqExecSQL(taos, sql);
|
||||
|
||||
sprintf(sql, "select * from %s", tbName);
|
||||
|
||||
int32_t qEnd = 0;
|
||||
SSP_CB_PARAM param = {0};
|
||||
param.fetch = fetch;
|
||||
param.end = &qEnd;
|
||||
taos_query_a(taos, sql, sqStopQueryCb, ¶m);
|
||||
while (0 == qEnd) {
|
||||
usleep(5000);
|
||||
}
|
||||
|
||||
taos_close(taos);
|
||||
}
|
||||
CASE_LEAVE();
|
||||
}
|
||||
|
||||
int sqSyncFreeQuery(bool fetch) {
|
||||
CASE_ENTER();
|
||||
for (int32_t i = 0; i < runTimes; ++i) {
|
||||
char sql[1024] = {0};
|
||||
int32_t code = 0;
|
||||
TAOS *taos = taos_connect(hostName, "root", "taosdata", NULL, 0);
|
||||
if (taos == NULL) sqExit("taos_connect", taos_errstr(NULL));
|
||||
|
||||
sprintf(sql, "reset query cache");
|
||||
sqExecSQL(taos, sql);
|
||||
|
||||
sprintf(sql, "use %s", dbName);
|
||||
sqExecSQL(taos, sql);
|
||||
|
||||
sprintf(sql, "select * from %s", tbName);
|
||||
TAOS_RES* pRes = taos_query(taos, sql);
|
||||
code = taos_errno(pRes);
|
||||
if (code) {
|
||||
sqExit("taos_query", taos_errstr(pRes));
|
||||
}
|
||||
|
||||
if (fetch) {
|
||||
taos_fetch_row(pRes);
|
||||
}
|
||||
|
||||
taos_free_result(pRes);
|
||||
taos_close(taos);
|
||||
}
|
||||
CASE_LEAVE();
|
||||
}
|
||||
|
||||
int sqAsyncFreeQuery(bool fetch) {
|
||||
CASE_ENTER();
|
||||
for (int32_t i = 0; i < runTimes; ++i) {
|
||||
char sql[1024] = {0};
|
||||
int32_t code = 0;
|
||||
TAOS *taos = taos_connect(hostName, "root", "taosdata", NULL, 0);
|
||||
if (taos == NULL) sqExit("taos_connect", taos_errstr(NULL));
|
||||
|
||||
sprintf(sql, "reset query cache");
|
||||
sqExecSQL(taos, sql);
|
||||
|
||||
sprintf(sql, "use %s", dbName);
|
||||
sqExecSQL(taos, sql);
|
||||
|
||||
sprintf(sql, "select * from %s", tbName);
|
||||
|
||||
int32_t qEnd = 0;
|
||||
SSP_CB_PARAM param = {0};
|
||||
param.fetch = fetch;
|
||||
param.end = &qEnd;
|
||||
taos_query_a(taos, sql, sqFreeQueryCb, ¶m);
|
||||
while (0 == qEnd) {
|
||||
usleep(5000);
|
||||
}
|
||||
|
||||
taos_close(taos);
|
||||
}
|
||||
CASE_LEAVE();
|
||||
}
|
||||
|
||||
int sqSyncCloseQuery(bool fetch) {
|
||||
CASE_ENTER();
|
||||
for (int32_t i = 0; i < runTimes; ++i) {
|
||||
char sql[1024] = {0};
|
||||
int32_t code = 0;
|
||||
TAOS *taos = taos_connect(hostName, "root", "taosdata", NULL, 0);
|
||||
if (taos == NULL) sqExit("taos_connect", taos_errstr(NULL));
|
||||
|
||||
sprintf(sql, "reset query cache");
|
||||
sqExecSQL(taos, sql);
|
||||
|
||||
sprintf(sql, "use %s", dbName);
|
||||
sqExecSQL(taos, sql);
|
||||
|
||||
sprintf(sql, "select * from %s", tbName);
|
||||
TAOS_RES* pRes = taos_query(taos, sql);
|
||||
code = taos_errno(pRes);
|
||||
if (code) {
|
||||
sqExit("taos_query", taos_errstr(pRes));
|
||||
}
|
||||
|
||||
if (fetch) {
|
||||
taos_fetch_row(pRes);
|
||||
}
|
||||
|
||||
taos_close(taos);
|
||||
}
|
||||
CASE_LEAVE();
|
||||
}
|
||||
|
||||
int sqAsyncCloseQuery(bool fetch) {
|
||||
CASE_ENTER();
|
||||
for (int32_t i = 0; i < runTimes; ++i) {
|
||||
char sql[1024] = {0};
|
||||
int32_t code = 0;
|
||||
TAOS *taos = taos_connect(hostName, "root", "taosdata", NULL, 0);
|
||||
if (taos == NULL) sqExit("taos_connect", taos_errstr(NULL));
|
||||
|
||||
sprintf(sql, "reset query cache");
|
||||
sqExecSQL(taos, sql);
|
||||
|
||||
sprintf(sql, "use %s", dbName);
|
||||
sqExecSQL(taos, sql);
|
||||
|
||||
sprintf(sql, "select * from %s", tbName);
|
||||
|
||||
int32_t qEnd = 0;
|
||||
SSP_CB_PARAM param = {0};
|
||||
param.fetch = fetch;
|
||||
param.end = &qEnd;
|
||||
taos_query_a(taos, sql, sqFreeQueryCb, ¶m);
|
||||
while (0 == qEnd) {
|
||||
usleep(5000);
|
||||
}
|
||||
}
|
||||
CASE_LEAVE();
|
||||
}
|
||||
|
||||
void *syncQueryThreadFp(void *arg) {
|
||||
SSP_CB_PARAM* qParam = (SSP_CB_PARAM*)arg;
|
||||
char sql[1024] = {0};
|
||||
int32_t code = 0;
|
||||
TAOS *taos = taos_connect(hostName, "root", "taosdata", NULL, 0);
|
||||
if (taos == NULL) sqExit("taos_connect", taos_errstr(NULL));
|
||||
|
||||
qParam->taos = taos;
|
||||
|
||||
sprintf(sql, "reset query cache");
|
||||
sqExecSQLE(taos, sql);
|
||||
|
||||
sprintf(sql, "use %s", dbName);
|
||||
sqExecSQLE(taos, sql);
|
||||
|
||||
sprintf(sql, "select * from %s", tbName);
|
||||
TAOS_RES* pRes = taos_query(taos, sql);
|
||||
|
||||
if (qParam->fetch) {
|
||||
taos_fetch_row(pRes);
|
||||
}
|
||||
|
||||
taos_free_result(pRes);
|
||||
}
|
||||
|
||||
void *closeThreadFp(void *arg) {
|
||||
SSP_CB_PARAM* qParam = (SSP_CB_PARAM*)arg;
|
||||
while (true) {
|
||||
if (qParam->taos) {
|
||||
usleep(rand() % 10000);
|
||||
taos_close(qParam->taos);
|
||||
break;
|
||||
}
|
||||
usleep(1);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
int sqConSyncCloseQuery(bool fetch) {
|
||||
CASE_ENTER();
|
||||
pthread_t qid, cid;
|
||||
for (int32_t i = 0; i < runTimes; ++i) {
|
||||
SSP_CB_PARAM param = {0};
|
||||
param.fetch = fetch;
|
||||
pthread_create(&qid, NULL, syncQueryThreadFp, (void*)¶m);
|
||||
pthread_create(&cid, NULL, closeThreadFp, (void*)¶m);
|
||||
|
||||
pthread_join(qid, NULL);
|
||||
pthread_join(cid, NULL);
|
||||
}
|
||||
CASE_LEAVE();
|
||||
}
|
||||
|
||||
void sqRunAllCase(void) {
|
||||
/*
|
||||
sqSyncStopQuery(false);
|
||||
sqSyncStopQuery(true);
|
||||
sqAsyncStopQuery(false);
|
||||
sqAsyncStopQuery(true);
|
||||
|
||||
sqSyncFreeQuery(false);
|
||||
sqSyncFreeQuery(true);
|
||||
sqAsyncFreeQuery(false);
|
||||
sqAsyncFreeQuery(true);
|
||||
|
||||
sqSyncCloseQuery(false);
|
||||
sqSyncCloseQuery(true);
|
||||
sqAsyncCloseQuery(false);
|
||||
sqAsyncCloseQuery(true);
|
||||
*/
|
||||
sqConSyncCloseQuery(false);
|
||||
sqConSyncCloseQuery(true);
|
||||
|
||||
}
|
||||
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
if (argc != 4) {
|
||||
printf("usage: %s server-ip dbname tablename\n", argv[0]);
|
||||
exit(0);
|
||||
}
|
||||
|
||||
srand((unsigned int)time(NULL));
|
||||
|
||||
strcpy(hostName, argv[1]);
|
||||
strcpy(dbName, argv[2]);
|
||||
strcpy(tbName, argv[3]);
|
||||
|
||||
sqRunAllCase();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
@ -6,6 +6,7 @@ if %1 == -n set NODE_NAME=%2
|
|||
if %1 == -s set EXEC_OPTON=%2
|
||||
if %3 == -n set NODE_NAME=%4
|
||||
if %3 == -s set EXEC_OPTON=%4
|
||||
if "%5" == "-x" set EXEC_SIGNAL=%6
|
||||
|
||||
rem echo NODE_NAME: %NODE_NAME%
|
||||
rem echo NODE: %EXEC_OPTON%
|
||||
|
@ -39,7 +40,7 @@ rem echo TAOS_LOG: %TAOS_LOG%
|
|||
if %EXEC_OPTON% == start (
|
||||
rm -rf %TAOS_LOG%
|
||||
echo start %TAOSD% -c %CFG_DIR%
|
||||
start %TAOSD% -c %CFG_DIR%
|
||||
mintty -h never %TAOSD% -c %CFG_DIR%
|
||||
set /a check_num=0
|
||||
:check_online
|
||||
sleep 1
|
||||
|
@ -58,13 +59,25 @@ if %EXEC_OPTON% == stop (
|
|||
rem echo wmic process where "name='taosd.exe' and CommandLine like '%%%NODE_NAME%%%'" list INSTANCE
|
||||
rem wmic process where "name='taosd.exe' and CommandLine like '%%%NODE_NAME%%%'" call terminate > NUL 2>&1
|
||||
|
||||
for /f "tokens=1 skip=1" %%A in (
|
||||
'wmic process where "name='taosd.exe' and CommandLine like '%%%NODE_NAME%%%'" get processId '
|
||||
) do (
|
||||
rem echo taskkill /IM %%A
|
||||
taskkill /IM %%A > NUL 2>&1
|
||||
for /f "tokens=2" %%A in ('wmic process where "name='taosd.exe' and CommandLine like '%%%NODE_NAME%%%'" get processId ^| xargs echo') do (
|
||||
for /f "tokens=1" %%B in ('ps ^| grep %%A') do (
|
||||
if "%EXEC_SIGNAL%" == "SIGKILL" (
|
||||
kill -9 %%B
|
||||
) else (
|
||||
kill -INT %%B
|
||||
call :check_offline
|
||||
)
|
||||
)
|
||||
goto :finish
|
||||
)
|
||||
)
|
||||
|
||||
:finish
|
||||
goto :eof
|
||||
|
||||
:check_offline
|
||||
sleep 1
|
||||
for /f "tokens=2" %%C in ('wmic process where "name='taosd.exe' and CommandLine like '%%%NODE_NAME%%%'" get processId ^| xargs echo') do (
|
||||
echo check taosd offline
|
||||
goto :check_offline
|
||||
)
|
||||
goto :eof
|
|
@ -62,7 +62,5 @@ goto :eof
|
|||
|
||||
:CheckSkipCase
|
||||
set skipCase=false
|
||||
if "%*" == "./test.sh -f tsim/query/scalarFunction.sim" ( set skipCase=true )
|
||||
if "%*" == "./test.sh -f tsim/stream/distributeInterval0.sim" ( set skipCase=true )
|
||||
if "%*" == "./test.sh -f tsim/sma/rsmaCreateInsertQuery.sim" ( set skipCase=true )
|
||||
@REM if "%*" == "./test.sh -f tsim/query/scalarFunction.sim" ( set skipCase=true )
|
||||
:goto eof
|
|
@ -124,7 +124,7 @@ if $data(5)[3] != 3 then
|
|||
return -1
|
||||
endi
|
||||
|
||||
#sql reset query cache
|
||||
sql reset query cache
|
||||
|
||||
print =============== step4: select data
|
||||
sql show d1.tables
|
||||
|
|
|
@ -199,7 +199,7 @@ class TDTestCase:
|
|||
tdSql.checkData(0, 0, "true")
|
||||
# test select json tag->'key', value is null
|
||||
tdSql.query("select jtag->'tag1' from jsons1_4")
|
||||
tdSql.checkData(0, 0, "null")
|
||||
tdSql.checkData(0, 0, None)
|
||||
# test select json tag->'key', value is double
|
||||
tdSql.query("select jtag->'tag1' from jsons1_5")
|
||||
tdSql.checkData(0, 0, "1.232000000")
|
||||
|
|
|
@ -23,7 +23,7 @@ python3 ./test.py -f 1-insert/alter_stable.py
|
|||
python3 ./test.py -f 1-insert/alter_table.py
|
||||
python3 ./test.py -f 1-insert/insertWithMoreVgroup.py
|
||||
python3 ./test.py -f 1-insert/table_comment.py
|
||||
python3 ./test.py -f 1-insert/table_param_ttl.py
|
||||
#python3 ./test.py -f 1-insert/table_param_ttl.py
|
||||
python3 ./test.py -f 2-query/between.py
|
||||
python3 ./test.py -f 2-query/distinct.py
|
||||
python3 ./test.py -f 2-query/varchar.py
|
||||
|
|
|
@ -1 +1 @@
|
|||
Subproject commit 28a49b447f71c4f014ebbac858b7215b897d57fd
|
||||
Subproject commit 7105027650b51e701cfa1dac11b8fb42d447dd01
|
Loading…
Reference in New Issue