From 140e2abc834fe076e9858dcc078800808363016a Mon Sep 17 00:00:00 2001 From: Hongze Cheng Date: Tue, 9 Nov 2021 17:09:06 +0800 Subject: [PATCH] refact --- include/server/vnode/vnode.h | 14 +++-- .../dnode/vnode/impl/src/vnodeMemAllocator.c | 55 ++++++++++++++++++- 2 files changed, 64 insertions(+), 5 deletions(-) diff --git a/include/server/vnode/vnode.h b/include/server/vnode/vnode.h index f787b07b00..29e14a673a 100644 --- a/include/server/vnode/vnode.h +++ b/include/server/vnode/vnode.h @@ -55,25 +55,31 @@ struct SVnodeOptions { /** * @brief time to live of tables in this vnode * in SECONDS - * + * */ uint32_t ttl; /** * @brief if time-series requests eventual consistency - * + * */ bool isWeak; + /** + * @brief if the allocator is heap allcator or arena allocator + * + */ + bool isHeapAllocator; + /** * @brief TSDB options - * + * */ STsdbOptions tsdbOptions; /** * @brief META options - * + * */ SMetaOptions metaOptions; // STqOptions tqOptions; // TODO diff --git a/source/dnode/vnode/impl/src/vnodeMemAllocator.c b/source/dnode/vnode/impl/src/vnodeMemAllocator.c index 6dea4a4e57..f3e81f38ec 100644 --- a/source/dnode/vnode/impl/src/vnodeMemAllocator.c +++ b/source/dnode/vnode/impl/src/vnodeMemAllocator.c @@ -11,4 +11,57 @@ * * 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" + +/* ------------------------ Heap Allocator ------------------------ */ +typedef struct { + uint64_t tsize; + uint64_t used; +} SVHeapAllocator; + +SMemAllocator *vhaCreate(uint64_t size) { + SMemAllocator *pma; + + pma = (SMemAllocator *)calloc(1, sizeof(*pma) + sizeof(SVHeapAllocator)); + if (pma == NULL) { + return NULL; + } + + pma->impl = POINTER_SHIFT(pma, sizeof(*pma)); + + /* TODO */ + return NULL; +} + +void vhaDestroy(SMemAllocator *pma) { /* TODO */ +} + +static void *vhaMalloc(SMemAllocator *pma, uint64_t size) { + SVHeapAllocator *pvha = (SVHeapAllocator *)(pma->impl); + /* TODO */ + return NULL; +} + +static void *vhaCalloc(SMemAllocator *pma, size_t nmemb, uint64_t size) { + // todo + return NULL; +} + +static void *vhaRealloc(SMemAllocator *pma, void *ptr, uint64_t size) { + /* TODO */ + return NULL; +} + +static void vhaFree(SMemAllocator *pma, void *ptr) { /* TODO */ +} + +static uint64_t vhaUsage(SMemAllocator *pma) { + /* TODO */ + return 0; +} + +/* ------------------------ Arena Allocator ------------------------ */ +typedef struct { +} SVArenaAllocator; \ No newline at end of file -- GitLab