mirror of
https://github.com/taosdata/TDengine
synced 2026-05-24 10:09:01 +00:00
* 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>
355 lines
7.9 KiB
C
355 lines
7.9 KiB
C
/*
|
|
* 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
|
|
#include "sdb.h"
|
|
|
|
int32_t sdbGetIdFromRaw(SSdb *pSdb, SSdbRaw *pRaw) {
|
|
EKeyType keytype = pSdb->keyTypes[pRaw->type];
|
|
if (keytype == SDB_KEY_INT32) {
|
|
int32_t id = *((int32_t *)(pRaw->pData));
|
|
return id;
|
|
} else {
|
|
return -2;
|
|
}
|
|
}
|
|
|
|
SSdbRaw *sdbAllocRaw(ESdbType type, int8_t sver, int32_t dataLen) {
|
|
SSdbRaw *pRaw = taosMemoryCalloc(1, dataLen + sizeof(SSdbRaw));
|
|
if (pRaw == NULL) {
|
|
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
|
return NULL;
|
|
}
|
|
|
|
pRaw->type = type;
|
|
pRaw->sver = sver;
|
|
pRaw->dataLen = dataLen;
|
|
|
|
#if 1
|
|
mTrace("raw:%p, is created, len:%d table:%s", pRaw, dataLen, sdbTableName(type));
|
|
#endif
|
|
return pRaw;
|
|
}
|
|
|
|
void sdbFreeRaw(SSdbRaw *pRaw) {
|
|
if (pRaw != NULL) {
|
|
#if 1
|
|
mTrace("raw:%p, is freed, len:%d, table:%s", pRaw, pRaw->dataLen, sdbTableName(pRaw->type));
|
|
#endif
|
|
taosMemoryFree(pRaw);
|
|
}
|
|
}
|
|
|
|
int32_t sdbSetRawInt8(SSdbRaw *pRaw, int32_t dataPos, int8_t val) {
|
|
int32_t code = 0;
|
|
if (pRaw == NULL) {
|
|
code = TSDB_CODE_INVALID_PTR;
|
|
TAOS_RETURN(code);
|
|
}
|
|
|
|
if (dataPos + sizeof(int8_t) > pRaw->dataLen) {
|
|
code = TSDB_CODE_SDB_INVALID_DATA_LEN;
|
|
TAOS_RETURN(code);
|
|
}
|
|
|
|
*(int8_t *)(pRaw->pData + dataPos) = val;
|
|
return 0;
|
|
}
|
|
|
|
int32_t sdbSetRawUInt8(SSdbRaw *pRaw, int32_t dataPos, uint8_t val) {
|
|
int32_t code = 0;
|
|
if (pRaw == NULL) {
|
|
code = TSDB_CODE_INVALID_PTR;
|
|
TAOS_RETURN(code);
|
|
}
|
|
|
|
if (dataPos + sizeof(uint8_t) > pRaw->dataLen) {
|
|
code = TSDB_CODE_SDB_INVALID_DATA_LEN;
|
|
TAOS_RETURN(code);
|
|
}
|
|
|
|
*(uint8_t *)(pRaw->pData + dataPos) = val;
|
|
return 0;
|
|
}
|
|
|
|
int32_t sdbSetRawBool(SSdbRaw *pRaw, int32_t dataPos, bool val) {
|
|
if (val) {
|
|
return sdbSetRawUInt8(pRaw, dataPos, 1);
|
|
} else {
|
|
return sdbSetRawUInt8(pRaw, dataPos, 0);
|
|
}
|
|
}
|
|
|
|
int32_t sdbSetRawInt32(SSdbRaw *pRaw, int32_t dataPos, int32_t val) {
|
|
int32_t code = 0;
|
|
if (pRaw == NULL) {
|
|
code = TSDB_CODE_INVALID_PTR;
|
|
TAOS_RETURN(code);
|
|
}
|
|
|
|
if (dataPos + sizeof(int32_t) > pRaw->dataLen) {
|
|
code = TSDB_CODE_SDB_INVALID_DATA_LEN;
|
|
TAOS_RETURN(code);
|
|
}
|
|
|
|
*(int32_t *)(pRaw->pData + dataPos) = val;
|
|
return 0;
|
|
}
|
|
|
|
int32_t sdbSetRawInt16(SSdbRaw *pRaw, int32_t dataPos, int16_t val) {
|
|
int32_t code = 0;
|
|
if (pRaw == NULL) {
|
|
code = TSDB_CODE_INVALID_PTR;
|
|
TAOS_RETURN(code);
|
|
}
|
|
|
|
if (dataPos + sizeof(int16_t) > pRaw->dataLen) {
|
|
code = TSDB_CODE_SDB_INVALID_DATA_LEN;
|
|
TAOS_RETURN(code);
|
|
}
|
|
|
|
*(int16_t *)(pRaw->pData + dataPos) = val;
|
|
return 0;
|
|
}
|
|
|
|
int32_t sdbSetRawInt64(SSdbRaw *pRaw, int32_t dataPos, int64_t val) {
|
|
int32_t code = 0;
|
|
if (pRaw == NULL) {
|
|
code = TSDB_CODE_INVALID_PTR;
|
|
TAOS_RETURN(code);
|
|
}
|
|
|
|
if (dataPos + sizeof(int64_t) > pRaw->dataLen) {
|
|
code = TSDB_CODE_SDB_INVALID_DATA_LEN;
|
|
TAOS_RETURN(code);
|
|
}
|
|
|
|
taosSetInt64Aligned((int64_t *)(pRaw->pData + dataPos), val);
|
|
return 0;
|
|
}
|
|
|
|
int32_t sdbSetRawFloat(SSdbRaw *pRaw, int32_t dataPos, float val) {
|
|
int32_t code = 0;
|
|
if (pRaw == NULL) {
|
|
code = TSDB_CODE_INVALID_PTR;
|
|
TAOS_RETURN(code);
|
|
}
|
|
|
|
if (dataPos + sizeof(float) > pRaw->dataLen) {
|
|
code = TSDB_CODE_SDB_INVALID_DATA_LEN;
|
|
TAOS_RETURN(code);
|
|
}
|
|
|
|
*(int64_t *)(pRaw->pData + dataPos) = val;
|
|
return 0;
|
|
}
|
|
|
|
int32_t sdbSetRawBinary(SSdbRaw *pRaw, int32_t dataPos, const char *pVal, int32_t valLen) {
|
|
int32_t code = 0;
|
|
if (pRaw == NULL) {
|
|
code = TSDB_CODE_INVALID_PTR;
|
|
TAOS_RETURN(code);
|
|
}
|
|
|
|
if (dataPos + valLen > pRaw->dataLen) {
|
|
code = TSDB_CODE_SDB_INVALID_DATA_LEN;
|
|
TAOS_RETURN(code);
|
|
}
|
|
|
|
if (pVal != NULL) {
|
|
memcpy(pRaw->pData + dataPos, pVal, valLen);
|
|
}
|
|
return 0;
|
|
}
|
|
|
|
int32_t sdbSetRawDataLen(SSdbRaw *pRaw, int32_t dataLen) {
|
|
int32_t code = 0;
|
|
if (pRaw == NULL) {
|
|
code = TSDB_CODE_INVALID_PTR;
|
|
TAOS_RETURN(code);
|
|
}
|
|
|
|
if (dataLen > pRaw->dataLen) {
|
|
code = TSDB_CODE_SDB_INVALID_DATA_LEN;
|
|
TAOS_RETURN(code);
|
|
}
|
|
|
|
pRaw->dataLen = dataLen;
|
|
return 0;
|
|
}
|
|
|
|
int32_t sdbSetRawStatus(SSdbRaw *pRaw, ESdbStatus status) {
|
|
int32_t code = 0;
|
|
if (pRaw == NULL) {
|
|
code = TSDB_CODE_INVALID_PTR;
|
|
TAOS_RETURN(code);
|
|
}
|
|
|
|
if (status == SDB_STATUS_INIT) {
|
|
code = TSDB_CODE_INVALID_PARA;
|
|
TAOS_RETURN(code);
|
|
}
|
|
|
|
pRaw->status = status;
|
|
return 0;
|
|
}
|
|
|
|
int32_t sdbGetRawInt8(SSdbRaw *pRaw, int32_t dataPos, int8_t *val) {
|
|
int32_t code = 0;
|
|
if (pRaw == NULL) {
|
|
code = TSDB_CODE_INVALID_PTR;
|
|
TAOS_RETURN(code);
|
|
}
|
|
|
|
if (dataPos + sizeof(int8_t) > pRaw->dataLen) {
|
|
code = TSDB_CODE_SDB_INVALID_DATA_LEN;
|
|
TAOS_RETURN(code);
|
|
}
|
|
|
|
*val = *(int8_t *)(pRaw->pData + dataPos);
|
|
return 0;
|
|
}
|
|
|
|
int32_t sdbGetRawUInt8(SSdbRaw *pRaw, int32_t dataPos, uint8_t *val) {
|
|
int32_t code = 0;
|
|
if (pRaw == NULL) {
|
|
code = TSDB_CODE_INVALID_PTR;
|
|
TAOS_RETURN(code);
|
|
}
|
|
|
|
if (dataPos + sizeof(uint8_t) > pRaw->dataLen) {
|
|
code = TSDB_CODE_SDB_INVALID_DATA_LEN;
|
|
TAOS_RETURN(code);
|
|
}
|
|
|
|
*val = *(uint8_t *)(pRaw->pData + dataPos);
|
|
return 0;
|
|
}
|
|
|
|
int32_t sdbGetRawBool(SSdbRaw *pRaw, int32_t dataPos, bool *val) {
|
|
int32_t code = 0;
|
|
uint8_t v = 0;
|
|
code = sdbGetRawUInt8(pRaw, dataPos, &v);
|
|
if (code != TSDB_CODE_SUCCESS) {
|
|
return code;
|
|
}
|
|
if (v) {
|
|
*val = true;
|
|
} else {
|
|
*val = false;
|
|
}
|
|
return TSDB_CODE_SUCCESS;
|
|
}
|
|
|
|
int32_t sdbGetRawInt32(SSdbRaw *pRaw, int32_t dataPos, int32_t *val) {
|
|
int32_t code = 0;
|
|
if (pRaw == NULL) {
|
|
code = TSDB_CODE_INVALID_PTR;
|
|
TAOS_RETURN(code);
|
|
}
|
|
|
|
if (dataPos + sizeof(int32_t) > pRaw->dataLen) {
|
|
code = TSDB_CODE_SDB_INVALID_DATA_LEN;
|
|
TAOS_RETURN(code);
|
|
}
|
|
|
|
*val = *(int32_t *)(pRaw->pData + dataPos);
|
|
return 0;
|
|
}
|
|
|
|
int32_t sdbGetRawInt16(SSdbRaw *pRaw, int32_t dataPos, int16_t *val) {
|
|
int32_t code = 0;
|
|
if (pRaw == NULL) {
|
|
code = TSDB_CODE_INVALID_PTR;
|
|
TAOS_RETURN(code);
|
|
}
|
|
|
|
if (dataPos + sizeof(int16_t) > pRaw->dataLen) {
|
|
code = TSDB_CODE_SDB_INVALID_DATA_LEN;
|
|
TAOS_RETURN(code);
|
|
}
|
|
|
|
*val = *(int16_t *)(pRaw->pData + dataPos);
|
|
return 0;
|
|
}
|
|
|
|
int32_t sdbGetRawInt64(SSdbRaw *pRaw, int32_t dataPos, int64_t *val) {
|
|
int32_t code = 0;
|
|
if (pRaw == NULL) {
|
|
code = TSDB_CODE_INVALID_PTR;
|
|
TAOS_RETURN(code);
|
|
}
|
|
|
|
if (dataPos + sizeof(int64_t) > pRaw->dataLen) {
|
|
code = TSDB_CODE_SDB_INVALID_DATA_LEN;
|
|
TAOS_RETURN(code);
|
|
}
|
|
|
|
taosSetPInt64Aligned(val, (int64_t *)(pRaw->pData + dataPos));
|
|
return 0;
|
|
}
|
|
|
|
int32_t sdbGetRawFloat(SSdbRaw *pRaw, int32_t dataPos, float *val) {
|
|
int32_t code = 0;
|
|
if (pRaw == NULL) {
|
|
code = TSDB_CODE_INVALID_PTR;
|
|
TAOS_RETURN(code);
|
|
}
|
|
|
|
if (dataPos + sizeof(float) > pRaw->dataLen) {
|
|
code = TSDB_CODE_SDB_INVALID_DATA_LEN;
|
|
TAOS_RETURN(code);
|
|
}
|
|
|
|
*val = *(int64_t *)(pRaw->pData + dataPos);
|
|
return 0;
|
|
}
|
|
|
|
int32_t sdbGetRawBinary(SSdbRaw *pRaw, int32_t dataPos, char *pVal, int32_t valLen) {
|
|
int32_t code = 0;
|
|
if (pRaw == NULL) {
|
|
code = TSDB_CODE_INVALID_PTR;
|
|
TAOS_RETURN(code);
|
|
}
|
|
|
|
if (dataPos + valLen > pRaw->dataLen) {
|
|
code = TSDB_CODE_SDB_INVALID_DATA_LEN;
|
|
TAOS_RETURN(code);
|
|
}
|
|
if (pVal != NULL) {
|
|
memcpy(pVal, pRaw->pData + dataPos, valLen);
|
|
}
|
|
return 0;
|
|
}
|
|
|
|
int32_t sdbGetRawSoftVer(SSdbRaw *pRaw, int8_t *sver) {
|
|
int32_t code = 0;
|
|
if (pRaw == NULL) {
|
|
code = TSDB_CODE_INVALID_PTR;
|
|
TAOS_RETURN(code);
|
|
}
|
|
|
|
*sver = pRaw->sver;
|
|
return 0;
|
|
}
|
|
|
|
int32_t sdbGetRawTotalSize(SSdbRaw *pRaw) {
|
|
if (pRaw == NULL) {
|
|
terrno = TSDB_CODE_INVALID_PTR;
|
|
return -1;
|
|
}
|
|
|
|
return sizeof(SSdbRaw) + pRaw->dataLen;
|
|
}
|