fix: regex hash

This commit is contained in:
factosea 2024-07-15 14:56:23 +08:00
parent e88277592a
commit a5073355bb
1 changed files with 13 additions and 17 deletions

View File

@ -1228,7 +1228,7 @@ static void checkRegexCache(void* param, void* tmrId) {
UsingRegex **ppUsingRegex = taosHashIterate(sRegexCache.regexHash, NULL);
while ((ppUsingRegex != NULL)) {
if (taosGetTimestampSec() - (*ppUsingRegex)->lastUsedTime > REGEX_CACHE_CLEAR_TIME) {
taosHashRelease(sRegexCache.regexHash, ppUsingRegex);
taosHashRemove(sRegexCache.regexHash, ppUsingRegex);
}
ppUsingRegex = taosHashIterate(sRegexCache.regexHash, ppUsingRegex);
}
@ -1312,9 +1312,11 @@ static UsingRegex **getRegComp(const char *pPattern) {
while (true) {
int code = taosHashPut(sRegexCache.regexHash, pPattern, strlen(pPattern), &pUsingRegex, sizeof(UsingRegex *));
if (code != 0) {
if (terrno == TSDB_CODE_DUP_KEY) {
terrno = TSDB_CODE_SUCCESS;
if (code != 0 && code != TSDB_CODE_DUP_KEY) {
regexCacheFree(&pUsingRegex);
uError("Failed to put regex pattern %s into cache, exception internal error.", pPattern);
return NULL;
}
ppUsingRegex = (UsingRegex **)taosHashAcquire(sRegexCache.regexHash, pPattern, strlen(pPattern));
if (ppUsingRegex) {
if (*ppUsingRegex != pUsingRegex) {
@ -1325,12 +1327,6 @@ static UsingRegex **getRegComp(const char *pPattern) {
} else {
continue;
}
} else {
regexCacheFree(&pUsingRegex);
uError("Failed to put regex pattern %s into cache, exception internal error.", pPattern);
return NULL;
}
}
}
pUsingRegex->lastUsedTime = taosGetTimestampSec();
return ppUsingRegex;