TDengine/source/dnode/vnode/src/tsdb/tsdbReaderWriter.c

927 lines
25 KiB
C
Raw Normal View History

2022-06-09 05:35:39 +00:00
/*
* Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com>
*
* This program is free software: you can use, redistribute, and/or modify
* it under the terms of the GNU Affero General Public License, version 3
* or later ("AGPL"), as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
2024-03-29 02:48:49 +00:00
#include "crypt.h"
#include "tcs.h"
#include "tsdb.h"
2024-07-18 09:17:02 +00:00
#include "tsdbDef.h"
#include "vnd.h"
2022-09-04 08:12:29 +00:00
static int32_t tsdbOpenFileImpl(STsdbFD *pFD) {
int32_t code = 0;
2024-07-18 09:17:02 +00:00
int32_t lino;
const char *path = pFD->path;
int32_t szPage = pFD->szPage;
int32_t flag = pFD->flag;
int64_t lc_size = 0;
2022-06-09 05:35:39 +00:00
2022-09-04 09:31:20 +00:00
pFD->pFD = taosOpenFile(path, flag);
2022-09-02 09:04:49 +00:00
if (pFD->pFD == NULL) {
if (tsS3Enabled && pFD->lcn > 1 && !strncmp(path + strlen(path) - 5, ".data", 5)) {
char lc_path[TSDB_FILENAME_LEN];
tstrncpy(lc_path, path, TSDB_FQDN_LEN);
int32_t vid = 0;
const char *object_name = taosDirEntryBaseName((char *)path);
2024-07-29 02:33:29 +00:00
(void)sscanf(object_name, "v%df%dver%" PRId64 ".data", &vid, &pFD->fid, &pFD->cid);
char *dot = strrchr(lc_path, '.');
if (!dot) {
tsdbError("unexpected path: %s", lc_path);
2024-07-18 09:17:02 +00:00
TSDB_CHECK_CODE(code = TAOS_SYSTEM_ERROR(ENOENT), lino, _exit);
}
snprintf(dot + 1, TSDB_FQDN_LEN - (dot + 1 - lc_path), "%d.data", pFD->lcn);
pFD->pFD = taosOpenFile(lc_path, flag);
if (pFD->pFD == NULL) {
2024-09-10 09:40:19 +00:00
TSDB_CHECK_CODE(code = terrno, lino, _exit);
}
if (taosStatFile(lc_path, &lc_size, NULL, NULL) < 0) {
2024-09-10 09:40:19 +00:00
TSDB_CHECK_CODE(code = terrno, lino, _exit);
}
} else {
tsdbInfo("no file: %s", path);
2024-09-10 09:40:19 +00:00
TSDB_CHECK_CODE(code = terrno, lino, _exit);
}
pFD->s3File = 1;
2022-06-11 06:36:22 +00:00
}
2022-09-04 15:51:26 +00:00
pFD->pBuf = taosMemoryCalloc(1, szPage);
2022-09-02 09:04:49 +00:00
if (pFD->pBuf == NULL) {
TSDB_CHECK_CODE(code = terrno, lino, _exit);
2022-06-11 03:59:06 +00:00
}
if (lc_size > 0) {
SVnodeCfg *pCfg = &pFD->pTsdb->pVnode->config;
int64_t chunksize = (int64_t)pCfg->tsdbPageSize * pCfg->s3ChunkSize;
pFD->szFile = lc_size + chunksize * (pFD->lcn - 1);
}
// not check file size when reading data files.
if (flag != TD_FILE_READ /* && !pFD->s3File*/) {
if (!lc_size && taosStatFile(path, &pFD->szFile, NULL, NULL) < 0) {
2024-09-10 09:40:19 +00:00
TSDB_CHECK_CODE(code = terrno, lino, _exit);
}
2022-09-04 11:59:21 +00:00
}
2024-08-20 06:47:05 +00:00
if (pFD->szFile % szPage != 0) {
TSDB_CHECK_CODE(code = TSDB_CODE_INVALID_PARA, lino, _exit);
}
pFD->szFile = pFD->szFile / szPage;
_exit:
2024-07-18 09:17:02 +00:00
if (code) {
TSDB_ERROR_LOG(TD_VID(pFD->pTsdb->pVnode), lino, code);
}
return code;
}
// =============== PAGE-WISE FILE ===============
int32_t tsdbOpenFile(const char *path, STsdb *pTsdb, int32_t flag, STsdbFD **ppFD, int32_t lcn) {
int32_t code = 0;
2024-07-18 09:17:02 +00:00
int32_t lino;
STsdbFD *pFD = NULL;
int32_t szPage = pTsdb->pVnode->config.tsdbPageSize;
*ppFD = NULL;
pFD = (STsdbFD *)taosMemoryCalloc(1, sizeof(*pFD) + strlen(path) + 1);
if (pFD == NULL) {
TSDB_CHECK_CODE(code = terrno, lino, _exit);
}
pFD->path = (char *)&pFD[1];
2024-12-17 09:47:08 +00:00
memcpy(pFD->path, path, strlen(path) + 1);
pFD->szPage = szPage;
pFD->flag = flag;
pFD->szPage = szPage;
pFD->pgno = 0;
pFD->lcn = lcn;
pFD->pTsdb = pTsdb;
2022-09-04 06:31:32 +00:00
*ppFD = pFD;
2022-06-11 03:59:06 +00:00
_exit:
2024-07-18 09:17:02 +00:00
if (code) {
TSDB_ERROR_LOG(TD_VID(pTsdb->pVnode), lino, code);
}
2022-06-11 03:59:06 +00:00
return code;
2022-09-02 09:04:49 +00:00
}
2022-06-11 03:59:06 +00:00
2023-03-22 11:24:40 +00:00
void tsdbCloseFile(STsdbFD **ppFD) {
2022-09-04 06:31:32 +00:00
STsdbFD *pFD = *ppFD;
2022-10-14 05:34:25 +00:00
if (pFD) {
taosMemoryFree(pFD->pBuf);
int32_t code = taosCloseFile(&pFD->pFD);
if (code) {
tsdbError("failed to close file: %s, code:%d reason:%s", pFD->path, code, tstrerror(code));
} else {
tsdbTrace("close file: %s", pFD->path);
}
2022-10-14 05:34:25 +00:00
taosMemoryFree(pFD);
*ppFD = NULL;
}
2022-06-10 09:49:01 +00:00
}
static int32_t tsdbWriteFilePage(STsdbFD *pFD, int32_t encryptAlgorithm, char *encryptKey) {
2022-08-06 12:23:29 +00:00
int32_t code = 0;
2024-07-18 09:17:02 +00:00
int32_t lino;
2022-06-11 09:20:29 +00:00
if (!pFD->pFD) {
code = tsdbOpenFileImpl(pFD);
2024-07-18 09:17:02 +00:00
TSDB_CHECK_CODE(code, lino, _exit);
}
2022-09-04 11:59:21 +00:00
if (pFD->pgno > 0) {
int64_t offset = PAGE_OFFSET(pFD->pgno, pFD->szPage);
if (pFD->s3File && pFD->lcn > 1) {
SVnodeCfg *pCfg = &pFD->pTsdb->pVnode->config;
int64_t chunksize = (int64_t)pCfg->tsdbPageSize * pCfg->s3ChunkSize;
int64_t chunkoffset = chunksize * (pFD->lcn - 1);
offset -= chunkoffset;
}
int64_t n = taosLSeekFile(pFD->pFD, offset, SEEK_SET);
2022-09-04 11:59:21 +00:00
if (n < 0) {
2024-09-10 06:55:14 +00:00
TSDB_CHECK_CODE(code = terrno, lino, _exit);
2022-09-04 11:59:21 +00:00
}
2022-06-11 09:20:29 +00:00
2024-09-11 02:56:40 +00:00
code = taosCalcChecksumAppend(0, pFD->pBuf, pFD->szPage);
TSDB_CHECK_CODE(code, lino, _exit);
if (encryptAlgorithm == DND_CA_SM4) {
// if(tsiEncryptAlgorithm == DND_CA_SM4 && (tsiEncryptScope & DND_CS_TSDB) == DND_CS_TSDB){
unsigned char PacketData[128];
int NewLen;
int32_t count = 0;
2024-03-29 02:48:49 +00:00
while (count < pFD->szPage) {
SCryptOpts opts = {0};
opts.len = 128;
opts.source = pFD->pBuf + count;
opts.result = PacketData;
opts.unitLen = 128;
2024-12-09 06:35:12 +00:00
tstrncpy(opts.key, encryptKey, ENCRYPT_KEY_LEN + 1);
2024-03-29 02:48:49 +00:00
NewLen = CBC_Encrypt(&opts);
memcpy(pFD->pBuf + count, PacketData, NewLen);
count += NewLen;
2024-03-29 02:48:49 +00:00
}
// tsdbDebug("CBC_Encrypt count:%d %s", count, __FUNCTION__);
2024-03-29 02:48:49 +00:00
}
2022-08-06 12:23:29 +00:00
2022-09-04 11:59:21 +00:00
n = taosWriteFile(pFD->pFD, pFD->pBuf, pFD->szPage);
if (n < 0) {
2024-09-10 06:55:14 +00:00
TSDB_CHECK_CODE(code = terrno, lino, _exit);
2022-09-04 11:59:21 +00:00
}
2022-07-05 03:08:10 +00:00
2022-09-04 11:59:21 +00:00
if (pFD->szFile < pFD->pgno) {
2022-09-04 15:51:26 +00:00
pFD->szFile = pFD->pgno;
2022-07-05 03:08:10 +00:00
}
2022-06-28 07:20:46 +00:00
}
2022-09-04 11:59:21 +00:00
pFD->pgno = 0;
2022-09-02 09:04:49 +00:00
_exit:
2024-07-18 09:17:02 +00:00
if (code) {
TSDB_ERROR_LOG(TD_VID(pFD->pTsdb->pVnode), lino, code);
}
2022-06-10 09:49:01 +00:00
return code;
}
static int32_t tsdbReadFilePage(STsdbFD *pFD, int64_t pgno, int32_t encryptAlgorithm, char *encryptKey) {
2022-08-06 12:23:29 +00:00
int32_t code = 0;
2024-07-18 09:17:02 +00:00
int32_t lino;
2022-06-13 04:01:10 +00:00
if (!pFD->pFD) {
code = tsdbOpenFileImpl(pFD);
2024-07-18 09:17:02 +00:00
TSDB_CHECK_CODE(code, lino, _exit);
}
2022-09-04 11:59:21 +00:00
int64_t offset = PAGE_OFFSET(pgno, pFD->szPage);
if (pFD->lcn > 1) {
SVnodeCfg *pCfg = &pFD->pTsdb->pVnode->config;
int64_t chunksize = (int64_t)pCfg->tsdbPageSize * pCfg->s3ChunkSize;
int64_t chunkoffset = chunksize * (pFD->lcn - 1);
offset -= chunkoffset;
}
// seek
int64_t n = taosLSeekFile(pFD->pFD, offset, SEEK_SET);
if (n < 0) {
2024-09-10 06:55:14 +00:00
TSDB_CHECK_CODE(code = terrno, lino, _exit);
}
// read
n = taosReadFile(pFD->pFD, pFD->pBuf, pFD->szPage);
if (n < 0) {
2024-09-10 03:29:50 +00:00
TSDB_CHECK_CODE(code = terrno, lino, _exit);
} else if (n < pFD->szPage) {
2024-07-18 09:17:02 +00:00
TSDB_CHECK_CODE(code = TSDB_CODE_FILE_CORRUPTED, lino, _exit);
2022-06-10 12:54:02 +00:00
}
//}
2022-06-10 12:54:02 +00:00
if (encryptAlgorithm == DND_CA_SM4) {
// if(tsiEncryptAlgorithm == DND_CA_SM4 && (tsiEncryptScope & DND_CS_TSDB) == DND_CS_TSDB){
unsigned char PacketData[128];
int NewLen;
2024-04-15 08:24:40 +00:00
int32_t count = 0;
while (count < pFD->szPage) {
2024-04-15 08:24:40 +00:00
SCryptOpts opts = {0};
opts.len = 128;
opts.source = pFD->pBuf + count;
opts.result = PacketData;
opts.unitLen = 128;
2024-12-09 06:48:21 +00:00
tstrncpy(opts.key, encryptKey, ENCRYPT_KEY_LEN + 1);
2024-04-15 08:24:40 +00:00
NewLen = CBC_Decrypt(&opts);
memcpy(pFD->pBuf + count, PacketData, NewLen);
count += NewLen;
}
// tsdbDebug("CBC_Decrypt count:%d %s", count, __FUNCTION__);
2024-04-15 08:24:40 +00:00
}
2022-09-04 09:31:20 +00:00
// check
if (pgno > 1 && !taosCheckChecksumWhole(pFD->pBuf, pFD->szPage)) {
2024-07-18 09:17:02 +00:00
TSDB_CHECK_CODE(code = TSDB_CODE_FILE_CORRUPTED, lino, _exit);
2022-06-10 12:54:02 +00:00
}
2022-09-02 09:04:49 +00:00
pFD->pgno = pgno;
2022-06-28 07:20:46 +00:00
2022-09-02 09:04:49 +00:00
_exit:
2024-07-18 09:17:02 +00:00
if (code) {
TSDB_ERROR_LOG(TD_VID(pFD->pTsdb->pVnode), lino, code);
}
2022-09-02 09:04:49 +00:00
return code;
}
2022-08-06 12:23:29 +00:00
int32_t tsdbWriteFile(STsdbFD *pFD, int64_t offset, const uint8_t *pBuf, int64_t size, int32_t encryptAlgorithm,
char *encryptKey) {
2022-09-04 11:59:21 +00:00
int32_t code = 0;
2024-07-18 09:17:02 +00:00
int32_t lino;
2022-09-04 11:59:21 +00:00
int64_t fOffset = LOGIC_TO_FILE_OFFSET(offset, pFD->szPage);
int64_t pgno = OFFSET_PGNO(fOffset, pFD->szPage);
int64_t bOffset = fOffset % pFD->szPage;
int64_t n = 0;
do {
if (pFD->pgno != pgno) {
2024-03-29 02:48:49 +00:00
code = tsdbWriteFilePage(pFD, encryptAlgorithm, encryptKey);
2024-07-18 09:17:02 +00:00
TSDB_CHECK_CODE(code, lino, _exit);
2022-09-04 11:59:21 +00:00
2022-09-05 04:03:03 +00:00
if (pgno <= pFD->szFile) {
2024-03-29 02:48:49 +00:00
code = tsdbReadFilePage(pFD, pgno, encryptAlgorithm, encryptKey);
2024-07-18 09:17:02 +00:00
TSDB_CHECK_CODE(code, lino, _exit);
2022-09-04 11:59:21 +00:00
} else {
pFD->pgno = pgno;
}
}
2022-09-04 13:38:19 +00:00
int64_t nWrite = TMIN(PAGE_CONTENT_SIZE(pFD->szPage) - bOffset, size - n);
memcpy(pFD->pBuf + bOffset, pBuf + n, nWrite);
2022-09-04 11:59:21 +00:00
pgno++;
bOffset = 0;
2022-09-04 13:38:19 +00:00
n += nWrite;
2022-09-04 11:59:21 +00:00
} while (n < size);
_exit:
2024-07-18 09:17:02 +00:00
if (code) {
TSDB_ERROR_LOG(TD_VID(pFD->pTsdb->pVnode), lino, code);
}
2022-09-04 11:59:21 +00:00
return code;
}
static int32_t tsdbReadFileImp(STsdbFD *pFD, int64_t offset, uint8_t *pBuf, int64_t size, int32_t encryptAlgorithm,
char *encryptKey) {
2022-09-02 09:04:49 +00:00
int32_t code = 0;
2024-07-18 09:17:02 +00:00
int32_t lino;
2022-09-04 13:38:19 +00:00
int64_t n = 0;
2022-09-04 10:18:01 +00:00
int64_t fOffset = LOGIC_TO_FILE_OFFSET(offset, pFD->szPage);
int64_t pgno = OFFSET_PGNO(fOffset, pFD->szPage);
2022-09-04 09:31:20 +00:00
int32_t szPgCont = PAGE_CONTENT_SIZE(pFD->szPage);
2022-09-04 13:50:36 +00:00
int64_t bOffset = fOffset % pFD->szPage;
2022-06-28 07:20:46 +00:00
2024-08-21 02:41:23 +00:00
if (bOffset >= szPgCont) {
2024-08-20 06:47:05 +00:00
TSDB_CHECK_CODE(code = TSDB_CODE_INVALID_PARA, lino, _exit);
}
2022-06-28 07:20:46 +00:00
2022-09-04 10:18:01 +00:00
while (n < size) {
2022-09-04 13:50:36 +00:00
if (pFD->pgno != pgno) {
2024-03-29 02:48:49 +00:00
code = tsdbReadFilePage(pFD, pgno, encryptAlgorithm, encryptKey);
2024-07-18 09:17:02 +00:00
TSDB_CHECK_CODE(code, lino, _exit);
2022-09-04 13:50:36 +00:00
}
2022-06-10 12:54:02 +00:00
2022-09-04 13:50:36 +00:00
int64_t nRead = TMIN(szPgCont - bOffset, size - n);
memcpy(pBuf + n, pFD->pBuf + bOffset, nRead);
2022-09-04 09:31:20 +00:00
2022-09-02 09:04:49 +00:00
n += nRead;
2022-09-04 09:31:20 +00:00
pgno++;
2022-09-04 13:50:36 +00:00
bOffset = 0;
2022-09-02 09:04:49 +00:00
}
_exit:
2024-07-18 09:17:02 +00:00
if (code) {
TSDB_ERROR_LOG(TD_VID(pFD->pTsdb->pVnode), lino, code);
}
2022-06-10 09:49:01 +00:00
return code;
2022-06-14 13:19:46 +00:00
}
feat: support customized taos/taosd (#29736) * feat: support TDAcoreOS * chore: cmake options for TD_ACORE * chore: disable lemon for TD_ACORE * chore: add lzma2 and msvcregex * chore: cmake for lzma2 * chore: adapt for TD_ACORE * chore: adapt strcasecmp for TD_ACORE * chore: adapt for geos/threadName * chore: build adapt for TD_ACORE * chore: build adapt for TD_ACORE * chore: build adapt for TD_ACORE * chore: build adapt for TD_ACORE * chore: build adapt for TD_ACORE termio * chore: refact transComm.h for TD_ACORE * chore: refact transportInt.h for TD_ACORE * chore: refact trans.c for TD_ACORE * chore: refact trpc.h for TD_ACORE * chore: refact transCli.c/transComm.c/transSvr.c for TD_ACORE * chore: refact uv.h for TD_ACORE * chore: refact geosWrapper.h for TD_ACORE * chore: refact token/builtins/udf for TD_ACORE * chore: refact rocks for TD_ACORE * chore: refact tsdbCache.c for TD_ACORE, use LRU cache for last/last_row, not use rocksdb * chore: refact FAIL to _ERR to solve conflicts for TD_ACORE * chore: restore lemon.c/lempar.c * chore: support build lemon for TD_ACORE * chore: refact trpc and siginfo_t for TD_ACORE * chore: refact timezone for TD_ACORE * chore: refact lz4 for TD_ACORE * chore: refact TD_ACORE to make compile pass * chore: code optimization for TD_ASTRA * feat: support run taos with taosd integrated * feat: support invoke taos shell * feat: support invoke taos shell * feat: support invoke taos shell * chore: code optimization * chore: fix undefined reference problem os TD_ASTRA * chore: resolve compile problem for TD_ASTRA * chore: fix undefined reference problem os TD_ASTRA * chore: fix undefined reference problem os TD_ASTRA * chore: fix undefined reference problem os TD_ASTRA * chore: fix undefined reference problem os TD_ASTRA * chore: fix undefined reference problem os TD_ASTRA * chore: fix undefined reference problem os TD_ASTRA * chore: fix undefined reference problem os TD_ASTRA * chore: fix undefined reference problem os TD_ASTRA * chore: fix undefined reference problem os TD_ASTRA * chore: fix undefined reference problem os TD_ASTRA * chore: fix undefined reference problem os TD_ASTRA * chore: fix undefined reference problem os TD_ASTRA * chore: fix undefined reference problem os TD_ASTRA * chore: fix undefined reference problem os TD_ASTRA * chore: fix undefined reference problem os TD_ASTRA * chore: fix undefined reference problem os TD_ASTRA * chore: fix undefined reference problem os TD_ASTRA * chore: fix undefined reference problem os TD_ASTRA * chore: fix getpid * chore: fix typo * chore: set stack size and ajust min pack size for TD_ASTRA * chore: fix pthread create parameters * chore: chmod adapt for TD_ASTRA * chore: fix trans compile problem * chore: adapt chmod for TD_ASTRA * chore: byte alignment for TD_ASTRA * chore: more code for adaption of TD_ASTRA * chore: more code for adaption of TD_ASTRA * chore: more code for adaption of TD_ASTRA * chore: byte alignment for TD_ASTRA * chore: conditional compile option * chore: adapt for TD_ASTRA * chore: adjust taosPId and msvcregex for TD_ASTRA * chore: log dir separator for wal build name * chore: fix type of pointer parameter * chore: fix compile problem of tsdbGetS3Size * enh: get last ver from wal log for TD_ASTRA * enh: refact wal meta ver * enh: refact wal meta ver * fix: typo of taosUcs4Compare * enh: process return value of CI * chore: more code for TD_ASTRA adaption * chore: return value of taosCloseFile in walMeta.c * chore: fix compile problem * chore: fix compile problem of TD_ASTRA * fix: update macro for tq and stream task * chore: code optimization for TD_ASTRA * chore: restore create log and init cfg interface * chore: restore strncasecmp and strcasecmp * fix: adjust the field position of SDataBlockInfo * fix: pragma pack min size * fix: pragma pack min size * chore: more code for TD_ASTRA adaption * fix: type of parameters * chore: adapt strncasecmp and strcasecmp for TD_ASTRA * chore: restore interface of init log * enh: pack push optimization * fix: taos init cfg * add astra support * fix: fetch the value of suid * chore: switch of build with udf * add temp code * chore: more code for TD_ASTRA adaption * chore: add macro ERRNO to replace errno * chore: bytes align for TD_ASTRA * fix: remove obsolete codes * enh: support USE_UDF macro * fix compile error * fix: resolve redefinition problem * fix: compile problem of log.cpp * fix: compile problem of osTimezone * fix: resolve compile problem of udf * fix: pragma definition on windows * fix: ucs4 and stpncpy for TD_ASTRA * fix: memory align problem for TD_ASTRA * enh: solve memory leak for TD_ASTRA_RPC * fix: compile problem of taosSetInt64Aligned * fix: restore mndSubscribe.c * fix: scalar for udf * chore: code adaption for TD_ASTRA * chore: code optimization for TD_ASTRA * fix: typo of add definition * fix: typo of macro in tudf.h * chore: remove void to make CI pass * enh: move macro from cmake.platform to cmake.options * enh: byte align for hash node and error code * chore: restore the size for lru cache * enh: restore some code about pack push * chore: restore the pack push in tmsg.h * fix: add macro of pack pop for windows --------- Co-authored-by: yihaoDeng <luomoxyz@126.com>
2025-03-14 05:32:13 +00:00
#ifdef USE_S3
static int32_t tsdbReadFileBlock(STsdbFD *pFD, int64_t offset, int64_t size, bool check, uint8_t **ppBlock) {
int32_t code = 0;
2024-07-18 09:17:02 +00:00
int32_t lino;
SVnodeCfg *pCfg = &pFD->pTsdb->pVnode->config;
int64_t chunksize = (int64_t)pCfg->tsdbPageSize * pCfg->s3ChunkSize;
int64_t cOffset = offset % chunksize;
int64_t n = 0;
2024-07-18 09:17:02 +00:00
char *buf = NULL;
char *object_name = taosDirEntryBaseName(pFD->path);
char object_name_prefix[TSDB_FILENAME_LEN];
int32_t node_id = vnodeNodeId(pFD->pTsdb->pVnode);
snprintf(object_name_prefix, TSDB_FQDN_LEN, "%d/%s", node_id, object_name);
char *dot = strrchr(object_name_prefix, '.');
if (!dot) {
tsdbError("unexpected path: %s", object_name_prefix);
2024-07-18 09:17:02 +00:00
TSDB_CHECK_CODE(code = TAOS_SYSTEM_ERROR(ENOENT), lino, _exit);
}
2024-07-18 09:17:02 +00:00
buf = taosMemoryCalloc(1, size);
if (buf == NULL) {
TSDB_CHECK_CODE(code = terrno, lino, _exit);
2024-07-18 09:17:02 +00:00
}
for (int32_t chunkno = offset / chunksize + 1; n < size; ++chunkno) {
int64_t nRead = TMIN(chunksize - cOffset, size - n);
if (chunkno >= pFD->lcn) {
// read last chunk
int64_t ret = taosLSeekFile(pFD->pFD, chunksize * (chunkno - pFD->lcn) + cOffset, SEEK_SET);
if (ret < 0) {
2024-09-10 06:55:14 +00:00
TSDB_CHECK_CODE(code = terrno, lino, _exit);
}
ret = taosReadFile(pFD->pFD, buf + n, nRead);
if (ret < 0) {
2024-09-10 03:29:50 +00:00
TSDB_CHECK_CODE(code = terrno, lino, _exit);
} else if (ret < nRead) {
2024-07-18 09:17:02 +00:00
TSDB_CHECK_CODE(code = TSDB_CODE_FILE_CORRUPTED, lino, _exit);
}
} else {
uint8_t *pBlock = NULL;
snprintf(dot + 1, TSDB_FQDN_LEN - (dot + 1 - object_name_prefix), "%d.data", chunkno);
code = tcsGetObjectBlock(object_name_prefix, cOffset, nRead, check, &pBlock);
2024-07-18 09:17:02 +00:00
TSDB_CHECK_CODE(code, lino, _exit);
memcpy(buf + n, pBlock, nRead);
taosMemoryFree(pBlock);
}
n += nRead;
cOffset = 0;
}
_exit:
2024-07-18 09:17:02 +00:00
if (code) {
TSDB_ERROR_LOG(TD_VID(pFD->pTsdb->pVnode), lino, code);
taosMemoryFree(buf);
} else {
*ppBlock = (uint8_t *)buf;
}
return code;
}
feat: support customized taos/taosd (#29736) * feat: support TDAcoreOS * chore: cmake options for TD_ACORE * chore: disable lemon for TD_ACORE * chore: add lzma2 and msvcregex * chore: cmake for lzma2 * chore: adapt for TD_ACORE * chore: adapt strcasecmp for TD_ACORE * chore: adapt for geos/threadName * chore: build adapt for TD_ACORE * chore: build adapt for TD_ACORE * chore: build adapt for TD_ACORE * chore: build adapt for TD_ACORE * chore: build adapt for TD_ACORE termio * chore: refact transComm.h for TD_ACORE * chore: refact transportInt.h for TD_ACORE * chore: refact trans.c for TD_ACORE * chore: refact trpc.h for TD_ACORE * chore: refact transCli.c/transComm.c/transSvr.c for TD_ACORE * chore: refact uv.h for TD_ACORE * chore: refact geosWrapper.h for TD_ACORE * chore: refact token/builtins/udf for TD_ACORE * chore: refact rocks for TD_ACORE * chore: refact tsdbCache.c for TD_ACORE, use LRU cache for last/last_row, not use rocksdb * chore: refact FAIL to _ERR to solve conflicts for TD_ACORE * chore: restore lemon.c/lempar.c * chore: support build lemon for TD_ACORE * chore: refact trpc and siginfo_t for TD_ACORE * chore: refact timezone for TD_ACORE * chore: refact lz4 for TD_ACORE * chore: refact TD_ACORE to make compile pass * chore: code optimization for TD_ASTRA * feat: support run taos with taosd integrated * feat: support invoke taos shell * feat: support invoke taos shell * feat: support invoke taos shell * chore: code optimization * chore: fix undefined reference problem os TD_ASTRA * chore: resolve compile problem for TD_ASTRA * chore: fix undefined reference problem os TD_ASTRA * chore: fix undefined reference problem os TD_ASTRA * chore: fix undefined reference problem os TD_ASTRA * chore: fix undefined reference problem os TD_ASTRA * chore: fix undefined reference problem os TD_ASTRA * chore: fix undefined reference problem os TD_ASTRA * chore: fix undefined reference problem os TD_ASTRA * chore: fix undefined reference problem os TD_ASTRA * chore: fix undefined reference problem os TD_ASTRA * chore: fix undefined reference problem os TD_ASTRA * chore: fix undefined reference problem os TD_ASTRA * chore: fix undefined reference problem os TD_ASTRA * chore: fix undefined reference problem os TD_ASTRA * chore: fix undefined reference problem os TD_ASTRA * chore: fix undefined reference problem os TD_ASTRA * chore: fix undefined reference problem os TD_ASTRA * chore: fix undefined reference problem os TD_ASTRA * chore: fix undefined reference problem os TD_ASTRA * chore: fix getpid * chore: fix typo * chore: set stack size and ajust min pack size for TD_ASTRA * chore: fix pthread create parameters * chore: chmod adapt for TD_ASTRA * chore: fix trans compile problem * chore: adapt chmod for TD_ASTRA * chore: byte alignment for TD_ASTRA * chore: more code for adaption of TD_ASTRA * chore: more code for adaption of TD_ASTRA * chore: more code for adaption of TD_ASTRA * chore: byte alignment for TD_ASTRA * chore: conditional compile option * chore: adapt for TD_ASTRA * chore: adjust taosPId and msvcregex for TD_ASTRA * chore: log dir separator for wal build name * chore: fix type of pointer parameter * chore: fix compile problem of tsdbGetS3Size * enh: get last ver from wal log for TD_ASTRA * enh: refact wal meta ver * enh: refact wal meta ver * fix: typo of taosUcs4Compare * enh: process return value of CI * chore: more code for TD_ASTRA adaption * chore: return value of taosCloseFile in walMeta.c * chore: fix compile problem * chore: fix compile problem of TD_ASTRA * fix: update macro for tq and stream task * chore: code optimization for TD_ASTRA * chore: restore create log and init cfg interface * chore: restore strncasecmp and strcasecmp * fix: adjust the field position of SDataBlockInfo * fix: pragma pack min size * fix: pragma pack min size * chore: more code for TD_ASTRA adaption * fix: type of parameters * chore: adapt strncasecmp and strcasecmp for TD_ASTRA * chore: restore interface of init log * enh: pack push optimization * fix: taos init cfg * add astra support * fix: fetch the value of suid * chore: switch of build with udf * add temp code * chore: more code for TD_ASTRA adaption * chore: add macro ERRNO to replace errno * chore: bytes align for TD_ASTRA * fix: remove obsolete codes * enh: support USE_UDF macro * fix compile error * fix: resolve redefinition problem * fix: compile problem of log.cpp * fix: compile problem of osTimezone * fix: resolve compile problem of udf * fix: pragma definition on windows * fix: ucs4 and stpncpy for TD_ASTRA * fix: memory align problem for TD_ASTRA * enh: solve memory leak for TD_ASTRA_RPC * fix: compile problem of taosSetInt64Aligned * fix: restore mndSubscribe.c * fix: scalar for udf * chore: code adaption for TD_ASTRA * chore: code optimization for TD_ASTRA * fix: typo of add definition * fix: typo of macro in tudf.h * chore: remove void to make CI pass * enh: move macro from cmake.platform to cmake.options * enh: byte align for hash node and error code * chore: restore the size for lru cache * enh: restore some code about pack push * chore: restore the pack push in tmsg.h * fix: add macro of pack pop for windows --------- Co-authored-by: yihaoDeng <luomoxyz@126.com>
2025-03-14 05:32:13 +00:00
#endif
static int32_t tsdbReadFileS3(STsdbFD *pFD, int64_t offset, uint8_t *pBuf, int64_t size, int64_t szHint) {
feat: support customized taos/taosd (#29736) * feat: support TDAcoreOS * chore: cmake options for TD_ACORE * chore: disable lemon for TD_ACORE * chore: add lzma2 and msvcregex * chore: cmake for lzma2 * chore: adapt for TD_ACORE * chore: adapt strcasecmp for TD_ACORE * chore: adapt for geos/threadName * chore: build adapt for TD_ACORE * chore: build adapt for TD_ACORE * chore: build adapt for TD_ACORE * chore: build adapt for TD_ACORE * chore: build adapt for TD_ACORE termio * chore: refact transComm.h for TD_ACORE * chore: refact transportInt.h for TD_ACORE * chore: refact trans.c for TD_ACORE * chore: refact trpc.h for TD_ACORE * chore: refact transCli.c/transComm.c/transSvr.c for TD_ACORE * chore: refact uv.h for TD_ACORE * chore: refact geosWrapper.h for TD_ACORE * chore: refact token/builtins/udf for TD_ACORE * chore: refact rocks for TD_ACORE * chore: refact tsdbCache.c for TD_ACORE, use LRU cache for last/last_row, not use rocksdb * chore: refact FAIL to _ERR to solve conflicts for TD_ACORE * chore: restore lemon.c/lempar.c * chore: support build lemon for TD_ACORE * chore: refact trpc and siginfo_t for TD_ACORE * chore: refact timezone for TD_ACORE * chore: refact lz4 for TD_ACORE * chore: refact TD_ACORE to make compile pass * chore: code optimization for TD_ASTRA * feat: support run taos with taosd integrated * feat: support invoke taos shell * feat: support invoke taos shell * feat: support invoke taos shell * chore: code optimization * chore: fix undefined reference problem os TD_ASTRA * chore: resolve compile problem for TD_ASTRA * chore: fix undefined reference problem os TD_ASTRA * chore: fix undefined reference problem os TD_ASTRA * chore: fix undefined reference problem os TD_ASTRA * chore: fix undefined reference problem os TD_ASTRA * chore: fix undefined reference problem os TD_ASTRA * chore: fix undefined reference problem os TD_ASTRA * chore: fix undefined reference problem os TD_ASTRA * chore: fix undefined reference problem os TD_ASTRA * chore: fix undefined reference problem os TD_ASTRA * chore: fix undefined reference problem os TD_ASTRA * chore: fix undefined reference problem os TD_ASTRA * chore: fix undefined reference problem os TD_ASTRA * chore: fix undefined reference problem os TD_ASTRA * chore: fix undefined reference problem os TD_ASTRA * chore: fix undefined reference problem os TD_ASTRA * chore: fix undefined reference problem os TD_ASTRA * chore: fix undefined reference problem os TD_ASTRA * chore: fix undefined reference problem os TD_ASTRA * chore: fix getpid * chore: fix typo * chore: set stack size and ajust min pack size for TD_ASTRA * chore: fix pthread create parameters * chore: chmod adapt for TD_ASTRA * chore: fix trans compile problem * chore: adapt chmod for TD_ASTRA * chore: byte alignment for TD_ASTRA * chore: more code for adaption of TD_ASTRA * chore: more code for adaption of TD_ASTRA * chore: more code for adaption of TD_ASTRA * chore: byte alignment for TD_ASTRA * chore: conditional compile option * chore: adapt for TD_ASTRA * chore: adjust taosPId and msvcregex for TD_ASTRA * chore: log dir separator for wal build name * chore: fix type of pointer parameter * chore: fix compile problem of tsdbGetS3Size * enh: get last ver from wal log for TD_ASTRA * enh: refact wal meta ver * enh: refact wal meta ver * fix: typo of taosUcs4Compare * enh: process return value of CI * chore: more code for TD_ASTRA adaption * chore: return value of taosCloseFile in walMeta.c * chore: fix compile problem * chore: fix compile problem of TD_ASTRA * fix: update macro for tq and stream task * chore: code optimization for TD_ASTRA * chore: restore create log and init cfg interface * chore: restore strncasecmp and strcasecmp * fix: adjust the field position of SDataBlockInfo * fix: pragma pack min size * fix: pragma pack min size * chore: more code for TD_ASTRA adaption * fix: type of parameters * chore: adapt strncasecmp and strcasecmp for TD_ASTRA * chore: restore interface of init log * enh: pack push optimization * fix: taos init cfg * add astra support * fix: fetch the value of suid * chore: switch of build with udf * add temp code * chore: more code for TD_ASTRA adaption * chore: add macro ERRNO to replace errno * chore: bytes align for TD_ASTRA * fix: remove obsolete codes * enh: support USE_UDF macro * fix compile error * fix: resolve redefinition problem * fix: compile problem of log.cpp * fix: compile problem of osTimezone * fix: resolve compile problem of udf * fix: pragma definition on windows * fix: ucs4 and stpncpy for TD_ASTRA * fix: memory align problem for TD_ASTRA * enh: solve memory leak for TD_ASTRA_RPC * fix: compile problem of taosSetInt64Aligned * fix: restore mndSubscribe.c * fix: scalar for udf * chore: code adaption for TD_ASTRA * chore: code optimization for TD_ASTRA * fix: typo of add definition * fix: typo of macro in tudf.h * chore: remove void to make CI pass * enh: move macro from cmake.platform to cmake.options * enh: byte align for hash node and error code * chore: restore the size for lru cache * enh: restore some code about pack push * chore: restore the pack push in tmsg.h * fix: add macro of pack pop for windows --------- Co-authored-by: yihaoDeng <luomoxyz@126.com>
2025-03-14 05:32:13 +00:00
#ifdef USE_S3
int32_t code = 0;
2024-07-18 09:17:02 +00:00
int32_t lino;
int64_t n = 0;
int32_t szPgCont = PAGE_CONTENT_SIZE(pFD->szPage);
int64_t fOffset = LOGIC_TO_FILE_OFFSET(offset, pFD->szPage);
int64_t pgno = OFFSET_PGNO(fOffset, pFD->szPage);
int64_t bOffset = fOffset % pFD->szPage;
2024-08-20 06:47:05 +00:00
if (bOffset >= szPgCont) {
TSDB_CHECK_CODE(code = TSDB_CODE_INVALID_PARA, lino, _exit);
}
// 1, find pgnoStart & pgnoEnd to fetch from s3, if all pgs are local, no need to fetch
// 2, fetch pgnoStart ~ pgnoEnd from s3
// 3, store pgs to pcache & last pg to pFD->pBuf
// 4, deliver pgs to [pBuf, pBuf + size)
while (n < size) {
if (pFD->pgno != pgno) {
LRUHandle *handle = NULL;
code = tsdbCacheGetPageS3(pFD->pTsdb->pgCache, pFD, pgno, &handle);
if (code != TSDB_CODE_SUCCESS) {
if (handle) {
2024-09-24 10:04:58 +00:00
tsdbCacheRelease(pFD->pTsdb->pgCache, handle);
}
2024-07-18 09:17:02 +00:00
TSDB_CHECK_CODE(code, lino, _exit);
}
if (!handle) {
break;
}
uint8_t *pPage = (uint8_t *)taosLRUCacheValue(pFD->pTsdb->pgCache, handle);
memcpy(pFD->pBuf, pPage, pFD->szPage);
2024-09-24 10:04:58 +00:00
tsdbCacheRelease(pFD->pTsdb->pgCache, handle);
// check
if (pgno > 1 && !taosCheckChecksumWhole(pFD->pBuf, pFD->szPage)) {
2024-07-18 09:17:02 +00:00
TSDB_CHECK_CODE(code = TSDB_CODE_FILE_CORRUPTED, lino, _exit);
}
pFD->pgno = pgno;
}
int64_t nRead = TMIN(szPgCont - bOffset, size - n);
memcpy(pBuf + n, pFD->pBuf + bOffset, nRead);
n += nRead;
++pgno;
bOffset = 0;
}
if (n < size) {
// 2, retrieve pgs from s3
uint8_t *pBlock = NULL;
int64_t retrieve_offset = PAGE_OFFSET(pgno, pFD->szPage);
int64_t pgnoEnd = pgno - 1 + (bOffset + size - n + szPgCont - 1) / szPgCont;
if (szHint > 0) {
pgnoEnd = pgno - 1 + (bOffset + szHint - n + szPgCont - 1) / szPgCont;
}
int64_t retrieve_size = (pgnoEnd - pgno + 1) * pFD->szPage;
2024-07-18 09:17:02 +00:00
code = tsdbReadFileBlock(pFD, retrieve_offset, retrieve_size, 1, &pBlock);
2024-07-18 09:17:02 +00:00
TSDB_CHECK_CODE(code, lino, _exit);
// 3, Store Pages in Cache
int nPage = pgnoEnd - pgno + 1;
for (int i = 0; i < nPage; ++i) {
if (pFD->szFile != pgno) { // DONOT cache last volatile page
2024-09-25 08:52:17 +00:00
tsdbCacheSetPageS3(pFD->pTsdb->pgCache, pFD, pgno, pBlock + i * pFD->szPage);
}
if (szHint > 0 && n >= size) {
++pgno;
continue;
}
memcpy(pFD->pBuf, pBlock + i * pFD->szPage, pFD->szPage);
// check
if (pgno > 1 && !taosCheckChecksumWhole(pFD->pBuf, pFD->szPage)) {
2024-07-18 09:17:02 +00:00
TSDB_CHECK_CODE(code = TSDB_CODE_FILE_CORRUPTED, lino, _exit);
}
pFD->pgno = pgno;
int64_t nRead = TMIN(szPgCont - bOffset, size - n);
memcpy(pBuf + n, pFD->pBuf + bOffset, nRead);
n += nRead;
++pgno;
bOffset = 0;
}
taosMemoryFree(pBlock);
}
_exit:
2024-07-18 09:17:02 +00:00
if (code) {
TSDB_ERROR_LOG(TD_VID(pFD->pTsdb->pVnode), lino, code);
}
return code;
feat: support customized taos/taosd (#29736) * feat: support TDAcoreOS * chore: cmake options for TD_ACORE * chore: disable lemon for TD_ACORE * chore: add lzma2 and msvcregex * chore: cmake for lzma2 * chore: adapt for TD_ACORE * chore: adapt strcasecmp for TD_ACORE * chore: adapt for geos/threadName * chore: build adapt for TD_ACORE * chore: build adapt for TD_ACORE * chore: build adapt for TD_ACORE * chore: build adapt for TD_ACORE * chore: build adapt for TD_ACORE termio * chore: refact transComm.h for TD_ACORE * chore: refact transportInt.h for TD_ACORE * chore: refact trans.c for TD_ACORE * chore: refact trpc.h for TD_ACORE * chore: refact transCli.c/transComm.c/transSvr.c for TD_ACORE * chore: refact uv.h for TD_ACORE * chore: refact geosWrapper.h for TD_ACORE * chore: refact token/builtins/udf for TD_ACORE * chore: refact rocks for TD_ACORE * chore: refact tsdbCache.c for TD_ACORE, use LRU cache for last/last_row, not use rocksdb * chore: refact FAIL to _ERR to solve conflicts for TD_ACORE * chore: restore lemon.c/lempar.c * chore: support build lemon for TD_ACORE * chore: refact trpc and siginfo_t for TD_ACORE * chore: refact timezone for TD_ACORE * chore: refact lz4 for TD_ACORE * chore: refact TD_ACORE to make compile pass * chore: code optimization for TD_ASTRA * feat: support run taos with taosd integrated * feat: support invoke taos shell * feat: support invoke taos shell * feat: support invoke taos shell * chore: code optimization * chore: fix undefined reference problem os TD_ASTRA * chore: resolve compile problem for TD_ASTRA * chore: fix undefined reference problem os TD_ASTRA * chore: fix undefined reference problem os TD_ASTRA * chore: fix undefined reference problem os TD_ASTRA * chore: fix undefined reference problem os TD_ASTRA * chore: fix undefined reference problem os TD_ASTRA * chore: fix undefined reference problem os TD_ASTRA * chore: fix undefined reference problem os TD_ASTRA * chore: fix undefined reference problem os TD_ASTRA * chore: fix undefined reference problem os TD_ASTRA * chore: fix undefined reference problem os TD_ASTRA * chore: fix undefined reference problem os TD_ASTRA * chore: fix undefined reference problem os TD_ASTRA * chore: fix undefined reference problem os TD_ASTRA * chore: fix undefined reference problem os TD_ASTRA * chore: fix undefined reference problem os TD_ASTRA * chore: fix undefined reference problem os TD_ASTRA * chore: fix undefined reference problem os TD_ASTRA * chore: fix undefined reference problem os TD_ASTRA * chore: fix getpid * chore: fix typo * chore: set stack size and ajust min pack size for TD_ASTRA * chore: fix pthread create parameters * chore: chmod adapt for TD_ASTRA * chore: fix trans compile problem * chore: adapt chmod for TD_ASTRA * chore: byte alignment for TD_ASTRA * chore: more code for adaption of TD_ASTRA * chore: more code for adaption of TD_ASTRA * chore: more code for adaption of TD_ASTRA * chore: byte alignment for TD_ASTRA * chore: conditional compile option * chore: adapt for TD_ASTRA * chore: adjust taosPId and msvcregex for TD_ASTRA * chore: log dir separator for wal build name * chore: fix type of pointer parameter * chore: fix compile problem of tsdbGetS3Size * enh: get last ver from wal log for TD_ASTRA * enh: refact wal meta ver * enh: refact wal meta ver * fix: typo of taosUcs4Compare * enh: process return value of CI * chore: more code for TD_ASTRA adaption * chore: return value of taosCloseFile in walMeta.c * chore: fix compile problem * chore: fix compile problem of TD_ASTRA * fix: update macro for tq and stream task * chore: code optimization for TD_ASTRA * chore: restore create log and init cfg interface * chore: restore strncasecmp and strcasecmp * fix: adjust the field position of SDataBlockInfo * fix: pragma pack min size * fix: pragma pack min size * chore: more code for TD_ASTRA adaption * fix: type of parameters * chore: adapt strncasecmp and strcasecmp for TD_ASTRA * chore: restore interface of init log * enh: pack push optimization * fix: taos init cfg * add astra support * fix: fetch the value of suid * chore: switch of build with udf * add temp code * chore: more code for TD_ASTRA adaption * chore: add macro ERRNO to replace errno * chore: bytes align for TD_ASTRA * fix: remove obsolete codes * enh: support USE_UDF macro * fix compile error * fix: resolve redefinition problem * fix: compile problem of log.cpp * fix: compile problem of osTimezone * fix: resolve compile problem of udf * fix: pragma definition on windows * fix: ucs4 and stpncpy for TD_ASTRA * fix: memory align problem for TD_ASTRA * enh: solve memory leak for TD_ASTRA_RPC * fix: compile problem of taosSetInt64Aligned * fix: restore mndSubscribe.c * fix: scalar for udf * chore: code adaption for TD_ASTRA * chore: code optimization for TD_ASTRA * fix: typo of add definition * fix: typo of macro in tudf.h * chore: remove void to make CI pass * enh: move macro from cmake.platform to cmake.options * enh: byte align for hash node and error code * chore: restore the size for lru cache * enh: restore some code about pack push * chore: restore the pack push in tmsg.h * fix: add macro of pack pop for windows --------- Co-authored-by: yihaoDeng <luomoxyz@126.com>
2025-03-14 05:32:13 +00:00
#else
return TSDB_CODE_INTERNAL_ERROR;
#endif
}
int32_t tsdbReadFile(STsdbFD *pFD, int64_t offset, uint8_t *pBuf, int64_t size, int64_t szHint,
int32_t encryptAlgorithm, char *encryptKey) {
int32_t code = 0;
2024-07-18 09:17:02 +00:00
int32_t lino;
if (!pFD->pFD) {
code = tsdbOpenFileImpl(pFD);
2024-07-18 09:17:02 +00:00
TSDB_CHECK_CODE(code, lino, _exit);
}
if (pFD->s3File && pFD->lcn > 1 /* && tsS3BlockSize < 0*/) {
2024-07-18 09:17:02 +00:00
code = tsdbReadFileS3(pFD, offset, pBuf, size, szHint);
TSDB_CHECK_CODE(code, lino, _exit);
} else {
2024-07-18 09:17:02 +00:00
code = tsdbReadFileImp(pFD, offset, pBuf, size, encryptAlgorithm, encryptKey);
TSDB_CHECK_CODE(code, lino, _exit);
}
_exit:
2024-07-18 09:17:02 +00:00
if (code) {
TSDB_ERROR_LOG(TD_VID(pFD->pTsdb->pVnode), lino, code);
}
return code;
}
2024-04-15 07:12:32 +00:00
int32_t tsdbReadFileToBuffer(STsdbFD *pFD, int64_t offset, int64_t size, SBuffer *buffer, int64_t szHint,
int32_t encryptAlgorithm, char *encryptKey) {
2024-03-04 11:25:20 +00:00
int32_t code;
2024-07-18 09:17:02 +00:00
int32_t lino;
2024-03-04 11:25:20 +00:00
code = tBufferEnsureCapacity(buffer, buffer->size + size);
2024-07-18 09:17:02 +00:00
TSDB_CHECK_CODE(code, lino, _exit);
code = tsdbReadFile(pFD, offset, (uint8_t *)tBufferGetDataEnd(buffer), size, szHint, encryptAlgorithm, encryptKey);
2024-07-18 09:17:02 +00:00
TSDB_CHECK_CODE(code, lino, _exit);
2024-03-04 11:25:20 +00:00
buffer->size += size;
2024-07-18 09:17:02 +00:00
_exit:
if (code) {
TSDB_ERROR_LOG(TD_VID(pFD->pTsdb->pVnode), lino, code);
}
2024-03-04 11:25:20 +00:00
return code;
}
int32_t tsdbFsyncFile(STsdbFD *pFD, int32_t encryptAlgorithm, char *encryptKey) {
2022-09-04 06:31:32 +00:00
int32_t code = 0;
2024-07-18 09:17:02 +00:00
int32_t lino;
2024-04-15 08:24:40 +00:00
code = tsdbWriteFilePage(pFD, encryptAlgorithm, encryptKey);
2024-07-18 09:17:02 +00:00
TSDB_CHECK_CODE(code, lino, _exit);
2022-09-04 11:59:21 +00:00
if (taosFsyncFile(pFD->pFD) < 0) {
feat: support customized taos/taosd (#29736) * feat: support TDAcoreOS * chore: cmake options for TD_ACORE * chore: disable lemon for TD_ACORE * chore: add lzma2 and msvcregex * chore: cmake for lzma2 * chore: adapt for TD_ACORE * chore: adapt strcasecmp for TD_ACORE * chore: adapt for geos/threadName * chore: build adapt for TD_ACORE * chore: build adapt for TD_ACORE * chore: build adapt for TD_ACORE * chore: build adapt for TD_ACORE * chore: build adapt for TD_ACORE termio * chore: refact transComm.h for TD_ACORE * chore: refact transportInt.h for TD_ACORE * chore: refact trans.c for TD_ACORE * chore: refact trpc.h for TD_ACORE * chore: refact transCli.c/transComm.c/transSvr.c for TD_ACORE * chore: refact uv.h for TD_ACORE * chore: refact geosWrapper.h for TD_ACORE * chore: refact token/builtins/udf for TD_ACORE * chore: refact rocks for TD_ACORE * chore: refact tsdbCache.c for TD_ACORE, use LRU cache for last/last_row, not use rocksdb * chore: refact FAIL to _ERR to solve conflicts for TD_ACORE * chore: restore lemon.c/lempar.c * chore: support build lemon for TD_ACORE * chore: refact trpc and siginfo_t for TD_ACORE * chore: refact timezone for TD_ACORE * chore: refact lz4 for TD_ACORE * chore: refact TD_ACORE to make compile pass * chore: code optimization for TD_ASTRA * feat: support run taos with taosd integrated * feat: support invoke taos shell * feat: support invoke taos shell * feat: support invoke taos shell * chore: code optimization * chore: fix undefined reference problem os TD_ASTRA * chore: resolve compile problem for TD_ASTRA * chore: fix undefined reference problem os TD_ASTRA * chore: fix undefined reference problem os TD_ASTRA * chore: fix undefined reference problem os TD_ASTRA * chore: fix undefined reference problem os TD_ASTRA * chore: fix undefined reference problem os TD_ASTRA * chore: fix undefined reference problem os TD_ASTRA * chore: fix undefined reference problem os TD_ASTRA * chore: fix undefined reference problem os TD_ASTRA * chore: fix undefined reference problem os TD_ASTRA * chore: fix undefined reference problem os TD_ASTRA * chore: fix undefined reference problem os TD_ASTRA * chore: fix undefined reference problem os TD_ASTRA * chore: fix undefined reference problem os TD_ASTRA * chore: fix undefined reference problem os TD_ASTRA * chore: fix undefined reference problem os TD_ASTRA * chore: fix undefined reference problem os TD_ASTRA * chore: fix undefined reference problem os TD_ASTRA * chore: fix undefined reference problem os TD_ASTRA * chore: fix getpid * chore: fix typo * chore: set stack size and ajust min pack size for TD_ASTRA * chore: fix pthread create parameters * chore: chmod adapt for TD_ASTRA * chore: fix trans compile problem * chore: adapt chmod for TD_ASTRA * chore: byte alignment for TD_ASTRA * chore: more code for adaption of TD_ASTRA * chore: more code for adaption of TD_ASTRA * chore: more code for adaption of TD_ASTRA * chore: byte alignment for TD_ASTRA * chore: conditional compile option * chore: adapt for TD_ASTRA * chore: adjust taosPId and msvcregex for TD_ASTRA * chore: log dir separator for wal build name * chore: fix type of pointer parameter * chore: fix compile problem of tsdbGetS3Size * enh: get last ver from wal log for TD_ASTRA * enh: refact wal meta ver * enh: refact wal meta ver * fix: typo of taosUcs4Compare * enh: process return value of CI * chore: more code for TD_ASTRA adaption * chore: return value of taosCloseFile in walMeta.c * chore: fix compile problem * chore: fix compile problem of TD_ASTRA * fix: update macro for tq and stream task * chore: code optimization for TD_ASTRA * chore: restore create log and init cfg interface * chore: restore strncasecmp and strcasecmp * fix: adjust the field position of SDataBlockInfo * fix: pragma pack min size * fix: pragma pack min size * chore: more code for TD_ASTRA adaption * fix: type of parameters * chore: adapt strncasecmp and strcasecmp for TD_ASTRA * chore: restore interface of init log * enh: pack push optimization * fix: taos init cfg * add astra support * fix: fetch the value of suid * chore: switch of build with udf * add temp code * chore: more code for TD_ASTRA adaption * chore: add macro ERRNO to replace errno * chore: bytes align for TD_ASTRA * fix: remove obsolete codes * enh: support USE_UDF macro * fix compile error * fix: resolve redefinition problem * fix: compile problem of log.cpp * fix: compile problem of osTimezone * fix: resolve compile problem of udf * fix: pragma definition on windows * fix: ucs4 and stpncpy for TD_ASTRA * fix: memory align problem for TD_ASTRA * enh: solve memory leak for TD_ASTRA_RPC * fix: compile problem of taosSetInt64Aligned * fix: restore mndSubscribe.c * fix: scalar for udf * chore: code adaption for TD_ASTRA * chore: code optimization for TD_ASTRA * fix: typo of add definition * fix: typo of macro in tudf.h * chore: remove void to make CI pass * enh: move macro from cmake.platform to cmake.options * enh: byte align for hash node and error code * chore: restore the size for lru cache * enh: restore some code about pack push * chore: restore the pack push in tmsg.h * fix: add macro of pack pop for windows --------- Co-authored-by: yihaoDeng <luomoxyz@126.com>
2025-03-14 05:32:13 +00:00
TSDB_CHECK_CODE(code = TAOS_SYSTEM_ERROR(ERRNO), lino, _exit);
2022-09-04 11:59:21 +00:00
}
_exit:
2024-07-18 09:17:02 +00:00
if (code) {
TSDB_ERROR_LOG(TD_VID(pFD->pTsdb->pVnode), lino, code);
}
2022-09-04 06:31:32 +00:00
return code;
}
2022-09-02 09:15:45 +00:00
// SDataFReader ====================================================
int32_t tsdbDataFReaderOpen(SDataFReader **ppReader, STsdb *pTsdb, SDFileSet *pSet) {
int32_t code = 0;
2022-10-15 03:20:37 +00:00
int32_t lino = 0;
SDataFReader *pReader = NULL;
2022-09-08 10:36:08 +00:00
int32_t szPage = pTsdb->pVnode->config.tsdbPageSize;
2022-09-02 09:15:45 +00:00
char fname[TSDB_FILENAME_LEN];
2022-07-21 06:27:32 +00:00
2022-09-02 09:15:45 +00:00
// alloc
pReader = (SDataFReader *)taosMemoryCalloc(1, sizeof(*pReader));
if (pReader == NULL) {
TSDB_CHECK_CODE(code = terrno, lino, _exit);
2022-07-21 06:27:32 +00:00
}
2022-09-02 09:15:45 +00:00
pReader->pTsdb = pTsdb;
pReader->pSet = pSet;
2022-07-21 06:27:32 +00:00
2022-09-02 09:15:45 +00:00
// head
tsdbHeadFileName(pTsdb, pSet->diskId, pSet->fid, pSet->pHeadF, fname);
code = tsdbOpenFile(fname, pTsdb, TD_FILE_READ, &pReader->pHeadFD, 0);
2022-10-15 03:20:37 +00:00
TSDB_CHECK_CODE(code, lino, _exit);
2022-06-20 08:06:34 +00:00
2022-09-02 09:15:45 +00:00
// data
tsdbDataFileName(pTsdb, pSet->diskId, pSet->fid, pSet->pDataF, fname);
code = tsdbOpenFile(fname, pTsdb, TD_FILE_READ, &pReader->pDataFD, 0);
2022-10-15 03:20:37 +00:00
TSDB_CHECK_CODE(code, lino, _exit);
2022-07-21 06:27:32 +00:00
2022-09-02 09:15:45 +00:00
// sma
tsdbSmaFileName(pTsdb, pSet->diskId, pSet->fid, pSet->pSmaF, fname);
code = tsdbOpenFile(fname, pTsdb, TD_FILE_READ, &pReader->pSmaFD, 0);
2022-10-15 03:20:37 +00:00
TSDB_CHECK_CODE(code, lino, _exit);
2022-06-20 08:06:34 +00:00
2022-09-05 09:31:41 +00:00
// stt
for (int32_t iStt = 0; iStt < pSet->nSttF; iStt++) {
tsdbSttFileName(pTsdb, pSet->diskId, pSet->fid, pSet->aSttF[iStt], fname);
code = tsdbOpenFile(fname, pTsdb, TD_FILE_READ, &pReader->aSttFD[iStt], 0);
2022-10-15 03:20:37 +00:00
TSDB_CHECK_CODE(code, lino, _exit);
2022-09-02 09:15:45 +00:00
}
2022-07-21 06:27:32 +00:00
2022-10-15 03:20:37 +00:00
_exit:
if (code) {
*ppReader = NULL;
2022-10-21 02:39:19 +00:00
tsdbError("vgId:%d, %s failed at line %d since %s", TD_VID(pTsdb->pVnode), __func__, lino, tstrerror(code));
2022-10-15 03:20:37 +00:00
if (pReader) {
for (int32_t iStt = 0; iStt < pSet->nSttF; iStt++) tsdbCloseFile(&pReader->aSttFD[iStt]);
tsdbCloseFile(&pReader->pSmaFD);
tsdbCloseFile(&pReader->pDataFD);
tsdbCloseFile(&pReader->pHeadFD);
taosMemoryFree(pReader);
}
} else {
*ppReader = pReader;
}
2022-09-02 09:15:45 +00:00
return code;
}
2024-09-11 02:56:40 +00:00
void tsdbDataFReaderClose(SDataFReader **ppReader) {
if (*ppReader == NULL) return;
2022-09-02 09:15:45 +00:00
// head
2022-09-04 06:31:32 +00:00
tsdbCloseFile(&(*ppReader)->pHeadFD);
2022-07-21 06:27:32 +00:00
2022-09-02 09:15:45 +00:00
// data
2022-09-04 06:31:32 +00:00
tsdbCloseFile(&(*ppReader)->pDataFD);
2022-06-20 08:06:34 +00:00
2022-09-02 09:15:45 +00:00
// sma
2022-09-04 06:31:32 +00:00
tsdbCloseFile(&(*ppReader)->pSmaFD);
2022-07-21 06:27:32 +00:00
2022-09-05 09:31:41 +00:00
// stt
for (int32_t iStt = 0; iStt < TSDB_STT_TRIGGER_ARRAY_SIZE; iStt++) {
2022-09-05 09:31:41 +00:00
if ((*ppReader)->aSttFD[iStt]) {
tsdbCloseFile(&(*ppReader)->aSttFD[iStt]);
2022-09-04 17:13:07 +00:00
}
2022-09-02 09:15:45 +00:00
}
for (int32_t iBuf = 0; iBuf < sizeof((*ppReader)->aBuf) / sizeof(uint8_t *); iBuf++) {
tFree((*ppReader)->aBuf[iBuf]);
2022-07-21 06:27:32 +00:00
}
2022-09-02 09:15:45 +00:00
taosMemoryFree(*ppReader);
*ppReader = NULL;
2022-06-14 13:19:46 +00:00
}
2022-09-02 09:15:45 +00:00
int32_t tsdbReadBlockIdx(SDataFReader *pReader, SArray *aBlockIdx) {
2022-09-04 10:18:01 +00:00
int32_t code = 0;
2024-07-18 09:17:02 +00:00
int32_t lino;
2022-09-04 10:18:01 +00:00
SHeadFile *pHeadFile = pReader->pSet->pHeadF;
int64_t offset = pHeadFile->offset;
int64_t size = pHeadFile->size - offset;
2022-06-30 06:02:47 +00:00
2022-09-02 09:15:45 +00:00
taosArrayClear(aBlockIdx);
2024-07-18 09:17:02 +00:00
if (size == 0) {
return code;
}
2022-06-15 07:41:14 +00:00
// alloc
2022-09-02 09:15:45 +00:00
code = tRealloc(&pReader->aBuf[0], size);
2024-07-18 09:17:02 +00:00
TSDB_CHECK_CODE(code, lino, _exit);
2022-06-15 07:41:14 +00:00
2022-09-02 09:15:45 +00:00
// read
2024-03-29 02:48:49 +00:00
int32_t encryptAlgorithm = pReader->pTsdb->pVnode->config.tsdbCfg.encryptAlgorithm;
char *encryptKey = pReader->pTsdb->pVnode->config.tsdbCfg.encryptKey;
2024-03-29 02:48:49 +00:00
code = tsdbReadFile(pReader->pHeadFD, offset, pReader->aBuf[0], size, 0, encryptAlgorithm, encryptKey);
2024-07-18 09:17:02 +00:00
TSDB_CHECK_CODE(code, lino, _exit);
2022-09-02 09:15:45 +00:00
// decode
2022-09-04 10:18:01 +00:00
int64_t n = 0;
2022-09-04 09:31:20 +00:00
while (n < size) {
2022-09-02 09:15:45 +00:00
SBlockIdx blockIdx;
n += tGetBlockIdx(pReader->aBuf[0] + n, &blockIdx);
if (taosArrayPush(aBlockIdx, &blockIdx) == NULL) {
2024-09-20 00:56:46 +00:00
TSDB_CHECK_CODE(code = terrno, lino, _exit);
2022-09-02 09:15:45 +00:00
}
2022-06-15 07:41:14 +00:00
}
2024-08-20 06:47:05 +00:00
if (n != size) {
TSDB_CHECK_CODE(code = TSDB_CODE_FILE_CORRUPTED, lino, _exit);
}
2022-06-15 07:41:14 +00:00
2024-07-18 09:17:02 +00:00
_exit:
if (code) {
TSDB_ERROR_LOG(TD_VID(pReader->pTsdb->pVnode), lino, code);
}
2022-06-14 13:19:46 +00:00
return code;
}
2022-09-05 09:31:41 +00:00
int32_t tsdbReadSttBlk(SDataFReader *pReader, int32_t iStt, SArray *aSttBlk) {
2022-09-04 10:18:01 +00:00
int32_t code = 0;
2024-07-18 09:17:02 +00:00
int32_t lino;
2022-09-05 09:31:41 +00:00
SSttFile *pSttFile = pReader->pSet->aSttF[iStt];
int64_t offset = pSttFile->offset;
int64_t size = pSttFile->size - offset;
2022-06-15 12:28:52 +00:00
2022-09-05 09:31:41 +00:00
taosArrayClear(aSttBlk);
2024-07-18 09:17:02 +00:00
if (size == 0) {
return 0;
}
2022-06-16 01:32:48 +00:00
// alloc
2022-09-02 09:15:45 +00:00
code = tRealloc(&pReader->aBuf[0], size);
2024-07-18 09:17:02 +00:00
TSDB_CHECK_CODE(code, lino, _exit);
2022-06-16 01:32:48 +00:00
2022-09-02 09:15:45 +00:00
// read
2024-03-29 02:48:49 +00:00
int32_t encryptAlgorithm = pReader->pTsdb->pVnode->config.tsdbCfg.encryptAlgorithm;
char *encryptKey = pReader->pTsdb->pVnode->config.tsdbCfg.encryptKey;
2024-03-29 02:48:49 +00:00
code = tsdbReadFile(pReader->aSttFD[iStt], offset, pReader->aBuf[0], size, 0, encryptAlgorithm, encryptKey);
2024-07-18 09:17:02 +00:00
TSDB_CHECK_CODE(code, lino, _exit);
2022-06-16 01:32:48 +00:00
2022-09-02 09:15:45 +00:00
// decode
2022-09-04 10:18:01 +00:00
int64_t n = 0;
2022-09-04 09:31:20 +00:00
while (n < size) {
2022-09-05 09:31:41 +00:00
SSttBlk sttBlk;
n += tGetSttBlk(pReader->aBuf[0] + n, &sttBlk);
2022-09-02 09:15:45 +00:00
2022-09-05 09:31:41 +00:00
if (taosArrayPush(aSttBlk, &sttBlk) == NULL) {
2024-09-20 00:56:46 +00:00
TSDB_CHECK_CODE(code = terrno, lino, _exit);
2022-09-02 09:15:45 +00:00
}
}
2024-08-20 06:47:05 +00:00
if (n != size) {
TSDB_CHECK_CODE(code = TSDB_CODE_FILE_CORRUPTED, lino, _exit);
}
2022-09-02 09:15:45 +00:00
2024-07-18 09:17:02 +00:00
_exit:
if (code) {
TSDB_ERROR_LOG(TD_VID(pReader->pTsdb->pVnode), lino, code);
}
2022-06-14 13:19:46 +00:00
return code;
}
2022-09-07 09:06:42 +00:00
int32_t tsdbReadDataBlk(SDataFReader *pReader, SBlockIdx *pBlockIdx, SMapData *mDataBlk) {
2022-09-02 09:15:45 +00:00
int32_t code = 0;
2024-07-18 09:17:02 +00:00
int32_t lino;
2022-09-02 09:15:45 +00:00
int64_t offset = pBlockIdx->offset;
int64_t size = pBlockIdx->size;
2022-08-01 10:03:00 +00:00
// alloc
2022-09-02 09:15:45 +00:00
code = tRealloc(&pReader->aBuf[0], size);
2024-07-18 09:17:02 +00:00
TSDB_CHECK_CODE(code, lino, _exit);
2022-08-01 10:03:00 +00:00
2022-09-02 09:15:45 +00:00
// read
2024-03-29 02:48:49 +00:00
int32_t encryptAlgorithm = pReader->pTsdb->pVnode->config.tsdbCfg.encryptAlgorithm;
char *encryptKey = pReader->pTsdb->pVnode->config.tsdbCfg.encryptKey;
2024-03-29 02:48:49 +00:00
code = tsdbReadFile(pReader->pHeadFD, offset, pReader->aBuf[0], size, 0, encryptAlgorithm, encryptKey);
2024-07-18 09:17:02 +00:00
TSDB_CHECK_CODE(code, lino, _exit);
2022-08-01 10:03:00 +00:00
2022-09-02 09:15:45 +00:00
// decode
2024-07-19 05:19:01 +00:00
int32_t n;
code = tGetMapData(pReader->aBuf[0], mDataBlk, &n);
2024-07-19 08:07:09 +00:00
if (code) goto _exit;
2024-08-20 06:47:05 +00:00
if (n != size) {
TSDB_CHECK_CODE(code = TSDB_CODE_FILE_CORRUPTED, lino, _exit);
}
2022-06-29 03:34:55 +00:00
2024-07-18 09:17:02 +00:00
_exit:
if (code) {
TSDB_ERROR_LOG(TD_VID(pReader->pTsdb->pVnode), lino, code);
}
2022-09-02 09:15:45 +00:00
return code;
2022-07-01 15:10:46 +00:00
}
2022-06-27 15:42:55 +00:00
2022-09-02 09:04:49 +00:00
// SDelFReader ====================================================
struct SDelFReader {
2022-09-04 12:28:12 +00:00
STsdb *pTsdb;
SDelFile fDel;
STsdbFD *pReadH;
2022-09-02 09:04:49 +00:00
uint8_t *aBuf[1];
};
2022-09-02 05:55:05 +00:00
2022-09-02 09:04:49 +00:00
int32_t tsdbDelFReaderOpen(SDelFReader **ppReader, SDelFile *pFile, STsdb *pTsdb) {
int32_t code = 0;
2022-10-14 05:34:25 +00:00
int32_t lino = 0;
2022-09-02 09:04:49 +00:00
char fname[TSDB_FILENAME_LEN];
2022-10-14 05:34:25 +00:00
SDelFReader *pDelFReader = NULL;
2022-09-02 05:55:05 +00:00
2022-09-02 09:04:49 +00:00
// alloc
pDelFReader = (SDelFReader *)taosMemoryCalloc(1, sizeof(*pDelFReader));
if (pDelFReader == NULL) {
TSDB_CHECK_CODE(code = terrno, lino, _exit);
2022-09-02 09:04:49 +00:00
}
// open impl
pDelFReader->pTsdb = pTsdb;
pDelFReader->fDel = *pFile;
tsdbDelFileName(pTsdb, pFile, fname);
code = tsdbOpenFile(fname, pTsdb, TD_FILE_READ, &pDelFReader->pReadH, 0);
2024-07-18 09:17:02 +00:00
TSDB_CHECK_CODE(code, lino, _exit);
2022-09-02 05:55:05 +00:00
2022-10-14 05:34:25 +00:00
_exit:
if (code) {
*ppReader = NULL;
2024-07-18 09:17:02 +00:00
TSDB_ERROR_LOG(TD_VID(pTsdb->pVnode), lino, code);
taosMemoryFree(pDelFReader);
2022-10-14 05:34:25 +00:00
} else {
*ppReader = pDelFReader;
}
2022-09-02 09:04:49 +00:00
return code;
2022-09-02 05:55:05 +00:00
}
2024-09-10 10:55:02 +00:00
void tsdbDelFReaderClose(SDelFReader **ppReader) {
2022-09-02 09:04:49 +00:00
int32_t code = 0;
SDelFReader *pReader = *ppReader;
2022-09-02 05:55:05 +00:00
2022-09-02 09:04:49 +00:00
if (pReader) {
2022-09-04 12:28:12 +00:00
tsdbCloseFile(&pReader->pReadH);
2022-09-02 09:04:49 +00:00
for (int32_t iBuf = 0; iBuf < sizeof(pReader->aBuf) / sizeof(uint8_t *); iBuf++) {
tFree(pReader->aBuf[iBuf]);
}
taosMemoryFree(pReader);
2022-09-02 05:55:05 +00:00
}
*ppReader = NULL;
2022-09-02 05:55:05 +00:00
}
2022-09-02 09:04:49 +00:00
int32_t tsdbReadDelData(SDelFReader *pReader, SDelIdx *pDelIdx, SArray *aDelData) {
2023-06-09 09:52:57 +00:00
return tsdbReadDelDatav1(pReader, pDelIdx, aDelData, INT64_MAX);
2023-06-02 16:20:59 +00:00
}
2023-06-02 15:36:47 +00:00
int32_t tsdbReadDelDatav1(SDelFReader *pReader, SDelIdx *pDelIdx, SArray *aDelData, int64_t maxVer) {
2022-09-02 05:55:05 +00:00
int32_t code = 0;
2024-07-18 09:17:02 +00:00
int32_t lino;
2022-09-02 09:04:49 +00:00
int64_t offset = pDelIdx->offset;
int64_t size = pDelIdx->size;
int64_t n;
2022-09-02 05:55:05 +00:00
2022-09-02 09:04:49 +00:00
taosArrayClear(aDelData);
2022-09-02 05:55:05 +00:00
2022-09-02 09:04:49 +00:00
// alloc
code = tRealloc(&pReader->aBuf[0], size);
2024-07-18 09:17:02 +00:00
TSDB_CHECK_CODE(code, lino, _exit);
2022-09-02 05:55:05 +00:00
2022-09-02 09:04:49 +00:00
// read
2024-03-29 02:48:49 +00:00
int32_t encryptAlgorithm = pReader->pTsdb->pVnode->config.tsdbCfg.encryptAlgorithm;
char *encryptKey = pReader->pTsdb->pVnode->config.tsdbCfg.encryptKey;
2024-03-29 02:48:49 +00:00
code = tsdbReadFile(pReader->pReadH, offset, pReader->aBuf[0], size, 0, encryptAlgorithm, encryptKey);
2024-07-18 09:17:02 +00:00
TSDB_CHECK_CODE(code, lino, _exit);
2022-09-02 09:04:49 +00:00
// // decode
n = 0;
2022-09-04 12:28:12 +00:00
while (n < size) {
2022-09-02 09:04:49 +00:00
SDelData delData;
n += tGetDelData(pReader->aBuf[0] + n, &delData);
if (delData.version > maxVer) {
continue;
2022-09-02 05:55:05 +00:00
}
2023-06-09 09:52:57 +00:00
if (taosArrayPush(aDelData, &delData) == NULL) {
2024-09-20 00:56:46 +00:00
TSDB_CHECK_CODE(code = terrno, lino, _exit);
2023-06-09 09:52:57 +00:00
}
2022-09-02 05:55:05 +00:00
}
2024-08-20 06:47:05 +00:00
if (n != size) {
TSDB_CHECK_CODE(code = TSDB_CODE_FILE_CORRUPTED, lino, _exit);
}
2022-09-02 09:04:49 +00:00
2024-07-18 09:17:02 +00:00
_exit:
if (code) {
TSDB_ERROR_LOG(TD_VID(pReader->pTsdb->pVnode), lino, code);
}
2022-09-02 05:55:05 +00:00
return code;
}
2022-09-02 09:04:49 +00:00
int32_t tsdbReadDelIdx(SDelFReader *pReader, SArray *aDelIdx) {
2022-09-02 05:55:05 +00:00
int32_t code = 0;
2024-07-18 09:17:02 +00:00
int32_t lino;
2022-09-02 09:04:49 +00:00
int32_t n;
int64_t offset = pReader->fDel.offset;
int64_t size = pReader->fDel.size - offset;
2022-09-02 05:55:05 +00:00
2022-09-02 09:04:49 +00:00
taosArrayClear(aDelIdx);
// alloc
code = tRealloc(&pReader->aBuf[0], size);
2024-07-18 09:17:02 +00:00
TSDB_CHECK_CODE(code, lino, _exit);
2022-09-02 09:04:49 +00:00
// read
2024-03-29 02:48:49 +00:00
int32_t encryptAlgorithm = pReader->pTsdb->pVnode->config.tsdbCfg.encryptAlgorithm;
char *encryptKey = pReader->pTsdb->pVnode->config.tsdbCfg.encryptKey;
2024-03-29 02:48:49 +00:00
code = tsdbReadFile(pReader->pReadH, offset, pReader->aBuf[0], size, 0, encryptAlgorithm, encryptKey);
2024-07-18 09:17:02 +00:00
TSDB_CHECK_CODE(code, lino, _exit);
2022-09-02 05:55:05 +00:00
2022-09-02 09:04:49 +00:00
// decode
n = 0;
2022-09-04 12:28:12 +00:00
while (n < size) {
2022-09-02 09:04:49 +00:00
SDelIdx delIdx;
2022-09-02 05:55:05 +00:00
2022-09-02 09:04:49 +00:00
n += tGetDelIdx(pReader->aBuf[0] + n, &delIdx);
2022-09-02 05:55:05 +00:00
2022-09-02 09:04:49 +00:00
if (taosArrayPush(aDelIdx, &delIdx) == NULL) {
2024-09-20 00:56:46 +00:00
TSDB_CHECK_CODE(code = terrno, lino, _exit);
2022-09-02 09:04:49 +00:00
}
2022-09-02 05:55:05 +00:00
}
2024-08-20 06:47:05 +00:00
if (n != size) {
TSDB_CHECK_CODE(code = TSDB_CODE_FILE_CORRUPTED, lino, _exit);
}
2022-09-02 05:55:05 +00:00
2024-07-18 09:17:02 +00:00
_exit:
if (code) {
TSDB_ERROR_LOG(TD_VID(pReader->pTsdb->pVnode), lino, code);
}
2022-09-02 05:55:05 +00:00
return code;
}