Merge branch '3.0' into cpwu/3.0
This commit is contained in:
commit
4a6f707702
|
@ -98,10 +98,10 @@ int32_t create_stream() {
|
|||
/*const char* sql = "select min(k), max(k), sum(k) as sum_of_k from st1";*/
|
||||
/*const char* sql = "select sum(k) from tu1 interval(10m)";*/
|
||||
/*pRes = tmq_create_stream(pConn, "stream1", "out1", sql);*/
|
||||
pRes = taos_query(
|
||||
pConn,
|
||||
"create stream stream1 trigger max_delay 10s into outstb as select _wstartts, sum(k) from st1 partition "
|
||||
"by tbname session(ts, 10s) ");
|
||||
pRes =
|
||||
taos_query(pConn,
|
||||
"create stream stream1 trigger max_delay 10s into outstb as select _wstart, sum(k) from st1 partition "
|
||||
"by tbname session(ts, 10s) ");
|
||||
if (taos_errno(pRes) != 0) {
|
||||
printf("failed to create stream stream1, reason:%s\n", taos_errstr(pRes));
|
||||
return -1;
|
||||
|
|
|
@ -108,6 +108,7 @@ typedef struct SDataBlockInfo {
|
|||
// TODO: optimize and remove following
|
||||
int32_t childId; // used for stream, do not serialize
|
||||
EStreamType type; // used for stream, do not serialize
|
||||
STimeWindow calWin; // used for stream, do not serialize
|
||||
} SDataBlockInfo;
|
||||
|
||||
typedef struct SSDataBlock {
|
||||
|
|
|
@ -64,18 +64,22 @@ int32_t tPutValue(uint8_t *p, SValue *pValue, int8_t type);
|
|||
int32_t tGetValue(uint8_t *p, SValue *pValue, int8_t type);
|
||||
int tValueCmprFn(const SValue *pValue1, const SValue *pValue2, int8_t type);
|
||||
|
||||
// STSRow2
|
||||
// SColVal
|
||||
#define COL_VAL_NONE(CID, TYPE) ((SColVal){.cid = (CID), .type = (TYPE), .isNone = 1})
|
||||
#define COL_VAL_NULL(CID, TYPE) ((SColVal){.cid = (CID), .type = (TYPE), .isNull = 1})
|
||||
#define COL_VAL_VALUE(CID, TYPE, V) ((SColVal){.cid = (CID), .type = (TYPE), .value = (V)})
|
||||
|
||||
// STSRow2
|
||||
#define TSROW_LEN(PROW, V) tGetI32v((uint8_t *)(PROW)->data, (V) ? &(V) : NULL)
|
||||
#define TSROW_SVER(PROW, V) tGetI32v((PROW)->data + TSROW_LEN(PROW, NULL), (V) ? &(V) : NULL)
|
||||
|
||||
int32_t tTSRowNew(STSRowBuilder *pBuilder, SArray *pArray, STSchema *pTSchema, STSRow2 **ppRow);
|
||||
int32_t tTSRowClone(const STSRow2 *pRow, STSRow2 **ppRow);
|
||||
void tTSRowFree(STSRow2 *pRow);
|
||||
void tTSRowGet(STSRow2 *pRow, STSchema *pTSchema, int32_t iCol, SColVal *pColVal);
|
||||
int32_t tTSRowToArray(STSRow2 *pRow, STSchema *pTSchema, SArray **ppArray);
|
||||
int32_t tPutTSRow(uint8_t *p, STSRow2 *pRow);
|
||||
int32_t tGetTSRow(uint8_t *p, STSRow2 *pRow);
|
||||
int32_t tGetTSRow(uint8_t *p, STSRow2 **ppRow);
|
||||
|
||||
// STSRowBuilder
|
||||
#define tsRowBuilderInit() ((STSRowBuilder){0})
|
||||
|
@ -97,7 +101,7 @@ int32_t tEncodeTag(SEncoder *pEncoder, const STag *pTag);
|
|||
int32_t tDecodeTag(SDecoder *pDecoder, STag **ppTag);
|
||||
int32_t tTagToValArray(const STag *pTag, SArray **ppArray);
|
||||
void debugPrintSTag(STag *pTag, const char *tag, int32_t ln); // TODO: remove
|
||||
int32_t parseJsontoTagData(const char* json, SArray* pTagVals, STag** ppTag, void* pMsgBuf);
|
||||
int32_t parseJsontoTagData(const char *json, SArray *pTagVals, STag **ppTag, void *pMsgBuf);
|
||||
|
||||
// STRUCT =================
|
||||
struct STColumn {
|
||||
|
@ -123,16 +127,16 @@ struct STSchema {
|
|||
#define TSROW_KV_SMALL ((uint8_t)0x10U)
|
||||
#define TSROW_KV_MID ((uint8_t)0x20U)
|
||||
#define TSROW_KV_BIG ((uint8_t)0x40U)
|
||||
#pragma pack(push, 1)
|
||||
struct STSRow2 {
|
||||
TSKEY ts;
|
||||
uint8_t flags;
|
||||
int32_t sver;
|
||||
uint32_t nData;
|
||||
uint8_t *pData;
|
||||
TSKEY ts;
|
||||
uint8_t flags;
|
||||
uint8_t data[];
|
||||
};
|
||||
#pragma pack(pop)
|
||||
|
||||
struct STSRowBuilder {
|
||||
STSRow2 tsRow;
|
||||
// STSRow2 tsRow;
|
||||
int32_t szBuf;
|
||||
uint8_t *pBuf;
|
||||
};
|
||||
|
@ -226,50 +230,6 @@ struct STag {
|
|||
memcpy(varDataVal(x), (str), (_size)); \
|
||||
} while (0);
|
||||
|
||||
// ----------------- TSDB COLUMN DEFINITION
|
||||
|
||||
#define colType(col) ((col)->type)
|
||||
#define colFlags(col) ((col)->flags)
|
||||
#define colColId(col) ((col)->colId)
|
||||
#define colBytes(col) ((col)->bytes)
|
||||
#define colOffset(col) ((col)->offset)
|
||||
|
||||
#define colSetType(col, t) (colType(col) = (t))
|
||||
#define colSetFlags(col, f) (colFlags(col) = (f))
|
||||
#define colSetColId(col, id) (colColId(col) = (id))
|
||||
#define colSetBytes(col, b) (colBytes(col) = (b))
|
||||
#define colSetOffset(col, o) (colOffset(col) = (o))
|
||||
|
||||
// ----------------- TSDB SCHEMA DEFINITION
|
||||
|
||||
#define schemaNCols(s) ((s)->numOfCols)
|
||||
#define schemaVersion(s) ((s)->version)
|
||||
#define schemaTLen(s) ((s)->tlen)
|
||||
#define schemaFLen(s) ((s)->flen)
|
||||
#define schemaVLen(s) ((s)->vlen)
|
||||
#define schemaColAt(s, i) ((s)->columns + i)
|
||||
#define tdFreeSchema(s) taosMemoryFreeClear((s))
|
||||
|
||||
STSchema *tdDupSchema(const STSchema *pSchema);
|
||||
int32_t tdEncodeSchema(void **buf, STSchema *pSchema);
|
||||
void *tdDecodeSchema(void *buf, STSchema **pRSchema);
|
||||
|
||||
static FORCE_INLINE int32_t comparColId(const void *key1, const void *key2) {
|
||||
if (*(int16_t *)key1 > ((STColumn *)key2)->colId) {
|
||||
return 1;
|
||||
} else if (*(int16_t *)key1 < ((STColumn *)key2)->colId) {
|
||||
return -1;
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
static FORCE_INLINE STColumn *tdGetColOfID(STSchema *pSchema, int16_t colId) {
|
||||
void *ptr = bsearch(&colId, (void *)pSchema->columns, schemaNCols(pSchema), sizeof(STColumn), comparColId);
|
||||
if (ptr == NULL) return NULL;
|
||||
return (STColumn *)ptr;
|
||||
}
|
||||
|
||||
// ----------------- SCHEMA BUILDER DEFINITION
|
||||
typedef struct {
|
||||
int32_t tCols;
|
||||
|
@ -299,141 +259,6 @@ void tdResetTSchemaBuilder(STSchemaBuilder *pBuilder, schema_ver_t version)
|
|||
int32_t tdAddColToSchema(STSchemaBuilder *pBuilder, int8_t type, int8_t flags, col_id_t colId, col_bytes_t bytes);
|
||||
STSchema *tdGetSchemaFromBuilder(STSchemaBuilder *pBuilder);
|
||||
|
||||
// ----------------- Semantic timestamp key definition
|
||||
// typedef uint64_t TKEY;
|
||||
#define TKEY TSKEY
|
||||
|
||||
#define TKEY_INVALID UINT64_MAX
|
||||
#define TKEY_NULL TKEY_INVALID
|
||||
#define TKEY_NEGATIVE_FLAG (((TKEY)1) << 63)
|
||||
#define TKEY_VALUE_FILTER (~(TKEY_NEGATIVE_FLAG))
|
||||
|
||||
#define TKEY_IS_NEGATIVE(tkey) (((tkey)&TKEY_NEGATIVE_FLAG) != 0)
|
||||
#define TKEY_IS_DELETED(tkey) (false)
|
||||
|
||||
#define tdGetTKEY(key) (key)
|
||||
#define tdGetKey(tskey) (tskey)
|
||||
|
||||
#define MIN_TS_KEY ((TSKEY)0x8000000000000001)
|
||||
#define MAX_TS_KEY ((TSKEY)0x7fffffffffffffff)
|
||||
|
||||
#define TD_TO_TKEY(key) tdGetTKEY(((key) < MIN_TS_KEY) ? MIN_TS_KEY : (((key) > MAX_TS_KEY) ? MAX_TS_KEY : key))
|
||||
|
||||
static FORCE_INLINE TKEY keyToTkey(TSKEY key) {
|
||||
TSKEY lkey = key;
|
||||
if (key > MAX_TS_KEY) {
|
||||
lkey = MAX_TS_KEY;
|
||||
} else if (key < MIN_TS_KEY) {
|
||||
lkey = MIN_TS_KEY;
|
||||
}
|
||||
|
||||
return tdGetTKEY(lkey);
|
||||
}
|
||||
|
||||
static FORCE_INLINE int32_t tkeyComparFn(const void *tkey1, const void *tkey2) {
|
||||
TSKEY key1 = tdGetKey(*(TKEY *)tkey1);
|
||||
TSKEY key2 = tdGetKey(*(TKEY *)tkey2);
|
||||
|
||||
if (key1 < key2) {
|
||||
return -1;
|
||||
} else if (key1 > key2) {
|
||||
return 1;
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
// ----------------- Data column structure
|
||||
// SDataCol arrangement: data => bitmap => dataOffset
|
||||
typedef struct SDataCol {
|
||||
int8_t type; // column type
|
||||
uint8_t bitmap : 1; // 0: no bitmap if all rows are NORM, 1: has bitmap if has NULL/NORM rows
|
||||
uint8_t reserve : 7;
|
||||
int16_t colId; // column ID
|
||||
int32_t bytes; // column data bytes defined
|
||||
int32_t offset; // data offset in a SDataRow (including the header size)
|
||||
int32_t spaceSize; // Total space size for this column
|
||||
int32_t len; // column data length
|
||||
VarDataOffsetT *dataOff; // For binary and nchar data, the offset in the data column
|
||||
void *pData; // Actual data pointer
|
||||
void *pBitmap; // Bitmap pointer
|
||||
TSKEY ts; // only used in last NULL column
|
||||
} SDataCol;
|
||||
|
||||
#define isAllRowsNull(pCol) ((pCol)->len == 0)
|
||||
#define isAllRowsNone(pCol) ((pCol)->len == 0)
|
||||
static FORCE_INLINE void dataColReset(SDataCol *pDataCol) { pDataCol->len = 0; }
|
||||
|
||||
int32_t tdAllocMemForCol(SDataCol *pCol, int32_t maxPoints);
|
||||
|
||||
void dataColInit(SDataCol *pDataCol, STColumn *pCol, int32_t maxPoints);
|
||||
int32_t dataColAppendVal(SDataCol *pCol, const void *value, int32_t numOfRows, int32_t maxPoints);
|
||||
void *dataColSetOffset(SDataCol *pCol, int32_t nEle);
|
||||
|
||||
bool isNEleNull(SDataCol *pCol, int32_t nEle);
|
||||
|
||||
typedef struct {
|
||||
col_id_t maxCols; // max number of columns
|
||||
col_id_t numOfCols; // Total number of cols
|
||||
int32_t maxPoints; // max number of points
|
||||
int32_t numOfRows;
|
||||
int32_t bitmapMode : 1; // default is 0(2 bits), otherwise 1(1 bit)
|
||||
int32_t sversion : 31; // TODO: set sversion(not used yet)
|
||||
SDataCol *cols;
|
||||
} SDataCols;
|
||||
|
||||
static FORCE_INLINE bool tdDataColsIsBitmapI(SDataCols *pCols) { return pCols->bitmapMode != TSDB_BITMODE_DEFAULT; }
|
||||
static FORCE_INLINE void tdDataColsSetBitmapI(SDataCols *pCols) { pCols->bitmapMode = TSDB_BITMODE_ONE_BIT; }
|
||||
static FORCE_INLINE bool tdIsBitmapModeI(int8_t bitmapMode) { return bitmapMode != TSDB_BITMODE_DEFAULT; }
|
||||
|
||||
#define keyCol(pCols) (&((pCols)->cols[0])) // Key column
|
||||
#define dataColsTKeyAt(pCols, idx) ((TKEY *)(keyCol(pCols)->pData))[(idx)] // the idx row of column-wised data
|
||||
#define dataColsKeyAt(pCols, idx) tdGetKey(dataColsTKeyAt(pCols, idx))
|
||||
static FORCE_INLINE TKEY dataColsTKeyFirst(SDataCols *pCols) {
|
||||
if (pCols->numOfRows) {
|
||||
return dataColsTKeyAt(pCols, 0);
|
||||
} else {
|
||||
return TKEY_INVALID;
|
||||
}
|
||||
}
|
||||
|
||||
static FORCE_INLINE TSKEY dataColsKeyAtRow(SDataCols *pCols, int32_t row) {
|
||||
assert(row < pCols->numOfRows);
|
||||
return dataColsKeyAt(pCols, row);
|
||||
}
|
||||
|
||||
static FORCE_INLINE TSKEY dataColsKeyFirst(SDataCols *pCols) {
|
||||
if (pCols->numOfRows) {
|
||||
return dataColsKeyAt(pCols, 0);
|
||||
} else {
|
||||
return TSDB_DATA_TIMESTAMP_NULL;
|
||||
}
|
||||
}
|
||||
|
||||
static FORCE_INLINE TKEY dataColsTKeyLast(SDataCols *pCols) {
|
||||
if (pCols->numOfRows) {
|
||||
return dataColsTKeyAt(pCols, pCols->numOfRows - 1);
|
||||
} else {
|
||||
return TKEY_INVALID;
|
||||
}
|
||||
}
|
||||
|
||||
static FORCE_INLINE TSKEY dataColsKeyLast(SDataCols *pCols) {
|
||||
if (pCols->numOfRows) {
|
||||
return dataColsKeyAt(pCols, pCols->numOfRows - 1);
|
||||
} else {
|
||||
return TSDB_DATA_TIMESTAMP_NULL;
|
||||
}
|
||||
}
|
||||
|
||||
SDataCols *tdNewDataCols(int32_t maxCols, int32_t maxRows);
|
||||
void tdResetDataCols(SDataCols *pCols);
|
||||
int32_t tdInitDataCols(SDataCols *pCols, STSchema *pSchema);
|
||||
SDataCols *tdDupDataCols(SDataCols *pCols, bool keepData);
|
||||
SDataCols *tdFreeDataCols(SDataCols *pCols);
|
||||
int32_t tdMergeDataCols(SDataCols *target, SDataCols *source, int32_t rowsToMerge, int32_t *pOffset, bool update,
|
||||
TDRowVerT maxVer);
|
||||
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
|
|
@ -64,6 +64,7 @@ extern int32_t tsNumOfMnodeQueryThreads;
|
|||
extern int32_t tsNumOfMnodeFetchThreads;
|
||||
extern int32_t tsNumOfMnodeReadThreads;
|
||||
extern int32_t tsNumOfVnodeQueryThreads;
|
||||
extern int32_t tsNumOfVnodeStreamThreads;
|
||||
extern int32_t tsNumOfVnodeFetchThreads;
|
||||
extern int32_t tsNumOfVnodeWriteThreads;
|
||||
extern int32_t tsNumOfVnodeSyncThreads;
|
||||
|
|
|
@ -34,6 +34,7 @@ typedef enum {
|
|||
WRITE_QUEUE,
|
||||
APPLY_QUEUE,
|
||||
SYNC_QUEUE,
|
||||
STREAM_QUEUE,
|
||||
QUEUE_MAX,
|
||||
} EQueueType;
|
||||
|
||||
|
|
|
@ -168,7 +168,7 @@ typedef struct {
|
|||
|
||||
// N.B. If without STSchema, getExtendedRowSize() is used to get the rowMaxBytes and
|
||||
// (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) ((s)->tlen + TD_ROW_HEAD_LEN)
|
||||
|
||||
#define TD_ROW_SET_INFO(r, i) (TD_ROW_INFO(r) = (i))
|
||||
#define TD_ROW_SET_TYPE(r, t) (TD_ROW_TYPE(r) = (t))
|
||||
|
@ -223,9 +223,10 @@ int32_t tdSetBitmapValTypeN(void *pBitmap, int16_t nEle, TDR
|
|||
static FORCE_INLINE int32_t tdGetBitmapValType(const void *pBitmap, int16_t colIdx, TDRowValT *pValType,
|
||||
int8_t bitmapMode);
|
||||
bool tdIsBitmapBlkNorm(const void *pBitmap, int32_t numOfBits, int8_t bitmapMode);
|
||||
int32_t tdAppendValToDataCol(SDataCol *pCol, TDRowValT valType, const void *val, int32_t numOfRows, int32_t maxPoints,
|
||||
int8_t bitmapMode, bool isMerge);
|
||||
int32_t tdAppendSTSRowToDataCol(STSRow *pRow, STSchema *pSchema, SDataCols *pCols, bool isMerge);
|
||||
// int32_t tdAppendValToDataCol(SDataCol *pCol, TDRowValT valType, const void *val, int32_t numOfRows, int32_t
|
||||
// maxPoints,
|
||||
// int8_t bitmapMode, bool isMerge);
|
||||
// int32_t tdAppendSTSRowToDataCol(STSRow *pRow, STSchema *pSchema, SDataCols *pCols, bool isMerge);
|
||||
|
||||
int32_t tdGetBitmapValTypeII(const void *pBitmap, int16_t colIdx, TDRowValT *pValType);
|
||||
int32_t tdSetBitmapValTypeI(void *pBitmap, int16_t colIdx, TDRowValT valType);
|
||||
|
@ -318,12 +319,9 @@ bool tdSTSRowGetVal(STSRowIter *pIter, col_id_t colId, col_type_t colType, SC
|
|||
bool tdGetTpRowDataOfCol(STSRowIter *pIter, col_type_t colType, int32_t offset, SCellVal *pVal);
|
||||
bool tdGetKvRowValOfColEx(STSRowIter *pIter, col_id_t colId, col_type_t colType, col_id_t *nIdx, SCellVal *pVal);
|
||||
bool tdSTSRowIterNext(STSRowIter *pIter, col_id_t colId, col_type_t colType, SCellVal *pVal);
|
||||
STSRow *mergeTwoRows(void *buffer, STSRow *row1, STSRow *row2, STSchema *pSchema1, STSchema *pSchema2);
|
||||
int32_t tdGetColDataOfRow(SCellVal *pVal, SDataCol *pCol, int32_t row, int8_t bitmapMode);
|
||||
bool tdSTpRowGetVal(STSRow *pRow, col_id_t colId, col_type_t colType, int32_t flen, uint32_t offset, col_id_t colIdx,
|
||||
SCellVal *pVal);
|
||||
bool tdSKvRowGetVal(STSRow *pRow, col_id_t colId, col_id_t colIdx, SCellVal *pVal);
|
||||
int32_t dataColGetNEleLen(SDataCol *pDataCol, int32_t rows, int8_t bitmapMode);
|
||||
void tdSCellValPrint(SCellVal *pVal, int8_t colType);
|
||||
void tdSRowPrint(STSRow *row, STSchema *pSchema, const char *tag);
|
||||
|
||||
|
|
|
@ -72,6 +72,8 @@ static FORCE_INLINE int64_t taosGetTimestampToday(int32_t precision) {
|
|||
}
|
||||
|
||||
int64_t taosTimeAdd(int64_t t, int64_t duration, char unit, int32_t precision);
|
||||
int64_t taosTimeSub(int64_t t, int64_t duration, char unit, int32_t precision);
|
||||
|
||||
int64_t taosTimeTruncate(int64_t t, const SInterval* pInterval, int32_t precision);
|
||||
int32_t taosTimeCountInterval(int64_t skey, int64_t ekey, int64_t interval, char unit, int32_t precision);
|
||||
|
||||
|
|
|
@ -213,63 +213,64 @@
|
|||
#define TK_NK_ARROW 195
|
||||
#define TK_ROWTS 196
|
||||
#define TK_TBNAME 197
|
||||
#define TK_QSTARTTS 198
|
||||
#define TK_QENDTS 199
|
||||
#define TK_WSTARTTS 200
|
||||
#define TK_WENDTS 201
|
||||
#define TK_WDURATION 202
|
||||
#define TK_CAST 203
|
||||
#define TK_NOW 204
|
||||
#define TK_TODAY 205
|
||||
#define TK_TIMEZONE 206
|
||||
#define TK_CLIENT_VERSION 207
|
||||
#define TK_SERVER_VERSION 208
|
||||
#define TK_SERVER_STATUS 209
|
||||
#define TK_CURRENT_USER 210
|
||||
#define TK_COUNT 211
|
||||
#define TK_LAST_ROW 212
|
||||
#define TK_BETWEEN 213
|
||||
#define TK_IS 214
|
||||
#define TK_NK_LT 215
|
||||
#define TK_NK_GT 216
|
||||
#define TK_NK_LE 217
|
||||
#define TK_NK_GE 218
|
||||
#define TK_NK_NE 219
|
||||
#define TK_MATCH 220
|
||||
#define TK_NMATCH 221
|
||||
#define TK_CONTAINS 222
|
||||
#define TK_JOIN 223
|
||||
#define TK_INNER 224
|
||||
#define TK_SELECT 225
|
||||
#define TK_DISTINCT 226
|
||||
#define TK_WHERE 227
|
||||
#define TK_PARTITION 228
|
||||
#define TK_BY 229
|
||||
#define TK_SESSION 230
|
||||
#define TK_STATE_WINDOW 231
|
||||
#define TK_SLIDING 232
|
||||
#define TK_FILL 233
|
||||
#define TK_VALUE 234
|
||||
#define TK_NONE 235
|
||||
#define TK_PREV 236
|
||||
#define TK_LINEAR 237
|
||||
#define TK_NEXT 238
|
||||
#define TK_HAVING 239
|
||||
#define TK_RANGE 240
|
||||
#define TK_EVERY 241
|
||||
#define TK_ORDER 242
|
||||
#define TK_SLIMIT 243
|
||||
#define TK_SOFFSET 244
|
||||
#define TK_LIMIT 245
|
||||
#define TK_OFFSET 246
|
||||
#define TK_ASC 247
|
||||
#define TK_NULLS 248
|
||||
#define TK_ID 249
|
||||
#define TK_NK_BITNOT 250
|
||||
#define TK_VALUES 251
|
||||
#define TK_IMPORT 252
|
||||
#define TK_NK_SEMI 253
|
||||
#define TK_FILE 254
|
||||
#define TK_QSTART 198
|
||||
#define TK_QEND 199
|
||||
#define TK_QDURATION 200
|
||||
#define TK_WSTART 201
|
||||
#define TK_WEND 202
|
||||
#define TK_WDURATION 203
|
||||
#define TK_CAST 204
|
||||
#define TK_NOW 205
|
||||
#define TK_TODAY 206
|
||||
#define TK_TIMEZONE 207
|
||||
#define TK_CLIENT_VERSION 208
|
||||
#define TK_SERVER_VERSION 209
|
||||
#define TK_SERVER_STATUS 210
|
||||
#define TK_CURRENT_USER 211
|
||||
#define TK_COUNT 212
|
||||
#define TK_LAST_ROW 213
|
||||
#define TK_BETWEEN 214
|
||||
#define TK_IS 215
|
||||
#define TK_NK_LT 216
|
||||
#define TK_NK_GT 217
|
||||
#define TK_NK_LE 218
|
||||
#define TK_NK_GE 219
|
||||
#define TK_NK_NE 220
|
||||
#define TK_MATCH 221
|
||||
#define TK_NMATCH 222
|
||||
#define TK_CONTAINS 223
|
||||
#define TK_JOIN 224
|
||||
#define TK_INNER 225
|
||||
#define TK_SELECT 226
|
||||
#define TK_DISTINCT 227
|
||||
#define TK_WHERE 228
|
||||
#define TK_PARTITION 229
|
||||
#define TK_BY 230
|
||||
#define TK_SESSION 231
|
||||
#define TK_STATE_WINDOW 232
|
||||
#define TK_SLIDING 233
|
||||
#define TK_FILL 234
|
||||
#define TK_VALUE 235
|
||||
#define TK_NONE 236
|
||||
#define TK_PREV 237
|
||||
#define TK_LINEAR 238
|
||||
#define TK_NEXT 239
|
||||
#define TK_HAVING 240
|
||||
#define TK_RANGE 241
|
||||
#define TK_EVERY 242
|
||||
#define TK_ORDER 243
|
||||
#define TK_SLIMIT 244
|
||||
#define TK_SOFFSET 245
|
||||
#define TK_LIMIT 246
|
||||
#define TK_OFFSET 247
|
||||
#define TK_ASC 248
|
||||
#define TK_NULLS 249
|
||||
#define TK_ID 250
|
||||
#define TK_NK_BITNOT 251
|
||||
#define TK_VALUES 252
|
||||
#define TK_IMPORT 253
|
||||
#define TK_NK_SEMI 254
|
||||
#define TK_FILE 255
|
||||
|
||||
#define TK_NK_SPACE 300
|
||||
#define TK_NK_COMMENT 301
|
||||
|
|
|
@ -42,25 +42,28 @@ typedef struct SReadHandle {
|
|||
bool initTqReader;
|
||||
} SReadHandle;
|
||||
|
||||
// in queue mode, data streams are seperated by msg
|
||||
typedef enum {
|
||||
OPTR_EXEC_MODEL_BATCH = 0x1,
|
||||
OPTR_EXEC_MODEL_STREAM = 0x2,
|
||||
OPTR_EXEC_MODEL_QUEUE = 0x3,
|
||||
} EOPTR_EXEC_MODEL;
|
||||
|
||||
/**
|
||||
* Create the exec task for streaming mode
|
||||
* Create the exec task for stream mode
|
||||
* @param pMsg
|
||||
* @param streamReadHandle
|
||||
* @param SReadHandle
|
||||
* @return
|
||||
*/
|
||||
qTaskInfo_t qCreateStreamExecTaskInfo(void* msg, SReadHandle* readers);
|
||||
|
||||
/**
|
||||
* Switch the stream scan to snapshot mode
|
||||
* @param tinfo
|
||||
* Create the exec task for queue mode
|
||||
* @param pMsg
|
||||
* @param SReadHandle
|
||||
* @return
|
||||
*/
|
||||
int32_t qStreamScanSnapshot(qTaskInfo_t tinfo);
|
||||
qTaskInfo_t qCreateQueueExecTaskInfo(void* msg, SReadHandle* readers);
|
||||
|
||||
/**
|
||||
* Set the input data block for the stream scan.
|
||||
|
@ -111,7 +114,7 @@ int32_t qCreateExecTask(SReadHandle* readHandle, int32_t vgId, uint64_t taskId,
|
|||
* @return
|
||||
*/
|
||||
int32_t qGetQueryTableSchemaVersion(qTaskInfo_t tinfo, char* dbName, char* tableName, int32_t* sversion,
|
||||
int32_t* tversion);
|
||||
int32_t* tversion);
|
||||
|
||||
/**
|
||||
* The main task execution function, including query on both table and multiple tables,
|
||||
|
@ -183,9 +186,12 @@ int32_t qStreamExtractOffset(qTaskInfo_t tinfo, STqOffsetVal* pOffset);
|
|||
|
||||
void* qStreamExtractMetaMsg(qTaskInfo_t tinfo);
|
||||
|
||||
void* qExtractReaderFromStreamScanner(void* scanner);
|
||||
void* qExtractReaderFromStreamScanner(void* scanner);
|
||||
|
||||
int32_t qExtractStreamScanner(qTaskInfo_t tinfo, void** scanner);
|
||||
|
||||
int32_t qStreamInput(qTaskInfo_t tinfo, void* pItem);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
|
|
@ -34,7 +34,7 @@ typedef enum EFunctionType {
|
|||
FUNCTION_TYPE_ELAPSED,
|
||||
FUNCTION_TYPE_IRATE,
|
||||
FUNCTION_TYPE_LAST_ROW,
|
||||
FUNCTION_TYPE_LAST_ROWT, //TODO: removed
|
||||
FUNCTION_TYPE_LAST_ROWT, // TODO: removed
|
||||
FUNCTION_TYPE_MAX,
|
||||
FUNCTION_TYPE_MIN,
|
||||
FUNCTION_TYPE_MODE,
|
||||
|
@ -114,10 +114,11 @@ typedef enum EFunctionType {
|
|||
// pseudo column function
|
||||
FUNCTION_TYPE_ROWTS = 3500,
|
||||
FUNCTION_TYPE_TBNAME,
|
||||
FUNCTION_TYPE_QSTARTTS,
|
||||
FUNCTION_TYPE_QENDTS,
|
||||
FUNCTION_TYPE_WSTARTTS,
|
||||
FUNCTION_TYPE_WENDTS,
|
||||
FUNCTION_TYPE_QSTART,
|
||||
FUNCTION_TYPE_QEND,
|
||||
FUNCTION_TYPE_QDURATION,
|
||||
FUNCTION_TYPE_WSTART,
|
||||
FUNCTION_TYPE_WEND,
|
||||
FUNCTION_TYPE_WDURATION,
|
||||
|
||||
// internal function
|
||||
|
@ -197,6 +198,7 @@ bool fmIsInterpFunc(int32_t funcId);
|
|||
bool fmIsLastRowFunc(int32_t funcId);
|
||||
bool fmIsSystemInfoFunc(int32_t funcId);
|
||||
bool fmIsImplicitTsFunc(int32_t funcId);
|
||||
bool fmIsClientPseudoColumnFunc(int32_t funcId);
|
||||
|
||||
int32_t fmGetDistMethod(const SFunctionNode* pFunc, SFunctionNode** pPartialFunc, SFunctionNode** pMergeFunc);
|
||||
|
||||
|
|
|
@ -228,7 +228,7 @@ typedef struct SFillNode {
|
|||
ENodeType type; // QUERY_NODE_FILL
|
||||
EFillMode mode;
|
||||
SNode* pValues; // SNodeListNode
|
||||
SNode* pWStartTs; // _wstartts pseudo column
|
||||
SNode* pWStartTs; // _wstart pseudo column
|
||||
STimeWindow timeRange;
|
||||
} SFillNode;
|
||||
|
||||
|
@ -248,6 +248,7 @@ typedef struct SSelectStmt {
|
|||
SNodeList* pOrderByList; // SOrderByExprNode
|
||||
SLimitNode* pLimit;
|
||||
SLimitNode* pSlimit;
|
||||
STimeWindow timeRange;
|
||||
char stmtName[TSDB_TABLE_NAME_LEN];
|
||||
uint8_t precision;
|
||||
int32_t selectFuncNum;
|
||||
|
|
|
@ -32,6 +32,7 @@ pNode will be freed in API;
|
|||
*pRes need to freed in caller
|
||||
*/
|
||||
int32_t scalarCalculateConstants(SNode *pNode, SNode **pRes);
|
||||
int32_t scalarCalculateConstantsFromDual(SNode *pNode, SNode **pRes);
|
||||
|
||||
/*
|
||||
pDst need to freed in caller
|
||||
|
|
|
@ -13,7 +13,9 @@
|
|||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "executor.h"
|
||||
#include "os.h"
|
||||
#include "query.h"
|
||||
#include "tdatablock.h"
|
||||
#include "tmsg.h"
|
||||
#include "tmsgcb.h"
|
||||
|
@ -305,13 +307,18 @@ static FORCE_INLINE int32_t streamTaskInput(SStreamTask* pTask, SStreamQueueItem
|
|||
atomic_store_8(&pTask->inputStatus, TASK_INPUT_STATUS__FAILED);
|
||||
return -1;
|
||||
}
|
||||
qDebug("task %d %p submit enqueue %p %p %p", pTask->taskId, pTask, pItem, pSubmitClone, pSubmitClone->data);
|
||||
taosWriteQitem(pTask->inputQueue->queue, pSubmitClone);
|
||||
// qStreamInput(pTask->exec.executor, pSubmitClone);
|
||||
} else if (pItem->type == STREAM_INPUT__DATA_BLOCK || pItem->type == STREAM_INPUT__DATA_RETRIEVE) {
|
||||
taosWriteQitem(pTask->inputQueue->queue, pItem);
|
||||
// qStreamInput(pTask->exec.executor, pItem);
|
||||
} else if (pItem->type == STREAM_INPUT__CHECKPOINT) {
|
||||
taosWriteQitem(pTask->inputQueue->queue, pItem);
|
||||
// qStreamInput(pTask->exec.executor, pItem);
|
||||
} else if (pItem->type == STREAM_INPUT__TRIGGER) {
|
||||
taosWriteQitem(pTask->inputQueue->queue, pItem);
|
||||
// qStreamInput(pTask->exec.executor, pItem);
|
||||
}
|
||||
|
||||
if (pItem->type != STREAM_INPUT__TRIGGER && pItem->type != STREAM_INPUT__CHECKPOINT && pTask->triggerParam != 0) {
|
||||
|
|
|
@ -26,6 +26,8 @@ extern "C" {
|
|||
|
||||
extern bool gRaftDetailLog;
|
||||
|
||||
#define SYNC_RESP_TTL_MS 5000
|
||||
|
||||
#define SYNC_MAX_BATCH_SIZE 500
|
||||
#define SYNC_INDEX_BEGIN 0
|
||||
#define SYNC_INDEX_INVALID -1
|
||||
|
|
|
@ -584,7 +584,8 @@ int32_t* taosGetErrno();
|
|||
#define TSDB_CODE_PAR_INVALID_INTERP_CLAUSE TAOS_DEF_ERROR_CODE(0, 0x265D)
|
||||
#define TSDB_CODE_PAR_NO_VALID_FUNC_IN_WIN TAOS_DEF_ERROR_CODE(0, 0x265E)
|
||||
#define TSDB_CODE_PAR_ONLY_SUPPORT_SINGLE_TABLE TAOS_DEF_ERROR_CODE(0, 0x265F)
|
||||
#define TSDB_CODE_PAR_INVALID_SMA_INDEX TAOS_DEF_ERROR_CODE(0, 0x265C)
|
||||
#define TSDB_CODE_PAR_INVALID_SMA_INDEX TAOS_DEF_ERROR_CODE(0, 0x2660)
|
||||
#define TSDB_CODE_PAR_INVALID_SELECTED_EXPR TAOS_DEF_ERROR_CODE(0, 0x2661)
|
||||
|
||||
//planner
|
||||
#define TSDB_CODE_PLAN_INTERNAL_ERROR TAOS_DEF_ERROR_CODE(0, 0x2700)
|
||||
|
|
|
@ -94,7 +94,7 @@ void taosPrintLongString(const char *flags, ELogLevel level, int32_t dflag, cons
|
|||
#define pError(...) { taosPrintLog("APP ERROR ", DEBUG_ERROR, 255, __VA_ARGS__); }
|
||||
#define pPrint(...) { taosPrintLog("APP ", DEBUG_INFO, 255, __VA_ARGS__); }
|
||||
// clang-format on
|
||||
#define BUF_PAGE_DEBUG
|
||||
//#define BUF_PAGE_DEBUG
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
|
|
@ -44,6 +44,8 @@ typedef struct STaosQset STaosQset;
|
|||
typedef struct STaosQall STaosQall;
|
||||
typedef struct {
|
||||
void *ahandle;
|
||||
void *fp;
|
||||
void *queue;
|
||||
int32_t workerId;
|
||||
int32_t threadNum;
|
||||
int64_t timestamp;
|
||||
|
@ -65,6 +67,7 @@ void taosFreeQitem(void *pItem);
|
|||
void taosWriteQitem(STaosQueue *queue, void *pItem);
|
||||
int32_t taosReadQitem(STaosQueue *queue, void **ppItem);
|
||||
bool taosQueueEmpty(STaosQueue *queue);
|
||||
void taosUpdateItemSize(STaosQueue *queue, int32_t items);
|
||||
int32_t taosQueueItemSize(STaosQueue *queue);
|
||||
int64_t taosQueueMemorySize(STaosQueue *queue);
|
||||
|
||||
|
@ -81,8 +84,8 @@ int32_t taosAddIntoQset(STaosQset *qset, STaosQueue *queue, void *ahandle);
|
|||
void taosRemoveFromQset(STaosQset *qset, STaosQueue *queue);
|
||||
int32_t taosGetQueueNumber(STaosQset *qset);
|
||||
|
||||
int32_t taosReadQitemFromQset(STaosQset *qset, void **ppItem, int64_t *ts, void **ahandle, FItem *itemFp);
|
||||
int32_t taosReadAllQitemsFromQset(STaosQset *qset, STaosQall *qall, void **ahandle, FItems *itemsFp);
|
||||
int32_t taosReadQitemFromQset(STaosQset *qset, void **ppItem, SQueueInfo *qinfo);
|
||||
int32_t taosReadAllQitemsFromQset(STaosQset *qset, STaosQall *qall, SQueueInfo *qinfo);
|
||||
void taosResetQsetThread(STaosQset *qset, void *pItem);
|
||||
|
||||
extern int64_t tsRpcQueueMemoryAllowed;
|
||||
|
|
|
@ -181,6 +181,7 @@ typedef struct SRequestSendRecvBody {
|
|||
tsem_t rspSem; // not used now
|
||||
__taos_async_fn_t queryFp;
|
||||
__taos_async_fn_t fetchFp;
|
||||
EQueryExecMode execMode;
|
||||
void* param;
|
||||
SDataBuf requestMsg;
|
||||
int64_t queryJob; // query job, created according to sql query DAG.
|
||||
|
@ -223,8 +224,8 @@ typedef struct SRequestObj {
|
|||
SArray* tableList;
|
||||
SQueryExecMetric metric;
|
||||
SRequestSendRecvBody body;
|
||||
bool stableQuery; // todo refactor
|
||||
bool validateOnly; // todo refactor
|
||||
bool stableQuery; // todo refactor
|
||||
bool validateOnly; // todo refactor
|
||||
|
||||
bool killed;
|
||||
uint32_t prevCode; // previous error code: todo refactor, add update flag for catalog
|
||||
|
@ -325,7 +326,8 @@ int32_t parseSql(SRequestObj* pRequest, bool topicQuery, SQuery** pQuery, SStmtC
|
|||
|
||||
int32_t getPlan(SRequestObj* pRequest, SQuery* pQuery, SQueryPlan** pPlan, SArray* pNodeList);
|
||||
|
||||
int32_t buildRequest(uint64_t connId, const char* sql, int sqlLen, void* param, bool validateSql, SRequestObj** pRequest);
|
||||
int32_t buildRequest(uint64_t connId, const char* sql, int sqlLen, void* param, bool validateSql,
|
||||
SRequestObj** pRequest);
|
||||
|
||||
void taos_close_internal(void* taos);
|
||||
|
||||
|
@ -359,9 +361,6 @@ int32_t removeMeta(STscObj* pTscObj, SArray* tbList); // todo move to clie
|
|||
int32_t handleAlterTbExecRes(void* res, struct SCatalog* pCatalog); // todo move to xxx
|
||||
bool qnodeRequired(SRequestObj* pRequest);
|
||||
|
||||
void initTscQhandle();
|
||||
void cleanupTscQhandle();
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
|
|
@ -35,22 +35,10 @@ SAppInfo appInfo;
|
|||
int32_t clientReqRefPool = -1;
|
||||
int32_t clientConnRefPool = -1;
|
||||
|
||||
void *tscQhandle = NULL;
|
||||
|
||||
static TdThreadOnce tscinit = PTHREAD_ONCE_INIT;
|
||||
volatile int32_t tscInitRes = 0;
|
||||
|
||||
void initTscQhandle() {
|
||||
// init handle
|
||||
tscQhandle = taosInitScheduler(4096, 5, "tsc");
|
||||
}
|
||||
|
||||
void cleanupTscQhandle() {
|
||||
// destroy handle
|
||||
taosCleanUpScheduler(tscQhandle);
|
||||
}
|
||||
|
||||
static int32_t registerRequest(SRequestObj *pRequest, STscObj* pTscObj) {
|
||||
static int32_t registerRequest(SRequestObj *pRequest, STscObj *pTscObj) {
|
||||
// connection has been released already, abort creating request.
|
||||
pRequest->self = taosAddRef(clientReqRefPool, pRequest);
|
||||
|
||||
|
@ -72,7 +60,7 @@ static int32_t registerRequest(SRequestObj *pRequest, STscObj* pTscObj) {
|
|||
static void deregisterRequest(SRequestObj *pRequest) {
|
||||
assert(pRequest != NULL);
|
||||
|
||||
STscObj * pTscObj = pRequest->pTscObj;
|
||||
STscObj *pTscObj = pRequest->pTscObj;
|
||||
SAppClusterSummary *pActivity = &pTscObj->pAppInfo->summary;
|
||||
|
||||
int32_t currentInst = atomic_sub_fetch_64((int64_t *)&pActivity->currentRequests, 1);
|
||||
|
@ -97,7 +85,8 @@ void closeTransporter(SAppInstInfo *pAppInfo) {
|
|||
|
||||
static bool clientRpcRfp(int32_t code, tmsg_t msgType) {
|
||||
if (NEED_REDIRECT_ERROR(code)) {
|
||||
if (msgType == TDMT_SCH_QUERY || msgType == TDMT_SCH_MERGE_QUERY || msgType == TDMT_SCH_FETCH || msgType == TDMT_SCH_MERGE_FETCH) {
|
||||
if (msgType == TDMT_SCH_QUERY || msgType == TDMT_SCH_MERGE_QUERY || msgType == TDMT_SCH_FETCH ||
|
||||
msgType == TDMT_SCH_MERGE_FETCH) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
|
@ -251,7 +240,7 @@ void *createRequest(uint64_t connId, int32_t type) {
|
|||
return NULL;
|
||||
}
|
||||
|
||||
STscObj* pTscObj = acquireTscObj(connId);
|
||||
STscObj *pTscObj = acquireTscObj(connId);
|
||||
if (pTscObj == NULL) {
|
||||
terrno = TSDB_CODE_TSC_DISCONNECTED;
|
||||
return NULL;
|
||||
|
@ -348,7 +337,6 @@ void taos_init_imp(void) {
|
|||
// In the APIs of other program language, taos_cleanup is not available yet.
|
||||
// So, to make sure taos_cleanup will be invoked to clean up the allocated resource to suppress the valgrind warning.
|
||||
atexit(taos_cleanup);
|
||||
initTscQhandle();
|
||||
errno = TSDB_CODE_SUCCESS;
|
||||
taosSeedRand(taosGetTimestampSec());
|
||||
|
||||
|
@ -407,7 +395,7 @@ int taos_options_imp(TSDB_OPTION option, const char *str) {
|
|||
return 0;
|
||||
}
|
||||
|
||||
SConfig * pCfg = taosGetCfg();
|
||||
SConfig *pCfg = taosGetCfg();
|
||||
SConfigItem *pItem = NULL;
|
||||
|
||||
switch (option) {
|
||||
|
|
|
@ -153,7 +153,7 @@ int32_t buildRequest(uint64_t connId, const char* sql, int sqlLen, void* param,
|
|||
*pRequest = createRequest(connId, TSDB_SQL_SELECT);
|
||||
if (*pRequest == NULL) {
|
||||
tscError("failed to malloc sqlObj, %s", sql);
|
||||
return TSDB_CODE_TSC_OUT_OF_MEMORY;
|
||||
return terrno;
|
||||
}
|
||||
|
||||
(*pRequest)->sqlstr = taosMemoryMalloc(sqlLen + 1);
|
||||
|
@ -933,6 +933,8 @@ SRequestObj* launchQuery(uint64_t connId, const char* sql, int sqlLen, bool vali
|
|||
void launchAsyncQuery(SRequestObj* pRequest, SQuery* pQuery, SMetaData* pResultMeta) {
|
||||
int32_t code = 0;
|
||||
|
||||
pRequest->body.execMode = pQuery->execMode;
|
||||
|
||||
switch (pQuery->execMode) {
|
||||
case QUERY_EXEC_MODE_LOCAL:
|
||||
asyncExecLocalCmd(pRequest, pQuery);
|
||||
|
@ -1149,7 +1151,6 @@ STscObj* taosConnectImpl(const char* user, const char* auth, const char* db, __t
|
|||
SRequestObj* pRequest = createRequest(pTscObj->id, TDMT_MND_CONNECT);
|
||||
if (pRequest == NULL) {
|
||||
destroyTscObj(pTscObj);
|
||||
terrno = TSDB_CODE_TSC_OUT_OF_MEMORY;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
@ -1274,8 +1275,8 @@ typedef struct SchedArg {
|
|||
SEpSet* pEpset;
|
||||
} SchedArg;
|
||||
|
||||
void doProcessMsgFromServer(SSchedMsg* schedMsg) {
|
||||
SchedArg* arg = (SchedArg*)schedMsg->ahandle;
|
||||
int32_t doProcessMsgFromServer(void* param) {
|
||||
SchedArg* arg = (SchedArg*)param;
|
||||
SRpcMsg* pMsg = &arg->msg;
|
||||
SEpSet* pEpSet = arg->pEpset;
|
||||
|
||||
|
@ -1328,11 +1329,10 @@ void doProcessMsgFromServer(SSchedMsg* schedMsg) {
|
|||
rpcFreeCont(pMsg->pCont);
|
||||
destroySendMsgInfo(pSendInfo);
|
||||
taosMemoryFree(arg);
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
void processMsgFromServer(void* parent, SRpcMsg* pMsg, SEpSet* pEpSet) {
|
||||
SSchedMsg schedMsg = {0};
|
||||
|
||||
SEpSet* tEpSet = NULL;
|
||||
if (pEpSet != NULL) {
|
||||
tEpSet = taosMemoryCalloc(1, sizeof(SEpSet));
|
||||
|
@ -1343,9 +1343,7 @@ void processMsgFromServer(void* parent, SRpcMsg* pMsg, SEpSet* pEpSet) {
|
|||
arg->msg = *pMsg;
|
||||
arg->pEpset = tEpSet;
|
||||
|
||||
schedMsg.fp = doProcessMsgFromServer;
|
||||
schedMsg.ahandle = arg;
|
||||
taosScheduleTask(tscQhandle, &schedMsg);
|
||||
taosAsyncExec(doProcessMsgFromServer, arg, NULL);
|
||||
}
|
||||
|
||||
TAOS* taos_connect_auth(const char* ip, const char* user, const char* auth, const char* db, uint16_t port) {
|
||||
|
|
|
@ -49,7 +49,7 @@ int taos_options(TSDB_OPTION option, const void *arg, ...) {
|
|||
}
|
||||
// this function may be called by user or system, or by both simultaneously.
|
||||
void taos_cleanup(void) {
|
||||
tscInfo("start to cleanup client environment");
|
||||
tscDebug("start to cleanup client environment");
|
||||
if (atomic_val_compare_exchange_32(&sentinel, TSC_VAR_NOT_RELEASE, TSC_VAR_RELEASED) != TSC_VAR_NOT_RELEASE) {
|
||||
return;
|
||||
}
|
||||
|
@ -58,7 +58,10 @@ void taos_cleanup(void) {
|
|||
clientReqRefPool = -1;
|
||||
taosCloseRef(id);
|
||||
|
||||
cleanupTaskQueue();
|
||||
hbMgrCleanUp();
|
||||
|
||||
catalogDestroy();
|
||||
schedulerDestroy();
|
||||
|
||||
fmFuncMgtDestroy();
|
||||
qCleanupKeywordsTable();
|
||||
|
@ -67,13 +70,11 @@ void taos_cleanup(void) {
|
|||
clientConnRefPool = -1;
|
||||
taosCloseRef(id);
|
||||
|
||||
hbMgrCleanUp();
|
||||
|
||||
catalogDestroy();
|
||||
schedulerDestroy();
|
||||
|
||||
cleanupTscQhandle();
|
||||
rpcCleanup();
|
||||
tscDebug("rpc cleanup");
|
||||
|
||||
cleanupTaskQueue();
|
||||
|
||||
tscInfo("all local resources released");
|
||||
taosCleanupCfg();
|
||||
taosCloseLog();
|
||||
|
@ -242,7 +243,7 @@ TAOS_ROW taos_fetch_row(TAOS_RES *res) {
|
|||
#endif
|
||||
|
||||
} else if (TD_RES_TMQ(res)) {
|
||||
SMqRspObj * msg = ((SMqRspObj *)res);
|
||||
SMqRspObj *msg = ((SMqRspObj *)res);
|
||||
SReqResultInfo *pResultInfo;
|
||||
if (msg->resIter == -1) {
|
||||
pResultInfo = tmqGetNextResInfo(res, true);
|
||||
|
@ -418,7 +419,7 @@ int taos_affected_rows(TAOS_RES *res) {
|
|||
return 0;
|
||||
}
|
||||
|
||||
SRequestObj * pRequest = (SRequestObj *)res;
|
||||
SRequestObj *pRequest = (SRequestObj *)res;
|
||||
SReqResultInfo *pResInfo = &pRequest->body.resInfo;
|
||||
return pResInfo->numOfRows;
|
||||
}
|
||||
|
@ -601,7 +602,7 @@ int *taos_get_column_data_offset(TAOS_RES *res, int columnIndex) {
|
|||
}
|
||||
|
||||
SReqResultInfo *pResInfo = tscGetCurResInfo(res);
|
||||
TAOS_FIELD * pField = &pResInfo->userFields[columnIndex];
|
||||
TAOS_FIELD *pField = &pResInfo->userFields[columnIndex];
|
||||
if (!IS_VAR_DATA_TYPE(pField->type)) {
|
||||
return 0;
|
||||
}
|
||||
|
@ -645,8 +646,8 @@ const char *taos_get_server_info(TAOS *taos) {
|
|||
typedef struct SqlParseWrapper {
|
||||
SParseContext *pCtx;
|
||||
SCatalogReq catalogReq;
|
||||
SRequestObj * pRequest;
|
||||
SQuery * pQuery;
|
||||
SRequestObj *pRequest;
|
||||
SQuery *pQuery;
|
||||
} SqlParseWrapper;
|
||||
|
||||
static void destorySqlParseWrapper(SqlParseWrapper *pWrapper) {
|
||||
|
@ -665,8 +666,8 @@ static void destorySqlParseWrapper(SqlParseWrapper *pWrapper) {
|
|||
|
||||
void retrieveMetaCallback(SMetaData *pResultMeta, void *param, int32_t code) {
|
||||
SqlParseWrapper *pWrapper = (SqlParseWrapper *)param;
|
||||
SQuery * pQuery = pWrapper->pQuery;
|
||||
SRequestObj * pRequest = pWrapper->pRequest;
|
||||
SQuery *pQuery = pWrapper->pQuery;
|
||||
SRequestObj *pRequest = pWrapper->pRequest;
|
||||
|
||||
if (code == TSDB_CODE_SUCCESS) {
|
||||
code = qAnalyseSqlSemantic(pWrapper->pCtx, &pWrapper->catalogReq, pResultMeta, pQuery);
|
||||
|
@ -684,7 +685,8 @@ void retrieveMetaCallback(SMetaData *pResultMeta, void *param, int32_t code) {
|
|||
|
||||
destorySqlParseWrapper(pWrapper);
|
||||
|
||||
tscDebug("0x%"PRIx64" analysis semantics completed, start async query, reqId:0x%"PRIx64, pRequest->self, pRequest->requestId);
|
||||
tscDebug("0x%" PRIx64 " analysis semantics completed, start async query, reqId:0x%" PRIx64, pRequest->self,
|
||||
pRequest->requestId);
|
||||
launchAsyncQuery(pRequest, pQuery, pResultMeta);
|
||||
} else {
|
||||
destorySqlParseWrapper(pWrapper);
|
||||
|
@ -705,7 +707,7 @@ void retrieveMetaCallback(SMetaData *pResultMeta, void *param, int32_t code) {
|
|||
}
|
||||
|
||||
void taos_query_a(TAOS *taos, const char *sql, __taos_async_fn_t fp, void *param) {
|
||||
int64_t connId = *(int64_t*)taos;
|
||||
int64_t connId = *(int64_t *)taos;
|
||||
taosAsyncQueryImpl(connId, sql, fp, param, false);
|
||||
}
|
||||
|
||||
|
@ -739,7 +741,7 @@ int32_t createParseContext(const SRequestObj *pRequest, SParseContext **pCxt) {
|
|||
|
||||
void doAsyncQuery(SRequestObj *pRequest, bool updateMetaForce) {
|
||||
SParseContext *pCxt = NULL;
|
||||
STscObj * pTscObj = pRequest->pTscObj;
|
||||
STscObj *pTscObj = pRequest->pTscObj;
|
||||
int32_t code = 0;
|
||||
|
||||
if (pRequest->retry++ > REQUEST_TOTAL_EXEC_TIMES) {
|
||||
|
@ -852,31 +854,28 @@ void taos_fetch_rows_a(TAOS_RES *res, __taos_async_fn_t fp, void *param) {
|
|||
}
|
||||
|
||||
// all data has returned to App already, no need to try again
|
||||
if (pResultInfo->completed && (pRequest->body.queryJob != 0)) {
|
||||
pResultInfo->numOfRows = 0;
|
||||
if (pResultInfo->completed) {
|
||||
// it is a local executed query, no need to do async fetch
|
||||
if (QUERY_EXEC_MODE_LOCAL == pRequest->body.execMode) {
|
||||
ASSERT(pResultInfo->numOfRows >= 0);
|
||||
if (pResultInfo->localResultFetched) {
|
||||
pResultInfo->numOfRows = 0;
|
||||
pResultInfo->current = 0;
|
||||
} else {
|
||||
pResultInfo->localResultFetched = true;
|
||||
}
|
||||
} else {
|
||||
pResultInfo->numOfRows = 0;
|
||||
}
|
||||
|
||||
pRequest->body.fetchFp(param, pRequest, pResultInfo->numOfRows);
|
||||
return;
|
||||
}
|
||||
|
||||
// it is a local executed query, no need to do async fetch
|
||||
if (pRequest->body.queryJob == 0) {
|
||||
ASSERT(pResultInfo->completed && pResultInfo->numOfRows >= 0);
|
||||
if (pResultInfo->localResultFetched) {
|
||||
pResultInfo->numOfRows = 0;
|
||||
pResultInfo->current = 0;
|
||||
pRequest->body.fetchFp(param, pRequest, pResultInfo->numOfRows);
|
||||
} else {
|
||||
pResultInfo->localResultFetched = true;
|
||||
pRequest->body.fetchFp(param, pRequest, pResultInfo->numOfRows);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
SSchedulerReq req = {
|
||||
.syncReq = false,
|
||||
.fetchFp = fetchCallback,
|
||||
.cbParam = pRequest,
|
||||
.syncReq = false,
|
||||
.fetchFp = fetchCallback,
|
||||
.cbParam = pRequest,
|
||||
};
|
||||
|
||||
schedulerFetchRows(pRequest->body.queryJob, &req);
|
||||
|
@ -886,7 +885,7 @@ void taos_fetch_raw_block_a(TAOS_RES *res, __taos_async_fn_t fp, void *param) {
|
|||
ASSERT(res != NULL && fp != NULL);
|
||||
ASSERT(TD_RES_QUERY(res));
|
||||
|
||||
SRequestObj *pRequest = res;
|
||||
SRequestObj *pRequest = res;
|
||||
SReqResultInfo *pResultInfo = &pRequest->body.resInfo;
|
||||
|
||||
// set the current block is all consumed
|
||||
|
@ -928,7 +927,7 @@ int taos_load_table_info(TAOS *taos, const char *tableNameList) {
|
|||
int64_t connId = *(int64_t *)taos;
|
||||
const int32_t MAX_TABLE_NAME_LENGTH = 12 * 1024 * 1024; // 12MB list
|
||||
int32_t code = 0;
|
||||
SRequestObj * pRequest = NULL;
|
||||
SRequestObj *pRequest = NULL;
|
||||
SCatalogReq catalogReq = {0};
|
||||
|
||||
if (NULL == tableNameList) {
|
||||
|
@ -950,7 +949,7 @@ int taos_load_table_info(TAOS *taos, const char *tableNameList) {
|
|||
goto _return;
|
||||
}
|
||||
|
||||
STscObj* pTscObj = pRequest->pTscObj;
|
||||
STscObj *pTscObj = pRequest->pTscObj;
|
||||
code = transferTableNameList(tableNameList, pTscObj->acctId, pTscObj->db, &catalogReq.pTableMeta);
|
||||
if (code) {
|
||||
goto _return;
|
||||
|
@ -972,7 +971,7 @@ int taos_load_table_info(TAOS *taos, const char *tableNameList) {
|
|||
goto _return;
|
||||
}
|
||||
|
||||
SSyncQueryParam* pParam = pRequest->body.param;
|
||||
SSyncQueryParam *pParam = pRequest->body.param;
|
||||
tsem_wait(&pParam->sem);
|
||||
|
||||
_return:
|
||||
|
|
|
@ -179,7 +179,6 @@ int32_t processUseDbRsp(void* param, SDataBuf* pMsg, int32_t code) {
|
|||
if (code != 0) {
|
||||
terrno = code;
|
||||
if (output.dbVgroup) taosHashCleanup(output.dbVgroup->vgHash);
|
||||
taosMemoryFreeClear(output.dbVgroup);
|
||||
|
||||
tscError("0x%" PRIx64 " failed to build use db output since %s", pRequest->requestId, terrstr());
|
||||
} else if (output.dbVgroup && output.dbVgroup->vgHash) {
|
||||
|
@ -189,12 +188,14 @@ int32_t processUseDbRsp(void* param, SDataBuf* pMsg, int32_t code) {
|
|||
if (code1 != TSDB_CODE_SUCCESS) {
|
||||
tscWarn("catalogGetHandle failed, clusterId:%" PRIx64 ", error:%s", pRequest->pTscObj->pAppInfo->clusterId,
|
||||
tstrerror(code1));
|
||||
taosMemoryFreeClear(output.dbVgroup);
|
||||
} else {
|
||||
catalogUpdateDBVgInfo(pCatalog, output.db, output.dbId, output.dbVgroup);
|
||||
output.dbVgroup = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
taosMemoryFreeClear(output.dbVgroup);
|
||||
|
||||
tFreeSUsedbRsp(&usedbRsp);
|
||||
|
||||
char db[TSDB_DB_NAME_LEN] = {0};
|
||||
|
|
|
@ -1149,11 +1149,10 @@ int32_t tmqPollCb(void* param, SDataBuf* pMsg, int32_t code) {
|
|||
tDecoderInit(&decoder, POINTER_SHIFT(pMsg->pData, sizeof(SMqRspHead)), pMsg->len - sizeof(SMqRspHead));
|
||||
tDecodeSMqDataRsp(&decoder, &pRspWrapper->dataRsp);
|
||||
memcpy(&pRspWrapper->dataRsp, pMsg->pData, sizeof(SMqRspHead));
|
||||
/*tDecodeSMqDataBlkRsp(POINTER_SHIFT(pMsg->pData, sizeof(SMqRspHead)), &pRspWrapper->dataRsp);*/
|
||||
} else {
|
||||
ASSERT(rspType == TMQ_MSG_TYPE__POLL_META_RSP);
|
||||
memcpy(&pRspWrapper->metaRsp, pMsg->pData, sizeof(SMqRspHead));
|
||||
tDecodeSMqMetaRsp(POINTER_SHIFT(pMsg->pData, sizeof(SMqRspHead)), &pRspWrapper->metaRsp);
|
||||
memcpy(&pRspWrapper->metaRsp, pMsg->pData, sizeof(SMqRspHead));
|
||||
}
|
||||
|
||||
taosMemoryFree(pMsg->pData);
|
||||
|
@ -2427,15 +2426,15 @@ static void destroyCreateTbReqBatch(void* data) {
|
|||
taosArrayDestroy(pTbBatch->req.pArray);
|
||||
}
|
||||
|
||||
static int32_t taosCreateTable(TAOS *taos, void *meta, int32_t metaLen){
|
||||
SVCreateTbBatchReq req = {0};
|
||||
SDecoder coder = {0};
|
||||
int32_t code = TSDB_CODE_SUCCESS;
|
||||
SRequestObj *pRequest = NULL;
|
||||
SQuery *pQuery = NULL;
|
||||
SHashObj *pVgroupHashmap = NULL;
|
||||
static int32_t taosCreateTable(TAOS* taos, void* meta, int32_t metaLen) {
|
||||
SVCreateTbBatchReq req = {0};
|
||||
SDecoder coder = {0};
|
||||
int32_t code = TSDB_CODE_SUCCESS;
|
||||
SRequestObj* pRequest = NULL;
|
||||
SQuery* pQuery = NULL;
|
||||
SHashObj* pVgroupHashmap = NULL;
|
||||
|
||||
code = buildRequest(*(int64_t*) taos, "", 0, NULL, false, &pRequest);
|
||||
code = buildRequest(*(int64_t*)taos, "", 0, NULL, false, &pRequest);
|
||||
if (code != TSDB_CODE_SUCCESS) {
|
||||
goto end;
|
||||
}
|
||||
|
@ -2455,8 +2454,8 @@ static int32_t taosCreateTable(TAOS *taos, void *meta, int32_t metaLen){
|
|||
|
||||
STscObj* pTscObj = pRequest->pTscObj;
|
||||
|
||||
SVCreateTbReq *pCreateReq = NULL;
|
||||
SCatalog* pCatalog = NULL;
|
||||
SVCreateTbReq* pCreateReq = NULL;
|
||||
SCatalog* pCatalog = NULL;
|
||||
code = catalogGetHandle(pTscObj->pAppInfo->clusterId, &pCatalog);
|
||||
if (code != TSDB_CODE_SUCCESS) {
|
||||
goto end;
|
||||
|
@ -2540,13 +2539,13 @@ static void destroyDropTbReqBatch(void* data) {
|
|||
taosArrayDestroy(pTbBatch->req.pArray);
|
||||
}
|
||||
|
||||
static int32_t taosDropTable(TAOS *taos, void *meta, int32_t metaLen){
|
||||
SVDropTbBatchReq req = {0};
|
||||
SDecoder coder = {0};
|
||||
int32_t code = TSDB_CODE_SUCCESS;
|
||||
SRequestObj *pRequest = NULL;
|
||||
SQuery *pQuery = NULL;
|
||||
SHashObj *pVgroupHashmap = NULL;
|
||||
static int32_t taosDropTable(TAOS* taos, void* meta, int32_t metaLen) {
|
||||
SVDropTbBatchReq req = {0};
|
||||
SDecoder coder = {0};
|
||||
int32_t code = TSDB_CODE_SUCCESS;
|
||||
SRequestObj* pRequest = NULL;
|
||||
SQuery* pQuery = NULL;
|
||||
SHashObj* pVgroupHashmap = NULL;
|
||||
|
||||
code = buildRequest(*(int64_t*)taos, "", 0, NULL, false, &pRequest);
|
||||
if (code != TSDB_CODE_SUCCESS) {
|
||||
|
@ -2568,8 +2567,8 @@ static int32_t taosDropTable(TAOS *taos, void *meta, int32_t metaLen){
|
|||
|
||||
STscObj* pTscObj = pRequest->pTscObj;
|
||||
|
||||
SVDropTbReq *pDropReq = NULL;
|
||||
SCatalog *pCatalog = NULL;
|
||||
SVDropTbReq* pDropReq = NULL;
|
||||
SCatalog* pCatalog = NULL;
|
||||
code = catalogGetHandle(pTscObj->pAppInfo->clusterId, &pCatalog);
|
||||
if (code != TSDB_CODE_SUCCESS) {
|
||||
goto end;
|
||||
|
@ -2640,17 +2639,16 @@ end:
|
|||
return code;
|
||||
}
|
||||
|
||||
static int32_t taosAlterTable(TAOS *taos, void *meta, int32_t metaLen){
|
||||
SVAlterTbReq req = {0};
|
||||
SDecoder coder = {0};
|
||||
int32_t code = TSDB_CODE_SUCCESS;
|
||||
SRequestObj *pRequest = NULL;
|
||||
SQuery *pQuery = NULL;
|
||||
SArray *pArray = NULL;
|
||||
SVgDataBlocks *pVgData = NULL;
|
||||
static int32_t taosAlterTable(TAOS* taos, void* meta, int32_t metaLen) {
|
||||
SVAlterTbReq req = {0};
|
||||
SDecoder coder = {0};
|
||||
int32_t code = TSDB_CODE_SUCCESS;
|
||||
SRequestObj* pRequest = NULL;
|
||||
SQuery* pQuery = NULL;
|
||||
SArray* pArray = NULL;
|
||||
SVgDataBlocks* pVgData = NULL;
|
||||
|
||||
|
||||
code = buildRequest(*(int64_t*) taos, "", 0, NULL, false, &pRequest);
|
||||
code = buildRequest(*(int64_t*)taos, "", 0, NULL, false, &pRequest);
|
||||
if (code != TSDB_CODE_SUCCESS) {
|
||||
goto end;
|
||||
}
|
||||
|
|
|
@ -320,7 +320,9 @@ int32_t colDataAssign(SColumnInfoData* pColumnInfoData, const SColumnInfoData* p
|
|||
memcpy(pColumnInfoData->pData, pSource->pData, pSource->varmeta.length);
|
||||
} else {
|
||||
memcpy(pColumnInfoData->nullbitmap, pSource->nullbitmap, BitmapLen(numOfRows));
|
||||
memcpy(pColumnInfoData->pData, pSource->pData, pSource->info.bytes * numOfRows);
|
||||
if (pSource->pData) {
|
||||
memcpy(pColumnInfoData->pData, pSource->pData, pSource->info.bytes * numOfRows);
|
||||
}
|
||||
}
|
||||
|
||||
pColumnInfoData->hasNull = pSource->hasNull;
|
||||
|
@ -1172,8 +1174,6 @@ int32_t colInfoDataEnsureCapacity(SColumnInfoData* pColumn, uint32_t numOfRows)
|
|||
|
||||
int32_t blockDataEnsureCapacity(SSDataBlock* pDataBlock, uint32_t numOfRows) {
|
||||
int32_t code = 0;
|
||||
// ASSERT(numOfRows > 0);
|
||||
|
||||
if (numOfRows == 0) {
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
@ -1736,56 +1736,57 @@ char* dumpBlockData(SSDataBlock* pDataBlock, const char* flag, char** pDataBuf)
|
|||
int32_t colNum = taosArrayGetSize(pDataBlock->pDataBlock);
|
||||
int32_t rows = pDataBlock->info.rows;
|
||||
int32_t len = 0;
|
||||
len += snprintf(dumpBuf + len, size - len, "\n%s |block type %d |child id %d|group id:%" PRIu64 "|\n", flag,
|
||||
(int32_t)pDataBlock->info.type, pDataBlock->info.childId, pDataBlock->info.groupId);
|
||||
len += snprintf(dumpBuf + len, size - len, "\n%s |block type %d |child id %d|group id:%" PRIu64 "| uid:%ld\n", flag,
|
||||
(int32_t)pDataBlock->info.type, pDataBlock->info.childId, pDataBlock->info.groupId,
|
||||
pDataBlock->info.uid);
|
||||
if (len >= size - 1) return dumpBuf;
|
||||
|
||||
for (int32_t j = 0; j < rows; j++) {
|
||||
len += snprintf(dumpBuf + len, size - len, "%s |", flag);
|
||||
if (len >= size -1) return dumpBuf;
|
||||
if (len >= size - 1) return dumpBuf;
|
||||
|
||||
for (int32_t k = 0; k < colNum; k++) {
|
||||
SColumnInfoData* pColInfoData = taosArrayGet(pDataBlock->pDataBlock, k);
|
||||
void* var = POINTER_SHIFT(pColInfoData->pData, j * pColInfoData->info.bytes);
|
||||
if (colDataIsNull(pColInfoData, rows, j, NULL) || !pColInfoData->pData) {
|
||||
len += snprintf(dumpBuf + len, size - len, " %15s |", "NULL");
|
||||
if (len >= size -1) return dumpBuf;
|
||||
if (len >= size - 1) return dumpBuf;
|
||||
continue;
|
||||
}
|
||||
switch (pColInfoData->info.type) {
|
||||
case TSDB_DATA_TYPE_TIMESTAMP:
|
||||
formatTimestamp(pBuf, *(uint64_t*)var, TSDB_TIME_PRECISION_MILLI);
|
||||
len += snprintf(dumpBuf + len, size - len, " %25s |", pBuf);
|
||||
if (len >= size -1) return dumpBuf;
|
||||
if (len >= size - 1) return dumpBuf;
|
||||
break;
|
||||
case TSDB_DATA_TYPE_INT:
|
||||
len += snprintf(dumpBuf + len, size - len, " %15d |", *(int32_t*)var);
|
||||
if (len >= size -1) return dumpBuf;
|
||||
if (len >= size - 1) return dumpBuf;
|
||||
break;
|
||||
case TSDB_DATA_TYPE_UINT:
|
||||
len += snprintf(dumpBuf + len, size - len, " %15u |", *(uint32_t*)var);
|
||||
if (len >= size -1) return dumpBuf;
|
||||
if (len >= size - 1) return dumpBuf;
|
||||
break;
|
||||
case TSDB_DATA_TYPE_BIGINT:
|
||||
len += snprintf(dumpBuf + len, size - len, " %15ld |", *(int64_t*)var);
|
||||
if (len >= size -1) return dumpBuf;
|
||||
if (len >= size - 1) return dumpBuf;
|
||||
break;
|
||||
case TSDB_DATA_TYPE_UBIGINT:
|
||||
len += snprintf(dumpBuf + len, size - len, " %15lu |", *(uint64_t*)var);
|
||||
if (len >= size -1) return dumpBuf;
|
||||
if (len >= size - 1) return dumpBuf;
|
||||
break;
|
||||
case TSDB_DATA_TYPE_FLOAT:
|
||||
len += snprintf(dumpBuf + len, size - len, " %15f |", *(float*)var);
|
||||
if (len >= size -1) return dumpBuf;
|
||||
if (len >= size - 1) return dumpBuf;
|
||||
break;
|
||||
case TSDB_DATA_TYPE_DOUBLE:
|
||||
len += snprintf(dumpBuf + len, size - len, " %15lf |", *(double*)var);
|
||||
if (len >= size -1) return dumpBuf;
|
||||
if (len >= size - 1) return dumpBuf;
|
||||
break;
|
||||
}
|
||||
}
|
||||
len += snprintf(dumpBuf + len, size - len, "\n");
|
||||
if (len >= size -1) return dumpBuf;
|
||||
if (len >= size - 1) return dumpBuf;
|
||||
}
|
||||
len += snprintf(dumpBuf + len, size - len, "%s |end\n", flag);
|
||||
return dumpBuf;
|
||||
|
|
|
@ -175,7 +175,8 @@ static void setBitMap(uint8_t *pb, uint8_t v, int32_t idx, uint8_t flags) {
|
|||
} while (0)
|
||||
|
||||
int32_t tTSRowNew(STSRowBuilder *pBuilder, SArray *pArray, STSchema *pTSchema, STSRow2 **ppRow) {
|
||||
int32_t code = 0;
|
||||
int32_t code = 0;
|
||||
#if 0
|
||||
STColumn *pTColumn;
|
||||
SColVal *pColVal;
|
||||
int32_t nColVal = taosArrayGetSize(pArray);
|
||||
|
@ -462,30 +463,22 @@ int32_t tTSRowNew(STSRowBuilder *pBuilder, SArray *pArray, STSchema *pTSchema, S
|
|||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
_exit:
|
||||
return code;
|
||||
}
|
||||
|
||||
int32_t tTSRowClone(const STSRow2 *pRow, STSRow2 **ppRow) {
|
||||
int32_t code = 0;
|
||||
int32_t rLen;
|
||||
|
||||
(*ppRow) = (STSRow2 *)taosMemoryMalloc(sizeof(**ppRow));
|
||||
TSROW_LEN(pRow, rLen);
|
||||
(*ppRow) = (STSRow2 *)taosMemoryMalloc(rLen);
|
||||
if (*ppRow == NULL) {
|
||||
code = TSDB_CODE_OUT_OF_MEMORY;
|
||||
goto _exit;
|
||||
}
|
||||
**ppRow = *pRow;
|
||||
(*ppRow)->pData = NULL;
|
||||
|
||||
if (pRow->nData) {
|
||||
(*ppRow)->pData = taosMemoryMalloc(pRow->nData);
|
||||
if ((*ppRow)->pData == NULL) {
|
||||
taosMemoryFree(*ppRow);
|
||||
code = TSDB_CODE_OUT_OF_MEMORY;
|
||||
goto _exit;
|
||||
}
|
||||
memcpy((*ppRow)->pData, pRow->pData, pRow->nData);
|
||||
}
|
||||
memcpy(*ppRow, pRow, rLen);
|
||||
|
||||
_exit:
|
||||
return code;
|
||||
|
@ -493,12 +486,12 @@ _exit:
|
|||
|
||||
void tTSRowFree(STSRow2 *pRow) {
|
||||
if (pRow) {
|
||||
if (pRow->pData) taosMemoryFree(pRow->pData);
|
||||
taosMemoryFree(pRow);
|
||||
}
|
||||
}
|
||||
|
||||
void tTSRowGet(STSRow2 *pRow, STSchema *pTSchema, int32_t iCol, SColVal *pColVal) {
|
||||
#if 0
|
||||
uint8_t isTuple = ((pRow->flags & 0xf0) == 0) ? 1 : 0;
|
||||
STColumn *pTColumn = &pTSchema->columns[iCol];
|
||||
uint8_t flags = pRow->flags & (uint8_t)0xf;
|
||||
|
@ -643,10 +636,12 @@ _return_null:
|
|||
_return_value:
|
||||
*pColVal = COL_VAL_VALUE(pTColumn->colId, pTColumn->type, value);
|
||||
return;
|
||||
#endif
|
||||
}
|
||||
|
||||
int32_t tTSRowToArray(STSRow2 *pRow, STSchema *pTSchema, SArray **ppArray) {
|
||||
int32_t code = 0;
|
||||
#if 0
|
||||
SColVal cv;
|
||||
|
||||
(*ppArray) = taosArrayInit(pTSchema->numOfCols, sizeof(SColVal));
|
||||
|
@ -660,52 +655,27 @@ int32_t tTSRowToArray(STSRow2 *pRow, STSchema *pTSchema, SArray **ppArray) {
|
|||
taosArrayPush(*ppArray, &cv);
|
||||
}
|
||||
|
||||
#endif
|
||||
_exit:
|
||||
return code;
|
||||
}
|
||||
|
||||
int32_t tPutTSRow(uint8_t *p, STSRow2 *pRow) {
|
||||
int32_t n = 0;
|
||||
int32_t n;
|
||||
|
||||
n += tPutI64(p ? p + n : p, pRow->ts);
|
||||
n += tPutI8(p ? p + n : p, pRow->flags);
|
||||
n += tPutI32v(p ? p + n : p, pRow->sver);
|
||||
|
||||
ASSERT(pRow->flags & 0xf);
|
||||
|
||||
switch (pRow->flags & 0xf) {
|
||||
case TSROW_HAS_NONE:
|
||||
case TSROW_HAS_NULL:
|
||||
ASSERT(pRow->nData == 0);
|
||||
ASSERT(pRow->pData == NULL);
|
||||
break;
|
||||
default:
|
||||
ASSERT(pRow->nData && pRow->pData);
|
||||
n += tPutBinary(p ? p + n : p, pRow->pData, pRow->nData);
|
||||
break;
|
||||
TSROW_LEN(pRow, n);
|
||||
if (p) {
|
||||
memcpy(p, pRow, n);
|
||||
}
|
||||
|
||||
return n;
|
||||
}
|
||||
|
||||
int32_t tGetTSRow(uint8_t *p, STSRow2 *pRow) {
|
||||
int32_t n = 0;
|
||||
int32_t tGetTSRow(uint8_t *p, STSRow2 **ppRow) {
|
||||
int32_t n;
|
||||
|
||||
n += tGetI64(p + n, &pRow->ts);
|
||||
n += tGetI8(p + n, &pRow->flags);
|
||||
n += tGetI32v(p + n, &pRow->sver);
|
||||
|
||||
ASSERT(pRow->flags);
|
||||
switch (pRow->flags & 0xf) {
|
||||
case TSROW_HAS_NONE:
|
||||
case TSROW_HAS_NULL:
|
||||
pRow->nData = 0;
|
||||
pRow->pData = NULL;
|
||||
break;
|
||||
default:
|
||||
n += tGetBinary(p + n, &pRow->pData, &pRow->nData);
|
||||
break;
|
||||
}
|
||||
*ppRow = (STSRow2 *)p;
|
||||
TSROW_LEN(*ppRow, n);
|
||||
|
||||
return n;
|
||||
}
|
||||
|
@ -904,15 +874,13 @@ static int32_t tGetTagVal(uint8_t *p, STagVal *pTagVal, int8_t isJson) {
|
|||
return n;
|
||||
}
|
||||
|
||||
bool tTagIsJson(const void *pTag){
|
||||
return (((const STag *)pTag)->flags & TD_TAG_JSON);
|
||||
}
|
||||
bool tTagIsJson(const void *pTag) { return (((const STag *)pTag)->flags & TD_TAG_JSON); }
|
||||
|
||||
bool tTagIsJsonNull(void *data){
|
||||
STag *pTag = (STag*)data;
|
||||
int8_t isJson = tTagIsJson(pTag);
|
||||
if(!isJson) return false;
|
||||
return ((STag*)data)->nTag == 0;
|
||||
bool tTagIsJsonNull(void *data) {
|
||||
STag *pTag = (STag *)data;
|
||||
int8_t isJson = tTagIsJson(pTag);
|
||||
if (!isJson) return false;
|
||||
return ((STag *)data)->nTag == 0;
|
||||
}
|
||||
|
||||
int32_t tTagNew(SArray *pArray, int32_t version, int8_t isJson, STag **ppTag) {
|
||||
|
@ -1097,112 +1065,6 @@ _err:
|
|||
}
|
||||
|
||||
#if 1 // ===================================================================================================================
|
||||
static void dataColSetNEleNull(SDataCol *pCol, int nEle);
|
||||
int tdAllocMemForCol(SDataCol *pCol, int maxPoints) {
|
||||
int spaceNeeded = pCol->bytes * maxPoints;
|
||||
if (IS_VAR_DATA_TYPE(pCol->type)) {
|
||||
spaceNeeded += sizeof(VarDataOffsetT) * maxPoints;
|
||||
}
|
||||
#ifdef TD_SUPPORT_BITMAP
|
||||
int32_t nBitmapBytes = (int32_t)TD_BITMAP_BYTES(maxPoints);
|
||||
spaceNeeded += (int)nBitmapBytes;
|
||||
// TODO: Currently, the compression of bitmap parts is affiliated to the column data parts, thus allocate 1 more
|
||||
// TYPE_BYTES as to comprise complete TYPE_BYTES. Otherwise, invalid read/write would be triggered.
|
||||
// spaceNeeded += TYPE_BYTES[pCol->type]; // the bitmap part is append as a single part since 2022.04.03, thus
|
||||
// remove the additional space
|
||||
#endif
|
||||
|
||||
if (pCol->spaceSize < spaceNeeded) {
|
||||
void *ptr = taosMemoryRealloc(pCol->pData, spaceNeeded);
|
||||
if (ptr == NULL) {
|
||||
uDebug("malloc failure, size:%" PRId64 " failed, reason:%s", (int64_t)spaceNeeded, strerror(errno));
|
||||
return -1;
|
||||
} else {
|
||||
pCol->pData = ptr;
|
||||
pCol->spaceSize = spaceNeeded;
|
||||
}
|
||||
}
|
||||
#ifdef TD_SUPPORT_BITMAP
|
||||
|
||||
if (IS_VAR_DATA_TYPE(pCol->type)) {
|
||||
pCol->pBitmap = POINTER_SHIFT(pCol->pData, pCol->bytes * maxPoints);
|
||||
pCol->dataOff = POINTER_SHIFT(pCol->pBitmap, nBitmapBytes);
|
||||
} else {
|
||||
pCol->pBitmap = POINTER_SHIFT(pCol->pData, pCol->bytes * maxPoints);
|
||||
}
|
||||
#else
|
||||
if (IS_VAR_DATA_TYPE(pCol->type)) {
|
||||
pCol->dataOff = POINTER_SHIFT(pCol->pData, pCol->bytes * maxPoints);
|
||||
}
|
||||
#endif
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Duplicate the schema and return a new object
|
||||
*/
|
||||
STSchema *tdDupSchema(const STSchema *pSchema) {
|
||||
int tlen = sizeof(STSchema) + sizeof(STColumn) * schemaNCols(pSchema);
|
||||
STSchema *tSchema = (STSchema *)taosMemoryMalloc(tlen);
|
||||
if (tSchema == NULL) return NULL;
|
||||
|
||||
memcpy((void *)tSchema, (void *)pSchema, tlen);
|
||||
|
||||
return tSchema;
|
||||
}
|
||||
|
||||
/**
|
||||
* Encode a schema to dst, and return the next pointer
|
||||
*/
|
||||
int tdEncodeSchema(void **buf, STSchema *pSchema) {
|
||||
int tlen = 0;
|
||||
tlen += taosEncodeFixedI32(buf, schemaVersion(pSchema));
|
||||
tlen += taosEncodeFixedI32(buf, schemaNCols(pSchema));
|
||||
|
||||
for (int i = 0; i < schemaNCols(pSchema); i++) {
|
||||
STColumn *pCol = schemaColAt(pSchema, i);
|
||||
tlen += taosEncodeFixedI8(buf, colType(pCol));
|
||||
tlen += taosEncodeFixedI8(buf, colFlags(pCol));
|
||||
tlen += taosEncodeFixedI16(buf, colColId(pCol));
|
||||
tlen += taosEncodeFixedI16(buf, colBytes(pCol));
|
||||
}
|
||||
|
||||
return tlen;
|
||||
}
|
||||
|
||||
/**
|
||||
* Decode a schema from a binary.
|
||||
*/
|
||||
void *tdDecodeSchema(void *buf, STSchema **pRSchema) {
|
||||
int version = 0;
|
||||
int numOfCols = 0;
|
||||
STSchemaBuilder schemaBuilder;
|
||||
|
||||
buf = taosDecodeFixedI32(buf, &version);
|
||||
buf = taosDecodeFixedI32(buf, &numOfCols);
|
||||
|
||||
if (tdInitTSchemaBuilder(&schemaBuilder, version) < 0) return NULL;
|
||||
|
||||
for (int i = 0; i < numOfCols; i++) {
|
||||
col_type_t type = 0;
|
||||
int8_t flags = 0;
|
||||
col_id_t colId = 0;
|
||||
col_bytes_t bytes = 0;
|
||||
buf = taosDecodeFixedI8(buf, &type);
|
||||
buf = taosDecodeFixedI8(buf, &flags);
|
||||
buf = taosDecodeFixedI16(buf, &colId);
|
||||
buf = taosDecodeFixedI32(buf, &bytes);
|
||||
if (tdAddColToSchema(&schemaBuilder, type, flags, colId, bytes) < 0) {
|
||||
tdDestroyTSchemaBuilder(&schemaBuilder);
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
*pRSchema = tdGetSchemaFromBuilder(&schemaBuilder);
|
||||
tdDestroyTSchemaBuilder(&schemaBuilder);
|
||||
return buf;
|
||||
}
|
||||
|
||||
int tdInitTSchemaBuilder(STSchemaBuilder *pBuilder, schema_ver_t version) {
|
||||
if (pBuilder == NULL) return -1;
|
||||
|
||||
|
@ -1239,22 +1101,22 @@ int32_t tdAddColToSchema(STSchemaBuilder *pBuilder, int8_t type, int8_t flags, c
|
|||
}
|
||||
|
||||
STColumn *pCol = &(pBuilder->columns[pBuilder->nCols]);
|
||||
colSetType(pCol, type);
|
||||
colSetColId(pCol, colId);
|
||||
colSetFlags(pCol, flags);
|
||||
pCol->type = type;
|
||||
pCol->colId = colId;
|
||||
pCol->flags = flags;
|
||||
if (pBuilder->nCols == 0) {
|
||||
colSetOffset(pCol, 0);
|
||||
pCol->offset = 0;
|
||||
} else {
|
||||
STColumn *pTCol = &(pBuilder->columns[pBuilder->nCols - 1]);
|
||||
colSetOffset(pCol, pTCol->offset + TYPE_BYTES[pTCol->type]);
|
||||
pCol->offset = pTCol->offset + TYPE_BYTES[pTCol->type];
|
||||
}
|
||||
|
||||
if (IS_VAR_DATA_TYPE(type)) {
|
||||
colSetBytes(pCol, bytes);
|
||||
pCol->bytes = bytes;
|
||||
pBuilder->tlen += (TYPE_BYTES[type] + bytes);
|
||||
pBuilder->vlen += bytes - sizeof(VarDataLenT);
|
||||
} else {
|
||||
colSetBytes(pCol, TYPE_BYTES[type]);
|
||||
pCol->bytes = TYPE_BYTES[type];
|
||||
pBuilder->tlen += TYPE_BYTES[type];
|
||||
pBuilder->vlen += TYPE_BYTES[type];
|
||||
}
|
||||
|
@ -1275,151 +1137,19 @@ STSchema *tdGetSchemaFromBuilder(STSchemaBuilder *pBuilder) {
|
|||
STSchema *pSchema = (STSchema *)taosMemoryMalloc(tlen);
|
||||
if (pSchema == NULL) return NULL;
|
||||
|
||||
schemaVersion(pSchema) = pBuilder->version;
|
||||
schemaNCols(pSchema) = pBuilder->nCols;
|
||||
schemaTLen(pSchema) = pBuilder->tlen;
|
||||
schemaFLen(pSchema) = pBuilder->flen;
|
||||
schemaVLen(pSchema) = pBuilder->vlen;
|
||||
pSchema->version = pBuilder->version;
|
||||
pSchema->numOfCols = pBuilder->nCols;
|
||||
pSchema->tlen = pBuilder->tlen;
|
||||
pSchema->flen = pBuilder->flen;
|
||||
pSchema->vlen = pBuilder->vlen;
|
||||
|
||||
#ifdef TD_SUPPORT_BITMAP
|
||||
schemaTLen(pSchema) += (int)TD_BITMAP_BYTES(schemaNCols(pSchema));
|
||||
pSchema->tlen += (int)TD_BITMAP_BYTES(pSchema->numOfCols);
|
||||
#endif
|
||||
|
||||
memcpy(schemaColAt(pSchema, 0), pBuilder->columns, sizeof(STColumn) * pBuilder->nCols);
|
||||
memcpy(&pSchema->columns[0], pBuilder->columns, sizeof(STColumn) * pBuilder->nCols);
|
||||
|
||||
return pSchema;
|
||||
}
|
||||
|
||||
void dataColInit(SDataCol *pDataCol, STColumn *pCol, int maxPoints) {
|
||||
pDataCol->type = colType(pCol);
|
||||
pDataCol->colId = colColId(pCol);
|
||||
pDataCol->bytes = colBytes(pCol);
|
||||
pDataCol->offset = colOffset(pCol) + 0; // TD_DATA_ROW_HEAD_SIZE;
|
||||
|
||||
pDataCol->len = 0;
|
||||
}
|
||||
|
||||
static FORCE_INLINE const void *tdGetColDataOfRowUnsafe(SDataCol *pCol, int row) {
|
||||
if (IS_VAR_DATA_TYPE(pCol->type)) {
|
||||
return POINTER_SHIFT(pCol->pData, pCol->dataOff[row]);
|
||||
} else {
|
||||
return POINTER_SHIFT(pCol->pData, TYPE_BYTES[pCol->type] * row);
|
||||
}
|
||||
}
|
||||
|
||||
bool isNEleNull(SDataCol *pCol, int nEle) {
|
||||
if (isAllRowsNull(pCol)) return true;
|
||||
for (int i = 0; i < nEle; ++i) {
|
||||
if (!isNull(tdGetColDataOfRowUnsafe(pCol, i), pCol->type)) return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
void *dataColSetOffset(SDataCol *pCol, int nEle) {
|
||||
ASSERT(((pCol->type == TSDB_DATA_TYPE_BINARY) || (pCol->type == TSDB_DATA_TYPE_NCHAR)));
|
||||
|
||||
void *tptr = pCol->pData;
|
||||
// char *tptr = (char *)(pCol->pData);
|
||||
|
||||
VarDataOffsetT offset = 0;
|
||||
for (int i = 0; i < nEle; ++i) {
|
||||
pCol->dataOff[i] = offset;
|
||||
offset += varDataTLen(tptr);
|
||||
tptr = POINTER_SHIFT(tptr, varDataTLen(tptr));
|
||||
}
|
||||
return POINTER_SHIFT(tptr, varDataTLen(tptr));
|
||||
}
|
||||
|
||||
SDataCols *tdNewDataCols(int maxCols, int maxRows) {
|
||||
SDataCols *pCols = (SDataCols *)taosMemoryCalloc(1, sizeof(SDataCols));
|
||||
if (pCols == NULL) {
|
||||
uDebug("malloc failure, size:%" PRId64 " failed, reason:%s", (int64_t)sizeof(SDataCols), strerror(errno));
|
||||
return NULL;
|
||||
}
|
||||
|
||||
pCols->maxPoints = maxRows;
|
||||
pCols->maxCols = maxCols;
|
||||
pCols->numOfRows = 0;
|
||||
pCols->numOfCols = 0;
|
||||
pCols->bitmapMode = TSDB_BITMODE_DEFAULT;
|
||||
|
||||
if (maxCols > 0) {
|
||||
pCols->cols = (SDataCol *)taosMemoryCalloc(maxCols, sizeof(SDataCol));
|
||||
if (pCols->cols == NULL) {
|
||||
uDebug("malloc failure, size:%" PRId64 " failed, reason:%s", (int64_t)sizeof(SDataCol) * maxCols,
|
||||
strerror(errno));
|
||||
tdFreeDataCols(pCols);
|
||||
return NULL;
|
||||
}
|
||||
#if 0 // no need as calloc used
|
||||
int i;
|
||||
for (i = 0; i < maxCols; i++) {
|
||||
pCols->cols[i].spaceSize = 0;
|
||||
pCols->cols[i].len = 0;
|
||||
pCols->cols[i].pData = NULL;
|
||||
pCols->cols[i].dataOff = NULL;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
return pCols;
|
||||
}
|
||||
|
||||
int tdInitDataCols(SDataCols *pCols, STSchema *pSchema) {
|
||||
int i;
|
||||
int oldMaxCols = pCols->maxCols;
|
||||
if (schemaNCols(pSchema) > oldMaxCols) {
|
||||
pCols->maxCols = schemaNCols(pSchema);
|
||||
void *ptr = (SDataCol *)taosMemoryRealloc(pCols->cols, sizeof(SDataCol) * pCols->maxCols);
|
||||
if (ptr == NULL) return -1;
|
||||
pCols->cols = ptr;
|
||||
for (i = oldMaxCols; i < pCols->maxCols; ++i) {
|
||||
pCols->cols[i].pData = NULL;
|
||||
pCols->cols[i].dataOff = NULL;
|
||||
pCols->cols[i].pBitmap = NULL;
|
||||
pCols->cols[i].spaceSize = 0;
|
||||
}
|
||||
}
|
||||
#if 0
|
||||
tdResetDataCols(pCols); // redundant loop to reset len/blen to 0, already reset in following dataColInit(...)
|
||||
#endif
|
||||
|
||||
pCols->numOfRows = 0;
|
||||
pCols->bitmapMode = TSDB_BITMODE_DEFAULT;
|
||||
pCols->numOfCols = schemaNCols(pSchema);
|
||||
|
||||
for (i = 0; i < schemaNCols(pSchema); ++i) {
|
||||
dataColInit(pCols->cols + i, schemaColAt(pSchema, i), pCols->maxPoints);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
SDataCols *tdFreeDataCols(SDataCols *pCols) {
|
||||
int i;
|
||||
if (pCols) {
|
||||
if (pCols->cols) {
|
||||
int maxCols = pCols->maxCols;
|
||||
for (i = 0; i < maxCols; ++i) {
|
||||
SDataCol *pCol = &pCols->cols[i];
|
||||
taosMemoryFreeClear(pCol->pData);
|
||||
}
|
||||
taosMemoryFree(pCols->cols);
|
||||
pCols->cols = NULL;
|
||||
}
|
||||
taosMemoryFree(pCols);
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void tdResetDataCols(SDataCols *pCols) {
|
||||
if (pCols != NULL) {
|
||||
pCols->numOfRows = 0;
|
||||
pCols->bitmapMode = 0;
|
||||
for (int i = 0; i < pCols->maxCols; ++i) {
|
||||
dataColReset(pCols->cols + i);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
|
@ -55,6 +55,7 @@ int32_t tsNumOfMnodeQueryThreads = 2;
|
|||
int32_t tsNumOfMnodeFetchThreads = 1;
|
||||
int32_t tsNumOfMnodeReadThreads = 1;
|
||||
int32_t tsNumOfVnodeQueryThreads = 2;
|
||||
int32_t tsNumOfVnodeStreamThreads = 2;
|
||||
int32_t tsNumOfVnodeFetchThreads = 4;
|
||||
int32_t tsNumOfVnodeWriteThreads = 2;
|
||||
int32_t tsNumOfVnodeSyncThreads = 2;
|
||||
|
@ -412,7 +413,12 @@ static int32_t taosAddServerCfg(SConfig *pCfg) {
|
|||
tsNumOfVnodeQueryThreads = TMAX(tsNumOfVnodeQueryThreads, 2);
|
||||
if (cfgAddInt32(pCfg, "numOfVnodeQueryThreads", tsNumOfVnodeQueryThreads, 1, 1024, 0) != 0) return -1;
|
||||
|
||||
tsNumOfVnodeFetchThreads = TRANGE(tsNumOfVnodeFetchThreads, 1, 1);
|
||||
tsNumOfVnodeStreamThreads = tsNumOfCores / 4;
|
||||
tsNumOfVnodeStreamThreads = TMAX(tsNumOfVnodeStreamThreads, 4);
|
||||
if (cfgAddInt32(pCfg, "numOfVnodeStreamThreads", tsNumOfVnodeStreamThreads, 1, 1024, 0) != 0) return -1;
|
||||
|
||||
tsNumOfVnodeFetchThreads = tsNumOfCores / 4;
|
||||
tsNumOfVnodeFetchThreads = TMAX(tsNumOfVnodeFetchThreads, 4);
|
||||
if (cfgAddInt32(pCfg, "numOfVnodeFetchThreads", tsNumOfVnodeFetchThreads, 1, 1024, 0) != 0) return -1;
|
||||
|
||||
tsNumOfVnodeWriteThreads = tsNumOfCores;
|
||||
|
@ -586,6 +592,7 @@ static int32_t taosSetServerCfg(SConfig *pCfg) {
|
|||
tsNumOfMnodeQueryThreads = cfgGetItem(pCfg, "numOfMnodeQueryThreads")->i32;
|
||||
tsNumOfMnodeReadThreads = cfgGetItem(pCfg, "numOfMnodeReadThreads")->i32;
|
||||
tsNumOfVnodeQueryThreads = cfgGetItem(pCfg, "numOfVnodeQueryThreads")->i32;
|
||||
tsNumOfVnodeStreamThreads = cfgGetItem(pCfg, "numOfVnodeStreamThreads")->i32;
|
||||
tsNumOfVnodeFetchThreads = cfgGetItem(pCfg, "numOfVnodeFetchThreads")->i32;
|
||||
tsNumOfVnodeWriteThreads = cfgGetItem(pCfg, "numOfVnodeWriteThreads")->i32;
|
||||
tsNumOfVnodeSyncThreads = cfgGetItem(pCfg, "numOfVnodeSyncThreads")->i32;
|
||||
|
@ -1116,10 +1123,44 @@ void taosCfgDynamicOptions(const char *option, const char *value) {
|
|||
if (strncasecmp(option, "debugFlag", 9) == 0) {
|
||||
int32_t flag = atoi(value);
|
||||
taosSetAllDebugFlag(flag);
|
||||
return;
|
||||
}
|
||||
|
||||
if (strcasecmp(option, "resetlog") == 0) {
|
||||
taosResetLog();
|
||||
cfgDumpCfg(tsCfg, 0, false);
|
||||
return;
|
||||
}
|
||||
|
||||
if (strcasecmp(option, "monitor") == 0) {
|
||||
int32_t monitor = atoi(value);
|
||||
uInfo("monitor set from %d to %d", tsEnableMonitor, monitor);
|
||||
tsEnableMonitor = monitor;
|
||||
return;
|
||||
}
|
||||
|
||||
const char *options[] = {
|
||||
"dDebugFlag", "vDebugFlag", "mDebugFlag", "wDebugFlag", "sDebugFlag", "tsdbDebugFlag",
|
||||
"tqDebugFlag", "fsDebugFlag", "udfDebugFlag", "smaDebugFlag", "idxDebugFlag", "tmrDebugFlag",
|
||||
"uDebugFlag", "smaDebugFlag", "rpcDebugFlag", "qDebugFlag",
|
||||
};
|
||||
int32_t *optionVars[] = {
|
||||
&dDebugFlag, &vDebugFlag, &mDebugFlag, &wDebugFlag, &sDebugFlag, &tsdbDebugFlag,
|
||||
&tqDebugFlag, &fsDebugFlag, &udfDebugFlag, &smaDebugFlag, &idxDebugFlag, &tmrDebugFlag,
|
||||
&uDebugFlag, &smaDebugFlag, &rpcDebugFlag, &qDebugFlag,
|
||||
};
|
||||
|
||||
int32_t optionSize = tListLen(options);
|
||||
for (int32_t d = 0; d < optionSize; ++d) {
|
||||
const char *optName = options[d];
|
||||
int32_t optLen = strlen(optName);
|
||||
if (strncasecmp(option, optName, optLen) != 0) continue;
|
||||
|
||||
int32_t flag = atoi(value);
|
||||
uInfo("%s set from %d to %d", optName, *optionVars[d], flag);
|
||||
*optionVars[d] = flag;
|
||||
return;
|
||||
}
|
||||
|
||||
uError("failed to cfg dynamic option:%s value:%s", option, value);
|
||||
}
|
||||
|
|
|
@ -4962,7 +4962,7 @@ int tDecodeSVCreateTbReq(SDecoder *pCoder, SVCreateTbReq *pReq) {
|
|||
if (tDecodeI64(pCoder, &pReq->ctb.suid) < 0) return -1;
|
||||
if (tDecodeTag(pCoder, (STag **)&pReq->ctb.pTag) < 0) return -1;
|
||||
} else if (pReq->type == TSDB_NORMAL_TABLE) {
|
||||
if (tDecodeSSchemaWrapper(pCoder, &pReq->ntb.schemaRow) < 0) return -1;
|
||||
if (tDecodeSSchemaWrapperEx(pCoder, &pReq->ntb.schemaRow) < 0) return -1;
|
||||
} else {
|
||||
ASSERT(0);
|
||||
}
|
||||
|
@ -5526,6 +5526,11 @@ bool tOffsetEqual(const STqOffsetVal *pLeft, const STqOffsetVal *pRight) {
|
|||
ASSERT(0);
|
||||
// TODO
|
||||
return pLeft->uid == pRight->uid && pLeft->ts == pRight->ts;
|
||||
} else {
|
||||
ASSERT(0);
|
||||
/*ASSERT(pLeft->type == TMQ_OFFSET__RESET_NONE || pLeft->type == TMQ_OFFSET__RESET_EARLIEAST ||*/
|
||||
/*pLeft->type == TMQ_OFFSET__RESET_LATEST);*/
|
||||
/*return true;*/
|
||||
}
|
||||
}
|
||||
return false;
|
||||
|
|
|
@ -32,28 +32,10 @@ const uint8_t tdVTypeByte[2][3] = {{
|
|||
};
|
||||
|
||||
// declaration
|
||||
static uint8_t tdGetBitmapByte(uint8_t byte);
|
||||
static int32_t tdCompareColId(const void *arg1, const void *arg2);
|
||||
static uint8_t tdGetBitmapByte(uint8_t byte);
|
||||
static int32_t tdCompareColId(const void *arg1, const void *arg2);
|
||||
static FORCE_INLINE int32_t compareKvRowColId(const void *key1, const void *key2);
|
||||
|
||||
// static void dataColSetNEleNull(SDataCol *pCol, int nEle);
|
||||
|
||||
/**
|
||||
* @brief src2 data has more priority than src1
|
||||
*
|
||||
* @param target
|
||||
* @param src1
|
||||
* @param iter1
|
||||
* @param limit1
|
||||
* @param src2
|
||||
* @param iter2
|
||||
* @param limit2
|
||||
* @param tRows
|
||||
* @param update
|
||||
*/
|
||||
static void tdMergeTwoDataCols(SDataCols *target, SDataCols *src1, int *iter1, int limit1, SDataCols *src2, int *iter2,
|
||||
int limit2, int tRows, bool update);
|
||||
|
||||
// implementation
|
||||
/**
|
||||
* @brief Compress bitmap bytes comprised of 2-bits to counterpart of 1-bit.
|
||||
|
@ -287,33 +269,6 @@ void tdMergeBitmap(uint8_t *srcBitmap, int32_t nBits, uint8_t *dstBitmap) {
|
|||
}
|
||||
}
|
||||
|
||||
static FORCE_INLINE void dataColSetNullAt(SDataCol *pCol, int index, bool setBitmap, int8_t bitmapMode) {
|
||||
if (IS_VAR_DATA_TYPE(pCol->type)) {
|
||||
pCol->dataOff[index] = pCol->len;
|
||||
char *ptr = POINTER_SHIFT(pCol->pData, pCol->len);
|
||||
setVardataNull(ptr, pCol->type);
|
||||
pCol->len += varDataTLen(ptr);
|
||||
} else {
|
||||
setNull(POINTER_SHIFT(pCol->pData, TYPE_BYTES[pCol->type] * index), pCol->type, pCol->bytes);
|
||||
pCol->len += TYPE_BYTES[pCol->type];
|
||||
}
|
||||
if (setBitmap) {
|
||||
tdSetBitmapValType(pCol->pBitmap, index, TD_VTYPE_NONE, bitmapMode);
|
||||
}
|
||||
}
|
||||
|
||||
// static void dataColSetNEleNull(SDataCol *pCol, int nEle) {
|
||||
// if (IS_VAR_DATA_TYPE(pCol->type)) {
|
||||
// pCol->len = 0;
|
||||
// for (int i = 0; i < nEle; i++) {
|
||||
// dataColSetNullAt(pCol, i);
|
||||
// }
|
||||
// } else {
|
||||
// setNullN(pCol->pData, pCol->type, pCol->bytes, nEle);
|
||||
// pCol->len = TYPE_BYTES[pCol->type] * nEle;
|
||||
// }
|
||||
// }
|
||||
|
||||
/**
|
||||
* @brief Set bitmap area by byte preferentially and then by bit.
|
||||
*
|
||||
|
@ -362,56 +317,6 @@ bool tdIsBitmapBlkNorm(const void *pBitmap, int32_t numOfBits, int8_t bitmapMode
|
|||
return true;
|
||||
}
|
||||
|
||||
static FORCE_INLINE void dataColSetNoneAt(SDataCol *pCol, int index, bool setBitmap, int8_t bitmapMode) {
|
||||
if (IS_VAR_DATA_TYPE(pCol->type)) {
|
||||
pCol->dataOff[index] = pCol->len;
|
||||
char *ptr = POINTER_SHIFT(pCol->pData, pCol->len);
|
||||
setVardataNull(ptr, pCol->type);
|
||||
pCol->len += varDataTLen(ptr);
|
||||
} else {
|
||||
setNull(POINTER_SHIFT(pCol->pData, TYPE_BYTES[pCol->type] * index), pCol->type, pCol->bytes);
|
||||
pCol->len += TYPE_BYTES[pCol->type];
|
||||
}
|
||||
if (setBitmap) {
|
||||
tdSetBitmapValType(pCol->pBitmap, index, TD_VTYPE_NONE, bitmapMode);
|
||||
}
|
||||
}
|
||||
|
||||
static void dataColSetNEleNone(SDataCol *pCol, int nEle, int8_t bitmapMode) {
|
||||
if (IS_VAR_DATA_TYPE(pCol->type)) {
|
||||
pCol->len = 0;
|
||||
for (int i = 0; i < nEle; ++i) {
|
||||
dataColSetNoneAt(pCol, i, false, bitmapMode);
|
||||
}
|
||||
} else {
|
||||
setNullN(pCol->pData, pCol->type, pCol->bytes, nEle);
|
||||
pCol->len = TYPE_BYTES[pCol->type] * nEle;
|
||||
}
|
||||
#ifdef TD_SUPPORT_BITMAP
|
||||
tdSetBitmapValTypeN(pCol->pBitmap, nEle, TD_VTYPE_NONE, bitmapMode);
|
||||
#endif
|
||||
}
|
||||
|
||||
#if 0
|
||||
void trbSetRowInfo(SRowBuilder *pRB, bool del, uint16_t sver) {
|
||||
// TODO
|
||||
}
|
||||
|
||||
void trbSetRowVersion(SRowBuilder *pRB, uint64_t ver) {
|
||||
// TODO
|
||||
}
|
||||
|
||||
void trbSetRowTS(SRowBuilder *pRB, TSKEY ts) {
|
||||
// TODO
|
||||
}
|
||||
|
||||
int trbWriteCol(SRowBuilder *pRB, void *pData, col_id_t cid) {
|
||||
// TODO
|
||||
return 0;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
STSRow *tdRowDup(STSRow *row) {
|
||||
STSRow *trow = taosMemoryMalloc(TD_ROW_LEN(row));
|
||||
if (trow == NULL) return NULL;
|
||||
|
@ -420,511 +325,6 @@ STSRow *tdRowDup(STSRow *row) {
|
|||
return trow;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief
|
||||
*
|
||||
* @param pCol
|
||||
* @param valType
|
||||
* @param val
|
||||
* @param numOfRows
|
||||
* @param maxPoints
|
||||
* @param bitmapMode default is 0(2 bits), otherwise 1(1 bit)
|
||||
* @param isMerge merge to current row
|
||||
* @return int
|
||||
*/
|
||||
int tdAppendValToDataCol(SDataCol *pCol, TDRowValT valType, const void *val, int numOfRows, int maxPoints,
|
||||
int8_t bitmapMode, bool isMerge) {
|
||||
TASSERT(pCol != NULL);
|
||||
|
||||
// Assume that the columns not specified during insert/upsert mean None.
|
||||
if (isAllRowsNone(pCol)) {
|
||||
if (tdValIsNone(valType)) {
|
||||
// all None value yet, just return
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (tdAllocMemForCol(pCol, maxPoints) < 0) return -1;
|
||||
if (numOfRows > 0) {
|
||||
// Find the first not None value, fill all previous values as None
|
||||
dataColSetNEleNone(pCol, numOfRows, bitmapMode);
|
||||
}
|
||||
}
|
||||
const void *value = val;
|
||||
if (!tdValTypeIsNorm(valType) || !val) {
|
||||
// TODO:
|
||||
// 1. back compatibility and easy to debug with codes of 2.0 to save NULL values.
|
||||
// 2. later on, considering further optimization, don't save Null/None for VarType.
|
||||
value = getNullValue(pCol->type);
|
||||
}
|
||||
if (!isMerge) {
|
||||
if (IS_VAR_DATA_TYPE(pCol->type)) {
|
||||
// set offset
|
||||
pCol->dataOff[numOfRows] = pCol->len;
|
||||
// Copy data
|
||||
memcpy(POINTER_SHIFT(pCol->pData, pCol->len), value, varDataTLen(value));
|
||||
// Update the length
|
||||
pCol->len += varDataTLen(value);
|
||||
} else {
|
||||
ASSERT(pCol->len == TYPE_BYTES[pCol->type] * numOfRows);
|
||||
memcpy(POINTER_SHIFT(pCol->pData, pCol->len), value, pCol->bytes);
|
||||
pCol->len += pCol->bytes;
|
||||
}
|
||||
} else if (!tdValTypeIsNone(valType)) {
|
||||
if (IS_VAR_DATA_TYPE(pCol->type)) {
|
||||
// keep the last offset
|
||||
// discard the last var data
|
||||
int32_t lastVarLen = varDataTLen(POINTER_SHIFT(pCol->pData, pCol->dataOff[numOfRows]));
|
||||
pCol->len -= lastVarLen;
|
||||
// Copy data
|
||||
memcpy(POINTER_SHIFT(pCol->pData, pCol->len), value, varDataTLen(value));
|
||||
// Update the length
|
||||
pCol->len += varDataTLen(value);
|
||||
} else {
|
||||
ASSERT(pCol->len - TYPE_BYTES[pCol->type] == TYPE_BYTES[pCol->type] * numOfRows);
|
||||
memcpy(POINTER_SHIFT(pCol->pData, pCol->len - TYPE_BYTES[pCol->type]), value, pCol->bytes);
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef TD_SUPPORT_BITMAP
|
||||
if (!isMerge || !tdValTypeIsNone(valType)) {
|
||||
tdSetBitmapValType(pCol->pBitmap, numOfRows, valType, bitmapMode);
|
||||
}
|
||||
#endif
|
||||
return 0;
|
||||
}
|
||||
|
||||
// internal
|
||||
static int32_t tdAppendTpRowToDataCol(STSRow *pRow, STSchema *pSchema, SDataCols *pCols, bool isMerge) {
|
||||
#if 0
|
||||
ASSERT(pCols->numOfRows == 0 || dataColsKeyLast(pCols) < TD_ROW_KEY(pRow));
|
||||
#endif
|
||||
|
||||
// Multi-Version rows with the same key and different versions supported
|
||||
ASSERT(pCols->numOfRows == 0 || dataColsKeyLast(pCols) <= TD_ROW_KEY(pRow));
|
||||
|
||||
int rcol = 1;
|
||||
int dcol = 1;
|
||||
void *pBitmap = tdGetBitmapAddrTp(pRow, pSchema->flen);
|
||||
|
||||
SDataCol *pDataCol = &(pCols->cols[0]);
|
||||
ASSERT(pDataCol->colId == PRIMARYKEY_TIMESTAMP_COL_ID);
|
||||
tdAppendValToDataCol(pDataCol, TD_VTYPE_NORM, &pRow->ts, pCols->numOfRows, pCols->maxPoints, pCols->bitmapMode,
|
||||
isMerge);
|
||||
|
||||
while (dcol < pCols->numOfCols) {
|
||||
pDataCol = &(pCols->cols[dcol]);
|
||||
if (rcol >= schemaNCols(pSchema)) {
|
||||
tdAppendValToDataCol(pDataCol, TD_VTYPE_NULL, NULL, pCols->numOfRows, pCols->maxPoints, pCols->bitmapMode,
|
||||
isMerge);
|
||||
++dcol;
|
||||
continue;
|
||||
}
|
||||
|
||||
STColumn *pRowCol = schemaColAt(pSchema, rcol);
|
||||
SCellVal sVal = {0};
|
||||
if (pRowCol->colId == pDataCol->colId) {
|
||||
if (tdGetTpRowValOfCol(&sVal, pRow, pBitmap, pRowCol->type, pRowCol->offset - sizeof(TSKEY), rcol - 1) < 0) {
|
||||
return terrno;
|
||||
}
|
||||
tdAppendValToDataCol(pDataCol, sVal.valType, sVal.val, pCols->numOfRows, pCols->maxPoints, pCols->bitmapMode,
|
||||
isMerge);
|
||||
++dcol;
|
||||
++rcol;
|
||||
} else if (pRowCol->colId < pDataCol->colId) {
|
||||
++rcol;
|
||||
} else {
|
||||
tdAppendValToDataCol(pDataCol, TD_VTYPE_NULL, NULL, pCols->numOfRows, pCols->maxPoints, pCols->bitmapMode,
|
||||
isMerge);
|
||||
++dcol;
|
||||
}
|
||||
}
|
||||
#if 0
|
||||
++pCols->numOfRows;
|
||||
#endif
|
||||
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
// internal
|
||||
static int32_t tdAppendKvRowToDataCol(STSRow *pRow, STSchema *pSchema, SDataCols *pCols, bool isMerge) {
|
||||
ASSERT(pCols->numOfRows == 0 || dataColsKeyLast(pCols) < TD_ROW_KEY(pRow));
|
||||
|
||||
int rcol = 0;
|
||||
int dcol = 1;
|
||||
int tRowCols = tdRowGetNCols(pRow) - 1; // the primary TS key not included in kvRowColIdx part
|
||||
int tSchemaCols = schemaNCols(pSchema) - 1;
|
||||
void *pBitmap = tdGetBitmapAddrKv(pRow, tdRowGetNCols(pRow));
|
||||
|
||||
SDataCol *pDataCol = &(pCols->cols[0]);
|
||||
ASSERT(pDataCol->colId == PRIMARYKEY_TIMESTAMP_COL_ID);
|
||||
tdAppendValToDataCol(pDataCol, TD_VTYPE_NORM, &pRow->ts, pCols->numOfRows, pCols->maxPoints, pCols->bitmapMode,
|
||||
isMerge);
|
||||
|
||||
while (dcol < pCols->numOfCols) {
|
||||
pDataCol = &(pCols->cols[dcol]);
|
||||
if (rcol >= tRowCols || rcol >= tSchemaCols) {
|
||||
tdAppendValToDataCol(pDataCol, TD_VTYPE_NULL, NULL, pCols->numOfRows, pCols->maxPoints, pCols->bitmapMode,
|
||||
isMerge);
|
||||
++dcol;
|
||||
continue;
|
||||
}
|
||||
|
||||
SKvRowIdx *pIdx = tdKvRowColIdxAt(pRow, rcol);
|
||||
int16_t colIdx = -1;
|
||||
if (pIdx) {
|
||||
colIdx = POINTER_DISTANCE(pIdx, TD_ROW_COL_IDX(pRow)) / sizeof(SKvRowIdx);
|
||||
}
|
||||
TASSERT(colIdx >= 0);
|
||||
SCellVal sVal = {0};
|
||||
if (pIdx->colId == pDataCol->colId) {
|
||||
if (tdGetKvRowValOfCol(&sVal, pRow, pBitmap, pIdx->offset, colIdx) < 0) {
|
||||
return terrno;
|
||||
}
|
||||
tdAppendValToDataCol(pDataCol, sVal.valType, sVal.val, pCols->numOfRows, pCols->maxPoints, pCols->bitmapMode,
|
||||
isMerge);
|
||||
++dcol;
|
||||
++rcol;
|
||||
} else if (pIdx->colId < pDataCol->colId) {
|
||||
++rcol;
|
||||
} else {
|
||||
tdAppendValToDataCol(pDataCol, TD_VTYPE_NULL, NULL, pCols->numOfRows, pCols->maxPoints, pCols->bitmapMode,
|
||||
isMerge);
|
||||
++dcol;
|
||||
}
|
||||
}
|
||||
#if 0
|
||||
++pCols->numOfRows;
|
||||
#endif
|
||||
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief exposed
|
||||
*
|
||||
* @param pRow
|
||||
* @param pSchema
|
||||
* @param pCols
|
||||
*/
|
||||
int32_t tdAppendSTSRowToDataCol(STSRow *pRow, STSchema *pSchema, SDataCols *pCols, bool isMerge) {
|
||||
#ifdef TD_DEBUG_PRINT_TSDB_LOAD_DCOLS
|
||||
printf("%s:%d ts: %" PRIi64 " sver:%d maxCols:%" PRIi16 " nCols:%" PRIi16 ", nRows:%d\n", __func__, __LINE__,
|
||||
TD_ROW_KEY(pRow), TD_ROW_SVER(pRow), pCols->maxCols, pCols->numOfCols, pCols->numOfRows);
|
||||
#endif
|
||||
if (TD_IS_TP_ROW(pRow)) {
|
||||
return tdAppendTpRowToDataCol(pRow, pSchema, pCols, isMerge);
|
||||
} else if (TD_IS_KV_ROW(pRow)) {
|
||||
return tdAppendKvRowToDataCol(pRow, pSchema, pCols, isMerge);
|
||||
} else {
|
||||
ASSERT(0);
|
||||
}
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief source data has more priority than target
|
||||
*
|
||||
* @param target
|
||||
* @param source
|
||||
* @param rowsToMerge
|
||||
* @param pOffset
|
||||
* @param update
|
||||
* @param maxVer
|
||||
* @return int
|
||||
*/
|
||||
int tdMergeDataCols(SDataCols *target, SDataCols *source, int rowsToMerge, int *pOffset, bool update,
|
||||
TDRowVerT maxVer) {
|
||||
ASSERT(rowsToMerge > 0 && rowsToMerge <= source->numOfRows);
|
||||
ASSERT(target->numOfCols == source->numOfCols);
|
||||
int offset = 0;
|
||||
|
||||
if (pOffset == NULL) {
|
||||
pOffset = &offset;
|
||||
}
|
||||
|
||||
SDataCols *pTarget = NULL;
|
||||
|
||||
if ((target->numOfRows == 0) || (dataColsKeyLast(target) < dataColsKeyAtRow(source, *pOffset))) { // No overlap
|
||||
ASSERT(target->numOfRows + rowsToMerge <= target->maxPoints);
|
||||
// TODO: filter the maxVer
|
||||
TSKEY lastKey = TSKEY_INITIAL_VAL;
|
||||
for (int i = 0; i < rowsToMerge; ++i) {
|
||||
bool merge = false;
|
||||
for (int j = 0; j < source->numOfCols; j++) {
|
||||
if (source->cols[j].len > 0 || target->cols[j].len > 0) {
|
||||
SCellVal sVal = {0};
|
||||
if (tdGetColDataOfRow(&sVal, source->cols + j, i + (*pOffset), source->bitmapMode) < 0) {
|
||||
TASSERT(0);
|
||||
}
|
||||
|
||||
if (j == 0) {
|
||||
if (lastKey == *(TSKEY *)sVal.val) {
|
||||
if (!update) {
|
||||
break;
|
||||
}
|
||||
merge = true;
|
||||
} else if (lastKey != TSKEY_INITIAL_VAL) {
|
||||
++target->numOfRows;
|
||||
}
|
||||
|
||||
lastKey = *(TSKEY *)sVal.val;
|
||||
}
|
||||
if (i == 0) {
|
||||
(target->cols + j)->bitmap = (source->cols + j)->bitmap;
|
||||
}
|
||||
|
||||
tdAppendValToDataCol(target->cols + j, sVal.valType, sVal.val, target->numOfRows, target->maxPoints,
|
||||
target->bitmapMode, merge);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (lastKey != TSKEY_INITIAL_VAL) {
|
||||
++target->numOfRows;
|
||||
}
|
||||
(*pOffset) += rowsToMerge;
|
||||
} else {
|
||||
pTarget = tdDupDataCols(target, true);
|
||||
if (pTarget == NULL) goto _err;
|
||||
|
||||
int iter1 = 0;
|
||||
tdMergeTwoDataCols(target, pTarget, &iter1, pTarget->numOfRows, source, pOffset, source->numOfRows,
|
||||
pTarget->numOfRows + rowsToMerge, update);
|
||||
}
|
||||
|
||||
tdFreeDataCols(pTarget);
|
||||
return 0;
|
||||
|
||||
_err:
|
||||
tdFreeDataCols(pTarget);
|
||||
return -1;
|
||||
}
|
||||
|
||||
static void tdAppendValToDataCols(SDataCols *target, SDataCols *src, int iter, bool isMerge) {
|
||||
for (int i = 0; i < src->numOfCols; ++i) {
|
||||
ASSERT(target->cols[i].type == src->cols[i].type);
|
||||
if (src->cols[i].len > 0 || target->cols[i].len > 0) {
|
||||
SCellVal sVal = {0};
|
||||
if (tdGetColDataOfRow(&sVal, src->cols + i, iter, src->bitmapMode) < 0) {
|
||||
TASSERT(0);
|
||||
}
|
||||
if (isMerge) {
|
||||
if (!tdValTypeIsNone(sVal.valType)) {
|
||||
tdAppendValToDataCol(&(target->cols[i]), sVal.valType, sVal.val, target->numOfRows, target->maxPoints,
|
||||
target->bitmapMode, isMerge);
|
||||
} else {
|
||||
// Keep the origin value for None
|
||||
}
|
||||
} else {
|
||||
tdAppendValToDataCol(&(target->cols[i]), sVal.valType, sVal.val, target->numOfRows, target->maxPoints,
|
||||
target->bitmapMode, isMerge);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
/**
|
||||
* @brief src2 data has more priority than src1
|
||||
*
|
||||
* @param target
|
||||
* @param src1
|
||||
* @param iter1
|
||||
* @param limit1
|
||||
* @param src2
|
||||
* @param iter2
|
||||
* @param limit2
|
||||
* @param tRows
|
||||
* @param update
|
||||
*/
|
||||
static void tdMergeTwoDataCols(SDataCols *target, SDataCols *src1, int *iter1, int limit1, SDataCols *src2, int *iter2,
|
||||
int limit2, int tRows, bool update) {
|
||||
tdResetDataCols(target);
|
||||
target->bitmapMode = src1->bitmapMode;
|
||||
ASSERT(limit1 <= src1->numOfRows && limit2 <= src2->numOfRows);
|
||||
int32_t nRows = 0;
|
||||
|
||||
// TODO: filter the maxVer
|
||||
// TODO: handle the delete function
|
||||
TSKEY lastKey = TSKEY_INITIAL_VAL;
|
||||
while (nRows < tRows) {
|
||||
if (*iter1 >= limit1 && *iter2 >= limit2) break;
|
||||
|
||||
TSKEY key1 = (*iter1 >= limit1) ? INT64_MAX : dataColsKeyAt(src1, *iter1);
|
||||
// TKEY tkey1 = (*iter1 >= limit1) ? TKEY_NULL : dataColsTKeyAt(src1, *iter1);
|
||||
TSKEY key2 = (*iter2 >= limit2) ? INT64_MAX : dataColsKeyAt(src2, *iter2);
|
||||
// TKEY tkey2 = (*iter2 >= limit2) ? TKEY_NULL : dataColsTKeyAt(src2, *iter2);
|
||||
|
||||
// ASSERT(tkey1 == TKEY_NULL || (!TKEY_IS_DELETED(tkey1)));
|
||||
|
||||
if (key1 <= key2) {
|
||||
// select key1 if not delete
|
||||
if (update && (lastKey == key1)) {
|
||||
tdAppendValToDataCols(target, src1, *iter1, true);
|
||||
} else if (lastKey != key1) {
|
||||
if (lastKey != TSKEY_INITIAL_VAL) {
|
||||
++target->numOfRows;
|
||||
}
|
||||
tdAppendValToDataCols(target, src1, *iter1, false);
|
||||
}
|
||||
++nRows;
|
||||
++(*iter1);
|
||||
lastKey = key1;
|
||||
} else {
|
||||
// use key2 if not deleted
|
||||
// TODO: handle the delete function
|
||||
if (update && (lastKey == key2)) {
|
||||
tdAppendValToDataCols(target, src2, *iter2, true);
|
||||
} else if (lastKey != key2) {
|
||||
if (lastKey != TSKEY_INITIAL_VAL) {
|
||||
++target->numOfRows;
|
||||
}
|
||||
tdAppendValToDataCols(target, src2, *iter2, false);
|
||||
}
|
||||
|
||||
++nRows;
|
||||
++(*iter2);
|
||||
lastKey = key2;
|
||||
}
|
||||
|
||||
ASSERT(target->numOfRows <= target->maxPoints - 1);
|
||||
}
|
||||
if (lastKey != TSKEY_INITIAL_VAL) {
|
||||
++target->numOfRows;
|
||||
}
|
||||
}
|
||||
|
||||
STSRow *mergeTwoRows(void *buffer, STSRow *row1, STSRow *row2, STSchema *pSchema1, STSchema *pSchema2) {
|
||||
#if 0
|
||||
ASSERT(TD_ROW_KEY(row1) == TD_ROW_KEY(row2));
|
||||
ASSERT(schemaVersion(pSchema1) == TD_ROW_SVER(row1));
|
||||
ASSERT(schemaVersion(pSchema2) == TD_ROW_SVER(row2));
|
||||
ASSERT(schemaVersion(pSchema1) >= schemaVersion(pSchema2));
|
||||
#endif
|
||||
|
||||
#if 0
|
||||
SArray *stashRow = taosArrayInit(pSchema1->numOfCols, sizeof(SColInfo));
|
||||
if (stashRow == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
STSRow pRow = buffer;
|
||||
STpRow dataRow = memRowDataBody(pRow);
|
||||
memRowSetType(pRow, SMEM_ROW_DATA);
|
||||
dataRowSetVersion(dataRow, schemaVersion(pSchema1)); // use latest schema version
|
||||
dataRowSetLen(dataRow, (TDRowLenT)(TD_DATA_ROW_HEAD_SIZE + pSchema1->flen));
|
||||
|
||||
TDRowLenT dataLen = 0, kvLen = TD_MEM_ROW_KV_HEAD_SIZE;
|
||||
|
||||
int32_t i = 0; // row1
|
||||
int32_t j = 0; // row2
|
||||
int32_t nCols1 = schemaNCols(pSchema1);
|
||||
int32_t nCols2 = schemaNCols(pSchema2);
|
||||
SColInfo colInfo = {0};
|
||||
int32_t kvIdx1 = 0, kvIdx2 = 0;
|
||||
|
||||
while (i < nCols1) {
|
||||
STColumn *pCol = schemaColAt(pSchema1, i);
|
||||
void * val1 = tdGetMemRowDataOfColEx(row1, pCol->colId, pCol->type, TD_DATA_ROW_HEAD_SIZE + pCol->offset, &kvIdx1);
|
||||
// if val1 != NULL, use val1;
|
||||
if (val1 != NULL && !isNull(val1, pCol->type)) {
|
||||
tdAppendColVal(dataRow, val1, pCol->type, pCol->offset);
|
||||
kvLen += tdGetColAppendLen(SMEM_ROW_KV, val1, pCol->type);
|
||||
setSColInfo(&colInfo, pCol->colId, pCol->type, val1);
|
||||
taosArrayPush(stashRow, &colInfo);
|
||||
++i; // next col
|
||||
continue;
|
||||
}
|
||||
|
||||
void *val2 = NULL;
|
||||
while (j < nCols2) {
|
||||
STColumn *tCol = schemaColAt(pSchema2, j);
|
||||
if (tCol->colId < pCol->colId) {
|
||||
++j;
|
||||
continue;
|
||||
}
|
||||
if (tCol->colId == pCol->colId) {
|
||||
val2 = tdGetMemRowDataOfColEx(row2, tCol->colId, tCol->type, TD_DATA_ROW_HEAD_SIZE + tCol->offset, &kvIdx2);
|
||||
} else if (tCol->colId > pCol->colId) {
|
||||
// set NULL
|
||||
}
|
||||
break;
|
||||
} // end of while(j<nCols2)
|
||||
if (val2 == NULL) {
|
||||
val2 = (void *)getNullValue(pCol->type);
|
||||
}
|
||||
tdAppendColVal(dataRow, val2, pCol->type, pCol->offset);
|
||||
if (!isNull(val2, pCol->type)) {
|
||||
kvLen += tdGetColAppendLen(SMEM_ROW_KV, val2, pCol->type);
|
||||
setSColInfo(&colInfo, pCol->colId, pCol->type, val2);
|
||||
taosArrayPush(stashRow, &colInfo);
|
||||
}
|
||||
|
||||
++i; // next col
|
||||
}
|
||||
|
||||
dataLen = TD_ROW_LEN(pRow);
|
||||
|
||||
if (kvLen < dataLen) {
|
||||
// scan stashRow and generate SKVRow
|
||||
memset(buffer, 0, sizeof(dataLen));
|
||||
STSRow tRow = buffer;
|
||||
memRowSetType(tRow, SMEM_ROW_KV);
|
||||
SKVRow kvRow = (SKVRow)memRowKvBody(tRow);
|
||||
int16_t nKvNCols = (int16_t) taosArrayGetSize(stashRow);
|
||||
kvRowSetLen(kvRow, (TDRowLenT)(TD_KV_ROW_HEAD_SIZE + sizeof(SColIdx) * nKvNCols));
|
||||
kvRowSetNCols(kvRow, nKvNCols);
|
||||
memRowSetKvVersion(tRow, pSchema1->version);
|
||||
|
||||
int32_t toffset = 0;
|
||||
int16_t k;
|
||||
for (k = 0; k < nKvNCols; ++k) {
|
||||
SColInfo *pColInfo = taosArrayGet(stashRow, k);
|
||||
tdAppendKvColVal(kvRow, pColInfo->colVal, true, pColInfo->colId, pColInfo->colType, toffset);
|
||||
toffset += sizeof(SColIdx);
|
||||
}
|
||||
ASSERT(kvLen == TD_ROW_LEN(tRow));
|
||||
}
|
||||
taosArrayDestroy(stashRow);
|
||||
return buffer;
|
||||
#endif
|
||||
return NULL;
|
||||
}
|
||||
|
||||
SDataCols *tdDupDataCols(SDataCols *pDataCols, bool keepData) {
|
||||
SDataCols *pRet = tdNewDataCols(pDataCols->maxCols, pDataCols->maxPoints);
|
||||
if (pRet == NULL) return NULL;
|
||||
|
||||
pRet->numOfCols = pDataCols->numOfCols;
|
||||
pRet->bitmapMode = pDataCols->bitmapMode;
|
||||
pRet->sversion = pDataCols->sversion;
|
||||
if (keepData) pRet->numOfRows = pDataCols->numOfRows;
|
||||
|
||||
for (int i = 0; i < pDataCols->numOfCols; ++i) {
|
||||
pRet->cols[i].type = pDataCols->cols[i].type;
|
||||
pRet->cols[i].bitmap = pDataCols->cols[i].bitmap;
|
||||
pRet->cols[i].colId = pDataCols->cols[i].colId;
|
||||
pRet->cols[i].bytes = pDataCols->cols[i].bytes;
|
||||
pRet->cols[i].offset = pDataCols->cols[i].offset;
|
||||
|
||||
if (keepData) {
|
||||
if (pDataCols->cols[i].len > 0) {
|
||||
if (tdAllocMemForCol(&pRet->cols[i], pRet->maxPoints) < 0) {
|
||||
tdFreeDataCols(pRet);
|
||||
return NULL;
|
||||
}
|
||||
pRet->cols[i].len = pDataCols->cols[i].len;
|
||||
memcpy(pRet->cols[i].pData, pDataCols->cols[i].pData, pDataCols->cols[i].len);
|
||||
if (IS_VAR_DATA_TYPE(pRet->cols[i].type)) {
|
||||
int dataOffSize = sizeof(VarDataOffsetT) * pDataCols->maxPoints;
|
||||
memcpy(pRet->cols[i].dataOff, pDataCols->cols[i].dataOff, dataOffSize);
|
||||
}
|
||||
if (!TD_COL_ROWS_NORM(pRet->cols + i)) {
|
||||
memcpy(pRet->cols[i].pBitmap, pDataCols->cols[i].pBitmap, TD_BITMAP_BYTES(pDataCols->numOfRows));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return pRet;
|
||||
}
|
||||
|
||||
void tdSRowPrint(STSRow *row, STSchema *pSchema, const char *tag) {
|
||||
STSRowIter iter = {0};
|
||||
tdSTSRowIterInit(&iter, pSchema);
|
||||
|
@ -1020,32 +420,6 @@ void tdSCellValPrint(SCellVal *pVal, int8_t colType) {
|
|||
}
|
||||
}
|
||||
|
||||
int32_t dataColGetNEleLen(SDataCol *pDataCol, int32_t rows, int8_t bitmapMode) {
|
||||
ASSERT(rows > 0);
|
||||
int32_t result = 0;
|
||||
|
||||
if (IS_VAR_DATA_TYPE(pDataCol->type)) {
|
||||
result += pDataCol->dataOff[rows - 1];
|
||||
SCellVal val = {0};
|
||||
if (tdGetColDataOfRow(&val, pDataCol, rows - 1, bitmapMode) < 0) {
|
||||
TASSERT(0);
|
||||
}
|
||||
|
||||
// Currently, count the varDataTLen in of Null/None cols considering back compatibility test for 2.4
|
||||
result += varDataTLen(val.val);
|
||||
// TODO: later on, don't save Null/None for VarDataT for 3.0
|
||||
// if (tdValTypeIsNorm(val.valType)) {
|
||||
// result += varDataTLen(val.val);
|
||||
// }
|
||||
} else {
|
||||
result += TYPE_BYTES[pDataCol->type] * rows;
|
||||
}
|
||||
|
||||
ASSERT(pDataCol->len == result);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
bool tdSKvRowGetVal(STSRow *pRow, col_id_t colId, col_id_t colIdx, SCellVal *pVal) {
|
||||
if (colId == PRIMARYKEY_TIMESTAMP_COL_ID) {
|
||||
tdRowSetVal(pVal, TD_VTYPE_NORM, TD_ROW_KEY_ADDR(pRow));
|
||||
|
@ -1082,40 +456,6 @@ bool tdSTpRowGetVal(STSRow *pRow, col_id_t colId, col_type_t colType, int32_t fl
|
|||
return true;
|
||||
}
|
||||
|
||||
int32_t tdGetColDataOfRow(SCellVal *pVal, SDataCol *pCol, int32_t row, int8_t bitmapMode) {
|
||||
if (isAllRowsNone(pCol)) {
|
||||
pVal->valType = TD_VTYPE_NONE;
|
||||
#ifdef TD_SUPPORT_READ2
|
||||
pVal->val = (void *)getNullValue(pCol->type);
|
||||
#else
|
||||
pVal->val = NULL;
|
||||
#endif
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
if (TD_COL_ROWS_NORM(pCol)) {
|
||||
pVal->valType = TD_VTYPE_NORM;
|
||||
} else if (tdGetBitmapValType(pCol->pBitmap, row, &(pVal->valType), bitmapMode) < 0) {
|
||||
return terrno;
|
||||
}
|
||||
|
||||
if (tdValTypeIsNorm(pVal->valType)) {
|
||||
if (IS_VAR_DATA_TYPE(pCol->type)) {
|
||||
pVal->val = POINTER_SHIFT(pCol->pData, pCol->dataOff[row]);
|
||||
} else {
|
||||
pVal->val = POINTER_SHIFT(pCol->pData, TYPE_BYTES[pCol->type] * row);
|
||||
}
|
||||
} else {
|
||||
pVal->valType = TD_VTYPE_NULL;
|
||||
#ifdef TD_SUPPORT_READ2
|
||||
pVal->val = (void *)getNullValue(pCol->type);
|
||||
#else
|
||||
pVal->val = NULL;
|
||||
#endif
|
||||
}
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
bool tdSTSRowIterNext(STSRowIter *pIter, col_id_t colId, col_type_t colType, SCellVal *pVal) {
|
||||
if (colId == PRIMARYKEY_TIMESTAMP_COL_ID) {
|
||||
pVal->val = &pIter->pRow->ts;
|
||||
|
|
|
@ -710,6 +710,32 @@ int64_t taosTimeAdd(int64_t t, int64_t duration, char unit, int32_t precision) {
|
|||
return (int64_t)(taosMktime(&tm) * TSDB_TICK_PER_SECOND(precision));
|
||||
}
|
||||
|
||||
int64_t taosTimeSub(int64_t t, int64_t duration, char unit, int32_t precision) {
|
||||
if (duration == 0) {
|
||||
return t;
|
||||
}
|
||||
|
||||
if (unit != 'n' && unit != 'y') {
|
||||
return t - duration;
|
||||
}
|
||||
|
||||
// The following code handles the y/n time duration
|
||||
int64_t numOfMonth = duration;
|
||||
if (unit == 'y') {
|
||||
numOfMonth *= 12;
|
||||
}
|
||||
|
||||
struct tm tm;
|
||||
time_t tt = (time_t)(t / TSDB_TICK_PER_SECOND(precision));
|
||||
taosLocalTime(&tt, &tm);
|
||||
int32_t mon = tm.tm_year * 12 + tm.tm_mon - (int32_t)numOfMonth;
|
||||
tm.tm_year = mon / 12;
|
||||
tm.tm_mon = mon % 12;
|
||||
|
||||
return (int64_t)(taosMktime(&tm) * TSDB_TICK_PER_SECOND(precision));
|
||||
}
|
||||
|
||||
|
||||
int32_t taosTimeCountInterval(int64_t skey, int64_t ekey, int64_t interval, char unit, int32_t precision) {
|
||||
if (ekey < skey) {
|
||||
int64_t tmp = ekey;
|
||||
|
|
|
@ -285,8 +285,8 @@ int32_t debugPrintSColVal(SColVal *cv, int8_t type) {
|
|||
}
|
||||
|
||||
void debugPrintTSRow(STSRow2 *row, STSchema *pTSchema, const char *tags, int32_t ln) {
|
||||
printf("%s:%d %s:v%d:%d ", tags, ln, (row->flags & 0xf0) ? "KV" : "TP", row->sver, row->nData);
|
||||
for (int16_t i = 0; i < schemaNCols(pTSchema); ++i) {
|
||||
// printf("%s:%d %s:v%d:%d ", tags, ln, (row->flags & 0xf0) ? "KV" : "TP", row->sver, row->nData);
|
||||
for (int16_t i = 0; i < pTSchema->numOfCols; ++i) {
|
||||
SColVal cv = {0};
|
||||
tTSRowGet(row, pTSchema, i, &cv);
|
||||
debugPrintSColVal(&cv, pTSchema->columns[i].type);
|
||||
|
@ -393,7 +393,7 @@ static int32_t checkSColVal(const char *rawVal, SColVal *cv, int8_t type) {
|
|||
}
|
||||
|
||||
static void checkTSRow(const char **data, STSRow2 *row, STSchema *pTSchema) {
|
||||
for (int16_t i = 0; i < schemaNCols(pTSchema); ++i) {
|
||||
for (int16_t i = 0; i < pTSchema->numOfCols; ++i) {
|
||||
SColVal cv = {0};
|
||||
tTSRowGet(row, pTSchema, i, &cv);
|
||||
checkSColVal(data[i], &cv, pTSchema->columns[i].type);
|
||||
|
|
|
@ -31,7 +31,8 @@ typedef struct SVnodeMgmt {
|
|||
const char *path;
|
||||
const char *name;
|
||||
SQWorkerPool queryPool;
|
||||
SQWorkerPool fetchPool;
|
||||
SQWorkerPool streamPool;
|
||||
SWWorkerPool fetchPool;
|
||||
SWWorkerPool syncPool;
|
||||
SWWorkerPool writePool;
|
||||
SWWorkerPool applyPool;
|
||||
|
@ -61,6 +62,7 @@ typedef struct {
|
|||
STaosQueue *pSyncQ;
|
||||
STaosQueue *pApplyQ;
|
||||
STaosQueue *pQueryQ;
|
||||
STaosQueue *pStreamQ;
|
||||
STaosQueue *pFetchQ;
|
||||
} SVnodeObj;
|
||||
|
||||
|
@ -105,6 +107,7 @@ int32_t vmPutMsgToWriteQueue(SVnodeMgmt *pMgmt, SRpcMsg *pMsg);
|
|||
int32_t vmPutMsgToSyncQueue(SVnodeMgmt *pMgmt, SRpcMsg *pMsg);
|
||||
int32_t vmPutMsgToQueryQueue(SVnodeMgmt *pMgmt, SRpcMsg *pMsg);
|
||||
int32_t vmPutMsgToFetchQueue(SVnodeMgmt *pMgmt, SRpcMsg *pMsg);
|
||||
int32_t vmPutMsgToStreamQueue(SVnodeMgmt *pMgmt, SRpcMsg *pMsg);
|
||||
int32_t vmPutMsgToMergeQueue(SVnodeMgmt *pMgmt, SRpcMsg *pMsg);
|
||||
int32_t vmPutMsgToMgmtQueue(SVnodeMgmt *pMgmt, SRpcMsg *pMsg);
|
||||
int32_t vmPutMsgToMonitorQueue(SVnodeMgmt *pMgmt, SRpcMsg *pMsg);
|
||||
|
|
|
@ -31,7 +31,7 @@ SVnodeObj **vmGetVnodeListFromHash(SVnodeMgmt *pMgmt, int32_t *numOfVnodes) {
|
|||
SVnodeObj *pVnode = *ppVnode;
|
||||
if (pVnode && num < size) {
|
||||
int32_t refCount = atomic_add_fetch_32(&pVnode->refCount, 1);
|
||||
// dTrace("vgId:%d, acquire vnode, refCount:%d", pVnode->vgId, refCount);
|
||||
// dTrace("vgId:%d, acquire vnode list, ref:%d", pVnode->vgId, refCount);
|
||||
pVnodes[num++] = (*ppVnode);
|
||||
pIter = taosHashIterate(pMgmt->hash, pIter);
|
||||
} else {
|
||||
|
|
|
@ -357,16 +357,16 @@ SArray *vmGetMsgHandles() {
|
|||
if (dmSetMgmtHandle(pArray, TDMT_VND_COMMIT, vmPutMsgToWriteQueue, 0) == NULL) goto _OVER;
|
||||
if (dmSetMgmtHandle(pArray, TDMT_SCH_QUERY_HEARTBEAT, vmPutMsgToFetchQueue, 0) == NULL) goto _OVER;
|
||||
|
||||
if (dmSetMgmtHandle(pArray, TDMT_VND_STREAM_TRIGGER, vmPutMsgToFetchQueue, 0) == NULL) goto _OVER;
|
||||
if (dmSetMgmtHandle(pArray, TDMT_VND_STREAM_TRIGGER, vmPutMsgToStreamQueue, 0) == NULL) goto _OVER;
|
||||
if (dmSetMgmtHandle(pArray, TDMT_STREAM_TASK_DROP, vmPutMsgToWriteQueue, 0) == NULL) goto _OVER;
|
||||
if (dmSetMgmtHandle(pArray, TDMT_STREAM_TASK_DEPLOY, vmPutMsgToWriteQueue, 0) == NULL) goto _OVER;
|
||||
if (dmSetMgmtHandle(pArray, TDMT_STREAM_TASK_RUN, vmPutMsgToFetchQueue, 0) == NULL) goto _OVER;
|
||||
if (dmSetMgmtHandle(pArray, TDMT_STREAM_TASK_DISPATCH, vmPutMsgToFetchQueue, 0) == NULL) goto _OVER;
|
||||
if (dmSetMgmtHandle(pArray, TDMT_STREAM_TASK_DISPATCH_RSP, vmPutMsgToFetchQueue, 0) == NULL) goto _OVER;
|
||||
if (dmSetMgmtHandle(pArray, TDMT_STREAM_TASK_RECOVER, vmPutMsgToFetchQueue, 0) == NULL) goto _OVER;
|
||||
if (dmSetMgmtHandle(pArray, TDMT_STREAM_TASK_RECOVER_RSP, vmPutMsgToFetchQueue, 0) == NULL) goto _OVER;
|
||||
if (dmSetMgmtHandle(pArray, TDMT_STREAM_RETRIEVE, vmPutMsgToFetchQueue, 0) == NULL) goto _OVER;
|
||||
if (dmSetMgmtHandle(pArray, TDMT_STREAM_RETRIEVE_RSP, vmPutMsgToFetchQueue, 0) == NULL) goto _OVER;
|
||||
if (dmSetMgmtHandle(pArray, TDMT_STREAM_TASK_RUN, vmPutMsgToStreamQueue, 0) == NULL) goto _OVER;
|
||||
if (dmSetMgmtHandle(pArray, TDMT_STREAM_TASK_DISPATCH, vmPutMsgToStreamQueue, 0) == NULL) goto _OVER;
|
||||
if (dmSetMgmtHandle(pArray, TDMT_STREAM_TASK_DISPATCH_RSP, vmPutMsgToStreamQueue, 0) == NULL) goto _OVER;
|
||||
if (dmSetMgmtHandle(pArray, TDMT_STREAM_TASK_RECOVER, vmPutMsgToStreamQueue, 0) == NULL) goto _OVER;
|
||||
if (dmSetMgmtHandle(pArray, TDMT_STREAM_TASK_RECOVER_RSP, vmPutMsgToStreamQueue, 0) == NULL) goto _OVER;
|
||||
if (dmSetMgmtHandle(pArray, TDMT_STREAM_RETRIEVE, vmPutMsgToStreamQueue, 0) == NULL) goto _OVER;
|
||||
if (dmSetMgmtHandle(pArray, TDMT_STREAM_RETRIEVE_RSP, vmPutMsgToStreamQueue, 0) == NULL) goto _OVER;
|
||||
|
||||
if (dmSetMgmtHandle(pArray, TDMT_VND_ALTER_REPLICA, vmPutMsgToWriteQueue, 0) == NULL) goto _OVER;
|
||||
if (dmSetMgmtHandle(pArray, TDMT_VND_ALTER_CONFIG, vmPutMsgToWriteQueue, 0) == NULL) goto _OVER;
|
||||
|
|
|
@ -23,6 +23,7 @@ SVnodeObj *vmAcquireVnode(SVnodeMgmt *pMgmt, int32_t vgId) {
|
|||
taosHashGetDup(pMgmt->hash, &vgId, sizeof(int32_t), (void *)&pVnode);
|
||||
if (pVnode == NULL || pVnode->dropped) {
|
||||
terrno = TSDB_CODE_VND_INVALID_VGROUP_ID;
|
||||
pVnode = NULL;
|
||||
} else {
|
||||
int32_t refCount = atomic_add_fetch_32(&pVnode->refCount, 1);
|
||||
// dTrace("vgId:%d, acquire vnode, ref:%d", pVnode->vgId, refCount);
|
||||
|
@ -82,6 +83,7 @@ void vmCloseVnode(SVnodeMgmt *pMgmt, SVnodeObj *pVnode) {
|
|||
taosThreadRwlockUnlock(&pMgmt->lock);
|
||||
vmReleaseVnode(pMgmt, pVnode);
|
||||
|
||||
dTrace("vgId:%d, wait for vnode ref become 0", pVnode->vgId);
|
||||
while (pVnode->refCount > 0) taosMsleep(10);
|
||||
dTrace("vgId:%d, wait for vnode queue is empty", pVnode->vgId);
|
||||
|
||||
|
@ -90,6 +92,7 @@ void vmCloseVnode(SVnodeMgmt *pMgmt, SVnodeObj *pVnode) {
|
|||
while (!taosQueueEmpty(pVnode->pApplyQ)) taosMsleep(10);
|
||||
while (!taosQueueEmpty(pVnode->pQueryQ)) taosMsleep(10);
|
||||
while (!taosQueueEmpty(pVnode->pFetchQ)) taosMsleep(10);
|
||||
while (!taosQueueEmpty(pVnode->pStreamQ)) taosMsleep(10);
|
||||
dTrace("vgId:%d, vnode queue is empty", pVnode->vgId);
|
||||
|
||||
vmFreeQueue(pMgmt, pVnode);
|
||||
|
|
|
@ -81,15 +81,15 @@ static void vmProcessQueryQueue(SQueueInfo *pInfo, SRpcMsg *pMsg) {
|
|||
taosFreeQitem(pMsg);
|
||||
}
|
||||
|
||||
static void vmProcessFetchQueue(SQueueInfo *pInfo, SRpcMsg *pMsg) {
|
||||
static void vmProcessStreamQueue(SQueueInfo *pInfo, SRpcMsg *pMsg) {
|
||||
SVnodeObj *pVnode = pInfo->ahandle;
|
||||
const STraceId *trace = &pMsg->info.traceId;
|
||||
|
||||
dGTrace("vgId:%d, msg:%p get from vnode-fetch queue", pVnode->vgId, pMsg);
|
||||
dGTrace("vgId:%d, msg:%p get from vnode-stream queue", pVnode->vgId, pMsg);
|
||||
int32_t code = vnodeProcessFetchMsg(pVnode->pImpl, pMsg, pInfo);
|
||||
if (code != 0) {
|
||||
if (terrno != 0) code = terrno;
|
||||
dGError("vgId:%d, msg:%p failed to fetch since %s", pVnode->vgId, pMsg, terrstr());
|
||||
dGError("vgId:%d, msg:%p failed to stream since %s", pVnode->vgId, pMsg, terrstr());
|
||||
vmSendRsp(pMsg, code);
|
||||
}
|
||||
|
||||
|
@ -98,6 +98,28 @@ static void vmProcessFetchQueue(SQueueInfo *pInfo, SRpcMsg *pMsg) {
|
|||
taosFreeQitem(pMsg);
|
||||
}
|
||||
|
||||
static void vmProcessFetchQueue(SQueueInfo *pInfo, STaosQall *qall, int32_t numOfMsgs) {
|
||||
SVnodeObj *pVnode = pInfo->ahandle;
|
||||
SRpcMsg *pMsg = NULL;
|
||||
|
||||
for (int32_t i = 0; i < numOfMsgs; ++i) {
|
||||
if (taosGetQitem(qall, (void **)&pMsg) == 0) continue;
|
||||
const STraceId *trace = &pMsg->info.traceId;
|
||||
dGTrace("vgId:%d, msg:%p get from vnode-fetch queue", pVnode->vgId, pMsg);
|
||||
|
||||
int32_t code = vnodeProcessFetchMsg(pVnode->pImpl, pMsg, pInfo);
|
||||
if (code != 0) {
|
||||
if (terrno != 0) code = terrno;
|
||||
dGError("vgId:%d, msg:%p failed to fetch since %s", pVnode->vgId, pMsg, terrstr());
|
||||
vmSendRsp(pMsg, code);
|
||||
}
|
||||
|
||||
dGTrace("vgId:%d, msg:%p is freed, code:0x%x", pVnode->vgId, pMsg, code);
|
||||
rpcFreeCont(pMsg->pCont);
|
||||
taosFreeQitem(pMsg);
|
||||
}
|
||||
}
|
||||
|
||||
static void vmProcessSyncQueue(SQueueInfo *pInfo, STaosQall *qall, int32_t numOfMsgs) {
|
||||
SVnodeObj *pVnode = pInfo->ahandle;
|
||||
SRpcMsg *pMsg = NULL;
|
||||
|
@ -135,6 +157,10 @@ static int32_t vmPutMsgToQueue(SVnodeMgmt *pMgmt, SRpcMsg *pMsg, EQueueType qtyp
|
|||
dGTrace("vgId:%d, msg:%p put into vnode-query queue", pVnode->vgId, pMsg);
|
||||
taosWriteQitem(pVnode->pQueryQ, pMsg);
|
||||
break;
|
||||
case STREAM_QUEUE:
|
||||
dGTrace("vgId:%d, msg:%p put into vnode-stream queue", pVnode->vgId, pMsg);
|
||||
taosWriteQitem(pVnode->pStreamQ, pMsg);
|
||||
break;
|
||||
case FETCH_QUEUE:
|
||||
dGTrace("vgId:%d, msg:%p put into vnode-fetch queue", pVnode->vgId, pMsg);
|
||||
taosWriteQitem(pVnode->pFetchQ, pMsg);
|
||||
|
@ -169,6 +195,8 @@ int32_t vmPutMsgToQueryQueue(SVnodeMgmt *pMgmt, SRpcMsg *pMsg) { return vmPutMsg
|
|||
|
||||
int32_t vmPutMsgToFetchQueue(SVnodeMgmt *pMgmt, SRpcMsg *pMsg) { return vmPutMsgToQueue(pMgmt, pMsg, FETCH_QUEUE); }
|
||||
|
||||
int32_t vmPutMsgToStreamQueue(SVnodeMgmt *pMgmt, SRpcMsg *pMsg) { return vmPutMsgToQueue(pMgmt, pMsg, STREAM_QUEUE); }
|
||||
|
||||
int32_t vmPutMsgToMgmtQueue(SVnodeMgmt *pMgmt, SRpcMsg *pMsg) {
|
||||
const STraceId *trace = &pMsg->info.traceId;
|
||||
dGTrace("msg:%p, put into vnode-mgmt queue", pMsg);
|
||||
|
@ -201,9 +229,9 @@ int32_t vmPutRpcMsgToQueue(SVnodeMgmt *pMgmt, EQueueType qtype, SRpcMsg *pRpc) {
|
|||
int32_t code = vmPutMsgToQueue(pMgmt, pMsg, qtype);
|
||||
if (code != 0) {
|
||||
dTrace("msg:%p, is freed", pMsg);
|
||||
taosFreeQitem(pMsg);
|
||||
rpcFreeCont(pMsg->pCont);
|
||||
pRpc->pCont = NULL;
|
||||
taosFreeQitem(pMsg);
|
||||
}
|
||||
|
||||
return code;
|
||||
|
@ -229,11 +257,14 @@ int32_t vmGetQueueSize(SVnodeMgmt *pMgmt, int32_t vgId, EQueueType qtype) {
|
|||
case FETCH_QUEUE:
|
||||
size = taosQueueItemSize(pVnode->pFetchQ);
|
||||
break;
|
||||
case STREAM_QUEUE:
|
||||
size = taosQueueItemSize(pVnode->pStreamQ);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
vmReleaseVnode(pMgmt, pVnode);
|
||||
}
|
||||
vmReleaseVnode(pMgmt, pVnode);
|
||||
return size;
|
||||
}
|
||||
|
||||
|
@ -242,15 +273,21 @@ int32_t vmAllocQueue(SVnodeMgmt *pMgmt, SVnodeObj *pVnode) {
|
|||
pVnode->pSyncQ = tWWorkerAllocQueue(&pMgmt->syncPool, pVnode, (FItems)vmProcessSyncQueue);
|
||||
pVnode->pApplyQ = tWWorkerAllocQueue(&pMgmt->applyPool, pVnode->pImpl, (FItems)vnodeApplyWriteMsg);
|
||||
pVnode->pQueryQ = tQWorkerAllocQueue(&pMgmt->queryPool, pVnode, (FItem)vmProcessQueryQueue);
|
||||
pVnode->pFetchQ = tQWorkerAllocQueue(&pMgmt->fetchPool, pVnode, (FItem)vmProcessFetchQueue);
|
||||
pVnode->pStreamQ = tQWorkerAllocQueue(&pMgmt->streamPool, pVnode, (FItem)vmProcessStreamQueue);
|
||||
pVnode->pFetchQ = tWWorkerAllocQueue(&pMgmt->fetchPool, pVnode, (FItems)vmProcessFetchQueue);
|
||||
|
||||
if (pVnode->pWriteQ == NULL || pVnode->pSyncQ == NULL || pVnode->pApplyQ == NULL || pVnode->pQueryQ == NULL ||
|
||||
pVnode->pFetchQ == NULL) {
|
||||
pVnode->pStreamQ == NULL || pVnode->pFetchQ == NULL) {
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
return -1;
|
||||
}
|
||||
|
||||
dDebug("vgId:%d, queue is alloced", pVnode->vgId);
|
||||
dDebug("vgId:%d, write-queue:%p is alloced", pVnode->vgId, pVnode->pWriteQ);
|
||||
dDebug("vgId:%d, sync-queue:%p is alloced", pVnode->vgId, pVnode->pSyncQ);
|
||||
dDebug("vgId:%d, apply-queue:%p is alloced", pVnode->vgId, pVnode->pApplyQ);
|
||||
dDebug("vgId:%d, query-queue:%p is alloced", pVnode->vgId, pVnode->pQueryQ);
|
||||
dDebug("vgId:%d, stream-queue:%p is alloced", pVnode->vgId, pVnode->pStreamQ);
|
||||
dDebug("vgId:%d, fetch-queue:%p is alloced", pVnode->vgId, pVnode->pFetchQ);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -259,11 +296,13 @@ void vmFreeQueue(SVnodeMgmt *pMgmt, SVnodeObj *pVnode) {
|
|||
tWWorkerFreeQueue(&pMgmt->applyPool, pVnode->pApplyQ);
|
||||
tWWorkerFreeQueue(&pMgmt->syncPool, pVnode->pSyncQ);
|
||||
tQWorkerFreeQueue(&pMgmt->queryPool, pVnode->pQueryQ);
|
||||
tQWorkerFreeQueue(&pMgmt->fetchPool, pVnode->pFetchQ);
|
||||
tQWorkerFreeQueue(&pMgmt->streamPool, pVnode->pStreamQ);
|
||||
tWWorkerFreeQueue(&pMgmt->fetchPool, pVnode->pFetchQ);
|
||||
pVnode->pWriteQ = NULL;
|
||||
pVnode->pSyncQ = NULL;
|
||||
pVnode->pApplyQ = NULL;
|
||||
pVnode->pQueryQ = NULL;
|
||||
pVnode->pStreamQ = NULL;
|
||||
pVnode->pFetchQ = NULL;
|
||||
dDebug("vgId:%d, queue is freed", pVnode->vgId);
|
||||
}
|
||||
|
@ -275,11 +314,16 @@ int32_t vmStartWorker(SVnodeMgmt *pMgmt) {
|
|||
pQPool->max = tsNumOfVnodeQueryThreads;
|
||||
if (tQWorkerInit(pQPool) != 0) return -1;
|
||||
|
||||
SQWorkerPool *pFPool = &pMgmt->fetchPool;
|
||||
SQWorkerPool *pStreamPool = &pMgmt->streamPool;
|
||||
pStreamPool->name = "vnode-stream";
|
||||
pStreamPool->min = tsNumOfVnodeStreamThreads;
|
||||
pStreamPool->max = tsNumOfVnodeStreamThreads;
|
||||
if (tQWorkerInit(pStreamPool) != 0) return -1;
|
||||
|
||||
SWWorkerPool *pFPool = &pMgmt->fetchPool;
|
||||
pFPool->name = "vnode-fetch";
|
||||
pFPool->min = tsNumOfVnodeFetchThreads;
|
||||
pFPool->max = tsNumOfVnodeFetchThreads;
|
||||
if (tQWorkerInit(pFPool) != 0) return -1;
|
||||
if (tWWorkerInit(pFPool) != 0) return -1;
|
||||
|
||||
SWWorkerPool *pWPool = &pMgmt->writePool;
|
||||
pWPool->name = "vnode-write";
|
||||
|
@ -325,6 +369,7 @@ void vmStopWorker(SVnodeMgmt *pMgmt) {
|
|||
tWWorkerCleanup(&pMgmt->applyPool);
|
||||
tWWorkerCleanup(&pMgmt->syncPool);
|
||||
tQWorkerCleanup(&pMgmt->queryPool);
|
||||
tQWorkerCleanup(&pMgmt->fetchPool);
|
||||
tQWorkerCleanup(&pMgmt->streamPool);
|
||||
tWWorkerCleanup(&pMgmt->fetchPool);
|
||||
dDebug("vnode workers are closed");
|
||||
}
|
||||
|
|
|
@ -781,7 +781,13 @@ _OVER:
|
|||
}
|
||||
|
||||
static int32_t mndProcessConfigDnodeReq(SRpcMsg *pReq) {
|
||||
SMnode *pMnode = pReq->info.node;
|
||||
SMnode *pMnode = pReq->info.node;
|
||||
const char *options[] = {
|
||||
"debugFlag", "dDebugFlag", "vDebugFlag", "mDebugFlag", "wDebugFlag", "sDebugFlag",
|
||||
"tsdbDebugFlag", "tqDebugFlag", "fsDebugFlag", "udfDebugFlag", "smaDebugFlag", "idxDebugFlag",
|
||||
"tmrDebugFlag", "uDebugFlag", "smaDebugFlag", "rpcDebugFlag", "qDebugFlag",
|
||||
};
|
||||
int32_t optionSize = tListLen(options);
|
||||
|
||||
SMCfgDnodeReq cfgReq = {0};
|
||||
if (tDeserializeSMCfgDnodeReq(pReq->pCont, pReq->contLen, &cfgReq) != 0) {
|
||||
|
@ -802,27 +808,52 @@ static int32_t mndProcessConfigDnodeReq(SRpcMsg *pReq) {
|
|||
SEpSet epSet = mndGetDnodeEpset(pDnode);
|
||||
mndReleaseDnode(pMnode, pDnode);
|
||||
|
||||
|
||||
SDCfgDnodeReq dcfgReq = {0};
|
||||
if (strncasecmp(cfgReq.config, "debugFlag", 9) == 0) {
|
||||
if (strcasecmp(cfgReq.config, "resetlog") == 0) {
|
||||
strcpy(dcfgReq.config, "resetlog");
|
||||
} else if (strncasecmp(cfgReq.config, "monitor", 7) == 0) {
|
||||
const char *value = cfgReq.value;
|
||||
int32_t flag = atoi(value);
|
||||
if (flag <= 0) {
|
||||
flag = atoi(cfgReq.config + 10);
|
||||
flag = atoi(cfgReq.config + 8);
|
||||
}
|
||||
if (flag <= 0 || flag > 255) {
|
||||
mError("dnode:%d, failed to config debugFlag since value:%d", cfgReq.dnodeId, flag);
|
||||
if (flag < 0 || flag > 2) {
|
||||
mError("dnode:%d, failed to config monitor since value:%d", cfgReq.dnodeId, flag);
|
||||
terrno = TSDB_CODE_INVALID_CFG;
|
||||
return -1;
|
||||
}
|
||||
|
||||
strcpy(dcfgReq.config, "debugFlag");
|
||||
strcpy(dcfgReq.config, "monitor");
|
||||
snprintf(dcfgReq.value, TSDB_DNODE_VALUE_LEN, "%d", flag);
|
||||
} else if (strcasecmp(cfgReq.config, "resetlog") == 0) {
|
||||
strcpy(dcfgReq.config, "resetlog");
|
||||
} else {
|
||||
terrno = TSDB_CODE_INVALID_CFG;
|
||||
mError("dnode:%d, failed to config since %s", cfgReq.dnodeId, terrstr());
|
||||
return -1;
|
||||
bool findOpt = false;
|
||||
for (int32_t d = 0; d < optionSize; ++d) {
|
||||
const char *optName = options[d];
|
||||
int32_t optLen = strlen(optName);
|
||||
if (strncasecmp(cfgReq.config, optName, optLen) != 0) continue;
|
||||
|
||||
const char *value = cfgReq.value;
|
||||
int32_t flag = atoi(value);
|
||||
if (flag <= 0) {
|
||||
flag = atoi(cfgReq.config + optLen + 1);
|
||||
}
|
||||
if (flag <= 0 || flag > 255) {
|
||||
mError("dnode:%d, failed to config %s since value:%d", cfgReq.dnodeId, optName, flag);
|
||||
terrno = TSDB_CODE_INVALID_CFG;
|
||||
return -1;
|
||||
}
|
||||
|
||||
tstrncpy(dcfgReq.config, optName, optLen + 1);
|
||||
snprintf(dcfgReq.value, TSDB_DNODE_VALUE_LEN, "%d", flag);
|
||||
findOpt = true;
|
||||
}
|
||||
|
||||
if (!findOpt) {
|
||||
terrno = TSDB_CODE_INVALID_CFG;
|
||||
mError("dnode:%d, failed to config since %s", cfgReq.dnodeId, terrstr());
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
int32_t bufLen = tSerializeSDCfgDnodeReq(NULL, 0, &dcfgReq);
|
||||
|
@ -831,13 +862,14 @@ static int32_t mndProcessConfigDnodeReq(SRpcMsg *pReq) {
|
|||
if (pBuf == NULL) return -1;
|
||||
tSerializeSDCfgDnodeReq(pBuf, bufLen, &dcfgReq);
|
||||
|
||||
mDebug("dnode:%d, send config req to dnode, app:%p", cfgReq.dnodeId, pReq->info.ahandle);
|
||||
mInfo("dnode:%d, send config req to dnode, app:%p config:%s value:%s", cfgReq.dnodeId, pReq->info.ahandle,
|
||||
dcfgReq.config, dcfgReq.value);
|
||||
SRpcMsg rpcMsg = {.msgType = TDMT_DND_CONFIG_DNODE, .pCont = pBuf, .contLen = bufLen};
|
||||
return tmsgSendReq(&epSet, &rpcMsg);
|
||||
}
|
||||
|
||||
static int32_t mndProcessConfigDnodeRsp(SRpcMsg *pRsp) {
|
||||
mDebug("config rsp from dnode, app:%p", pRsp->info.ahandle);
|
||||
mInfo("config rsp from dnode, app:%p", pRsp->info.ahandle);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
|
@ -218,6 +218,7 @@ bool mndIsMnode(SMnode *pMnode, int32_t dnodeId) {
|
|||
}
|
||||
|
||||
void mndGetMnodeEpSet(SMnode *pMnode, SEpSet *pEpSet) {
|
||||
#if 0
|
||||
SSdb *pSdb = pMnode->pSdb;
|
||||
int32_t totalMnodes = sdbGetSize(pSdb, SDB_MNODE);
|
||||
void *pIter = NULL;
|
||||
|
@ -237,6 +238,9 @@ void mndGetMnodeEpSet(SMnode *pMnode, SEpSet *pEpSet) {
|
|||
addEpIntoEpSet(pEpSet, pObj->pDnode->fqdn, pObj->pDnode->port);
|
||||
sdbRelease(pSdb, pObj);
|
||||
}
|
||||
#else
|
||||
syncGetRetryEpSet(pMnode->syncMgmt.sync, pEpSet);
|
||||
#endif
|
||||
}
|
||||
|
||||
static int32_t mndSetCreateMnodeRedoLogs(SMnode *pMnode, STrans *pTrans, SMnodeObj *pObj) {
|
||||
|
|
|
@ -56,20 +56,22 @@ void mndSyncCommitMsg(struct SSyncFSM *pFsm, const SRpcMsg *pMsg, SFsmCbMeta cbM
|
|||
sdbSetApplyInfo(pMnode->pSdb, cbMeta.index, cbMeta.term, cbMeta.lastConfigIndex);
|
||||
}
|
||||
|
||||
if (pMgmt->transId == transId) {
|
||||
if (pMgmt->transId == transId && transId != 0) {
|
||||
if (pMgmt->errCode != 0) {
|
||||
mError("trans:%d, failed to propose since %s", transId, tstrerror(pMgmt->errCode));
|
||||
}
|
||||
pMgmt->transId = 0;
|
||||
tsem_post(&pMgmt->syncSem);
|
||||
} else {
|
||||
#if 1
|
||||
mError("trans:%d, invalid commit msg since trandId not match with %d", transId, pMgmt->transId);
|
||||
#else
|
||||
STrans *pTrans = mndAcquireTrans(pMnode, transId);
|
||||
if (pTrans != NULL) {
|
||||
mndTransExecute(pMnode, pTrans);
|
||||
mndReleaseTrans(pMnode, pTrans);
|
||||
}
|
||||
#if 0
|
||||
sdbWriteFile(pMnode->pSdb, SDB_WRITE_DELTA);
|
||||
// sdbWriteFile(pMnode->pSdb, SDB_WRITE_DELTA);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
|
|
@ -137,9 +137,8 @@ int64_t tsdbGetNumOfRowsInMemTable(STsdbReader *pHandle);
|
|||
void *tsdbGetIdx(SMeta *pMeta);
|
||||
void *tsdbGetIvtIdx(SMeta *pMeta);
|
||||
|
||||
int32_t tsdbLastRowReaderOpen(void *pVnode, int32_t type, SArray *pTableIdList, int32_t *colId, int32_t numOfCols,
|
||||
void **pReader);
|
||||
int32_t tsdbRetrieveLastRow(void *pReader, SSDataBlock *pResBlock, const int32_t *slotIds);
|
||||
int32_t tsdbLastRowReaderOpen(void *pVnode, int32_t type, SArray *pTableIdList, int32_t numOfCols, void **pReader);
|
||||
int32_t tsdbRetrieveLastRow(void *pReader, SSDataBlock *pResBlock, const int32_t *slotIds, SArray* pTableUids);
|
||||
int32_t tsdbLastrowReaderClose(void *pReader);
|
||||
int32_t tsdbGetTableSchema(SVnode *pVnode, int64_t uid, STSchema **pSchema, int64_t *suid);
|
||||
|
||||
|
|
|
@ -89,8 +89,6 @@ typedef struct {
|
|||
STqExecTb execTb;
|
||||
STqExecDb execDb;
|
||||
};
|
||||
// TODO remove it
|
||||
int64_t tsdbEndVer;
|
||||
|
||||
} STqExecHandle;
|
||||
|
||||
|
@ -101,6 +99,8 @@ typedef struct {
|
|||
int32_t epoch;
|
||||
int8_t fetchMeta;
|
||||
|
||||
int64_t snapshotVer;
|
||||
|
||||
// TODO remove
|
||||
SWalReader* pWalReader;
|
||||
|
||||
|
@ -131,7 +131,7 @@ typedef struct {
|
|||
static STqMgmt tqMgmt = {0};
|
||||
|
||||
// tqRead
|
||||
int64_t tqScan(STQ* pTq, const STqExecHandle* pExec, SMqDataRsp* pRsp, STqOffsetVal* offset);
|
||||
int64_t tqScan(STQ* pTq, const STqHandle* pHandle, SMqDataRsp* pRsp, STqOffsetVal* offset);
|
||||
int64_t tqFetchLog(STQ* pTq, STqHandle* pHandle, int64_t* fetchOffset, SWalCkHead** pHeadWithCkSum);
|
||||
|
||||
// tqExec
|
||||
|
|
|
@ -244,6 +244,9 @@ int32_t tqProcessPollReq(STQ* pTq, SRpcMsg* pMsg, int32_t workerId) {
|
|||
STqOffsetVal reqOffset = pReq->reqOffset;
|
||||
STqOffsetVal fetchOffsetNew;
|
||||
|
||||
// todo
|
||||
workerId = 0;
|
||||
|
||||
// 1.find handle
|
||||
STqHandle* pHandle = taosHashGet(pTq->handles, pReq->subKey, strlen(pReq->subKey));
|
||||
/*ASSERT(pHandle);*/
|
||||
|
@ -284,7 +287,8 @@ int32_t tqProcessPollReq(STQ* pTq, SRpcMsg* pMsg, int32_t workerId) {
|
|||
fetchOffsetNew = pOffset->val;
|
||||
char formatBuf[80];
|
||||
tFormatOffset(formatBuf, 80, &fetchOffsetNew);
|
||||
tqDebug("tmq poll: consumer %" PRId64 ", subkey %s, offset reset to %s", consumerId, pHandle->subKey, formatBuf);
|
||||
tqDebug("tmq poll: consumer %" PRId64 ", subkey %s, vg %d, offset reset to %s", consumerId, pHandle->subKey,
|
||||
TD_VID(pTq->pVnode), formatBuf);
|
||||
} else {
|
||||
if (reqOffset.type == TMQ_OFFSET__RESET_EARLIEAST) {
|
||||
if (pReq->useSnapshot && pHandle->execHandle.subType == TOPIC_SUB_TYPE__COLUMN) {
|
||||
|
@ -299,8 +303,8 @@ int32_t tqProcessPollReq(STQ* pTq, SRpcMsg* pMsg, int32_t workerId) {
|
|||
}
|
||||
} else if (reqOffset.type == TMQ_OFFSET__RESET_LATEST) {
|
||||
tqOffsetResetToLog(&dataRsp.rspOffset, walGetLastVer(pTq->pVnode->pWal));
|
||||
tqDebug("tmq poll: consumer %ld, subkey %s, offset reset to %ld", consumerId, pHandle->subKey,
|
||||
dataRsp.rspOffset.version);
|
||||
tqDebug("tmq poll: consumer %ld, subkey %s, vg %d, offset reset to %ld", consumerId, pHandle->subKey,
|
||||
TD_VID(pTq->pVnode), dataRsp.rspOffset.version);
|
||||
if (tqSendDataRsp(pTq, pMsg, pReq, &dataRsp) < 0) {
|
||||
code = -1;
|
||||
}
|
||||
|
@ -318,10 +322,10 @@ int32_t tqProcessPollReq(STQ* pTq, SRpcMsg* pMsg, int32_t workerId) {
|
|||
|
||||
// 3.query
|
||||
if (pHandle->execHandle.subType == TOPIC_SUB_TYPE__COLUMN) {
|
||||
if (fetchOffsetNew.type == TMQ_OFFSET__LOG) {
|
||||
fetchOffsetNew.version++;
|
||||
}
|
||||
if (tqScan(pTq, &pHandle->execHandle, &dataRsp, &fetchOffsetNew) < 0) {
|
||||
/*if (fetchOffsetNew.type == TMQ_OFFSET__LOG) {*/
|
||||
/*fetchOffsetNew.version++;*/
|
||||
/*}*/
|
||||
if (tqScan(pTq, pHandle, &dataRsp, &fetchOffsetNew) < 0) {
|
||||
ASSERT(0);
|
||||
code = -1;
|
||||
goto OVER;
|
||||
|
@ -480,30 +484,28 @@ int32_t tqProcessVgChangeReq(STQ* pTq, char* msg, int32_t msgLen) {
|
|||
pHandle->fetchMeta = req.withMeta;
|
||||
|
||||
pHandle->pWalReader = walOpenReader(pTq->pVnode->pWal, NULL);
|
||||
/*for (int32_t i = 0; i < 5; i++) {*/
|
||||
/*pHandle->execHandle.pExecReader[i] = tqOpenReader(pTq->pVnode);*/
|
||||
/*}*/
|
||||
|
||||
// TODO version should be assigned in preprocess
|
||||
int64_t ver = walGetCommittedVer(pTq->pVnode->pWal);
|
||||
if (pHandle->execHandle.subType == TOPIC_SUB_TYPE__COLUMN) {
|
||||
pHandle->execHandle.execCol.qmsg = req.qmsg;
|
||||
pHandle->snapshotVer = ver;
|
||||
req.qmsg = NULL;
|
||||
for (int32_t i = 0; i < 5; i++) {
|
||||
SReadHandle handle = {
|
||||
.tqReader = pHandle->execHandle.pExecReader[i],
|
||||
.meta = pTq->pVnode->pMeta,
|
||||
.vnode = pTq->pVnode,
|
||||
.initTableReader = true,
|
||||
.initTqReader = true,
|
||||
.version = ver,
|
||||
};
|
||||
pHandle->execHandle.execCol.task[i] = qCreateStreamExecTaskInfo(pHandle->execHandle.execCol.qmsg, &handle);
|
||||
pHandle->execHandle.execCol.task[i] = qCreateQueueExecTaskInfo(pHandle->execHandle.execCol.qmsg, &handle);
|
||||
ASSERT(pHandle->execHandle.execCol.task[i]);
|
||||
void* scanner = NULL;
|
||||
qExtractStreamScanner(pHandle->execHandle.execCol.task[i], &scanner);
|
||||
ASSERT(scanner);
|
||||
pHandle->execHandle.pExecReader[i] = qExtractReaderFromStreamScanner(scanner);
|
||||
ASSERT(pHandle->execHandle.pExecReader[i]);
|
||||
pHandle->execHandle.tsdbEndVer = ver;
|
||||
}
|
||||
} else if (pHandle->execHandle.subType == TOPIC_SUB_TYPE__DB) {
|
||||
for (int32_t i = 0; i < 5; i++) {
|
||||
|
|
|
@ -59,13 +59,13 @@ static int32_t tqAddTbNameToRsp(const STQ* pTq, int64_t uid, SMqDataRsp* pRsp) {
|
|||
return 0;
|
||||
}
|
||||
|
||||
int64_t tqScan(STQ* pTq, const STqExecHandle* pExec, SMqDataRsp* pRsp, STqOffsetVal* pOffset) {
|
||||
qTaskInfo_t task = pExec->execCol.task[0];
|
||||
int64_t tqScan(STQ* pTq, const STqHandle* pHandle, SMqDataRsp* pRsp, STqOffsetVal* pOffset) {
|
||||
const STqExecHandle* pExec = &pHandle->execHandle;
|
||||
qTaskInfo_t task = pExec->execCol.task[0];
|
||||
|
||||
if (qStreamPrepareScan(task, pOffset) < 0) {
|
||||
ASSERT(pOffset->type == TMQ_OFFSET__LOG);
|
||||
pRsp->rspOffset = *pOffset;
|
||||
pRsp->rspOffset.version--;
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -73,9 +73,11 @@ int64_t tqScan(STQ* pTq, const STqExecHandle* pExec, SMqDataRsp* pRsp, STqOffset
|
|||
while (1) {
|
||||
SSDataBlock* pDataBlock = NULL;
|
||||
uint64_t ts = 0;
|
||||
tqDebug("task start to execute");
|
||||
if (qExecTask(task, &pDataBlock, &ts) < 0) {
|
||||
ASSERT(0);
|
||||
}
|
||||
tqDebug("task execute end, get %p", pDataBlock);
|
||||
|
||||
if (pDataBlock != NULL) {
|
||||
tqAddBlockDataToRsp(pDataBlock, pRsp);
|
||||
|
@ -97,7 +99,7 @@ int64_t tqScan(STQ* pTq, const STqExecHandle* pExec, SMqDataRsp* pRsp, STqOffset
|
|||
}
|
||||
|
||||
if (pRsp->blockNum == 0 && pOffset->type == TMQ_OFFSET__SNAPSHOT_DATA) {
|
||||
tqOffsetResetToLog(pOffset, pExec->tsdbEndVer + 1);
|
||||
tqOffsetResetToLog(pOffset, pHandle->snapshotVer + 1);
|
||||
qStreamPrepareScan(task, pOffset);
|
||||
continue;
|
||||
}
|
||||
|
@ -116,7 +118,7 @@ int64_t tqScan(STQ* pTq, const STqExecHandle* pExec, SMqDataRsp* pRsp, STqOffset
|
|||
if (pRsp->reqOffset.type == TMQ_OFFSET__LOG) {
|
||||
ASSERT(pRsp->rspOffset.version + 1 >= pRsp->reqOffset.version);
|
||||
}
|
||||
|
||||
tqDebug("task exec exited");
|
||||
break;
|
||||
}
|
||||
|
||||
|
|
|
@ -19,6 +19,7 @@ static int32_t tEncodeSTqHandle(SEncoder* pEncoder, const STqHandle* pHandle) {
|
|||
if (tStartEncode(pEncoder) < 0) return -1;
|
||||
if (tEncodeCStr(pEncoder, pHandle->subKey) < 0) return -1;
|
||||
if (tEncodeI64(pEncoder, pHandle->consumerId) < 0) return -1;
|
||||
if (tEncodeI64(pEncoder, pHandle->snapshotVer) < 0) return -1;
|
||||
if (tEncodeI32(pEncoder, pHandle->epoch) < 0) return -1;
|
||||
if (tEncodeI8(pEncoder, pHandle->execHandle.subType) < 0) return -1;
|
||||
if (pHandle->execHandle.subType == TOPIC_SUB_TYPE__COLUMN) {
|
||||
|
@ -32,6 +33,7 @@ static int32_t tDecodeSTqHandle(SDecoder* pDecoder, STqHandle* pHandle) {
|
|||
if (tStartDecode(pDecoder) < 0) return -1;
|
||||
if (tDecodeCStrTo(pDecoder, pHandle->subKey) < 0) return -1;
|
||||
if (tDecodeI64(pDecoder, &pHandle->consumerId) < 0) return -1;
|
||||
if (tDecodeI64(pDecoder, &pHandle->snapshotVer) < 0) return -1;
|
||||
if (tDecodeI32(pDecoder, &pHandle->epoch) < 0) return -1;
|
||||
if (tDecodeI8(pDecoder, &pHandle->execHandle.subType) < 0) return -1;
|
||||
if (pHandle->execHandle.subType == TOPIC_SUB_TYPE__COLUMN) {
|
||||
|
@ -78,19 +80,25 @@ int32_t tqMetaOpen(STQ* pTq) {
|
|||
tDecoderInit(&decoder, (uint8_t*)pVal, vLen);
|
||||
tDecodeSTqHandle(&decoder, &handle);
|
||||
handle.pWalReader = walOpenReader(pTq->pVnode->pWal, NULL);
|
||||
for (int32_t i = 0; i < 5; i++) {
|
||||
handle.execHandle.pExecReader[i] = tqOpenReader(pTq->pVnode);
|
||||
}
|
||||
/*for (int32_t i = 0; i < 5; i++) {*/
|
||||
/*handle.execHandle.pExecReader[i] = tqOpenReader(pTq->pVnode);*/
|
||||
/*}*/
|
||||
if (handle.execHandle.subType == TOPIC_SUB_TYPE__COLUMN) {
|
||||
for (int32_t i = 0; i < 5; i++) {
|
||||
SReadHandle reader = {
|
||||
.tqReader = handle.execHandle.pExecReader[i],
|
||||
.meta = pTq->pVnode->pMeta,
|
||||
.pMsgCb = &pTq->pVnode->msgCb,
|
||||
.vnode = pTq->pVnode,
|
||||
.initTableReader = true,
|
||||
.initTqReader = true,
|
||||
.version = handle.snapshotVer,
|
||||
};
|
||||
handle.execHandle.execCol.task[i] = qCreateStreamExecTaskInfo(handle.execHandle.execCol.qmsg, &reader);
|
||||
handle.execHandle.execCol.task[i] = qCreateQueueExecTaskInfo(handle.execHandle.execCol.qmsg, &reader);
|
||||
ASSERT(handle.execHandle.execCol.task[i]);
|
||||
void* scanner = NULL;
|
||||
qExtractStreamScanner(handle.execHandle.execCol.task[i], &scanner);
|
||||
ASSERT(scanner);
|
||||
handle.execHandle.pExecReader[i] = qExtractReaderFromStreamScanner(scanner);
|
||||
ASSERT(handle.execHandle.pExecReader[i]);
|
||||
}
|
||||
} else {
|
||||
handle.execHandle.execDb.pFilterOutTbUid =
|
||||
|
|
|
@ -22,34 +22,35 @@ typedef struct SLastrowReader {
|
|||
SVnode* pVnode;
|
||||
STSchema* pSchema;
|
||||
uint64_t uid;
|
||||
// int32_t* pSlotIds;
|
||||
char** transferBuf; // todo remove it soon
|
||||
int32_t numOfCols;
|
||||
int32_t type;
|
||||
int32_t tableIndex; // currently returned result tables
|
||||
SArray* pTableList; // table id list
|
||||
char** transferBuf; // todo remove it soon
|
||||
int32_t numOfCols;
|
||||
int32_t type;
|
||||
int32_t tableIndex; // currently returned result tables
|
||||
SArray* pTableList; // table id list
|
||||
} SLastrowReader;
|
||||
|
||||
static void saveOneRow(STSRow* pRow, SSDataBlock* pBlock, SLastrowReader* pReader, const int32_t* slotIds) {
|
||||
ASSERT(pReader->numOfCols <= taosArrayGetSize(pBlock->pDataBlock));
|
||||
int32_t numOfRows = pBlock->info.rows;
|
||||
size_t numOfCols = taosArrayGetSize(pBlock->pDataBlock);
|
||||
|
||||
SColVal colVal = {0};
|
||||
for (int32_t i = 0; i < numOfCols; ++i) {
|
||||
for (int32_t i = 0; i < pReader->numOfCols; ++i) {
|
||||
SColumnInfoData* pColInfoData = taosArrayGet(pBlock->pDataBlock, i);
|
||||
|
||||
if (slotIds[i] == -1) {
|
||||
colDataAppend(pColInfoData, numOfRows, (const char*)&pRow->ts, false);
|
||||
} else {
|
||||
tTSRowGetVal(pRow, pReader->pSchema, slotIds[i], &colVal);
|
||||
int32_t slotId = slotIds[i];
|
||||
|
||||
tTSRowGetVal(pRow, pReader->pSchema, slotId, &colVal);
|
||||
|
||||
if (IS_VAR_DATA_TYPE(colVal.type)) {
|
||||
if (colVal.isNull || colVal.isNone) {
|
||||
colDataAppendNULL(pColInfoData, numOfRows);
|
||||
} else {
|
||||
varDataSetLen(pReader->transferBuf[i], colVal.value.nData);
|
||||
memcpy(varDataVal(pReader->transferBuf[i]), colVal.value.pData, colVal.value.nData);
|
||||
colDataAppend(pColInfoData, numOfRows, pReader->transferBuf[i], false);
|
||||
varDataSetLen(pReader->transferBuf[slotId], colVal.value.nData);
|
||||
memcpy(varDataVal(pReader->transferBuf[slotId]), colVal.value.pData, colVal.value.nData);
|
||||
colDataAppend(pColInfoData, numOfRows, pReader->transferBuf[slotId], false);
|
||||
}
|
||||
} else {
|
||||
colDataAppend(pColInfoData, numOfRows, (const char*)&colVal.value, colVal.isNull || colVal.isNone);
|
||||
|
@ -60,8 +61,7 @@ static void saveOneRow(STSRow* pRow, SSDataBlock* pBlock, SLastrowReader* pReade
|
|||
pBlock->info.rows += 1;
|
||||
}
|
||||
|
||||
int32_t tsdbLastRowReaderOpen(void* pVnode, int32_t type, SArray* pTableIdList, int32_t* colId, int32_t numOfCols,
|
||||
void** pReader) {
|
||||
int32_t tsdbLastRowReaderOpen(void* pVnode, int32_t type, SArray* pTableIdList, int32_t numOfCols, void** pReader) {
|
||||
SLastrowReader* p = taosMemoryCalloc(1, sizeof(SLastrowReader));
|
||||
if (p == NULL) {
|
||||
return TSDB_CODE_OUT_OF_MEMORY;
|
||||
|
@ -70,13 +70,18 @@ int32_t tsdbLastRowReaderOpen(void* pVnode, int32_t type, SArray* pTableIdList,
|
|||
p->type = type;
|
||||
p->pVnode = pVnode;
|
||||
p->numOfCols = numOfCols;
|
||||
p->transferBuf = taosMemoryCalloc(p->numOfCols, POINTER_BYTES);
|
||||
|
||||
if (taosArrayGetSize(pTableIdList) == 0) {
|
||||
*pReader = p;
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
STableKeyInfo* pKeyInfo = taosArrayGet(pTableIdList, 0);
|
||||
p->pSchema = metaGetTbTSchema(p->pVnode->pMeta, pKeyInfo->uid, -1);
|
||||
p->pTableList = pTableIdList;
|
||||
|
||||
for (int32_t i = 0; i < p->numOfCols; ++i) {
|
||||
p->transferBuf = taosMemoryCalloc(p->pSchema->numOfCols, POINTER_BYTES);
|
||||
for (int32_t i = 0; i < p->pSchema->numOfCols; ++i) {
|
||||
if (IS_VAR_DATA_TYPE(p->pSchema->columns[i].type)) {
|
||||
p->transferBuf[i] = taosMemoryMalloc(p->pSchema->columns[i].bytes);
|
||||
}
|
||||
|
@ -89,16 +94,20 @@ int32_t tsdbLastRowReaderOpen(void* pVnode, int32_t type, SArray* pTableIdList,
|
|||
int32_t tsdbLastrowReaderClose(void* pReader) {
|
||||
SLastrowReader* p = pReader;
|
||||
|
||||
for (int32_t i = 0; i < p->numOfCols; ++i) {
|
||||
taosMemoryFreeClear(p->transferBuf[i]);
|
||||
if (p->pSchema != NULL) {
|
||||
for (int32_t i = 0; i < p->pSchema->numOfCols; ++i) {
|
||||
taosMemoryFreeClear(p->transferBuf[i]);
|
||||
}
|
||||
|
||||
taosMemoryFree(p->transferBuf);
|
||||
taosMemoryFree(p->pSchema);
|
||||
}
|
||||
|
||||
taosMemoryFree(p->transferBuf);
|
||||
taosMemoryFree(pReader);
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
int32_t tsdbRetrieveLastRow(void* pReader, SSDataBlock* pResBlock, const int32_t* slotIds) {
|
||||
int32_t tsdbRetrieveLastRow(void* pReader, SSDataBlock* pResBlock, const int32_t* slotIds, SArray* pTableUidList) {
|
||||
if (pReader == NULL || pResBlock == NULL) {
|
||||
return TSDB_CODE_INVALID_PARA;
|
||||
}
|
||||
|
@ -135,14 +144,15 @@ int32_t tsdbRetrieveLastRow(void* pReader, SSDataBlock* pResBlock, const int32_t
|
|||
// appended or not.
|
||||
if (internalResult) {
|
||||
pResBlock->info.rows -= 1;
|
||||
taosArrayClear(pTableUidList);
|
||||
}
|
||||
|
||||
saveOneRow(pRow, pResBlock, pr, slotIds);
|
||||
taosArrayPush(pTableUidList, &pKeyInfo->uid);
|
||||
internalResult = true;
|
||||
lastKey = pRow->ts;
|
||||
}
|
||||
|
||||
// taosMemoryFree(pRow);
|
||||
tsdbCacheRelease(lruCache, h);
|
||||
}
|
||||
} else if (pr->type == LASTROW_RETRIEVE_TYPE_ALL) {
|
||||
|
@ -165,6 +175,7 @@ int32_t tsdbRetrieveLastRow(void* pReader, SSDataBlock* pResBlock, const int32_t
|
|||
// tsdbCacheLastArray2Row(pLast, &pRow, pr->pSchema);
|
||||
|
||||
saveOneRow(pRow, pResBlock, pr, slotIds);
|
||||
taosArrayPush(pTableUidList, &pKeyInfo->uid);
|
||||
|
||||
// taosMemoryFree(pRow);
|
||||
tsdbCacheRelease(lruCache, h);
|
||||
|
|
|
@ -71,7 +71,7 @@ typedef struct SFilesetIter {
|
|||
|
||||
typedef struct SFileDataBlockInfo {
|
||||
int32_t
|
||||
tbBlockIdx; // index position in STableBlockScanInfo in order to check whether neighbor block overlaps with it
|
||||
tbBlockIdx; // index position in STableBlockScanInfo in order to check whether neighbor block overlaps with it
|
||||
uint64_t uid;
|
||||
} SFileDataBlockInfo;
|
||||
|
||||
|
@ -119,10 +119,10 @@ struct STsdbReader {
|
|||
int32_t type; // query type: 1. retrieve all data blocks, 2. retrieve direct prev|next rows
|
||||
SBlockLoadSuppInfo suppInfo;
|
||||
|
||||
SIOCostSummary cost;
|
||||
STSchema* pSchema;
|
||||
SDataFReader* pFileReader;
|
||||
SVersionRange verRange;
|
||||
SIOCostSummary cost;
|
||||
STSchema* pSchema;
|
||||
SDataFReader* pFileReader;
|
||||
SVersionRange verRange;
|
||||
};
|
||||
|
||||
static SFileDataBlockInfo* getCurrentBlockInfo(SDataBlockIter* pBlockIter);
|
||||
|
@ -234,6 +234,7 @@ static void destroyBlockScanInfo(SHashObj* pTableMap) {
|
|||
}
|
||||
|
||||
taosArrayDestroy(p->delSkyline);
|
||||
taosArrayDestroy(p->pBlockList);
|
||||
p->delSkyline = NULL;
|
||||
}
|
||||
|
||||
|
@ -287,9 +288,7 @@ static int32_t initFilesetIterator(SFilesetIter* pIter, const STsdbFSState* pFSt
|
|||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
static void cleanupFilesetIterator(SFilesetIter* pIter) {
|
||||
taosArrayDestroy(pIter->pFileList);
|
||||
}
|
||||
static void cleanupFilesetIterator(SFilesetIter* pIter) { taosArrayDestroy(pIter->pFileList); }
|
||||
|
||||
static bool filesetIteratorNext(SFilesetIter* pIter, STsdbReader* pReader) {
|
||||
bool asc = ASCENDING_TRAVERSE(pIter->order);
|
||||
|
@ -304,6 +303,10 @@ static bool filesetIteratorNext(SFilesetIter* pIter, STsdbReader* pReader) {
|
|||
STimeWindow win = {0};
|
||||
|
||||
while (1) {
|
||||
if (pReader->pFileReader != NULL) {
|
||||
tsdbDataFReaderClose(&pReader->pFileReader);
|
||||
}
|
||||
|
||||
pReader->status.pCurrentFileset = (SDFileSet*)taosArrayGet(pIter->pFileList, pIter->index);
|
||||
|
||||
int32_t code = tsdbDataFReaderOpen(&pReader->pFileReader, pReader->pTsdb, pReader->status.pCurrentFileset);
|
||||
|
@ -349,9 +352,7 @@ static void resetDataBlockIterator(SDataBlockIter* pIter, int32_t order) {
|
|||
}
|
||||
}
|
||||
|
||||
static void cleanupDataBlockIterator(SDataBlockIter* pIter) {
|
||||
taosArrayDestroy(pIter->blockList);
|
||||
}
|
||||
static void cleanupDataBlockIterator(SDataBlockIter* pIter) { taosArrayDestroy(pIter->blockList); }
|
||||
|
||||
static void initReaderStatus(SReaderStatus* pStatus) {
|
||||
pStatus->pTableIter = NULL;
|
||||
|
@ -392,8 +393,7 @@ static int32_t tsdbReaderCreate(SVnode* pVnode, SQueryTableDataCond* pCond, STsd
|
|||
|
||||
initReaderStatus(&pReader->status);
|
||||
|
||||
pReader->pTsdb =
|
||||
getTsdbByRetentions(pVnode, pCond->twindows.skey, pVnode->config.tsdbCfg.retentions, idstr, &level);
|
||||
pReader->pTsdb = getTsdbByRetentions(pVnode, pCond->twindows.skey, pVnode->config.tsdbCfg.retentions, idstr, &level);
|
||||
pReader->suid = pCond->suid;
|
||||
pReader->order = pCond->order;
|
||||
pReader->capacity = 4096;
|
||||
|
@ -697,12 +697,14 @@ static int32_t doLoadFileBlock(STsdbReader* pReader, SArray* pIndexList, uint32_
|
|||
|
||||
void* p = taosArrayPush(pScanInfo->pBlockList, &block);
|
||||
if (p == NULL) {
|
||||
tMapDataClear(&mapData);
|
||||
return TSDB_CODE_OUT_OF_MEMORY;
|
||||
}
|
||||
|
||||
(*numOfBlocks) += 1;
|
||||
}
|
||||
|
||||
tMapDataClear(&mapData);
|
||||
if (pScanInfo->pBlockList != NULL && taosArrayGetSize(pScanInfo->pBlockList) > 0) {
|
||||
(*numOfValidTables) += 1;
|
||||
}
|
||||
|
@ -833,7 +835,7 @@ static int32_t doLoadFileBlockData(STsdbReader* pReader, SDataBlockIter* pBlockI
|
|||
|
||||
uint8_t *pb = NULL, *pb1 = NULL;
|
||||
int32_t code = tsdbReadColData(pReader->pFileReader, &pBlockScanInfo->blockIdx, pBlock, pSupInfo->colIds, numOfCols,
|
||||
pBlockData, &pb, &pb1);
|
||||
pBlockData, &pb, &pb1);
|
||||
if (code != TSDB_CODE_SUCCESS) {
|
||||
goto _error;
|
||||
}
|
||||
|
@ -1309,6 +1311,8 @@ static int32_t initBlockIterator(STsdbReader* pReader, SDataBlockIter* pBlockIte
|
|||
pReader->idStr);
|
||||
|
||||
pBlockIter->index = asc ? 0 : (numOfBlocks - 1);
|
||||
|
||||
cleanupBlockOrderSupporter(&sup);
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
|
@ -1459,18 +1463,18 @@ static bool overlapWithDelSkyline(STableBlockScanInfo* pBlockScanInfo, const SBl
|
|||
}
|
||||
|
||||
TSDBKEY* pFirst = taosArrayGet(pBlockScanInfo->delSkyline, 0);
|
||||
TSDBKEY* pLast = taosArrayGetLast(pBlockScanInfo->delSkyline);
|
||||
TSDBKEY* pLast = taosArrayGetLast(pBlockScanInfo->delSkyline);
|
||||
|
||||
// ts is not overlap
|
||||
if (pBlock->minKey.ts > pLast->ts || pBlock->maxKey.ts < pFirst->ts) {
|
||||
return false;
|
||||
}
|
||||
|
||||
int32_t step = ASCENDING_TRAVERSE(order)? 1:-1;
|
||||
int32_t step = ASCENDING_TRAVERSE(order) ? 1 : -1;
|
||||
|
||||
// version is not overlap
|
||||
size_t num = taosArrayGetSize(pBlockScanInfo->delSkyline);
|
||||
for(int32_t i = pBlockScanInfo->fileDelIndex; i < num; i += step) {
|
||||
for (int32_t i = pBlockScanInfo->fileDelIndex; i < num; i += step) {
|
||||
TSDBKEY* p = taosArrayGet(pBlockScanInfo->delSkyline, i);
|
||||
if (p->ts >= pBlock->minKey.ts && p->ts <= pBlock->maxKey.ts) {
|
||||
if (p->version >= pBlock->minVersion) {
|
||||
|
@ -1502,8 +1506,8 @@ static bool fileBlockShouldLoad(STsdbReader* pReader, SFileDataBlockInfo* pFBloc
|
|||
}
|
||||
|
||||
// has duplicated ts of different version in this block
|
||||
bool hasDup = (pBlock->nSubBlock == 1)? pBlock->hasDup:true;
|
||||
bool overlapWithDel= overlapWithDelSkyline(pScanInfo, pBlock, pReader->order);
|
||||
bool hasDup = (pBlock->nSubBlock == 1) ? pBlock->hasDup : true;
|
||||
bool overlapWithDel = overlapWithDelSkyline(pScanInfo, pBlock, pReader->order);
|
||||
|
||||
return (overlapWithNeighbor || hasDup || dataBlockPartiallyRequired(&pReader->window, &pReader->verRange, pBlock) ||
|
||||
keyOverlapFileBlock(key, pBlock, &pReader->verRange) || (pBlock->nRow > pReader->capacity) || overlapWithDel);
|
||||
|
@ -1991,6 +1995,7 @@ static TSDBKEY getCurrentKeyInBuf(SDataBlockIter* pBlockIter, STsdbReader* pRead
|
|||
|
||||
static int32_t moveToNextFile(STsdbReader* pReader, int32_t* numOfBlocks) {
|
||||
SReaderStatus* pStatus = &pReader->status;
|
||||
SArray* pIndexList = taosArrayInit(4, sizeof(SBlockIdx));
|
||||
|
||||
while (1) {
|
||||
bool hasNext = filesetIteratorNext(&pStatus->fileIter, pReader);
|
||||
|
@ -1998,9 +2003,10 @@ static int32_t moveToNextFile(STsdbReader* pReader, int32_t* numOfBlocks) {
|
|||
break;
|
||||
}
|
||||
|
||||
SArray* pIndexList = taosArrayInit(4, sizeof(SBlockIdx));
|
||||
taosArrayClear(pIndexList);
|
||||
int32_t code = doLoadBlockIndex(pReader, pReader->pFileReader, pIndexList);
|
||||
if (code != TSDB_CODE_SUCCESS) {
|
||||
taosArrayDestroy(pIndexList);
|
||||
return code;
|
||||
}
|
||||
|
||||
|
@ -2008,6 +2014,7 @@ static int32_t moveToNextFile(STsdbReader* pReader, int32_t* numOfBlocks) {
|
|||
uint32_t numOfValidTable = 0;
|
||||
code = doLoadFileBlock(pReader, pIndexList, &numOfValidTable, numOfBlocks);
|
||||
if (code != TSDB_CODE_SUCCESS) {
|
||||
taosArrayDestroy(pIndexList);
|
||||
return code;
|
||||
}
|
||||
|
||||
|
@ -2015,10 +2022,10 @@ static int32_t moveToNextFile(STsdbReader* pReader, int32_t* numOfBlocks) {
|
|||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// no blocks in current file, try next files
|
||||
}
|
||||
|
||||
taosArrayDestroy(pIndexList);
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
|
@ -2220,17 +2227,18 @@ static STsdb* getTsdbByRetentions(SVnode* pVnode, TSKEY winSKey, SRetention* ret
|
|||
}
|
||||
|
||||
SVersionRange getQueryVerRange(SVnode* pVnode, SQueryTableDataCond* pCond, int8_t level) {
|
||||
int64_t startVer = (pCond->startVersion == -1)? 0:pCond->startVersion;
|
||||
int64_t startVer = (pCond->startVersion == -1) ? 0 : pCond->startVersion;
|
||||
|
||||
if (VND_IS_RSMA(pVnode)) {
|
||||
return (SVersionRange){.minVer = startVer, .maxVer = tdRSmaGetMaxSubmitVer(pVnode->pSma, level)};
|
||||
}
|
||||
|
||||
int64_t endVer = 0;
|
||||
if (pCond->endVersion == -1) { // user not specified end version, set current maximum version of vnode as the endVersion
|
||||
if (pCond->endVersion ==
|
||||
-1) { // user not specified end version, set current maximum version of vnode as the endVersion
|
||||
endVer = pVnode->state.applied;
|
||||
} else {
|
||||
endVer = (pCond->endVersion > pVnode->state.applied)? pVnode->state.applied:pCond->endVersion;
|
||||
endVer = (pCond->endVersion > pVnode->state.applied) ? pVnode->state.applied : pCond->endVersion;
|
||||
}
|
||||
|
||||
return (SVersionRange){.minVer = startVer, .maxVer = endVer};
|
||||
|
@ -2274,9 +2282,9 @@ bool hasBeenDropped(const SArray* pDelList, int32_t* index, TSDBKEY* pKey, int32
|
|||
if (pDelList == NULL) {
|
||||
return false;
|
||||
}
|
||||
size_t num = taosArrayGetSize(pDelList);
|
||||
bool asc = ASCENDING_TRAVERSE(order);
|
||||
int32_t step = asc? 1:-1;
|
||||
size_t num = taosArrayGetSize(pDelList);
|
||||
bool asc = ASCENDING_TRAVERSE(order);
|
||||
int32_t step = asc ? 1 : -1;
|
||||
|
||||
if (asc) {
|
||||
if (*index >= num - 1) {
|
||||
|
@ -2437,6 +2445,7 @@ static int32_t doMergeRowsInFileBlockImpl(SBlockData* pBlockData, int32_t rowInd
|
|||
SVersionRange* pVerRange, int32_t step) {
|
||||
while (pBlockData->aTSKEY[rowIndex] == key && rowIndex < pBlockData->nRow && rowIndex >= 0) {
|
||||
if (pBlockData->aVersion[rowIndex] > pVerRange->maxVer || pBlockData->aVersion[rowIndex] < pVerRange->minVer) {
|
||||
rowIndex += step;
|
||||
continue;
|
||||
}
|
||||
|
||||
|
@ -2823,7 +2832,7 @@ void tsdbReaderClose(STsdbReader* pReader) {
|
|||
taosMemoryFree(pSupInfo->colIds);
|
||||
|
||||
taosArrayDestroy(pSupInfo->pColAgg);
|
||||
for(int32_t i = 0; i < blockDataGetNumOfCols(pReader->pResBlock); ++i) {
|
||||
for (int32_t i = 0; i < blockDataGetNumOfCols(pReader->pResBlock); ++i) {
|
||||
if (pSupInfo->buildBuf[i] != NULL) {
|
||||
taosMemoryFreeClear(pSupInfo->buildBuf[i]);
|
||||
}
|
||||
|
@ -2835,6 +2844,9 @@ void tsdbReaderClose(STsdbReader* pReader) {
|
|||
destroyBlockScanInfo(pReader->status.pTableMap);
|
||||
blockDataDestroy(pReader->pResBlock);
|
||||
|
||||
if (pReader->pFileReader != NULL) {
|
||||
tsdbDataFReaderClose(&pReader->pFileReader);
|
||||
}
|
||||
|
||||
#if 0
|
||||
// if (pReader->status.pTableScanInfo != NULL) {
|
||||
|
@ -3011,8 +3023,8 @@ int32_t tsdbReaderReset(STsdbReader* pReader, SQueryTableDataCond* pCond) {
|
|||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
pReader->order = pCond->order;
|
||||
pReader->type = BLOCK_LOAD_OFFSET_ORDER;
|
||||
pReader->order = pCond->order;
|
||||
pReader->type = BLOCK_LOAD_OFFSET_ORDER;
|
||||
pReader->status.loadFromFile = true;
|
||||
pReader->status.pTableIter = NULL;
|
||||
|
||||
|
@ -3023,11 +3035,14 @@ int32_t tsdbReaderReset(STsdbReader* pReader, SQueryTableDataCond* pCond) {
|
|||
memset(pReader->suppInfo.plist, 0, POINTER_BYTES);
|
||||
|
||||
pReader->suppInfo.tsColAgg.colId = PRIMARYKEY_TIMESTAMP_COL_ID;
|
||||
tsdbDataFReaderClose(&pReader->pFileReader);
|
||||
|
||||
// todo set the correct numOfTables
|
||||
int32_t numOfTables = 1;
|
||||
SDataBlockIter* pBlockIter = &pReader->status.blockIter;
|
||||
|
||||
tsdbDataFReaderClose(&pReader->pFileReader);
|
||||
|
||||
STsdbFSState* pFState = pReader->pTsdb->fs->cState;
|
||||
initFilesetIterator(&pReader->status.fileIter, pFState, pReader->order, pReader->idStr);
|
||||
resetDataBlockIterator(&pReader->status.blockIter, pReader->order);
|
||||
|
@ -3074,10 +3089,13 @@ int32_t tsdbGetFileBlocksDistInfo(STsdbReader* pReader, STableBlockDistInfo* pTa
|
|||
|
||||
SDataBlockIter* pBlockIter = &pStatus->blockIter;
|
||||
pTableBlockInfo->numOfFiles += pStatus->fileIter.numOfFiles;
|
||||
pTableBlockInfo->numOfBlocks += pBlockIter->numOfBlocks;
|
||||
|
||||
if (pBlockIter->numOfBlocks > 0) {
|
||||
pTableBlockInfo->numOfBlocks += pBlockIter->numOfBlocks;
|
||||
}
|
||||
|
||||
pTableBlockInfo->numOfTables = numOfTables;
|
||||
bool hasNext = true;
|
||||
bool hasNext = (pBlockIter->numOfBlocks > 0);
|
||||
|
||||
while (true) {
|
||||
if (hasNext) {
|
||||
|
@ -3114,13 +3132,12 @@ int32_t tsdbGetFileBlocksDistInfo(STsdbReader* pReader, STableBlockDistInfo* pTa
|
|||
pTableBlockInfo->numOfBlocks += pBlockIter->numOfBlocks;
|
||||
}
|
||||
|
||||
/*
|
||||
hasNext = blockIteratorNext(&pStatus->blockIter);
|
||||
*/
|
||||
/*
|
||||
hasNext = blockIteratorNext(&pStatus->blockIter);
|
||||
*/
|
||||
|
||||
|
||||
// tsdbDebug("%p %d blocks found in file for %d table(s), fid:%d, %s", pReader, numOfBlocks, numOfTables,
|
||||
// pReader->pFileGroup->fid, pReader->idStr);
|
||||
// tsdbDebug("%p %d blocks found in file for %d table(s), fid:%d, %s", pReader, numOfBlocks, numOfTables,
|
||||
// pReader->pFileGroup->fid, pReader->idStr);
|
||||
}
|
||||
|
||||
return code;
|
||||
|
@ -3158,7 +3175,7 @@ int64_t tsdbGetNumOfRowsInMemTable(STsdbReader* pReader) {
|
|||
return rows;
|
||||
}
|
||||
|
||||
int32_t tsdbGetTableSchema(SVnode* pVnode, int64_t uid, STSchema** pSchema, int64_t *suid) {
|
||||
int32_t tsdbGetTableSchema(SVnode* pVnode, int64_t uid, STSchema** pSchema, int64_t* suid) {
|
||||
int32_t sversion = 1;
|
||||
|
||||
SMetaReader mr = {0};
|
||||
|
@ -3192,4 +3209,3 @@ int32_t tsdbGetTableSchema(SVnode* pVnode, int64_t uid, STSchema** pSchema, int6
|
|||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -427,13 +427,22 @@ static void vnodeSyncCommitMsg(SSyncFSM *pFsm, const SRpcMsg *pMsg, SFsmCbMeta c
|
|||
syncGetVgId(pVnode->sync), pFsm, cbMeta.index, cbMeta.isWeak, cbMeta.code, cbMeta.state,
|
||||
syncUtilState2String(cbMeta.state), pMsg->msgType, TMSG_INFO(pMsg->msgType));
|
||||
|
||||
SRpcMsg rpcMsg = {.msgType = pMsg->msgType, .contLen = pMsg->contLen};
|
||||
rpcMsg.pCont = rpcMallocCont(rpcMsg.contLen);
|
||||
memcpy(rpcMsg.pCont, pMsg->pCont, pMsg->contLen);
|
||||
syncGetAndDelRespRpc(pVnode->sync, cbMeta.seqNum, &rpcMsg.info);
|
||||
rpcMsg.info.conn.applyIndex = cbMeta.index;
|
||||
rpcMsg.info.conn.applyTerm = cbMeta.term;
|
||||
tmsgPutToQueue(&pVnode->msgCb, APPLY_QUEUE, &rpcMsg);
|
||||
if (cbMeta.code == 0) {
|
||||
SRpcMsg rpcMsg = {.msgType = pMsg->msgType, .contLen = pMsg->contLen};
|
||||
rpcMsg.pCont = rpcMallocCont(rpcMsg.contLen);
|
||||
memcpy(rpcMsg.pCont, pMsg->pCont, pMsg->contLen);
|
||||
syncGetAndDelRespRpc(pVnode->sync, cbMeta.seqNum, &rpcMsg.info);
|
||||
rpcMsg.info.conn.applyIndex = cbMeta.index;
|
||||
rpcMsg.info.conn.applyTerm = cbMeta.term;
|
||||
tmsgPutToQueue(&pVnode->msgCb, APPLY_QUEUE, &rpcMsg);
|
||||
} else {
|
||||
SRpcMsg rsp = {.code = cbMeta.code, .info = pMsg->info};
|
||||
vError("vgId:%d, sync commit error, msgtype:%d,%s, error:0x%X, errmsg:%s", syncGetVgId(pVnode->sync), pMsg->msgType,
|
||||
TMSG_INFO(pMsg->msgType), cbMeta.code, tstrerror(cbMeta.code));
|
||||
if (rsp.info.handle != NULL) {
|
||||
tmsgSendRsp(&rsp);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void vnodeSyncPreCommitMsg(SSyncFSM *pFsm, const SRpcMsg *pMsg, SFsmCbMeta cbMeta) {
|
||||
|
|
|
@ -642,6 +642,7 @@ void ctgFreeSTableIndex(void *info);
|
|||
void ctgClearSubTaskRes(SCtgSubRes *pRes);
|
||||
void ctgFreeQNode(SCtgQNode *node);
|
||||
void ctgClearHandle(SCatalog* pCtg);
|
||||
void ctgFreeTbCacheImpl(SCtgTbCache *pCache);
|
||||
|
||||
|
||||
extern SCatalogMgmt gCtgMgmt;
|
||||
|
|
|
@ -647,6 +647,8 @@ int32_t ctgEnqueue(SCatalog* pCtg, SCtgCacheOperation *operation) {
|
|||
CTG_RET(TSDB_CODE_OUT_OF_MEMORY);
|
||||
}
|
||||
|
||||
bool syncOp = operation->syncOp;
|
||||
char* opName = gCtgCacheOperation[operation->opId].name;
|
||||
if (operation->syncOp) {
|
||||
tsem_init(&operation->rspSem, 0, 0);
|
||||
}
|
||||
|
@ -664,14 +666,14 @@ int32_t ctgEnqueue(SCatalog* pCtg, SCtgCacheOperation *operation) {
|
|||
gCtgMgmt.queue.tail = node;
|
||||
CTG_UNLOCK(CTG_WRITE, &gCtgMgmt.queue.qlock);
|
||||
|
||||
ctgDebug("action [%s] added into queue", opName);
|
||||
|
||||
CTG_QUEUE_INC();
|
||||
CTG_RT_STAT_INC(numOfOpEnqueue, 1);
|
||||
|
||||
tsem_post(&gCtgMgmt.queue.reqSem);
|
||||
|
||||
ctgDebug("action [%s] added into queue", gCtgCacheOperation[operation->opId].name);
|
||||
|
||||
if (operation->syncOp) {
|
||||
if (syncOp) {
|
||||
tsem_wait(&operation->rspSem);
|
||||
taosMemoryFree(operation);
|
||||
}
|
||||
|
@ -840,6 +842,7 @@ _return:
|
|||
|
||||
ctgFreeVgInfo(dbInfo);
|
||||
taosMemoryFreeClear(op->data);
|
||||
taosMemoryFreeClear(op);
|
||||
CTG_RET(code);
|
||||
}
|
||||
|
||||
|
@ -852,7 +855,7 @@ int32_t ctgUpdateTbMetaEnqueue(SCatalog* pCtg, STableMetaOutput *output, bool sy
|
|||
SCtgUpdateTbMetaMsg *msg = taosMemoryMalloc(sizeof(SCtgUpdateTbMetaMsg));
|
||||
if (NULL == msg) {
|
||||
ctgError("malloc %d failed", (int32_t)sizeof(SCtgUpdateTbMetaMsg));
|
||||
CTG_ERR_RET(TSDB_CODE_OUT_OF_MEMORY);
|
||||
CTG_ERR_JRET(TSDB_CODE_OUT_OF_MEMORY);
|
||||
}
|
||||
|
||||
char *p = strchr(output->dbFName, '.');
|
||||
|
@ -871,6 +874,11 @@ int32_t ctgUpdateTbMetaEnqueue(SCatalog* pCtg, STableMetaOutput *output, bool sy
|
|||
|
||||
_return:
|
||||
|
||||
if (output) {
|
||||
taosMemoryFree(output->tbMeta);
|
||||
taosMemoryFree(output);
|
||||
}
|
||||
|
||||
taosMemoryFreeClear(msg);
|
||||
|
||||
CTG_RET(code);
|
||||
|
@ -1753,6 +1761,16 @@ int32_t ctgOpDropStbMeta(SCtgCacheOperation *operation) {
|
|||
CTG_CACHE_STAT_DEC(numOfStb, 1);
|
||||
}
|
||||
|
||||
SCtgTbCache* pTbCache = taosHashGet(dbCache->tbCache, msg->stbName, strlen(msg->stbName));
|
||||
if (NULL == pTbCache) {
|
||||
ctgDebug("stb %s already not in cache", msg->stbName);
|
||||
goto _return;
|
||||
}
|
||||
|
||||
CTG_LOCK(CTG_WRITE, &pTbCache->metaLock);
|
||||
ctgFreeTbCacheImpl(pTbCache);
|
||||
CTG_UNLOCK(CTG_WRITE, &pTbCache->metaLock);
|
||||
|
||||
if (taosHashRemove(dbCache->tbCache, msg->stbName, strlen(msg->stbName))) {
|
||||
ctgError("stb not exist in cache, dbFName:%s, stb:%s, suid:0x%"PRIx64, msg->dbFName, msg->stbName, msg->suid);
|
||||
} else {
|
||||
|
@ -1780,14 +1798,24 @@ int32_t ctgOpDropTbMeta(SCtgCacheOperation *operation) {
|
|||
SCtgDBCache *dbCache = NULL;
|
||||
ctgGetDBCache(pCtg, msg->dbFName, &dbCache);
|
||||
if (NULL == dbCache) {
|
||||
return TSDB_CODE_SUCCESS;
|
||||
goto _return;
|
||||
}
|
||||
|
||||
if (dbCache->dbId != msg->dbId) {
|
||||
ctgDebug("dbId 0x%" PRIx64 " not match with curId 0x%"PRIx64", dbFName:%s, tbName:%s", msg->dbId, dbCache->dbId, msg->dbFName, msg->tbName);
|
||||
return TSDB_CODE_SUCCESS;
|
||||
goto _return;
|
||||
}
|
||||
|
||||
SCtgTbCache* pTbCache = taosHashGet(dbCache->tbCache, msg->tbName, strlen(msg->tbName));
|
||||
if (NULL == pTbCache) {
|
||||
ctgDebug("tb %s already not in cache", msg->tbName);
|
||||
goto _return;
|
||||
}
|
||||
|
||||
CTG_LOCK(CTG_WRITE, &pTbCache->metaLock);
|
||||
ctgFreeTbCacheImpl(pTbCache);
|
||||
CTG_UNLOCK(CTG_WRITE, &pTbCache->metaLock);
|
||||
|
||||
if (taosHashRemove(dbCache->tbCache, msg->tbName, strlen(msg->tbName))) {
|
||||
ctgError("tb %s not exist in cache, dbFName:%s", msg->tbName, msg->dbFName);
|
||||
CTG_ERR_JRET(TSDB_CODE_CTG_INTERNAL_ERROR);
|
||||
|
@ -2063,6 +2091,8 @@ void* ctgUpdateThreadFunc(void* param) {
|
|||
|
||||
if (operation->syncOp) {
|
||||
tsem_post(&operation->rspSem);
|
||||
} else {
|
||||
taosMemoryFreeClear(operation);
|
||||
}
|
||||
|
||||
CTG_RT_STAT_INC(numOfOpDequeue, 1);
|
||||
|
|
|
@ -261,6 +261,8 @@ int32_t ctgHandleMsgCallback(void *param, SDataBuf *pMsg, int32_t rspCode) {
|
|||
|
||||
_return:
|
||||
|
||||
taosMemoryFree(pMsg->pData);
|
||||
|
||||
if (pJob) {
|
||||
taosReleaseRef(gCtgMgmt.jobPool, cbParam->refId);
|
||||
}
|
||||
|
|
|
@ -152,6 +152,7 @@ void ctgFreeStbMetaCache(SCtgDBCache *dbCache) {
|
|||
}
|
||||
|
||||
void ctgFreeTbCacheImpl(SCtgTbCache *pCache) {
|
||||
qDebug("tbMeta freed, p:%p", pCache->pMeta);
|
||||
taosMemoryFreeClear(pCache->pMeta);
|
||||
if (pCache->pIndex) {
|
||||
taosArrayDestroyEx(pCache->pIndex->pIndex, tFreeSTableIndexInfo);
|
||||
|
@ -831,6 +832,7 @@ int32_t ctgCloneMetaOutput(STableMetaOutput *output, STableMetaOutput **pOutput)
|
|||
if (output->tbMeta) {
|
||||
int32_t metaSize = CTG_META_SIZE(output->tbMeta);
|
||||
(*pOutput)->tbMeta = taosMemoryMalloc(metaSize);
|
||||
qDebug("tbMeta cloned, size:%d, p:%p", metaSize, (*pOutput)->tbMeta);
|
||||
if (NULL == (*pOutput)->tbMeta) {
|
||||
qError("malloc %d failed", (int32_t)sizeof(STableMetaOutput));
|
||||
taosMemoryFreeClear(*pOutput);
|
||||
|
|
|
@ -570,10 +570,14 @@ int32_t buildSelectResultDataBlock(SNodeList* pProjects, SSDataBlock* pBlock) {
|
|||
int32_t index = 0;
|
||||
SNode* pProj = NULL;
|
||||
FOREACH(pProj, pProjects) {
|
||||
if (((SValueNode*)pProj)->isNull) {
|
||||
colDataAppend(taosArrayGet(pBlock->pDataBlock, index++), 0, NULL, true);
|
||||
if (QUERY_NODE_VALUE != nodeType(pProj)) {
|
||||
return TSDB_CODE_PAR_INVALID_SELECTED_EXPR;
|
||||
} else {
|
||||
colDataAppend(taosArrayGet(pBlock->pDataBlock, index++), 0, nodesGetValueFromNode((SValueNode*)pProj), false);
|
||||
if (((SValueNode*)pProj)->isNull) {
|
||||
colDataAppend(taosArrayGet(pBlock->pDataBlock, index++), 0, NULL, true);
|
||||
} else {
|
||||
colDataAppend(taosArrayGet(pBlock->pDataBlock, index++), 0, nodesGetValueFromNode((SValueNode*)pProj), false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -8,7 +8,7 @@ add_library(executor STATIC ${EXECUTOR_SRC})
|
|||
# )
|
||||
|
||||
target_link_libraries(executor
|
||||
PRIVATE os util common function parser planner qcom vnode scalar nodes index
|
||||
PRIVATE os util common function parser planner qcom vnode scalar nodes index stream
|
||||
)
|
||||
|
||||
target_include_directories(
|
||||
|
|
|
@ -39,6 +39,7 @@ extern "C" {
|
|||
#include "tmsg.h"
|
||||
#include "tpagedbuf.h"
|
||||
#include "tstreamUpdate.h"
|
||||
#include "tstream.h"
|
||||
|
||||
#include "vnode.h"
|
||||
#include "executorInt.h"
|
||||
|
@ -139,12 +140,14 @@ typedef struct STaskIdInfo {
|
|||
} STaskIdInfo;
|
||||
|
||||
typedef struct {
|
||||
//TODO remove prepareStatus
|
||||
STqOffsetVal prepareStatus; // for tmq
|
||||
STqOffsetVal lastStatus; // for tmq
|
||||
void* metaBlk; // for tmq fetching meta
|
||||
SSDataBlock* pullOverBlk; // for streaming
|
||||
SWalFilterCond cond;
|
||||
int64_t lastScanUid;
|
||||
SStreamQueue* inputQueue;
|
||||
} SStreamTaskInfo;
|
||||
|
||||
typedef struct SExecTaskInfo {
|
||||
|
@ -319,6 +322,7 @@ typedef struct SLastrowScanInfo {
|
|||
void *pLastrowReader;
|
||||
SArray *pColMatchInfo;
|
||||
int32_t *pSlotIds;
|
||||
SExprSupp pseudoExprSup;
|
||||
} SLastrowScanInfo;
|
||||
|
||||
typedef enum EStreamScanMode {
|
||||
|
@ -389,6 +393,7 @@ typedef struct SStreamScanInfo {
|
|||
SSDataBlock* pPullDataRes; // pull data SSDataBlock
|
||||
SSDataBlock* pDeleteDataRes; // delete data SSDataBlock
|
||||
int32_t deleteDataIndex;
|
||||
STimeWindow updateWin;
|
||||
|
||||
// status for tmq
|
||||
// SSchemaWrapper schema;
|
||||
|
@ -786,6 +791,8 @@ int32_t getBufferPgSize(int32_t rowSize, uint32_t* defaultPgsz, uint32_t* defaul
|
|||
|
||||
void doSetOperatorCompleted(SOperatorInfo* pOperator);
|
||||
void doFilter(const SNode* pFilterNode, SSDataBlock* pBlock);
|
||||
int32_t addTagPseudoColumnData(SReadHandle* pHandle, SExprInfo* pPseudoExpr, int32_t numOfPseudoExpr,
|
||||
SSDataBlock* pBlock, const char* idStr);
|
||||
|
||||
void cleanupAggSup(SAggSupporter* pAggSup);
|
||||
void destroyBasicOperatorInfo(void* param, int32_t numOfOutput);
|
||||
|
|
|
@ -45,20 +45,20 @@ SOperatorInfo* createLastrowScanOperator(SLastRowScanPhysiNode* pScanNode, SRead
|
|||
int32_t numOfCols = 0;
|
||||
pInfo->pColMatchInfo = extractColMatchInfo(pScanNode->pScanCols, pScanNode->node.pOutputDataBlockDesc, &numOfCols,
|
||||
COL_MATCH_FROM_COL_ID);
|
||||
int32_t* pCols = taosMemoryMalloc(numOfCols * sizeof(int32_t));
|
||||
for (int32_t i = 0; i < numOfCols; ++i) {
|
||||
SColMatchInfo* pColMatch = taosArrayGet(pInfo->pColMatchInfo, i);
|
||||
pCols[i] = pColMatch->colId;
|
||||
}
|
||||
|
||||
int32_t code = extractTargetSlotId(pInfo->pColMatchInfo, pTaskInfo, &pInfo->pSlotIds);
|
||||
if (code != TSDB_CODE_SUCCESS) {
|
||||
goto _error;
|
||||
}
|
||||
|
||||
tsdbLastRowReaderOpen(readHandle->vnode, LASTROW_RETRIEVE_TYPE_ALL, pTableList, pCols, numOfCols,
|
||||
tsdbLastRowReaderOpen(readHandle->vnode, LASTROW_RETRIEVE_TYPE_SINGLE, pTableList, taosArrayGetSize(pInfo->pColMatchInfo),
|
||||
&pInfo->pLastrowReader);
|
||||
taosMemoryFree(pCols);
|
||||
|
||||
if (pScanNode->pScanPseudoCols != NULL) {
|
||||
SExprSupp* pPseudoExpr = &pInfo->pseudoExprSup;
|
||||
|
||||
pPseudoExpr->pExprInfo = createExprInfo(pScanNode->pScanPseudoCols, NULL, &pPseudoExpr->numOfExprs);
|
||||
pPseudoExpr->pCtx = createSqlFunctionCtx(pPseudoExpr->pExprInfo, pPseudoExpr->numOfExprs, &pPseudoExpr->rowEntryInfoOffset);
|
||||
}
|
||||
|
||||
pOperator->name = "LastrowScanOperator";
|
||||
pOperator->operatorType = QUERY_NODE_PHYSICAL_PLAN_LAST_ROW_SCAN;
|
||||
|
@ -100,7 +100,20 @@ SSDataBlock* doScanLastrow(SOperatorInfo* pOperator) {
|
|||
// check if it is a group by tbname
|
||||
if (size == taosArrayGetSize(pInfo->pTableList)) {
|
||||
blockDataCleanup(pInfo->pRes);
|
||||
tsdbRetrieveLastRow(pInfo->pLastrowReader, pInfo->pRes, pInfo->pSlotIds);
|
||||
SArray* pUidList = taosArrayInit(1, sizeof(tb_uid_t));
|
||||
int32_t code = tsdbRetrieveLastRow(pInfo->pLastrowReader, pInfo->pRes, pInfo->pSlotIds, pUidList);
|
||||
if (code != TSDB_CODE_SUCCESS) {
|
||||
longjmp(pTaskInfo->env, code);
|
||||
}
|
||||
|
||||
// check for tag values
|
||||
if (pInfo->pRes->info.rows > 0 && pInfo->pseudoExprSup.numOfExprs > 0) {
|
||||
SExprSupp* pSup = &pInfo->pseudoExprSup;
|
||||
pInfo->pRes->info.uid = *(tb_uid_t*) taosArrayGet(pUidList, 0);
|
||||
addTagPseudoColumnData(&pInfo->readHandle, pSup->pExprInfo, pSup->numOfExprs, pInfo->pRes, GET_TASKID(pTaskInfo));
|
||||
}
|
||||
|
||||
doSetOperatorCompleted(pOperator);
|
||||
return (pInfo->pRes->info.rows == 0) ? NULL : pInfo->pRes;
|
||||
} else {
|
||||
// todo fetch the result for each group
|
||||
|
|
|
@ -191,6 +191,7 @@ SSDataBlock* createResDataBlock(SDataBlockDescNode* pNode) {
|
|||
|
||||
pBlock->info.blockId = pNode->dataBlockId;
|
||||
pBlock->info.type = STREAM_INVALID;
|
||||
pBlock->info.calWin = (STimeWindow){.skey = INT64_MIN, .ekey = INT64_MAX};
|
||||
|
||||
for (int32_t i = 0; i < numOfCols; ++i) {
|
||||
SSlotDescNode* pDescNode = (SSlotDescNode*)nodesListGetNode(pNode->pSlots, i);
|
||||
|
|
|
@ -60,8 +60,6 @@ static int32_t doSetStreamBlock(SOperatorInfo* pOperator, void* input, size_t nu
|
|||
taosArrayAddAll(p->pDataBlock, pDataBlock->pDataBlock);
|
||||
taosArrayPush(pInfo->pBlockLists, &p);
|
||||
}
|
||||
/*} else if (type == STREAM_INPUT__TABLE_SCAN) {*/
|
||||
/*ASSERT(pInfo->blockType == STREAM_INPUT__TABLE_SCAN);*/
|
||||
} else {
|
||||
ASSERT(0);
|
||||
}
|
||||
|
@ -106,6 +104,30 @@ int32_t qSetMultiStreamInput(qTaskInfo_t tinfo, const void* pBlocks, size_t numO
|
|||
return code;
|
||||
}
|
||||
|
||||
qTaskInfo_t qCreateQueueExecTaskInfo(void* msg, SReadHandle* readers) {
|
||||
if (msg == NULL) {
|
||||
// TODO create raw scan
|
||||
return NULL;
|
||||
}
|
||||
|
||||
struct SSubplan* plan = NULL;
|
||||
int32_t code = qStringToSubplan(msg, &plan);
|
||||
if (code != TSDB_CODE_SUCCESS) {
|
||||
terrno = code;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
qTaskInfo_t pTaskInfo = NULL;
|
||||
code = qCreateExecTask(readers, 0, 0, plan, &pTaskInfo, NULL, NULL, OPTR_EXEC_MODEL_QUEUE);
|
||||
if (code != TSDB_CODE_SUCCESS) {
|
||||
// TODO: destroy SSubplan & pTaskInfo
|
||||
terrno = code;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return pTaskInfo;
|
||||
}
|
||||
|
||||
qTaskInfo_t qCreateStreamExecTaskInfo(void* msg, SReadHandle* readers) {
|
||||
if (msg == NULL) {
|
||||
return NULL;
|
||||
|
@ -186,7 +208,7 @@ int32_t qUpdateQualifiedTableId(qTaskInfo_t tinfo, const SArray* tableIdList, bo
|
|||
}
|
||||
|
||||
int32_t qGetQueryTableSchemaVersion(qTaskInfo_t tinfo, char* dbName, char* tableName, int32_t* sversion,
|
||||
int32_t* tversion) {
|
||||
int32_t* tversion) {
|
||||
ASSERT(tinfo != NULL && dbName != NULL && tableName != NULL);
|
||||
SExecTaskInfo* pTaskInfo = (SExecTaskInfo*)tinfo;
|
||||
|
||||
|
|
|
@ -44,6 +44,13 @@ int32_t qCreateExecTask(SReadHandle* readHandle, int32_t vgId, uint64_t taskId,
|
|||
goto _error;
|
||||
}
|
||||
|
||||
if (model == OPTR_EXEC_MODEL_STREAM) {
|
||||
(*pTask)->streamInfo.inputQueue = streamQueueOpen();
|
||||
if ((*pTask)->streamInfo.inputQueue == NULL) {
|
||||
goto _error;
|
||||
}
|
||||
}
|
||||
|
||||
SDataSinkMgtCfg cfg = {.maxDataBlockNum = 1000, .maxDataBlockNumPerQuery = 100};
|
||||
code = dsDataSinkMgtInit(&cfg);
|
||||
if (code != TSDB_CODE_SUCCESS) {
|
||||
|
@ -252,6 +259,13 @@ int32_t qExtractStreamScanner(qTaskInfo_t tinfo, void** scanner) {
|
|||
}
|
||||
}
|
||||
|
||||
int32_t qStreamInput(qTaskInfo_t tinfo, void* pItem) {
|
||||
SExecTaskInfo* pTaskInfo = (SExecTaskInfo*)tinfo;
|
||||
ASSERT(pTaskInfo->execModel == OPTR_EXEC_MODEL_STREAM);
|
||||
taosWriteQitem(pTaskInfo->streamInfo.inputQueue->queue, pItem);
|
||||
return 0;
|
||||
}
|
||||
|
||||
void* qExtractReaderFromStreamScanner(void* scanner) {
|
||||
SStreamScanInfo* pInfo = scanner;
|
||||
return (void*)pInfo->tqReader;
|
||||
|
@ -269,13 +283,13 @@ const STqOffset* qExtractStatusFromStreamScanner(void* scanner) {
|
|||
|
||||
void* qStreamExtractMetaMsg(qTaskInfo_t tinfo) {
|
||||
SExecTaskInfo* pTaskInfo = (SExecTaskInfo*)tinfo;
|
||||
ASSERT(pTaskInfo->execModel == OPTR_EXEC_MODEL_STREAM);
|
||||
ASSERT(pTaskInfo->execModel == OPTR_EXEC_MODEL_QUEUE);
|
||||
return pTaskInfo->streamInfo.metaBlk;
|
||||
}
|
||||
|
||||
int32_t qStreamExtractOffset(qTaskInfo_t tinfo, STqOffsetVal* pOffset) {
|
||||
SExecTaskInfo* pTaskInfo = (SExecTaskInfo*)tinfo;
|
||||
ASSERT(pTaskInfo->execModel == OPTR_EXEC_MODEL_STREAM);
|
||||
ASSERT(pTaskInfo->execModel == OPTR_EXEC_MODEL_QUEUE);
|
||||
memcpy(pOffset, &pTaskInfo->streamInfo.lastStatus, sizeof(STqOffsetVal));
|
||||
return 0;
|
||||
}
|
||||
|
@ -283,35 +297,41 @@ int32_t qStreamExtractOffset(qTaskInfo_t tinfo, STqOffsetVal* pOffset) {
|
|||
int32_t qStreamPrepareScan(qTaskInfo_t tinfo, const STqOffsetVal* pOffset) {
|
||||
SExecTaskInfo* pTaskInfo = (SExecTaskInfo*)tinfo;
|
||||
SOperatorInfo* pOperator = pTaskInfo->pRoot;
|
||||
ASSERT(pTaskInfo->execModel == OPTR_EXEC_MODEL_STREAM);
|
||||
ASSERT(pTaskInfo->execModel == OPTR_EXEC_MODEL_QUEUE);
|
||||
pTaskInfo->streamInfo.prepareStatus = *pOffset;
|
||||
// TODO: optimize
|
||||
/*if (pTaskInfo->streamInfo.lastStatus.type != pOffset->type ||*/
|
||||
/*pTaskInfo->streamInfo.prepareStatus.version != pTaskInfo->streamInfo.lastStatus.version) {*/
|
||||
while (1) {
|
||||
uint8_t type = pOperator->operatorType;
|
||||
pOperator->status = OP_OPENED;
|
||||
if (type == QUERY_NODE_PHYSICAL_PLAN_STREAM_SCAN) {
|
||||
SStreamScanInfo* pInfo = pOperator->info;
|
||||
if (pOffset->type == TMQ_OFFSET__LOG) {
|
||||
if (tqSeekVer(pInfo->tqReader, pOffset->version) < 0) {
|
||||
return -1;
|
||||
}
|
||||
ASSERT(pInfo->tqReader->pWalReader->curVersion == pOffset->version);
|
||||
} else if (pOffset->type == TMQ_OFFSET__SNAPSHOT_DATA) {
|
||||
/*pInfo->blockType = STREAM_INPUT__TABLE_SCAN;*/
|
||||
int64_t uid = pOffset->uid;
|
||||
int64_t ts = pOffset->ts;
|
||||
|
||||
if (uid == 0) {
|
||||
if (taosArrayGetSize(pTaskInfo->tableqinfoList.pTableList) != 0) {
|
||||
STableKeyInfo* pTableInfo = taosArrayGet(pTaskInfo->tableqinfoList.pTableList, 0);
|
||||
uid = pTableInfo->uid;
|
||||
ts = INT64_MIN;
|
||||
if (!tOffsetEqual(pOffset, &pTaskInfo->streamInfo.lastStatus)) {
|
||||
while (1) {
|
||||
uint8_t type = pOperator->operatorType;
|
||||
pOperator->status = OP_OPENED;
|
||||
if (type == QUERY_NODE_PHYSICAL_PLAN_STREAM_SCAN) {
|
||||
SStreamScanInfo* pInfo = pOperator->info;
|
||||
if (pOffset->type == TMQ_OFFSET__LOG) {
|
||||
#if 0
|
||||
if (tOffsetEqual(pOffset, &pTaskInfo->streamInfo.lastStatus) &&
|
||||
pInfo->tqReader->pWalReader->curVersion != pOffset->version) {
|
||||
qError("prepare scan ver %ld actual ver %ld, last %ld", pOffset->version,
|
||||
pInfo->tqReader->pWalReader->curVersion, pTaskInfo->streamInfo.lastStatus.version);
|
||||
ASSERT(0);
|
||||
}
|
||||
}
|
||||
if (pTaskInfo->streamInfo.lastStatus.type != TMQ_OFFSET__SNAPSHOT_DATA ||
|
||||
pTaskInfo->streamInfo.lastStatus.uid != uid || pTaskInfo->streamInfo.lastStatus.ts != ts) {
|
||||
#endif
|
||||
if (tqSeekVer(pInfo->tqReader, pOffset->version + 1) < 0) {
|
||||
return -1;
|
||||
}
|
||||
ASSERT(pInfo->tqReader->pWalReader->curVersion == pOffset->version + 1);
|
||||
} else if (pOffset->type == TMQ_OFFSET__SNAPSHOT_DATA) {
|
||||
/*pInfo->blockType = STREAM_INPUT__TABLE_SCAN;*/
|
||||
int64_t uid = pOffset->uid;
|
||||
int64_t ts = pOffset->ts;
|
||||
|
||||
if (uid == 0) {
|
||||
if (taosArrayGetSize(pTaskInfo->tableqinfoList.pTableList) != 0) {
|
||||
STableKeyInfo* pTableInfo = taosArrayGet(pTaskInfo->tableqinfoList.pTableList, 0);
|
||||
uid = pTableInfo->uid;
|
||||
ts = INT64_MIN;
|
||||
}
|
||||
}
|
||||
/*if (pTaskInfo->streamInfo.lastStatus.type != TMQ_OFFSET__SNAPSHOT_DATA ||*/
|
||||
/*pTaskInfo->streamInfo.lastStatus.uid != uid || pTaskInfo->streamInfo.lastStatus.ts != ts) {*/
|
||||
STableScanInfo* pTableScanInfo = pInfo->pTableScanOp->info;
|
||||
int32_t tableSz = taosArrayGetSize(pTaskInfo->tableqinfoList.pTableList);
|
||||
bool found = false;
|
||||
|
@ -320,6 +340,7 @@ int32_t qStreamPrepareScan(qTaskInfo_t tinfo, const STqOffsetVal* pOffset) {
|
|||
if (pTableInfo->uid == uid) {
|
||||
found = true;
|
||||
pTableScanInfo->currentTable = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -335,18 +356,18 @@ int32_t qStreamPrepareScan(qTaskInfo_t tinfo, const STqOffsetVal* pOffset) {
|
|||
|
||||
qDebug("tsdb reader offset seek to uid %ld ts %ld, table cur set to %d , all table num %d", uid, ts,
|
||||
pTableScanInfo->currentTable, tableSz);
|
||||
}
|
||||
/*}*/
|
||||
|
||||
} else {
|
||||
ASSERT(0);
|
||||
}
|
||||
return 0;
|
||||
} else {
|
||||
ASSERT(0);
|
||||
ASSERT(pOperator->numOfDownstream == 1);
|
||||
pOperator = pOperator->pDownstream[0];
|
||||
}
|
||||
return 0;
|
||||
} else {
|
||||
ASSERT(pOperator->numOfDownstream == 1);
|
||||
pOperator = pOperator->pDownstream[0];
|
||||
}
|
||||
}
|
||||
/*}*/
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
|
@ -594,10 +594,14 @@ int32_t projectApplyFunctions(SExprInfo* pExpr, SSDataBlock* pResult, SSDataBloc
|
|||
SColumnInfoData* pColInfoData = taosArrayGet(pResult->pDataBlock, outputSlotId);
|
||||
|
||||
int32_t offset = createNewColModel ? 0 : pResult->info.rows;
|
||||
for (int32_t i = 0; i < pSrcBlock->info.rows; ++i) {
|
||||
colDataAppend(pColInfoData, i + offset,
|
||||
taosVariantGet(&pExpr[k].base.pParam[0].param, pExpr[k].base.pParam[0].param.nType),
|
||||
TSDB_DATA_TYPE_NULL == pExpr[k].base.pParam[0].param.nType);
|
||||
|
||||
int32_t type = pExpr[k].base.pParam[0].param.nType;
|
||||
if (TSDB_DATA_TYPE_NULL == type) {
|
||||
colDataAppendNNULL(pColInfoData, offset, pSrcBlock->info.rows);
|
||||
} else {
|
||||
for (int32_t i = 0; i < pSrcBlock->info.rows; ++i) {
|
||||
colDataAppend(pColInfoData, i + offset, taosVariantGet(&pExpr[k].base.pParam[0].param, type), false);
|
||||
}
|
||||
}
|
||||
|
||||
numOfRows = pSrcBlock->info.rows;
|
||||
|
@ -1479,8 +1483,8 @@ int32_t finalizeResultRowIntoResultDataBlock(SDiskbasedBuf* pBuf, SResultRowPosi
|
|||
} else if (strcmp(pCtx[j].pExpr->pExpr->_function.functionName, "_select_value") == 0) {
|
||||
// do nothing, todo refactor
|
||||
} else {
|
||||
// expand the result into multiple rows. E.g., _wstartts, top(k, 20)
|
||||
// the _wstartts needs to copy to 20 following rows, since the results of top-k expands to 20 different rows.
|
||||
// expand the result into multiple rows. E.g., _wstart, top(k, 20)
|
||||
// the _wstart needs to copy to 20 following rows, since the results of top-k expands to 20 different rows.
|
||||
SColumnInfoData* pColInfoData = taosArrayGet(pBlock->pDataBlock, slotId);
|
||||
char* in = GET_ROWCELL_INTERBUF(pCtx[j].resultInfo);
|
||||
for (int32_t k = 0; k < pRow->numOfRows; ++k) {
|
||||
|
@ -1551,8 +1555,8 @@ int32_t doCopyToSDataBlock(SExecTaskInfo* pTaskInfo, SSDataBlock* pBlock, SExprI
|
|||
} else if (strcmp(pCtx[j].pExpr->pExpr->_function.functionName, "_select_value") == 0) {
|
||||
// do nothing, todo refactor
|
||||
} else {
|
||||
// expand the result into multiple rows. E.g., _wstartts, top(k, 20)
|
||||
// the _wstartts needs to copy to 20 following rows, since the results of top-k expands to 20 different rows.
|
||||
// expand the result into multiple rows. E.g., _wstart, top(k, 20)
|
||||
// the _wstart needs to copy to 20 following rows, since the results of top-k expands to 20 different rows.
|
||||
SColumnInfoData* pColInfoData = taosArrayGet(pBlock->pDataBlock, slotId);
|
||||
char* in = GET_ROWCELL_INTERBUF(pCtx[j].resultInfo);
|
||||
if (pCtx[j].increase) {
|
||||
|
@ -3235,6 +3239,10 @@ static SSDataBlock* doProjectOperation(SOperatorInfo* pOperator) {
|
|||
|
||||
SExecTaskInfo* pTaskInfo = pOperator->pTaskInfo;
|
||||
if (pOperator->status == OP_EXEC_DONE) {
|
||||
if (pTaskInfo->execModel == OPTR_EXEC_MODEL_QUEUE) {
|
||||
pOperator->status = OP_OPENED;
|
||||
return NULL;
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
@ -3268,11 +3276,15 @@ static SSDataBlock* doProjectOperation(SOperatorInfo* pOperator) {
|
|||
|
||||
while (1) {
|
||||
// The downstream exec may change the value of the newgroup, so use a local variable instead.
|
||||
qDebug("projection call next");
|
||||
SSDataBlock* pBlock = downstream->fpSet.getNextFn(downstream);
|
||||
if (pBlock == NULL) {
|
||||
// TODO optimize
|
||||
/*if (pTaskInfo->execModel != OPTR_EXEC_MODEL_STREAM) {*/
|
||||
qDebug("projection get null");
|
||||
|
||||
/*if (pTaskInfo->execModel == OPTR_EXEC_MODEL_BATCH) {*/
|
||||
doSetOperatorCompleted(pOperator);
|
||||
/*} else if (pTaskInfo->execModel == OPTR_EXEC_MODEL_QUEUE) {*/
|
||||
/*pOperator->status = OP_RES_TO_RETURN;*/
|
||||
/*}*/
|
||||
break;
|
||||
}
|
||||
|
@ -3463,9 +3475,12 @@ static SSDataBlock* doFill(SOperatorInfo* pOperator) {
|
|||
static void destroyExprInfo(SExprInfo* pExpr, int32_t numOfExprs) {
|
||||
for (int32_t i = 0; i < numOfExprs; ++i) {
|
||||
SExprInfo* pExprInfo = &pExpr[i];
|
||||
if (pExprInfo->pExpr->nodeType == QUERY_NODE_COLUMN) {
|
||||
taosMemoryFree(pExprInfo->base.pParam[0].pCol);
|
||||
for(int32_t j = 0; j < pExprInfo->base.numOfParams; ++j) {
|
||||
if (pExprInfo->base.pParam[j].type == FUNC_PARAM_TYPE_COLUMN) {
|
||||
taosMemoryFreeClear(pExprInfo->base.pParam[j].pCol);
|
||||
}
|
||||
}
|
||||
|
||||
taosMemoryFree(pExprInfo->base.pParam);
|
||||
taosMemoryFree(pExprInfo->pExpr);
|
||||
}
|
||||
|
@ -3673,10 +3688,20 @@ void destroyBasicOperatorInfo(void* param, int32_t numOfOutput) {
|
|||
taosMemoryFreeClear(param);
|
||||
}
|
||||
|
||||
|
||||
static void freeItem(void* pItem) {
|
||||
void** p = pItem;
|
||||
if (*p != NULL) {
|
||||
taosMemoryFreeClear(*p);
|
||||
}
|
||||
}
|
||||
|
||||
void destroyAggOperatorInfo(void* param, int32_t numOfOutput) {
|
||||
SAggOperatorInfo* pInfo = (SAggOperatorInfo*)param;
|
||||
cleanupBasicInfo(&pInfo->binfo);
|
||||
|
||||
cleanupAggSup(&pInfo->aggSup);
|
||||
taosArrayDestroyEx(pInfo->groupResInfo.pRows, freeItem);
|
||||
taosMemoryFreeClear(param);
|
||||
}
|
||||
|
||||
|
@ -4322,6 +4347,7 @@ SOperatorInfo* createOperatorTree(SPhysiNode* pPhyNode, SExecTaskInfo* pTaskInfo
|
|||
pTaskInfo->code = code;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
code = extractTableSchemaInfo(pHandle, pTableScanNode->scan.uid, pTaskInfo);
|
||||
if (code) {
|
||||
pTaskInfo->code = terrno;
|
||||
|
@ -4337,7 +4363,6 @@ SOperatorInfo* createOperatorTree(SPhysiNode* pPhyNode, SExecTaskInfo* pTaskInfo
|
|||
|
||||
} else if (QUERY_NODE_PHYSICAL_PLAN_EXCHANGE == type) {
|
||||
return createExchangeOperatorInfo(pHandle->pMsgCb->clientRpc, (SExchangePhysiNode*)pPhyNode, pTaskInfo);
|
||||
|
||||
} else if (QUERY_NODE_PHYSICAL_PLAN_STREAM_SCAN == type) {
|
||||
STableScanPhysiNode* pTableScanNode = (STableScanPhysiNode*)pPhyNode;
|
||||
STimeWindowAggSupp twSup = {
|
||||
|
|
|
@ -39,8 +39,6 @@ static int32_t buildSysDbTableInfo(const SSysTableScanInfo* pInfo, int32_t capac
|
|||
static int32_t buildDbTableInfoBlock(const SSDataBlock* p, const SSysTableMeta* pSysDbTableMeta, size_t size,
|
||||
const char* dbName);
|
||||
|
||||
static int32_t addTagPseudoColumnData(SReadHandle* pHandle, SExprInfo* pPseudoExpr, int32_t numOfPseudoExpr,
|
||||
SSDataBlock* pBlock, const char* idStr);
|
||||
static bool processBlockWithProbability(const SSampleExecInfo* pInfo);
|
||||
|
||||
bool processBlockWithProbability(const SSampleExecInfo* pInfo) {
|
||||
|
@ -198,12 +196,6 @@ static int32_t loadDataBlock(SOperatorInfo* pOperator, STableScanInfo* pTableSca
|
|||
pBlockInfo->window.skey, pBlockInfo->window.ekey, pBlockInfo->rows);
|
||||
pCost->skipBlocks += 1;
|
||||
|
||||
// clear all data in pBlock that are set when handing the previous block
|
||||
for (int32_t i = 0; i < taosArrayGetSize(pBlock->pDataBlock); ++i) {
|
||||
SColumnInfoData* pcol = taosArrayGet(pBlock->pDataBlock, i);
|
||||
pcol->pData = NULL;
|
||||
}
|
||||
|
||||
return TSDB_CODE_SUCCESS;
|
||||
} else if (*status == FUNC_DATA_REQUIRED_STATIS_LOAD) {
|
||||
pCost->loadBlockStatis += 1;
|
||||
|
@ -320,8 +312,6 @@ int32_t addTagPseudoColumnData(SReadHandle* pHandle, SExprInfo* pPseudoExpr, int
|
|||
int32_t dstSlotId = pExpr->base.resSchema.slotId;
|
||||
|
||||
SColumnInfoData* pColInfoData = taosArrayGet(pBlock->pDataBlock, dstSlotId);
|
||||
|
||||
colInfoDataEnsureCapacity(pColInfoData, pBlock->info.rows);
|
||||
colInfoDataCleanup(pColInfoData, pBlock->info.rows);
|
||||
|
||||
int32_t functionId = pExpr->pExpr->_function.functionId;
|
||||
|
@ -884,6 +874,28 @@ static bool prepareRangeScan(SStreamScanInfo* pInfo, SSDataBlock* pBlock, int32_
|
|||
return true;
|
||||
}
|
||||
|
||||
static STimeWindow getSlidingWindow(TSKEY* tsCol, SInterval* pInterval, SDataBlockInfo* pDataBlockInfo, int32_t* pRowIndex) {
|
||||
SResultRowInfo dumyInfo;
|
||||
dumyInfo.cur.pageId = -1;
|
||||
STimeWindow win = getActiveTimeWindow(NULL, &dumyInfo, tsCol[*pRowIndex], pInterval,
|
||||
TSDB_ORDER_ASC);
|
||||
STimeWindow endWin = win;
|
||||
STimeWindow preWin = win;
|
||||
while (1) {
|
||||
(*pRowIndex) += getNumOfRowsInTimeWindow(pDataBlockInfo, tsCol, *pRowIndex, endWin.ekey,
|
||||
binarySearchForKey, NULL, TSDB_ORDER_ASC);
|
||||
do {
|
||||
preWin = endWin;
|
||||
getNextTimeWindow(pInterval, &endWin, TSDB_ORDER_ASC);
|
||||
} while (tsCol[(*pRowIndex) - 1] >= endWin.skey);
|
||||
endWin = preWin;
|
||||
if (win.ekey == endWin.ekey || (*pRowIndex) == pDataBlockInfo->rows ) {
|
||||
win.ekey = endWin.ekey;
|
||||
return win;
|
||||
}
|
||||
win.ekey = endWin.ekey;
|
||||
}
|
||||
}
|
||||
static bool prepareDataScan(SStreamScanInfo* pInfo, SSDataBlock* pSDB, int32_t tsColIndex, int32_t* pRowIndex) {
|
||||
STimeWindow win = {
|
||||
.skey = INT64_MIN,
|
||||
|
@ -905,10 +917,13 @@ static bool prepareDataScan(SStreamScanInfo* pInfo, SSDataBlock* pSDB, int32_t t
|
|||
setGroupId(pInfo, pSDB, GROUPID_COLUMN_INDEX, *pRowIndex);
|
||||
(*pRowIndex) += updateSessionWindowInfo(pCurWin, tsCols, NULL, pSDB->info.rows, *pRowIndex, gap, NULL);
|
||||
} else {
|
||||
win = getActiveTimeWindow(NULL, &dumyInfo, tsCols[*pRowIndex], &pInfo->interval, TSDB_ORDER_ASC);
|
||||
setGroupId(pInfo, pSDB, GROUPID_COLUMN_INDEX, *pRowIndex);
|
||||
(*pRowIndex) +=
|
||||
getNumOfRowsInTimeWindow(&pSDB->info, tsCols, *pRowIndex, win.ekey, binarySearchForKey, NULL, TSDB_ORDER_ASC);
|
||||
pInfo->updateWin.skey = tsCols[*pRowIndex];
|
||||
win = getSlidingWindow(tsCols, &pInfo->interval, &pSDB->info, pRowIndex);
|
||||
pInfo->updateWin.ekey = tsCols[*pRowIndex - 1];
|
||||
// win = getActiveTimeWindow(NULL, &dumyInfo, tsCols[*pRowIndex], &pInfo->interval, TSDB_ORDER_ASC);
|
||||
// (*pRowIndex) +=
|
||||
// getNumOfRowsInTimeWindow(&pSDB->info, tsCols, *pRowIndex, win.ekey, binarySearchForKey, NULL, TSDB_ORDER_ASC);
|
||||
}
|
||||
needRead = true;
|
||||
} else if (isStateWindow(pInfo)) {
|
||||
|
@ -974,10 +989,12 @@ static SSDataBlock* doDataScan(SStreamScanInfo* pInfo, SSDataBlock* pSDB, int32_
|
|||
}
|
||||
}
|
||||
if (!pResult) {
|
||||
pInfo->updateWin = (STimeWindow){.skey = INT64_MIN, .ekey = INT64_MAX};
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (pResult->info.groupId == pInfo->groupId) {
|
||||
pResult->info.calWin = pInfo->updateWin;
|
||||
return pResult;
|
||||
}
|
||||
}
|
||||
|
@ -1130,10 +1147,11 @@ static int32_t setBlockIntoRes(SStreamScanInfo* pInfo, const SSDataBlock* pBlock
|
|||
SOperatorInfo* pOperator = pInfo->pStreamScanOp;
|
||||
SExecTaskInfo* pTaskInfo = pInfo->pStreamScanOp->pTaskInfo;
|
||||
|
||||
blockDataEnsureCapacity(pInfo->pRes, pBlock->info.rows);
|
||||
|
||||
pInfo->pRes->info.rows = pBlock->info.rows;
|
||||
pInfo->pRes->info.uid = pBlock->info.uid;
|
||||
pInfo->pRes->info.type = STREAM_NORMAL;
|
||||
pInfo->pRes->info.capacity = pBlock->info.rows;
|
||||
|
||||
uint64_t* groupIdPre = taosHashGet(pOperator->pTaskInfo->tableqinfoList.map, &pBlock->info.uid, sizeof(int64_t));
|
||||
if (groupIdPre) {
|
||||
|
@ -1159,7 +1177,10 @@ static int32_t setBlockIntoRes(SStreamScanInfo* pInfo, const SSDataBlock* pBlock
|
|||
for (int32_t j = 0; j < blockDataGetNumOfCols(pBlock); ++j) {
|
||||
SColumnInfoData* pResCol = bdGetColumnInfoData(pBlock, j);
|
||||
if (pResCol->info.colId == pColMatchInfo->colId) {
|
||||
taosArraySet(pInfo->pRes->pDataBlock, pColMatchInfo->targetSlotId, pResCol);
|
||||
|
||||
SColumnInfoData* pDst = taosArrayGet(pInfo->pRes->pDataBlock, pColMatchInfo->targetSlotId);
|
||||
colDataAssign(pDst, pResCol, pBlock->info.rows, &pInfo->pRes->info);
|
||||
// taosArraySet(pInfo->pRes->pDataBlock, pColMatchInfo->targetSlotId, pResCol);
|
||||
colExists = true;
|
||||
break;
|
||||
}
|
||||
|
@ -1175,15 +1196,6 @@ static int32_t setBlockIntoRes(SStreamScanInfo* pInfo, const SSDataBlock* pBlock
|
|||
taosArrayDestroy(pBlock->pDataBlock);
|
||||
|
||||
ASSERT(pInfo->pRes->pDataBlock != NULL);
|
||||
#if 0
|
||||
if (pInfo->pRes->pDataBlock == NULL) {
|
||||
// TODO add log
|
||||
updateInfoDestoryColseWinSBF(pInfo->pUpdateInfo);
|
||||
pOperator->status = OP_EXEC_DONE;
|
||||
pTaskInfo->code = terrno;
|
||||
return -1;
|
||||
}
|
||||
#endif
|
||||
|
||||
// currently only the tbname pseudo column
|
||||
if (pInfo->numOfPseudoExpr > 0) {
|
||||
|
@ -1204,11 +1216,7 @@ static SSDataBlock* doStreamScan(SOperatorInfo* pOperator) {
|
|||
SExecTaskInfo* pTaskInfo = pOperator->pTaskInfo;
|
||||
SStreamScanInfo* pInfo = pOperator->info;
|
||||
|
||||
/*pTaskInfo->code = pOperator->fpSet._openFn(pOperator);*/
|
||||
/*if (pTaskInfo->code != TSDB_CODE_SUCCESS || pOperator->status == OP_EXEC_DONE) {*/
|
||||
/*return NULL;*/
|
||||
/*}*/
|
||||
|
||||
qDebug("stream scan called");
|
||||
if (pTaskInfo->streamInfo.prepareStatus.type == TMQ_OFFSET__LOG) {
|
||||
while (1) {
|
||||
SFetchRet ret = {0};
|
||||
|
@ -1220,6 +1228,7 @@ static SSDataBlock* doStreamScan(SOperatorInfo* pOperator) {
|
|||
}
|
||||
// TODO clean data block
|
||||
if (pInfo->pRes->info.rows > 0) {
|
||||
qDebug("stream scan log return %d rows", pInfo->pRes->info.rows);
|
||||
return pInfo->pRes;
|
||||
}
|
||||
} else if (ret.fetchType == FETCH_TYPE__META) {
|
||||
|
@ -1230,6 +1239,7 @@ static SSDataBlock* doStreamScan(SOperatorInfo* pOperator) {
|
|||
} else if (ret.fetchType == FETCH_TYPE__NONE) {
|
||||
pTaskInfo->streamInfo.lastStatus = ret.offset;
|
||||
ASSERT(pTaskInfo->streamInfo.lastStatus.version + 1 >= pTaskInfo->streamInfo.prepareStatus.version);
|
||||
qDebug("stream scan log return null");
|
||||
return NULL;
|
||||
} else {
|
||||
ASSERT(0);
|
||||
|
@ -1237,7 +1247,12 @@ static SSDataBlock* doStreamScan(SOperatorInfo* pOperator) {
|
|||
}
|
||||
} else if (pTaskInfo->streamInfo.prepareStatus.type == TMQ_OFFSET__SNAPSHOT_DATA) {
|
||||
SSDataBlock* pResult = doTableScan(pInfo->pTableScanOp);
|
||||
return pResult && pResult->info.rows > 0 ? pResult : NULL;
|
||||
if (pResult && pResult->info.rows > 0) {
|
||||
qDebug("stream scan tsdb return %d rows", pResult->info.rows);
|
||||
return pResult;
|
||||
}
|
||||
qDebug("stream scan tsdb return null");
|
||||
return NULL;
|
||||
} else if (pTaskInfo->streamInfo.prepareStatus.type == TMQ_OFFSET__SNAPSHOT_META) {
|
||||
// TODO scan meta
|
||||
ASSERT(0);
|
||||
|
@ -1256,8 +1271,13 @@ static SSDataBlock* doStreamScan(SOperatorInfo* pOperator) {
|
|||
int32_t current = pInfo->validBlockIndex++;
|
||||
SSDataBlock* pBlock = taosArrayGetP(pInfo->pBlockLists, current);
|
||||
// TODO move into scan
|
||||
pBlock->info.calWin.skey = INT64_MIN;
|
||||
pBlock->info.calWin.ekey = INT64_MAX;
|
||||
blockDataUpdateTsWindow(pBlock, 0);
|
||||
switch (pBlock->info.type) {
|
||||
case STREAM_NORMAL:
|
||||
case STREAM_GET_ALL:
|
||||
return pBlock;
|
||||
case STREAM_RETRIEVE: {
|
||||
pInfo->blockType = STREAM_INPUT__DATA_SUBMIT;
|
||||
pInfo->scanMode = STREAM_SCAN_FROM_DATAREADER_RETRIEVE;
|
||||
|
@ -1287,6 +1307,7 @@ static SSDataBlock* doStreamScan(SOperatorInfo* pOperator) {
|
|||
}
|
||||
return pBlock;
|
||||
} else if (pInfo->blockType == STREAM_INPUT__DATA_SUBMIT) {
|
||||
qDebug("scan mode %d", pInfo->scanMode);
|
||||
if (pInfo->scanMode == STREAM_SCAN_FROM_RES) {
|
||||
blockDataDestroy(pInfo->pUpdateRes);
|
||||
pInfo->scanMode = STREAM_SCAN_FROM_READERHANDLE;
|
||||
|
@ -1381,18 +1402,9 @@ static SSDataBlock* doStreamScan(SOperatorInfo* pOperator) {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
qDebug("scan rows: %d", pBlockInfo->rows);
|
||||
return (pBlockInfo->rows == 0) ? NULL : pInfo->pRes;
|
||||
|
||||
#if 0
|
||||
} else if (pInfo->blockType == STREAM_INPUT__TABLE_SCAN) {
|
||||
ASSERT(0);
|
||||
// check reader last status
|
||||
// if not match, reset status
|
||||
SSDataBlock* pResult = doTableScan(pInfo->pTableScanOp);
|
||||
return pResult && pResult->info.rows > 0 ? pResult : NULL;
|
||||
#endif
|
||||
|
||||
} else {
|
||||
ASSERT(0);
|
||||
return NULL;
|
||||
|
@ -1533,6 +1545,7 @@ SOperatorInfo* createStreamScanOperatorInfo(SReadHandle* pHandle, STableScanPhys
|
|||
pInfo->pStreamScanOp = pOperator;
|
||||
pInfo->deleteDataIndex = 0;
|
||||
pInfo->pDeleteDataRes = createPullDataBlock();
|
||||
pInfo->updateWin = (STimeWindow){.skey = INT64_MAX, .ekey = INT64_MAX};
|
||||
|
||||
pOperator->name = "StreamScanOperator";
|
||||
pOperator->operatorType = QUERY_NODE_PHYSICAL_PLAN_STREAM_SCAN;
|
||||
|
@ -2377,6 +2390,7 @@ int32_t createScanTableListInfo(STableScanPhysiNode* pTableScanNode, SReadHandle
|
|||
qDebug("no table qualified for query, TID:0x%" PRIx64 ", QID:0x%" PRIx64, taskId, queryId);
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
pTableListInfo->needSortTableByGroupId = pTableScanNode->groupSort;
|
||||
code = generateGroupIdMap(pTableListInfo, pHandle, pTableScanNode->pGroupTags);
|
||||
if (code != TSDB_CODE_SUCCESS) {
|
||||
|
@ -2550,9 +2564,11 @@ static SSDataBlock* getTableDataBlock(void* param) {
|
|||
SDataBlockInfo binfo = pBlock->info;
|
||||
tsdbRetrieveDataBlockInfo(reader, &binfo);
|
||||
|
||||
binfo.capacity = binfo.rows;
|
||||
blockDataEnsureCapacity(pBlock, binfo.capacity);
|
||||
pBlock->info = binfo;
|
||||
blockDataEnsureCapacity(pBlock, binfo.rows);
|
||||
pBlock->info.type = binfo.type;
|
||||
pBlock->info.uid = binfo.uid;
|
||||
pBlock->info.window = binfo.window;
|
||||
pBlock->info.rows = binfo.rows;
|
||||
|
||||
uint32_t status = 0;
|
||||
int32_t code = loadDataBlockFromOneTable(pOperator, pTableScanInfo, readerIdx, pBlock, &status);
|
||||
|
@ -2579,11 +2595,19 @@ static SSDataBlock* getTableDataBlock(void* param) {
|
|||
return NULL;
|
||||
}
|
||||
|
||||
SArray* generateSortByTsInfo(int32_t order) {
|
||||
SArray* generateSortByTsInfo(SArray* colMatchInfo, int32_t order) {
|
||||
int32_t tsTargetSlotId = 0;
|
||||
for (int32_t i = 0; i < taosArrayGetSize(colMatchInfo); ++i) {
|
||||
SColMatchInfo* colInfo = taosArrayGet(colMatchInfo, i);
|
||||
if (colInfo->colId == PRIMARYKEY_TIMESTAMP_COL_ID) {
|
||||
tsTargetSlotId = colInfo->targetSlotId;
|
||||
}
|
||||
}
|
||||
|
||||
SArray* pList = taosArrayInit(1, sizeof(SBlockOrderInfo));
|
||||
SBlockOrderInfo bi = {0};
|
||||
bi.order = order;
|
||||
bi.slotId = 0;
|
||||
bi.slotId = tsTargetSlotId;
|
||||
bi.nullFirst = NULL_ORDER_FIRST;
|
||||
|
||||
taosArrayPush(pList, &bi);
|
||||
|
@ -2832,7 +2856,7 @@ SOperatorInfo* createTableMergeScanOperatorInfo(STableScanPhysiNode* pTableScanN
|
|||
|
||||
pInfo->sortSourceParams = taosArrayInit(64, sizeof(STableMergeScanSortSourceParam));
|
||||
|
||||
pInfo->pSortInfo = generateSortByTsInfo(pInfo->cond.order);
|
||||
pInfo->pSortInfo = generateSortByTsInfo(pInfo->pColMatchInfo, pInfo->cond.order);
|
||||
pInfo->pSortInputBlock = createOneDataBlock(pInfo->pResBlock, false);
|
||||
|
||||
int32_t rowSize = pInfo->pResBlock->info.rowSize;
|
||||
|
|
|
@ -621,7 +621,9 @@ SSDataBlock* getMultiwaySortedBlockData(SSortHandle* pHandle, SSDataBlock* pData
|
|||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (pInfo->groupSort) {
|
||||
pInfo->hasGroupId = false;
|
||||
}
|
||||
if (p->info.rows > 0) { // todo extract method
|
||||
blockDataEnsureCapacity(pDataBlock, p->info.rows);
|
||||
int32_t numOfCols = taosArrayGetSize(pColMatchInfo);
|
||||
|
|
|
@ -419,6 +419,14 @@ static bool setTimeWindowInterpolationEndTs(SIntervalAggOperatorInfo* pInfo, SEx
|
|||
return true;
|
||||
}
|
||||
|
||||
bool inSlidingWindow(SInterval* pInterval, STimeWindow* pWin, SDataBlockInfo* pBlockInfo) {
|
||||
if (pInterval->interval != pInterval->sliding &&
|
||||
(pWin->ekey < pBlockInfo->calWin.skey || pWin->skey > pBlockInfo->calWin.ekey)) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
static int32_t getNextQualifiedWindow(SInterval* pInterval, STimeWindow* pNext, SDataBlockInfo* pDataBlockInfo,
|
||||
TSKEY* primaryKeys, int32_t prevPosition, int32_t order) {
|
||||
bool ascQuery = (order == TSDB_ORDER_ASC);
|
||||
|
@ -432,6 +440,10 @@ static int32_t getNextQualifiedWindow(SInterval* pInterval, STimeWindow* pNext,
|
|||
return -1;
|
||||
}
|
||||
|
||||
if (!inSlidingWindow(pInterval, pNext, pDataBlockInfo) && order == TSDB_ORDER_ASC) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
TSKEY skey = ascQuery ? pNext->skey : pNext->ekey;
|
||||
int32_t startPos = 0;
|
||||
|
||||
|
@ -801,7 +813,8 @@ static void hashIntervalAgg(SOperatorInfo* pOperatorInfo, SResultRowInfo* pResul
|
|||
|
||||
STimeWindow win = getActiveTimeWindow(pInfo->aggSup.pResultBuf, pResultRowInfo, ts, &pInfo->interval, pInfo->order);
|
||||
int32_t ret = TSDB_CODE_SUCCESS;
|
||||
if (!pInfo->ignoreExpiredData || !isCloseWindow(&win, &pInfo->twAggSup)) {
|
||||
if ((!pInfo->ignoreExpiredData || !isCloseWindow(&win, &pInfo->twAggSup)) &&
|
||||
inSlidingWindow(&pInfo->interval, &win, &pBlock->info)) {
|
||||
ret = setTimeWindowOutputBuf(pResultRowInfo, &win, (scanFlag == MAIN_SCAN), &pResult, tableGroupId, pSup->pCtx,
|
||||
numOfOutput, pSup->rowEntryInfoOffset, &pInfo->aggSup, pTaskInfo);
|
||||
if (ret != TSDB_CODE_SUCCESS || pResult == NULL) {
|
||||
|
@ -834,7 +847,8 @@ static void hashIntervalAgg(SOperatorInfo* pOperatorInfo, SResultRowInfo* pResul
|
|||
doWindowBorderInterpolation(pInfo, pBlock, pResult, &win, startPos, forwardRows, pSup);
|
||||
}
|
||||
|
||||
if (!pInfo->ignoreExpiredData || !isCloseWindow(&win, &pInfo->twAggSup)) {
|
||||
if ((!pInfo->ignoreExpiredData || !isCloseWindow(&win, &pInfo->twAggSup)) &&
|
||||
inSlidingWindow(&pInfo->interval, &win, &pBlock->info)) {
|
||||
updateTimeWindowInfo(&pInfo->twAggSup.timeWindowData, &win, true);
|
||||
doApplyFunctions(pTaskInfo, pSup->pCtx, &win, &pInfo->twAggSup.timeWindowData, startPos, forwardRows, tsCols,
|
||||
pBlock->info.rows, numOfOutput, pInfo->order);
|
||||
|
@ -1278,18 +1292,25 @@ static void doClearWindows(SAggSupporter* pAggSup, SExprSupp* pSup1, SInterval*
|
|||
SColumnInfoData* pGpCol = taosArrayGet(pBlock->pDataBlock, GROUPID_COLUMN_INDEX);
|
||||
pGpDatas = (uint64_t*)pGpCol->pData;
|
||||
}
|
||||
int32_t step = 0;
|
||||
for (int32_t i = 0; i < pBlock->info.rows; i += step) {
|
||||
SResultRowInfo dumyInfo;
|
||||
dumyInfo.cur.pageId = -1;
|
||||
STimeWindow win = getActiveTimeWindow(NULL, &dumyInfo, tsCols[i], pInterval, TSDB_ORDER_ASC);
|
||||
step = getNumOfRowsInTimeWindow(&pBlock->info, tsCols, i, win.ekey, binarySearchForKey, NULL, TSDB_ORDER_ASC);
|
||||
uint64_t winGpId = pGpDatas ? pGpDatas[i] : pBlock->info.groupId;
|
||||
bool res = doClearWindow(pAggSup, pSup1, (char*)&win.skey, sizeof(TKEY), winGpId, numOfOutput);
|
||||
int32_t step = 0;
|
||||
int32_t startPos = 0;
|
||||
SResultRowInfo dumyInfo;
|
||||
dumyInfo.cur.pageId = -1;
|
||||
STimeWindow win = getActiveTimeWindow(NULL, &dumyInfo, tsCols[0], pInterval, TSDB_ORDER_ASC);
|
||||
while (1) {
|
||||
step =
|
||||
getNumOfRowsInTimeWindow(&pBlock->info, tsCols, startPos, win.ekey, binarySearchForKey, NULL, TSDB_ORDER_ASC);
|
||||
uint64_t winGpId = pGpDatas ? pGpDatas[startPos] : pBlock->info.groupId;
|
||||
bool res = doClearWindow(pAggSup, pSup1, (char*)&win.skey, sizeof(TSKEY), winGpId, numOfOutput);
|
||||
if (pUpWins && res) {
|
||||
SWinRes winRes = {.ts = win.skey, .groupId = winGpId};
|
||||
taosArrayPush(pUpWins, &winRes);
|
||||
}
|
||||
int32_t prevEndPos = step - 1 + startPos;
|
||||
startPos = getNextQualifiedWindow(pInterval, &win, &pBlock->info, tsCols, prevEndPos, TSDB_ORDER_ASC);
|
||||
if (startPos < 0) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1320,9 +1341,9 @@ static int32_t closeIntervalWindow(SHashObj* pHashMap, STimeWindowAggSupp* pSup,
|
|||
uint64_t groupId = *(uint64_t*)key;
|
||||
ASSERT(keyLen == GET_RES_WINDOW_KEY_LEN(sizeof(TSKEY)));
|
||||
TSKEY ts = *(int64_t*)((char*)key + sizeof(uint64_t));
|
||||
SResultRowInfo dumyInfo;
|
||||
dumyInfo.cur.pageId = -1;
|
||||
STimeWindow win = getActiveTimeWindow(NULL, &dumyInfo, ts, pInterval, TSDB_ORDER_ASC);
|
||||
STimeWindow win;
|
||||
win.skey = ts;
|
||||
win.ekey = taosTimeAdd(win.skey, pInterval->interval, pInterval->intervalUnit, pInterval->precision) - 1;
|
||||
SWinRes winRe = {
|
||||
.ts = win.skey,
|
||||
.groupId = groupId,
|
||||
|
@ -1332,13 +1353,13 @@ static int32_t closeIntervalWindow(SHashObj* pHashMap, STimeWindowAggSupp* pSup,
|
|||
if (chIds && pPullDataMap) {
|
||||
SArray* chAy = *(SArray**)chIds;
|
||||
int32_t size = taosArrayGetSize(chAy);
|
||||
qInfo("window %" PRId64 " wait child size:%d", win.skey, size);
|
||||
qDebug("window %" PRId64 " wait child size:%d", win.skey, size);
|
||||
for (int32_t i = 0; i < size; i++) {
|
||||
qInfo("window %" PRId64 " wait chid id:%d", win.skey, *(int32_t*)taosArrayGet(chAy, i));
|
||||
qDebug("window %" PRId64 " wait chid id:%d", win.skey, *(int32_t*)taosArrayGet(chAy, i));
|
||||
}
|
||||
continue;
|
||||
} else if (pPullDataMap) {
|
||||
qInfo("close window %" PRId64, win.skey);
|
||||
qDebug("close window %" PRId64, win.skey);
|
||||
}
|
||||
SResultRowPosition* pPos = (SResultRowPosition*)pIte;
|
||||
if (pSup->calTrigger == STREAM_TRIGGER_WINDOW_CLOSE) {
|
||||
|
@ -1579,7 +1600,7 @@ static bool timeWindowinterpNeeded(SqlFunctionCtx* pCtx, int32_t numOfCols, SInt
|
|||
}
|
||||
|
||||
void increaseTs(SqlFunctionCtx* pCtx) {
|
||||
if (pCtx[0].pExpr->pExpr->_function.pFunctNode->funcType == FUNCTION_TYPE_WSTARTTS) {
|
||||
if (pCtx[0].pExpr->pExpr->_function.pFunctNode->funcType == FUNCTION_TYPE_WSTART) {
|
||||
pCtx[0].increase = true;
|
||||
}
|
||||
}
|
||||
|
@ -2434,7 +2455,7 @@ static void doHashInterval(SOperatorInfo* pOperatorInfo, SSDataBlock* pSDataBloc
|
|||
}
|
||||
while (1) {
|
||||
bool isClosed = isCloseWindow(&nextWin, &pInfo->twAggSup);
|
||||
if (pInfo->ignoreExpiredData && isClosed) {
|
||||
if ((pInfo->ignoreExpiredData && isClosed) || !inSlidingWindow(&pInfo->interval, &nextWin, &pSDataBlock->info)) {
|
||||
startPos = getNexWindowPos(&pInfo->interval, &pSDataBlock->info, tsCols, startPos, nextWin.ekey, &nextWin);
|
||||
if (startPos < 0) {
|
||||
break;
|
||||
|
@ -2491,8 +2512,8 @@ static void doHashInterval(SOperatorInfo* pOperatorInfo, SSDataBlock* pSDataBloc
|
|||
if (IS_FINAL_OP(pInfo)) {
|
||||
forwardRows = 1;
|
||||
} else {
|
||||
forwardRows = getNumOfRowsInTimeWindow(&pSDataBlock->info, tsCols, startPos, nextWin.ekey, binarySearchForKey, NULL,
|
||||
TSDB_ORDER_ASC);
|
||||
forwardRows = getNumOfRowsInTimeWindow(&pSDataBlock->info, tsCols, startPos, nextWin.ekey, binarySearchForKey,
|
||||
NULL, TSDB_ORDER_ASC);
|
||||
}
|
||||
if (pInfo->twAggSup.calTrigger == STREAM_TRIGGER_AT_ONCE && pUpdated) {
|
||||
saveResultRow(pResult, tableGroupId, pUpdated);
|
||||
|
@ -2609,6 +2630,8 @@ static SSDataBlock* doStreamFinalIntervalAgg(SOperatorInfo* pOperator) {
|
|||
|
||||
SExprSupp* pSup = &pOperator->exprSupp;
|
||||
|
||||
qDebug("interval status %d %s", pOperator->status, IS_FINAL_OP(pInfo) ? "interval Final" : "interval Semi");
|
||||
|
||||
if (pOperator->status == OP_EXEC_DONE) {
|
||||
return NULL;
|
||||
} else if (pOperator->status == OP_RES_TO_RETURN) {
|
||||
|
@ -2659,7 +2682,7 @@ static SSDataBlock* doStreamFinalIntervalAgg(SOperatorInfo* pOperator) {
|
|||
clearSpecialDataBlock(pInfo->pUpdateRes);
|
||||
removeDeleteResults(pUpdated, pInfo->pDelWins);
|
||||
pOperator->status = OP_RES_TO_RETURN;
|
||||
qInfo("%s return data", IS_FINAL_OP(pInfo) ? "interval Final" : "interval Semi");
|
||||
qDebug("%s return data", IS_FINAL_OP(pInfo) ? "interval Final" : "interval Semi");
|
||||
break;
|
||||
}
|
||||
printDataBlock(pBlock, IS_FINAL_OP(pInfo) ? "interval Final recv" : "interval Semi recv");
|
||||
|
@ -3101,12 +3124,7 @@ int64_t getSessionWindowEndkey(void* data, int32_t index) {
|
|||
}
|
||||
|
||||
bool isInTimeWindow(STimeWindow* pWin, TSKEY ts, int64_t gap) {
|
||||
int64_t sGap = ts - pWin->skey + gap;
|
||||
int64_t eGap = pWin->ekey - ts + gap;
|
||||
// if ((sGap < 0 && sGap >= -gap) || (eGap < 0 && eGap >= -gap) || (sGap >= 0 && eGap >= 0)) {
|
||||
// return true;
|
||||
// }
|
||||
if (sGap >= 0 && eGap >= 0) {
|
||||
if (ts + gap >= pWin->skey && ts - gap <= pWin->ekey) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
|
@ -4489,13 +4507,14 @@ static SSDataBlock* doMergeAlignedIntervalAgg(SOperatorInfo* pOperator) {
|
|||
setInputDataBlock(pOperator, pSup->pCtx, pBlock, iaInfo->order, scanFlag, true);
|
||||
doMergeAlignedIntervalAggImpl(pOperator, &iaInfo->binfo.resultRowInfo, pBlock, scanFlag, pRes);
|
||||
doFilter(miaInfo->pCondition, pRes);
|
||||
if (pRes->info.rows > 0) {
|
||||
if (pRes->info.rows >= pOperator->resultInfo.capacity) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
pRes->info.groupId = miaInfo->groupId;
|
||||
}
|
||||
miaInfo->hasGroupId = false;
|
||||
|
||||
if (miaInfo->inputBlocksFinished) {
|
||||
doSetOperatorCompleted(pOperator);
|
||||
|
|
|
@ -47,6 +47,7 @@ extern "C" {
|
|||
#define FUNC_MGT_FORBID_WINDOW_FUNC FUNC_MGT_FUNC_CLASSIFICATION_MASK(18)
|
||||
#define FUNC_MGT_FORBID_GROUP_BY_FUNC FUNC_MGT_FUNC_CLASSIFICATION_MASK(19)
|
||||
#define FUNC_MGT_SYSTEM_INFO_FUNC FUNC_MGT_FUNC_CLASSIFICATION_MASK(20)
|
||||
#define FUNC_MGT_CLIENT_PC_FUNC FUNC_MGT_FUNC_CLASSIFICATION_MASK(21)
|
||||
|
||||
#define FUNC_MGT_TEST_MASK(val, mask) (((val) & (mask)) != 0)
|
||||
|
||||
|
|
|
@ -1976,7 +1976,7 @@ const SBuiltinFuncDefinition funcMgtBuiltins[] = {
|
|||
{
|
||||
.name = "leastsquares",
|
||||
.type = FUNCTION_TYPE_LEASTSQUARES,
|
||||
.classification = FUNC_MGT_AGG_FUNC | FUNC_MGT_FORBID_STREAM_FUNC,
|
||||
.classification = FUNC_MGT_AGG_FUNC | FUNC_MGT_TIMELINE_FUNC | FUNC_MGT_FORBID_STREAM_FUNC,
|
||||
.translateFunc = translateLeastSQR,
|
||||
.getEnvFunc = getLeastSQRFuncEnv,
|
||||
.initFunc = leastSQRFunctionSetup,
|
||||
|
@ -2217,7 +2217,7 @@ const SBuiltinFuncDefinition funcMgtBuiltins[] = {
|
|||
{
|
||||
.name = "last_row",
|
||||
.type = FUNCTION_TYPE_LAST_ROW,
|
||||
.classification = FUNC_MGT_AGG_FUNC | FUNC_MGT_MULTI_RES_FUNC | FUNC_MGT_SELECT_FUNC | FUNC_MGT_TIMELINE_FUNC,
|
||||
.classification = FUNC_MGT_AGG_FUNC | FUNC_MGT_MULTI_RES_FUNC | FUNC_MGT_SELECT_FUNC | FUNC_MGT_TIMELINE_FUNC | FUNC_MGT_IMPLICIT_TS_FUNC,
|
||||
.translateFunc = translateFirstLast,
|
||||
.getEnvFunc = getFirstLastFuncEnv,
|
||||
.initFunc = functionSetup,
|
||||
|
@ -2784,28 +2784,38 @@ const SBuiltinFuncDefinition funcMgtBuiltins[] = {
|
|||
.finalizeFunc = NULL
|
||||
},
|
||||
{
|
||||
.name = "_qstartts",
|
||||
.type = FUNCTION_TYPE_QSTARTTS,
|
||||
.classification = FUNC_MGT_PSEUDO_COLUMN_FUNC | FUNC_MGT_WINDOW_PC_FUNC,
|
||||
.name = "_qstart",
|
||||
.type = FUNCTION_TYPE_QSTART,
|
||||
.classification = FUNC_MGT_PSEUDO_COLUMN_FUNC | FUNC_MGT_CLIENT_PC_FUNC,
|
||||
.translateFunc = translateTimePseudoColumn,
|
||||
.getEnvFunc = getTimePseudoFuncEnv,
|
||||
.getEnvFunc = NULL,
|
||||
.initFunc = NULL,
|
||||
.sprocessFunc = qStartTsFunction,
|
||||
.sprocessFunc = NULL,
|
||||
.finalizeFunc = NULL
|
||||
},
|
||||
{
|
||||
.name = "_qendts",
|
||||
.type = FUNCTION_TYPE_QENDTS,
|
||||
.classification = FUNC_MGT_PSEUDO_COLUMN_FUNC | FUNC_MGT_WINDOW_PC_FUNC,
|
||||
.name = "_qend",
|
||||
.type = FUNCTION_TYPE_QEND,
|
||||
.classification = FUNC_MGT_PSEUDO_COLUMN_FUNC | FUNC_MGT_CLIENT_PC_FUNC,
|
||||
.translateFunc = translateTimePseudoColumn,
|
||||
.getEnvFunc = getTimePseudoFuncEnv,
|
||||
.getEnvFunc = NULL,
|
||||
.initFunc = NULL,
|
||||
.sprocessFunc = qEndTsFunction,
|
||||
.sprocessFunc = NULL,
|
||||
.finalizeFunc = NULL
|
||||
},
|
||||
{
|
||||
.name = "_wstartts",
|
||||
.type = FUNCTION_TYPE_WSTARTTS,
|
||||
.name = "_qduration",
|
||||
.type = FUNCTION_TYPE_QDURATION,
|
||||
.classification = FUNC_MGT_PSEUDO_COLUMN_FUNC | FUNC_MGT_CLIENT_PC_FUNC,
|
||||
.translateFunc = translateWduration,
|
||||
.getEnvFunc = NULL,
|
||||
.initFunc = NULL,
|
||||
.sprocessFunc = NULL,
|
||||
.finalizeFunc = NULL
|
||||
},
|
||||
{
|
||||
.name = "_wstart",
|
||||
.type = FUNCTION_TYPE_WSTART,
|
||||
.classification = FUNC_MGT_PSEUDO_COLUMN_FUNC | FUNC_MGT_WINDOW_PC_FUNC,
|
||||
.translateFunc = translateTimePseudoColumn,
|
||||
.getEnvFunc = getTimePseudoFuncEnv,
|
||||
|
@ -2814,8 +2824,8 @@ const SBuiltinFuncDefinition funcMgtBuiltins[] = {
|
|||
.finalizeFunc = NULL
|
||||
},
|
||||
{
|
||||
.name = "_wendts",
|
||||
.type = FUNCTION_TYPE_WENDTS,
|
||||
.name = "_wend",
|
||||
.type = FUNCTION_TYPE_WEND,
|
||||
.classification = FUNC_MGT_PSEUDO_COLUMN_FUNC | FUNC_MGT_WINDOW_PC_FUNC,
|
||||
.translateFunc = translateTimePseudoColumn,
|
||||
.getEnvFunc = getTimePseudoFuncEnv,
|
||||
|
|
|
@ -81,8 +81,11 @@ typedef struct STopBotRes {
|
|||
|
||||
typedef struct SFirstLastRes {
|
||||
bool hasResult;
|
||||
bool isNull; // used for last_row function only
|
||||
// used for last_row function only, isNullRes in SResultRowEntry can not be passed to downstream.So,
|
||||
// this attribute is required
|
||||
bool isNull;
|
||||
int32_t bytes;
|
||||
int64_t ts;
|
||||
char buf[];
|
||||
} SFirstLastRes;
|
||||
|
||||
|
@ -1144,9 +1147,9 @@ static void copyTupleData(SqlFunctionCtx* pCtx, int32_t rowIndex, const SSDataBl
|
|||
|
||||
static int32_t findRowIndex(int32_t start, int32_t num, SColumnInfoData* pCol, const char* tval) {
|
||||
// the data is loaded, not only the block SMA value
|
||||
for(int32_t i = start; i < num + start; ++i) {
|
||||
for (int32_t i = start; i < num + start; ++i) {
|
||||
char* p = colDataGetData(pCol, i);
|
||||
if (memcpy((void*)tval, p, pCol->info.bytes) == 0) {
|
||||
if (memcpy((void*)tval, p, pCol->info.bytes) == 0) {
|
||||
return i;
|
||||
}
|
||||
}
|
||||
|
@ -1154,7 +1157,6 @@ static int32_t findRowIndex(int32_t start, int32_t num, SColumnInfoData* pCol, c
|
|||
ASSERT(0);
|
||||
}
|
||||
|
||||
|
||||
int32_t doMinMaxHelper(SqlFunctionCtx* pCtx, int32_t isMinFunc) {
|
||||
int32_t numOfElems = 0;
|
||||
|
||||
|
@ -1631,10 +1633,14 @@ void setNullSelectivityValue(SqlFunctionCtx* pCtx, SSDataBlock* pBlock, int32_t
|
|||
}
|
||||
|
||||
void setSelectivityValue(SqlFunctionCtx* pCtx, SSDataBlock* pBlock, const STuplePos* pTuplePos, int32_t rowIndex) {
|
||||
if (pCtx->subsidiaries.num <= 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
int32_t pageId = pTuplePos->pageId;
|
||||
int32_t offset = pTuplePos->offset;
|
||||
|
||||
if (pTuplePos->pageId != -1 && pCtx->subsidiaries.num > 0) {
|
||||
if (pTuplePos->pageId != -1) {
|
||||
int32_t numOfCols = pCtx->subsidiaries.num;
|
||||
SFilePage* pPage = getBufPage(pCtx->pBuf, pageId);
|
||||
|
||||
|
@ -1934,7 +1940,7 @@ int32_t stddevFunctionMerge(SqlFunctionCtx* pCtx) {
|
|||
|
||||
SStddevRes* pInfo = GET_ROWCELL_INTERBUF(GET_RES_INFO(pCtx));
|
||||
|
||||
for(int32_t i = pInput->startRowIndex; i < pInput->startRowIndex + pInput->numOfRows; ++i) {
|
||||
for (int32_t i = pInput->startRowIndex; i < pInput->startRowIndex + pInput->numOfRows; ++i) {
|
||||
char* data = colDataGetData(pCol, i);
|
||||
SStddevRes* pInputInfo = (SStddevRes*)varDataVal(data);
|
||||
stddevTransferInfo(pInputInfo, pInfo);
|
||||
|
@ -2945,7 +2951,8 @@ int32_t firstLastFinalize(SqlFunctionCtx* pCtx, SSDataBlock* pBlock) {
|
|||
pResInfo->isNullRes = (pResInfo->numOfRes == 0) ? 1 : 0;
|
||||
|
||||
SFirstLastRes* pRes = GET_ROWCELL_INTERBUF(pResInfo);
|
||||
colDataAppend(pCol, pBlock->info.rows, pRes->buf, pResInfo->isNullRes);
|
||||
colDataAppend(pCol, pBlock->info.rows, pRes->buf, pRes->isNull||pResInfo->isNullRes);
|
||||
|
||||
// handle selectivity
|
||||
STuplePos* pTuplePos = (STuplePos*)(pRes->buf + pRes->bytes + sizeof(TSKEY));
|
||||
setSelectivityValue(pCtx, pBlock, pTuplePos, pBlock->info.rows);
|
||||
|
@ -3508,8 +3515,7 @@ void saveTupleData(SqlFunctionCtx* pCtx, int32_t rowIndex, const SSDataBlock* pS
|
|||
setBufPageDirty(pPage, true);
|
||||
releaseBufPage(pCtx->pBuf, pPage);
|
||||
#ifdef BUF_PAGE_DEBUG
|
||||
qDebug("page_saveTuple pos:%p,pageId:%d, offset:%d\n", pPos, pPos->pageId,
|
||||
pPos->offset);
|
||||
qDebug("page_saveTuple pos:%p,pageId:%d, offset:%d\n", pPos, pPos->pageId, pPos->offset);
|
||||
#endif
|
||||
}
|
||||
|
||||
|
@ -3810,7 +3816,7 @@ bool elapsedFunctionSetup(SqlFunctionCtx* pCtx, SResultRowEntryInfo* pResultInfo
|
|||
|
||||
SElapsedInfo* pInfo = GET_ROWCELL_INTERBUF(pResultInfo);
|
||||
pInfo->result = 0;
|
||||
pInfo->min = MAX_TS_KEY;
|
||||
pInfo->min = TSKEY_MAX;
|
||||
pInfo->max = 0;
|
||||
|
||||
if (pCtx->numOfParams > 1) {
|
||||
|
@ -3837,7 +3843,7 @@ int32_t elapsedFunction(SqlFunctionCtx* pCtx) {
|
|||
}
|
||||
|
||||
if (pInput->colDataAggIsSet) {
|
||||
if (pInfo->min == MAX_TS_KEY) {
|
||||
if (pInfo->min == TSKEY_MAX) {
|
||||
pInfo->min = GET_INT64_VAL(&pAgg->min);
|
||||
pInfo->max = GET_INT64_VAL(&pAgg->max);
|
||||
} else {
|
||||
|
@ -5553,6 +5559,10 @@ int32_t blockDistFinalize(SqlFunctionCtx* pCtx, SSDataBlock* pBlock) {
|
|||
|
||||
SColumnInfoData* pColInfo = taosArrayGet(pBlock->pDataBlock, 0);
|
||||
|
||||
if (pData->totalRows == 0) {
|
||||
pData->minRows = 0;
|
||||
}
|
||||
|
||||
int32_t row = 0;
|
||||
char st[256] = {0};
|
||||
double totalRawSize = pData->totalRows * pData->rowSize;
|
||||
|
@ -5564,10 +5574,14 @@ int32_t blockDistFinalize(SqlFunctionCtx* pCtx, SSDataBlock* pBlock) {
|
|||
varDataSetLen(st, len);
|
||||
colDataAppend(pColInfo, row++, st, false);
|
||||
|
||||
int64_t avgRows = 0;
|
||||
if (pData->numOfBlocks > 0) {
|
||||
avgRows = pData->totalRows / pData->numOfBlocks;
|
||||
}
|
||||
|
||||
len = sprintf(st + VARSTR_HEADER_SIZE,
|
||||
"Total_Rows=[%" PRId64 "] Inmem_Rows=[%d] MinRows=[%d] MaxRows=[%d] Average_Rows=[%" PRId64 "]",
|
||||
pData->totalRows, pData->numOfInmemRows, pData->minRows, pData->maxRows,
|
||||
pData->totalRows / pData->numOfBlocks);
|
||||
pData->totalRows, pData->numOfInmemRows, pData->minRows, pData->maxRows, avgRows);
|
||||
|
||||
varDataSetLen(st, len);
|
||||
colDataAppend(pColInfo, row++, st, false);
|
||||
|
@ -5984,28 +5998,31 @@ int32_t lastrowFunction(SqlFunctionCtx* pCtx) {
|
|||
SInputColumnInfoData* pInput = &pCtx->input;
|
||||
SColumnInfoData* pInputCol = pInput->pData[0];
|
||||
|
||||
int32_t type = pInputCol->info.type;
|
||||
int32_t type = pInputCol->info.type;
|
||||
int32_t bytes = pInputCol->info.bytes;
|
||||
|
||||
pInfo->bytes = bytes;
|
||||
|
||||
// last_row function does not ignore the null value
|
||||
for (int32_t i = pInput->numOfRows + pInput->startRowIndex - 1; i >= pInput->startRowIndex; --i) {
|
||||
if (pInputCol->hasNull && colDataIsNull_s(pInputCol, i)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
numOfElems++;
|
||||
|
||||
char* data = colDataGetData(pInputCol, i);
|
||||
TSKEY cts = getRowPTs(pInput->pPTS, i);
|
||||
if (pResInfo->numOfRes == 0 || *(TSKEY*)(pInfo->buf + bytes) < cts) {
|
||||
if (IS_VAR_DATA_TYPE(type)) {
|
||||
bytes = varDataTLen(data);
|
||||
pInfo->bytes = bytes;
|
||||
if (pResInfo->numOfRes == 0 || pInfo->ts < cts) {
|
||||
|
||||
if (colDataIsNull_s(pInputCol, i)) {
|
||||
pInfo->isNull = true;
|
||||
} else {
|
||||
if (IS_VAR_DATA_TYPE(type)) {
|
||||
bytes = varDataTLen(data);
|
||||
pInfo->bytes = bytes;
|
||||
}
|
||||
|
||||
memcpy(pInfo->buf, data, bytes);
|
||||
}
|
||||
|
||||
memcpy(pInfo->buf, data, bytes);
|
||||
*(TSKEY*)(pInfo->buf + bytes) = cts;
|
||||
|
||||
pInfo->ts = cts;
|
||||
pInfo->hasResult = true;
|
||||
pResInfo->numOfRes = 1;
|
||||
|
||||
|
|
|
@ -183,6 +183,8 @@ bool fmIsSystemInfoFunc(int32_t funcId) { return isSpecificClassifyFunc(funcId,
|
|||
|
||||
bool fmIsImplicitTsFunc(int32_t funcId) { return isSpecificClassifyFunc(funcId, FUNC_MGT_IMPLICIT_TS_FUNC); }
|
||||
|
||||
bool fmIsClientPseudoColumnFunc(int32_t funcId) { return isSpecificClassifyFunc(funcId, FUNC_MGT_CLIENT_PC_FUNC); }
|
||||
|
||||
bool fmIsInterpFunc(int32_t funcId) {
|
||||
if (funcId < 0 || funcId >= funcMgtBuiltinsNum) {
|
||||
return false;
|
||||
|
@ -227,8 +229,8 @@ bool fmIsInvertible(int32_t funcId) {
|
|||
case FUNCTION_TYPE_SUM:
|
||||
case FUNCTION_TYPE_STDDEV:
|
||||
case FUNCTION_TYPE_AVG:
|
||||
case FUNCTION_TYPE_WSTARTTS:
|
||||
case FUNCTION_TYPE_WENDTS:
|
||||
case FUNCTION_TYPE_WSTART:
|
||||
case FUNCTION_TYPE_WEND:
|
||||
case FUNCTION_TYPE_WDURATION:
|
||||
res = true;
|
||||
break;
|
||||
|
|
|
@ -127,6 +127,7 @@ static int32_t valueNodeCopy(const SValueNode* pSrc, SValueNode* pDst) {
|
|||
COPY_SCALAR_FIELD(isDuration);
|
||||
COPY_SCALAR_FIELD(translate);
|
||||
COPY_SCALAR_FIELD(notReserved);
|
||||
COPY_SCALAR_FIELD(isNull);
|
||||
COPY_SCALAR_FIELD(placeholderNo);
|
||||
COPY_SCALAR_FIELD(typeData);
|
||||
COPY_SCALAR_FIELD(unit);
|
||||
|
|
|
@ -225,6 +225,8 @@ const char* nodesNodeName(ENodeType type) {
|
|||
return "PhysiBlockDistScan";
|
||||
case QUERY_NODE_PHYSICAL_PLAN_LAST_ROW_SCAN:
|
||||
return "PhysiLastRowScan";
|
||||
case QUERY_NODE_PHYSICAL_PLAN_TABLE_MERGE_SCAN:
|
||||
return "PhysiTableMergeScan";
|
||||
case QUERY_NODE_PHYSICAL_PLAN_PROJECT:
|
||||
return "PhysiProject";
|
||||
case QUERY_NODE_PHYSICAL_PLAN_MERGE_JOIN:
|
||||
|
@ -2712,6 +2714,7 @@ static const char* jkValueLiteral = "Literal";
|
|||
static const char* jkValueDuration = "Duration";
|
||||
static const char* jkValueTranslate = "Translate";
|
||||
static const char* jkValueNotReserved = "NotReserved";
|
||||
static const char* jkValueIsNull = "IsNull";
|
||||
static const char* jkValueDatum = "Datum";
|
||||
|
||||
static int32_t datumToJson(const void* pObj, SJson* pJson) {
|
||||
|
@ -2798,6 +2801,9 @@ static int32_t valueNodeToJson(const void* pObj, SJson* pJson) {
|
|||
if (TSDB_CODE_SUCCESS == code) {
|
||||
code = tjsonAddBoolToObject(pJson, jkValueNotReserved, pNode->notReserved);
|
||||
}
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
code = tjsonAddBoolToObject(pJson, jkValueIsNull, pNode->isNull);
|
||||
}
|
||||
if (TSDB_CODE_SUCCESS == code && pNode->translate) {
|
||||
code = datumToJson(pNode, pJson);
|
||||
}
|
||||
|
@ -2945,6 +2951,9 @@ static int32_t jsonToValueNode(const SJson* pJson, void* pObj) {
|
|||
if (TSDB_CODE_SUCCESS == code) {
|
||||
code = tjsonGetBoolValue(pJson, jkValueNotReserved, &pNode->notReserved);
|
||||
}
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
code = tjsonGetBoolValue(pJson, jkValueIsNull, &pNode->isNull);
|
||||
}
|
||||
if (TSDB_CODE_SUCCESS == code && pNode->translate) {
|
||||
code = jsonToDatum(pJson, pNode);
|
||||
}
|
||||
|
|
|
@ -956,7 +956,6 @@ void nodesDestroyNode(SNode* pNode) {
|
|||
}
|
||||
case QUERY_NODE_PHYSICAL_SUBPLAN: {
|
||||
SSubplan* pSubplan = (SSubplan*)pNode;
|
||||
// nodesDestroyList(pSubplan->pChildren);
|
||||
nodesClearList(pSubplan->pChildren);
|
||||
nodesDestroyNode((SNode*)pSubplan->pNode);
|
||||
nodesDestroyNode((SNode*)pSubplan->pDataSink);
|
||||
|
@ -965,25 +964,9 @@ void nodesDestroyNode(SNode* pNode) {
|
|||
nodesClearList(pSubplan->pParents);
|
||||
break;
|
||||
}
|
||||
case QUERY_NODE_PHYSICAL_PLAN: {
|
||||
SQueryPlan* pPlan = (SQueryPlan*)pNode;
|
||||
if (NULL != pPlan->pSubplans) {
|
||||
// only need to destroy the top-level subplans, because they will recurse to all the subplans below
|
||||
bool first = true;
|
||||
SNode* pElement = NULL;
|
||||
FOREACH(pElement, pPlan->pSubplans) {
|
||||
if (first) {
|
||||
// first = false;
|
||||
nodesDestroyNode(pElement);
|
||||
} else {
|
||||
nodesClearList(((SNodeListNode*)pElement)->pNodeList);
|
||||
taosMemoryFreeClear(pElement);
|
||||
}
|
||||
}
|
||||
nodesClearList(pPlan->pSubplans);
|
||||
}
|
||||
case QUERY_NODE_PHYSICAL_PLAN:
|
||||
nodesDestroyList(((SQueryPlan*)pNode)->pSubplans);
|
||||
break;
|
||||
}
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
@ -1709,6 +1692,11 @@ int32_t nodesGetOutputNumFromSlotList(SNodeList* pSlots) {
|
|||
}
|
||||
|
||||
void nodesValueNodeToVariant(const SValueNode* pNode, SVariant* pVal) {
|
||||
if (pNode->isNull) {
|
||||
pVal->nType = TSDB_DATA_TYPE_NULL;
|
||||
pVal->nLen = tDataTypes[TSDB_DATA_TYPE_NULL].bytes;
|
||||
return;
|
||||
}
|
||||
pVal->nType = pNode->node.resType.type;
|
||||
pVal->nLen = pNode->node.resType.bytes;
|
||||
switch (pNode->node.resType.type) {
|
||||
|
@ -1789,7 +1777,7 @@ static EDealRes classifyConditionImpl(SNode* pNode, void* pContext) {
|
|||
SClassifyConditionCxt* pCxt = (SClassifyConditionCxt*)pContext;
|
||||
if (QUERY_NODE_COLUMN == nodeType(pNode)) {
|
||||
SColumnNode* pCol = (SColumnNode*)pNode;
|
||||
if (PRIMARYKEY_TIMESTAMP_COL_ID == pCol->colId) {
|
||||
if (PRIMARYKEY_TIMESTAMP_COL_ID == pCol->colId && TSDB_SYSTEM_TABLE != pCol->tableType) {
|
||||
pCxt->hasPrimaryKey = true;
|
||||
} else if (pCol->hasIndex) {
|
||||
pCxt->hasTagIndexCol = true;
|
||||
|
|
|
@ -520,7 +520,9 @@ cmd ::= DELETE FROM full_table_name(A) where_clause_opt(B).
|
|||
cmd ::= query_expression(A). { pCxt->pRootNode = A; }
|
||||
|
||||
/************************************************ insert **************************************************************/
|
||||
cmd ::= INSERT INTO full_table_name(A) specific_cols_opt(B) query_expression(C). { pCxt->pRootNode = createInsertStmt(pCxt, A, B, C); }
|
||||
cmd ::= INSERT INTO full_table_name(A)
|
||||
NK_LP col_name_list(B) NK_RP query_expression(C). { pCxt->pRootNode = createInsertStmt(pCxt, A, B, C); }
|
||||
cmd ::= INSERT INTO full_table_name(A) query_expression(B). { pCxt->pRootNode = createInsertStmt(pCxt, A, NULL, B); }
|
||||
|
||||
/************************************************ literal *************************************************************/
|
||||
literal(A) ::= NK_INTEGER(B). { A = createRawExprNode(pCxt, &B, createValueNode(pCxt, TSDB_DATA_TYPE_BIGINT, &B)); }
|
||||
|
@ -675,10 +677,11 @@ column_reference(A) ::= table_name(B) NK_DOT column_name(C).
|
|||
pseudo_column(A) ::= ROWTS(B). { A = createRawExprNode(pCxt, &B, createFunctionNode(pCxt, &B, NULL)); }
|
||||
pseudo_column(A) ::= TBNAME(B). { A = createRawExprNode(pCxt, &B, createFunctionNode(pCxt, &B, NULL)); }
|
||||
pseudo_column(A) ::= table_name(B) NK_DOT TBNAME(C). { A = createRawExprNodeExt(pCxt, &B, &C, createFunctionNode(pCxt, &C, createNodeList(pCxt, createValueNode(pCxt, TSDB_DATA_TYPE_BINARY, &B)))); }
|
||||
pseudo_column(A) ::= QSTARTTS(B). { A = createRawExprNode(pCxt, &B, createFunctionNode(pCxt, &B, NULL)); }
|
||||
pseudo_column(A) ::= QENDTS(B). { A = createRawExprNode(pCxt, &B, createFunctionNode(pCxt, &B, NULL)); }
|
||||
pseudo_column(A) ::= WSTARTTS(B). { A = createRawExprNode(pCxt, &B, createFunctionNode(pCxt, &B, NULL)); }
|
||||
pseudo_column(A) ::= WENDTS(B). { A = createRawExprNode(pCxt, &B, createFunctionNode(pCxt, &B, NULL)); }
|
||||
pseudo_column(A) ::= QSTART(B). { A = createRawExprNode(pCxt, &B, createFunctionNode(pCxt, &B, NULL)); }
|
||||
pseudo_column(A) ::= QEND(B). { A = createRawExprNode(pCxt, &B, createFunctionNode(pCxt, &B, NULL)); }
|
||||
pseudo_column(A) ::= QDURATION(B). { A = createRawExprNode(pCxt, &B, createFunctionNode(pCxt, &B, NULL)); }
|
||||
pseudo_column(A) ::= WSTART(B). { A = createRawExprNode(pCxt, &B, createFunctionNode(pCxt, &B, NULL)); }
|
||||
pseudo_column(A) ::= WEND(B). { A = createRawExprNode(pCxt, &B, createFunctionNode(pCxt, &B, NULL)); }
|
||||
pseudo_column(A) ::= WDURATION(B). { A = createRawExprNode(pCxt, &B, createFunctionNode(pCxt, &B, NULL)); }
|
||||
|
||||
function_expression(A) ::= function_name(B) NK_LP expression_list(C) NK_RP(D). { A = createRawExprNodeExt(pCxt, &B, &D, createFunctionNode(pCxt, &B, C)); }
|
||||
|
|
|
@ -598,7 +598,7 @@ SNode* createFillNode(SAstCreateContext* pCxt, EFillMode mode, SNode* pValues) {
|
|||
nodesDestroyNode((SNode*)fill);
|
||||
CHECK_OUT_OF_MEM(fill->pWStartTs);
|
||||
}
|
||||
strcpy(((SFunctionNode*)fill->pWStartTs)->functionName, "_wstartts");
|
||||
strcpy(((SFunctionNode*)fill->pWStartTs)->functionName, "_wstart");
|
||||
return (SNode*)fill;
|
||||
}
|
||||
|
||||
|
@ -740,6 +740,7 @@ SNode* createSelectStmt(SAstCreateContext* pCxt, bool isDistinct, SNodeList* pPr
|
|||
select->pFromTable = pTable;
|
||||
sprintf(select->stmtName, "%p", select);
|
||||
select->isTimeLineResult = true;
|
||||
select->timeRange = TSWINDOW_INITIALIZER;
|
||||
return (SNode*)select;
|
||||
}
|
||||
|
||||
|
|
|
@ -166,7 +166,7 @@ static int32_t calcConstStmtCondition(SCalcConstContext* pCxt, SNode** pCond, bo
|
|||
return code;
|
||||
}
|
||||
|
||||
static int32_t calcConstProject(SNode* pProject, SNode** pNew) {
|
||||
static int32_t calcConstProject(SNode* pProject, bool dual, SNode** pNew) {
|
||||
SArray* pAssociation = NULL;
|
||||
if (NULL != ((SExprNode*)pProject)->pAssociation) {
|
||||
pAssociation = taosArrayDup(((SExprNode*)pProject)->pAssociation);
|
||||
|
@ -177,7 +177,12 @@ static int32_t calcConstProject(SNode* pProject, SNode** pNew) {
|
|||
|
||||
char aliasName[TSDB_COL_NAME_LEN] = {0};
|
||||
strcpy(aliasName, ((SExprNode*)pProject)->aliasName);
|
||||
int32_t code = scalarCalculateConstants(pProject, pNew);
|
||||
int32_t code = TSDB_CODE_SUCCESS;
|
||||
if (dual) {
|
||||
code = scalarCalculateConstantsFromDual(pProject, pNew);
|
||||
} else {
|
||||
code = scalarCalculateConstants(pProject, pNew);
|
||||
}
|
||||
if (TSDB_CODE_SUCCESS == code && QUERY_NODE_VALUE == nodeType(*pNew) && NULL != pAssociation) {
|
||||
strcpy(((SExprNode*)*pNew)->aliasName, aliasName);
|
||||
int32_t size = taosArrayGetSize(pAssociation);
|
||||
|
@ -218,12 +223,12 @@ static SNode* createConstantValue() {
|
|||
static int32_t calcConstProjections(SCalcConstContext* pCxt, SSelectStmt* pSelect, bool subquery) {
|
||||
SNode* pProj = NULL;
|
||||
WHERE_EACH(pProj, pSelect->pProjectionList) {
|
||||
if (subquery && isUselessCol((SExprNode*)pProj)) {
|
||||
if (subquery && !pSelect->isDistinct && isUselessCol((SExprNode*)pProj)) {
|
||||
ERASE_NODE(pSelect->pProjectionList);
|
||||
continue;
|
||||
}
|
||||
SNode* pNew = NULL;
|
||||
int32_t code = calcConstProject(pProj, &pNew);
|
||||
int32_t code = calcConstProject(pProj, (NULL == pSelect->pFromTable), &pNew);
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
REPLACE_NODE(pNew);
|
||||
} else {
|
||||
|
|
|
@ -240,12 +240,13 @@ static SKeyword keywordTable[] = {
|
|||
{"WITH", TK_WITH},
|
||||
{"WRITE", TK_WRITE},
|
||||
{"_C0", TK_ROWTS},
|
||||
{"_QENDTS", TK_QENDTS},
|
||||
{"_QSTARTTS", TK_QSTARTTS},
|
||||
{"_QDURATION", TK_QDURATION},
|
||||
{"_QEND", TK_QEND},
|
||||
{"_QSTART", TK_QSTART},
|
||||
{"_ROWTS", TK_ROWTS},
|
||||
{"_WDURATION", TK_WDURATION},
|
||||
{"_WENDTS", TK_WENDTS},
|
||||
{"_WSTARTTS", TK_WSTARTTS},
|
||||
{"_WEND", TK_WEND},
|
||||
{"_WSTART", TK_WSTART},
|
||||
// {"ID", TK_ID},
|
||||
// {"STRING", TK_STRING},
|
||||
// {"EQ", TK_EQ},
|
||||
|
|
|
@ -496,7 +496,7 @@ static bool isPrimaryKeyImpl(SNode* pExpr) {
|
|||
SFunctionNode* pFunc = (SFunctionNode*)pExpr;
|
||||
if (FUNCTION_TYPE_SELECT_VALUE == pFunc->funcType) {
|
||||
return isPrimaryKeyImpl(nodesListGetNode(pFunc->pParameterList, 0));
|
||||
} else if (FUNCTION_TYPE_WSTARTTS == pFunc->funcType || FUNCTION_TYPE_WENDTS == pFunc->funcType) {
|
||||
} else if (FUNCTION_TYPE_WSTART == pFunc->funcType || FUNCTION_TYPE_WEND == pFunc->funcType) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
@ -916,8 +916,6 @@ static EDealRes translateValueImpl(STranslateContext* pCxt, SValueNode* pVal, SD
|
|||
}
|
||||
|
||||
if (TSDB_DATA_TYPE_NULL == pVal->node.resType.type) {
|
||||
// TODO
|
||||
// pVal->node.resType = targetDt;
|
||||
pVal->translate = true;
|
||||
pVal->isNull = true;
|
||||
return DEAL_RES_CONTINUE;
|
||||
|
@ -932,6 +930,7 @@ static EDealRes translateValueImpl(STranslateContext* pCxt, SValueNode* pVal, SD
|
|||
res = translateNormalValue(pCxt, pVal, targetDt, strict);
|
||||
}
|
||||
pVal->node.resType = targetDt;
|
||||
pVal->node.resType.scale = pVal->unit;
|
||||
pVal->translate = true;
|
||||
return res;
|
||||
}
|
||||
|
@ -1198,7 +1197,7 @@ static void setFuncClassification(SNode* pCurrStmt, SFunctionNode* pFunc) {
|
|||
}
|
||||
}
|
||||
|
||||
static int32_t rewriteSystemInfoFuncImpl(STranslateContext* pCxt, char* pLiteral, SNode** pNode) {
|
||||
static int32_t rewriteFuncToValue(STranslateContext* pCxt, char* pLiteral, SNode** pNode) {
|
||||
SValueNode* pVal = (SValueNode*)nodesMakeNode(QUERY_NODE_VALUE);
|
||||
if (NULL == pVal) {
|
||||
return TSDB_CODE_OUT_OF_MEMORY;
|
||||
|
@ -1229,7 +1228,7 @@ static int32_t rewriteDatabaseFunc(STranslateContext* pCxt, SNode** pNode) {
|
|||
return TSDB_CODE_OUT_OF_MEMORY;
|
||||
}
|
||||
}
|
||||
return rewriteSystemInfoFuncImpl(pCxt, pCurrDb, pNode);
|
||||
return rewriteFuncToValue(pCxt, pCurrDb, pNode);
|
||||
}
|
||||
|
||||
static int32_t rewriteClentVersionFunc(STranslateContext* pCxt, SNode** pNode) {
|
||||
|
@ -1237,7 +1236,7 @@ static int32_t rewriteClentVersionFunc(STranslateContext* pCxt, SNode** pNode) {
|
|||
if (NULL == pVer) {
|
||||
return TSDB_CODE_OUT_OF_MEMORY;
|
||||
}
|
||||
return rewriteSystemInfoFuncImpl(pCxt, pVer, pNode);
|
||||
return rewriteFuncToValue(pCxt, pVer, pNode);
|
||||
}
|
||||
|
||||
static int32_t rewriteServerVersionFunc(STranslateContext* pCxt, SNode** pNode) {
|
||||
|
@ -1245,7 +1244,7 @@ static int32_t rewriteServerVersionFunc(STranslateContext* pCxt, SNode** pNode)
|
|||
if (NULL == pVer) {
|
||||
return TSDB_CODE_OUT_OF_MEMORY;
|
||||
}
|
||||
return rewriteSystemInfoFuncImpl(pCxt, pVer, pNode);
|
||||
return rewriteFuncToValue(pCxt, pVer, pNode);
|
||||
}
|
||||
|
||||
static int32_t rewriteServerStatusFunc(STranslateContext* pCxt, SNode** pNode) {
|
||||
|
@ -1253,7 +1252,7 @@ static int32_t rewriteServerStatusFunc(STranslateContext* pCxt, SNode** pNode) {
|
|||
return TSDB_CODE_RPC_NETWORK_UNAVAIL;
|
||||
}
|
||||
char* pStatus = taosMemoryStrDup((void*)"1");
|
||||
return rewriteSystemInfoFuncImpl(pCxt, pStatus, pNode);
|
||||
return rewriteFuncToValue(pCxt, pStatus, pNode);
|
||||
}
|
||||
|
||||
static int32_t rewriteUserFunc(STranslateContext* pCxt, SNode** pNode) {
|
||||
|
@ -1264,7 +1263,7 @@ static int32_t rewriteUserFunc(STranslateContext* pCxt, SNode** pNode) {
|
|||
if (NULL == pUserConn) {
|
||||
return TSDB_CODE_OUT_OF_MEMORY;
|
||||
}
|
||||
return rewriteSystemInfoFuncImpl(pCxt, pUserConn, pNode);
|
||||
return rewriteFuncToValue(pCxt, pUserConn, pNode);
|
||||
}
|
||||
|
||||
static int32_t rewriteSystemInfoFunc(STranslateContext* pCxt, SNode** pNode) {
|
||||
|
@ -1318,10 +1317,60 @@ static int32_t translateNoramlFunction(STranslateContext* pCxt, SFunctionNode* p
|
|||
return code;
|
||||
}
|
||||
|
||||
static int32_t rewriteQueryTimeFunc(STranslateContext* pCxt, int64_t val, SNode** pNode) {
|
||||
if (INT64_MIN == val || INT64_MAX == val) {
|
||||
return rewriteFuncToValue(pCxt, NULL, pNode);
|
||||
}
|
||||
|
||||
char* pStr = taosMemoryCalloc(1, 20);
|
||||
if (NULL == pStr) {
|
||||
return TSDB_CODE_OUT_OF_MEMORY;
|
||||
}
|
||||
snprintf(pStr, 20, "%" PRId64 "", val);
|
||||
return rewriteFuncToValue(pCxt, pStr, pNode);
|
||||
}
|
||||
|
||||
static int32_t rewriteQstartFunc(STranslateContext* pCxt, SNode** pNode) {
|
||||
return rewriteQueryTimeFunc(pCxt, ((SSelectStmt*)pCxt->pCurrStmt)->timeRange.skey, pNode);
|
||||
}
|
||||
|
||||
static int32_t rewriteQendFunc(STranslateContext* pCxt, SNode** pNode) {
|
||||
return rewriteQueryTimeFunc(pCxt, ((SSelectStmt*)pCxt->pCurrStmt)->timeRange.ekey, pNode);
|
||||
}
|
||||
|
||||
static int32_t rewriteQdurationFunc(STranslateContext* pCxt, SNode** pNode) {
|
||||
STimeWindow range = ((SSelectStmt*)pCxt->pCurrStmt)->timeRange;
|
||||
if (INT64_MIN == range.skey || INT64_MAX == range.ekey) {
|
||||
return rewriteQueryTimeFunc(pCxt, INT64_MIN, pNode);
|
||||
}
|
||||
return rewriteQueryTimeFunc(pCxt, range.ekey - range.skey + 1, pNode);
|
||||
}
|
||||
|
||||
static int32_t rewriteClientPseudoColumnFunc(STranslateContext* pCxt, SNode** pNode) {
|
||||
if (NULL == pCxt->pCurrStmt || QUERY_NODE_SELECT_STMT != nodeType(pCxt->pCurrStmt) ||
|
||||
pCxt->currClause <= SQL_CLAUSE_WHERE) {
|
||||
return generateSyntaxErrMsgExt(&pCxt->msgBuf, TSDB_CODE_PAR_NOT_ALLOWED_FUNC, "Illegal pseudo column");
|
||||
}
|
||||
switch (((SFunctionNode*)*pNode)->funcType) {
|
||||
case FUNCTION_TYPE_QSTART:
|
||||
return rewriteQstartFunc(pCxt, pNode);
|
||||
case FUNCTION_TYPE_QEND:
|
||||
return rewriteQendFunc(pCxt, pNode);
|
||||
case FUNCTION_TYPE_QDURATION:
|
||||
return rewriteQdurationFunc(pCxt, pNode);
|
||||
default:
|
||||
break;
|
||||
}
|
||||
return TSDB_CODE_PAR_INTERNAL_ERROR;
|
||||
}
|
||||
|
||||
static int32_t translateFunctionImpl(STranslateContext* pCxt, SFunctionNode** pFunc) {
|
||||
if (fmIsSystemInfoFunc((*pFunc)->funcId)) {
|
||||
return rewriteSystemInfoFunc(pCxt, (SNode**)pFunc);
|
||||
}
|
||||
if (fmIsClientPseudoColumnFunc((*pFunc)->funcId)) {
|
||||
return rewriteClientPseudoColumnFunc(pCxt, (SNode**)pFunc);
|
||||
}
|
||||
return translateNoramlFunction(pCxt, *pFunc);
|
||||
}
|
||||
|
||||
|
@ -2078,7 +2127,7 @@ static int32_t getTimeRange(SNode** pPrimaryKeyCond, STimeWindow* pTimeRange, bo
|
|||
return code;
|
||||
}
|
||||
|
||||
static int32_t getFillTimeRange(STranslateContext* pCxt, SNode* pWhere, STimeWindow* pTimeRange) {
|
||||
static int32_t getQueryTimeRange(STranslateContext* pCxt, SNode* pWhere, STimeWindow* pTimeRange) {
|
||||
if (NULL == pWhere) {
|
||||
*pTimeRange = TSWINDOW_INITIALIZER;
|
||||
return TSDB_CODE_SUCCESS;
|
||||
|
@ -2139,16 +2188,13 @@ static int32_t checkFill(STranslateContext* pCxt, SFillNode* pFill, SValueNode*
|
|||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
static int32_t translateFill(STranslateContext* pCxt, SNode* pWhere, SIntervalWindowNode* pInterval) {
|
||||
static int32_t translateFill(STranslateContext* pCxt, SSelectStmt* pSelect, SIntervalWindowNode* pInterval) {
|
||||
if (NULL == pInterval->pFill) {
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
int32_t code = getFillTimeRange(pCxt, pWhere, &(((SFillNode*)pInterval->pFill)->timeRange));
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
code = checkFill(pCxt, (SFillNode*)pInterval->pFill, (SValueNode*)pInterval->pInterval);
|
||||
}
|
||||
return code;
|
||||
((SFillNode*)pInterval->pFill)->timeRange = pSelect->timeRange;
|
||||
return checkFill(pCxt, (SFillNode*)pInterval->pFill, (SValueNode*)pInterval->pInterval);
|
||||
}
|
||||
|
||||
static int64_t getMonthsFromTimeVal(int64_t val, int32_t fromPrecision, char unit) {
|
||||
|
@ -2235,7 +2281,7 @@ static int32_t checkIntervalWindow(STranslateContext* pCxt, SIntervalWindowNode*
|
|||
static int32_t translateIntervalWindow(STranslateContext* pCxt, SSelectStmt* pSelect, SIntervalWindowNode* pInterval) {
|
||||
int32_t code = checkIntervalWindow(pCxt, pInterval);
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
code = translateFill(pCxt, pSelect->pWhere, pInterval);
|
||||
code = translateFill(pCxt, pSelect, pInterval);
|
||||
}
|
||||
return code;
|
||||
}
|
||||
|
@ -2330,7 +2376,7 @@ static int32_t translateInterpFill(STranslateContext* pCxt, SSelectStmt* pSelect
|
|||
code = translateExpr(pCxt, &pSelect->pFill);
|
||||
}
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
code = getFillTimeRange(pCxt, pSelect->pRange, &(((SFillNode*)pSelect->pFill)->timeRange));
|
||||
code = getQueryTimeRange(pCxt, pSelect->pRange, &(((SFillNode*)pSelect->pFill)->timeRange));
|
||||
}
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
code = checkFill(pCxt, (SFillNode*)pSelect->pFill, (SValueNode*)pSelect->pEvery);
|
||||
|
@ -2362,9 +2408,13 @@ static int32_t translatePartitionBy(STranslateContext* pCxt, SNodeList* pPartiti
|
|||
return translateExprList(pCxt, pPartitionByList);
|
||||
}
|
||||
|
||||
static int32_t translateWhere(STranslateContext* pCxt, SNode** pWhere) {
|
||||
static int32_t translateWhere(STranslateContext* pCxt, SSelectStmt* pSelect) {
|
||||
pCxt->currClause = SQL_CLAUSE_WHERE;
|
||||
return translateExpr(pCxt, pWhere);
|
||||
int32_t code = translateExpr(pCxt, &pSelect->pWhere);
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
code = getQueryTimeRange(pCxt, pSelect->pWhere, &pSelect->timeRange);
|
||||
}
|
||||
return code;
|
||||
}
|
||||
|
||||
static int32_t translateFrom(STranslateContext* pCxt, SNode* pTable) {
|
||||
|
@ -2495,7 +2545,7 @@ static int32_t translateSelectFrom(STranslateContext* pCxt, SSelectStmt* pSelect
|
|||
int32_t code = translateFrom(pCxt, pSelect->pFromTable);
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
pSelect->precision = ((STableNode*)pSelect->pFromTable)->precision;
|
||||
code = translateWhere(pCxt, &pSelect->pWhere);
|
||||
code = translateWhere(pCxt, pSelect);
|
||||
}
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
code = translatePartitionBy(pCxt, pSelect->pPartitionByList);
|
||||
|
@ -2681,7 +2731,8 @@ static int32_t partitionDeleteWhere(STranslateContext* pCxt, SDeleteStmt* pDelet
|
|||
}
|
||||
|
||||
static int32_t translateDeleteWhere(STranslateContext* pCxt, SDeleteStmt* pDelete) {
|
||||
int32_t code = translateWhere(pCxt, &pDelete->pWhere);
|
||||
pCxt->currClause = SQL_CLAUSE_WHERE;
|
||||
int32_t code = translateExpr(pCxt, &pDelete->pWhere);
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
code = partitionDeleteWhere(pCxt, pDelete);
|
||||
}
|
||||
|
@ -3508,7 +3559,7 @@ static int32_t buildSampleAst(STranslateContext* pCxt, SSampleAstInfo* pInfo, ch
|
|||
nodesDestroyNode((SNode*)pSelect);
|
||||
return TSDB_CODE_OUT_OF_MEMORY;
|
||||
}
|
||||
strcpy(pFunc->functionName, "_wstartts");
|
||||
strcpy(pFunc->functionName, "_wstart");
|
||||
nodesListPushFront(pSelect->pProjectionList, (SNode*)pFunc);
|
||||
SNode* pProject = NULL;
|
||||
FOREACH(pProject, pSelect->pProjectionList) { sprintf(((SExprNode*)pProject)->aliasName, "#%p", pProject); }
|
||||
|
@ -4334,14 +4385,14 @@ static int32_t addWstartTsToCreateStreamQuery(SNode* pStmt) {
|
|||
SSelectStmt* pSelect = (SSelectStmt*)pStmt;
|
||||
SNode* pProj = nodesListGetNode(pSelect->pProjectionList, 0);
|
||||
if (NULL == pSelect->pWindow ||
|
||||
(QUERY_NODE_FUNCTION == nodeType(pProj) && 0 == strcmp("_wstartts", ((SFunctionNode*)pProj)->functionName))) {
|
||||
(QUERY_NODE_FUNCTION == nodeType(pProj) && 0 == strcmp("_wstart", ((SFunctionNode*)pProj)->functionName))) {
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
SFunctionNode* pFunc = (SFunctionNode*)nodesMakeNode(QUERY_NODE_FUNCTION);
|
||||
if (NULL == pFunc) {
|
||||
return TSDB_CODE_OUT_OF_MEMORY;
|
||||
}
|
||||
strcpy(pFunc->functionName, "_wstartts");
|
||||
strcpy(pFunc->functionName, "_wstart");
|
||||
strcpy(pFunc->node.aliasName, pFunc->functionName);
|
||||
int32_t code = nodesListPushFront(pSelect->pProjectionList, (SNode*)pFunc);
|
||||
if (TSDB_CODE_SUCCESS != code) {
|
||||
|
@ -4757,8 +4808,13 @@ static int32_t extractQueryResultSchema(const SNodeList* pProjections, int32_t*
|
|||
int32_t index = 0;
|
||||
FOREACH(pNode, pProjections) {
|
||||
SExprNode* pExpr = (SExprNode*)pNode;
|
||||
(*pSchema)[index].type = pExpr->resType.type;
|
||||
(*pSchema)[index].bytes = pExpr->resType.bytes;
|
||||
if (TSDB_DATA_TYPE_NULL == pExpr->resType.type) {
|
||||
(*pSchema)[index].type = TSDB_DATA_TYPE_VARCHAR;
|
||||
(*pSchema)[index].bytes = 0;
|
||||
} else {
|
||||
(*pSchema)[index].type = pExpr->resType.type;
|
||||
(*pSchema)[index].bytes = pExpr->resType.bytes;
|
||||
}
|
||||
(*pSchema)[index].colId = index + 1;
|
||||
if ('\0' != pExpr->userAlias[0]) {
|
||||
strcpy((*pSchema)[index].name, pExpr->userAlias);
|
||||
|
|
|
@ -187,7 +187,7 @@ static char* getSyntaxErrFormat(int32_t errCode) {
|
|||
case TSDB_CODE_PAR_FILL_NOT_ALLOWED_FUNC:
|
||||
return "%s function is not supported in fill query";
|
||||
case TSDB_CODE_PAR_INVALID_WINDOW_PC:
|
||||
return "_WSTARTTS, _WENDTS and _WDURATION can only be used in window query";
|
||||
return "_WSTART, _WEND and _WDURATION can only be used in window query";
|
||||
case TSDB_CODE_PAR_WINDOW_NOT_ALLOWED_FUNC:
|
||||
return "%s function is not supported in time window query";
|
||||
case TSDB_CODE_PAR_STREAM_NOT_ALLOWED_FUNC:
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -75,7 +75,7 @@ TEST_F(ParserSelectTest, condition) {
|
|||
TEST_F(ParserSelectTest, pseudoColumn) {
|
||||
useDb("root", "test");
|
||||
|
||||
run("SELECT _WSTARTTS, _WENDTS, COUNT(*) FROM t1 INTERVAL(10s)");
|
||||
run("SELECT _WSTART, _WEND, COUNT(*) FROM t1 INTERVAL(10s)");
|
||||
}
|
||||
|
||||
TEST_F(ParserSelectTest, pseudoColumnSemanticCheck) {
|
||||
|
@ -286,7 +286,7 @@ TEST_F(ParserSelectTest, intervalSemanticCheck) {
|
|||
run("SELECT HISTOGRAM(c1, 'log_bin', '{\"start\": -33,\"factor\": 55,\"count\": 5,\"infinity\": false}', 1) FROM t1 "
|
||||
"WHERE ts > TIMESTAMP '2022-04-01 00:00:00' and ts < TIMESTAMP '2022-04-30 23:59:59' INTERVAL(10s) FILL(NULL)",
|
||||
TSDB_CODE_PAR_FILL_NOT_ALLOWED_FUNC);
|
||||
run("SELECT _WSTARTTS, _WENDTS, _WDURATION, sum(c1) FROM t1", TSDB_CODE_PAR_INVALID_WINDOW_PC);
|
||||
run("SELECT _WSTART, _WEND, _WDURATION, sum(c1) FROM t1", TSDB_CODE_PAR_INVALID_WINDOW_PC);
|
||||
}
|
||||
|
||||
TEST_F(ParserSelectTest, interp) {
|
||||
|
@ -310,11 +310,11 @@ TEST_F(ParserSelectTest, subquery) {
|
|||
|
||||
run("SELECT SUM(a) FROM (SELECT MAX(c1) a, ts FROM st1s1 INTERVAL(1m)) INTERVAL(1n)");
|
||||
|
||||
run("SELECT SUM(a) FROM (SELECT MAX(c1) a, _wstartts FROM st1s1 INTERVAL(1m)) INTERVAL(1n)");
|
||||
run("SELECT SUM(a) FROM (SELECT MAX(c1) a, _wstart FROM st1s1 INTERVAL(1m)) INTERVAL(1n)");
|
||||
|
||||
run("SELECT SUM(a) FROM (SELECT MAX(c1) a, ts FROM st1s1 PARTITION BY TBNAME INTERVAL(1m)) INTERVAL(1n)");
|
||||
|
||||
run("SELECT SUM(a) FROM (SELECT MAX(c1) a, _wstartts FROM st1s1 PARTITION BY TBNAME INTERVAL(1m)) INTERVAL(1n)");
|
||||
run("SELECT SUM(a) FROM (SELECT MAX(c1) a, _wstart FROM st1s1 PARTITION BY TBNAME INTERVAL(1m)) INTERVAL(1n)");
|
||||
|
||||
run("SELECT _C0 FROM (SELECT _ROWTS, ts FROM st1s1)");
|
||||
|
||||
|
|
|
@ -59,7 +59,7 @@ static EDealRes doRewriteExpr(SNode** pNode, void* pContext) {
|
|||
strcpy(pCol->node.aliasName, pToBeRewrittenExpr->aliasName);
|
||||
strcpy(pCol->colName, ((SExprNode*)pExpr)->aliasName);
|
||||
if (QUERY_NODE_FUNCTION == nodeType(pExpr)) {
|
||||
if (FUNCTION_TYPE_WSTARTTS == ((SFunctionNode*)pExpr)->funcType) {
|
||||
if (FUNCTION_TYPE_WSTART == ((SFunctionNode*)pExpr)->funcType) {
|
||||
pCol->colId = PRIMARYKEY_TIMESTAMP_COL_ID;
|
||||
} else if (FUNCTION_TYPE_TBNAME == ((SFunctionNode*)pExpr)->funcType) {
|
||||
pCol->colType = COLUMN_TYPE_TBNAME;
|
||||
|
|
|
@ -124,12 +124,15 @@ static bool scanPathOptMayBeOptimized(SLogicNode* pNode) {
|
|||
QUERY_NODE_LOGIC_PLAN_PARTITION != nodeType(pNode->pParent))) {
|
||||
return false;
|
||||
}
|
||||
if (QUERY_NODE_LOGIC_PLAN_WINDOW == nodeType(pNode->pParent) ||
|
||||
if ((QUERY_NODE_LOGIC_PLAN_WINDOW == nodeType(pNode->pParent) && WINDOW_TYPE_INTERVAL == ((SWindowLogicNode*)pNode->pParent)->winType) ||
|
||||
(QUERY_NODE_LOGIC_PLAN_PARTITION == nodeType(pNode->pParent) && pNode->pParent->pParent &&
|
||||
QUERY_NODE_LOGIC_PLAN_WINDOW == nodeType(pNode->pParent->pParent))) {
|
||||
QUERY_NODE_LOGIC_PLAN_WINDOW == nodeType(pNode->pParent->pParent) && WINDOW_TYPE_INTERVAL == ((SWindowLogicNode*)pNode->pParent)->winType)) {
|
||||
return true;
|
||||
}
|
||||
return !scanPathOptHaveNormalCol(((SAggLogicNode*)pNode->pParent)->pGroupKeys);
|
||||
if (QUERY_NODE_LOGIC_PLAN_AGG == nodeType(pNode->pParent)) {
|
||||
return !scanPathOptHaveNormalCol(((SAggLogicNode*)pNode->pParent)->pGroupKeys);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
static SNodeList* scanPathOptGetAllFuncs(SLogicNode* pNode) {
|
||||
|
@ -792,15 +795,15 @@ static EDealRes rewriteAggGroupKeyCondForPushDownImpl(SNode** pNode, void* pCont
|
|||
if (0 == strcmp(((SExprNode*)pGroup)->aliasName, ((SColumnNode*)(*pNode))->colName)) {
|
||||
SNode* pExpr = nodesCloneNode(pGroup);
|
||||
if (pExpr == NULL) {
|
||||
pCxt->errCode = terrno;
|
||||
pCxt->errCode = TSDB_CODE_OUT_OF_MEMORY;
|
||||
return DEAL_RES_ERROR;
|
||||
}
|
||||
nodesDestroyNode(*pNode);
|
||||
*pNode = pExpr;
|
||||
return DEAL_RES_IGNORE_CHILD;
|
||||
}
|
||||
}
|
||||
}
|
||||
return DEAL_RES_IGNORE_CHILD;
|
||||
}
|
||||
return DEAL_RES_CONTINUE;
|
||||
}
|
||||
|
@ -861,16 +864,16 @@ static EDealRes rewriteProjectCondForPushDownImpl(SNode** ppNode, void* pContext
|
|||
if (0 == strcmp(((SExprNode*)pProjection)->aliasName, ((SColumnNode*)(*ppNode))->colName)) {
|
||||
SNode* pExpr = nodesCloneNode(pProjection);
|
||||
if (pExpr == NULL) {
|
||||
pCxt->errCode = terrno;
|
||||
pCxt->errCode = TSDB_CODE_OUT_OF_MEMORY;
|
||||
return DEAL_RES_ERROR;
|
||||
}
|
||||
nodesDestroyNode(*ppNode);
|
||||
*ppNode = pExpr;
|
||||
return DEAL_RES_IGNORE_CHILD;
|
||||
} // end if expr alias name equal column name
|
||||
} // end for each project
|
||||
} // end if target node equals cond column node
|
||||
} // end for each targets
|
||||
return DEAL_RES_IGNORE_CHILD;
|
||||
}
|
||||
return DEAL_RES_CONTINUE;
|
||||
}
|
||||
|
@ -1208,7 +1211,7 @@ static int32_t smaIndexOptCreateSmaCols(SNodeList* pFuncs, uint64_t tableId, SNo
|
|||
int32_t smaFuncIndex = -1;
|
||||
*pWStrartIndex = -1;
|
||||
FOREACH(pFunc, pFuncs) {
|
||||
if (FUNCTION_TYPE_WSTARTTS == ((SFunctionNode*)pFunc)->funcType) {
|
||||
if (FUNCTION_TYPE_WSTART == ((SFunctionNode*)pFunc)->funcType) {
|
||||
*pWStrartIndex = index;
|
||||
}
|
||||
smaFuncIndex = smaIndexOptFindSmaFunc(pFunc, pSmaFuncs);
|
||||
|
@ -1252,7 +1255,7 @@ static SNode* smaIndexOptCreateWStartTs() {
|
|||
if (NULL == pWStart) {
|
||||
return NULL;
|
||||
}
|
||||
strcpy(pWStart->functionName, "_wstartts");
|
||||
strcpy(pWStart->functionName, "_wstart");
|
||||
snprintf(pWStart->node.aliasName, sizeof(pWStart->node.aliasName), "%s.%p", pWStart->functionName, pWStart);
|
||||
if (TSDB_CODE_SUCCESS != fmGetFuncInfo(pWStart, NULL, 0)) {
|
||||
nodesDestroyNode((SNode*)pWStart);
|
||||
|
@ -2054,11 +2057,11 @@ static EDealRes mergeProjectionsExpr(SNode** pNode, void* pContext) {
|
|||
((SExprNode*)*pNode)->aliasName);
|
||||
nodesDestroyNode(*pNode);
|
||||
*pNode = pExpr;
|
||||
return DEAL_RES_IGNORE_CHILD;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return DEAL_RES_IGNORE_CHILD;
|
||||
}
|
||||
return DEAL_RES_CONTINUE;
|
||||
}
|
||||
|
@ -2100,11 +2103,12 @@ static bool tagScanMayBeOptimized(SLogicNode* pNode) {
|
|||
if (QUERY_NODE_LOGIC_PLAN_SCAN != nodeType(pNode) || (SCAN_TYPE_TAG == ((SScanLogicNode*)pNode)->scanType)) {
|
||||
return false;
|
||||
}
|
||||
SScanLogicNode *pScan = (SScanLogicNode*)pNode;
|
||||
SScanLogicNode* pScan = (SScanLogicNode*)pNode;
|
||||
if (NULL != pScan->pScanCols) {
|
||||
return false;
|
||||
}
|
||||
if (NULL == pNode->pParent || QUERY_NODE_LOGIC_PLAN_AGG != nodeType(pNode->pParent) || 1 != LIST_LENGTH(pNode->pParent->pChildren)) {
|
||||
if (NULL == pNode->pParent || QUERY_NODE_LOGIC_PLAN_AGG != nodeType(pNode->pParent) ||
|
||||
1 != LIST_LENGTH(pNode->pParent->pChildren)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
|
@ -308,7 +308,7 @@ static int32_t stbSplAppendWStart(SNodeList* pFuncs, int32_t* pIndex) {
|
|||
int32_t index = 0;
|
||||
SNode* pFunc = NULL;
|
||||
FOREACH(pFunc, pFuncs) {
|
||||
if (FUNCTION_TYPE_WSTARTTS == ((SFunctionNode*)pFunc)->funcType) {
|
||||
if (FUNCTION_TYPE_WSTART == ((SFunctionNode*)pFunc)->funcType) {
|
||||
*pIndex = index;
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
@ -319,7 +319,7 @@ static int32_t stbSplAppendWStart(SNodeList* pFuncs, int32_t* pIndex) {
|
|||
if (NULL == pWStart) {
|
||||
return TSDB_CODE_OUT_OF_MEMORY;
|
||||
}
|
||||
strcpy(pWStart->functionName, "_wstartts");
|
||||
strcpy(pWStart->functionName, "_wstart");
|
||||
snprintf(pWStart->node.aliasName, sizeof(pWStart->node.aliasName), "%s.%p", pWStart->functionName, pWStart);
|
||||
int32_t code = fmGetFuncInfo(pWStart, NULL, 0);
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
|
@ -333,7 +333,7 @@ static int32_t stbSplAppendWEnd(SWindowLogicNode* pWin, int32_t* pIndex) {
|
|||
int32_t index = 0;
|
||||
SNode* pFunc = NULL;
|
||||
FOREACH(pFunc, pWin->pFuncs) {
|
||||
if (FUNCTION_TYPE_WENDTS == ((SFunctionNode*)pFunc)->funcType) {
|
||||
if (FUNCTION_TYPE_WEND == ((SFunctionNode*)pFunc)->funcType) {
|
||||
*pIndex = index;
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
@ -344,7 +344,7 @@ static int32_t stbSplAppendWEnd(SWindowLogicNode* pWin, int32_t* pIndex) {
|
|||
if (NULL == pWEnd) {
|
||||
return TSDB_CODE_OUT_OF_MEMORY;
|
||||
}
|
||||
strcpy(pWEnd->functionName, "_wendts");
|
||||
strcpy(pWEnd->functionName, "_wend");
|
||||
snprintf(pWEnd->node.aliasName, sizeof(pWEnd->node.aliasName), "%s.%p", pWEnd->functionName, pWEnd);
|
||||
int32_t code = fmGetFuncInfo(pWEnd, NULL, 0);
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
|
|
|
@ -137,6 +137,17 @@ TEST_F(PlanBasicTest, sampleFunc) {
|
|||
run("SELECT SAMPLE(c1, 10) FROM st1 PARTITION BY TBNAME");
|
||||
}
|
||||
|
||||
TEST_F(PlanBasicTest, pseudoColumn) {
|
||||
useDb("root", "test");
|
||||
|
||||
run("SELECT _QSTART, _QEND, _QDURATION FROM t1");
|
||||
|
||||
run("SELECT _QSTART, _QEND, _QDURATION FROM t1 WHERE ts BETWEEN '2017-7-14 18:00:00' AND '2017-7-14 19:00:00'");
|
||||
|
||||
run("SELECT _QSTART, _QEND, _QDURATION, _WSTART, _WEND, _WDURATION, COUNT(*) FROM t1 "
|
||||
"WHERE ts BETWEEN '2017-7-14 18:00:00' AND '2017-7-14 19:00:00' INTERVAL(10S)");
|
||||
}
|
||||
|
||||
TEST_F(PlanBasicTest, withoutFrom) {
|
||||
useDb("root", "test");
|
||||
|
||||
|
|
|
@ -29,7 +29,7 @@ TEST_F(PlanIntervalTest, basic) {
|
|||
TEST_F(PlanIntervalTest, pseudoCol) {
|
||||
useDb("root", "test");
|
||||
|
||||
run("SELECT _WSTARTTS, _WDURATION, _WENDTS, COUNT(*) FROM t1 INTERVAL(10s)");
|
||||
run("SELECT _WSTART, _WDURATION, _WEND, COUNT(*) FROM t1 INTERVAL(10s)");
|
||||
}
|
||||
|
||||
TEST_F(PlanIntervalTest, fill) {
|
||||
|
@ -59,9 +59,9 @@ TEST_F(PlanIntervalTest, stable) {
|
|||
|
||||
run("SELECT COUNT(*) FROM st1 INTERVAL(10s)");
|
||||
|
||||
run("SELECT _WSTARTTS, COUNT(*) FROM st1 INTERVAL(10s)");
|
||||
run("SELECT _WSTART, COUNT(*) FROM st1 INTERVAL(10s)");
|
||||
|
||||
run("SELECT _WSTARTTS, COUNT(*) FROM st1 PARTITION BY TBNAME INTERVAL(10s)");
|
||||
run("SELECT _WSTART, COUNT(*) FROM st1 PARTITION BY TBNAME INTERVAL(10s)");
|
||||
|
||||
run("SELECT TBNAME, COUNT(*) FROM st1 PARTITION BY TBNAME INTERVAL(10s)");
|
||||
}
|
||||
|
|
|
@ -55,7 +55,7 @@ TEST_F(PlanOptimizeTest, sortPrimaryKey) {
|
|||
|
||||
run("SELECT c1 FROM t1 ORDER BY ts DESC");
|
||||
|
||||
run("SELECT COUNT(*) FROM t1 INTERVAL(10S) ORDER BY _WSTARTTS DESC");
|
||||
run("SELECT COUNT(*) FROM t1 INTERVAL(10S) ORDER BY _WSTART DESC");
|
||||
}
|
||||
|
||||
TEST_F(PlanOptimizeTest, PartitionTags) {
|
||||
|
|
|
@ -49,7 +49,7 @@ TEST_F(PlanOtherTest, createSmaIndex) {
|
|||
|
||||
run("SELECT SUM(c4) FROM t1 INTERVAL(10s)");
|
||||
|
||||
run("SELECT _WSTARTTS, MIN(c3 + 10) FROM t1 "
|
||||
run("SELECT _WSTART, MIN(c3 + 10) FROM t1 "
|
||||
"WHERE ts BETWEEN TIMESTAMP '2022-04-01 00:00:00' AND TIMESTAMP '2022-04-30 23:59:59.999' INTERVAL(10s)");
|
||||
|
||||
run("SELECT SUM(c4), MAX(c3) FROM t1 INTERVAL(10s)");
|
||||
|
|
|
@ -282,7 +282,7 @@ int32_t dataConverToStr(char* str, int type, void* buf, int32_t bufSize, int32_t
|
|||
}
|
||||
|
||||
*str = '"';
|
||||
int32_t length = taosUcs4ToMbs((TdUcs4 *)buf, bufSize, str + 1);
|
||||
int32_t length = taosUcs4ToMbs((TdUcs4*)buf, bufSize, str + 1);
|
||||
if (length <= 0) {
|
||||
return TSDB_CODE_TSC_INVALID_VALUE;
|
||||
}
|
||||
|
@ -310,15 +310,15 @@ int32_t dataConverToStr(char* str, int type, void* buf, int32_t bufSize, int32_t
|
|||
return TSDB_CODE_TSC_INVALID_VALUE;
|
||||
}
|
||||
|
||||
if(len) *len = n;
|
||||
if (len) *len = n;
|
||||
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
char* parseTagDatatoJson(void* p) {
|
||||
char* string = NULL;
|
||||
char* string = NULL;
|
||||
SArray* pTagVals = NULL;
|
||||
cJSON* json = NULL;
|
||||
cJSON* json = NULL;
|
||||
if (tTagToValArray((const STag*)p, &pTagVals) != 0) {
|
||||
goto end;
|
||||
}
|
||||
|
@ -327,7 +327,7 @@ char* parseTagDatatoJson(void* p) {
|
|||
if (nCols == 0) {
|
||||
goto end;
|
||||
}
|
||||
char tagJsonKey[256] = {0};
|
||||
char tagJsonKey[256] = {0};
|
||||
json = cJSON_CreateObject();
|
||||
if (json == NULL) {
|
||||
goto end;
|
||||
|
@ -390,7 +390,7 @@ char* parseTagDatatoJson(void* p) {
|
|||
end:
|
||||
cJSON_Delete(json);
|
||||
taosArrayDestroy(pTagVals);
|
||||
if(string == NULL){
|
||||
if (string == NULL) {
|
||||
string = strdup(TSDB_DATA_NULL_STR_L);
|
||||
}
|
||||
return string;
|
||||
|
|
|
@ -30,6 +30,7 @@ typedef struct SOperatorValueType {
|
|||
|
||||
typedef struct SScalarCtx {
|
||||
int32_t code;
|
||||
bool dual;
|
||||
SArray *pBlockList; /* element is SSDataBlock* */
|
||||
SHashObj *pRes; /* element is SScalarParam */
|
||||
void *param; // additional parameter (meta actually) for acquire value such as tbname/tags values
|
||||
|
|
|
@ -729,6 +729,7 @@ EDealRes sclRewriteFunction(SNode** pNode, SScalarCtx *ctx) {
|
|||
|
||||
if (colDataIsNull_s(output.columnData, 0)) {
|
||||
res->node.resType.type = TSDB_DATA_TYPE_NULL;
|
||||
res->node.resType.bytes = tDataTypes[TSDB_DATA_TYPE_NULL].bytes;
|
||||
} else {
|
||||
res->node.resType.type = output.columnData->info.type;
|
||||
res->node.resType.bytes = output.columnData->info.bytes;
|
||||
|
@ -819,6 +820,7 @@ EDealRes sclRewriteOperator(SNode** pNode, SScalarCtx *ctx) {
|
|||
if (colDataIsNull_s(output.columnData, 0)) {
|
||||
if(node->node.resType.type != TSDB_DATA_TYPE_JSON){
|
||||
res->node.resType.type = TSDB_DATA_TYPE_NULL;
|
||||
res->node.resType.bytes = tDataTypes[TSDB_DATA_TYPE_NULL].bytes;
|
||||
}else{
|
||||
res->node.resType = node->node.resType;
|
||||
res->isNull = true;
|
||||
|
@ -1008,13 +1010,14 @@ int32_t sclExtendResRows(SScalarParam *pDst, SScalarParam *pSrc, SArray *pBlockL
|
|||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
int32_t scalarCalculateConstants(SNode *pNode, SNode **pRes) {
|
||||
int32_t sclCalcConstants(SNode *pNode, bool dual, SNode **pRes) {
|
||||
if (NULL == pNode) {
|
||||
SCL_ERR_RET(TSDB_CODE_QRY_INVALID_INPUT);
|
||||
}
|
||||
|
||||
int32_t code = 0;
|
||||
SScalarCtx ctx = {0};
|
||||
ctx.dual = dual;
|
||||
ctx.pRes = taosHashInit(SCL_DEFAULT_OP_NUM, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BIGINT), false, HASH_NO_LOCK);
|
||||
if (NULL == ctx.pRes) {
|
||||
sclError("taosHashInit failed, num:%d", SCL_DEFAULT_OP_NUM);
|
||||
|
@ -1026,10 +1029,88 @@ int32_t scalarCalculateConstants(SNode *pNode, SNode **pRes) {
|
|||
*pRes = pNode;
|
||||
|
||||
_return:
|
||||
|
||||
sclFreeRes(ctx.pRes);
|
||||
return code;
|
||||
}
|
||||
|
||||
static int32_t sclGetMinusOperatorResType(SOperatorNode* pOp) {
|
||||
if (!IS_MATHABLE_TYPE(((SExprNode*)(pOp->pLeft))->resType.type)) {
|
||||
return TSDB_CODE_TSC_INVALID_OPERATION;
|
||||
}
|
||||
pOp->node.resType.type = TSDB_DATA_TYPE_DOUBLE;
|
||||
pOp->node.resType.bytes = tDataTypes[TSDB_DATA_TYPE_DOUBLE].bytes;
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
static int32_t sclGetMathOperatorResType(SOperatorNode* pOp) {
|
||||
SDataType ldt = ((SExprNode*)(pOp->pLeft))->resType;
|
||||
SDataType rdt = ((SExprNode*)(pOp->pRight))->resType;
|
||||
if ((TSDB_DATA_TYPE_TIMESTAMP == ldt.type && TSDB_DATA_TYPE_TIMESTAMP == rdt.type) ||
|
||||
(TSDB_DATA_TYPE_TIMESTAMP == ldt.type && (IS_VAR_DATA_TYPE(rdt.type) || IS_FLOAT_TYPE(rdt.type))) ||
|
||||
(TSDB_DATA_TYPE_TIMESTAMP == rdt.type && (IS_VAR_DATA_TYPE(ldt.type) || IS_FLOAT_TYPE(ldt.type)))) {
|
||||
return TSDB_CODE_TSC_INVALID_OPERATION;
|
||||
}
|
||||
|
||||
if ((TSDB_DATA_TYPE_TIMESTAMP == ldt.type && IS_INTEGER_TYPE(rdt.type)) ||
|
||||
(TSDB_DATA_TYPE_TIMESTAMP == rdt.type && IS_INTEGER_TYPE(ldt.type)) ||
|
||||
(TSDB_DATA_TYPE_TIMESTAMP == ldt.type && TSDB_DATA_TYPE_BOOL == rdt.type) ||
|
||||
(TSDB_DATA_TYPE_TIMESTAMP == rdt.type && TSDB_DATA_TYPE_BOOL == ldt.type)) {
|
||||
pOp->node.resType.type = TSDB_DATA_TYPE_TIMESTAMP;
|
||||
pOp->node.resType.bytes = tDataTypes[TSDB_DATA_TYPE_TIMESTAMP].bytes;
|
||||
} else {
|
||||
pOp->node.resType.type = TSDB_DATA_TYPE_DOUBLE;
|
||||
pOp->node.resType.bytes = tDataTypes[TSDB_DATA_TYPE_DOUBLE].bytes;
|
||||
}
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
static int32_t sclGetCompOperatorResType(SOperatorNode* pOp) {
|
||||
SDataType ldt = ((SExprNode*)(pOp->pLeft))->resType;
|
||||
if (OP_TYPE_IN == pOp->opType || OP_TYPE_NOT_IN == pOp->opType) {
|
||||
((SExprNode*)(pOp->pRight))->resType = ldt;
|
||||
} else if (nodesIsRegularOp(pOp)) {
|
||||
SDataType rdt = ((SExprNode*)(pOp->pRight))->resType;
|
||||
if (!IS_VAR_DATA_TYPE(ldt.type) || QUERY_NODE_VALUE != nodeType(pOp->pRight) ||
|
||||
(!IS_STR_DATA_TYPE(rdt.type) && (rdt.type != TSDB_DATA_TYPE_NULL))) {
|
||||
return TSDB_CODE_TSC_INVALID_OPERATION;
|
||||
}
|
||||
}
|
||||
pOp->node.resType.type = TSDB_DATA_TYPE_BOOL;
|
||||
pOp->node.resType.bytes = tDataTypes[TSDB_DATA_TYPE_BOOL].bytes;
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
static int32_t sclGetJsonOperatorResType(SOperatorNode* pOp) {
|
||||
SDataType ldt = ((SExprNode*)(pOp->pLeft))->resType;
|
||||
SDataType rdt = ((SExprNode*)(pOp->pRight))->resType;
|
||||
if (TSDB_DATA_TYPE_JSON != ldt.type || !IS_STR_DATA_TYPE(rdt.type)) {
|
||||
return TSDB_CODE_TSC_INVALID_OPERATION;
|
||||
}
|
||||
if (pOp->opType == OP_TYPE_JSON_GET_VALUE) {
|
||||
pOp->node.resType.type = TSDB_DATA_TYPE_JSON;
|
||||
} else if (pOp->opType == OP_TYPE_JSON_CONTAINS) {
|
||||
pOp->node.resType.type = TSDB_DATA_TYPE_BOOL;
|
||||
}
|
||||
pOp->node.resType.bytes = tDataTypes[pOp->node.resType.type].bytes;
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
static int32_t sclGetBitwiseOperatorResType(SOperatorNode* pOp) {
|
||||
pOp->node.resType.type = TSDB_DATA_TYPE_BIGINT;
|
||||
pOp->node.resType.bytes = tDataTypes[TSDB_DATA_TYPE_BIGINT].bytes;
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
int32_t scalarCalculateConstants(SNode *pNode, SNode **pRes) {
|
||||
return sclCalcConstants(pNode, false, pRes);
|
||||
}
|
||||
|
||||
int32_t scalarCalculateConstantsFromDual(SNode *pNode, SNode **pRes) {
|
||||
return sclCalcConstants(pNode, true, pRes);
|
||||
}
|
||||
|
||||
int32_t scalarCalculate(SNode *pNode, SArray *pBlockList, SScalarParam *pDst) {
|
||||
if (NULL == pNode || NULL == pBlockList) {
|
||||
SCL_ERR_RET(TSDB_CODE_QRY_INVALID_INPUT);
|
||||
|
@ -1073,74 +1154,6 @@ _return:
|
|||
return code;
|
||||
}
|
||||
|
||||
static int32_t getMinusOperatorResultType(SOperatorNode* pOp) {
|
||||
if (!IS_MATHABLE_TYPE(((SExprNode*)(pOp->pLeft))->resType.type)) {
|
||||
return TSDB_CODE_TSC_INVALID_OPERATION;
|
||||
}
|
||||
pOp->node.resType.type = TSDB_DATA_TYPE_DOUBLE;
|
||||
pOp->node.resType.bytes = tDataTypes[TSDB_DATA_TYPE_DOUBLE].bytes;
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
static int32_t getArithmeticOperatorResultType(SOperatorNode* pOp) {
|
||||
SDataType ldt = ((SExprNode*)(pOp->pLeft))->resType;
|
||||
SDataType rdt = ((SExprNode*)(pOp->pRight))->resType;
|
||||
if ((TSDB_DATA_TYPE_TIMESTAMP == ldt.type && TSDB_DATA_TYPE_TIMESTAMP == rdt.type) ||
|
||||
(TSDB_DATA_TYPE_TIMESTAMP == ldt.type && (IS_VAR_DATA_TYPE(rdt.type) || IS_FLOAT_TYPE(rdt.type))) ||
|
||||
(TSDB_DATA_TYPE_TIMESTAMP == rdt.type && (IS_VAR_DATA_TYPE(ldt.type) || IS_FLOAT_TYPE(ldt.type)))) {
|
||||
return TSDB_CODE_TSC_INVALID_OPERATION;
|
||||
}
|
||||
|
||||
if ((TSDB_DATA_TYPE_TIMESTAMP == ldt.type && IS_INTEGER_TYPE(rdt.type)) ||
|
||||
(TSDB_DATA_TYPE_TIMESTAMP == rdt.type && IS_INTEGER_TYPE(ldt.type)) ||
|
||||
(TSDB_DATA_TYPE_TIMESTAMP == ldt.type && TSDB_DATA_TYPE_BOOL == rdt.type) ||
|
||||
(TSDB_DATA_TYPE_TIMESTAMP == rdt.type && TSDB_DATA_TYPE_BOOL == ldt.type)) {
|
||||
pOp->node.resType.type = TSDB_DATA_TYPE_TIMESTAMP;
|
||||
pOp->node.resType.bytes = tDataTypes[TSDB_DATA_TYPE_TIMESTAMP].bytes;
|
||||
} else {
|
||||
pOp->node.resType.type = TSDB_DATA_TYPE_DOUBLE;
|
||||
pOp->node.resType.bytes = tDataTypes[TSDB_DATA_TYPE_DOUBLE].bytes;
|
||||
}
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
static int32_t getComparisonOperatorResultType(SOperatorNode* pOp) {
|
||||
SDataType ldt = ((SExprNode*)(pOp->pLeft))->resType;
|
||||
if (OP_TYPE_IN == pOp->opType || OP_TYPE_NOT_IN == pOp->opType) {
|
||||
((SExprNode*)(pOp->pRight))->resType = ldt;
|
||||
} else if (nodesIsRegularOp(pOp)) {
|
||||
SDataType rdt = ((SExprNode*)(pOp->pRight))->resType;
|
||||
if (!IS_VAR_DATA_TYPE(ldt.type) || QUERY_NODE_VALUE != nodeType(pOp->pRight) ||
|
||||
(!IS_STR_DATA_TYPE(rdt.type) && (rdt.type != TSDB_DATA_TYPE_NULL))) {
|
||||
return TSDB_CODE_TSC_INVALID_OPERATION;
|
||||
}
|
||||
}
|
||||
pOp->node.resType.type = TSDB_DATA_TYPE_BOOL;
|
||||
pOp->node.resType.bytes = tDataTypes[TSDB_DATA_TYPE_BOOL].bytes;
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
static int32_t getJsonOperatorResultType(SOperatorNode* pOp) {
|
||||
SDataType ldt = ((SExprNode*)(pOp->pLeft))->resType;
|
||||
SDataType rdt = ((SExprNode*)(pOp->pRight))->resType;
|
||||
if (TSDB_DATA_TYPE_JSON != ldt.type || !IS_STR_DATA_TYPE(rdt.type)) {
|
||||
return TSDB_CODE_TSC_INVALID_OPERATION;
|
||||
}
|
||||
if (pOp->opType == OP_TYPE_JSON_GET_VALUE) {
|
||||
pOp->node.resType.type = TSDB_DATA_TYPE_JSON;
|
||||
} else if (pOp->opType == OP_TYPE_JSON_CONTAINS) {
|
||||
pOp->node.resType.type = TSDB_DATA_TYPE_BOOL;
|
||||
}
|
||||
pOp->node.resType.bytes = tDataTypes[pOp->node.resType.type].bytes;
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
static int32_t getBitwiseOperatorResultType(SOperatorNode* pOp) {
|
||||
pOp->node.resType.type = TSDB_DATA_TYPE_BIGINT;
|
||||
pOp->node.resType.bytes = tDataTypes[TSDB_DATA_TYPE_BIGINT].bytes;
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
int32_t scalarGetOperatorResultType(SOperatorNode* pOp) {
|
||||
if (TSDB_DATA_TYPE_BLOB == ((SExprNode*)(pOp->pLeft))->resType.type ||
|
||||
(NULL != pOp->pRight && TSDB_DATA_TYPE_BLOB == ((SExprNode*)(pOp->pRight))->resType.type)) {
|
||||
|
@ -1153,15 +1166,15 @@ int32_t scalarGetOperatorResultType(SOperatorNode* pOp) {
|
|||
case OP_TYPE_MULTI:
|
||||
case OP_TYPE_DIV:
|
||||
case OP_TYPE_REM:
|
||||
return getArithmeticOperatorResultType(pOp);
|
||||
return sclGetMathOperatorResType(pOp);
|
||||
case OP_TYPE_MINUS:
|
||||
return getMinusOperatorResultType(pOp);
|
||||
return sclGetMinusOperatorResType(pOp);
|
||||
case OP_TYPE_ASSIGN:
|
||||
pOp->node.resType = ((SExprNode*)(pOp->pLeft))->resType;
|
||||
break;
|
||||
case OP_TYPE_BIT_AND:
|
||||
case OP_TYPE_BIT_OR:
|
||||
return getBitwiseOperatorResultType(pOp);
|
||||
return sclGetBitwiseOperatorResType(pOp);
|
||||
case OP_TYPE_GREATER_THAN:
|
||||
case OP_TYPE_GREATER_EQUAL:
|
||||
case OP_TYPE_LOWER_THAN:
|
||||
|
@ -1182,10 +1195,10 @@ int32_t scalarGetOperatorResultType(SOperatorNode* pOp) {
|
|||
case OP_TYPE_NMATCH:
|
||||
case OP_TYPE_IN:
|
||||
case OP_TYPE_NOT_IN:
|
||||
return getComparisonOperatorResultType(pOp);
|
||||
return sclGetCompOperatorResType(pOp);
|
||||
case OP_TYPE_JSON_GET_VALUE:
|
||||
case OP_TYPE_JSON_CONTAINS:
|
||||
return getJsonOperatorResultType(pOp);
|
||||
return sclGetJsonOperatorResType(pOp);
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
|
|
@ -1055,7 +1055,7 @@ static void vectorMathAddHelper(SColumnInfoData* pLeftCol, SColumnInfoData* pRig
|
|||
}
|
||||
}
|
||||
|
||||
static void vectorMathBigintAddHelper(SColumnInfoData* pLeftCol, SColumnInfoData* pRightCol, SColumnInfoData* pOutputCol, int32_t numOfRows, int32_t step, int32_t i) {
|
||||
static void vectorMathTsAddHelper(SColumnInfoData* pLeftCol, SColumnInfoData* pRightCol, SColumnInfoData* pOutputCol, int32_t numOfRows, int32_t step, int32_t i) {
|
||||
_getBigintValue_fn_t getVectorBigintValueFnLeft = getVectorBigintValueFn(pLeftCol->info.type);
|
||||
_getBigintValue_fn_t getVectorBigintValueFnRight = getVectorBigintValueFn(pRightCol->info.type);
|
||||
|
||||
|
@ -1069,7 +1069,8 @@ static void vectorMathBigintAddHelper(SColumnInfoData* pLeftCol, SColumnInfoData
|
|||
colDataAppendNULL(pOutputCol, i);
|
||||
continue; // TODO set null or ignore
|
||||
}
|
||||
*output = getVectorBigintValueFnLeft(pLeftCol->pData, i) + getVectorBigintValueFnRight(pRightCol->pData, 0);
|
||||
*output = taosTimeAdd(getVectorBigintValueFnLeft(pLeftCol->pData, i), getVectorBigintValueFnRight(pRightCol->pData, 0),
|
||||
pRightCol->info.scale, pRightCol->info.precision);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1116,7 +1117,17 @@ void vectorMathAdd(SScalarParam* pLeft, SScalarParam* pRight, SScalarParam *pOut
|
|||
_getBigintValue_fn_t getVectorBigintValueFnLeft = getVectorBigintValueFn(pLeftCol->info.type);
|
||||
_getBigintValue_fn_t getVectorBigintValueFnRight = getVectorBigintValueFn(pRightCol->info.type);
|
||||
|
||||
if (pLeft->numOfRows == pRight->numOfRows) {
|
||||
if (pLeft->numOfRows == 1 && pRight->numOfRows == 1) {
|
||||
if (GET_PARAM_TYPE(pLeft) == TSDB_DATA_TYPE_TIMESTAMP) {
|
||||
vectorMathTsAddHelper(pLeftCol, pRightCol, pOutputCol, pRight->numOfRows, step, i);
|
||||
} else {
|
||||
vectorMathTsAddHelper(pRightCol, pLeftCol, pOutputCol, pRight->numOfRows, step, i);
|
||||
}
|
||||
} else if (pLeft->numOfRows == 1) {
|
||||
vectorMathTsAddHelper(pRightCol, pLeftCol, pOutputCol, pRight->numOfRows, step, i);
|
||||
} else if (pRight->numOfRows == 1) {
|
||||
vectorMathTsAddHelper(pLeftCol, pRightCol, pOutputCol, pLeft->numOfRows, step, i);
|
||||
} else if (pLeft->numOfRows == pRight->numOfRows) {
|
||||
for (; i < pRight->numOfRows && i >= 0; i += step, output += 1) {
|
||||
if (IS_NULL) {
|
||||
colDataAppendNULL(pOutputCol, i);
|
||||
|
@ -1124,10 +1135,6 @@ void vectorMathAdd(SScalarParam* pLeft, SScalarParam* pRight, SScalarParam *pOut
|
|||
}
|
||||
*output = getVectorBigintValueFnLeft(pLeftCol->pData, i) + getVectorBigintValueFnRight(pRightCol->pData, i);
|
||||
}
|
||||
} else if (pLeft->numOfRows == 1) {
|
||||
vectorMathBigintAddHelper(pRightCol, pLeftCol, pOutputCol, pRight->numOfRows, step, i);
|
||||
} else if (pRight->numOfRows == 1) {
|
||||
vectorMathBigintAddHelper(pLeftCol, pRightCol, pOutputCol, pLeft->numOfRows, step, i);
|
||||
}
|
||||
} else {
|
||||
double *output = (double *)pOutputCol->pData;
|
||||
|
@ -1174,7 +1181,7 @@ static void vectorMathSubHelper(SColumnInfoData* pLeftCol, SColumnInfoData* pRig
|
|||
}
|
||||
}
|
||||
|
||||
static void vectorMathBigintSubHelper(SColumnInfoData* pLeftCol, SColumnInfoData* pRightCol, SColumnInfoData* pOutputCol, int32_t numOfRows, int32_t step, int32_t factor, int32_t i) {
|
||||
static void vectorMathTsSubHelper(SColumnInfoData* pLeftCol, SColumnInfoData* pRightCol, SColumnInfoData* pOutputCol, int32_t numOfRows, int32_t step, int32_t factor, int32_t i) {
|
||||
_getBigintValue_fn_t getVectorBigintValueFnLeft = getVectorBigintValueFn(pLeftCol->info.type);
|
||||
_getBigintValue_fn_t getVectorBigintValueFnRight = getVectorBigintValueFn(pRightCol->info.type);
|
||||
|
||||
|
@ -1188,7 +1195,9 @@ static void vectorMathBigintSubHelper(SColumnInfoData* pLeftCol, SColumnInfoData
|
|||
colDataAppendNULL(pOutputCol, i);
|
||||
continue; // TODO set null or ignore
|
||||
}
|
||||
*output = (getVectorBigintValueFnLeft(pLeftCol->pData, i) - getVectorBigintValueFnRight(pRightCol->pData, 0)) * factor;
|
||||
*output = taosTimeSub(getVectorBigintValueFnLeft(pLeftCol->pData, i), getVectorBigintValueFnRight(pRightCol->pData, 0),
|
||||
pRightCol->info.scale, pRightCol->info.precision);
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1211,7 +1220,13 @@ void vectorMathSub(SScalarParam* pLeft, SScalarParam* pRight, SScalarParam *pOut
|
|||
_getBigintValue_fn_t getVectorBigintValueFnLeft = getVectorBigintValueFn(pLeftCol->info.type);
|
||||
_getBigintValue_fn_t getVectorBigintValueFnRight = getVectorBigintValueFn(pRightCol->info.type);
|
||||
|
||||
if (pLeft->numOfRows == pRight->numOfRows) {
|
||||
if (pLeft->numOfRows == 1 && pRight->numOfRows == 1) {
|
||||
vectorMathTsSubHelper(pLeftCol, pRightCol, pOutputCol, pLeft->numOfRows, step, 1, i);
|
||||
} else if (pLeft->numOfRows == 1) {
|
||||
vectorMathTsSubHelper(pRightCol, pLeftCol, pOutputCol, pRight->numOfRows, step, -1, i);
|
||||
} else if (pRight->numOfRows == 1) {
|
||||
vectorMathTsSubHelper(pLeftCol, pRightCol, pOutputCol, pLeft->numOfRows, step, 1, i);
|
||||
} else if (pLeft->numOfRows == pRight->numOfRows) {
|
||||
for (; i < pRight->numOfRows && i >= 0; i += step, output += 1) {
|
||||
if (IS_NULL) {
|
||||
colDataAppendNULL(pOutputCol, i);
|
||||
|
@ -1219,10 +1234,6 @@ void vectorMathSub(SScalarParam* pLeft, SScalarParam* pRight, SScalarParam *pOut
|
|||
}
|
||||
*output = getVectorBigintValueFnLeft(pLeftCol->pData, i) - getVectorBigintValueFnRight(pRightCol->pData, i);
|
||||
}
|
||||
} else if (pLeft->numOfRows == 1) {
|
||||
vectorMathBigintSubHelper(pRightCol, pLeftCol, pOutputCol, pRight->numOfRows, step, -1, i);
|
||||
} else if (pRight->numOfRows == 1) {
|
||||
vectorMathBigintSubHelper(pLeftCol, pRightCol, pOutputCol, pLeft->numOfRows, step, 1, i);
|
||||
}
|
||||
} else {
|
||||
double *output = (double *)pOutputCol->pData;
|
||||
|
|
|
@ -223,6 +223,7 @@ typedef struct SSchJobAttr {
|
|||
|
||||
typedef struct {
|
||||
int32_t op;
|
||||
SRWLatch lock;
|
||||
bool syncReq;
|
||||
} SSchOpStatus;
|
||||
|
||||
|
@ -473,6 +474,7 @@ int32_t schGetTaskFromList(SHashObj *pTaskList, uint64_t taskId, SSchTask **pTas
|
|||
int32_t schInitTask(SSchJob *pJob, SSchTask *pTask, SSubplan *pPlan, SSchLevel *pLevel, int32_t levelNum);
|
||||
int32_t schSwitchTaskCandidateAddr(SSchJob *pJob, SSchTask *pTask);
|
||||
void schDirectPostJobRes(SSchedulerReq* pReq, int32_t errCode);
|
||||
bool schChkCurrentOp(SSchJob *pJob, int32_t op, bool sync);
|
||||
|
||||
extern SSchDebug gSCHDebug;
|
||||
|
||||
|
|
|
@ -443,25 +443,37 @@ int32_t schNotifyUserFetchRes(SSchJob* pJob) {
|
|||
}
|
||||
|
||||
void schPostJobRes(SSchJob *pJob, SCH_OP_TYPE op) {
|
||||
SCH_LOCK(SCH_WRITE, &pJob->opStatus.lock);
|
||||
|
||||
if (SCH_OP_NULL == pJob->opStatus.op) {
|
||||
SCH_JOB_DLOG("job not in any operation, no need to post job res, status:%s", jobTaskStatusStr(pJob->status));
|
||||
return;
|
||||
goto _return;
|
||||
}
|
||||
|
||||
if (op && pJob->opStatus.op != op) {
|
||||
SCH_JOB_ELOG("job in operation %s mis-match with expected %s", schGetOpStr(pJob->opStatus.op), schGetOpStr(op));
|
||||
return;
|
||||
goto _return;
|
||||
}
|
||||
|
||||
if (SCH_JOB_IN_SYNC_OP(pJob)) {
|
||||
SCH_UNLOCK(SCH_WRITE, &pJob->opStatus.lock);
|
||||
tsem_post(&pJob->rspSem);
|
||||
} else if (SCH_JOB_IN_ASYNC_EXEC_OP(pJob)) {
|
||||
SCH_UNLOCK(SCH_WRITE, &pJob->opStatus.lock);
|
||||
schNotifyUserExecRes(pJob);
|
||||
} else if (SCH_JOB_IN_ASYNC_FETCH_OP(pJob)) {
|
||||
SCH_UNLOCK(SCH_WRITE, &pJob->opStatus.lock);
|
||||
schNotifyUserFetchRes(pJob);
|
||||
} else {
|
||||
SCH_UNLOCK(SCH_WRITE, &pJob->opStatus.lock);
|
||||
SCH_JOB_ELOG("job not in any operation, status:%s", jobTaskStatusStr(pJob->status));
|
||||
}
|
||||
|
||||
return;
|
||||
|
||||
_return:
|
||||
|
||||
SCH_UNLOCK(SCH_WRITE, &pJob->opStatus.lock);
|
||||
}
|
||||
|
||||
int32_t schProcessOnJobFailureImpl(SSchJob *pJob, int32_t status, int32_t errCode) {
|
||||
|
@ -658,13 +670,13 @@ int32_t schJobFetchRows(SSchJob *pJob) {
|
|||
if (!(pJob->attr.explainMode == EXPLAIN_MODE_STATIC)) {
|
||||
SCH_ERR_RET(schLaunchFetchTask(pJob));
|
||||
|
||||
if (pJob->opStatus.syncReq) {
|
||||
if (schChkCurrentOp(pJob, SCH_OP_FETCH, true)) {
|
||||
SCH_JOB_DLOG("sync wait for rsp now, job status:%s", SCH_GET_JOB_STATUS_STR(pJob));
|
||||
tsem_wait(&pJob->rspSem);
|
||||
SCH_RET(schDumpJobFetchRes(pJob, pJob->userRes.fetchRes));
|
||||
}
|
||||
} else {
|
||||
if (pJob->opStatus.syncReq) {
|
||||
if (schChkCurrentOp(pJob, SCH_OP_FETCH, true)) {
|
||||
SCH_RET(schDumpJobFetchRes(pJob, pJob->userRes.fetchRes));
|
||||
} else {
|
||||
schPostJobRes(pJob, SCH_OP_FETCH);
|
||||
|
@ -775,25 +787,37 @@ void schDirectPostJobRes(SSchedulerReq* pReq, int32_t errCode) {
|
|||
}
|
||||
}
|
||||
|
||||
bool schChkCurrentOp(SSchJob *pJob, int32_t op, bool sync) {
|
||||
SCH_LOCK(SCH_READ, &pJob->opStatus.lock);
|
||||
bool r = (pJob->opStatus.op == op) && (pJob->opStatus.syncReq == sync);
|
||||
SCH_UNLOCK(SCH_READ, &pJob->opStatus.lock);
|
||||
|
||||
return r;
|
||||
}
|
||||
|
||||
void schProcessOnOpEnd(SSchJob *pJob, SCH_OP_TYPE type, SSchedulerReq* pReq, int32_t errCode) {
|
||||
int32_t op = 0;
|
||||
|
||||
switch (type) {
|
||||
case SCH_OP_EXEC:
|
||||
if (pReq && pReq->syncReq) {
|
||||
SCH_LOCK(SCH_WRITE, &pJob->opStatus.lock);
|
||||
op = atomic_val_compare_exchange_32(&pJob->opStatus.op, type, SCH_OP_NULL);
|
||||
if (SCH_OP_NULL == op || op != type) {
|
||||
SCH_JOB_ELOG("job not in %s operation, op:%s, status:%s", schGetOpStr(type), schGetOpStr(op), jobTaskStatusStr(pJob->status));
|
||||
}
|
||||
SCH_UNLOCK(SCH_WRITE, &pJob->opStatus.lock);
|
||||
schDumpJobExecRes(pJob, pReq->pExecRes);
|
||||
}
|
||||
break;
|
||||
case SCH_OP_FETCH:
|
||||
if (pReq && pReq->syncReq) {
|
||||
SCH_LOCK(SCH_WRITE, &pJob->opStatus.lock);
|
||||
op = atomic_val_compare_exchange_32(&pJob->opStatus.op, type, SCH_OP_NULL);
|
||||
if (SCH_OP_NULL == op || op != type) {
|
||||
SCH_JOB_ELOG("job not in %s operation, op:%s, status:%s", schGetOpStr(type), schGetOpStr(op), jobTaskStatusStr(pJob->status));
|
||||
}
|
||||
SCH_UNLOCK(SCH_WRITE, &pJob->opStatus.lock);
|
||||
}
|
||||
break;
|
||||
case SCH_OP_GET_STATUS:
|
||||
|
@ -816,8 +840,10 @@ int32_t schProcessOnOpBegin(SSchJob* pJob, SCH_OP_TYPE type, SSchedulerReq* pReq
|
|||
|
||||
switch (type) {
|
||||
case SCH_OP_EXEC:
|
||||
SCH_LOCK(SCH_WRITE, &pJob->opStatus.lock);
|
||||
if (SCH_OP_NULL != atomic_val_compare_exchange_32(&pJob->opStatus.op, SCH_OP_NULL, type)) {
|
||||
SCH_JOB_ELOG("job already in %s operation", schGetOpStr(pJob->opStatus.op));
|
||||
SCH_UNLOCK(SCH_WRITE, &pJob->opStatus.lock);
|
||||
schDirectPostJobRes(pReq, TSDB_CODE_TSC_APP_ERROR);
|
||||
SCH_ERR_RET(TSDB_CODE_TSC_APP_ERROR);
|
||||
}
|
||||
|
@ -825,10 +851,13 @@ int32_t schProcessOnOpBegin(SSchJob* pJob, SCH_OP_TYPE type, SSchedulerReq* pReq
|
|||
SCH_JOB_DLOG("job start %s operation", schGetOpStr(pJob->opStatus.op));
|
||||
|
||||
pJob->opStatus.syncReq = pReq->syncReq;
|
||||
SCH_UNLOCK(SCH_WRITE, &pJob->opStatus.lock);
|
||||
break;
|
||||
case SCH_OP_FETCH:
|
||||
SCH_LOCK(SCH_WRITE, &pJob->opStatus.lock);
|
||||
if (SCH_OP_NULL != atomic_val_compare_exchange_32(&pJob->opStatus.op, SCH_OP_NULL, type)) {
|
||||
SCH_JOB_ELOG("job already in %s operation", schGetOpStr(pJob->opStatus.op));
|
||||
SCH_UNLOCK(SCH_WRITE, &pJob->opStatus.lock);
|
||||
schDirectPostJobRes(pReq, TSDB_CODE_TSC_APP_ERROR);
|
||||
SCH_ERR_RET(TSDB_CODE_TSC_APP_ERROR);
|
||||
}
|
||||
|
@ -840,6 +869,7 @@ int32_t schProcessOnOpBegin(SSchJob* pJob, SCH_OP_TYPE type, SSchedulerReq* pReq
|
|||
pJob->userRes.cbParam = pReq->cbParam;
|
||||
|
||||
pJob->opStatus.syncReq = pReq->syncReq;
|
||||
SCH_UNLOCK(SCH_WRITE, &pJob->opStatus.lock);
|
||||
|
||||
if (!SCH_JOB_NEED_FETCH(pJob)) {
|
||||
SCH_JOB_ELOG("no need to fetch data, status:%s", SCH_GET_JOB_STATUS_STR(pJob));
|
||||
|
|
|
@ -41,6 +41,8 @@ void schFreeTask(SSchJob *pJob, SSchTask *pTask) {
|
|||
if (pTask->execNodes) {
|
||||
taosHashCleanup(pTask->execNodes);
|
||||
}
|
||||
|
||||
taosMemoryFree(pTask->profile.execTime);
|
||||
}
|
||||
|
||||
int32_t schInitTask(SSchJob *pJob, SSchTask *pTask, SSubplan *pPlan, SSchLevel *pLevel, int32_t levelNum) {
|
||||
|
@ -503,6 +505,7 @@ int32_t schTaskCheckSetRetry(SSchJob *pJob, SSchTask *pTask, int32_t errCode, bo
|
|||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
/*
|
||||
if (SCH_IS_DATA_BIND_TASK(pTask)) {
|
||||
if ((pTask->execId + 1) >= SCH_TASK_NUM_OF_EPS(&pTask->plan->execNode)) {
|
||||
*needRetry = false;
|
||||
|
@ -520,6 +523,7 @@ int32_t schTaskCheckSetRetry(SSchJob *pJob, SSchTask *pTask, int32_t errCode, bo
|
|||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
*needRetry = true;
|
||||
SCH_TASK_DLOG("task need the %dth retry, errCode:%x - %s", pTask->execId + 1, errCode, tstrerror(errCode));
|
||||
|
|
|
@ -42,6 +42,9 @@ int32_t streamBroadcastToChildren(SStreamTask* pTask, const SSDataBlock* pBlock)
|
|||
|
||||
int32_t tEncodeStreamRetrieveReq(SEncoder* pEncoder, const SStreamRetrieveReq* pReq);
|
||||
|
||||
int32_t streamAppendQueueItem(SStreamQueueItem* dst, SStreamQueueItem* elem);
|
||||
void streamFreeQitem(SStreamQueueItem* data);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
|
|
@ -97,7 +97,7 @@ int32_t streamLaunchByWrite(SStreamTask* pTask, int32_t vgId) {
|
|||
.pCont = pRunReq,
|
||||
.contLen = sizeof(SStreamTaskRunReq),
|
||||
};
|
||||
tmsgPutToQueue(pTask->pMsgCb, FETCH_QUEUE, &msg);
|
||||
tmsgPutToQueue(pTask->pMsgCb, STREAM_QUEUE, &msg);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
@ -173,7 +173,8 @@ int32_t streamTaskEnqueueRetrieve(SStreamTask* pTask, SStreamRetrieveReq* pReq,
|
|||
}
|
||||
|
||||
int32_t streamProcessDispatchReq(SStreamTask* pTask, SStreamDispatchReq* pReq, SRpcMsg* pRsp) {
|
||||
qInfo("task %d receive dispatch req from node %d task %d", pTask->taskId, pReq->upstreamNodeId, pReq->upstreamTaskId);
|
||||
qDebug("task %d receive dispatch req from node %d task %d", pTask->taskId, pReq->upstreamNodeId,
|
||||
pReq->upstreamTaskId);
|
||||
|
||||
// 1. handle input
|
||||
streamTaskEnqueue(pTask, pReq, pRsp);
|
||||
|
|
|
@ -97,3 +97,29 @@ void streamDataSubmitRefDec(SStreamDataSubmit* pDataSubmit) {
|
|||
taosMemoryFree(pDataSubmit->dataRef);
|
||||
}
|
||||
}
|
||||
|
||||
int32_t streamAppendQueueItem(SStreamQueueItem* dst, SStreamQueueItem* elem) {
|
||||
ASSERT(elem);
|
||||
if (dst->type == elem->type && dst->type == STREAM_INPUT__DATA_BLOCK) {
|
||||
SStreamDataBlock* pBlock = (SStreamDataBlock*)dst;
|
||||
SStreamDataBlock* pBlockSrc = (SStreamDataBlock*)elem;
|
||||
taosArrayAddAll(pBlock->blocks, pBlockSrc->blocks);
|
||||
return 0;
|
||||
} else {
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
void streamFreeQitem(SStreamQueueItem* data) {
|
||||
int8_t type = data->type;
|
||||
if (type == STREAM_INPUT__TRIGGER) {
|
||||
blockDataDestroy(((SStreamTrigger*)data)->pBlock);
|
||||
taosFreeQitem(data);
|
||||
} else if (type == STREAM_INPUT__DATA_BLOCK || type == STREAM_INPUT__DATA_RETRIEVE) {
|
||||
taosArrayDestroyEx(((SStreamDataBlock*)data)->blocks, (FDelete)tDeleteSSDataBlock);
|
||||
taosFreeQitem(data);
|
||||
} else if (type == STREAM_INPUT__DATA_SUBMIT) {
|
||||
streamDataSubmitRefDec((SStreamDataSubmit*)data);
|
||||
taosFreeQitem(data);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -251,8 +251,8 @@ int32_t streamBuildDispatchMsg(SStreamTask* pTask, const SStreamDataBlock* data,
|
|||
ASSERT(vgId > 0 || vgId == SNODE_HANDLE);
|
||||
req.taskId = downstreamTaskId;
|
||||
|
||||
qInfo("dispatch from task %d (child id %d) to down stream task %d in vnode %d", pTask->taskId, pTask->selfChildId,
|
||||
downstreamTaskId, vgId);
|
||||
qDebug("dispatch from task %d (child id %d) to down stream task %d in vnode %d", pTask->taskId, pTask->selfChildId,
|
||||
downstreamTaskId, vgId);
|
||||
|
||||
// serialize
|
||||
int32_t tlen;
|
||||
|
@ -298,6 +298,7 @@ int32_t streamDispatch(SStreamTask* pTask, SMsgCb* pMsgCb) {
|
|||
|
||||
SStreamDataBlock* pBlock = streamQueueNextItem(pTask->outputQueue);
|
||||
if (pBlock == NULL) {
|
||||
qDebug("stream stop dispatching since no output: task %d", pTask->taskId);
|
||||
atomic_store_8(&pTask->outputStatus, TASK_OUTPUT_STATUS__NORMAL);
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -26,10 +26,12 @@ static int32_t streamTaskExecImpl(SStreamTask* pTask, void* data, SArray* pRes)
|
|||
} else if (pItem->type == STREAM_INPUT__DATA_SUBMIT) {
|
||||
ASSERT(pTask->isDataScan);
|
||||
SStreamDataSubmit* pSubmit = (SStreamDataSubmit*)data;
|
||||
qDebug("task %d %p set submit input %p %p %d", pTask->taskId, pTask, pSubmit, pSubmit->data, *pSubmit->dataRef);
|
||||
qSetStreamInput(exec, pSubmit->data, STREAM_INPUT__DATA_SUBMIT, false);
|
||||
} else if (pItem->type == STREAM_INPUT__DATA_BLOCK || pItem->type == STREAM_INPUT__DATA_RETRIEVE) {
|
||||
SStreamDataBlock* pBlock = (SStreamDataBlock*)data;
|
||||
SArray* blocks = pBlock->blocks;
|
||||
qDebug("task %d %p set ssdata input", pTask->taskId, pTask);
|
||||
qSetMultiStreamInput(exec, blocks->pData, blocks->size, STREAM_INPUT__DATA_BLOCK, false);
|
||||
} else if (pItem->type == STREAM_INPUT__DROP) {
|
||||
// TODO exec drop
|
||||
|
@ -73,10 +75,35 @@ static int32_t streamTaskExecImpl(SStreamTask* pTask, void* data, SArray* pRes)
|
|||
|
||||
static SArray* streamExecForQall(SStreamTask* pTask, SArray* pRes) {
|
||||
while (1) {
|
||||
void* data = streamQueueNextItem(pTask->inputQueue);
|
||||
int32_t cnt = 0;
|
||||
void* data = NULL;
|
||||
while (1) {
|
||||
SStreamQueueItem* qItem = streamQueueNextItem(pTask->inputQueue);
|
||||
if (qItem == NULL) {
|
||||
qDebug("stream exec over, queue empty");
|
||||
break;
|
||||
}
|
||||
if (data == NULL) {
|
||||
data = qItem;
|
||||
streamQueueProcessSuccess(pTask->inputQueue);
|
||||
continue;
|
||||
} else {
|
||||
if (streamAppendQueueItem(data, qItem) < 0) {
|
||||
streamQueueProcessFail(pTask->inputQueue);
|
||||
break;
|
||||
} else {
|
||||
cnt++;
|
||||
streamQueueProcessSuccess(pTask->inputQueue);
|
||||
taosArrayDestroy(((SStreamDataBlock*)qItem)->blocks);
|
||||
taosFreeQitem(qItem);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (data == NULL) break;
|
||||
|
||||
qDebug("stream task %d exec begin, batch msg: %d", pTask->taskId, cnt);
|
||||
streamTaskExecImpl(pTask, data, pRes);
|
||||
qDebug("stream task %d exec end", pTask->taskId);
|
||||
|
||||
if (pTask->taskStatus == TASK_STATUS__DROPPING) {
|
||||
taosArrayDestroyEx(pRes, (FDelete)tDeleteSSDataBlock);
|
||||
|
@ -93,27 +120,16 @@ static SArray* streamExecForQall(SStreamTask* pTask, SArray* pRes) {
|
|||
qRes->type = STREAM_INPUT__DATA_BLOCK;
|
||||
qRes->blocks = pRes;
|
||||
if (streamTaskOutput(pTask, qRes) < 0) {
|
||||
streamQueueProcessFail(pTask->inputQueue);
|
||||
/*streamQueueProcessFail(pTask->inputQueue);*/
|
||||
taosArrayDestroyEx(pRes, (FDelete)tDeleteSSDataBlock);
|
||||
taosFreeQitem(qRes);
|
||||
return NULL;
|
||||
}
|
||||
streamQueueProcessSuccess(pTask->inputQueue);
|
||||
/*streamQueueProcessSuccess(pTask->inputQueue);*/
|
||||
pRes = taosArrayInit(0, sizeof(SSDataBlock));
|
||||
}
|
||||
|
||||
int8_t type = ((SStreamQueueItem*)data)->type;
|
||||
if (type == STREAM_INPUT__TRIGGER) {
|
||||
blockDataDestroy(((SStreamTrigger*)data)->pBlock);
|
||||
taosFreeQitem(data);
|
||||
} else if (type == STREAM_INPUT__DATA_BLOCK || type == STREAM_INPUT__DATA_RETRIEVE) {
|
||||
taosArrayDestroyEx(((SStreamDataBlock*)data)->blocks, (FDelete)tDeleteSSDataBlock);
|
||||
taosFreeQitem(data);
|
||||
} else if (type == STREAM_INPUT__DATA_SUBMIT) {
|
||||
ASSERT(pTask->isDataScan);
|
||||
streamDataSubmitRefDec((SStreamDataSubmit*)data);
|
||||
taosFreeQitem(data);
|
||||
}
|
||||
streamFreeQitem(data);
|
||||
}
|
||||
return pRes;
|
||||
}
|
||||
|
@ -127,6 +143,7 @@ int32_t streamExec(SStreamTask* pTask, SMsgCb* pMsgCb) {
|
|||
atomic_val_compare_exchange_8(&pTask->execStatus, TASK_EXEC_STATUS__IDLE, TASK_EXEC_STATUS__EXECUTING);
|
||||
if (execStatus == TASK_EXEC_STATUS__IDLE) {
|
||||
// first run
|
||||
qDebug("stream exec, enter exec status");
|
||||
pRes = streamExecForQall(pTask, pRes);
|
||||
if (pRes == NULL) goto FAIL;
|
||||
|
||||
|
@ -134,11 +151,13 @@ int32_t streamExec(SStreamTask* pTask, SMsgCb* pMsgCb) {
|
|||
atomic_store_8(&pTask->execStatus, TASK_EXEC_STATUS__CLOSING);
|
||||
|
||||
// second run, make sure inputQ and qall are cleared
|
||||
qDebug("stream exec, enter closing status");
|
||||
pRes = streamExecForQall(pTask, pRes);
|
||||
if (pRes == NULL) goto FAIL;
|
||||
|
||||
taosArrayDestroyEx(pRes, (FDelete)tDeleteSSDataBlock);
|
||||
atomic_store_8(&pTask->execStatus, TASK_EXEC_STATUS__IDLE);
|
||||
qDebug("stream exec, return result");
|
||||
return 0;
|
||||
} else if (execStatus == TASK_EXEC_STATUS__CLOSING) {
|
||||
continue;
|
||||
|
|
|
@ -26,6 +26,7 @@ extern "C" {
|
|||
#include "syncInt.h"
|
||||
#include "syncMessage.h"
|
||||
#include "taosdef.h"
|
||||
#include "tskiplist.h"
|
||||
|
||||
typedef struct SSyncRaftEntry {
|
||||
uint32_t bytes;
|
||||
|
@ -58,29 +59,52 @@ void syncEntryLog(const SSyncRaftEntry* pObj);
|
|||
void syncEntryLog2(char* s, const SSyncRaftEntry* pObj);
|
||||
|
||||
//-----------------------------------
|
||||
typedef struct SRaftEntryCache {
|
||||
typedef struct SRaftEntryHashCache {
|
||||
SHashObj* pEntryHash;
|
||||
int32_t maxCount;
|
||||
int32_t currentCount;
|
||||
TdThreadMutex mutex;
|
||||
SSyncNode* pSyncNode;
|
||||
} SRaftEntryHashCache;
|
||||
|
||||
SRaftEntryHashCache* raftCacheCreate(SSyncNode* pSyncNode, int32_t maxCount);
|
||||
void raftCacheDestroy(SRaftEntryHashCache* pCache);
|
||||
int32_t raftCachePutEntry(struct SRaftEntryHashCache* pCache, SSyncRaftEntry* pEntry);
|
||||
int32_t raftCacheGetEntry(struct SRaftEntryHashCache* pCache, SyncIndex index, SSyncRaftEntry** ppEntry);
|
||||
int32_t raftCacheGetEntryP(struct SRaftEntryHashCache* pCache, SyncIndex index, SSyncRaftEntry** ppEntry);
|
||||
int32_t raftCacheDelEntry(struct SRaftEntryHashCache* pCache, SyncIndex index);
|
||||
int32_t raftCacheGetAndDel(struct SRaftEntryHashCache* pCache, SyncIndex index, SSyncRaftEntry** ppEntry);
|
||||
int32_t raftCacheClear(struct SRaftEntryHashCache* pCache);
|
||||
|
||||
cJSON* raftCache2Json(SRaftEntryHashCache* pObj);
|
||||
char* raftCache2Str(SRaftEntryHashCache* pObj);
|
||||
void raftCachePrint(SRaftEntryHashCache* pObj);
|
||||
void raftCachePrint2(char* s, SRaftEntryHashCache* pObj);
|
||||
void raftCacheLog(SRaftEntryHashCache* pObj);
|
||||
void raftCacheLog2(char* s, SRaftEntryHashCache* pObj);
|
||||
|
||||
//-----------------------------------
|
||||
typedef struct SRaftEntryCache {
|
||||
SSkipList* pSkipList;
|
||||
int32_t maxCount;
|
||||
int32_t currentCount;
|
||||
TdThreadMutex mutex;
|
||||
SSyncNode* pSyncNode;
|
||||
} SRaftEntryCache;
|
||||
|
||||
SRaftEntryCache* raftCacheCreate(SSyncNode* pSyncNode, int32_t maxCount);
|
||||
void raftCacheDestroy(SRaftEntryCache* pCache);
|
||||
int32_t raftCachePutEntry(struct SRaftEntryCache* pCache, SSyncRaftEntry* pEntry);
|
||||
int32_t raftCacheGetEntry(struct SRaftEntryCache* pCache, SyncIndex index, SSyncRaftEntry** ppEntry);
|
||||
int32_t raftCacheGetEntryP(struct SRaftEntryCache* pCache, SyncIndex index, SSyncRaftEntry** ppEntry);
|
||||
int32_t raftCacheDelEntry(struct SRaftEntryCache* pCache, SyncIndex index);
|
||||
int32_t raftCacheGetAndDel(struct SRaftEntryCache* pCache, SyncIndex index, SSyncRaftEntry** ppEntry);
|
||||
int32_t raftCacheClear(struct SRaftEntryCache* pCache);
|
||||
SRaftEntryCache* raftEntryCacheCreate(SSyncNode* pSyncNode, int32_t maxCount);
|
||||
void raftEntryCacheDestroy(SRaftEntryCache* pCache);
|
||||
int32_t raftEntryCachePutEntry(struct SRaftEntryCache* pCache, SSyncRaftEntry* pEntry);
|
||||
int32_t raftEntryCacheGetEntry(struct SRaftEntryCache* pCache, SyncIndex index, SSyncRaftEntry** ppEntry);
|
||||
int32_t raftEntryCacheGetEntryP(struct SRaftEntryCache* pCache, SyncIndex index, SSyncRaftEntry** ppEntry);
|
||||
int32_t raftEntryCacheClear(struct SRaftEntryCache* pCache, int32_t count);
|
||||
|
||||
cJSON* raftCache2Json(SRaftEntryCache* pObj);
|
||||
char* raftCache2Str(SRaftEntryCache* pObj);
|
||||
void raftCachePrint(SRaftEntryCache* pObj);
|
||||
void raftCachePrint2(char* s, SRaftEntryCache* pObj);
|
||||
void raftCacheLog(SRaftEntryCache* pObj);
|
||||
void raftCacheLog2(char* s, SRaftEntryCache* pObj);
|
||||
cJSON* raftEntryCache2Json(SRaftEntryCache* pObj);
|
||||
char* raftEntryCache2Str(SRaftEntryCache* pObj);
|
||||
void raftEntryCachePrint(SRaftEntryCache* pObj);
|
||||
void raftEntryCachePrint2(char* s, SRaftEntryCache* pObj);
|
||||
void raftEntryCacheLog(SRaftEntryCache* pObj);
|
||||
void raftEntryCacheLog2(char* s, SRaftEntryCache* pObj);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
|
|
@ -242,13 +242,13 @@ static int32_t syncIOStopInternal(SSyncIO *io) {
|
|||
}
|
||||
|
||||
static void *syncIOConsumerFunc(void *param) {
|
||||
SSyncIO * io = param;
|
||||
STaosQall *qall;
|
||||
SRpcMsg * pRpcMsg, rpcMsg;
|
||||
qall = taosAllocateQall();
|
||||
SSyncIO *io = param;
|
||||
STaosQall *qall = taosAllocateQall();
|
||||
SRpcMsg *pRpcMsg, rpcMsg;
|
||||
SQueueInfo qinfo = {0};
|
||||
|
||||
while (1) {
|
||||
int numOfMsgs = taosReadAllQitemsFromQset(io->pQset, qall, NULL, NULL);
|
||||
int numOfMsgs = taosReadAllQitemsFromQset(io->pQset, qall, &qinfo);
|
||||
sTrace("syncIOConsumerFunc %d msgs are received", numOfMsgs);
|
||||
if (numOfMsgs <= 0) {
|
||||
break;
|
||||
|
@ -369,6 +369,8 @@ static void *syncIOConsumerFunc(void *param) {
|
|||
|
||||
taosFreeQitem(pRpcMsg);
|
||||
}
|
||||
|
||||
taosUpdateItemSize(qinfo.queue, numOfMsgs);
|
||||
}
|
||||
|
||||
taosFreeQall(qall);
|
||||
|
|
|
@ -293,7 +293,7 @@ int32_t syncLeaderTransferTo(int64_t rid, SNodeInfo newLeader) {
|
|||
|
||||
int32_t syncNodeLeaderTransfer(SSyncNode* pSyncNode) {
|
||||
if (pSyncNode->peersNum == 0) {
|
||||
sError("only one replica, cannot leader transfer");
|
||||
sDebug("only one replica, cannot leader transfer");
|
||||
terrno = TSDB_CODE_SYN_ONE_REPLICA;
|
||||
return -1;
|
||||
}
|
||||
|
@ -307,7 +307,7 @@ int32_t syncNodeLeaderTransferTo(SSyncNode* pSyncNode, SNodeInfo newLeader) {
|
|||
int32_t ret = 0;
|
||||
|
||||
if (pSyncNode->replicaNum == 1) {
|
||||
sError("only one replica, cannot leader transfer");
|
||||
sDebug("only one replica, cannot leader transfer");
|
||||
terrno = TSDB_CODE_SYN_ONE_REPLICA;
|
||||
return -1;
|
||||
}
|
||||
|
@ -1055,19 +1055,12 @@ SSyncNode* syncNodeOpen(const SSyncInfo* pOldSyncInfo) {
|
|||
}
|
||||
|
||||
// tools
|
||||
pSyncNode->pSyncRespMgr = syncRespMgrCreate(pSyncNode, 0);
|
||||
pSyncNode->pSyncRespMgr = syncRespMgrCreate(pSyncNode, SYNC_RESP_TTL_MS);
|
||||
ASSERT(pSyncNode->pSyncRespMgr != NULL);
|
||||
|
||||
// restore state
|
||||
pSyncNode->restoreFinish = false;
|
||||
|
||||
// pSyncNode->pSnapshot = NULL;
|
||||
// if (pSyncNode->pFsm->FpGetSnapshotInfo != NULL) {
|
||||
// pSyncNode->pSnapshot = taosMemoryMalloc(sizeof(SSnapshot));
|
||||
// pSyncNode->pFsm->FpGetSnapshotInfo(pSyncNode->pFsm, pSyncNode->pSnapshot);
|
||||
// }
|
||||
// tsem_init(&(pSyncNode->restoreSem), 0, 0);
|
||||
|
||||
// snapshot senders
|
||||
for (int i = 0; i < TSDB_MAX_REPLICA; ++i) {
|
||||
SSyncSnapshotSender* pSender = snapshotSenderCreate(pSyncNode, i);
|
||||
|
|
|
@ -198,8 +198,8 @@ void syncEntryLog2(char* s, const SSyncRaftEntry* pObj) {
|
|||
}
|
||||
|
||||
//-----------------------------------
|
||||
SRaftEntryCache* raftCacheCreate(SSyncNode* pSyncNode, int32_t maxCount) {
|
||||
SRaftEntryCache* pCache = taosMemoryMalloc(sizeof(SRaftEntryCache));
|
||||
SRaftEntryHashCache* raftCacheCreate(SSyncNode* pSyncNode, int32_t maxCount) {
|
||||
SRaftEntryHashCache* pCache = taosMemoryMalloc(sizeof(SRaftEntryHashCache));
|
||||
if (pCache == NULL) {
|
||||
sError("vgId:%d raft cache create error", pSyncNode->vgId);
|
||||
return NULL;
|
||||
|
@ -220,7 +220,7 @@ SRaftEntryCache* raftCacheCreate(SSyncNode* pSyncNode, int32_t maxCount) {
|
|||
return pCache;
|
||||
}
|
||||
|
||||
void raftCacheDestroy(SRaftEntryCache* pCache) {
|
||||
void raftCacheDestroy(SRaftEntryHashCache* pCache) {
|
||||
if (pCache != NULL) {
|
||||
taosThreadMutexLock(&(pCache->mutex));
|
||||
taosHashCleanup(pCache->pEntryHash);
|
||||
|
@ -233,7 +233,7 @@ void raftCacheDestroy(SRaftEntryCache* pCache) {
|
|||
// success, return 1
|
||||
// max count, return 0
|
||||
// error, return -1
|
||||
int32_t raftCachePutEntry(struct SRaftEntryCache* pCache, SSyncRaftEntry* pEntry) {
|
||||
int32_t raftCachePutEntry(struct SRaftEntryHashCache* pCache, SSyncRaftEntry* pEntry) {
|
||||
taosThreadMutexLock(&(pCache->mutex));
|
||||
|
||||
if (pCache->currentCount >= pCache->maxCount) {
|
||||
|
@ -259,7 +259,7 @@ int32_t raftCachePutEntry(struct SRaftEntryCache* pCache, SSyncRaftEntry* pEntry
|
|||
// success, return 0
|
||||
// error, return -1
|
||||
// not exist, return -1, terrno = TSDB_CODE_WAL_LOG_NOT_EXIST
|
||||
int32_t raftCacheGetEntry(struct SRaftEntryCache* pCache, SyncIndex index, SSyncRaftEntry** ppEntry) {
|
||||
int32_t raftCacheGetEntry(struct SRaftEntryHashCache* pCache, SyncIndex index, SSyncRaftEntry** ppEntry) {
|
||||
if (ppEntry == NULL) {
|
||||
return -1;
|
||||
}
|
||||
|
@ -292,7 +292,7 @@ int32_t raftCacheGetEntry(struct SRaftEntryCache* pCache, SyncIndex index, SSync
|
|||
// success, return 0
|
||||
// error, return -1
|
||||
// not exist, return -1, terrno = TSDB_CODE_WAL_LOG_NOT_EXIST
|
||||
int32_t raftCacheGetEntryP(struct SRaftEntryCache* pCache, SyncIndex index, SSyncRaftEntry** ppEntry) {
|
||||
int32_t raftCacheGetEntryP(struct SRaftEntryHashCache* pCache, SyncIndex index, SSyncRaftEntry** ppEntry) {
|
||||
if (ppEntry == NULL) {
|
||||
return -1;
|
||||
}
|
||||
|
@ -321,7 +321,7 @@ int32_t raftCacheGetEntryP(struct SRaftEntryCache* pCache, SyncIndex index, SSyn
|
|||
return -1;
|
||||
}
|
||||
|
||||
int32_t raftCacheDelEntry(struct SRaftEntryCache* pCache, SyncIndex index) {
|
||||
int32_t raftCacheDelEntry(struct SRaftEntryHashCache* pCache, SyncIndex index) {
|
||||
taosThreadMutexLock(&(pCache->mutex));
|
||||
taosHashRemove(pCache->pEntryHash, &index, sizeof(index));
|
||||
--(pCache->currentCount);
|
||||
|
@ -329,7 +329,7 @@ int32_t raftCacheDelEntry(struct SRaftEntryCache* pCache, SyncIndex index) {
|
|||
return 0;
|
||||
}
|
||||
|
||||
int32_t raftCacheGetAndDel(struct SRaftEntryCache* pCache, SyncIndex index, SSyncRaftEntry** ppEntry) {
|
||||
int32_t raftCacheGetAndDel(struct SRaftEntryHashCache* pCache, SyncIndex index, SSyncRaftEntry** ppEntry) {
|
||||
if (ppEntry == NULL) {
|
||||
return -1;
|
||||
}
|
||||
|
@ -362,7 +362,7 @@ int32_t raftCacheGetAndDel(struct SRaftEntryCache* pCache, SyncIndex index, SSyn
|
|||
return -1;
|
||||
}
|
||||
|
||||
int32_t raftCacheClear(struct SRaftEntryCache* pCache) {
|
||||
int32_t raftCacheClear(struct SRaftEntryHashCache* pCache) {
|
||||
taosThreadMutexLock(&(pCache->mutex));
|
||||
taosHashClear(pCache->pEntryHash);
|
||||
pCache->currentCount = 0;
|
||||
|
@ -371,7 +371,7 @@ int32_t raftCacheClear(struct SRaftEntryCache* pCache) {
|
|||
}
|
||||
|
||||
//-----------------------------------
|
||||
cJSON* raftCache2Json(SRaftEntryCache* pCache) {
|
||||
cJSON* raftCache2Json(SRaftEntryHashCache* pCache) {
|
||||
char u64buf[128] = {0};
|
||||
cJSON* pRoot = cJSON_CreateObject();
|
||||
|
||||
|
@ -402,41 +402,283 @@ cJSON* raftCache2Json(SRaftEntryCache* pCache) {
|
|||
}
|
||||
|
||||
cJSON* pJson = cJSON_CreateObject();
|
||||
cJSON_AddItemToObject(pJson, "SRaftEntryCache", pRoot);
|
||||
cJSON_AddItemToObject(pJson, "SRaftEntryHashCache", pRoot);
|
||||
return pJson;
|
||||
}
|
||||
|
||||
char* raftCache2Str(SRaftEntryCache* pCache) {
|
||||
char* raftCache2Str(SRaftEntryHashCache* pCache) {
|
||||
cJSON* pJson = raftCache2Json(pCache);
|
||||
char* serialized = cJSON_Print(pJson);
|
||||
cJSON_Delete(pJson);
|
||||
return serialized;
|
||||
}
|
||||
|
||||
void raftCachePrint(SRaftEntryCache* pCache) {
|
||||
void raftCachePrint(SRaftEntryHashCache* pCache) {
|
||||
char* serialized = raftCache2Str(pCache);
|
||||
printf("raftCachePrint | len:%" PRIu64 " | %s \n", strlen(serialized), serialized);
|
||||
fflush(NULL);
|
||||
taosMemoryFree(serialized);
|
||||
}
|
||||
|
||||
void raftCachePrint2(char* s, SRaftEntryCache* pCache) {
|
||||
void raftCachePrint2(char* s, SRaftEntryHashCache* pCache) {
|
||||
char* serialized = raftCache2Str(pCache);
|
||||
printf("raftCachePrint2 | len:%" PRIu64 " | %s | %s \n", strlen(serialized), s, serialized);
|
||||
fflush(NULL);
|
||||
taosMemoryFree(serialized);
|
||||
}
|
||||
|
||||
void raftCacheLog(SRaftEntryCache* pCache) {
|
||||
void raftCacheLog(SRaftEntryHashCache* pCache) {
|
||||
char* serialized = raftCache2Str(pCache);
|
||||
sTrace("raftCacheLog | len:%" PRIu64 " | %s", strlen(serialized), serialized);
|
||||
taosMemoryFree(serialized);
|
||||
}
|
||||
|
||||
void raftCacheLog2(char* s, SRaftEntryCache* pCache) {
|
||||
void raftCacheLog2(char* s, SRaftEntryHashCache* pCache) {
|
||||
if (gRaftDetailLog) {
|
||||
char* serialized = raftCache2Str(pCache);
|
||||
sTraceLong("raftCacheLog2 | len:%" PRIu64 " | %s | %s", strlen(serialized), s, serialized);
|
||||
taosMemoryFree(serialized);
|
||||
}
|
||||
}
|
||||
|
||||
//-----------------------------------
|
||||
static char* keyFn(const void* pData) {
|
||||
SSyncRaftEntry* pEntry = (SSyncRaftEntry*)pData;
|
||||
return (char*)(&(pEntry->index));
|
||||
}
|
||||
|
||||
static int cmpFn(const void* p1, const void* p2) { return memcmp(p1, p2, sizeof(SyncIndex)); }
|
||||
|
||||
SRaftEntryCache* raftEntryCacheCreate(SSyncNode* pSyncNode, int32_t maxCount) {
|
||||
SRaftEntryCache* pCache = taosMemoryMalloc(sizeof(SRaftEntryCache));
|
||||
if (pCache == NULL) {
|
||||
sError("vgId:%d raft cache create error", pSyncNode->vgId);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
pCache->pSkipList =
|
||||
tSkipListCreate(MAX_SKIP_LIST_LEVEL, TSDB_DATA_TYPE_BINARY, sizeof(SyncIndex), cmpFn, SL_ALLOW_DUP_KEY, keyFn);
|
||||
if (pCache->pSkipList == NULL) {
|
||||
sError("vgId:%d raft cache create hash error", pSyncNode->vgId);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
taosThreadMutexInit(&(pCache->mutex), NULL);
|
||||
pCache->maxCount = maxCount;
|
||||
pCache->currentCount = 0;
|
||||
pCache->pSyncNode = pSyncNode;
|
||||
|
||||
return pCache;
|
||||
}
|
||||
|
||||
void raftEntryCacheDestroy(SRaftEntryCache* pCache) {
|
||||
if (pCache != NULL) {
|
||||
taosThreadMutexLock(&(pCache->mutex));
|
||||
tSkipListDestroy(pCache->pSkipList);
|
||||
taosThreadMutexUnlock(&(pCache->mutex));
|
||||
taosThreadMutexDestroy(&(pCache->mutex));
|
||||
taosMemoryFree(pCache);
|
||||
}
|
||||
}
|
||||
|
||||
// success, return 1
|
||||
// max count, return 0
|
||||
// error, return -1
|
||||
int32_t raftEntryCachePutEntry(struct SRaftEntryCache* pCache, SSyncRaftEntry* pEntry) {
|
||||
taosThreadMutexLock(&(pCache->mutex));
|
||||
|
||||
if (pCache->currentCount >= pCache->maxCount) {
|
||||
taosThreadMutexUnlock(&(pCache->mutex));
|
||||
return 0;
|
||||
}
|
||||
|
||||
SSkipListNode* pSkipListNode = tSkipListPut(pCache->pSkipList, pEntry);
|
||||
ASSERT(pSkipListNode != NULL);
|
||||
++(pCache->currentCount);
|
||||
|
||||
do {
|
||||
char eventLog[128];
|
||||
snprintf(eventLog, sizeof(eventLog), "raft cache add, type:%s,%d, type2:%s,%d, index:%" PRId64 ", bytes:%d",
|
||||
TMSG_INFO(pEntry->msgType), pEntry->msgType, TMSG_INFO(pEntry->originalRpcType), pEntry->originalRpcType,
|
||||
pEntry->index, pEntry->bytes);
|
||||
syncNodeEventLog(pCache->pSyncNode, eventLog);
|
||||
} while (0);
|
||||
|
||||
taosThreadMutexUnlock(&(pCache->mutex));
|
||||
return 1;
|
||||
}
|
||||
|
||||
// find one, return 1
|
||||
// not found, return 0
|
||||
// error, return -1
|
||||
int32_t raftEntryCacheGetEntry(struct SRaftEntryCache* pCache, SyncIndex index, SSyncRaftEntry** ppEntry) {
|
||||
ASSERT(ppEntry != NULL);
|
||||
SSyncRaftEntry* pEntry = NULL;
|
||||
int32_t code = raftEntryCacheGetEntryP(pCache, index, &pEntry);
|
||||
if (code == 1) {
|
||||
*ppEntry = taosMemoryMalloc(pEntry->bytes);
|
||||
memcpy(*ppEntry, pEntry, pEntry->bytes);
|
||||
} else {
|
||||
*ppEntry = NULL;
|
||||
}
|
||||
return code;
|
||||
}
|
||||
|
||||
// find one, return 1
|
||||
// not found, return 0
|
||||
// error, return -1
|
||||
int32_t raftEntryCacheGetEntryP(struct SRaftEntryCache* pCache, SyncIndex index, SSyncRaftEntry** ppEntry) {
|
||||
taosThreadMutexLock(&(pCache->mutex));
|
||||
|
||||
SyncIndex index2 = index;
|
||||
int32_t code = 0;
|
||||
|
||||
SArray* entryPArray = tSkipListGet(pCache->pSkipList, (char*)(&index2));
|
||||
int32_t arraySize = taosArrayGetSize(entryPArray);
|
||||
if (arraySize == 1) {
|
||||
SSkipListNode** ppNode = (SSkipListNode**)taosArrayGet(entryPArray, 0);
|
||||
ASSERT(*ppNode != NULL);
|
||||
*ppEntry = (SSyncRaftEntry*)SL_GET_NODE_DATA(*ppNode);
|
||||
code = 1;
|
||||
|
||||
} else if (arraySize == 0) {
|
||||
code = 0;
|
||||
|
||||
} else {
|
||||
ASSERT(0);
|
||||
|
||||
code = -1;
|
||||
}
|
||||
taosArrayDestroy(entryPArray);
|
||||
|
||||
taosThreadMutexUnlock(&(pCache->mutex));
|
||||
return code;
|
||||
}
|
||||
|
||||
// count = -1, clear all
|
||||
// count >= 0, clear count
|
||||
// return -1, error
|
||||
// return delete count
|
||||
int32_t raftEntryCacheClear(struct SRaftEntryCache* pCache, int32_t count) {
|
||||
taosThreadMutexLock(&(pCache->mutex));
|
||||
int32_t returnCnt = 0;
|
||||
|
||||
if (count == -1) {
|
||||
// clear all
|
||||
SSkipListIterator* pIter = tSkipListCreateIter(pCache->pSkipList);
|
||||
while (tSkipListIterNext(pIter)) {
|
||||
SSkipListNode* pNode = tSkipListIterGet(pIter);
|
||||
ASSERT(pNode != NULL);
|
||||
SSyncRaftEntry* pEntry = (SSyncRaftEntry*)SL_GET_NODE_DATA(pNode);
|
||||
syncEntryDestory(pEntry);
|
||||
++returnCnt;
|
||||
}
|
||||
tSkipListDestroyIter(pIter);
|
||||
|
||||
tSkipListDestroy(pCache->pSkipList);
|
||||
pCache->pSkipList =
|
||||
tSkipListCreate(MAX_SKIP_LIST_LEVEL, TSDB_DATA_TYPE_BINARY, sizeof(SyncIndex), cmpFn, SL_ALLOW_DUP_KEY, keyFn);
|
||||
ASSERT(pCache->pSkipList != NULL);
|
||||
|
||||
} else {
|
||||
// clear count
|
||||
int i = 0;
|
||||
SSkipListIterator* pIter = tSkipListCreateIter(pCache->pSkipList);
|
||||
SArray* delNodeArray = taosArrayInit(0, sizeof(SSkipListNode*));
|
||||
|
||||
// free entry
|
||||
while (tSkipListIterNext(pIter)) {
|
||||
SSkipListNode* pNode = tSkipListIterGet(pIter);
|
||||
ASSERT(pNode != NULL);
|
||||
if (i++ >= count) {
|
||||
break;
|
||||
}
|
||||
|
||||
// sDebug("push pNode:%p", pNode);
|
||||
taosArrayPush(delNodeArray, &pNode);
|
||||
++returnCnt;
|
||||
SSyncRaftEntry* pEntry = (SSyncRaftEntry*)SL_GET_NODE_DATA(pNode);
|
||||
syncEntryDestory(pEntry);
|
||||
}
|
||||
tSkipListDestroyIter(pIter);
|
||||
|
||||
// delete skiplist node
|
||||
int32_t arraySize = taosArrayGetSize(delNodeArray);
|
||||
for (int32_t i = 0; i < arraySize; ++i) {
|
||||
SSkipListNode** ppNode = taosArrayGet(delNodeArray, i);
|
||||
// sDebug("get pNode:%p", *ppNode);
|
||||
tSkipListRemoveNode(pCache->pSkipList, *ppNode);
|
||||
}
|
||||
taosArrayDestroy(delNodeArray);
|
||||
}
|
||||
|
||||
pCache->currentCount -= returnCnt;
|
||||
taosThreadMutexUnlock(&(pCache->mutex));
|
||||
return returnCnt;
|
||||
}
|
||||
|
||||
cJSON* raftEntryCache2Json(SRaftEntryCache* pCache) {
|
||||
char u64buf[128] = {0};
|
||||
cJSON* pRoot = cJSON_CreateObject();
|
||||
|
||||
if (pCache != NULL) {
|
||||
taosThreadMutexLock(&(pCache->mutex));
|
||||
|
||||
snprintf(u64buf, sizeof(u64buf), "%p", pCache->pSyncNode);
|
||||
cJSON_AddStringToObject(pRoot, "pSyncNode", u64buf);
|
||||
cJSON_AddNumberToObject(pRoot, "currentCount", pCache->currentCount);
|
||||
cJSON_AddNumberToObject(pRoot, "maxCount", pCache->maxCount);
|
||||
cJSON* pEntries = cJSON_CreateArray();
|
||||
cJSON_AddItemToObject(pRoot, "entries", pEntries);
|
||||
|
||||
SSkipListIterator* pIter = tSkipListCreateIter(pCache->pSkipList);
|
||||
while (tSkipListIterNext(pIter)) {
|
||||
SSkipListNode* pNode = tSkipListIterGet(pIter);
|
||||
ASSERT(pNode != NULL);
|
||||
SSyncRaftEntry* pEntry = (SSyncRaftEntry*)SL_GET_NODE_DATA(pNode);
|
||||
cJSON_AddItemToArray(pEntries, syncEntry2Json(pEntry));
|
||||
}
|
||||
tSkipListDestroyIter(pIter);
|
||||
|
||||
taosThreadMutexUnlock(&(pCache->mutex));
|
||||
}
|
||||
|
||||
cJSON* pJson = cJSON_CreateObject();
|
||||
cJSON_AddItemToObject(pJson, "SRaftEntryCache", pRoot);
|
||||
return pJson;
|
||||
}
|
||||
|
||||
char* raftEntryCache2Str(SRaftEntryCache* pObj) {
|
||||
cJSON* pJson = raftEntryCache2Json(pObj);
|
||||
char* serialized = cJSON_Print(pJson);
|
||||
cJSON_Delete(pJson);
|
||||
return serialized;
|
||||
}
|
||||
|
||||
void raftEntryCachePrint(SRaftEntryCache* pObj) {
|
||||
char* serialized = raftEntryCache2Str(pObj);
|
||||
printf("raftEntryCachePrint | len:%" PRIu64 " | %s \n", strlen(serialized), serialized);
|
||||
fflush(NULL);
|
||||
taosMemoryFree(serialized);
|
||||
}
|
||||
|
||||
void raftEntryCachePrint2(char* s, SRaftEntryCache* pObj) {
|
||||
char* serialized = raftEntryCache2Str(pObj);
|
||||
printf("raftEntryCachePrint2 | len:%" PRIu64 " | %s | %s \n", strlen(serialized), s, serialized);
|
||||
fflush(NULL);
|
||||
taosMemoryFree(serialized);
|
||||
}
|
||||
|
||||
void raftEntryCacheLog(SRaftEntryCache* pObj) {
|
||||
char* serialized = raftEntryCache2Str(pObj);
|
||||
sTrace("raftEntryCacheLog | len:%" PRIu64 " | %s", strlen(serialized), serialized);
|
||||
taosMemoryFree(serialized);
|
||||
}
|
||||
|
||||
void raftEntryCacheLog2(char* s, SRaftEntryCache* pObj) {
|
||||
if (gRaftDetailLog) {
|
||||
char* serialized = raftEntryCache2Str(pObj);
|
||||
sTraceLong("raftEntryCacheLog2 | len:%" PRIu64 " | %s | %s", strlen(serialized), s, serialized);
|
||||
taosMemoryFree(serialized);
|
||||
}
|
||||
}
|
|
@ -122,54 +122,45 @@ void syncRespCleanByTTL(SSyncRespMgr *pObj, int64_t ttl) {
|
|||
int cnt = 0;
|
||||
SSyncNode *pSyncNode = pObj->data;
|
||||
|
||||
SArray *delIndexArray = taosArrayInit(0, sizeof(SyncIndex));
|
||||
SArray *delIndexArray = taosArrayInit(0, sizeof(uint64_t));
|
||||
ASSERT(delIndexArray != NULL);
|
||||
|
||||
while (pStub) {
|
||||
size_t len;
|
||||
void * key = taosHashGetKey(pStub, &len);
|
||||
SyncIndex *pIndex = (SyncIndex *)key;
|
||||
size_t len;
|
||||
void * key = taosHashGetKey(pStub, &len);
|
||||
uint64_t *pSeqNum = (uint64_t *)key;
|
||||
|
||||
int64_t nowMS = taosGetTimestampMs();
|
||||
if (nowMS - pStub->createTime > ttl) {
|
||||
taosArrayPush(delIndexArray, pIndex);
|
||||
taosArrayPush(delIndexArray, pSeqNum);
|
||||
cnt++;
|
||||
|
||||
SSyncRaftEntry *pEntry = NULL;
|
||||
int32_t code = 0;
|
||||
if (pSyncNode->pLogStore != NULL) {
|
||||
code = pSyncNode->pLogStore->syncLogGetEntry(pSyncNode->pLogStore, *pIndex, &pEntry);
|
||||
if (code == 0 && pEntry != NULL) {
|
||||
SFsmCbMeta cbMeta = {0};
|
||||
cbMeta.index = pEntry->index;
|
||||
cbMeta.lastConfigIndex = syncNodeGetSnapshotConfigIndex(pSyncNode, cbMeta.index);
|
||||
cbMeta.isWeak = pEntry->isWeak;
|
||||
cbMeta.code = TSDB_CODE_SYN_TIMEOUT;
|
||||
cbMeta.state = pSyncNode->state;
|
||||
cbMeta.seqNum = pEntry->seqNum;
|
||||
cbMeta.term = pEntry->term;
|
||||
cbMeta.currentTerm = pSyncNode->pRaftStore->currentTerm;
|
||||
cbMeta.flag = 0;
|
||||
SFsmCbMeta cbMeta = {0};
|
||||
cbMeta.index = SYNC_INDEX_INVALID;
|
||||
cbMeta.lastConfigIndex = SYNC_INDEX_INVALID;
|
||||
cbMeta.isWeak = false;
|
||||
cbMeta.code = TSDB_CODE_SYN_TIMEOUT;
|
||||
cbMeta.state = pSyncNode->state;
|
||||
cbMeta.seqNum = *pSeqNum;
|
||||
cbMeta.term = SYNC_TERM_INVALID;
|
||||
cbMeta.currentTerm = pSyncNode->pRaftStore->currentTerm;
|
||||
cbMeta.flag = 0;
|
||||
|
||||
SRpcMsg rpcMsg = pStub->rpcMsg;
|
||||
rpcMsg.pCont = rpcMallocCont(pEntry->dataLen);
|
||||
memcpy(rpcMsg.pCont, pEntry->data, pEntry->dataLen);
|
||||
pSyncNode->pFsm->FpCommitCb(pSyncNode->pFsm, &rpcMsg, cbMeta);
|
||||
|
||||
syncEntryDestory(pEntry);
|
||||
}
|
||||
}
|
||||
pStub->rpcMsg.pCont = NULL;
|
||||
pStub->rpcMsg.contLen = 0;
|
||||
pSyncNode->pFsm->FpCommitCb(pSyncNode->pFsm, &(pStub->rpcMsg), cbMeta);
|
||||
}
|
||||
|
||||
pStub = (SRespStub *)taosHashIterate(pObj->pRespHash, pStub);
|
||||
}
|
||||
|
||||
int32_t arraySize = taosArrayGetSize(delIndexArray);
|
||||
sDebug("vgId:%d, resp clean by ttl, cnt:%d, array-size:%d", pSyncNode->vgId, cnt, arraySize);
|
||||
sDebug("vgId:%d, resp mgr clean by ttl, cnt:%d, array-size:%d", pSyncNode->vgId, cnt, arraySize);
|
||||
|
||||
for (int32_t i = 0; i < arraySize; ++i) {
|
||||
SyncIndex *pIndex = taosArrayGet(delIndexArray, i);
|
||||
taosHashRemove(pObj->pRespHash, pIndex, sizeof(SyncIndex));
|
||||
uint64_t *pSeqNum = taosArrayGet(delIndexArray, i);
|
||||
taosHashRemove(pObj->pRespHash, pSeqNum, sizeof(uint64_t));
|
||||
sDebug("vgId:%d, resp mgr clean by ttl, seq:%d", pSyncNode->vgId, *pSeqNum);
|
||||
}
|
||||
taosArrayDestroy(delIndexArray);
|
||||
}
|
||||
|
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue