From 768ea68c69f60c92120a45d15af1b7189aebeffa Mon Sep 17 00:00:00 2001 From: Hongze Cheng Date: Wed, 17 Nov 2021 15:02:42 +0800 Subject: [PATCH 01/41] more --- include/dnode/vnode/tsdb/tsdb.h | 1 + include/util/mallocator.h | 12 +-- source/dnode/vnode/impl/inc/vnodeStateMgr.h | 3 + source/dnode/vnode/impl/src/vnodeBufferPool.c | 96 ++++++++++++++++++- source/dnode/vnode/impl/src/vnodeWrite.c | 44 +++------ 5 files changed, 119 insertions(+), 37 deletions(-) diff --git a/include/dnode/vnode/tsdb/tsdb.h b/include/dnode/vnode/tsdb/tsdb.h index e92205378a..e486da5419 100644 --- a/include/dnode/vnode/tsdb/tsdb.h +++ b/include/dnode/vnode/tsdb/tsdb.h @@ -29,6 +29,7 @@ typedef struct STsdbMemAllocator STsdbMemAllocator; STsdb *tsdbOpen(const char *path, const STsdbOptions *); void tsdbClose(STsdb *); void tsdbRemove(const char *path); +int tsdbInsertData(STsdb *pTsdb, void *); // STsdbOptions int tsdbOptionsInit(STsdbOptions *); diff --git a/include/util/mallocator.h b/include/util/mallocator.h index fd66811f38..ffe242017e 100644 --- a/include/util/mallocator.h +++ b/include/util/mallocator.h @@ -22,10 +22,10 @@ extern "C" { #endif -typedef struct SMemAllocator SMemAllocator; +typedef struct SMemAllocator SMemAllocator; +typedef struct SMemAllocatorFactory SMemAllocatorFactory; struct SMemAllocator { - char name[16]; void *impl; void *(*malloc)(SMemAllocator *, uint64_t size); void *(*calloc)(SMemAllocator *, uint64_t nmemb, uint64_t size); @@ -34,11 +34,11 @@ struct SMemAllocator { uint64_t (*usage)(SMemAllocator *); }; -typedef struct { +struct SMemAllocatorFactory { void *impl; - SMemAllocator *(*create)(); - void (*destroy)(SMemAllocator *); -} SMemAllocatorFactory; + SMemAllocator *(*create)(SMemAllocatorFactory *); + void (*destroy)(SMemAllocatorFactory *, SMemAllocator *); +}; #ifdef __cplusplus } diff --git a/source/dnode/vnode/impl/inc/vnodeStateMgr.h b/source/dnode/vnode/impl/inc/vnodeStateMgr.h index a32f682846..788426e25e 100644 --- a/source/dnode/vnode/impl/inc/vnodeStateMgr.h +++ b/source/dnode/vnode/impl/inc/vnodeStateMgr.h @@ -21,6 +21,9 @@ extern "C" { #endif typedef struct { + uint64_t processed; + uint64_t committed; + uint64_t applied; } SVState; #ifdef __cplusplus diff --git a/source/dnode/vnode/impl/src/vnodeBufferPool.c b/source/dnode/vnode/impl/src/vnodeBufferPool.c index eba71b5ba3..07dc56db95 100644 --- a/source/dnode/vnode/impl/src/vnodeBufferPool.c +++ b/source/dnode/vnode/impl/src/vnodeBufferPool.c @@ -19,9 +19,12 @@ #define VNODE_BUF_POOL_SHARDS 3 struct SVBufPool { + // buffer pool impl SList free; SList incycle; SListNode *inuse; + // MAF for submodules + SMemAllocatorFactory maf; }; typedef enum { @@ -49,6 +52,11 @@ typedef struct { SVArenaNode node; } SVArenaAllocator; +typedef struct { + SVnode * pVnode; + SListNode *pNode; +} SVMAWrapper; + typedef struct { T_REF_DECLARE() uint64_t capacity; @@ -59,8 +67,10 @@ typedef struct { }; } SVMemAllocator; -static SListNode *vBufPoolNewNode(uint64_t capacity, EVMemAllocatorT type); -static void vBufPoolFreeNode(SListNode *pNode); +static SListNode * vBufPoolNewNode(uint64_t capacity, EVMemAllocatorT type); +static void vBufPoolFreeNode(SListNode *pNode); +static SMemAllocator *vBufPoolCreateMA(SMemAllocatorFactory *pmaf); +static void vBufPoolDestroyMA(SMemAllocatorFactory *pmaf, SMemAllocator *pma); int vnodeOpenBufPool(SVnode *pVnode) { uint64_t capacity; @@ -89,6 +99,10 @@ int vnodeOpenBufPool(SVnode *pVnode) { tdListAppendNode(&(pVnode->pBufPool->free), pNode); } + pVnode->pBufPool->maf.impl = pVnode; + pVnode->pBufPool->maf.create = vBufPoolCreateMA; + pVnode->pBufPool->maf.destroy = vBufPoolDestroyMA; + return 0; } @@ -185,4 +199,82 @@ static void vBufPoolFreeNode(SListNode *pNode) { } free(pNode); +} + +static void *vBufPoolMalloc(SMemAllocator *pma, uint64_t size) { + SVMAWrapper * pvmaw = (SVMAWrapper *)(pma->impl); + SVMemAllocator *pvma = (SVMemAllocator *)(pvmaw->pNode->data); + void * ptr = NULL; + + if (pvma->type == E_V_ARENA_ALLOCATOR) { + SVArenaAllocator *pvaa = &(pvma->vaa); + + if (POINTER_DISTANCE(pvaa->inuse->ptr, pvaa->inuse->data) + size > pvaa->inuse->size) { + SVArenaNode *pNode = (SVArenaNode *)malloc(sizeof(*pNode) + MAX(size, pvaa->ssize)); + if (pNode == NULL) { + // TODO: handle error + return NULL; + } + + pNode->prev = pvaa->inuse; + pNode->size = MAX(size, pvaa->ssize); + pNode->ptr = pNode->data; + + pvaa->inuse = pNode; + } + + ptr = pvaa->inuse->ptr; + pvaa->inuse->ptr = POINTER_SHIFT(ptr, size); + } else if (pvma->type == E_V_HEAP_ALLOCATOR) { + /* TODO */ + } + + return NULL; +} + +static SMemAllocator *vBufPoolCreateMA(SMemAllocatorFactory *pmaf) { + SVnode * pVnode; + SMemAllocator * pma; + SVMemAllocator *pvma; + SVMAWrapper * pvmaw; + + pVnode = (SVnode *)(pmaf->impl); + pma = (SMemAllocator *)calloc(1, sizeof(*pma) + sizeof(SVMAWrapper)); + if (pma == NULL) { + // TODO: handle error + return NULL; + } + pvmaw = (SVMAWrapper *)POINTER_SHIFT(pma, sizeof(*pma)); + + // No allocator used currently + if (pVnode->pBufPool->inuse == NULL) { + while (listNEles(&(pVnode->pBufPool->free)) == 0) { + // TODO: wait until all released ro kill query + // tsem_wait(); + ASSERT(0); + } + + pVnode->pBufPool->inuse = tdListPopHead(&(pVnode->pBufPool->free)); + pvma = (SVMemAllocator *)(pVnode->pBufPool->inuse->data); + T_REF_INIT_VAL(pvma, 1); + } else { + pvma = (SVMemAllocator *)(pVnode->pBufPool->inuse->data); + } + + T_REF_INC(pvma); + + pvmaw->pVnode = pVnode; + pvmaw->pNode = pVnode->pBufPool->inuse; + + pma->impl = pvmaw; + pma->malloc = vBufPoolMalloc; + pma->calloc = NULL; /* TODO */ + pma->realloc = NULL; /* TODO */ + pma->free = NULL; /* TODO */ + pma->usage = NULL; /* TODO */ + + return pma; +} + +static void vBufPoolDestroyMA(SMemAllocatorFactory *pmaf, SMemAllocator *pma) { /* TODO */ } \ No newline at end of file diff --git a/source/dnode/vnode/impl/src/vnodeWrite.c b/source/dnode/vnode/impl/src/vnodeWrite.c index 810ac570bc..f858309c66 100644 --- a/source/dnode/vnode/impl/src/vnodeWrite.c +++ b/source/dnode/vnode/impl/src/vnodeWrite.c @@ -21,46 +21,32 @@ int vnodeProcessWMsgs(SVnode *pVnode, SArray *pMsgs) { } int vnodeApplyWMsg(SVnode *pVnode, SRpcMsg *pMsg, SRpcMsg **pRsp) { -#if 0 - int reqType; /* TODO */ - size_t reqSize; /* TODO */ - uint64_t reqVersion = 0; /* TODO */ - int code = 0; + // TODO + int code = 0; - // Copy the request to vnode buffer - void *pReq = mMalloc(pVnode->inuse, reqSize); - if (pReq == NULL) { - // TODO: handle error - } - - memcpy(pReq, pMsg, reqSize); - - // Push the request to TQ so consumers can consume - tqPushMsg(pVnode->pTq, pReq, 0); - - // Process the request - switch (reqType) { + switch (pMsg->msgType) { case TSDB_MSG_TYPE_CREATE_TABLE: - code = metaCreateTable(pVnode->pMeta, NULL /* TODO */); + if (metaCreateTable(pVnode->pMeta, pMsg->pCont) < 0) { + /* TODO */ + return -1; + } break; case TSDB_MSG_TYPE_DROP_TABLE: - code = metaDropTable(pVnode->pMeta, 0 /* TODO */); + if (metaDropTable(pVnode->pMeta, pMsg->pCont) < 0) { + /* TODO */ + return -1; + } break; case TSDB_MSG_TYPE_SUBMIT: - /* TODO */ + if (tsdbInsertData(pVnode->pTsdb, pMsg->pCont) < 0) { + /* TODO */ + return -1; + } break; default: break; } - if (vnodeShouldCommit(pVnode)) { - if (vnodeAsyncCommit(pVnode) < 0) { - // TODO: handle error - } - } - - return code; -#endif return 0; } From b59bda18f86767a4a85219b23839d28bbfb6913c Mon Sep 17 00:00:00 2001 From: Hongze Cheng Date: Wed, 17 Nov 2021 15:31:03 +0800 Subject: [PATCH 02/41] more --- source/dnode/vnode/impl/src/vnodeBufferPool.c | 23 +++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/source/dnode/vnode/impl/src/vnodeBufferPool.c b/source/dnode/vnode/impl/src/vnodeBufferPool.c index 07dc56db95..daba6a9aac 100644 --- a/source/dnode/vnode/impl/src/vnodeBufferPool.c +++ b/source/dnode/vnode/impl/src/vnodeBufferPool.c @@ -277,4 +277,27 @@ static SMemAllocator *vBufPoolCreateMA(SMemAllocatorFactory *pmaf) { } static void vBufPoolDestroyMA(SMemAllocatorFactory *pmaf, SMemAllocator *pma) { /* TODO */ + SVnode * pVnode = (SVnode *)(pmaf->impl); + SListNode * pNode = ((SVMAWrapper *)(pma->impl))->pNode; + SVMemAllocator *pvma = (SVMemAllocator *)(pNode->data); + + if (T_REF_DEC(pvma) == 0) { + if (pvma->type == E_V_ARENA_ALLOCATOR) { + SVArenaAllocator *pvaa = &(pvma->vaa); + while (pvaa->inuse != &(pvaa->node)) { + SVArenaNode *pNode = pvaa->inuse; + pvaa->inuse = pNode->prev; + /* code */ + } + + pvaa->inuse->ptr = pvaa->inuse->data; + } else if (pvma->type == E_V_HEAP_ALLOCATOR) { + } else { + ASSERT(0); + } + + // Move node from incycle to free + tdListAppendNode(&(pVnode->pBufPool->free), tdListPopNode(&(pVnode->pBufPool->incycle), pNode)); + // tsem_post(); todo: sem_post + } } \ No newline at end of file From 89f9caeaddda89f44576e8e96b295cd44422d02d Mon Sep 17 00:00:00 2001 From: Hongze Cheng Date: Wed, 17 Nov 2021 16:45:42 +0800 Subject: [PATCH 03/41] more --- source/dnode/vnode/impl/inc/vnodeRequest.h | 8 ++++---- source/dnode/vnode/impl/src/vnodeWrite.c | 10 +++++++++- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/source/dnode/vnode/impl/inc/vnodeRequest.h b/source/dnode/vnode/impl/inc/vnodeRequest.h index 788918f105..f2b4ecee91 100644 --- a/source/dnode/vnode/impl/inc/vnodeRequest.h +++ b/source/dnode/vnode/impl/inc/vnodeRequest.h @@ -23,15 +23,15 @@ extern "C" { typedef struct SVnodeReq SVnodeReq; typedef struct SVnodeRsp SVnodeRsp; -typedef enum { -} EVReqT; +typedef enum {} EVReqT; +typedef enum {} EVRspT; struct SVnodeReq { - /* TODO */ + EVReqT type; }; struct SVnodeRsp { - /* TODO */ + EVRspT type; }; #ifdef __cplusplus diff --git a/source/dnode/vnode/impl/src/vnodeWrite.c b/source/dnode/vnode/impl/src/vnodeWrite.c index f858309c66..69a7cf3478 100644 --- a/source/dnode/vnode/impl/src/vnodeWrite.c +++ b/source/dnode/vnode/impl/src/vnodeWrite.c @@ -16,7 +16,15 @@ #include "vnodeDef.h" int vnodeProcessWMsgs(SVnode *pVnode, SArray *pMsgs) { - /* TODO */ + SRpcMsg *pReq; + SRpcMsg *pRsp; + + for (size_t i = 0; i < taosArrayGetSize(pMsgs); i++) { + pReq = taosArrayGet(pMsgs, i); + + vnodeApplyWMsg(pVnode, pReq, pRsp); + } + return 0; } From 274d115a058ded7090867fd72c116f4f831f453f Mon Sep 17 00:00:00 2001 From: Hongze Cheng Date: Fri, 19 Nov 2021 13:30:59 +0800 Subject: [PATCH 04/41] more --- include/common/trow.h | 92 +++++++++++++++++++++------------ include/common/tschema.h | 18 +++++++ include/dnode/vnode/meta/meta.h | 12 +++-- source/common/src/trow.c | 4 +- 4 files changed, 86 insertions(+), 40 deletions(-) diff --git a/include/common/trow.h b/include/common/trow.h index e699031d7a..8c6d9846fa 100644 --- a/include/common/trow.h +++ b/include/common/trow.h @@ -17,53 +17,77 @@ #define _TD_COMMON_ROW_H_ #include "os.h" +#include "tbuffer.h" +#include "tdef.h" #ifdef __cplusplus extern "C" { #endif -// types -typedef void * SRow; -typedef struct SRowBatch SRowBatch; -typedef struct SRowBuilder SRowBuilder; -typedef struct SRowBatchIter SRowBatchIter; -typedef struct SRowBatchBuilder SRowBatchBuilder; +#define TD_OR_ROW 0 +#define TD_KV_ROW 1 -// SRow -#define ROW_HEADER_SIZE (sizeof(uint8_t) + 2 * sizeof(uint16_t) + sizeof(uint64_t)) -#define rowType(r) (*(uint8_t *)(r)) // row type -#define rowLen(r) (*(uint16_t *)POINTER_SHIFT(r, sizeof(uint8_t))) // row length -#define rowSVer(r) \ - (*(uint16_t *)POINTER_SHIFT(r, sizeof(uint8_t) + sizeof(uint16_t))) // row schema version, only for SDataRow -#define rowNCols(r) rowSVer(r) // only for SKVRow -#define rowVer(r) (*(uint64_t)POINTER_SHIFT(r, sizeof(uint8_t) + 2 * sizeof(uint16_t))) // row version -#define rowCopy(dest, r) memcpy((dest), r, rowLen(r)) +typedef uint16_t col_id_t; -static FORCE_INLINE SRow rowDup(SRow row) { - SRow r = malloc(rowLen(row)); - if (r == NULL) { - return NULL; - } +typedef struct { + TSKEY ts; +} SOrRow; - rowCopy(r, row); +typedef struct { + col_id_t cid; + uint32_t offset; +} SKvRowIdx; - return r; -} +typedef struct { + uint16_t ncols; + SKvRowIdx cidx[]; +} SKvRow; -// SRowBatch +typedef struct { + union { + /// union field for encode and decode + uint64_t info; + struct { + /// row type + uint64_t type : 2; + /// row schema version + uint64_t sver : 16; + /// row total length + uint64_t len : 46; + }; + }; + /// row version + uint64_t ver; + /// timestamp of the row + TSKEY ts; + char content[]; +} SRow; -// SRowBuilder -SRowBuilder *rowBuilderCreate(); -void rowBuilderDestroy(SRowBuilder *); +typedef enum { + /// ordinary row builder + TD_OR_ROW_BUILDER = 0, + /// kv row builder + TD_KV_ROW_BUILDER, + /// self-determined row builder + TD_SD_ROW_BUILDER +} ERowBbuilderT; -// SRowBatchIter -SRowBatchIter *rowBatchIterCreate(SRowBatch *); -void rowBatchIterDestroy(SRowBatchIter *); -const SRow rowBatchIterNext(SRowBatchIter *); +typedef struct { + /// row builder type + ERowBbuilderT type; + /// buffer writer + SBufferWriter bw; + /// target row + SRow *pRow; +} SRowBuilder; -// SRowBatchBuilder -SRowBatchBuilder *rowBatchBuilderCreate(); -void rowBatchBuilderDestroy(SRowBatchBuilder *); +typedef struct { + /* TODO */ +} SRowBatchBuilder; + +#define tRBInit(type, allocator, endian) \ + { .type = (type), tbufInitWriter(allocator, endian), NULL } +void tRBClear(SRowBuilder *pRB); #ifdef __cplusplus } diff --git a/include/common/tschema.h b/include/common/tschema.h index 5e9057520b..acc6a4ad7a 100644 --- a/include/common/tschema.h +++ b/include/common/tschema.h @@ -16,10 +16,28 @@ #ifndef _TD_COMMON_SCHEMA_H_ #define _TD_COMMON_SCHEMA_H_ +#include "os.h" + #ifdef __cplusplus extern "C" { #endif +typedef struct SColAttr { + /* data */ +} SColAttr; + +typedef struct SColumn { + uint8_t type; + uint16_t cid; + uint16_t bytes; +} SColumn; + +typedef struct SSchema { + /// schema version + uint16_t sver; + /* data */ +} SSchema; + #ifdef __cplusplus } #endif diff --git a/include/dnode/vnode/meta/meta.h b/include/dnode/vnode/meta/meta.h index 421f96ef5f..92c44ec4ae 100644 --- a/include/dnode/vnode/meta/meta.h +++ b/include/dnode/vnode/meta/meta.h @@ -41,11 +41,13 @@ void metaOptionsClear(SMetaOptions *pOptions); // STableOpts #define META_TABLE_OPTS_DECLARE(name) STableOpts name = {0} -void metaNormalTableOptsInit(STbOptions *pTbOptions, const char *name, const STSchema *pSchema); -void metaSuperTableOptsInit(STbOptions *pTbOptions, const char *name, tb_uid_t uid, const STSchema *pSchema, - const STSchema *pTagSchema); -void metaChildTableOptsInit(STbOptions *pTbOptions, const char *name, tb_uid_t suid, const SKVRow tags); -void metaTableOptsClear(STbOptions *pTbOptions); +void metaNormalTableOptsInit(STbOptions *pTbOptions, const char *name, const STSchema *pSchema); +void metaSuperTableOptsInit(STbOptions *pTbOptions, const char *name, tb_uid_t uid, const STSchema *pSchema, + const STSchema *pTagSchema); +void metaChildTableOptsInit(STbOptions *pTbOptions, const char *name, tb_uid_t suid, const SKVRow tags); +void metaTableOptsClear(STbOptions *pTbOptions); +uint64_t metaEncodeTbOptions(void **pBuf, STbOptions *pTbOptions); +STbOptions *metaDecodeTbOptions(void *pBuf, size_t size, bool endian); #ifdef __cplusplus } diff --git a/source/common/src/trow.c b/source/common/src/trow.c index cf1b0eceff..e443f92b25 100644 --- a/source/common/src/trow.c +++ b/source/common/src/trow.c @@ -15,6 +15,7 @@ #include "trow.h" +#if 0 /* ------------ Structures ---------- */ struct SRowBatch { int32_t compress : 1; // if batch row is compressed @@ -86,4 +87,5 @@ const SRow rowBatchIterNext(SRowBatchIter *pRowBatchIter) { // SRowBatchBuilder SRowBatchBuilder *rowBatchBuilderCreate(); -void rowBatchBuilderDestroy(SRowBatchBuilder *); \ No newline at end of file +void rowBatchBuilderDestroy(SRowBatchBuilder *); +#endif \ No newline at end of file From 416e6354e9bd610fd8af57eb1e23773bc96871ed Mon Sep 17 00:00:00 2001 From: Hongze Cheng Date: Mon, 22 Nov 2021 13:45:41 +0800 Subject: [PATCH 05/41] more --- include/common/trow.h | 59 +++++++++++++++++------ include/common/tschema.h | 48 ++++++++++++++++--- source/common/src/trow.c | 76 ++++-------------------------- source/common/test/trowTest.cpp | 21 +++++++++ source/common/test/tschemaTest.cpp | 6 +++ 5 files changed, 121 insertions(+), 89 deletions(-) create mode 100644 source/common/test/trowTest.cpp create mode 100644 source/common/test/tschemaTest.cpp diff --git a/include/common/trow.h b/include/common/trow.h index 8c6d9846fa..7186505e03 100644 --- a/include/common/trow.h +++ b/include/common/trow.h @@ -19,18 +19,18 @@ #include "os.h" #include "tbuffer.h" #include "tdef.h" +#include "tschema.h" #ifdef __cplusplus extern "C" { #endif -#define TD_OR_ROW 0 -#define TD_KV_ROW 1 - -typedef uint16_t col_id_t; +#define TD_UNDECIDED_ROW 0 +#define TD_OR_ROW 1 +#define TD_KV_ROW 2 typedef struct { - TSKEY ts; + // TODO } SOrRow; typedef struct { @@ -48,21 +48,30 @@ typedef struct { /// union field for encode and decode uint64_t info; struct { + /// is deleted row + uint64_t del : 1; /// row type - uint64_t type : 2; + uint64_t type : 3; /// row schema version uint64_t sver : 16; /// row total length - uint64_t len : 46; + uint64_t len : 32; + /// reserved for back compatibility + uint64_t reserve : 12; }; }; /// row version uint64_t ver; - /// timestamp of the row - TSKEY ts; - char content[]; + /// timestamp + TSKEY ts; + char content[]; } SRow; +typedef struct { + uint32_t nRows; + char rows[]; +} SRowBatch; + typedef enum { /// ordinary row builder TD_OR_ROW_BUILDER = 0, @@ -82,12 +91,32 @@ typedef struct { } SRowBuilder; typedef struct { - /* TODO */ -} SRowBatchBuilder; + SSchema *pSchema; + SRow * pRow; +} SRowReader; -#define tRBInit(type, allocator, endian) \ - { .type = (type), tbufInitWriter(allocator, endian), NULL } -void tRBClear(SRowBuilder *pRB); +typedef struct { + uint32_t it; + SRowBatch *pRowBatch; +} SRowBatchIter; + +// SRowBuilder +#define trbInit(rt, allocator, endian, target, size) \ + { .type = (rt), .bw = tbufInitWriter(allocator, endian), .pRow = (target) } +void trbSetRowInfo(SRowBuilder *pRB, bool del, uint16_t sver); +void trbSetRowVersion(SRowBuilder *pRB, uint64_t ver); +void trbSetRowTS(SRowBuilder *pRB, TSKEY ts); +int trbWriteCol(SRowBuilder *pRB, void *pData, col_id_t cid); + +// SRowReader +#define tRowReaderInit(schema, row) \ + { .schema = (schema), .row = (row) } +int tRowReaderRead(SRowReader *pRowReader, col_id_t cid, void *target, uint64_t size); + +// SRowBatchIter +#define tRowBatchIterInit(pRB) \ + { .it = 0, .pRowBatch = (pRB) } +const SRow *tRowBatchIterNext(SRowBatchIter *pRowBatchIter); #ifdef __cplusplus } diff --git a/include/common/tschema.h b/include/common/tschema.h index acc6a4ad7a..59a858bbb7 100644 --- a/include/common/tschema.h +++ b/include/common/tschema.h @@ -17,27 +17,61 @@ #define _TD_COMMON_SCHEMA_H_ #include "os.h" +#include "tarray.h" #ifdef __cplusplus extern "C" { #endif -typedef struct SColAttr { - /* data */ -} SColAttr; +typedef uint16_t col_id_t; typedef struct SColumn { - uint8_t type; - uint16_t cid; - uint16_t bytes; + /// column name + char *cname; + union { + /// for encode purpose + uint64_t info; + struct { + uint64_t sma : 1; + /// column data type + uint64_t type : 7; + /// column id + uint64_t cid : 16; + /// max bytes of the column + uint64_t bytes : 32; + /// reserved + uint64_t reserve : 8; + }; + }; + /// comment about the column + char *comment; } SColumn; typedef struct SSchema { /// schema version uint16_t sver; - /* data */ + /// number of columns + uint16_t ncols; + /// sma attributes + struct { + bool sma; + SArray *smaArray; + }; + /// column info + SColumn cols[]; } SSchema; +typedef struct { + uint64_t size; + SSchema *pSchema; +} SShemaBuilder; + +#define tSchemaBuilderInit(target, capacity) \ + { .size = (capacity), .pSchema = (target) } +void tSchemaBuilderSetSver(SShemaBuilder *pSchemaBuilder, uint16_t sver); +void tSchemaBuilderSetSMA(bool sma, SArray *smaArray); +int tSchemaBuilderPutColumn(char *cname, bool sma, uint8_t type, col_id_t cid, uint32_t bytes, char *comment); + #ifdef __cplusplus } #endif diff --git a/source/common/src/trow.c b/source/common/src/trow.c index e443f92b25..2e36e6a757 100644 --- a/source/common/src/trow.c +++ b/source/common/src/trow.c @@ -15,77 +15,19 @@ #include "trow.h" -#if 0 -/* ------------ Structures ---------- */ -struct SRowBatch { - int32_t compress : 1; // if batch row is compressed - int32_t nrows : 31; // number of rows - int32_t tlen; // total length (including `nrows` and `tlen`) - char rows[]; -}; - -struct SRowBuilder { +void trbSetRowInfo(SRowBuilder *pRB, bool del, uint16_t sver) { // TODO -}; +} -struct SRowBatchIter { - int32_t counter; // row counter - SRowBatch *rb; // row batch to iter - SRow nrow; // next row -}; - -struct SRowBatchBuilder { +void trbSetRowVersion(SRowBuilder *pRB, uint64_t ver) { // TODO -}; +} -/* ------------ Methods ---------- */ - -// SRowBuilder -SRowBuilder *rowBuilderCreate() { - SRowBuilder *pRowBuilder = NULL; +void trbSetRowTS(SRowBuilder *pRB, TSKEY ts) { // TODO - - return pRowBuilder; } -void rowBuilderDestroy(SRowBuilder *pRowBuilder) { - if (pRowBuilder) { - free(pRowBuilder); - } -} - -// SRowBatchIter -SRowBatchIter *rowBatchIterCreate(SRowBatch *pRowBatch) { - SRowBatchIter *pRowBatchIter = (SRowBatchIter *)malloc(sizeof(*pRowBatchIter)); - if (pRowBatchIter == NULL) { - return NULL; - } - - pRowBatchIter->counter = 0; - pRowBatchIter->rb = pRowBatch; - pRowBatchIter->nrow = pRowBatch->rows; - - return pRowBatchIter; -}; - -void rowBatchIterDestroy(SRowBatchIter *pRowBatchIter) { - if (pRowBatchIter) { - free(pRowBatchIter); - } -} - -const SRow rowBatchIterNext(SRowBatchIter *pRowBatchIter) { - SRow r = NULL; - if (pRowBatchIter->counter < pRowBatchIter->rb->nrows) { - r = pRowBatchIter->nrow; - pRowBatchIter->counter += 1; - pRowBatchIter->nrow = (SRow)POINTER_SHIFT(r, rowLen(r)); - } - - return r; -} - -// SRowBatchBuilder -SRowBatchBuilder *rowBatchBuilderCreate(); -void rowBatchBuilderDestroy(SRowBatchBuilder *); -#endif \ No newline at end of file +int trbWriteCol(SRowBuilder *pRB, void *pData, col_id_t cid) { + // TODO + return 0; +} \ No newline at end of file diff --git a/source/common/test/trowTest.cpp b/source/common/test/trowTest.cpp new file mode 100644 index 0000000000..8c628464e3 --- /dev/null +++ b/source/common/test/trowTest.cpp @@ -0,0 +1,21 @@ +#include + +#include "trow.h" + +TEST(td_row_test, build_row_to_target) { + char dst[1024]; + SRow* pRow = (SRow*)dst; + int ncols = 10; + col_id_t cid; + void* pData; + SRowBuilder rb = trbInit(TD_OR_ROW_BUILDER, NULL, 0, pRow, 1024); + + trbSetRowInfo(&rb, false, 0); + trbSetRowTS(&rb, 1637550210000); + for (int c = 0; c < ncols; c++) { + cid = c; + if (trbWriteCol(&rb, pData, cid) < 0) { + // TODO + } + } +} \ No newline at end of file diff --git a/source/common/test/tschemaTest.cpp b/source/common/test/tschemaTest.cpp new file mode 100644 index 0000000000..acced6e09e --- /dev/null +++ b/source/common/test/tschemaTest.cpp @@ -0,0 +1,6 @@ +#include +#include "tschema.h" + +TEST(td_schema_test, build_schema_test) { + +} \ No newline at end of file From 9001468b21203ecfb062d3200acaee5391b0c6aa Mon Sep 17 00:00:00 2001 From: Hongze Cheng Date: Mon, 22 Nov 2021 15:02:53 +0800 Subject: [PATCH 06/41] refact --- include/common/trow.h | 5 +- include/common/tschema.h | 21 +++--- include/dnode/vnode/meta/impl/metaImpl.h | 75 ------------------- include/dnode/vnode/meta/meta.h | 69 +++++++++++++---- include/dnode/vnode/vnode.h | 58 +++++++------- source/dnode/mgmt/src/dnodeVnodes.c | 34 +++++---- .../impl/inc/{vnodeOptions.h => vnodeCfg.h} | 12 +-- source/dnode/vnode/impl/inc/vnodeDef.h | 22 +++--- source/dnode/vnode/impl/src/vnodeBufferPool.c | 4 +- .../impl/src/{vnodeOptions.c => vnodeCfg.c} | 12 +-- source/dnode/vnode/impl/src/vnodeMain.c | 20 ++--- .../meta/inc/{metaOptions.h => metaCfg.h} | 12 +-- source/dnode/vnode/meta/inc/metaDB.h | 2 +- source/dnode/vnode/meta/inc/metaDef.h | 6 +- source/dnode/vnode/meta/inc/metaIdx.h | 2 +- .../meta/inc/{metaTbOptions.h => metaTbCfg.h} | 14 ++-- source/dnode/vnode/meta/src/metaCache.c | 4 +- .../meta/src/{metaOptions.c => metaCfg.c} | 10 +-- source/dnode/vnode/meta/src/metaDB.c | 14 ++-- source/dnode/vnode/meta/src/metaIdx.c | 2 +- source/dnode/vnode/meta/src/metaMain.c | 9 +-- source/dnode/vnode/meta/src/metaTable.c | 2 +- .../meta/src/{metaTbOptions.c => metaTbCfg.c} | 10 +-- 23 files changed, 194 insertions(+), 225 deletions(-) delete mode 100644 include/dnode/vnode/meta/impl/metaImpl.h rename source/dnode/vnode/impl/inc/{vnodeOptions.h => vnodeCfg.h} (73%) rename source/dnode/vnode/impl/src/{vnodeOptions.c => vnodeCfg.c} (65%) rename source/dnode/vnode/meta/inc/{metaOptions.h => metaCfg.h} (74%) rename source/dnode/vnode/meta/inc/{metaTbOptions.h => metaTbCfg.h} (69%) rename source/dnode/vnode/meta/src/{metaOptions.c => metaCfg.c} (68%) rename source/dnode/vnode/meta/src/{metaTbOptions.c => metaTbCfg.c} (75%) diff --git a/include/common/trow.h b/include/common/trow.h index 7186505e03..cff0f08302 100644 --- a/include/common/trow.h +++ b/include/common/trow.h @@ -18,6 +18,7 @@ #include "os.h" #include "tbuffer.h" +#include "tdataformat.h" #include "tdef.h" #include "tschema.h" @@ -91,8 +92,8 @@ typedef struct { } SRowBuilder; typedef struct { - SSchema *pSchema; - SRow * pRow; + STSchema *pSchema; + SRow * pRow; } SRowReader; typedef struct { diff --git a/include/common/tschema.h b/include/common/tschema.h index 59a858bbb7..4063758043 100644 --- a/include/common/tschema.h +++ b/include/common/tschema.h @@ -25,7 +25,8 @@ extern "C" { typedef uint16_t col_id_t; -typedef struct SColumn { +#if 0 +typedef struct STColumn { /// column name char *cname; union { @@ -45,9 +46,9 @@ typedef struct SColumn { }; /// comment about the column char *comment; -} SColumn; +} STColumn; -typedef struct SSchema { +typedef struct STSchema { /// schema version uint16_t sver; /// number of columns @@ -58,20 +59,22 @@ typedef struct SSchema { SArray *smaArray; }; /// column info - SColumn cols[]; -} SSchema; + STColumn cols[]; +} STSchema; typedef struct { - uint64_t size; - SSchema *pSchema; -} SShemaBuilder; + uint64_t size; + STSchema *pSchema; +} STShemaBuilder; #define tSchemaBuilderInit(target, capacity) \ { .size = (capacity), .pSchema = (target) } -void tSchemaBuilderSetSver(SShemaBuilder *pSchemaBuilder, uint16_t sver); +void tSchemaBuilderSetSver(STShemaBuilder *pSchemaBuilder, uint16_t sver); void tSchemaBuilderSetSMA(bool sma, SArray *smaArray); int tSchemaBuilderPutColumn(char *cname, bool sma, uint8_t type, col_id_t cid, uint32_t bytes, char *comment); +#endif + #ifdef __cplusplus } #endif diff --git a/include/dnode/vnode/meta/impl/metaImpl.h b/include/dnode/vnode/meta/impl/metaImpl.h deleted file mode 100644 index 90ced02f30..0000000000 --- a/include/dnode/vnode/meta/impl/metaImpl.h +++ /dev/null @@ -1,75 +0,0 @@ -/* - * 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_META_IMPL_H_ -#define _TD_META_IMPL_H_ - -#include "os.h" - -#include "taosmsg.h" - -#ifdef __cplusplus -extern "C" { -#endif -typedef uint64_t tb_uid_t; - -/* ------------------------ SMetaOptions ------------------------ */ -struct SMetaOptions { - size_t lruCacheSize; // LRU cache size -}; - -/* ------------------------ STbOptions ------------------------ */ -#define META_NORMAL_TABLE ((uint8_t)1) -#define META_SUPER_TABLE ((uint8_t)2) -#define META_CHILD_TABLE ((uint8_t)3) - -typedef struct { -} SSMAOptions; - -// super table options -typedef struct { - tb_uid_t uid; - STSchema* pSchema; - STSchema* pTagSchema; -} SSTbOptions; - -// child table options -typedef struct { - tb_uid_t suid; - SKVRow tags; -} SCTbOptions; - -// normal table options -typedef struct { - STSchema* pSchame; -} SNTbOptions; - -struct STbOptions { - uint8_t type; - char* name; - uint32_t ttl; // time to live in (SECONDS) - SSMAOptions bsma; // Block-wise sma - union { - SSTbOptions stbOptions; - SNTbOptions ntbOptions; - SCTbOptions ctbOptions; - }; -}; - -#ifdef __cplusplus -} -#endif - -#endif /*_TD_META_IMPL_H_*/ \ No newline at end of file diff --git a/include/dnode/vnode/meta/meta.h b/include/dnode/vnode/meta/meta.h index 92c44ec4ae..09539cb287 100644 --- a/include/dnode/vnode/meta/meta.h +++ b/include/dnode/vnode/meta/meta.h @@ -16,38 +16,75 @@ #ifndef _TD_META_H_ #define _TD_META_H_ -#include "impl/metaImpl.h" +#include "os.h" +#include "trow.h" #ifdef __cplusplus extern "C" { #endif // Types exported -typedef struct SMeta SMeta; -typedef struct SMetaOptions SMetaOptions; -typedef struct STbOptions STbOptions; +typedef uint64_t tb_uid_t; +typedef struct SMeta SMeta; + +typedef struct SMetaCfg { + /// LRU cache size + uint64_t lruSize; +} SMetaCfg; + +typedef struct STbCfg { + /// name of the table + char *name; + /// time to live of the table + uint32_t ttl; + /// type of table + uint8_t type; + union { + /// super table configurations + struct { + /// super table UID + tb_uid_t suid; + /// row schema + STSchema *pSchema; + /// tag schema + STSchema *pTagSchema; + } stbCfg; + + /// normal table configuration + struct { + /// row schema + STSchema *pSchema; + } ntbCfg; + /// child table configuration + struct { + /// super table UID + tb_uid_t suid; + SRow * pTag; + } ctbCfg; + }; +} STbCfg; // SMeta operations -SMeta *metaOpen(const char *path, const SMetaOptions *pOptions); +SMeta *metaOpen(const char *path, const SMetaCfg *pOptions); void metaClose(SMeta *pMeta); void metaRemove(const char *path); -int metaCreateTable(SMeta *pMeta, const STbOptions *pTbOptions); +int metaCreateTable(SMeta *pMeta, const STbCfg *pTbOptions); int metaDropTable(SMeta *pMeta, tb_uid_t uid); int metaCommit(SMeta *pMeta); // Options -void metaOptionsInit(SMetaOptions *pOptions); -void metaOptionsClear(SMetaOptions *pOptions); +void metaOptionsInit(SMetaCfg *pOptions); +void metaOptionsClear(SMetaCfg *pOptions); // STableOpts -#define META_TABLE_OPTS_DECLARE(name) STableOpts name = {0} -void metaNormalTableOptsInit(STbOptions *pTbOptions, const char *name, const STSchema *pSchema); -void metaSuperTableOptsInit(STbOptions *pTbOptions, const char *name, tb_uid_t uid, const STSchema *pSchema, - const STSchema *pTagSchema); -void metaChildTableOptsInit(STbOptions *pTbOptions, const char *name, tb_uid_t suid, const SKVRow tags); -void metaTableOptsClear(STbOptions *pTbOptions); -uint64_t metaEncodeTbOptions(void **pBuf, STbOptions *pTbOptions); -STbOptions *metaDecodeTbOptions(void *pBuf, size_t size, bool endian); +// #define META_TABLE_OPTS_DECLARE(name) STableOpts name = {0} +// void metaNormalTableOptsInit(STbCfg *pTbOptions, const char *name, const STSchema *pSchema); +// void metaSuperTableOptsInit(STbCfg *pTbOptions, const char *name, tb_uid_t uid, const STSchema *pSchema, +// const STSchema *pTagSchema); +// void metaChildTableOptsInit(STbCfg *pTbOptions, const char *name, tb_uid_t suid, const SKVRow tags); +// void metaTableOptsClear(STbCfg *pTbOptions); +// uint64_t metaEncodeTbOptions(void **pBuf, STbCfg *pTbOptions); +// STbCfg * metaDecodeTbOptions(void *pBuf, size_t size, bool endian); #ifdef __cplusplus } diff --git a/include/dnode/vnode/vnode.h b/include/dnode/vnode/vnode.h index 52470d60a9..507cd84a1d 100644 --- a/include/dnode/vnode/vnode.h +++ b/include/dnode/vnode/vnode.h @@ -29,8 +29,8 @@ extern "C" { #endif /* ------------------------ TYPES EXPOSED ------------------------ */ -typedef struct SVnode SVnode; -typedef struct SVnodeOptions SVnodeOptions; +typedef struct SVnode SVnode; +typedef struct SVnodeCfg SVnodeCfg; /* ------------------------ SVnode ------------------------ */ /** @@ -40,7 +40,7 @@ typedef struct SVnodeOptions SVnodeOptions; * @param pVnodeOptions options of the vnode * @return SVnode* The vnode object */ -SVnode *vnodeOpen(const char *path, const SVnodeOptions *pVnodeOptions); +SVnode *vnodeOpen(const char *path, const SVnodeCfg *pVnodeOptions); /** * @brief Close a VNODE @@ -85,23 +85,23 @@ int vnodeApplyWMsg(SVnode *pVnode, SRpcMsg *pMsg, SRpcMsg **pRsp); */ int vnodeProcessSyncReq(SVnode *pVnode, SRpcMsg *pMsg, SRpcMsg **pRsp); -/* ------------------------ SVnodeOptions ------------------------ */ +/* ------------------------ SVnodeCfg ------------------------ */ /** * @brief Initialize VNODE options. * * @param pOptions The options object to be initialized. It should not be NULL. */ -void vnodeOptionsInit(SVnodeOptions *pOptions); +void vnodeOptionsInit(SVnodeCfg *pOptions); /** * @brief Clear VNODE options. * * @param pOptions Options to clear. */ -void vnodeOptionsClear(SVnodeOptions *pOptions); +void vnodeOptionsClear(SVnodeCfg *pOptions); /* ------------------------ STRUCT DEFINITIONS ------------------------ */ -struct SVnodeOptions { +struct SVnodeCfg { /** * @brief write buffer size in BYTES * @@ -137,7 +137,7 @@ struct SVnodeOptions { * @brief META options * */ - SMetaOptions metaOptions; + SMetaCfg metaOptions; // STqOptions tqOptions; // TODO }; @@ -148,27 +148,27 @@ struct SVnodeOptions { #include "taosmsg.h" #include "trpc.h" -typedef struct { - char db[TSDB_FULL_DB_NAME_LEN]; - int32_t cacheBlockSize; // MB - int32_t totalBlocks; - int32_t daysPerFile; - int32_t daysToKeep0; - int32_t daysToKeep1; - int32_t daysToKeep2; - int32_t minRowsPerFileBlock; - int32_t maxRowsPerFileBlock; - int8_t precision; // time resolution - int8_t compression; - int8_t cacheLastRow; - int8_t update; - int8_t quorum; - int8_t replica; - int8_t selfIndex; - int8_t walLevel; - int32_t fsyncPeriod; // millisecond - SReplica replicas[TSDB_MAX_REPLICA]; -} SVnodeCfg; +// typedef struct { +// char db[TSDB_FULL_DB_NAME_LEN]; +// int32_t cacheBlockSize; // MB +// int32_t totalBlocks; +// int32_t daysPerFile; +// int32_t daysToKeep0; +// int32_t daysToKeep1; +// int32_t daysToKeep2; +// int32_t minRowsPerFileBlock; +// int32_t maxRowsPerFileBlock; +// int8_t precision; // time resolution +// int8_t compression; +// int8_t cacheLastRow; +// int8_t update; +// int8_t quorum; +// int8_t replica; +// int8_t selfIndex; +// int8_t walLevel; +// int32_t fsyncPeriod; // millisecond +// SReplica replicas[TSDB_MAX_REPLICA]; +// } SVnodeCfg; typedef enum { VN_MSG_TYPE_WRITE = 1, diff --git a/source/dnode/mgmt/src/dnodeVnodes.c b/source/dnode/mgmt/src/dnodeVnodes.c index 4ec9e1dc60..36a8060161 100644 --- a/source/dnode/mgmt/src/dnodeVnodes.c +++ b/source/dnode/mgmt/src/dnodeVnodes.c @@ -15,8 +15,8 @@ #define _DEFAULT_SOURCE #include "dnodeVnodes.h" -#include "dnodeTransport.h" #include "cJSON.h" +#include "dnodeTransport.h" #include "thash.h" #include "tlockfree.h" #include "tqueue.h" @@ -30,7 +30,7 @@ typedef struct { int32_t refCount; int8_t dropped; int8_t accessState; - SVnode *pImpl; + SVnode * pImpl; taos_queue pWriteQ; taos_queue pSyncQ; taos_queue pApplyQ; @@ -48,14 +48,14 @@ typedef struct { } SVThread; static struct { - SHashObj *hash; + SHashObj * hash; SWorkerPool mgmtPool; SWorkerPool queryPool; SWorkerPool fetchPool; SMWorkerPool syncPool; SMWorkerPool writePool; taos_queue pMgmtQ; - SSteps *pSteps; + SSteps * pSteps; int32_t openVnodes; int32_t totalVnodes; SRWLatch latch; @@ -169,7 +169,7 @@ static SVnodeObj **dnodeGetVnodesFromHash(int32_t *numOfVnodes) { void *pIter = taosHashIterate(tsVnodes.hash, NULL); while (pIter) { SVnodeObj **ppVnode = pIter; - SVnodeObj *pVnode = *ppVnode; + SVnodeObj * pVnode = *ppVnode; if (pVnode) { num++; if (num < size) { @@ -191,14 +191,14 @@ static int32_t dnodeGetVnodesFromFile(SVnodeObj **ppVnodes, int32_t *numOfVnodes int32_t code = TSDB_CODE_DND_PARSE_VNODE_FILE_ERROR; int32_t len = 0; int32_t maxLen = 30000; - char *content = calloc(1, maxLen + 1); - cJSON *root = NULL; - FILE *fp = NULL; + char * content = calloc(1, maxLen + 1); + cJSON * root = NULL; + FILE * fp = NULL; char file[PATH_MAX + 20] = {0}; SVnodeObj *pVnodes = NULL; snprintf(file, PATH_MAX + 20, "%s/vnodes.json", tsVnodeDir); - + fp = fopen(file, "r"); if (!fp) { dDebug("file %s not exist", file); @@ -238,7 +238,7 @@ static int32_t dnodeGetVnodesFromFile(SVnodeObj **ppVnodes, int32_t *numOfVnodes } for (int32_t i = 0; i < vnodesNum; ++i) { - cJSON *vnode = cJSON_GetArrayItem(vnodes, i); + cJSON * vnode = cJSON_GetArrayItem(vnodes, i); SVnodeObj *pVnode = &pVnodes[i]; cJSON *vgId = cJSON_GetObjectItem(vnode, "vgId"); @@ -281,7 +281,7 @@ static int32_t dnodeWriteVnodesToFile() { int32_t len = 0; int32_t maxLen = 30000; - char *content = calloc(1, maxLen + 1); + char * content = calloc(1, maxLen + 1); int32_t numOfVnodes = 0; SVnodeObj **pVnodes = dnodeGetVnodesFromHash(&numOfVnodes); @@ -322,7 +322,7 @@ static int32_t dnodeCreateVnode(int32_t vgId, SVnodeCfg *pCfg) { int32_t code = 0; char path[PATH_MAX + 20] = {0}; - snprintf(path, sizeof(path),"%s/vnode%d", tsVnodeDir, vgId); + snprintf(path, sizeof(path), "%s/vnode%d", tsVnodeDir, vgId); SVnode *pImpl = vnodeCreate(vgId, path, pCfg); if (pImpl == NULL) { @@ -375,7 +375,7 @@ static void *dnodeOpenVnodeFunc(void *param) { dnodeReportStartup("open-vnodes", stepDesc); char path[PATH_MAX + 20] = {0}; - snprintf(path, sizeof(path),"%s/vnode%d", tsVnodeDir, pVnode->vgId); + snprintf(path, sizeof(path), "%s/vnode%d", tsVnodeDir, pVnode->vgId); SVnode *pImpl = vnodeOpen(path, NULL); if (pImpl == NULL) { dError("vgId:%d, failed to open vnode by thread:%d", pVnode->vgId, pThread->threadIndex); @@ -481,6 +481,7 @@ static int32_t dnodeParseCreateVnodeReq(SRpcMsg *rpcMsg, int32_t *vgId, SVnodeCf SCreateVnodeMsg *pCreate = rpcMsg->pCont; *vgId = htonl(pCreate->vgId); +#if 0 tstrncpy(pCfg->db, pCreate->db, TSDB_FULL_DB_NAME_LEN); pCfg->cacheBlockSize = htonl(pCreate->cacheBlockSize); pCfg->totalBlocks = htonl(pCreate->totalBlocks); @@ -503,6 +504,7 @@ static int32_t dnodeParseCreateVnodeReq(SRpcMsg *rpcMsg, int32_t *vgId, SVnodeCf pCfg->replicas[i].port = htons(pCreate->replicas[i].port); tstrncpy(pCfg->replicas[i].fqdn, pCreate->replicas[i].fqdn, TSDB_FQDN_LEN); } +#endif return 0; } @@ -668,7 +670,7 @@ static void dnodeProcessVnodeMgmtQueue(void *unused, SRpcMsg *pMsg) { break; case TSDB_MSG_TYPE_AUTH_VNODE_IN: code = vnodeProcessAuthVnodeReq(pMsg); - break; + break; case TSDB_MSG_TYPE_SYNC_VNODE_IN: code = vnodeProcessSyncVnodeReq(pMsg); break; @@ -696,7 +698,7 @@ static void dnodeProcessVnodeFetchQueue(SVnodeObj *pVnode, SVnodeMsg *pMsg) { static void dnodeProcessVnodeWriteQueue(SVnodeObj *pVnode, taos_qall qall, int32_t numOfMsgs) { SVnodeMsg *pMsg = vnodeInitMsg(numOfMsgs); - SRpcMsg *pRpcMsg = NULL; + SRpcMsg * pRpcMsg = NULL; for (int32_t i = 0; i < numOfMsgs; ++i) { taosGetQitem(qall, (void **)&pRpcMsg); @@ -1008,7 +1010,7 @@ void dnodeGetVnodeLoads(SVnodeLoads *pLoads) { pLoads->num = taosHashGetSize(tsVnodes.hash); int32_t v = 0; - void *pIter = taosHashIterate(tsVnodes.hash, NULL); + void * pIter = taosHashIterate(tsVnodes.hash, NULL); while (pIter) { SVnodeObj **ppVnode = pIter; if (ppVnode == NULL) continue; diff --git a/source/dnode/vnode/impl/inc/vnodeOptions.h b/source/dnode/vnode/impl/inc/vnodeCfg.h similarity index 73% rename from source/dnode/vnode/impl/inc/vnodeOptions.h rename to source/dnode/vnode/impl/inc/vnodeCfg.h index edb4be2a77..c4245b4023 100644 --- a/source/dnode/vnode/impl/inc/vnodeOptions.h +++ b/source/dnode/vnode/impl/inc/vnodeCfg.h @@ -13,8 +13,8 @@ * along with this program. If not, see . */ -#ifndef _TD_VNODE_OPTIONS_H_ -#define _TD_VNODE_OPTIONS_H_ +#ifndef _TD_VNODE_CFG_H_ +#define _TD_VNODE_CFG_H_ #include "vnode.h" @@ -22,13 +22,13 @@ extern "C" { #endif -extern const SVnodeOptions defaultVnodeOptions; +extern const SVnodeCfg defaultVnodeOptions; -int vnodeValidateOptions(const SVnodeOptions *); -void vnodeOptionsCopy(SVnodeOptions *pDest, const SVnodeOptions *pSrc); +int vnodeValidateOptions(const SVnodeCfg *); +void vnodeOptionsCopy(SVnodeCfg *pDest, const SVnodeCfg *pSrc); #ifdef __cplusplus } #endif -#endif /*_TD_VNODE_OPTIONS_H_*/ \ No newline at end of file +#endif /*_TD_VNODE_CFG_H_*/ \ No newline at end of file diff --git a/source/dnode/vnode/impl/inc/vnodeDef.h b/source/dnode/vnode/impl/inc/vnodeDef.h index 9cf9210cf3..791db342a3 100644 --- a/source/dnode/vnode/impl/inc/vnodeDef.h +++ b/source/dnode/vnode/impl/inc/vnodeDef.h @@ -25,7 +25,7 @@ #include "vnodeBufferPool.h" #include "vnodeCommit.h" #include "vnodeFileSystem.h" -#include "vnodeOptions.h" +#include "vnodeCfg.h" #include "vnodeStateMgr.h" #include "vnodeSync.h" @@ -34,16 +34,16 @@ extern "C" { #endif struct SVnode { - char* path; - SVnodeOptions options; - SVState state; - SVBufPool* pBufPool; - SMeta* pMeta; - STsdb* pTsdb; - STQ* pTq; - SWal* pWal; - SVnodeSync* pSync; - SVnodeFS* pFs; + char* path; + SVnodeCfg config; + SVState state; + SVBufPool* pBufPool; + SMeta* pMeta; + STsdb* pTsdb; + STQ* pTq; + SWal* pWal; + SVnodeSync* pSync; + SVnodeFS* pFs; }; #ifdef __cplusplus diff --git a/source/dnode/vnode/impl/src/vnodeBufferPool.c b/source/dnode/vnode/impl/src/vnodeBufferPool.c index daba6a9aac..3d8ebfdc47 100644 --- a/source/dnode/vnode/impl/src/vnodeBufferPool.c +++ b/source/dnode/vnode/impl/src/vnodeBufferPool.c @@ -84,8 +84,8 @@ int vnodeOpenBufPool(SVnode *pVnode) { tdListInit(&(pVnode->pBufPool->free), 0); tdListInit(&(pVnode->pBufPool->incycle), 0); - capacity = pVnode->options.wsize / VNODE_BUF_POOL_SHARDS; - if (pVnode->options.isHeapAllocator) { + capacity = pVnode->config.wsize / VNODE_BUF_POOL_SHARDS; + if (pVnode->config.isHeapAllocator) { type = E_V_HEAP_ALLOCATOR; } diff --git a/source/dnode/vnode/impl/src/vnodeOptions.c b/source/dnode/vnode/impl/src/vnodeCfg.c similarity index 65% rename from source/dnode/vnode/impl/src/vnodeOptions.c rename to source/dnode/vnode/impl/src/vnodeCfg.c index 5f519416b9..01facba888 100644 --- a/source/dnode/vnode/impl/src/vnodeOptions.c +++ b/source/dnode/vnode/impl/src/vnodeCfg.c @@ -15,20 +15,20 @@ #include "vnodeDef.h" -const SVnodeOptions defaultVnodeOptions = {0}; /* TODO */ +const SVnodeCfg defaultVnodeOptions = {0}; /* TODO */ -void vnodeOptionsInit(SVnodeOptions *pVnodeOptions) { /* TODO */ +void vnodeOptionsInit(SVnodeCfg *pVnodeOptions) { /* TODO */ vnodeOptionsCopy(pVnodeOptions, &defaultVnodeOptions); } -void vnodeOptionsClear(SVnodeOptions *pVnodeOptions) { /* TODO */ +void vnodeOptionsClear(SVnodeCfg *pVnodeOptions) { /* TODO */ } -int vnodeValidateOptions(const SVnodeOptions *pVnodeOptions) { +int vnodeValidateOptions(const SVnodeCfg *pVnodeOptions) { // TODO return 0; } -void vnodeOptionsCopy(SVnodeOptions *pDest, const SVnodeOptions *pSrc) { - memcpy((void *)pDest, (void *)pSrc, sizeof(SVnodeOptions)); +void vnodeOptionsCopy(SVnodeCfg *pDest, const SVnodeCfg *pSrc) { + memcpy((void *)pDest, (void *)pSrc, sizeof(SVnodeCfg)); } \ No newline at end of file diff --git a/source/dnode/vnode/impl/src/vnodeMain.c b/source/dnode/vnode/impl/src/vnodeMain.c index 2746b729a6..9ced3b9304 100644 --- a/source/dnode/vnode/impl/src/vnodeMain.c +++ b/source/dnode/vnode/impl/src/vnodeMain.c @@ -15,27 +15,27 @@ #include "vnodeDef.h" -static SVnode *vnodeNew(const char *path, const SVnodeOptions *pVnodeOptions); +static SVnode *vnodeNew(const char *path, const SVnodeCfg *pVnodeCfg); static void vnodeFree(SVnode *pVnode); static int vnodeOpenImpl(SVnode *pVnode); static void vnodeCloseImpl(SVnode *pVnode); -SVnode *vnodeOpen(const char *path, const SVnodeOptions *pVnodeOptions) { +SVnode *vnodeOpen(const char *path, const SVnodeCfg *pVnodeCfg) { SVnode *pVnode = NULL; // Set default options - if (pVnodeOptions == NULL) { - pVnodeOptions = &defaultVnodeOptions; + if (pVnodeCfg == NULL) { + pVnodeCfg = &defaultVnodeOptions; } // Validate options - if (vnodeValidateOptions(pVnodeOptions) < 0) { + if (vnodeValidateOptions(pVnodeCfg) < 0) { // TODO return NULL; } // Create the handle - pVnode = vnodeNew(path, pVnodeOptions); + pVnode = vnodeNew(path, pVnodeCfg); if (pVnode == NULL) { // TODO: handle error return NULL; @@ -62,7 +62,7 @@ void vnodeClose(SVnode *pVnode) { void vnodeDestroy(const char *path) { taosRemoveDir(path); } /* ------------------------ STATIC METHODS ------------------------ */ -static SVnode *vnodeNew(const char *path, const SVnodeOptions *pVnodeOptions) { +static SVnode *vnodeNew(const char *path, const SVnodeCfg *pVnodeCfg) { SVnode *pVnode = NULL; pVnode = (SVnode *)calloc(1, sizeof(*pVnode)); @@ -72,7 +72,7 @@ static SVnode *vnodeNew(const char *path, const SVnodeOptions *pVnodeOptions) { } pVnode->path = strdup(path); - vnodeOptionsCopy(&(pVnode->options), pVnodeOptions); + vnodeOptionsCopy(&(pVnode->config), pVnodeCfg); return pVnode; } @@ -94,7 +94,7 @@ static int vnodeOpenImpl(SVnode *pVnode) { // Open meta sprintf(dir, "%s/meta", pVnode->path); - pVnode->pMeta = metaOpen(dir, &(pVnode->options.metaOptions)); + pVnode->pMeta = metaOpen(dir, &(pVnode->config.metaOptions)); if (pVnode->pMeta == NULL) { // TODO: handle error return -1; @@ -102,7 +102,7 @@ static int vnodeOpenImpl(SVnode *pVnode) { // Open tsdb sprintf(dir, "%s/tsdb", pVnode->path); - pVnode->pTsdb = tsdbOpen(dir, &(pVnode->options.tsdbOptions)); + pVnode->pTsdb = tsdbOpen(dir, &(pVnode->config.tsdbOptions)); if (pVnode->pTsdb == NULL) { // TODO: handle error return -1; diff --git a/source/dnode/vnode/meta/inc/metaOptions.h b/source/dnode/vnode/meta/inc/metaCfg.h similarity index 74% rename from source/dnode/vnode/meta/inc/metaOptions.h rename to source/dnode/vnode/meta/inc/metaCfg.h index 500f2d5e59..5c72ffa680 100644 --- a/source/dnode/vnode/meta/inc/metaOptions.h +++ b/source/dnode/vnode/meta/inc/metaCfg.h @@ -13,8 +13,8 @@ * along with this program. If not, see . */ -#ifndef _TD_META_OPTIONS_H_ -#define _TD_META_OPTIONS_H_ +#ifndef _TD_META_CFG_H_ +#define _TD_META_CFG_H_ #include "meta.h" @@ -22,13 +22,13 @@ extern "C" { #endif -extern const SMetaOptions defaultMetaOptions; +extern const SMetaCfg defaultMetaOptions; -int metaValidateOptions(const SMetaOptions *); -void metaOptionsCopy(SMetaOptions *pDest, const SMetaOptions *pSrc); +int metaValidateOptions(const SMetaCfg *); +void metaOptionsCopy(SMetaCfg *pDest, const SMetaCfg *pSrc); #ifdef __cplusplus } #endif -#endif /*_TD_META_OPTIONS_H_*/ \ No newline at end of file +#endif /*_TD_META_CFG_H_*/ \ No newline at end of file diff --git a/source/dnode/vnode/meta/inc/metaDB.h b/source/dnode/vnode/meta/inc/metaDB.h index b1531d2fd7..f758af0673 100644 --- a/source/dnode/vnode/meta/inc/metaDB.h +++ b/source/dnode/vnode/meta/inc/metaDB.h @@ -34,7 +34,7 @@ typedef struct { int metaOpenDB(SMeta *pMeta); void metaCloseDB(SMeta *pMeta); -int metaSaveTableToDB(SMeta *pMeta, const STbOptions *pTbOptions); +int metaSaveTableToDB(SMeta *pMeta, const STbCfg *pTbOptions); int metaRemoveTableFromDb(SMeta *pMeta, tb_uid_t uid); #ifdef __cplusplus diff --git a/source/dnode/vnode/meta/inc/metaDef.h b/source/dnode/vnode/meta/inc/metaDef.h index b0d31de1b4..fd14efd50b 100644 --- a/source/dnode/vnode/meta/inc/metaDef.h +++ b/source/dnode/vnode/meta/inc/metaDef.h @@ -20,10 +20,10 @@ #include "meta.h" #include "metaCache.h" +#include "metaCfg.h" #include "metaDB.h" #include "metaIdx.h" -#include "metaOptions.h" -#include "metaTbOptions.h" +#include "metaTbCfg.h" #include "metaTbTag.h" #include "metaTbUid.h" @@ -33,7 +33,7 @@ extern "C" { struct SMeta { char* path; - SMetaOptions options; + SMetaCfg options; meta_db_t* pDB; meta_index_t* pIdx; meta_cache_t* pCache; diff --git a/source/dnode/vnode/meta/inc/metaIdx.h b/source/dnode/vnode/meta/inc/metaIdx.h index d43df9afc3..28d58cb4f1 100644 --- a/source/dnode/vnode/meta/inc/metaIdx.h +++ b/source/dnode/vnode/meta/inc/metaIdx.h @@ -28,7 +28,7 @@ typedef rocksdb_t meta_index_t; int metaOpenIdx(SMeta *pMeta); void metaCloseIdx(SMeta *pMeta); -int metaSaveTableToIdx(SMeta *pMeta, const STbOptions *pTbOptions); +int metaSaveTableToIdx(SMeta *pMeta, const STbCfg *pTbOptions); int metaRemoveTableFromIdx(SMeta *pMeta, tb_uid_t uid); #ifdef __cplusplus diff --git a/source/dnode/vnode/meta/inc/metaTbOptions.h b/source/dnode/vnode/meta/inc/metaTbCfg.h similarity index 69% rename from source/dnode/vnode/meta/inc/metaTbOptions.h rename to source/dnode/vnode/meta/inc/metaTbCfg.h index b0fbd3a463..68c609d6b4 100644 --- a/source/dnode/vnode/meta/inc/metaTbOptions.h +++ b/source/dnode/vnode/meta/inc/metaTbCfg.h @@ -13,8 +13,8 @@ * along with this program. If not, see . */ -#ifndef _TD_META_TABLE_OPTIONS_H_ -#define _TD_META_TABLE_OPTIONS_H_ +#ifndef _TD_META_TABLE_CFG_H_ +#define _TD_META_TABLE_CFG_H_ #include "meta.h" @@ -22,11 +22,15 @@ extern "C" { #endif -int metaValidateTbOptions(SMeta *pMeta, const STbOptions *); -size_t metaEncodeTbObjFromTbOptions(const STbOptions *, void *pBuf, size_t bsize); +#define META_SUPER_TABLE 0 +#define META_CHILD_TABLE 1 +#define META_NORMAL_TABLE 2 + +int metaValidateTbOptions(SMeta *pMeta, const STbCfg *); +size_t metaEncodeTbObjFromTbOptions(const STbCfg *, void *pBuf, size_t bsize); #ifdef __cplusplus } #endif -#endif /*_TD_META_TABLE_OPTIONS_H_*/ \ No newline at end of file +#endif /*_TD_META_TABLE_CFG_H_*/ \ No newline at end of file diff --git a/source/dnode/vnode/meta/src/metaCache.c b/source/dnode/vnode/meta/src/metaCache.c index 9166f1724a..aaa97caea0 100644 --- a/source/dnode/vnode/meta/src/metaCache.c +++ b/source/dnode/vnode/meta/src/metaCache.c @@ -18,8 +18,8 @@ int metaOpenCache(SMeta *pMeta) { // TODO - if (pMeta->options.lruCacheSize) { - pMeta->pCache = rocksdb_cache_create_lru(pMeta->options.lruCacheSize); + if (pMeta->options.lruSize) { + pMeta->pCache = rocksdb_cache_create_lru(pMeta->options.lruSize); if (pMeta->pCache == NULL) { // TODO: handle error return -1; diff --git a/source/dnode/vnode/meta/src/metaOptions.c b/source/dnode/vnode/meta/src/metaCfg.c similarity index 68% rename from source/dnode/vnode/meta/src/metaOptions.c rename to source/dnode/vnode/meta/src/metaCfg.c index f92cd73cae..cbaac1c409 100644 --- a/source/dnode/vnode/meta/src/metaOptions.c +++ b/source/dnode/vnode/meta/src/metaCfg.c @@ -15,20 +15,20 @@ #include "metaDef.h" -const SMetaOptions defaultMetaOptions = {.lruCacheSize = 0}; +const SMetaCfg defaultMetaOptions = {.lruSize = 0}; /* ------------------------ EXPOSED METHODS ------------------------ */ -void metaOptionsInit(SMetaOptions *pMetaOptions) { metaOptionsCopy(pMetaOptions, &defaultMetaOptions); } +void metaOptionsInit(SMetaCfg *pMetaOptions) { metaOptionsCopy(pMetaOptions, &defaultMetaOptions); } -void metaOptionsClear(SMetaOptions *pMetaOptions) { +void metaOptionsClear(SMetaCfg *pMetaOptions) { // TODO } -int metaValidateOptions(const SMetaOptions *pMetaOptions) { +int metaValidateOptions(const SMetaCfg *pMetaOptions) { // TODO return 0; } -void metaOptionsCopy(SMetaOptions *pDest, const SMetaOptions *pSrc) { memcpy(pDest, pSrc, sizeof(*pSrc)); } +void metaOptionsCopy(SMetaCfg *pDest, const SMetaCfg *pSrc) { memcpy(pDest, pSrc, sizeof(*pSrc)); } /* ------------------------ STATIC METHODS ------------------------ */ \ No newline at end of file diff --git a/source/dnode/vnode/meta/src/metaDB.c b/source/dnode/vnode/meta/src/metaDB.c index 8865678508..1f511ca4dc 100644 --- a/source/dnode/vnode/meta/src/metaDB.c +++ b/source/dnode/vnode/meta/src/metaDB.c @@ -92,7 +92,7 @@ void metaCloseDB(SMeta *pMeta) { } } -int metaSaveTableToDB(SMeta *pMeta, const STbOptions *pTbOptions) { +int metaSaveTableToDB(SMeta *pMeta, const STbCfg *pTbOptions) { tb_uid_t uid; char * err = NULL; size_t size; @@ -102,7 +102,7 @@ int metaSaveTableToDB(SMeta *pMeta, const STbOptions *pTbOptions) { // Generate a uid for child and normal table if (pTbOptions->type == META_SUPER_TABLE) { - uid = pTbOptions->stbOptions.uid; + uid = pTbOptions->stbCfg.suid; } else { uid = metaGenerateUid(pMeta); } @@ -117,22 +117,22 @@ int metaSaveTableToDB(SMeta *pMeta, const STbOptions *pTbOptions) { switch (pTbOptions->type) { case META_NORMAL_TABLE: // save schemaDB - metaSaveSchemaDB(pMeta, uid, pTbOptions->ntbOptions.pSchame); + metaSaveSchemaDB(pMeta, uid, pTbOptions->ntbCfg.pSchema); break; case META_SUPER_TABLE: // save schemaDB - metaSaveSchemaDB(pMeta, uid, pTbOptions->stbOptions.pSchema); + metaSaveSchemaDB(pMeta, uid, pTbOptions->stbCfg.pSchema); // save mapDB (really need?) rocksdb_put(pMeta->pDB->mapDb, wopt, (char *)(&uid), sizeof(uid), "", 0, &err); break; case META_CHILD_TABLE: // save tagDB - rocksdb_put(pMeta->pDB->tagDb, wopt, (char *)(&uid), sizeof(uid), pTbOptions->ctbOptions.tags, - kvRowLen(pTbOptions->ctbOptions.tags), &err); + rocksdb_put(pMeta->pDB->tagDb, wopt, (char *)(&uid), sizeof(uid), pTbOptions->ctbCfg.pTag, + kvRowLen(pTbOptions->ctbCfg.pTag), &err); // save mapDB - metaSaveMapDB(pMeta, pTbOptions->ctbOptions.suid, uid); + metaSaveMapDB(pMeta, pTbOptions->ctbCfg.suid, uid); break; default: ASSERT(0); diff --git a/source/dnode/vnode/meta/src/metaIdx.c b/source/dnode/vnode/meta/src/metaIdx.c index 54cc8bd461..0666609f9f 100644 --- a/source/dnode/vnode/meta/src/metaIdx.c +++ b/source/dnode/vnode/meta/src/metaIdx.c @@ -47,7 +47,7 @@ void metaCloseIdx(SMeta *pMeta) { /* TODO */ } } -int metaSaveTableToIdx(SMeta *pMeta, const STbOptions *pTbOptions) { +int metaSaveTableToIdx(SMeta *pMeta, const STbCfg *pTbOptions) { // TODO return 0; } \ No newline at end of file diff --git a/source/dnode/vnode/meta/src/metaMain.c b/source/dnode/vnode/meta/src/metaMain.c index 000b10a126..a936002328 100644 --- a/source/dnode/vnode/meta/src/metaMain.c +++ b/source/dnode/vnode/meta/src/metaMain.c @@ -15,17 +15,14 @@ #include "tcoding.h" -#include "meta.h" -#include "metaDB.h" #include "metaDef.h" -#include "metaOptions.h" -static SMeta *metaNew(const char *path, const SMetaOptions *pMetaOptions); +static SMeta *metaNew(const char *path, const SMetaCfg *pMetaOptions); static void metaFree(SMeta *pMeta); static int metaOpenImpl(SMeta *pMeta); static void metaCloseImpl(SMeta *pMeta); -SMeta *metaOpen(const char *path, const SMetaOptions *pMetaOptions) { +SMeta *metaOpen(const char *path, const SMetaCfg *pMetaOptions) { SMeta *pMeta = NULL; // Set default options @@ -68,7 +65,7 @@ void metaClose(SMeta *pMeta) { void metaRemove(const char *path) { taosRemoveDir(path); } /* ------------------------ STATIC METHODS ------------------------ */ -static SMeta *metaNew(const char *path, const SMetaOptions *pMetaOptions) { +static SMeta *metaNew(const char *path, const SMetaCfg *pMetaOptions) { SMeta *pMeta; size_t psize = strlen(path); diff --git a/source/dnode/vnode/meta/src/metaTable.c b/source/dnode/vnode/meta/src/metaTable.c index d4a1ad3e38..6a92fedc3d 100644 --- a/source/dnode/vnode/meta/src/metaTable.c +++ b/source/dnode/vnode/meta/src/metaTable.c @@ -15,7 +15,7 @@ #include "metaDef.h" -int metaCreateTable(SMeta *pMeta, const STbOptions *pTbOptions) { +int metaCreateTable(SMeta *pMeta, const STbCfg *pTbOptions) { // Validate the tbOptions if (metaValidateTbOptions(pMeta, pTbOptions) < 0) { // TODO: handle error diff --git a/source/dnode/vnode/meta/src/metaTbOptions.c b/source/dnode/vnode/meta/src/metaTbCfg.c similarity index 75% rename from source/dnode/vnode/meta/src/metaTbOptions.c rename to source/dnode/vnode/meta/src/metaTbCfg.c index 9bf9607df7..8d58edaa08 100644 --- a/source/dnode/vnode/meta/src/metaTbOptions.c +++ b/source/dnode/vnode/meta/src/metaTbCfg.c @@ -16,12 +16,12 @@ #include "metaDef.h" #include "tcoding.h" -int metaValidateTbOptions(SMeta *pMeta, const STbOptions *pTbOptions) { +int metaValidateTbOptions(SMeta *pMeta, const STbCfg *pTbOptions) { // TODO return 0; } -size_t metaEncodeTbObjFromTbOptions(const STbOptions *pTbOptions, void *pBuf, size_t bsize) { +size_t metaEncodeTbObjFromTbOptions(const STbCfg *pTbOptions, void *pBuf, size_t bsize) { void **ppBuf = &pBuf; int tlen = 0; @@ -31,12 +31,12 @@ size_t metaEncodeTbObjFromTbOptions(const STbOptions *pTbOptions, void *pBuf, si switch (pTbOptions->type) { case META_SUPER_TABLE: - tlen += taosEncodeFixedU64(ppBuf, pTbOptions->stbOptions.uid); - tlen += tdEncodeSchema(ppBuf, pTbOptions->stbOptions.pTagSchema); + tlen += taosEncodeFixedU64(ppBuf, pTbOptions->stbCfg.suid); + tlen += tdEncodeSchema(ppBuf, pTbOptions->stbCfg.pTagSchema); // TODO: encode schema version array break; case META_CHILD_TABLE: - tlen += taosEncodeFixedU64(ppBuf, pTbOptions->ctbOptions.suid); + tlen += taosEncodeFixedU64(ppBuf, pTbOptions->ctbCfg.suid); break; case META_NORMAL_TABLE: // TODO: encode schema version array From 73d2c81bd1450d56b9d84202cdad9034453c9ced Mon Sep 17 00:00:00 2001 From: Hongze Cheng Date: Mon, 22 Nov 2021 15:18:32 +0800 Subject: [PATCH 07/41] make compile --- source/dnode/vnode/tq/src/tq.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/dnode/vnode/tq/src/tq.c b/source/dnode/vnode/tq/src/tq.c index c010042b8c..099d540c20 100644 --- a/source/dnode/vnode/tq/src/tq.c +++ b/source/dnode/vnode/tq/src/tq.c @@ -50,7 +50,7 @@ STQ* tqOpen(const char* path, TqConfig* tqConfig, TqLogReader* tqLogReader, SMem pTq->tqConfig = tqConfig; pTq->tqLogReader = tqLogReader; pTq->tqMemRef.pAlloctorFactory = allocFac; - pTq->tqMemRef.pAllocator = allocFac->create(); + pTq->tqMemRef.pAllocator = allocFac->create(allocFac); if(pTq->tqMemRef.pAllocator == NULL) { //TODO } From 3906f6a70731b6ee0920bd3d5acf4a790ce2537a Mon Sep 17 00:00:00 2001 From: Hongze Cheng Date: Mon, 22 Nov 2021 15:39:05 +0800 Subject: [PATCH 08/41] refact --- include/dnode/vnode/vnode.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/include/dnode/vnode/vnode.h b/include/dnode/vnode/vnode.h index 507cd84a1d..2c534fd3e3 100644 --- a/include/dnode/vnode/vnode.h +++ b/include/dnode/vnode/vnode.h @@ -37,10 +37,10 @@ typedef struct SVnodeCfg SVnodeCfg; * @brief Open a VNODE. * * @param path path of the vnode - * @param pVnodeOptions options of the vnode + * @param pVnodeCfg options of the vnode * @return SVnode* The vnode object */ -SVnode *vnodeOpen(const char *path, const SVnodeCfg *pVnodeOptions); +SVnode *vnodeOpen(const char *path, const SVnodeCfg *pVnodeCfg); /** * @brief Close a VNODE From 9ae30318989c24b43a89a77453a1d0ad0109bf86 Mon Sep 17 00:00:00 2001 From: Hongze Cheng Date: Wed, 24 Nov 2021 16:01:11 +0800 Subject: [PATCH 09/41] make compile --- source/dnode/mgmt/impl/src/dndVnodes.c | 38 ++++++++++++++------------ 1 file changed, 20 insertions(+), 18 deletions(-) diff --git a/source/dnode/mgmt/impl/src/dndVnodes.c b/source/dnode/mgmt/impl/src/dndVnodes.c index d5e94106a7..7c599923c0 100644 --- a/source/dnode/mgmt/impl/src/dndVnodes.c +++ b/source/dnode/mgmt/impl/src/dndVnodes.c @@ -22,7 +22,7 @@ typedef struct { int32_t refCount; int8_t dropped; int8_t accessState; - SVnode *pImpl; + SVnode * pImpl; taos_queue pWriteQ; taos_queue pSyncQ; taos_queue pApplyQ; @@ -37,7 +37,7 @@ typedef struct { int32_t threadIndex; pthread_t *pThreadId; SVnodeObj *pVnodes; - SDnode *pDnode; + SDnode * pDnode; } SVnodeThread; static int32_t dndInitVnodeReadWorker(SDnode *pDnode); @@ -72,7 +72,7 @@ void dndProcessVnodeSyncMsg(SDnode *pDnode, SRpcMsg *pMsg, SEpSet *pEp void dndProcessVnodeMgmtMsg(SDnode *pDnode, SRpcMsg *pMsg, SEpSet *pEpSet); static int32_t dndPutMsgIntoVnodeApplyQueue(SDnode *pDnode, int32_t vgId, SVnodeMsg *pMsg); -static SVnodeObj *dndAcquireVnode(SDnode *pDnode, int32_t vgId); +static SVnodeObj * dndAcquireVnode(SDnode *pDnode, int32_t vgId); static void dndReleaseVnode(SDnode *pDnode, SVnodeObj *pVnode); static int32_t dndCreateVnodeWrapper(SDnode *pDnode, int32_t vgId, SVnode *pImpl); static void dndDropVnodeWrapper(SDnode *pDnode, SVnodeObj *pVnode); @@ -94,7 +94,7 @@ static int32_t dndProcessCompactVnodeReq(SDnode *pDnode, SRpcMsg *rpcMsg); static SVnodeObj *dndAcquireVnode(SDnode *pDnode, int32_t vgId) { SVnodesMgmt *pMgmt = &pDnode->vmgmt; - SVnodeObj *pVnode = NULL; + SVnodeObj * pVnode = NULL; int32_t refCount = 0; taosRLockLatch(&pMgmt->latch); @@ -127,7 +127,7 @@ static void dndReleaseVnode(SDnode *pDnode, SVnodeObj *pVnode) { static int32_t dndCreateVnodeWrapper(SDnode *pDnode, int32_t vgId, SVnode *pImpl) { SVnodesMgmt *pMgmt = &pDnode->vmgmt; - SVnodeObj *pVnode = calloc(1, sizeof(SVnodeObj)); + SVnodeObj * pVnode = calloc(1, sizeof(SVnodeObj)); if (pVnode == NULL) { terrno = TSDB_CODE_OUT_OF_MEMORY; return -1; @@ -201,7 +201,7 @@ static SVnodeObj **dndGetVnodesFromHash(SDnode *pDnode, int32_t *numOfVnodes) { void *pIter = taosHashIterate(pMgmt->hash, NULL); while (pIter) { SVnodeObj **ppVnode = pIter; - SVnodeObj *pVnode = *ppVnode; + SVnodeObj * pVnode = *ppVnode; if (pVnode) { num++; if (num < size) { @@ -223,9 +223,9 @@ static int32_t dndGetVnodesFromFile(SDnode *pDnode, SVnodeObj **ppVnodes, int32_ int32_t code = TSDB_CODE_DND_VNODE_READ_FILE_ERROR; int32_t len = 0; int32_t maxLen = 30000; - char *content = calloc(1, maxLen + 1); - cJSON *root = NULL; - FILE *fp = NULL; + char * content = calloc(1, maxLen + 1); + cJSON * root = NULL; + FILE * fp = NULL; char file[PATH_MAX + 20] = {0}; SVnodeObj *pVnodes = NULL; @@ -270,7 +270,7 @@ static int32_t dndGetVnodesFromFile(SDnode *pDnode, SVnodeObj **ppVnodes, int32_ } for (int32_t i = 0; i < vnodesNum; ++i) { - cJSON *vnode = cJSON_GetArrayItem(vnodes, i); + cJSON * vnode = cJSON_GetArrayItem(vnodes, i); SVnodeObj *pVnode = &pVnodes[i]; cJSON *vgId = cJSON_GetObjectItem(vnode, "vgId"); @@ -314,7 +314,7 @@ static int32_t dndWriteVnodesToFile(SDnode *pDnode) { int32_t len = 0; int32_t maxLen = 30000; - char *content = calloc(1, maxLen + 1); + char * content = calloc(1, maxLen + 1); int32_t numOfVnodes = 0; SVnodeObj **pVnodes = dndGetVnodesFromHash(pDnode, &numOfVnodes); @@ -392,8 +392,8 @@ static int32_t dndDropVnode(SDnode *pDnode, SVnodeObj *pVnode) { static void *dnodeOpenVnodeFunc(void *param) { SVnodeThread *pThread = param; - SDnode *pDnode = pThread->pDnode; - SVnodesMgmt *pMgmt = &pDnode->vmgmt; + SDnode * pDnode = pThread->pDnode; + SVnodesMgmt * pMgmt = &pDnode->vmgmt; dDebug("thread:%d, start to open %d vnodes", pThread->threadIndex, pThread->vnodeNum); setThreadName("open-vnodes"); @@ -516,6 +516,7 @@ static int32_t dndParseCreateVnodeReq(SRpcMsg *rpcMsg, int32_t *vgId, SVnodeCfg SCreateVnodeMsg *pCreate = rpcMsg->pCont; *vgId = htonl(pCreate->vgId); +#if 0 tstrncpy(pCfg->db, pCreate->db, TSDB_FULL_DB_NAME_LEN); pCfg->cacheBlockSize = htonl(pCreate->cacheBlockSize); pCfg->totalBlocks = htonl(pCreate->totalBlocks); @@ -538,6 +539,7 @@ static int32_t dndParseCreateVnodeReq(SRpcMsg *rpcMsg, int32_t *vgId, SVnodeCfg pCfg->replicas[i].port = htons(pCreate->replicas[i].port); tstrncpy(pCfg->replicas[i].fqdn, pCreate->replicas[i].fqdn, TSDB_FQDN_LEN); } +#endif return 0; } @@ -727,7 +729,7 @@ static void dndProcessVnodeFetchQueue(SVnodeObj *pVnode, SVnodeMsg *pMsg) { static void dndProcessVnodeWriteQueue(SVnodeObj *pVnode, taos_qall qall, int32_t numOfMsgs) { SVnodeMsg *pMsg = vnodeInitMsg(numOfMsgs); - SRpcMsg *pRpcMsg = NULL; + SRpcMsg * pRpcMsg = NULL; for (int32_t i = 0; i < numOfMsgs; ++i) { taosGetQitem(qall, (void **)&pRpcMsg); @@ -993,7 +995,7 @@ static void dndFreeVnodeApplyQueue(SDnode *pDnode, SVnodeObj *pVnode) { } static int32_t dndInitVnodeWriteWorker(SDnode *pDnode) { - SVnodesMgmt *pMgmt = &pDnode->vmgmt; + SVnodesMgmt * pMgmt = &pDnode->vmgmt; SMWorkerPool *pPool = &pMgmt->writePool; pPool->name = "vnode-write"; pPool->max = tsNumOfCores; @@ -1031,7 +1033,7 @@ static int32_t dndInitVnodeSyncWorker(SDnode *pDnode) { int32_t maxThreads = tsNumOfCores / 2; if (maxThreads < 1) maxThreads = 1; - SVnodesMgmt *pMgmt = &pDnode->vmgmt; + SVnodesMgmt * pMgmt = &pDnode->vmgmt; SMWorkerPool *pPool = &pMgmt->writePool; pPool->name = "vnode-sync"; pPool->max = maxThreads; @@ -1097,12 +1099,12 @@ void dndGetVnodeLoads(SDnode *pDnode, SVnodeLoads *pLoads) { pLoads->num = taosHashGetSize(pMgmt->hash); int32_t v = 0; - void *pIter = taosHashIterate(pMgmt->hash, NULL); + void * pIter = taosHashIterate(pMgmt->hash, NULL); while (pIter) { SVnodeObj **ppVnode = pIter; if (ppVnode == NULL || *ppVnode == NULL) continue; - SVnodeObj *pVnode = *ppVnode; + SVnodeObj * pVnode = *ppVnode; SVnodeLoad *pLoad = &pLoads->data[v++]; vnodeGetLoad(pVnode->pImpl, pLoad); From 2b5e0592c4d4efc7dd8adc1f4ec4d02b00a3f8c9 Mon Sep 17 00:00:00 2001 From: Hongze Cheng Date: Wed, 24 Nov 2021 16:29:02 +0800 Subject: [PATCH 10/41] refact --- include/dnode/vnode/tq/tq.h | 8 ++-- include/dnode/vnode/tsdb/tsdb.h | 12 +++--- include/dnode/vnode/vnode.h | 52 ++++++++++------------- source/dnode/vnode/impl/src/vnodeMain.c | 4 +- source/dnode/vnode/tq/src/tq.c | 2 +- source/dnode/vnode/tsdb/inc/tsdbDef.h | 2 +- source/dnode/vnode/tsdb/inc/tsdbOptions.h | 6 +-- source/dnode/vnode/tsdb/src/tsdbMain.c | 6 +-- source/dnode/vnode/tsdb/src/tsdbOptions.c | 10 ++--- 9 files changed, 47 insertions(+), 55 deletions(-) diff --git a/include/dnode/vnode/tq/tq.h b/include/dnode/vnode/tq/tq.h index 2785b6de96..85533f65bc 100644 --- a/include/dnode/vnode/tq/tq.h +++ b/include/dnode/vnode/tq/tq.h @@ -161,9 +161,9 @@ typedef struct TqLogReader { int64_t (*logGetLastVer)(void* logHandle); } TqLogReader; -typedef struct TqConfig { +typedef struct STqCfg { // TODO -} TqConfig; +} STqCfg; typedef struct TqMemRef { SMemAllocatorFactory *pAlloctorFactory; @@ -256,14 +256,14 @@ typedef struct STQ { // the collection of group handle // the handle of kvstore char* path; - TqConfig* tqConfig; + STqCfg* tqConfig; TqLogReader* tqLogReader; TqMemRef tqMemRef; TqMetaStore* tqMeta; } STQ; // open in each vnode -STQ* tqOpen(const char* path, TqConfig* tqConfig, TqLogReader* tqLogReader, SMemAllocatorFactory *allocFac); +STQ* tqOpen(const char* path, STqCfg* tqConfig, TqLogReader* tqLogReader, SMemAllocatorFactory *allocFac); void tqDestroy(STQ*); // void* will be replace by a msg type diff --git a/include/dnode/vnode/tsdb/tsdb.h b/include/dnode/vnode/tsdb/tsdb.h index e486da5419..d74a828538 100644 --- a/include/dnode/vnode/tsdb/tsdb.h +++ b/include/dnode/vnode/tsdb/tsdb.h @@ -22,21 +22,21 @@ extern "C" { // TYPES EXPOSED typedef struct STsdb STsdb; -typedef struct STsdbOptions STsdbOptions; +typedef struct STsdbCfg STsdbCfg; typedef struct STsdbMemAllocator STsdbMemAllocator; // STsdb -STsdb *tsdbOpen(const char *path, const STsdbOptions *); +STsdb *tsdbOpen(const char *path, const STsdbCfg *); void tsdbClose(STsdb *); void tsdbRemove(const char *path); int tsdbInsertData(STsdb *pTsdb, void *); -// STsdbOptions -int tsdbOptionsInit(STsdbOptions *); -void tsdbOptionsClear(STsdbOptions *); +// STsdbCfg +int tsdbOptionsInit(STsdbCfg *); +void tsdbOptionsClear(STsdbCfg *); /* ------------------------ STRUCT DEFINITIONS ------------------------ */ -struct STsdbOptions { +struct STsdbCfg { uint64_t lruCacheSize; /* TODO */ }; diff --git a/include/dnode/vnode/vnode.h b/include/dnode/vnode/vnode.h index febcdafacd..cc74f8e433 100644 --- a/include/dnode/vnode/vnode.h +++ b/include/dnode/vnode/vnode.h @@ -23,6 +23,7 @@ #include "tarray.h" #include "tq.h" #include "tsdb.h" +#include "wal.h" #ifdef __cplusplus extern "C" { @@ -102,43 +103,34 @@ void vnodeOptionsClear(SVnodeCfg *pOptions); /* ------------------------ STRUCT DEFINITIONS ------------------------ */ struct SVnodeCfg { - /** - * @brief write buffer size in BYTES - * - */ - uint64_t wsize; + /** vnode buffer pool options */ + struct { + /** write buffer size */ + uint64_t wsize; + /** use heap allocator or arena allocator */ + bool isHeapAllocator; + }; - /** - * @brief time to live of tables in this vnode - * in SECONDS - * - */ + /** time to live of tables in this vnode * uint32_t ttl; - /** - * @brief if time-series requests eventual consistency - * - */ + /** data to keep in this vnode */ + uint32_t keep; + + /** if TS data is eventually consistency */ bool isWeak; - /** - * @brief if the allocator is heap allcator or arena allocator - * - */ - bool isHeapAllocator; + /** TSDB config */ + STsdbCfg tsdbCfg; - /** - * @brief TSDB options - * - */ - STsdbOptions tsdbOptions; + /** META config */ + SMetaCfg metaCfg; - /** - * @brief META options - * - */ - SMetaCfg metaOptions; - // STqOptions tqOptions; // TODO + /** TQ config */ + STqCfg tqCfg; + + /** WAL config */ + SWalCfg walCfg; }; /* ------------------------ FOR COMPILE ------------------------ */ diff --git a/source/dnode/vnode/impl/src/vnodeMain.c b/source/dnode/vnode/impl/src/vnodeMain.c index 9ced3b9304..74a7ea61b0 100644 --- a/source/dnode/vnode/impl/src/vnodeMain.c +++ b/source/dnode/vnode/impl/src/vnodeMain.c @@ -94,7 +94,7 @@ static int vnodeOpenImpl(SVnode *pVnode) { // Open meta sprintf(dir, "%s/meta", pVnode->path); - pVnode->pMeta = metaOpen(dir, &(pVnode->config.metaOptions)); + pVnode->pMeta = metaOpen(dir, &(pVnode->config.metaCfg)); if (pVnode->pMeta == NULL) { // TODO: handle error return -1; @@ -102,7 +102,7 @@ static int vnodeOpenImpl(SVnode *pVnode) { // Open tsdb sprintf(dir, "%s/tsdb", pVnode->path); - pVnode->pTsdb = tsdbOpen(dir, &(pVnode->config.tsdbOptions)); + pVnode->pTsdb = tsdbOpen(dir, &(pVnode->config.tsdbCfg)); if (pVnode->pTsdb == NULL) { // TODO: handle error return -1; diff --git a/source/dnode/vnode/tq/src/tq.c b/source/dnode/vnode/tq/src/tq.c index 099d540c20..c5f2252c72 100644 --- a/source/dnode/vnode/tq/src/tq.c +++ b/source/dnode/vnode/tq/src/tq.c @@ -40,7 +40,7 @@ void* tqSerializeBufItem(TqBufferItem* bufItem, void* ptr); const void* tqDeserializeBufHandle(const void* pBytes, TqBufferHandle* bufHandle); const void* tqDeserializeBufItem(const void* pBytes, TqBufferItem* bufItem); -STQ* tqOpen(const char* path, TqConfig* tqConfig, TqLogReader* tqLogReader, SMemAllocatorFactory *allocFac) { +STQ* tqOpen(const char* path, STqCfg* tqConfig, TqLogReader* tqLogReader, SMemAllocatorFactory *allocFac) { STQ* pTq = malloc(sizeof(STQ)); if(pTq == NULL) { //TODO: memory error diff --git a/source/dnode/vnode/tsdb/inc/tsdbDef.h b/source/dnode/vnode/tsdb/inc/tsdbDef.h index ca3d0319c1..0a57f5f670 100644 --- a/source/dnode/vnode/tsdb/inc/tsdbDef.h +++ b/source/dnode/vnode/tsdb/inc/tsdbDef.h @@ -28,7 +28,7 @@ extern "C" { struct STsdb { char * path; - STsdbOptions options; + STsdbCfg options; SMemAllocatorFactory *pmaf; }; diff --git a/source/dnode/vnode/tsdb/inc/tsdbOptions.h b/source/dnode/vnode/tsdb/inc/tsdbOptions.h index ffd409099a..46607ea2fe 100644 --- a/source/dnode/vnode/tsdb/inc/tsdbOptions.h +++ b/source/dnode/vnode/tsdb/inc/tsdbOptions.h @@ -20,10 +20,10 @@ extern "C" { #endif -extern const STsdbOptions defautlTsdbOptions; +extern const STsdbCfg defautlTsdbOptions; -int tsdbValidateOptions(const STsdbOptions *); -void tsdbOptionsCopy(STsdbOptions *pDest, const STsdbOptions *pSrc); +int tsdbValidateOptions(const STsdbCfg *); +void tsdbOptionsCopy(STsdbCfg *pDest, const STsdbCfg *pSrc); #ifdef __cplusplus } diff --git a/source/dnode/vnode/tsdb/src/tsdbMain.c b/source/dnode/vnode/tsdb/src/tsdbMain.c index 10b6c2aa65..2fe7a61930 100644 --- a/source/dnode/vnode/tsdb/src/tsdbMain.c +++ b/source/dnode/vnode/tsdb/src/tsdbMain.c @@ -15,12 +15,12 @@ #include "tsdbDef.h" -static STsdb *tsdbNew(const char *path, const STsdbOptions *pTsdbOptions); +static STsdb *tsdbNew(const char *path, const STsdbCfg *pTsdbOptions); static void tsdbFree(STsdb *pTsdb); static int tsdbOpenImpl(STsdb *pTsdb); static void tsdbCloseImpl(STsdb *pTsdb); -STsdb *tsdbOpen(const char *path, const STsdbOptions *pTsdbOptions) { +STsdb *tsdbOpen(const char *path, const STsdbCfg *pTsdbOptions) { STsdb *pTsdb = NULL; // Set default TSDB Options @@ -62,7 +62,7 @@ void tsdbClose(STsdb *pTsdb) { void tsdbRemove(const char *path) { taosRemoveDir(path); } /* ------------------------ STATIC METHODS ------------------------ */ -static STsdb *tsdbNew(const char *path, const STsdbOptions *pTsdbOptions) { +static STsdb *tsdbNew(const char *path, const STsdbCfg *pTsdbOptions) { STsdb *pTsdb = NULL; pTsdb = (STsdb *)calloc(1, sizeof(STsdb)); diff --git a/source/dnode/vnode/tsdb/src/tsdbOptions.c b/source/dnode/vnode/tsdb/src/tsdbOptions.c index 3a1102f048..1c2b3c640a 100644 --- a/source/dnode/vnode/tsdb/src/tsdbOptions.c +++ b/source/dnode/vnode/tsdb/src/tsdbOptions.c @@ -15,20 +15,20 @@ #include "tsdbDef.h" -const STsdbOptions defautlTsdbOptions = {.lruCacheSize = 0}; +const STsdbCfg defautlTsdbOptions = {.lruCacheSize = 0}; -int tsdbOptionsInit(STsdbOptions *pTsdbOptions) { +int tsdbOptionsInit(STsdbCfg *pTsdbOptions) { // TODO return 0; } -void tsdbOptionsClear(STsdbOptions *pTsdbOptions) { +void tsdbOptionsClear(STsdbCfg *pTsdbOptions) { // TODO } -int tsdbValidateOptions(const STsdbOptions *pTsdbOptions) { +int tsdbValidateOptions(const STsdbCfg *pTsdbOptions) { // TODO return 0; } -void tsdbOptionsCopy(STsdbOptions *pDest, const STsdbOptions *pSrc) { memcpy(pDest, pSrc, sizeof(STsdbOptions)); } \ No newline at end of file +void tsdbOptionsCopy(STsdbCfg *pDest, const STsdbCfg *pSrc) { memcpy(pDest, pSrc, sizeof(STsdbCfg)); } \ No newline at end of file From 55a2ee0aa26cdafa7a11cf9c872d0a1ddb6d7769 Mon Sep 17 00:00:00 2001 From: Hongze Cheng Date: Wed, 24 Nov 2021 18:37:15 +0800 Subject: [PATCH 11/41] refact --- include/common/type/type.h | 27 +++++++++++++++++++++++++ source/common/type/type.c | 14 +++++++++++++ source/common/type/typeBigint.c | 14 +++++++++++++ source/common/type/typeBinary.c | 14 +++++++++++++ source/common/type/typeBlob.c | 14 +++++++++++++ source/common/type/typeBool.c | 14 +++++++++++++ source/common/type/typeDecimal.c | 14 +++++++++++++ source/common/type/typeDouble.c | 14 +++++++++++++ source/common/type/typeFloat.c | 14 +++++++++++++ source/common/type/typeInt.c | 14 +++++++++++++ source/common/type/typeJson.c | 14 +++++++++++++ source/common/type/typeLongblob.c | 14 +++++++++++++ source/common/type/typeNchar.c | 14 +++++++++++++ source/common/type/typeNull.c | 14 +++++++++++++ source/common/type/typeSmallint.c | 14 +++++++++++++ source/common/type/typeTimestamp.c | 14 +++++++++++++ source/common/type/typeTinyint.c | 14 +++++++++++++ source/common/type/typeUBigint.c | 14 +++++++++++++ source/common/type/typeUSmallint.c | 14 +++++++++++++ source/common/type/typeUTinyint.c | 14 +++++++++++++ source/common/type/typeUint.c | 14 +++++++++++++ source/common/type/typeVarchar.c | 14 +++++++++++++ source/dnode/vnode/impl/src/vnodeMain.c | 12 +++++------ 23 files changed, 327 insertions(+), 6 deletions(-) create mode 100644 include/common/type/type.h create mode 100644 source/common/type/type.c create mode 100644 source/common/type/typeBigint.c create mode 100644 source/common/type/typeBinary.c create mode 100644 source/common/type/typeBlob.c create mode 100644 source/common/type/typeBool.c create mode 100644 source/common/type/typeDecimal.c create mode 100644 source/common/type/typeDouble.c create mode 100644 source/common/type/typeFloat.c create mode 100644 source/common/type/typeInt.c create mode 100644 source/common/type/typeJson.c create mode 100644 source/common/type/typeLongblob.c create mode 100644 source/common/type/typeNchar.c create mode 100644 source/common/type/typeNull.c create mode 100644 source/common/type/typeSmallint.c create mode 100644 source/common/type/typeTimestamp.c create mode 100644 source/common/type/typeTinyint.c create mode 100644 source/common/type/typeUBigint.c create mode 100644 source/common/type/typeUSmallint.c create mode 100644 source/common/type/typeUTinyint.c create mode 100644 source/common/type/typeUint.c create mode 100644 source/common/type/typeVarchar.c diff --git a/include/common/type/type.h b/include/common/type/type.h new file mode 100644 index 0000000000..3cbea6edbb --- /dev/null +++ b/include/common/type/type.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_TYPE_H_ +#define _TD_TYPE_H_ + +#ifdef __cplusplus +extern "C" { +#endif + +#ifdef __cplusplus +} +#endif + +#endif /*_TD_TYPE_H_*/ \ No newline at end of file diff --git a/source/common/type/type.c b/source/common/type/type.c new file mode 100644 index 0000000000..6dea4a4e57 --- /dev/null +++ b/source/common/type/type.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/common/type/typeBigint.c b/source/common/type/typeBigint.c new file mode 100644 index 0000000000..6dea4a4e57 --- /dev/null +++ b/source/common/type/typeBigint.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/common/type/typeBinary.c b/source/common/type/typeBinary.c new file mode 100644 index 0000000000..6dea4a4e57 --- /dev/null +++ b/source/common/type/typeBinary.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/common/type/typeBlob.c b/source/common/type/typeBlob.c new file mode 100644 index 0000000000..6dea4a4e57 --- /dev/null +++ b/source/common/type/typeBlob.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/common/type/typeBool.c b/source/common/type/typeBool.c new file mode 100644 index 0000000000..6dea4a4e57 --- /dev/null +++ b/source/common/type/typeBool.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/common/type/typeDecimal.c b/source/common/type/typeDecimal.c new file mode 100644 index 0000000000..6dea4a4e57 --- /dev/null +++ b/source/common/type/typeDecimal.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/common/type/typeDouble.c b/source/common/type/typeDouble.c new file mode 100644 index 0000000000..6dea4a4e57 --- /dev/null +++ b/source/common/type/typeDouble.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/common/type/typeFloat.c b/source/common/type/typeFloat.c new file mode 100644 index 0000000000..6dea4a4e57 --- /dev/null +++ b/source/common/type/typeFloat.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/common/type/typeInt.c b/source/common/type/typeInt.c new file mode 100644 index 0000000000..6dea4a4e57 --- /dev/null +++ b/source/common/type/typeInt.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/common/type/typeJson.c b/source/common/type/typeJson.c new file mode 100644 index 0000000000..6dea4a4e57 --- /dev/null +++ b/source/common/type/typeJson.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/common/type/typeLongblob.c b/source/common/type/typeLongblob.c new file mode 100644 index 0000000000..6dea4a4e57 --- /dev/null +++ b/source/common/type/typeLongblob.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/common/type/typeNchar.c b/source/common/type/typeNchar.c new file mode 100644 index 0000000000..6dea4a4e57 --- /dev/null +++ b/source/common/type/typeNchar.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/common/type/typeNull.c b/source/common/type/typeNull.c new file mode 100644 index 0000000000..6dea4a4e57 --- /dev/null +++ b/source/common/type/typeNull.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/common/type/typeSmallint.c b/source/common/type/typeSmallint.c new file mode 100644 index 0000000000..6dea4a4e57 --- /dev/null +++ b/source/common/type/typeSmallint.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/common/type/typeTimestamp.c b/source/common/type/typeTimestamp.c new file mode 100644 index 0000000000..6dea4a4e57 --- /dev/null +++ b/source/common/type/typeTimestamp.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/common/type/typeTinyint.c b/source/common/type/typeTinyint.c new file mode 100644 index 0000000000..6dea4a4e57 --- /dev/null +++ b/source/common/type/typeTinyint.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/common/type/typeUBigint.c b/source/common/type/typeUBigint.c new file mode 100644 index 0000000000..6dea4a4e57 --- /dev/null +++ b/source/common/type/typeUBigint.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/common/type/typeUSmallint.c b/source/common/type/typeUSmallint.c new file mode 100644 index 0000000000..6dea4a4e57 --- /dev/null +++ b/source/common/type/typeUSmallint.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/common/type/typeUTinyint.c b/source/common/type/typeUTinyint.c new file mode 100644 index 0000000000..6dea4a4e57 --- /dev/null +++ b/source/common/type/typeUTinyint.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/common/type/typeUint.c b/source/common/type/typeUint.c new file mode 100644 index 0000000000..6dea4a4e57 --- /dev/null +++ b/source/common/type/typeUint.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/common/type/typeVarchar.c b/source/common/type/typeVarchar.c new file mode 100644 index 0000000000..6dea4a4e57 --- /dev/null +++ b/source/common/type/typeVarchar.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/dnode/vnode/impl/src/vnodeMain.c b/source/dnode/vnode/impl/src/vnodeMain.c index 74a7ea61b0..fb0106ab0a 100644 --- a/source/dnode/vnode/impl/src/vnodeMain.c +++ b/source/dnode/vnode/impl/src/vnodeMain.c @@ -110,15 +110,15 @@ static int vnodeOpenImpl(SVnode *pVnode) { // TODO: Open TQ sprintf(dir, "%s/wal", pVnode->path); - // pVnode->pTq = tqOpen(dir, NULL /* TODO */); - // if (pVnode->pTq == NULL) { - // // TODO: handle error - // return -1; - // } + pVnode->pTq = tqOpen(dir, &(pVnode->config.tqCfg), NULL, NULL); + if (pVnode->pTq == NULL) { + // TODO: handle error + return -1; + } // Open WAL sprintf(dir, "%s/wal", pVnode->path); - pVnode->pWal = walOpen(dir, NULL /* TODO */); + pVnode->pWal = walOpen(dir, &(pVnode->config.walCfg)); if (pVnode->pWal == NULL) { // TODO: handle error return -1; From 2ae35c3404c725a9c872cae4140ce7ac8dea0d05 Mon Sep 17 00:00:00 2001 From: Hongze Cheng Date: Fri, 26 Nov 2021 13:43:38 +0800 Subject: [PATCH 12/41] more --- include/dnode/vnode/meta/meta.h | 4 +- include/dnode/vnode/tsdb/tsdb.h | 5 +- include/dnode/vnode/vnode.h | 65 +++++++++---------- source/dnode/vnode/impl/inc/vnodeDef.h | 2 +- .../impl/inc/{vnodeFileSystem.h => vnodeFS.h} | 23 ++++++- .../impl/src/{vnodeFileSystem.c => vnodeFS.c} | 0 source/dnode/vnode/impl/src/vnodeWrite.c | 6 +- source/dnode/vnode/meta/src/metaTable.c | 12 ++-- source/dnode/vnode/tq/src/tq.c | 4 +- 9 files changed, 70 insertions(+), 51 deletions(-) rename source/dnode/vnode/impl/inc/{vnodeFileSystem.h => vnodeFS.h} (69%) rename source/dnode/vnode/impl/src/{vnodeFileSystem.c => vnodeFS.c} (100%) diff --git a/include/dnode/vnode/meta/meta.h b/include/dnode/vnode/meta/meta.h index 09539cb287..c91db3d831 100644 --- a/include/dnode/vnode/meta/meta.h +++ b/include/dnode/vnode/meta/meta.h @@ -68,8 +68,8 @@ typedef struct STbCfg { SMeta *metaOpen(const char *path, const SMetaCfg *pOptions); void metaClose(SMeta *pMeta); void metaRemove(const char *path); -int metaCreateTable(SMeta *pMeta, const STbCfg *pTbOptions); -int metaDropTable(SMeta *pMeta, tb_uid_t uid); +int metaCreateTable(SMeta *pMeta, const void *pReq, const int len); +int metaDropTable(SMeta *pMeta, const void *pReq, const int len); int metaCommit(SMeta *pMeta); // Options diff --git a/include/dnode/vnode/tsdb/tsdb.h b/include/dnode/vnode/tsdb/tsdb.h index d74a828538..26efce5d43 100644 --- a/include/dnode/vnode/tsdb/tsdb.h +++ b/include/dnode/vnode/tsdb/tsdb.h @@ -29,7 +29,7 @@ typedef struct STsdbMemAllocator STsdbMemAllocator; STsdb *tsdbOpen(const char *path, const STsdbCfg *); void tsdbClose(STsdb *); void tsdbRemove(const char *path); -int tsdbInsertData(STsdb *pTsdb, void *); +int tsdbInsertData(STsdb *pTsdb, void *pData, int len); // STsdbCfg int tsdbOptionsInit(STsdbCfg *); @@ -38,6 +38,9 @@ void tsdbOptionsClear(STsdbCfg *); /* ------------------------ STRUCT DEFINITIONS ------------------------ */ struct STsdbCfg { uint64_t lruCacheSize; + uint32_t keep0; + uint32_t keep1; + uint32_t keep2; /* TODO */ }; diff --git a/include/dnode/vnode/vnode.h b/include/dnode/vnode/vnode.h index cc74f8e433..79ac57ddcb 100644 --- a/include/dnode/vnode/vnode.h +++ b/include/dnode/vnode/vnode.h @@ -30,8 +30,37 @@ extern "C" { #endif /* ------------------------ TYPES EXPOSED ------------------------ */ -typedef struct SVnode SVnode; -typedef struct SVnodeCfg SVnodeCfg; +typedef struct SVnode SVnode; +typedef struct SVnodeCfg { + /** vnode buffer pool options */ + struct { + /** write buffer size */ + uint64_t wsize; + /** use heap allocator or arena allocator */ + bool isHeapAllocator; + }; + + /** time to live of tables in this vnode */ + uint32_t ttl; + + /** data to keep in this vnode */ + uint32_t keep; + + /** if TS data is eventually consistency */ + bool isWeak; + + /** TSDB config */ + STsdbCfg tsdbCfg; + + /** META config */ + SMetaCfg metaCfg; + + /** TQ config */ + STqCfg tqCfg; + + /** WAL config */ + SWalCfg walCfg; +} SVnodeCfg; /* ------------------------ SVnode ------------------------ */ /** @@ -101,38 +130,6 @@ void vnodeOptionsInit(SVnodeCfg *pOptions); */ void vnodeOptionsClear(SVnodeCfg *pOptions); -/* ------------------------ STRUCT DEFINITIONS ------------------------ */ -struct SVnodeCfg { - /** vnode buffer pool options */ - struct { - /** write buffer size */ - uint64_t wsize; - /** use heap allocator or arena allocator */ - bool isHeapAllocator; - }; - - /** time to live of tables in this vnode * - uint32_t ttl; - - /** data to keep in this vnode */ - uint32_t keep; - - /** if TS data is eventually consistency */ - bool isWeak; - - /** TSDB config */ - STsdbCfg tsdbCfg; - - /** META config */ - SMetaCfg metaCfg; - - /** TQ config */ - STqCfg tqCfg; - - /** WAL config */ - SWalCfg walCfg; -}; - /* ------------------------ FOR COMPILE ------------------------ */ #if 1 diff --git a/source/dnode/vnode/impl/inc/vnodeDef.h b/source/dnode/vnode/impl/inc/vnodeDef.h index 791db342a3..41943ce4f1 100644 --- a/source/dnode/vnode/impl/inc/vnodeDef.h +++ b/source/dnode/vnode/impl/inc/vnodeDef.h @@ -24,7 +24,7 @@ #include "vnode.h" #include "vnodeBufferPool.h" #include "vnodeCommit.h" -#include "vnodeFileSystem.h" +#include "vnodeFS.h" #include "vnodeCfg.h" #include "vnodeStateMgr.h" #include "vnodeSync.h" diff --git a/source/dnode/vnode/impl/inc/vnodeFileSystem.h b/source/dnode/vnode/impl/inc/vnodeFS.h similarity index 69% rename from source/dnode/vnode/impl/inc/vnodeFileSystem.h rename to source/dnode/vnode/impl/inc/vnodeFS.h index 2a885c9c34..dbec985695 100644 --- a/source/dnode/vnode/impl/inc/vnodeFileSystem.h +++ b/source/dnode/vnode/impl/inc/vnodeFS.h @@ -13,18 +13,35 @@ * along with this program. If not, see . */ -#ifndef _TD_VNODE_FILE_SYSTEM_H_ -#define _TD_VNODE_FILE_SYSTEM_H_ +#ifndef _TD_VNODE_FS_H_ +#define _TD_VNODE_FS_H_ + +#include "vnode.h" #ifdef __cplusplus extern "C" { #endif +typedef struct { +} SDir; + +typedef struct { +} SFile; + +typedef struct SFS { + void *pImpl; + int (*startEdit)(struct SFS *); + int (*endEdit)(struct SFS *); +} SFS; + typedef struct { } SVnodeFS; +int vnodeOpenFS(SVnode *pVnode); +void vnodeCloseFS(SVnode *pVnode); + #ifdef __cplusplus } #endif -#endif /*_TD_VNODE_FILE_SYSTEM_H_*/ \ No newline at end of file +#endif /*_TD_VNODE_FS_H_*/ \ No newline at end of file diff --git a/source/dnode/vnode/impl/src/vnodeFileSystem.c b/source/dnode/vnode/impl/src/vnodeFS.c similarity index 100% rename from source/dnode/vnode/impl/src/vnodeFileSystem.c rename to source/dnode/vnode/impl/src/vnodeFS.c diff --git a/source/dnode/vnode/impl/src/vnodeWrite.c b/source/dnode/vnode/impl/src/vnodeWrite.c index 69a7cf3478..61bc54eab3 100644 --- a/source/dnode/vnode/impl/src/vnodeWrite.c +++ b/source/dnode/vnode/impl/src/vnodeWrite.c @@ -34,19 +34,19 @@ int vnodeApplyWMsg(SVnode *pVnode, SRpcMsg *pMsg, SRpcMsg **pRsp) { switch (pMsg->msgType) { case TSDB_MSG_TYPE_CREATE_TABLE: - if (metaCreateTable(pVnode->pMeta, pMsg->pCont) < 0) { + if (metaCreateTable(pVnode->pMeta, pMsg->pCont, pMsg->contLen) < 0) { /* TODO */ return -1; } break; case TSDB_MSG_TYPE_DROP_TABLE: - if (metaDropTable(pVnode->pMeta, pMsg->pCont) < 0) { + if (metaDropTable(pVnode->pMeta, pMsg->pCont, pMsg->contLen) < 0) { /* TODO */ return -1; } break; case TSDB_MSG_TYPE_SUBMIT: - if (tsdbInsertData(pVnode->pTsdb, pMsg->pCont) < 0) { + if (tsdbInsertData(pVnode->pTsdb, pMsg->pCont, pMsg->contLen) < 0) { /* TODO */ return -1; } diff --git a/source/dnode/vnode/meta/src/metaTable.c b/source/dnode/vnode/meta/src/metaTable.c index 6a92fedc3d..f34732a9fe 100644 --- a/source/dnode/vnode/meta/src/metaTable.c +++ b/source/dnode/vnode/meta/src/metaTable.c @@ -15,21 +15,22 @@ #include "metaDef.h" -int metaCreateTable(SMeta *pMeta, const STbCfg *pTbOptions) { +int metaCreateTable(SMeta *pMeta, const void *pCont, const int len) { + STbCfg *pTbCfg = NULL; // Validate the tbOptions - if (metaValidateTbOptions(pMeta, pTbOptions) < 0) { + if (metaValidateTbOptions(pMeta, pTbCfg) < 0) { // TODO: handle error return -1; } // TODO: add atomicity - if (metaSaveTableToDB(pMeta, pTbOptions) < 0) { + if (metaSaveTableToDB(pMeta, pTbCfg) < 0) { // TODO: handle error return -1; } - if (metaSaveTableToIdx(pMeta, pTbOptions) < 0) { + if (metaSaveTableToIdx(pMeta, pTbCfg) < 0) { // TODO: handle error return -1; } @@ -37,7 +38,8 @@ int metaCreateTable(SMeta *pMeta, const STbCfg *pTbOptions) { return 0; } -int metaDropTable(SMeta *pMeta, tb_uid_t uid) { +int metaDropTable(SMeta *pMeta, const void *pCont, const int len) { + tb_uid_t uid; if (metaRemoveTableFromIdx(pMeta, uid) < 0) { // TODO: handle error return -1; diff --git a/source/dnode/vnode/tq/src/tq.c b/source/dnode/vnode/tq/src/tq.c index c5f2252c72..130ff70408 100644 --- a/source/dnode/vnode/tq/src/tq.c +++ b/source/dnode/vnode/tq/src/tq.c @@ -49,8 +49,8 @@ STQ* tqOpen(const char* path, STqCfg* tqConfig, TqLogReader* tqLogReader, SMemAl strcpy(pTq->path, path); pTq->tqConfig = tqConfig; pTq->tqLogReader = tqLogReader; - pTq->tqMemRef.pAlloctorFactory = allocFac; - pTq->tqMemRef.pAllocator = allocFac->create(allocFac); + // pTq->tqMemRef.pAlloctorFactory = allocFac; + // pTq->tqMemRef.pAllocator = allocFac->create(allocFac); if(pTq->tqMemRef.pAllocator == NULL) { //TODO } From 6d69cedd2822cd779492da9895ad07ebd8c4c5f0 Mon Sep 17 00:00:00 2001 From: Hongze Cheng Date: Fri, 26 Nov 2021 14:49:26 +0800 Subject: [PATCH 13/41] more --- include/dnode/vnode/meta/meta.h | 39 ++++++++++++++----- include/dnode/vnode/vnode.h | 10 +++++ source/dnode/vnode/impl/src/vnodeWrite.c | 2 +- .../dnode/vnode/impl/test/vnodeApiTests.cpp | 11 ++++++ source/dnode/vnode/meta/src/metaTbCfg.c | 9 +++++ 5 files changed, 61 insertions(+), 10 deletions(-) diff --git a/include/dnode/vnode/meta/meta.h b/include/dnode/vnode/meta/meta.h index c91db3d831..3a8ff3a717 100644 --- a/include/dnode/vnode/meta/meta.h +++ b/include/dnode/vnode/meta/meta.h @@ -27,6 +27,10 @@ extern "C" { typedef uint64_t tb_uid_t; typedef struct SMeta SMeta; +#define META_SUPER_TABLE 0 +#define META_CHILD_TABLE 1 +#define META_NORMAL_TABLE 2 + typedef struct SMetaCfg { /// LRU cache size uint64_t lruSize; @@ -37,6 +41,8 @@ typedef struct STbCfg { char *name; /// time to live of the table uint32_t ttl; + /// keep time of this table + uint32_t keep; /// type of table uint8_t type; union { @@ -76,15 +82,30 @@ int metaCommit(SMeta *pMeta); void metaOptionsInit(SMetaCfg *pOptions); void metaOptionsClear(SMetaCfg *pOptions); -// STableOpts -// #define META_TABLE_OPTS_DECLARE(name) STableOpts name = {0} -// void metaNormalTableOptsInit(STbCfg *pTbOptions, const char *name, const STSchema *pSchema); -// void metaSuperTableOptsInit(STbCfg *pTbOptions, const char *name, tb_uid_t uid, const STSchema *pSchema, -// const STSchema *pTagSchema); -// void metaChildTableOptsInit(STbCfg *pTbOptions, const char *name, tb_uid_t suid, const SKVRow tags); -// void metaTableOptsClear(STbCfg *pTbOptions); -// uint64_t metaEncodeTbOptions(void **pBuf, STbCfg *pTbOptions); -// STbCfg * metaDecodeTbOptions(void *pBuf, size_t size, bool endian); +// STbCfg +#define META_INIT_STB_CFG(NAME, TTL, KEEP, SUID, PSCHEMA, PTAGSCHEMA) \ + { \ + .name = (NAME), .ttl = (TTL), .keep = (KEEP), .type = META_SUPER_TABLE, .stbCfg = { \ + .suid = (SUID), \ + .pSchema = (PSCHEMA), \ + .pTagSchema = (PTAGSCHEMA) \ + } \ + } + +#define META_INIT_CTB_CFG(NAME, TTL, KEEP, SUID, PTAG) \ + { \ + .name = (NAME), .ttl = (TTL), .keep = (KEEP), .type = META_CHILD_TABLE, .ctbCfg = {.suid = (SUID), .pTag = PTAG } \ + } + +#define META_INIT_NTB_CFG(NAME, TTL, KEEP, SUID, PSCHEMA) \ + { \ + .name = (NAME), .ttl = (TTL), .keep = (KEEP), .type = META_NORMAL_TABLE, .ntbCfg = {.pSchema = (PSCHEMA) } \ + } + +#define META_CLEAR_TB_CFG(pTbCfg) + +int metaEncodeTbCfg(void **pBuf, STbCfg *pTbCfg); +void *metaDecodeTbCfg(void *pBuf, STbCfg **pTbCfg); #ifdef __cplusplus } diff --git a/include/dnode/vnode/vnode.h b/include/dnode/vnode/vnode.h index 79ac57ddcb..a926ab294b 100644 --- a/include/dnode/vnode/vnode.h +++ b/include/dnode/vnode/vnode.h @@ -130,6 +130,16 @@ void vnodeOptionsInit(SVnodeCfg *pOptions); */ void vnodeOptionsClear(SVnodeCfg *pOptions); +/* ------------------------ REQUESTS ------------------------ */ + +// Create table request + +typedef STbCfg SVCreateTableReq; +typedef struct { + int err; + char info[]; +} SVCreateTableRsp; + /* ------------------------ FOR COMPILE ------------------------ */ #if 1 diff --git a/source/dnode/vnode/impl/src/vnodeWrite.c b/source/dnode/vnode/impl/src/vnodeWrite.c index 61bc54eab3..96eb653d1c 100644 --- a/source/dnode/vnode/impl/src/vnodeWrite.c +++ b/source/dnode/vnode/impl/src/vnodeWrite.c @@ -22,7 +22,7 @@ int vnodeProcessWMsgs(SVnode *pVnode, SArray *pMsgs) { for (size_t i = 0; i < taosArrayGetSize(pMsgs); i++) { pReq = taosArrayGet(pMsgs, i); - vnodeApplyWMsg(pVnode, pReq, pRsp); + vnodeApplyWMsg(pVnode, pReq, &pRsp); } return 0; diff --git a/source/dnode/vnode/impl/test/vnodeApiTests.cpp b/source/dnode/vnode/impl/test/vnodeApiTests.cpp index 65aa0f506c..0aa6a9edb6 100644 --- a/source/dnode/vnode/impl/test/vnodeApiTests.cpp +++ b/source/dnode/vnode/impl/test/vnodeApiTests.cpp @@ -11,3 +11,14 @@ TEST(vnodeApiTest, vnodeOpen_vnodeClose_test) { // Close the vnode vnodeClose(pVnode); } + +TEST(vnodeApiTest, vnode_process_create_table) { + STSchema * pSchema = NULL; + STSchema * pTagSchema = NULL; + char stname[15]; + SVCreateTableReq pReq = META_INIT_STB_CFG(stname, UINT32_MAX, UINT32_MAX, 0, pSchema, pTagSchema); + + int k = 10; + + META_CLEAR_TB_CFG(pReq); +} diff --git a/source/dnode/vnode/meta/src/metaTbCfg.c b/source/dnode/vnode/meta/src/metaTbCfg.c index 8d58edaa08..8485d82a8d 100644 --- a/source/dnode/vnode/meta/src/metaTbCfg.c +++ b/source/dnode/vnode/meta/src/metaTbCfg.c @@ -46,4 +46,13 @@ size_t metaEncodeTbObjFromTbOptions(const STbCfg *pTbOptions, void *pBuf, size_t } return tlen; +} + +int metaEncodeTbCfg(void **pBuf, STbCfg *pTbCfg) { + // TODO + return 0; +} + +void *metaDecodeTbCfg(void *pBuf, STbCfg **pTbCfg) { + // TODO } \ No newline at end of file From ab9ef13488953f7fc183a1da95ac73b4bfcdc349 Mon Sep 17 00:00:00 2001 From: Hongze Cheng Date: Fri, 26 Nov 2021 15:22:02 +0800 Subject: [PATCH 14/41] refact --- include/dnode/vnode/vnode.h | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/include/dnode/vnode/vnode.h b/include/dnode/vnode/vnode.h index a926ab294b..596454f7d3 100644 --- a/include/dnode/vnode/vnode.h +++ b/include/dnode/vnode/vnode.h @@ -131,14 +131,25 @@ void vnodeOptionsInit(SVnodeCfg *pOptions); void vnodeOptionsClear(SVnodeCfg *pOptions); /* ------------------------ REQUESTS ------------------------ */ - -// Create table request - -typedef STbCfg SVCreateTableReq; typedef struct { int err; char info[]; -} SVCreateTableRsp; +} SVnodeRsp; + +/// Create table request +typedef STbCfg SVCreateTableReq; +/// Drop table request +typedef struct { + tb_uid_t uid; +} SVDropTableReq; +/// Alter table request +typedef struct { + // TODO +} SVAlterTableReq; + +int vnodeCreateTable(SVnode *pVnode, SVCreateTableReq *pReq, SVnodeRsp *pRsp); +int vnodeDropTable(SVnode *pVnode, SVDropTableReq *pReq, SVnodeRsp *pRsp); +int vnodeAlterTable(SVnode *pVnode, SVAlterTableReq *pReq, SVnodeRsp *pRsp); /* ------------------------ FOR COMPILE ------------------------ */ From e3478a52a58af599988f4cb527198c24369fb6c9 Mon Sep 17 00:00:00 2001 From: Hongze Cheng Date: Mon, 29 Nov 2021 11:37:26 +0800 Subject: [PATCH 15/41] more --- include/dnode/vnode/meta/meta.h | 2 +- include/dnode/vnode/vnode.h | 5 + source/dnode/vnode/impl/inc/vnodeBufferPool.h | 5 +- source/dnode/vnode/impl/inc/vnodeRequest.h | 17 +--- source/dnode/vnode/impl/src/vnodeBufferPool.c | 29 ++++-- source/dnode/vnode/impl/src/vnodeWrite.c | 96 +++++++++++++------ source/dnode/vnode/meta/src/metaTable.c | 3 +- 7 files changed, 103 insertions(+), 54 deletions(-) diff --git a/include/dnode/vnode/meta/meta.h b/include/dnode/vnode/meta/meta.h index 3a8ff3a717..df67b37686 100644 --- a/include/dnode/vnode/meta/meta.h +++ b/include/dnode/vnode/meta/meta.h @@ -74,7 +74,7 @@ typedef struct STbCfg { SMeta *metaOpen(const char *path, const SMetaCfg *pOptions); void metaClose(SMeta *pMeta); void metaRemove(const char *path); -int metaCreateTable(SMeta *pMeta, const void *pReq, const int len); +int metaCreateTable(SMeta *pMeta, STbCfg *pTbCfg); int metaDropTable(SMeta *pMeta, const void *pReq, const int len); int metaCommit(SMeta *pMeta); diff --git a/include/dnode/vnode/vnode.h b/include/dnode/vnode/vnode.h index 6092877d0b..84e57c4180 100644 --- a/include/dnode/vnode/vnode.h +++ b/include/dnode/vnode/vnode.h @@ -131,6 +131,11 @@ void vnodeOptionsInit(SVnodeCfg *pOptions); void vnodeOptionsClear(SVnodeCfg *pOptions); /* ------------------------ REQUESTS ------------------------ */ +typedef struct { + uint64_t ver; + char req[]; +} SVnodeReq; + typedef struct { int err; char info[]; diff --git a/source/dnode/vnode/impl/inc/vnodeBufferPool.h b/source/dnode/vnode/impl/inc/vnodeBufferPool.h index 3033862779..d64dc93847 100644 --- a/source/dnode/vnode/impl/inc/vnodeBufferPool.h +++ b/source/dnode/vnode/impl/inc/vnodeBufferPool.h @@ -25,8 +25,9 @@ extern "C" { typedef struct SVBufPool SVBufPool; -int vnodeOpenBufPool(SVnode *pVnode); -void vnodeCloseBufPool(SVnode *pVnode); +int vnodeOpenBufPool(SVnode *pVnode); +void vnodeCloseBufPool(SVnode *pVnode); +void *vnodeMalloc(SVnode *pVnode, uint64_t size); #ifdef __cplusplus } diff --git a/source/dnode/vnode/impl/inc/vnodeRequest.h b/source/dnode/vnode/impl/inc/vnodeRequest.h index f2b4ecee91..e7fdff092e 100644 --- a/source/dnode/vnode/impl/inc/vnodeRequest.h +++ b/source/dnode/vnode/impl/inc/vnodeRequest.h @@ -16,23 +16,14 @@ #ifndef _TD_VNODE_REQUEST_H_ #define _TD_VNODE_REQUEST_H_ +#include "vnode.h" + #ifdef __cplusplus extern "C" { #endif -typedef struct SVnodeReq SVnodeReq; -typedef struct SVnodeRsp SVnodeRsp; - -typedef enum {} EVReqT; -typedef enum {} EVRspT; - -struct SVnodeReq { - EVReqT type; -}; - -struct SVnodeRsp { - EVRspT type; -}; +int vnodeBuildCreateTableReq(const SVCreateTableReq *pReq, char *msg, int len); +int vnodeParseCreateTableReq(const char *msg, int len, SVCreateTableReq *pReq); #ifdef __cplusplus } diff --git a/source/dnode/vnode/impl/src/vnodeBufferPool.c b/source/dnode/vnode/impl/src/vnodeBufferPool.c index 3d8ebfdc47..00203ed9b6 100644 --- a/source/dnode/vnode/impl/src/vnodeBufferPool.c +++ b/source/dnode/vnode/impl/src/vnodeBufferPool.c @@ -71,6 +71,7 @@ static SListNode * vBufPoolNewNode(uint64_t capacity, EVMemAllocatorT type); static void vBufPoolFreeNode(SListNode *pNode); static SMemAllocator *vBufPoolCreateMA(SMemAllocatorFactory *pmaf); static void vBufPoolDestroyMA(SMemAllocatorFactory *pmaf, SMemAllocator *pma); +static void * vBufPoolMalloc(SVMemAllocator *pvma, uint64_t size); int vnodeOpenBufPool(SVnode *pVnode) { uint64_t capacity; @@ -129,6 +130,24 @@ void vnodeCloseBufPool(SVnode *pVnode) { } } +void *vnodeMalloc(SVnode *pVnode, uint64_t size) { + void *ptr; + + if (pVnode->pBufPool->inuse == NULL) { + SListNode *pNode; + while ((pNode = tdListPopHead(&(pVnode->pBufPool->free))) == NULL) { + // todo + // tsem_wait(); + ASSERT(0); + } + + pVnode->pBufPool->inuse = pNode; + } + + SVMemAllocator *pvma = (SVMemAllocator *)(pVnode->pBufPool->inuse->data); + return vBufPoolMalloc(pvma, size); +} + /* ------------------------ STATIC METHODS ------------------------ */ static void vArenaAllocatorInit(SVArenaAllocator *pvaa, uint64_t capacity, uint64_t ssize, uint64_t lsize) { /* TODO */ pvaa->ssize = ssize; @@ -201,10 +220,8 @@ static void vBufPoolFreeNode(SListNode *pNode) { free(pNode); } -static void *vBufPoolMalloc(SMemAllocator *pma, uint64_t size) { - SVMAWrapper * pvmaw = (SVMAWrapper *)(pma->impl); - SVMemAllocator *pvma = (SVMemAllocator *)(pvmaw->pNode->data); - void * ptr = NULL; +static void *vBufPoolMalloc(SVMemAllocator *pvma, uint64_t size) { + void *ptr = NULL; if (pvma->type == E_V_ARENA_ALLOCATOR) { SVArenaAllocator *pvaa = &(pvma->vaa); @@ -229,7 +246,7 @@ static void *vBufPoolMalloc(SMemAllocator *pma, uint64_t size) { /* TODO */ } - return NULL; + return ptr; } static SMemAllocator *vBufPoolCreateMA(SMemAllocatorFactory *pmaf) { @@ -267,7 +284,7 @@ static SMemAllocator *vBufPoolCreateMA(SMemAllocatorFactory *pmaf) { pvmaw->pNode = pVnode->pBufPool->inuse; pma->impl = pvmaw; - pma->malloc = vBufPoolMalloc; + pma->malloc = NULL; pma->calloc = NULL; /* TODO */ pma->realloc = NULL; /* TODO */ pma->free = NULL; /* TODO */ diff --git a/source/dnode/vnode/impl/src/vnodeWrite.c b/source/dnode/vnode/impl/src/vnodeWrite.c index 96eb653d1c..2daee82b69 100644 --- a/source/dnode/vnode/impl/src/vnodeWrite.c +++ b/source/dnode/vnode/impl/src/vnodeWrite.c @@ -16,13 +16,74 @@ #include "vnodeDef.h" int vnodeProcessWMsgs(SVnode *pVnode, SArray *pMsgs) { - SRpcMsg *pReq; - SRpcMsg *pRsp; + SRpcMsg * pMsg; + SVnodeReq *pVnodeReq; - for (size_t i = 0; i < taosArrayGetSize(pMsgs); i++) { - pReq = taosArrayGet(pMsgs, i); + for (int i = 0; i < taosArrayGetSize(pMsgs); i++) { + pMsg = *(SRpcMsg **)taosArrayGet(pMsgs, i); - vnodeApplyWMsg(pVnode, pReq, &pRsp); + // 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 + } + } + + walFsync(pVnode->pWal, false); + + // Apply each request now + for (int i = 0; i < taosArrayGetSize(pMsgs); i++) { + pMsg = *(SRpcMsg **)taosArrayGet(pMsgs, i); + pVnodeReq = (SVnodeReq *)(pMsg->pCont); + SVCreateTableReq ctReq; + + // Apply the request + { + void *ptr = vnodeMalloc(pVnode, pMsg->contLen); + if (ptr == NULL) { + // TODO: handle error + } + + memcpy(ptr, pVnodeReq, pMsg->contLen); + + // todo: change the interface here + if (tqPushMsg(pVnode->pTq, pVnodeReq->req, pVnodeReq->ver) < 0) { + // TODO: handle error + } + + switch (pMsg->msgType) { + case TSDB_MSG_TYPE_CREATE_TABLE: + if (vnodeParseCreateTableReq(pVnodeReq->req, pMsg->contLen - sizeof(pVnodeReq->ver), &(ctReq)) < 0) { + // TODO: handle error + } + + if (metaCreateTable(pVnode->pMeta, &ctReq) < 0) { + // TODO: handle error + } + + // TODO: maybe need to clear the requst struct + break; + case TSDB_MSG_TYPE_DROP_TABLE: + /* code */ + break; + case TSDB_MSG_TYPE_SUBMIT: + /* code */ + break; + default: + break; + } + } + + pVnode->state.applied = pVnodeReq->ver; + + // Check if it needs to commit + if (vnodeShouldCommit(pVnode)) { + if (vnodeAsyncCommit(pVnode) < 0) { + // TODO: handle error + } + } } return 0; @@ -30,31 +91,6 @@ int vnodeProcessWMsgs(SVnode *pVnode, SArray *pMsgs) { int vnodeApplyWMsg(SVnode *pVnode, SRpcMsg *pMsg, SRpcMsg **pRsp) { // TODO - int code = 0; - - switch (pMsg->msgType) { - case TSDB_MSG_TYPE_CREATE_TABLE: - if (metaCreateTable(pVnode->pMeta, pMsg->pCont, pMsg->contLen) < 0) { - /* TODO */ - return -1; - } - break; - case TSDB_MSG_TYPE_DROP_TABLE: - if (metaDropTable(pVnode->pMeta, pMsg->pCont, pMsg->contLen) < 0) { - /* TODO */ - return -1; - } - break; - case TSDB_MSG_TYPE_SUBMIT: - if (tsdbInsertData(pVnode->pTsdb, pMsg->pCont, pMsg->contLen) < 0) { - /* TODO */ - return -1; - } - break; - default: - break; - } - return 0; } diff --git a/source/dnode/vnode/meta/src/metaTable.c b/source/dnode/vnode/meta/src/metaTable.c index f34732a9fe..bed2140f51 100644 --- a/source/dnode/vnode/meta/src/metaTable.c +++ b/source/dnode/vnode/meta/src/metaTable.c @@ -15,8 +15,7 @@ #include "metaDef.h" -int metaCreateTable(SMeta *pMeta, const void *pCont, const int len) { - STbCfg *pTbCfg = NULL; +int metaCreateTable(SMeta *pMeta, STbCfg *pTbCfg) { // Validate the tbOptions if (metaValidateTbOptions(pMeta, pTbCfg) < 0) { // TODO: handle error From 8eae8112c73202435e7c15de9f802b27d5f8b4d6 Mon Sep 17 00:00:00 2001 From: Hongze Cheng Date: Mon, 29 Nov 2021 11:53:31 +0800 Subject: [PATCH 16/41] more --- include/dnode/vnode/meta/meta.h | 2 +- source/dnode/vnode/impl/inc/vnodeDef.h | 3 ++- source/dnode/vnode/impl/inc/vnodeRequest.h | 4 ++++ source/dnode/vnode/impl/src/vnodeWrite.c | 11 +++++++++-- source/dnode/vnode/meta/src/metaTable.c | 3 +-- 5 files changed, 17 insertions(+), 6 deletions(-) diff --git a/include/dnode/vnode/meta/meta.h b/include/dnode/vnode/meta/meta.h index df67b37686..6060db02c4 100644 --- a/include/dnode/vnode/meta/meta.h +++ b/include/dnode/vnode/meta/meta.h @@ -75,7 +75,7 @@ SMeta *metaOpen(const char *path, const SMetaCfg *pOptions); void metaClose(SMeta *pMeta); void metaRemove(const char *path); int metaCreateTable(SMeta *pMeta, STbCfg *pTbCfg); -int metaDropTable(SMeta *pMeta, const void *pReq, const int len); +int metaDropTable(SMeta *pMeta, tb_uid_t uid); int metaCommit(SMeta *pMeta); // Options diff --git a/source/dnode/vnode/impl/inc/vnodeDef.h b/source/dnode/vnode/impl/inc/vnodeDef.h index 41943ce4f1..ee414eb5e2 100644 --- a/source/dnode/vnode/impl/inc/vnodeDef.h +++ b/source/dnode/vnode/impl/inc/vnodeDef.h @@ -23,9 +23,10 @@ #include "vnode.h" #include "vnodeBufferPool.h" +#include "vnodeCfg.h" #include "vnodeCommit.h" #include "vnodeFS.h" -#include "vnodeCfg.h" +#include "vnodeRequest.h" #include "vnodeStateMgr.h" #include "vnodeSync.h" diff --git a/source/dnode/vnode/impl/inc/vnodeRequest.h b/source/dnode/vnode/impl/inc/vnodeRequest.h index e7fdff092e..e31ce8a5ee 100644 --- a/source/dnode/vnode/impl/inc/vnodeRequest.h +++ b/source/dnode/vnode/impl/inc/vnodeRequest.h @@ -22,8 +22,12 @@ extern "C" { #endif +// SVCreateTableReq int vnodeBuildCreateTableReq(const SVCreateTableReq *pReq, char *msg, int len); int vnodeParseCreateTableReq(const char *msg, int len, SVCreateTableReq *pReq); +// SVDropTableReq +int vnodeBuildDropTableReq(const SVDropTableReq *pReq, char *msg, int len); +int vnodeParseDropTableReq(const char *msg, int len, SVDropTableReq *pReq); #ifdef __cplusplus } diff --git a/source/dnode/vnode/impl/src/vnodeWrite.c b/source/dnode/vnode/impl/src/vnodeWrite.c index 2daee82b69..0d4250c60e 100644 --- a/source/dnode/vnode/impl/src/vnodeWrite.c +++ b/source/dnode/vnode/impl/src/vnodeWrite.c @@ -38,6 +38,7 @@ int vnodeProcessWMsgs(SVnode *pVnode, SArray *pMsgs) { pMsg = *(SRpcMsg **)taosArrayGet(pMsgs, i); pVnodeReq = (SVnodeReq *)(pMsg->pCont); SVCreateTableReq ctReq; + SVDropTableReq dtReq; // Apply the request { @@ -49,7 +50,7 @@ int vnodeProcessWMsgs(SVnode *pVnode, SArray *pMsgs) { memcpy(ptr, pVnodeReq, pMsg->contLen); // todo: change the interface here - if (tqPushMsg(pVnode->pTq, pVnodeReq->req, pVnodeReq->ver) < 0) { + if (tqPushMsg(pVnode->pTq, ptr, pVnodeReq->ver) < 0) { // TODO: handle error } @@ -66,7 +67,13 @@ int vnodeProcessWMsgs(SVnode *pVnode, SArray *pMsgs) { // TODO: maybe need to clear the requst struct break; case TSDB_MSG_TYPE_DROP_TABLE: - /* code */ + if (vnodeParseDropTableReq(pVnodeReq->req, pMsg->contLen - sizeof(pVnodeReq->ver), &(dtReq)) < 0) { + // TODO: handle error + } + + if (metaDropTable(pVnode->pMeta, dtReq.uid) < 0) { + // TODO: handle error + } break; case TSDB_MSG_TYPE_SUBMIT: /* code */ diff --git a/source/dnode/vnode/meta/src/metaTable.c b/source/dnode/vnode/meta/src/metaTable.c index bed2140f51..fc0f19302f 100644 --- a/source/dnode/vnode/meta/src/metaTable.c +++ b/source/dnode/vnode/meta/src/metaTable.c @@ -37,8 +37,7 @@ int metaCreateTable(SMeta *pMeta, STbCfg *pTbCfg) { return 0; } -int metaDropTable(SMeta *pMeta, const void *pCont, const int len) { - tb_uid_t uid; +int metaDropTable(SMeta *pMeta, tb_uid_t uid) { if (metaRemoveTableFromIdx(pMeta, uid) < 0) { // TODO: handle error return -1; From b97e8808089adec5a6ba7067da58c6489c85cb52 Mon Sep 17 00:00:00 2001 From: Hongze Cheng Date: Mon, 29 Nov 2021 13:44:52 +0800 Subject: [PATCH 17/41] more --- source/dnode/vnode/impl/src/vnodeMain.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/dnode/vnode/impl/src/vnodeMain.c b/source/dnode/vnode/impl/src/vnodeMain.c index fb0106ab0a..59e3bae5d7 100644 --- a/source/dnode/vnode/impl/src/vnodeMain.c +++ b/source/dnode/vnode/impl/src/vnodeMain.c @@ -109,7 +109,7 @@ static int vnodeOpenImpl(SVnode *pVnode) { } // TODO: Open TQ - sprintf(dir, "%s/wal", pVnode->path); + sprintf(dir, "%s/tq", pVnode->path); pVnode->pTq = tqOpen(dir, &(pVnode->config.tqCfg), NULL, NULL); if (pVnode->pTq == NULL) { // TODO: handle error From 757dea61705ae957ebb99b0ad1933b690889d213 Mon Sep 17 00:00:00 2001 From: Hongze Cheng Date: Mon, 29 Nov 2021 14:06:16 +0800 Subject: [PATCH 18/41] more --- include/dnode/vnode/vnode.h | 13 +++++++++++++ source/dnode/vnode/impl/src/vnodeMain.c | 13 +++++++++++++ source/dnode/vnode/impl/test/vnodeApiTests.cpp | 8 ++++++++ 3 files changed, 34 insertions(+) diff --git a/include/dnode/vnode/vnode.h b/include/dnode/vnode/vnode.h index 84e57c4180..027bee709d 100644 --- a/include/dnode/vnode/vnode.h +++ b/include/dnode/vnode/vnode.h @@ -63,6 +63,19 @@ typedef struct SVnodeCfg { } SVnodeCfg; /* ------------------------ SVnode ------------------------ */ +/** + * @brief Initialize the vnode module + * + * @return int 0 for success and -1 for failure + */ +int vnodeInit(); + +/** + * @brief clear a vnode + * + */ +void vnodeClear(); + /** * @brief Open a VNODE. * diff --git a/source/dnode/vnode/impl/src/vnodeMain.c b/source/dnode/vnode/impl/src/vnodeMain.c index 59e3bae5d7..ab33b58858 100644 --- a/source/dnode/vnode/impl/src/vnodeMain.c +++ b/source/dnode/vnode/impl/src/vnodeMain.c @@ -20,6 +20,19 @@ static void vnodeFree(SVnode *pVnode); static int vnodeOpenImpl(SVnode *pVnode); static void vnodeCloseImpl(SVnode *pVnode); +int vnodeInit() { + // TODO + if (walInit() < 0) { + return -1; + } + + return 0; +} + +void vnodeClear() { + walCleanUp(); +} + SVnode *vnodeOpen(const char *path, const SVnodeCfg *pVnodeCfg) { SVnode *pVnode = NULL; diff --git a/source/dnode/vnode/impl/test/vnodeApiTests.cpp b/source/dnode/vnode/impl/test/vnodeApiTests.cpp index 0aa6a9edb6..3b0c059b98 100644 --- a/source/dnode/vnode/impl/test/vnodeApiTests.cpp +++ b/source/dnode/vnode/impl/test/vnodeApiTests.cpp @@ -4,12 +4,20 @@ #include "vnode.h" TEST(vnodeApiTest, vnodeOpen_vnodeClose_test) { + GTEST_ASSERT_GE(vnodeInit(), 0); + // Create and open a vnode SVnode *pVnode = vnodeOpen("vnode1", NULL); ASSERT_NE(pVnode, nullptr); + // Create table + // SArray *pArray = taosArrayInit() + // vnodeProcessWMsgs(pVnode, ); + // Close the vnode vnodeClose(pVnode); + + vnodeClear(); } TEST(vnodeApiTest, vnode_process_create_table) { From 018661e177987dc347fd87d0b996223a5ce9dbca Mon Sep 17 00:00:00 2001 From: Hongze Cheng Date: Mon, 29 Nov 2021 15:42:17 +0800 Subject: [PATCH 19/41] more --- include/dnode/vnode/vnode.h | 8 ++- source/dnode/vnode/impl/inc/vnodeDef.h | 1 + source/dnode/vnode/impl/inc/vnodeRequest.h | 7 +- source/dnode/vnode/impl/src/vnodeRequest.c | 67 ++++++++++++++++++- source/dnode/vnode/impl/src/vnodeWrite.c | 6 +- .../dnode/vnode/impl/test/vnodeApiTests.cpp | 63 ++++++++++++++++- source/dnode/vnode/meta/src/metaIdx.c | 5 ++ 7 files changed, 142 insertions(+), 15 deletions(-) diff --git a/include/dnode/vnode/vnode.h b/include/dnode/vnode/vnode.h index 027bee709d..58ad933461 100644 --- a/include/dnode/vnode/vnode.h +++ b/include/dnode/vnode/vnode.h @@ -65,14 +65,14 @@ typedef struct SVnodeCfg { /* ------------------------ SVnode ------------------------ */ /** * @brief Initialize the vnode module - * + * * @return int 0 for success and -1 for failure */ int vnodeInit(); /** * @brief clear a vnode - * + * */ void vnodeClear(); @@ -156,6 +156,10 @@ typedef struct { /// Create table request typedef STbCfg SVCreateTableReq; + +int vnodeBuildCreateTableReq(void **buf, const SVCreateTableReq *pReq); +void *vnodeParseCreateTableReq(void *buf, SVCreateTableReq *pReq); + /// Drop table request typedef struct { tb_uid_t uid; diff --git a/source/dnode/vnode/impl/inc/vnodeDef.h b/source/dnode/vnode/impl/inc/vnodeDef.h index ee414eb5e2..c92de433c3 100644 --- a/source/dnode/vnode/impl/inc/vnodeDef.h +++ b/source/dnode/vnode/impl/inc/vnodeDef.h @@ -20,6 +20,7 @@ #include "sync.h" #include "tlockfree.h" #include "wal.h" +#include "tcoding.h" #include "vnode.h" #include "vnodeBufferPool.h" diff --git a/source/dnode/vnode/impl/inc/vnodeRequest.h b/source/dnode/vnode/impl/inc/vnodeRequest.h index e31ce8a5ee..d70fc84cab 100644 --- a/source/dnode/vnode/impl/inc/vnodeRequest.h +++ b/source/dnode/vnode/impl/inc/vnodeRequest.h @@ -22,12 +22,9 @@ extern "C" { #endif -// SVCreateTableReq -int vnodeBuildCreateTableReq(const SVCreateTableReq *pReq, char *msg, int len); -int vnodeParseCreateTableReq(const char *msg, int len, SVCreateTableReq *pReq); // SVDropTableReq -int vnodeBuildDropTableReq(const SVDropTableReq *pReq, char *msg, int len); -int vnodeParseDropTableReq(const char *msg, int len, SVDropTableReq *pReq); +int vnodeBuildDropTableReq(void **buf, const SVDropTableReq *pReq); +void *vnodeParseDropTableReq(void *buf, SVDropTableReq *pReq); #ifdef __cplusplus } diff --git a/source/dnode/vnode/impl/src/vnodeRequest.c b/source/dnode/vnode/impl/src/vnodeRequest.c index 6dea4a4e57..d89f34e7e5 100644 --- a/source/dnode/vnode/impl/src/vnodeRequest.c +++ b/source/dnode/vnode/impl/src/vnodeRequest.c @@ -11,4 +11,69 @@ * * 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 + */ + +#include "vnodeDef.h" + +int vnodeBuildCreateTableReq(void **buf, const SVCreateTableReq *pReq) { + int tsize = 0; + + tsize += taosEncodeString(buf, pReq->name); + tsize += taosEncodeFixedU32(buf, pReq->ttl); + tsize += taosEncodeFixedU32(buf, pReq->keep); + tsize += taosEncodeFixedU8(buf, pReq->type); + + switch (pReq->type) { + case META_SUPER_TABLE: + tsize += taosEncodeFixedU64(buf, pReq->stbCfg.suid); + tsize += tdEncodeSchema(buf, pReq->stbCfg.pSchema); + tsize += tdEncodeSchema(buf, pReq->stbCfg.pTagSchema); + break; + case META_CHILD_TABLE: + tsize += taosEncodeFixedU64(buf, pReq->ctbCfg.suid); + tsize += tdEncodeKVRow(buf, pReq->ctbCfg.pTag); + break; + case META_NORMAL_TABLE: + tsize += tdEncodeSchema(buf, pReq->ntbCfg.pSchema); + break; + default: + break; + } + + return tsize; +} + +void *vnodeParseCreateTableReq(void *buf, SVCreateTableReq *pReq) { + buf = taosDecodeString(buf, &(pReq->name)); + buf = taosDecodeFixedU32(buf, &(pReq->ttl)); + buf = taosDecodeFixedU32(buf, &(pReq->keep)); + buf = taosDecodeFixedU8(buf, &(pReq->type)); + + switch (pReq->type) { + case META_SUPER_TABLE: + buf = taosDecodeFixedU64(buf, &(pReq->stbCfg.suid)); + buf = tdDecodeSchema(buf, &(pReq->stbCfg.pSchema)); + buf = tdDecodeSchema(buf, &(pReq->stbCfg.pTagSchema)); + break; + case META_CHILD_TABLE: + buf = taosDecodeFixedU64(buf, &(pReq->ctbCfg.suid)); + buf = tdDecodeKVRow(buf, pReq->ctbCfg.pTag); + break; + case META_NORMAL_TABLE: + buf = tdDecodeSchema(buf, &(pReq->ntbCfg.pSchema)); + break; + default: + break; + } + + return buf; +} + +int vnodeBuildDropTableReq(void **buf, const SVDropTableReq *pReq) { + // TODO + return 0; +} + +void *vnodeParseDropTableReq(void *buf, SVDropTableReq *pReq) { + // TODO +} \ No newline at end of file diff --git a/source/dnode/vnode/impl/src/vnodeWrite.c b/source/dnode/vnode/impl/src/vnodeWrite.c index 0d4250c60e..074453aded 100644 --- a/source/dnode/vnode/impl/src/vnodeWrite.c +++ b/source/dnode/vnode/impl/src/vnodeWrite.c @@ -56,9 +56,7 @@ int vnodeProcessWMsgs(SVnode *pVnode, SArray *pMsgs) { switch (pMsg->msgType) { case TSDB_MSG_TYPE_CREATE_TABLE: - if (vnodeParseCreateTableReq(pVnodeReq->req, pMsg->contLen - sizeof(pVnodeReq->ver), &(ctReq)) < 0) { - // TODO: handle error - } + vnodeParseCreateTableReq(pVnodeReq->req, &(ctReq)); if (metaCreateTable(pVnode->pMeta, &ctReq) < 0) { // TODO: handle error @@ -67,7 +65,7 @@ int vnodeProcessWMsgs(SVnode *pVnode, SArray *pMsgs) { // TODO: maybe need to clear the requst struct break; case TSDB_MSG_TYPE_DROP_TABLE: - if (vnodeParseDropTableReq(pVnodeReq->req, pMsg->contLen - sizeof(pVnodeReq->ver), &(dtReq)) < 0) { + if (vnodeParseDropTableReq(pVnodeReq->req, &(dtReq)) < 0) { // TODO: handle error } diff --git a/source/dnode/vnode/impl/test/vnodeApiTests.cpp b/source/dnode/vnode/impl/test/vnodeApiTests.cpp index 3b0c059b98..940c09e7c3 100644 --- a/source/dnode/vnode/impl/test/vnodeApiTests.cpp +++ b/source/dnode/vnode/impl/test/vnodeApiTests.cpp @@ -10,9 +10,66 @@ TEST(vnodeApiTest, vnodeOpen_vnodeClose_test) { SVnode *pVnode = vnodeOpen("vnode1", NULL); ASSERT_NE(pVnode, nullptr); - // Create table - // SArray *pArray = taosArrayInit() - // vnodeProcessWMsgs(pVnode, ); + tb_uid_t suid = 1638166374163; + { + // Create a super table + STSchema *pSchema = NULL; + STSchema *pTagSchema = NULL; + char tbname[128] = "st"; + + SArray *pMsgs = (SArray *)taosArrayInit(1, sizeof(SRpcMsg *)); + STbCfg stbCfg = META_INIT_STB_CFG(tbname, UINT32_MAX, UINT32_MAX, suid, pSchema, pTagSchema); + + int zs = vnodeBuildCreateTableReq(NULL, &stbCfg); + SRpcMsg *pMsg = (SRpcMsg *)malloc(sizeof(SRpcMsg) + zs); + pMsg->contLen = zs; + pMsg->pCont = POINTER_SHIFT(pMsg, sizeof(SRpcMsg)); + + void **pBuf = &(pMsg->pCont); + + vnodeBuildCreateTableReq(pBuf, &stbCfg); + META_CLEAR_TB_CFG(&stbCfg); + + taosArrayPush(pMsgs, &(pMsg)); + + vnodeProcessWMsgs(pVnode, pMsgs); + + free(pMsg); + taosArrayClear(pMsgs); + } + + { + // Create some child tables + int ntables = 1000000; + int batch = 10; + for (int i = 0; i < ntables / batch; i++) { + SArray *pMsgs = (SArray *)taosArrayInit(batch, sizeof(SRpcMsg *)); + for (int j = 0; j < batch; j++) { + SRow *pTag = NULL; + char tbname[128]; + sprintf(tbname, "tb%d", i * batch + j); + STbCfg ctbCfg = META_INIT_CTB_CFG(tbname, UINT32_MAX, UINT32_MAX, suid, pTag); + + int tz = vnodeBuildCreateTableReq(NULL, &ctbCfg); + SRpcMsg *pMsg = (SRpcMsg *)malloc(sizeof(SRpcMsg) + tz); + pMsg->contLen = tz; + pMsg->pCont = POINTER_SHIFT(pMsg, sizeof(*pMsg)); + void **pBuf = &(pMsg->pCont); + + vnodeBuildCreateTableReq(pBuf, &ctbCfg); + META_CLEAR_TB_CFG(&ctbCfg); + } + + vnodeProcessWMsgs(pVnode, pMsgs); + + for (int j = 0; j < batch; j++) { + SRpcMsg *pMsg = *(SRpcMsg **)taosArrayPop(pMsgs); + free(pMsg); + } + + taosArrayClear(pMsgs); + } + } // Close the vnode vnodeClose(pVnode); diff --git a/source/dnode/vnode/meta/src/metaIdx.c b/source/dnode/vnode/meta/src/metaIdx.c index 0666609f9f..a3c0d3540e 100644 --- a/source/dnode/vnode/meta/src/metaIdx.c +++ b/source/dnode/vnode/meta/src/metaIdx.c @@ -50,4 +50,9 @@ void metaCloseIdx(SMeta *pMeta) { /* TODO */ int metaSaveTableToIdx(SMeta *pMeta, const STbCfg *pTbOptions) { // TODO return 0; +} + +int metaRemoveTableFromIdx(SMeta *pMeta, tb_uid_t uid) { + // TODO + return 0; } \ No newline at end of file From e861bdeb0a939d2c4040e34ed738bf954bbffa0d Mon Sep 17 00:00:00 2001 From: Hongze Cheng Date: Mon, 29 Nov 2021 16:59:18 +0800 Subject: [PATCH 20/41] more --- include/dnode/vnode/vnode.h | 37 +++++++++-------- source/dnode/vnode/impl/src/vnodeRequest.c | 41 +++++++++++++++++-- source/dnode/vnode/impl/src/vnodeWrite.c | 31 +++++++------- .../dnode/vnode/impl/test/vnodeApiTests.cpp | 18 ++++---- 4 files changed, 81 insertions(+), 46 deletions(-) diff --git a/include/dnode/vnode/vnode.h b/include/dnode/vnode/vnode.h index 58ad933461..393028651a 100644 --- a/include/dnode/vnode/vnode.h +++ b/include/dnode/vnode/vnode.h @@ -144,9 +144,17 @@ void vnodeOptionsInit(SVnodeCfg *pOptions); void vnodeOptionsClear(SVnodeCfg *pOptions); /* ------------------------ REQUESTS ------------------------ */ +typedef STbCfg SVCreateTableReq; +typedef struct { + tb_uid_t uid; +} SVDropTableReq; + typedef struct { uint64_t ver; - char req[]; + union { + SVCreateTableReq ctReq; + SVDropTableReq dtReq; + }; } SVnodeReq; typedef struct { @@ -154,25 +162,22 @@ typedef struct { char info[]; } SVnodeRsp; -/// Create table request -typedef STbCfg SVCreateTableReq; +#define VNODE_INIT_CREATE_STB_REQ(VER, NAME, TTL, KEEP, SUID, PSCHEMA, PTAGSCHEMA) \ + { .ver = (VER), .ctReq = META_INIT_STB_CFG(NAME, TTL, KEEP, SUID, PSCHEMA, PTAGSCHEMA) } +#define VNODE_INIT_CREATE_CTB_REQ(VER, NAME, TTL, KEEP, SUID, PTAG) \ + { .ver = (VER), .ctReq = META_INIT_CTB_CFG(NAME, TTL, KEEP, SUID, PTAG) } + +#define VNODE_INIT_CREATE_NTB_REQ(VER, NAME, TTL, KEEP, SUID, PSCHEMA) \ + { .ver = (VER), .ctReq = META_INIT_NTB_CFG(NAME, TTL, KEEP, SUID, PSCHEMA) } + +int vnodeBuildReq(void **buf, const SVnodeReq *pReq, uint8_t type); +void *vnodeParseReq(void *buf, SVnodeReq *pReq, uint8_t type); + +// TODO int vnodeBuildCreateTableReq(void **buf, const SVCreateTableReq *pReq); void *vnodeParseCreateTableReq(void *buf, SVCreateTableReq *pReq); -/// Drop table request -typedef struct { - tb_uid_t uid; -} SVDropTableReq; -/// Alter table request -typedef struct { - // TODO -} SVAlterTableReq; - -int vnodeCreateTable(SVnode *pVnode, SVCreateTableReq *pReq, SVnodeRsp *pRsp); -int vnodeDropTable(SVnode *pVnode, SVDropTableReq *pReq, SVnodeRsp *pRsp); -int vnodeAlterTable(SVnode *pVnode, SVAlterTableReq *pReq, SVnodeRsp *pRsp); - /* ------------------------ FOR COMPILE ------------------------ */ #if 1 diff --git a/source/dnode/vnode/impl/src/vnodeRequest.c b/source/dnode/vnode/impl/src/vnodeRequest.c index d89f34e7e5..59031fd530 100644 --- a/source/dnode/vnode/impl/src/vnodeRequest.c +++ b/source/dnode/vnode/impl/src/vnodeRequest.c @@ -15,6 +15,39 @@ #include "vnodeDef.h" +int vnodeBuildReq(void **buf, const SVnodeReq *pReq, uint8_t type) { + int tsize = 0; + + tsize += taosEncodeFixedU64(buf, pReq->ver); + switch (type) { + case TSDB_MSG_TYPE_CREATE_TABLE: + tsize += vnodeBuildCreateTableReq(buf, &(pReq->ctReq)); + /* code */ + break; + + default: + break; + } + /* TODO */ + return tsize; +} + +void *vnodeParseReq(void *buf, SVnodeReq *pReq, uint8_t type) { + buf = taosDecodeFixedU64(buf, &(pReq->ver)); + + switch (type) { + case TSDB_MSG_TYPE_CREATE_TABLE: + buf = vnodeParseCreateTableReq(buf, &(pReq->ctReq)); + break; + + default: + break; + } + + // TODO + return buf; +} + int vnodeBuildCreateTableReq(void **buf, const SVCreateTableReq *pReq) { int tsize = 0; @@ -69,11 +102,11 @@ void *vnodeParseCreateTableReq(void *buf, SVCreateTableReq *pReq) { return buf; } -int vnodeBuildDropTableReq(void **buf, const SVDropTableReq *pReq) { - // TODO - return 0; +int vnodeBuildDropTableReq(void **buf, const SVDropTableReq *pReq) { + // TODO + return 0; } void *vnodeParseDropTableReq(void *buf, SVDropTableReq *pReq) { - // TODO + // TODO } \ No newline at end of file diff --git a/source/dnode/vnode/impl/src/vnodeWrite.c b/source/dnode/vnode/impl/src/vnodeWrite.c index 074453aded..08c2bd3542 100644 --- a/source/dnode/vnode/impl/src/vnodeWrite.c +++ b/source/dnode/vnode/impl/src/vnodeWrite.c @@ -23,10 +23,10 @@ int vnodeProcessWMsgs(SVnode *pVnode, SArray *pMsgs) { pMsg = *(SRpcMsg **)taosArrayGet(pMsgs, i); // ser request version - pVnodeReq = (SVnodeReq *)(pMsg->pCont); - pVnodeReq->ver = pVnode->state.processed++; + void **pBuf = &(pMsg->pCont); + taosEncodeFixedU64(pBuf, pVnode->state.processed++); - if (walWrite(pVnode->pWal, pVnodeReq->ver, pVnodeReq->req, pMsg->contLen - sizeof(pVnodeReq->ver)) < 0) { + if (walWrite(pVnode->pWal, pVnodeReq->ver, pMsg->pCont, pMsg->contLen) < 0) { // TODO: handle error } } @@ -36,9 +36,7 @@ int vnodeProcessWMsgs(SVnode *pVnode, SArray *pMsgs) { // Apply each request now for (int i = 0; i < taosArrayGetSize(pMsgs); i++) { pMsg = *(SRpcMsg **)taosArrayGet(pMsgs, i); - pVnodeReq = (SVnodeReq *)(pMsg->pCont); - SVCreateTableReq ctReq; - SVDropTableReq dtReq; + SVnodeReq vReq; // Apply the request { @@ -47,29 +45,28 @@ int vnodeProcessWMsgs(SVnode *pVnode, SArray *pMsgs) { // TODO: handle error } - memcpy(ptr, pVnodeReq, pMsg->contLen); + // TODO: copy here need to be extended + memcpy(ptr, pMsg->pCont, pMsg->contLen); - // todo: change the interface here - if (tqPushMsg(pVnode->pTq, ptr, pVnodeReq->ver) < 0) { + // // todo: change the interface here + uint64_t ver; + taosDecodeFixedU64(pMsg->pCont, &ver); + if (tqPushMsg(pVnode->pTq, ptr, ver) < 0) { // TODO: handle error } + vnodeParseReq(pMsg->pCont, &vReq, pMsg->msgType); + switch (pMsg->msgType) { case TSDB_MSG_TYPE_CREATE_TABLE: - vnodeParseCreateTableReq(pVnodeReq->req, &(ctReq)); - - if (metaCreateTable(pVnode->pMeta, &ctReq) < 0) { + if (metaCreateTable(pVnode->pMeta, &(vReq.ctReq)) < 0) { // TODO: handle error } // TODO: maybe need to clear the requst struct break; case TSDB_MSG_TYPE_DROP_TABLE: - if (vnodeParseDropTableReq(pVnodeReq->req, &(dtReq)) < 0) { - // TODO: handle error - } - - if (metaDropTable(pVnode->pMeta, dtReq.uid) < 0) { + if (metaDropTable(pVnode->pMeta, vReq.dtReq.uid) < 0) { // TODO: handle error } break; diff --git a/source/dnode/vnode/impl/test/vnodeApiTests.cpp b/source/dnode/vnode/impl/test/vnodeApiTests.cpp index 940c09e7c3..5679fc06f2 100644 --- a/source/dnode/vnode/impl/test/vnodeApiTests.cpp +++ b/source/dnode/vnode/impl/test/vnodeApiTests.cpp @@ -17,18 +17,18 @@ TEST(vnodeApiTest, vnodeOpen_vnodeClose_test) { STSchema *pTagSchema = NULL; char tbname[128] = "st"; - SArray *pMsgs = (SArray *)taosArrayInit(1, sizeof(SRpcMsg *)); - STbCfg stbCfg = META_INIT_STB_CFG(tbname, UINT32_MAX, UINT32_MAX, suid, pSchema, pTagSchema); + SArray * pMsgs = (SArray *)taosArrayInit(1, sizeof(SRpcMsg *)); + SVnodeReq vCreateSTbReq = VNODE_INIT_CREATE_STB_REQ(0, tbname, UINT32_MAX, UINT32_MAX, suid, pSchema, pTagSchema); - int zs = vnodeBuildCreateTableReq(NULL, &stbCfg); + int zs = vnodeBuildReq(NULL, &vCreateSTbReq, TSDB_MSG_TYPE_CREATE_TABLE); SRpcMsg *pMsg = (SRpcMsg *)malloc(sizeof(SRpcMsg) + zs); pMsg->contLen = zs; pMsg->pCont = POINTER_SHIFT(pMsg, sizeof(SRpcMsg)); void **pBuf = &(pMsg->pCont); - vnodeBuildCreateTableReq(pBuf, &stbCfg); - META_CLEAR_TB_CFG(&stbCfg); + vnodeBuildReq(pBuf, &vCreateSTbReq, TSDB_MSG_TYPE_CREATE_TABLE); + META_CLEAR_TB_CFG(&vCreateSTbReq); taosArrayPush(pMsgs, &(pMsg)); @@ -48,16 +48,16 @@ TEST(vnodeApiTest, vnodeOpen_vnodeClose_test) { SRow *pTag = NULL; char tbname[128]; sprintf(tbname, "tb%d", i * batch + j); - STbCfg ctbCfg = META_INIT_CTB_CFG(tbname, UINT32_MAX, UINT32_MAX, suid, pTag); + SVnodeReq vCreateCTbReq = VNODE_INIT_CREATE_CTB_REQ(0, tbname, UINT32_MAX, UINT32_MAX, suid, pTag); - int tz = vnodeBuildCreateTableReq(NULL, &ctbCfg); + int tz = vnodeBuildReq(NULL, &vCreateCTbReq, TSDB_MSG_TYPE_CREATE_TABLE); SRpcMsg *pMsg = (SRpcMsg *)malloc(sizeof(SRpcMsg) + tz); pMsg->contLen = tz; pMsg->pCont = POINTER_SHIFT(pMsg, sizeof(*pMsg)); void **pBuf = &(pMsg->pCont); - vnodeBuildCreateTableReq(pBuf, &ctbCfg); - META_CLEAR_TB_CFG(&ctbCfg); + vnodeBuildReq(pBuf, &vCreateCTbReq, TSDB_MSG_TYPE_CREATE_TABLE); + META_CLEAR_TB_CFG(&vCreateCTbReq); } vnodeProcessWMsgs(pVnode, pMsgs); From 6b36c2ae1c2e15c842b9b9a8df53d771e4fcc52e Mon Sep 17 00:00:00 2001 From: Hongze Cheng Date: Mon, 29 Nov 2021 17:57:44 +0800 Subject: [PATCH 21/41] more --- include/dnode/vnode/meta/meta.h | 2 +- include/dnode/vnode/vnode.h | 12 ++-- .../dnode/vnode/impl/test/vnodeApiTests.cpp | 71 +++++++++++++++++-- 3 files changed, 72 insertions(+), 13 deletions(-) diff --git a/include/dnode/vnode/meta/meta.h b/include/dnode/vnode/meta/meta.h index 6060db02c4..1de1f9fa2c 100644 --- a/include/dnode/vnode/meta/meta.h +++ b/include/dnode/vnode/meta/meta.h @@ -65,7 +65,7 @@ typedef struct STbCfg { struct { /// super table UID tb_uid_t suid; - SRow * pTag; + SKVRow pTag; } ctbCfg; }; } STbCfg; diff --git a/include/dnode/vnode/vnode.h b/include/dnode/vnode/vnode.h index 393028651a..4e5829a403 100644 --- a/include/dnode/vnode/vnode.h +++ b/include/dnode/vnode/vnode.h @@ -162,14 +162,14 @@ typedef struct { char info[]; } SVnodeRsp; -#define VNODE_INIT_CREATE_STB_REQ(VER, NAME, TTL, KEEP, SUID, PSCHEMA, PTAGSCHEMA) \ - { .ver = (VER), .ctReq = META_INIT_STB_CFG(NAME, TTL, KEEP, SUID, PSCHEMA, PTAGSCHEMA) } +#define VNODE_INIT_CREATE_STB_REQ(NAME, TTL, KEEP, SUID, PSCHEMA, PTAGSCHEMA) \ + { .ver = 0, .ctReq = META_INIT_STB_CFG(NAME, TTL, KEEP, SUID, PSCHEMA, PTAGSCHEMA) } -#define VNODE_INIT_CREATE_CTB_REQ(VER, NAME, TTL, KEEP, SUID, PTAG) \ - { .ver = (VER), .ctReq = META_INIT_CTB_CFG(NAME, TTL, KEEP, SUID, PTAG) } +#define VNODE_INIT_CREATE_CTB_REQ(NAME, TTL, KEEP, SUID, PTAG) \ + { .ver = 0, .ctReq = META_INIT_CTB_CFG(NAME, TTL, KEEP, SUID, PTAG) } -#define VNODE_INIT_CREATE_NTB_REQ(VER, NAME, TTL, KEEP, SUID, PSCHEMA) \ - { .ver = (VER), .ctReq = META_INIT_NTB_CFG(NAME, TTL, KEEP, SUID, PSCHEMA) } +#define VNODE_INIT_CREATE_NTB_REQ(NAME, TTL, KEEP, SUID, PSCHEMA) \ + { .ver = 0, .ctReq = META_INIT_NTB_CFG(NAME, TTL, KEEP, SUID, PSCHEMA) } int vnodeBuildReq(void **buf, const SVnodeReq *pReq, uint8_t type); void *vnodeParseReq(void *buf, SVnodeReq *pReq, uint8_t type); diff --git a/source/dnode/vnode/impl/test/vnodeApiTests.cpp b/source/dnode/vnode/impl/test/vnodeApiTests.cpp index 5679fc06f2..19d758b0b3 100644 --- a/source/dnode/vnode/impl/test/vnodeApiTests.cpp +++ b/source/dnode/vnode/impl/test/vnodeApiTests.cpp @@ -3,6 +3,63 @@ #include "vnode.h" +static STSchema *createBasicSchema() { + STSchemaBuilder sb; + STSchema * pSchema = NULL; + + tdInitTSchemaBuilder(&sb, 0); + + tdAddColToSchema(&sb, TSDB_DATA_TYPE_TIMESTAMP, 0, 0); + for (int i = 1; i < 10; i++) { + tdAddColToSchema(&sb, TSDB_DATA_TYPE_INT, i, 0); + } + + pSchema = tdGetSchemaFromBuilder(&sb); + + tdDestroyTSchemaBuilder(&sb); + + return pSchema; +} + +static STSchema *createBasicTagSchema() { + STSchemaBuilder sb; + STSchema * pSchema = NULL; + + tdInitTSchemaBuilder(&sb, 0); + + tdAddColToSchema(&sb, TSDB_DATA_TYPE_TIMESTAMP, 0, 0); + for (int i = 10; i < 12; i++) { + tdAddColToSchema(&sb, TSDB_DATA_TYPE_BINARY, i, 20); + } + + pSchema = tdGetSchemaFromBuilder(&sb); + + tdDestroyTSchemaBuilder(&sb); + + return pSchema; +} + +static SKVRow createBasicTag() { + SKVRowBuilder rb; + SKVRow pTag; + + tdInitKVRowBuilder(&rb); + + for (int i = 10; i < 12; i++) { + void *pVal = malloc(sizeof(VarDataLenT) + strlen("foo")); + varDataLen(pVal) = strlen("foo"); + memcpy(varDataVal(pVal), "foo", strlen("foo")); + + tdAddColToKVRow(&rb, i, TSDB_DATA_TYPE_BINARY, pVal); + free(pVal); + } + + pTag = tdGetKVRowFromBuilder(&rb); + tdDestroyKVRowBuilder(&rb); + + return pTag; +} + TEST(vnodeApiTest, vnodeOpen_vnodeClose_test) { GTEST_ASSERT_GE(vnodeInit(), 0); @@ -13,12 +70,12 @@ TEST(vnodeApiTest, vnodeOpen_vnodeClose_test) { tb_uid_t suid = 1638166374163; { // Create a super table - STSchema *pSchema = NULL; - STSchema *pTagSchema = NULL; + STSchema *pSchema = createBasicSchema(); + STSchema *pTagSchema = createBasicTagSchema(); char tbname[128] = "st"; SArray * pMsgs = (SArray *)taosArrayInit(1, sizeof(SRpcMsg *)); - SVnodeReq vCreateSTbReq = VNODE_INIT_CREATE_STB_REQ(0, tbname, UINT32_MAX, UINT32_MAX, suid, pSchema, pTagSchema); + SVnodeReq vCreateSTbReq = VNODE_INIT_CREATE_STB_REQ(tbname, UINT32_MAX, UINT32_MAX, suid, pSchema, pTagSchema); int zs = vnodeBuildReq(NULL, &vCreateSTbReq, TSDB_MSG_TYPE_CREATE_TABLE); SRpcMsg *pMsg = (SRpcMsg *)malloc(sizeof(SRpcMsg) + zs); @@ -36,6 +93,8 @@ TEST(vnodeApiTest, vnodeOpen_vnodeClose_test) { free(pMsg); taosArrayClear(pMsgs); + tdFreeSchema(pSchema); + tdFreeSchema(pTagSchema); } { @@ -45,10 +104,10 @@ TEST(vnodeApiTest, vnodeOpen_vnodeClose_test) { for (int i = 0; i < ntables / batch; i++) { SArray *pMsgs = (SArray *)taosArrayInit(batch, sizeof(SRpcMsg *)); for (int j = 0; j < batch; j++) { - SRow *pTag = NULL; - char tbname[128]; + SKVRow pTag = createBasicTag(); + char tbname[128]; sprintf(tbname, "tb%d", i * batch + j); - SVnodeReq vCreateCTbReq = VNODE_INIT_CREATE_CTB_REQ(0, tbname, UINT32_MAX, UINT32_MAX, suid, pTag); + SVnodeReq vCreateCTbReq = VNODE_INIT_CREATE_CTB_REQ(tbname, UINT32_MAX, UINT32_MAX, suid, pTag); int tz = vnodeBuildReq(NULL, &vCreateCTbReq, TSDB_MSG_TYPE_CREATE_TABLE); SRpcMsg *pMsg = (SRpcMsg *)malloc(sizeof(SRpcMsg) + tz); From 0d2461a96cd85876acc041881914b06f5e591a94 Mon Sep 17 00:00:00 2001 From: Hongze Cheng Date: Mon, 29 Nov 2021 18:07:42 +0800 Subject: [PATCH 22/41] fix test bug --- source/dnode/vnode/impl/test/vnodeApiTests.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/source/dnode/vnode/impl/test/vnodeApiTests.cpp b/source/dnode/vnode/impl/test/vnodeApiTests.cpp index 19d758b0b3..591e0cc0d9 100644 --- a/source/dnode/vnode/impl/test/vnodeApiTests.cpp +++ b/source/dnode/vnode/impl/test/vnodeApiTests.cpp @@ -117,6 +117,8 @@ TEST(vnodeApiTest, vnodeOpen_vnodeClose_test) { vnodeBuildReq(pBuf, &vCreateCTbReq, TSDB_MSG_TYPE_CREATE_TABLE); META_CLEAR_TB_CFG(&vCreateCTbReq); + + taosArrayPush(pMsgs, pMsg); } vnodeProcessWMsgs(pVnode, pMsgs); From fbf47592fc5d65be2438b2ea5a75fcc3f5109644 Mon Sep 17 00:00:00 2001 From: Hongze Cheng Date: Mon, 29 Nov 2021 18:18:35 +0800 Subject: [PATCH 23/41] fix coredump --- source/dnode/vnode/impl/test/vnodeApiTests.cpp | 2 +- source/dnode/vnode/tq/src/tq.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/source/dnode/vnode/impl/test/vnodeApiTests.cpp b/source/dnode/vnode/impl/test/vnodeApiTests.cpp index 591e0cc0d9..07d61cb53a 100644 --- a/source/dnode/vnode/impl/test/vnodeApiTests.cpp +++ b/source/dnode/vnode/impl/test/vnodeApiTests.cpp @@ -118,7 +118,7 @@ TEST(vnodeApiTest, vnodeOpen_vnodeClose_test) { vnodeBuildReq(pBuf, &vCreateCTbReq, TSDB_MSG_TYPE_CREATE_TABLE); META_CLEAR_TB_CFG(&vCreateCTbReq); - taosArrayPush(pMsgs, pMsg); + taosArrayPush(pMsgs, &(pMsg)); } vnodeProcessWMsgs(pVnode, pMsgs); diff --git a/source/dnode/vnode/tq/src/tq.c b/source/dnode/vnode/tq/src/tq.c index 130ff70408..c1a46e567b 100644 --- a/source/dnode/vnode/tq/src/tq.c +++ b/source/dnode/vnode/tq/src/tq.c @@ -46,7 +46,7 @@ STQ* tqOpen(const char* path, STqCfg* tqConfig, TqLogReader* tqLogReader, SMemAl //TODO: memory error return NULL; } - strcpy(pTq->path, path); + pTq->path = strdup(path); pTq->tqConfig = tqConfig; pTq->tqLogReader = tqLogReader; // pTq->tqMemRef.pAlloctorFactory = allocFac; From 8c1638b8fb155753f756a51f7c69c74e764a0e75 Mon Sep 17 00:00:00 2001 From: Hongze Cheng Date: Mon, 29 Nov 2021 18:25:00 +0800 Subject: [PATCH 24/41] more --- include/dnode/vnode/vnode.h | 4 ---- source/dnode/vnode/impl/src/vnodeRequest.c | 7 +++++-- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/include/dnode/vnode/vnode.h b/include/dnode/vnode/vnode.h index 4e5829a403..fcb77a4967 100644 --- a/include/dnode/vnode/vnode.h +++ b/include/dnode/vnode/vnode.h @@ -174,10 +174,6 @@ typedef struct { int vnodeBuildReq(void **buf, const SVnodeReq *pReq, uint8_t type); void *vnodeParseReq(void *buf, SVnodeReq *pReq, uint8_t type); -// TODO -int vnodeBuildCreateTableReq(void **buf, const SVCreateTableReq *pReq); -void *vnodeParseCreateTableReq(void *buf, SVCreateTableReq *pReq); - /* ------------------------ FOR COMPILE ------------------------ */ #if 1 diff --git a/source/dnode/vnode/impl/src/vnodeRequest.c b/source/dnode/vnode/impl/src/vnodeRequest.c index 59031fd530..5b17bf0ffb 100644 --- a/source/dnode/vnode/impl/src/vnodeRequest.c +++ b/source/dnode/vnode/impl/src/vnodeRequest.c @@ -15,6 +15,9 @@ #include "vnodeDef.h" +static int vnodeBuildCreateTableReq(void **buf, const SVCreateTableReq *pReq); +static void *vnodeParseCreateTableReq(void *buf, SVCreateTableReq *pReq); + int vnodeBuildReq(void **buf, const SVnodeReq *pReq, uint8_t type) { int tsize = 0; @@ -48,7 +51,7 @@ void *vnodeParseReq(void *buf, SVnodeReq *pReq, uint8_t type) { return buf; } -int vnodeBuildCreateTableReq(void **buf, const SVCreateTableReq *pReq) { +static int vnodeBuildCreateTableReq(void **buf, const SVCreateTableReq *pReq) { int tsize = 0; tsize += taosEncodeString(buf, pReq->name); @@ -76,7 +79,7 @@ int vnodeBuildCreateTableReq(void **buf, const SVCreateTableReq *pReq) { return tsize; } -void *vnodeParseCreateTableReq(void *buf, SVCreateTableReq *pReq) { +static void *vnodeParseCreateTableReq(void *buf, SVCreateTableReq *pReq) { buf = taosDecodeString(buf, &(pReq->name)); buf = taosDecodeFixedU32(buf, &(pReq->ttl)); buf = taosDecodeFixedU32(buf, &(pReq->keep)); From df9ba31d81fd943d884ee5dc51437dbdf6dbc1fc Mon Sep 17 00:00:00 2001 From: Hongze Cheng Date: Mon, 29 Nov 2021 18:37:04 +0800 Subject: [PATCH 25/41] more --- source/dnode/vnode/impl/src/vnodeWrite.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/source/dnode/vnode/impl/src/vnodeWrite.c b/source/dnode/vnode/impl/src/vnodeWrite.c index 08c2bd3542..ee4c6e5443 100644 --- a/source/dnode/vnode/impl/src/vnodeWrite.c +++ b/source/dnode/vnode/impl/src/vnodeWrite.c @@ -24,9 +24,10 @@ int vnodeProcessWMsgs(SVnode *pVnode, SArray *pMsgs) { // ser request version void **pBuf = &(pMsg->pCont); - taosEncodeFixedU64(pBuf, pVnode->state.processed++); + uint64_t ver = pVnode->state.processed++; + taosEncodeFixedU64(pBuf, ver); - if (walWrite(pVnode->pWal, pVnodeReq->ver, pMsg->pCont, pMsg->contLen) < 0) { + if (walWrite(pVnode->pWal, ver, pMsg->pCont, pMsg->contLen) < 0) { // TODO: handle error } } @@ -76,9 +77,9 @@ int vnodeProcessWMsgs(SVnode *pVnode, SArray *pMsgs) { default: break; } - } - pVnode->state.applied = pVnodeReq->ver; + pVnode->state.applied = ver; + } // Check if it needs to commit if (vnodeShouldCommit(pVnode)) { From 8b88d1ad43c5ecb39f0fbdadfaa83514d38d0715 Mon Sep 17 00:00:00 2001 From: Hongze Cheng Date: Tue, 30 Nov 2021 11:24:13 +0800 Subject: [PATCH 26/41] fix multiple coredump --- source/dnode/vnode/impl/src/vnodeWrite.c | 6 +++--- source/dnode/vnode/impl/test/vnodeApiTests.cpp | 17 ++++++++++------- 2 files changed, 13 insertions(+), 10 deletions(-) diff --git a/source/dnode/vnode/impl/src/vnodeWrite.c b/source/dnode/vnode/impl/src/vnodeWrite.c index ee4c6e5443..acfcbb10d5 100644 --- a/source/dnode/vnode/impl/src/vnodeWrite.c +++ b/source/dnode/vnode/impl/src/vnodeWrite.c @@ -23,9 +23,9 @@ int vnodeProcessWMsgs(SVnode *pVnode, SArray *pMsgs) { pMsg = *(SRpcMsg **)taosArrayGet(pMsgs, i); // ser request version - void **pBuf = &(pMsg->pCont); + void * pBuf = pMsg->pCont; uint64_t ver = pVnode->state.processed++; - taosEncodeFixedU64(pBuf, ver); + taosEncodeFixedU64(&pBuf, ver); if (walWrite(pVnode->pWal, ver, pMsg->pCont, pMsg->contLen) < 0) { // TODO: handle error @@ -49,7 +49,7 @@ int vnodeProcessWMsgs(SVnode *pVnode, SArray *pMsgs) { // TODO: copy here need to be extended memcpy(ptr, pMsg->pCont, pMsg->contLen); - // // todo: change the interface here + // todo: change the interface here uint64_t ver; taosDecodeFixedU64(pMsg->pCont, &ver); if (tqPushMsg(pVnode->pTq, ptr, ver) < 0) { diff --git a/source/dnode/vnode/impl/test/vnodeApiTests.cpp b/source/dnode/vnode/impl/test/vnodeApiTests.cpp index 07d61cb53a..928c5c52be 100644 --- a/source/dnode/vnode/impl/test/vnodeApiTests.cpp +++ b/source/dnode/vnode/impl/test/vnodeApiTests.cpp @@ -79,12 +79,13 @@ TEST(vnodeApiTest, vnodeOpen_vnodeClose_test) { int zs = vnodeBuildReq(NULL, &vCreateSTbReq, TSDB_MSG_TYPE_CREATE_TABLE); SRpcMsg *pMsg = (SRpcMsg *)malloc(sizeof(SRpcMsg) + zs); + pMsg->msgType = TSDB_MSG_TYPE_CREATE_TABLE; pMsg->contLen = zs; pMsg->pCont = POINTER_SHIFT(pMsg, sizeof(SRpcMsg)); - void **pBuf = &(pMsg->pCont); + void *pBuf = pMsg->pCont; - vnodeBuildReq(pBuf, &vCreateSTbReq, TSDB_MSG_TYPE_CREATE_TABLE); + vnodeBuildReq(&pBuf, &vCreateSTbReq, TSDB_MSG_TYPE_CREATE_TABLE); META_CLEAR_TB_CFG(&vCreateSTbReq); taosArrayPush(pMsgs, &(pMsg)); @@ -92,7 +93,7 @@ TEST(vnodeApiTest, vnodeOpen_vnodeClose_test) { vnodeProcessWMsgs(pVnode, pMsgs); free(pMsg); - taosArrayClear(pMsgs); + taosArrayDestroy(pMsgs); tdFreeSchema(pSchema); tdFreeSchema(pTagSchema); } @@ -111,12 +112,14 @@ TEST(vnodeApiTest, vnodeOpen_vnodeClose_test) { int tz = vnodeBuildReq(NULL, &vCreateCTbReq, TSDB_MSG_TYPE_CREATE_TABLE); SRpcMsg *pMsg = (SRpcMsg *)malloc(sizeof(SRpcMsg) + tz); + pMsg->msgType = TSDB_MSG_TYPE_CREATE_TABLE; pMsg->contLen = tz; pMsg->pCont = POINTER_SHIFT(pMsg, sizeof(*pMsg)); - void **pBuf = &(pMsg->pCont); + void *pBuf = pMsg->pCont; - vnodeBuildReq(pBuf, &vCreateCTbReq, TSDB_MSG_TYPE_CREATE_TABLE); + vnodeBuildReq(&pBuf, &vCreateCTbReq, TSDB_MSG_TYPE_CREATE_TABLE); META_CLEAR_TB_CFG(&vCreateCTbReq); + free(pTag); taosArrayPush(pMsgs, &(pMsg)); } @@ -128,7 +131,7 @@ TEST(vnodeApiTest, vnodeOpen_vnodeClose_test) { free(pMsg); } - taosArrayClear(pMsgs); + taosArrayDestroy(pMsgs); } } @@ -138,7 +141,7 @@ TEST(vnodeApiTest, vnodeOpen_vnodeClose_test) { vnodeClear(); } -TEST(vnodeApiTest, vnode_process_create_table) { +TEST(vnodeApiTest, DISABLED_vnode_process_create_table) { STSchema * pSchema = NULL; STSchema * pTagSchema = NULL; char stname[15]; From 6834e624347ef4a5f20cdaf616ef349ac8781681 Mon Sep 17 00:00:00 2001 From: Hongze Cheng Date: Tue, 30 Nov 2021 11:46:18 +0800 Subject: [PATCH 27/41] fix another coredump --- source/dnode/vnode/impl/src/vnodeRequest.c | 2 +- .../dnode/vnode/impl/test/vnodeApiTests.cpp | 20 +++++++++++++++++++ 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/source/dnode/vnode/impl/src/vnodeRequest.c b/source/dnode/vnode/impl/src/vnodeRequest.c index 5b17bf0ffb..be5f5c890c 100644 --- a/source/dnode/vnode/impl/src/vnodeRequest.c +++ b/source/dnode/vnode/impl/src/vnodeRequest.c @@ -93,7 +93,7 @@ static void *vnodeParseCreateTableReq(void *buf, SVCreateTableReq *pReq) { break; case META_CHILD_TABLE: buf = taosDecodeFixedU64(buf, &(pReq->ctbCfg.suid)); - buf = tdDecodeKVRow(buf, pReq->ctbCfg.pTag); + buf = tdDecodeKVRow(buf, &(pReq->ctbCfg.pTag)); break; case META_NORMAL_TABLE: buf = tdDecodeSchema(buf, &(pReq->ntbCfg.pSchema)); diff --git a/source/dnode/vnode/impl/test/vnodeApiTests.cpp b/source/dnode/vnode/impl/test/vnodeApiTests.cpp index 928c5c52be..2182e61769 100644 --- a/source/dnode/vnode/impl/test/vnodeApiTests.cpp +++ b/source/dnode/vnode/impl/test/vnodeApiTests.cpp @@ -60,6 +60,26 @@ static SKVRow createBasicTag() { return pTag; } +#if 0 +TEST(vnodeApiTest, test_create_table_encode_and_decode_function) { + tb_uid_t suid = 1638166374163; + STSchema *pSchema = createBasicSchema(); + STSchema *pTagSchema = createBasicTagSchema(); + char tbname[128] = "st"; + char * buffer = new char[1024]; + void * pBuf = (void *)buffer; + SVnodeReq vCreateSTbReq = VNODE_INIT_CREATE_STB_REQ(tbname, UINT32_MAX, UINT32_MAX, suid, pSchema, pTagSchema); + + vnodeBuildReq(&pBuf, &vCreateSTbReq, TSDB_MSG_TYPE_CREATE_TABLE); + + SVnodeReq decoded_req; + + vnodeParseReq(buffer, &decoded_req, TSDB_MSG_TYPE_CREATE_TABLE); + + int k = 10; +} +#endif + TEST(vnodeApiTest, vnodeOpen_vnodeClose_test) { GTEST_ASSERT_GE(vnodeInit(), 0); From 1545dc5990192ff3177efa5571ea97c5a772d71b Mon Sep 17 00:00:00 2001 From: Hongze Cheng Date: Tue, 30 Nov 2021 13:21:06 +0800 Subject: [PATCH 28/41] more --- source/dnode/vnode/impl/test/vnodeApiTests.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/source/dnode/vnode/impl/test/vnodeApiTests.cpp b/source/dnode/vnode/impl/test/vnodeApiTests.cpp index 2182e61769..853524e511 100644 --- a/source/dnode/vnode/impl/test/vnodeApiTests.cpp +++ b/source/dnode/vnode/impl/test/vnodeApiTests.cpp @@ -120,7 +120,7 @@ TEST(vnodeApiTest, vnodeOpen_vnodeClose_test) { { // Create some child tables - int ntables = 1000000; + int ntables = 50000; int batch = 10; for (int i = 0; i < ntables / batch; i++) { SArray *pMsgs = (SArray *)taosArrayInit(batch, sizeof(SRpcMsg *)); @@ -152,6 +152,8 @@ TEST(vnodeApiTest, vnodeOpen_vnodeClose_test) { } taosArrayDestroy(pMsgs); + + std::cout << "the " << i << "th batch is created" << std::endl; } } From f10c5430b3c5237f781d50d6457d3fdeb34f49ef Mon Sep 17 00:00:00 2001 From: Hongze Cheng Date: Tue, 30 Nov 2021 16:24:21 +0800 Subject: [PATCH 29/41] more --- include/common/trow.h | 53 +++++++++++++++++---------------- include/dnode/vnode/vnode.h | 4 +++ source/common/src/trow.c | 4 ++- source/common/test/trowTest.cpp | 2 ++ 4 files changed, 36 insertions(+), 27 deletions(-) diff --git a/include/common/trow.h b/include/common/trow.h index cff0f08302..4092500d5f 100644 --- a/include/common/trow.h +++ b/include/common/trow.h @@ -47,31 +47,32 @@ typedef struct { typedef struct { union { /// union field for encode and decode - uint64_t info; + uint32_t info; struct { - /// is deleted row - uint64_t del : 1; /// row type - uint64_t type : 3; + uint32_t type : 2; /// row schema version - uint64_t sver : 16; - /// row total length - uint64_t len : 32; + uint32_t sver : 16; + /// is delete row + uint32_t del : 1; /// reserved for back compatibility - uint64_t reserve : 12; + uint32_t reserve : 13; }; }; + /// row total length + uint32_t len; /// row version uint64_t ver; /// timestamp TSKEY ts; - char content[]; -} SRow; + /// the inline data, maybe a tuple or a k-v tuple + char data[]; +} STSRow; typedef struct { uint32_t nRows; char rows[]; -} SRowBatch; +} STSRowBatch; typedef enum { /// ordinary row builder @@ -88,36 +89,36 @@ typedef struct { /// buffer writer SBufferWriter bw; /// target row - SRow *pRow; -} SRowBuilder; + STSRow *pRow; +} STSRowBuilder; typedef struct { STSchema *pSchema; - SRow * pRow; -} SRowReader; + STSRow * pRow; +} STSRowReader; typedef struct { uint32_t it; - SRowBatch *pRowBatch; -} SRowBatchIter; + STSRowBatch *pRowBatch; +} STSRowBatchIter; -// SRowBuilder +// STSRowBuilder #define trbInit(rt, allocator, endian, target, size) \ { .type = (rt), .bw = tbufInitWriter(allocator, endian), .pRow = (target) } -void trbSetRowInfo(SRowBuilder *pRB, bool del, uint16_t sver); -void trbSetRowVersion(SRowBuilder *pRB, uint64_t ver); -void trbSetRowTS(SRowBuilder *pRB, TSKEY ts); -int trbWriteCol(SRowBuilder *pRB, void *pData, col_id_t cid); +void trbSetRowInfo(STSRowBuilder *pRB, bool del, uint16_t sver); +void trbSetRowVersion(STSRowBuilder *pRB, uint64_t ver); +void trbSetRowTS(STSRowBuilder *pRB, TSKEY ts); +int trbWriteCol(STSRowBuilder *pRB, void *pData, col_id_t cid); -// SRowReader +// STSRowReader #define tRowReaderInit(schema, row) \ { .schema = (schema), .row = (row) } -int tRowReaderRead(SRowReader *pRowReader, col_id_t cid, void *target, uint64_t size); +int tRowReaderRead(STSRowReader *pRowReader, col_id_t cid, void *target, uint64_t size); -// SRowBatchIter +// STSRowBatchIter #define tRowBatchIterInit(pRB) \ { .it = 0, .pRowBatch = (pRB) } -const SRow *tRowBatchIterNext(SRowBatchIter *pRowBatchIter); +const STSRow *tRowBatchIterNext(STSRowBatchIter *pRowBatchIter); #ifdef __cplusplus } diff --git a/include/dnode/vnode/vnode.h b/include/dnode/vnode/vnode.h index fcb77a4967..30531ad738 100644 --- a/include/dnode/vnode/vnode.h +++ b/include/dnode/vnode/vnode.h @@ -149,6 +149,10 @@ typedef struct { tb_uid_t uid; } SVDropTableReq; +typedef struct { + // TODO +} SVSubmitReq; + typedef struct { uint64_t ver; union { diff --git a/source/common/src/trow.c b/source/common/src/trow.c index 2e36e6a757..f383cd04dc 100644 --- a/source/common/src/trow.c +++ b/source/common/src/trow.c @@ -15,6 +15,7 @@ #include "trow.h" +#if 0 void trbSetRowInfo(SRowBuilder *pRB, bool del, uint16_t sver) { // TODO } @@ -30,4 +31,5 @@ void trbSetRowTS(SRowBuilder *pRB, TSKEY ts) { int trbWriteCol(SRowBuilder *pRB, void *pData, col_id_t cid) { // TODO return 0; -} \ No newline at end of file +} +#endif \ No newline at end of file diff --git a/source/common/test/trowTest.cpp b/source/common/test/trowTest.cpp index 8c628464e3..d7f0783d4a 100644 --- a/source/common/test/trowTest.cpp +++ b/source/common/test/trowTest.cpp @@ -3,6 +3,7 @@ #include "trow.h" TEST(td_row_test, build_row_to_target) { +#if 0 char dst[1024]; SRow* pRow = (SRow*)dst; int ncols = 10; @@ -18,4 +19,5 @@ TEST(td_row_test, build_row_to_target) { // TODO } } +#endif } \ No newline at end of file From 45be96a4546468591728c552d4688d2f68c1d528 Mon Sep 17 00:00:00 2001 From: Hongze Cheng Date: Wed, 1 Dec 2021 10:27:22 +0800 Subject: [PATCH 30/41] make vnode compile --- source/dnode/vnode/impl/src/vnodeWrite.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/dnode/vnode/impl/src/vnodeWrite.c b/source/dnode/vnode/impl/src/vnodeWrite.c index acfcbb10d5..cdeb894932 100644 --- a/source/dnode/vnode/impl/src/vnodeWrite.c +++ b/source/dnode/vnode/impl/src/vnodeWrite.c @@ -27,7 +27,7 @@ int vnodeProcessWMsgs(SVnode *pVnode, SArray *pMsgs) { uint64_t ver = pVnode->state.processed++; taosEncodeFixedU64(&pBuf, ver); - if (walWrite(pVnode->pWal, ver, pMsg->pCont, pMsg->contLen) < 0) { + if (walWrite(pVnode->pWal, ver, pMsg->msgType, pMsg->pCont, pMsg->contLen) < 0) { // TODO: handle error } } From 0e8e3f16ed108453eea94339435fa275a1d238c5 Mon Sep 17 00:00:00 2001 From: Hongze Cheng Date: Wed, 1 Dec 2021 11:00:55 +0800 Subject: [PATCH 31/41] add a test --- deps/test/CMakeLists.txt | 2 + deps/test/tdev/CMakeLists.txt | 4 ++ deps/test/tdev/src/main.c | 87 +++++++++++++++++++++++++++++++++++ 3 files changed, 93 insertions(+) create mode 100644 deps/test/tdev/CMakeLists.txt create mode 100644 deps/test/tdev/src/main.c diff --git a/deps/test/CMakeLists.txt b/deps/test/CMakeLists.txt index e571146b86..1c02ac1049 100644 --- a/deps/test/CMakeLists.txt +++ b/deps/test/CMakeLists.txt @@ -6,3 +6,5 @@ endif(${BUILD_WITH_ROCKSDB}) if(${BUILD_WITH_LUCENE}) add_subdirectory(lucene) endif(${BUILD_WITH_LUCENE}) + +add_subdirectory(tdev) diff --git a/deps/test/tdev/CMakeLists.txt b/deps/test/tdev/CMakeLists.txt new file mode 100644 index 0000000000..d173e8d24a --- /dev/null +++ b/deps/test/tdev/CMakeLists.txt @@ -0,0 +1,4 @@ +aux_source_directory(src TDEV_SRC) +add_executable(tdev ${TDEV_SRC}) + +target_include_directories(tdev PUBLIC inc) \ No newline at end of file diff --git a/deps/test/tdev/src/main.c b/deps/test/tdev/src/main.c new file mode 100644 index 0000000000..687b175a62 --- /dev/null +++ b/deps/test/tdev/src/main.c @@ -0,0 +1,87 @@ +#include +#include +#include +#include + +#define POINTER_SHIFT(ptr, s) ((void *)(((char *)ptr) + (s))) +#define POINTER_DISTANCE(pa, pb) ((char *)(pb) - (char *)(pa)) + +#define tPutA(buf, val) \ + ({ \ + memcpy(buf, &val, sizeof(val)); \ + POINTER_SHIFT(buf, sizeof(val)); \ + }) + +#define tPutB(buf, val) \ + ({ \ + ((uint8_t *)buf)[3] = ((val) >> 24) & 0xff; \ + ((uint8_t *)buf)[2] = ((val) >> 16) & 0xff; \ + ((uint8_t *)buf)[1] = ((val) >> 8) & 0xff; \ + ((uint8_t *)buf)[0] = (val)&0xff; \ + POINTER_SHIFT(buf, sizeof(val)); \ + }) + +#define tPutC(buf, val) \ + ({ \ + ((uint64_t *)buf)[0] = (val); \ + POINTER_SHIFT(buf, sizeof(val)); \ + }) + +typedef enum { A, B, C } T; + +static void func(T t) { + uint64_t val = 198; + char buf[1024]; + void * pBuf = buf; + + switch (t) { + case A: + for (size_t i = 0; i < 10 * 1024l * 1024l * 1024l; i++) { + pBuf = tPutA(pBuf, val); + if (POINTER_DISTANCE(buf, pBuf) == 1024) { + pBuf = buf; + } + } + break; + case B: + for (size_t i = 0; i < 10 * 1024l * 1024l * 1024l; i++) { + pBuf = tPutB(pBuf, val); + if (POINTER_DISTANCE(buf, pBuf) == 1024) { + pBuf = buf; + } + } + break; + case C: + for (size_t i = 0; i < 10 * 1024l * 1024l * 1024l; i++) { + pBuf = tPutC(pBuf, val); + if (POINTER_DISTANCE(buf, pBuf) == 1024) { + pBuf = buf; + } + } + break; + + default: + break; + } +} + +static uint64_t now() { + struct timeval tv; + gettimeofday(&tv, NULL); + + return tv.tv_sec * 1000000 + tv.tv_usec; +} + +int main(int argc, char const *argv[]) { + uint64_t t1 = now(); + func(A); + uint64_t t2 = now(); + printf("A: %ld\n", t2 - t1); + func(B); + uint64_t t3 = now(); + printf("B: %ld\n", t3 - t2); + func(C); + uint64_t t4 = now(); + printf("C: %ld\n", t4 - t3); + return 0; +} From 7fa1d26d7b680599cd2e6f20ca0824d39377d6da Mon Sep 17 00:00:00 2001 From: Hongze Cheng Date: Wed, 1 Dec 2021 11:54:44 +0800 Subject: [PATCH 32/41] fix memory leak --- source/dnode/vnode/meta/src/metaDB.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/source/dnode/vnode/meta/src/metaDB.c b/source/dnode/vnode/meta/src/metaDB.c index 1f511ca4dc..d1fb65d2ed 100644 --- a/source/dnode/vnode/meta/src/metaDB.c +++ b/source/dnode/vnode/meta/src/metaDB.c @@ -109,6 +109,7 @@ int metaSaveTableToDB(SMeta *pMeta, const STbCfg *pTbOptions) { // Save tbname -> uid to tbnameDB rocksdb_put(pMeta->pDB->nameDb, wopt, pTbOptions->name, strlen(pTbOptions->name), (char *)(&uid), sizeof(uid), &err); + rocksdb_writeoptions_disable_WAL(wopt, 1); // Save uid -> tb_obj to tbDB size = metaEncodeTbObjFromTbOptions(pTbOptions, pBuf, 1024); @@ -157,6 +158,7 @@ static void metaSaveSchemaDB(SMeta *pMeta, tb_uid_t uid, STSchema *pSchema) { char * err = NULL; rocksdb_writeoptions_t *wopt = rocksdb_writeoptions_create(); + rocksdb_writeoptions_disable_WAL(wopt, 1); metaGetSchemaDBKey(key, uid, schemaVersion(pSchema)); vsize = tdEncodeSchema((void **)(&ppBuf), pSchema); @@ -190,10 +192,12 @@ static int metaSaveMapDB(SMeta *pMeta, tb_uid_t suid, tb_uid_t uid) { memcpy(POINTER_SHIFT(nval, vlen), (void *)(&uid), sizeof(uid)); rocksdb_writeoptions_t *wopt = rocksdb_writeoptions_create(); + rocksdb_writeoptions_disable_WAL(wopt, 1); rocksdb_put(pMeta->pDB->mapDb, wopt, (char *)(&suid), sizeof(suid), nval, vlen + sizeof(uid), &err); rocksdb_writeoptions_destroy(wopt); + free(nval); return 0; } \ No newline at end of file From c57e586052ad174fae29b8fcc5d28a6a5d415c0b Mon Sep 17 00:00:00 2001 From: Hongze Cheng Date: Wed, 1 Dec 2021 13:10:26 +0800 Subject: [PATCH 33/41] integrate BDB --- CMakeLists.txt | 5 +++++ cmake/bdb_CMakeLists.txt.in | 13 +++++++++++++ cmake/cmake.options | 6 ++++++ 3 files changed, 24 insertions(+) create mode 100644 cmake/bdb_CMakeLists.txt.in diff --git a/CMakeLists.txt b/CMakeLists.txt index 46f0517fdc..6e47b8c24a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -45,6 +45,11 @@ if(${BUILD_WITH_ROCKSDB}) add_definitions(-DUSE_ROCKSDB) endif(${BUILD_WITH_ROCKSDB}) +## bdb +if(${BUILD_WITH_BDB}) + cat("${CMAKE_SUPPORT_DIR}/bdb_CMakeLists.txt.in" ${DEPS_TMP_FILE}) +endif(${BUILD_WITH_DBD}) + ## lucene if(${BUILD_WITH_LUCENE}) cat("${CMAKE_SUPPORT_DIR}/lucene_CMakeLists.txt.in" ${DEPS_TMP_FILE}) diff --git a/cmake/bdb_CMakeLists.txt.in b/cmake/bdb_CMakeLists.txt.in new file mode 100644 index 0000000000..102863006c --- /dev/null +++ b/cmake/bdb_CMakeLists.txt.in @@ -0,0 +1,13 @@ + +# bdb +ExternalProject_Add(bdb + GIT_REPOSITORY https://github.com/berkeleydb/libdb.git + GIT_TAG v5.3.28 + SOURCE_DIR "${CMAKE_SOURCE_DIR}/deps/bdb" + BINARY_DIR "${CMAKE_SOURCE_DIR}/deps/bdb" + #BUILD_IN_SOURCE TRUE + CONFIGURE_COMMAND "./dist/configure" + BUILD_COMMAND "make" + INSTALL_COMMAND "" + TEST_COMMAND "" +) \ No newline at end of file diff --git a/cmake/cmake.options b/cmake/cmake.options index 97fd1781e0..0a92d693e6 100644 --- a/cmake/cmake.options +++ b/cmake/cmake.options @@ -19,6 +19,12 @@ option( ON ) +option( + BUILD_WITH_BDB + "If build with BerkleyDB" + ON +) + option( BUILD_WITH_LUCENE "If build with lucene" From db9aa603ce154e2a0feab756bc3cec7a19d6eff5 Mon Sep 17 00:00:00 2001 From: Hongze Cheng Date: Wed, 1 Dec 2021 13:58:29 +0800 Subject: [PATCH 34/41] integrate berkeley db --- cmake/bdb_CMakeLists.txt.in | 2 +- cmake/sqlite_CMakeLists.txt.in | 13 +++++++++++++ deps/CMakeLists.txt | 10 ++++++++++ deps/test/CMakeLists.txt | 4 ++++ deps/test/bdb/CMakeLists.txt | 7 +++++++ deps/test/bdb/bdbTest.c | 7 +++++++ 6 files changed, 42 insertions(+), 1 deletion(-) create mode 100644 cmake/sqlite_CMakeLists.txt.in create mode 100644 deps/test/bdb/CMakeLists.txt create mode 100644 deps/test/bdb/bdbTest.c diff --git a/cmake/bdb_CMakeLists.txt.in b/cmake/bdb_CMakeLists.txt.in index 102863006c..ecb7b91d09 100644 --- a/cmake/bdb_CMakeLists.txt.in +++ b/cmake/bdb_CMakeLists.txt.in @@ -7,7 +7,7 @@ ExternalProject_Add(bdb BINARY_DIR "${CMAKE_SOURCE_DIR}/deps/bdb" #BUILD_IN_SOURCE TRUE CONFIGURE_COMMAND "./dist/configure" - BUILD_COMMAND "make" + BUILD_COMMAND "$(MAKE)" INSTALL_COMMAND "" TEST_COMMAND "" ) \ No newline at end of file diff --git a/cmake/sqlite_CMakeLists.txt.in b/cmake/sqlite_CMakeLists.txt.in new file mode 100644 index 0000000000..912e3e8805 --- /dev/null +++ b/cmake/sqlite_CMakeLists.txt.in @@ -0,0 +1,13 @@ + +# sqlite +ExternalProject_Add(sqlite + GIT_REPOSITORY https://github.com/sqlite/sqlite.git + GIT_TAG version-3.37.0 + SOURCE_DIR "${CMAKE_SOURCE_DIR}/deps/sqlite" + BINARY_DIR "${CMAKE_SOURCE_DIR}/deps/sqlite" + #BUILD_IN_SOURCE TRUE + CONFIGURE_COMMAND "" + BUILD_COMMAND "" + INSTALL_COMMAND "" + TEST_COMMAND "" +) \ No newline at end of file diff --git a/deps/CMakeLists.txt b/deps/CMakeLists.txt index e10ea9fa01..2166c79c18 100644 --- a/deps/CMakeLists.txt +++ b/deps/CMakeLists.txt @@ -80,6 +80,16 @@ if(${BUILD_WITH_NURAFT}) add_subdirectory(nuraft) endif(${BUILD_WITH_NURAFT}) +# BDB +if(${BUILD_WITH_BDB}) + add_library(bdb STATIC IMPORTED) + set_target_properties(bdb PROPERTIES + IMPORTED_LOCATION "${CMAKE_CURRENT_SOURCE_DIR}/bdb/libdb.a" + INTERFACE_INCLUDE_DIRECTORIES "${CMAKE_CURRENT_SOURCE_DIR}/bdb" + ) +endif(${BUILD_WITH_BDB}) + + # ================================================================================================ # DEPENDENCY TEST diff --git a/deps/test/CMakeLists.txt b/deps/test/CMakeLists.txt index 1c02ac1049..686362c37e 100644 --- a/deps/test/CMakeLists.txt +++ b/deps/test/CMakeLists.txt @@ -7,4 +7,8 @@ if(${BUILD_WITH_LUCENE}) add_subdirectory(lucene) endif(${BUILD_WITH_LUCENE}) +if(${BUILD_WITH_BDB}) + add_subdirectory(bdb) +endif(${BUILD_WITH_BDB}) + add_subdirectory(tdev) diff --git a/deps/test/bdb/CMakeLists.txt b/deps/test/bdb/CMakeLists.txt new file mode 100644 index 0000000000..62da0d4ac8 --- /dev/null +++ b/deps/test/bdb/CMakeLists.txt @@ -0,0 +1,7 @@ +add_executable(bdbTest "") +target_sources( + bdbTest PRIVATE + "bdbTest.c" +) + +target_link_libraries(bdbTest bdb) \ No newline at end of file diff --git a/deps/test/bdb/bdbTest.c b/deps/test/bdb/bdbTest.c new file mode 100644 index 0000000000..a3e94b6ec1 --- /dev/null +++ b/deps/test/bdb/bdbTest.c @@ -0,0 +1,7 @@ +#include +#include "db.h" + +int main(int argc, char const *argv[]) { + printf("Hello world!\n"); + return 0; +} From 755bc7a7454e257c6b86b3009d8b44926a01bcda Mon Sep 17 00:00:00 2001 From: Hongze Cheng Date: Wed, 1 Dec 2021 15:02:32 +0800 Subject: [PATCH 35/41] integrate sqlite --- CMakeLists.txt | 5 +++++ cmake/cmake.options | 6 ++++++ cmake/sqlite_CMakeLists.txt.in | 6 +++--- deps/CMakeLists.txt | 9 +++++++++ 4 files changed, 23 insertions(+), 3 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 6e47b8c24a..a9450220a7 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -50,6 +50,11 @@ if(${BUILD_WITH_BDB}) cat("${CMAKE_SUPPORT_DIR}/bdb_CMakeLists.txt.in" ${DEPS_TMP_FILE}) endif(${BUILD_WITH_DBD}) +## sqlite +if(${BUILD_WITH_SQLITE}) + cat("${CMAKE_SUPPORT_DIR}/sqlite_CMakeLists.txt.in" ${DEPS_TMP_FILE}) +endif(${BUILD_WITH_SQLITE}) + ## lucene if(${BUILD_WITH_LUCENE}) cat("${CMAKE_SUPPORT_DIR}/lucene_CMakeLists.txt.in" ${DEPS_TMP_FILE}) diff --git a/cmake/cmake.options b/cmake/cmake.options index 0a92d693e6..c8d6e33c1a 100644 --- a/cmake/cmake.options +++ b/cmake/cmake.options @@ -19,6 +19,12 @@ option( ON ) +option( + BUILD_WITH_SQLITE + "If build with sqlite" + ON +) + option( BUILD_WITH_BDB "If build with BerkleyDB" diff --git a/cmake/sqlite_CMakeLists.txt.in b/cmake/sqlite_CMakeLists.txt.in index 912e3e8805..6fd981aeff 100644 --- a/cmake/sqlite_CMakeLists.txt.in +++ b/cmake/sqlite_CMakeLists.txt.in @@ -2,12 +2,12 @@ # sqlite ExternalProject_Add(sqlite GIT_REPOSITORY https://github.com/sqlite/sqlite.git - GIT_TAG version-3.37.0 + GIT_TAG version-3.36.0 SOURCE_DIR "${CMAKE_SOURCE_DIR}/deps/sqlite" BINARY_DIR "${CMAKE_SOURCE_DIR}/deps/sqlite" #BUILD_IN_SOURCE TRUE - CONFIGURE_COMMAND "" - BUILD_COMMAND "" + CONFIGURE_COMMAND "./configure" + BUILD_COMMAND "$(MAKE)" INSTALL_COMMAND "" TEST_COMMAND "" ) \ No newline at end of file diff --git a/deps/CMakeLists.txt b/deps/CMakeLists.txt index 2166c79c18..00a6791b33 100644 --- a/deps/CMakeLists.txt +++ b/deps/CMakeLists.txt @@ -89,6 +89,15 @@ if(${BUILD_WITH_BDB}) ) endif(${BUILD_WITH_BDB}) +# SQLite +if(${BUILD_WITH_SQLITE}) + add_library(sqlite STATIC IMPORTED) + set_target_properties(bdb PROPERTIES + IMPORTED_LOCATION "${CMAKE_CURRENT_SOURCE_DIR}/sqlite/.lib/libsqlite3.a" + INTERFACE_INCLUDE_DIRECTORIES "${CMAKE_CURRENT_SOURCE_DIR}/sqlite" + ) +endif(${BUILD_WITH_SQLITE}) + # ================================================================================================ From 53f5b22b5441c7a6692d7aa892132addbc3d71f7 Mon Sep 17 00:00:00 2001 From: Hongze Cheng Date: Wed, 1 Dec 2021 15:06:32 +0800 Subject: [PATCH 36/41] make some change --- source/dnode/vnode/impl/test/vnodeApiTests.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/source/dnode/vnode/impl/test/vnodeApiTests.cpp b/source/dnode/vnode/impl/test/vnodeApiTests.cpp index 853524e511..493fe4448b 100644 --- a/source/dnode/vnode/impl/test/vnodeApiTests.cpp +++ b/source/dnode/vnode/impl/test/vnodeApiTests.cpp @@ -120,7 +120,7 @@ TEST(vnodeApiTest, vnodeOpen_vnodeClose_test) { { // Create some child tables - int ntables = 50000; + int ntables = 100000; int batch = 10; for (int i = 0; i < ntables / batch; i++) { SArray *pMsgs = (SArray *)taosArrayInit(batch, sizeof(SRpcMsg *)); @@ -153,7 +153,7 @@ TEST(vnodeApiTest, vnodeOpen_vnodeClose_test) { taosArrayDestroy(pMsgs); - std::cout << "the " << i << "th batch is created" << std::endl; + // std::cout << "the " << i << "th batch is created" << std::endl; } } From 881dcf0dbf29db082e3023dce9087dbf9d4a56ba Mon Sep 17 00:00:00 2001 From: Hongze Cheng Date: Wed, 1 Dec 2021 15:59:05 +0800 Subject: [PATCH 37/41] integrate SQLite --- deps/CMakeLists.txt | 4 ++-- deps/test/CMakeLists.txt | 4 ++++ deps/test/sqlite/CMakeLists.txt | 6 ++++++ deps/test/sqlite/sqliteTest.c | 6 ++++++ 4 files changed, 18 insertions(+), 2 deletions(-) create mode 100644 deps/test/sqlite/CMakeLists.txt create mode 100644 deps/test/sqlite/sqliteTest.c diff --git a/deps/CMakeLists.txt b/deps/CMakeLists.txt index 00a6791b33..08b1f113c1 100644 --- a/deps/CMakeLists.txt +++ b/deps/CMakeLists.txt @@ -92,8 +92,8 @@ endif(${BUILD_WITH_BDB}) # SQLite if(${BUILD_WITH_SQLITE}) add_library(sqlite STATIC IMPORTED) - set_target_properties(bdb PROPERTIES - IMPORTED_LOCATION "${CMAKE_CURRENT_SOURCE_DIR}/sqlite/.lib/libsqlite3.a" + set_target_properties(sqlite PROPERTIES + IMPORTED_LOCATION "${CMAKE_CURRENT_SOURCE_DIR}/sqlite/.libs/libsqlite3.a" INTERFACE_INCLUDE_DIRECTORIES "${CMAKE_CURRENT_SOURCE_DIR}/sqlite" ) endif(${BUILD_WITH_SQLITE}) diff --git a/deps/test/CMakeLists.txt b/deps/test/CMakeLists.txt index 686362c37e..0a333f604c 100644 --- a/deps/test/CMakeLists.txt +++ b/deps/test/CMakeLists.txt @@ -11,4 +11,8 @@ if(${BUILD_WITH_BDB}) add_subdirectory(bdb) endif(${BUILD_WITH_BDB}) +if(${BUILD_WITH_SQLITE}) + add_subdirectory(sqlite) +endif(${BUILD_WITH_SQLITE}) + add_subdirectory(tdev) diff --git a/deps/test/sqlite/CMakeLists.txt b/deps/test/sqlite/CMakeLists.txt new file mode 100644 index 0000000000..b679dd82d9 --- /dev/null +++ b/deps/test/sqlite/CMakeLists.txt @@ -0,0 +1,6 @@ +add_executable(sqliteTest "") +target_sources( + sqliteTest PRIVATE + "sqliteTest.c" +) +target_link_libraries(sqliteTest sqlite) \ No newline at end of file diff --git a/deps/test/sqlite/sqliteTest.c b/deps/test/sqlite/sqliteTest.c new file mode 100644 index 0000000000..ecc0d99ec8 --- /dev/null +++ b/deps/test/sqlite/sqliteTest.c @@ -0,0 +1,6 @@ +#include + +int main(int argc, char const *argv[]) { + printf("Hello world!\n"); + return 0; +} From e2ea6c51587e0d96c73c9270115680a9844a83f1 Mon Sep 17 00:00:00 2001 From: Hongze Cheng Date: Wed, 1 Dec 2021 17:10:40 +0800 Subject: [PATCH 38/41] test integrate SQLite --- cmake/cmake.options | 2 +- deps/CMakeLists.txt | 5 +++ deps/test/sqlite/sqliteTest.c | 58 ++++++++++++++++++++++++++++++++++- 3 files changed, 63 insertions(+), 2 deletions(-) diff --git a/cmake/cmake.options b/cmake/cmake.options index c8d6e33c1a..4c082fe79a 100644 --- a/cmake/cmake.options +++ b/cmake/cmake.options @@ -46,7 +46,7 @@ option( option( BUILD_DEPENDENCY_TESTS "If build dependency tests" - OFF + ON ) option( diff --git a/deps/CMakeLists.txt b/deps/CMakeLists.txt index 08b1f113c1..e8699a6b04 100644 --- a/deps/CMakeLists.txt +++ b/deps/CMakeLists.txt @@ -96,6 +96,11 @@ if(${BUILD_WITH_SQLITE}) IMPORTED_LOCATION "${CMAKE_CURRENT_SOURCE_DIR}/sqlite/.libs/libsqlite3.a" INTERFACE_INCLUDE_DIRECTORIES "${CMAKE_CURRENT_SOURCE_DIR}/sqlite" ) + target_link_libraries(sqlite + INTERFACE m + INTERFACE pthread + INTERFACE dl + ) endif(${BUILD_WITH_SQLITE}) diff --git a/deps/test/sqlite/sqliteTest.c b/deps/test/sqlite/sqliteTest.c index ecc0d99ec8..ae0829181c 100644 --- a/deps/test/sqlite/sqliteTest.c +++ b/deps/test/sqlite/sqliteTest.c @@ -1,6 +1,62 @@ #include +#include "sqlite3.h" int main(int argc, char const *argv[]) { - printf("Hello world!\n"); + sqlite3 *db; + char * err_msg = 0; + + int rc = sqlite3_open("test.db", &db); + + if (rc != SQLITE_OK) { + fprintf(stderr, "Cannot open database: %s\n", sqlite3_errmsg(db)); + sqlite3_close(db); + + return 1; + } + + char *sql = + "DROP TABLE IF EXISTS t;" + "CREATE TABLE t(id BIGINT);"; + + rc = sqlite3_exec(db, sql, 0, 0, &err_msg); + + if (rc != SQLITE_OK) { + fprintf(stderr, "SQL error: %s\n", err_msg); + + sqlite3_free(err_msg); + sqlite3_close(db); + + return 1; + } + + // Write a lot of data + int nrows = 100000; + int batch = 1000; + char tsql[1024]; + + int v = 0; + for (int k = 0; k < nrows / batch; k++) { + sqlite3_exec(db, "begin;", 0, 0, &err_msg); + + for (int i = 0; i < batch; i++) { + v++; + sprintf(tsql, "insert into t values (%d)", v); + rc = sqlite3_exec(db, tsql, 0, 0, &err_msg); + + if (rc != SQLITE_OK) { + fprintf(stderr, "SQL error: %s\n", err_msg); + + sqlite3_free(err_msg); + sqlite3_close(db); + + return 1; + } + } + + sqlite3_exec(db, "commit;", 0, 0, &err_msg); + } + + sqlite3_close(db); + return 0; } From a44b2423f2af0450f804cecf15689e740a7d9a50 Mon Sep 17 00:00:00 2001 From: Hongze Cheng Date: Wed, 1 Dec 2021 17:44:28 +0800 Subject: [PATCH 39/41] more --- deps/test/sqlite/sqliteTest.c | 40 +++++++++++++++++++---------------- 1 file changed, 22 insertions(+), 18 deletions(-) diff --git a/deps/test/sqlite/sqliteTest.c b/deps/test/sqlite/sqliteTest.c index ae0829181c..65fc826931 100644 --- a/deps/test/sqlite/sqliteTest.c +++ b/deps/test/sqlite/sqliteTest.c @@ -1,4 +1,6 @@ #include +#include + #include "sqlite3.h" int main(int argc, char const *argv[]) { @@ -29,31 +31,33 @@ int main(int argc, char const *argv[]) { return 1; } - // Write a lot of data - int nrows = 100000; - int batch = 1000; - char tsql[1024]; + { + // Write a lot of data + int nrows = 100000; + int batch = 1000; + char tsql[1024]; - int v = 0; - for (int k = 0; k < nrows / batch; k++) { - sqlite3_exec(db, "begin;", 0, 0, &err_msg); + int v = 0; + for (int k = 0; k < nrows / batch; k++) { + sqlite3_exec(db, "begin;", 0, 0, &err_msg); - for (int i = 0; i < batch; i++) { - v++; - sprintf(tsql, "insert into t values (%d)", v); - rc = sqlite3_exec(db, tsql, 0, 0, &err_msg); + for (int i = 0; i < batch; i++) { + v++; + sprintf(tsql, "insert into t values (%d)", v); + rc = sqlite3_exec(db, tsql, 0, 0, &err_msg); - if (rc != SQLITE_OK) { - fprintf(stderr, "SQL error: %s\n", err_msg); + if (rc != SQLITE_OK) { + fprintf(stderr, "SQL error: %s\n", err_msg); - sqlite3_free(err_msg); - sqlite3_close(db); + sqlite3_free(err_msg); + sqlite3_close(db); - return 1; + return 1; + } } - } - sqlite3_exec(db, "commit;", 0, 0, &err_msg); + sqlite3_exec(db, "commit;", 0, 0, &err_msg); + } } sqlite3_close(db); From dd436399cfa9dc43894b5aa467fcc756b775f441 Mon Sep 17 00:00:00 2001 From: Hongze Cheng Date: Thu, 2 Dec 2021 09:43:11 +0800 Subject: [PATCH 40/41] add bdb test --- deps/CMakeLists.txt | 3 +++ deps/test/bdb/bdbTest.c | 23 ++++++++++++++++++++++- 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/deps/CMakeLists.txt b/deps/CMakeLists.txt index e8699a6b04..afd606c403 100644 --- a/deps/CMakeLists.txt +++ b/deps/CMakeLists.txt @@ -87,6 +87,9 @@ if(${BUILD_WITH_BDB}) IMPORTED_LOCATION "${CMAKE_CURRENT_SOURCE_DIR}/bdb/libdb.a" INTERFACE_INCLUDE_DIRECTORIES "${CMAKE_CURRENT_SOURCE_DIR}/bdb" ) + target_link_libraries(bdb + INTERFACE pthread + ) endif(${BUILD_WITH_BDB}) # SQLite diff --git a/deps/test/bdb/bdbTest.c b/deps/test/bdb/bdbTest.c index a3e94b6ec1..ab80b33fd0 100644 --- a/deps/test/bdb/bdbTest.c +++ b/deps/test/bdb/bdbTest.c @@ -1,7 +1,28 @@ #include +#include + #include "db.h" +// refer: https://docs.oracle.com/cd/E17076_05/html/gsg/C/BerkeleyDB-Core-C-GSG.pdf + int main(int argc, char const *argv[]) { - printf("Hello world!\n"); + DB * db; + int ret; + uint32_t flags; + + ret = db_create(&db, NULL, 0); + if (ret != 0) { + exit(1); + } + + flags = DB_CREATE; + + ret = db->open(db, NULL, "test.db", NULL, DB_BTREE, flags, 0); + if (ret != 0) { + exit(1); + } + + db->close(db, 0); + return 0; } From 7dab7965c049ae45dcb9bceabc2ef81022009354 Mon Sep 17 00:00:00 2001 From: Hongze Cheng Date: Thu, 2 Dec 2021 11:37:04 +0800 Subject: [PATCH 41/41] this is what we need --- deps/test/sqlite/sqliteTest.c | 24 +++++++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) diff --git a/deps/test/sqlite/sqliteTest.c b/deps/test/sqlite/sqliteTest.c index 65fc826931..8766d94288 100644 --- a/deps/test/sqlite/sqliteTest.c +++ b/deps/test/sqlite/sqliteTest.c @@ -3,6 +3,20 @@ #include "sqlite3.h" +static void count_table(sqlite3 *db) { + int rc; + char * sql = "select * from t;"; + sqlite3_stmt *stmt = NULL; + int nrows = 0; + + rc = sqlite3_prepare_v2(db, sql, -1, &stmt, NULL); + while (SQLITE_ROW == sqlite3_step(stmt)) { + nrows++; + } + + printf("Number of rows: %d\n", nrows); +} + int main(int argc, char const *argv[]) { sqlite3 *db; char * err_msg = 0; @@ -33,11 +47,14 @@ int main(int argc, char const *argv[]) { { // Write a lot of data - int nrows = 100000; - int batch = 1000; + int nrows = 1000; + int batch = 100; char tsql[1024]; + int v = 0; + + // sqlite3_exec(db, "PRAGMA journal_mode=WAL;", 0, 0, &err_msg); + sqlite3_exec(db, "PRAGMA read_uncommitted=true;", 0, 0, &err_msg); - int v = 0; for (int k = 0; k < nrows / batch; k++) { sqlite3_exec(db, "begin;", 0, 0, &err_msg); @@ -56,6 +73,7 @@ int main(int argc, char const *argv[]) { } } + count_table(db); sqlite3_exec(db, "commit;", 0, 0, &err_msg); } }