TDengine/source/dnode/mnode/sdb/src/sdbFile.c

881 lines
24 KiB
C
Raw Normal View History

2021-11-12 07:06:58 +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/>.
*/
#define _DEFAULT_SOURCE
2024-07-16 09:23:23 +00:00
#include "crypt.h"
2022-05-25 04:13:36 +00:00
#include "sdb.h"
#include "sync.h"
2021-11-12 11:37:22 +00:00
#include "tchecksum.h"
2024-03-29 02:48:49 +00:00
#include "tglobal.h"
2024-07-16 09:23:23 +00:00
#include "wal.h"
2021-11-12 07:06:58 +00:00
2022-04-28 09:44:42 +00:00
#define SDB_TABLE_SIZE 24
2022-01-04 03:23:54 +00:00
#define SDB_RESERVE_SIZE 512
2022-05-20 12:47:00 +00:00
#define SDB_FILE_VER 1
2022-01-04 03:23:54 +00:00
2024-10-15 02:00:38 +00:00
#define SDB_TABLE_SIZE_EXTRA SDB_MAX
#define SDB_RESERVE_SIZE_EXTRA (512 - (SDB_TABLE_SIZE_EXTRA - SDB_TABLE_SIZE) * 2 * sizeof(int64_t))
2022-05-28 03:11:48 +00:00
static int32_t sdbDeployData(SSdb *pSdb) {
2024-07-16 03:25:30 +00:00
int32_t code = 0;
2022-09-23 07:42:36 +00:00
mInfo("start to deploy sdb");
2021-11-12 11:11:35 +00:00
2022-01-04 03:23:54 +00:00
for (int32_t i = SDB_MAX - 1; i >= 0; --i) {
2021-11-29 07:53:02 +00:00
SdbDeployFp fp = pSdb->deployFps[i];
2021-11-12 07:06:58 +00:00
if (fp == NULL) continue;
2021-11-29 07:53:02 +00:00
2022-09-23 07:42:36 +00:00
mInfo("start to deploy sdb:%s", sdbTableName(i));
2024-07-16 03:25:30 +00:00
code = (*fp)(pSdb->pMnode);
if (code != 0) {
mError("failed to deploy sdb:%s since %s", sdbTableName(i), tstrerror(code));
2021-11-29 11:35:42 +00:00
return -1;
2021-11-12 07:06:58 +00:00
}
}
2022-09-23 07:42:36 +00:00
mInfo("sdb deploy success");
2021-11-12 07:06:58 +00:00
return 0;
}
static int32_t sdbAfterRestoredData(SSdb *pSdb) {
2024-11-15 06:39:10 +00:00
int32_t code = 0;
mInfo("start to prepare sdb");
for (int32_t i = SDB_MAX - 1; i >= 0; --i) {
SdbAfterRestoredFp fp = pSdb->afterRestoredFps[i];
2024-11-15 06:39:10 +00:00
if (fp == NULL) continue;
mInfo("start to prepare sdb:%s", sdbTableName(i));
code = (*fp)(pSdb->pMnode);
if (code != 0) {
mError("failed to prepare sdb:%s since %s", sdbTableName(i), tstrerror(code));
return -1;
}
}
mInfo("sdb prepare success");
return 0;
}
2022-05-28 03:11:48 +00:00
static void sdbResetData(SSdb *pSdb) {
2022-09-23 07:42:36 +00:00
mInfo("start to reset sdb");
2022-05-28 03:11:48 +00:00
for (ESdbType i = 0; i < SDB_MAX; ++i) {
SHashObj *hash = pSdb->hashObjs[i];
if (hash == NULL) continue;
2024-08-21 04:23:42 +00:00
sdbWriteLock(pSdb, i);
2022-05-28 03:11:48 +00:00
SSdbRow **ppRow = taosHashIterate(hash, NULL);
while (ppRow != NULL) {
SSdbRow *pRow = *ppRow;
if (pRow == NULL) continue;
sdbFreeRow(pSdb, pRow, true);
ppRow = taosHashIterate(hash, ppRow);
}
taosHashClear(pSdb->hashObjs[i]);
pSdb->tableVer[i] = 0;
pSdb->maxId[i] = 0;
2024-08-21 04:23:42 +00:00
sdbUnLock(pSdb, i);
2022-09-23 07:42:36 +00:00
mInfo("sdb:%s is reset", sdbTableName(i));
2022-05-28 03:11:48 +00:00
}
2022-06-17 06:46:59 +00:00
pSdb->applyIndex = -1;
pSdb->applyTerm = -1;
pSdb->applyConfig = -1;
pSdb->commitIndex = -1;
pSdb->commitTerm = -1;
pSdb->commitConfig = -1;
2022-09-23 07:42:36 +00:00
mInfo("sdb reset success");
2022-05-28 03:11:48 +00:00
}
static int32_t sdbReadFileHead(SSdb *pSdb, TdFilePtr pFile) {
2024-07-16 03:25:30 +00:00
int32_t code = 0;
2022-05-20 12:47:00 +00:00
int64_t sver = 0;
int32_t ret = taosReadFile(pFile, &sver, sizeof(int64_t));
if (ret < 0) {
2024-09-10 03:29:50 +00:00
return terrno;
2022-05-20 12:47:00 +00:00
}
if (ret != sizeof(int64_t)) {
2024-07-16 03:25:30 +00:00
code = TSDB_CODE_FILE_CORRUPTED;
TAOS_RETURN(code);
2022-05-20 12:47:00 +00:00
}
if (sver != SDB_FILE_VER) {
2024-07-16 03:25:30 +00:00
code = TSDB_CODE_FILE_CORRUPTED;
TAOS_RETURN(code);
2022-05-20 12:47:00 +00:00
}
2022-06-17 06:46:59 +00:00
ret = taosReadFile(pFile, &pSdb->applyIndex, sizeof(int64_t));
2022-01-04 03:23:54 +00:00
if (ret < 0) {
2024-09-10 03:29:50 +00:00
return terrno;
2022-01-04 03:23:54 +00:00
}
if (ret != sizeof(int64_t)) {
2024-07-16 03:25:30 +00:00
code = TSDB_CODE_FILE_CORRUPTED;
TAOS_RETURN(code);
2022-01-04 03:23:54 +00:00
}
2022-06-17 06:46:59 +00:00
ret = taosReadFile(pFile, &pSdb->applyTerm, sizeof(int64_t));
2022-05-23 05:14:54 +00:00
if (ret < 0) {
2024-09-10 03:29:50 +00:00
return terrno;
2022-05-23 05:14:54 +00:00
}
if (ret != sizeof(int64_t)) {
2024-07-16 03:25:30 +00:00
code = TSDB_CODE_FILE_CORRUPTED;
TAOS_RETURN(code);
2022-05-23 05:14:54 +00:00
}
2022-06-17 06:46:59 +00:00
ret = taosReadFile(pFile, &pSdb->applyConfig, sizeof(int64_t));
2022-06-09 06:12:52 +00:00
if (ret < 0) {
2024-09-10 03:29:50 +00:00
return terrno;
2022-06-09 06:12:52 +00:00
}
if (ret != sizeof(int64_t)) {
2024-07-16 03:25:30 +00:00
code = TSDB_CODE_FILE_CORRUPTED;
TAOS_RETURN(code);
2022-06-09 06:12:52 +00:00
}
2022-01-04 03:23:54 +00:00
for (int32_t i = 0; i < SDB_TABLE_SIZE; ++i) {
2022-04-28 12:17:37 +00:00
int64_t maxId = 0;
ret = taosReadFile(pFile, &maxId, sizeof(int64_t));
2022-01-04 03:23:54 +00:00
if (ret < 0) {
2024-09-10 03:29:50 +00:00
return terrno;
2022-01-04 03:23:54 +00:00
}
if (ret != sizeof(int64_t)) {
2024-07-16 03:25:30 +00:00
code = TSDB_CODE_FILE_CORRUPTED;
TAOS_RETURN(code);
2022-01-04 03:23:54 +00:00
}
if (i < SDB_MAX) {
pSdb->maxId[i] = maxId;
}
}
for (int32_t i = 0; i < SDB_TABLE_SIZE; ++i) {
2022-04-28 12:32:27 +00:00
int64_t ver = 0;
ret = taosReadFile(pFile, &ver, sizeof(int64_t));
2022-01-04 03:23:54 +00:00
if (ret < 0) {
2024-09-10 03:29:50 +00:00
return terrno;
2022-01-04 03:23:54 +00:00
}
if (ret != sizeof(int64_t)) {
2024-07-16 03:25:30 +00:00
code = TSDB_CODE_FILE_CORRUPTED;
TAOS_RETURN(code);
2022-01-04 03:23:54 +00:00
}
if (i < SDB_MAX) {
pSdb->tableVer[i] = ver;
}
}
2024-10-15 02:00:38 +00:00
// for sdb compatibility
for (int32_t i = SDB_TABLE_SIZE; i < SDB_TABLE_SIZE_EXTRA; ++i) {
int64_t maxId = 0;
ret = taosReadFile(pFile, &maxId, sizeof(int64_t));
if (ret < 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
code = TAOS_SYSTEM_ERROR(ERRNO);
2024-10-15 02:00:38 +00:00
TAOS_RETURN(code);
}
if (ret != sizeof(int64_t)) {
code = TSDB_CODE_FILE_CORRUPTED;
TAOS_RETURN(code);
}
if (i < SDB_MAX) {
pSdb->maxId[i] = maxId;
}
int64_t ver = 0;
ret = taosReadFile(pFile, &ver, sizeof(int64_t));
if (ret < 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
code = TAOS_SYSTEM_ERROR(ERRNO);
2024-10-15 02:00:38 +00:00
TAOS_RETURN(code);
}
if (ret != sizeof(int64_t)) {
code = TSDB_CODE_FILE_CORRUPTED;
TAOS_RETURN(code);
}
if (i < SDB_MAX) {
pSdb->tableVer[i] = ver;
}
}
char reserve[SDB_RESERVE_SIZE_EXTRA] = {0};
ret = taosReadFile(pFile, reserve, sizeof(reserve));
2022-01-04 03:23:54 +00:00
if (ret < 0) {
2024-09-10 03:29:50 +00:00
return terrno;
2022-01-04 03:23:54 +00:00
}
if (ret != sizeof(reserve)) {
2024-07-16 03:25:30 +00:00
code = TSDB_CODE_FILE_CORRUPTED;
TAOS_RETURN(code);
2022-01-04 03:23:54 +00:00
}
return 0;
}
static int32_t sdbWriteFileHead(SSdb *pSdb, TdFilePtr pFile) {
2022-05-20 12:47:00 +00:00
int64_t sver = SDB_FILE_VER;
if (taosWriteFile(pFile, &sver, sizeof(int64_t)) != sizeof(int64_t)) {
2024-09-10 06:55:14 +00:00
return terrno;
2022-05-20 12:47:00 +00:00
}
mInfo("vgId:1, write sdb file with sdb applyIndex:%" PRId64 " term:%" PRId64 " config:%" PRId64, pSdb->applyIndex,
pSdb->applyTerm, pSdb->applyConfig);
2022-06-17 06:46:59 +00:00
if (taosWriteFile(pFile, &pSdb->applyIndex, sizeof(int64_t)) != sizeof(int64_t)) {
2024-09-10 06:55:14 +00:00
return terrno;
2022-01-04 03:23:54 +00:00
}
2022-06-17 06:46:59 +00:00
if (taosWriteFile(pFile, &pSdb->applyTerm, sizeof(int64_t)) != sizeof(int64_t)) {
2024-09-10 06:55:14 +00:00
return terrno;
2022-05-23 05:14:54 +00:00
}
2022-06-17 06:46:59 +00:00
if (taosWriteFile(pFile, &pSdb->applyConfig, sizeof(int64_t)) != sizeof(int64_t)) {
2024-09-10 06:55:14 +00:00
return terrno;
2022-06-09 06:12:52 +00:00
}
2022-01-04 03:23:54 +00:00
for (int32_t i = 0; i < SDB_TABLE_SIZE; ++i) {
2022-04-28 12:17:37 +00:00
int64_t maxId = 0;
2022-01-04 03:23:54 +00:00
if (i < SDB_MAX) {
maxId = pSdb->maxId[i];
}
if (taosWriteFile(pFile, &maxId, sizeof(int64_t)) != sizeof(int64_t)) {
2024-09-10 06:55:14 +00:00
return terrno;
2022-01-04 03:23:54 +00:00
}
}
for (int32_t i = 0; i < SDB_TABLE_SIZE; ++i) {
2022-04-28 12:17:37 +00:00
int64_t ver = 0;
2022-01-04 03:23:54 +00:00
if (i < SDB_MAX) {
ver = pSdb->tableVer[i];
}
if (taosWriteFile(pFile, &ver, sizeof(int64_t)) != sizeof(int64_t)) {
2024-09-10 06:55:14 +00:00
return terrno;
2022-01-04 03:23:54 +00:00
}
}
2024-10-15 02:00:38 +00:00
// for sdb compatibility
for (int32_t i = SDB_TABLE_SIZE; i < SDB_TABLE_SIZE_EXTRA; ++i) {
int64_t maxId = 0;
if (i < SDB_MAX) {
maxId = pSdb->maxId[i];
}
if (taosWriteFile(pFile, &maxId, sizeof(int64_t)) != sizeof(int64_t)) {
return terrno;
}
int64_t ver = 0;
if (i < SDB_MAX) {
ver = pSdb->tableVer[i];
}
if (taosWriteFile(pFile, &ver, sizeof(int64_t)) != sizeof(int64_t)) {
return terrno;
}
}
char reserve[SDB_RESERVE_SIZE_EXTRA] = {0};
if (taosWriteFile(pFile, reserve, sizeof(reserve)) != sizeof(reserve)) {
2024-09-10 06:55:14 +00:00
return terrno;
2022-01-04 03:23:54 +00:00
}
return 0;
}
2022-05-28 03:11:48 +00:00
static int32_t sdbReadFileImp(SSdb *pSdb) {
2021-11-29 07:53:02 +00:00
int64_t offset = 0;
int32_t code = 0;
int32_t readLen = 0;
int64_t ret = 0;
2022-05-28 03:11:48 +00:00
char file[PATH_MAX] = {0};
2023-01-11 08:37:45 +00:00
int32_t bufLen = TSDB_MAX_MSG_SIZE;
2022-05-28 03:11:48 +00:00
snprintf(file, sizeof(file), "%s%ssdb.data", pSdb->currDir, TD_DIRSEP);
2022-09-23 07:42:36 +00:00
mInfo("start to read sdb file:%s", file);
2021-11-29 07:53:02 +00:00
2023-01-11 08:37:45 +00:00
SSdbRaw *pRaw = taosMemoryMalloc(bufLen + 100);
2021-11-12 07:06:58 +00:00
if (pRaw == NULL) {
2024-09-12 07:46:30 +00:00
code = terrno;
2024-07-16 03:25:30 +00:00
mError("failed read sdb file since %s", tstrerror(code));
TAOS_RETURN(code);
2021-11-12 07:06:58 +00:00
}
TdFilePtr pFile = taosOpenFile(file, TD_FILE_READ);
if (pFile == NULL) {
2022-03-25 16:29:53 +00:00
taosMemoryFree(pRaw);
2024-09-10 09:40:19 +00:00
code = terrno;
2024-07-16 03:25:30 +00:00
mInfo("read sdb file:%s finished since %s", file, tstrerror(code));
2024-07-16 09:23:23 +00:00
return 0;
2021-11-12 07:06:58 +00:00
}
2024-07-16 03:25:30 +00:00
code = sdbReadFileHead(pSdb, pFile);
if (code != 0) {
mError("failed to read sdb file:%s head since %s", file, tstrerror(code));
2022-03-25 16:29:53 +00:00
taosMemoryFree(pRaw);
2024-09-05 04:00:49 +00:00
int32_t ret = 0;
if ((ret = taosCloseFile(&pFile)) != 0) {
mError("failed to close sdb file:%s since %s", file, tstrerror(ret));
}
return code;
2022-01-04 03:23:54 +00:00
}
2022-04-28 09:44:42 +00:00
int64_t tableVer[SDB_MAX] = {0};
memcpy(tableVer, pSdb->tableVer, sizeof(tableVer));
2021-11-12 07:06:58 +00:00
while (1) {
2021-11-12 13:35:29 +00:00
readLen = sizeof(SSdbRaw);
ret = taosReadFile(pFile, pRaw, readLen);
2021-11-12 07:06:58 +00:00
if (ret == 0) break;
if (ret < 0) {
2024-09-10 03:29:50 +00:00
code = terrno;
mError("failed to read sdb file:%s since %s", file, tstrerror(code));
goto _OVER;
2021-11-12 07:06:58 +00:00
}
2021-11-12 13:35:29 +00:00
if (ret != readLen) {
2021-11-12 11:37:22 +00:00
code = TSDB_CODE_FILE_CORRUPTED;
mError("failed to read sdb file:%s since %s, ret:%" PRId64 " != readLen:%d", file, tstrerror(code), ret, readLen);
goto _OVER;
2021-11-12 11:37:22 +00:00
}
2021-11-12 13:35:29 +00:00
readLen = pRaw->dataLen + sizeof(int32_t);
2024-07-16 09:23:23 +00:00
if (tsiEncryptAlgorithm == DND_CA_SM4 && (tsiEncryptScope & DND_CS_SDB) == DND_CS_SDB) {
2024-03-29 02:48:49 +00:00
readLen = ENCRYPTED_LEN(pRaw->dataLen) + sizeof(int32_t);
}
2023-01-11 08:37:45 +00:00
if (readLen >= bufLen) {
bufLen = pRaw->dataLen * 2;
SSdbRaw *pNewRaw = taosMemoryMalloc(bufLen + 100);
if (pNewRaw == NULL) {
2024-09-12 07:46:30 +00:00
code = terrno;
2023-01-11 08:37:45 +00:00
mError("failed read sdb file since malloc new sdbRaw size:%d failed", bufLen);
goto _OVER;
}
2023-01-11 08:37:45 +00:00
mInfo("malloc new sdb raw size:%d, type:%d", bufLen, pRaw->type);
memcpy(pNewRaw, pRaw, sizeof(SSdbRaw));
sdbFreeRaw(pRaw);
pRaw = pNewRaw;
}
ret = taosReadFile(pFile, pRaw->pData, readLen);
2021-11-12 11:37:22 +00:00
if (ret < 0) {
2024-09-10 03:29:50 +00:00
code = terrno;
mError("failed to read sdb file:%s since %s, ret:%" PRId64 " readLen:%d", file, tstrerror(code), ret, readLen);
goto _OVER;
2021-11-12 11:37:22 +00:00
}
2021-11-12 13:35:29 +00:00
if (ret != readLen) {
2021-11-12 11:37:22 +00:00
code = TSDB_CODE_FILE_CORRUPTED;
mError("failed to read sdb file:%s since %s, ret:%" PRId64 " != readLen:%d", file, tstrerror(code), ret, readLen);
goto _OVER;
2021-11-12 11:37:22 +00:00
}
2024-07-16 09:23:23 +00:00
if (tsiEncryptAlgorithm == DND_CA_SM4 && (tsiEncryptScope & DND_CS_SDB) == DND_CS_SDB) {
2024-03-29 02:48:49 +00:00
int32_t count = 0;
char *plantContent = taosMemoryMalloc(ENCRYPTED_LEN(pRaw->dataLen));
2024-07-17 09:50:21 +00:00
if (plantContent == NULL) {
2024-09-12 07:46:30 +00:00
code = terrno;
2024-07-17 09:50:21 +00:00
goto _OVER;
}
2024-03-29 02:48:49 +00:00
SCryptOpts opts;
opts.len = ENCRYPTED_LEN(pRaw->dataLen);
opts.source = pRaw->pData;
opts.result = plantContent;
opts.unitLen = 16;
2024-12-09 06:35:12 +00:00
tstrncpy(opts.key, tsEncryptKey, ENCRYPT_KEY_LEN + 1);
2024-03-29 02:48:49 +00:00
count = CBC_Decrypt(&opts);
2024-07-16 09:23:23 +00:00
// mDebug("read sdb, CBC_Decrypt dataLen:%d, descrypted len:%d, %s", pRaw->dataLen, count, __FUNCTION__);
2024-03-29 02:48:49 +00:00
memcpy(pRaw->pData, plantContent, pRaw->dataLen);
taosMemoryFree(plantContent);
memcpy(pRaw->pData + pRaw->dataLen, &pRaw->pData[ENCRYPTED_LEN(pRaw->dataLen)], sizeof(int32_t));
}
2021-11-12 13:35:29 +00:00
int32_t totalLen = sizeof(SSdbRaw) + pRaw->dataLen + sizeof(int32_t);
if ((!taosCheckChecksumWhole((const uint8_t *)pRaw, totalLen)) != 0) {
2021-11-12 11:37:22 +00:00
code = TSDB_CODE_CHECKSUM_ERROR;
mError("failed to read sdb file:%s since %s, readLen:%d", file, tstrerror(code), readLen);
goto _OVER;
2021-11-12 07:06:58 +00:00
}
2024-12-06 03:15:28 +00:00
if (pRaw->type >= SDB_MAX) {
mInfo("skip sdb raw type:%d since it is not supported", pRaw->type);
continue;
}
2022-04-26 07:47:45 +00:00
code = sdbWriteWithoutFree(pSdb, pRaw);
2021-11-12 07:06:58 +00:00
if (code != 0) {
2024-11-18 11:52:41 +00:00
mError("failed to exec sdbWrite while read sdb file:%s since %s", file, terrstr());
2022-04-28 12:32:27 +00:00
goto _OVER;
2021-11-12 07:06:58 +00:00
}
}
code = 0;
2022-06-17 06:46:59 +00:00
pSdb->commitIndex = pSdb->applyIndex;
pSdb->commitTerm = pSdb->applyTerm;
pSdb->commitConfig = pSdb->applyConfig;
2022-04-28 09:44:42 +00:00
memcpy(pSdb->tableVer, tableVer, sizeof(tableVer));
2024-10-25 02:53:48 +00:00
mInfo("vgId:1, trans:0, read sdb file:%s success, commit index:%" PRId64 " term:%" PRId64 " config:%" PRId64, file,
pSdb->commitIndex, pSdb->commitTerm, pSdb->commitConfig);
2021-11-12 07:06:58 +00:00
2022-04-28 12:32:27 +00:00
_OVER:
2024-09-05 04:00:49 +00:00
if ((ret = taosCloseFile(&pFile)) != 0) {
mError("failed to close sdb file:%s since %s", file, tstrerror(ret));
}
2021-11-12 11:37:22 +00:00
sdbFreeRaw(pRaw);
2021-11-29 07:53:02 +00:00
2024-07-17 09:50:21 +00:00
TAOS_RETURN(code);
2021-11-12 07:06:58 +00:00
}
2022-05-28 03:11:48 +00:00
int32_t sdbReadFile(SSdb *pSdb) {
2024-07-29 04:42:42 +00:00
(void)taosThreadMutexLock(&pSdb->filelock);
2022-05-28 03:11:48 +00:00
sdbResetData(pSdb);
int32_t code = sdbReadFileImp(pSdb);
if (code != 0) {
2024-07-16 03:25:30 +00:00
mError("failed to read sdb file since %s", tstrerror(code));
2022-05-28 03:11:48 +00:00
sdbResetData(pSdb);
}
2024-07-29 04:42:42 +00:00
(void)taosThreadMutexUnlock(&pSdb->filelock);
2022-05-28 03:11:48 +00:00
return code;
}
2024-08-28 06:52:38 +00:00
static int32_t sdbWriteFileImp(SSdb *pSdb, int32_t skip_type) {
2021-11-29 07:53:02 +00:00
int32_t code = 0;
2021-11-12 07:06:58 +00:00
char tmpfile[PATH_MAX] = {0};
2021-11-29 11:35:42 +00:00
snprintf(tmpfile, sizeof(tmpfile), "%s%ssdb.data", pSdb->tmpDir, TD_DIRSEP);
2021-11-29 07:53:02 +00:00
char curfile[PATH_MAX] = {0};
2021-11-29 11:35:42 +00:00
snprintf(curfile, sizeof(curfile), "%s%ssdb.data", pSdb->currDir, TD_DIRSEP);
2021-11-12 07:06:58 +00:00
2022-09-23 07:42:36 +00:00
mInfo("start to write sdb file, apply index:%" PRId64 " term:%" PRId64 " config:%" PRId64 ", commit index:%" PRId64
2022-10-13 03:56:16 +00:00
" term:%" PRId64 " config:%" PRId64 ", file:%s",
pSdb->applyIndex, pSdb->applyTerm, pSdb->applyConfig, pSdb->commitIndex, pSdb->commitTerm, pSdb->commitConfig,
curfile);
2021-12-31 02:52:10 +00:00
2022-04-11 10:55:43 +00:00
TdFilePtr pFile = taosOpenFile(tmpfile, TD_FILE_CREATE | TD_FILE_WRITE | TD_FILE_TRUNC);
if (pFile == NULL) {
2024-09-10 09:40:19 +00:00
code = terrno;
2024-07-16 03:25:30 +00:00
mError("failed to open sdb file:%s for write since %s", tmpfile, tstrerror(code));
TAOS_RETURN(code);
2021-11-12 07:06:58 +00:00
}
2024-07-16 03:25:30 +00:00
code = sdbWriteFileHead(pSdb, pFile);
if (code != 0) {
mError("failed to write sdb file:%s head since %s", tmpfile, tstrerror(code));
2024-09-05 04:00:49 +00:00
int32_t ret = 0;
if ((ret = taosCloseFile(&pFile)) != 0) {
mError("failed to close sdb file:%s since %s", tmpfile, tstrerror(ret));
}
return code;
2022-01-04 03:23:54 +00:00
}
for (int32_t i = SDB_MAX - 1; i >= 0; --i) {
2024-08-28 06:52:38 +00:00
if (i == skip_type) continue;
2021-11-29 07:53:02 +00:00
SdbEncodeFp encodeFp = pSdb->encodeFps[i];
2021-11-12 11:11:35 +00:00
if (encodeFp == NULL) continue;
2022-09-23 07:42:36 +00:00
mInfo("write %s to sdb file, total %d rows", sdbTableName(i), sdbGetSize(pSdb, i));
2021-12-31 02:52:10 +00:00
SHashObj *hash = pSdb->hashObjs[i];
sdbWriteLock(pSdb, i);
2021-11-12 07:06:58 +00:00
2021-11-12 13:35:29 +00:00
SSdbRow **ppRow = taosHashIterate(hash, NULL);
while (ppRow != NULL) {
SSdbRow *pRow = *ppRow;
if (pRow == NULL) {
ppRow = taosHashIterate(hash, ppRow);
continue;
}
if (pRow->status != SDB_STATUS_READY && pRow->status != SDB_STATUS_DROPPING) {
sdbPrintOper(pSdb, pRow, "not-write");
2021-11-12 13:35:29 +00:00
ppRow = taosHashIterate(hash, ppRow);
continue;
}
2021-11-12 11:37:22 +00:00
2022-04-26 07:47:45 +00:00
sdbPrintOper(pSdb, pRow, "write");
2021-12-31 02:52:10 +00:00
2021-11-12 07:06:58 +00:00
SSdbRaw *pRaw = (*encodeFp)(pRow->pObj);
if (pRaw != NULL) {
2021-11-12 13:35:29 +00:00
pRaw->status = pRow->status;
2024-03-29 02:48:49 +00:00
if (taosWriteFile(pFile, pRaw, sizeof(SSdbRaw)) != sizeof(SSdbRaw)) {
2024-09-10 06:55:14 +00:00
code = terrno;
2024-03-29 02:48:49 +00:00
taosHashCancelIterate(hash, ppRow);
sdbFreeRaw(pRaw);
break;
}
int32_t newDataLen = pRaw->dataLen;
2024-07-16 09:23:23 +00:00
char *newData = pRaw->pData;
if (tsiEncryptAlgorithm == DND_CA_SM4 && (tsiEncryptScope & DND_CS_SDB) == DND_CS_SDB) {
2024-03-29 02:48:49 +00:00
newDataLen = ENCRYPTED_LEN(pRaw->dataLen);
newData = taosMemoryMalloc(newDataLen);
if (newData == NULL) {
2024-09-12 07:46:30 +00:00
code = terrno;
2024-03-29 02:48:49 +00:00
taosHashCancelIterate(hash, ppRow);
sdbFreeRaw(pRaw);
break;
}
SCryptOpts opts;
opts.len = newDataLen;
opts.source = pRaw->pData;
opts.result = newData;
opts.unitLen = 16;
2024-12-09 06:48:21 +00:00
tstrncpy(opts.key, tsEncryptKey, ENCRYPT_KEY_LEN + 1);
2024-03-29 02:48:49 +00:00
int32_t count = CBC_Encrypt(&opts);
2024-07-16 09:23:23 +00:00
// mDebug("write sdb, CBC_Encrypt encryptedDataLen:%d, dataLen:%d, %s",
// newDataLen, pRaw->dataLen, __FUNCTION__);
2024-03-29 02:48:49 +00:00
}
if (taosWriteFile(pFile, newData, newDataLen) != newDataLen) {
2024-09-10 06:55:14 +00:00
code = terrno;
2021-11-12 13:35:29 +00:00
taosHashCancelIterate(hash, ppRow);
2021-12-28 12:51:05 +00:00
sdbFreeRaw(pRaw);
2021-11-12 11:37:22 +00:00
break;
}
2021-11-12 13:35:29 +00:00
2024-07-16 09:23:23 +00:00
if (tsiEncryptAlgorithm == DND_CA_SM4 && (tsiEncryptScope & DND_CS_SDB) == DND_CS_SDB) {
2024-03-29 02:48:49 +00:00
taosMemoryFree(newData);
}
2021-11-12 13:35:29 +00:00
int32_t cksum = taosCalcChecksum(0, (const uint8_t *)pRaw, sizeof(SSdbRaw) + pRaw->dataLen);
if (taosWriteFile(pFile, &cksum, sizeof(int32_t)) != sizeof(int32_t)) {
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
code = terrno;
2021-11-12 13:35:29 +00:00
taosHashCancelIterate(hash, ppRow);
2021-12-28 12:51:05 +00:00
sdbFreeRaw(pRaw);
2021-11-12 11:37:22 +00:00
break;
}
2021-11-12 07:06:58 +00:00
} else {
2022-12-03 02:03:18 +00:00
code = TSDB_CODE_APP_ERROR;
2021-11-12 13:35:29 +00:00
taosHashCancelIterate(hash, ppRow);
2021-11-12 07:06:58 +00:00
break;
}
2021-12-28 12:51:05 +00:00
sdbFreeRaw(pRaw);
2021-11-12 13:35:29 +00:00
ppRow = taosHashIterate(hash, ppRow);
2021-11-12 07:06:58 +00:00
}
sdbUnLock(pSdb, i);
2021-11-12 07:06:58 +00:00
}
if (code == 0) {
code = taosFsyncFile(pFile);
2021-11-29 07:53:02 +00:00
if (code != 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
code = TAOS_SYSTEM_ERROR(ERRNO);
mError("failed to sync sdb file:%s since %s", tmpfile, tstrerror(code));
2021-11-29 07:53:02 +00:00
}
2021-11-12 07:06:58 +00:00
}
2024-07-29 04:42:42 +00:00
if (taosCloseFile(&pFile) != 0) {
code = taosRenameFile(tmpfile, curfile);
}
2021-11-12 13:35:29 +00:00
2021-11-12 11:11:35 +00:00
if (code == 0) {
2021-11-12 07:06:58 +00:00
code = taosRenameFile(tmpfile, curfile);
2021-11-29 07:53:02 +00:00
if (code != 0) {
mError("failed to write sdb file:%s since %s", curfile, tstrerror(code));
2021-11-29 07:53:02 +00:00
}
2021-11-12 07:06:58 +00:00
}
if (code != 0) {
mError("failed to write sdb file:%s since %s", curfile, tstrerror(code));
2021-11-12 07:06:58 +00:00
} else {
2022-06-17 06:46:59 +00:00
pSdb->commitIndex = pSdb->applyIndex;
pSdb->commitTerm = pSdb->applyTerm;
pSdb->commitConfig = pSdb->applyConfig;
2024-10-25 02:53:48 +00:00
mInfo("vgId:1, trans:0, write sdb file success, commit index:%" PRId64 " term:%" PRId64 " config:%" PRId64
" file:%s",
2022-10-13 03:56:16 +00:00
pSdb->commitIndex, pSdb->commitTerm, pSdb->commitConfig, curfile);
2021-11-12 07:06:58 +00:00
}
2021-11-29 11:35:42 +00:00
terrno = code;
2021-11-12 07:06:58 +00:00
return code;
}
2022-06-17 07:23:17 +00:00
int32_t sdbWriteFile(SSdb *pSdb, int32_t delta) {
int32_t code = 0;
2022-06-17 06:46:59 +00:00
if (pSdb->applyIndex == pSdb->commitIndex) {
2022-01-25 11:46:15 +00:00
return 0;
}
2022-06-17 07:23:17 +00:00
if (pSdb->applyIndex - pSdb->commitIndex < delta) {
return 0;
}
2024-07-29 04:42:42 +00:00
(void)taosThreadMutexLock(&pSdb->filelock);
if (pSdb->pWal != NULL) {
2023-03-01 02:02:33 +00:00
if (pSdb->sync > 0) {
code = syncBeginSnapshot(pSdb->sync, pSdb->applyIndex);
}
}
if (code == 0) {
2024-08-28 06:52:38 +00:00
code = sdbWriteFileImp(pSdb, -1);
}
if (code == 0) {
if (pSdb->pWal != NULL) {
2023-03-01 02:02:33 +00:00
if (pSdb->sync > 0) {
code = syncEndSnapshot(pSdb->sync);
}
}
}
2022-05-28 03:11:48 +00:00
if (code != 0) {
2024-07-16 03:25:30 +00:00
mError("failed to write sdb file since %s", tstrerror(code));
} else {
2024-10-25 02:53:48 +00:00
mInfo("vgId:1, trans:0, write sdb file success, apply index:%" PRId64 ", term:%" PRId64 ", config:%" PRId64,
pSdb->applyIndex, pSdb->applyTerm, pSdb->applyConfig);
2022-05-28 03:11:48 +00:00
}
2024-07-29 04:42:42 +00:00
(void)taosThreadMutexUnlock(&pSdb->filelock);
2022-05-28 03:11:48 +00:00
return code;
2022-01-25 11:46:15 +00:00
}
2024-08-28 06:52:38 +00:00
int32_t sdbWriteFileForDump(SSdb *pSdb) {
int32_t code = 0;
code = sdbWriteFileImp(pSdb, 0);
return code;
}
2021-11-29 07:53:02 +00:00
int32_t sdbDeploy(SSdb *pSdb) {
2024-07-16 03:25:30 +00:00
int32_t code = 0;
code = sdbDeployData(pSdb);
if (code != 0) {
TAOS_RETURN(code);
2021-11-12 07:06:58 +00:00
}
2024-07-16 03:25:30 +00:00
code = sdbWriteFile(pSdb, 0);
if (code != 0) {
TAOS_RETURN(code);
2021-11-12 07:06:58 +00:00
}
return 0;
}
2022-05-24 11:29:23 +00:00
int32_t sdbAfterRestored(SSdb *pSdb) {
2024-11-15 06:39:10 +00:00
int32_t code = 0;
code = sdbAfterRestoredData(pSdb);
2024-11-15 06:39:10 +00:00
if (code != 0) {
TAOS_RETURN(code);
}
return 0;
}
2022-05-28 08:41:38 +00:00
static SSdbIter *sdbCreateIter(SSdb *pSdb) {
2022-05-24 11:29:23 +00:00
SSdbIter *pIter = taosMemoryCalloc(1, sizeof(SSdbIter));
if (pIter == NULL) {
terrno = TSDB_CODE_OUT_OF_MEMORY;
return NULL;
}
2022-05-28 08:41:38 +00:00
char name[PATH_MAX + 100] = {0};
snprintf(name, sizeof(name), "%s%ssdb.data.%" PRIu64, pSdb->tmpDir, TD_DIRSEP, (uint64_t)pIter);
pIter->name = taosStrdup(name);
2022-05-28 08:41:38 +00:00
if (pIter->name == NULL) {
2022-05-24 11:29:23 +00:00
taosMemoryFree(pIter);
2022-05-28 08:41:38 +00:00
terrno = TSDB_CODE_OUT_OF_MEMORY;
2022-05-24 11:29:23 +00:00
return NULL;
}
return pIter;
}
2022-05-28 08:41:38 +00:00
static void sdbCloseIter(SSdbIter *pIter) {
2022-05-27 14:49:18 +00:00
if (pIter == NULL) return;
2022-05-28 08:41:38 +00:00
2022-05-27 14:49:18 +00:00
if (pIter->file != NULL) {
2024-09-05 04:00:49 +00:00
int32_t ret = 0;
if ((ret = taosCloseFile(&pIter->file)) != 0) {
mError("failed to close sdb file since %s", tstrerror(ret));
}
2022-05-28 08:41:38 +00:00
pIter->file = NULL;
2022-05-27 14:49:18 +00:00
}
2022-05-28 03:11:48 +00:00
2022-05-28 08:41:38 +00:00
if (pIter->name != NULL) {
2024-09-05 04:00:49 +00:00
int32_t ret = 0;
if ((ret = taosRemoveFile(pIter->name)) != 0) {
mError("failed to remove sdb file:%s since %s", pIter->name, tstrerror(ret));
}
2022-05-28 08:41:38 +00:00
taosMemoryFree(pIter->name);
pIter->name = NULL;
}
2022-05-28 03:11:48 +00:00
2022-09-23 07:42:36 +00:00
mInfo("sdbiter:%p, is closed, total:%" PRId64, pIter, pIter->total);
2022-05-27 14:49:18 +00:00
taosMemoryFree(pIter);
}
int32_t sdbStartRead(SSdb *pSdb, SSdbIter **ppIter, int64_t *index, int64_t *term, int64_t *config) {
2024-07-16 09:23:23 +00:00
int32_t code = 0;
2022-05-28 08:41:38 +00:00
SSdbIter *pIter = sdbCreateIter(pSdb);
if (pIter == NULL) return -1;
2022-05-27 14:49:18 +00:00
2022-05-28 08:41:38 +00:00
char datafile[PATH_MAX] = {0};
snprintf(datafile, sizeof(datafile), "%s%ssdb.data", pSdb->currDir, TD_DIRSEP);
2024-07-29 04:42:42 +00:00
(void)taosThreadMutexLock(&pSdb->filelock);
2022-06-17 06:46:59 +00:00
int64_t commitIndex = pSdb->commitIndex;
int64_t commitTerm = pSdb->commitTerm;
int64_t commitConfig = pSdb->commitConfig;
2022-05-28 08:41:38 +00:00
if (taosCopyFile(datafile, pIter->name) < 0) {
2024-09-10 09:40:19 +00:00
code = terrno;
2024-07-29 04:42:42 +00:00
(void)taosThreadMutexUnlock(&pSdb->filelock);
2024-07-16 03:25:30 +00:00
mError("failed to copy sdb file %s to %s since %s", datafile, pIter->name, tstrerror(code));
2022-05-28 08:41:38 +00:00
sdbCloseIter(pIter);
2024-07-16 03:25:30 +00:00
TAOS_RETURN(code);
2022-05-27 14:49:18 +00:00
}
2024-07-29 04:42:42 +00:00
(void)taosThreadMutexUnlock(&pSdb->filelock);
2022-05-27 14:49:18 +00:00
2022-05-28 08:41:38 +00:00
pIter->file = taosOpenFile(pIter->name, TD_FILE_READ);
if (pIter->file == NULL) {
2024-09-10 09:40:19 +00:00
code = terrno;
2024-07-16 03:25:30 +00:00
mError("failed to open sdb file:%s since %s", pIter->name, tstrerror(code));
2022-05-28 08:41:38 +00:00
sdbCloseIter(pIter);
2024-07-16 03:25:30 +00:00
TAOS_RETURN(code);
2022-05-28 08:41:38 +00:00
}
*ppIter = pIter;
if (index != NULL) *index = commitIndex;
if (term != NULL) *term = commitTerm;
if (config != NULL) *config = commitConfig;
2022-10-13 03:56:16 +00:00
mInfo("sdbiter:%p, is created to read snapshot, commit index:%" PRId64 " term:%" PRId64 " config:%" PRId64 " file:%s",
pIter, commitIndex, commitTerm, commitConfig, pIter->name);
2022-05-28 08:41:38 +00:00
return 0;
2022-05-27 14:49:18 +00:00
}
void sdbStopRead(SSdb *pSdb, SSdbIter *pIter) { sdbCloseIter(pIter); }
2022-05-27 14:49:18 +00:00
2022-05-28 08:41:38 +00:00
int32_t sdbDoRead(SSdb *pSdb, SSdbIter *pIter, void **ppBuf, int32_t *len) {
2024-07-16 03:25:30 +00:00
int32_t code = 0;
2022-09-23 07:42:36 +00:00
int32_t maxlen = 4096;
2022-05-28 07:00:18 +00:00
void *pBuf = taosMemoryCalloc(1, maxlen);
2022-05-24 11:29:23 +00:00
if (pBuf == NULL) {
code = terrno;
2024-07-16 03:25:30 +00:00
TAOS_RETURN(code);
2022-05-24 11:29:23 +00:00
}
int32_t readlen = taosReadFile(pIter->file, pBuf, maxlen);
2022-05-28 07:00:18 +00:00
if (readlen < 0 || readlen > maxlen) {
2024-09-10 03:29:50 +00:00
code = terrno;
2024-07-16 03:25:30 +00:00
mError("sdbiter:%p, failed to read snapshot since %s, total:%" PRId64, pIter, tstrerror(code), pIter->total);
2022-05-27 14:49:18 +00:00
*ppBuf = NULL;
*len = 0;
2022-05-24 11:29:23 +00:00
taosMemoryFree(pBuf);
2024-07-16 03:25:30 +00:00
TAOS_RETURN(code);
2022-05-27 14:49:18 +00:00
} else if (readlen == 0) {
2022-09-23 07:42:36 +00:00
mInfo("sdbiter:%p, read snapshot to the end, total:%" PRId64, pIter, pIter->total);
2022-05-27 14:49:18 +00:00
*ppBuf = NULL;
*len = 0;
taosMemoryFree(pBuf);
return 0;
2022-05-28 07:00:18 +00:00
} else { // (readlen <= maxlen)
2022-05-27 14:49:18 +00:00
pIter->total += readlen;
2022-09-23 07:42:36 +00:00
mInfo("sdbiter:%p, read:%d bytes from snapshot, total:%" PRId64, pIter, readlen, pIter->total);
2022-05-27 14:49:18 +00:00
*ppBuf = pBuf;
*len = readlen;
return 0;
2022-05-24 11:29:23 +00:00
}
}
2022-05-27 14:49:18 +00:00
2022-05-28 08:41:38 +00:00
int32_t sdbStartWrite(SSdb *pSdb, SSdbIter **ppIter) {
2024-07-16 09:23:23 +00:00
int32_t code = 0;
2022-05-28 08:41:38 +00:00
SSdbIter *pIter = sdbCreateIter(pSdb);
2024-07-16 03:25:30 +00:00
if (pIter == NULL) {
code = terrno;
TAOS_RETURN(code);
}
2022-05-27 14:49:18 +00:00
2022-05-28 08:41:38 +00:00
pIter->file = taosOpenFile(pIter->name, TD_FILE_CREATE | TD_FILE_WRITE | TD_FILE_TRUNC);
if (pIter->file == NULL) {
2024-09-10 09:40:19 +00:00
code = terrno;
2024-07-16 03:25:30 +00:00
mError("failed to open %s since %s", pIter->name, tstrerror(code));
2022-09-28 01:29:54 +00:00
sdbCloseIter(pIter);
2024-07-16 03:25:30 +00:00
TAOS_RETURN(code);
2022-05-27 14:49:18 +00:00
}
2022-05-28 08:41:38 +00:00
*ppIter = pIter;
2022-09-23 07:42:36 +00:00
mInfo("sdbiter:%p, is created to write snapshot, file:%s", pIter, pIter->name);
2022-05-28 08:41:38 +00:00
return 0;
}
2022-05-27 14:49:18 +00:00
int32_t sdbStopWrite(SSdb *pSdb, SSdbIter *pIter, bool isApply, int64_t index, int64_t term, int64_t config) {
2023-01-06 07:40:09 +00:00
int32_t code = -1;
2022-05-28 08:41:38 +00:00
if (!isApply) {
2022-09-23 07:42:36 +00:00
mInfo("sdbiter:%p, not apply to sdb", pIter);
2023-01-06 07:40:09 +00:00
code = 0;
goto _OVER;
2022-05-27 14:49:18 +00:00
}
2023-01-06 07:40:09 +00:00
if (taosFsyncFile(pIter->file) != 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
code = TAOS_SYSTEM_ERROR(ERRNO);
2024-07-16 03:25:30 +00:00
mError("sdbiter:%p, failed to fasync file %s since %s", pIter, pIter->name, tstrerror(code));
2023-01-06 07:40:09 +00:00
goto _OVER;
2022-05-27 14:49:18 +00:00
}
2024-07-29 04:42:42 +00:00
if (taosCloseFile(&pIter->file) != 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
code = TAOS_SYSTEM_ERROR(ERRNO);
2024-07-29 04:42:42 +00:00
goto _OVER;
}
2022-05-28 08:41:38 +00:00
pIter->file = NULL;
2022-05-27 14:49:18 +00:00
2022-05-28 08:41:38 +00:00
char datafile[PATH_MAX] = {0};
snprintf(datafile, sizeof(datafile), "%s%ssdb.data", pSdb->currDir, TD_DIRSEP);
2024-09-10 03:29:50 +00:00
code = taosRenameFile(pIter->name, datafile);
if (code != 0) {
2024-07-16 03:25:30 +00:00
mError("sdbiter:%p, failed to rename file %s to %s since %s", pIter, pIter->name, datafile, tstrerror(code));
2023-01-06 07:40:09 +00:00
goto _OVER;
2022-05-27 14:49:18 +00:00
}
2024-07-16 03:25:30 +00:00
code = sdbReadFile(pSdb);
if (code != 0) {
mError("sdbiter:%p, failed to read from %s since %s", pIter, datafile, tstrerror(code));
2023-01-06 07:40:09 +00:00
goto _OVER;
2022-05-28 08:41:38 +00:00
}
if (config > 0) {
pSdb->commitConfig = config;
}
if (term > 0) {
pSdb->commitTerm = term;
}
if (index > 0) {
pSdb->commitIndex = index;
}
2022-09-23 07:42:36 +00:00
mInfo("sdbiter:%p, success applyed to sdb", pIter);
2023-01-06 07:40:09 +00:00
code = 0;
_OVER:
2022-09-28 01:29:54 +00:00
sdbCloseIter(pIter);
2023-01-06 07:40:09 +00:00
return code;
2022-05-28 08:41:38 +00:00
}
int32_t sdbDoWrite(SSdb *pSdb, SSdbIter *pIter, void *pBuf, int32_t len) {
2024-07-16 03:25:30 +00:00
int32_t code = 0;
2022-05-28 08:41:38 +00:00
int32_t writelen = taosWriteFile(pIter->file, pBuf, len);
if (writelen != len) {
2024-09-10 06:55:14 +00:00
code = terrno;
2024-07-16 03:25:30 +00:00
mError("failed to write len:%d since %s, total:%" PRId64, len, tstrerror(code), pIter->total);
2024-07-17 09:50:21 +00:00
TAOS_RETURN(code);
2022-05-27 14:49:18 +00:00
}
2022-05-28 08:41:38 +00:00
pIter->total += writelen;
2022-09-23 07:42:36 +00:00
mInfo("sdbiter:%p, write:%d bytes to snapshot, total:%" PRId64, pIter, writelen, pIter->total);
2022-05-27 14:49:18 +00:00
return 0;
}