l2 cache
This commit is contained in:
parent
37fc4f5674
commit
8fcf57c077
|
@ -49,6 +49,7 @@ int32_t InitRegexCache();
|
|||
void DestroyRegexCache();
|
||||
int32_t patternMatch(const char *pattern, size_t psize, const char *str, size_t ssize, const SPatternCompareInfo *pInfo);
|
||||
int32_t checkRegexPattern(const char *pPattern);
|
||||
void DestoryThreadLocalRegComp();
|
||||
|
||||
int32_t wcsPatternMatch(const TdUcs4 *pattern, size_t psize, const TdUcs4 *str, size_t ssize, const SPatternCompareInfo *pInfo);
|
||||
|
||||
|
|
|
@ -1290,13 +1290,12 @@ int32_t checkRegexPattern(const char *pPattern) {
|
|||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
static UsingRegex **getRegComp(const char *pPattern) {
|
||||
UsingRegex **getRegComp(const char *pPattern) {
|
||||
UsingRegex **ppUsingRegex = (UsingRegex **)taosHashAcquire(sRegexCache.regexHash, pPattern, strlen(pPattern));
|
||||
if (ppUsingRegex != NULL) {
|
||||
(*ppUsingRegex)->lastUsedTime = taosGetTimestampSec();
|
||||
return ppUsingRegex;
|
||||
}
|
||||
|
||||
UsingRegex *pUsingRegex = taosMemoryMalloc(sizeof(UsingRegex));
|
||||
if (pUsingRegex == NULL) {
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
|
@ -1341,20 +1340,56 @@ void releaseRegComp(UsingRegex **regex){
|
|||
taosHashRelease(sRegexCache.regexHash, regex);
|
||||
}
|
||||
|
||||
static int32_t doExecRegexMatch(const char *pString, const char *pPattern) {
|
||||
int32_t ret = 0;
|
||||
char msgbuf[256] = {0};
|
||||
static threadlocal UsingRegex ** ppRegex;
|
||||
static threadlocal char *pOldPattern = NULL;
|
||||
void DestoryThreadLocalRegComp() {
|
||||
if (NULL != pOldPattern) {
|
||||
releaseRegComp(ppRegex);
|
||||
taosMemoryFree(pOldPattern);
|
||||
pOldPattern = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
int32_t threadGetRegComp(regex_t **regex, const char *pPattern) {
|
||||
if (NULL != pOldPattern) {
|
||||
if (strcmp(pOldPattern, pPattern) == 0) {
|
||||
*regex = &(*ppRegex)->pRegex;
|
||||
return 0;
|
||||
} else {
|
||||
DestoryThreadLocalRegComp();
|
||||
}
|
||||
}
|
||||
|
||||
UsingRegex **pUsingRegex = getRegComp(pPattern);
|
||||
if (pUsingRegex == NULL) {
|
||||
return 1;
|
||||
}
|
||||
pOldPattern = (char *)taosMemoryMalloc(strlen(pPattern) + 1);
|
||||
if (NULL == pOldPattern) {
|
||||
uError("Failed to Malloc when compile regex pattern %s.", pPattern);
|
||||
return TSDB_CODE_OUT_OF_MEMORY;
|
||||
}
|
||||
strcpy(pOldPattern, pPattern);
|
||||
ppRegex = pUsingRegex;
|
||||
*regex = &(*pUsingRegex)->pRegex;
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int32_t doExecRegexMatch(const char *pString, const char *pPattern) {
|
||||
int32_t ret = 0;
|
||||
char msgbuf[256] = {0};
|
||||
|
||||
regex_t *regex = NULL;
|
||||
ret = threadGetRegComp(®ex, pPattern);
|
||||
if (ret != 0) {
|
||||
return ret;
|
||||
}
|
||||
|
||||
regmatch_t pmatch[1];
|
||||
ret = regexec(&(*pUsingRegex)->pRegex, pString, 1, pmatch, 0);
|
||||
releaseRegComp(pUsingRegex);
|
||||
ret = regexec(regex, pString, 1, pmatch, 0);
|
||||
if (ret != 0 && ret != REG_NOMATCH) {
|
||||
terrno = TSDB_CODE_PAR_REGULAR_EXPRESSION_ERROR;
|
||||
(void)regerror(ret, &(*pUsingRegex)->pRegex, msgbuf, sizeof(msgbuf));
|
||||
(void)regerror(ret, regex, msgbuf, sizeof(msgbuf));
|
||||
uDebug("Failed to match %s with pattern %s, reason %s", pString, pPattern, msgbuf)
|
||||
}
|
||||
|
||||
|
|
|
@ -106,6 +106,7 @@ static void *tQWorkerThreadFp(SQueueWorker *worker) {
|
|||
}
|
||||
|
||||
destroyThreadLocalGeosCtx();
|
||||
DestoryThreadLocalRegComp();
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
@ -237,6 +238,7 @@ static void *tAutoQWorkerThreadFp(SQueueWorker *worker) {
|
|||
|
||||
taosUpdateItemSize(qinfo.queue, 1);
|
||||
}
|
||||
DestoryThreadLocalRegComp();
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
|
|
@ -119,6 +119,13 @@ add_test(
|
|||
COMMAND bufferTest
|
||||
)
|
||||
|
||||
add_executable(regexTest "regexTest.cpp")
|
||||
target_link_libraries(regexTest os util gtest_main )
|
||||
add_test(
|
||||
NAME regexTest
|
||||
COMMAND regexTest
|
||||
)
|
||||
|
||||
#add_executable(decompressTest "decompressTest.cpp")
|
||||
#target_link_libraries(decompressTest os util common gtest_main)
|
||||
#add_test(
|
||||
|
|
Loading…
Reference in New Issue