TDengine/source/dnode/vnode/impl/src/vnodeWrite.c

118 lines
3 KiB
C
Raw Normal View History

/*
* 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/>.
*/
2021-11-08 02:32:36 +00:00
#include "vnodeDef.h"
2021-12-17 05:40:27 +00:00
int vnodeProcessNoWalWMsgs(SVnode *pVnode, SRpcMsg *pMsg) {
SVnodeReq *pVnodeReq;
switch (pMsg->msgType) {
case TSDB_MSG_TYPE_MQ_SET:
if (tqSetCursor(pVnode->pTq, pMsg->pCont) < 0) {
// TODO: handle error
}
break;
}
void *pBuf = pMsg->pCont;
return 0;
}
2021-11-11 03:41:16 +00:00
int vnodeProcessWMsgs(SVnode *pVnode, SArray *pMsgs) {
2021-12-17 05:40:27 +00:00
SRpcMsg *pMsg;
2021-11-29 03:37:26 +00:00
SVnodeReq *pVnodeReq;
2021-11-17 08:45:42 +00:00
2021-11-29 03:37:26 +00:00
for (int i = 0; i < taosArrayGetSize(pMsgs); i++) {
pMsg = *(SRpcMsg **)taosArrayGet(pMsgs, i);
2021-11-17 08:45:42 +00:00
2021-11-29 03:37:26 +00:00
// ser request version
2021-12-17 05:40:27 +00:00
void *pBuf = pMsg->pCont;
int64_t ver = pVnode->state.processed++;
2021-11-30 03:24:13 +00:00
taosEncodeFixedU64(&pBuf, ver);
2021-11-29 03:37:26 +00:00
2021-12-01 02:27:22 +00:00
if (walWrite(pVnode->pWal, ver, pMsg->msgType, pMsg->pCont, pMsg->contLen) < 0) {
2021-11-29 03:37:26 +00:00
// TODO: handle error
}
2021-11-17 08:45:42 +00:00
}
2021-11-29 03:37:26 +00:00
walFsync(pVnode->pWal, false);
2021-11-08 02:32:36 +00:00
2021-11-29 03:37:26 +00:00
// Apply each request now
for (int i = 0; i < taosArrayGetSize(pMsgs); i++) {
pMsg = *(SRpcMsg **)taosArrayGet(pMsgs, i);
2021-11-29 08:59:18 +00:00
SVnodeReq vReq;
2021-11-09 03:22:25 +00:00
2021-11-29 03:37:26 +00:00
// Apply the request
{
void *ptr = vnodeMalloc(pVnode, pMsg->contLen);
if (ptr == NULL) {
// TODO: handle error
2021-11-17 07:02:42 +00:00
}
2021-11-29 03:37:26 +00:00
2021-11-29 08:59:18 +00:00
// TODO: copy here need to be extended
memcpy(ptr, pMsg->pCont, pMsg->contLen);
2021-11-29 03:37:26 +00:00
2021-11-30 03:24:13 +00:00
// todo: change the interface here
2021-11-29 08:59:18 +00:00
uint64_t ver;
taosDecodeFixedU64(pMsg->pCont, &ver);
if (tqPushMsg(pVnode->pTq, ptr, ver) < 0) {
2021-11-29 03:37:26 +00:00
// TODO: handle error
}
2021-11-29 08:59:18 +00:00
vnodeParseReq(pMsg->pCont, &vReq, pMsg->msgType);
2021-11-29 03:37:26 +00:00
switch (pMsg->msgType) {
case TSDB_MSG_TYPE_CREATE_TABLE:
2021-11-29 08:59:18 +00:00
if (metaCreateTable(pVnode->pMeta, &(vReq.ctReq)) < 0) {
2021-11-29 03:37:26 +00:00
// TODO: handle error
}
// TODO: maybe need to clear the requst struct
break;
case TSDB_MSG_TYPE_DROP_TABLE:
2021-11-29 08:59:18 +00:00
if (metaDropTable(pVnode->pMeta, vReq.dtReq.uid) < 0) {
2021-11-29 03:53:31 +00:00
// TODO: handle error
}
2021-11-29 03:37:26 +00:00
break;
case TSDB_MSG_TYPE_SUBMIT:
2021-12-15 08:24:43 +00:00
if (tsdbInsertData(pVnode->pTsdb, (SSubmitMsg *)ptr) < 0) {
// TODO: handle error
}
2021-11-29 03:37:26 +00:00
break;
default:
break;
2021-11-17 07:02:42 +00:00
}
2021-11-29 03:37:26 +00:00
2021-11-29 10:37:04 +00:00
pVnode->state.applied = ver;
}
2021-11-29 03:37:26 +00:00
// Check if it needs to commit
if (vnodeShouldCommit(pVnode)) {
if (vnodeAsyncCommit(pVnode) < 0) {
// TODO: handle error
2021-11-17 07:02:42 +00:00
}
2021-11-29 03:37:26 +00:00
}
2021-11-09 03:22:25 +00:00
}
2021-11-12 02:53:52 +00:00
return 0;
2021-11-08 02:58:46 +00:00
}
2021-11-29 03:37:26 +00:00
int vnodeApplyWMsg(SVnode *pVnode, SRpcMsg *pMsg, SRpcMsg **pRsp) {
// TODO
return 0;
}
2021-12-17 05:40:27 +00:00
/* ------------------------ STATIC METHODS ------------------------ */