Merge remote-tracking branch 'upstream/develop' into odbc-win
This commit is contained in:
commit
9081fd67aa
|
@ -27,6 +27,7 @@ pipeline {
|
|||
cd debug
|
||||
cmake .. > /dev/null
|
||||
make > /dev/null
|
||||
make install > /dev/null
|
||||
cd ${WKC}/tests
|
||||
#./test-all.sh smoke
|
||||
./test-all.sh pytest
|
||||
|
@ -89,7 +90,6 @@ pipeline {
|
|||
catchError(buildResult: 'SUCCESS', stageResult: 'FAILURE') {
|
||||
sh '''
|
||||
cd ${WKC}/tests/pytest
|
||||
./crash_gen.sh --valgrind -p -t 10 -s 100 -b 4
|
||||
./handle_crash_gen_val_log.sh
|
||||
'''
|
||||
}
|
||||
|
|
|
@ -1016,9 +1016,9 @@ SELECT AVG(current),MAX(current),LEASTSQUARES(current, start_val, step_val), PER
|
|||
```
|
||||
|
||||
## TAOS SQL 边界限制
|
||||
- 数据库名最大长度为33
|
||||
- 表名最大长度为193,每行数据最大长度16k个字符
|
||||
- 列名最大长度为65,最多允许1024列,最少需要2列,第一列必须是时间戳
|
||||
- 数据库名最大长度为32
|
||||
- 表名最大长度为192,每行数据最大长度16k个字符
|
||||
- 列名最大长度为64,最多允许1024列,最少需要2列,第一列必须是时间戳
|
||||
- 标签最多允许128个,可以0个,标签总长度不超过16k个字符
|
||||
- SQL语句最大长度65480个字符,但可通过系统配置参数maxSQLLength修改,最长可配置为1M
|
||||
- 库的数目,超级表的数目、表的数目,系统不做限制,仅受系统资源限制
|
||||
|
|
|
@ -48,6 +48,7 @@ cp ${compile_dir}/../packaging/deb/taosd ${pkg_dir}${install_home_pat
|
|||
cp ${compile_dir}/../packaging/tools/post.sh ${pkg_dir}${install_home_path}/script
|
||||
cp ${compile_dir}/../packaging/tools/preun.sh ${pkg_dir}${install_home_path}/script
|
||||
cp ${compile_dir}/build/bin/taosdemo ${pkg_dir}${install_home_path}/bin
|
||||
cp ${compile_dir}/build/bin/taosdump ${pkg_dir}${install_home_path}/bin
|
||||
cp ${compile_dir}/build/bin/taosd ${pkg_dir}${install_home_path}/bin
|
||||
cp ${compile_dir}/build/bin/taos ${pkg_dir}${install_home_path}/bin
|
||||
cp ${compile_dir}/build/lib/${libfile} ${pkg_dir}${install_home_path}/driver
|
||||
|
|
|
@ -58,6 +58,7 @@ cp %{_compiledir}/../packaging/tools/preun.sh %{buildroot}%{homepath}/scri
|
|||
cp %{_compiledir}/build/bin/taos %{buildroot}%{homepath}/bin
|
||||
cp %{_compiledir}/build/bin/taosd %{buildroot}%{homepath}/bin
|
||||
cp %{_compiledir}/build/bin/taosdemo %{buildroot}%{homepath}/bin
|
||||
cp %{_compiledir}/build/bin/taosdump %{buildroot}%{homepath}/bin
|
||||
cp %{_compiledir}/build/lib/${libfile} %{buildroot}%{homepath}/driver
|
||||
cp %{_compiledir}/../src/inc/taos.h %{buildroot}%{homepath}/include
|
||||
cp %{_compiledir}/../src/inc/taoserror.h %{buildroot}%{homepath}/include
|
||||
|
@ -134,6 +135,7 @@ if [ $1 -eq 0 ];then
|
|||
${csudo} rm -f ${bin_link_dir}/taos || :
|
||||
${csudo} rm -f ${bin_link_dir}/taosd || :
|
||||
${csudo} rm -f ${bin_link_dir}/taosdemo || :
|
||||
${csudo} rm -f ${bin_link_dir}/taosdump || :
|
||||
${csudo} rm -f ${cfg_link_dir}/* || :
|
||||
${csudo} rm -f ${inc_link_dir}/taos.h || :
|
||||
${csudo} rm -f ${inc_link_dir}/taoserror.h || :
|
||||
|
|
|
@ -45,7 +45,7 @@ if [ "$osType" != "Darwin" ]; then
|
|||
strip ${build_dir}/bin/taos
|
||||
bin_files="${build_dir}/bin/taos ${script_dir}/remove_client.sh"
|
||||
else
|
||||
bin_files="${build_dir}/bin/taos ${build_dir}/bin/taosdemo ${script_dir}/remove_client.sh ${script_dir}/set_core.sh"
|
||||
bin_files="${build_dir}/bin/taos ${build_dir}/bin/taosdump ${build_dir}/bin/taosdemo ${script_dir}/remove_client.sh ${script_dir}/set_core.sh"
|
||||
fi
|
||||
lib_files="${build_dir}/lib/libtaos.so.${version}"
|
||||
else
|
||||
|
|
|
@ -36,7 +36,7 @@ if [ "$pagMode" == "lite" ]; then
|
|||
strip ${build_dir}/bin/taos
|
||||
bin_files="${build_dir}/bin/taosd ${build_dir}/bin/taos ${script_dir}/remove.sh"
|
||||
else
|
||||
bin_files="${build_dir}/bin/taosd ${build_dir}/bin/taos ${build_dir}/bin/taosdemo ${build_dir}/bin/tarbitrator ${script_dir}/remove.sh ${script_dir}/set_core.sh"
|
||||
bin_files="${build_dir}/bin/taosd ${build_dir}/bin/taos ${build_dir}/bin/taosdump ${build_dir}/bin/taosdemo ${build_dir}/bin/tarbitrator ${script_dir}/remove.sh ${script_dir}/set_core.sh"
|
||||
fi
|
||||
|
||||
lib_files="${build_dir}/lib/libtaos.so.${version}"
|
||||
|
|
|
@ -81,8 +81,10 @@ function install_lib() {
|
|||
${csudo} ln -s ${lib_dir}/libtaos.* ${lib_link_dir}/libtaos.so.1
|
||||
${csudo} ln -s ${lib_link_dir}/libtaos.so.1 ${lib_link_dir}/libtaos.so
|
||||
|
||||
${csudo} ln -s ${lib_dir}/libtaos.* ${lib64_link_dir}/libtaos.so.1 || :
|
||||
${csudo} ln -s ${lib64_link_dir}/libtaos.so.1 ${lib64_link_dir}/libtaos.so || :
|
||||
if [[ -d ${lib64_link_dir} && ! -e ${lib64_link_dir}/libtaos.so ]]; then
|
||||
${csudo} ln -s ${lib_dir}/libtaos.* ${lib64_link_dir}/libtaos.so.1 || :
|
||||
${csudo} ln -s ${lib64_link_dir}/libtaos.so.1 ${lib64_link_dir}/libtaos.so || :
|
||||
fi
|
||||
}
|
||||
|
||||
function install_bin() {
|
||||
|
|
|
@ -330,6 +330,7 @@ typedef struct STscObj {
|
|||
char writeAuth : 1;
|
||||
char superAuth : 1;
|
||||
uint32_t connId;
|
||||
uint64_t rid; // ref ID returned by taosAddRef
|
||||
struct SSqlObj * pHb;
|
||||
struct SSqlObj * sqlList;
|
||||
struct SSqlStream *streamList;
|
||||
|
@ -348,7 +349,7 @@ typedef struct SSqlObj {
|
|||
void *signature;
|
||||
pthread_t owner; // owner of sql object, by which it is executed
|
||||
STscObj *pTscObj;
|
||||
void *pRpcCtx;
|
||||
int64_t rpcRid;
|
||||
void (*fp)();
|
||||
void (*fetchFp)();
|
||||
void *param;
|
||||
|
|
|
@ -428,6 +428,7 @@ void tscTableMetaCallBack(void *param, TAOS_RES *res, int code) {
|
|||
} else {
|
||||
assert(code == TSDB_CODE_SUCCESS);
|
||||
}
|
||||
|
||||
// param already freed by other routine and pSql in tscCache when ctrl + c
|
||||
if (atomic_load_ptr(&pSql->param) == NULL) {
|
||||
return;
|
||||
|
@ -441,6 +442,20 @@ void tscTableMetaCallBack(void *param, TAOS_RES *res, int code) {
|
|||
assert(pParObj->signature == pParObj && trs->subqueryIndex == pTableMetaInfo->vgroupIndex &&
|
||||
pTableMetaInfo->vgroupIndex >= 0 && pTableMetaInfo->vgroupList != NULL);
|
||||
|
||||
// tscProcessSql can add error into async res
|
||||
tscProcessSql(pSql);
|
||||
return;
|
||||
} else if (TSDB_QUERY_HAS_TYPE(pQueryInfo->type, TSDB_QUERY_TYPE_TAG_FILTER_QUERY)) {
|
||||
tscDebug("%p update table meta in local cache, continue to process sql and send corresponding tid_tag query", pSql);
|
||||
STableMetaInfo* pTableMetaInfo = tscGetMetaInfo(pQueryInfo, 0);
|
||||
code = tscGetTableMeta(pSql, pTableMetaInfo);
|
||||
if (code == TSDB_CODE_TSC_ACTION_IN_PROGRESS) {
|
||||
return;
|
||||
} else {
|
||||
assert(code == TSDB_CODE_SUCCESS);
|
||||
}
|
||||
|
||||
assert((tscGetNumOfTags(pTableMetaInfo->pTableMeta) != 0));
|
||||
// tscProcessSql can add error into async res
|
||||
tscProcessSql(pSql);
|
||||
return;
|
||||
|
@ -465,7 +480,6 @@ void tscTableMetaCallBack(void *param, TAOS_RES *res, int code) {
|
|||
tscResetSqlCmdObj(pCmd, false);
|
||||
|
||||
code = tsParseSql(pSql, true);
|
||||
|
||||
if (code == TSDB_CODE_TSC_ACTION_IN_PROGRESS) {
|
||||
return;
|
||||
} else if (code != TSDB_CODE_SUCCESS) {
|
||||
|
|
|
@ -3978,7 +3978,7 @@ static void interp_function(SQLFunctionCtx *pCtx) {
|
|||
if (isNull(data1, srcType) || isNull(data2, srcType)) {
|
||||
setNull(pCtx->aOutputBuf, srcType, pCtx->inputBytes);
|
||||
} else {
|
||||
taosDoLinearInterpolation(pCtx->outputType, &point1, &point2, &point);
|
||||
taosGetLinearInterpolationVal(pCtx->outputType, &point1, &point2, &point);
|
||||
}
|
||||
} else if (srcType == TSDB_DATA_TYPE_FLOAT) {
|
||||
point1.val = data1;
|
||||
|
@ -3987,7 +3987,7 @@ static void interp_function(SQLFunctionCtx *pCtx) {
|
|||
if (isNull(data1, srcType) || isNull(data2, srcType)) {
|
||||
setNull(pCtx->aOutputBuf, srcType, pCtx->inputBytes);
|
||||
} else {
|
||||
taosDoLinearInterpolation(pCtx->outputType, &point1, &point2, &point);
|
||||
taosGetLinearInterpolationVal(pCtx->outputType, &point1, &point2, &point);
|
||||
}
|
||||
|
||||
} else {
|
||||
|
|
|
@ -97,6 +97,9 @@ static void tscInitSqlContext(SSqlCmd *pCmd, SLocalReducer *pReducer, tOrderDesc
|
|||
pCtx->param[2].i64Key = pQueryInfo->order.order;
|
||||
pCtx->param[2].nType = TSDB_DATA_TYPE_BIGINT;
|
||||
pCtx->param[1].i64Key = pQueryInfo->order.orderColId;
|
||||
} else if (functionId == TSDB_FUNC_APERCT) {
|
||||
pCtx->param[0].i64Key = pExpr->param[0].i64Key;
|
||||
pCtx->param[0].nType = pExpr->param[0].nType;
|
||||
}
|
||||
|
||||
pCtx->interBufBytes = pExpr->interBytes;
|
||||
|
|
|
@ -1309,7 +1309,7 @@ int tsParseSql(SSqlObj *pSql, bool initial) {
|
|||
if ((!pCmd->parseFinished) && (!initial)) {
|
||||
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;
|
||||
|
|
|
@ -2758,6 +2758,7 @@ int32_t parseGroupbyClause(SQueryInfo* pQueryInfo, tVariantList* pList, SSqlCmd*
|
|||
const char* msg1 = "too many columns in group by clause";
|
||||
const char* msg2 = "invalid column name in group by clause";
|
||||
const char* msg3 = "columns from one table allowed as group by columns";
|
||||
const char* msg4 = "join query does not support group by";
|
||||
const char* msg7 = "not support group by expression";
|
||||
const char* msg8 = "not allowed column type for group by";
|
||||
const char* msg9 = "tags not allowed for table query";
|
||||
|
@ -2778,6 +2779,10 @@ int32_t parseGroupbyClause(SQueryInfo* pQueryInfo, tVariantList* pList, SSqlCmd*
|
|||
return invalidSqlErrMsg(tscGetErrorMsgPayload(pCmd), msg1);
|
||||
}
|
||||
|
||||
if (pQueryInfo->numOfTables > 1) {
|
||||
return invalidSqlErrMsg(tscGetErrorMsgPayload(pCmd), msg4);
|
||||
}
|
||||
|
||||
STableMeta* pTableMeta = NULL;
|
||||
SSchema* pSchema = NULL;
|
||||
SSchema s = tscGetTbnameColumnSchema();
|
||||
|
@ -5306,6 +5311,7 @@ static void setCreateDBOption(SCreateDbMsg* pMsg, SCreateDBInfo* pCreateDb) {
|
|||
pMsg->replications = pCreateDb->replica;
|
||||
pMsg->quorum = pCreateDb->quorum;
|
||||
pMsg->ignoreExist = pCreateDb->ignoreExists;
|
||||
pMsg->update = pCreateDb->update;
|
||||
}
|
||||
|
||||
int32_t parseCreateDBOptions(SSqlCmd* pCmd, SCreateDBInfo* pCreateDbSql) {
|
||||
|
|
|
@ -182,27 +182,23 @@ void tscProcessHeartBeatRsp(void *param, TAOS_RES *tres, int code) {
|
|||
int32_t waitingDuring = tsShellActivityTimer * 500;
|
||||
tscDebug("%p send heartbeat in %dms", pSql, waitingDuring);
|
||||
|
||||
taosTmrReset(tscProcessActivityTimer, waitingDuring, pObj, tscTmr, &pObj->pTimer);
|
||||
taosTmrReset(tscProcessActivityTimer, waitingDuring, (void *)pObj->rid, tscTmr, &pObj->pTimer);
|
||||
} else {
|
||||
tscDebug("%p start to close tscObj:%p, not send heartbeat again", pSql, pObj);
|
||||
}
|
||||
}
|
||||
|
||||
void tscProcessActivityTimer(void *handle, void *tmrId) {
|
||||
STscObj *pObj = (STscObj *)handle;
|
||||
|
||||
int ret = taosAcquireRef(tscRefId, pObj);
|
||||
if (ret < 0) {
|
||||
tscTrace("%p failed to acquire TSC obj, reason:%s", pObj, tstrerror(ret));
|
||||
return;
|
||||
}
|
||||
int64_t rid = (int64_t) handle;
|
||||
STscObj *pObj = taosAcquireRef(tscRefId, rid);
|
||||
if (pObj == NULL) return;
|
||||
|
||||
SSqlObj* pHB = pObj->pHb;
|
||||
|
||||
void** p = taosCacheAcquireByKey(tscObjCache, &pHB, sizeof(TSDB_CACHE_PTR_TYPE));
|
||||
if (p == NULL) {
|
||||
tscWarn("%p HB object has been released already", pHB);
|
||||
taosReleaseRef(tscRefId, pObj);
|
||||
taosReleaseRef(tscRefId, pObj->rid);
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -216,7 +212,7 @@ void tscProcessActivityTimer(void *handle, void *tmrId) {
|
|||
tscError("%p failed to sent HB to server, reason:%s", pHB, tstrerror(code));
|
||||
}
|
||||
|
||||
taosReleaseRef(tscRefId, pObj);
|
||||
taosReleaseRef(tscRefId, rid);
|
||||
}
|
||||
|
||||
int tscSendMsgToServer(SSqlObj *pSql) {
|
||||
|
@ -241,7 +237,7 @@ int tscSendMsgToServer(SSqlObj *pSql) {
|
|||
.pCont = pMsg,
|
||||
.contLen = pSql->cmd.payloadLen,
|
||||
.ahandle = pSql,
|
||||
.handle = &pSql->pRpcCtx,
|
||||
.handle = NULL,
|
||||
.code = 0
|
||||
};
|
||||
|
||||
|
@ -249,7 +245,7 @@ int tscSendMsgToServer(SSqlObj *pSql) {
|
|||
// Otherwise, the pSql object may have been released already during the response function, which is
|
||||
// processMsgFromServer function. In the meanwhile, the assignment of the rpc context to sql object will absolutely
|
||||
// cause crash.
|
||||
rpcSendRequest(pObj->pDnodeConn, &pSql->epSet, &rpcMsg);
|
||||
pSql->rpcRid = rpcSendRequest(pObj->pDnodeConn, &pSql->epSet, &rpcMsg);
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
|
@ -269,7 +265,7 @@ void tscProcessMsgFromServer(SRpcMsg *rpcMsg, SRpcEpSet *pEpSet) {
|
|||
SSqlCmd *pCmd = &pSql->cmd;
|
||||
|
||||
assert(*pSql->self == pSql);
|
||||
pSql->pRpcCtx = NULL;
|
||||
pSql->rpcRid = -1;
|
||||
|
||||
if (pObj->signature != pObj) {
|
||||
tscDebug("%p DB connection is closed, cmd:%d pObj:%p signature:%p", pSql, pCmd->command, pObj, pObj->signature);
|
||||
|
@ -882,7 +878,7 @@ int tscBuildQueryMsg(SSqlObj *pSql, SSqlInfo *pInfo) {
|
|||
if (pQueryInfo->tsBuf != NULL) {
|
||||
// note: here used the index instead of actual vnode id.
|
||||
int32_t vnodeIndex = pTableMetaInfo->vgroupIndex;
|
||||
int32_t code = dumpFileBlockByVnodeId(pQueryInfo->tsBuf, vnodeIndex, pMsg, &pQueryMsg->tsLen, &pQueryMsg->tsNumOfBlocks);
|
||||
int32_t code = dumpFileBlockByGroupId(pQueryInfo->tsBuf, vnodeIndex, pMsg, &pQueryMsg->tsLen, &pQueryMsg->tsNumOfBlocks);
|
||||
if (code != TSDB_CODE_SUCCESS) {
|
||||
return code;
|
||||
}
|
||||
|
@ -2026,7 +2022,7 @@ int tscProcessConnectRsp(SSqlObj *pSql) {
|
|||
createHBObj(pObj);
|
||||
|
||||
//launch a timer to send heartbeat to maintain the connection and send status to mnode
|
||||
taosTmrReset(tscProcessActivityTimer, tsShellActivityTimer * 500, pObj, tscTmr, &pObj->pTimer);
|
||||
taosTmrReset(tscProcessActivityTimer, tsShellActivityTimer * 500, (void *)pObj->rid, tscTmr, &pObj->pTimer);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -161,7 +161,7 @@ static SSqlObj *taosConnectImpl(const char *ip, const char *user, const char *pa
|
|||
registerSqlObj(pSql);
|
||||
tsInsertHeadSize = sizeof(SMsgDesc) + sizeof(SSubmitMsg);
|
||||
|
||||
taosAddRef(tscRefId, pObj);
|
||||
pObj->rid = taosAddRef(tscRefId, pObj);
|
||||
return pSql;
|
||||
}
|
||||
|
||||
|
@ -279,9 +279,9 @@ void taos_close(TAOS *taos) {
|
|||
|
||||
SSqlObj* pHb = pObj->pHb;
|
||||
if (pHb != NULL && atomic_val_compare_exchange_ptr(&pObj->pHb, pHb, 0) == pHb) {
|
||||
if (pHb->pRpcCtx != NULL) { // wait for rsp from dnode
|
||||
rpcCancelRequest(pHb->pRpcCtx);
|
||||
pHb->pRpcCtx = NULL;
|
||||
if (pHb->rpcRid > 0) { // wait for rsp from dnode
|
||||
rpcCancelRequest(pHb->rpcRid);
|
||||
pHb->rpcRid = -1;
|
||||
}
|
||||
|
||||
tscDebug("%p HB is freed", pHb);
|
||||
|
@ -298,7 +298,7 @@ void taos_close(TAOS *taos) {
|
|||
|
||||
tscDebug("%p all sqlObj are freed, free tscObj and close dnodeConn:%p", pObj, pObj->pDnodeConn);
|
||||
|
||||
taosRemoveRef(tscRefId, pObj);
|
||||
taosRemoveRef(tscRefId, pObj->rid);
|
||||
}
|
||||
|
||||
void waitForQueryRsp(void *param, TAOS_RES *tres, int code) {
|
||||
|
@ -748,9 +748,9 @@ static void tscKillSTableQuery(SSqlObj *pSql) {
|
|||
assert(pSubObj->self == (SSqlObj**) p);
|
||||
|
||||
pSubObj->res.code = TSDB_CODE_TSC_QUERY_CANCELLED;
|
||||
if (pSubObj->pRpcCtx != NULL) {
|
||||
rpcCancelRequest(pSubObj->pRpcCtx);
|
||||
pSubObj->pRpcCtx = NULL;
|
||||
if (pSubObj->rpcRid > 0) {
|
||||
rpcCancelRequest(pSubObj->rpcRid);
|
||||
pSubObj->rpcRid = -1;
|
||||
}
|
||||
|
||||
tscQueueAsyncRes(pSubObj);
|
||||
|
@ -775,7 +775,7 @@ void taos_stop_query(TAOS_RES *res) {
|
|||
SQueryInfo *pQueryInfo = tscGetQueryInfoDetail(pCmd, pCmd->clauseIndex);
|
||||
|
||||
if (tscIsTwoStageSTableQuery(pQueryInfo, 0)) {
|
||||
assert(pSql->pRpcCtx == NULL);
|
||||
assert(pSql->rpcRid <= 0);
|
||||
tscKillSTableQuery(pSql);
|
||||
} else {
|
||||
if (pSql->cmd.command < TSDB_SQL_LOCAL) {
|
||||
|
@ -784,9 +784,9 @@ void taos_stop_query(TAOS_RES *res) {
|
|||
* reset and freed in the processMsgFromServer function, and causes the invalid
|
||||
* write problem for rpcCancelRequest.
|
||||
*/
|
||||
if (pSql->pRpcCtx != NULL) {
|
||||
rpcCancelRequest(pSql->pRpcCtx);
|
||||
pSql->pRpcCtx = NULL;
|
||||
if (pSql->rpcRid > 0) {
|
||||
rpcCancelRequest(pSql->rpcRid);
|
||||
pSql->rpcRid = -1;
|
||||
}
|
||||
|
||||
tscQueueAsyncRes(pSql);
|
||||
|
|
|
@ -156,8 +156,8 @@ static int64_t doTSBlockIntersect(SSqlObj* pSql, SJoinSupporter* pSupporter1, SJ
|
|||
win->ekey = elem1.ts;
|
||||
}
|
||||
|
||||
tsBufAppend(output1, elem1.vnode, elem1.tag, (const char*)&elem1.ts, sizeof(elem1.ts));
|
||||
tsBufAppend(output2, elem2.vnode, elem2.tag, (const char*)&elem2.ts, sizeof(elem2.ts));
|
||||
tsBufAppend(output1, elem1.id, elem1.tag, (const char*)&elem1.ts, sizeof(elem1.ts));
|
||||
tsBufAppend(output2, elem2.id, elem2.tag, (const char*)&elem2.ts, sizeof(elem2.ts));
|
||||
} else {
|
||||
pLimit->offset -= 1;//offset apply to projection?
|
||||
}
|
||||
|
@ -193,8 +193,8 @@ static int64_t doTSBlockIntersect(SSqlObj* pSql, SJoinSupporter* pSupporter1, SJ
|
|||
TSKEY et = taosGetTimestampUs();
|
||||
tscDebug("%p input1:%" PRId64 ", input2:%" PRId64 ", final:%" PRId64 " in %d vnodes for secondary query after ts blocks "
|
||||
"intersecting, skey:%" PRId64 ", ekey:%" PRId64 ", numOfVnode:%d, elapsed time:%" PRId64 " us",
|
||||
pSql, numOfInput1, numOfInput2, output1->numOfTotal, output1->numOfVnodes, win->skey, win->ekey,
|
||||
tsBufGetNumOfVnodes(output1), et - st);
|
||||
pSql, numOfInput1, numOfInput2, output1->numOfTotal, output1->numOfGroups, win->skey, win->ekey,
|
||||
tsBufGetNumOfGroup(output1), et - st);
|
||||
|
||||
return output1->numOfTotal;
|
||||
}
|
||||
|
@ -282,7 +282,7 @@ static UNUSED_FUNC bool needSecondaryQuery(SQueryInfo* pQueryInfo) {
|
|||
static void filterVgroupTables(SQueryInfo* pQueryInfo, SArray* pVgroupTables) {
|
||||
int32_t num = 0;
|
||||
int32_t* list = NULL;
|
||||
tsBufGetVnodeIdList(pQueryInfo->tsBuf, &num, &list);
|
||||
tsBufGetGroupIdList(pQueryInfo->tsBuf, &num, &list);
|
||||
|
||||
// The virtual node, of which all tables are disqualified after the timestamp intersection,
|
||||
// is removed to avoid next stage query.
|
||||
|
@ -314,7 +314,7 @@ static void filterVgroupTables(SQueryInfo* pQueryInfo, SArray* pVgroupTables) {
|
|||
static SArray* buildVgroupTableByResult(SQueryInfo* pQueryInfo, SArray* pVgroupTables) {
|
||||
int32_t num = 0;
|
||||
int32_t* list = NULL;
|
||||
tsBufGetVnodeIdList(pQueryInfo->tsBuf, &num, &list);
|
||||
tsBufGetGroupIdList(pQueryInfo->tsBuf, &num, &list);
|
||||
|
||||
size_t numOfGroups = taosArrayGetSize(pVgroupTables);
|
||||
|
||||
|
@ -523,7 +523,7 @@ static void quitAllSubquery(SSqlObj* pSqlObj, SJoinSupporter* pSupporter) {
|
|||
assert(pSqlObj->subState.numOfRemain > 0);
|
||||
|
||||
if (atomic_sub_fetch_32(&pSqlObj->subState.numOfRemain, 1) <= 0) {
|
||||
tscError("%p all subquery return and query failed, global code:%d", pSqlObj, pSqlObj->res.code);
|
||||
tscError("%p all subquery return and query failed, global code:%s", pSqlObj, tstrerror(pSqlObj->res.code));
|
||||
freeJoinSubqueryObj(pSqlObj);
|
||||
}
|
||||
}
|
||||
|
@ -565,7 +565,7 @@ int32_t tagValCompar(const void* p1, const void* p2) {
|
|||
return (tag1->len > tag2->len)? 1: -1;
|
||||
}
|
||||
|
||||
return strncmp(tag1->data, tag2->data, tag1->len);
|
||||
return memcmp(tag1->data, tag2->data, tag1->len);
|
||||
}
|
||||
|
||||
void tscBuildVgroupTableInfo(SSqlObj* pSql, STableMetaInfo* pTableMetaInfo, SArray* tables) {
|
||||
|
@ -853,11 +853,15 @@ static void tidTagRetrieveCallback(void* param, TAOS_RES* tres, int32_t numOfRow
|
|||
}
|
||||
|
||||
if (taosArrayGetSize(s1) == 0 || taosArrayGetSize(s2) == 0) { // no results,return.
|
||||
assert(pParentSql->fp != tscJoinQueryCallback);
|
||||
|
||||
tscDebug("%p tag intersect does not generated qualified tables for join, free all sub SqlObj and quit", pParentSql);
|
||||
freeJoinSubqueryObj(pParentSql);
|
||||
|
||||
// set no result command
|
||||
pParentSql->cmd.command = TSDB_SQL_RETRIEVE_EMPTY_RESULT;
|
||||
assert(pParentSql->fp != tscJoinQueryCallback);
|
||||
|
||||
(*pParentSql->fp)(pParentSql->param, pParentSql, 0);
|
||||
} else {
|
||||
// proceed to for ts_comp query
|
||||
|
@ -2366,7 +2370,7 @@ void tscBuildResFromSubqueries(SSqlObj *pSql) {
|
|||
SQueryInfo* pQueryInfo = tscGetQueryInfoDetail(&pSql->cmd, pSql->cmd.clauseIndex);
|
||||
|
||||
size_t numOfExprs = tscSqlExprNumOfExprs(pQueryInfo);
|
||||
pRes->numOfCols = (int32_t)numOfExprs;
|
||||
pRes->numOfCols = (int16_t)numOfExprs;
|
||||
|
||||
pRes->tsrow = calloc(numOfExprs, POINTER_BYTES);
|
||||
pRes->buffer = calloc(numOfExprs, POINTER_BYTES);
|
||||
|
|
|
@ -36,7 +36,7 @@ void * tscTmr;
|
|||
void * tscQhandle;
|
||||
void * tscCheckDiskUsageTmr;
|
||||
int tsInsertHeadSize;
|
||||
int tscRefId;
|
||||
int tscRefId = -1;
|
||||
|
||||
int tscNumOfThreads;
|
||||
|
||||
|
|
|
@ -376,7 +376,7 @@ void tscFreeRegisteredSqlObj(void *pSql) {
|
|||
tscDebug("%p free sqlObj completed, tscObj:%p ref:%d", *p, pTscObj, ref);
|
||||
if (ref == 0) {
|
||||
tscDebug("%p all sqlObj freed, free tscObj:%p", *p, pTscObj);
|
||||
taosRemoveRef(tscRefId, pTscObj);
|
||||
taosRemoveRef(tscRefId, pTscObj->rid);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -119,6 +119,33 @@ void tdResetTSchemaBuilder(STSchemaBuilder *pBuilder, int32_t version);
|
|||
int tdAddColToSchema(STSchemaBuilder *pBuilder, int8_t type, int16_t colId, int16_t bytes);
|
||||
STSchema *tdGetSchemaFromBuilder(STSchemaBuilder *pBuilder);
|
||||
|
||||
// ----------------- Semantic timestamp key definition
|
||||
typedef uint64_t TKEY;
|
||||
|
||||
#define TKEY_INVALID UINT64_MAX
|
||||
#define TKEY_NULL TKEY_INVALID
|
||||
#define TKEY_NEGATIVE_FLAG (((TKEY)1) << 63)
|
||||
#define TKEY_DELETE_FLAG (((TKEY)1) << 62)
|
||||
#define TKEY_VALUE_FILTER (~(TKEY_NEGATIVE_FLAG | TKEY_DELETE_FLAG))
|
||||
|
||||
#define TKEY_IS_NEGATIVE(tkey) (((tkey)&TKEY_NEGATIVE_FLAG) != 0)
|
||||
#define TKEY_IS_DELETED(tkey) (((tkey)&TKEY_DELETE_FLAG) != 0)
|
||||
#define tdSetTKEYDeleted(tkey) ((tkey) | TKEY_DELETE_FLAG)
|
||||
#define tdGetTKEY(key) (((TKEY)ABS(key)) | (TKEY_NEGATIVE_FLAG & (TKEY)(key)))
|
||||
#define tdGetKey(tkey) (((TSKEY)((tkey)&TKEY_VALUE_FILTER)) * (TKEY_IS_NEGATIVE(tkey) ? -1 : 1))
|
||||
|
||||
static FORCE_INLINE int tkeyComparFn(const void *tkey1, const void *tkey2) {
|
||||
TSKEY key1 = tdGetKey(*(TKEY *)tkey1);
|
||||
TSKEY key2 = tdGetKey(*(TKEY *)tkey2);
|
||||
|
||||
if (key1 < key2) {
|
||||
return -1;
|
||||
} else if (key1 > key2) {
|
||||
return 1;
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
// ----------------- Data row structure
|
||||
|
||||
/* A data row, the format is like below:
|
||||
|
@ -129,6 +156,8 @@ STSchema *tdGetSchemaFromBuilder(STSchemaBuilder *pBuilder);
|
|||
* +----------+----------+---------------------------------+---------------------------------+
|
||||
* | len | sversion | First part | Second part |
|
||||
* +----------+----------+---------------------------------+---------------------------------+
|
||||
*
|
||||
* NOTE: timestamp in this row structure is TKEY instead of TSKEY
|
||||
*/
|
||||
typedef void *SDataRow;
|
||||
|
||||
|
@ -137,11 +166,13 @@ typedef void *SDataRow;
|
|||
#define dataRowLen(r) (*(uint16_t *)(r))
|
||||
#define dataRowVersion(r) *(int16_t *)POINTER_SHIFT(r, sizeof(int16_t))
|
||||
#define dataRowTuple(r) POINTER_SHIFT(r, TD_DATA_ROW_HEAD_SIZE)
|
||||
#define dataRowKey(r) (*(TSKEY *)(dataRowTuple(r)))
|
||||
#define dataRowTKey(r) (*(TKEY *)(dataRowTuple(r)))
|
||||
#define dataRowKey(r) tdGetKey(dataRowTKey(r))
|
||||
#define dataRowSetLen(r, l) (dataRowLen(r) = (l))
|
||||
#define dataRowSetVersion(r, v) (dataRowVersion(r) = (v))
|
||||
#define dataRowCpy(dst, r) memcpy((dst), (r), dataRowLen(r))
|
||||
#define dataRowMaxBytesFromSchema(s) (schemaTLen(s) + TD_DATA_ROW_HEAD_SIZE)
|
||||
#define dataRowDeleted(r) TKEY_IS_DELETED(dataRowTKey(r))
|
||||
|
||||
SDataRow tdNewDataRowFromSchema(STSchema *pSchema);
|
||||
void tdFreeDataRow(SDataRow row);
|
||||
|
@ -154,16 +185,18 @@ static FORCE_INLINE int tdAppendColVal(SDataRow row, void *value, int8_t type, i
|
|||
int32_t toffset = offset + TD_DATA_ROW_HEAD_SIZE;
|
||||
char * ptr = (char *)POINTER_SHIFT(row, dataRowLen(row));
|
||||
|
||||
switch (type) {
|
||||
case TSDB_DATA_TYPE_BINARY:
|
||||
case TSDB_DATA_TYPE_NCHAR:
|
||||
*(VarDataOffsetT *)POINTER_SHIFT(row, toffset) = dataRowLen(row);
|
||||
memcpy(ptr, value, varDataTLen(value));
|
||||
dataRowLen(row) += varDataTLen(value);
|
||||
break;
|
||||
default:
|
||||
if (IS_VAR_DATA_TYPE(type)) {
|
||||
*(VarDataOffsetT *)POINTER_SHIFT(row, toffset) = dataRowLen(row);
|
||||
memcpy(ptr, value, varDataTLen(value));
|
||||
dataRowLen(row) += varDataTLen(value);
|
||||
} else {
|
||||
if (offset == 0) {
|
||||
ASSERT(type == TSDB_DATA_TYPE_TIMESTAMP);
|
||||
TKEY tvalue = tdGetTKEY(*(TSKEY *)value);
|
||||
memcpy(POINTER_SHIFT(row, toffset), (void *)(&tvalue), TYPE_BYTES[type]);
|
||||
} else {
|
||||
memcpy(POINTER_SHIFT(row, toffset), value, TYPE_BYTES[type]);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
@ -171,12 +204,10 @@ static FORCE_INLINE int tdAppendColVal(SDataRow row, void *value, int8_t type, i
|
|||
|
||||
// NOTE: offset here including the header size
|
||||
static FORCE_INLINE void *tdGetRowDataOfCol(SDataRow row, int8_t type, int32_t offset) {
|
||||
switch (type) {
|
||||
case TSDB_DATA_TYPE_BINARY:
|
||||
case TSDB_DATA_TYPE_NCHAR:
|
||||
return POINTER_SHIFT(row, *(VarDataOffsetT *)POINTER_SHIFT(row, offset));
|
||||
default:
|
||||
return POINTER_SHIFT(row, offset);
|
||||
if (IS_VAR_DATA_TYPE(type)) {
|
||||
return POINTER_SHIFT(row, *(VarDataOffsetT *)POINTER_SHIFT(row, offset));
|
||||
} else {
|
||||
return POINTER_SHIFT(row, offset);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -196,7 +227,6 @@ static FORCE_INLINE void dataColReset(SDataCol *pDataCol) { pDataCol->len = 0; }
|
|||
|
||||
void dataColInit(SDataCol *pDataCol, STColumn *pCol, void **pBuf, int maxPoints);
|
||||
void dataColAppendVal(SDataCol *pCol, void *value, int numOfRows, int maxPoints);
|
||||
void dataColPopPoints(SDataCol *pCol, int pointsToPop, int numOfRows);
|
||||
void dataColSetOffset(SDataCol *pCol, int nEle);
|
||||
|
||||
bool isNEleNull(SDataCol *pCol, int nEle);
|
||||
|
@ -204,28 +234,20 @@ void dataColSetNEleNull(SDataCol *pCol, int nEle, int maxPoints);
|
|||
|
||||
// Get the data pointer from a column-wised data
|
||||
static FORCE_INLINE void *tdGetColDataOfRow(SDataCol *pCol, int row) {
|
||||
switch (pCol->type) {
|
||||
case TSDB_DATA_TYPE_BINARY:
|
||||
case TSDB_DATA_TYPE_NCHAR:
|
||||
return POINTER_SHIFT(pCol->pData, pCol->dataOff[row]);
|
||||
break;
|
||||
|
||||
default:
|
||||
return POINTER_SHIFT(pCol->pData, TYPE_BYTES[pCol->type] * row);
|
||||
break;
|
||||
if (IS_VAR_DATA_TYPE(pCol->type)) {
|
||||
return POINTER_SHIFT(pCol->pData, pCol->dataOff[row]);
|
||||
} else {
|
||||
return POINTER_SHIFT(pCol->pData, TYPE_BYTES[pCol->type] * row);
|
||||
}
|
||||
}
|
||||
|
||||
static FORCE_INLINE int32_t dataColGetNEleLen(SDataCol *pDataCol, int rows) {
|
||||
ASSERT(rows > 0);
|
||||
|
||||
switch (pDataCol->type) {
|
||||
case TSDB_DATA_TYPE_BINARY:
|
||||
case TSDB_DATA_TYPE_NCHAR:
|
||||
return pDataCol->dataOff[rows - 1] + varDataTLen(tdGetColDataOfRow(pDataCol, rows - 1));
|
||||
break;
|
||||
default:
|
||||
return TYPE_BYTES[pDataCol->type] * rows;
|
||||
if (IS_VAR_DATA_TYPE(pDataCol->type)) {
|
||||
return pDataCol->dataOff[rows - 1] + varDataTLen(tdGetColDataOfRow(pDataCol, rows - 1));
|
||||
} else {
|
||||
return TYPE_BYTES[pDataCol->type] * rows;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -243,9 +265,14 @@ typedef struct {
|
|||
} SDataCols;
|
||||
|
||||
#define keyCol(pCols) (&((pCols)->cols[0])) // Key column
|
||||
#define dataColsKeyAt(pCols, idx) ((TSKEY *)(keyCol(pCols)->pData))[(idx)]
|
||||
#define dataColsKeyFirst(pCols) dataColsKeyAt(pCols, 0)
|
||||
#define dataColsKeyLast(pCols) ((pCols->numOfRows == 0) ? 0 : dataColsKeyAt(pCols, (pCols)->numOfRows - 1))
|
||||
#define dataColsTKeyAt(pCols, idx) ((TKEY *)(keyCol(pCols)->pData))[(idx)]
|
||||
#define dataColsKeyAt(pCols, idx) tdGetKey(dataColsTKeyAt(pCols, idx))
|
||||
#define dataColsTKeyFirst(pCols) (((pCols)->numOfRows == 0) ? TKEY_INVALID : dataColsTKeyAt(pCols, 0))
|
||||
#define dataColsKeyFirst(pCols) (((pCols)->numOfRows == 0) ? TSDB_DATA_TIMESTAMP_NULL : dataColsKeyAt(pCols, 0))
|
||||
#define dataColsTKeyLast(pCols) \
|
||||
(((pCols)->numOfRows == 0) ? TKEY_INVALID : dataColsTKeyAt(pCols, (pCols)->numOfRows - 1))
|
||||
#define dataColsKeyLast(pCols) \
|
||||
(((pCols)->numOfRows == 0) ? TSDB_DATA_TIMESTAMP_NULL : dataColsKeyAt(pCols, (pCols)->numOfRows - 1))
|
||||
|
||||
SDataCols *tdNewDataCols(int maxRowSize, int maxCols, int maxRows);
|
||||
void tdResetDataCols(SDataCols *pCols);
|
||||
|
@ -253,10 +280,7 @@ int tdInitDataCols(SDataCols *pCols, STSchema *pSchema);
|
|||
SDataCols *tdDupDataCols(SDataCols *pCols, bool keepData);
|
||||
void tdFreeDataCols(SDataCols *pCols);
|
||||
void tdAppendDataRowToDataCol(SDataRow row, STSchema *pSchema, SDataCols *pCols);
|
||||
void tdPopDataColsPoints(SDataCols *pCols, int pointsToPop); //!!!!
|
||||
int tdMergeDataCols(SDataCols *target, SDataCols *src, int rowsToMerge);
|
||||
void tdMergeTwoDataCols(SDataCols *target, SDataCols *src1, int *iter1, int limit1, SDataCols *src2, int *iter2,
|
||||
int limit2, int tRows);
|
||||
|
||||
// ----------------- K-V data row structure
|
||||
/*
|
||||
|
|
|
@ -88,6 +88,7 @@ extern int16_t tsWAL;
|
|||
extern int32_t tsFsyncPeriod;
|
||||
extern int32_t tsReplications;
|
||||
extern int32_t tsQuorum;
|
||||
extern int32_t tsUpdate;
|
||||
|
||||
// balance
|
||||
extern int32_t tsEnableBalance;
|
||||
|
|
|
@ -18,6 +18,9 @@
|
|||
#include "tcoding.h"
|
||||
#include "wchar.h"
|
||||
|
||||
static void tdMergeTwoDataCols(SDataCols *target, SDataCols *src1, int *iter1, int limit1, SDataCols *src2, int *iter2,
|
||||
int limit2, int tRows);
|
||||
|
||||
/**
|
||||
* Duplicate the schema and return a new object
|
||||
*/
|
||||
|
@ -202,7 +205,7 @@ void dataColInit(SDataCol *pDataCol, STColumn *pCol, void **pBuf, int maxPoints)
|
|||
pDataCol->offset = colOffset(pCol) + TD_DATA_ROW_HEAD_SIZE;
|
||||
|
||||
pDataCol->len = 0;
|
||||
if (pDataCol->type == TSDB_DATA_TYPE_BINARY || pDataCol->type == TSDB_DATA_TYPE_NCHAR) {
|
||||
if (IS_VAR_DATA_TYPE(pDataCol->type)) {
|
||||
pDataCol->dataOff = (VarDataOffsetT *)(*pBuf);
|
||||
pDataCol->pData = POINTER_SHIFT(*pBuf, sizeof(VarDataOffsetT) * maxPoints);
|
||||
pDataCol->spaceSize = pDataCol->bytes * maxPoints;
|
||||
|
@ -215,60 +218,29 @@ void dataColInit(SDataCol *pDataCol, STColumn *pCol, void **pBuf, int maxPoints)
|
|||
}
|
||||
}
|
||||
|
||||
// value from timestamp should be TKEY here instead of TSKEY
|
||||
void dataColAppendVal(SDataCol *pCol, void *value, int numOfRows, int maxPoints) {
|
||||
ASSERT(pCol != NULL && value != NULL);
|
||||
|
||||
switch (pCol->type) {
|
||||
case TSDB_DATA_TYPE_BINARY:
|
||||
case TSDB_DATA_TYPE_NCHAR:
|
||||
// set offset
|
||||
pCol->dataOff[numOfRows] = pCol->len;
|
||||
// Copy data
|
||||
memcpy(POINTER_SHIFT(pCol->pData, pCol->len), value, varDataTLen(value));
|
||||
// Update the length
|
||||
pCol->len += varDataTLen(value);
|
||||
break;
|
||||
default:
|
||||
ASSERT(pCol->len == TYPE_BYTES[pCol->type] * numOfRows);
|
||||
memcpy(POINTER_SHIFT(pCol->pData, pCol->len), value, pCol->bytes);
|
||||
pCol->len += pCol->bytes;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void dataColPopPoints(SDataCol *pCol, int pointsToPop, int numOfRows) {
|
||||
int pointsLeft = numOfRows - pointsToPop;
|
||||
|
||||
ASSERT(pointsLeft > 0);
|
||||
|
||||
if (pCol->type == TSDB_DATA_TYPE_BINARY || pCol->type == TSDB_DATA_TYPE_NCHAR) {
|
||||
ASSERT(pCol->len > 0);
|
||||
VarDataOffsetT toffset = pCol->dataOff[pointsToPop];
|
||||
pCol->len = pCol->len - toffset;
|
||||
ASSERT(pCol->len > 0);
|
||||
memmove(pCol->pData, POINTER_SHIFT(pCol->pData, toffset), pCol->len);
|
||||
dataColSetOffset(pCol, pointsLeft);
|
||||
if (IS_VAR_DATA_TYPE(pCol->type)) {
|
||||
// set offset
|
||||
pCol->dataOff[numOfRows] = pCol->len;
|
||||
// Copy data
|
||||
memcpy(POINTER_SHIFT(pCol->pData, pCol->len), value, varDataTLen(value));
|
||||
// Update the length
|
||||
pCol->len += varDataTLen(value);
|
||||
} else {
|
||||
ASSERT(pCol->len == TYPE_BYTES[pCol->type] * numOfRows);
|
||||
pCol->len = TYPE_BYTES[pCol->type] * pointsLeft;
|
||||
memmove(pCol->pData, POINTER_SHIFT(pCol->pData, TYPE_BYTES[pCol->type] * pointsToPop), pCol->len);
|
||||
memcpy(POINTER_SHIFT(pCol->pData, pCol->len), value, pCol->bytes);
|
||||
pCol->len += pCol->bytes;
|
||||
}
|
||||
}
|
||||
|
||||
bool isNEleNull(SDataCol *pCol, int nEle) {
|
||||
switch (pCol->type) {
|
||||
case TSDB_DATA_TYPE_BINARY:
|
||||
case TSDB_DATA_TYPE_NCHAR:
|
||||
for (int i = 0; i < nEle; i++) {
|
||||
if (!isNull(tdGetColDataOfRow(pCol, i), pCol->type)) return false;
|
||||
}
|
||||
return true;
|
||||
default:
|
||||
for (int i = 0; i < nEle; i++) {
|
||||
if (!isNull(tdGetColDataOfRow(pCol, i), pCol->type)) return false;
|
||||
}
|
||||
return true;
|
||||
for (int i = 0; i < nEle; i++) {
|
||||
if (!isNull(tdGetColDataOfRow(pCol, i), pCol->type)) return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
void dataColSetNullAt(SDataCol *pCol, int index) {
|
||||
|
@ -390,7 +362,7 @@ SDataCols *tdDupDataCols(SDataCols *pDataCols, bool keepData) {
|
|||
pRet->cols[i].spaceSize = pDataCols->cols[i].spaceSize;
|
||||
pRet->cols[i].pData = (void *)((char *)pRet->buf + ((char *)(pDataCols->cols[i].pData) - (char *)(pDataCols->buf)));
|
||||
|
||||
if (pRet->cols[i].type == TSDB_DATA_TYPE_BINARY || pRet->cols[i].type == TSDB_DATA_TYPE_NCHAR) {
|
||||
if (IS_VAR_DATA_TYPE(pRet->cols[i].type)) {
|
||||
ASSERT(pDataCols->cols[i].dataOff != NULL);
|
||||
pRet->cols[i].dataOff =
|
||||
(int32_t *)((char *)pRet->buf + ((char *)(pDataCols->cols[i].dataOff) - (char *)(pDataCols->buf)));
|
||||
|
@ -400,7 +372,7 @@ SDataCols *tdDupDataCols(SDataCols *pDataCols, bool keepData) {
|
|||
pRet->cols[i].len = pDataCols->cols[i].len;
|
||||
if (pDataCols->cols[i].len > 0) {
|
||||
memcpy(pRet->cols[i].pData, pDataCols->cols[i].pData, pDataCols->cols[i].len);
|
||||
if (pRet->cols[i].type == TSDB_DATA_TYPE_BINARY || pRet->cols[i].type == TSDB_DATA_TYPE_NCHAR) {
|
||||
if (IS_VAR_DATA_TYPE(pRet->cols[i].type)) {
|
||||
memcpy(pRet->cols[i].dataOff, pDataCols->cols[i].dataOff, sizeof(VarDataOffsetT) * pDataCols->maxPoints);
|
||||
}
|
||||
}
|
||||
|
@ -420,58 +392,54 @@ void tdResetDataCols(SDataCols *pCols) {
|
|||
}
|
||||
|
||||
void tdAppendDataRowToDataCol(SDataRow row, STSchema *pSchema, SDataCols *pCols) {
|
||||
ASSERT(dataColsKeyLast(pCols) < dataRowKey(row));
|
||||
ASSERT(pCols->numOfRows == 0 || dataColsKeyLast(pCols) < dataRowKey(row));
|
||||
|
||||
int rcol = 0;
|
||||
int dcol = 0;
|
||||
|
||||
while (dcol < pCols->numOfCols) {
|
||||
SDataCol *pDataCol = &(pCols->cols[dcol]);
|
||||
if (rcol >= schemaNCols(pSchema)) {
|
||||
dataColSetNullAt(pDataCol, pCols->numOfRows);
|
||||
dcol++;
|
||||
continue;
|
||||
if (dataRowDeleted(row)) {
|
||||
for (; dcol < pCols->numOfCols; dcol++) {
|
||||
SDataCol *pDataCol = &(pCols->cols[dcol]);
|
||||
if (dcol == 0) {
|
||||
dataColAppendVal(pDataCol, dataRowTuple(row), pCols->numOfRows, pCols->maxPoints);
|
||||
} else {
|
||||
dataColSetNullAt(pDataCol, pCols->numOfRows);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
while (dcol < pCols->numOfCols) {
|
||||
SDataCol *pDataCol = &(pCols->cols[dcol]);
|
||||
if (rcol >= schemaNCols(pSchema)) {
|
||||
dataColSetNullAt(pDataCol, pCols->numOfRows);
|
||||
dcol++;
|
||||
continue;
|
||||
}
|
||||
|
||||
STColumn *pRowCol = schemaColAt(pSchema, rcol);
|
||||
if (pRowCol->colId == pDataCol->colId) {
|
||||
void *value = tdGetRowDataOfCol(row, pRowCol->type, pRowCol->offset+TD_DATA_ROW_HEAD_SIZE);
|
||||
dataColAppendVal(pDataCol, value, pCols->numOfRows, pCols->maxPoints);
|
||||
dcol++;
|
||||
rcol++;
|
||||
} else if (pRowCol->colId < pDataCol->colId) {
|
||||
rcol++;
|
||||
} else {
|
||||
dataColSetNullAt(pDataCol, pCols->numOfRows);
|
||||
dcol++;
|
||||
STColumn *pRowCol = schemaColAt(pSchema, rcol);
|
||||
if (pRowCol->colId == pDataCol->colId) {
|
||||
void *value = tdGetRowDataOfCol(row, pRowCol->type, pRowCol->offset + TD_DATA_ROW_HEAD_SIZE);
|
||||
dataColAppendVal(pDataCol, value, pCols->numOfRows, pCols->maxPoints);
|
||||
dcol++;
|
||||
rcol++;
|
||||
} else if (pRowCol->colId < pDataCol->colId) {
|
||||
rcol++;
|
||||
} else {
|
||||
dataColSetNullAt(pDataCol, pCols->numOfRows);
|
||||
dcol++;
|
||||
}
|
||||
}
|
||||
}
|
||||
pCols->numOfRows++;
|
||||
}
|
||||
|
||||
// Pop pointsToPop points from the SDataCols
|
||||
void tdPopDataColsPoints(SDataCols *pCols, int pointsToPop) {
|
||||
int pointsLeft = pCols->numOfRows - pointsToPop;
|
||||
if (pointsLeft <= 0) {
|
||||
tdResetDataCols(pCols);
|
||||
return;
|
||||
}
|
||||
|
||||
for (int iCol = 0; iCol < pCols->numOfCols; iCol++) {
|
||||
SDataCol *pCol = pCols->cols + iCol;
|
||||
dataColPopPoints(pCol, pointsToPop, pCols->numOfRows);
|
||||
}
|
||||
pCols->numOfRows = pointsLeft;
|
||||
}
|
||||
|
||||
int tdMergeDataCols(SDataCols *target, SDataCols *source, int rowsToMerge) {
|
||||
ASSERT(rowsToMerge > 0 && rowsToMerge <= source->numOfRows);
|
||||
ASSERT(target->numOfRows + rowsToMerge <= target->maxPoints);
|
||||
ASSERT(target->numOfCols == source->numOfCols);
|
||||
|
||||
SDataCols *pTarget = NULL;
|
||||
|
||||
if (dataColsKeyLast(target) < dataColsKeyFirst(source)) { // No overlap
|
||||
ASSERT(target->numOfRows + rowsToMerge <= target->maxPoints);
|
||||
for (int i = 0; i < rowsToMerge; i++) {
|
||||
for (int j = 0; j < source->numOfCols; j++) {
|
||||
if (source->cols[j].len > 0) {
|
||||
|
@ -499,17 +467,23 @@ _err:
|
|||
return -1;
|
||||
}
|
||||
|
||||
void tdMergeTwoDataCols(SDataCols *target, SDataCols *src1, int *iter1, int limit1, SDataCols *src2, int *iter2, int limit2, int tRows) {
|
||||
// src2 data has more priority than src1
|
||||
static void tdMergeTwoDataCols(SDataCols *target, SDataCols *src1, int *iter1, int limit1, SDataCols *src2, int *iter2,
|
||||
int limit2, int tRows) {
|
||||
tdResetDataCols(target);
|
||||
ASSERT(limit1 <= src1->numOfRows && limit2 <= src2->numOfRows);
|
||||
|
||||
while (target->numOfRows < tRows) {
|
||||
if (*iter1 >= limit1 && *iter2 >= limit2) break;
|
||||
|
||||
TSKEY key1 = (*iter1 >= limit1) ? INT64_MAX : ((TSKEY *)(src1->cols[0].pData))[*iter1];
|
||||
TSKEY key2 = (*iter2 >= limit2) ? INT64_MAX : ((TSKEY *)(src2->cols[0].pData))[*iter2];
|
||||
TSKEY key1 = (*iter1 >= limit1) ? INT64_MAX : dataColsKeyAt(src1, *iter1);
|
||||
TKEY tkey1 = (*iter1 >= limit1) ? TKEY_NULL : dataColsTKeyAt(src1, *iter1);
|
||||
TSKEY key2 = (*iter2 >= limit2) ? INT64_MAX : dataColsKeyAt(src2, *iter2);
|
||||
TKEY tkey2 = (*iter2 >= limit2) ? TKEY_NULL : dataColsTKeyAt(src2, *iter2);
|
||||
|
||||
if (key1 <= key2) {
|
||||
ASSERT(tkey1 == TKEY_NULL || (!TKEY_IS_DELETED(tkey1)));
|
||||
|
||||
if (key1 < key2) {
|
||||
for (int i = 0; i < src1->numOfCols; i++) {
|
||||
ASSERT(target->cols[i].type == src1->cols[i].type);
|
||||
if (src1->cols[i].len > 0) {
|
||||
|
@ -520,19 +494,23 @@ void tdMergeTwoDataCols(SDataCols *target, SDataCols *src1, int *iter1, int limi
|
|||
|
||||
target->numOfRows++;
|
||||
(*iter1)++;
|
||||
if (key1 == key2) (*iter2)++;
|
||||
} else {
|
||||
for (int i = 0; i < src2->numOfCols; i++) {
|
||||
ASSERT(target->cols[i].type == src2->cols[i].type);
|
||||
if (src2->cols[i].len > 0) {
|
||||
dataColAppendVal(&(target->cols[i]), tdGetColDataOfRow(src2->cols + i, *iter2), target->numOfRows,
|
||||
target->maxPoints);
|
||||
} else if (key1 >= key2) {
|
||||
if ((key1 > key2) || (key1 == key2 && !TKEY_IS_DELETED(tkey2))) {
|
||||
for (int i = 0; i < src2->numOfCols; i++) {
|
||||
ASSERT(target->cols[i].type == src2->cols[i].type);
|
||||
if (src2->cols[i].len > 0) {
|
||||
dataColAppendVal(&(target->cols[i]), tdGetColDataOfRow(src2->cols + i, *iter2), target->numOfRows,
|
||||
target->maxPoints);
|
||||
}
|
||||
}
|
||||
target->numOfRows++;
|
||||
}
|
||||
|
||||
target->numOfRows++;
|
||||
(*iter2)++;
|
||||
if (key1 == key2) (*iter1)++;
|
||||
}
|
||||
|
||||
ASSERT(target->numOfRows <= target->maxPoints);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -120,6 +120,7 @@ int16_t tsWAL = TSDB_DEFAULT_WAL_LEVEL;
|
|||
int32_t tsFsyncPeriod = TSDB_DEFAULT_FSYNC_PERIOD;
|
||||
int32_t tsReplications = TSDB_DEFAULT_DB_REPLICA_OPTION;
|
||||
int32_t tsQuorum = TSDB_DEFAULT_DB_QUORUM_OPTION;
|
||||
int32_t tsUpdate = TSDB_DEFAULT_DB_UPDATE_OPTION;
|
||||
int32_t tsMaxVgroupsPerDb = 0;
|
||||
int32_t tsMinTablePerVnode = TSDB_TABLES_STEP;
|
||||
int32_t tsMaxTablePerVnode = TSDB_DEFAULT_TABLES;
|
||||
|
@ -786,6 +787,16 @@ static void doInitGlobalConfig(void) {
|
|||
cfg.unitType = TAOS_CFG_UTYPE_NONE;
|
||||
taosInitConfigOption(cfg);
|
||||
|
||||
cfg.option = "update";
|
||||
cfg.ptr = &tsUpdate;
|
||||
cfg.valType = TAOS_CFG_VTYPE_INT32;
|
||||
cfg.cfgType = TSDB_CFG_CTYPE_B_CONFIG | TSDB_CFG_CTYPE_B_SHOW;
|
||||
cfg.minValue = TSDB_MIN_DB_UPDATE;
|
||||
cfg.maxValue = TSDB_MAX_DB_UPDATE;
|
||||
cfg.ptrLength = 0;
|
||||
cfg.unitType = TAOS_CFG_UTYPE_NONE;
|
||||
taosInitConfigOption(cfg);
|
||||
|
||||
cfg.option = "mqttHostName";
|
||||
cfg.ptr = tsMqttHostName;
|
||||
cfg.valType = TAOS_CFG_VTYPE_STRING;
|
||||
|
|
|
@ -52,7 +52,6 @@ public class TSDBConnection implements Connection {
|
|||
|
||||
public TSDBConnection(Properties info, TSDBDatabaseMetaData meta) throws SQLException {
|
||||
this.dbMetaData = meta;
|
||||
|
||||
connect(info.getProperty(TSDBDriver.PROPERTY_KEY_HOST),
|
||||
Integer.parseInt(info.getProperty(TSDBDriver.PROPERTY_KEY_PORT, "0")),
|
||||
info.getProperty(TSDBDriver.PROPERTY_KEY_DBNAME), info.getProperty(TSDBDriver.PROPERTY_KEY_USER),
|
||||
|
@ -197,12 +196,13 @@ public class TSDBConnection implements Connection {
|
|||
}
|
||||
|
||||
public SQLWarning getWarnings() throws SQLException {
|
||||
//todo: implement getWarnings according to the warning messages returned from TDengine
|
||||
throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG);
|
||||
}
|
||||
|
||||
public void clearWarnings() throws SQLException {
|
||||
// left blank to support HikariCP connection
|
||||
//todo: implement getWarnings according to the warning messages returned from TDengine
|
||||
//todo: implement clearWarnings according to the warning messages returned from TDengine
|
||||
}
|
||||
|
||||
public Statement createStatement(int resultSetType, int resultSetConcurrency) throws SQLException {
|
||||
|
|
|
@ -96,7 +96,7 @@ public class TSDBDatabaseMetaData implements java.sql.DatabaseMetaData {
|
|||
}
|
||||
|
||||
public int getDriverMajorVersion() {
|
||||
return 0;
|
||||
return 2;
|
||||
}
|
||||
|
||||
public int getDriverMinorVersion() {
|
||||
|
|
|
@ -14,13 +14,9 @@
|
|||
*****************************************************************************/
|
||||
package com.taosdata.jdbc;
|
||||
|
||||
|
||||
import java.io.*;
|
||||
|
||||
import java.sql.*;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Properties;
|
||||
import java.util.*;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
/**
|
||||
|
@ -44,76 +40,53 @@ import java.util.logging.Logger;
|
|||
*/
|
||||
public class TSDBDriver implements java.sql.Driver {
|
||||
|
||||
|
||||
@Deprecated
|
||||
private static final String URL_PREFIX1 = "jdbc:TSDB://";
|
||||
|
||||
private static final String URL_PREFIX = "jdbc:TAOS://";
|
||||
|
||||
/**
|
||||
* Key used to retrieve the database value from the properties instance passed
|
||||
* to the driver.
|
||||
*/
|
||||
public static final String PROPERTY_KEY_DBNAME = "dbname";
|
||||
|
||||
/**
|
||||
* Key used to retrieve the host value from the properties instance passed to
|
||||
* the driver.
|
||||
*/
|
||||
public static final String PROPERTY_KEY_HOST = "host";
|
||||
/**
|
||||
* Key used to retrieve the password value from the properties instance passed
|
||||
* to the driver.
|
||||
*/
|
||||
public static final String PROPERTY_KEY_PASSWORD = "password";
|
||||
|
||||
/**
|
||||
* Key used to retrieve the port number value from the properties instance
|
||||
* passed to the driver.
|
||||
*/
|
||||
public static final String PROPERTY_KEY_PORT = "port";
|
||||
|
||||
/**
|
||||
* Key used to retrieve the database value from the properties instance passed
|
||||
* to the driver.
|
||||
*/
|
||||
public static final String PROPERTY_KEY_DBNAME = "dbname";
|
||||
/**
|
||||
* Key used to retrieve the user value from the properties instance passed to
|
||||
* the driver.
|
||||
*/
|
||||
public static final String PROPERTY_KEY_USER = "user";
|
||||
|
||||
|
||||
/**
|
||||
* Key used to retrieve the password value from the properties instance passed
|
||||
* to the driver.
|
||||
*/
|
||||
public static final String PROPERTY_KEY_PASSWORD = "password";
|
||||
/**
|
||||
* Key for the configuration file directory of TSDB client in properties instance
|
||||
*/
|
||||
public static final String PROPERTY_KEY_CONFIG_DIR = "cfgdir";
|
||||
|
||||
/**
|
||||
* Key for the timezone used by the TSDB client in properties instance
|
||||
*/
|
||||
public static final String PROPERTY_KEY_TIME_ZONE = "timezone";
|
||||
|
||||
/**
|
||||
* Key for the locale used by the TSDB client in properties instance
|
||||
*/
|
||||
public static final String PROPERTY_KEY_LOCALE = "locale";
|
||||
|
||||
|
||||
/**
|
||||
* Key for the char encoding used by the TSDB client in properties instance
|
||||
*/
|
||||
public static final String PROPERTY_KEY_CHARSET = "charset";
|
||||
|
||||
public static final String PROPERTY_KEY_PROTOCOL = "protocol";
|
||||
|
||||
|
||||
/**
|
||||
* Index for port coming out of parseHostPortPair().
|
||||
*/
|
||||
public final static int PORT_NUMBER_INDEX = 1;
|
||||
|
||||
/**
|
||||
* Index for host coming out of parseHostPortPair().
|
||||
*/
|
||||
public final static int HOST_NAME_INDEX = 0;
|
||||
|
||||
private TSDBDatabaseMetaData dbMetaData = null;
|
||||
|
||||
static {
|
||||
|
@ -169,9 +142,11 @@ public class TSDBDriver implements java.sql.Driver {
|
|||
}
|
||||
|
||||
public Connection connect(String url, Properties info) throws SQLException {
|
||||
if (url == null) {
|
||||
if (url == null)
|
||||
throw new SQLException(TSDBConstants.WrapErrMsg("url is not set!"));
|
||||
}
|
||||
|
||||
if (!acceptsURL(url))
|
||||
return null;
|
||||
|
||||
Properties props = null;
|
||||
if ((props = parseURL(url, info)) == null) {
|
||||
|
@ -179,7 +154,10 @@ public class TSDBDriver implements java.sql.Driver {
|
|||
}
|
||||
|
||||
//load taos.cfg start
|
||||
if (info.getProperty(TSDBDriver.PROPERTY_KEY_HOST) == null && info.getProperty(TSDBDriver.PROPERTY_KEY_PORT) == null) {
|
||||
if ((info.getProperty(TSDBDriver.PROPERTY_KEY_HOST) == null ||
|
||||
info.getProperty(TSDBDriver.PROPERTY_KEY_HOST).isEmpty()) && (
|
||||
info.getProperty(TSDBDriver.PROPERTY_KEY_PORT) == null ||
|
||||
info.getProperty(TSDBDriver.PROPERTY_KEY_PORT).isEmpty())) {
|
||||
File cfgDir = loadConfigDir(info.getProperty(TSDBDriver.PROPERTY_KEY_CONFIG_DIR));
|
||||
File cfgFile = cfgDir.listFiles((dir, name) -> "taos.cfg".equalsIgnoreCase(name))[0];
|
||||
List<String> endpoints = loadConfigEndpoints(cfgFile);
|
||||
|
@ -190,7 +168,9 @@ public class TSDBDriver implements java.sql.Driver {
|
|||
}
|
||||
|
||||
try {
|
||||
TSDBJNIConnector.init((String) props.get(PROPERTY_KEY_CONFIG_DIR), (String) props.get(PROPERTY_KEY_LOCALE), (String) props.get(PROPERTY_KEY_CHARSET),
|
||||
TSDBJNIConnector.init((String) props.get(PROPERTY_KEY_CONFIG_DIR),
|
||||
(String) props.get(PROPERTY_KEY_LOCALE),
|
||||
(String) props.get(PROPERTY_KEY_CHARSET),
|
||||
(String) props.get(PROPERTY_KEY_TIME_ZONE));
|
||||
Connection newConn = new TSDBConnection(props, this.dbMetaData);
|
||||
return newConn;
|
||||
|
@ -208,43 +188,15 @@ public class TSDBDriver implements java.sql.Driver {
|
|||
}
|
||||
|
||||
/**
|
||||
* Parses hostPortPair in the form of [host][:port] into an array, with the
|
||||
* element of index HOST_NAME_INDEX being the host (or null if not specified),
|
||||
* and the element of index PORT_NUMBER_INDEX being the port (or null if not
|
||||
* specified).
|
||||
*
|
||||
* @param hostPortPair host and port in form of of [host][:port]
|
||||
* @return array containing host and port as Strings
|
||||
* @throws SQLException if a parse error occurs
|
||||
* @param url the URL of the database
|
||||
* @return <code>true</code> if this driver understands the given URL;
|
||||
* <code>false</code> otherwise
|
||||
* @throws SQLException if a database access error occurs or the url is {@code null}
|
||||
*/
|
||||
protected static String[] parseHostPortPair(String hostPortPair) throws SQLException {
|
||||
String[] splitValues = new String[2];
|
||||
|
||||
int portIndex = hostPortPair.indexOf(":");
|
||||
|
||||
String hostname = null;
|
||||
|
||||
if (portIndex != -1) {
|
||||
if ((portIndex + 1) < hostPortPair.length()) {
|
||||
String portAsString = hostPortPair.substring(portIndex + 1);
|
||||
hostname = hostPortPair.substring(0, portIndex);
|
||||
|
||||
splitValues[HOST_NAME_INDEX] = hostname;
|
||||
|
||||
splitValues[PORT_NUMBER_INDEX] = portAsString;
|
||||
} else {
|
||||
throw new SQLException(TSDBConstants.WrapErrMsg("port is not proper!"));
|
||||
}
|
||||
} else {
|
||||
splitValues[HOST_NAME_INDEX] = hostPortPair;
|
||||
splitValues[PORT_NUMBER_INDEX] = null;
|
||||
}
|
||||
|
||||
return splitValues;
|
||||
}
|
||||
|
||||
public boolean acceptsURL(String url) throws SQLException {
|
||||
return (url != null && url.length() > 0 && url.trim().length() > 0) && url.startsWith(URL_PREFIX);
|
||||
if (url == null)
|
||||
throw new SQLException(TSDBConstants.WrapErrMsg("url is null"));
|
||||
return (url != null && url.length() > 0 && url.trim().length() > 0) && (url.startsWith(URL_PREFIX) || url.startsWith(URL_PREFIX1));
|
||||
}
|
||||
|
||||
public DriverPropertyInfo[] getPropertyInfo(String url, Properties info) throws SQLException {
|
||||
|
@ -252,15 +204,17 @@ public class TSDBDriver implements java.sql.Driver {
|
|||
info = new Properties();
|
||||
}
|
||||
|
||||
if ((url != null) && (url.startsWith(URL_PREFIX) || url.startsWith(URL_PREFIX1))) {
|
||||
if (acceptsURL(url)) {
|
||||
info = parseURL(url, info);
|
||||
}
|
||||
|
||||
DriverPropertyInfo hostProp = new DriverPropertyInfo(PROPERTY_KEY_HOST, info.getProperty(PROPERTY_KEY_HOST));
|
||||
hostProp.required = true;
|
||||
hostProp.required = false;
|
||||
hostProp.description = "Hostname";
|
||||
|
||||
DriverPropertyInfo portProp = new DriverPropertyInfo(PROPERTY_KEY_PORT, info.getProperty(PROPERTY_KEY_PORT, TSDBConstants.DEFAULT_PORT));
|
||||
portProp.required = false;
|
||||
portProp.description = "Port";
|
||||
|
||||
DriverPropertyInfo dbProp = new DriverPropertyInfo(PROPERTY_KEY_DBNAME, info.getProperty(PROPERTY_KEY_DBNAME));
|
||||
dbProp.required = false;
|
||||
|
@ -268,9 +222,11 @@ public class TSDBDriver implements java.sql.Driver {
|
|||
|
||||
DriverPropertyInfo userProp = new DriverPropertyInfo(PROPERTY_KEY_USER, info.getProperty(PROPERTY_KEY_USER));
|
||||
userProp.required = true;
|
||||
userProp.description = "User";
|
||||
|
||||
DriverPropertyInfo passwordProp = new DriverPropertyInfo(PROPERTY_KEY_PASSWORD, info.getProperty(PROPERTY_KEY_PASSWORD));
|
||||
passwordProp.required = true;
|
||||
passwordProp.description = "Password";
|
||||
|
||||
DriverPropertyInfo[] propertyInfo = new DriverPropertyInfo[5];
|
||||
propertyInfo[0] = hostProp;
|
||||
|
@ -283,20 +239,68 @@ public class TSDBDriver implements java.sql.Driver {
|
|||
}
|
||||
|
||||
/**
|
||||
* example: jdbc:TSDB://127.0.0.1:0/db?user=root&password=your_password
|
||||
* example: jdbc:TAOS://127.0.0.1:0/db?user=root&password=your_password
|
||||
*/
|
||||
public Properties parseURL(String url, Properties defaults) throws java.sql.SQLException {
|
||||
public Properties parseURL(String url, Properties defaults) {
|
||||
Properties urlProps = (defaults != null) ? defaults : new Properties();
|
||||
if (url == null) {
|
||||
if (url == null || url.length() <= 0 || url.trim().length() <= 0)
|
||||
return null;
|
||||
}
|
||||
|
||||
if (!url.startsWith(URL_PREFIX) && !url.startsWith(URL_PREFIX1)) {
|
||||
if (!url.startsWith(URL_PREFIX) && !url.startsWith(URL_PREFIX1))
|
||||
return null;
|
||||
}
|
||||
|
||||
// parse properties
|
||||
String urlForMeta = url;
|
||||
int beginningOfSlashes = url.indexOf("//");
|
||||
int index = url.indexOf("?");
|
||||
if (index != -1) {
|
||||
String paramString = url.substring(index + 1, url.length());
|
||||
url = url.substring(0, index);
|
||||
StringTokenizer queryParams = new StringTokenizer(paramString, "&");
|
||||
while (queryParams.hasMoreElements()) {
|
||||
String parameterValuePair = queryParams.nextToken();
|
||||
int indexOfEqual = parameterValuePair.indexOf("=");
|
||||
String parameter = null;
|
||||
String value = null;
|
||||
if (indexOfEqual != -1) {
|
||||
parameter = parameterValuePair.substring(0, indexOfEqual);
|
||||
if (indexOfEqual + 1 < parameterValuePair.length()) {
|
||||
value = parameterValuePair.substring(indexOfEqual + 1);
|
||||
}
|
||||
}
|
||||
if ((value != null && value.length() > 0) && (parameter != null && parameter.length() > 0)) {
|
||||
urlProps.setProperty(parameter, value);
|
||||
}
|
||||
}
|
||||
}
|
||||
// parse Product Name
|
||||
String dbProductName = url.substring(0, beginningOfSlashes);
|
||||
dbProductName = dbProductName.substring(dbProductName.indexOf(":") + 1);
|
||||
dbProductName = dbProductName.substring(0, dbProductName.indexOf(":"));
|
||||
// parse dbname
|
||||
url = url.substring(beginningOfSlashes + 2);
|
||||
int indexOfSlash = url.indexOf("/");
|
||||
if (indexOfSlash != -1) {
|
||||
if (indexOfSlash + 1 < url.length()) {
|
||||
urlProps.setProperty(TSDBDriver.PROPERTY_KEY_DBNAME, url.substring(indexOfSlash + 1));
|
||||
}
|
||||
url = url.substring(0, indexOfSlash);
|
||||
}
|
||||
// parse port
|
||||
int indexOfColon = url.indexOf(":");
|
||||
if (indexOfColon != -1) {
|
||||
if (indexOfColon + 1 < url.length()) {
|
||||
urlProps.setProperty(TSDBDriver.PROPERTY_KEY_PORT, url.substring(indexOfColon + 1));
|
||||
}
|
||||
url = url.substring(0, indexOfColon);
|
||||
}
|
||||
if (url != null && url.length() > 0 && url.trim().length() > 0) {
|
||||
urlProps.setProperty(TSDBDriver.PROPERTY_KEY_HOST, url);
|
||||
}
|
||||
|
||||
this.dbMetaData = new TSDBDatabaseMetaData(dbProductName, urlForMeta, urlProps.getProperty(TSDBDriver.PROPERTY_KEY_USER));
|
||||
|
||||
/*
|
||||
String urlForMeta = url;
|
||||
String dbProductName = url.substring(url.indexOf(":") + 1);
|
||||
dbProductName = dbProductName.substring(0, dbProductName.indexOf(":"));
|
||||
int beginningOfSlashes = url.indexOf("//");
|
||||
|
@ -345,11 +349,11 @@ public class TSDBDriver implements java.sql.Driver {
|
|||
|
||||
user = urlProps.getProperty(PROPERTY_KEY_USER).toString();
|
||||
this.dbMetaData = new TSDBDatabaseMetaData(dbProductName, urlForMeta, user);
|
||||
|
||||
*/
|
||||
return urlProps;
|
||||
}
|
||||
|
||||
public void setPropertyValue(Properties property, String[] keyValuePair) {
|
||||
private void setPropertyValue(Properties property, String[] keyValuePair) {
|
||||
switch (keyValuePair[0].toLowerCase()) {
|
||||
case PROPERTY_KEY_USER:
|
||||
property.setProperty(PROPERTY_KEY_USER, keyValuePair[1]);
|
||||
|
@ -372,13 +376,12 @@ public class TSDBDriver implements java.sql.Driver {
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
public int getMajorVersion() {
|
||||
return 1;
|
||||
return 2;
|
||||
}
|
||||
|
||||
public int getMinorVersion() {
|
||||
return 1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
public boolean jdbcCompliant() {
|
||||
|
@ -389,33 +392,4 @@ public class TSDBDriver implements java.sql.Driver {
|
|||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the host property
|
||||
*
|
||||
* @param props the java.util.Properties instance to retrieve the hostname from.
|
||||
* @return the host
|
||||
*/
|
||||
public String host(Properties props) {
|
||||
return props.getProperty(PROPERTY_KEY_HOST, "localhost");
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the port number property
|
||||
*
|
||||
* @param props the properties to get the port number from
|
||||
* @return the port number
|
||||
*/
|
||||
public int port(Properties props) {
|
||||
return Integer.parseInt(props.getProperty(PROPERTY_KEY_PORT, TSDBConstants.DEFAULT_PORT));
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the database property from <code>props</code>
|
||||
*
|
||||
* @param props the Properties to look for the database property.
|
||||
* @return the database name.
|
||||
*/
|
||||
public String database(Properties props) {
|
||||
return props.getProperty(PROPERTY_KEY_DBNAME);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,47 +1,210 @@
|
|||
package com.taosdata.jdbc;
|
||||
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.sql.SQLException;
|
||||
import java.io.BufferedReader;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStreamReader;
|
||||
import java.sql.*;
|
||||
import java.util.Properties;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
public class TSDBDriverTest {
|
||||
|
||||
@Test
|
||||
public void urlParserTest() throws SQLException {
|
||||
TSDBDriver driver = new TSDBDriver();
|
||||
String url = "jdbc:TSDB://127.0.0.1:0/db";
|
||||
private static final String[] validURLs = {
|
||||
"jdbc:TAOS://localhost:0",
|
||||
"jdbc:TAOS://localhost",
|
||||
"jdbc:TAOS://localhost:6030/test",
|
||||
"jdbc:TAOS://localhost:6030",
|
||||
"jdbc:TAOS://localhost:6030/",
|
||||
"jdbc:TSDB://localhost:6030",
|
||||
"jdbc:TSDB://localhost:6030/",
|
||||
"jdbc:TAOS://127.0.0.1:0/db?user=root&password=taosdata",
|
||||
"jdbc:TAOS://:",
|
||||
"jdbc:TAOS://:/",
|
||||
"jdbc:TAOS://:/test",
|
||||
"jdbc:TAOS://localhost:0/?user=root&password=taosdata"
|
||||
};
|
||||
private static boolean islibLoaded = false;
|
||||
private static boolean isTaosdActived;
|
||||
|
||||
Properties properties = new Properties();
|
||||
driver.parseURL(url, properties);
|
||||
assertEquals(properties.get("host"), "127.0.0.1");
|
||||
assertEquals(properties.get("port"), "0");
|
||||
assertEquals(properties.get("dbname"), "db");
|
||||
assertEquals(properties.get("user"), "root");
|
||||
assertEquals(properties.get("password"), "your_password");
|
||||
private Connection conn;
|
||||
|
||||
url = "jdbc:TSDB://127.0.0.1:0/log?charset=UTF-8";
|
||||
properties = new Properties();
|
||||
driver.parseURL(url, properties);
|
||||
assertEquals(properties.get("host"), "127.0.0.1");
|
||||
assertEquals(properties.get("port"), "0");
|
||||
assertEquals(properties.get("dbname"), "log");
|
||||
assertEquals(properties.get("charset"), "UTF-8");
|
||||
|
||||
url = "jdbc:TSDB://127.0.0.1:0/";
|
||||
properties = new Properties();
|
||||
driver.parseURL(url, properties);
|
||||
assertEquals(properties.get("host"), "127.0.0.1");
|
||||
assertEquals(properties.get("port"), "0");
|
||||
assertEquals(properties.get("dbname"), null);
|
||||
|
||||
url = "jdbc:TSDB://127.0.0.1:0/db";
|
||||
properties = new Properties();
|
||||
driver.parseURL(url, properties);
|
||||
assertEquals(properties.get("host"), "127.0.0.1");
|
||||
assertEquals(properties.get("port"), "0");
|
||||
assertEquals(properties.get("dbname"), "db");
|
||||
@BeforeClass
|
||||
public static void before() {
|
||||
String osName = System.getProperty("os.name").toLowerCase();
|
||||
if (!osName.equals("linux"))
|
||||
return;
|
||||
// try to load taos lib
|
||||
try {
|
||||
System.loadLibrary("taos");
|
||||
islibLoaded = true;
|
||||
} catch (UnsatisfiedLinkError error) {
|
||||
System.out.println("load tdengine lib failed.");
|
||||
error.printStackTrace();
|
||||
}
|
||||
// check taosd is activated
|
||||
try {
|
||||
String[] cmd = {"/bin/bash", "-c", "ps -ef | grep taosd | grep -v \"grep\""};
|
||||
Process exec = Runtime.getRuntime().exec(cmd);
|
||||
BufferedReader reader = new BufferedReader(new InputStreamReader(exec.getInputStream()));
|
||||
int lineCnt = 0;
|
||||
while (reader.readLine() != null) {
|
||||
lineCnt++;
|
||||
}
|
||||
if (lineCnt > 0)
|
||||
isTaosdActived = true;
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
try {
|
||||
Class.forName("com.taosdata.jdbc.TSDBDriver");
|
||||
} catch (ClassNotFoundException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testConnectWithJdbcURL() {
|
||||
final String url = "jdbc:TAOS://localhost:6030/log?user=root&password=taosdata";
|
||||
try {
|
||||
if (islibLoaded && isTaosdActived) {
|
||||
conn = DriverManager.getConnection(url);
|
||||
assertNotNull("failure - connection should not be null", conn);
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
fail("failure - should not throw Exception");
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testConnectWithProperties() {
|
||||
final String jdbcUrl = "jdbc:TAOS://localhost:6030/log?user=root&password=taosdata";
|
||||
Properties connProps = new Properties();
|
||||
connProps.setProperty(TSDBDriver.PROPERTY_KEY_CHARSET, "UTF-8");
|
||||
connProps.setProperty(TSDBDriver.PROPERTY_KEY_LOCALE, "en_US.UTF-8");
|
||||
connProps.setProperty(TSDBDriver.PROPERTY_KEY_TIME_ZONE, "UTC-8");
|
||||
try {
|
||||
if (islibLoaded && isTaosdActived) {
|
||||
conn = DriverManager.getConnection(jdbcUrl, connProps);
|
||||
assertNotNull("failure - connection should not be null", conn);
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
fail("failure - should not throw Exception");
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testConnectWithConfigFile() {
|
||||
String jdbcUrl = "jdbc:TAOS://:/log?user=root&password=taosdata";
|
||||
Properties connProps = new Properties();
|
||||
connProps.setProperty(TSDBDriver.PROPERTY_KEY_CHARSET, "UTF-8");
|
||||
connProps.setProperty(TSDBDriver.PROPERTY_KEY_LOCALE, "en_US.UTF-8");
|
||||
connProps.setProperty(TSDBDriver.PROPERTY_KEY_TIME_ZONE, "UTC-8");
|
||||
try {
|
||||
if (islibLoaded && isTaosdActived) {
|
||||
conn = DriverManager.getConnection(jdbcUrl, connProps);
|
||||
assertNotNull("failure - connection should not be null", conn);
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
fail("failure - should not throw Exception");
|
||||
}
|
||||
}
|
||||
|
||||
@Test(expected = SQLException.class)
|
||||
public void testAcceptsURL() throws SQLException {
|
||||
Driver driver = new TSDBDriver();
|
||||
for (String url : validURLs) {
|
||||
assertTrue("failure - acceptsURL(\" " + url + " \") should be true", driver.acceptsURL(url));
|
||||
}
|
||||
driver.acceptsURL(null);
|
||||
fail("acceptsURL throws exception when parameter is null");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testParseURL() {
|
||||
TSDBDriver driver = new TSDBDriver();
|
||||
|
||||
String url = "jdbc:TAOS://127.0.0.1:0/db?user=root&password=taosdata&charset=UTF-8";
|
||||
Properties config = new Properties();
|
||||
Properties actual = driver.parseURL(url, config);
|
||||
assertEquals("failure - host should be 127.0.0.1", "127.0.0.1", actual.get("host"));
|
||||
assertEquals("failure - port should be 0", "0", actual.get("port"));
|
||||
assertEquals("failure - dbname should be db", "db", actual.get("dbname"));
|
||||
assertEquals("failure - user should be root", "root", actual.get("user"));
|
||||
assertEquals("failure - password should be taosdata", "taosdata", actual.get("password"));
|
||||
assertEquals("failure - charset should be UTF-8", "UTF-8", actual.get("charset"));
|
||||
|
||||
url = "jdbc:TAOS://127.0.0.1:0";
|
||||
config = new Properties();
|
||||
actual = driver.parseURL(url, config);
|
||||
assertEquals("failure - host should be 127.0.0.1", "127.0.0.1", actual.getProperty("host"));
|
||||
assertEquals("failure - port should be 0", "0", actual.get("port"));
|
||||
assertNull("failure - dbname should be null", actual.get("dbname"));
|
||||
|
||||
url = "jdbc:TAOS://127.0.0.1:0/db";
|
||||
config = new Properties();
|
||||
actual = driver.parseURL(url, config);
|
||||
assertEquals("failure - host should be 127.0.0.1", "127.0.0.1", actual.getProperty("host"));
|
||||
assertEquals("failure - port should be 0", "0", actual.get("port"));
|
||||
assertEquals("failure - dbname should be db", "db", actual.get("dbname"));
|
||||
|
||||
url = "jdbc:TAOS://:/?";
|
||||
config = new Properties();
|
||||
config.setProperty(TSDBDriver.PROPERTY_KEY_USER, "root");
|
||||
config.setProperty(TSDBDriver.PROPERTY_KEY_PASSWORD, "taosdata");
|
||||
actual = driver.parseURL(url, config);
|
||||
assertEquals("failure - user should be root", "root", actual.getProperty("user"));
|
||||
assertEquals("failure - password should be taosdata", "taosdata", actual.getProperty("password"));
|
||||
assertNull("failure - host should be null", actual.getProperty("host"));
|
||||
assertNull("failure - port should be null", actual.getProperty("port"));
|
||||
assertNull("failure - dbname should be null", actual.getProperty("dbname"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetPropertyInfo() throws SQLException {
|
||||
Driver driver = new TSDBDriver();
|
||||
final String url = "jdbc:TAOS://localhost:6030/log?user=root&password=taosdata";
|
||||
Properties connProps = new Properties();
|
||||
DriverPropertyInfo[] propertyInfo = driver.getPropertyInfo(url, connProps);
|
||||
for (DriverPropertyInfo info : propertyInfo) {
|
||||
if (info.name.equals(TSDBDriver.PROPERTY_KEY_HOST))
|
||||
assertEquals("failure - host should be localhost", "localhost", info.value);
|
||||
if (info.name.equals(TSDBDriver.PROPERTY_KEY_PORT))
|
||||
assertEquals("failure - port should be 6030", "6030", info.value);
|
||||
if (info.name.equals(TSDBDriver.PROPERTY_KEY_DBNAME))
|
||||
assertEquals("failure - dbname should be test", "log", info.value);
|
||||
if (info.name.equals(TSDBDriver.PROPERTY_KEY_USER))
|
||||
assertEquals("failure - user should be root", "root", info.value);
|
||||
if (info.name.equals(TSDBDriver.PROPERTY_KEY_PASSWORD))
|
||||
assertEquals("failure - password should be root", "taosdata", info.value);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetMajorVersion() {
|
||||
assertEquals("failure - getMajorVersion should be 2", 2, new TSDBDriver().getMajorVersion());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetMinorVersion() {
|
||||
assertEquals("failure - getMinorVersion should be 0", 0, new TSDBDriver().getMinorVersion());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testJdbcCompliant() {
|
||||
assertFalse("failure - jdbcCompliant should be false", new TSDBDriver().jdbcCompliant());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetParentLogger() throws SQLFeatureNotSupportedException {
|
||||
assertNull("failure - getParentLogger should be be null", new TSDBDriver().getParentLogger());
|
||||
}
|
||||
|
||||
}
|
|
@ -334,7 +334,7 @@ static void cqProcessStreamRes(void *param, TAOS_RES *tres, TAOS_ROW row) {
|
|||
pHead->version = 0;
|
||||
|
||||
// write into vnode write queue
|
||||
pContext->cqWrite(pContext->ahandle, pHead, TAOS_QTYPE_CQ);
|
||||
pContext->cqWrite(pContext->ahandle, pHead, TAOS_QTYPE_CQ, NULL);
|
||||
free(buffer);
|
||||
}
|
||||
|
||||
|
|
|
@ -24,7 +24,7 @@
|
|||
int64_t ver = 0;
|
||||
void *pCq = NULL;
|
||||
|
||||
int writeToQueue(void *pVnode, void *data, int type) {
|
||||
int writeToQueue(void *pVnode, void *data, int type, void *pMsg) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
|
@ -20,9 +20,11 @@
|
|||
extern "C" {
|
||||
#endif
|
||||
|
||||
int32_t dnodeInitVnodeRead();
|
||||
void dnodeCleanupVnodeRead();
|
||||
void dnodeDispatchToVnodeReadQueue(SRpcMsg *pMsg);
|
||||
int32_t dnodeInitVRead();
|
||||
void dnodeCleanupVRead();
|
||||
void dnodeDispatchToVReadQueue(SRpcMsg *pMsg);
|
||||
void * dnodeAllocVReadQueue(void *pVnode);
|
||||
void dnodeFreeVReadQueue(void *rqueue);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
|
|
@ -61,7 +61,7 @@ static const SDnodeComponent tsDnodeComponents[] = {
|
|||
{"mnodeinfos",dnodeInitMInfos, dnodeCleanupMInfos},
|
||||
{"wal", walInit, walCleanUp},
|
||||
{"check", dnodeInitCheck, dnodeCleanupCheck}, // NOTES: dnodeInitCheck must be behind the dnodeinitStorage component !!!
|
||||
{"vread", dnodeInitVnodeRead, dnodeCleanupVnodeRead},
|
||||
{"vread", dnodeInitVRead, dnodeCleanupVRead},
|
||||
{"vwrite", dnodeInitVWrite, dnodeCleanupVWrite},
|
||||
{"mread", dnodeInitMnodeRead, dnodeCleanupMnodeRead},
|
||||
{"mwrite", dnodeInitMnodeWrite, dnodeCleanupMnodeWrite},
|
||||
|
|
|
@ -39,8 +39,8 @@ static int32_t tsDnodeSubmitReqNum = 0;
|
|||
|
||||
int32_t dnodeInitShell() {
|
||||
dnodeProcessShellMsgFp[TSDB_MSG_TYPE_SUBMIT] = dnodeDispatchToVWriteQueue;
|
||||
dnodeProcessShellMsgFp[TSDB_MSG_TYPE_QUERY] = dnodeDispatchToVnodeReadQueue;
|
||||
dnodeProcessShellMsgFp[TSDB_MSG_TYPE_FETCH] = dnodeDispatchToVnodeReadQueue;
|
||||
dnodeProcessShellMsgFp[TSDB_MSG_TYPE_QUERY] = dnodeDispatchToVReadQueue;
|
||||
dnodeProcessShellMsgFp[TSDB_MSG_TYPE_FETCH] = dnodeDispatchToVReadQueue;
|
||||
dnodeProcessShellMsgFp[TSDB_MSG_TYPE_UPDATE_TAG_VAL] = dnodeDispatchToVWriteQueue;
|
||||
|
||||
// the following message shall be treated as mnode write
|
||||
|
|
|
@ -17,225 +17,184 @@
|
|||
#include "os.h"
|
||||
#include "taoserror.h"
|
||||
#include "taosmsg.h"
|
||||
#include "tutil.h"
|
||||
#include "tqueue.h"
|
||||
#include "twal.h"
|
||||
#include "tglobal.h"
|
||||
#include "dnodeInt.h"
|
||||
#include "dnodeMgmt.h"
|
||||
#include "dnodeVRead.h"
|
||||
#include "tqueue.h"
|
||||
#include "vnode.h"
|
||||
#include "dnodeInt.h"
|
||||
|
||||
typedef struct {
|
||||
pthread_t thread; // thread
|
||||
int32_t workerId; // worker ID
|
||||
} SReadWorker;
|
||||
pthread_t thread; // thread
|
||||
int32_t workerId; // worker ID
|
||||
} SVReadWorker;
|
||||
|
||||
typedef struct {
|
||||
int32_t max; // max number of workers
|
||||
int32_t min; // min number of workers
|
||||
int32_t num; // current number of workers
|
||||
SReadWorker *readWorker;
|
||||
int32_t max; // max number of workers
|
||||
int32_t min; // min number of workers
|
||||
int32_t num; // current number of workers
|
||||
SVReadWorker * worker;
|
||||
pthread_mutex_t mutex;
|
||||
} SReadWorkerPool;
|
||||
} SVReadWorkerPool;
|
||||
|
||||
static void *dnodeProcessReadQueue(void *param);
|
||||
static void dnodeHandleIdleReadWorker(SReadWorker *);
|
||||
|
||||
// module global variable
|
||||
static SReadWorkerPool readPool;
|
||||
static taos_qset readQset;
|
||||
static SVReadWorkerPool tsVReadWP;
|
||||
static taos_qset tsVReadQset;
|
||||
|
||||
int32_t dnodeInitVnodeRead() {
|
||||
readQset = taosOpenQset();
|
||||
int32_t dnodeInitVRead() {
|
||||
tsVReadQset = taosOpenQset();
|
||||
|
||||
readPool.min = tsNumOfCores;
|
||||
readPool.max = tsNumOfCores * tsNumOfThreadsPerCore;
|
||||
if (readPool.max <= readPool.min * 2) readPool.max = 2 * readPool.min;
|
||||
readPool.readWorker = (SReadWorker *)calloc(sizeof(SReadWorker), readPool.max);
|
||||
pthread_mutex_init(&readPool.mutex, NULL);
|
||||
tsVReadWP.min = tsNumOfCores;
|
||||
tsVReadWP.max = tsNumOfCores * tsNumOfThreadsPerCore;
|
||||
if (tsVReadWP.max <= tsVReadWP.min * 2) tsVReadWP.max = 2 * tsVReadWP.min;
|
||||
tsVReadWP.worker = (SVReadWorker *)calloc(sizeof(SVReadWorker), tsVReadWP.max);
|
||||
pthread_mutex_init(&tsVReadWP.mutex, NULL);
|
||||
|
||||
if (readPool.readWorker == NULL) return -1;
|
||||
for (int i = 0; i < readPool.max; ++i) {
|
||||
SReadWorker *pWorker = readPool.readWorker + i;
|
||||
if (tsVReadWP.worker == NULL) return -1;
|
||||
for (int i = 0; i < tsVReadWP.max; ++i) {
|
||||
SVReadWorker *pWorker = tsVReadWP.worker + i;
|
||||
pWorker->workerId = i;
|
||||
}
|
||||
|
||||
dInfo("dnode read is initialized, min worker:%d max worker:%d", readPool.min, readPool.max);
|
||||
dInfo("dnode vread is initialized, min worker:%d max worker:%d", tsVReadWP.min, tsVReadWP.max);
|
||||
return 0;
|
||||
}
|
||||
|
||||
void dnodeCleanupVnodeRead() {
|
||||
for (int i = 0; i < readPool.max; ++i) {
|
||||
SReadWorker *pWorker = readPool.readWorker + i;
|
||||
void dnodeCleanupVRead() {
|
||||
for (int i = 0; i < tsVReadWP.max; ++i) {
|
||||
SVReadWorker *pWorker = tsVReadWP.worker + i;
|
||||
if (pWorker->thread) {
|
||||
taosQsetThreadResume(readQset);
|
||||
taosQsetThreadResume(tsVReadQset);
|
||||
}
|
||||
}
|
||||
|
||||
for (int i = 0; i < readPool.max; ++i) {
|
||||
SReadWorker *pWorker = readPool.readWorker + i;
|
||||
for (int i = 0; i < tsVReadWP.max; ++i) {
|
||||
SVReadWorker *pWorker = tsVReadWP.worker + i;
|
||||
if (pWorker->thread) {
|
||||
pthread_join(pWorker->thread, NULL);
|
||||
}
|
||||
}
|
||||
|
||||
free(readPool.readWorker);
|
||||
taosCloseQset(readQset);
|
||||
pthread_mutex_destroy(&readPool.mutex);
|
||||
free(tsVReadWP.worker);
|
||||
taosCloseQset(tsVReadQset);
|
||||
pthread_mutex_destroy(&tsVReadWP.mutex);
|
||||
|
||||
dInfo("dnode read is closed");
|
||||
dInfo("dnode vread is closed");
|
||||
}
|
||||
|
||||
void dnodeDispatchToVnodeReadQueue(SRpcMsg *pMsg) {
|
||||
int32_t queuedMsgNum = 0;
|
||||
int32_t leftLen = pMsg->contLen;
|
||||
char *pCont = (char *) pMsg->pCont;
|
||||
void dnodeDispatchToVReadQueue(SRpcMsg *pMsg) {
|
||||
int32_t queuedMsgNum = 0;
|
||||
int32_t leftLen = pMsg->contLen;
|
||||
char * pCont = (char *)pMsg->pCont;
|
||||
|
||||
while (leftLen > 0) {
|
||||
SMsgHead *pHead = (SMsgHead *) pCont;
|
||||
pHead->vgId = htonl(pHead->vgId);
|
||||
SMsgHead *pHead = (SMsgHead *)pCont;
|
||||
pHead->vgId = htonl(pHead->vgId);
|
||||
pHead->contLen = htonl(pHead->contLen);
|
||||
|
||||
taos_queue queue = vnodeAcquireRqueue(pHead->vgId);
|
||||
|
||||
if (queue == NULL) {
|
||||
leftLen -= pHead->contLen;
|
||||
pCont -= pHead->contLen;
|
||||
continue;
|
||||
void *pVnode = vnodeAcquire(pHead->vgId);
|
||||
if (pVnode != NULL) {
|
||||
int32_t code = vnodeWriteToRQueue(pVnode, pCont, pHead->contLen, TAOS_QTYPE_RPC, pMsg);
|
||||
if (code == TSDB_CODE_SUCCESS) queuedMsgNum++;
|
||||
vnodeRelease(pVnode);
|
||||
}
|
||||
|
||||
// put message into queue
|
||||
SReadMsg *pRead = (SReadMsg *)taosAllocateQitem(sizeof(SReadMsg));
|
||||
pRead->rpcMsg = *pMsg;
|
||||
pRead->pCont = pCont;
|
||||
pRead->contLen = pHead->contLen;
|
||||
|
||||
// next vnode
|
||||
leftLen -= pHead->contLen;
|
||||
pCont -= pHead->contLen;
|
||||
queuedMsgNum++;
|
||||
|
||||
taosWriteQitem(queue, TAOS_QTYPE_RPC, pRead);
|
||||
}
|
||||
|
||||
if (queuedMsgNum == 0) {
|
||||
SRpcMsg rpcRsp = {
|
||||
.handle = pMsg->handle,
|
||||
.pCont = NULL,
|
||||
.contLen = 0,
|
||||
.code = TSDB_CODE_VND_INVALID_VGROUP_ID,
|
||||
.msgType = 0
|
||||
};
|
||||
SRpcMsg rpcRsp = {.handle = pMsg->handle, .code = TSDB_CODE_VND_INVALID_VGROUP_ID};
|
||||
rpcSendResponse(&rpcRsp);
|
||||
rpcFreeCont(pMsg->pCont);
|
||||
}
|
||||
|
||||
rpcFreeCont(pMsg->pCont);
|
||||
}
|
||||
|
||||
void *dnodeAllocVReadQueue(void *pVnode) {
|
||||
pthread_mutex_lock(&readPool.mutex);
|
||||
pthread_mutex_lock(&tsVReadWP.mutex);
|
||||
taos_queue queue = taosOpenQueue();
|
||||
if (queue == NULL) {
|
||||
pthread_mutex_unlock(&readPool.mutex);
|
||||
pthread_mutex_unlock(&tsVReadWP.mutex);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
taosAddIntoQset(readQset, queue, pVnode);
|
||||
taosAddIntoQset(tsVReadQset, queue, pVnode);
|
||||
|
||||
// spawn a thread to process queue
|
||||
if (readPool.num < readPool.max) {
|
||||
if (tsVReadWP.num < tsVReadWP.max) {
|
||||
do {
|
||||
SReadWorker *pWorker = readPool.readWorker + readPool.num;
|
||||
SVReadWorker *pWorker = tsVReadWP.worker + tsVReadWP.num;
|
||||
|
||||
pthread_attr_t thAttr;
|
||||
pthread_attr_init(&thAttr);
|
||||
pthread_attr_setdetachstate(&thAttr, PTHREAD_CREATE_JOINABLE);
|
||||
|
||||
if (pthread_create(&pWorker->thread, &thAttr, dnodeProcessReadQueue, pWorker) != 0) {
|
||||
dError("failed to create thread to process read queue, reason:%s", strerror(errno));
|
||||
dError("failed to create thread to process vread vqueue since %s", strerror(errno));
|
||||
}
|
||||
|
||||
pthread_attr_destroy(&thAttr);
|
||||
readPool.num++;
|
||||
dDebug("read worker:%d is launched, total:%d", pWorker->workerId, readPool.num);
|
||||
} while (readPool.num < readPool.min);
|
||||
tsVReadWP.num++;
|
||||
dDebug("dnode vread worker:%d is launched, total:%d", pWorker->workerId, tsVReadWP.num);
|
||||
} while (tsVReadWP.num < tsVReadWP.min);
|
||||
}
|
||||
|
||||
pthread_mutex_unlock(&readPool.mutex);
|
||||
dDebug("pVnode:%p, read queue:%p is allocated", pVnode, queue);
|
||||
pthread_mutex_unlock(&tsVReadWP.mutex);
|
||||
dDebug("pVnode:%p, dnode vread queue:%p is allocated", pVnode, queue);
|
||||
|
||||
return queue;
|
||||
}
|
||||
|
||||
void dnodeFreeVReadQueue(void *rqueue) {
|
||||
taosCloseQueue(rqueue);
|
||||
|
||||
// dynamically adjust the number of threads
|
||||
}
|
||||
|
||||
void dnodeSendRpcReadRsp(void *pVnode, SReadMsg *pRead, int32_t code) {
|
||||
void dnodeSendRpcVReadRsp(void *pVnode, SVReadMsg *pRead, int32_t code) {
|
||||
SRpcMsg rpcRsp = {
|
||||
.handle = pRead->rpcMsg.handle,
|
||||
.handle = pRead->rpcHandle,
|
||||
.pCont = pRead->rspRet.rsp,
|
||||
.contLen = pRead->rspRet.len,
|
||||
.code = code,
|
||||
};
|
||||
|
||||
rpcSendResponse(&rpcRsp);
|
||||
rpcFreeCont(pRead->rpcMsg.pCont);
|
||||
vnodeRelease(pVnode);
|
||||
}
|
||||
|
||||
void dnodeDispatchNonRspMsg(void *pVnode, SReadMsg *pRead, int32_t code) {
|
||||
rpcFreeCont(pRead->rpcMsg.pCont);
|
||||
void dnodeDispatchNonRspMsg(void *pVnode, SVReadMsg *pRead, int32_t code) {
|
||||
vnodeRelease(pVnode);
|
||||
}
|
||||
|
||||
static void *dnodeProcessReadQueue(void *param) {
|
||||
SReadMsg *pReadMsg;
|
||||
int type;
|
||||
void *pVnode;
|
||||
SVReadMsg *pRead;
|
||||
int32_t qtype;
|
||||
void * pVnode;
|
||||
|
||||
while (1) {
|
||||
if (taosReadQitemFromQset(readQset, &type, (void **)&pReadMsg, &pVnode) == 0) {
|
||||
dDebug("qset:%p dnode read got no message from qset, exiting", readQset);
|
||||
if (taosReadQitemFromQset(tsVReadQset, &qtype, (void **)&pRead, &pVnode) == 0) {
|
||||
dDebug("qset:%p dnode vread got no message from qset, exiting", tsVReadQset);
|
||||
break;
|
||||
}
|
||||
|
||||
dDebug("%p, msg:%s will be processed in vread queue, qtype:%d, msg:%p", pReadMsg->rpcMsg.ahandle,
|
||||
taosMsg[pReadMsg->rpcMsg.msgType], type, pReadMsg);
|
||||
dDebug("%p, msg:%p:%s will be processed in vread queue, qtype:%d", pRead->rpcAhandle, pRead,
|
||||
taosMsg[pRead->msgType], qtype);
|
||||
|
||||
int32_t code = vnodeProcessRead(pVnode, pReadMsg);
|
||||
int32_t code = vnodeProcessRead(pVnode, pRead);
|
||||
|
||||
if (type == TAOS_QTYPE_RPC && code != TSDB_CODE_QRY_NOT_READY) {
|
||||
dnodeSendRpcReadRsp(pVnode, pReadMsg, code);
|
||||
if (qtype == TAOS_QTYPE_RPC && code != TSDB_CODE_QRY_NOT_READY) {
|
||||
dnodeSendRpcVReadRsp(pVnode, pRead, code);
|
||||
} else {
|
||||
if (code == TSDB_CODE_QRY_HAS_RSP) {
|
||||
dnodeSendRpcReadRsp(pVnode, pReadMsg, pReadMsg->rpcMsg.code);
|
||||
} else { // code == TSDB_CODE_QRY_NOT_READY, do not return msg to client
|
||||
assert(pReadMsg->rpcMsg.handle == NULL || (pReadMsg->rpcMsg.handle != NULL && pReadMsg->rpcMsg.msgType == 5));
|
||||
dnodeDispatchNonRspMsg(pVnode, pReadMsg, code);
|
||||
dnodeSendRpcVReadRsp(pVnode, pRead, pRead->code);
|
||||
} else { // code == TSDB_CODE_QRY_NOT_READY, do not return msg to client
|
||||
assert(pRead->rpcHandle == NULL || (pRead->rpcHandle != NULL && pRead->msgType == 5));
|
||||
dnodeDispatchNonRspMsg(pVnode, pRead, code);
|
||||
}
|
||||
}
|
||||
|
||||
taosFreeQitem(pReadMsg);
|
||||
taosFreeQitem(pRead);
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
UNUSED_FUNC
|
||||
static void dnodeHandleIdleReadWorker(SReadWorker *pWorker) {
|
||||
int32_t num = taosGetQueueNumber(readQset);
|
||||
|
||||
if (num == 0 || (num <= readPool.min && readPool.num > readPool.min)) {
|
||||
readPool.num--;
|
||||
dDebug("read worker:%d is released, total:%d", pWorker->workerId, readPool.num);
|
||||
pthread_exit(NULL);
|
||||
} else {
|
||||
usleep(30000);
|
||||
sched_yield();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -15,13 +15,12 @@
|
|||
|
||||
#define _DEFAULT_SOURCE
|
||||
#include "os.h"
|
||||
#include "taoserror.h"
|
||||
#include "taosmsg.h"
|
||||
#include "tglobal.h"
|
||||
#include "tqueue.h"
|
||||
#include "tsdb.h"
|
||||
#include "twal.h"
|
||||
#include "tsync.h"
|
||||
#include "vnode.h"
|
||||
#include "syncInt.h"
|
||||
#include "dnodeInt.h"
|
||||
|
||||
typedef struct {
|
||||
|
@ -29,30 +28,21 @@ typedef struct {
|
|||
taos_qset qset; // queue set
|
||||
int32_t workerId; // worker ID
|
||||
pthread_t thread; // thread
|
||||
} SWriteWorker;
|
||||
|
||||
typedef struct {
|
||||
SRspRet rspRet;
|
||||
SRpcMsg rpcMsg;
|
||||
int32_t processedCount;
|
||||
int32_t code;
|
||||
int32_t contLen;
|
||||
void * pCont;
|
||||
} SWriteMsg;
|
||||
} SVWriteWorker;
|
||||
|
||||
typedef struct {
|
||||
int32_t max; // max number of workers
|
||||
int32_t nextId; // from 0 to max-1, cyclic
|
||||
SWriteWorker *worker;
|
||||
SVWriteWorker * worker;
|
||||
pthread_mutex_t mutex;
|
||||
} SWriteWorkerPool;
|
||||
} SVWriteWorkerPool;
|
||||
|
||||
static SWriteWorkerPool tsVWriteWP;
|
||||
static void *dnodeProcessWriteQueue(void *param);
|
||||
static SVWriteWorkerPool tsVWriteWP;
|
||||
static void *dnodeProcessVWriteQueue(void *param);
|
||||
|
||||
int32_t dnodeInitVWrite() {
|
||||
tsVWriteWP.max = tsNumOfCores;
|
||||
tsVWriteWP.worker = (SWriteWorker *)tcalloc(sizeof(SWriteWorker), tsVWriteWP.max);
|
||||
tsVWriteWP.worker = (SVWriteWorker *)tcalloc(sizeof(SVWriteWorker), tsVWriteWP.max);
|
||||
if (tsVWriteWP.worker == NULL) return -1;
|
||||
pthread_mutex_init(&tsVWriteWP.mutex, NULL);
|
||||
|
||||
|
@ -66,14 +56,14 @@ int32_t dnodeInitVWrite() {
|
|||
|
||||
void dnodeCleanupVWrite() {
|
||||
for (int32_t i = 0; i < tsVWriteWP.max; ++i) {
|
||||
SWriteWorker *pWorker = tsVWriteWP.worker + i;
|
||||
SVWriteWorker *pWorker = tsVWriteWP.worker + i;
|
||||
if (pWorker->thread) {
|
||||
taosQsetThreadResume(pWorker->qset);
|
||||
}
|
||||
}
|
||||
|
||||
for (int32_t i = 0; i < tsVWriteWP.max; ++i) {
|
||||
SWriteWorker *pWorker = tsVWriteWP.worker + i;
|
||||
SVWriteWorker *pWorker = tsVWriteWP.worker + i;
|
||||
if (pWorker->thread) {
|
||||
pthread_join(pWorker->thread, NULL);
|
||||
taosFreeQall(pWorker->qall);
|
||||
|
@ -86,44 +76,43 @@ void dnodeCleanupVWrite() {
|
|||
dInfo("dnode vwrite is closed");
|
||||
}
|
||||
|
||||
void dnodeDispatchToVWriteQueue(SRpcMsg *pMsg) {
|
||||
char *pCont = pMsg->pCont;
|
||||
void dnodeDispatchToVWriteQueue(SRpcMsg *pRpcMsg) {
|
||||
int32_t code;
|
||||
char *pCont = pRpcMsg->pCont;
|
||||
|
||||
if (pMsg->msgType == TSDB_MSG_TYPE_SUBMIT) {
|
||||
if (pRpcMsg->msgType == TSDB_MSG_TYPE_SUBMIT) {
|
||||
SMsgDesc *pDesc = (SMsgDesc *)pCont;
|
||||
pDesc->numOfVnodes = htonl(pDesc->numOfVnodes);
|
||||
pCont += sizeof(SMsgDesc);
|
||||
}
|
||||
|
||||
SMsgHead *pHead = (SMsgHead *) pCont;
|
||||
pHead->vgId = htonl(pHead->vgId);
|
||||
pHead->contLen = htonl(pHead->contLen);
|
||||
SMsgHead *pMsg = (SMsgHead *)pCont;
|
||||
pMsg->vgId = htonl(pMsg->vgId);
|
||||
pMsg->contLen = htonl(pMsg->contLen);
|
||||
|
||||
taos_queue queue = vnodeAcquireWqueue(pHead->vgId);
|
||||
if (queue) {
|
||||
// put message into queue
|
||||
SWriteMsg *pWrite = taosAllocateQitem(sizeof(SWriteMsg));
|
||||
pWrite->rpcMsg = *pMsg;
|
||||
pWrite->pCont = pCont;
|
||||
pWrite->contLen = pHead->contLen;
|
||||
|
||||
taosWriteQitem(queue, TAOS_QTYPE_RPC, pWrite);
|
||||
void *pVnode = vnodeAcquire(pMsg->vgId);
|
||||
if (pVnode == NULL) {
|
||||
code = TSDB_CODE_VND_INVALID_VGROUP_ID;
|
||||
} else {
|
||||
SRpcMsg rpcRsp = {
|
||||
.handle = pMsg->handle,
|
||||
.pCont = NULL,
|
||||
.contLen = 0,
|
||||
.code = TSDB_CODE_VND_INVALID_VGROUP_ID,
|
||||
.msgType = 0
|
||||
};
|
||||
rpcSendResponse(&rpcRsp);
|
||||
rpcFreeCont(pMsg->pCont);
|
||||
SWalHead *pHead = (SWalHead *)(pCont - sizeof(SWalHead));
|
||||
pHead->msgType = pRpcMsg->msgType;
|
||||
pHead->version = 0;
|
||||
pHead->len = pMsg->contLen;
|
||||
code = vnodeWriteToWQueue(pVnode, pHead, TAOS_QTYPE_RPC, pRpcMsg);
|
||||
}
|
||||
|
||||
if (code != TSDB_CODE_SUCCESS) {
|
||||
SRpcMsg rpcRsp = {.handle = pRpcMsg->handle, .code = code};
|
||||
rpcSendResponse(&rpcRsp);
|
||||
}
|
||||
|
||||
vnodeRelease(pVnode);
|
||||
rpcFreeCont(pRpcMsg->pCont);
|
||||
}
|
||||
|
||||
void *dnodeAllocVWriteQueue(void *pVnode) {
|
||||
pthread_mutex_lock(&tsVWriteWP.mutex);
|
||||
SWriteWorker *pWorker = tsVWriteWP.worker + tsVWriteWP.nextId;
|
||||
SVWriteWorker *pWorker = tsVWriteWP.worker + tsVWriteWP.nextId;
|
||||
void *queue = taosOpenQueue();
|
||||
if (queue == NULL) {
|
||||
pthread_mutex_unlock(&tsVWriteWP.mutex);
|
||||
|
@ -150,7 +139,7 @@ void *dnodeAllocVWriteQueue(void *pVnode) {
|
|||
pthread_attr_init(&thAttr);
|
||||
pthread_attr_setdetachstate(&thAttr, PTHREAD_CREATE_JOINABLE);
|
||||
|
||||
if (pthread_create(&pWorker->thread, &thAttr, dnodeProcessWriteQueue, pWorker) != 0) {
|
||||
if (pthread_create(&pWorker->thread, &thAttr, dnodeProcessVWriteQueue, pWorker) != 0) {
|
||||
dError("failed to create thread to process vwrite queue since %s", strerror(errno));
|
||||
taosFreeQall(pWorker->qall);
|
||||
taosCloseQset(pWorker->qset);
|
||||
|
@ -179,7 +168,7 @@ void dnodeFreeVWriteQueue(void *wqueue) {
|
|||
|
||||
void dnodeSendRpcVWriteRsp(void *pVnode, void *param, int32_t code) {
|
||||
if (param == NULL) return;
|
||||
SWriteMsg *pWrite = param;
|
||||
SVWriteMsg *pWrite = param;
|
||||
|
||||
if (code < 0) pWrite->code = code;
|
||||
int32_t count = atomic_add_fetch_32(&pWrite->processedCount, 1);
|
||||
|
@ -187,28 +176,24 @@ void dnodeSendRpcVWriteRsp(void *pVnode, void *param, int32_t code) {
|
|||
if (count <= 1) return;
|
||||
|
||||
SRpcMsg rpcRsp = {
|
||||
.handle = pWrite->rpcMsg.handle,
|
||||
.handle = pWrite->rpcHandle,
|
||||
.pCont = pWrite->rspRet.rsp,
|
||||
.contLen = pWrite->rspRet.len,
|
||||
.code = pWrite->code,
|
||||
};
|
||||
|
||||
rpcSendResponse(&rpcRsp);
|
||||
rpcFreeCont(pWrite->rpcMsg.pCont);
|
||||
taosFreeQitem(pWrite);
|
||||
|
||||
vnodeRelease(pVnode);
|
||||
}
|
||||
|
||||
static void *dnodeProcessWriteQueue(void *param) {
|
||||
SWriteWorker *pWorker = (SWriteWorker *)param;
|
||||
SWriteMsg * pWrite;
|
||||
SWalHead * pHead;
|
||||
SRspRet * pRspRet;
|
||||
void * pVnode;
|
||||
void * pItem;
|
||||
int32_t numOfMsgs;
|
||||
int32_t qtype;
|
||||
static void *dnodeProcessVWriteQueue(void *param) {
|
||||
SVWriteWorker *pWorker = param;
|
||||
SVWriteMsg * pWrite;
|
||||
void * pVnode;
|
||||
int32_t numOfMsgs;
|
||||
int32_t qtype;
|
||||
|
||||
dDebug("dnode vwrite worker:%d is running", pWorker->workerId);
|
||||
|
||||
|
@ -219,55 +204,33 @@ static void *dnodeProcessWriteQueue(void *param) {
|
|||
break;
|
||||
}
|
||||
|
||||
bool forceFsync = false;
|
||||
for (int32_t i = 0; i < numOfMsgs; ++i) {
|
||||
pWrite = NULL;
|
||||
pRspRet = NULL;
|
||||
taosGetQitem(pWorker->qall, &qtype, &pItem);
|
||||
if (qtype == TAOS_QTYPE_RPC) {
|
||||
pWrite = pItem;
|
||||
pRspRet = &pWrite->rspRet;
|
||||
pHead = (SWalHead *)((char *)pWrite->pCont - sizeof(SWalHead));
|
||||
pHead->msgType = pWrite->rpcMsg.msgType;
|
||||
pHead->version = 0;
|
||||
pHead->len = pWrite->contLen;
|
||||
dDebug("%p, rpc msg:%s will be processed in vwrite queue", pWrite->rpcMsg.ahandle,
|
||||
taosMsg[pWrite->rpcMsg.msgType]);
|
||||
} else if (qtype == TAOS_QTYPE_CQ) {
|
||||
pHead = (SWalHead *)((char *)pItem + sizeof(SSyncHead));
|
||||
dTrace("%p, CQ wal msg:%s will be processed in vwrite queue, version:%" PRIu64, pHead, taosMsg[pHead->msgType],
|
||||
pHead->version);
|
||||
} else {
|
||||
pHead = pItem;
|
||||
dTrace("%p, wal msg:%s will be processed in vwrite queue, version:%" PRIu64, pHead, taosMsg[pHead->msgType],
|
||||
pHead->version);
|
||||
}
|
||||
taosGetQitem(pWorker->qall, &qtype, (void **)&pWrite);
|
||||
dTrace("%p, msg:%p:%s will be processed in vwrite queue, qtype:%d version:%" PRIu64, pWrite->rpcAhandle, pWrite,
|
||||
taosMsg[pWrite->pHead->msgType], qtype, pWrite->pHead->version);
|
||||
|
||||
int32_t code = vnodeProcessWrite(pVnode, qtype, pHead, pRspRet);
|
||||
dTrace("%p, msg:%s is processed in vwrite queue, version:%" PRIu64 ", result:%s", pHead, taosMsg[pHead->msgType],
|
||||
pHead->version, tstrerror(code));
|
||||
pWrite->code = vnodeProcessWrite(pVnode, pWrite->pHead, qtype, &pWrite->rspRet);
|
||||
if (pWrite->code <= 0) pWrite->processedCount = 1;
|
||||
if (pWrite->pHead->msgType != TSDB_MSG_TYPE_SUBMIT) forceFsync = true;
|
||||
|
||||
if (pWrite) {
|
||||
pWrite->rpcMsg.code = code;
|
||||
if (code <= 0) pWrite->processedCount = 1;
|
||||
}
|
||||
dTrace("msg:%p is processed in vwrite queue, result:%s", pWrite, tstrerror(pWrite->code));
|
||||
}
|
||||
|
||||
walFsync(vnodeGetWal(pVnode));
|
||||
walFsync(vnodeGetWal(pVnode), forceFsync);
|
||||
|
||||
// browse all items, and process them one by one
|
||||
taosResetQitems(pWorker->qall);
|
||||
for (int32_t i = 0; i < numOfMsgs; ++i) {
|
||||
taosGetQitem(pWorker->qall, &qtype, &pItem);
|
||||
taosGetQitem(pWorker->qall, &qtype, (void **)&pWrite);
|
||||
if (qtype == TAOS_QTYPE_RPC) {
|
||||
pWrite = pItem;
|
||||
dnodeSendRpcVWriteRsp(pVnode, pItem, pWrite->rpcMsg.code);
|
||||
dnodeSendRpcVWriteRsp(pVnode, pWrite, pWrite->code);
|
||||
} else if (qtype == TAOS_QTYPE_FWD) {
|
||||
pHead = pItem;
|
||||
vnodeConfirmForward(pVnode, pHead->version, 0);
|
||||
taosFreeQitem(pItem);
|
||||
vnodeConfirmForward(pVnode, pWrite->pHead->version, 0);
|
||||
taosFreeQitem(pWrite);
|
||||
vnodeRelease(pVnode);
|
||||
} else {
|
||||
taosFreeQitem(pItem);
|
||||
taosFreeQitem(pWrite);
|
||||
vnodeRelease(pVnode);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -55,9 +55,9 @@ void *dnodeSendCfgTableToRecv(int32_t vgId, int32_t tid);
|
|||
|
||||
void *dnodeAllocVWriteQueue(void *pVnode);
|
||||
void dnodeFreeVWriteQueue(void *wqueue);
|
||||
void dnodeSendRpcVWriteRsp(void *pVnode, void *param, int32_t code);
|
||||
void *dnodeAllocVReadQueue(void *pVnode);
|
||||
void dnodeFreeVReadQueue(void *rqueue);
|
||||
void dnodeSendRpcVWriteRsp(void *pVnode, void *param, int32_t code);
|
||||
|
||||
int32_t dnodeAllocateMnodePqueue();
|
||||
void dnodeFreeMnodePqueue();
|
||||
|
|
|
@ -75,6 +75,7 @@ extern const int32_t TYPE_BYTES[11];
|
|||
#define TSDB_DATA_SMALLINT_NULL 0x8000
|
||||
#define TSDB_DATA_INT_NULL 0x80000000L
|
||||
#define TSDB_DATA_BIGINT_NULL 0x8000000000000000L
|
||||
#define TSDB_DATA_TIMESTAMP_NULL TSDB_DATA_BIGINT_NULL
|
||||
|
||||
#define TSDB_DATA_FLOAT_NULL 0x7FF00000 // it is an NAN
|
||||
#define TSDB_DATA_DOUBLE_NULL 0x7FFFFF0000000000L // an NAN
|
||||
|
@ -363,6 +364,10 @@ void tsDataSwap(void *pLeft, void *pRight, int32_t type, int32_t size, void* buf
|
|||
#define TSDB_MAX_WAL_LEVEL 2
|
||||
#define TSDB_DEFAULT_WAL_LEVEL 1
|
||||
|
||||
#define TSDB_MIN_DB_UPDATE 0
|
||||
#define TSDB_MAX_DB_UPDATE 1
|
||||
#define TSDB_DEFAULT_DB_UPDATE_OPTION 0
|
||||
|
||||
#define TSDB_MIN_FSYNC_PERIOD 0
|
||||
#define TSDB_MAX_FSYNC_PERIOD 180000 // millisecond
|
||||
#define TSDB_DEFAULT_FSYNC_PERIOD 3000 // three second
|
||||
|
|
|
@ -544,6 +544,8 @@ typedef struct {
|
|||
int8_t replications;
|
||||
int8_t quorum;
|
||||
int8_t ignoreExist;
|
||||
int8_t update;
|
||||
int8_t reserve[9];
|
||||
} SCreateDbMsg, SAlterDbMsg;
|
||||
|
||||
typedef struct {
|
||||
|
@ -654,7 +656,8 @@ typedef struct {
|
|||
int8_t replications;
|
||||
int8_t wals;
|
||||
int8_t quorum;
|
||||
int8_t reserved[16];
|
||||
int8_t update;
|
||||
int8_t reserved[15];
|
||||
} SVnodeCfg;
|
||||
|
||||
typedef struct {
|
||||
|
|
|
@ -21,7 +21,7 @@ extern "C" {
|
|||
|
||||
#include "tdataformat.h"
|
||||
|
||||
typedef int (*FCqWrite)(void *ahandle, void *pHead, int type);
|
||||
typedef int32_t (*FCqWrite)(void *ahandle, void *pHead, int32_t qtype, void *pMsg);
|
||||
|
||||
typedef struct {
|
||||
int vgId;
|
||||
|
|
|
@ -83,13 +83,13 @@ void rpcClose(void *);
|
|||
void *rpcMallocCont(int contLen);
|
||||
void rpcFreeCont(void *pCont);
|
||||
void *rpcReallocCont(void *ptr, int contLen);
|
||||
void rpcSendRequest(void *thandle, const SRpcEpSet *pEpSet, SRpcMsg *pMsg);
|
||||
int64_t rpcSendRequest(void *thandle, const SRpcEpSet *pEpSet, SRpcMsg *pMsg);
|
||||
void rpcSendResponse(const SRpcMsg *pMsg);
|
||||
void rpcSendRedirectRsp(void *pConn, const SRpcEpSet *pEpSet);
|
||||
int rpcGetConnInfo(void *thandle, SRpcConnInfo *pInfo);
|
||||
void rpcSendRecv(void *shandle, SRpcEpSet *pEpSet, SRpcMsg *pReq, SRpcMsg *pRsp);
|
||||
int rpcReportProgress(void *pConn, char *pCont, int contLen);
|
||||
void rpcCancelRequest(void *pContext);
|
||||
void rpcCancelRequest(int64_t rid);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
|
|
@ -65,6 +65,7 @@ typedef struct {
|
|||
int32_t maxRowsPerFileBlock; // maximum rows per file block
|
||||
int8_t precision;
|
||||
int8_t compression;
|
||||
int8_t update;
|
||||
} STsdbCfg;
|
||||
|
||||
// --------- TSDB REPOSITORY USAGE STATISTICS
|
||||
|
|
|
@ -70,8 +70,8 @@ typedef uint32_t (*FGetFileInfo)(void *ahandle, char *name, uint32_t *index, uin
|
|||
// return value, -1: error, 1:more wal files, 0:last WAL. if name[0]==0, no WAL file
|
||||
typedef int32_t (*FGetWalInfo)(void *ahandle, char *fileName, int64_t *fileId);
|
||||
|
||||
// when a forward pkt is received, call this to handle data
|
||||
typedef int (*FWriteToCache)(void *ahandle, void *pHead, int type);
|
||||
// when a forward pkt is received, call this to handle data
|
||||
typedef int32_t (*FWriteToCache)(void *ahandle, void *pHead, int32_t qtype, void *pMsg);
|
||||
|
||||
// when forward is confirmed by peer, master call this API to notify app
|
||||
typedef void (*FConfirmForward)(void *ahandle, void *mhandle, int32_t code);
|
||||
|
@ -106,13 +106,13 @@ typedef void* tsync_h;
|
|||
int32_t syncInit();
|
||||
void syncCleanUp();
|
||||
|
||||
tsync_h syncStart(const SSyncInfo *);
|
||||
void syncStop(tsync_h shandle);
|
||||
int32_t syncReconfig(tsync_h shandle, const SSyncCfg *);
|
||||
int32_t syncForwardToPeer(tsync_h shandle, void *pHead, void *mhandle, int qtype);
|
||||
void syncConfirmForward(tsync_h shandle, uint64_t version, int32_t code);
|
||||
void syncRecover(tsync_h shandle); // recover from other nodes:
|
||||
int syncGetNodesRole(tsync_h shandle, SNodesRole *);
|
||||
int64_t syncStart(const SSyncInfo *);
|
||||
void syncStop(int64_t rid);
|
||||
int32_t syncReconfig(int64_t rid, const SSyncCfg *);
|
||||
int32_t syncForwardToPeer(int64_t rid, void *pHead, void *mhandle, int qtype);
|
||||
void syncConfirmForward(int64_t rid, uint64_t version, int32_t code);
|
||||
void syncRecover(int64_t rid); // recover from other nodes:
|
||||
int syncGetNodesRole(int64_t rid, SNodesRole *);
|
||||
|
||||
extern char *syncRole[];
|
||||
|
||||
|
|
|
@ -114,114 +114,115 @@
|
|||
#define TK_FSYNC 95
|
||||
#define TK_COMP 96
|
||||
#define TK_PRECISION 97
|
||||
#define TK_LP 98
|
||||
#define TK_RP 99
|
||||
#define TK_TAGS 100
|
||||
#define TK_USING 101
|
||||
#define TK_AS 102
|
||||
#define TK_COMMA 103
|
||||
#define TK_NULL 104
|
||||
#define TK_SELECT 105
|
||||
#define TK_UNION 106
|
||||
#define TK_ALL 107
|
||||
#define TK_FROM 108
|
||||
#define TK_VARIABLE 109
|
||||
#define TK_INTERVAL 110
|
||||
#define TK_FILL 111
|
||||
#define TK_SLIDING 112
|
||||
#define TK_ORDER 113
|
||||
#define TK_BY 114
|
||||
#define TK_ASC 115
|
||||
#define TK_DESC 116
|
||||
#define TK_GROUP 117
|
||||
#define TK_HAVING 118
|
||||
#define TK_LIMIT 119
|
||||
#define TK_OFFSET 120
|
||||
#define TK_SLIMIT 121
|
||||
#define TK_SOFFSET 122
|
||||
#define TK_WHERE 123
|
||||
#define TK_NOW 124
|
||||
#define TK_RESET 125
|
||||
#define TK_QUERY 126
|
||||
#define TK_ADD 127
|
||||
#define TK_COLUMN 128
|
||||
#define TK_TAG 129
|
||||
#define TK_CHANGE 130
|
||||
#define TK_SET 131
|
||||
#define TK_KILL 132
|
||||
#define TK_CONNECTION 133
|
||||
#define TK_STREAM 134
|
||||
#define TK_COLON 135
|
||||
#define TK_ABORT 136
|
||||
#define TK_AFTER 137
|
||||
#define TK_ATTACH 138
|
||||
#define TK_BEFORE 139
|
||||
#define TK_BEGIN 140
|
||||
#define TK_CASCADE 141
|
||||
#define TK_CLUSTER 142
|
||||
#define TK_CONFLICT 143
|
||||
#define TK_COPY 144
|
||||
#define TK_DEFERRED 145
|
||||
#define TK_DELIMITERS 146
|
||||
#define TK_DETACH 147
|
||||
#define TK_EACH 148
|
||||
#define TK_END 149
|
||||
#define TK_EXPLAIN 150
|
||||
#define TK_FAIL 151
|
||||
#define TK_FOR 152
|
||||
#define TK_IGNORE 153
|
||||
#define TK_IMMEDIATE 154
|
||||
#define TK_INITIALLY 155
|
||||
#define TK_INSTEAD 156
|
||||
#define TK_MATCH 157
|
||||
#define TK_KEY 158
|
||||
#define TK_OF 159
|
||||
#define TK_RAISE 160
|
||||
#define TK_REPLACE 161
|
||||
#define TK_RESTRICT 162
|
||||
#define TK_ROW 163
|
||||
#define TK_STATEMENT 164
|
||||
#define TK_TRIGGER 165
|
||||
#define TK_VIEW 166
|
||||
#define TK_COUNT 167
|
||||
#define TK_SUM 168
|
||||
#define TK_AVG 169
|
||||
#define TK_MIN 170
|
||||
#define TK_MAX 171
|
||||
#define TK_FIRST 172
|
||||
#define TK_LAST 173
|
||||
#define TK_TOP 174
|
||||
#define TK_BOTTOM 175
|
||||
#define TK_STDDEV 176
|
||||
#define TK_PERCENTILE 177
|
||||
#define TK_APERCENTILE 178
|
||||
#define TK_LEASTSQUARES 179
|
||||
#define TK_HISTOGRAM 180
|
||||
#define TK_DIFF 181
|
||||
#define TK_SPREAD 182
|
||||
#define TK_TWA 183
|
||||
#define TK_INTERP 184
|
||||
#define TK_LAST_ROW 185
|
||||
#define TK_RATE 186
|
||||
#define TK_IRATE 187
|
||||
#define TK_SUM_RATE 188
|
||||
#define TK_SUM_IRATE 189
|
||||
#define TK_AVG_RATE 190
|
||||
#define TK_AVG_IRATE 191
|
||||
#define TK_TBID 192
|
||||
#define TK_SEMI 193
|
||||
#define TK_NONE 194
|
||||
#define TK_PREV 195
|
||||
#define TK_LINEAR 196
|
||||
#define TK_IMPORT 197
|
||||
#define TK_METRIC 198
|
||||
#define TK_TBNAME 199
|
||||
#define TK_JOIN 200
|
||||
#define TK_METRICS 201
|
||||
#define TK_STABLE 202
|
||||
#define TK_INSERT 203
|
||||
#define TK_INTO 204
|
||||
#define TK_VALUES 205
|
||||
#define TK_UPDATE 98
|
||||
#define TK_LP 99
|
||||
#define TK_RP 100
|
||||
#define TK_TAGS 101
|
||||
#define TK_USING 102
|
||||
#define TK_AS 103
|
||||
#define TK_COMMA 104
|
||||
#define TK_NULL 105
|
||||
#define TK_SELECT 106
|
||||
#define TK_UNION 107
|
||||
#define TK_ALL 108
|
||||
#define TK_FROM 109
|
||||
#define TK_VARIABLE 110
|
||||
#define TK_INTERVAL 111
|
||||
#define TK_FILL 112
|
||||
#define TK_SLIDING 113
|
||||
#define TK_ORDER 114
|
||||
#define TK_BY 115
|
||||
#define TK_ASC 116
|
||||
#define TK_DESC 117
|
||||
#define TK_GROUP 118
|
||||
#define TK_HAVING 119
|
||||
#define TK_LIMIT 120
|
||||
#define TK_OFFSET 121
|
||||
#define TK_SLIMIT 122
|
||||
#define TK_SOFFSET 123
|
||||
#define TK_WHERE 124
|
||||
#define TK_NOW 125
|
||||
#define TK_RESET 126
|
||||
#define TK_QUERY 127
|
||||
#define TK_ADD 128
|
||||
#define TK_COLUMN 129
|
||||
#define TK_TAG 130
|
||||
#define TK_CHANGE 131
|
||||
#define TK_SET 132
|
||||
#define TK_KILL 133
|
||||
#define TK_CONNECTION 134
|
||||
#define TK_STREAM 135
|
||||
#define TK_COLON 136
|
||||
#define TK_ABORT 137
|
||||
#define TK_AFTER 138
|
||||
#define TK_ATTACH 139
|
||||
#define TK_BEFORE 140
|
||||
#define TK_BEGIN 141
|
||||
#define TK_CASCADE 142
|
||||
#define TK_CLUSTER 143
|
||||
#define TK_CONFLICT 144
|
||||
#define TK_COPY 145
|
||||
#define TK_DEFERRED 146
|
||||
#define TK_DELIMITERS 147
|
||||
#define TK_DETACH 148
|
||||
#define TK_EACH 149
|
||||
#define TK_END 150
|
||||
#define TK_EXPLAIN 151
|
||||
#define TK_FAIL 152
|
||||
#define TK_FOR 153
|
||||
#define TK_IGNORE 154
|
||||
#define TK_IMMEDIATE 155
|
||||
#define TK_INITIALLY 156
|
||||
#define TK_INSTEAD 157
|
||||
#define TK_MATCH 158
|
||||
#define TK_KEY 159
|
||||
#define TK_OF 160
|
||||
#define TK_RAISE 161
|
||||
#define TK_REPLACE 162
|
||||
#define TK_RESTRICT 163
|
||||
#define TK_ROW 164
|
||||
#define TK_STATEMENT 165
|
||||
#define TK_TRIGGER 166
|
||||
#define TK_VIEW 167
|
||||
#define TK_COUNT 168
|
||||
#define TK_SUM 169
|
||||
#define TK_AVG 170
|
||||
#define TK_MIN 171
|
||||
#define TK_MAX 172
|
||||
#define TK_FIRST 173
|
||||
#define TK_LAST 174
|
||||
#define TK_TOP 175
|
||||
#define TK_BOTTOM 176
|
||||
#define TK_STDDEV 177
|
||||
#define TK_PERCENTILE 178
|
||||
#define TK_APERCENTILE 179
|
||||
#define TK_LEASTSQUARES 180
|
||||
#define TK_HISTOGRAM 181
|
||||
#define TK_DIFF 182
|
||||
#define TK_SPREAD 183
|
||||
#define TK_TWA 184
|
||||
#define TK_INTERP 185
|
||||
#define TK_LAST_ROW 186
|
||||
#define TK_RATE 187
|
||||
#define TK_IRATE 188
|
||||
#define TK_SUM_RATE 189
|
||||
#define TK_SUM_IRATE 190
|
||||
#define TK_AVG_RATE 191
|
||||
#define TK_AVG_IRATE 192
|
||||
#define TK_TBID 193
|
||||
#define TK_SEMI 194
|
||||
#define TK_NONE 195
|
||||
#define TK_PREV 196
|
||||
#define TK_LINEAR 197
|
||||
#define TK_IMPORT 198
|
||||
#define TK_METRIC 199
|
||||
#define TK_TBNAME 200
|
||||
#define TK_JOIN 201
|
||||
#define TK_METRICS 202
|
||||
#define TK_STABLE 203
|
||||
#define TK_INSERT 204
|
||||
#define TK_INTO 205
|
||||
#define TK_VALUES 206
|
||||
|
||||
#define TK_SPACE 300
|
||||
#define TK_COMMENT 301
|
||||
|
|
|
@ -43,8 +43,8 @@ typedef struct {
|
|||
int8_t keep; // keep the wal file when closed
|
||||
} SWalCfg;
|
||||
|
||||
typedef void* twalh; // WAL HANDLE
|
||||
typedef int (*FWalWrite)(void *ahandle, void *pHead, int type);
|
||||
typedef void * twalh; // WAL HANDLE
|
||||
typedef int32_t FWalWrite(void *ahandle, void *pHead, int32_t qtype, void *pMsg);
|
||||
|
||||
int32_t walInit();
|
||||
void walCleanUp();
|
||||
|
@ -55,7 +55,7 @@ void walStop(twalh);
|
|||
void walClose(twalh);
|
||||
int32_t walRenew(twalh);
|
||||
int32_t walWrite(twalh, SWalHead *);
|
||||
void walFsync(twalh);
|
||||
void walFsync(twalh, bool forceFsync);
|
||||
int32_t walRestore(twalh, void *pVnode, FWalWrite writeFp);
|
||||
int32_t walGetWalFile(twalh, char *fileName, int64_t *fileId);
|
||||
int64_t walGetVersion(twalh);
|
||||
|
|
|
@ -20,6 +20,8 @@
|
|||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include "twal.h"
|
||||
|
||||
typedef enum _VN_STATUS {
|
||||
TAOS_VN_STATUS_INIT,
|
||||
TAOS_VN_STATUS_READY,
|
||||
|
@ -29,17 +31,32 @@ typedef enum _VN_STATUS {
|
|||
} EVnStatus;
|
||||
|
||||
typedef struct {
|
||||
int len;
|
||||
void *rsp;
|
||||
void *qhandle; //used by query and retrieve msg
|
||||
int32_t len;
|
||||
void * rsp;
|
||||
void * qhandle; // used by query and retrieve msg
|
||||
} SRspRet;
|
||||
|
||||
typedef struct {
|
||||
int32_t code;
|
||||
int32_t contLen;
|
||||
void * rpcHandle;
|
||||
void * rpcAhandle;
|
||||
void * qhandle;
|
||||
int8_t qtype;
|
||||
int8_t msgType;
|
||||
SRspRet rspRet;
|
||||
char pCont[];
|
||||
} SVReadMsg;
|
||||
|
||||
typedef struct {
|
||||
int32_t code;
|
||||
int32_t processedCount;
|
||||
void * rpcHandle;
|
||||
void * rpcAhandle;
|
||||
SRspRet rspRet;
|
||||
void *pCont;
|
||||
int32_t contLen;
|
||||
SRpcMsg rpcMsg;
|
||||
} SReadMsg;
|
||||
char reserveForSync[16];
|
||||
SWalHead pHead[];
|
||||
} SVWriteMsg;
|
||||
|
||||
extern char *vnodeStatus[];
|
||||
|
||||
|
@ -50,13 +67,11 @@ int32_t vnodeAlter(void *pVnode, SCreateVnodeMsg *pVnodeCfg);
|
|||
int32_t vnodeClose(int32_t vgId);
|
||||
|
||||
void* vnodeAcquire(int32_t vgId); // add refcount
|
||||
void* vnodeAcquireRqueue(int32_t vgId); // add refCount, get read queue
|
||||
void* vnodeAcquireWqueue(int32_t vgId); // add recCount, get write queue
|
||||
void vnodeRelease(void *pVnode); // dec refCount
|
||||
void* vnodeGetWal(void *pVnode);
|
||||
|
||||
int32_t vnodeProcessWrite(void *pVnode, int qtype, void *pHead, void *item);
|
||||
int32_t vnodeCheckWrite(void *pVnode);
|
||||
int32_t vnodeWriteToWQueue(void *vparam, void *wparam, int32_t qtype, void *rparam);
|
||||
int32_t vnodeProcessWrite(void *vparam, void *wparam, int32_t qtype, void *rparam);
|
||||
int32_t vnodeGetVnodeList(int32_t vnodeList[], int32_t *numOfVnodes);
|
||||
void vnodeBuildStatusMsg(void *param);
|
||||
void vnodeConfirmForward(void *param, uint64_t version, int32_t code);
|
||||
|
@ -65,8 +80,8 @@ void vnodeSetAccess(SVgroupAccess *pAccess, int32_t numOfVnodes);
|
|||
int32_t vnodeInitResources();
|
||||
void vnodeCleanupResources();
|
||||
|
||||
int32_t vnodeProcessRead(void *pVnode, SReadMsg *pReadMsg);
|
||||
int32_t vnodeCheckRead(void *pVnode);
|
||||
int32_t vnodeWriteToRQueue(void *vparam, void *pCont, int32_t contLen, int8_t qtype, void *rparam);
|
||||
int32_t vnodeProcessRead(void *pVnode, SVReadMsg *pRead);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
|
|
@ -172,7 +172,8 @@ typedef struct {
|
|||
int8_t walLevel;
|
||||
int8_t replications;
|
||||
int8_t quorum;
|
||||
int8_t reserved[12];
|
||||
int8_t update;
|
||||
int8_t reserved[11];
|
||||
} SDbCfg;
|
||||
|
||||
typedef struct SDbObj {
|
||||
|
|
|
@ -319,6 +319,11 @@ static int32_t mnodeCheckDbCfg(SDbCfg *pCfg) {
|
|||
}
|
||||
#endif
|
||||
|
||||
if (pCfg->update < TSDB_MIN_DB_UPDATE || pCfg->update > TSDB_MAX_DB_UPDATE) {
|
||||
mError("invalid db option update:%d valid range: [%d, %d]", pCfg->update, TSDB_MIN_DB_UPDATE, TSDB_MAX_DB_UPDATE);
|
||||
return TSDB_CODE_MND_INVALID_DB_OPTION;
|
||||
}
|
||||
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
|
@ -339,6 +344,7 @@ static void mnodeSetDefaultDbCfg(SDbCfg *pCfg) {
|
|||
if (pCfg->walLevel < 0) pCfg->walLevel = tsWAL;
|
||||
if (pCfg->replications < 0) pCfg->replications = tsReplications;
|
||||
if (pCfg->quorum < 0) pCfg->quorum = tsQuorum;
|
||||
if (pCfg->update < 0) pCfg->update = tsUpdate;
|
||||
}
|
||||
|
||||
static int32_t mnodeCreateDbCb(SMnodeMsg *pMsg, int32_t code) {
|
||||
|
@ -391,7 +397,8 @@ static int32_t mnodeCreateDb(SAcctObj *pAcct, SCreateDbMsg *pCreate, SMnodeMsg *
|
|||
.compression = pCreate->compression,
|
||||
.walLevel = pCreate->walLevel,
|
||||
.replications = pCreate->replications,
|
||||
.quorum = pCreate->quorum
|
||||
.quorum = pCreate->quorum,
|
||||
.update = pCreate->update
|
||||
};
|
||||
|
||||
mnodeSetDefaultDbCfg(&pDb->cfg);
|
||||
|
@ -610,6 +617,12 @@ static int32_t mnodeGetDbMeta(STableMetaMsg *pMeta, SShowObj *pShow, void *pConn
|
|||
pSchema[cols].bytes = htons(pShow->bytes[cols]);
|
||||
cols++;
|
||||
|
||||
pShow->bytes[cols] = 1;
|
||||
pSchema[cols].type = TSDB_DATA_TYPE_TINYINT;
|
||||
strcpy(pSchema[cols].name, "update");
|
||||
pSchema[cols].bytes = htons(pShow->bytes[cols]);
|
||||
cols++;
|
||||
|
||||
pShow->bytes[cols] = 10 + VARSTR_HEADER_SIZE;
|
||||
pSchema[cols].type = TSDB_DATA_TYPE_BINARY;
|
||||
strcpy(pSchema[cols].name, "status");
|
||||
|
@ -749,6 +762,10 @@ static int32_t mnodeRetrieveDbs(SShowObj *pShow, char *data, int32_t rows, void
|
|||
STR_WITH_SIZE_TO_VARSTR(pWrite, prec, 2);
|
||||
cols++;
|
||||
|
||||
pWrite = data + pShow->offset[cols] * rows + pShow->bytes[cols] * numOfRows;
|
||||
*(int8_t *)pWrite = pDb->cfg.update;
|
||||
cols++;
|
||||
|
||||
pWrite = data + pShow->offset[cols] * rows + pShow->bytes[cols] * numOfRows;
|
||||
if (pDb->status == TSDB_DB_STATUS_READY) {
|
||||
const char *src = "ready";
|
||||
|
@ -848,6 +865,7 @@ static SDbCfg mnodeGetAlterDbOption(SDbObj *pDb, SAlterDbMsg *pAlter) {
|
|||
int8_t replications = pAlter->replications;
|
||||
int8_t quorum = pAlter->quorum;
|
||||
int8_t precision = pAlter->precision;
|
||||
int8_t update = pAlter->update;
|
||||
|
||||
terrno = TSDB_CODE_SUCCESS;
|
||||
|
||||
|
@ -950,6 +968,16 @@ static SDbCfg mnodeGetAlterDbOption(SDbObj *pDb, SAlterDbMsg *pAlter) {
|
|||
newCfg.quorum = quorum;
|
||||
}
|
||||
|
||||
if (update >= 0 && update != pDb->cfg.update) {
|
||||
#if 0
|
||||
mDebug("db:%s, update:%d change to %d", pDb->name, pDb->cfg.update, update);
|
||||
newCfg.update = update;
|
||||
#else
|
||||
mError("db:%s, can't alter update option", pDb->name);
|
||||
terrno = TSDB_CODE_MND_INVALID_DB_OPTION;
|
||||
#endif
|
||||
}
|
||||
|
||||
return newCfg;
|
||||
}
|
||||
|
||||
|
|
|
@ -72,7 +72,7 @@ typedef struct {
|
|||
ESyncRole role;
|
||||
ESdbStatus status;
|
||||
int64_t version;
|
||||
void * sync;
|
||||
int64_t sync;
|
||||
void * wal;
|
||||
SSyncCfg cfg;
|
||||
int32_t numOfTables;
|
||||
|
@ -98,8 +98,8 @@ static taos_qall tsSdbWriteQall;
|
|||
static taos_queue tsSdbWriteQueue;
|
||||
static SSdbWriteWorkerPool tsSdbPool;
|
||||
|
||||
static int sdbWrite(void *param, void *data, int type);
|
||||
static int sdbWriteToQueue(void *param, void *data, int type);
|
||||
static int32_t sdbWrite(void *param, void *data, int32_t type, void *pMsg);
|
||||
static int32_t sdbWriteToQueue(void *param, void *data, int32_t type, void *pMsg);
|
||||
static void * sdbWorkerFp(void *param);
|
||||
static int32_t sdbInitWriteWorker();
|
||||
static void sdbCleanupWriteWorker();
|
||||
|
@ -212,7 +212,7 @@ static void sdbRestoreTables() {
|
|||
}
|
||||
|
||||
void sdbUpdateMnodeRoles() {
|
||||
if (tsSdbObj.sync == NULL) return;
|
||||
if (tsSdbObj.sync <= 0) return;
|
||||
|
||||
SNodesRole roles = {0};
|
||||
syncGetNodesRole(tsSdbObj.sync, &roles);
|
||||
|
@ -433,7 +433,7 @@ void sdbCleanUp() {
|
|||
|
||||
if (tsSdbObj.sync) {
|
||||
syncStop(tsSdbObj.sync);
|
||||
tsSdbObj.sync = NULL;
|
||||
tsSdbObj.sync = -1;
|
||||
}
|
||||
|
||||
if (tsSdbObj.wal) {
|
||||
|
@ -575,7 +575,7 @@ static int32_t sdbUpdateHash(SSdbTable *pTable, SSdbOper *pOper) {
|
|||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
static int sdbWrite(void *param, void *data, int type) {
|
||||
static int sdbWrite(void *param, void *data, int32_t type, void *pMsg) {
|
||||
SSdbOper *pOper = param;
|
||||
SWalHead *pHead = data;
|
||||
int32_t tableId = pHead->msgType / 10;
|
||||
|
@ -1040,13 +1040,13 @@ void sdbFreeWritequeue() {
|
|||
tsSdbWriteQueue = NULL;
|
||||
}
|
||||
|
||||
int sdbWriteToQueue(void *param, void *data, int type) {
|
||||
int32_t sdbWriteToQueue(void *param, void *data, int32_t qtype, void *pMsg) {
|
||||
SWalHead *pHead = data;
|
||||
int size = sizeof(SWalHead) + pHead->len;
|
||||
int32_t size = sizeof(SWalHead) + pHead->len;
|
||||
SWalHead *pWal = (SWalHead *)taosAllocateQitem(size);
|
||||
memcpy(pWal, pHead, size);
|
||||
|
||||
taosWriteQitem(tsSdbWriteQueue, type, pWal);
|
||||
taosWriteQitem(tsSdbWriteQueue, qtype, pWal);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -1081,7 +1081,7 @@ static void *sdbWorkerFp(void *param) {
|
|||
pOper = NULL;
|
||||
}
|
||||
|
||||
int32_t code = sdbWrite(pOper, pHead, type);
|
||||
int32_t code = sdbWrite(pOper, pHead, type, NULL);
|
||||
if (code > 0) code = 0;
|
||||
if (pOper) {
|
||||
pOper->retCode = code;
|
||||
|
@ -1090,7 +1090,7 @@ static void *sdbWorkerFp(void *param) {
|
|||
}
|
||||
}
|
||||
|
||||
walFsync(tsSdbObj.wal);
|
||||
walFsync(tsSdbObj.wal, true);
|
||||
|
||||
// browse all items, and process them one by one
|
||||
taosResetQitems(tsSdbWriteQall);
|
||||
|
|
|
@ -850,6 +850,7 @@ static SCreateVnodeMsg *mnodeBuildVnodeMsg(SVgObj *pVgroup) {
|
|||
pCfg->replications = (int8_t) pVgroup->numOfVnodes;
|
||||
pCfg->wals = 3;
|
||||
pCfg->quorum = pDb->cfg.quorum;
|
||||
pCfg->update = pDb->cfg.update;
|
||||
|
||||
SVnodeDesc *pNodes = pVnode->nodes;
|
||||
for (int32_t j = 0; j < pVgroup->numOfVnodes; ++j) {
|
||||
|
|
|
@ -44,7 +44,7 @@ long interlocked_add_fetch_32(long volatile* ptr, long val) {
|
|||
|
||||
__int64 interlocked_add_fetch_64(__int64 volatile* ptr, __int64 val) {
|
||||
//#ifdef _WIN64
|
||||
return _InterlockedExchangeAdd64(ptr, val) + val;
|
||||
return InterlockedExchangeAdd64(ptr, val) + val;
|
||||
//#else
|
||||
// return _InterlockedExchangeAdd(ptr, val) + val;
|
||||
//#endif
|
||||
|
|
|
@ -65,12 +65,12 @@ int64_t taosFSendFile(FILE *out_file, FILE *in_file, int64_t *offset, int64_t co
|
|||
|
||||
int64_t remain = count - writeLen;
|
||||
if (remain > 0) {
|
||||
size_t rlen = fread(buffer, 1, remain, in_file);
|
||||
size_t rlen = fread(buffer, 1, (size_t) remain, in_file);
|
||||
if (rlen <= 0) {
|
||||
return writeLen;
|
||||
}
|
||||
else {
|
||||
fwrite(buffer, 1, remain, out_file);
|
||||
fwrite(buffer, 1, (size_t) remain, out_file);
|
||||
writeLen += remain;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -49,7 +49,6 @@ typedef struct SFillInfo {
|
|||
int32_t numOfTags; // number of tags
|
||||
int32_t numOfCols; // number of columns, including the tags columns
|
||||
int32_t rowSize; // size of each row
|
||||
// char ** pTags; // tags value for current interpolation
|
||||
SFillTagColInfo* pTags; // tags value for filling gap
|
||||
SInterval interval;
|
||||
char * prevValues; // previous row of data, to generate the interpolation results
|
||||
|
@ -83,7 +82,7 @@ int64_t getFilledNumOfRes(SFillInfo* pFillInfo, int64_t ekey, int32_t maxNumOfRo
|
|||
|
||||
int32_t taosNumOfRemainRows(SFillInfo *pFillInfo);
|
||||
|
||||
int taosDoLinearInterpolation(int32_t type, SPoint *point1, SPoint *point2, SPoint *point);
|
||||
int32_t taosGetLinearInterpolationVal(int32_t type, SPoint *point1, SPoint *point2, SPoint *point);
|
||||
|
||||
int64_t taosGenerateDataBlock(SFillInfo* pFillInfo, tFilePage** output, int32_t capacity);
|
||||
|
||||
|
|
|
@ -129,6 +129,7 @@ typedef struct SCreateDBInfo {
|
|||
int32_t compressionLevel;
|
||||
SStrToken precision;
|
||||
bool ignoreExists;
|
||||
int8_t update;
|
||||
|
||||
tVariantList *keep;
|
||||
} SCreateDBInfo;
|
||||
|
|
|
@ -26,7 +26,7 @@ extern "C" {
|
|||
|
||||
#define MEM_BUF_SIZE (1 << 20)
|
||||
#define TS_COMP_FILE_MAGIC 0x87F5EC4C
|
||||
#define TS_COMP_FILE_VNODE_MAX 512
|
||||
#define TS_COMP_FILE_GROUP_MAX 512
|
||||
|
||||
typedef struct STSList {
|
||||
char* rawBuf;
|
||||
|
@ -38,7 +38,7 @@ typedef struct STSList {
|
|||
typedef struct STSElem {
|
||||
TSKEY ts;
|
||||
tVariant* tag;
|
||||
int32_t vnode;
|
||||
int32_t id;
|
||||
} STSElem;
|
||||
|
||||
typedef struct STSCursor {
|
||||
|
@ -60,17 +60,17 @@ typedef struct STSBlock {
|
|||
* The size of buffer file should not be greater than 2G,
|
||||
* and the offset of int32_t type is enough
|
||||
*/
|
||||
typedef struct STSVnodeBlockInfo {
|
||||
int32_t vnode; // vnode id
|
||||
typedef struct STSGroupBlockInfo {
|
||||
int32_t id; // group id
|
||||
int32_t offset; // offset set value in file
|
||||
int32_t numOfBlocks; // number of total blocks
|
||||
int32_t compLen; // compressed size
|
||||
} STSVnodeBlockInfo;
|
||||
} STSGroupBlockInfo;
|
||||
|
||||
typedef struct STSVnodeBlockInfoEx {
|
||||
STSVnodeBlockInfo info;
|
||||
typedef struct STSGroupBlockInfoEx {
|
||||
STSGroupBlockInfo info;
|
||||
int32_t len; // length before compress
|
||||
} STSVnodeBlockInfoEx;
|
||||
} STSGroupBlockInfoEx;
|
||||
|
||||
typedef struct STSBuf {
|
||||
FILE* f;
|
||||
|
@ -78,9 +78,9 @@ typedef struct STSBuf {
|
|||
uint32_t fileSize;
|
||||
|
||||
// todo use array
|
||||
STSVnodeBlockInfoEx* pData;
|
||||
STSGroupBlockInfoEx* pData;
|
||||
uint32_t numOfAlloc;
|
||||
uint32_t numOfVnodes;
|
||||
uint32_t numOfGroups;
|
||||
|
||||
char* assistBuf;
|
||||
int32_t bufSize;
|
||||
|
@ -94,22 +94,22 @@ typedef struct STSBuf {
|
|||
|
||||
typedef struct STSBufFileHeader {
|
||||
uint32_t magic; // file magic number
|
||||
uint32_t numOfVnode; // number of vnode stored in current file
|
||||
uint32_t numOfGroup; // number of group stored in current file
|
||||
int32_t tsOrder; // timestamp order in current file
|
||||
} STSBufFileHeader;
|
||||
|
||||
STSBuf* tsBufCreate(bool autoDelete, int32_t order);
|
||||
STSBuf* tsBufCreateFromFile(const char* path, bool autoDelete);
|
||||
STSBuf* tsBufCreateFromCompBlocks(const char* pData, int32_t numOfBlocks, int32_t len, int32_t tsOrder, int32_t vnodeId);
|
||||
STSBuf* tsBufCreateFromCompBlocks(const char* pData, int32_t numOfBlocks, int32_t len, int32_t tsOrder, int32_t id);
|
||||
|
||||
void* tsBufDestroy(STSBuf* pTSBuf);
|
||||
|
||||
void tsBufAppend(STSBuf* pTSBuf, int32_t vnodeId, tVariant* tag, const char* pData, int32_t len);
|
||||
void tsBufAppend(STSBuf* pTSBuf, int32_t id, tVariant* tag, const char* pData, int32_t len);
|
||||
int32_t tsBufMerge(STSBuf* pDestBuf, const STSBuf* pSrcBuf);
|
||||
|
||||
STSBuf* tsBufClone(STSBuf* pTSBuf);
|
||||
|
||||
STSVnodeBlockInfo* tsBufGetVnodeBlockInfo(STSBuf* pTSBuf, int32_t vnodeId);
|
||||
STSGroupBlockInfo* tsBufGetGroupBlockInfo(STSBuf* pTSBuf, int32_t id);
|
||||
|
||||
void tsBufFlush(STSBuf* pTSBuf);
|
||||
|
||||
|
@ -118,7 +118,7 @@ STSElem tsBufGetElem(STSBuf* pTSBuf);
|
|||
|
||||
bool tsBufNextPos(STSBuf* pTSBuf);
|
||||
|
||||
STSElem tsBufGetElemStartPos(STSBuf* pTSBuf, int32_t vnodeId, tVariant* tag);
|
||||
STSElem tsBufGetElemStartPos(STSBuf* pTSBuf, int32_t id, tVariant* tag);
|
||||
|
||||
STSCursor tsBufGetCursor(STSBuf* pTSBuf);
|
||||
void tsBufSetTraverseOrder(STSBuf* pTSBuf, int32_t order);
|
||||
|
@ -131,11 +131,11 @@ void tsBufSetCursor(STSBuf* pTSBuf, STSCursor* pCur);
|
|||
*/
|
||||
void tsBufDisplay(STSBuf* pTSBuf);
|
||||
|
||||
int32_t tsBufGetNumOfVnodes(STSBuf* pTSBuf);
|
||||
int32_t tsBufGetNumOfGroup(STSBuf* pTSBuf);
|
||||
|
||||
void tsBufGetVnodeIdList(STSBuf* pTSBuf, int32_t* num, int32_t** vnodeId);
|
||||
void tsBufGetGroupIdList(STSBuf* pTSBuf, int32_t* num, int32_t** id);
|
||||
|
||||
int32_t dumpFileBlockByVnodeId(STSBuf* pTSBuf, int32_t vnodeId, void* buf, int32_t* len, int32_t* numOfBlocks);
|
||||
int32_t dumpFileBlockByGroupId(STSBuf* pTSBuf, int32_t id, void* buf, int32_t* len, int32_t* numOfBlocks);
|
||||
|
||||
STSElem tsBufFindElemStartPosByTag(STSBuf* pTSBuf, tVariant* pTag);
|
||||
|
||||
|
|
|
@ -239,6 +239,7 @@ wal(Y) ::= WAL INTEGER(X). { Y = X; }
|
|||
fsync(Y) ::= FSYNC INTEGER(X). { Y = X; }
|
||||
comp(Y) ::= COMP INTEGER(X). { Y = X; }
|
||||
prec(Y) ::= PRECISION STRING(X). { Y = X; }
|
||||
update(Y) ::= UPDATE INTEGER(X). { Y = X; }
|
||||
|
||||
%type db_optr {SCreateDBInfo}
|
||||
db_optr(Y) ::= . {setDefaultCreateDbOption(&Y);}
|
||||
|
@ -256,6 +257,7 @@ db_optr(Y) ::= db_optr(Z) fsync(X). { Y = Z; Y.fsyncPeriod = strtol(X.z
|
|||
db_optr(Y) ::= db_optr(Z) comp(X). { Y = Z; Y.compressionLevel = strtol(X.z, NULL, 10); }
|
||||
db_optr(Y) ::= db_optr(Z) prec(X). { Y = Z; Y.precision = X; }
|
||||
db_optr(Y) ::= db_optr(Z) keep(X). { Y = Z; Y.keep = X; }
|
||||
db_optr(Y) ::= db_optr(Z) update(X). { Y = Z; Y.update = strtol(X.z, NULL, 10); }
|
||||
|
||||
%type alter_db_optr {SCreateDBInfo}
|
||||
alter_db_optr(Y) ::= . { setDefaultCreateDbOption(&Y);}
|
||||
|
@ -267,6 +269,7 @@ alter_db_optr(Y) ::= alter_db_optr(Z) blocks(X). { Y = Z; Y.numOfBlocks = s
|
|||
alter_db_optr(Y) ::= alter_db_optr(Z) comp(X). { Y = Z; Y.compressionLevel = strtol(X.z, NULL, 10); }
|
||||
alter_db_optr(Y) ::= alter_db_optr(Z) wal(X). { Y = Z; Y.walLevel = strtol(X.z, NULL, 10); }
|
||||
alter_db_optr(Y) ::= alter_db_optr(Z) fsync(X). { Y = Z; Y.fsyncPeriod = strtol(X.z, NULL, 10); }
|
||||
alter_db_optr(Y) ::= alter_db_optr(Z) update(X). { Y = Z; Y.update = strtol(X.z, NULL, 10); }
|
||||
|
||||
%type typename {TAOS_FIELD}
|
||||
typename(A) ::= ids(X). {
|
||||
|
|
|
@ -149,7 +149,7 @@ typedef struct SResultRowCellInfo {
|
|||
int8_t hasResult; // result generated, not NULL value
|
||||
bool initialized; // output buffer has been initialized
|
||||
bool complete; // query has completed
|
||||
uint16_t numOfRes; // num of output result in current buffer
|
||||
uint32_t numOfRes; // num of output result in current buffer
|
||||
} SResultRowCellInfo;
|
||||
|
||||
#define GET_ROWCELL_INTERBUF(_c) ((void*) ((char*)(_c) + sizeof(SResultRowCellInfo)))
|
||||
|
|
|
@ -32,7 +32,6 @@
|
|||
#include "tstoken.h"
|
||||
#include "ttokendef.h"
|
||||
#include "tulog.h"
|
||||
#include "tutil.h"
|
||||
|
||||
/*
|
||||
*
|
||||
|
@ -415,9 +414,9 @@ static void tQueryIndexColumn(SSkipList* pSkipList, tQueryInfo* pQueryInfo, SArr
|
|||
}
|
||||
|
||||
if (cond.start != NULL) {
|
||||
iter = tSkipListCreateIterFromVal(pSkipList, (char*) cond.start->v, pSkipList->keyInfo.type, TSDB_ORDER_ASC);
|
||||
iter = tSkipListCreateIterFromVal(pSkipList, (char*) cond.start->v, pSkipList->type, TSDB_ORDER_ASC);
|
||||
} else {
|
||||
iter = tSkipListCreateIterFromVal(pSkipList, (char*)(cond.end ? cond.end->v: NULL), pSkipList->keyInfo.type, TSDB_ORDER_DESC);
|
||||
iter = tSkipListCreateIterFromVal(pSkipList, (char*)(cond.end ? cond.end->v: NULL), pSkipList->type, TSDB_ORDER_DESC);
|
||||
}
|
||||
|
||||
if (cond.start != NULL) {
|
||||
|
@ -432,7 +431,7 @@ static void tQueryIndexColumn(SSkipList* pSkipList, tQueryInfo* pQueryInfo, SArr
|
|||
break;
|
||||
}
|
||||
|
||||
STableKeyInfo info = {.pTable = *(void**)SL_GET_NODE_DATA(pNode), .lastKey = TSKEY_INITIAL_VAL};
|
||||
STableKeyInfo info = {.pTable = (void*)SL_GET_NODE_DATA(pNode), .lastKey = TSKEY_INITIAL_VAL};
|
||||
taosArrayPush(result, &info);
|
||||
}
|
||||
} else if (optr == TSDB_RELATION_GREATER || optr == TSDB_RELATION_GREATER_EQUAL) { // greater equal
|
||||
|
@ -450,7 +449,7 @@ static void tQueryIndexColumn(SSkipList* pSkipList, tQueryInfo* pQueryInfo, SArr
|
|||
if (ret == 0 && optr == TSDB_RELATION_GREATER) {
|
||||
continue;
|
||||
} else {
|
||||
STableKeyInfo info = {.pTable = *(void**)SL_GET_NODE_DATA(pNode), .lastKey = TSKEY_INITIAL_VAL};
|
||||
STableKeyInfo info = {.pTable = (void*)SL_GET_NODE_DATA(pNode), .lastKey = TSKEY_INITIAL_VAL};
|
||||
taosArrayPush(result, &info);
|
||||
comp = false;
|
||||
}
|
||||
|
@ -465,22 +464,22 @@ static void tQueryIndexColumn(SSkipList* pSkipList, tQueryInfo* pQueryInfo, SArr
|
|||
continue;
|
||||
}
|
||||
|
||||
STableKeyInfo info = {.pTable = *(void**)SL_GET_NODE_DATA(pNode), .lastKey = TSKEY_INITIAL_VAL};
|
||||
STableKeyInfo info = {.pTable = (void*)SL_GET_NODE_DATA(pNode), .lastKey = TSKEY_INITIAL_VAL};
|
||||
taosArrayPush(result, &info);
|
||||
}
|
||||
|
||||
tSkipListDestroyIter(iter);
|
||||
|
||||
comp = true;
|
||||
iter = tSkipListCreateIterFromVal(pSkipList, (char*) cond.start->v, pSkipList->keyInfo.type, TSDB_ORDER_DESC);
|
||||
iter = tSkipListCreateIterFromVal(pSkipList, (char*) cond.start->v, pSkipList->type, TSDB_ORDER_DESC);
|
||||
while(tSkipListIterNext(iter)) {
|
||||
SSkipListNode* pNode = tSkipListIterGet(iter);
|
||||
comp = comp && (pQueryInfo->compare(SL_GET_NODE_KEY(pSkipList, pNode), cond.start->v) == 0);
|
||||
if (comp) {
|
||||
if (comp) {
|
||||
continue;
|
||||
}
|
||||
|
||||
STableKeyInfo info = {.pTable = *(void**)SL_GET_NODE_DATA(pNode), .lastKey = TSKEY_INITIAL_VAL};
|
||||
STableKeyInfo info = {.pTable = (void*)SL_GET_NODE_DATA(pNode), .lastKey = TSKEY_INITIAL_VAL};
|
||||
taosArrayPush(result, &info);
|
||||
}
|
||||
|
||||
|
@ -504,7 +503,7 @@ static void tQueryIndexColumn(SSkipList* pSkipList, tQueryInfo* pQueryInfo, SArr
|
|||
if (ret == 0 && optr == TSDB_RELATION_LESS) {
|
||||
continue;
|
||||
} else {
|
||||
STableKeyInfo info = {.pTable = *(void **)SL_GET_NODE_DATA(pNode), .lastKey = TSKEY_INITIAL_VAL};
|
||||
STableKeyInfo info = {.pTable = (void *)SL_GET_NODE_DATA(pNode), .lastKey = TSKEY_INITIAL_VAL};
|
||||
taosArrayPush(result, &info);
|
||||
comp = false; // no need to compare anymore
|
||||
}
|
||||
|
@ -518,7 +517,7 @@ static void tQueryIndexColumn(SSkipList* pSkipList, tQueryInfo* pQueryInfo, SArr
|
|||
bool isnull = isNull(SL_GET_NODE_KEY(pSkipList, pNode), pQueryInfo->sch.type);
|
||||
if ((pQueryInfo->optr == TSDB_RELATION_ISNULL && isnull) ||
|
||||
(pQueryInfo->optr == TSDB_RELATION_NOTNULL && (!isnull))) {
|
||||
STableKeyInfo info = {.pTable = *(void **)SL_GET_NODE_DATA(pNode), .lastKey = TSKEY_INITIAL_VAL};
|
||||
STableKeyInfo info = {.pTable = (void *)SL_GET_NODE_DATA(pNode), .lastKey = TSKEY_INITIAL_VAL};
|
||||
taosArrayPush(result, &info);
|
||||
}
|
||||
}
|
||||
|
@ -609,7 +608,7 @@ int32_t intersect(SArray *pLeft, SArray *pRight, SArray *pFinalRes) {
|
|||
/*
|
||||
* traverse the result and apply the function to each item to check if the item is qualified or not
|
||||
*/
|
||||
static void tArrayTraverse(tExprNode *pExpr, __result_filter_fn_t fp, SArray *pResult) {
|
||||
static UNUSED_FUNC void tArrayTraverse(tExprNode *pExpr, __result_filter_fn_t fp, SArray *pResult) {
|
||||
assert(pExpr->_node.pLeft->nodeType == TSQL_NODE_COL && pExpr->_node.pRight->nodeType == TSQL_NODE_VALUE && fp != NULL);
|
||||
|
||||
// scan the result array list and check for each item in the list
|
||||
|
@ -660,7 +659,7 @@ static bool filterItem(tExprNode *pExpr, const void *pItem, SExprTraverseSupp *p
|
|||
* @param pSchema tag schemas
|
||||
* @param fp filter callback function
|
||||
*/
|
||||
static void exprTreeTraverseImpl(tExprNode *pExpr, SArray *pResult, SExprTraverseSupp *param) {
|
||||
static UNUSED_FUNC void exprTreeTraverseImpl(tExprNode *pExpr, SArray *pResult, SExprTraverseSupp *param) {
|
||||
size_t size = taosArrayGetSize(pResult);
|
||||
|
||||
SArray* array = taosArrayInit(size, POINTER_BYTES);
|
||||
|
@ -682,7 +681,7 @@ static void tSQLBinaryTraverseOnSkipList(tExprNode *pExpr, SArray *pResult, SSki
|
|||
while (tSkipListIterNext(iter)) {
|
||||
SSkipListNode *pNode = tSkipListIterGet(iter);
|
||||
if (filterItem(pExpr, pNode, param)) {
|
||||
taosArrayPush(pResult, SL_GET_NODE_DATA(pNode));
|
||||
taosArrayPush(pResult, &(SL_GET_NODE_DATA(pNode)));
|
||||
}
|
||||
}
|
||||
tSkipListDestroyIter(iter);
|
||||
|
@ -697,7 +696,7 @@ static void tQueryIndexlessColumn(SSkipList* pSkipList, tQueryInfo* pQueryInfo,
|
|||
SSkipListNode *pNode = tSkipListIterGet(iter);
|
||||
char * pData = SL_GET_NODE_DATA(pNode);
|
||||
|
||||
tstr *name = (tstr*) tsdbGetTableName(*(void**) pData);
|
||||
tstr *name = (tstr*) tsdbGetTableName((void*) pData);
|
||||
|
||||
// todo speed up by using hash
|
||||
if (pQueryInfo->sch.colId == TSDB_TBNAME_COLUMN_INDEX) {
|
||||
|
@ -711,7 +710,7 @@ static void tQueryIndexlessColumn(SSkipList* pSkipList, tQueryInfo* pQueryInfo,
|
|||
}
|
||||
|
||||
if (addToResult) {
|
||||
STableKeyInfo info = {.pTable = *(void**)pData, .lastKey = TSKEY_INITIAL_VAL};
|
||||
STableKeyInfo info = {.pTable = (void*)pData, .lastKey = TSKEY_INITIAL_VAL};
|
||||
taosArrayPush(res, &info);
|
||||
}
|
||||
}
|
||||
|
@ -733,10 +732,6 @@ void tExprTreeTraverse(tExprNode *pExpr, SSkipList *pSkipList, SArray *result, S
|
|||
assert(pLeft->nodeType == TSQL_NODE_COL && (pRight->nodeType == TSQL_NODE_VALUE || pRight->nodeType == TSQL_NODE_DUMMY));
|
||||
|
||||
param->setupInfoFn(pExpr, param->pExtInfo);
|
||||
if (pSkipList == NULL) {
|
||||
tArrayTraverse(pExpr, param->nodeFilterFn, result);
|
||||
return;
|
||||
}
|
||||
|
||||
tQueryInfo *pQueryInfo = pExpr->_node.info;
|
||||
if (pQueryInfo->indexed && pQueryInfo->optr != TSDB_RELATION_LIKE) {
|
||||
|
@ -748,49 +743,14 @@ void tExprTreeTraverse(tExprNode *pExpr, SSkipList *pSkipList, SArray *result, S
|
|||
return;
|
||||
}
|
||||
|
||||
// recursive traverse left child branch
|
||||
// The value of hasPK is always 0.
|
||||
uint8_t weight = pLeft->_node.hasPK + pRight->_node.hasPK;
|
||||
assert(weight == 0 && pSkipList != NULL && taosArrayGetSize(result) == 0);
|
||||
|
||||
if (weight == 0 ) {
|
||||
if (taosArrayGetSize(result) > 0 && pSkipList == NULL) {
|
||||
/**
|
||||
* Perform the filter operation based on the initial filter result, which is obtained from filtering from index.
|
||||
* Since no index presented, the filter operation is done by scan all elements in the result set.
|
||||
*
|
||||
* if the query is a high selectivity filter, only small portion of meters are retrieved.
|
||||
*/
|
||||
exprTreeTraverseImpl(pExpr, result, param);
|
||||
} else {
|
||||
/**
|
||||
* apply the hierarchical expression to every node in skiplist for find the qualified nodes
|
||||
*/
|
||||
assert(taosArrayGetSize(result) == 0);
|
||||
tSQLBinaryTraverseOnSkipList(pExpr, result, pSkipList, param);
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if (weight == 2 || (weight == 1 && pExpr->_node.optr == TSDB_RELATION_OR)) {
|
||||
SArray* rLeft = taosArrayInit(10, POINTER_BYTES);
|
||||
SArray* rRight = taosArrayInit(10, POINTER_BYTES);
|
||||
|
||||
tExprTreeTraverse(pLeft, pSkipList, rLeft, param);
|
||||
tExprTreeTraverse(pRight, pSkipList, rRight, param);
|
||||
|
||||
if (pExpr->_node.optr == TSDB_RELATION_AND) { // CROSS
|
||||
intersect(rLeft, rRight, result);
|
||||
} else if (pExpr->_node.optr == TSDB_RELATION_OR) { // or
|
||||
merge(rLeft, rRight, result);
|
||||
} else {
|
||||
assert(false);
|
||||
}
|
||||
|
||||
taosArrayDestroy(rLeft);
|
||||
taosArrayDestroy(rRight);
|
||||
return;
|
||||
}
|
||||
//apply the hierarchical expression to every node in skiplist for find the qualified nodes
|
||||
tSQLBinaryTraverseOnSkipList(pExpr, result, pSkipList, param);
|
||||
|
||||
#if 0
|
||||
/*
|
||||
* (weight == 1 && pExpr->nSQLBinaryOptr == TSDB_RELATION_AND) is handled here
|
||||
*
|
||||
|
@ -819,6 +779,7 @@ void tExprTreeTraverse(tExprNode *pExpr, SSkipList *pSkipList, SArray *result, S
|
|||
* So, we do not set the skip list index as a parameter
|
||||
*/
|
||||
tExprTreeTraverse(pSecond, NULL, result, param);
|
||||
#endif
|
||||
}
|
||||
|
||||
void tExprTreeCalcTraverse(tExprNode *pExprs, int32_t numOfRows, char *pOutput, void *param, int32_t order,
|
||||
|
|
|
@ -1609,7 +1609,7 @@ static int32_t setupQueryRuntimeEnv(SQueryRuntimeEnv *pRuntimeEnv, int16_t order
|
|||
|
||||
pRuntimeEnv->pCtx = (SQLFunctionCtx *)calloc(pQuery->numOfOutput, sizeof(SQLFunctionCtx));
|
||||
pRuntimeEnv->rowCellInfoOffset = calloc(pQuery->numOfOutput, sizeof(int32_t));
|
||||
pRuntimeEnv->pResultRow = getNewResultRow(pRuntimeEnv->pool);//calloc(1, sizeof(SResultRow));
|
||||
pRuntimeEnv->pResultRow = getNewResultRow(pRuntimeEnv->pool);
|
||||
|
||||
if (pRuntimeEnv->pResultRow == NULL || pRuntimeEnv->pCtx == NULL || pRuntimeEnv->rowCellInfoOffset == NULL) {
|
||||
goto _clean;
|
||||
|
@ -1745,6 +1745,7 @@ static void teardownQueryRuntimeEnv(SQueryRuntimeEnv *pRuntimeEnv) {
|
|||
|
||||
pRuntimeEnv->pTSBuf = tsBufDestroy(pRuntimeEnv->pTSBuf);
|
||||
taosTFree(pRuntimeEnv->keyBuf);
|
||||
taosTFree(pRuntimeEnv->rowCellInfoOffset);
|
||||
|
||||
taosHashCleanup(pRuntimeEnv->pResultRowHashTable);
|
||||
pRuntimeEnv->pResultRowHashTable = NULL;
|
||||
|
@ -3843,7 +3844,7 @@ int32_t setAdditionalInfo(SQInfo *pQInfo, void* pTable, STableQueryInfo *pTableQ
|
|||
STSElem elem = tsBufGetElemStartPos(pRuntimeEnv->pTSBuf, pQInfo->vgId, &pTableQueryInfo->tag);
|
||||
|
||||
// failed to find data with the specified tag value and vnodeId
|
||||
if (elem.vnode < 0) {
|
||||
if (!tsBufIsValidElem(&elem)) {
|
||||
if (pTag->nType == TSDB_DATA_TYPE_BINARY || pTag->nType == TSDB_DATA_TYPE_NCHAR) {
|
||||
qError("QInfo:%p failed to find tag:%s in ts_comp", pQInfo, pTag->pz);
|
||||
} else {
|
||||
|
@ -4777,7 +4778,7 @@ static bool multiTableMultioutputHelper(SQInfo *pQInfo, int32_t index) {
|
|||
if (pRuntimeEnv->cur.vgroupIndex == -1) {
|
||||
STSElem elem = tsBufGetElemStartPos(pRuntimeEnv->pTSBuf, pQInfo->vgId, pTag);
|
||||
// failed to find data with the specified tag value and vnodeId
|
||||
if (elem.vnode < 0) {
|
||||
if (!tsBufIsValidElem(&elem)) {
|
||||
if (pTag->nType == TSDB_DATA_TYPE_BINARY || pTag->nType == TSDB_DATA_TYPE_NCHAR) {
|
||||
qError("QInfo:%p failed to find tag:%s in ts_comp", pQInfo, pTag->pz);
|
||||
} else {
|
||||
|
@ -4802,7 +4803,7 @@ static bool multiTableMultioutputHelper(SQInfo *pQInfo, int32_t index) {
|
|||
|
||||
STSElem elem1 = tsBufGetElemStartPos(pRuntimeEnv->pTSBuf, pQInfo->vgId, pTag);
|
||||
// failed to find data with the specified tag value and vnodeId
|
||||
if (elem1.vnode < 0) {
|
||||
if (!tsBufIsValidElem(&elem1)) {
|
||||
if (pTag->nType == TSDB_DATA_TYPE_BINARY || pTag->nType == TSDB_DATA_TYPE_NCHAR) {
|
||||
qError("QInfo:%p failed to find tag:%s in ts_comp", pQInfo, pTag->pz);
|
||||
} else {
|
||||
|
|
|
@ -170,7 +170,7 @@ int64_t getFilledNumOfRes(SFillInfo* pFillInfo, TSKEY ekey, int32_t maxNumOfRows
|
|||
int32_t numOfRows = taosNumOfRemainRows(pFillInfo);
|
||||
|
||||
TSKEY ekey1 = ekey;
|
||||
if (pFillInfo->order != TSDB_ORDER_ASC) {
|
||||
if (!FILL_IS_ASC_FILL(pFillInfo)) {
|
||||
pFillInfo->endKey = taosTimeTruncate(ekey, &pFillInfo->interval, pFillInfo->precision);
|
||||
}
|
||||
|
||||
|
@ -215,7 +215,7 @@ static double linearInterpolationImpl(double v1, double v2, double k1, double k2
|
|||
return v1 + (v2 - v1) * (k - k1) / (k2 - k1);
|
||||
}
|
||||
|
||||
int taosDoLinearInterpolation(int32_t type, SPoint* point1, SPoint* point2, SPoint* point) {
|
||||
int32_t taosGetLinearInterpolationVal(int32_t type, SPoint* point1, SPoint* point2, SPoint* point) {
|
||||
switch (type) {
|
||||
case TSDB_DATA_TYPE_INT: {
|
||||
*(int32_t*)point->val = (int32_t)linearInterpolationImpl(*(int32_t*)point1->val, *(int32_t*)point2->val, (double)point1->key,
|
||||
|
@ -343,7 +343,7 @@ static void doFillResultImpl(SFillInfo* pFillInfo, tFilePage** data, int32_t* nu
|
|||
point1 = (SPoint){.key = *(TSKEY*)(prevValues), .val = prevValues + pCol->col.offset};
|
||||
point2 = (SPoint){.key = ts, .val = srcData[i] + pFillInfo->rowIdx * bytes};
|
||||
point = (SPoint){.key = pFillInfo->start, .val = val1};
|
||||
taosDoLinearInterpolation(type, &point1, &point2, &point);
|
||||
taosGetLinearInterpolationVal(type, &point1, &point2, &point);
|
||||
}
|
||||
|
||||
setTagsValue(pFillInfo, data, *num);
|
||||
|
|
|
@ -168,7 +168,7 @@ int32_t tHistogramAdd(SHistogramInfo** pHisto, double val) {
|
|||
(*pHisto)->numOfEntries += 1;
|
||||
}
|
||||
} else { /* insert a new slot */
|
||||
if ((*pHisto)->numOfElems > 1 && idx < (*pHisto)->numOfEntries) {
|
||||
if ((*pHisto)->numOfElems >= 1 && idx < (*pHisto)->numOfEntries) {
|
||||
if (idx > 0) {
|
||||
assert((*pHisto)->elems[idx - 1].val <= val);
|
||||
}
|
||||
|
@ -661,4 +661,4 @@ SHistogramInfo* tHistogramMerge(SHistogramInfo* pHisto1, SHistogramInfo* pHisto2
|
|||
|
||||
free(pHistoBins);
|
||||
return pResHistogram;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -872,5 +872,6 @@ void setDefaultCreateDbOption(SCreateDBInfo *pDBInfo) {
|
|||
pDBInfo->quorum = -1;
|
||||
pDBInfo->keep = NULL;
|
||||
|
||||
pDBInfo->update = -1;
|
||||
memset(&pDBInfo->precision, 0, sizeof(SStrToken));
|
||||
}
|
||||
|
|
|
@ -155,6 +155,7 @@ static SKeyword keywordTable[] = {
|
|||
{"INSERT", TK_INSERT},
|
||||
{"INTO", TK_INTO},
|
||||
{"VALUES", TK_VALUES},
|
||||
{"UPDATE", TK_UPDATE},
|
||||
{"RESET", TK_RESET},
|
||||
{"QUERY", TK_QUERY},
|
||||
{"ADD", TK_ADD},
|
||||
|
@ -664,4 +665,4 @@ void taosCleanupKeywordsTable() {
|
|||
if (m != NULL && atomic_val_compare_exchange_ptr(&keywordHashTable, m, 0) == m) {
|
||||
taosHashCleanup(m);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
#include "tutil.h"
|
||||
|
||||
static int32_t getDataStartOffset();
|
||||
static void TSBufUpdateVnodeInfo(STSBuf* pTSBuf, int32_t index, STSVnodeBlockInfo* pBlockInfo);
|
||||
static void TSBufUpdateGroupInfo(STSBuf* pTSBuf, int32_t index, STSGroupBlockInfo* pBlockInfo);
|
||||
static STSBuf* allocResForTSBuf(STSBuf* pTSBuf);
|
||||
static int32_t STSBufUpdateHeader(STSBuf* pTSBuf, STSBufFileHeader* pHeader);
|
||||
|
||||
|
@ -32,7 +32,7 @@ STSBuf* tsBufCreate(bool autoDelete, int32_t order) {
|
|||
}
|
||||
|
||||
// update the header info
|
||||
STSBufFileHeader header = {.magic = TS_COMP_FILE_MAGIC, .numOfVnode = pTSBuf->numOfVnodes, .tsOrder = TSDB_ORDER_ASC};
|
||||
STSBufFileHeader header = {.magic = TS_COMP_FILE_MAGIC, .numOfGroup = pTSBuf->numOfGroups, .tsOrder = TSDB_ORDER_ASC};
|
||||
STSBufUpdateHeader(pTSBuf, &header);
|
||||
|
||||
tsBufResetPos(pTSBuf);
|
||||
|
@ -75,9 +75,9 @@ STSBuf* tsBufCreateFromFile(const char* path, bool autoDelete) {
|
|||
return NULL;
|
||||
}
|
||||
|
||||
if (header.numOfVnode > pTSBuf->numOfAlloc) {
|
||||
pTSBuf->numOfAlloc = header.numOfVnode;
|
||||
STSVnodeBlockInfoEx* tmp = realloc(pTSBuf->pData, sizeof(STSVnodeBlockInfoEx) * pTSBuf->numOfAlloc);
|
||||
if (header.numOfGroup > pTSBuf->numOfAlloc) {
|
||||
pTSBuf->numOfAlloc = header.numOfGroup;
|
||||
STSGroupBlockInfoEx* tmp = realloc(pTSBuf->pData, sizeof(STSGroupBlockInfoEx) * pTSBuf->numOfAlloc);
|
||||
if (tmp == NULL) {
|
||||
tsBufDestroy(pTSBuf);
|
||||
return NULL;
|
||||
|
@ -86,7 +86,7 @@ STSBuf* tsBufCreateFromFile(const char* path, bool autoDelete) {
|
|||
pTSBuf->pData = tmp;
|
||||
}
|
||||
|
||||
pTSBuf->numOfVnodes = header.numOfVnode;
|
||||
pTSBuf->numOfGroups = header.numOfGroup;
|
||||
|
||||
// check the ts order
|
||||
pTSBuf->tsOrder = header.tsOrder;
|
||||
|
@ -96,9 +96,9 @@ STSBuf* tsBufCreateFromFile(const char* path, bool autoDelete) {
|
|||
return NULL;
|
||||
}
|
||||
|
||||
size_t infoSize = sizeof(STSVnodeBlockInfo) * pTSBuf->numOfVnodes;
|
||||
size_t infoSize = sizeof(STSGroupBlockInfo) * pTSBuf->numOfGroups;
|
||||
|
||||
STSVnodeBlockInfo* buf = (STSVnodeBlockInfo*)calloc(1, infoSize);
|
||||
STSGroupBlockInfo* buf = (STSGroupBlockInfo*)calloc(1, infoSize);
|
||||
if (buf == NULL) {
|
||||
tsBufDestroy(pTSBuf);
|
||||
return NULL;
|
||||
|
@ -109,9 +109,9 @@ STSBuf* tsBufCreateFromFile(const char* path, bool autoDelete) {
|
|||
UNUSED(sz);
|
||||
|
||||
// the length value for each vnode is not kept in file, so does not set the length value
|
||||
for (int32_t i = 0; i < pTSBuf->numOfVnodes; ++i) {
|
||||
STSVnodeBlockInfoEx* pBlockList = &pTSBuf->pData[i];
|
||||
memcpy(&pBlockList->info, &buf[i], sizeof(STSVnodeBlockInfo));
|
||||
for (int32_t i = 0; i < pTSBuf->numOfGroups; ++i) {
|
||||
STSGroupBlockInfoEx* pBlockList = &pTSBuf->pData[i];
|
||||
memcpy(&pBlockList->info, &buf[i], sizeof(STSGroupBlockInfo));
|
||||
}
|
||||
free(buf);
|
||||
|
||||
|
@ -131,8 +131,8 @@ STSBuf* tsBufCreateFromFile(const char* path, bool autoDelete) {
|
|||
pTSBuf->cur.order = TSDB_ORDER_ASC;
|
||||
pTSBuf->autoDelete = autoDelete;
|
||||
|
||||
// tscDebug("create tsBuf from file:%s, fd:%d, size:%d, numOfVnode:%d, autoDelete:%d", pTSBuf->path, fileno(pTSBuf->f),
|
||||
// pTSBuf->fileSize, pTSBuf->numOfVnodes, pTSBuf->autoDelete);
|
||||
// tscDebug("create tsBuf from file:%s, fd:%d, size:%d, numOfGroups:%d, autoDelete:%d", pTSBuf->path, fileno(pTSBuf->f),
|
||||
// pTSBuf->fileSize, pTSBuf->numOfGroups, pTSBuf->autoDelete);
|
||||
|
||||
return pTSBuf;
|
||||
}
|
||||
|
@ -162,53 +162,53 @@ void* tsBufDestroy(STSBuf* pTSBuf) {
|
|||
return NULL;
|
||||
}
|
||||
|
||||
static STSVnodeBlockInfoEx* tsBufGetLastVnodeInfo(STSBuf* pTSBuf) {
|
||||
int32_t last = pTSBuf->numOfVnodes - 1;
|
||||
static STSGroupBlockInfoEx* tsBufGetLastGroupInfo(STSBuf* pTSBuf) {
|
||||
int32_t last = pTSBuf->numOfGroups - 1;
|
||||
|
||||
assert(last >= 0);
|
||||
return &pTSBuf->pData[last];
|
||||
}
|
||||
|
||||
static STSVnodeBlockInfoEx* addOneVnodeInfo(STSBuf* pTSBuf, int32_t vnodeId) {
|
||||
if (pTSBuf->numOfAlloc <= pTSBuf->numOfVnodes) {
|
||||
static STSGroupBlockInfoEx* addOneGroupInfo(STSBuf* pTSBuf, int32_t id) {
|
||||
if (pTSBuf->numOfAlloc <= pTSBuf->numOfGroups) {
|
||||
uint32_t newSize = (uint32_t)(pTSBuf->numOfAlloc * 1.5);
|
||||
assert((int32_t)newSize > pTSBuf->numOfAlloc);
|
||||
|
||||
STSVnodeBlockInfoEx* tmp = (STSVnodeBlockInfoEx*)realloc(pTSBuf->pData, sizeof(STSVnodeBlockInfoEx) * newSize);
|
||||
STSGroupBlockInfoEx* tmp = (STSGroupBlockInfoEx*)realloc(pTSBuf->pData, sizeof(STSGroupBlockInfoEx) * newSize);
|
||||
if (tmp == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
pTSBuf->pData = tmp;
|
||||
pTSBuf->numOfAlloc = newSize;
|
||||
memset(&pTSBuf->pData[pTSBuf->numOfVnodes], 0, sizeof(STSVnodeBlockInfoEx) * (newSize - pTSBuf->numOfVnodes));
|
||||
memset(&pTSBuf->pData[pTSBuf->numOfGroups], 0, sizeof(STSGroupBlockInfoEx) * (newSize - pTSBuf->numOfGroups));
|
||||
}
|
||||
|
||||
if (pTSBuf->numOfVnodes > 0) {
|
||||
STSVnodeBlockInfoEx* pPrevBlockInfoEx = tsBufGetLastVnodeInfo(pTSBuf);
|
||||
if (pTSBuf->numOfGroups > 0) {
|
||||
STSGroupBlockInfoEx* pPrevBlockInfoEx = tsBufGetLastGroupInfo(pTSBuf);
|
||||
|
||||
// update prev vnode length info in file
|
||||
TSBufUpdateVnodeInfo(pTSBuf, pTSBuf->numOfVnodes - 1, &pPrevBlockInfoEx->info);
|
||||
TSBufUpdateGroupInfo(pTSBuf, pTSBuf->numOfGroups - 1, &pPrevBlockInfoEx->info);
|
||||
}
|
||||
|
||||
// set initial value for vnode block
|
||||
STSVnodeBlockInfo* pBlockInfo = &pTSBuf->pData[pTSBuf->numOfVnodes].info;
|
||||
pBlockInfo->vnode = vnodeId;
|
||||
STSGroupBlockInfo* pBlockInfo = &pTSBuf->pData[pTSBuf->numOfGroups].info;
|
||||
pBlockInfo->id = id;
|
||||
pBlockInfo->offset = pTSBuf->fileSize;
|
||||
assert(pBlockInfo->offset >= getDataStartOffset());
|
||||
|
||||
// update vnode info in file
|
||||
TSBufUpdateVnodeInfo(pTSBuf, pTSBuf->numOfVnodes, pBlockInfo);
|
||||
TSBufUpdateGroupInfo(pTSBuf, pTSBuf->numOfGroups, pBlockInfo);
|
||||
|
||||
// add one vnode info
|
||||
pTSBuf->numOfVnodes += 1;
|
||||
pTSBuf->numOfGroups += 1;
|
||||
|
||||
// update the header info
|
||||
STSBufFileHeader header = {
|
||||
.magic = TS_COMP_FILE_MAGIC, .numOfVnode = pTSBuf->numOfVnodes, .tsOrder = pTSBuf->tsOrder};
|
||||
.magic = TS_COMP_FILE_MAGIC, .numOfGroup = pTSBuf->numOfGroups, .tsOrder = pTSBuf->tsOrder};
|
||||
|
||||
STSBufUpdateHeader(pTSBuf, &header);
|
||||
return tsBufGetLastVnodeInfo(pTSBuf);
|
||||
return tsBufGetLastGroupInfo(pTSBuf);
|
||||
}
|
||||
|
||||
static void shrinkBuffer(STSList* ptsData) {
|
||||
|
@ -279,10 +279,10 @@ static void writeDataToDisk(STSBuf* pTSBuf) {
|
|||
|
||||
pTSBuf->tsData.len = 0;
|
||||
|
||||
STSVnodeBlockInfoEx* pVnodeBlockInfoEx = tsBufGetLastVnodeInfo(pTSBuf);
|
||||
STSGroupBlockInfoEx* pGroupBlockInfoEx = tsBufGetLastGroupInfo(pTSBuf);
|
||||
|
||||
pVnodeBlockInfoEx->info.compLen += blockSize;
|
||||
pVnodeBlockInfoEx->info.numOfBlocks += 1;
|
||||
pGroupBlockInfoEx->info.compLen += blockSize;
|
||||
pGroupBlockInfoEx->info.numOfBlocks += 1;
|
||||
|
||||
shrinkBuffer(&pTSBuf->tsData);
|
||||
}
|
||||
|
@ -413,20 +413,20 @@ static int32_t setCheckTSOrder(STSBuf* pTSBuf, const char* pData, int32_t len) {
|
|||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
void tsBufAppend(STSBuf* pTSBuf, int32_t vnodeId, tVariant* tag, const char* pData, int32_t len) {
|
||||
STSVnodeBlockInfoEx* pBlockInfo = NULL;
|
||||
void tsBufAppend(STSBuf* pTSBuf, int32_t id, tVariant* tag, const char* pData, int32_t len) {
|
||||
STSGroupBlockInfoEx* pBlockInfo = NULL;
|
||||
STSList* ptsData = &pTSBuf->tsData;
|
||||
|
||||
if (pTSBuf->numOfVnodes == 0 || tsBufGetLastVnodeInfo(pTSBuf)->info.vnode != vnodeId) {
|
||||
if (pTSBuf->numOfGroups == 0 || tsBufGetLastGroupInfo(pTSBuf)->info.id != id) {
|
||||
writeDataToDisk(pTSBuf);
|
||||
shrinkBuffer(ptsData);
|
||||
|
||||
pBlockInfo = addOneVnodeInfo(pTSBuf, vnodeId);
|
||||
pBlockInfo = addOneGroupInfo(pTSBuf, id);
|
||||
} else {
|
||||
pBlockInfo = tsBufGetLastVnodeInfo(pTSBuf);
|
||||
pBlockInfo = tsBufGetLastGroupInfo(pTSBuf);
|
||||
}
|
||||
|
||||
assert(pBlockInfo->info.vnode == vnodeId);
|
||||
assert(pBlockInfo->info.id == id);
|
||||
|
||||
if ((tVariantCompare(&pTSBuf->block.tag, tag) != 0) && ptsData->len > 0) {
|
||||
// new arrived data with different tags value, save current value into disk first
|
||||
|
@ -464,23 +464,23 @@ void tsBufFlush(STSBuf* pTSBuf) {
|
|||
writeDataToDisk(pTSBuf);
|
||||
shrinkBuffer(&pTSBuf->tsData);
|
||||
|
||||
STSVnodeBlockInfoEx* pBlockInfoEx = tsBufGetLastVnodeInfo(pTSBuf);
|
||||
STSGroupBlockInfoEx* pBlockInfoEx = tsBufGetLastGroupInfo(pTSBuf);
|
||||
|
||||
// update prev vnode length info in file
|
||||
TSBufUpdateVnodeInfo(pTSBuf, pTSBuf->numOfVnodes - 1, &pBlockInfoEx->info);
|
||||
TSBufUpdateGroupInfo(pTSBuf, pTSBuf->numOfGroups - 1, &pBlockInfoEx->info);
|
||||
|
||||
// save the ts order into header
|
||||
STSBufFileHeader header = {
|
||||
.magic = TS_COMP_FILE_MAGIC, .numOfVnode = pTSBuf->numOfVnodes, .tsOrder = pTSBuf->tsOrder};
|
||||
.magic = TS_COMP_FILE_MAGIC, .numOfGroup = pTSBuf->numOfGroups, .tsOrder = pTSBuf->tsOrder};
|
||||
STSBufUpdateHeader(pTSBuf, &header);
|
||||
|
||||
fsync(fileno(pTSBuf->f));
|
||||
}
|
||||
|
||||
static int32_t tsBufFindVnodeById(STSVnodeBlockInfoEx* pVnodeInfoEx, int32_t numOfVnodes, int32_t vnodeId) {
|
||||
static int32_t tsBufFindGroupById(STSGroupBlockInfoEx* pGroupInfoEx, int32_t numOfGroups, int32_t id) {
|
||||
int32_t j = -1;
|
||||
for (int32_t i = 0; i < numOfVnodes; ++i) {
|
||||
if (pVnodeInfoEx[i].info.vnode == vnodeId) {
|
||||
for (int32_t i = 0; i < numOfGroups; ++i) {
|
||||
if (pGroupInfoEx[i].info.id == id) {
|
||||
j = i;
|
||||
break;
|
||||
}
|
||||
|
@ -490,7 +490,7 @@ static int32_t tsBufFindVnodeById(STSVnodeBlockInfoEx* pVnodeInfoEx, int32_t num
|
|||
}
|
||||
|
||||
// todo opt performance by cache blocks info
|
||||
static int32_t tsBufFindBlock(STSBuf* pTSBuf, STSVnodeBlockInfo* pBlockInfo, int32_t blockIndex) {
|
||||
static int32_t tsBufFindBlock(STSBuf* pTSBuf, STSGroupBlockInfo* pBlockInfo, int32_t blockIndex) {
|
||||
if (fseek(pTSBuf->f, pBlockInfo->offset, SEEK_SET) != 0) {
|
||||
return -1;
|
||||
}
|
||||
|
@ -517,7 +517,7 @@ static int32_t tsBufFindBlock(STSBuf* pTSBuf, STSVnodeBlockInfo* pBlockInfo, int
|
|||
return 0;
|
||||
}
|
||||
|
||||
static int32_t tsBufFindBlockByTag(STSBuf* pTSBuf, STSVnodeBlockInfo* pBlockInfo, tVariant* tag) {
|
||||
static int32_t tsBufFindBlockByTag(STSBuf* pTSBuf, STSGroupBlockInfo* pBlockInfo, tVariant* tag) {
|
||||
bool decomp = false;
|
||||
|
||||
int64_t offset = 0;
|
||||
|
@ -544,14 +544,14 @@ static int32_t tsBufFindBlockByTag(STSBuf* pTSBuf, STSVnodeBlockInfo* pBlockInfo
|
|||
return -1;
|
||||
}
|
||||
|
||||
static void tsBufGetBlock(STSBuf* pTSBuf, int32_t vnodeIndex, int32_t blockIndex) {
|
||||
STSVnodeBlockInfo* pBlockInfo = &pTSBuf->pData[vnodeIndex].info;
|
||||
static void tsBufGetBlock(STSBuf* pTSBuf, int32_t groupIndex, int32_t blockIndex) {
|
||||
STSGroupBlockInfo* pBlockInfo = &pTSBuf->pData[groupIndex].info;
|
||||
if (pBlockInfo->numOfBlocks <= blockIndex) {
|
||||
assert(false);
|
||||
}
|
||||
|
||||
STSCursor* pCur = &pTSBuf->cur;
|
||||
if (pCur->vgroupIndex == vnodeIndex && ((pCur->blockIndex <= blockIndex && pCur->order == TSDB_ORDER_ASC) ||
|
||||
if (pCur->vgroupIndex == groupIndex && ((pCur->blockIndex <= blockIndex && pCur->order == TSDB_ORDER_ASC) ||
|
||||
(pCur->blockIndex >= blockIndex && pCur->order == TSDB_ORDER_DESC))) {
|
||||
int32_t i = 0;
|
||||
bool decomp = false;
|
||||
|
@ -586,13 +586,13 @@ static void tsBufGetBlock(STSBuf* pTSBuf, int32_t vnodeIndex, int32_t blockIndex
|
|||
|
||||
assert((pTSBuf->tsData.len / TSDB_KEYSIZE == pBlock->numOfElem) && (pTSBuf->tsData.allocSize >= pTSBuf->tsData.len));
|
||||
|
||||
pCur->vgroupIndex = vnodeIndex;
|
||||
pCur->vgroupIndex = groupIndex;
|
||||
pCur->blockIndex = blockIndex;
|
||||
|
||||
pCur->tsIndex = (pCur->order == TSDB_ORDER_ASC) ? 0 : pBlock->numOfElem - 1;
|
||||
}
|
||||
|
||||
static int32_t doUpdateVnodeInfo(STSBuf* pTSBuf, int64_t offset, STSVnodeBlockInfo* pVInfo) {
|
||||
static int32_t doUpdateGroupInfo(STSBuf* pTSBuf, int64_t offset, STSGroupBlockInfo* pVInfo) {
|
||||
if (offset < 0 || offset >= getDataStartOffset()) {
|
||||
return -1;
|
||||
}
|
||||
|
@ -601,12 +601,12 @@ static int32_t doUpdateVnodeInfo(STSBuf* pTSBuf, int64_t offset, STSVnodeBlockIn
|
|||
return -1;
|
||||
}
|
||||
|
||||
fwrite(pVInfo, sizeof(STSVnodeBlockInfo), 1, pTSBuf->f);
|
||||
fwrite(pVInfo, sizeof(STSGroupBlockInfo), 1, pTSBuf->f);
|
||||
return 0;
|
||||
}
|
||||
|
||||
STSVnodeBlockInfo* tsBufGetVnodeBlockInfo(STSBuf* pTSBuf, int32_t vnodeId) {
|
||||
int32_t j = tsBufFindVnodeById(pTSBuf->pData, pTSBuf->numOfVnodes, vnodeId);
|
||||
STSGroupBlockInfo* tsBufGetGroupBlockInfo(STSBuf* pTSBuf, int32_t id) {
|
||||
int32_t j = tsBufFindGroupById(pTSBuf->pData, pTSBuf->numOfGroups, id);
|
||||
if (j == -1) {
|
||||
return NULL;
|
||||
}
|
||||
|
@ -615,7 +615,7 @@ STSVnodeBlockInfo* tsBufGetVnodeBlockInfo(STSBuf* pTSBuf, int32_t vnodeId) {
|
|||
}
|
||||
|
||||
int32_t STSBufUpdateHeader(STSBuf* pTSBuf, STSBufFileHeader* pHeader) {
|
||||
if ((pTSBuf->f == NULL) || pHeader == NULL || pHeader->numOfVnode == 0 || pHeader->magic != TS_COMP_FILE_MAGIC) {
|
||||
if ((pTSBuf->f == NULL) || pHeader == NULL || pHeader->numOfGroup == 0 || pHeader->magic != TS_COMP_FILE_MAGIC) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
@ -631,7 +631,7 @@ int32_t STSBufUpdateHeader(STSBuf* pTSBuf, STSBufFileHeader* pHeader) {
|
|||
}
|
||||
|
||||
bool tsBufNextPos(STSBuf* pTSBuf) {
|
||||
if (pTSBuf == NULL || pTSBuf->numOfVnodes == 0) {
|
||||
if (pTSBuf == NULL || pTSBuf->numOfGroups == 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -650,16 +650,16 @@ bool tsBufNextPos(STSBuf* pTSBuf) {
|
|||
}
|
||||
|
||||
} else { // get the last timestamp record in the last block of the last vnode
|
||||
assert(pTSBuf->numOfVnodes > 0);
|
||||
assert(pTSBuf->numOfGroups > 0);
|
||||
|
||||
int32_t vnodeIndex = pTSBuf->numOfVnodes - 1;
|
||||
pCur->vgroupIndex = vnodeIndex;
|
||||
int32_t groupIndex = pTSBuf->numOfGroups - 1;
|
||||
pCur->vgroupIndex = groupIndex;
|
||||
|
||||
int32_t vnodeId = pTSBuf->pData[pCur->vgroupIndex].info.vnode;
|
||||
STSVnodeBlockInfo* pBlockInfo = tsBufGetVnodeBlockInfo(pTSBuf, vnodeId);
|
||||
int32_t id = pTSBuf->pData[pCur->vgroupIndex].info.id;
|
||||
STSGroupBlockInfo* pBlockInfo = tsBufGetGroupBlockInfo(pTSBuf, id);
|
||||
int32_t blockIndex = pBlockInfo->numOfBlocks - 1;
|
||||
|
||||
tsBufGetBlock(pTSBuf, vnodeIndex, blockIndex);
|
||||
tsBufGetBlock(pTSBuf, groupIndex, blockIndex);
|
||||
|
||||
pCur->tsIndex = pTSBuf->block.numOfElem - 1;
|
||||
if (pTSBuf->block.numOfElem == 0) {
|
||||
|
@ -678,12 +678,12 @@ bool tsBufNextPos(STSBuf* pTSBuf) {
|
|||
|
||||
if ((pCur->order == TSDB_ORDER_ASC && pCur->tsIndex >= pTSBuf->block.numOfElem - 1) ||
|
||||
(pCur->order == TSDB_ORDER_DESC && pCur->tsIndex <= 0)) {
|
||||
int32_t vnodeId = pTSBuf->pData[pCur->vgroupIndex].info.vnode;
|
||||
int32_t id = pTSBuf->pData[pCur->vgroupIndex].info.id;
|
||||
|
||||
STSVnodeBlockInfo* pBlockInfo = tsBufGetVnodeBlockInfo(pTSBuf, vnodeId);
|
||||
STSGroupBlockInfo* pBlockInfo = tsBufGetGroupBlockInfo(pTSBuf, id);
|
||||
if (pBlockInfo == NULL || (pCur->blockIndex >= pBlockInfo->numOfBlocks - 1 && pCur->order == TSDB_ORDER_ASC) ||
|
||||
(pCur->blockIndex <= 0 && pCur->order == TSDB_ORDER_DESC)) {
|
||||
if ((pCur->vgroupIndex >= pTSBuf->numOfVnodes - 1 && pCur->order == TSDB_ORDER_ASC) ||
|
||||
if ((pCur->vgroupIndex >= pTSBuf->numOfGroups - 1 && pCur->order == TSDB_ORDER_ASC) ||
|
||||
(pCur->vgroupIndex <= 0 && pCur->order == TSDB_ORDER_DESC)) {
|
||||
pCur->vgroupIndex = -1;
|
||||
return false;
|
||||
|
@ -719,7 +719,7 @@ void tsBufResetPos(STSBuf* pTSBuf) {
|
|||
}
|
||||
|
||||
STSElem tsBufGetElem(STSBuf* pTSBuf) {
|
||||
STSElem elem1 = {.vnode = -1};
|
||||
STSElem elem1 = {.id = -1};
|
||||
if (pTSBuf == NULL) {
|
||||
return elem1;
|
||||
}
|
||||
|
@ -731,7 +731,7 @@ STSElem tsBufGetElem(STSBuf* pTSBuf) {
|
|||
|
||||
STSBlock* pBlock = &pTSBuf->block;
|
||||
|
||||
elem1.vnode = pTSBuf->pData[pCur->vgroupIndex].info.vnode;
|
||||
elem1.id = pTSBuf->pData[pCur->vgroupIndex].info.id;
|
||||
elem1.ts = *(TSKEY*)(pTSBuf->tsData.rawBuf + pCur->tsIndex * TSDB_KEYSIZE);
|
||||
elem1.tag = &pBlock->tag;
|
||||
|
||||
|
@ -742,34 +742,34 @@ STSElem tsBufGetElem(STSBuf* pTSBuf) {
|
|||
* current only support ts comp data from two vnode merge
|
||||
* @param pDestBuf
|
||||
* @param pSrcBuf
|
||||
* @param vnodeId
|
||||
* @param id
|
||||
* @return
|
||||
*/
|
||||
int32_t tsBufMerge(STSBuf* pDestBuf, const STSBuf* pSrcBuf) {
|
||||
if (pDestBuf == NULL || pSrcBuf == NULL || pSrcBuf->numOfVnodes <= 0) {
|
||||
if (pDestBuf == NULL || pSrcBuf == NULL || pSrcBuf->numOfGroups <= 0) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (pDestBuf->numOfVnodes + pSrcBuf->numOfVnodes > TS_COMP_FILE_VNODE_MAX) {
|
||||
if (pDestBuf->numOfGroups + pSrcBuf->numOfGroups > TS_COMP_FILE_GROUP_MAX) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
// src can only have one vnode index
|
||||
assert(pSrcBuf->numOfVnodes == 1);
|
||||
assert(pSrcBuf->numOfGroups == 1);
|
||||
|
||||
// there are data in buffer, flush to disk first
|
||||
tsBufFlush(pDestBuf);
|
||||
|
||||
// compared with the last vnode id
|
||||
int32_t vnodeId = tsBufGetLastVnodeInfo((STSBuf*) pSrcBuf)->info.vnode;
|
||||
if (vnodeId != tsBufGetLastVnodeInfo(pDestBuf)->info.vnode) {
|
||||
int32_t oldSize = pDestBuf->numOfVnodes;
|
||||
int32_t newSize = oldSize + pSrcBuf->numOfVnodes;
|
||||
int32_t id = tsBufGetLastGroupInfo((STSBuf*) pSrcBuf)->info.id;
|
||||
if (id != tsBufGetLastGroupInfo(pDestBuf)->info.id) {
|
||||
int32_t oldSize = pDestBuf->numOfGroups;
|
||||
int32_t newSize = oldSize + pSrcBuf->numOfGroups;
|
||||
|
||||
if (pDestBuf->numOfAlloc < newSize) {
|
||||
pDestBuf->numOfAlloc = newSize;
|
||||
|
||||
STSVnodeBlockInfoEx* tmp = realloc(pDestBuf->pData, sizeof(STSVnodeBlockInfoEx) * newSize);
|
||||
STSGroupBlockInfoEx* tmp = realloc(pDestBuf->pData, sizeof(STSGroupBlockInfoEx) * newSize);
|
||||
if (tmp == NULL) {
|
||||
return -1;
|
||||
}
|
||||
|
@ -778,23 +778,23 @@ int32_t tsBufMerge(STSBuf* pDestBuf, const STSBuf* pSrcBuf) {
|
|||
}
|
||||
|
||||
// directly copy the vnode index information
|
||||
memcpy(&pDestBuf->pData[oldSize], pSrcBuf->pData, (size_t)pSrcBuf->numOfVnodes * sizeof(STSVnodeBlockInfoEx));
|
||||
memcpy(&pDestBuf->pData[oldSize], pSrcBuf->pData, (size_t)pSrcBuf->numOfGroups * sizeof(STSGroupBlockInfoEx));
|
||||
|
||||
// set the new offset value
|
||||
for (int32_t i = 0; i < pSrcBuf->numOfVnodes; ++i) {
|
||||
STSVnodeBlockInfoEx* pBlockInfoEx = &pDestBuf->pData[i + oldSize];
|
||||
for (int32_t i = 0; i < pSrcBuf->numOfGroups; ++i) {
|
||||
STSGroupBlockInfoEx* pBlockInfoEx = &pDestBuf->pData[i + oldSize];
|
||||
pBlockInfoEx->info.offset = (pSrcBuf->pData[i].info.offset - getDataStartOffset()) + pDestBuf->fileSize;
|
||||
pBlockInfoEx->info.vnode = vnodeId;
|
||||
pBlockInfoEx->info.id = id;
|
||||
}
|
||||
|
||||
pDestBuf->numOfVnodes = newSize;
|
||||
pDestBuf->numOfGroups = newSize;
|
||||
} else {
|
||||
STSVnodeBlockInfoEx* pBlockInfoEx = tsBufGetLastVnodeInfo(pDestBuf);
|
||||
STSGroupBlockInfoEx* pBlockInfoEx = tsBufGetLastGroupInfo(pDestBuf);
|
||||
|
||||
pBlockInfoEx->len += pSrcBuf->pData[0].len;
|
||||
pBlockInfoEx->info.numOfBlocks += pSrcBuf->pData[0].info.numOfBlocks;
|
||||
pBlockInfoEx->info.compLen += pSrcBuf->pData[0].info.compLen;
|
||||
pBlockInfoEx->info.vnode = vnodeId;
|
||||
pBlockInfoEx->info.id = id;
|
||||
}
|
||||
|
||||
int32_t r = fseek(pDestBuf->f, 0, SEEK_END);
|
||||
|
@ -827,23 +827,23 @@ int32_t tsBufMerge(STSBuf* pDestBuf, const STSBuf* pSrcBuf) {
|
|||
|
||||
assert(pDestBuf->fileSize == oldSize + size);
|
||||
|
||||
// tscDebug("tsBuf merge success, %p, path:%s, fd:%d, file size:%d, numOfVnode:%d, autoDelete:%d", pDestBuf,
|
||||
// pDestBuf->path, fileno(pDestBuf->f), pDestBuf->fileSize, pDestBuf->numOfVnodes, pDestBuf->autoDelete);
|
||||
// tscDebug("tsBuf merge success, %p, path:%s, fd:%d, file size:%d, numOfGroups:%d, autoDelete:%d", pDestBuf,
|
||||
// pDestBuf->path, fileno(pDestBuf->f), pDestBuf->fileSize, pDestBuf->numOfGroups, pDestBuf->autoDelete);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
STSBuf* tsBufCreateFromCompBlocks(const char* pData, int32_t numOfBlocks, int32_t len, int32_t order, int32_t vnodeId) {
|
||||
STSBuf* tsBufCreateFromCompBlocks(const char* pData, int32_t numOfBlocks, int32_t len, int32_t order, int32_t id) {
|
||||
STSBuf* pTSBuf = tsBufCreate(true, order);
|
||||
|
||||
STSVnodeBlockInfo* pBlockInfo = &(addOneVnodeInfo(pTSBuf, 0)->info);
|
||||
STSGroupBlockInfo* pBlockInfo = &(addOneGroupInfo(pTSBuf, 0)->info);
|
||||
pBlockInfo->numOfBlocks = numOfBlocks;
|
||||
pBlockInfo->compLen = len;
|
||||
pBlockInfo->offset = getDataStartOffset();
|
||||
pBlockInfo->vnode = vnodeId;
|
||||
pBlockInfo->id = id;
|
||||
|
||||
// update prev vnode length info in file
|
||||
TSBufUpdateVnodeInfo(pTSBuf, pTSBuf->numOfVnodes - 1, pBlockInfo);
|
||||
TSBufUpdateGroupInfo(pTSBuf, pTSBuf->numOfGroups - 1, pBlockInfo);
|
||||
|
||||
int32_t ret = fseek(pTSBuf->f, pBlockInfo->offset, SEEK_SET);
|
||||
UNUSED(ret);
|
||||
|
@ -855,7 +855,7 @@ STSBuf* tsBufCreateFromCompBlocks(const char* pData, int32_t numOfBlocks, int32_
|
|||
assert(order == TSDB_ORDER_ASC || order == TSDB_ORDER_DESC);
|
||||
|
||||
STSBufFileHeader header = {
|
||||
.magic = TS_COMP_FILE_MAGIC, .numOfVnode = pTSBuf->numOfVnodes, .tsOrder = pTSBuf->tsOrder};
|
||||
.magic = TS_COMP_FILE_MAGIC, .numOfGroup = pTSBuf->numOfGroups, .tsOrder = pTSBuf->tsOrder};
|
||||
STSBufUpdateHeader(pTSBuf, &header);
|
||||
|
||||
fsync(fileno(pTSBuf->f));
|
||||
|
@ -863,14 +863,14 @@ STSBuf* tsBufCreateFromCompBlocks(const char* pData, int32_t numOfBlocks, int32_
|
|||
return pTSBuf;
|
||||
}
|
||||
|
||||
STSElem tsBufGetElemStartPos(STSBuf* pTSBuf, int32_t vnodeId, tVariant* tag) {
|
||||
STSElem elem = {.vnode = -1};
|
||||
STSElem tsBufGetElemStartPos(STSBuf* pTSBuf, int32_t id, tVariant* tag) {
|
||||
STSElem elem = {.id = -1};
|
||||
|
||||
if (pTSBuf == NULL) {
|
||||
return elem;
|
||||
}
|
||||
|
||||
int32_t j = tsBufFindVnodeById(pTSBuf->pData, pTSBuf->numOfVnodes, vnodeId);
|
||||
int32_t j = tsBufFindGroupById(pTSBuf->pData, pTSBuf->numOfGroups, id);
|
||||
if (j == -1) {
|
||||
return elem;
|
||||
}
|
||||
|
@ -879,7 +879,7 @@ STSElem tsBufGetElemStartPos(STSBuf* pTSBuf, int32_t vnodeId, tVariant* tag) {
|
|||
// tsBufDisplay(pTSBuf);
|
||||
|
||||
STSCursor* pCur = &pTSBuf->cur;
|
||||
STSVnodeBlockInfo* pBlockInfo = &pTSBuf->pData[j].info;
|
||||
STSGroupBlockInfo* pBlockInfo = &pTSBuf->pData[j].info;
|
||||
|
||||
int32_t blockIndex = tsBufFindBlockByTag(pTSBuf, pBlockInfo, tag);
|
||||
if (blockIndex < 0) {
|
||||
|
@ -935,7 +935,7 @@ STSBuf* tsBufClone(STSBuf* pTSBuf) {
|
|||
|
||||
void tsBufDisplay(STSBuf* pTSBuf) {
|
||||
printf("-------start of ts comp file-------\n");
|
||||
printf("number of vnode:%d\n", pTSBuf->numOfVnodes);
|
||||
printf("number of vnode:%d\n", pTSBuf->numOfGroups);
|
||||
|
||||
int32_t old = pTSBuf->cur.order;
|
||||
pTSBuf->cur.order = TSDB_ORDER_ASC;
|
||||
|
@ -945,7 +945,7 @@ void tsBufDisplay(STSBuf* pTSBuf) {
|
|||
while (tsBufNextPos(pTSBuf)) {
|
||||
STSElem elem = tsBufGetElem(pTSBuf);
|
||||
if (elem.tag->nType == TSDB_DATA_TYPE_BIGINT) {
|
||||
printf("%d-%" PRId64 "-%" PRId64 "\n", elem.vnode, elem.tag->i64Key, elem.ts);
|
||||
printf("%d-%" PRId64 "-%" PRId64 "\n", elem.id, elem.tag->i64Key, elem.ts);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -954,20 +954,20 @@ void tsBufDisplay(STSBuf* pTSBuf) {
|
|||
}
|
||||
|
||||
static int32_t getDataStartOffset() {
|
||||
return sizeof(STSBufFileHeader) + TS_COMP_FILE_VNODE_MAX * sizeof(STSVnodeBlockInfo);
|
||||
return sizeof(STSBufFileHeader) + TS_COMP_FILE_GROUP_MAX * sizeof(STSGroupBlockInfo);
|
||||
}
|
||||
|
||||
// update prev vnode length info in file
|
||||
static void TSBufUpdateVnodeInfo(STSBuf* pTSBuf, int32_t index, STSVnodeBlockInfo* pBlockInfo) {
|
||||
int32_t offset = sizeof(STSBufFileHeader) + index * sizeof(STSVnodeBlockInfo);
|
||||
doUpdateVnodeInfo(pTSBuf, offset, pBlockInfo);
|
||||
static void TSBufUpdateGroupInfo(STSBuf* pTSBuf, int32_t index, STSGroupBlockInfo* pBlockInfo) {
|
||||
int32_t offset = sizeof(STSBufFileHeader) + index * sizeof(STSGroupBlockInfo);
|
||||
doUpdateGroupInfo(pTSBuf, offset, pBlockInfo);
|
||||
}
|
||||
|
||||
static STSBuf* allocResForTSBuf(STSBuf* pTSBuf) {
|
||||
const int32_t INITIAL_VNODEINFO_SIZE = 4;
|
||||
const int32_t INITIAL_GROUPINFO_SIZE = 4;
|
||||
|
||||
pTSBuf->numOfAlloc = INITIAL_VNODEINFO_SIZE;
|
||||
pTSBuf->pData = calloc(pTSBuf->numOfAlloc, sizeof(STSVnodeBlockInfoEx));
|
||||
pTSBuf->numOfAlloc = INITIAL_GROUPINFO_SIZE;
|
||||
pTSBuf->pData = calloc(pTSBuf->numOfAlloc, sizeof(STSGroupBlockInfoEx));
|
||||
if (pTSBuf->pData == NULL) {
|
||||
tsBufDestroy(pTSBuf);
|
||||
return NULL;
|
||||
|
@ -999,35 +999,35 @@ static STSBuf* allocResForTSBuf(STSBuf* pTSBuf) {
|
|||
return pTSBuf;
|
||||
}
|
||||
|
||||
int32_t tsBufGetNumOfVnodes(STSBuf* pTSBuf) {
|
||||
int32_t tsBufGetNumOfGroup(STSBuf* pTSBuf) {
|
||||
if (pTSBuf == NULL) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
return pTSBuf->numOfVnodes;
|
||||
return pTSBuf->numOfGroups;
|
||||
}
|
||||
|
||||
void tsBufGetVnodeIdList(STSBuf* pTSBuf, int32_t* num, int32_t** vnodeId) {
|
||||
int32_t size = tsBufGetNumOfVnodes(pTSBuf);
|
||||
void tsBufGetGroupIdList(STSBuf* pTSBuf, int32_t* num, int32_t** id) {
|
||||
int32_t size = tsBufGetNumOfGroup(pTSBuf);
|
||||
if (num != NULL) {
|
||||
*num = size;
|
||||
}
|
||||
|
||||
*vnodeId = NULL;
|
||||
*id = NULL;
|
||||
if (size == 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
(*vnodeId) = malloc(tsBufGetNumOfVnodes(pTSBuf) * sizeof(int32_t));
|
||||
(*id) = malloc(tsBufGetNumOfGroup(pTSBuf) * sizeof(int32_t));
|
||||
|
||||
for(int32_t i = 0; i < size; ++i) {
|
||||
(*vnodeId)[i] = pTSBuf->pData[i].info.vnode;
|
||||
(*id)[i] = pTSBuf->pData[i].info.id;
|
||||
}
|
||||
}
|
||||
|
||||
int32_t dumpFileBlockByVnodeId(STSBuf* pTSBuf, int32_t vnodeIndex, void* buf, int32_t* len, int32_t* numOfBlocks) {
|
||||
assert(vnodeIndex >= 0 && vnodeIndex < pTSBuf->numOfVnodes);
|
||||
STSVnodeBlockInfo *pBlockInfo = &pTSBuf->pData[vnodeIndex].info;
|
||||
int32_t dumpFileBlockByGroupId(STSBuf* pTSBuf, int32_t groupIndex, void* buf, int32_t* len, int32_t* numOfBlocks) {
|
||||
assert(groupIndex >= 0 && groupIndex < pTSBuf->numOfGroups);
|
||||
STSGroupBlockInfo *pBlockInfo = &pTSBuf->pData[groupIndex].info;
|
||||
|
||||
*len = 0;
|
||||
*numOfBlocks = 0;
|
||||
|
@ -1052,11 +1052,11 @@ int32_t dumpFileBlockByVnodeId(STSBuf* pTSBuf, int32_t vnodeIndex, void* buf, in
|
|||
}
|
||||
|
||||
STSElem tsBufFindElemStartPosByTag(STSBuf* pTSBuf, tVariant* pTag) {
|
||||
STSElem el = {.vnode = -1};
|
||||
STSElem el = {.id = -1};
|
||||
|
||||
for (int32_t i = 0; i < pTSBuf->numOfVnodes; ++i) {
|
||||
el = tsBufGetElemStartPos(pTSBuf, pTSBuf->pData[i].info.vnode, pTag);
|
||||
if (el.vnode == pTSBuf->pData[i].info.vnode) {
|
||||
for (int32_t i = 0; i < pTSBuf->numOfGroups; ++i) {
|
||||
el = tsBufGetElemStartPos(pTSBuf, pTSBuf->pData[i].info.id, pTag);
|
||||
if (el.id == pTSBuf->pData[i].info.id) {
|
||||
return el;
|
||||
}
|
||||
}
|
||||
|
@ -1065,5 +1065,5 @@ STSElem tsBufFindElemStartPosByTag(STSBuf* pTSBuf, tVariant* pTag) {
|
|||
}
|
||||
|
||||
bool tsBufIsValidElem(STSElem* pElem) {
|
||||
return pElem->vnode >= 0;
|
||||
return pElem->id >= 0;
|
||||
}
|
||||
|
|
2330
src/query/src/sql.c
2330
src/query/src/sql.c
File diff suppressed because it is too large
Load Diff
|
@ -42,7 +42,7 @@ void simpleTest() {
|
|||
|
||||
EXPECT_EQ(pTSBuf->tsData.len, sizeof(int64_t) * num);
|
||||
EXPECT_EQ(tVariantCompare(&pTSBuf->block.tag, &t), 0);
|
||||
EXPECT_EQ(pTSBuf->numOfVnodes, 1);
|
||||
EXPECT_EQ(pTSBuf->numOfGroups, 1);
|
||||
|
||||
tsBufFlush(pTSBuf);
|
||||
EXPECT_EQ(pTSBuf->tsData.len, 0);
|
||||
|
@ -69,7 +69,7 @@ void largeTSTest() {
|
|||
// the data has been flush to disk, no data in cache
|
||||
EXPECT_EQ(pTSBuf->tsData.len, 0);
|
||||
EXPECT_EQ(tVariantCompare(&pTSBuf->block.tag, &t), 0);
|
||||
EXPECT_EQ(pTSBuf->numOfVnodes, 1);
|
||||
EXPECT_EQ(pTSBuf->numOfGroups, 1);
|
||||
EXPECT_EQ(pTSBuf->tsOrder, TSDB_ORDER_ASC);
|
||||
|
||||
tsBufFlush(pTSBuf);
|
||||
|
@ -105,7 +105,7 @@ void multiTagsTest() {
|
|||
EXPECT_EQ(pTSBuf->tsData.len, num * sizeof(int64_t));
|
||||
|
||||
EXPECT_EQ(pTSBuf->block.tag.i64Key, numOfTags - 1);
|
||||
EXPECT_EQ(pTSBuf->numOfVnodes, 1);
|
||||
EXPECT_EQ(pTSBuf->numOfGroups, 1);
|
||||
|
||||
tsBufFlush(pTSBuf);
|
||||
EXPECT_EQ(pTSBuf->tsData.len, 0);
|
||||
|
@ -139,7 +139,7 @@ void multiVnodeTagsTest() {
|
|||
start += step * num;
|
||||
}
|
||||
|
||||
EXPECT_EQ(pTSBuf->numOfVnodes, j + 1);
|
||||
EXPECT_EQ(pTSBuf->numOfGroups, j + 1);
|
||||
}
|
||||
|
||||
EXPECT_EQ(pTSBuf->tsOrder, TSDB_ORDER_ASC);
|
||||
|
@ -184,7 +184,7 @@ void loadDataTest() {
|
|||
start += step * num;
|
||||
}
|
||||
|
||||
EXPECT_EQ(pTSBuf->numOfVnodes, j + 1);
|
||||
EXPECT_EQ(pTSBuf->numOfGroups, j + 1);
|
||||
}
|
||||
|
||||
EXPECT_EQ(pTSBuf->tsOrder, TSDB_ORDER_ASC);
|
||||
|
@ -203,7 +203,7 @@ void loadDataTest() {
|
|||
// create from exists file
|
||||
STSBuf* pNewBuf = tsBufCreateFromFile(pTSBuf->path, false);
|
||||
EXPECT_EQ(pNewBuf->tsOrder, pTSBuf->tsOrder);
|
||||
EXPECT_EQ(pNewBuf->numOfVnodes, numOfVnode);
|
||||
EXPECT_EQ(pNewBuf->numOfGroups, numOfVnode);
|
||||
EXPECT_EQ(pNewBuf->fileSize, pTSBuf->fileSize);
|
||||
|
||||
EXPECT_EQ(pNewBuf->pData[0].info.offset, pTSBuf->pData[0].info.offset);
|
||||
|
@ -269,7 +269,7 @@ void TSTraverse() {
|
|||
start += step * num;
|
||||
}
|
||||
|
||||
EXPECT_EQ(pTSBuf->numOfVnodes, j + 1);
|
||||
EXPECT_EQ(pTSBuf->numOfGroups, j + 1);
|
||||
}
|
||||
|
||||
tsBufResetPos(pTSBuf);
|
||||
|
@ -304,7 +304,7 @@ void TSTraverse() {
|
|||
int32_t totalOutput = 10;
|
||||
while (1) {
|
||||
STSElem elem = tsBufGetElem(pTSBuf);
|
||||
printf("%d-%" PRIu64 "-%" PRIu64 "\n", elem.vnode, elem.tag->i64Key, elem.ts);
|
||||
printf("%d-%" PRIu64 "-%" PRIu64 "\n", elem.id, elem.tag->i64Key, elem.ts);
|
||||
|
||||
if (!tsBufNextPos(pTSBuf)) {
|
||||
break;
|
||||
|
@ -352,7 +352,7 @@ void TSTraverse() {
|
|||
totalOutput = 10;
|
||||
while (1) {
|
||||
STSElem elem = tsBufGetElem(pTSBuf);
|
||||
printf("%d-%" PRIu64 "-%" PRIu64 "\n", elem.vnode, elem.tag->i64Key, elem.ts);
|
||||
printf("%d-%" PRIu64 "-%" PRIu64 "\n", elem.id, elem.tag->i64Key, elem.ts);
|
||||
|
||||
if (!tsBufNextPos(pTSBuf)) {
|
||||
break;
|
||||
|
@ -427,7 +427,7 @@ void mergeDiffVnodeBufferTest() {
|
|||
tsBufFlush(pTSBuf2);
|
||||
|
||||
tsBufMerge(pTSBuf1, pTSBuf2);
|
||||
EXPECT_EQ(pTSBuf1->numOfVnodes, 2);
|
||||
EXPECT_EQ(pTSBuf1->numOfGroups, 2);
|
||||
EXPECT_EQ(pTSBuf1->numOfTotal, numOfTags * 2 * num);
|
||||
|
||||
tsBufDisplay(pTSBuf1);
|
||||
|
@ -472,7 +472,7 @@ void mergeIdenticalVnodeBufferTest() {
|
|||
tsBufFlush(pTSBuf2);
|
||||
|
||||
tsBufMerge(pTSBuf1, pTSBuf2);
|
||||
EXPECT_EQ(pTSBuf1->numOfVnodes, 2);
|
||||
EXPECT_EQ(pTSBuf1->numOfGroups, 2);
|
||||
EXPECT_EQ(pTSBuf1->numOfTotal, numOfTags * 2 * num);
|
||||
|
||||
tsBufResetPos(pTSBuf1);
|
||||
|
@ -482,12 +482,12 @@ void mergeIdenticalVnodeBufferTest() {
|
|||
STSElem elem = tsBufGetElem(pTSBuf1);
|
||||
|
||||
if (count++ < numOfTags * num) {
|
||||
EXPECT_EQ(elem.vnode, 12);
|
||||
EXPECT_EQ(elem.id, 12);
|
||||
} else {
|
||||
EXPECT_EQ(elem.vnode, 77);
|
||||
EXPECT_EQ(elem.id, 77);
|
||||
}
|
||||
|
||||
printf("%d-%" PRIu64 "-%" PRIu64 "\n", elem.vnode, elem.tag->i64Key, elem.ts);
|
||||
printf("%d-%" PRIu64 "-%" PRIu64 "\n", elem.id, elem.tag->i64Key, elem.ts);
|
||||
}
|
||||
|
||||
tsBufDestroy(pTSBuf1);
|
||||
|
|
|
@ -82,6 +82,7 @@ typedef struct {
|
|||
int8_t oldInUse; // server EP inUse passed by app
|
||||
int8_t redirect; // flag to indicate redirect
|
||||
int8_t connType; // connection type
|
||||
int64_t rid; // refId returned by taosAddRef
|
||||
SRpcMsg *pRsp; // for synchronous API
|
||||
tsem_t *pSem; // for synchronous API
|
||||
SRpcEpSet *pSet; // for synchronous API
|
||||
|
@ -220,8 +221,7 @@ static void rpcFree(void *p) {
|
|||
free(p);
|
||||
}
|
||||
|
||||
static void rpcInit(void) {
|
||||
|
||||
void rpcInit(void) {
|
||||
tsProgressTimer = tsRpcTimer/2;
|
||||
tsRpcMaxRetry = tsRpcMaxTime * 1000/tsProgressTimer;
|
||||
tsRpcHeadSize = RPC_MSG_OVERHEAD;
|
||||
|
@ -230,6 +230,11 @@ static void rpcInit(void) {
|
|||
tsRpcRefId = taosOpenRef(200, rpcFree);
|
||||
}
|
||||
|
||||
void rpcCleanup(void) {
|
||||
taosCloseRef(tsRpcRefId);
|
||||
tsRpcRefId = -1;
|
||||
}
|
||||
|
||||
void *rpcOpen(const SRpcInit *pInit) {
|
||||
SRpcInfo *pRpc;
|
||||
|
||||
|
@ -374,7 +379,7 @@ void *rpcReallocCont(void *ptr, int contLen) {
|
|||
return start + sizeof(SRpcReqContext) + sizeof(SRpcHead);
|
||||
}
|
||||
|
||||
void rpcSendRequest(void *shandle, const SRpcEpSet *pEpSet, SRpcMsg *pMsg) {
|
||||
int64_t rpcSendRequest(void *shandle, const SRpcEpSet *pEpSet, SRpcMsg *pMsg) {
|
||||
SRpcInfo *pRpc = (SRpcInfo *)shandle;
|
||||
SRpcReqContext *pContext;
|
||||
|
||||
|
@ -403,10 +408,11 @@ void rpcSendRequest(void *shandle, const SRpcEpSet *pEpSet, SRpcMsg *pMsg) {
|
|||
// set the handle to pContext, so app can cancel the request
|
||||
if (pMsg->handle) *((void **)pMsg->handle) = pContext;
|
||||
|
||||
taosAddRef(tsRpcRefId, pContext);
|
||||
pContext->rid = taosAddRef(tsRpcRefId, pContext);
|
||||
|
||||
rpcSendReqToServer(pRpc, pContext);
|
||||
|
||||
return;
|
||||
return pContext->rid;
|
||||
}
|
||||
|
||||
void rpcSendResponse(const SRpcMsg *pRsp) {
|
||||
|
@ -551,15 +557,14 @@ int rpcReportProgress(void *handle, char *pCont, int contLen) {
|
|||
return code;
|
||||
}
|
||||
|
||||
void rpcCancelRequest(void *handle) {
|
||||
SRpcReqContext *pContext = handle;
|
||||
void rpcCancelRequest(int64_t rid) {
|
||||
|
||||
int code = taosAcquireRef(tsRpcRefId, pContext);
|
||||
if (code < 0) return;
|
||||
SRpcReqContext *pContext = taosAcquireRef(tsRpcRefId, rid);
|
||||
if (pContext == NULL) return;
|
||||
|
||||
rpcCloseConn(pContext->pConn);
|
||||
|
||||
taosReleaseRef(tsRpcRefId, pContext);
|
||||
taosReleaseRef(tsRpcRefId, rid);
|
||||
}
|
||||
|
||||
static void rpcFreeMsg(void *msg) {
|
||||
|
@ -628,7 +633,7 @@ static void rpcReleaseConn(SRpcConn *pConn) {
|
|||
// if there is an outgoing message, free it
|
||||
if (pConn->outType && pConn->pReqMsg) {
|
||||
if (pConn->pContext) pConn->pContext->pConn = NULL;
|
||||
taosRemoveRef(tsRpcRefId, pConn->pContext);
|
||||
taosRemoveRef(tsRpcRefId, pConn->pContext->rid);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1109,7 +1114,7 @@ static void rpcNotifyClient(SRpcReqContext *pContext, SRpcMsg *pMsg) {
|
|||
}
|
||||
|
||||
// free the request message
|
||||
taosRemoveRef(tsRpcRefId, pContext);
|
||||
taosRemoveRef(tsRpcRefId, pContext->rid);
|
||||
}
|
||||
|
||||
static void rpcProcessIncomingMsg(SRpcConn *pConn, SRpcHead *pHead, SRpcReqContext *pContext) {
|
||||
|
@ -1620,11 +1625,7 @@ static void rpcDecRef(SRpcInfo *pRpc)
|
|||
tDebug("%s rpc resources are released", pRpc->label);
|
||||
taosTFree(pRpc);
|
||||
|
||||
int count = atomic_sub_fetch_32(&tsRpcNum, 1);
|
||||
if (count == 0) {
|
||||
taosCloseRef(tsRpcRefId);
|
||||
// tsRpcInit = PTHREAD_ONCE_INIT; // windows compliling error
|
||||
}
|
||||
atomic_sub_fetch_32(&tsRpcNum, 1);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -141,6 +141,7 @@ typedef struct SSyncNode {
|
|||
int8_t replica;
|
||||
int8_t quorum;
|
||||
uint32_t vgId;
|
||||
int64_t rid;
|
||||
void *ahandle;
|
||||
int8_t selfIndex;
|
||||
SSyncPeer *peerInfo[TAOS_SYNC_MAX_REPLICA+1]; // extra one for arbitrator
|
||||
|
|
|
@ -142,14 +142,14 @@ void syncCleanUp() {
|
|||
sInfo("sync module is cleaned up");
|
||||
}
|
||||
|
||||
void *syncStart(const SSyncInfo *pInfo) {
|
||||
int64_t syncStart(const SSyncInfo *pInfo) {
|
||||
const SSyncCfg *pCfg = &pInfo->syncCfg;
|
||||
|
||||
SSyncNode *pNode = (SSyncNode *)calloc(sizeof(SSyncNode), 1);
|
||||
if (pNode == NULL) {
|
||||
sError("no memory to allocate syncNode");
|
||||
terrno = TAOS_SYSTEM_ERROR(errno);
|
||||
return NULL;
|
||||
return -1;
|
||||
}
|
||||
|
||||
tstrncpy(pNode->path, pInfo->path, sizeof(pNode->path));
|
||||
|
@ -170,10 +170,10 @@ void *syncStart(const SSyncInfo *pInfo) {
|
|||
pNode->quorum = pCfg->quorum;
|
||||
if (pNode->quorum > pNode->replica) pNode->quorum = pNode->replica;
|
||||
|
||||
int ret = taosAddRef(tsSyncRefId, pNode);
|
||||
if (ret < 0) {
|
||||
pNode->rid = taosAddRef(tsSyncRefId, pNode);
|
||||
if (pNode->rid < 0) {
|
||||
syncFreeNode(pNode);
|
||||
return NULL;
|
||||
return -1;
|
||||
}
|
||||
|
||||
for (int i = 0; i < pCfg->replica; ++i) {
|
||||
|
@ -187,8 +187,8 @@ void *syncStart(const SSyncInfo *pInfo) {
|
|||
if (pNode->selfIndex < 0) {
|
||||
sInfo("vgId:%d, this node is not configured", pNode->vgId);
|
||||
terrno = TSDB_CODE_SYN_INVALID_CONFIG;
|
||||
syncStop(pNode);
|
||||
return NULL;
|
||||
syncStop(pNode->rid);
|
||||
return -1;
|
||||
}
|
||||
|
||||
nodeVersion = pInfo->version; // set the initial version
|
||||
|
@ -200,15 +200,15 @@ void *syncStart(const SSyncInfo *pInfo) {
|
|||
if (pNode->pSyncFwds == NULL) {
|
||||
sError("vgId:%d, no memory to allocate syncFwds", pNode->vgId);
|
||||
terrno = TAOS_SYSTEM_ERROR(errno);
|
||||
syncStop(pNode);
|
||||
return NULL;
|
||||
syncStop(pNode->rid);
|
||||
return -1;
|
||||
}
|
||||
|
||||
pNode->pFwdTimer = taosTmrStart(syncMonitorFwdInfos, 300, pNode, syncTmrCtrl);
|
||||
pNode->pFwdTimer = taosTmrStart(syncMonitorFwdInfos, 300, (void *)pNode->rid, syncTmrCtrl);
|
||||
if (pNode->pFwdTimer == NULL) {
|
||||
sError("vgId:%d, failed to allocate timer", pNode->vgId);
|
||||
syncStop(pNode);
|
||||
return NULL;
|
||||
syncStop(pNode->rid);
|
||||
return -1;
|
||||
}
|
||||
|
||||
syncAddArbitrator(pNode);
|
||||
|
@ -218,15 +218,14 @@ void *syncStart(const SSyncInfo *pInfo) {
|
|||
(*pNode->notifyRole)(pNode->ahandle, nodeRole);
|
||||
}
|
||||
|
||||
return pNode;
|
||||
return pNode->rid;
|
||||
}
|
||||
|
||||
void syncStop(void *param) {
|
||||
SSyncNode *pNode = param;
|
||||
void syncStop(int64_t rid) {
|
||||
SSyncPeer *pPeer;
|
||||
|
||||
int ret = taosAcquireRef(tsSyncRefId, pNode);
|
||||
if (ret < 0) return;
|
||||
SSyncNode *pNode = taosAcquireRef(tsSyncRefId, rid);
|
||||
if (pNode == NULL) return;
|
||||
|
||||
sInfo("vgId:%d, cleanup sync", pNode->vgId);
|
||||
|
||||
|
@ -245,16 +244,15 @@ void syncStop(void *param) {
|
|||
|
||||
pthread_mutex_unlock(&(pNode->mutex));
|
||||
|
||||
taosReleaseRef(tsSyncRefId, pNode);
|
||||
taosRemoveRef(tsSyncRefId, pNode);
|
||||
taosReleaseRef(tsSyncRefId, rid);
|
||||
taosRemoveRef(tsSyncRefId, rid);
|
||||
}
|
||||
|
||||
int32_t syncReconfig(void *param, const SSyncCfg *pNewCfg) {
|
||||
SSyncNode *pNode = param;
|
||||
int32_t syncReconfig(int64_t rid, const SSyncCfg *pNewCfg) {
|
||||
int i, j;
|
||||
|
||||
int ret = taosAcquireRef(tsSyncRefId, pNode);
|
||||
if (ret < 0) return TSDB_CODE_SYN_INVALID_CONFIG;
|
||||
SSyncNode *pNode = taosAcquireRef(tsSyncRefId, rid);
|
||||
if (pNode == NULL) return TSDB_CODE_SYN_INVALID_CONFIG;
|
||||
|
||||
sInfo("vgId:%d, reconfig, role:%s replica:%d old:%d", pNode->vgId, syncRole[nodeRole], pNewCfg->replica,
|
||||
pNode->replica);
|
||||
|
@ -318,29 +316,25 @@ int32_t syncReconfig(void *param, const SSyncCfg *pNewCfg) {
|
|||
syncRole[nodeRole]);
|
||||
syncBroadcastStatus(pNode);
|
||||
|
||||
taosReleaseRef(tsSyncRefId, pNode);
|
||||
taosReleaseRef(tsSyncRefId, rid);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int32_t syncForwardToPeer(void *param, void *data, void *mhandle, int qtype) {
|
||||
SSyncNode *pNode = param;
|
||||
|
||||
int ret = taosAcquireRef(tsSyncRefId, pNode);
|
||||
if (ret < 0) return 0;
|
||||
int32_t syncForwardToPeer(int64_t rid, void *data, void *mhandle, int qtype) {
|
||||
SSyncNode *pNode = taosAcquireRef(tsSyncRefId, rid);
|
||||
if (pNode == NULL) return 0;
|
||||
|
||||
int32_t code = syncForwardToPeerImpl(pNode, data, mhandle, qtype);
|
||||
|
||||
taosReleaseRef(tsSyncRefId, pNode);
|
||||
taosReleaseRef(tsSyncRefId, rid);
|
||||
|
||||
return code;
|
||||
}
|
||||
|
||||
void syncConfirmForward(void *param, uint64_t version, int32_t code) {
|
||||
SSyncNode *pNode = param;
|
||||
|
||||
int ret = taosAcquireRef(tsSyncRefId, pNode);
|
||||
if (ret < 0) return;
|
||||
void syncConfirmForward(int64_t rid, uint64_t version, int32_t code) {
|
||||
SSyncNode *pNode = taosAcquireRef(tsSyncRefId, rid);
|
||||
if (pNode == NULL) return;
|
||||
|
||||
SSyncPeer *pPeer = pNode->pMaster;
|
||||
if (pPeer && pNode->quorum > 1) {
|
||||
|
@ -365,15 +359,14 @@ void syncConfirmForward(void *param, uint64_t version, int32_t code) {
|
|||
}
|
||||
}
|
||||
|
||||
taosReleaseRef(tsSyncRefId, pNode);
|
||||
taosReleaseRef(tsSyncRefId, rid);
|
||||
}
|
||||
|
||||
void syncRecover(void *param) {
|
||||
SSyncNode *pNode = param;
|
||||
void syncRecover(int64_t rid) {
|
||||
SSyncPeer *pPeer;
|
||||
|
||||
int ret = taosAcquireRef(tsSyncRefId, pNode);
|
||||
if (ret < 0) return;
|
||||
SSyncNode *pNode = taosAcquireRef(tsSyncRefId, rid);
|
||||
if (pNode == NULL) return;
|
||||
|
||||
// to do: add a few lines to check if recover is OK
|
||||
// if take this node to unsync state, the whole system may not work
|
||||
|
@ -393,14 +386,12 @@ void syncRecover(void *param) {
|
|||
|
||||
pthread_mutex_unlock(&(pNode->mutex));
|
||||
|
||||
taosReleaseRef(tsSyncRefId, pNode);
|
||||
taosReleaseRef(tsSyncRefId, rid);
|
||||
}
|
||||
|
||||
int syncGetNodesRole(void *param, SNodesRole *pNodesRole) {
|
||||
SSyncNode *pNode = param;
|
||||
|
||||
int ret = taosAcquireRef(tsSyncRefId, pNode);
|
||||
if (ret < 0) return -1;
|
||||
int syncGetNodesRole(int64_t rid, SNodesRole *pNodesRole) {
|
||||
SSyncNode *pNode = taosAcquireRef(tsSyncRefId, rid);
|
||||
if (pNode == NULL) return -1;
|
||||
|
||||
pNodesRole->selfIndex = pNode->selfIndex;
|
||||
for (int i = 0; i < pNode->replica; ++i) {
|
||||
|
@ -408,7 +399,7 @@ int syncGetNodesRole(void *param, SNodesRole *pNodesRole) {
|
|||
pNodesRole->role[i] = pNode->peerInfo[i]->role;
|
||||
}
|
||||
|
||||
taosReleaseRef(tsSyncRefId, pNode);
|
||||
taosReleaseRef(tsSyncRefId, rid);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
@ -455,7 +446,7 @@ void syncAddPeerRef(SSyncPeer *pPeer) { atomic_add_fetch_8(&pPeer->refCount, 1);
|
|||
|
||||
int syncDecPeerRef(SSyncPeer *pPeer) {
|
||||
if (atomic_sub_fetch_8(&pPeer->refCount, 1) == 0) {
|
||||
taosReleaseRef(tsSyncRefId, pPeer->pSyncNode);
|
||||
taosReleaseRef(tsSyncRefId, pPeer->pSyncNode->rid);
|
||||
|
||||
sDebug("%s, resource is freed", pPeer->id);
|
||||
taosTFree(pPeer->watchFd);
|
||||
|
@ -512,7 +503,7 @@ static SSyncPeer *syncAddPeer(SSyncNode *pNode, const SNodeInfo *pInfo) {
|
|||
taosTmrReset(syncCheckPeerConnection, checkMs, pPeer, syncTmrCtrl, &pPeer->timer);
|
||||
}
|
||||
|
||||
taosAcquireRef(tsSyncRefId, pNode);
|
||||
taosAcquireRef(tsSyncRefId, pNode->rid);
|
||||
return pPeer;
|
||||
}
|
||||
|
||||
|
@ -863,7 +854,7 @@ static void syncProcessForwardFromPeer(char *cont, SSyncPeer *pPeer) {
|
|||
|
||||
if (nodeRole == TAOS_SYNC_ROLE_SLAVE) {
|
||||
// nodeVersion = pHead->version;
|
||||
(*pNode->writeToCache)(pNode->ahandle, pHead, TAOS_QTYPE_FWD);
|
||||
(*pNode->writeToCache)(pNode->ahandle, pHead, TAOS_QTYPE_FWD, NULL);
|
||||
} else {
|
||||
if (nodeSStatus != TAOS_SYNC_STATUS_INIT) {
|
||||
syncSaveIntoBuffer(pPeer, pHead);
|
||||
|
@ -1105,7 +1096,7 @@ static void syncProcessBrokenLink(void *param) {
|
|||
SSyncPeer *pPeer = param;
|
||||
SSyncNode *pNode = pPeer->pSyncNode;
|
||||
|
||||
if (taosAcquireRef(tsSyncRefId, pNode) < 0) return;
|
||||
if (taosAcquireRef(tsSyncRefId, pNode->rid) < 0) return;
|
||||
pthread_mutex_lock(&(pNode->mutex));
|
||||
|
||||
sDebug("%s, TCP link is broken(%s)", pPeer->id, strerror(errno));
|
||||
|
@ -1116,7 +1107,7 @@ static void syncProcessBrokenLink(void *param) {
|
|||
}
|
||||
|
||||
pthread_mutex_unlock(&(pNode->mutex));
|
||||
taosReleaseRef(tsSyncRefId, pNode);
|
||||
taosReleaseRef(tsSyncRefId, pNode->rid);
|
||||
}
|
||||
|
||||
static void syncSaveFwdInfo(SSyncNode *pNode, uint64_t version, void *mhandle) {
|
||||
|
@ -1184,10 +1175,9 @@ static void syncProcessFwdAck(SSyncNode *pNode, SFwdInfo *pFwdInfo, int32_t code
|
|||
}
|
||||
|
||||
static void syncMonitorFwdInfos(void *param, void *tmrId) {
|
||||
SSyncNode *pNode = param;
|
||||
|
||||
int ret = taosAcquireRef(tsSyncRefId, pNode);
|
||||
if ( ret < 0) return;
|
||||
int64_t rid = (int64_t) param;
|
||||
SSyncNode *pNode = taosAcquireRef(tsSyncRefId, rid);
|
||||
if (pNode == NULL) return;
|
||||
|
||||
SSyncFwds *pSyncFwds = pNode->pSyncFwds;
|
||||
|
||||
|
@ -1206,10 +1196,10 @@ static void syncMonitorFwdInfos(void *param, void *tmrId) {
|
|||
pthread_mutex_unlock(&(pNode->mutex));
|
||||
}
|
||||
|
||||
pNode->pFwdTimer = taosTmrStart(syncMonitorFwdInfos, 300, pNode, syncTmrCtrl);
|
||||
pNode->pFwdTimer = taosTmrStart(syncMonitorFwdInfos, 300, (void *)pNode->rid, syncTmrCtrl);
|
||||
}
|
||||
|
||||
taosReleaseRef(tsSyncRefId, pNode);
|
||||
taosReleaseRef(tsSyncRefId, rid);
|
||||
}
|
||||
|
||||
static int32_t syncForwardToPeerImpl(SSyncNode *pNode, void *data, void *mhandle, int qtype) {
|
||||
|
|
|
@ -154,7 +154,7 @@ static int syncRestoreWal(SSyncPeer *pPeer) {
|
|||
if (ret < 0) break;
|
||||
|
||||
sDebug("%s, restore a record, ver:%" PRIu64, pPeer->id, pHead->version);
|
||||
(*pNode->writeToCache)(pNode->ahandle, pHead, TAOS_QTYPE_WAL);
|
||||
(*pNode->writeToCache)(pNode->ahandle, pHead, TAOS_QTYPE_WAL, NULL);
|
||||
}
|
||||
|
||||
if (code < 0) {
|
||||
|
@ -169,7 +169,7 @@ static char *syncProcessOneBufferedFwd(SSyncPeer *pPeer, char *offset) {
|
|||
SSyncNode *pNode = pPeer->pSyncNode;
|
||||
SWalHead * pHead = (SWalHead *)offset;
|
||||
|
||||
(*pNode->writeToCache)(pNode->ahandle, pHead, TAOS_QTYPE_FWD);
|
||||
(*pNode->writeToCache)(pNode->ahandle, pHead, TAOS_QTYPE_FWD, NULL);
|
||||
offset += pHead->len + sizeof(SWalHead);
|
||||
|
||||
return offset;
|
||||
|
|
|
@ -30,7 +30,7 @@ int dataFd = -1;
|
|||
void * qhandle = NULL;
|
||||
int walNum = 0;
|
||||
uint64_t tversion = 0;
|
||||
void * syncHandle;
|
||||
int64_t syncHandle;
|
||||
int role;
|
||||
int nodeId;
|
||||
char path[256];
|
||||
|
|
|
@ -320,6 +320,15 @@ typedef struct {
|
|||
void* compBuffer; // Buffer for temperary compress/decompress purpose
|
||||
} SRWHelper;
|
||||
|
||||
typedef struct {
|
||||
int rowsInserted;
|
||||
int rowsUpdated;
|
||||
int rowsDeleteSucceed;
|
||||
int rowsDeleteFailed;
|
||||
int nOperations;
|
||||
TSKEY keyFirst;
|
||||
TSKEY keyLast;
|
||||
} SMergeInfo;
|
||||
// ------------------ tsdbScan.c
|
||||
typedef struct {
|
||||
SFileGroup fGroup;
|
||||
|
@ -422,7 +431,7 @@ void tsdbCloseBufPool(STsdbRepo* pRepo);
|
|||
SListNode* tsdbAllocBufBlockFromPool(STsdbRepo* pRepo);
|
||||
|
||||
// ------------------ tsdbMemTable.c
|
||||
int tsdbInsertRowToMem(STsdbRepo* pRepo, SDataRow row, STable* pTable);
|
||||
int tsdbUpdateRowInMem(STsdbRepo* pRepo, SDataRow row, STable* pTable);
|
||||
int tsdbRefMemTable(STsdbRepo* pRepo, SMemTable* pMemTable);
|
||||
int tsdbUnRefMemTable(STsdbRepo* pRepo, SMemTable* pMemTable);
|
||||
int tsdbTakeMemSnapshot(STsdbRepo* pRepo, SMemTable** pMem, SMemTable** pIMem);
|
||||
|
@ -430,7 +439,7 @@ void tsdbUnTakeMemSnapShot(STsdbRepo* pRepo, SMemTable* pMem, SMemTable* pIMem)
|
|||
void* tsdbAllocBytes(STsdbRepo* pRepo, int bytes);
|
||||
int tsdbAsyncCommit(STsdbRepo* pRepo);
|
||||
int tsdbLoadDataFromCache(STable* pTable, SSkipListIterator* pIter, TSKEY maxKey, int maxRowsToRead, SDataCols* pCols,
|
||||
TSKEY* filterKeys, int nFilterKeys);
|
||||
TKEY* filterKeys, int nFilterKeys, bool keepDup, SMergeInfo* pMergeInfo);
|
||||
|
||||
static FORCE_INLINE SDataRow tsdbNextIterRow(SSkipListIterator* pIter) {
|
||||
if (pIter == NULL) return NULL;
|
||||
|
@ -438,16 +447,23 @@ static FORCE_INLINE SDataRow tsdbNextIterRow(SSkipListIterator* pIter) {
|
|||
SSkipListNode* node = tSkipListIterGet(pIter);
|
||||
if (node == NULL) return NULL;
|
||||
|
||||
return *(SDataRow *)SL_GET_NODE_DATA(node);
|
||||
return (SDataRow)SL_GET_NODE_DATA(node);
|
||||
}
|
||||
|
||||
static FORCE_INLINE TSKEY tsdbNextIterKey(SSkipListIterator* pIter) {
|
||||
SDataRow row = tsdbNextIterRow(pIter);
|
||||
if (row == NULL) return -1;
|
||||
if (row == NULL) return TSDB_DATA_TIMESTAMP_NULL;
|
||||
|
||||
return dataRowKey(row);
|
||||
}
|
||||
|
||||
static FORCE_INLINE TKEY tsdbNextIterTKey(SSkipListIterator* pIter) {
|
||||
SDataRow row = tsdbNextIterRow(pIter);
|
||||
if (row == NULL) return TKEY_NULL;
|
||||
|
||||
return dataRowTKey(row);
|
||||
}
|
||||
|
||||
static FORCE_INLINE STsdbBufBlock* tsdbGetCurrBufBlock(STsdbRepo* pRepo) {
|
||||
ASSERT(pRepo != NULL);
|
||||
if (pRepo->mem == NULL) return NULL;
|
||||
|
|
|
@ -512,6 +512,9 @@ static int32_t tsdbCheckAndSetDefaultCfg(STsdbCfg *pCfg) {
|
|||
}
|
||||
}
|
||||
|
||||
// update check
|
||||
if (pCfg->update != 0) pCfg->update = 1;
|
||||
|
||||
return 0;
|
||||
|
||||
_err:
|
||||
|
@ -762,7 +765,7 @@ static int32_t tsdbInsertDataToTable(STsdbRepo *pRepo, SSubmitBlk *pBlock, TSKEY
|
|||
return -1;
|
||||
}
|
||||
|
||||
if (tsdbInsertRowToMem(pRepo, row, pTable) < 0) return -1;
|
||||
if (tsdbUpdateRowInMem(pRepo, row, pTable) < 0) return -1;
|
||||
|
||||
(*affectedrows)++;
|
||||
points++;
|
||||
|
@ -923,6 +926,7 @@ static int tsdbEncodeCfg(void **buf, STsdbCfg *pCfg) {
|
|||
tlen += taosEncodeVariantI32(buf, pCfg->maxRowsPerFileBlock);
|
||||
tlen += taosEncodeFixedI8(buf, pCfg->precision);
|
||||
tlen += taosEncodeFixedI8(buf, pCfg->compression);
|
||||
tlen += taosEncodeFixedI8(buf, pCfg->update);
|
||||
|
||||
return tlen;
|
||||
}
|
||||
|
@ -939,6 +943,7 @@ static void *tsdbDecodeCfg(void *buf, STsdbCfg *pCfg) {
|
|||
buf = taosDecodeVariantI32(buf, &(pCfg->maxRowsPerFileBlock));
|
||||
buf = taosDecodeFixedI8(buf, &(pCfg->precision));
|
||||
buf = taosDecodeFixedI8(buf, &(pCfg->compression));
|
||||
buf = taosDecodeFixedI8(buf, &(pCfg->update));
|
||||
|
||||
return buf;
|
||||
}
|
||||
|
|
|
@ -32,43 +32,40 @@ static int tsdbCommitToFile(STsdbRepo *pRepo, int fid, SCommitIter *iters, SRWHe
|
|||
static SCommitIter *tsdbCreateCommitIters(STsdbRepo *pRepo);
|
||||
static void tsdbDestroyCommitIters(SCommitIter *iters, int maxTables);
|
||||
static int tsdbAdjustMemMaxTables(SMemTable *pMemTable, int maxTables);
|
||||
static int tsdbAppendTableRowToCols(STable *pTable, SDataCols *pCols, STSchema **ppSchema, SDataRow row);
|
||||
|
||||
// ---------------- INTERNAL FUNCTIONS ----------------
|
||||
int tsdbInsertRowToMem(STsdbRepo *pRepo, SDataRow row, STable *pTable) {
|
||||
int tsdbUpdateRowInMem(STsdbRepo *pRepo, SDataRow row, STable *pTable) {
|
||||
STsdbCfg * pCfg = &pRepo->config;
|
||||
STsdbMeta * pMeta = pRepo->tsdbMeta;
|
||||
int32_t level = 0;
|
||||
int32_t headSize = 0;
|
||||
TKEY tkey = dataRowTKey(row);
|
||||
TSKEY key = dataRowKey(row);
|
||||
SMemTable * pMemTable = pRepo->mem;
|
||||
STableData *pTableData = NULL;
|
||||
SSkipList * pSList = NULL;
|
||||
bool isRowDelete = TKEY_IS_DELETED(tkey);
|
||||
|
||||
if (pMemTable != NULL && TABLE_TID(pTable) < pMemTable->maxTables && pMemTable->tData[TABLE_TID(pTable)] != NULL &&
|
||||
pMemTable->tData[TABLE_TID(pTable)]->uid == TABLE_UID(pTable)) {
|
||||
pTableData = pMemTable->tData[TABLE_TID(pTable)];
|
||||
pSList = pTableData->pData;
|
||||
}
|
||||
if (isRowDelete) {
|
||||
if (!pCfg->update) {
|
||||
tsdbWarn("vgId:%d vnode is not allowed to update but try to delete a data row", REPO_ID(pRepo));
|
||||
terrno = TSDB_CODE_TDB_INVALID_ACTION;
|
||||
return -1;
|
||||
}
|
||||
|
||||
tSkipListNewNodeInfo(pSList, &level, &headSize);
|
||||
|
||||
SSkipListNode *pNode = (SSkipListNode *)malloc(headSize + sizeof(SDataRow *));
|
||||
if (pNode == NULL) {
|
||||
terrno = TSDB_CODE_TDB_OUT_OF_MEMORY;
|
||||
return -1;
|
||||
if (key > TABLE_LASTKEY(pTable)) {
|
||||
tsdbTrace("vgId:%d skip to delete row key %" PRId64 " which is larger than table lastKey %" PRId64,
|
||||
REPO_ID(pRepo), key, TABLE_LASTKEY(pTable));
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
void *pRow = tsdbAllocBytes(pRepo, dataRowLen(row));
|
||||
if (pRow == NULL) {
|
||||
tsdbError("vgId:%d failed to insert row with key %" PRId64 " to table %s while allocate %d bytes since %s",
|
||||
REPO_ID(pRepo), key, TABLE_CHAR_NAME(pTable), dataRowLen(row), tstrerror(terrno));
|
||||
free(pNode);
|
||||
return -1;
|
||||
}
|
||||
|
||||
pNode->level = level;
|
||||
dataRowCpy(pRow, row);
|
||||
*(SDataRow *)SL_GET_NODE_DATA(pNode) = pRow;
|
||||
|
||||
// Operations above may change pRepo->mem, retake those values
|
||||
ASSERT(pRepo->mem != NULL);
|
||||
|
@ -77,7 +74,6 @@ int tsdbInsertRowToMem(STsdbRepo *pRepo, SDataRow row, STable *pTable) {
|
|||
if (TABLE_TID(pTable) >= pMemTable->maxTables) {
|
||||
if (tsdbAdjustMemMaxTables(pMemTable, pMeta->maxTables) < 0) {
|
||||
tsdbFreeBytes(pRepo, pRow, dataRowLen(row));
|
||||
free(pNode);
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
@ -97,7 +93,6 @@ int tsdbInsertRowToMem(STsdbRepo *pRepo, SDataRow row, STable *pTable) {
|
|||
" to table %s while create new table data object since %s",
|
||||
REPO_ID(pRepo), key, TABLE_CHAR_NAME(pTable), tstrerror(terrno));
|
||||
tsdbFreeBytes(pRepo, (void *)pRow, dataRowLen(row));
|
||||
free(pNode);
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
@ -106,24 +101,31 @@ int tsdbInsertRowToMem(STsdbRepo *pRepo, SDataRow row, STable *pTable) {
|
|||
|
||||
ASSERT((pTableData != NULL) && pTableData->uid == TABLE_UID(pTable));
|
||||
|
||||
if (tSkipListPut(pTableData->pData, pNode) == NULL) {
|
||||
int64_t oldSize = SL_SIZE(pTableData->pData);
|
||||
if (tSkipListPut(pTableData->pData, pRow) == NULL) {
|
||||
tsdbFreeBytes(pRepo, (void *)pRow, dataRowLen(row));
|
||||
free(pNode);
|
||||
} else {
|
||||
if (TABLE_LASTKEY(pTable) < key) TABLE_LASTKEY(pTable) = key;
|
||||
int64_t deltaSize = SL_SIZE(pTableData->pData) - oldSize;
|
||||
if (isRowDelete) {
|
||||
if (TABLE_LASTKEY(pTable) == key) {
|
||||
// TODO: need to update table last key here (may from file)
|
||||
}
|
||||
} else {
|
||||
if (TABLE_LASTKEY(pTable) < key) TABLE_LASTKEY(pTable) = key;
|
||||
}
|
||||
|
||||
if (pMemTable->keyFirst > key) pMemTable->keyFirst = key;
|
||||
if (pMemTable->keyLast < key) pMemTable->keyLast = key;
|
||||
pMemTable->numOfRows++;
|
||||
pMemTable->numOfRows += deltaSize;
|
||||
|
||||
if (pTableData->keyFirst > key) pTableData->keyFirst = key;
|
||||
if (pTableData->keyLast < key) pTableData->keyLast = key;
|
||||
pTableData->numOfRows++;
|
||||
|
||||
ASSERT(pTableData->numOfRows == tSkipListGetSize(pTableData->pData));
|
||||
pTableData->numOfRows += deltaSize;
|
||||
}
|
||||
|
||||
tsdbTrace("vgId:%d a row is inserted to table %s tid %d uid %" PRIu64 " key %" PRIu64, REPO_ID(pRepo),
|
||||
TABLE_CHAR_NAME(pTable), TABLE_TID(pTable), TABLE_UID(pTable), key);
|
||||
tsdbTrace("vgId:%d a row is %s table %s tid %d uid %" PRIu64 " key %" PRIu64, REPO_ID(pRepo),
|
||||
isRowDelete ? "deleted from" : "updated in", TABLE_CHAR_NAME(pTable), TABLE_TID(pTable), TABLE_UID(pTable),
|
||||
key);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
@ -295,63 +297,124 @@ int tsdbAsyncCommit(STsdbRepo *pRepo) {
|
|||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* This is an important function to load data or try to load data from memory skiplist iterator.
|
||||
*
|
||||
* This function load memory data until:
|
||||
* 1. iterator ends
|
||||
* 2. data key exceeds maxKey
|
||||
* 3. rowsIncreased = rowsInserted - rowsDeleteSucceed >= maxRowsToRead
|
||||
* 4. operations in pCols not exceeds its max capacity if pCols is given
|
||||
*
|
||||
* The function tries to procceed AS MUSH AS POSSIBLE.
|
||||
*/
|
||||
int tsdbLoadDataFromCache(STable *pTable, SSkipListIterator *pIter, TSKEY maxKey, int maxRowsToRead, SDataCols *pCols,
|
||||
TSKEY *filterKeys, int nFilterKeys) {
|
||||
ASSERT(maxRowsToRead > 0 && nFilterKeys >= 0);
|
||||
TKEY *filterKeys, int nFilterKeys, bool keepDup, SMergeInfo *pMergeInfo) {
|
||||
ASSERT(maxRowsToRead > 0 && nFilterKeys >= 0 && pMergeInfo != NULL);
|
||||
if (pIter == NULL) return 0;
|
||||
STSchema *pSchema = NULL;
|
||||
int numOfRows = 0;
|
||||
TSKEY keyNext = 0;
|
||||
TSKEY rowKey = 0;
|
||||
TSKEY fKey = 0;
|
||||
bool isRowDel = false;
|
||||
int filterIter = 0;
|
||||
SDataRow row = NULL;
|
||||
|
||||
if (nFilterKeys != 0) { // for filter purpose
|
||||
ASSERT(filterKeys != NULL);
|
||||
keyNext = tsdbNextIterKey(pIter);
|
||||
if (keyNext < 0 || keyNext > maxKey) return numOfRows;
|
||||
void *ptr = taosbsearch((void *)(&keyNext), (void *)filterKeys, nFilterKeys, sizeof(TSKEY), compTSKEY, TD_GE);
|
||||
filterIter = (ptr == NULL) ? nFilterKeys : (int)((POINTER_DISTANCE(ptr, filterKeys) / sizeof(TSKEY)));
|
||||
memset(pMergeInfo, 0, sizeof(*pMergeInfo));
|
||||
pMergeInfo->keyFirst = INT64_MAX;
|
||||
pMergeInfo->keyLast = INT64_MIN;
|
||||
if (pCols) tdResetDataCols(pCols);
|
||||
|
||||
row = tsdbNextIterRow(pIter);
|
||||
if (row == NULL || dataRowKey(row) > maxKey) {
|
||||
rowKey = INT64_MAX;
|
||||
isRowDel = false;
|
||||
} else {
|
||||
rowKey = dataRowKey(row);
|
||||
isRowDel = dataRowDeleted(row);
|
||||
}
|
||||
|
||||
do {
|
||||
SDataRow row = tsdbNextIterRow(pIter);
|
||||
if (row == NULL) break;
|
||||
if (filterIter >= nFilterKeys) {
|
||||
fKey = INT64_MAX;
|
||||
} else {
|
||||
fKey = tdGetKey(filterKeys[filterIter]);
|
||||
}
|
||||
|
||||
keyNext = dataRowKey(row);
|
||||
if (keyNext > maxKey) break;
|
||||
while (true) {
|
||||
if (fKey == INT64_MAX && rowKey == INT64_MAX) break;
|
||||
|
||||
bool keyFiltered = false;
|
||||
if (nFilterKeys != 0) {
|
||||
while (true) {
|
||||
if (filterIter >= nFilterKeys) break;
|
||||
if (keyNext == filterKeys[filterIter]) {
|
||||
keyFiltered = true;
|
||||
filterIter++;
|
||||
break;
|
||||
} else if (keyNext < filterKeys[filterIter]) {
|
||||
break;
|
||||
if (fKey < rowKey) {
|
||||
pMergeInfo->keyFirst = MIN(pMergeInfo->keyFirst, fKey);
|
||||
pMergeInfo->keyLast = MAX(pMergeInfo->keyLast, fKey);
|
||||
|
||||
filterIter++;
|
||||
if (filterIter >= nFilterKeys) {
|
||||
fKey = INT64_MAX;
|
||||
} else {
|
||||
fKey = tdGetKey(filterKeys[filterIter]);
|
||||
}
|
||||
} else if (fKey > rowKey) {
|
||||
if (isRowDel) {
|
||||
pMergeInfo->rowsDeleteFailed++;
|
||||
} else {
|
||||
if (pMergeInfo->rowsInserted - pMergeInfo->rowsDeleteSucceed >= maxRowsToRead) break;
|
||||
if (pCols && pMergeInfo->nOperations >= pCols->maxPoints) break;
|
||||
pMergeInfo->rowsInserted++;
|
||||
pMergeInfo->nOperations++;
|
||||
pMergeInfo->keyFirst = MIN(pMergeInfo->keyFirst, rowKey);
|
||||
pMergeInfo->keyLast = MAX(pMergeInfo->keyLast, rowKey);
|
||||
tsdbAppendTableRowToCols(pTable, pCols, &pSchema, row);
|
||||
}
|
||||
|
||||
tSkipListIterNext(pIter);
|
||||
row = tsdbNextIterRow(pIter);
|
||||
if (row == NULL || dataRowKey(row) > maxKey) {
|
||||
rowKey = INT64_MAX;
|
||||
isRowDel = false;
|
||||
} else {
|
||||
rowKey = dataRowKey(row);
|
||||
isRowDel = dataRowDeleted(row);
|
||||
}
|
||||
} else {
|
||||
if (isRowDel) {
|
||||
ASSERT(!keepDup);
|
||||
if (pCols && pMergeInfo->nOperations >= pCols->maxPoints) break;
|
||||
pMergeInfo->rowsDeleteSucceed++;
|
||||
pMergeInfo->nOperations++;
|
||||
tsdbAppendTableRowToCols(pTable, pCols, &pSchema, row);
|
||||
} else {
|
||||
if (keepDup) {
|
||||
if (pCols && pMergeInfo->nOperations >= pCols->maxPoints) break;
|
||||
pMergeInfo->rowsUpdated++;
|
||||
pMergeInfo->nOperations++;
|
||||
pMergeInfo->keyFirst = MIN(pMergeInfo->keyFirst, rowKey);
|
||||
pMergeInfo->keyLast = MAX(pMergeInfo->keyLast, rowKey);
|
||||
tsdbAppendTableRowToCols(pTable, pCols, &pSchema, row);
|
||||
} else {
|
||||
filterIter++;
|
||||
pMergeInfo->keyFirst = MIN(pMergeInfo->keyFirst, fKey);
|
||||
pMergeInfo->keyLast = MAX(pMergeInfo->keyLast, fKey);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!keyFiltered) {
|
||||
if (numOfRows >= maxRowsToRead) break;
|
||||
if (pCols) {
|
||||
if (pSchema == NULL || schemaVersion(pSchema) != dataRowVersion(row)) {
|
||||
pSchema = tsdbGetTableSchemaImpl(pTable, false, false, dataRowVersion(row));
|
||||
if (pSchema == NULL) {
|
||||
ASSERT(0);
|
||||
}
|
||||
}
|
||||
|
||||
tdAppendDataRowToDataCol(row, pSchema, pCols);
|
||||
tSkipListIterNext(pIter);
|
||||
row = tsdbNextIterRow(pIter);
|
||||
if (row == NULL || dataRowKey(row) > maxKey) {
|
||||
rowKey = INT64_MAX;
|
||||
isRowDel = false;
|
||||
} else {
|
||||
rowKey = dataRowKey(row);
|
||||
isRowDel = dataRowDeleted(row);
|
||||
}
|
||||
numOfRows++;
|
||||
}
|
||||
} while (tSkipListIterNext(pIter));
|
||||
|
||||
return numOfRows;
|
||||
filterIter++;
|
||||
if (filterIter >= nFilterKeys) {
|
||||
fKey = INT64_MAX;
|
||||
} else {
|
||||
fKey = tdGetKey(filterKeys[filterIter]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
// ---------------- LOCAL FUNCTIONS ----------------
|
||||
|
@ -440,8 +503,9 @@ static STableData *tsdbNewTableData(STsdbCfg *pCfg, STable *pTable) {
|
|||
pTableData->keyLast = 0;
|
||||
pTableData->numOfRows = 0;
|
||||
|
||||
pTableData->pData = tSkipListCreate(TSDB_DATA_SKIPLIST_LEVEL, TSDB_DATA_TYPE_TIMESTAMP,
|
||||
TYPE_BYTES[TSDB_DATA_TYPE_TIMESTAMP], 0, 0, 1, tsdbGetTsTupleKey);
|
||||
pTableData->pData =
|
||||
tSkipListCreate(TSDB_DATA_SKIPLIST_LEVEL, TSDB_DATA_TYPE_TIMESTAMP, TYPE_BYTES[TSDB_DATA_TYPE_TIMESTAMP],
|
||||
tkeyComparFn, pCfg->update ? SL_UPDATE_DUP_KEY : SL_DISCARD_DUP_KEY, tsdbGetTsTupleKey);
|
||||
if (pTableData->pData == NULL) {
|
||||
terrno = TSDB_CODE_TDB_OUT_OF_MEMORY;
|
||||
goto _err;
|
||||
|
@ -461,7 +525,7 @@ static void tsdbFreeTableData(STableData *pTableData) {
|
|||
}
|
||||
}
|
||||
|
||||
static char *tsdbGetTsTupleKey(const void *data) { return dataRowTuple(*(SDataRow *)data); }
|
||||
static char *tsdbGetTsTupleKey(const void *data) { return dataRowTuple((SDataRow)data); }
|
||||
|
||||
static void *tsdbCommitData(void *arg) {
|
||||
STsdbRepo * pRepo = (STsdbRepo *)arg;
|
||||
|
@ -583,7 +647,7 @@ static void tsdbEndCommit(STsdbRepo *pRepo) {
|
|||
static int tsdbHasDataToCommit(SCommitIter *iters, int nIters, TSKEY minKey, TSKEY maxKey) {
|
||||
for (int i = 0; i < nIters; i++) {
|
||||
TSKEY nextKey = tsdbNextIterKey((iters + i)->pIter);
|
||||
if (nextKey > 0 && (nextKey >= minKey && nextKey <= maxKey)) return 1;
|
||||
if (nextKey != TSDB_DATA_TIMESTAMP_NULL && (nextKey >= minKey && nextKey <= maxKey)) return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
@ -779,5 +843,21 @@ static int tsdbAdjustMemMaxTables(SMemTable *pMemTable, int maxTables) {
|
|||
|
||||
taosTFree(tData);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int tsdbAppendTableRowToCols(STable *pTable, SDataCols *pCols, STSchema **ppSchema, SDataRow row) {
|
||||
if (pCols) {
|
||||
if (*ppSchema == NULL || schemaVersion(*ppSchema) != dataRowVersion(row)) {
|
||||
*ppSchema = tsdbGetTableSchemaImpl(pTable, false, false, dataRowVersion(row));
|
||||
if (*ppSchema == NULL) {
|
||||
ASSERT(false);
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
tdAppendDataRowToDataCol(row, *ppSchema, pCols);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
|
@ -86,7 +86,8 @@ int tsdbCreateTable(TSDB_REPO_T *repo, STableCfg *pCfg) {
|
|||
if (pTable != NULL) {
|
||||
tsdbError("vgId:%d table %s already exists, tid %d uid %" PRId64, REPO_ID(pRepo), TABLE_CHAR_NAME(pTable),
|
||||
TABLE_TID(pTable), TABLE_UID(pTable));
|
||||
return TSDB_CODE_TDB_TABLE_ALREADY_EXIST;
|
||||
terrno = TSDB_CODE_TDB_TABLE_ALREADY_EXIST;
|
||||
goto _err;
|
||||
}
|
||||
|
||||
if (pCfg->type == TSDB_CHILD_TABLE) {
|
||||
|
@ -643,7 +644,7 @@ static void tsdbOrgMeta(void *pHandle) {
|
|||
}
|
||||
|
||||
static char *getTagIndexKey(const void *pData) {
|
||||
STable *pTable = *(STable **)pData;
|
||||
STable *pTable = (STable *)pData;
|
||||
|
||||
STSchema *pSchema = tsdbGetTableTagSchema(pTable);
|
||||
STColumn *pCol = schemaColAt(pSchema, DEFAULT_TAG_INDEX_COLUMN);
|
||||
|
@ -700,7 +701,7 @@ static STable *tsdbCreateTableFromCfg(STableCfg *pCfg, bool isSuper) {
|
|||
}
|
||||
pTable->tagVal = NULL;
|
||||
STColumn *pCol = schemaColAt(pTable->tagSchema, DEFAULT_TAG_INDEX_COLUMN);
|
||||
pTable->pIndex = tSkipListCreate(TSDB_SUPER_TABLE_SL_LEVEL, colType(pCol), (uint8_t)(colBytes(pCol)), 1, 0, 1, getTagIndexKey);
|
||||
pTable->pIndex = tSkipListCreate(TSDB_SUPER_TABLE_SL_LEVEL, colType(pCol), (uint8_t)(colBytes(pCol)), NULL, SL_ALLOW_DUP_KEY, getTagIndexKey);
|
||||
if (pTable->pIndex == NULL) {
|
||||
terrno = TSDB_CODE_TDB_OUT_OF_MEMORY;
|
||||
goto _err;
|
||||
|
@ -900,23 +901,8 @@ static int tsdbAddTableIntoIndex(STsdbMeta *pMeta, STable *pTable, bool refSuper
|
|||
|
||||
pTable->pSuper = pSTable;
|
||||
|
||||
int32_t level = 0;
|
||||
int32_t headSize = 0;
|
||||
tSkipListPut(pSTable->pIndex, (void *)pTable);
|
||||
|
||||
tSkipListNewNodeInfo(pSTable->pIndex, &level, &headSize);
|
||||
|
||||
// NOTE: do not allocate the space for key, since in each skip list node, only keep the pointer to pTable, not the
|
||||
// actual key value, and the key value will be retrieved during query through the pTable and getTagIndexKey function
|
||||
SSkipListNode *pNode = calloc(1, headSize + sizeof(STable *));
|
||||
if (pNode == NULL) {
|
||||
terrno = TSDB_CODE_TDB_OUT_OF_MEMORY;
|
||||
return -1;
|
||||
}
|
||||
pNode->level = level;
|
||||
|
||||
memcpy(SL_GET_NODE_DATA(pNode), &pTable, sizeof(STable *));
|
||||
|
||||
tSkipListPut(pSTable->pIndex, pNode);
|
||||
if (refSuper) T_REF_INC(pSTable);
|
||||
return 0;
|
||||
}
|
||||
|
@ -940,7 +926,7 @@ static int tsdbRemoveTableFromIndex(STsdbMeta *pMeta, STable *pTable) {
|
|||
SSkipListNode *pNode = taosArrayGetP(res, i);
|
||||
|
||||
// STableIndexElem* pElem = (STableIndexElem*) SL_GET_NODE_DATA(pNode);
|
||||
if (*(STable **)SL_GET_NODE_DATA(pNode) == pTable) { // this is the exact what we need
|
||||
if ((STable *)SL_GET_NODE_DATA(pNode) == pTable) { // this is the exact what we need
|
||||
tSkipListRemoveNode(pSTable->pIndex, pNode);
|
||||
}
|
||||
}
|
||||
|
@ -1170,8 +1156,8 @@ static void *tsdbDecodeTable(void *buf, STable **pRTable) {
|
|||
if (TABLE_TYPE(pTable) == TSDB_SUPER_TABLE) {
|
||||
buf = tdDecodeSchema(buf, &(pTable->tagSchema));
|
||||
STColumn *pCol = schemaColAt(pTable->tagSchema, DEFAULT_TAG_INDEX_COLUMN);
|
||||
pTable->pIndex =
|
||||
tSkipListCreate(TSDB_SUPER_TABLE_SL_LEVEL, colType(pCol), (uint8_t)(colBytes(pCol)), 1, 0, 1, getTagIndexKey);
|
||||
pTable->pIndex = tSkipListCreate(TSDB_SUPER_TABLE_SL_LEVEL, colType(pCol), (uint8_t)(colBytes(pCol)), NULL,
|
||||
SL_ALLOW_DUP_KEY, getTagIndexKey);
|
||||
if (pTable->pIndex == NULL) {
|
||||
terrno = TSDB_CODE_TDB_OUT_OF_MEMORY;
|
||||
tsdbFreeTable(pTable);
|
||||
|
@ -1197,7 +1183,7 @@ static int tsdbGetTableEncodeSize(int8_t act, STable *pTable) {
|
|||
tlen = sizeof(SListNode) + sizeof(SActObj) + sizeof(SActCont) + tsdbEncodeTable(NULL, pTable) + sizeof(TSCKSUM);
|
||||
} else {
|
||||
if (TABLE_TYPE(pTable) == TSDB_SUPER_TABLE) {
|
||||
tlen = (int)((sizeof(SListNode) + sizeof(SActObj)) * (tSkipListGetSize(pTable->pIndex) + 1));
|
||||
tlen = (int)((sizeof(SListNode) + sizeof(SActObj)) * (SL_SIZE(pTable->pIndex) + 1));
|
||||
} else {
|
||||
tlen = sizeof(SListNode) + sizeof(SActObj);
|
||||
}
|
||||
|
@ -1244,7 +1230,7 @@ static int tsdbRemoveTableFromStore(STsdbRepo *pRepo, STable *pTable) {
|
|||
}
|
||||
|
||||
while (tSkipListIterNext(pIter)) {
|
||||
STable *tTable = *(STable **)SL_GET_NODE_DATA(tSkipListIterGet(pIter));
|
||||
STable *tTable = (STable *)SL_GET_NODE_DATA(tSkipListIterGet(pIter));
|
||||
ASSERT(TABLE_TYPE(tTable) == TSDB_CHILD_TABLE);
|
||||
pBuf = tsdbInsertTableAct(pRepo, TSDB_DROP_META, pBuf, tTable);
|
||||
}
|
||||
|
@ -1269,7 +1255,7 @@ static int tsdbRmTableFromMeta(STsdbRepo *pRepo, STable *pTable) {
|
|||
tsdbWLockRepoMeta(pRepo);
|
||||
|
||||
while (tSkipListIterNext(pIter)) {
|
||||
STable *tTable = *(STable **)SL_GET_NODE_DATA(tSkipListIterGet(pIter));
|
||||
STable *tTable = (STable *)SL_GET_NODE_DATA(tSkipListIterGet(pIter));
|
||||
tsdbRemoveTableFromMeta(pRepo, tTable, false, false);
|
||||
}
|
||||
|
||||
|
|
|
@ -25,6 +25,7 @@
|
|||
#define TSDB_GET_COMPCOL_LEN(nCols) (sizeof(SCompData) + sizeof(SCompCol) * (nCols) + sizeof(TSCKSUM))
|
||||
#define TSDB_KEY_COL_OFFSET 0
|
||||
#define TSDB_GET_COMPBLOCK_IDX(h, b) (POINTER_DISTANCE(b, (h)->pCompInfo->blocks)/sizeof(SCompBlock))
|
||||
#define TSDB_IS_LAST_BLOCK(pb) ((pb)->last)
|
||||
|
||||
static bool tsdbShouldCreateNewLast(SRWHelper *pHelper);
|
||||
static int tsdbWriteBlockToFile(SRWHelper *pHelper, SFile *pFile, SDataCols *pDataCols, SCompBlock *pCompBlock,
|
||||
|
@ -32,7 +33,7 @@ static int tsdbWriteBlockToFile(SRWHelper *pHelper, SFile *pFile, SDataCols *pD
|
|||
static int compareKeyBlock(const void *arg1, const void *arg2);
|
||||
static int tsdbAdjustInfoSizeIfNeeded(SRWHelper *pHelper, size_t esize);
|
||||
static int tsdbInsertSuperBlock(SRWHelper *pHelper, SCompBlock *pCompBlock, int blkIdx);
|
||||
static int tsdbAddSubBlock(SRWHelper *pHelper, SCompBlock *pCompBlock, int blkIdx, int rowsAdded);
|
||||
static int tsdbAddSubBlock(SRWHelper *pHelper, SCompBlock *pCompBlock, int blkIdx, SMergeInfo *pMergeInfo);
|
||||
static int tsdbUpdateSuperBlock(SRWHelper *pHelper, SCompBlock *pCompBlock, int blkIdx);
|
||||
static void tsdbResetHelperFileImpl(SRWHelper *pHelper);
|
||||
static int tsdbInitHelperFile(SRWHelper *pHelper);
|
||||
|
@ -59,8 +60,10 @@ static int tsdbLoadColData(SRWHelper *pHelper, SFile *pFile, SCompBlock *pComp
|
|||
static int tsdbWriteBlockToProperFile(SRWHelper *pHelper, SDataCols *pDataCols, SCompBlock *pCompBlock);
|
||||
static int tsdbProcessMergeCommit(SRWHelper *pHelper, SCommitIter *pCommitIter, SDataCols *pDataCols, TSKEY maxKey,
|
||||
int *blkIdx);
|
||||
static int tsdbLoadAndMergeFromCache(SDataCols *pDataCols, int *iter, SCommitIter *pCommitIter, SDataCols *pTarget,
|
||||
TSKEY maxKey, int maxRows);
|
||||
static void tsdbLoadAndMergeFromCache(SDataCols *pDataCols, int *iter, SCommitIter *pCommitIter, SDataCols *pTarget,
|
||||
TSKEY maxKey, int maxRows, int8_t update);
|
||||
static bool tsdbCheckAddSubBlockCond(SRWHelper *pHelper, SCompBlock *pCompBlock, SMergeInfo *pMergeInfo, int maxOps);
|
||||
static int tsdbDeleteSuperBlock(SRWHelper *pHelper, int blkIdx);
|
||||
|
||||
// ---------------------- INTERNAL FUNCTIONS ----------------------
|
||||
int tsdbInitReadHelper(SRWHelper *pHelper, STsdbRepo *pRepo) {
|
||||
|
@ -277,7 +280,7 @@ int tsdbCommitTableData(SRWHelper *pHelper, SCommitIter *pCommitIter, SDataCols
|
|||
while (true) {
|
||||
ASSERT(blkIdx <= (int)pIdx->numOfBlocks);
|
||||
TSKEY keyFirst = tsdbNextIterKey(pCommitIter->pIter);
|
||||
if (keyFirst < 0 || keyFirst > maxKey) break; // iter over
|
||||
if (keyFirst == TSDB_DATA_TIMESTAMP_NULL || keyFirst > maxKey) break; // iter over
|
||||
|
||||
if (pIdx->len <= 0 || keyFirst > pIdx->maxKey) {
|
||||
if (tsdbProcessAppendCommit(pHelper, pCommitIter, pDataCols, maxKey) < 0) return -1;
|
||||
|
@ -923,7 +926,7 @@ _err:
|
|||
return -1;
|
||||
}
|
||||
|
||||
static int tsdbAddSubBlock(SRWHelper *pHelper, SCompBlock *pCompBlock, int blkIdx, int rowsAdded) {
|
||||
static int tsdbAddSubBlock(SRWHelper *pHelper, SCompBlock *pCompBlock, int blkIdx, SMergeInfo *pMergeInfo) {
|
||||
ASSERT(pCompBlock->numOfSubBlocks == 0);
|
||||
|
||||
SCompIdx *pIdx = &(pHelper->curCompIdx);
|
||||
|
@ -956,9 +959,9 @@ static int tsdbAddSubBlock(SRWHelper *pHelper, SCompBlock *pCompBlock, int blkId
|
|||
pSCompBlock->numOfSubBlocks++;
|
||||
ASSERT(pSCompBlock->numOfSubBlocks <= TSDB_MAX_SUBBLOCKS);
|
||||
pSCompBlock->len += sizeof(SCompBlock);
|
||||
pSCompBlock->numOfRows += rowsAdded;
|
||||
pSCompBlock->keyFirst = MIN(pSCompBlock->keyFirst, pCompBlock->keyFirst);
|
||||
pSCompBlock->keyLast = MAX(pSCompBlock->keyLast, pCompBlock->keyLast);
|
||||
pSCompBlock->numOfRows = pSCompBlock->numOfRows + pMergeInfo->rowsInserted - pMergeInfo->rowsDeleteSucceed;
|
||||
pSCompBlock->keyFirst = pMergeInfo->keyFirst;
|
||||
pSCompBlock->keyLast = pMergeInfo->keyLast;
|
||||
pIdx->len += sizeof(SCompBlock);
|
||||
} else { // Need to create two sub-blocks
|
||||
void *ptr = NULL;
|
||||
|
@ -987,11 +990,11 @@ static int tsdbAddSubBlock(SRWHelper *pHelper, SCompBlock *pCompBlock, int blkId
|
|||
((SCompBlock *)ptr)[1] = *pCompBlock;
|
||||
|
||||
pSCompBlock->numOfSubBlocks = 2;
|
||||
pSCompBlock->numOfRows += rowsAdded;
|
||||
pSCompBlock->numOfRows = pSCompBlock->numOfRows + pMergeInfo->rowsInserted - pMergeInfo->rowsDeleteSucceed;
|
||||
pSCompBlock->offset = ((char *)ptr) - ((char *)pHelper->pCompInfo);
|
||||
pSCompBlock->len = sizeof(SCompBlock) * 2;
|
||||
pSCompBlock->keyFirst = MIN(((SCompBlock *)ptr)[0].keyFirst, ((SCompBlock *)ptr)[1].keyFirst);
|
||||
pSCompBlock->keyLast = MAX(((SCompBlock *)ptr)[0].keyLast, ((SCompBlock *)ptr)[1].keyLast);
|
||||
pSCompBlock->keyFirst = pMergeInfo->keyFirst;
|
||||
pSCompBlock->keyLast = pMergeInfo->keyLast;
|
||||
|
||||
pIdx->len += (sizeof(SCompBlock) * 2);
|
||||
}
|
||||
|
@ -1045,6 +1048,45 @@ static int tsdbUpdateSuperBlock(SRWHelper *pHelper, SCompBlock *pCompBlock, int
|
|||
return 0;
|
||||
}
|
||||
|
||||
static int tsdbDeleteSuperBlock(SRWHelper *pHelper, int blkIdx) {
|
||||
SCompIdx *pCompIdx = &(pHelper->curCompIdx);
|
||||
|
||||
ASSERT(pCompIdx->numOfBlocks > 0 && blkIdx < pCompIdx->numOfBlocks);
|
||||
|
||||
SCompBlock *pCompBlock= blockAtIdx(pHelper, blkIdx);
|
||||
SCompBlock compBlock = *pCompBlock;
|
||||
ASSERT(pCompBlock->numOfSubBlocks > 0 && pCompBlock->numOfSubBlocks <= TSDB_MAX_SUBBLOCKS);
|
||||
|
||||
if (pCompIdx->numOfBlocks == 1) {
|
||||
memset(pCompIdx, 0, sizeof(*pCompIdx));
|
||||
} else {
|
||||
int tsize = 0;
|
||||
|
||||
if (compBlock.numOfSubBlocks > 1) {
|
||||
tsize = (int)(pCompIdx->len - (compBlock.offset + sizeof(SCompBlock) * compBlock.numOfSubBlocks));
|
||||
|
||||
ASSERT(tsize > 0);
|
||||
memmove(POINTER_SHIFT(pHelper->pCompInfo, compBlock.offset),
|
||||
POINTER_SHIFT(pHelper->pCompInfo, compBlock.offset + sizeof(SCompBlock) * compBlock.numOfSubBlocks),
|
||||
tsize);
|
||||
|
||||
pCompIdx->len = pCompIdx->len - sizeof(SCompBlock) * compBlock.numOfSubBlocks;
|
||||
}
|
||||
|
||||
tsize = (int)(pCompIdx->len - POINTER_DISTANCE(blockAtIdx(pHelper, blkIdx + 1), pHelper->pCompInfo));
|
||||
ASSERT(tsize > 0);
|
||||
memmove((void *)blockAtIdx(pHelper, blkIdx), (void *)blockAtIdx(pHelper, blkIdx + 1), tsize);
|
||||
|
||||
pCompIdx->len -= sizeof(SCompBlock);
|
||||
|
||||
pCompIdx->numOfBlocks--;
|
||||
pCompIdx->hasLast = (uint32_t)(blockAtIdx(pHelper, pCompIdx->numOfBlocks - 1)->last);
|
||||
pCompIdx->maxKey = blockAtIdx(pHelper, pCompIdx->numOfBlocks - 1)->keyLast;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void tsdbResetHelperFileImpl(SRWHelper *pHelper) {
|
||||
pHelper->idxH.numOfIdx = 0;
|
||||
pHelper->idxH.curIdx = 0;
|
||||
|
@ -1437,51 +1479,62 @@ static void *tsdbDecodeSCompIdx(void *buf, SCompIdx *pIdx) {
|
|||
}
|
||||
|
||||
static int tsdbProcessAppendCommit(SRWHelper *pHelper, SCommitIter *pCommitIter, SDataCols *pDataCols, TSKEY maxKey) {
|
||||
STsdbCfg * pCfg = &(pHelper->pRepo->config);
|
||||
STable * pTable = pCommitIter->pTable;
|
||||
SCompIdx * pIdx = &(pHelper->curCompIdx);
|
||||
TSKEY keyFirst = tsdbNextIterKey(pCommitIter->pIter);
|
||||
int defaultRowsInBlock = pCfg->maxRowsPerFileBlock * 4 / 5;
|
||||
SCompBlock compBlock = {0};
|
||||
STsdbCfg * pCfg = &(pHelper->pRepo->config);
|
||||
STable * pTable = pCommitIter->pTable;
|
||||
SCompIdx * pIdx = &(pHelper->curCompIdx);
|
||||
TSKEY keyFirst = tsdbNextIterKey(pCommitIter->pIter);
|
||||
int defaultRowsInBlock = pCfg->maxRowsPerFileBlock * 4 / 5;
|
||||
SCompBlock compBlock = {0};
|
||||
SMergeInfo mergeInfo = {0};
|
||||
SMergeInfo *pMergeInfo = &mergeInfo;
|
||||
|
||||
ASSERT(pIdx->len <= 0 || keyFirst > pIdx->maxKey);
|
||||
if (pIdx->hasLast) { // append to with last block
|
||||
ASSERT(pIdx->len > 0);
|
||||
SCompBlock *pCompBlock = blockAtIdx(pHelper, pIdx->numOfBlocks - 1);
|
||||
ASSERT(pCompBlock->last && pCompBlock->numOfRows < pCfg->minRowsPerFileBlock);
|
||||
tdResetDataCols(pDataCols);
|
||||
int rowsRead = tsdbLoadDataFromCache(pTable, pCommitIter->pIter, maxKey, defaultRowsInBlock - pCompBlock->numOfRows,
|
||||
pDataCols, NULL, 0);
|
||||
ASSERT(rowsRead > 0 && rowsRead == pDataCols->numOfRows);
|
||||
if (rowsRead + pCompBlock->numOfRows < pCfg->minRowsPerFileBlock &&
|
||||
pCompBlock->numOfSubBlocks < TSDB_MAX_SUBBLOCKS && !TSDB_NLAST_FILE_OPENED(pHelper)) {
|
||||
if (tsdbWriteBlockToFile(pHelper, helperLastF(pHelper), pDataCols, &compBlock, true, false) < 0) return -1;
|
||||
if (tsdbAddSubBlock(pHelper, &compBlock, pIdx->numOfBlocks - 1, rowsRead) < 0) return -1;
|
||||
} else {
|
||||
if (tsdbLoadBlockData(pHelper, pCompBlock, NULL) < 0) return -1;
|
||||
ASSERT(pHelper->pDataCols[0]->numOfRows == pCompBlock->numOfRows);
|
||||
tsdbLoadDataFromCache(pTable, pCommitIter->pIter, maxKey, defaultRowsInBlock - pCompBlock->numOfRows, pDataCols,
|
||||
NULL, 0, pCfg->update, pMergeInfo);
|
||||
|
||||
if (tdMergeDataCols(pHelper->pDataCols[0], pDataCols, pDataCols->numOfRows) < 0) return -1;
|
||||
ASSERT(pHelper->pDataCols[0]->numOfRows == pCompBlock->numOfRows + pDataCols->numOfRows);
|
||||
ASSERT(pMergeInfo->rowsInserted == pMergeInfo->nOperations && pMergeInfo->nOperations == pDataCols->numOfRows);
|
||||
|
||||
if (tsdbWriteBlockToProperFile(pHelper, pHelper->pDataCols[0], &compBlock) < 0) return -1;
|
||||
if (tsdbUpdateSuperBlock(pHelper, &compBlock, pIdx->numOfBlocks - 1) < 0) return -1;
|
||||
if (pDataCols->numOfRows > 0) {
|
||||
ASSERT((pMergeInfo->keyFirst == dataColsKeyFirst(pDataCols)) && (pMergeInfo->keyLast == dataColsKeyLast(pDataCols)));
|
||||
|
||||
if (pDataCols->numOfRows + pCompBlock->numOfRows < pCfg->minRowsPerFileBlock &&
|
||||
pCompBlock->numOfSubBlocks < TSDB_MAX_SUBBLOCKS && !TSDB_NLAST_FILE_OPENED(pHelper)) {
|
||||
if (tsdbWriteBlockToFile(pHelper, helperLastF(pHelper), pDataCols, &compBlock, true, false) < 0) return -1;
|
||||
pMergeInfo->keyFirst = MIN(pMergeInfo->keyFirst, pCompBlock->keyFirst);
|
||||
pMergeInfo->keyLast = MAX(pMergeInfo->keyLast, pCompBlock->keyLast);
|
||||
if (tsdbAddSubBlock(pHelper, &compBlock, pIdx->numOfBlocks - 1, pMergeInfo) < 0) return -1;
|
||||
} else {
|
||||
if (tsdbLoadBlockData(pHelper, pCompBlock, NULL) < 0) return -1;
|
||||
ASSERT(pHelper->pDataCols[0]->numOfRows == pCompBlock->numOfRows);
|
||||
|
||||
if (tdMergeDataCols(pHelper->pDataCols[0], pDataCols, pDataCols->numOfRows) < 0) return -1;
|
||||
ASSERT(pHelper->pDataCols[0]->numOfRows == pCompBlock->numOfRows + pDataCols->numOfRows);
|
||||
|
||||
if (tsdbWriteBlockToProperFile(pHelper, pHelper->pDataCols[0], &compBlock) < 0) return -1;
|
||||
if (tsdbUpdateSuperBlock(pHelper, &compBlock, pIdx->numOfBlocks - 1) < 0) return -1;
|
||||
}
|
||||
|
||||
if (pHelper->hasOldLastBlock) pHelper->hasOldLastBlock = false;
|
||||
}
|
||||
|
||||
if (pHelper->hasOldLastBlock) pHelper->hasOldLastBlock = false;
|
||||
} else {
|
||||
ASSERT(!pHelper->hasOldLastBlock);
|
||||
tdResetDataCols(pDataCols);
|
||||
int rowsRead = tsdbLoadDataFromCache(pTable, pCommitIter->pIter, maxKey, defaultRowsInBlock, pDataCols, NULL, 0);
|
||||
ASSERT(rowsRead > 0 && rowsRead == pDataCols->numOfRows);
|
||||
tsdbLoadDataFromCache(pTable, pCommitIter->pIter, maxKey, defaultRowsInBlock, pDataCols, NULL, 0, pCfg->update, pMergeInfo);
|
||||
ASSERT(pMergeInfo->rowsInserted == pMergeInfo->nOperations && pMergeInfo->nOperations == pDataCols->numOfRows);
|
||||
|
||||
if (tsdbWriteBlockToProperFile(pHelper, pDataCols, &compBlock) < 0) return -1;
|
||||
if (tsdbInsertSuperBlock(pHelper, &compBlock, pIdx->numOfBlocks) < 0) return -1;
|
||||
if (pDataCols->numOfRows > 0) {
|
||||
ASSERT((pMergeInfo->keyFirst == dataColsKeyFirst(pDataCols)) && (pMergeInfo->keyLast == dataColsKeyLast(pDataCols)));
|
||||
if (tsdbWriteBlockToProperFile(pHelper, pDataCols, &compBlock) < 0) return -1;
|
||||
if (tsdbInsertSuperBlock(pHelper, &compBlock, pIdx->numOfBlocks) < 0) return -1;
|
||||
}
|
||||
}
|
||||
|
||||
#ifndef NDEBUG
|
||||
TSKEY keyNext = tsdbNextIterKey(pCommitIter->pIter);
|
||||
ASSERT(keyNext < 0 || keyNext > pIdx->maxKey);
|
||||
ASSERT(keyNext == TSDB_DATA_TIMESTAMP_NULL || keyNext > pIdx->maxKey);
|
||||
#endif
|
||||
|
||||
return 0;
|
||||
|
@ -1489,13 +1542,16 @@ static int tsdbProcessAppendCommit(SRWHelper *pHelper, SCommitIter *pCommitIter,
|
|||
|
||||
static int tsdbProcessMergeCommit(SRWHelper *pHelper, SCommitIter *pCommitIter, SDataCols *pDataCols, TSKEY maxKey,
|
||||
int *blkIdx) {
|
||||
STsdbCfg * pCfg = &(pHelper->pRepo->config);
|
||||
STable * pTable = pCommitIter->pTable;
|
||||
SCompIdx * pIdx = &(pHelper->curCompIdx);
|
||||
SCompBlock compBlock = {0};
|
||||
TSKEY keyFirst = tsdbNextIterKey(pCommitIter->pIter);
|
||||
int defaultRowsInBlock = pCfg->maxRowsPerFileBlock * 4 / 5;
|
||||
SDataCols *pDataCols0 = pHelper->pDataCols[0];
|
||||
STsdbCfg * pCfg = &(pHelper->pRepo->config);
|
||||
STable * pTable = pCommitIter->pTable;
|
||||
SCompIdx * pIdx = &(pHelper->curCompIdx);
|
||||
SCompBlock compBlock = {0};
|
||||
TSKEY keyFirst = tsdbNextIterKey(pCommitIter->pIter);
|
||||
int defaultRowsInBlock = pCfg->maxRowsPerFileBlock * 4 / 5;
|
||||
SDataCols * pDataCols0 = pHelper->pDataCols[0];
|
||||
SMergeInfo mergeInfo = {0};
|
||||
SMergeInfo *pMergeInfo = &mergeInfo;
|
||||
SCompBlock oBlock = {0};
|
||||
|
||||
SSkipListIterator slIter = {0};
|
||||
|
||||
|
@ -1505,123 +1561,82 @@ static int tsdbProcessMergeCommit(SRWHelper *pHelper, SCommitIter *pCommitIter,
|
|||
pIdx->numOfBlocks - *blkIdx, sizeof(SCompBlock), compareKeyBlock, TD_GE);
|
||||
ASSERT(pCompBlock != NULL);
|
||||
int tblkIdx = (int32_t)(TSDB_GET_COMPBLOCK_IDX(pHelper, pCompBlock));
|
||||
oBlock = *pCompBlock;
|
||||
|
||||
if (pCompBlock->last) {
|
||||
ASSERT(pCompBlock->numOfRows < pCfg->minRowsPerFileBlock && tblkIdx == pIdx->numOfBlocks - 1);
|
||||
int16_t colId = 0;
|
||||
slIter = *(pCommitIter->pIter);
|
||||
if (tsdbLoadBlockDataCols(pHelper, pCompBlock, NULL, &colId, 1) < 0) return -1;
|
||||
ASSERT(pDataCols0->numOfRows == pCompBlock->numOfRows);
|
||||
ASSERT((!TSDB_IS_LAST_BLOCK(&oBlock)) || (tblkIdx == pIdx->numOfBlocks - 1));
|
||||
|
||||
int rows1 = defaultRowsInBlock - pCompBlock->numOfRows;
|
||||
int rows2 =
|
||||
tsdbLoadDataFromCache(pTable, &slIter, maxKey, rows1, NULL, pDataCols0->cols[0].pData, pDataCols0->numOfRows);
|
||||
if (rows2 == 0) { // all data filtered out
|
||||
*(pCommitIter->pIter) = slIter;
|
||||
} else {
|
||||
if (pCompBlock->numOfRows + rows2 < pCfg->minRowsPerFileBlock &&
|
||||
pCompBlock->numOfSubBlocks < TSDB_MAX_SUBBLOCKS && !TSDB_NLAST_FILE_OPENED(pHelper)) {
|
||||
tdResetDataCols(pDataCols);
|
||||
int rowsRead = tsdbLoadDataFromCache(pTable, pCommitIter->pIter, maxKey, rows1, pDataCols,
|
||||
pDataCols0->cols[0].pData, pDataCols0->numOfRows);
|
||||
ASSERT(rowsRead == rows2 && rowsRead == pDataCols->numOfRows);
|
||||
if (tsdbWriteBlockToFile(pHelper, helperLastF(pHelper), pDataCols, &compBlock, true, false) < 0) return -1;
|
||||
if (tsdbAddSubBlock(pHelper, &compBlock, tblkIdx, rowsRead) < 0) return -1;
|
||||
tblkIdx++;
|
||||
} else {
|
||||
if (tsdbLoadBlockData(pHelper, pCompBlock, NULL) < 0) return -1;
|
||||
int round = 0;
|
||||
int dIter = 0;
|
||||
while (true) {
|
||||
tdResetDataCols(pDataCols);
|
||||
int rowsRead =
|
||||
tsdbLoadAndMergeFromCache(pDataCols0, &dIter, pCommitIter, pDataCols, maxKey, defaultRowsInBlock);
|
||||
if (rowsRead == 0) break;
|
||||
if ((!TSDB_IS_LAST_BLOCK(&oBlock)) && keyFirst < pCompBlock->keyFirst) {
|
||||
while (true) {
|
||||
tsdbLoadDataFromCache(pTable, pCommitIter->pIter, oBlock.keyFirst-1, defaultRowsInBlock, pDataCols, NULL, 0,
|
||||
pCfg->update, pMergeInfo);
|
||||
ASSERT(pMergeInfo->rowsInserted == pMergeInfo->nOperations && pMergeInfo->nOperations == pDataCols->numOfRows);
|
||||
if (pDataCols->numOfRows == 0) break;
|
||||
|
||||
if (tsdbWriteBlockToProperFile(pHelper, pDataCols, &compBlock) < 0) return -1;
|
||||
if (round == 0) {
|
||||
if (tsdbUpdateSuperBlock(pHelper, &compBlock, tblkIdx) < 0) return -1;
|
||||
} else {
|
||||
if (tsdbInsertSuperBlock(pHelper, &compBlock, tblkIdx) < 0) return -1;
|
||||
}
|
||||
|
||||
tblkIdx++;
|
||||
round++;
|
||||
}
|
||||
}
|
||||
if (pHelper->hasOldLastBlock) pHelper->hasOldLastBlock = false;
|
||||
if (tsdbWriteBlockToFile(pHelper, helperDataF(pHelper), pDataCols, &compBlock, false, true) < 0) return -1;
|
||||
if (tsdbInsertSuperBlock(pHelper, &compBlock, tblkIdx) < 0) return -1;
|
||||
tblkIdx++;
|
||||
}
|
||||
ASSERT(tblkIdx == 0 || (tsdbNextIterKey(pCommitIter->pIter) == TSDB_DATA_TIMESTAMP_NULL ||
|
||||
tsdbNextIterKey(pCommitIter->pIter) > blockAtIdx(pHelper, tblkIdx - 1)->keyLast));
|
||||
} else {
|
||||
TSKEY keyLimit = (tblkIdx == pIdx->numOfBlocks - 1) ? maxKey : (pCompBlock[1].keyFirst - 1);
|
||||
TSKEY blkKeyFirst = pCompBlock->keyFirst;
|
||||
TSKEY blkKeyLast = pCompBlock->keyLast;
|
||||
int16_t colId = 0;
|
||||
if (tsdbLoadBlockDataCols(pHelper, &oBlock, NULL, &colId, 1) < 0) return -1;
|
||||
|
||||
if (keyFirst < blkKeyFirst) {
|
||||
while (true) {
|
||||
tdResetDataCols(pDataCols);
|
||||
int rowsRead =
|
||||
tsdbLoadDataFromCache(pTable, pCommitIter->pIter, blkKeyFirst - 1, defaultRowsInBlock, pDataCols, NULL, 0);
|
||||
if (rowsRead == 0) break;
|
||||
TSKEY keyLimit = (tblkIdx == pIdx->numOfBlocks - 1) ? maxKey : (blockAtIdx(pHelper, tblkIdx + 1)->keyFirst - 1);
|
||||
|
||||
ASSERT(rowsRead == pDataCols->numOfRows);
|
||||
if (tsdbWriteBlockToFile(pHelper, helperDataF(pHelper), pDataCols, &compBlock, false, true) < 0) return -1;
|
||||
if (tsdbInsertSuperBlock(pHelper, &compBlock, tblkIdx) < 0) return -1;
|
||||
tblkIdx++;
|
||||
slIter = *(pCommitIter->pIter);
|
||||
tsdbLoadDataFromCache(pTable, &slIter, keyLimit, INT_MAX, NULL, pDataCols0->cols[0].pData, pDataCols0->numOfRows,
|
||||
pCfg->update, pMergeInfo);
|
||||
|
||||
if (pMergeInfo->nOperations == 0) {
|
||||
// Do nothing
|
||||
ASSERT(pMergeInfo->rowsDeleteFailed >= 0);
|
||||
*(pCommitIter->pIter) = slIter;
|
||||
tblkIdx++;
|
||||
} else if (oBlock.numOfRows + pMergeInfo->rowsInserted - pMergeInfo->rowsDeleteSucceed == 0) {
|
||||
// Delete the block and do some stuff
|
||||
ASSERT(pMergeInfo->keyFirst == INT64_MAX && pMergeInfo->keyFirst == INT64_MIN);
|
||||
if (tsdbDeleteSuperBlock(pHelper, tblkIdx) < 0) return -1;
|
||||
*pCommitIter->pIter = slIter;
|
||||
if (oBlock.last && pHelper->hasOldLastBlock) pHelper->hasOldLastBlock = false;
|
||||
} else if (tsdbCheckAddSubBlockCond(pHelper, &oBlock, pMergeInfo, pDataCols->maxPoints)) {
|
||||
// Append as a sub-block of the searched block
|
||||
tsdbLoadDataFromCache(pTable, pCommitIter->pIter, keyLimit, INT_MAX, pDataCols, pDataCols0->cols[0].pData,
|
||||
pDataCols0->numOfRows, pCfg->update, pMergeInfo);
|
||||
ASSERT(memcmp(pCommitIter->pIter, &slIter, sizeof(slIter)) == 0);
|
||||
if (tsdbWriteBlockToFile(pHelper, oBlock.last ? helperLastF(pHelper) : helperDataF(pHelper), pDataCols,
|
||||
&compBlock, oBlock.last, false) < 0) {
|
||||
return -1;
|
||||
}
|
||||
ASSERT(tblkIdx == 0 || (tsdbNextIterKey(pCommitIter->pIter) < 0 ||
|
||||
tsdbNextIterKey(pCommitIter->pIter) > blockAtIdx(pHelper, tblkIdx - 1)->keyLast));
|
||||
if (tsdbAddSubBlock(pHelper, &compBlock, tblkIdx, pMergeInfo) < 0) {
|
||||
return -1;
|
||||
}
|
||||
tblkIdx++;
|
||||
} else {
|
||||
ASSERT(keyFirst <= blkKeyLast);
|
||||
int16_t colId = 0;
|
||||
if (tsdbLoadBlockDataCols(pHelper, pCompBlock, NULL, &colId, 1) < 0) return -1;
|
||||
// load the block data, merge with the memory data
|
||||
if (tsdbLoadBlockData(pHelper, &oBlock, NULL) < 0) return -1;
|
||||
int round = 0;
|
||||
int dIter = 0;
|
||||
while (true) {
|
||||
tsdbLoadAndMergeFromCache(pDataCols0, &dIter, pCommitIter, pDataCols, keyLimit, defaultRowsInBlock,
|
||||
pCfg->update);
|
||||
|
||||
slIter = *(pCommitIter->pIter);
|
||||
int rows1 = (pCfg->maxRowsPerFileBlock - pCompBlock->numOfRows);
|
||||
int rows2 = tsdbLoadDataFromCache(pTable, &slIter, blkKeyLast, INT_MAX, NULL, pDataCols0->cols[0].pData,
|
||||
pDataCols0->numOfRows);
|
||||
|
||||
if (rows2 == 0) { // all filtered out
|
||||
*(pCommitIter->pIter) = slIter;
|
||||
ASSERT(tblkIdx == 0 || (tsdbNextIterKey(pCommitIter->pIter) < 0 ||
|
||||
tsdbNextIterKey(pCommitIter->pIter) > blockAtIdx(pHelper, tblkIdx - 1)->keyLast));
|
||||
} else {
|
||||
int rows3 = tsdbLoadDataFromCache(pTable, &slIter, keyLimit, INT_MAX, NULL, NULL, 0) + rows2;
|
||||
|
||||
if (pCompBlock->numOfSubBlocks < TSDB_MAX_SUBBLOCKS && rows1 >= rows2) {
|
||||
int rows = (rows1 >= rows3) ? rows3 : rows2;
|
||||
tdResetDataCols(pDataCols);
|
||||
int rowsRead = tsdbLoadDataFromCache(pTable, pCommitIter->pIter, keyLimit, rows, pDataCols,
|
||||
pDataCols0->cols[0].pData, pDataCols0->numOfRows);
|
||||
ASSERT(rowsRead == rows && rowsRead == pDataCols->numOfRows);
|
||||
if (tsdbWriteBlockToFile(pHelper, helperDataF(pHelper), pDataCols, &compBlock, false, false) < 0)
|
||||
return -1;
|
||||
if (tsdbAddSubBlock(pHelper, &compBlock, tblkIdx, rowsRead) < 0) return -1;
|
||||
tblkIdx++;
|
||||
ASSERT(tblkIdx == 0 || (tsdbNextIterKey(pCommitIter->pIter) < 0 ||
|
||||
tsdbNextIterKey(pCommitIter->pIter) > blockAtIdx(pHelper, tblkIdx - 1)->keyLast));
|
||||
if (pDataCols->numOfRows == 0) break;
|
||||
if (tblkIdx == pIdx->numOfBlocks - 1) {
|
||||
if (tsdbWriteBlockToProperFile(pHelper, pDataCols, &compBlock) < 0) return -1;
|
||||
} else {
|
||||
if (tsdbLoadBlockData(pHelper, pCompBlock, NULL) < 0) return -1;
|
||||
int round = 0;
|
||||
int dIter = 0;
|
||||
while (true) {
|
||||
int rowsRead =
|
||||
tsdbLoadAndMergeFromCache(pDataCols0, &dIter, pCommitIter, pDataCols, keyLimit, defaultRowsInBlock);
|
||||
if (rowsRead == 0) break;
|
||||
|
||||
if (tsdbWriteBlockToFile(pHelper, helperDataF(pHelper), pDataCols, &compBlock, false, true) < 0)
|
||||
return -1;
|
||||
if (round == 0) {
|
||||
if (tsdbUpdateSuperBlock(pHelper, &compBlock, tblkIdx) < 0) return -1;
|
||||
} else {
|
||||
if (tsdbInsertSuperBlock(pHelper, &compBlock, tblkIdx) < 0) return -1;
|
||||
}
|
||||
|
||||
round++;
|
||||
tblkIdx++;
|
||||
}
|
||||
ASSERT(tblkIdx == 0 || (tsdbNextIterKey(pCommitIter->pIter) < 0 ||
|
||||
tsdbNextIterKey(pCommitIter->pIter) > blockAtIdx(pHelper, tblkIdx - 1)->keyLast));
|
||||
if (tsdbWriteBlockToFile(pHelper, helperDataF(pHelper), pDataCols, &compBlock, false, true) < 0) return -1;
|
||||
}
|
||||
|
||||
if (round == 0) {
|
||||
if (oBlock.last && pHelper->hasOldLastBlock) pHelper->hasOldLastBlock = false;
|
||||
if (tsdbUpdateSuperBlock(pHelper, &compBlock, tblkIdx) < 0) return -1;
|
||||
} else {
|
||||
if (tsdbInsertSuperBlock(pHelper, &compBlock, tblkIdx) < 0) return -1;
|
||||
}
|
||||
|
||||
round++;
|
||||
tblkIdx++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1630,9 +1645,8 @@ static int tsdbProcessMergeCommit(SRWHelper *pHelper, SCommitIter *pCommitIter,
|
|||
return 0;
|
||||
}
|
||||
|
||||
static int tsdbLoadAndMergeFromCache(SDataCols *pDataCols, int *iter, SCommitIter *pCommitIter, SDataCols *pTarget,
|
||||
TSKEY maxKey, int maxRows) {
|
||||
int numOfRows = 0;
|
||||
static void tsdbLoadAndMergeFromCache(SDataCols *pDataCols, int *iter, SCommitIter *pCommitIter, SDataCols *pTarget,
|
||||
TSKEY maxKey, int maxRows, int8_t update) {
|
||||
TSKEY key1 = INT64_MAX;
|
||||
TSKEY key2 = INT64_MAX;
|
||||
STSchema *pSchema = NULL;
|
||||
|
@ -1642,35 +1656,62 @@ static int tsdbLoadAndMergeFromCache(SDataCols *pDataCols, int *iter, SCommitIte
|
|||
|
||||
while (true) {
|
||||
key1 = (*iter >= pDataCols->numOfRows) ? INT64_MAX : dataColsKeyAt(pDataCols, *iter);
|
||||
bool isRowDel = false;
|
||||
SDataRow row = tsdbNextIterRow(pCommitIter->pIter);
|
||||
key2 = (row == NULL || dataRowKey(row) > maxKey) ? INT64_MAX : dataRowKey(row);
|
||||
if (row == NULL || dataRowKey(row) > maxKey) {
|
||||
key2 = INT64_MAX;
|
||||
} else {
|
||||
key2 = dataRowKey(row);
|
||||
isRowDel = dataRowDeleted(row);
|
||||
}
|
||||
|
||||
if (key1 == INT64_MAX && key2 == INT64_MAX) break;
|
||||
|
||||
if (key1 <= key2) {
|
||||
if (key1 < key2) {
|
||||
for (int i = 0; i < pDataCols->numOfCols; i++) {
|
||||
dataColAppendVal(pTarget->cols + i, tdGetColDataOfRow(pDataCols->cols + i, *iter), pTarget->numOfRows,
|
||||
pTarget->maxPoints);
|
||||
}
|
||||
|
||||
pTarget->numOfRows++;
|
||||
(*iter)++;
|
||||
if (key1 == key2) tSkipListIterNext(pCommitIter->pIter);
|
||||
} else {
|
||||
if (pSchema == NULL || schemaVersion(pSchema) != dataRowVersion(row)) {
|
||||
pSchema = tsdbGetTableSchemaImpl(pCommitIter->pTable, false, false, dataRowVersion(row));
|
||||
ASSERT(pSchema != NULL);
|
||||
} else if (key1 > key2) {
|
||||
if (!isRowDel) {
|
||||
if (pSchema == NULL || schemaVersion(pSchema) != dataRowVersion(row)) {
|
||||
pSchema = tsdbGetTableSchemaImpl(pCommitIter->pTable, false, false, dataRowVersion(row));
|
||||
ASSERT(pSchema != NULL);
|
||||
}
|
||||
|
||||
tdAppendDataRowToDataCol(row, pSchema, pTarget);
|
||||
}
|
||||
|
||||
tdAppendDataRowToDataCol(row, pSchema, pTarget);
|
||||
tSkipListIterNext(pCommitIter->pIter);
|
||||
} else {
|
||||
if (update) {
|
||||
if (!isRowDel) {
|
||||
if (pSchema == NULL || schemaVersion(pSchema) != dataRowVersion(row)) {
|
||||
pSchema = tsdbGetTableSchemaImpl(pCommitIter->pTable, false, false, dataRowVersion(row));
|
||||
ASSERT(pSchema != NULL);
|
||||
}
|
||||
|
||||
tdAppendDataRowToDataCol(row, pSchema, pTarget);
|
||||
}
|
||||
} else {
|
||||
ASSERT(!isRowDel);
|
||||
|
||||
for (int i = 0; i < pDataCols->numOfCols; i++) {
|
||||
dataColAppendVal(pTarget->cols + i, tdGetColDataOfRow(pDataCols->cols + i, *iter), pTarget->numOfRows,
|
||||
pTarget->maxPoints);
|
||||
}
|
||||
|
||||
pTarget->numOfRows++;
|
||||
}
|
||||
(*iter)++;
|
||||
tSkipListIterNext(pCommitIter->pIter);
|
||||
}
|
||||
|
||||
numOfRows++;
|
||||
if (numOfRows >= maxRows) break;
|
||||
ASSERT(numOfRows == pTarget->numOfRows && numOfRows <= pTarget->maxPoints);
|
||||
if (pTarget->numOfRows >= maxRows) break;
|
||||
}
|
||||
|
||||
return numOfRows;
|
||||
}
|
||||
|
||||
static int tsdbWriteBlockToProperFile(SRWHelper *pHelper, SDataCols *pDataCols, SCompBlock *pCompBlock) {
|
||||
|
@ -1693,3 +1734,20 @@ static int tsdbWriteBlockToProperFile(SRWHelper *pHelper, SDataCols *pDataCols,
|
|||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static bool tsdbCheckAddSubBlockCond(SRWHelper *pHelper, SCompBlock *pCompBlock, SMergeInfo *pMergeInfo, int maxOps) {
|
||||
STsdbCfg *pCfg = &(pHelper->pRepo->config);
|
||||
int mergeRows = pCompBlock->numOfRows + pMergeInfo->rowsInserted - pMergeInfo->rowsDeleteSucceed;
|
||||
|
||||
ASSERT(mergeRows > 0);
|
||||
|
||||
if (pCompBlock->numOfSubBlocks < TSDB_MAX_SUBBLOCKS && pMergeInfo->nOperations <= maxOps) {
|
||||
if (pCompBlock->last) {
|
||||
if (!TSDB_NLAST_FILE_OPENED(pHelper) && mergeRows < pCfg->minRowsPerFileBlock) return true;
|
||||
} else {
|
||||
if (mergeRows < pCfg->maxRowsPerFileBlock) return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
|
@ -457,7 +457,7 @@ static bool initTableMemIterator(STsdbQueryHandle* pHandle, STableCheckInfo* pCh
|
|||
SSkipListNode* node = tSkipListIterGet(pCheckInfo->iter);
|
||||
assert(node != NULL);
|
||||
|
||||
SDataRow row = *(SDataRow *)SL_GET_NODE_DATA(node);
|
||||
SDataRow row = (SDataRow)SL_GET_NODE_DATA(node);
|
||||
TSKEY key = dataRowKey(row); // first timestamp in buffer
|
||||
tsdbDebug("%p uid:%" PRId64 ", tid:%d check data in mem from skey:%" PRId64 ", order:%d, ts range in buf:%" PRId64
|
||||
"-%" PRId64 ", lastKey:%" PRId64 ", numOfRows:%"PRId64", %p",
|
||||
|
@ -479,7 +479,7 @@ static bool initTableMemIterator(STsdbQueryHandle* pHandle, STableCheckInfo* pCh
|
|||
SSkipListNode* node = tSkipListIterGet(pCheckInfo->iiter);
|
||||
assert(node != NULL);
|
||||
|
||||
SDataRow row = *(SDataRow *)SL_GET_NODE_DATA(node);
|
||||
SDataRow row = (SDataRow)SL_GET_NODE_DATA(node);
|
||||
TSKEY key = dataRowKey(row); // first timestamp in buffer
|
||||
tsdbDebug("%p uid:%" PRId64 ", tid:%d check data in imem from skey:%" PRId64 ", order:%d, ts range in buf:%" PRId64
|
||||
"-%" PRId64 ", lastKey:%" PRId64 ", numOfRows:%"PRId64", %p",
|
||||
|
@ -504,19 +504,19 @@ static void destroyTableMemIterator(STableCheckInfo* pCheckInfo) {
|
|||
tSkipListDestroyIter(pCheckInfo->iiter);
|
||||
}
|
||||
|
||||
static SDataRow getSDataRowInTableMem(STableCheckInfo* pCheckInfo, int32_t order) {
|
||||
static SDataRow getSDataRowInTableMem(STableCheckInfo* pCheckInfo, int32_t order, int32_t update) {
|
||||
SDataRow rmem = NULL, rimem = NULL;
|
||||
if (pCheckInfo->iter) {
|
||||
SSkipListNode* node = tSkipListIterGet(pCheckInfo->iter);
|
||||
if (node != NULL) {
|
||||
rmem = *(SDataRow *)SL_GET_NODE_DATA(node);
|
||||
rmem = (SDataRow)SL_GET_NODE_DATA(node);
|
||||
}
|
||||
}
|
||||
|
||||
if (pCheckInfo->iiter) {
|
||||
SSkipListNode* node = tSkipListIterGet(pCheckInfo->iiter);
|
||||
if (node != NULL) {
|
||||
rimem = *(SDataRow *)SL_GET_NODE_DATA(node);
|
||||
rimem = (SDataRow)SL_GET_NODE_DATA(node);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -538,9 +538,15 @@ static SDataRow getSDataRowInTableMem(STableCheckInfo* pCheckInfo, int32_t order
|
|||
TSKEY r2 = dataRowKey(rimem);
|
||||
|
||||
if (r1 == r2) { // data ts are duplicated, ignore the data in mem
|
||||
tSkipListIterNext(pCheckInfo->iter);
|
||||
pCheckInfo->chosen = 1;
|
||||
return rimem;
|
||||
if (!update) {
|
||||
tSkipListIterNext(pCheckInfo->iter);
|
||||
pCheckInfo->chosen = 1;
|
||||
return rimem;
|
||||
} else {
|
||||
tSkipListIterNext(pCheckInfo->iiter);
|
||||
pCheckInfo->chosen = 0;
|
||||
return rmem;
|
||||
}
|
||||
} else {
|
||||
if (ASCENDING_TRAVERSE(order)) {
|
||||
if (r1 < r2) {
|
||||
|
@ -594,6 +600,7 @@ static bool moveToNextRowInMem(STableCheckInfo* pCheckInfo) {
|
|||
}
|
||||
|
||||
static bool hasMoreDataInCache(STsdbQueryHandle* pHandle) {
|
||||
STsdbCfg *pCfg = &pHandle->pTsdb->config;
|
||||
size_t size = taosArrayGetSize(pHandle->pTableCheckInfo);
|
||||
assert(pHandle->activeIndex < size && pHandle->activeIndex >= 0 && size >= 1);
|
||||
pHandle->cur.fid = -1;
|
||||
|
@ -607,7 +614,7 @@ static bool hasMoreDataInCache(STsdbQueryHandle* pHandle) {
|
|||
initTableMemIterator(pHandle, pCheckInfo);
|
||||
}
|
||||
|
||||
SDataRow row = getSDataRowInTableMem(pCheckInfo, pHandle->order);
|
||||
SDataRow row = getSDataRowInTableMem(pCheckInfo, pHandle->order, pCfg->update);
|
||||
if (row == NULL) {
|
||||
return false;
|
||||
}
|
||||
|
@ -827,11 +834,12 @@ static void copyAllRemainRowsFromFileBlock(STsdbQueryHandle* pQueryHandle, STabl
|
|||
|
||||
static int32_t handleDataMergeIfNeeded(STsdbQueryHandle* pQueryHandle, SCompBlock* pBlock, STableCheckInfo* pCheckInfo){
|
||||
SQueryFilePos* cur = &pQueryHandle->cur;
|
||||
STsdbCfg* pCfg = &pQueryHandle->pTsdb->config;
|
||||
SDataBlockInfo binfo = GET_FILE_DATA_BLOCK_INFO(pCheckInfo, pBlock);
|
||||
int32_t code = TSDB_CODE_SUCCESS;
|
||||
|
||||
/*bool hasData = */ initTableMemIterator(pQueryHandle, pCheckInfo);
|
||||
SDataRow row = getSDataRowInTableMem(pCheckInfo, pQueryHandle->order);
|
||||
SDataRow row = getSDataRowInTableMem(pCheckInfo, pQueryHandle->order, pCfg->update);
|
||||
|
||||
assert(cur->pos >= 0 && cur->pos <= binfo.rows);
|
||||
|
||||
|
@ -1316,6 +1324,7 @@ int32_t getEndPosInDataBlock(STsdbQueryHandle* pQueryHandle, SDataBlockInfo* pBl
|
|||
static void doMergeTwoLevelData(STsdbQueryHandle* pQueryHandle, STableCheckInfo* pCheckInfo, SCompBlock* pBlock) {
|
||||
SQueryFilePos* cur = &pQueryHandle->cur;
|
||||
SDataBlockInfo blockInfo = GET_FILE_DATA_BLOCK_INFO(pCheckInfo, pBlock);
|
||||
STsdbCfg* pCfg = &pQueryHandle->pTsdb->config;
|
||||
|
||||
initTableMemIterator(pQueryHandle, pCheckInfo);
|
||||
|
||||
|
@ -1353,7 +1362,7 @@ static void doMergeTwoLevelData(STsdbQueryHandle* pQueryHandle, STableCheckInfo*
|
|||
} else if (pCheckInfo->iter != NULL || pCheckInfo->iiter != NULL) {
|
||||
SSkipListNode* node = NULL;
|
||||
do {
|
||||
SDataRow row = getSDataRowInTableMem(pCheckInfo, pQueryHandle->order);
|
||||
SDataRow row = getSDataRowInTableMem(pCheckInfo, pQueryHandle->order, pCfg->update);
|
||||
if (row == NULL) {
|
||||
break;
|
||||
}
|
||||
|
@ -1383,7 +1392,22 @@ static void doMergeTwoLevelData(STsdbQueryHandle* pQueryHandle, STableCheckInfo*
|
|||
|
||||
moveToNextRowInMem(pCheckInfo);
|
||||
} else if (key == tsArray[pos]) { // data in buffer has the same timestamp of data in file block, ignore it
|
||||
moveToNextRowInMem(pCheckInfo);
|
||||
if (pCfg->update) {
|
||||
copyOneRowFromMem(pQueryHandle, pQueryHandle->outputCapacity, numOfRows, row, numOfCols, pTable);
|
||||
numOfRows += 1;
|
||||
if (cur->win.skey == TSKEY_INITIAL_VAL) {
|
||||
cur->win.skey = key;
|
||||
}
|
||||
|
||||
cur->win.ekey = key;
|
||||
cur->lastKey = key + step;
|
||||
cur->mixBlock = true;
|
||||
|
||||
moveToNextRowInMem(pCheckInfo);
|
||||
pos += step;
|
||||
} else {
|
||||
moveToNextRowInMem(pCheckInfo);
|
||||
}
|
||||
} else if ((key > tsArray[pos] && ASCENDING_TRAVERSE(pQueryHandle->order)) ||
|
||||
(key < tsArray[pos] && !ASCENDING_TRAVERSE(pQueryHandle->order))) {
|
||||
if (cur->win.skey == TSKEY_INITIAL_VAL) {
|
||||
|
@ -1394,7 +1418,11 @@ static void doMergeTwoLevelData(STsdbQueryHandle* pQueryHandle, STableCheckInfo*
|
|||
assert(end != -1);
|
||||
|
||||
if (tsArray[end] == key) { // the value of key in cache equals to the end timestamp value, ignore it
|
||||
moveToNextRowInMem(pCheckInfo);
|
||||
if (!pCfg->update) {
|
||||
moveToNextRowInMem(pCheckInfo);
|
||||
} else {
|
||||
end -= step;
|
||||
}
|
||||
}
|
||||
|
||||
int32_t qstart = 0, qend = 0;
|
||||
|
@ -1414,8 +1442,8 @@ static void doMergeTwoLevelData(STsdbQueryHandle* pQueryHandle, STableCheckInfo*
|
|||
* copy them all to result buffer, since it may be overlapped with file data block.
|
||||
*/
|
||||
if (node == NULL ||
|
||||
((dataRowKey(*(SDataRow *)SL_GET_NODE_DATA(node)) > pQueryHandle->window.ekey) && ASCENDING_TRAVERSE(pQueryHandle->order)) ||
|
||||
((dataRowKey(*(SDataRow *)SL_GET_NODE_DATA(node)) < pQueryHandle->window.ekey) && !ASCENDING_TRAVERSE(pQueryHandle->order))) {
|
||||
((dataRowKey((SDataRow)SL_GET_NODE_DATA(node)) > pQueryHandle->window.ekey) && ASCENDING_TRAVERSE(pQueryHandle->order)) ||
|
||||
((dataRowKey((SDataRow)SL_GET_NODE_DATA(node)) < pQueryHandle->window.ekey) && !ASCENDING_TRAVERSE(pQueryHandle->order))) {
|
||||
// no data in cache or data in cache is greater than the ekey of time window, load data from file block
|
||||
if (cur->win.skey == TSKEY_INITIAL_VAL) {
|
||||
cur->win.skey = tsArray[pos];
|
||||
|
@ -1862,13 +1890,14 @@ static int tsdbReadRowsFromCache(STableCheckInfo* pCheckInfo, TSKEY maxKey, int
|
|||
STsdbQueryHandle* pQueryHandle) {
|
||||
int numOfRows = 0;
|
||||
int32_t numOfCols = (int32_t)taosArrayGetSize(pQueryHandle->pColumns);
|
||||
STsdbCfg* pCfg = &pQueryHandle->pTsdb->config;
|
||||
win->skey = TSKEY_INITIAL_VAL;
|
||||
|
||||
int64_t st = taosGetTimestampUs();
|
||||
STable* pTable = pCheckInfo->pTableObj;
|
||||
|
||||
do {
|
||||
SDataRow row = getSDataRowInTableMem(pCheckInfo, pQueryHandle->order);
|
||||
SDataRow row = getSDataRowInTableMem(pCheckInfo, pQueryHandle->order, pCfg->update);
|
||||
if (row == NULL) {
|
||||
break;
|
||||
}
|
||||
|
@ -1919,9 +1948,9 @@ static int32_t getAllTableList(STable* pSuperTable, SArray* list) {
|
|||
while (tSkipListIterNext(iter)) {
|
||||
SSkipListNode* pNode = tSkipListIterGet(iter);
|
||||
|
||||
STable** pTable = (STable**) SL_GET_NODE_DATA((SSkipListNode*) pNode);
|
||||
STable* pTable = (STable*) SL_GET_NODE_DATA((SSkipListNode*) pNode);
|
||||
|
||||
STableKeyInfo info = {.pTable = *pTable, .lastKey = TSKEY_INITIAL_VAL};
|
||||
STableKeyInfo info = {.pTable = pTable, .lastKey = TSKEY_INITIAL_VAL};
|
||||
taosArrayPush(list, &info);
|
||||
}
|
||||
|
||||
|
@ -2311,7 +2340,11 @@ void filterPrepare(void* expr, void* param) {
|
|||
if (pInfo->optr == TSDB_RELATION_IN) {
|
||||
pInfo->q = (char*) pCond->arr;
|
||||
} else {
|
||||
pInfo->q = calloc(1, pSchema->bytes + TSDB_NCHAR_SIZE); // to make sure tonchar does not cause invalid write, since the '\0' needs at least sizeof(wchar_t) space.
|
||||
uint32_t size = pCond->nLen * TSDB_NCHAR_SIZE;
|
||||
if (size < (uint32_t)pSchema->bytes) {
|
||||
size = pSchema->bytes;
|
||||
}
|
||||
pInfo->q = calloc(1, size + TSDB_NCHAR_SIZE); // to make sure tonchar does not cause invalid write, since the '\0' needs at least sizeof(wchar_t) space.
|
||||
tVariantDump(pCond, pInfo->q, pSchema->type, true);
|
||||
}
|
||||
}
|
||||
|
@ -2460,7 +2493,7 @@ SArray* createTableGroup(SArray* pTableList, STSchema* pTagSchema, SColIndex* pC
|
|||
static bool indexedNodeFilterFp(const void* pNode, void* param) {
|
||||
tQueryInfo* pInfo = (tQueryInfo*) param;
|
||||
|
||||
STable* pTable = *(STable**)(SL_GET_NODE_DATA((SSkipListNode*)pNode));
|
||||
STable* pTable = (STable*)(SL_GET_NODE_DATA((SSkipListNode*)pNode));
|
||||
|
||||
char* val = NULL;
|
||||
|
||||
|
|
|
@ -8,7 +8,7 @@ TARGET_LINK_LIBRARIES(tutil pthread osdetail lz4 z)
|
|||
|
||||
IF (TD_LINUX)
|
||||
TARGET_LINK_LIBRARIES(tutil m rt)
|
||||
ADD_SUBDIRECTORY(tests)
|
||||
# ADD_SUBDIRECTORY(tests)
|
||||
|
||||
FIND_PATH(ICONV_INCLUDE_EXIST iconv.h /usr/include/ /usr/local/include/)
|
||||
IF (ICONV_INCLUDE_EXIST)
|
||||
|
|
|
@ -0,0 +1,42 @@
|
|||
/*
|
||||
* Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com>
|
||||
*
|
||||
* This program is free software: you can use, redistribute, and/or modify
|
||||
* it under the terms of the GNU Affero General Public License, version 3
|
||||
* or later ("AGPL"), as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef TDENGINE_TFILE_H
|
||||
#define TDENGINE_TFILE_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include <unistd.h>
|
||||
|
||||
// init taos file module
|
||||
int32_t tfinit();
|
||||
|
||||
// clean up taos file module
|
||||
void tfcleanup();
|
||||
|
||||
// the same syntax as UNIX standard open/close/read/write
|
||||
// but FD is int64_t and will never be reused
|
||||
int64_t tfopen(const char *pathname, int32_t flags);
|
||||
int64_t tfclose(int64_t tfd);
|
||||
int64_t tfwrite(int64_t tfd, void *buf, int64_t count);
|
||||
int64_t tfread(int64_t tfd, void *buf, int64_t count);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif // TDENGINE_TREF_H
|
|
@ -21,38 +21,48 @@
|
|||
extern "C" {
|
||||
#endif
|
||||
|
||||
// open an instance, return refId which will be used by other APIs
|
||||
int taosOpenRef(int max, void (*fp)(void *));
|
||||
// open a reference set, max is the mod used by hash, fp is the pointer to free resource function
|
||||
// return rsetId which will be used by other APIs. On error, -1 is returned, and terrno is set appropriately
|
||||
int taosOpenRef(int max, void (*fp)(void *));
|
||||
|
||||
// close the Ref instance
|
||||
void taosCloseRef(int refId);
|
||||
// close the reference set, refId is the return value by taosOpenRef
|
||||
// return 0 if success. On error, -1 is returned, and terrno is set appropriately
|
||||
int taosCloseRef(int refId);
|
||||
|
||||
// add ref, p is the pointer to resource or pointer ID
|
||||
int taosAddRef(int refId, void *p);
|
||||
#define taosRemoveRef taosReleaseRef
|
||||
// return Reference ID(rid) allocated. On error, -1 is returned, and terrno is set appropriately
|
||||
int64_t taosAddRef(int refId, void *p);
|
||||
|
||||
// acquire ref, p is the pointer to resource or pointer ID
|
||||
int taosAcquireRef(int refId, void *p);
|
||||
// remove ref, rid is the reference ID returned by taosAddRef
|
||||
// return 0 if success. On error, -1 is returned, and terrno is set appropriately
|
||||
int taosRemoveRef(int rsetId, int64_t rid);
|
||||
|
||||
// release ref, p is the pointer to resource or pinter ID
|
||||
void taosReleaseRef(int refId, void *p);
|
||||
// acquire ref, rid is the reference ID returned by taosAddRef
|
||||
// return the resource p. On error, NULL is returned, and terrno is set appropriately
|
||||
void *taosAcquireRef(int rsetId, int64_t rid);
|
||||
|
||||
// return the first if p is null, otherwise return the next after p
|
||||
void *taosIterateRef(int refId, void *p);
|
||||
// release ref, rid is the reference ID returned by taosAddRef
|
||||
// return 0 if success. On error, -1 is returned, and terrno is set appropriately
|
||||
int taosReleaseRef(int rsetId, int64_t rid);
|
||||
|
||||
// return the first reference if rid is 0, otherwise return the next after current reference.
|
||||
// if return value is NULL, it means list is over(if terrno is set, it means error happens)
|
||||
void *taosIterateRef(int rsetId, int64_t rid);
|
||||
|
||||
// return the number of references in system
|
||||
int taosListRef();
|
||||
|
||||
/* sample code to iterate the refs
|
||||
|
||||
void demoIterateRefs(int refId) {
|
||||
void demoIterateRefs(int rsetId) {
|
||||
|
||||
void *p = taosIterateRef(refId, NULL);
|
||||
void *p = taosIterateRef(refId, 0);
|
||||
while (p) {
|
||||
|
||||
// process P
|
||||
|
||||
// get the rid from p
|
||||
|
||||
p = taosIterateRef(refId, p);
|
||||
p = taosIterateRef(rsetId, rid);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -27,33 +27,25 @@ extern "C" {
|
|||
#define MAX_SKIP_LIST_LEVEL 15
|
||||
#define SKIP_LIST_RECORD_PERFORMANCE 0
|
||||
|
||||
// For key property setting
|
||||
#define SL_ALLOW_DUP_KEY (uint8_t)0x0 // Allow duplicate key exists (for tag index usage)
|
||||
#define SL_DISCARD_DUP_KEY (uint8_t)0x1 // Discard duplicate key (for data update=0 case)
|
||||
#define SL_UPDATE_DUP_KEY (uint8_t)0x2 // Update duplicate key by remove/insert (for data update=1 case)
|
||||
// For thread safety setting
|
||||
#define SL_THREAD_SAFE (uint8_t)0x4
|
||||
|
||||
typedef char *SSkipListKey;
|
||||
typedef char *(*__sl_key_fn_t)(const void *);
|
||||
|
||||
/**
|
||||
* the skip list node is located in a consecutive memory area,
|
||||
* the format of skip list node is as follows:
|
||||
* +------------+-----------------------+------------------------+-----+------+
|
||||
* | node level | forward pointer array | backward pointer array | key | data |
|
||||
* +------------+-----------------------+------------------------+-----+------+
|
||||
*/
|
||||
typedef struct SSkipListNode {
|
||||
uint8_t level;
|
||||
uint8_t level;
|
||||
void * pData;
|
||||
struct SSkipListNode *forwards[];
|
||||
} SSkipListNode;
|
||||
|
||||
#define SL_NODE_HEADER_SIZE(_l) (sizeof(SSkipListNode) + ((_l) << 1u) * POINTER_BYTES)
|
||||
|
||||
#define SL_GET_FORWARD_POINTER(n, _l) ((SSkipListNode **)((char *)(n) + sizeof(SSkipListNode)))[(_l)]
|
||||
#define SL_GET_BACKWARD_POINTER(n, _l) \
|
||||
((SSkipListNode **)((char *)(n) + sizeof(SSkipListNode) + ((n)->level) * POINTER_BYTES))[(_l)]
|
||||
|
||||
#define SL_GET_NODE_DATA(n) ((char *)(n) + SL_NODE_HEADER_SIZE((n)->level))
|
||||
#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_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_DATA(n) (n)->pData
|
||||
#define SL_NODE_GET_FORWARD_POINTER(n, l) (n)->forwards[(l)]
|
||||
#define SL_NODE_GET_BACKWARD_POINTER(n, l) (n)->forwards[(n)->level + (l)]
|
||||
|
||||
/*
|
||||
* @version 0.3
|
||||
|
@ -103,34 +95,23 @@ typedef struct tSkipListState {
|
|||
uint64_t nTotalElapsedTimeForInsert;
|
||||
} tSkipListState;
|
||||
|
||||
typedef struct SSkipListKeyInfo {
|
||||
uint8_t dupKey : 2; // if allow duplicated key in the skip list
|
||||
uint8_t type : 4; // key type
|
||||
uint8_t freeNode:2; // free node when destroy the skiplist
|
||||
uint8_t len; // maximum key length, used in case of string key
|
||||
} SSkipListKeyInfo;
|
||||
|
||||
typedef struct SSkipList {
|
||||
__compar_fn_t comparFn;
|
||||
__sl_key_fn_t keyFn;
|
||||
uint32_t size;
|
||||
uint8_t maxLevel;
|
||||
uint8_t level;
|
||||
SSkipListKeyInfo keyInfo;
|
||||
pthread_rwlock_t *lock;
|
||||
SSkipListNode * pHead; // point to the first element
|
||||
SSkipListNode * pTail; // point to the last element
|
||||
uint16_t len;
|
||||
uint8_t maxLevel;
|
||||
uint8_t flags;
|
||||
uint8_t type; // static info above
|
||||
uint8_t level;
|
||||
uint32_t size;
|
||||
SSkipListNode * pHead; // point to the first element
|
||||
SSkipListNode * pTail; // point to the last element
|
||||
#if SKIP_LIST_RECORD_PERFORMANCE
|
||||
tSkipListState state; // skiplist state
|
||||
#endif
|
||||
} SSkipList;
|
||||
|
||||
/*
|
||||
* iterate the skiplist
|
||||
* this will cause the multi-thread problem, when the skiplist is destroyed, the iterate may
|
||||
* continue iterating the skiplist, so add the reference count for skiplist
|
||||
* TODO add the ref for skip list when one iterator is created
|
||||
*/
|
||||
typedef struct SSkipListIterator {
|
||||
SSkipList * pSkipList;
|
||||
SSkipListNode *cur;
|
||||
|
@ -139,114 +120,26 @@ typedef struct SSkipListIterator {
|
|||
SSkipListNode *next; // next points to the true qualified node in skip list
|
||||
} SSkipListIterator;
|
||||
|
||||
/**
|
||||
*
|
||||
* @param nMaxLevel maximum skip list level
|
||||
* @param keyType type of key
|
||||
* @param dupKey allow the duplicated key in the skip list
|
||||
* @return
|
||||
*/
|
||||
SSkipList *tSkipListCreate(uint8_t nMaxLevel, uint8_t keyType, uint8_t keyLen, uint8_t dupKey, uint8_t threadsafe,
|
||||
uint8_t freeNode, __sl_key_fn_t fn);
|
||||
#define SL_IS_THREAD_SAFE(s) (((s)->flags) & SL_THREAD_SAFE)
|
||||
#define SL_DUP_MODE(s) (((s)->flags) & ((((uint8_t)1) << 2) - 1))
|
||||
#define SL_GET_NODE_KEY(s, n) ((s)->keyFn((n)->pData))
|
||||
#define SL_GET_MIN_KEY(s) SL_GET_NODE_KEY(s, SL_NODE_GET_FORWARD_POINTER((s)->pHead, 0))
|
||||
#define SL_GET_MAX_KEY(s) SL_GET_NODE_KEY((s), SL_NODE_GET_BACKWARD_POINTER((s)->pTail, 0))
|
||||
#define SL_SIZE(s) (s)->size
|
||||
|
||||
/**
|
||||
*
|
||||
* @param pSkipList
|
||||
* @return NULL will always be returned
|
||||
*/
|
||||
void *tSkipListDestroy(SSkipList *pSkipList);
|
||||
|
||||
/**
|
||||
*
|
||||
* @param pSkipList
|
||||
* @param level
|
||||
* @param headSize
|
||||
*/
|
||||
void tSkipListNewNodeInfo(SSkipList *pSkipList, int32_t *level, int32_t *headSize);
|
||||
|
||||
/**
|
||||
* put the skip list node into the skip list.
|
||||
* If failed, NULL will be returned, otherwise, the pNode will be returned.
|
||||
*
|
||||
* @param pSkipList
|
||||
* @param pNode
|
||||
* @return
|
||||
*/
|
||||
SSkipListNode *tSkipListPut(SSkipList *pSkipList, SSkipListNode *pNode);
|
||||
|
||||
/**
|
||||
* get *all* nodes which key are equivalent to pKey
|
||||
*
|
||||
* @param pSkipList
|
||||
* @param pKey
|
||||
* @return
|
||||
*/
|
||||
SArray *tSkipListGet(SSkipList *pSkipList, SSkipListKey pKey);
|
||||
|
||||
/**
|
||||
* get the size of skip list
|
||||
* @param pSkipList
|
||||
* @return
|
||||
*/
|
||||
size_t tSkipListGetSize(const SSkipList *pSkipList);
|
||||
|
||||
/**
|
||||
* display skip list of the given level, for debug purpose only
|
||||
* @param pSkipList
|
||||
* @param nlevel
|
||||
*/
|
||||
void tSkipListPrint(SSkipList *pSkipList, int16_t nlevel);
|
||||
|
||||
/**
|
||||
* create skiplist iterator
|
||||
* @param pSkipList
|
||||
* @return
|
||||
*/
|
||||
SSkipList *tSkipListCreate(uint8_t maxLevel, uint8_t keyType, uint16_t keyLen, __compar_fn_t comparFn, uint8_t flags,
|
||||
__sl_key_fn_t fn);
|
||||
void tSkipListDestroy(SSkipList *pSkipList);
|
||||
SSkipListNode * tSkipListPut(SSkipList *pSkipList, void *pData);
|
||||
SArray * tSkipListGet(SSkipList *pSkipList, SSkipListKey pKey);
|
||||
void tSkipListPrint(SSkipList *pSkipList, int16_t nlevel);
|
||||
SSkipListIterator *tSkipListCreateIter(SSkipList *pSkipList);
|
||||
|
||||
/**
|
||||
* create skip list iterator from the given node and specified the order
|
||||
* @param pSkipList
|
||||
* @param pNode start position, instead of the first node in skip list
|
||||
* @param order traverse order of the iterator
|
||||
* @return
|
||||
*/
|
||||
SSkipListIterator *tSkipListCreateIterFromVal(SSkipList* pSkipList, const char* val, int32_t type, int32_t order);
|
||||
|
||||
/**
|
||||
* forward the skip list iterator
|
||||
* @param iter
|
||||
* @return
|
||||
*/
|
||||
bool tSkipListIterNext(SSkipListIterator *iter);
|
||||
|
||||
/**
|
||||
* get the element of skip list node
|
||||
* @param iter
|
||||
* @return
|
||||
*/
|
||||
SSkipListNode *tSkipListIterGet(SSkipListIterator *iter);
|
||||
|
||||
/**
|
||||
* destroy the skip list node
|
||||
* @param iter
|
||||
* @return
|
||||
*/
|
||||
void *tSkipListDestroyIter(SSkipListIterator *iter);
|
||||
|
||||
/*
|
||||
* remove nodes of the pKey value.
|
||||
* If more than one node has the same value, all will be removed
|
||||
*
|
||||
* @Return
|
||||
* the count of removed nodes
|
||||
*/
|
||||
uint32_t tSkipListRemove(SSkipList *pSkipList, SSkipListKey key);
|
||||
|
||||
/*
|
||||
* remove the specified node in parameters
|
||||
*/
|
||||
void tSkipListRemoveNode(SSkipList *pSkipList, SSkipListNode *pNode);
|
||||
SSkipListIterator *tSkipListCreateIterFromVal(SSkipList *pSkipList, const char *val, int32_t type, int32_t order);
|
||||
bool tSkipListIterNext(SSkipListIterator *iter);
|
||||
SSkipListNode * tSkipListIterGet(SSkipListIterator *iter);
|
||||
void * tSkipListDestroyIter(SSkipListIterator *iter);
|
||||
uint32_t tSkipListRemove(SSkipList *pSkipList, SSkipListKey key);
|
||||
void tSkipListRemoveNode(SSkipList *pSkipList, SSkipListNode *pNode);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
|
|
@ -367,7 +367,14 @@ int32_t doCompare(const char* f1, const char* f2, int32_t type, size_t size) {
|
|||
case TSDB_DATA_TYPE_TINYINT:
|
||||
case TSDB_DATA_TYPE_BOOL: DEFAULT_COMP(GET_INT8_VAL(f1), GET_INT8_VAL(f2));
|
||||
case TSDB_DATA_TYPE_NCHAR: {
|
||||
int32_t ret = wcsncmp((wchar_t*) f1, (wchar_t*) f2, size/TSDB_NCHAR_SIZE);
|
||||
tstr* t1 = (tstr*) f1;
|
||||
tstr* t2 = (tstr*) f2;
|
||||
|
||||
if (t1->len != t2->len) {
|
||||
return t1->len > t2->len? 1:-1;
|
||||
}
|
||||
|
||||
int32_t ret = wcsncmp((wchar_t*) t1->data, (wchar_t*) t2->data, t2->len/TSDB_NCHAR_SIZE);
|
||||
if (ret == 0) {
|
||||
return ret;
|
||||
}
|
||||
|
|
|
@ -0,0 +1,81 @@
|
|||
/*
|
||||
* Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com>
|
||||
*
|
||||
* This program is free software: you can use, redistribute, and/or modify
|
||||
* it under the terms of the GNU Affero General Public License, version 3
|
||||
* or later ("AGPL"), as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "os.h"
|
||||
#include "taoserror.h"
|
||||
#include "tulog.h"
|
||||
#include "tutil.h"
|
||||
#include "tref.h"
|
||||
|
||||
static int32_t tsFileRsetId = -1;
|
||||
|
||||
static void taosCloseFile(void *p) {
|
||||
close((int32_t)(uintptr_t)p);
|
||||
}
|
||||
|
||||
int32_t tfinit() {
|
||||
tsFileRsetId = taosOpenRef(2000, taosCloseFile);
|
||||
return tsFileRsetId;
|
||||
}
|
||||
|
||||
void tfcleanup() {
|
||||
if (tsFileRsetId >= 0) taosCloseRef(tsFileRsetId);
|
||||
tsFileRsetId = -1;
|
||||
}
|
||||
|
||||
int64_t tfopen(const char *pathname, int32_t flags) {
|
||||
int32_t fd = open(pathname, flags);
|
||||
|
||||
if (fd < 0) {
|
||||
terrno = TAOS_SYSTEM_ERROR(errno);
|
||||
return -1;
|
||||
}
|
||||
|
||||
void *p = (void *)(int64_t)fd;
|
||||
int64_t rid = taosAddRef(tsFileRsetId, p);
|
||||
if (rid < 0) close(fd);
|
||||
|
||||
return rid;
|
||||
}
|
||||
|
||||
int64_t tfclose(int64_t tfd) {
|
||||
return taosRemoveRef(tsFileRsetId, tfd);
|
||||
}
|
||||
|
||||
int64_t tfwrite(int64_t tfd, void *buf, int64_t count) {
|
||||
void *p = taosAcquireRef(tsFileRsetId, tfd);
|
||||
if (p == NULL) return -1;
|
||||
|
||||
int32_t fd = (int32_t)(uintptr_t)p;
|
||||
|
||||
int64_t ret = taosWrite(fd, buf, count);
|
||||
if (ret < 0) terrno = TAOS_SYSTEM_ERROR(errno);
|
||||
|
||||
taosReleaseRef(tsFileRsetId, tfd);
|
||||
return ret;
|
||||
}
|
||||
|
||||
int64_t tfread(int64_t tfd, void *buf, int64_t count) {
|
||||
void *p = taosAcquireRef(tsFileRsetId, tfd);
|
||||
if (p == NULL) return -1;
|
||||
|
||||
int32_t fd = (int32_t)(uintptr_t)p;
|
||||
|
||||
int64_t ret = taosRead(fd, buf, count);
|
||||
if (ret < 0) terrno = TAOS_SYSTEM_ERROR(errno);
|
||||
|
||||
taosReleaseRef(tsFileRsetId, tfd);
|
||||
return ret;
|
||||
}
|
|
@ -24,19 +24,22 @@
|
|||
#define TSDB_REF_STATE_DELETED 2
|
||||
|
||||
typedef struct SRefNode {
|
||||
struct SRefNode *prev;
|
||||
struct SRefNode *next;
|
||||
void *p;
|
||||
int32_t count;
|
||||
struct SRefNode *prev; // previous node
|
||||
struct SRefNode *next; // next node
|
||||
void *p; // pointer to resource protected,
|
||||
int64_t rid; // reference ID
|
||||
int32_t count; // number of references
|
||||
int removed; // 1: removed
|
||||
} SRefNode;
|
||||
|
||||
typedef struct {
|
||||
SRefNode **nodeList;
|
||||
int state; // 0: empty, 1: active; 2: deleted
|
||||
int refId;
|
||||
int max;
|
||||
int32_t count; // total number of SRefNodes in this set
|
||||
int64_t *lockedBy;
|
||||
SRefNode **nodeList; // array of SRefNode linked list
|
||||
int state; // 0: empty, 1: active; 2: deleted
|
||||
int rsetId; // refSet ID, global unique
|
||||
int64_t rid; // increase by one for each new reference
|
||||
int max; // mod
|
||||
int32_t count; // total number of SRefNodes in this set
|
||||
int64_t *lockedBy;
|
||||
void (*fp)(void *);
|
||||
} SRefSet;
|
||||
|
||||
|
@ -47,54 +50,58 @@ static int tsRefSetNum = 0;
|
|||
static int tsNextId = 0;
|
||||
|
||||
static void taosInitRefModule(void);
|
||||
static int taosHashRef(SRefSet *pSet, void *p);
|
||||
static void taosLockList(int64_t *lockedBy);
|
||||
static void taosUnlockList(int64_t *lockedBy);
|
||||
static void taosIncRefCount(SRefSet *pSet);
|
||||
static void taosDecRefCount(SRefSet *pSet);
|
||||
static void taosIncRsetCount(SRefSet *pSet);
|
||||
static void taosDecRsetCount(SRefSet *pSet);
|
||||
static int taosDecRefCount(int rsetId, int64_t rid, int remove);
|
||||
|
||||
int taosOpenRef(int max, void (*fp)(void *))
|
||||
{
|
||||
SRefNode **nodeList;
|
||||
SRefSet *pSet;
|
||||
int64_t *lockedBy;
|
||||
int i, refId;
|
||||
int i, rsetId;
|
||||
|
||||
pthread_once(&tsRefModuleInit, taosInitRefModule);
|
||||
|
||||
nodeList = calloc(sizeof(SRefNode *), (size_t)max);
|
||||
if (nodeList == NULL) {
|
||||
return TSDB_CODE_REF_NO_MEMORY;
|
||||
if (nodeList == NULL) {
|
||||
terrno = TSDB_CODE_REF_NO_MEMORY;
|
||||
return -1;
|
||||
}
|
||||
|
||||
lockedBy = calloc(sizeof(int64_t), (size_t)max);
|
||||
if (lockedBy == NULL) {
|
||||
free(nodeList);
|
||||
return TSDB_CODE_REF_NO_MEMORY;
|
||||
terrno = TSDB_CODE_REF_NO_MEMORY;
|
||||
return -1;
|
||||
}
|
||||
|
||||
pthread_mutex_lock(&tsRefMutex);
|
||||
|
||||
for (i = 0; i < TSDB_REF_OBJECTS; ++i) {
|
||||
tsNextId = (tsNextId + 1) % TSDB_REF_OBJECTS;
|
||||
if (tsNextId == 0) tsNextId = 1; // dont use 0 as rsetId
|
||||
if (tsRefSetList[tsNextId].state == TSDB_REF_STATE_EMPTY) break;
|
||||
}
|
||||
|
||||
if (i < TSDB_REF_OBJECTS) {
|
||||
refId = tsNextId;
|
||||
pSet = tsRefSetList + refId;
|
||||
taosIncRefCount(pSet);
|
||||
rsetId = tsNextId;
|
||||
pSet = tsRefSetList + rsetId;
|
||||
pSet->max = max;
|
||||
pSet->nodeList = nodeList;
|
||||
pSet->lockedBy = lockedBy;
|
||||
pSet->fp = fp;
|
||||
pSet->rid = 1;
|
||||
pSet->rsetId = rsetId;
|
||||
pSet->state = TSDB_REF_STATE_ACTIVE;
|
||||
pSet->refId = refId;
|
||||
taosIncRsetCount(pSet);
|
||||
|
||||
tsRefSetNum++;
|
||||
uTrace("refId:%d is opened, max:%d, fp:%p refSetNum:%d", refId, max, fp, tsRefSetNum);
|
||||
uTrace("rsetId:%d is opened, max:%d, fp:%p refSetNum:%d", rsetId, max, fp, tsRefSetNum);
|
||||
} else {
|
||||
refId = TSDB_CODE_REF_FULL;
|
||||
rsetId = TSDB_CODE_REF_FULL;
|
||||
free (nodeList);
|
||||
free (lockedBy);
|
||||
uTrace("run out of Ref ID, maximum:%d refSetNum:%d", TSDB_REF_OBJECTS, tsRefSetNum);
|
||||
|
@ -102,121 +109,128 @@ int taosOpenRef(int max, void (*fp)(void *))
|
|||
|
||||
pthread_mutex_unlock(&tsRefMutex);
|
||||
|
||||
return refId;
|
||||
return rsetId;
|
||||
}
|
||||
|
||||
void taosCloseRef(int refId)
|
||||
int taosCloseRef(int rsetId)
|
||||
{
|
||||
SRefSet *pSet;
|
||||
int deleted = 0;
|
||||
|
||||
if (refId < 0 || refId >= TSDB_REF_OBJECTS) {
|
||||
uTrace("refId:%d is invalid, out of range", refId);
|
||||
return;
|
||||
if (rsetId < 0 || rsetId >= TSDB_REF_OBJECTS) {
|
||||
uTrace("rsetId:%d is invalid, out of range", rsetId);
|
||||
terrno = TSDB_CODE_REF_INVALID_ID;
|
||||
return -1;
|
||||
}
|
||||
|
||||
pSet = tsRefSetList + refId;
|
||||
pSet = tsRefSetList + rsetId;
|
||||
|
||||
pthread_mutex_lock(&tsRefMutex);
|
||||
|
||||
if (pSet->state == TSDB_REF_STATE_ACTIVE) {
|
||||
pSet->state = TSDB_REF_STATE_DELETED;
|
||||
deleted = 1;
|
||||
uTrace("refId:%d is closed, count:%d", refId, pSet->count);
|
||||
uTrace("rsetId:%d is closed, count:%d", rsetId, pSet->count);
|
||||
} else {
|
||||
uTrace("refId:%d is already closed, count:%d", refId, pSet->count);
|
||||
uTrace("rsetId:%d is already closed, count:%d", rsetId, pSet->count);
|
||||
}
|
||||
|
||||
pthread_mutex_unlock(&tsRefMutex);
|
||||
|
||||
if (deleted) taosDecRefCount(pSet);
|
||||
if (deleted) taosDecRsetCount(pSet);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int taosAddRef(int refId, void *p)
|
||||
int64_t taosAddRef(int rsetId, void *p)
|
||||
{
|
||||
int hash;
|
||||
SRefNode *pNode;
|
||||
SRefSet *pSet;
|
||||
int64_t rid = 0;
|
||||
|
||||
if (refId < 0 || refId >= TSDB_REF_OBJECTS) {
|
||||
uTrace("refId:%d p:%p failed to add, refId not valid", refId, p);
|
||||
return TSDB_CODE_REF_INVALID_ID;
|
||||
if (rsetId < 0 || rsetId >= TSDB_REF_OBJECTS) {
|
||||
uTrace("rsetId:%d p:%p failed to add, rsetId not valid", rsetId, p);
|
||||
terrno = TSDB_CODE_REF_INVALID_ID;
|
||||
return -1;
|
||||
}
|
||||
|
||||
pSet = tsRefSetList + refId;
|
||||
taosIncRefCount(pSet);
|
||||
pSet = tsRefSetList + rsetId;
|
||||
taosIncRsetCount(pSet);
|
||||
if (pSet->state != TSDB_REF_STATE_ACTIVE) {
|
||||
taosDecRefCount(pSet);
|
||||
uTrace("refId:%d p:%p failed to add, not active", refId, p);
|
||||
return TSDB_CODE_REF_ID_REMOVED;
|
||||
taosDecRsetCount(pSet);
|
||||
uTrace("rsetId:%d p:%p failed to add, not active", rsetId, p);
|
||||
terrno = TSDB_CODE_REF_ID_REMOVED;
|
||||
return -1;
|
||||
}
|
||||
|
||||
int code = 0;
|
||||
hash = taosHashRef(pSet, p);
|
||||
pNode = calloc(sizeof(SRefNode), 1);
|
||||
if (pNode == NULL) {
|
||||
terrno = TSDB_CODE_REF_NO_MEMORY;
|
||||
return -1;
|
||||
}
|
||||
|
||||
rid = atomic_add_fetch_64(&pSet->rid, 1);
|
||||
hash = rid % pSet->max;
|
||||
taosLockList(pSet->lockedBy+hash);
|
||||
|
||||
pNode = pSet->nodeList[hash];
|
||||
while (pNode) {
|
||||
if (pNode->p == p)
|
||||
break;
|
||||
pNode->p = p;
|
||||
pNode->rid = rid;
|
||||
pNode->count = 1;
|
||||
|
||||
pNode = pNode->next;
|
||||
}
|
||||
pNode->prev = NULL;
|
||||
pNode->next = pSet->nodeList[hash];
|
||||
if (pSet->nodeList[hash]) pSet->nodeList[hash]->prev = pNode;
|
||||
pSet->nodeList[hash] = pNode;
|
||||
|
||||
if (pNode) {
|
||||
code = TSDB_CODE_REF_ALREADY_EXIST;
|
||||
uTrace("refId:%d p:%p is already there, faild to add", refId, p);
|
||||
} else {
|
||||
pNode = calloc(sizeof(SRefNode), 1);
|
||||
if (pNode) {
|
||||
pNode->p = p;
|
||||
pNode->count = 1;
|
||||
pNode->prev = 0;
|
||||
pNode->next = pSet->nodeList[hash];
|
||||
if (pSet->nodeList[hash]) pSet->nodeList[hash]->prev = pNode;
|
||||
pSet->nodeList[hash] = pNode;
|
||||
uTrace("refId:%d p:%p is added, count:%d malloc mem: %p", refId, p, pSet->count, pNode);
|
||||
} else {
|
||||
code = TSDB_CODE_REF_NO_MEMORY;
|
||||
uTrace("refId:%d p:%p is not added, since no memory", refId, p);
|
||||
}
|
||||
}
|
||||
|
||||
if (code < 0) taosDecRefCount(pSet);
|
||||
uTrace("rsetId:%d p:%p rid:%" PRId64 " is added, count:%d", rsetId, p, rid, pSet->count);
|
||||
|
||||
taosUnlockList(pSet->lockedBy+hash);
|
||||
|
||||
return code;
|
||||
return rid;
|
||||
}
|
||||
|
||||
int taosAcquireRef(int refId, void *p)
|
||||
int taosRemoveRef(int rsetId, int64_t rid)
|
||||
{
|
||||
int hash, code = 0;
|
||||
return taosDecRefCount(rsetId, rid, 1);
|
||||
}
|
||||
|
||||
// if rid is 0, return the first p in hash list, otherwise, return the next after current rid
|
||||
void *taosAcquireRef(int rsetId, int64_t rid)
|
||||
{
|
||||
int hash;
|
||||
SRefNode *pNode;
|
||||
SRefSet *pSet;
|
||||
void *p = NULL;
|
||||
|
||||
if (refId < 0 || refId >= TSDB_REF_OBJECTS) {
|
||||
uTrace("refId:%d p:%p failed to acquire, refId not valid", refId, p);
|
||||
return TSDB_CODE_REF_INVALID_ID;
|
||||
if (rsetId < 0 || rsetId >= TSDB_REF_OBJECTS) {
|
||||
uTrace("rsetId:%d rid:%" PRId64 " failed to acquire, rsetId not valid", rsetId, rid);
|
||||
terrno = TSDB_CODE_REF_INVALID_ID;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
pSet = tsRefSetList + refId;
|
||||
taosIncRefCount(pSet);
|
||||
if (rid <= 0) {
|
||||
uTrace("rsetId:%d rid:%" PRId64 " failed to acquire, rid not valid", rsetId, rid);
|
||||
terrno = TSDB_CODE_REF_NOT_EXIST;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
pSet = tsRefSetList + rsetId;
|
||||
taosIncRsetCount(pSet);
|
||||
if (pSet->state != TSDB_REF_STATE_ACTIVE) {
|
||||
uTrace("refId:%d p:%p failed to acquire, not active", refId, p);
|
||||
taosDecRefCount(pSet);
|
||||
return TSDB_CODE_REF_ID_REMOVED;
|
||||
uTrace("rsetId:%d rid:%" PRId64 " failed to acquire, not active", rsetId, rid);
|
||||
taosDecRsetCount(pSet);
|
||||
terrno = TSDB_CODE_REF_ID_REMOVED;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
hash = taosHashRef(pSet, p);
|
||||
|
||||
hash = rid % pSet->max;
|
||||
taosLockList(pSet->lockedBy+hash);
|
||||
|
||||
pNode = pSet->nodeList[hash];
|
||||
|
||||
while (pNode) {
|
||||
if (pNode->p == p) {
|
||||
if (pNode->rid == rid) {
|
||||
break;
|
||||
}
|
||||
|
||||
|
@ -224,117 +238,76 @@ int taosAcquireRef(int refId, void *p)
|
|||
}
|
||||
|
||||
if (pNode) {
|
||||
pNode->count++;
|
||||
uTrace("refId:%d p:%p is acquired", refId, p);
|
||||
} else {
|
||||
code = TSDB_CODE_REF_NOT_EXIST;
|
||||
uTrace("refId:%d p:%p is not there, failed to acquire", refId, p);
|
||||
}
|
||||
|
||||
taosUnlockList(pSet->lockedBy+hash);
|
||||
|
||||
taosDecRefCount(pSet);
|
||||
|
||||
return code;
|
||||
}
|
||||
|
||||
void taosReleaseRef(int refId, void *p)
|
||||
{
|
||||
int hash;
|
||||
SRefNode *pNode;
|
||||
SRefSet *pSet;
|
||||
int released = 0;
|
||||
|
||||
if (refId < 0 || refId >= TSDB_REF_OBJECTS) {
|
||||
uTrace("refId:%d p:%p failed to release, refId not valid", refId, p);
|
||||
return;
|
||||
}
|
||||
|
||||
pSet = tsRefSetList + refId;
|
||||
if (pSet->state == TSDB_REF_STATE_EMPTY) {
|
||||
uTrace("refId:%d p:%p failed to release, cleaned", refId, p);
|
||||
return;
|
||||
}
|
||||
|
||||
hash = taosHashRef(pSet, p);
|
||||
|
||||
taosLockList(pSet->lockedBy+hash);
|
||||
|
||||
pNode = pSet->nodeList[hash];
|
||||
while (pNode) {
|
||||
if (pNode->p == p)
|
||||
break;
|
||||
|
||||
pNode = pNode->next;
|
||||
}
|
||||
|
||||
if (pNode) {
|
||||
pNode->count--;
|
||||
|
||||
if (pNode->count == 0) {
|
||||
if ( pNode->prev ) {
|
||||
pNode->prev->next = pNode->next;
|
||||
} else {
|
||||
pSet->nodeList[hash] = pNode->next;
|
||||
}
|
||||
|
||||
if ( pNode->next ) {
|
||||
pNode->next->prev = pNode->prev;
|
||||
}
|
||||
|
||||
(*pSet->fp)(pNode->p);
|
||||
|
||||
free(pNode);
|
||||
released = 1;
|
||||
uTrace("refId:%d p:%p is removed, count:%d, free mem: %p", refId, p, pSet->count, pNode);
|
||||
if (pNode->removed == 0) {
|
||||
pNode->count++;
|
||||
p = pNode->p;
|
||||
uTrace("rsetId:%d p:%p rid:%" PRId64 " is acquired", rsetId, pNode->p, rid);
|
||||
} else {
|
||||
uTrace("refId:%d p:%p is released", refId, p);
|
||||
terrno = TSDB_CODE_REF_NOT_EXIST;
|
||||
uTrace("rsetId:%d p:%p rid:%" PRId64 " is already removed, failed to acquire", rsetId, pNode->p, rid);
|
||||
}
|
||||
} else {
|
||||
uTrace("refId:%d p:%p is not there, failed to release", refId, p);
|
||||
terrno = TSDB_CODE_REF_NOT_EXIST;
|
||||
uTrace("rsetId:%d rid:%" PRId64 " is not there, failed to acquire", rsetId, rid);
|
||||
}
|
||||
|
||||
taosUnlockList(pSet->lockedBy+hash);
|
||||
|
||||
if (released) taosDecRefCount(pSet);
|
||||
taosDecRsetCount(pSet);
|
||||
|
||||
return p;
|
||||
}
|
||||
|
||||
// if p is NULL, return the first p in hash list, otherwise, return the next after p
|
||||
void *taosIterateRef(int refId, void *p) {
|
||||
int taosReleaseRef(int rsetId, int64_t rid)
|
||||
{
|
||||
return taosDecRefCount(rsetId, rid, 0);
|
||||
}
|
||||
|
||||
// if rid is 0, return the first p in hash list, otherwise, return the next after current rid
|
||||
void *taosIterateRef(int rsetId, int64_t rid) {
|
||||
SRefNode *pNode = NULL;
|
||||
SRefSet *pSet;
|
||||
|
||||
if (refId < 0 || refId >= TSDB_REF_OBJECTS) {
|
||||
uTrace("refId:%d p:%p failed to iterate, refId not valid", refId, p);
|
||||
if (rsetId < 0 || rsetId >= TSDB_REF_OBJECTS) {
|
||||
uTrace("rsetId:%d rid:%" PRId64 " failed to iterate, rsetId not valid", rsetId, rid);
|
||||
terrno = TSDB_CODE_REF_INVALID_ID;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
pSet = tsRefSetList + refId;
|
||||
taosIncRefCount(pSet);
|
||||
if (rid <= 0) {
|
||||
uTrace("rsetId:%d rid:%" PRId64 " failed to iterate, rid not valid", rsetId, rid);
|
||||
terrno = TSDB_CODE_REF_NOT_EXIST;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
pSet = tsRefSetList + rsetId;
|
||||
taosIncRsetCount(pSet);
|
||||
if (pSet->state != TSDB_REF_STATE_ACTIVE) {
|
||||
uTrace("refId:%d p:%p failed to iterate, not active", refId, p);
|
||||
taosDecRefCount(pSet);
|
||||
uTrace("rsetId:%d rid:%" PRId64 " failed to iterate, rset not active", rsetId, rid);
|
||||
terrno = TSDB_CODE_REF_ID_REMOVED;
|
||||
taosDecRsetCount(pSet);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
int hash = 0;
|
||||
if (p) {
|
||||
hash = taosHashRef(pSet, p);
|
||||
if (rid > 0) {
|
||||
hash = rid % pSet->max;
|
||||
taosLockList(pSet->lockedBy+hash);
|
||||
|
||||
pNode = pSet->nodeList[hash];
|
||||
while (pNode) {
|
||||
if (pNode->p == p) break;
|
||||
if (pNode->rid == rid) break;
|
||||
pNode = pNode->next;
|
||||
}
|
||||
|
||||
if (pNode == NULL) {
|
||||
uError("refId:%d p:%p not there, quit", refId, p);
|
||||
uError("rsetId:%d rid:%" PRId64 " not there, quit", rsetId, rid);
|
||||
terrno = TSDB_CODE_REF_NOT_EXIST;
|
||||
taosUnlockList(pSet->lockedBy+hash);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
// p is there
|
||||
// rid is there
|
||||
pNode = pNode->next;
|
||||
if (pNode == NULL) {
|
||||
taosUnlockList(pSet->lockedBy+hash);
|
||||
|
@ -356,14 +329,14 @@ void *taosIterateRef(int refId, void *p) {
|
|||
pNode->count++; // acquire it
|
||||
newP = pNode->p;
|
||||
taosUnlockList(pSet->lockedBy+hash);
|
||||
uTrace("refId:%d p:%p is returned", refId, p);
|
||||
uTrace("rsetId:%d p:%p rid:%" PRId64 " is returned", rsetId, newP, rid);
|
||||
} else {
|
||||
uTrace("refId:%d p:%p the list is over", refId, p);
|
||||
uTrace("rsetId:%d the list is over", rsetId);
|
||||
}
|
||||
|
||||
if (p) taosReleaseRef(refId, p); // release the current one
|
||||
if (rid > 0) taosReleaseRef(rsetId, rid); // release the current one
|
||||
|
||||
taosDecRefCount(pSet);
|
||||
taosDecRsetCount(pSet);
|
||||
|
||||
return newP;
|
||||
}
|
||||
|
@ -381,13 +354,13 @@ int taosListRef() {
|
|||
if (pSet->state == TSDB_REF_STATE_EMPTY)
|
||||
continue;
|
||||
|
||||
uInfo("refId:%d state:%d count::%d", i, pSet->state, pSet->count);
|
||||
uInfo("rsetId:%d state:%d count::%d", i, pSet->state, pSet->count);
|
||||
|
||||
for (int j=0; j < pSet->max; ++j) {
|
||||
pNode = pSet->nodeList[j];
|
||||
|
||||
while (pNode) {
|
||||
uInfo("refId:%d p:%p count:%d", i, pNode->p, pNode->count);
|
||||
uInfo("rsetId:%d p:%p rid:%" PRId64 "count:%d", i, pNode->p, pNode->rid, pNode->count);
|
||||
pNode = pNode->next;
|
||||
num++;
|
||||
}
|
||||
|
@ -399,21 +372,78 @@ int taosListRef() {
|
|||
return num;
|
||||
}
|
||||
|
||||
static int taosHashRef(SRefSet *pSet, void *p)
|
||||
{
|
||||
int hash = 0;
|
||||
int64_t v = (int64_t)p;
|
||||
|
||||
for (int i = 0; i < sizeof(v); ++i) {
|
||||
hash += (int)(v & 0xFFFF);
|
||||
v = v >> 16;
|
||||
i = i + 2;
|
||||
static int taosDecRefCount(int rsetId, int64_t rid, int remove) {
|
||||
int hash;
|
||||
SRefSet *pSet;
|
||||
SRefNode *pNode;
|
||||
int released = 0;
|
||||
int code = 0;
|
||||
|
||||
if (rsetId < 0 || rsetId >= TSDB_REF_OBJECTS) {
|
||||
uTrace("rsetId:%d rid:%" PRId64 " failed to remove, rsetId not valid", rsetId, rid);
|
||||
terrno = TSDB_CODE_REF_INVALID_ID;
|
||||
return -1;
|
||||
}
|
||||
|
||||
hash = hash % pSet->max;
|
||||
if (rid <= 0) {
|
||||
uTrace("rsetId:%d rid:%" PRId64 " failed to remove, rid not valid", rsetId, rid);
|
||||
terrno = TSDB_CODE_REF_NOT_EXIST;
|
||||
return -1;
|
||||
}
|
||||
|
||||
return hash;
|
||||
}
|
||||
pSet = tsRefSetList + rsetId;
|
||||
if (pSet->state == TSDB_REF_STATE_EMPTY) {
|
||||
uTrace("rsetId:%d rid:%" PRId64 " failed to remove, cleaned", rsetId, rid);
|
||||
terrno = TSDB_CODE_REF_ID_REMOVED;
|
||||
return -1;
|
||||
}
|
||||
|
||||
hash = rid % pSet->max;
|
||||
taosLockList(pSet->lockedBy+hash);
|
||||
|
||||
pNode = pSet->nodeList[hash];
|
||||
while (pNode) {
|
||||
if (pNode->rid == rid)
|
||||
break;
|
||||
|
||||
pNode = pNode->next;
|
||||
}
|
||||
|
||||
if (pNode) {
|
||||
pNode->count--;
|
||||
if (remove) pNode->removed = 1;
|
||||
|
||||
if (pNode->count <= 0) {
|
||||
if (pNode->prev) {
|
||||
pNode->prev->next = pNode->next;
|
||||
} else {
|
||||
pSet->nodeList[hash] = pNode->next;
|
||||
}
|
||||
|
||||
if (pNode->next) {
|
||||
pNode->next->prev = pNode->prev;
|
||||
}
|
||||
|
||||
(*pSet->fp)(pNode->p);
|
||||
|
||||
uTrace("rsetId:%d p:%p rid:%" PRId64 "is removed, count:%d, free mem: %p", rsetId, pNode->p, rid, pSet->count, pNode);
|
||||
free(pNode);
|
||||
released = 1;
|
||||
} else {
|
||||
uTrace("rsetId:%d p:%p rid:%" PRId64 "is released, count:%d", rsetId, pNode->p, rid, pNode->count);
|
||||
}
|
||||
} else {
|
||||
uTrace("rsetId:%d rid:%" PRId64 " is not there, failed to release/remove", rsetId, rid);
|
||||
terrno = TSDB_CODE_REF_NOT_EXIST;
|
||||
code = -1;
|
||||
}
|
||||
|
||||
taosUnlockList(pSet->lockedBy+hash);
|
||||
|
||||
if (released) taosDecRsetCount(pSet);
|
||||
|
||||
return code;
|
||||
}
|
||||
|
||||
static void taosLockList(int64_t *lockedBy) {
|
||||
int64_t tid = taosGetPthreadId();
|
||||
|
@ -436,14 +466,14 @@ static void taosInitRefModule(void) {
|
|||
pthread_mutex_init(&tsRefMutex, NULL);
|
||||
}
|
||||
|
||||
static void taosIncRefCount(SRefSet *pSet) {
|
||||
static void taosIncRsetCount(SRefSet *pSet) {
|
||||
atomic_add_fetch_32(&pSet->count, 1);
|
||||
uTrace("refId:%d inc count:%d", pSet->refId, pSet->count);
|
||||
// uTrace("rsetId:%d inc count:%d", pSet->rsetId, count);
|
||||
}
|
||||
|
||||
static void taosDecRefCount(SRefSet *pSet) {
|
||||
static void taosDecRsetCount(SRefSet *pSet) {
|
||||
int32_t count = atomic_sub_fetch_32(&pSet->count, 1);
|
||||
uTrace("refId:%d dec count:%d", pSet->refId, pSet->count);
|
||||
// uTrace("rsetId:%d dec count:%d", pSet->rsetId, count);
|
||||
|
||||
if (count > 0) return;
|
||||
|
||||
|
@ -458,7 +488,7 @@ static void taosDecRefCount(SRefSet *pSet) {
|
|||
taosTFree(pSet->lockedBy);
|
||||
|
||||
tsRefSetNum--;
|
||||
uTrace("refId:%d is cleaned, refSetNum:%d count:%d", pSet->refId, tsRefSetNum, pSet->count);
|
||||
uTrace("rsetId:%d is cleaned, refSetNum:%d count:%d", pSet->rsetId, tsRefSetNum, pSet->count);
|
||||
}
|
||||
|
||||
pthread_mutex_unlock(&tsRefMutex);
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -247,7 +247,7 @@ void skiplistPerformanceTest() {
|
|||
printf("total:%" PRIu64 " ms, avg:%f\n", e - s, (e - s) / (double)size);
|
||||
printf("max level of skiplist:%d, actually level:%d\n ", pSkipList->maxLevel, pSkipList->level);
|
||||
|
||||
assert(tSkipListGetSize(pSkipList) == size);
|
||||
assert(SL_GET_SIZE(pSkipList) == size);
|
||||
|
||||
// printf("the level of skiplist is:\n");
|
||||
//
|
||||
|
@ -273,7 +273,7 @@ void skiplistPerformanceTest() {
|
|||
|
||||
int64_t et = taosGetTimestampMs();
|
||||
printf("delete %d data from skiplist, elapased time:%" PRIu64 "ms\n", 10000, et - st);
|
||||
assert(tSkipListGetSize(pSkipList) == size);
|
||||
assert(SL_GET_SIZE(pSkipList) == size);
|
||||
|
||||
tSkipListDestroy(pSkipList);
|
||||
taosTFree(total);
|
||||
|
|
|
@ -11,106 +11,119 @@
|
|||
#include "tulog.h"
|
||||
|
||||
typedef struct {
|
||||
int refNum;
|
||||
int steps;
|
||||
int refId;
|
||||
void **p;
|
||||
int refNum;
|
||||
int steps;
|
||||
int rsetId;
|
||||
int64_t rid;
|
||||
void **p;
|
||||
} SRefSpace;
|
||||
|
||||
void iterateRefs(int refId) {
|
||||
void iterateRefs(int rsetId) {
|
||||
int count = 0;
|
||||
|
||||
void *p = taosIterateRef(refId, NULL);
|
||||
void *p = taosIterateRef(rsetId, NULL);
|
||||
while (p) {
|
||||
// process P
|
||||
count++;
|
||||
p = taosIterateRef(refId, p);
|
||||
p = taosIterateRef(rsetId, p);
|
||||
}
|
||||
|
||||
printf(" %d ", count);
|
||||
}
|
||||
|
||||
void *takeRefActions(void *param) {
|
||||
void *addRef(void *param) {
|
||||
SRefSpace *pSpace = (SRefSpace *)param;
|
||||
int code, id;
|
||||
int id;
|
||||
int64_t rid;
|
||||
|
||||
for (int i=0; i < pSpace->steps; ++i) {
|
||||
printf("s");
|
||||
printf("a");
|
||||
id = random() % pSpace->refNum;
|
||||
code = taosAddRef(pSpace->refId, pSpace->p[id]);
|
||||
usleep(1);
|
||||
|
||||
id = random() % pSpace->refNum;
|
||||
code = taosAcquireRef(pSpace->refId, pSpace->p[id]);
|
||||
if (code >= 0) {
|
||||
usleep(id % 5 + 1);
|
||||
taosReleaseRef(pSpace->refId, pSpace->p[id]);
|
||||
if (pSpace->rid[id] <= 0) {
|
||||
pSpace->p[id] = malloc(128);
|
||||
pSpace->rid[id] = taosAddRef(pSpace->rsetId, pSpace->p[id]);
|
||||
}
|
||||
|
||||
id = random() % pSpace->refNum;
|
||||
taosRemoveRef(pSpace->refId, pSpace->p[id]);
|
||||
usleep(id %5 + 1);
|
||||
|
||||
id = random() % pSpace->refNum;
|
||||
code = taosAcquireRef(pSpace->refId, pSpace->p[id]);
|
||||
if (code >= 0) {
|
||||
usleep(id % 5 + 1);
|
||||
taosReleaseRef(pSpace->refId, pSpace->p[id]);
|
||||
}
|
||||
|
||||
id = random() % pSpace->refNum;
|
||||
iterateRefs(id);
|
||||
usleep(100);
|
||||
}
|
||||
|
||||
for (int i=0; i < pSpace->refNum; ++i) {
|
||||
taosRemoveRef(pSpace->refId, pSpace->p[i]);
|
||||
}
|
||||
|
||||
//uInfo("refId:%d thread exits", pSpace->refId);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void *removeRef(void *param) {
|
||||
SRefSpace *pSpace = (SRefSpace *)param;
|
||||
int id;
|
||||
int64_t rid;
|
||||
|
||||
for (int i=0; i < pSpace->steps; ++i) {
|
||||
printf("d");
|
||||
id = random() % pSpace->refNum;
|
||||
if (pSpace->rid[id] > 0) {
|
||||
code = taosRemoveRef(pSpace->rsetId, pSpace->rid[id]);
|
||||
if (code == 0) pSpace->rid[id] = 0;
|
||||
}
|
||||
|
||||
usleep(100);
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void *acquireRelease(void *param) {
|
||||
SRefSpace *pSpace = (SRefSpace *)param;
|
||||
int id;
|
||||
int64_t rid;
|
||||
|
||||
for (int i=0; i < pSpace->steps; ++i) {
|
||||
printf("a");
|
||||
|
||||
id = random() % pSpace->refNum;
|
||||
code = taosAcquireRef(pSpace->rsetId, pSpace->p[id]);
|
||||
if (code >= 0) {
|
||||
usleep(id % 5 + 1);
|
||||
taosReleaseRef(pSpace->rsetId, pSpace->p[id]);
|
||||
}
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void myfree(void *p) {
|
||||
return;
|
||||
free(p);
|
||||
}
|
||||
|
||||
void *openRefSpace(void *param) {
|
||||
SRefSpace *pSpace = (SRefSpace *)param;
|
||||
|
||||
printf("c");
|
||||
pSpace->refId = taosOpenRef(50, myfree);
|
||||
pSpace->rsetId = taosOpenRef(50, myfree);
|
||||
|
||||
if (pSpace->refId < 0) {
|
||||
printf("failed to open ref, reson:%s\n", tstrerror(pSpace->refId));
|
||||
if (pSpace->rsetId < 0) {
|
||||
printf("failed to open ref, reson:%s\n", tstrerror(pSpace->rsetId));
|
||||
return NULL;
|
||||
}
|
||||
|
||||
pSpace->p = (void **) calloc(sizeof(void *), pSpace->refNum);
|
||||
for (int i=0; i<pSpace->refNum; ++i) {
|
||||
pSpace->p[i] = (void *) malloc(128);
|
||||
}
|
||||
|
||||
pthread_attr_t thattr;
|
||||
pthread_attr_init(&thattr);
|
||||
pthread_attr_setdetachstate(&thattr, PTHREAD_CREATE_JOINABLE);
|
||||
|
||||
pthread_t thread1, thread2, thread3;
|
||||
pthread_create(&(thread1), &thattr, takeRefActions, (void *)(pSpace));
|
||||
pthread_create(&(thread2), &thattr, takeRefActions, (void *)(pSpace));
|
||||
pthread_create(&(thread3), &thattr, takeRefActions, (void *)(pSpace));
|
||||
pthread_create(&(thread1), &thattr, addRef, (void *)(pSpace));
|
||||
pthread_create(&(thread2), &thattr, removeRef, (void *)(pSpace));
|
||||
pthread_create(&(thread3), &thattr, acquireRelease, (void *)(pSpace));
|
||||
|
||||
pthread_join(thread1, NULL);
|
||||
pthread_join(thread2, NULL);
|
||||
pthread_join(thread3, NULL);
|
||||
|
||||
taosCloseRef(pSpace->refId);
|
||||
|
||||
for (int i=0; i<pSpace->refNum; ++i) {
|
||||
free(pSpace->p[i]);
|
||||
taosRemoveRef(pSpace->rsetId, pSpace->rid[i]);
|
||||
}
|
||||
|
||||
uInfo("refId:%d main thread exit", pSpace->refId);
|
||||
taosCloseRef(pSpace->rsetId);
|
||||
|
||||
uInfo("rsetId:%d main thread exit", pSpace->rsetId);
|
||||
free(pSpace->p);
|
||||
pSpace->p = NULL;
|
||||
|
||||
|
@ -140,7 +153,7 @@ int main(int argc, char *argv[]) {
|
|||
printf("\nusage: %s [options] \n", argv[0]);
|
||||
printf(" [-n]: number of references, default: %d\n", refNum);
|
||||
printf(" [-s]: steps to run for each reference, default: %d\n", steps);
|
||||
printf(" [-t]: number of refIds running in parallel, default: %d\n", threads);
|
||||
printf(" [-t]: number of rsetIds running in parallel, default: %d\n", threads);
|
||||
printf(" [-l]: number of loops, default: %d\n", loops);
|
||||
printf(" [-d]: debugFlag, default: %d\n", uDebugFlag);
|
||||
exit(0);
|
||||
|
|
|
@ -47,7 +47,7 @@ typedef struct {
|
|||
void *rqueue;
|
||||
void *wal;
|
||||
void *tsdb;
|
||||
void *sync;
|
||||
int64_t sync;
|
||||
void *events;
|
||||
void *cq; // continuous query
|
||||
int32_t cfgVersion;
|
||||
|
@ -61,8 +61,6 @@ typedef struct {
|
|||
char db[TSDB_DB_NAME_LEN];
|
||||
} SVnodeObj;
|
||||
|
||||
int vnodeWriteToQueue(void *param, void *pHead, int type);
|
||||
int vnodeWriteCqMsgToQueue(void *param, void *pHead, int type);
|
||||
void vnodeInitWriteFp(void);
|
||||
void vnodeInitReadFp(void);
|
||||
|
||||
|
|
|
@ -44,12 +44,12 @@ static void vnodeCtrlFlow(void *handle, int32_t mseconds);
|
|||
static int vnodeNotifyFileSynced(void *ahandle, uint64_t fversion);
|
||||
|
||||
#ifndef _SYNC
|
||||
tsync_h syncStart(const SSyncInfo *info) { return NULL; }
|
||||
int32_t syncForwardToPeer(tsync_h shandle, void *pHead, void *mhandle, int qtype) { return 0; }
|
||||
void syncStop(tsync_h shandle) {}
|
||||
int32_t syncReconfig(tsync_h shandle, const SSyncCfg * cfg) { return 0; }
|
||||
int syncGetNodesRole(tsync_h shandle, SNodesRole * cfg) { return 0; }
|
||||
void syncConfirmForward(tsync_h shandle, uint64_t version, int32_t code) {}
|
||||
int64_t syncStart(const SSyncInfo *info) { return NULL; }
|
||||
int32_t syncForwardToPeer(int64_t rid, void *pHead, void *mhandle, int qtype) { return 0; }
|
||||
void syncStop(int64_t rid) {}
|
||||
int32_t syncReconfig(int64_t rid, const SSyncCfg * cfg) { return 0; }
|
||||
int syncGetNodesRole(int64_t rid, SNodesRole * cfg) { return 0; }
|
||||
void syncConfirmForward(int64_t rid, uint64_t version, int32_t code) {}
|
||||
#endif
|
||||
|
||||
char* vnodeStatus[] = {
|
||||
|
@ -140,6 +140,7 @@ int32_t vnodeCreate(SCreateVnodeMsg *pVnodeCfg) {
|
|||
tsdbCfg.maxRowsPerFileBlock = pVnodeCfg->cfg.maxRowsPerFileBlock;
|
||||
tsdbCfg.precision = pVnodeCfg->cfg.precision;
|
||||
tsdbCfg.compression = pVnodeCfg->cfg.compression;
|
||||
tsdbCfg.update = pVnodeCfg->cfg.update;
|
||||
|
||||
char tsdbDir[TSDB_FILENAME_LEN] = {0};
|
||||
sprintf(tsdbDir, "%s/vnode%d/tsdb", tsVnodeDir, pVnodeCfg->cfg.vgId);
|
||||
|
@ -266,7 +267,7 @@ int32_t vnodeOpen(int32_t vnode, char *rootDir) {
|
|||
strcpy(cqCfg.pass, tsInternalPass);
|
||||
strcpy(cqCfg.db, pVnode->db);
|
||||
cqCfg.vgId = vnode;
|
||||
cqCfg.cqWrite = vnodeWriteCqMsgToQueue;
|
||||
cqCfg.cqWrite = vnodeWriteToWQueue;
|
||||
pVnode->cq = cqOpen(pVnode, &cqCfg);
|
||||
if (pVnode->cq == NULL) {
|
||||
vnodeCleanUp(pVnode);
|
||||
|
@ -305,7 +306,7 @@ int32_t vnodeOpen(int32_t vnode, char *rootDir) {
|
|||
return terrno;
|
||||
}
|
||||
|
||||
walRestore(pVnode->wal, pVnode, vnodeWriteToQueue);
|
||||
walRestore(pVnode->wal, pVnode, vnodeProcessWrite);
|
||||
if (pVnode->version == 0) {
|
||||
pVnode->version = walGetVersion(pVnode->wal);
|
||||
}
|
||||
|
@ -320,7 +321,7 @@ int32_t vnodeOpen(int32_t vnode, char *rootDir) {
|
|||
syncInfo.ahandle = pVnode;
|
||||
syncInfo.getWalInfo = vnodeGetWalInfo;
|
||||
syncInfo.getFileInfo = vnodeGetFileInfo;
|
||||
syncInfo.writeToCache = vnodeWriteToQueue;
|
||||
syncInfo.writeToCache = vnodeWriteToWQueue;
|
||||
syncInfo.confirmForward = dnodeSendRpcVWriteRsp;
|
||||
syncInfo.notifyRole = vnodeNotifyRole;
|
||||
syncInfo.notifyFlowCtrl = vnodeCtrlFlow;
|
||||
|
@ -330,7 +331,7 @@ int32_t vnodeOpen(int32_t vnode, char *rootDir) {
|
|||
#ifndef _SYNC
|
||||
pVnode->role = TAOS_SYNC_ROLE_MASTER;
|
||||
#else
|
||||
if (pVnode->sync == NULL) {
|
||||
if (pVnode->sync <= 0) {
|
||||
vError("vgId:%d, failed to open sync module, replica:%d reason:%s", pVnode->vgId, pVnode->syncCfg.replica,
|
||||
tstrerror(terrno));
|
||||
vnodeCleanUp(pVnode);
|
||||
|
@ -365,6 +366,7 @@ int32_t vnodeClose(int32_t vgId) {
|
|||
}
|
||||
|
||||
void vnodeRelease(void *pVnodeRaw) {
|
||||
if (pVnodeRaw == NULL) return;
|
||||
SVnodeObj *pVnode = pVnodeRaw;
|
||||
int32_t vgId = pVnode->vgId;
|
||||
|
||||
|
@ -467,36 +469,6 @@ void *vnodeAcquire(int32_t vgId) {
|
|||
return *ppVnode;
|
||||
}
|
||||
|
||||
void *vnodeAcquireRqueue(int32_t vgId) {
|
||||
SVnodeObj *pVnode = vnodeAcquire(vgId);
|
||||
if (pVnode == NULL) return NULL;
|
||||
|
||||
int32_t code = vnodeCheckRead(pVnode);
|
||||
if (code != TSDB_CODE_SUCCESS) {
|
||||
terrno = code;
|
||||
vInfo("vgId:%d, can not provide read service, status is %s", vgId, vnodeStatus[pVnode->status]);
|
||||
vnodeRelease(pVnode);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return pVnode->rqueue;
|
||||
}
|
||||
|
||||
void *vnodeAcquireWqueue(int32_t vgId) {
|
||||
SVnodeObj *pVnode = vnodeAcquire(vgId);
|
||||
if (pVnode == NULL) return NULL;
|
||||
|
||||
int32_t code = vnodeCheckWrite(pVnode);
|
||||
if (code != TSDB_CODE_SUCCESS) {
|
||||
terrno = code;
|
||||
vInfo("vgId:%d, can not provide write service, status is %s", vgId, vnodeStatus[pVnode->status]);
|
||||
vnodeRelease(pVnode);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return pVnode->wqueue;
|
||||
}
|
||||
|
||||
void *vnodeGetWal(void *pVnode) {
|
||||
return ((SVnodeObj *)pVnode)->wal;
|
||||
}
|
||||
|
@ -589,9 +561,9 @@ static void vnodeCleanUp(SVnodeObj *pVnode) {
|
|||
}
|
||||
|
||||
// stop replication module
|
||||
if (pVnode->sync) {
|
||||
void *sync = pVnode->sync;
|
||||
pVnode->sync = NULL;
|
||||
if (pVnode->sync > 0) {
|
||||
int64_t sync = pVnode->sync;
|
||||
pVnode->sync = -1;
|
||||
syncStop(sync);
|
||||
}
|
||||
|
||||
|
|
|
@ -29,9 +29,9 @@
|
|||
#include "vnodeInt.h"
|
||||
#include "tqueue.h"
|
||||
|
||||
static int32_t (*vnodeProcessReadMsgFp[TSDB_MSG_TYPE_MAX])(SVnodeObj *pVnode, SReadMsg *pReadMsg);
|
||||
static int32_t vnodeProcessQueryMsg(SVnodeObj *pVnode, SReadMsg *pReadMsg);
|
||||
static int32_t vnodeProcessFetchMsg(SVnodeObj *pVnode, SReadMsg *pReadMsg);
|
||||
static int32_t (*vnodeProcessReadMsgFp[TSDB_MSG_TYPE_MAX])(SVnodeObj *pVnode, SVReadMsg *pReadMsg);
|
||||
static int32_t vnodeProcessQueryMsg(SVnodeObj *pVnode, SVReadMsg *pReadMsg);
|
||||
static int32_t vnodeProcessFetchMsg(SVnodeObj *pVnode, SVReadMsg *pReadMsg);
|
||||
static int32_t vnodeNotifyCurrentQhandle(void* handle, void* qhandle, int32_t vgId);
|
||||
|
||||
void vnodeInitReadFp(void) {
|
||||
|
@ -44,9 +44,9 @@ void vnodeInitReadFp(void) {
|
|||
// still required, or there will be a deadlock, so we don’t do any check here, but put the check codes before the
|
||||
// request enters the queue
|
||||
//
|
||||
int32_t vnodeProcessRead(void *param, SReadMsg *pReadMsg) {
|
||||
int32_t vnodeProcessRead(void *param, SVReadMsg *pReadMsg) {
|
||||
SVnodeObj *pVnode = (SVnodeObj *)param;
|
||||
int msgType = pReadMsg->rpcMsg.msgType;
|
||||
int32_t msgType = pReadMsg->msgType;
|
||||
|
||||
if (vnodeProcessReadMsgFp[msgType] == NULL) {
|
||||
vDebug("vgId:%d, msgType:%s not processed, no handle", pVnode->vgId, taosMsg[msgType]);
|
||||
|
@ -56,7 +56,7 @@ int32_t vnodeProcessRead(void *param, SReadMsg *pReadMsg) {
|
|||
return (*vnodeProcessReadMsgFp[msgType])(pVnode, pReadMsg);
|
||||
}
|
||||
|
||||
int32_t vnodeCheckRead(void *param) {
|
||||
static int32_t vnodeCheckRead(void *param) {
|
||||
SVnodeObj *pVnode = param;
|
||||
if (pVnode->status != TAOS_VN_STATUS_READY) {
|
||||
vDebug("vgId:%d, vnode status is %s, recCount:%d pVnode:%p", pVnode->vgId, vnodeStatus[pVnode->status],
|
||||
|
@ -78,24 +78,58 @@ int32_t vnodeCheckRead(void *param) {
|
|||
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
static int32_t vnodePutItemIntoReadQueue(SVnodeObj *pVnode, void **qhandle, void *ahandle) {
|
||||
int32_t code = vnodeCheckRead(pVnode);
|
||||
if (code != TSDB_CODE_SUCCESS) return code;
|
||||
|
||||
SReadMsg *pRead = (SReadMsg *)taosAllocateQitem(sizeof(SReadMsg));
|
||||
pRead->rpcMsg.msgType = TSDB_MSG_TYPE_QUERY;
|
||||
pRead->pCont = qhandle;
|
||||
pRead->contLen = 0;
|
||||
pRead->rpcMsg.ahandle = ahandle;
|
||||
int32_t vnodeWriteToRQueue(void *vparam, void *pCont, int32_t contLen, int8_t qtype, void *rparam) {
|
||||
SVnodeObj *pVnode = vparam;
|
||||
|
||||
if (qtype == TAOS_QTYPE_RPC || qtype == TAOS_QTYPE_QUERY) {
|
||||
int32_t code = vnodeCheckRead(pVnode);
|
||||
if (code != TSDB_CODE_SUCCESS) return code;
|
||||
}
|
||||
|
||||
int32_t size = sizeof(SVReadMsg) + contLen;
|
||||
SVReadMsg *pRead = taosAllocateQitem(size);
|
||||
if (pRead == NULL) {
|
||||
return TSDB_CODE_VND_OUT_OF_MEMORY;
|
||||
}
|
||||
|
||||
if (rparam != NULL) {
|
||||
SRpcMsg *pRpcMsg = rparam;
|
||||
pRead->rpcHandle = pRpcMsg->handle;
|
||||
pRead->rpcAhandle = pRpcMsg->ahandle;
|
||||
pRead->msgType = pRpcMsg->msgType;
|
||||
pRead->code = pRpcMsg->code;
|
||||
}
|
||||
|
||||
if (contLen != 0) {
|
||||
pRead->contLen = contLen;
|
||||
memcpy(pRead->pCont, pCont, contLen);
|
||||
} else {
|
||||
pRead->qhandle = pCont;
|
||||
}
|
||||
|
||||
pRead->qtype = qtype;
|
||||
|
||||
atomic_add_fetch_32(&pVnode->refCount, 1);
|
||||
vTrace("vgId:%d, get vnode rqueue, refCount:%d pVnode:%p", pVnode->vgId, pVnode->refCount, pVnode);
|
||||
|
||||
vDebug("QInfo:%p add to vread queue for exec query, msg:%p", *qhandle, pRead);
|
||||
taosWriteQitem(pVnode->rqueue, TAOS_QTYPE_QUERY, pRead);
|
||||
|
||||
taosWriteQitem(pVnode->rqueue, qtype, pRead);
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
static int32_t vnodePutItemIntoReadQueue(SVnodeObj *pVnode, void **qhandle, void *ahandle) {
|
||||
SRpcMsg rpcMsg = {0};
|
||||
rpcMsg.msgType = TSDB_MSG_TYPE_QUERY;
|
||||
rpcMsg.ahandle = ahandle;
|
||||
|
||||
int32_t code = vnodeWriteToRQueue(pVnode, qhandle, 0, TAOS_QTYPE_QUERY, &rpcMsg);
|
||||
if (code == TSDB_CODE_SUCCESS) {
|
||||
vDebug("QInfo:%p add to vread queue for exec query", *qhandle);
|
||||
}
|
||||
|
||||
return code;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param pRet response message object
|
||||
|
@ -146,7 +180,7 @@ static void vnodeBuildNoResultQueryRsp(SRspRet *pRet) {
|
|||
pRsp->completed = true;
|
||||
}
|
||||
|
||||
static int32_t vnodeProcessQueryMsg(SVnodeObj *pVnode, SReadMsg *pReadMsg) {
|
||||
static int32_t vnodeProcessQueryMsg(SVnodeObj *pVnode, SVReadMsg *pReadMsg) {
|
||||
void * pCont = pReadMsg->pCont;
|
||||
int32_t contLen = pReadMsg->contLen;
|
||||
SRspRet *pRet = &pReadMsg->rspRet;
|
||||
|
@ -155,18 +189,18 @@ static int32_t vnodeProcessQueryMsg(SVnodeObj *pVnode, SReadMsg *pReadMsg) {
|
|||
memset(pRet, 0, sizeof(SRspRet));
|
||||
|
||||
// qHandle needs to be freed correctly
|
||||
if (pReadMsg->rpcMsg.code == TSDB_CODE_RPC_NETWORK_UNAVAIL) {
|
||||
if (pReadMsg->code == TSDB_CODE_RPC_NETWORK_UNAVAIL) {
|
||||
SRetrieveTableMsg *killQueryMsg = (SRetrieveTableMsg *)pReadMsg->pCont;
|
||||
killQueryMsg->free = htons(killQueryMsg->free);
|
||||
killQueryMsg->qhandle = htobe64(killQueryMsg->qhandle);
|
||||
|
||||
vWarn("QInfo:%p connection %p broken, kill query", (void *)killQueryMsg->qhandle, pReadMsg->rpcMsg.handle);
|
||||
assert(pReadMsg->rpcMsg.contLen > 0 && killQueryMsg->free == 1);
|
||||
vWarn("QInfo:%p connection %p broken, kill query", (void *)killQueryMsg->qhandle, pReadMsg->rpcHandle);
|
||||
assert(pReadMsg->contLen > 0 && killQueryMsg->free == 1);
|
||||
|
||||
void **qhandle = qAcquireQInfo(pVnode->qMgmt, (uint64_t)killQueryMsg->qhandle);
|
||||
if (qhandle == NULL || *qhandle == NULL) {
|
||||
vWarn("QInfo:%p invalid qhandle, no matched query handle, conn:%p", (void *)killQueryMsg->qhandle,
|
||||
pReadMsg->rpcMsg.handle);
|
||||
pReadMsg->rpcHandle);
|
||||
} else {
|
||||
assert(*qhandle == (void *)killQueryMsg->qhandle);
|
||||
|
||||
|
@ -208,9 +242,9 @@ static int32_t vnodeProcessQueryMsg(SVnodeObj *pVnode, SReadMsg *pReadMsg) {
|
|||
}
|
||||
|
||||
if (handle != NULL &&
|
||||
vnodeNotifyCurrentQhandle(pReadMsg->rpcMsg.handle, *handle, pVnode->vgId) != TSDB_CODE_SUCCESS) {
|
||||
vnodeNotifyCurrentQhandle(pReadMsg->rpcHandle, *handle, pVnode->vgId) != TSDB_CODE_SUCCESS) {
|
||||
vError("vgId:%d, QInfo:%p, query discarded since link is broken, %p", pVnode->vgId, *handle,
|
||||
pReadMsg->rpcMsg.handle);
|
||||
pReadMsg->rpcHandle);
|
||||
pRsp->code = TSDB_CODE_RPC_NETWORK_UNAVAIL;
|
||||
qReleaseQInfo(pVnode->qMgmt, (void **)&handle, true);
|
||||
return pRsp->code;
|
||||
|
@ -221,7 +255,7 @@ static int32_t vnodeProcessQueryMsg(SVnodeObj *pVnode, SReadMsg *pReadMsg) {
|
|||
|
||||
if (handle != NULL) {
|
||||
vDebug("vgId:%d, QInfo:%p, dnode query msg disposed, create qhandle and returns to app", vgId, *handle);
|
||||
code = vnodePutItemIntoReadQueue(pVnode, handle, pReadMsg->rpcMsg.ahandle);
|
||||
code = vnodePutItemIntoReadQueue(pVnode, handle, pReadMsg->rpcHandle);
|
||||
if (code != TSDB_CODE_SUCCESS) {
|
||||
pRsp->code = code;
|
||||
qReleaseQInfo(pVnode->qMgmt, (void **)&handle, true);
|
||||
|
@ -230,7 +264,7 @@ static int32_t vnodeProcessQueryMsg(SVnodeObj *pVnode, SReadMsg *pReadMsg) {
|
|||
}
|
||||
} else {
|
||||
assert(pCont != NULL);
|
||||
void **qhandle = (void **)pCont;
|
||||
void **qhandle = (void **)pReadMsg->qhandle;
|
||||
|
||||
vDebug("vgId:%d, QInfo:%p, dnode continues to exec query", pVnode->vgId, *qhandle);
|
||||
|
||||
|
@ -242,14 +276,14 @@ static int32_t vnodeProcessQueryMsg(SVnodeObj *pVnode, SReadMsg *pReadMsg) {
|
|||
// build query rsp, the retrieve request has reached here already
|
||||
if (buildRes) {
|
||||
// update the connection info according to the retrieve connection
|
||||
pReadMsg->rpcMsg.handle = qGetResultRetrieveMsg(*qhandle);
|
||||
assert(pReadMsg->rpcMsg.handle != NULL);
|
||||
pReadMsg->rpcHandle = qGetResultRetrieveMsg(*qhandle);
|
||||
assert(pReadMsg->rpcHandle != NULL);
|
||||
|
||||
vDebug("vgId:%d, QInfo:%p, start to build retrieval rsp after query paused, %p", pVnode->vgId, *qhandle,
|
||||
pReadMsg->rpcMsg.handle);
|
||||
pReadMsg->rpcHandle);
|
||||
|
||||
// set the real rsp error code
|
||||
pReadMsg->rpcMsg.code = vnodeDumpQueryResult(&pReadMsg->rspRet, pVnode, qhandle, &freehandle, pReadMsg->rpcMsg.ahandle);
|
||||
pReadMsg->code = vnodeDumpQueryResult(&pRead->rspRet, pVnode, qhandle, &freehandle, pReadMsg->rpcHandle);
|
||||
|
||||
// NOTE: set return code to be TSDB_CODE_QRY_HAS_RSP to notify dnode to return msg to client
|
||||
code = TSDB_CODE_QRY_HAS_RSP;
|
||||
|
@ -274,7 +308,7 @@ static int32_t vnodeProcessQueryMsg(SVnodeObj *pVnode, SReadMsg *pReadMsg) {
|
|||
return code;
|
||||
}
|
||||
|
||||
static int32_t vnodeProcessFetchMsg(SVnodeObj *pVnode, SReadMsg *pReadMsg) {
|
||||
static int32_t vnodeProcessFetchMsg(SVnodeObj *pVnode, SVReadMsg *pReadMsg) {
|
||||
void * pCont = pReadMsg->pCont;
|
||||
SRspRet *pRet = &pReadMsg->rspRet;
|
||||
|
||||
|
@ -283,7 +317,7 @@ static int32_t vnodeProcessFetchMsg(SVnodeObj *pVnode, SReadMsg *pReadMsg) {
|
|||
pRetrieve->qhandle = htobe64(pRetrieve->qhandle);
|
||||
|
||||
vDebug("vgId:%d, QInfo:%p, retrieve msg is disposed, free:%d, conn:%p", pVnode->vgId, (void *)pRetrieve->qhandle,
|
||||
pRetrieve->free, pReadMsg->rpcMsg.handle);
|
||||
pRetrieve->free, pReadMsg->rpcHandle);
|
||||
|
||||
memset(pRet, 0, sizeof(SRspRet));
|
||||
|
||||
|
@ -298,7 +332,7 @@ static int32_t vnodeProcessFetchMsg(SVnodeObj *pVnode, SReadMsg *pReadMsg) {
|
|||
}
|
||||
|
||||
if (code != TSDB_CODE_SUCCESS) {
|
||||
vDebug("vgId:%d, invalid handle in retrieving result, code:0x%08x, QInfo:%p", pVnode->vgId, code, (void *)pRetrieve->qhandle);
|
||||
vError("vgId:%d, invalid handle in retrieving result, code:0x%08x, QInfo:%p", pVnode->vgId, code, (void *)pRetrieve->qhandle);
|
||||
vnodeBuildNoResultQueryRsp(pRet);
|
||||
return code;
|
||||
}
|
||||
|
@ -314,9 +348,8 @@ static int32_t vnodeProcessFetchMsg(SVnodeObj *pVnode, SReadMsg *pReadMsg) {
|
|||
}
|
||||
|
||||
// register the qhandle to connect to quit query immediate if connection is broken
|
||||
if (vnodeNotifyCurrentQhandle(pReadMsg->rpcMsg.handle, *handle, pVnode->vgId) != TSDB_CODE_SUCCESS) {
|
||||
vError("vgId:%d, QInfo:%p, retrieve discarded since link is broken, %p", pVnode->vgId, *handle,
|
||||
pReadMsg->rpcMsg.handle);
|
||||
if (vnodeNotifyCurrentQhandle(pReadMsg->rpcHandle, *handle, pVnode->vgId) != TSDB_CODE_SUCCESS) {
|
||||
vError("vgId:%d, QInfo:%p, retrieve discarded since link is broken, %p", pVnode->vgId, *handle, pReadMsg->rpcHandle);
|
||||
code = TSDB_CODE_RPC_NETWORK_UNAVAIL;
|
||||
qKillQuery(*handle);
|
||||
qReleaseQInfo(pVnode->qMgmt, (void **)&handle, true);
|
||||
|
@ -326,7 +359,7 @@ static int32_t vnodeProcessFetchMsg(SVnodeObj *pVnode, SReadMsg *pReadMsg) {
|
|||
bool freeHandle = true;
|
||||
bool buildRes = false;
|
||||
|
||||
code = qRetrieveQueryResultInfo(*handle, &buildRes, pReadMsg->rpcMsg.handle);
|
||||
code = qRetrieveQueryResultInfo(*handle, &buildRes, pReadMsg->rpcHandle);
|
||||
if (code != TSDB_CODE_SUCCESS) {
|
||||
// TODO handle malloc failure
|
||||
pRet->rsp = (SRetrieveTableRsp *)rpcMallocCont(sizeof(SRetrieveTableRsp));
|
||||
|
@ -337,7 +370,7 @@ static int32_t vnodeProcessFetchMsg(SVnodeObj *pVnode, SReadMsg *pReadMsg) {
|
|||
assert(buildRes == true);
|
||||
#if _NON_BLOCKING_RETRIEVE
|
||||
if (!buildRes) {
|
||||
assert(pReadMsg->rpcMsg.handle != NULL);
|
||||
assert(pReadMsg->rpcHandle != NULL);
|
||||
|
||||
qReleaseQInfo(pVnode->qMgmt, (void **)&handle, false);
|
||||
return TSDB_CODE_QRY_NOT_READY;
|
||||
|
@ -345,7 +378,7 @@ static int32_t vnodeProcessFetchMsg(SVnodeObj *pVnode, SReadMsg *pReadMsg) {
|
|||
#endif
|
||||
|
||||
// ahandle is the sqlObj pointer
|
||||
code = vnodeDumpQueryResult(pRet, pVnode, handle, &freeHandle, pReadMsg->rpcMsg.ahandle);
|
||||
code = vnodeDumpQueryResult(pRet, pVnode, handle, &freeHandle, pReadMsg->rpcHandle);
|
||||
}
|
||||
|
||||
// If qhandle is not added into vread queue, the query should be completed already or paused with error.
|
||||
|
|
|
@ -46,10 +46,11 @@ void vnodeInitWriteFp(void) {
|
|||
vnodeProcessWriteMsgFp[TSDB_MSG_TYPE_UPDATE_TAG_VAL] = vnodeProcessUpdateTagValMsg;
|
||||
}
|
||||
|
||||
int32_t vnodeProcessWrite(void *param1, int qtype, void *param2, void *item) {
|
||||
int32_t code = 0;
|
||||
SVnodeObj *pVnode = (SVnodeObj *)param1;
|
||||
SWalHead * pHead = param2;
|
||||
int32_t vnodeProcessWrite(void *vparam, void *wparam, int32_t qtype, void *rparam) {
|
||||
int32_t code = 0;
|
||||
SVnodeObj * pVnode = vparam;
|
||||
SWalHead * pHead = wparam;
|
||||
SRspRet * pRspRet = rparam;
|
||||
|
||||
if (vnodeProcessWriteMsgFp[pHead->msgType] == NULL) {
|
||||
vDebug("vgId:%d, msgType:%s not processed, no handle", pVnode->vgId, taosMsg[pHead->msgType]);
|
||||
|
@ -80,7 +81,7 @@ int32_t vnodeProcessWrite(void *param1, int qtype, void *param2, void *item) {
|
|||
|
||||
// forward to peers, even it is WAL/FWD, it shall be called to update version in sync
|
||||
int32_t syncCode = 0;
|
||||
syncCode = syncForwardToPeer(pVnode->sync, pHead, item, qtype);
|
||||
syncCode = syncForwardToPeer(pVnode->sync, pHead, pRspRet, qtype);
|
||||
if (syncCode < 0) return syncCode;
|
||||
|
||||
// write into WAL
|
||||
|
@ -90,13 +91,13 @@ int32_t vnodeProcessWrite(void *param1, int qtype, void *param2, void *item) {
|
|||
pVnode->version = pHead->version;
|
||||
|
||||
// write data locally
|
||||
code = (*vnodeProcessWriteMsgFp[pHead->msgType])(pVnode, pHead->cont, item);
|
||||
code = (*vnodeProcessWriteMsgFp[pHead->msgType])(pVnode, pHead->cont, pRspRet);
|
||||
if (code < 0) return code;
|
||||
|
||||
return syncCode;
|
||||
}
|
||||
|
||||
int32_t vnodeCheckWrite(void *param) {
|
||||
static int32_t vnodeCheckWrite(void *param) {
|
||||
SVnodeObj *pVnode = param;
|
||||
if (!(pVnode->accessState & TSDB_VN_WRITE_ACCCESS)) {
|
||||
vDebug("vgId:%d, no write auth, recCount:%d pVnode:%p", pVnode->vgId, pVnode->refCount, pVnode);
|
||||
|
@ -204,35 +205,32 @@ static int32_t vnodeProcessUpdateTagValMsg(SVnodeObj *pVnode, void *pCont, SRspR
|
|||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
int vnodeWriteCqMsgToQueue(void *param, void *data, int type) {
|
||||
SVnodeObj *pVnode = param;
|
||||
SWalHead * pHead = data;
|
||||
int32_t vnodeWriteToWQueue(void *vparam, void *wparam, int32_t qtype, void *rparam) {
|
||||
SVnodeObj *pVnode = vparam;
|
||||
SWalHead * pHead = wparam;
|
||||
|
||||
int size = sizeof(SWalHead) + pHead->len;
|
||||
SSyncHead *pSync = (SSyncHead*) taosAllocateQitem(size + sizeof(SSyncHead));
|
||||
SWalHead *pWal = (SWalHead *)(pSync + 1);
|
||||
memcpy(pWal, pHead, size);
|
||||
if (qtype == TAOS_QTYPE_RPC) {
|
||||
int32_t code = vnodeCheckWrite(pVnode);
|
||||
if (code != TSDB_CODE_SUCCESS) return code;
|
||||
}
|
||||
|
||||
atomic_add_fetch_32(&pVnode->refCount, 1);
|
||||
vTrace("CQ: vgId:%d, get vnode wqueue, refCount:%d pVnode:%p", pVnode->vgId, pVnode->refCount, pVnode);
|
||||
int32_t size = sizeof(SVWriteMsg) + sizeof(SWalHead) + pHead->len;
|
||||
SVWriteMsg *pWrite = taosAllocateQitem(size);
|
||||
if (pWrite == NULL) {
|
||||
return TSDB_CODE_VND_OUT_OF_MEMORY;
|
||||
}
|
||||
|
||||
taosWriteQitem(pVnode->wqueue, type, pSync);
|
||||
if (rparam != NULL) {
|
||||
SRpcMsg *pRpcMsg = rparam;
|
||||
pWrite->rpcHandle = pRpcMsg->handle;
|
||||
pWrite->rpcAhandle = pRpcMsg->ahandle;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int vnodeWriteToQueue(void *param, void *data, int type) {
|
||||
SVnodeObj *pVnode = param;
|
||||
SWalHead * pHead = data;
|
||||
|
||||
int size = sizeof(SWalHead) + pHead->len;
|
||||
SWalHead *pWal = (SWalHead *)taosAllocateQitem(size);
|
||||
memcpy(pWal, pHead, size);
|
||||
memcpy(pWrite->pHead, pHead, sizeof(SWalHead) + pHead->len);
|
||||
|
||||
atomic_add_fetch_32(&pVnode->refCount, 1);
|
||||
vTrace("vgId:%d, get vnode wqueue, refCount:%d pVnode:%p", pVnode->vgId, pVnode->refCount, pVnode);
|
||||
|
||||
taosWriteQitem(pVnode->wqueue, type, pWal);
|
||||
|
||||
return 0;
|
||||
taosWriteQitem(pVnode->wqueue, qtype, pWrite);
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
|
|
@ -43,6 +43,7 @@ extern int32_t wDebugFlag;
|
|||
typedef struct {
|
||||
uint64_t version;
|
||||
int64_t fileId;
|
||||
int64_t rid;
|
||||
int32_t vgId;
|
||||
int32_t fd;
|
||||
int32_t keep;
|
||||
|
|
|
@ -70,7 +70,7 @@ void *walOpen(char *path, SWalCfg *pCfg) {
|
|||
tstrncpy(pWal->path, path, sizeof(pWal->path));
|
||||
pthread_mutex_init(&pWal->mutex, NULL);
|
||||
|
||||
pWal->fsyncSeq = pCfg->fsyncPeriod % 1000;
|
||||
pWal->fsyncSeq = pCfg->fsyncPeriod / 1000;
|
||||
if (pWal->fsyncSeq <= 0) pWal->fsyncSeq = 1;
|
||||
|
||||
if (walInitObj(pWal) != TSDB_CODE_SUCCESS) {
|
||||
|
@ -78,7 +78,8 @@ void *walOpen(char *path, SWalCfg *pCfg) {
|
|||
return NULL;
|
||||
}
|
||||
|
||||
if (taosAddRef(tsWal.refId, pWal) != TSDB_CODE_SUCCESS) {
|
||||
pWal->rid = taosAddRef(tsWal.refId, pWal);
|
||||
if (pWal->rid < 0) {
|
||||
walFreeObj(pWal);
|
||||
return NULL;
|
||||
}
|
||||
|
@ -143,7 +144,7 @@ void walClose(void *handle) {
|
|||
}
|
||||
|
||||
pthread_mutex_unlock(&pWal->mutex);
|
||||
taosRemoveRef(tsWal.refId, pWal);
|
||||
taosRemoveRef(tsWal.refId, pWal->rid);
|
||||
}
|
||||
|
||||
static int32_t walInitObj(SWal *pWal) {
|
||||
|
@ -185,7 +186,7 @@ static void walUpdateSeq() {
|
|||
}
|
||||
|
||||
static void walFsyncAll() {
|
||||
SWal *pWal = taosIterateRef(tsWal.refId, NULL);
|
||||
SWal *pWal = taosIterateRef(tsWal.refId, 0);
|
||||
while (pWal) {
|
||||
if (walNeedFsync(pWal)) {
|
||||
wTrace("vgId:%d, do fsync, level:%d seq:%d rseq:%d", pWal->vgId, pWal->level, pWal->fsyncSeq, tsWal.seq);
|
||||
|
@ -194,7 +195,7 @@ static void walFsyncAll() {
|
|||
wError("vgId:%d, file:%s, failed to fsync since %s", pWal->vgId, pWal->name, strerror(code));
|
||||
}
|
||||
}
|
||||
pWal = taosIterateRef(tsWal.refId, pWal);
|
||||
pWal = taosIterateRef(tsWal.refId, pWal->rid);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -111,18 +111,19 @@ int32_t walWrite(void *handle, SWalHead *pHead) {
|
|||
return code;
|
||||
}
|
||||
|
||||
void walFsync(void *handle) {
|
||||
void walFsync(void *handle, bool forceFsync) {
|
||||
SWal *pWal = handle;
|
||||
if (pWal == NULL || pWal->level != TAOS_WAL_FSYNC || pWal->fd < 0) return;
|
||||
if (pWal == NULL || pWal->fd < 0) return;
|
||||
|
||||
if (pWal->fsyncPeriod == 0) {
|
||||
if (forceFsync || (pWal->level == TAOS_WAL_FSYNC && pWal->fsyncPeriod == 0)) {
|
||||
wTrace("vgId:%d, file:%s, do fsync", pWal->vgId, pWal->name);
|
||||
if (fsync(pWal->fd) < 0) {
|
||||
wError("vgId:%d, file:%s, fsync failed since %s", pWal->vgId, pWal->name, strerror(errno));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int32_t walRestore(void *handle, void *pVnode, int32_t (*writeFp)(void *, void *, int32_t)) {
|
||||
int32_t walRestore(void *handle, void *pVnode, FWalWrite writeFp) {
|
||||
if (handle == NULL) return -1;
|
||||
|
||||
SWal * pWal = handle;
|
||||
|
@ -143,12 +144,7 @@ int32_t walRestore(void *handle, void *pVnode, int32_t (*writeFp)(void *, void *
|
|||
continue;
|
||||
}
|
||||
|
||||
if (!pWal->keep) {
|
||||
wDebug("vgId:%d, file:%s, restore success, remove this file", pWal->vgId, walName);
|
||||
remove(walName);
|
||||
} else {
|
||||
wDebug("vgId:%d, file:%s, restore success and keep it", pWal->vgId, walName);
|
||||
}
|
||||
wDebug("vgId:%d, file:%s, restore success and keep it", pWal->vgId, walName);
|
||||
|
||||
count++;
|
||||
}
|
||||
|
@ -305,9 +301,8 @@ static int32_t walRestoreWalFile(SWal *pWal, void *pVnode, FWalWrite writeFp, ch
|
|||
wTrace("vgId:%d, fileId:%" PRId64 ", restore wal ver:%" PRIu64 ", head ver:%" PRIu64 " len:%d", pWal->vgId, fileId,
|
||||
pWal->version, pHead->version, pHead->len);
|
||||
|
||||
if (pWal->keep) pWal->version = pHead->version;
|
||||
|
||||
(*writeFp)(pVnode, pHead, TAOS_QTYPE_WAL);
|
||||
pWal->version = pHead->version;
|
||||
(*writeFp)(pVnode, pHead, TAOS_QTYPE_WAL, NULL);
|
||||
}
|
||||
|
||||
tclose(fd);
|
||||
|
|
|
@ -23,7 +23,7 @@
|
|||
int64_t ver = 0;
|
||||
void *pWal = NULL;
|
||||
|
||||
int writeToQueue(void *pVnode, void *data, int type) {
|
||||
int writeToQueue(void *pVnode, void *data, int type, void *pMsg) {
|
||||
// do nothing
|
||||
SWalHead *pHead = data;
|
||||
|
||||
|
|
|
@ -9,26 +9,40 @@
|
|||
|
||||
|
||||
static void prepare_data(TAOS* taos) {
|
||||
taos_query(taos, "drop database if exists test;");
|
||||
TAOS_RES *result;
|
||||
result = taos_query(taos, "drop database if exists test;");
|
||||
taos_free_result(result);
|
||||
usleep(100000);
|
||||
taos_query(taos, "create database test;");
|
||||
result = taos_query(taos, "create database test;");
|
||||
taos_free_result(result);
|
||||
usleep(100000);
|
||||
taos_select_db(taos, "test");
|
||||
|
||||
taos_query(taos, "create table meters(ts timestamp, a int) tags(area int);");
|
||||
result = taos_query(taos, "create table meters(ts timestamp, a int) tags(area int);");
|
||||
taos_free_result(result);
|
||||
|
||||
taos_query(taos, "create table t0 using meters tags(0);");
|
||||
taos_query(taos, "create table t1 using meters tags(1);");
|
||||
taos_query(taos, "create table t2 using meters tags(2);");
|
||||
taos_query(taos, "create table t3 using meters tags(3);");
|
||||
taos_query(taos, "create table t4 using meters tags(4);");
|
||||
taos_query(taos, "create table t5 using meters tags(5);");
|
||||
taos_query(taos, "create table t6 using meters tags(6);");
|
||||
taos_query(taos, "create table t7 using meters tags(7);");
|
||||
taos_query(taos, "create table t8 using meters tags(8);");
|
||||
taos_query(taos, "create table t9 using meters tags(9);");
|
||||
result = taos_query(taos, "create table t0 using meters tags(0);");
|
||||
taos_free_result(result);
|
||||
result = taos_query(taos, "create table t1 using meters tags(1);");
|
||||
taos_free_result(result);
|
||||
result = taos_query(taos, "create table t2 using meters tags(2);");
|
||||
taos_free_result(result);
|
||||
result = taos_query(taos, "create table t3 using meters tags(3);");
|
||||
taos_free_result(result);
|
||||
result = taos_query(taos, "create table t4 using meters tags(4);");
|
||||
taos_free_result(result);
|
||||
result = taos_query(taos, "create table t5 using meters tags(5);");
|
||||
taos_free_result(result);
|
||||
result = taos_query(taos, "create table t6 using meters tags(6);");
|
||||
taos_free_result(result);
|
||||
result = taos_query(taos, "create table t7 using meters tags(7);");
|
||||
taos_free_result(result);
|
||||
result = taos_query(taos, "create table t8 using meters tags(8);");
|
||||
taos_free_result(result);
|
||||
result = taos_query(taos, "create table t9 using meters tags(9);");
|
||||
taos_free_result(result);
|
||||
|
||||
TAOS_RES* res = taos_query(taos, "insert into t0 values('2020-01-01 00:00:00.000', 0)"
|
||||
result = taos_query(taos, "insert into t0 values('2020-01-01 00:00:00.000', 0)"
|
||||
" ('2020-01-01 00:01:00.000', 0)"
|
||||
" ('2020-01-01 00:02:00.000', 0)"
|
||||
" t1 values('2020-01-01 00:00:00.000', 0)"
|
||||
|
@ -46,10 +60,11 @@ static void prepare_data(TAOS* taos) {
|
|||
" t7 values('2020-01-01 00:01:02.000', 0)"
|
||||
" t8 values('2020-01-01 00:01:02.000', 0)"
|
||||
" t9 values('2020-01-01 00:01:02.000', 0)");
|
||||
int affected = taos_affected_rows(res);
|
||||
int affected = taos_affected_rows(result);
|
||||
if (affected != 18) {
|
||||
printf("\033[31m%d rows affected by last insert statement, but it should be 18\033[0m\n", affected);
|
||||
}
|
||||
taos_free_result(result);
|
||||
// super tables subscription
|
||||
usleep(1000000);
|
||||
}
|
||||
|
@ -135,6 +150,7 @@ static void verify_query(TAOS* taos) {
|
|||
|
||||
res = taos_query(taos, "select * from meters");
|
||||
taos_stop_query(res);
|
||||
taos_free_result(res);
|
||||
}
|
||||
|
||||
|
||||
|
@ -153,23 +169,30 @@ static void verify_subscribe(TAOS* taos) {
|
|||
res = taos_consume(tsub);
|
||||
check_row_count(__LINE__, res, 0);
|
||||
|
||||
taos_query(taos, "insert into t0 values('2020-01-01 00:02:00.001', 0);");
|
||||
taos_query(taos, "insert into t8 values('2020-01-01 00:01:03.000', 0);");
|
||||
TAOS_RES *result;
|
||||
result = taos_query(taos, "insert into t0 values('2020-01-01 00:02:00.001', 0);");
|
||||
taos_free_result(result);
|
||||
result = taos_query(taos, "insert into t8 values('2020-01-01 00:01:03.000', 0);");
|
||||
taos_free_result(result);
|
||||
res = taos_consume(tsub);
|
||||
check_row_count(__LINE__, res, 2);
|
||||
|
||||
taos_query(taos, "insert into t2 values('2020-01-01 00:01:02.001', 0);");
|
||||
taos_query(taos, "insert into t1 values('2020-01-01 00:03:00.001', 0);");
|
||||
result = taos_query(taos, "insert into t2 values('2020-01-01 00:01:02.001', 0);");
|
||||
taos_free_result(result);
|
||||
result = taos_query(taos, "insert into t1 values('2020-01-01 00:03:00.001', 0);");
|
||||
taos_free_result(result);
|
||||
res = taos_consume(tsub);
|
||||
check_row_count(__LINE__, res, 2);
|
||||
|
||||
taos_query(taos, "insert into t1 values('2020-01-01 00:03:00.002', 0);");
|
||||
result = taos_query(taos, "insert into t1 values('2020-01-01 00:03:00.002', 0);");
|
||||
taos_free_result(result);
|
||||
res = taos_consume(tsub);
|
||||
check_row_count(__LINE__, res, 1);
|
||||
|
||||
// keep progress information and restart subscription
|
||||
taos_unsubscribe(tsub, 1);
|
||||
taos_query(taos, "insert into t0 values('2020-01-01 00:04:00.000', 0);");
|
||||
result = taos_query(taos, "insert into t0 values('2020-01-01 00:04:00.000', 0);");
|
||||
taos_free_result(result);
|
||||
tsub = taos_subscribe(taos, 1, "test", "select * from meters;", NULL, NULL, 0);
|
||||
res = taos_consume(tsub);
|
||||
check_row_count(__LINE__, res, 24);
|
||||
|
@ -196,7 +219,8 @@ static void verify_subscribe(TAOS* taos) {
|
|||
res = taos_consume(tsub);
|
||||
check_row_count(__LINE__, res, 0);
|
||||
|
||||
taos_query(taos, "insert into t0 values('2020-01-01 00:04:00.001', 0);");
|
||||
result = taos_query(taos, "insert into t0 values('2020-01-01 00:04:00.001', 0);");
|
||||
taos_free_result(result);
|
||||
res = taos_consume(tsub);
|
||||
check_row_count(__LINE__, res, 1);
|
||||
|
||||
|
@ -205,7 +229,8 @@ static void verify_subscribe(TAOS* taos) {
|
|||
int blockFetch = 0;
|
||||
tsub = taos_subscribe(taos, 1, "test", "select * from meters;", subscribe_callback, &blockFetch, 1000);
|
||||
usleep(2000000);
|
||||
taos_query(taos, "insert into t0 values('2020-01-01 00:05:00.001', 0);");
|
||||
result = taos_query(taos, "insert into t0 values('2020-01-01 00:05:00.001', 0);");
|
||||
taos_free_result(result);
|
||||
usleep(2000000);
|
||||
taos_unsubscribe(tsub, 0);
|
||||
}
|
||||
|
@ -213,8 +238,9 @@ static void verify_subscribe(TAOS* taos) {
|
|||
|
||||
void verify_prepare(TAOS* taos) {
|
||||
TAOS_RES* result = taos_query(taos, "drop database if exists test;");
|
||||
taos_free_result(result);
|
||||
usleep(100000);
|
||||
taos_query(taos, "create database test;");
|
||||
result = taos_query(taos, "create database test;");
|
||||
|
||||
int code = taos_errno(result);
|
||||
if (code != 0) {
|
||||
|
@ -429,7 +455,8 @@ void verify_stream(TAOS* taos) {
|
|||
NULL);
|
||||
printf("waiting for stream data\n");
|
||||
usleep(100000);
|
||||
taos_query(taos, "insert into t0 values(now, 0)(now+5s,1)(now+10s, 2);");
|
||||
TAOS_RES* result = taos_query(taos, "insert into t0 values(now, 0)(now+5s,1)(now+10s, 2);");
|
||||
taos_free_result(result);
|
||||
usleep(200000000);
|
||||
taos_close_stream(strm);
|
||||
}
|
||||
|
|
|
@ -46,6 +46,34 @@ void taos_insert_call_back(void *param, TAOS_RES *tres, int code);
|
|||
void taos_select_call_back(void *param, TAOS_RES *tres, int code);
|
||||
void taos_error(TAOS *taos);
|
||||
|
||||
static void queryDB(TAOS *taos, char *command) {
|
||||
int i;
|
||||
TAOS_RES *pSql = NULL;
|
||||
int32_t code = -1;
|
||||
|
||||
for (i = 0; i < 5; i++) {
|
||||
if (NULL != pSql) {
|
||||
taos_free_result(pSql);
|
||||
pSql = NULL;
|
||||
}
|
||||
|
||||
pSql = taos_query(taos, command);
|
||||
code = taos_errno(pSql);
|
||||
if (0 == code) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (code != 0) {
|
||||
fprintf(stderr, "Failed to run %s, reason: %s\n", command, taos_errstr(pSql));
|
||||
taos_free_result(pSql);
|
||||
taos_close(taos);
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
taos_free_result(pSql);
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
TAOS *taos;
|
||||
|
@ -78,16 +106,14 @@ int main(int argc, char *argv[])
|
|||
|
||||
printf("success to connect to server\n");
|
||||
|
||||
sprintf(sql, "drop database %s", db);
|
||||
taos_query(taos, sql);
|
||||
sprintf(sql, "drop database if exists %s", db);
|
||||
queryDB(taos, sql);
|
||||
|
||||
sprintf(sql, "create database %s", db);
|
||||
if (taos_query(taos, sql) != 0)
|
||||
taos_error(taos);
|
||||
queryDB(taos, sql);
|
||||
|
||||
sprintf(sql, "use %s", db);
|
||||
if (taos_query(taos, sql) != 0)
|
||||
taos_error(taos);
|
||||
queryDB(taos, sql);
|
||||
|
||||
strcpy(prefix, "asytbl_");
|
||||
for (i = 0; i < numOfTables; ++i) {
|
||||
|
@ -95,8 +121,7 @@ int main(int argc, char *argv[])
|
|||
tableList[i].taos = taos;
|
||||
sprintf(tableList[i].name, "%s%d", prefix, i);
|
||||
sprintf(sql, "create table %s%d (ts timestamp, volume bigint)", prefix, i);
|
||||
if (taos_query(taos, sql) != 0)
|
||||
taos_error(taos);
|
||||
queryDB(taos, sql);
|
||||
}
|
||||
|
||||
gettimeofday(&systemTime, NULL);
|
||||
|
|
|
@ -22,6 +22,34 @@
|
|||
#include <inttypes.h>
|
||||
#include <taos.h> // TAOS header file
|
||||
|
||||
static void queryDB(TAOS *taos, char *command) {
|
||||
int i;
|
||||
TAOS_RES *pSql = NULL;
|
||||
int32_t code = -1;
|
||||
|
||||
for (i = 0; i < 5; i++) {
|
||||
if (NULL != pSql) {
|
||||
taos_free_result(pSql);
|
||||
pSql = NULL;
|
||||
}
|
||||
|
||||
pSql = taos_query(taos, command);
|
||||
code = taos_errno(pSql);
|
||||
if (0 == code) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (code != 0) {
|
||||
fprintf(stderr, "Failed to run %s, reason: %s\n", command, taos_errstr(pSql));
|
||||
taos_free_result(pSql);
|
||||
taos_close(taos);
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
taos_free_result(pSql);
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
TAOS * taos;
|
||||
char qstr[1024];
|
||||
|
@ -44,22 +72,26 @@ int main(int argc, char *argv[]) {
|
|||
printf("success to connect to server\n");
|
||||
|
||||
|
||||
taos_query(taos, "drop database demo");
|
||||
//taos_query(taos, "drop database demo");
|
||||
queryDB(taos, "drop database if exists demo");
|
||||
|
||||
result = taos_query(taos, "create database demo");
|
||||
if (result == NULL) {
|
||||
printf("failed to create database, reason:%s\n", "null result"/*taos_errstr(taos)*/);
|
||||
exit(1);
|
||||
}
|
||||
//result = taos_query(taos, "create database demo");
|
||||
//if (result == NULL) {
|
||||
// printf("failed to create database, reason:%s\n", "null result"/*taos_errstr(taos)*/);
|
||||
// exit(1);
|
||||
//}
|
||||
queryDB(taos, "create database demo");
|
||||
printf("success to create database\n");
|
||||
|
||||
taos_query(taos, "use demo");
|
||||
//taos_query(taos, "use demo");
|
||||
queryDB(taos, "use demo");
|
||||
|
||||
// create table
|
||||
if (taos_query(taos, "create table m1 (ts timestamp, ti tinyint, si smallint, i int, bi bigint, f float, d double, b binary(10))") == 0) {
|
||||
printf("failed to create table, reason:%s\n", taos_errstr(result));
|
||||
exit(1);
|
||||
}
|
||||
//if (taos_query(taos, "create table m1 (ts timestamp, ti tinyint, si smallint, i int, bi bigint, f float, d double, b binary(10))") == 0) {
|
||||
// printf("failed to create table, reason:%s\n", taos_errstr(result));
|
||||
// exit(1);
|
||||
//}
|
||||
queryDB(taos, "create table m1 (ts timestamp, ti tinyint, si smallint, i int, bi bigint, f float, d double, b binary(10))");
|
||||
printf("success to create table\n");
|
||||
|
||||
// sleep for one second to make sure table is created on data node
|
||||
|
@ -80,8 +112,10 @@ int main(int argc, char *argv[]) {
|
|||
printf("insert row: %i\n", i);
|
||||
} else {
|
||||
printf("failed to insert row: %i, reason:%s\n", i, "null result"/*taos_errstr(result)*/);
|
||||
taos_free_result(result);
|
||||
exit(1);
|
||||
}
|
||||
taos_free_result(result);
|
||||
|
||||
//sleep(1);
|
||||
}
|
||||
|
@ -91,7 +125,8 @@ int main(int argc, char *argv[]) {
|
|||
sprintf(qstr, "SELECT * FROM m1");
|
||||
result = taos_query(taos, qstr);
|
||||
if (result == NULL || taos_errno(result) != 0) {
|
||||
printf("failed to select, reason:%s\n", taos_errstr(result));
|
||||
printf("failed to select, reason:%s\n", taos_errstr(result));
|
||||
taos_free_result(result);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
|
|
|
@ -0,0 +1,71 @@
|
|||
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
import random
|
||||
import string
|
||||
import subprocess
|
||||
import sys
|
||||
from util.log import *
|
||||
from util.cases import *
|
||||
from util.sql import *
|
||||
|
||||
|
||||
class TDTestCase:
|
||||
def init(self, conn, logSql):
|
||||
tdLog.debug("start to execute %s" % __file__)
|
||||
tdSql.init(conn.cursor(), logSql)
|
||||
def run(self):
|
||||
tdLog.debug("check database")
|
||||
tdSql.prepare()
|
||||
|
||||
# check default update value
|
||||
sql = "create database if not exists db"
|
||||
tdSql.execute(sql)
|
||||
tdSql.query('show databases')
|
||||
tdSql.checkRows(1)
|
||||
tdSql.checkData(0,16,0)
|
||||
|
||||
sql = "alter database db update 1"
|
||||
|
||||
# check update value
|
||||
tdSql.execute(sql)
|
||||
tdSql.query('show databases')
|
||||
tdSql.checkRows(1)
|
||||
tdSql.checkData(0,16,1)
|
||||
|
||||
|
||||
sql = "alter database db update 0"
|
||||
tdSql.execute(sql)
|
||||
tdSql.query('show databases')
|
||||
tdSql.checkRows(1)
|
||||
tdSql.checkData(0,16,0)
|
||||
|
||||
sql = "alter database db update -1"
|
||||
tdSql.error(sql)
|
||||
|
||||
sql = "alter database db update 100"
|
||||
tdSql.error(sql)
|
||||
|
||||
tdSql.query('show databases')
|
||||
tdSql.checkRows(1)
|
||||
tdSql.checkData(0,16,0)
|
||||
|
||||
tdSql.execute('drop database db')
|
||||
tdSql.error('create database db update 100')
|
||||
tdSql.error('create database db update -1')
|
||||
|
||||
tdSql.execute('create database db update 1')
|
||||
|
||||
tdSql.query('show databases')
|
||||
tdSql.checkRows(1)
|
||||
tdSql.checkData(0,16,1)
|
||||
|
||||
tdSql.execute('drop database db')
|
||||
|
||||
def stop(self):
|
||||
tdSql.close()
|
||||
tdLog.success("%s successfully executed" % __file__)
|
||||
|
||||
|
||||
tdCases.addWindows(__file__, TDTestCase())
|
||||
tdCases.addLinux(__file__, TDTestCase())
|
|
@ -38,9 +38,9 @@ import resource
|
|||
from guppy import hpy
|
||||
import gc
|
||||
|
||||
from .service_manager import ServiceManager, TdeInstance
|
||||
from .misc import Logging, Status, CrashGenError, Dice, Helper, Progress
|
||||
from .db import DbConn, MyTDSql, DbConnNative, DbManager
|
||||
from crash_gen.service_manager import ServiceManager, TdeInstance
|
||||
from crash_gen.misc import Logging, Status, CrashGenError, Dice, Helper, Progress
|
||||
from crash_gen.db import DbConn, MyTDSql, DbConnNative, DbManager
|
||||
|
||||
import taos
|
||||
import requests
|
||||
|
@ -243,7 +243,7 @@ class WorkerThread:
|
|||
|
||||
|
||||
class ThreadCoordinator:
|
||||
WORKER_THREAD_TIMEOUT = 180 # one minute
|
||||
WORKER_THREAD_TIMEOUT = 120 # Normal: 120
|
||||
|
||||
def __init__(self, pool: ThreadPool, dbManager: DbManager):
|
||||
self._curStep = -1 # first step is 0
|
||||
|
@ -388,9 +388,9 @@ class ThreadCoordinator:
|
|||
self._syncAtBarrier() # For now just cross the barrier
|
||||
Progress.emit(Progress.END_THREAD_STEP)
|
||||
except threading.BrokenBarrierError as err:
|
||||
Logging.info("Main loop aborted, caused by worker thread time-out")
|
||||
Logging.info("Main loop aborted, caused by worker thread(s) time-out")
|
||||
self._execStats.registerFailure("Aborted due to worker thread timeout")
|
||||
print("\n\nWorker Thread time-out detected, important thread info:")
|
||||
print("\n\nWorker Thread time-out detected, TAOS related threads are:")
|
||||
ts = ThreadStacks()
|
||||
ts.print(filterInternal=True)
|
||||
workerTimeout = True
|
||||
|
@ -435,7 +435,7 @@ class ThreadCoordinator:
|
|||
Logging.debug("\r\n\n--> Main thread ready to finish up...")
|
||||
Logging.debug("Main thread joining all threads")
|
||||
self._pool.joinAll() # Get all threads to finish
|
||||
Logging.info("\nAll worker threads finished")
|
||||
Logging.info(". . . All worker threads finished") # No CR/LF before
|
||||
self._execStats.endExec()
|
||||
|
||||
def cleanup(self): # free resources
|
||||
|
@ -1072,17 +1072,18 @@ class Database:
|
|||
t3 = datetime.datetime(2012, 1, 1) # default "keep" is 10 years
|
||||
t4 = datetime.datetime.fromtimestamp(
|
||||
t3.timestamp() + elSec2) # see explanation above
|
||||
Logging.info("Setting up TICKS to start from: {}".format(t4))
|
||||
Logging.debug("Setting up TICKS to start from: {}".format(t4))
|
||||
return t4
|
||||
|
||||
@classmethod
|
||||
def getNextTick(cls):
|
||||
with cls._clsLock: # prevent duplicate tick
|
||||
if cls._lastLaggingTick==0:
|
||||
if cls._lastLaggingTick==0 or cls._lastTick==0 : # not initialized
|
||||
# 10k at 1/20 chance, should be enough to avoid overlaps
|
||||
cls._lastLaggingTick = cls.setupLastTick() + datetime.timedelta(0, -10000)
|
||||
if cls._lastTick==0: # should be quite a bit into the future
|
||||
cls._lastTick = cls.setupLastTick()
|
||||
tick = cls.setupLastTick()
|
||||
cls._lastTick = tick
|
||||
cls._lastLaggingTick = tick + datetime.timedelta(0, -10000)
|
||||
# if : # should be quite a bit into the future
|
||||
|
||||
if Dice.throw(20) == 0: # 1 in 20 chance, return lagging tick
|
||||
cls._lastLaggingTick += datetime.timedelta(0, 1) # Go back in time 100 seconds
|
||||
|
@ -1177,6 +1178,8 @@ class Task():
|
|||
instead. But a task is always associated with a DB
|
||||
'''
|
||||
taskSn = 100
|
||||
_lock = threading.Lock()
|
||||
_tableLocks: Dict[str, threading.Lock] = {}
|
||||
|
||||
@classmethod
|
||||
def allocTaskNum(cls):
|
||||
|
@ -1198,6 +1201,8 @@ class Task():
|
|||
self._execStats = execStats
|
||||
self._db = db # A task is always associated/for a specific DB
|
||||
|
||||
|
||||
|
||||
def isSuccess(self):
|
||||
return self._err is None
|
||||
|
||||
|
@ -1237,6 +1242,7 @@ class Task():
|
|||
0x0B, # Unable to establish connection, more details in TD-1648
|
||||
0x200, # invalid SQL, TODO: re-examine with TD-934
|
||||
0x20F, # query terminated, possibly due to vnoding being dropped, see TD-1776
|
||||
0x213, # "Disconnected from service", result of "kill connection ???"
|
||||
0x217, # "db not selected", client side defined error code
|
||||
# 0x218, # "Table does not exist" client side defined error code
|
||||
0x360, # Table already exists
|
||||
|
@ -1318,7 +1324,7 @@ class Task():
|
|||
self._err = err
|
||||
self._aborted = True
|
||||
except Exception as e:
|
||||
self.logInfo("Non-TAOS exception encountered")
|
||||
Logging.info("Non-TAOS exception encountered with: {}".format(self.__class__.__name__))
|
||||
self._err = e
|
||||
self._aborted = True
|
||||
traceback.print_exc()
|
||||
|
@ -1351,6 +1357,24 @@ class Task():
|
|||
def getQueryResult(self, wt: WorkerThread): # execute an SQL on the worker thread
|
||||
return wt.getQueryResult()
|
||||
|
||||
def lockTable(self, ftName): # full table name
|
||||
# print(" <<" + ftName + '_', end="", flush=True)
|
||||
with Task._lock:
|
||||
if not ftName in Task._tableLocks:
|
||||
Task._tableLocks[ftName] = threading.Lock()
|
||||
|
||||
Task._tableLocks[ftName].acquire()
|
||||
|
||||
def unlockTable(self, ftName):
|
||||
# print('_' + ftName + ">> ", end="", flush=True)
|
||||
with Task._lock:
|
||||
if not ftName in self._tableLocks:
|
||||
raise RuntimeError("Corrupt state, no such lock")
|
||||
lock = Task._tableLocks[ftName]
|
||||
if not lock.locked():
|
||||
raise RuntimeError("Corrupte state, already unlocked")
|
||||
lock.release()
|
||||
|
||||
|
||||
class ExecutionStats:
|
||||
def __init__(self):
|
||||
|
@ -1461,7 +1485,7 @@ class StateTransitionTask(Task):
|
|||
|
||||
_baseTableNumber = None
|
||||
|
||||
_endState = None
|
||||
_endState = None # TODO: no longter used?
|
||||
|
||||
@classmethod
|
||||
def getInfo(cls): # each sub class should supply their own information
|
||||
|
@ -1486,7 +1510,7 @@ class StateTransitionTask(Task):
|
|||
|
||||
@classmethod
|
||||
def getRegTableName(cls, i):
|
||||
if ( StateTransitionTask._baseTableNumber is None):
|
||||
if ( StateTransitionTask._baseTableNumber is None): # Set it one time
|
||||
StateTransitionTask._baseTableNumber = Dice.throw(
|
||||
999) if gConfig.dynamic_db_table_names else 0
|
||||
return "reg_table_{}".format(StateTransitionTask._baseTableNumber + i)
|
||||
|
@ -1544,8 +1568,11 @@ class TaskCreateSuperTable(StateTransitionTask):
|
|||
|
||||
sTable = self._db.getFixedSuperTable() # type: TdSuperTable
|
||||
# wt.execSql("use db") # should always be in place
|
||||
|
||||
sTable.create(wt.getDbConn(), self._db.getName(),
|
||||
{'ts':'timestamp', 'speed':'int'}, {'b':'binary(200)', 'f':'float'})
|
||||
{'ts':'timestamp', 'speed':'int'}, {'b':'binary(200)', 'f':'float'},
|
||||
dropIfExists = True
|
||||
)
|
||||
# self.execWtSql(wt,"create table db.{} (ts timestamp, speed int) tags (b binary(200), f float) ".format(tblName))
|
||||
# No need to create the regular tables, INSERT will do that
|
||||
# automatically
|
||||
|
@ -1558,14 +1585,41 @@ class TdSuperTable:
|
|||
def getName(self):
|
||||
return self._stName
|
||||
|
||||
def drop(self, dbc, dbName, skipCheck = False):
|
||||
if self.exists(dbc, dbName) : # if myself exists
|
||||
fullTableName = dbName + '.' + self._stName
|
||||
dbc.execute("DROP TABLE {}".format(fullTableName))
|
||||
else:
|
||||
if not skipCheck:
|
||||
raise CrashGenError("Cannot drop non-existant super table: {}".format(self._stName))
|
||||
|
||||
def exists(self, dbc, dbName):
|
||||
dbc.execute("USE " + dbName)
|
||||
return dbc.existsSuperTable(self._stName)
|
||||
|
||||
# TODO: odd semantic, create() method is usually static?
|
||||
def create(self, dbc, dbName, cols: dict, tags: dict):
|
||||
def create(self, dbc, dbName, cols: dict, tags: dict,
|
||||
dropIfExists = False
|
||||
):
|
||||
|
||||
'''Creating a super table'''
|
||||
sql = "CREATE TABLE {}.{} ({}) TAGS ({})".format(
|
||||
dbName,
|
||||
self._stName,
|
||||
",".join(['%s %s'%(k,v) for (k,v) in cols.items()]),
|
||||
",".join(['%s %s'%(k,v) for (k,v) in tags.items()])
|
||||
dbc.execute("USE " + dbName)
|
||||
fullTableName = dbName + '.' + self._stName
|
||||
if dbc.existsSuperTable(self._stName):
|
||||
if dropIfExists:
|
||||
dbc.execute("DROP TABLE {}".format(fullTableName))
|
||||
else: # error
|
||||
raise CrashGenError("Cannot create super table, already exists: {}".format(self._stName))
|
||||
|
||||
# Now let's create
|
||||
sql = "CREATE TABLE {} ({})".format(
|
||||
fullTableName,
|
||||
",".join(['%s %s'%(k,v) for (k,v) in cols.items()]))
|
||||
if tags is None :
|
||||
sql += " TAGS (dummy int) "
|
||||
else:
|
||||
sql += " TAGS ({})".format(
|
||||
",".join(['%s %s'%(k,v) for (k,v) in tags.items()])
|
||||
)
|
||||
dbc.execute(sql)
|
||||
|
||||
|
@ -1583,14 +1637,25 @@ class TdSuperTable:
|
|||
def hasRegTables(self, dbc: DbConn, dbName: str):
|
||||
return dbc.query("SELECT * FROM {}.{}".format(dbName, self._stName)) > 0
|
||||
|
||||
def ensureTable(self, dbc: DbConn, dbName: str, regTableName: str):
|
||||
def ensureTable(self, task: Task, dbc: DbConn, dbName: str, regTableName: str):
|
||||
sql = "select tbname from {}.{} where tbname in ('{}')".format(dbName, self._stName, regTableName)
|
||||
if dbc.query(sql) >= 1 : # reg table exists already
|
||||
return
|
||||
sql = "CREATE TABLE {}.{} USING {}.{} tags ({})".format(
|
||||
dbName, regTableName, dbName, self._stName, self._getTagStrForSql(dbc, dbName)
|
||||
)
|
||||
dbc.execute(sql)
|
||||
|
||||
# acquire a lock first, so as to be able to *verify*. More details in TD-1471
|
||||
fullTableName = dbName + '.' + regTableName
|
||||
if task is not None: # optional lock
|
||||
task.lockTable(fullTableName)
|
||||
Progress.emit(Progress.CREATE_TABLE_ATTEMPT) # ATTEMPT to create a new table
|
||||
# print("(" + fullTableName[-3:] + ")", end="", flush=True)
|
||||
try:
|
||||
sql = "CREATE TABLE {} USING {}.{} tags ({})".format(
|
||||
fullTableName, dbName, self._stName, self._getTagStrForSql(dbc, dbName)
|
||||
)
|
||||
dbc.execute(sql)
|
||||
finally:
|
||||
if task is not None:
|
||||
task.unlockTable(fullTableName) # no matter what
|
||||
|
||||
def _getTagStrForSql(self, dbc, dbName: str) :
|
||||
tags = self._getTags(dbc, dbName)
|
||||
|
@ -1809,7 +1874,7 @@ class TaskRestartService(StateTransitionTask):
|
|||
|
||||
with self._classLock:
|
||||
if self._isRunning:
|
||||
print("Skipping restart task, another running already")
|
||||
Logging.info("Skipping restart task, another running already")
|
||||
return
|
||||
self._isRunning = True
|
||||
|
||||
|
@ -1847,13 +1912,88 @@ class TaskAddData(StateTransitionTask):
|
|||
def canBeginFrom(cls, state: AnyState):
|
||||
return state.canAddData()
|
||||
|
||||
def _addDataInBatch(self, db, dbc, regTableName, te: TaskExecutor):
|
||||
numRecords = self.LARGE_NUMBER_OF_RECORDS if gConfig.larger_data else self.SMALL_NUMBER_OF_RECORDS
|
||||
fullTableName = db.getName() + '.' + regTableName
|
||||
|
||||
sql = "insert into {} values ".format(fullTableName)
|
||||
for j in range(numRecords): # number of records per table
|
||||
nextInt = db.getNextInt()
|
||||
nextTick = db.getNextTick()
|
||||
sql += "('{}', {});".format(nextTick, nextInt)
|
||||
dbc.execute(sql)
|
||||
|
||||
def _addData(self, db, dbc, regTableName, te: TaskExecutor): # implied: NOT in batches
|
||||
numRecords = self.LARGE_NUMBER_OF_RECORDS if gConfig.larger_data else self.SMALL_NUMBER_OF_RECORDS
|
||||
|
||||
for j in range(numRecords): # number of records per table
|
||||
nextInt = db.getNextInt()
|
||||
nextTick = db.getNextTick()
|
||||
if gConfig.record_ops:
|
||||
self.prepToRecordOps()
|
||||
self.fAddLogReady.write("Ready to write {} to {}\n".format(nextInt, regTableName))
|
||||
self.fAddLogReady.flush()
|
||||
os.fsync(self.fAddLogReady)
|
||||
|
||||
# TODO: too ugly trying to lock the table reliably, refactor...
|
||||
fullTableName = db.getName() + '.' + regTableName
|
||||
if gConfig.verify_data:
|
||||
self.lockTable(fullTableName)
|
||||
# print("_w" + str(nextInt % 100), end="", flush=True) # Trace what was written
|
||||
|
||||
try:
|
||||
sql = "insert into {} values ('{}', {});".format( # removed: tags ('{}', {})
|
||||
fullTableName,
|
||||
# ds.getFixedSuperTableName(),
|
||||
# ds.getNextBinary(), ds.getNextFloat(),
|
||||
nextTick, nextInt)
|
||||
dbc.execute(sql)
|
||||
except: # Any exception at all
|
||||
if gConfig.verify_data:
|
||||
self.unlockTable(fullTableName)
|
||||
raise
|
||||
|
||||
# Now read it back and verify, we might encounter an error if table is dropped
|
||||
if gConfig.verify_data: # only if command line asks for it
|
||||
try:
|
||||
readBack = dbc.queryScalar("SELECT speed from {}.{} WHERE ts='{}'".
|
||||
format(db.getName(), regTableName, nextTick))
|
||||
if readBack != nextInt :
|
||||
raise taos.error.ProgrammingError(
|
||||
"Failed to read back same data, wrote: {}, read: {}"
|
||||
.format(nextInt, readBack), 0x999)
|
||||
except taos.error.ProgrammingError as err:
|
||||
errno = Helper.convertErrno(err.errno)
|
||||
if errno in [0x991, 0x992] : # not a single result
|
||||
raise taos.error.ProgrammingError(
|
||||
"Failed to read back same data for tick: {}, wrote: {}, read: {}"
|
||||
.format(nextTick, nextInt, "Empty Result" if errno==0x991 else "Multiple Result"),
|
||||
errno)
|
||||
elif errno in [0x218, 0x362]: # table doesn't exist
|
||||
# do nothing
|
||||
dummy = 0
|
||||
else:
|
||||
# Re-throw otherwise
|
||||
raise
|
||||
finally:
|
||||
self.unlockTable(fullTableName) # Unlock the table no matter what
|
||||
|
||||
# Successfully wrote the data into the DB, let's record it somehow
|
||||
te.recordDataMark(nextInt)
|
||||
|
||||
if gConfig.record_ops:
|
||||
self.fAddLogDone.write("Wrote {} to {}\n".format(nextInt, regTableName))
|
||||
self.fAddLogDone.flush()
|
||||
os.fsync(self.fAddLogDone)
|
||||
|
||||
def _executeInternal(self, te: TaskExecutor, wt: WorkerThread):
|
||||
# ds = self._dbManager # Quite DANGEROUS here, may result in multi-thread client access
|
||||
db = self._db
|
||||
dbc = wt.getDbConn()
|
||||
tblSeq = list(range(
|
||||
self.LARGE_NUMBER_OF_TABLES if gConfig.larger_data else self.SMALL_NUMBER_OF_TABLES))
|
||||
random.shuffle(tblSeq)
|
||||
numTables = self.LARGE_NUMBER_OF_TABLES if gConfig.larger_data else self.SMALL_NUMBER_OF_TABLES
|
||||
numRecords = self.LARGE_NUMBER_OF_RECORDS if gConfig.larger_data else self.SMALL_NUMBER_OF_RECORDS
|
||||
tblSeq = list(range(numTables ))
|
||||
random.shuffle(tblSeq) # now we have random sequence
|
||||
for i in tblSeq:
|
||||
if (i in self.activeTable): # wow already active
|
||||
print("x", end="", flush=True) # concurrent insertion
|
||||
|
@ -1861,60 +2001,20 @@ class TaskAddData(StateTransitionTask):
|
|||
self.activeTable.add(i) # marking it active
|
||||
|
||||
sTable = db.getFixedSuperTable()
|
||||
regTableName = self.getRegTableName(i) # "db.reg_table_{}".format(i)
|
||||
sTable.ensureTable(wt.getDbConn(), db.getName(), regTableName) # Ensure the table exists
|
||||
regTableName = self.getRegTableName(i) # "db.reg_table_{}".format(i)
|
||||
fullTableName = db.getName() + '.' + regTableName
|
||||
# self._lockTable(fullTableName) # "create table" below. Stop it if the table is "locked"
|
||||
sTable.ensureTable(self, wt.getDbConn(), db.getName(), regTableName) # Ensure the table exists
|
||||
# self._unlockTable(fullTableName)
|
||||
|
||||
for j in range(self.LARGE_NUMBER_OF_RECORDS if gConfig.larger_data else self.SMALL_NUMBER_OF_RECORDS): # number of records per table
|
||||
nextInt = db.getNextInt()
|
||||
nextTick = db.getNextTick()
|
||||
if gConfig.record_ops:
|
||||
self.prepToRecordOps()
|
||||
self.fAddLogReady.write("Ready to write {} to {}\n".format(nextInt, regTableName))
|
||||
self.fAddLogReady.flush()
|
||||
os.fsync(self.fAddLogReady)
|
||||
sql = "insert into {}.{} values ('{}', {});".format( # removed: tags ('{}', {})
|
||||
db.getName(),
|
||||
regTableName,
|
||||
# ds.getFixedSuperTableName(),
|
||||
# ds.getNextBinary(), ds.getNextFloat(),
|
||||
nextTick, nextInt)
|
||||
dbc.execute(sql)
|
||||
# Successfully wrote the data into the DB, let's record it
|
||||
# somehow
|
||||
te.recordDataMark(nextInt)
|
||||
if gConfig.record_ops:
|
||||
self.fAddLogDone.write(
|
||||
"Wrote {} to {}\n".format(
|
||||
nextInt, regTableName))
|
||||
self.fAddLogDone.flush()
|
||||
os.fsync(self.fAddLogDone)
|
||||
|
||||
# Now read it back and verify, we might encounter an error if table is dropped
|
||||
if gConfig.verify_data: # only if command line asks for it
|
||||
try:
|
||||
readBack = dbc.queryScalar("SELECT speed from {}.{} WHERE ts= '{}'".
|
||||
format(db.getName(), regTableName, nextTick))
|
||||
if readBack != nextInt :
|
||||
raise taos.error.ProgrammingError(
|
||||
"Failed to read back same data, wrote: {}, read: {}"
|
||||
.format(nextInt, readBack), 0x999)
|
||||
except taos.error.ProgrammingError as err:
|
||||
errno = Helper.convertErrno(err.errno)
|
||||
if errno in [0x991, 0x992] : # not a single result
|
||||
raise taos.error.ProgrammingError(
|
||||
"Failed to read back same data for tick: {}, wrote: {}, read: {}"
|
||||
.format(nextTick, nextInt, "Empty Result" if errno==0x991 else "Multiple Result"),
|
||||
errno)
|
||||
# Re-throw no matter what
|
||||
raise
|
||||
|
||||
if Dice.throw(1) == 0: # 1 in 2 chance
|
||||
self._addData(db, dbc, regTableName, te)
|
||||
else:
|
||||
self._addDataInBatch(db, dbc, regTableName, te)
|
||||
|
||||
self.activeTable.discard(i) # not raising an error, unlike remove
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
class ThreadStacks: # stack info for all threads
|
||||
def __init__(self):
|
||||
self._allStacks = {}
|
||||
|
@ -1936,17 +2036,18 @@ class ThreadStacks: # stack info for all threads
|
|||
'__init__']: # the thread that extracted the stack
|
||||
continue # ignore
|
||||
# Now print
|
||||
print("\n<----- Thread Info for ID: {}".format(thNid))
|
||||
print("\n<----- Thread Info for LWP/ID: {} (Execution stopped at Bottom Frame) <-----".format(thNid))
|
||||
stackFrame = 0
|
||||
for frame in stack:
|
||||
# print(frame)
|
||||
print("File {filename}, line {lineno}, in {name}".format(
|
||||
filename=frame.filename, lineno=frame.lineno, name=frame.name))
|
||||
print("[{sf}] File {filename}, line {lineno}, in {name}".format(
|
||||
sf=stackFrame, filename=frame.filename, lineno=frame.lineno, name=frame.name))
|
||||
print(" {}".format(frame.line))
|
||||
print("-----> End of Thread Info\n")
|
||||
print("-----> End of Thread Info ----->\n")
|
||||
|
||||
class ClientManager:
|
||||
def __init__(self):
|
||||
print("Starting service manager")
|
||||
Logging.info("Starting service manager")
|
||||
# signal.signal(signal.SIGTERM, self.sigIntHandler)
|
||||
# signal.signal(signal.SIGINT, self.sigIntHandler)
|
||||
|
||||
|
@ -2048,7 +2149,7 @@ class ClientManager:
|
|||
thPool = ThreadPool(gConfig.num_threads, gConfig.max_steps)
|
||||
self.tc = ThreadCoordinator(thPool, dbManager)
|
||||
|
||||
print("Starting client instance to: {}".format(tInst))
|
||||
Logging.info("Starting client instance: {}".format(tInst))
|
||||
self.tc.run()
|
||||
# print("exec stats: {}".format(self.tc.getExecStats()))
|
||||
# print("TC failed = {}".format(self.tc.isFailed()))
|
|
@ -95,6 +95,11 @@ class DbConn:
|
|||
# print("dbs = {}, str = {}, ret2={}, type2={}".format(dbs, dbName,ret2, type(dbName)))
|
||||
return dbName in dbs # TODO: super weird type mangling seen, once here
|
||||
|
||||
def existsSuperTable(self, stName):
|
||||
self.query("show stables")
|
||||
sts = [v[0] for v in self.getQueryResult()]
|
||||
return stName in sts
|
||||
|
||||
def hasTables(self):
|
||||
return self.query("show tables") > 0
|
||||
|
||||
|
@ -240,6 +245,7 @@ class MyTDSql:
|
|||
|
||||
def _execInternal(self, sql):
|
||||
startTime = time.time()
|
||||
# Logging.debug("Executing SQL: " + sql)
|
||||
ret = self._cursor.execute(sql)
|
||||
# print("\nSQL success: {}".format(sql))
|
||||
queryTime = time.time() - startTime
|
||||
|
|
|
@ -27,7 +27,7 @@ class LoggingFilter(logging.Filter):
|
|||
|
||||
class MyLoggingAdapter(logging.LoggerAdapter):
|
||||
def process(self, msg, kwargs):
|
||||
return "[{}] {}".format(threading.get_ident() % 10000, msg), kwargs
|
||||
return "[{:04d}] {}".format(threading.get_ident() % 10000, msg), kwargs
|
||||
# return '[%s] %s' % (self.extra['connid'], msg), kwargs
|
||||
|
||||
|
||||
|
@ -51,7 +51,7 @@ class Logging:
|
|||
_logger.addHandler(ch)
|
||||
|
||||
# Logging adapter, to be used as a logger
|
||||
print("setting logger variable")
|
||||
# print("setting logger variable")
|
||||
# global logger
|
||||
cls.logger = MyLoggingAdapter(_logger, [])
|
||||
|
||||
|
@ -166,6 +166,9 @@ class Progress:
|
|||
SERVICE_RECONNECT_START = 4
|
||||
SERVICE_RECONNECT_SUCCESS = 5
|
||||
SERVICE_RECONNECT_FAILURE = 6
|
||||
SERVICE_START_NAP = 7
|
||||
CREATE_TABLE_ATTEMPT = 8
|
||||
|
||||
tokens = {
|
||||
STEP_BOUNDARY: '.',
|
||||
BEGIN_THREAD_STEP: '[',
|
||||
|
@ -174,6 +177,8 @@ class Progress:
|
|||
SERVICE_RECONNECT_START: '<r.',
|
||||
SERVICE_RECONNECT_SUCCESS: '.r>',
|
||||
SERVICE_RECONNECT_FAILURE: '.xr>',
|
||||
SERVICE_START_NAP: '_zz',
|
||||
CREATE_TABLE_ATTEMPT: '_c',
|
||||
}
|
||||
|
||||
@classmethod
|
||||
|
|
|
@ -47,6 +47,17 @@ class TdeInstance():
|
|||
.format(selfPath, projPath))
|
||||
return buildPath
|
||||
|
||||
@classmethod
|
||||
def prepareGcovEnv(cls, env):
|
||||
# Ref: https://gcc.gnu.org/onlinedocs/gcc/Cross-profiling.html
|
||||
bPath = cls._getBuildPath() # build PATH
|
||||
numSegments = len(bPath.split('/')) - 1 # "/x/TDengine/build" should yield 3
|
||||
numSegments = numSegments - 1 # DEBUG only
|
||||
env['GCOV_PREFIX'] = bPath + '/svc_gcov'
|
||||
env['GCOV_PREFIX_STRIP'] = str(numSegments) # Strip every element, plus, ENV needs strings
|
||||
Logging.info("Preparing GCOV environement to strip {} elements and use path: {}".format(
|
||||
numSegments, env['GCOV_PREFIX'] ))
|
||||
|
||||
def __init__(self, subdir='test', tInstNum=0, port=6030, fepPort=6030):
|
||||
self._buildDir = self._getBuildPath()
|
||||
self._subdir = '/' + subdir # TODO: tolerate "/"
|
||||
|
@ -217,6 +228,11 @@ class TdeSubProcess:
|
|||
# raise CrashGenError("Empty instance not allowed in TdeSubProcess")
|
||||
# self._tInst = tInst # Default create at ServiceManagerThread
|
||||
|
||||
def __repr__(self):
|
||||
if self.subProcess is None:
|
||||
return '[TdeSubProc: Empty]'
|
||||
return '[TdeSubProc: pid = {}]'.format(self.getPid())
|
||||
|
||||
def getStdOut(self):
|
||||
return self.subProcess.stdout
|
||||
|
||||
|
@ -235,17 +251,30 @@ class TdeSubProcess:
|
|||
# Sanity check
|
||||
if self.subProcess: # already there
|
||||
raise RuntimeError("Corrupt process state")
|
||||
|
||||
|
||||
# Prepare environment variables for coverage information
|
||||
# Ref: https://stackoverflow.com/questions/2231227/python-subprocess-popen-with-a-modified-environment
|
||||
myEnv = os.environ.copy()
|
||||
TdeInstance.prepareGcovEnv(myEnv)
|
||||
|
||||
# print(myEnv)
|
||||
# print(myEnv.items())
|
||||
# print("Starting TDengine via Shell: {}".format(cmdLineStr))
|
||||
|
||||
useShell = True
|
||||
self.subProcess = subprocess.Popen(
|
||||
cmdLine,
|
||||
shell=False,
|
||||
' '.join(cmdLine) if useShell else cmdLine,
|
||||
shell=useShell,
|
||||
# svcCmdSingle, shell=True, # capture core dump?
|
||||
stdout=subprocess.PIPE,
|
||||
stderr=subprocess.PIPE,
|
||||
# bufsize=1, # not supported in binary mode
|
||||
close_fds=ON_POSIX
|
||||
close_fds=ON_POSIX,
|
||||
env=myEnv
|
||||
) # had text=True, which interferred with reading EOF
|
||||
|
||||
STOP_SIGNAL = signal.SIGKILL # What signal to use (in kill) to stop a taosd process?
|
||||
|
||||
def stop(self):
|
||||
"""
|
||||
Stop a sub process, and try to return a meaningful return code.
|
||||
|
@ -267,7 +296,7 @@ class TdeSubProcess:
|
|||
SIGUSR2 12
|
||||
"""
|
||||
if not self.subProcess:
|
||||
print("Sub process already stopped")
|
||||
Logging.error("Sub process already stopped")
|
||||
return # -1
|
||||
|
||||
retCode = self.subProcess.poll() # ret -N means killed with signal N, otherwise it's from exit(N)
|
||||
|
@ -278,20 +307,25 @@ class TdeSubProcess:
|
|||
return retCode
|
||||
|
||||
# process still alive, let's interrupt it
|
||||
print("Terminate running process, send SIG_INT and wait...")
|
||||
# sub process should end, then IPC queue should end, causing IO thread to end
|
||||
# sig = signal.SIGINT
|
||||
sig = signal.SIGKILL
|
||||
self.subProcess.send_signal(sig) # SIGNINT or SIGKILL
|
||||
Logging.info("Terminate running process, send SIG_{} and wait...".format(self.STOP_SIGNAL))
|
||||
# sub process should end, then IPC queue should end, causing IO thread to end
|
||||
topSubProc = psutil.Process(self.subProcess.pid)
|
||||
for child in topSubProc.children(recursive=True): # or parent.children() for recursive=False
|
||||
child.send_signal(self.STOP_SIGNAL)
|
||||
time.sleep(0.2) # 200 ms
|
||||
# topSubProc.send_signal(sig) # now kill the main sub process (likely the Shell)
|
||||
|
||||
self.subProcess.send_signal(self.STOP_SIGNAL) # main sub process (likely the Shell)
|
||||
self.subProcess.wait(20)
|
||||
retCode = self.subProcess.returncode # should always be there
|
||||
# May throw subprocess.TimeoutExpired exception above, therefore
|
||||
# The process is guranteed to have ended by now
|
||||
self.subProcess = None
|
||||
if retCode != 0: # != (- signal.SIGINT):
|
||||
Logging.error("TSP.stop(): Failed to stop sub proc properly w/ SIG {}, retCode={}".format(sig, retCode))
|
||||
Logging.error("TSP.stop(): Failed to stop sub proc properly w/ SIG {}, retCode={}".format(
|
||||
self.STOP_SIGNAL, retCode))
|
||||
else:
|
||||
Logging.info("TSP.stop(): sub proc successfully terminated with SIG {}".format(sig))
|
||||
Logging.info("TSP.stop(): sub proc successfully terminated with SIG {}".format(self.STOP_SIGNAL))
|
||||
return - retCode
|
||||
|
||||
class ServiceManager:
|
||||
|
@ -439,7 +473,7 @@ class ServiceManager:
|
|||
|
||||
time.sleep(self.PAUSE_BETWEEN_IPC_CHECK) # pause, before next round
|
||||
# raise CrashGenError("dummy")
|
||||
print("Service Manager Thread (with subprocess) ended, main thread exiting...")
|
||||
Logging.info("Service Manager Thread (with subprocess) ended, main thread exiting...")
|
||||
|
||||
def _getFirstInstance(self):
|
||||
return self._tInsts[0]
|
||||
|
@ -452,7 +486,7 @@ class ServiceManager:
|
|||
# Find if there's already a taosd service, and then kill it
|
||||
for proc in psutil.process_iter():
|
||||
if proc.name() == 'taosd':
|
||||
print("Killing an existing TAOSD process in 2 seconds... press CTRL-C to interrupt")
|
||||
Logging.info("Killing an existing TAOSD process in 2 seconds... press CTRL-C to interrupt")
|
||||
time.sleep(2.0)
|
||||
proc.kill()
|
||||
# print("Process: {}".format(proc.name()))
|
||||
|
@ -559,7 +593,8 @@ class ServiceManagerThread:
|
|||
for i in range(0, 100):
|
||||
time.sleep(1.0)
|
||||
# self.procIpcBatch() # don't pump message during start up
|
||||
print("_zz_", end="", flush=True)
|
||||
Progress.emit(Progress.SERVICE_START_NAP)
|
||||
# print("_zz_", end="", flush=True)
|
||||
if self._status.isRunning():
|
||||
Logging.info("[] TDengine service READY to process requests")
|
||||
Logging.info("[] TAOS service started: {}".format(self))
|
||||
|
@ -595,12 +630,12 @@ class ServiceManagerThread:
|
|||
|
||||
def stop(self):
|
||||
# can be called from both main thread or signal handler
|
||||
print("Terminating TDengine service running as the sub process...")
|
||||
Logging.info("Terminating TDengine service running as the sub process...")
|
||||
if self.getStatus().isStopped():
|
||||
print("Service already stopped")
|
||||
Logging.info("Service already stopped")
|
||||
return
|
||||
if self.getStatus().isStopping():
|
||||
print("Service is already being stopped")
|
||||
Logging.info("Service is already being stopped")
|
||||
return
|
||||
# Linux will send Control-C generated SIGINT to the TDengine process
|
||||
# already, ref:
|
||||
|
@ -616,10 +651,10 @@ class ServiceManagerThread:
|
|||
if retCode == signal.SIGSEGV : # SGV
|
||||
Logging.error("[[--ERROR--]]: TDengine service SEGV fault (check core file!)")
|
||||
except subprocess.TimeoutExpired as err:
|
||||
print("Time out waiting for TDengine service process to exit")
|
||||
Logging.info("Time out waiting for TDengine service process to exit")
|
||||
else:
|
||||
if self._tdeSubProcess.isRunning(): # still running, should now never happen
|
||||
print("FAILED to stop sub process, it is still running... pid = {}".format(
|
||||
Logging.error("FAILED to stop sub process, it is still running... pid = {}".format(
|
||||
self._tdeSubProcess.getPid()))
|
||||
else:
|
||||
self._tdeSubProcess = None # not running any more
|
||||
|
@ -683,9 +718,9 @@ class ServiceManagerThread:
|
|||
return # we are done with THIS BATCH
|
||||
else: # got line, printing out
|
||||
if forceOutput:
|
||||
Logging.info(line)
|
||||
Logging.info('[TAOSD] ' + line)
|
||||
else:
|
||||
Logging.debug(line)
|
||||
Logging.debug('[TAOSD] ' + line)
|
||||
print(">", end="", flush=True)
|
||||
|
||||
_ProgressBars = ["--", "//", "||", "\\\\"]
|
||||
|
@ -728,11 +763,11 @@ class ServiceManagerThread:
|
|||
|
||||
# queue.put(line)
|
||||
# meaning sub process must have died
|
||||
Logging.info("\nEnd of stream detected for TDengine STDOUT: {}".format(self))
|
||||
Logging.info("EOF for TDengine STDOUT: {}".format(self))
|
||||
out.close()
|
||||
|
||||
def svcErrorReader(self, err: IO, queue):
|
||||
for line in iter(err.readline, b''):
|
||||
print("\nTDengine Service (taosd) ERROR (from stderr): {}".format(line))
|
||||
Logging.info("\nEnd of stream detected for TDengine STDERR: {}".format(self))
|
||||
Logging.info("TDengine STDERR: {}".format(line))
|
||||
Logging.info("EOF for TDengine STDERR: {}".format(self))
|
||||
err.close()
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue