From dfa681df3c2a7fa18d70bc9386579f7f08bbc548 Mon Sep 17 00:00:00 2001 From: root Date: Mon, 14 Sep 2020 17:24:08 +0800 Subject: [PATCH] [TD-1291] --- src/plugins/http/inc/httpParser.h | 1 + src/plugins/http/src/httpContext.c | 26 ++++++++++---------- src/plugins/http/src/httpHandle.c | 4 ++-- src/plugins/http/src/httpJson.c | 2 +- src/plugins/http/src/httpParser.c | 38 ++++++++++++++++++------------ src/plugins/http/src/httpQueue.c | 2 +- src/plugins/http/src/httpServer.c | 6 ++--- tests/script/sh/deploy.sh | 32 ++++++++++++------------- 8 files changed, 60 insertions(+), 51 deletions(-) diff --git a/src/plugins/http/inc/httpParser.h b/src/plugins/http/inc/httpParser.h index 7dd6d3e0fc..85ba843716 100644 --- a/src/plugins/http/inc/httpParser.h +++ b/src/plugins/http/inc/httpParser.h @@ -111,6 +111,7 @@ typedef struct HttpParser { void httpInitParser(HttpParser *parser); HttpParser *httpCreateParser(struct HttpContext *pContext); +void httpClearParser(HttpParser *parser); void httpDestroyParser(HttpParser *parser); int32_t httpParseBuf(HttpParser *parser, const char *buf, int32_t len); char * httpGetStatusDesc(int32_t statusCode); diff --git a/src/plugins/http/src/httpContext.c b/src/plugins/http/src/httpContext.c index 2c65b9d16a..3114fb702e 100644 --- a/src/plugins/http/src/httpContext.c +++ b/src/plugins/http/src/httpContext.c @@ -138,7 +138,7 @@ HttpContext *httpGetContext(void *ptr) { HttpContext *pContext = *ppContext; if (pContext) { int32_t refCount = atomic_add_fetch_32(&pContext->refCount, 1); - httpDebug("context:%p, fd:%d, is accquired, data:%p refCount:%d", pContext, pContext->fd, ppContext, refCount); + httpTrace("context:%p, fd:%d, is accquired, data:%p refCount:%d", pContext, pContext->fd, ppContext, refCount); return pContext; } } @@ -152,9 +152,9 @@ void httpReleaseContext(HttpContext *pContext) { return; } - pContext->parser->inited = 0; + httpClearParser(pContext->parser); HttpContext **ppContext = pContext->ppContext; - httpDebug("context:%p, is released, data:%p refCount:%d", pContext, ppContext, refCount); + httpTrace("context:%p, is released, data:%p refCount:%d", pContext, ppContext, refCount); if (tsHttpServer.contextCache != NULL) { taosCacheRelease(tsHttpServer.contextCache, (void **)(&ppContext), false); @@ -173,7 +173,7 @@ bool httpInitContext(HttpContext *pContext) { memset(&pContext->singleCmd, 0, sizeof(HttpSqlCmd)); - httpDebug("context:%p, fd:%d, parsed:%d", pContext, pContext->fd, pContext->parsed); + httpTrace("context:%p, fd:%d, parsed:%d", pContext, pContext->fd, pContext->parsed); return true; } @@ -191,15 +191,15 @@ void httpCloseContextByApp(HttpContext *pContext) { if (keepAlive) { if (httpAlterContextState(pContext, HTTP_CONTEXT_STATE_HANDLING, HTTP_CONTEXT_STATE_READY)) { - httpDebug("context:%p, fd:%d, last state:handling, keepAlive:true, reuse context", pContext, pContext->fd); + httpTrace("context:%p, fd:%d, last state:handling, keepAlive:true, reuse context", pContext, pContext->fd); } else if (httpAlterContextState(pContext, HTTP_CONTEXT_STATE_DROPPING, HTTP_CONTEXT_STATE_CLOSED)) { httpRemoveContextFromEpoll(pContext); - httpDebug("context:%p, fd:%d, ast state:dropping, keepAlive:true, close connect", pContext, pContext->fd); + httpTrace("context:%p, fd:%d, ast state:dropping, keepAlive:true, close connect", pContext, pContext->fd); } else if (httpAlterContextState(pContext, HTTP_CONTEXT_STATE_READY, HTTP_CONTEXT_STATE_READY)) { - httpDebug("context:%p, fd:%d, last state:ready, keepAlive:true, reuse context", pContext, pContext->fd); + httpTrace("context:%p, fd:%d, last state:ready, keepAlive:true, reuse context", pContext, pContext->fd); } else if (httpAlterContextState(pContext, HTTP_CONTEXT_STATE_CLOSED, HTTP_CONTEXT_STATE_CLOSED)) { httpRemoveContextFromEpoll(pContext); - httpDebug("context:%p, fd:%d, last state:ready, keepAlive:true, close connect", pContext, pContext->fd); + httpTrace("context:%p, fd:%d, last state:ready, keepAlive:true, close connect", pContext, pContext->fd); } else { httpRemoveContextFromEpoll(pContext); httpError("context:%p, fd:%d, last state:%s:%d, keepAlive:true, close connect", pContext, pContext->fd, @@ -207,7 +207,7 @@ void httpCloseContextByApp(HttpContext *pContext) { } } else { httpRemoveContextFromEpoll(pContext); - httpDebug("context:%p, fd:%d, ilast state:%s:%d, keepAlive:false, close context", pContext, pContext->fd, + httpTrace("context:%p, fd:%d, ilast state:%s:%d, keepAlive:false, close context", pContext, pContext->fd, httpContextStateStr(pContext->state), pContext->state); } @@ -216,13 +216,13 @@ void httpCloseContextByApp(HttpContext *pContext) { void httpCloseContextByServer(HttpContext *pContext) { if (httpAlterContextState(pContext, HTTP_CONTEXT_STATE_HANDLING, HTTP_CONTEXT_STATE_DROPPING)) { - httpDebug("context:%p, fd:%d, epoll finished, still used by app", pContext, pContext->fd); + httpTrace("context:%p, fd:%d, epoll finished, still used by app", pContext, pContext->fd); } else if (httpAlterContextState(pContext, HTTP_CONTEXT_STATE_DROPPING, HTTP_CONTEXT_STATE_DROPPING)) { - httpDebug("context:%p, fd:%d, epoll already finished, wait app finished", pContext, pContext->fd); + httpTrace("context:%p, fd:%d, epoll already finished, wait app finished", pContext, pContext->fd); } else if (httpAlterContextState(pContext, HTTP_CONTEXT_STATE_READY, HTTP_CONTEXT_STATE_CLOSED)) { - httpDebug("context:%p, fd:%d, epoll finished, close connect", pContext, pContext->fd); + httpTrace("context:%p, fd:%d, epoll finished, close connect", pContext, pContext->fd); } else if (httpAlterContextState(pContext, HTTP_CONTEXT_STATE_CLOSED, HTTP_CONTEXT_STATE_CLOSED)) { - httpDebug("context:%p, fd:%d, epoll finished, will be closed soon", pContext, pContext->fd); + httpTrace("context:%p, fd:%d, epoll finished, will be closed soon", pContext, pContext->fd); } else { httpError("context:%p, fd:%d, unknown state:%d", pContext, pContext->fd, pContext->state); } diff --git a/src/plugins/http/src/httpHandle.c b/src/plugins/http/src/httpHandle.c index 9fb46c5734..b50217cfc4 100644 --- a/src/plugins/http/src/httpHandle.c +++ b/src/plugins/http/src/httpHandle.c @@ -33,7 +33,7 @@ bool httpDecodeRequest(HttpContext* pContext) { */ bool httpProcessData(HttpContext* pContext) { if (!httpAlterContextState(pContext, HTTP_CONTEXT_STATE_READY, HTTP_CONTEXT_STATE_HANDLING)) { - httpDebug("context:%p, fd:%d, state:%s not in ready state, stop process request", pContext, pContext->fd, + httpTrace("context:%p, fd:%d, state:%s not in ready state, stop process request", pContext, pContext->fd, httpContextStateStr(pContext->state)); httpCloseContextByApp(pContext); return false; @@ -41,7 +41,7 @@ bool httpProcessData(HttpContext* pContext) { // handle Cross-domain request if (strcmp(pContext->parser->method, "OPTIONS") == 0) { - httpDebug("context:%p, fd:%d, process options request", pContext, pContext->fd); + httpTrace("context:%p, fd:%d, process options request", pContext, pContext->fd); httpSendOptionResp(pContext, "process options request success"); } else { if (!httpDecodeRequest(pContext)) { diff --git a/src/plugins/http/src/httpJson.c b/src/plugins/http/src/httpJson.c index 669e7c9781..e9a8947df2 100644 --- a/src/plugins/http/src/httpJson.c +++ b/src/plugins/http/src/httpJson.c @@ -189,7 +189,7 @@ void httpInitJsonBuf(JsonBuf* buf, struct HttpContext* pContext) { httpGzipCompressInit(buf->pContext); } - httpDebug("context:%p, fd:%d, json buffer initialized", buf->pContext, buf->pContext->fd); + httpTrace("context:%p, fd:%d, json buffer initialized", buf->pContext, buf->pContext->fd); } void httpJsonItemToken(JsonBuf* buf) { diff --git a/src/plugins/http/src/httpParser.c b/src/plugins/http/src/httpParser.c index ec71bb2daf..6f64e55b73 100644 --- a/src/plugins/http/src/httpParser.c +++ b/src/plugins/http/src/httpParser.c @@ -178,7 +178,7 @@ static int32_t httpOnRequestLine(HttpParser *pParser, char *method, char *target } if (pContext->decodeMethod != NULL) { - httpDebug("context:%p, fd:%d, decode method is %s", pContext, pContext->fd, pContext->decodeMethod->module); + httpTrace("context:%p, fd:%d, decode method is %s", pContext, pContext->fd, pContext->decodeMethod->module); } else { httpError("context:%p, fd:%d, the url is not support, target:%s", pContext, pContext->fd, target); httpOnError(pParser, 0, TSDB_CODE_HTTP_UNSUPPORT_URL); @@ -190,7 +190,7 @@ static int32_t httpOnRequestLine(HttpParser *pParser, char *method, char *target httpError("context:%p, fd:%d, unsupport httpVersion %d", pContext, pContext->fd, pParser->httpVersion); httpOnError(pParser, 0, TSDB_CODE_HTTP_INVALID_VERSION); } else { - httpDebug("context:%p, fd:%d, httpVersion:1.%d", pContext, pContext->fd, pParser->httpVersion); + httpTrace("context:%p, fd:%d, httpVersion:1.%d", pContext, pContext->fd, pParser->httpVersion); } return 0; @@ -204,7 +204,7 @@ static int32_t httpOnStatusLine(HttpParser *pParser, int32_t code, const char *r static int32_t httpOnParseHeaderField(HttpParser *parser, const char *key, const char *val) { HttpContext *pContext = parser->pContext; - httpDebug("context:%p, fd:%d, key:%s val:%s", pContext, pContext->fd, key, val); + httpTrace("context:%p, fd:%d, key:%s val:%s", pContext, pContext->fd, key, val); if (0 == strcasecmp(key, "Content-Length")) { int32_t len = 0; @@ -214,7 +214,7 @@ static int32_t httpOnParseHeaderField(HttpParser *parser, const char *key, const parser->contentLength = len; parser->chunkSize = len; parser->contentLengthSpecified = 1; - httpDebug("context:%p, fd:%d, contentLength:%d chunkSize:%d contentLengthSpecified:%d", pContext, pContext->fd, + httpTrace("context:%p, fd:%d, contentLength:%d chunkSize:%d contentLengthSpecified:%d", pContext, pContext->fd, parser->contentLength, parser->chunkSize, parser->contentLengthSpecified); return 0; } else { @@ -227,11 +227,11 @@ static int32_t httpOnParseHeaderField(HttpParser *parser, const char *key, const else if (0 == strcasecmp(key, "Accept-Encoding")) { if (strstr(val, "gzip")) { parser->acceptEncodingGzip = 1; - httpDebug("context:%p, fd:%d, acceptEncodingGzip:%d", pContext, pContext->fd, parser->acceptEncodingGzip); + httpTrace("context:%p, fd:%d, acceptEncodingGzip:%d", pContext, pContext->fd, parser->acceptEncodingGzip); } if (strstr(val, "chunked")) { parser->acceptEncodingChunked = 1; - httpDebug("context:%p, fd:%d, acceptEncodingChunked:%d", pContext, pContext->fd, parser->acceptEncodingChunked); + httpTrace("context:%p, fd:%d, acceptEncodingChunked:%d", pContext, pContext->fd, parser->acceptEncodingChunked); } return 0; } @@ -248,7 +248,7 @@ static int32_t httpOnParseHeaderField(HttpParser *parser, const char *key, const else if (0 == strcasecmp(key, "Content-Encoding")) { if (0 == strcmp(val, "gzip")) { parser->contentChunked = 1; - httpDebug("context:%p, fd:%d, contentChunked:%d", pContext, pContext->fd, parser->contentChunked); + httpTrace("context:%p, fd:%d, contentChunked:%d", pContext, pContext->fd, parser->contentChunked); } return 0; } @@ -271,7 +271,7 @@ static int32_t httpOnParseHeaderField(HttpParser *parser, const char *key, const } if (strstr(val, "chunked")) { parser->transferChunked = 1; - httpDebug("context:%p, fd:%d, transferChunked:%d", pContext, pContext->fd, parser->transferChunked); + httpTrace("context:%p, fd:%d, transferChunked:%d", pContext, pContext->fd, parser->transferChunked); } return 0; } @@ -289,7 +289,7 @@ static int32_t httpOnParseHeaderField(HttpParser *parser, const char *key, const s = NULL; free(t); free(s); - httpDebug("context:%p, fd:%d, basic auth:%s", pContext, pContext->fd, parser->authContent); + httpTrace("context:%p, fd:%d, basic auth:%s", pContext, pContext->fd, parser->authContent); int32_t ok = httpParseBasicAuthToken(pContext, parser->authContent, strlen(parser->authContent)); if (ok != 0) { httpOnError(parser, 0, TSDB_CODE_HTTP_INVALID_BASIC_AUTH); @@ -303,7 +303,7 @@ static int32_t httpOnParseHeaderField(HttpParser *parser, const char *key, const s = NULL; free(t); free(s); - httpDebug("context:%p, fd:%d, taosd auth:%s", pContext, pContext->fd, parser->authContent); + httpTrace("context:%p, fd:%d, taosd auth:%s", pContext, pContext->fd, parser->authContent); int32_t ok = httpParseTaosdAuthToken(pContext, parser->authContent, strlen(parser->authContent)); if (ok != 0) { httpOnError(parser, 0, TSDB_CODE_HTTP_INVALID_TAOSD_AUTH); @@ -371,7 +371,7 @@ static int32_t httpOnEnd(HttpParser *parser) { return -1; } - httpDebug("context:%p, fd:%d, parse success", pContext, pContext->fd); + httpTrace("context:%p, fd:%d, parse success", pContext, pContext->fd); return 0; } @@ -422,7 +422,7 @@ static int32_t httpCleanupStack(HttpStack *stack) { void httpInitParser(HttpParser *parser) { HttpContext *pContext = parser->pContext; - httpTrace("context:%p, fd:%d, free parser", pContext, pContext->fd); + httpTrace("context:%p, fd:%d, init parser", pContext, pContext->fd); parser->parsed = false; parser->inited = 1; @@ -475,9 +475,17 @@ HttpParser *httpCreateParser(HttpContext *pContext) { return parser; } +void httpClearParser(HttpParser *parser) { + HttpContext *pContext = parser->pContext; + httpTrace("context:%p, fd:%d, clear parser", pContext, pContext->fd); + + pContext->parser->inited = 0; + pContext->parser->parsed = false; +} + void httpDestroyParser(HttpParser *parser) { HttpContext *pContext = parser->pContext; - httpTrace("context:%p, fd:%d, free parser", pContext, pContext->fd); + httpTrace("context:%p, fd:%d, destroy parser", pContext, pContext->fd); if (!parser) return; @@ -603,7 +611,7 @@ static int32_t httpParserOnMethod(HttpParser *parser, HTTP_PARSER_STATE state, c do { if (isalnum(c) || strchr("!#$%&'*+-.^_`|~", c)) { if (httpAppendString(&parser->str, &c, 1)) { - httpDebug("context:%p, fd:%d, parser state:%d, char:[%c]%02x, oom", pContext, pContext->fd, state, c, c); + httpError("context:%p, fd:%d, parser state:%d, char:[%c]%02x, oom", pContext, pContext->fd, state, c, c); ok = -1; httpOnError(parser, 507, TSDB_CODE_HTTP_PARSE_METHOD_FAILED); break; @@ -719,7 +727,7 @@ static int32_t httpParserOnSp(HttpParser *parser, HTTP_PARSER_STATE state, const httpPopStack(parser); break; } - httpDebug("context:%p, fd:%d, parser state:%d, char:[%c]%02x, oom", pContext, pContext->fd, state, c, c); + httpError("context:%p, fd:%d, parser state:%d, char:[%c]%02x, oom", pContext, pContext->fd, state, c, c); ok = -1; httpOnError(parser, 507, TSDB_CODE_HTTP_PARSE_SP_FAILED); } while (0); diff --git a/src/plugins/http/src/httpQueue.c b/src/plugins/http/src/httpQueue.c index 76632eb508..86a97a6abe 100644 --- a/src/plugins/http/src/httpQueue.c +++ b/src/plugins/http/src/httpQueue.c @@ -71,7 +71,7 @@ static void *httpProcessResultQueue(void *param) { break; } - httpDebug("context:%p, res:%p will be processed in result queue", pMsg->param, pMsg->result); + httpTrace("context:%p, res:%p will be processed in result queue", pMsg->param, pMsg->result); (*pMsg->fp)(pMsg->param, pMsg->result, pMsg->numOfRows); taosFreeQitem(pMsg); } diff --git a/src/plugins/http/src/httpServer.c b/src/plugins/http/src/httpServer.c index 0bca8cf041..a4d84b7a03 100644 --- a/src/plugins/http/src/httpServer.c +++ b/src/plugins/http/src/httpServer.c @@ -302,11 +302,11 @@ bool httpInitConnect() { static bool httpReadData(HttpContext *pContext) { HttpParser *pParser = pContext->parser; - ASSERT(!pParser->parsed); if (!pParser->inited) { httpInitParser(pParser); } + ASSERT(!pParser->parsed); pContext->accessTimes++; pContext->lastAccessTime = taosGetTimestampSec(); @@ -332,10 +332,10 @@ static bool httpReadData(HttpContext *pContext) { } if (!pParser->parsed) { - httpDebug("context:%p, fd:%d, read not over yet, len:%d", pContext, pContext->fd, pParser->body.pos); + httpTrace("context:%p, fd:%d, read not over yet, len:%d", pContext, pContext->fd, pParser->body.pos); return false; } else { - httpDebug("context:%p, fd:%d, len:%d, body:%s", pContext, pContext->fd, pParser->body.pos, pParser->body.str); + httpTraceL("context:%p, fd:%d, len:%d, body:%s", pContext, pContext->fd, pParser->body.pos, pParser->body.str); return true; } } else if (nread < 0) { diff --git a/tests/script/sh/deploy.sh b/tests/script/sh/deploy.sh index 45739b7d99..0d444a5a6e 100755 --- a/tests/script/sh/deploy.sh +++ b/tests/script/sh/deploy.sh @@ -111,23 +111,23 @@ echo "serverPort ${NODE}" >> $TAOS_CFG echo "dataDir $DATA_DIR" >> $TAOS_CFG echo "logDir $LOG_DIR" >> $TAOS_CFG echo "debugFlag 0" >> $TAOS_CFG -echo "mDebugFlag 131" >> $TAOS_CFG -echo "sdbDebugFlag 131" >> $TAOS_CFG -echo "dDebugFlag 131" >> $TAOS_CFG -echo "vDebugFlag 131" >> $TAOS_CFG -echo "tsdbDebugFlag 131" >> $TAOS_CFG -echo "cDebugFlag 131" >> $TAOS_CFG -echo "jnidebugFlag 131" >> $TAOS_CFG -echo "odbcdebugFlag 131" >> $TAOS_CFG -echo "httpDebugFlag 207" >> $TAOS_CFG -echo "monitorDebugFlag 131" >> $TAOS_CFG -echo "mqttDebugFlag 131" >> $TAOS_CFG -echo "qdebugFlag 131" >> $TAOS_CFG -echo "rpcDebugFlag 131" >> $TAOS_CFG +echo "mDebugFlag 135" >> $TAOS_CFG +echo "sdbDebugFlag 135" >> $TAOS_CFG +echo "dDebugFlag 135" >> $TAOS_CFG +echo "vDebugFlag 135" >> $TAOS_CFG +echo "tsdbDebugFlag 135" >> $TAOS_CFG +echo "cDebugFlag 135" >> $TAOS_CFG +echo "jnidebugFlag 135" >> $TAOS_CFG +echo "odbcdebugFlag 135" >> $TAOS_CFG +echo "httpDebugFlag 135" >> $TAOS_CFG +echo "monitorDebugFlag 135" >> $TAOS_CFG +echo "mqttDebugFlag 135" >> $TAOS_CFG +echo "qdebugFlag 135" >> $TAOS_CFG +echo "rpcDebugFlag 135" >> $TAOS_CFG echo "tmrDebugFlag 131" >> $TAOS_CFG -echo "udebugFlag 131" >> $TAOS_CFG -echo "sdebugFlag 131" >> $TAOS_CFG -echo "wdebugFlag 131" >> $TAOS_CFG +echo "udebugFlag 135" >> $TAOS_CFG +echo "sdebugFlag 135" >> $TAOS_CFG +echo "wdebugFlag 135" >> $TAOS_CFG echo "monitor 0" >> $TAOS_CFG echo "monitorInterval 1" >> $TAOS_CFG echo "http 0" >> $TAOS_CFG -- GitLab