diff --git a/src/vnode/tsdb/src/tsdbFile.c b/src/vnode/tsdb/src/tsdbFile.c index c4d4ad119aab309baa92699537de279b3d15f752..ff8da1cdadd130dc28b6544f58620a50429c5643 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 0e8cfb5457357d246225a79ddbacb9653320b016..8ab7648510c4a4b53ec0571305a42c15ec1665e3 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);