From 9c188c53ff9ae6b968a8669407fc9129593b72f2 Mon Sep 17 00:00:00 2001 From: Hongze Cheng Date: Thu, 14 Oct 2021 13:28:18 +0800 Subject: [PATCH] refact --- include/util/amalloc.h | 25 +++++++------- source/server/vnode/tsdb/inc/tsdbMemTable.h | 13 ++++--- source/server/vnode/tsdb/inc/tsdbWriteBatch.h | 34 +++++++++++++++++++ source/server/vnode/tsdb/src/tsdbMemTable.c | 15 +++++++- 4 files changed, 70 insertions(+), 17 deletions(-) create mode 100644 source/server/vnode/tsdb/inc/tsdbWriteBatch.h diff --git a/include/util/amalloc.h b/include/util/amalloc.h index 6d2869f719..938e1caa4c 100644 --- a/include/util/amalloc.h +++ b/include/util/amalloc.h @@ -22,27 +22,28 @@ extern "C" { #endif +#define AMALLOC_APIS \ + void *(*malloc)(void *, size_t size); \ + void *(*calloc)(void *, size_t nmemb, size_t size); \ + void *(*realloc)(void *, size_t size); \ + void (*free)(void *ptr); + // Interfaces to implement typedef struct { - void *(*malloc)(void *, size_t size); - void *(*calloc)(void *, size_t nmemb, size_t size); - void (*free)(void *ptr, size_t size); // Do we need to set size in the allocated memory? - void *(*realloc)(void *ptr, size_t size); + AMALLOC_APIS } SMemAllocatorIf; typedef struct { - void * impl; - SMemAllocatorIf interface; + void *impl; + AMALLOC_APIS } SMemAllocator; -#define amalloc(allocator, size) \ - ((allocator) ? (*((allocator)->interface.malloc))((allocator)->impl, (size)) : malloc(size)) +#define amalloc(allocator, size) ((allocator) ? (*((allocator)->malloc))((allocator)->impl, (size)) : malloc(size)) #define acalloc(allocator, nmemb, size) \ - ((allocator) ? (*((allocator)->interface.calloc))((allocator)->impl, (nmemb), (size)) : calloc((nmemb), (size))) + ((allocator) ? (*((allocator)->calloc))((allocator)->impl, (nmemb), (size)) : calloc((nmemb), (size))) #define arealloc(allocator, ptr, size) \ - ((allocator) ? (*((allocator)->interface.realloc))((allocator)->impl, (ptr), (size)) : realloc((ptr), (size))) -#define afree(allocator, ptr, size) \ - ((allocator) ? (*((allocator)->interface.free))((allocator)->impl, (ptr), (size)) : free(ptr)) + ((allocator) ? (*((allocator)->realloc))((allocator)->impl, (ptr), (size)) : realloc((ptr), (size))) +#define afree(allocator, ptr, size) ((allocator) ? (*((allocator)->free))((allocator)->impl, (ptr), (size)) : free(ptr)) #ifdef __cplusplus } diff --git a/source/server/vnode/tsdb/inc/tsdbMemTable.h b/source/server/vnode/tsdb/inc/tsdbMemTable.h index b13c0579ce..5d1dcfcac7 100644 --- a/source/server/vnode/tsdb/inc/tsdbMemTable.h +++ b/source/server/vnode/tsdb/inc/tsdbMemTable.h @@ -18,6 +18,7 @@ #include "tdef.h" #include "thash.h" +#include "amalloc.h" #ifdef __cplusplus extern "C" { @@ -25,12 +26,16 @@ extern "C" { typedef struct STsdbMemTable STsdbMemTable; +STsdbMemTable *tsdbMemTableCreate(SMemAllocator *); +void tsdbMemTableDestroy(STsdbMemTable *); +int tsdbMemTableWriteBatch(STsdbMemTable *pTsdbMemTable, void *batch); + /* --------------------- For compile and test only --------------------- */ struct STsdbMemTable { - TSKEY minKey; - TSKEY maxKey; - SHashObj *tData; // uid --> SSkipList - void * mallocator; + TSKEY minKey; + TSKEY maxKey; + SHashObj * tData; // uid --> SSkipList + SMemAllocator *ma; T_REF_DECLARE() }; diff --git a/source/server/vnode/tsdb/inc/tsdbWriteBatch.h b/source/server/vnode/tsdb/inc/tsdbWriteBatch.h new file mode 100644 index 0000000000..f6b761f6a5 --- /dev/null +++ b/source/server/vnode/tsdb/inc/tsdbWriteBatch.h @@ -0,0 +1,34 @@ +/* + * 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_TSDB_WRITE_BATCH_H_ +#define _TD_TSDB_WRITE_BATCH_H_ + +#ifdef __cplusplus +extern "C" { +#endif + +typedef struct STsdbWriteBatch STsdbWriteBatch; + +/* ------------------------- ------------------------- */ +struct STsdbWriteBatch { + // TODO +}; + +#ifdef __cplusplus +} +#endif + +#endif /*_TD_TSDB_WRITE_BATCH_H_*/ \ No newline at end of file diff --git a/source/server/vnode/tsdb/src/tsdbMemTable.c b/source/server/vnode/tsdb/src/tsdbMemTable.c index 91700a37d6..9fd815155f 100644 --- a/source/server/vnode/tsdb/src/tsdbMemTable.c +++ b/source/server/vnode/tsdb/src/tsdbMemTable.c @@ -15,7 +15,7 @@ #include "tsdbMemTable.h" -STsdbMemTable *tsdbMemTableCreate(void *mallocator) { +STsdbMemTable *tsdbMemTableCreate(SMemAllocator *ma) { STsdbMemTable *pTsdbMemTable = NULL; pTsdbMemTable = (STsdbMemTable *)malloc(sizeof(*pTsdbMemTable)); @@ -24,6 +24,13 @@ STsdbMemTable *tsdbMemTableCreate(void *mallocator) { } // TODO + pTsdbMemTable->minKey = TSKEY_INITIAL_VAL; + pTsdbMemTable->maxKey = TSKEY_INITIAL_VAL; + pTsdbMemTable->ma = ma; + pTsdbMemTable->tData = taosHashInit(1024, taosIntHash_64, true /* TODO */, HASH_NO_LOCK); + if (pTsdbMemTable->tData == NULL) { + // TODO + } return pTsdbMemTable; } @@ -33,4 +40,10 @@ void tsdbMemTableDestroy(STsdbMemTable *pTsdbMemTable) { // TODO free(pTsdbMemTable); } +} + +int tsdbMemTableWriteBatch(STsdbMemTable *pTsdbMemTable, void *batch) { + // TODO + + return 0; } \ No newline at end of file -- GitLab