This commit is contained in:
xsren 2024-09-09 15:47:17 +08:00
parent 3825f76dfc
commit 520336e129
10 changed files with 44 additions and 20 deletions

View File

@ -821,9 +821,10 @@ int32_t monitorInit() {
return code;
}
if (taosMulModeMkDir(tmpSlowLogPath, 0777, true) != 0) {
code = taosMulModeMkDir(tmpSlowLogPath, 0777, true);
if (code != 0) {
tscError("failed to create dir:%s since %s", tmpSlowLogPath, terrstr());
return TAOS_GET_TERRNO(TSDB_CODE_OUT_OF_MEMORY);
return code;
}
if (tsem2_init(&monitorSem, 0, 0) != 0) {

View File

@ -1881,7 +1881,6 @@ void s3EvictCache(const char *path, long object_size) {
// 1, list data files' atime under dir(path)
tdbDirPtr pDir = taosOpenDir(dir_name);
if (pDir == NULL) {
terrno = TAOS_SYSTEM_ERROR(errno);
vError("failed to open %s since %s", dir_name, terrstr());
}
SArray *evict_files = taosArrayInit(16, sizeof(SEvictFile));

View File

@ -1125,7 +1125,7 @@ static int32_t tfileGetFileList(const char* path, SArray** ppResult) {
TdDirPtr pDir = taosOpenDir(path);
if (NULL == pDir) {
TAOS_CHECK_GOTO(TAOS_SYSTEM_ERROR(errno), NULL, _exception);
TAOS_CHECK_GOTO(terrno, NULL, _exception);
}
TdDirEntryPtr pDirEntry;
while ((pDirEntry = taosReadDir(pDir)) != NULL) {

View File

@ -599,7 +599,7 @@ int32_t backendFileCopyFilesImpl(const char* src, const char* dst) {
// copy file to dst
TdDirPtr pDir = taosOpenDir(src);
if (pDir == NULL) {
code = TAOS_SYSTEM_ERROR(errno);
code = terrno;
goto _ERROR;
}
@ -1428,7 +1428,7 @@ int32_t chkpPreBuildDir(char* path, int64_t chkpId, char** chkpDir, char** chkpI
code = taosMulModeMkDir(pChkpDir, 0755, true);
if (code != 0) {
code = TAOS_SYSTEM_ERROR(errno);
code = terrno;
stError("failed to prepare checkpoint dir, path:%s, reason:%s", path, tstrerror(code));
goto _EXIT;
}
@ -4633,7 +4633,7 @@ int32_t dbChkpGetDelta(SDbChkp* p, int64_t chkpId, SArray* list) {
TdDirPtr pDir = taosOpenDir(p->buf);
if (pDir == NULL) {
(void)taosThreadRwlockUnlock(&p->rwLock);
return TAOS_SYSTEM_ERROR(errno);
return terrno;
}
TdDirEntryPtr de = NULL;

View File

@ -1224,7 +1224,7 @@ static int32_t uploadCheckpointToS3(const char* id, const char* path) {
TdDirPtr pDir = taosOpenDir(path);
if (pDir == NULL) {
return TAOS_SYSTEM_ERROR(errno);
return terrno;
}
TdDirEntryPtr de = NULL;

View File

@ -271,7 +271,7 @@ int32_t snapFileReadMeta(SBackendSnapFile2* pSnapFile) {
int32_t code = 0;
TdDirPtr pDir = taosOpenDir(pSnapFile->path);
if (NULL == pDir) {
code = TAOS_SYSTEM_ERROR(errno);
code = terrno;
stError("%s failed to open %s, reason:%s", STREAM_STATE_TRANSFER, pSnapFile->path, tstrerror(code));
return code;
}

View File

@ -1136,7 +1136,7 @@ int tdbPagerRestoreJournals(SPager *pPager) {
tdbDirPtr pDir = taosOpenDir(pPager->pEnv->dbName);
if (pDir == NULL) {
tdbError("failed to open %s since %s", pPager->pEnv->dbName, strerror(errno));
return TAOS_SYSTEM_ERROR(errno);
return terrno;
}
SArray *pTxnList = taosArrayInit(16, sizeof(int64_t));
@ -1182,7 +1182,7 @@ int tdbPagerRollback(SPager *pPager) {
tdbDirPtr pDir = taosOpenDir(pPager->pEnv->dbName);
if (pDir == NULL) {
tdbError("failed to open %s since %s", pPager->pEnv->dbName, strerror(errno));
return terrno = TAOS_SYSTEM_ERROR(errno);
return terrno;
}
while ((pDirEntry = tdbReadDir(pDir)) != NULL) {

View File

@ -403,7 +403,7 @@ int32_t walCheckAndRepairMeta(SWal* pWal) {
regfree(&logRegPattern);
regfree(&idxRegPattern);
wError("vgId:%d, path:%s, failed to open since %s", pWal->cfg.vgId, pWal->path, strerror(errno));
TAOS_RETURN(TSDB_CODE_FAILED);
return terrno;
}
SArray* actualLog = taosArrayInit(8, sizeof(SWalFileInfo));
@ -422,7 +422,7 @@ int32_t walCheckAndRepairMeta(SWal* pWal) {
regfree(&idxRegPattern);
(void)taosCloseDir(&pDir);
TAOS_RETURN(TSDB_CODE_OUT_OF_MEMORY);
return terrno;
}
}
}

View File

@ -145,7 +145,10 @@ int32_t taosMulMkDir(const char *dirname) {
char *pos = temp;
int32_t code = 0;
#ifdef WINDOWS
taosRealPath(dirname, temp, sizeof(temp));
code = taosRealPath(dirname, temp, sizeof(temp));
if(code != 0) {
return code;
}
if (temp[1] == ':') pos += 3;
#else
(void)strcpy(temp, dirname);
@ -207,7 +210,10 @@ int32_t taosMulModeMkDir(const char *dirname, int mode, bool checkAccess) {
char *pos = temp;
int32_t code = 0;
#ifdef WINDOWS
taosRealPath(dirname, temp, sizeof(temp));
code = taosRealPath(dirname, temp, sizeof(temp));
if(code != 0) {
return code;
}
if (temp[1] == ':') pos += 3;
#else
(void)strcpy(temp, dirname);
@ -430,6 +436,9 @@ TdDirPtr taosOpenDir(const char *dirname) {
HANDLE hFind;
TdDirPtr pDir = taosMemoryMalloc(sizeof(TdDir));
if(pDir == NULL) {
return NULL;
}
strcpy(szFind, dirname);
strcat(szFind, "\\*.*"); //利用通配符找这个目录下的所以文件,包括目录
@ -437,6 +446,8 @@ TdDirPtr taosOpenDir(const char *dirname) {
pDir->hFind = FindFirstFile(szFind, &(pDir->dirEntry.findFileData));
if (INVALID_HANDLE_VALUE == pDir->hFind) {
taosMemoryFree(pDir);
DWORD errorCode = GetLastError();
terrno = TAOS_SYSTEM_ERROR(errorCode);
return NULL;
}
return pDir;
@ -444,6 +455,11 @@ TdDirPtr taosOpenDir(const char *dirname) {
DIR *pDir = opendir(dirname);
if (pDir == NULL) return NULL;
TdDirPtr dirPtr = (TdDirPtr)taosMemoryMalloc(sizeof(TdDir));
if (dirPtr == NULL) {
(void)closedir(pDir);
terrno = TAOS_SYSTEM_ERROR(errno);
return NULL;
}
dirPtr->dirEntryPtr = (TdDirEntryPtr) & (dirPtr->dirEntry1);
dirPtr->pDir = pDir;
return dirPtr;
@ -506,22 +522,30 @@ char *taosGetDirEntryName(TdDirEntryPtr pDirEntry) {
}
int32_t taosCloseDir(TdDirPtr *ppDir) {
int32_t code = 0;
if (ppDir == NULL || *ppDir == NULL) {
terrno = TSDB_CODE_INVALID_PARA;
return terrno;
}
#ifdef WINDOWS
FindClose((*ppDir)->hFind);
if(!FindClose((*ppDir)->hFind)) {
terrno = TAOS_SYSTEM_ERROR(GetLastError());
return terrno;
}
taosMemoryFree(*ppDir);
*ppDir = NULL;
return 0;
#elif defined(DARWIN)
closedir((*ppDir)->pDir);
code = closedir((*ppDir)->pDir);
if (-1 == code) {
terrno = TAOS_SYSTEM_ERROR(errno);
return terrno;
}
taosMemoryFree(*ppDir);
*ppDir = NULL;
return 0;
#else
int32_t code = closedir((DIR *)*ppDir);
code = closedir((DIR *)*ppDir);
*ppDir = NULL;
if (-1 == code) {
terrno = TAOS_SYSTEM_ERROR(errno);

View File

@ -1227,8 +1227,8 @@ static void checkRegexCache(void* param, void* tmrId) {
if(sRegexCache.exit) {
goto _exit;
}
bool ret = taosTmrReset(checkRegexCache, REGEX_CACHE_CLEAR_TIME * 1000, param, sRegexCache.regexCacheTmr, &tmrId);
if (!ret) {
bool stopped = taosTmrReset(checkRegexCache, REGEX_CACHE_CLEAR_TIME * 1000, param, sRegexCache.regexCacheTmr, &tmrId);
if (stopped) {
uError("failed to reset regex cache timer");
goto _exit;
}