From 6c3b627e54bcd5a9460f11ff2c2a9999ea2394a6 Mon Sep 17 00:00:00 2001 From: Hongze Cheng Date: Mon, 27 Sep 2021 10:49:36 +0800 Subject: [PATCH] refact --- include/common/taosMsg.h | 55 +++++++++++++++++ include/server/vnode/meta/meta.h | 4 ++ include/server/vnode/tq/tq.h | 5 ++ include/server/vnode/tsdb/tsdb.h | 3 +- source/server/vnode/CMakeLists.txt | 10 +-- source/server/vnode/inc/vnodeCommit.h | 29 +++++++++ source/server/vnode/inc/vnodeInt.h | 11 ++++ source/server/vnode/inc/vnodeMemAllocator.h | 27 ++++++++ source/server/vnode/inc/vnodeWrite.h | 21 +++++++ source/server/vnode/src/vnodeCommit.c | 53 ++++++++++++++++ source/server/vnode/src/vnodeMemAllocator.c | 14 +++++ source/server/vnode/src/vnodeWrite.c | 68 +++++++++++++++++++++ source/server/vnode/tsdb/CMakeLists.txt | 1 + 13 files changed, 296 insertions(+), 5 deletions(-) create mode 100644 include/common/taosMsg.h create mode 100644 source/server/vnode/inc/vnodeCommit.h create mode 100644 source/server/vnode/inc/vnodeMemAllocator.h create mode 100644 source/server/vnode/inc/vnodeWrite.h create mode 100644 source/server/vnode/src/vnodeCommit.c create mode 100644 source/server/vnode/src/vnodeMemAllocator.c create mode 100644 source/server/vnode/src/vnodeWrite.c diff --git a/include/common/taosMsg.h b/include/common/taosMsg.h new file mode 100644 index 0000000000..0d083a4ca5 --- /dev/null +++ b/include/common/taosMsg.h @@ -0,0 +1,55 @@ +/* + * Copyright (c) 2019 TAOS Data, Inc. + * + * 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 . + */ + +#ifndef _TD_TAOS_MSG_H_ +#define _TD_TAOS_MSG_H_ + +typedef struct { + /* data */ +} SSubmitReq; + +typedef struct { + /* data */ +} SSubmitRsp; + +typedef struct { + /* data */ +} SSubmitReqReader; + +typedef struct { + /* data */ +} SCreateTableReq; + +typedef struct { + /* data */ +} SCreateTableRsp; + +typedef struct { + /* data */ +} SDropTableReq; + +typedef struct { + /* data */ +} SDropTableRsp; + +typedef struct { + /* data */ +} SAlterTableReq; + +typedef struct { + /* data */ +} SAlterTableRsp; + +#endif /*_TD_TAOS_MSG_H_*/ \ No newline at end of file diff --git a/include/server/vnode/meta/meta.h b/include/server/vnode/meta/meta.h index c584c03de0..2addcdc6c3 100644 --- a/include/server/vnode/meta/meta.h +++ b/include/server/vnode/meta/meta.h @@ -20,6 +20,10 @@ extern "C" { #endif +typedef struct SMeta SMeta; + +int metaCommit(SMeta *pMeta); + #ifdef __cplusplus } #endif diff --git a/include/server/vnode/tq/tq.h b/include/server/vnode/tq/tq.h index 77d6cdf2c9..4c626a1e25 100644 --- a/include/server/vnode/tq/tq.h +++ b/include/server/vnode/tq/tq.h @@ -20,6 +20,11 @@ extern "C" { #endif +typedef struct STQ STQ; + +int tqPushMsg(void *); +int tqCommit(STQ *pTQ); + #ifdef __cplusplus } #endif diff --git a/include/server/vnode/tsdb/tsdb.h b/include/server/vnode/tsdb/tsdb.h index 988669324e..968bac2fa2 100644 --- a/include/server/vnode/tsdb/tsdb.h +++ b/include/server/vnode/tsdb/tsdb.h @@ -17,6 +17,7 @@ #define _TD_TSDB_H_ #include "os.h" +#include "taosMsg.h" #ifdef __cplusplus extern "C" { @@ -47,7 +48,7 @@ int tsdbCloseRepo(STsdb *pTsdb); int tsdbForceCloseRepo(STsdb *pTsdb); // Data commit -int tsdbInsert(STsdb *pTsdb, SSubmitMsg *pMsg); +int tsdbInsert(STsdb *pTsdb, SSubmitReq *pMsg); int tsdbCommit(STsdb *pTsdb); #ifdef __cplusplus diff --git a/source/server/vnode/CMakeLists.txt b/source/server/vnode/CMakeLists.txt index 75d24ed64e..d5778f9344 100644 --- a/source/server/vnode/CMakeLists.txt +++ b/source/server/vnode/CMakeLists.txt @@ -9,9 +9,11 @@ target_include_directories( PUBLIC "${CMAKE_SOURCE_DIR}/include/server/vnode" private "${CMAKE_CURRENT_SOURCE_DIR}/inc" ) -target_include_directories( +target_link_libraries( vnode - PRIVATE meta - PRIVATE tq - PRIVATE tsdb + PUBLIC meta + PUBLIC tq + PUBLIC tsdb + PRIVATE os + PRIVATE common ) \ No newline at end of file diff --git a/source/server/vnode/inc/vnodeCommit.h b/source/server/vnode/inc/vnodeCommit.h new file mode 100644 index 0000000000..d37c61008c --- /dev/null +++ b/source/server/vnode/inc/vnodeCommit.h @@ -0,0 +1,29 @@ +/* + * Copyright (c) 2019 TAOS Data, Inc. + * + * 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 . + */ + +#ifndef _TD_VNODE_COMMIT_H_ +#define _TD_VNODE_COMMIT_H_ + +#ifdef __cplusplus +extern "C" { +#endif + +int vnodeAsyncCommit(SVnode *pVnode); + +#ifdef __cplusplus +} +#endif + +#endif /*_TD_VNODE_COMMIT_H_*/ \ No newline at end of file diff --git a/source/server/vnode/inc/vnodeInt.h b/source/server/vnode/inc/vnodeInt.h index 855eb66c8a..79ff0bc76a 100644 --- a/source/server/vnode/inc/vnodeInt.h +++ b/source/server/vnode/inc/vnodeInt.h @@ -16,10 +16,21 @@ #ifndef _TD_VNODE_INT_H_ #define _TD_VNODE_INT_H_ +#include "tq.h" +#include "tsdb.h" +#include "meta.h" + #ifdef __cplusplus extern "C" { #endif +typedef struct SVnode { + SMeta *pMeta; + STsdb *pTsdb; + STQ * pTQ; + void * allocator; // TODO +} SVnode; + #ifdef __cplusplus } #endif diff --git a/source/server/vnode/inc/vnodeMemAllocator.h b/source/server/vnode/inc/vnodeMemAllocator.h new file mode 100644 index 0000000000..f17af4a5a2 --- /dev/null +++ b/source/server/vnode/inc/vnodeMemAllocator.h @@ -0,0 +1,27 @@ +/* + * Copyright (c) 2019 TAOS Data, Inc. + * + * 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 . + */ + +#ifndef _TD_VNODE_MEM_ALLOCATOR_H_ +#define _TD_VNODE_MEM_ALLOCATOR_H_ + +#ifdef __cplusplus +extern "C" { +#endif + +#ifdef __cplusplus +} +#endif + +#endif /*_TD_VNODE_MEM_ALLOCATOR_H_*/ \ No newline at end of file diff --git a/source/server/vnode/inc/vnodeWrite.h b/source/server/vnode/inc/vnodeWrite.h new file mode 100644 index 0000000000..b4430cd255 --- /dev/null +++ b/source/server/vnode/inc/vnodeWrite.h @@ -0,0 +1,21 @@ +/* + * Copyright (c) 2019 TAOS Data, Inc. + * + * 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 . + */ + +#ifndef _TD_VNODE_WRITE_H_ +#define _TD_VNODE_WRITE_H_ + +int vnodeProcessSubmitReq(SVnode *pVnode, SSubmitReq *pReq, SSubmitRsp *pRsp); + +#endif /*_TD_VNODE_WRITE_H_*/ \ No newline at end of file diff --git a/source/server/vnode/src/vnodeCommit.c b/source/server/vnode/src/vnodeCommit.c new file mode 100644 index 0000000000..3200411f4d --- /dev/null +++ b/source/server/vnode/src/vnodeCommit.c @@ -0,0 +1,53 @@ +/* + * Copyright (c) 2019 TAOS Data, Inc. + * + * 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 . + */ + +#include "vnodeInt.h" + +static int vnodeStartCommit(SVnode *pVnode); +static int vnodeEndCommit(SVnode *pVnode); + +int vnodeAsyncCommit(SVnode *pVnode) { + if (vnodeStartCommit(pVnode) < 0) { + // TODO + } + + if (tqCommit(pVnode->pTQ) < 0) { + // TODO + } + + if (metaCommit(pVnode->pMeta) < 0) { + // TODO + } + + if (tsdbCommit(pVnode->pTsdb) < 0) { + // TODO + } + + if (vnodeEndCommit(pVnode) < 0) { + // TODO + } + + return 0; +} + +static int vnodeStartCommit(SVnode *pVnode) { + // TODO + return 0; +} + +static int vnodeEndCommit(SVnode *pVnode) { + // TODO + return 0; +} \ No newline at end of file diff --git a/source/server/vnode/src/vnodeMemAllocator.c b/source/server/vnode/src/vnodeMemAllocator.c new file mode 100644 index 0000000000..6dea4a4e57 --- /dev/null +++ b/source/server/vnode/src/vnodeMemAllocator.c @@ -0,0 +1,14 @@ +/* + * Copyright (c) 2019 TAOS Data, Inc. + * + * 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 . + */ \ No newline at end of file diff --git a/source/server/vnode/src/vnodeWrite.c b/source/server/vnode/src/vnodeWrite.c new file mode 100644 index 0000000000..d6c97132d8 --- /dev/null +++ b/source/server/vnode/src/vnodeWrite.c @@ -0,0 +1,68 @@ +/* + * Copyright (c) 2019 TAOS Data, Inc. + * + * 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 . + */ + +#include "vnodeInt.h" + +int vnodeProcessSubmitReq(SVnode *pVnode, SSubmitReq *pReq, SSubmitRsp *pRsp) { + // TODO: Check inputs + +#if 1 + void *pMem = NULL; + if ((pMem = aMalloc(pVnode->allocator, REQ_SIZE(pReq))) == NULL) { + // No more memory to allocate, schedule an async commit + // and continue + vnodeAsyncCommit(pVnode); + + // Reset allocator and allocat more + vnodeResetAllocator(pVnode); + pMem = aMalloc(pVnode->allocator, REQ_SIZE(pReq)); + if (pMem == NULL) { + // TODO: handle the error + } + } + + // TODO: if SSubmitReq is compressed or encoded, we need to decode the request + memcpy(pMem, pReq, REQ_SIZE(pReq)); + + if (tqPushMsg((SSubmitReq *)pReq) < 0) { + // TODO: handle error + } + + SSubmitReqReader reader; + taosInitSubmitReqReader(&reader, (SSubmitReq *)pMem); + + if (tsdbInsertData((SSubmitReq *)pMem) < 0) { + // TODO: handler error + } + +#endif + + return 0; +} + +int vnodeProcessCreateTableReq(SVnode *pVnode, SCreateTableReq *pReq, SCreateTableRsp *pRsp) { + // TODO + return 0; +} + +int vnodeProcessDropTableReq(SVnode *pVnode, SDropTableReq *pReq, SDropTableRsp *pRsp) { + // TODO + return 0; +} + +int vnodeProcessAlterTableReq(SVnode *pVnode, SDropTableReq *pReq, SDropTableRsp *pRsp) { + // TODO + return 0; +} diff --git a/source/server/vnode/tsdb/CMakeLists.txt b/source/server/vnode/tsdb/CMakeLists.txt index 3c1dc5810b..4a1e154cd5 100644 --- a/source/server/vnode/tsdb/CMakeLists.txt +++ b/source/server/vnode/tsdb/CMakeLists.txt @@ -8,4 +8,5 @@ target_include_directories( target_include_directories( tsdb PRIVATE os + PRIVATE common ) \ No newline at end of file -- GitLab