-
Notifications
You must be signed in to change notification settings - Fork 5k
Refactor/freemine.tdengine.stmt2 #35366
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
332f432
60e5796
b046501
dc9afb5
9729efd
3004f93
fe056b8
e22df35
7e3bcf2
d7072c7
581d339
fc237de
6beea07
462e523
fe17b3e
f0ea74d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3247,7 +3247,7 @@ void taosAsyncQueryImpl(uint64_t connId, const char* sql, __taos_async_fn_t fp, | |
| doAsyncQuery(pRequest, false); | ||
| } | ||
|
|
||
| void taosAsyncQueryImplWithReqid(uint64_t connId, const char* sql, __taos_async_fn_t fp, void* param, bool validateOnly, | ||
| void taosAsyncQueryImplWithReqid(TAOS_STMT2 *stmt, uint64_t connId, const char* sql, __taos_async_fn_t fp, void* param, bool validateOnly, | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. stmt的函数单独封装,不要和query耦合在一起
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. just don't get a clear solutions, otherwise i have to hard-copy the whole logic in the block. |
||
| int64_t reqid) { | ||
| if (sql == NULL || NULL == fp) { | ||
| terrno = TSDB_CODE_INVALID_PARA; | ||
|
|
@@ -3276,6 +3276,8 @@ void taosAsyncQueryImplWithReqid(uint64_t connId, const char* sql, __taos_async_ | |
| return; | ||
| } | ||
|
|
||
| pRequest->literal_by_stmt2 = stmt; | ||
|
|
||
| code = connCheckAndUpateMetric(connId); | ||
|
|
||
| if (code != TSDB_CODE_SUCCESS) { | ||
|
|
@@ -3347,7 +3349,7 @@ TAOS_RES* taosQueryImplWithReqid(TAOS* taos, const char* sql, bool validateOnly, | |
| return NULL; | ||
| } | ||
|
|
||
| taosAsyncQueryImplWithReqid(*(int64_t*)taos, sql, syncQueryFn, param, validateOnly, reqid); | ||
| taosAsyncQueryImplWithReqid(NULL, *(int64_t*)taos, sql, syncQueryFn, param, validateOnly, reqid); | ||
| code = tsem_wait(¶m->sem); | ||
| if (TSDB_CODE_SUCCESS != code) { | ||
| taosMemoryFree(param); | ||
|
|
@@ -3460,6 +3462,13 @@ void doRequestCallback(SRequestObj* pRequest, int32_t code) { | |
| pRequest->inCallback = true; | ||
|
|
||
| int64_t this = pRequest->self; | ||
| SRequestObj* pThis = acquireRequest(this); | ||
| if (pThis != pRequest) { | ||
| // NOTE: internal logic error, not recoverable!!! | ||
| tscError("internal logic error: SRequestObj lifecycle management"); | ||
| abort(); | ||
| } | ||
|
|
||
| if (tsQueryTbNotExistAsEmpty && TD_RES_QUERY(&pRequest->resType) && pRequest->isQuery && | ||
| (code == TSDB_CODE_PAR_TABLE_NOT_EXIST || code == TSDB_CODE_TDB_TABLE_NOT_EXIST)) { | ||
| code = TSDB_CODE_SUCCESS; | ||
|
|
@@ -3479,11 +3488,8 @@ void doRequestCallback(SRequestObj* pRequest, int32_t code) { | |
| pRequest->body.queryFp(((SSyncQueryParam*)pRequest->body.interParam)->userParam, pRequest, code); | ||
| } | ||
|
|
||
| SRequestObj* pReq = acquireRequest(this); | ||
| if (pReq != NULL) { | ||
| pReq->inCallback = false; | ||
| (void)releaseRequest(this); | ||
| } | ||
| pRequest->inCallback = false; | ||
| (void)releaseRequest(this); // NOTE: pairing `pThis = acquireRequest(this);` | ||
| } | ||
|
|
||
| int32_t clientParseSql(void* param, const char* dbName, const char* sql, bool parseOnly, const char* effectiveUser, | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -1897,7 +1897,8 @@ void handleQueryAnslyseRes(SSqlCallbackWrapper *pWrapper, SMetaData *pResultMeta | |
| qDestroyQuery(pRequest->pQuery); | ||
| pRequest->pQuery = NULL; | ||
|
|
||
| if (NEED_CLIENT_HANDLE_ERROR(code) && pRequest->stmtBindVersion == 0) { | ||
| if (NEED_CLIENT_HANDLE_ERROR(code) && (pRequest->stmtBindVersion == 0 || (pRequest->stmtBindVersion == 2 && pRequest->literal_by_stmt2))) { | ||
| // NOTE: also cover literal statement by stmt2 | ||
| tscDebug("req:0x%" PRIx64 ", client retry to handle the error, code:%d - %s, tryCount:%d, QID:0x%" PRIx64, | ||
| pRequest->self, code, tstrerror(code), pRequest->retry, pRequest->requestId); | ||
| restartAsyncQuery(pRequest, code); | ||
|
|
@@ -2005,7 +2006,7 @@ void taos_query_a(TAOS *taos, const char *sql, __taos_async_fn_t fp, void *param | |
|
|
||
| void taos_query_a_with_reqid(TAOS *taos, const char *sql, __taos_async_fn_t fp, void *param, int64_t reqid) { | ||
| int64_t connId = *(int64_t *)taos; | ||
| taosAsyncQueryImplWithReqid(connId, sql, fp, param, false, reqid); | ||
| taosAsyncQueryImplWithReqid(NULL, connId, sql, fp, param, false, reqid); | ||
| } | ||
|
|
||
| int32_t createParseContext(const SRequestObj *pRequest, SParseContext **pCxt, SSqlCallbackWrapper *pWrapper) { | ||
|
|
@@ -2089,24 +2090,8 @@ int32_t prepareAndParseSqlSyntax(SSqlCallbackWrapper **ppWrapper, SRequestObj *p | |
| return code; | ||
| } | ||
|
|
||
| void doAsyncQuery(SRequestObj *pRequest, bool updateMetaForce) { | ||
| SSqlCallbackWrapper *pWrapper = NULL; | ||
| int32_t code = TSDB_CODE_SUCCESS; | ||
|
|
||
| CLIENT_UPDATE_REQUEST_PHASE_IF_CHANGED(pRequest, QUERY_PHASE_PARSE); | ||
|
|
||
| if (pRequest->retry++ > REQUEST_TOTAL_EXEC_TIMES) { | ||
| code = pRequest->prevCode; | ||
| terrno = code; | ||
| pRequest->code = code; | ||
| tscDebug("req:0x%" PRIx64 ", call sync query cb with code:%s", pRequest->self, tstrerror(code)); | ||
| doRequestCallback(pRequest, code); | ||
| return; | ||
| } | ||
|
|
||
| if (TSDB_CODE_SUCCESS == code) { | ||
| code = prepareAndParseSqlSyntax(&pWrapper, pRequest, updateMetaForce); | ||
| } | ||
| static void doAsyncExec(SRequestObj *pRequest, int32_t code) { | ||
| SSqlCallbackWrapper *pWrapper = pRequest->pWrapper; | ||
|
|
||
| if (TSDB_CODE_SUCCESS == code) { | ||
| pRequest->stmtType = pRequest->pQuery->pRoot->type; | ||
|
|
@@ -2146,6 +2131,44 @@ void doAsyncQuery(SRequestObj *pRequest, bool updateMetaForce) { | |
| } | ||
| } | ||
|
|
||
| void doAsyncQuery(SRequestObj *pRequest, bool updateMetaForce) { | ||
| SSqlCallbackWrapper *pWrapper = NULL; | ||
| int32_t code = TSDB_CODE_SUCCESS; | ||
|
|
||
| CLIENT_UPDATE_REQUEST_PHASE_IF_CHANGED(pRequest, QUERY_PHASE_PARSE); | ||
|
|
||
| if (pRequest->retry++ > REQUEST_TOTAL_EXEC_TIMES) { | ||
| code = pRequest->prevCode; | ||
| terrno = code; | ||
| pRequest->code = code; | ||
| tscDebug("req:0x%" PRIx64 ", call sync query cb with code:%s", pRequest->self, tstrerror(code)); | ||
| doRequestCallback(pRequest, code); | ||
| return; | ||
| } | ||
|
|
||
| if (TSDB_CODE_SUCCESS == code) { | ||
| code = prepareAndParseSqlSyntax(&pWrapper, pRequest, updateMetaForce); | ||
| } | ||
|
|
||
| if (pRequest->literal_by_stmt2) { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 问题: 证据:
与本 MR 的关联:本 MR 引入该请求→stmt 反向引用以实现 literal exec-direct 功能。 修复建议:在赋值 |
||
| TAOS_STMT2* stmt = pRequest->literal_by_stmt2; | ||
| STscStmt2* pStmt = (STscStmt2*)stmt; | ||
| if (pStmt->ctx.prepared == 0) { | ||
| // NOTE: preparing stage for literal statement by stmt2 | ||
| doRequestCallback(pRequest, code); | ||
| return; | ||
| } | ||
| } | ||
|
|
||
| assert(pWrapper == pRequest->pWrapper); | ||
| doAsyncExec(pRequest, code); | ||
| } | ||
|
|
||
| void taosAsyncExecLiteral(TAOS_STMT2 *stmt) { | ||
| STscStmt2* pStmt = (STscStmt2*)stmt; | ||
| doAsyncExec(pStmt->exec.pRequest, pStmt->ctx.code); | ||
| } | ||
|
|
||
| void restartAsyncQuery(SRequestObj *pRequest, int32_t code) { | ||
| tscInfo("restart request:%s p:%p", pRequest->sqlstr, pRequest); | ||
| SRequestObj *pUserReq = pRequest; | ||
|
|
@@ -2815,6 +2838,10 @@ int taos_stmt2_bind_param(TAOS_STMT2 *stmt, TAOS_STMT2_BINDV *bindv, int32_t col | |
| int32_t code = TSDB_CODE_SUCCESS; | ||
| STMT2_DLOG_E("start to bind param"); | ||
|
|
||
| if (stmtIsLiteral(pStmt)) { | ||
| return stmtBindLiteral2(stmt); | ||
| } | ||
|
|
||
| // check query bind number | ||
| bool isQuery = (STMT_TYPE_QUERY == pStmt->sql.type || (pStmt->sql.type == 0 && stmt2IsSelect(stmt))); | ||
| if (isQuery) { | ||
|
|
@@ -2908,6 +2935,10 @@ int taos_stmt2_bind_param_a(TAOS_STMT2 *stmt, TAOS_STMT2_BINDV *bindv, int32_t c | |
|
|
||
| STscStmt2 *pStmt = (STscStmt2 *)stmt; | ||
|
|
||
| if (stmtIsLiteral(pStmt)) { | ||
| return stmtBindLiteral2(stmt); | ||
| } | ||
|
|
||
| ThreadArgs *args = (ThreadArgs *)taosMemoryMalloc(sizeof(ThreadArgs)); | ||
| args->stmt = stmt; | ||
| args->bindv = bindv; | ||
|
|
@@ -2978,6 +3009,12 @@ int taos_stmt2_get_fields(TAOS_STMT2 *stmt, int *count, TAOS_FIELD_ALL **fields) | |
| STscStmt2 *pStmt = (STscStmt2 *)stmt; | ||
| STMT2_DLOG_E("start to get fields"); | ||
|
|
||
| if (stmtIsLiteral(pStmt)) { | ||
| if (count) *count = 0; | ||
| if (fields) *fields = NULL; | ||
| return TSDB_CODE_SUCCESS; | ||
| } | ||
|
|
||
| if (STMT_TYPE_INSERT == pStmt->sql.type || STMT_TYPE_MULTI_INSERT == pStmt->sql.type || | ||
| (pStmt->sql.type == 0 && stmt2IsInsert(stmt))) { | ||
| return stmtGetStbColFields2(stmt, count, fields); | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.