Merge pull request #11218 from taosdata/fix/ZhiqiangWang/TD-13756-log-file-open-fail-error
[TD-13756]<fix>: log file open fail error.
This commit is contained in:
commit
5b98a16d95
|
@ -325,7 +325,7 @@ int64_t taosReadFile(TdFilePtr pFile, void *buf, int64_t count) {
|
||||||
#if FILE_WITH_LOCK
|
#if FILE_WITH_LOCK
|
||||||
taosThreadRwlockRdlock(&(pFile->rwlock));
|
taosThreadRwlockRdlock(&(pFile->rwlock));
|
||||||
#endif
|
#endif
|
||||||
assert(pFile->fd >= 0);
|
assert(pFile->fd >= 0); // Please check if you have closed the file.
|
||||||
int64_t leftbytes = count;
|
int64_t leftbytes = count;
|
||||||
int64_t readbytes;
|
int64_t readbytes;
|
||||||
char *tbuf = (char *)buf;
|
char *tbuf = (char *)buf;
|
||||||
|
@ -365,7 +365,7 @@ int64_t taosPReadFile(TdFilePtr pFile, void *buf, int64_t count, int64_t offset)
|
||||||
#if FILE_WITH_LOCK
|
#if FILE_WITH_LOCK
|
||||||
taosThreadRwlockRdlock(&(pFile->rwlock));
|
taosThreadRwlockRdlock(&(pFile->rwlock));
|
||||||
#endif
|
#endif
|
||||||
assert(pFile->fd >= 0);
|
assert(pFile->fd >= 0); // Please check if you have closed the file.
|
||||||
int64_t ret = pread(pFile->fd, buf, count, offset);
|
int64_t ret = pread(pFile->fd, buf, count, offset);
|
||||||
#if FILE_WITH_LOCK
|
#if FILE_WITH_LOCK
|
||||||
taosThreadRwlockUnlock(&(pFile->rwlock));
|
taosThreadRwlockUnlock(&(pFile->rwlock));
|
||||||
|
@ -380,7 +380,7 @@ int64_t taosWriteFile(TdFilePtr pFile, const void *buf, int64_t count) {
|
||||||
#if FILE_WITH_LOCK
|
#if FILE_WITH_LOCK
|
||||||
taosThreadRwlockWrlock(&(pFile->rwlock));
|
taosThreadRwlockWrlock(&(pFile->rwlock));
|
||||||
#endif
|
#endif
|
||||||
assert(pFile->fd >= 0);
|
assert(pFile->fd >= 0); // Please check if you have closed the file.
|
||||||
|
|
||||||
int64_t nleft = count;
|
int64_t nleft = count;
|
||||||
int64_t nwritten = 0;
|
int64_t nwritten = 0;
|
||||||
|
@ -414,7 +414,7 @@ int64_t taosLSeekFile(TdFilePtr pFile, int64_t offset, int32_t whence) {
|
||||||
#if FILE_WITH_LOCK
|
#if FILE_WITH_LOCK
|
||||||
taosThreadRwlockRdlock(&(pFile->rwlock));
|
taosThreadRwlockRdlock(&(pFile->rwlock));
|
||||||
#endif
|
#endif
|
||||||
assert(pFile->fd >= 0);
|
assert(pFile->fd >= 0); // Please check if you have closed the file.
|
||||||
int64_t ret = lseek(pFile->fd, (long)offset, whence);
|
int64_t ret = lseek(pFile->fd, (long)offset, whence);
|
||||||
#if FILE_WITH_LOCK
|
#if FILE_WITH_LOCK
|
||||||
taosThreadRwlockUnlock(&(pFile->rwlock));
|
taosThreadRwlockUnlock(&(pFile->rwlock));
|
||||||
|
@ -429,7 +429,7 @@ int32_t taosFStatFile(TdFilePtr pFile, int64_t *size, int32_t *mtime) {
|
||||||
if (pFile == NULL) {
|
if (pFile == NULL) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
assert(pFile->fd >= 0);
|
assert(pFile->fd >= 0); // Please check if you have closed the file.
|
||||||
|
|
||||||
struct stat fileStat;
|
struct stat fileStat;
|
||||||
int32_t code = fstat(pFile->fd, &fileStat);
|
int32_t code = fstat(pFile->fd, &fileStat);
|
||||||
|
@ -456,7 +456,7 @@ int32_t taosLockFile(TdFilePtr pFile) {
|
||||||
if (pFile == NULL) {
|
if (pFile == NULL) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
assert(pFile->fd >= 0);
|
assert(pFile->fd >= 0); // Please check if you have closed the file.
|
||||||
|
|
||||||
return (int32_t)flock(pFile->fd, LOCK_EX | LOCK_NB);
|
return (int32_t)flock(pFile->fd, LOCK_EX | LOCK_NB);
|
||||||
#endif
|
#endif
|
||||||
|
@ -469,7 +469,7 @@ int32_t taosUnLockFile(TdFilePtr pFile) {
|
||||||
if (pFile == NULL) {
|
if (pFile == NULL) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
assert(pFile->fd >= 0);
|
assert(pFile->fd >= 0); // Please check if you have closed the file.
|
||||||
|
|
||||||
return (int32_t)flock(pFile->fd, LOCK_UN | LOCK_NB);
|
return (int32_t)flock(pFile->fd, LOCK_UN | LOCK_NB);
|
||||||
#endif
|
#endif
|
||||||
|
@ -529,7 +529,7 @@ int32_t taosFtruncateFile(TdFilePtr pFile, int64_t l_size) {
|
||||||
if (pFile == NULL) {
|
if (pFile == NULL) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
assert(pFile->fd >= 0);
|
assert(pFile->fd >= 0); // Please check if you have closed the file.
|
||||||
|
|
||||||
return ftruncate(pFile->fd, l_size);
|
return ftruncate(pFile->fd, l_size);
|
||||||
#endif
|
#endif
|
||||||
|
@ -750,7 +750,7 @@ void *taosMmapReadOnlyFile(TdFilePtr pFile, int64_t length) {
|
||||||
if (pFile == NULL) {
|
if (pFile == NULL) {
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
assert(pFile->fd >= 0);
|
assert(pFile->fd >= 0); // Please check if you have closed the file.
|
||||||
|
|
||||||
void *ptr = mmap(NULL, length, PROT_READ, MAP_SHARED, pFile->fd, 0);
|
void *ptr = mmap(NULL, length, PROT_READ, MAP_SHARED, pFile->fd, 0);
|
||||||
return ptr;
|
return ptr;
|
||||||
|
|
|
@ -214,6 +214,7 @@ static void *taosThreadToOpenNewFile(void *param) {
|
||||||
tsLogObj.logHandle->pFile = pFile;
|
tsLogObj.logHandle->pFile = pFile;
|
||||||
tsLogObj.lines = 0;
|
tsLogObj.lines = 0;
|
||||||
tsLogObj.openInProgress = 0;
|
tsLogObj.openInProgress = 0;
|
||||||
|
taosSsleep(3);
|
||||||
taosCloseLogByFd(pOldFile);
|
taosCloseLogByFd(pOldFile);
|
||||||
|
|
||||||
uInfo(" new log file:%d is opened", tsLogObj.flag);
|
uInfo(" new log file:%d is opened", tsLogObj.flag);
|
||||||
|
@ -347,16 +348,12 @@ static int32_t taosOpenLogFile(char *fn, int32_t maxLines, int32_t maxFileNum) {
|
||||||
taosThreadMutexInit(&tsLogObj.logMutex, NULL);
|
taosThreadMutexInit(&tsLogObj.logMutex, NULL);
|
||||||
|
|
||||||
taosUmaskFile(0);
|
taosUmaskFile(0);
|
||||||
TdFilePtr pFile = taosOpenFile(fileName, TD_FILE_CTEATE | TD_FILE_WRITE);
|
tsLogObj.logHandle->pFile = taosOpenFile(fileName, TD_FILE_CTEATE | TD_FILE_WRITE);
|
||||||
|
|
||||||
if (pFile == NULL) {
|
if (tsLogObj.logHandle->pFile == NULL) {
|
||||||
printf("\nfailed to open log file:%s, reason:%s\n", fileName, strerror(errno));
|
printf("\nfailed to open log file:%s, reason:%s\n", fileName, strerror(errno));
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
TdFilePtr pOldFile = tsLogObj.logHandle->pFile;
|
|
||||||
tsLogObj.logHandle->pFile = pFile;
|
|
||||||
taosUnLockLogFile(pOldFile);
|
|
||||||
taosCloseFile(&pOldFile);
|
|
||||||
taosLockLogFile(tsLogObj.logHandle->pFile);
|
taosLockLogFile(tsLogObj.logHandle->pFile);
|
||||||
|
|
||||||
// only an estimate for number of lines
|
// only an estimate for number of lines
|
||||||
|
|
Loading…
Reference in New Issue