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

102 lines
2.8 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-11-11 03:41:16 +00:00
int vnodeProcessWMsgs(SVnode *pVnode, SArray *pMsgs) {
2021-11-29 03:37:26 +00:00
SRpcMsg * pMsg;
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
pVnodeReq = (SVnodeReq *)(pMsg->pCont);
pVnodeReq->ver = pVnode->state.processed++;
if (walWrite(pVnode->pWal, pVnodeReq->ver, pVnodeReq->req, pMsg->contLen - sizeof(pVnodeReq->ver)) < 0) {
// 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);
pVnodeReq = (SVnodeReq *)(pMsg->pCont);
SVCreateTableReq ctReq;
2021-11-29 03:53:31 +00:00
SVDropTableReq dtReq;
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
memcpy(ptr, pVnodeReq, pMsg->contLen);
// todo: change the interface here
2021-11-29 03:53:31 +00:00
if (tqPushMsg(pVnode->pTq, ptr, pVnodeReq->ver) < 0) {
2021-11-29 03:37:26 +00:00
// TODO: handle error
}
switch (pMsg->msgType) {
case TSDB_MSG_TYPE_CREATE_TABLE:
2021-11-29 07:42:17 +00:00
vnodeParseCreateTableReq(pVnodeReq->req, &(ctReq));
2021-11-29 03:37:26 +00:00
if (metaCreateTable(pVnode->pMeta, &ctReq) < 0) {
// TODO: handle error
}
// TODO: maybe need to clear the requst struct
break;
case TSDB_MSG_TYPE_DROP_TABLE:
2021-11-29 07:42:17 +00:00
if (vnodeParseDropTableReq(pVnodeReq->req, &(dtReq)) < 0) {
2021-11-29 03:53:31 +00:00
// TODO: handle error
}
if (metaDropTable(pVnode->pMeta, dtReq.uid) < 0) {
// TODO: handle error
}
2021-11-29 03:37:26 +00:00
break;
case TSDB_MSG_TYPE_SUBMIT:
/* code */
break;
default:
break;
2021-11-17 07:02:42 +00:00
}
2021-11-29 03:37:26 +00:00
}
pVnode->state.applied = pVnodeReq->ver;
// 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-11-08 03:43:39 +00:00
/* ------------------------ STATIC METHODS ------------------------ */