Merge pull request #26722 from taosdata/fix/matchError

fix: client init regex cache
This commit is contained in:
dapan1121 2024-07-22 18:41:45 +08:00 committed by GitHub
commit dec8095e53
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 13 additions and 0 deletions

View File

@ -35,6 +35,7 @@
#include "tsched.h"
#include "ttime.h"
#include "tversion.h"
#include "tcompare.h"
#if defined(CUS_NAME) || defined(CUS_PROMPT) || defined(CUS_EMAIL)
#include "cus_name.h"
@ -875,6 +876,12 @@ void taos_init_imp(void) {
}
rpcInit();
if (InitRegexCache() != 0) {
tscInitRes = -1;
tscError("failed to init regex cache");
return;
}
SCatalogCfg cfg = {.maxDBCacheNum = 100, .maxTblCacheNum = 100};
catalogInit(&cfg);

View File

@ -28,6 +28,7 @@
#include "tref.h"
#include "trpc.h"
#include "version.h"
#include "tcompare.h"
#define TSC_VAR_NOT_RELEASE 1
#define TSC_VAR_RELEASED 0
@ -78,6 +79,7 @@ void taos_cleanup(void) {
clientConnRefPool = -1;
taosCloseRef(id);
DestroyRegexCache();
rpcCleanup();
tscDebug("rpc cleanup");

View File

@ -1299,6 +1299,7 @@ static UsingRegex **getRegComp(const char *pPattern) {
UsingRegex *pUsingRegex = taosMemoryMalloc(sizeof(UsingRegex));
if (pUsingRegex == NULL) {
terrno = TSDB_CODE_OUT_OF_MEMORY;
uError("Failed to Malloc when compile regex pattern %s.", pPattern);
return NULL;
}
@ -1309,6 +1310,7 @@ static UsingRegex **getRegComp(const char *pPattern) {
regerror(ret, &pUsingRegex->pRegex, msgbuf, tListLen(msgbuf));
uError("Failed to compile regex pattern %s. reason %s", pPattern, msgbuf);
taosMemoryFree(pUsingRegex);
terrno = TSDB_CODE_PAR_REGULAR_EXPRESSION_ERROR;
return NULL;
}
@ -1317,6 +1319,7 @@ static UsingRegex **getRegComp(const char *pPattern) {
if (code != 0 && code != TSDB_CODE_DUP_KEY) {
regexCacheFree(&pUsingRegex);
uError("Failed to put regex pattern %s into cache, exception internal error.", pPattern);
terrno = code;
return NULL;
}
ppUsingRegex = (UsingRegex **)taosHashAcquire(sRegexCache.regexHash, pPattern, strlen(pPattern));
@ -1350,6 +1353,7 @@ static int32_t doExecRegexMatch(const char *pString, const char *pPattern) {
ret = regexec(&(*pUsingRegex)->pRegex, pString, 1, pmatch, 0);
releaseRegComp(pUsingRegex);
if (ret != 0 && ret != REG_NOMATCH) {
terrno = TSDB_CODE_PAR_REGULAR_EXPRESSION_ERROR;
regerror(ret, &(*pUsingRegex)->pRegex, msgbuf, sizeof(msgbuf));
uDebug("Failed to match %s with pattern %s, reason %s", pString, pPattern, msgbuf)
}