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); UsingRegex **ppUsingRegex = taosHashIterate(sRegexCache.regexHash, NULL);
while ((ppUsingRegex != NULL)) { while ((ppUsingRegex != NULL)) {
if (taosGetTimestampSec() - (*ppUsingRegex)->lastUsedTime > REGEX_CACHE_CLEAR_TIME) { if (taosGetTimestampSec() - (*ppUsingRegex)->lastUsedTime > REGEX_CACHE_CLEAR_TIME) {
taosHashRelease(sRegexCache.regexHash, ppUsingRegex); taosHashRemove(sRegexCache.regexHash, ppUsingRegex);
} }
ppUsingRegex = taosHashIterate(sRegexCache.regexHash, ppUsingRegex); ppUsingRegex = taosHashIterate(sRegexCache.regexHash, ppUsingRegex);
} }
@ -1312,24 +1312,20 @@ static UsingRegex **getRegComp(const char *pPattern) {
while (true) { while (true) {
int code = taosHashPut(sRegexCache.regexHash, pPattern, strlen(pPattern), &pUsingRegex, sizeof(UsingRegex *)); int code = taosHashPut(sRegexCache.regexHash, pPattern, strlen(pPattern), &pUsingRegex, sizeof(UsingRegex *));
if (code != 0) { if (code != 0 && code != TSDB_CODE_DUP_KEY) {
if (terrno == TSDB_CODE_DUP_KEY) { regexCacheFree(&pUsingRegex);
terrno = TSDB_CODE_SUCCESS; uError("Failed to put regex pattern %s into cache, exception internal error.", pPattern);
ppUsingRegex = (UsingRegex **)taosHashAcquire(sRegexCache.regexHash, pPattern, strlen(pPattern)); return NULL;
if (ppUsingRegex) { }
if (*ppUsingRegex != pUsingRegex) { ppUsingRegex = (UsingRegex **)taosHashAcquire(sRegexCache.regexHash, pPattern, strlen(pPattern));
regexCacheFree(&pUsingRegex); if (ppUsingRegex) {
} if (*ppUsingRegex != pUsingRegex) {
pUsingRegex = (*ppUsingRegex);
break;
} else {
continue;
}
} else {
regexCacheFree(&pUsingRegex); regexCacheFree(&pUsingRegex);
uError("Failed to put regex pattern %s into cache, exception internal error.", pPattern);
return NULL;
} }
pUsingRegex = (*ppUsingRegex);
break;
} else {
continue;
} }
} }
pUsingRegex->lastUsedTime = taosGetTimestampSec(); pUsingRegex->lastUsedTime = taosGetTimestampSec();