Merge remote-tracking branch 'origin/3.0' into feature/qnode
This commit is contained in:
commit
a82fc113fe
|
@ -89,6 +89,7 @@ tests/examples/JDBC/JDBCDemo/.project
|
|||
tests/examples/JDBC/JDBCDemo/.settings/
|
||||
source/libs/parser/inc/sql.*
|
||||
tests/script/tmqResult.txt
|
||||
tests/tmqResult.txt
|
||||
|
||||
# Emacs
|
||||
# -*- mode: gitignore; -*-
|
||||
|
|
|
@ -116,7 +116,7 @@ typedef struct SParsedDataColInfo {
|
|||
uint16_t allNullLen; // TODO: get from STSchema(base on SDataRow)
|
||||
uint16_t extendedVarLen;
|
||||
uint16_t boundNullLen; // bound column len with all NULL value(without VarDataOffsetT/SColIdx part)
|
||||
int32_t * boundedColumns; // bound column idx according to schema
|
||||
int32_t *boundColumns; // bound column idx according to schema
|
||||
SBoundColumn * cols;
|
||||
SBoundIdxInfo *colIdxInfo;
|
||||
int8_t orderStatus; // bound columns
|
||||
|
@ -125,7 +125,7 @@ typedef struct SParsedDataColInfo {
|
|||
#define IS_DATA_COL_ORDERED(spd) ((spd->orderStatus) == (int8_t)ORDER_STATUS_ORDERED)
|
||||
|
||||
typedef struct {
|
||||
uint8_t memRowType; // default is 0, that is SDataRow
|
||||
uint8_t rowType; // default is 0, that is SDataRow
|
||||
int32_t rowSize;
|
||||
} SMemRowBuilder;
|
||||
|
||||
|
@ -137,17 +137,17 @@ void destroyMemRowBuilder(SMemRowBuilder *pBuilder);
|
|||
/**
|
||||
* @brief
|
||||
*
|
||||
* @param memRowType
|
||||
* @param rowType
|
||||
* @param spd
|
||||
* @param idx the absolute bound index of columns
|
||||
* @return FORCE_INLINE
|
||||
*/
|
||||
static FORCE_INLINE void tscGetMemRowAppendInfo(SSchema *pSchema, uint8_t memRowType, SParsedDataColInfo *spd,
|
||||
int32_t idx, int32_t *toffset, int16_t *colId) {
|
||||
static FORCE_INLINE void tscGetSTSRowAppendInfo(SSchema *pSchema, uint8_t rowType, SParsedDataColInfo *spd, int32_t idx,
|
||||
int32_t *toffset, int16_t *colId) {
|
||||
int32_t schemaIdx = 0;
|
||||
if (IS_DATA_COL_ORDERED(spd)) {
|
||||
schemaIdx = spd->boundedColumns[idx];
|
||||
if (isDataRowT(memRowType)) {
|
||||
schemaIdx = spd->boundColumns[idx];
|
||||
if (isDataRowT(rowType)) {
|
||||
*toffset = (spd->cols + schemaIdx)->toffset; // the offset of firstPart
|
||||
} else {
|
||||
*toffset = idx * sizeof(SColIdx); // the offset of SColIdx
|
||||
|
@ -155,7 +155,7 @@ static FORCE_INLINE void tscGetMemRowAppendInfo(SSchema *pSchema, uint8_t memRow
|
|||
} else {
|
||||
ASSERT(idx == (spd->colIdxInfo + idx)->boundIdx);
|
||||
schemaIdx = (spd->colIdxInfo + idx)->schemaColIdx;
|
||||
if (isDataRowT(memRowType)) {
|
||||
if (isDataRowT(rowType)) {
|
||||
*toffset = (spd->cols + schemaIdx)->toffset;
|
||||
} else {
|
||||
*toffset = ((spd->colIdxInfo + idx)->finalIdx) * sizeof(SColIdx);
|
||||
|
|
|
@ -428,7 +428,7 @@ int tsParseOneRow(char **str, STableDataBlocks *pDataBlocks, int16_t timePrec, i
|
|||
// 1. set the parsed value from sql string
|
||||
for (int i = 0; i < spd->numOfBound; ++i) {
|
||||
// the start position in data block buffer of current value in sql
|
||||
int32_t colIndex = spd->boundedColumns[i];
|
||||
int32_t colIndex = spd->boundColumns[i];
|
||||
|
||||
char *start = row + spd->cols[colIndex].offset;
|
||||
|
||||
|
@ -495,7 +495,7 @@ int tsParseOneRow(char **str, STableDataBlocks *pDataBlocks, int16_t timePrec, i
|
|||
bool isPrimaryKey = (colIndex == PRIMARYKEY_TIMESTAMP_COL_INDEX);
|
||||
int32_t toffset = -1;
|
||||
int16_t colId = -1;
|
||||
tscGetMemRowAppendInfo(schema, pBuilder->memRowType, spd, i, &toffset, &colId);
|
||||
tscGetSTSRowAppendInfo(schema, pBuilder->memRowType, spd, i, &toffset, &colId);
|
||||
|
||||
int32_t ret =
|
||||
tsParseOneColumnKV(pSchema, &sToken, row, pInsertParam->msg, str, isPrimaryKey, timePrec, toffset, colId);
|
||||
|
@ -630,7 +630,7 @@ void tscSetBoundColumnInfo(SParsedDataColInfo *pColInfo, SSchema *pSchema, int32
|
|||
pColInfo->numOfCols = numOfCols;
|
||||
pColInfo->numOfBound = numOfCols;
|
||||
pColInfo->orderStatus = ORDER_STATUS_ORDERED; // default is ORDERED for non-bound mode
|
||||
pColInfo->boundedColumns = calloc(pColInfo->numOfCols, sizeof(int32_t));
|
||||
pColInfo->boundColumns = calloc(pColInfo->numOfCols, sizeof(int32_t));
|
||||
pColInfo->cols = calloc(pColInfo->numOfCols, sizeof(SBoundColumn));
|
||||
pColInfo->colIdxInfo = NULL;
|
||||
pColInfo->flen = 0;
|
||||
|
@ -656,7 +656,7 @@ void tscSetBoundColumnInfo(SParsedDataColInfo *pColInfo, SSchema *pSchema, int32
|
|||
default:
|
||||
break;
|
||||
}
|
||||
pColInfo->boundedColumns[i] = i;
|
||||
pColInfo->boundColumns[i] = i;
|
||||
}
|
||||
pColInfo->allNullLen += pColInfo->flen;
|
||||
pColInfo->boundNullLen = pColInfo->allNullLen; // default set allNullLen
|
||||
|
@ -991,7 +991,7 @@ static int32_t tscCheckIfCreateTable(char **sqlstr, SSqlObj *pSql, char** boundC
|
|||
}
|
||||
|
||||
for (int i = 0; i < spd.numOfBound; ++i) {
|
||||
SSchema* pSchema = &pTagSchema[spd.boundedColumns[i]];
|
||||
SSchema *pSchema = &pTagSchema[spd.boundColumns[i]];
|
||||
|
||||
index = 0;
|
||||
sToken = tStrGetToken(sql, &index, true);
|
||||
|
@ -1158,7 +1158,7 @@ static int32_t parseBoundColumns(SInsertStatementParam *pInsertParam, SParsedDat
|
|||
|
||||
pColInfo->numOfBound = 0;
|
||||
pColInfo->boundNullLen = 0;
|
||||
memset(pColInfo->boundedColumns, 0, sizeof(int32_t) * nCols);
|
||||
memset(pColInfo->boundColumns, 0, sizeof(int32_t) * nCols);
|
||||
for (int32_t i = 0; i < nCols; ++i) {
|
||||
pColInfo->cols[i].valStat = VAL_STAT_NONE;
|
||||
}
|
||||
|
@ -1205,7 +1205,7 @@ static int32_t parseBoundColumns(SInsertStatementParam *pInsertParam, SParsedDat
|
|||
}
|
||||
|
||||
pColInfo->cols[t].valStat = VAL_STAT_HAS;
|
||||
pColInfo->boundedColumns[pColInfo->numOfBound] = t;
|
||||
pColInfo->boundColumns[pColInfo->numOfBound] = t;
|
||||
++pColInfo->numOfBound;
|
||||
switch (pSchema[t].type) {
|
||||
case TSDB_DATA_TYPE_BINARY:
|
||||
|
@ -1239,7 +1239,7 @@ static int32_t parseBoundColumns(SInsertStatementParam *pInsertParam, SParsedDat
|
|||
}
|
||||
|
||||
pColInfo->cols[t].valStat = VAL_STAT_HAS;
|
||||
pColInfo->boundedColumns[pColInfo->numOfBound] = t;
|
||||
pColInfo->boundColumns[pColInfo->numOfBound] = t;
|
||||
++pColInfo->numOfBound;
|
||||
switch (pSchema[t].type) {
|
||||
case TSDB_DATA_TYPE_BINARY:
|
||||
|
@ -1279,7 +1279,7 @@ static int32_t parseBoundColumns(SInsertStatementParam *pInsertParam, SParsedDat
|
|||
}
|
||||
SBoundIdxInfo *pColIdx = pColInfo->colIdxInfo;
|
||||
for (uint16_t i = 0; i < pColInfo->numOfBound; ++i) {
|
||||
pColIdx[i].schemaColIdx = (uint16_t)pColInfo->boundedColumns[i];
|
||||
pColIdx[i].schemaColIdx = (uint16_t)pColInfo->boundColumns[i];
|
||||
pColIdx[i].boundIdx = i;
|
||||
}
|
||||
qsort(pColIdx, pColInfo->numOfBound, sizeof(SBoundIdxInfo), schemaIdxCompar);
|
||||
|
@ -1289,7 +1289,7 @@ static int32_t parseBoundColumns(SInsertStatementParam *pInsertParam, SParsedDat
|
|||
qsort(pColIdx, pColInfo->numOfBound, sizeof(SBoundIdxInfo), boundIdxCompar);
|
||||
}
|
||||
|
||||
memset(&pColInfo->boundedColumns[pColInfo->numOfBound], 0,
|
||||
memset(&pColInfo->boundColumns[pColInfo->numOfBound], 0,
|
||||
sizeof(int32_t) * (pColInfo->numOfCols - pColInfo->numOfBound));
|
||||
|
||||
return TSDB_CODE_SUCCESS;
|
||||
|
|
|
@ -1554,7 +1554,7 @@ void tscFreeSqlObj(SSqlObj* pSql) {
|
|||
}
|
||||
|
||||
void tscDestroyBoundColumnInfo(SParsedDataColInfo* pColInfo) {
|
||||
tfree(pColInfo->boundedColumns);
|
||||
tfree(pColInfo->boundColumns);
|
||||
tfree(pColInfo->cols);
|
||||
tfree(pColInfo->colIdxInfo);
|
||||
}
|
||||
|
|
|
@ -44,7 +44,7 @@ int32_t init_env() {
|
|||
|
||||
pRes = taos_query(pConn, "create stable if not exists st1 (ts timestamp, k int) tags(a int)");
|
||||
if (taos_errno(pRes) != 0) {
|
||||
printf("failed to create super table 123_$^), reason:%s\n", taos_errstr(pRes));
|
||||
printf("failed to create super table st1, reason:%s\n", taos_errstr(pRes));
|
||||
return -1;
|
||||
}
|
||||
taos_free_result(pRes);
|
||||
|
|
|
@ -213,9 +213,10 @@ typedef void(tmq_commit_cb(tmq_t *, tmq_resp_err_t, tmq_topic_vgroup_list_t *, v
|
|||
|
||||
DLL_EXPORT tmq_list_t *tmq_list_new();
|
||||
DLL_EXPORT int32_t tmq_list_append(tmq_list_t *, const char *);
|
||||
DLL_EXPORT void tmq_list_destroy(tmq_list_t *);
|
||||
|
||||
DLL_EXPORT tmq_t *tmq_consumer_new(void *conn, tmq_conf_t *conf, char *errstr, int32_t errstrLen);
|
||||
DLL_EXPORT void tmq_message_destroy(tmq_message_t *tmq_message);
|
||||
DLL_EXPORT tmq_t *tmq_consumer_new1(tmq_conf_t *conf, char *errstr, int32_t errstrLen);
|
||||
DLL_EXPORT const char *tmq_err2str(tmq_resp_err_t);
|
||||
|
||||
/* ------------------------TMQ CONSUMER INTERFACE------------------------ */
|
||||
|
@ -244,8 +245,8 @@ enum tmq_conf_res_t {
|
|||
typedef enum tmq_conf_res_t tmq_conf_res_t;
|
||||
|
||||
DLL_EXPORT tmq_conf_t *tmq_conf_new();
|
||||
DLL_EXPORT void tmq_conf_destroy(tmq_conf_t *conf);
|
||||
DLL_EXPORT tmq_conf_res_t tmq_conf_set(tmq_conf_t *conf, const char *key, const char *value);
|
||||
DLL_EXPORT void tmq_conf_destroy(tmq_conf_t *conf);
|
||||
DLL_EXPORT void tmq_conf_set_offset_commit_cb(tmq_conf_t *conf, tmq_commit_cb *cb);
|
||||
|
||||
// temporary used function for demo only
|
||||
|
@ -256,6 +257,8 @@ int32_t tmqGetSkipLogNum(tmq_message_t *tmq_message);
|
|||
|
||||
DLL_EXPORT TAOS_ROW tmq_get_row(tmq_message_t *message);
|
||||
DLL_EXPORT char *tmq_get_topic_name(tmq_message_t *message);
|
||||
DLL_EXPORT void *tmq_get_topic_schema(tmq_t *tmq, const char *topic);
|
||||
DLL_EXPORT void tmq_message_destroy(tmq_message_t *tmq_message);
|
||||
|
||||
/* --------------------TMPORARY INTERFACE FOR TESTING--------------------- */
|
||||
DLL_EXPORT TAOS_RES *tmq_create_topic(TAOS *taos, const char *name, const char *sql, int sqlLen);
|
||||
|
|
|
@ -127,7 +127,7 @@ static FORCE_INLINE int32_t tEncodeSMqPollRsp(void** buf, const SMqPollRsp* pRsp
|
|||
tlen += taosEncodeFixedI32(buf, pRsp->skipLogNum);
|
||||
tlen += taosEncodeFixedI32(buf, pRsp->numOfTopics);
|
||||
if (pRsp->numOfTopics == 0) return tlen;
|
||||
tlen += tEncodeSSchemaWrapper(buf, pRsp->schema);
|
||||
tlen += taosEncodeSSchemaWrapper(buf, pRsp->schema);
|
||||
if (pRsp->pBlockData) {
|
||||
sz = taosArrayGetSize(pRsp->pBlockData);
|
||||
}
|
||||
|
@ -149,7 +149,7 @@ static FORCE_INLINE void* tDecodeSMqPollRsp(void* buf, SMqPollRsp* pRsp) {
|
|||
if (pRsp->numOfTopics == 0) return buf;
|
||||
pRsp->schema = (SSchemaWrapper*)taosMemoryCalloc(1, sizeof(SSchemaWrapper));
|
||||
if (pRsp->schema == NULL) return NULL;
|
||||
buf = tDecodeSSchemaWrapper(buf, pRsp->schema);
|
||||
buf = taosDecodeSSchemaWrapper(buf, pRsp->schema);
|
||||
buf = taosDecodeFixedI32(buf, &sz);
|
||||
pRsp->pBlockData = taosArrayInit(sz, sizeof(SSDataBlock));
|
||||
for (int32_t i = 0; i < sz; i++) {
|
||||
|
|
|
@ -59,12 +59,15 @@ extern "C" {
|
|||
} while (0);
|
||||
|
||||
// ----------------- TSDB COLUMN DEFINITION
|
||||
#pragma pack(push, 1)
|
||||
typedef struct {
|
||||
int8_t type; // Column type
|
||||
col_id_t colId; // column ID(start from PRIMARYKEY_TIMESTAMP_COL_ID(1))
|
||||
int16_t bytes; // column bytes (restore to int16_t in case of misuse)
|
||||
uint16_t offset; // point offset in STpRow after the header part.
|
||||
int32_t type : 8; // column type
|
||||
int32_t bytes : 24; // column bytes (restore to int32_t in case of misuse)
|
||||
int32_t sma : 8; // block SMA: 0, no SMA, 1, sum/min/max, 2, ...
|
||||
int32_t offset : 24; // point offset in STpRow after the header part.
|
||||
} STColumn;
|
||||
#pragma pack(pop)
|
||||
|
||||
#define colType(col) ((col)->type)
|
||||
#define colColId(col) ((col)->colId)
|
||||
|
@ -136,7 +139,7 @@ typedef struct {
|
|||
int32_t tdInitTSchemaBuilder(STSchemaBuilder *pBuilder, int32_t version);
|
||||
void tdDestroyTSchemaBuilder(STSchemaBuilder *pBuilder);
|
||||
void tdResetTSchemaBuilder(STSchemaBuilder *pBuilder, int32_t version);
|
||||
int32_t tdAddColToSchema(STSchemaBuilder *pBuilder, int8_t type, int16_t colId, int16_t bytes);
|
||||
int32_t tdAddColToSchema(STSchemaBuilder *pBuilder, int8_t type, col_id_t colId, col_bytes_t bytes);
|
||||
STSchema *tdGetSchemaFromBuilder(STSchemaBuilder *pBuilder);
|
||||
|
||||
// ----------------- Semantic timestamp key definition
|
||||
|
@ -590,7 +593,7 @@ void tdDestroyKVRowBuilder(SKVRowBuilder *pBuilder);
|
|||
void tdResetKVRowBuilder(SKVRowBuilder *pBuilder);
|
||||
SKVRow tdGetKVRowFromBuilder(SKVRowBuilder *pBuilder);
|
||||
|
||||
static FORCE_INLINE int32_t tdAddColToKVRow(SKVRowBuilder *pBuilder, int16_t colId, int8_t type, const void *value) {
|
||||
static FORCE_INLINE int32_t tdAddColToKVRow(SKVRowBuilder *pBuilder, col_id_t colId, int8_t type, const void *value) {
|
||||
if (pBuilder->nCols >= pBuilder->tCols) {
|
||||
pBuilder->tCols *= 2;
|
||||
SColIdx *pColIdx = (SColIdx *)taosMemoryRealloc((void *)(pBuilder->pColIdx), sizeof(SColIdx) * pBuilder->tCols);
|
||||
|
|
|
@ -208,11 +208,11 @@ typedef struct {
|
|||
typedef struct SSubmitBlk {
|
||||
int64_t uid; // table unique id
|
||||
int64_t suid; // stable id
|
||||
int32_t padding; // TODO just for padding here
|
||||
int32_t sversion; // data schema version
|
||||
int32_t dataLen; // data part length, not including the SSubmitBlk head
|
||||
int32_t schemaLen; // schema length, if length is 0, no schema exists
|
||||
int16_t numOfRows; // total number of rows in current submit block
|
||||
int16_t padding; // TODO just for padding here
|
||||
char data[];
|
||||
} SSubmitBlk;
|
||||
|
||||
|
@ -260,7 +260,7 @@ typedef struct {
|
|||
|
||||
typedef struct SSchema {
|
||||
int8_t type;
|
||||
int32_t colId;
|
||||
col_id_t colId;
|
||||
int32_t bytes;
|
||||
char name[TSDB_COL_NAME_LEN];
|
||||
} SSchema;
|
||||
|
@ -438,7 +438,7 @@ typedef struct {
|
|||
*/
|
||||
typedef struct {
|
||||
union {
|
||||
int16_t colId;
|
||||
col_id_t colId;
|
||||
int16_t slotId;
|
||||
};
|
||||
|
||||
|
@ -1901,7 +1901,7 @@ static FORCE_INLINE int32_t taosEncodeSSchema(void** buf, const SSchema* pSchema
|
|||
int32_t tlen = 0;
|
||||
tlen += taosEncodeFixedI8(buf, pSchema->type);
|
||||
tlen += taosEncodeFixedI32(buf, pSchema->bytes);
|
||||
tlen += taosEncodeFixedI32(buf, pSchema->colId);
|
||||
tlen += taosEncodeFixedI16(buf, pSchema->colId);
|
||||
tlen += taosEncodeString(buf, pSchema->name);
|
||||
return tlen;
|
||||
}
|
||||
|
@ -1909,7 +1909,7 @@ static FORCE_INLINE int32_t taosEncodeSSchema(void** buf, const SSchema* pSchema
|
|||
static FORCE_INLINE void* taosDecodeSSchema(void* buf, SSchema* pSchema) {
|
||||
buf = taosDecodeFixedI8(buf, &pSchema->type);
|
||||
buf = taosDecodeFixedI32(buf, &pSchema->bytes);
|
||||
buf = taosDecodeFixedI32(buf, &pSchema->colId);
|
||||
buf = taosDecodeFixedI16(buf, &pSchema->colId);
|
||||
buf = taosDecodeStringTo(buf, pSchema->name);
|
||||
return buf;
|
||||
}
|
||||
|
@ -1917,7 +1917,7 @@ static FORCE_INLINE void* taosDecodeSSchema(void* buf, SSchema* pSchema) {
|
|||
static FORCE_INLINE int32_t tEncodeSSchema(SCoder* pEncoder, const SSchema* pSchema) {
|
||||
if (tEncodeI8(pEncoder, pSchema->type) < 0) return -1;
|
||||
if (tEncodeI32(pEncoder, pSchema->bytes) < 0) return -1;
|
||||
if (tEncodeI32(pEncoder, pSchema->colId) < 0) return -1;
|
||||
if (tEncodeI16(pEncoder, pSchema->colId) < 0) return -1;
|
||||
if (tEncodeCStr(pEncoder, pSchema->name) < 0) return -1;
|
||||
return 0;
|
||||
}
|
||||
|
@ -1925,12 +1925,12 @@ static FORCE_INLINE int32_t tEncodeSSchema(SCoder* pEncoder, const SSchema* pSch
|
|||
static FORCE_INLINE int32_t tDecodeSSchema(SCoder* pDecoder, SSchema* pSchema) {
|
||||
if (tDecodeI8(pDecoder, &pSchema->type) < 0) return -1;
|
||||
if (tDecodeI32(pDecoder, &pSchema->bytes) < 0) return -1;
|
||||
if (tDecodeI32(pDecoder, &pSchema->colId) < 0) return -1;
|
||||
if (tDecodeI16(pDecoder, &pSchema->colId) < 0) return -1;
|
||||
if (tDecodeCStrTo(pDecoder, pSchema->name) < 0) return -1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
static FORCE_INLINE int32_t tEncodeSSchemaWrapper(void** buf, const SSchemaWrapper* pSW) {
|
||||
static FORCE_INLINE int32_t taosEncodeSSchemaWrapper(void** buf, const SSchemaWrapper* pSW) {
|
||||
int32_t tlen = 0;
|
||||
tlen += taosEncodeFixedU32(buf, pSW->nCols);
|
||||
for (int32_t i = 0; i < pSW->nCols; i++) {
|
||||
|
@ -1939,7 +1939,7 @@ static FORCE_INLINE int32_t tEncodeSSchemaWrapper(void** buf, const SSchemaWrapp
|
|||
return tlen;
|
||||
}
|
||||
|
||||
static FORCE_INLINE void* tDecodeSSchemaWrapper(void* buf, SSchemaWrapper* pSW) {
|
||||
static FORCE_INLINE void* taosDecodeSSchemaWrapper(void* buf, SSchemaWrapper* pSW) {
|
||||
buf = taosDecodeFixedU32(buf, &pSW->nCols);
|
||||
pSW->pSchema = (SSchema*)taosMemoryCalloc(pSW->nCols, sizeof(SSchema));
|
||||
if (pSW->pSchema == NULL) {
|
||||
|
@ -1952,6 +1952,27 @@ static FORCE_INLINE void* tDecodeSSchemaWrapper(void* buf, SSchemaWrapper* pSW)
|
|||
return buf;
|
||||
}
|
||||
|
||||
static FORCE_INLINE int32_t tEncodeSSchemaWrapper(SCoder* pEncoder, const SSchemaWrapper* pSW) {
|
||||
if (tEncodeU32(pEncoder, pSW->nCols) < 0) return -1;
|
||||
for (int32_t i = 0; i < pSW->nCols; i++) {
|
||||
if (tEncodeSSchema(pEncoder, &pSW->pSchema[i]) < 0) return -1;
|
||||
}
|
||||
return pEncoder->pos;
|
||||
}
|
||||
|
||||
static FORCE_INLINE int32_t tDecodeSSchemaWrapper(SCoder* pDecoder, SSchemaWrapper* pSW) {
|
||||
if (tDecodeU32(pDecoder, &pSW->nCols) < 0) return -1;
|
||||
void* ptr = taosMemoryRealloc(pSW->pSchema, pSW->nCols * sizeof(SSchema));
|
||||
if (ptr == NULL) {
|
||||
return -1;
|
||||
}
|
||||
pSW->pSchema = (SSchema*)ptr;
|
||||
for (int32_t i = 0; i < pSW->nCols; i++) {
|
||||
if (tDecodeSSchema(pDecoder, &pSW->pSchema[i]) < 0) return -1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
typedef struct {
|
||||
char name[TSDB_TABLE_FNAME_LEN];
|
||||
char stb[TSDB_TABLE_FNAME_LEN];
|
||||
|
|
|
@ -671,8 +671,9 @@ static FORCE_INLINE int32_t tdAppendColValToKvRow(SRowBuilder *pBuilder, TDRowVa
|
|||
* @param colIdx sorted column index, start from 0
|
||||
* @return FORCE_INLINE
|
||||
*/
|
||||
static FORCE_INLINE int32_t tdAppendColValToRow(SRowBuilder *pBuilder, int16_t colId, int8_t colType, TDRowValT valType,
|
||||
const void *val, bool isCopyVarData, int32_t offset, int16_t colIdx) {
|
||||
static FORCE_INLINE int32_t tdAppendColValToRow(SRowBuilder *pBuilder, col_id_t colId, int8_t colType,
|
||||
TDRowValT valType, const void *val, bool isCopyVarData, int32_t offset,
|
||||
col_id_t colIdx) {
|
||||
STSRow *pRow = pBuilder->pBuf;
|
||||
if (!val) {
|
||||
#ifdef TD_SUPPORT_BITMAP
|
||||
|
|
|
@ -29,6 +29,7 @@ typedef uint32_t TDRowLenT;
|
|||
typedef uint8_t TDRowValT;
|
||||
typedef int16_t col_id_t;
|
||||
typedef int8_t col_type_t;
|
||||
typedef int32_t col_bytes_t;
|
||||
|
||||
#pragma pack(push, 1)
|
||||
typedef struct {
|
||||
|
|
|
@ -120,6 +120,7 @@ typedef enum ENodeType {
|
|||
QUERY_NODE_LOGIC_PLAN_VNODE_MODIF,
|
||||
QUERY_NODE_LOGIC_PLAN_EXCHANGE,
|
||||
QUERY_NODE_LOGIC_PLAN_WINDOW,
|
||||
QUERY_NODE_LOGIC_PLAN_SORT,
|
||||
QUERY_NODE_LOGIC_SUBPLAN,
|
||||
QUERY_NODE_LOGIC_PLAN,
|
||||
|
||||
|
|
|
@ -66,6 +66,7 @@ typedef struct SAggLogicNode {
|
|||
typedef struct SProjectLogicNode {
|
||||
SLogicNode node;
|
||||
SNodeList* pProjections;
|
||||
char stmtName[TSDB_TABLE_NAME_LEN];
|
||||
} SProjectLogicNode;
|
||||
|
||||
typedef struct SVnodeModifLogicNode {
|
||||
|
@ -97,8 +98,14 @@ typedef struct SWindowLogicNode {
|
|||
int8_t slidingUnit;
|
||||
SFillNode* pFill;
|
||||
int64_t sessionGap;
|
||||
SNode* pTspk;
|
||||
} SWindowLogicNode;
|
||||
|
||||
typedef struct SSortLogicNode {
|
||||
SLogicNode node;
|
||||
SNodeList* pSortKeys;
|
||||
} SSortLogicNode;
|
||||
|
||||
typedef enum ESubplanType {
|
||||
SUBPLAN_TYPE_MERGE = 1,
|
||||
SUBPLAN_TYPE_PARTIAL,
|
||||
|
@ -200,7 +207,7 @@ typedef struct SJoinPhysiNode {
|
|||
typedef struct SAggPhysiNode {
|
||||
SPhysiNode node;
|
||||
SNodeList* pExprs; // these are expression list of group_by_clause and parameter expression of aggregate function
|
||||
SNodeList* pGroupKeys; // SColumnRefNode list
|
||||
SNodeList* pGroupKeys;
|
||||
SNodeList* pAggFuncs;
|
||||
} SAggPhysiNode;
|
||||
|
||||
|
@ -225,6 +232,7 @@ typedef struct SWinodwPhysiNode {
|
|||
|
||||
typedef struct SIntervalPhysiNode {
|
||||
SWinodwPhysiNode window;
|
||||
SNode* pTspk; // timestamp primary key
|
||||
int64_t interval;
|
||||
int64_t offset;
|
||||
int64_t sliding;
|
||||
|
@ -238,6 +246,12 @@ typedef struct SSessionWinodwPhysiNode {
|
|||
int64_t gap;
|
||||
} SSessionWinodwPhysiNode;
|
||||
|
||||
typedef struct SSortPhysiNode {
|
||||
SPhysiNode node;
|
||||
SNodeList* pExprs; // these are expression list of order_by_clause and parameter expression of aggregate function
|
||||
SNodeList* pSortKeys; // element is SOrderByExprNode, and SOrderByExprNode::pExpr is SColumnNode
|
||||
} SSortPhysiNode;
|
||||
|
||||
typedef struct SDataSinkNode {
|
||||
ENodeType type;
|
||||
SDataBlockDescNode* pInputDataBlockDesc;
|
||||
|
|
|
@ -56,7 +56,7 @@ typedef enum EColumnType {
|
|||
typedef struct SColumnNode {
|
||||
SExprNode node; // QUERY_NODE_COLUMN
|
||||
uint64_t tableId;
|
||||
int16_t colId;
|
||||
col_id_t colId;
|
||||
EColumnType colType; // column or tag
|
||||
char dbName[TSDB_DB_NAME_LEN];
|
||||
char tableName[TSDB_TABLE_NAME_LEN];
|
||||
|
@ -191,12 +191,13 @@ typedef struct SStateWindowNode {
|
|||
|
||||
typedef struct SSessionWindowNode {
|
||||
ENodeType type; // QUERY_NODE_SESSION_WINDOW
|
||||
SNode* pCol;
|
||||
SNode* pCol; // timestamp primary key
|
||||
SNode* pGap; // gap between two session window(in microseconds)
|
||||
} SSessionWindowNode;
|
||||
|
||||
typedef struct SIntervalWindowNode {
|
||||
ENodeType type; // QUERY_NODE_INTERVAL_WINDOW
|
||||
SNode* pCol; // timestamp primary key
|
||||
SNode* pInterval; // SValueNode
|
||||
SNode* pOffset; // SValueNode
|
||||
SNode* pSliding; // SValueNode
|
||||
|
@ -231,6 +232,7 @@ typedef struct SSelectStmt {
|
|||
SNodeList* pOrderByList; // SOrderByExprNode
|
||||
SNode* pLimit;
|
||||
SNode* pSlimit;
|
||||
char stmtName[TSDB_TABLE_NAME_LEN];
|
||||
} SSelectStmt;
|
||||
|
||||
typedef enum ESetOperatorType {
|
||||
|
|
|
@ -45,7 +45,7 @@ typedef enum {
|
|||
typedef struct STableComInfo {
|
||||
uint8_t numOfTags; // the number of tags in schema
|
||||
uint8_t precision; // the number of precision
|
||||
int16_t numOfColumns; // the number of columns
|
||||
col_id_t numOfColumns; // the number of columns
|
||||
int32_t rowSize; // row size of the schema
|
||||
} STableComInfo;
|
||||
|
||||
|
@ -173,7 +173,7 @@ bool tIsValidSchema(struct SSchema* pSchema, int32_t numOfCols, int32_
|
|||
int32_t queryCreateTableMetaFromMsg(STableMetaRsp* msg, bool isSuperTable, STableMeta** pMeta);
|
||||
char *jobTaskStatusStr(int32_t status);
|
||||
|
||||
SSchema createSchema(uint8_t type, int32_t bytes, int32_t colId, const char* name);
|
||||
SSchema createSchema(int8_t type, int32_t bytes, col_id_t colId, const char* name);
|
||||
|
||||
extern int32_t (*queryBuildMsg[TDMT_MAX])(void* input, char** msg, int32_t msgSize, int32_t* msgLen);
|
||||
extern int32_t (*queryProcessMsgRsp[TDMT_MAX])(void* output, char* msg, int32_t msgSize);
|
||||
|
|
|
@ -62,10 +62,11 @@ typedef struct {
|
|||
} STaskExec;
|
||||
|
||||
typedef struct {
|
||||
int8_t reserved;
|
||||
int32_t taskId;
|
||||
} STaskDispatcherInplace;
|
||||
|
||||
typedef struct {
|
||||
int32_t taskId;
|
||||
int32_t nodeId;
|
||||
SEpSet epSet;
|
||||
} STaskDispatcherFixedEp;
|
||||
|
|
|
@ -75,7 +75,6 @@ extern "C" {
|
|||
#include "osDef.h"
|
||||
#include "osDir.h"
|
||||
#include "osEndian.h"
|
||||
#include "osEnv.h"
|
||||
#include "osFile.h"
|
||||
#include "osLocale.h"
|
||||
#include "osLz4.h"
|
||||
|
@ -93,8 +92,9 @@ extern "C" {
|
|||
#include "osTime.h"
|
||||
#include "osTimer.h"
|
||||
#include "osTimezone.h"
|
||||
#include "osEnv.h"
|
||||
|
||||
void osInit();
|
||||
void osDefaultInit();
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
|
|
@ -23,7 +23,8 @@ extern "C" {
|
|||
#endif
|
||||
|
||||
extern char tsOsName[];
|
||||
extern char tsTimezone[];
|
||||
extern char tsTimezoneStr[];
|
||||
extern enum TdTimezone tsTimezone;
|
||||
extern char tsCharset[];
|
||||
extern char tsLocale[];
|
||||
extern int8_t tsDaylight;
|
||||
|
@ -43,11 +44,12 @@ extern SDiskSpace tsDataSpace;
|
|||
extern SDiskSpace tsLogSpace;
|
||||
extern SDiskSpace tsTempSpace;
|
||||
|
||||
void osInit();
|
||||
void osDefaultInit();
|
||||
void osUpdate();
|
||||
void osCleanup();
|
||||
bool osLogSpaceAvailable();
|
||||
void osSetTimezone(const char *timezone);
|
||||
void osSetSystemLocale(const char *inLocale, const char *inCharSet);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
|
|
@ -26,8 +26,37 @@ extern "C" {
|
|||
#define tzset TZSET_FUNC_TAOS_FORBID
|
||||
#endif
|
||||
|
||||
void taosGetSystemTimezone(char *outTimezone);
|
||||
void taosSetSystemTimezone(const char *inTimezone, char *outTimezone, int8_t *outDaylight);
|
||||
enum TdTimezone
|
||||
{
|
||||
TdWestZone12=-12,
|
||||
TdWestZone11,
|
||||
TdWestZone10,
|
||||
TdWestZone9,
|
||||
TdWestZone8,
|
||||
TdWestZone7,
|
||||
TdWestZone6,
|
||||
TdWestZone5,
|
||||
TdWestZone4,
|
||||
TdWestZone3,
|
||||
TdWestZone2,
|
||||
TdWestZone1,
|
||||
TdZeroZone,
|
||||
TdEastZone1,
|
||||
TdEastZone2,
|
||||
TdEastZone3,
|
||||
TdEastZone4,
|
||||
TdEastZone5,
|
||||
TdEastZone6,
|
||||
TdEastZone7,
|
||||
TdEastZone8,
|
||||
TdEastZone9,
|
||||
TdEastZone10,
|
||||
TdEastZone11,
|
||||
TdEastZone12
|
||||
};
|
||||
|
||||
void taosGetSystemTimezone(char *outTimezone, enum TdTimezone *tsTimezone);
|
||||
void taosSetSystemTimezone(const char *inTimezone, char *outTimezone, int8_t *outDaylight, enum TdTimezone *tsTimezone);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
|
|
@ -16,6 +16,8 @@
|
|||
#ifndef _TD_UTIL_TAOS_ERROR_H_
|
||||
#define _TD_UTIL_TAOS_ERROR_H_
|
||||
|
||||
#include "os.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
|
|
@ -209,7 +209,7 @@ typedef enum ELogicConditionType {
|
|||
#define TSDB_FUNC_TYPE_AGGREGATE 2
|
||||
#define TSDB_FUNC_MAX_RETRIEVE 1024
|
||||
|
||||
#define TSDB_INDEX_NAME_LEN 33 // 32 + 1 '\0'
|
||||
#define TSDB_INDEX_NAME_LEN 65 // 64 + 1 '\0'
|
||||
#define TSDB_TYPE_STR_MAX_LEN 32
|
||||
#define TSDB_TABLE_FNAME_LEN (TSDB_DB_FNAME_LEN + TSDB_TABLE_NAME_LEN + TSDB_NAME_DELIMITER_LEN)
|
||||
#define TSDB_TOPIC_FNAME_LEN TSDB_TABLE_FNAME_LEN
|
||||
|
|
|
@ -51,6 +51,7 @@ void taosProcCleanup(SProcObj *pProc);
|
|||
int32_t taosProcRun(SProcObj *pProc);
|
||||
void taosProcStop(SProcObj *pProc);
|
||||
bool taosProcIsChild(SProcObj *pProc);
|
||||
int32_t taosProcChildId(SProcObj *pProc);
|
||||
|
||||
int32_t taosProcPutToChildQueue(SProcObj *pProc, void *pHead, int32_t headLen, void *pBody, int32_t bodyLen);
|
||||
int32_t taosProcPutToParentQueue(SProcObj *pProc, void *pHead, int32_t headLen, void *pBody, int32_t bodyLen);
|
||||
|
|
|
@ -408,10 +408,10 @@ int taos_options_imp(TSDB_OPTION option, const char *str) {
|
|||
assert(cfg != NULL);
|
||||
|
||||
if (cfg->cfgStatus <= TAOS_CFG_CSTATUS_OPTION) {
|
||||
tstrncpy(tsTimezone, str, TD_TIMEZONE_LEN);
|
||||
tstrncpy(tsTimezoneStr, str, TD_TIMEZONE_LEN);
|
||||
tsSetTimeZone();
|
||||
cfg->cfgStatus = TAOS_CFG_CSTATUS_OPTION;
|
||||
tscDebug("timezone set:%s, input:%s by taos_options", tsTimezone, str);
|
||||
tscDebug("timezone set:%s, input:%s by taos_options", tsTimezoneStr, str);
|
||||
} else {
|
||||
tscWarn("config option:%s, input value:%s, is configured by %s, use %s", cfg->option, str,
|
||||
tsCfgStatusStr[cfg->cfgStatus], (char *)cfg->ptr);
|
||||
|
|
|
@ -91,7 +91,7 @@ static int32_t hbProcessStbInfoRsp(void *value, int32_t valueLen, struct SCatalo
|
|||
} else {
|
||||
tscDebug("hb update stb, db:%s, stb:%s", rsp->dbFName, rsp->stbName);
|
||||
if (rsp->pSchemas[0].colId != PRIMARYKEY_TIMESTAMP_COL_ID) {
|
||||
tscError("invalid colId[%d] for the first column in table meta rsp msg", rsp->pSchemas[0].colId);
|
||||
tscError("invalid colId[%" PRIi16 "] for the first column in table meta rsp msg", rsp->pSchemas[0].colId);
|
||||
tFreeSTableMetaBatchRsp(&batchMetaRsp);
|
||||
return TSDB_CODE_TSC_INVALID_VALUE;
|
||||
}
|
||||
|
|
|
@ -27,9 +27,7 @@
|
|||
#include "tref.h"
|
||||
|
||||
struct tmq_list_t {
|
||||
int32_t cnt;
|
||||
int32_t tot;
|
||||
char* elems[];
|
||||
SArray container;
|
||||
};
|
||||
|
||||
struct tmq_topic_vgroup_t {
|
||||
|
@ -45,11 +43,14 @@ struct tmq_topic_vgroup_list_t {
|
|||
struct tmq_conf_t {
|
||||
char clientId[256];
|
||||
char groupId[TSDB_CGROUP_LEN];
|
||||
int8_t auto_commit;
|
||||
int8_t autoCommit;
|
||||
int8_t resetOffset;
|
||||
uint16_t port;
|
||||
char* ip;
|
||||
char* user;
|
||||
char* pass;
|
||||
char* db;
|
||||
tmq_commit_cb* commit_cb;
|
||||
/*char* ip;*/
|
||||
/*uint16_t port;*/
|
||||
};
|
||||
|
||||
struct tmq_t {
|
||||
|
@ -104,6 +105,7 @@ typedef struct {
|
|||
int64_t topicId;
|
||||
int32_t nextVgIdx;
|
||||
SArray* vgs; // SArray<SMqClientVg>
|
||||
SSchemaWrapper schema;
|
||||
} SMqClientTopic;
|
||||
|
||||
typedef struct {
|
||||
|
@ -137,7 +139,7 @@ typedef struct {
|
|||
|
||||
tmq_conf_t* tmq_conf_new() {
|
||||
tmq_conf_t* conf = taosMemoryCalloc(1, sizeof(tmq_conf_t));
|
||||
conf->auto_commit = false;
|
||||
conf->autoCommit = false;
|
||||
conf->resetOffset = TMQ_CONF__RESET_OFFSET__EARLIEAST;
|
||||
return conf;
|
||||
}
|
||||
|
@ -151,21 +153,24 @@ tmq_conf_res_t tmq_conf_set(tmq_conf_t* conf, const char* key, const char* value
|
|||
strcpy(conf->groupId, value);
|
||||
return TMQ_CONF_OK;
|
||||
}
|
||||
|
||||
if (strcmp(key, "client.id") == 0) {
|
||||
strcpy(conf->clientId, value);
|
||||
return TMQ_CONF_OK;
|
||||
}
|
||||
|
||||
if (strcmp(key, "enable.auto.commit") == 0) {
|
||||
if (strcmp(value, "true") == 0) {
|
||||
conf->auto_commit = true;
|
||||
conf->autoCommit = true;
|
||||
return TMQ_CONF_OK;
|
||||
} else if (strcmp(value, "false") == 0) {
|
||||
conf->auto_commit = false;
|
||||
conf->autoCommit = false;
|
||||
return TMQ_CONF_OK;
|
||||
} else {
|
||||
return TMQ_CONF_INVALID;
|
||||
}
|
||||
}
|
||||
|
||||
if (strcmp(key, "auto.offset.reset") == 0) {
|
||||
if (strcmp(value, "none") == 0) {
|
||||
conf->resetOffset = TMQ_CONF__RESET_OFFSET__NONE;
|
||||
|
@ -180,28 +185,51 @@ tmq_conf_res_t tmq_conf_set(tmq_conf_t* conf, const char* key, const char* value
|
|||
return TMQ_CONF_INVALID;
|
||||
}
|
||||
}
|
||||
|
||||
if (strcmp(key, "td.connect.ip") == 0) {
|
||||
conf->ip = strdup(value);
|
||||
return TMQ_CONF_OK;
|
||||
}
|
||||
if (strcmp(key, "td.connect.user") == 0) {
|
||||
conf->user = strdup(value);
|
||||
return TMQ_CONF_OK;
|
||||
}
|
||||
if (strcmp(key, "td.connect.pass") == 0) {
|
||||
conf->pass = strdup(value);
|
||||
return TMQ_CONF_OK;
|
||||
}
|
||||
if (strcmp(key, "td.connect.port") == 0) {
|
||||
conf->port = atoi(value);
|
||||
return TMQ_CONF_OK;
|
||||
}
|
||||
if (strcmp(key, "td.connect.db") == 0) {
|
||||
conf->db = strdup(value);
|
||||
return TMQ_CONF_OK;
|
||||
}
|
||||
|
||||
return TMQ_CONF_UNKNOWN;
|
||||
}
|
||||
|
||||
tmq_list_t* tmq_list_new() {
|
||||
tmq_list_t* ptr = taosMemoryMalloc(sizeof(tmq_list_t) + 8 * sizeof(char*));
|
||||
if (ptr == NULL) {
|
||||
return ptr;
|
||||
}
|
||||
ptr->cnt = 0;
|
||||
ptr->tot = 8;
|
||||
return ptr;
|
||||
//
|
||||
return (tmq_list_t*)taosArrayInit(0, sizeof(void*));
|
||||
}
|
||||
|
||||
int32_t tmq_list_append(tmq_list_t* ptr, const char* src) {
|
||||
if (ptr->cnt >= ptr->tot - 1) return -1;
|
||||
ptr->elems[ptr->cnt] = strdup(src);
|
||||
ptr->cnt++;
|
||||
int32_t tmq_list_append(tmq_list_t* list, const char* src) {
|
||||
SArray* container = &list->container;
|
||||
char* topic = strdup(src);
|
||||
if (taosArrayPush(container, &topic) == NULL) return -1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
void tmq_list_destroy(tmq_list_t* list) {
|
||||
SArray* container = &list->container;
|
||||
/*taosArrayDestroy(container);*/
|
||||
taosArrayDestroyEx(container, (void (*)(void*))taosMemoryFree);
|
||||
}
|
||||
|
||||
void tmqClearUnhandleMsg(tmq_t* tmq) {
|
||||
tmq_message_t* msg;
|
||||
tmq_message_t* msg = NULL;
|
||||
while (1) {
|
||||
taosGetQitem(tmq->qall, (void**)&msg);
|
||||
if (msg)
|
||||
|
@ -268,17 +296,57 @@ tmq_t* tmq_consumer_new(void* conn, tmq_conf_t* conf, char* errstr, int32_t errs
|
|||
// set conf
|
||||
strcpy(pTmq->clientId, conf->clientId);
|
||||
strcpy(pTmq->groupId, conf->groupId);
|
||||
pTmq->autoCommit = conf->auto_commit;
|
||||
pTmq->autoCommit = conf->autoCommit;
|
||||
pTmq->commit_cb = conf->commit_cb;
|
||||
pTmq->resetOffsetCfg = conf->resetOffset;
|
||||
|
||||
tsem_init(&pTmq->rspSem, 0, 0);
|
||||
|
||||
pTmq->consumerId = generateRequestId() & (((uint64_t)-1) >> 1);
|
||||
pTmq->clientTopics = taosArrayInit(0, sizeof(SMqClientTopic));
|
||||
if (pTmq->clientTopics == NULL) {
|
||||
taosMemoryFree(pTmq);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
pTmq->mqueue = taosOpenQueue();
|
||||
pTmq->qall = taosAllocateQall();
|
||||
|
||||
tsem_init(&pTmq->rspSem, 0, 0);
|
||||
|
||||
return pTmq;
|
||||
}
|
||||
|
||||
tmq_t* tmq_consumer_new1(tmq_conf_t* conf, char* errstr, int32_t errstrLen) {
|
||||
tmq_t* pTmq = taosMemoryCalloc(1, sizeof(tmq_t));
|
||||
if (pTmq == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
pTmq->pTscObj = taos_connect(conf->ip, conf->user, conf->pass, conf->db, conf->port);
|
||||
|
||||
pTmq->inWaiting = 0;
|
||||
pTmq->status = 0;
|
||||
pTmq->pollCnt = 0;
|
||||
pTmq->epoch = 0;
|
||||
pTmq->waitingRequest = 0;
|
||||
pTmq->readyRequest = 0;
|
||||
// set conf
|
||||
strcpy(pTmq->clientId, conf->clientId);
|
||||
strcpy(pTmq->groupId, conf->groupId);
|
||||
pTmq->autoCommit = conf->autoCommit;
|
||||
pTmq->commit_cb = conf->commit_cb;
|
||||
pTmq->resetOffsetCfg = conf->resetOffset;
|
||||
|
||||
pTmq->consumerId = generateRequestId() & (((uint64_t)-1) >> 1);
|
||||
pTmq->clientTopics = taosArrayInit(0, sizeof(SMqClientTopic));
|
||||
if (pTmq->clientTopics == NULL) {
|
||||
taosMemoryFree(pTmq);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
pTmq->mqueue = taosOpenQueue();
|
||||
pTmq->qall = taosAllocateQall();
|
||||
|
||||
tsem_init(&pTmq->rspSem, 0, 0);
|
||||
|
||||
return pTmq;
|
||||
}
|
||||
|
||||
|
@ -372,7 +440,8 @@ tmq_resp_err_t tmq_commit(tmq_t* tmq, const tmq_topic_vgroup_list_t* offsets, in
|
|||
|
||||
tmq_resp_err_t tmq_subscribe(tmq_t* tmq, tmq_list_t* topic_list) {
|
||||
SRequestObj* pRequest = NULL;
|
||||
int32_t sz = topic_list->cnt;
|
||||
SArray* container = &topic_list->container;
|
||||
int32_t sz = taosArrayGetSize(container);
|
||||
// destroy ex
|
||||
taosArrayDestroy(tmq->clientTopics);
|
||||
tmq->clientTopics = taosArrayInit(sz, sizeof(SMqClientTopic));
|
||||
|
@ -384,7 +453,8 @@ tmq_resp_err_t tmq_subscribe(tmq_t* tmq, tmq_list_t* topic_list) {
|
|||
req.topicNames = taosArrayInit(sz, sizeof(void*));
|
||||
|
||||
for (int i = 0; i < sz; i++) {
|
||||
char* topicName = topic_list->elems[i];
|
||||
/*char* topicName = topic_list->elems[i];*/
|
||||
char* topicName = taosArrayGetP(container, i);
|
||||
|
||||
SName name = {0};
|
||||
char* dbName = getDbOfConnection(tmq->pTscObj);
|
||||
|
@ -737,7 +807,7 @@ int32_t tmqPollCb(void* param, const SDataBuf* pMsg, int32_t code) {
|
|||
SMqClientVg* pVg = pParam->pVg;
|
||||
tmq_t* tmq = pParam->tmq;
|
||||
if (code != 0) {
|
||||
printf("msg discard %x\n", code);
|
||||
printf("msg discard, code:%x\n", code);
|
||||
goto WRITE_QUEUE_FAIL;
|
||||
}
|
||||
|
||||
|
@ -807,10 +877,10 @@ WRITE_QUEUE_FAIL:
|
|||
}
|
||||
|
||||
bool tmqUpdateEp(tmq_t* tmq, int32_t epoch, SMqCMGetSubEpRsp* pRsp) {
|
||||
printf("call update ep %d\n", epoch);
|
||||
bool set = false;
|
||||
int32_t sz = taosArrayGetSize(pRsp->topics);
|
||||
if (tmq->clientTopics) taosArrayDestroy(tmq->clientTopics);
|
||||
tmq->clientTopics = taosArrayInit(sz, sizeof(SMqClientTopic));
|
||||
SArray* newTopics = taosArrayInit(sz, sizeof(SMqClientTopic));
|
||||
for (int32_t i = 0; i < sz; i++) {
|
||||
SMqClientTopic topic = {0};
|
||||
SMqSubTopicEp* pTopicEp = taosArrayGet(pRsp->topics, i);
|
||||
|
@ -829,8 +899,10 @@ bool tmqUpdateEp(tmq_t* tmq, int32_t epoch, SMqCMGetSubEpRsp* pRsp) {
|
|||
taosArrayPush(topic.vgs, &clientVg);
|
||||
set = true;
|
||||
}
|
||||
taosArrayPush(tmq->clientTopics, &topic);
|
||||
taosArrayPush(newTopics, &topic);
|
||||
}
|
||||
if (tmq->clientTopics) taosArrayDestroy(tmq->clientTopics);
|
||||
tmq->clientTopics = newTopics;
|
||||
atomic_store_32(&tmq->epoch, epoch);
|
||||
return set;
|
||||
}
|
||||
|
@ -1149,6 +1221,7 @@ tmq_message_t* tmqHandleAllRsp(tmq_t* tmq, int64_t blockingTime, bool pollIfRese
|
|||
if (rspMsg->msg.head.epoch == atomic_load_32(&tmq->epoch)) {
|
||||
/*printf("epoch match\n");*/
|
||||
SMqClientVg* pVg = rspMsg->vg;
|
||||
/*printf("vg %d offset %ld up to %ld\n", pVg->vgId, pVg->currentOffset, rspMsg->msg.rspOffset);*/
|
||||
pVg->currentOffset = rspMsg->msg.rspOffset;
|
||||
atomic_store_32(&pVg->vgStatus, TMQ_VG_STATUS__IDLE);
|
||||
return rspMsg;
|
||||
|
|
|
@ -106,12 +106,12 @@ void *tdDecodeSchema(void *buf, STSchema **pRSchema) {
|
|||
if (tdInitTSchemaBuilder(&schemaBuilder, version) < 0) return NULL;
|
||||
|
||||
for (int i = 0; i < numOfCols; i++) {
|
||||
int8_t type = 0;
|
||||
int16_t colId = 0;
|
||||
int16_t bytes = 0;
|
||||
col_type_t type = 0;
|
||||
col_id_t colId = 0;
|
||||
col_bytes_t bytes = 0;
|
||||
buf = taosDecodeFixedI8(buf, &type);
|
||||
buf = taosDecodeFixedI16(buf, &colId);
|
||||
buf = taosDecodeFixedI16(buf, &bytes);
|
||||
buf = taosDecodeFixedI32(buf, &bytes);
|
||||
if (tdAddColToSchema(&schemaBuilder, type, colId, bytes) < 0) {
|
||||
tdDestroyTSchemaBuilder(&schemaBuilder);
|
||||
return NULL;
|
||||
|
@ -148,7 +148,7 @@ void tdResetTSchemaBuilder(STSchemaBuilder *pBuilder, int32_t version) {
|
|||
pBuilder->version = version;
|
||||
}
|
||||
|
||||
int tdAddColToSchema(STSchemaBuilder *pBuilder, int8_t type, int16_t colId, int16_t bytes) {
|
||||
int tdAddColToSchema(STSchemaBuilder *pBuilder, int8_t type, col_id_t colId, col_bytes_t bytes) {
|
||||
if (!isValidDataType(type)) return -1;
|
||||
|
||||
if (pBuilder->nCols >= pBuilder->tCols) {
|
||||
|
|
|
@ -303,7 +303,7 @@ static int32_t taosAddClientCfg(SConfig *pCfg) {
|
|||
static int32_t taosAddSystemCfg(SConfig *pCfg) {
|
||||
SysNameInfo info = taosGetSysNameInfo();
|
||||
|
||||
if (cfgAddTimezone(pCfg, "timezone", tsTimezone) != 0) return -1;
|
||||
if (cfgAddTimezone(pCfg, "timezone", tsTimezoneStr) != 0) return -1;
|
||||
if (cfgAddLocale(pCfg, "locale", tsLocale) != 0) return -1;
|
||||
if (cfgAddCharset(pCfg, "charset", tsCharset) != 0) return -1;
|
||||
if (cfgAddBool(pCfg, "enableCoreFile", 1, 1) != 0) return -1;
|
||||
|
@ -431,12 +431,13 @@ static int32_t taosSetClientCfg(SConfig *pCfg) {
|
|||
static void taosSetSystemCfg(SConfig *pCfg) {
|
||||
SConfigItem *pItem = cfgGetItem(pCfg, "timezone");
|
||||
osSetTimezone(pItem->str);
|
||||
uDebug("timezone format changed from %s to %s", pItem->str, tsTimezone);
|
||||
cfgSetItem(pCfg, "timezone", tsTimezone, pItem->stype);
|
||||
uDebug("timezone format changed from %s to %s", pItem->str, tsTimezoneStr);
|
||||
cfgSetItem(pCfg, "timezone", tsTimezoneStr, pItem->stype);
|
||||
|
||||
const char *locale = cfgGetItem(pCfg, "locale")->str;
|
||||
const char *charset = cfgGetItem(pCfg, "charset")->str;
|
||||
taosSetSystemLocale(locale, charset);
|
||||
osSetSystemLocale(locale, charset);
|
||||
|
||||
bool enableCore = cfgGetItem(pCfg, "enableCoreFile")->bval;
|
||||
taosSetConsoleEcho(enableCore);
|
||||
|
@ -483,7 +484,7 @@ static int32_t taosSetServerCfg(SConfig *pCfg) {
|
|||
|
||||
int32_t taosCreateLog(const char *logname, int32_t logFileNum, const char *cfgDir, const char *envFile,
|
||||
const char *apolloUrl, SArray *pArgs, bool tsc) {
|
||||
osInit();
|
||||
osDefaultInit();
|
||||
|
||||
SConfig *pCfg = cfgInit();
|
||||
if (pCfg == NULL) return -1;
|
||||
|
|
|
@ -299,14 +299,14 @@ int32_t tSerializeSVCreateTbReq(void **buf, SVCreateTbReq *pReq) {
|
|||
tlen += taosEncodeFixedU32(buf, pReq->stbCfg.nCols);
|
||||
for (uint32_t i = 0; i < pReq->stbCfg.nCols; i++) {
|
||||
tlen += taosEncodeFixedI8(buf, pReq->stbCfg.pSchema[i].type);
|
||||
tlen += taosEncodeFixedI32(buf, pReq->stbCfg.pSchema[i].colId);
|
||||
tlen += taosEncodeFixedI16(buf, pReq->stbCfg.pSchema[i].colId);
|
||||
tlen += taosEncodeFixedI32(buf, pReq->stbCfg.pSchema[i].bytes);
|
||||
tlen += taosEncodeString(buf, pReq->stbCfg.pSchema[i].name);
|
||||
}
|
||||
tlen += taosEncodeFixedU32(buf, pReq->stbCfg.nTagCols);
|
||||
for (uint32_t i = 0; i < pReq->stbCfg.nTagCols; i++) {
|
||||
tlen += taosEncodeFixedI8(buf, pReq->stbCfg.pTagSchema[i].type);
|
||||
tlen += taosEncodeFixedI32(buf, pReq->stbCfg.pTagSchema[i].colId);
|
||||
tlen += taosEncodeFixedI16(buf, pReq->stbCfg.pTagSchema[i].colId);
|
||||
tlen += taosEncodeFixedI32(buf, pReq->stbCfg.pTagSchema[i].bytes);
|
||||
tlen += taosEncodeString(buf, pReq->stbCfg.pTagSchema[i].name);
|
||||
}
|
||||
|
@ -333,7 +333,7 @@ int32_t tSerializeSVCreateTbReq(void **buf, SVCreateTbReq *pReq) {
|
|||
tlen += taosEncodeFixedU32(buf, pReq->ntbCfg.nCols);
|
||||
for (uint32_t i = 0; i < pReq->ntbCfg.nCols; i++) {
|
||||
tlen += taosEncodeFixedI8(buf, pReq->ntbCfg.pSchema[i].type);
|
||||
tlen += taosEncodeFixedI32(buf, pReq->ntbCfg.pSchema[i].colId);
|
||||
tlen += taosEncodeFixedI16(buf, pReq->ntbCfg.pSchema[i].colId);
|
||||
tlen += taosEncodeFixedI32(buf, pReq->ntbCfg.pSchema[i].bytes);
|
||||
tlen += taosEncodeString(buf, pReq->ntbCfg.pSchema[i].name);
|
||||
}
|
||||
|
@ -374,7 +374,7 @@ void *tDeserializeSVCreateTbReq(void *buf, SVCreateTbReq *pReq) {
|
|||
pReq->stbCfg.pSchema = (SSchema *)taosMemoryMalloc(pReq->stbCfg.nCols * sizeof(SSchema));
|
||||
for (uint32_t i = 0; i < pReq->stbCfg.nCols; i++) {
|
||||
buf = taosDecodeFixedI8(buf, &(pReq->stbCfg.pSchema[i].type));
|
||||
buf = taosDecodeFixedI32(buf, &(pReq->stbCfg.pSchema[i].colId));
|
||||
buf = taosDecodeFixedI16(buf, &(pReq->stbCfg.pSchema[i].colId));
|
||||
buf = taosDecodeFixedI32(buf, &(pReq->stbCfg.pSchema[i].bytes));
|
||||
buf = taosDecodeStringTo(buf, pReq->stbCfg.pSchema[i].name);
|
||||
}
|
||||
|
@ -382,7 +382,7 @@ void *tDeserializeSVCreateTbReq(void *buf, SVCreateTbReq *pReq) {
|
|||
pReq->stbCfg.pTagSchema = (SSchema *)taosMemoryMalloc(pReq->stbCfg.nTagCols * sizeof(SSchema));
|
||||
for (uint32_t i = 0; i < pReq->stbCfg.nTagCols; i++) {
|
||||
buf = taosDecodeFixedI8(buf, &(pReq->stbCfg.pTagSchema[i].type));
|
||||
buf = taosDecodeFixedI32(buf, &pReq->stbCfg.pTagSchema[i].colId);
|
||||
buf = taosDecodeFixedI16(buf, &pReq->stbCfg.pTagSchema[i].colId);
|
||||
buf = taosDecodeFixedI32(buf, &pReq->stbCfg.pTagSchema[i].bytes);
|
||||
buf = taosDecodeStringTo(buf, pReq->stbCfg.pTagSchema[i].name);
|
||||
}
|
||||
|
@ -422,7 +422,7 @@ void *tDeserializeSVCreateTbReq(void *buf, SVCreateTbReq *pReq) {
|
|||
pReq->ntbCfg.pSchema = (SSchema *)taosMemoryMalloc(pReq->ntbCfg.nCols * sizeof(SSchema));
|
||||
for (uint32_t i = 0; i < pReq->ntbCfg.nCols; i++) {
|
||||
buf = taosDecodeFixedI8(buf, &pReq->ntbCfg.pSchema[i].type);
|
||||
buf = taosDecodeFixedI32(buf, &pReq->ntbCfg.pSchema[i].colId);
|
||||
buf = taosDecodeFixedI16(buf, &pReq->ntbCfg.pSchema[i].colId);
|
||||
buf = taosDecodeFixedI32(buf, &pReq->ntbCfg.pSchema[i].bytes);
|
||||
buf = taosDecodeStringTo(buf, pReq->ntbCfg.pSchema[i].name);
|
||||
}
|
||||
|
|
|
@ -56,7 +56,6 @@ void dndCleanupServer(SDnode *pDnode);
|
|||
int32_t dndInitClient(SDnode *pDnode);
|
||||
void dndCleanupClient(SDnode *pDnode);
|
||||
int32_t dndInitMsgHandle(SDnode *pDnode);
|
||||
void dndSendRpcRsp(SMgmtWrapper *pWrapper, SRpcMsg *pRsp);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
|
|
@ -20,7 +20,7 @@ static void dndResetLog(SMgmtWrapper *pMgmt) {
|
|||
char logname[24] = {0};
|
||||
snprintf(logname, sizeof(logname), "%slog", pMgmt->name);
|
||||
|
||||
dInfo("node:%s, reset log to %s", pMgmt->name, logname);
|
||||
dInfo("node:%s, reset log to %s in child process", pMgmt->name, logname);
|
||||
taosCloseLog();
|
||||
taosInitLog(logname, 1);
|
||||
}
|
||||
|
@ -51,6 +51,7 @@ int32_t dndOpenNode(SMgmtWrapper *pWrapper) {
|
|||
|
||||
void dndCloseNode(SMgmtWrapper *pWrapper) {
|
||||
dDebug("node:%s, start to close", pWrapper->name);
|
||||
pWrapper->required = false;
|
||||
taosWLockLatch(&pWrapper->latch);
|
||||
if (pWrapper->deployed) {
|
||||
(*pWrapper->fp.closeFp)(pWrapper);
|
||||
|
@ -138,7 +139,7 @@ static void dndConsumeChildQueue(SMgmtWrapper *pWrapper, SNodeMsg *pMsg, int32_t
|
|||
static void dndConsumeParentQueue(SMgmtWrapper *pWrapper, SRpcMsg *pRsp, int32_t msgLen, void *pCont, int32_t contLen) {
|
||||
dTrace("msg:%p, get from parent queue", pRsp);
|
||||
pRsp->pCont = pCont;
|
||||
dndSendRpcRsp(pWrapper, pRsp);
|
||||
dndSendRsp(pWrapper, pRsp);
|
||||
taosMemoryFree(pRsp);
|
||||
}
|
||||
|
||||
|
@ -178,7 +179,6 @@ static int32_t dndRunInMultiProcess(SDnode *pDnode) {
|
|||
.parentFreeHeadFp = (ProcFreeFp)taosMemoryFree,
|
||||
.parentMallocBodyFp = (ProcMallocFp)rpcMallocCont,
|
||||
.parentFreeBodyFp = (ProcFreeFp)rpcFreeCont,
|
||||
.testFlag = 0,
|
||||
.pParent = pWrapper,
|
||||
.name = pWrapper->name};
|
||||
SProcObj *pProc = taosProcInit(&cfg);
|
||||
|
@ -200,7 +200,7 @@ static int32_t dndRunInMultiProcess(SDnode *pDnode) {
|
|||
dInfo("node:%s, will be initialized in child process", pWrapper->name);
|
||||
dndOpenNode(pWrapper);
|
||||
} else {
|
||||
dInfo("node:%s, will not start in parent process", pWrapper->name);
|
||||
dInfo("node:%s, will not start in parent process, child pid:%d", pWrapper->name, taosProcChildId(pProc));
|
||||
pWrapper->procType = PROC_PARENT;
|
||||
}
|
||||
|
||||
|
@ -210,16 +210,20 @@ static int32_t dndRunInMultiProcess(SDnode *pDnode) {
|
|||
}
|
||||
}
|
||||
|
||||
#if 0
|
||||
SMgmtWrapper *pWrapper = dndAcquireWrapper(pDnode, DNODE);
|
||||
if (pWrapper->procType == PROC_PARENT && dmStart(pWrapper->pMgmt) != 0) {
|
||||
dndReleaseWrapper(pWrapper);
|
||||
dError("failed to start dnode worker since %s", terrstr());
|
||||
dndSetStatus(pDnode, DND_STAT_RUNNING);
|
||||
|
||||
for (ENodeType n = 0; n < NODE_MAX; ++n) {
|
||||
SMgmtWrapper *pWrapper = &pDnode->wrappers[n];
|
||||
if (!pWrapper->required) continue;
|
||||
if (pWrapper->fp.startFp == NULL) continue;
|
||||
if (pWrapper->procType == PROC_PARENT && n != DNODE) continue;
|
||||
if (pWrapper->procType == PROC_CHILD && n == DNODE) continue;
|
||||
if ((*pWrapper->fp.startFp)(pWrapper) != 0) {
|
||||
dError("node:%s, failed to start since %s", pWrapper->name, terrstr());
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
dndReleaseWrapper(pWrapper);
|
||||
#endif
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
|
@ -16,11 +16,13 @@
|
|||
#define _DEFAULT_SOURCE
|
||||
#include "dndInt.h"
|
||||
|
||||
#define MAXLEN 1024
|
||||
|
||||
int32_t dndReadFile(SMgmtWrapper *pWrapper, bool *pDeployed) {
|
||||
int32_t code = TSDB_CODE_NODE_PARSE_FILE_ERROR;
|
||||
int32_t len = 0;
|
||||
int32_t maxLen = 1024;
|
||||
char *content = taosMemoryCalloc(1, maxLen + 1);
|
||||
const int32_t maxLen = MAXLEN;
|
||||
char content[MAXLEN + 1] = {0};
|
||||
cJSON *root = NULL;
|
||||
char file[PATH_MAX];
|
||||
TdFilePtr pFile = NULL;
|
||||
|
@ -57,7 +59,6 @@ int32_t dndReadFile(SMgmtWrapper *pWrapper, bool *pDeployed) {
|
|||
dDebug("succcessed to read file %s, deployed:%d", file, *pDeployed);
|
||||
|
||||
_OVER:
|
||||
if (content != NULL) taosMemoryFree(content);
|
||||
if (root != NULL) cJSON_Delete(root);
|
||||
if (pFile != NULL) taosCloseFile(&pFile);
|
||||
|
||||
|
@ -66,7 +67,7 @@ _OVER:
|
|||
}
|
||||
|
||||
int32_t dndWriteFile(SMgmtWrapper *pWrapper, bool deployed) {
|
||||
char file[PATH_MAX];
|
||||
char file[PATH_MAX] = {0};
|
||||
snprintf(file, sizeof(file), "%s%s%s.json", pWrapper->path, TD_DIRSEP, pWrapper->name);
|
||||
|
||||
TdFilePtr pFile = taosOpenFile(file, TD_FILE_CTEATE | TD_FILE_WRITE | TD_FILE_TRUNC);
|
||||
|
@ -77,8 +78,8 @@ int32_t dndWriteFile(SMgmtWrapper *pWrapper, bool deployed) {
|
|||
}
|
||||
|
||||
int32_t len = 0;
|
||||
int32_t maxLen = 1024;
|
||||
char *content = taosMemoryCalloc(1, maxLen + 1);
|
||||
const int32_t maxLen = MAXLEN;
|
||||
char content[MAXLEN + 1] = {0};
|
||||
|
||||
len += snprintf(content + len, maxLen - len, "{\n");
|
||||
len += snprintf(content + len, maxLen - len, " \"deployed\": %d\n", deployed);
|
||||
|
@ -87,9 +88,8 @@ int32_t dndWriteFile(SMgmtWrapper *pWrapper, bool deployed) {
|
|||
taosWriteFile(pFile, content, len);
|
||||
taosFsyncFile(pFile);
|
||||
taosCloseFile(&pFile);
|
||||
taosMemoryFree(content);
|
||||
|
||||
char realfile[PATH_MAX];
|
||||
char realfile[PATH_MAX] = {0};
|
||||
snprintf(realfile, sizeof(realfile), "%s%s%s.json", pWrapper->path, TD_DIRSEP, pWrapper->name);
|
||||
|
||||
if (taosRenameFile(file, realfile) != 0) {
|
||||
|
|
|
@ -43,36 +43,40 @@ static inline int32_t dndBuildMsg(SNodeMsg *pMsg, SRpcMsg *pRpc) {
|
|||
|
||||
memcpy(pMsg->user, connInfo.user, TSDB_USER_LEN);
|
||||
memcpy(&pMsg->rpcMsg, pRpc, sizeof(SRpcMsg));
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void dndProcessRpcMsg(SMgmtWrapper *pWrapper, SRpcMsg *pRpc, SEpSet *pEpSet) {
|
||||
if (pEpSet && pEpSet->numOfEps > 0 && pRpc->msgType == TDMT_MND_STATUS_RSP) {
|
||||
dndUpdateMnodeEpSet(pWrapper->pDnode, pEpSet);
|
||||
}
|
||||
|
||||
int32_t code = -1;
|
||||
SNodeMsg *pMsg = NULL;
|
||||
NodeMsgFp msgFp = NULL;
|
||||
|
||||
if (pEpSet && pEpSet->numOfEps > 0 && pRpc->msgType == TDMT_MND_STATUS_RSP) {
|
||||
dndUpdateMnodeEpSet(pWrapper->pDnode, pEpSet);
|
||||
}
|
||||
|
||||
if (dndMarkWrapper(pWrapper) != 0) goto _OVER;
|
||||
if ((msgFp = dndGetMsgFp(pWrapper, pRpc)) == NULL) goto _OVER;
|
||||
if ((pMsg = taosAllocateQitem(sizeof(SNodeMsg))) == NULL) goto _OVER;
|
||||
if (dndBuildMsg(pMsg, pRpc) != 0) goto _OVER;
|
||||
|
||||
dTrace("msg:%p, is created, handle:%p app:%p user:%s", pMsg, pRpc->handle, pRpc->ahandle, pMsg->user);
|
||||
if (pWrapper->procType == PROC_SINGLE) {
|
||||
dTrace("msg:%p, is created, handle:%p app:%p user:%s", pMsg, pRpc->handle, pRpc->ahandle, pMsg->user);
|
||||
code = (*msgFp)(pWrapper->pMgmt, pMsg);
|
||||
} else if (pWrapper->procType == PROC_PARENT) {
|
||||
dTrace("msg:%p, is created and will put into child queue, handle:%p app:%p user:%s", pMsg, pRpc->handle,
|
||||
pRpc->ahandle, pMsg->user);
|
||||
code = taosProcPutToChildQueue(pWrapper->pProc, pMsg, sizeof(SNodeMsg), pRpc->pCont, pRpc->contLen);
|
||||
} else {
|
||||
dTrace("msg:%p, should not processed in child process, handle:%p app:%p user:%s", pMsg, pRpc->handle, pRpc->ahandle,
|
||||
pMsg->user);
|
||||
ASSERT(1);
|
||||
}
|
||||
|
||||
_OVER:
|
||||
if (code == 0) {
|
||||
if (pWrapper->procType == PROC_PARENT) {
|
||||
dTrace("msg:%p, is freed", pMsg);
|
||||
dTrace("msg:%p, is freed in parent process", pMsg);
|
||||
taosFreeQitem(pMsg);
|
||||
rpcFreeCont(pRpc->pCont);
|
||||
}
|
||||
|
|
|
@ -175,7 +175,7 @@ int32_t dndMarkWrapper(SMgmtWrapper *pWrapper) {
|
|||
int32_t code = 0;
|
||||
|
||||
taosRLockLatch(&pWrapper->latch);
|
||||
if (pWrapper->deployed) {
|
||||
if (pWrapper->deployed || (pWrapper->procType == PROC_PARENT && pWrapper->required)) {
|
||||
int32_t refCount = atomic_add_fetch_32(&pWrapper->refCount, 1);
|
||||
dTrace("node:%s, is marked, refCount:%d", pWrapper->name, refCount);
|
||||
} else {
|
||||
|
|
|
@ -348,7 +348,7 @@ int32_t dndSendReqToMnode(SMgmtWrapper *pWrapper, SRpcMsg *pReq) {
|
|||
}
|
||||
}
|
||||
|
||||
void dndSendRpcRsp(SMgmtWrapper *pWrapper, SRpcMsg *pRsp) {
|
||||
static void dndSendRpcRsp(SMgmtWrapper *pWrapper, SRpcMsg *pRsp) {
|
||||
if (pRsp->code == TSDB_CODE_APP_NOT_READY) {
|
||||
SMgmtWrapper *pDnodeWrapper = dndAcquireWrapper(pWrapper->pDnode, DNODE);
|
||||
if (pDnodeWrapper != NULL) {
|
||||
|
|
|
@ -36,7 +36,7 @@ void dmSendStatusReq(SDnodeMgmt *pMgmt) {
|
|||
req.clusterCfg.checkTime = 0;
|
||||
char timestr[32] = "1970-01-01 00:00:00.00";
|
||||
(void)taosParseTime(timestr, &req.clusterCfg.checkTime, (int32_t)strlen(timestr), TSDB_TIME_PRECISION_MILLI, 0);
|
||||
memcpy(req.clusterCfg.timezone, tsTimezone, TD_TIMEZONE_LEN);
|
||||
memcpy(req.clusterCfg.timezone, tsTimezoneStr, TD_TIMEZONE_LEN);
|
||||
memcpy(req.clusterCfg.locale, tsLocale, TD_LOCALE_LEN);
|
||||
memcpy(req.clusterCfg.charset, tsCharset, TD_LOCALE_LEN);
|
||||
taosRUnLockLatch(&pMgmt->latch);
|
||||
|
|
|
@ -160,6 +160,24 @@ static void vmProcessSyncQueue(SQueueInfo *pInfo, STaosQall *qall, int32_t numOf
|
|||
}
|
||||
}
|
||||
|
||||
static void vmProcessMergeQueue(SQueueInfo *pInfo, STaosQall *qall, int32_t numOfMsgs) {
|
||||
SVnodeObj *pVnode = pInfo->ahandle;
|
||||
SNodeMsg *pMsg = NULL;
|
||||
|
||||
for (int32_t i = 0; i < numOfMsgs; ++i) {
|
||||
taosGetQitem(qall, (void **)&pMsg);
|
||||
|
||||
dTrace("msg:%p, will be processed in vnode-merge queue", pMsg);
|
||||
int32_t code = vnodeProcessFetchMsg(pVnode->pImpl, &pMsg->rpcMsg);
|
||||
if (code != 0) {
|
||||
vmSendRsp(pVnode->pWrapper, pMsg, code);
|
||||
dTrace("msg:%p, is freed, result:0x%04x:%s", pMsg, code & 0XFFFF, tstrerror(code));
|
||||
rpcFreeCont(pMsg->rpcMsg.pCont);
|
||||
taosFreeQitem(pMsg);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static int32_t vmPutNodeMsgToQueue(SVnodesMgmt *pMgmt, SNodeMsg *pMsg, EQueueType qtype) {
|
||||
SRpcMsg *pRpc = &pMsg->rpcMsg;
|
||||
int32_t code = -1;
|
||||
|
@ -308,7 +326,7 @@ int32_t vmGetQueueSize(SMgmtWrapper *pWrapper, int32_t vgId, EQueueType qtype) {
|
|||
int32_t vmAllocQueue(SVnodesMgmt *pMgmt, SVnodeObj *pVnode) {
|
||||
pVnode->pWriteQ = tWWorkerAllocQueue(&pMgmt->writePool, pVnode, (FItems)vmProcessWriteQueue);
|
||||
pVnode->pApplyQ = tWWorkerAllocQueue(&pMgmt->writePool, pVnode, (FItems)vmProcessApplyQueue);
|
||||
pVnode->pMergeQ = tWWorkerAllocQueue(&pMgmt->mergePool, pVnode, (FItems)vmProcessMergeMsg);
|
||||
pVnode->pMergeQ = tWWorkerAllocQueue(&pMgmt->mergePool, pVnode, (FItems)vmProcessMergeQueue);
|
||||
pVnode->pSyncQ = tWWorkerAllocQueue(&pMgmt->syncPool, pVnode, (FItems)vmProcessSyncQueue);
|
||||
pVnode->pFetchQ = tQWorkerAllocQueue(&pMgmt->fetchPool, pVnode, (FItem)vmProcessFetchQueue);
|
||||
pVnode->pQueryQ = tQWorkerAllocQueue(&pMgmt->queryPool, pVnode, (FItem)vmProcessQueryQueue);
|
||||
|
|
|
@ -645,6 +645,7 @@ typedef struct {
|
|||
char* sql;
|
||||
char* logicalPlan;
|
||||
char* physicalPlan;
|
||||
SSchemaWrapper schema;
|
||||
} SMqTopicObj;
|
||||
|
||||
typedef struct {
|
||||
|
@ -738,7 +739,7 @@ typedef struct {
|
|||
char* logicalPlan;
|
||||
char* physicalPlan;
|
||||
SArray* tasks; // SArray<SArray<SStreamTask>>
|
||||
SArray* ColAlias; // SArray<char*>
|
||||
SSchemaWrapper outputSchema;
|
||||
} SStreamObj;
|
||||
|
||||
int32_t tEncodeSStreamObj(SCoder* pEncoder, const SStreamObj* pObj);
|
||||
|
|
|
@ -17,7 +17,7 @@
|
|||
|
||||
int32_t tEncodeSStreamObj(SCoder *pEncoder, const SStreamObj *pObj) {
|
||||
int32_t sz = 0;
|
||||
int32_t outputNameSz = 0;
|
||||
/*int32_t outputNameSz = 0;*/
|
||||
if (tEncodeCStr(pEncoder, pObj->name) < 0) return -1;
|
||||
if (tEncodeCStr(pEncoder, pObj->db) < 0) return -1;
|
||||
if (tEncodeI64(pEncoder, pObj->createTime) < 0) return -1;
|
||||
|
@ -45,6 +45,9 @@ int32_t tEncodeSStreamObj(SCoder *pEncoder, const SStreamObj *pObj) {
|
|||
}
|
||||
}
|
||||
|
||||
if (tEncodeSSchemaWrapper(pEncoder, &pObj->outputSchema) < 0) return -1;
|
||||
|
||||
#if 0
|
||||
if (pObj->ColAlias != NULL) {
|
||||
outputNameSz = taosArrayGetSize(pObj->ColAlias);
|
||||
}
|
||||
|
@ -53,6 +56,7 @@ int32_t tEncodeSStreamObj(SCoder *pEncoder, const SStreamObj *pObj) {
|
|||
char *name = taosArrayGetP(pObj->ColAlias, i);
|
||||
if (tEncodeCStr(pEncoder, name) < 0) return -1;
|
||||
}
|
||||
#endif
|
||||
return pEncoder->pos;
|
||||
}
|
||||
|
||||
|
@ -85,6 +89,9 @@ int32_t tDecodeSStreamObj(SCoder *pDecoder, SStreamObj *pObj) {
|
|||
taosArrayPush(pObj->tasks, pArray);
|
||||
}
|
||||
}
|
||||
|
||||
if (tDecodeSSchemaWrapper(pDecoder, &pObj->outputSchema) < 0) return -1;
|
||||
#if 0
|
||||
int32_t outputNameSz;
|
||||
if (tDecodeI32(pDecoder, &outputNameSz) < 0) return -1;
|
||||
if (outputNameSz != 0) {
|
||||
|
@ -98,5 +105,6 @@ int32_t tDecodeSStreamObj(SCoder *pDecoder, SStreamObj *pObj) {
|
|||
if (tDecodeCStrAlloc(pDecoder, &name) < 0) return -1;
|
||||
taosArrayPush(pObj->ColAlias, &name);
|
||||
}
|
||||
#endif
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -277,8 +277,8 @@ static int32_t mndCheckClusterCfgPara(SMnode *pMnode, const SClusterCfg *pCfg) {
|
|||
return DND_REASON_STATUS_INTERVAL_NOT_MATCH;
|
||||
}
|
||||
|
||||
if ((0 != strcasecmp(pCfg->timezone, tsTimezone)) && (pMnode->checkTime != pCfg->checkTime)) {
|
||||
mError("timezone [%s - %s] [%" PRId64 " - %" PRId64 "] cfg inconsistent", pCfg->timezone, tsTimezone,
|
||||
if ((0 != strcasecmp(pCfg->timezone, tsTimezoneStr)) && (pMnode->checkTime != pCfg->checkTime)) {
|
||||
mError("timezone [%s - %s] [%" PRId64 " - %" PRId64 "] cfg inconsistent", pCfg->timezone, tsTimezoneStr,
|
||||
pCfg->checkTime, pMnode->checkTime);
|
||||
return DND_REASON_TIME_ZONE_NOT_MATCH;
|
||||
}
|
||||
|
@ -677,7 +677,7 @@ static int32_t mndRetrieveConfigs(SNodeMsg *pReq, SShowObj *pShow, char *data, i
|
|||
totalRows++;
|
||||
|
||||
cfgOpts[totalRows] = "timezone";
|
||||
snprintf(cfgVals[totalRows], TSDB_CONIIG_VALUE_LEN, "%s", tsTimezone);
|
||||
snprintf(cfgVals[totalRows], TSDB_CONIIG_VALUE_LEN, "%s", tsTimezoneStr);
|
||||
totalRows++;
|
||||
|
||||
cfgOpts[totalRows] = "locale";
|
||||
|
|
|
@ -185,6 +185,7 @@ int32_t mndScheduleStream(SMnode* pMnode, STrans* pTrans, SStreamObj* pStream) {
|
|||
pTask->dispatchMsgType = TDMT_VND_TASK_MERGE_EXEC;
|
||||
pTask->dispatchType = TASK_DISPATCH__FIXED;
|
||||
|
||||
pTask->fixedEpDispatcher.taskId = lastLevelTask->taskId;
|
||||
pTask->fixedEpDispatcher.nodeId = lastLevelTask->nodeId;
|
||||
pTask->fixedEpDispatcher.epSet = lastLevelTask->epSet;
|
||||
}
|
||||
|
|
|
@ -98,7 +98,7 @@ SSdbRaw *mndStbActionEncode(SStbObj *pStb) {
|
|||
for (int32_t i = 0; i < pStb->numOfColumns; ++i) {
|
||||
SSchema *pSchema = &pStb->pColumns[i];
|
||||
SDB_SET_INT8(pRaw, dataPos, pSchema->type, STB_ENCODE_OVER)
|
||||
SDB_SET_INT32(pRaw, dataPos, pSchema->colId, STB_ENCODE_OVER)
|
||||
SDB_SET_INT16(pRaw, dataPos, pSchema->colId, STB_ENCODE_OVER)
|
||||
SDB_SET_INT32(pRaw, dataPos, pSchema->bytes, STB_ENCODE_OVER)
|
||||
SDB_SET_BINARY(pRaw, dataPos, pSchema->name, TSDB_COL_NAME_LEN, STB_ENCODE_OVER)
|
||||
}
|
||||
|
@ -106,7 +106,7 @@ SSdbRaw *mndStbActionEncode(SStbObj *pStb) {
|
|||
for (int32_t i = 0; i < pStb->numOfTags; ++i) {
|
||||
SSchema *pSchema = &pStb->pTags[i];
|
||||
SDB_SET_INT8(pRaw, dataPos, pSchema->type, STB_ENCODE_OVER)
|
||||
SDB_SET_INT32(pRaw, dataPos, pSchema->colId, STB_ENCODE_OVER)
|
||||
SDB_SET_INT16(pRaw, dataPos, pSchema->colId, STB_ENCODE_OVER)
|
||||
SDB_SET_INT32(pRaw, dataPos, pSchema->bytes, STB_ENCODE_OVER)
|
||||
SDB_SET_BINARY(pRaw, dataPos, pSchema->name, TSDB_COL_NAME_LEN, STB_ENCODE_OVER)
|
||||
}
|
||||
|
@ -114,7 +114,7 @@ SSdbRaw *mndStbActionEncode(SStbObj *pStb) {
|
|||
for (int32_t i = 0; i < pStb->numOfSmas; ++i) {
|
||||
SSchema *pSchema = &pStb->pSmas[i];
|
||||
SDB_SET_INT8(pRaw, dataPos, pSchema->type, STB_ENCODE_OVER)
|
||||
SDB_SET_INT32(pRaw, dataPos, pSchema->colId, STB_ENCODE_OVER)
|
||||
SDB_SET_INT16(pRaw, dataPos, pSchema->colId, STB_ENCODE_OVER)
|
||||
SDB_SET_INT32(pRaw, dataPos, pSchema->bytes, STB_ENCODE_OVER)
|
||||
SDB_SET_BINARY(pRaw, dataPos, pSchema->name, TSDB_COL_NAME_LEN, STB_ENCODE_OVER)
|
||||
}
|
||||
|
@ -185,7 +185,7 @@ static SSdbRow *mndStbActionDecode(SSdbRaw *pRaw) {
|
|||
for (int32_t i = 0; i < pStb->numOfColumns; ++i) {
|
||||
SSchema *pSchema = &pStb->pColumns[i];
|
||||
SDB_GET_INT8(pRaw, dataPos, &pSchema->type, STB_DECODE_OVER)
|
||||
SDB_GET_INT32(pRaw, dataPos, &pSchema->colId, STB_DECODE_OVER)
|
||||
SDB_GET_INT16(pRaw, dataPos, &pSchema->colId, STB_DECODE_OVER)
|
||||
SDB_GET_INT32(pRaw, dataPos, &pSchema->bytes, STB_DECODE_OVER)
|
||||
SDB_GET_BINARY(pRaw, dataPos, pSchema->name, TSDB_COL_NAME_LEN, STB_DECODE_OVER)
|
||||
}
|
||||
|
@ -193,7 +193,7 @@ static SSdbRow *mndStbActionDecode(SSdbRaw *pRaw) {
|
|||
for (int32_t i = 0; i < pStb->numOfTags; ++i) {
|
||||
SSchema *pSchema = &pStb->pTags[i];
|
||||
SDB_GET_INT8(pRaw, dataPos, &pSchema->type, STB_DECODE_OVER)
|
||||
SDB_GET_INT32(pRaw, dataPos, &pSchema->colId, STB_DECODE_OVER)
|
||||
SDB_GET_INT16(pRaw, dataPos, &pSchema->colId, STB_DECODE_OVER)
|
||||
SDB_GET_INT32(pRaw, dataPos, &pSchema->bytes, STB_DECODE_OVER)
|
||||
SDB_GET_BINARY(pRaw, dataPos, pSchema->name, TSDB_COL_NAME_LEN, STB_DECODE_OVER)
|
||||
}
|
||||
|
@ -201,7 +201,7 @@ static SSdbRow *mndStbActionDecode(SSdbRaw *pRaw) {
|
|||
for (int32_t i = 0; i < pStb->numOfSmas; ++i) {
|
||||
SSchema *pSchema = &pStb->pSmas[i];
|
||||
SDB_GET_INT8(pRaw, dataPos, &pSchema->type, STB_DECODE_OVER)
|
||||
SDB_GET_INT32(pRaw, dataPos, &pSchema->colId, STB_DECODE_OVER)
|
||||
SDB_GET_INT16(pRaw, dataPos, &pSchema->colId, STB_DECODE_OVER)
|
||||
SDB_GET_INT32(pRaw, dataPos, &pSchema->bytes, STB_DECODE_OVER)
|
||||
SDB_GET_BINARY(pRaw, dataPos, pSchema->name, TSDB_COL_NAME_LEN, STB_DECODE_OVER)
|
||||
}
|
||||
|
|
|
@ -14,7 +14,6 @@
|
|||
*/
|
||||
|
||||
#include "mndStream.h"
|
||||
#include "parser.h"
|
||||
#include "mndAuth.h"
|
||||
#include "mndDb.h"
|
||||
#include "mndDnode.h"
|
||||
|
@ -26,6 +25,7 @@
|
|||
#include "mndTrans.h"
|
||||
#include "mndUser.h"
|
||||
#include "mndVgroup.h"
|
||||
#include "parser.h"
|
||||
#include "tname.h"
|
||||
|
||||
#define MND_STREAM_VER_NUMBER 1
|
||||
|
@ -248,23 +248,22 @@ static int32_t mndStreamGetPlanString(const char *ast, char **pStr) {
|
|||
|
||||
int32_t mndAddStreamToTrans(SMnode *pMnode, SStreamObj *pStream, const char *ast, STrans *pTrans) {
|
||||
SNode *pAst = NULL;
|
||||
#if 1 // TODO: remove debug info later
|
||||
printf("ast = %s\n", ast);
|
||||
#endif
|
||||
|
||||
if (nodesStringToNode(ast, &pAst) < 0) {
|
||||
return -1;
|
||||
}
|
||||
#if 1
|
||||
SSchemaWrapper sw = {0};
|
||||
qExtractResultSchema(pAst, (int32_t*)&sw.nCols, &sw.pSchema);
|
||||
|
||||
if (qExtractResultSchema(pAst, (int32_t *)&pStream->outputSchema.nCols, &pStream->outputSchema.pSchema) != 0) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
#if 1
|
||||
printf("|");
|
||||
for (int i = 0; i < sw.nCols; i++) {
|
||||
printf(" %15s |", (char *)sw.pSchema[i].name);
|
||||
for (int i = 0; i < pStream->outputSchema.nCols; i++) {
|
||||
printf(" %15s |", (char *)pStream->outputSchema.pSchema[i].name);
|
||||
}
|
||||
printf("\n=======================================================\n");
|
||||
|
||||
pStream->ColAlias = NULL;
|
||||
#endif
|
||||
|
||||
if (TSDB_CODE_SUCCESS != mndStreamGetPlanString(ast, &pStream->physicalPlan)) {
|
||||
|
|
|
@ -23,6 +23,7 @@
|
|||
#include "mndTrans.h"
|
||||
#include "mndUser.h"
|
||||
#include "mndVgroup.h"
|
||||
#include "parser.h"
|
||||
#include "tname.h"
|
||||
|
||||
#define MND_TOPIC_VER_NUMBER 1
|
||||
|
@ -85,6 +86,16 @@ SSdbRaw *mndTopicActionEncode(SMqTopicObj *pTopic) {
|
|||
SDB_SET_INT32(pRaw, dataPos, physicalPlanLen, TOPIC_ENCODE_OVER);
|
||||
SDB_SET_BINARY(pRaw, dataPos, pTopic->physicalPlan, physicalPlanLen, TOPIC_ENCODE_OVER);
|
||||
|
||||
int32_t swLen = taosEncodeSSchemaWrapper(NULL, &pTopic->schema);
|
||||
void *swBuf = taosMemoryMalloc(swLen);
|
||||
if (swBuf == NULL) {
|
||||
goto TOPIC_ENCODE_OVER;
|
||||
}
|
||||
void *aswBuf = swBuf;
|
||||
taosEncodeSSchemaWrapper(&aswBuf, &pTopic->schema);
|
||||
SDB_SET_INT32(pRaw, dataPos, swLen, TOPIC_ENCODE_OVER);
|
||||
SDB_SET_BINARY(pRaw, dataPos, swBuf, swLen, TOPIC_ENCODE_OVER);
|
||||
|
||||
SDB_SET_RESERVE(pRaw, dataPos, MND_TOPIC_RESERVE_SIZE, TOPIC_ENCODE_OVER);
|
||||
SDB_SET_DATALEN(pRaw, dataPos, TOPIC_ENCODE_OVER);
|
||||
|
||||
|
@ -149,6 +160,17 @@ SSdbRow *mndTopicActionDecode(SSdbRaw *pRaw) {
|
|||
}
|
||||
SDB_GET_BINARY(pRaw, dataPos, pTopic->physicalPlan, len, TOPIC_DECODE_OVER);
|
||||
|
||||
SDB_GET_INT32(pRaw, dataPos, &len, TOPIC_DECODE_OVER);
|
||||
void *buf = taosMemoryMalloc(len);
|
||||
if (buf == NULL) {
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
goto TOPIC_DECODE_OVER;
|
||||
}
|
||||
SDB_GET_BINARY(pRaw, dataPos, buf, len, TOPIC_DECODE_OVER);
|
||||
if (taosDecodeSSchemaWrapper(buf, &pTopic->schema) == NULL) {
|
||||
goto TOPIC_DECODE_OVER;
|
||||
}
|
||||
|
||||
SDB_GET_RESERVE(pRaw, dataPos, MND_TOPIC_RESERVE_SIZE, TOPIC_DECODE_OVER);
|
||||
|
||||
terrno = TSDB_CODE_SUCCESS;
|
||||
|
@ -283,6 +305,14 @@ static int32_t mndCreateTopic(SMnode *pMnode, SNodeMsg *pReq, SCMCreateTopicReq
|
|||
topicObj.physicalPlan = pPlanStr;
|
||||
}
|
||||
|
||||
SNode *pAst = NULL;
|
||||
if (nodesStringToNode(pCreate->ast, &pAst) < 0) {
|
||||
return -1;
|
||||
}
|
||||
if (qExtractResultSchema(pAst, &topicObj.schema.nCols, &topicObj.schema.pSchema) != 0) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
STrans *pTrans = mndTransCreate(pMnode, TRN_POLICY_ROLLBACK, TRN_TYPE_CREATE_TOPIC, &pReq->rpcMsg);
|
||||
if (pTrans == NULL) {
|
||||
mError("topic:%s, failed to create since %s", pCreate->name, terrstr());
|
||||
|
|
|
@ -270,7 +270,7 @@ static int32_t mndCreateUser(SMnode *pMnode, char *acct, SCreateUserReq *pCreate
|
|||
userObj.updateTime = userObj.createdTime;
|
||||
userObj.superUser = pCreate->superUser;
|
||||
|
||||
STrans *pTrans = mndTransCreate(pMnode, TRN_POLICY_ROLLBACK,TRN_TYPE_CREATE_USER, &pReq->rpcMsg);
|
||||
STrans *pTrans = mndTransCreate(pMnode, TRN_POLICY_ROLLBACK, TRN_TYPE_CREATE_USER, &pReq->rpcMsg);
|
||||
if (pTrans == NULL) {
|
||||
mError("user:%s, failed to create since %s", pCreate->user, terrstr());
|
||||
return -1;
|
||||
|
@ -350,7 +350,7 @@ CREATE_USER_OVER:
|
|||
}
|
||||
|
||||
static int32_t mndUpdateUser(SMnode *pMnode, SUserObj *pOld, SUserObj *pNew, SNodeMsg *pReq) {
|
||||
STrans *pTrans = mndTransCreate(pMnode, TRN_POLICY_ROLLBACK, TRN_TYPE_ALTER_USER,&pReq->rpcMsg);
|
||||
STrans *pTrans = mndTransCreate(pMnode, TRN_POLICY_ROLLBACK, TRN_TYPE_ALTER_USER, &pReq->rpcMsg);
|
||||
if (pTrans == NULL) {
|
||||
mError("user:%s, failed to update since %s", pOld->user, terrstr());
|
||||
return -1;
|
||||
|
@ -511,7 +511,7 @@ ALTER_USER_OVER:
|
|||
}
|
||||
|
||||
static int32_t mndDropUser(SMnode *pMnode, SNodeMsg *pReq, SUserObj *pUser) {
|
||||
STrans *pTrans = mndTransCreate(pMnode, TRN_POLICY_ROLLBACK,TRN_TYPE_DROP_USER, &pReq->rpcMsg);
|
||||
STrans *pTrans = mndTransCreate(pMnode, TRN_POLICY_ROLLBACK, TRN_TYPE_DROP_USER, &pReq->rpcMsg);
|
||||
if (pTrans == NULL) {
|
||||
mError("user:%s, failed to drop since %s", pUser->user, terrstr());
|
||||
return -1;
|
||||
|
|
|
@ -233,7 +233,7 @@ int metaSaveSmaToDB(SMeta *pMeta, STSma *pSmaCfg) {
|
|||
|
||||
// save sma info
|
||||
int32_t len = tEncodeTSma(NULL, pSmaCfg);
|
||||
pBuf = taosMemoryCalloc(len, 1);
|
||||
pBuf = taosMemoryCalloc(1, len);
|
||||
if (pBuf == NULL) {
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
return -1;
|
||||
|
@ -285,7 +285,7 @@ static int metaEncodeSchema(void **buf, SSchemaWrapper *pSW) {
|
|||
for (int i = 0; i < pSW->nCols; i++) {
|
||||
pSchema = pSW->pSchema + i;
|
||||
tlen += taosEncodeFixedI8(buf, pSchema->type);
|
||||
tlen += taosEncodeFixedI32(buf, pSchema->colId);
|
||||
tlen += taosEncodeFixedI16(buf, pSchema->colId);
|
||||
tlen += taosEncodeFixedI32(buf, pSchema->bytes);
|
||||
tlen += taosEncodeString(buf, pSchema->name);
|
||||
}
|
||||
|
@ -301,7 +301,7 @@ static void *metaDecodeSchema(void *buf, SSchemaWrapper *pSW) {
|
|||
for (int i = 0; i < pSW->nCols; i++) {
|
||||
pSchema = pSW->pSchema + i;
|
||||
buf = taosDecodeFixedI8(buf, &pSchema->type);
|
||||
buf = taosDecodeFixedI32(buf, &pSchema->colId);
|
||||
buf = taosDecodeFixedI16(buf, &pSchema->colId);
|
||||
buf = taosDecodeFixedI32(buf, &pSchema->bytes);
|
||||
buf = taosDecodeStringTo(buf, pSchema->name);
|
||||
}
|
||||
|
@ -516,6 +516,7 @@ static int metaEncodeTbInfo(void **buf, STbCfg *pTbCfg) {
|
|||
tsize += taosEncodeFixedU64(buf, pTbCfg->ctbCfg.suid);
|
||||
tsize += tdEncodeKVRow(buf, pTbCfg->ctbCfg.pTag);
|
||||
} else if (pTbCfg->type == META_NORMAL_TABLE) {
|
||||
// TODO
|
||||
} else {
|
||||
ASSERT(0);
|
||||
}
|
||||
|
@ -538,6 +539,7 @@ static void *metaDecodeTbInfo(void *buf, STbCfg *pTbCfg) {
|
|||
buf = taosDecodeFixedU64(buf, &(pTbCfg->ctbCfg.suid));
|
||||
buf = tdDecodeKVRow(buf, &(pTbCfg->ctbCfg.pTag));
|
||||
} else if (pTbCfg->type == META_NORMAL_TABLE) {
|
||||
// TODO
|
||||
} else {
|
||||
ASSERT(0);
|
||||
}
|
||||
|
|
|
@ -42,8 +42,8 @@ STQ* tqOpen(const char* path, SVnode* pVnode, SWal* pWal, SMeta* pVnodeMeta, STq
|
|||
// TODO: error code of buffer pool
|
||||
}
|
||||
#endif
|
||||
pTq->tqMeta =
|
||||
tqStoreOpen(pTq, path, (FTqSerialize)tqSerializeConsumer, (FTqDeserialize)tqDeserializeConsumer, (FTqDelete)taosMemoryFree, 0);
|
||||
pTq->tqMeta = tqStoreOpen(pTq, path, (FTqSerialize)tqSerializeConsumer, (FTqDeserialize)tqDeserializeConsumer,
|
||||
(FTqDelete)taosMemoryFree, 0);
|
||||
if (pTq->tqMeta == NULL) {
|
||||
taosMemoryFree(pTq);
|
||||
#if 0
|
||||
|
@ -498,12 +498,16 @@ int32_t tqProcessStreamTrigger(STQ* pTq, void* data, int32_t dataLen) {
|
|||
}
|
||||
|
||||
int32_t tqProcessTaskExec(STQ* pTq, SRpcMsg* msg) {
|
||||
SStreamTaskExecReq* pReq = msg->pCont;
|
||||
int32_t taskId = pReq->taskId;
|
||||
char* msgstr = POINTER_SHIFT(msg->pCont, sizeof(SMsgHead));
|
||||
|
||||
SStreamTaskExecReq req;
|
||||
tDecodeSStreamTaskExecReq(msgstr, &req);
|
||||
|
||||
int32_t taskId = req.taskId;
|
||||
SStreamTask* pTask = taosHashGet(pTq->pStreamTasks, &taskId, sizeof(int32_t));
|
||||
ASSERT(pTask);
|
||||
|
||||
if (streamExecTask(pTask, &pTq->pVnode->msgCb, pReq->data, STREAM_DATA_TYPE_SSDATA_BLOCK, 0) < 0) {
|
||||
if (streamExecTask(pTask, &pTq->pVnode->msgCb, req.data, STREAM_DATA_TYPE_SSDATA_BLOCK, 0) < 0) {
|
||||
// TODO
|
||||
}
|
||||
return 0;
|
||||
|
|
|
@ -130,8 +130,8 @@ SArray* tqRetrieveDataBlock(STqReadHandle* pHandle) {
|
|||
int32_t colNeed = 0;
|
||||
while (colMeta < pSchemaWrapper->nCols && colNeed < colNumNeed) {
|
||||
SSchema* pColSchema = &pSchemaWrapper->pSchema[colMeta];
|
||||
int16_t colIdSchema = pColSchema->colId;
|
||||
int16_t colIdNeed = *(int16_t*)taosArrayGet(pHandle->pColIdList, colNeed);
|
||||
col_id_t colIdSchema = pColSchema->colId;
|
||||
col_id_t colIdNeed = *(col_id_t*)taosArrayGet(pHandle->pColIdList, colNeed);
|
||||
if (colIdSchema < colIdNeed) {
|
||||
colMeta++;
|
||||
} else if (colIdSchema > colIdNeed) {
|
||||
|
@ -159,7 +159,7 @@ SArray* tqRetrieveDataBlock(STqReadHandle* pHandle) {
|
|||
|
||||
int j = 0;
|
||||
for (int32_t i = 0; i < colNumNeed; i++) {
|
||||
int16_t colId = *(int16_t*)taosArrayGet(pHandle->pColIdList, i);
|
||||
col_id_t colId = *(col_id_t*)taosArrayGet(pHandle->pColIdList, i);
|
||||
while (j < pSchemaWrapper->nCols && pSchemaWrapper->pSchema[j].colId < colId) {
|
||||
j++;
|
||||
}
|
||||
|
|
|
@ -1369,7 +1369,7 @@ int tsdbWriteBlockImpl(STsdb *pRepo, STable *pTable, SDFile *pDFile, SDFile *pDF
|
|||
}
|
||||
}
|
||||
|
||||
// Update pBlock membership vairables
|
||||
// Update pBlock membership variables
|
||||
pBlock->last = isLast;
|
||||
pBlock->offset = offset;
|
||||
pBlock->algorithm = pCfg->compression;
|
||||
|
|
|
@ -255,7 +255,7 @@ int32_t tdScanAndConvertSubmitMsg(SSubmitReq *pMsg) {
|
|||
return 0;
|
||||
}
|
||||
|
||||
int tsdbScanAndConvertSubmitMsg(STsdb *pTsdb, SSubmitReq *pMsg) {
|
||||
static int tsdbScanAndConvertSubmitMsg(STsdb *pTsdb, SSubmitReq *pMsg) {
|
||||
ASSERT(pMsg != NULL);
|
||||
// STsdbMeta * pMeta = pTsdb->tsdbMeta;
|
||||
SSubmitMsgIter msgIter = {0};
|
||||
|
|
|
@ -40,6 +40,7 @@ typedef enum {
|
|||
typedef struct {
|
||||
STsdb *pTsdb;
|
||||
SDBFile dFile;
|
||||
SSDataBlock *pData; // sma data
|
||||
int32_t interval; // interval with the precision of DB
|
||||
} STSmaWriteH;
|
||||
|
||||
|
@ -98,7 +99,8 @@ static int32_t tsdbGetTSmaDataImpl(STsdb *pTsdb, STSmaDataWrapper *pData, int64_
|
|||
int32_t nMaxResult);
|
||||
|
||||
// insert data
|
||||
static int32_t tsdbInitTSmaWriteH(STSmaWriteH *pSmaH, STsdb *pTsdb, STSmaDataWrapper *pData);
|
||||
static int32_t tsdbInitTSmaWriteH(STSmaWriteH *pSmaH, STsdb *pTsdb, SSDataBlock *pData, int64_t interval,
|
||||
int8_t intervalUnit);
|
||||
static void tsdbDestroyTSmaWriteH(STSmaWriteH *pSmaH);
|
||||
static int32_t tsdbInitTSmaReadH(STSmaReadH *pSmaH, STsdb *pTsdb, int64_t interval, int8_t intervalUnit);
|
||||
static int32_t tsdbGetSmaStorageLevel(int64_t interval, int8_t intervalUnit);
|
||||
|
@ -800,9 +802,10 @@ static int32_t tsdbInsertTSmaDataSection(STSmaWriteH *pSmaH, STSmaDataWrapper *p
|
|||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
static int32_t tsdbInitTSmaWriteH(STSmaWriteH *pSmaH, STsdb *pTsdb, STSmaDataWrapper *pData) {
|
||||
static int32_t tsdbInitTSmaWriteH(STSmaWriteH *pSmaH, STsdb *pTsdb, SSDataBlock *pData, int64_t interval, int8_t intervalUnit) {
|
||||
pSmaH->pTsdb = pTsdb;
|
||||
pSmaH->interval = tsdbGetIntervalByPrecision(pData->interval, pData->intervalUnit, REPO_CFG(pTsdb)->precision);
|
||||
pSmaH->interval = tsdbGetIntervalByPrecision(interval, intervalUnit, REPO_CFG(pTsdb)->precision);
|
||||
pSmaH->pData = pData;
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
|
@ -858,7 +861,7 @@ static int32_t tsdbGetTSmaDays(STsdb *pTsdb, int64_t interval, int32_t storageLe
|
|||
*/
|
||||
static int32_t tsdbInsertTSmaDataImpl(STsdb *pTsdb, char *msg) {
|
||||
STsdbCfg *pCfg = REPO_CFG(pTsdb);
|
||||
STSmaDataWrapper *pData = (STSmaDataWrapper *)msg;
|
||||
SSDataBlock *pData = (SSDataBlock *)msg;
|
||||
SSmaEnv *pEnv = atomic_load_ptr(&pTsdb->pTSmaEnv);
|
||||
int64_t indexUid = SMA_TEST_INDEX_UID;
|
||||
|
||||
|
@ -868,15 +871,15 @@ static int32_t tsdbInsertTSmaDataImpl(STsdb *pTsdb, char *msg) {
|
|||
return terrno;
|
||||
}
|
||||
|
||||
if (pData->dataLen <= 0) {
|
||||
TASSERT(0);
|
||||
terrno = TSDB_CODE_INVALID_PARA;
|
||||
return TSDB_CODE_FAILED;
|
||||
if (pData == NULL) {
|
||||
terrno = TSDB_CODE_INVALID_PTR;
|
||||
tsdbWarn("vgId:%d insert tSma data failed since pData is NULL", REPO_ID(pTsdb));
|
||||
return terrno;
|
||||
}
|
||||
|
||||
STSmaWriteH tSmaH = {0};
|
||||
|
||||
if (tsdbInitTSmaWriteH(&tSmaH, pTsdb, pData) != 0) {
|
||||
if (taosArrayGetSize(pData->pDataBlock) <= 0) {
|
||||
terrno = TSDB_CODE_INVALID_PARA;
|
||||
tsdbWarn("vgId:%d insert tSma data failed since pDataBlock is empty", REPO_ID(pTsdb));
|
||||
return TSDB_CODE_FAILED;
|
||||
}
|
||||
|
||||
|
@ -895,6 +898,14 @@ static int32_t tsdbInsertTSmaDataImpl(STsdb *pTsdb, char *msg) {
|
|||
return TSDB_CODE_FAILED;
|
||||
}
|
||||
|
||||
STSma *pSma = pItem->pSma;
|
||||
|
||||
STSmaWriteH tSmaH = {0};
|
||||
|
||||
if (tsdbInitTSmaWriteH(&tSmaH, pTsdb, pData, pSma->interval, pSma->intervalUnit) != 0) {
|
||||
return TSDB_CODE_FAILED;
|
||||
}
|
||||
|
||||
char rPath[TSDB_FILENAME_LEN] = {0};
|
||||
char aPath[TSDB_FILENAME_LEN] = {0};
|
||||
snprintf(rPath, TSDB_FILENAME_LEN, "%s%s%" PRIi64, SMA_ENV_PATH(pEnv), TD_DIRSEP, indexUid);
|
||||
|
@ -907,8 +918,11 @@ static int32_t tsdbInsertTSmaDataImpl(STsdb *pTsdb, char *msg) {
|
|||
}
|
||||
|
||||
// Step 1: Judge the storage level and days
|
||||
int32_t storageLevel = tsdbGetSmaStorageLevel(pData->interval, pData->intervalUnit);
|
||||
int32_t storageLevel = tsdbGetSmaStorageLevel(pSma->interval, pSma->intervalUnit);
|
||||
int32_t daysPerFile = tsdbGetTSmaDays(pTsdb, tSmaH.interval, storageLevel);
|
||||
|
||||
|
||||
#if 0
|
||||
int32_t fid = (int32_t)(TSDB_KEY_FID(pData->skey, daysPerFile, pCfg->precision));
|
||||
|
||||
// Step 2: Set the DFile for storage of SMA index, and iterate/split the TSma data and store to B+Tree index file
|
||||
|
@ -933,7 +947,7 @@ static int32_t tsdbInsertTSmaDataImpl(STsdb *pTsdb, char *msg) {
|
|||
|
||||
// Step 3: reset the SSmaStat
|
||||
tsdbResetExpiredWindow(pTsdb, SMA_ENV_STAT(pTsdb->pTSmaEnv), pData->indexUid, pData->skey);
|
||||
|
||||
#endif
|
||||
tsdbDestroyTSmaWriteH(&tSmaH);
|
||||
tsdbUnRefSmaStat(pTsdb, pStat);
|
||||
return TSDB_CODE_SUCCESS;
|
||||
|
@ -1000,28 +1014,57 @@ static int32_t tsdbSetRSmaDataFile(STSmaWriteH *pSmaH, STSmaDataWrapper *pData,
|
|||
|
||||
static int32_t tsdbInsertRSmaDataImpl(STsdb *pTsdb, char *msg) {
|
||||
STsdbCfg *pCfg = REPO_CFG(pTsdb);
|
||||
STSmaDataWrapper *pData = (STSmaDataWrapper *)msg;
|
||||
SSDataBlock *pData = (SSDataBlock *)msg;
|
||||
SSmaEnv *pEnv = atomic_load_ptr(&pTsdb->pRSmaEnv);
|
||||
int64_t indexUid = SMA_TEST_INDEX_UID;
|
||||
|
||||
if (pEnv == NULL) {
|
||||
terrno = TSDB_CODE_INVALID_PTR;
|
||||
tsdbWarn("vgId:%d insert tSma data failed since pTSmaEnv is NULL", REPO_ID(pTsdb));
|
||||
tsdbWarn("vgId:%d insert rSma data failed since pTSmaEnv is NULL", REPO_ID(pTsdb));
|
||||
return terrno;
|
||||
}
|
||||
|
||||
if (pData->dataLen <= 0) {
|
||||
TASSERT(0);
|
||||
if (pEnv == NULL) {
|
||||
terrno = TSDB_CODE_INVALID_PTR;
|
||||
tsdbWarn("vgId:%d insert rSma data failed since pTSmaEnv is NULL", REPO_ID(pTsdb));
|
||||
return terrno;
|
||||
}
|
||||
|
||||
if (pData == NULL) {
|
||||
terrno = TSDB_CODE_INVALID_PTR;
|
||||
tsdbWarn("vgId:%d insert rSma data failed since pData is NULL", REPO_ID(pTsdb));
|
||||
return terrno;
|
||||
}
|
||||
|
||||
if (taosArrayGetSize(pData->pDataBlock) <= 0) {
|
||||
terrno = TSDB_CODE_INVALID_PARA;
|
||||
tsdbWarn("vgId:%d insert rSma data failed since pDataBlock is empty", REPO_ID(pTsdb));
|
||||
return TSDB_CODE_FAILED;
|
||||
}
|
||||
|
||||
SSmaStat *pStat = SMA_ENV_STAT(pTsdb->pTSmaEnv);
|
||||
SSmaStatItem *pItem = NULL;
|
||||
|
||||
tsdbRefSmaStat(pTsdb, pStat);
|
||||
|
||||
if (pStat && pStat->smaStatItems) {
|
||||
pItem = taosHashGet(pStat->smaStatItems, &indexUid, sizeof(indexUid));
|
||||
}
|
||||
|
||||
if ((pItem == NULL) || ((pItem = *(SSmaStatItem **)pItem) == NULL) || tsdbSmaStatIsDropped(pItem)) {
|
||||
terrno = TSDB_CODE_TDB_INVALID_SMA_STAT;
|
||||
tsdbUnRefSmaStat(pTsdb, pStat);
|
||||
return TSDB_CODE_FAILED;
|
||||
}
|
||||
|
||||
STSma *pSma = pItem->pSma;
|
||||
|
||||
STSmaWriteH tSmaH = {0};
|
||||
|
||||
if (tsdbInitTSmaWriteH(&tSmaH, pTsdb, pData) != 0) {
|
||||
if (tsdbInitTSmaWriteH(&tSmaH, pTsdb, pData, pSma->interval, pSma->intervalUnit) != 0) {
|
||||
return TSDB_CODE_FAILED;
|
||||
}
|
||||
|
||||
int64_t indexUid = SMA_TEST_INDEX_UID;
|
||||
char rPath[TSDB_FILENAME_LEN] = {0};
|
||||
char aPath[TSDB_FILENAME_LEN] = {0};
|
||||
snprintf(rPath, TSDB_FILENAME_LEN, "%s%s%" PRIi64, SMA_ENV_PATH(pEnv), TD_DIRSEP, indexUid);
|
||||
|
@ -1033,8 +1076,9 @@ static int32_t tsdbInsertRSmaDataImpl(STsdb *pTsdb, char *msg) {
|
|||
}
|
||||
|
||||
// Step 1: Judge the storage level and days
|
||||
int32_t storageLevel = tsdbGetSmaStorageLevel(pData->interval, pData->intervalUnit);
|
||||
int32_t storageLevel = tsdbGetSmaStorageLevel(pSma->interval, pSma->intervalUnit);
|
||||
int32_t daysPerFile = tsdbGetTSmaDays(pTsdb, tSmaH.interval, storageLevel);
|
||||
#if 0
|
||||
int32_t fid = (int32_t)(TSDB_KEY_FID(pData->skey, daysPerFile, pCfg->precision));
|
||||
|
||||
// Step 2: Set the DFile for storage of SMA index, and iterate/split the TSma data and store to B+Tree index file
|
||||
|
@ -1057,8 +1101,10 @@ static int32_t tsdbInsertRSmaDataImpl(STsdb *pTsdb, char *msg) {
|
|||
|
||||
// Step 3: reset the SSmaStat
|
||||
tsdbResetExpiredWindow(pTsdb, SMA_ENV_STAT(pTsdb->pTSmaEnv), pData->indexUid, pData->skey);
|
||||
#endif
|
||||
|
||||
tsdbDestroyTSmaWriteH(&tSmaH);
|
||||
tsdbUnRefSmaStat(pTsdb, pStat);
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
|
|
|
@ -66,6 +66,8 @@ int vnodeProcessFetchMsg(SVnode *pVnode, SRpcMsg *pMsg) {
|
|||
case TDMT_VND_CONSUME:
|
||||
return tqProcessPollReq(pVnode->pTq, pMsg);
|
||||
case TDMT_VND_TASK_EXEC:
|
||||
case TDMT_VND_TASK_PIPE_EXEC:
|
||||
case TDMT_VND_TASK_MERGE_EXEC:
|
||||
return tqProcessTaskExec(pVnode->pTq, pMsg);
|
||||
case TDMT_VND_STREAM_TRIGGER:
|
||||
return tqProcessStreamTrigger(pVnode->pTq, pMsg->pCont, pMsg->contLen);
|
||||
|
|
|
@ -74,6 +74,9 @@ int vnodeApplyWMsg(SVnode *pVnode, SRpcMsg *pMsg, SRpcMsg **pRsp) {
|
|||
// TODO: maybe need to clear the request struct
|
||||
taosMemoryFree(vCreateTbReq.stbCfg.pSchema);
|
||||
taosMemoryFree(vCreateTbReq.stbCfg.pTagSchema);
|
||||
taosMemoryFree(vCreateTbReq.stbCfg.pBSmaCols);
|
||||
taosMemoryFree(vCreateTbReq.stbCfg.pRSmaParam);
|
||||
taosMemoryFree(vCreateTbReq.dbFName);
|
||||
taosMemoryFree(vCreateTbReq.name);
|
||||
break;
|
||||
}
|
||||
|
@ -102,13 +105,18 @@ int vnodeApplyWMsg(SVnode *pVnode, SRpcMsg *pMsg, SRpcMsg **pRsp) {
|
|||
vError("vgId:%d, failed to create table: %s", pVnode->vgId, pCreateTbReq->name);
|
||||
}
|
||||
taosMemoryFree(pCreateTbReq->name);
|
||||
taosMemoryFree(pCreateTbReq->dbFName);
|
||||
if (pCreateTbReq->type == TD_SUPER_TABLE) {
|
||||
taosMemoryFree(pCreateTbReq->stbCfg.pSchema);
|
||||
taosMemoryFree(pCreateTbReq->stbCfg.pTagSchema);
|
||||
taosMemoryFree(pCreateTbReq->stbCfg.pBSmaCols);
|
||||
taosMemoryFree(pCreateTbReq->stbCfg.pRSmaParam);
|
||||
} else if (pCreateTbReq->type == TD_CHILD_TABLE) {
|
||||
taosMemoryFree(pCreateTbReq->ctbCfg.pTag);
|
||||
} else {
|
||||
taosMemoryFree(pCreateTbReq->ntbCfg.pSchema);
|
||||
taosMemoryFree(pCreateTbReq->ntbCfg.pBSmaCols);
|
||||
taosMemoryFree(pCreateTbReq->ntbCfg.pRSmaParam);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -135,6 +143,9 @@ int vnodeApplyWMsg(SVnode *pVnode, SRpcMsg *pMsg, SRpcMsg **pRsp) {
|
|||
tDeserializeSVCreateTbReq(POINTER_SHIFT(pMsg->pCont, sizeof(SMsgHead)), &vAlterTbReq);
|
||||
taosMemoryFree(vAlterTbReq.stbCfg.pSchema);
|
||||
taosMemoryFree(vAlterTbReq.stbCfg.pTagSchema);
|
||||
taosMemoryFree(vAlterTbReq.stbCfg.pBSmaCols);
|
||||
taosMemoryFree(vAlterTbReq.stbCfg.pRSmaParam);
|
||||
taosMemoryFree(vAlterTbReq.dbFName);
|
||||
taosMemoryFree(vAlterTbReq.name);
|
||||
break;
|
||||
}
|
||||
|
@ -176,7 +187,7 @@ int vnodeApplyWMsg(SVnode *pVnode, SRpcMsg *pMsg, SRpcMsg **pRsp) {
|
|||
}
|
||||
|
||||
// record current timezone of server side
|
||||
tstrncpy(vCreateSmaReq.tSma.timezone, tsTimezone, TD_TIMEZONE_LEN);
|
||||
tstrncpy(vCreateSmaReq.tSma.timezone, tsTimezoneStr, TD_TIMEZONE_LEN);
|
||||
|
||||
if (metaCreateTSma(pVnode->pMeta, &vCreateSmaReq) < 0) {
|
||||
// TODO: handle error
|
||||
|
|
|
@ -280,7 +280,7 @@ TEST(testCase, tSma_metaDB_Put_Get_Del_Test) {
|
|||
}
|
||||
#endif
|
||||
|
||||
#if 1
|
||||
#if 0
|
||||
TEST(testCase, tSma_Data_Insert_Query_Test) {
|
||||
// step 1: prepare meta
|
||||
const char *smaIndexName1 = "sma_index_test_1";
|
||||
|
|
|
@ -53,7 +53,6 @@ SCtgAction gCtgAction[CTG_ACT_MAX] = {{
|
|||
}
|
||||
};
|
||||
|
||||
|
||||
void ctgFreeMetaRent(SCtgRentMgmt *mgmt) {
|
||||
if (NULL == mgmt->slots) {
|
||||
return;
|
||||
|
|
|
@ -415,6 +415,7 @@ typedef struct STableScanInfo {
|
|||
int32_t* rowCellInfoOffset;
|
||||
SExprInfo* pExpr;
|
||||
SSDataBlock block;
|
||||
SArray* pColMatchInfo;
|
||||
int32_t numOfOutput;
|
||||
int64_t elapsedTime;
|
||||
int32_t prevGroupId; // previous table group id
|
||||
|
@ -648,8 +649,8 @@ typedef struct SDistinctOperatorInfo {
|
|||
} SDistinctOperatorInfo;
|
||||
|
||||
SOperatorInfo* createExchangeOperatorInfo(const SNodeList* pSources, SSDataBlock* pBlock, SExecTaskInfo* pTaskInfo);
|
||||
SOperatorInfo* createTableScanOperatorInfo(void* pTsdbReadHandle, int32_t order, int32_t numOfOutput,
|
||||
int32_t repeatTime, int32_t reverseTime, SExecTaskInfo* pTaskInfo);
|
||||
SOperatorInfo* createTableScanOperatorInfo(void* pTsdbReadHandle, int32_t order, int32_t numOfCols, int32_t repeatTime,
|
||||
int32_t reverseTime, SArray* pColMatchInfo, SExecTaskInfo* pTaskInfo);
|
||||
SOperatorInfo* createAggregateOperatorInfo(SOperatorInfo* downstream, SExprInfo* pExprInfo, int32_t numOfCols, SSDataBlock* pResultBlock,
|
||||
SExecTaskInfo* pTaskInfo, const STableGroupInfo* pTableGroupInfo);
|
||||
SOperatorInfo* createMultiTableAggOperatorInfo(SOperatorInfo* downstream, SExprInfo* pExprInfo, int32_t numOfCols, SSDataBlock* pResBlock, SExecTaskInfo* pTaskInfo, const STableGroupInfo* pTableGroupInfo);
|
||||
|
|
|
@ -97,6 +97,8 @@ qTaskInfo_t qCreateStreamExecTaskInfo(void* msg, void* streamReadHandle) {
|
|||
pMsg->contentLen = pMsg->contentLen;
|
||||
#endif
|
||||
|
||||
qDebugL("stream task string %s", (const char*)msg);
|
||||
|
||||
struct SSubplan* plan = NULL;
|
||||
int32_t code = qStringToSubplan(msg, &plan);
|
||||
if (code != TSDB_CODE_SUCCESS) {
|
||||
|
|
|
@ -66,6 +66,11 @@ typedef enum SResultTsInterpType {
|
|||
RESULT_ROW_END_INTERP = 2,
|
||||
} SResultTsInterpType;
|
||||
|
||||
typedef struct SColMatchInfo {
|
||||
int32_t colId;
|
||||
int32_t targetSlotId;
|
||||
} SColMatchInfo;
|
||||
|
||||
#if 0
|
||||
static UNUSED_FUNC void *u_malloc (size_t __size) {
|
||||
uint32_t v = taosRand();
|
||||
|
@ -2944,12 +2949,21 @@ int32_t loadDataBlock(SExecTaskInfo *pTaskInfo, STableScanInfo* pTableScanInfo,
|
|||
|
||||
*status = BLK_DATA_ALL_NEEDED;
|
||||
|
||||
pBlock->pDataBlock = tsdbRetrieveDataBlock(pTableScanInfo->pTsdbReadHandle, NULL);
|
||||
if (pBlock->pDataBlock == NULL) {
|
||||
SArray* pCols = tsdbRetrieveDataBlock(pTableScanInfo->pTsdbReadHandle, NULL);
|
||||
if (pCols == NULL) {
|
||||
return terrno;
|
||||
} else {
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
int32_t numOfCols = pBlock->info.numOfCols;
|
||||
for(int32_t i = 0; i < numOfCols; ++i) {
|
||||
SColumnInfoData* p = taosArrayGet(pCols, i);
|
||||
SColMatchInfo* pColMatchInfo = taosArrayGet(pTableScanInfo->pColMatchInfo, i);
|
||||
ASSERT(pColMatchInfo->colId == p->info.colId);
|
||||
|
||||
taosArraySet(pBlock->pDataBlock, pColMatchInfo->targetSlotId, p);
|
||||
}
|
||||
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
int32_t loadDataBlockOnDemand(SExecTaskInfo *pTaskInfo, STableScanInfo* pTableScanInfo, SSDataBlock* pBlock, uint32_t* status) {
|
||||
|
@ -5374,7 +5388,8 @@ SSDataBlock* createResultDataBlock(const SArray* pExprInfo) {
|
|||
return pResBlock;
|
||||
}
|
||||
|
||||
SOperatorInfo* createTableScanOperatorInfo(void* pTsdbReadHandle, int32_t order, int32_t numOfOutput, int32_t repeatTime, int32_t reverseTime, SExecTaskInfo* pTaskInfo) {
|
||||
SOperatorInfo* createTableScanOperatorInfo(void* pTsdbReadHandle, int32_t order, int32_t numOfOutput, int32_t repeatTime, int32_t reverseTime, SArray* pColMatchInfo,
|
||||
SExecTaskInfo* pTaskInfo) {
|
||||
assert(repeatTime > 0);
|
||||
|
||||
STableScanInfo* pInfo = taosMemoryCalloc(1, sizeof(STableScanInfo));
|
||||
|
@ -5387,12 +5402,19 @@ SOperatorInfo* createTableScanOperatorInfo(void* pTsdbReadHandle, int32_t order,
|
|||
return NULL;
|
||||
}
|
||||
|
||||
pInfo->block.pDataBlock = taosArrayInit(numOfOutput, sizeof(SColumnInfoData));
|
||||
for(int32_t i = 0; i < numOfOutput; ++i) {
|
||||
SColumnInfoData idata = {0};
|
||||
taosArrayPush(pInfo->block.pDataBlock, &idata);
|
||||
}
|
||||
|
||||
pInfo->pTsdbReadHandle = pTsdbReadHandle;
|
||||
pInfo->times = repeatTime;
|
||||
pInfo->reverseTimes = reverseTime;
|
||||
pInfo->order = order;
|
||||
pInfo->current = 0;
|
||||
pInfo->scanFlag = MAIN_SCAN;
|
||||
pInfo->pColMatchInfo = pColMatchInfo;
|
||||
pOperator->name = "TableScanOperator";
|
||||
pOperator->operatorType = QUERY_NODE_PHYSICAL_PLAN_TABLE_SCAN;
|
||||
pOperator->blockingOptr = false;
|
||||
|
@ -8569,6 +8591,7 @@ static int32_t doCreateTableGroup(void* metaHandle, int32_t tableType, uint64_t
|
|||
static SArray* extractTableIdList(const STableGroupInfo* pTableGroupInfo);
|
||||
static SArray* extractScanColumnId(SNodeList* pNodeList);
|
||||
static SArray* extractColumnInfo(SNodeList* pNodeList);
|
||||
static SArray* extractColMatchInfo(SNodeList* pNodeList);
|
||||
|
||||
SOperatorInfo* doCreateOperatorTreeNode(SPhysiNode* pPhyNode, SExecTaskInfo* pTaskInfo, SReadHandle* pHandle, uint64_t queryId, uint64_t taskId, STableGroupInfo* pTableGroupInfo) {
|
||||
if (pPhyNode->pChildren == NULL || LIST_LENGTH(pPhyNode->pChildren) == 0) {
|
||||
|
@ -8577,7 +8600,9 @@ SOperatorInfo* doCreateOperatorTreeNode(SPhysiNode* pPhyNode, SExecTaskInfo* pTa
|
|||
|
||||
size_t numOfCols = LIST_LENGTH(pScanPhyNode->pScanCols);
|
||||
tsdbReaderT pDataReader = doCreateDataReader((STableScanPhysiNode*)pPhyNode, pHandle, pTableGroupInfo, (uint64_t)queryId, taskId);
|
||||
return createTableScanOperatorInfo(pDataReader, pScanPhyNode->order, numOfCols, pScanPhyNode->count, pScanPhyNode->reverse, pTaskInfo);
|
||||
SArray* pColList = extractColMatchInfo(pScanPhyNode->pScanCols);
|
||||
|
||||
return createTableScanOperatorInfo(pDataReader, pScanPhyNode->order, numOfCols, pScanPhyNode->count, pScanPhyNode->reverse, pColList, pTaskInfo);
|
||||
} else if (QUERY_NODE_PHYSICAL_PLAN_EXCHANGE == nodeType(pPhyNode)) {
|
||||
SExchangePhysiNode* pExchange = (SExchangePhysiNode*)pPhyNode;
|
||||
SSDataBlock* pResBlock = createOutputBuf_rv1(pExchange->node.pOutputDataBlockDesc);
|
||||
|
@ -8717,9 +8742,14 @@ SArray* extractScanColumnId(SNodeList* pNodeList) {
|
|||
}
|
||||
|
||||
for(int32_t i = 0; i < numOfCols; ++i) {
|
||||
STargetNode* pNode = (STargetNode*) nodesListGetNode(pNodeList, i);
|
||||
for (int32_t j = 0; j < numOfCols; ++j) {
|
||||
STargetNode* pNode = (STargetNode*) nodesListGetNode(pNodeList, j);
|
||||
if (pNode->slotId == i) {
|
||||
SColumnNode* pColNode = (SColumnNode*) pNode->pExpr;
|
||||
taosArrayPush(pList, &pColNode->colId);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return pList;
|
||||
|
@ -8751,6 +8781,28 @@ SArray* extractColumnInfo(SNodeList* pNodeList) {
|
|||
return pList;
|
||||
}
|
||||
|
||||
SArray* extractColMatchInfo(SNodeList* pNodeList) {
|
||||
size_t numOfCols = LIST_LENGTH(pNodeList);
|
||||
SArray* pList = taosArrayInit(numOfCols, sizeof(SColMatchInfo));
|
||||
if (pList == NULL) {
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
for(int32_t i = 0; i < numOfCols; ++i) {
|
||||
STargetNode* pNode = (STargetNode*) nodesListGetNode(pNodeList, i);
|
||||
SColumnNode* pColNode = (SColumnNode*) pNode->pExpr;
|
||||
|
||||
SColMatchInfo c = {0};
|
||||
c.colId = pColNode->colId;
|
||||
c.targetSlotId = pNode->slotId;
|
||||
|
||||
taosArrayPush(pList, &c);
|
||||
}
|
||||
|
||||
return pList;
|
||||
}
|
||||
|
||||
int32_t doCreateTableGroup(void* metaHandle, int32_t tableType, uint64_t tableUid, STableGroupInfo* pGroupInfo, uint64_t queryId, uint64_t taskId) {
|
||||
int32_t code = 0;
|
||||
if (tableType == TSDB_SUPER_TABLE) {
|
||||
|
|
|
@ -19,6 +19,11 @@
|
|||
#include "taos.h"
|
||||
#include "taoserror.h"
|
||||
|
||||
#define COPY_ALL_SCALAR_FIELDS \
|
||||
do { \
|
||||
memcpy((pDst), (pSrc), sizeof(*pSrc)); \
|
||||
} while (0)
|
||||
|
||||
#define COPY_SCALAR_FIELD(fldname) \
|
||||
do { \
|
||||
(pDst)->fldname = (pSrc)->fldname; \
|
||||
|
@ -195,6 +200,12 @@ static SNode* groupingSetNodeCopy(const SGroupingSetNode* pSrc, SGroupingSetNode
|
|||
return (SNode*)pDst;
|
||||
}
|
||||
|
||||
static SNode* orderByExprNodeCopy(const SOrderByExprNode* pSrc, SOrderByExprNode* pDst) {
|
||||
COPY_ALL_SCALAR_FIELDS;
|
||||
CLONE_NODE_FIELD(pExpr);
|
||||
return (SNode*)pDst;
|
||||
}
|
||||
|
||||
static SNode* fillNodeCopy(const SFillNode* pSrc, SFillNode* pDst) {
|
||||
COPY_SCALAR_FIELD(mode);
|
||||
CLONE_NODE_FIELD(pValues);
|
||||
|
@ -251,6 +262,7 @@ static SNode* logicAggCopy(const SAggLogicNode* pSrc, SAggLogicNode* pDst) {
|
|||
static SNode* logicProjectCopy(const SProjectLogicNode* pSrc, SProjectLogicNode* pDst) {
|
||||
COPY_BASE_OBJECT_FIELD(node, logicNodeCopy);
|
||||
CLONE_NODE_LIST_FIELD(pProjections);
|
||||
COPY_CHAR_ARRAY_FIELD(stmtName);
|
||||
return (SNode*)pDst;
|
||||
}
|
||||
|
||||
|
@ -267,16 +279,24 @@ static SNode* logicExchangeCopy(const SExchangeLogicNode* pSrc, SExchangeLogicNo
|
|||
}
|
||||
|
||||
static SNode* logicWindowCopy(const SWindowLogicNode* pSrc, SWindowLogicNode* pDst) {
|
||||
COPY_ALL_SCALAR_FIELDS;
|
||||
COPY_BASE_OBJECT_FIELD(node, logicNodeCopy);
|
||||
COPY_SCALAR_FIELD(winType);
|
||||
// COPY_SCALAR_FIELD(winType);
|
||||
CLONE_NODE_LIST_FIELD(pFuncs);
|
||||
COPY_SCALAR_FIELD(interval);
|
||||
COPY_SCALAR_FIELD(offset);
|
||||
COPY_SCALAR_FIELD(sliding);
|
||||
COPY_SCALAR_FIELD(intervalUnit);
|
||||
COPY_SCALAR_FIELD(slidingUnit);
|
||||
// COPY_SCALAR_FIELD(interval);
|
||||
// COPY_SCALAR_FIELD(offset);
|
||||
// COPY_SCALAR_FIELD(sliding);
|
||||
// COPY_SCALAR_FIELD(intervalUnit);
|
||||
// COPY_SCALAR_FIELD(slidingUnit);
|
||||
CLONE_NODE_FIELD(pFill);
|
||||
COPY_SCALAR_FIELD(sessionGap);
|
||||
// COPY_SCALAR_FIELD(sessionGap);
|
||||
CLONE_NODE_FIELD(pTspk);
|
||||
return (SNode*)pDst;
|
||||
}
|
||||
|
||||
static SNode* logicSortCopy(const SSortLogicNode* pSrc, SSortLogicNode* pDst) {
|
||||
COPY_BASE_OBJECT_FIELD(node, logicNodeCopy);
|
||||
CLONE_NODE_LIST_FIELD(pSortKeys);
|
||||
return (SNode*)pDst;
|
||||
}
|
||||
|
||||
|
@ -339,6 +359,7 @@ SNodeptr nodesCloneNode(const SNodeptr pNode) {
|
|||
case QUERY_NODE_GROUPING_SET:
|
||||
return groupingSetNodeCopy((const SGroupingSetNode*)pNode, (SGroupingSetNode*)pDst);
|
||||
case QUERY_NODE_ORDER_BY_EXPR:
|
||||
return orderByExprNodeCopy((const SOrderByExprNode*)pNode, (SOrderByExprNode*)pDst);
|
||||
case QUERY_NODE_LIMIT:
|
||||
break;
|
||||
case QUERY_NODE_FILL:
|
||||
|
@ -361,6 +382,8 @@ SNodeptr nodesCloneNode(const SNodeptr pNode) {
|
|||
return logicExchangeCopy((const SExchangeLogicNode*)pNode, (SExchangeLogicNode*)pDst);
|
||||
case QUERY_NODE_LOGIC_PLAN_WINDOW:
|
||||
return logicWindowCopy((const SWindowLogicNode*)pNode, (SWindowLogicNode*)pDst);
|
||||
case QUERY_NODE_LOGIC_PLAN_SORT:
|
||||
return logicSortCopy((const SSortLogicNode*)pNode, (SSortLogicNode*)pDst);
|
||||
case QUERY_NODE_LOGIC_SUBPLAN:
|
||||
return logicSubplanCopy((const SLogicSubplan*)pNode, (SLogicSubplan*)pDst);
|
||||
default:
|
||||
|
|
|
@ -851,9 +851,7 @@ static int32_t jsonToPhysiJoinNode(const SJson* pJson, void* pObj) {
|
|||
|
||||
int32_t code = jsonToPhysicPlanNode(pJson, pObj);
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
int32_t val;
|
||||
code = tjsonGetIntValue(pJson, jkJoinPhysiPlanJoinType, &val);
|
||||
pNode->joinType = val;
|
||||
code = tjsonGetNumberValue(pJson, jkJoinPhysiPlanJoinType, pNode->joinType);
|
||||
}
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
code = jsonToNodeObject(pJson, jkJoinPhysiPlanOnConditions, &pNode->pOnConditions);
|
||||
|
@ -934,6 +932,37 @@ static int32_t jsonToPhysiExchangeNode(const SJson* pJson, void* pObj) {
|
|||
return code;
|
||||
}
|
||||
|
||||
static const char* jkSortPhysiPlanExprs = "Exprs";
|
||||
static const char* jkSortPhysiPlanSortKeys = "SortKeys";
|
||||
|
||||
static int32_t physiSortNodeToJson(const void* pObj, SJson* pJson) {
|
||||
const SSortPhysiNode* pNode = (const SSortPhysiNode*)pObj;
|
||||
|
||||
int32_t code = physicPlanNodeToJson(pObj, pJson);
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
code = nodeListToJson(pJson, jkSortPhysiPlanExprs, pNode->pExprs);
|
||||
}
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
code = nodeListToJson(pJson, jkSortPhysiPlanSortKeys, pNode->pSortKeys);
|
||||
}
|
||||
|
||||
return code;
|
||||
}
|
||||
|
||||
static int32_t jsonToPhysiSortNode(const SJson* pJson, void* pObj) {
|
||||
SSortPhysiNode* pNode = (SSortPhysiNode*)pObj;
|
||||
|
||||
int32_t code = jsonToPhysicPlanNode(pJson, pObj);
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
code = jsonToNodeList(pJson, jkSortPhysiPlanExprs, &pNode->pExprs);
|
||||
}
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
code = jsonToNodeList(pJson, jkSortPhysiPlanSortKeys, &pNode->pSortKeys);
|
||||
}
|
||||
|
||||
return code;
|
||||
}
|
||||
|
||||
static const char* jkWindowPhysiPlanExprs = "Exprs";
|
||||
static const char* jkWindowPhysiPlanFuncs = "Funcs";
|
||||
|
||||
|
@ -971,6 +1000,7 @@ static const char* jkIntervalPhysiPlanSliding = "Sliding";
|
|||
static const char* jkIntervalPhysiPlanIntervalUnit = "intervalUnit";
|
||||
static const char* jkIntervalPhysiPlanSlidingUnit = "slidingUnit";
|
||||
static const char* jkIntervalPhysiPlanFill = "Fill";
|
||||
static const char* jkIntervalPhysiPlanTsPk = "TsPk";
|
||||
|
||||
static int32_t physiIntervalNodeToJson(const void* pObj, SJson* pJson) {
|
||||
const SIntervalPhysiNode* pNode = (const SIntervalPhysiNode*)pObj;
|
||||
|
@ -994,6 +1024,9 @@ static int32_t physiIntervalNodeToJson(const void* pObj, SJson* pJson) {
|
|||
if (TSDB_CODE_SUCCESS == code) {
|
||||
code = tjsonAddObject(pJson, jkIntervalPhysiPlanFill, nodeToJson, pNode->pFill);
|
||||
}
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
code = tjsonAddObject(pJson, jkIntervalPhysiPlanTsPk, nodeToJson, pNode->pTspk);
|
||||
}
|
||||
|
||||
return code;
|
||||
}
|
||||
|
@ -1020,6 +1053,9 @@ static int32_t jsonToPhysiIntervalNode(const SJson* pJson, void* pObj) {
|
|||
if (TSDB_CODE_SUCCESS == code) {
|
||||
code = jsonToNodeObject(pJson, jkIntervalPhysiPlanFill, (SNode**)&pNode->pFill);
|
||||
}
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
code = jsonToNodeObject(pJson, jkIntervalPhysiPlanTsPk, (SNode**)&pNode->pTspk);
|
||||
}
|
||||
|
||||
return code;
|
||||
}
|
||||
|
@ -1178,9 +1214,7 @@ static int32_t jsonToSubplan(const SJson* pJson, void* pObj) {
|
|||
|
||||
int32_t code = tjsonToObject(pJson, jkSubplanId, jsonToSubplanId, &pNode->id);
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
int32_t val;
|
||||
code = tjsonGetIntValue(pJson, jkSubplanType, &val);
|
||||
pNode->subplanType = val;
|
||||
code = tjsonGetNumberValue(pJson, jkSubplanType, pNode->subplanType);
|
||||
}
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
code = tjsonGetIntValue(pJson, jkSubplanMsgType, &pNode->msgType);
|
||||
|
@ -1370,9 +1404,7 @@ static int32_t jsonToColumnNode(const SJson* pJson, void* pObj) {
|
|||
code = tjsonGetSmallIntValue(pJson, jkColumnColId, &pNode->colId);
|
||||
}
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
int32_t tmp;
|
||||
code = tjsonGetIntValue(pJson, jkColumnColType, &tmp);
|
||||
pNode->colType = tmp;
|
||||
code = tjsonGetNumberValue(pJson, jkColumnColType, pNode->colType);
|
||||
}
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
code = tjsonGetStringValue(pJson, jkColumnDbName, pNode->dbName);
|
||||
|
@ -1560,9 +1592,7 @@ static int32_t jsonToOperatorNode(const SJson* pJson, void* pObj) {
|
|||
|
||||
int32_t code = jsonToExprNode(pJson, pObj);
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
int32_t val;
|
||||
code = tjsonGetIntValue(pJson, jkOperatorType, &val);
|
||||
pNode->opType = val;
|
||||
code = tjsonGetNumberValue(pJson, jkOperatorType, pNode->opType);
|
||||
}
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
code = jsonToNodeObject(pJson, jkOperatorLeft, &pNode->pLeft);
|
||||
|
@ -1596,9 +1626,7 @@ static int32_t jsonToLogicConditionNode(const SJson* pJson, void* pObj) {
|
|||
|
||||
int32_t code = jsonToExprNode(pJson, pObj);
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
int32_t val;
|
||||
code = tjsonGetIntValue(pJson, jkLogicCondType, &val);
|
||||
pNode->condType = val;
|
||||
code = tjsonGetNumberValue(pJson, jkLogicCondType, pNode->condType);
|
||||
}
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
code = jsonToNodeList(pJson, jkLogicCondParameters, &pNode->pParameterList);
|
||||
|
@ -1821,10 +1849,43 @@ static int32_t groupingSetNodeToJson(const void* pObj, SJson* pJson) {
|
|||
return code;
|
||||
}
|
||||
|
||||
static const char* jkOrderByExprExpr = "Expr";
|
||||
static const char* jkOrderByExprOrder = "Order";
|
||||
static const char* jkOrderByExprNullOrder = "NullOrder";
|
||||
|
||||
static int32_t orderByExprNodeToJson(const void* pObj, SJson* pJson) {
|
||||
const SOrderByExprNode* pNode = (const SOrderByExprNode*)pObj;
|
||||
|
||||
int32_t code = tjsonAddObject(pJson, jkOrderByExprExpr, nodeToJson, pNode->pExpr);
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
code = tjsonAddIntegerToObject(pJson, jkOrderByExprOrder, pNode->order);
|
||||
}
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
code = tjsonAddIntegerToObject(pJson, jkOrderByExprNullOrder, pNode->nullOrder);
|
||||
}
|
||||
|
||||
return code;
|
||||
}
|
||||
|
||||
static int32_t jsonToOrderByExprNode(const SJson* pJson, void* pObj) {
|
||||
SOrderByExprNode* pNode = (SOrderByExprNode*)pObj;
|
||||
|
||||
int32_t code = jsonToNodeObject(pJson, jkOrderByExprExpr, &pNode->pExpr);
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
code = tjsonGetNumberValue(pJson, jkOrderByExprOrder, pNode->order);
|
||||
}
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
code = tjsonGetNumberValue(pJson, jkOrderByExprNullOrder, pNode->nullOrder);
|
||||
}
|
||||
|
||||
return code;
|
||||
}
|
||||
|
||||
static const char* jkIntervalWindowInterval = "Interval";
|
||||
static const char* jkIntervalWindowOffset = "Offset";
|
||||
static const char* jkIntervalWindowSliding = "Sliding";
|
||||
static const char* jkIntervalWindowFill = "Fill";
|
||||
static const char* jkIntervalWindowTsPk = "TsPk";
|
||||
|
||||
static int32_t intervalWindowNodeToJson(const void* pObj, SJson* pJson) {
|
||||
const SIntervalWindowNode* pNode = (const SIntervalWindowNode*)pObj;
|
||||
|
@ -1839,6 +1900,9 @@ static int32_t intervalWindowNodeToJson(const void* pObj, SJson* pJson) {
|
|||
if (TSDB_CODE_SUCCESS == code) {
|
||||
code = tjsonAddObject(pJson, jkIntervalWindowFill, nodeToJson, pNode->pFill);
|
||||
}
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
code = tjsonAddObject(pJson, jkIntervalWindowTsPk, nodeToJson, pNode->pCol);
|
||||
}
|
||||
|
||||
return code;
|
||||
}
|
||||
|
@ -1856,6 +1920,9 @@ static int32_t jsonToIntervalWindowNode(const SJson* pJson, void* pObj) {
|
|||
if (TSDB_CODE_SUCCESS == code) {
|
||||
code = jsonToNodeObject(pJson, jkIntervalWindowFill, &pNode->pFill);
|
||||
}
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
code = jsonToNodeObject(pJson, jkIntervalWindowTsPk, &pNode->pCol);
|
||||
}
|
||||
|
||||
return code;
|
||||
}
|
||||
|
@ -2033,6 +2100,7 @@ static const char* jkSelectStmtHaving = "Having";
|
|||
static const char* jkSelectStmtOrderBy = "OrderBy";
|
||||
static const char* jkSelectStmtLimit = "Limit";
|
||||
static const char* jkSelectStmtSlimit = "Slimit";
|
||||
static const char* jkSelectStmtStmtName = "StmtName";
|
||||
|
||||
static int32_t selectStmtTojson(const void* pObj, SJson* pJson) {
|
||||
const SSelectStmt* pNode = (const SSelectStmt*)pObj;
|
||||
|
@ -2068,6 +2136,9 @@ static int32_t selectStmtTojson(const void* pObj, SJson* pJson) {
|
|||
if (TSDB_CODE_SUCCESS == code) {
|
||||
code = tjsonAddObject(pJson, jkSelectStmtSlimit, nodeToJson, pNode->pSlimit);
|
||||
}
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
code = tjsonAddStringToObject(pJson, jkSelectStmtStmtName, pNode->stmtName);
|
||||
}
|
||||
|
||||
return code;
|
||||
}
|
||||
|
@ -2106,6 +2177,9 @@ static int32_t jsonToSelectStmt(const SJson* pJson, void* pObj) {
|
|||
if (TSDB_CODE_SUCCESS == code) {
|
||||
code = jsonToNodeObject(pJson, jkSelectStmtSlimit, &pNode->pSlimit);
|
||||
}
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
code = tjsonGetStringValue(pJson, jkSelectStmtStmtName, pNode->stmtName);
|
||||
}
|
||||
|
||||
return code;
|
||||
}
|
||||
|
@ -2169,6 +2243,7 @@ static int32_t specificNodeToJson(const void* pObj, SJson* pJson) {
|
|||
case QUERY_NODE_GROUPING_SET:
|
||||
return groupingSetNodeToJson(pObj, pJson);
|
||||
case QUERY_NODE_ORDER_BY_EXPR:
|
||||
return orderByExprNodeToJson(pObj, pJson);
|
||||
case QUERY_NODE_LIMIT:
|
||||
case QUERY_NODE_STATE_WINDOW:
|
||||
case QUERY_NODE_SESSION_WINDOW:
|
||||
|
@ -2232,7 +2307,7 @@ static int32_t specificNodeToJson(const void* pObj, SJson* pJson) {
|
|||
case QUERY_NODE_PHYSICAL_PLAN_EXCHANGE:
|
||||
return physiExchangeNodeToJson(pObj, pJson);
|
||||
case QUERY_NODE_PHYSICAL_PLAN_SORT:
|
||||
break;
|
||||
return physiSortNodeToJson(pObj, pJson);
|
||||
case QUERY_NODE_PHYSICAL_PLAN_INTERVAL:
|
||||
return physiIntervalNodeToJson(pObj, pJson);
|
||||
case QUERY_NODE_PHYSICAL_PLAN_SESSION_WINDOW:
|
||||
|
@ -2272,7 +2347,8 @@ static int32_t jsonToSpecificNode(const SJson* pJson, void* pObj) {
|
|||
// break;
|
||||
// case QUERY_NODE_GROUPING_SET:
|
||||
// return jsonToGroupingSetNode(pJson, pObj);
|
||||
// case QUERY_NODE_ORDER_BY_EXPR:
|
||||
case QUERY_NODE_ORDER_BY_EXPR:
|
||||
return jsonToOrderByExprNode(pJson, pObj);
|
||||
// case QUERY_NODE_LIMIT:
|
||||
// case QUERY_NODE_STATE_WINDOW:
|
||||
// case QUERY_NODE_SESSION_WINDOW:
|
||||
|
@ -2321,6 +2397,8 @@ static int32_t jsonToSpecificNode(const SJson* pJson, void* pObj) {
|
|||
return jsonToPhysiAggNode(pJson, pObj);
|
||||
case QUERY_NODE_PHYSICAL_PLAN_EXCHANGE:
|
||||
return jsonToPhysiExchangeNode(pJson, pObj);
|
||||
case QUERY_NODE_PHYSICAL_PLAN_SORT:
|
||||
return jsonToPhysiSortNode(pJson, pObj);
|
||||
case QUERY_NODE_PHYSICAL_PLAN_INTERVAL:
|
||||
return jsonToPhysiIntervalNode(pJson, pObj);
|
||||
case QUERY_NODE_PHYSICAL_PLAN_SESSION_WINDOW:
|
||||
|
@ -2362,9 +2440,7 @@ static int32_t nodeToJson(const void* pObj, SJson* pJson) {
|
|||
static int32_t jsonToNode(const SJson* pJson, void* pObj) {
|
||||
SNode* pNode = (SNode*)pObj;
|
||||
|
||||
int32_t val = 0;
|
||||
int32_t code = tjsonGetIntValue(pJson, jkNodeType, &val);
|
||||
pNode->type = val;
|
||||
int32_t code = tjsonGetNumberValue(pJson, jkNodeType, pNode->type);
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
code = tjsonToObject(pJson, nodesNodeName(pNode->type), jsonToSpecificNode, pNode);
|
||||
if (TSDB_CODE_SUCCESS != code) {
|
||||
|
|
|
@ -99,6 +99,9 @@ static EDealRes walkNode(SNode* pNode, ETraversalOrder order, FNodeWalker walker
|
|||
if (DEAL_RES_ERROR != res) {
|
||||
res = walkNode(pInterval->pFill, order, walker, pContext);
|
||||
}
|
||||
if (DEAL_RES_ERROR != res) {
|
||||
res = walkNode(pInterval->pCol, order, walker, pContext);
|
||||
}
|
||||
break;
|
||||
}
|
||||
case QUERY_NODE_NODE_LIST:
|
||||
|
@ -225,6 +228,9 @@ static EDealRes rewriteNode(SNode** pRawNode, ETraversalOrder order, FNodeRewrit
|
|||
if (DEAL_RES_ERROR != res) {
|
||||
res = rewriteNode(&(pInterval->pFill), order, rewriter, pContext);
|
||||
}
|
||||
if (DEAL_RES_ERROR != res) {
|
||||
res = rewriteNode(&(pInterval->pCol), order, rewriter, pContext);
|
||||
}
|
||||
break;
|
||||
}
|
||||
case QUERY_NODE_NODE_LIST:
|
||||
|
@ -294,10 +300,10 @@ void nodesWalkSelectStmt(SSelectStmt* pSelect, ESqlClause clause, FNodeWalker wa
|
|||
case SQL_CLAUSE_GROUP_BY:
|
||||
nodesWalkNode(pSelect->pHaving, walker, pContext);
|
||||
case SQL_CLAUSE_HAVING:
|
||||
nodesWalkList(pSelect->pProjectionList, walker, pContext);
|
||||
case SQL_CLAUSE_SELECT:
|
||||
nodesWalkList(pSelect->pOrderByList, walker, pContext);
|
||||
case SQL_CLAUSE_ORDER_BY:
|
||||
nodesWalkList(pSelect->pProjectionList, walker, pContext);
|
||||
case SQL_CLAUSE_SELECT:
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
|
|
@ -159,6 +159,8 @@ SNodeptr nodesMakeNode(ENodeType type) {
|
|||
return makeNode(type, sizeof(SExchangeLogicNode));
|
||||
case QUERY_NODE_LOGIC_PLAN_WINDOW:
|
||||
return makeNode(type, sizeof(SWindowLogicNode));
|
||||
case QUERY_NODE_LOGIC_PLAN_SORT:
|
||||
return makeNode(type, sizeof(SSortLogicNode));
|
||||
case QUERY_NODE_LOGIC_SUBPLAN:
|
||||
return makeNode(type, sizeof(SLogicSubplan));
|
||||
case QUERY_NODE_LOGIC_PLAN:
|
||||
|
@ -182,7 +184,7 @@ SNodeptr nodesMakeNode(ENodeType type) {
|
|||
case QUERY_NODE_PHYSICAL_PLAN_EXCHANGE:
|
||||
return makeNode(type, sizeof(SExchangePhysiNode));
|
||||
case QUERY_NODE_PHYSICAL_PLAN_SORT:
|
||||
return makeNode(type, sizeof(SNode));
|
||||
return makeNode(type, sizeof(SSortPhysiNode));
|
||||
case QUERY_NODE_PHYSICAL_PLAN_INTERVAL:
|
||||
return makeNode(type, sizeof(SIntervalPhysiNode));
|
||||
case QUERY_NODE_PHYSICAL_PLAN_SESSION_WINDOW:
|
||||
|
@ -555,7 +557,7 @@ static EDealRes collectColumns(SNode* pNode, void* pContext) {
|
|||
if (QUERY_NODE_COLUMN == nodeType(pNode)) {
|
||||
SColumnNode* pCol = (SColumnNode*)pNode;
|
||||
int32_t colId = pCol->colId;
|
||||
if (0 == strcmp(pCxt->pTableAlias, pCol->tableAlias)) {
|
||||
if (NULL == pCxt->pTableAlias || 0 == strcmp(pCxt->pTableAlias, pCol->tableAlias)) {
|
||||
return doCollect(pCxt, colId, pNode);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -41,26 +41,26 @@ typedef struct SBoundColumn {
|
|||
} SBoundColumn;
|
||||
|
||||
typedef struct {
|
||||
uint16_t schemaColIdx;
|
||||
uint16_t boundIdx;
|
||||
uint16_t finalIdx;
|
||||
col_id_t schemaColIdx;
|
||||
col_id_t boundIdx;
|
||||
col_id_t finalIdx;
|
||||
} SBoundIdxInfo;
|
||||
|
||||
typedef struct SParsedDataColInfo {
|
||||
int16_t numOfCols;
|
||||
int16_t numOfBound;
|
||||
col_id_t numOfCols;
|
||||
col_id_t numOfBound;
|
||||
uint16_t flen; // TODO: get from STSchema
|
||||
uint16_t allNullLen; // TODO: get from STSchema(base on SDataRow)
|
||||
uint16_t extendedVarLen;
|
||||
uint16_t boundNullLen; // bound column len with all NULL value(without VarDataOffsetT/SColIdx part)
|
||||
int32_t * boundedColumns; // bound column idx according to schema
|
||||
SBoundColumn * cols;
|
||||
col_id_t *boundColumns; // bound column idx according to schema
|
||||
SBoundColumn *cols;
|
||||
SBoundIdxInfo *colIdxInfo;
|
||||
int8_t orderStatus; // bound columns
|
||||
} SParsedDataColInfo;
|
||||
|
||||
typedef struct {
|
||||
uint8_t memRowType; // default is 0, that is SDataRow
|
||||
uint8_t rowType; // default is 0, that is SDataRow
|
||||
int32_t rowSize;
|
||||
} SMemRowBuilder;
|
||||
|
||||
|
@ -92,11 +92,11 @@ static FORCE_INLINE int32_t getExtendedRowSize(STableDataBlocks *pBlock) {
|
|||
(int32_t)TD_BITMAP_BYTES(pTableInfo->numOfColumns - 1);
|
||||
}
|
||||
|
||||
static FORCE_INLINE void getMemRowAppendInfo(SSchema *pSchema, uint8_t rowType, SParsedDataColInfo *spd,
|
||||
int32_t idx, int32_t *toffset, int32_t *colIdx) {
|
||||
int32_t schemaIdx = 0;
|
||||
static FORCE_INLINE void getSTSRowAppendInfo(SSchema *pSchema, uint8_t rowType, SParsedDataColInfo *spd, col_id_t idx,
|
||||
int32_t *toffset, col_id_t *colIdx) {
|
||||
col_id_t schemaIdx = 0;
|
||||
if (IS_DATA_COL_ORDERED(spd)) {
|
||||
schemaIdx = spd->boundedColumns[idx] - PRIMARYKEY_TIMESTAMP_COL_ID;
|
||||
schemaIdx = spd->boundColumns[idx] - PRIMARYKEY_TIMESTAMP_COL_ID;
|
||||
if (TD_IS_TP_ROW_T(rowType)) {
|
||||
*toffset = (spd->cols + schemaIdx)->toffset; // the offset of firstPart
|
||||
*colIdx = schemaIdx;
|
||||
|
@ -132,7 +132,7 @@ static FORCE_INLINE int32_t setBlockInfo(SSubmitBlk *pBlocks, STableDataBlocks*
|
|||
|
||||
int32_t schemaIdxCompar(const void *lhs, const void *rhs);
|
||||
int32_t boundIdxCompar(const void *lhs, const void *rhs);
|
||||
void setBoundColumnInfo(SParsedDataColInfo* pColList, SSchema* pSchema, int32_t numOfCols);
|
||||
void setBoundColumnInfo(SParsedDataColInfo *pColList, SSchema *pSchema, col_id_t numOfCols);
|
||||
void destroyBoundColumnInfo(SParsedDataColInfo* pColList);
|
||||
void destroyBlockArrayList(SArray* pDataBlockList);
|
||||
void destroyBlockHashmap(SHashObj* pDataBlockHash);
|
||||
|
|
|
@ -30,6 +30,8 @@ extern "C" {
|
|||
#define parserDebug(param, ...) qDebug("PARSER: " param, __VA_ARGS__)
|
||||
#define parserTrace(param, ...) qTrace("PARSER: " param, __VA_ARGS__)
|
||||
|
||||
#define PK_TS_COL_INTERNAL_NAME "_rowts"
|
||||
|
||||
typedef struct SMsgBuf {
|
||||
int32_t len;
|
||||
char *buf;
|
||||
|
|
|
@ -645,6 +645,11 @@ SNode* createTempTableNode(SAstCreateContext* pCxt, SNode* pSubquery, const STok
|
|||
tempTable->pSubquery = pSubquery;
|
||||
if (NULL != pTableAlias && TK_NK_NIL != pTableAlias->type) {
|
||||
strncpy(tempTable->table.tableAlias, pTableAlias->z, pTableAlias->n);
|
||||
} else {
|
||||
sprintf(tempTable->table.tableAlias, "%p", tempTable);
|
||||
}
|
||||
if (QUERY_NODE_SELECT_STMT == nodeType(pSubquery)) {
|
||||
strcpy(((SSelectStmt*)pSubquery)->stmtName, tempTable->table.tableAlias);
|
||||
}
|
||||
return (SNode*)tempTable;
|
||||
}
|
||||
|
@ -697,6 +702,13 @@ SNode* createStateWindowNode(SAstCreateContext* pCxt, SNode* pCol) {
|
|||
SNode* createIntervalWindowNode(SAstCreateContext* pCxt, SNode* pInterval, SNode* pOffset, SNode* pSliding, SNode* pFill) {
|
||||
SIntervalWindowNode* interval = (SIntervalWindowNode*)nodesMakeNode(QUERY_NODE_INTERVAL_WINDOW);
|
||||
CHECK_OUT_OF_MEM(interval);
|
||||
interval->pCol = nodesMakeNode(QUERY_NODE_COLUMN);
|
||||
if (NULL == interval->pCol) {
|
||||
nodesDestroyNode(interval);
|
||||
CHECK_OUT_OF_MEM(interval->pCol);
|
||||
}
|
||||
((SColumnNode*)interval->pCol)->colId = PRIMARYKEY_TIMESTAMP_COL_ID;
|
||||
strcpy(((SColumnNode*)interval->pCol)->colName, PK_TS_COL_INTERNAL_NAME);
|
||||
interval->pInterval = pInterval;
|
||||
interval->pOffset = pOffset;
|
||||
interval->pSliding = pSliding;
|
||||
|
@ -792,6 +804,7 @@ SNode* createSelectStmt(SAstCreateContext* pCxt, bool isDistinct, SNodeList* pPr
|
|||
select->isDistinct = isDistinct;
|
||||
select->pProjectionList = pProjectionList;
|
||||
select->pFromTable = pTable;
|
||||
sprintf(select->stmtName, "%p", select);
|
||||
return (SNode*)select;
|
||||
}
|
||||
|
||||
|
|
|
@ -602,7 +602,7 @@ typedef struct SMemParam {
|
|||
SRowBuilder* rb;
|
||||
SSchema* schema;
|
||||
int32_t toffset;
|
||||
int32_t colIdx;
|
||||
col_id_t colIdx;
|
||||
} SMemParam;
|
||||
|
||||
static FORCE_INLINE int32_t MemRowAppend(const void* value, int32_t len, void* param) {
|
||||
|
@ -623,9 +623,11 @@ static FORCE_INLINE int32_t MemRowAppend(const void* value, int32_t len, void* p
|
|||
tdAppendColValToRow(rb, pa->schema->colId, pa->schema->type, TD_VTYPE_NORM, rowEnd, false, pa->toffset, pa->colIdx);
|
||||
} else {
|
||||
if (value == NULL) { // it is a null data
|
||||
tdAppendColValToRow(rb, pa->schema->colId, pa->schema->type, TD_VTYPE_NULL, value, false, pa->toffset, pa->colIdx);
|
||||
tdAppendColValToRow(rb, pa->schema->colId, pa->schema->type, TD_VTYPE_NULL, value, false, pa->toffset,
|
||||
pa->colIdx);
|
||||
} else {
|
||||
tdAppendColValToRow(rb, pa->schema->colId, pa->schema->type, TD_VTYPE_NORM, value, false, pa->toffset, pa->colIdx);
|
||||
tdAppendColValToRow(rb, pa->schema->colId, pa->schema->type, TD_VTYPE_NORM, value, false, pa->toffset,
|
||||
pa->colIdx);
|
||||
}
|
||||
}
|
||||
return TSDB_CODE_SUCCESS;
|
||||
|
@ -633,18 +635,18 @@ static FORCE_INLINE int32_t MemRowAppend(const void* value, int32_t len, void* p
|
|||
|
||||
// pSql -> tag1_name, ...)
|
||||
static int32_t parseBoundColumns(SInsertParseContext* pCxt, SParsedDataColInfo* pColList, SSchema* pSchema) {
|
||||
int32_t nCols = pColList->numOfCols;
|
||||
col_id_t nCols = pColList->numOfCols;
|
||||
|
||||
pColList->numOfBound = 0;
|
||||
pColList->boundNullLen = 0;
|
||||
memset(pColList->boundedColumns, 0, sizeof(int32_t) * nCols);
|
||||
for (int32_t i = 0; i < nCols; ++i) {
|
||||
memset(pColList->boundColumns, 0, sizeof(col_id_t) * nCols);
|
||||
for (col_id_t i = 0; i < nCols; ++i) {
|
||||
pColList->cols[i].valStat = VAL_STAT_NONE;
|
||||
}
|
||||
|
||||
SToken sToken;
|
||||
bool isOrdered = true;
|
||||
int32_t lastColIdx = -1; // last column found
|
||||
col_id_t lastColIdx = -1; // last column found
|
||||
while (1) {
|
||||
NEXT_TOKEN(pCxt->pSql, sToken);
|
||||
|
||||
|
@ -652,8 +654,8 @@ static int32_t parseBoundColumns(SInsertParseContext* pCxt, SParsedDataColInfo*
|
|||
break;
|
||||
}
|
||||
|
||||
int32_t t = lastColIdx + 1;
|
||||
int32_t index = findCol(&sToken, t, nCols, pSchema);
|
||||
col_id_t t = lastColIdx + 1;
|
||||
col_id_t index = findCol(&sToken, t, nCols, pSchema);
|
||||
if (index < 0 && t > 0) {
|
||||
index = findCol(&sToken, 0, t, pSchema);
|
||||
isOrdered = false;
|
||||
|
@ -666,7 +668,7 @@ static int32_t parseBoundColumns(SInsertParseContext* pCxt, SParsedDataColInfo*
|
|||
}
|
||||
lastColIdx = index;
|
||||
pColList->cols[index].valStat = VAL_STAT_HAS;
|
||||
pColList->boundedColumns[pColList->numOfBound] = index + PRIMARYKEY_TIMESTAMP_COL_ID;
|
||||
pColList->boundColumns[pColList->numOfBound] = index + PRIMARYKEY_TIMESTAMP_COL_ID;
|
||||
++pColList->numOfBound;
|
||||
switch (pSchema[t].type) {
|
||||
case TSDB_DATA_TYPE_BINARY:
|
||||
|
@ -689,18 +691,19 @@ static int32_t parseBoundColumns(SInsertParseContext* pCxt, SParsedDataColInfo*
|
|||
return TSDB_CODE_TSC_OUT_OF_MEMORY;
|
||||
}
|
||||
SBoundIdxInfo* pColIdx = pColList->colIdxInfo;
|
||||
for (uint16_t i = 0; i < pColList->numOfBound; ++i) {
|
||||
pColIdx[i].schemaColIdx = (uint16_t)pColList->boundedColumns[i];
|
||||
for (col_id_t i = 0; i < pColList->numOfBound; ++i) {
|
||||
pColIdx[i].schemaColIdx = pColList->boundColumns[i];
|
||||
pColIdx[i].boundIdx = i;
|
||||
}
|
||||
qsort(pColIdx, pColList->numOfBound, sizeof(SBoundIdxInfo), schemaIdxCompar);
|
||||
for (uint16_t i = 0; i < pColList->numOfBound; ++i) {
|
||||
for (col_id_t i = 0; i < pColList->numOfBound; ++i) {
|
||||
pColIdx[i].finalIdx = i;
|
||||
}
|
||||
qsort(pColIdx, pColList->numOfBound, sizeof(SBoundIdxInfo), boundIdxCompar);
|
||||
}
|
||||
|
||||
memset(&pColList->boundedColumns[pColList->numOfBound], 0, sizeof(int32_t) * (pColList->numOfCols - pColList->numOfBound));
|
||||
memset(&pColList->boundColumns[pColList->numOfBound], 0,
|
||||
sizeof(col_id_t) * (pColList->numOfCols - pColList->numOfBound));
|
||||
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
@ -714,8 +717,8 @@ typedef struct SKvParam {
|
|||
static int32_t KvRowAppend(const void *value, int32_t len, void *param) {
|
||||
SKvParam* pa = (SKvParam*) param;
|
||||
|
||||
int32_t type = pa->schema->type;
|
||||
int32_t colId = pa->schema->colId;
|
||||
int8_t type = pa->schema->type;
|
||||
int16_t colId = pa->schema->colId;
|
||||
|
||||
if (TSDB_DATA_TYPE_BINARY == type) {
|
||||
STR_WITH_SIZE_TO_VARSTR(pa->buf, value, len);
|
||||
|
@ -747,7 +750,7 @@ static int32_t parseTagsClause(SInsertParseContext* pCxt, SSchema* pTagsSchema,
|
|||
char tmpTokenBuf[TSDB_MAX_BYTES_PER_ROW] = {0}; // used for deleting Escape character: \\, \', \"
|
||||
for (int i = 0; i < pCxt->tags.numOfBound; ++i) {
|
||||
NEXT_TOKEN_WITH_PREV(pCxt->pSql, sToken);
|
||||
SSchema* pSchema = &pTagsSchema[pCxt->tags.boundedColumns[i]];
|
||||
SSchema* pSchema = &pTagsSchema[pCxt->tags.boundColumns[i]];
|
||||
param.schema = pSchema;
|
||||
CHECK_CODE(parseValueToken(&pCxt->pSql, &sToken, pSchema, precision, tmpTokenBuf, KvRowAppend, ¶m, &pCxt->msg));
|
||||
}
|
||||
|
@ -813,9 +816,9 @@ static int parseOneRow(SInsertParseContext* pCxt, STableDataBlocks* pDataBlocks,
|
|||
// 1. set the parsed value from sql string
|
||||
for (int i = 0; i < spd->numOfBound; ++i) {
|
||||
NEXT_TOKEN_WITH_PREV(pCxt->pSql, sToken);
|
||||
SSchema *pSchema = &schema[spd->boundedColumns[i] - 1];
|
||||
SSchema* pSchema = &schema[spd->boundColumns[i] - 1];
|
||||
param.schema = pSchema;
|
||||
getMemRowAppendInfo(schema, pBuilder->rowType, spd, i, ¶m.toffset, ¶m.colIdx);
|
||||
getSTSRowAppendInfo(schema, pBuilder->rowType, spd, i, ¶m.toffset, ¶m.colIdx);
|
||||
CHECK_CODE(parseValueToken(&pCxt->pSql, &sToken, pSchema, timePrec, tmpTokenBuf, MemRowAppend, ¶m, &pCxt->msg));
|
||||
|
||||
if (PRIMARYKEY_TIMESTAMP_COL_ID == pSchema->colId) {
|
||||
|
|
|
@ -43,11 +43,11 @@ static int32_t rowDataCompar(const void *lhs, const void *rhs) {
|
|||
}
|
||||
}
|
||||
|
||||
void setBoundColumnInfo(SParsedDataColInfo* pColList, SSchema* pSchema, int32_t numOfCols) {
|
||||
void setBoundColumnInfo(SParsedDataColInfo* pColList, SSchema* pSchema, col_id_t numOfCols) {
|
||||
pColList->numOfCols = numOfCols;
|
||||
pColList->numOfBound = numOfCols;
|
||||
pColList->orderStatus = ORDER_STATUS_ORDERED; // default is ORDERED for non-bound mode
|
||||
pColList->boundedColumns = taosMemoryCalloc(pColList->numOfCols, sizeof(int32_t));
|
||||
pColList->boundColumns = taosMemoryCalloc(pColList->numOfCols, sizeof(col_id_t));
|
||||
pColList->cols = taosMemoryCalloc(pColList->numOfCols, sizeof(SBoundColumn));
|
||||
pColList->colIdxInfo = NULL;
|
||||
pColList->flen = 0;
|
||||
|
@ -73,7 +73,7 @@ void setBoundColumnInfo(SParsedDataColInfo* pColList, SSchema* pSchema, int32_t
|
|||
default:
|
||||
break;
|
||||
}
|
||||
pColList->boundedColumns[i] = pSchema[i].colId;
|
||||
pColList->boundColumns[i] = pSchema[i].colId;
|
||||
}
|
||||
pColList->allNullLen += pColList->flen;
|
||||
pColList->boundNullLen = pColList->allNullLen; // default set allNullLen
|
||||
|
@ -103,7 +103,7 @@ int32_t boundIdxCompar(const void *lhs, const void *rhs) {
|
|||
}
|
||||
|
||||
void destroyBoundColumnInfo(SParsedDataColInfo* pColList) {
|
||||
taosMemoryFreeClear(pColList->boundedColumns);
|
||||
taosMemoryFreeClear(pColList->boundColumns);
|
||||
taosMemoryFreeClear(pColList->cols);
|
||||
taosMemoryFreeClear(pColList->colIdxInfo);
|
||||
}
|
||||
|
|
|
@ -271,6 +271,10 @@ static bool findAndSetColumn(SColumnNode* pCol, const STableNode* pTable) {
|
|||
bool found = false;
|
||||
if (QUERY_NODE_REAL_TABLE == nodeType(pTable)) {
|
||||
const STableMeta* pMeta = ((SRealTableNode*)pTable)->pMeta;
|
||||
if (PRIMARYKEY_TIMESTAMP_COL_ID == pCol->colId && 0 == strcmp(pCol->colName, PK_TS_COL_INTERNAL_NAME)) {
|
||||
setColumnInfoBySchema((SRealTableNode*)pTable, pMeta->schema, false, pCol);
|
||||
return true;
|
||||
}
|
||||
int32_t nums = pMeta->tableInfo.numOfTags + pMeta->tableInfo.numOfColumns;
|
||||
for (int32_t i = 0; i < nums; ++i) {
|
||||
if (0 == strcmp(pCol->colName, pMeta->schema[i].name)) {
|
||||
|
@ -1448,6 +1452,7 @@ static int32_t getSmaIndexBuildAst(STranslateContext* pCxt, SCreateIndexStmt* pS
|
|||
if (NULL == pSelect) {
|
||||
return TSDB_CODE_OUT_OF_MEMORY;
|
||||
}
|
||||
sprintf(pSelect->stmtName, "%p", pSelect);
|
||||
|
||||
SRealTableNode* pTable = nodesMakeNode(QUERY_NODE_REAL_TABLE);
|
||||
if (NULL == pTable) {
|
||||
|
@ -1463,6 +1468,10 @@ static int32_t getSmaIndexBuildAst(STranslateContext* pCxt, SCreateIndexStmt* pS
|
|||
nodesDestroyNode(pSelect);
|
||||
return TSDB_CODE_OUT_OF_MEMORY;
|
||||
}
|
||||
SNode* pProject = NULL;
|
||||
FOREACH(pProject, pSelect->pProjectionList) {
|
||||
sprintf(((SExprNode*)pProject)->aliasName, "#sma_%p", pProject);
|
||||
}
|
||||
|
||||
SIntervalWindowNode* pInterval = nodesMakeNode(QUERY_NODE_INTERVAL_WINDOW);
|
||||
if (NULL == pInterval) {
|
||||
|
@ -1470,14 +1479,18 @@ static int32_t getSmaIndexBuildAst(STranslateContext* pCxt, SCreateIndexStmt* pS
|
|||
return TSDB_CODE_OUT_OF_MEMORY;
|
||||
}
|
||||
pSelect->pWindow = (SNode*)pInterval;
|
||||
pInterval->pCol = nodesMakeNode(QUERY_NODE_COLUMN);
|
||||
pInterval->pInterval = nodesCloneNode(pStmt->pOptions->pInterval);
|
||||
pInterval->pOffset = nodesCloneNode(pStmt->pOptions->pOffset);
|
||||
pInterval->pSliding = nodesCloneNode(pStmt->pOptions->pSliding);
|
||||
if (NULL == pInterval->pInterval || (NULL != pStmt->pOptions->pOffset && NULL == pInterval->pOffset) ||
|
||||
if (NULL == pInterval->pCol || NULL == pInterval->pInterval ||
|
||||
(NULL != pStmt->pOptions->pOffset && NULL == pInterval->pOffset) ||
|
||||
(NULL != pStmt->pOptions->pSliding && NULL == pInterval->pSliding)) {
|
||||
nodesDestroyNode(pSelect);
|
||||
return TSDB_CODE_OUT_OF_MEMORY;
|
||||
}
|
||||
((SColumnNode*)pInterval->pCol)->colId = PRIMARYKEY_TIMESTAMP_COL_ID;
|
||||
strcpy(((SColumnNode*)pInterval->pCol)->colName, PK_TS_COL_INTERNAL_NAME);
|
||||
|
||||
int32_t code = translateQuery(pCxt, (SNode*)pSelect);
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
|
@ -1787,7 +1800,7 @@ static int32_t translateSubquery(STranslateContext* pCxt, SNode* pNode) {
|
|||
}
|
||||
|
||||
int32_t qExtractResultSchema(const SNode* pRoot, int32_t* numOfCols, SSchema** pSchema) {
|
||||
if (QUERY_NODE_SELECT_STMT == nodeType(pRoot)) {
|
||||
if (NULL != pRoot && QUERY_NODE_SELECT_STMT == nodeType(pRoot)) {
|
||||
SSelectStmt* pSelect = (SSelectStmt*) pRoot;
|
||||
*numOfCols = LIST_LENGTH(pSelect->pProjectionList);
|
||||
*pSchema = taosMemoryCalloc((*numOfCols), sizeof(SSchema));
|
||||
|
@ -1865,6 +1878,7 @@ static int32_t createSelectStmtForShow(ENodeType showType, SSelectStmt** pStmt)
|
|||
if (NULL == pSelect) {
|
||||
return TSDB_CODE_OUT_OF_MEMORY;
|
||||
}
|
||||
sprintf(pSelect->stmtName, "%p", pSelect);
|
||||
|
||||
SRealTableNode* pTable = nodesMakeNode(QUERY_NODE_REAL_TABLE);
|
||||
if (NULL == pTable) {
|
||||
|
@ -1873,6 +1887,7 @@ static int32_t createSelectStmtForShow(ENodeType showType, SSelectStmt** pStmt)
|
|||
}
|
||||
strcpy(pTable->table.dbName, TSDB_INFORMATION_SCHEMA_DB);
|
||||
strcpy(pTable->table.tableName, getSysTableName(showType));
|
||||
strcpy(pTable->table.tableAlias, pTable->table.tableName);
|
||||
pSelect->pFromTable = (SNode*)pTable;
|
||||
|
||||
*pStmt = pSelect;
|
||||
|
@ -1975,7 +1990,7 @@ typedef struct SVgroupTablesBatch {
|
|||
char dbName[TSDB_DB_NAME_LEN];
|
||||
} SVgroupTablesBatch;
|
||||
|
||||
static void toSchema(const SColumnDefNode* pCol, int32_t colId, SSchema* pSchema) {
|
||||
static void toSchema(const SColumnDefNode* pCol, col_id_t colId, SSchema* pSchema) {
|
||||
pSchema->colId = colId;
|
||||
pSchema->type = pCol->dataType.type;
|
||||
pSchema->bytes = pCol->dataType.bytes;
|
||||
|
@ -2385,13 +2400,14 @@ static int32_t rewriteQuery(STranslateContext* pCxt, SQuery* pQuery) {
|
|||
}
|
||||
|
||||
static int32_t setQuery(STranslateContext* pCxt, SQuery* pQuery) {
|
||||
int32_t code = TSDB_CODE_SUCCESS;
|
||||
switch (nodeType(pQuery->pRoot)) {
|
||||
case QUERY_NODE_SELECT_STMT:
|
||||
pQuery->haveResultSet = true;
|
||||
pQuery->directRpc = false;
|
||||
pQuery->msgType = TDMT_VND_QUERY;
|
||||
code = qExtractResultSchema(pQuery->pRoot, &pQuery->numOfResCols, &pQuery->pResSchema);
|
||||
if (TSDB_CODE_SUCCESS != qExtractResultSchema(pQuery->pRoot, &pQuery->numOfResCols, &pQuery->pResSchema)) {
|
||||
return TSDB_CODE_OUT_OF_MEMORY;
|
||||
}
|
||||
break;
|
||||
case QUERY_NODE_VNODE_MODIF_STMT:
|
||||
pQuery->haveResultSet = false;
|
||||
|
@ -2431,7 +2447,7 @@ static int32_t setQuery(STranslateContext* pCxt, SQuery* pQuery) {
|
|||
}
|
||||
}
|
||||
|
||||
return code;
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
int32_t doTranslate(SParseContext* pParseCxt, SQuery* pQuery) {
|
||||
|
|
|
@ -87,7 +87,7 @@ private:
|
|||
return meta_;
|
||||
}
|
||||
|
||||
int32_t colId_;
|
||||
col_id_t colId_;
|
||||
int32_t rowsize_;
|
||||
std::shared_ptr<MockTableMeta> meta_;
|
||||
};
|
||||
|
|
|
@ -22,32 +22,6 @@ extern "C" {
|
|||
|
||||
#include "planner.h"
|
||||
|
||||
#define CHECK_ALLOC(p, res) \
|
||||
do { \
|
||||
if (NULL == (p)) { \
|
||||
pCxt->errCode = TSDB_CODE_OUT_OF_MEMORY; \
|
||||
return (res); \
|
||||
} \
|
||||
} while (0)
|
||||
|
||||
#define CHECK_CODE(exec, res) \
|
||||
do { \
|
||||
int32_t code = (exec); \
|
||||
if (TSDB_CODE_SUCCESS != code) { \
|
||||
pCxt->errCode = code; \
|
||||
return (res); \
|
||||
} \
|
||||
} while (0)
|
||||
|
||||
#define CHECK_CODE_EXT(exec) \
|
||||
do { \
|
||||
int32_t code = (exec); \
|
||||
if (TSDB_CODE_SUCCESS != code) { \
|
||||
pCxt->errCode = code; \
|
||||
return code; \
|
||||
} \
|
||||
} while (0)
|
||||
|
||||
#define planFatal(param, ...) qFatal("PLAN: " param, __VA_ARGS__)
|
||||
#define planError(param, ...) qError("PLAN: " param, __VA_ARGS__)
|
||||
#define planWarn(param, ...) qWarn("PLAN: " param, __VA_ARGS__)
|
||||
|
|
|
@ -45,7 +45,9 @@ static EDealRes doRewriteExpr(SNode** pNode, void* pContext) {
|
|||
}
|
||||
if (nodesEqualNode(pExpr, *pNode)) {
|
||||
SColumnNode* pCol = (SColumnNode*)nodesMakeNode(QUERY_NODE_COLUMN);
|
||||
CHECK_ALLOC(pCol, DEAL_RES_ERROR);
|
||||
if (NULL == pCol) {
|
||||
return DEAL_RES_ERROR;
|
||||
}
|
||||
SExprNode* pToBeRewrittenExpr = (SExprNode*)(*pNode);
|
||||
pCol->node.resType = pToBeRewrittenExpr->resType;
|
||||
strcpy(pCol->node.aliasName, pToBeRewrittenExpr->aliasName);
|
||||
|
@ -65,17 +67,12 @@ static EDealRes doRewriteExpr(SNode** pNode, void* pContext) {
|
|||
return DEAL_RES_CONTINUE;
|
||||
}
|
||||
|
||||
typedef struct SNameExprCxt {
|
||||
int32_t rewriteId;
|
||||
} SNameExprCxt;
|
||||
|
||||
static EDealRes doNameExpr(SNode* pNode, void* pContext) {
|
||||
switch (nodeType(pNode)) {
|
||||
case QUERY_NODE_OPERATOR:
|
||||
case QUERY_NODE_LOGIC_CONDITION:
|
||||
case QUERY_NODE_FUNCTION: {
|
||||
SNameExprCxt* pCxt = (SNameExprCxt*)pContext;
|
||||
sprintf(((SExprNode*)pNode)->aliasName, "#expr_%d", pCxt->rewriteId++);
|
||||
sprintf(((SExprNode*)pNode)->aliasName, "#expr_%p", pNode);
|
||||
return DEAL_RES_IGNORE_CHILD;
|
||||
}
|
||||
default:
|
||||
|
@ -86,9 +83,7 @@ static EDealRes doNameExpr(SNode* pNode, void* pContext) {
|
|||
}
|
||||
|
||||
static int32_t rewriteExpr(SNodeList* pExprs, SSelectStmt* pSelect, ESqlClause clause) {
|
||||
static int32_t rewriteId = 1;
|
||||
SNameExprCxt nameCxt = { .rewriteId = rewriteId };
|
||||
nodesWalkList(pExprs, doNameExpr, &nameCxt);
|
||||
nodesWalkList(pExprs, doNameExpr, NULL);
|
||||
SRewriteExprCxt cxt = { .errCode = TSDB_CODE_SUCCESS, .pExprs = pExprs };
|
||||
nodesRewriteSelectStmt(pSelect, clause, doRewriteExpr, &cxt);
|
||||
return cxt.errCode;
|
||||
|
@ -291,13 +286,14 @@ static int32_t createLogicNodeByTable(SLogicPlanContext* pCxt, SSelectStmt* pSel
|
|||
return code;
|
||||
}
|
||||
|
||||
static SColumnNode* createColumnByExpr(SExprNode* pExpr) {
|
||||
static SColumnNode* createColumnByExpr(const char* pStmtName, SExprNode* pExpr) {
|
||||
SColumnNode* pCol = nodesMakeNode(QUERY_NODE_COLUMN);
|
||||
if (NULL == pCol) {
|
||||
return NULL;
|
||||
}
|
||||
pCol->node.resType = pExpr->resType;
|
||||
strcpy(pCol->colName, pExpr->aliasName);
|
||||
strcpy(pCol->tableAlias, pStmtName);
|
||||
return pCol;
|
||||
}
|
||||
|
||||
|
@ -311,20 +307,22 @@ static EDealRes doCreateColumn(SNode* pNode, void* pContext) {
|
|||
switch (nodeType(pNode)) {
|
||||
case QUERY_NODE_COLUMN: {
|
||||
SNode* pCol = nodesCloneNode(pNode);
|
||||
CHECK_ALLOC(pCol, DEAL_RES_ERROR);
|
||||
CHECK_CODE(nodesListAppend(pCxt->pList, pCol), DEAL_RES_ERROR);
|
||||
return DEAL_RES_IGNORE_CHILD;
|
||||
if (NULL == pCol) {
|
||||
return DEAL_RES_ERROR;
|
||||
}
|
||||
return (TSDB_CODE_SUCCESS == nodesListAppend(pCxt->pList, pCol) ? DEAL_RES_IGNORE_CHILD : DEAL_RES_ERROR);
|
||||
}
|
||||
case QUERY_NODE_OPERATOR:
|
||||
case QUERY_NODE_LOGIC_CONDITION:
|
||||
case QUERY_NODE_FUNCTION: {
|
||||
SExprNode* pExpr = (SExprNode*)pNode;
|
||||
SColumnNode* pCol = (SColumnNode*)nodesMakeNode(QUERY_NODE_COLUMN);
|
||||
CHECK_ALLOC(pCol, DEAL_RES_ERROR);
|
||||
if (NULL == pCol) {
|
||||
return DEAL_RES_ERROR;
|
||||
}
|
||||
pCol->node.resType = pExpr->resType;
|
||||
strcpy(pCol->colName, pExpr->aliasName);
|
||||
CHECK_CODE(nodesListAppend(pCxt->pList, (SNode*)pCol), DEAL_RES_ERROR);
|
||||
return DEAL_RES_IGNORE_CHILD;
|
||||
return (TSDB_CODE_SUCCESS == nodesListAppend(pCxt->pList, pCol) ? DEAL_RES_IGNORE_CHILD : DEAL_RES_ERROR);
|
||||
}
|
||||
default:
|
||||
break;
|
||||
|
@ -457,6 +455,12 @@ static int32_t createWindowLogicNodeByInterval(SLogicPlanContext* pCxt, SInterva
|
|||
pWindow->sliding = (NULL != pInterval->pSliding ? ((SValueNode*)pInterval->pSliding)->datum.i : pWindow->interval);
|
||||
pWindow->slidingUnit = (NULL != pInterval->pSliding ? ((SValueNode*)pInterval->pSliding)->unit : pWindow->intervalUnit);
|
||||
|
||||
pWindow->pTspk = nodesCloneNode(pInterval->pCol);
|
||||
if (NULL == pWindow->pTspk) {
|
||||
nodesDestroyNode(pWindow);
|
||||
return TSDB_CODE_OUT_OF_MEMORY;
|
||||
}
|
||||
|
||||
if (NULL != pInterval->pFill) {
|
||||
pWindow->pFill = nodesCloneNode(pInterval->pFill);
|
||||
if (NULL == pWindow->pFill) {
|
||||
|
@ -485,7 +489,42 @@ static int32_t createWindowLogicNode(SLogicPlanContext* pCxt, SSelectStmt* pSele
|
|||
return TSDB_CODE_FAILED;
|
||||
}
|
||||
|
||||
static int32_t createColumnByProjections(SLogicPlanContext* pCxt, SNodeList* pExprs, SNodeList** pCols) {
|
||||
static int32_t createSortLogicNode(SLogicPlanContext* pCxt, SSelectStmt* pSelect, SLogicNode** pLogicNode) {
|
||||
if (NULL == pSelect->pOrderByList) {
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
SSortLogicNode* pSort = nodesMakeNode(QUERY_NODE_LOGIC_PLAN_SORT);
|
||||
if (NULL == pSort) {
|
||||
return TSDB_CODE_OUT_OF_MEMORY;
|
||||
}
|
||||
|
||||
SNodeList* pCols = NULL;
|
||||
int32_t code = nodesCollectColumns(pSelect, SQL_CLAUSE_ORDER_BY, NULL, &pCols);
|
||||
if (TSDB_CODE_SUCCESS == code && NULL != pCols) {
|
||||
pSort->node.pTargets = nodesCloneList(pCols);
|
||||
if (NULL == pSort->node.pTargets) {
|
||||
code = TSDB_CODE_OUT_OF_MEMORY;
|
||||
}
|
||||
}
|
||||
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
pSort->pSortKeys = nodesCloneList(pSelect->pOrderByList);
|
||||
if (NULL == pSort->pSortKeys) {
|
||||
code = TSDB_CODE_OUT_OF_MEMORY;
|
||||
}
|
||||
}
|
||||
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
*pLogicNode = (SLogicNode*)pSort;
|
||||
} else {
|
||||
nodesDestroyNode(pSort);
|
||||
}
|
||||
|
||||
return code;
|
||||
}
|
||||
|
||||
static int32_t createColumnByProjections(SLogicPlanContext* pCxt, const char* pStmtName, SNodeList* pExprs, SNodeList** pCols) {
|
||||
SNodeList* pList = nodesMakeList();
|
||||
if (NULL == pList) {
|
||||
return TSDB_CODE_OUT_OF_MEMORY;
|
||||
|
@ -493,7 +532,7 @@ static int32_t createColumnByProjections(SLogicPlanContext* pCxt, SNodeList* pEx
|
|||
|
||||
SNode* pNode;
|
||||
FOREACH(pNode, pExprs) {
|
||||
if (TSDB_CODE_SUCCESS != nodesListAppend(pList, createColumnByExpr((SExprNode*)pNode))) {
|
||||
if (TSDB_CODE_SUCCESS != nodesListAppend(pList, createColumnByExpr(pStmtName, (SExprNode*)pNode))) {
|
||||
nodesDestroyList(pList);
|
||||
return TSDB_CODE_OUT_OF_MEMORY;
|
||||
}
|
||||
|
@ -515,9 +554,10 @@ static int32_t createProjectLogicNode(SLogicPlanContext* pCxt, SSelectStmt* pSel
|
|||
if (NULL == pProject->pProjections) {
|
||||
code = TSDB_CODE_OUT_OF_MEMORY;
|
||||
}
|
||||
strcpy(pProject->stmtName, pSelect->stmtName);
|
||||
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
code = createColumnByProjections(pCxt,pSelect->pProjectionList, &pProject->node.pTargets);
|
||||
code = createColumnByProjections(pCxt, pSelect->stmtName, pSelect->pProjectionList, &pProject->node.pTargets);
|
||||
}
|
||||
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
|
@ -538,6 +578,9 @@ static int32_t createSelectLogicNode(SLogicPlanContext* pCxt, SSelectStmt* pSele
|
|||
if (TSDB_CODE_SUCCESS == code) {
|
||||
code = createChildLogicNode(pCxt, pSelect, createAggLogicNode, &pRoot);
|
||||
}
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
code = createChildLogicNode(pCxt, pSelect, createSortLogicNode, &pRoot);
|
||||
}
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
code = createChildLogicNode(pCxt, pSelect, createProjectLogicNode, &pRoot);
|
||||
}
|
||||
|
|
|
@ -17,9 +17,14 @@
|
|||
|
||||
#include "functionMgt.h"
|
||||
|
||||
typedef struct SSlotIdInfo {
|
||||
int16_t slotId;
|
||||
bool set;
|
||||
} SSlotIdInfo;
|
||||
|
||||
typedef struct SSlotIndex {
|
||||
int16_t dataBlockId;
|
||||
int16_t slotId;
|
||||
SArray* pSlotIdsInfo; // duplicate name slot
|
||||
} SSlotIndex;
|
||||
|
||||
typedef struct SPhysiPlanContext {
|
||||
|
@ -30,72 +35,195 @@ typedef struct SPhysiPlanContext {
|
|||
SArray* pExecNodeList;
|
||||
} SPhysiPlanContext;
|
||||
|
||||
static int32_t getSlotKey(SNode* pNode, char* pKey) {
|
||||
static int32_t getSlotKey(SNode* pNode, const char* pStmtName, char* pKey) {
|
||||
if (QUERY_NODE_ORDER_BY_EXPR == nodeType(pNode)) {
|
||||
return getSlotKey(((SOrderByExprNode*)pNode)->pExpr, pStmtName, pKey);
|
||||
}
|
||||
|
||||
if (QUERY_NODE_COLUMN == nodeType(pNode)) {
|
||||
SColumnNode* pCol = (SColumnNode*)pNode;
|
||||
if (NULL != pStmtName) {
|
||||
return sprintf(pKey, "%s.%s", pStmtName, pCol->node.aliasName);
|
||||
}
|
||||
if ('\0' == pCol->tableAlias[0]) {
|
||||
return sprintf(pKey, "%s", pCol->colName);
|
||||
}
|
||||
return sprintf(pKey, "%s.%s", pCol->tableAlias, pCol->colName);
|
||||
}
|
||||
|
||||
if (NULL != pStmtName) {
|
||||
return sprintf(pKey, "%s.%s", pStmtName, ((SExprNode*)pNode)->aliasName);
|
||||
}
|
||||
return sprintf(pKey, "%s", ((SExprNode*)pNode)->aliasName);
|
||||
}
|
||||
|
||||
static SNode* createSlotDesc(SPhysiPlanContext* pCxt, const SNode* pNode, int16_t slotId) {
|
||||
static SNode* createSlotDesc(SPhysiPlanContext* pCxt, const SNode* pNode, int16_t slotId, bool output) {
|
||||
SSlotDescNode* pSlot = (SSlotDescNode*)nodesMakeNode(QUERY_NODE_SLOT_DESC);
|
||||
CHECK_ALLOC(pSlot, NULL);
|
||||
if (NULL == pSlot) {
|
||||
return NULL;
|
||||
}
|
||||
pSlot->slotId = slotId;
|
||||
pSlot->dataType = ((SExprNode*)pNode)->resType;
|
||||
pSlot->reserve = false;
|
||||
pSlot->output = true;
|
||||
pSlot->output = output;
|
||||
return (SNode*)pSlot;
|
||||
}
|
||||
|
||||
static SNode* createTarget(SNode* pNode, int16_t dataBlockId, int16_t slotId) {
|
||||
static int32_t createTarget(SNode* pNode, int16_t dataBlockId, int16_t slotId, SNode** pOutput) {
|
||||
STargetNode* pTarget = (STargetNode*)nodesMakeNode(QUERY_NODE_TARGET);
|
||||
if (NULL == pTarget) {
|
||||
return NULL;
|
||||
return TSDB_CODE_OUT_OF_MEMORY;
|
||||
}
|
||||
|
||||
pTarget->dataBlockId = dataBlockId;
|
||||
pTarget->slotId = slotId;
|
||||
pTarget->pExpr = pNode;
|
||||
return (SNode*)pTarget;
|
||||
|
||||
*pOutput = (SNode*)pTarget;
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
static int32_t addDataBlockDesc(SPhysiPlanContext* pCxt, SNodeList* pList, SDataBlockDescNode* pDataBlockDesc) {
|
||||
SHashObj* pHash = NULL;
|
||||
if (NULL == pDataBlockDesc->pSlots) {
|
||||
pDataBlockDesc->pSlots = nodesMakeList();
|
||||
CHECK_ALLOC(pDataBlockDesc->pSlots, TSDB_CODE_OUT_OF_MEMORY);
|
||||
static int32_t putSlotToHashImpl(int16_t dataBlockId, int16_t slotId, const char* pName, int32_t len, SHashObj* pHash) {
|
||||
SSlotIndex* pIndex = taosHashGet(pHash, pName, len);
|
||||
if (NULL != pIndex) {
|
||||
SSlotIdInfo info = { .slotId = slotId, .set = false };
|
||||
taosArrayPush(pIndex->pSlotIdsInfo, &info);
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
pHash = taosHashInit(LIST_LENGTH(pList), taosGetDefaultHashFunction(TSDB_DATA_TYPE_BINARY), true, HASH_NO_LOCK);
|
||||
CHECK_ALLOC(pHash, TSDB_CODE_OUT_OF_MEMORY);
|
||||
if (NULL == taosArrayInsert(pCxt->pLocationHelper, pDataBlockDesc->dataBlockId, &pHash)) {
|
||||
SSlotIndex index = { .dataBlockId = dataBlockId, .pSlotIdsInfo = taosArrayInit(TARRAY_MIN_SIZE, sizeof(SSlotIdInfo)) };
|
||||
if (NULL == index.pSlotIdsInfo) {
|
||||
return TSDB_CODE_OUT_OF_MEMORY;
|
||||
}
|
||||
SSlotIdInfo info = { .slotId = slotId, .set = false };
|
||||
taosArrayPush(index.pSlotIdsInfo, &info);
|
||||
return taosHashPut(pHash, pName, len, &index, sizeof(SSlotIndex));
|
||||
}
|
||||
|
||||
static int32_t putSlotToHash(int16_t dataBlockId, int16_t slotId, SNode* pNode, SHashObj* pHash) {
|
||||
char name[TSDB_TABLE_NAME_LEN + TSDB_COL_NAME_LEN];
|
||||
int32_t len = getSlotKey(pNode, NULL, name);
|
||||
return putSlotToHashImpl(dataBlockId, slotId, name, len, pHash);
|
||||
}
|
||||
|
||||
static int32_t createDataBlockDescHash(SPhysiPlanContext* pCxt, int32_t capacity, int16_t dataBlockId, SHashObj** pDescHash) {
|
||||
SHashObj* pHash = taosHashInit(capacity, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BINARY), false, HASH_NO_LOCK);
|
||||
if (NULL == pHash) {
|
||||
return TSDB_CODE_OUT_OF_MEMORY;
|
||||
}
|
||||
if (NULL == taosArrayInsert(pCxt->pLocationHelper, dataBlockId, &pHash)) {
|
||||
taosHashCleanup(pHash);
|
||||
return TSDB_CODE_OUT_OF_MEMORY;
|
||||
}
|
||||
} else {
|
||||
pHash = taosArrayGetP(pCxt->pLocationHelper, pDataBlockDesc->dataBlockId);
|
||||
|
||||
*pDescHash = pHash;
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
static int32_t buildDataBlockSlots(SPhysiPlanContext* pCxt, SNodeList* pList, SDataBlockDescNode* pDataBlockDesc, SHashObj* pHash) {
|
||||
pDataBlockDesc->pSlots = nodesMakeList();
|
||||
if (NULL == pDataBlockDesc->pSlots) {
|
||||
return TSDB_CODE_OUT_OF_MEMORY;
|
||||
}
|
||||
|
||||
int32_t code = TSDB_CODE_SUCCESS;
|
||||
int16_t slotId = 0;
|
||||
SNode* pNode = NULL;
|
||||
int16_t slotId = taosHashGetSize(pHash);
|
||||
FOREACH(pNode, pList) {
|
||||
CHECK_CODE_EXT(nodesListStrictAppend(pDataBlockDesc->pSlots, createSlotDesc(pCxt, pNode, slotId)));
|
||||
|
||||
SSlotIndex index = { .dataBlockId = pDataBlockDesc->dataBlockId, .slotId = slotId };
|
||||
char name[TSDB_TABLE_NAME_LEN + TSDB_COL_NAME_LEN];
|
||||
int32_t len = getSlotKey(pNode, name);
|
||||
CHECK_CODE(taosHashPut(pHash, name, len, &index, sizeof(SSlotIndex)), TSDB_CODE_OUT_OF_MEMORY);
|
||||
|
||||
SNode* pTarget = createTarget(pNode, pDataBlockDesc->dataBlockId, slotId);
|
||||
CHECK_ALLOC(pTarget, TSDB_CODE_OUT_OF_MEMORY);
|
||||
REPLACE_NODE(pTarget);
|
||||
|
||||
code = nodesListStrictAppend(pDataBlockDesc->pSlots, createSlotDesc(pCxt, pNode, slotId, true));
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
code = putSlotToHash(pDataBlockDesc->dataBlockId, slotId, pNode, pHash);
|
||||
}
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
pDataBlockDesc->resultRowSize += ((SExprNode*)pNode)->resType.bytes;
|
||||
++slotId;
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
return code;
|
||||
}
|
||||
|
||||
static int32_t createDataBlockDesc(SPhysiPlanContext* pCxt, SNodeList* pList, SDataBlockDescNode** pDataBlockDesc) {
|
||||
SDataBlockDescNode* pDesc = nodesMakeNode(QUERY_NODE_DATABLOCK_DESC);
|
||||
if (NULL == pDesc) {
|
||||
return TSDB_CODE_OUT_OF_MEMORY;
|
||||
}
|
||||
pDesc->dataBlockId = pCxt->nextDataBlockId++;
|
||||
|
||||
SHashObj* pHash = NULL;
|
||||
int32_t code = createDataBlockDescHash(pCxt, LIST_LENGTH(pList), pDesc->dataBlockId, &pHash);
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
code = buildDataBlockSlots(pCxt, pList, pDesc, pHash);
|
||||
}
|
||||
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
*pDataBlockDesc = pDesc;
|
||||
} else {
|
||||
nodesDestroyNode(pDesc);
|
||||
}
|
||||
|
||||
return code;
|
||||
}
|
||||
|
||||
static int16_t getUnsetSlotId(const SArray* pSlotIdsInfo) {
|
||||
int32_t size = taosArrayGetSize(pSlotIdsInfo);
|
||||
for (int32_t i = 0; i < size; ++i) {
|
||||
SSlotIdInfo* pInfo = taosArrayGet(pSlotIdsInfo, i);
|
||||
if (!pInfo->set) {
|
||||
pInfo->set = true;
|
||||
return pInfo->slotId;
|
||||
}
|
||||
}
|
||||
return ((SSlotIdInfo*)taosArrayGet(pSlotIdsInfo, 0))->slotId;
|
||||
}
|
||||
|
||||
static int32_t addDataBlockSlotsImpl(SPhysiPlanContext* pCxt, SNodeList* pList, SDataBlockDescNode* pDataBlockDesc, const char* pStmtName, bool output) {
|
||||
int32_t code = TSDB_CODE_SUCCESS;
|
||||
SHashObj* pHash = taosArrayGetP(pCxt->pLocationHelper, pDataBlockDesc->dataBlockId);
|
||||
int16_t nextSlotId = taosHashGetSize(pHash), slotId = 0;
|
||||
SNode* pNode = NULL;
|
||||
FOREACH(pNode, pList) {
|
||||
char name[TSDB_TABLE_NAME_LEN + TSDB_COL_NAME_LEN] = {0};
|
||||
int32_t len = getSlotKey(pNode, pStmtName, name);
|
||||
SSlotIndex* pIndex = taosHashGet(pHash, name, len);
|
||||
if (NULL == pIndex) {
|
||||
code = nodesListStrictAppend(pDataBlockDesc->pSlots, createSlotDesc(pCxt, pNode, nextSlotId, output));
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
code = putSlotToHashImpl(pDataBlockDesc->dataBlockId, nextSlotId, name, len, pHash);
|
||||
}
|
||||
pDataBlockDesc->resultRowSize += ((SExprNode*)pNode)->resType.bytes;
|
||||
slotId = nextSlotId;
|
||||
++nextSlotId;
|
||||
} else {
|
||||
slotId = getUnsetSlotId(pIndex->pSlotIdsInfo);
|
||||
}
|
||||
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
SNode* pTarget = NULL;
|
||||
code = createTarget(pNode, pDataBlockDesc->dataBlockId, slotId, &pTarget);
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
REPLACE_NODE(pTarget);
|
||||
}
|
||||
}
|
||||
|
||||
if (TSDB_CODE_SUCCESS != code) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
return code;
|
||||
}
|
||||
|
||||
static int32_t addDataBlockSlots(SPhysiPlanContext* pCxt, SNodeList* pList, SDataBlockDescNode* pDataBlockDesc) {
|
||||
return addDataBlockSlotsImpl(pCxt, pList, pDataBlockDesc, NULL, false);
|
||||
}
|
||||
|
||||
static int32_t addDataBlockSlotsForProject(SPhysiPlanContext* pCxt, const char* pStmtName, SNodeList* pList, SDataBlockDescNode* pDataBlockDesc) {
|
||||
return addDataBlockSlotsImpl(pCxt, pList, pDataBlockDesc, pStmtName, true);
|
||||
}
|
||||
|
||||
static int32_t pushdownDataBlockSlots(SPhysiPlanContext* pCxt, SNodeList* pList, SDataBlockDescNode* pDataBlockDesc) {
|
||||
return addDataBlockSlotsImpl(pCxt, pList, pDataBlockDesc, NULL, true);
|
||||
}
|
||||
|
||||
typedef struct SSetSlotIdCxt {
|
||||
|
@ -108,16 +236,17 @@ static EDealRes doSetSlotId(SNode* pNode, void* pContext) {
|
|||
if (QUERY_NODE_COLUMN == nodeType(pNode) && 0 != strcmp(((SColumnNode*)pNode)->colName, "*")) {
|
||||
SSetSlotIdCxt* pCxt = (SSetSlotIdCxt*)pContext;
|
||||
char name[TSDB_TABLE_NAME_LEN + TSDB_COL_NAME_LEN];
|
||||
int32_t len = getSlotKey(pNode, name);
|
||||
int32_t len = getSlotKey(pNode, NULL, name);
|
||||
SSlotIndex* pIndex = taosHashGet(pCxt->pLeftHash, name, len);
|
||||
if (NULL == pIndex) {
|
||||
pIndex = taosHashGet(pCxt->pRightHash, name, len);
|
||||
}
|
||||
// pIndex is definitely not NULL, otherwise it is a bug
|
||||
CHECK_ALLOC(pIndex, DEAL_RES_ERROR);
|
||||
if (NULL == pIndex) {
|
||||
return DEAL_RES_ERROR;
|
||||
}
|
||||
((SColumnNode*)pNode)->dataBlockId = pIndex->dataBlockId;
|
||||
((SColumnNode*)pNode)->slotId = pIndex->slotId;
|
||||
CHECK_ALLOC(pNode, DEAL_RES_ERROR);
|
||||
((SColumnNode*)pNode)->slotId = ((SSlotIdInfo*)taosArrayGet(pIndex->pSlotIdsInfo, 0))->slotId;
|
||||
return DEAL_RES_IGNORE_CHILD;
|
||||
}
|
||||
return DEAL_RES_CONTINUE;
|
||||
|
@ -144,7 +273,7 @@ static int32_t setNodeSlotId(SPhysiPlanContext* pCxt, int16_t leftDataBlockId, i
|
|||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
static int32_t setListSlotId(SPhysiPlanContext* pCxt, int16_t leftDataBlockId, int16_t rightDataBlockId, SNodeList* pList, SNodeList** pOutput) {
|
||||
static int32_t setListSlotId(SPhysiPlanContext* pCxt, int16_t leftDataBlockId, int16_t rightDataBlockId, const SNodeList* pList, SNodeList** pOutput) {
|
||||
SNodeList* pRes = nodesCloneList(pList);
|
||||
if (NULL == pRes) {
|
||||
return TSDB_CODE_OUT_OF_MEMORY;
|
||||
|
@ -164,18 +293,17 @@ static int32_t setListSlotId(SPhysiPlanContext* pCxt, int16_t leftDataBlockId, i
|
|||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
static SPhysiNode* makePhysiNode(SPhysiPlanContext* pCxt, ENodeType type) {
|
||||
static SPhysiNode* makePhysiNode(SPhysiPlanContext* pCxt, SLogicNode* pLogicNode, ENodeType type) {
|
||||
SPhysiNode* pPhysiNode = (SPhysiNode*)nodesMakeNode(type);
|
||||
if (NULL == pPhysiNode) {
|
||||
return NULL;
|
||||
}
|
||||
pPhysiNode->pOutputDataBlockDesc = nodesMakeNode(QUERY_NODE_DATABLOCK_DESC);
|
||||
if (NULL == pPhysiNode->pOutputDataBlockDesc) {
|
||||
|
||||
int32_t code = createDataBlockDesc(pCxt, pLogicNode->pTargets, &pPhysiNode->pOutputDataBlockDesc);
|
||||
if (TSDB_CODE_SUCCESS != code) {
|
||||
nodesDestroyNode(pPhysiNode);
|
||||
return NULL;
|
||||
}
|
||||
pPhysiNode->pOutputDataBlockDesc->dataBlockId = pCxt->nextDataBlockId++;
|
||||
pPhysiNode->pOutputDataBlockDesc->type = QUERY_NODE_DATABLOCK_DESC;
|
||||
return pPhysiNode;
|
||||
}
|
||||
|
||||
|
@ -186,24 +314,11 @@ static int32_t setConditionsSlotId(SPhysiPlanContext* pCxt, const SLogicNode* pL
|
|||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
static int32_t setSlotOutput(SPhysiPlanContext* pCxt, SNodeList* pTargets, SDataBlockDescNode* pDataBlockDesc) {
|
||||
SHashObj* pHash = taosArrayGetP(pCxt->pLocationHelper, pDataBlockDesc->dataBlockId);
|
||||
char name[TSDB_TABLE_NAME_LEN + TSDB_COL_NAME_LEN];
|
||||
SNode* pNode;
|
||||
FOREACH(pNode, pTargets) {
|
||||
int32_t len = getSlotKey(pNode, name);
|
||||
SSlotIndex* pIndex = taosHashGet(pHash, name, len);
|
||||
// pIndex is definitely not NULL, otherwise it is a bug
|
||||
CHECK_ALLOC(pIndex, TSDB_CODE_FAILED);
|
||||
((SSlotDescNode*)nodesListGetNode(pDataBlockDesc->pSlots, pIndex->slotId))->output = true;
|
||||
}
|
||||
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
static SNodeptr createPrimaryKeyCol(SPhysiPlanContext* pCxt, uint64_t tableId) {
|
||||
SColumnNode* pCol = nodesMakeNode(QUERY_NODE_COLUMN);
|
||||
CHECK_ALLOC(pCol, NULL);
|
||||
if (NULL == pCol) {
|
||||
return NULL;
|
||||
}
|
||||
pCol->node.resType.type = TSDB_DATA_TYPE_TIMESTAMP;
|
||||
pCol->node.resType.bytes = tDataTypes[TSDB_DATA_TYPE_TIMESTAMP].bytes;
|
||||
pCol->tableId = tableId;
|
||||
|
@ -244,8 +359,12 @@ static int32_t createScanCols(SPhysiPlanContext* pCxt, SScanPhysiNode* pScanPhys
|
|||
if (QUERY_NODE_PHYSICAL_PLAN_TABLE_SCAN == nodeType(pScanPhysiNode)
|
||||
|| QUERY_NODE_PHYSICAL_PLAN_TABLE_SEQ_SCAN == nodeType(pScanPhysiNode)) {
|
||||
pScanPhysiNode->pScanCols = nodesMakeList();
|
||||
CHECK_ALLOC(pScanPhysiNode->pScanCols, TSDB_CODE_OUT_OF_MEMORY);
|
||||
CHECK_CODE_EXT(nodesListStrictAppend(pScanPhysiNode->pScanCols, createPrimaryKeyCol(pCxt, pScanPhysiNode->uid)));
|
||||
if (NULL == pScanPhysiNode->pScanCols) {
|
||||
return TSDB_CODE_OUT_OF_MEMORY;
|
||||
}
|
||||
if (TSDB_CODE_SUCCESS != nodesListStrictAppend(pScanPhysiNode->pScanCols, createPrimaryKeyCol(pCxt, pScanPhysiNode->uid))) {
|
||||
return TSDB_CODE_OUT_OF_MEMORY;
|
||||
}
|
||||
|
||||
SNode* pNode;
|
||||
FOREACH(pNode, pScanCols) {
|
||||
|
@ -255,29 +374,29 @@ static int32_t createScanCols(SPhysiPlanContext* pCxt, SScanPhysiNode* pScanPhys
|
|||
strcpy(pCol->colName, ((SColumnNode*)pNode)->colName);
|
||||
continue;
|
||||
}
|
||||
CHECK_CODE_EXT(nodesListStrictAppend(pScanPhysiNode->pScanCols, nodesCloneNode(pNode)));
|
||||
if (TSDB_CODE_SUCCESS != nodesListStrictAppend(pScanPhysiNode->pScanCols, nodesCloneNode(pNode))) {
|
||||
return TSDB_CODE_OUT_OF_MEMORY;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
pScanPhysiNode->pScanCols = nodesCloneList(pScanCols);
|
||||
CHECK_ALLOC(pScanPhysiNode->pScanCols, TSDB_CODE_OUT_OF_MEMORY);
|
||||
if (NULL == pScanPhysiNode->pScanCols) {
|
||||
return TSDB_CODE_OUT_OF_MEMORY;
|
||||
}
|
||||
}
|
||||
|
||||
// return sortScanCols(pScanPhysiNode->pScanCols);
|
||||
return TSDB_CODE_SUCCESS;
|
||||
return sortScanCols(pScanPhysiNode->pScanCols);
|
||||
}
|
||||
|
||||
static int32_t createScanPhysiNodeFinalize(SPhysiPlanContext* pCxt, SScanLogicNode* pScanLogicNode, SScanPhysiNode* pScanPhysiNode, SPhysiNode** pPhyNode) {
|
||||
int32_t code = createScanCols(pCxt, pScanPhysiNode, pScanLogicNode->pScanCols);
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
// Data block describe also needs to be set without scanning column, such as SELECT COUNT(*) FROM t
|
||||
code = addDataBlockDesc(pCxt, pScanPhysiNode->pScanCols, pScanPhysiNode->node.pOutputDataBlockDesc);
|
||||
code = addDataBlockSlots(pCxt, pScanPhysiNode->pScanCols, pScanPhysiNode->node.pOutputDataBlockDesc);
|
||||
}
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
code = setConditionsSlotId(pCxt, (const SLogicNode*)pScanLogicNode, (SPhysiNode*)pScanPhysiNode);
|
||||
}
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
code = setSlotOutput(pCxt, pScanLogicNode->node.pTargets, pScanPhysiNode->node.pOutputDataBlockDesc);
|
||||
}
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
pScanPhysiNode->uid = pScanLogicNode->pMeta->uid;
|
||||
pScanPhysiNode->tableType = pScanLogicNode->pMeta->tableType;
|
||||
|
@ -302,7 +421,7 @@ static void vgroupInfoToNodeAddr(const SVgroupInfo* vg, SQueryNodeAddr* pNodeAdd
|
|||
}
|
||||
|
||||
static int32_t createTagScanPhysiNode(SPhysiPlanContext* pCxt, SScanLogicNode* pScanLogicNode, SPhysiNode** pPhyNode) {
|
||||
STagScanPhysiNode* pTagScan = (STagScanPhysiNode*)makePhysiNode(pCxt, QUERY_NODE_PHYSICAL_PLAN_TAG_SCAN);
|
||||
STagScanPhysiNode* pTagScan = (STagScanPhysiNode*)makePhysiNode(pCxt, (SLogicNode*)pScanLogicNode, QUERY_NODE_PHYSICAL_PLAN_TAG_SCAN);
|
||||
if (NULL == pTagScan) {
|
||||
return TSDB_CODE_OUT_OF_MEMORY;
|
||||
}
|
||||
|
@ -310,7 +429,7 @@ static int32_t createTagScanPhysiNode(SPhysiPlanContext* pCxt, SScanLogicNode* p
|
|||
}
|
||||
|
||||
static int32_t createTableScanPhysiNode(SPhysiPlanContext* pCxt, SSubplan* pSubplan, SScanLogicNode* pScanLogicNode, SPhysiNode** pPhyNode) {
|
||||
STableScanPhysiNode* pTableScan = (STableScanPhysiNode*)makePhysiNode(pCxt, QUERY_NODE_PHYSICAL_PLAN_TABLE_SCAN);
|
||||
STableScanPhysiNode* pTableScan = (STableScanPhysiNode*)makePhysiNode(pCxt, (SLogicNode*)pScanLogicNode, QUERY_NODE_PHYSICAL_PLAN_TABLE_SCAN);
|
||||
if (NULL == pTableScan) {
|
||||
return TSDB_CODE_OUT_OF_MEMORY;
|
||||
}
|
||||
|
@ -326,7 +445,7 @@ static int32_t createTableScanPhysiNode(SPhysiPlanContext* pCxt, SSubplan* pSubp
|
|||
}
|
||||
|
||||
static int32_t createSystemTableScanPhysiNode(SPhysiPlanContext* pCxt, SSubplan* pSubplan, SScanLogicNode* pScanLogicNode, SPhysiNode** pPhyNode) {
|
||||
SSystemTableScanPhysiNode* pScan = (SSystemTableScanPhysiNode*)makePhysiNode(pCxt, QUERY_NODE_PHYSICAL_PLAN_SYSTABLE_SCAN);
|
||||
SSystemTableScanPhysiNode* pScan = (SSystemTableScanPhysiNode*)makePhysiNode(pCxt, (SLogicNode*)pScanLogicNode, QUERY_NODE_PHYSICAL_PLAN_SYSTABLE_SCAN);
|
||||
if (NULL == pScan) {
|
||||
return TSDB_CODE_OUT_OF_MEMORY;
|
||||
}
|
||||
|
@ -347,7 +466,7 @@ static int32_t createSystemTableScanPhysiNode(SPhysiPlanContext* pCxt, SSubplan*
|
|||
}
|
||||
|
||||
static int32_t createStreamScanPhysiNode(SPhysiPlanContext* pCxt, SSubplan* pSubplan, SScanLogicNode* pScanLogicNode, SPhysiNode** pPhyNode) {
|
||||
SStreamScanPhysiNode* pScan = (SStreamScanPhysiNode*)makePhysiNode(pCxt, QUERY_NODE_PHYSICAL_PLAN_STREAM_SCAN);
|
||||
SStreamScanPhysiNode* pScan = (SStreamScanPhysiNode*)makePhysiNode(pCxt, (SLogicNode*)pScanLogicNode, QUERY_NODE_PHYSICAL_PLAN_STREAM_SCAN);
|
||||
if (NULL == pScan) {
|
||||
return TSDB_CODE_OUT_OF_MEMORY;
|
||||
}
|
||||
|
@ -411,7 +530,7 @@ static int32_t createJoinOutputCols(SPhysiPlanContext* pCxt, SDataBlockDescNode*
|
|||
}
|
||||
|
||||
static int32_t createJoinPhysiNode(SPhysiPlanContext* pCxt, SNodeList* pChildren, SJoinLogicNode* pJoinLogicNode, SPhysiNode** pPhyNode) {
|
||||
SJoinPhysiNode* pJoin = (SJoinPhysiNode*)makePhysiNode(pCxt, QUERY_NODE_PHYSICAL_PLAN_JOIN);
|
||||
SJoinPhysiNode* pJoin = (SJoinPhysiNode*)makePhysiNode(pCxt, (SLogicNode*)pJoinLogicNode, QUERY_NODE_PHYSICAL_PLAN_JOIN);
|
||||
if (NULL == pJoin) {
|
||||
return TSDB_CODE_OUT_OF_MEMORY;
|
||||
}
|
||||
|
@ -424,14 +543,11 @@ static int32_t createJoinPhysiNode(SPhysiPlanContext* pCxt, SNodeList* pChildren
|
|||
code = createJoinOutputCols(pCxt, pLeftDesc, pRightDesc, &pJoin->pTargets);
|
||||
}
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
code = addDataBlockDesc(pCxt, pJoin->pTargets, pJoin->node.pOutputDataBlockDesc);
|
||||
code = addDataBlockSlots(pCxt, pJoin->pTargets, pJoin->node.pOutputDataBlockDesc);
|
||||
}
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
code = setConditionsSlotId(pCxt, (const SLogicNode*)pJoinLogicNode, (SPhysiNode*)pJoin);
|
||||
}
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
code = setSlotOutput(pCxt, pJoinLogicNode->node.pTargets, pJoin->node.pOutputDataBlockDesc);
|
||||
}
|
||||
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
*pPhyNode = (SPhysiNode*)pJoin;
|
||||
|
@ -451,7 +567,9 @@ typedef struct SRewritePrecalcExprsCxt {
|
|||
|
||||
static EDealRes collectAndRewrite(SRewritePrecalcExprsCxt* pCxt, SNode** pNode) {
|
||||
SNode* pExpr = nodesCloneNode(*pNode);
|
||||
CHECK_ALLOC(pExpr, DEAL_RES_ERROR);
|
||||
if (NULL == pExpr) {
|
||||
return DEAL_RES_ERROR;
|
||||
}
|
||||
if (nodesListAppend(pCxt->pPrecalcExprs, pExpr)) {
|
||||
nodesDestroyNode(pExpr);
|
||||
return DEAL_RES_ERROR;
|
||||
|
@ -499,11 +617,15 @@ static int32_t rewritePrecalcExprs(SPhysiPlanContext* pCxt, SNodeList* pList, SN
|
|||
|
||||
if (NULL == *pPrecalcExprs) {
|
||||
*pPrecalcExprs = nodesMakeList();
|
||||
CHECK_ALLOC(*pPrecalcExprs, TSDB_CODE_OUT_OF_MEMORY);
|
||||
if (NULL == *pPrecalcExprs) {
|
||||
return TSDB_CODE_OUT_OF_MEMORY;
|
||||
}
|
||||
}
|
||||
if (NULL == *pRewrittenList) {
|
||||
*pRewrittenList = nodesMakeList();
|
||||
CHECK_ALLOC(*pRewrittenList, TSDB_CODE_OUT_OF_MEMORY);
|
||||
if (NULL == *pRewrittenList) {
|
||||
return TSDB_CODE_OUT_OF_MEMORY;
|
||||
}
|
||||
}
|
||||
SNode* pNode = NULL;
|
||||
FOREACH(pNode, pList) {
|
||||
|
@ -513,8 +635,12 @@ static int32_t rewritePrecalcExprs(SPhysiPlanContext* pCxt, SNodeList* pList, SN
|
|||
} else {
|
||||
pNew = nodesCloneNode(pNode);
|
||||
}
|
||||
CHECK_ALLOC(pNew, TSDB_CODE_OUT_OF_MEMORY);
|
||||
CHECK_CODE(nodesListAppend(*pRewrittenList, pNew), TSDB_CODE_OUT_OF_MEMORY);
|
||||
if (NULL == pNew) {
|
||||
return TSDB_CODE_OUT_OF_MEMORY;
|
||||
}
|
||||
if (TSDB_CODE_SUCCESS != nodesListAppend(*pRewrittenList, pNew)) {
|
||||
return TSDB_CODE_OUT_OF_MEMORY;
|
||||
}
|
||||
}
|
||||
SRewritePrecalcExprsCxt cxt = { .errCode = TSDB_CODE_SUCCESS, .pPrecalcExprs = *pPrecalcExprs };
|
||||
nodesRewriteList(*pRewrittenList, doRewritePrecalcExprs, &cxt);
|
||||
|
@ -526,7 +652,7 @@ static int32_t rewritePrecalcExprs(SPhysiPlanContext* pCxt, SNodeList* pList, SN
|
|||
}
|
||||
|
||||
static int32_t createAggPhysiNode(SPhysiPlanContext* pCxt, SNodeList* pChildren, SAggLogicNode* pAggLogicNode, SPhysiNode** pPhyNode) {
|
||||
SAggPhysiNode* pAgg = (SAggPhysiNode*)makePhysiNode(pCxt, QUERY_NODE_PHYSICAL_PLAN_AGG);
|
||||
SAggPhysiNode* pAgg = (SAggPhysiNode*)makePhysiNode(pCxt, (SLogicNode*)pAggLogicNode, QUERY_NODE_PHYSICAL_PLAN_AGG);
|
||||
if (NULL == pAgg) {
|
||||
return TSDB_CODE_OUT_OF_MEMORY;
|
||||
}
|
||||
|
@ -544,30 +670,27 @@ static int32_t createAggPhysiNode(SPhysiPlanContext* pCxt, SNodeList* pChildren,
|
|||
if (TSDB_CODE_SUCCESS == code && NULL != pPrecalcExprs) {
|
||||
code = setListSlotId(pCxt, pChildTupe->dataBlockId, -1, pPrecalcExprs, &pAgg->pExprs);
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
code = addDataBlockDesc(pCxt, pAgg->pExprs, pChildTupe);
|
||||
code = pushdownDataBlockSlots(pCxt, pAgg->pExprs, pChildTupe);
|
||||
}
|
||||
}
|
||||
|
||||
if (TSDB_CODE_SUCCESS == code && NULL != pGroupKeys) {
|
||||
code = setListSlotId(pCxt, pChildTupe->dataBlockId, -1, pGroupKeys, &pAgg->pGroupKeys);
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
code = addDataBlockDesc(pCxt, pAgg->pGroupKeys, pAgg->node.pOutputDataBlockDesc);
|
||||
code = addDataBlockSlots(pCxt, pAgg->pGroupKeys, pAgg->node.pOutputDataBlockDesc);
|
||||
}
|
||||
}
|
||||
|
||||
if (TSDB_CODE_SUCCESS == code && NULL != pAggFuncs) {
|
||||
code = setListSlotId(pCxt, pChildTupe->dataBlockId, -1, pAggFuncs, &pAgg->pAggFuncs);
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
code = addDataBlockDesc(pCxt, pAgg->pAggFuncs, pAgg->node.pOutputDataBlockDesc);
|
||||
code = addDataBlockSlots(pCxt, pAgg->pAggFuncs, pAgg->node.pOutputDataBlockDesc);
|
||||
}
|
||||
}
|
||||
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
code = setConditionsSlotId(pCxt, (const SLogicNode*)pAggLogicNode, (SPhysiNode*)pAgg);
|
||||
}
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
code = setSlotOutput(pCxt, pAggLogicNode->node.pTargets, pAgg->node.pOutputDataBlockDesc);
|
||||
}
|
||||
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
*pPhyNode = (SPhysiNode*)pAgg;
|
||||
|
@ -575,18 +698,22 @@ static int32_t createAggPhysiNode(SPhysiPlanContext* pCxt, SNodeList* pChildren,
|
|||
nodesDestroyNode(pAgg);
|
||||
}
|
||||
|
||||
nodesDestroyList(pPrecalcExprs);
|
||||
nodesDestroyList(pGroupKeys);
|
||||
nodesDestroyList(pAggFuncs);
|
||||
|
||||
return code;
|
||||
}
|
||||
|
||||
static int32_t createProjectPhysiNode(SPhysiPlanContext* pCxt, SNodeList* pChildren, SProjectLogicNode* pProjectLogicNode, SPhysiNode** pPhyNode) {
|
||||
SProjectPhysiNode* pProject = (SProjectPhysiNode*)makePhysiNode(pCxt, QUERY_NODE_PHYSICAL_PLAN_PROJECT);
|
||||
SProjectPhysiNode* pProject = (SProjectPhysiNode*)makePhysiNode(pCxt, (SLogicNode*)pProjectLogicNode, QUERY_NODE_PHYSICAL_PLAN_PROJECT);
|
||||
if (NULL == pProject) {
|
||||
return TSDB_CODE_OUT_OF_MEMORY;
|
||||
}
|
||||
|
||||
int32_t code = setListSlotId(pCxt, ((SPhysiNode*)nodesListGetNode(pChildren, 0))->pOutputDataBlockDesc->dataBlockId, -1, pProjectLogicNode->pProjections, &pProject->pProjections);
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
code = addDataBlockDesc(pCxt, pProject->pProjections, pProject->node.pOutputDataBlockDesc);
|
||||
code = addDataBlockSlotsForProject(pCxt, pProjectLogicNode->stmtName, pProject->pProjections, pProject->node.pOutputDataBlockDesc);
|
||||
}
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
code = setConditionsSlotId(pCxt, (const SLogicNode*)pProjectLogicNode, (SPhysiNode*)pProject);
|
||||
|
@ -602,34 +729,30 @@ static int32_t createProjectPhysiNode(SPhysiPlanContext* pCxt, SNodeList* pChild
|
|||
}
|
||||
|
||||
static int32_t doCreateExchangePhysiNode(SPhysiPlanContext* pCxt, SExchangeLogicNode* pExchangeLogicNode, SPhysiNode** pPhyNode) {
|
||||
SExchangePhysiNode* pExchange = (SExchangePhysiNode*)makePhysiNode(pCxt, QUERY_NODE_PHYSICAL_PLAN_EXCHANGE);
|
||||
SExchangePhysiNode* pExchange = (SExchangePhysiNode*)makePhysiNode(pCxt, (SLogicNode*)pExchangeLogicNode, QUERY_NODE_PHYSICAL_PLAN_EXCHANGE);
|
||||
if (NULL == pExchange) {
|
||||
return TSDB_CODE_OUT_OF_MEMORY;
|
||||
}
|
||||
|
||||
pExchange->srcGroupId = pExchangeLogicNode->srcGroupId;
|
||||
int32_t code = addDataBlockDesc(pCxt, pExchangeLogicNode->node.pTargets, pExchange->node.pOutputDataBlockDesc);
|
||||
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
*pPhyNode = (SPhysiNode*)pExchange;
|
||||
} else {
|
||||
nodesDestroyNode(pExchange);
|
||||
}
|
||||
|
||||
return code;
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
static int32_t createStreamScanPhysiNodeByExchange(SPhysiPlanContext* pCxt, SExchangeLogicNode* pExchangeLogicNode, SPhysiNode** pPhyNode) {
|
||||
SStreamScanPhysiNode* pScan = (SStreamScanPhysiNode*)makePhysiNode(pCxt, QUERY_NODE_PHYSICAL_PLAN_STREAM_SCAN);
|
||||
SStreamScanPhysiNode* pScan = (SStreamScanPhysiNode*)makePhysiNode(pCxt, (SLogicNode*)pExchangeLogicNode, QUERY_NODE_PHYSICAL_PLAN_STREAM_SCAN);
|
||||
if (NULL == pScan) {
|
||||
return TSDB_CODE_OUT_OF_MEMORY;
|
||||
}
|
||||
|
||||
int32_t code = addDataBlockDesc(pCxt, pExchangeLogicNode->node.pTargets, pScan->node.pOutputDataBlockDesc);
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
int32_t code = TSDB_CODE_SUCCESS;
|
||||
|
||||
pScan->pScanCols = nodesCloneList(pExchangeLogicNode->node.pTargets);
|
||||
if (NULL == pScan->pScanCols) {
|
||||
code = TSDB_CODE_OUT_OF_MEMORY;
|
||||
}
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
code = addDataBlockSlots(pCxt, pScan->pScanCols, pScan->node.pOutputDataBlockDesc);
|
||||
}
|
||||
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
|
@ -659,21 +782,17 @@ static int32_t createWindowPhysiNodeFinalize(SPhysiPlanContext* pCxt, SNodeList*
|
|||
if (TSDB_CODE_SUCCESS == code && NULL != pPrecalcExprs) {
|
||||
code = setListSlotId(pCxt, pChildTupe->dataBlockId, -1, pPrecalcExprs, &pWindow->pExprs);
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
code = addDataBlockDesc(pCxt, pWindow->pExprs, pChildTupe);
|
||||
code = addDataBlockSlots(pCxt, pWindow->pExprs, pChildTupe);
|
||||
}
|
||||
}
|
||||
|
||||
if (TSDB_CODE_SUCCESS == code && NULL != pFuncs) {
|
||||
code = setListSlotId(pCxt, pChildTupe->dataBlockId, -1, pFuncs, &pWindow->pFuncs);
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
code = addDataBlockDesc(pCxt, pWindow->pFuncs, pWindow->node.pOutputDataBlockDesc);
|
||||
code = addDataBlockSlots(pCxt, pWindow->pFuncs, pWindow->node.pOutputDataBlockDesc);
|
||||
}
|
||||
}
|
||||
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
code = setSlotOutput(pCxt, pWindowLogicNode->node.pTargets, pWindow->node.pOutputDataBlockDesc);
|
||||
}
|
||||
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
*pPhyNode = (SPhysiNode*)pWindow;
|
||||
} else {
|
||||
|
@ -684,7 +803,7 @@ static int32_t createWindowPhysiNodeFinalize(SPhysiPlanContext* pCxt, SNodeList*
|
|||
}
|
||||
|
||||
static int32_t createIntervalPhysiNode(SPhysiPlanContext* pCxt, SNodeList* pChildren, SWindowLogicNode* pWindowLogicNode, SPhysiNode** pPhyNode) {
|
||||
SIntervalPhysiNode* pInterval = (SIntervalPhysiNode*)makePhysiNode(pCxt, QUERY_NODE_PHYSICAL_PLAN_INTERVAL);
|
||||
SIntervalPhysiNode* pInterval = (SIntervalPhysiNode*)makePhysiNode(pCxt, (SLogicNode*)pWindowLogicNode, QUERY_NODE_PHYSICAL_PLAN_INTERVAL);
|
||||
if (NULL == pInterval) {
|
||||
return TSDB_CODE_OUT_OF_MEMORY;
|
||||
}
|
||||
|
@ -701,11 +820,18 @@ static int32_t createIntervalPhysiNode(SPhysiPlanContext* pCxt, SNodeList* pChil
|
|||
return TSDB_CODE_OUT_OF_MEMORY;
|
||||
}
|
||||
|
||||
SDataBlockDescNode* pChildTupe = (((SPhysiNode*)nodesListGetNode(pChildren, 0))->pOutputDataBlockDesc);
|
||||
int32_t code = setNodeSlotId(pCxt, pChildTupe->dataBlockId, -1, pWindowLogicNode->pTspk, &pInterval->pTspk);
|
||||
if (TSDB_CODE_SUCCESS != code) {
|
||||
nodesDestroyNode(pInterval);
|
||||
return code;
|
||||
}
|
||||
|
||||
return createWindowPhysiNodeFinalize(pCxt, pChildren, &pInterval->window, pWindowLogicNode, pPhyNode);
|
||||
}
|
||||
|
||||
static int32_t createSessionWindowPhysiNode(SPhysiPlanContext* pCxt, SNodeList* pChildren, SWindowLogicNode* pWindowLogicNode, SPhysiNode** pPhyNode) {
|
||||
SSessionWinodwPhysiNode* pSession = (SSessionWinodwPhysiNode*)makePhysiNode(pCxt, QUERY_NODE_PHYSICAL_PLAN_SESSION_WINDOW);
|
||||
SSessionWinodwPhysiNode* pSession = (SSessionWinodwPhysiNode*)makePhysiNode(pCxt, (SLogicNode*)pWindowLogicNode, QUERY_NODE_PHYSICAL_PLAN_SESSION_WINDOW);
|
||||
if (NULL == pSession) {
|
||||
return TSDB_CODE_OUT_OF_MEMORY;
|
||||
}
|
||||
|
@ -729,6 +855,41 @@ static int32_t createWindowPhysiNode(SPhysiPlanContext* pCxt, SNodeList* pChildr
|
|||
return TSDB_CODE_FAILED;
|
||||
}
|
||||
|
||||
static int32_t createSortPhysiNode(SPhysiPlanContext* pCxt, SNodeList* pChildren, SSortLogicNode* pSortLogicNode, SPhysiNode** pPhyNode) {
|
||||
SSortPhysiNode* pSort = (SSortPhysiNode*)makePhysiNode(pCxt, (SLogicNode*)pSortLogicNode, QUERY_NODE_PHYSICAL_PLAN_SORT);
|
||||
if (NULL == pSort) {
|
||||
return TSDB_CODE_OUT_OF_MEMORY;
|
||||
}
|
||||
|
||||
SNodeList* pPrecalcExprs = NULL;
|
||||
SNodeList* pSortKeys = NULL;
|
||||
int32_t code = rewritePrecalcExprs(pCxt, pSortLogicNode->pSortKeys, &pPrecalcExprs, &pSortKeys);
|
||||
|
||||
SDataBlockDescNode* pChildTupe = (((SPhysiNode*)nodesListGetNode(pChildren, 0))->pOutputDataBlockDesc);
|
||||
// push down expression to pOutputDataBlockDesc of child node
|
||||
if (TSDB_CODE_SUCCESS == code && NULL != pPrecalcExprs) {
|
||||
code = setListSlotId(pCxt, pChildTupe->dataBlockId, -1, pPrecalcExprs, &pSort->pExprs);
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
code = addDataBlockSlots(pCxt, pSort->pExprs, pChildTupe);
|
||||
}
|
||||
}
|
||||
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
code = setListSlotId(pCxt, pChildTupe->dataBlockId, -1, pSortKeys, &pSort->pSortKeys);
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
code = addDataBlockSlots(pCxt, pSort->pSortKeys, pSort->node.pOutputDataBlockDesc);
|
||||
}
|
||||
}
|
||||
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
*pPhyNode = (SPhysiNode*)pSort;
|
||||
} else {
|
||||
nodesDestroyNode(pSort);
|
||||
}
|
||||
|
||||
return code;
|
||||
}
|
||||
|
||||
static int32_t doCreatePhysiNode(SPhysiPlanContext* pCxt, SLogicNode* pLogicNode, SSubplan* pSubplan, SNodeList* pChildren, SPhysiNode** pPhyNode) {
|
||||
switch (nodeType(pLogicNode)) {
|
||||
case QUERY_NODE_LOGIC_PLAN_SCAN:
|
||||
|
@ -743,6 +904,8 @@ static int32_t doCreatePhysiNode(SPhysiPlanContext* pCxt, SLogicNode* pLogicNode
|
|||
return createExchangePhysiNode(pCxt, (SExchangeLogicNode*)pLogicNode, pPhyNode);
|
||||
case QUERY_NODE_LOGIC_PLAN_WINDOW:
|
||||
return createWindowPhysiNode(pCxt, pChildren, (SWindowLogicNode*)pLogicNode, pPhyNode);
|
||||
case QUERY_NODE_LOGIC_PLAN_SORT:
|
||||
return createSortPhysiNode(pCxt, pChildren, (SSortLogicNode*)pLogicNode, pPhyNode);
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
@ -874,17 +1037,22 @@ static int32_t pushSubplan(SPhysiPlanContext* pCxt, SNodeptr pSubplan, int32_t l
|
|||
SNodeListNode* pGroup;
|
||||
if (level >= LIST_LENGTH(pSubplans)) {
|
||||
pGroup = nodesMakeNode(QUERY_NODE_NODE_LIST);
|
||||
CHECK_ALLOC(pGroup, TSDB_CODE_OUT_OF_MEMORY);
|
||||
CHECK_CODE(nodesListStrictAppend(pSubplans, pGroup), TSDB_CODE_OUT_OF_MEMORY);
|
||||
if (NULL == pGroup) {
|
||||
return TSDB_CODE_OUT_OF_MEMORY;
|
||||
}
|
||||
if (TSDB_CODE_SUCCESS != nodesListStrictAppend(pSubplans, pGroup)) {
|
||||
return TSDB_CODE_OUT_OF_MEMORY;
|
||||
}
|
||||
} else {
|
||||
pGroup = nodesListGetNode(pSubplans, level);
|
||||
}
|
||||
if (NULL == pGroup->pNodeList) {
|
||||
pGroup->pNodeList = nodesMakeList();
|
||||
CHECK_ALLOC(pGroup->pNodeList, TSDB_CODE_OUT_OF_MEMORY);
|
||||
if (NULL == pGroup->pNodeList) {
|
||||
return TSDB_CODE_OUT_OF_MEMORY;
|
||||
}
|
||||
CHECK_CODE(nodesListStrictAppend(pGroup->pNodeList, pSubplan), TSDB_CODE_OUT_OF_MEMORY);
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
return nodesListStrictAppend(pGroup->pNodeList, pSubplan);
|
||||
}
|
||||
|
||||
static int32_t buildPhysiPlan(SPhysiPlanContext* pCxt, SLogicSubplan* pLogicSubplan, SSubplan* pParent, SQueryPlan* pQueryPlan) {
|
||||
|
|
|
@ -65,7 +65,9 @@ static int32_t stsMatch(SSplitContext* pCxt, SLogicSubplan* pSubplan) {
|
|||
SLogicNode* pSplitNode = stsMatchByNode(pSubplan->pNode);
|
||||
if (NULL != pSplitNode) {
|
||||
SStsInfo* pInfo = taosMemoryCalloc(1, sizeof(SStsInfo));
|
||||
CHECK_ALLOC(pInfo, TSDB_CODE_OUT_OF_MEMORY);
|
||||
if (NULL == pInfo) {
|
||||
return TSDB_CODE_OUT_OF_MEMORY;
|
||||
}
|
||||
pInfo->pScan = (SScanLogicNode*)pSplitNode;
|
||||
pInfo->pSubplan = pSubplan;
|
||||
pCxt->pInfo = pInfo;
|
||||
|
|
|
@ -170,7 +170,7 @@ TEST_F(PlannerTest, groupBy) {
|
|||
bind("SELECT count(*) FROM t1");
|
||||
ASSERT_TRUE(run());
|
||||
|
||||
bind("SELECT c1, count(*) FROM t1 GROUP BY c1");
|
||||
bind("SELECT c1, max(c3), min(c2), count(*) FROM t1 GROUP BY c1");
|
||||
ASSERT_TRUE(run());
|
||||
|
||||
bind("SELECT c1 + c3, c1 + count(*) FROM t1 where c2 = 'abc' GROUP BY c1, c3");
|
||||
|
@ -201,10 +201,31 @@ TEST_F(PlannerTest, sessionWindow) {
|
|||
ASSERT_TRUE(run());
|
||||
}
|
||||
|
||||
TEST_F(PlannerTest, orderBy) {
|
||||
setDatabase("root", "test");
|
||||
|
||||
bind("SELECT * FROM t1 order by c1");
|
||||
ASSERT_TRUE(run());
|
||||
|
||||
bind("SELECT c1 FROM t1 order by c2");
|
||||
ASSERT_TRUE(run());
|
||||
|
||||
bind("SELECT * FROM t1 order by c1 + 10, c2");
|
||||
ASSERT_TRUE(run());
|
||||
}
|
||||
|
||||
TEST_F(PlannerTest, showTables) {
|
||||
setDatabase("root", "test");
|
||||
|
||||
bind("show tables");
|
||||
ASSERT_TRUE(run());
|
||||
}
|
||||
|
||||
TEST_F(PlannerTest, showStables) {
|
||||
setDatabase("root", "test");
|
||||
|
||||
bind("show stables");
|
||||
ASSERT_TRUE(run());
|
||||
}
|
||||
|
||||
TEST_F(PlannerTest, createTopic) {
|
||||
|
|
|
@ -198,7 +198,7 @@ char *jobTaskStatusStr(int32_t status) {
|
|||
return "UNKNOWN";
|
||||
}
|
||||
|
||||
SSchema createSchema(uint8_t type, int32_t bytes, int32_t colId, const char* name) {
|
||||
SSchema createSchema(int8_t type, int32_t bytes, col_id_t colId, const char* name) {
|
||||
SSchema s = {0};
|
||||
s.type = type;
|
||||
s.bytes = bytes;
|
||||
|
|
|
@ -188,7 +188,7 @@ static int32_t queryConvertTableMetaMsg(STableMetaRsp *pMetaMsg) {
|
|||
}
|
||||
|
||||
if (pMetaMsg->pSchemas[0].colId != PRIMARYKEY_TIMESTAMP_COL_ID) {
|
||||
qError("invalid colId[%d] for the first column in table meta rsp msg", pMetaMsg->pSchemas[0].colId);
|
||||
qError("invalid colId[%" PRIi16 "] for the first column in table meta rsp msg", pMetaMsg->pSchemas[0].colId);
|
||||
return TSDB_CODE_TSC_INVALID_VALUE;
|
||||
}
|
||||
|
||||
|
|
|
@ -947,10 +947,12 @@ int32_t qwProcessQuery(QW_FPARAMS_DEF, SQWMsg *qwMsg, int8_t taskType) {
|
|||
QW_ERR_JRET(qwGetTaskCtx(QW_FPARAMS(), &ctx));
|
||||
|
||||
atomic_store_8(&ctx->taskType, taskType);
|
||||
|
||||
atomic_store_ptr(&ctx->connInfo.handle, qwMsg->connInfo.handle);
|
||||
atomic_store_ptr(&ctx->connInfo.ahandle, qwMsg->connInfo.ahandle);
|
||||
|
||||
QW_TASK_DLOGL("subplan json string, len:%d, %s", qwMsg->msgLen, qwMsg->msg);
|
||||
|
||||
code = qStringToSubplan(qwMsg->msg, &plan);
|
||||
if (TSDB_CODE_SUCCESS != code) {
|
||||
QW_TASK_ELOG("task string to subplan failed, code:%x - %s", code, tstrerror(code));
|
||||
|
|
|
@ -170,7 +170,7 @@ int32_t qwBuildAndSendShowRsp(SRpcMsg *pMsg, int32_t code) {
|
|||
return -1;
|
||||
}
|
||||
|
||||
int32_t cols = 0;
|
||||
col_id_t cols = 0;
|
||||
SSchema *pSchema = showRsp.tableMeta.pSchemas;
|
||||
|
||||
const SSchema *s = tGetTbnameColumnSchema();
|
||||
|
|
|
@ -121,7 +121,7 @@ int32_t streamExecTask(SStreamTask* pTask, SMsgCb* pMsgCb, const void* input, in
|
|||
} else if (pTask->dispatchType == TASK_DISPATCH__FIXED) {
|
||||
SStreamTaskExecReq req = {
|
||||
.streamId = pTask->streamId,
|
||||
.taskId = pTask->taskId,
|
||||
.taskId = pTask->fixedEpDispatcher.taskId,
|
||||
.data = pRes,
|
||||
};
|
||||
|
||||
|
@ -211,8 +211,9 @@ int32_t tEncodeSStreamTask(SCoder* pEncoder, const SStreamTask* pTask) {
|
|||
}
|
||||
|
||||
if (pTask->dispatchType == TASK_DISPATCH__INPLACE) {
|
||||
if (tEncodeI8(pEncoder, pTask->inplaceDispatcher.reserved) < 0) return -1;
|
||||
if (tEncodeI32(pEncoder, pTask->inplaceDispatcher.taskId) < 0) return -1;
|
||||
} else if (pTask->dispatchType == TASK_DISPATCH__FIXED) {
|
||||
if (tEncodeI32(pEncoder, pTask->fixedEpDispatcher.taskId) < 0) return -1;
|
||||
if (tEncodeI32(pEncoder, pTask->fixedEpDispatcher.nodeId) < 0) return -1;
|
||||
if (tEncodeSEpSet(pEncoder, &pTask->fixedEpDispatcher.epSet) < 0) return -1;
|
||||
} else if (pTask->dispatchType == TASK_DISPATCH__SHUFFLE) {
|
||||
|
@ -248,8 +249,9 @@ int32_t tDecodeSStreamTask(SCoder* pDecoder, SStreamTask* pTask) {
|
|||
}
|
||||
|
||||
if (pTask->dispatchType == TASK_DISPATCH__INPLACE) {
|
||||
if (tDecodeI8(pDecoder, &pTask->inplaceDispatcher.reserved) < 0) return -1;
|
||||
if (tDecodeI32(pDecoder, &pTask->inplaceDispatcher.taskId) < 0) return -1;
|
||||
} else if (pTask->dispatchType == TASK_DISPATCH__FIXED) {
|
||||
if (tDecodeI32(pDecoder, &pTask->fixedEpDispatcher.taskId) < 0) return -1;
|
||||
if (tDecodeI32(pDecoder, &pTask->fixedEpDispatcher.nodeId) < 0) return -1;
|
||||
if (tDecodeSEpSet(pDecoder, &pTask->fixedEpDispatcher.epSet) < 0) return -1;
|
||||
} else if (pTask->dispatchType == TASK_DISPATCH__SHUFFLE) {
|
||||
|
|
|
@ -8,7 +8,6 @@ target_sources(tdb
|
|||
"src/db/tdbBtree.c"
|
||||
"src/db/tdbDb.c"
|
||||
"src/db/tdbEnv.c"
|
||||
# "src/db/tdbPage.c"
|
||||
"src/page/tdbPage.c"
|
||||
"src/page/tdbPageL.c"
|
||||
)
|
||||
|
|
|
@ -0,0 +1,14 @@
|
|||
/*
|
||||
* Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com>
|
||||
*
|
||||
* This program is free software: you can use, redistribute, and/or modify
|
||||
* it under the terms of the GNU Affero General Public License, version 3
|
||||
* or later ("AGPL"), as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
|
@ -0,0 +1,14 @@
|
|||
/*
|
||||
* Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com>
|
||||
*
|
||||
* This program is free software: you can use, redistribute, and/or modify
|
||||
* it under the terms of the GNU Affero General Public License, version 3
|
||||
* or later ("AGPL"), as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
|
@ -0,0 +1,14 @@
|
|||
/*
|
||||
* Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com>
|
||||
*
|
||||
* This program is free software: you can use, redistribute, and/or modify
|
||||
* it under the terms of the GNU Affero General Public License, version 3
|
||||
* or later ("AGPL"), as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
|
@ -0,0 +1,14 @@
|
|||
/*
|
||||
* Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com>
|
||||
*
|
||||
* This program is free software: you can use, redistribute, and/or modify
|
||||
* it under the terms of the GNU Affero General Public License, version 3
|
||||
* or later ("AGPL"), as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
|
@ -0,0 +1,27 @@
|
|||
/*
|
||||
* Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com>
|
||||
*
|
||||
* This program is free software: you can use, redistribute, and/or modify
|
||||
* it under the terms of the GNU Affero General Public License, version 3
|
||||
* or later ("AGPL"), as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef _TDB_BTREE_INT_H_
|
||||
#define _TDB_BTREE_INT_H_
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /*_TDB_BTREE_INT_H_*/
|
|
@ -0,0 +1,14 @@
|
|||
/*
|
||||
* Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com>
|
||||
*
|
||||
* This program is free software: you can use, redistribute, and/or modify
|
||||
* it under the terms of the GNU Affero General Public License, version 3
|
||||
* or later ("AGPL"), as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
File diff suppressed because it is too large
Load Diff
|
@ -15,13 +15,17 @@
|
|||
|
||||
#include "tdbInt.h"
|
||||
|
||||
struct STDb {
|
||||
struct STDB {
|
||||
STEnv *pEnv;
|
||||
SBTree *pBt;
|
||||
};
|
||||
|
||||
int tdbDbOpen(const char *fname, int keyLen, int valLen, FKeyComparator keyCmprFn, STEnv *pEnv, STDb **ppDb) {
|
||||
STDb *pDb;
|
||||
struct STDBC {
|
||||
SBTC btc;
|
||||
};
|
||||
|
||||
int tdbDbOpen(const char *fname, int keyLen, int valLen, FKeyComparator keyCmprFn, STEnv *pEnv, STDB **ppDb) {
|
||||
STDB *pDb;
|
||||
SPager *pPager;
|
||||
int ret;
|
||||
char fFullName[TDB_FILENAME_LEN];
|
||||
|
@ -30,7 +34,7 @@ int tdbDbOpen(const char *fname, int keyLen, int valLen, FKeyComparator keyCmprF
|
|||
|
||||
*ppDb = NULL;
|
||||
|
||||
pDb = (STDb *)taosMemoryCalloc(1, sizeof(*pDb));
|
||||
pDb = (STDB *)calloc(1, sizeof(*pDb));
|
||||
if (pDb == NULL) {
|
||||
return -1;
|
||||
}
|
||||
|
@ -59,23 +63,23 @@ int tdbDbOpen(const char *fname, int keyLen, int valLen, FKeyComparator keyCmprF
|
|||
return 0;
|
||||
}
|
||||
|
||||
int tdbDbClose(STDb *pDb) {
|
||||
int tdbDbClose(STDB *pDb) {
|
||||
// TODO
|
||||
return 0;
|
||||
}
|
||||
|
||||
int tdbDbDrop(STDb *pDb) {
|
||||
int tdbDbDrop(STDB *pDb) {
|
||||
// TODO
|
||||
return 0;
|
||||
}
|
||||
|
||||
int tdbDbInsert(STDb *pDb, const void *pKey, int keyLen, const void *pVal, int valLen) {
|
||||
SBtCursor btc;
|
||||
SBtCursor *pCur;
|
||||
int tdbDbInsert(STDB *pDb, const void *pKey, int keyLen, const void *pVal, int valLen) {
|
||||
SBTC btc;
|
||||
SBTC *pCur;
|
||||
int ret;
|
||||
|
||||
pCur = &btc;
|
||||
ret = tdbBtreeCursor(pCur, pDb->pBt);
|
||||
ret = tdbBtcOpen(pCur, pDb->pBt);
|
||||
if (ret < 0) {
|
||||
return -1;
|
||||
}
|
||||
|
@ -87,3 +91,43 @@ int tdbDbInsert(STDb *pDb, const void *pKey, int keyLen, const void *pVal, int v
|
|||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int tdbDbGet(STDB *pDb, const void *pKey, int kLen, void **ppVal, int *vLen) {
|
||||
return tdbBtreeGet(pDb->pBt, pKey, kLen, ppVal, vLen);
|
||||
}
|
||||
|
||||
int tdbDbcOpen(STDB *pDb, STDBC **ppDbc) {
|
||||
int ret;
|
||||
STDBC *pDbc = NULL;
|
||||
|
||||
*ppDbc = NULL;
|
||||
pDbc = malloc(sizeof(*pDbc));
|
||||
if (pDbc == NULL) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
tdbBtcOpen(&pDbc->btc, pDb->pBt);
|
||||
|
||||
// TODO: move to first now, we can move to any key-value
|
||||
// and in any direction, design new APIs.
|
||||
ret = tdbBtcMoveToFirst(&pDbc->btc);
|
||||
if (ret < 0) {
|
||||
ASSERT(0);
|
||||
return -1;
|
||||
}
|
||||
|
||||
*ppDbc = pDbc;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int tdbDbNext(STDBC *pDbc, void **ppKey, int *kLen, void **ppVal, int *vLen) {
|
||||
return tdbBtreeNext(&pDbc->btc, ppKey, kLen, ppVal, vLen);
|
||||
}
|
||||
|
||||
int tdbDbcClose(STDBC *pDbc) {
|
||||
if (pDbc) {
|
||||
free(pDbc);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
|
@ -27,7 +27,7 @@ int tdbEnvOpen(const char *rootDir, int pageSize, int cacheSize, STEnv **ppEnv)
|
|||
dsize = strlen(rootDir);
|
||||
zsize = sizeof(*pEnv) + dsize * 2 + strlen(TDB_JOURNAL_NAME) + 3;
|
||||
|
||||
pPtr = (uint8_t *)taosMemoryCalloc(1, zsize);
|
||||
pPtr = (uint8_t *)calloc(1, zsize);
|
||||
if (pPtr == NULL) {
|
||||
return -1;
|
||||
}
|
||||
|
|
|
@ -17,7 +17,7 @@
|
|||
struct SPCache {
|
||||
int pageSize;
|
||||
int cacheSize;
|
||||
TdThreadMutex mutex;
|
||||
pthread_mutex_t mutex;
|
||||
int nFree;
|
||||
SPage *pFree;
|
||||
int nPage;
|
||||
|
@ -53,19 +53,17 @@ static void tdbPCacheLock(SPCache *pCache);
|
|||
static void tdbPCacheUnlock(SPCache *pCache);
|
||||
static bool tdbPCacheLocked(SPCache *pCache);
|
||||
static SPage *tdbPCacheFetchImpl(SPCache *pCache, const SPgid *pPgid, bool alcNewPage);
|
||||
static void tdbPCachePinPage(SPage *pPage);
|
||||
static void tdbPCacheRemovePageFromHash(SPage *pPage);
|
||||
static void tdbPCacheAddPageToHash(SPage *pPage);
|
||||
static void tdbPCacheUnpinPage(SPage *pPage);
|
||||
static void *tdbOsMalloc(void *arg, size_t size);
|
||||
static void tdbOsFree(void *arg, void *ptr);
|
||||
static void tdbPCachePinPage(SPCache *pCache, SPage *pPage);
|
||||
static void tdbPCacheRemovePageFromHash(SPCache *pCache, SPage *pPage);
|
||||
static void tdbPCacheAddPageToHash(SPCache *pCache, SPage *pPage);
|
||||
static void tdbPCacheUnpinPage(SPCache *pCache, SPage *pPage);
|
||||
|
||||
int tdbPCacheOpen(int pageSize, int cacheSize, SPCache **ppCache) {
|
||||
SPCache *pCache;
|
||||
void *pPtr;
|
||||
SPage *pPgHdr;
|
||||
|
||||
pCache = (SPCache *)taosMemoryCalloc(1, sizeof(*pCache));
|
||||
pCache = (SPCache *)calloc(1, sizeof(*pCache));
|
||||
if (pCache == NULL) {
|
||||
return -1;
|
||||
}
|
||||
|
@ -74,7 +72,7 @@ int tdbPCacheOpen(int pageSize, int cacheSize, SPCache **ppCache) {
|
|||
pCache->cacheSize = cacheSize;
|
||||
|
||||
if (tdbPCacheOpenImpl(pCache) < 0) {
|
||||
taosMemoryFree(pCache);
|
||||
free(pCache);
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
@ -102,7 +100,7 @@ SPage *tdbPCacheFetch(SPCache *pCache, const SPgid *pPgid, bool alcNewPage) {
|
|||
return pPage;
|
||||
}
|
||||
|
||||
void tdbPCacheRelease(SPage *pPage) {
|
||||
void tdbPCacheRelease(SPCache *pCache, SPage *pPage) {
|
||||
i32 nRef;
|
||||
|
||||
nRef = TDB_UNREF_PAGE(pPage);
|
||||
|
@ -110,7 +108,7 @@ void tdbPCacheRelease(SPage *pPage) {
|
|||
|
||||
if (nRef == 0) {
|
||||
if (1 /*TODO: page still clean*/) {
|
||||
tdbPCacheUnpinPage(pPage);
|
||||
tdbPCacheUnpinPage(pCache, pPage);
|
||||
} else {
|
||||
// TODO
|
||||
ASSERT(0);
|
||||
|
@ -118,13 +116,13 @@ void tdbPCacheRelease(SPage *pPage) {
|
|||
}
|
||||
}
|
||||
|
||||
static void tdbPCacheInitLock(SPCache *pCache) { taosThreadMutexInit(&(pCache->mutex), NULL); }
|
||||
static void tdbPCacheInitLock(SPCache *pCache) { pthread_mutex_init(&(pCache->mutex), NULL); }
|
||||
|
||||
static void tdbPCacheClearLock(SPCache *pCache) { taosThreadMutexDestroy(&(pCache->mutex)); }
|
||||
static void tdbPCacheClearLock(SPCache *pCache) { pthread_mutex_destroy(&(pCache->mutex)); }
|
||||
|
||||
static void tdbPCacheLock(SPCache *pCache) { taosThreadMutexLock(&(pCache->mutex)); }
|
||||
static void tdbPCacheLock(SPCache *pCache) { pthread_mutex_lock(&(pCache->mutex)); }
|
||||
|
||||
static void tdbPCacheUnlock(SPCache *pCache) { taosThreadMutexUnlock(&(pCache->mutex)); }
|
||||
static void tdbPCacheUnlock(SPCache *pCache) { pthread_mutex_unlock(&(pCache->mutex)); }
|
||||
|
||||
static bool tdbPCacheLocked(SPCache *pCache) {
|
||||
assert(0);
|
||||
|
@ -144,7 +142,7 @@ static SPage *tdbPCacheFetchImpl(SPCache *pCache, const SPgid *pPgid, bool alcNe
|
|||
|
||||
if (pPage || !alcNewPage) {
|
||||
if (pPage) {
|
||||
tdbPCachePinPage(pPage);
|
||||
tdbPCachePinPage(pCache, pPage);
|
||||
}
|
||||
return pPage;
|
||||
}
|
||||
|
@ -160,8 +158,8 @@ static SPage *tdbPCacheFetchImpl(SPCache *pCache, const SPgid *pPgid, bool alcNe
|
|||
// 3. Try to Recycle a page
|
||||
if (!pPage && !pCache->lru.pLruPrev->isAnchor) {
|
||||
pPage = pCache->lru.pLruPrev;
|
||||
tdbPCacheRemovePageFromHash(pPage);
|
||||
tdbPCachePinPage(pPage);
|
||||
tdbPCacheRemovePageFromHash(pCache, pPage);
|
||||
tdbPCachePinPage(pCache, pPage);
|
||||
}
|
||||
|
||||
// 4. Try a stress allocation (TODO)
|
||||
|
@ -173,16 +171,13 @@ static SPage *tdbPCacheFetchImpl(SPCache *pCache, const SPgid *pPgid, bool alcNe
|
|||
memcpy(&(pPage->pgid), pPgid, sizeof(*pPgid));
|
||||
pPage->pLruNext = NULL;
|
||||
pPage->pPager = NULL;
|
||||
tdbPCacheAddPageToHash(pPage);
|
||||
tdbPCacheAddPageToHash(pCache, pPage);
|
||||
}
|
||||
|
||||
return pPage;
|
||||
}
|
||||
|
||||
static void tdbPCachePinPage(SPage *pPage) {
|
||||
SPCache *pCache;
|
||||
|
||||
pCache = pPage->pCache;
|
||||
static void tdbPCachePinPage(SPCache *pCache, SPage *pPage) {
|
||||
if (!PAGE_IS_PINNED(pPage)) {
|
||||
pPage->pLruPrev->pLruNext = pPage->pLruNext;
|
||||
pPage->pLruNext->pLruPrev = pPage->pLruPrev;
|
||||
|
@ -192,12 +187,9 @@ static void tdbPCachePinPage(SPage *pPage) {
|
|||
}
|
||||
}
|
||||
|
||||
static void tdbPCacheUnpinPage(SPage *pPage) {
|
||||
SPCache *pCache;
|
||||
static void tdbPCacheUnpinPage(SPCache *pCache, SPage *pPage) {
|
||||
i32 nRef;
|
||||
|
||||
pCache = pPage->pCache;
|
||||
|
||||
tdbPCacheLock(pCache);
|
||||
|
||||
nRef = TDB_GET_PAGE_REF(pPage);
|
||||
|
@ -217,12 +209,10 @@ static void tdbPCacheUnpinPage(SPage *pPage) {
|
|||
tdbPCacheUnlock(pCache);
|
||||
}
|
||||
|
||||
static void tdbPCacheRemovePageFromHash(SPage *pPage) {
|
||||
SPCache *pCache;
|
||||
static void tdbPCacheRemovePageFromHash(SPCache *pCache, SPage *pPage) {
|
||||
SPage **ppPage;
|
||||
int h;
|
||||
|
||||
pCache = pPage->pCache;
|
||||
h = PCACHE_PAGE_HASH(&(pPage->pgid));
|
||||
for (ppPage = &(pCache->pgHash[h % pCache->nHash]); *ppPage != pPage; ppPage = &((*ppPage)->pHashNext))
|
||||
;
|
||||
|
@ -232,11 +222,9 @@ static void tdbPCacheRemovePageFromHash(SPage *pPage) {
|
|||
pCache->nPage--;
|
||||
}
|
||||
|
||||
static void tdbPCacheAddPageToHash(SPage *pPage) {
|
||||
SPCache *pCache;
|
||||
static void tdbPCacheAddPageToHash(SPCache *pCache, SPage *pPage) {
|
||||
int h;
|
||||
|
||||
pCache = pPage->pCache;
|
||||
h = PCACHE_PAGE_HASH(&(pPage->pgid)) % pCache->nHash;
|
||||
|
||||
pPage->pHashNext = pCache->pgHash[h];
|
||||
|
@ -257,7 +245,7 @@ static int tdbPCacheOpenImpl(SPCache *pCache) {
|
|||
pCache->nFree = 0;
|
||||
pCache->pFree = NULL;
|
||||
for (int i = 0; i < pCache->cacheSize; i++) {
|
||||
ret = tdbPageCreate(pCache->pageSize, &pPage, tdbOsMalloc, NULL);
|
||||
ret = tdbPageCreate(pCache->pageSize, &pPage, NULL, NULL);
|
||||
if (ret < 0) {
|
||||
// TODO: handle error
|
||||
return -1;
|
||||
|
@ -266,7 +254,6 @@ static int tdbPCacheOpenImpl(SPCache *pCache) {
|
|||
// pPage->pgid = 0;
|
||||
pPage->isAnchor = 0;
|
||||
pPage->isLocalPage = 1;
|
||||
pPage->pCache = pCache;
|
||||
TDB_INIT_PAGE_REF(pPage);
|
||||
pPage->pHashNext = NULL;
|
||||
pPage->pLruNext = NULL;
|
||||
|
@ -281,7 +268,7 @@ static int tdbPCacheOpenImpl(SPCache *pCache) {
|
|||
// Open the hash table
|
||||
pCache->nPage = 0;
|
||||
pCache->nHash = pCache->cacheSize;
|
||||
pCache->pgHash = (SPage **)taosMemoryCalloc(pCache->nHash, sizeof(SPage *));
|
||||
pCache->pgHash = (SPage **)calloc(pCache->nHash, sizeof(SPage *));
|
||||
if (pCache->pgHash == NULL) {
|
||||
// TODO
|
||||
return -1;
|
||||
|
@ -297,13 +284,3 @@ static int tdbPCacheOpenImpl(SPCache *pCache) {
|
|||
}
|
||||
|
||||
int tdbPCacheGetPageSize(SPCache *pCache) { return pCache->pageSize; }
|
||||
|
||||
static void *tdbOsMalloc(void *arg, size_t size) {
|
||||
void *ptr;
|
||||
|
||||
ptr = taosMemoryMalloc(size);
|
||||
|
||||
return ptr;
|
||||
}
|
||||
|
||||
static void tdbOsFree(void *arg, void *ptr) { taosMemoryFree(ptr); }
|
|
@ -1,253 +0,0 @@
|
|||
/*
|
||||
* Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com>
|
||||
*
|
||||
* This program is free software: you can use, redistribute, and/or modify
|
||||
* it under the terms of the GNU Affero General Public License, version 3
|
||||
* or later ("AGPL"), as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "tdbInt.h"
|
||||
|
||||
typedef struct __attribute__((__packed__)) {
|
||||
u8 szCell[2];
|
||||
u8 nxOffset[2];
|
||||
} SFreeCell;
|
||||
|
||||
typedef struct __attribute__((__packed__)) {
|
||||
u8 szCell[3];
|
||||
u8 nxOffset[3];
|
||||
} SFreeCellL;
|
||||
|
||||
/* For small page */
|
||||
#define TDB_SPAGE_FREE_CELL_SIZE_PTR(PCELL) (((SFreeCell *)(PCELL))->szCell)
|
||||
#define TDB_SPAGE_FREE_CELL_NXOFFSET_PTR(PCELL) (((SFreeCell *)(PCELL))->nxOffset)
|
||||
|
||||
#define TDB_SPAGE_FREE_CELL_SIZE(PCELL) ((u16 *)TDB_SPAGE_FREE_CELL_SIZE_PTR(PCELL))[0]
|
||||
#define TDB_SPAGE_FREE_CELL_NXOFFSET(PCELL) ((u16 *)TDB_SPAGE_FREE_CELL_NXOFFSET_PTR(PCELL))[0]
|
||||
|
||||
#define TDB_SPAGE_FREE_CELL_SIZE_SET(PCELL, SIZE) (TDB_SPAGE_FREE_CELL_SIZE(PCELL) = (SIZE))
|
||||
#define TDB_SPAGE_FREE_CELL_NXOFFSET_SET(PCELL, OFFSET) (TDB_SPAGE_FREE_CELL_NXOFFSET(PCELL) = (OFFSET))
|
||||
|
||||
/* For large page */
|
||||
#define TDB_LPAGE_FREE_CELL_SIZE_PTR(PCELL) (((SFreeCellL *)(PCELL))->szCell)
|
||||
#define TDB_LPAGE_FREE_CELL_NXOFFSET_PTR(PCELL) (((SFreeCellL *)(PCELL))->nxOffset)
|
||||
|
||||
#define TDB_LPAGE_FREE_CELL_SIZE(PCELL) TDB_GET_U24(TDB_LPAGE_FREE_CELL_SIZE_PTR(PCELL))
|
||||
#define TDB_LPAGE_FREE_CELL_NXOFFSET(PCELL) TDB_GET_U24(TDB_LPAGE_FREE_CELL_NXOFFSET_PTR(PCELL))
|
||||
|
||||
#define TDB_LPAGE_FREE_CELL_SIZE_SET(PCELL, SIZE) TDB_PUT_U24(TDB_LPAGE_FREE_CELL_SIZE_PTR(PCELL), SIZE)
|
||||
#define TDB_LPAGE_FREE_CELL_NXOFFSET_SET(PCELL, OFFSET) TDB_PUT_U24(TDB_LPAGE_FREE_CELL_NXOFFSET_PTR(PCELL), OFFSET)
|
||||
|
||||
/* For page */
|
||||
#define TDB_PAGE_FREE_CELL_SIZE_PTR(PPAGE, PCELL) \
|
||||
(TDB_IS_LARGE_PAGE(pPage) ? TDB_LPAGE_FREE_CELL_SIZE_PTR(PCELL) : TDB_SPAGE_FREE_CELL_SIZE_PTR(PCELL))
|
||||
#define TDB_PAGE_FREE_CELL_NXOFFSET_PTR(PPAGE, PCELL) \
|
||||
(TDB_IS_LARGE_PAGE(pPage) ? TDB_LPAGE_FREE_CELL_NXOFFSET_PTR(PCELL) : TDB_SPAGE_FREE_CELL_NXOFFSET_PTR(PCELL))
|
||||
|
||||
#define TDB_PAGE_FREE_CELL_SIZE(PPAGE, PCELL) \
|
||||
(TDB_IS_LARGE_PAGE(pPage) ? TDB_LPAGE_FREE_CELL_SIZE(PCELL) : TDB_SPAGE_FREE_CELL_SIZE(PCELL))
|
||||
#define TDB_PAGE_FREE_CELL_NXOFFSET(PPAGE, PCELL) \
|
||||
(TDB_IS_LARGE_PAGE(pPage) ? TDB_LPAGE_FREE_CELL_NXOFFSET(PCELL) : TDB_SPAGE_FREE_CELL_NXOFFSET(PCELL))
|
||||
|
||||
#define TDB_PAGE_FREE_CELL_SIZE_SET(PPAGE, PCELL, SIZE) \
|
||||
do { \
|
||||
if (TDB_IS_LARGE_PAGE(PPAGE)) { \
|
||||
TDB_LPAGE_FREE_CELL_SIZE_SET(PCELL, SIZE); \
|
||||
} else { \
|
||||
TDB_SPAGE_FREE_CELL_SIZE_SET(PCELL, SIZE); \
|
||||
} \
|
||||
} while (0)
|
||||
#define TDB_PAGE_FREE_CELL_NXOFFSET_SET(PPAGE, PCELL, OFFSET) \
|
||||
do { \
|
||||
if (TDB_IS_LARGE_PAGE(PPAGE)) { \
|
||||
TDB_LPAGE_FREE_CELL_NXOFFSET_SET(PCELL, OFFSET); \
|
||||
} else { \
|
||||
TDB_SPAGE_FREE_CELL_NXOFFSET_SET(PCELL, OFFSET); \
|
||||
} \
|
||||
} while (0)
|
||||
|
||||
static int tdbPageAllocate(SPage *pPage, int size, SCell **ppCell);
|
||||
static int tdbPageDefragment(SPage *pPage);
|
||||
|
||||
int tdbPageCreate(int pageSize, SPage **ppPage, void *(*xMalloc)(void *, size_t), void *arg) {
|
||||
SPage *pPage;
|
||||
u8 *ptr;
|
||||
int size;
|
||||
|
||||
ASSERT(TDB_IS_PGSIZE_VLD(pageSize));
|
||||
|
||||
*ppPage = NULL;
|
||||
size = pageSize + sizeof(*pPage);
|
||||
|
||||
ptr = (u8 *)((*xMalloc)(arg, size));
|
||||
if (pPage == NULL) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
memset(ptr, 0, size);
|
||||
pPage = (SPage *)(ptr + pageSize);
|
||||
|
||||
pPage->pData = ptr;
|
||||
pPage->pageSize = pageSize;
|
||||
if (pageSize < 65536) {
|
||||
pPage->szOffset = 2;
|
||||
pPage->szPageHdr = sizeof(SPageHdr);
|
||||
pPage->szFreeCell = sizeof(SFreeCell);
|
||||
} else {
|
||||
pPage->szOffset = 3;
|
||||
pPage->szPageHdr = sizeof(SPageHdrL);
|
||||
pPage->szFreeCell = sizeof(SFreeCellL);
|
||||
}
|
||||
TDB_INIT_PAGE_LOCK(pPage);
|
||||
|
||||
/* TODO */
|
||||
|
||||
*ppPage = pPage;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int tdbPageDestroy(SPage *pPage, void (*xFree)(void *arg, void *ptr), void *arg) {
|
||||
u8 *ptr;
|
||||
|
||||
ptr = pPage->pData;
|
||||
(*xFree)(arg, ptr);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int tdbPageInsertCell(SPage *pPage, int idx, SCell *pCell, int szCell) {
|
||||
int ret;
|
||||
SCell *pTarget;
|
||||
u8 *pTmp;
|
||||
int j;
|
||||
|
||||
if (pPage->nOverflow || szCell + pPage->szOffset > pPage->nFree) {
|
||||
// TODO: need to figure out if pCell may be used by outside of this function
|
||||
j = pPage->nOverflow++;
|
||||
|
||||
pPage->apOvfl[j] = pCell;
|
||||
pPage->aiOvfl[j] = idx;
|
||||
} else {
|
||||
ret = tdbPageAllocate(pPage, szCell, &pTarget);
|
||||
if (ret < 0) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
memcpy(pTarget, pCell, szCell);
|
||||
pTmp = pPage->pCellIdx + idx * pPage->szOffset;
|
||||
memmove(pTmp + pPage->szOffset, pTmp, pPage->pFreeStart - pTmp - pPage->szOffset);
|
||||
TDB_PAGE_CELL_OFFSET_AT_SET(pPage, idx, pTarget - pPage->pData);
|
||||
TDB_PAGE_NCELLS_SET(pPage, TDB_PAGE_NCELLS(pPage) + 1);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int tdbPageDropCell(SPage *pPage, int idx) {
|
||||
// TODO
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int tdbPageAllocate(SPage *pPage, int size, SCell **ppCell) {
|
||||
SCell *pCell;
|
||||
SFreeCell *pFreeCell;
|
||||
u8 *pOffset;
|
||||
int ret;
|
||||
|
||||
ASSERT(pPage->nFree > size + pPage->szOffset);
|
||||
|
||||
pCell = NULL;
|
||||
*ppCell = NULL;
|
||||
|
||||
// 1. Try to allocate from the free space area
|
||||
if (pPage->pFreeEnd - pPage->pFreeStart > size + pPage->szOffset) {
|
||||
pPage->pFreeEnd -= size;
|
||||
pPage->pFreeStart += pPage->szOffset;
|
||||
pCell = pPage->pFreeEnd;
|
||||
}
|
||||
|
||||
// 2. Try to allocate from the page free list
|
||||
if ((pCell == NULL) && (pPage->pFreeEnd - pPage->pFreeStart >= pPage->szOffset) && TDB_PAGE_FCELL(pPage)) {
|
||||
int szCell;
|
||||
int nxOffset;
|
||||
|
||||
pCell = pPage->pData + TDB_PAGE_FCELL(pPage);
|
||||
pOffset = TDB_IS_LARGE_PAGE(pPage) ? ((SPageHdrL *)(pPage->pPageHdr))[0].fCell
|
||||
: (u8 *)&(((SPageHdr *)(pPage->pPageHdr))[0].fCell);
|
||||
szCell = TDB_PAGE_FREE_CELL_SIZE(pPage, pCell);
|
||||
nxOffset = TDB_PAGE_FREE_CELL_NXOFFSET(pPage, pCell);
|
||||
|
||||
for (;;) {
|
||||
// Find a cell
|
||||
if (szCell >= size) {
|
||||
if (szCell - size >= pPage->szFreeCell) {
|
||||
SCell *pTmpCell = pCell + size;
|
||||
|
||||
TDB_PAGE_FREE_CELL_SIZE_SET(pPage, pTmpCell, szCell - size);
|
||||
TDB_PAGE_FREE_CELL_NXOFFSET_SET(pPage, pTmpCell, nxOffset);
|
||||
// TODO: *pOffset = pTmpCell - pPage->pData;
|
||||
} else {
|
||||
TDB_PAGE_NFREE_SET(pPage, TDB_PAGE_NFREE(pPage) + szCell - size);
|
||||
// TODO: *pOffset = nxOffset;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
// Not find a cell yet
|
||||
if (nxOffset > 0) {
|
||||
pCell = pPage->pData + nxOffset;
|
||||
pOffset = TDB_PAGE_FREE_CELL_NXOFFSET_PTR(pPage, pCell);
|
||||
szCell = TDB_PAGE_FREE_CELL_SIZE(pPage, pCell);
|
||||
nxOffset = TDB_PAGE_FREE_CELL_NXOFFSET(pPage, pCell);
|
||||
continue;
|
||||
} else {
|
||||
pCell = NULL;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (pCell) {
|
||||
pPage->pFreeStart = pPage->pFreeStart + pPage->szOffset;
|
||||
}
|
||||
}
|
||||
|
||||
// 3. Try to dfragment and allocate again
|
||||
if (pCell == NULL) {
|
||||
ret = tdbPageDefragment(pPage);
|
||||
if (ret < 0) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
ASSERT(pPage->pFreeEnd - pPage->pFreeStart > size + pPage->szOffset);
|
||||
ASSERT(pPage->nFree == pPage->pFreeEnd - pPage->pFreeStart);
|
||||
|
||||
// Allocate from the free space area again
|
||||
pPage->pFreeEnd -= size;
|
||||
pPage->pFreeStart += pPage->szOffset;
|
||||
pCell = pPage->pFreeEnd;
|
||||
}
|
||||
|
||||
ASSERT(pCell != NULL);
|
||||
|
||||
pPage->nFree = pPage->nFree - size - pPage->szOffset;
|
||||
*ppCell = pCell;
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int tdbPageFree(SPage *pPage, int idx, SCell *pCell, int size) {
|
||||
// TODO
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int tdbPageDefragment(SPage *pPage) {
|
||||
// TODO
|
||||
ASSERT(0);
|
||||
return 0;
|
||||
}
|
|
@ -60,7 +60,7 @@ int tdbPagerOpen(SPCache *pCache, const char *fileName, SPager **ppPager) {
|
|||
zsize = sizeof(*pPager) /* SPager */
|
||||
+ fsize + 1 /* dbFileName */
|
||||
+ fsize + 8 + 1; /* jFileName */
|
||||
pPtr = (uint8_t *)taosMemoryCalloc(1, zsize);
|
||||
pPtr = (uint8_t *)calloc(1, zsize);
|
||||
if (pPtr == NULL) {
|
||||
return -1;
|
||||
}
|
||||
|
@ -255,6 +255,10 @@ int tdbPagerNewPage(SPager *pPager, SPgno *ppgno, SPage **ppPage, int (*initPage
|
|||
return 0;
|
||||
}
|
||||
|
||||
void tdbPagerReturnPage(SPager *pPager, SPage *pPage) {
|
||||
tdbPCacheRelease(pPager->pCache, pPage);
|
||||
}
|
||||
|
||||
static int tdbPagerAllocFreePage(SPager *pPager, SPgno *ppgno) {
|
||||
// TODO: Allocate a page from the free list
|
||||
return 0;
|
||||
|
|
|
@ -21,9 +21,14 @@ extern "C" {
|
|||
#endif
|
||||
|
||||
typedef struct SBTree SBTree;
|
||||
typedef struct SBtCursor SBtCursor;
|
||||
typedef struct SBTC SBTC;
|
||||
typedef struct SBtInfo {
|
||||
SPgno root;
|
||||
int nLevel;
|
||||
int nData;
|
||||
} SBtInfo;
|
||||
|
||||
struct SBtCursor {
|
||||
struct SBTC {
|
||||
SBTree *pBt;
|
||||
i8 iPage;
|
||||
SPage *pPage;
|
||||
|
@ -33,10 +38,19 @@ struct SBtCursor {
|
|||
void *pBuf;
|
||||
};
|
||||
|
||||
// SBTree
|
||||
int tdbBtreeOpen(int keyLen, int valLen, SPager *pFile, FKeyComparator kcmpr, SBTree **ppBt);
|
||||
int tdbBtreeClose(SBTree *pBt);
|
||||
int tdbBtreeCursor(SBtCursor *pCur, SBTree *pBt);
|
||||
int tdbBtCursorInsert(SBtCursor *pCur, const void *pKey, int kLen, const void *pVal, int vLen);
|
||||
int tdbBtCursorInsert(SBTC *pCur, const void *pKey, int kLen, const void *pVal, int vLen);
|
||||
int tdbBtreeGet(SBTree *pBt, const void *pKey, int kLen, void **ppVal, int *vLen);
|
||||
|
||||
// SBTC
|
||||
int tdbBtcOpen(SBTC *pCur, SBTree *pBt);
|
||||
int tdbBtcMoveToFirst(SBTC *pBtc);
|
||||
int tdbBtcMoveToLast(SBTC *pBtc);
|
||||
int tdbBtcMoveTo(SBTC *pBtc, const void *pKey, int kLen);
|
||||
int tdbBtreeNext(SBTC *pBtc, void **ppKey, int *kLen, void **ppVal, int *vLen);
|
||||
int tdbBtcClose(SBTC *pBtc);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
|
|
@ -20,12 +20,20 @@
|
|||
extern "C" {
|
||||
#endif
|
||||
|
||||
typedef struct STDb STDb;
|
||||
typedef struct STDB STDB;
|
||||
typedef struct STDBC STDBC;
|
||||
|
||||
int tdbDbOpen(const char *fname, int keyLen, int valLen, FKeyComparator keyCmprFn, STEnv *pEnv, STDb **ppDb);
|
||||
int tdbDbClose(STDb *pDb);
|
||||
int tdbDbDrop(STDb *pDb);
|
||||
int tdbDbInsert(STDb *pDb, const void *pKey, int keyLen, const void *pVal, int valLen);
|
||||
// STDB
|
||||
int tdbDbOpen(const char *fname, int keyLen, int valLen, FKeyComparator keyCmprFn, STEnv *pEnv, STDB **ppDb);
|
||||
int tdbDbClose(STDB *pDb);
|
||||
int tdbDbDrop(STDB *pDb);
|
||||
int tdbDbInsert(STDB *pDb, const void *pKey, int keyLen, const void *pVal, int valLen);
|
||||
int tdbDbGet(STDB *pDb, const void *pKey, int kLen, void **ppVal, int *vLen);
|
||||
|
||||
// STDBC
|
||||
int tdbDbcOpen(STDB *pDb, STDBC **ppDbc);
|
||||
int tdbDbNext(STDBC *pDbc, void **ppKey, int *kLen, void **ppVal, int *vLen);
|
||||
int tdbDbcClose(STDBC *pDbc);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
|
|
@ -95,7 +95,7 @@ static FORCE_INLINE int tdbCmprPgId(const void *p1, const void *p2) {
|
|||
// tdb_log
|
||||
#define tdbError(var)
|
||||
|
||||
typedef TD_DLIST(STDb) STDbList;
|
||||
typedef TD_DLIST(STDB) STDbList;
|
||||
typedef TD_DLIST(SPgFile) SPgFileList;
|
||||
typedef TD_DLIST_NODE(SPgFile) SPgFileListNode;
|
||||
|
||||
|
@ -141,8 +141,8 @@ typedef int (*FKeyComparator)(const void *pKey1, int kLen1, const void *pKey2, i
|
|||
#define TDB_FLAG_IS(flags, flag) ((flags) == (flag))
|
||||
#define TDB_FLAG_HAS(flags, flag) (((flags) & (flag)) != 0)
|
||||
#define TDB_FLAG_NO(flags, flag) ((flags) & (flag) == 0)
|
||||
#define TDB_FLAG_ADD(flags, flag) ((flags) |= (flag))
|
||||
#define TDB_FLAG_REMOVE(flags, flag) ((flags) &= (~(flag)))
|
||||
#define TDB_FLAG_ADD(flags, flag) ((flags) | (flag))
|
||||
#define TDB_FLAG_REMOVE(flags, flag) ((flags) & (~(flag)))
|
||||
|
||||
typedef struct SPager SPager;
|
||||
typedef struct SPCache SPCache;
|
||||
|
|
|
@ -25,7 +25,6 @@ extern "C" {
|
|||
u8 isLocalPage; \
|
||||
u8 isDirty; \
|
||||
i32 nRef; \
|
||||
SPCache *pCache; \
|
||||
SPage *pFreeNext; \
|
||||
SPage *pHashNext; \
|
||||
SPage *pLruNext; \
|
||||
|
@ -37,7 +36,7 @@ extern "C" {
|
|||
int tdbPCacheOpen(int pageSize, int cacheSize, SPCache **ppCache);
|
||||
int tdbPCacheClose(SPCache *pCache);
|
||||
SPage *tdbPCacheFetch(SPCache *pCache, const SPgid *pPgid, bool alcNewPage);
|
||||
void tdbPCacheRelease(SPage *pPage);
|
||||
void tdbPCacheRelease(SPCache *pCache, SPage *pPage);
|
||||
int tdbPCacheGetPageSize(SPCache *pCache);
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
|
|
@ -27,9 +27,6 @@ typedef struct {
|
|||
int szOffset;
|
||||
int szPageHdr;
|
||||
int szFreeCell;
|
||||
// flags
|
||||
u16 (*getFlags)(SPage *);
|
||||
void (*setFlags)(SPage *, u16);
|
||||
// cell number
|
||||
int (*getCellNum)(SPage *);
|
||||
void (*setCellNum)(SPage *, int);
|
||||
|
@ -45,6 +42,9 @@ typedef struct {
|
|||
// cell offset at idx
|
||||
int (*getCellOffset)(SPage *, int);
|
||||
void (*setCellOffset)(SPage *, int, int);
|
||||
// free cell info
|
||||
void (*getFreeCellInfo)(SCell *pCell, int *szCell, int *nxOffset);
|
||||
void (*setFreeCellInfo)(SCell *pCell, int szCell, int nxOffset);
|
||||
} SPageMethods;
|
||||
|
||||
// Page footer
|
||||
|
@ -53,58 +53,37 @@ typedef struct __attribute__((__packed__)) {
|
|||
} SPageFtr;
|
||||
|
||||
struct SPage {
|
||||
TdThreadSpinlock lock;
|
||||
u8 *pData;
|
||||
pthread_spinlock_t lock;
|
||||
int pageSize;
|
||||
u8 *pData;
|
||||
SPageMethods *pPageMethods;
|
||||
// Fields below used by pager and am
|
||||
u8 szAmHdr;
|
||||
u8 *pPageHdr;
|
||||
u8 *pAmHdr;
|
||||
u8 *pCellIdx;
|
||||
u8 *pFreeStart;
|
||||
u8 *pFreeEnd;
|
||||
SPageFtr *pPageFtr;
|
||||
int kLen; // key length of the page, -1 for unknown
|
||||
int vLen; // value length of the page, -1 for unknown
|
||||
int nFree;
|
||||
int maxLocal;
|
||||
int minLocal;
|
||||
int nOverflow;
|
||||
SCell *apOvfl[4];
|
||||
int aiOvfl[4];
|
||||
int kLen; // key length of the page, -1 for unknown
|
||||
int vLen; // value length of the page, -1 for unknown
|
||||
int maxLocal;
|
||||
int minLocal;
|
||||
int (*xCellSize)(const SPage *, SCell *);
|
||||
// Fields used by SPCache
|
||||
TDB_PCACHE_PAGE
|
||||
};
|
||||
|
||||
/* For page */
|
||||
#define TDB_PAGE_FLAGS(pPage) (*(pPage)->pPageMethods->getFlags)(pPage)
|
||||
#define TDB_PAGE_NCELLS(pPage) (*(pPage)->pPageMethods->getCellNum)(pPage)
|
||||
#define TDB_PAGE_CCELLS(pPage) (*(pPage)->pPageMethods->getCellBody)(pPage)
|
||||
#define TDB_PAGE_FCELL(pPage) (*(pPage)->pPageMethods->getCellFree)(pPage)
|
||||
#define TDB_PAGE_NFREE(pPage) (*(pPage)->pPageMethods->getFreeBytes)(pPage)
|
||||
#define TDB_PAGE_CELL_OFFSET_AT(pPage, idx) (*(pPage)->pPageMethods->getCellOffset)(pPage, idx)
|
||||
|
||||
#define TDB_PAGE_FLAGS_SET(pPage, FLAGS) (*(pPage)->pPageMethods->setFlags)(pPage, FLAGS)
|
||||
#define TDB_PAGE_NCELLS_SET(pPage, NCELLS) (*(pPage)->pPageMethods->setCellNum)(pPage, NCELLS)
|
||||
#define TDB_PAGE_CCELLS_SET(pPage, CCELLS) (*(pPage)->pPageMethods->setCellBody)(pPage, CCELLS)
|
||||
#define TDB_PAGE_FCELL_SET(pPage, FCELL) (*(pPage)->pPageMethods->setCellFree)(pPage, FCELL)
|
||||
#define TDB_PAGE_NFREE_SET(pPage, NFREE) (*(pPage)->pPageMethods->setFreeBytes)(pPage, NFREE)
|
||||
#define TDB_PAGE_CELL_OFFSET_AT_SET(pPage, idx, OFFSET) (*(pPage)->pPageMethods->setCellOffset)(pPage, idx, OFFSET)
|
||||
|
||||
#define TDB_PAGE_OFFSET_SIZE(pPage) ((pPage)->pPageMethods->szOffset)
|
||||
|
||||
#define TDB_PAGE_CELL_AT(pPage, idx) ((pPage)->pData + TDB_PAGE_CELL_OFFSET_AT(pPage, idx))
|
||||
|
||||
// For page lock
|
||||
#define P_LOCK_SUCC 0
|
||||
#define P_LOCK_BUSY 1
|
||||
#define P_LOCK_FAIL -1
|
||||
|
||||
#define TDB_INIT_PAGE_LOCK(pPage) taosThreadSpinInit(&((pPage)->lock), 0)
|
||||
#define TDB_DESTROY_PAGE_LOCK(pPage) taosThreadSpinDestroy(&((pPage)->lock))
|
||||
#define TDB_LOCK_PAGE(pPage) taosThreadSpinLock(&((pPage)->lock))
|
||||
#define TDB_UNLOCK_PAGE(pPage) taosThreadSpinUnlock(&((pPage)->lock))
|
||||
#define TDB_INIT_PAGE_LOCK(pPage) pthread_spin_init(&((pPage)->lock), 0)
|
||||
#define TDB_DESTROY_PAGE_LOCK(pPage) pthread_spin_destroy(&((pPage)->lock))
|
||||
#define TDB_LOCK_PAGE(pPage) pthread_spin_lock(&((pPage)->lock))
|
||||
#define TDB_UNLOCK_PAGE(pPage) pthread_spin_unlock(&((pPage)->lock))
|
||||
#define TDB_TRY_LOCK_PAGE(pPage) \
|
||||
({ \
|
||||
int ret; \
|
||||
|
@ -119,10 +98,43 @@ struct SPage {
|
|||
})
|
||||
|
||||
// APIs
|
||||
#define TDB_PAGE_TOTAL_CELLS(pPage) ((pPage)->nOverflow + (pPage)->pPageMethods->getCellNum(pPage))
|
||||
#define TDB_PAGE_USABLE_SIZE(pPage) ((u8 *)(pPage)->pPageFtr - (pPage)->pCellIdx)
|
||||
#define TDB_PAGE_PGNO(pPage) ((pPage)->pgid.pgno)
|
||||
#define TDB_BYTES_CELL_TAKEN(pPage, pCell) ((*(pPage)->xCellSize)(pPage, pCell) + (pPage)->pPageMethods->szOffset)
|
||||
#define TDB_PAGE_OFFSET_SIZE(pPage) ((pPage)->pPageMethods->szOffset)
|
||||
|
||||
int tdbPageCreate(int pageSize, SPage **ppPage, void *(*xMalloc)(void *, size_t), void *arg);
|
||||
int tdbPageDestroy(SPage *pPage, void (*xFree)(void *arg, void *ptr), void *arg);
|
||||
int tdbPageInsertCell(SPage *pPage, int idx, SCell *pCell, int szCell);
|
||||
void tdbPageZero(SPage *pPage, u8 szAmHdr, int (*xCellSize)(const SPage *, SCell *));
|
||||
void tdbPageInit(SPage *pPage, u8 szAmHdr, int (*xCellSize)(const SPage *, SCell *));
|
||||
int tdbPageInsertCell(SPage *pPage, int idx, SCell *pCell, int szCell, u8 asOvfl);
|
||||
int tdbPageDropCell(SPage *pPage, int idx);
|
||||
void tdbPageCopy(SPage *pFromPage, SPage *pToPage);
|
||||
|
||||
static inline SCell *tdbPageGetCell(SPage *pPage, int idx) {
|
||||
SCell *pCell;
|
||||
int iOvfl;
|
||||
int lidx;
|
||||
|
||||
ASSERT(idx >= 0 && idx < TDB_PAGE_TOTAL_CELLS(pPage));
|
||||
|
||||
iOvfl = 0;
|
||||
for (; iOvfl < pPage->nOverflow; iOvfl++) {
|
||||
if (pPage->aiOvfl[iOvfl] == idx) {
|
||||
pCell = pPage->apOvfl[iOvfl];
|
||||
return pCell;
|
||||
} else if (pPage->aiOvfl[iOvfl] > idx) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
lidx = idx - iOvfl;
|
||||
ASSERT(lidx >= 0 && lidx < pPage->pPageMethods->getCellNum(pPage));
|
||||
pCell = pPage->pData + pPage->pPageMethods->getCellOffset(pPage, lidx);
|
||||
|
||||
return pCell;
|
||||
}
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
|
|
@ -29,6 +29,7 @@ int tdbPagerCommit(SPager *pPager);
|
|||
int tdbPagerGetPageSize(SPager *pPager);
|
||||
int tdbPagerFetchPage(SPager *pPager, SPgno pgno, SPage **ppPage, int (*initPage)(SPage *, void *), void *arg);
|
||||
int tdbPagerNewPage(SPager *pPager, SPgno *ppgno, SPage **ppPage, int (*initPage)(SPage *, void *), void *arg);
|
||||
void tdbPagerReturnPage(SPager *pPager, SPage *pPage);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
|
|
@ -39,6 +39,38 @@ int tdbGetFileSize(const char *fname, int pgSize, SPgno *pSize);
|
|||
|
||||
int tdbPRead(int fd, void *pData, int count, i64 offset);
|
||||
|
||||
#define TDB_REALLOC(PTR, SIZE) \
|
||||
({ \
|
||||
void *nPtr; \
|
||||
if ((PTR) == NULL || ((int *)(PTR))[-1] < (SIZE)) { \
|
||||
nPtr = realloc((PTR) ? (char *)(PTR) - sizeof(int) : NULL, (SIZE) + sizeof(int)); \
|
||||
if (nPtr) { \
|
||||
((int *)nPtr)[0] = (SIZE); \
|
||||
nPtr = (char *)nPtr + sizeof(int); \
|
||||
} \
|
||||
} else { \
|
||||
nPtr = (PTR); \
|
||||
} \
|
||||
nPtr; \
|
||||
})
|
||||
|
||||
#define TDB_FREE(PTR) \
|
||||
do { \
|
||||
if (PTR) { \
|
||||
free((char *)(PTR) - sizeof(int)); \
|
||||
} \
|
||||
} while (0)
|
||||
|
||||
static inline void *tdbOsMalloc(void *arg, size_t size) {
|
||||
void *ptr;
|
||||
|
||||
ptr = malloc(size);
|
||||
|
||||
return ptr;
|
||||
}
|
||||
|
||||
static inline void tdbOsFree(void *arg, void *ptr) { free(ptr); }
|
||||
|
||||
static inline int tdbPutVarInt(u8 *p, int v) {
|
||||
int n = 0;
|
||||
|
||||
|
|
|
@ -18,13 +18,25 @@
|
|||
extern SPageMethods pageMethods;
|
||||
extern SPageMethods pageLargeMethods;
|
||||
|
||||
typedef struct __attribute__((__packed__)) {
|
||||
u16 szCell;
|
||||
u16 nxOffset;
|
||||
} SFreeCell;
|
||||
#define TDB_PAGE_HDR_SIZE(pPage) ((pPage)->pPageMethods->szPageHdr)
|
||||
#define TDB_PAGE_FREE_CELL_SIZE(pPage) ((pPage)->pPageMethods->szFreeCell)
|
||||
#define TDB_PAGE_NCELLS(pPage) (*(pPage)->pPageMethods->getCellNum)(pPage)
|
||||
#define TDB_PAGE_CCELLS(pPage) (*(pPage)->pPageMethods->getCellBody)(pPage)
|
||||
#define TDB_PAGE_FCELL(pPage) (*(pPage)->pPageMethods->getCellFree)(pPage)
|
||||
#define TDB_PAGE_NFREE(pPage) (*(pPage)->pPageMethods->getFreeBytes)(pPage)
|
||||
#define TDB_PAGE_CELL_OFFSET_AT(pPage, idx) (*(pPage)->pPageMethods->getCellOffset)(pPage, idx)
|
||||
#define TDB_PAGE_NCELLS_SET(pPage, NCELLS) (*(pPage)->pPageMethods->setCellNum)(pPage, NCELLS)
|
||||
#define TDB_PAGE_CCELLS_SET(pPage, CCELLS) (*(pPage)->pPageMethods->setCellBody)(pPage, CCELLS)
|
||||
#define TDB_PAGE_FCELL_SET(pPage, FCELL) (*(pPage)->pPageMethods->setCellFree)(pPage, FCELL)
|
||||
#define TDB_PAGE_NFREE_SET(pPage, NFREE) (*(pPage)->pPageMethods->setFreeBytes)(pPage, NFREE)
|
||||
#define TDB_PAGE_CELL_OFFSET_AT_SET(pPage, idx, OFFSET) (*(pPage)->pPageMethods->setCellOffset)(pPage, idx, OFFSET)
|
||||
#define TDB_PAGE_CELL_AT(pPage, idx) ((pPage)->pData + TDB_PAGE_CELL_OFFSET_AT(pPage, idx))
|
||||
#define TDB_PAGE_MAX_FREE_BLOCK(pPage, szAmHdr) \
|
||||
((pPage)->pageSize - (szAmHdr)-TDB_PAGE_HDR_SIZE(pPage) - sizeof(SPageFtr))
|
||||
|
||||
static int tdbPageAllocate(SPage *pPage, int size, SCell **ppCell);
|
||||
static int tdbPageDefragment(SPage *pPage);
|
||||
static int tdbPageFree(SPage *pPage, int idx, SCell *pCell, int szCell);
|
||||
|
||||
int tdbPageCreate(int pageSize, SPage **ppPage, void *(*xMalloc)(void *, size_t), void *arg) {
|
||||
SPage *pPage;
|
||||
|
@ -35,25 +47,26 @@ int tdbPageCreate(int pageSize, SPage **ppPage, void *(*xMalloc)(void *, size_t)
|
|||
|
||||
*ppPage = NULL;
|
||||
size = pageSize + sizeof(*pPage);
|
||||
if (xMalloc == NULL) {
|
||||
xMalloc = tdbOsMalloc;
|
||||
}
|
||||
|
||||
ptr = (u8 *)((*xMalloc)(arg, size));
|
||||
if (pPage == NULL) {
|
||||
if (ptr == NULL) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
memset(ptr, 0, size);
|
||||
pPage = (SPage *)(ptr + pageSize);
|
||||
|
||||
pPage->pData = ptr;
|
||||
TDB_INIT_PAGE_LOCK(pPage);
|
||||
pPage->pageSize = pageSize;
|
||||
pPage->pData = ptr;
|
||||
if (pageSize < 65536) {
|
||||
pPage->pPageMethods = &pageMethods;
|
||||
} else {
|
||||
pPage->pPageMethods = &pageLargeMethods;
|
||||
}
|
||||
TDB_INIT_PAGE_LOCK(pPage);
|
||||
|
||||
/* TODO */
|
||||
|
||||
*ppPage = pPage;
|
||||
return 0;
|
||||
|
@ -62,157 +75,365 @@ int tdbPageCreate(int pageSize, SPage **ppPage, void *(*xMalloc)(void *, size_t)
|
|||
int tdbPageDestroy(SPage *pPage, void (*xFree)(void *arg, void *ptr), void *arg) {
|
||||
u8 *ptr;
|
||||
|
||||
if (!xFree) {
|
||||
xFree = tdbOsFree;
|
||||
}
|
||||
|
||||
ptr = pPage->pData;
|
||||
(*xFree)(arg, ptr);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int tdbPageInsertCell(SPage *pPage, int idx, SCell *pCell, int szCell) {
|
||||
int ret;
|
||||
SCell *pTarget;
|
||||
u8 *pTmp;
|
||||
int j;
|
||||
void tdbPageZero(SPage *pPage, u8 szAmHdr, int (*xCellSize)(const SPage *, SCell *)) {
|
||||
pPage->pPageHdr = pPage->pData + szAmHdr;
|
||||
TDB_PAGE_NCELLS_SET(pPage, 0);
|
||||
TDB_PAGE_CCELLS_SET(pPage, pPage->pageSize - sizeof(SPageFtr));
|
||||
TDB_PAGE_FCELL_SET(pPage, 0);
|
||||
TDB_PAGE_NFREE_SET(pPage, TDB_PAGE_MAX_FREE_BLOCK(pPage, szAmHdr));
|
||||
pPage->pCellIdx = pPage->pPageHdr + TDB_PAGE_HDR_SIZE(pPage);
|
||||
pPage->pFreeStart = pPage->pCellIdx;
|
||||
pPage->pFreeEnd = pPage->pData + TDB_PAGE_CCELLS(pPage);
|
||||
pPage->pPageFtr = (SPageFtr *)(pPage->pData + pPage->pageSize - sizeof(SPageFtr));
|
||||
pPage->nOverflow = 0;
|
||||
pPage->xCellSize = xCellSize;
|
||||
|
||||
if (pPage->nOverflow || szCell + TDB_PAGE_OFFSET_SIZE(pPage) > pPage->nFree) {
|
||||
// TODO: need to figure out if pCell may be used by outside of this function
|
||||
j = pPage->nOverflow++;
|
||||
ASSERT((u8 *)pPage->pPageFtr == pPage->pFreeEnd);
|
||||
}
|
||||
|
||||
pPage->apOvfl[j] = pCell;
|
||||
pPage->aiOvfl[j] = idx;
|
||||
} else {
|
||||
ret = tdbPageAllocate(pPage, szCell, &pTarget);
|
||||
if (ret < 0) {
|
||||
return -1;
|
||||
void tdbPageInit(SPage *pPage, u8 szAmHdr, int (*xCellSize)(const SPage *, SCell *)) {
|
||||
pPage->pPageHdr = pPage->pData + szAmHdr;
|
||||
pPage->pCellIdx = pPage->pPageHdr + TDB_PAGE_HDR_SIZE(pPage);
|
||||
pPage->pFreeStart = pPage->pCellIdx + TDB_PAGE_OFFSET_SIZE(pPage) * TDB_PAGE_NCELLS(pPage);
|
||||
pPage->pFreeEnd = pPage->pData + TDB_PAGE_CCELLS(pPage);
|
||||
pPage->pPageFtr = (SPageFtr *)(pPage->pData + pPage->pageSize - sizeof(SPageFtr));
|
||||
pPage->nOverflow = 0;
|
||||
pPage->xCellSize = xCellSize;
|
||||
|
||||
ASSERT(pPage->pFreeEnd >= pPage->pFreeStart);
|
||||
ASSERT(pPage->pFreeEnd - pPage->pFreeStart <= TDB_PAGE_NFREE(pPage));
|
||||
}
|
||||
|
||||
int tdbPageInsertCell(SPage *pPage, int idx, SCell *pCell, int szCell, u8 asOvfl) {
|
||||
int nFree;
|
||||
int nCells;
|
||||
int iOvfl;
|
||||
int lidx; // local idx
|
||||
SCell *pNewCell;
|
||||
|
||||
ASSERT(szCell <= TDB_PAGE_MAX_FREE_BLOCK(pPage, pPage->pPageHdr - pPage->pData));
|
||||
|
||||
nFree = TDB_PAGE_NFREE(pPage);
|
||||
nCells = TDB_PAGE_NCELLS(pPage);
|
||||
iOvfl = 0;
|
||||
|
||||
for (; iOvfl < pPage->nOverflow; iOvfl++) {
|
||||
if (pPage->aiOvfl[iOvfl] >= idx) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
memcpy(pTarget, pCell, szCell);
|
||||
pTmp = pPage->pCellIdx + idx * TDB_PAGE_OFFSET_SIZE(pPage);
|
||||
memmove(pTmp + TDB_PAGE_OFFSET_SIZE(pPage), pTmp, pPage->pFreeStart - pTmp - TDB_PAGE_OFFSET_SIZE(pPage));
|
||||
TDB_PAGE_CELL_OFFSET_AT_SET(pPage, idx, pTarget - pPage->pData);
|
||||
TDB_PAGE_NCELLS_SET(pPage, TDB_PAGE_NCELLS(pPage) + 1);
|
||||
lidx = idx - iOvfl;
|
||||
|
||||
if (asOvfl || nFree < szCell + TDB_PAGE_OFFSET_SIZE(pPage)) {
|
||||
// TODO: make it extensible
|
||||
// add the cell as an overflow cell
|
||||
for (int i = pPage->nOverflow; i > iOvfl; i--) {
|
||||
pPage->apOvfl[i] = pPage->apOvfl[i - 1];
|
||||
pPage->aiOvfl[i] = pPage->aiOvfl[i - 1];
|
||||
}
|
||||
|
||||
// TODO: here has memory leak
|
||||
pNewCell = (SCell *)malloc(szCell);
|
||||
memcpy(pNewCell, pCell, szCell);
|
||||
|
||||
pPage->apOvfl[iOvfl] = pNewCell;
|
||||
pPage->aiOvfl[iOvfl] = idx;
|
||||
pPage->nOverflow++;
|
||||
iOvfl++;
|
||||
} else {
|
||||
// page must has enough space to hold the cell locally
|
||||
tdbPageAllocate(pPage, szCell, &pNewCell);
|
||||
|
||||
memcpy(pNewCell, pCell, szCell);
|
||||
|
||||
// no overflow cell exists in this page
|
||||
u8 *src = pPage->pCellIdx + TDB_PAGE_OFFSET_SIZE(pPage) * lidx;
|
||||
u8 *dest = src + TDB_PAGE_OFFSET_SIZE(pPage);
|
||||
memmove(dest, src, pPage->pFreeStart - dest);
|
||||
TDB_PAGE_CELL_OFFSET_AT_SET(pPage, lidx, pNewCell - pPage->pData);
|
||||
TDB_PAGE_NCELLS_SET(pPage, nCells + 1);
|
||||
|
||||
ASSERT(pPage->pFreeStart == pPage->pCellIdx + TDB_PAGE_OFFSET_SIZE(pPage) * (nCells + 1));
|
||||
}
|
||||
|
||||
for (; iOvfl < pPage->nOverflow; iOvfl++) {
|
||||
pPage->aiOvfl[iOvfl]++;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int tdbPageDropCell(SPage *pPage, int idx) {
|
||||
// TODO
|
||||
int lidx;
|
||||
SCell *pCell;
|
||||
int szCell;
|
||||
int nCells;
|
||||
int iOvfl;
|
||||
|
||||
nCells = TDB_PAGE_NCELLS(pPage);
|
||||
|
||||
ASSERT(idx >= 0 && idx < nCells + pPage->nOverflow);
|
||||
|
||||
iOvfl = 0;
|
||||
for (; iOvfl < pPage->nOverflow; iOvfl++) {
|
||||
if (pPage->aiOvfl[iOvfl] == idx) {
|
||||
// remove the over flow cell
|
||||
for (; (++iOvfl) < pPage->nOverflow;) {
|
||||
pPage->aiOvfl[iOvfl - 1] = pPage->aiOvfl[iOvfl] - 1;
|
||||
pPage->apOvfl[iOvfl - 1] = pPage->apOvfl[iOvfl];
|
||||
}
|
||||
|
||||
pPage->nOverflow--;
|
||||
return 0;
|
||||
} else if (pPage->aiOvfl[iOvfl] > idx) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
lidx = idx - iOvfl;
|
||||
pCell = TDB_PAGE_CELL_AT(pPage, lidx);
|
||||
szCell = (*pPage->xCellSize)(pPage, pCell);
|
||||
tdbPageFree(pPage, lidx, pCell, szCell);
|
||||
TDB_PAGE_NCELLS_SET(pPage, nCells - 1);
|
||||
|
||||
for (; iOvfl < pPage->nOverflow; iOvfl++) {
|
||||
pPage->aiOvfl[iOvfl]--;
|
||||
ASSERT(pPage->aiOvfl[iOvfl] > 0);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int tdbPageAllocate(SPage *pPage, int size, SCell **ppCell) {
|
||||
SCell *pCell;
|
||||
SFreeCell *pFreeCell;
|
||||
void tdbPageCopy(SPage *pFromPage, SPage *pToPage) {
|
||||
int delta, nFree;
|
||||
|
||||
pToPage->pFreeStart = pToPage->pPageHdr + (pFromPage->pFreeStart - pFromPage->pPageHdr);
|
||||
pToPage->pFreeEnd = (u8 *)(pToPage->pPageFtr) - ((u8 *)pFromPage->pPageFtr - pFromPage->pFreeEnd);
|
||||
|
||||
ASSERT(pToPage->pFreeEnd >= pToPage->pFreeStart);
|
||||
|
||||
memcpy(pToPage->pPageHdr, pFromPage->pPageHdr, pFromPage->pFreeStart - pFromPage->pPageHdr);
|
||||
memcpy(pToPage->pFreeEnd, pFromPage->pFreeEnd, (u8 *)pFromPage->pPageFtr - pFromPage->pFreeEnd);
|
||||
|
||||
ASSERT(TDB_PAGE_CCELLS(pToPage) == pToPage->pFreeEnd - pToPage->pData);
|
||||
|
||||
delta = (pToPage->pPageHdr - pToPage->pData) - (pFromPage->pPageHdr - pFromPage->pData);
|
||||
if (delta != 0) {
|
||||
nFree = TDB_PAGE_NFREE(pFromPage);
|
||||
TDB_PAGE_NFREE_SET(pToPage, nFree - delta);
|
||||
}
|
||||
|
||||
// Copy the overflow cells
|
||||
for (int iOvfl = 0; iOvfl < pFromPage->nOverflow; iOvfl++) {
|
||||
pToPage->aiOvfl[iOvfl] = pFromPage->aiOvfl[iOvfl];
|
||||
pToPage->apOvfl[iOvfl] = pFromPage->apOvfl[iOvfl];
|
||||
}
|
||||
pToPage->nOverflow = pFromPage->nOverflow;
|
||||
}
|
||||
|
||||
static int tdbPageAllocate(SPage *pPage, int szCell, SCell **ppCell) {
|
||||
SCell *pFreeCell;
|
||||
u8 *pOffset;
|
||||
int nFree;
|
||||
int ret;
|
||||
int cellFree;
|
||||
SCell *pCell = NULL;
|
||||
|
||||
ASSERT(pPage->nFree > size + TDB_PAGE_OFFSET_SIZE(pPage));
|
||||
|
||||
pCell = NULL;
|
||||
*ppCell = NULL;
|
||||
nFree = TDB_PAGE_NFREE(pPage);
|
||||
|
||||
// 1. Try to allocate from the free space area
|
||||
if (pPage->pFreeEnd - pPage->pFreeStart > size + TDB_PAGE_OFFSET_SIZE(pPage)) {
|
||||
pPage->pFreeEnd -= size;
|
||||
pPage->pFreeStart += TDB_PAGE_OFFSET_SIZE(pPage);
|
||||
ASSERT(nFree >= szCell + TDB_PAGE_OFFSET_SIZE(pPage));
|
||||
ASSERT(TDB_PAGE_CCELLS(pPage) == pPage->pFreeEnd - pPage->pData);
|
||||
|
||||
// 1. Try to allocate from the free space block area
|
||||
if (pPage->pFreeEnd - pPage->pFreeStart >= szCell + TDB_PAGE_OFFSET_SIZE(pPage)) {
|
||||
pPage->pFreeEnd -= szCell;
|
||||
pCell = pPage->pFreeEnd;
|
||||
TDB_PAGE_CCELLS_SET(pPage, pPage->pFreeEnd - pPage->pData);
|
||||
goto _alloc_finish;
|
||||
}
|
||||
|
||||
// 2. Try to allocate from the page free list
|
||||
if ((pCell == NULL) && (pPage->pFreeEnd - pPage->pFreeStart >= TDB_PAGE_OFFSET_SIZE(pPage)) &&
|
||||
TDB_PAGE_FCELL(pPage)) {
|
||||
#if 0
|
||||
int szCell;
|
||||
int nxOffset;
|
||||
|
||||
pCell = pPage->pData + TDB_PAGE_FCELL(pPage);
|
||||
pOffset = TDB_IS_LARGE_PAGE(pPage) ? ((SPageHdrL *)(pPage->pPageHdr))[0].fCell
|
||||
: (u8 *)&(((SPageHdr *)(pPage->pPageHdr))[0].fCell);
|
||||
szCell = TDB_PAGE_FREE_CELL_SIZE(pPage, pCell);
|
||||
nxOffset = TDB_PAGE_FREE_CELL_NXOFFSET(pPage, pCell);
|
||||
cellFree = TDB_PAGE_FCELL(pPage);
|
||||
ASSERT(cellFree == 0 || cellFree > pPage->pFreeEnd - pPage->pData);
|
||||
if (cellFree && pPage->pFreeEnd - pPage->pFreeStart >= TDB_PAGE_OFFSET_SIZE(pPage)) {
|
||||
SCell *pPrevFreeCell = NULL;
|
||||
int szPrevFreeCell;
|
||||
int szFreeCell;
|
||||
int nxFreeCell;
|
||||
int newSize;
|
||||
|
||||
for (;;) {
|
||||
// Find a cell
|
||||
if (szCell >= size) {
|
||||
if (szCell - size >= pPage->szFreeCell) {
|
||||
SCell *pTmpCell = pCell + size;
|
||||
if (cellFree == 0) break;
|
||||
|
||||
TDB_PAGE_FREE_CELL_SIZE_SET(pPage, pTmpCell, szCell - size);
|
||||
TDB_PAGE_FREE_CELL_NXOFFSET_SET(pPage, pTmpCell, nxOffset);
|
||||
// TODO: *pOffset = pTmpCell - pPage->pData;
|
||||
pFreeCell = pPage->pData + cellFree;
|
||||
pPage->pPageMethods->getFreeCellInfo(pFreeCell, &szFreeCell, &nxFreeCell);
|
||||
|
||||
if (szFreeCell >= szCell) {
|
||||
pCell = pFreeCell;
|
||||
|
||||
newSize = szFreeCell - szCell;
|
||||
pFreeCell += szCell;
|
||||
if (newSize >= TDB_PAGE_FREE_CELL_SIZE(pPage)) {
|
||||
pPage->pPageMethods->setFreeCellInfo(pFreeCell, newSize, nxFreeCell);
|
||||
if (pPrevFreeCell) {
|
||||
pPage->pPageMethods->setFreeCellInfo(pPrevFreeCell, szPrevFreeCell, pFreeCell - pPage->pData);
|
||||
} else {
|
||||
TDB_PAGE_NFREE_SET(pPage, TDB_PAGE_NFREE(pPage) + szCell - size);
|
||||
// TODO: *pOffset = nxOffset;
|
||||
TDB_PAGE_FCELL_SET(pPage, pFreeCell - pPage->pData);
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
// Not find a cell yet
|
||||
if (nxOffset > 0) {
|
||||
pCell = pPage->pData + nxOffset;
|
||||
pOffset = TDB_PAGE_FREE_CELL_NXOFFSET_PTR(pPage, pCell);
|
||||
szCell = TDB_PAGE_FREE_CELL_SIZE(pPage, pCell);
|
||||
nxOffset = TDB_PAGE_FREE_CELL_NXOFFSET(pPage, pCell);
|
||||
continue;
|
||||
} else {
|
||||
pCell = NULL;
|
||||
break;
|
||||
if (pPrevFreeCell) {
|
||||
pPage->pPageMethods->setFreeCellInfo(pPrevFreeCell, szPrevFreeCell, nxFreeCell);
|
||||
} else {
|
||||
TDB_PAGE_FCELL_SET(pPage, nxFreeCell);
|
||||
}
|
||||
}
|
||||
|
||||
if (pCell) {
|
||||
pPage->pFreeStart = pPage->pFreeStart + pPage->szOffset;
|
||||
goto _alloc_finish;
|
||||
} else {
|
||||
pPrevFreeCell = pFreeCell;
|
||||
szPrevFreeCell = szFreeCell;
|
||||
cellFree = nxFreeCell;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
// 3. Try to dfragment and allocate again
|
||||
if (pCell == NULL) {
|
||||
ret = tdbPageDefragment(pPage);
|
||||
if (ret < 0) {
|
||||
return -1;
|
||||
}
|
||||
tdbPageDefragment(pPage);
|
||||
ASSERT(pPage->pFreeEnd - pPage->pFreeStart == nFree);
|
||||
ASSERT(nFree == TDB_PAGE_NFREE(pPage));
|
||||
ASSERT(pPage->pFreeEnd - pPage->pData == TDB_PAGE_CCELLS(pPage));
|
||||
|
||||
ASSERT(pPage->pFreeEnd - pPage->pFreeStart > size + TDB_PAGE_OFFSET_SIZE(pPage));
|
||||
ASSERT(pPage->nFree == pPage->pFreeEnd - pPage->pFreeStart);
|
||||
|
||||
// Allocate from the free space area again
|
||||
pPage->pFreeEnd -= size;
|
||||
pPage->pFreeStart += TDB_PAGE_OFFSET_SIZE(pPage);
|
||||
pPage->pFreeEnd -= szCell;
|
||||
pCell = pPage->pFreeEnd;
|
||||
}
|
||||
TDB_PAGE_CCELLS_SET(pPage, pPage->pFreeEnd - pPage->pData);
|
||||
|
||||
ASSERT(pCell != NULL);
|
||||
|
||||
pPage->nFree = pPage->nFree - size - TDB_PAGE_OFFSET_SIZE(pPage);
|
||||
_alloc_finish:
|
||||
ASSERT(pCell);
|
||||
pPage->pFreeStart += TDB_PAGE_OFFSET_SIZE(pPage);
|
||||
TDB_PAGE_NFREE_SET(pPage, nFree - szCell - TDB_PAGE_OFFSET_SIZE(pPage));
|
||||
*ppCell = pCell;
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int tdbPageFree(SPage *pPage, int idx, SCell *pCell, int size) {
|
||||
// TODO
|
||||
static int tdbPageFree(SPage *pPage, int idx, SCell *pCell, int szCell) {
|
||||
int nFree;
|
||||
int cellFree;
|
||||
u8 *dest;
|
||||
u8 *src;
|
||||
|
||||
ASSERT(pCell >= pPage->pFreeEnd);
|
||||
ASSERT(pCell + szCell <= (u8 *)(pPage->pPageFtr));
|
||||
ASSERT(pCell == TDB_PAGE_CELL_AT(pPage, idx));
|
||||
|
||||
nFree = TDB_PAGE_NFREE(pPage);
|
||||
|
||||
if (pCell == pPage->pFreeEnd) {
|
||||
pPage->pFreeEnd += szCell;
|
||||
TDB_PAGE_CCELLS_SET(pPage, pPage->pFreeEnd - pPage->pData);
|
||||
} else {
|
||||
if (szCell >= TDB_PAGE_FREE_CELL_SIZE(pPage)) {
|
||||
cellFree = TDB_PAGE_FCELL(pPage);
|
||||
pPage->pPageMethods->setFreeCellInfo(pCell, szCell, cellFree);
|
||||
TDB_PAGE_FCELL_SET(pPage, pCell - pPage->pData);
|
||||
} else {
|
||||
ASSERT(0);
|
||||
}
|
||||
}
|
||||
|
||||
dest = pPage->pCellIdx + TDB_PAGE_OFFSET_SIZE(pPage) * idx;
|
||||
src = dest + TDB_PAGE_OFFSET_SIZE(pPage);
|
||||
memmove(dest, src, pPage->pFreeStart - src);
|
||||
|
||||
pPage->pFreeStart -= TDB_PAGE_OFFSET_SIZE(pPage);
|
||||
nFree = nFree + szCell + TDB_PAGE_OFFSET_SIZE(pPage);
|
||||
TDB_PAGE_NFREE_SET(pPage, nFree);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int tdbPageDefragment(SPage *pPage) {
|
||||
// TODO
|
||||
ASSERT(0);
|
||||
int nFree;
|
||||
int nCells;
|
||||
SCell *pCell;
|
||||
SCell *pNextCell;
|
||||
SCell *pTCell;
|
||||
int szCell;
|
||||
int idx;
|
||||
int iCell;
|
||||
|
||||
ASSERT(pPage->pFreeEnd - pPage->pFreeStart < nFree);
|
||||
|
||||
nFree = TDB_PAGE_NFREE(pPage);
|
||||
nCells = TDB_PAGE_NCELLS(pPage);
|
||||
|
||||
// Loop to compact the page content
|
||||
// Here we use an O(n^2) algorithm to do the job since
|
||||
// this is a low frequency job.
|
||||
pNextCell = (u8 *)pPage->pPageFtr;
|
||||
pCell = NULL;
|
||||
for (iCell = 0;; iCell++) {
|
||||
// compact over
|
||||
if (iCell == nCells) {
|
||||
pPage->pFreeEnd = pNextCell;
|
||||
break;
|
||||
}
|
||||
|
||||
for (int i = 0; i < nCells; i++) {
|
||||
if (TDB_PAGE_CELL_OFFSET_AT(pPage, i) < pNextCell - pPage->pData) {
|
||||
pTCell = TDB_PAGE_CELL_AT(pPage, i);
|
||||
if (pCell == NULL || pCell < pTCell) {
|
||||
pCell = pTCell;
|
||||
idx = i;
|
||||
}
|
||||
} else {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
ASSERT(pCell != NULL);
|
||||
|
||||
szCell = (*pPage->xCellSize)(pPage, pCell);
|
||||
|
||||
ASSERT(pCell + szCell <= pNextCell);
|
||||
if (pCell + szCell < pNextCell) {
|
||||
memmove(pNextCell - szCell, pCell, szCell);
|
||||
}
|
||||
|
||||
pCell = NULL;
|
||||
pNextCell = pNextCell - szCell;
|
||||
TDB_PAGE_CELL_OFFSET_AT_SET(pPage, idx, pNextCell - pPage->pData);
|
||||
}
|
||||
|
||||
ASSERT(pPage->pFreeEnd - pPage->pFreeStart == nFree);
|
||||
TDB_PAGE_CCELLS_SET(pPage, pPage->pFreeEnd - pPage->pData);
|
||||
TDB_PAGE_FCELL_SET(pPage, 0);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* ---------------------------------------------------------------------------------------------------------- */
|
||||
typedef struct __attribute__((__packed__)) {
|
||||
u16 flags;
|
||||
u16 cellNum;
|
||||
u16 cellBody;
|
||||
u16 cellFree;
|
||||
u16 nFree;
|
||||
} SPageHdr;
|
||||
|
||||
// flags
|
||||
static inline u16 getPageFlags(SPage *pPage) { return ((SPageHdr *)(pPage->pPageHdr))[0].flags; }
|
||||
static inline void setPageFlags(SPage *pPage, u16 flags) { ((SPageHdr *)(pPage->pPageHdr))[0].flags = flags; }
|
||||
typedef struct __attribute__((__packed__)) {
|
||||
u16 szCell;
|
||||
u16 nxOffset;
|
||||
} SFreeCell;
|
||||
|
||||
// cellNum
|
||||
static inline int getPageCellNum(SPage *pPage) { return ((SPageHdr *)(pPage->pPageHdr))[0].cellNum; }
|
||||
|
@ -253,12 +474,23 @@ static inline void setPageCellOffset(SPage *pPage, int idx, int offset) {
|
|||
((u16 *)pPage->pCellIdx)[idx] = (u16)offset;
|
||||
}
|
||||
|
||||
// free cell info
|
||||
static inline void getPageFreeCellInfo(SCell *pCell, int *szCell, int *nxOffset) {
|
||||
SFreeCell *pFreeCell = (SFreeCell *)pCell;
|
||||
*szCell = pFreeCell->szCell;
|
||||
*nxOffset = pFreeCell->nxOffset;
|
||||
}
|
||||
|
||||
static inline void setPageFreeCellInfo(SCell *pCell, int szCell, int nxOffset) {
|
||||
SFreeCell *pFreeCell = (SFreeCell *)pCell;
|
||||
pFreeCell->szCell = szCell;
|
||||
pFreeCell->nxOffset = nxOffset;
|
||||
}
|
||||
|
||||
SPageMethods pageMethods = {
|
||||
2, // szOffset
|
||||
sizeof(SPageHdr), // szPageHdr
|
||||
sizeof(SFreeCell), // szFreeCell
|
||||
getPageFlags, // getPageFlags
|
||||
setPageFlags, // setFlagsp
|
||||
getPageCellNum, // getCellNum
|
||||
setPageCellNum, // setCellNum
|
||||
getPageCellBody, // getCellBody
|
||||
|
@ -268,5 +500,7 @@ SPageMethods pageMethods = {
|
|||
getPageNFree, // getFreeBytes
|
||||
setPageNFree, // setFreeBytes
|
||||
getPageCellOffset, // getCellOffset
|
||||
setPageCellOffset // setCellOffset
|
||||
setPageCellOffset, // setCellOffset
|
||||
getPageFreeCellInfo, // getFreeCellInfo
|
||||
setPageFreeCellInfo // setFreeCellInfo
|
||||
};
|
|
@ -16,7 +16,6 @@
|
|||
#include "tdbInt.h"
|
||||
|
||||
typedef struct __attribute__((__packed__)) {
|
||||
u16 flags;
|
||||
u8 cellNum[3];
|
||||
u8 cellBody[3];
|
||||
u8 cellFree[3];
|
||||
|
@ -28,10 +27,6 @@ typedef struct __attribute__((__packed__)) {
|
|||
u8 nxOffset[3];
|
||||
} SFreeCellL;
|
||||
|
||||
// flags
|
||||
static inline u16 getPageFlags(SPage *pPage) { return ((SPageHdrL *)(pPage->pPageHdr))[0].flags; }
|
||||
static inline void setPageFlags(SPage *pPage, u16 flags) { ((SPageHdrL *)(pPage->pPageHdr))[0].flags = flags; }
|
||||
|
||||
// cellNum
|
||||
static inline int getPageCellNum(SPage *pPage) { return TDB_GET_U24(((SPageHdrL *)(pPage->pPageHdr))[0].cellNum); }
|
||||
static inline void setPageCellNum(SPage *pPage, int cellNum) {
|
||||
|
@ -66,12 +61,23 @@ static inline void setPageCellOffset(SPage *pPage, int idx, int offset) {
|
|||
TDB_PUT_U24(pPage->pCellIdx + 3 * idx, offset);
|
||||
}
|
||||
|
||||
// free cell info
|
||||
static inline void getPageFreeCellInfo(SCell *pCell, int *szCell, int *nxOffset) {
|
||||
SFreeCellL *pFreeCell = (SFreeCellL *)pCell;
|
||||
*szCell = TDB_GET_U24(pFreeCell->szCell);
|
||||
*nxOffset = TDB_GET_U24(pFreeCell->nxOffset);
|
||||
}
|
||||
|
||||
static inline void setPageFreeCellInfo(SCell *pCell, int szCell, int nxOffset) {
|
||||
SFreeCellL *pFreeCell = (SFreeCellL *)pCell;
|
||||
TDB_PUT_U24(pFreeCell->szCell, szCell);
|
||||
TDB_PUT_U24(pFreeCell->nxOffset, nxOffset);
|
||||
}
|
||||
|
||||
SPageMethods pageLargeMethods = {
|
||||
3, // szOffset
|
||||
sizeof(SPageHdrL), // szPageHdr
|
||||
sizeof(SFreeCellL), // szFreeCell
|
||||
getPageFlags, // getPageFlags
|
||||
setPageFlags, // setFlagsp
|
||||
getPageCellNum, // getCellNum
|
||||
setPageCellNum, // setCellNum
|
||||
getPageCellBody, // getCellBody
|
||||
|
@ -81,5 +87,7 @@ SPageMethods pageLargeMethods = {
|
|||
getPageNFree, // getFreeBytes
|
||||
setPageNFree, // setFreeBytes
|
||||
getPageCellOffset, // getCellOffset
|
||||
setPageCellOffset // setCellOffset
|
||||
setPageCellOffset, // setCellOffset
|
||||
getPageFreeCellInfo, // getFreeCellInfo
|
||||
setPageFreeCellInfo // setFreeCellInfo
|
||||
};
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue