提交 2cb89fe8 编写于 作者: L Liu Jicong

Merge branch '3.0' into feature/tq

...@@ -589,7 +589,7 @@ SOperatorInfo* createTableSeqScanOperatorInfo(void* pTsdbQueryHandle, SQueryRunt ...@@ -589,7 +589,7 @@ SOperatorInfo* createTableSeqScanOperatorInfo(void* pTsdbQueryHandle, SQueryRunt
SOperatorInfo* createAggregateOperatorInfo(SQueryRuntimeEnv* pRuntimeEnv, SOperatorInfo* upstream, SExprInfo* pExpr, int32_t numOfOutput); SOperatorInfo* createAggregateOperatorInfo(SQueryRuntimeEnv* pRuntimeEnv, SOperatorInfo* upstream, SExprInfo* pExpr, int32_t numOfOutput);
SOperatorInfo* createProjectOperatorInfo(SQueryRuntimeEnv* pRuntimeEnv, SOperatorInfo* upstream, SExprInfo* pExpr, int32_t numOfOutput); SOperatorInfo* createProjectOperatorInfo(SQueryRuntimeEnv* pRuntimeEnv, SOperatorInfo* upstream, SExprInfo* pExpr, int32_t numOfOutput);
SOperatorInfo* createLimitOperatorInfo(SQueryRuntimeEnv* pRuntimeEnv, SOperatorInfo* upstream); SOperatorInfo* createLimitOperatorInfo(SQueryRuntimeEnv* pRuntimeEnv, SOperatorInfo* upstream);
SOperatorInfo* createTimeIntervalOperatorInfo(SQueryRuntimeEnv* pRuntimeEnv, SOperatorInfo* upstream, SExprInfo* pExpr, int32_t numOfOutput); SOperatorInfo* createIntervalOperatorInfo(SQueryRuntimeEnv* pRuntimeEnv, SOperatorInfo* upstream, SExprInfo* pExpr, int32_t numOfOutput);
SOperatorInfo* createAllTimeIntervalOperatorInfo(SQueryRuntimeEnv* pRuntimeEnv, SOperatorInfo* upstream, SExprInfo* pExpr, int32_t numOfOutput); SOperatorInfo* createAllTimeIntervalOperatorInfo(SQueryRuntimeEnv* pRuntimeEnv, SOperatorInfo* upstream, SExprInfo* pExpr, int32_t numOfOutput);
SOperatorInfo* createSWindowOperatorInfo(SQueryRuntimeEnv* pRuntimeEnv, SOperatorInfo* upstream, SExprInfo* pExpr, int32_t numOfOutput); SOperatorInfo* createSWindowOperatorInfo(SQueryRuntimeEnv* pRuntimeEnv, SOperatorInfo* upstream, SExprInfo* pExpr, int32_t numOfOutput);
SOperatorInfo* createFillOperatorInfo(SQueryRuntimeEnv* pRuntimeEnv, SOperatorInfo* upstream, SExprInfo* pExpr, int32_t numOfOutput, bool multigroupResult); SOperatorInfo* createFillOperatorInfo(SQueryRuntimeEnv* pRuntimeEnv, SOperatorInfo* upstream, SExprInfo* pExpr, int32_t numOfOutput, bool multigroupResult);
......
...@@ -2166,7 +2166,7 @@ static int32_t setupQueryRuntimeEnv(SQueryRuntimeEnv *pRuntimeEnv, int32_t numOf ...@@ -2166,7 +2166,7 @@ static int32_t setupQueryRuntimeEnv(SQueryRuntimeEnv *pRuntimeEnv, int32_t numOf
} }
case OP_TimeWindow: { case OP_TimeWindow: {
pRuntimeEnv->proot = pRuntimeEnv->proot =
createTimeIntervalOperatorInfo(pRuntimeEnv, pRuntimeEnv->proot, pQueryAttr->pExpr1, pQueryAttr->numOfOutput); createIntervalOperatorInfo(pRuntimeEnv, pRuntimeEnv->proot, pQueryAttr->pExpr1, pQueryAttr->numOfOutput);
int32_t opType = pRuntimeEnv->proot->upstream[0]->operatorType; int32_t opType = pRuntimeEnv->proot->upstream[0]->operatorType;
if (opType != OP_DummyInput && opType != OP_Join) { if (opType != OP_DummyInput && opType != OP_Join) {
setTableScanFilterOperatorInfo(pRuntimeEnv->proot->upstream[0]->info, pRuntimeEnv->proot); setTableScanFilterOperatorInfo(pRuntimeEnv->proot->upstream[0]->info, pRuntimeEnv->proot);
...@@ -6756,7 +6756,7 @@ SOperatorInfo* createLimitOperatorInfo(SQueryRuntimeEnv* pRuntimeEnv, SOperatorI ...@@ -6756,7 +6756,7 @@ SOperatorInfo* createLimitOperatorInfo(SQueryRuntimeEnv* pRuntimeEnv, SOperatorI
return pOperator; return pOperator;
} }
SOperatorInfo* createTimeIntervalOperatorInfo(SQueryRuntimeEnv* pRuntimeEnv, SOperatorInfo* upstream, SExprInfo* pExpr, int32_t numOfOutput) { SOperatorInfo* createIntervalOperatorInfo(SQueryRuntimeEnv* pRuntimeEnv, SOperatorInfo* upstream, SExprInfo* pExpr, int32_t numOfOutput) {
STableIntervalOperatorInfo* pInfo = calloc(1, sizeof(STableIntervalOperatorInfo)); STableIntervalOperatorInfo* pInfo = calloc(1, sizeof(STableIntervalOperatorInfo));
pInfo->pCtx = createSQLFunctionCtx(pRuntimeEnv, pExpr, numOfOutput, &pInfo->rowCellInfoOffset); pInfo->pCtx = createSQLFunctionCtx(pRuntimeEnv, pExpr, numOfOutput, &pInfo->rowCellInfoOffset);
......
...@@ -193,6 +193,7 @@ endif(${BUILD_WITH_TRAFT}) ...@@ -193,6 +193,7 @@ endif(${BUILD_WITH_TRAFT})
# LIBUV # LIBUV
if(${BUILD_WITH_UV}) if(${BUILD_WITH_UV})
add_compile_options(-Wno-sign-compare)
add_subdirectory(libuv) add_subdirectory(libuv)
endif(${BUILD_WITH_UV}) endif(${BUILD_WITH_UV})
......
...@@ -10,7 +10,7 @@ ...@@ -10,7 +10,7 @@
#include <raft.h> #include <raft.h>
#include <raft/uv.h> #include <raft/uv.h>
#include "raftServer.h" #include "raftServer.h"
#include "common.h" #include "tcommon.h"
const char *exe_name; const char *exe_name;
......
#include <stdlib.h> #include <stdlib.h>
#include "common.h" #include "tcommon.h"
#include "raftServer.h" #include "raftServer.h"
char *keys; char *keys;
......
...@@ -11,7 +11,7 @@ extern "C" { ...@@ -11,7 +11,7 @@ extern "C" {
#include <string.h> #include <string.h>
#include "raft.h" #include "raft.h"
#include "raft/uv.h" #include "raft/uv.h"
#include "common.h" #include "tcommon.h"
// simulate a db store, just for test // simulate a db store, just for test
......
...@@ -16,27 +16,19 @@ ...@@ -16,27 +16,19 @@
#ifndef _TD_COMMON_TAOS_DEF_H_ #ifndef _TD_COMMON_TAOS_DEF_H_
#define _TD_COMMON_TAOS_DEF_H_ #define _TD_COMMON_TAOS_DEF_H_
#include "taos.h"
#include "tdef.h"
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C" {
#endif #endif
#include "taos.h"
#include "tdef.h"
typedef int64_t tb_uid_t; typedef int64_t tb_uid_t;
#define TSWINDOW_INITIALIZER ((STimeWindow){INT64_MIN, INT64_MAX}) #define TSWINDOW_INITIALIZER ((STimeWindow){INT64_MIN, INT64_MAX})
#define TSWINDOW_DESC_INITIALIZER ((STimeWindow){INT64_MAX, INT64_MIN}) #define TSWINDOW_DESC_INITIALIZER ((STimeWindow){INT64_MAX, INT64_MIN})
#define IS_TSWINDOW_SPECIFIED(win) (((win).skey != INT64_MIN) || ((win).ekey != INT64_MAX)) #define IS_TSWINDOW_SPECIFIED(win) (((win).skey != INT64_MIN) || ((win).ekey != INT64_MAX))
typedef enum {
TAOS_QTYPE_RPC = 1,
TAOS_QTYPE_FWD = 2,
TAOS_QTYPE_WAL = 3,
TAOS_QTYPE_CQ = 4,
TAOS_QTYPE_QUERY = 5
} EQType;
typedef enum { typedef enum {
TSDB_SUPER_TABLE = 1, // super table TSDB_SUPER_TABLE = 1, // super table
TSDB_CHILD_TABLE = 2, // table created from super table TSDB_CHILD_TABLE = 2, // table created from super table
...@@ -46,14 +38,6 @@ typedef enum { ...@@ -46,14 +38,6 @@ typedef enum {
TSDB_TABLE_MAX = 6 TSDB_TABLE_MAX = 6
} ETableType; } ETableType;
typedef enum {
TSDB_MOD_MNODE = 1,
TSDB_MOD_HTTP = 2,
TSDB_MOD_MONITOR = 3,
TSDB_MOD_MQTT = 4,
TSDB_MOD_MAX = 5
} EModuleType;
typedef enum { typedef enum {
TSDB_CHECK_ITEM_NETWORK, TSDB_CHECK_ITEM_NETWORK,
TSDB_CHECK_ITEM_MEM, TSDB_CHECK_ITEM_MEM,
......
...@@ -13,17 +13,18 @@ ...@@ -13,17 +13,18 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#ifndef TDENGINE_COMMON_H #ifndef _TD_COMMON_DEF_H_
#define TDENGINE_COMMON_H #define _TD_COMMON_DEF_H_
#ifdef __cplusplus
extern "C" {
#endif
#include "taosdef.h" #include "taosdef.h"
#include "tarray.h" #include "tarray.h"
#include "tmsg.h" #include "tmsg.h"
#include "tvariant.h" #include "tvariant.h"
#ifdef __cplusplus
extern "C" {
#endif
// typedef struct STimeWindow { // typedef struct STimeWindow {
// TSKEY skey; // TSKEY skey;
// TSKEY ekey; // TSKEY ekey;
...@@ -214,7 +215,7 @@ static FORCE_INLINE void tDeleteSMqConsumeRsp(SMqConsumeRsp* pRsp) { ...@@ -214,7 +215,7 @@ static FORCE_INLINE void tDeleteSMqConsumeRsp(SMqConsumeRsp* pRsp) {
} }
taosArrayDestroyEx(pRsp->pBlockData, (void (*)(void*))tDeleteSSDataBlock); taosArrayDestroyEx(pRsp->pBlockData, (void (*)(void*))tDeleteSSDataBlock);
pRsp->pBlockData = NULL; pRsp->pBlockData = NULL;
// for (int i = 0; i < taosArrayGetSize(pRsp->pBlockData); i++) { // for (int32_t i = 0; i < taosArrayGetSize(pRsp->pBlockData); i++) {
// SSDataBlock* pDataBlock = (SSDataBlock*)taosArrayGet(pRsp->pBlockData, i); // SSDataBlock* pDataBlock = (SSDataBlock*)taosArrayGet(pRsp->pBlockData, i);
// tDeleteSSDataBlock(pDataBlock); // tDeleteSSDataBlock(pDataBlock);
//} //}
...@@ -279,4 +280,4 @@ typedef struct SSessionWindow { ...@@ -279,4 +280,4 @@ typedef struct SSessionWindow {
} }
#endif #endif
#endif // TDENGINE_COMMON_H #endif /*_TD_COMMON_DEF_H_*/
...@@ -12,6 +12,7 @@ ...@@ -12,6 +12,7 @@
* You should have received a copy of the GNU Affero General Public License * 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/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#ifndef _TD_COMMON_DATA_FORMAT_H_ #ifndef _TD_COMMON_DATA_FORMAT_H_
#define _TD_COMMON_DATA_FORMAT_H_ #define _TD_COMMON_DATA_FORMAT_H_
...@@ -77,9 +78,9 @@ typedef struct { ...@@ -77,9 +78,9 @@ typedef struct {
// ----------------- TSDB SCHEMA DEFINITION // ----------------- TSDB SCHEMA DEFINITION
typedef struct { typedef struct {
int version; // version int32_t version; // version
int numOfCols; // Number of columns appended int32_t numOfCols; // Number of columns appended
int tlen; // maximum length of a STpRow without the header part (sizeof(VarDataOffsetT) + sizeof(VarDataLenT) + int32_t tlen; // maximum length of a STpRow without the header part (sizeof(VarDataOffsetT) + sizeof(VarDataLenT) +
// (bytes)) // (bytes))
uint16_t flen; // First part length in a STpRow after the header part uint16_t flen; // First part length in a STpRow after the header part
uint16_t vlen; // pure value part length, excluded the overhead (bytes only) uint16_t vlen; // pure value part length, excluded the overhead (bytes only)
...@@ -95,10 +96,10 @@ typedef struct { ...@@ -95,10 +96,10 @@ typedef struct {
#define tdFreeSchema(s) tfree((s)) #define tdFreeSchema(s) tfree((s))
STSchema *tdDupSchema(const STSchema *pSchema); STSchema *tdDupSchema(const STSchema *pSchema);
int tdEncodeSchema(void **buf, STSchema *pSchema); int32_t tdEncodeSchema(void **buf, STSchema *pSchema);
void * tdDecodeSchema(void *buf, STSchema **pRSchema); void *tdDecodeSchema(void *buf, STSchema **pRSchema);
static FORCE_INLINE int comparColId(const void *key1, const void *key2) { static FORCE_INLINE int32_t comparColId(const void *key1, const void *key2) {
if (*(int16_t *)key1 > ((STColumn *)key2)->colId) { if (*(int16_t *)key1 > ((STColumn *)key2)->colId) {
return 1; return 1;
} else if (*(int16_t *)key1 < ((STColumn *)key2)->colId) { } else if (*(int16_t *)key1 < ((STColumn *)key2)->colId) {
...@@ -116,12 +117,12 @@ static FORCE_INLINE STColumn *tdGetColOfID(STSchema *pSchema, int16_t colId) { ...@@ -116,12 +117,12 @@ static FORCE_INLINE STColumn *tdGetColOfID(STSchema *pSchema, int16_t colId) {
// ----------------- SCHEMA BUILDER DEFINITION // ----------------- SCHEMA BUILDER DEFINITION
typedef struct { typedef struct {
int tCols; int32_t tCols;
int nCols; int32_t nCols;
int tlen; int32_t tlen;
uint16_t flen; uint16_t flen;
uint16_t vlen; uint16_t vlen;
int version; int32_t version;
STColumn *columns; STColumn *columns;
} STSchemaBuilder; } STSchemaBuilder;
...@@ -132,10 +133,10 @@ typedef struct { ...@@ -132,10 +133,10 @@ typedef struct {
#define TD_BITMAP_BYTES(cnt) (ceil((double)cnt / TD_VTYPE_PARTS)) #define TD_BITMAP_BYTES(cnt) (ceil((double)cnt / TD_VTYPE_PARTS))
#define TD_BIT_TO_BYTES(cnt) (ceil((double)cnt / 8)) #define TD_BIT_TO_BYTES(cnt) (ceil((double)cnt / 8))
int tdInitTSchemaBuilder(STSchemaBuilder *pBuilder, int32_t version); int32_t tdInitTSchemaBuilder(STSchemaBuilder *pBuilder, int32_t version);
void tdDestroyTSchemaBuilder(STSchemaBuilder *pBuilder); void tdDestroyTSchemaBuilder(STSchemaBuilder *pBuilder);
void tdResetTSchemaBuilder(STSchemaBuilder *pBuilder, int32_t version); void tdResetTSchemaBuilder(STSchemaBuilder *pBuilder, int32_t version);
int tdAddColToSchema(STSchemaBuilder *pBuilder, int8_t type, int16_t colId, int16_t bytes); int32_t tdAddColToSchema(STSchemaBuilder *pBuilder, int8_t type, int16_t colId, int16_t bytes);
STSchema *tdGetSchemaFromBuilder(STSchemaBuilder *pBuilder); STSchema *tdGetSchemaFromBuilder(STSchemaBuilder *pBuilder);
// ----------------- Semantic timestamp key definition // ----------------- Semantic timestamp key definition
...@@ -194,7 +195,7 @@ static FORCE_INLINE TKEY keyToTkey(TSKEY key) { ...@@ -194,7 +195,7 @@ static FORCE_INLINE TKEY keyToTkey(TSKEY key) {
return tdGetTKEY(lkey); return tdGetTKEY(lkey);
} }
static FORCE_INLINE int tkeyComparFn(const void *tkey1, const void *tkey2) { static FORCE_INLINE int32_t tkeyComparFn(const void *tkey1, const void *tkey2) {
TSKEY key1 = tdGetKey(*(TKEY *)tkey1); TSKEY key1 = tdGetKey(*(TKEY *)tkey1);
TSKEY key2 = tdGetKey(*(TKEY *)tkey2); TSKEY key2 = tdGetKey(*(TKEY *)tkey2);
...@@ -243,7 +244,7 @@ void tdInitDataRow(SDataRow row, STSchema *pSchema); ...@@ -243,7 +244,7 @@ void tdInitDataRow(SDataRow row, STSchema *pSchema);
SDataRow tdDataRowDup(SDataRow row); SDataRow tdDataRowDup(SDataRow row);
// offset here not include dataRow header length // offset here not include dataRow header length
static FORCE_INLINE int tdAppendDataColVal(SDataRow row, const void *value, bool isCopyVarData, int8_t type, static FORCE_INLINE int32_t tdAppendDataColVal(SDataRow row, const void *value, bool isCopyVarData, int8_t type,
int32_t offset) { int32_t offset) {
assert(value != NULL); assert(value != NULL);
int32_t toffset = offset + TD_DATA_ROW_HEAD_SIZE; int32_t toffset = offset + TD_DATA_ROW_HEAD_SIZE;
...@@ -268,7 +269,7 @@ static FORCE_INLINE int tdAppendDataColVal(SDataRow row, const void *value, bool ...@@ -268,7 +269,7 @@ static FORCE_INLINE int tdAppendDataColVal(SDataRow row, const void *value, bool
} }
// offset here not include dataRow header length // offset here not include dataRow header length
static FORCE_INLINE int tdAppendColVal(SDataRow row, const void *value, int8_t type, int32_t offset) { static FORCE_INLINE int32_t tdAppendColVal(SDataRow row, const void *value, int8_t type, int32_t offset) {
return tdAppendDataColVal(row, value, true, type, offset); return tdAppendDataColVal(row, value, true, type, offset);
} }
...@@ -281,25 +282,25 @@ static FORCE_INLINE void *tdGetRowDataOfCol(SDataRow row, int8_t type, int32_t o ...@@ -281,25 +282,25 @@ static FORCE_INLINE void *tdGetRowDataOfCol(SDataRow row, int8_t type, int32_t o
} }
} }
static FORCE_INLINE void *tdGetPtrToCol(SDataRow row, STSchema *pSchema, int idx) { static FORCE_INLINE void *tdGetPtrToCol(SDataRow row, STSchema *pSchema, int32_t idx) {
return POINTER_SHIFT(row, TD_DATA_ROW_HEAD_SIZE + pSchema->columns[idx].offset); return POINTER_SHIFT(row, TD_DATA_ROW_HEAD_SIZE + pSchema->columns[idx].offset);
} }
static FORCE_INLINE void *tdGetColOfRowBySchema(SDataRow row, STSchema *pSchema, int idx) { static FORCE_INLINE void *tdGetColOfRowBySchema(SDataRow row, STSchema *pSchema, int32_t idx) {
int16_t offset = TD_DATA_ROW_HEAD_SIZE + pSchema->columns[idx].offset; int16_t offset = TD_DATA_ROW_HEAD_SIZE + pSchema->columns[idx].offset;
int8_t type = pSchema->columns[idx].type; int8_t type = pSchema->columns[idx].type;
return tdGetRowDataOfCol(row, type, offset); return tdGetRowDataOfCol(row, type, offset);
} }
static FORCE_INLINE bool tdIsColOfRowNullBySchema(SDataRow row, STSchema *pSchema, int idx) { static FORCE_INLINE bool tdIsColOfRowNullBySchema(SDataRow row, STSchema *pSchema, int32_t idx) {
int16_t offset = TD_DATA_ROW_HEAD_SIZE + pSchema->columns[idx].offset; int16_t offset = TD_DATA_ROW_HEAD_SIZE + pSchema->columns[idx].offset;
int8_t type = pSchema->columns[idx].type; int8_t type = pSchema->columns[idx].type;
return isNull(tdGetRowDataOfCol(row, type, offset), type); return isNull(tdGetRowDataOfCol(row, type, offset), type);
} }
static FORCE_INLINE void tdSetColOfRowNullBySchema(SDataRow row, STSchema *pSchema, int idx) { static FORCE_INLINE void tdSetColOfRowNullBySchema(SDataRow row, STSchema *pSchema, int32_t idx) {
int16_t offset = TD_DATA_ROW_HEAD_SIZE + pSchema->columns[idx].offset; int16_t offset = TD_DATA_ROW_HEAD_SIZE + pSchema->columns[idx].offset;
int8_t type = pSchema->columns[idx].type; int8_t type = pSchema->columns[idx].type;
int16_t bytes = pSchema->columns[idx].bytes; int16_t bytes = pSchema->columns[idx].bytes;
...@@ -307,8 +308,8 @@ static FORCE_INLINE void tdSetColOfRowNullBySchema(SDataRow row, STSchema *pSche ...@@ -307,8 +308,8 @@ static FORCE_INLINE void tdSetColOfRowNullBySchema(SDataRow row, STSchema *pSche
setNull(tdGetRowDataOfCol(row, type, offset), type, bytes); setNull(tdGetRowDataOfCol(row, type, offset), type, bytes);
} }
static FORCE_INLINE void tdCopyColOfRowBySchema(SDataRow dst, STSchema *pDstSchema, int dstIdx, SDataRow src, static FORCE_INLINE void tdCopyColOfRowBySchema(SDataRow dst, STSchema *pDstSchema, int32_t dstIdx, SDataRow src,
STSchema *pSrcSchema, int srcIdx) { STSchema *pSrcSchema, int32_t srcIdx) {
int8_t type = pDstSchema->columns[dstIdx].type; int8_t type = pDstSchema->columns[dstIdx].type;
assert(type == pSrcSchema->columns[srcIdx].type); assert(type == pSrcSchema->columns[srcIdx].type);
void *pData = tdGetPtrToCol(dst, pDstSchema, dstIdx); void *pData = tdGetPtrToCol(dst, pDstSchema, dstIdx);
...@@ -364,13 +365,13 @@ typedef struct SDataCol { ...@@ -364,13 +365,13 @@ typedef struct SDataCol {
uint8_t bitmap : 1; // 0: has bitmap if has NULL/NORM rows, 1: no bitmap if all rows are NORM uint8_t bitmap : 1; // 0: has bitmap if has NULL/NORM rows, 1: no bitmap if all rows are NORM
uint8_t reserve : 7; uint8_t reserve : 7;
int16_t colId; // column ID int16_t colId; // column ID
int bytes; // column data bytes defined int32_t bytes; // column data bytes defined
int offset; // data offset in a SDataRow (including the header size) int32_t offset; // data offset in a SDataRow (including the header size)
int spaceSize; // Total space size for this column int32_t spaceSize; // Total space size for this column
int len; // column data length int32_t len; // column data length
VarDataOffsetT *dataOff; // For binary and nchar data, the offset in the data column VarDataOffsetT *dataOff; // For binary and nchar data, the offset in the data column
void * pData; // Actual data pointer void *pData; // Actual data pointer
void * pBitmap; // Bitmap pointer void *pBitmap; // Bitmap pointer
TSKEY ts; // only used in last NULL column TSKEY ts; // only used in last NULL column
} SDataCol; } SDataCol;
...@@ -378,17 +379,17 @@ typedef struct SDataCol { ...@@ -378,17 +379,17 @@ typedef struct SDataCol {
#define isAllRowsNone(pCol) ((pCol)->len == 0) #define isAllRowsNone(pCol) ((pCol)->len == 0)
static FORCE_INLINE void dataColReset(SDataCol *pDataCol) { pDataCol->len = 0; } static FORCE_INLINE void dataColReset(SDataCol *pDataCol) { pDataCol->len = 0; }
int tdAllocMemForCol(SDataCol *pCol, int maxPoints); int32_t tdAllocMemForCol(SDataCol *pCol, int32_t maxPoints);
void dataColInit(SDataCol *pDataCol, STColumn *pCol, int maxPoints); void dataColInit(SDataCol *pDataCol, STColumn *pCol, int32_t maxPoints);
int dataColAppendVal(SDataCol *pCol, const void *value, int numOfRows, int maxPoints); int32_t dataColAppendVal(SDataCol *pCol, const void *value, int32_t numOfRows, int32_t maxPoints);
void *dataColSetOffset(SDataCol *pCol, int nEle); void *dataColSetOffset(SDataCol *pCol, int32_t nEle);
bool isNEleNull(SDataCol *pCol, int nEle); bool isNEleNull(SDataCol *pCol, int32_t nEle);
#if 0 #if 0
// Get the data pointer from a column-wised data // Get the data pointer from a column-wised data
static FORCE_INLINE const void *tdGetColDataOfRow(SDataCol *pCol, int row) { static FORCE_INLINE const void *tdGetColDataOfRow(SDataCol *pCol, int32_t row) {
if (isAllRowsNull(pCol)) { if (isAllRowsNull(pCol)) {
return getNullValue(pCol->type); return getNullValue(pCol->type);
} }
...@@ -399,7 +400,7 @@ static FORCE_INLINE const void *tdGetColDataOfRow(SDataCol *pCol, int row) { ...@@ -399,7 +400,7 @@ static FORCE_INLINE const void *tdGetColDataOfRow(SDataCol *pCol, int row) {
} }
} }
static FORCE_INLINE int32_t dataColGetNEleLen(SDataCol *pDataCol, int rows) { static FORCE_INLINE int32_t dataColGetNEleLen(SDataCol *pDataCol, int32_t rows) {
assert(rows > 0); assert(rows > 0);
if (IS_VAR_DATA_TYPE(pDataCol->type)) { if (IS_VAR_DATA_TYPE(pDataCol->type)) {
...@@ -412,9 +413,9 @@ static FORCE_INLINE int32_t dataColGetNEleLen(SDataCol *pDataCol, int rows) { ...@@ -412,9 +413,9 @@ static FORCE_INLINE int32_t dataColGetNEleLen(SDataCol *pDataCol, int rows) {
typedef struct { typedef struct {
col_id_t maxCols; // max number of columns col_id_t maxCols; // max number of columns
col_id_t numOfCols; // Total number of cols col_id_t numOfCols; // Total number of cols
int maxPoints; // max number of points int32_t maxPoints; // max number of points
int numOfRows; int32_t numOfRows;
int sversion; // TODO: set sversion int32_t sversion; // TODO: set sversion
SDataCol *cols; SDataCol *cols;
} SDataCols; } SDataCols;
...@@ -429,7 +430,7 @@ static FORCE_INLINE TKEY dataColsTKeyFirst(SDataCols *pCols) { ...@@ -429,7 +430,7 @@ static FORCE_INLINE TKEY dataColsTKeyFirst(SDataCols *pCols) {
} }
} }
static FORCE_INLINE TSKEY dataColsKeyAtRow(SDataCols *pCols, int row) { static FORCE_INLINE TSKEY dataColsKeyAtRow(SDataCols *pCols, int32_t row) {
assert(row < pCols->numOfRows); assert(row < pCols->numOfRows);
return dataColsKeyAt(pCols, row); return dataColsKeyAt(pCols, row);
} }
...@@ -458,12 +459,12 @@ static FORCE_INLINE TSKEY dataColsKeyLast(SDataCols *pCols) { ...@@ -458,12 +459,12 @@ static FORCE_INLINE TSKEY dataColsKeyLast(SDataCols *pCols) {
} }
} }
SDataCols *tdNewDataCols(int maxCols, int maxRows); SDataCols *tdNewDataCols(int32_t maxCols, int32_t maxRows);
void tdResetDataCols(SDataCols *pCols); void tdResetDataCols(SDataCols *pCols);
int tdInitDataCols(SDataCols *pCols, STSchema *pSchema); int32_t tdInitDataCols(SDataCols *pCols, STSchema *pSchema);
SDataCols *tdDupDataCols(SDataCols *pCols, bool keepData); SDataCols *tdDupDataCols(SDataCols *pCols, bool keepData);
SDataCols *tdFreeDataCols(SDataCols *pCols); SDataCols *tdFreeDataCols(SDataCols *pCols);
int tdMergeDataCols(SDataCols *target, SDataCols *source, int rowsToMerge, int *pOffset, bool forceSetNull); int32_t tdMergeDataCols(SDataCols *target, SDataCols *source, int32_t rowsToMerge, int32_t *pOffset, bool forceSetNull);
// ----------------- K-V data row structure // ----------------- K-V data row structure
/* |<-------------------------------------- len -------------------------------------------->| /* |<-------------------------------------- len -------------------------------------------->|
...@@ -501,12 +502,12 @@ typedef struct { ...@@ -501,12 +502,12 @@ typedef struct {
#define kvRowDeleted(r) TKEY_IS_DELETED(kvRowTKey(r)) #define kvRowDeleted(r) TKEY_IS_DELETED(kvRowTKey(r))
SKVRow tdKVRowDup(SKVRow row); SKVRow tdKVRowDup(SKVRow row);
int tdSetKVRowDataOfCol(SKVRow *orow, int16_t colId, int8_t type, void *value); int32_t tdSetKVRowDataOfCol(SKVRow *orow, int16_t colId, int8_t type, void *value);
int tdEncodeKVRow(void **buf, SKVRow row); int32_t tdEncodeKVRow(void **buf, SKVRow row);
void * tdDecodeKVRow(void *buf, SKVRow *row); void *tdDecodeKVRow(void *buf, SKVRow *row);
void tdSortKVRowByColIdx(SKVRow row); void tdSortKVRowByColIdx(SKVRow row);
static FORCE_INLINE int comparTagId(const void *key1, const void *key2) { static FORCE_INLINE int32_t comparTagId(const void *key1, const void *key2) {
if (*(int16_t *)key1 > ((SColIdx *)key2)->colId) { if (*(int16_t *)key1 > ((SColIdx *)key2)->colId) {
return 1; return 1;
} else if (*(int16_t *)key1 < ((SColIdx *)key2)->colId) { } else if (*(int16_t *)key1 < ((SColIdx *)key2)->colId) {
...@@ -528,7 +529,7 @@ static FORCE_INLINE void *tdGetKVRowIdxOfCol(SKVRow row, int16_t colId) { ...@@ -528,7 +529,7 @@ static FORCE_INLINE void *tdGetKVRowIdxOfCol(SKVRow row, int16_t colId) {
#if 0 #if 0
// offset here not include kvRow header length // offset here not include kvRow header length
static FORCE_INLINE int tdAppendKvColVal(SKVRow row, const void *value, bool isCopyValData, int16_t colId, int8_t type, static FORCE_INLINE int32_t tdAppendKvColVal(SKVRow row, const void *value, bool isCopyValData, int16_t colId, int8_t type,
int32_t offset) { int32_t offset) {
assert(value != NULL); assert(value != NULL);
int32_t toffset = offset + TD_KV_ROW_HEAD_SIZE; int32_t toffset = offset + TD_KV_ROW_HEAD_SIZE;
...@@ -581,15 +582,15 @@ typedef struct { ...@@ -581,15 +582,15 @@ typedef struct {
SColIdx *pColIdx; SColIdx *pColIdx;
uint16_t alloc; uint16_t alloc;
uint16_t size; uint16_t size;
void * buf; void *buf;
} SKVRowBuilder; } SKVRowBuilder;
int tdInitKVRowBuilder(SKVRowBuilder *pBuilder); int32_t tdInitKVRowBuilder(SKVRowBuilder *pBuilder);
void tdDestroyKVRowBuilder(SKVRowBuilder *pBuilder); void tdDestroyKVRowBuilder(SKVRowBuilder *pBuilder);
void tdResetKVRowBuilder(SKVRowBuilder *pBuilder); void tdResetKVRowBuilder(SKVRowBuilder *pBuilder);
SKVRow tdGetKVRowFromBuilder(SKVRowBuilder *pBuilder); SKVRow tdGetKVRowFromBuilder(SKVRowBuilder *pBuilder);
static FORCE_INLINE int tdAddColToKVRow(SKVRowBuilder *pBuilder, int16_t colId, int8_t type, const void *value) { static FORCE_INLINE int32_t tdAddColToKVRow(SKVRowBuilder *pBuilder, int16_t colId, int8_t type, const void *value) {
if (pBuilder->nCols >= pBuilder->tCols) { if (pBuilder->nCols >= pBuilder->tCols) {
pBuilder->tCols *= 2; pBuilder->tCols *= 2;
SColIdx *pColIdx = (SColIdx *)realloc((void *)(pBuilder->pColIdx), sizeof(SColIdx) * pBuilder->tCols); SColIdx *pColIdx = (SColIdx *)realloc((void *)(pBuilder->pColIdx), sizeof(SColIdx) * pBuilder->tCols);
...@@ -602,7 +603,7 @@ static FORCE_INLINE int tdAddColToKVRow(SKVRowBuilder *pBuilder, int16_t colId, ...@@ -602,7 +603,7 @@ static FORCE_INLINE int tdAddColToKVRow(SKVRowBuilder *pBuilder, int16_t colId,
pBuilder->nCols++; pBuilder->nCols++;
int tlen = IS_VAR_DATA_TYPE(type) ? varDataTLen(value) : TYPE_BYTES[type]; int32_t tlen = IS_VAR_DATA_TYPE(type) ? varDataTLen(value) : TYPE_BYTES[type];
if (tlen > pBuilder->alloc - pBuilder->size) { if (tlen > pBuilder->alloc - pBuilder->size) {
while (tlen > pBuilder->alloc - pBuilder->size) { while (tlen > pBuilder->alloc - pBuilder->size) {
pBuilder->alloc *= 2; pBuilder->alloc *= 2;
...@@ -736,7 +737,7 @@ static FORCE_INLINE void *tdGetMemRowDataOfColEx(void *row, int16_t colId, int8_ ...@@ -736,7 +737,7 @@ static FORCE_INLINE void *tdGetMemRowDataOfColEx(void *row, int16_t colId, int8_
} }
} }
static FORCE_INLINE int tdAppendMemRowColVal(SMemRow row, const void *value, bool isCopyVarData, int16_t colId, static FORCE_INLINE int32_t tdAppendMemRowColVal(SMemRow row, const void *value, bool isCopyVarData, int16_t colId,
int8_t type, int32_t offset) { int8_t type, int32_t offset) {
if (isDataRow(row)) { if (isDataRow(row)) {
tdAppendDataColVal(memRowDataBody(row), value, isCopyVarData, type, offset); tdAppendDataColVal(memRowDataBody(row), value, isCopyVarData, type, offset);
......
#ifndef TDENGINE_TEP_H /*
#define TDENGINE_TEP_H * 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/>.
*/
#ifndef _TD_COMMON_EP_H_
#define _TD_COMMON_EP_H_
#include "tcommon.h"
#include "tmsg.h"
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C" {
#endif #endif
#include "os.h"
#include "tmsg.h"
#include "common.h"
typedef struct SCorEpSet { typedef struct SCorEpSet {
int32_t version; int32_t version;
SEpSet epSet; SEpSet epSet;
...@@ -17,19 +31,16 @@ typedef struct SCorEpSet { ...@@ -17,19 +31,16 @@ typedef struct SCorEpSet {
typedef struct SBlockOrderInfo { typedef struct SBlockOrderInfo {
int32_t order; int32_t order;
int32_t colIndex; int32_t colIndex;
SColumnInfoData *pColData; SColumnInfoData* pColData;
// int32_t type;
// int32_t bytes;
// bool hasNull;
} SBlockOrderInfo; } SBlockOrderInfo;
int taosGetFqdnPortFromEp(const char *ep, SEp *pEp); int32_t taosGetFqdnPortFromEp(const char* ep, SEp* pEp);
void addEpIntoEpSet(SEpSet *pEpSet, const char *fqdn, uint16_t port); void addEpIntoEpSet(SEpSet* pEpSet, const char* fqdn, uint16_t port);
bool isEpsetEqual(const SEpSet *s1, const SEpSet *s2); bool isEpsetEqual(const SEpSet* s1, const SEpSet* s2);
void updateEpSet_s(SCorEpSet *pEpSet, SEpSet *pNewEpSet); void updateEpSet_s(SCorEpSet* pEpSet, SEpSet* pNewEpSet);
SEpSet getEpSet_s(SCorEpSet *pEpSet); SEpSet getEpSet_s(SCorEpSet* pEpSet);
#define NBIT (3u) #define NBIT (3u)
#define BitPos(_n) ((_n) & ((1 << NBIT) - 1)) #define BitPos(_n) ((_n) & ((1 << NBIT) - 1))
...@@ -41,7 +52,8 @@ SEpSet getEpSet_s(SCorEpSet *pEpSet); ...@@ -41,7 +52,8 @@ SEpSet getEpSet_s(SCorEpSet *pEpSet);
BMCharPos(bm_, r_) |= (1u << (7u - BitPos(r_))); \ BMCharPos(bm_, r_) |= (1u << (7u - BitPos(r_))); \
} while (0) } while (0)
static FORCE_INLINE bool colDataIsNull(const SColumnInfoData* pColumnInfoData, uint32_t totalRows, uint32_t row, SColumnDataAgg* pColAgg) { static FORCE_INLINE bool colDataIsNull(const SColumnInfoData* pColumnInfoData, uint32_t totalRows, uint32_t row,
SColumnDataAgg* pColAgg) {
if (!pColumnInfoData->hasNull) { if (!pColumnInfoData->hasNull) {
return false; return false;
} }
...@@ -67,22 +79,27 @@ static FORCE_INLINE bool colDataIsNull(const SColumnInfoData* pColumnInfoData, u ...@@ -67,22 +79,27 @@ static FORCE_INLINE bool colDataIsNull(const SColumnInfoData* pColumnInfoData, u
} }
} }
#define colDataGet(p1_, r_) \ #define BitmapLen(_n) (((_n) + ((1<<NBIT)-1)) >> NBIT)
((IS_VAR_DATA_TYPE((p1_)->info.type)) ? (p1_)->pData + (p1_)->varmeta.offset[(r_)] \
: (p1_)->pData + ((r_) * (p1_)->info.bytes));
#define colDataGetData(p1_, r_) \
((IS_VAR_DATA_TYPE((p1_)->info.type)) ? ((p1_)->pData + (p1_)->varmeta.offset[(r_)]) \
: ((p1_)->pData + ((r_) * (p1_)->info.bytes)))
int32_t colDataAppend(SColumnInfoData* pColumnInfoData, uint32_t currentRow, const char* pData, bool isNull); int32_t colDataAppend(SColumnInfoData* pColumnInfoData, uint32_t currentRow, const char* pData, bool isNull);
int32_t colDataMergeCol(SColumnInfoData* pColumnInfoData, uint32_t numOfRow1, const SColumnInfoData* pSource, uint32_t numOfRow2); int32_t colDataMergeCol(SColumnInfoData* pColumnInfoData, uint32_t numOfRow1, const SColumnInfoData* pSource,
uint32_t numOfRow2);
int32_t blockDataUpdateTsWindow(SSDataBlock* pDataBlock); int32_t blockDataUpdateTsWindow(SSDataBlock* pDataBlock);
int32_t colDataGetSize(const SColumnInfoData* pColumnInfoData, int32_t numOfRows); int32_t colDataGetLength(const SColumnInfoData* pColumnInfoData, int32_t numOfRows);
void colDataTrim(SColumnInfoData* pColumnInfoData); void colDataTrim(SColumnInfoData* pColumnInfoData);
size_t colDataGetNumOfCols(const SSDataBlock* pBlock); size_t colDataGetNumOfCols(const SSDataBlock* pBlock);
size_t colDataGetNumOfRows(const SSDataBlock* pBlock); size_t colDataGetNumOfRows(const SSDataBlock* pBlock);
int32_t blockDataMerge(SSDataBlock* pDest, const SSDataBlock* pSrc); int32_t blockDataMerge(SSDataBlock* pDest, const SSDataBlock* pSrc);
int32_t blockDataSplitRows(SSDataBlock* pBlock, bool hasVarCol, int32_t startIndex, int32_t* stopIndex, int32_t pageSize); int32_t blockDataSplitRows(SSDataBlock* pBlock, bool hasVarCol, int32_t startIndex, int32_t* stopIndex,
int32_t pageSize);
SSDataBlock* blockDataExtractBlock(SSDataBlock* pBlock, int32_t startIndex, int32_t rowCount); SSDataBlock* blockDataExtractBlock(SSDataBlock* pBlock, int32_t startIndex, int32_t rowCount);
int32_t blockDataToBuf(char* buf, const SSDataBlock* pBlock); int32_t blockDataToBuf(char* buf, const SSDataBlock* pBlock);
...@@ -93,17 +110,20 @@ size_t blockDataGetRowSize(const SSDataBlock* pBlock); ...@@ -93,17 +110,20 @@ size_t blockDataGetRowSize(const SSDataBlock* pBlock);
double blockDataGetSerialRowSize(const SSDataBlock* pBlock); double blockDataGetSerialRowSize(const SSDataBlock* pBlock);
size_t blockDataGetSerialMetaSize(const SSDataBlock* pBlock); size_t blockDataGetSerialMetaSize(const SSDataBlock* pBlock);
size_t blockDataNumOfRowsForSerialize(const SSDataBlock* pBlock, int32_t blockSize); SSchema* blockDataExtractSchema(const SSDataBlock* pBlock, int32_t* numOfCols);
int32_t blockDataSort(SSDataBlock* pDataBlock, SArray* pOrderInfo, bool nullFirst); int32_t blockDataSort(SSDataBlock* pDataBlock, SArray* pOrderInfo, bool nullFirst);
int32_t blockDataSort_rv(SSDataBlock* pDataBlock, SArray* pOrderInfo, bool nullFirst); int32_t blockDataSort_rv(SSDataBlock* pDataBlock, SArray* pOrderInfo, bool nullFirst);
int32_t blockDataEnsureColumnCapacity(SColumnInfoData* pColumn, uint32_t numOfRows);
int32_t blockDataEnsureCapacity(SSDataBlock* pDataBlock, uint32_t numOfRows); int32_t blockDataEnsureCapacity(SSDataBlock* pDataBlock, uint32_t numOfRows);
void blockDataClearup(SSDataBlock* pDataBlock, bool hasVarCol); void blockDataClearup(SSDataBlock* pDataBlock, bool hasVarCol);
void *blockDataDestroy(SSDataBlock *pBlock); SSDataBlock* createOneDataBlock(const SSDataBlock* pDataBlock);
size_t blockDataGetCapacityInRow(const SSDataBlock* pBlock, size_t pageSize);
void* blockDataDestroy(SSDataBlock* pBlock);
#ifdef __cplusplus #ifdef __cplusplus
} }
#endif #endif
#endif // TDENGINE_TEP_H #endif /*_TD_COMMON_EP_H_*/
...@@ -16,57 +16,52 @@ ...@@ -16,57 +16,52 @@
#ifndef _TD_COMMON_GLOBAL_H_ #ifndef _TD_COMMON_GLOBAL_H_
#define _TD_COMMON_GLOBAL_H_ #define _TD_COMMON_GLOBAL_H_
#include "tarray.h"
#include "tdef.h"
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C" {
#endif #endif
#include "tdef.h"
#include "tcfg.h"
// cluster // cluster
extern char tsFirst[]; extern char tsFirst[];
extern char tsSecond[]; extern char tsSecond[];
extern char tsLocalFqdn[]; extern char tsLocalFqdn[];
extern char tsLocalEp[]; extern char tsLocalEp[];
extern uint16_t tsServerPort; extern uint16_t tsServerPort;
extern int32_t tsVersion;
extern int32_t tsStatusInterval; extern int32_t tsStatusInterval;
extern int8_t tsEnableTelemetryReporting; extern bool tsEnableTelemetryReporting;
extern int32_t tsNumOfSupportVnodes;
// common // common
extern int tsRpcTimer; extern int32_t tsRpcTimer;
extern int tsRpcMaxTime; extern int32_t tsRpcMaxTime;
extern int tsRpcForceTcp; // all commands go to tcp protocol if this is enabled extern bool tsRpcForceTcp; // all commands go to tcp protocol if this is enabled
extern int32_t tsMaxConnections; extern int32_t tsMaxConnections;
extern int32_t tsMaxShellConns; extern int32_t tsMaxShellConns;
extern int32_t tsShellActivityTimer; extern int32_t tsShellActivityTimer;
extern uint32_t tsMaxTmrCtrl; extern int32_t tsMaxTmrCtrl;
extern float tsNumOfThreadsPerCore; extern float tsNumOfThreadsPerCore;
extern int32_t tsNumOfCommitThreads; extern int32_t tsNumOfCommitThreads;
extern float tsRatioOfQueryCores; extern float tsRatioOfQueryCores;
extern int8_t tsDaylight;
extern int8_t tsEnableCoreFile;
extern int32_t tsCompressMsgSize; extern int32_t tsCompressMsgSize;
extern int32_t tsCompressColData; extern int32_t tsCompressColData;
extern int32_t tsMaxNumOfDistinctResults; extern int32_t tsMaxNumOfDistinctResults;
extern char tsTempDir[]; extern int32_t tsCompatibleModel;
extern int tsCompatibleModel; // 2.0 compatible model extern bool tsEnableSlaveQuery;
extern int8_t tsEnableSlaveQuery; extern bool tsPrintAuth;
extern int8_t tsEnableAdjustMaster;
extern int8_t tsPrintAuth;
extern int64_t tsTickPerDay[3]; extern int64_t tsTickPerDay[3];
// query buffer management // query buffer management
extern int32_t tsQueryBufferSize; // maximum allowed usage buffer size in MB for each data node during query processing extern int32_t tsQueryBufferSize; // maximum allowed usage buffer size in MB for each data node during query processing
extern int64_t tsQueryBufferSizeBytes; // maximum allowed usage buffer size in byte for each data node extern int64_t tsQueryBufferSizeBytes; // maximum allowed usage buffer size in byte for each data node
extern int32_t tsRetrieveBlockingModel; // retrieve threads will be blocked extern bool tsRetrieveBlockingModel; // retrieve threads will be blocked
extern int8_t tsKeepOriginalColumnName; extern bool tsKeepOriginalColumnName;
extern int8_t tsDeadLockKillQuery; extern bool tsDeadLockKillQuery;
// client // client
extern int32_t tsMaxWildCardsLen; extern int32_t tsMaxWildCardsLen;
extern int32_t tsMaxRegexStringLen; extern int32_t tsMaxRegexStringLen;
extern int8_t tsTscEnableRecordSql;
extern int32_t tsMaxNumOfOrderedResults; extern int32_t tsMaxNumOfOrderedResults;
extern int32_t tsMinSlidingTime; extern int32_t tsMinSlidingTime;
extern int32_t tsMinIntervalTime; extern int32_t tsMinIntervalTime;
...@@ -77,19 +72,6 @@ extern float tsStreamComputDelayRatio; // the delayed computing ration of the ...@@ -77,19 +72,6 @@ extern float tsStreamComputDelayRatio; // the delayed computing ration of the
extern int32_t tsProjectExecInterval; extern int32_t tsProjectExecInterval;
extern int64_t tsMaxRetentWindow; extern int64_t tsMaxRetentWindow;
// system info
extern float tsTotalLogDirGB;
extern float tsTotalTmpDirGB;
extern float tsTotalDataDirGB;
extern float tsAvailLogDirGB;
extern float tsAvailTmpDirectorySpace;
extern float tsAvailDataDirGB;
extern float tsUsedDataDirGB;
extern float tsMinimalLogDirGB;
extern float tsReservedTmpDirectorySpace;
extern float tsMinimalDataDirGB;
extern uint32_t tsVersion;
// build info // build info
extern char version[]; extern char version[];
extern char compatible_version[]; extern char compatible_version[];
...@@ -105,18 +87,19 @@ extern uint32_t tsMaxRange; ...@@ -105,18 +87,19 @@ extern uint32_t tsMaxRange;
extern uint32_t tsCurRange; extern uint32_t tsCurRange;
extern char tsCompressor[]; extern char tsCompressor[];
// tfs
extern int32_t tsDiskCfgNum; extern int32_t tsDiskCfgNum;
extern SDiskCfg tsDiskCfg[]; extern SDiskCfg tsDiskCfg[];
#define NEEDTO_COMPRESSS_MSG(size) (tsCompressMsgSize != -1 && (size) > tsCompressMsgSize) #define NEEDTO_COMPRESSS_MSG(size) (tsCompressMsgSize != -1 && (size) > tsCompressMsgSize)
void taosInitGlobalCfg(); int32_t taosCreateLog(const char *logname, int32_t logFileNum, const char *cfgDir, const char *envFile,
int32_t taosCheckAndPrintCfg(); const char *apolloUrl, SArray *pArgs, bool tsc);
int32_t taosCfgDynamicOptions(char *msg); int32_t taosInitCfg(const char *cfgDir, const char *envFile, const char *apolloUrl, SArray *pArgs, bool tsc);
bool taosCheckBalanceCfgOptions(const char *option, int32_t *vnodeId, int32_t *dnodeId); void taosCleanupCfg();
void taosAddDataDir(int index, char *v1, int level, int primary); void taosCfgDynamicOptions(const char *option, const char *value);
void taosReadDataDirCfg(char *v1, char *v2, char *v3);
void taosPrintDataDirCfg(); struct SConfig *taosGetCfg();
#ifdef __cplusplus #ifdef __cplusplus
} }
......
...@@ -16,19 +16,19 @@ ...@@ -16,19 +16,19 @@
#ifndef _TD_COMMON_TAOS_MSG_H_ #ifndef _TD_COMMON_TAOS_MSG_H_
#define _TD_COMMON_TAOS_MSG_H_ #define _TD_COMMON_TAOS_MSG_H_
#ifdef __cplusplus
extern "C" {
#endif
#include "encode.h"
#include "taosdef.h" #include "taosdef.h"
#include "taoserror.h" #include "taoserror.h"
#include "tarray.h" #include "tarray.h"
#include "tcoding.h" #include "tcoding.h"
#include "tencode.h"
#include "thash.h" #include "thash.h"
#include "tlist.h" #include "tlist.h"
#include "trow.h" #include "trow.h"
#ifdef __cplusplus
extern "C" {
#endif
/* ------------------------ MESSAGE DEFINITIONS ------------------------ */ /* ------------------------ MESSAGE DEFINITIONS ------------------------ */
#define TD_MSG_NUMBER_ #define TD_MSG_NUMBER_
#undef TD_MSG_DICT_ #undef TD_MSG_DICT_
...@@ -49,7 +49,7 @@ extern "C" { ...@@ -49,7 +49,7 @@ extern "C" {
#include "tmsgdef.h" #include "tmsgdef.h"
extern char* tMsgInfo[]; extern char* tMsgInfo[];
extern int tMsgDict[]; extern int32_t tMsgDict[];
#define TMSG_SEG_CODE(TYPE) (((TYPE)&0xff00) >> 8) #define TMSG_SEG_CODE(TYPE) (((TYPE)&0xff00) >> 8)
#define TMSG_SEG_SEQ(TYPE) ((TYPE)&0xff) #define TMSG_SEG_SEQ(TYPE) ((TYPE)&0xff)
...@@ -656,9 +656,9 @@ int32_t tDeserializeSRetrieveFuncRsp(void* buf, int32_t bufLen, SRetrieveFuncRsp ...@@ -656,9 +656,9 @@ int32_t tDeserializeSRetrieveFuncRsp(void* buf, int32_t bufLen, SRetrieveFuncRsp
typedef struct { typedef struct {
int32_t statusInterval; int32_t statusInterval;
int64_t checkTime; // 1970-01-01 00:00:00.000 int64_t checkTime; // 1970-01-01 00:00:00.000
char timezone[TSDB_TIMEZONE_LEN]; // tsTimezone char timezone[TD_TIMEZONE_LEN]; // tsTimezone
char locale[TSDB_LOCALE_LEN]; // tsLocale char locale[TD_LOCALE_LEN]; // tsLocale
char charset[TSDB_LOCALE_LEN]; // tsCharset char charset[TD_LOCALE_LEN]; // tsCharset
} SClusterCfg; } SClusterCfg;
typedef struct { typedef struct {
...@@ -1117,13 +1117,13 @@ typedef struct { ...@@ -1117,13 +1117,13 @@ typedef struct {
SArray* topicNames; // SArray<char*> SArray* topicNames; // SArray<char*>
} SCMSubscribeReq; } SCMSubscribeReq;
static FORCE_INLINE int tSerializeSCMSubscribeReq(void** buf, const SCMSubscribeReq* pReq) { static FORCE_INLINE int32_t tSerializeSCMSubscribeReq(void** buf, const SCMSubscribeReq* pReq) {
int tlen = 0; int32_t tlen = 0;
tlen += taosEncodeFixedI32(buf, pReq->topicNum); tlen += taosEncodeFixedI32(buf, pReq->topicNum);
tlen += taosEncodeFixedI64(buf, pReq->consumerId); tlen += taosEncodeFixedI64(buf, pReq->consumerId);
tlen += taosEncodeString(buf, pReq->consumerGroup); tlen += taosEncodeString(buf, pReq->consumerGroup);
for (int i = 0; i < pReq->topicNum; i++) { for (int32_t i = 0; i < pReq->topicNum; i++) {
tlen += taosEncodeString(buf, (char*)taosArrayGetP(pReq->topicNames, i)); tlen += taosEncodeString(buf, (char*)taosArrayGetP(pReq->topicNames, i));
} }
return tlen; return tlen;
...@@ -1134,7 +1134,7 @@ static FORCE_INLINE void* tDeserializeSCMSubscribeReq(void* buf, SCMSubscribeReq ...@@ -1134,7 +1134,7 @@ static FORCE_INLINE void* tDeserializeSCMSubscribeReq(void* buf, SCMSubscribeReq
buf = taosDecodeFixedI64(buf, &pReq->consumerId); buf = taosDecodeFixedI64(buf, &pReq->consumerId);
buf = taosDecodeString(buf, &pReq->consumerGroup); buf = taosDecodeString(buf, &pReq->consumerGroup);
pReq->topicNames = taosArrayInit(pReq->topicNum, sizeof(void*)); pReq->topicNames = taosArrayInit(pReq->topicNum, sizeof(void*));
for (int i = 0; i < pReq->topicNum; i++) { for (int32_t i = 0; i < pReq->topicNum; i++) {
char* name; char* name;
buf = taosDecodeString(buf, &name); buf = taosDecodeString(buf, &name);
taosArrayPush(pReq->topicNames, &name); taosArrayPush(pReq->topicNames, &name);
...@@ -1153,10 +1153,10 @@ typedef struct { ...@@ -1153,10 +1153,10 @@ typedef struct {
SMqSubTopic topics[]; SMqSubTopic topics[];
} SCMSubscribeRsp; } SCMSubscribeRsp;
static FORCE_INLINE int tSerializeSCMSubscribeRsp(void** buf, const SCMSubscribeRsp* pRsp) { static FORCE_INLINE int32_t tSerializeSCMSubscribeRsp(void** buf, const SCMSubscribeRsp* pRsp) {
int tlen = 0; int32_t tlen = 0;
tlen += taosEncodeFixedI32(buf, pRsp->topicNum); tlen += taosEncodeFixedI32(buf, pRsp->topicNum);
for (int i = 0; i < pRsp->topicNum; i++) { for (int32_t i = 0; i < pRsp->topicNum; i++) {
tlen += taosEncodeFixedI32(buf, pRsp->topics[i].vgId); tlen += taosEncodeFixedI32(buf, pRsp->topics[i].vgId);
tlen += taosEncodeFixedI64(buf, pRsp->topics[i].topicId); tlen += taosEncodeFixedI64(buf, pRsp->topics[i].topicId);
tlen += taosEncodeSEpSet(buf, &pRsp->topics[i].epSet); tlen += taosEncodeSEpSet(buf, &pRsp->topics[i].epSet);
...@@ -1166,7 +1166,7 @@ static FORCE_INLINE int tSerializeSCMSubscribeRsp(void** buf, const SCMSubscribe ...@@ -1166,7 +1166,7 @@ static FORCE_INLINE int tSerializeSCMSubscribeRsp(void** buf, const SCMSubscribe
static FORCE_INLINE void* tDeserializeSCMSubscribeRsp(void* buf, SCMSubscribeRsp* pRsp) { static FORCE_INLINE void* tDeserializeSCMSubscribeRsp(void* buf, SCMSubscribeRsp* pRsp) {
buf = taosDecodeFixedI32(buf, &pRsp->topicNum); buf = taosDecodeFixedI32(buf, &pRsp->topicNum);
for (int i = 0; i < pRsp->topicNum; i++) { for (int32_t i = 0; i < pRsp->topicNum; i++) {
buf = taosDecodeFixedI32(buf, &pRsp->topics[i].vgId); buf = taosDecodeFixedI32(buf, &pRsp->topics[i].vgId);
buf = taosDecodeFixedI64(buf, &pRsp->topics[i].topicId); buf = taosDecodeFixedI64(buf, &pRsp->topics[i].topicId);
buf = taosDecodeSEpSet(buf, &pRsp->topics[i].epSet); buf = taosDecodeSEpSet(buf, &pRsp->topics[i].epSet);
...@@ -1184,8 +1184,8 @@ typedef struct { ...@@ -1184,8 +1184,8 @@ typedef struct {
char* physicalPlan; char* physicalPlan;
} SMVSubscribeReq; } SMVSubscribeReq;
static FORCE_INLINE int tSerializeSMVSubscribeReq(void** buf, SMVSubscribeReq* pReq) { static FORCE_INLINE int32_t tSerializeSMVSubscribeReq(void** buf, SMVSubscribeReq* pReq) {
int tlen = 0; int32_t tlen = 0;
tlen += taosEncodeFixedI64(buf, pReq->topicId); tlen += taosEncodeFixedI64(buf, pReq->topicId);
tlen += taosEncodeFixedI64(buf, pReq->consumerId); tlen += taosEncodeFixedI64(buf, pReq->consumerId);
tlen += taosEncodeFixedI64(buf, pReq->consumerGroupId); tlen += taosEncodeFixedI64(buf, pReq->consumerGroupId);
...@@ -1395,8 +1395,8 @@ typedef struct SMqHbRsp { ...@@ -1395,8 +1395,8 @@ typedef struct SMqHbRsp {
SEpSet epSet; SEpSet epSet;
} SMqHbRsp; } SMqHbRsp;
static FORCE_INLINE int taosEncodeSMqHbRsp(void** buf, const SMqHbRsp* pRsp) { static FORCE_INLINE int32_t taosEncodeSMqHbRsp(void** buf, const SMqHbRsp* pRsp) {
int tlen = 0; int32_t tlen = 0;
tlen += taosEncodeFixedI8(buf, pRsp->status); tlen += taosEncodeFixedI8(buf, pRsp->status);
tlen += taosEncodeFixedI8(buf, pRsp->vnodeChanged); tlen += taosEncodeFixedI8(buf, pRsp->vnodeChanged);
tlen += taosEncodeFixedI8(buf, pRsp->epChanged); tlen += taosEncodeFixedI8(buf, pRsp->epChanged);
...@@ -1417,8 +1417,8 @@ typedef struct SMqHbOneTopicBatchRsp { ...@@ -1417,8 +1417,8 @@ typedef struct SMqHbOneTopicBatchRsp {
SArray* rsps; // SArray<SMqHbRsp> SArray* rsps; // SArray<SMqHbRsp>
} SMqHbOneTopicBatchRsp; } SMqHbOneTopicBatchRsp;
static FORCE_INLINE int taosEncodeSMqHbOneTopicBatchRsp(void** buf, const SMqHbOneTopicBatchRsp* pBatchRsp) { static FORCE_INLINE int32_t taosEncodeSMqHbOneTopicBatchRsp(void** buf, const SMqHbOneTopicBatchRsp* pBatchRsp) {
int tlen = 0; int32_t tlen = 0;
tlen += taosEncodeString(buf, pBatchRsp->topicName); tlen += taosEncodeString(buf, pBatchRsp->topicName);
int32_t sz = taosArrayGetSize(pBatchRsp->rsps); int32_t sz = taosArrayGetSize(pBatchRsp->rsps);
tlen += taosEncodeFixedI32(buf, sz); tlen += taosEncodeFixedI32(buf, sz);
...@@ -1447,8 +1447,8 @@ typedef struct SMqHbBatchRsp { ...@@ -1447,8 +1447,8 @@ typedef struct SMqHbBatchRsp {
SArray* batchRsps; // SArray<SMqHbOneTopicBatchRsp> SArray* batchRsps; // SArray<SMqHbOneTopicBatchRsp>
} SMqHbBatchRsp; } SMqHbBatchRsp;
static FORCE_INLINE int taosEncodeSMqHbBatchRsp(void** buf, const SMqHbBatchRsp* pBatchRsp) { static FORCE_INLINE int32_t taosEncodeSMqHbBatchRsp(void** buf, const SMqHbBatchRsp* pBatchRsp) {
int tlen = 0; int32_t tlen = 0;
tlen += taosEncodeFixedI64(buf, pBatchRsp->consumerId); tlen += taosEncodeFixedI64(buf, pBatchRsp->consumerId);
int32_t sz; int32_t sz;
tlen += taosEncodeFixedI32(buf, sz); tlen += taosEncodeFixedI32(buf, sz);
...@@ -1589,8 +1589,8 @@ typedef struct SMqHbVgInfo { ...@@ -1589,8 +1589,8 @@ typedef struct SMqHbVgInfo {
int32_t vgId; int32_t vgId;
} SMqHbVgInfo; } SMqHbVgInfo;
static FORCE_INLINE int taosEncodeSMqVgInfo(void** buf, const SMqHbVgInfo* pVgInfo) { static FORCE_INLINE int32_t taosEncodeSMqVgInfo(void** buf, const SMqHbVgInfo* pVgInfo) {
int tlen = 0; int32_t tlen = 0;
tlen += taosEncodeFixedI32(buf, pVgInfo->vgId); tlen += taosEncodeFixedI32(buf, pVgInfo->vgId);
return tlen; return tlen;
} }
...@@ -1607,8 +1607,8 @@ typedef struct SMqHbTopicInfo { ...@@ -1607,8 +1607,8 @@ typedef struct SMqHbTopicInfo {
SArray* pVgInfo; SArray* pVgInfo;
} SMqHbTopicInfo; } SMqHbTopicInfo;
static FORCE_INLINE int taosEncodeSMqHbTopicInfoMsg(void** buf, const SMqHbTopicInfo* pTopicInfo) { static FORCE_INLINE int32_t taosEncodeSMqHbTopicInfoMsg(void** buf, const SMqHbTopicInfo* pTopicInfo) {
int tlen = 0; int32_t tlen = 0;
tlen += taosEncodeFixedI32(buf, pTopicInfo->epoch); tlen += taosEncodeFixedI32(buf, pTopicInfo->epoch);
tlen += taosEncodeFixedI64(buf, pTopicInfo->topicUid); tlen += taosEncodeFixedI64(buf, pTopicInfo->topicUid);
tlen += taosEncodeString(buf, pTopicInfo->name); tlen += taosEncodeString(buf, pTopicInfo->name);
...@@ -1643,14 +1643,14 @@ typedef struct SMqHbMsg { ...@@ -1643,14 +1643,14 @@ typedef struct SMqHbMsg {
SArray* pTopics; // SArray<SMqHbTopicInfo> SArray* pTopics; // SArray<SMqHbTopicInfo>
} SMqHbMsg; } SMqHbMsg;
static FORCE_INLINE int taosEncodeSMqMsg(void** buf, const SMqHbMsg* pMsg) { static FORCE_INLINE int32_t taosEncodeSMqMsg(void** buf, const SMqHbMsg* pMsg) {
int tlen = 0; int32_t tlen = 0;
tlen += taosEncodeFixedI32(buf, pMsg->status); tlen += taosEncodeFixedI32(buf, pMsg->status);
tlen += taosEncodeFixedI32(buf, pMsg->epoch); tlen += taosEncodeFixedI32(buf, pMsg->epoch);
tlen += taosEncodeFixedI64(buf, pMsg->consumerId); tlen += taosEncodeFixedI64(buf, pMsg->consumerId);
int32_t sz = taosArrayGetSize(pMsg->pTopics); int32_t sz = taosArrayGetSize(pMsg->pTopics);
tlen += taosEncodeFixedI32(buf, sz); tlen += taosEncodeFixedI32(buf, sz);
for (int i = 0; i < sz; i++) { for (int32_t i = 0; i < sz; i++) {
SMqHbTopicInfo* topicInfo = (SMqHbTopicInfo*)taosArrayGet(pMsg->pTopics, i); SMqHbTopicInfo* topicInfo = (SMqHbTopicInfo*)taosArrayGet(pMsg->pTopics, i);
tlen += taosEncodeSMqHbTopicInfoMsg(buf, topicInfo); tlen += taosEncodeSMqHbTopicInfoMsg(buf, topicInfo);
} }
...@@ -1664,7 +1664,7 @@ static FORCE_INLINE void* taosDecodeSMqMsg(void* buf, SMqHbMsg* pMsg) { ...@@ -1664,7 +1664,7 @@ static FORCE_INLINE void* taosDecodeSMqMsg(void* buf, SMqHbMsg* pMsg) {
int32_t sz; int32_t sz;
buf = taosDecodeFixedI32(buf, &sz); buf = taosDecodeFixedI32(buf, &sz);
pMsg->pTopics = taosArrayInit(sz, sizeof(SMqHbTopicInfo)); pMsg->pTopics = taosArrayInit(sz, sizeof(SMqHbTopicInfo));
for (int i = 0; i < sz; i++) { for (int32_t i = 0; i < sz; i++) {
SMqHbTopicInfo topicInfo; SMqHbTopicInfo topicInfo;
buf = taosDecodeSMqHbTopicInfoMsg(buf, &topicInfo); buf = taosDecodeSMqHbTopicInfoMsg(buf, &topicInfo);
taosArrayPush(pMsg->pTopics, &topicInfo); taosArrayPush(pMsg->pTopics, &topicInfo);
......
...@@ -47,7 +47,7 @@ enum { ...@@ -47,7 +47,7 @@ enum {
#define TD_NEW_MSG_SEG(TYPE) TYPE##_NUM, #define TD_NEW_MSG_SEG(TYPE) TYPE##_NUM,
#define TD_DEF_MSG_TYPE(TYPE, MSG, REQ, RSP) #define TD_DEF_MSG_TYPE(TYPE, MSG, REQ, RSP)
int tMsgDict[] = { int32_t tMsgDict[] = {
#elif defined(TD_MSG_SEG_CODE_) #elif defined(TD_MSG_SEG_CODE_)
...@@ -127,7 +127,7 @@ enum { ...@@ -127,7 +127,7 @@ enum {
TD_DEF_MSG_TYPE(TDMT_MND_CREATE_STB, "mnode-create-stb", NULL, NULL) TD_DEF_MSG_TYPE(TDMT_MND_CREATE_STB, "mnode-create-stb", NULL, NULL)
TD_DEF_MSG_TYPE(TDMT_MND_ALTER_STB, "mnode-alter-stb", NULL, NULL) TD_DEF_MSG_TYPE(TDMT_MND_ALTER_STB, "mnode-alter-stb", NULL, NULL)
TD_DEF_MSG_TYPE(TDMT_MND_DROP_STB, "mnode-drop-stb", NULL, NULL) TD_DEF_MSG_TYPE(TDMT_MND_DROP_STB, "mnode-drop-stb", NULL, NULL)
TD_DEF_MSG_TYPE(TDMT_MND_STB_META, "mnode-stb-meta", NULL, NULL) TD_DEF_MSG_TYPE(TDMT_MND_TABLE_META, "mnode-table-meta", NULL, NULL)
TD_DEF_MSG_TYPE(TDMT_MND_VGROUP_LIST, "mnode-vgroup-list", NULL, NULL) TD_DEF_MSG_TYPE(TDMT_MND_VGROUP_LIST, "mnode-vgroup-list", NULL, NULL)
TD_DEF_MSG_TYPE(TDMT_MND_KILL_QUERY, "mnode-kill-query", NULL, NULL) TD_DEF_MSG_TYPE(TDMT_MND_KILL_QUERY, "mnode-kill-query", NULL, NULL)
TD_DEF_MSG_TYPE(TDMT_MND_KILL_CONN, "mnode-kill-conn", NULL, NULL) TD_DEF_MSG_TYPE(TDMT_MND_KILL_CONN, "mnode-kill-conn", NULL, NULL)
...@@ -135,8 +135,9 @@ enum { ...@@ -135,8 +135,9 @@ enum {
TD_DEF_MSG_TYPE(TDMT_MND_SHOW, "mnode-show", NULL, NULL) TD_DEF_MSG_TYPE(TDMT_MND_SHOW, "mnode-show", NULL, NULL)
TD_DEF_MSG_TYPE(TDMT_MND_SHOW_RETRIEVE, "mnode-retrieve", NULL, NULL) TD_DEF_MSG_TYPE(TDMT_MND_SHOW_RETRIEVE, "mnode-retrieve", NULL, NULL)
TD_DEF_MSG_TYPE(TDMT_MND_STATUS, "mnode-status", NULL, NULL) TD_DEF_MSG_TYPE(TDMT_MND_STATUS, "mnode-status", NULL, NULL)
TD_DEF_MSG_TYPE(TDMT_MND_TRANS, "mnode-trans", NULL, NULL) TD_DEF_MSG_TYPE(TDMT_MND_TRANS_TIMER, "mnode-trans-tmr", NULL, NULL)
TD_DEF_MSG_TYPE(TDMT_MND_KILL_TRANS, "mnode-kill-trans", NULL, NULL) TD_DEF_MSG_TYPE(TDMT_MND_KILL_TRANS, "mnode-kill-trans", NULL, NULL)
TD_DEF_MSG_TYPE(TDMT_MND_TELEM_TIMER, "mnode-telem-tmr", SMTimerReq, SMTimerReq)
TD_DEF_MSG_TYPE(TDMT_MND_GRANT, "mnode-grant", NULL, NULL) TD_DEF_MSG_TYPE(TDMT_MND_GRANT, "mnode-grant", NULL, NULL)
TD_DEF_MSG_TYPE(TDMT_MND_AUTH, "mnode-auth", NULL, NULL) TD_DEF_MSG_TYPE(TDMT_MND_AUTH, "mnode-auth", NULL, NULL)
TD_DEF_MSG_TYPE(TDMT_MND_CREATE_TOPIC, "mnode-create-topic", SMCreateTopicReq, SMCreateTopicRsp) TD_DEF_MSG_TYPE(TDMT_MND_CREATE_TOPIC, "mnode-create-topic", SMCreateTopicReq, SMCreateTopicRsp)
...@@ -144,7 +145,7 @@ enum { ...@@ -144,7 +145,7 @@ enum {
TD_DEF_MSG_TYPE(TDMT_MND_DROP_TOPIC, "mnode-drop-topic", NULL, NULL) TD_DEF_MSG_TYPE(TDMT_MND_DROP_TOPIC, "mnode-drop-topic", NULL, NULL)
TD_DEF_MSG_TYPE(TDMT_MND_SUBSCRIBE, "mnode-subscribe", SCMSubscribeReq, SCMSubscribeRsp) TD_DEF_MSG_TYPE(TDMT_MND_SUBSCRIBE, "mnode-subscribe", SCMSubscribeReq, SCMSubscribeRsp)
TD_DEF_MSG_TYPE(TDMT_MND_GET_SUB_EP, "mnode-get-sub-ep", SMqCMGetSubEpReq, SMqCMGetSubEpRsp) TD_DEF_MSG_TYPE(TDMT_MND_GET_SUB_EP, "mnode-get-sub-ep", SMqCMGetSubEpReq, SMqCMGetSubEpRsp)
TD_DEF_MSG_TYPE(TDMT_MND_MQ_TIMER, "mnode-mq-timer", SMTimerReq, SMTimerReq) TD_DEF_MSG_TYPE(TDMT_MND_MQ_TIMER, "mnode-mq-tmr", SMTimerReq, SMTimerReq)
TD_DEF_MSG_TYPE(TDMT_MND_MQ_DO_REBALANCE, "mnode-mq-do-rebalance", SMqDoRebalanceMsg, SMqDoRebalanceMsg) TD_DEF_MSG_TYPE(TDMT_MND_MQ_DO_REBALANCE, "mnode-mq-do-rebalance", SMqDoRebalanceMsg, SMqDoRebalanceMsg)
TD_DEF_MSG_TYPE(TDMT_MND_MQ_COMMIT_OFFSET, "mnode-mq-commit-offset", SMqCMCommitOffsetReq, SMqCMCommitOffsetRsp) TD_DEF_MSG_TYPE(TDMT_MND_MQ_COMMIT_OFFSET, "mnode-mq-commit-offset", SMqCMCommitOffsetReq, SMqCMCommitOffsetRsp)
......
...@@ -13,17 +13,16 @@ ...@@ -13,17 +13,16 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#ifndef TDENGINE_TNAME_H #ifndef _TD_COMMON_NAME_H_
#define TDENGINE_TNAME_H #define _TD_COMMON_NAME_H_
#include "tdef.h"
#include "tmsg.h"
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C" {
#endif #endif
#include "tdef.h"
#include "tmsg.h"
#define TSDB_DB_NAME_T 1 #define TSDB_DB_NAME_T 1
#define TSDB_TABLE_NAME_T 2 #define TSDB_TABLE_NAME_T 2
...@@ -32,7 +31,7 @@ extern "C" { ...@@ -32,7 +31,7 @@ extern "C" {
#define T_NAME_TABLE 0x4u #define T_NAME_TABLE 0x4u
typedef struct SName { typedef struct SName {
uint8_t type; //db_name_t, table_name_t uint8_t type; // db_name_t, table_name_t
int32_t acctId; int32_t acctId;
char dbname[TSDB_DB_NAME_LEN]; char dbname[TSDB_DB_NAME_LEN];
char tname[TSDB_TABLE_NAME_LEN]; char tname[TSDB_TABLE_NAME_LEN];
...@@ -68,5 +67,4 @@ SSchema createSchema(uint8_t type, int32_t bytes, int32_t colId, const char* nam ...@@ -68,5 +67,4 @@ SSchema createSchema(uint8_t type, int32_t bytes, int32_t colId, const char* nam
} }
#endif #endif
#endif /*_TD_COMMON_NAME_H_*/
#endif // TDENGINE_TNAME_H
...@@ -13,8 +13,8 @@ ...@@ -13,8 +13,8 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#ifndef _TD_TREQUEST_H_ #ifndef _TD_COMMON_REQUEST_H_
#define _TD_TREQUEST_H_ #define _TD_COMMON_REQUEST_H_
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C" {
...@@ -36,7 +36,7 @@ void tdClearRBIter(SReqBatchIter *pIter); ...@@ -36,7 +36,7 @@ void tdClearRBIter(SReqBatchIter *pIter);
/* ------------------------ TYPES DEFINITION ------------------------ */ /* ------------------------ TYPES DEFINITION ------------------------ */
struct SReqBatchIter { struct SReqBatchIter {
int iReq; int32_t iReq;
SReqBatch *pReqBatch; SReqBatch *pReqBatch;
}; };
...@@ -44,4 +44,4 @@ struct SReqBatchIter { ...@@ -44,4 +44,4 @@ struct SReqBatchIter {
} }
#endif #endif
#endif /*_TD_TREQUEST_H_*/ #endif /*_TD_COMMON_REQUEST_H_*/
\ No newline at end of file \ No newline at end of file
...@@ -18,11 +18,11 @@ ...@@ -18,11 +18,11 @@
#include "os.h" #include "os.h"
#include "talgo.h" #include "talgo.h"
#include "taosdef.h"
#include "taoserror.h" #include "taoserror.h"
#include "tbuffer.h" #include "tbuffer.h"
#include "tdef.h"
#include "taosdef.h"
#include "tdataformat.h" #include "tdataformat.h"
#include "tdef.h"
#include "tschema.h" #include "tschema.h"
#include "ttypes.h" #include "ttypes.h"
#include "tutil.h" #include "tutil.h"
...@@ -98,7 +98,7 @@ typedef void *SRow; ...@@ -98,7 +98,7 @@ typedef void *SRow;
typedef struct { typedef struct {
TDRowValT valType; TDRowValT valType;
void * val; void *val;
} SCellVal; } SCellVal;
typedef struct { typedef struct {
...@@ -157,8 +157,8 @@ typedef struct { ...@@ -157,8 +157,8 @@ typedef struct {
int16_t nBitmaps; int16_t nBitmaps;
int16_t nBoundBitmaps; int16_t nBoundBitmaps;
int32_t offset; int32_t offset;
void * pBitmap; void *pBitmap;
void * pOffset; void *pOffset;
int32_t extendedRowSize; int32_t extendedRowSize;
} SRowBuilder; } SRowBuilder;
...@@ -176,7 +176,7 @@ typedef struct { ...@@ -176,7 +176,7 @@ typedef struct {
#define TD_ROW_KEY_ADDR(r) POINTER_SHIFT((r), 16) #define TD_ROW_KEY_ADDR(r) POINTER_SHIFT((r), 16)
// N.B. If without STSchema, getExtendedRowSize() is used to get the rowMaxBytes and // N.B. If without STSchema, getExtendedRowSize() is used to get the rowMaxBytes and
// (int)ceil((double)nCols/TD_VTYPE_PARTS) should be added if TD_SUPPORT_BITMAP defined. // (int32_t)ceil((double)nCols/TD_VTYPE_PARTS) should be added if TD_SUPPORT_BITMAP defined.
#define TD_ROW_MAX_BYTES_FROM_SCHEMA(s) (schemaTLen(s) + TD_ROW_HEAD_LEN) #define TD_ROW_MAX_BYTES_FROM_SCHEMA(s) (schemaTLen(s) + TD_ROW_HEAD_LEN)
#define TD_ROW_SET_TYPE(r, t) (TD_ROW_TYPE(r) = (t)) #define TD_ROW_SET_TYPE(r, t) (TD_ROW_TYPE(r) = (t))
...@@ -217,7 +217,7 @@ static FORCE_INLINE void tdRowCopy(void *dst, STSRow *row) { memcpy(dst, row, ...@@ -217,7 +217,7 @@ static FORCE_INLINE void tdRowCopy(void *dst, STSRow *row) { memcpy(dst, row,
static FORCE_INLINE int32_t tdSetBitmapValType(void *pBitmap, int16_t colIdx, TDRowValT valType); static FORCE_INLINE int32_t tdSetBitmapValType(void *pBitmap, int16_t colIdx, TDRowValT valType);
int32_t tdSetBitmapValTypeN(void *pBitmap, int16_t nEle, TDRowValT valType); int32_t tdSetBitmapValTypeN(void *pBitmap, int16_t nEle, TDRowValT valType);
static FORCE_INLINE int32_t tdGetBitmapValType(void *pBitmap, int16_t colIdx, TDRowValT *pValType); static FORCE_INLINE int32_t tdGetBitmapValType(void *pBitmap, int16_t colIdx, TDRowValT *pValType);
int tdAppendValToDataCol(SDataCol *pCol, TDRowValT valType, const void *val, int numOfRows, int maxPoints); int32_t tdAppendValToDataCol(SDataCol *pCol, TDRowValT valType, const void *val, int32_t numOfRows, int32_t maxPoints);
static FORCE_INLINE int32_t tdAppendColValToTpRow(SRowBuilder *pBuilder, TDRowValT valType, const void *val, static FORCE_INLINE int32_t tdAppendColValToTpRow(SRowBuilder *pBuilder, TDRowValT valType, const void *val,
bool isCopyVarData, int8_t colType, int16_t colIdx, int32_t offset); bool isCopyVarData, int8_t colType, int16_t colIdx, int32_t offset);
static FORCE_INLINE int32_t tdAppendColValToKvRow(SRowBuilder *pBuilder, TDRowValT valType, const void *val, static FORCE_INLINE int32_t tdAppendColValToKvRow(SRowBuilder *pBuilder, TDRowValT valType, const void *val,
...@@ -272,7 +272,7 @@ static FORCE_INLINE int32_t tdSetBitmapValType(void *pBitmap, int16_t colIdx, TD ...@@ -272,7 +272,7 @@ static FORCE_INLINE int32_t tdSetBitmapValType(void *pBitmap, int16_t colIdx, TD
} }
int16_t nBytes = colIdx / TD_VTYPE_PARTS; int16_t nBytes = colIdx / TD_VTYPE_PARTS;
int16_t nOffset = colIdx & TD_VTYPE_OPTR; int16_t nOffset = colIdx & TD_VTYPE_OPTR;
char * pDestByte = (char *)POINTER_SHIFT(pBitmap, nBytes); char *pDestByte = (char *)POINTER_SHIFT(pBitmap, nBytes);
switch (nOffset) { switch (nOffset) {
case 0: case 0:
*pDestByte = ((*pDestByte) & 0x3F) | (valType << 6); *pDestByte = ((*pDestByte) & 0x3F) | (valType << 6);
...@@ -310,7 +310,7 @@ static FORCE_INLINE int32_t tdGetBitmapValType(void *pBitmap, int16_t colIdx, TD ...@@ -310,7 +310,7 @@ static FORCE_INLINE int32_t tdGetBitmapValType(void *pBitmap, int16_t colIdx, TD
} }
int16_t nBytes = colIdx / TD_VTYPE_PARTS; int16_t nBytes = colIdx / TD_VTYPE_PARTS;
int16_t nOffset = colIdx & TD_VTYPE_OPTR; int16_t nOffset = colIdx & TD_VTYPE_OPTR;
char * pDestByte = (char *)POINTER_SHIFT(pBitmap, nBytes); char *pDestByte = (char *)POINTER_SHIFT(pBitmap, nBytes);
switch (nOffset) { switch (nOffset) {
case 0: case 0:
*pValType = (((*pDestByte) & 0xC0) >> 6); *pValType = (((*pDestByte) & 0xC0) >> 6);
...@@ -355,7 +355,6 @@ static FORCE_INLINE int32_t tdGetBitmapValType(void *pBitmap, int16_t colIdx, TD ...@@ -355,7 +355,6 @@ static FORCE_INLINE int32_t tdGetBitmapValType(void *pBitmap, int16_t colIdx, TD
* *
*/ */
/** /**
* @brief * @brief
* *
...@@ -432,7 +431,6 @@ static FORCE_INLINE int32_t tdSRowSetExtendedInfo(SRowBuilder *pBuilder, int32_t ...@@ -432,7 +431,6 @@ static FORCE_INLINE int32_t tdSRowSetExtendedInfo(SRowBuilder *pBuilder, int32_t
pBuilder->rowType = TD_ROW_TP; pBuilder->rowType = TD_ROW_TP;
} }
} else { } else {
pBuilder->rowType = TD_ROW_TP; pBuilder->rowType = TD_ROW_TP;
} }
...@@ -618,7 +616,7 @@ static FORCE_INLINE int32_t tdAppendColValToKvRow(SRowBuilder *pBuilder, TDRowVa ...@@ -618,7 +616,7 @@ static FORCE_INLINE int32_t tdAppendColValToKvRow(SRowBuilder *pBuilder, TDRowVa
if (tdValIsNorm(valType, val, colType)) { if (tdValIsNorm(valType, val, colType)) {
// ts key stored in STSRow.ts // ts key stored in STSRow.ts
SKvRowIdx *pColIdx = (SKvRowIdx *)POINTER_SHIFT(TD_ROW_COL_IDX(row), offset); SKvRowIdx *pColIdx = (SKvRowIdx *)POINTER_SHIFT(TD_ROW_COL_IDX(row), offset);
char * ptr = (char *)POINTER_SHIFT(row, TD_ROW_LEN(row)); char *ptr = (char *)POINTER_SHIFT(row, TD_ROW_LEN(row));
pColIdx->colId = colId; pColIdx->colId = colId;
pColIdx->offset = TD_ROW_LEN(row); // the offset include the TD_ROW_HEAD_LEN pColIdx->offset = TD_ROW_LEN(row); // the offset include the TD_ROW_HEAD_LEN
...@@ -636,7 +634,7 @@ static FORCE_INLINE int32_t tdAppendColValToKvRow(SRowBuilder *pBuilder, TDRowVa ...@@ -636,7 +634,7 @@ static FORCE_INLINE int32_t tdAppendColValToKvRow(SRowBuilder *pBuilder, TDRowVa
// NULL/None value // NULL/None value
else { else {
SKvRowIdx *pColIdx = (SKvRowIdx *)POINTER_SHIFT(TD_ROW_COL_IDX(row), offset); SKvRowIdx *pColIdx = (SKvRowIdx *)POINTER_SHIFT(TD_ROW_COL_IDX(row), offset);
char * ptr = (char *)POINTER_SHIFT(row, TD_ROW_LEN(row)); char *ptr = (char *)POINTER_SHIFT(row, TD_ROW_LEN(row));
pColIdx->colId = colId; pColIdx->colId = colId;
pColIdx->offset = TD_ROW_LEN(row); // the offset include the TD_ROW_HEAD_LEN pColIdx->offset = TD_ROW_LEN(row); // the offset include the TD_ROW_HEAD_LEN
const void *nullVal = getNullValue(colType); const void *nullVal = getNullValue(colType);
...@@ -731,7 +729,7 @@ static FORCE_INLINE int32_t tdGetTpRowValOfCol(SCellVal *output, STSRow *pRow, v ...@@ -731,7 +729,7 @@ static FORCE_INLINE int32_t tdGetTpRowValOfCol(SCellVal *output, STSRow *pRow, v
return TSDB_CODE_SUCCESS; return TSDB_CODE_SUCCESS;
} }
static FORCE_INLINE int compareKvRowColId(const void *key1, const void *key2) { static FORCE_INLINE int32_t compareKvRowColId(const void *key1, const void *key2) {
if (*(int16_t *)key1 > ((SColIdx *)key2)->colId) { if (*(int16_t *)key1 > ((SColIdx *)key2)->colId) {
return 1; return 1;
} else if (*(int16_t *)key1 < ((SColIdx *)key2)->colId) { } else if (*(int16_t *)key1 < ((SColIdx *)key2)->colId) {
...@@ -772,8 +770,8 @@ static FORCE_INLINE int32_t tdGetKvRowValOfCol(SCellVal *output, STSRow *pRow, v ...@@ -772,8 +770,8 @@ static FORCE_INLINE int32_t tdGetKvRowValOfCol(SCellVal *output, STSRow *pRow, v
typedef struct { typedef struct {
STSchema *pSchema; STSchema *pSchema;
STSRow * pRow; STSRow *pRow;
void * pBitmap; void *pBitmap;
uint32_t offset; uint32_t offset;
col_id_t maxColId; col_id_t maxColId;
col_id_t colIdx; // [PRIMARYKEY_TIMESTAMP_COL_ID, nSchemaCols], PRIMARYKEY_TIMESTAMP_COL_ID equals 1 col_id_t colIdx; // [PRIMARYKEY_TIMESTAMP_COL_ID, nSchemaCols], PRIMARYKEY_TIMESTAMP_COL_ID equals 1
...@@ -793,8 +791,8 @@ static FORCE_INLINE void tdSTSRowIterInit(STSRowIter *pIter, STSchema *pSchema) ...@@ -793,8 +791,8 @@ static FORCE_INLINE void tdSTSRowIterInit(STSRowIter *pIter, STSchema *pSchema)
pIter->maxColId = pSchema->columns[pSchema->numOfCols - 1].colId; pIter->maxColId = pSchema->columns[pSchema->numOfCols - 1].colId;
} }
static int tdCompareColId(const void *arg1, const void *arg2) { static int32_t tdCompareColId(const void *arg1, const void *arg2) {
int colId = *(int *)arg1; int32_t colId = *(int32_t *)arg1;
STColumn *pCol = (STColumn *)arg2; STColumn *pCol = (STColumn *)arg2;
if (colId < pCol->colId) { if (colId < pCol->colId) {
...@@ -878,7 +876,7 @@ static FORCE_INLINE bool tdGetTpRowDataOfCol(STSRowIter *pIter, col_type_t colTy ...@@ -878,7 +876,7 @@ static FORCE_INLINE bool tdGetTpRowDataOfCol(STSRowIter *pIter, col_type_t colTy
// internal // internal
static FORCE_INLINE bool tdGetKvRowValOfColEx(STSRowIter *pIter, col_id_t colId, col_type_t colType, col_id_t *nIdx, static FORCE_INLINE bool tdGetKvRowValOfColEx(STSRowIter *pIter, col_id_t colId, col_type_t colType, col_id_t *nIdx,
SCellVal *pVal) { SCellVal *pVal) {
STSRow * pRow = pIter->pRow; STSRow *pRow = pIter->pRow;
SKvRowIdx *pKvIdx = NULL; SKvRowIdx *pKvIdx = NULL;
bool colFound = false; bool colFound = false;
col_id_t kvNCols = tdRowGetNCols(pRow); col_id_t kvNCols = tdRowGetNCols(pRow);
...@@ -959,11 +957,11 @@ static FORCE_INLINE bool tdSTSRowIterNext(STSRowIter *pIter, col_id_t colId, col ...@@ -959,11 +957,11 @@ static FORCE_INLINE bool tdSTSRowIterNext(STSRowIter *pIter, col_id_t colId, col
STSRow *mergeTwoRows(void *buffer, STSRow *row1, STSRow *row2, STSchema *pSchema1, STSchema *pSchema2); STSRow *mergeTwoRows(void *buffer, STSRow *row1, STSRow *row2, STSchema *pSchema1, STSchema *pSchema2);
// Get the data pointer from a column-wised data // Get the data pointer from a column-wised data
static FORCE_INLINE int32_t tdGetColDataOfRow(SCellVal *pVal, SDataCol *pCol, int row) { static FORCE_INLINE int32_t tdGetColDataOfRow(SCellVal *pVal, SDataCol *pCol, int32_t row) {
if (isAllRowsNone(pCol)) { if (isAllRowsNone(pCol)) {
pVal->valType = TD_VTYPE_NULL; pVal->valType = TD_VTYPE_NULL;
#ifdef TD_SUPPORT_READ2 #ifdef TD_SUPPORT_READ2
pVal->val = (void*)getNullValue(pCol->type); pVal->val = (void *)getNullValue(pCol->type);
#else #else
pVal->val = NULL; pVal->val = NULL;
#endif #endif
...@@ -981,7 +979,7 @@ static FORCE_INLINE int32_t tdGetColDataOfRow(SCellVal *pVal, SDataCol *pCol, in ...@@ -981,7 +979,7 @@ static FORCE_INLINE int32_t tdGetColDataOfRow(SCellVal *pVal, SDataCol *pCol, in
} else { } else {
pVal->valType = TD_VTYPE_NULL; pVal->valType = TD_VTYPE_NULL;
#ifdef TD_SUPPORT_READ2 #ifdef TD_SUPPORT_READ2
pVal->val = (void*)getNullValue(pCol->type); pVal->val = (void *)getNullValue(pCol->type);
#else #else
pVal->val = NULL; pVal->val = NULL;
#endif #endif
...@@ -1000,7 +998,8 @@ static FORCE_INLINE bool tdSTpRowGetVal(STSRow *pRow, col_id_t colId, col_type_t ...@@ -1000,7 +998,8 @@ static FORCE_INLINE bool tdSTpRowGetVal(STSRow *pRow, col_id_t colId, col_type_t
return true; return true;
} }
static FORCE_INLINE bool tdSKvRowGetVal(STSRow *pRow, col_id_t colId, uint32_t offset, col_id_t colIdx, SCellVal *pVal) { static FORCE_INLINE bool tdSKvRowGetVal(STSRow *pRow, col_id_t colId, uint32_t offset, col_id_t colIdx,
SCellVal *pVal) {
if (colId == PRIMARYKEY_TIMESTAMP_COL_ID) { if (colId == PRIMARYKEY_TIMESTAMP_COL_ID) {
tdRowSetVal(pVal, TD_VTYPE_NORM, TD_ROW_KEY_ADDR(pRow)); tdRowSetVal(pVal, TD_VTYPE_NORM, TD_ROW_KEY_ADDR(pRow));
return true; return true;
...@@ -1010,7 +1009,7 @@ static FORCE_INLINE bool tdSKvRowGetVal(STSRow *pRow, col_id_t colId, uint32_t o ...@@ -1010,7 +1009,7 @@ static FORCE_INLINE bool tdSKvRowGetVal(STSRow *pRow, col_id_t colId, uint32_t o
return true; return true;
} }
static FORCE_INLINE int32_t dataColGetNEleLen(SDataCol *pDataCol, int rows) { static FORCE_INLINE int32_t dataColGetNEleLen(SDataCol *pDataCol, int32_t rows) {
ASSERT(rows > 0); ASSERT(rows > 0);
int32_t result = 0; int32_t result = 0;
...@@ -1068,7 +1067,7 @@ typedef struct { ...@@ -1068,7 +1067,7 @@ typedef struct {
typedef struct { typedef struct {
STSchema *pSchema; STSchema *pSchema;
STSRow * pRow; STSRow *pRow;
} STSRowReader; } STSRowReader;
typedef struct { typedef struct {
...@@ -1082,12 +1081,12 @@ typedef struct { ...@@ -1082,12 +1081,12 @@ typedef struct {
void trbSetRowInfo(STSRowBuilder *pRB, bool del, uint16_t sver); void trbSetRowInfo(STSRowBuilder *pRB, bool del, uint16_t sver);
void trbSetRowVersion(STSRowBuilder *pRB, uint64_t ver); void trbSetRowVersion(STSRowBuilder *pRB, uint64_t ver);
void trbSetRowTS(STSRowBuilder *pRB, TSKEY ts); void trbSetRowTS(STSRowBuilder *pRB, TSKEY ts);
int trbWriteCol(STSRowBuilder *pRB, void *pData, col_id_t cid); int32_t trbWriteCol(STSRowBuilder *pRB, void *pData, col_id_t cid);
// STSRowReader // STSRowReader
#define tRowReaderInit(schema, row) \ #define tRowReaderInit(schema, row) \
{ .schema = (schema), .row = (row) } { .schema = (schema), .row = (row) }
int tRowReaderRead(STSRowReader *pRowReader, col_id_t cid, void *target, uint64_t size); int32_t tRowReaderRead(STSRowReader *pRowReader, col_id_t cid, void *target, uint64_t size);
// STSRowBatchIter // STSRowBatchIter
#define tRowBatchIterInit(pRB) \ #define tRowBatchIterInit(pRB) \
......
...@@ -70,7 +70,7 @@ typedef struct { ...@@ -70,7 +70,7 @@ typedef struct {
{ .size = (capacity), .pSchema = (target) } { .size = (capacity), .pSchema = (target) }
void tSchemaBuilderSetSver(STShemaBuilder *pSchemaBuilder, uint16_t sver); void tSchemaBuilderSetSver(STShemaBuilder *pSchemaBuilder, uint16_t sver);
void tSchemaBuilderSetSMA(bool sma, SArray *smaArray); void tSchemaBuilderSetSMA(bool sma, SArray *smaArray);
int tSchemaBuilderPutColumn(char *cname, bool sma, uint8_t type, col_id_t cid, uint32_t bytes, char *comment); int32_t tSchemaBuilderPutColumn(char *cname, bool sma, uint8_t type, col_id_t cid, uint32_t bytes, char *comment);
#endif #endif
......
...@@ -16,13 +16,13 @@ ...@@ -16,13 +16,13 @@
#ifndef _TD_COMMON_TIME_H_ #ifndef _TD_COMMON_TIME_H_
#define _TD_COMMON_TIME_H_ #define _TD_COMMON_TIME_H_
#include "taosdef.h"
#include "tmsg.h"
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C" {
#endif #endif
#include "taosdef.h"
#include "tmsg.h"
#define TIME_IS_VAR_DURATION(_t) ((_t) == 'n' || (_t) == 'y' || (_t) == 'N' || (_t) == 'Y') #define TIME_IS_VAR_DURATION(_t) ((_t) == 'n' || (_t) == 'y' || (_t) == 'N' || (_t) == 'Y')
/* /*
...@@ -35,7 +35,7 @@ static FORCE_INLINE int64_t taosGetTimestamp(int32_t precision) { ...@@ -35,7 +35,7 @@ static FORCE_INLINE int64_t taosGetTimestamp(int32_t precision) {
return taosGetTimestampUs(); return taosGetTimestampUs();
} else if (precision == TSDB_TIME_PRECISION_NANO) { } else if (precision == TSDB_TIME_PRECISION_NANO) {
return taosGetTimestampNs(); return taosGetTimestampNs();
}else { } else {
return taosGetTimestampMs(); return taosGetTimestampMs();
} }
} }
......
...@@ -13,8 +13,8 @@ ...@@ -13,8 +13,8 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#ifndef TDENGINE_TTOKENDEF_H #ifndef _TD_COMMON_TOKEN_H_
#define TDENGINE_TTOKENDEF_H #define _TD_COMMON_TOKEN_H_
#define TK_ID 1 #define TK_ID 1
#define TK_BOOL 2 #define TK_BOOL 2
...@@ -291,6 +291,4 @@ ...@@ -291,6 +291,4 @@
#define TK_NIL 65535 #define TK_NIL 65535
#endif #endif /*_TD_COMMON_TOKEN_H_*/
...@@ -13,17 +13,17 @@ ...@@ -13,17 +13,17 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#ifndef TDENGINE_TTSZIP_H #ifndef _TD_COMMON_TTSZIP_H_
#define TDENGINE_TTSZIP_H #define _TD_COMMON_TTSZIP_H_
#ifdef __cplusplus
extern "C" {
#endif
#include "os.h" #include "os.h"
#include "tdef.h" #include "tdef.h"
#include "tvariant.h" #include "tvariant.h"
#ifdef __cplusplus
extern "C" {
#endif
#define MEM_BUF_SIZE (1 << 20) #define MEM_BUF_SIZE (1 << 20)
#define TS_COMP_FILE_MAGIC 0x87F5EC4C #define TS_COMP_FILE_MAGIC 0x87F5EC4C
#define TS_COMP_FILE_GROUP_MAX 512 #define TS_COMP_FILE_GROUP_MAX 512
...@@ -73,7 +73,7 @@ typedef struct STSGroupBlockInfoEx { ...@@ -73,7 +73,7 @@ typedef struct STSGroupBlockInfoEx {
} STSGroupBlockInfoEx; } STSGroupBlockInfoEx;
typedef struct STSBuf { typedef struct STSBuf {
FILE* f; TdFilePtr pFile;
char path[PATH_MAX]; char path[PATH_MAX];
uint32_t fileSize; uint32_t fileSize;
...@@ -144,4 +144,4 @@ bool tsBufIsValidElem(STSElem* pElem); ...@@ -144,4 +144,4 @@ bool tsBufIsValidElem(STSElem* pElem);
} }
#endif #endif
#endif // TDENGINE_TTSZIP_H #endif /*_TD_COMMON_TTSZIP_H_*/
#ifndef TDENGINE_TTYPE_H /*
#define TDENGINE_TTYPE_H * 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/>.
*/
#ifndef _TD_COMMON_TTYPE_H_
#define _TD_COMMON_TTYPE_H_
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C" {
...@@ -15,11 +30,6 @@ typedef uint8_t TDRowValT; ...@@ -15,11 +30,6 @@ typedef uint8_t TDRowValT;
typedef uint16_t col_id_t; typedef uint16_t col_id_t;
typedef int8_t col_type_t; typedef int8_t col_type_t;
typedef struct tstr {
VarDataLenT len;
char data[];
} tstr;
#pragma pack(push, 1) #pragma pack(push, 1)
typedef struct { typedef struct {
VarDataLenT len; VarDataLenT len;
...@@ -33,15 +43,14 @@ typedef struct { ...@@ -33,15 +43,14 @@ typedef struct {
#pragma pack(pop) #pragma pack(pop)
#define varDataTLen(v) (sizeof(VarDataLenT) + varDataLen(v)) #define varDataTLen(v) (sizeof(VarDataLenT) + varDataLen(v))
#define varDataCopy(dst, v) memcpy((dst), (void*) (v), varDataTLen(v)) #define varDataCopy(dst, v) memcpy((dst), (void *)(v), varDataTLen(v))
#define varDataLenByData(v) (*(VarDataLenT *)(((char*)(v)) - VARSTR_HEADER_SIZE)) #define varDataLenByData(v) (*(VarDataLenT *)(((char *)(v)) - VARSTR_HEADER_SIZE))
#define varDataSetLen(v, _len) (((VarDataLenT *)(v))[0] = (VarDataLenT) (_len)) #define varDataSetLen(v, _len) (((VarDataLenT *)(v))[0] = (VarDataLenT)(_len))
#define IS_VAR_DATA_TYPE(t) (((t) == TSDB_DATA_TYPE_BINARY) || ((t) == TSDB_DATA_TYPE_NCHAR)) #define IS_VAR_DATA_TYPE(t) (((t) == TSDB_DATA_TYPE_BINARY) || ((t) == TSDB_DATA_TYPE_NCHAR))
#define varDataNetLen(v) (htons(((VarDataLenT *)(v))[0])) #define varDataNetLen(v) (htons(((VarDataLenT *)(v))[0]))
#define varDataNetTLen(v) (sizeof(VarDataLenT) + varDataNetLen(v)) #define varDataNetTLen(v) (sizeof(VarDataLenT) + varDataNetLen(v))
// this data type is internally used only in 'in' query to hold the values // this data type is internally used only in 'in' query to hold the values
#define TSDB_DATA_TYPE_POINTER_ARRAY (1000) #define TSDB_DATA_TYPE_POINTER_ARRAY (1000)
#define TSDB_DATA_TYPE_VALUE_ARRAY (1001) #define TSDB_DATA_TYPE_VALUE_ARRAY (1001)
...@@ -62,7 +71,7 @@ typedef struct { ...@@ -62,7 +71,7 @@ typedef struct {
case TSDB_DATA_TYPE_USMALLINT: \ case TSDB_DATA_TYPE_USMALLINT: \
(_v) = (_finalType)GET_UINT16_VAL(_data); \ (_v) = (_finalType)GET_UINT16_VAL(_data); \
break; \ break; \
case TSDB_DATA_TYPE_TIMESTAMP:\ case TSDB_DATA_TYPE_TIMESTAMP: \
case TSDB_DATA_TYPE_BIGINT: \ case TSDB_DATA_TYPE_BIGINT: \
(_v) = (_finalType)(GET_INT64_VAL(_data)); \ (_v) = (_finalType)(GET_INT64_VAL(_data)); \
break; \ break; \
...@@ -146,7 +155,8 @@ typedef struct { ...@@ -146,7 +155,8 @@ typedef struct {
#define IS_VALID_FLOAT(_t) ((_t) >= -FLT_MAX && (_t) <= FLT_MAX) #define IS_VALID_FLOAT(_t) ((_t) >= -FLT_MAX && (_t) <= FLT_MAX)
#define IS_VALID_DOUBLE(_t) ((_t) >= -DBL_MAX && (_t) <= DBL_MAX) #define IS_VALID_DOUBLE(_t) ((_t) >= -DBL_MAX && (_t) <= DBL_MAX)
#define IS_CONVERT_AS_SIGNED(_t) (IS_SIGNED_NUMERIC_TYPE(_t) || (_t) == (TSDB_DATA_TYPE_BOOL) || (_t) == (TSDB_DATA_TYPE_TIMESTAMP)) #define IS_CONVERT_AS_SIGNED(_t) \
(IS_SIGNED_NUMERIC_TYPE(_t) || (_t) == (TSDB_DATA_TYPE_BOOL) || (_t) == (TSDB_DATA_TYPE_TIMESTAMP))
#define IS_CONVERT_AS_UNSIGNED(_t) (IS_UNSIGNED_NUMERIC_TYPE(_t) || (_t) == (TSDB_DATA_TYPE_BOOL)) #define IS_CONVERT_AS_UNSIGNED(_t) (IS_UNSIGNED_NUMERIC_TYPE(_t) || (_t) == (TSDB_DATA_TYPE_BOOL))
static FORCE_INLINE bool isNull(const void *val, int32_t type) { static FORCE_INLINE bool isNull(const void *val, int32_t type) {
...@@ -167,17 +177,17 @@ static FORCE_INLINE bool isNull(const void *val, int32_t type) { ...@@ -167,17 +177,17 @@ static FORCE_INLINE bool isNull(const void *val, int32_t type) {
case TSDB_DATA_TYPE_DOUBLE: case TSDB_DATA_TYPE_DOUBLE:
return *(uint64_t *)val == TSDB_DATA_DOUBLE_NULL; return *(uint64_t *)val == TSDB_DATA_DOUBLE_NULL;
case TSDB_DATA_TYPE_NCHAR: case TSDB_DATA_TYPE_NCHAR:
return varDataLen(val) == sizeof(int32_t) && *(uint32_t*) varDataVal(val) == TSDB_DATA_NCHAR_NULL; return varDataLen(val) == sizeof(int32_t) && *(uint32_t *)varDataVal(val) == TSDB_DATA_NCHAR_NULL;
case TSDB_DATA_TYPE_BINARY: case TSDB_DATA_TYPE_BINARY:
return varDataLen(val) == sizeof(int8_t) && *(uint8_t *) varDataVal(val) == TSDB_DATA_BINARY_NULL; return varDataLen(val) == sizeof(int8_t) && *(uint8_t *)varDataVal(val) == TSDB_DATA_BINARY_NULL;
case TSDB_DATA_TYPE_UTINYINT: case TSDB_DATA_TYPE_UTINYINT:
return *(uint8_t*) val == TSDB_DATA_UTINYINT_NULL; return *(uint8_t *)val == TSDB_DATA_UTINYINT_NULL;
case TSDB_DATA_TYPE_USMALLINT: case TSDB_DATA_TYPE_USMALLINT:
return *(uint16_t*) val == TSDB_DATA_USMALLINT_NULL; return *(uint16_t *)val == TSDB_DATA_USMALLINT_NULL;
case TSDB_DATA_TYPE_UINT: case TSDB_DATA_TYPE_UINT:
return *(uint32_t*) val == TSDB_DATA_UINT_NULL; return *(uint32_t *)val == TSDB_DATA_UINT_NULL;
case TSDB_DATA_TYPE_UBIGINT: case TSDB_DATA_TYPE_UBIGINT:
return *(uint64_t*) val == TSDB_DATA_UBIGINT_NULL; return *(uint64_t *)val == TSDB_DATA_UBIGINT_NULL;
default: default:
return false; return false;
...@@ -188,32 +198,31 @@ typedef struct tDataTypeDescriptor { ...@@ -188,32 +198,31 @@ typedef struct tDataTypeDescriptor {
int16_t type; int16_t type;
int16_t nameLen; int16_t nameLen;
int32_t bytes; int32_t bytes;
char * name; char *name;
int64_t minValue; int64_t minValue;
int64_t maxValue; int64_t maxValue;
int (*compFunc)(const char *const input, int inputSize, const int nelements, char *const output, int outputSize, int32_t (*compFunc)(const char *const input, int32_t inputSize, const int32_t nelements, char *const output,
char algorithm, char *const buffer, int bufferSize); int32_t outputSize, char algorithm, char *const buffer, int32_t bufferSize);
int (*decompFunc)(const char *const input, int compressedSize, const int nelements, char *const output, int32_t (*decompFunc)(const char *const input, int32_t compressedSize, const int32_t nelements, char *const output,
int outputSize, char algorithm, char *const buffer, int bufferSize); int32_t outputSize, char algorithm, char *const buffer, int32_t bufferSize);
void (*statisFunc)(const void *pData, int32_t numofrow, int64_t *min, int64_t *max, int64_t *sum, void (*statisFunc)(const void *pData, int32_t numofrow, int64_t *min, int64_t *max, int64_t *sum, int16_t *minindex,
int16_t *minindex, int16_t *maxindex, int16_t *numofnull); int16_t *maxindex, int16_t *numofnull);
} tDataTypeDescriptor; } tDataTypeDescriptor;
extern tDataTypeDescriptor tDataTypes[15]; extern tDataTypeDescriptor tDataTypes[15];
bool isValidDataType(int32_t type); bool isValidDataType(int32_t type);
void setVardataNull(void* val, int32_t type); void setVardataNull(void *val, int32_t type);
void setNull(void *val, int32_t type, int32_t bytes); void setNull(void *val, int32_t type, int32_t bytes);
void setNullN(void *val, int32_t type, int32_t bytes, int32_t numOfElems); void setNullN(void *val, int32_t type, int32_t bytes, int32_t numOfElems);
const void *getNullValue(int32_t type); const void *getNullValue(int32_t type);
void assignVal(char *val, const char *src, int32_t len, int32_t type); void assignVal(char *val, const char *src, int32_t len, int32_t type);
void tsDataSwap(void *pLeft, void *pRight, int32_t type, int32_t size, void* buf); void tsDataSwap(void *pLeft, void *pRight, int32_t type, int32_t size, void *buf);
void operateVal(void *dst, void *s1, void *s2, int32_t optr, int32_t type); void operateVal(void *dst, void *s1, void *s2, int32_t optr, int32_t type);
void* getDataMin(int32_t type); void *getDataMin(int32_t type);
void* getDataMax(int32_t type); void *getDataMax(int32_t type);
#define SET_DOUBLE_NULL(v) (*(uint64_t *)(v) = TSDB_DATA_DOUBLE_NULL) #define SET_DOUBLE_NULL(v) (*(uint64_t *)(v) = TSDB_DATA_DOUBLE_NULL)
#define SET_BIGINT_NULL(v) (*(uint64_t *)(v) = TSDB_DATA_BIGINT_NULL) #define SET_BIGINT_NULL(v) (*(uint64_t *)(v) = TSDB_DATA_BIGINT_NULL)
...@@ -222,4 +231,4 @@ void* getDataMax(int32_t type); ...@@ -222,4 +231,4 @@ void* getDataMax(int32_t type);
} }
#endif #endif
#endif // TDENGINE_TTYPE_H #endif /*_TD_COMMON_TTYPE_H_*/
...@@ -13,15 +13,15 @@ ...@@ -13,15 +13,15 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#ifndef TDENGINE_TVARIANT_H #ifndef _TD_COMMON_VARIANT_H_
#define TDENGINE_TVARIANT_H #define _TD_COMMON_VARIANT_H_
#include "tarray.h"
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C" {
#endif #endif
#include "tarray.h"
// variant, each number/string/field_id has a corresponding struct during parsing sql // variant, each number/string/field_id has a corresponding struct during parsing sql
typedef struct SVariant { typedef struct SVariant {
uint32_t nType; uint32_t nType;
...@@ -36,11 +36,11 @@ typedef struct SVariant { ...@@ -36,11 +36,11 @@ typedef struct SVariant {
}; };
} SVariant; } SVariant;
int32_t toInteger(const char* z, int32_t n, int32_t base, int64_t* value, bool* issigned); int32_t toInteger(const char *z, int32_t n, int32_t base, int64_t *value, bool *issigned);
bool taosVariantIsValid(SVariant *pVar); bool taosVariantIsValid(SVariant *pVar);
void taosVariantCreate(SVariant *pVar, const char* z, int32_t n, int32_t type); void taosVariantCreate(SVariant *pVar, const char *z, int32_t n, int32_t type);
void taosVariantCreateFromBinary(SVariant *pVar, const char *pz, size_t len, uint32_t type); void taosVariantCreateFromBinary(SVariant *pVar, const char *pz, size_t len, uint32_t type);
...@@ -48,7 +48,7 @@ void taosVariantDestroy(SVariant *pV); ...@@ -48,7 +48,7 @@ void taosVariantDestroy(SVariant *pV);
void taosVariantAssign(SVariant *pDst, const SVariant *pSrc); void taosVariantAssign(SVariant *pDst, const SVariant *pSrc);
int32_t taosVariantCompare(const SVariant* p1, const SVariant* p2); int32_t taosVariantCompare(const SVariant *p1, const SVariant *p2);
int32_t taosVariantToString(SVariant *pVar, char *dst); int32_t taosVariantToString(SVariant *pVar, char *dst);
...@@ -64,4 +64,4 @@ int32_t taosVariantTypeSetType(SVariant *pVariant, char type); ...@@ -64,4 +64,4 @@ int32_t taosVariantTypeSetType(SVariant *pVariant, char type);
} }
#endif #endif
#endif // TDENGINE_TVARIANT_H #endif /*_TD_COMMON_VARIANT_H_*/
...@@ -25,26 +25,12 @@ extern "C" { ...@@ -25,26 +25,12 @@ extern "C" {
/* ------------------------ TYPES EXPOSED ---------------- */ /* ------------------------ TYPES EXPOSED ---------------- */
typedef struct SDnode SDnode; typedef struct SDnode SDnode;
/* ------------------------ Environment ------------------ */
typedef struct {
int32_t sver;
int32_t numOfCores;
int16_t numOfCommitThreads;
int8_t enableTelem;
char timezone[TSDB_TIMEZONE_LEN];
char locale[TSDB_LOCALE_LEN];
char charset[TSDB_LOCALE_LEN];
char buildinfo[64];
char gitinfo[48];
} SDnodeEnvCfg;
/** /**
* @brief Initialize the environment * @brief Initialize the environment
* *
* @param pOption Option of the environment
* @return int32_t 0 for success and -1 for failure * @return int32_t 0 for success and -1 for failure
*/ */
int32_t dndInit(const SDnodeEnvCfg *pCfg); int32_t dndInit();
/** /**
* @brief clear the environment * @brief clear the environment
...@@ -55,16 +41,14 @@ void dndCleanup(); ...@@ -55,16 +41,14 @@ void dndCleanup();
/* ------------------------ SDnode ----------------------- */ /* ------------------------ SDnode ----------------------- */
typedef struct { typedef struct {
int32_t numOfSupportVnodes; int32_t numOfSupportVnodes;
int32_t statusInterval;
float numOfThreadsPerCore;
float ratioOfQueryCores;
int32_t maxShellConns;
int32_t shellActivityTimer;
uint16_t serverPort; uint16_t serverPort;
char dataDir[TSDB_FILENAME_LEN]; char dataDir[TSDB_FILENAME_LEN];
char localEp[TSDB_EP_LEN]; char localEp[TSDB_EP_LEN];
char localFqdn[TSDB_FQDN_LEN]; char localFqdn[TSDB_FQDN_LEN];
char firstEp[TSDB_EP_LEN]; char firstEp[TSDB_EP_LEN];
char secondEp[TSDB_EP_LEN];
SDiskCfg *pDisks;
int32_t numOfDisks;
} SDnodeObjCfg; } SDnodeObjCfg;
/** /**
......
...@@ -44,25 +44,12 @@ typedef struct SMnodeLoad { ...@@ -44,25 +44,12 @@ typedef struct SMnodeLoad {
int64_t compStorage; int64_t compStorage;
} SMnodeLoad; } SMnodeLoad;
typedef struct SMnodeCfg {
int32_t sver;
int8_t enableTelem;
int32_t statusInterval;
int32_t shellActivityTimer;
char *timezone;
char *locale;
char *charset;
char *buildinfo;
char *gitinfo;
} SMnodeCfg;
typedef struct { typedef struct {
int32_t dnodeId; int32_t dnodeId;
int64_t clusterId; int64_t clusterId;
int8_t replica; int8_t replica;
int8_t selfIndex; int8_t selfIndex;
SReplica replicas[TSDB_MAX_REPLICA]; SReplica replicas[TSDB_MAX_REPLICA];
SMnodeCfg cfg;
SDnode *pDnode; SDnode *pDnode;
PutReqToMWriteQFp putReqToMWriteQFp; PutReqToMWriteQFp putReqToMWriteQFp;
PutReqToMReadQFp putReqToMReadQFp; PutReqToMReadQFp putReqToMReadQFp;
......
...@@ -24,7 +24,7 @@ extern "C" { ...@@ -24,7 +24,7 @@ extern "C" {
#include "taosdef.h" #include "taosdef.h"
#include "query.h" #include "query.h"
#include "tname.h" #include "tname.h"
#include "common.h" #include "tcommon.h"
#include "tarray.h" #include "tarray.h"
#include "thash.h" #include "thash.h"
#include "tmsg.h" #include "tmsg.h"
......
...@@ -20,7 +20,7 @@ ...@@ -20,7 +20,7 @@
extern "C" { extern "C" {
#endif #endif
#include "common.h" #include "tcommon.h"
typedef void* qTaskInfo_t; typedef void* qTaskInfo_t;
typedef void* DataSinkHandle; typedef void* DataSinkHandle;
...@@ -31,6 +31,7 @@ typedef struct SReadHandle { ...@@ -31,6 +31,7 @@ typedef struct SReadHandle {
void* reader; void* reader;
void* meta; void* meta;
} SReadHandle; } SReadHandle;
/** /**
* Create the exec task for streaming mode * Create the exec task for streaming mode
* @param pMsg * @param pMsg
...@@ -40,13 +41,23 @@ typedef struct SReadHandle { ...@@ -40,13 +41,23 @@ typedef struct SReadHandle {
qTaskInfo_t qCreateStreamExecTaskInfo(void *msg, void* streamReadHandle); qTaskInfo_t qCreateStreamExecTaskInfo(void *msg, void* streamReadHandle);
/** /**
* * Set the input data block for the stream scan.
* @param tinfo * @param tinfo
* @param input * @param input
* @return * @return
*/ */
int32_t qSetStreamInput(qTaskInfo_t tinfo, const void* input); int32_t qSetStreamInput(qTaskInfo_t tinfo, const void* input);
/**
* Update the table id list, add or remove.
*
* @param tinfo
* @param id
* @param isAdd
* @return
*/
int32_t qUpdateQualifiedTableId(qTaskInfo_t tinfo, SArray* tableIdList, bool isAdd);
/** /**
* Create the exec task object according to task json * Create the exec task object according to task json
* @param readHandle * @param readHandle
......
...@@ -20,7 +20,7 @@ ...@@ -20,7 +20,7 @@
extern "C" { extern "C" {
#endif #endif
#include "common.h" #include "tcommon.h"
#include "tvariant.h" #include "tvariant.h"
#include "tbuffer.h" #include "tbuffer.h"
...@@ -138,8 +138,10 @@ extern SFunctionFpSet fpSet[1]; ...@@ -138,8 +138,10 @@ extern SFunctionFpSet fpSet[1];
// sql function runtime context // sql function runtime context
typedef struct SqlFunctionCtx { typedef struct SqlFunctionCtx {
int32_t startRow;
int32_t size; // number of rows int32_t size; // number of rows
void * pInput; // input data buffer SColumnInfoData* pInput;
uint32_t order; // asc|desc uint32_t order; // asc|desc
int16_t inputType; int16_t inputType;
int16_t inputBytes; int16_t inputBytes;
...@@ -227,8 +229,13 @@ typedef struct SAggFunctionInfo { ...@@ -227,8 +229,13 @@ typedef struct SAggFunctionInfo {
} SAggFunctionInfo; } SAggFunctionInfo;
typedef struct SScalarParam { typedef struct SScalarParam {
void* data; void *data;
bool colData; union {
SColumnInfoData *columnData;
void *data;
} orig;
char *bitmap;
bool dataInBlock;
int32_t num; int32_t num;
int32_t type; int32_t type;
int32_t bytes; int32_t bytes;
......
...@@ -62,9 +62,8 @@ typedef enum ENodeType { ...@@ -62,9 +62,8 @@ typedef enum ENodeType {
QUERY_NODE_NODE_LIST, QUERY_NODE_NODE_LIST,
QUERY_NODE_FILL, QUERY_NODE_FILL,
QUERY_NODE_RAW_EXPR, // Only be used in parser module. QUERY_NODE_RAW_EXPR, // Only be used in parser module.
QUERY_NODE_COLUMN_REF,
QUERY_NODE_TARGET, QUERY_NODE_TARGET,
QUERY_NODE_TUPLE_DESC, QUERY_NODE_DATABLOCK_DESC,
QUERY_NODE_SLOT_DESC, QUERY_NODE_SLOT_DESC,
// Statement nodes are used in parser and planner module. // Statement nodes are used in parser and planner module.
...@@ -81,7 +80,9 @@ typedef enum ENodeType { ...@@ -81,7 +80,9 @@ typedef enum ENodeType {
// physical plan node // physical plan node
QUERY_NODE_PHYSICAL_PLAN_TAG_SCAN, QUERY_NODE_PHYSICAL_PLAN_TAG_SCAN,
QUERY_NODE_PHYSICAL_PLAN_TABLE_SCAN, QUERY_NODE_PHYSICAL_PLAN_TABLE_SCAN,
QUERY_NODE_PHYSICAL_PLAN_PROJECT QUERY_NODE_PHYSICAL_PLAN_PROJECT,
QUERY_NODE_PHYSICAL_PLAN_JOIN,
QUERY_NODE_PHYSICAL_PLAN_AGG
} ENodeType; } ENodeType;
/** /**
......
...@@ -69,21 +69,20 @@ typedef struct SSlotDescNode { ...@@ -69,21 +69,20 @@ typedef struct SSlotDescNode {
ENodeType type; ENodeType type;
int16_t slotId; int16_t slotId;
SDataType dataType; SDataType dataType;
int16_t srcTupleId;
int16_t srcSlotId;
bool reserve; bool reserve;
bool output; bool output;
bool tag;
} SSlotDescNode; } SSlotDescNode;
typedef struct STupleDescNode { typedef struct SDataBlockDescNode {
ENodeType type; ENodeType type;
int16_t tupleId; int16_t dataBlockId;
SNodeList* pSlots; SNodeList* pSlots;
} STupleDescNode; } SDataBlockDescNode;
typedef struct SPhysiNode { typedef struct SPhysiNode {
ENodeType type; ENodeType type;
STupleDescNode outputTuple; SDataBlockDescNode outputDataBlockDesc;
SNode* pConditions; SNode* pConditions;
SNodeList* pChildren; SNodeList* pChildren;
struct SPhysiNode* pParent; struct SPhysiNode* pParent;
...@@ -106,6 +105,7 @@ typedef struct STableScanPhysiNode { ...@@ -106,6 +105,7 @@ typedef struct STableScanPhysiNode {
SScanPhysiNode scan; SScanPhysiNode scan;
uint8_t scanFlag; // denotes reversed scan of data or not uint8_t scanFlag; // denotes reversed scan of data or not
STimeWindow scanRange; STimeWindow scanRange;
SNode* pScanConditions;
} STableScanPhysiNode; } STableScanPhysiNode;
typedef STableScanPhysiNode STableSeqScanPhysiNode; typedef STableScanPhysiNode STableSeqScanPhysiNode;
...@@ -115,6 +115,20 @@ typedef struct SProjectPhysiNode { ...@@ -115,6 +115,20 @@ typedef struct SProjectPhysiNode {
SNodeList* pProjections; SNodeList* pProjections;
} SProjectPhysiNode; } SProjectPhysiNode;
typedef struct SJoinPhysiNode {
SPhysiNode node;
EJoinType joinType;
SNode* pOnConditions; // in or out tuple ?
SNodeList* pTargets;
} SJoinPhysiNode;
typedef struct SAggPhysiNode {
SPhysiNode node;
SNodeList* pExprs; // these are expression list of group_by_clause and parameter expression of aggregate function
SNodeList* pGroupKeys; // SColumnRefNode list
SNodeList* pAggFuncs;
} SAggPhysiNode;
#ifdef __cplusplus #ifdef __cplusplus
} }
#endif #endif
......
...@@ -58,19 +58,13 @@ typedef struct SColumnNode { ...@@ -58,19 +58,13 @@ typedef struct SColumnNode {
char tableAlias[TSDB_TABLE_NAME_LEN]; char tableAlias[TSDB_TABLE_NAME_LEN];
char colName[TSDB_COL_NAME_LEN]; char colName[TSDB_COL_NAME_LEN];
SNode* pProjectRef; SNode* pProjectRef;
} SColumnNode; int16_t dataBlockId;
typedef struct SColumnRefNode {
ENodeType type;
SDataType dataType;
int16_t tupleId;
int16_t slotId; int16_t slotId;
int16_t columnId; } SColumnNode;
} SColumnRefNode;
typedef struct STargetNode { typedef struct STargetNode {
ENodeType type; ENodeType type;
int16_t tupleId; int16_t dataBlockId;
int16_t slotId; int16_t slotId;
SNode* pExpr; SNode* pExpr;
} STargetNode; } STargetNode;
......
...@@ -21,7 +21,7 @@ extern "C" { ...@@ -21,7 +21,7 @@ extern "C" {
#endif #endif
#include "catalog.h" #include "catalog.h"
#include "common.h" #include "tcommon.h"
#include "function.h" #include "function.h"
#include "tmsgtype.h" #include "tmsgtype.h"
#include "tname.h" #include "tname.h"
......
...@@ -47,5 +47,6 @@ OP_ENUM_MACRO(AllTimeWindow) ...@@ -47,5 +47,6 @@ OP_ENUM_MACRO(AllTimeWindow)
OP_ENUM_MACRO(AllMultiTableTimeInterval) OP_ENUM_MACRO(AllMultiTableTimeInterval)
OP_ENUM_MACRO(Order) OP_ENUM_MACRO(Order)
OP_ENUM_MACRO(Exchange) OP_ENUM_MACRO(Exchange)
OP_ENUM_MACRO(SortedMerge)
//OP_ENUM_MACRO(TableScan) //OP_ENUM_MACRO(TableScan)
...@@ -37,8 +37,8 @@ typedef struct SFilterColumnParam{ ...@@ -37,8 +37,8 @@ typedef struct SFilterColumnParam{
extern int32_t filterInitFromNode(SNode *pNode, SFilterInfo **pinfo, uint32_t options); extern int32_t filterInitFromNode(SNode *pNode, SFilterInfo **pinfo, uint32_t options);
extern bool filterExecute(SFilterInfo *info, SSDataBlock *pSrc, int8_t** p, SColumnDataAgg *statis, int16_t numOfCols); extern bool filterExecute(SFilterInfo *info, SSDataBlock *pSrc, int8_t** p, SColumnDataAgg *statis, int16_t numOfCols);
extern int32_t filterSetDataFromSlotId(SFilterInfo *info, void *param, filer_get_col_from_id fp); extern int32_t filterSetDataFromSlotId(SFilterInfo *info, void *param);
extern int32_t filterSetDataFromColId(SFilterInfo *info, void *param, filer_get_col_from_id fp); extern int32_t filterSetDataFromColId(SFilterInfo *info, void *param);
extern int32_t filterGetTimeRange(SFilterInfo *info, STimeWindow *win); extern int32_t filterGetTimeRange(SFilterInfo *info, STimeWindow *win);
extern int32_t filterConverNcharColumns(SFilterInfo* pFilterInfo, int32_t rows, bool *gotNchar); extern int32_t filterConverNcharColumns(SFilterInfo* pFilterInfo, int32_t rows, bool *gotNchar);
extern int32_t filterFreeNcharColumns(SFilterInfo* pFilterInfo); extern int32_t filterFreeNcharColumns(SFilterInfo* pFilterInfo);
......
...@@ -25,9 +25,17 @@ extern "C" { ...@@ -25,9 +25,17 @@ extern "C" {
typedef struct SFilterInfo SFilterInfo; typedef struct SFilterInfo SFilterInfo;
/*
pNode will be freed in API;
*pRes need to freed in caller
*/
int32_t scalarCalculateConstants(SNode *pNode, SNode **pRes); int32_t scalarCalculateConstants(SNode *pNode, SNode **pRes);
int32_t scalarCalculate(SNode *pNode, SSDataBlock *pSrc, SScalarParam *pDst);
/*
pDst need to freed in caller
*/
int32_t scalarCalculate(SNode *pNode, SArray *pBlockList, SScalarParam *pDst);
int32_t scalarGetOperatorParamNum(EOperatorType type); int32_t scalarGetOperatorParamNum(EOperatorType type);
int32_t scalarGenerateSetFromList(void **data, void *pNode, uint32_t type); int32_t scalarGenerateSetFromList(void **data, void *pNode, uint32_t type);
......
...@@ -21,7 +21,9 @@ extern "C" { ...@@ -21,7 +21,9 @@ extern "C" {
#endif #endif
#include <stdint.h> #include <stdint.h>
#include <tep.h>
#include "taosdef.h" #include "taosdef.h"
#include "trpc.h"
typedef uint64_t SyncNodeId; typedef uint64_t SyncNodeId;
typedef int32_t SyncGroupId; typedef int32_t SyncGroupId;
...@@ -34,23 +36,23 @@ typedef enum { ...@@ -34,23 +36,23 @@ typedef enum {
TAOS_SYNC_STATE_LEADER = 2, TAOS_SYNC_STATE_LEADER = 2,
} ESyncState; } ESyncState;
typedef struct { typedef struct SSyncBuffer {
void* data; void* data;
size_t len; size_t len;
} SSyncBuffer; } SSyncBuffer;
typedef struct { typedef struct SNodeInfo {
SyncNodeId nodeId;
uint16_t nodePort; // node sync Port uint16_t nodePort; // node sync Port
char nodeFqdn[TSDB_FQDN_LEN]; // node FQDN char nodeFqdn[TSDB_FQDN_LEN]; // node FQDN
} SNodeInfo; } SNodeInfo;
typedef struct { typedef struct SSyncCfg {
int32_t replicaNum; int32_t replicaNum;
int32_t myIndex;
SNodeInfo nodeInfo[TSDB_MAX_REPLICA]; SNodeInfo nodeInfo[TSDB_MAX_REPLICA];
} SSyncCfg; } SSyncCfg;
typedef struct { typedef struct SNodesRole {
int32_t replicaNum; int32_t replicaNum;
SNodeInfo nodeInfo[TSDB_MAX_REPLICA]; SNodeInfo nodeInfo[TSDB_MAX_REPLICA];
ESyncState role[TSDB_MAX_REPLICA]; ESyncState role[TSDB_MAX_REPLICA];
...@@ -128,12 +130,12 @@ typedef struct SStateMgr { ...@@ -128,12 +130,12 @@ typedef struct SStateMgr {
} SStateMgr; } SStateMgr;
typedef struct { typedef struct SSyncInfo {
SyncGroupId vgId; SyncGroupId vgId;
SSyncCfg syncCfg; SSyncCfg syncCfg;
SSyncLogStore logStore; char path[TSDB_FILENAME_LEN];
SStateMgr stateManager; SSyncFSM* pFsm;
SSyncFSM syncFsm; int32_t (*FpSendMsg)(void* handle, const SEpSet* pEpSet, SRpcMsg* pMsg);
} SSyncInfo; } SSyncInfo;
......
...@@ -16,7 +16,7 @@ ...@@ -16,7 +16,7 @@
#ifndef _TD_TFS_H_ #ifndef _TD_TFS_H_
#define _TD_TFS_H_ #define _TD_TFS_H_
#include "tcfg.h" #include "tdef.h"
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C" {
......
...@@ -78,12 +78,15 @@ typedef struct SRpcInit { ...@@ -78,12 +78,15 @@ typedef struct SRpcInit {
// call back to retrieve the client auth info, for server app only // call back to retrieve the client auth info, for server app only
int (*afp)(void *parent, char *tableId, char *spi, char *encrypt, char *secret, char *ckey); int (*afp)(void *parent, char *tableId, char *spi, char *encrypt, char *secret, char *ckey);
// call back to keep conn or not
bool (*pfp)(void *parent, tmsg_t msgType);
void *parent; void *parent;
} SRpcInit; } SRpcInit;
int32_t rpcInit(); int32_t rpcInit();
void rpcCleanup(); void rpcCleanup();
void * rpcOpen(const SRpcInit *pRpc); void *rpcOpen(const SRpcInit *pRpc);
void rpcClose(void *); void rpcClose(void *);
void * rpcMallocCont(int contLen); void * rpcMallocCont(int contLen);
void rpcFreeCont(void *pCont); void rpcFreeCont(void *pCont);
......
...@@ -120,8 +120,8 @@ typedef struct SWal { ...@@ -120,8 +120,8 @@ typedef struct SWal {
int32_t fsyncSeq; int32_t fsyncSeq;
// meta // meta
SWalVer vers; SWalVer vers;
int64_t writeLogTfd; TdFilePtr pWriteLogTFile;
int64_t writeIdxTfd; TdFilePtr pWriteIdxTFile;
int32_t writeCur; int32_t writeCur;
SArray *fileInfoSet; SArray *fileInfoSet;
// status // status
...@@ -138,8 +138,8 @@ typedef struct SWal { ...@@ -138,8 +138,8 @@ typedef struct SWal {
typedef struct SWalReadHandle { typedef struct SWalReadHandle {
SWal *pWal; SWal *pWal;
int64_t readLogTfd; TdFilePtr pReadLogTFile;
int64_t readIdxTfd; TdFilePtr pReadIdxTFile;
int64_t curFileFirstVer; int64_t curFileFirstVer;
int64_t curVersion; int64_t curVersion;
int64_t capacity; int64_t capacity;
......
...@@ -13,8 +13,8 @@ ...@@ -13,8 +13,8 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#ifndef TDENGINE_OS_H #ifndef _TD_OS_H_
#define TDENGINE_OS_H #define _TD_OS_H_
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C" {
...@@ -59,6 +59,7 @@ extern "C" { ...@@ -59,6 +59,7 @@ extern "C" {
#include "osEndian.h" #include "osEndian.h"
#include "osEnv.h" #include "osEnv.h"
#include "osFile.h" #include "osFile.h"
#include "osLocale.h"
#include "osLz4.h" #include "osLz4.h"
#include "osMath.h" #include "osMath.h"
#include "osMemory.h" #include "osMemory.h"
...@@ -73,6 +74,7 @@ extern "C" { ...@@ -73,6 +74,7 @@ extern "C" {
#include "osThread.h" #include "osThread.h"
#include "osTime.h" #include "osTime.h"
#include "osTimer.h" #include "osTimer.h"
#include "osTimezone.h"
void osInit(); void osInit();
...@@ -80,4 +82,4 @@ void osInit(); ...@@ -80,4 +82,4 @@ void osInit();
} }
#endif #endif
#endif #endif /*_TD_OS_H_*/
...@@ -191,6 +191,10 @@ extern "C" { ...@@ -191,6 +191,10 @@ extern "C" {
#define TD_DIRSEP "/" #define TD_DIRSEP "/"
#endif #endif
#define TD_LOCALE_LEN 64
#define TD_CHARSET_LEN 64
#define TD_TIMEZONE_LEN 96
#ifdef __cplusplus #ifdef __cplusplus
} }
#endif #endif
......
...@@ -23,8 +23,8 @@ extern "C" { ...@@ -23,8 +23,8 @@ extern "C" {
void taosRemoveDir(const char *dirname); void taosRemoveDir(const char *dirname);
int32_t taosDirExist(char *dirname); int32_t taosDirExist(char *dirname);
int32_t taosMkDir(const char *dirname); int32_t taosMkDir(const char *dirname);
void taosRemoveOldFiles(char *dirname, int32_t keepDays); void taosRemoveOldFiles(const char *dirname, int32_t keepDays);
int32_t taosExpandDir(char *dirname, char *outname, int32_t maxlen); int32_t taosExpandDir(const char *dirname, char *outname, int32_t maxlen);
int32_t taosRealPath(char *dirname, int32_t maxlen); int32_t taosRealPath(char *dirname, int32_t maxlen);
#ifdef __cplusplus #ifdef __cplusplus
......
...@@ -16,15 +16,37 @@ ...@@ -16,15 +16,37 @@
#ifndef _TD_OS_ENV_H_ #ifndef _TD_OS_ENV_H_
#define _TD_OS_ENV_H_ #define _TD_OS_ENV_H_
#include "osSysinfo.h"
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C" {
#endif #endif
extern char tsOsName[]; extern char tsOsName[];
extern char tsTimezone[];
extern char tsCharset[];
extern char tsLocale[];
extern int8_t tsDaylight;
extern bool tsEnableCoreFile;
extern int64_t tsPageSize;
extern int64_t tsOpenMax;
extern int64_t tsStreamMax;
extern int32_t tsNumOfCores;
extern int32_t tsTotalMemoryMB;
extern char configDir[];
extern char tsDataDir[]; extern char tsDataDir[];
extern char tsLogDir[]; extern char tsLogDir[];
extern char tsScriptDir[]; extern char tsTempDir[];
extern char configDir[];
extern SDiskSpace tsDataSpace;
extern SDiskSpace tsLogSpace;
extern SDiskSpace tsTempSpace;
void osInit();
void osUpdate();
bool osLogSpaceAvailable();
void osSetTimezone(const char *timezone);
#ifdef __cplusplus #ifdef __cplusplus
} }
......
...@@ -22,49 +22,64 @@ extern "C" { ...@@ -22,49 +22,64 @@ extern "C" {
#include "osSocket.h" #include "osSocket.h"
#if defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32) #ifndef ALLOW_FORBID_FUNC
typedef int32_t FileFd; #define open OPEN_FUNC_TAOS_FORBID
#else #define fopen FOPEN_FUNC_TAOS_FORBID
typedef int32_t FileFd; // #define close CLOSE_FUNC_TAOS_FORBID
// #define fclose FCLOSE_FUNC_TAOS_FORBID
#endif #endif
#define FD_INITIALIZER ((int32_t)-1)
#ifndef PATH_MAX #ifndef PATH_MAX
#define PATH_MAX 256 #define PATH_MAX 256
#endif #endif
int32_t taosLockFile(FileFd fd); typedef struct TdFile *TdFilePtr;
int32_t taosUnLockFile(FileFd fd);
#define TD_FILE_CTEATE 0x0001
#define TD_FILE_WRITE 0x0002
#define TD_FILE_READ 0x0004
#define TD_FILE_TRUNC 0x0008
#define TD_FILE_APPEND 0x0010
#define TD_FILE_TEXT 0x0020
#define TD_FILE_AUTO_DEL 0x0040
#define TD_FILE_EXCL 0x0080
#define TD_FILE_STREAM 0x0100 // Only support taosFprintfFile, taosGetLineFile, taosGetLineFile, taosEOFFile
int32_t taosLockFile(TdFilePtr pFile);
int32_t taosUnLockFile(TdFilePtr pFile);
int32_t taosUmaskFile(FileFd fd); int32_t taosUmaskFile(int32_t maskVal);
int32_t taosStatFile(const char *path, int64_t *size, int32_t *mtime); int32_t taosStatFile(const char *path, int64_t *size, int32_t *mtime);
int32_t taosFStatFile(FileFd fd, int64_t *size, int32_t *mtime); int32_t taosFStatFile(TdFilePtr pFile, int64_t *size, int32_t *mtime);
FileFd taosOpenFileWrite(const char *path); TdFilePtr taosOpenFile(const char *path,int32_t tdFileOptions);
FileFd taosOpenFileCreateWrite(const char *path);
FileFd taosOpenFileCreateWriteTrunc(const char *path);
FileFd taosOpenFileCreateWriteAppend(const char *path);
FileFd taosOpenFileRead(const char *path);
FileFd taosOpenFileReadWrite(const char *path);
int64_t taosLSeekFile(FileFd fd, int64_t offset, int32_t whence); int64_t taosLSeekFile(TdFilePtr pFile, int64_t offset, int32_t whence);
int32_t taosFtruncateFile(FileFd fd, int64_t length); int32_t taosFtruncateFile(TdFilePtr pFile, int64_t length);
int32_t taosFsyncFile(FileFd fd); int32_t taosFsyncFile(TdFilePtr pFile);
int64_t taosReadFile(FileFd fd, void *buf, int64_t count); int64_t taosReadFile(TdFilePtr pFile, void *buf, int64_t count);
int64_t taosWriteFile(FileFd fd, const void *buf, int64_t count); int64_t taosPReadFile(TdFilePtr pFile, void *buf, int64_t count, int64_t offset);
int64_t taosWriteFile(TdFilePtr pFile, const void *buf, int64_t count);
void taosFprintfFile(TdFilePtr pFile, const char *format, ...);
int64_t taosGetLineFile(TdFilePtr pFile, char ** __restrict__ ptrBuf);
int32_t taosEOFFile(TdFilePtr pFile);
void taosCloseFile(FileFd fd); int64_t taosCloseFile(TdFilePtr *ppFile);
int32_t taosRenameFile(const char *oldName, const char *newName); int32_t taosRenameFile(const char *oldName, const char *newName);
int64_t taosCopyFile(const char *from, const char *to); int64_t taosCopyFile(const char *from, const char *to);
void taosGetTmpfilePath(const char *inputTmpDir, const char *fileNamePrefix, char *dstPath); void taosGetTmpfilePath(const char *inputTmpDir, const char *fileNamePrefix, char *dstPath);
int64_t taosSendFile(SocketFd dfd, FileFd sfd, int64_t *offset, int64_t size); int64_t taosSendFile(SocketFd fdDst, TdFilePtr pFileSrc, int64_t *offset, int64_t size);
int64_t taosFSendFile(FILE *outfile, FILE *infile, int64_t *offset, int64_t size); int64_t taosFSendFile(TdFilePtr pFileOut, TdFilePtr pFileIn, int64_t *offset, int64_t size);
void *taosMmapReadOnlyFile(TdFilePtr pFile, int64_t length);
bool taosValidFile(TdFilePtr pFile);
int taosGetErrorFile(TdFilePtr pFile);
#ifdef __cplusplus #ifdef __cplusplus
} }
......
/*
* 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/>.
*/
#ifndef _TD_OS_LOCALE_H_
#define _TD_OS_LOCALE_H_
#include "os.h"
#include "osString.h"
#ifdef __cplusplus
extern "C" {
#endif
char *taosCharsetReplace(char *charsetstr);
void taosGetSystemLocale(char *outLocale, char *outCharset);
void taosSetSystemLocale(const char *inLocale, const char *inCharSet);
#ifdef __cplusplus
}
#endif
#endif /*_TD_OS_LOCALE_H_*/
...@@ -16,12 +16,12 @@ ...@@ -16,12 +16,12 @@
#ifndef _TD_OS_SEMPHONE_H_ #ifndef _TD_OS_SEMPHONE_H_
#define _TD_OS_SEMPHONE_H_ #define _TD_OS_SEMPHONE_H_
#include <semaphore.h>
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C" {
#endif #endif
#include <semaphore.h>
#if defined (_TD_DARWIN_64) #if defined (_TD_DARWIN_64)
typedef struct tsem_s *tsem_t; typedef struct tsem_s *tsem_t;
int tsem_init(tsem_t *sem, int pshared, unsigned int value); int tsem_init(tsem_t *sem, int pshared, unsigned int value);
......
...@@ -16,10 +16,6 @@ ...@@ -16,10 +16,6 @@
#ifndef _TD_OS_SOCKET_H_ #ifndef _TD_OS_SOCKET_H_
#define _TD_OS_SOCKET_H_ #define _TD_OS_SOCKET_H_
#ifdef __cplusplus
extern "C" {
#endif
#if defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32) #if defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32)
#include "winsock2.h" #include "winsock2.h"
#include <WS2tcpip.h> #include <WS2tcpip.h>
...@@ -30,6 +26,10 @@ extern "C" { ...@@ -30,6 +26,10 @@ extern "C" {
#include <sys/epoll.h> #include <sys/epoll.h>
#endif #endif
#ifdef __cplusplus
extern "C" {
#endif
#define TAOS_EPOLL_WAIT_TIME 500 #define TAOS_EPOLL_WAIT_TIME 500
typedef int32_t SOCKET; typedef int32_t SOCKET;
typedef SOCKET EpollFd; typedef SOCKET EpollFd;
...@@ -55,7 +55,7 @@ void taosSetMaskSIGPIPE(); ...@@ -55,7 +55,7 @@ void taosSetMaskSIGPIPE();
int32_t taosSetSockOpt(SOCKET socketfd, int32_t level, int32_t optname, void *optval, int32_t optlen); int32_t taosSetSockOpt(SOCKET socketfd, int32_t level, int32_t optname, void *optval, int32_t optlen);
int32_t taosGetSockOpt(SOCKET socketfd, int32_t level, int32_t optname, void *optval, int32_t *optlen); int32_t taosGetSockOpt(SOCKET socketfd, int32_t level, int32_t optname, void *optval, int32_t *optlen);
uint32_t taosInetAddr(char *ipAddr); uint32_t taosInetAddr(const char *ipAddr);
const char *taosInetNtoa(struct in_addr ipInt); const char *taosInetNtoa(struct in_addr ipInt);
#if (defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32)) #if (defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32))
......
...@@ -45,7 +45,6 @@ int32_t taosUcs4ToMbs(void *ucs4, int32_t ucs4_max_len, char *mbs); ...@@ -45,7 +45,6 @@ int32_t taosUcs4ToMbs(void *ucs4, int32_t ucs4_max_len, char *mbs);
bool taosMbsToUcs4(const char *mbs, size_t mbs_len, char *ucs4, int32_t ucs4_max_len, int32_t *len); bool taosMbsToUcs4(const char *mbs, size_t mbs_len, char *ucs4, int32_t ucs4_max_len, int32_t *len);
int32_t tasoUcs4Compare(void *f1_ucs4, void *f2_ucs4, int32_t bytes, int8_t ncharSize); int32_t tasoUcs4Compare(void *f1_ucs4, void *f2_ucs4, int32_t bytes, int8_t ncharSize);
bool taosValidateEncodec(const char *encodec); bool taosValidateEncodec(const char *encodec);
char * taosCharsetReplace(char *charsetstr);
#ifdef __cplusplus #ifdef __cplusplus
} }
......
...@@ -16,30 +16,23 @@ ...@@ -16,30 +16,23 @@
#ifndef _TD_OS_SYSINFO_H_ #ifndef _TD_OS_SYSINFO_H_
#define _TD_OS_SYSINFO_H_ #define _TD_OS_SYSINFO_H_
#include "os.h"
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C" {
#endif #endif
#include "os.h"
#define TSDB_LOCALE_LEN 64
#define TSDB_TIMEZONE_LEN 96
extern int64_t tsPageSize;
extern int64_t tsOpenMax;
extern int64_t tsStreamMax;
extern int32_t tsNumOfCores;
extern int32_t tsTotalMemoryMB;
extern char tsTimezone[];
extern char tsLocale[];
extern char tsCharset[]; // default encode string
typedef struct { typedef struct {
int64_t total; int64_t total;
int64_t used; int64_t used;
int64_t avail; int64_t avail;
} SDiskSize; } SDiskSize;
typedef struct {
int64_t reserved;
SDiskSize size;
} SDiskSpace;
int32_t taosGetDiskSize(char *dataDir, SDiskSize *diskSize); int32_t taosGetDiskSize(char *dataDir, SDiskSize *diskSize);
int32_t taosGetCpuCores(); int32_t taosGetCpuCores();
void taosGetSystemInfo(); void taosGetSystemInfo();
...@@ -51,7 +44,6 @@ void taosGetDisk(); ...@@ -51,7 +44,6 @@ void taosGetDisk();
bool taosGetCpuUsage(float *sysCpuUsage, float *procCpuUsage); bool taosGetCpuUsage(float *sysCpuUsage, float *procCpuUsage);
bool taosGetProcMemory(float *memoryUsedMB); bool taosGetProcMemory(float *memoryUsedMB);
bool taosGetSysMemory(float *memoryUsedMB); bool taosGetSysMemory(float *memoryUsedMB);
void taosPrintOsInfo();
int taosSystem(const char *cmd); int taosSystem(const char *cmd);
void taosKillSystem(); void taosKillSystem();
int32_t taosGetSystemUUID(char *uid, int32_t uidlen); int32_t taosGetSystemUUID(char *uid, int32_t uidlen);
......
...@@ -16,12 +16,12 @@ ...@@ -16,12 +16,12 @@
#ifndef _TD_OS_THREAD_H_ #ifndef _TD_OS_THREAD_H_
#define _TD_OS_THREAD_H_ #define _TD_OS_THREAD_H_
#include <pthread.h>
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C" {
#endif #endif
#include <pthread.h>
#ifdef __cplusplus #ifdef __cplusplus
} }
#endif #endif
......
...@@ -13,17 +13,18 @@ ...@@ -13,17 +13,18 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#ifndef _TD_COMMON_LOCALE_H_ #ifndef _TD_OS_TIMEZONE_H_
#define _TD_COMMON_LOCALE_H_ #define _TD_OS_TIMEZONE_H_
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C" {
#endif #endif
void tsSetLocale(); void taosGetSystemTimezone(char *outTimezone);
void taosSetSystemTimezone(const char *inTimezone, char *outTimezone, int8_t *outDaylight);
#ifdef __cplusplus #ifdef __cplusplus
} }
#endif /*_TD_COMMON_LOCALE_H_*/
#endif #endif
#endif /*_TD_OS_TIMEZONE_H_*/
/*
* Copyright (c) 2020 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/>.
*/
#ifndef _TD_UTIL_EXCEPTION_H
#define _TD_UTIL_EXCEPTION_H
#include "os.h"
#ifdef __cplusplus
extern "C" {
#endif
/*
* cleanup actions
*/
typedef struct SCleanupAction {
bool failOnly;
uint8_t wrapper;
uint16_t reserved;
void* func;
union {
void* Ptr;
bool Bool;
char Char;
int8_t Int8;
uint8_t Uint8;
int16_t Int16;
uint16_t Uint16;
int Int;
unsigned int Uint;
int32_t Int32;
uint32_t Uint32;
int64_t Int64;
uint64_t Uint64;
float Float;
double Double;
} arg1, arg2;
} SCleanupAction;
/*
* exception hander registration
*/
typedef struct SExceptionNode {
struct SExceptionNode* prev;
jmp_buf jb;
int32_t code;
int32_t maxCleanupAction;
int32_t numCleanupAction;
SCleanupAction* cleanupActions;
} SExceptionNode;
////////////////////////////////////////////////////////////////////////////////
// functions & macros for auto-cleanup
void cleanupPush_void_ptr_ptr ( bool failOnly, void* func, void* arg1, void* arg2 );
void cleanupPush_void_ptr_bool ( bool failOnly, void* func, void* arg1, bool arg2 );
void cleanupPush_void_ptr ( bool failOnly, void* func, void* arg );
void cleanupPush_int_int ( bool failOnly, void* func, int arg );
void cleanupPush_void ( bool failOnly, void* func );
void cleanupPush_int_ptr ( bool failOnly, void* func, void* arg );
int32_t cleanupGetActionCount();
void cleanupExecuteTo( int32_t anchor, bool failed );
void cleanupExecute( SExceptionNode* node, bool failed );
bool cleanupExceedLimit();
#define CLEANUP_PUSH_VOID_PTR_PTR( failOnly, func, arg1, arg2 ) cleanupPush_void_ptr_ptr( (failOnly), (void*)(func), (void*)(arg1), (void*)(arg2) )
#define CLEANUP_PUSH_VOID_PTR_BOOL( failOnly, func, arg1, arg2 ) cleanupPush_void_ptr_bool( (failOnly), (void*)(func), (void*)(arg1), (bool)(arg2) )
#define CLEANUP_PUSH_VOID_PTR( failOnly, func, arg ) cleanupPush_void_ptr( (failOnly), (void*)(func), (void*)(arg) )
#define CLEANUP_PUSH_INT_INT( failOnly, func, arg ) cleanupPush_void_ptr( (failOnly), (void*)(func), (int)(arg) )
#define CLEANUP_PUSH_VOID( failOnly, func ) cleanupPush_void( (failOnly), (void*)(func) )
#define CLEANUP_PUSH_INT_PTR( failOnly, func, arg ) cleanupPush_int_ptr( (failOnly), (void*)(func), (void*)(arg) )
#define CLEANUP_PUSH_FREE( failOnly, arg ) cleanupPush_void_ptr( (failOnly), free, (void*)(arg) )
#define CLEANUP_PUSH_CLOSE( failOnly, arg ) cleanupPush_int_int( (failOnly), close, (int)(arg) )
#define CLEANUP_PUSH_FCLOSE( failOnly, arg ) cleanupPush_int_ptr( (failOnly), fclose, (void*)(arg) )
#define CLEANUP_GET_ANCHOR() cleanupGetActionCount()
#define CLEANUP_EXECUTE_TO( anchor, failed ) cleanupExecuteTo( (anchor), (failed) )
#define CLEANUP_EXCEED_LIMIT() cleanupExceedLimit()
////////////////////////////////////////////////////////////////////////////////
// functions & macros for exception handling
void exceptionPushNode( SExceptionNode* node );
int32_t exceptionPopNode();
void exceptionThrow( int32_t code );
#define TRY(maxCleanupActions) do { \
SExceptionNode exceptionNode = { 0 }; \
SCleanupAction cleanupActions[(maxCleanupActions) > 0 ? (maxCleanupActions) : 1]; \
exceptionNode.maxCleanupAction = (maxCleanupActions) > 0 ? (maxCleanupActions) : 1; \
exceptionNode.cleanupActions = cleanupActions; \
exceptionPushNode( &exceptionNode ); \
int caughtException = setjmp( exceptionNode.jb ); \
if( caughtException == 0 )
#define CATCH( code ) int32_t code = exceptionPopNode(); \
if( caughtException == 1 )
#define FINALLY( code ) int32_t code = exceptionPopNode();
#define END_TRY } while( 0 );
#define THROW( x ) exceptionThrow( (x) )
#define CAUGHT_EXCEPTION() ((bool)(caughtException == 1))
#define CLEANUP_EXECUTE() cleanupExecute( &exceptionNode, CAUGHT_EXCEPTION() )
#ifdef __cplusplus
}
#endif
#endif /*_TD_UTIL_EXCEPTION_H*/
...@@ -13,16 +13,18 @@ ...@@ -13,16 +13,18 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#ifndef _TD_UTIL_TALGO_H #ifndef _TD_UTIL_TALGO_H_
#define _TD_UTIL_TALGO_H #define _TD_UTIL_TALGO_H_
#include "os.h"
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C" {
#endif #endif
#ifndef __COMPAR_FN_T #ifndef __COMPAR_FN_T
# define __COMPAR_FN_T #define __COMPAR_FN_T
typedef int (*__compar_fn_t) (const void *, const void *); typedef int32_t (*__compar_fn_t)(const void *, const void *);
#endif #endif
#define TD_EQ 0x1 #define TD_EQ 0x1
...@@ -45,7 +47,7 @@ typedef void (*__ext_swap_fn_t)(void *p1, void *p2, const void *param); ...@@ -45,7 +47,7 @@ typedef void (*__ext_swap_fn_t)(void *p1, void *p2, const void *param);
* @param param * @param param
* @param comparFn * @param comparFn
*/ */
void taosqsort(void *src, size_t numOfElem, size_t size, const void* param, __ext_compar_fn_t comparFn); void taosqsort(void *src, int64_t numOfElem, int64_t size, const void *param, __ext_compar_fn_t comparFn);
/** /**
* binary search, with range support * binary search, with range support
...@@ -58,7 +60,7 @@ void taosqsort(void *src, size_t numOfElem, size_t size, const void* param, __ex ...@@ -58,7 +60,7 @@ void taosqsort(void *src, size_t numOfElem, size_t size, const void* param, __ex
* @param flags * @param flags
* @return * @return
*/ */
void *taosbsearch(const void *key, const void *base, size_t nmemb, size_t size, __compar_fn_t fn, int flags); void *taosbsearch(const void *key, const void *base, int64_t nmemb, int64_t size, __compar_fn_t fn, int32_t flags);
/** /**
* adjust heap * adjust heap
...@@ -74,7 +76,8 @@ void *taosbsearch(const void *key, const void *base, size_t nmemb, size_t size, ...@@ -74,7 +76,8 @@ void *taosbsearch(const void *key, const void *base, size_t nmemb, size_t size,
* @param maxroot: if heap is max root heap * @param maxroot: if heap is max root heap
* @return * @return
*/ */
void taosheapadjust(void *base, int32_t size, int32_t start, int32_t end, const void *parcompar, __ext_compar_fn_t compar, const void *parswap, __ext_swap_fn_t swap, bool maxroot); void taosheapadjust(void *base, int32_t size, int32_t start, int32_t end, const void *parcompar,
__ext_compar_fn_t compar, const void *parswap, __ext_swap_fn_t swap, bool maxroot);
/** /**
* sort heap to make sure it is a max/min root heap * sort heap to make sure it is a max/min root heap
...@@ -89,10 +92,11 @@ void taosheapadjust(void *base, int32_t size, int32_t start, int32_t end, const ...@@ -89,10 +92,11 @@ void taosheapadjust(void *base, int32_t size, int32_t start, int32_t end, const
* @param maxroot: if heap is max root heap * @param maxroot: if heap is max root heap
* @return * @return
*/ */
void taosheapsort(void *base, int32_t size, int32_t len, const void *parcompar, __ext_compar_fn_t compar, const void *parswap, __ext_swap_fn_t swap, bool maxroot); void taosheapsort(void *base, int32_t size, int32_t len, const void *parcompar, __ext_compar_fn_t compar,
const void *parswap, __ext_swap_fn_t swap, bool maxroot);
#ifdef __cplusplus #ifdef __cplusplus
} }
#endif #endif
#endif /*_TD_UTIL_TALGO_H*/
#endif /*_TD_UTIL_TALGO_H_*/
此差异已折叠。
...@@ -13,16 +13,15 @@ ...@@ -13,16 +13,15 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#ifndef _TD_UTIL_ARRAY_H #ifndef _TD_UTIL_ARRAY_H_
#define _TD_UTIL_ARRAY_H #define _TD_UTIL_ARRAY_H_
#include "talgo.h"
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C" {
#endif #endif
#include "os.h"
#include "talgo.h"
#if 0 #if 0
#define TARRAY(TYPE) \ #define TARRAY(TYPE) \
struct { \ struct { \
...@@ -43,8 +42,8 @@ extern "C" { ...@@ -43,8 +42,8 @@ extern "C" {
typedef struct SArray { typedef struct SArray {
size_t size; size_t size;
size_t capacity; uint32_t capacity;
size_t elemSize; uint32_t elemSize;
void* pData; void* pData;
} SArray; } SArray;
...@@ -70,7 +69,7 @@ int32_t taosArrayEnsureCap(SArray* pArray, size_t tsize); ...@@ -70,7 +69,7 @@ int32_t taosArrayEnsureCap(SArray* pArray, size_t tsize);
* @param nEles * @param nEles
* @return * @return
*/ */
void* taosArrayAddBatch(SArray* pArray, const void* pData, int nEles); void* taosArrayAddBatch(SArray* pArray, const void* pData, int32_t nEles);
/** /**
* *
...@@ -238,7 +237,7 @@ void taosArraySortString(SArray* pArray, __compar_fn_t comparFn); ...@@ -238,7 +237,7 @@ void taosArraySortString(SArray* pArray, __compar_fn_t comparFn);
* @param compar * @param compar
* @param key * @param key
*/ */
void* taosArraySearch(const SArray* pArray, const void* key, __compar_fn_t comparFn, int flags); void* taosArraySearch(const SArray* pArray, const void* key, __compar_fn_t comparFn, int32_t flags);
/** /**
* search the array, return index of the element * search the array, return index of the element
...@@ -246,14 +245,14 @@ void* taosArraySearch(const SArray* pArray, const void* key, __compar_fn_t compa ...@@ -246,14 +245,14 @@ void* taosArraySearch(const SArray* pArray, const void* key, __compar_fn_t compa
* @param compar * @param compar
* @param key * @param key
*/ */
int32_t taosArraySearchIdx(const SArray* pArray, const void* key, __compar_fn_t comparFn, int flags); int32_t taosArraySearchIdx(const SArray* pArray, const void* key, __compar_fn_t comparFn, int32_t flags);
/** /**
* search the array * search the array
* @param pArray * @param pArray
* @param key * @param key
*/ */
char* taosArraySearchString(const SArray* pArray, const char* key, __compar_fn_t comparFn, int flags); char* taosArraySearchString(const SArray* pArray, const char* key, __compar_fn_t comparFn, int32_t flags);
/** /**
* sort the pointer data in the array * sort the pointer data in the array
...@@ -269,4 +268,4 @@ void taosArraySortPWithExt(SArray* pArray, __ext_compar_fn_t fn, const void* par ...@@ -269,4 +268,4 @@ void taosArraySortPWithExt(SArray* pArray, __ext_compar_fn_t fn, const void* par
} }
#endif #endif
#endif /*_TD_UTIL_ARRAY_H*/ #endif /*_TD_UTIL_ARRAY_H_*/
/*
* 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/>.
*/
#ifndef _TD_UTIL_BASE64_H_
#define _TD_UTIL_BASE64_H_
#include "os.h"
#ifdef __cplusplus
extern "C" {
#endif
uint8_t *base64_decode(const char *value, int32_t inlen, int32_t *outlen);
char *base64_encode(const uint8_t *value, int32_t vlen);
#ifdef __cplusplus
}
#endif
#endif /*_TD_UTIL_BASE64_H_*/
\ No newline at end of file
...@@ -13,8 +13,8 @@ ...@@ -13,8 +13,8 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#ifndef _TD_UTIL_BUFFER_H #ifndef _TD_UTIL_BUFFER_H_
#define _TD_UTIL_BUFFER_H #define _TD_UTIL_BUFFER_H_
#include "os.h" #include "os.h"
...@@ -26,9 +26,9 @@ extern "C" { ...@@ -26,9 +26,9 @@ extern "C" {
// usage example // usage example
/* /*
#include <stdio.h> #include <stdio.h>
#include "exception.h" #include "texception.h"
int main( int argc, char** argv ) { int32_t main( int32_t argc, char** argv ) {
SBufferWriter bw = tbufInitWriter( NULL, false ); SBufferWriter bw = tbufInitWriter( NULL, false );
TRY( 1 ) { TRY( 1 ) {
...@@ -39,7 +39,7 @@ int main( int argc, char** argv ) { ...@@ -39,7 +39,7 @@ int main( int argc, char** argv ) {
// reserve space for the interger count // reserve space for the interger count
size_t pos = tbufReserve( &bw, sizeof(int32_t) ); size_t pos = tbufReserve( &bw, sizeof(int32_t) );
// write 5 integers to the buffer // write 5 integers to the buffer
for( int i = 0; i < 5; i++) { for( int32_t i = 0; i < 5; i++) {
tbufWriteInt32( &bw, i ); tbufWriteInt32( &bw, i );
} }
// write the integer count to buffer at reserved position // write the integer count to buffer at reserved position
...@@ -55,7 +55,7 @@ int main( int argc, char** argv ) { ...@@ -55,7 +55,7 @@ int main( int argc, char** argv ) {
SBufferReader br = tbufInitReader( data, size, false ); SBufferReader br = tbufInitReader( data, size, false );
// read & print out all integers // read & print out all integers
int32_t count = tbufReadInt32( &br ); int32_t count = tbufReadInt32( &br );
for( int i = 0; i < count; i++ ) { for( int32_t i = 0; i < count; i++ ) {
printf( "%d\n", tbufReadInt32(&br) ); printf( "%d\n", tbufReadInt32(&br) );
} }
// read & print out a string // read & print out a string
...@@ -87,12 +87,10 @@ typedef struct SBufferWriter { ...@@ -87,12 +87,10 @@ typedef struct SBufferWriter {
void* (*allocator)(void*, size_t); void* (*allocator)(void*, size_t);
} SBufferWriter; } SBufferWriter;
////////////////////////////////////////////////////////////////////////////////
// common functions & macros for both reader & writer // common functions & macros for both reader & writer
#define tbufTell(buf) ((buf)->pos) #define tbufTell(buf) ((buf)->pos)
////////////////////////////////////////////////////////////////////////////////
/* ------------------------ BUFFER WRITER FUNCTIONS AND MACROS ------------------------ */ /* ------------------------ BUFFER WRITER FUNCTIONS AND MACROS ------------------------ */
// *Allocator*, function to allocate memory, will use 'realloc' if NULL // *Allocator*, function to allocate memory, will use 'realloc' if NULL
// *Endian*, if true, writer functions of primitive types will do 'hton' automatically // *Endian*, if true, writer functions of primitive types will do 'hton' automatically
...@@ -167,4 +165,4 @@ double tbufReadDouble(SBufferReader* buf); ...@@ -167,4 +165,4 @@ double tbufReadDouble(SBufferReader* buf);
} }
#endif #endif
#endif /*_TD_UTIL_BUFFER_H*/ #endif /*_TD_UTIL_BUFFER_H_*/
...@@ -13,27 +13,25 @@ ...@@ -13,27 +13,25 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#ifndef _TD_UTIL_CACHE_H #ifndef _TD_UTIL_CACHE_H_
#define _TD_UTIL_CACHE_H #define _TD_UTIL_CACHE_H_
#include "thash.h"
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C" {
#endif #endif
#include "os.h"
#include "tlockfree.h"
#include "thash.h"
#if defined(_TD_ARM_32) #if defined(_TD_ARM_32)
#define TSDB_CACHE_PTR_KEY TSDB_DATA_TYPE_INT #define TSDB_CACHE_PTR_KEY TSDB_DATA_TYPE_INT
#define TSDB_CACHE_PTR_TYPE int32_t #define TSDB_CACHE_PTR_TYPE int32_t
#else #else
#define TSDB_CACHE_PTR_KEY TSDB_DATA_TYPE_BIGINT #define TSDB_CACHE_PTR_KEY TSDB_DATA_TYPE_BIGINT
#define TSDB_CACHE_PTR_TYPE int64_t #define TSDB_CACHE_PTR_TYPE int64_t
#endif #endif
typedef void (*__cache_free_fn_t)(void*); typedef void (*__cache_free_fn_t)(void *);
typedef void (*__cache_trav_fn_t)(void*, void*); typedef void (*__cache_trav_fn_t)(void *, void *);
typedef struct SCacheStatis { typedef struct SCacheStatis {
int64_t missCount; int64_t missCount;
...@@ -50,8 +48,8 @@ typedef struct SCacheDataNode { ...@@ -50,8 +48,8 @@ typedef struct SCacheDataNode {
uint64_t expireTime; // expire time uint64_t expireTime; // expire time
uint64_t signature; uint64_t signature;
struct STrashElem *pTNodeHeader; // point to trash node head struct STrashElem *pTNodeHeader; // point to trash node head
uint16_t keySize: 15; // max key size: 32kb uint16_t keySize : 15; // max key size: 32kb
bool inTrashcan: 1;// denote if it is in trash or not bool inTrashcan : 1; // denote if it is in trash or not
uint32_t size; // allocated size for current SCacheDataNode uint32_t size; // allocated size for current SCacheDataNode
T_REF_DECLARE() T_REF_DECLARE()
char *key; char *key;
...@@ -75,10 +73,10 @@ typedef struct STrashElem { ...@@ -75,10 +73,10 @@ typedef struct STrashElem {
typedef struct { typedef struct {
int64_t totalSize; // total allocated buffer in this hash table, SCacheObj is not included. int64_t totalSize; // total allocated buffer in this hash table, SCacheObj is not included.
int64_t refreshTime; int64_t refreshTime;
STrashElem * pTrash; STrashElem *pTrash;
char* name; char *name;
SCacheStatis statistics; SCacheStatis statistics;
SHashObj * pHashTable; SHashObj *pHashTable;
__cache_free_fn_t freeFp; __cache_free_fn_t freeFp;
uint32_t numOfElemsInTrash; // number of element in trash uint32_t numOfElemsInTrash; // number of element in trash
uint8_t deleting; // set the deleting flag to stop refreshing ASAP. uint8_t deleting; // set the deleting flag to stop refreshing ASAP.
...@@ -101,7 +99,8 @@ typedef struct { ...@@ -101,7 +99,8 @@ typedef struct {
* @param fn free resource callback function * @param fn free resource callback function
* @return * @return
*/ */
SCacheObj *taosCacheInit(int32_t keyType, int64_t refreshTimeInSeconds, bool extendLifespan, __cache_free_fn_t fn, const char *cacheName); SCacheObj *taosCacheInit(int32_t keyType, int64_t refreshTimeInSeconds, bool extendLifespan, __cache_free_fn_t fn,
const char *cacheName);
/** /**
* add data into cache * add data into cache
...@@ -113,7 +112,8 @@ SCacheObj *taosCacheInit(int32_t keyType, int64_t refreshTimeInSeconds, bool ext ...@@ -113,7 +112,8 @@ SCacheObj *taosCacheInit(int32_t keyType, int64_t refreshTimeInSeconds, bool ext
* @param keepTime survival time in second * @param keepTime survival time in second
* @return cached element * @return cached element
*/ */
void *taosCachePut(SCacheObj *pCacheObj, const void *key, size_t keyLen, const void *pData, size_t dataSize, int durationMS); void *taosCachePut(SCacheObj *pCacheObj, const void *key, size_t keyLen, const void *pData, size_t dataSize,
int32_t durationMS);
/** /**
* get data from cache * get data from cache
...@@ -177,7 +177,7 @@ void taosCacheCleanup(SCacheObj *pCacheObj); ...@@ -177,7 +177,7 @@ void taosCacheCleanup(SCacheObj *pCacheObj);
* @param fp * @param fp
* @return * @return
*/ */
void taosCacheRefresh(SCacheObj *pCacheObj, __cache_trav_fn_t fp, void* param1); void taosCacheRefresh(SCacheObj *pCacheObj, __cache_trav_fn_t fp, void *param1);
/** /**
* stop background refresh worker thread * stop background refresh worker thread
...@@ -188,4 +188,4 @@ void taosStopCacheRefreshWorker(); ...@@ -188,4 +188,4 @@ void taosStopCacheRefreshWorker();
} }
#endif #endif
#endif /*_TD_UTIL_CACHE_H*/ #endif /*_TD_UTIL_CACHE_H_*/
...@@ -13,24 +13,22 @@ ...@@ -13,24 +13,22 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#ifndef _TD_UTIL_CHECKSUM_H #ifndef _TD_UTIL_CHECKSUM_H_
#define _TD_UTIL_CHECKSUM_H #define _TD_UTIL_CHECKSUM_H_
#include "tcrc32c.h"
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C" {
#endif #endif
#include "os.h"
#include "tcrc32c.h"
#include "tutil.h"
typedef uint32_t TSCKSUM; typedef uint32_t TSCKSUM;
static FORCE_INLINE TSCKSUM taosCalcChecksum(TSCKSUM csi, const uint8_t *stream, uint32_t ssize) { static FORCE_INLINE TSCKSUM taosCalcChecksum(TSCKSUM csi, const uint8_t *stream, uint32_t ssize) {
return (*crc32c)(csi, stream, (size_t)ssize); return (*crc32c)(csi, stream, (size_t)ssize);
} }
static FORCE_INLINE int taosCalcChecksumAppend(TSCKSUM csi, uint8_t *stream, uint32_t ssize) { static FORCE_INLINE int32_t taosCalcChecksumAppend(TSCKSUM csi, uint8_t *stream, uint32_t ssize) {
if (ssize < sizeof(TSCKSUM)) return -1; if (ssize < sizeof(TSCKSUM)) return -1;
*((TSCKSUM *)(stream + ssize - sizeof(TSCKSUM))) = (*crc32c)(csi, stream, (size_t)(ssize - sizeof(TSCKSUM))); *((TSCKSUM *)(stream + ssize - sizeof(TSCKSUM))) = (*crc32c)(csi, stream, (size_t)(ssize - sizeof(TSCKSUM)));
...@@ -38,11 +36,11 @@ static FORCE_INLINE int taosCalcChecksumAppend(TSCKSUM csi, uint8_t *stream, uin ...@@ -38,11 +36,11 @@ static FORCE_INLINE int taosCalcChecksumAppend(TSCKSUM csi, uint8_t *stream, uin
return 0; return 0;
} }
static FORCE_INLINE int taosCheckChecksum(const uint8_t *stream, uint32_t ssize, TSCKSUM checksum) { static FORCE_INLINE int32_t taosCheckChecksum(const uint8_t *stream, uint32_t ssize, TSCKSUM checksum) {
return (checksum != (*crc32c)(0, stream, (size_t)ssize)); return (checksum != (*crc32c)(0, stream, (size_t)ssize));
} }
static FORCE_INLINE int taosCheckChecksumWhole(const uint8_t *stream, uint32_t ssize) { static FORCE_INLINE int32_t taosCheckChecksumWhole(const uint8_t *stream, uint32_t ssize) {
if (ssize < sizeof(TSCKSUM)) return 0; if (ssize < sizeof(TSCKSUM)) return 0;
#if (_WIN64) #if (_WIN64)
...@@ -56,4 +54,4 @@ static FORCE_INLINE int taosCheckChecksumWhole(const uint8_t *stream, uint32_t s ...@@ -56,4 +54,4 @@ static FORCE_INLINE int taosCheckChecksumWhole(const uint8_t *stream, uint32_t s
} }
#endif #endif
#endif /*_TD_UTIL_CHECKSUM_H*/ #endif /*_TD_UTIL_CHECKSUM_H_*/
...@@ -12,15 +12,16 @@ ...@@ -12,15 +12,16 @@
* You should have received a copy of the GNU Affero General Public License * 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/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#ifndef _TD_UTIL_CODING_H
#define _TD_UTIL_CODING_H #ifndef _TD_UTIL_CODING_H_
#define _TD_UTIL_CODING_H_
#include "os.h"
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C" {
#endif #endif
#include "os.h"
#define ENCODE_LIMIT (((uint8_t)1) << 7) #define ENCODE_LIMIT (((uint8_t)1) << 7)
#define ZIGZAGE(T, v) ((u##T)((v) >> (sizeof(T) * 8 - 1))) ^ (((u##T)(v)) << 1) // zigzag encode #define ZIGZAGE(T, v) ((u##T)((v) >> (sizeof(T) * 8 - 1))) ^ (((u##T)(v)) << 1) // zigzag encode
#define ZIGZAGD(T, v) ((v) >> 1) ^ -((T)((v)&1)) // zigzag decode #define ZIGZAGD(T, v) ((v) >> 1) ^ -((T)((v)&1)) // zigzag decode
...@@ -28,13 +29,13 @@ extern "C" { ...@@ -28,13 +29,13 @@ extern "C" {
/* ------------------------ LEGACY CODES ------------------------ */ /* ------------------------ LEGACY CODES ------------------------ */
#if 1 #if 1
// ---- Fixed U8 // ---- Fixed U8
static FORCE_INLINE int taosEncodeFixedU8(void **buf, uint8_t value) { static FORCE_INLINE int32_t taosEncodeFixedU8(void **buf, uint8_t value) {
if (buf != NULL) { if (buf != NULL) {
((uint8_t *)(*buf))[0] = value; ((uint8_t *)(*buf))[0] = value;
*buf = POINTER_SHIFT(*buf, sizeof(value)); *buf = POINTER_SHIFT(*buf, sizeof(value));
} }
return (int)sizeof(value); return (int32_t)sizeof(value);
} }
static FORCE_INLINE void *taosDecodeFixedU8(const void *buf, uint8_t *value) { static FORCE_INLINE void *taosDecodeFixedU8(const void *buf, uint8_t *value) {
...@@ -43,12 +44,12 @@ static FORCE_INLINE void *taosDecodeFixedU8(const void *buf, uint8_t *value) { ...@@ -43,12 +44,12 @@ static FORCE_INLINE void *taosDecodeFixedU8(const void *buf, uint8_t *value) {
} }
// ---- Fixed I8 // ---- Fixed I8
static FORCE_INLINE int taosEncodeFixedI8(void **buf, int8_t value) { static FORCE_INLINE int32_t taosEncodeFixedI8(void **buf, int8_t value) {
if (buf != NULL) { if (buf != NULL) {
((int8_t *)(*buf))[0] = value; ((int8_t *)(*buf))[0] = value;
*buf = POINTER_SHIFT(*buf, sizeof(value)); *buf = POINTER_SHIFT(*buf, sizeof(value));
} }
return (int)sizeof(value); return (int32_t)sizeof(value);
} }
static FORCE_INLINE void *taosDecodeFixedI8(const void *buf, int8_t *value) { static FORCE_INLINE void *taosDecodeFixedI8(const void *buf, int8_t *value) {
...@@ -57,7 +58,7 @@ static FORCE_INLINE void *taosDecodeFixedI8(const void *buf, int8_t *value) { ...@@ -57,7 +58,7 @@ static FORCE_INLINE void *taosDecodeFixedI8(const void *buf, int8_t *value) {
} }
// ---- Fixed U16 // ---- Fixed U16
static FORCE_INLINE int taosEncodeFixedU16(void **buf, uint16_t value) { static FORCE_INLINE int32_t taosEncodeFixedU16(void **buf, uint16_t value) {
if (buf != NULL) { if (buf != NULL) {
if (IS_LITTLE_ENDIAN()) { if (IS_LITTLE_ENDIAN()) {
memcpy(*buf, &value, sizeof(value)); memcpy(*buf, &value, sizeof(value));
...@@ -68,7 +69,7 @@ static FORCE_INLINE int taosEncodeFixedU16(void **buf, uint16_t value) { ...@@ -68,7 +69,7 @@ static FORCE_INLINE int taosEncodeFixedU16(void **buf, uint16_t value) {
*buf = POINTER_SHIFT(*buf, sizeof(value)); *buf = POINTER_SHIFT(*buf, sizeof(value));
} }
return (int)sizeof(value); return (int32_t)sizeof(value);
} }
static FORCE_INLINE void *taosDecodeFixedU16(const void *buf, uint16_t *value) { static FORCE_INLINE void *taosDecodeFixedU16(const void *buf, uint16_t *value) {
...@@ -83,7 +84,7 @@ static FORCE_INLINE void *taosDecodeFixedU16(const void *buf, uint16_t *value) { ...@@ -83,7 +84,7 @@ static FORCE_INLINE void *taosDecodeFixedU16(const void *buf, uint16_t *value) {
} }
// ---- Fixed I16 // ---- Fixed I16
static FORCE_INLINE int taosEncodeFixedI16(void **buf, int16_t value) { static FORCE_INLINE int32_t taosEncodeFixedI16(void **buf, int16_t value) {
return taosEncodeFixedU16(buf, ZIGZAGE(int16_t, value)); return taosEncodeFixedU16(buf, ZIGZAGE(int16_t, value));
} }
...@@ -95,7 +96,7 @@ static FORCE_INLINE void *taosDecodeFixedI16(const void *buf, int16_t *value) { ...@@ -95,7 +96,7 @@ static FORCE_INLINE void *taosDecodeFixedI16(const void *buf, int16_t *value) {
} }
// ---- Fixed U32 // ---- Fixed U32
static FORCE_INLINE int taosEncodeFixedU32(void **buf, uint32_t value) { static FORCE_INLINE int32_t taosEncodeFixedU32(void **buf, uint32_t value) {
if (buf != NULL) { if (buf != NULL) {
if (IS_LITTLE_ENDIAN()) { if (IS_LITTLE_ENDIAN()) {
memcpy(*buf, &value, sizeof(value)); memcpy(*buf, &value, sizeof(value));
...@@ -108,7 +109,7 @@ static FORCE_INLINE int taosEncodeFixedU32(void **buf, uint32_t value) { ...@@ -108,7 +109,7 @@ static FORCE_INLINE int taosEncodeFixedU32(void **buf, uint32_t value) {
*buf = POINTER_SHIFT(*buf, sizeof(value)); *buf = POINTER_SHIFT(*buf, sizeof(value));
} }
return (int)sizeof(value); return (int32_t)sizeof(value);
} }
static FORCE_INLINE void *taosDecodeFixedU32(const void *buf, uint32_t *value) { static FORCE_INLINE void *taosDecodeFixedU32(const void *buf, uint32_t *value) {
...@@ -125,7 +126,7 @@ static FORCE_INLINE void *taosDecodeFixedU32(const void *buf, uint32_t *value) { ...@@ -125,7 +126,7 @@ static FORCE_INLINE void *taosDecodeFixedU32(const void *buf, uint32_t *value) {
} }
// ---- Fixed I32 // ---- Fixed I32
static FORCE_INLINE int taosEncodeFixedI32(void **buf, int32_t value) { static FORCE_INLINE int32_t taosEncodeFixedI32(void **buf, int32_t value) {
return taosEncodeFixedU32(buf, ZIGZAGE(int32_t, value)); return taosEncodeFixedU32(buf, ZIGZAGE(int32_t, value));
} }
...@@ -137,7 +138,7 @@ static FORCE_INLINE void *taosDecodeFixedI32(const void *buf, int32_t *value) { ...@@ -137,7 +138,7 @@ static FORCE_INLINE void *taosDecodeFixedI32(const void *buf, int32_t *value) {
} }
// ---- Fixed U64 // ---- Fixed U64
static FORCE_INLINE int taosEncodeFixedU64(void **buf, uint64_t value) { static FORCE_INLINE int32_t taosEncodeFixedU64(void **buf, uint64_t value) {
if (buf != NULL) { if (buf != NULL) {
if (IS_LITTLE_ENDIAN()) { if (IS_LITTLE_ENDIAN()) {
memcpy(*buf, &value, sizeof(value)); memcpy(*buf, &value, sizeof(value));
...@@ -155,7 +156,7 @@ static FORCE_INLINE int taosEncodeFixedU64(void **buf, uint64_t value) { ...@@ -155,7 +156,7 @@ static FORCE_INLINE int taosEncodeFixedU64(void **buf, uint64_t value) {
*buf = POINTER_SHIFT(*buf, sizeof(value)); *buf = POINTER_SHIFT(*buf, sizeof(value));
} }
return (int)sizeof(value); return (int32_t)sizeof(value);
} }
static FORCE_INLINE void *taosDecodeFixedU64(const void *buf, uint64_t *value) { static FORCE_INLINE void *taosDecodeFixedU64(const void *buf, uint64_t *value) {
...@@ -176,7 +177,7 @@ static FORCE_INLINE void *taosDecodeFixedU64(const void *buf, uint64_t *value) { ...@@ -176,7 +177,7 @@ static FORCE_INLINE void *taosDecodeFixedU64(const void *buf, uint64_t *value) {
} }
// ---- Fixed I64 // ---- Fixed I64
static FORCE_INLINE int taosEncodeFixedI64(void **buf, int64_t value) { static FORCE_INLINE int32_t taosEncodeFixedI64(void **buf, int64_t value) {
return taosEncodeFixedU64(buf, ZIGZAGE(int64_t, value)); return taosEncodeFixedU64(buf, ZIGZAGE(int64_t, value));
} }
...@@ -188,8 +189,8 @@ static FORCE_INLINE void *taosDecodeFixedI64(const void *buf, int64_t *value) { ...@@ -188,8 +189,8 @@ static FORCE_INLINE void *taosDecodeFixedI64(const void *buf, int64_t *value) {
} }
// ---- Variant U16 // ---- Variant U16
static FORCE_INLINE int taosEncodeVariantU16(void **buf, uint16_t value) { static FORCE_INLINE int32_t taosEncodeVariantU16(void **buf, uint16_t value) {
int i = 0; int32_t i = 0;
while (value >= ENCODE_LIMIT) { while (value >= ENCODE_LIMIT) {
if (buf != NULL) ((uint8_t *)(*buf))[i] = (uint8_t)(value | ENCODE_LIMIT); if (buf != NULL) ((uint8_t *)(*buf))[i] = (uint8_t)(value | ENCODE_LIMIT);
value >>= 7; value >>= 7;
...@@ -206,7 +207,7 @@ static FORCE_INLINE int taosEncodeVariantU16(void **buf, uint16_t value) { ...@@ -206,7 +207,7 @@ static FORCE_INLINE int taosEncodeVariantU16(void **buf, uint16_t value) {
} }
static FORCE_INLINE void *taosDecodeVariantU16(const void *buf, uint16_t *value) { static FORCE_INLINE void *taosDecodeVariantU16(const void *buf, uint16_t *value) {
int i = 0; int32_t i = 0;
uint16_t tval = 0; uint16_t tval = 0;
*value = 0; *value = 0;
while (i < 3) { while (i < 3) {
...@@ -224,7 +225,7 @@ static FORCE_INLINE void *taosDecodeVariantU16(const void *buf, uint16_t *value) ...@@ -224,7 +225,7 @@ static FORCE_INLINE void *taosDecodeVariantU16(const void *buf, uint16_t *value)
} }
// ---- Variant I16 // ---- Variant I16
static FORCE_INLINE int taosEncodeVariantI16(void **buf, int16_t value) { static FORCE_INLINE int32_t taosEncodeVariantI16(void **buf, int16_t value) {
return taosEncodeVariantU16(buf, ZIGZAGE(int16_t, value)); return taosEncodeVariantU16(buf, ZIGZAGE(int16_t, value));
} }
...@@ -236,8 +237,8 @@ static FORCE_INLINE void *taosDecodeVariantI16(const void *buf, int16_t *value) ...@@ -236,8 +237,8 @@ static FORCE_INLINE void *taosDecodeVariantI16(const void *buf, int16_t *value)
} }
// ---- Variant U32 // ---- Variant U32
static FORCE_INLINE int taosEncodeVariantU32(void **buf, uint32_t value) { static FORCE_INLINE int32_t taosEncodeVariantU32(void **buf, uint32_t value) {
int i = 0; int32_t i = 0;
while (value >= ENCODE_LIMIT) { while (value >= ENCODE_LIMIT) {
if (buf != NULL) ((uint8_t *)(*buf))[i] = (value | ENCODE_LIMIT); if (buf != NULL) ((uint8_t *)(*buf))[i] = (value | ENCODE_LIMIT);
value >>= 7; value >>= 7;
...@@ -254,7 +255,7 @@ static FORCE_INLINE int taosEncodeVariantU32(void **buf, uint32_t value) { ...@@ -254,7 +255,7 @@ static FORCE_INLINE int taosEncodeVariantU32(void **buf, uint32_t value) {
} }
static FORCE_INLINE void *taosDecodeVariantU32(const void *buf, uint32_t *value) { static FORCE_INLINE void *taosDecodeVariantU32(const void *buf, uint32_t *value) {
int i = 0; int32_t i = 0;
uint32_t tval = 0; uint32_t tval = 0;
*value = 0; *value = 0;
while (i < 5) { while (i < 5) {
...@@ -272,7 +273,7 @@ static FORCE_INLINE void *taosDecodeVariantU32(const void *buf, uint32_t *value) ...@@ -272,7 +273,7 @@ static FORCE_INLINE void *taosDecodeVariantU32(const void *buf, uint32_t *value)
} }
// ---- Variant I32 // ---- Variant I32
static FORCE_INLINE int taosEncodeVariantI32(void **buf, int32_t value) { static FORCE_INLINE int32_t taosEncodeVariantI32(void **buf, int32_t value) {
return taosEncodeVariantU32(buf, ZIGZAGE(int32_t, value)); return taosEncodeVariantU32(buf, ZIGZAGE(int32_t, value));
} }
...@@ -284,8 +285,8 @@ static FORCE_INLINE void *taosDecodeVariantI32(const void *buf, int32_t *value) ...@@ -284,8 +285,8 @@ static FORCE_INLINE void *taosDecodeVariantI32(const void *buf, int32_t *value)
} }
// ---- Variant U64 // ---- Variant U64
static FORCE_INLINE int taosEncodeVariantU64(void **buf, uint64_t value) { static FORCE_INLINE int32_t taosEncodeVariantU64(void **buf, uint64_t value) {
int i = 0; int32_t i = 0;
while (value >= ENCODE_LIMIT) { while (value >= ENCODE_LIMIT) {
if (buf != NULL) ((uint8_t *)(*buf))[i] = (uint8_t)(value | ENCODE_LIMIT); if (buf != NULL) ((uint8_t *)(*buf))[i] = (uint8_t)(value | ENCODE_LIMIT);
value >>= 7; value >>= 7;
...@@ -302,7 +303,7 @@ static FORCE_INLINE int taosEncodeVariantU64(void **buf, uint64_t value) { ...@@ -302,7 +303,7 @@ static FORCE_INLINE int taosEncodeVariantU64(void **buf, uint64_t value) {
} }
static FORCE_INLINE void *taosDecodeVariantU64(const void *buf, uint64_t *value) { static FORCE_INLINE void *taosDecodeVariantU64(const void *buf, uint64_t *value) {
int i = 0; int32_t i = 0;
uint64_t tval = 0; uint64_t tval = 0;
*value = 0; *value = 0;
while (i < 10) { while (i < 10) {
...@@ -320,7 +321,7 @@ static FORCE_INLINE void *taosDecodeVariantU64(const void *buf, uint64_t *value) ...@@ -320,7 +321,7 @@ static FORCE_INLINE void *taosDecodeVariantU64(const void *buf, uint64_t *value)
} }
// ---- Variant I64 // ---- Variant I64
static FORCE_INLINE int taosEncodeVariantI64(void **buf, int64_t value) { static FORCE_INLINE int32_t taosEncodeVariantI64(void **buf, int64_t value) {
return taosEncodeVariantU64(buf, ZIGZAGE(int64_t, value)); return taosEncodeVariantU64(buf, ZIGZAGE(int64_t, value));
} }
...@@ -332,8 +333,8 @@ static FORCE_INLINE void *taosDecodeVariantI64(const void *buf, int64_t *value) ...@@ -332,8 +333,8 @@ static FORCE_INLINE void *taosDecodeVariantI64(const void *buf, int64_t *value)
} }
// ---- string // ---- string
static FORCE_INLINE int taosEncodeString(void **buf, const char *value) { static FORCE_INLINE int32_t taosEncodeString(void **buf, const char *value) {
int tlen = 0; int32_t tlen = 0;
size_t size = strlen(value); size_t size = strlen(value);
tlen += taosEncodeVariantU64(buf, size); tlen += taosEncodeVariantU64(buf, size);
...@@ -341,7 +342,7 @@ static FORCE_INLINE int taosEncodeString(void **buf, const char *value) { ...@@ -341,7 +342,7 @@ static FORCE_INLINE int taosEncodeString(void **buf, const char *value) {
memcpy(*buf, value, size); memcpy(*buf, value, size);
*buf = POINTER_SHIFT(*buf, size); *buf = POINTER_SHIFT(*buf, size);
} }
tlen += (int)size; tlen += (int32_t)size;
return tlen; return tlen;
} }
...@@ -372,14 +373,14 @@ static FORCE_INLINE void *taosDecodeStringTo(const void *buf, char *value) { ...@@ -372,14 +373,14 @@ static FORCE_INLINE void *taosDecodeStringTo(const void *buf, char *value) {
} }
// ---- binary // ---- binary
static FORCE_INLINE int taosEncodeBinary(void **buf, const void *value, int32_t valueLen) { static FORCE_INLINE int32_t taosEncodeBinary(void **buf, const void *value, int32_t valueLen) {
int tlen = 0; int32_t tlen = 0;
if (buf != NULL) { if (buf != NULL) {
memcpy(*buf, value, valueLen); memcpy(*buf, value, valueLen);
*buf = POINTER_SHIFT(*buf, valueLen); *buf = POINTER_SHIFT(*buf, valueLen);
} }
tlen += (int)valueLen; tlen += (int32_t)valueLen;
return tlen; return tlen;
} }
...@@ -403,4 +404,4 @@ static FORCE_INLINE void *taosDecodeBinaryTo(const void *buf, void *value, int32 ...@@ -403,4 +404,4 @@ static FORCE_INLINE void *taosDecodeBinaryTo(const void *buf, void *value, int32
} }
#endif #endif
#endif /*_TD_UTIL_CODING_H*/ #endif /*_TD_UTIL_CODING_H_*/
...@@ -16,12 +16,13 @@ ...@@ -16,12 +16,13 @@
#ifndef _TD_UTIL_COMPARE_H_ #ifndef _TD_UTIL_COMPARE_H_
#define _TD_UTIL_COMPARE_H_ #define _TD_UTIL_COMPARE_H_
#include "os.h"
#include "taos.h"
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C" {
#endif #endif
#include "os.h"
#define TSDB_PATTERN_MATCH 0 #define TSDB_PATTERN_MATCH 0
#define TSDB_PATTERN_NOMATCH 1 #define TSDB_PATTERN_NOMATCH 1
#define TSDB_PATTERN_NOWILDCARDMATCH 2 #define TSDB_PATTERN_NOWILDCARDMATCH 2
...@@ -62,7 +63,6 @@ int32_t setChkNotInBytes8(const void *pLeft, const void *pRight); ...@@ -62,7 +63,6 @@ int32_t setChkNotInBytes8(const void *pLeft, const void *pRight);
int32_t compareChkInString(const void *pLeft, const void *pRight); int32_t compareChkInString(const void *pLeft, const void *pRight);
int32_t compareChkNotInString(const void *pLeft, const void *pRight); int32_t compareChkNotInString(const void *pLeft, const void *pRight);
int32_t compareInt8Val(const void *pLeft, const void *pRight); int32_t compareInt8Val(const void *pLeft, const void *pRight);
int32_t compareInt16Val(const void *pLeft, const void *pRight); int32_t compareInt16Val(const void *pLeft, const void *pRight);
int32_t compareInt32Val(const void *pLeft, const void *pRight); int32_t compareInt32Val(const void *pLeft, const void *pRight);
...@@ -83,7 +83,6 @@ int32_t compareStrRegexComp(const void *pLeft, const void *pRight); ...@@ -83,7 +83,6 @@ int32_t compareStrRegexComp(const void *pLeft, const void *pRight);
int32_t compareStrRegexCompMatch(const void *pLeft, const void *pRight); int32_t compareStrRegexCompMatch(const void *pLeft, const void *pRight);
int32_t compareStrRegexCompNMatch(const void *pLeft, const void *pRight); int32_t compareStrRegexCompNMatch(const void *pLeft, const void *pRight);
int32_t compareInt8ValDesc(const void *pLeft, const void *pRight); int32_t compareInt8ValDesc(const void *pLeft, const void *pRight);
int32_t compareInt16ValDesc(const void *pLeft, const void *pRight); int32_t compareInt16ValDesc(const void *pLeft, const void *pRight);
int32_t compareInt32ValDesc(const void *pLeft, const void *pRight); int32_t compareInt32ValDesc(const void *pLeft, const void *pRight);
...@@ -100,8 +99,15 @@ int32_t compareUint64ValDesc(const void *pLeft, const void *pRight); ...@@ -100,8 +99,15 @@ int32_t compareUint64ValDesc(const void *pLeft, const void *pRight);
int32_t compareLenPrefixedStrDesc(const void *pLeft, const void *pRight); int32_t compareLenPrefixedStrDesc(const void *pLeft, const void *pRight);
int32_t compareLenPrefixedWStrDesc(const void *pLeft, const void *pRight); int32_t compareLenPrefixedWStrDesc(const void *pLeft, const void *pRight);
__compar_fn_t getComparFunc(int32_t type, int32_t optr); int32_t compareStrPatternMatch(const void *pLeft, const void *pRight);
int32_t compareStrPatternNotMatch(const void *pLeft, const void *pRight);
int32_t compareWStrPatternMatch(const void *pLeft, const void *pRight);
int32_t compareWStrPatternNotMatch(const void *pLeft, const void *pRight);
__compar_fn_t getComparFunc(int32_t type, int32_t optr);
__compar_fn_t getKeyComparFunc(int32_t keyType, int32_t order);
int32_t doCompare(const char *a, const char *b, int32_t type, size_t size);
#ifdef __cplusplus #ifdef __cplusplus
} }
......
此差异已折叠。
/* /*
* Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com> * Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com>
* *
...@@ -13,85 +14,98 @@ ...@@ -13,85 +14,98 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#ifndef _TD_UTIL_CONFIG_H #ifndef _TD_CONFIG_H_
#define _TD_UTIL_CONFIG_H #define _TD_CONFIG_H_
#include "tarray.h"
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C" {
#endif #endif
#define TSDB_CFG_MAX_NUM 115 #define CFG_NAME_MAX_LEN 128
#define TSDB_CFG_PRINT_LEN 23
#define TSDB_CFG_OPTION_LEN 24 typedef enum {
#define TSDB_CFG_VALUE_LEN 41 CFG_STYPE_DEFAULT,
CFG_STYPE_CFG_FILE,
#define TSDB_CFG_CTYPE_B_CONFIG 1U // can be configured from file CFG_STYPE_ENV_FILE,
#define TSDB_CFG_CTYPE_B_SHOW 2U // can displayed by "show configs" commands CFG_STYPE_ENV_VAR,
#define TSDB_CFG_CTYPE_B_LOG 4U // is a log type configuration CFG_STYPE_APOLLO_URL,
#define TSDB_CFG_CTYPE_B_CLIENT 8U // can be displayed in the client log CFG_STYPE_ARG_LIST,
#define TSDB_CFG_CTYPE_B_OPTION 16U // can be configured by taos_options function } ECfgSrcType;
#define TSDB_CFG_CTYPE_B_NOT_PRINT 32U // such as password
typedef enum {
#define MAX_FLOAT 100000 CFG_DTYPE_NONE,
#define MIN_FLOAT 0 CFG_DTYPE_BOOL,
CFG_DTYPE_INT32,
enum { CFG_DTYPE_INT64,
TAOS_CFG_CSTATUS_NONE, // not configured CFG_DTYPE_FLOAT,
TAOS_CFG_CSTATUS_DEFAULT, // use system default value CFG_DTYPE_STRING,
TAOS_CFG_CSTATUS_FILE, // configured from file CFG_DTYPE_DIR,
TAOS_CFG_CSTATUS_OPTION, // configured by taos_options function CFG_DTYPE_LOCALE,
TAOS_CFG_CSTATUS_ARG, // configured by program argument CFG_DTYPE_CHARSET,
}; CFG_DTYPE_TIMEZONE
} ECfgDataType;
enum {
TAOS_CFG_VTYPE_INT8, typedef struct SConfigItem {
TAOS_CFG_VTYPE_INT16, ECfgSrcType stype;
TAOS_CFG_VTYPE_INT32, ECfgDataType dtype;
TAOS_CFG_VTYPE_UINT16, bool tsc;
TAOS_CFG_VTYPE_FLOAT, char *name;
TAOS_CFG_VTYPE_STRING, union {
TAOS_CFG_VTYPE_IPSTR, bool bval;
TAOS_CFG_VTYPE_DIRECTORY, float fval;
TAOS_CFG_VTYPE_DATA_DIRCTORY, int32_t i32;
TAOS_CFG_VTYPE_DOUBLE, int64_t i64;
}; char *str;
};
enum { union {
TAOS_CFG_UTYPE_NONE, int64_t imin;
TAOS_CFG_UTYPE_PERCENT, double fmin;
TAOS_CFG_UTYPE_GB, };
TAOS_CFG_UTYPE_MB, union {
TAOS_CFG_UTYPE_BYTE, int64_t imax;
TAOS_CFG_UTYPE_SECOND, double fmax;
TAOS_CFG_UTYPE_MS };
}; SArray *array; // SDiskCfg
} SConfigItem;
typedef struct { typedef struct {
char * option; const char *name;
void * ptr; const char *value;
float minValue; } SConfigPair;
float maxValue;
int8_t cfgType; typedef struct SConfig {
int8_t cfgStatus; ECfgSrcType stype;
int8_t unitType; SArray *array;
int8_t valType; } SConfig;
int32_t ptrLength;
} SGlobalCfg; SConfig *cfgInit();
int32_t cfgLoad(SConfig *pCfg, ECfgSrcType cfgType, const char *sourceStr);
extern SGlobalCfg tsGlobalConfig[]; int32_t cfgLoadArray(SConfig *pCfg, SArray *pArgs); // SConfigPair
extern int32_t tsGlobalConfigNum; void cfgCleanup(SConfig *pCfg);
extern char * tsCfgStatusStr[];
int32_t cfgGetSize(SConfig *pCfg);
void taosReadGlobalLogCfg(); SConfigItem *cfgGetItem(SConfig *pCfg, const char *name);
int32_t taosReadCfgFromFile(); int32_t cfgSetItem(SConfig *pCfg, const char *name, const char *value, ECfgSrcType stype);
void taosPrintCfg();
void taosDumpGlobalCfg(); int32_t cfgAddBool(SConfig *pCfg, const char *name, bool defaultVal, bool tsc);
int32_t cfgAddInt32(SConfig *pCfg, const char *name, int32_t defaultVal, int64_t minval, int64_t maxval, bool tsc);
void taosAddConfigOption(SGlobalCfg cfg); int32_t cfgAddInt64(SConfig *pCfg, const char *name, int64_t defaultVal, int64_t minval, int64_t maxval, bool tsc);
SGlobalCfg *taosGetConfigOption(const char *option); int32_t cfgAddFloat(SConfig *pCfg, const char *name, float defaultVal, double minval, double maxval, bool tsc);
int32_t cfgAddString(SConfig *pCfg, const char *name, const char *defaultVal, bool tsc);
int32_t cfgAddDir(SConfig *pCfg, const char *name, const char *defaultVal, bool tsc);
int32_t cfgAddLocale(SConfig *pCfg, const char *name, const char *defaultVal);
int32_t cfgAddCharset(SConfig *pCfg, const char *name, const char *defaultVal);
int32_t cfgAddTimezone(SConfig *pCfg, const char *name, const char *defaultVal);
const char *cfgStypeStr(ECfgSrcType type);
const char *cfgDtypeStr(ECfgDataType type);
void cfgDumpCfg(SConfig *pCfg, bool tsc, bool dump);
#ifdef __cplusplus #ifdef __cplusplus
} }
#endif #endif
#endif /*_TD_UTIL_CONFIG_H*/ #endif /*_TD_CONFIG_H_*/
...@@ -18,8 +18,10 @@ ...@@ -18,8 +18,10 @@
3. This notice may not be removed or altered from any source distribution. 3. This notice may not be removed or altered from any source distribution.
*/ */
#ifndef _TD_UTIL_CRC32_H #ifndef _TD_UTIL_CRC32_H_
#define _TD_UTIL_CRC32_H #define _TD_UTIL_CRC32_H_
#include "os.h"
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C" {
...@@ -39,4 +41,4 @@ void taosResolveCRC(); ...@@ -39,4 +41,4 @@ void taosResolveCRC();
} }
#endif #endif
#endif /*_TD_UTIL_CRC32_H*/ #endif /*_TD_UTIL_CRC32_H_*/
...@@ -13,10 +13,8 @@ ...@@ -13,10 +13,8 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
// clang-format off #ifndef _TD_UTIL_DEF_H_
#define _TD_UTIL_DEF_H_
#ifndef _TD_UTIL_DEF_H
#define _TD_UTIL_DEF_H
#include "os.h" #include "os.h"
...@@ -96,19 +94,36 @@ extern const int32_t TYPE_BYTES[15]; ...@@ -96,19 +94,36 @@ extern const int32_t TYPE_BYTES[15];
#define TSDB_TIME_PRECISION_MICRO_STR "us" #define TSDB_TIME_PRECISION_MICRO_STR "us"
#define TSDB_TIME_PRECISION_NANO_STR "ns" #define TSDB_TIME_PRECISION_NANO_STR "ns"
#define TSDB_TICK_PER_SECOND(precision) ((int64_t)((precision)==TSDB_TIME_PRECISION_MILLI ? 1e3L : ((precision)==TSDB_TIME_PRECISION_MICRO ? 1e6L : 1e9L))) #define TSDB_INFORMATION_SCHEMA_DB "information_schema"
#define TSDB_INS_TABLE_DNODES "dnodes"
#define TSDB_INS_TABLE_MNODES "mnodes"
#define TSDB_INS_TABLE_MODULES "modules"
#define TSDB_INS_TABLE_QNODES "qnodes"
#define TSDB_INS_TABLE_USER_DATABASE "user_database"
#define TSDB_INS_TABLE_USER_FUNCTIONS "user_functions"
#define TSDB_INS_TABLE_USER_INDEXES "user_indexes"
#define TSDB_INS_TABLE_USER_STABLES "user_stables"
#define TSDB_INS_TABLE_USER_STREAMS "user_streams"
#define TSDB_INS_TABLE_USER_TABLES "user_tables"
#define TSDB_INS_TABLE_USER_TABLE_DISTRIBUTED "user_table_distributed"
#define TSDB_INS_TABLE_USER_USERS "user_users"
#define TSDB_INS_TABLE_VGROUPS "vgroups"
#define TSDB_TICK_PER_SECOND(precision) \
((int64_t)((precision) == TSDB_TIME_PRECISION_MILLI ? 1e3L \
: ((precision) == TSDB_TIME_PRECISION_MICRO ? 1e6L : 1e9L)))
#define T_MEMBER_SIZE(type, member) sizeof(((type *)0)->member) #define T_MEMBER_SIZE(type, member) sizeof(((type *)0)->member)
#define T_APPEND_MEMBER(dst, ptr, type, member) \ #define T_APPEND_MEMBER(dst, ptr, type, member) \
do {\ do { \
memcpy((void *)(dst), (void *)(&((ptr)->member)), T_MEMBER_SIZE(type, member));\ memcpy((void *)(dst), (void *)(&((ptr)->member)), T_MEMBER_SIZE(type, member)); \
dst = (void *)((char *)(dst) + T_MEMBER_SIZE(type, member));\ dst = (void *)((char *)(dst) + T_MEMBER_SIZE(type, member)); \
} while(0) } while (0)
#define T_READ_MEMBER(src, type, target) \ #define T_READ_MEMBER(src, type, target) \
do { \ do { \
(target) = *(type *)(src); \ (target) = *(type *)(src); \
(src) = (void *)((char *)src + sizeof(type));\ (src) = (void *)((char *)src + sizeof(type)); \
} while(0) } while (0)
typedef enum EOperatorType { typedef enum EOperatorType {
// arithmetic operator // arithmetic operator
...@@ -149,14 +164,12 @@ typedef enum EOperatorType { ...@@ -149,14 +164,12 @@ typedef enum EOperatorType {
OP_TYPE_JSON_CONTAINS OP_TYPE_JSON_CONTAINS
} EOperatorType; } EOperatorType;
typedef enum ELogicConditionType { typedef enum ELogicConditionType {
LOGIC_COND_TYPE_AND, LOGIC_COND_TYPE_AND,
LOGIC_COND_TYPE_OR, LOGIC_COND_TYPE_OR,
LOGIC_COND_TYPE_NOT, LOGIC_COND_TYPE_NOT,
} ELogicConditionType; } ELogicConditionType;
#define FUNCTION_CEIL 4500 #define FUNCTION_CEIL 4500
#define FUNCTION_FLOOR 4501 #define FUNCTION_FLOOR 4501
#define FUNCTION_ABS 4502 #define FUNCTION_ABS 4502
...@@ -177,7 +190,7 @@ typedef enum ELogicConditionType { ...@@ -177,7 +190,7 @@ typedef enum ELogicConditionType {
#define TSDB_ACCT_ID_LEN 11 #define TSDB_ACCT_ID_LEN 11
#define TSDB_MAX_COLUMNS 4096 #define TSDB_MAX_COLUMNS 4096
#define TSDB_MIN_COLUMNS 2 //PRIMARY COLUMN(timestamp) + other columns #define TSDB_MIN_COLUMNS 2 // PRIMARY COLUMN(timestamp) + other columns
#define TSDB_NODE_NAME_LEN 64 #define TSDB_NODE_NAME_LEN 64
#define TSDB_TABLE_NAME_LEN 193 // it is a null-terminated string #define TSDB_TABLE_NAME_LEN 193 // it is a null-terminated string
...@@ -203,11 +216,11 @@ typedef enum ELogicConditionType { ...@@ -203,11 +216,11 @@ typedef enum ELogicConditionType {
#define TSDB_MAX_SAVED_SQL_LEN TSDB_MAX_COLUMNS * 64 #define TSDB_MAX_SAVED_SQL_LEN TSDB_MAX_COLUMNS * 64
#define TSDB_MAX_SQL_LEN TSDB_PAYLOAD_SIZE #define TSDB_MAX_SQL_LEN TSDB_PAYLOAD_SIZE
#define TSDB_MAX_SQL_SHOW_LEN 1024 #define TSDB_MAX_SQL_SHOW_LEN 1024
#define TSDB_MAX_ALLOWED_SQL_LEN (1*1024*1024u) // sql length should be less than 1mb #define TSDB_MAX_ALLOWED_SQL_LEN (1 * 1024 * 1024u) // sql length should be less than 1mb
#define TSDB_APP_NAME_LEN TSDB_UNI_LEN #define TSDB_APP_NAME_LEN TSDB_UNI_LEN
#define TSDB_STB_COMMENT_LEN 1024 #define TSDB_STB_COMMENT_LEN 1024
/** /**
* In some scenarios uint16_t (0~65535) is used to store the row len. * In some scenarios uint16_t (0~65535) is used to store the row len.
* - Firstly, we use 65531(65535 - 4), as the SDataRow/SKVRow contains 4 bits header. * - Firstly, we use 65531(65535 - 4), as the SDataRow/SKVRow contains 4 bits header.
* - Secondly, if all cols are VarDataT type except primary key, we need 4 bits to store the offset, thus * - Secondly, if all cols are VarDataT type except primary key, we need 4 bits to store the offset, thus
...@@ -254,7 +267,7 @@ typedef enum ELogicConditionType { ...@@ -254,7 +267,7 @@ typedef enum ELogicConditionType {
#define TSDB_DB_TYPE_DEFAULT 0 #define TSDB_DB_TYPE_DEFAULT 0
#define TSDB_DB_TYPE_TOPIC 1 #define TSDB_DB_TYPE_TOPIC 1
#define TSDB_DEFAULT_PKT_SIZE 65480 //same as RPC_MAX_UDP_SIZE #define TSDB_DEFAULT_PKT_SIZE 65480 // same as RPC_MAX_UDP_SIZE
#define TSDB_PAYLOAD_SIZE TSDB_DEFAULT_PKT_SIZE #define TSDB_PAYLOAD_SIZE TSDB_DEFAULT_PKT_SIZE
#define TSDB_DEFAULT_PAYLOAD_SIZE 5120 // default payload size, greater than PATH_MAX value #define TSDB_DEFAULT_PAYLOAD_SIZE 5120 // default payload size, greater than PATH_MAX value
...@@ -342,8 +355,8 @@ typedef enum ELogicConditionType { ...@@ -342,8 +355,8 @@ typedef enum ELogicConditionType {
#define TSDB_MAX_UNION_CLAUSE 5 #define TSDB_MAX_UNION_CLAUSE 5
#define TSDB_MAX_FIELD_LEN 16384 #define TSDB_MAX_FIELD_LEN 16384
#define TSDB_MAX_BINARY_LEN (TSDB_MAX_FIELD_LEN-TSDB_KEYSIZE) // keep 16384 #define TSDB_MAX_BINARY_LEN (TSDB_MAX_FIELD_LEN - TSDB_KEYSIZE) // keep 16384
#define TSDB_MAX_NCHAR_LEN (TSDB_MAX_FIELD_LEN-TSDB_KEYSIZE) // keep 16384 #define TSDB_MAX_NCHAR_LEN (TSDB_MAX_FIELD_LEN - TSDB_KEYSIZE) // keep 16384
#define PRIMARYKEY_TIMESTAMP_COL_ID 1 #define PRIMARYKEY_TIMESTAMP_COL_ID 1
#define COL_REACH_END(colId, maxColId) ((colId) > (maxColId)) #define COL_REACH_END(colId, maxColId) ((colId) > (maxColId))
...@@ -354,8 +367,6 @@ typedef enum ELogicConditionType { ...@@ -354,8 +367,6 @@ typedef enum ELogicConditionType {
#define TSDB_META_COMPACT_RATIO 0 // disable tsdb meta compact by default #define TSDB_META_COMPACT_RATIO 0 // disable tsdb meta compact by default
/* /*
* 1. ordinary sub query for select * from super_table * 1. ordinary sub query for select * from super_table
* 2. all sqlobj generated by createSubqueryObj with this flag * 2. all sqlobj generated by createSubqueryObj with this flag
...@@ -394,7 +405,7 @@ typedef enum ELogicConditionType { ...@@ -394,7 +405,7 @@ typedef enum ELogicConditionType {
#define TSDB_DEFAULT_STABLES_HASH_SIZE 100 #define TSDB_DEFAULT_STABLES_HASH_SIZE 100
#define TSDB_DEFAULT_CTABLES_HASH_SIZE 20000 #define TSDB_DEFAULT_CTABLES_HASH_SIZE 20000
#define TSDB_MAX_WAL_SIZE (1024*1024*3) #define TSDB_MAX_WAL_SIZE (1024 * 1024 * 3)
#define TSDB_ARB_DUMMY_TIME 4765104000000 // 2121-01-01 00:00:00.000, :P #define TSDB_ARB_DUMMY_TIME 4765104000000 // 2121-01-01 00:00:00.000, :P
...@@ -410,6 +421,12 @@ typedef enum ELogicConditionType { ...@@ -410,6 +421,12 @@ typedef enum ELogicConditionType {
enum { TRANS_STAT_INIT = 0, TRANS_STAT_EXECUTING, TRANS_STAT_EXECUTED, TRANS_STAT_ROLLBACKING, TRANS_STAT_ROLLBACKED }; enum { TRANS_STAT_INIT = 0, TRANS_STAT_EXECUTING, TRANS_STAT_EXECUTED, TRANS_STAT_ROLLBACKING, TRANS_STAT_ROLLBACKED };
enum { TRANS_OPER_INIT = 0, TRANS_OPER_EXECUTE, TRANS_OPER_ROLLBACK }; enum { TRANS_OPER_INIT = 0, TRANS_OPER_EXECUTE, TRANS_OPER_ROLLBACK };
typedef struct {
char dir[TSDB_FILENAME_LEN];
int32_t level;
int32_t primary;
} SDiskCfg;
#ifdef __cplusplus #ifdef __cplusplus
} }
#endif #endif
......
...@@ -13,23 +13,20 @@ ...@@ -13,23 +13,20 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#ifndef _TD_COMMON_CFG_H_ #ifndef _TD_UTIL_DES_H
#define _TD_COMMON_CFG_H_ #define _TD_UTIL_DES_H
#include "os.h"
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C" {
#endif #endif
#include "tdef.h" char *taosDesEncode(int64_t key, char *src, int32_t len);
char *taosDesDecode(int64_t key, char *src, int32_t len);
typedef struct {
char dir[TSDB_FILENAME_LEN];
int level;
int primary;
} SDiskCfg;
#ifdef __cplusplus #ifdef __cplusplus
} }
#endif #endif
#endif /*_TD_COMMON_CFG_H_*/ #endif /*_TD_UTIL_DES_H*/
\ No newline at end of file
...@@ -16,8 +16,8 @@ ...@@ -16,8 +16,8 @@
#ifndef _TD_UTIL_ENCODE_H_ #ifndef _TD_UTIL_ENCODE_H_
#define _TD_UTIL_ENCODE_H_ #define _TD_UTIL_ENCODE_H_
#include "freelist.h"
#include "tcoding.h" #include "tcoding.h"
#include "tfreelist.h"
#include "tmacro.h" #include "tmacro.h"
#ifdef __cplusplus #ifdef __cplusplus
...@@ -81,52 +81,52 @@ void tCoderInit(SCoder* pCoder, td_endian_t endian, uint8_t* data, int32_t size, ...@@ -81,52 +81,52 @@ void tCoderInit(SCoder* pCoder, td_endian_t endian, uint8_t* data, int32_t size,
void tCoderClear(SCoder* pCoder); void tCoderClear(SCoder* pCoder);
/* ------------------------ ENCODE ------------------------ */ /* ------------------------ ENCODE ------------------------ */
int tStartEncode(SCoder* pEncoder); int32_t tStartEncode(SCoder* pEncoder);
void tEndEncode(SCoder* pEncoder); void tEndEncode(SCoder* pEncoder);
static int tEncodeU8(SCoder* pEncoder, uint8_t val); static int32_t tEncodeU8(SCoder* pEncoder, uint8_t val);
static int tEncodeI8(SCoder* pEncoder, int8_t val); static int32_t tEncodeI8(SCoder* pEncoder, int8_t val);
static int tEncodeU16(SCoder* pEncoder, uint16_t val); static int32_t tEncodeU16(SCoder* pEncoder, uint16_t val);
static int tEncodeI16(SCoder* pEncoder, int16_t val); static int32_t tEncodeI16(SCoder* pEncoder, int16_t val);
static int tEncodeU32(SCoder* pEncoder, uint32_t val); static int32_t tEncodeU32(SCoder* pEncoder, uint32_t val);
static int tEncodeI32(SCoder* pEncoder, int32_t val); static int32_t tEncodeI32(SCoder* pEncoder, int32_t val);
static int tEncodeU64(SCoder* pEncoder, uint64_t val); static int32_t tEncodeU64(SCoder* pEncoder, uint64_t val);
static int tEncodeI64(SCoder* pEncoder, int64_t val); static int32_t tEncodeI64(SCoder* pEncoder, int64_t val);
static int tEncodeU16v(SCoder* pEncoder, uint16_t val); static int32_t tEncodeU16v(SCoder* pEncoder, uint16_t val);
static int tEncodeI16v(SCoder* pEncoder, int16_t val); static int32_t tEncodeI16v(SCoder* pEncoder, int16_t val);
static int tEncodeU32v(SCoder* pEncoder, uint32_t val); static int32_t tEncodeU32v(SCoder* pEncoder, uint32_t val);
static int tEncodeI32v(SCoder* pEncoder, int32_t val); static int32_t tEncodeI32v(SCoder* pEncoder, int32_t val);
static int tEncodeU64v(SCoder* pEncoder, uint64_t val); static int32_t tEncodeU64v(SCoder* pEncoder, uint64_t val);
static int tEncodeI64v(SCoder* pEncoder, int64_t val); static int32_t tEncodeI64v(SCoder* pEncoder, int64_t val);
static int tEncodeFloat(SCoder* pEncoder, float val); static int32_t tEncodeFloat(SCoder* pEncoder, float val);
static int tEncodeDouble(SCoder* pEncoder, double val); static int32_t tEncodeDouble(SCoder* pEncoder, double val);
static int tEncodeBinary(SCoder* pEncoder, const void* val, uint64_t len); static int32_t tEncodeBinary(SCoder* pEncoder, const void* val, uint64_t len);
static int tEncodeCStrWithLen(SCoder* pEncoder, const char* val, uint64_t len); static int32_t tEncodeCStrWithLen(SCoder* pEncoder, const char* val, uint64_t len);
static int tEncodeCStr(SCoder* pEncoder, const char* val); static int32_t tEncodeCStr(SCoder* pEncoder, const char* val);
/* ------------------------ DECODE ------------------------ */ /* ------------------------ DECODE ------------------------ */
int tStartDecode(SCoder* pDecoder); int32_t tStartDecode(SCoder* pDecoder);
void tEndDecode(SCoder* pDecoder); void tEndDecode(SCoder* pDecoder);
static bool tDecodeIsEnd(SCoder* pCoder); static bool tDecodeIsEnd(SCoder* pCoder);
static int tDecodeU8(SCoder* pDecoder, uint8_t* val); static int32_t tDecodeU8(SCoder* pDecoder, uint8_t* val);
static int tDecodeI8(SCoder* pDecoder, int8_t* val); static int32_t tDecodeI8(SCoder* pDecoder, int8_t* val);
static int tDecodeU16(SCoder* pDecoder, uint16_t* val); static int32_t tDecodeU16(SCoder* pDecoder, uint16_t* val);
static int tDecodeI16(SCoder* pDecoder, int16_t* val); static int32_t tDecodeI16(SCoder* pDecoder, int16_t* val);
static int tDecodeU32(SCoder* pDecoder, uint32_t* val); static int32_t tDecodeU32(SCoder* pDecoder, uint32_t* val);
static int tDecodeI32(SCoder* pDecoder, int32_t* val); static int32_t tDecodeI32(SCoder* pDecoder, int32_t* val);
static int tDecodeU64(SCoder* pDecoder, uint64_t* val); static int32_t tDecodeU64(SCoder* pDecoder, uint64_t* val);
static int tDecodeI64(SCoder* pDecoder, int64_t* val); static int32_t tDecodeI64(SCoder* pDecoder, int64_t* val);
static int tDecodeU16v(SCoder* pDecoder, uint16_t* val); static int32_t tDecodeU16v(SCoder* pDecoder, uint16_t* val);
static int tDecodeI16v(SCoder* pDecoder, int16_t* val); static int32_t tDecodeI16v(SCoder* pDecoder, int16_t* val);
static int tDecodeU32v(SCoder* pDecoder, uint32_t* val); static int32_t tDecodeU32v(SCoder* pDecoder, uint32_t* val);
static int tDecodeI32v(SCoder* pDecoder, int32_t* val); static int32_t tDecodeI32v(SCoder* pDecoder, int32_t* val);
static int tDecodeU64v(SCoder* pDecoder, uint64_t* val); static int32_t tDecodeU64v(SCoder* pDecoder, uint64_t* val);
static int tDecodeI64v(SCoder* pDecoder, int64_t* val); static int32_t tDecodeI64v(SCoder* pDecoder, int64_t* val);
static int tDecodeFloat(SCoder* pDecoder, float* val); static int32_t tDecodeFloat(SCoder* pDecoder, float* val);
static int tDecodeDouble(SCoder* pDecoder, double* val); static int32_t tDecodeDouble(SCoder* pDecoder, double* val);
static int tDecodeBinary(SCoder* pDecoder, const void** val, uint64_t* len); static int32_t tDecodeBinary(SCoder* pDecoder, const void** val, uint64_t* len);
static int tDecodeCStrAndLen(SCoder* pDecoder, const char** val, uint64_t* len); static int32_t tDecodeCStrAndLen(SCoder* pDecoder, const char** val, uint64_t* len);
static int tDecodeCStr(SCoder* pDecoder, const char** val); static int32_t tDecodeCStr(SCoder* pDecoder, const char** val);
static int tDecodeCStrTo(SCoder* pDecoder, char* val); static int32_t tDecodeCStrTo(SCoder* pDecoder, char* val);
/* ------------------------ IMPL ------------------------ */ /* ------------------------ IMPL ------------------------ */
#define TD_ENCODE_MACRO(CODER, VAL, TYPE, BITS) \ #define TD_ENCODE_MACRO(CODER, VAL, TYPE, BITS) \
...@@ -190,7 +190,7 @@ static int tDecodeCStrTo(SCoder* pDecoder, char* val); ...@@ -190,7 +190,7 @@ static int tDecodeCStrTo(SCoder* pDecoder, char* val);
return 0; return 0;
// 8 // 8
static FORCE_INLINE int tEncodeU8(SCoder* pEncoder, uint8_t val) { static FORCE_INLINE int32_t tEncodeU8(SCoder* pEncoder, uint8_t val) {
if (pEncoder->data) { if (pEncoder->data) {
if (TD_CODER_CHECK_CAPACITY_FAILED(pEncoder, sizeof(val))) return -1; if (TD_CODER_CHECK_CAPACITY_FAILED(pEncoder, sizeof(val))) return -1;
tPut(uint8_t, TD_CODER_CURRENT(pEncoder), val); tPut(uint8_t, TD_CODER_CURRENT(pEncoder), val);
...@@ -199,7 +199,7 @@ static FORCE_INLINE int tEncodeU8(SCoder* pEncoder, uint8_t val) { ...@@ -199,7 +199,7 @@ static FORCE_INLINE int tEncodeU8(SCoder* pEncoder, uint8_t val) {
return 0; return 0;
} }
static FORCE_INLINE int tEncodeI8(SCoder* pEncoder, int8_t val) { static FORCE_INLINE int32_t tEncodeI8(SCoder* pEncoder, int8_t val) {
if (pEncoder->data) { if (pEncoder->data) {
if (TD_CODER_CHECK_CAPACITY_FAILED(pEncoder, sizeof(val))) return -1; if (TD_CODER_CHECK_CAPACITY_FAILED(pEncoder, sizeof(val))) return -1;
tPut(int8_t, TD_CODER_CURRENT(pEncoder), val); tPut(int8_t, TD_CODER_CURRENT(pEncoder), val);
...@@ -209,31 +209,31 @@ static FORCE_INLINE int tEncodeI8(SCoder* pEncoder, int8_t val) { ...@@ -209,31 +209,31 @@ static FORCE_INLINE int tEncodeI8(SCoder* pEncoder, int8_t val) {
} }
// 16 // 16
static FORCE_INLINE int tEncodeU16(SCoder* pEncoder, uint16_t val) { TD_ENCODE_MACRO(pEncoder, val, uint16_t, 16); } static FORCE_INLINE int32_t tEncodeU16(SCoder* pEncoder, uint16_t val) { TD_ENCODE_MACRO(pEncoder, val, uint16_t, 16); }
static FORCE_INLINE int tEncodeI16(SCoder* pEncoder, int16_t val) { TD_ENCODE_MACRO(pEncoder, val, int16_t, 16); } static FORCE_INLINE int32_t tEncodeI16(SCoder* pEncoder, int16_t val) { TD_ENCODE_MACRO(pEncoder, val, int16_t, 16); }
// 32 // 32
static FORCE_INLINE int tEncodeU32(SCoder* pEncoder, uint32_t val) { TD_ENCODE_MACRO(pEncoder, val, uint32_t, 32); } static FORCE_INLINE int32_t tEncodeU32(SCoder* pEncoder, uint32_t val) { TD_ENCODE_MACRO(pEncoder, val, uint32_t, 32); }
static FORCE_INLINE int tEncodeI32(SCoder* pEncoder, int32_t val) { TD_ENCODE_MACRO(pEncoder, val, int32_t, 32); } static FORCE_INLINE int32_t tEncodeI32(SCoder* pEncoder, int32_t val) { TD_ENCODE_MACRO(pEncoder, val, int32_t, 32); }
// 64 // 64
static FORCE_INLINE int tEncodeU64(SCoder* pEncoder, uint64_t val) { TD_ENCODE_MACRO(pEncoder, val, uint64_t, 64); } static FORCE_INLINE int32_t tEncodeU64(SCoder* pEncoder, uint64_t val) { TD_ENCODE_MACRO(pEncoder, val, uint64_t, 64); }
static FORCE_INLINE int tEncodeI64(SCoder* pEncoder, int64_t val) { TD_ENCODE_MACRO(pEncoder, val, int64_t, 64); } static FORCE_INLINE int32_t tEncodeI64(SCoder* pEncoder, int64_t val) { TD_ENCODE_MACRO(pEncoder, val, int64_t, 64); }
// 16v // 16v
static FORCE_INLINE int tEncodeU16v(SCoder* pEncoder, uint16_t val) { TD_ENCODE_VARIANT_MACRO(pEncoder, val); } static FORCE_INLINE int32_t tEncodeU16v(SCoder* pEncoder, uint16_t val) { TD_ENCODE_VARIANT_MACRO(pEncoder, val); }
static FORCE_INLINE int tEncodeI16v(SCoder* pEncoder, int16_t val) { static FORCE_INLINE int32_t tEncodeI16v(SCoder* pEncoder, int16_t val) {
return tEncodeU16v(pEncoder, ZIGZAGE(int16_t, val)); return tEncodeU16v(pEncoder, ZIGZAGE(int16_t, val));
} }
// 32v // 32v
static FORCE_INLINE int tEncodeU32v(SCoder* pEncoder, uint32_t val) { TD_ENCODE_VARIANT_MACRO(pEncoder, val); } static FORCE_INLINE int32_t tEncodeU32v(SCoder* pEncoder, uint32_t val) { TD_ENCODE_VARIANT_MACRO(pEncoder, val); }
static FORCE_INLINE int tEncodeI32v(SCoder* pEncoder, int32_t val) { static FORCE_INLINE int32_t tEncodeI32v(SCoder* pEncoder, int32_t val) {
return tEncodeU32v(pEncoder, ZIGZAGE(int32_t, val)); return tEncodeU32v(pEncoder, ZIGZAGE(int32_t, val));
} }
// 64v // 64v
static FORCE_INLINE int tEncodeU64v(SCoder* pEncoder, uint64_t val) { TD_ENCODE_VARIANT_MACRO(pEncoder, val); } static FORCE_INLINE int32_t tEncodeU64v(SCoder* pEncoder, uint64_t val) { TD_ENCODE_VARIANT_MACRO(pEncoder, val); }
static FORCE_INLINE int tEncodeI64v(SCoder* pEncoder, int64_t val) { static FORCE_INLINE int32_t tEncodeI64v(SCoder* pEncoder, int64_t val) {
return tEncodeU64v(pEncoder, ZIGZAGE(int64_t, val)); return tEncodeU64v(pEncoder, ZIGZAGE(int64_t, val));
} }
static FORCE_INLINE int tEncodeFloat(SCoder* pEncoder, float val) { static FORCE_INLINE int32_t tEncodeFloat(SCoder* pEncoder, float val) {
union { union {
uint32_t ui; uint32_t ui;
float f; float f;
...@@ -242,7 +242,7 @@ static FORCE_INLINE int tEncodeFloat(SCoder* pEncoder, float val) { ...@@ -242,7 +242,7 @@ static FORCE_INLINE int tEncodeFloat(SCoder* pEncoder, float val) {
return tEncodeU32(pEncoder, v.ui); return tEncodeU32(pEncoder, v.ui);
} }
static FORCE_INLINE int tEncodeDouble(SCoder* pEncoder, double val) { static FORCE_INLINE int32_t tEncodeDouble(SCoder* pEncoder, double val) {
union { union {
uint64_t ui; uint64_t ui;
double d; double d;
...@@ -251,7 +251,7 @@ static FORCE_INLINE int tEncodeDouble(SCoder* pEncoder, double val) { ...@@ -251,7 +251,7 @@ static FORCE_INLINE int tEncodeDouble(SCoder* pEncoder, double val) {
return tEncodeU64(pEncoder, v.ui); return tEncodeU64(pEncoder, v.ui);
} }
static FORCE_INLINE int tEncodeBinary(SCoder* pEncoder, const void* val, uint64_t len) { static FORCE_INLINE int32_t tEncodeBinary(SCoder* pEncoder, const void* val, uint64_t len) {
if (tEncodeU64v(pEncoder, len) < 0) return -1; if (tEncodeU64v(pEncoder, len) < 0) return -1;
if (pEncoder->data) { if (pEncoder->data) {
if (TD_CODER_CHECK_CAPACITY_FAILED(pEncoder, len)) return -1; if (TD_CODER_CHECK_CAPACITY_FAILED(pEncoder, len)) return -1;
...@@ -262,24 +262,24 @@ static FORCE_INLINE int tEncodeBinary(SCoder* pEncoder, const void* val, uint64_ ...@@ -262,24 +262,24 @@ static FORCE_INLINE int tEncodeBinary(SCoder* pEncoder, const void* val, uint64_
return 0; return 0;
} }
static FORCE_INLINE int tEncodeCStrWithLen(SCoder* pEncoder, const char* val, uint64_t len) { static FORCE_INLINE int32_t tEncodeCStrWithLen(SCoder* pEncoder, const char* val, uint64_t len) {
return tEncodeBinary(pEncoder, (void*)val, len + 1); return tEncodeBinary(pEncoder, (void*)val, len + 1);
} }
static FORCE_INLINE int tEncodeCStr(SCoder* pEncoder, const char* val) { static FORCE_INLINE int32_t tEncodeCStr(SCoder* pEncoder, const char* val) {
return tEncodeCStrWithLen(pEncoder, val, (uint64_t)strlen(val)); return tEncodeCStrWithLen(pEncoder, val, (uint64_t)strlen(val));
} }
/* ------------------------ FOR DECODER ------------------------ */ /* ------------------------ FOR DECODER ------------------------ */
// 8 // 8
static FORCE_INLINE int tDecodeU8(SCoder* pDecoder, uint8_t* val) { static FORCE_INLINE int32_t tDecodeU8(SCoder* pDecoder, uint8_t* val) {
if (TD_CODER_CHECK_CAPACITY_FAILED(pDecoder, sizeof(*val))) return -1; if (TD_CODER_CHECK_CAPACITY_FAILED(pDecoder, sizeof(*val))) return -1;
tGet(uint8_t, TD_CODER_CURRENT(pDecoder), *val); tGet(uint8_t, TD_CODER_CURRENT(pDecoder), *val);
TD_CODER_MOVE_POS(pDecoder, sizeof(*val)); TD_CODER_MOVE_POS(pDecoder, sizeof(*val));
return 0; return 0;
} }
static FORCE_INLINE int tDecodeI8(SCoder* pDecoder, int8_t* val) { static FORCE_INLINE int32_t tDecodeI8(SCoder* pDecoder, int8_t* val) {
if (TD_CODER_CHECK_CAPACITY_FAILED(pDecoder, sizeof(*val))) return -1; if (TD_CODER_CHECK_CAPACITY_FAILED(pDecoder, sizeof(*val))) return -1;
tGet(int8_t, TD_CODER_CURRENT(pDecoder), *val); tGet(int8_t, TD_CODER_CURRENT(pDecoder), *val);
TD_CODER_MOVE_POS(pDecoder, sizeof(*val)); TD_CODER_MOVE_POS(pDecoder, sizeof(*val));
...@@ -287,21 +287,27 @@ static FORCE_INLINE int tDecodeI8(SCoder* pDecoder, int8_t* val) { ...@@ -287,21 +287,27 @@ static FORCE_INLINE int tDecodeI8(SCoder* pDecoder, int8_t* val) {
} }
// 16 // 16
static FORCE_INLINE int tDecodeU16(SCoder* pDecoder, uint16_t* val) { TD_DECODE_MACRO(pDecoder, val, uint16_t, 16); } static FORCE_INLINE int32_t tDecodeU16(SCoder* pDecoder, uint16_t* val) {
static FORCE_INLINE int tDecodeI16(SCoder* pDecoder, int16_t* val) { TD_DECODE_MACRO(pDecoder, val, int16_t, 16); } TD_DECODE_MACRO(pDecoder, val, uint16_t, 16);
}
static FORCE_INLINE int32_t tDecodeI16(SCoder* pDecoder, int16_t* val) { TD_DECODE_MACRO(pDecoder, val, int16_t, 16); }
// 32 // 32
static FORCE_INLINE int tDecodeU32(SCoder* pDecoder, uint32_t* val) { TD_DECODE_MACRO(pDecoder, val, uint32_t, 32); } static FORCE_INLINE int32_t tDecodeU32(SCoder* pDecoder, uint32_t* val) {
static FORCE_INLINE int tDecodeI32(SCoder* pDecoder, int32_t* val) { TD_DECODE_MACRO(pDecoder, val, int32_t, 32); } TD_DECODE_MACRO(pDecoder, val, uint32_t, 32);
}
static FORCE_INLINE int32_t tDecodeI32(SCoder* pDecoder, int32_t* val) { TD_DECODE_MACRO(pDecoder, val, int32_t, 32); }
// 64 // 64
static FORCE_INLINE int tDecodeU64(SCoder* pDecoder, uint64_t* val) { TD_DECODE_MACRO(pDecoder, val, uint64_t, 64); } static FORCE_INLINE int32_t tDecodeU64(SCoder* pDecoder, uint64_t* val) {
static FORCE_INLINE int tDecodeI64(SCoder* pDecoder, int64_t* val) { TD_DECODE_MACRO(pDecoder, val, int64_t, 64); } TD_DECODE_MACRO(pDecoder, val, uint64_t, 64);
}
static FORCE_INLINE int32_t tDecodeI64(SCoder* pDecoder, int64_t* val) { TD_DECODE_MACRO(pDecoder, val, int64_t, 64); }
// 16v // 16v
static FORCE_INLINE int tDecodeU16v(SCoder* pDecoder, uint16_t* val) { static FORCE_INLINE int32_t tDecodeU16v(SCoder* pDecoder, uint16_t* val) {
TD_DECODE_VARIANT_MACRO(pDecoder, val, uint16_t); TD_DECODE_VARIANT_MACRO(pDecoder, val, uint16_t);
} }
static FORCE_INLINE int tDecodeI16v(SCoder* pDecoder, int16_t* val) { static FORCE_INLINE int32_t tDecodeI16v(SCoder* pDecoder, int16_t* val) {
uint16_t tval; uint16_t tval;
if (tDecodeU16v(pDecoder, &tval) < 0) { if (tDecodeU16v(pDecoder, &tval) < 0) {
return -1; return -1;
...@@ -311,11 +317,11 @@ static FORCE_INLINE int tDecodeI16v(SCoder* pDecoder, int16_t* val) { ...@@ -311,11 +317,11 @@ static FORCE_INLINE int tDecodeI16v(SCoder* pDecoder, int16_t* val) {
} }
// 32v // 32v
static FORCE_INLINE int tDecodeU32v(SCoder* pDecoder, uint32_t* val) { static FORCE_INLINE int32_t tDecodeU32v(SCoder* pDecoder, uint32_t* val) {
TD_DECODE_VARIANT_MACRO(pDecoder, val, uint32_t); TD_DECODE_VARIANT_MACRO(pDecoder, val, uint32_t);
} }
static FORCE_INLINE int tDecodeI32v(SCoder* pDecoder, int32_t* val) { static FORCE_INLINE int32_t tDecodeI32v(SCoder* pDecoder, int32_t* val) {
uint32_t tval; uint32_t tval;
if (tDecodeU32v(pDecoder, &tval) < 0) { if (tDecodeU32v(pDecoder, &tval) < 0) {
return -1; return -1;
...@@ -325,11 +331,11 @@ static FORCE_INLINE int tDecodeI32v(SCoder* pDecoder, int32_t* val) { ...@@ -325,11 +331,11 @@ static FORCE_INLINE int tDecodeI32v(SCoder* pDecoder, int32_t* val) {
} }
// 64v // 64v
static FORCE_INLINE int tDecodeU64v(SCoder* pDecoder, uint64_t* val) { static FORCE_INLINE int32_t tDecodeU64v(SCoder* pDecoder, uint64_t* val) {
TD_DECODE_VARIANT_MACRO(pDecoder, val, uint64_t); TD_DECODE_VARIANT_MACRO(pDecoder, val, uint64_t);
} }
static FORCE_INLINE int tDecodeI64v(SCoder* pDecoder, int64_t* val) { static FORCE_INLINE int32_t tDecodeI64v(SCoder* pDecoder, int64_t* val) {
uint64_t tval; uint64_t tval;
if (tDecodeU64v(pDecoder, &tval) < 0) { if (tDecodeU64v(pDecoder, &tval) < 0) {
return -1; return -1;
...@@ -338,7 +344,7 @@ static FORCE_INLINE int tDecodeI64v(SCoder* pDecoder, int64_t* val) { ...@@ -338,7 +344,7 @@ static FORCE_INLINE int tDecodeI64v(SCoder* pDecoder, int64_t* val) {
return 0; return 0;
} }
static FORCE_INLINE int tDecodeFloat(SCoder* pDecoder, float* val) { static FORCE_INLINE int32_t tDecodeFloat(SCoder* pDecoder, float* val) {
union { union {
uint32_t ui; uint32_t ui;
float f; float f;
...@@ -352,7 +358,7 @@ static FORCE_INLINE int tDecodeFloat(SCoder* pDecoder, float* val) { ...@@ -352,7 +358,7 @@ static FORCE_INLINE int tDecodeFloat(SCoder* pDecoder, float* val) {
return 0; return 0;
} }
static FORCE_INLINE int tDecodeDouble(SCoder* pDecoder, double* val) { static FORCE_INLINE int32_t tDecodeDouble(SCoder* pDecoder, double* val) {
union { union {
uint64_t ui; uint64_t ui;
double d; double d;
...@@ -366,7 +372,7 @@ static FORCE_INLINE int tDecodeDouble(SCoder* pDecoder, double* val) { ...@@ -366,7 +372,7 @@ static FORCE_INLINE int tDecodeDouble(SCoder* pDecoder, double* val) {
return 0; return 0;
} }
static FORCE_INLINE int tDecodeBinary(SCoder* pDecoder, const void** val, uint64_t* len) { static FORCE_INLINE int32_t tDecodeBinary(SCoder* pDecoder, const void** val, uint64_t* len) {
if (tDecodeU64v(pDecoder, len) < 0) return -1; if (tDecodeU64v(pDecoder, len) < 0) return -1;
if (TD_CODER_CHECK_CAPACITY_FAILED(pDecoder, *len)) return -1; if (TD_CODER_CHECK_CAPACITY_FAILED(pDecoder, *len)) return -1;
...@@ -376,18 +382,18 @@ static FORCE_INLINE int tDecodeBinary(SCoder* pDecoder, const void** val, uint64 ...@@ -376,18 +382,18 @@ static FORCE_INLINE int tDecodeBinary(SCoder* pDecoder, const void** val, uint64
return 0; return 0;
} }
static FORCE_INLINE int tDecodeCStrAndLen(SCoder* pDecoder, const char** val, uint64_t* len) { static FORCE_INLINE int32_t tDecodeCStrAndLen(SCoder* pDecoder, const char** val, uint64_t* len) {
if (tDecodeBinary(pDecoder, (const void**)val, len) < 0) return -1; if (tDecodeBinary(pDecoder, (const void**)val, len) < 0) return -1;
(*len) -= 1; (*len) -= 1;
return 0; return 0;
} }
static FORCE_INLINE int tDecodeCStr(SCoder* pDecoder, const char** val) { static FORCE_INLINE int32_t tDecodeCStr(SCoder* pDecoder, const char** val) {
uint64_t len; uint64_t len;
return tDecodeCStrAndLen(pDecoder, val, &len); return tDecodeCStrAndLen(pDecoder, val, &len);
} }
static int tDecodeCStrTo(SCoder* pDecoder, char* val) { static int32_t tDecodeCStrTo(SCoder* pDecoder, char* val) {
const char* pStr; const char* pStr;
uint64_t len; uint64_t len;
if (tDecodeCStrAndLen(pDecoder, &pStr, &len) < 0) return -1; if (tDecodeCStrAndLen(pDecoder, &pStr, &len) < 0) return -1;
......
/*
* Copyright (c) 2020 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/>.
*/
#ifndef _TD_UTIL_EXCEPTION_H_
#define _TD_UTIL_EXCEPTION_H_
#include "os.h"
#ifdef __cplusplus
extern "C" {
#endif
/*
* cleanup actions
*/
typedef struct SCleanupAction {
bool failOnly;
uint8_t wrapper;
uint16_t reserved;
void* func;
union {
void* Ptr;
bool Bool;
char Char;
int8_t Int8;
uint8_t Uint8;
int16_t Int16;
uint16_t Uint16;
int32_t Int;
uint32_t Uint;
int32_t Int32;
uint32_t Uint32;
int64_t Int64;
uint64_t Uint64;
float Float;
double Double;
} arg1, arg2;
} SCleanupAction;
/*
* exception hander registration
*/
typedef struct SExceptionNode {
struct SExceptionNode* prev;
jmp_buf jb;
int32_t code;
int32_t maxCleanupAction;
int32_t numCleanupAction;
SCleanupAction* cleanupActions;
} SExceptionNode;
// functions & macros for auto-cleanup
void cleanupPush_void_ptr_ptr(bool failOnly, void* func, void* arg1, void* arg2);
void cleanupPush_void_ptr_bool(bool failOnly, void* func, void* arg1, bool arg2);
void cleanupPush_void_ptr(bool failOnly, void* func, void* arg);
void cleanupPush_int_int(bool failOnly, void* func, int32_t arg);
void cleanupPush_void(bool failOnly, void* func);
void cleanupPush_int_ptr(bool failOnly, void* func, void* arg);
int32_t cleanupGetActionCount();
void cleanupExecuteTo(int32_t anchor, bool failed);
void cleanupExecute(SExceptionNode* node, bool failed);
bool cleanupExceedLimit();
#define CLEANUP_PUSH_VOID_PTR_PTR(failOnly, func, arg1, arg2) \
cleanupPush_void_ptr_ptr((failOnly), (void*)(func), (void*)(arg1), (void*)(arg2))
#define CLEANUP_PUSH_VOID_PTR_BOOL(failOnly, func, arg1, arg2) \
cleanupPush_void_ptr_bool((failOnly), (void*)(func), (void*)(arg1), (bool)(arg2))
#define CLEANUP_PUSH_VOID_PTR(failOnly, func, arg) cleanupPush_void_ptr((failOnly), (void*)(func), (void*)(arg))
#define CLEANUP_PUSH_INT_INT(failOnly, func, arg) cleanupPush_void_ptr((failOnly), (void*)(func), (int32_t)(arg))
#define CLEANUP_PUSH_VOID(failOnly, func) cleanupPush_void((failOnly), (void*)(func))
#define CLEANUP_PUSH_INT_PTR(failOnly, func, arg) cleanupPush_int_ptr((failOnly), (void*)(func), (void*)(arg))
#define CLEANUP_PUSH_FREE(failOnly, arg) cleanupPush_void_ptr((failOnly), free, (void*)(arg))
#define CLEANUP_PUSH_CLOSE(failOnly, arg) cleanupPush_int_int((failOnly), close, (int32_t)(arg))
#define CLEANUP_PUSH_FCLOSE(failOnly, arg) cleanupPush_int_ptr((failOnly), fclose, (void*)(arg))
#define CLEANUP_GET_ANCHOR() cleanupGetActionCount()
#define CLEANUP_EXECUTE_TO(anchor, failed) cleanupExecuteTo((anchor), (failed))
#define CLEANUP_EXCEED_LIMIT() cleanupExceedLimit()
// functions & macros for exception handling
void exceptionPushNode(SExceptionNode* node);
int32_t exceptionPopNode();
void exceptionThrow(int32_t code);
#define TRY(maxCleanupActions) \
do { \
SExceptionNode exceptionNode = {0}; \
SCleanupAction cleanupActions[(maxCleanupActions) > 0 ? (maxCleanupActions) : 1]; \
exceptionNode.maxCleanupAction = (maxCleanupActions) > 0 ? (maxCleanupActions) : 1; \
exceptionNode.cleanupActions = cleanupActions; \
exceptionPushNode(&exceptionNode); \
int32_t caughtException = setjmp(exceptionNode.jb); \
if (caughtException == 0)
#define CATCH(code) \
int32_t code = exceptionPopNode(); \
if (caughtException == 1)
#define FINALLY(code) int32_t code = exceptionPopNode();
#define END_TRY \
} \
while (0) \
;
#define THROW(x) exceptionThrow((x))
#define CAUGHT_EXCEPTION() ((bool)(caughtException == 1))
#define CLEANUP_EXECUTE() cleanupExecute(&exceptionNode, CAUGHT_EXCEPTION())
#ifdef __cplusplus
}
#endif
#endif /*_TD_UTIL_EXCEPTION_H_*/
...@@ -16,7 +16,6 @@ ...@@ -16,7 +16,6 @@
#ifndef _TD_UTIL_FREELIST_H_ #ifndef _TD_UTIL_FREELIST_H_
#define _TD_UTIL_FREELIST_H_ #define _TD_UTIL_FREELIST_H_
#include "os.h"
#include "tlist.h" #include "tlist.h"
#ifdef __cplusplus #ifdef __cplusplus
......
...@@ -12,39 +12,39 @@ ...@@ -12,39 +12,39 @@
* You should have received a copy of the GNU Affero General Public License * 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/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#ifndef _TD_UTIL_FUNCTIONAL_H #ifndef _TD_UTIL_FUNCTIONAL_H_
#define _TD_UTIL_FUNCTIONAL_H #define _TD_UTIL_FUNCTIONAL_H_
#include "os.h"
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C" {
#endif #endif
#include "os.h" // TODO: hard to use, trying to rewrite it using va_list
//TODO: hard to use, trying to rewrite it using va_list
typedef void* (*GenericVaFunc)(void* args[]); typedef void* (*GenericVaFunc)(void* args[]);
typedef int32_t (*I32VaFunc) (void* args[]); typedef int32_t (*I32VaFunc)(void* args[]);
typedef void (*VoidVaFunc) (void* args[]); typedef void (*VoidVaFunc)(void* args[]);
typedef struct GenericSavedFunc { typedef struct GenericSavedFunc {
GenericVaFunc func; GenericVaFunc func;
void * args[]; void* args[];
} tGenericSavedFunc; } tGenericSavedFunc;
typedef struct I32SavedFunc { typedef struct I32SavedFunc {
I32VaFunc func; I32VaFunc func;
void * args[]; void* args[];
} tI32SavedFunc; } tI32SavedFunc;
typedef struct VoidSavedFunc { typedef struct VoidSavedFunc {
VoidVaFunc func; VoidVaFunc func;
void * args[]; void* args[];
} tVoidSavedFunc; } tVoidSavedFunc;
tGenericSavedFunc* genericSavedFuncInit(GenericVaFunc func, int numOfArgs); tGenericSavedFunc* genericSavedFuncInit(GenericVaFunc func, int32_t numOfArgs);
tI32SavedFunc* i32SavedFuncInit(I32VaFunc func, int numOfArgs); tI32SavedFunc* i32SavedFuncInit(I32VaFunc func, int32_t numOfArgs);
tVoidSavedFunc* voidSavedFuncInit(VoidVaFunc func, int numOfArgs); tVoidSavedFunc* voidSavedFuncInit(VoidVaFunc func, int32_t numOfArgs);
void* genericInvoke(tGenericSavedFunc* const pSavedFunc); void* genericInvoke(tGenericSavedFunc* const pSavedFunc);
int32_t i32Invoke(tI32SavedFunc* const pSavedFunc); int32_t i32Invoke(tI32SavedFunc* const pSavedFunc);
void voidInvoke(tVoidSavedFunc* const pSavedFunc); void voidInvoke(tVoidSavedFunc* const pSavedFunc);
...@@ -53,4 +53,4 @@ void voidInvoke(tVoidSavedFunc* const pSavedFunc); ...@@ -53,4 +53,4 @@ void voidInvoke(tVoidSavedFunc* const pSavedFunc);
} }
#endif #endif
#endif /*_TD_UTIL_FUNCTIONAL_H*/ #endif /*_TD_UTIL_FUNCTIONAL_H_*/
...@@ -13,18 +13,18 @@ ...@@ -13,18 +13,18 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#ifndef TDENGINE_HASH_H #ifndef _TD_UTIL_HASH_H_
#define TDENGINE_HASH_H #define _TD_UTIL_HASH_H_
#include "tarray.h"
#include "tlockfree.h"
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C" {
#endif #endif
#include "tarray.h"
#include "tlockfree.h"
typedef uint32_t (*_hash_fn_t)(const char *, uint32_t); typedef uint32_t (*_hash_fn_t)(const char *, uint32_t);
typedef int32_t (*_equal_fn_t)(const void*, const void*, size_t len); typedef int32_t (*_equal_fn_t)(const void *, const void *, size_t len);
typedef void (*_hash_before_fn_t)(void *); typedef void (*_hash_before_fn_t)(void *);
typedef void (*_hash_free_fn_t)(void *); typedef void (*_hash_free_fn_t)(void *);
...@@ -67,9 +67,9 @@ typedef struct SHashNode { ...@@ -67,9 +67,9 @@ typedef struct SHashNode {
char data[]; char data[];
} SHashNode; } SHashNode;
#define GET_HASH_NODE_KEY(_n) ((char*)(_n) + sizeof(SHashNode) + (_n)->dataLen) #define GET_HASH_NODE_KEY(_n) ((char *)(_n) + sizeof(SHashNode) + (_n)->dataLen)
#define GET_HASH_NODE_DATA(_n) ((char*)(_n) + sizeof(SHashNode)) #define GET_HASH_NODE_DATA(_n) ((char *)(_n) + sizeof(SHashNode))
#define GET_HASH_PNODE(_n) ((SHashNode *)((char*)(_n) - sizeof(SHashNode))) #define GET_HASH_PNODE(_n) ((SHashNode *)((char *)(_n) - sizeof(SHashNode)))
typedef enum SHashLockTypeE { typedef enum SHashLockTypeE {
HASH_NO_LOCK = 0, HASH_NO_LOCK = 0,
...@@ -128,7 +128,6 @@ int32_t taosHashPut(SHashObj *pHashObj, const void *key, size_t keyLen, void *da ...@@ -128,7 +128,6 @@ int32_t taosHashPut(SHashObj *pHashObj, const void *key, size_t keyLen, void *da
int32_t taosHashPutExt(SHashObj *pHashObj, const void *key, size_t keyLen, void *data, size_t size, bool *newAdded); int32_t taosHashPutExt(SHashObj *pHashObj, const void *key, size_t keyLen, void *data, size_t size, bool *newAdded);
/** /**
* return the payload data with the specified key * return the payload data with the specified key
* *
...@@ -147,7 +146,7 @@ void *taosHashGet(SHashObj *pHashObj, const void *key, size_t keyLen); ...@@ -147,7 +146,7 @@ void *taosHashGet(SHashObj *pHashObj, const void *key, size_t keyLen);
* @param destBuf * @param destBuf
* @return * @return
*/ */
void *taosHashGetClone(SHashObj *pHashObj, const void *key, size_t keyLen, void* destBuf); void *taosHashGetClone(SHashObj *pHashObj, const void *key, size_t keyLen, void *destBuf);
/** /**
* Clone the result to interval allocated buffer * Clone the result to interval allocated buffer
...@@ -157,7 +156,7 @@ void *taosHashGetClone(SHashObj *pHashObj, const void *key, size_t keyLen, void* ...@@ -157,7 +156,7 @@ void *taosHashGetClone(SHashObj *pHashObj, const void *key, size_t keyLen, void*
* @param destBuf * @param destBuf
* @return * @return
*/ */
void* taosHashGetCloneExt(SHashObj *pHashObj, const void *key, size_t keyLen, void (*fp)(void *), void** d, size_t *sz); void *taosHashGetCloneExt(SHashObj *pHashObj, const void *key, size_t keyLen, void (*fp)(void *), void **d, size_t *sz);
/** /**
* remove item with the specified key * remove item with the specified key
...@@ -213,8 +212,7 @@ void taosHashCancelIterate(SHashObj *pHashObj, void *p); ...@@ -213,8 +212,7 @@ void taosHashCancelIterate(SHashObj *pHashObj, void *p);
* @param data * @param data
* @return * @return
*/ */
int32_t taosHashGetKey(void *data, void** key, size_t* keyLen); int32_t taosHashGetKey(void *data, void **key, size_t *keyLen);
/** /**
* Get the corresponding key information for a given data in hash table, using memcpy * Get the corresponding key information for a given data in hash table, using memcpy
...@@ -222,13 +220,13 @@ int32_t taosHashGetKey(void *data, void** key, size_t* keyLen); ...@@ -222,13 +220,13 @@ int32_t taosHashGetKey(void *data, void** key, size_t* keyLen);
* @param dst * @param dst
* @return * @return
*/ */
static FORCE_INLINE int32_t taosHashCopyKey(void *data, void* dst) { static FORCE_INLINE int32_t taosHashCopyKey(void *data, void *dst) {
if (NULL == data || NULL == dst) { if (NULL == data || NULL == dst) {
return -1; return -1;
} }
SHashNode * node = GET_HASH_PNODE(data); SHashNode *node = GET_HASH_PNODE(data);
void* key = GET_HASH_NODE_KEY(node); void *key = GET_HASH_NODE_KEY(node);
memcpy(dst, key, node->keyLen); memcpy(dst, key, node->keyLen);
return 0; return 0;
...@@ -249,7 +247,7 @@ int32_t taosHashGetDataLen(void *data); ...@@ -249,7 +247,7 @@ int32_t taosHashGetDataLen(void *data);
* @param keyLen * @param keyLen
* @return * @return
*/ */
void* taosHashAcquire(SHashObj *pHashObj, const void *key, size_t keyLen); void *taosHashAcquire(SHashObj *pHashObj, const void *key, size_t keyLen);
/** /**
* release the prevous acquired obj * release the prevous acquired obj
...@@ -262,9 +260,8 @@ void taosHashRelease(SHashObj *pHashObj, void *p); ...@@ -262,9 +260,8 @@ void taosHashRelease(SHashObj *pHashObj, void *p);
void taosHashSetEqualFp(SHashObj *pHashObj, _equal_fn_t fp); void taosHashSetEqualFp(SHashObj *pHashObj, _equal_fn_t fp);
#ifdef __cplusplus #ifdef __cplusplus
} }
#endif #endif
#endif // TDENGINE_HASH_H #endif // _TD_UTIL_HASH_H_
...@@ -12,19 +12,20 @@ ...@@ -12,19 +12,20 @@
* You should have received a copy of the GNU Affero General Public License * 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/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#ifndef TDENGINE_HEAP_H
#define TDENGINE_HEAP_H #ifndef _TD_UTIL_HEAP_H_
#define _TD_UTIL_HEAP_H_
#include "os.h"
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C" {
#endif #endif
#include "os.h"
struct HeapNode; struct HeapNode;
/* Return non-zero if a < b. */ /* Return non-zero if a < b. */
typedef int (*HeapCompareFn)(const struct HeapNode* a, const struct HeapNode* b); typedef int32_t (*HeapCompareFn)(const struct HeapNode* a, const struct HeapNode* b);
typedef struct HeapNode { typedef struct HeapNode {
struct HeapNode* left; struct HeapNode* left;
...@@ -43,10 +44,9 @@ typedef struct { ...@@ -43,10 +44,9 @@ typedef struct {
HeapCompareFn compFn; HeapCompareFn compFn;
} Heap; } Heap;
Heap* heapCreate(HeapCompareFn fn); Heap* heapCreate(HeapCompareFn fn);
void heapDestroy(Heap *heap); void heapDestroy(Heap* heap);
HeapNode* heapMin(const Heap* heap); HeapNode* heapMin(const Heap* heap);
...@@ -56,10 +56,10 @@ void heapRemove(Heap* heap, struct HeapNode* node); ...@@ -56,10 +56,10 @@ void heapRemove(Heap* heap, struct HeapNode* node);
void heapDequeue(Heap* heap); void heapDequeue(Heap* heap);
size_t heapSize(Heap *heap); size_t heapSize(Heap* heap);
#ifdef __cplusplus #ifdef __cplusplus
} }
#endif #endif
#endif // TDENGINE_HASH_H #endif /*_TD_UTIL_HEAP_H_*/
...@@ -13,31 +13,34 @@ ...@@ -13,31 +13,34 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#ifndef _TD_UTIL_IDPOOL_H #ifndef _TD_UTIL_IDPOOL_H_
#define _TD_UTIL_IDPOOL_H #define _TD_UTIL_IDPOOL_H_
#include "os.h"
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C" {
#endif #endif
void *taosInitIdPool(int maxId); typedef struct {
int32_t maxId;
int taosUpdateIdPool(void *handle, int maxId); int32_t numOfFree;
int32_t freeSlot;
int taosIdPoolMaxSize(void *handle); bool *freeList;
pthread_mutex_t mutex;
int taosAllocateId(void *handle); } id_pool_t;
void taosFreeId(void *handle, int id); void *taosInitIdPool(int32_t maxId);
int32_t taosUpdateIdPool(id_pool_t *handle, int32_t maxId);
void taosIdPoolCleanUp(void *handle); int32_t taosIdPoolMaxSize(id_pool_t *handle);
int32_t taosAllocateId(id_pool_t *handle);
int taosIdPoolNumOfUsed(void *handle); void taosFreeId(id_pool_t *handle, int32_t id);
void taosIdPoolCleanUp(id_pool_t *handle);
bool taosIdPoolMarkStatus(void *handle, int id); int32_t taosIdPoolNumOfUsed(id_pool_t *handle);
bool taosIdPoolMarkStatus(id_pool_t *handle, int32_t id);
#ifdef __cplusplus #ifdef __cplusplus
} }
#endif #endif
#endif /*_TD_UTIL_IDPOOL_H*/ #endif /*_TD_UTIL_IDPOOL_H_*/
...@@ -16,35 +16,54 @@ ...@@ -16,35 +16,54 @@
#ifndef _TD_UTIL_JSON_H_ #ifndef _TD_UTIL_JSON_H_
#define _TD_UTIL_JSON_H_ #define _TD_UTIL_JSON_H_
#include "os.h"
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C" {
#endif #endif
#include "os.h"
typedef void SJson; typedef void SJson;
SJson* tjsonCreateObject(); SJson* tjsonCreateObject();
void tjsonDelete(SJson* pJson); void tjsonDelete(SJson* pJson);
SJson* tjsonAddArrayToObject(SJson* pJson, const char* pName); SJson* tjsonAddArrayToObject(SJson* pJson, const char* pName);
int32_t tjsonAddIntegerToObject(SJson* pJson, const char* pName, const uint64_t number); int32_t tjsonAddIntegerToObject(SJson* pJson, const char* pName, const uint64_t number);
int32_t tjsonAddDoubleToObject(SJson* pJson, const char* pName, const double number); int32_t tjsonAddDoubleToObject(SJson* pJson, const char* pName, const double number);
int32_t tjsonAddBoolToObject(SJson* pJson, const char* pName, const bool boolean);
int32_t tjsonAddStringToObject(SJson* pJson, const char* pName, const char* pVal); int32_t tjsonAddStringToObject(SJson* pJson, const char* pName, const char* pVal);
int32_t tjsonAddItemToObject(SJson* pJson, const char* pName, SJson* pItem); int32_t tjsonAddItemToObject(SJson* pJson, const char* pName, SJson* pItem);
int32_t tjsonAddItemToArray(SJson* pJson, SJson* pItem); int32_t tjsonAddItemToArray(SJson* pJson, SJson* pItem);
SJson* tjsonGetObjectItem(const SJson* pJson, const char* pName);
int32_t tjsonGetStringValue(const SJson* pJson, const char* pName, char* pVal);
int32_t tjsonDupStringValue(const SJson* pJson, const char* pName, char** pVal);
int32_t tjsonGetBigIntValue(const SJson* pJson, const char* pName, int64_t* pVal);
int32_t tjsonGetIntValue(const SJson* pJson, const char* pName, int32_t* pVal);
int32_t tjsonGetSmallIntValue(const SJson* pJson, const char* pName, int16_t* pVal);
int32_t tjsonGetTinyIntValue(const SJson* pJson, const char* pName, int8_t* pVal);
int32_t tjsonGetUBigIntValue(const SJson* pJson, const char* pName, uint64_t* pVal);
int32_t tjsonGetUTinyIntValue(const SJson* pJson, const char* pName, uint8_t* pVal);
int32_t tjsonGetBoolValue(const SJson* pJson, const char* pName, bool* pVal);
int32_t tjsonGetDoubleValue(const SJson* pJson, const char* pName, double* pVal);
int32_t tjsonGetArraySize(const SJson* pJson);
SJson* tjsonGetArrayItem(const SJson* pJson, int32_t index);
typedef int32_t (*FToJson)(const void* pObj, SJson* pJson); typedef int32_t (*FToJson)(const void* pObj, SJson* pJson);
int32_t tjsonAddObject(SJson* pJson, const char* pName, FToJson func, const void* pObj); int32_t tjsonAddObject(SJson* pJson, const char* pName, FToJson func, const void* pObj);
int32_t tjsonAddItem(SJson* pJson, FToJson func, const void* pObj); int32_t tjsonAddItem(SJson* pJson, FToJson func, const void* pObj);
typedef int32_t (*FFromJson)(const SJson* pJson, void* pObj); typedef int32_t (*FToObject)(const SJson* pJson, void* pObj);
int32_t tjsonToObject(const SJson* pJson, const char* pName, FToObject func, void* pObj);
char* tjsonToString(const SJson* pJson); char* tjsonToString(const SJson* pJson);
char* tjsonToUnformattedString(const SJson* pJson); char* tjsonToUnformattedString(const SJson* pJson);
SJson* tjsonParse(const char* pStr);
#ifdef __cplusplus #ifdef __cplusplus
} }
#endif #endif
......
/*
* 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/>.
*/
#ifndef _TD_UTIL_KEY_H
#define _TD_UTIL_KEY_H
#ifdef __cplusplus
extern "C" {
#endif
unsigned char *base64_decode(const char *value, int inlen, int *outlen);
char * base64_encode(const unsigned char *value, int vlen);
char * taosDesEncode(int64_t key, char *src, int len);
char * taosDesDecode(int64_t key, char *src, int len);
#ifdef __cplusplus
}
#endif
#endif /*_TD_UTIL_KEY_H*/
\ No newline at end of file
...@@ -12,8 +12,11 @@ ...@@ -12,8 +12,11 @@
* You should have received a copy of the GNU Affero General Public License * 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/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#ifndef _TD_UTIL_LIST_H
#define _TD_UTIL_LIST_H #ifndef _TD_UTIL_LIST_H_
#define _TD_UTIL_LIST_H_
#include "os.h"
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C" {
...@@ -28,7 +31,7 @@ extern "C" { ...@@ -28,7 +31,7 @@ extern "C" {
#define TD_SLIST(TYPE) \ #define TD_SLIST(TYPE) \
struct { \ struct { \
struct TYPE *sl_head_; \ struct TYPE *sl_head_; \
int sl_neles_; \ int32_t sl_neles_; \
} }
#define TD_SLIST_HEAD(sl) ((sl)->sl_head_) #define TD_SLIST_HEAD(sl) ((sl)->sl_head_)
...@@ -79,7 +82,7 @@ extern "C" { ...@@ -79,7 +82,7 @@ extern "C" {
struct { \ struct { \
struct TYPE *dl_head_; \ struct TYPE *dl_head_; \
struct TYPE *dl_tail_; \ struct TYPE *dl_tail_; \
int dl_neles_; \ int32_t dl_neles_; \
} }
#define TD_DLIST_NODE_PREV(dln) ((dln)->dl_prev_) #define TD_DLIST_NODE_PREV(dln) ((dln)->dl_prev_)
...@@ -200,11 +203,11 @@ typedef struct SListNode { ...@@ -200,11 +203,11 @@ typedef struct SListNode {
typedef struct { typedef struct {
TD_DLIST(SListNode); TD_DLIST(SListNode);
int eleSize; int32_t eleSize;
} SList; } SList;
typedef struct { typedef struct {
SListNode * next; SListNode *next;
TD_LIST_DIRECTION_T direction; TD_LIST_DIRECTION_T direction;
} SListIter; } SListIter;
...@@ -215,14 +218,14 @@ typedef struct { ...@@ -215,14 +218,14 @@ typedef struct {
#define isListEmpty(l) (TD_DLIST_NELES(l) == 0) #define isListEmpty(l) (TD_DLIST_NELES(l) == 0)
#define listNodeFree(n) free(n) #define listNodeFree(n) free(n)
void tdListInit(SList *list, int eleSize); void tdListInit(SList *list, int32_t eleSize);
void tdListEmpty(SList *list); void tdListEmpty(SList *list);
SList * tdListNew(int eleSize); SList *tdListNew(int32_t eleSize);
void * tdListFree(SList *list); void *tdListFree(SList *list);
void tdListPrependNode(SList *list, SListNode *node); void tdListPrependNode(SList *list, SListNode *node);
void tdListAppendNode(SList *list, SListNode *node); void tdListAppendNode(SList *list, SListNode *node);
int tdListPrepend(SList *list, void *data); int32_t tdListPrepend(SList *list, void *data);
int tdListAppend(SList *list, void *data); int32_t tdListAppend(SList *list, void *data);
SListNode *tdListPopHead(SList *list); SListNode *tdListPopHead(SList *list);
SListNode *tdListPopTail(SList *list); SListNode *tdListPopTail(SList *list);
SListNode *tdListGetHead(SList *list); SListNode *tdListGetHead(SList *list);
...@@ -239,4 +242,4 @@ SListNode *tdListNext(SListIter *pIter); ...@@ -239,4 +242,4 @@ SListNode *tdListNext(SListIter *pIter);
} }
#endif #endif
#endif /*_TD_UTIL_LIST_H*/ #endif /*_TD_UTIL_LIST_H_*/
\ No newline at end of file \ No newline at end of file
此差异已折叠。
此差异已折叠。
...@@ -13,14 +13,16 @@ ...@@ -13,14 +13,16 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#ifndef _TD_UTIL_LOSERTREE_H #ifndef _TD_UTIL_LOSERTREE_H_
#define _TD_UTIL_LOSERTREE_H #define _TD_UTIL_LOSERTREE_H_
#include "os.h"
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C" {
#endif #endif
typedef int (*__merge_compare_fn_t)(const void *, const void *, void *param); typedef int32_t (*__merge_compare_fn_t)(const void *, const void *, void *param);
typedef struct STreeNode { typedef struct STreeNode {
int32_t index; int32_t index;
...@@ -31,16 +33,17 @@ typedef struct SMultiwayMergeTreeInfo { ...@@ -31,16 +33,17 @@ typedef struct SMultiwayMergeTreeInfo {
int32_t numOfSources; int32_t numOfSources;
int32_t totalSources; int32_t totalSources;
__merge_compare_fn_t comparFn; __merge_compare_fn_t comparFn;
void * param; void *param;
struct STreeNode *pNode; struct STreeNode *pNode;
} SMultiwayMergeTreeInfo; } SMultiwayMergeTreeInfo;
#define tMergeTreeGetChosenIndex(t_) ((t_)->pNode[0].index) #define tMergeTreeGetChosenIndex(t_) ((t_)->pNode[0].index)
#define tMergeTreeGetAdjustIndex(t_) (tMergeTreeGetChosenIndex(t_) + (t_)->numOfSources) #define tMergeTreeGetAdjustIndex(t_) (tMergeTreeGetChosenIndex(t_) + (t_)->numOfSources)
int32_t tMergeTreeCreate(SMultiwayMergeTreeInfo **pTree, uint32_t numOfEntries, void *param, __merge_compare_fn_t compareFn); int32_t tMergeTreeCreate(SMultiwayMergeTreeInfo **pTree, uint32_t numOfEntries, void *param,
__merge_compare_fn_t compareFn);
void tMergeTreeDestroy(SMultiwayMergeTreeInfo* pTree); void tMergeTreeDestroy(SMultiwayMergeTreeInfo *pTree);
void tMergeTreeAdjust(SMultiwayMergeTreeInfo *pTree, int32_t idx); void tMergeTreeAdjust(SMultiwayMergeTreeInfo *pTree, int32_t idx);
...@@ -52,4 +55,4 @@ void tMergeTreePrint(const SMultiwayMergeTreeInfo *pTree); ...@@ -52,4 +55,4 @@ void tMergeTreePrint(const SMultiwayMergeTreeInfo *pTree);
} }
#endif #endif
#endif /*_TD_UTIL_LOSERTREE_H*/ #endif /*_TD_UTIL_LOSERTREE_H_*/
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册