Merge pull request #17105 from taosdata/fix/idxReadCrash

fix(idx): fix index read crash
This commit is contained in:
Shengliang Guan 2022-09-28 08:57:57 +08:00 committed by GitHub
commit 17f0aabf5d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 29 additions and 18 deletions

View File

@ -302,6 +302,7 @@ static int32_t cacheSearchCompareFunc_JSON(void* cache, SIndexTerm* term, SIdxTR
char* p = taosMemoryCalloc(1, strlen(c->colVal) + 1);
memcpy(p, c->colVal, strlen(c->colVal));
cond = cmpFn(p + skip, term->colVal, dType);
taosMemoryFree(p);
}
}
if (cond == MATCH) {

View File

@ -69,6 +69,8 @@ static int idxFileCtxDoReadFrom(IFileCtx* ctx, uint8_t* buf, int len, int32_t of
int32_t blkOffset = offset % kBlockSize;
int32_t blkLeft = kBlockSize - blkOffset;
if (offset >= ctx->file.size) return 0;
do {
char key[128] = {0};
idxGenLRUKey(key, ctx->file.buf, blkId);
@ -79,6 +81,15 @@ static int idxFileCtxDoReadFrom(IFileCtx* ctx, uint8_t* buf, int len, int32_t of
nread = TMIN(blkLeft, len);
memcpy(buf + total, blk->buf + blkOffset, nread);
taosLRUCacheRelease(ctx->lru, h, false);
} else {
int32_t left = ctx->file.size - offset;
if (left < kBlockSize) {
nread = TMIN(left, len);
int32_t bytes = taosPReadFile(ctx->file.pFile, buf + total, nread, offset);
assert(bytes == nread);
total += bytes;
return total;
} else {
int32_t cacheMemSize = sizeof(SDataBlock) + kBlockSize;
@ -100,6 +111,7 @@ static int idxFileCtxDoReadFrom(IFileCtx* ctx, uint8_t* buf, int len, int32_t of
return -1;
}
}
}
total += nread;
len -= nread;
offset += nread;
@ -146,9 +158,7 @@ IFileCtx* idxFileCtxCreate(WriterType type, const char* path, bool readOnly, int
} else {
ctx->file.pFile = taosOpenFile(path, TD_FILE_READ);
int64_t size = 0;
taosFStatFile(ctx->file.pFile, &ctx->file.size, NULL);
ctx->file.size = (int)size;
#ifdef USE_MMAP
ctx->file.ptr = (char*)tfMmapReadOnly(ctx->file.pFile, ctx->file.size);
#endif

View File

@ -172,9 +172,9 @@ TEST_F(JsonEnv, testWriteMillonData) {
{
std::string colName("voltagefdadfa");
std::string colVal("abxxxxxxxxxxxx");
for (int i = 0; i < 10; i++) {
for (int i = 0; i < 10000; i++) {
colVal[i % colVal.size()] = '0' + i % 128;
for (size_t i = 0; i < 100; i++) {
for (size_t i = 0; i < 10; i++) {
SIndexTerm* term = indexTermCreateT(1, ADD_VALUE, TSDB_DATA_TYPE_BINARY, colName.c_str(), colName.size(),
colVal.c_str(), colVal.size());