mnode/qnode support QueryAutoQWorkerPool
This commit is contained in:
parent
26adfdd48d
commit
5040ff5bd9
|
@ -109,7 +109,7 @@ int64_t mndGetRoleTimeMs(SMnode *pMnode);
|
||||||
* @param pMsg The request msg.
|
* @param pMsg The request msg.
|
||||||
* @return int32_t 0 for success, -1 for failure.
|
* @return int32_t 0 for success, -1 for failure.
|
||||||
*/
|
*/
|
||||||
int32_t mndProcessRpcMsg(SRpcMsg *pMsg);
|
int32_t mndProcessRpcMsg(SRpcMsg *pMsg, SQueueInfo* pQueueInfo);
|
||||||
int32_t mndProcessSyncMsg(SRpcMsg *pMsg);
|
int32_t mndProcessSyncMsg(SRpcMsg *pMsg);
|
||||||
int32_t mndPreProcessQueryMsg(SRpcMsg *pMsg);
|
int32_t mndPreProcessQueryMsg(SRpcMsg *pMsg);
|
||||||
void mndPostProcessQueryMsg(SRpcMsg *pMsg);
|
void mndPostProcessQueryMsg(SRpcMsg *pMsg);
|
||||||
|
|
|
@ -60,7 +60,7 @@ int32_t qndGetLoad(SQnode *pQnode, SQnodeLoad *pLoad);
|
||||||
* @param pQnode The qnode object.
|
* @param pQnode The qnode object.
|
||||||
* @param pMsg The request message
|
* @param pMsg The request message
|
||||||
*/
|
*/
|
||||||
int32_t qndProcessQueryMsg(SQnode *pQnode, int64_t ts, SRpcMsg *pMsg);
|
int32_t qndProcessQueryMsg(SQnode *pQnode, SQueueInfo* pInfo, SRpcMsg *pMsg);
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
|
|
|
@ -49,7 +49,7 @@ typedef struct {
|
||||||
int32_t workerId;
|
int32_t workerId;
|
||||||
int32_t threadNum;
|
int32_t threadNum;
|
||||||
int64_t timestamp;
|
int64_t timestamp;
|
||||||
void *poolCb;
|
void *workerCb;
|
||||||
} SQueueInfo;
|
} SQueueInfo;
|
||||||
|
|
||||||
typedef enum {
|
typedef enum {
|
||||||
|
|
|
@ -84,18 +84,25 @@ void tWWorkerCleanup(SWWorkerPool *pool);
|
||||||
STaosQueue *tWWorkerAllocQueue(SWWorkerPool *pool, void *ahandle, FItems fp);
|
STaosQueue *tWWorkerAllocQueue(SWWorkerPool *pool, void *ahandle, FItems fp);
|
||||||
void tWWorkerFreeQueue(SWWorkerPool *pool, STaosQueue *queue);
|
void tWWorkerFreeQueue(SWWorkerPool *pool, STaosQueue *queue);
|
||||||
|
|
||||||
|
typedef enum SQWorkerPoolType {
|
||||||
|
QWORKER_POOL = 0,
|
||||||
|
QUERY_AUTO_QWORKER_POOL,
|
||||||
|
} SQWorkerPoolType;
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
const char *name;
|
const char *name;
|
||||||
int32_t min;
|
int32_t min;
|
||||||
int32_t max;
|
int32_t max;
|
||||||
FItem fp;
|
FItem fp;
|
||||||
void *param;
|
void *param;
|
||||||
|
SQWorkerPoolType poolType;
|
||||||
} SSingleWorkerCfg;
|
} SSingleWorkerCfg;
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
const char *name;
|
const char *name;
|
||||||
STaosQueue *queue;
|
STaosQueue *queue;
|
||||||
SQWorkerPool pool;
|
SQWorkerPoolType poolType; // default to QWORKER_POOL
|
||||||
|
void *pool;
|
||||||
} SSingleWorker;
|
} SSingleWorker;
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
|
@ -134,6 +141,8 @@ typedef struct SQueryAutoQWorkerPool {
|
||||||
|
|
||||||
int32_t activeN; // running workers and workers waiting at reading new queue msg
|
int32_t activeN; // running workers and workers waiting at reading new queue msg
|
||||||
int32_t runningN; // workers processing queue msgs, not include blocking/waitingA/waitingB workers.
|
int32_t runningN; // workers processing queue msgs, not include blocking/waitingA/waitingB workers.
|
||||||
|
TdThreadMutex activeLock;
|
||||||
|
|
||||||
|
|
||||||
int32_t waitingAfterBlockN; // workers that recovered from blocking but waiting for too many running workers
|
int32_t waitingAfterBlockN; // workers that recovered from blocking but waiting for too many running workers
|
||||||
TdThreadMutex waitingAfterBlockLock;
|
TdThreadMutex waitingAfterBlockLock;
|
||||||
|
|
|
@ -53,7 +53,7 @@ static void mmProcessRpcMsg(SQueueInfo *pInfo, SRpcMsg *pMsg) {
|
||||||
const STraceId *trace = &pMsg->info.traceId;
|
const STraceId *trace = &pMsg->info.traceId;
|
||||||
dGTrace("msg:%p, get from mnode queue, type:%s", pMsg, TMSG_INFO(pMsg->msgType));
|
dGTrace("msg:%p, get from mnode queue, type:%s", pMsg, TMSG_INFO(pMsg->msgType));
|
||||||
|
|
||||||
int32_t code = mndProcessRpcMsg(pMsg);
|
int32_t code = mndProcessRpcMsg(pMsg, pInfo);
|
||||||
|
|
||||||
if (pInfo->timestamp != 0) {
|
if (pInfo->timestamp != 0) {
|
||||||
int64_t cost = taosGetTimestampUs() - pInfo->timestamp;
|
int64_t cost = taosGetTimestampUs() - pInfo->timestamp;
|
||||||
|
@ -203,6 +203,7 @@ int32_t mmStartWorker(SMnodeMgmt *pMgmt) {
|
||||||
.name = "mnode-query",
|
.name = "mnode-query",
|
||||||
.fp = (FItem)mmProcessRpcMsg,
|
.fp = (FItem)mmProcessRpcMsg,
|
||||||
.param = pMgmt,
|
.param = pMgmt,
|
||||||
|
.poolType = QUERY_AUTO_QWORKER_POOL,
|
||||||
};
|
};
|
||||||
if (tSingleWorkerInit(&pMgmt->queryWorker, &qCfg) != 0) {
|
if (tSingleWorkerInit(&pMgmt->queryWorker, &qCfg) != 0) {
|
||||||
dError("failed to start mnode-query worker since %s", terrstr());
|
dError("failed to start mnode-query worker since %s", terrstr());
|
||||||
|
|
|
@ -30,7 +30,7 @@ static void qmProcessQueue(SQueueInfo *pInfo, SRpcMsg *pMsg) {
|
||||||
SQnodeMgmt *pMgmt = pInfo->ahandle;
|
SQnodeMgmt *pMgmt = pInfo->ahandle;
|
||||||
dTrace("msg:%p, get from qnode queue", pMsg);
|
dTrace("msg:%p, get from qnode queue", pMsg);
|
||||||
|
|
||||||
int32_t code = qndProcessQueryMsg(pMgmt->pQnode, pInfo->timestamp, pMsg);
|
int32_t code = qndProcessQueryMsg(pMgmt->pQnode, pInfo, pMsg);
|
||||||
if (IsReq(pMsg) && code != TSDB_CODE_ACTION_IN_PROGRESS) {
|
if (IsReq(pMsg) && code != TSDB_CODE_ACTION_IN_PROGRESS) {
|
||||||
if (code != 0 && terrno != 0) code = terrno;
|
if (code != 0 && terrno != 0) code = terrno;
|
||||||
qmSendRsp(pMsg, code);
|
qmSendRsp(pMsg, code);
|
||||||
|
@ -105,6 +105,7 @@ int32_t qmStartWorker(SQnodeMgmt *pMgmt) {
|
||||||
.name = "qnode-query",
|
.name = "qnode-query",
|
||||||
.fp = (FItem)qmProcessQueue,
|
.fp = (FItem)qmProcessQueue,
|
||||||
.param = pMgmt,
|
.param = pMgmt,
|
||||||
|
.poolType = QUERY_AUTO_QWORKER_POOL,
|
||||||
};
|
};
|
||||||
|
|
||||||
if (tSingleWorkerInit(&pMgmt->queryWorker, &queryCfg) != 0) {
|
if (tSingleWorkerInit(&pMgmt->queryWorker, &queryCfg) != 0) {
|
||||||
|
|
|
@ -54,6 +54,7 @@ extern "C" {
|
||||||
#define SYSTABLE_SCH_COL_NAME_LEN ((TSDB_COL_NAME_LEN - 1) + VARSTR_HEADER_SIZE)
|
#define SYSTABLE_SCH_COL_NAME_LEN ((TSDB_COL_NAME_LEN - 1) + VARSTR_HEADER_SIZE)
|
||||||
|
|
||||||
typedef int32_t (*MndMsgFp)(SRpcMsg *pMsg);
|
typedef int32_t (*MndMsgFp)(SRpcMsg *pMsg);
|
||||||
|
typedef int32_t (*MndMsgFpExt)(SRpcMsg *pMsg, SQueueInfo* pInfo);
|
||||||
typedef int32_t (*MndInitFp)(SMnode *pMnode);
|
typedef int32_t (*MndInitFp)(SMnode *pMnode);
|
||||||
typedef void (*MndCleanupFp)(SMnode *pMnode);
|
typedef void (*MndCleanupFp)(SMnode *pMnode);
|
||||||
typedef int32_t (*ShowRetrieveFp)(SRpcMsg *pMsg, SShowObj *pShow, SSDataBlock *pBlock, int32_t rows);
|
typedef int32_t (*ShowRetrieveFp)(SRpcMsg *pMsg, SShowObj *pShow, SSDataBlock *pBlock, int32_t rows);
|
||||||
|
@ -137,11 +138,13 @@ typedef struct SMnode {
|
||||||
SEncryptMgmt encryptMgmt;
|
SEncryptMgmt encryptMgmt;
|
||||||
SGrantInfo grant;
|
SGrantInfo grant;
|
||||||
MndMsgFp msgFp[TDMT_MAX];
|
MndMsgFp msgFp[TDMT_MAX];
|
||||||
|
MndMsgFpExt msgFpExt[TDMT_MAX];
|
||||||
SMsgCb msgCb;
|
SMsgCb msgCb;
|
||||||
int64_t ipWhiteVer;
|
int64_t ipWhiteVer;
|
||||||
} SMnode;
|
} SMnode;
|
||||||
|
|
||||||
void mndSetMsgHandle(SMnode *pMnode, tmsg_t msgType, MndMsgFp fp);
|
void mndSetMsgHandle(SMnode *pMnode, tmsg_t msgType, MndMsgFp fp);
|
||||||
|
void mndSetMsgHandleExt(SMnode *pMnode, tmsg_t msgType, MndMsgFpExt fp);
|
||||||
int64_t mndGenerateUid(const char *name, int32_t len);
|
int64_t mndGenerateUid(const char *name, int32_t len);
|
||||||
|
|
||||||
void mndSetRestored(SMnode *pMnode, bool restored);
|
void mndSetRestored(SMnode *pMnode, bool restored);
|
||||||
|
|
|
@ -844,21 +844,29 @@ _OVER:
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t mndProcessRpcMsg(SRpcMsg *pMsg) {
|
int32_t mndProcessRpcMsg(SRpcMsg *pMsg, SQueueInfo* pQueueInfo) {
|
||||||
SMnode *pMnode = pMsg->info.node;
|
SMnode *pMnode = pMsg->info.node;
|
||||||
const STraceId *trace = &pMsg->info.traceId;
|
const STraceId *trace = &pMsg->info.traceId;
|
||||||
|
int32_t code = TSDB_CODE_SUCCESS;
|
||||||
|
|
||||||
MndMsgFp fp = pMnode->msgFp[TMSG_INDEX(pMsg->msgType)];
|
MndMsgFp fp = pMnode->msgFp[TMSG_INDEX(pMsg->msgType)];
|
||||||
|
MndMsgFpExt fpExt = NULL;
|
||||||
if (fp == NULL) {
|
if (fp == NULL) {
|
||||||
mGError("msg:%p, failed to get msg handle, app:%p type:%s", pMsg, pMsg->info.ahandle, TMSG_INFO(pMsg->msgType));
|
fpExt = pMnode->msgFpExt[TMSG_INDEX(pMsg->msgType)];
|
||||||
terrno = TSDB_CODE_MSG_NOT_PROCESSED;
|
if (fpExt == NULL) {
|
||||||
return -1;
|
mGError("msg:%p, failed to get msg handle, app:%p type:%s", pMsg, pMsg->info.ahandle, TMSG_INFO(pMsg->msgType));
|
||||||
|
terrno = TSDB_CODE_MSG_NOT_PROCESSED;
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (mndCheckMnodeState(pMsg) != 0) return -1;
|
if (mndCheckMnodeState(pMsg) != 0) return -1;
|
||||||
|
|
||||||
mGTrace("msg:%p, start to process in mnode, app:%p type:%s", pMsg, pMsg->info.ahandle, TMSG_INFO(pMsg->msgType));
|
mGTrace("msg:%p, start to process in mnode, app:%p type:%s", pMsg, pMsg->info.ahandle, TMSG_INFO(pMsg->msgType));
|
||||||
int32_t code = (*fp)(pMsg);
|
if (fp)
|
||||||
|
code = (*fp)(pMsg);
|
||||||
|
else
|
||||||
|
code = (*fpExt)(pMsg, pQueueInfo);
|
||||||
mndReleaseRpc(pMnode);
|
mndReleaseRpc(pMnode);
|
||||||
|
|
||||||
if (code == TSDB_CODE_ACTION_IN_PROGRESS) {
|
if (code == TSDB_CODE_ACTION_IN_PROGRESS) {
|
||||||
|
@ -883,6 +891,13 @@ void mndSetMsgHandle(SMnode *pMnode, tmsg_t msgType, MndMsgFp fp) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void mndSetMsgHandleExt(SMnode *pMnode, tmsg_t msgType, MndMsgFpExt fp) {
|
||||||
|
tmsg_t type = TMSG_INDEX(msgType);
|
||||||
|
if (type < TDMT_MAX) {
|
||||||
|
pMnode->msgFpExt[type] = fp;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Note: uid 0 is reserved
|
// Note: uid 0 is reserved
|
||||||
int64_t mndGenerateUid(const char *name, int32_t len) {
|
int64_t mndGenerateUid(const char *name, int32_t len) {
|
||||||
int32_t hashval = MurmurHash3_32(name, len);
|
int32_t hashval = MurmurHash3_32(name, len);
|
||||||
|
|
|
@ -30,11 +30,11 @@ void mndPostProcessQueryMsg(SRpcMsg *pMsg) {
|
||||||
qWorkerAbortPreprocessQueryMsg(pMnode->pQuery, pMsg);
|
qWorkerAbortPreprocessQueryMsg(pMnode->pQuery, pMsg);
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t mndProcessQueryMsg(SRpcMsg *pMsg) {
|
int32_t mndProcessQueryMsg(SRpcMsg *pMsg, SQueueInfo* pInfo) {
|
||||||
int32_t code = -1;
|
int32_t code = -1;
|
||||||
SMnode *pMnode = pMsg->info.node;
|
SMnode *pMnode = pMsg->info.node;
|
||||||
|
|
||||||
SReadHandle handle = {.mnd = pMnode, .pMsgCb = &pMnode->msgCb};
|
SReadHandle handle = {.mnd = pMnode, .pMsgCb = &pMnode->msgCb, .pWorkerCb = pInfo->workerCb};
|
||||||
|
|
||||||
mTrace("msg:%p, in query queue is processing", pMsg);
|
mTrace("msg:%p, in query queue is processing", pMsg);
|
||||||
switch (pMsg->msgType) {
|
switch (pMsg->msgType) {
|
||||||
|
@ -173,14 +173,14 @@ int32_t mndInitQuery(SMnode *pMnode) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
mndSetMsgHandle(pMnode, TDMT_SCH_QUERY, mndProcessQueryMsg);
|
mndSetMsgHandleExt(pMnode, TDMT_SCH_QUERY, mndProcessQueryMsg);
|
||||||
mndSetMsgHandle(pMnode, TDMT_SCH_MERGE_QUERY, mndProcessQueryMsg);
|
mndSetMsgHandleExt(pMnode, TDMT_SCH_MERGE_QUERY, mndProcessQueryMsg);
|
||||||
mndSetMsgHandle(pMnode, TDMT_SCH_QUERY_CONTINUE, mndProcessQueryMsg);
|
mndSetMsgHandleExt(pMnode, TDMT_SCH_QUERY_CONTINUE, mndProcessQueryMsg);
|
||||||
mndSetMsgHandle(pMnode, TDMT_SCH_FETCH, mndProcessQueryMsg);
|
mndSetMsgHandleExt(pMnode, TDMT_SCH_FETCH, mndProcessQueryMsg);
|
||||||
mndSetMsgHandle(pMnode, TDMT_SCH_MERGE_FETCH, mndProcessQueryMsg);
|
mndSetMsgHandleExt(pMnode, TDMT_SCH_MERGE_FETCH, mndProcessQueryMsg);
|
||||||
mndSetMsgHandle(pMnode, TDMT_SCH_TASK_NOTIFY, mndProcessQueryMsg);
|
mndSetMsgHandleExt(pMnode, TDMT_SCH_TASK_NOTIFY, mndProcessQueryMsg);
|
||||||
mndSetMsgHandle(pMnode, TDMT_SCH_DROP_TASK, mndProcessQueryMsg);
|
mndSetMsgHandleExt(pMnode, TDMT_SCH_DROP_TASK, mndProcessQueryMsg);
|
||||||
mndSetMsgHandle(pMnode, TDMT_SCH_QUERY_HEARTBEAT, mndProcessQueryMsg);
|
mndSetMsgHandleExt(pMnode, TDMT_SCH_QUERY_HEARTBEAT, mndProcessQueryMsg);
|
||||||
mndSetMsgHandle(pMnode, TDMT_MND_BATCH_META, mndProcessBatchMetaMsg);
|
mndSetMsgHandle(pMnode, TDMT_MND_BATCH_META, mndProcessBatchMetaMsg);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
|
|
@ -29,7 +29,7 @@
|
||||||
extern "C" {
|
extern "C" {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
typedef struct SQueueWorker SQHandle;
|
typedef struct SQWorker SQHandle;
|
||||||
|
|
||||||
typedef struct SQnode {
|
typedef struct SQnode {
|
||||||
int32_t qndId;
|
int32_t qndId;
|
||||||
|
|
|
@ -13,6 +13,7 @@
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#include "tqueue.h"
|
||||||
#include "executor.h"
|
#include "executor.h"
|
||||||
#include "qndInt.h"
|
#include "qndInt.h"
|
||||||
#include "query.h"
|
#include "query.h"
|
||||||
|
@ -24,6 +25,7 @@ SQnode *qndOpen(const SQnodeOpt *pOption) {
|
||||||
qError("calloc SQnode failed");
|
qError("calloc SQnode failed");
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
pQnode->qndId = QNODE_HANDLE;
|
||||||
|
|
||||||
if (qWorkerInit(NODE_TYPE_QNODE, pQnode->qndId, (void **)&pQnode->pQuery, &pOption->msgCb)) {
|
if (qWorkerInit(NODE_TYPE_QNODE, pQnode->qndId, (void **)&pQnode->pQuery, &pOption->msgCb)) {
|
||||||
taosMemoryFreeClear(pQnode);
|
taosMemoryFreeClear(pQnode);
|
||||||
|
@ -72,9 +74,10 @@ int32_t qndPreprocessQueryMsg(SQnode *pQnode, SRpcMsg *pMsg) {
|
||||||
return qWorkerPreprocessQueryMsg(pQnode->pQuery, pMsg, false);
|
return qWorkerPreprocessQueryMsg(pQnode->pQuery, pMsg, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t qndProcessQueryMsg(SQnode *pQnode, int64_t ts, SRpcMsg *pMsg) {
|
int32_t qndProcessQueryMsg(SQnode *pQnode, SQueueInfo* pInfo, SRpcMsg *pMsg) {
|
||||||
int32_t code = -1;
|
int32_t code = -1;
|
||||||
SReadHandle handle = {.pMsgCb = &pQnode->msgCb};
|
int64_t ts = pInfo->timestamp;
|
||||||
|
SReadHandle handle = {.pMsgCb = &pQnode->msgCb, .pWorkerCb = pInfo->workerCb};
|
||||||
qTrace("message in qnode queue is processing");
|
qTrace("message in qnode queue is processing");
|
||||||
|
|
||||||
switch (pMsg->msgType) {
|
switch (pMsg->msgType) {
|
||||||
|
|
|
@ -747,7 +747,7 @@ int32_t vnodeProcessQueryMsg(SVnode *pVnode, SRpcMsg *pMsg, SQueueInfo* pInfo) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
SReadHandle handle = {.vnode = pVnode, .pMsgCb = &pVnode->msgCb, .pWorkerCb = pInfo->poolCb};
|
SReadHandle handle = {.vnode = pVnode, .pMsgCb = &pVnode->msgCb, .pWorkerCb = pInfo->workerCb};
|
||||||
initStorageAPI(&handle.api);
|
initStorageAPI(&handle.api);
|
||||||
|
|
||||||
switch (pMsg->msgType) {
|
switch (pMsg->msgType) {
|
||||||
|
|
|
@ -22,7 +22,6 @@
|
||||||
#include "ttime.h"
|
#include "ttime.h"
|
||||||
#include "tjson.h"
|
#include "tjson.h"
|
||||||
#include "tglobal.h"
|
#include "tglobal.h"
|
||||||
#include "mnode.h"
|
|
||||||
#include "audit.h"
|
#include "audit.h"
|
||||||
#include "osMemory.h"
|
#include "osMemory.h"
|
||||||
|
|
||||||
|
|
|
@ -976,14 +976,21 @@ int32_t handleLimitOffset(SOperatorInfo* pOperator, SLimitInfo* pLimitInfo, SSDa
|
||||||
|
|
||||||
static int32_t exchangeWait(SOperatorInfo* pOperator, SExchangeInfo* pExchangeInfo) {
|
static int32_t exchangeWait(SOperatorInfo* pOperator, SExchangeInfo* pExchangeInfo) {
|
||||||
SExecTaskInfo* pTask = pOperator->pTaskInfo;
|
SExecTaskInfo* pTask = pOperator->pTaskInfo;
|
||||||
|
int32_t code = TSDB_CODE_SUCCESS;
|
||||||
if (pTask->pWorkerCb) {
|
if (pTask->pWorkerCb) {
|
||||||
pTask->code = pTask->pWorkerCb->beforeBlocking(pTask->pWorkerCb->pPool);
|
code = pTask->pWorkerCb->beforeBlocking(pTask->pWorkerCb->pPool);
|
||||||
if (pTask->code != TSDB_CODE_SUCCESS) return pTask->code;
|
if (code != TSDB_CODE_SUCCESS) {
|
||||||
|
pTask->code = code;
|
||||||
|
return pTask->code;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
tsem_wait(&pExchangeInfo->ready);
|
tsem_wait(&pExchangeInfo->ready);
|
||||||
if (pTask->pWorkerCb) {
|
if (pTask->pWorkerCb) {
|
||||||
pTask->code = pTask->pWorkerCb->afterRecoverFromBlocking(pTask->pWorkerCb->pPool);
|
code = pTask->pWorkerCb->afterRecoverFromBlocking(pTask->pWorkerCb->pPool);
|
||||||
if (pTask->code != TSDB_CODE_SUCCESS) return pTask->code;
|
if (code != TSDB_CODE_SUCCESS) {
|
||||||
|
pTask->code = code;
|
||||||
|
return pTask->code;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return TSDB_CODE_SUCCESS;
|
return TSDB_CODE_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
|
@ -794,6 +794,7 @@ void qStopTaskOperators(SExecTaskInfo* pTaskInfo) {
|
||||||
SExchangeOpStopInfo* pStop = taosArrayGet(pTaskInfo->stopInfo.pStopInfo, i);
|
SExchangeOpStopInfo* pStop = taosArrayGet(pTaskInfo->stopInfo.pStopInfo, i);
|
||||||
SExchangeInfo* pExchangeInfo = taosAcquireRef(exchangeObjRefPool, pStop->refId);
|
SExchangeInfo* pExchangeInfo = taosAcquireRef(exchangeObjRefPool, pStop->refId);
|
||||||
if (pExchangeInfo) {
|
if (pExchangeInfo) {
|
||||||
|
qDebug("%s stop exchange operator", GET_TASKID(pTaskInfo));
|
||||||
tsem_post(&pExchangeInfo->ready);
|
tsem_post(&pExchangeInfo->ready);
|
||||||
taosReleaseRef(exchangeObjRefPool, pStop->refId);
|
taosReleaseRef(exchangeObjRefPool, pStop->refId);
|
||||||
}
|
}
|
||||||
|
|
|
@ -433,28 +433,66 @@ void tWWorkerFreeQueue(SWWorkerPool *pool, STaosQueue *queue) {
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t tSingleWorkerInit(SSingleWorker *pWorker, const SSingleWorkerCfg *pCfg) {
|
int32_t tSingleWorkerInit(SSingleWorker *pWorker, const SSingleWorkerCfg *pCfg) {
|
||||||
SQWorkerPool *pPool = &pWorker->pool;
|
pWorker->poolType = pCfg->poolType;
|
||||||
pPool->name = pCfg->name;
|
|
||||||
pPool->min = pCfg->min;
|
|
||||||
pPool->max = pCfg->max;
|
|
||||||
if (tQWorkerInit(pPool) != 0) return -1;
|
|
||||||
|
|
||||||
pWorker->queue = tQWorkerAllocQueue(pPool, pCfg->param, pCfg->fp);
|
|
||||||
if (pWorker->queue == NULL) return -1;
|
|
||||||
|
|
||||||
pWorker->name = pCfg->name;
|
pWorker->name = pCfg->name;
|
||||||
|
|
||||||
|
switch (pCfg->poolType) {
|
||||||
|
case QWORKER_POOL: {
|
||||||
|
SQWorkerPool *pPool = taosMemoryCalloc(1, sizeof(SQWorkerPool));
|
||||||
|
if (!pPool) {
|
||||||
|
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
pPool->name = pCfg->name;
|
||||||
|
pPool->min = pCfg->min;
|
||||||
|
pPool->max = pCfg->max;
|
||||||
|
pWorker->pool = pPool;
|
||||||
|
if (tQWorkerInit(pPool) != 0) return -1;
|
||||||
|
|
||||||
|
pWorker->queue = tQWorkerAllocQueue(pPool, pCfg->param, pCfg->fp);
|
||||||
|
if (pWorker->queue == NULL) return -1;
|
||||||
|
} break;
|
||||||
|
case QUERY_AUTO_QWORKER_POOL: {
|
||||||
|
SQueryAutoQWorkerPool *pPool = taosMemoryCalloc(1, sizeof(SQueryAutoQWorkerPool));
|
||||||
|
if (!pPool) {
|
||||||
|
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
pPool->name = pCfg->name;
|
||||||
|
pPool->min = pCfg->min;
|
||||||
|
pPool->max = pCfg->max;
|
||||||
|
pWorker->pool = pPool;
|
||||||
|
if (tQueryAutoQWorkerInit(pPool) != 0) return -1;
|
||||||
|
|
||||||
|
pWorker->queue = tQueryAutoQWorkerAllocQueue(pPool, pCfg->param, pCfg->fp);
|
||||||
|
if (!pWorker->queue) return -1;
|
||||||
|
} break;
|
||||||
|
default:
|
||||||
|
assert(0);
|
||||||
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void tSingleWorkerCleanup(SSingleWorker *pWorker) {
|
void tSingleWorkerCleanup(SSingleWorker *pWorker) {
|
||||||
if (pWorker->queue == NULL) return;
|
if (pWorker->queue == NULL) return;
|
||||||
|
|
||||||
while (!taosQueueEmpty(pWorker->queue)) {
|
while (!taosQueueEmpty(pWorker->queue)) {
|
||||||
taosMsleep(10);
|
taosMsleep(10);
|
||||||
}
|
}
|
||||||
|
|
||||||
tQWorkerCleanup(&pWorker->pool);
|
switch (pWorker->poolType) {
|
||||||
tQWorkerFreeQueue(&pWorker->pool, pWorker->queue);
|
case QWORKER_POOL:
|
||||||
|
tQWorkerCleanup(pWorker->pool);
|
||||||
|
tQWorkerFreeQueue(pWorker->pool, pWorker->queue);
|
||||||
|
taosMemoryFree(pWorker->pool);
|
||||||
|
break;
|
||||||
|
case QUERY_AUTO_QWORKER_POOL:
|
||||||
|
tQueryAutoQWorkerCleanup(pWorker->pool);
|
||||||
|
tQueryAutoQWorkerFreeQueue(pWorker->pool, pWorker->queue);
|
||||||
|
taosMemoryFree(pWorker->pool);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
assert(0);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t tMultiWorkerInit(SMultiWorker *pWorker, const SMultiWorkerCfg *pCfg) {
|
int32_t tMultiWorkerInit(SMultiWorker *pWorker, const SMultiWorkerCfg *pCfg) {
|
||||||
|
@ -517,7 +555,7 @@ static void *tQueryAutoQWorkerThreadFp(SQueryAutoQWorker *worker) {
|
||||||
if (qinfo.fp != NULL) {
|
if (qinfo.fp != NULL) {
|
||||||
qinfo.workerId = worker->id;
|
qinfo.workerId = worker->id;
|
||||||
qinfo.threadNum = pool->num;
|
qinfo.threadNum = pool->num;
|
||||||
qinfo.poolCb = pool->pCb;
|
qinfo.workerCb = pool->pCb;
|
||||||
(*((FItem)qinfo.fp))(&qinfo, msg);
|
(*((FItem)qinfo.fp))(&qinfo, msg);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -573,33 +611,38 @@ static bool tQueryAutoQWorkerTrySignalWaitingBeforeProcess(void* p) {
|
||||||
static bool tQueryAutoQWorkerTryDecActive(void* p, int32_t minActive) {
|
static bool tQueryAutoQWorkerTryDecActive(void* p, int32_t minActive) {
|
||||||
SQueryAutoQWorkerPool *pPool = p;
|
SQueryAutoQWorkerPool *pPool = p;
|
||||||
bool ret = false;
|
bool ret = false;
|
||||||
|
taosThreadMutexLock(&pPool->activeLock);
|
||||||
int32_t active = pPool->activeN;
|
int32_t active = pPool->activeN;
|
||||||
while (active > minActive) {
|
while (active > minActive) {
|
||||||
int32_t activeNew = atomic_val_compare_exchange_32(&pPool->activeN, active, active - 1);
|
int32_t activeNew = atomic_val_compare_exchange_32(&pPool->activeN, active, active - 1);
|
||||||
if (activeNew == active) {
|
if (activeNew == active) {
|
||||||
atomic_fetch_sub_32(&pPool->runningN, 1);
|
|
||||||
ret = true;
|
ret = true;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
active = activeNew;
|
active = activeNew;
|
||||||
}
|
}
|
||||||
|
atomic_fetch_sub_32(&pPool->runningN, 1);
|
||||||
|
taosThreadMutexUnlock(&pPool->activeLock);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int32_t tQueryAutoQWorkerWaitingCheck(SQueryAutoQWorkerPool* pPool) {
|
static int32_t tQueryAutoQWorkerWaitingCheck(SQueryAutoQWorkerPool* pPool) {
|
||||||
|
taosThreadMutexLock(&pPool->activeLock);
|
||||||
int32_t running = pPool->runningN;
|
int32_t running = pPool->runningN;
|
||||||
while (running < pPool->num) {
|
while (running < pPool->num) {
|
||||||
int32_t runningNew = atomic_val_compare_exchange_32(&pPool->runningN, running, running + 1);
|
int32_t runningNew = atomic_val_compare_exchange_32(&pPool->runningN, running, running + 1);
|
||||||
if (runningNew == running) {
|
if (runningNew == running) {
|
||||||
// to running
|
// to running
|
||||||
|
taosThreadMutexUnlock(&pPool->activeLock);
|
||||||
return TSDB_CODE_SUCCESS;
|
return TSDB_CODE_SUCCESS;
|
||||||
}
|
}
|
||||||
running = runningNew;
|
running = runningNew;
|
||||||
}
|
}
|
||||||
|
atomic_fetch_sub_32(&pPool->activeN, 1);
|
||||||
|
taosThreadMutexUnlock(&pPool->activeLock);
|
||||||
// to wait for process
|
// to wait for process
|
||||||
taosThreadMutexLock(&pPool->waitingBeforeProcessMsgLock);
|
taosThreadMutexLock(&pPool->waitingBeforeProcessMsgLock);
|
||||||
atomic_fetch_add_32(&pPool->waitingBeforeProcessMsgN, 1);
|
atomic_fetch_add_32(&pPool->waitingBeforeProcessMsgN, 1);
|
||||||
atomic_fetch_sub_32(&pPool->activeN, 1);
|
|
||||||
if (!pPool->exit) taosThreadCondWait(&pPool->waitingBeforeProcessMsgCond, &pPool->waitingBeforeProcessMsgLock);
|
if (!pPool->exit) taosThreadCondWait(&pPool->waitingBeforeProcessMsgCond, &pPool->waitingBeforeProcessMsgLock);
|
||||||
// recovered from waiting
|
// recovered from waiting
|
||||||
taosThreadMutexUnlock(&pPool->waitingBeforeProcessMsgLock);
|
taosThreadMutexUnlock(&pPool->waitingBeforeProcessMsgLock);
|
||||||
|
@ -650,7 +693,6 @@ bool tQueryAutoQWorkerTryRecycleWorker(SQueryAutoQWorkerPool* pPool, SQueryAutoQ
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
} else {
|
} else {
|
||||||
atomic_fetch_sub_32(&pPool->runningN, 1);
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -670,6 +712,7 @@ int32_t tQueryAutoQWorkerInit(SQueryAutoQWorkerPool *pool) {
|
||||||
(void)taosThreadMutexInit(&pool->backupLock, NULL);
|
(void)taosThreadMutexInit(&pool->backupLock, NULL);
|
||||||
(void)taosThreadMutexInit(&pool->waitingAfterBlockLock, NULL);
|
(void)taosThreadMutexInit(&pool->waitingAfterBlockLock, NULL);
|
||||||
(void)taosThreadMutexInit(&pool->waitingBeforeProcessMsgLock, NULL);
|
(void)taosThreadMutexInit(&pool->waitingBeforeProcessMsgLock, NULL);
|
||||||
|
(void)taosThreadMutexInit(&pool->activeLock, NULL);
|
||||||
|
|
||||||
(void)taosThreadCondInit(&pool->waitingBeforeProcessMsgCond, NULL);
|
(void)taosThreadCondInit(&pool->waitingBeforeProcessMsgCond, NULL);
|
||||||
(void)taosThreadCondInit(&pool->waitingAfterBlockCond, NULL);
|
(void)taosThreadCondInit(&pool->waitingAfterBlockCond, NULL);
|
||||||
|
@ -757,6 +800,7 @@ void tQueryAutoQWorkerCleanup(SQueryAutoQWorkerPool *pPool) {
|
||||||
taosThreadMutexDestroy(&pPool->backupLock);
|
taosThreadMutexDestroy(&pPool->backupLock);
|
||||||
taosThreadMutexDestroy(&pPool->waitingAfterBlockLock);
|
taosThreadMutexDestroy(&pPool->waitingAfterBlockLock);
|
||||||
taosThreadMutexDestroy(&pPool->waitingBeforeProcessMsgLock);
|
taosThreadMutexDestroy(&pPool->waitingBeforeProcessMsgLock);
|
||||||
|
taosThreadMutexDestroy(&pPool->activeLock);
|
||||||
|
|
||||||
taosThreadCondDestroy(&pPool->backupCond);
|
taosThreadCondDestroy(&pPool->backupCond);
|
||||||
taosThreadCondDestroy(&pPool->waitingAfterBlockCond);
|
taosThreadCondDestroy(&pPool->waitingAfterBlockCond);
|
||||||
|
@ -866,7 +910,6 @@ static int32_t tQueryAutoQWorkerBeforeBlocking(void *p) {
|
||||||
if (code != TSDB_CODE_SUCCESS) {
|
if (code != TSDB_CODE_SUCCESS) {
|
||||||
return code;
|
return code;
|
||||||
}
|
}
|
||||||
atomic_fetch_sub_32(&pPool->runningN, 1);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return TSDB_CODE_SUCCESS;
|
return TSDB_CODE_SUCCESS;
|
||||||
|
|
Loading…
Reference in New Issue