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

148 lines
4.4 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/>.
*/
2022-01-20 02:45:15 +00:00
#include "tq.h"
2022-01-20 10:09:28 +00:00
#include "vnd.h"
2021-11-08 02:32:36 +00:00
2022-01-28 20:45:01 +00:00
#if 0
2021-12-17 05:40:27 +00:00
int vnodeProcessNoWalWMsgs(SVnode *pVnode, SRpcMsg *pMsg) {
switch (pMsg->msgType) {
2021-12-24 07:00:51 +00:00
case TDMT_VND_MQ_SET_CUR:
2021-12-17 05:40:27 +00:00
if (tqSetCursor(pVnode->pTq, pMsg->pCont) < 0) {
// TODO: handle error
}
break;
}
return 0;
}
2022-01-28 20:45:01 +00:00
#endif
2021-12-17 05:40:27 +00:00
2021-11-11 03:41:16 +00:00
int vnodeProcessWMsgs(SVnode *pVnode, SArray *pMsgs) {
2021-12-31 08:30:40 +00:00
SRpcMsg *pMsg;
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
2022-01-24 06:27:28 +00:00
void * pBuf = POINTER_SHIFT(pMsg->pCont, sizeof(SMsgHead));
2021-12-17 05:40:27 +00:00
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-12-20 09:11:50 +00:00
// TODO: Integrate RAFT module here
2021-12-20 08:52:39 +00:00
return 0;
}
int vnodeApplyWMsg(SVnode *pVnode, SRpcMsg *pMsg, SRpcMsg **pRsp) {
2021-12-31 08:30:40 +00:00
SVCreateTbReq vCreateTbReq;
SVCreateTbBatchReq vCreateTbBatchReq;
2022-01-24 06:27:28 +00:00
void * ptr = vnodeMalloc(pVnode, pMsg->contLen);
2021-12-20 08:52:39 +00:00
if (ptr == NULL) {
// TODO: handle error
}
2021-11-29 03:37:26 +00:00
2021-12-20 08:52:39 +00:00
// TODO: copy here need to be extended
memcpy(ptr, pMsg->pCont, pMsg->contLen);
// todo: change the interface here
uint64_t ver;
2021-12-25 08:54:28 +00:00
taosDecodeFixedU64(POINTER_SHIFT(pMsg->pCont, sizeof(SMsgHead)), &ver);
2021-12-20 08:52:39 +00:00
if (tqPushMsg(pVnode->pTq, ptr, ver) < 0) {
// TODO: handle error
}
2021-11-29 03:37:26 +00:00
2021-12-20 08:52:39 +00:00
switch (pMsg->msgType) {
2021-12-24 07:00:51 +00:00
case TDMT_VND_CREATE_STB:
2021-12-25 08:54:28 +00:00
tDeserializeSVCreateTbReq(POINTER_SHIFT(pMsg->pCont, sizeof(SMsgHead)), &vCreateTbReq);
if (metaCreateTable(pVnode->pMeta, &(vCreateTbReq)) < 0) {
2021-11-29 03:37:26 +00:00
// TODO: handle error
}
2021-12-20 08:52:39 +00:00
// TODO: maybe need to clear the requst struct
2022-01-24 06:27:28 +00:00
free(vCreateTbReq.stbCfg.pSchema);
free(vCreateTbReq.stbCfg.pTagSchema);
free(vCreateTbReq.name);
2021-12-20 08:52:39 +00:00
break;
2021-12-31 08:30:40 +00:00
case TDMT_VND_CREATE_TABLE:
tSVCreateTbBatchReqDeserialize(POINTER_SHIFT(pMsg->pCont, sizeof(SMsgHead)), &vCreateTbBatchReq);
for (int i = 0; i < taosArrayGetSize(vCreateTbBatchReq.pArray); i++) {
SVCreateTbReq *pCreateTbReq = taosArrayGet(vCreateTbBatchReq.pArray, i);
if (metaCreateTable(pVnode->pMeta, pCreateTbReq) < 0) {
// TODO: handle error
2022-01-21 08:15:35 +00:00
vError("vgId:%d, failed to create table: %s", pVnode->vgId, pCreateTbReq->name);
2021-12-31 08:30:40 +00:00
}
2022-01-17 03:58:39 +00:00
free(pCreateTbReq->name);
2022-01-12 01:55:37 +00:00
if (pCreateTbReq->type == TD_SUPER_TABLE) {
free(pCreateTbReq->stbCfg.pSchema);
free(pCreateTbReq->stbCfg.pTagSchema);
} else if (pCreateTbReq->type == TD_CHILD_TABLE) {
free(pCreateTbReq->ctbCfg.pTag);
} else {
free(pCreateTbReq->ntbCfg.pSchema);
}
2021-12-31 08:30:40 +00:00
}
2022-01-21 08:15:35 +00:00
2022-01-22 04:43:46 +00:00
vTrace("vgId:%d process create %" PRIzu " tables", pVnode->vgId, taosArrayGetSize(vCreateTbBatchReq.pArray));
2022-01-12 01:55:37 +00:00
taosArrayDestroy(vCreateTbBatchReq.pArray);
break;
2022-01-28 01:29:17 +00:00
case TDMT_VND_ALTER_STB:
vTrace("vgId:%d, process drop stb req", pVnode->vgId);
break;
2021-12-24 07:00:51 +00:00
case TDMT_VND_DROP_STB:
2022-01-28 01:29:17 +00:00
vTrace("vgId:%d, process drop stb req", pVnode->vgId);
break;
2021-12-27 07:15:03 +00:00
case TDMT_VND_DROP_TABLE:
2021-12-28 07:01:58 +00:00
// if (metaDropTable(pVnode->pMeta, vReq.dtReq.uid) < 0) {
// // TODO: handle error
// }
2021-12-20 08:52:39 +00:00
break;
2021-12-24 07:00:51 +00:00
case TDMT_VND_SUBMIT:
2022-01-07 01:54:05 +00:00
if (tsdbInsertData(pVnode->pTsdb, (SSubmitMsg *)ptr, NULL) < 0) {
2021-11-29 03:37:26 +00:00
// TODO: handle error
2021-11-17 07:02:42 +00:00
}
2021-12-20 08:52:39 +00:00
break;
2022-01-20 01:49:27 +00:00
case TDMT_VND_MQ_SET_CONN: {
if (tqProcessSetConnReq(pVnode->pTq, POINTER_SHIFT(ptr, sizeof(SMsgHead))) < 0) {
2022-01-24 13:39:00 +00:00
// TODO: handle error
2022-01-20 02:45:15 +00:00
}
2022-01-20 10:09:28 +00:00
} break;
2021-12-20 08:52:39 +00:00
default:
2021-12-25 08:54:28 +00:00
ASSERT(0);
2021-12-20 08:52:39 +00:00
break;
2021-11-09 03:22:25 +00:00
}
2021-12-20 08:52:39 +00:00
pVnode->state.applied = ver;
2021-11-08 02:58:46 +00:00
2021-12-20 08:52:39 +00:00
// Check if it needs to commit
if (vnodeShouldCommit(pVnode)) {
2022-01-14 05:42:37 +00:00
// tsem_wait(&(pVnode->canCommit));
2021-12-20 08:52:39 +00:00
if (vnodeAsyncCommit(pVnode) < 0) {
// TODO: handle error
}
}
2022-01-24 06:27:28 +00:00
2021-11-29 03:37:26 +00:00
return 0;
}
2021-12-17 05:40:27 +00:00
/* ------------------------ STATIC METHODS ------------------------ */