Merge pull request #6555 from taosdata/hotfix/TD-4777
[TD-4777]taosd crashes when disk full
This commit is contained in:
commit
199f7190be
|
@ -6720,7 +6720,11 @@ int32_t initQInfo(SQueryTableMsg *pQueryMsg, void *tsdb, int32_t vgId, SQInfo *p
|
|||
if (pQueryMsg->tsLen > 0) { // open new file to save the result
|
||||
char *tsBlock = (char *) pQueryMsg + pQueryMsg->tsOffset;
|
||||
pTsBuf = tsBufCreateFromCompBlocks(tsBlock, pQueryMsg->tsNumOfBlocks, pQueryMsg->tsLen, pQueryMsg->tsOrder, vgId);
|
||||
|
||||
if (pTsBuf == NULL) {
|
||||
code = TSDB_CODE_QRY_NO_DISKSPACE;
|
||||
goto _error;
|
||||
}
|
||||
|
||||
tsBufResetPos(pTsBuf);
|
||||
bool ret = tsBufNextPos(pTsBuf);
|
||||
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
#include "taoserror.h"
|
||||
#include "tscompression.h"
|
||||
#include "tutil.h"
|
||||
#include "queryLog.h"
|
||||
|
||||
static int32_t getDataStartOffset();
|
||||
static void TSBufUpdateGroupInfo(STSBuf* pTSBuf, int32_t index, STSGroupBlockInfo* pBlockInfo);
|
||||
|
@ -633,10 +634,15 @@ int32_t STSBufUpdateHeader(STSBuf* pTSBuf, STSBufFileHeader* pHeader) {
|
|||
|
||||
int32_t r = fseek(pTSBuf->f, 0, SEEK_SET);
|
||||
if (r != 0) {
|
||||
qError("fseek failed, errno:%d", errno);
|
||||
return -1;
|
||||
}
|
||||
|
||||
size_t ws = fwrite(pHeader, sizeof(STSBufFileHeader), 1, pTSBuf->f);
|
||||
if (ws != 1) {
|
||||
qError("ts update header fwrite failed, size:%d, expected size:%d", (int32_t)ws, (int32_t)sizeof(STSBufFileHeader));
|
||||
return -1;
|
||||
}
|
||||
|
||||
fwrite(pHeader, sizeof(STSBufFileHeader), 1, pTSBuf->f);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -856,9 +862,17 @@ STSBuf* tsBufCreateFromCompBlocks(const char* pData, int32_t numOfBlocks, int32_
|
|||
TSBufUpdateGroupInfo(pTSBuf, pTSBuf->numOfGroups - 1, pBlockInfo);
|
||||
|
||||
int32_t ret = fseek(pTSBuf->f, pBlockInfo->offset, SEEK_SET);
|
||||
UNUSED(ret);
|
||||
if (ret == -1) {
|
||||
qError("fseek failed, errno:%d", errno);
|
||||
tsBufDestroy(pTSBuf);
|
||||
return NULL;
|
||||
}
|
||||
size_t sz = fwrite((void*)pData, 1, len, pTSBuf->f);
|
||||
UNUSED(sz);
|
||||
if (sz != len) {
|
||||
qError("ts data fwrite failed, write size:%d, expected size:%d", (int32_t)sz, len);
|
||||
tsBufDestroy(pTSBuf);
|
||||
return NULL;
|
||||
}
|
||||
pTSBuf->fileSize += len;
|
||||
|
||||
pTSBuf->tsOrder = order;
|
||||
|
@ -866,9 +880,16 @@ STSBuf* tsBufCreateFromCompBlocks(const char* pData, int32_t numOfBlocks, int32_
|
|||
|
||||
STSBufFileHeader header = {
|
||||
.magic = TS_COMP_FILE_MAGIC, .numOfGroup = pTSBuf->numOfGroups, .tsOrder = pTSBuf->tsOrder};
|
||||
STSBufUpdateHeader(pTSBuf, &header);
|
||||
if (STSBufUpdateHeader(pTSBuf, &header) < 0) {
|
||||
tsBufDestroy(pTSBuf);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
fsync(fileno(pTSBuf->f));
|
||||
if (fsync(fileno(pTSBuf->f)) == -1) {
|
||||
qError("fsync failed, errno:%d", errno);
|
||||
tsBufDestroy(pTSBuf);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return pTSBuf;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue