diff --git a/src/common/src/tdisk.c b/src/common/src/tdisk.c index 425a66058f..0c7d633773 100644 --- a/src/common/src/tdisk.c +++ b/src/common/src/tdisk.c @@ -99,7 +99,10 @@ int tdUpdateTiersInfo(SDnodeTier *pDnodeTier) { for (int j = 0; j < pTier->nDisks; j++) { SDisk *pDisk = pTier->disks[j]; - if (tdUpdateDiskMeta(pDisk) < 0) return -1; + if (tdUpdateDiskMeta(pDisk) < 0) { + tdUnLockTiers(pDnodeTier); + return -1; + } pDnodeTier->meta.tsize += pDisk->dmeta.size; pDnodeTier->meta.avail += pDisk->dmeta.free; diff --git a/src/os/inc/osFile.h b/src/os/inc/osFile.h index dc19c8177c..75c2b749d1 100644 --- a/src/os/inc/osFile.h +++ b/src/os/inc/osFile.h @@ -34,6 +34,7 @@ int taosFSendFileImp(FILE* out_file, FILE* in_file, int64_t* offset, int32_t #define taosTRead(fd, buf, count) taosTReadImp(fd, buf, count) #define taosTWrite(fd, buf, count) taosTWriteImp(fd, buf, count) #define taosLSeek(fd, offset, whence) lseek(fd, offset, whence) +ssize_t taosTCopy(char *from, char *to); #ifdef TAOS_RANDOM_FILE_FAIL void taosSetRandomFileFailFactor(int factor); diff --git a/src/os/src/detail/osFile.c b/src/os/src/detail/osFile.c index 8f055dd812..429aab77e4 100644 --- a/src/os/src/detail/osFile.c +++ b/src/os/src/detail/osFile.c @@ -108,6 +108,39 @@ ssize_t taosTWriteImp(int fd, void *buf, size_t n) { return (ssize_t)n; } +ssize_t taosTCopy(char *from, char *to) { + char buffer[4096]; + int fidto = -1, fidfrom = -1; + ssize_t size = 0; + ssize_t bytes; + + fidfrom = open(from, O_RDONLY); + if (fidfrom < 0) goto _err; + + fidto = open(to, O_WRONLY | O_CREAT, 0755); + if (fidto < 0) goto _err; + + while (true) { + bytes = taosTRead(fidfrom, buffer, sizeof(buffer)); + if (bytes < 0) goto _err; + if (bytes == 0) break; + + size += bytes; + + if (taosTWrite(fidto, (void *)buffer, bytes) < bytes) goto _err; + if (bytes < sizeof(buffer)) break; + } + + close(fidfrom); + close(fidto); + return size; + +_err: + if (fidfrom >= 0) close(fidfrom); + if (fidto >= 0) close(fidto); + return -1; +} + #ifndef TAOS_OS_FUNC_FILE_SENDIFLE ssize_t taosTSendFileImp(int dfd, int sfd, off_t *offset, size_t size) { size_t leftbytes = size; diff --git a/src/tsdb/src/tsdbFile.c b/src/tsdb/src/tsdbFile.c index 365f4953c4..450ba879e8 100644 --- a/src/tsdb/src/tsdbFile.c +++ b/src/tsdb/src/tsdbFile.c @@ -471,11 +471,14 @@ int tsdbApplyRetention(STsdbRepo *pRepo, SFidGroup *pFidGroup) { nFileGroup.level = level; nFileGroup.did = pDisk->did; + char tsdbRootDir[TSDB_FILENAME_LEN]; + tdGetTsdbRootDir(pDisk->dir, REPO_ID(pRepo), tsdbRootDir); for (int type = 0; type < TSDB_FILE_TYPE_MAX; type++) { - // TODO fileGroup.files[type].fname + tsdbGetDataFileName(tsdbRootDir, REPO_ID(pRepo), pGroup->fileId, type, nFileGroup.files[type].fname); } for (int type = 0; type < TSDB_FILE_TYPE_MAX; type++) { + if (taosTCopy(oFileGroup.files[type].fname, nFileGroup.files[type].fname) < 0) return -1; } pthread_rwlock_wrlock(&(pFileH->fhlock));