Merge pull request #10554 from taosdata/fix/ZhiqiangWang/TD-13756-file-system-remove-func
[TD-13756]<fix>: file system remove func.
This commit is contained in:
commit
0cd6a4cf05
|
@ -22,6 +22,7 @@ extern "C" {
|
||||||
|
|
||||||
#include "osSocket.h"
|
#include "osSocket.h"
|
||||||
|
|
||||||
|
// If the error is in a third-party library, place this header file under the third-party library header file.
|
||||||
#ifndef ALLOW_FORBID_FUNC
|
#ifndef ALLOW_FORBID_FUNC
|
||||||
#define open OPEN_FUNC_TAOS_FORBID
|
#define open OPEN_FUNC_TAOS_FORBID
|
||||||
#define fopen FOPEN_FUNC_TAOS_FORBID
|
#define fopen FOPEN_FUNC_TAOS_FORBID
|
||||||
|
@ -31,6 +32,8 @@ extern "C" {
|
||||||
#define fstat FSTAT_FUNC_TAOS_FORBID
|
#define fstat FSTAT_FUNC_TAOS_FORBID
|
||||||
#define close CLOSE_FUNC_TAOS_FORBID
|
#define close CLOSE_FUNC_TAOS_FORBID
|
||||||
#define fclose FCLOSE_FUNC_TAOS_FORBID
|
#define fclose FCLOSE_FUNC_TAOS_FORBID
|
||||||
|
#define fsync FSYNC_FUNC_TAOS_FORBID
|
||||||
|
// #define fflush FFLUSH_FUNC_TAOS_FORBID
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifndef PATH_MAX
|
#ifndef PATH_MAX
|
||||||
|
@ -47,7 +50,7 @@ typedef struct TdFile *TdFilePtr;
|
||||||
#define TD_FILE_TEXT 0x0020
|
#define TD_FILE_TEXT 0x0020
|
||||||
#define TD_FILE_AUTO_DEL 0x0040
|
#define TD_FILE_AUTO_DEL 0x0040
|
||||||
#define TD_FILE_EXCL 0x0080
|
#define TD_FILE_EXCL 0x0080
|
||||||
#define TD_FILE_STREAM 0x0100 // Only support taosFprintfFile, taosGetLineFile, taosGetLineFile, taosEOFFile
|
#define TD_FILE_STREAM 0x0100 // Only support taosFprintfFile, taosGetLineFile, taosEOFFile
|
||||||
TdFilePtr taosOpenFile(const char *path,int32_t tdFileOptions);
|
TdFilePtr taosOpenFile(const char *path,int32_t tdFileOptions);
|
||||||
|
|
||||||
#define TD_FILE_ACCESS_EXIST_OK 0x1
|
#define TD_FILE_ACCESS_EXIST_OK 0x1
|
||||||
|
@ -80,6 +83,7 @@ int64_t taosCloseFile(TdFilePtr *ppFile);
|
||||||
|
|
||||||
int32_t taosRenameFile(const char *oldName, const char *newName);
|
int32_t taosRenameFile(const char *oldName, const char *newName);
|
||||||
int64_t taosCopyFile(const char *from, const char *to);
|
int64_t taosCopyFile(const char *from, const char *to);
|
||||||
|
int32_t taosRemoveFile(const char *path);
|
||||||
|
|
||||||
void taosGetTmpfilePath(const char *inputTmpDir, const char *fileNamePrefix, char *dstPath);
|
void taosGetTmpfilePath(const char *inputTmpDir, const char *fileNamePrefix, char *dstPath);
|
||||||
|
|
||||||
|
|
|
@ -46,7 +46,7 @@ STSBuf* tsBufCreate(bool autoDelete, int32_t order) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!autoDelete) {
|
if (!autoDelete) {
|
||||||
remove(pTSBuf->path);
|
taosRemoveFile(pTSBuf->path);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (NULL == allocResForTSBuf(pTSBuf)) {
|
if (NULL == allocResForTSBuf(pTSBuf)) {
|
||||||
|
@ -178,7 +178,7 @@ void* tsBufDestroy(STSBuf* pTSBuf) {
|
||||||
|
|
||||||
if (pTSBuf->autoDelete) {
|
if (pTSBuf->autoDelete) {
|
||||||
// ("tsBuf %p destroyed, delete tmp file:%s", pTSBuf, pTSBuf->path);
|
// ("tsBuf %p destroyed, delete tmp file:%s", pTSBuf, pTSBuf->path);
|
||||||
remove(pTSBuf->path);
|
taosRemoveFile(pTSBuf->path);
|
||||||
} else {
|
} else {
|
||||||
// tscDebug("tsBuf %p destroyed, tmp file:%s, remains", pTSBuf, pTSBuf->path);
|
// tscDebug("tsBuf %p destroyed, tmp file:%s, remains", pTSBuf, pTSBuf->path);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1054,7 +1054,7 @@ int tsdbWriteBlockIdx(SDFile *pHeadf, SArray *pIdxA, void **ppBuf) {
|
||||||
// pfs->metaCacheComp = NULL;
|
// pfs->metaCacheComp = NULL;
|
||||||
// } else {
|
// } else {
|
||||||
// // remove meta.tmp file
|
// // remove meta.tmp file
|
||||||
// remove(mf.f.aname);
|
// taosRemoveFile(mf.f.aname);
|
||||||
// taosHashCleanup(pfs->metaCacheComp);
|
// taosHashCleanup(pfs->metaCacheComp);
|
||||||
// pfs->metaCacheComp = NULL;
|
// pfs->metaCacheComp = NULL;
|
||||||
// }
|
// }
|
||||||
|
|
|
@ -439,7 +439,7 @@ static int tsdbSaveFSStatus(STsdb *pRepo, SFSStatus *pStatus) {
|
||||||
if (taosWriteFile(pFile, hbuf, TSDB_FILE_HEAD_SIZE) < TSDB_FILE_HEAD_SIZE) {
|
if (taosWriteFile(pFile, hbuf, TSDB_FILE_HEAD_SIZE) < TSDB_FILE_HEAD_SIZE) {
|
||||||
terrno = TAOS_SYSTEM_ERROR(errno);
|
terrno = TAOS_SYSTEM_ERROR(errno);
|
||||||
taosCloseFile(&pFile);
|
taosCloseFile(&pFile);
|
||||||
remove(tfname);
|
taosRemoveFile(tfname);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -447,7 +447,7 @@ static int tsdbSaveFSStatus(STsdb *pRepo, SFSStatus *pStatus) {
|
||||||
if (fsheader.len > 0) {
|
if (fsheader.len > 0) {
|
||||||
if (tsdbMakeRoom(&(pBuf), fsheader.len) < 0) {
|
if (tsdbMakeRoom(&(pBuf), fsheader.len) < 0) {
|
||||||
taosCloseFile(&pFile);
|
taosCloseFile(&pFile);
|
||||||
remove(tfname);
|
taosRemoveFile(tfname);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -458,7 +458,7 @@ static int tsdbSaveFSStatus(STsdb *pRepo, SFSStatus *pStatus) {
|
||||||
if (taosWriteFile(pFile, pBuf, fsheader.len) < fsheader.len) {
|
if (taosWriteFile(pFile, pBuf, fsheader.len) < fsheader.len) {
|
||||||
terrno = TAOS_SYSTEM_ERROR(errno);
|
terrno = TAOS_SYSTEM_ERROR(errno);
|
||||||
taosCloseFile(&pFile);
|
taosCloseFile(&pFile);
|
||||||
(void)remove(tfname);
|
(void)taosRemoveFile(tfname);
|
||||||
taosTZfree(pBuf);
|
taosTZfree(pBuf);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
@ -468,7 +468,7 @@ static int tsdbSaveFSStatus(STsdb *pRepo, SFSStatus *pStatus) {
|
||||||
if (taosFsyncFile(pFile) < 0) {
|
if (taosFsyncFile(pFile) < 0) {
|
||||||
terrno = TAOS_SYSTEM_ERROR(errno);
|
terrno = TAOS_SYSTEM_ERROR(errno);
|
||||||
taosCloseFile(&pFile);
|
taosCloseFile(&pFile);
|
||||||
remove(tfname);
|
taosRemoveFile(tfname);
|
||||||
taosTZfree(pBuf);
|
taosTZfree(pBuf);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,7 +19,7 @@ static std::string fileName = "/tmp/tindex.tindex";
|
||||||
class FstWriter {
|
class FstWriter {
|
||||||
public:
|
public:
|
||||||
FstWriter() {
|
FstWriter() {
|
||||||
remove(fileName.c_str());
|
taosRemoveFile(fileName.c_str());
|
||||||
_wc = writerCtxCreate(TFile, fileName.c_str(), false, 64 * 1024 * 1024);
|
_wc = writerCtxCreate(TFile, fileName.c_str(), false, 64 * 1024 * 1024);
|
||||||
_b = fstBuilderCreate(_wc, 0);
|
_b = fstBuilderCreate(_wc, 0);
|
||||||
}
|
}
|
||||||
|
|
|
@ -202,7 +202,7 @@ void tfsDirname(const STfsFile *pFile, char *dest) {
|
||||||
tstrncpy(dest, dirname(tname), TSDB_FILENAME_LEN);
|
tstrncpy(dest, dirname(tname), TSDB_FILENAME_LEN);
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t tfsRemoveFile(const STfsFile *pFile) { return remove(pFile->aname); }
|
int32_t tfsRemoveFile(const STfsFile *pFile) { return taosRemoveFile(pFile->aname); }
|
||||||
|
|
||||||
int32_t tfsCopyFile(const STfsFile *pFile1, const STfsFile *pFile2) {
|
int32_t tfsCopyFile(const STfsFile *pFile1, const STfsFile *pFile2) {
|
||||||
return taosCopyFile(pFile1->aname, pFile2->aname);
|
return taosCopyFile(pFile1->aname, pFile2->aname);
|
||||||
|
|
|
@ -192,7 +192,7 @@ int main(int argc, char *argv[]) {
|
||||||
|
|
||||||
if (pDataFile != NULL) {
|
if (pDataFile != NULL) {
|
||||||
taosCloseFile(&pDataFile);
|
taosCloseFile(&pDataFile);
|
||||||
remove(dataName);
|
taosRemoveFile(dataName);
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
|
|
@ -181,7 +181,7 @@ int main(int argc, char *argv[]) {
|
||||||
|
|
||||||
if (pDataFile != NULL) {
|
if (pDataFile != NULL) {
|
||||||
taosCloseFile(&pDataFile);
|
taosCloseFile(&pDataFile);
|
||||||
remove(dataName);
|
taosRemoveFile(dataName);
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
|
|
@ -379,7 +379,7 @@ int walSaveMeta(SWal* pWal) {
|
||||||
// delete old file
|
// delete old file
|
||||||
if (metaVer > -1) {
|
if (metaVer > -1) {
|
||||||
walBuildMetaName(pWal, metaVer, fnameStr);
|
walBuildMetaName(pWal, metaVer, fnameStr);
|
||||||
remove(fnameStr);
|
taosRemoveFile(fnameStr);
|
||||||
}
|
}
|
||||||
free(serialized);
|
free(serialized);
|
||||||
return 0;
|
return 0;
|
||||||
|
|
|
@ -55,9 +55,9 @@ int32_t walRollback(SWal *pWal, int64_t ver) {
|
||||||
int fileSetSize = taosArrayGetSize(pWal->fileInfoSet);
|
int fileSetSize = taosArrayGetSize(pWal->fileInfoSet);
|
||||||
for (int i = pWal->writeCur; i < fileSetSize; i++) {
|
for (int i = pWal->writeCur; i < fileSetSize; i++) {
|
||||||
walBuildLogName(pWal, ((SWalFileInfo *)taosArrayGet(pWal->fileInfoSet, i))->firstVer, fnameStr);
|
walBuildLogName(pWal, ((SWalFileInfo *)taosArrayGet(pWal->fileInfoSet, i))->firstVer, fnameStr);
|
||||||
remove(fnameStr);
|
taosRemoveFile(fnameStr);
|
||||||
walBuildIdxName(pWal, ((SWalFileInfo *)taosArrayGet(pWal->fileInfoSet, i))->firstVer, fnameStr);
|
walBuildIdxName(pWal, ((SWalFileInfo *)taosArrayGet(pWal->fileInfoSet, i))->firstVer, fnameStr);
|
||||||
remove(fnameStr);
|
taosRemoveFile(fnameStr);
|
||||||
}
|
}
|
||||||
// pop from fileInfoSet
|
// pop from fileInfoSet
|
||||||
taosArraySetSize(pWal->fileInfoSet, pWal->writeCur + 1);
|
taosArraySetSize(pWal->fileInfoSet, pWal->writeCur + 1);
|
||||||
|
@ -174,9 +174,9 @@ int32_t walEndSnapshot(SWal *pWal) {
|
||||||
for (int i = 0; i < deleteCnt; i++) {
|
for (int i = 0; i < deleteCnt; i++) {
|
||||||
SWalFileInfo *pInfo = taosArrayGet(pWal->fileInfoSet, i);
|
SWalFileInfo *pInfo = taosArrayGet(pWal->fileInfoSet, i);
|
||||||
walBuildLogName(pWal, pInfo->firstVer, fnameStr);
|
walBuildLogName(pWal, pInfo->firstVer, fnameStr);
|
||||||
remove(fnameStr);
|
taosRemoveFile(fnameStr);
|
||||||
walBuildIdxName(pWal, pInfo->firstVer, fnameStr);
|
walBuildIdxName(pWal, pInfo->firstVer, fnameStr);
|
||||||
remove(fnameStr);
|
taosRemoveFile(fnameStr);
|
||||||
}
|
}
|
||||||
|
|
||||||
// make new array, remove files
|
// make new array, remove files
|
||||||
|
|
|
@ -339,9 +339,9 @@ TEST_F(WalRetentionEnv, repairMeta1) {
|
||||||
//getchar();
|
//getchar();
|
||||||
char buf[100];
|
char buf[100];
|
||||||
sprintf(buf, "%s/meta-ver%d", pathName, 0);
|
sprintf(buf, "%s/meta-ver%d", pathName, 0);
|
||||||
remove(buf);
|
taosRemoveFile(buf);
|
||||||
sprintf(buf, "%s/meta-ver%d", pathName, 1);
|
sprintf(buf, "%s/meta-ver%d", pathName, 1);
|
||||||
remove(buf);
|
taosRemoveFile(buf);
|
||||||
SetUp();
|
SetUp();
|
||||||
//getchar();
|
//getchar();
|
||||||
|
|
||||||
|
|
|
@ -49,7 +49,7 @@ void taosRemoveDir(const char *dirname) {
|
||||||
if (de->d_type & DT_DIR) {
|
if (de->d_type & DT_DIR) {
|
||||||
taosRemoveDir(filename);
|
taosRemoveDir(filename);
|
||||||
} else {
|
} else {
|
||||||
(void)remove(filename);
|
(void)taosRemoveFile(filename);
|
||||||
//printf("file:%s is removed\n", filename);
|
//printf("file:%s is removed\n", filename);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -102,7 +102,7 @@ void taosRemoveOldFiles(const char *dirname, int32_t keepDays) {
|
||||||
if (fileSec <= 100) continue;
|
if (fileSec <= 100) continue;
|
||||||
int32_t days = (int32_t)(TABS(sec - fileSec) / 86400 + 1);
|
int32_t days = (int32_t)(TABS(sec - fileSec) / 86400 + 1);
|
||||||
if (days > keepDays) {
|
if (days > keepDays) {
|
||||||
(void)remove(filename);
|
(void)taosRemoveFile(filename);
|
||||||
//printf("file:%s is removed, days:%d keepDays:%d", filename, days, keepDays);
|
//printf("file:%s is removed, days:%d keepDays:%d", filename, days, keepDays);
|
||||||
} else {
|
} else {
|
||||||
//printf("file:%s won't be removed, days:%d keepDays:%d", filename, days, keepDays);
|
//printf("file:%s won't be removed, days:%d keepDays:%d", filename, days, keepDays);
|
||||||
|
|
|
@ -142,11 +142,13 @@ int64_t taosCopyFile(const char *from, const char *to) {
|
||||||
_err:
|
_err:
|
||||||
if (pFileFrom != NULL) taosCloseFile(&pFileFrom);
|
if (pFileFrom != NULL) taosCloseFile(&pFileFrom);
|
||||||
if (pFileTo != NULL) taosCloseFile(&pFileTo);
|
if (pFileTo != NULL) taosCloseFile(&pFileTo);
|
||||||
remove(to);
|
taosRemoveFile(to);
|
||||||
return -1;
|
return -1;
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int32_t taosRemoveFile(const char *path) { return remove(path); }
|
||||||
|
|
||||||
int32_t taosRenameFile(const char *oldName, const char *newName) {
|
int32_t taosRenameFile(const char *oldName, const char *newName) {
|
||||||
#if defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32)
|
#if defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32)
|
||||||
int32_t code = MoveFileEx(oldName, newName, MOVEFILE_REPLACE_EXISTING | MOVEFILE_COPY_ALLOWED);
|
int32_t code = MoveFileEx(oldName, newName, MOVEFILE_REPLACE_EXISTING | MOVEFILE_COPY_ALLOWED);
|
||||||
|
|
|
@ -180,7 +180,7 @@ static void taosKeepOldLog(char *oldName) {
|
||||||
char compressFileName[LOG_FILE_NAME_LEN + 20];
|
char compressFileName[LOG_FILE_NAME_LEN + 20];
|
||||||
snprintf(compressFileName, LOG_FILE_NAME_LEN + 20, "%s.%" PRId64 ".gz", tsLogObj.logName, fileSec);
|
snprintf(compressFileName, LOG_FILE_NAME_LEN + 20, "%s.%" PRId64 ".gz", tsLogObj.logName, fileSec);
|
||||||
if (taosCompressFile(fileName, compressFileName) == 0) {
|
if (taosCompressFile(fileName, compressFileName) == 0) {
|
||||||
(void)remove(fileName);
|
(void)taosRemoveFile(fileName);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -251,7 +251,7 @@ void taosResetLog() {
|
||||||
tsLogObj.lines = tsLogObj.maxLines + 10;
|
tsLogObj.lines = tsLogObj.maxLines + 10;
|
||||||
|
|
||||||
taosOpenNewLogFile();
|
taosOpenNewLogFile();
|
||||||
(void)remove(lastName);
|
(void)taosRemoveFile(lastName);
|
||||||
|
|
||||||
uInfo("==================================");
|
uInfo("==================================");
|
||||||
uInfo(" reset log file ");
|
uInfo(" reset log file ");
|
||||||
|
|
|
@ -563,7 +563,7 @@ void destroyDiskbasedBuf(SDiskbasedBuf* pBuf) {
|
||||||
ps->loadPages, ps->loadBytes / (1024.0 * ps->loadPages));
|
ps->loadPages, ps->loadBytes / (1024.0 * ps->loadPages));
|
||||||
}
|
}
|
||||||
|
|
||||||
remove(pBuf->path);
|
taosRemoveFile(pBuf->path);
|
||||||
tfree(pBuf->path);
|
tfree(pBuf->path);
|
||||||
|
|
||||||
SArray** p = taosHashIterate(pBuf->groupSet, NULL);
|
SArray** p = taosHashIterate(pBuf->groupSet, NULL);
|
||||||
|
|
Loading…
Reference in New Issue