void unused return value

This commit is contained in:
Minglei Jin 2024-07-25 15:54:46 +08:00
parent 10531c0b19
commit e0e467086c
8 changed files with 182 additions and 182 deletions

View File

@ -116,7 +116,7 @@ typedef SOCKET EpollFd;
#endif #endif
typedef int32_t SocketFd; typedef int32_t SocketFd;
typedef SocketFd EpollFd; // typedef SocketFd EpollFd;
typedef struct TdSocketServer *TdSocketServerPtr; typedef struct TdSocketServer *TdSocketServerPtr;
typedef struct TdSocket *TdSocketPtr; typedef struct TdSocket *TdSocketPtr;

View File

@ -114,11 +114,11 @@ static inline SWalFileInfo* walGetCurFileInfo(SWal* pWal) {
} }
static inline void walBuildLogName(SWal* pWal, int64_t fileFirstVer, char* buf) { static inline void walBuildLogName(SWal* pWal, int64_t fileFirstVer, char* buf) {
sprintf(buf, "%s/%020" PRId64 "." WAL_LOG_SUFFIX, pWal->path, fileFirstVer); TAOS_UNUSED(sprintf(buf, "%s/%020" PRId64 "." WAL_LOG_SUFFIX, pWal->path, fileFirstVer));
} }
static inline void walBuildIdxName(SWal* pWal, int64_t fileFirstVer, char* buf) { static inline void walBuildIdxName(SWal* pWal, int64_t fileFirstVer, char* buf) {
sprintf(buf, "%s/%020" PRId64 "." WAL_INDEX_SUFFIX, pWal->path, fileFirstVer); TAOS_UNUSED(sprintf(buf, "%s/%020" PRId64 "." WAL_INDEX_SUFFIX, pWal->path, fileFirstVer));
} }
static inline int walValidHeadCksum(SWalCkHead* pHead) { static inline int walValidHeadCksum(SWalCkHead* pHead) {

View File

@ -57,7 +57,7 @@ static FORCE_INLINE int32_t walScanLogGetLastVer(SWal* pWal, int32_t fileIdx, in
walBuildLogName(pWal, pFileInfo->firstVer, fnameStr); walBuildLogName(pWal, pFileInfo->firstVer, fnameStr);
int64_t fileSize = 0; int64_t fileSize = 0;
taosStatFile(fnameStr, &fileSize, NULL, NULL); (void)taosStatFile(fnameStr, &fileSize, NULL, NULL);
TdFilePtr pFile = taosOpenFile(fnameStr, TD_FILE_READ | TD_FILE_WRITE); TdFilePtr pFile = taosOpenFile(fnameStr, TD_FILE_READ | TD_FILE_WRITE);
if (pFile == NULL) { if (pFile == NULL) {
@ -362,7 +362,7 @@ static int32_t walTrimIdxFile(SWal* pWal, int32_t fileIdx) {
walBuildIdxName(pWal, pFileInfo->firstVer, fnameStr); walBuildIdxName(pWal, pFileInfo->firstVer, fnameStr);
int64_t fileSize = 0; int64_t fileSize = 0;
taosStatFile(fnameStr, &fileSize, NULL, NULL); (void)taosStatFile(fnameStr, &fileSize, NULL, NULL);
int64_t records = TMAX(0, pFileInfo->lastVer - pFileInfo->firstVer + 1); int64_t records = TMAX(0, pFileInfo->lastVer - pFileInfo->firstVer + 1);
int64_t lastEndOffset = records * sizeof(SWalIdxEntry); int64_t lastEndOffset = records * sizeof(SWalIdxEntry);
@ -378,8 +378,8 @@ static int32_t walTrimIdxFile(SWal* pWal, int32_t fileIdx) {
wInfo("vgId:%d, trim idx file. file: %s, size: %" PRId64 ", offset: %" PRId64, pWal->cfg.vgId, fnameStr, fileSize, wInfo("vgId:%d, trim idx file. file: %s, size: %" PRId64 ", offset: %" PRId64, pWal->cfg.vgId, fnameStr, fileSize,
lastEndOffset); lastEndOffset);
taosFtruncateFile(pFile, lastEndOffset); (void)taosFtruncateFile(pFile, lastEndOffset);
taosCloseFile(&pFile); (void)taosCloseFile(&pFile);
TAOS_RETURN(TSDB_CODE_SUCCESS); TAOS_RETURN(TSDB_CODE_SUCCESS);
} }
@ -392,8 +392,8 @@ int32_t walCheckAndRepairMeta(SWal* pWal) {
regex_t logRegPattern; regex_t logRegPattern;
regex_t idxRegPattern; regex_t idxRegPattern;
regcomp(&logRegPattern, logPattern, REG_EXTENDED); (void)regcomp(&logRegPattern, logPattern, REG_EXTENDED);
regcomp(&idxRegPattern, idxPattern, REG_EXTENDED); (void)regcomp(&idxRegPattern, idxPattern, REG_EXTENDED);
TdDirPtr pDir = taosOpenDir(pWal->path); TdDirPtr pDir = taosOpenDir(pWal->path);
if (pDir == NULL) { if (pDir == NULL) {
@ -412,13 +412,13 @@ int32_t walCheckAndRepairMeta(SWal* pWal) {
int code = regexec(&logRegPattern, name, 0, NULL, 0); int code = regexec(&logRegPattern, name, 0, NULL, 0);
if (code == 0) { if (code == 0) {
SWalFileInfo fileInfo; SWalFileInfo fileInfo;
memset(&fileInfo, -1, sizeof(SWalFileInfo)); (void)memset(&fileInfo, -1, sizeof(SWalFileInfo));
sscanf(name, "%" PRId64 ".log", &fileInfo.firstVer); (void)sscanf(name, "%" PRId64 ".log", &fileInfo.firstVer);
taosArrayPush(actualLog, &fileInfo); (void)taosArrayPush(actualLog, &fileInfo);
} }
} }
taosCloseDir(&pDir); (void)taosCloseDir(&pDir);
regfree(&logRegPattern); regfree(&logRegPattern);
regfree(&idxRegPattern); regfree(&idxRegPattern);
@ -549,7 +549,7 @@ static int32_t walCheckAndRepairIdxFile(SWal* pWal, int32_t fileIdx) {
TdFilePtr pIdxFile = NULL; TdFilePtr pIdxFile = NULL;
SWalIdxEntry idxEntry = {.ver = pFileInfo->firstVer - 1, .offset = -sizeof(SWalCkHead)}; SWalIdxEntry idxEntry = {.ver = pFileInfo->firstVer - 1, .offset = -sizeof(SWalCkHead)};
SWalCkHead ckHead; SWalCkHead ckHead;
memset(&ckHead, 0, sizeof(ckHead)); (void)memset(&ckHead, 0, sizeof(ckHead));
ckHead.head.version = idxEntry.ver; ckHead.head.version = idxEntry.ver;
pIdxFile = taosOpenFile(fnameStr, TD_FILE_READ | TD_FILE_WRITE | TD_FILE_CREATE); pIdxFile = taosOpenFile(fnameStr, TD_FILE_READ | TD_FILE_WRITE | TD_FILE_CREATE);
@ -675,7 +675,7 @@ _err:
int64_t walGetVerRetention(SWal* pWal, int64_t bytes) { int64_t walGetVerRetention(SWal* pWal, int64_t bytes) {
int64_t ver = -1; int64_t ver = -1;
int64_t totSize = 0; int64_t totSize = 0;
taosThreadMutexLock(&pWal->mutex); (void)taosThreadMutexLock(&pWal->mutex);
int32_t fileIdx = taosArrayGetSize(pWal->fileInfoSet); int32_t fileIdx = taosArrayGetSize(pWal->fileInfoSet);
while (--fileIdx) { while (--fileIdx) {
SWalFileInfo* pInfo = taosArrayGet(pWal->fileInfoSet, fileIdx); SWalFileInfo* pInfo = taosArrayGet(pWal->fileInfoSet, fileIdx);
@ -685,7 +685,7 @@ int64_t walGetVerRetention(SWal* pWal, int64_t bytes) {
} }
totSize += pInfo->fileSize; totSize += pInfo->fileSize;
} }
taosThreadMutexUnlock(&pWal->mutex); (void)taosThreadMutexUnlock(&pWal->mutex);
return ver + 1; return ver + 1;
} }
@ -727,7 +727,7 @@ int32_t walRollFileInfo(SWal* pWal) {
pNewInfo->closeTs = -1; pNewInfo->closeTs = -1;
pNewInfo->fileSize = 0; pNewInfo->fileSize = 0;
pNewInfo->syncedOffset = 0; pNewInfo->syncedOffset = 0;
taosArrayPush(pArray, pNewInfo); (void)taosArrayPush(pArray, pNewInfo);
taosMemoryFree(pNewInfo); taosMemoryFree(pNewInfo);
TAOS_RETURN(TSDB_CODE_SUCCESS); TAOS_RETURN(TSDB_CODE_SUCCESS);
@ -753,21 +753,21 @@ int32_t walMetaSerialize(SWal* pWal, char** serialized) {
TAOS_RETURN(TSDB_CODE_OUT_OF_MEMORY); TAOS_RETURN(TSDB_CODE_OUT_OF_MEMORY);
} }
cJSON_AddItemToObject(pRoot, "meta", pMeta); (void)cJSON_AddItemToObject(pRoot, "meta", pMeta);
sprintf(buf, "%" PRId64, pWal->vers.firstVer); (void)sprintf(buf, "%" PRId64, pWal->vers.firstVer);
cJSON_AddStringToObject(pMeta, "firstVer", buf); (void)cJSON_AddStringToObject(pMeta, "firstVer", buf);
sprintf(buf, "%" PRId64, pWal->vers.snapshotVer); (void)sprintf(buf, "%" PRId64, pWal->vers.snapshotVer);
cJSON_AddStringToObject(pMeta, "snapshotVer", buf); (void)cJSON_AddStringToObject(pMeta, "snapshotVer", buf);
sprintf(buf, "%" PRId64, pWal->vers.commitVer); (void)sprintf(buf, "%" PRId64, pWal->vers.commitVer);
cJSON_AddStringToObject(pMeta, "commitVer", buf); (void)cJSON_AddStringToObject(pMeta, "commitVer", buf);
sprintf(buf, "%" PRId64, pWal->vers.lastVer); (void)sprintf(buf, "%" PRId64, pWal->vers.lastVer);
cJSON_AddStringToObject(pMeta, "lastVer", buf); (void)cJSON_AddStringToObject(pMeta, "lastVer", buf);
cJSON_AddItemToObject(pRoot, "files", pFiles); (void)cJSON_AddItemToObject(pRoot, "files", pFiles);
SWalFileInfo* pData = pWal->fileInfoSet->pData; SWalFileInfo* pData = pWal->fileInfoSet->pData;
for (int i = 0; i < sz; i++) { for (int i = 0; i < sz; i++) {
SWalFileInfo* pInfo = &pData[i]; SWalFileInfo* pInfo = &pData[i];
cJSON_AddItemToArray(pFiles, pField = cJSON_CreateObject()); (void)cJSON_AddItemToArray(pFiles, pField = cJSON_CreateObject());
if (pField == NULL) { if (pField == NULL) {
cJSON_Delete(pRoot); cJSON_Delete(pRoot);
@ -775,16 +775,16 @@ int32_t walMetaSerialize(SWal* pWal, char** serialized) {
} }
// cjson only support int32_t or double // cjson only support int32_t or double
// string are used to prohibit the loss of precision // string are used to prohibit the loss of precision
sprintf(buf, "%" PRId64, pInfo->firstVer); (void)sprintf(buf, "%" PRId64, pInfo->firstVer);
cJSON_AddStringToObject(pField, "firstVer", buf); (void)cJSON_AddStringToObject(pField, "firstVer", buf);
sprintf(buf, "%" PRId64, pInfo->lastVer); (void)sprintf(buf, "%" PRId64, pInfo->lastVer);
cJSON_AddStringToObject(pField, "lastVer", buf); (void)cJSON_AddStringToObject(pField, "lastVer", buf);
sprintf(buf, "%" PRId64, pInfo->createTs); (void)sprintf(buf, "%" PRId64, pInfo->createTs);
cJSON_AddStringToObject(pField, "createTs", buf); (void)cJSON_AddStringToObject(pField, "createTs", buf);
sprintf(buf, "%" PRId64, pInfo->closeTs); (void)sprintf(buf, "%" PRId64, pInfo->closeTs);
cJSON_AddStringToObject(pField, "closeTs", buf); (void)cJSON_AddStringToObject(pField, "closeTs", buf);
sprintf(buf, "%" PRId64, pInfo->fileSize); (void)sprintf(buf, "%" PRId64, pInfo->fileSize);
cJSON_AddStringToObject(pField, "fileSize", buf); (void)cJSON_AddStringToObject(pField, "fileSize", buf);
} }
char* pSerialized = cJSON_Print(pRoot); char* pSerialized = cJSON_Print(pRoot);
cJSON_Delete(pRoot); cJSON_Delete(pRoot);
@ -818,7 +818,7 @@ int32_t walMetaDeserialize(SWal* pWal, const char* bytes) {
int sz = cJSON_GetArraySize(pFiles); int sz = cJSON_GetArraySize(pFiles);
// deserialize // deserialize
SArray* pArray = pWal->fileInfoSet; SArray* pArray = pWal->fileInfoSet;
taosArrayEnsureCap(pArray, sz); (void)taosArrayEnsureCap(pArray, sz);
for (int i = 0; i < sz; i++) { for (int i = 0; i < sz; i++) {
pInfoJson = cJSON_GetArrayItem(pFiles, i); pInfoJson = cJSON_GetArrayItem(pFiles, i);
@ -841,7 +841,7 @@ int32_t walMetaDeserialize(SWal* pWal, const char* bytes) {
pField = cJSON_GetObjectItem(pInfoJson, "fileSize"); pField = cJSON_GetObjectItem(pInfoJson, "fileSize");
if (!pField) goto _err; if (!pField) goto _err;
info.fileSize = atoll(cJSON_GetStringValue(pField)); info.fileSize = atoll(cJSON_GetStringValue(pField));
taosArrayPush(pArray, &info); (void)taosArrayPush(pArray, &info);
} }
pWal->fileInfoSet = pArray; pWal->fileInfoSet = pArray;
pWal->writeCur = sz - 1; pWal->writeCur = sz - 1;
@ -856,7 +856,7 @@ _err:
static int walFindCurMetaVer(SWal* pWal) { static int walFindCurMetaVer(SWal* pWal) {
const char* pattern = "^meta-ver[0-9]+$"; const char* pattern = "^meta-ver[0-9]+$";
regex_t walMetaRegexPattern; regex_t walMetaRegexPattern;
regcomp(&walMetaRegexPattern, pattern, REG_EXTENDED); (void)regcomp(&walMetaRegexPattern, pattern, REG_EXTENDED);
TdDirPtr pDir = taosOpenDir(pWal->path); TdDirPtr pDir = taosOpenDir(pWal->path);
if (pDir == NULL) { if (pDir == NULL) {
@ -872,13 +872,13 @@ static int walFindCurMetaVer(SWal* pWal) {
char* name = taosDirEntryBaseName(taosGetDirEntryName(pDirEntry)); char* name = taosDirEntryBaseName(taosGetDirEntryName(pDirEntry));
int code = regexec(&walMetaRegexPattern, name, 0, NULL, 0); int code = regexec(&walMetaRegexPattern, name, 0, NULL, 0);
if (code == 0) { if (code == 0) {
sscanf(name, "meta-ver%d", &metaVer); (void)sscanf(name, "meta-ver%d", &metaVer);
wDebug("vgId:%d, wal find current meta: %s is the meta file, ver %d", pWal->cfg.vgId, name, metaVer); wDebug("vgId:%d, wal find current meta: %s is the meta file, ver %d", pWal->cfg.vgId, name, metaVer);
break; break;
} }
wDebug("vgId:%d, wal find current meta: %s is not meta file", pWal->cfg.vgId, name); wDebug("vgId:%d, wal find current meta: %s is not meta file", pWal->cfg.vgId, name);
} }
taosCloseDir(&pDir); (void)taosCloseDir(&pDir);
regfree(&walMetaRegexPattern); regfree(&walMetaRegexPattern);
return metaVer; return metaVer;
} }
@ -961,8 +961,8 @@ int32_t walSaveMeta(SWal* pWal) {
// delete old file // delete old file
if (metaVer > -1) { if (metaVer > -1) {
walBuildMetaName(pWal, metaVer, fnameStr); (void)walBuildMetaName(pWal, metaVer, fnameStr);
taosRemoveFile(fnameStr); (void)taosRemoveFile(fnameStr);
} }
taosMemoryFree(serialized); taosMemoryFree(serialized);
@ -984,10 +984,10 @@ int32_t walLoadMeta(SWal* pWal) {
TAOS_RETURN(TSDB_CODE_FAILED); TAOS_RETURN(TSDB_CODE_FAILED);
} }
char fnameStr[WAL_FILE_LEN]; char fnameStr[WAL_FILE_LEN];
walBuildMetaName(pWal, metaVer, fnameStr); (void)walBuildMetaName(pWal, metaVer, fnameStr);
// read metafile // read metafile
int64_t fileSize = 0; int64_t fileSize = 0;
taosStatFile(fnameStr, &fileSize, NULL, NULL); (void)taosStatFile(fnameStr, &fileSize, NULL, NULL);
if (fileSize == 0) { if (fileSize == 0) {
(void)taosRemoveFile(fnameStr); (void)taosRemoveFile(fnameStr);
wDebug("vgId:%d, wal find empty meta ver %d", pWal->cfg.vgId, metaVer); wDebug("vgId:%d, wal find empty meta ver %d", pWal->cfg.vgId, metaVer);
@ -999,7 +999,7 @@ int32_t walLoadMeta(SWal* pWal) {
if (buf == NULL) { if (buf == NULL) {
TAOS_RETURN(TSDB_CODE_OUT_OF_MEMORY); TAOS_RETURN(TSDB_CODE_OUT_OF_MEMORY);
} }
memset(buf, 0, size + 5); (void)memset(buf, 0, size + 5);
TdFilePtr pFile = taosOpenFile(fnameStr, TD_FILE_READ); TdFilePtr pFile = taosOpenFile(fnameStr, TD_FILE_READ);
if (pFile == NULL) { if (pFile == NULL) {
taosMemoryFree(buf); taosMemoryFree(buf);
@ -1007,7 +1007,7 @@ int32_t walLoadMeta(SWal* pWal) {
TAOS_RETURN(TSDB_CODE_WAL_FILE_CORRUPTED); TAOS_RETURN(TSDB_CODE_WAL_FILE_CORRUPTED);
} }
if (taosReadFile(pFile, buf, size) != size) { if (taosReadFile(pFile, buf, size) != size) {
taosCloseFile(&pFile); (void)taosCloseFile(&pFile);
taosMemoryFree(buf); taosMemoryFree(buf);
TAOS_RETURN(TAOS_SYSTEM_ERROR(errno)); TAOS_RETURN(TAOS_SYSTEM_ERROR(errno));
@ -1018,7 +1018,7 @@ int32_t walLoadMeta(SWal* pWal) {
wError("failed to deserialize wal meta. file:%s", fnameStr); wError("failed to deserialize wal meta. file:%s", fnameStr);
code = TSDB_CODE_WAL_FILE_CORRUPTED; code = TSDB_CODE_WAL_FILE_CORRUPTED;
} }
taosCloseFile(&pFile); (void)taosCloseFile(&pFile);
taosMemoryFree(buf); taosMemoryFree(buf);
TAOS_RETURN(code); TAOS_RETURN(code);
@ -1028,6 +1028,6 @@ int32_t walRemoveMeta(SWal* pWal) {
int metaVer = walFindCurMetaVer(pWal); int metaVer = walFindCurMetaVer(pWal);
if (metaVer == -1) return 0; if (metaVer == -1) return 0;
char fnameStr[WAL_FILE_LEN]; char fnameStr[WAL_FILE_LEN];
walBuildMetaName(pWal, metaVer, fnameStr); (void)walBuildMetaName(pWal, metaVer, fnameStr);
return taosRemoveFile(fnameStr); return taosRemoveFile(fnameStr);
} }

View File

@ -33,7 +33,7 @@ static int32_t walCreateThread();
static void walStopThread(); static void walStopThread();
static void walFreeObj(void *pWal); static void walFreeObj(void *pWal);
int64_t walGetSeq() { return (int64_t)atomic_load_32(&tsWal.seq); } int64_t walGetSeq() { return (int64_t)atomic_load_32((volatile int32_t *)&tsWal.seq); }
int32_t walInit() { int32_t walInit() {
int8_t old; int8_t old;
@ -69,7 +69,7 @@ void walCleanUp() {
if (old == 1) { if (old == 1) {
walStopThread(); walStopThread();
taosCloseRef(tsWal.refSetId); TAOS_UNUSED(taosCloseRef(tsWal.refSetId));
wInfo("wal module is cleaned up"); wInfo("wal module is cleaned up");
atomic_store_8(&tsWal.inited, 0); atomic_store_8(&tsWal.inited, 0);
} }
@ -89,7 +89,7 @@ SWal *walOpen(const char *path, SWalCfg *pCfg) {
} }
// set config // set config
memcpy(&pWal->cfg, pCfg, sizeof(SWalCfg)); TAOS_UNUSED(memcpy(&pWal->cfg, pCfg, sizeof(SWalCfg)));
pWal->fsyncSeq = pCfg->fsyncPeriod / 1000; pWal->fsyncSeq = pCfg->fsyncPeriod / 1000;
if (pWal->cfg.retentionSize > 0) { if (pWal->cfg.retentionSize > 0) {
@ -140,7 +140,7 @@ SWal *walOpen(const char *path, SWalCfg *pCfg) {
pWal->lastRollSeq = -1; pWal->lastRollSeq = -1;
// init write buffer // init write buffer
memset(&pWal->writeHead, 0, sizeof(SWalCkHead)); TAOS_UNUSED(memset(&pWal->writeHead, 0, sizeof(SWalCkHead)));
pWal->writeHead.head.protoVer = WAL_PROTO_VER; pWal->writeHead.head.protoVer = WAL_PROTO_VER;
pWal->writeHead.magic = WAL_MAGIC; pWal->writeHead.magic = WAL_MAGIC;
@ -171,7 +171,7 @@ SWal *walOpen(const char *path, SWalCfg *pCfg) {
_err: _err:
taosArrayDestroy(pWal->fileInfoSet); taosArrayDestroy(pWal->fileInfoSet);
taosHashCleanup(pWal->pRefHash); taosHashCleanup(pWal->pRefHash);
taosThreadMutexDestroy(&pWal->mutex); TAOS_UNUSED(taosThreadMutexDestroy(&pWal->mutex));
taosMemoryFreeClear(pWal); taosMemoryFreeClear(pWal);
return NULL; return NULL;
@ -207,19 +207,19 @@ int32_t walAlter(SWal *pWal, SWalCfg *pCfg) {
int32_t walPersist(SWal *pWal) { int32_t walPersist(SWal *pWal) {
int32_t code = 0; int32_t code = 0;
taosThreadMutexLock(&pWal->mutex); TAOS_UNUSED(taosThreadMutexLock(&pWal->mutex));
code = walSaveMeta(pWal); code = walSaveMeta(pWal);
taosThreadMutexUnlock(&pWal->mutex); TAOS_UNUSED(taosThreadMutexUnlock(&pWal->mutex));
TAOS_RETURN(code); TAOS_RETURN(code);
} }
void walClose(SWal *pWal) { void walClose(SWal *pWal) {
taosThreadMutexLock(&pWal->mutex); TAOS_UNUSED(taosThreadMutexLock(&pWal->mutex));
(void)walSaveMeta(pWal); (void)walSaveMeta(pWal);
taosCloseFile(&pWal->pLogFile); TAOS_UNUSED(taosCloseFile(&pWal->pLogFile));
pWal->pLogFile = NULL; pWal->pLogFile = NULL;
taosCloseFile(&pWal->pIdxFile); (void)taosCloseFile(&pWal->pIdxFile);
pWal->pIdxFile = NULL; pWal->pIdxFile = NULL;
taosArrayDestroy(pWal->fileInfoSet); taosArrayDestroy(pWal->fileInfoSet);
pWal->fileInfoSet = NULL; pWal->fileInfoSet = NULL;
@ -235,22 +235,22 @@ void walClose(SWal *pWal) {
} }
taosHashCleanup(pWal->pRefHash); taosHashCleanup(pWal->pRefHash);
pWal->pRefHash = NULL; pWal->pRefHash = NULL;
taosThreadMutexUnlock(&pWal->mutex); (void)taosThreadMutexUnlock(&pWal->mutex);
if (pWal->cfg.level == TAOS_WAL_SKIP) { if (pWal->cfg.level == TAOS_WAL_SKIP) {
wInfo("vgId:%d, remove all wals, path:%s", pWal->cfg.vgId, pWal->path); wInfo("vgId:%d, remove all wals, path:%s", pWal->cfg.vgId, pWal->path);
taosRemoveDir(pWal->path); taosRemoveDir(pWal->path);
taosMkDir(pWal->path); (void)taosMkDir(pWal->path);
} }
taosRemoveRef(tsWal.refSetId, pWal->refId); (void)taosRemoveRef(tsWal.refSetId, pWal->refId);
} }
static void walFreeObj(void *wal) { static void walFreeObj(void *wal) {
SWal *pWal = wal; SWal *pWal = wal;
wDebug("vgId:%d, wal:%p is freed", pWal->cfg.vgId, pWal); wDebug("vgId:%d, wal:%p is freed", pWal->cfg.vgId, pWal);
taosThreadMutexDestroy(&pWal->mutex); (void)taosThreadMutexDestroy(&pWal->mutex);
taosMemoryFreeClear(pWal); taosMemoryFreeClear(pWal);
} }
@ -259,7 +259,7 @@ static bool walNeedFsync(SWal *pWal) {
return false; return false;
} }
if (atomic_load_32(&tsWal.seq) % pWal->fsyncSeq == 0) { if (atomic_load_32((volatile int32_t *)&tsWal.seq) % pWal->fsyncSeq == 0) {
return true; return true;
} }
@ -268,7 +268,7 @@ static bool walNeedFsync(SWal *pWal) {
static void walUpdateSeq() { static void walUpdateSeq() {
taosMsleep(WAL_REFRESH_MS); taosMsleep(WAL_REFRESH_MS);
atomic_add_fetch_32(&tsWal.seq, 1); (void)atomic_add_fetch_32((volatile int32_t *)&tsWal.seq, 1);
} }
static void walFsyncAll() { static void walFsyncAll() {
@ -276,7 +276,7 @@ static void walFsyncAll() {
while (pWal) { while (pWal) {
if (walNeedFsync(pWal)) { if (walNeedFsync(pWal)) {
wTrace("vgId:%d, do fsync, level:%d seq:%d rseq:%d", pWal->cfg.vgId, pWal->cfg.level, pWal->fsyncSeq, wTrace("vgId:%d, do fsync, level:%d seq:%d rseq:%d", pWal->cfg.vgId, pWal->cfg.level, pWal->fsyncSeq,
atomic_load_32(&tsWal.seq)); atomic_load_32((volatile int32_t *)&tsWal.seq));
int32_t code = taosFsyncFile(pWal->pLogFile); int32_t code = taosFsyncFile(pWal->pLogFile);
if (code != 0) { if (code != 0) {
wError("vgId:%d, file:%" PRId64 ".log, failed to fsync since %s", pWal->cfg.vgId, walGetLastFileFirstVer(pWal), wError("vgId:%d, file:%" PRId64 ".log, failed to fsync since %s", pWal->cfg.vgId, walGetLastFileFirstVer(pWal),
@ -301,8 +301,8 @@ static void *walThreadFunc(void *param) {
static int32_t walCreateThread() { static int32_t walCreateThread() {
TdThreadAttr thAttr; TdThreadAttr thAttr;
taosThreadAttrInit(&thAttr); (void)taosThreadAttrInit(&thAttr);
taosThreadAttrSetDetachState(&thAttr, PTHREAD_CREATE_JOINABLE); (void)taosThreadAttrSetDetachState(&thAttr, PTHREAD_CREATE_JOINABLE);
if (taosThreadCreate(&tsWal.thread, &thAttr, walThreadFunc, NULL) != 0) { if (taosThreadCreate(&tsWal.thread, &thAttr, walThreadFunc, NULL) != 0) {
wError("failed to create wal thread since %s", strerror(errno)); wError("failed to create wal thread since %s", strerror(errno));
@ -310,7 +310,7 @@ static int32_t walCreateThread() {
TAOS_RETURN(TAOS_SYSTEM_ERROR(errno)); TAOS_RETURN(TAOS_SYSTEM_ERROR(errno));
} }
taosThreadAttrDestroy(&thAttr); (void)taosThreadAttrDestroy(&thAttr);
wDebug("wal thread is launched, thread:0x%08" PRIx64, taosGetPthreadId(tsWal.thread)); wDebug("wal thread is launched, thread:0x%08" PRIx64, taosGetPthreadId(tsWal.thread));
TAOS_RETURN(TSDB_CODE_SUCCESS); TAOS_RETURN(TSDB_CODE_SUCCESS);
@ -320,7 +320,7 @@ static void walStopThread() {
atomic_store_8(&tsWal.stop, 1); atomic_store_8(&tsWal.stop, 1);
if (taosCheckPthreadValid(tsWal.thread)) { if (taosCheckPthreadValid(tsWal.thread)) {
taosThreadJoin(tsWal.thread, NULL); (void)taosThreadJoin(tsWal.thread, NULL);
taosThreadClear(&tsWal.thread); taosThreadClear(&tsWal.thread);
} }

View File

@ -41,7 +41,7 @@ SWalReader *walOpenReader(SWal *pWal, SWalFilterCond *cond, int64_t id) {
pReader->cond.enableRef = 0; pReader->cond.enableRef = 0;
} }
taosThreadMutexInit(&pReader->mutex, NULL); TAOS_UNUSED(taosThreadMutexInit(&pReader->mutex, NULL));
pReader->pHead = taosMemoryMalloc(sizeof(SWalCkHead)); pReader->pHead = taosMemoryMalloc(sizeof(SWalCkHead));
if (pReader->pHead == NULL) { if (pReader->pHead == NULL) {
@ -60,8 +60,8 @@ SWalReader *walOpenReader(SWal *pWal, SWalFilterCond *cond, int64_t id) {
void walCloseReader(SWalReader *pReader) { void walCloseReader(SWalReader *pReader) {
if (pReader == NULL) return; if (pReader == NULL) return;
taosCloseFile(&pReader->pIdxFile); TAOS_UNUSED(taosCloseFile(&pReader->pIdxFile));
taosCloseFile(&pReader->pLogFile); TAOS_UNUSED(taosCloseFile(&pReader->pLogFile));
taosMemoryFreeClear(pReader->pHead); taosMemoryFreeClear(pReader->pHead);
taosMemoryFree(pReader); taosMemoryFree(pReader);
} }
@ -115,9 +115,9 @@ void walReaderValidVersionRange(SWalReader *pReader, int64_t *sver, int64_t *eve
void walReaderVerifyOffset(SWalReader *pWalReader, STqOffsetVal *pOffset) { void walReaderVerifyOffset(SWalReader *pWalReader, STqOffsetVal *pOffset) {
// if offset version is small than first version , let's seek to first version // if offset version is small than first version , let's seek to first version
taosThreadMutexLock(&pWalReader->pWal->mutex); TAOS_UNUSED(taosThreadMutexLock(&pWalReader->pWal->mutex));
int64_t firstVer = walGetFirstVer((pWalReader)->pWal); int64_t firstVer = walGetFirstVer((pWalReader)->pWal);
taosThreadMutexUnlock(&pWalReader->pWal->mutex); TAOS_UNUSED(taosThreadMutexUnlock(&pWalReader->pWal->mutex));
if (pOffset->version < firstVer) { if (pOffset->version < firstVer) {
pOffset->version = firstVer; pOffset->version = firstVer;
@ -167,8 +167,8 @@ static int32_t walReadSeekFilePos(SWalReader *pReader, int64_t fileFirstVer, int
static int32_t walReadChangeFile(SWalReader *pReader, int64_t fileFirstVer) { static int32_t walReadChangeFile(SWalReader *pReader, int64_t fileFirstVer) {
char fnameStr[WAL_FILE_LEN] = {0}; char fnameStr[WAL_FILE_LEN] = {0};
taosCloseFile(&pReader->pIdxFile); TAOS_UNUSED(taosCloseFile(&pReader->pIdxFile));
taosCloseFile(&pReader->pLogFile); TAOS_UNUSED(taosCloseFile(&pReader->pLogFile));
walBuildLogName(pReader->pWal, fileFirstVer, fnameStr); walBuildLogName(pReader->pWal, fileFirstVer, fnameStr);
TdFilePtr pLogFile = taosOpenFile(fnameStr, TD_FILE_READ); TdFilePtr pLogFile = taosOpenFile(fnameStr, TD_FILE_READ);
@ -393,13 +393,13 @@ int32_t walReadVer(SWalReader *pReader, int64_t ver) {
TAOS_RETURN(TSDB_CODE_WAL_LOG_NOT_EXIST); TAOS_RETURN(TSDB_CODE_WAL_LOG_NOT_EXIST);
} }
taosThreadMutexLock(&pReader->mutex); TAOS_UNUSED(taosThreadMutexLock(&pReader->mutex));
if (pReader->curVersion != ver) { if (pReader->curVersion != ver) {
code = walReaderSeekVer(pReader, ver); code = walReaderSeekVer(pReader, ver);
if (code) { if (code) {
wError("vgId:%d, unexpected wal log, index:%" PRId64 ", since %s", pReader->pWal->cfg.vgId, ver, terrstr()); wError("vgId:%d, unexpected wal log, index:%" PRId64 ", since %s", pReader->pWal->cfg.vgId, ver, terrstr());
taosThreadMutexUnlock(&pReader->mutex); TAOS_UNUSED(taosThreadMutexUnlock(&pReader->mutex));
TAOS_RETURN(code); TAOS_RETURN(code);
} }
@ -414,7 +414,7 @@ int32_t walReadVer(SWalReader *pReader, int64_t ver) {
} else if (contLen == 0 && !seeked) { } else if (contLen == 0 && !seeked) {
code = walReadSeekVerImpl(pReader, ver); code = walReadSeekVerImpl(pReader, ver);
if (code) { if (code) {
taosThreadMutexUnlock(&pReader->mutex); TAOS_UNUSED(taosThreadMutexUnlock(&pReader->mutex));
TAOS_RETURN(code); TAOS_RETURN(code);
} }
@ -423,7 +423,7 @@ int32_t walReadVer(SWalReader *pReader, int64_t ver) {
} else { } else {
wError("vgId:%d, failed to read WAL record head, index:%" PRId64 ", from log file since %s", wError("vgId:%d, failed to read WAL record head, index:%" PRId64 ", from log file since %s",
pReader->pWal->cfg.vgId, ver, terrstr()); pReader->pWal->cfg.vgId, ver, terrstr());
taosThreadMutexUnlock(&pReader->mutex); TAOS_UNUSED(taosThreadMutexUnlock(&pReader->mutex));
if (contLen < 0) { if (contLen < 0) {
TAOS_RETURN(TAOS_SYSTEM_ERROR(errno)); TAOS_RETURN(TAOS_SYSTEM_ERROR(errno));
@ -437,7 +437,7 @@ int32_t walReadVer(SWalReader *pReader, int64_t ver) {
if (code != 0) { if (code != 0) {
wError("vgId:%d, unexpected wal log, index:%" PRId64 ", since head checksum not passed", pReader->pWal->cfg.vgId, wError("vgId:%d, unexpected wal log, index:%" PRId64 ", since head checksum not passed", pReader->pWal->cfg.vgId,
ver); ver);
taosThreadMutexUnlock(&pReader->mutex); TAOS_UNUSED(taosThreadMutexUnlock(&pReader->mutex));
TAOS_RETURN(TSDB_CODE_WAL_FILE_CORRUPTED); TAOS_RETURN(TSDB_CODE_WAL_FILE_CORRUPTED);
} }
@ -453,7 +453,7 @@ int32_t walReadVer(SWalReader *pReader, int64_t ver) {
if (pReader->capacity < cryptedBodyLen) { if (pReader->capacity < cryptedBodyLen) {
SWalCkHead *ptr = (SWalCkHead *)taosMemoryRealloc(pReader->pHead, sizeof(SWalCkHead) + cryptedBodyLen); SWalCkHead *ptr = (SWalCkHead *)taosMemoryRealloc(pReader->pHead, sizeof(SWalCkHead) + cryptedBodyLen);
if (ptr == NULL) { if (ptr == NULL) {
taosThreadMutexUnlock(&pReader->mutex); TAOS_UNUSED(taosThreadMutexUnlock(&pReader->mutex));
TAOS_RETURN(TSDB_CODE_OUT_OF_MEMORY); TAOS_RETURN(TSDB_CODE_OUT_OF_MEMORY);
} }
@ -464,7 +464,7 @@ int32_t walReadVer(SWalReader *pReader, int64_t ver) {
if ((contLen = taosReadFile(pReader->pLogFile, pReader->pHead->head.body, cryptedBodyLen)) != cryptedBodyLen) { if ((contLen = taosReadFile(pReader->pLogFile, pReader->pHead->head.body, cryptedBodyLen)) != cryptedBodyLen) {
wError("vgId:%d, failed to read WAL record body, index:%" PRId64 ", from log file since %s", wError("vgId:%d, failed to read WAL record body, index:%" PRId64 ", from log file since %s",
pReader->pWal->cfg.vgId, ver, terrstr()); pReader->pWal->cfg.vgId, ver, terrstr());
taosThreadMutexUnlock(&pReader->mutex); TAOS_UNUSED(taosThreadMutexUnlock(&pReader->mutex));
if (contLen < 0) { if (contLen < 0) {
TAOS_RETURN(TAOS_SYSTEM_ERROR(errno)); TAOS_RETURN(TAOS_SYSTEM_ERROR(errno));
@ -477,14 +477,14 @@ int32_t walReadVer(SWalReader *pReader, int64_t ver) {
wError("vgId:%d, unexpected wal log, index:%" PRId64 ", read request index:%" PRId64, pReader->pWal->cfg.vgId, wError("vgId:%d, unexpected wal log, index:%" PRId64 ", read request index:%" PRId64, pReader->pWal->cfg.vgId,
pReader->pHead->head.version, ver); pReader->pHead->head.version, ver);
// pReader->curInvalid = 1; // pReader->curInvalid = 1;
taosThreadMutexUnlock(&pReader->mutex); TAOS_UNUSED(taosThreadMutexUnlock(&pReader->mutex));
TAOS_RETURN(TSDB_CODE_WAL_FILE_CORRUPTED); TAOS_RETURN(TSDB_CODE_WAL_FILE_CORRUPTED);
} }
code = decryptBody(&pReader->pWal->cfg, pReader->pHead, plainBodyLen, __FUNCTION__); code = decryptBody(&pReader->pWal->cfg, pReader->pHead, plainBodyLen, __FUNCTION__);
if (code) { if (code) {
taosThreadMutexUnlock(&pReader->mutex); TAOS_UNUSED(taosThreadMutexUnlock(&pReader->mutex));
TAOS_RETURN(code); TAOS_RETURN(code);
} }
@ -498,13 +498,13 @@ int32_t walReadVer(SWalReader *pReader, int64_t ver) {
wError("checksum written into log:%u, checksum calculated:%u", logCkSum, readCkSum); wError("checksum written into log:%u, checksum calculated:%u", logCkSum, readCkSum);
// pReader->curInvalid = 1; // pReader->curInvalid = 1;
taosThreadMutexUnlock(&pReader->mutex); TAOS_UNUSED(taosThreadMutexUnlock(&pReader->mutex));
TAOS_RETURN(TSDB_CODE_WAL_FILE_CORRUPTED); TAOS_RETURN(TSDB_CODE_WAL_FILE_CORRUPTED);
} }
pReader->curVersion++; pReader->curVersion++;
taosThreadMutexUnlock(&pReader->mutex); TAOS_UNUSED(taosThreadMutexUnlock(&pReader->mutex));
TAOS_RETURN(TSDB_CODE_SUCCESS); TAOS_RETURN(TSDB_CODE_SUCCESS);
} }
@ -523,13 +523,13 @@ int32_t decryptBody(SWalCfg *cfg, SWalCkHead *pHead, int32_t plainBodyLen, const
opts.source = pHead->head.body; opts.source = pHead->head.body;
opts.result = newBody; opts.result = newBody;
opts.unitLen = 16; opts.unitLen = 16;
strncpy(opts.key, cfg->encryptKey, 16); TAOS_UNUSED(strncpy((char *)opts.key, cfg->encryptKey, 16));
int32_t count = CBC_Decrypt(&opts); int32_t count = CBC_Decrypt(&opts);
// wDebug("CBC_Decrypt cryptedBodyLen:%d, plainBodyLen:%d, %s", count, plainBodyLen, func); // wDebug("CBC_Decrypt cryptedBodyLen:%d, plainBodyLen:%d, %s", count, plainBodyLen, func);
memcpy(pHead->head.body, newBody, plainBodyLen); TAOS_UNUSED(memcpy(pHead->head.body, newBody, plainBodyLen));
taosMemoryFree(newBody); taosMemoryFree(newBody);
} }
@ -538,10 +538,10 @@ int32_t decryptBody(SWalCfg *cfg, SWalCkHead *pHead, int32_t plainBodyLen, const
} }
void walReadReset(SWalReader *pReader) { void walReadReset(SWalReader *pReader) {
taosThreadMutexLock(&pReader->mutex); TAOS_UNUSED(taosThreadMutexLock(&pReader->mutex));
taosCloseFile(&pReader->pIdxFile); TAOS_UNUSED(taosCloseFile(&pReader->pIdxFile));
taosCloseFile(&pReader->pLogFile); TAOS_UNUSED(taosCloseFile(&pReader->pLogFile));
pReader->curFileFirstVer = -1; pReader->curFileFirstVer = -1;
pReader->curVersion = -1; pReader->curVersion = -1;
taosThreadMutexUnlock(&pReader->mutex); TAOS_UNUSED(taosThreadMutexUnlock(&pReader->mutex));
} }

View File

@ -61,34 +61,34 @@ int32_t walSetRefVer(SWalRef *pRef, int64_t ver) {
SWal *pWal = pRef->pWal; SWal *pWal = pRef->pWal;
wDebug("vgId:%d, wal ref version %" PRId64 ", refId %" PRId64, pWal->cfg.vgId, ver, pRef->refId); wDebug("vgId:%d, wal ref version %" PRId64 ", refId %" PRId64, pWal->cfg.vgId, ver, pRef->refId);
if (pRef->refVer != ver) { if (pRef->refVer != ver) {
taosThreadMutexLock(&pWal->mutex); TAOS_UNUSED(taosThreadMutexLock(&pWal->mutex));
if (ver < pWal->vers.firstVer || ver > pWal->vers.lastVer) { if (ver < pWal->vers.firstVer || ver > pWal->vers.lastVer) {
taosThreadMutexUnlock(&pWal->mutex); TAOS_UNUSED(taosThreadMutexUnlock(&pWal->mutex));
TAOS_RETURN(TSDB_CODE_WAL_INVALID_VER); TAOS_RETURN(TSDB_CODE_WAL_INVALID_VER);
} }
pRef->refVer = ver; pRef->refVer = ver;
taosThreadMutexUnlock(&pWal->mutex); TAOS_UNUSED(taosThreadMutexUnlock(&pWal->mutex));
} }
TAOS_RETURN(TSDB_CODE_SUCCESS); TAOS_RETURN(TSDB_CODE_SUCCESS);
} }
void walRefFirstVer(SWal *pWal, SWalRef *pRef) { void walRefFirstVer(SWal *pWal, SWalRef *pRef) {
taosThreadMutexLock(&pWal->mutex); TAOS_UNUSED(taosThreadMutexLock(&pWal->mutex));
pRef->refVer = pWal->vers.firstVer; pRef->refVer = pWal->vers.firstVer;
taosThreadMutexUnlock(&pWal->mutex); TAOS_UNUSED(taosThreadMutexUnlock(&pWal->mutex));
wDebug("vgId:%d, wal ref version %" PRId64 " for first", pWal->cfg.vgId, pRef->refVer); wDebug("vgId:%d, wal ref version %" PRId64 " for first", pWal->cfg.vgId, pRef->refVer);
} }
void walRefLastVer(SWal *pWal, SWalRef *pRef) { void walRefLastVer(SWal *pWal, SWalRef *pRef) {
taosThreadMutexLock(&pWal->mutex); TAOS_UNUSED(taosThreadMutexLock(&pWal->mutex));
pRef->refVer = pWal->vers.lastVer; pRef->refVer = pWal->vers.lastVer;
taosThreadMutexUnlock(&pWal->mutex); TAOS_UNUSED(taosThreadMutexUnlock(&pWal->mutex));
wDebug("vgId:%d, wal ref version %" PRId64 " for last", pWal->cfg.vgId, pRef->refVer); wDebug("vgId:%d, wal ref version %" PRId64 " for last", pWal->cfg.vgId, pRef->refVer);
} }

View File

@ -23,7 +23,7 @@
int32_t walRestoreFromSnapshot(SWal *pWal, int64_t ver) { int32_t walRestoreFromSnapshot(SWal *pWal, int64_t ver) {
int32_t code = 0; int32_t code = 0;
taosThreadMutexLock(&pWal->mutex); TAOS_UNUSED(taosThreadMutexLock(&pWal->mutex));
wInfo("vgId:%d, restore from snapshot, version %" PRId64, pWal->cfg.vgId, ver); wInfo("vgId:%d, restore from snapshot, version %" PRId64, pWal->cfg.vgId, ver);
@ -34,14 +34,14 @@ int32_t walRestoreFromSnapshot(SWal *pWal, int64_t ver) {
SWalRef *pRef = *(SWalRef **)pIter; SWalRef *pRef = *(SWalRef **)pIter;
if (pRef->refVer != -1 && pRef->refVer <= ver) { if (pRef->refVer != -1 && pRef->refVer <= ver) {
taosHashCancelIterate(pWal->pRefHash, pIter); taosHashCancelIterate(pWal->pRefHash, pIter);
taosThreadMutexUnlock(&pWal->mutex); TAOS_UNUSED(taosThreadMutexUnlock(&pWal->mutex));
TAOS_RETURN(TSDB_CODE_FAILED); TAOS_RETURN(TSDB_CODE_FAILED);
} }
} }
taosCloseFile(&pWal->pLogFile); TAOS_UNUSED(taosCloseFile(&pWal->pLogFile));
taosCloseFile(&pWal->pIdxFile); TAOS_UNUSED(taosCloseFile(&pWal->pIdxFile));
if (pWal->vers.firstVer != -1) { if (pWal->vers.firstVer != -1) {
int32_t fileSetSize = taosArrayGetSize(pWal->fileInfoSet); int32_t fileSetSize = taosArrayGetSize(pWal->fileInfoSet);
@ -51,7 +51,7 @@ int32_t walRestoreFromSnapshot(SWal *pWal, int64_t ver) {
walBuildLogName(pWal, pFileInfo->firstVer, fnameStr); walBuildLogName(pWal, pFileInfo->firstVer, fnameStr);
if (taosRemoveFile(fnameStr) < 0) { if (taosRemoveFile(fnameStr) < 0) {
wError("vgId:%d, restore from snapshot, cannot remove file %s since %s", pWal->cfg.vgId, fnameStr, terrstr()); wError("vgId:%d, restore from snapshot, cannot remove file %s since %s", pWal->cfg.vgId, fnameStr, terrstr());
taosThreadMutexUnlock(&pWal->mutex); TAOS_UNUSED(taosThreadMutexUnlock(&pWal->mutex));
TAOS_RETURN(TAOS_SYSTEM_ERROR(errno)); TAOS_RETURN(TAOS_SYSTEM_ERROR(errno));
} }
@ -60,7 +60,7 @@ int32_t walRestoreFromSnapshot(SWal *pWal, int64_t ver) {
walBuildIdxName(pWal, pFileInfo->firstVer, fnameStr); walBuildIdxName(pWal, pFileInfo->firstVer, fnameStr);
if (taosRemoveFile(fnameStr) < 0) { if (taosRemoveFile(fnameStr) < 0) {
wError("vgId:%d, cannot remove file %s since %s", pWal->cfg.vgId, fnameStr, terrstr()); wError("vgId:%d, cannot remove file %s since %s", pWal->cfg.vgId, fnameStr, terrstr());
taosThreadMutexUnlock(&pWal->mutex); TAOS_UNUSED(taosThreadMutexUnlock(&pWal->mutex));
TAOS_RETURN(TAOS_SYSTEM_ERROR(errno)); TAOS_RETURN(TAOS_SYSTEM_ERROR(errno));
} }
@ -81,7 +81,7 @@ int32_t walRestoreFromSnapshot(SWal *pWal, int64_t ver) {
pWal->vers.snapshotVer = ver; pWal->vers.snapshotVer = ver;
pWal->vers.verInSnapshotting = -1; pWal->vers.verInSnapshotting = -1;
taosThreadMutexUnlock(&pWal->mutex); TAOS_UNUSED(taosThreadMutexUnlock(&pWal->mutex));
TAOS_RETURN(TSDB_CODE_SUCCESS); TAOS_RETURN(TSDB_CODE_SUCCESS);
} }
@ -146,7 +146,7 @@ static int64_t walChangeWrite(SWal *pWal, int64_t ver) {
walBuildLogName(pWal, fileFirstVer, fnameStr); walBuildLogName(pWal, fileFirstVer, fnameStr);
pLogTFile = taosOpenFile(fnameStr, TD_FILE_CREATE | TD_FILE_WRITE | TD_FILE_APPEND); pLogTFile = taosOpenFile(fnameStr, TD_FILE_CREATE | TD_FILE_WRITE | TD_FILE_APPEND);
if (pLogTFile == NULL) { if (pLogTFile == NULL) {
taosCloseFile(&pIdxTFile); TAOS_UNUSED(taosCloseFile(&pIdxTFile));
pWal->pLogFile = NULL; pWal->pLogFile = NULL;
TAOS_RETURN(TAOS_SYSTEM_ERROR(errno)); TAOS_RETURN(TAOS_SYSTEM_ERROR(errno));
@ -160,12 +160,12 @@ static int64_t walChangeWrite(SWal *pWal, int64_t ver) {
} }
int32_t walRollback(SWal *pWal, int64_t ver) { int32_t walRollback(SWal *pWal, int64_t ver) {
taosThreadMutexLock(&pWal->mutex); TAOS_UNUSED(taosThreadMutexLock(&pWal->mutex));
wInfo("vgId:%d, wal rollback for version %" PRId64, pWal->cfg.vgId, ver); wInfo("vgId:%d, wal rollback for version %" PRId64, pWal->cfg.vgId, ver);
int64_t code; int64_t code;
char fnameStr[WAL_FILE_LEN]; char fnameStr[WAL_FILE_LEN];
if (ver > pWal->vers.lastVer || ver <= pWal->vers.commitVer || ver <= pWal->vers.snapshotVer) { if (ver > pWal->vers.lastVer || ver <= pWal->vers.commitVer || ver <= pWal->vers.snapshotVer) {
taosThreadMutexUnlock(&pWal->mutex); TAOS_UNUSED(taosThreadMutexUnlock(&pWal->mutex));
TAOS_RETURN(TSDB_CODE_WAL_INVALID_VER); TAOS_RETURN(TSDB_CODE_WAL_INVALID_VER);
} }
@ -175,7 +175,7 @@ int32_t walRollback(SWal *pWal, int64_t ver) {
// change current files // change current files
code = walChangeWrite(pWal, ver); code = walChangeWrite(pWal, ver);
if (code < 0) { if (code < 0) {
taosThreadMutexUnlock(&pWal->mutex); TAOS_UNUSED(taosThreadMutexUnlock(&pWal->mutex));
TAOS_RETURN(code); TAOS_RETURN(code);
} }
@ -187,50 +187,50 @@ int32_t walRollback(SWal *pWal, int64_t ver) {
walBuildLogName(pWal, pInfo->firstVer, fnameStr); walBuildLogName(pWal, pInfo->firstVer, fnameStr);
wDebug("vgId:%d, wal remove file %s for rollback", pWal->cfg.vgId, fnameStr); wDebug("vgId:%d, wal remove file %s for rollback", pWal->cfg.vgId, fnameStr);
taosRemoveFile(fnameStr); TAOS_UNUSED(taosRemoveFile(fnameStr));
walBuildIdxName(pWal, pInfo->firstVer, fnameStr); walBuildIdxName(pWal, pInfo->firstVer, fnameStr);
wDebug("vgId:%d, wal remove file %s for rollback", pWal->cfg.vgId, fnameStr); wDebug("vgId:%d, wal remove file %s for rollback", pWal->cfg.vgId, fnameStr);
taosRemoveFile(fnameStr); TAOS_UNUSED(taosRemoveFile(fnameStr));
} }
} }
walBuildIdxName(pWal, walGetCurFileFirstVer(pWal), fnameStr); walBuildIdxName(pWal, walGetCurFileFirstVer(pWal), fnameStr);
taosCloseFile(&pWal->pIdxFile); TAOS_UNUSED(taosCloseFile(&pWal->pIdxFile));
TdFilePtr pIdxFile = taosOpenFile(fnameStr, TD_FILE_WRITE | TD_FILE_READ | TD_FILE_APPEND); TdFilePtr pIdxFile = taosOpenFile(fnameStr, TD_FILE_WRITE | TD_FILE_READ | TD_FILE_APPEND);
if (pIdxFile == NULL) { if (pIdxFile == NULL) {
taosThreadMutexUnlock(&pWal->mutex); TAOS_UNUSED(taosThreadMutexUnlock(&pWal->mutex));
TAOS_RETURN(TAOS_SYSTEM_ERROR(errno)); TAOS_RETURN(TAOS_SYSTEM_ERROR(errno));
} }
int64_t idxOff = walGetVerIdxOffset(pWal, ver); int64_t idxOff = walGetVerIdxOffset(pWal, ver);
code = taosLSeekFile(pIdxFile, idxOff, SEEK_SET); code = taosLSeekFile(pIdxFile, idxOff, SEEK_SET);
if (code < 0) { if (code < 0) {
taosThreadMutexUnlock(&pWal->mutex); TAOS_UNUSED(taosThreadMutexUnlock(&pWal->mutex));
TAOS_RETURN(TAOS_SYSTEM_ERROR(errno)); TAOS_RETURN(TAOS_SYSTEM_ERROR(errno));
} }
// read idx file and get log file pos // read idx file and get log file pos
SWalIdxEntry entry; SWalIdxEntry entry;
if (taosReadFile(pIdxFile, &entry, sizeof(SWalIdxEntry)) != sizeof(SWalIdxEntry)) { if (taosReadFile(pIdxFile, &entry, sizeof(SWalIdxEntry)) != sizeof(SWalIdxEntry)) {
taosThreadMutexUnlock(&pWal->mutex); TAOS_UNUSED(taosThreadMutexUnlock(&pWal->mutex));
TAOS_RETURN(TAOS_SYSTEM_ERROR(errno)); TAOS_RETURN(TAOS_SYSTEM_ERROR(errno));
} }
walBuildLogName(pWal, walGetCurFileFirstVer(pWal), fnameStr); walBuildLogName(pWal, walGetCurFileFirstVer(pWal), fnameStr);
taosCloseFile(&pWal->pLogFile); TAOS_UNUSED(taosCloseFile(&pWal->pLogFile));
TdFilePtr pLogFile = taosOpenFile(fnameStr, TD_FILE_WRITE | TD_FILE_READ | TD_FILE_APPEND); TdFilePtr pLogFile = taosOpenFile(fnameStr, TD_FILE_WRITE | TD_FILE_READ | TD_FILE_APPEND);
wDebug("vgId:%d, wal truncate file %s", pWal->cfg.vgId, fnameStr); wDebug("vgId:%d, wal truncate file %s", pWal->cfg.vgId, fnameStr);
if (pLogFile == NULL) { if (pLogFile == NULL) {
// TODO // TODO
taosThreadMutexUnlock(&pWal->mutex); TAOS_UNUSED(taosThreadMutexUnlock(&pWal->mutex));
TAOS_RETURN(TAOS_SYSTEM_ERROR(errno)); TAOS_RETURN(TAOS_SYSTEM_ERROR(errno));
} }
code = taosLSeekFile(pLogFile, entry.offset, SEEK_SET); code = taosLSeekFile(pLogFile, entry.offset, SEEK_SET);
if (code < 0) { if (code < 0) {
// TODO // TODO
taosThreadMutexUnlock(&pWal->mutex); TAOS_UNUSED(taosThreadMutexUnlock(&pWal->mutex));
TAOS_RETURN(TAOS_SYSTEM_ERROR(errno)); TAOS_RETURN(TAOS_SYSTEM_ERROR(errno));
} }
@ -238,19 +238,19 @@ int32_t walRollback(SWal *pWal, int64_t ver) {
SWalCkHead head; SWalCkHead head;
int64_t size = taosReadFile(pLogFile, &head, sizeof(SWalCkHead)); int64_t size = taosReadFile(pLogFile, &head, sizeof(SWalCkHead));
if (size != sizeof(SWalCkHead)) { if (size != sizeof(SWalCkHead)) {
taosThreadMutexUnlock(&pWal->mutex); TAOS_UNUSED(taosThreadMutexUnlock(&pWal->mutex));
TAOS_RETURN(TAOS_SYSTEM_ERROR(errno)); TAOS_RETURN(TAOS_SYSTEM_ERROR(errno));
} }
code = walValidHeadCksum(&head); code = walValidHeadCksum(&head);
if (code != 0) { if (code != 0) {
taosThreadMutexUnlock(&pWal->mutex); TAOS_UNUSED(taosThreadMutexUnlock(&pWal->mutex));
TAOS_RETURN(TSDB_CODE_WAL_FILE_CORRUPTED); TAOS_RETURN(TSDB_CODE_WAL_FILE_CORRUPTED);
} }
if (head.head.version != ver) { if (head.head.version != ver) {
taosThreadMutexUnlock(&pWal->mutex); TAOS_UNUSED(taosThreadMutexUnlock(&pWal->mutex));
TAOS_RETURN(TSDB_CODE_WAL_FILE_CORRUPTED); TAOS_RETURN(TSDB_CODE_WAL_FILE_CORRUPTED);
} }
@ -258,13 +258,13 @@ int32_t walRollback(SWal *pWal, int64_t ver) {
// truncate old files // truncate old files
code = taosFtruncateFile(pLogFile, entry.offset); code = taosFtruncateFile(pLogFile, entry.offset);
if (code < 0) { if (code < 0) {
taosThreadMutexUnlock(&pWal->mutex); TAOS_UNUSED(taosThreadMutexUnlock(&pWal->mutex));
TAOS_RETURN(TAOS_SYSTEM_ERROR(errno)); TAOS_RETURN(TAOS_SYSTEM_ERROR(errno));
} }
code = taosFtruncateFile(pIdxFile, idxOff); code = taosFtruncateFile(pIdxFile, idxOff);
if (code < 0) { if (code < 0) {
taosThreadMutexUnlock(&pWal->mutex); TAOS_UNUSED(taosThreadMutexUnlock(&pWal->mutex));
TAOS_RETURN(TAOS_SYSTEM_ERROR(errno)); TAOS_RETURN(TAOS_SYSTEM_ERROR(errno));
} }
@ -272,19 +272,19 @@ int32_t walRollback(SWal *pWal, int64_t ver) {
((SWalFileInfo *)taosArrayGetLast(pWal->fileInfoSet))->lastVer = ver - 1; ((SWalFileInfo *)taosArrayGetLast(pWal->fileInfoSet))->lastVer = ver - 1;
((SWalFileInfo *)taosArrayGetLast(pWal->fileInfoSet))->fileSize = entry.offset; ((SWalFileInfo *)taosArrayGetLast(pWal->fileInfoSet))->fileSize = entry.offset;
taosCloseFile(&pIdxFile); TAOS_UNUSED(taosCloseFile(&pIdxFile));
taosCloseFile(&pLogFile); TAOS_UNUSED(taosCloseFile(&pLogFile));
code = walSaveMeta(pWal); code = walSaveMeta(pWal);
if (code < 0) { if (code < 0) {
wError("vgId:%d, failed to save meta since %s", pWal->cfg.vgId, terrstr()); wError("vgId:%d, failed to save meta since %s", pWal->cfg.vgId, terrstr());
taosThreadMutexUnlock(&pWal->mutex); TAOS_UNUSED(taosThreadMutexUnlock(&pWal->mutex));
TAOS_RETURN(code); TAOS_RETURN(code);
} }
// unlock // unlock
taosThreadMutexUnlock(&pWal->mutex); TAOS_UNUSED(taosThreadMutexUnlock(&pWal->mutex));
TAOS_RETURN(TSDB_CODE_SUCCESS); TAOS_RETURN(TSDB_CODE_SUCCESS);
} }
@ -371,7 +371,7 @@ static FORCE_INLINE int32_t walCheckAndRoll(SWal *pWal) {
int32_t walBeginSnapshot(SWal *pWal, int64_t ver, int64_t logRetention) { int32_t walBeginSnapshot(SWal *pWal, int64_t ver, int64_t logRetention) {
int32_t code = 0; int32_t code = 0;
taosThreadMutexLock(&pWal->mutex); TAOS_UNUSED(taosThreadMutexLock(&pWal->mutex));
ASSERT(logRetention >= 0); ASSERT(logRetention >= 0);
pWal->vers.verInSnapshotting = ver; pWal->vers.verInSnapshotting = ver;
pWal->vers.logRetention = logRetention; pWal->vers.logRetention = logRetention;
@ -388,7 +388,7 @@ int32_t walBeginSnapshot(SWal *pWal, int64_t ver, int64_t logRetention) {
} }
_exit: _exit:
taosThreadMutexUnlock(&pWal->mutex); TAOS_UNUSED(taosThreadMutexUnlock(&pWal->mutex));
TAOS_RETURN(code); TAOS_RETURN(code);
} }
@ -396,7 +396,7 @@ _exit:
int32_t walEndSnapshot(SWal *pWal) { int32_t walEndSnapshot(SWal *pWal) {
int32_t code = 0, lino = 0; int32_t code = 0, lino = 0;
taosThreadMutexLock(&pWal->mutex); TAOS_UNUSED(taosThreadMutexLock(&pWal->mutex));
int64_t ver = pWal->vers.verInSnapshotting; int64_t ver = pWal->vers.verInSnapshotting;
wDebug("vgId:%d, wal end snapshot for version %" PRId64 ", log retention %" PRId64 " first ver %" PRId64 wDebug("vgId:%d, wal end snapshot for version %" PRId64 ", log retention %" PRId64 " first ver %" PRId64
@ -456,7 +456,7 @@ int32_t walEndSnapshot(SWal *pWal) {
} }
for (SWalFileInfo *iter = pWal->fileInfoSet->pData; iter <= pUntil; iter++) { for (SWalFileInfo *iter = pWal->fileInfoSet->pData; iter <= pUntil; iter++) {
deleteCnt++; deleteCnt++;
taosArrayPush(pWal->toDeleteFiles, iter); TAOS_UNUSED(taosArrayPush(pWal->toDeleteFiles, iter));
} }
// make new array, remove files // make new array, remove files
@ -589,8 +589,8 @@ static FORCE_INLINE int32_t walWriteImpl(SWal *pWal, int64_t index, tmsg_t msgTy
TAOS_CHECK_GOTO(TSDB_CODE_OUT_OF_MEMORY, &lino, _exit); TAOS_CHECK_GOTO(TSDB_CODE_OUT_OF_MEMORY, &lino, _exit);
} }
memset(newBody, 0, cyptedBodyLen); TAOS_UNUSED(memset(newBody, 0, cyptedBodyLen));
memcpy(newBody, body, plainBodyLen); TAOS_UNUSED(memcpy(newBody, body, plainBodyLen));
newBodyEncrypted = taosMemoryMalloc(cyptedBodyLen); newBodyEncrypted = taosMemoryMalloc(cyptedBodyLen);
if (newBodyEncrypted == NULL) { if (newBodyEncrypted == NULL) {
@ -607,7 +607,7 @@ static FORCE_INLINE int32_t walWriteImpl(SWal *pWal, int64_t index, tmsg_t msgTy
opts.source = newBody; opts.source = newBody;
opts.result = newBodyEncrypted; opts.result = newBodyEncrypted;
opts.unitLen = 16; opts.unitLen = 16;
strncpy(opts.key, pWal->cfg.encryptKey, ENCRYPT_KEY_LEN); TAOS_UNUSED(strncpy((char *)opts.key, pWal->cfg.encryptKey, ENCRYPT_KEY_LEN));
int32_t count = CBC_Encrypt(&opts); int32_t count = CBC_Encrypt(&opts);
@ -698,7 +698,7 @@ int32_t walAppendLog(SWal *pWal, int64_t index, tmsg_t msgType, SWalSyncInfo syn
int32_t bodyLen) { int32_t bodyLen) {
int32_t code = 0, lino = 0; int32_t code = 0, lino = 0;
taosThreadMutexLock(&pWal->mutex); TAOS_UNUSED(taosThreadMutexLock(&pWal->mutex));
if (index != pWal->vers.lastVer + 1) { if (index != pWal->vers.lastVer + 1) {
TAOS_CHECK_GOTO(TSDB_CODE_WAL_INVALID_VER, &lino, _exit); TAOS_CHECK_GOTO(TSDB_CODE_WAL_INVALID_VER, &lino, _exit);
@ -717,7 +717,7 @@ _exit:
wError("%s failed at line %d since %s", __func__, lino, tstrerror(code)); wError("%s failed at line %d since %s", __func__, lino, tstrerror(code));
} }
taosThreadMutexUnlock(&pWal->mutex); TAOS_UNUSED(taosThreadMutexUnlock(&pWal->mutex));
return code; return code;
} }
@ -728,7 +728,7 @@ int32_t walFsync(SWal *pWal, bool forceFsync) {
return code; return code;
} }
taosThreadMutexLock(&pWal->mutex); TAOS_UNUSED(taosThreadMutexLock(&pWal->mutex));
if (forceFsync || (pWal->cfg.level == TAOS_WAL_FSYNC && pWal->cfg.fsyncPeriod == 0)) { if (forceFsync || (pWal->cfg.level == TAOS_WAL_FSYNC && pWal->cfg.fsyncPeriod == 0)) {
wTrace("vgId:%d, fileId:%" PRId64 ".log, do fsync", pWal->cfg.vgId, walGetCurFileFirstVer(pWal)); wTrace("vgId:%d, fileId:%" PRId64 ".log, do fsync", pWal->cfg.vgId, walGetCurFileFirstVer(pWal));
if (taosFsyncFile(pWal->pLogFile) < 0) { if (taosFsyncFile(pWal->pLogFile) < 0) {
@ -737,7 +737,7 @@ int32_t walFsync(SWal *pWal, bool forceFsync) {
code = TAOS_SYSTEM_ERROR(errno); code = TAOS_SYSTEM_ERROR(errno);
} }
} }
taosThreadMutexUnlock(&pWal->mutex); TAOS_UNUSED(taosThreadMutexUnlock(&pWal->mutex));
return code; return code;
} }

View File

@ -333,13 +333,13 @@ static void taosLRUCacheShardEvictLRU(SLRUCacheShard *shard, size_t charge, SArr
static void taosLRUCacheShardSetCapacity(SLRUCacheShard *shard, size_t capacity) { static void taosLRUCacheShardSetCapacity(SLRUCacheShard *shard, size_t capacity) {
SArray *lastReferenceList = taosArrayInit(16, POINTER_BYTES); SArray *lastReferenceList = taosArrayInit(16, POINTER_BYTES);
taosThreadMutexLock(&shard->mutex); (void)taosThreadMutexLock(&shard->mutex);
shard->capacity = capacity; shard->capacity = capacity;
shard->highPriPoolCapacity = capacity * shard->highPriPoolRatio; shard->highPriPoolCapacity = capacity * shard->highPriPoolRatio;
taosLRUCacheShardEvictLRU(shard, 0, lastReferenceList); taosLRUCacheShardEvictLRU(shard, 0, lastReferenceList);
taosThreadMutexUnlock(&shard->mutex); (void)taosThreadMutexUnlock(&shard->mutex);
for (int i = 0; i < taosArrayGetSize(lastReferenceList); ++i) { for (int i = 0; i < taosArrayGetSize(lastReferenceList); ++i) {
SLRUEntry *entry = taosArrayGetP(lastReferenceList, i); SLRUEntry *entry = taosArrayGetP(lastReferenceList, i);
@ -352,9 +352,9 @@ static int taosLRUCacheShardInit(SLRUCacheShard *shard, size_t capacity, bool st
int maxUpperHashBits) { int maxUpperHashBits) {
TAOS_CHECK_RETURN(taosLRUEntryTableInit(&shard->table, maxUpperHashBits)); TAOS_CHECK_RETURN(taosLRUEntryTableInit(&shard->table, maxUpperHashBits));
taosThreadMutexInit(&shard->mutex, NULL); (void)taosThreadMutexInit(&shard->mutex, NULL);
taosThreadMutexLock(&shard->mutex); (void)taosThreadMutexLock(&shard->mutex);
shard->capacity = 0; shard->capacity = 0;
shard->highPriPoolUsage = 0; shard->highPriPoolUsage = 0;
shard->strictCapacity = strict; shard->strictCapacity = strict;
@ -367,7 +367,7 @@ static int taosLRUCacheShardInit(SLRUCacheShard *shard, size_t capacity, bool st
shard->lru.next = &shard->lru; shard->lru.next = &shard->lru;
shard->lru.prev = &shard->lru; shard->lru.prev = &shard->lru;
shard->lruLowPri = &shard->lru; shard->lruLowPri = &shard->lru;
taosThreadMutexUnlock(&shard->mutex); (void)taosThreadMutexUnlock(&shard->mutex);
taosLRUCacheShardSetCapacity(shard, capacity); taosLRUCacheShardSetCapacity(shard, capacity);
@ -375,7 +375,7 @@ static int taosLRUCacheShardInit(SLRUCacheShard *shard, size_t capacity, bool st
} }
static void taosLRUCacheShardCleanup(SLRUCacheShard *shard) { static void taosLRUCacheShardCleanup(SLRUCacheShard *shard) {
taosThreadMutexDestroy(&shard->mutex); (void)taosThreadMutexDestroy(&shard->mutex);
taosLRUEntryTableCleanup(&shard->table); taosLRUEntryTableCleanup(&shard->table);
} }
@ -385,7 +385,7 @@ static LRUStatus taosLRUCacheShardInsertEntry(SLRUCacheShard *shard, SLRUEntry *
LRUStatus status = TAOS_LRU_STATUS_OK; LRUStatus status = TAOS_LRU_STATUS_OK;
SArray *lastReferenceList = taosArrayInit(16, POINTER_BYTES); SArray *lastReferenceList = taosArrayInit(16, POINTER_BYTES);
taosThreadMutexLock(&shard->mutex); (void)taosThreadMutexLock(&shard->mutex);
taosLRUCacheShardEvictLRU(shard, e->totalCharge, lastReferenceList); taosLRUCacheShardEvictLRU(shard, e->totalCharge, lastReferenceList);
@ -429,7 +429,7 @@ static LRUStatus taosLRUCacheShardInsertEntry(SLRUCacheShard *shard, SLRUEntry *
} }
} }
taosThreadMutexUnlock(&shard->mutex); (void)taosThreadMutexUnlock(&shard->mutex);
for (int i = 0; i < taosArrayGetSize(lastReferenceList); ++i) { for (int i = 0; i < taosArrayGetSize(lastReferenceList); ++i) {
SLRUEntry *entry = taosArrayGetP(lastReferenceList, i); SLRUEntry *entry = taosArrayGetP(lastReferenceList, i);
@ -470,7 +470,7 @@ static LRUStatus taosLRUCacheShardInsert(SLRUCacheShard *shard, const void *key,
static LRUHandle *taosLRUCacheShardLookup(SLRUCacheShard *shard, const void *key, size_t keyLen, uint32_t hash) { static LRUHandle *taosLRUCacheShardLookup(SLRUCacheShard *shard, const void *key, size_t keyLen, uint32_t hash) {
SLRUEntry *e = NULL; SLRUEntry *e = NULL;
taosThreadMutexLock(&shard->mutex); (void)taosThreadMutexLock(&shard->mutex);
e = taosLRUEntryTableLookup(&shard->table, key, keyLen, hash); e = taosLRUEntryTableLookup(&shard->table, key, keyLen, hash);
if (e != NULL) { if (e != NULL) {
ASSERT(TAOS_LRU_ENTRY_IN_CACHE(e)); ASSERT(TAOS_LRU_ENTRY_IN_CACHE(e));
@ -481,14 +481,14 @@ static LRUHandle *taosLRUCacheShardLookup(SLRUCacheShard *shard, const void *key
TAOS_LRU_ENTRY_SET_HIT(e); TAOS_LRU_ENTRY_SET_HIT(e);
} }
taosThreadMutexUnlock(&shard->mutex); (void)taosThreadMutexUnlock(&shard->mutex);
return (LRUHandle *)e; return (LRUHandle *)e;
} }
static void taosLRUCacheShardErase(SLRUCacheShard *shard, const void *key, size_t keyLen, uint32_t hash) { static void taosLRUCacheShardErase(SLRUCacheShard *shard, const void *key, size_t keyLen, uint32_t hash) {
bool lastReference = false; bool lastReference = false;
taosThreadMutexLock(&shard->mutex); (void)taosThreadMutexLock(&shard->mutex);
SLRUEntry *e = taosLRUEntryTableRemove(&shard->table, key, keyLen, hash); SLRUEntry *e = taosLRUEntryTableRemove(&shard->table, key, keyLen, hash);
if (e != NULL) { if (e != NULL) {
@ -503,7 +503,7 @@ static void taosLRUCacheShardErase(SLRUCacheShard *shard, const void *key, size_
} }
} }
taosThreadMutexUnlock(&shard->mutex); (void)taosThreadMutexUnlock(&shard->mutex);
if (lastReference) { if (lastReference) {
taosLRUEntryFree(e); taosLRUEntryFree(e);
@ -513,11 +513,11 @@ static void taosLRUCacheShardErase(SLRUCacheShard *shard, const void *key, size_
static int taosLRUCacheShardApply(SLRUCacheShard *shard, _taos_lru_functor_t functor, void *ud) { static int taosLRUCacheShardApply(SLRUCacheShard *shard, _taos_lru_functor_t functor, void *ud) {
int ret; int ret;
taosThreadMutexLock(&shard->mutex); (void)taosThreadMutexLock(&shard->mutex);
ret = taosLRUEntryTableApplyF(&shard->table, functor, ud); ret = taosLRUEntryTableApplyF(&shard->table, functor, ud);
taosThreadMutexUnlock(&shard->mutex); (void)taosThreadMutexUnlock(&shard->mutex);
return ret; return ret;
} }
@ -525,7 +525,7 @@ static int taosLRUCacheShardApply(SLRUCacheShard *shard, _taos_lru_functor_t fun
static void taosLRUCacheShardEraseUnrefEntries(SLRUCacheShard *shard) { static void taosLRUCacheShardEraseUnrefEntries(SLRUCacheShard *shard) {
SArray *lastReferenceList = taosArrayInit(16, POINTER_BYTES); SArray *lastReferenceList = taosArrayInit(16, POINTER_BYTES);
taosThreadMutexLock(&shard->mutex); (void)taosThreadMutexLock(&shard->mutex);
while (shard->lru.next != &shard->lru) { while (shard->lru.next != &shard->lru) {
SLRUEntry *old = shard->lru.next; SLRUEntry *old = shard->lru.next;
@ -539,7 +539,7 @@ static void taosLRUCacheShardEraseUnrefEntries(SLRUCacheShard *shard) {
taosArrayPush(lastReferenceList, &old); taosArrayPush(lastReferenceList, &old);
} }
taosThreadMutexUnlock(&shard->mutex); (void)taosThreadMutexUnlock(&shard->mutex);
for (int i = 0; i < taosArrayGetSize(lastReferenceList); ++i) { for (int i = 0; i < taosArrayGetSize(lastReferenceList); ++i) {
SLRUEntry *entry = taosArrayGetP(lastReferenceList, i); SLRUEntry *entry = taosArrayGetP(lastReferenceList, i);
@ -552,12 +552,12 @@ static void taosLRUCacheShardEraseUnrefEntries(SLRUCacheShard *shard) {
static bool taosLRUCacheShardRef(SLRUCacheShard *shard, LRUHandle *handle) { static bool taosLRUCacheShardRef(SLRUCacheShard *shard, LRUHandle *handle) {
SLRUEntry *e = (SLRUEntry *)handle; SLRUEntry *e = (SLRUEntry *)handle;
taosThreadMutexLock(&shard->mutex); (void)taosThreadMutexLock(&shard->mutex);
ASSERT(TAOS_LRU_ENTRY_HAS_REFS(e)); ASSERT(TAOS_LRU_ENTRY_HAS_REFS(e));
TAOS_LRU_ENTRY_REF(e); TAOS_LRU_ENTRY_REF(e);
taosThreadMutexUnlock(&shard->mutex); (void)taosThreadMutexUnlock(&shard->mutex);
return true; return true;
} }
@ -570,7 +570,7 @@ static bool taosLRUCacheShardRelease(SLRUCacheShard *shard, LRUHandle *handle, b
SLRUEntry *e = (SLRUEntry *)handle; SLRUEntry *e = (SLRUEntry *)handle;
bool lastReference = false; bool lastReference = false;
taosThreadMutexLock(&shard->mutex); (void)taosThreadMutexLock(&shard->mutex);
lastReference = taosLRUEntryUnref(e); lastReference = taosLRUEntryUnref(e);
if (lastReference && TAOS_LRU_ENTRY_IN_CACHE(e)) { if (lastReference && TAOS_LRU_ENTRY_IN_CACHE(e)) {
@ -591,7 +591,7 @@ static bool taosLRUCacheShardRelease(SLRUCacheShard *shard, LRUHandle *handle, b
shard->usage -= e->totalCharge; shard->usage -= e->totalCharge;
} }
taosThreadMutexUnlock(&shard->mutex); (void)taosThreadMutexUnlock(&shard->mutex);
if (lastReference) { if (lastReference) {
taosLRUEntryFree(e); taosLRUEntryFree(e);
@ -603,9 +603,9 @@ static bool taosLRUCacheShardRelease(SLRUCacheShard *shard, LRUHandle *handle, b
static size_t taosLRUCacheShardGetUsage(SLRUCacheShard *shard) { static size_t taosLRUCacheShardGetUsage(SLRUCacheShard *shard) {
size_t usage = 0; size_t usage = 0;
taosThreadMutexLock(&shard->mutex); (void)taosThreadMutexLock(&shard->mutex);
usage = shard->usage; usage = shard->usage;
taosThreadMutexUnlock(&shard->mutex); (void)taosThreadMutexUnlock(&shard->mutex);
return usage; return usage;
} }
@ -613,9 +613,9 @@ static size_t taosLRUCacheShardGetUsage(SLRUCacheShard *shard) {
static int32_t taosLRUCacheShardGetElems(SLRUCacheShard *shard) { static int32_t taosLRUCacheShardGetElems(SLRUCacheShard *shard) {
int32_t elems = 0; int32_t elems = 0;
taosThreadMutexLock(&shard->mutex); (void)taosThreadMutexLock(&shard->mutex);
elems = shard->table.elems; elems = shard->table.elems;
taosThreadMutexUnlock(&shard->mutex); (void)taosThreadMutexUnlock(&shard->mutex);
return elems; return elems;
} }
@ -623,22 +623,22 @@ static int32_t taosLRUCacheShardGetElems(SLRUCacheShard *shard) {
static size_t taosLRUCacheShardGetPinnedUsage(SLRUCacheShard *shard) { static size_t taosLRUCacheShardGetPinnedUsage(SLRUCacheShard *shard) {
size_t usage = 0; size_t usage = 0;
taosThreadMutexLock(&shard->mutex); (void)taosThreadMutexLock(&shard->mutex);
ASSERT(shard->usage >= shard->lruUsage); ASSERT(shard->usage >= shard->lruUsage);
usage = shard->usage - shard->lruUsage; usage = shard->usage - shard->lruUsage;
taosThreadMutexUnlock(&shard->mutex); (void)taosThreadMutexUnlock(&shard->mutex);
return usage; return usage;
} }
static void taosLRUCacheShardSetStrictCapacity(SLRUCacheShard *shard, bool strict) { static void taosLRUCacheShardSetStrictCapacity(SLRUCacheShard *shard, bool strict) {
taosThreadMutexLock(&shard->mutex); (void)taosThreadMutexLock(&shard->mutex);
shard->strictCapacity = strict; shard->strictCapacity = strict;
taosThreadMutexUnlock(&shard->mutex); (void)taosThreadMutexUnlock(&shard->mutex);
} }
struct SShardedCache { struct SShardedCache {
@ -706,7 +706,7 @@ SLRUCache *taosLRUCacheInit(size_t capacity, int numShardBits, double highPriPoo
cache->shardedCache.capacity = capacity; cache->shardedCache.capacity = capacity;
cache->shardedCache.lastId = 1; cache->shardedCache.lastId = 1;
taosThreadMutexInit(&cache->shardedCache.capacityMutex, NULL); (void)taosThreadMutexInit(&cache->shardedCache.capacityMutex, NULL);
return cache; return cache;
} }
@ -723,7 +723,7 @@ void taosLRUCacheCleanup(SLRUCache *cache) {
cache->shards = 0; cache->shards = 0;
} }
taosThreadMutexDestroy(&cache->shardedCache.capacityMutex); (void)taosThreadMutexDestroy(&cache->shardedCache.capacityMutex);
taosMemoryFree(cache); taosMemoryFree(cache);
} }
@ -826,7 +826,7 @@ void taosLRUCacheSetCapacity(SLRUCache *cache, size_t capacity) {
uint32_t numShards = cache->numShards; uint32_t numShards = cache->numShards;
size_t perShard = (capacity + (numShards - 1)) / numShards; size_t perShard = (capacity + (numShards - 1)) / numShards;
taosThreadMutexLock(&cache->shardedCache.capacityMutex); (void)taosThreadMutexLock(&cache->shardedCache.capacityMutex);
for (int i = 0; i < numShards; ++i) { for (int i = 0; i < numShards; ++i) {
taosLRUCacheShardSetCapacity(&cache->shards[i], perShard); taosLRUCacheShardSetCapacity(&cache->shards[i], perShard);
@ -834,17 +834,17 @@ void taosLRUCacheSetCapacity(SLRUCache *cache, size_t capacity) {
cache->shardedCache.capacity = capacity; cache->shardedCache.capacity = capacity;
taosThreadMutexUnlock(&cache->shardedCache.capacityMutex); (void)taosThreadMutexUnlock(&cache->shardedCache.capacityMutex);
} }
size_t taosLRUCacheGetCapacity(SLRUCache *cache) { size_t taosLRUCacheGetCapacity(SLRUCache *cache) {
size_t capacity = 0; size_t capacity = 0;
taosThreadMutexLock(&cache->shardedCache.capacityMutex); (void)taosThreadMutexLock(&cache->shardedCache.capacityMutex);
capacity = cache->shardedCache.capacity; capacity = cache->shardedCache.capacity;
taosThreadMutexUnlock(&cache->shardedCache.capacityMutex); (void)taosThreadMutexUnlock(&cache->shardedCache.capacityMutex);
return capacity; return capacity;
} }
@ -852,7 +852,7 @@ size_t taosLRUCacheGetCapacity(SLRUCache *cache) {
void taosLRUCacheSetStrictCapacity(SLRUCache *cache, bool strict) { void taosLRUCacheSetStrictCapacity(SLRUCache *cache, bool strict) {
uint32_t numShards = cache->numShards; uint32_t numShards = cache->numShards;
taosThreadMutexLock(&cache->shardedCache.capacityMutex); (void)taosThreadMutexLock(&cache->shardedCache.capacityMutex);
for (int i = 0; i < numShards; ++i) { for (int i = 0; i < numShards; ++i) {
taosLRUCacheShardSetStrictCapacity(&cache->shards[i], strict); taosLRUCacheShardSetStrictCapacity(&cache->shards[i], strict);
@ -860,17 +860,17 @@ void taosLRUCacheSetStrictCapacity(SLRUCache *cache, bool strict) {
cache->shardedCache.strictCapacity = strict; cache->shardedCache.strictCapacity = strict;
taosThreadMutexUnlock(&cache->shardedCache.capacityMutex); (void)taosThreadMutexUnlock(&cache->shardedCache.capacityMutex);
} }
bool taosLRUCacheIsStrictCapacity(SLRUCache *cache) { bool taosLRUCacheIsStrictCapacity(SLRUCache *cache) {
bool strict = false; bool strict = false;
taosThreadMutexLock(&cache->shardedCache.capacityMutex); (void)taosThreadMutexLock(&cache->shardedCache.capacityMutex);
strict = cache->shardedCache.strictCapacity; strict = cache->shardedCache.strictCapacity;
taosThreadMutexUnlock(&cache->shardedCache.capacityMutex); (void)taosThreadMutexUnlock(&cache->shardedCache.capacityMutex);
return strict; return strict;
} }