From a9e81a0df4ff374e9145f26cd005897ef8ade8c0 Mon Sep 17 00:00:00 2001 From: hzcheng Date: Thu, 2 Apr 2020 09:47:03 +0800 Subject: [PATCH] TD-34 --- src/vnode/tsdb/src/tsdbFile.c | 2 +- src/vnode/tsdb/src/tsdbMain.c | 10 ++++++++-- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/src/vnode/tsdb/src/tsdbFile.c b/src/vnode/tsdb/src/tsdbFile.c index c4d4ad119a..ff8da1cdad 100644 --- a/src/vnode/tsdb/src/tsdbFile.c +++ b/src/vnode/tsdb/src/tsdbFile.c @@ -356,7 +356,7 @@ int tsdbCreateFile(char *dataDir, int fileId, const char *suffix, int maxTables, return -1; } - if (tsdbOpenFile(pFile, O_WRONLY | O_CREAT) < 0) { + if (tsdbOpenFile(pFile, O_RDWR | O_CREAT) < 0) { // TODO: deal with the ERROR here return -1; } diff --git a/src/vnode/tsdb/src/tsdbMain.c b/src/vnode/tsdb/src/tsdbMain.c index 0e8cfb5457..8ab7648510 100644 --- a/src/vnode/tsdb/src/tsdbMain.c +++ b/src/vnode/tsdb/src/tsdbMain.c @@ -13,6 +13,7 @@ // #include "taosdef.h" // #include "disk.h" +#include "os.h" #include "tsdb.h" #include "tsdbMain.h" @@ -914,7 +915,8 @@ static int tsdbCommitToFile(STsdbRepo *pRepo, int fid, SSkipListIterator **iters pGroup = tsdbOpenFilesForCommit(pFileH, fid); if (pGroup == NULL) { /* TODO */ } - tsdbCreateFile(dataDir, fid, ".h", pCfg->maxTables, &hFile, 1, 0); + tsdbCreateFile(dataDir, fid, ".h", pCfg->maxTables, &hFile, 1, 1); + tsdbOpenFile(&hFile, O_RDWR); if (0 /*pGroup->files[TSDB_FILE_TYPE_LAST].size > TSDB_MAX_LAST_FILE_SIZE*/) { // TODO: make it not to write the last file every time tsdbCreateFile(dataDir, fid, ".l", pCfg->maxTables, &lFile, 0, 0); @@ -1045,7 +1047,11 @@ _table_over: // Write the SCompBlock part pIdx->offset = lseek(hFile.fd, 0, SEEK_END); if (pIdx->len > 0) { - sendfile(pGroup->files[TSDB_FILE_TYPE_HEAD].fd, hFile.fd, NULL, pIdx->len); + int bytes = tsendfile(hFile.fd, pGroup->files[TSDB_FILE_TYPE_HEAD].fd, NULL, pIdx->len); + if (bytes < pIdx->len) { + printf("Failed to send file, reason: %s\n", strerror(errno)); + int d = 1; + } if (nNewBlocks > 0) { write(hFile.fd, (void *)(pCompInfo->blocks), sizeof(SCompBlock) * nNewBlocks); pIdx->len += (sizeof(SCompBlock) * nNewBlocks); -- GitLab