Merge branch 'develop' into coverity_scan
This commit is contained in:
commit
4edf364dac
16
.travis.yml
16
.travis.yml
|
@ -13,7 +13,7 @@ branches:
|
||||||
|
|
||||||
matrix:
|
matrix:
|
||||||
- os: linux
|
- os: linux
|
||||||
dist: bionic
|
dist: focal
|
||||||
language: c
|
language: c
|
||||||
|
|
||||||
git:
|
git:
|
||||||
|
@ -28,8 +28,6 @@ matrix:
|
||||||
- build-essential
|
- build-essential
|
||||||
- cmake
|
- cmake
|
||||||
- net-tools
|
- net-tools
|
||||||
- python-pip
|
|
||||||
- python-setuptools
|
|
||||||
- python3-pip
|
- python3-pip
|
||||||
- python3-setuptools
|
- python3-setuptools
|
||||||
- valgrind
|
- valgrind
|
||||||
|
@ -54,13 +52,19 @@ matrix:
|
||||||
cd ${TRAVIS_BUILD_DIR}/debug
|
cd ${TRAVIS_BUILD_DIR}/debug
|
||||||
make install > /dev/null || travis_terminate $?
|
make install > /dev/null || travis_terminate $?
|
||||||
|
|
||||||
pip install numpy
|
|
||||||
pip install --user ${TRAVIS_BUILD_DIR}/src/connector/python/linux/python2/
|
|
||||||
pip3 install numpy
|
pip3 install numpy
|
||||||
pip3 install --user ${TRAVIS_BUILD_DIR}/src/connector/python/linux/python3/
|
pip3 install --user ${TRAVIS_BUILD_DIR}/src/connector/python/linux/python3/
|
||||||
|
|
||||||
cd ${TRAVIS_BUILD_DIR}/tests
|
cd ${TRAVIS_BUILD_DIR}/tests
|
||||||
./test-all.sh smoke || travis_terminate $?
|
./test-all.sh smoke || travis_terminate $?
|
||||||
|
sleep 1
|
||||||
|
|
||||||
|
cd ${TRAVIS_BUILD_DIR}/tests/pytest
|
||||||
|
pkill -TERM -x taosd
|
||||||
|
fuser -k -n tcp 6030
|
||||||
|
sleep 1
|
||||||
|
./crash_gen.sh -a -p -t 4 -s 25|| travis_terminate $?
|
||||||
|
sleep 1
|
||||||
|
|
||||||
cd ${TRAVIS_BUILD_DIR}/tests/pytest
|
cd ${TRAVIS_BUILD_DIR}/tests/pytest
|
||||||
./valgrind-test.sh 2>&1 > mem-error-out.log
|
./valgrind-test.sh 2>&1 > mem-error-out.log
|
||||||
|
@ -160,7 +164,7 @@ matrix:
|
||||||
|
|
||||||
script:
|
script:
|
||||||
- cmake .. > /dev/null
|
- cmake .. > /dev/null
|
||||||
- make > /dev/null
|
- make
|
||||||
|
|
||||||
- os: linux
|
- os: linux
|
||||||
dist: bionic
|
dist: bionic
|
||||||
|
|
|
@ -480,9 +480,9 @@ TDengine支持针对数据的聚合查询。提供支持的聚合和选择函数
|
||||||
|
|
||||||
- **LEASTSQUARES**
|
- **LEASTSQUARES**
|
||||||
```mysql
|
```mysql
|
||||||
SELECT LEASTSQUARES(field_name) FROM tb_name [WHERE clause]
|
SELECT LEASTSQUARES(field_name, start_val, step_val) FROM tb_name [WHERE clause]
|
||||||
```
|
```
|
||||||
功能说明:统计表中某列的值是主键(时间戳)的拟合直线方程。
|
功能说明:统计表中某列的值是主键(时间戳)的拟合直线方程。start_val是自变量初始值,step_val是自变量的步长值。
|
||||||
返回结果数据类型:字符串表达式(斜率, 截距)。
|
返回结果数据类型:字符串表达式(斜率, 截距)。
|
||||||
应用字段:不能应用在timestamp、binary、nchar、bool类型字段。
|
应用字段:不能应用在timestamp、binary、nchar、bool类型字段。
|
||||||
说明:自变量是时间戳,因变量是该列的值。
|
说明:自变量是时间戳,因变量是该列的值。
|
||||||
|
|
|
@ -412,7 +412,7 @@ TDengine supports aggregations over numerical values, they are listed below:
|
||||||
SELECT PERCENTILE(field_name, P) FROM { tb_name | stb_name } [WHERE clause]
|
SELECT PERCENTILE(field_name, P) FROM { tb_name | stb_name } [WHERE clause]
|
||||||
```
|
```
|
||||||
Function: the value of the specified column below which `P` percent of the data points fall.
|
Function: the value of the specified column below which `P` percent of the data points fall.
|
||||||
Return Data Type: the same data type.
|
Return Data Type: double.
|
||||||
Applicable Data Types: all types except `timestamp`, `binary`, `nchar`, `bool`.
|
Applicable Data Types: all types except `timestamp`, `binary`, `nchar`, `bool`.
|
||||||
Applied to: table/STable.
|
Applied to: table/STable.
|
||||||
Note: The range of `P` is `[0, 100]`. When `P=0` , `PERCENTILE` returns the equal value as `MIN`; when `P=100`, `PERCENTILE` returns the equal value as `MAX`.
|
Note: The range of `P` is `[0, 100]`. When `P=0` , `PERCENTILE` returns the equal value as `MIN`; when `P=100`, `PERCENTILE` returns the equal value as `MAX`.
|
||||||
|
@ -446,7 +446,7 @@ TDengine supports aggregations over numerical values, they are listed below:
|
||||||
SELECT SPREAD(field_name) FROM { tb_name | stb_name } [WHERE clause]
|
SELECT SPREAD(field_name) FROM { tb_name | stb_name } [WHERE clause]
|
||||||
```
|
```
|
||||||
Function: return the difference between the maximum and the mimimum value.
|
Function: return the difference between the maximum and the mimimum value.
|
||||||
Return Data Type: the same data type.
|
Return Data Type: double.
|
||||||
Applicable Data Types: all types except `timestamp`, `binary`, `nchar`, `bool`.
|
Applicable Data Types: all types except `timestamp`, `binary`, `nchar`, `bool`.
|
||||||
Applied to: table/STable.
|
Applied to: table/STable.
|
||||||
Note: spread gives the range of data variation in a table/supertable; it is equivalent to `MAX()` - `MIN()`
|
Note: spread gives the range of data variation in a table/supertable; it is equivalent to `MAX()` - `MIN()`
|
||||||
|
|
|
@ -18,7 +18,7 @@ import (
|
||||||
"sync"
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
_ "github.com/taosdata/TDengine/src/connector/go/taosSql"
|
_ "github.com/taosdata/driver-go/taosSql"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
|
|
|
@ -31,9 +31,7 @@ extern int32_t tscEmbedded;
|
||||||
#define tscInfo(...) { if (cDebugFlag & DEBUG_INFO) { taosPrintLog("TSC INFO ", tscEmbedded ? 255 : cDebugFlag, __VA_ARGS__); }}
|
#define tscInfo(...) { if (cDebugFlag & DEBUG_INFO) { taosPrintLog("TSC INFO ", tscEmbedded ? 255 : cDebugFlag, __VA_ARGS__); }}
|
||||||
#define tscDebug(...) { if (cDebugFlag & DEBUG_DEBUG) { taosPrintLog("TSC DEBUG ", cDebugFlag, __VA_ARGS__); }}
|
#define tscDebug(...) { if (cDebugFlag & DEBUG_DEBUG) { taosPrintLog("TSC DEBUG ", cDebugFlag, __VA_ARGS__); }}
|
||||||
#define tscTrace(...) { if (cDebugFlag & DEBUG_TRACE) { taosPrintLog("TSC TRACE ", cDebugFlag, __VA_ARGS__); }}
|
#define tscTrace(...) { if (cDebugFlag & DEBUG_TRACE) { taosPrintLog("TSC TRACE ", cDebugFlag, __VA_ARGS__); }}
|
||||||
|
#define tscDebugL(...){ if (cDebugFlag & DEBUG_DEBUG) { taosPrintLongString("TSC DEBUG ", cDebugFlag, __VA_ARGS__); }}
|
||||||
#define tscDebugDump(...) { if (cDebugFlag & DEBUG_DEBUG) { taosPrintLongString("TSC DEBUG ", cDebugFlag, __VA_ARGS__); }}
|
|
||||||
#define tscTraceDump(...) { if (cDebugFlag & DEBUG_TRACE) { taosPrintLongString("TSC TRACE ", cDebugFlag, __VA_ARGS__); }}
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
|
|
|
@ -87,6 +87,16 @@ typedef struct SVgroupTableInfo {
|
||||||
SArray* itemList; //SArray<STableIdInfo>
|
SArray* itemList; //SArray<STableIdInfo>
|
||||||
} SVgroupTableInfo;
|
} SVgroupTableInfo;
|
||||||
|
|
||||||
|
static FORCE_INLINE SQueryInfo* tscGetQueryInfoDetail(SSqlCmd* pCmd, int32_t subClauseIndex) {
|
||||||
|
assert(pCmd != NULL && subClauseIndex >= 0 && subClauseIndex < TSDB_MAX_UNION_CLAUSE);
|
||||||
|
|
||||||
|
if (pCmd->pQueryInfo == NULL || subClauseIndex >= pCmd->numOfClause) {
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
return pCmd->pQueryInfo[subClauseIndex];
|
||||||
|
}
|
||||||
|
|
||||||
int32_t tscCreateDataBlock(size_t initialSize, int32_t rowSize, int32_t startOffset, const char* name,
|
int32_t tscCreateDataBlock(size_t initialSize, int32_t rowSize, int32_t startOffset, const char* name,
|
||||||
STableMeta* pTableMeta, STableDataBlocks** dataBlocks);
|
STableMeta* pTableMeta, STableDataBlocks** dataBlocks);
|
||||||
void tscDestroyDataBlock(STableDataBlocks* pDataBlock);
|
void tscDestroyDataBlock(STableDataBlocks* pDataBlock);
|
||||||
|
|
|
@ -110,8 +110,6 @@ STableMeta* tscCreateTableMetaFromMsg(STableMetaMsg* pTableMetaMsg, size_t* size
|
||||||
//todo tags value as well as the table id structure needs refactor
|
//todo tags value as well as the table id structure needs refactor
|
||||||
char *tsGetTagsValue(STableMeta *pMeta);
|
char *tsGetTagsValue(STableMeta *pMeta);
|
||||||
|
|
||||||
void extractTableNameFromToken(SSQLToken *pToken, SSQLToken* pTable);
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -320,6 +320,8 @@ typedef struct SSqlStream {
|
||||||
SSqlObj *pSql;
|
SSqlObj *pSql;
|
||||||
uint32_t streamId;
|
uint32_t streamId;
|
||||||
char listed;
|
char listed;
|
||||||
|
bool isProject;
|
||||||
|
int16_t precision;
|
||||||
int64_t num; // number of computing count
|
int64_t num; // number of computing count
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -334,7 +336,6 @@ typedef struct SSqlStream {
|
||||||
int64_t etime; // stream end query time, when time is larger then etime, the stream will be closed
|
int64_t etime; // stream end query time, when time is larger then etime, the stream will be closed
|
||||||
int64_t interval;
|
int64_t interval;
|
||||||
int64_t slidingTime;
|
int64_t slidingTime;
|
||||||
int16_t precision;
|
|
||||||
void * pTimer;
|
void * pTimer;
|
||||||
|
|
||||||
void (*fp)();
|
void (*fp)();
|
||||||
|
|
|
@ -29,9 +29,6 @@
|
||||||
#define jniDebug(...) { if (jniDebugFlag & DEBUG_DEBUG) { taosPrintLog("JNI DEBUG ", jniDebugFlag, __VA_ARGS__); }}
|
#define jniDebug(...) { if (jniDebugFlag & DEBUG_DEBUG) { taosPrintLog("JNI DEBUG ", jniDebugFlag, __VA_ARGS__); }}
|
||||||
#define jniTrace(...) { if (jniDebugFlag & DEBUG_TRACE) { taosPrintLog("JNI TRACE ", jniDebugFlag, __VA_ARGS__); }}
|
#define jniTrace(...) { if (jniDebugFlag & DEBUG_TRACE) { taosPrintLog("JNI TRACE ", jniDebugFlag, __VA_ARGS__); }}
|
||||||
|
|
||||||
#define jniDebugDump(...) { if (jniDebugFlag & DEBUG_DEBUG) { taosPrintLongString("JNI DEBUG ", jniDebugFlag, __VA_ARGS__); }}
|
|
||||||
#define jniTraceDump(...) { if (jniDebugFlag & DEBUG_TRACE) { taosPrintLongString("JNI DEBUG ", jniDebugFlag, __VA_ARGS__); }}
|
|
||||||
|
|
||||||
int __init = 0;
|
int __init = 0;
|
||||||
|
|
||||||
JavaVM *g_vm = NULL;
|
JavaVM *g_vm = NULL;
|
||||||
|
|
|
@ -55,7 +55,7 @@ void doAsyncQuery(STscObj* pObj, SSqlObj* pSql, void (*fp)(), void* param, const
|
||||||
|
|
||||||
strtolower(pSql->sqlstr, sqlstr);
|
strtolower(pSql->sqlstr, sqlstr);
|
||||||
|
|
||||||
tscDebugDump("%p SQL: %s", pSql, pSql->sqlstr);
|
tscDebugL("%p SQL: %s", pSql, pSql->sqlstr);
|
||||||
pSql->cmd.curSql = pSql->sqlstr;
|
pSql->cmd.curSql = pSql->sqlstr;
|
||||||
|
|
||||||
int32_t code = tsParseSql(pSql, true);
|
int32_t code = tsParseSql(pSql, true);
|
||||||
|
@ -471,13 +471,19 @@ void tscTableMetaCallBack(void *param, TAOS_RES *res, int code) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// in case of insert, redo parsing the sql string and build new submit data block for two reasons:
|
// in case of insert, redo parsing the sql string and build new submit data block for two reasons:
|
||||||
// 1. the table Id(tid & uid) may have been update, the submit block needs to be updated
|
// 1. the table Id(tid & uid) may have been update, the submit block needs to be updated accordingly.
|
||||||
// 2. vnode may need the schema information along with submit block to update its local table schema.
|
// 2. vnode may need the schema information along with submit block to update its local table schema.
|
||||||
if (pCmd->command == TSDB_SQL_INSERT) {
|
if (pCmd->command == TSDB_SQL_INSERT) {
|
||||||
tscDebug("%p redo parse sql string to build submit block", pSql);
|
tscDebug("%p redo parse sql string to build submit block", pSql);
|
||||||
|
|
||||||
pCmd->parseFinished = false;
|
pCmd->parseFinished = false;
|
||||||
if ((code = tsParseSql(pSql, true)) == TSDB_CODE_SUCCESS) {
|
code = tsParseSql(pSql, true);
|
||||||
|
|
||||||
|
if (code == TSDB_CODE_TSC_ACTION_IN_PROGRESS) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (code == TSDB_CODE_SUCCESS) {
|
||||||
/*
|
/*
|
||||||
* Discard previous built submit blocks, and then parse the sql string again and build up all submit blocks,
|
* Discard previous built submit blocks, and then parse the sql string again and build up all submit blocks,
|
||||||
* and send the required submit block according to index value in supporter to server.
|
* and send the required submit block according to index value in supporter to server.
|
||||||
|
|
|
@ -14,7 +14,6 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "os.h"
|
#include "os.h"
|
||||||
#include "qast.h"
|
|
||||||
#include "qextbuffer.h"
|
#include "qextbuffer.h"
|
||||||
#include "qfill.h"
|
#include "qfill.h"
|
||||||
#include "qhistogram.h"
|
#include "qhistogram.h"
|
||||||
|
@ -23,6 +22,7 @@
|
||||||
#include "qtsbuf.h"
|
#include "qtsbuf.h"
|
||||||
#include "taosdef.h"
|
#include "taosdef.h"
|
||||||
#include "taosmsg.h"
|
#include "taosmsg.h"
|
||||||
|
#include "qast.h"
|
||||||
#include "tscLog.h"
|
#include "tscLog.h"
|
||||||
#include "tscSubquery.h"
|
#include "tscSubquery.h"
|
||||||
#include "tscompression.h"
|
#include "tscompression.h"
|
||||||
|
@ -340,13 +340,12 @@ bool stableQueryFunctChanged(int32_t funcId) {
|
||||||
*/
|
*/
|
||||||
void resetResultInfo(SResultInfo *pResInfo) { pResInfo->initialized = false; }
|
void resetResultInfo(SResultInfo *pResInfo) { pResInfo->initialized = false; }
|
||||||
|
|
||||||
void setResultInfoBuf(SResultInfo *pResInfo, int32_t size, bool superTable) {
|
void setResultInfoBuf(SResultInfo *pResInfo, int32_t size, bool superTable, char* buf) {
|
||||||
assert(pResInfo->interResultBuf == NULL);
|
assert(pResInfo->interResultBuf == NULL);
|
||||||
|
|
||||||
pResInfo->bufLen = size;
|
pResInfo->bufLen = size;
|
||||||
pResInfo->superTableQ = superTable;
|
pResInfo->superTableQ = superTable;
|
||||||
|
pResInfo->interResultBuf = buf;
|
||||||
pResInfo->interResultBuf = calloc(1, (size_t)size);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// set the query flag to denote that query is completed
|
// set the query flag to denote that query is completed
|
||||||
|
|
|
@ -406,7 +406,7 @@ int tscProcessLocalCmd(SSqlObj *pSql) {
|
||||||
pSql->res.qhandle = 0x1;
|
pSql->res.qhandle = 0x1;
|
||||||
pSql->res.numOfRows = 0;
|
pSql->res.numOfRows = 0;
|
||||||
} else if (pCmd->command == TSDB_SQL_RESET_CACHE) {
|
} else if (pCmd->command == TSDB_SQL_RESET_CACHE) {
|
||||||
taosCacheEmpty(tscCacheHandle,false);
|
taosCacheEmpty(tscCacheHandle);
|
||||||
} else if (pCmd->command == TSDB_SQL_SERV_VERSION) {
|
} else if (pCmd->command == TSDB_SQL_SERV_VERSION) {
|
||||||
tscProcessServerVer(pSql);
|
tscProcessServerVer(pSql);
|
||||||
} else if (pCmd->command == TSDB_SQL_CLI_VERSION) {
|
} else if (pCmd->command == TSDB_SQL_CLI_VERSION) {
|
||||||
|
|
|
@ -274,6 +274,10 @@ void tscCreateLocalReducer(tExtMemBuffer **pMemBuffer, int32_t numOfBuffer, tOrd
|
||||||
pReducer->numOfBuffer = idx;
|
pReducer->numOfBuffer = idx;
|
||||||
|
|
||||||
SCompareParam *param = malloc(sizeof(SCompareParam));
|
SCompareParam *param = malloc(sizeof(SCompareParam));
|
||||||
|
if (param == NULL) {
|
||||||
|
tfree(pReducer);
|
||||||
|
return;
|
||||||
|
}
|
||||||
param->pLocalData = pReducer->pLocalDataSrc;
|
param->pLocalData = pReducer->pLocalDataSrc;
|
||||||
param->pDesc = pReducer->pDesc;
|
param->pDesc = pReducer->pDesc;
|
||||||
param->num = pReducer->pLocalDataSrc[0]->pMemBuffer->numOfElemsPerPage;
|
param->num = pReducer->pLocalDataSrc[0]->pMemBuffer->numOfElemsPerPage;
|
||||||
|
@ -284,6 +288,7 @@ void tscCreateLocalReducer(tExtMemBuffer **pMemBuffer, int32_t numOfBuffer, tOrd
|
||||||
|
|
||||||
pRes->code = tLoserTreeCreate(&pReducer->pLoserTree, pReducer->numOfBuffer, param, treeComparator);
|
pRes->code = tLoserTreeCreate(&pReducer->pLoserTree, pReducer->numOfBuffer, param, treeComparator);
|
||||||
if (pReducer->pLoserTree == NULL || pRes->code != 0) {
|
if (pReducer->pLoserTree == NULL || pRes->code != 0) {
|
||||||
|
tfree(param);
|
||||||
tfree(pReducer);
|
tfree(pReducer);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -332,6 +337,8 @@ void tscCreateLocalReducer(tExtMemBuffer **pMemBuffer, int32_t numOfBuffer, tOrd
|
||||||
tfree(pReducer->pResultBuf);
|
tfree(pReducer->pResultBuf);
|
||||||
tfree(pReducer->pFinalRes);
|
tfree(pReducer->pFinalRes);
|
||||||
tfree(pReducer->prevRowOfInput);
|
tfree(pReducer->prevRowOfInput);
|
||||||
|
tfree(pReducer->pLoserTree);
|
||||||
|
tfree(param);
|
||||||
tfree(pReducer);
|
tfree(pReducer);
|
||||||
pRes->code = TSDB_CODE_TSC_OUT_OF_MEMORY;
|
pRes->code = TSDB_CODE_TSC_OUT_OF_MEMORY;
|
||||||
return;
|
return;
|
||||||
|
@ -364,7 +371,7 @@ void tscCreateLocalReducer(tExtMemBuffer **pMemBuffer, int32_t numOfBuffer, tOrd
|
||||||
|
|
||||||
TSKEY stime = MIN(pQueryInfo->window.skey, pQueryInfo->window.ekey);
|
TSKEY stime = MIN(pQueryInfo->window.skey, pQueryInfo->window.ekey);
|
||||||
int64_t revisedSTime =
|
int64_t revisedSTime =
|
||||||
taosGetIntervalStartTimestamp(stime, pQueryInfo->intervalTime, pQueryInfo->slidingTimeUnit, tinfo.precision);
|
taosGetIntervalStartTimestamp(stime, pQueryInfo->slidingTime, pQueryInfo->intervalTime, pQueryInfo->slidingTimeUnit, tinfo.precision);
|
||||||
|
|
||||||
if (pQueryInfo->fillType != TSDB_FILL_NONE) {
|
if (pQueryInfo->fillType != TSDB_FILL_NONE) {
|
||||||
SFillColInfo* pFillCol = createFillColInfo(pQueryInfo);
|
SFillColInfo* pFillCol = createFillColInfo(pQueryInfo);
|
||||||
|
@ -831,7 +838,7 @@ void savePrevRecordAndSetupInterpoInfo(SLocalReducer *pLocalReducer, SQueryInfo
|
||||||
if (pFillInfo != NULL) {
|
if (pFillInfo != NULL) {
|
||||||
int64_t stime = (pQueryInfo->window.skey < pQueryInfo->window.ekey) ? pQueryInfo->window.skey : pQueryInfo->window.ekey;
|
int64_t stime = (pQueryInfo->window.skey < pQueryInfo->window.ekey) ? pQueryInfo->window.skey : pQueryInfo->window.ekey;
|
||||||
int64_t revisedSTime =
|
int64_t revisedSTime =
|
||||||
taosGetIntervalStartTimestamp(stime, pQueryInfo->slidingTime, pQueryInfo->slidingTimeUnit, tinfo.precision);
|
taosGetIntervalStartTimestamp(stime, pQueryInfo->slidingTime, pQueryInfo->intervalTime, pQueryInfo->slidingTimeUnit, tinfo.precision);
|
||||||
|
|
||||||
taosResetFillInfo(pFillInfo, revisedSTime);
|
taosResetFillInfo(pFillInfo, revisedSTime);
|
||||||
}
|
}
|
||||||
|
@ -1301,9 +1308,7 @@ static void resetEnvForNewResultset(SSqlRes *pRes, SSqlCmd *pCmd, SLocalReducer
|
||||||
if (pQueryInfo->fillType != TSDB_FILL_NONE) {
|
if (pQueryInfo->fillType != TSDB_FILL_NONE) {
|
||||||
TSKEY skey = MIN(pQueryInfo->window.skey, pQueryInfo->window.ekey);
|
TSKEY skey = MIN(pQueryInfo->window.skey, pQueryInfo->window.ekey);
|
||||||
int64_t newTime =
|
int64_t newTime =
|
||||||
taosGetIntervalStartTimestamp(skey, pQueryInfo->intervalTime, pQueryInfo->slidingTimeUnit, precision);
|
taosGetIntervalStartTimestamp(skey, pQueryInfo->slidingTime, pQueryInfo->intervalTime, pQueryInfo->slidingTimeUnit, precision);
|
||||||
// taosResetFillInfo(pLocalReducer->pFillInfo, pQueryInfo->order.order, newTime,
|
|
||||||
// pQueryInfo->groupbyExpr.numOfGroupCols, 4096, 0, NULL, pLocalReducer->rowSize);
|
|
||||||
taosResetFillInfo(pLocalReducer->pFillInfo, newTime);
|
taosResetFillInfo(pLocalReducer->pFillInfo, newTime);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1310,6 +1310,11 @@ int tsParseSql(SSqlObj *pSql, bool initial) {
|
||||||
tscDebug("%p resume to parse sql: %s", pSql, pCmd->curSql);
|
tscDebug("%p resume to parse sql: %s", pSql, pCmd->curSql);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ret = tscAllocPayload(&pSql->cmd, TSDB_DEFAULT_PAYLOAD_SIZE);
|
||||||
|
if (TSDB_CODE_SUCCESS != ret) {
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
if (tscIsInsertData(pSql->sqlstr)) {
|
if (tscIsInsertData(pSql->sqlstr)) {
|
||||||
/*
|
/*
|
||||||
* Set the fp before parse the sql string, in case of getTableMeta failed, in which
|
* Set the fp before parse the sql string, in case of getTableMeta failed, in which
|
||||||
|
@ -1326,11 +1331,6 @@ int tsParseSql(SSqlObj *pSql, bool initial) {
|
||||||
|
|
||||||
ret = tsParseInsertSql(pSql);
|
ret = tsParseInsertSql(pSql);
|
||||||
} else {
|
} else {
|
||||||
ret = tscAllocPayload(&pSql->cmd, TSDB_DEFAULT_PAYLOAD_SIZE);
|
|
||||||
if (TSDB_CODE_SUCCESS != ret) {
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
SSqlInfo SQLInfo = qSQLParse(pSql->sqlstr);
|
SSqlInfo SQLInfo = qSQLParse(pSql->sqlstr);
|
||||||
ret = tscToSQLCmd(pSql, &SQLInfo);
|
ret = tscToSQLCmd(pSql, &SQLInfo);
|
||||||
SQLInfoDestroy(&SQLInfo);
|
SQLInfoDestroy(&SQLInfo);
|
||||||
|
|
|
@ -538,7 +538,7 @@ int taos_stmt_prepare(TAOS_STMT* stmt, const char* sql, unsigned long length) {
|
||||||
pRes->numOfRows = 1;
|
pRes->numOfRows = 1;
|
||||||
|
|
||||||
strtolower(pSql->sqlstr, sql);
|
strtolower(pSql->sqlstr, sql);
|
||||||
tscDebugDump("%p SQL: %s", pSql, pSql->sqlstr);
|
tscDebugL("%p SQL: %s", pSql, pSql->sqlstr);
|
||||||
|
|
||||||
if (tscIsInsertData(pSql->sqlstr)) {
|
if (tscIsInsertData(pSql->sqlstr)) {
|
||||||
pStmt->isInsert = true;
|
pStmt->isInsert = true;
|
||||||
|
|
|
@ -18,19 +18,19 @@
|
||||||
#define _DEFAULT_SOURCE
|
#define _DEFAULT_SOURCE
|
||||||
|
|
||||||
#include "os.h"
|
#include "os.h"
|
||||||
#include "qast.h"
|
|
||||||
#include "taos.h"
|
#include "taos.h"
|
||||||
#include "taosmsg.h"
|
#include "taosmsg.h"
|
||||||
#include "tstoken.h"
|
#include "qast.h"
|
||||||
#include "tstrbuild.h"
|
#include "tcompare.h"
|
||||||
#include "ttime.h"
|
#include "tname.h"
|
||||||
#include "tscLog.h"
|
#include "tscLog.h"
|
||||||
#include "tscUtil.h"
|
#include "tscUtil.h"
|
||||||
#include "tschemautil.h"
|
#include "tschemautil.h"
|
||||||
#include "tsclient.h"
|
#include "tsclient.h"
|
||||||
|
#include "tstoken.h"
|
||||||
|
#include "tstrbuild.h"
|
||||||
|
#include "ttime.h"
|
||||||
#include "ttokendef.h"
|
#include "ttokendef.h"
|
||||||
#include "tname.h"
|
|
||||||
#include "tcompare.h"
|
|
||||||
|
|
||||||
#define DEFAULT_PRIMARY_TIMESTAMP_COL_NAME "_c0"
|
#define DEFAULT_PRIMARY_TIMESTAMP_COL_NAME "_c0"
|
||||||
|
|
||||||
|
@ -90,6 +90,7 @@ static int32_t validateSqlFunctionInStreamSql(SSqlCmd* pCmd, SQueryInfo* pQueryI
|
||||||
static int32_t buildArithmeticExprString(tSQLExpr* pExpr, char** exprString);
|
static int32_t buildArithmeticExprString(tSQLExpr* pExpr, char** exprString);
|
||||||
static int32_t validateFunctionsInIntervalOrGroupbyQuery(SSqlCmd* pCmd, SQueryInfo* pQueryInfo);
|
static int32_t validateFunctionsInIntervalOrGroupbyQuery(SSqlCmd* pCmd, SQueryInfo* pQueryInfo);
|
||||||
static int32_t validateArithmeticSQLExpr(SSqlCmd* pCmd, tSQLExpr* pExpr, SQueryInfo* pQueryInfo, SColumnList* pList, int32_t* type);
|
static int32_t validateArithmeticSQLExpr(SSqlCmd* pCmd, tSQLExpr* pExpr, SQueryInfo* pQueryInfo, SColumnList* pList, int32_t* type);
|
||||||
|
static int32_t validateEp(char* ep);
|
||||||
static int32_t validateDNodeConfig(tDCLSQL* pOptions);
|
static int32_t validateDNodeConfig(tDCLSQL* pOptions);
|
||||||
static int32_t validateLocalConfig(tDCLSQL* pOptions);
|
static int32_t validateLocalConfig(tDCLSQL* pOptions);
|
||||||
static int32_t validateColumnName(char* name);
|
static int32_t validateColumnName(char* name);
|
||||||
|
@ -359,6 +360,7 @@ int32_t tscToSQLCmd(SSqlObj* pSql, struct SSqlInfo* pInfo) {
|
||||||
|
|
||||||
case TSDB_SQL_CFG_DNODE: {
|
case TSDB_SQL_CFG_DNODE: {
|
||||||
const char* msg2 = "invalid configure options or values";
|
const char* msg2 = "invalid configure options or values";
|
||||||
|
const char* msg3 = "invalid dnode ep";
|
||||||
|
|
||||||
/* validate the ip address */
|
/* validate the ip address */
|
||||||
tDCLSQL* pDCL = pInfo->pDCLInfo;
|
tDCLSQL* pDCL = pInfo->pDCLInfo;
|
||||||
|
@ -375,6 +377,10 @@ int32_t tscToSQLCmd(SSqlObj* pSql, struct SSqlInfo* pInfo) {
|
||||||
|
|
||||||
strncpy(pCfg->ep, pDCL->a[0].z, pDCL->a[0].n);
|
strncpy(pCfg->ep, pDCL->a[0].z, pDCL->a[0].n);
|
||||||
|
|
||||||
|
if (validateEp(pCfg->ep) != TSDB_CODE_SUCCESS) {
|
||||||
|
return invalidSqlErrMsg(tscGetErrorMsgPayload(pCmd), msg3);
|
||||||
|
}
|
||||||
|
|
||||||
strncpy(pCfg->config, pDCL->a[1].z, pDCL->a[1].n);
|
strncpy(pCfg->config, pDCL->a[1].z, pDCL->a[1].n);
|
||||||
|
|
||||||
if (pDCL->nTokens == 3) {
|
if (pDCL->nTokens == 3) {
|
||||||
|
@ -654,11 +660,14 @@ int32_t parseIntervalClause(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, SQuerySQL* pQ
|
||||||
int32_t parseSlidingClause(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, SQuerySQL* pQuerySql) {
|
int32_t parseSlidingClause(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, SQuerySQL* pQuerySql) {
|
||||||
const char* msg0 = "sliding value too small";
|
const char* msg0 = "sliding value too small";
|
||||||
const char* msg1 = "sliding value no larger than the interval value";
|
const char* msg1 = "sliding value no larger than the interval value";
|
||||||
|
const char* msg2 = "sliding value can not less than 1% of interval value";
|
||||||
|
|
||||||
|
const static int32_t INTERVAL_SLIDING_FACTOR = 100;
|
||||||
|
|
||||||
STableMetaInfo* pTableMetaInfo = tscGetMetaInfo(pQueryInfo, 0);
|
STableMetaInfo* pTableMetaInfo = tscGetMetaInfo(pQueryInfo, 0);
|
||||||
SSQLToken* pSliding = &pQuerySql->sliding;
|
|
||||||
STableComInfo tinfo = tscGetTableInfo(pTableMetaInfo->pTableMeta);
|
STableComInfo tinfo = tscGetTableInfo(pTableMetaInfo->pTableMeta);
|
||||||
|
|
||||||
|
SSQLToken* pSliding = &pQuerySql->sliding;
|
||||||
if (pSliding->n != 0) {
|
if (pSliding->n != 0) {
|
||||||
getTimestampInUsFromStr(pSliding->z, pSliding->n, &pQueryInfo->slidingTime);
|
getTimestampInUsFromStr(pSliding->z, pSliding->n, &pQueryInfo->slidingTime);
|
||||||
if (tinfo.precision == TSDB_TIME_PRECISION_MILLI) {
|
if (tinfo.precision == TSDB_TIME_PRECISION_MILLI) {
|
||||||
|
@ -676,6 +685,10 @@ int32_t parseSlidingClause(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, SQuerySQL* pQu
|
||||||
pQueryInfo->slidingTime = pQueryInfo->intervalTime;
|
pQueryInfo->slidingTime = pQueryInfo->intervalTime;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ((pQueryInfo->intervalTime != 0) && (pQueryInfo->intervalTime/pQueryInfo->slidingTime > INTERVAL_SLIDING_FACTOR)) {
|
||||||
|
return invalidSqlErrMsg(tscGetErrorMsgPayload(pCmd), msg2);
|
||||||
|
}
|
||||||
|
|
||||||
return TSDB_CODE_SUCCESS;
|
return TSDB_CODE_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -4487,10 +4500,12 @@ int32_t setAlterTableInfo(SSqlObj* pSql, struct SSqlInfo* pInfo) {
|
||||||
|
|
||||||
SUpdateTableTagValMsg* pUpdateMsg = (SUpdateTableTagValMsg*) pCmd->payload;
|
SUpdateTableTagValMsg* pUpdateMsg = (SUpdateTableTagValMsg*) pCmd->payload;
|
||||||
pUpdateMsg->head.vgId = htonl(pTableMeta->vgroupInfo.vgId);
|
pUpdateMsg->head.vgId = htonl(pTableMeta->vgroupInfo.vgId);
|
||||||
pUpdateMsg->tid = htonl(pTableMeta->sid);
|
pUpdateMsg->tid = htonl(pTableMeta->sid);
|
||||||
pUpdateMsg->uid = htobe64(pTableMeta->uid);
|
pUpdateMsg->uid = htobe64(pTableMeta->uid);
|
||||||
pUpdateMsg->colId = htons(pTagsSchema->colId);
|
pUpdateMsg->colId = htons(pTagsSchema->colId);
|
||||||
pUpdateMsg->tversion = htons(pTableMeta->tversion);
|
pUpdateMsg->type = pTagsSchema->type;
|
||||||
|
pUpdateMsg->bytes = htons(pTagsSchema->bytes);
|
||||||
|
pUpdateMsg->tversion = htons(pTableMeta->tversion);
|
||||||
pUpdateMsg->numOfTags = htons(numOfTags);
|
pUpdateMsg->numOfTags = htons(numOfTags);
|
||||||
pUpdateMsg->schemaLen = htonl(schemaLen);
|
pUpdateMsg->schemaLen = htonl(schemaLen);
|
||||||
|
|
||||||
|
@ -4627,6 +4642,24 @@ typedef struct SDNodeDynConfOption {
|
||||||
int32_t len; // name string length
|
int32_t len; // name string length
|
||||||
} SDNodeDynConfOption;
|
} SDNodeDynConfOption;
|
||||||
|
|
||||||
|
|
||||||
|
int32_t validateEp(char* ep) {
|
||||||
|
char buf[TSDB_EP_LEN + 1] = {0};
|
||||||
|
tstrncpy(buf, ep, TSDB_EP_LEN);
|
||||||
|
|
||||||
|
char *pos = strchr(buf, ':');
|
||||||
|
if (NULL == pos) {
|
||||||
|
return TSDB_CODE_TSC_INVALID_SQL;
|
||||||
|
}
|
||||||
|
|
||||||
|
uint16_t port = atoi(pos+1);
|
||||||
|
if (0 == port) {
|
||||||
|
return TSDB_CODE_TSC_INVALID_SQL;
|
||||||
|
}
|
||||||
|
|
||||||
|
return TSDB_CODE_SUCCESS;
|
||||||
|
}
|
||||||
|
|
||||||
int32_t validateDNodeConfig(tDCLSQL* pOptions) {
|
int32_t validateDNodeConfig(tDCLSQL* pOptions) {
|
||||||
if (pOptions->nTokens < 2 || pOptions->nTokens > 3) {
|
if (pOptions->nTokens < 2 || pOptions->nTokens > 3) {
|
||||||
return TSDB_CODE_TSC_INVALID_SQL;
|
return TSDB_CODE_TSC_INVALID_SQL;
|
||||||
|
@ -6094,16 +6127,12 @@ int32_t exprTreeFromSqlExpr(SSqlCmd* pCmd, tExprNode **pExpr, const tSQLExpr* pS
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// NOTE: binary|nchar data allows the >|< type filter
|
||||||
if ((*pExpr)->_node.optr != TSDB_RELATION_EQUAL && (*pExpr)->_node.optr != TSDB_RELATION_NOT_EQUAL) {
|
if ((*pExpr)->_node.optr != TSDB_RELATION_EQUAL && (*pExpr)->_node.optr != TSDB_RELATION_NOT_EQUAL) {
|
||||||
if (pRight->nodeType == TSQL_NODE_VALUE) {
|
if (pRight->nodeType == TSQL_NODE_VALUE) {
|
||||||
if (pRight->pVal->nType == TSDB_DATA_TYPE_BOOL) {
|
if (pRight->pVal->nType == TSDB_DATA_TYPE_BOOL) {
|
||||||
return TSDB_CODE_TSC_INVALID_SQL;
|
return TSDB_CODE_TSC_INVALID_SQL;
|
||||||
}
|
}
|
||||||
if ((pRight->pVal->nType == TSDB_DATA_TYPE_BINARY || pRight->pVal->nType == TSDB_DATA_TYPE_NCHAR)
|
|
||||||
&& (*pExpr)->_node.optr != TSDB_RELATION_LIKE) {
|
|
||||||
return TSDB_CODE_TSC_INVALID_SQL;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -215,25 +215,3 @@ __attribute__ ((unused)) static FORCE_INLINE size_t copy(char* dst, const char*
|
||||||
return len;
|
return len;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
* tablePrefix.columnName
|
|
||||||
* extract table name and save it in pTable, with only column name in pToken
|
|
||||||
*/
|
|
||||||
void extractTableNameFromToken(SSQLToken* pToken, SSQLToken* pTable) {
|
|
||||||
const char sep = TS_PATH_DELIMITER[0];
|
|
||||||
|
|
||||||
if (pToken == pTable || pToken == NULL || pTable == NULL) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
char* r = strnchr(pToken->z, sep, pToken->n, false);
|
|
||||||
|
|
||||||
if (r != NULL) { // record the table name token
|
|
||||||
pTable->n = r - pToken->z;
|
|
||||||
pTable->z = pToken->z;
|
|
||||||
|
|
||||||
r += 1;
|
|
||||||
pToken->n -= (r - pToken->z);
|
|
||||||
pToken->z = r;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
|
@ -247,7 +247,7 @@ void tscProcessMsgFromServer(SRpcMsg *rpcMsg, SRpcIpSet *pIpSet) {
|
||||||
} else {
|
} else {
|
||||||
STableMetaInfo *pTableMetaInfo = tscGetTableMetaInfoFromCmd(pCmd, pCmd->clauseIndex, 0);
|
STableMetaInfo *pTableMetaInfo = tscGetTableMetaInfoFromCmd(pCmd, pCmd->clauseIndex, 0);
|
||||||
if (rpcMsg->code == TSDB_CODE_TDB_INVALID_TABLE_ID || rpcMsg->code == TSDB_CODE_VND_INVALID_VGROUP_ID ||
|
if (rpcMsg->code == TSDB_CODE_TDB_INVALID_TABLE_ID || rpcMsg->code == TSDB_CODE_VND_INVALID_VGROUP_ID ||
|
||||||
rpcMsg->code == TSDB_CODE_RPC_NETWORK_UNAVAIL) {
|
rpcMsg->code == TSDB_CODE_RPC_NETWORK_UNAVAIL || rpcMsg->code == TSDB_CODE_TDB_TABLE_RECONFIGURE) {
|
||||||
if (pCmd->command == TSDB_SQL_CONNECT) {
|
if (pCmd->command == TSDB_SQL_CONNECT) {
|
||||||
rpcMsg->code = TSDB_CODE_RPC_NETWORK_UNAVAIL;
|
rpcMsg->code = TSDB_CODE_RPC_NETWORK_UNAVAIL;
|
||||||
rpcFreeCont(rpcMsg->pCont);
|
rpcFreeCont(rpcMsg->pCont);
|
||||||
|
@ -261,6 +261,11 @@ void tscProcessMsgFromServer(SRpcMsg *rpcMsg, SRpcIpSet *pIpSet) {
|
||||||
} else {
|
} else {
|
||||||
tscWarn("%p it shall renew table meta, code:%s, retry:%d", pSql, tstrerror(rpcMsg->code), ++pSql->retry);
|
tscWarn("%p it shall renew table meta, code:%s, retry:%d", pSql, tstrerror(rpcMsg->code), ++pSql->retry);
|
||||||
|
|
||||||
|
// set the flag to denote that sql string needs to be re-parsed and build submit block with table schema
|
||||||
|
if (rpcMsg->code == TSDB_CODE_TDB_TABLE_RECONFIGURE) {
|
||||||
|
pSql->cmd.submitSchema = 1;
|
||||||
|
}
|
||||||
|
|
||||||
pSql->res.code = rpcMsg->code; // keep the previous error code
|
pSql->res.code = rpcMsg->code; // keep the previous error code
|
||||||
if (pSql->retry > pSql->maxRetry) {
|
if (pSql->retry > pSql->maxRetry) {
|
||||||
tscError("%p max retry %d reached, give up", pSql, pSql->maxRetry);
|
tscError("%p max retry %d reached, give up", pSql, pSql->maxRetry);
|
||||||
|
@ -433,8 +438,9 @@ void tscKillSTableQuery(SSqlObj *pSql) {
|
||||||
* here, we cannot set the command = TSDB_SQL_KILL_QUERY. Otherwise, it may cause
|
* here, we cannot set the command = TSDB_SQL_KILL_QUERY. Otherwise, it may cause
|
||||||
* sub-queries not correctly released and master sql object of super table query reaches an abnormal state.
|
* sub-queries not correctly released and master sql object of super table query reaches an abnormal state.
|
||||||
*/
|
*/
|
||||||
pSql->pSubs[i]->res.code = TSDB_CODE_TSC_QUERY_CANCELLED;
|
rpcCancelRequest(pSub->pRpcCtx);
|
||||||
rpcCancelRequest(pSql->pSubs[i]->pRpcCtx);
|
pSub->res.code = TSDB_CODE_TSC_QUERY_CANCELLED;
|
||||||
|
tscQueueAsyncRes(pSub);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -1950,7 +1956,7 @@ int tscProcessUseDbRsp(SSqlObj *pSql) {
|
||||||
}
|
}
|
||||||
|
|
||||||
int tscProcessDropDbRsp(SSqlObj *UNUSED_PARAM(pSql)) {
|
int tscProcessDropDbRsp(SSqlObj *UNUSED_PARAM(pSql)) {
|
||||||
taosCacheEmpty(tscCacheHandle, false);
|
taosCacheEmpty(tscCacheHandle);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1996,7 +2002,7 @@ int tscProcessAlterTableMsgRsp(SSqlObj *pSql) {
|
||||||
|
|
||||||
if (isSuperTable) { // if it is a super table, reset whole query cache
|
if (isSuperTable) { // if it is a super table, reset whole query cache
|
||||||
tscDebug("%p reset query cache since table:%s is stable", pSql, pTableMetaInfo->name);
|
tscDebug("%p reset query cache since table:%s is stable", pSql, pTableMetaInfo->name);
|
||||||
taosCacheEmpty(tscCacheHandle, false);
|
taosCacheEmpty(tscCacheHandle);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -617,19 +617,18 @@ void taos_stop_query(TAOS_RES *res) {
|
||||||
if (pSql->signature != pSql) return;
|
if (pSql->signature != pSql) return;
|
||||||
tscDebug("%p start to cancel query", res);
|
tscDebug("%p start to cancel query", res);
|
||||||
|
|
||||||
pSql->res.code = TSDB_CODE_TSC_QUERY_CANCELLED;
|
|
||||||
|
|
||||||
SQueryInfo *pQueryInfo = tscGetQueryInfoDetail(pCmd, pCmd->clauseIndex);
|
SQueryInfo *pQueryInfo = tscGetQueryInfoDetail(pCmd, pCmd->clauseIndex);
|
||||||
if (tscIsTwoStageSTableQuery(pQueryInfo, 0)) {
|
if (tscIsTwoStageSTableQuery(pQueryInfo, 0)) {
|
||||||
tscKillSTableQuery(pSql);
|
tscKillSTableQuery(pSql);
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (pSql->cmd.command >= TSDB_SQL_LOCAL) {
|
if (pSql->cmd.command < TSDB_SQL_LOCAL) {
|
||||||
return;
|
rpcCancelRequest(pSql->pRpcCtx);
|
||||||
}
|
}
|
||||||
|
pSql->res.code = TSDB_CODE_TSC_QUERY_CANCELLED;
|
||||||
|
tscQueueAsyncRes(pSql);
|
||||||
|
|
||||||
rpcCancelRequest(pSql->pRpcCtx);
|
|
||||||
tscDebug("%p query is cancelled", res);
|
tscDebug("%p query is cancelled", res);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -71,6 +71,7 @@ static void tscProcessStreamLaunchQuery(SSchedMsg *pMsg) {
|
||||||
|
|
||||||
pSql->fp = tscProcessStreamQueryCallback;
|
pSql->fp = tscProcessStreamQueryCallback;
|
||||||
pSql->param = pStream;
|
pSql->param = pStream;
|
||||||
|
pSql->res.completed = false;
|
||||||
|
|
||||||
SQueryInfo *pQueryInfo = tscGetQueryInfoDetail(&pSql->cmd, 0);
|
SQueryInfo *pQueryInfo = tscGetQueryInfoDetail(&pSql->cmd, 0);
|
||||||
STableMetaInfo *pTableMetaInfo = tscGetMetaInfo(pQueryInfo, 0);
|
STableMetaInfo *pTableMetaInfo = tscGetMetaInfo(pQueryInfo, 0);
|
||||||
|
@ -86,7 +87,7 @@ static void tscProcessStreamLaunchQuery(SSchedMsg *pMsg) {
|
||||||
// failed to get meter/metric meta, retry in 10sec.
|
// failed to get meter/metric meta, retry in 10sec.
|
||||||
if (code != TSDB_CODE_SUCCESS) {
|
if (code != TSDB_CODE_SUCCESS) {
|
||||||
int64_t retryDelayTime = tscGetRetryDelayTime(pStream->slidingTime, pStream->precision);
|
int64_t retryDelayTime = tscGetRetryDelayTime(pStream->slidingTime, pStream->precision);
|
||||||
tscError("%p stream:%p,get metermeta failed, retry in %" PRId64 "ms", pStream->pSql, pStream, retryDelayTime);
|
tscDebug("%p stream:%p,get metermeta failed, retry in %" PRId64 "ms", pStream->pSql, pStream, retryDelayTime);
|
||||||
tscSetRetryTimer(pStream, pSql, retryDelayTime);
|
tscSetRetryTimer(pStream, pSql, retryDelayTime);
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
|
@ -108,7 +109,7 @@ static void tscProcessStreamTimer(void *handle, void *tmrId) {
|
||||||
SQueryInfo* pQueryInfo = tscGetQueryInfoDetail(&pSql->cmd, 0);
|
SQueryInfo* pQueryInfo = tscGetQueryInfoDetail(&pSql->cmd, 0);
|
||||||
tscDebug("%p add into timer", pSql);
|
tscDebug("%p add into timer", pSql);
|
||||||
|
|
||||||
if (isProjectStream(pQueryInfo)) {
|
if (pStream->isProject) {
|
||||||
/*
|
/*
|
||||||
* pQueryInfo->window.ekey, which is the start time, does not change in case of
|
* pQueryInfo->window.ekey, which is the start time, does not change in case of
|
||||||
* repeat first execution, once the first execution failed.
|
* repeat first execution, once the first execution failed.
|
||||||
|
@ -121,7 +122,19 @@ static void tscProcessStreamTimer(void *handle, void *tmrId) {
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
pQueryInfo->window.skey = pStream->stime - pStream->interval;
|
pQueryInfo->window.skey = pStream->stime - pStream->interval;
|
||||||
pQueryInfo->window.ekey = pStream->stime - 1;
|
int64_t etime = taosGetTimestamp(pStream->precision);
|
||||||
|
// delay to wait all data in last time window
|
||||||
|
if (pStream->precision == TSDB_TIME_PRECISION_MICRO) {
|
||||||
|
etime -= tsMaxStreamComputDelay * 1000l;
|
||||||
|
} else {
|
||||||
|
etime -= tsMaxStreamComputDelay;
|
||||||
|
}
|
||||||
|
if (etime > pStream->etime) {
|
||||||
|
etime = pStream->etime;
|
||||||
|
} else {
|
||||||
|
etime = pStream->stime + (etime - pStream->stime) / pStream->interval * pStream->interval;
|
||||||
|
}
|
||||||
|
pQueryInfo->window.ekey = etime;
|
||||||
}
|
}
|
||||||
|
|
||||||
// launch stream computing in a new thread
|
// launch stream computing in a new thread
|
||||||
|
@ -137,7 +150,7 @@ static void tscProcessStreamQueryCallback(void *param, TAOS_RES *tres, int numOf
|
||||||
SSqlStream *pStream = (SSqlStream *)param;
|
SSqlStream *pStream = (SSqlStream *)param;
|
||||||
if (tres == NULL || numOfRows < 0) {
|
if (tres == NULL || numOfRows < 0) {
|
||||||
int64_t retryDelay = tscGetRetryDelayTime(pStream->slidingTime, pStream->precision);
|
int64_t retryDelay = tscGetRetryDelayTime(pStream->slidingTime, pStream->precision);
|
||||||
tscError("%p stream:%p, query data failed, code:%d, retry in %" PRId64 "ms", pStream->pSql, pStream, numOfRows,
|
tscError("%p stream:%p, query data failed, code:0x%08x, retry in %" PRId64 "ms", pStream->pSql, pStream, numOfRows,
|
||||||
retryDelay);
|
retryDelay);
|
||||||
|
|
||||||
STableMetaInfo* pTableMetaInfo = tscGetTableMetaInfoFromCmd(&pStream->pSql->cmd, 0, 0);
|
STableMetaInfo* pTableMetaInfo = tscGetTableMetaInfoFromCmd(&pStream->pSql->cmd, 0, 0);
|
||||||
|
@ -151,17 +164,45 @@ static void tscProcessStreamQueryCallback(void *param, TAOS_RES *tres, int numOf
|
||||||
taos_fetch_rows_a(tres, tscProcessStreamRetrieveResult, param);
|
taos_fetch_rows_a(tres, tscProcessStreamRetrieveResult, param);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void tscSetTimestampForRes(SSqlStream *pStream, SSqlObj *pSql) {
|
// no need to be called as this is alreay done in the query
|
||||||
SSqlRes *pRes = &pSql->res;
|
static void tscStreamFillTimeGap(SSqlStream* pStream, TSKEY ts) {
|
||||||
|
#if 0
|
||||||
|
SSqlObj * pSql = pStream->pSql;
|
||||||
|
SQueryInfo* pQueryInfo = tscGetQueryInfoDetail(&pSql->cmd, 0);
|
||||||
|
|
||||||
int64_t timestamp = *(int64_t *)pRes->data;
|
if (pQueryInfo->fillType != TSDB_FILL_SET_VALUE && pQueryInfo->fillType != TSDB_FILL_NULL) {
|
||||||
int64_t actualTimestamp = pStream->stime - pStream->interval;
|
return;
|
||||||
|
|
||||||
if (timestamp != actualTimestamp) {
|
|
||||||
// reset the timestamp of each agg point by using start time of each interval
|
|
||||||
*((int64_t *)pRes->data) = actualTimestamp;
|
|
||||||
tscWarn("%p stream:%p, timestamp of points is:%" PRId64 ", reset to %" PRId64, pSql, pStream, timestamp, actualTimestamp);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
SSqlRes *pRes = &pSql->res;
|
||||||
|
/* failed to retrieve any result in this retrieve */
|
||||||
|
pSql->res.numOfRows = 1;
|
||||||
|
void *row[TSDB_MAX_COLUMNS] = {0};
|
||||||
|
char tmpRes[TSDB_MAX_BYTES_PER_ROW] = {0};
|
||||||
|
void *oldPtr = pSql->res.data;
|
||||||
|
pSql->res.data = tmpRes;
|
||||||
|
int32_t rowNum = 0;
|
||||||
|
|
||||||
|
while (pStream->stime + pStream->slidingTime < ts) {
|
||||||
|
pStream->stime += pStream->slidingTime;
|
||||||
|
*(TSKEY*)row[0] = pStream->stime;
|
||||||
|
for (int32_t i = 1; i < pQueryInfo->fieldsInfo.numOfOutput; ++i) {
|
||||||
|
int16_t offset = tscFieldInfoGetOffset(pQueryInfo, i);
|
||||||
|
TAOS_FIELD *pField = tscFieldInfoGetField(&pQueryInfo->fieldsInfo, i);
|
||||||
|
assignVal(pSql->res.data + offset, (char *)(&pQueryInfo->fillVal[i]), pField->bytes, pField->type);
|
||||||
|
row[i] = pSql->res.data + offset;
|
||||||
|
}
|
||||||
|
(*pStream->fp)(pStream->param, pSql, row);
|
||||||
|
++rowNum;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (rowNum > 0) {
|
||||||
|
tscDebug("%p stream:%p %d rows padded", pSql, pStream, rowNum);
|
||||||
|
}
|
||||||
|
|
||||||
|
pRes->numOfRows = 0;
|
||||||
|
pRes->data = oldPtr;
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
static void tscProcessStreamRetrieveResult(void *param, TAOS_RES *res, int numOfRows) {
|
static void tscProcessStreamRetrieveResult(void *param, TAOS_RES *res, int numOfRows) {
|
||||||
|
@ -170,7 +211,7 @@ static void tscProcessStreamRetrieveResult(void *param, TAOS_RES *res, int numOf
|
||||||
|
|
||||||
if (pSql == NULL || numOfRows < 0) {
|
if (pSql == NULL || numOfRows < 0) {
|
||||||
int64_t retryDelayTime = tscGetRetryDelayTime(pStream->slidingTime, pStream->precision);
|
int64_t retryDelayTime = tscGetRetryDelayTime(pStream->slidingTime, pStream->precision);
|
||||||
tscError("%p stream:%p, retrieve data failed, code:%d, retry in %" PRId64 "ms", pSql, pStream, numOfRows, retryDelayTime);
|
tscError("%p stream:%p, retrieve data failed, code:0x%08x, retry in %" PRId64 "ms", pSql, pStream, numOfRows, retryDelayTime);
|
||||||
|
|
||||||
tscSetRetryTimer(pStream, pStream->pSql, retryDelayTime);
|
tscSetRetryTimer(pStream, pStream->pSql, retryDelayTime);
|
||||||
return;
|
return;
|
||||||
|
@ -180,16 +221,11 @@ static void tscProcessStreamRetrieveResult(void *param, TAOS_RES *res, int numOf
|
||||||
|
|
||||||
if (numOfRows > 0) { // when reaching here the first execution of stream computing is successful.
|
if (numOfRows > 0) { // when reaching here the first execution of stream computing is successful.
|
||||||
pStream->numOfRes += numOfRows;
|
pStream->numOfRes += numOfRows;
|
||||||
SQueryInfo* pQueryInfo = tscGetQueryInfoDetail(&pSql->cmd, 0);
|
|
||||||
|
|
||||||
for(int32_t i = 0; i < numOfRows; ++i) {
|
for(int32_t i = 0; i < numOfRows; ++i) {
|
||||||
TAOS_ROW row = taos_fetch_row(res);
|
TAOS_ROW row = taos_fetch_row(res);
|
||||||
tscDebug("%p stream:%p fetch result", pSql, pStream);
|
tscDebug("%p stream:%p fetch result", pSql, pStream);
|
||||||
if (isProjectStream(pQueryInfo)) {
|
tscStreamFillTimeGap(pStream, *(TSKEY*)row[0]);
|
||||||
pStream->stime = *(TSKEY *)row[0];
|
pStream->stime = *(TSKEY *)row[0];
|
||||||
} else {
|
|
||||||
tscSetTimestampForRes(pStream, pSql);
|
|
||||||
}
|
|
||||||
|
|
||||||
// user callback function
|
// user callback function
|
||||||
(*pStream->fp)(pStream->param, res, row);
|
(*pStream->fp)(pStream->param, res, row);
|
||||||
|
@ -199,55 +235,18 @@ static void tscProcessStreamRetrieveResult(void *param, TAOS_RES *res, int numOf
|
||||||
taos_fetch_rows_a(res, tscProcessStreamRetrieveResult, pStream);
|
taos_fetch_rows_a(res, tscProcessStreamRetrieveResult, pStream);
|
||||||
} else { // numOfRows == 0, all data has been retrieved
|
} else { // numOfRows == 0, all data has been retrieved
|
||||||
pStream->useconds += pSql->res.useconds;
|
pStream->useconds += pSql->res.useconds;
|
||||||
|
|
||||||
SQueryInfo* pQueryInfo = tscGetQueryInfoDetail(&pSql->cmd, 0);
|
|
||||||
|
|
||||||
if (pStream->numOfRes == 0) {
|
if (pStream->numOfRes == 0) {
|
||||||
if (pQueryInfo->fillType == TSDB_FILL_SET_VALUE || pQueryInfo->fillType == TSDB_FILL_NULL) {
|
if (pStream->isProject) {
|
||||||
SSqlRes *pRes = &pSql->res;
|
|
||||||
|
|
||||||
/* failed to retrieve any result in this retrieve */
|
|
||||||
pSql->res.numOfRows = 1;
|
|
||||||
void *row[TSDB_MAX_COLUMNS] = {0};
|
|
||||||
char tmpRes[TSDB_MAX_BYTES_PER_ROW] = {0};
|
|
||||||
|
|
||||||
void *oldPtr = pSql->res.data;
|
|
||||||
pSql->res.data = tmpRes;
|
|
||||||
|
|
||||||
for (int32_t i = 1; i < pQueryInfo->fieldsInfo.numOfOutput; ++i) {
|
|
||||||
int16_t offset = tscFieldInfoGetOffset(pQueryInfo, i);
|
|
||||||
TAOS_FIELD *pField = tscFieldInfoGetField(&pQueryInfo->fieldsInfo, i);
|
|
||||||
|
|
||||||
assignVal(pSql->res.data + offset, (char *)(&pQueryInfo->fillVal[i]), pField->bytes, pField->type);
|
|
||||||
row[i] = pSql->res.data + offset;
|
|
||||||
}
|
|
||||||
|
|
||||||
tscSetTimestampForRes(pStream, pSql);
|
|
||||||
row[0] = pRes->data;
|
|
||||||
|
|
||||||
// char result[512] = {0};
|
|
||||||
// taos_print_row(result, row, pQueryInfo->fieldsInfo.pFields, pQueryInfo->fieldsInfo.numOfOutput);
|
|
||||||
// tscInfo("%p stream:%p query result: %s", pSql, pStream, result);
|
|
||||||
tscDebug("%p stream:%p fetch result", pSql, pStream);
|
|
||||||
|
|
||||||
// user callback function
|
|
||||||
(*pStream->fp)(pStream->param, res, row);
|
|
||||||
|
|
||||||
pRes->numOfRows = 0;
|
|
||||||
pRes->data = oldPtr;
|
|
||||||
} else if (isProjectStream(pQueryInfo)) {
|
|
||||||
/* no resuls in the query range, retry */
|
/* no resuls in the query range, retry */
|
||||||
// todo set retry dynamic time
|
// todo set retry dynamic time
|
||||||
int32_t retry = tsProjectExecInterval;
|
int32_t retry = tsProjectExecInterval;
|
||||||
tscError("%p stream:%p, retrieve no data, code:%d, retry in %" PRId32 "ms", pSql, pStream, numOfRows, retry);
|
tscError("%p stream:%p, retrieve no data, code:0x%08x, retry in %" PRId32 "ms", pSql, pStream, numOfRows, retry);
|
||||||
|
|
||||||
tscSetRetryTimer(pStream, pStream->pSql, retry);
|
tscSetRetryTimer(pStream, pStream->pSql, retry);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
} else {
|
} else if (pStream->isProject) {
|
||||||
if (isProjectStream(pQueryInfo)) {
|
pStream->stime += 1;
|
||||||
pStream->stime += 1;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
tscDebug("%p stream:%p, query on:%s, fetch result completed, fetched rows:%" PRId64, pSql, pStream, pTableMetaInfo->name,
|
tscDebug("%p stream:%p, query on:%s, fetch result completed, fetched rows:%" PRId64, pSql, pStream, pTableMetaInfo->name,
|
||||||
|
@ -256,16 +255,18 @@ static void tscProcessStreamRetrieveResult(void *param, TAOS_RES *res, int numOf
|
||||||
// release the metric/meter meta information reference, so data in cache can be updated
|
// release the metric/meter meta information reference, so data in cache can be updated
|
||||||
|
|
||||||
taosCacheRelease(tscCacheHandle, (void**)&(pTableMetaInfo->pTableMeta), false);
|
taosCacheRelease(tscCacheHandle, (void**)&(pTableMetaInfo->pTableMeta), false);
|
||||||
|
tscFreeSqlResult(pSql);
|
||||||
|
tfree(pSql->pSubs);
|
||||||
|
pSql->numOfSubs = 0;
|
||||||
tfree(pTableMetaInfo->vgroupList);
|
tfree(pTableMetaInfo->vgroupList);
|
||||||
tscSetNextLaunchTimer(pStream, pSql);
|
tscSetNextLaunchTimer(pStream, pSql);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void tscSetRetryTimer(SSqlStream *pStream, SSqlObj *pSql, int64_t timer) {
|
static void tscSetRetryTimer(SSqlStream *pStream, SSqlObj *pSql, int64_t timer) {
|
||||||
SQueryInfo* pQueryInfo = tscGetQueryInfoDetail(&pSql->cmd, 0);
|
|
||||||
int64_t delay = getDelayValueAfterTimewindowClosed(pStream, timer);
|
int64_t delay = getDelayValueAfterTimewindowClosed(pStream, timer);
|
||||||
|
|
||||||
if (isProjectStream(pQueryInfo)) {
|
if (pStream->isProject) {
|
||||||
int64_t now = taosGetTimestamp(pStream->precision);
|
int64_t now = taosGetTimestamp(pStream->precision);
|
||||||
int64_t etime = now > pStream->etime ? pStream->etime : now;
|
int64_t etime = now > pStream->etime ? pStream->etime : now;
|
||||||
|
|
||||||
|
@ -323,8 +324,7 @@ static int64_t getLaunchTimeDelay(const SSqlStream* pStream) {
|
||||||
static void tscSetNextLaunchTimer(SSqlStream *pStream, SSqlObj *pSql) {
|
static void tscSetNextLaunchTimer(SSqlStream *pStream, SSqlObj *pSql) {
|
||||||
int64_t timer = 0;
|
int64_t timer = 0;
|
||||||
|
|
||||||
SQueryInfo* pQueryInfo = tscGetQueryInfoDetail(&pSql->cmd, 0);
|
if (pStream->isProject) {
|
||||||
if (isProjectStream(pQueryInfo)) {
|
|
||||||
/*
|
/*
|
||||||
* for project query, no mater fetch data successfully or not, next launch will issue
|
* for project query, no mater fetch data successfully or not, next launch will issue
|
||||||
* more than the sliding time window
|
* more than the sliding time window
|
||||||
|
@ -342,7 +342,6 @@ static void tscSetNextLaunchTimer(SSqlStream *pStream, SSqlObj *pSql) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
pStream->stime += pStream->slidingTime;
|
|
||||||
if ((pStream->stime - pStream->interval) >= pStream->etime) {
|
if ((pStream->stime - pStream->interval) >= pStream->etime) {
|
||||||
tscDebug("%p stream:%p, stime:%" PRId64 " is larger than end time: %" PRId64 ", stop the stream", pStream->pSql, pStream,
|
tscDebug("%p stream:%p, stime:%" PRId64 " is larger than end time: %" PRId64 ", stop the stream", pStream->pSql, pStream,
|
||||||
pStream->stime, pStream->etime);
|
pStream->stime, pStream->etime);
|
||||||
|
@ -409,14 +408,16 @@ static void tscSetSlidingWindowInfo(SSqlObj *pSql, SSqlStream *pStream) {
|
||||||
|
|
||||||
pStream->slidingTime = pQueryInfo->slidingTime;
|
pStream->slidingTime = pQueryInfo->slidingTime;
|
||||||
|
|
||||||
pQueryInfo->intervalTime = 0; // clear the interval value to avoid the force time window split by query processor
|
if (pStream->isProject) {
|
||||||
pQueryInfo->slidingTime = 0;
|
pQueryInfo->intervalTime = 0; // clear the interval value to avoid the force time window split by query processor
|
||||||
|
pQueryInfo->slidingTime = 0;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static int64_t tscGetStreamStartTimestamp(SSqlObj *pSql, SSqlStream *pStream, int64_t stime) {
|
static int64_t tscGetStreamStartTimestamp(SSqlObj *pSql, SSqlStream *pStream, int64_t stime) {
|
||||||
SQueryInfo* pQueryInfo = tscGetQueryInfoDetail(&pSql->cmd, 0);
|
SQueryInfo* pQueryInfo = tscGetQueryInfoDetail(&pSql->cmd, 0);
|
||||||
|
|
||||||
if (isProjectStream(pQueryInfo)) {
|
if (pStream->isProject) {
|
||||||
// no data in table, flush all data till now to destination meter, 10sec delay
|
// no data in table, flush all data till now to destination meter, 10sec delay
|
||||||
pStream->interval = tsProjectExecInterval;
|
pStream->interval = tsProjectExecInterval;
|
||||||
pStream->slidingTime = tsProjectExecInterval;
|
pStream->slidingTime = tsProjectExecInterval;
|
||||||
|
@ -489,7 +490,7 @@ TAOS_STREAM *taos_open_stream(TAOS *taos, const char *sqlstr, void (*fp)(void *p
|
||||||
|
|
||||||
SSqlStream *pStream = (SSqlStream *)calloc(1, sizeof(SSqlStream));
|
SSqlStream *pStream = (SSqlStream *)calloc(1, sizeof(SSqlStream));
|
||||||
if (pStream == NULL) {
|
if (pStream == NULL) {
|
||||||
tscError("%p open stream failed, sql:%s, reason:%s, code:%d", pSql, sqlstr, pCmd->payload, pRes->code);
|
tscError("%p open stream failed, sql:%s, reason:%s, code:0x%08x", pSql, sqlstr, pCmd->payload, pRes->code);
|
||||||
tscFreeSqlObj(pSql);
|
tscFreeSqlObj(pSql);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
@ -503,7 +504,7 @@ TAOS_STREAM *taos_open_stream(TAOS *taos, const char *sqlstr, void (*fp)(void *p
|
||||||
}
|
}
|
||||||
strtolower(pSql->sqlstr, sqlstr);
|
strtolower(pSql->sqlstr, sqlstr);
|
||||||
|
|
||||||
tscDebugDump("%p SQL: %s", pSql, pSql->sqlstr);
|
tscDebugL("%p SQL: %s", pSql, pSql->sqlstr);
|
||||||
tsem_init(&pSql->rspSem, 0, 0);
|
tsem_init(&pSql->rspSem, 0, 0);
|
||||||
|
|
||||||
int32_t code = tsParseSql(pSql, true);
|
int32_t code = tsParseSql(pSql, true);
|
||||||
|
@ -514,7 +515,7 @@ TAOS_STREAM *taos_open_stream(TAOS *taos, const char *sqlstr, void (*fp)(void *p
|
||||||
if (pRes->code != TSDB_CODE_SUCCESS) {
|
if (pRes->code != TSDB_CODE_SUCCESS) {
|
||||||
setErrorInfo(pSql, pRes->code, pCmd->payload);
|
setErrorInfo(pSql, pRes->code, pCmd->payload);
|
||||||
|
|
||||||
tscError("%p open stream failed, sql:%s, reason:%s, code:%d", pSql, sqlstr, pCmd->payload, pRes->code);
|
tscError("%p open stream failed, sql:%s, reason:%s, code:0x%08x", pSql, sqlstr, pCmd->payload, pRes->code);
|
||||||
tscFreeSqlObj(pSql);
|
tscFreeSqlObj(pSql);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
@ -523,6 +524,7 @@ TAOS_STREAM *taos_open_stream(TAOS *taos, const char *sqlstr, void (*fp)(void *p
|
||||||
STableMetaInfo* pTableMetaInfo = tscGetMetaInfo(pQueryInfo, 0);
|
STableMetaInfo* pTableMetaInfo = tscGetMetaInfo(pQueryInfo, 0);
|
||||||
STableComInfo tinfo = tscGetTableInfo(pTableMetaInfo->pTableMeta);
|
STableComInfo tinfo = tscGetTableInfo(pTableMetaInfo->pTableMeta);
|
||||||
|
|
||||||
|
pStream->isProject = isProjectStream(pQueryInfo);
|
||||||
pStream->fp = fp;
|
pStream->fp = fp;
|
||||||
pStream->callback = callback;
|
pStream->callback = callback;
|
||||||
pStream->param = param;
|
pStream->param = param;
|
||||||
|
@ -565,6 +567,8 @@ void taos_close_stream(TAOS_STREAM *handle) {
|
||||||
taosTmrStopA(&(pStream->pTimer));
|
taosTmrStopA(&(pStream->pTimer));
|
||||||
|
|
||||||
tscDebug("%p stream:%p is closed", pSql, pStream);
|
tscDebug("%p stream:%p is closed", pSql, pStream);
|
||||||
|
// notify CQ to release the pStream object
|
||||||
|
pStream->fp(pStream->param, NULL, NULL);
|
||||||
|
|
||||||
tscFreeSqlObj(pSql);
|
tscFreeSqlObj(pSql);
|
||||||
pStream->pSql = NULL;
|
pStream->pSql = NULL;
|
||||||
|
|
|
@ -14,12 +14,12 @@
|
||||||
*/
|
*/
|
||||||
#include "os.h"
|
#include "os.h"
|
||||||
|
|
||||||
#include "tscSubquery.h"
|
#include "qtsbuf.h"
|
||||||
#include "qast.h"
|
#include "qast.h"
|
||||||
#include "tcompare.h"
|
#include "tcompare.h"
|
||||||
#include "tschemautil.h"
|
|
||||||
#include "qtsbuf.h"
|
|
||||||
#include "tscLog.h"
|
#include "tscLog.h"
|
||||||
|
#include "tscSubquery.h"
|
||||||
|
#include "tschemautil.h"
|
||||||
#include "tsclient.h"
|
#include "tsclient.h"
|
||||||
|
|
||||||
typedef struct SInsertSupporter {
|
typedef struct SInsertSupporter {
|
||||||
|
@ -57,10 +57,15 @@ static int64_t doTSBlockIntersect(SSqlObj* pSql, SJoinSupporter* pSupporter1, SJ
|
||||||
pSubQueryInfo1->tsBuf = output1;
|
pSubQueryInfo1->tsBuf = output1;
|
||||||
pSubQueryInfo2->tsBuf = output2;
|
pSubQueryInfo2->tsBuf = output2;
|
||||||
|
|
||||||
|
// no result generated, return directly
|
||||||
|
if (pSupporter1->pTSBuf == NULL || pSupporter2->pTSBuf == NULL) {
|
||||||
|
tscDebug("%p at least one ts-comp is empty, 0 for secondary query after ts blocks intersecting", pSql);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
tsBufResetPos(pSupporter1->pTSBuf);
|
tsBufResetPos(pSupporter1->pTSBuf);
|
||||||
tsBufResetPos(pSupporter2->pTSBuf);
|
tsBufResetPos(pSupporter2->pTSBuf);
|
||||||
|
|
||||||
// TODO add more details information
|
|
||||||
if (!tsBufNextPos(pSupporter1->pTSBuf)) {
|
if (!tsBufNextPos(pSupporter1->pTSBuf)) {
|
||||||
tsBufFlush(output1);
|
tsBufFlush(output1);
|
||||||
tsBufFlush(output2);
|
tsBufFlush(output2);
|
||||||
|
@ -210,6 +215,7 @@ static void tscDestroyJoinSupporter(SJoinSupporter* pSupporter) {
|
||||||
pSupporter->f = NULL;
|
pSupporter->f = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
tfree(pSupporter->pIdTagList);
|
||||||
tscTagCondRelease(&pSupporter->tagCond);
|
tscTagCondRelease(&pSupporter->tagCond);
|
||||||
free(pSupporter);
|
free(pSupporter);
|
||||||
}
|
}
|
||||||
|
@ -420,43 +426,6 @@ static void updateQueryTimeRange(SQueryInfo* pQueryInfo, STimeWindow* win) {
|
||||||
pQueryInfo->window = *win;
|
pQueryInfo->window = *win;
|
||||||
}
|
}
|
||||||
|
|
||||||
static UNUSED_FUNC void tSIntersectionAndLaunchSecQuery(SJoinSupporter* pSupporter, SSqlObj* pSql) {
|
|
||||||
SSqlObj* pParentSql = pSupporter->pObj;
|
|
||||||
SQueryInfo* pParentQueryInfo = tscGetQueryInfoDetail(&pParentSql->cmd, pParentSql->cmd.clauseIndex);
|
|
||||||
|
|
||||||
// if (tscNonOrderedProjectionQueryOnSTable(pParentQueryInfo, 0)) {
|
|
||||||
// STableMetaInfo* pTableMetaInfo = tscGetMetaInfo(pQueryInfo, 0);
|
|
||||||
// assert(pQueryInfo->numOfTables == 1);
|
|
||||||
//
|
|
||||||
// // for projection query, need to try next vnode
|
|
||||||
//// int32_t totalVnode = pTableMetaInfo->pMetricMeta->numOfVnodes;
|
|
||||||
// int32_t totalVnode = 0;
|
|
||||||
// if ((++pTableMetaInfo->vgroupIndex) < totalVnode) {
|
|
||||||
// tscDebug("%p current vnode:%d exhausted, try next:%d. total vnode:%d. current numOfRes:%d", pSql,
|
|
||||||
// pTableMetaInfo->vgroupIndex - 1, pTableMetaInfo->vgroupIndex, totalVnode, pRes->numOfTotal);
|
|
||||||
//
|
|
||||||
// pSql->cmd.command = TSDB_SQL_SELECT;
|
|
||||||
// pSql->fp = tscJoinQueryCallback;
|
|
||||||
// tscProcessSql(pSql);
|
|
||||||
//
|
|
||||||
// return;
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
|
|
||||||
SJoinSupporter* p1 = pParentSql->pSubs[0]->param;
|
|
||||||
SJoinSupporter* p2 = pParentSql->pSubs[1]->param;
|
|
||||||
|
|
||||||
STimeWindow win = TSWINDOW_INITIALIZER;
|
|
||||||
int64_t num = doTSBlockIntersect(pParentSql, p1, p2, &win);
|
|
||||||
if (num <= 0) { // no result during ts intersect
|
|
||||||
tscDebug("%p free all sub SqlObj and quit", pParentSql);
|
|
||||||
freeJoinSubqueryObj(pParentSql);
|
|
||||||
} else {
|
|
||||||
updateQueryTimeRange(pParentQueryInfo, &win);
|
|
||||||
tscLaunchRealSubqueries(pParentSql);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
int32_t tscCompareTidTags(const void* p1, const void* p2) {
|
int32_t tscCompareTidTags(const void* p1, const void* p2) {
|
||||||
const STidTags* t1 = (const STidTags*) varDataVal(p1);
|
const STidTags* t1 = (const STidTags*) varDataVal(p1);
|
||||||
const STidTags* t2 = (const STidTags*) varDataVal(p2);
|
const STidTags* t2 = (const STidTags*) varDataVal(p2);
|
||||||
|
@ -713,9 +682,12 @@ static void tidTagRetrieveCallback(void* param, TAOS_RES* tres, int32_t numOfRow
|
||||||
SArray *s1 = NULL, *s2 = NULL;
|
SArray *s1 = NULL, *s2 = NULL;
|
||||||
getIntersectionOfTableTuple(pQueryInfo, pParentSql, &s1, &s2);
|
getIntersectionOfTableTuple(pQueryInfo, pParentSql, &s1, &s2);
|
||||||
if (taosArrayGetSize(s1) == 0 || taosArrayGetSize(s2) == 0) { // no results,return.
|
if (taosArrayGetSize(s1) == 0 || taosArrayGetSize(s2) == 0) { // no results,return.
|
||||||
tscDebug("%p free all sub SqlObj and quit", pParentSql);
|
tscDebug("%p tag intersect does not generated qualified tables for join, free all sub SqlObj and quit", pParentSql);
|
||||||
freeJoinSubqueryObj(pParentSql);
|
freeJoinSubqueryObj(pParentSql);
|
||||||
|
|
||||||
|
// set no result command
|
||||||
|
pParentSql->cmd.command = TSDB_SQL_RETRIEVE_EMPTY_RESULT;
|
||||||
|
(*pParentSql->fp)(pParentSql->param, pParentSql, 0);
|
||||||
} else {
|
} else {
|
||||||
// proceed to for ts_comp query
|
// proceed to for ts_comp query
|
||||||
SSqlCmd* pSubCmd1 = &pParentSql->pSubs[0]->cmd;
|
SSqlCmd* pSubCmd1 = &pParentSql->pSubs[0]->cmd;
|
||||||
|
@ -847,6 +819,9 @@ static void tsCompRetrieveCallback(void* param, TAOS_RES* tres, int32_t numOfRow
|
||||||
tscDebug("%p no results generated in ts intersection, free all sub SqlObj and quit", pParentSql);
|
tscDebug("%p no results generated in ts intersection, free all sub SqlObj and quit", pParentSql);
|
||||||
freeJoinSubqueryObj(pParentSql);
|
freeJoinSubqueryObj(pParentSql);
|
||||||
|
|
||||||
|
// set no result command
|
||||||
|
pParentSql->cmd.command = TSDB_SQL_RETRIEVE_EMPTY_RESULT;
|
||||||
|
(*pParentSql->fp)(pParentSql->param, pParentSql, 0);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1472,9 +1447,7 @@ int32_t tscHandleMasterSTableQuery(SSqlObj *pSql) {
|
||||||
static void tscFreeSubSqlObj(SRetrieveSupport *trsupport, SSqlObj *pSql) {
|
static void tscFreeSubSqlObj(SRetrieveSupport *trsupport, SSqlObj *pSql) {
|
||||||
tscDebug("%p start to free subquery result", pSql);
|
tscDebug("%p start to free subquery result", pSql);
|
||||||
|
|
||||||
if (pSql->res.code == TSDB_CODE_SUCCESS) {
|
taos_free_result(pSql);
|
||||||
taos_free_result(pSql);
|
|
||||||
}
|
|
||||||
|
|
||||||
tfree(trsupport->localBuffer);
|
tfree(trsupport->localBuffer);
|
||||||
|
|
||||||
|
@ -1805,6 +1778,7 @@ static SSqlObj *tscCreateSqlObjForSubquery(SSqlObj *pSql, SRetrieveSupport *trsu
|
||||||
pSql->pSubs[trsupport->subqueryIndex] = pNew;
|
pSql->pSubs[trsupport->subqueryIndex] = pNew;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
printf("------------alloc:%p\n", pNew);
|
||||||
return pNew;
|
return pNew;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -14,21 +14,21 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "os.h"
|
#include "os.h"
|
||||||
#include "qast.h"
|
#include "hash.h"
|
||||||
|
#include "tscUtil.h"
|
||||||
#include "taosmsg.h"
|
#include "taosmsg.h"
|
||||||
|
#include "qast.h"
|
||||||
#include "tcache.h"
|
#include "tcache.h"
|
||||||
#include "tkey.h"
|
#include "tkey.h"
|
||||||
#include "tmd5.h"
|
#include "tmd5.h"
|
||||||
#include "tscProfile.h"
|
|
||||||
#include "tscLocalMerge.h"
|
#include "tscLocalMerge.h"
|
||||||
|
#include "tscLog.h"
|
||||||
|
#include "tscProfile.h"
|
||||||
#include "tscSubquery.h"
|
#include "tscSubquery.h"
|
||||||
#include "tschemautil.h"
|
#include "tschemautil.h"
|
||||||
#include "tsclient.h"
|
#include "tsclient.h"
|
||||||
#include "ttimer.h"
|
#include "ttimer.h"
|
||||||
#include "ttokendef.h"
|
#include "ttokendef.h"
|
||||||
#include "tscLog.h"
|
|
||||||
#include "tscUtil.h"
|
|
||||||
#include "hash.h"
|
|
||||||
|
|
||||||
static void freeQueryInfoImpl(SQueryInfo* pQueryInfo);
|
static void freeQueryInfoImpl(SQueryInfo* pQueryInfo);
|
||||||
static void clearAllTableMetaInfo(SQueryInfo* pQueryInfo, const char* address, bool removeFromCache);
|
static void clearAllTableMetaInfo(SQueryInfo* pQueryInfo, const char* address, bool removeFromCache);
|
||||||
|
@ -579,9 +579,9 @@ static int trimDataBlock(void* pDataBlock, STableDataBlocks* pTableDataBlock, bo
|
||||||
int32_t numOfCols = tscGetNumOfColumns(pTableDataBlock->pTableMeta);
|
int32_t numOfCols = tscGetNumOfColumns(pTableDataBlock->pTableMeta);
|
||||||
for(int32_t j = 0; j < numOfCols; ++j) {
|
for(int32_t j = 0; j < numOfCols; ++j) {
|
||||||
STColumn* pCol = (STColumn*) pDataBlock;
|
STColumn* pCol = (STColumn*) pDataBlock;
|
||||||
pCol->colId = pSchema[j].colId;
|
pCol->colId = htons(pSchema[j].colId);
|
||||||
pCol->type = pSchema[j].type;
|
pCol->type = pSchema[j].type;
|
||||||
pCol->bytes = pSchema[j].bytes;
|
pCol->bytes = htons(pSchema[j].bytes);
|
||||||
pCol->offset = 0;
|
pCol->offset = 0;
|
||||||
|
|
||||||
pDataBlock += sizeof(STColumn);
|
pDataBlock += sizeof(STColumn);
|
||||||
|
@ -663,7 +663,7 @@ int32_t tscMergeTableDataBlocks(SSqlObj* pSql, SArray* pTableDataBlockList) {
|
||||||
}
|
}
|
||||||
|
|
||||||
SSubmitBlk* pBlocks = (SSubmitBlk*) pOneTableBlock->pData;
|
SSubmitBlk* pBlocks = (SSubmitBlk*) pOneTableBlock->pData;
|
||||||
int64_t destSize = dataBuf->size + pOneTableBlock->size + pBlocks->numOfRows * expandSize;
|
int64_t destSize = dataBuf->size + pOneTableBlock->size + pBlocks->numOfRows * expandSize + sizeof(STColumn) * tscGetNumOfColumns(pOneTableBlock->pTableMeta);
|
||||||
|
|
||||||
if (dataBuf->nAllocSize < destSize) {
|
if (dataBuf->nAllocSize < destSize) {
|
||||||
while (dataBuf->nAllocSize < destSize) {
|
while (dataBuf->nAllocSize < destSize) {
|
||||||
|
@ -691,7 +691,7 @@ int32_t tscMergeTableDataBlocks(SSqlObj* pSql, SArray* pTableDataBlockList) {
|
||||||
tscDebug("%p tableId:%s, sid:%d rows:%d sversion:%d skey:%" PRId64 ", ekey:%" PRId64, pSql, pOneTableBlock->tableId,
|
tscDebug("%p tableId:%s, sid:%d rows:%d sversion:%d skey:%" PRId64 ", ekey:%" PRId64, pSql, pOneTableBlock->tableId,
|
||||||
pBlocks->tid, pBlocks->numOfRows, pBlocks->sversion, GET_INT64_VAL(pBlocks->data), GET_INT64_VAL(ekey));
|
pBlocks->tid, pBlocks->numOfRows, pBlocks->sversion, GET_INT64_VAL(pBlocks->data), GET_INT64_VAL(ekey));
|
||||||
|
|
||||||
int32_t len = pBlocks->numOfRows * (pOneTableBlock->rowSize + expandSize);
|
int32_t len = pBlocks->numOfRows * (pOneTableBlock->rowSize + expandSize) + sizeof(STColumn) * tscGetNumOfColumns(pOneTableBlock->pTableMeta);
|
||||||
|
|
||||||
pBlocks->tid = htonl(pBlocks->tid);
|
pBlocks->tid = htonl(pBlocks->tid);
|
||||||
pBlocks->uid = htobe64(pBlocks->uid);
|
pBlocks->uid = htobe64(pBlocks->uid);
|
||||||
|
@ -1464,16 +1464,6 @@ STableMetaInfo* tscGetMetaInfo(SQueryInfo* pQueryInfo, int32_t tableIndex) {
|
||||||
return pQueryInfo->pTableMetaInfo[tableIndex];
|
return pQueryInfo->pTableMetaInfo[tableIndex];
|
||||||
}
|
}
|
||||||
|
|
||||||
SQueryInfo* tscGetQueryInfoDetail(SSqlCmd* pCmd, int32_t subClauseIndex) {
|
|
||||||
assert(pCmd != NULL && subClauseIndex >= 0 && subClauseIndex < TSDB_MAX_UNION_CLAUSE);
|
|
||||||
|
|
||||||
if (pCmd->pQueryInfo == NULL || subClauseIndex >= pCmd->numOfClause) {
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
return pCmd->pQueryInfo[subClauseIndex];
|
|
||||||
}
|
|
||||||
|
|
||||||
int32_t tscGetQueryInfoDetailSafely(SSqlCmd* pCmd, int32_t subClauseIndex, SQueryInfo** pQueryInfo) {
|
int32_t tscGetQueryInfoDetailSafely(SSqlCmd* pCmd, int32_t subClauseIndex, SQueryInfo** pQueryInfo) {
|
||||||
int32_t ret = TSDB_CODE_SUCCESS;
|
int32_t ret = TSDB_CODE_SUCCESS;
|
||||||
|
|
||||||
|
@ -1832,7 +1822,6 @@ SSqlObj* createSubqueryObj(SSqlObj* pSql, int16_t tableIndex, void (*fp)(), void
|
||||||
STableMeta* pPrevTableMeta = taosCacheTransfer(tscCacheHandle, (void**)&pPrevInfo->pTableMeta);
|
STableMeta* pPrevTableMeta = taosCacheTransfer(tscCacheHandle, (void**)&pPrevInfo->pTableMeta);
|
||||||
|
|
||||||
SVgroupsInfo* pVgroupsInfo = pPrevInfo->vgroupList;
|
SVgroupsInfo* pVgroupsInfo = pPrevInfo->vgroupList;
|
||||||
pPrevInfo->vgroupList = NULL;
|
|
||||||
pFinalInfo = tscAddTableMetaInfo(pNewQueryInfo, name, pPrevTableMeta, pVgroupsInfo, pTableMetaInfo->tagColList);
|
pFinalInfo = tscAddTableMetaInfo(pNewQueryInfo, name, pPrevTableMeta, pVgroupsInfo, pTableMetaInfo->tagColList);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2097,7 +2086,7 @@ void tscTryQueryNextClause(SSqlObj* pSql, void (*queryFp)()) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void tscGetResultColumnChr(SSqlRes* pRes, SFieldInfo* pFieldInfo, int32_t columnIndex) {
|
void tscGetResultColumnChr(SSqlRes* pRes, SFieldInfo* pFieldInfo, int32_t columnIndex) {
|
||||||
SFieldSupInfo* pInfo = taosArrayGet(pFieldInfo->pSupportInfo, columnIndex);//tscFieldInfoGetSupp(pFieldInfo, columnIndex);
|
SFieldSupInfo* pInfo = taosArrayGet(pFieldInfo->pSupportInfo, columnIndex);
|
||||||
assert(pInfo->pSqlExpr != NULL);
|
assert(pInfo->pSqlExpr != NULL);
|
||||||
|
|
||||||
int32_t type = pInfo->pSqlExpr->resType;
|
int32_t type = pInfo->pSqlExpr->resType;
|
||||||
|
@ -2112,7 +2101,7 @@ void tscGetResultColumnChr(SSqlRes* pRes, SFieldInfo* pFieldInfo, int32_t column
|
||||||
if (isNull(pData, type)) {
|
if (isNull(pData, type)) {
|
||||||
pRes->tsrow[columnIndex] = NULL;
|
pRes->tsrow[columnIndex] = NULL;
|
||||||
} else {
|
} else {
|
||||||
pRes->tsrow[columnIndex] = pData + VARSTR_HEADER_SIZE;
|
pRes->tsrow[columnIndex] = ((tstr*)pData)->data;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (realLen < pInfo->pSqlExpr->resBytes - VARSTR_HEADER_SIZE) { // todo refactor
|
if (realLen < pInfo->pSqlExpr->resBytes - VARSTR_HEADER_SIZE) { // todo refactor
|
||||||
|
|
|
@ -3,6 +3,7 @@
|
||||||
|
|
||||||
#include "os.h"
|
#include "os.h"
|
||||||
#include "taosmsg.h"
|
#include "taosmsg.h"
|
||||||
|
#include "tstoken.h"
|
||||||
|
|
||||||
typedef struct SDataStatis {
|
typedef struct SDataStatis {
|
||||||
int16_t colId;
|
int16_t colId;
|
||||||
|
@ -23,10 +24,14 @@ void extractTableName(const char *tableId, char *name);
|
||||||
|
|
||||||
char* extractDBName(const char *tableId, char *name);
|
char* extractDBName(const char *tableId, char *name);
|
||||||
|
|
||||||
|
void extractTableNameFromToken(SSQLToken *pToken, SSQLToken* pTable);
|
||||||
|
|
||||||
SSchema tGetTableNameColumnSchema();
|
SSchema tGetTableNameColumnSchema();
|
||||||
|
|
||||||
bool tscValidateTableNameLength(size_t len);
|
bool tscValidateTableNameLength(size_t len);
|
||||||
|
|
||||||
SColumnFilterInfo* tscFilterInfoClone(const SColumnFilterInfo* src, int32_t numOfFilters);
|
SColumnFilterInfo* tscFilterInfoClone(const SColumnFilterInfo* src, int32_t numOfFilters);
|
||||||
|
|
||||||
|
int64_t taosGetIntervalStartTimestamp(int64_t startTime, int64_t slidingTime, int64_t intervalTime, char timeUnit, int16_t precision);
|
||||||
|
|
||||||
#endif // TDENGINE_NAME_H
|
#endif // TDENGINE_NAME_H
|
||||||
|
|
|
@ -32,9 +32,6 @@ extern int32_t tscEmbedded;
|
||||||
#define uDebug(...) { if (uDebugFlag & DEBUG_DEBUG) { taosPrintLog("UTL DEBUG ", uDebugFlag, __VA_ARGS__); }}
|
#define uDebug(...) { if (uDebugFlag & DEBUG_DEBUG) { taosPrintLog("UTL DEBUG ", uDebugFlag, __VA_ARGS__); }}
|
||||||
#define uTrace(...) { if (uDebugFlag & DEBUG_TRACE) { taosPrintLog("UTL TRACE ", uDebugFlag, __VA_ARGS__); }}
|
#define uTrace(...) { if (uDebugFlag & DEBUG_TRACE) { taosPrintLog("UTL TRACE ", uDebugFlag, __VA_ARGS__); }}
|
||||||
|
|
||||||
#define uDebugDump(...) { if (uDebugFlag & DEBUG_DEBUG) { taosPrintLongString("UTL DEBUG ", uDebugFlag, __VA_ARGS__); }}
|
|
||||||
#define uTraceDump(...) { if (uDebugFlag & DEBUG_TRACE) { taosPrintLongString("UTL TRACE ", uDebugFlag, __VA_ARGS__); }}
|
|
||||||
|
|
||||||
#define pError(...) { taosPrintLog("APP ERROR ", 255, __VA_ARGS__); }
|
#define pError(...) { taosPrintLog("APP ERROR ", 255, __VA_ARGS__); }
|
||||||
#define pPrint(...) { taosPrintLog("APP INFO ", 255, __VA_ARGS__); }
|
#define pPrint(...) { taosPrintLog("APP INFO ", 255, __VA_ARGS__); }
|
||||||
|
|
||||||
|
|
|
@ -129,7 +129,7 @@ int32_t tsMnodeEqualVnodeNum = 4;
|
||||||
int32_t tsEnableHttpModule = 1;
|
int32_t tsEnableHttpModule = 1;
|
||||||
int32_t tsRestRowLimit = 10240;
|
int32_t tsRestRowLimit = 10240;
|
||||||
uint16_t tsHttpPort = 6020; // only tcp, range tcp[6020]
|
uint16_t tsHttpPort = 6020; // only tcp, range tcp[6020]
|
||||||
int32_t tsHttpCacheSessions = 100;
|
int32_t tsHttpCacheSessions = 1000;
|
||||||
int32_t tsHttpSessionExpire = 36000;
|
int32_t tsHttpSessionExpire = 36000;
|
||||||
int32_t tsHttpMaxThreads = 2;
|
int32_t tsHttpMaxThreads = 2;
|
||||||
int32_t tsHttpEnableCompress = 0;
|
int32_t tsHttpEnableCompress = 0;
|
||||||
|
@ -1210,7 +1210,7 @@ void taosInitGlobalCfg() {
|
||||||
}
|
}
|
||||||
|
|
||||||
bool taosCheckGlobalCfg() {
|
bool taosCheckGlobalCfg() {
|
||||||
if (debugFlag & DEBUG_TRACE || debugFlag & DEBUG_DEBUG) {
|
if (debugFlag & DEBUG_TRACE || debugFlag & DEBUG_DEBUG || debugFlag & DEBUG_DUMP) {
|
||||||
taosSetAllDebugFlag();
|
taosSetAllDebugFlag();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -75,3 +75,56 @@ SColumnFilterInfo* tscFilterInfoClone(const SColumnFilterInfo* src, int32_t numO
|
||||||
|
|
||||||
return pFilter;
|
return pFilter;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int64_t taosGetIntervalStartTimestamp(int64_t startTime, int64_t slidingTime, int64_t intervalTime, char timeUnit, int16_t precision) {
|
||||||
|
if (slidingTime == 0) {
|
||||||
|
return startTime;
|
||||||
|
}
|
||||||
|
|
||||||
|
int64_t start = ((startTime - intervalTime) / slidingTime + 1) * slidingTime;
|
||||||
|
if (!(timeUnit == 'a' || timeUnit == 'm' || timeUnit == 's' || timeUnit == 'h')) {
|
||||||
|
/*
|
||||||
|
* here we revised the start time of day according to the local time zone,
|
||||||
|
* but in case of DST, the start time of one day need to be dynamically decided.
|
||||||
|
*/
|
||||||
|
// todo refactor to extract function that is available for Linux/Windows/Mac platform
|
||||||
|
#if defined(WINDOWS) && _MSC_VER >= 1900
|
||||||
|
// see https://docs.microsoft.com/en-us/cpp/c-runtime-library/daylight-dstbias-timezone-and-tzname?view=vs-2019
|
||||||
|
int64_t timezone = _timezone;
|
||||||
|
int32_t daylight = _daylight;
|
||||||
|
char** tzname = _tzname;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
int64_t t = (precision == TSDB_TIME_PRECISION_MILLI) ? MILLISECOND_PER_SECOND : MILLISECOND_PER_SECOND * 1000L;
|
||||||
|
start += timezone * t;
|
||||||
|
}
|
||||||
|
|
||||||
|
int64_t end = start + intervalTime - 1;
|
||||||
|
if (end < startTime) {
|
||||||
|
start += slidingTime;
|
||||||
|
}
|
||||||
|
return start;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* tablePrefix.columnName
|
||||||
|
* extract table name and save it in pTable, with only column name in pToken
|
||||||
|
*/
|
||||||
|
void extractTableNameFromToken(SSQLToken* pToken, SSQLToken* pTable) {
|
||||||
|
const char sep = TS_PATH_DELIMITER[0];
|
||||||
|
|
||||||
|
if (pToken == pTable || pToken == NULL || pTable == NULL) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
char* r = strnchr(pToken->z, sep, pToken->n, false);
|
||||||
|
|
||||||
|
if (r != NULL) { // record the table name token
|
||||||
|
pTable->n = r - pToken->z;
|
||||||
|
pTable->z = pToken->z;
|
||||||
|
|
||||||
|
r += 1;
|
||||||
|
pToken->n -= (r - pToken->z);
|
||||||
|
pToken->z = r;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -1,44 +0,0 @@
|
||||||
#!/bin/bash
|
|
||||||
ulimit -c unlimited
|
|
||||||
|
|
||||||
function buildTDengine {
|
|
||||||
cd /root/TDengine
|
|
||||||
|
|
||||||
git remote update
|
|
||||||
REMOTE_COMMIT=`git rev-parse --short remotes/origin/develop`
|
|
||||||
LOCAL_COMMIT=`git rev-parse --short @`
|
|
||||||
|
|
||||||
echo " LOCAL: $LOCAL_COMMIT"
|
|
||||||
echo "REMOTE: $REMOTE_COMMIT"
|
|
||||||
if [ "$LOCAL_COMMIT" == "$REMOTE_COMMIT" ]; then
|
|
||||||
echo "repo up-to-date"
|
|
||||||
else
|
|
||||||
echo "repo need to pull"
|
|
||||||
git pull
|
|
||||||
|
|
||||||
LOCAL_COMMIT=`git rev-parse --short @`
|
|
||||||
cd /root/TDengine/debug
|
|
||||||
rm -rf /root/TDengine/debug/*
|
|
||||||
cmake ..
|
|
||||||
make > /dev/null
|
|
||||||
make install
|
|
||||||
fi
|
|
||||||
}
|
|
||||||
|
|
||||||
function restartTaosd {
|
|
||||||
systemctl stop taosd
|
|
||||||
pkill -KILL -x taosd
|
|
||||||
sleep 10
|
|
||||||
|
|
||||||
logDir=`grep 'logDir' /etc/taos/taos.cfg|awk 'END{print $2}'`
|
|
||||||
dataDir=`grep 'dataDir' /etc/taos/taos.cfg|awk '{print $2}'`
|
|
||||||
|
|
||||||
rm -rf $logDir/*
|
|
||||||
rm -rf $dataDir/*
|
|
||||||
|
|
||||||
taosd 2>&1 > /dev/null &
|
|
||||||
sleep 10
|
|
||||||
}
|
|
||||||
|
|
||||||
buildTDengine
|
|
||||||
restartTaosd
|
|
|
@ -0,0 +1,236 @@
|
||||||
|
package com.taosdata.jdbc.utils;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.util.*;
|
||||||
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
|
public class TDNode {
|
||||||
|
|
||||||
|
private int index;
|
||||||
|
private int running;
|
||||||
|
private int deployed;
|
||||||
|
private boolean testCluster;
|
||||||
|
private String path;
|
||||||
|
private String cfgDir;
|
||||||
|
private String dataDir;
|
||||||
|
private String logDir;
|
||||||
|
private String cfgPath;
|
||||||
|
|
||||||
|
public TDNode(int index) {
|
||||||
|
this.index = index;
|
||||||
|
running = 0;
|
||||||
|
deployed = 0;
|
||||||
|
testCluster = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setPath(String path) {
|
||||||
|
this.path = path;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setTestCluster(boolean testCluster) {
|
||||||
|
this.testCluster = testCluster;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void searchTaosd(File dir, ArrayList<String> taosdPath) {
|
||||||
|
File[] fileList = dir.listFiles();
|
||||||
|
|
||||||
|
if(fileList == null || fileList.length == 0) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
for(File file : fileList) {
|
||||||
|
if(file.isFile()) {
|
||||||
|
if(file.getName().equals("taosd")) {
|
||||||
|
taosdPath.add(file.getAbsolutePath());
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
searchTaosd(file, taosdPath);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void start() {
|
||||||
|
String selfPath = System.getProperty("user.dir");
|
||||||
|
String binPath = "";
|
||||||
|
String projDir = selfPath + "/../../../../";
|
||||||
|
|
||||||
|
try {
|
||||||
|
ArrayList<String> taosdPath = new ArrayList<>();
|
||||||
|
|
||||||
|
File dir = new File(projDir);
|
||||||
|
String realProjDir = dir.getCanonicalPath();
|
||||||
|
dir = new File(realProjDir);
|
||||||
|
System.out.println("project Dir: " + projDir);
|
||||||
|
searchTaosd(dir, taosdPath);
|
||||||
|
|
||||||
|
if(taosdPath.size() == 0) {
|
||||||
|
System.out.println("The project path doens't exist");
|
||||||
|
return;
|
||||||
|
} else {
|
||||||
|
for(String p : taosdPath) {
|
||||||
|
if(!p.contains("packing")) {
|
||||||
|
binPath = p;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
|
||||||
|
if(binPath.isEmpty()) {
|
||||||
|
System.out.println("taosd not found");
|
||||||
|
return;
|
||||||
|
} else {
|
||||||
|
System.out.println("taosd found in " + binPath);
|
||||||
|
}
|
||||||
|
|
||||||
|
if(this.deployed == 0) {
|
||||||
|
System.out.println("dnode" + index + "is not deployed");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
String cmd = "nohup " + binPath + " -c " + cfgDir + " > /dev/null 2>&1 & ";
|
||||||
|
System.out.println("start taosd cmd: " + cmd);
|
||||||
|
|
||||||
|
try{
|
||||||
|
Runtime.getRuntime().exec(cmd);
|
||||||
|
TimeUnit.SECONDS.sleep(5);
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
|
||||||
|
this.running = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void stop() {
|
||||||
|
String toBeKilled = "taosd";
|
||||||
|
|
||||||
|
if (this.running != 0) {
|
||||||
|
String killCmd = "pkill -kill -x " + toBeKilled;
|
||||||
|
String[] killCmds = {"sh", "-c", killCmd};
|
||||||
|
try {
|
||||||
|
Runtime.getRuntime().exec(killCmds).waitFor();
|
||||||
|
|
||||||
|
for(int port = 6030; port < 6041; port ++) {
|
||||||
|
String fuserCmd = "fuser -k -n tcp " + port;
|
||||||
|
Runtime.getRuntime().exec(fuserCmd).waitFor();
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
|
||||||
|
this.running = 0;
|
||||||
|
System.out.println("dnode:" + this.index + " is stopped by pkill");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void startIP() {
|
||||||
|
try{
|
||||||
|
String cmd = "sudo ifconfig lo:" + index + "192.168.0." + index + " up";
|
||||||
|
Runtime.getRuntime().exec(cmd).waitFor();
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void stopIP() {
|
||||||
|
try{
|
||||||
|
String cmd = "sudo ifconfig lo:" + index + "192.168.0." + index + " down";
|
||||||
|
Runtime.getRuntime().exec(cmd).waitFor();
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setCfgConfig(String option, String value) {
|
||||||
|
try{
|
||||||
|
String cmd = "echo " + option + " " + value + " >> " + this.cfgPath;
|
||||||
|
String[] cmdLine = {"sh", "-c", cmd};
|
||||||
|
Process ps = Runtime.getRuntime().exec(cmdLine);
|
||||||
|
ps.waitFor();
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getDnodeRootDir() {
|
||||||
|
String dnodeRootDir = this.path + "/sim/psim/dnode" + this.index;
|
||||||
|
return dnodeRootDir;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getDnodesRootDir() {
|
||||||
|
String dnodesRootDir = this.path + "/sim/psim" + this.index;
|
||||||
|
return dnodesRootDir;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void deploy() {
|
||||||
|
this.logDir = this.path + "/sim/dnode" + this.index + "/log";
|
||||||
|
this.dataDir = this.path + "/sim/dnode" + this.index + "/data";
|
||||||
|
this.cfgDir = this.path + "/sim/dnode" + this.index + "/cfg";
|
||||||
|
this.cfgPath = this.path + "/sim/dnode" + this.index + "/cfg/taos.cfg";
|
||||||
|
|
||||||
|
try {
|
||||||
|
String cmd = "rm -rf " + this.logDir;
|
||||||
|
Runtime.getRuntime().exec(cmd).waitFor();
|
||||||
|
|
||||||
|
cmd = "rm -rf " + this.cfgDir;
|
||||||
|
Runtime.getRuntime().exec(cmd).waitFor();
|
||||||
|
|
||||||
|
cmd = "rm -rf " + this.dataDir;
|
||||||
|
Runtime.getRuntime().exec(cmd).waitFor();
|
||||||
|
|
||||||
|
cmd = "mkdir -p " + this.logDir;
|
||||||
|
Runtime.getRuntime().exec(cmd).waitFor();
|
||||||
|
|
||||||
|
cmd = "mkdir -p " + this.cfgDir;
|
||||||
|
Runtime.getRuntime().exec(cmd).waitFor();
|
||||||
|
|
||||||
|
cmd = "mkdir -p " + this.dataDir;
|
||||||
|
Runtime.getRuntime().exec(cmd).waitFor();
|
||||||
|
|
||||||
|
cmd = "touch " + this.cfgPath;
|
||||||
|
Runtime.getRuntime().exec(cmd).waitFor();
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
|
||||||
|
if(this.testCluster) {
|
||||||
|
startIP();
|
||||||
|
setCfgConfig("masterIp", "192.168.0.1");
|
||||||
|
setCfgConfig("secondIp", "192.168.0.2");
|
||||||
|
setCfgConfig("publicIp", "192.168.0." + this.index);
|
||||||
|
setCfgConfig("internalIp", "192.168.0." + this.index);
|
||||||
|
setCfgConfig("privateIp", "192.168.0." + this.index);
|
||||||
|
}
|
||||||
|
setCfgConfig("dataDir", this.dataDir);
|
||||||
|
setCfgConfig("logDir", this.logDir);
|
||||||
|
setCfgConfig("numOfLogLines", "1000000/00");
|
||||||
|
setCfgConfig("mnodeEqualVnodeNum", "0");
|
||||||
|
setCfgConfig("walLevel", "1");
|
||||||
|
setCfgConfig("statusInterval", "1");
|
||||||
|
setCfgConfig("numOfTotalVnodes", "64");
|
||||||
|
setCfgConfig("numOfMnodes", "3");
|
||||||
|
setCfgConfig("numOfThreadsPerCore", "2.0");
|
||||||
|
setCfgConfig("monitor", "0");
|
||||||
|
setCfgConfig("maxVnodeConnections", "30000");
|
||||||
|
setCfgConfig("maxMgmtConnections", "30000");
|
||||||
|
setCfgConfig("maxMeterConnections", "30000");
|
||||||
|
setCfgConfig("maxShellConns", "30000");
|
||||||
|
setCfgConfig("locale", "en_US.UTF-8");
|
||||||
|
setCfgConfig("charset", "UTF-8");
|
||||||
|
setCfgConfig("asyncLog", "0");
|
||||||
|
setCfgConfig("anyIp", "0");
|
||||||
|
setCfgConfig("dDebugFlag", "135");
|
||||||
|
setCfgConfig("mDebugFlag", "135");
|
||||||
|
setCfgConfig("sdbDebugFlag", "135");
|
||||||
|
setCfgConfig("rpcDebugFlag", "135");
|
||||||
|
setCfgConfig("tmrDebugFlag", "131");
|
||||||
|
setCfgConfig("cDebugFlag", "135");
|
||||||
|
setCfgConfig("httpDebugFlag", "135");
|
||||||
|
setCfgConfig("monitorDebugFlag", "135");
|
||||||
|
setCfgConfig("udebugFlag", "135");
|
||||||
|
setCfgConfig("jnidebugFlag", "135");
|
||||||
|
setCfgConfig("qdebugFlag", "135");
|
||||||
|
this.deployed = 1;
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,94 @@
|
||||||
|
package com.taosdata.jdbc.utils;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.util.*;
|
||||||
|
|
||||||
|
public class TDNodes {
|
||||||
|
private ArrayList<TDNode> tdNodes;
|
||||||
|
private boolean testCluster;
|
||||||
|
|
||||||
|
public TDNodes () {
|
||||||
|
tdNodes = new ArrayList<>();
|
||||||
|
for(int i = 1; i < 11; i ++) {
|
||||||
|
tdNodes.add(new TDNode(i));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setPath(String path) {
|
||||||
|
try {
|
||||||
|
String killCmd = "pkill -kill -x taosd";
|
||||||
|
String[] killCmds = {"sh", "-c", killCmd};
|
||||||
|
Runtime.getRuntime().exec(killCmds).waitFor();
|
||||||
|
|
||||||
|
String binPath = System.getProperty("user.dir");
|
||||||
|
binPath += "/../../../debug";
|
||||||
|
System.out.println("binPath: " + binPath);
|
||||||
|
|
||||||
|
File file = new File(path);
|
||||||
|
binPath = file.getCanonicalPath();
|
||||||
|
System.out.println("binPath real path: " + binPath);
|
||||||
|
|
||||||
|
if(path.isEmpty()){
|
||||||
|
file = new File(path + "/../../");
|
||||||
|
path = file.getCanonicalPath();
|
||||||
|
}
|
||||||
|
|
||||||
|
for(int i = 0; i < tdNodes.size(); i++) {
|
||||||
|
tdNodes.get(i).setPath(path);
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setTestCluster(boolean testCluster) {
|
||||||
|
this.testCluster = testCluster;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void check(int index) {
|
||||||
|
if(index < 1 || index > 10) {
|
||||||
|
System.out.println("index: " + index + " should on a scale of [1, 10]");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void deploy(int index) {
|
||||||
|
try {
|
||||||
|
File file = new File(System.getProperty("user.dir") + "/../../../");
|
||||||
|
String projectRealPath = file.getCanonicalPath();
|
||||||
|
check(index);
|
||||||
|
tdNodes.get(index - 1).setTestCluster(this.testCluster);
|
||||||
|
tdNodes.get(index - 1).setPath(projectRealPath);
|
||||||
|
tdNodes.get(index - 1).deploy();
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
System.out.println("deploy Test Exception");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void cfg(int index, String option, String value) {
|
||||||
|
check(index);
|
||||||
|
tdNodes.get(index - 1).setCfgConfig(option, value);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void start(int index) {
|
||||||
|
check(index);
|
||||||
|
tdNodes.get(index - 1).start();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void stop(int index) {
|
||||||
|
check(index);
|
||||||
|
tdNodes.get(index - 1).stop();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void startIP(int index) {
|
||||||
|
check(index);
|
||||||
|
tdNodes.get(index - 1).startIP();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void stopIP(int index) {
|
||||||
|
check(index);
|
||||||
|
tdNodes.get(index - 1).stopIP();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -1,27 +1,38 @@
|
||||||
package com.taosdata.jdbc;
|
package com.taosdata.jdbc;
|
||||||
|
|
||||||
import java.io.BufferedReader;
|
import java.io.File;
|
||||||
import java.io.InputStreamReader;
|
import com.taosdata.jdbc.utils.TDNodes;
|
||||||
|
|
||||||
|
import org.junit.AfterClass;
|
||||||
import org.junit.BeforeClass;
|
import org.junit.BeforeClass;
|
||||||
|
|
||||||
public class BaseTest {
|
public class BaseTest {
|
||||||
|
|
||||||
|
private static boolean testCluster = false;
|
||||||
|
private static String deployPath = System.getProperty("user.dir");
|
||||||
|
private static TDNodes tdNodes = new TDNodes();
|
||||||
|
|
||||||
|
|
||||||
@BeforeClass
|
@BeforeClass
|
||||||
public static void setupEnv() {
|
public static void setupEnv() {
|
||||||
try{
|
try{
|
||||||
String path = System.getProperty("user.dir");
|
File file = new File(deployPath + "/../../../");
|
||||||
String bashPath = path + "/buildTDengine.sh";
|
String rootPath = file.getCanonicalPath();
|
||||||
|
|
||||||
Process ps = Runtime.getRuntime().exec(bashPath);
|
tdNodes.setPath(rootPath);
|
||||||
ps.waitFor();
|
tdNodes.setTestCluster(testCluster);
|
||||||
|
|
||||||
|
tdNodes.deploy(1);
|
||||||
|
tdNodes.start(1);
|
||||||
|
|
||||||
BufferedReader br = new BufferedReader(new InputStreamReader(ps.getInputStream()));
|
|
||||||
while(br.readLine() != null) {
|
|
||||||
System.out.println(br.readLine());
|
|
||||||
}
|
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
|
System.out.println("Base Test Exception");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@AfterClass
|
||||||
|
public static void cleanUpEnv() {
|
||||||
|
tdNodes.stop(1);
|
||||||
|
}
|
||||||
}
|
}
|
|
@ -1,6 +1,7 @@
|
||||||
from .cinterface import CTaosInterface
|
from .cinterface import CTaosInterface
|
||||||
from .error import *
|
from .error import *
|
||||||
from .constants import FieldType
|
from .constants import FieldType
|
||||||
|
import threading
|
||||||
|
|
||||||
# querySeqNum = 0
|
# querySeqNum = 0
|
||||||
|
|
||||||
|
@ -37,6 +38,7 @@ class TDengineCursor(object):
|
||||||
self._block_iter = 0
|
self._block_iter = 0
|
||||||
self._affected_rows = 0
|
self._affected_rows = 0
|
||||||
self._logfile = ""
|
self._logfile = ""
|
||||||
|
self._threadId = threading.get_ident()
|
||||||
|
|
||||||
if connection is not None:
|
if connection is not None:
|
||||||
self._connection = connection
|
self._connection = connection
|
||||||
|
@ -103,6 +105,12 @@ class TDengineCursor(object):
|
||||||
def execute(self, operation, params=None):
|
def execute(self, operation, params=None):
|
||||||
"""Prepare and execute a database operation (query or command).
|
"""Prepare and execute a database operation (query or command).
|
||||||
"""
|
"""
|
||||||
|
# if threading.get_ident() != self._threadId:
|
||||||
|
# info ="Cursor execute:Thread ID not match,creater:"+str(self._threadId)+" caller:"+str(threading.get_ident())
|
||||||
|
# raise OperationalError(info)
|
||||||
|
# print(info)
|
||||||
|
# return None
|
||||||
|
|
||||||
if not operation:
|
if not operation:
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
@ -188,6 +196,11 @@ class TDengineCursor(object):
|
||||||
def fetchall(self):
|
def fetchall(self):
|
||||||
"""Fetch all (remaining) rows of a query result, returning them as a sequence of sequences (e.g. a list of tuples). Note that the cursor's arraysize attribute can affect the performance of this operation.
|
"""Fetch all (remaining) rows of a query result, returning them as a sequence of sequences (e.g. a list of tuples). Note that the cursor's arraysize attribute can affect the performance of this operation.
|
||||||
"""
|
"""
|
||||||
|
# if threading.get_ident() != self._threadId:
|
||||||
|
# info ="[WARNING] Cursor fetchall:Thread ID not match,creater:"+str(self._threadId)+" caller:"+str(threading.get_ident())
|
||||||
|
# raise OperationalError(info)
|
||||||
|
# print(info)
|
||||||
|
# return None
|
||||||
if self._result is None or self._fields is None:
|
if self._result is None or self._fields is None:
|
||||||
raise OperationalError("Invalid use of fetchall")
|
raise OperationalError("Invalid use of fetchall")
|
||||||
|
|
||||||
|
@ -232,6 +245,12 @@ class TDengineCursor(object):
|
||||||
def _handle_result(self):
|
def _handle_result(self):
|
||||||
"""Handle the return result from query.
|
"""Handle the return result from query.
|
||||||
"""
|
"""
|
||||||
|
# if threading.get_ident() != self._threadId:
|
||||||
|
# info = "Cursor handleresult:Thread ID not match,creater:"+str(self._threadId)+" caller:"+str(threading.get_ident())
|
||||||
|
# raise OperationalError(info)
|
||||||
|
# print(info)
|
||||||
|
# return None
|
||||||
|
|
||||||
self._description = []
|
self._description = []
|
||||||
for ele in self._fields:
|
for ele in self._fields:
|
||||||
self._description.append(
|
self._description.append(
|
||||||
|
|
|
@ -109,6 +109,8 @@ void cqClose(void *handle) {
|
||||||
while (pObj) {
|
while (pObj) {
|
||||||
SCqObj *pTemp = pObj;
|
SCqObj *pTemp = pObj;
|
||||||
pObj = pObj->next;
|
pObj = pObj->next;
|
||||||
|
tdFreeSchema(pTemp->pSchema);
|
||||||
|
tfree(pTemp->sqlStr);
|
||||||
free(pTemp);
|
free(pTemp);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -242,6 +244,10 @@ static void cqCreateStream(SCqContext *pContext, SCqObj *pObj) {
|
||||||
|
|
||||||
static void cqProcessStreamRes(void *param, TAOS_RES *tres, TAOS_ROW row) {
|
static void cqProcessStreamRes(void *param, TAOS_RES *tres, TAOS_ROW row) {
|
||||||
SCqObj *pObj = (SCqObj *)param;
|
SCqObj *pObj = (SCqObj *)param;
|
||||||
|
if (tres == NULL && row == NULL) {
|
||||||
|
pObj->pStream = NULL;
|
||||||
|
return;
|
||||||
|
}
|
||||||
SCqContext *pContext = pObj->pContext;
|
SCqContext *pContext = pObj->pContext;
|
||||||
STSchema *pSchema = pObj->pSchema;
|
STSchema *pSchema = pObj->pSchema;
|
||||||
if (pObj->pStream == NULL) return;
|
if (pObj->pStream == NULL) return;
|
||||||
|
@ -263,8 +269,14 @@ static void cqProcessStreamRes(void *param, TAOS_RES *tres, TAOS_ROW row) {
|
||||||
void* val = row[i];
|
void* val = row[i];
|
||||||
if (val == NULL) {
|
if (val == NULL) {
|
||||||
val = getNullValue(c->type);
|
val = getNullValue(c->type);
|
||||||
} else if (IS_VAR_DATA_TYPE(c->type)) {
|
} else if (c->type == TSDB_DATA_TYPE_BINARY) {
|
||||||
val = ((char*)val) - sizeof(VarDataLenT);
|
val = ((char*)val) - sizeof(VarDataLenT);
|
||||||
|
} else if (c->type == TSDB_DATA_TYPE_NCHAR) {
|
||||||
|
char buf[TSDB_MAX_NCHAR_LEN];
|
||||||
|
size_t len = taos_fetch_lengths(tres)[i];
|
||||||
|
taosMbsToUcs4(val, len, buf, sizeof(buf), &len);
|
||||||
|
memcpy(val + sizeof(VarDataLenT), buf, len);
|
||||||
|
varDataLen(val) = len;
|
||||||
}
|
}
|
||||||
tdAppendColVal(trow, val, c->type, c->bytes, c->offset);
|
tdAppendColVal(trow, val, c->type, c->bytes, c->offset);
|
||||||
}
|
}
|
||||||
|
|
|
@ -22,6 +22,8 @@ extern "C" {
|
||||||
|
|
||||||
int32_t dnodeInitMgmt();
|
int32_t dnodeInitMgmt();
|
||||||
void dnodeCleanupMgmt();
|
void dnodeCleanupMgmt();
|
||||||
|
int32_t dnodeInitMgmtTimer();
|
||||||
|
void dnodeCleanupMgmtTimer();
|
||||||
void dnodeDispatchToMgmtQueue(SRpcMsg *rpcMsg);
|
void dnodeDispatchToMgmtQueue(SRpcMsg *rpcMsg);
|
||||||
|
|
||||||
void* dnodeGetVnode(int32_t vgId);
|
void* dnodeGetVnode(int32_t vgId);
|
||||||
|
|
|
@ -131,8 +131,8 @@ static void dnodeFreeMnodeWriteMsg(SMnodeMsg *pWrite) {
|
||||||
taosFreeQitem(pWrite);
|
taosFreeQitem(pWrite);
|
||||||
}
|
}
|
||||||
|
|
||||||
void dnodeSendRpcMnodeWriteRsp(void *pRaw, int32_t code) {
|
void dnodeSendRpcMnodeWriteRsp(void *pMsg, int32_t code) {
|
||||||
SMnodeMsg *pWrite = pRaw;
|
SMnodeMsg *pWrite = pMsg;
|
||||||
if (pWrite == NULL) return;
|
if (pWrite == NULL) return;
|
||||||
if (code == TSDB_CODE_MND_ACTION_IN_PROGRESS) return;
|
if (code == TSDB_CODE_MND_ACTION_IN_PROGRESS) return;
|
||||||
if (code == TSDB_CODE_MND_ACTION_NEED_REPROCESSED) {
|
if (code == TSDB_CODE_MND_ACTION_NEED_REPROCESSED) {
|
||||||
|
|
|
@ -57,6 +57,7 @@ static const SDnodeComponent tsDnodeComponents[] = {
|
||||||
{"server", dnodeInitServer, dnodeCleanupServer},
|
{"server", dnodeInitServer, dnodeCleanupServer},
|
||||||
{"mgmt", dnodeInitMgmt, dnodeCleanupMgmt},
|
{"mgmt", dnodeInitMgmt, dnodeCleanupMgmt},
|
||||||
{"modules", dnodeInitModules, dnodeCleanupModules},
|
{"modules", dnodeInitModules, dnodeCleanupModules},
|
||||||
|
{"mgmt-tmr",dnodeInitMgmtTimer, dnodeCleanupMgmtTimer},
|
||||||
{"shell", dnodeInitShell, dnodeCleanupShell}
|
{"shell", dnodeInitShell, dnodeCleanupShell}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -106,6 +106,12 @@ int32_t dnodeInitMgmt() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int32_t code = vnodeInitResources();
|
||||||
|
if (code != TSDB_CODE_SUCCESS) {
|
||||||
|
dnodeCleanupMgmt();
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
// create the queue and thread to handle the message
|
// create the queue and thread to handle the message
|
||||||
tsMgmtQset = taosOpenQset();
|
tsMgmtQset = taosOpenQset();
|
||||||
if (tsMgmtQset == NULL) {
|
if (tsMgmtQset == NULL) {
|
||||||
|
@ -127,7 +133,7 @@ int32_t dnodeInitMgmt() {
|
||||||
pthread_attr_init(&thAttr);
|
pthread_attr_init(&thAttr);
|
||||||
pthread_attr_setdetachstate(&thAttr, PTHREAD_CREATE_JOINABLE);
|
pthread_attr_setdetachstate(&thAttr, PTHREAD_CREATE_JOINABLE);
|
||||||
|
|
||||||
int32_t code = pthread_create(&tsQthread, &thAttr, dnodeProcessMgmtQueue, NULL);
|
code = pthread_create(&tsQthread, &thAttr, dnodeProcessMgmtQueue, NULL);
|
||||||
pthread_attr_destroy(&thAttr);
|
pthread_attr_destroy(&thAttr);
|
||||||
if (code != 0) {
|
if (code != 0) {
|
||||||
dError("failed to create thread to process mgmt queue, reason:%s", strerror(errno));
|
dError("failed to create thread to process mgmt queue, reason:%s", strerror(errno));
|
||||||
|
@ -141,6 +147,12 @@ int32_t dnodeInitMgmt() {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
dInfo("dnode mgmt is initialized");
|
||||||
|
|
||||||
|
return TSDB_CODE_SUCCESS;
|
||||||
|
}
|
||||||
|
|
||||||
|
int32_t dnodeInitMgmtTimer() {
|
||||||
tsDnodeTmr = taosTmrInit(100, 200, 60000, "DND-DM");
|
tsDnodeTmr = taosTmrInit(100, 200, 60000, "DND-DM");
|
||||||
if (tsDnodeTmr == NULL) {
|
if (tsDnodeTmr == NULL) {
|
||||||
dError("failed to init dnode timer");
|
dError("failed to init dnode timer");
|
||||||
|
@ -149,13 +161,11 @@ int32_t dnodeInitMgmt() {
|
||||||
}
|
}
|
||||||
|
|
||||||
taosTmrReset(dnodeSendStatusMsg, 500, NULL, tsDnodeTmr, &tsStatusTimer);
|
taosTmrReset(dnodeSendStatusMsg, 500, NULL, tsDnodeTmr, &tsStatusTimer);
|
||||||
|
dInfo("dnode mgmt timer is initialized");
|
||||||
dInfo("dnode mgmt is initialized");
|
|
||||||
|
|
||||||
return TSDB_CODE_SUCCESS;
|
return TSDB_CODE_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
void dnodeCleanupMgmt() {
|
void dnodeCleanupMgmtTimer() {
|
||||||
if (tsStatusTimer != NULL) {
|
if (tsStatusTimer != NULL) {
|
||||||
taosTmrStopA(&tsStatusTimer);
|
taosTmrStopA(&tsStatusTimer);
|
||||||
tsStatusTimer = NULL;
|
tsStatusTimer = NULL;
|
||||||
|
@ -165,7 +175,10 @@ void dnodeCleanupMgmt() {
|
||||||
taosTmrCleanUp(tsDnodeTmr);
|
taosTmrCleanUp(tsDnodeTmr);
|
||||||
tsDnodeTmr = NULL;
|
tsDnodeTmr = NULL;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void dnodeCleanupMgmt() {
|
||||||
|
dnodeCleanupMgmtTimer();
|
||||||
dnodeCloseVnodes();
|
dnodeCloseVnodes();
|
||||||
|
|
||||||
if (tsMgmtQset) taosQsetThreadResume(tsMgmtQset);
|
if (tsMgmtQset) taosQsetThreadResume(tsMgmtQset);
|
||||||
|
@ -282,13 +295,12 @@ static void *dnodeOpenVnode(void *param) {
|
||||||
}
|
}
|
||||||
|
|
||||||
static int32_t dnodeOpenVnodes() {
|
static int32_t dnodeOpenVnodes() {
|
||||||
int32_t *vnodeList = calloc(TSDB_MAX_VNODES, sizeof(int32_t));
|
int32_t vnodeList[TSDB_MAX_VNODES] = {0};
|
||||||
int32_t numOfVnodes = 0;
|
int32_t numOfVnodes = 0;
|
||||||
int32_t status = dnodeGetVnodeList(vnodeList, &numOfVnodes);
|
int32_t status = dnodeGetVnodeList(vnodeList, &numOfVnodes);
|
||||||
|
|
||||||
if (status != TSDB_CODE_SUCCESS) {
|
if (status != TSDB_CODE_SUCCESS) {
|
||||||
dInfo("get dnode list failed");
|
dInfo("get dnode list failed");
|
||||||
free(vnodeList);
|
|
||||||
return status;
|
return status;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -334,7 +346,6 @@ static int32_t dnodeOpenVnodes() {
|
||||||
free(pThread->vnodeList);
|
free(pThread->vnodeList);
|
||||||
}
|
}
|
||||||
|
|
||||||
free(vnodeList);
|
|
||||||
free(threads);
|
free(threads);
|
||||||
dInfo("there are total vnodes:%d, openned:%d failed:%d", numOfVnodes, openVnodes, failedVnodes);
|
dInfo("there are total vnodes:%d, openned:%d failed:%d", numOfVnodes, openVnodes, failedVnodes);
|
||||||
|
|
||||||
|
@ -342,7 +353,7 @@ static int32_t dnodeOpenVnodes() {
|
||||||
}
|
}
|
||||||
|
|
||||||
void dnodeStartStream() {
|
void dnodeStartStream() {
|
||||||
int32_t vnodeList[TSDB_MAX_VNODES];
|
int32_t vnodeList[TSDB_MAX_VNODES] = {0};
|
||||||
int32_t numOfVnodes = 0;
|
int32_t numOfVnodes = 0;
|
||||||
int32_t status = vnodeGetVnodeList(vnodeList, &numOfVnodes);
|
int32_t status = vnodeGetVnodeList(vnodeList, &numOfVnodes);
|
||||||
|
|
||||||
|
@ -359,7 +370,7 @@ void dnodeStartStream() {
|
||||||
}
|
}
|
||||||
|
|
||||||
static void dnodeCloseVnodes() {
|
static void dnodeCloseVnodes() {
|
||||||
int32_t vnodeList[TSDB_MAX_VNODES];
|
int32_t vnodeList[TSDB_MAX_VNODES]= {0};
|
||||||
int32_t numOfVnodes = 0;
|
int32_t numOfVnodes = 0;
|
||||||
int32_t status;
|
int32_t status;
|
||||||
|
|
||||||
|
@ -398,6 +409,7 @@ static int32_t dnodeProcessCreateVnodeMsg(SRpcMsg *rpcMsg) {
|
||||||
|
|
||||||
void *pVnode = vnodeAcquireVnode(pCreate->cfg.vgId);
|
void *pVnode = vnodeAcquireVnode(pCreate->cfg.vgId);
|
||||||
if (pVnode != NULL) {
|
if (pVnode != NULL) {
|
||||||
|
dDebug("vgId:%d, already exist, processed as alter msg", pCreate->cfg.vgId);
|
||||||
int32_t code = vnodeAlter(pVnode, pCreate);
|
int32_t code = vnodeAlter(pVnode, pCreate);
|
||||||
vnodeRelease(pVnode);
|
vnodeRelease(pVnode);
|
||||||
return code;
|
return code;
|
||||||
|
|
|
@ -20,6 +20,7 @@
|
||||||
#include "tglobal.h"
|
#include "tglobal.h"
|
||||||
#include "dnodeInt.h"
|
#include "dnodeInt.h"
|
||||||
#include "dnodeMain.h"
|
#include "dnodeMain.h"
|
||||||
|
#include "tfile.h"
|
||||||
|
|
||||||
static void signal_handler(int32_t signum, siginfo_t *sigInfo, void *context);
|
static void signal_handler(int32_t signum, siginfo_t *sigInfo, void *context);
|
||||||
static sem_t exitSem;
|
static sem_t exitSem;
|
||||||
|
@ -67,6 +68,18 @@ int32_t main(int32_t argc, char *argv[]) {
|
||||||
taosSetAllocMode(TAOS_ALLOC_MODE_DETECT_LEAK, NULL, true);
|
taosSetAllocMode(TAOS_ALLOC_MODE_DETECT_LEAK, NULL, true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
#ifdef TAOS_RANDOM_FILE_FAIL
|
||||||
|
else if (strcmp(argv[i], "--random-file-fail-factor") == 0) {
|
||||||
|
if ( (i+1) < argc ) {
|
||||||
|
int factor = atoi(argv[i+1]);
|
||||||
|
printf("The factor of random failure is %d\n", factor);
|
||||||
|
taosSetRandomFileFailFactor(factor);
|
||||||
|
} else {
|
||||||
|
printf("Please specify a number for random failure factor!");
|
||||||
|
exit(EXIT_FAILURE);
|
||||||
|
}
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -210,6 +210,7 @@ static void *dnodeProcessWriteQueue(void *param) {
|
||||||
int32_t numOfMsgs;
|
int32_t numOfMsgs;
|
||||||
int type;
|
int type;
|
||||||
void *pVnode, *item;
|
void *pVnode, *item;
|
||||||
|
SRspRet *pRspRet;
|
||||||
|
|
||||||
dDebug("write worker:%d is running", pWorker->workerId);
|
dDebug("write worker:%d is running", pWorker->workerId);
|
||||||
|
|
||||||
|
@ -222,9 +223,11 @@ static void *dnodeProcessWriteQueue(void *param) {
|
||||||
|
|
||||||
for (int32_t i = 0; i < numOfMsgs; ++i) {
|
for (int32_t i = 0; i < numOfMsgs; ++i) {
|
||||||
pWrite = NULL;
|
pWrite = NULL;
|
||||||
|
pRspRet = NULL;
|
||||||
taosGetQitem(pWorker->qall, &type, &item);
|
taosGetQitem(pWorker->qall, &type, &item);
|
||||||
if (type == TAOS_QTYPE_RPC) {
|
if (type == TAOS_QTYPE_RPC) {
|
||||||
pWrite = (SWriteMsg *)item;
|
pWrite = (SWriteMsg *)item;
|
||||||
|
pRspRet = &pWrite->rspRet;
|
||||||
pHead = (SWalHead *)(pWrite->pCont - sizeof(SWalHead));
|
pHead = (SWalHead *)(pWrite->pCont - sizeof(SWalHead));
|
||||||
pHead->msgType = pWrite->rpcMsg.msgType;
|
pHead->msgType = pWrite->rpcMsg.msgType;
|
||||||
pHead->version = 0;
|
pHead->version = 0;
|
||||||
|
@ -234,7 +237,7 @@ static void *dnodeProcessWriteQueue(void *param) {
|
||||||
pHead = (SWalHead *)item;
|
pHead = (SWalHead *)item;
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t code = vnodeProcessWrite(pVnode, type, pHead, item);
|
int32_t code = vnodeProcessWrite(pVnode, type, pHead, pRspRet);
|
||||||
if (pWrite) pWrite->rpcMsg.code = code;
|
if (pWrite) pWrite->rpcMsg.code = code;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -247,6 +250,11 @@ static void *dnodeProcessWriteQueue(void *param) {
|
||||||
if (type == TAOS_QTYPE_RPC) {
|
if (type == TAOS_QTYPE_RPC) {
|
||||||
pWrite = (SWriteMsg *)item;
|
pWrite = (SWriteMsg *)item;
|
||||||
dnodeSendRpcVnodeWriteRsp(pVnode, item, pWrite->rpcMsg.code);
|
dnodeSendRpcVnodeWriteRsp(pVnode, item, pWrite->rpcMsg.code);
|
||||||
|
} else if (type == TAOS_QTYPE_FWD) {
|
||||||
|
pHead = (SWalHead *)item;
|
||||||
|
vnodeConfirmForward(pVnode, pHead->version, 0);
|
||||||
|
taosFreeQitem(item);
|
||||||
|
vnodeRelease(pVnode);
|
||||||
} else {
|
} else {
|
||||||
taosFreeQitem(item);
|
taosFreeQitem(item);
|
||||||
vnodeRelease(pVnode);
|
vnodeRelease(pVnode);
|
||||||
|
|
|
@ -87,8 +87,8 @@ int32_t qKillQuery(qinfo_t qinfo);
|
||||||
void* qOpenQueryMgmt(int32_t vgId);
|
void* qOpenQueryMgmt(int32_t vgId);
|
||||||
void qSetQueryMgmtClosed(void* pExecutor);
|
void qSetQueryMgmtClosed(void* pExecutor);
|
||||||
void qCleanupQueryMgmt(void* pExecutor);
|
void qCleanupQueryMgmt(void* pExecutor);
|
||||||
void** qRegisterQInfo(void* pMgmt, void* qInfo);
|
void** qRegisterQInfo(void* pMgmt, uint64_t qInfo);
|
||||||
void** qAcquireQInfo(void* pMgmt, void** key);
|
void** qAcquireQInfo(void* pMgmt, uint64_t key);
|
||||||
void** qReleaseQInfo(void* pMgmt, void* pQInfo, bool needFree);
|
void** qReleaseQInfo(void* pMgmt, void* pQInfo, bool needFree);
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
|
|
|
@ -129,9 +129,7 @@ TAOS_DEFINE_ERROR(TSDB_CODE_MND_CLUSTER_CFG_INCONSISTENT, 0, 0x0335, "mnode clus
|
||||||
|
|
||||||
TAOS_DEFINE_ERROR(TSDB_CODE_MND_ACCT_ALREADY_EXIST, 0, 0x0340, "mnode accounts already exist")
|
TAOS_DEFINE_ERROR(TSDB_CODE_MND_ACCT_ALREADY_EXIST, 0, 0x0340, "mnode accounts already exist")
|
||||||
TAOS_DEFINE_ERROR(TSDB_CODE_MND_INVALID_ACCT, 0, 0x0341, "mnode invalid account")
|
TAOS_DEFINE_ERROR(TSDB_CODE_MND_INVALID_ACCT, 0, 0x0341, "mnode invalid account")
|
||||||
TAOS_DEFINE_ERROR(TSDB_CODE_MND_INVALID_ACCT_PARA, 0, 0x0342, "mnode invalid account parameter")
|
TAOS_DEFINE_ERROR(TSDB_CODE_MND_INVALID_ACCT_OPTION, 0, 0x0342, "mnode invalid acct option")
|
||||||
TAOS_DEFINE_ERROR(TSDB_CODE_MND_INVALID_ACCT_OPTION, 0, 0x0343, "mnode invalid acct option")
|
|
||||||
TAOS_DEFINE_ERROR(TSDB_CODE_MND_TOO_MANY_ACCTS, 0, 0x0344, "mnode too many accounts")
|
|
||||||
|
|
||||||
TAOS_DEFINE_ERROR(TSDB_CODE_MND_USER_ALREADY_EXIST, 0, 0x0350, "mnode user already exist")
|
TAOS_DEFINE_ERROR(TSDB_CODE_MND_USER_ALREADY_EXIST, 0, 0x0350, "mnode user already exist")
|
||||||
TAOS_DEFINE_ERROR(TSDB_CODE_MND_INVALID_USER, 0, 0x0351, "mnode invalid user")
|
TAOS_DEFINE_ERROR(TSDB_CODE_MND_INVALID_USER, 0, 0x0351, "mnode invalid user")
|
||||||
|
@ -145,7 +143,6 @@ TAOS_DEFINE_ERROR(TSDB_CODE_MND_INVALID_TABLE_ID, 0, 0x0361, "mnode inva
|
||||||
TAOS_DEFINE_ERROR(TSDB_CODE_MND_INVALID_TABLE_NAME, 0, 0x0362, "mnode invalid table name")
|
TAOS_DEFINE_ERROR(TSDB_CODE_MND_INVALID_TABLE_NAME, 0, 0x0362, "mnode invalid table name")
|
||||||
TAOS_DEFINE_ERROR(TSDB_CODE_MND_INVALID_TABLE_TYPE, 0, 0x0363, "mnode invalid table type")
|
TAOS_DEFINE_ERROR(TSDB_CODE_MND_INVALID_TABLE_TYPE, 0, 0x0363, "mnode invalid table type")
|
||||||
TAOS_DEFINE_ERROR(TSDB_CODE_MND_TOO_MANY_TAGS, 0, 0x0364, "mnode too many tags")
|
TAOS_DEFINE_ERROR(TSDB_CODE_MND_TOO_MANY_TAGS, 0, 0x0364, "mnode too many tags")
|
||||||
TAOS_DEFINE_ERROR(TSDB_CODE_MND_TOO_MANY_TABLES, 0, 0x0365, "mnode too many tables")
|
|
||||||
TAOS_DEFINE_ERROR(TSDB_CODE_MND_TOO_MANY_TIMESERIES, 0, 0x0366, "mnode not enough time series")
|
TAOS_DEFINE_ERROR(TSDB_CODE_MND_TOO_MANY_TIMESERIES, 0, 0x0366, "mnode not enough time series")
|
||||||
TAOS_DEFINE_ERROR(TSDB_CODE_MND_NOT_SUPER_TABLE, 0, 0x0367, "mnode no super table") // operation only available for super table
|
TAOS_DEFINE_ERROR(TSDB_CODE_MND_NOT_SUPER_TABLE, 0, 0x0367, "mnode no super table") // operation only available for super table
|
||||||
TAOS_DEFINE_ERROR(TSDB_CODE_MND_COL_NAME_TOO_LONG, 0, 0x0368, "mnode column name too long")
|
TAOS_DEFINE_ERROR(TSDB_CODE_MND_COL_NAME_TOO_LONG, 0, 0x0368, "mnode column name too long")
|
||||||
|
@ -161,13 +158,13 @@ TAOS_DEFINE_ERROR(TSDB_CODE_MND_INVALID_DB_OPTION, 0, 0x0382, "mnode inva
|
||||||
TAOS_DEFINE_ERROR(TSDB_CODE_MND_INVALID_DB, 0, 0x0383, "mnode invalid database")
|
TAOS_DEFINE_ERROR(TSDB_CODE_MND_INVALID_DB, 0, 0x0383, "mnode invalid database")
|
||||||
TAOS_DEFINE_ERROR(TSDB_CODE_MND_MONITOR_DB_FORBIDDEN, 0, 0x0384, "mnode monitor db forbidden")
|
TAOS_DEFINE_ERROR(TSDB_CODE_MND_MONITOR_DB_FORBIDDEN, 0, 0x0384, "mnode monitor db forbidden")
|
||||||
TAOS_DEFINE_ERROR(TSDB_CODE_MND_TOO_MANY_DATABASES, 0, 0x0385, "mnode too many databases")
|
TAOS_DEFINE_ERROR(TSDB_CODE_MND_TOO_MANY_DATABASES, 0, 0x0385, "mnode too many databases")
|
||||||
|
TAOS_DEFINE_ERROR(TSDB_CODE_MND_DB_IN_DROPPING, 0, 0x0386, "mnode db in dropping")
|
||||||
|
|
||||||
// dnode
|
// dnode
|
||||||
TAOS_DEFINE_ERROR(TSDB_CODE_DND_MSG_NOT_PROCESSED, 0, 0x0400, "dnode message not processed")
|
TAOS_DEFINE_ERROR(TSDB_CODE_DND_MSG_NOT_PROCESSED, 0, 0x0400, "dnode message not processed")
|
||||||
TAOS_DEFINE_ERROR(TSDB_CODE_DND_OUT_OF_MEMORY, 0, 0x0401, "dnode out of memory")
|
TAOS_DEFINE_ERROR(TSDB_CODE_DND_OUT_OF_MEMORY, 0, 0x0401, "dnode out of memory")
|
||||||
TAOS_DEFINE_ERROR(TSDB_CODE_DND_NO_WRITE_ACCESS, 0, 0x0402, "dnode no disk write access")
|
TAOS_DEFINE_ERROR(TSDB_CODE_DND_NO_WRITE_ACCESS, 0, 0x0402, "dnode no disk write access")
|
||||||
TAOS_DEFINE_ERROR(TSDB_CODE_DND_INVALID_MSG_LEN, 0, 0x0403, "dnode invalid message length")
|
TAOS_DEFINE_ERROR(TSDB_CODE_DND_INVALID_MSG_LEN, 0, 0x0403, "dnode invalid message length")
|
||||||
TAOS_DEFINE_ERROR(TSDB_CODE_DND_INVALID_FILE_FORMAT, 0, 0x0404, "dnode invalid file format")
|
|
||||||
|
|
||||||
// vnode
|
// vnode
|
||||||
TAOS_DEFINE_ERROR(TSDB_CODE_VND_ACTION_IN_PROGRESS, 0, 0x0500, "vnode action in progress")
|
TAOS_DEFINE_ERROR(TSDB_CODE_VND_ACTION_IN_PROGRESS, 0, 0x0500, "vnode action in progress")
|
||||||
|
@ -180,7 +177,9 @@ TAOS_DEFINE_ERROR(TSDB_CODE_VND_NO_DISK_PERMISSIONS, 0, 0x0506, "vnode no d
|
||||||
TAOS_DEFINE_ERROR(TSDB_CODE_VND_NO_SUCH_FILE_OR_DIR, 0, 0x0507, "vnode no such file or directory")
|
TAOS_DEFINE_ERROR(TSDB_CODE_VND_NO_SUCH_FILE_OR_DIR, 0, 0x0507, "vnode no such file or directory")
|
||||||
TAOS_DEFINE_ERROR(TSDB_CODE_VND_OUT_OF_MEMORY, 0, 0x0508, "vnode out of memory")
|
TAOS_DEFINE_ERROR(TSDB_CODE_VND_OUT_OF_MEMORY, 0, 0x0508, "vnode out of memory")
|
||||||
TAOS_DEFINE_ERROR(TSDB_CODE_VND_APP_ERROR, 0, 0x0509, "vnode app error")
|
TAOS_DEFINE_ERROR(TSDB_CODE_VND_APP_ERROR, 0, 0x0509, "vnode app error")
|
||||||
TAOS_DEFINE_ERROR(TSDB_CODE_VND_NO_WRITE_AUTH, 0, 0x0214, "vnode no write auth")
|
TAOS_DEFINE_ERROR(TSDB_CODE_VND_INVALID_STATUS, 0, 0x0510, "vnode not in ready state")
|
||||||
|
TAOS_DEFINE_ERROR(TSDB_CODE_VND_NOT_SYNCED, 0, 0x0511, "vnode not in synced state")
|
||||||
|
TAOS_DEFINE_ERROR(TSDB_CODE_VND_NO_WRITE_AUTH, 0, 0x0512, "vnode no write auth")
|
||||||
|
|
||||||
// tsdb
|
// tsdb
|
||||||
TAOS_DEFINE_ERROR(TSDB_CODE_TDB_INVALID_TABLE_ID, 0, 0x0600, "tsdb invalid table id")
|
TAOS_DEFINE_ERROR(TSDB_CODE_TDB_INVALID_TABLE_ID, 0, 0x0600, "tsdb invalid table id")
|
||||||
|
@ -200,6 +199,7 @@ TAOS_DEFINE_ERROR(TSDB_CODE_TDB_INVALID_ACTION, 0, 0x060D, "tsdb inval
|
||||||
TAOS_DEFINE_ERROR(TSDB_CODE_TDB_INVALID_CREATE_TB_MSG, 0, 0x060E, "tsdb invalid create table message")
|
TAOS_DEFINE_ERROR(TSDB_CODE_TDB_INVALID_CREATE_TB_MSG, 0, 0x060E, "tsdb invalid create table message")
|
||||||
TAOS_DEFINE_ERROR(TSDB_CODE_TDB_NO_TABLE_DATA_IN_MEM, 0, 0x060F, "tsdb no table data in memory skiplist")
|
TAOS_DEFINE_ERROR(TSDB_CODE_TDB_NO_TABLE_DATA_IN_MEM, 0, 0x060F, "tsdb no table data in memory skiplist")
|
||||||
TAOS_DEFINE_ERROR(TSDB_CODE_TDB_FILE_ALREADY_EXISTS, 0, 0x0610, "tsdb file already exists")
|
TAOS_DEFINE_ERROR(TSDB_CODE_TDB_FILE_ALREADY_EXISTS, 0, 0x0610, "tsdb file already exists")
|
||||||
|
TAOS_DEFINE_ERROR(TSDB_CODE_TDB_TABLE_RECONFIGURE, 0, 0x0611, "tsdb need to reconfigure table")
|
||||||
|
|
||||||
// query
|
// query
|
||||||
TAOS_DEFINE_ERROR(TSDB_CODE_QRY_INVALID_QHANDLE, 0, 0x0700, "query invalid handle")
|
TAOS_DEFINE_ERROR(TSDB_CODE_QRY_INVALID_QHANDLE, 0, 0x0700, "query invalid handle")
|
||||||
|
|
|
@ -203,8 +203,7 @@ typedef struct SSubmitBlk {
|
||||||
typedef struct SSubmitMsg {
|
typedef struct SSubmitMsg {
|
||||||
SMsgHead header;
|
SMsgHead header;
|
||||||
int32_t length;
|
int32_t length;
|
||||||
int32_t compressed : 2;
|
int32_t numOfBlocks;
|
||||||
int32_t numOfBlocks : 30;
|
|
||||||
SSubmitBlk blocks[];
|
SSubmitBlk blocks[];
|
||||||
} SSubmitMsg;
|
} SSubmitMsg;
|
||||||
|
|
||||||
|
@ -285,6 +284,8 @@ typedef struct {
|
||||||
int32_t tid;
|
int32_t tid;
|
||||||
int16_t tversion;
|
int16_t tversion;
|
||||||
int16_t colId;
|
int16_t colId;
|
||||||
|
int8_t type;
|
||||||
|
int16_t bytes;
|
||||||
int32_t tagValLen;
|
int32_t tagValLen;
|
||||||
int16_t numOfTags;
|
int16_t numOfTags;
|
||||||
int32_t schemaLen;
|
int32_t schemaLen;
|
||||||
|
@ -472,7 +473,7 @@ typedef struct {
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
int32_t code;
|
int32_t code;
|
||||||
uint64_t qhandle;
|
uint64_t qhandle; // query handle
|
||||||
} SQueryTableRsp;
|
} SQueryTableRsp;
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
|
@ -485,7 +486,7 @@ typedef struct SRetrieveTableRsp {
|
||||||
int32_t numOfRows;
|
int32_t numOfRows;
|
||||||
int8_t completed; // all results are returned to client
|
int8_t completed; // all results are returned to client
|
||||||
int16_t precision;
|
int16_t precision;
|
||||||
int64_t offset; // updated offset value for multi-vnode projection query
|
int64_t offset; // updated offset value for multi-vnode projection query
|
||||||
int64_t useconds;
|
int64_t useconds;
|
||||||
char data[];
|
char data[];
|
||||||
} SRetrieveTableRsp;
|
} SRetrieveTableRsp;
|
||||||
|
|
|
@ -108,12 +108,14 @@ void tsdbClearTableCfg(STableCfg *config);
|
||||||
|
|
||||||
void* tsdbGetTableTagVal(const void* pTable, int32_t colId, int16_t type, int16_t bytes);
|
void* tsdbGetTableTagVal(const void* pTable, int32_t colId, int16_t type, int16_t bytes);
|
||||||
char* tsdbGetTableName(void *pTable);
|
char* tsdbGetTableName(void *pTable);
|
||||||
STableId tsdbGetTableId(void *pTable);
|
|
||||||
|
#define TSDB_TABLEID(_table) ((STableId*) (_table))
|
||||||
|
|
||||||
STableCfg *tsdbCreateTableCfgFromMsg(SMDCreateTableMsg *pMsg);
|
STableCfg *tsdbCreateTableCfgFromMsg(SMDCreateTableMsg *pMsg);
|
||||||
|
|
||||||
int tsdbCreateTable(TSDB_REPO_T *repo, STableCfg *pCfg);
|
int tsdbCreateTable(TSDB_REPO_T *repo, STableCfg *pCfg);
|
||||||
int tsdbDropTable(TSDB_REPO_T *pRepo, STableId tableId);
|
int tsdbDropTable(TSDB_REPO_T *pRepo, STableId tableId);
|
||||||
int tsdbUpdateTagValue(TSDB_REPO_T *repo, SUpdateTableTagValMsg *pMsg);
|
int tsdbUpdateTableTagValue(TSDB_REPO_T *repo, SUpdateTableTagValMsg *pMsg);
|
||||||
TSKEY tsdbGetTableLastKey(TSDB_REPO_T *repo, uint64_t uid);
|
TSKEY tsdbGetTableLastKey(TSDB_REPO_T *repo, uint64_t uid);
|
||||||
void tsdbStartStream(TSDB_REPO_T *repo);
|
void tsdbStartStream(TSDB_REPO_T *repo);
|
||||||
|
|
||||||
|
@ -233,9 +235,10 @@ bool tsdbNextDataBlock(TsdbQueryHandleT *pQueryHandle);
|
||||||
* Get current data block information
|
* Get current data block information
|
||||||
*
|
*
|
||||||
* @param pQueryHandle
|
* @param pQueryHandle
|
||||||
|
* @param pBlockInfo
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
SDataBlockInfo tsdbRetrieveDataBlockInfo(TsdbQueryHandleT *pQueryHandle);
|
void tsdbRetrieveDataBlockInfo(TsdbQueryHandleT *pQueryHandle, SDataBlockInfo* pBlockInfo);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
|
|
|
@ -60,7 +60,10 @@ void* vnodeGetWal(void *pVnode);
|
||||||
int32_t vnodeProcessWrite(void *pVnode, int qtype, void *pHead, void *item);
|
int32_t vnodeProcessWrite(void *pVnode, int qtype, void *pHead, void *item);
|
||||||
int32_t vnodeGetVnodeList(int32_t vnodeList[], int32_t *numOfVnodes);
|
int32_t vnodeGetVnodeList(int32_t vnodeList[], int32_t *numOfVnodes);
|
||||||
void vnodeBuildStatusMsg(void *param);
|
void vnodeBuildStatusMsg(void *param);
|
||||||
|
void vnodeConfirmForward(void *param, uint64_t version, int32_t code);
|
||||||
void vnodeSetAccess(SDMVgroupAccess *pAccess, int32_t numOfVnodes);
|
void vnodeSetAccess(SDMVgroupAccess *pAccess, int32_t numOfVnodes);
|
||||||
|
|
||||||
|
int32_t vnodeInitResources();
|
||||||
void vnodeCleanupResources();
|
void vnodeCleanupResources();
|
||||||
|
|
||||||
int32_t vnodeProcessRead(void *pVnode, SReadMsg *pReadMsg);
|
int32_t vnodeProcessRead(void *pVnode, SReadMsg *pReadMsg);
|
||||||
|
|
|
@ -206,10 +206,11 @@ static void shellSourceFile(TAOS *con, char *fptr) {
|
||||||
|
|
||||||
if (code != 0) {
|
if (code != 0) {
|
||||||
fprintf(stderr, "DB error: %s: %s (%d)\n", taos_errstr(con), fname, lineNo);
|
fprintf(stderr, "DB error: %s: %s (%d)\n", taos_errstr(con), fname, lineNo);
|
||||||
/* free local resouce: allocated memory/metric-meta refcnt */
|
|
||||||
taos_free_result(pSql);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* free local resouce: allocated memory/metric-meta refcnt */
|
||||||
|
taos_free_result(pSql);
|
||||||
|
|
||||||
memset(cmd, 0, MAX_COMMAND_SIZE);
|
memset(cmd, 0, MAX_COMMAND_SIZE);
|
||||||
cmd_len = 0;
|
cmd_len = 0;
|
||||||
}
|
}
|
||||||
|
|
|
@ -520,9 +520,8 @@ int main(int argc, char *argv[]) {
|
||||||
snprintf(command, BUFFER_SIZE, "create table if not exists %s.meters (ts timestamp%s tags (areaid int, loc binary(10))", db_name, cols);
|
snprintf(command, BUFFER_SIZE, "create table if not exists %s.meters (ts timestamp%s tags (areaid int, loc binary(10))", db_name, cols);
|
||||||
queryDB(taos, command);
|
queryDB(taos, command);
|
||||||
printf("meters created!\n");
|
printf("meters created!\n");
|
||||||
|
|
||||||
taos_close(taos);
|
|
||||||
}
|
}
|
||||||
|
taos_close(taos);
|
||||||
|
|
||||||
/* Wait for table to create */
|
/* Wait for table to create */
|
||||||
multiThreadCreateTable(cols, use_metric, threads, ntables, db_name, tb_prefix, ip_addr, port, user, pass);
|
multiThreadCreateTable(cols, use_metric, threads, ntables, db_name, tb_prefix, ip_addr, port, user, pass);
|
||||||
|
@ -792,9 +791,6 @@ void * createTable(void *sarg)
|
||||||
snprintf(command, BUFFER_SIZE, "create table if not exists %s.%s%d (ts timestamp%s;", winfo->db_name, winfo->tb_prefix, i, winfo->cols);
|
snprintf(command, BUFFER_SIZE, "create table if not exists %s.%s%d (ts timestamp%s;", winfo->db_name, winfo->tb_prefix, i, winfo->cols);
|
||||||
queryDB(winfo->taos, command);
|
queryDB(winfo->taos, command);
|
||||||
}
|
}
|
||||||
|
|
||||||
taos_close(winfo->taos);
|
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
/* Create all the tables; */
|
/* Create all the tables; */
|
||||||
printf("Creating table from %d to %d\n", winfo->start_table_id, winfo->end_table_id);
|
printf("Creating table from %d to %d\n", winfo->start_table_id, winfo->end_table_id);
|
||||||
|
@ -812,7 +808,6 @@ void * createTable(void *sarg)
|
||||||
}
|
}
|
||||||
queryDB(winfo->taos, command);
|
queryDB(winfo->taos, command);
|
||||||
}
|
}
|
||||||
taos_close(winfo->taos);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return NULL;
|
return NULL;
|
||||||
|
@ -857,7 +852,6 @@ void multiThreadCreateTable(char* cols, bool use_metric, int threads, int ntable
|
||||||
|
|
||||||
for (int i = 0; i < threads; i++) {
|
for (int i = 0; i < threads; i++) {
|
||||||
info *t_info = infos + i;
|
info *t_info = infos + i;
|
||||||
taos_close(t_info->taos);
|
|
||||||
sem_destroy(&(t_info->mutex_sem));
|
sem_destroy(&(t_info->mutex_sem));
|
||||||
sem_destroy(&(t_info->lock_sem));
|
sem_destroy(&(t_info->lock_sem));
|
||||||
}
|
}
|
||||||
|
@ -875,6 +869,11 @@ void *readTable(void *sarg) {
|
||||||
int64_t sTime = rinfo->start_time;
|
int64_t sTime = rinfo->start_time;
|
||||||
char *tb_prefix = rinfo->tb_prefix;
|
char *tb_prefix = rinfo->tb_prefix;
|
||||||
FILE *fp = fopen(rinfo->fp, "a");
|
FILE *fp = fopen(rinfo->fp, "a");
|
||||||
|
if (NULL == fp) {
|
||||||
|
printf("fopen %s fail, reason:%s.\n", rinfo->fp, strerror(errno));
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
int num_of_DPT = rinfo->nrecords_per_table;
|
int num_of_DPT = rinfo->nrecords_per_table;
|
||||||
int num_of_tables = rinfo->end_table_id - rinfo->start_table_id + 1;
|
int num_of_tables = rinfo->end_table_id - rinfo->start_table_id + 1;
|
||||||
int totalData = num_of_DPT * num_of_tables;
|
int totalData = num_of_DPT * num_of_tables;
|
||||||
|
@ -930,6 +929,11 @@ void *readMetric(void *sarg) {
|
||||||
TAOS *taos = rinfo->taos;
|
TAOS *taos = rinfo->taos;
|
||||||
char command[BUFFER_SIZE] = "\0";
|
char command[BUFFER_SIZE] = "\0";
|
||||||
FILE *fp = fopen(rinfo->fp, "a");
|
FILE *fp = fopen(rinfo->fp, "a");
|
||||||
|
if (NULL == fp) {
|
||||||
|
printf("fopen %s fail, reason:%s.\n", rinfo->fp, strerror(errno));
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
int num_of_DPT = rinfo->nrecords_per_table;
|
int num_of_DPT = rinfo->nrecords_per_table;
|
||||||
int num_of_tables = rinfo->end_table_id - rinfo->start_table_id + 1;
|
int num_of_tables = rinfo->end_table_id - rinfo->start_table_id + 1;
|
||||||
int totalData = num_of_DPT * num_of_tables;
|
int totalData = num_of_DPT * num_of_tables;
|
||||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -40,7 +40,7 @@ struct arguments {
|
||||||
static error_t parse_opt(int key, char *arg, struct argp_state *state) {
|
static error_t parse_opt(int key, char *arg, struct argp_state *state) {
|
||||||
struct arguments *arguments = state->input;
|
struct arguments *arguments = state->input;
|
||||||
switch (key) {
|
switch (key) {
|
||||||
case 'w':
|
case 'r':
|
||||||
arguments->dataDir = arg;
|
arguments->dataDir = arg;
|
||||||
break;
|
break;
|
||||||
case 'd':
|
case 'd':
|
||||||
|
@ -51,6 +51,7 @@ static error_t parse_opt(int key, char *arg, struct argp_state *state) {
|
||||||
break;
|
break;
|
||||||
case 'f':
|
case 'f':
|
||||||
arguments->fqdn = arg;
|
arguments->fqdn = arg;
|
||||||
|
break;
|
||||||
case 'g':
|
case 'g':
|
||||||
arguments->dnodeGroups = arg;
|
arguments->dnodeGroups = arg;
|
||||||
break;
|
break;
|
||||||
|
|
|
@ -96,6 +96,7 @@ void walModWalFile(char* walfile) {
|
||||||
if (wfd < 0) {
|
if (wfd < 0) {
|
||||||
printf("wal:%s, failed to open(%s)\n", newWalFile, strerror(errno));
|
printf("wal:%s, failed to open(%s)\n", newWalFile, strerror(errno));
|
||||||
free(buffer);
|
free(buffer);
|
||||||
|
close(rfd);
|
||||||
return ;
|
return ;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -116,6 +117,11 @@ void walModWalFile(char* walfile) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (pHead->len >= 1024000 - sizeof(SWalHead)) {
|
||||||
|
printf("wal:%s, SWalHead.len(%d) overflow, skip the rest of file\n", walfile, pHead->len);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
ret = read(rfd, pHead->cont, pHead->len);
|
ret = read(rfd, pHead->cont, pHead->len);
|
||||||
if ( ret != pHead->len) {
|
if ( ret != pHead->len) {
|
||||||
printf("wal:%s, failed to read body, skip, len:%d ret:%d\n", walfile, pHead->len, ret);
|
printf("wal:%s, failed to read body, skip, len:%d ret:%d\n", walfile, pHead->len, ret);
|
||||||
|
|
|
@ -99,6 +99,8 @@ static int32_t readVnodeCfg(SVnodeObj *pVnode, char* cfgFile)
|
||||||
goto PARSE_OVER;
|
goto PARSE_OVER;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
content[maxLen] = (char)0;
|
||||||
|
|
||||||
root = cJSON_Parse(content);
|
root = cJSON_Parse(content);
|
||||||
if (root == NULL) {
|
if (root == NULL) {
|
||||||
printf("failed to json parse %s, invalid json format\n", cfgFile);
|
printf("failed to json parse %s, invalid json format\n", cfgFile);
|
||||||
|
|
|
@ -44,6 +44,7 @@ void mnodeDecMnodeRef(struct SMnodeObj *pMnode);
|
||||||
char * mnodeGetMnodeRoleStr();
|
char * mnodeGetMnodeRoleStr();
|
||||||
void mnodeGetMnodeIpSetForPeer(SRpcIpSet *ipSet);
|
void mnodeGetMnodeIpSetForPeer(SRpcIpSet *ipSet);
|
||||||
void mnodeGetMnodeIpSetForShell(SRpcIpSet *ipSet);
|
void mnodeGetMnodeIpSetForShell(SRpcIpSet *ipSet);
|
||||||
|
char* mnodeGetMnodeMasterEp();
|
||||||
|
|
||||||
void mnodeGetMnodeInfos(void *mnodes);
|
void mnodeGetMnodeInfos(void *mnodes);
|
||||||
void mnodeUpdateMnodeIpSet();
|
void mnodeUpdateMnodeIpSet();
|
||||||
|
|
|
@ -53,6 +53,7 @@ typedef struct {
|
||||||
void * rowData;
|
void * rowData;
|
||||||
int32_t rowSize;
|
int32_t rowSize;
|
||||||
int32_t retCode; // for callback in sdb queue
|
int32_t retCode; // for callback in sdb queue
|
||||||
|
int32_t processedCount; // for sync fwd callback
|
||||||
int32_t (*cb)(struct SMnodeMsg *pMsg, int32_t code);
|
int32_t (*cb)(struct SMnodeMsg *pMsg, int32_t code);
|
||||||
struct SMnodeMsg *pMsg;
|
struct SMnodeMsg *pMsg;
|
||||||
} SSdbOper;
|
} SSdbOper;
|
||||||
|
|
|
@ -128,6 +128,7 @@ int32_t mnodeInitAccts() {
|
||||||
void mnodeCleanupAccts() {
|
void mnodeCleanupAccts() {
|
||||||
acctCleanUp();
|
acctCleanUp();
|
||||||
sdbCloseTable(tsAcctSdb);
|
sdbCloseTable(tsAcctSdb);
|
||||||
|
tsAcctSdb = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
void *mnodeGetAcct(char *name) {
|
void *mnodeGetAcct(char *name) {
|
||||||
|
|
|
@ -180,8 +180,13 @@ void mnodeDecDbRef(SDbObj *pDb) {
|
||||||
SDbObj *mnodeGetDbByTableId(char *tableId) {
|
SDbObj *mnodeGetDbByTableId(char *tableId) {
|
||||||
char db[TSDB_TABLE_ID_LEN], *pos;
|
char db[TSDB_TABLE_ID_LEN], *pos;
|
||||||
|
|
||||||
|
// tableId format should be : acct.db.table
|
||||||
pos = strstr(tableId, TS_PATH_DELIMITER);
|
pos = strstr(tableId, TS_PATH_DELIMITER);
|
||||||
|
assert(NULL != pos);
|
||||||
|
|
||||||
pos = strstr(pos + 1, TS_PATH_DELIMITER);
|
pos = strstr(pos + 1, TS_PATH_DELIMITER);
|
||||||
|
assert(NULL != pos);
|
||||||
|
|
||||||
memset(db, 0, sizeof(db));
|
memset(db, 0, sizeof(db));
|
||||||
strncpy(db, tableId, pos - tableId);
|
strncpy(db, tableId, pos - tableId);
|
||||||
|
|
||||||
|
@ -459,6 +464,7 @@ void mnodeMoveVgroupToHead(SVgObj *pVgroup) {
|
||||||
|
|
||||||
void mnodeCleanupDbs() {
|
void mnodeCleanupDbs() {
|
||||||
sdbCloseTable(tsDbSdb);
|
sdbCloseTable(tsDbSdb);
|
||||||
|
tsDbSdb = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int32_t mnodeGetDbMeta(STableMetaMsg *pMeta, SShowObj *pShow, void *pConn) {
|
static int32_t mnodeGetDbMeta(STableMetaMsg *pMeta, SShowObj *pShow, void *pConn) {
|
||||||
|
@ -965,6 +971,11 @@ static int32_t mnodeProcessAlterDbMsg(SMnodeMsg *pMsg) {
|
||||||
return TSDB_CODE_MND_INVALID_DB;
|
return TSDB_CODE_MND_INVALID_DB;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (pMsg->pDb->status != TSDB_DB_STATUS_READY) {
|
||||||
|
mError("db:%s, status:%d, in dropping", pAlter->db, pMsg->pDb->status);
|
||||||
|
return TSDB_CODE_MND_DB_IN_DROPPING;
|
||||||
|
}
|
||||||
|
|
||||||
return mnodeAlterDb(pMsg->pDb, pAlter, pMsg);
|
return mnodeAlterDb(pMsg->pDb, pAlter, pMsg);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -88,13 +88,13 @@ static int32_t mnodeDnodeActionDelete(SSdbOper *pOper) {
|
||||||
}
|
}
|
||||||
|
|
||||||
static int32_t mnodeDnodeActionUpdate(SSdbOper *pOper) {
|
static int32_t mnodeDnodeActionUpdate(SSdbOper *pOper) {
|
||||||
SDnodeObj *pDnode = pOper->pObj;
|
SDnodeObj *pNew = pOper->pObj;
|
||||||
SDnodeObj *pSaved = mnodeGetDnode(pDnode->dnodeId);
|
SDnodeObj *pDnode = mnodeGetDnode(pNew->dnodeId);
|
||||||
if (pSaved != NULL && pDnode != pSaved) {
|
if (pDnode != NULL && pNew != pDnode) {
|
||||||
memcpy(pSaved, pDnode, pOper->rowSize);
|
memcpy(pDnode, pNew, pOper->rowSize);
|
||||||
free(pDnode);
|
free(pNew);
|
||||||
mnodeDecDnodeRef(pSaved);
|
|
||||||
}
|
}
|
||||||
|
mnodeDecDnodeRef(pDnode);
|
||||||
|
|
||||||
return TSDB_CODE_SUCCESS;
|
return TSDB_CODE_SUCCESS;
|
||||||
}
|
}
|
||||||
|
@ -176,6 +176,7 @@ int32_t mnodeInitDnodes() {
|
||||||
|
|
||||||
void mnodeCleanupDnodes() {
|
void mnodeCleanupDnodes() {
|
||||||
sdbCloseTable(tsDnodeSdb);
|
sdbCloseTable(tsDnodeSdb);
|
||||||
|
tsDnodeSdb = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
void *mnodeGetNextDnode(void *pIter, SDnodeObj **pDnode) {
|
void *mnodeGetNextDnode(void *pIter, SDnodeObj **pDnode) {
|
||||||
|
@ -334,7 +335,7 @@ static int32_t mnodeProcessDnodeStatusMsg(SMnodeMsg *pMsg) {
|
||||||
if (pStatus->dnodeId == 0) {
|
if (pStatus->dnodeId == 0) {
|
||||||
mDebug("dnode:%d %s, first access", pDnode->dnodeId, pDnode->dnodeEp);
|
mDebug("dnode:%d %s, first access", pDnode->dnodeId, pDnode->dnodeEp);
|
||||||
} else {
|
} else {
|
||||||
//mDebug("dnode:%d, status received, access times %d", pDnode->dnodeId, pDnode->lastAccess);
|
mTrace("dnode:%d, status received, access times %d", pDnode->dnodeId, pDnode->lastAccess);
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t openVnodes = htons(pStatus->openVnodes);
|
int32_t openVnodes = htons(pStatus->openVnodes);
|
||||||
|
@ -468,7 +469,7 @@ static int32_t mnodeDropDnodeByEp(char *ep, SMnodeMsg *pMsg) {
|
||||||
}
|
}
|
||||||
|
|
||||||
mnodeDecDnodeRef(pDnode);
|
mnodeDecDnodeRef(pDnode);
|
||||||
if (strcmp(pDnode->dnodeEp, dnodeGetMnodeMasterEp()) == 0) {
|
if (strcmp(pDnode->dnodeEp, mnodeGetMnodeMasterEp()) == 0) {
|
||||||
mError("dnode:%d, can't drop dnode:%s which is master", pDnode->dnodeId, ep);
|
mError("dnode:%d, can't drop dnode:%s which is master", pDnode->dnodeId, ep);
|
||||||
return TSDB_CODE_MND_NO_REMOVE_MASTER;
|
return TSDB_CODE_MND_NO_REMOVE_MASTER;
|
||||||
}
|
}
|
||||||
|
|
|
@ -41,7 +41,7 @@ typedef struct {
|
||||||
void (*cleanup)();
|
void (*cleanup)();
|
||||||
} SMnodeComponent;
|
} SMnodeComponent;
|
||||||
|
|
||||||
void *tsMnodeTmr;
|
void *tsMnodeTmr = NULL;
|
||||||
static bool tsMgmtIsRunning = false;
|
static bool tsMgmtIsRunning = false;
|
||||||
|
|
||||||
static const SMnodeComponent tsMnodeComponents[] = {
|
static const SMnodeComponent tsMnodeComponents[] = {
|
||||||
|
@ -121,8 +121,8 @@ void mnodeCleanupSystem() {
|
||||||
dnodeFreeMnodeWqueue();
|
dnodeFreeMnodeWqueue();
|
||||||
dnodeFreeMnodeRqueue();
|
dnodeFreeMnodeRqueue();
|
||||||
dnodeFreeMnodePqueue();
|
dnodeFreeMnodePqueue();
|
||||||
mnodeCleanupComponents(sizeof(tsMnodeComponents) / sizeof(tsMnodeComponents[0]) - 1);
|
|
||||||
mnodeCleanupTimer();
|
mnodeCleanupTimer();
|
||||||
|
mnodeCleanupComponents(sizeof(tsMnodeComponents) / sizeof(tsMnodeComponents[0]) - 1);
|
||||||
|
|
||||||
mInfo("mnode is cleaned up");
|
mInfo("mnode is cleaned up");
|
||||||
}
|
}
|
||||||
|
|
|
@ -165,6 +165,7 @@ int32_t mnodeInitMnodes() {
|
||||||
|
|
||||||
void mnodeCleanupMnodes() {
|
void mnodeCleanupMnodes() {
|
||||||
sdbCloseTable(tsMnodeSdb);
|
sdbCloseTable(tsMnodeSdb);
|
||||||
|
tsMnodeSdb = NULL;
|
||||||
mnodeMnodeDestroyLock();
|
mnodeMnodeDestroyLock();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -267,6 +268,10 @@ void mnodeGetMnodeIpSetForShell(SRpcIpSet *ipSet) {
|
||||||
mnodeMnodeUnLock();
|
mnodeMnodeUnLock();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
char* mnodeGetMnodeMasterEp() {
|
||||||
|
return tsMnodeInfos.nodeInfos[tsMnodeInfos.inUse].nodeEp;
|
||||||
|
}
|
||||||
|
|
||||||
void mnodeGetMnodeInfos(void *mnodeInfos) {
|
void mnodeGetMnodeInfos(void *mnodeInfos) {
|
||||||
mnodeMnodeRdLock();
|
mnodeMnodeRdLock();
|
||||||
*(SDMMnodeInfos *)mnodeInfos = tsMnodeInfos;
|
*(SDMMnodeInfos *)mnodeInfos = tsMnodeInfos;
|
||||||
|
|
|
@ -72,8 +72,6 @@ typedef struct {
|
||||||
void * sync;
|
void * sync;
|
||||||
void * wal;
|
void * wal;
|
||||||
SSyncCfg cfg;
|
SSyncCfg cfg;
|
||||||
sem_t sem;
|
|
||||||
int32_t code;
|
|
||||||
int32_t numOfTables;
|
int32_t numOfTables;
|
||||||
SSdbTable *tableList[SDB_TABLE_MAX];
|
SSdbTable *tableList[SDB_TABLE_MAX];
|
||||||
pthread_mutex_t mutex;
|
pthread_mutex_t mutex;
|
||||||
|
@ -201,7 +199,7 @@ static void sdbRestoreTables() {
|
||||||
sdbDebug("table:%s, is restored, numOfRows:%" PRId64, pTable->tableName, pTable->numOfRows);
|
sdbDebug("table:%s, is restored, numOfRows:%" PRId64, pTable->tableName, pTable->numOfRows);
|
||||||
}
|
}
|
||||||
|
|
||||||
sdbInfo("sdb is restored, version:%" PRId64 " totalRows:%d numOfTables:%d", tsSdbObj.version, totalRows, numOfTables);
|
sdbInfo("sdb is restored, ver:%" PRId64 " totalRows:%d numOfTables:%d", tsSdbObj.version, totalRows, numOfTables);
|
||||||
}
|
}
|
||||||
|
|
||||||
void sdbUpdateMnodeRoles() {
|
void sdbUpdateMnodeRoles() {
|
||||||
|
@ -244,27 +242,36 @@ static void sdbNotifyRole(void *ahandle, int8_t role) {
|
||||||
sdbUpdateMnodeRoles();
|
sdbUpdateMnodeRoles();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
FORCE_INLINE
|
||||||
static void sdbConfirmForward(void *ahandle, void *param, int32_t code) {
|
static void sdbConfirmForward(void *ahandle, void *param, int32_t code) {
|
||||||
tsSdbObj.code = code;
|
assert(param);
|
||||||
sem_post(&tsSdbObj.sem);
|
SSdbOper * pOper = param;
|
||||||
sdbDebug("forward request confirmed, version:%" PRIu64 ", result:%s", (int64_t)param, tstrerror(code));
|
SMnodeMsg *pMsg = pOper->pMsg;
|
||||||
}
|
if (code <= 0) pOper->retCode = code;
|
||||||
|
|
||||||
static int32_t sdbForwardToPeer(SWalHead *pHead) {
|
int32_t processedCount = atomic_add_fetch_32(&pOper->processedCount, 1);
|
||||||
if (tsSdbObj.sync == NULL) return TSDB_CODE_SUCCESS;
|
if (processedCount <= 1) {
|
||||||
|
if (pMsg != NULL) {
|
||||||
int32_t code = syncForwardToPeer(tsSdbObj.sync, pHead, (void*)pHead->version, TAOS_QTYPE_RPC);
|
sdbDebug("app:%p:%p, waiting for confirm this operation, count:%d", pMsg->rpcMsg.ahandle, pMsg, processedCount);
|
||||||
if (code > 0) {
|
}
|
||||||
sdbDebug("forward request is sent, version:%" PRIu64 ", code:%d", pHead->version, code);
|
return;
|
||||||
sem_wait(&tsSdbObj.sem);
|
|
||||||
return tsSdbObj.code;
|
|
||||||
}
|
}
|
||||||
return code;
|
|
||||||
|
if (pMsg != NULL) {
|
||||||
|
sdbDebug("app:%p:%p, is confirmed and will do callback func", pMsg->rpcMsg.ahandle, pMsg);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (pOper->cb != NULL) {
|
||||||
|
pOper->retCode = (*pOper->cb)(pMsg, pOper->retCode);
|
||||||
|
}
|
||||||
|
|
||||||
|
dnodeSendRpcMnodeWriteRsp(pMsg, pOper->retCode);
|
||||||
|
taosFreeQitem(pOper);
|
||||||
}
|
}
|
||||||
|
|
||||||
void sdbUpdateSync() {
|
void sdbUpdateSync() {
|
||||||
SSyncCfg syncCfg = {0};
|
SSyncCfg syncCfg = {0};
|
||||||
int32_t index = 0;
|
int32_t index = 0;
|
||||||
|
|
||||||
SDMMnodeInfos *mnodes = dnodeGetMnodeInfos();
|
SDMMnodeInfos *mnodes = dnodeGetMnodeInfos();
|
||||||
for (int32_t i = 0; i < mnodes->nodeNum; ++i) {
|
for (int32_t i = 0; i < mnodes->nodeNum; ++i) {
|
||||||
|
@ -298,7 +305,7 @@ void sdbUpdateSync() {
|
||||||
}
|
}
|
||||||
|
|
||||||
syncCfg.replica = index;
|
syncCfg.replica = index;
|
||||||
syncCfg.quorum = (syncCfg.replica == 1) ? 1:2;
|
syncCfg.quorum = (syncCfg.replica == 1) ? 1 : 2;
|
||||||
|
|
||||||
bool hasThisDnode = false;
|
bool hasThisDnode = false;
|
||||||
for (int32_t i = 0; i < syncCfg.replica; ++i) {
|
for (int32_t i = 0; i < syncCfg.replica; ++i) {
|
||||||
|
@ -339,7 +346,6 @@ void sdbUpdateSync() {
|
||||||
|
|
||||||
int32_t sdbInit() {
|
int32_t sdbInit() {
|
||||||
pthread_mutex_init(&tsSdbObj.mutex, NULL);
|
pthread_mutex_init(&tsSdbObj.mutex, NULL);
|
||||||
sem_init(&tsSdbObj.sem, 0, 0);
|
|
||||||
|
|
||||||
if (sdbInitWriteWorker() != 0) {
|
if (sdbInitWriteWorker() != 0) {
|
||||||
return -1;
|
return -1;
|
||||||
|
@ -367,7 +373,7 @@ void sdbCleanUp() {
|
||||||
tsSdbObj.status = SDB_STATUS_CLOSING;
|
tsSdbObj.status = SDB_STATUS_CLOSING;
|
||||||
|
|
||||||
sdbCleanupWriteWorker();
|
sdbCleanupWriteWorker();
|
||||||
sdbDebug("sdb will be closed, version:%" PRId64, tsSdbObj.version);
|
sdbDebug("sdb will be closed, ver:%" PRId64, tsSdbObj.version);
|
||||||
|
|
||||||
if (tsSdbObj.sync) {
|
if (tsSdbObj.sync) {
|
||||||
syncStop(tsSdbObj.sync);
|
syncStop(tsSdbObj.sync);
|
||||||
|
@ -379,7 +385,6 @@ void sdbCleanUp() {
|
||||||
tsSdbObj.wal = NULL;
|
tsSdbObj.wal = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
sem_destroy(&tsSdbObj.sem);
|
|
||||||
pthread_mutex_destroy(&tsSdbObj.mutex);
|
pthread_mutex_destroy(&tsSdbObj.mutex);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -466,8 +471,8 @@ static int32_t sdbInsertHash(SSdbTable *pTable, SSdbOper *pOper) {
|
||||||
atomic_add_fetch_32(&pTable->autoIndex, 1);
|
atomic_add_fetch_32(&pTable->autoIndex, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
sdbDebug("table:%s, insert record:%s to hash, rowSize:%d numOfRows:%" PRId64 " version:%" PRIu64, pTable->tableName,
|
sdbDebug("table:%s, insert record:%s to hash, rowSize:%d numOfRows:%" PRId64 ", msg:%p", pTable->tableName,
|
||||||
sdbGetKeyStrFromObj(pTable, pOper->pObj), pOper->rowSize, pTable->numOfRows, sdbGetVersion());
|
sdbGetKeyStrFromObj(pTable, pOper->pObj), pOper->rowSize, pTable->numOfRows, pOper->pMsg);
|
||||||
|
|
||||||
(*pTable->insertFp)(pOper);
|
(*pTable->insertFp)(pOper);
|
||||||
return TSDB_CODE_SUCCESS;
|
return TSDB_CODE_SUCCESS;
|
||||||
|
@ -485,8 +490,8 @@ static int32_t sdbDeleteHash(SSdbTable *pTable, SSdbOper *pOper) {
|
||||||
taosHashRemove(pTable->iHandle, key, keySize);
|
taosHashRemove(pTable->iHandle, key, keySize);
|
||||||
atomic_sub_fetch_32(&pTable->numOfRows, 1);
|
atomic_sub_fetch_32(&pTable->numOfRows, 1);
|
||||||
|
|
||||||
sdbDebug("table:%s, delete record:%s from hash, numOfRows:%" PRId64 " version:%" PRIu64, pTable->tableName,
|
sdbDebug("table:%s, delete record:%s from hash, numOfRows:%" PRId64 ", msg:%p", pTable->tableName,
|
||||||
sdbGetKeyStrFromObj(pTable, pOper->pObj), pTable->numOfRows, sdbGetVersion());
|
sdbGetKeyStrFromObj(pTable, pOper->pObj), pTable->numOfRows, pOper->pMsg);
|
||||||
|
|
||||||
int8_t *updateEnd = pOper->pObj + pTable->refCountPos - 1;
|
int8_t *updateEnd = pOper->pObj + pTable->refCountPos - 1;
|
||||||
*updateEnd = 1;
|
*updateEnd = 1;
|
||||||
|
@ -496,8 +501,8 @@ static int32_t sdbDeleteHash(SSdbTable *pTable, SSdbOper *pOper) {
|
||||||
}
|
}
|
||||||
|
|
||||||
static int32_t sdbUpdateHash(SSdbTable *pTable, SSdbOper *pOper) {
|
static int32_t sdbUpdateHash(SSdbTable *pTable, SSdbOper *pOper) {
|
||||||
sdbDebug("table:%s, update record:%s in hash, numOfRows:%" PRId64 " version:%" PRIu64, pTable->tableName,
|
sdbDebug("table:%s, update record:%s in hash, numOfRows:%" PRId64 ", msg:%p", pTable->tableName,
|
||||||
sdbGetKeyStrFromObj(pTable, pOper->pObj), pTable->numOfRows, sdbGetVersion());
|
sdbGetKeyStrFromObj(pTable, pOper->pObj), pTable->numOfRows, pOper->pMsg);
|
||||||
|
|
||||||
(*pTable->updateFp)(pOper);
|
(*pTable->updateFp)(pOper);
|
||||||
return TSDB_CODE_SUCCESS;
|
return TSDB_CODE_SUCCESS;
|
||||||
|
@ -513,24 +518,22 @@ static int sdbWrite(void *param, void *data, int type) {
|
||||||
assert(pTable != NULL);
|
assert(pTable != NULL);
|
||||||
|
|
||||||
pthread_mutex_lock(&tsSdbObj.mutex);
|
pthread_mutex_lock(&tsSdbObj.mutex);
|
||||||
|
|
||||||
if (pHead->version == 0) {
|
if (pHead->version == 0) {
|
||||||
// assign version
|
// assign version
|
||||||
tsSdbObj.version++;
|
tsSdbObj.version++;
|
||||||
pHead->version = tsSdbObj.version;
|
pHead->version = tsSdbObj.version;
|
||||||
} else {
|
} else {
|
||||||
// for data from WAL or forward, version may be smaller
|
// for data from WAL or forward, version may be smaller
|
||||||
if (pHead->version <= tsSdbObj.version) {
|
if (pHead->version <= tsSdbObj.version) {
|
||||||
pthread_mutex_unlock(&tsSdbObj.mutex);
|
pthread_mutex_unlock(&tsSdbObj.mutex);
|
||||||
if (type == TAOS_QTYPE_FWD && tsSdbObj.sync != NULL) {
|
sdbDebug("table:%s, failed to restore %s record:%s from source(%d), ver:%" PRId64 " too large, sdb ver:%" PRId64,
|
||||||
sdbDebug("forward request is received, version:%" PRIu64 " confirm it", pHead->version);
|
pTable->tableName, sdbGetActionStr(action), sdbGetKeyStr(pTable, pHead->cont), type, pHead->version, tsSdbObj.version);
|
||||||
syncConfirmForward(tsSdbObj.sync, pHead->version, TSDB_CODE_SUCCESS);
|
|
||||||
}
|
|
||||||
return TSDB_CODE_SUCCESS;
|
return TSDB_CODE_SUCCESS;
|
||||||
} else if (pHead->version != tsSdbObj.version + 1) {
|
} else if (pHead->version != tsSdbObj.version + 1) {
|
||||||
pthread_mutex_unlock(&tsSdbObj.mutex);
|
pthread_mutex_unlock(&tsSdbObj.mutex);
|
||||||
sdbError("table:%s, failed to restore %s record:%s from wal, version:%" PRId64 " too large, sdb version:%" PRId64,
|
sdbError("table:%s, failed to restore %s record:%s from source(%d), ver:%" PRId64 " too large, sdb ver:%" PRId64,
|
||||||
pTable->tableName, sdbGetActionStr(action), sdbGetKeyStr(pTable, pHead->cont), pHead->version,
|
pTable->tableName, sdbGetActionStr(action), sdbGetKeyStr(pTable, pHead->cont), type, pHead->version, tsSdbObj.version);
|
||||||
tsSdbObj.version);
|
|
||||||
return TSDB_CODE_MND_APP_ERROR;
|
return TSDB_CODE_MND_APP_ERROR;
|
||||||
} else {
|
} else {
|
||||||
tsSdbObj.version = pHead->version;
|
tsSdbObj.version = pHead->version;
|
||||||
|
@ -543,27 +546,35 @@ static int sdbWrite(void *param, void *data, int type) {
|
||||||
return code;
|
return code;
|
||||||
}
|
}
|
||||||
|
|
||||||
code = sdbForwardToPeer(pHead);
|
|
||||||
pthread_mutex_unlock(&tsSdbObj.mutex);
|
pthread_mutex_unlock(&tsSdbObj.mutex);
|
||||||
|
|
||||||
// from app, oper is created
|
// from app, oper is created
|
||||||
if (pOper != NULL) {
|
if (pOper != NULL) {
|
||||||
sdbTrace("record from app is disposed, table:%s action:%s record:%s version:%" PRIu64 " result:%s",
|
// forward to peers
|
||||||
pTable->tableName, sdbGetActionStr(action), sdbGetKeyStr(pTable, pHead->cont), pHead->version,
|
pOper->processedCount = 0;
|
||||||
tstrerror(code));
|
int32_t syncCode = syncForwardToPeer(tsSdbObj.sync, pHead, pOper, TAOS_QTYPE_RPC);
|
||||||
return code;
|
if (syncCode <= 0) pOper->processedCount = 1;
|
||||||
|
|
||||||
|
if (syncCode < 0) {
|
||||||
|
sdbError("table:%s, failed to forward request, result:%s action:%s record:%s ver:%" PRId64 ", msg:%p", pTable->tableName,
|
||||||
|
tstrerror(syncCode), sdbGetActionStr(action), sdbGetKeyStr(pTable, pHead->cont), pHead->version, pOper->pMsg);
|
||||||
|
} else if (syncCode > 0) {
|
||||||
|
sdbDebug("table:%s, forward request is sent, action:%s record:%s ver:%" PRId64 ", msg:%p", pTable->tableName,
|
||||||
|
sdbGetActionStr(action), sdbGetKeyStr(pTable, pHead->cont), pHead->version, pOper->pMsg);
|
||||||
|
} else {
|
||||||
|
sdbTrace("table:%s, no need to send fwd request, action:%s record:%s ver:%" PRId64 ", msg:%p", pTable->tableName,
|
||||||
|
sdbGetActionStr(action), sdbGetKeyStr(pTable, pHead->cont), pHead->version, pOper->pMsg);
|
||||||
|
}
|
||||||
|
return syncCode;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
sdbDebug("table:%s, record from wal/fwd is disposed, action:%s record:%s ver:%" PRId64, pTable->tableName,
|
||||||
|
sdbGetActionStr(action), sdbGetKeyStr(pTable, pHead->cont), pHead->version);
|
||||||
|
|
||||||
|
// even it is WAL/FWD, it shall be called to update version in sync
|
||||||
|
syncForwardToPeer(tsSdbObj.sync, pHead, pOper, TAOS_QTYPE_RPC);
|
||||||
|
|
||||||
// from wal or forward msg, oper not created, should add into hash
|
// from wal or forward msg, oper not created, should add into hash
|
||||||
if (tsSdbObj.sync != NULL) {
|
|
||||||
sdbTrace("record from wal forward is disposed, table:%s action:%s record:%s version:%" PRIu64 " confirm it",
|
|
||||||
pTable->tableName, sdbGetActionStr(action), sdbGetKeyStr(pTable, pHead->cont), pHead->version);
|
|
||||||
syncConfirmForward(tsSdbObj.sync, pHead->version, code);
|
|
||||||
} else {
|
|
||||||
sdbTrace("record from wal restore is disposed, table:%s action:%s record:%s version:%" PRIu64, pTable->tableName,
|
|
||||||
sdbGetActionStr(action), sdbGetKeyStr(pTable, pHead->cont), pHead->version);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (action == SDB_ACTION_INSERT) {
|
if (action == SDB_ACTION_INSERT) {
|
||||||
SSdbOper oper = {.rowSize = pHead->len, .rowData = pHead->cont, .table = pTable};
|
SSdbOper oper = {.rowSize = pHead->len, .rowData = pHead->cont, .table = pTable};
|
||||||
code = (*pTable->decodeFp)(&oper);
|
code = (*pTable->decodeFp)(&oper);
|
||||||
|
@ -627,7 +638,7 @@ int32_t sdbInsertRow(SSdbOper *pOper) {
|
||||||
memcpy(pNewOper, pOper, sizeof(SSdbOper));
|
memcpy(pNewOper, pOper, sizeof(SSdbOper));
|
||||||
|
|
||||||
if (pNewOper->pMsg != NULL) {
|
if (pNewOper->pMsg != NULL) {
|
||||||
sdbDebug("app:%p:%p, table:%s record:%p:%s, insert action is add to sdb queue, ", pNewOper->pMsg->rpcMsg.ahandle,
|
sdbDebug("app:%p:%p, table:%s record:%p:%s, insert action is add to sdb queue", pNewOper->pMsg->rpcMsg.ahandle,
|
||||||
pNewOper->pMsg, pTable->tableName, pOper->pObj, sdbGetKeyStrFromObj(pTable, pOper->pObj));
|
pNewOper->pMsg, pTable->tableName, pOper->pObj, sdbGetKeyStrFromObj(pTable, pOper->pObj));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -677,7 +688,7 @@ int32_t sdbDeleteRow(SSdbOper *pOper) {
|
||||||
memcpy(pNewOper, pOper, sizeof(SSdbOper));
|
memcpy(pNewOper, pOper, sizeof(SSdbOper));
|
||||||
|
|
||||||
if (pNewOper->pMsg != NULL) {
|
if (pNewOper->pMsg != NULL) {
|
||||||
sdbDebug("app:%p:%p, table:%s record:%p:%s, delete action is add to sdb queue, ", pNewOper->pMsg->rpcMsg.ahandle,
|
sdbDebug("app:%p:%p, table:%s record:%p:%s, delete action is add to sdb queue", pNewOper->pMsg->rpcMsg.ahandle,
|
||||||
pNewOper->pMsg, pTable->tableName, pOper->pObj, sdbGetKeyStrFromObj(pTable, pOper->pObj));
|
pNewOper->pMsg, pTable->tableName, pOper->pObj, sdbGetKeyStrFromObj(pTable, pOper->pObj));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -727,7 +738,7 @@ int32_t sdbUpdateRow(SSdbOper *pOper) {
|
||||||
memcpy(pNewOper, pOper, sizeof(SSdbOper));
|
memcpy(pNewOper, pOper, sizeof(SSdbOper));
|
||||||
|
|
||||||
if (pNewOper->pMsg != NULL) {
|
if (pNewOper->pMsg != NULL) {
|
||||||
sdbDebug("app:%p:%p, table:%s record:%p:%s, update action is add to sdb queue, ", pNewOper->pMsg->rpcMsg.ahandle,
|
sdbDebug("app:%p:%p, table:%s record:%p:%s, update action is add to sdb queue", pNewOper->pMsg->rpcMsg.ahandle,
|
||||||
pNewOper->pMsg, pTable->tableName, pOper->pObj, sdbGetKeyStrFromObj(pTable, pOper->pObj));
|
pNewOper->pMsg, pTable->tableName, pOper->pObj, sdbGetKeyStrFromObj(pTable, pOper->pObj));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -943,20 +954,24 @@ static void *sdbWorkerFp(void *param) {
|
||||||
taosGetQitem(tsSdbWriteQall, &type, &item);
|
taosGetQitem(tsSdbWriteQall, &type, &item);
|
||||||
if (type == TAOS_QTYPE_RPC) {
|
if (type == TAOS_QTYPE_RPC) {
|
||||||
pOper = (SSdbOper *)item;
|
pOper = (SSdbOper *)item;
|
||||||
|
pOper->processedCount = 1;
|
||||||
pHead = (void *)pOper + sizeof(SSdbOper) + SDB_SYNC_HACK;
|
pHead = (void *)pOper + sizeof(SSdbOper) + SDB_SYNC_HACK;
|
||||||
|
if (pOper->pMsg != NULL) {
|
||||||
|
sdbDebug("app:%p:%p, table:%s record:%p:%s ver:%" PRIu64 ", will be processed in sdb queue",
|
||||||
|
pOper->pMsg->rpcMsg.ahandle, pOper->pMsg, ((SSdbTable *)pOper->table)->tableName, pOper->pObj,
|
||||||
|
sdbGetKeyStr(pOper->table, pHead->cont), pHead->version);
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
pHead = (SWalHead *)item;
|
pHead = (SWalHead *)item;
|
||||||
pOper = NULL;
|
pOper = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (pOper != NULL && pOper->pMsg != NULL) {
|
|
||||||
sdbDebug("app:%p:%p, table:%s record:%p:%s version:%" PRIu64 ", will be processed in sdb queue",
|
|
||||||
pOper->pMsg->rpcMsg.ahandle, pOper->pMsg, ((SSdbTable *)pOper->table)->tableName, pOper->pObj,
|
|
||||||
sdbGetKeyStr(pOper->table, pHead->cont), pHead->version);
|
|
||||||
}
|
|
||||||
|
|
||||||
int32_t code = sdbWrite(pOper, pHead, type);
|
int32_t code = sdbWrite(pOper, pHead, type);
|
||||||
if (pOper) pOper->retCode = code;
|
if (code > 0) code = 0;
|
||||||
|
if (pOper)
|
||||||
|
pOper->retCode = code;
|
||||||
|
else
|
||||||
|
pHead->len = code; // hackway
|
||||||
}
|
}
|
||||||
|
|
||||||
walFsync(tsSdbObj.wal);
|
walFsync(tsSdbObj.wal);
|
||||||
|
@ -965,25 +980,18 @@ static void *sdbWorkerFp(void *param) {
|
||||||
taosResetQitems(tsSdbWriteQall);
|
taosResetQitems(tsSdbWriteQall);
|
||||||
for (int32_t i = 0; i < numOfMsgs; ++i) {
|
for (int32_t i = 0; i < numOfMsgs; ++i) {
|
||||||
taosGetQitem(tsSdbWriteQall, &type, &item);
|
taosGetQitem(tsSdbWriteQall, &type, &item);
|
||||||
|
|
||||||
if (type == TAOS_QTYPE_RPC) {
|
if (type == TAOS_QTYPE_RPC) {
|
||||||
pOper = (SSdbOper *)item;
|
pOper = (SSdbOper *)item;
|
||||||
if (pOper != NULL && pOper->cb != NULL) {
|
sdbDecRef(pOper->table, pOper->pObj);
|
||||||
sdbTrace("app:%p:%p, will do callback func, index:%d", pOper->pMsg->rpcMsg.ahandle, pOper->pMsg, i);
|
sdbConfirmForward(NULL, pOper, pOper->retCode);
|
||||||
pOper->retCode = (*pOper->cb)(pOper->pMsg, pOper->retCode);
|
} else if (type == TAOS_QTYPE_FWD) {
|
||||||
}
|
pHead = (SWalHead *)item;
|
||||||
|
syncConfirmForward(tsSdbObj.sync, pHead->version, pHead->len);
|
||||||
if (pOper != NULL && pOper->pMsg != NULL) {
|
taosFreeQitem(item);
|
||||||
sdbTrace("app:%p:%p, msg is processed, result:%s", pOper->pMsg->rpcMsg.ahandle, pOper->pMsg,
|
} else {
|
||||||
tstrerror(pOper->retCode));
|
taosFreeQitem(item);
|
||||||
}
|
|
||||||
|
|
||||||
if (pOper != NULL) {
|
|
||||||
sdbDecRef(pOper->table, pOper->pObj);
|
|
||||||
}
|
|
||||||
|
|
||||||
dnodeSendRpcMnodeWriteRsp(pOper->pMsg, pOper->retCode);
|
|
||||||
}
|
}
|
||||||
taosFreeQitem(item);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -307,6 +307,12 @@ static int32_t mnodeProcessConnectMsg(SMnodeMsg *pMsg) {
|
||||||
code = TSDB_CODE_MND_INVALID_DB;
|
code = TSDB_CODE_MND_INVALID_DB;
|
||||||
goto connect_over;
|
goto connect_over;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (pDb->status != TSDB_DB_STATUS_READY) {
|
||||||
|
mError("db:%s, status:%d, in dropping", pDb->name, pDb->status);
|
||||||
|
code = TSDB_CODE_MND_DB_IN_DROPPING;
|
||||||
|
goto connect_over;
|
||||||
|
}
|
||||||
mnodeDecDbRef(pDb);
|
mnodeDecDbRef(pDb);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -350,7 +356,12 @@ static int32_t mnodeProcessUseMsg(SMnodeMsg *pMsg) {
|
||||||
int32_t code = TSDB_CODE_SUCCESS;
|
int32_t code = TSDB_CODE_SUCCESS;
|
||||||
if (pMsg->pDb == NULL) pMsg->pDb = mnodeGetDb(pUseDbMsg->db);
|
if (pMsg->pDb == NULL) pMsg->pDb = mnodeGetDb(pUseDbMsg->db);
|
||||||
if (pMsg->pDb == NULL) {
|
if (pMsg->pDb == NULL) {
|
||||||
code = TSDB_CODE_MND_INVALID_DB;
|
return TSDB_CODE_MND_INVALID_DB;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (pMsg->pDb->status != TSDB_DB_STATUS_READY) {
|
||||||
|
mError("db:%s, status:%d, in dropping", pMsg->pDb->name, pMsg->pDb->status);
|
||||||
|
return TSDB_CODE_MND_DB_IN_DROPPING;
|
||||||
}
|
}
|
||||||
|
|
||||||
return code;
|
return code;
|
||||||
|
|
|
@ -116,6 +116,11 @@ static int32_t mnodeChildTableActionInsert(SSdbOper *pOper) {
|
||||||
mError("ctable:%s, vgId:%d not in db:%s", pTable->info.tableId, pVgroup->vgId, pVgroup->dbName);
|
mError("ctable:%s, vgId:%d not in db:%s", pTable->info.tableId, pVgroup->vgId, pVgroup->dbName);
|
||||||
return TSDB_CODE_MND_INVALID_DB;
|
return TSDB_CODE_MND_INVALID_DB;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (pDb->status != TSDB_DB_STATUS_READY) {
|
||||||
|
mError("db:%s, status:%d, in dropping", pDb->name, pDb->status);
|
||||||
|
return TSDB_CODE_MND_DB_IN_DROPPING;
|
||||||
|
}
|
||||||
mnodeDecDbRef(pDb);
|
mnodeDecDbRef(pDb);
|
||||||
|
|
||||||
SAcctObj *pAcct = mnodeGetAcct(pDb->acct);
|
SAcctObj *pAcct = mnodeGetAcct(pDb->acct);
|
||||||
|
@ -284,8 +289,8 @@ static int32_t mnodeChildTableActionRestored() {
|
||||||
if (pTable == NULL) break;
|
if (pTable == NULL) break;
|
||||||
|
|
||||||
SDbObj *pDb = mnodeGetDbByTableId(pTable->info.tableId);
|
SDbObj *pDb = mnodeGetDbByTableId(pTable->info.tableId);
|
||||||
if (pDb == NULL) {
|
if (pDb == NULL || pDb->status != TSDB_DB_STATUS_READY) {
|
||||||
mError("ctable:%s, failed to get db, discard it", pTable->info.tableId);
|
mError("ctable:%s, failed to get db or db in dropping, discard it", pTable->info.tableId);
|
||||||
SSdbOper desc = {.type = SDB_OPER_LOCAL, .pObj = pTable, .table = tsChildTableSdb};
|
SSdbOper desc = {.type = SDB_OPER_LOCAL, .pObj = pTable, .table = tsChildTableSdb};
|
||||||
sdbDeleteRow(&desc);
|
sdbDeleteRow(&desc);
|
||||||
mnodeDecTableRef(pTable);
|
mnodeDecTableRef(pTable);
|
||||||
|
@ -376,6 +381,7 @@ static int32_t mnodeInitChildTables() {
|
||||||
|
|
||||||
static void mnodeCleanupChildTables() {
|
static void mnodeCleanupChildTables() {
|
||||||
sdbCloseTable(tsChildTableSdb);
|
sdbCloseTable(tsChildTableSdb);
|
||||||
|
tsChildTableSdb = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void mnodeAddTableIntoStable(SSuperTableObj *pStable, SChildTableObj *pCtable) {
|
static void mnodeAddTableIntoStable(SSuperTableObj *pStable, SChildTableObj *pCtable) {
|
||||||
|
@ -422,7 +428,7 @@ static int32_t mnodeSuperTableActionDestroy(SSdbOper *pOper) {
|
||||||
static int32_t mnodeSuperTableActionInsert(SSdbOper *pOper) {
|
static int32_t mnodeSuperTableActionInsert(SSdbOper *pOper) {
|
||||||
SSuperTableObj *pStable = pOper->pObj;
|
SSuperTableObj *pStable = pOper->pObj;
|
||||||
SDbObj *pDb = mnodeGetDbByTableId(pStable->info.tableId);
|
SDbObj *pDb = mnodeGetDbByTableId(pStable->info.tableId);
|
||||||
if (pDb != NULL) {
|
if (pDb != NULL && pDb->status == TSDB_DB_STATUS_READY) {
|
||||||
mnodeAddSuperTableIntoDb(pDb);
|
mnodeAddSuperTableIntoDb(pDb);
|
||||||
}
|
}
|
||||||
mnodeDecDbRef(pDb);
|
mnodeDecDbRef(pDb);
|
||||||
|
@ -554,6 +560,7 @@ static int32_t mnodeInitSuperTables() {
|
||||||
|
|
||||||
static void mnodeCleanupSuperTables() {
|
static void mnodeCleanupSuperTables() {
|
||||||
sdbCloseTable(tsSuperTableSdb);
|
sdbCloseTable(tsSuperTableSdb);
|
||||||
|
tsSuperTableSdb = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t mnodeInitTables() {
|
int32_t mnodeInitTables() {
|
||||||
|
@ -683,11 +690,16 @@ static int32_t mnodeProcessCreateTableMsg(SMnodeMsg *pMsg) {
|
||||||
SCMCreateTableMsg *pCreate = pMsg->rpcMsg.pCont;
|
SCMCreateTableMsg *pCreate = pMsg->rpcMsg.pCont;
|
||||||
|
|
||||||
if (pMsg->pDb == NULL) pMsg->pDb = mnodeGetDb(pCreate->db);
|
if (pMsg->pDb == NULL) pMsg->pDb = mnodeGetDb(pCreate->db);
|
||||||
if (pMsg->pDb == NULL || pMsg->pDb->status != TSDB_DB_STATUS_READY) {
|
if (pMsg->pDb == NULL) {
|
||||||
mError("app:%p:%p, table:%s, failed to create, db not selected", pMsg->rpcMsg.ahandle, pMsg, pCreate->tableId);
|
mError("app:%p:%p, table:%s, failed to create, db not selected", pMsg->rpcMsg.ahandle, pMsg, pCreate->tableId);
|
||||||
return TSDB_CODE_MND_DB_NOT_SELECTED;
|
return TSDB_CODE_MND_DB_NOT_SELECTED;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (pMsg->pDb->status != TSDB_DB_STATUS_READY) {
|
||||||
|
mError("db:%s, status:%d, in dropping", pMsg->pDb->name, pMsg->pDb->status);
|
||||||
|
return TSDB_CODE_MND_DB_IN_DROPPING;
|
||||||
|
}
|
||||||
|
|
||||||
if (pMsg->pTable == NULL) pMsg->pTable = mnodeGetTable(pCreate->tableId);
|
if (pMsg->pTable == NULL) pMsg->pTable = mnodeGetTable(pCreate->tableId);
|
||||||
if (pMsg->pTable != NULL && pMsg->retry == 0) {
|
if (pMsg->pTable != NULL && pMsg->retry == 0) {
|
||||||
if (pCreate->getMeta) {
|
if (pCreate->getMeta) {
|
||||||
|
@ -717,11 +729,16 @@ static int32_t mnodeProcessCreateTableMsg(SMnodeMsg *pMsg) {
|
||||||
static int32_t mnodeProcessDropTableMsg(SMnodeMsg *pMsg) {
|
static int32_t mnodeProcessDropTableMsg(SMnodeMsg *pMsg) {
|
||||||
SCMDropTableMsg *pDrop = pMsg->rpcMsg.pCont;
|
SCMDropTableMsg *pDrop = pMsg->rpcMsg.pCont;
|
||||||
if (pMsg->pDb == NULL) pMsg->pDb = mnodeGetDbByTableId(pDrop->tableId);
|
if (pMsg->pDb == NULL) pMsg->pDb = mnodeGetDbByTableId(pDrop->tableId);
|
||||||
if (pMsg->pDb == NULL || pMsg->pDb->status != TSDB_DB_STATUS_READY) {
|
if (pMsg->pDb == NULL) {
|
||||||
mError("app:%p:%p, table:%s, failed to drop table, db not selected", pMsg->rpcMsg.ahandle, pMsg, pDrop->tableId);
|
mError("app:%p:%p, table:%s, failed to drop table, db not selected or db in dropping", pMsg->rpcMsg.ahandle, pMsg, pDrop->tableId);
|
||||||
return TSDB_CODE_MND_DB_NOT_SELECTED;
|
return TSDB_CODE_MND_DB_NOT_SELECTED;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (pMsg->pDb->status != TSDB_DB_STATUS_READY) {
|
||||||
|
mError("db:%s, status:%d, in dropping", pMsg->pDb->name, pMsg->pDb->status);
|
||||||
|
return TSDB_CODE_MND_DB_IN_DROPPING;
|
||||||
|
}
|
||||||
|
|
||||||
if (mnodeCheckIsMonitorDB(pMsg->pDb->name, tsMonitorDbName)) {
|
if (mnodeCheckIsMonitorDB(pMsg->pDb->name, tsMonitorDbName)) {
|
||||||
mError("app:%p:%p, table:%s, failed to drop table, in monitor database", pMsg->rpcMsg.ahandle, pMsg,
|
mError("app:%p:%p, table:%s, failed to drop table, in monitor database", pMsg->rpcMsg.ahandle, pMsg,
|
||||||
pDrop->tableId);
|
pDrop->tableId);
|
||||||
|
@ -755,12 +772,17 @@ static int32_t mnodeProcessTableMetaMsg(SMnodeMsg *pMsg) {
|
||||||
pInfo->tableId, pMsg->rpcMsg.handle, pInfo->createFlag);
|
pInfo->tableId, pMsg->rpcMsg.handle, pInfo->createFlag);
|
||||||
|
|
||||||
if (pMsg->pDb == NULL) pMsg->pDb = mnodeGetDbByTableId(pInfo->tableId);
|
if (pMsg->pDb == NULL) pMsg->pDb = mnodeGetDbByTableId(pInfo->tableId);
|
||||||
if (pMsg->pDb == NULL || pMsg->pDb->status != TSDB_DB_STATUS_READY) {
|
if (pMsg->pDb == NULL) {
|
||||||
mError("app:%p:%p, table:%s, failed to get table meta, db not selected", pMsg->rpcMsg.ahandle, pMsg,
|
mError("app:%p:%p, table:%s, failed to get table meta, db not selected", pMsg->rpcMsg.ahandle, pMsg,
|
||||||
pInfo->tableId);
|
pInfo->tableId);
|
||||||
return TSDB_CODE_MND_DB_NOT_SELECTED;
|
return TSDB_CODE_MND_DB_NOT_SELECTED;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (pMsg->pDb->status != TSDB_DB_STATUS_READY) {
|
||||||
|
mError("db:%s, status:%d, in dropping", pMsg->pDb->name, pMsg->pDb->status);
|
||||||
|
return TSDB_CODE_MND_DB_IN_DROPPING;
|
||||||
|
}
|
||||||
|
|
||||||
if (pMsg->pTable == NULL) pMsg->pTable = mnodeGetTable(pInfo->tableId);
|
if (pMsg->pTable == NULL) pMsg->pTable = mnodeGetTable(pInfo->tableId);
|
||||||
if (pMsg->pTable == NULL) {
|
if (pMsg->pTable == NULL) {
|
||||||
if (!pInfo->createFlag) {
|
if (!pInfo->createFlag) {
|
||||||
|
@ -783,9 +805,15 @@ static int32_t mnodeProcessTableMetaMsg(SMnodeMsg *pMsg) {
|
||||||
|
|
||||||
static int32_t mnodeCreateSuperTableCb(SMnodeMsg *pMsg, int32_t code) {
|
static int32_t mnodeCreateSuperTableCb(SMnodeMsg *pMsg, int32_t code) {
|
||||||
SSuperTableObj *pTable = (SSuperTableObj *)pMsg->pTable;
|
SSuperTableObj *pTable = (SSuperTableObj *)pMsg->pTable;
|
||||||
if (pTable != NULL) {
|
assert(pTable);
|
||||||
mLInfo("app:%p:%p, stable:%s, is created in sdb, result:%s", pMsg->rpcMsg.ahandle, pMsg, pTable->info.tableId,
|
|
||||||
tstrerror(code));
|
if (code == TSDB_CODE_SUCCESS) {
|
||||||
|
mLInfo("stable:%s, is created in sdb", pTable->info.tableId);
|
||||||
|
} else {
|
||||||
|
mError("app:%p:%p, stable:%s, failed to create in sdb, reason:%s", pMsg->rpcMsg.ahandle, pMsg, pTable->info.tableId,
|
||||||
|
tstrerror(code));
|
||||||
|
SSdbOper desc = {.type = SDB_OPER_GLOBAL, .pObj = pTable, .table = tsSuperTableSdb};
|
||||||
|
sdbDeleteRow(&desc);
|
||||||
}
|
}
|
||||||
|
|
||||||
return code;
|
return code;
|
||||||
|
@ -1202,6 +1230,11 @@ static int32_t mnodeGetShowSuperTableMeta(STableMetaMsg *pMeta, SShowObj *pShow,
|
||||||
SDbObj *pDb = mnodeGetDb(pShow->db);
|
SDbObj *pDb = mnodeGetDb(pShow->db);
|
||||||
if (pDb == NULL) return TSDB_CODE_MND_DB_NOT_SELECTED;
|
if (pDb == NULL) return TSDB_CODE_MND_DB_NOT_SELECTED;
|
||||||
|
|
||||||
|
if (pDb->status != TSDB_DB_STATUS_READY) {
|
||||||
|
mError("db:%s, status:%d, in dropping", pDb->name, pDb->status);
|
||||||
|
return TSDB_CODE_MND_DB_IN_DROPPING;
|
||||||
|
}
|
||||||
|
|
||||||
int32_t cols = 0;
|
int32_t cols = 0;
|
||||||
SSchema *pSchema = pMeta->schema;
|
SSchema *pSchema = pMeta->schema;
|
||||||
|
|
||||||
|
@ -1261,6 +1294,11 @@ int32_t mnodeRetrieveShowSuperTables(SShowObj *pShow, char *data, int32_t rows,
|
||||||
SDbObj *pDb = mnodeGetDb(pShow->db);
|
SDbObj *pDb = mnodeGetDb(pShow->db);
|
||||||
if (pDb == NULL) return 0;
|
if (pDb == NULL) return 0;
|
||||||
|
|
||||||
|
if (pDb->status != TSDB_DB_STATUS_READY) {
|
||||||
|
mError("db:%s, status:%d, in dropping", pDb->name, pDb->status);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
tstrncpy(prefix, pDb->name, 64);
|
tstrncpy(prefix, pDb->name, 64);
|
||||||
strcat(prefix, TS_PATH_DELIMITER);
|
strcat(prefix, TS_PATH_DELIMITER);
|
||||||
prefixLen = strlen(prefix);
|
prefixLen = strlen(prefix);
|
||||||
|
@ -1561,10 +1599,16 @@ static int32_t mnodeDoCreateChildTableCb(SMnodeMsg *pMsg, int32_t code) {
|
||||||
SChildTableObj *pTable = (SChildTableObj *)pMsg->pTable;
|
SChildTableObj *pTable = (SChildTableObj *)pMsg->pTable;
|
||||||
assert(pTable);
|
assert(pTable);
|
||||||
|
|
||||||
mDebug("app:%p:%p, table:%s, create table in id:%d, uid:%" PRIu64 ", result:%s", pMsg->rpcMsg.ahandle, pMsg,
|
if (code == TSDB_CODE_SUCCESS) {
|
||||||
pTable->info.tableId, pTable->sid, pTable->uid, tstrerror(code));
|
mDebug("app:%p:%p, table:%s, create table in sid:%d, uid:%" PRIu64, pMsg->rpcMsg.ahandle, pMsg, pTable->info.tableId,
|
||||||
|
pTable->sid, pTable->uid);
|
||||||
if (code != TSDB_CODE_SUCCESS) return code;
|
} else {
|
||||||
|
mError("app:%p:%p, table:%s, failed to create table sid:%d, uid:%" PRIu64 ", reason:%s", pMsg->rpcMsg.ahandle, pMsg,
|
||||||
|
pTable->info.tableId, pTable->sid, pTable->uid, tstrerror(code));
|
||||||
|
SSdbOper desc = {.type = SDB_OPER_GLOBAL, .pObj = pTable, .table = tsChildTableSdb};
|
||||||
|
sdbDeleteRow(&desc);
|
||||||
|
return code;
|
||||||
|
}
|
||||||
|
|
||||||
SCMCreateTableMsg *pCreate = pMsg->rpcMsg.pCont;
|
SCMCreateTableMsg *pCreate = pMsg->rpcMsg.pCont;
|
||||||
SMDCreateTableMsg *pMDCreate = mnodeBuildCreateChildTableMsg(pCreate, pTable);
|
SMDCreateTableMsg *pMDCreate = mnodeBuildCreateChildTableMsg(pCreate, pTable);
|
||||||
|
@ -2285,7 +2329,7 @@ static int32_t mnodeProcessMultiTableMetaMsg(SMnodeMsg *pMsg) {
|
||||||
if (pTable == NULL) continue;
|
if (pTable == NULL) continue;
|
||||||
|
|
||||||
if (pMsg->pDb == NULL) pMsg->pDb = mnodeGetDbByTableId(tableId);
|
if (pMsg->pDb == NULL) pMsg->pDb = mnodeGetDbByTableId(tableId);
|
||||||
if (pMsg->pDb == NULL) {
|
if (pMsg->pDb == NULL || pMsg->pDb->status != TSDB_DB_STATUS_READY) {
|
||||||
mnodeDecTableRef(pTable);
|
mnodeDecTableRef(pTable);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
@ -2324,6 +2368,11 @@ static int32_t mnodeGetShowTableMeta(STableMetaMsg *pMeta, SShowObj *pShow, void
|
||||||
SDbObj *pDb = mnodeGetDb(pShow->db);
|
SDbObj *pDb = mnodeGetDb(pShow->db);
|
||||||
if (pDb == NULL) return TSDB_CODE_MND_DB_NOT_SELECTED;
|
if (pDb == NULL) return TSDB_CODE_MND_DB_NOT_SELECTED;
|
||||||
|
|
||||||
|
if (pDb->status != TSDB_DB_STATUS_READY) {
|
||||||
|
mError("db:%s, status:%d, in dropping", pDb->name, pDb->status);
|
||||||
|
return TSDB_CODE_MND_DB_IN_DROPPING;
|
||||||
|
}
|
||||||
|
|
||||||
int32_t cols = 0;
|
int32_t cols = 0;
|
||||||
SSchema *pSchema = pMeta->schema;
|
SSchema *pSchema = pMeta->schema;
|
||||||
|
|
||||||
|
@ -2372,6 +2421,11 @@ static int32_t mnodeRetrieveShowTables(SShowObj *pShow, char *data, int32_t rows
|
||||||
SDbObj *pDb = mnodeGetDb(pShow->db);
|
SDbObj *pDb = mnodeGetDb(pShow->db);
|
||||||
if (pDb == NULL) return 0;
|
if (pDb == NULL) return 0;
|
||||||
|
|
||||||
|
if (pDb->status != TSDB_DB_STATUS_READY) {
|
||||||
|
mError("db:%s, status:%d, in dropping", pDb->name, pDb->status);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
int32_t numOfRows = 0;
|
int32_t numOfRows = 0;
|
||||||
SChildTableObj *pTable = NULL;
|
SChildTableObj *pTable = NULL;
|
||||||
SPatternCompareInfo info = PATTERN_COMPARE_INFO_INITIALIZER;
|
SPatternCompareInfo info = PATTERN_COMPARE_INFO_INITIALIZER;
|
||||||
|
@ -2462,11 +2516,16 @@ static int32_t mnodeProcessAlterTableMsg(SMnodeMsg *pMsg) {
|
||||||
pAlter->tableId, pMsg->rpcMsg.handle);
|
pAlter->tableId, pMsg->rpcMsg.handle);
|
||||||
|
|
||||||
if (pMsg->pDb == NULL) pMsg->pDb = mnodeGetDbByTableId(pAlter->tableId);
|
if (pMsg->pDb == NULL) pMsg->pDb = mnodeGetDbByTableId(pAlter->tableId);
|
||||||
if (pMsg->pDb == NULL || pMsg->pDb->status != TSDB_DB_STATUS_READY) {
|
if (pMsg->pDb == NULL) {
|
||||||
mError("app:%p:%p, table:%s, failed to alter table, db not selected", pMsg->rpcMsg.ahandle, pMsg, pAlter->tableId);
|
mError("app:%p:%p, table:%s, failed to alter table, db not selected", pMsg->rpcMsg.ahandle, pMsg, pAlter->tableId);
|
||||||
return TSDB_CODE_MND_DB_NOT_SELECTED;
|
return TSDB_CODE_MND_DB_NOT_SELECTED;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (pMsg->pDb->status != TSDB_DB_STATUS_READY) {
|
||||||
|
mError("db:%s, status:%d, in dropping", pMsg->pDb->name, pMsg->pDb->status);
|
||||||
|
return TSDB_CODE_MND_DB_IN_DROPPING;
|
||||||
|
}
|
||||||
|
|
||||||
if (mnodeCheckIsMonitorDB(pMsg->pDb->name, tsMonitorDbName)) {
|
if (mnodeCheckIsMonitorDB(pMsg->pDb->name, tsMonitorDbName)) {
|
||||||
mError("app:%p:%p, table:%s, failed to alter table, its log db", pMsg->rpcMsg.ahandle, pMsg, pAlter->tableId);
|
mError("app:%p:%p, table:%s, failed to alter table, its log db", pMsg->rpcMsg.ahandle, pMsg, pAlter->tableId);
|
||||||
return TSDB_CODE_MND_MONITOR_DB_FORBIDDEN;
|
return TSDB_CODE_MND_MONITOR_DB_FORBIDDEN;
|
||||||
|
@ -2526,6 +2585,11 @@ static int32_t mnodeGetStreamTableMeta(STableMetaMsg *pMeta, SShowObj *pShow, vo
|
||||||
SDbObj *pDb = mnodeGetDb(pShow->db);
|
SDbObj *pDb = mnodeGetDb(pShow->db);
|
||||||
if (pDb == NULL) return TSDB_CODE_MND_DB_NOT_SELECTED;
|
if (pDb == NULL) return TSDB_CODE_MND_DB_NOT_SELECTED;
|
||||||
|
|
||||||
|
if (pDb->status != TSDB_DB_STATUS_READY) {
|
||||||
|
mError("db:%s, status:%d, in dropping", pDb->name, pDb->status);
|
||||||
|
return TSDB_CODE_MND_DB_IN_DROPPING;
|
||||||
|
}
|
||||||
|
|
||||||
int32_t cols = 0;
|
int32_t cols = 0;
|
||||||
SSchema *pSchema = pMeta->schema;
|
SSchema *pSchema = pMeta->schema;
|
||||||
|
|
||||||
|
@ -2573,6 +2637,10 @@ static int32_t mnodeRetrieveStreamTables(SShowObj *pShow, char *data, int32_t ro
|
||||||
SDbObj *pDb = mnodeGetDb(pShow->db);
|
SDbObj *pDb = mnodeGetDb(pShow->db);
|
||||||
if (pDb == NULL) return 0;
|
if (pDb == NULL) return 0;
|
||||||
|
|
||||||
|
if (pDb->status != TSDB_DB_STATUS_READY) {
|
||||||
|
mError("db:%s, status:%d, in dropping", pDb->name, pDb->status);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
int32_t numOfRows = 0;
|
int32_t numOfRows = 0;
|
||||||
SChildTableObj *pTable = NULL;
|
SChildTableObj *pTable = NULL;
|
||||||
|
|
|
@ -154,6 +154,7 @@ int32_t mnodeInitUsers() {
|
||||||
|
|
||||||
void mnodeCleanupUsers() {
|
void mnodeCleanupUsers() {
|
||||||
sdbCloseTable(tsUserSdb);
|
sdbCloseTable(tsUserSdb);
|
||||||
|
tsUserSdb = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
SUserObj *mnodeGetUser(char *name) {
|
SUserObj *mnodeGetUser(char *name) {
|
||||||
|
|
|
@ -76,6 +76,11 @@ static int32_t mnodeVgroupActionInsert(SSdbOper *pOper) {
|
||||||
return TSDB_CODE_MND_INVALID_DB;
|
return TSDB_CODE_MND_INVALID_DB;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (pDb->status != TSDB_DB_STATUS_READY) {
|
||||||
|
mError("db:%s, status:%d, in dropping", pDb->name, pDb->status);
|
||||||
|
return TSDB_CODE_MND_DB_IN_DROPPING;
|
||||||
|
}
|
||||||
|
|
||||||
pVgroup->pDb = pDb;
|
pVgroup->pDb = pDb;
|
||||||
pVgroup->prev = NULL;
|
pVgroup->prev = NULL;
|
||||||
pVgroup->next = NULL;
|
pVgroup->next = NULL;
|
||||||
|
@ -165,10 +170,18 @@ static int32_t mnodeVgroupActionUpdate(SSdbOper *pOper) {
|
||||||
}
|
}
|
||||||
mnodeDecDnodeRef(pDnode);
|
mnodeDecDnodeRef(pDnode);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
free(pNew);
|
||||||
}
|
}
|
||||||
|
|
||||||
mnodeVgroupUpdateIdPool(pVgroup);
|
mnodeVgroupUpdateIdPool(pVgroup);
|
||||||
|
|
||||||
|
// reset vgid status on vgroup changed
|
||||||
|
mDebug("vgId:%d, reset sync status to unsynced", pVgroup->vgId);
|
||||||
|
for (int32_t v = 0; v < pVgroup->numOfVnodes; ++v) {
|
||||||
|
pVgroup->vnodeGid[v].role = TAOS_SYNC_ROLE_UNSYNCED;
|
||||||
|
}
|
||||||
|
|
||||||
mnodeDecVgroupRef(pVgroup);
|
mnodeDecVgroupRef(pVgroup);
|
||||||
|
|
||||||
mDebug("vgId:%d, is updated, numOfVnode:%d", pVgroup->vgId, pVgroup->numOfVnodes);
|
mDebug("vgId:%d, is updated, numOfVnode:%d", pVgroup->vgId, pVgroup->numOfVnodes);
|
||||||
|
@ -300,6 +313,7 @@ void mnodeUpdateVgroupStatus(SVgObj *pVgroup, SDnodeObj *pDnode, SVnodeLoad *pVl
|
||||||
for (int32_t i = 0; i < pVgroup->numOfVnodes; ++i) {
|
for (int32_t i = 0; i < pVgroup->numOfVnodes; ++i) {
|
||||||
SVnodeGid *pVgid = &pVgroup->vnodeGid[i];
|
SVnodeGid *pVgid = &pVgroup->vnodeGid[i];
|
||||||
if (pVgid->pDnode == pDnode) {
|
if (pVgid->pDnode == pDnode) {
|
||||||
|
mTrace("dnode:%d, receive status from dnode, vgId:%d status is %d", pVgroup->vgId, pDnode->dnodeId, pVgid->role);
|
||||||
pVgid->role = pVload->role;
|
pVgid->role = pVload->role;
|
||||||
if (pVload->role == TAOS_SYNC_ROLE_MASTER) {
|
if (pVload->role == TAOS_SYNC_ROLE_MASTER) {
|
||||||
pVgroup->inUse = i;
|
pVgroup->inUse = i;
|
||||||
|
@ -339,20 +353,25 @@ void *mnodeGetNextVgroup(void *pIter, SVgObj **pVgroup) {
|
||||||
}
|
}
|
||||||
|
|
||||||
static int32_t mnodeCreateVgroupCb(SMnodeMsg *pMsg, int32_t code) {
|
static int32_t mnodeCreateVgroupCb(SMnodeMsg *pMsg, int32_t code) {
|
||||||
|
SVgObj *pVgroup = pMsg->pVgroup;
|
||||||
|
SDbObj *pDb = pMsg->pDb;
|
||||||
|
assert(pVgroup);
|
||||||
|
|
||||||
if (code != TSDB_CODE_SUCCESS) {
|
if (code != TSDB_CODE_SUCCESS) {
|
||||||
pMsg->pVgroup = NULL;
|
mError("app:%p:%p, vgId:%d, failed to create in sdb, reason:%s", pMsg->rpcMsg.ahandle, pMsg, pVgroup->vgId,
|
||||||
|
tstrerror(code));
|
||||||
|
SSdbOper desc = {.type = SDB_OPER_GLOBAL, .pObj = pVgroup, .table = tsVgroupSdb};
|
||||||
|
sdbDeleteRow(&desc);
|
||||||
return code;
|
return code;
|
||||||
}
|
}
|
||||||
|
|
||||||
SVgObj *pVgroup = pMsg->pVgroup;
|
mInfo("app:%p:%p, vgId:%d, is created in mnode, db:%s replica:%d", pMsg->rpcMsg.ahandle, pMsg, pVgroup->vgId,
|
||||||
SDbObj *pDb = pMsg->pDb;
|
pDb->name, pVgroup->numOfVnodes);
|
||||||
|
|
||||||
mInfo("vgId:%d, is created in mnode, db:%s replica:%d", pVgroup->vgId, pDb->name, pVgroup->numOfVnodes);
|
|
||||||
for (int32_t i = 0; i < pVgroup->numOfVnodes; ++i) {
|
for (int32_t i = 0; i < pVgroup->numOfVnodes; ++i) {
|
||||||
mInfo("vgId:%d, index:%d, dnode:%d", pVgroup->vgId, i, pVgroup->vnodeGid[i].dnodeId);
|
mInfo("app:%p:%p, vgId:%d, index:%d, dnode:%d", pMsg->rpcMsg.ahandle, pMsg, pVgroup->vgId, i,
|
||||||
|
pVgroup->vnodeGid[i].dnodeId);
|
||||||
}
|
}
|
||||||
|
|
||||||
mnodeIncVgroupRef(pVgroup);
|
|
||||||
pMsg->expected = pVgroup->numOfVnodes;
|
pMsg->expected = pVgroup->numOfVnodes;
|
||||||
mnodeSendCreateVgroupMsg(pVgroup, pMsg);
|
mnodeSendCreateVgroupMsg(pVgroup, pMsg);
|
||||||
|
|
||||||
|
@ -373,6 +392,9 @@ int32_t mnodeCreateVgroup(SMnodeMsg *pMsg, SDbObj *pDb) {
|
||||||
return TSDB_CODE_MND_NO_ENOUGH_DNODES;
|
return TSDB_CODE_MND_NO_ENOUGH_DNODES;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pMsg->pVgroup = pVgroup;
|
||||||
|
mnodeIncVgroupRef(pVgroup);
|
||||||
|
|
||||||
SSdbOper oper = {
|
SSdbOper oper = {
|
||||||
.type = SDB_OPER_GLOBAL,
|
.type = SDB_OPER_GLOBAL,
|
||||||
.table = tsVgroupSdb,
|
.table = tsVgroupSdb,
|
||||||
|
@ -382,8 +404,6 @@ int32_t mnodeCreateVgroup(SMnodeMsg *pMsg, SDbObj *pDb) {
|
||||||
.cb = mnodeCreateVgroupCb
|
.cb = mnodeCreateVgroupCb
|
||||||
};
|
};
|
||||||
|
|
||||||
pMsg->pVgroup = pVgroup;
|
|
||||||
|
|
||||||
int32_t code = sdbInsertRow(&oper);
|
int32_t code = sdbInsertRow(&oper);
|
||||||
if (code != TSDB_CODE_SUCCESS) {
|
if (code != TSDB_CODE_SUCCESS) {
|
||||||
pMsg->pVgroup = NULL;
|
pMsg->pVgroup = NULL;
|
||||||
|
@ -412,6 +432,7 @@ void mnodeDropVgroup(SVgObj *pVgroup, void *ahandle) {
|
||||||
|
|
||||||
void mnodeCleanupVgroups() {
|
void mnodeCleanupVgroups() {
|
||||||
sdbCloseTable(tsVgroupSdb);
|
sdbCloseTable(tsVgroupSdb);
|
||||||
|
tsVgroupSdb = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t mnodeGetVgroupMeta(STableMetaMsg *pMeta, SShowObj *pShow, void *pConn) {
|
int32_t mnodeGetVgroupMeta(STableMetaMsg *pMeta, SShowObj *pShow, void *pConn) {
|
||||||
|
@ -420,6 +441,11 @@ int32_t mnodeGetVgroupMeta(STableMetaMsg *pMeta, SShowObj *pShow, void *pConn) {
|
||||||
return TSDB_CODE_MND_DB_NOT_SELECTED;
|
return TSDB_CODE_MND_DB_NOT_SELECTED;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (pDb->status != TSDB_DB_STATUS_READY) {
|
||||||
|
mError("db:%s, status:%d, in dropping", pDb->name, pDb->status);
|
||||||
|
return TSDB_CODE_MND_DB_IN_DROPPING;
|
||||||
|
}
|
||||||
|
|
||||||
int32_t cols = 0;
|
int32_t cols = 0;
|
||||||
SSchema *pSchema = pMeta->schema;
|
SSchema *pSchema = pMeta->schema;
|
||||||
|
|
||||||
|
@ -508,6 +534,11 @@ int32_t mnodeRetrieveVgroups(SShowObj *pShow, char *data, int32_t rows, void *pC
|
||||||
SDbObj *pDb = mnodeGetDb(pShow->db);
|
SDbObj *pDb = mnodeGetDb(pShow->db);
|
||||||
if (pDb == NULL) return 0;
|
if (pDb == NULL) return 0;
|
||||||
|
|
||||||
|
if (pDb->status != TSDB_DB_STATUS_READY) {
|
||||||
|
mError("db:%s, status:%d, in dropping", pDb->name, pDb->status);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
pVgroup = pDb->pHead;
|
pVgroup = pDb->pHead;
|
||||||
while (pVgroup != NULL) {
|
while (pVgroup != NULL) {
|
||||||
maxReplica = pVgroup->numOfVnodes > maxReplica ? pVgroup->numOfVnodes : maxReplica;
|
maxReplica = pVgroup->numOfVnodes > maxReplica ? pVgroup->numOfVnodes : maxReplica;
|
||||||
|
@ -681,9 +712,9 @@ static void mnodeProcessCreateVnodeRsp(SRpcMsg *rpcMsg) {
|
||||||
if (rpcMsg->ahandle == NULL) return;
|
if (rpcMsg->ahandle == NULL) return;
|
||||||
|
|
||||||
SMnodeMsg *mnodeMsg = rpcMsg->ahandle;
|
SMnodeMsg *mnodeMsg = rpcMsg->ahandle;
|
||||||
mnodeMsg->received++;
|
atomic_add_fetch_8(&mnodeMsg->received, 1);
|
||||||
if (rpcMsg->code == TSDB_CODE_SUCCESS) {
|
if (rpcMsg->code == TSDB_CODE_SUCCESS) {
|
||||||
mnodeMsg->successed++;
|
atomic_add_fetch_8(&mnodeMsg->successed, 1);
|
||||||
} else {
|
} else {
|
||||||
mnodeMsg->code = rpcMsg->code;
|
mnodeMsg->code = rpcMsg->code;
|
||||||
}
|
}
|
||||||
|
@ -783,19 +814,20 @@ static int32_t mnodeProcessVnodeCfgMsg(SMnodeMsg *pMsg) {
|
||||||
mDebug("dnode:%s, vgId:%d, invalid dnode", taosIpStr(pCfg->dnodeId), pCfg->vgId);
|
mDebug("dnode:%s, vgId:%d, invalid dnode", taosIpStr(pCfg->dnodeId), pCfg->vgId);
|
||||||
return TSDB_CODE_MND_VGROUP_NOT_EXIST;
|
return TSDB_CODE_MND_VGROUP_NOT_EXIST;
|
||||||
}
|
}
|
||||||
mnodeDecDnodeRef(pDnode);
|
|
||||||
|
|
||||||
SVgObj *pVgroup = mnodeGetVgroup(pCfg->vgId);
|
SVgObj *pVgroup = mnodeGetVgroup(pCfg->vgId);
|
||||||
if (pVgroup == NULL) {
|
if (pVgroup == NULL) {
|
||||||
mDebug("dnode:%s, vgId:%d, no vgroup info", taosIpStr(pCfg->dnodeId), pCfg->vgId);
|
mDebug("dnode:%s, vgId:%d, no vgroup info", taosIpStr(pCfg->dnodeId), pCfg->vgId);
|
||||||
|
mnodeDecDnodeRef(pDnode);
|
||||||
return TSDB_CODE_MND_VGROUP_NOT_EXIST;
|
return TSDB_CODE_MND_VGROUP_NOT_EXIST;
|
||||||
}
|
}
|
||||||
mnodeDecVgroupRef(pVgroup);
|
|
||||||
|
|
||||||
mDebug("vgId:%d, send create vnode msg to dnode %s for vnode cfg msg", pVgroup->vgId, pDnode->dnodeEp);
|
mDebug("vgId:%d, send create vnode msg to dnode %s for vnode cfg msg", pVgroup->vgId, pDnode->dnodeEp);
|
||||||
SRpcIpSet ipSet = mnodeGetIpSetFromIp(pDnode->dnodeEp);
|
SRpcIpSet ipSet = mnodeGetIpSetFromIp(pDnode->dnodeEp);
|
||||||
mnodeSendCreateVnodeMsg(pVgroup, &ipSet, NULL);
|
mnodeSendCreateVnodeMsg(pVgroup, &ipSet, NULL);
|
||||||
|
|
||||||
|
mnodeDecDnodeRef(pDnode);
|
||||||
|
mnodeDecVgroupRef(pVgroup);
|
||||||
return TSDB_CODE_SUCCESS;
|
return TSDB_CODE_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -206,7 +206,7 @@ typedef struct HttpThread {
|
||||||
pthread_mutex_t threadMutex;
|
pthread_mutex_t threadMutex;
|
||||||
bool stop;
|
bool stop;
|
||||||
int pollFd;
|
int pollFd;
|
||||||
int numOfFds;
|
int numOfContexts;
|
||||||
int threadId;
|
int threadId;
|
||||||
char label[HTTP_LABEL_SIZE];
|
char label[HTTP_LABEL_SIZE];
|
||||||
bool (*processData)(HttpContext *pContext);
|
bool (*processData)(HttpContext *pContext);
|
||||||
|
|
|
@ -26,8 +26,6 @@ extern int32_t httpDebugFlag;
|
||||||
#define httpInfo(...) { if (httpDebugFlag & DEBUG_INFO) { taosPrintLog("HTP INFO ", 255, __VA_ARGS__); }}
|
#define httpInfo(...) { if (httpDebugFlag & DEBUG_INFO) { taosPrintLog("HTP INFO ", 255, __VA_ARGS__); }}
|
||||||
#define httpDebug(...) { if (httpDebugFlag & DEBUG_DEBUG) { taosPrintLog("HTP DEBUG ", httpDebugFlag, __VA_ARGS__); }}
|
#define httpDebug(...) { if (httpDebugFlag & DEBUG_DEBUG) { taosPrintLog("HTP DEBUG ", httpDebugFlag, __VA_ARGS__); }}
|
||||||
#define httpTrace(...) { if (httpDebugFlag & DEBUG_TRACE) { taosPrintLog("HTP TRACE ", httpDebugFlag, __VA_ARGS__); }}
|
#define httpTrace(...) { if (httpDebugFlag & DEBUG_TRACE) { taosPrintLog("HTP TRACE ", httpDebugFlag, __VA_ARGS__); }}
|
||||||
|
#define httpTraceL(...){ if (httpDebugFlag & DEBUG_TRACE) { taosPrintLongString("HTP TRACE ", httpDebugFlag, __VA_ARGS__); }}
|
||||||
#define httpDebugDump(...) { if (httpDebugFlag & DEBUG_DEBUG) { taosPrintLongString("HTP DEBUG ", httpDebugFlag, __VA_ARGS__); }}
|
|
||||||
#define httpTraceDump(...) { if (httpDebugFlag & DEBUG_TRACE) { taosPrintLongString("HTP TRACE ", httpDebugFlag, __VA_ARGS__); }}
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -44,7 +44,7 @@ static void httpDestroyContext(void *data) {
|
||||||
HttpThread *pThread = pContext->pThread;
|
HttpThread *pThread = pContext->pThread;
|
||||||
httpRemoveContextFromEpoll(pContext);
|
httpRemoveContextFromEpoll(pContext);
|
||||||
httpReleaseSession(pContext);
|
httpReleaseSession(pContext);
|
||||||
atomic_sub_fetch_32(&pThread->numOfFds, 1);
|
atomic_sub_fetch_32(&pThread->numOfContexts, 1);
|
||||||
|
|
||||||
pContext->pThread = 0;
|
pContext->pThread = 0;
|
||||||
pContext->state = HTTP_CONTEXT_STATE_CLOSED;
|
pContext->state = HTTP_CONTEXT_STATE_CLOSED;
|
||||||
|
@ -171,38 +171,39 @@ bool httpInitContext(HttpContext *pContext) {
|
||||||
|
|
||||||
void httpCloseContextByApp(HttpContext *pContext) {
|
void httpCloseContextByApp(HttpContext *pContext) {
|
||||||
pContext->parsed = false;
|
pContext->parsed = false;
|
||||||
|
|
||||||
bool keepAlive = true;
|
bool keepAlive = true;
|
||||||
|
|
||||||
if (pContext->httpVersion == HTTP_VERSION_10 && pContext->httpKeepAlive != HTTP_KEEPALIVE_ENABLE) {
|
if (pContext->httpVersion == HTTP_VERSION_10 && pContext->httpKeepAlive != HTTP_KEEPALIVE_ENABLE) {
|
||||||
keepAlive = false;
|
keepAlive = false;
|
||||||
} else if (pContext->httpVersion != HTTP_VERSION_10 && pContext->httpKeepAlive == HTTP_KEEPALIVE_DISABLE) {
|
} else if (pContext->httpVersion != HTTP_VERSION_10 && pContext->httpKeepAlive == HTTP_KEEPALIVE_DISABLE) {
|
||||||
keepAlive = false;
|
keepAlive = false;
|
||||||
} else {}
|
} else {
|
||||||
|
}
|
||||||
|
|
||||||
if (keepAlive) {
|
if (keepAlive) {
|
||||||
if (httpAlterContextState(pContext, HTTP_CONTEXT_STATE_HANDLING, HTTP_CONTEXT_STATE_READY)) {
|
if (httpAlterContextState(pContext, HTTP_CONTEXT_STATE_HANDLING, HTTP_CONTEXT_STATE_READY)) {
|
||||||
httpDebug("context:%p, fd:%d, ip:%s, last state:handling, keepAlive:true, reuse connect",
|
httpDebug("context:%p, fd:%d, ip:%s, last state:handling, keepAlive:true, reuse context", pContext, pContext->fd,
|
||||||
pContext, pContext->fd, pContext->ipstr);
|
pContext->ipstr);
|
||||||
} else if (httpAlterContextState(pContext, HTTP_CONTEXT_STATE_DROPPING, HTTP_CONTEXT_STATE_CLOSED)) {
|
} else if (httpAlterContextState(pContext, HTTP_CONTEXT_STATE_DROPPING, HTTP_CONTEXT_STATE_CLOSED)) {
|
||||||
httpRemoveContextFromEpoll(pContext);
|
httpRemoveContextFromEpoll(pContext);
|
||||||
httpDebug("context:%p, fd:%d, ip:%s, last state:dropping, keepAlive:true, close connect",
|
httpDebug("context:%p, fd:%d, ip:%s, last state:dropping, keepAlive:true, close connect", pContext, pContext->fd,
|
||||||
pContext, pContext->fd, pContext->ipstr);
|
pContext->ipstr);
|
||||||
} else if (httpAlterContextState(pContext, HTTP_CONTEXT_STATE_READY, HTTP_CONTEXT_STATE_READY)) {
|
} else if (httpAlterContextState(pContext, HTTP_CONTEXT_STATE_READY, HTTP_CONTEXT_STATE_READY)) {
|
||||||
httpDebug("context:%p, fd:%d, ip:%s, last state:ready, keepAlive:true, reuse connect",
|
httpDebug("context:%p, fd:%d, ip:%s, last state:ready, keepAlive:true, reuse context", pContext, pContext->fd,
|
||||||
pContext, pContext->fd, pContext->ipstr);
|
pContext->ipstr);
|
||||||
} else if (httpAlterContextState(pContext, HTTP_CONTEXT_STATE_CLOSED, HTTP_CONTEXT_STATE_CLOSED)) {
|
} else if (httpAlterContextState(pContext, HTTP_CONTEXT_STATE_CLOSED, HTTP_CONTEXT_STATE_CLOSED)) {
|
||||||
httpRemoveContextFromEpoll(pContext);
|
httpRemoveContextFromEpoll(pContext);
|
||||||
httpDebug("context:%p, fd:%d, ip:%s, last state:ready, keepAlive:true, close connect",
|
httpDebug("context:%p, fd:%d, ip:%s, last state:ready, keepAlive:true, close connect", pContext, pContext->fd,
|
||||||
pContext, pContext->fd, pContext->ipstr);
|
pContext->ipstr);
|
||||||
} else {
|
} else {
|
||||||
httpRemoveContextFromEpoll(pContext);
|
httpRemoveContextFromEpoll(pContext);
|
||||||
httpError("context:%p, fd:%d, ip:%s, last state:%s:%d, keepAlive:true, close connect",
|
httpError("context:%p, fd:%d, ip:%s, last state:%s:%d, keepAlive:true, close connect", pContext, pContext->fd,
|
||||||
pContext, pContext->fd, pContext->ipstr, httpContextStateStr(pContext->state), pContext->state);
|
pContext->ipstr, httpContextStateStr(pContext->state), pContext->state);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
httpRemoveContextFromEpoll(pContext);
|
httpRemoveContextFromEpoll(pContext);
|
||||||
httpDebug("context:%p, fd:%d, ip:%s, last state:%s:%d, keepAlive:false, close connect",
|
httpDebug("context:%p, fd:%d, ip:%s, last state:%s:%d, keepAlive:false, close context", pContext, pContext->fd,
|
||||||
pContext, pContext->fd, pContext->ipstr, httpContextStateStr(pContext->state), pContext->state);
|
pContext->ipstr, httpContextStateStr(pContext->state), pContext->state);
|
||||||
}
|
}
|
||||||
|
|
||||||
httpReleaseContext(pContext);
|
httpReleaseContext(pContext);
|
||||||
|
@ -214,7 +215,7 @@ void httpCloseContextByServer(HttpContext *pContext) {
|
||||||
} else if (httpAlterContextState(pContext, HTTP_CONTEXT_STATE_DROPPING, HTTP_CONTEXT_STATE_DROPPING)) {
|
} else if (httpAlterContextState(pContext, HTTP_CONTEXT_STATE_DROPPING, HTTP_CONTEXT_STATE_DROPPING)) {
|
||||||
httpDebug("context:%p, fd:%d, ip:%s, epoll already finished, wait app finished", pContext, pContext->fd, pContext->ipstr);
|
httpDebug("context:%p, fd:%d, ip:%s, epoll already finished, wait app finished", pContext, pContext->fd, pContext->ipstr);
|
||||||
} else if (httpAlterContextState(pContext, HTTP_CONTEXT_STATE_READY, HTTP_CONTEXT_STATE_CLOSED)) {
|
} else if (httpAlterContextState(pContext, HTTP_CONTEXT_STATE_READY, HTTP_CONTEXT_STATE_CLOSED)) {
|
||||||
httpDebug("context:%p, fd:%d, ip:%s, epoll finished, close context", pContext, pContext->fd, pContext->ipstr);
|
httpDebug("context:%p, fd:%d, ip:%s, epoll finished, close connect", pContext, pContext->fd, pContext->ipstr);
|
||||||
} else if (httpAlterContextState(pContext, HTTP_CONTEXT_STATE_CLOSED, HTTP_CONTEXT_STATE_CLOSED)) {
|
} else if (httpAlterContextState(pContext, HTTP_CONTEXT_STATE_CLOSED, HTTP_CONTEXT_STATE_CLOSED)) {
|
||||||
httpDebug("context:%p, fd:%d, ip:%s, epoll finished, will be closed soon", pContext, pContext->fd, pContext->ipstr);
|
httpDebug("context:%p, fd:%d, ip:%s, epoll finished, will be closed soon", pContext, pContext->fd, pContext->ipstr);
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -313,9 +313,9 @@ bool httpParseRequest(HttpContext* pContext) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
httpTraceDump("context:%p, fd:%d, ip:%s, thread:%s, numOfFds:%d, read size:%d, raw data:\n%s", pContext, pContext->fd,
|
httpTraceL("context:%p, fd:%d, ip:%s, thread:%s, numOfContexts:%d, read size:%d, raw data:\n%s", pContext,
|
||||||
pContext->ipstr, pContext->pThread->label, pContext->pThread->numOfFds, pContext->parser.bufsize,
|
pContext->fd, pContext->ipstr, pContext->pThread->label, pContext->pThread->numOfContexts,
|
||||||
pContext->parser.buffer);
|
pContext->parser.bufsize, pContext->parser.buffer);
|
||||||
|
|
||||||
if (!httpGetHttpMethod(pContext)) {
|
if (!httpGetHttpMethod(pContext)) {
|
||||||
return false;
|
return false;
|
||||||
|
|
|
@ -108,7 +108,7 @@ bool httpReadDataImp(HttpContext *pContext) {
|
||||||
|
|
||||||
static bool httpDecompressData(HttpContext *pContext) {
|
static bool httpDecompressData(HttpContext *pContext) {
|
||||||
if (pContext->contentEncoding != HTTP_COMPRESS_GZIP) {
|
if (pContext->contentEncoding != HTTP_COMPRESS_GZIP) {
|
||||||
httpTraceDump("context:%p, fd:%d, ip:%s, content:%s", pContext, pContext->fd, pContext->ipstr, pContext->parser.data.pos);
|
httpTraceL("context:%p, fd:%d, ip:%s, content:%s", pContext, pContext->fd, pContext->ipstr, pContext->parser.data.pos);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -124,8 +124,8 @@ static bool httpDecompressData(HttpContext *pContext) {
|
||||||
if (ret == 0) {
|
if (ret == 0) {
|
||||||
memcpy(pContext->parser.data.pos, decompressBuf, decompressBufLen);
|
memcpy(pContext->parser.data.pos, decompressBuf, decompressBufLen);
|
||||||
pContext->parser.data.pos[decompressBufLen] = 0;
|
pContext->parser.data.pos[decompressBufLen] = 0;
|
||||||
httpTraceDump("context:%p, fd:%d, ip:%s, rawSize:%d, decompressSize:%d, content:%s",
|
httpTraceL("context:%p, fd:%d, ip:%s, rawSize:%d, decompressSize:%d, content:%s", pContext, pContext->fd,
|
||||||
pContext, pContext->fd, pContext->ipstr, pContext->parser.data.len, decompressBufLen, decompressBuf);
|
pContext->ipstr, pContext->parser.data.len, decompressBufLen, decompressBuf);
|
||||||
pContext->parser.data.len = decompressBufLen;
|
pContext->parser.data.len = decompressBufLen;
|
||||||
} else {
|
} else {
|
||||||
httpError("context:%p, fd:%d, ip:%s, failed to decompress data, rawSize:%d, error:%d",
|
httpError("context:%p, fd:%d, ip:%s, failed to decompress data, rawSize:%d, error:%d",
|
||||||
|
@ -293,7 +293,7 @@ static void *httpAcceptHttpConnection(void *arg) {
|
||||||
|
|
||||||
totalFds = 1;
|
totalFds = 1;
|
||||||
for (int i = 0; i < pServer->numOfThreads; ++i) {
|
for (int i = 0; i < pServer->numOfThreads; ++i) {
|
||||||
totalFds += pServer->pThreads[i].numOfFds;
|
totalFds += pServer->pThreads[i].numOfContexts;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (totalFds > tsHttpCacheSessions * 100) {
|
if (totalFds > tsHttpCacheSessions * 100) {
|
||||||
|
@ -332,9 +332,9 @@ static void *httpAcceptHttpConnection(void *arg) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// notify the data process, add into the FdObj list
|
// notify the data process, add into the FdObj list
|
||||||
atomic_add_fetch_32(&pThread->numOfFds, 1);
|
atomic_add_fetch_32(&pThread->numOfContexts, 1);
|
||||||
httpDebug("context:%p, fd:%d, ip:%s, thread:%s numOfFds:%d totalFds:%d, accept a new connection", pContext, connFd,
|
httpDebug("context:%p, fd:%d, ip:%s, thread:%s numOfContexts:%d totalFds:%d, accept a new connection", pContext,
|
||||||
pContext->ipstr, pThread->label, pThread->numOfFds, totalFds);
|
connFd, pContext->ipstr, pThread->label, pThread->numOfContexts, totalFds);
|
||||||
|
|
||||||
// pick up next thread for next connection
|
// pick up next thread for next connection
|
||||||
threadId++;
|
threadId++;
|
||||||
|
|
|
@ -166,8 +166,8 @@ void httpProcessMultiSql(HttpContext *pContext) {
|
||||||
HttpSqlCmd *cmd = multiCmds->cmds + multiCmds->pos;
|
HttpSqlCmd *cmd = multiCmds->cmds + multiCmds->pos;
|
||||||
|
|
||||||
char *sql = httpGetCmdsString(pContext, cmd->sql);
|
char *sql = httpGetCmdsString(pContext, cmd->sql);
|
||||||
httpTraceDump("context:%p, fd:%d, ip:%s, user:%s, process pos:%d, start query, sql:%s", pContext, pContext->fd,
|
httpTraceL("context:%p, fd:%d, ip:%s, user:%s, process pos:%d, start query, sql:%s", pContext, pContext->fd,
|
||||||
pContext->ipstr, pContext->user, multiCmds->pos, sql);
|
pContext->ipstr, pContext->user, multiCmds->pos, sql);
|
||||||
taosNotePrintHttp(sql);
|
taosNotePrintHttp(sql);
|
||||||
taos_query_a(pContext->session->taos, sql, httpProcessMultiSqlCallBack, (void *)pContext);
|
taos_query_a(pContext->session->taos, sql, httpProcessMultiSqlCallBack, (void *)pContext);
|
||||||
}
|
}
|
||||||
|
@ -233,10 +233,11 @@ void httpProcessSingleSqlRetrieveCallBack(void *param, TAOS_RES *result, int num
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void httpProcessSingleSqlCallBack(void *param, TAOS_RES *result, int code) {
|
void httpProcessSingleSqlCallBack(void *param, TAOS_RES *result, int unUsedCode) {
|
||||||
HttpContext *pContext = (HttpContext *)param;
|
HttpContext *pContext = (HttpContext *)param;
|
||||||
if (pContext == NULL) return;
|
if (pContext == NULL) return;
|
||||||
|
|
||||||
|
int32_t code = taos_errno(result);
|
||||||
HttpEncodeMethod *encode = pContext->encodeMethod;
|
HttpEncodeMethod *encode = pContext->encodeMethod;
|
||||||
|
|
||||||
if (code == TSDB_CODE_TSC_ACTION_IN_PROGRESS) {
|
if (code == TSDB_CODE_TSC_ACTION_IN_PROGRESS) {
|
||||||
|
@ -260,8 +261,8 @@ void httpProcessSingleSqlCallBack(void *param, TAOS_RES *result, int code) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
int num_fields = taos_field_count(result);
|
bool isUpdate = tscIsUpdateQuery(result);
|
||||||
if (num_fields == 0) {
|
if (isUpdate) {
|
||||||
// not select or show commands
|
// not select or show commands
|
||||||
int affectRows = taos_affected_rows(result);
|
int affectRows = taos_affected_rows(result);
|
||||||
|
|
||||||
|
@ -306,8 +307,8 @@ void httpProcessSingleSqlCmd(HttpContext *pContext) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
httpTraceDump("context:%p, fd:%d, ip:%s, user:%s, start query, sql:%s", pContext, pContext->fd, pContext->ipstr,
|
httpTraceL("context:%p, fd:%d, ip:%s, user:%s, start query, sql:%s", pContext, pContext->fd, pContext->ipstr,
|
||||||
pContext->user, sql);
|
pContext->user, sql);
|
||||||
taosNotePrintHttp(sql);
|
taosNotePrintHttp(sql);
|
||||||
taos_query_a(pSession->taos, sql, httpProcessSingleSqlCallBack, (void *)pContext);
|
taos_query_a(pSession->taos, sql, httpProcessSingleSqlCallBack, (void *)pContext);
|
||||||
}
|
}
|
||||||
|
|
|
@ -35,9 +35,6 @@
|
||||||
#define monitorDebug(...) { if (monitorDebugFlag & DEBUG_DEBUG) { taosPrintLog("MON DEBUG ", monitorDebugFlag, __VA_ARGS__); }}
|
#define monitorDebug(...) { if (monitorDebugFlag & DEBUG_DEBUG) { taosPrintLog("MON DEBUG ", monitorDebugFlag, __VA_ARGS__); }}
|
||||||
#define monitorTrace(...) { if (monitorDebugFlag & DEBUG_TRACE) { taosPrintLog("MON TRACE ", monitorDebugFlag, __VA_ARGS__); }}
|
#define monitorTrace(...) { if (monitorDebugFlag & DEBUG_TRACE) { taosPrintLog("MON TRACE ", monitorDebugFlag, __VA_ARGS__); }}
|
||||||
|
|
||||||
#define monitorDebugDump(...) { if (monitorDebugFlag & DEBUG_DEBUG) { taosPrintLongString("MON DEBUG ", monitorDebugFlag, __VA_ARGS__); }}
|
|
||||||
#define monitorTraceDump(...) { if (monitorDebugFlag & DEBUG_TRACE) { taosPrintLongString("MON TRACE ", monitorDebugFlag, __VA_ARGS__); }}
|
|
||||||
|
|
||||||
#define SQL_LENGTH 1024
|
#define SQL_LENGTH 1024
|
||||||
#define LOG_LEN_STR 100
|
#define LOG_LEN_STR 100
|
||||||
#define IP_LEN_STR 18
|
#define IP_LEN_STR 18
|
||||||
|
|
|
@ -27,7 +27,4 @@ extern int32_t mqttDebugFlag;
|
||||||
#define mqttDebug(...) { if (mqttDebugFlag & DEBUG_DEBUG) { taosPrintLog("MQT DEBUG ", mqttDebugFlag, __VA_ARGS__); }}
|
#define mqttDebug(...) { if (mqttDebugFlag & DEBUG_DEBUG) { taosPrintLog("MQT DEBUG ", mqttDebugFlag, __VA_ARGS__); }}
|
||||||
#define mqttTrace(...) { if (mqttDebugFlag & DEBUG_TRACE) { taosPrintLog("MQT TRACE ", mqttDebugFlag, __VA_ARGS__); }}
|
#define mqttTrace(...) { if (mqttDebugFlag & DEBUG_TRACE) { taosPrintLog("MQT TRACE ", mqttDebugFlag, __VA_ARGS__); }}
|
||||||
|
|
||||||
#define mqttDebugDump(...) { if (mqttDebugFlag & DEBUG_DEBUG) { taosPrintLongString("MQT DEBUG ", mqttDebugFlag, __VA_ARGS__); }}
|
|
||||||
#define mqttTraceDump(...) { if (mqttDebugFlag & DEBUG_TRACE) { taosPrintLongString("MQT DEBUG ", mqttDebugFlag, __VA_ARGS__); }}
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -154,6 +154,7 @@ typedef struct SQuery {
|
||||||
} SQuery;
|
} SQuery;
|
||||||
|
|
||||||
typedef struct SQueryRuntimeEnv {
|
typedef struct SQueryRuntimeEnv {
|
||||||
|
jmp_buf env;
|
||||||
SResultInfo* resultInfo; // todo refactor to merge with SWindowResInfo
|
SResultInfo* resultInfo; // todo refactor to merge with SWindowResInfo
|
||||||
SQuery* pQuery;
|
SQuery* pQuery;
|
||||||
SQLFunctionCtx* pCtx;
|
SQLFunctionCtx* pCtx;
|
||||||
|
@ -169,6 +170,9 @@ typedef struct SQueryRuntimeEnv {
|
||||||
void* pSecQueryHandle; // another thread for
|
void* pSecQueryHandle; // another thread for
|
||||||
bool stableQuery; // super table query or not
|
bool stableQuery; // super table query or not
|
||||||
bool topBotQuery; // false
|
bool topBotQuery; // false
|
||||||
|
bool groupbyNormalCol; // denote if this is a groupby normal column query
|
||||||
|
bool hasTagResults; // if there are tag values in final result or not
|
||||||
|
int32_t interBufSize; // intermediate buffer sizse
|
||||||
int32_t prevGroupId; // previous executed group id
|
int32_t prevGroupId; // previous executed group id
|
||||||
SDiskbasedResultBuf* pResultBuf; // query result buffer based on blocked-wised disk file
|
SDiskbasedResultBuf* pResultBuf; // query result buffer based on blocked-wised disk file
|
||||||
} SQueryRuntimeEnv;
|
} SQueryRuntimeEnv;
|
||||||
|
@ -197,8 +201,10 @@ typedef struct SQInfo {
|
||||||
*/
|
*/
|
||||||
int32_t tableIndex;
|
int32_t tableIndex;
|
||||||
int32_t numOfGroupResultPages;
|
int32_t numOfGroupResultPages;
|
||||||
_qinfo_free_fn_t freeFn;
|
_qinfo_free_fn_t freeFn; //todo remove it
|
||||||
jmp_buf env;
|
|
||||||
|
void* pBuf; // allocated buffer for STableQueryInfo, sizeof(STableQueryInfo)*numOfTables;
|
||||||
|
|
||||||
} SQInfo;
|
} SQInfo;
|
||||||
|
|
||||||
#endif // TDENGINE_QUERYEXECUTOR_H
|
#endif // TDENGINE_QUERYEXECUTOR_H
|
||||||
|
|
|
@ -15,6 +15,8 @@
|
||||||
#ifndef TDENGINE_QUERYUTIL_H
|
#ifndef TDENGINE_QUERYUTIL_H
|
||||||
#define TDENGINE_QUERYUTIL_H
|
#define TDENGINE_QUERYUTIL_H
|
||||||
|
|
||||||
|
int32_t getOutputInterResultBufSize(SQuery* pQuery);
|
||||||
|
|
||||||
void clearTimeWindowResBuf(SQueryRuntimeEnv* pRuntimeEnv, SWindowResult* pOneOutputRes);
|
void clearTimeWindowResBuf(SQueryRuntimeEnv* pRuntimeEnv, SWindowResult* pOneOutputRes);
|
||||||
void copyTimeWindowResBuf(SQueryRuntimeEnv* pRuntimeEnv, SWindowResult* dst, const SWindowResult* src);
|
void copyTimeWindowResBuf(SQueryRuntimeEnv* pRuntimeEnv, SWindowResult* dst, const SWindowResult* src);
|
||||||
|
|
||||||
|
@ -35,7 +37,7 @@ SWindowResult *getWindowResult(SWindowResInfo *pWindowResInfo, int32_t slot);
|
||||||
#define curTimeWindow(_winres) ((_winres)->curIndex)
|
#define curTimeWindow(_winres) ((_winres)->curIndex)
|
||||||
bool isWindowResClosed(SWindowResInfo *pWindowResInfo, int32_t slot);
|
bool isWindowResClosed(SWindowResInfo *pWindowResInfo, int32_t slot);
|
||||||
|
|
||||||
void createQueryResultInfo(SQuery *pQuery, SWindowResult *pResultRow, bool isSTableQuery, SPosInfo *posInfo);
|
void createQueryResultInfo(SQuery *pQuery, SWindowResult *pResultRow, bool isSTableQuery, SPosInfo *posInfo, size_t interBufSize);
|
||||||
|
|
||||||
char *getPosInResultPage(SQueryRuntimeEnv *pRuntimeEnv, int32_t columnIndex, SWindowResult *pResult);
|
char *getPosInResultPage(SQueryRuntimeEnv *pRuntimeEnv, int32_t columnIndex, SWindowResult *pResult);
|
||||||
|
|
||||||
|
|
|
@ -16,16 +16,16 @@
|
||||||
#ifndef TDENGINE_TAST_H
|
#ifndef TDENGINE_TAST_H
|
||||||
#define TDENGINE_TAST_H
|
#define TDENGINE_TAST_H
|
||||||
|
|
||||||
#include <tbuffer.h>
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
extern "C" {
|
extern "C" {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include <tskiplist.h>
|
|
||||||
#include "os.h"
|
#include "os.h"
|
||||||
|
|
||||||
#include "taosmsg.h"
|
#include "taosmsg.h"
|
||||||
#include "taosdef.h"
|
#include "taosdef.h"
|
||||||
|
#include "tskiplist.h"
|
||||||
|
#include "tbuffer.h"
|
||||||
#include "tvariant.h"
|
#include "tvariant.h"
|
||||||
|
|
||||||
struct tExprNode;
|
struct tExprNode;
|
||||||
|
@ -75,10 +75,6 @@ typedef struct tExprNode {
|
||||||
};
|
};
|
||||||
} tExprNode;
|
} tExprNode;
|
||||||
|
|
||||||
void tSQLBinaryExprFromString(tExprNode **pExpr, SSchema *pSchema, int32_t numOfCols, char *src, int32_t len);
|
|
||||||
|
|
||||||
void tSQLBinaryExprToString(tExprNode *pExpr, char *dst, int32_t *len);
|
|
||||||
|
|
||||||
void tExprTreeDestroy(tExprNode **pExprs, void (*fp)(void*));
|
void tExprTreeDestroy(tExprNode **pExprs, void (*fp)(void*));
|
||||||
|
|
||||||
void tExprTreeTraverse(tExprNode *pExpr, SSkipList *pSkipList, SArray *result, SExprTraverseSupp *param);
|
void tExprTreeTraverse(tExprNode *pExpr, SSkipList *pSkipList, SArray *result, SExprTraverseSupp *param);
|
||||||
|
@ -86,12 +82,9 @@ void tExprTreeTraverse(tExprNode *pExpr, SSkipList *pSkipList, SArray *result, S
|
||||||
void tExprTreeCalcTraverse(tExprNode *pExprs, int32_t numOfRows, char *pOutput, void *param, int32_t order,
|
void tExprTreeCalcTraverse(tExprNode *pExprs, int32_t numOfRows, char *pOutput, void *param, int32_t order,
|
||||||
char *(*cb)(void *, const char*, int32_t));
|
char *(*cb)(void *, const char*, int32_t));
|
||||||
|
|
||||||
// todo refactor: remove it
|
|
||||||
void tSQLBinaryExprTrv(tExprNode *pExprs, SArray* res);
|
|
||||||
|
|
||||||
uint8_t getBinaryExprOptr(SSQLToken *pToken);
|
uint8_t getBinaryExprOptr(SSQLToken *pToken);
|
||||||
|
|
||||||
void tExprNodeDestroy(tExprNode *pNode, void (*fp)(void *));
|
void tExprNodeDestroy(tExprNode *pNode, void (*fp)(void *));
|
||||||
void exprTreeToBinary(SBufferWriter* bw, tExprNode* pExprTree);
|
void exprTreeToBinary(SBufferWriter* bw, tExprNode* pExprTree);
|
||||||
|
|
||||||
tExprNode* exprTreeFromBinary(const void* data, size_t size);
|
tExprNode* exprTreeFromBinary(const void* data, size_t size);
|
||||||
|
|
|
@ -60,8 +60,6 @@ typedef struct SPoint {
|
||||||
void * val;
|
void * val;
|
||||||
} SPoint;
|
} SPoint;
|
||||||
|
|
||||||
int64_t taosGetIntervalStartTimestamp(int64_t startTime, int64_t slidingTime, char timeUnit, int16_t precision);
|
|
||||||
|
|
||||||
SFillInfo* taosInitFillInfo(int32_t order, TSKEY skey, int32_t numOfTags, int32_t capacity, int32_t numOfCols,
|
SFillInfo* taosInitFillInfo(int32_t order, TSKEY skey, int32_t numOfTags, int32_t capacity, int32_t numOfCols,
|
||||||
int64_t slidingTime, int8_t slidingUnit, int8_t precision, int32_t fillType,
|
int64_t slidingTime, int8_t slidingUnit, int8_t precision, int32_t fillType,
|
||||||
SFillColInfo* pFillCol);
|
SFillColInfo* pFillCol);
|
||||||
|
|
|
@ -272,7 +272,7 @@ bool top_bot_datablock_filter(SQLFunctionCtx *pCtx, int32_t functionId, char *mi
|
||||||
bool stableQueryFunctChanged(int32_t funcId);
|
bool stableQueryFunctChanged(int32_t funcId);
|
||||||
|
|
||||||
void resetResultInfo(SResultInfo *pResInfo);
|
void resetResultInfo(SResultInfo *pResInfo);
|
||||||
void setResultInfoBuf(SResultInfo *pResInfo, int32_t size, bool superTable);
|
void setResultInfoBuf(SResultInfo *pResInfo, int32_t size, bool superTable, char* buf);
|
||||||
|
|
||||||
static FORCE_INLINE void initResultInfo(SResultInfo *pResInfo) {
|
static FORCE_INLINE void initResultInfo(SResultInfo *pResInfo) {
|
||||||
pResInfo->initialized = true; // the this struct has been initialized flag
|
pResInfo->initialized = true; // the this struct has been initialized flag
|
||||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -17,22 +17,30 @@
|
||||||
|
|
||||||
#include "hash.h"
|
#include "hash.h"
|
||||||
#include "taosmsg.h"
|
#include "taosmsg.h"
|
||||||
#include "qextbuffer.h"
|
|
||||||
#include "ttime.h"
|
|
||||||
|
|
||||||
#include "qfill.h"
|
|
||||||
#include "ttime.h"
|
#include "ttime.h"
|
||||||
|
|
||||||
#include "qExecutor.h"
|
#include "qExecutor.h"
|
||||||
#include "qUtil.h"
|
#include "qUtil.h"
|
||||||
|
|
||||||
|
int32_t getOutputInterResultBufSize(SQuery* pQuery) {
|
||||||
|
int32_t size = 0;
|
||||||
|
|
||||||
|
for (int32_t i = 0; i < pQuery->numOfOutput; ++i) {
|
||||||
|
assert(pQuery->pSelectExpr[i].interBytes <= DEFAULT_INTERN_BUF_PAGE_SIZE);
|
||||||
|
size += pQuery->pSelectExpr[i].interBytes;
|
||||||
|
}
|
||||||
|
|
||||||
|
assert(size > 0);
|
||||||
|
|
||||||
|
return size;
|
||||||
|
}
|
||||||
|
|
||||||
int32_t initWindowResInfo(SWindowResInfo *pWindowResInfo, SQueryRuntimeEnv *pRuntimeEnv, int32_t size,
|
int32_t initWindowResInfo(SWindowResInfo *pWindowResInfo, SQueryRuntimeEnv *pRuntimeEnv, int32_t size,
|
||||||
int32_t threshold, int16_t type) {
|
int32_t threshold, int16_t type) {
|
||||||
pWindowResInfo->capacity = size;
|
pWindowResInfo->capacity = size;
|
||||||
pWindowResInfo->threshold = threshold;
|
pWindowResInfo->threshold = threshold;
|
||||||
|
|
||||||
pWindowResInfo->type = type;
|
pWindowResInfo->type = type;
|
||||||
|
|
||||||
_hash_fn_t fn = taosGetDefaultHashFunction(type);
|
_hash_fn_t fn = taosGetDefaultHashFunction(type);
|
||||||
pWindowResInfo->hashList = taosHashInit(threshold, fn, false);
|
pWindowResInfo->hashList = taosHashInit(threshold, fn, false);
|
||||||
|
|
||||||
|
@ -44,7 +52,7 @@ int32_t initWindowResInfo(SWindowResInfo *pWindowResInfo, SQueryRuntimeEnv *pRun
|
||||||
pWindowResInfo->pResult = calloc(threshold, sizeof(SWindowResult));
|
pWindowResInfo->pResult = calloc(threshold, sizeof(SWindowResult));
|
||||||
for (int32_t i = 0; i < pWindowResInfo->capacity; ++i) {
|
for (int32_t i = 0; i < pWindowResInfo->capacity; ++i) {
|
||||||
SPosInfo posInfo = {-1, -1};
|
SPosInfo posInfo = {-1, -1};
|
||||||
createQueryResultInfo(pRuntimeEnv->pQuery, &pWindowResInfo->pResult[i], pRuntimeEnv->stableQuery, &posInfo);
|
createQueryResultInfo(pRuntimeEnv->pQuery, &pWindowResInfo->pResult[i], pRuntimeEnv->stableQuery, &posInfo, pRuntimeEnv->interBufSize);
|
||||||
}
|
}
|
||||||
|
|
||||||
return TSDB_CODE_SUCCESS;
|
return TSDB_CODE_SUCCESS;
|
||||||
|
@ -55,10 +63,7 @@ void destroyTimeWindowRes(SWindowResult *pWindowRes, int32_t nOutputCols) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (int32_t i = 0; i < nOutputCols; ++i) {
|
free(pWindowRes->resultInfo[0].interResultBuf);
|
||||||
free(pWindowRes->resultInfo[i].interResultBuf);
|
|
||||||
}
|
|
||||||
|
|
||||||
free(pWindowRes->resultInfo);
|
free(pWindowRes->resultInfo);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -180,19 +185,33 @@ void closeAllTimeWindow(SWindowResInfo *pWindowResInfo) {
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* remove the results that are not the FIRST time window that spreads beyond the
|
* remove the results that are not the FIRST time window that spreads beyond the
|
||||||
* the last qualified time stamp in case of sliding query, which the sliding time is not equalled to the interval time
|
* the last qualified time stamp in case of sliding query, which the sliding time is not equalled to the interval time.
|
||||||
|
* NOTE: remove redundant, only when the result set order equals to traverse order
|
||||||
*/
|
*/
|
||||||
void removeRedundantWindow(SWindowResInfo *pWindowResInfo, TSKEY lastKey, int32_t order) {
|
void removeRedundantWindow(SWindowResInfo *pWindowResInfo, TSKEY lastKey, int32_t order) {
|
||||||
assert(pWindowResInfo->size >= 0 && pWindowResInfo->capacity >= pWindowResInfo->size);
|
assert(pWindowResInfo->size >= 0 && pWindowResInfo->capacity >= pWindowResInfo->size);
|
||||||
|
if (pWindowResInfo->size <= 1) {
|
||||||
int32_t i = 0;
|
return;
|
||||||
while (i < pWindowResInfo->size &&
|
}
|
||||||
((pWindowResInfo->pResult[i].window.ekey < lastKey && order == QUERY_ASC_FORWARD_STEP) ||
|
|
||||||
(pWindowResInfo->pResult[i].window.skey > lastKey && order == QUERY_DESC_FORWARD_STEP))) {
|
// get the result order
|
||||||
++i;
|
int32_t resultOrder = (pWindowResInfo->pResult[0].window.skey < pWindowResInfo->pResult[1].window.skey)? 1:-1;
|
||||||
|
|
||||||
|
if (order != resultOrder) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
int32_t i = 0;
|
||||||
|
if (order == QUERY_ASC_FORWARD_STEP) {
|
||||||
|
while (i < pWindowResInfo->size && (pWindowResInfo->pResult[i].window.ekey < lastKey)) {
|
||||||
|
++i;
|
||||||
|
}
|
||||||
|
} else if (order == QUERY_DESC_FORWARD_STEP) {
|
||||||
|
while (i < pWindowResInfo->size && (pWindowResInfo->pResult[i].window.skey > lastKey)) {
|
||||||
|
++i;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// assert(i < pWindowResInfo->size);
|
|
||||||
if (i < pWindowResInfo->size) {
|
if (i < pWindowResInfo->size) {
|
||||||
pWindowResInfo->size = (i + 1);
|
pWindowResInfo->size = (i + 1);
|
||||||
}
|
}
|
||||||
|
@ -227,10 +246,9 @@ void clearTimeWindowResBuf(SQueryRuntimeEnv *pRuntimeEnv, SWindowResult *pWindow
|
||||||
}
|
}
|
||||||
|
|
||||||
pWindowRes->numOfRows = 0;
|
pWindowRes->numOfRows = 0;
|
||||||
// pWindowRes->nAlloc = 0;
|
|
||||||
pWindowRes->pos = (SPosInfo){-1, -1};
|
pWindowRes->pos = (SPosInfo){-1, -1};
|
||||||
pWindowRes->status.closed = false;
|
pWindowRes->status.closed = false;
|
||||||
pWindowRes->window = (STimeWindow){0, 0};
|
pWindowRes->window = TSWINDOW_INITIALIZER;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -240,7 +258,6 @@ void clearTimeWindowResBuf(SQueryRuntimeEnv *pRuntimeEnv, SWindowResult *pWindow
|
||||||
*/
|
*/
|
||||||
void copyTimeWindowResBuf(SQueryRuntimeEnv *pRuntimeEnv, SWindowResult *dst, const SWindowResult *src) {
|
void copyTimeWindowResBuf(SQueryRuntimeEnv *pRuntimeEnv, SWindowResult *dst, const SWindowResult *src) {
|
||||||
dst->numOfRows = src->numOfRows;
|
dst->numOfRows = src->numOfRows;
|
||||||
// dst->nAlloc = src->nAlloc;
|
|
||||||
dst->window = src->window;
|
dst->window = src->window;
|
||||||
dst->status = src->status;
|
dst->status = src->status;
|
||||||
|
|
||||||
|
|
|
@ -13,25 +13,26 @@
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
#include "os.h"
|
#include "os.h"
|
||||||
#include "tulog.h"
|
|
||||||
#include "tutil.h"
|
#include "tname.h"
|
||||||
#include "tbuffer.h"
|
|
||||||
#include "qast.h"
|
#include "qast.h"
|
||||||
#include "tcompare.h"
|
#include "tsdb.h"
|
||||||
|
#include "exception.h"
|
||||||
#include "qsqlparser.h"
|
#include "qsqlparser.h"
|
||||||
#include "qsyntaxtreefunction.h"
|
#include "qsyntaxtreefunction.h"
|
||||||
#include "taosdef.h"
|
#include "taosdef.h"
|
||||||
#include "taosmsg.h"
|
#include "taosmsg.h"
|
||||||
|
#include "tarray.h"
|
||||||
|
#include "tbuffer.h"
|
||||||
|
#include "tcompare.h"
|
||||||
|
#include "tskiplist.h"
|
||||||
#include "tsqlfunction.h"
|
#include "tsqlfunction.h"
|
||||||
#include "tstoken.h"
|
#include "tstoken.h"
|
||||||
#include "ttokendef.h"
|
#include "ttokendef.h"
|
||||||
#include "tschemautil.h"
|
#include "tulog.h"
|
||||||
#include "tarray.h"
|
#include "tutil.h"
|
||||||
#include "tskiplist.h"
|
|
||||||
#include "queryLog.h"
|
|
||||||
#include "tsdbMain.h"
|
|
||||||
#include "exception.h"
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
*
|
*
|
||||||
|
@ -327,104 +328,6 @@ static tExprNode *createSyntaxTree(SSchema *pSchema, int32_t numOfCols, char *st
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void tSQLBinaryExprFromString(tExprNode **pExpr, SSchema *pSchema, int32_t numOfCols, char *src, int32_t len) {
|
|
||||||
*pExpr = NULL;
|
|
||||||
|
|
||||||
if (len <= 0 || src == NULL || pSchema == NULL || numOfCols <= 0) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
int32_t pos = 0;
|
|
||||||
|
|
||||||
*pExpr = createSyntaxTree(pSchema, numOfCols, src, &pos);
|
|
||||||
if (*pExpr != NULL) {
|
|
||||||
assert((*pExpr)->nodeType == TSQL_NODE_EXPR);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
int32_t tSQLBinaryExprToStringImpl(tExprNode *pNode, char *dst, uint8_t type) {
|
|
||||||
int32_t len = 0;
|
|
||||||
if (type == TSQL_NODE_EXPR) {
|
|
||||||
*dst = '(';
|
|
||||||
tSQLBinaryExprToString(pNode, dst + 1, &len);
|
|
||||||
len += 2;
|
|
||||||
*(dst + len - 1) = ')';
|
|
||||||
} else if (type == TSQL_NODE_COL) {
|
|
||||||
len = sprintf(dst, "%s", pNode->pSchema->name);
|
|
||||||
} else {
|
|
||||||
len = tVariantToString(pNode->pVal, dst);
|
|
||||||
}
|
|
||||||
return len;
|
|
||||||
}
|
|
||||||
|
|
||||||
// TODO REFACTOR WITH SQL PARSER
|
|
||||||
static char *tSQLOptrToString(uint8_t optr, char *dst) {
|
|
||||||
switch (optr) {
|
|
||||||
case TSDB_RELATION_LESS: {
|
|
||||||
*dst = '<';
|
|
||||||
dst += 1;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case TSDB_RELATION_LESS_EQUAL: {
|
|
||||||
*dst = '<';
|
|
||||||
*(dst + 1) = '=';
|
|
||||||
dst += 2;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case TSDB_RELATION_EQUAL: {
|
|
||||||
*dst = '=';
|
|
||||||
dst += 1;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case TSDB_RELATION_GREATER: {
|
|
||||||
*dst = '>';
|
|
||||||
dst += 1;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case TSDB_RELATION_GREATER_EQUAL: {
|
|
||||||
*dst = '>';
|
|
||||||
*(dst + 1) = '=';
|
|
||||||
dst += 2;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case TSDB_RELATION_NOT_EQUAL: {
|
|
||||||
*dst = '<';
|
|
||||||
*(dst + 1) = '>';
|
|
||||||
dst += 2;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case TSDB_RELATION_OR: {
|
|
||||||
memcpy(dst, "or", 2);
|
|
||||||
dst += 2;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case TSDB_RELATION_AND: {
|
|
||||||
memcpy(dst, "and", 3);
|
|
||||||
dst += 3;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
default:;
|
|
||||||
}
|
|
||||||
return dst;
|
|
||||||
}
|
|
||||||
|
|
||||||
void tSQLBinaryExprToString(tExprNode *pExpr, char *dst, int32_t *len) {
|
|
||||||
if (pExpr == NULL) {
|
|
||||||
*dst = 0;
|
|
||||||
*len = 0;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
int32_t lhs = tSQLBinaryExprToStringImpl(pExpr->_node.pLeft, dst, pExpr->_node.pLeft->nodeType);
|
|
||||||
dst += lhs;
|
|
||||||
*len = lhs;
|
|
||||||
|
|
||||||
char *start = tSQLOptrToString(pExpr->_node.optr, dst);
|
|
||||||
*len += (start - dst);
|
|
||||||
|
|
||||||
*len += tSQLBinaryExprToStringImpl(pExpr->_node.pRight, start, pExpr->_node.pRight->nodeType);
|
|
||||||
}
|
|
||||||
|
|
||||||
static void UNUSED_FUNC destroySyntaxTree(tExprNode *pNode) { tExprNodeDestroy(pNode, NULL); }
|
static void UNUSED_FUNC destroySyntaxTree(tExprNode *pNode) { tExprNodeDestroy(pNode, NULL); }
|
||||||
|
|
||||||
void tExprNodeDestroy(tExprNode *pNode, void (*fp)(void *)) {
|
void tExprNodeDestroy(tExprNode *pNode, void (*fp)(void *)) {
|
||||||
|
@ -773,8 +676,7 @@ static void tQueryIndexlessColumn(SSkipList* pSkipList, tQueryInfo* pQueryInfo,
|
||||||
SSkipListNode *pNode = tSkipListIterGet(iter);
|
SSkipListNode *pNode = tSkipListIterGet(iter);
|
||||||
char * pData = SL_GET_NODE_DATA(pNode);
|
char * pData = SL_GET_NODE_DATA(pNode);
|
||||||
|
|
||||||
// todo refactor:
|
tstr *name = (tstr*) tsdbGetTableName(*(void**) pData);
|
||||||
tstr *name = (*(STable **)pData)->name;
|
|
||||||
// todo speed up by using hash
|
// todo speed up by using hash
|
||||||
if (pQueryInfo->colIndex == TSDB_TBNAME_COLUMN_INDEX) {
|
if (pQueryInfo->colIndex == TSDB_TBNAME_COLUMN_INDEX) {
|
||||||
if (pQueryInfo->optr == TSDB_RELATION_IN) {
|
if (pQueryInfo->optr == TSDB_RELATION_IN) {
|
||||||
|
@ -976,27 +878,27 @@ void tExprTreeCalcTraverse(tExprNode *pExprs, int32_t numOfRows, char *pOutput,
|
||||||
free(pRightOutput);
|
free(pRightOutput);
|
||||||
}
|
}
|
||||||
|
|
||||||
void tSQLBinaryExprTrv(tExprNode *pExprs, SArray* res) {
|
//void tSQLBinaryExprTrv(tExprNode *pExprs, SArray* res) {
|
||||||
if (pExprs == NULL) {
|
// if (pExprs == NULL) {
|
||||||
return;
|
// return;
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
tExprNode *pLeft = pExprs->_node.pLeft;
|
// tExprNode *pLeft = pExprs->_node.pLeft;
|
||||||
tExprNode *pRight = pExprs->_node.pRight;
|
// tExprNode *pRight = pExprs->_node.pRight;
|
||||||
|
//
|
||||||
// recursive traverse left child branch
|
// // recursive traverse left child branch
|
||||||
if (pLeft->nodeType == TSQL_NODE_EXPR) {
|
// if (pLeft->nodeType == TSQL_NODE_EXPR) {
|
||||||
tSQLBinaryExprTrv(pLeft, res);
|
// tSQLBinaryExprTrv(pLeft, res);
|
||||||
} else if (pLeft->nodeType == TSQL_NODE_COL) {
|
// } else if (pLeft->nodeType == TSQL_NODE_COL) {
|
||||||
taosArrayPush(res, &pLeft->pSchema->colId);
|
// taosArrayPush(res, &pLeft->pSchema->colId);
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
if (pRight->nodeType == TSQL_NODE_EXPR) {
|
// if (pRight->nodeType == TSQL_NODE_EXPR) {
|
||||||
tSQLBinaryExprTrv(pRight, res);
|
// tSQLBinaryExprTrv(pRight, res);
|
||||||
} else if (pRight->nodeType == TSQL_NODE_COL) {
|
// } else if (pRight->nodeType == TSQL_NODE_COL) {
|
||||||
taosArrayPush(res, &pRight->pSchema->colId);
|
// taosArrayPush(res, &pRight->pSchema->colId);
|
||||||
}
|
// }
|
||||||
}
|
//}
|
||||||
|
|
||||||
static void exprTreeToBinaryImpl(SBufferWriter* bw, tExprNode* expr) {
|
static void exprTreeToBinaryImpl(SBufferWriter* bw, tExprNode* expr) {
|
||||||
tbufWriteUint8(bw, expr->nodeType);
|
tbufWriteUint8(bw, expr->nodeType);
|
||||||
|
|
|
@ -118,7 +118,7 @@ static bool tExtMemBufferAlloc(tExtMemBuffer *pMemBuffer) {
|
||||||
* To flush data to disk to accommodate more data
|
* To flush data to disk to accommodate more data
|
||||||
*/
|
*/
|
||||||
if (pMemBuffer->numOfInMemPages > 0 && pMemBuffer->numOfInMemPages == pMemBuffer->inMemCapacity) {
|
if (pMemBuffer->numOfInMemPages > 0 && pMemBuffer->numOfInMemPages == pMemBuffer->inMemCapacity) {
|
||||||
if (!tExtMemBufferFlush(pMemBuffer)) {
|
if (tExtMemBufferFlush(pMemBuffer) != 0) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -268,6 +268,7 @@ int32_t tExtMemBufferFlush(tExtMemBuffer *pMemBuffer) {
|
||||||
size_t retVal = fwrite((char *)&(first->item), pMemBuffer->pageSize, 1, pMemBuffer->file);
|
size_t retVal = fwrite((char *)&(first->item), pMemBuffer->pageSize, 1, pMemBuffer->file);
|
||||||
if (retVal <= 0) { // failed to write to buffer, may be not enough space
|
if (retVal <= 0) { // failed to write to buffer, may be not enough space
|
||||||
ret = TAOS_SYSTEM_ERROR(errno);
|
ret = TAOS_SYSTEM_ERROR(errno);
|
||||||
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
pMemBuffer->fileMeta.numOfElemsInFile += first->item.num;
|
pMemBuffer->fileMeta.numOfElemsInFile += first->item.num;
|
||||||
|
|
|
@ -22,41 +22,6 @@
|
||||||
|
|
||||||
#define FILL_IS_ASC_FILL(_f) ((_f)->order == TSDB_ORDER_ASC)
|
#define FILL_IS_ASC_FILL(_f) ((_f)->order == TSDB_ORDER_ASC)
|
||||||
|
|
||||||
int64_t taosGetIntervalStartTimestamp(int64_t startTime, int64_t slidingTime, char timeUnit, int16_t precision) {
|
|
||||||
if (slidingTime == 0) {
|
|
||||||
return startTime;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (timeUnit == 'a' || timeUnit == 'm' || timeUnit == 's' || timeUnit == 'h') {
|
|
||||||
return (startTime / slidingTime) * slidingTime;
|
|
||||||
} else {
|
|
||||||
/*
|
|
||||||
* here we revised the start time of day according to the local time zone,
|
|
||||||
* but in case of DST, the start time of one day need to be dynamically decided.
|
|
||||||
*
|
|
||||||
* TODO dynamically decide the start time of a day, move to common module
|
|
||||||
*/
|
|
||||||
|
|
||||||
// todo refactor to extract function that is available for Linux/Windows/Mac platform
|
|
||||||
#if defined(WINDOWS) && _MSC_VER >= 1900
|
|
||||||
// see https://docs.microsoft.com/en-us/cpp/c-runtime-library/daylight-dstbias-timezone-and-tzname?view=vs-2019
|
|
||||||
int64_t timezone = _timezone;
|
|
||||||
int32_t daylight = _daylight;
|
|
||||||
char** tzname = _tzname;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
int64_t t = (precision == TSDB_TIME_PRECISION_MILLI) ? MILLISECOND_PER_SECOND : MILLISECOND_PER_SECOND * 1000L;
|
|
||||||
|
|
||||||
int64_t revStartime = (startTime / slidingTime) * slidingTime + timezone * t;
|
|
||||||
int64_t revEndtime = revStartime + slidingTime - 1;
|
|
||||||
if (revEndtime < startTime) {
|
|
||||||
revStartime += slidingTime;
|
|
||||||
}
|
|
||||||
|
|
||||||
return revStartime;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
SFillInfo* taosInitFillInfo(int32_t order, TSKEY skey, int32_t numOfTags, int32_t capacity, int32_t numOfCols,
|
SFillInfo* taosInitFillInfo(int32_t order, TSKEY skey, int32_t numOfTags, int32_t capacity, int32_t numOfCols,
|
||||||
int64_t slidingTime, int8_t slidingUnit, int8_t precision, int32_t fillType, SFillColInfo* pFillCol) {
|
int64_t slidingTime, int8_t slidingUnit, int8_t precision, int32_t fillType, SFillColInfo* pFillCol) {
|
||||||
if (fillType == TSDB_FILL_NONE) {
|
if (fillType == TSDB_FILL_NONE) {
|
||||||
|
@ -128,7 +93,7 @@ static TSKEY taosGetRevisedEndKey(TSKEY ekey, int32_t order, int64_t timeInterva
|
||||||
if (order == TSDB_ORDER_ASC) {
|
if (order == TSDB_ORDER_ASC) {
|
||||||
return ekey;
|
return ekey;
|
||||||
} else {
|
} else {
|
||||||
return taosGetIntervalStartTimestamp(ekey, timeInterval, slidingTimeUnit, precision);
|
return taosGetIntervalStartTimestamp(ekey, timeInterval, timeInterval, slidingTimeUnit, precision);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -209,7 +174,7 @@ int32_t taosNumOfRemainRows(SFillInfo* pFillInfo) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
return FILL_IS_ASC_FILL(pFillInfo) ? (pFillInfo->numOfRows - pFillInfo->rowIdx) : pFillInfo->rowIdx + 1;
|
return pFillInfo->numOfRows - pFillInfo->rowIdx;
|
||||||
}
|
}
|
||||||
|
|
||||||
// todo: refactor
|
// todo: refactor
|
||||||
|
|
|
@ -1,11 +1,10 @@
|
||||||
#include <gtest/gtest.h>
|
#include <gtest/gtest.h>
|
||||||
#include <qast.h>
|
|
||||||
#include <sys/time.h>
|
#include <sys/time.h>
|
||||||
#include <cassert>
|
#include <cassert>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
|
||||||
#include "qast.h"
|
|
||||||
#include "taosmsg.h"
|
#include "taosmsg.h"
|
||||||
|
#include "qast.h"
|
||||||
#include "tsdb.h"
|
#include "tsdb.h"
|
||||||
#include "tskiplist.h"
|
#include "tskiplist.h"
|
||||||
|
|
||||||
|
@ -24,8 +23,6 @@ static void initSchema_binary(SSchema *schema, int32_t numOfCols);
|
||||||
static SSkipList *createSkipList(SSchema *pSchema, int32_t numOfTags);
|
static SSkipList *createSkipList(SSchema *pSchema, int32_t numOfTags);
|
||||||
static SSkipList *createSkipList_binary(SSchema *pSchema, int32_t numOfTags);
|
static SSkipList *createSkipList_binary(SSchema *pSchema, int32_t numOfTags);
|
||||||
|
|
||||||
static void testQueryStr(SSchema *schema, int32_t numOfCols, char *sql, SSkipList *pSkipList, ResultObj *expectedVal);
|
|
||||||
|
|
||||||
static void dropMeter(SSkipList *pSkipList);
|
static void dropMeter(SSkipList *pSkipList);
|
||||||
|
|
||||||
static void Right2LeftTest(SSchema *schema, int32_t numOfCols, SSkipList *pSkipList);
|
static void Right2LeftTest(SSchema *schema, int32_t numOfCols, SSkipList *pSkipList);
|
||||||
|
@ -239,44 +236,45 @@ static void initSchema(SSchema *schema, int32_t numOfCols) {
|
||||||
// return pSkipList;
|
// return pSkipList;
|
||||||
//}
|
//}
|
||||||
|
|
||||||
static void testQueryStr(SSchema *schema, int32_t numOfCols, char *sql, SSkipList *pSkipList, ResultObj *pResult) {
|
//static void testQueryStr(SSchema *schema, int32_t numOfCols, char *sql, SSkipList *pSkipList, ResultObj *pResult) {
|
||||||
tExprNode *pExpr = NULL;
|
// tExprNode *pExpr = NULL;
|
||||||
tSQLBinaryExprFromString(&pExpr, schema, numOfCols, sql, strlen(sql));
|
// tSQLBinaryExprFromString(&pExpr, schema, numOfCols, sql, strlen(sql));
|
||||||
|
//
|
||||||
char str[512] = {0};
|
// char str[512] = {0};
|
||||||
int32_t len = 0;
|
// int32_t len = 0;
|
||||||
if (pExpr == NULL) {
|
// if (pExpr == NULL) {
|
||||||
printf("-----error in parse syntax:%s\n\n", sql);
|
// printf("-----error in parse syntax:%s\n\n", sql);
|
||||||
assert(pResult == NULL);
|
// assert(pResult == NULL);
|
||||||
return;
|
// return;
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
tSQLBinaryExprToString(pExpr, str, &len);
|
// tSQLBinaryExprToString(pExpr, str, &len);
|
||||||
printf("expr is: %s\n", str);
|
// printf("expr is: %s\n", str);
|
||||||
|
//
|
||||||
SArray *result = NULL;
|
// SArray *result = NULL;
|
||||||
// tExprTreeTraverse(pExpr, pSkipList, result, SSkipListNodeFilterCallback, &result);
|
// // tExprTreeTraverse(pExpr, pSkipList, result, SSkipListNodeFilterCallback, &result);
|
||||||
// printf("the result is:%lld\n", result.num);
|
// // printf("the result is:%lld\n", result.num);
|
||||||
//
|
// //
|
||||||
// bool findResult = false;
|
// // bool findResult = false;
|
||||||
// for (int32_t i = 0; i < result.num; ++i) {
|
// // for (int32_t i = 0; i < result.num; ++i) {
|
||||||
// STabObj *pm = (STabObj *)result.pRes[i];
|
// // STabObj *pm = (STabObj *)result.pRes[i];
|
||||||
// printf("meterid:%s,\t", pm->meterId);
|
// // printf("meterid:%s,\t", pm->meterId);
|
||||||
//
|
// //
|
||||||
// for (int32_t j = 0; j < pResult->numOfResult; ++j) {
|
// // for (int32_t j = 0; j < pResult->numOfResult; ++j) {
|
||||||
// if (strcmp(pm->meterId, pResult->resultName[j]) == 0) {
|
// // if (strcmp(pm->meterId, pResult->resultName[j]) == 0) {
|
||||||
// findResult = true;
|
// // findResult = true;
|
||||||
// break;
|
// // break;
|
||||||
// }
|
// // }
|
||||||
// }
|
// // }
|
||||||
// assert(findResult == true);
|
// // assert(findResult == true);
|
||||||
// findResult = false;
|
// // findResult = false;
|
||||||
// }
|
// // }
|
||||||
|
//
|
||||||
printf("\n\n");
|
// printf("\n\n");
|
||||||
tExprTreeDestroy(&pExpr, NULL);
|
// tExprTreeDestroy(&pExpr, NULL);
|
||||||
}
|
//}
|
||||||
|
|
||||||
|
#if 0
|
||||||
static void Left2RightTest(SSchema *schema, int32_t numOfCols, SSkipList *pSkipList) {
|
static void Left2RightTest(SSchema *schema, int32_t numOfCols, SSkipList *pSkipList) {
|
||||||
char str[256] = {0};
|
char str[256] = {0};
|
||||||
|
|
||||||
|
@ -633,3 +631,4 @@ void exprSerializeTest2() {
|
||||||
TEST(testCase, astTest) {
|
TEST(testCase, astTest) {
|
||||||
// exprSerializeTest2();
|
// exprSerializeTest2();
|
||||||
}
|
}
|
||||||
|
#endif
|
|
@ -31,9 +31,7 @@ extern int32_t tscEmbedded;
|
||||||
#define tInfo(...) { if (rpcDebugFlag & DEBUG_INFO) { taosPrintLog("RPC INFO ", tscEmbedded ? 255 : rpcDebugFlag, __VA_ARGS__); }}
|
#define tInfo(...) { if (rpcDebugFlag & DEBUG_INFO) { taosPrintLog("RPC INFO ", tscEmbedded ? 255 : rpcDebugFlag, __VA_ARGS__); }}
|
||||||
#define tDebug(...) { if (rpcDebugFlag & DEBUG_DEBUG) { taosPrintLog("RPC DEBUG ", rpcDebugFlag, __VA_ARGS__); }}
|
#define tDebug(...) { if (rpcDebugFlag & DEBUG_DEBUG) { taosPrintLog("RPC DEBUG ", rpcDebugFlag, __VA_ARGS__); }}
|
||||||
#define tTrace(...) { if (rpcDebugFlag & DEBUG_TRACE) { taosPrintLog("RPC TRACE ", rpcDebugFlag, __VA_ARGS__); }}
|
#define tTrace(...) { if (rpcDebugFlag & DEBUG_TRACE) { taosPrintLog("RPC TRACE ", rpcDebugFlag, __VA_ARGS__); }}
|
||||||
|
#define tDump(x, y) { if (rpcDebugFlag & DEBUG_DUMP) { taosDumpData((unsigned char *)x, y); }}
|
||||||
#define tDebugDump(x, y) { if (rpcDebugFlag & DEBUG_DEBUG) { taosDumpData((unsigned char *)x, y); }}
|
|
||||||
#define tTraceDump(x, y) { if (rpcDebugFlag & DEBUG_TRACE) { taosDumpData((unsigned char *)x, y); }}
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
|
|
|
@ -538,6 +538,7 @@ void rpcCancelRequest(void *handle) {
|
||||||
|
|
||||||
if (pContext->pConn) {
|
if (pContext->pConn) {
|
||||||
tDebug("%s, app trys to cancel request", pContext->pConn->info);
|
tDebug("%s, app trys to cancel request", pContext->pConn->info);
|
||||||
|
pContext->pConn->pReqMsg = NULL;
|
||||||
rpcCloseConn(pContext->pConn);
|
rpcCloseConn(pContext->pConn);
|
||||||
pContext->pConn = NULL;
|
pContext->pConn = NULL;
|
||||||
rpcFreeCont(pContext->pCont);
|
rpcFreeCont(pContext->pCont);
|
||||||
|
@ -602,7 +603,12 @@ static void rpcReleaseConn(SRpcConn *pConn) {
|
||||||
rpcFreeMsg(pConn->pRspMsg); // it may have a response msg saved, but not request msg
|
rpcFreeMsg(pConn->pRspMsg); // it may have a response msg saved, but not request msg
|
||||||
pConn->pRspMsg = NULL;
|
pConn->pRspMsg = NULL;
|
||||||
|
|
||||||
if (pConn->pReqMsg) rpcFreeCont(pConn->pReqMsg);
|
// if server has ever reported progress, free content
|
||||||
|
if (pConn->pReqMsg) rpcFreeCont(pConn->pReqMsg); // do not use rpcFreeMsg
|
||||||
|
} else {
|
||||||
|
// if there is an outgoing message, free it
|
||||||
|
if (pConn->outType && pConn->pReqMsg)
|
||||||
|
rpcFreeMsg(pConn->pReqMsg);
|
||||||
}
|
}
|
||||||
|
|
||||||
// memset could not be used, since lockeBy can not be reset
|
// memset could not be used, since lockeBy can not be reset
|
||||||
|
@ -959,6 +965,7 @@ static void rpcProcessBrokenLink(SRpcConn *pConn) {
|
||||||
if (pConn->outType) {
|
if (pConn->outType) {
|
||||||
SRpcReqContext *pContext = pConn->pContext;
|
SRpcReqContext *pContext = pConn->pContext;
|
||||||
pContext->code = TSDB_CODE_RPC_NETWORK_UNAVAIL;
|
pContext->code = TSDB_CODE_RPC_NETWORK_UNAVAIL;
|
||||||
|
pConn->pReqMsg = NULL;
|
||||||
taosTmrStart(rpcProcessConnError, 0, pContext, pRpc->tmrCtrl);
|
taosTmrStart(rpcProcessConnError, 0, pContext, pRpc->tmrCtrl);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -973,7 +980,7 @@ static void *rpcProcessMsgFromPeer(SRecvInfo *pRecv) {
|
||||||
SRpcInfo *pRpc = (SRpcInfo *)pRecv->shandle;
|
SRpcInfo *pRpc = (SRpcInfo *)pRecv->shandle;
|
||||||
SRpcConn *pConn = (SRpcConn *)pRecv->thandle;
|
SRpcConn *pConn = (SRpcConn *)pRecv->thandle;
|
||||||
|
|
||||||
tTraceDump(pRecv->msg, pRecv->msgLen);
|
tDump(pRecv->msg, pRecv->msgLen);
|
||||||
|
|
||||||
// underlying UDP layer does not know it is server or client
|
// underlying UDP layer does not know it is server or client
|
||||||
pRecv->connType = pRecv->connType | pRpc->connType;
|
pRecv->connType = pRecv->connType | pRpc->connType;
|
||||||
|
@ -1061,6 +1068,7 @@ static void rpcProcessIncomingMsg(SRpcConn *pConn, SRpcHead *pHead) {
|
||||||
SRpcReqContext *pContext = pConn->pContext;
|
SRpcReqContext *pContext = pConn->pContext;
|
||||||
rpcMsg.handle = pContext;
|
rpcMsg.handle = pContext;
|
||||||
pConn->pContext = NULL;
|
pConn->pContext = NULL;
|
||||||
|
pConn->pReqMsg = NULL;
|
||||||
|
|
||||||
// for UDP, port may be changed by server, the port in ipSet shall be used for cache
|
// for UDP, port may be changed by server, the port in ipSet shall be used for cache
|
||||||
if (pHead->code != TSDB_CODE_RPC_TOO_SLOW) {
|
if (pHead->code != TSDB_CODE_RPC_TOO_SLOW) {
|
||||||
|
@ -1247,7 +1255,7 @@ static void rpcSendMsgToPeer(SRpcConn *pConn, void *msg, int msgLen) {
|
||||||
tError("%s, failed to send, msgLen:%d written:%d, reason:%s", pConn->info, msgLen, writtenLen, strerror(errno));
|
tError("%s, failed to send, msgLen:%d written:%d, reason:%s", pConn->info, msgLen, writtenLen, strerror(errno));
|
||||||
}
|
}
|
||||||
|
|
||||||
tTraceDump(msg, msgLen);
|
tDump(msg, msgLen);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void rpcProcessConnError(void *param, void *id) {
|
static void rpcProcessConnError(void *param, void *id) {
|
||||||
|
@ -1297,6 +1305,7 @@ static void rpcProcessRetryTimer(void *param, void *tmrId) {
|
||||||
tDebug("%s, failed to send msg:%s to %s:%hu", pConn->info, taosMsg[pConn->outType], pConn->peerFqdn, pConn->peerPort);
|
tDebug("%s, failed to send msg:%s to %s:%hu", pConn->info, taosMsg[pConn->outType], pConn->peerFqdn, pConn->peerPort);
|
||||||
if (pConn->pContext) {
|
if (pConn->pContext) {
|
||||||
pConn->pContext->code = TSDB_CODE_RPC_NETWORK_UNAVAIL;
|
pConn->pContext->code = TSDB_CODE_RPC_NETWORK_UNAVAIL;
|
||||||
|
pConn->pReqMsg = NULL;
|
||||||
taosTmrStart(rpcProcessConnError, 0, pConn->pContext, pRpc->tmrCtrl);
|
taosTmrStart(rpcProcessConnError, 0, pConn->pContext, pRpc->tmrCtrl);
|
||||||
rpcReleaseConn(pConn);
|
rpcReleaseConn(pConn);
|
||||||
}
|
}
|
||||||
|
@ -1357,6 +1366,7 @@ static int32_t rpcCompressRpcMsg(char* pCont, int32_t contLen) {
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t compLen = LZ4_compress_default(pCont, buf, contLen, contLen + overhead);
|
int32_t compLen = LZ4_compress_default(pCont, buf, contLen, contLen + overhead);
|
||||||
|
tDebug("compress rpc msg, before:%d, after:%d, overhead:%d", contLen, compLen, overhead);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* only the compressed size is less than the value of contLen - overhead, the compression is applied
|
* only the compressed size is less than the value of contLen - overhead, the compression is applied
|
||||||
|
@ -1369,7 +1379,7 @@ static int32_t rpcCompressRpcMsg(char* pCont, int32_t contLen) {
|
||||||
memcpy(pCont + overhead, buf, compLen);
|
memcpy(pCont + overhead, buf, compLen);
|
||||||
|
|
||||||
pHead->comp = 1;
|
pHead->comp = 1;
|
||||||
//tDebug("compress rpc msg, before:%d, after:%d", contLen, compLen);
|
tDebug("compress rpc msg, before:%d, after:%d", contLen, compLen);
|
||||||
finalLen = compLen + overhead;
|
finalLen = compLen + overhead;
|
||||||
} else {
|
} else {
|
||||||
finalLen = contLen;
|
finalLen = contLen;
|
||||||
|
|
|
@ -156,6 +156,7 @@ int main(int argc, char *argv[]) {
|
||||||
}
|
}
|
||||||
|
|
||||||
tInfo("client is initialized");
|
tInfo("client is initialized");
|
||||||
|
tInfo("threads:%d msgSize:%d requests:%d", appThreads, msgSize, numOfReqs);
|
||||||
|
|
||||||
gettimeofday(&systemTime, NULL);
|
gettimeofday(&systemTime, NULL);
|
||||||
startTime = systemTime.tv_sec*1000000 + systemTime.tv_usec;
|
startTime = systemTime.tv_sec*1000000 + systemTime.tv_usec;
|
||||||
|
|
|
@ -24,23 +24,21 @@ int msgSize = 128;
|
||||||
int commit = 0;
|
int commit = 0;
|
||||||
int dataFd = -1;
|
int dataFd = -1;
|
||||||
void *qhandle = NULL;
|
void *qhandle = NULL;
|
||||||
|
void *qset = NULL;
|
||||||
|
|
||||||
void processShellMsg() {
|
void processShellMsg() {
|
||||||
static int num = 0;
|
static int num = 0;
|
||||||
taos_qall qall;
|
taos_qall qall;
|
||||||
SRpcMsg *pRpcMsg, rpcMsg;
|
SRpcMsg *pRpcMsg, rpcMsg;
|
||||||
int type;
|
int type;
|
||||||
|
void *pvnode;
|
||||||
|
|
||||||
qall = taosAllocateQall();
|
qall = taosAllocateQall();
|
||||||
|
|
||||||
while (1) {
|
while (1) {
|
||||||
int numOfMsgs = taosReadAllQitems(qhandle, qall);
|
int numOfMsgs = taosReadAllQitemsFromQset(qset, qall, &pvnode);
|
||||||
if (numOfMsgs <= 0) {
|
|
||||||
usleep(100);
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
tDebug("%d shell msgs are received", numOfMsgs);
|
tDebug("%d shell msgs are received", numOfMsgs);
|
||||||
|
if (numOfMsgs <= 0) break;
|
||||||
|
|
||||||
for (int i=0; i<numOfMsgs; ++i) {
|
for (int i=0; i<numOfMsgs; ++i) {
|
||||||
taosGetQitem(qall, &type, (void **)&pRpcMsg);
|
taosGetQitem(qall, &type, (void **)&pRpcMsg);
|
||||||
|
@ -82,15 +80,6 @@ void processShellMsg() {
|
||||||
}
|
}
|
||||||
|
|
||||||
taosFreeQall(qall);
|
taosFreeQall(qall);
|
||||||
/*
|
|
||||||
SRpcIpSet ipSet;
|
|
||||||
ipSet.numOfIps = 1;
|
|
||||||
ipSet.index = 0;
|
|
||||||
ipSet.port = 7000;
|
|
||||||
ipSet.ip[0] = inet_addr("192.168.0.2");
|
|
||||||
|
|
||||||
rpcSendRedirectRsp(ahandle, &ipSet);
|
|
||||||
*/
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -189,6 +178,8 @@ int main(int argc, char *argv[]) {
|
||||||
}
|
}
|
||||||
|
|
||||||
qhandle = taosOpenQueue(sizeof(SRpcMsg));
|
qhandle = taosOpenQueue(sizeof(SRpcMsg));
|
||||||
|
qset = taosOpenQset();
|
||||||
|
taosAddIntoQset(qset, qhandle, NULL);
|
||||||
|
|
||||||
processShellMsg();
|
processShellMsg();
|
||||||
|
|
||||||
|
|
|
@ -47,9 +47,9 @@ extern int tsdbDebugFlag;
|
||||||
// Definitions
|
// Definitions
|
||||||
// ------------------ tsdbMeta.c
|
// ------------------ tsdbMeta.c
|
||||||
typedef struct STable {
|
typedef struct STable {
|
||||||
|
STableId tableId;
|
||||||
ETableType type;
|
ETableType type;
|
||||||
tstr* name; // NOTE: there a flexible string here
|
tstr* name; // NOTE: there a flexible string here
|
||||||
STableId tableId;
|
|
||||||
uint64_t suid;
|
uint64_t suid;
|
||||||
struct STable* pSuper; // super table pointer
|
struct STable* pSuper; // super table pointer
|
||||||
uint8_t numOfSchemas;
|
uint8_t numOfSchemas;
|
||||||
|
@ -195,7 +195,6 @@ typedef struct {
|
||||||
typedef struct {
|
typedef struct {
|
||||||
uint32_t len;
|
uint32_t len;
|
||||||
uint32_t offset;
|
uint32_t offset;
|
||||||
// uint32_t padding;
|
|
||||||
uint32_t hasLast : 2;
|
uint32_t hasLast : 2;
|
||||||
uint32_t numOfBlocks : 30;
|
uint32_t numOfBlocks : 30;
|
||||||
uint64_t uid;
|
uint64_t uid;
|
||||||
|
@ -224,7 +223,7 @@ typedef struct {
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
int16_t colId;
|
int16_t colId;
|
||||||
int16_t len;
|
int32_t len;
|
||||||
int32_t type : 8;
|
int32_t type : 8;
|
||||||
int32_t offset : 24;
|
int32_t offset : 24;
|
||||||
int64_t sum;
|
int64_t sum;
|
||||||
|
@ -298,16 +297,71 @@ STsdbMeta* tsdbNewMeta(STsdbCfg* pCfg);
|
||||||
void tsdbFreeMeta(STsdbMeta* pMeta);
|
void tsdbFreeMeta(STsdbMeta* pMeta);
|
||||||
int tsdbOpenMeta(STsdbRepo* pRepo);
|
int tsdbOpenMeta(STsdbRepo* pRepo);
|
||||||
int tsdbCloseMeta(STsdbRepo* pRepo);
|
int tsdbCloseMeta(STsdbRepo* pRepo);
|
||||||
STSchema* tsdbGetTableSchema(STable* pTable);
|
|
||||||
STable* tsdbGetTableByUid(STsdbMeta* pMeta, uint64_t uid);
|
STable* tsdbGetTableByUid(STsdbMeta* pMeta, uint64_t uid);
|
||||||
STSchema* tsdbGetTableSchemaByVersion(STable* pTable, int16_t version);
|
STSchema* tsdbGetTableSchemaByVersion(STable* pTable, int16_t version);
|
||||||
STSchema* tsdbGetTableTagSchema(STable* pTable);
|
|
||||||
int tsdbUpdateTable(STsdbRepo* pRepo, STable* pTable, STableCfg* pCfg);
|
|
||||||
int tsdbWLockRepoMeta(STsdbRepo* pRepo);
|
int tsdbWLockRepoMeta(STsdbRepo* pRepo);
|
||||||
int tsdbRLockRepoMeta(STsdbRepo* pRepo);
|
int tsdbRLockRepoMeta(STsdbRepo* pRepo);
|
||||||
int tsdbUnlockRepoMeta(STsdbRepo* pRepo);
|
int tsdbUnlockRepoMeta(STsdbRepo* pRepo);
|
||||||
void tsdbRefTable(STable* pTable);
|
void tsdbRefTable(STable* pTable);
|
||||||
void tsdbUnRefTable(STable* pTable);
|
void tsdbUnRefTable(STable* pTable);
|
||||||
|
void tsdbUpdateTableSchema(STsdbRepo* pRepo, STable* pTable, STSchema* pSchema, bool insertAct);
|
||||||
|
|
||||||
|
static FORCE_INLINE int tsdbCompareSchemaVersion(const void *key1, const void *key2) {
|
||||||
|
if (*(int16_t *)key1 < schemaVersion(*(STSchema **)key2)) {
|
||||||
|
return -1;
|
||||||
|
} else if (*(int16_t *)key1 > schemaVersion(*(STSchema **)key2)) {
|
||||||
|
return 1;
|
||||||
|
} else {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static FORCE_INLINE STSchema* tsdbGetTableSchemaImpl(STable* pTable, bool lock, bool copy, int16_t version) {
|
||||||
|
STable* pDTable = (TABLE_TYPE(pTable) == TSDB_CHILD_TABLE) ? pTable->pSuper : pTable;
|
||||||
|
STSchema* pSchema = NULL;
|
||||||
|
STSchema* pTSchema = NULL;
|
||||||
|
|
||||||
|
if (lock) taosRLockLatch(&(pDTable->latch));
|
||||||
|
if (version < 0) { // get the latest version of schema
|
||||||
|
pTSchema = pDTable->schema[pDTable->numOfSchemas - 1];
|
||||||
|
} else { // get the schema with version
|
||||||
|
void* ptr = taosbsearch(&version, pDTable->schema, pDTable->numOfSchemas, sizeof(STSchema*),
|
||||||
|
tsdbCompareSchemaVersion, TD_EQ);
|
||||||
|
if (ptr == NULL) {
|
||||||
|
terrno = TSDB_CODE_TDB_IVD_TB_SCHEMA_VERSION;
|
||||||
|
goto _exit;
|
||||||
|
}
|
||||||
|
pTSchema = *(STSchema**)ptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
ASSERT(pTSchema != NULL);
|
||||||
|
|
||||||
|
if (copy) {
|
||||||
|
if ((pSchema = tdDupSchema(pTSchema)) == NULL) terrno = TSDB_CODE_TDB_OUT_OF_MEMORY;
|
||||||
|
} else {
|
||||||
|
pSchema = pTSchema;
|
||||||
|
}
|
||||||
|
|
||||||
|
_exit:
|
||||||
|
if (lock) taosRUnLockLatch(&(pDTable->latch));
|
||||||
|
return pSchema;
|
||||||
|
}
|
||||||
|
|
||||||
|
static FORCE_INLINE STSchema* tsdbGetTableSchema(STable* pTable) {
|
||||||
|
return tsdbGetTableSchemaImpl(pTable, false, false, -1);
|
||||||
|
}
|
||||||
|
|
||||||
|
static FORCE_INLINE STSchema *tsdbGetTableTagSchema(STable *pTable) {
|
||||||
|
if (pTable->type == TSDB_CHILD_TABLE) { // check child table first
|
||||||
|
STable *pSuper = pTable->pSuper;
|
||||||
|
if (pSuper == NULL) return NULL;
|
||||||
|
return pSuper->tagSchema;
|
||||||
|
} else if (pTable->type == TSDB_SUPER_TABLE) {
|
||||||
|
return pTable->tagSchema;
|
||||||
|
} else {
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// ------------------ tsdbBuffer.c
|
// ------------------ tsdbBuffer.c
|
||||||
STsdbBufPool* tsdbNewBufPool();
|
STsdbBufPool* tsdbNewBufPool();
|
||||||
|
@ -383,8 +437,9 @@ int tsdbLoadCompIdx(SRWHelper* pHelper, void* target);
|
||||||
int tsdbLoadCompInfo(SRWHelper* pHelper, void* target);
|
int tsdbLoadCompInfo(SRWHelper* pHelper, void* target);
|
||||||
int tsdbLoadCompData(SRWHelper* phelper, SCompBlock* pcompblock, void* target);
|
int tsdbLoadCompData(SRWHelper* phelper, SCompBlock* pcompblock, void* target);
|
||||||
void tsdbGetDataStatis(SRWHelper* pHelper, SDataStatis* pStatis, int numOfCols);
|
void tsdbGetDataStatis(SRWHelper* pHelper, SDataStatis* pStatis, int numOfCols);
|
||||||
int tsdbLoadBlockDataCols(SRWHelper* pHelper, SCompBlock* pCompBlock, int16_t* colIds, int numOfColIds);
|
int tsdbLoadBlockDataCols(SRWHelper* pHelper, SCompBlock* pCompBlock, SCompInfo* pCompInfo, int16_t* colIds,
|
||||||
int tsdbLoadBlockData(SRWHelper* pHelper, SCompBlock* pCompBlock);
|
int numOfColIds);
|
||||||
|
int tsdbLoadBlockData(SRWHelper* pHelper, SCompBlock* pCompBlock, SCompInfo* pCompInfo);
|
||||||
|
|
||||||
// ------------------ tsdbMain.c
|
// ------------------ tsdbMain.c
|
||||||
#define REPO_ID(r) (r)->config.tsdbId
|
#define REPO_ID(r) (r)->config.tsdbId
|
||||||
|
|
|
@ -41,9 +41,9 @@ typedef struct {
|
||||||
} SSubmitBlkIter;
|
} SSubmitBlkIter;
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
int32_t totalLen;
|
int32_t totalLen;
|
||||||
int32_t len;
|
int32_t len;
|
||||||
SSubmitBlk *pBlock;
|
void * pMsg;
|
||||||
} SSubmitMsgIter;
|
} SSubmitMsgIter;
|
||||||
|
|
||||||
static int32_t tsdbCheckAndSetDefaultCfg(STsdbCfg *pCfg);
|
static int32_t tsdbCheckAndSetDefaultCfg(STsdbCfg *pCfg);
|
||||||
|
@ -56,7 +56,7 @@ static STsdbRepo * tsdbNewRepo(char *rootDir, STsdbAppH *pAppH, STsdbCfg *pCfg);
|
||||||
static void tsdbFreeRepo(STsdbRepo *pRepo);
|
static void tsdbFreeRepo(STsdbRepo *pRepo);
|
||||||
static int tsdbInitSubmitMsgIter(SSubmitMsg *pMsg, SSubmitMsgIter *pIter);
|
static int tsdbInitSubmitMsgIter(SSubmitMsg *pMsg, SSubmitMsgIter *pIter);
|
||||||
static int32_t tsdbInsertDataToTable(STsdbRepo *pRepo, SSubmitBlk *pBlock, TSKEY now, int32_t *affectedrows);
|
static int32_t tsdbInsertDataToTable(STsdbRepo *pRepo, SSubmitBlk *pBlock, TSKEY now, int32_t *affectedrows);
|
||||||
static SSubmitBlk *tsdbGetSubmitMsgNext(SSubmitMsgIter *pIter);
|
static int tsdbGetSubmitMsgNext(SSubmitMsgIter *pIter, SSubmitBlk **pPBlock);
|
||||||
static SDataRow tsdbGetSubmitBlkNext(SSubmitBlkIter *pIter);
|
static SDataRow tsdbGetSubmitBlkNext(SSubmitBlkIter *pIter);
|
||||||
static int tsdbRestoreInfo(STsdbRepo *pRepo);
|
static int tsdbRestoreInfo(STsdbRepo *pRepo);
|
||||||
static int tsdbInitSubmitBlkIter(SSubmitBlk *pBlock, SSubmitBlkIter *pIter);
|
static int tsdbInitSubmitBlkIter(SSubmitBlk *pBlock, SSubmitBlkIter *pIter);
|
||||||
|
@ -68,6 +68,7 @@ static int keyFGroupCompFunc(const void *key, const void *fgroup);
|
||||||
static int tsdbEncodeCfg(void **buf, STsdbCfg *pCfg);
|
static int tsdbEncodeCfg(void **buf, STsdbCfg *pCfg);
|
||||||
static void * tsdbDecodeCfg(void *buf, STsdbCfg *pCfg);
|
static void * tsdbDecodeCfg(void *buf, STsdbCfg *pCfg);
|
||||||
static int tsdbCheckTableSchema(STsdbRepo *pRepo, SSubmitBlk *pBlock, STable *pTable);
|
static int tsdbCheckTableSchema(STsdbRepo *pRepo, SSubmitBlk *pBlock, STable *pTable);
|
||||||
|
static int tsdbScanAndConvertSubmitMsg(STsdbRepo *pRepo, SSubmitMsg *pMsg);
|
||||||
|
|
||||||
// Function declaration
|
// Function declaration
|
||||||
int32_t tsdbCreateRepo(char *rootDir, STsdbCfg *pCfg) {
|
int32_t tsdbCreateRepo(char *rootDir, STsdbCfg *pCfg) {
|
||||||
|
@ -164,6 +165,13 @@ int32_t tsdbInsertData(TSDB_REPO_T *repo, SSubmitMsg *pMsg, SShellSubmitRspMsg *
|
||||||
STsdbRepo * pRepo = (STsdbRepo *)repo;
|
STsdbRepo * pRepo = (STsdbRepo *)repo;
|
||||||
SSubmitMsgIter msgIter = {0};
|
SSubmitMsgIter msgIter = {0};
|
||||||
|
|
||||||
|
if (tsdbScanAndConvertSubmitMsg(pRepo, pMsg) < 0) {
|
||||||
|
if (terrno != TSDB_CODE_TDB_TABLE_RECONFIGURE) {
|
||||||
|
tsdbError("vgId:%d failed to insert data since %s", REPO_ID(pRepo), tstrerror(terrno));
|
||||||
|
}
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
if (tsdbInitSubmitMsgIter(pMsg, &msgIter) < 0) {
|
if (tsdbInitSubmitMsgIter(pMsg, &msgIter) < 0) {
|
||||||
tsdbError("vgId:%d failed to insert data since %s", REPO_ID(pRepo), tstrerror(terrno));
|
tsdbError("vgId:%d failed to insert data since %s", REPO_ID(pRepo), tstrerror(terrno));
|
||||||
return -1;
|
return -1;
|
||||||
|
@ -173,12 +181,14 @@ int32_t tsdbInsertData(TSDB_REPO_T *repo, SSubmitMsg *pMsg, SShellSubmitRspMsg *
|
||||||
int32_t affectedrows = 0;
|
int32_t affectedrows = 0;
|
||||||
|
|
||||||
TSKEY now = taosGetTimestamp(pRepo->config.precision);
|
TSKEY now = taosGetTimestamp(pRepo->config.precision);
|
||||||
|
while (true) {
|
||||||
while ((pBlock = tsdbGetSubmitMsgNext(&msgIter)) != NULL) {
|
tsdbGetSubmitMsgNext(&msgIter, &pBlock);
|
||||||
|
if (pBlock == NULL) break;
|
||||||
if (tsdbInsertDataToTable(pRepo, pBlock, now, &affectedrows) < 0) {
|
if (tsdbInsertDataToTable(pRepo, pBlock, now, &affectedrows) < 0) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (pRsp != NULL) pRsp->affectedRows = htonl(affectedrows);
|
if (pRsp != NULL) pRsp->affectedRows = htonl(affectedrows);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -263,7 +273,7 @@ void tsdbStartStream(TSDB_REPO_T *repo) {
|
||||||
STable *pTable = pMeta->tables[i];
|
STable *pTable = pMeta->tables[i];
|
||||||
if (pTable && pTable->type == TSDB_STREAM_TABLE) {
|
if (pTable && pTable->type == TSDB_STREAM_TABLE) {
|
||||||
pTable->cqhandle = (*pRepo->appH.cqCreateFunc)(pRepo->appH.cqH, TABLE_UID(pTable), TABLE_TID(pTable), pTable->sql,
|
pTable->cqhandle = (*pRepo->appH.cqCreateFunc)(pRepo->appH.cqH, TABLE_UID(pTable), TABLE_TID(pTable), pTable->sql,
|
||||||
tsdbGetTableSchema(pTable));
|
tsdbGetTableSchemaImpl(pTable, false, false, -1));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -694,17 +704,12 @@ static int tsdbInitSubmitMsgIter(SSubmitMsg *pMsg, SSubmitMsgIter *pIter) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
pMsg->length = htonl(pMsg->length);
|
|
||||||
pMsg->numOfBlocks = htonl(pMsg->numOfBlocks);
|
|
||||||
pMsg->compressed = htonl(pMsg->compressed);
|
|
||||||
|
|
||||||
pIter->totalLen = pMsg->length;
|
pIter->totalLen = pMsg->length;
|
||||||
pIter->len = TSDB_SUBMIT_MSG_HEAD_SIZE;
|
pIter->len = 0;
|
||||||
|
pIter->pMsg = pMsg;
|
||||||
if (pMsg->length <= TSDB_SUBMIT_MSG_HEAD_SIZE) {
|
if (pMsg->length <= TSDB_SUBMIT_MSG_HEAD_SIZE) {
|
||||||
terrno = TSDB_CODE_TDB_SUBMIT_MSG_MSSED_UP;
|
terrno = TSDB_CODE_TDB_SUBMIT_MSG_MSSED_UP;
|
||||||
return -1;
|
return -1;
|
||||||
} else {
|
|
||||||
pIter->pBlock = pMsg->blocks;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -714,26 +719,8 @@ static int32_t tsdbInsertDataToTable(STsdbRepo *pRepo, SSubmitBlk *pBlock, TSKEY
|
||||||
STsdbMeta *pMeta = pRepo->tsdbMeta;
|
STsdbMeta *pMeta = pRepo->tsdbMeta;
|
||||||
int64_t points = 0;
|
int64_t points = 0;
|
||||||
|
|
||||||
STable *pTable = tsdbGetTableByUid(pMeta, pBlock->uid);
|
STable *pTable = pMeta->tables[pBlock->tid];
|
||||||
if (pTable == NULL || TABLE_TID(pTable) != pBlock->tid) {
|
ASSERT(pTable != NULL && TABLE_UID(pTable) == pBlock->uid);
|
||||||
tsdbError("vgId:%d failed to get table to insert data, uid %" PRIu64 " tid %d", REPO_ID(pRepo), pBlock->uid,
|
|
||||||
pBlock->tid);
|
|
||||||
terrno = TSDB_CODE_TDB_INVALID_TABLE_ID;
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (TABLE_TYPE(pTable) == TSDB_SUPER_TABLE) {
|
|
||||||
tsdbError("vgId:%d invalid action trying to insert a super table %s", REPO_ID(pRepo), TABLE_CHAR_NAME(pTable));
|
|
||||||
terrno = TSDB_CODE_TDB_INVALID_ACTION;
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Check schema version and update schema if needed
|
|
||||||
if (tsdbCheckTableSchema(pRepo, pBlock, pTable) < 0) {
|
|
||||||
tsdbError("vgId:%d failed to insert data to table %s since %s", REPO_ID(pRepo), TABLE_CHAR_NAME(pTable),
|
|
||||||
tstrerror(terrno));
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
SSubmitBlkIter blkIter = {0};
|
SSubmitBlkIter blkIter = {0};
|
||||||
SDataRow row = NULL;
|
SDataRow row = NULL;
|
||||||
|
@ -764,27 +751,23 @@ static int32_t tsdbInsertDataToTable(STsdbRepo *pRepo, SSubmitBlk *pBlock, TSKEY
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static SSubmitBlk *tsdbGetSubmitMsgNext(SSubmitMsgIter *pIter) {
|
static int tsdbGetSubmitMsgNext(SSubmitMsgIter *pIter, SSubmitBlk **pPBlock) {
|
||||||
SSubmitBlk *pBlock = pIter->pBlock;
|
if (pIter->len == 0) {
|
||||||
if (pBlock == NULL) return NULL;
|
pIter->len += TSDB_SUBMIT_MSG_HEAD_SIZE;
|
||||||
|
|
||||||
pBlock->dataLen = htonl(pBlock->dataLen);
|
|
||||||
pBlock->schemaLen = htonl(pBlock->schemaLen);
|
|
||||||
pBlock->numOfRows = htons(pBlock->numOfRows);
|
|
||||||
pBlock->uid = htobe64(pBlock->uid);
|
|
||||||
pBlock->tid = htonl(pBlock->tid);
|
|
||||||
|
|
||||||
pBlock->sversion = htonl(pBlock->sversion);
|
|
||||||
pBlock->padding = htonl(pBlock->padding);
|
|
||||||
|
|
||||||
pIter->len = pIter->len + sizeof(SSubmitBlk) + pBlock->dataLen;
|
|
||||||
if (pIter->len >= pIter->totalLen) {
|
|
||||||
pIter->pBlock = NULL;
|
|
||||||
} else {
|
} else {
|
||||||
pIter->pBlock = (SSubmitBlk *)((char *)pBlock + pBlock->dataLen + sizeof(SSubmitBlk));
|
SSubmitBlk *pSubmitBlk = (SSubmitBlk *)POINTER_SHIFT(pIter->pMsg, pIter->len);
|
||||||
|
pIter->len += (sizeof(SSubmitBlk) + pSubmitBlk->dataLen + pSubmitBlk->schemaLen);
|
||||||
}
|
}
|
||||||
|
|
||||||
return pBlock;
|
if (pIter->len > pIter->totalLen) {
|
||||||
|
terrno = TSDB_CODE_TDB_SUBMIT_MSG_MSSED_UP;
|
||||||
|
*pPBlock = NULL;
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
*pPBlock = (pIter->len == pIter->totalLen) ? NULL : (SSubmitBlk *)POINTER_SHIFT(pIter->pMsg, pIter->len);
|
||||||
|
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static SDataRow tsdbGetSubmitBlkNext(SSubmitBlkIter *pIter) {
|
static SDataRow tsdbGetSubmitBlkNext(SSubmitBlkIter *pIter) {
|
||||||
|
@ -969,42 +952,64 @@ static void *tsdbDecodeCfg(void *buf, STsdbCfg *pCfg) {
|
||||||
static int tsdbCheckTableSchema(STsdbRepo *pRepo, SSubmitBlk *pBlock, STable *pTable) {
|
static int tsdbCheckTableSchema(STsdbRepo *pRepo, SSubmitBlk *pBlock, STable *pTable) {
|
||||||
ASSERT(pTable != NULL);
|
ASSERT(pTable != NULL);
|
||||||
|
|
||||||
STSchema *pSchema = tsdbGetTableSchema(pTable);
|
STSchema *pSchema = tsdbGetTableSchemaImpl(pTable, false, false, -1);
|
||||||
int sversion = schemaVersion(pSchema);
|
int sversion = schemaVersion(pSchema);
|
||||||
|
|
||||||
if (pBlock->sversion == sversion) return 0;
|
if (pBlock->sversion == sversion) {
|
||||||
if (pBlock->sversion > sversion) { // need to config
|
return 0;
|
||||||
tsdbDebug("vgId:%d table %s tid %d has version %d smaller than client version %d, try to config", REPO_ID(pRepo),
|
} else {
|
||||||
TABLE_CHAR_NAME(pTable), TABLE_TID(pTable), sversion, pBlock->sversion);
|
if (TABLE_TYPE(pTable) == TSDB_STREAM_TABLE) { // stream table is not allowed to change schema
|
||||||
if (pRepo->appH.configFunc) {
|
|
||||||
void *msg = (*pRepo->appH.configFunc)(REPO_ID(pRepo), TABLE_TID(pTable));
|
|
||||||
if (msg == NULL) {
|
|
||||||
tsdbError("vgId:%d failed to config table %s tid %d since %s", REPO_ID(pRepo), TABLE_CHAR_NAME(pTable),
|
|
||||||
TABLE_TID(pTable), tstrerror(terrno));
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
STableCfg *pTableCfg = tsdbCreateTableCfgFromMsg(msg);
|
|
||||||
if (pTableCfg == NULL) {
|
|
||||||
rpcFreeCont(msg);
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (tsdbUpdateTable(pRepo, (TABLE_TYPE(pTable) == TSDB_CHILD_TABLE) ? pTable->pSuper : pTable, pTableCfg) < 0) {
|
|
||||||
tsdbError("vgId:%d failed to update table %s since %s", REPO_ID(pRepo), TABLE_CHAR_NAME(pTable),
|
|
||||||
tstrerror(terrno));
|
|
||||||
tsdbClearTableCfg(pTableCfg);
|
|
||||||
rpcFreeCont(msg);
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
tsdbClearTableCfg(pTableCfg);
|
|
||||||
rpcFreeCont(msg);
|
|
||||||
} else {
|
|
||||||
terrno = TSDB_CODE_TDB_IVD_TB_SCHEMA_VERSION;
|
terrno = TSDB_CODE_TDB_IVD_TB_SCHEMA_VERSION;
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (pBlock->sversion > sversion) { // may need to update table schema
|
||||||
|
if (pBlock->schemaLen > 0) {
|
||||||
|
tsdbDebug(
|
||||||
|
"vgId:%d table %s tid %d uid %" PRIu64 " schema version %d is out of data, client version %d, update...",
|
||||||
|
REPO_ID(pRepo), TABLE_CHAR_NAME(pTable), TABLE_TID(pTable), TABLE_UID(pTable), sversion, pBlock->sversion);
|
||||||
|
ASSERT(pBlock->schemaLen % sizeof(STColumn) == 0);
|
||||||
|
int numOfCols = pBlock->schemaLen / sizeof(STColumn);
|
||||||
|
STColumn *pTCol = (STColumn *)pBlock->data;
|
||||||
|
|
||||||
|
STSchemaBuilder schemaBuilder = {0};
|
||||||
|
if (tdInitTSchemaBuilder(&schemaBuilder, pBlock->sversion) < 0) {
|
||||||
|
terrno = TSDB_CODE_TDB_OUT_OF_MEMORY;
|
||||||
|
tsdbError("vgId:%d failed to update schema of table %s since %s", REPO_ID(pRepo), TABLE_CHAR_NAME(pTable),
|
||||||
|
tstrerror(terrno));
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (int i = 0; i < numOfCols; i++) {
|
||||||
|
if (tdAddColToSchema(&schemaBuilder, pTCol[i].type, htons(pTCol[i].colId), htons(pTCol[i].bytes)) < 0) {
|
||||||
|
terrno = TSDB_CODE_TDB_OUT_OF_MEMORY;
|
||||||
|
tsdbError("vgId:%d failed to update schema of table %s since %s", REPO_ID(pRepo), TABLE_CHAR_NAME(pTable),
|
||||||
|
tstrerror(terrno));
|
||||||
|
tdDestroyTSchemaBuilder(&schemaBuilder);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
STSchema *pNSchema = tdGetSchemaFromBuilder(&schemaBuilder);
|
||||||
|
if (pNSchema == NULL) {
|
||||||
|
terrno = TSDB_CODE_TDB_OUT_OF_MEMORY;
|
||||||
|
tdDestroyTSchemaBuilder(&schemaBuilder);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
tdDestroyTSchemaBuilder(&schemaBuilder);
|
||||||
|
tsdbUpdateTableSchema(pRepo, pTable, pNSchema, true);
|
||||||
|
} else {
|
||||||
|
tsdbDebug(
|
||||||
|
"vgId:%d table %s tid %d uid %" PRIu64 " schema version %d is out of data, client version %d, reconfigure...",
|
||||||
|
REPO_ID(pRepo), TABLE_CHAR_NAME(pTable), TABLE_TID(pTable), TABLE_UID(pTable), sversion, pBlock->sversion);
|
||||||
|
terrno = TSDB_CODE_TDB_TABLE_RECONFIGURE;
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
if (tsdbGetTableSchemaByVersion(pTable, pBlock->sversion) == NULL) {
|
ASSERT(pBlock->sversion >= 0);
|
||||||
|
if (tsdbGetTableSchemaImpl(pTable, false, false, pBlock->sversion) == NULL) {
|
||||||
tsdbError("vgId:%d invalid submit schema version %d to table %s tid %d from client", REPO_ID(pRepo),
|
tsdbError("vgId:%d invalid submit schema version %d to table %s tid %d from client", REPO_ID(pRepo),
|
||||||
pBlock->sversion, TABLE_CHAR_NAME(pTable), TABLE_TID(pTable));
|
pBlock->sversion, TABLE_CHAR_NAME(pTable), TABLE_TID(pTable));
|
||||||
}
|
}
|
||||||
|
@ -1013,7 +1018,64 @@ static int tsdbCheckTableSchema(STsdbRepo *pRepo, SSubmitBlk *pBlock, STable *pT
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int tsdbScanAndConvertSubmitMsg(STsdbRepo *pRepo, SSubmitMsg *pMsg) {
|
||||||
|
ASSERT(pMsg != NULL);
|
||||||
|
STsdbMeta * pMeta = pRepo->tsdbMeta;
|
||||||
|
SSubmitMsgIter msgIter = {0};
|
||||||
|
SSubmitBlk * pBlock = NULL;
|
||||||
|
|
||||||
|
terrno = TSDB_CODE_SUCCESS;
|
||||||
|
pMsg->length = htonl(pMsg->length);
|
||||||
|
pMsg->numOfBlocks = htonl(pMsg->numOfBlocks);
|
||||||
|
|
||||||
|
if (tsdbInitSubmitMsgIter(pMsg, &msgIter) < 0) return -1;
|
||||||
|
while (true) {
|
||||||
|
if (tsdbGetSubmitMsgNext(&msgIter, &pBlock) < 0) return -1;
|
||||||
|
if (pBlock == NULL) break;
|
||||||
|
|
||||||
|
pBlock->uid = htobe64(pBlock->uid);
|
||||||
|
pBlock->tid = htonl(pBlock->tid);
|
||||||
|
pBlock->sversion = htonl(pBlock->sversion);
|
||||||
|
pBlock->dataLen = htonl(pBlock->dataLen);
|
||||||
|
pBlock->schemaLen = htonl(pBlock->schemaLen);
|
||||||
|
pBlock->numOfRows = htons(pBlock->numOfRows);
|
||||||
|
|
||||||
|
if (pBlock->tid <= 0 || pBlock->tid >= pRepo->config.maxTables) {
|
||||||
|
tsdbError("vgId:%d failed to get table to insert data, uid %" PRIu64 " tid %d", REPO_ID(pRepo), pBlock->uid,
|
||||||
|
pBlock->tid);
|
||||||
|
terrno = TSDB_CODE_TDB_INVALID_TABLE_ID;
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
STable *pTable = pMeta->tables[pBlock->tid];
|
||||||
|
if (pTable == NULL || TABLE_UID(pTable) != pBlock->uid) {
|
||||||
|
tsdbError("vgId:%d failed to get table to insert data, uid %" PRIu64 " tid %d", REPO_ID(pRepo), pBlock->uid,
|
||||||
|
pBlock->tid);
|
||||||
|
terrno = TSDB_CODE_TDB_INVALID_TABLE_ID;
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (TABLE_TYPE(pTable) == TSDB_SUPER_TABLE) {
|
||||||
|
tsdbError("vgId:%d invalid action trying to insert a super table %s", REPO_ID(pRepo), TABLE_CHAR_NAME(pTable));
|
||||||
|
terrno = TSDB_CODE_TDB_INVALID_ACTION;
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check schema version and update schema if needed
|
||||||
|
if (tsdbCheckTableSchema(pRepo, pBlock, pTable) < 0) {
|
||||||
|
if (terrno == TSDB_CODE_TDB_TABLE_RECONFIGURE) {
|
||||||
|
continue;
|
||||||
|
} else {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (terrno != TSDB_CODE_SUCCESS) return -1;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
static int tsdbAlterCacheTotalBlocks(STsdbRepo *pRepo, int totalBlocks) {
|
static int tsdbAlterCacheTotalBlocks(STsdbRepo *pRepo, int totalBlocks) {
|
||||||
// TODO
|
// TODO
|
||||||
|
|
|
@ -119,7 +119,8 @@ int tsdbInsertRowToMem(STsdbRepo *pRepo, SDataRow row, STable *pTable) {
|
||||||
|
|
||||||
int tsdbRefMemTable(STsdbRepo *pRepo, SMemTable *pMemTable) {
|
int tsdbRefMemTable(STsdbRepo *pRepo, SMemTable *pMemTable) {
|
||||||
if (pMemTable == NULL) return 0;
|
if (pMemTable == NULL) return 0;
|
||||||
T_REF_INC(pMemTable);
|
int ref = T_REF_INC(pMemTable);
|
||||||
|
tsdbDebug("vgId:%d ref memtable %p ref %d", REPO_ID(pRepo), pMemTable, ref);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -127,7 +128,9 @@ int tsdbRefMemTable(STsdbRepo *pRepo, SMemTable *pMemTable) {
|
||||||
int tsdbUnRefMemTable(STsdbRepo *pRepo, SMemTable *pMemTable) {
|
int tsdbUnRefMemTable(STsdbRepo *pRepo, SMemTable *pMemTable) {
|
||||||
if (pMemTable == NULL) return 0;
|
if (pMemTable == NULL) return 0;
|
||||||
|
|
||||||
if (T_REF_DEC(pMemTable) == 0) {
|
int ref = T_REF_DEC(pMemTable);
|
||||||
|
tsdbDebug("vgId:%d unref memtable %p ref %d", REPO_ID(pRepo), pMemTable, ref);
|
||||||
|
if (ref == 0) {
|
||||||
STsdbCfg * pCfg = &pRepo->config;
|
STsdbCfg * pCfg = &pRepo->config;
|
||||||
STsdbBufPool *pBufPool = pRepo->pPool;
|
STsdbBufPool *pBufPool = pRepo->pPool;
|
||||||
|
|
||||||
|
@ -167,6 +170,7 @@ int tsdbTakeMemSnapshot(STsdbRepo *pRepo, SMemTable **pMem, SMemTable **pIMem) {
|
||||||
tsdbRefMemTable(pRepo, *pIMem);
|
tsdbRefMemTable(pRepo, *pIMem);
|
||||||
|
|
||||||
if (tsdbUnlockRepo(pRepo) < 0) return -1;
|
if (tsdbUnlockRepo(pRepo) < 0) return -1;
|
||||||
|
tsdbDebug("vgId:%d take memory snapshot, pMem %p pIMem %p", REPO_ID(pRepo), *pMem, *pIMem);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -538,10 +542,12 @@ static int tsdbCommitToFile(STsdbRepo *pRepo, int fid, SCommitIter *iters, SRWHe
|
||||||
SCommitIter *pIter = iters + tid;
|
SCommitIter *pIter = iters + tid;
|
||||||
if (pIter->pTable == NULL) continue;
|
if (pIter->pTable == NULL) continue;
|
||||||
|
|
||||||
|
taosRLockLatch(&(pIter->pTable->latch));
|
||||||
|
|
||||||
tsdbSetHelperTable(pHelper, pIter->pTable, pRepo);
|
tsdbSetHelperTable(pHelper, pIter->pTable, pRepo);
|
||||||
|
|
||||||
if (pIter->pIter != NULL) {
|
if (pIter->pIter != NULL) {
|
||||||
tdInitDataCols(pDataCols, tsdbGetTableSchema(pIter->pTable));
|
tdInitDataCols(pDataCols, tsdbGetTableSchemaImpl(pIter->pTable, false, false, -1));
|
||||||
|
|
||||||
int maxRowsToRead = pCfg->maxRowsPerFileBlock * 4 / 5;
|
int maxRowsToRead = pCfg->maxRowsPerFileBlock * 4 / 5;
|
||||||
int nLoop = 0;
|
int nLoop = 0;
|
||||||
|
@ -557,6 +563,7 @@ static int tsdbCommitToFile(STsdbRepo *pRepo, int fid, SCommitIter *iters, SRWHe
|
||||||
int rowsWritten = tsdbWriteDataBlock(pHelper, pDataCols);
|
int rowsWritten = tsdbWriteDataBlock(pHelper, pDataCols);
|
||||||
ASSERT(rowsWritten != 0);
|
ASSERT(rowsWritten != 0);
|
||||||
if (rowsWritten < 0) {
|
if (rowsWritten < 0) {
|
||||||
|
taosRUnLockLatch(&(pIter->pTable->latch));
|
||||||
tsdbError("vgId:%d failed to write data block to table %s tid %d uid %" PRIu64 " since %s", REPO_ID(pRepo),
|
tsdbError("vgId:%d failed to write data block to table %s tid %d uid %" PRIu64 " since %s", REPO_ID(pRepo),
|
||||||
TABLE_CHAR_NAME(pIter->pTable), TABLE_TID(pIter->pTable), TABLE_UID(pIter->pTable),
|
TABLE_CHAR_NAME(pIter->pTable), TABLE_TID(pIter->pTable), TABLE_UID(pIter->pTable),
|
||||||
tstrerror(terrno));
|
tstrerror(terrno));
|
||||||
|
@ -571,6 +578,8 @@ static int tsdbCommitToFile(STsdbRepo *pRepo, int fid, SCommitIter *iters, SRWHe
|
||||||
ASSERT(pDataCols->numOfRows == 0);
|
ASSERT(pDataCols->numOfRows == 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
taosRUnLockLatch(&(pIter->pTable->latch));
|
||||||
|
|
||||||
// Move the last block to the new .l file if neccessary
|
// Move the last block to the new .l file if neccessary
|
||||||
if (tsdbMoveLastBlockIfNeccessary(pHelper) < 0) {
|
if (tsdbMoveLastBlockIfNeccessary(pHelper) < 0) {
|
||||||
tsdbError("vgId:%d, failed to move last block, since %s", REPO_ID(pRepo), tstrerror(terrno));
|
tsdbError("vgId:%d, failed to move last block, since %s", REPO_ID(pRepo), tstrerror(terrno));
|
||||||
|
@ -680,10 +689,10 @@ static int tsdbReadRowsFromCache(STsdbMeta *pMeta, STable *pTable, SSkipListIter
|
||||||
if (dataRowKey(row) > maxKey) break;
|
if (dataRowKey(row) > maxKey) break;
|
||||||
|
|
||||||
if (pSchema == NULL || schemaVersion(pSchema) != dataRowVersion(row)) {
|
if (pSchema == NULL || schemaVersion(pSchema) != dataRowVersion(row)) {
|
||||||
pSchema = tsdbGetTableSchemaByVersion(pTable, dataRowVersion(row));
|
pSchema = tsdbGetTableSchemaImpl(pTable, true, false, dataRowVersion(row));
|
||||||
if (pSchema == NULL) {
|
if (pSchema == NULL) {
|
||||||
// TODO: deal with the error here
|
// TODO: deal with the error here
|
||||||
ASSERT(false);
|
ASSERT(0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -29,10 +29,9 @@ static void tsdbOrgMeta(void *pHandle);
|
||||||
static char * getTagIndexKey(const void *pData);
|
static char * getTagIndexKey(const void *pData);
|
||||||
static STable *tsdbNewTable(STableCfg *pCfg, bool isSuper);
|
static STable *tsdbNewTable(STableCfg *pCfg, bool isSuper);
|
||||||
static void tsdbFreeTable(STable *pTable);
|
static void tsdbFreeTable(STable *pTable);
|
||||||
static int tsdbUpdateTableTagSchema(STable *pTable, STSchema *newSchema);
|
static int tsdbAddTableToMeta(STsdbRepo *pRepo, STable *pTable, bool addIdx, bool lock);
|
||||||
static int tsdbAddTableToMeta(STsdbRepo *pRepo, STable *pTable, bool addIdx);
|
|
||||||
static void tsdbRemoveTableFromMeta(STsdbRepo *pRepo, STable *pTable, bool rmFromIdx, bool lock);
|
static void tsdbRemoveTableFromMeta(STsdbRepo *pRepo, STable *pTable, bool rmFromIdx, bool lock);
|
||||||
static int tsdbAddTableIntoIndex(STsdbMeta *pMeta, STable *pTable);
|
static int tsdbAddTableIntoIndex(STsdbMeta *pMeta, STable *pTable, bool refSuper);
|
||||||
static int tsdbRemoveTableFromIndex(STsdbMeta *pMeta, STable *pTable);
|
static int tsdbRemoveTableFromIndex(STsdbMeta *pMeta, STable *pTable);
|
||||||
static int tsdbInitTableCfg(STableCfg *config, ETableType type, uint64_t uid, int32_t tid);
|
static int tsdbInitTableCfg(STableCfg *config, ETableType type, uint64_t uid, int32_t tid);
|
||||||
static int tsdbTableSetSchema(STableCfg *config, STSchema *pSchema, bool dup);
|
static int tsdbTableSetSchema(STableCfg *config, STSchema *pSchema, bool dup);
|
||||||
|
@ -76,7 +75,7 @@ int tsdbCreateTable(TSDB_REPO_T *repo, STableCfg *pCfg) {
|
||||||
// TODO
|
// TODO
|
||||||
if (super->type != TSDB_SUPER_TABLE) return -1;
|
if (super->type != TSDB_SUPER_TABLE) return -1;
|
||||||
if (super->tableId.uid != pCfg->superUid) return -1;
|
if (super->tableId.uid != pCfg->superUid) return -1;
|
||||||
tsdbUpdateTable(pRepo, super, pCfg);
|
// tsdbUpdateTable(pRepo, super, pCfg);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -84,10 +83,18 @@ int tsdbCreateTable(TSDB_REPO_T *repo, STableCfg *pCfg) {
|
||||||
if (table == NULL) goto _err;
|
if (table == NULL) goto _err;
|
||||||
|
|
||||||
// Register to meta
|
// Register to meta
|
||||||
|
tsdbWLockRepoMeta(pRepo);
|
||||||
if (newSuper) {
|
if (newSuper) {
|
||||||
if (tsdbAddTableToMeta(pRepo, super, true) < 0) goto _err;
|
if (tsdbAddTableToMeta(pRepo, super, true, false) < 0) {
|
||||||
|
tsdbUnlockRepoMeta(pRepo);
|
||||||
|
goto _err;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if (tsdbAddTableToMeta(pRepo, table, true) < 0) goto _err;
|
if (tsdbAddTableToMeta(pRepo, table, true, false) < 0) {
|
||||||
|
tsdbUnlockRepoMeta(pRepo);
|
||||||
|
goto _err;
|
||||||
|
}
|
||||||
|
tsdbUnlockRepoMeta(pRepo);
|
||||||
|
|
||||||
// Write to memtable action
|
// Write to memtable action
|
||||||
int tlen1 = (newSuper) ? tsdbGetTableEncodeSize(TSDB_UPDATE_META, super) : 0;
|
int tlen1 = (newSuper) ? tsdbGetTableEncodeSize(TSDB_UPDATE_META, super) : 0;
|
||||||
|
@ -185,11 +192,6 @@ char *tsdbGetTableName(void* pTable) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
STableId tsdbGetTableId(void *pTable) {
|
|
||||||
assert(pTable);
|
|
||||||
return ((STable*)pTable)->tableId;
|
|
||||||
}
|
|
||||||
|
|
||||||
STableCfg *tsdbCreateTableCfgFromMsg(SMDCreateTableMsg *pMsg) {
|
STableCfg *tsdbCreateTableCfgFromMsg(SMDCreateTableMsg *pMsg) {
|
||||||
if (pMsg == NULL) return NULL;
|
if (pMsg == NULL) return NULL;
|
||||||
|
|
||||||
|
@ -255,7 +257,7 @@ _err:
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int32_t colIdCompar(const void* left, const void* right) {
|
static UNUSED_FUNC int32_t colIdCompar(const void* left, const void* right) {
|
||||||
int16_t colId = *(int16_t*) left;
|
int16_t colId = *(int16_t*) left;
|
||||||
STColumn* p2 = (STColumn*) right;
|
STColumn* p2 = (STColumn*) right;
|
||||||
|
|
||||||
|
@ -266,89 +268,118 @@ static int32_t colIdCompar(const void* left, const void* right) {
|
||||||
return (colId < p2->colId)? -1:1;
|
return (colId < p2->colId)? -1:1;
|
||||||
}
|
}
|
||||||
|
|
||||||
int tsdbUpdateTagValue(TSDB_REPO_T *repo, SUpdateTableTagValMsg *pMsg) {
|
int tsdbUpdateTableTagValue(TSDB_REPO_T *repo, SUpdateTableTagValMsg *pMsg) {
|
||||||
STsdbRepo *pRepo = (STsdbRepo *)repo;
|
STsdbRepo *pRepo = (STsdbRepo *)repo;
|
||||||
STsdbMeta *pMeta = pRepo->tsdbMeta;
|
STsdbMeta *pMeta = pRepo->tsdbMeta;
|
||||||
|
STSchema * pNewSchema = NULL;
|
||||||
|
|
||||||
pMsg->uid = htobe64(pMsg->uid);
|
pMsg->uid = htobe64(pMsg->uid);
|
||||||
pMsg->tid = htonl(pMsg->tid);
|
pMsg->tid = htonl(pMsg->tid);
|
||||||
pMsg->tversion = htons(pMsg->tversion);
|
pMsg->tversion = htons(pMsg->tversion);
|
||||||
pMsg->colId = htons(pMsg->colId);
|
pMsg->colId = htons(pMsg->colId);
|
||||||
|
pMsg->bytes = htons(pMsg->bytes);
|
||||||
pMsg->tagValLen = htonl(pMsg->tagValLen);
|
pMsg->tagValLen = htonl(pMsg->tagValLen);
|
||||||
pMsg->numOfTags = htons(pMsg->numOfTags);
|
pMsg->numOfTags = htons(pMsg->numOfTags);
|
||||||
pMsg->schemaLen = htonl(pMsg->schemaLen);
|
pMsg->schemaLen = htonl(pMsg->schemaLen);
|
||||||
assert(pMsg->schemaLen == sizeof(STColumn) * pMsg->numOfTags);
|
for (int i = 0; i < pMsg->numOfTags; i++) {
|
||||||
|
STColumn *pTCol = (STColumn *)pMsg->data + i;
|
||||||
char* d = pMsg->data;
|
pTCol->bytes = htons(pTCol->bytes);
|
||||||
for(int32_t i = 0; i < pMsg->numOfTags; ++i) {
|
pTCol->colId = htons(pTCol->colId);
|
||||||
STColumn* pCol = (STColumn*) d;
|
|
||||||
pCol->colId = htons(pCol->colId);
|
|
||||||
pCol->bytes = htons(pCol->bytes);
|
|
||||||
pCol->offset = 0;
|
|
||||||
|
|
||||||
d += sizeof(STColumn);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
STable *pTable = tsdbGetTableByUid(pMeta, pMsg->uid);
|
STable *pTable = tsdbGetTableByUid(pMeta, pMsg->uid);
|
||||||
if (pTable == NULL) {
|
if (pTable == NULL || TABLE_TID(pTable) != pMsg->tid) {
|
||||||
terrno = TSDB_CODE_TDB_INVALID_TABLE_ID;
|
tsdbError("vgId:%d failed to update table tag value since invalid table id %d uid %" PRIu64, REPO_ID(pRepo),
|
||||||
return -1;
|
pMsg->tid, pMsg->uid);
|
||||||
}
|
|
||||||
if (TABLE_TID(pTable) != pMsg->tid) {
|
|
||||||
terrno = TSDB_CODE_TDB_INVALID_TABLE_ID;
|
terrno = TSDB_CODE_TDB_INVALID_TABLE_ID;
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (TABLE_TYPE(pTable) != TSDB_CHILD_TABLE) {
|
if (TABLE_TYPE(pTable) != TSDB_CHILD_TABLE) {
|
||||||
tsdbError("vgId:%d failed to update tag value of table %s since its type is %d", REPO_ID(pRepo),
|
tsdbError("vgId:%d try to update tag value of a non-child table, invalid action", REPO_ID(pRepo));
|
||||||
TABLE_CHAR_NAME(pTable), TABLE_TYPE(pTable));
|
|
||||||
terrno = TSDB_CODE_TDB_INVALID_ACTION;
|
terrno = TSDB_CODE_TDB_INVALID_ACTION;
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (schemaVersion(tsdbGetTableTagSchema(pTable)) < pMsg->tversion) {
|
if (schemaVersion(pTable->pSuper->tagSchema) > pMsg->tversion) {
|
||||||
tsdbDebug("vgId:%d server tag version %d is older than client tag version %d, try to config", REPO_ID(pRepo),
|
|
||||||
schemaVersion(tsdbGetTableTagSchema(pTable)), pMsg->tversion);
|
|
||||||
void *msg = (*pRepo->appH.configFunc)(pRepo->config.tsdbId, pMsg->tid);
|
|
||||||
if (msg == NULL) return -1;
|
|
||||||
|
|
||||||
// Deal with error her
|
|
||||||
STableCfg *pTableCfg = tsdbCreateTableCfgFromMsg(msg);
|
|
||||||
STable * super = tsdbGetTableByUid(pMeta, pTableCfg->superUid);
|
|
||||||
ASSERT(super != NULL);
|
|
||||||
|
|
||||||
int32_t code = tsdbUpdateTable(pRepo, super, pTableCfg);
|
|
||||||
if (code != TSDB_CODE_SUCCESS) {
|
|
||||||
tsdbClearTableCfg(pTableCfg);
|
|
||||||
return code;
|
|
||||||
}
|
|
||||||
tsdbClearTableCfg(pTableCfg);
|
|
||||||
rpcFreeCont(msg);
|
|
||||||
}
|
|
||||||
|
|
||||||
STSchema *pTagSchema = tsdbGetTableTagSchema(pTable);
|
|
||||||
|
|
||||||
if (schemaVersion(pTagSchema) > pMsg->tversion) {
|
|
||||||
tsdbError(
|
tsdbError(
|
||||||
"vgId:%d failed to update tag value of table %s since version out of date, client tag version %d server tag "
|
"vgId:%d failed to update tag value of table %s since version out of date, client tag version %d server tag "
|
||||||
"version %d",
|
"version %d",
|
||||||
REPO_ID(pRepo), TABLE_CHAR_NAME(pTable), pMsg->tversion, schemaVersion(pTable->tagSchema));
|
REPO_ID(pRepo), TABLE_CHAR_NAME(pTable), pMsg->tversion, schemaVersion(pTable->tagSchema));
|
||||||
return TSDB_CODE_TDB_TAG_VER_OUT_OF_DATE;
|
terrno = TSDB_CODE_TDB_TAG_VER_OUT_OF_DATE;
|
||||||
|
return -1;
|
||||||
}
|
}
|
||||||
if (schemaColAt(pTagSchema, DEFAULT_TAG_INDEX_COLUMN)->colId == pMsg->colId) {
|
|
||||||
|
if (schemaVersion(pTable->pSuper->tagSchema) < pMsg->tversion) { // tag schema out of data,
|
||||||
|
tsdbDebug("vgId:%d need to update tag schema of table %s tid %d uid %" PRIu64
|
||||||
|
" since out of date, current version %d new version %d",
|
||||||
|
REPO_ID(pRepo), TABLE_CHAR_NAME(pTable), TABLE_TID(pTable), TABLE_UID(pTable),
|
||||||
|
schemaVersion(pTable->pSuper->tagSchema), pMsg->tversion);
|
||||||
|
|
||||||
|
STSchemaBuilder schemaBuilder = {0};
|
||||||
|
|
||||||
|
STColumn *pTCol = (STColumn *)pMsg->data;
|
||||||
|
ASSERT(pMsg->schemaLen % sizeof(STColumn) == 0 && pTCol[0].colId == colColId(schemaColAt(pTable->pSuper->tagSchema, 0)));
|
||||||
|
if (tdInitTSchemaBuilder(&schemaBuilder, pMsg->tversion) < 0) {
|
||||||
|
tsdbDebug("vgId:%d failed to update tag schema of table %s tid %d uid %" PRIu64 " since out of memory",
|
||||||
|
REPO_ID(pRepo), TABLE_CHAR_NAME(pTable), TABLE_TID(pTable), TABLE_UID(pTable));
|
||||||
|
terrno = TSDB_CODE_TDB_OUT_OF_MEMORY;
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
for (int i = 0; i < (pMsg->schemaLen / sizeof(STColumn)); i++) {
|
||||||
|
if (tdAddColToSchema(&schemaBuilder, pTCol[i].type, pTCol[i].colId, pTCol[i].bytes) < 0) {
|
||||||
|
tdDestroyTSchemaBuilder(&schemaBuilder);
|
||||||
|
terrno = TSDB_CODE_TDB_OUT_OF_MEMORY;
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
pNewSchema = tdGetSchemaFromBuilder(&schemaBuilder);
|
||||||
|
if (pNewSchema == NULL) {
|
||||||
|
tdDestroyTSchemaBuilder(&schemaBuilder);
|
||||||
|
terrno = TSDB_CODE_TDB_OUT_OF_MEMORY;
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
tdDestroyTSchemaBuilder(&schemaBuilder);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Chage in memory
|
||||||
|
if (pNewSchema != NULL) { // change super table tag schema
|
||||||
|
taosWLockLatch(&(pTable->pSuper->latch));
|
||||||
|
STSchema *pOldSchema = pTable->pSuper->tagSchema;
|
||||||
|
pTable->pSuper->tagSchema = pNewSchema;
|
||||||
|
tdFreeSchema(pOldSchema);
|
||||||
|
taosWUnLockLatch(&(pTable->pSuper->latch));
|
||||||
|
}
|
||||||
|
|
||||||
|
bool isChangeIndexCol = (pMsg->colId == colColId(schemaColAt(pTable->pSuper->tagSchema, 0)));
|
||||||
|
// STColumn *pCol = bsearch(&(pMsg->colId), pMsg->data, pMsg->numOfTags, sizeof(STColumn), colIdCompar);
|
||||||
|
// ASSERT(pCol != NULL);
|
||||||
|
|
||||||
|
if (isChangeIndexCol) {
|
||||||
|
tsdbWLockRepoMeta(pRepo);
|
||||||
tsdbRemoveTableFromIndex(pMeta, pTable);
|
tsdbRemoveTableFromIndex(pMeta, pTable);
|
||||||
}
|
}
|
||||||
// TODO: remove table from index if it is the first column of tag
|
taosWLockLatch(&(pTable->latch));
|
||||||
|
tdSetKVRowDataOfCol(&(pTable->tagVal), pMsg->colId, pMsg->type, POINTER_SHIFT(pMsg->data, pMsg->schemaLen));
|
||||||
// TODO: convert the tag schema from client, and then extract the type and bytes from schema according to colId
|
taosWUnLockLatch(&(pTable->latch));
|
||||||
STColumn* res = bsearch(&pMsg->colId, pMsg->data, pMsg->numOfTags, sizeof(STColumn), colIdCompar);
|
if (isChangeIndexCol) {
|
||||||
assert(res != NULL);
|
tsdbAddTableIntoIndex(pMeta, pTable, false);
|
||||||
|
tsdbUnlockRepoMeta(pRepo);
|
||||||
tdSetKVRowDataOfCol(&pTable->tagVal, pMsg->colId, res->type, pMsg->data + pMsg->schemaLen);
|
|
||||||
if (schemaColAt(pTagSchema, DEFAULT_TAG_INDEX_COLUMN)->colId == pMsg->colId) {
|
|
||||||
tsdbAddTableIntoIndex(pMeta, pTable);
|
|
||||||
}
|
}
|
||||||
return TSDB_CODE_SUCCESS;
|
|
||||||
|
// Update on file
|
||||||
|
int tlen1 = (pNewSchema) ? tsdbGetTableEncodeSize(TSDB_UPDATE_META, pTable->pSuper) : 0;
|
||||||
|
int tlen2 = tsdbGetTableEncodeSize(TSDB_UPDATE_META, pTable);
|
||||||
|
void *buf = tsdbAllocBytes(pRepo, tlen1+tlen2);
|
||||||
|
ASSERT(buf != NULL);
|
||||||
|
if (pNewSchema) {
|
||||||
|
void *pBuf = tsdbInsertTableAct(pRepo, TSDB_UPDATE_META, buf, pTable->pSuper);
|
||||||
|
ASSERT(POINTER_DISTANCE(pBuf, buf) == tlen1);
|
||||||
|
buf = pBuf;
|
||||||
|
}
|
||||||
|
tsdbInsertTableAct(pRepo, TSDB_UPDATE_META, buf, pTable);
|
||||||
|
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
// ------------------ INTERNAL FUNCTIONS ------------------
|
// ------------------ INTERNAL FUNCTIONS ------------------
|
||||||
|
@ -449,18 +480,6 @@ int tsdbCloseMeta(STsdbRepo *pRepo) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
STSchema *tsdbGetTableSchema(STable *pTable) {
|
|
||||||
if (pTable->type == TSDB_NORMAL_TABLE || pTable->type == TSDB_SUPER_TABLE || pTable->type == TSDB_STREAM_TABLE) {
|
|
||||||
return pTable->schema[pTable->numOfSchemas - 1];
|
|
||||||
} else if (pTable->type == TSDB_CHILD_TABLE) {
|
|
||||||
STable *pSuper = pTable->pSuper;
|
|
||||||
if (pSuper == NULL) return NULL;
|
|
||||||
return pSuper->schema[pSuper->numOfSchemas - 1];
|
|
||||||
} else {
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
STable *tsdbGetTableByUid(STsdbMeta *pMeta, uint64_t uid) {
|
STable *tsdbGetTableByUid(STsdbMeta *pMeta, uint64_t uid) {
|
||||||
void *ptr = taosHashGet(pMeta->uidMap, (char *)(&uid), sizeof(uid));
|
void *ptr = taosHashGet(pMeta->uidMap, (char *)(&uid), sizeof(uid));
|
||||||
|
|
||||||
|
@ -470,68 +489,7 @@ STable *tsdbGetTableByUid(STsdbMeta *pMeta, uint64_t uid) {
|
||||||
}
|
}
|
||||||
|
|
||||||
STSchema *tsdbGetTableSchemaByVersion(STable *pTable, int16_t version) {
|
STSchema *tsdbGetTableSchemaByVersion(STable *pTable, int16_t version) {
|
||||||
STable *pSearchTable = (pTable->type == TSDB_CHILD_TABLE) ? pTable->pSuper : pTable;
|
return tsdbGetTableSchemaImpl(pTable, true, false, version);
|
||||||
if (pSearchTable == NULL) return NULL;
|
|
||||||
|
|
||||||
void *ptr = taosbsearch(&version, pSearchTable->schema, pSearchTable->numOfSchemas, sizeof(STSchema *),
|
|
||||||
tsdbCompareSchemaVersion, TD_EQ);
|
|
||||||
if (ptr == NULL) return NULL;
|
|
||||||
|
|
||||||
return *(STSchema **)ptr;
|
|
||||||
}
|
|
||||||
|
|
||||||
STSchema *tsdbGetTableTagSchema(STable *pTable) {
|
|
||||||
if (pTable->type == TSDB_SUPER_TABLE) {
|
|
||||||
return pTable->tagSchema;
|
|
||||||
} else if (pTable->type == TSDB_CHILD_TABLE) {
|
|
||||||
STable *pSuper = pTable->pSuper;
|
|
||||||
if (pSuper == NULL) return NULL;
|
|
||||||
return pSuper->tagSchema;
|
|
||||||
} else {
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
int tsdbUpdateTable(STsdbRepo *pRepo, STable *pTable, STableCfg *pCfg) {
|
|
||||||
// TODO: this function can only be called when there is no query and commit on this table
|
|
||||||
ASSERT(TABLE_TYPE(pTable) != TSDB_CHILD_TABLE);
|
|
||||||
bool changed = false;
|
|
||||||
STsdbMeta *pMeta = pRepo->tsdbMeta;
|
|
||||||
|
|
||||||
if ((pTable->type == TSDB_SUPER_TABLE) && (schemaVersion(pTable->tagSchema) < schemaVersion(pCfg->tagSchema))) {
|
|
||||||
if (tsdbUpdateTableTagSchema(pTable, pCfg->tagSchema) < 0) {
|
|
||||||
tsdbError("vgId:%d failed to update table %s tag schema since %s", REPO_ID(pRepo), TABLE_CHAR_NAME(pTable),
|
|
||||||
tstrerror(terrno));
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
changed = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
STSchema *pTSchema = tsdbGetTableSchema(pTable);
|
|
||||||
if (schemaVersion(pTSchema) < schemaVersion(pCfg->schema)) {
|
|
||||||
if (pTable->numOfSchemas < TSDB_MAX_TABLE_SCHEMAS) {
|
|
||||||
pTable->schema[pTable->numOfSchemas++] = tdDupSchema(pCfg->schema);
|
|
||||||
} else {
|
|
||||||
ASSERT(pTable->numOfSchemas == TSDB_MAX_TABLE_SCHEMAS);
|
|
||||||
STSchema *tSchema = tdDupSchema(pCfg->schema);
|
|
||||||
tdFreeSchema(pTable->schema[0]);
|
|
||||||
memmove(pTable->schema, pTable->schema + 1, sizeof(STSchema *) * (TSDB_MAX_TABLE_SCHEMAS - 1));
|
|
||||||
pTable->schema[pTable->numOfSchemas - 1] = tSchema;
|
|
||||||
}
|
|
||||||
|
|
||||||
pMeta->maxRowBytes = MAX(pMeta->maxRowBytes, dataRowMaxBytesFromSchema(pCfg->schema));
|
|
||||||
pMeta->maxCols = MAX(pMeta->maxCols, schemaNCols(pCfg->schema));
|
|
||||||
|
|
||||||
changed = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (changed) {
|
|
||||||
int tlen = tsdbGetTableEncodeSize(TSDB_UPDATE_META, pTable);
|
|
||||||
void *buf = tsdbAllocBytes(pRepo, tlen);
|
|
||||||
tsdbInsertTableAct(pRepo, TSDB_UPDATE_META, buf, pTable);
|
|
||||||
}
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int tsdbWLockRepoMeta(STsdbRepo *pRepo) {
|
int tsdbWLockRepoMeta(STsdbRepo *pRepo) {
|
||||||
|
@ -575,7 +533,7 @@ void tsdbRefTable(STable *pTable) {
|
||||||
|
|
||||||
void tsdbUnRefTable(STable *pTable) {
|
void tsdbUnRefTable(STable *pTable) {
|
||||||
int32_t ref = T_REF_DEC(pTable);
|
int32_t ref = T_REF_DEC(pTable);
|
||||||
tsdbTrace("unref table uid:%"PRIu64", tid:%d, refCount:%d", TABLE_UID(pTable), TABLE_TID(pTable), ref);
|
tsdbDebug("unref table uid:%"PRIu64", tid:%d, refCount:%d", TABLE_UID(pTable), TABLE_TID(pTable), ref);
|
||||||
|
|
||||||
if (ref == 0) {
|
if (ref == 0) {
|
||||||
// tsdbDebug("destory table name:%s uid:%"PRIu64", tid:%d", TABLE_CHAR_NAME(pTable), TABLE_UID(pTable), TABLE_TID(pTable));
|
// tsdbDebug("destory table name:%s uid:%"PRIu64", tid:%d", TABLE_CHAR_NAME(pTable), TABLE_UID(pTable), TABLE_TID(pTable));
|
||||||
|
@ -587,17 +545,36 @@ void tsdbUnRefTable(STable *pTable) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// ------------------ LOCAL FUNCTIONS ------------------
|
void tsdbUpdateTableSchema(STsdbRepo *pRepo, STable *pTable, STSchema *pSchema, bool insertAct) {
|
||||||
static int tsdbCompareSchemaVersion(const void *key1, const void *key2) {
|
ASSERT(TABLE_TYPE(pTable) != TSDB_STREAM_TABLE && TABLE_TYPE(pTable) != TSDB_SUPER_TABLE);
|
||||||
if (*(int16_t *)key1 < schemaVersion(*(STSchema **)key2)) {
|
STsdbMeta *pMeta = pRepo->tsdbMeta;
|
||||||
return -1;
|
|
||||||
} else if (*(int16_t *)key1 > schemaVersion(*(STSchema **)key2)) {
|
STable *pCTable = (TABLE_TYPE(pTable) == TSDB_CHILD_TABLE) ? pTable->pSuper : pTable;
|
||||||
return 1;
|
ASSERT(schemaVersion(pSchema) > schemaVersion(pCTable->schema[pCTable->numOfSchemas - 1]));
|
||||||
|
|
||||||
|
taosWLockLatch(&(pCTable->latch));
|
||||||
|
if (pCTable->numOfSchemas < TSDB_MAX_TABLE_SCHEMAS) {
|
||||||
|
pCTable->schema[pCTable->numOfSchemas++] = pSchema;
|
||||||
} else {
|
} else {
|
||||||
return 0;
|
ASSERT(pCTable->numOfSchemas == TSDB_MAX_TABLE_SCHEMAS);
|
||||||
|
tdFreeSchema(pCTable->schema[0]);
|
||||||
|
memmove(pCTable->schema, pCTable->schema + 1, sizeof(STSchema *) * (TSDB_MAX_TABLE_SCHEMAS - 1));
|
||||||
|
pCTable->schema[pCTable->numOfSchemas - 1] = pSchema;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (schemaNCols(pSchema) > pMeta->maxCols) pMeta->maxCols = schemaNCols(pSchema);
|
||||||
|
if (schemaTLen(pSchema) > pMeta->maxRowBytes) pMeta->maxRowBytes = schemaTLen(pSchema);
|
||||||
|
taosWUnLockLatch(&(pCTable->latch));
|
||||||
|
|
||||||
|
if (insertAct) {
|
||||||
|
int tlen = tsdbGetTableEncodeSize(TSDB_UPDATE_META, pCTable);
|
||||||
|
void *buf = tsdbAllocBytes(pRepo, tlen);
|
||||||
|
ASSERT(buf != NULL);
|
||||||
|
tsdbInsertTableAct(pRepo, TSDB_UPDATE_META, buf, pTable);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ------------------ LOCAL FUNCTIONS ------------------
|
||||||
static int tsdbRestoreTable(void *pHandle, void *cont, int contLen) {
|
static int tsdbRestoreTable(void *pHandle, void *cont, int contLen) {
|
||||||
STsdbRepo *pRepo = (STsdbRepo *)pHandle;
|
STsdbRepo *pRepo = (STsdbRepo *)pHandle;
|
||||||
STable * pTable = NULL;
|
STable * pTable = NULL;
|
||||||
|
@ -609,7 +586,7 @@ static int tsdbRestoreTable(void *pHandle, void *cont, int contLen) {
|
||||||
|
|
||||||
tsdbDecodeTable(cont, &pTable);
|
tsdbDecodeTable(cont, &pTable);
|
||||||
|
|
||||||
if (tsdbAddTableToMeta(pRepo, pTable, false) < 0) {
|
if (tsdbAddTableToMeta(pRepo, pTable, false, false) < 0) {
|
||||||
tsdbFreeTable(pTable);
|
tsdbFreeTable(pTable);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
@ -627,7 +604,7 @@ static void tsdbOrgMeta(void *pHandle) {
|
||||||
for (int i = 1; i < pCfg->maxTables; i++) {
|
for (int i = 1; i < pCfg->maxTables; i++) {
|
||||||
STable *pTable = pMeta->tables[i];
|
STable *pTable = pMeta->tables[i];
|
||||||
if (pTable != NULL && pTable->type == TSDB_CHILD_TABLE) {
|
if (pTable != NULL && pTable->type == TSDB_CHILD_TABLE) {
|
||||||
tsdbAddTableIntoIndex(pMeta, pTable);
|
tsdbAddTableIntoIndex(pMeta, pTable, true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -737,7 +714,7 @@ _err:
|
||||||
|
|
||||||
static void tsdbFreeTable(STable *pTable) {
|
static void tsdbFreeTable(STable *pTable) {
|
||||||
if (pTable) {
|
if (pTable) {
|
||||||
tsdbDebug("table %s is destroyed", TABLE_CHAR_NAME(pTable));
|
if (pTable->name != NULL) tsdbDebug("table %s is destroyed", TABLE_CHAR_NAME(pTable));
|
||||||
tfree(TABLE_NAME(pTable));
|
tfree(TABLE_NAME(pTable));
|
||||||
if (TABLE_TYPE(pTable) != TSDB_CHILD_TABLE) {
|
if (TABLE_TYPE(pTable) != TSDB_CHILD_TABLE) {
|
||||||
for (int i = 0; i < TSDB_MAX_TABLE_SCHEMAS; i++) {
|
for (int i = 0; i < TSDB_MAX_TABLE_SCHEMAS; i++) {
|
||||||
|
@ -757,25 +734,10 @@ static void tsdbFreeTable(STable *pTable) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static int tsdbUpdateTableTagSchema(STable *pTable, STSchema *newSchema) {
|
static int tsdbAddTableToMeta(STsdbRepo *pRepo, STable *pTable, bool addIdx, bool lock) {
|
||||||
ASSERT(pTable->type == TSDB_SUPER_TABLE);
|
|
||||||
ASSERT(schemaVersion(pTable->tagSchema) < schemaVersion(newSchema));
|
|
||||||
STSchema *pOldSchema = pTable->tagSchema;
|
|
||||||
STSchema *pNewSchema = tdDupSchema(newSchema);
|
|
||||||
if (pNewSchema == NULL) {
|
|
||||||
terrno = TSDB_CODE_TDB_OUT_OF_MEMORY;
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
pTable->tagSchema = pNewSchema;
|
|
||||||
tdFreeSchema(pOldSchema);
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
static int tsdbAddTableToMeta(STsdbRepo *pRepo, STable *pTable, bool addIdx) {
|
|
||||||
STsdbMeta *pMeta = pRepo->tsdbMeta;
|
STsdbMeta *pMeta = pRepo->tsdbMeta;
|
||||||
|
|
||||||
if (addIdx && tsdbWLockRepoMeta(pRepo) < 0) {
|
if (lock && tsdbWLockRepoMeta(pRepo) < 0) {
|
||||||
tsdbError("vgId:%d failed to add table %s to meta since %s", REPO_ID(pRepo), TABLE_CHAR_NAME(pTable),
|
tsdbError("vgId:%d failed to add table %s to meta since %s", REPO_ID(pRepo), TABLE_CHAR_NAME(pTable),
|
||||||
tstrerror(terrno));
|
tstrerror(terrno));
|
||||||
return -1;
|
return -1;
|
||||||
|
@ -790,7 +752,7 @@ static int tsdbAddTableToMeta(STsdbRepo *pRepo, STable *pTable, bool addIdx) {
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (TABLE_TYPE(pTable) == TSDB_CHILD_TABLE && addIdx) { // add STABLE to the index
|
if (TABLE_TYPE(pTable) == TSDB_CHILD_TABLE && addIdx) { // add STABLE to the index
|
||||||
if (tsdbAddTableIntoIndex(pMeta, pTable) < 0) {
|
if (tsdbAddTableIntoIndex(pMeta, pTable, true) < 0) {
|
||||||
tsdbDebug("vgId:%d failed to add table %s to meta while add table to index since %s", REPO_ID(pRepo),
|
tsdbDebug("vgId:%d failed to add table %s to meta while add table to index since %s", REPO_ID(pRepo),
|
||||||
TABLE_CHAR_NAME(pTable), tstrerror(terrno));
|
TABLE_CHAR_NAME(pTable), tstrerror(terrno));
|
||||||
goto _err;
|
goto _err;
|
||||||
|
@ -809,14 +771,15 @@ static int tsdbAddTableToMeta(STsdbRepo *pRepo, STable *pTable, bool addIdx) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (TABLE_TYPE(pTable) != TSDB_CHILD_TABLE) {
|
if (TABLE_TYPE(pTable) != TSDB_CHILD_TABLE) {
|
||||||
STSchema *pSchema = tsdbGetTableSchema(pTable);
|
STSchema *pSchema = tsdbGetTableSchemaImpl(pTable, false, false, -1);
|
||||||
if (schemaNCols(pSchema) > pMeta->maxCols) pMeta->maxCols = schemaNCols(pSchema);
|
if (schemaNCols(pSchema) > pMeta->maxCols) pMeta->maxCols = schemaNCols(pSchema);
|
||||||
if (schemaTLen(pSchema) > pMeta->maxRowBytes) pMeta->maxRowBytes = schemaTLen(pSchema);
|
if (schemaTLen(pSchema) > pMeta->maxRowBytes) pMeta->maxRowBytes = schemaTLen(pSchema);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (addIdx && tsdbUnlockRepoMeta(pRepo) < 0) return -1;
|
if (lock && tsdbUnlockRepoMeta(pRepo) < 0) return -1;
|
||||||
if (TABLE_TYPE(pTable) == TSDB_STREAM_TABLE && addIdx) {
|
if (TABLE_TYPE(pTable) == TSDB_STREAM_TABLE && addIdx) {
|
||||||
pTable->cqhandle = (*pRepo->appH.cqCreateFunc)(pRepo->appH.cqH, TABLE_UID(pTable), TABLE_TID(pTable), pTable->sql, tsdbGetTableSchema(pTable));
|
pTable->cqhandle = (*pRepo->appH.cqCreateFunc)(pRepo->appH.cqH, TABLE_UID(pTable), TABLE_TID(pTable), pTable->sql,
|
||||||
|
tsdbGetTableSchemaImpl(pTable, false, false, -1));
|
||||||
}
|
}
|
||||||
|
|
||||||
tsdbTrace("vgId:%d table %s tid %d uid %" PRIu64 " is added to meta", REPO_ID(pRepo), TABLE_CHAR_NAME(pTable),
|
tsdbTrace("vgId:%d table %s tid %d uid %" PRIu64 " is added to meta", REPO_ID(pRepo), TABLE_CHAR_NAME(pTable),
|
||||||
|
@ -825,7 +788,7 @@ static int tsdbAddTableToMeta(STsdbRepo *pRepo, STable *pTable, bool addIdx) {
|
||||||
|
|
||||||
_err:
|
_err:
|
||||||
tsdbRemoveTableFromMeta(pRepo, pTable, false, false);
|
tsdbRemoveTableFromMeta(pRepo, pTable, false, false);
|
||||||
if (addIdx) tsdbUnlockRepoMeta(pRepo);
|
if (lock) tsdbUnlockRepoMeta(pRepo);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -836,7 +799,7 @@ static void tsdbRemoveTableFromMeta(STsdbRepo *pRepo, STable *pTable, bool rmFro
|
||||||
STable * tTable = NULL;
|
STable * tTable = NULL;
|
||||||
STsdbCfg * pCfg = &(pRepo->config);
|
STsdbCfg * pCfg = &(pRepo->config);
|
||||||
|
|
||||||
STSchema *pSchema = tsdbGetTableSchema(pTable);
|
STSchema *pSchema = tsdbGetTableSchemaImpl(pTable, false, false, -1);
|
||||||
int maxCols = schemaNCols(pSchema);
|
int maxCols = schemaNCols(pSchema);
|
||||||
int maxRowBytes = schemaTLen(pSchema);
|
int maxRowBytes = schemaTLen(pSchema);
|
||||||
|
|
||||||
|
@ -870,7 +833,7 @@ static void tsdbRemoveTableFromMeta(STsdbRepo *pRepo, STable *pTable, bool rmFro
|
||||||
for (int i = 0; i < pCfg->maxTables; i++) {
|
for (int i = 0; i < pCfg->maxTables; i++) {
|
||||||
STable *pTable = pMeta->tables[i];
|
STable *pTable = pMeta->tables[i];
|
||||||
if (pTable != NULL) {
|
if (pTable != NULL) {
|
||||||
pSchema = tsdbGetTableSchema(pTable);
|
pSchema = tsdbGetTableSchemaImpl(pTable, false, false, -1);
|
||||||
maxCols = MAX(maxCols, schemaNCols(pSchema));
|
maxCols = MAX(maxCols, schemaNCols(pSchema));
|
||||||
maxRowBytes = MAX(maxRowBytes, schemaTLen(pSchema));
|
maxRowBytes = MAX(maxRowBytes, schemaTLen(pSchema));
|
||||||
}
|
}
|
||||||
|
@ -882,7 +845,7 @@ static void tsdbRemoveTableFromMeta(STsdbRepo *pRepo, STable *pTable, bool rmFro
|
||||||
tsdbUnRefTable(pTable);
|
tsdbUnRefTable(pTable);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int tsdbAddTableIntoIndex(STsdbMeta *pMeta, STable *pTable) {
|
static int tsdbAddTableIntoIndex(STsdbMeta *pMeta, STable *pTable, bool refSuper) {
|
||||||
ASSERT(pTable->type == TSDB_CHILD_TABLE && pTable != NULL);
|
ASSERT(pTable->type == TSDB_CHILD_TABLE && pTable != NULL);
|
||||||
STable *pSTable = tsdbGetTableByUid(pMeta, TABLE_SUID(pTable));
|
STable *pSTable = tsdbGetTableByUid(pMeta, TABLE_SUID(pTable));
|
||||||
ASSERT(pSTable != NULL);
|
ASSERT(pSTable != NULL);
|
||||||
|
@ -906,7 +869,7 @@ static int tsdbAddTableIntoIndex(STsdbMeta *pMeta, STable *pTable) {
|
||||||
memcpy(SL_GET_NODE_DATA(pNode), &pTable, sizeof(STable *));
|
memcpy(SL_GET_NODE_DATA(pNode), &pTable, sizeof(STable *));
|
||||||
|
|
||||||
tSkipListPut(pSTable->pIndex, pNode);
|
tSkipListPut(pSTable->pIndex, pNode);
|
||||||
T_REF_INC(pSTable);
|
if (refSuper) T_REF_INC(pSTable);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -218,7 +218,7 @@ void tsdbSetHelperTable(SRWHelper *pHelper, STable *pTable, STsdbRepo *pRepo) {
|
||||||
|
|
||||||
pHelper->tableInfo.tid = pTable->tableId.tid;
|
pHelper->tableInfo.tid = pTable->tableId.tid;
|
||||||
pHelper->tableInfo.uid = pTable->tableId.uid;
|
pHelper->tableInfo.uid = pTable->tableId.uid;
|
||||||
STSchema *pSchema = tsdbGetTableSchema(pTable);
|
STSchema *pSchema = tsdbGetTableSchemaImpl(pTable, false, false, -1);
|
||||||
pHelper->tableInfo.sversion = schemaVersion(pSchema);
|
pHelper->tableInfo.sversion = schemaVersion(pSchema);
|
||||||
|
|
||||||
tdInitDataCols(pHelper->pDataCols[0], pSchema);
|
tdInitDataCols(pHelper->pDataCols[0], pSchema);
|
||||||
|
@ -318,7 +318,7 @@ int tsdbMoveLastBlockIfNeccessary(SRWHelper *pHelper) {
|
||||||
ASSERT(pCompBlock->last);
|
ASSERT(pCompBlock->last);
|
||||||
|
|
||||||
if (pCompBlock->numOfSubBlocks > 1) {
|
if (pCompBlock->numOfSubBlocks > 1) {
|
||||||
if (tsdbLoadBlockData(pHelper, blockAtIdx(pHelper, pIdx->numOfBlocks - 1)) < 0) return -1;
|
if (tsdbLoadBlockData(pHelper, blockAtIdx(pHelper, pIdx->numOfBlocks - 1), NULL) < 0) return -1;
|
||||||
ASSERT(pHelper->pDataCols[0]->numOfRows > 0 && pHelper->pDataCols[0]->numOfRows < pCfg->minRowsPerFileBlock);
|
ASSERT(pHelper->pDataCols[0]->numOfRows > 0 && pHelper->pDataCols[0]->numOfRows < pCfg->minRowsPerFileBlock);
|
||||||
if (tsdbWriteBlockToFile(pHelper, &(pHelper->files.nLastF), pHelper->pDataCols[0],
|
if (tsdbWriteBlockToFile(pHelper, &(pHelper->files.nLastF), pHelper->pDataCols[0],
|
||||||
pHelper->pDataCols[0]->numOfRows, &compBlock, true, true) < 0)
|
pHelper->pDataCols[0]->numOfRows, &compBlock, true, true) < 0)
|
||||||
|
@ -577,11 +577,12 @@ void tsdbGetDataStatis(SRWHelper *pHelper, SDataStatis *pStatis, int numOfCols)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int tsdbLoadBlockDataCols(SRWHelper *pHelper, SCompBlock *pCompBlock, int16_t *colIds, int numOfColIds) {
|
int tsdbLoadBlockDataCols(SRWHelper *pHelper, SCompBlock *pCompBlock, SCompInfo *pCompInfo, int16_t *colIds, int numOfColIds) {
|
||||||
ASSERT(pCompBlock->numOfSubBlocks >= 1); // Must be super block
|
ASSERT(pCompBlock->numOfSubBlocks >= 1); // Must be super block
|
||||||
|
|
||||||
int numOfSubBlocks = pCompBlock->numOfSubBlocks;
|
int numOfSubBlocks = pCompBlock->numOfSubBlocks;
|
||||||
if (numOfSubBlocks > 1) pCompBlock = (SCompBlock *)POINTER_SHIFT(pHelper->pCompInfo, pCompBlock->offset);
|
if (numOfSubBlocks > 1)
|
||||||
|
pCompBlock = (SCompBlock *)POINTER_SHIFT((pCompInfo == NULL) ? pHelper->pCompInfo : pCompInfo, pCompBlock->offset);
|
||||||
|
|
||||||
tdResetDataCols(pHelper->pDataCols[0]);
|
tdResetDataCols(pHelper->pDataCols[0]);
|
||||||
if (tsdbLoadBlockDataColsImpl(pHelper, pCompBlock, pHelper->pDataCols[0], colIds, numOfColIds) < 0) goto _err;
|
if (tsdbLoadBlockDataColsImpl(pHelper, pCompBlock, pHelper->pDataCols[0], colIds, numOfColIds) < 0) goto _err;
|
||||||
|
@ -598,10 +599,10 @@ _err:
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
int tsdbLoadBlockData(SRWHelper *pHelper, SCompBlock *pCompBlock) {
|
int tsdbLoadBlockData(SRWHelper *pHelper, SCompBlock *pCompBlock, SCompInfo *pCompInfo) {
|
||||||
|
|
||||||
int numOfSubBlock = pCompBlock->numOfSubBlocks;
|
int numOfSubBlock = pCompBlock->numOfSubBlocks;
|
||||||
if (numOfSubBlock > 1) pCompBlock = (SCompBlock *)POINTER_SHIFT(pHelper->pCompInfo, pCompBlock->offset);
|
if (numOfSubBlock > 1)
|
||||||
|
pCompBlock = (SCompBlock *)POINTER_SHIFT((pCompInfo == NULL) ? pHelper->pCompInfo : pCompInfo, pCompBlock->offset);
|
||||||
|
|
||||||
tdResetDataCols(pHelper->pDataCols[0]);
|
tdResetDataCols(pHelper->pDataCols[0]);
|
||||||
if (tsdbLoadBlockDataImpl(pHelper, pCompBlock, pHelper->pDataCols[0]) < 0) goto _err;
|
if (tsdbLoadBlockDataImpl(pHelper, pCompBlock, pHelper->pDataCols[0]) < 0) goto _err;
|
||||||
|
@ -703,6 +704,7 @@ static int tsdbWriteBlockToFile(SRWHelper *pHelper, SFile *pFile, SDataCols *pDa
|
||||||
}
|
}
|
||||||
|
|
||||||
// Add checksum
|
// Add checksum
|
||||||
|
ASSERT(pCompCol->len > 0);
|
||||||
pCompCol->len += sizeof(TSCKSUM);
|
pCompCol->len += sizeof(TSCKSUM);
|
||||||
taosCalcChecksumAppend(0, (uint8_t *)tptr, pCompCol->len);
|
taosCalcChecksumAppend(0, (uint8_t *)tptr, pCompCol->len);
|
||||||
|
|
||||||
|
@ -792,7 +794,7 @@ static int tsdbMergeDataWithBlock(SRWHelper *pHelper, int blkIdx, SDataCols *pDa
|
||||||
if (tsdbAddSubBlock(pHelper, &compBlock, blkIdx, rowsWritten) < 0) goto _err;
|
if (tsdbAddSubBlock(pHelper, &compBlock, blkIdx, rowsWritten) < 0) goto _err;
|
||||||
} else {
|
} else {
|
||||||
// Load
|
// Load
|
||||||
if (tsdbLoadBlockData(pHelper, blockAtIdx(pHelper, blkIdx)) < 0) goto _err;
|
if (tsdbLoadBlockData(pHelper, blockAtIdx(pHelper, blkIdx), NULL) < 0) goto _err;
|
||||||
ASSERT(pHelper->pDataCols[0]->numOfRows <= blockAtIdx(pHelper, blkIdx)->numOfRows);
|
ASSERT(pHelper->pDataCols[0]->numOfRows <= blockAtIdx(pHelper, blkIdx)->numOfRows);
|
||||||
// Merge
|
// Merge
|
||||||
if (tdMergeDataCols(pHelper->pDataCols[0], pDataCols, rowsWritten) < 0) goto _err;
|
if (tdMergeDataCols(pHelper->pDataCols[0], pDataCols, rowsWritten) < 0) goto _err;
|
||||||
|
@ -848,7 +850,7 @@ static int tsdbMergeDataWithBlock(SRWHelper *pHelper, int blkIdx, SDataCols *pDa
|
||||||
if (tsdbAddSubBlock(pHelper, &compBlock, blkIdx, rowsWritten) < 0) goto _err;
|
if (tsdbAddSubBlock(pHelper, &compBlock, blkIdx, rowsWritten) < 0) goto _err;
|
||||||
} else { // Load-Merge-Write
|
} else { // Load-Merge-Write
|
||||||
// Load
|
// Load
|
||||||
if (tsdbLoadBlockData(pHelper, blockAtIdx(pHelper, blkIdx)) < 0) goto _err;
|
if (tsdbLoadBlockData(pHelper, blockAtIdx(pHelper, blkIdx), NULL) < 0) goto _err;
|
||||||
if (blockAtIdx(pHelper, blkIdx)->last) pHelper->hasOldLastBlock = false;
|
if (blockAtIdx(pHelper, blkIdx)->last) pHelper->hasOldLastBlock = false;
|
||||||
|
|
||||||
rowsWritten = rows3;
|
rowsWritten = rows3;
|
||||||
|
|
|
@ -22,7 +22,7 @@
|
||||||
#include "exception.h"
|
#include "exception.h"
|
||||||
|
|
||||||
#include "../../../query/inc/qast.h" // todo move to common module
|
#include "../../../query/inc/qast.h" // todo move to common module
|
||||||
#include "../../../query/inc/tlosertree.h" // todo move to util module
|
#include "tlosertree.h"
|
||||||
#include "tsdb.h"
|
#include "tsdb.h"
|
||||||
#include "tsdbMain.h"
|
#include "tsdbMain.h"
|
||||||
|
|
||||||
|
@ -122,7 +122,7 @@ static void changeQueryHandleForInterpQuery(TsdbQueryHandleT pHandle);
|
||||||
static void doMergeTwoLevelData(STsdbQueryHandle* pQueryHandle, STableCheckInfo* pCheckInfo, SCompBlock* pBlock,
|
static void doMergeTwoLevelData(STsdbQueryHandle* pQueryHandle, STableCheckInfo* pCheckInfo, SCompBlock* pBlock,
|
||||||
SArray* sa);
|
SArray* sa);
|
||||||
static int32_t binarySearchForKey(char* pValue, int num, TSKEY key, int order);
|
static int32_t binarySearchForKey(char* pValue, int num, TSKEY key, int order);
|
||||||
static int tsdbReadRowsFromCache(STableCheckInfo* pCheckInfo, TSKEY maxKey, int maxRowsToRead, TSKEY* skey, TSKEY* ekey,
|
static int tsdbReadRowsFromCache(STableCheckInfo* pCheckInfo, TSKEY maxKey, int maxRowsToRead, STimeWindow* win,
|
||||||
STsdbQueryHandle* pQueryHandle);
|
STsdbQueryHandle* pQueryHandle);
|
||||||
|
|
||||||
static void tsdbInitDataBlockLoadInfo(SDataBlockLoadInfo* pBlockLoadInfo) {
|
static void tsdbInitDataBlockLoadInfo(SDataBlockLoadInfo* pBlockLoadInfo) {
|
||||||
|
@ -249,8 +249,6 @@ static bool initTableMemIterator(STsdbQueryHandle* pHandle, STableCheckInfo* pCh
|
||||||
pCheckInfo->initBuf = true;
|
pCheckInfo->initBuf = true;
|
||||||
int32_t order = pHandle->order;
|
int32_t order = pHandle->order;
|
||||||
|
|
||||||
// tsdbTakeMemSnapshot(pHandle->pTsdb, &pCheckInfo->mem, &pCheckInfo->imem);
|
|
||||||
|
|
||||||
// no data in buffer, abort
|
// no data in buffer, abort
|
||||||
if (pHandle->mem == NULL && pHandle->imem == NULL) {
|
if (pHandle->mem == NULL && pHandle->imem == NULL) {
|
||||||
return false;
|
return false;
|
||||||
|
@ -393,7 +391,10 @@ static bool hasMoreDataInCache(STsdbQueryHandle* pHandle) {
|
||||||
STable* pTable = pCheckInfo->pTableObj;
|
STable* pTable = pCheckInfo->pTableObj;
|
||||||
assert(pTable != NULL);
|
assert(pTable != NULL);
|
||||||
|
|
||||||
initTableMemIterator(pHandle, pCheckInfo);
|
if (!pCheckInfo->initBuf) {
|
||||||
|
initTableMemIterator(pHandle, pCheckInfo);
|
||||||
|
}
|
||||||
|
|
||||||
SDataRow row = getSDataRowInTableMem(pCheckInfo);
|
SDataRow row = getSDataRowInTableMem(pCheckInfo);
|
||||||
if (row == NULL) {
|
if (row == NULL) {
|
||||||
return false;
|
return false;
|
||||||
|
@ -411,8 +412,7 @@ static bool hasMoreDataInCache(STsdbQueryHandle* pHandle) {
|
||||||
|
|
||||||
int32_t step = ASCENDING_TRAVERSE(pHandle->order)? 1:-1;
|
int32_t step = ASCENDING_TRAVERSE(pHandle->order)? 1:-1;
|
||||||
STimeWindow* win = &pHandle->cur.win;
|
STimeWindow* win = &pHandle->cur.win;
|
||||||
pHandle->cur.rows = tsdbReadRowsFromCache(pCheckInfo, pHandle->window.ekey,
|
pHandle->cur.rows = tsdbReadRowsFromCache(pCheckInfo, pHandle->window.ekey, pHandle->outputCapacity, win, pHandle);
|
||||||
pHandle->outputCapacity, &win->skey, &win->ekey, pHandle); // todo refactor API
|
|
||||||
|
|
||||||
// update the last key value
|
// update the last key value
|
||||||
pCheckInfo->lastKey = win->ekey + step;
|
pCheckInfo->lastKey = win->ekey + step;
|
||||||
|
@ -576,6 +576,8 @@ static SArray* getDefaultLoadColumns(STsdbQueryHandle* pQueryHandle, bool loadTS
|
||||||
|
|
||||||
static bool doLoadFileDataBlock(STsdbQueryHandle* pQueryHandle, SCompBlock* pBlock, STableCheckInfo* pCheckInfo) {
|
static bool doLoadFileDataBlock(STsdbQueryHandle* pQueryHandle, SCompBlock* pBlock, STableCheckInfo* pCheckInfo) {
|
||||||
STsdbRepo *pRepo = pQueryHandle->pTsdb;
|
STsdbRepo *pRepo = pQueryHandle->pTsdb;
|
||||||
|
|
||||||
|
// TODO refactor
|
||||||
SCompData* data = calloc(1, sizeof(SCompData) + sizeof(SCompCol) * pBlock->numOfCols);
|
SCompData* data = calloc(1, sizeof(SCompData) + sizeof(SCompCol) * pBlock->numOfCols);
|
||||||
|
|
||||||
data->numOfCols = pBlock->numOfCols;
|
data->numOfCols = pBlock->numOfCols;
|
||||||
|
@ -592,9 +594,12 @@ static bool doLoadFileDataBlock(STsdbQueryHandle* pQueryHandle, SCompBlock* pBlo
|
||||||
pCheckInfo->pDataCols = tdNewDataCols(pMeta->maxRowBytes, pMeta->maxCols, pRepo->config.maxRowsPerFileBlock);
|
pCheckInfo->pDataCols = tdNewDataCols(pMeta->maxRowBytes, pMeta->maxCols, pRepo->config.maxRowsPerFileBlock);
|
||||||
}
|
}
|
||||||
|
|
||||||
tdInitDataCols(pCheckInfo->pDataCols, tsdbGetTableSchema(pCheckInfo->pTableObj));
|
STSchema* pSchema = tsdbGetTableSchema(pCheckInfo->pTableObj);
|
||||||
|
tdInitDataCols(pCheckInfo->pDataCols, pSchema);
|
||||||
|
tdInitDataCols(pQueryHandle->rhelper.pDataCols[0], pSchema);
|
||||||
|
tdInitDataCols(pQueryHandle->rhelper.pDataCols[1], pSchema);
|
||||||
|
|
||||||
if (tsdbLoadBlockData(&(pQueryHandle->rhelper), pBlock) == 0) {
|
if (tsdbLoadBlockData(&(pQueryHandle->rhelper), pBlock, pCheckInfo->pCompInfo) == 0) {
|
||||||
SDataBlockLoadInfo* pBlockLoadInfo = &pQueryHandle->dataBlockLoadInfo;
|
SDataBlockLoadInfo* pBlockLoadInfo = &pQueryHandle->dataBlockLoadInfo;
|
||||||
|
|
||||||
pBlockLoadInfo->fileGroup = pQueryHandle->pFileGroup;
|
pBlockLoadInfo->fileGroup = pQueryHandle->pFileGroup;
|
||||||
|
@ -605,8 +610,9 @@ static bool doLoadFileDataBlock(STsdbQueryHandle* pQueryHandle, SCompBlock* pBlo
|
||||||
}
|
}
|
||||||
|
|
||||||
SDataCols* pCols = pQueryHandle->rhelper.pDataCols[0];
|
SDataCols* pCols = pQueryHandle->rhelper.pDataCols[0];
|
||||||
assert(pCols->numOfRows != 0);
|
assert(pCols->numOfRows != 0 && pCols->numOfRows <= pBlock->numOfRows);
|
||||||
|
|
||||||
|
pBlock->numOfRows = pCols->numOfRows;
|
||||||
taosArrayDestroy(sa);
|
taosArrayDestroy(sa);
|
||||||
tfree(data);
|
tfree(data);
|
||||||
|
|
||||||
|
@ -636,7 +642,7 @@ static void handleDataMergeIfNeeded(STsdbQueryHandle* pQueryHandle, SCompBlock*
|
||||||
int32_t step = ASCENDING_TRAVERSE(pQueryHandle->order) ? 1 : -1;
|
int32_t step = ASCENDING_TRAVERSE(pQueryHandle->order) ? 1 : -1;
|
||||||
|
|
||||||
cur->rows = tsdbReadRowsFromCache(pCheckInfo, binfo.window.skey - step,
|
cur->rows = tsdbReadRowsFromCache(pCheckInfo, binfo.window.skey - step,
|
||||||
pQueryHandle->outputCapacity, &cur->win.skey, &cur->win.ekey, pQueryHandle);
|
pQueryHandle->outputCapacity, &cur->win, pQueryHandle);
|
||||||
pQueryHandle->realNumOfRows = cur->rows;
|
pQueryHandle->realNumOfRows = cur->rows;
|
||||||
|
|
||||||
// update the last key value
|
// update the last key value
|
||||||
|
@ -1237,7 +1243,6 @@ static int32_t dataBlockOrderCompar(const void* pLeft, const void* pRight, void*
|
||||||
// assert(pLeftBlockInfoEx->compBlock->offset != pRightBlockInfoEx->compBlock->offset);
|
// assert(pLeftBlockInfoEx->compBlock->offset != pRightBlockInfoEx->compBlock->offset);
|
||||||
if (pLeftBlockInfoEx->compBlock->offset == pRightBlockInfoEx->compBlock->offset &&
|
if (pLeftBlockInfoEx->compBlock->offset == pRightBlockInfoEx->compBlock->offset &&
|
||||||
pLeftBlockInfoEx->compBlock->last == pRightBlockInfoEx->compBlock->last) {
|
pLeftBlockInfoEx->compBlock->last == pRightBlockInfoEx->compBlock->last) {
|
||||||
// todo add more information
|
|
||||||
tsdbError("error in header file, two block with same offset:%" PRId64, (int64_t)pLeftBlockInfoEx->compBlock->offset);
|
tsdbError("error in header file, two block with same offset:%" PRId64, (int64_t)pLeftBlockInfoEx->compBlock->offset);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1478,6 +1483,7 @@ bool tsdbNextDataBlock(TsdbQueryHandleT* pHandle) {
|
||||||
size_t numOfTables = taosArrayGetSize(pQueryHandle->pTableCheckInfo);
|
size_t numOfTables = taosArrayGetSize(pQueryHandle->pTableCheckInfo);
|
||||||
assert(numOfTables > 0);
|
assert(numOfTables > 0);
|
||||||
|
|
||||||
|
SDataBlockInfo blockInfo = {{0}, 0};
|
||||||
if (pQueryHandle->type == TSDB_QUERY_TYPE_EXTERNAL) {
|
if (pQueryHandle->type == TSDB_QUERY_TYPE_EXTERNAL) {
|
||||||
pQueryHandle->type = TSDB_QUERY_TYPE_ALL;
|
pQueryHandle->type = TSDB_QUERY_TYPE_ALL;
|
||||||
pQueryHandle->order = TSDB_ORDER_DESC;
|
pQueryHandle->order = TSDB_ORDER_DESC;
|
||||||
|
@ -1487,7 +1493,7 @@ bool tsdbNextDataBlock(TsdbQueryHandleT* pHandle) {
|
||||||
}
|
}
|
||||||
|
|
||||||
SArray* sa = getDefaultLoadColumns(pQueryHandle, true);
|
SArray* sa = getDefaultLoadColumns(pQueryHandle, true);
|
||||||
/*SDataBlockInfo* pBlockInfo =*/ tsdbRetrieveDataBlockInfo(pHandle);
|
/*SDataBlockInfo* pBlockInfo =*/ tsdbRetrieveDataBlockInfo(pHandle, &blockInfo);
|
||||||
/*SArray *pDataBlock = */tsdbRetrieveDataBlock(pHandle, sa);
|
/*SArray *pDataBlock = */tsdbRetrieveDataBlock(pHandle, sa);
|
||||||
|
|
||||||
if (pQueryHandle->cur.win.ekey == pQueryHandle->window.skey) {
|
if (pQueryHandle->cur.win.ekey == pQueryHandle->window.skey) {
|
||||||
|
@ -1558,7 +1564,7 @@ bool tsdbNextDataBlock(TsdbQueryHandleT* pHandle) {
|
||||||
bool ret = tsdbNextDataBlock((void*) pSecQueryHandle);
|
bool ret = tsdbNextDataBlock((void*) pSecQueryHandle);
|
||||||
assert(ret);
|
assert(ret);
|
||||||
|
|
||||||
/*SDataBlockInfo* pBlockInfo =*/ tsdbRetrieveDataBlockInfo((void*) pSecQueryHandle);
|
/*SDataBlockInfo* pBlockInfo =*/ tsdbRetrieveDataBlockInfo((void*) pSecQueryHandle, &blockInfo);
|
||||||
/*SArray *pDataBlock = */tsdbRetrieveDataBlock((void*) pSecQueryHandle, sa);
|
/*SArray *pDataBlock = */tsdbRetrieveDataBlock((void*) pSecQueryHandle, sa);
|
||||||
|
|
||||||
for (int32_t i = 0; i < numOfCols; ++i) {
|
for (int32_t i = 0; i < numOfCols; ++i) {
|
||||||
|
@ -1693,11 +1699,11 @@ static void changeQueryHandleForInterpQuery(TsdbQueryHandleT pHandle) {
|
||||||
pQueryHandle->window = (STimeWindow) {info.lastKey, TSKEY_INITIAL_VAL};
|
pQueryHandle->window = (STimeWindow) {info.lastKey, TSKEY_INITIAL_VAL};
|
||||||
}
|
}
|
||||||
|
|
||||||
static int tsdbReadRowsFromCache(STableCheckInfo* pCheckInfo, TSKEY maxKey, int maxRowsToRead, TSKEY* skey, TSKEY* ekey,
|
static int tsdbReadRowsFromCache(STableCheckInfo* pCheckInfo, TSKEY maxKey, int maxRowsToRead, STimeWindow* win,
|
||||||
STsdbQueryHandle* pQueryHandle) {
|
STsdbQueryHandle* pQueryHandle) {
|
||||||
int numOfRows = 0;
|
int numOfRows = 0;
|
||||||
int32_t numOfCols = taosArrayGetSize(pQueryHandle->pColumns);
|
int32_t numOfCols = taosArrayGetSize(pQueryHandle->pColumns);
|
||||||
*skey = TSKEY_INITIAL_VAL;
|
win->skey = TSKEY_INITIAL_VAL;
|
||||||
|
|
||||||
int64_t st = taosGetTimestampUs();
|
int64_t st = taosGetTimestampUs();
|
||||||
STsdbMeta* pMeta = tsdbGetMeta(pQueryHandle->pTsdb);
|
STsdbMeta* pMeta = tsdbGetMeta(pQueryHandle->pTsdb);
|
||||||
|
@ -1717,11 +1723,11 @@ static int tsdbReadRowsFromCache(STableCheckInfo* pCheckInfo, TSKEY maxKey, int
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (*skey == INT64_MIN) {
|
if (win->skey == INT64_MIN) {
|
||||||
*skey = key;
|
win->skey = key;
|
||||||
}
|
}
|
||||||
|
|
||||||
*ekey = key;
|
win->ekey = key;
|
||||||
copyOneRowFromMem(pQueryHandle, maxRowsToRead, numOfRows, row, pMeta, numOfCols, pTable);
|
copyOneRowFromMem(pQueryHandle, maxRowsToRead, numOfRows, row, pMeta, numOfCols, pTable);
|
||||||
|
|
||||||
if (++numOfRows >= maxRowsToRead) {
|
if (++numOfRows >= maxRowsToRead) {
|
||||||
|
@ -1750,7 +1756,7 @@ static int tsdbReadRowsFromCache(STableCheckInfo* pCheckInfo, TSKEY maxKey, int
|
||||||
return numOfRows;
|
return numOfRows;
|
||||||
}
|
}
|
||||||
|
|
||||||
SDataBlockInfo tsdbRetrieveDataBlockInfo(TsdbQueryHandleT* pQueryHandle) {
|
void tsdbRetrieveDataBlockInfo(TsdbQueryHandleT* pQueryHandle, SDataBlockInfo* pDataBlockInfo) {
|
||||||
STsdbQueryHandle* pHandle = (STsdbQueryHandle*)pQueryHandle;
|
STsdbQueryHandle* pHandle = (STsdbQueryHandle*)pQueryHandle;
|
||||||
SQueryFilePos* cur = &pHandle->cur;
|
SQueryFilePos* cur = &pHandle->cur;
|
||||||
STable* pTable = NULL;
|
STable* pTable = NULL;
|
||||||
|
@ -1764,15 +1770,11 @@ SDataBlockInfo tsdbRetrieveDataBlockInfo(TsdbQueryHandleT* pQueryHandle) {
|
||||||
pTable = pCheckInfo->pTableObj;
|
pTable = pCheckInfo->pTableObj;
|
||||||
}
|
}
|
||||||
|
|
||||||
SDataBlockInfo blockInfo = {
|
pDataBlockInfo->uid = pTable->tableId.uid;
|
||||||
.uid = pTable->tableId.uid,
|
pDataBlockInfo->tid = pTable->tableId.tid;
|
||||||
.tid = pTable->tableId.tid,
|
pDataBlockInfo->rows = cur->rows;
|
||||||
.rows = cur->rows,
|
pDataBlockInfo->window = cur->win;
|
||||||
.window = cur->win,
|
pDataBlockInfo->numOfCols = QH_GET_NUM_OF_COLS(pHandle);
|
||||||
.numOfCols = QH_GET_NUM_OF_COLS(pHandle),
|
|
||||||
};
|
|
||||||
|
|
||||||
return blockInfo;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -1974,9 +1976,9 @@ int32_t tableGroupComparFn(const void *p1, const void *p2, const void *param) {
|
||||||
int32_t type = 0;
|
int32_t type = 0;
|
||||||
int32_t bytes = 0;
|
int32_t bytes = 0;
|
||||||
|
|
||||||
if (colIndex == TSDB_TBNAME_COLUMN_INDEX) { // todo refactor extract method , to queryExecutor to generate tags values
|
if (colIndex == TSDB_TBNAME_COLUMN_INDEX) {
|
||||||
f1 = (char*) pTable1->name;
|
f1 = (char*) TABLE_NAME(pTable1);
|
||||||
f2 = (char*) pTable2->name;
|
f2 = (char*) TABLE_NAME(pTable2);
|
||||||
type = TSDB_DATA_TYPE_BINARY;
|
type = TSDB_DATA_TYPE_BINARY;
|
||||||
bytes = tGetTableNameColumnSchema().bytes;
|
bytes = tGetTableNameColumnSchema().bytes;
|
||||||
} else {
|
} else {
|
||||||
|
@ -2085,13 +2087,17 @@ bool indexedNodeFilterFp(const void* pNode, void* param) {
|
||||||
char* val = NULL;
|
char* val = NULL;
|
||||||
|
|
||||||
if (pInfo->colIndex == TSDB_TBNAME_COLUMN_INDEX) {
|
if (pInfo->colIndex == TSDB_TBNAME_COLUMN_INDEX) {
|
||||||
val = (char*) pTable->name;
|
val = (char*) TABLE_NAME(pTable);
|
||||||
} else {
|
} else {
|
||||||
val = tdGetKVRowValOfCol(pTable->tagVal, pInfo->sch.colId);
|
val = tdGetKVRowValOfCol(pTable->tagVal, pInfo->sch.colId);
|
||||||
}
|
}
|
||||||
|
|
||||||
//todo :the val is possible to be null, so check it out carefully
|
int32_t ret = 0;
|
||||||
int32_t ret = pInfo->compare(val, pInfo->q);
|
if (val == NULL) { //the val is possible to be null, so check it out carefully
|
||||||
|
ret = -1; // val is missing in table tags value pairs
|
||||||
|
} else {
|
||||||
|
ret = pInfo->compare(val, pInfo->q);
|
||||||
|
}
|
||||||
|
|
||||||
switch (pInfo->optr) {
|
switch (pInfo->optr) {
|
||||||
case TSDB_RELATION_EQUAL: {
|
case TSDB_RELATION_EQUAL: {
|
||||||
|
|
|
@ -24,14 +24,13 @@ extern "C" {
|
||||||
#include "tref.h"
|
#include "tref.h"
|
||||||
#include "hash.h"
|
#include "hash.h"
|
||||||
|
|
||||||
typedef void (*__cache_freeres_fn_t)(void*);
|
typedef void (*__cache_free_fn_t)(void*);
|
||||||
|
|
||||||
typedef struct SCacheStatis {
|
typedef struct SCacheStatis {
|
||||||
int64_t missCount;
|
int64_t missCount;
|
||||||
int64_t hitCount;
|
int64_t hitCount;
|
||||||
int64_t totalAccess;
|
int64_t totalAccess;
|
||||||
int64_t refreshCount;
|
int64_t refreshCount;
|
||||||
int32_t numOfCollision;
|
|
||||||
} SCacheStatis;
|
} SCacheStatis;
|
||||||
|
|
||||||
typedef struct SCacheDataNode {
|
typedef struct SCacheDataNode {
|
||||||
|
@ -70,7 +69,7 @@ typedef struct {
|
||||||
// void * pTimer;
|
// void * pTimer;
|
||||||
SCacheStatis statistics;
|
SCacheStatis statistics;
|
||||||
SHashObj * pHashTable;
|
SHashObj * pHashTable;
|
||||||
__cache_freeres_fn_t freeFp;
|
__cache_free_fn_t freeFp;
|
||||||
uint32_t numOfElemsInTrash; // number of element in trash
|
uint32_t numOfElemsInTrash; // number of element in trash
|
||||||
uint8_t deleting; // set the deleting flag to stop refreshing ASAP.
|
uint8_t deleting; // set the deleting flag to stop refreshing ASAP.
|
||||||
pthread_t refreshWorker;
|
pthread_t refreshWorker;
|
||||||
|
@ -91,15 +90,7 @@ typedef struct {
|
||||||
* @param fn free resource callback function
|
* @param fn free resource callback function
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
SCacheObj *taosCacheInit(int32_t keyType, int64_t refreshTimeInSeconds, bool extendLifespan, __cache_freeres_fn_t fn, const char *cacheName);
|
SCacheObj *taosCacheInit(int32_t keyType, int64_t refreshTimeInSeconds, bool extendLifespan, __cache_free_fn_t fn, const char *cacheName);
|
||||||
|
|
||||||
/**
|
|
||||||
* initialize the cache object and set the free object callback function
|
|
||||||
* @param refreshTimeInSeconds
|
|
||||||
* @param freeCb
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
SCacheObj *taosCacheInitWithCb(int32_t keyType, int64_t refreshTimeInSeconds, bool extendLifespan, __cache_freeres_fn_t fn, const char *cacheName);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* add data into cache
|
* add data into cache
|
||||||
|
@ -163,9 +154,8 @@ void taosCacheRelease(SCacheObj *pCacheObj, void **data, bool _remove);
|
||||||
/**
|
/**
|
||||||
* move all data node into trash, clear node in trash can if it is not referenced by any clients
|
* move all data node into trash, clear node in trash can if it is not referenced by any clients
|
||||||
* @param handle
|
* @param handle
|
||||||
* @param _remove remove the data or not if refcount is greater than 0
|
|
||||||
*/
|
*/
|
||||||
void taosCacheEmpty(SCacheObj *pCacheObj, bool _remove);
|
void taosCacheEmpty(SCacheObj *pCacheObj);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* release all allocated memory and destroy the cache object.
|
* release all allocated memory and destroy the cache object.
|
||||||
|
@ -180,6 +170,14 @@ void taosCacheEmpty(SCacheObj *pCacheObj, bool _remove);
|
||||||
*/
|
*/
|
||||||
void taosCacheCleanup(SCacheObj *pCacheObj);
|
void taosCacheCleanup(SCacheObj *pCacheObj);
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @param pCacheObj
|
||||||
|
* @param fp
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
void taosCacheRefresh(SCacheObj *pCacheObj, __cache_free_fn_t fp);
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -18,6 +18,7 @@
|
||||||
|
|
||||||
#ifdef TAOS_RANDOM_FILE_FAIL
|
#ifdef TAOS_RANDOM_FILE_FAIL
|
||||||
|
|
||||||
|
void taosSetRandomFileFailFactor(int factor);
|
||||||
ssize_t taos_tread(int fd, void *buf, size_t count);
|
ssize_t taos_tread(int fd, void *buf, size_t count);
|
||||||
ssize_t taos_twrite(int fd, void *buf, size_t count);
|
ssize_t taos_twrite(int fd, void *buf, size_t count);
|
||||||
off_t taos_lseek(int fd, off_t offset, int whence);
|
off_t taos_lseek(int fd, off_t offset, int whence);
|
||||||
|
|
|
@ -26,6 +26,7 @@ extern "C" {
|
||||||
#define DEBUG_INFO DEBUG_WARN
|
#define DEBUG_INFO DEBUG_WARN
|
||||||
#define DEBUG_DEBUG 4U
|
#define DEBUG_DEBUG 4U
|
||||||
#define DEBUG_TRACE 8U
|
#define DEBUG_TRACE 8U
|
||||||
|
#define DEBUG_DUMP 16U
|
||||||
|
|
||||||
#define DEBUG_SCREEN 64U
|
#define DEBUG_SCREEN 64U
|
||||||
#define DEBUG_FILE 128U
|
#define DEBUG_FILE 128U
|
||||||
|
|
|
@ -51,6 +51,7 @@ typedef struct SSkipListNode {
|
||||||
#define SL_GET_NODE_KEY(s, n) ((s)->keyFn(SL_GET_NODE_DATA(n)))
|
#define SL_GET_NODE_KEY(s, n) ((s)->keyFn(SL_GET_NODE_DATA(n)))
|
||||||
|
|
||||||
#define SL_GET_SL_MIN_KEY(s) (SL_GET_NODE_KEY((s), SL_GET_FORWARD_POINTER((s)->pHead, 0)))
|
#define SL_GET_SL_MIN_KEY(s) (SL_GET_NODE_KEY((s), SL_GET_FORWARD_POINTER((s)->pHead, 0)))
|
||||||
|
#define SL_GET_SL_MAX_KEY(s) (SL_GET_NODE_KEY((s), SL_GET_BACKWARD_POINTER((s)->pTail, 0)))
|
||||||
|
|
||||||
#define SL_GET_NODE_LEVEL(n) *(uint8_t *)((n))
|
#define SL_GET_NODE_LEVEL(n) *(uint8_t *)((n))
|
||||||
|
|
||||||
|
@ -119,7 +120,6 @@ typedef struct SSkipList {
|
||||||
pthread_rwlock_t *lock;
|
pthread_rwlock_t *lock;
|
||||||
SSkipListNode * pHead; // point to the first element
|
SSkipListNode * pHead; // point to the first element
|
||||||
SSkipListNode * pTail; // point to the last element
|
SSkipListNode * pTail; // point to the last element
|
||||||
void * lastKey; // last key in the skiplist
|
|
||||||
#if SKIP_LIST_RECORD_PERFORMANCE
|
#if SKIP_LIST_RECORD_PERFORMANCE
|
||||||
tSkipListState state; // skiplist state
|
tSkipListState state; // skiplist state
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -223,9 +223,9 @@ static void doCleanupDataCache(SCacheObj *pCacheObj);
|
||||||
* refresh cache to remove data in both hash list and trash, if any nodes' refcount == 0, every pCacheObj->refreshTime
|
* refresh cache to remove data in both hash list and trash, if any nodes' refcount == 0, every pCacheObj->refreshTime
|
||||||
* @param handle Cache object handle
|
* @param handle Cache object handle
|
||||||
*/
|
*/
|
||||||
static void* taosCacheRefresh(void *handle);
|
static void* taosCacheTimedRefresh(void *pCacheObj);
|
||||||
|
|
||||||
SCacheObj *taosCacheInit(int32_t keyType, int64_t refreshTimeInSeconds, bool extendLifespan, __cache_freeres_fn_t fn, const char* cacheName) {
|
SCacheObj *taosCacheInit(int32_t keyType, int64_t refreshTimeInSeconds, bool extendLifespan, __cache_free_fn_t fn, const char* cacheName) {
|
||||||
if (refreshTimeInSeconds <= 0) {
|
if (refreshTimeInSeconds <= 0) {
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
@ -261,7 +261,7 @@ SCacheObj *taosCacheInit(int32_t keyType, int64_t refreshTimeInSeconds, bool ext
|
||||||
pthread_attr_init(&thattr);
|
pthread_attr_init(&thattr);
|
||||||
pthread_attr_setdetachstate(&thattr, PTHREAD_CREATE_JOINABLE);
|
pthread_attr_setdetachstate(&thattr, PTHREAD_CREATE_JOINABLE);
|
||||||
|
|
||||||
pthread_create(&pCacheObj->refreshWorker, &thattr, taosCacheRefresh, pCacheObj);
|
pthread_create(&pCacheObj->refreshWorker, &thattr, taosCacheTimedRefresh, pCacheObj);
|
||||||
|
|
||||||
pthread_attr_destroy(&thattr);
|
pthread_attr_destroy(&thattr);
|
||||||
return pCacheObj;
|
return pCacheObj;
|
||||||
|
@ -450,7 +450,7 @@ void taosCacheRelease(SCacheObj *pCacheObj, void **data, bool _remove) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void taosCacheEmpty(SCacheObj *pCacheObj, bool _remove) {
|
void taosCacheEmpty(SCacheObj *pCacheObj) {
|
||||||
SHashMutableIterator *pIter = taosHashCreateIter(pCacheObj->pHashTable);
|
SHashMutableIterator *pIter = taosHashCreateIter(pCacheObj->pHashTable);
|
||||||
|
|
||||||
__cache_wr_lock(pCacheObj);
|
__cache_wr_lock(pCacheObj);
|
||||||
|
@ -459,8 +459,8 @@ void taosCacheEmpty(SCacheObj *pCacheObj, bool _remove) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
SCacheDataNode *pNode = *(SCacheDataNode **)taosHashIterGet(pIter);
|
SCacheDataNode *pNode = *(SCacheDataNode **) taosHashIterGet(pIter);
|
||||||
if (T_REF_VAL_GET(pNode) == 0 || _remove) {
|
if (T_REF_VAL_GET(pNode) == 0) {
|
||||||
taosCacheReleaseNode(pCacheObj, pNode);
|
taosCacheReleaseNode(pCacheObj, pNode);
|
||||||
} else {
|
} else {
|
||||||
taosCacheMoveToTrash(pCacheObj, pNode);
|
taosCacheMoveToTrash(pCacheObj, pNode);
|
||||||
|
@ -469,7 +469,7 @@ void taosCacheEmpty(SCacheObj *pCacheObj, bool _remove) {
|
||||||
__cache_unlock(pCacheObj);
|
__cache_unlock(pCacheObj);
|
||||||
|
|
||||||
taosHashDestroyIter(pIter);
|
taosHashDestroyIter(pIter);
|
||||||
taosTrashCanEmpty(pCacheObj, _remove);
|
taosTrashCanEmpty(pCacheObj, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
void taosCacheCleanup(SCacheObj *pCacheObj) {
|
void taosCacheCleanup(SCacheObj *pCacheObj) {
|
||||||
|
@ -623,8 +623,29 @@ void doCleanupDataCache(SCacheObj *pCacheObj) {
|
||||||
free(pCacheObj);
|
free(pCacheObj);
|
||||||
}
|
}
|
||||||
|
|
||||||
void* taosCacheRefresh(void *handle) {
|
static void doCacheRefresh(SCacheObj* pCacheObj, int64_t time, __cache_free_fn_t fp) {
|
||||||
SCacheObj *pCacheObj = (SCacheObj *)handle;
|
SHashMutableIterator *pIter = taosHashCreateIter(pCacheObj->pHashTable);
|
||||||
|
|
||||||
|
__cache_wr_lock(pCacheObj);
|
||||||
|
while (taosHashIterNext(pIter)) {
|
||||||
|
SCacheDataNode *pNode = *(SCacheDataNode **)taosHashIterGet(pIter);
|
||||||
|
if ((pNode->addedTime + pNode->lifespan * pNode->extendFactor) <= time && T_REF_VAL_GET(pNode) <= 0) {
|
||||||
|
taosCacheReleaseNode(pCacheObj, pNode);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (fp) {
|
||||||
|
fp(pNode->data);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
__cache_unlock(pCacheObj);
|
||||||
|
|
||||||
|
taosHashDestroyIter(pIter);
|
||||||
|
}
|
||||||
|
|
||||||
|
void* taosCacheTimedRefresh(void *handle) {
|
||||||
|
SCacheObj* pCacheObj = handle;
|
||||||
if (pCacheObj == NULL) {
|
if (pCacheObj == NULL) {
|
||||||
uDebug("object is destroyed. no refresh retry");
|
uDebug("object is destroyed. no refresh retry");
|
||||||
return NULL;
|
return NULL;
|
||||||
|
@ -657,21 +678,8 @@ void* taosCacheRefresh(void *handle) {
|
||||||
|
|
||||||
// refresh data in hash table
|
// refresh data in hash table
|
||||||
if (elemInHash > 0) {
|
if (elemInHash > 0) {
|
||||||
int64_t expiredTime = taosGetTimestampMs();
|
int64_t now = taosGetTimestampMs();
|
||||||
|
doCacheRefresh(pCacheObj, now, NULL);
|
||||||
SHashMutableIterator *pIter = taosHashCreateIter(pCacheObj->pHashTable);
|
|
||||||
|
|
||||||
__cache_wr_lock(pCacheObj);
|
|
||||||
while (taosHashIterNext(pIter)) {
|
|
||||||
SCacheDataNode *pNode = *(SCacheDataNode **)taosHashIterGet(pIter);
|
|
||||||
if ((pNode->addedTime + pNode->lifespan * pNode->extendFactor) <= expiredTime && T_REF_VAL_GET(pNode) <= 0) {
|
|
||||||
taosCacheReleaseNode(pCacheObj, pNode);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
__cache_unlock(pCacheObj);
|
|
||||||
|
|
||||||
taosHashDestroyIter(pIter);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
taosTrashCanEmpty(pCacheObj, false);
|
taosTrashCanEmpty(pCacheObj, false);
|
||||||
|
@ -679,3 +687,12 @@ void* taosCacheRefresh(void *handle) {
|
||||||
|
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void taosCacheRefresh(SCacheObj *pCacheObj, __cache_free_fn_t fp) {
|
||||||
|
if (pCacheObj == NULL) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
int64_t now = taosGetTimestampMs();
|
||||||
|
doCacheRefresh(pCacheObj, now, fp);
|
||||||
|
}
|
||||||
|
|
|
@ -26,40 +26,51 @@
|
||||||
|
|
||||||
#include "os.h"
|
#include "os.h"
|
||||||
|
|
||||||
#define RANDOM_FILE_FAIL_FACTOR 5
|
#ifdef TAOS_RANDOM_FILE_FAIL
|
||||||
|
|
||||||
|
static int random_file_fail_factor = 20;
|
||||||
|
|
||||||
|
void taosSetRandomFileFailFactor(int factor)
|
||||||
|
{
|
||||||
|
random_file_fail_factor = factor;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
ssize_t taos_tread(int fd, void *buf, size_t count)
|
ssize_t taos_tread(int fd, void *buf, size_t count)
|
||||||
{
|
{
|
||||||
#ifdef TAOS_RANDOM_FILE_FAIL
|
#ifdef TAOS_RANDOM_FILE_FAIL
|
||||||
if (rand() % RANDOM_FILE_FAIL_FACTOR == 0) {
|
if (random_file_fail_factor > 0) {
|
||||||
errno = EIO;
|
if (rand() % random_file_fail_factor == 0) {
|
||||||
return -1;
|
errno = EIO;
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
return tread(fd, buf, count);
|
return tread(fd, buf, count);
|
||||||
}
|
}
|
||||||
|
|
||||||
ssize_t taos_twrite(int fd, void *buf, size_t count)
|
ssize_t taos_twrite(int fd, void *buf, size_t count)
|
||||||
{
|
{
|
||||||
#ifdef TAOS_RANDOM_FILE_FAIL
|
#ifdef TAOS_RANDOM_FILE_FAIL
|
||||||
if (rand() % RANDOM_FILE_FAIL_FACTOR == 0) {
|
if (random_file_fail_factor > 0) {
|
||||||
errno = EIO;
|
if (rand() % random_file_fail_factor == 0) {
|
||||||
return -1;
|
errno = EIO;
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
return twrite(fd, buf, count);
|
return twrite(fd, buf, count);
|
||||||
}
|
}
|
||||||
|
|
||||||
off_t taos_lseek(int fd, off_t offset, int whence)
|
off_t taos_lseek(int fd, off_t offset, int whence)
|
||||||
{
|
{
|
||||||
#ifdef TAOS_RANDOM_FILE_FAIL
|
#ifdef TAOS_RANDOM_FILE_FAIL
|
||||||
if (rand() % RANDOM_FILE_FAIL_FACTOR == 0) {
|
if (random_file_fail_factor > 0) {
|
||||||
errno = EIO;
|
if (rand() % random_file_fail_factor == 0) {
|
||||||
return -1;
|
errno = EIO;
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
return lseek(fd, offset, whence);
|
return lseek(fd, offset, whence);
|
||||||
}
|
}
|
||||||
|
|
|
@ -13,10 +13,10 @@
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#include "tlosertree.h"
|
||||||
#include "os.h"
|
#include "os.h"
|
||||||
#include "taosmsg.h"
|
#include "taosmsg.h"
|
||||||
#include "tlosertree.h"
|
#include "tulog.h"
|
||||||
#include "queryLog.h"
|
|
||||||
|
|
||||||
// set initial value for loser tree
|
// set initial value for loser tree
|
||||||
void tLoserTreeInit(SLoserTreeInfo* pTree) {
|
void tLoserTreeInit(SLoserTreeInfo* pTree) {
|
||||||
|
@ -45,7 +45,7 @@ uint32_t tLoserTreeCreate(SLoserTreeInfo** pTree, int32_t numOfEntries, void* pa
|
||||||
|
|
||||||
*pTree = (SLoserTreeInfo*)calloc(1, sizeof(SLoserTreeInfo) + sizeof(SLoserTreeNode) * totalEntries);
|
*pTree = (SLoserTreeInfo*)calloc(1, sizeof(SLoserTreeInfo) + sizeof(SLoserTreeNode) * totalEntries);
|
||||||
if ((*pTree) == NULL) {
|
if ((*pTree) == NULL) {
|
||||||
qError("allocate memory for loser-tree failed. reason:%s", strerror(errno));
|
uError("allocate memory for loser-tree failed. reason:%s", strerror(errno));
|
||||||
return TSDB_CODE_QRY_OUT_OF_MEMORY;
|
return TSDB_CODE_QRY_OUT_OF_MEMORY;
|
||||||
}
|
}
|
||||||
|
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue