Merge branch 'feature/vnode' into 3.0
This commit is contained in:
commit
81488ee35c
|
@ -491,7 +491,7 @@ EXTRACT_PACKAGE = NO
|
||||||
# included in the documentation.
|
# included in the documentation.
|
||||||
# The default value is: NO.
|
# The default value is: NO.
|
||||||
|
|
||||||
EXTRACT_STATIC = NO
|
EXTRACT_STATIC = YES
|
||||||
|
|
||||||
# If the EXTRACT_LOCAL_CLASSES tag is set to YES, classes (and structs) defined
|
# If the EXTRACT_LOCAL_CLASSES tag is set to YES, classes (and structs) defined
|
||||||
# locally in source files will be included in the documentation. If set to NO,
|
# locally in source files will be included in the documentation. If set to NO,
|
||||||
|
@ -1526,7 +1526,7 @@ ECLIPSE_DOC_ID = org.doxygen.Project
|
||||||
# The default value is: NO.
|
# The default value is: NO.
|
||||||
# This tag requires that the tag GENERATE_HTML is set to YES.
|
# This tag requires that the tag GENERATE_HTML is set to YES.
|
||||||
|
|
||||||
DISABLE_INDEX = NO
|
DISABLE_INDEX = YES
|
||||||
|
|
||||||
# The GENERATE_TREEVIEW tag is used to specify whether a tree-like index
|
# The GENERATE_TREEVIEW tag is used to specify whether a tree-like index
|
||||||
# structure should be generated to display hierarchical information. If the tag
|
# structure should be generated to display hierarchical information. If the tag
|
||||||
|
@ -1543,7 +1543,7 @@ DISABLE_INDEX = NO
|
||||||
# The default value is: NO.
|
# The default value is: NO.
|
||||||
# This tag requires that the tag GENERATE_HTML is set to YES.
|
# This tag requires that the tag GENERATE_HTML is set to YES.
|
||||||
|
|
||||||
GENERATE_TREEVIEW = NO
|
GENERATE_TREEVIEW = YES
|
||||||
|
|
||||||
# The ENUM_VALUES_PER_LINE tag can be used to set the number of enum values that
|
# The ENUM_VALUES_PER_LINE tag can be used to set the number of enum values that
|
||||||
# doxygen will group on one line in the generated HTML documentation.
|
# doxygen will group on one line in the generated HTML documentation.
|
||||||
|
@ -2416,7 +2416,7 @@ INCLUDED_BY_GRAPH = YES
|
||||||
# The default value is: NO.
|
# The default value is: NO.
|
||||||
# This tag requires that the tag HAVE_DOT is set to YES.
|
# This tag requires that the tag HAVE_DOT is set to YES.
|
||||||
|
|
||||||
CALL_GRAPH = NO
|
CALL_GRAPH = YES
|
||||||
|
|
||||||
# If the CALLER_GRAPH tag is set to YES then doxygen will generate a caller
|
# If the CALLER_GRAPH tag is set to YES then doxygen will generate a caller
|
||||||
# dependency graph for every global function or class method.
|
# dependency graph for every global function or class method.
|
||||||
|
@ -2428,7 +2428,7 @@ CALL_GRAPH = NO
|
||||||
# The default value is: NO.
|
# The default value is: NO.
|
||||||
# This tag requires that the tag HAVE_DOT is set to YES.
|
# This tag requires that the tag HAVE_DOT is set to YES.
|
||||||
|
|
||||||
CALLER_GRAPH = NO
|
CALLER_GRAPH = YES
|
||||||
|
|
||||||
# If the GRAPHICAL_HIERARCHY tag is set to YES then doxygen will graphical
|
# If the GRAPHICAL_HIERARCHY tag is set to YES then doxygen will graphical
|
||||||
# hierarchy of all classes instead of a textual one.
|
# hierarchy of all classes instead of a textual one.
|
||||||
|
|
|
@ -28,24 +28,24 @@ typedef struct SMetaOptions SMetaOptions;
|
||||||
typedef struct STbOptions STbOptions;
|
typedef struct STbOptions STbOptions;
|
||||||
|
|
||||||
// SMeta operations
|
// SMeta operations
|
||||||
SMeta *metaOpen(const char *path, const SMetaOptions *);
|
SMeta *metaOpen(const char *path, const SMetaOptions *pOptions);
|
||||||
void metaClose(SMeta *);
|
void metaClose(SMeta *pMeta);
|
||||||
void metaRemove(const char *path);
|
void metaRemove(const char *path);
|
||||||
int metaCreateTable(SMeta *pMeta, const STbOptions *);
|
int metaCreateTable(SMeta *pMeta, const STbOptions *pTbOptions);
|
||||||
int metaDropTable(SMeta *pMeta, tb_uid_t uid);
|
int metaDropTable(SMeta *pMeta, tb_uid_t uid);
|
||||||
int metaCommit(SMeta *);
|
int metaCommit(SMeta *pMeta);
|
||||||
|
|
||||||
// Options
|
// Options
|
||||||
void metaOptionsInit(SMetaOptions *);
|
void metaOptionsInit(SMetaOptions *pOptions);
|
||||||
void metaOptionsClear(SMetaOptions *);
|
void metaOptionsClear(SMetaOptions *pOptions);
|
||||||
|
|
||||||
// STableOpts
|
// STableOpts
|
||||||
#define META_TABLE_OPTS_DECLARE(name) STableOpts name = {0}
|
#define META_TABLE_OPTS_DECLARE(name) STableOpts name = {0}
|
||||||
void metaNormalTableOptsInit(STbOptions *, const char *name, const STSchema *pSchema);
|
void metaNormalTableOptsInit(STbOptions *pTbOptions, const char *name, const STSchema *pSchema);
|
||||||
void metaSuperTableOptsInit(STbOptions *, const char *name, tb_uid_t uid, const STSchema *pSchema,
|
void metaSuperTableOptsInit(STbOptions *pTbOptions, const char *name, tb_uid_t uid, const STSchema *pSchema,
|
||||||
const STSchema *pTagSchema);
|
const STSchema *pTagSchema);
|
||||||
void metaChildTableOptsInit(STbOptions *, const char *name, tb_uid_t suid, const SKVRow tags);
|
void metaChildTableOptsInit(STbOptions *pTbOptions, const char *name, tb_uid_t suid, const SKVRow tags);
|
||||||
void metaTableOptsClear(STbOptions *);
|
void metaTableOptsClear(STbOptions *pTbOptions);
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,15 +16,14 @@
|
||||||
#ifndef _TD_TSDB_H_
|
#ifndef _TD_TSDB_H_
|
||||||
#define _TD_TSDB_H_
|
#define _TD_TSDB_H_
|
||||||
|
|
||||||
#include "impl/tsdbImpl.h"
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
extern "C" {
|
extern "C" {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// TYPES EXPOSED
|
// TYPES EXPOSED
|
||||||
typedef struct STsdb STsdb;
|
typedef struct STsdb STsdb;
|
||||||
typedef struct STsdbOptions STsdbOptions;
|
typedef struct STsdbOptions STsdbOptions;
|
||||||
|
typedef struct STsdbMemAllocator STsdbMemAllocator;
|
||||||
|
|
||||||
// STsdb
|
// STsdb
|
||||||
STsdb *tsdbOpen(const char *path, const STsdbOptions *);
|
STsdb *tsdbOpen(const char *path, const STsdbOptions *);
|
||||||
|
@ -35,6 +34,12 @@ void tsdbRemove(const char *path);
|
||||||
int tsdbOptionsInit(STsdbOptions *);
|
int tsdbOptionsInit(STsdbOptions *);
|
||||||
void tsdbOptionsClear(STsdbOptions *);
|
void tsdbOptionsClear(STsdbOptions *);
|
||||||
|
|
||||||
|
/* ------------------------ STRUCT DEFINITIONS ------------------------ */
|
||||||
|
struct STsdbOptions {
|
||||||
|
uint64_t lruCacheSize;
|
||||||
|
/* TODO */
|
||||||
|
};
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -17,9 +17,10 @@
|
||||||
#define _TD_VNODE_H_
|
#define _TD_VNODE_H_
|
||||||
|
|
||||||
#include "os.h"
|
#include "os.h"
|
||||||
#include "trequest.h"
|
#include "trpc.h"
|
||||||
|
|
||||||
#include "meta.h"
|
#include "meta.h"
|
||||||
|
#include "tarray.h"
|
||||||
#include "tq.h"
|
#include "tq.h"
|
||||||
#include "tsdb.h"
|
#include "tsdb.h"
|
||||||
|
|
||||||
|
@ -32,17 +33,72 @@ typedef struct SVnode SVnode;
|
||||||
typedef struct SVnodeOptions SVnodeOptions;
|
typedef struct SVnodeOptions SVnodeOptions;
|
||||||
|
|
||||||
/* ------------------------ SVnode ------------------------ */
|
/* ------------------------ SVnode ------------------------ */
|
||||||
|
/**
|
||||||
|
* @brief Open a VNODE.
|
||||||
|
*
|
||||||
|
* @param path path of the vnode
|
||||||
|
* @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 SVnodeOptions *pVnodeOptions);
|
||||||
void vnodeClose(SVnode *pVnode);
|
|
||||||
void vnodeDestroy(const char *path);
|
/**
|
||||||
int vnodeProcessWriteReqs(SVnode *pVnode, SReqBatch *pReqBatch);
|
* @brief Close a VNODE
|
||||||
int vnodeApplyWriteRequest(SVnode *pVnode, const SRequest *pRequest);
|
*
|
||||||
int vnodeProcessReadReq(SVnode *pVnode, SRequest *pReq);
|
* @param pVnode The vnode object to close
|
||||||
int vnodeProcessSyncReq(SVnode *pVnode, SRequest *pReq);
|
*/
|
||||||
|
void vnodeClose(SVnode *pVnode);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Destroy a VNODE.
|
||||||
|
*
|
||||||
|
* @param path Path of the VNODE.
|
||||||
|
*/
|
||||||
|
void vnodeDestroy(const char *path);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Process an array of write messages.
|
||||||
|
*
|
||||||
|
* @param pVnode The vnode object.
|
||||||
|
* @param pMsgs The array of SRpcMsg
|
||||||
|
* @return int 0 for success, -1 for failure
|
||||||
|
*/
|
||||||
|
int vnodeProcessWMsgs(SVnode *pVnode, SArray *pMsgs);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Apply a write request message.
|
||||||
|
*
|
||||||
|
* @param pVnode The vnode object.
|
||||||
|
* @param pMsg The request message
|
||||||
|
* @param pRsp The response message
|
||||||
|
* @return int 0 for success, -1 for failure
|
||||||
|
*/
|
||||||
|
int vnodeApplyWMsg(SVnode *pVnode, SRpcMsg *pMsg, SRpcMsg **pRsp);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Process the sync request
|
||||||
|
*
|
||||||
|
* @param pVnode
|
||||||
|
* @param pMsg
|
||||||
|
* @param pRsp
|
||||||
|
* @return int
|
||||||
|
*/
|
||||||
|
int vnodeProcessSyncReq(SVnode *pVnode, SRpcMsg *pMsg, SRpcMsg **pRsp);
|
||||||
|
|
||||||
/* ------------------------ SVnodeOptions ------------------------ */
|
/* ------------------------ SVnodeOptions ------------------------ */
|
||||||
void vnodeOptionsInit(SVnodeOptions *);
|
/**
|
||||||
void vnodeOptionsClear(SVnodeOptions *);
|
* @brief Initialize VNODE options.
|
||||||
|
*
|
||||||
|
* @param pOptions The options object to be initialized. It should not be NULL.
|
||||||
|
*/
|
||||||
|
void vnodeOptionsInit(SVnodeOptions *pOptions);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Clear VNODE options.
|
||||||
|
*
|
||||||
|
* @param pOptions Options to clear.
|
||||||
|
*/
|
||||||
|
void vnodeOptionsClear(SVnodeOptions *pOptions);
|
||||||
|
|
||||||
/* ------------------------ STRUCT DEFINITIONS ------------------------ */
|
/* ------------------------ STRUCT DEFINITIONS ------------------------ */
|
||||||
struct SVnodeOptions {
|
struct SVnodeOptions {
|
||||||
|
|
|
@ -13,8 +13,8 @@
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef _TD_LRU_H_
|
#ifndef _TD_CACHE_H_
|
||||||
#define _TD_LRU_H_
|
#define _TD_CACHE_H_
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
extern "C" {
|
extern "C" {
|
||||||
|
@ -24,4 +24,4 @@ extern "C" {
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#endif /*_TD_LRU_H_*/
|
#endif /*_TD_CACHE_H_*/
|
|
@ -24,37 +24,21 @@ extern "C" {
|
||||||
|
|
||||||
typedef struct SMemAllocator SMemAllocator;
|
typedef struct SMemAllocator SMemAllocator;
|
||||||
|
|
||||||
#define MALLOCATOR_APIS \
|
|
||||||
void *(*malloc)(SMemAllocator *, size_t size); \
|
|
||||||
void *(*calloc)(SMemAllocator *, size_t nmemb, size_t size); \
|
|
||||||
void *(*realloc)(SMemAllocator *, void *ptr, size_t size); \
|
|
||||||
void (*free)(SMemAllocator *, void *ptr); \
|
|
||||||
size_t (*usage)(SMemAllocator *);
|
|
||||||
|
|
||||||
// Interfaces to implement
|
|
||||||
typedef struct {
|
|
||||||
MALLOCATOR_APIS
|
|
||||||
} SMemAllocatorIf;
|
|
||||||
|
|
||||||
struct SMemAllocator {
|
struct SMemAllocator {
|
||||||
void * impl;
|
char name[16];
|
||||||
size_t usize;
|
void *impl;
|
||||||
MALLOCATOR_APIS
|
void *(*malloc)(SMemAllocator *, uint64_t size);
|
||||||
|
void *(*calloc)(SMemAllocator *, uint64_t nmemb, uint64_t size);
|
||||||
|
void *(*realloc)(SMemAllocator *, void *ptr, uint64_t size);
|
||||||
|
void (*free)(SMemAllocator *, void *ptr);
|
||||||
|
uint64_t (*usage)(SMemAllocator *);
|
||||||
};
|
};
|
||||||
|
|
||||||
// heap allocator
|
typedef struct {
|
||||||
SMemAllocator *tdCreateHeapAllocator();
|
void *impl;
|
||||||
void tdDestroyHeapAllocator(SMemAllocator *pMemAllocator);
|
SMemAllocator *(*create)();
|
||||||
|
void (*destroy)(SMemAllocator *);
|
||||||
// arena allocator
|
} SMemAllocatorFactory;
|
||||||
SMemAllocator *tdCreateArenaAllocator(size_t size);
|
|
||||||
void tdDestroyArenaAllocator(SMemAllocator *);
|
|
||||||
|
|
||||||
#define mMalloc(pMemAllocator, size) (*(pMemAllocator->malloc))(pMemAllocator, size)
|
|
||||||
#define mCalloc(pMemAllocator, nmemb, size) (*(pMemAllocator->calloc))(pMemAllocator, nmemb, size)
|
|
||||||
#define mRealloc(pMemAllocator, ptr, size) (*(pMemAllocator->realloc))(pMemAllocator, ptr, size)
|
|
||||||
#define mFree(pMemAllocator, ptr) (*(pMemAllocator->free))(pMemAllocator, ptr)
|
|
||||||
#define mUsage(pMemAllocator) (*(pMemAllocator->usage))(pMemAllocator)
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
|
|
|
@ -46,9 +46,10 @@ typedef struct {
|
||||||
#define isListEmpty(l) ((l)->numOfEles == 0)
|
#define isListEmpty(l) ((l)->numOfEles == 0)
|
||||||
#define listNodeFree(n) free(n)
|
#define listNodeFree(n) free(n)
|
||||||
|
|
||||||
|
void tdListInit(SList *list, int eleSize);
|
||||||
|
void tdListEmpty(SList *list);
|
||||||
SList * tdListNew(int eleSize);
|
SList * tdListNew(int eleSize);
|
||||||
void * tdListFree(SList *list);
|
void * tdListFree(SList *list);
|
||||||
void tdListEmpty(SList *list);
|
|
||||||
void tdListPrependNode(SList *list, SListNode *node);
|
void tdListPrependNode(SList *list, SListNode *node);
|
||||||
void tdListAppendNode(SList *list, SListNode *node);
|
void tdListAppendNode(SList *list, SListNode *node);
|
||||||
int tdListPrepend(SList *list, void *data);
|
int tdListPrepend(SList *list, void *data);
|
||||||
|
|
|
@ -13,27 +13,23 @@
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef _TD_VNODE_ALLOCATOR_POOL_H_
|
#ifndef _TD_VNODE_BUFFER_POOL_H_
|
||||||
#define _TD_VNODE_ALLOCATOR_POOL_H_
|
#define _TD_VNODE_BUFFER_POOL_H_
|
||||||
|
|
||||||
|
#include "tlist.h"
|
||||||
#include "vnode.h"
|
#include "vnode.h"
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
extern "C" {
|
extern "C" {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
typedef struct {
|
typedef struct SVBufPool SVBufPool;
|
||||||
int nexta;
|
|
||||||
int enda;
|
|
||||||
SMemAllocator *free[3];
|
|
||||||
SMemAllocator *used[3];
|
|
||||||
} SVAllocatorPool;
|
|
||||||
|
|
||||||
int vnodeOpenAllocatorPool(SVnode *pVnode);
|
int vnodeOpenBufPool(SVnode *pVnode);
|
||||||
void vnodeCloseAllocatorPool(SVnode *pVnode);
|
void vnodeCloseBufPool(SVnode *pVnode);
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#endif /*_TD_VNODE_ALLOCATOR_POOL_H_*/
|
#endif /*_TD_VNODE_BUFFER_POOL_H_*/
|
|
@ -19,9 +19,10 @@
|
||||||
#include "mallocator.h"
|
#include "mallocator.h"
|
||||||
#include "sync.h"
|
#include "sync.h"
|
||||||
#include "tlockfree.h"
|
#include "tlockfree.h"
|
||||||
|
#include "wal.h"
|
||||||
|
|
||||||
#include "vnode.h"
|
#include "vnode.h"
|
||||||
#include "vnodeAllocatorPool.h"
|
#include "vnodeBufferPool.h"
|
||||||
#include "vnodeCommit.h"
|
#include "vnodeCommit.h"
|
||||||
#include "vnodeFileSystem.h"
|
#include "vnodeFileSystem.h"
|
||||||
#include "vnodeOptions.h"
|
#include "vnodeOptions.h"
|
||||||
|
@ -33,16 +34,16 @@ extern "C" {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
struct SVnode {
|
struct SVnode {
|
||||||
char* path;
|
char* path;
|
||||||
SVnodeOptions options;
|
SVnodeOptions options;
|
||||||
SVState state;
|
SVState state;
|
||||||
SVAllocatorPool* pool;
|
SVBufPool* pBufPool;
|
||||||
SMemAllocator* inuse;
|
SMeta* pMeta;
|
||||||
SMeta* pMeta;
|
STsdb* pTsdb;
|
||||||
STsdb* pTsdb;
|
STQ* pTq;
|
||||||
STQ* pTq;
|
SWal* pWal;
|
||||||
SVnodeSync* pSync;
|
SVnodeSync* pSync;
|
||||||
SVnodeFS* pFs;
|
SVnodeFS* pFs;
|
||||||
};
|
};
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
|
|
|
@ -16,10 +16,16 @@
|
||||||
#ifndef _TD_VNODE_MEM_ALLOCATOR_H_
|
#ifndef _TD_VNODE_MEM_ALLOCATOR_H_
|
||||||
#define _TD_VNODE_MEM_ALLOCATOR_H_
|
#define _TD_VNODE_MEM_ALLOCATOR_H_
|
||||||
|
|
||||||
|
#include "mallocator.h"
|
||||||
|
#include "vnode.h"
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
extern "C" {
|
extern "C" {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
SMemAllocator *vnodeCreateMemAllocator(SVnode *pVnode);
|
||||||
|
void vnodeDestroyMemAllocator(SMemAllocator *pma);
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -20,6 +20,20 @@
|
||||||
extern "C" {
|
extern "C" {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
typedef struct SVnodeReq SVnodeReq;
|
||||||
|
typedef struct SVnodeRsp SVnodeRsp;
|
||||||
|
|
||||||
|
typedef enum {
|
||||||
|
} EVReqT;
|
||||||
|
|
||||||
|
struct SVnodeReq {
|
||||||
|
/* TODO */
|
||||||
|
};
|
||||||
|
|
||||||
|
struct SVnodeRsp {
|
||||||
|
/* TODO */
|
||||||
|
};
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -0,0 +1,188 @@
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com>
|
||||||
|
*
|
||||||
|
* 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 <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "vnodeDef.h"
|
||||||
|
|
||||||
|
/* ------------------------ STRUCTURES ------------------------ */
|
||||||
|
#define VNODE_BUF_POOL_SHARDS 3
|
||||||
|
|
||||||
|
struct SVBufPool {
|
||||||
|
SList free;
|
||||||
|
SList incycle;
|
||||||
|
SListNode *inuse;
|
||||||
|
};
|
||||||
|
|
||||||
|
typedef enum {
|
||||||
|
// Heap allocator
|
||||||
|
E_V_HEAP_ALLOCATOR = 0,
|
||||||
|
// Arena allocator
|
||||||
|
E_V_ARENA_ALLOCATOR
|
||||||
|
} EVMemAllocatorT;
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
/* TODO */
|
||||||
|
} SVHeapAllocator;
|
||||||
|
|
||||||
|
typedef struct SVArenaNode {
|
||||||
|
struct SVArenaNode *prev;
|
||||||
|
uint64_t size;
|
||||||
|
void * ptr;
|
||||||
|
char data[];
|
||||||
|
} SVArenaNode;
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
uint64_t ssize; // step size
|
||||||
|
uint64_t lsize; // limit size
|
||||||
|
SVArenaNode *inuse;
|
||||||
|
SVArenaNode node;
|
||||||
|
} SVArenaAllocator;
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
T_REF_DECLARE()
|
||||||
|
uint64_t capacity;
|
||||||
|
EVMemAllocatorT type;
|
||||||
|
union {
|
||||||
|
SVHeapAllocator vha;
|
||||||
|
SVArenaAllocator vaa;
|
||||||
|
};
|
||||||
|
} SVMemAllocator;
|
||||||
|
|
||||||
|
static SListNode *vBufPoolNewNode(uint64_t capacity, EVMemAllocatorT type);
|
||||||
|
static void vBufPoolFreeNode(SListNode *pNode);
|
||||||
|
|
||||||
|
int vnodeOpenBufPool(SVnode *pVnode) {
|
||||||
|
uint64_t capacity;
|
||||||
|
EVMemAllocatorT type = E_V_ARENA_ALLOCATOR;
|
||||||
|
|
||||||
|
if ((pVnode->pBufPool = (SVBufPool *)calloc(1, sizeof(SVBufPool))) == NULL) {
|
||||||
|
/* TODO */
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
tdListInit(&(pVnode->pBufPool->free), 0);
|
||||||
|
tdListInit(&(pVnode->pBufPool->incycle), 0);
|
||||||
|
|
||||||
|
capacity = pVnode->options.wsize / VNODE_BUF_POOL_SHARDS;
|
||||||
|
if (pVnode->options.isHeapAllocator) {
|
||||||
|
type = E_V_HEAP_ALLOCATOR;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (int i = 0; i < VNODE_BUF_POOL_SHARDS; i++) {
|
||||||
|
SListNode *pNode = vBufPoolNewNode(capacity, type);
|
||||||
|
if (pNode == NULL) {
|
||||||
|
vnodeCloseBufPool(pVnode);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
tdListAppendNode(&(pVnode->pBufPool->free), pNode);
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
void vnodeCloseBufPool(SVnode *pVnode) {
|
||||||
|
SListNode *pNode;
|
||||||
|
if (pVnode->pBufPool) {
|
||||||
|
// Clear free list
|
||||||
|
while ((pNode = tdListPopHead(&(pVnode->pBufPool->free))) != NULL) {
|
||||||
|
vBufPoolFreeNode(pNode);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Clear incycle list
|
||||||
|
while ((pNode = tdListPopHead(&(pVnode->pBufPool->incycle))) != NULL) {
|
||||||
|
vBufPoolFreeNode(pNode);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Free inuse node
|
||||||
|
if (pVnode->pBufPool->inuse) {
|
||||||
|
vBufPoolFreeNode(pVnode->pBufPool->inuse);
|
||||||
|
}
|
||||||
|
|
||||||
|
free(pVnode->pBufPool);
|
||||||
|
pVnode->pBufPool = NULL;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* ------------------------ STATIC METHODS ------------------------ */
|
||||||
|
static void vArenaAllocatorInit(SVArenaAllocator *pvaa, uint64_t capacity, uint64_t ssize, uint64_t lsize) { /* TODO */
|
||||||
|
pvaa->ssize = ssize;
|
||||||
|
pvaa->lsize = lsize;
|
||||||
|
pvaa->inuse = &pvaa->node;
|
||||||
|
|
||||||
|
pvaa->node.prev = NULL;
|
||||||
|
pvaa->node.size = capacity;
|
||||||
|
pvaa->node.ptr = pvaa->node.data;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void vArenaAllocatorClear(SVArenaAllocator *pvaa) { /* TODO */
|
||||||
|
while (pvaa->inuse != &(pvaa->node)) {
|
||||||
|
SVArenaNode *pANode = pvaa->inuse;
|
||||||
|
pvaa->inuse = pANode->prev;
|
||||||
|
free(pANode);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static SListNode *vBufPoolNewNode(uint64_t capacity, EVMemAllocatorT type) {
|
||||||
|
SListNode * pNode;
|
||||||
|
SVMemAllocator *pvma;
|
||||||
|
uint64_t msize;
|
||||||
|
uint64_t ssize = 0; // TODO
|
||||||
|
uint64_t lsize = 0; // TODO
|
||||||
|
|
||||||
|
msize = sizeof(SListNode) + sizeof(SVMemAllocator);
|
||||||
|
if (type == E_V_ARENA_ALLOCATOR) {
|
||||||
|
msize += capacity;
|
||||||
|
}
|
||||||
|
|
||||||
|
pNode = (SListNode *)calloc(1, msize);
|
||||||
|
if (pNode == NULL) {
|
||||||
|
// TODO: handle error
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
pvma = (SVMemAllocator *)(pNode->data);
|
||||||
|
pvma->capacity = capacity;
|
||||||
|
pvma->type = type;
|
||||||
|
|
||||||
|
switch (type) {
|
||||||
|
case E_V_ARENA_ALLOCATOR:
|
||||||
|
vArenaAllocatorInit(&(pvma->vaa), capacity, ssize, lsize);
|
||||||
|
break;
|
||||||
|
case E_V_HEAP_ALLOCATOR:
|
||||||
|
// vHeapAllocatorInit(&(pvma->vha));
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
ASSERT(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
return pNode;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void vBufPoolFreeNode(SListNode *pNode) {
|
||||||
|
SVMemAllocator *pvma = (SVMemAllocator *)(pNode->data);
|
||||||
|
|
||||||
|
switch (pvma->type) {
|
||||||
|
case E_V_ARENA_ALLOCATOR:
|
||||||
|
vArenaAllocatorClear(&(pvma->vaa));
|
||||||
|
break;
|
||||||
|
case E_V_HEAP_ALLOCATOR:
|
||||||
|
// vHeapAllocatorClear(&(pvma->vha));
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
free(pNode);
|
||||||
|
}
|
|
@ -87,8 +87,7 @@ static void vnodeFree(SVnode *pVnode) {
|
||||||
static int vnodeOpenImpl(SVnode *pVnode) {
|
static int vnodeOpenImpl(SVnode *pVnode) {
|
||||||
char dir[TSDB_FILENAME_LEN];
|
char dir[TSDB_FILENAME_LEN];
|
||||||
|
|
||||||
// Open allocator pool
|
if (vnodeOpenBufPool(pVnode) < 0) {
|
||||||
if (vnodeOpenAllocatorPool(pVnode) < 0) {
|
|
||||||
// TODO: handle error
|
// TODO: handle error
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
@ -132,8 +131,6 @@ static int vnodeOpenImpl(SVnode *pVnode) {
|
||||||
static void vnodeCloseImpl(SVnode *pVnode) {
|
static void vnodeCloseImpl(SVnode *pVnode) {
|
||||||
if (pVnode) {
|
if (pVnode) {
|
||||||
vnodeCloseBufPool(pVnode);
|
vnodeCloseBufPool(pVnode);
|
||||||
walClose(pVnode->pWal);
|
|
||||||
tqClose(pVnode->pTq);
|
|
||||||
tsdbClose(pVnode->pTsdb);
|
tsdbClose(pVnode->pTsdb);
|
||||||
metaClose(pVnode->pMeta);
|
metaClose(pVnode->pMeta);
|
||||||
}
|
}
|
||||||
|
|
|
@ -15,6 +15,17 @@
|
||||||
|
|
||||||
#include "vnodeDef.h"
|
#include "vnodeDef.h"
|
||||||
|
|
||||||
|
SMemAllocator *vnodeCreateMemAllocator(SVnode *pVnode) {
|
||||||
|
SMemAllocator *pma = NULL;
|
||||||
|
/* TODO */
|
||||||
|
return pma;
|
||||||
|
}
|
||||||
|
|
||||||
|
void vnodeDestroyMemAllocator(SMemAllocator *pma) {
|
||||||
|
// TODO
|
||||||
|
}
|
||||||
|
|
||||||
|
#if 0
|
||||||
#define VNODE_HEAP_ALLOCATOR 0
|
#define VNODE_HEAP_ALLOCATOR 0
|
||||||
#define VNODE_ARENA_ALLOCATOR 1
|
#define VNODE_ARENA_ALLOCATOR 1
|
||||||
|
|
||||||
|
@ -97,4 +108,6 @@ void vnodeUnrefMemAllocator(SMemAllocator *pma) {
|
||||||
|
|
||||||
/* ------------------------ Heap Allocator IMPL ------------------------ */
|
/* ------------------------ Heap Allocator IMPL ------------------------ */
|
||||||
|
|
||||||
/* ------------------------ Arena Allocator IMPL ------------------------ */
|
/* ------------------------ Arena Allocator IMPL ------------------------ */
|
||||||
|
|
||||||
|
#endif
|
|
@ -15,24 +15,25 @@
|
||||||
|
|
||||||
#include "vnodeDef.h"
|
#include "vnodeDef.h"
|
||||||
|
|
||||||
int vnodeProcessWriteReqs(SVnode *pVnode, SReqBatch *pReqBatch) {
|
int vnodeProcessWMsgs(SVnode *pVnode, SArray *pMsgs) {
|
||||||
/* TODO */
|
/* TODO */
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int vnodeApplyWriteRequest(SVnode *pVnode, const SRequest *pRequest) {
|
int vnodeApplyWMsg(SVnode *pVnode, SRpcMsg *pMsg, SRpcMsg **pRsp) {
|
||||||
|
#if 0
|
||||||
int reqType; /* TODO */
|
int reqType; /* TODO */
|
||||||
size_t reqSize; /* TODO */
|
size_t reqSize; /* TODO */
|
||||||
uint64_t reqVersion = 0; /* TODO */
|
uint64_t reqVersion = 0; /* TODO */
|
||||||
int code = 0;
|
int code = 0;
|
||||||
|
|
||||||
// Copy the request to vnode buffer
|
// Copy the request to vnode buffer
|
||||||
SRequest *pReq = mMalloc(pVnode->inuse, reqSize);
|
void *pReq = mMalloc(pVnode->inuse, reqSize);
|
||||||
if (pReq == NULL) {
|
if (pReq == NULL) {
|
||||||
// TODO: handle error
|
// TODO: handle error
|
||||||
}
|
}
|
||||||
|
|
||||||
memcpy(pReq, pRequest, reqSize);
|
memcpy(pReq, pMsg, reqSize);
|
||||||
|
|
||||||
// Push the request to TQ so consumers can consume
|
// Push the request to TQ so consumers can consume
|
||||||
tqPushMsg(pVnode->pTq, pReq, 0);
|
tqPushMsg(pVnode->pTq, pReq, 0);
|
||||||
|
@ -45,7 +46,9 @@ int vnodeApplyWriteRequest(SVnode *pVnode, const SRequest *pRequest) {
|
||||||
case TSDB_MSG_TYPE_DROP_TABLE:
|
case TSDB_MSG_TYPE_DROP_TABLE:
|
||||||
code = metaDropTable(pVnode->pMeta, 0 /* TODO */);
|
code = metaDropTable(pVnode->pMeta, 0 /* TODO */);
|
||||||
break;
|
break;
|
||||||
|
case TSDB_MSG_TYPE_SUBMIT:
|
||||||
/* TODO */
|
/* TODO */
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -57,6 +60,8 @@ int vnodeApplyWriteRequest(SVnode *pVnode, const SRequest *pRequest) {
|
||||||
}
|
}
|
||||||
|
|
||||||
return code;
|
return code;
|
||||||
|
#endif
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ------------------------ STATIC METHODS ------------------------ */
|
/* ------------------------ STATIC METHODS ------------------------ */
|
|
@ -16,6 +16,8 @@
|
||||||
#ifndef _TD_META_DEF_H_
|
#ifndef _TD_META_DEF_H_
|
||||||
#define _TD_META_DEF_H_
|
#define _TD_META_DEF_H_
|
||||||
|
|
||||||
|
#include "mallocator.h"
|
||||||
|
|
||||||
#include "meta.h"
|
#include "meta.h"
|
||||||
#include "metaCache.h"
|
#include "metaCache.h"
|
||||||
#include "metaDB.h"
|
#include "metaDB.h"
|
||||||
|
@ -30,12 +32,13 @@ extern "C" {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
struct SMeta {
|
struct SMeta {
|
||||||
char* path; // path of current meta
|
char* path;
|
||||||
SMetaOptions options; // meta option
|
SMetaOptions options;
|
||||||
meta_db_t* pDB; // raw data db
|
meta_db_t* pDB;
|
||||||
meta_index_t* pIdx; // tag index
|
meta_index_t* pIdx;
|
||||||
meta_cache_t* pCache; // LRU cache
|
meta_cache_t* pCache;
|
||||||
STbUidGenerator uidGnrt; // meta table UID generator
|
STbUidGenerator uidGnrt;
|
||||||
|
SMemAllocatorFactory* pmaf;
|
||||||
};
|
};
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
|
|
|
@ -16,7 +16,10 @@
|
||||||
#ifndef _TD_TSDB_DEF_H_
|
#ifndef _TD_TSDB_DEF_H_
|
||||||
#define _TD_TSDB_DEF_H_
|
#define _TD_TSDB_DEF_H_
|
||||||
|
|
||||||
|
#include "mallocator.h"
|
||||||
|
|
||||||
#include "tsdb.h"
|
#include "tsdb.h"
|
||||||
|
#include "tsdbMemTable.h"
|
||||||
#include "tsdbOptions.h"
|
#include "tsdbOptions.h"
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
|
@ -24,8 +27,9 @@ extern "C" {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
struct STsdb {
|
struct STsdb {
|
||||||
char * path;
|
char * path;
|
||||||
STsdbOptions options;
|
STsdbOptions options;
|
||||||
|
SMemAllocatorFactory *pmaf;
|
||||||
};
|
};
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
|
|
|
@ -13,22 +13,22 @@
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef _TD_TSDB_IMPL_H_
|
#ifndef _TD_TSDB_MEM_TABLE_H_
|
||||||
#define _TD_TSDB_IMPL_H_
|
#define _TD_TSDB_MEM_TABLE_H_
|
||||||
|
|
||||||
#include "os.h"
|
#include "tsdb.h"
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
extern "C" {
|
extern "C" {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
struct STsdbOptions {
|
typedef struct SMemTable {
|
||||||
size_t lruCacheSize;
|
|
||||||
/* TODO */
|
/* TODO */
|
||||||
};
|
SMemAllocator *pma;
|
||||||
|
} SMemTable;
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#endif /*_TD_TSDB_IMPL_H_*/
|
#endif /*_TD_TSDB_MEM_TABLE_H_*/
|
|
@ -5,7 +5,7 @@ add_subdirectory(index)
|
||||||
add_subdirectory(wal)
|
add_subdirectory(wal)
|
||||||
add_subdirectory(parser)
|
add_subdirectory(parser)
|
||||||
add_subdirectory(scheduler)
|
add_subdirectory(scheduler)
|
||||||
add_subdirectory(lru)
|
add_subdirectory(cache)
|
||||||
add_subdirectory(catalog)
|
add_subdirectory(catalog)
|
||||||
add_subdirectory(executor)
|
add_subdirectory(executor)
|
||||||
add_subdirectory(planner)
|
add_subdirectory(planner)
|
||||||
|
|
|
@ -0,0 +1,7 @@
|
||||||
|
aux_source_directory(src CACHE_SRC)
|
||||||
|
add_library(cache ${CACHE_SRC})
|
||||||
|
target_include_directories(
|
||||||
|
cache
|
||||||
|
PUBLIC "${CMAKE_SOURCE_DIR}/include/libs/cache"
|
||||||
|
PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/inc"
|
||||||
|
)
|
|
@ -13,8 +13,8 @@
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef _TD_LRU_INT_H_
|
#ifndef _TD_CACHE_DEF_H_
|
||||||
#define _TD_LRU_INT_H_
|
#define _TD_CACHE_DEF_H_
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
extern "C" {
|
extern "C" {
|
||||||
|
@ -24,4 +24,4 @@ extern "C" {
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#endif /*_TD_LRU_INT_H_*/
|
#endif /*_TD_CACHE_DEF_H_*/
|
|
@ -11,27 +11,4 @@
|
||||||
*
|
*
|
||||||
* You should have received a copy of the GNU Affero General Public License
|
* You should have received a copy of the GNU Affero General Public License
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "vnodeDef.h"
|
|
||||||
|
|
||||||
int vnodeOpenAllocatorPool(SVnode *pVnode) {
|
|
||||||
// TODO
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
void vnodeCloseAllocatorPool(SVnode *pVnode) {
|
|
||||||
if (pVnode->pool) {
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/* ------------------------ STATIC METHODS ------------------------ */
|
|
||||||
static SVAllocatorPool *vapCreate() {
|
|
||||||
SVAllocatorPool *pPool = NULL;
|
|
||||||
/* TODO */
|
|
||||||
return pPool;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void vapDestroy() {
|
|
||||||
// TODO
|
|
||||||
}
|
|
|
@ -1,7 +0,0 @@
|
||||||
aux_source_directory(src LRU_SRC)
|
|
||||||
add_library(lru ${LRU_SRC})
|
|
||||||
target_include_directories(
|
|
||||||
lru
|
|
||||||
PUBLIC "${CMAKE_SOURCE_DIR}/include/libs/lru"
|
|
||||||
PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/inc"
|
|
||||||
)
|
|
|
@ -13,16 +13,20 @@
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "os.h"
|
|
||||||
#include "tlist.h"
|
#include "tlist.h"
|
||||||
|
#include "os.h"
|
||||||
|
|
||||||
|
void tdListInit(SList *list, int eleSize) {
|
||||||
|
list->eleSize = eleSize;
|
||||||
|
list->numOfEles = 0;
|
||||||
|
list->head = list->tail = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
SList *tdListNew(int eleSize) {
|
SList *tdListNew(int eleSize) {
|
||||||
SList *list = (SList *)malloc(sizeof(SList));
|
SList *list = (SList *)malloc(sizeof(SList));
|
||||||
if (list == NULL) return NULL;
|
if (list == NULL) return NULL;
|
||||||
|
|
||||||
list->eleSize = eleSize;
|
tdListInit(list, eleSize);
|
||||||
list->numOfEles = 0;
|
|
||||||
list->head = list->tail = NULL;
|
|
||||||
return list;
|
return list;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue