From 49be2ab41d2c2d5f194783f56f394e8ac5f74c1e Mon Sep 17 00:00:00 2001 From: Hongze Cheng Date: Mon, 10 Jan 2022 11:43:58 +0000 Subject: [PATCH 1/8] more tkv --- source/libs/tkv/src/tDiskMgr.c | 27 +++++++++++++++++++++++++-- 1 file changed, 25 insertions(+), 2 deletions(-) diff --git a/source/libs/tkv/src/tDiskMgr.c b/source/libs/tkv/src/tDiskMgr.c index d759171f85..c8ce3c6c2a 100644 --- a/source/libs/tkv/src/tDiskMgr.c +++ b/source/libs/tkv/src/tDiskMgr.c @@ -25,12 +25,35 @@ struct SDiskMgr { #define PAGE_OFFSET(PGID, PGSIZE) ((PGID) * (PGSIZE)) int tdmOpen(SDiskMgr **ppDiskMgr, const char *fname, uint16_t pgsize) { - // TODO + SDiskMgr *pDiskMgr; + + pDiskMgr = malloc(sizeof(*pDiskMgr)); + if (pDiskMgr == NULL) { + return -1; + } + + pDiskMgr->fname = strdup(fname); + if (pDiskMgr->fname == NULL) { + free(pDiskMgr); + return -1; + } + pDiskMgr->pgsize = pgsize; + pDiskMgr->fd = open(fname, O_CREAT | O_RDWR, 0755); + if (pDiskMgr->fd < 0) { + free(pDiskMgr->fname); + free(pDiskMgr); + return -1; + } + + *ppDiskMgr = pDiskMgr; + return 0; } int tdmClose(SDiskMgr *pDiskMgr) { - // TODO + close(pDiskMgr->fd); + free(pDiskMgr->fname); + free(pDiskMgr); return 0; } From 358b5641aa4a20f164102bb736627765f5309839 Mon Sep 17 00:00:00 2001 From: Hongze Cheng Date: Mon, 10 Jan 2022 11:55:41 +0000 Subject: [PATCH 2/8] more tkv --- include/libs/tkv/tkv.h | 64 ---------------------------------- source/libs/tkv/inc/tDiskMgr.h | 11 +++--- source/libs/tkv/inc/tkv.h | 32 +++++++++++++++++ source/libs/tkv/src/tDiskMgr.c | 10 +++--- 4 files changed, 44 insertions(+), 73 deletions(-) delete mode 100644 include/libs/tkv/tkv.h create mode 100644 source/libs/tkv/inc/tkv.h diff --git a/include/libs/tkv/tkv.h b/include/libs/tkv/tkv.h deleted file mode 100644 index 98194f090c..0000000000 --- a/include/libs/tkv/tkv.h +++ /dev/null @@ -1,64 +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_TKV_H_ -#define _TD_TKV_H_ - -#if 0 -#include "os.h" - -#ifdef __cplusplus -extern "C" { -#endif - -// Types exported -typedef struct STkvDb STkvDb; -typedef struct STkvOpts STkvOpts; -typedef struct STkvCache STkvCache; -typedef struct STkvReadOpts STkvReadOpts; -typedef struct STkvWriteOpts STkvWriteOpts; - -// DB operations -STkvDb *tkvOpen(const STkvOpts *options, const char *path); -void tkvClose(STkvDb *db); -void tkvPut(STkvDb *db, const STkvWriteOpts *, const char *key, size_t keylen, const char *val, size_t vallen); -char * tkvGet(STkvDb *db, const STkvReadOpts *, const char *key, size_t keylen, size_t *vallen); -void tkvCommit(STkvDb *db); - -// DB options -STkvOpts *tkvOptsCreate(); -void tkvOptsDestroy(STkvOpts *); -void tkvOptionsSetCache(STkvOpts *, STkvCache *); -void tkvOptsSetCreateIfMissing(STkvOpts *, unsigned char); - -// DB cache -typedef enum { TKV_LRU_CACHE = 0, TKV_LFU_CACHE = 1 } ETkvCacheType; -STkvCache *tkvCacheCreate(size_t capacity, ETkvCacheType type); -void tkvCacheDestroy(STkvCache *); - -// STkvReadOpts -STkvReadOpts *tkvReadOptsCreate(); -void tkvReadOptsDestroy(STkvReadOpts *); - -// STkvWriteOpts -STkvWriteOpts *tkvWriteOptsCreate(); -void tkvWriteOptsDestroy(STkvWriteOpts *); - -#ifdef __cplusplus -} -#endif - -#endif -#endif /*_TD_TKV_H_*/ \ No newline at end of file diff --git a/source/libs/tkv/inc/tDiskMgr.h b/source/libs/tkv/inc/tDiskMgr.h index 03622284f4..65ab4d7a3d 100644 --- a/source/libs/tkv/inc/tDiskMgr.h +++ b/source/libs/tkv/inc/tDiskMgr.h @@ -26,11 +26,12 @@ extern "C" { typedef struct SDiskMgr SDiskMgr; -int tdmOpen(SDiskMgr **ppDiskMgr, const char *fname, uint16_t pgsize); -int tdmClose(SDiskMgr *pDiskMgr); -int tdmReadPage(SDiskMgr *pDiskMgr, pgid_t pgid, void *pData); -int tdmWritePage(SDiskMgr *pDiskMgr, pgid_t pgid, const void *pData); -int32_t tdmAllocPage(SDiskMgr *pDiskMgr); +int tdmOpen(SDiskMgr **ppDiskMgr, const char *fname, uint16_t pgsize); +int tdmClose(SDiskMgr *pDiskMgr); +int tdmReadPage(SDiskMgr *pDiskMgr, pgid_t pgid, void *pData); +int tdmWritePage(SDiskMgr *pDiskMgr, pgid_t pgid, const void *pData); +int tdmFlush(SDiskMgr *pDiskMgr); +pgid_t tdmAllocPage(SDiskMgr *pDiskMgr); #ifdef __cplusplus } diff --git a/source/libs/tkv/inc/tkv.h b/source/libs/tkv/inc/tkv.h new file mode 100644 index 0000000000..3a08906033 --- /dev/null +++ b/source/libs/tkv/inc/tkv.h @@ -0,0 +1,32 @@ +/* + * 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_TKV_H_ +#define _TD_TKV_H_ + +#ifdef __cplusplus +extern "C" { +#endif + +// SKey +typedef struct SKey { + void *bdata; +} SKey, SValue; + +#ifdef __cplusplus +} +#endif + +#endif /*_TD_TKV_H_*/ \ No newline at end of file diff --git a/source/libs/tkv/src/tDiskMgr.c b/source/libs/tkv/src/tDiskMgr.c index c8ce3c6c2a..5774555ae0 100644 --- a/source/libs/tkv/src/tDiskMgr.c +++ b/source/libs/tkv/src/tDiskMgr.c @@ -16,10 +16,10 @@ #include "tDiskMgr.h" struct SDiskMgr { - const char *fname; - uint16_t pgsize; - FileFd fd; - int32_t npgid; + char * fname; + uint16_t pgsize; + FileFd fd; + pgid_t npgid; }; #define PAGE_OFFSET(PGID, PGSIZE) ((PGID) * (PGSIZE)) @@ -69,4 +69,6 @@ int tdmWritePage(SDiskMgr *pDiskMgr, pgid_t pgid, const void *pData) { return 0; } +int tdmFlush(SDiskMgr *pDiskMgr) { return taosFsyncFile(pDiskMgr->fd); } + int32_t tdmAllocPage(SDiskMgr *pDiskMgr) { return pDiskMgr->npgid++; } \ No newline at end of file From dca02a8566bb931178894502bbe35a0168abe102 Mon Sep 17 00:00:00 2001 From: Hongze Cheng Date: Mon, 10 Jan 2022 12:40:15 +0000 Subject: [PATCH 3/8] more tkv --- source/libs/tkv/CMakeLists.txt | 1 + source/libs/tkv/inc/tkvBufPool.h | 39 ++++++++++++++ source/libs/tkv/inc/tkvDef.h | 3 ++ .../libs/tkv/inc/{tDiskMgr.h => tkvDiskMgr.h} | 14 ++--- source/libs/tkv/inc/{tPage.h => tkvPage.h} | 20 ++++--- source/libs/tkv/src/tDiskMgr.c | 18 +++---- source/libs/tkv/src/tkvBufPool.c | 54 +++++++++++++++++++ 7 files changed, 127 insertions(+), 22 deletions(-) create mode 100644 source/libs/tkv/inc/tkvBufPool.h rename source/libs/tkv/inc/{tDiskMgr.h => tkvDiskMgr.h} (67%) rename source/libs/tkv/inc/{tPage.h => tkvPage.h} (71%) create mode 100644 source/libs/tkv/src/tkvBufPool.c diff --git a/source/libs/tkv/CMakeLists.txt b/source/libs/tkv/CMakeLists.txt index 0620e12f55..ec3259d1f2 100644 --- a/source/libs/tkv/CMakeLists.txt +++ b/source/libs/tkv/CMakeLists.txt @@ -8,4 +8,5 @@ target_include_directories( target_link_libraries( tkv PUBLIC os + PUBLIC util ) \ No newline at end of file diff --git a/source/libs/tkv/inc/tkvBufPool.h b/source/libs/tkv/inc/tkvBufPool.h new file mode 100644 index 0000000000..ec8d177a9a --- /dev/null +++ b/source/libs/tkv/inc/tkvBufPool.h @@ -0,0 +1,39 @@ +/* + * 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_TKV_BUF_POOL_H_ +#define _TD_TKV_BUF_POOL_H_ + +#include "tkvPage.h" + +#ifdef __cplusplus +extern "C" { +#endif + +typedef struct STkvBufPool STkvBufPool; + +int tbpOpen(STkvBufPool **ppTkvBufPool); +int tbpClose(STkvBufPool *pTkvBufPool); +STkvPage *tbpNewPage(STkvBufPool *pTkvBufPool); +int tbpDelPage(STkvBufPool *pTkvBufPool); +STkvPage *tbpFetchPage(STkvBufPool *pTkvBufPool, pgid_t pgid); +int tbpUnpinPage(STkvBufPool *pTkvBufPool, pgid_t pgid); +void tbpFlushPages(STkvBufPool *pTkvBufPool); + +#ifdef __cplusplus +} +#endif + +#endif /*_TD_TKV_BUF_POOL_H_*/ \ No newline at end of file diff --git a/source/libs/tkv/inc/tkvDef.h b/source/libs/tkv/inc/tkvDef.h index 6f1072abd5..a80c395364 100644 --- a/source/libs/tkv/inc/tkvDef.h +++ b/source/libs/tkv/inc/tkvDef.h @@ -26,6 +26,9 @@ extern "C" { typedef int32_t pgid_t; #define TKV_IVLD_PGID ((pgid_t)-1) +// framd_id_t +typedef int32_t frame_id_t; + #ifdef __cplusplus } #endif diff --git a/source/libs/tkv/inc/tDiskMgr.h b/source/libs/tkv/inc/tkvDiskMgr.h similarity index 67% rename from source/libs/tkv/inc/tDiskMgr.h rename to source/libs/tkv/inc/tkvDiskMgr.h index 65ab4d7a3d..2ebe98ace2 100644 --- a/source/libs/tkv/inc/tDiskMgr.h +++ b/source/libs/tkv/inc/tkvDiskMgr.h @@ -24,14 +24,14 @@ extern "C" { #include "tkvDef.h" -typedef struct SDiskMgr SDiskMgr; +typedef struct STkvDiskMgr STkvDiskMgr; -int tdmOpen(SDiskMgr **ppDiskMgr, const char *fname, uint16_t pgsize); -int tdmClose(SDiskMgr *pDiskMgr); -int tdmReadPage(SDiskMgr *pDiskMgr, pgid_t pgid, void *pData); -int tdmWritePage(SDiskMgr *pDiskMgr, pgid_t pgid, const void *pData); -int tdmFlush(SDiskMgr *pDiskMgr); -pgid_t tdmAllocPage(SDiskMgr *pDiskMgr); +int tdmOpen(STkvDiskMgr **ppDiskMgr, const char *fname, uint16_t pgsize); +int tdmClose(STkvDiskMgr *pDiskMgr); +int tdmReadPage(STkvDiskMgr *pDiskMgr, pgid_t pgid, void *pData); +int tdmWritePage(STkvDiskMgr *pDiskMgr, pgid_t pgid, const void *pData); +int tdmFlush(STkvDiskMgr *pDiskMgr); +pgid_t tdmAllocPage(STkvDiskMgr *pDiskMgr); #ifdef __cplusplus } diff --git a/source/libs/tkv/inc/tPage.h b/source/libs/tkv/inc/tkvPage.h similarity index 71% rename from source/libs/tkv/inc/tPage.h rename to source/libs/tkv/inc/tkvPage.h index 0546f6184f..d596d215cd 100644 --- a/source/libs/tkv/inc/tPage.h +++ b/source/libs/tkv/inc/tkvPage.h @@ -17,22 +17,30 @@ #define _TD_TKV_PAGE_H_ #include "os.h" +#include "tkvDef.h" #ifdef __cplusplus extern "C" { #endif +typedef struct STkvPage { + pgid_t pgid; + int32_t pinCount; + bool idDirty; + char* pData; +} STkvPage; + typedef struct { uint16_t dbver; uint16_t pgsize; uint32_t cksm; -} SPgHdr; +} STkvPgHdr; -typedef struct { - SPgHdr chdr; - uint16_t used; // number of used slots - uint16_t loffset; // the offset of the starting location of the last slot used -} SSlottedPgHdr; +// typedef struct { +// SPgHdr chdr; +// uint16_t used; // number of used slots +// uint16_t loffset; // the offset of the starting location of the last slot used +// } SSlottedPgHdr; #ifdef __cplusplus } diff --git a/source/libs/tkv/src/tDiskMgr.c b/source/libs/tkv/src/tDiskMgr.c index 5774555ae0..fa8f6062d8 100644 --- a/source/libs/tkv/src/tDiskMgr.c +++ b/source/libs/tkv/src/tDiskMgr.c @@ -13,9 +13,9 @@ * along with this program. If not, see . */ -#include "tDiskMgr.h" +#include "tkvDiskMgr.h" -struct SDiskMgr { +struct STkvDiskMgr { char * fname; uint16_t pgsize; FileFd fd; @@ -24,8 +24,8 @@ struct SDiskMgr { #define PAGE_OFFSET(PGID, PGSIZE) ((PGID) * (PGSIZE)) -int tdmOpen(SDiskMgr **ppDiskMgr, const char *fname, uint16_t pgsize) { - SDiskMgr *pDiskMgr; +int tdmOpen(STkvDiskMgr **ppDiskMgr, const char *fname, uint16_t pgsize) { + STkvDiskMgr *pDiskMgr; pDiskMgr = malloc(sizeof(*pDiskMgr)); if (pDiskMgr == NULL) { @@ -50,25 +50,25 @@ int tdmOpen(SDiskMgr **ppDiskMgr, const char *fname, uint16_t pgsize) { return 0; } -int tdmClose(SDiskMgr *pDiskMgr) { +int tdmClose(STkvDiskMgr *pDiskMgr) { close(pDiskMgr->fd); free(pDiskMgr->fname); free(pDiskMgr); return 0; } -int tdmReadPage(SDiskMgr *pDiskMgr, pgid_t pgid, void *pData) { +int tdmReadPage(STkvDiskMgr *pDiskMgr, pgid_t pgid, void *pData) { taosLSeekFile(pDiskMgr->fd, PAGE_OFFSET(pgid, pDiskMgr->pgsize), SEEK_SET); taosReadFile(pDiskMgr->fd, pData, pDiskMgr->pgsize); return 0; } -int tdmWritePage(SDiskMgr *pDiskMgr, pgid_t pgid, const void *pData) { +int tdmWritePage(STkvDiskMgr *pDiskMgr, pgid_t pgid, const void *pData) { taosLSeekFile(pDiskMgr->fd, PAGE_OFFSET(pgid, pDiskMgr->pgsize), SEEK_SET); taosWriteFile(pDiskMgr->fd, pData, pDiskMgr->pgsize); return 0; } -int tdmFlush(SDiskMgr *pDiskMgr) { return taosFsyncFile(pDiskMgr->fd); } +int tdmFlush(STkvDiskMgr *pDiskMgr) { return taosFsyncFile(pDiskMgr->fd); } -int32_t tdmAllocPage(SDiskMgr *pDiskMgr) { return pDiskMgr->npgid++; } \ No newline at end of file +int32_t tdmAllocPage(STkvDiskMgr *pDiskMgr) { return pDiskMgr->npgid++; } \ No newline at end of file diff --git a/source/libs/tkv/src/tkvBufPool.c b/source/libs/tkv/src/tkvBufPool.c new file mode 100644 index 0000000000..86bfa0ba3e --- /dev/null +++ b/source/libs/tkv/src/tkvBufPool.c @@ -0,0 +1,54 @@ +/* + * Copyright (c) 2019 TAOS Data, Inc. + * + * This program is free software: you can use, redistribute, and/or modify + * it under the terms of the GNU Affero General Public License, version 3 + * or later ("AGPL"), as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +#include "thash.h" +#include "tlist.h" + +#include "tkvBufPool.h" +#include "tkvDiskMgr.h" +#include "tkvPage.h" + +struct SFrameIdWrapper { + TD_SLIST_NODE(SFrameIdWrapper); + frame_id_t id; +}; + +struct STkvBufPool { + STkvPage* pages; + STkvDiskMgr* pDiskMgr; + SHashObj* pgTb; // page_id_t --> frame_id_t + TD_SLIST(SFrameIdWrapper) freeList; + pthread_mutex_t mutex; +}; + +typedef struct STkvLRUReplacer { +} STkvLRUReplacer; + +typedef struct STkvLFUReplacer { +} STkvLFUReplacer; + +typedef struct STkvCLKReplacer { +} STkvCLKReplacer; + +typedef enum { TKV_LRU_REPLACER = 0, TKV_LFU_REPLACER, TVK_CLK_REPLACER } tkv_replacer_t; + +typedef struct STkvReplacer { + tkv_replacer_t type; + union { + STkvLRUReplacer lruRep; + STkvLFUReplacer lfuRep; + STkvCLKReplacer clkRep; + }; +} STkvReplacer; \ No newline at end of file From 3513390fb8828d3d9cfa443303891b0699bd1b58 Mon Sep 17 00:00:00 2001 From: Hongze Cheng Date: Mon, 10 Jan 2022 12:51:40 +0000 Subject: [PATCH 4/8] just have a try --- include/util/tarray.h | 32 ++++++++++++++++++++++---------- 1 file changed, 22 insertions(+), 10 deletions(-) diff --git a/include/util/tarray.h b/include/util/tarray.h index f7c72add01..6d6120a49b 100644 --- a/include/util/tarray.h +++ b/include/util/tarray.h @@ -23,10 +23,23 @@ extern "C" { #include "os.h" #include "talgo.h" +#if 0 +#define TARRAY(TYPE) \ + struct { \ + int32_t tarray_size_; \ + int32_t tarray_neles_; \ + struct TYPE* td_array_data_; \ + } + +#define TARRAY_SIZE(ARRAY) (ARRAY)->tarray_size_ +#define TARRAY_NELES(ARRAY) (ARRAY)->tarray_neles_ +#define TARRAY_ELE_AT(ARRAY, IDX) ((ARRAY)->td_array_data_ + idx) +#endif + #define TARRAY_MIN_SIZE 8 #define TARRAY_GET_ELEM(array, index) ((void*)((char*)((array)->pData) + (index) * (array)->elemSize)) -#define TARRAY_ELEM_IDX(array, ele) (POINTER_DISTANCE(ele, (array)->pData) / (array)->elemSize) -#define TARRAY_GET_START(array) ((array)->pData) +#define TARRAY_ELEM_IDX(array, ele) (POINTER_DISTANCE(ele, (array)->pData) / (array)->elemSize) +#define TARRAY_GET_START(array) ((array)->pData) typedef struct SArray { size_t size; @@ -57,7 +70,7 @@ int32_t taosArrayEnsureCap(SArray* pArray, size_t tsize); * @param nEles * @return */ -void *taosArrayAddBatch(SArray *pArray, const void *pData, int nEles); +void* taosArrayAddBatch(SArray* pArray, const void* pData, int nEles); /** * @@ -65,7 +78,7 @@ void *taosArrayAddBatch(SArray *pArray, const void *pData, int nEles); * @param pData position array list * @param numOfElems the number of removed position */ -void taosArrayRemoveBatch(SArray *pArray, const int32_t* pData, int32_t numOfElems); +void taosArrayRemoveBatch(SArray* pArray, const int32_t* pData, int32_t numOfElems); /** * @@ -73,7 +86,7 @@ void taosArrayRemoveBatch(SArray *pArray, const int32_t* pData, int32_t numOfEle * @param comparFn * @param fp */ -void taosArrayRemoveDuplicate(SArray *pArray, __compar_fn_t comparFn, void (*fp)(void*)); +void taosArrayRemoveDuplicate(SArray* pArray, __compar_fn_t comparFn, void (*fp)(void*)); /** * add all element from the source array list into the destination @@ -242,19 +255,18 @@ int32_t taosArraySearchIdx(const SArray* pArray, const void* key, __compar_fn_t */ char* taosArraySearchString(const SArray* pArray, const char* key, __compar_fn_t comparFn, int flags); - /** * sort the pointer data in the array * @param pArray - * @param compar - * @param param + * @param compar + * @param param * @return */ -void taosArraySortPWithExt(SArray* pArray, __ext_compar_fn_t fn, const void *param); +void taosArraySortPWithExt(SArray* pArray, __ext_compar_fn_t fn, const void* param); #ifdef __cplusplus } #endif -#endif /*_TD_UTIL_ARRAY_H*/ +#endif /*_TD_UTIL_ARRAY_H*/ From 3d1c8dcb7d1cc872c9e54a63b0f058719e21263f Mon Sep 17 00:00:00 2001 From: Hongze Cheng Date: Tue, 11 Jan 2022 06:55:44 +0000 Subject: [PATCH 5/8] more --- source/libs/tkv/inc/tkvDef.h | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/source/libs/tkv/inc/tkvDef.h b/source/libs/tkv/inc/tkvDef.h index a80c395364..cd418019be 100644 --- a/source/libs/tkv/inc/tkvDef.h +++ b/source/libs/tkv/inc/tkvDef.h @@ -29,6 +29,12 @@ typedef int32_t pgid_t; // framd_id_t typedef int32_t frame_id_t; +// pgsize_t +typedef int32_t pgsize_t; +#define TKV_MIN_PGSIZE 512 +#define TKV_MAX_PGSIZE 16384 +#define TKV_IS_PGSIZE_VLD(s) (((s) >= TKV_MIN_PGSIZE) && (TKV_MAX_PGSIZE <= TKV_MAX_PGSIZE)) + #ifdef __cplusplus } #endif From e456c6391aac090f143fabe0eeaf5cd6e304024c Mon Sep 17 00:00:00 2001 From: Hongze Cheng Date: Tue, 11 Jan 2022 07:12:38 +0000 Subject: [PATCH 6/8] refact --- source/libs/tkv/CMakeLists.txt | 9 +++++++-- source/libs/tkv/inc/tkv.h | 13 ++++++++++--- source/libs/tkv/{ => src}/inc/tkvBufPool.h | 0 source/libs/tkv/{ => src}/inc/tkvDef.h | 0 source/libs/tkv/{ => src}/inc/tkvDiskMgr.h | 0 source/libs/tkv/{ => src}/inc/tkvPage.h | 0 6 files changed, 17 insertions(+), 5 deletions(-) rename source/libs/tkv/{ => src}/inc/tkvBufPool.h (100%) rename source/libs/tkv/{ => src}/inc/tkvDef.h (100%) rename source/libs/tkv/{ => src}/inc/tkvDiskMgr.h (100%) rename source/libs/tkv/{ => src}/inc/tkvPage.h (100%) diff --git a/source/libs/tkv/CMakeLists.txt b/source/libs/tkv/CMakeLists.txt index ec3259d1f2..fec3f37cd5 100644 --- a/source/libs/tkv/CMakeLists.txt +++ b/source/libs/tkv/CMakeLists.txt @@ -1,9 +1,14 @@ aux_source_directory(src TKV_SRC) add_library(tkv STATIC ${TKV_SRC}) +# target_include_directories( +# tkv +# PUBLIC "${CMAKE_SOURCE_DIR}/include/libs/tkv" +# PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/inc" +# ) target_include_directories( tkv - PUBLIC "${CMAKE_SOURCE_DIR}/include/libs/tkv" - PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/inc" + PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/inc" + PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/src/inc" ) target_link_libraries( tkv diff --git a/source/libs/tkv/inc/tkv.h b/source/libs/tkv/inc/tkv.h index 3a08906033..00534d2827 100644 --- a/source/libs/tkv/inc/tkv.h +++ b/source/libs/tkv/inc/tkv.h @@ -16,14 +16,21 @@ #ifndef _TD_TKV_H_ #define _TD_TKV_H_ +#include "os.h" + #ifdef __cplusplus extern "C" { #endif +// Forward declaration +typedef struct TDB TDB; +typedef struct TDB_ENV TDB_ENV; + // SKey -typedef struct SKey { - void *bdata; -} SKey, SValue; +typedef struct { + void * bdata; + uint32_t size; +} TDB_KEY, TDB_VALUE; #ifdef __cplusplus } diff --git a/source/libs/tkv/inc/tkvBufPool.h b/source/libs/tkv/src/inc/tkvBufPool.h similarity index 100% rename from source/libs/tkv/inc/tkvBufPool.h rename to source/libs/tkv/src/inc/tkvBufPool.h diff --git a/source/libs/tkv/inc/tkvDef.h b/source/libs/tkv/src/inc/tkvDef.h similarity index 100% rename from source/libs/tkv/inc/tkvDef.h rename to source/libs/tkv/src/inc/tkvDef.h diff --git a/source/libs/tkv/inc/tkvDiskMgr.h b/source/libs/tkv/src/inc/tkvDiskMgr.h similarity index 100% rename from source/libs/tkv/inc/tkvDiskMgr.h rename to source/libs/tkv/src/inc/tkvDiskMgr.h diff --git a/source/libs/tkv/inc/tkvPage.h b/source/libs/tkv/src/inc/tkvPage.h similarity index 100% rename from source/libs/tkv/inc/tkvPage.h rename to source/libs/tkv/src/inc/tkvPage.h From a5df21beab302198b655ecd6951ac0bbf5505ead Mon Sep 17 00:00:00 2001 From: Hongze Cheng Date: Wed, 12 Jan 2022 01:26:00 +0000 Subject: [PATCH 7/8] more --- source/libs/tkv/src/inc/tkvDB.h | 31 +++++++++++++++++++++++++++++++ source/libs/tkv/src/inc/tkvEnv.h | 31 +++++++++++++++++++++++++++++++ 2 files changed, 62 insertions(+) create mode 100644 source/libs/tkv/src/inc/tkvDB.h create mode 100644 source/libs/tkv/src/inc/tkvEnv.h diff --git a/source/libs/tkv/src/inc/tkvDB.h b/source/libs/tkv/src/inc/tkvDB.h new file mode 100644 index 0000000000..1a45702540 --- /dev/null +++ b/source/libs/tkv/src/inc/tkvDB.h @@ -0,0 +1,31 @@ +/* + * 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_TKV_DB_H_ +#define _TD_TKV_DB_H_ + +#ifdef __cplusplus +extern "C" { +#endif + +struct TDB { + // TODO +}; + +#ifdef __cplusplus +} +#endif + +#endif /*_TD_TKV_DB_H_*/ \ No newline at end of file diff --git a/source/libs/tkv/src/inc/tkvEnv.h b/source/libs/tkv/src/inc/tkvEnv.h new file mode 100644 index 0000000000..eba442e5a5 --- /dev/null +++ b/source/libs/tkv/src/inc/tkvEnv.h @@ -0,0 +1,31 @@ +/* + * 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_TKV_ENV_H_ +#define _TD_TKV_ENV_H_ + +#ifdef __cplusplus +extern "C" { +#endif + +struct TDB_ENV { + char *homeDir; +}; + +#ifdef __cplusplus +} +#endif + +#endif /*_TD_TKV_ENV_H_*/ \ No newline at end of file From 8b5e6b689555f586b43b21b5d4169f0476fe79f9 Mon Sep 17 00:00:00 2001 From: Hongze Cheng Date: Wed, 12 Jan 2022 01:55:37 +0000 Subject: [PATCH 8/8] fix memory leakage --- source/dnode/vnode/impl/src/vnodeWrite.c | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/source/dnode/vnode/impl/src/vnodeWrite.c b/source/dnode/vnode/impl/src/vnodeWrite.c index ddcb93863a..185487757f 100644 --- a/source/dnode/vnode/impl/src/vnodeWrite.c +++ b/source/dnode/vnode/impl/src/vnodeWrite.c @@ -83,8 +83,18 @@ int vnodeApplyWMsg(SVnode *pVnode, SRpcMsg *pMsg, SRpcMsg **pRsp) { if (metaCreateTable(pVnode->pMeta, pCreateTbReq) < 0) { // TODO: handle error } + if (pCreateTbReq->type == TD_SUPER_TABLE) { + free(pCreateTbReq->stbCfg.pSchema); + free(pCreateTbReq->stbCfg.pTagSchema); + } else if (pCreateTbReq->type == TD_CHILD_TABLE) { + free(pCreateTbReq->ctbCfg.pTag); + } else { + free(pCreateTbReq->ntbCfg.pSchema); + } } - + taosArrayDestroy(vCreateTbBatchReq.pArray); + break; + case TDMT_VND_DROP_STB: case TDMT_VND_DROP_TABLE: // if (metaDropTable(pVnode->pMeta, vReq.dtReq.uid) < 0) {