refact
This commit is contained in:
parent
0831a3120a
commit
d860e2687a
|
@ -1,41 +0,0 @@
|
||||||
/*
|
|
||||||
* 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/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifndef _TD_VNODE_BUFFER_POOL_H_
|
|
||||||
#define _TD_VNODE_BUFFER_POOL_H_
|
|
||||||
|
|
||||||
#include "tlist.h"
|
|
||||||
#include "vnode.h"
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
|
||||||
extern "C" {
|
|
||||||
#endif
|
|
||||||
|
|
||||||
typedef struct SVBufPool SVBufPool;
|
|
||||||
|
|
||||||
int vnodeOpenBufPool(SVnode *pVnode);
|
|
||||||
void vnodeCloseBufPool(SVnode *pVnode);
|
|
||||||
int vnodeBufPoolSwitch(SVnode *pVnode);
|
|
||||||
int vnodeBufPoolRecycle(SVnode *pVnode);
|
|
||||||
void *vnodeMalloc(SVnode *pVnode, uint64_t size);
|
|
||||||
bool vnodeBufPoolIsFull(SVnode *pVnode);
|
|
||||||
|
|
||||||
SMemAllocatorFactory *vBufPoolGetMAF(SVnode *pVnode);
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#endif /*_TD_VNODE_BUFFER_POOL_H_*/
|
|
|
@ -1,34 +0,0 @@
|
||||||
/*
|
|
||||||
* 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/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifndef _TD_VNODE_CFG_H_
|
|
||||||
#define _TD_VNODE_CFG_H_
|
|
||||||
|
|
||||||
#include "vnode.h"
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
|
||||||
extern "C" {
|
|
||||||
#endif
|
|
||||||
|
|
||||||
extern const SVnodeCfg defaultVnodeOptions;
|
|
||||||
|
|
||||||
int vnodeValidateOptions(const SVnodeCfg *);
|
|
||||||
void vnodeOptionsCopy(SVnodeCfg *pDest, const SVnodeCfg *pSrc);
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#endif /*_TD_VNODE_CFG_H_*/
|
|
|
@ -1,33 +0,0 @@
|
||||||
/*
|
|
||||||
* 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/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifndef _TD_VNODE_COMMIT_H_
|
|
||||||
#define _TD_VNODE_COMMIT_H_
|
|
||||||
|
|
||||||
#include "vnode.h"
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
|
||||||
extern "C" {
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#define vnodeShouldCommit vnodeBufPoolIsFull
|
|
||||||
int vnodeSyncCommit(SVnode *pVnode);
|
|
||||||
int vnodeAsyncCommit(SVnode *pVnode);
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#endif /*_TD_VNODE_COMMIT_H_*/
|
|
|
@ -19,25 +19,23 @@
|
||||||
#include "mallocator.h"
|
#include "mallocator.h"
|
||||||
// #include "sync.h"
|
// #include "sync.h"
|
||||||
#include "tcoding.h"
|
#include "tcoding.h"
|
||||||
|
#include "tfs.h"
|
||||||
#include "tlist.h"
|
#include "tlist.h"
|
||||||
#include "tlockfree.h"
|
#include "tlockfree.h"
|
||||||
#include "tmacro.h"
|
#include "tmacro.h"
|
||||||
#include "wal.h"
|
#include "wal.h"
|
||||||
#include "tfs.h"
|
|
||||||
|
|
||||||
#include "vnode.h"
|
#include "vnode.h"
|
||||||
|
|
||||||
#include "vnodeBufferPool.h"
|
|
||||||
#include "vnodeCfg.h"
|
|
||||||
#include "vnodeCommit.h"
|
|
||||||
#include "vnodeMemAllocator.h"
|
|
||||||
#include "vnodeQuery.h"
|
#include "vnodeQuery.h"
|
||||||
#include "vnodeStateMgr.h"
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
extern "C" {
|
extern "C" {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
typedef struct SVState SVState;
|
||||||
|
typedef struct SVBufPool SVBufPool;
|
||||||
|
|
||||||
typedef struct SVnodeTask {
|
typedef struct SVnodeTask {
|
||||||
TD_DLIST_NODE(SVnodeTask);
|
TD_DLIST_NODE(SVnodeTask);
|
||||||
void* arg;
|
void* arg;
|
||||||
|
@ -60,34 +58,119 @@ typedef struct SVnodeMgr {
|
||||||
|
|
||||||
extern SVnodeMgr vnodeMgr;
|
extern SVnodeMgr vnodeMgr;
|
||||||
|
|
||||||
|
// SVState
|
||||||
|
struct SVState {
|
||||||
|
int64_t processed;
|
||||||
|
int64_t committed;
|
||||||
|
int64_t applied;
|
||||||
|
};
|
||||||
|
|
||||||
struct SVnode {
|
struct SVnode {
|
||||||
int32_t vgId;
|
int32_t vgId;
|
||||||
char* path;
|
char* path;
|
||||||
SVnodeCfg config;
|
SVnodeCfg config;
|
||||||
SVState state;
|
SVState state;
|
||||||
SVBufPool* pBufPool;
|
SVBufPool* pBufPool;
|
||||||
SMeta* pMeta;
|
SMeta* pMeta;
|
||||||
STsdb* pTsdb;
|
STsdb* pTsdb;
|
||||||
STQ* pTq;
|
STQ* pTq;
|
||||||
SWal* pWal;
|
SWal* pWal;
|
||||||
tsem_t canCommit;
|
tsem_t canCommit;
|
||||||
SQHandle* pQuery;
|
SQHandle* pQuery;
|
||||||
SDnode* pDnode;
|
SDnode* pDnode;
|
||||||
};
|
};
|
||||||
|
|
||||||
int vnodeScheduleTask(SVnodeTask* task);
|
int vnodeScheduleTask(SVnodeTask* task);
|
||||||
|
|
||||||
int32_t vnodePutReqToVQueryQ(SVnode *pVnode, struct SRpcMsg *pReq);
|
int32_t vnodePutReqToVQueryQ(SVnode* pVnode, struct SRpcMsg* pReq);
|
||||||
|
|
||||||
// For Log
|
// For Log
|
||||||
extern int32_t vDebugFlag;
|
extern int32_t vDebugFlag;
|
||||||
|
|
||||||
#define vFatal(...) do { if (vDebugFlag & DEBUG_FATAL) { taosPrintLog("VND FATAL ", 255, __VA_ARGS__); }} while(0)
|
#define vFatal(...) \
|
||||||
#define vError(...) do { if (vDebugFlag & DEBUG_ERROR) { taosPrintLog("VND ERROR ", 255, __VA_ARGS__); }} while(0)
|
do { \
|
||||||
#define vWarn(...) do { if (vDebugFlag & DEBUG_WARN) { taosPrintLog("VND WARN ", 255, __VA_ARGS__); }} while(0)
|
if (vDebugFlag & DEBUG_FATAL) { \
|
||||||
#define vInfo(...) do { if (vDebugFlag & DEBUG_INFO) { taosPrintLog("VND ", 255, __VA_ARGS__); }} while(0)
|
taosPrintLog("VND FATAL ", 255, __VA_ARGS__); \
|
||||||
#define vDebug(...) do { if (vDebugFlag & DEBUG_DEBUG) { taosPrintLog("VND ", tsdbDebugFlag, __VA_ARGS__); }} while(0)
|
} \
|
||||||
#define vTrace(...) do { if (vDebugFlag & DEBUG_TRACE) { taosPrintLog("VND ", tsdbDebugFlag, __VA_ARGS__); }} while(0)
|
} while (0)
|
||||||
|
#define vError(...) \
|
||||||
|
do { \
|
||||||
|
if (vDebugFlag & DEBUG_ERROR) { \
|
||||||
|
taosPrintLog("VND ERROR ", 255, __VA_ARGS__); \
|
||||||
|
} \
|
||||||
|
} while (0)
|
||||||
|
#define vWarn(...) \
|
||||||
|
do { \
|
||||||
|
if (vDebugFlag & DEBUG_WARN) { \
|
||||||
|
taosPrintLog("VND WARN ", 255, __VA_ARGS__); \
|
||||||
|
} \
|
||||||
|
} while (0)
|
||||||
|
#define vInfo(...) \
|
||||||
|
do { \
|
||||||
|
if (vDebugFlag & DEBUG_INFO) { \
|
||||||
|
taosPrintLog("VND ", 255, __VA_ARGS__); \
|
||||||
|
} \
|
||||||
|
} while (0)
|
||||||
|
#define vDebug(...) \
|
||||||
|
do { \
|
||||||
|
if (vDebugFlag & DEBUG_DEBUG) { \
|
||||||
|
taosPrintLog("VND ", tsdbDebugFlag, __VA_ARGS__); \
|
||||||
|
} \
|
||||||
|
} while (0)
|
||||||
|
#define vTrace(...) \
|
||||||
|
do { \
|
||||||
|
if (vDebugFlag & DEBUG_TRACE) { \
|
||||||
|
taosPrintLog("VND ", tsdbDebugFlag, __VA_ARGS__); \
|
||||||
|
} \
|
||||||
|
} while (0)
|
||||||
|
|
||||||
|
// vnodeCfg.h
|
||||||
|
extern const SVnodeCfg defaultVnodeOptions;
|
||||||
|
|
||||||
|
int vnodeValidateOptions(const SVnodeCfg*);
|
||||||
|
void vnodeOptionsCopy(SVnodeCfg* pDest, const SVnodeCfg* pSrc);
|
||||||
|
|
||||||
|
// For commit
|
||||||
|
#define vnodeShouldCommit vnodeBufPoolIsFull
|
||||||
|
int vnodeSyncCommit(SVnode* pVnode);
|
||||||
|
int vnodeAsyncCommit(SVnode* pVnode);
|
||||||
|
|
||||||
|
// SVBufPool
|
||||||
|
|
||||||
|
int vnodeOpenBufPool(SVnode* pVnode);
|
||||||
|
void vnodeCloseBufPool(SVnode* pVnode);
|
||||||
|
int vnodeBufPoolSwitch(SVnode* pVnode);
|
||||||
|
int vnodeBufPoolRecycle(SVnode* pVnode);
|
||||||
|
void* vnodeMalloc(SVnode* pVnode, uint64_t size);
|
||||||
|
bool vnodeBufPoolIsFull(SVnode* pVnode);
|
||||||
|
|
||||||
|
SMemAllocatorFactory* vBufPoolGetMAF(SVnode* pVnode);
|
||||||
|
|
||||||
|
// SVMemAllocator
|
||||||
|
typedef struct SVArenaNode {
|
||||||
|
TD_SLIST_NODE(SVArenaNode);
|
||||||
|
uint64_t size; // current node size
|
||||||
|
void* ptr;
|
||||||
|
char data[];
|
||||||
|
} SVArenaNode;
|
||||||
|
|
||||||
|
typedef struct SVMemAllocator {
|
||||||
|
T_REF_DECLARE()
|
||||||
|
TD_DLIST_NODE(SVMemAllocator);
|
||||||
|
uint64_t capacity;
|
||||||
|
uint64_t ssize;
|
||||||
|
uint64_t lsize;
|
||||||
|
SVArenaNode* pNode;
|
||||||
|
TD_SLIST(SVArenaNode) nlist;
|
||||||
|
} SVMemAllocator;
|
||||||
|
|
||||||
|
SVMemAllocator* vmaCreate(uint64_t capacity, uint64_t ssize, uint64_t lsize);
|
||||||
|
void vmaDestroy(SVMemAllocator* pVMA);
|
||||||
|
void vmaReset(SVMemAllocator* pVMA);
|
||||||
|
void* vmaMalloc(SVMemAllocator* pVMA, uint64_t size);
|
||||||
|
void vmaFree(SVMemAllocator* pVMA, void* ptr);
|
||||||
|
bool vmaIsFull(SVMemAllocator* pVMA);
|
||||||
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,53 +0,0 @@
|
||||||
/*
|
|
||||||
* 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/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifndef _TD_VNODE_MEM_ALLOCATOR_H_
|
|
||||||
#define _TD_VNODE_MEM_ALLOCATOR_H_
|
|
||||||
|
|
||||||
#include "os.h"
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
|
||||||
extern "C" {
|
|
||||||
#endif
|
|
||||||
|
|
||||||
typedef struct SVArenaNode {
|
|
||||||
TD_SLIST_NODE(SVArenaNode);
|
|
||||||
uint64_t size; // current node size
|
|
||||||
void * ptr;
|
|
||||||
char data[];
|
|
||||||
} SVArenaNode;
|
|
||||||
|
|
||||||
typedef struct SVMemAllocator {
|
|
||||||
T_REF_DECLARE()
|
|
||||||
TD_DLIST_NODE(SVMemAllocator);
|
|
||||||
uint64_t capacity;
|
|
||||||
uint64_t ssize;
|
|
||||||
uint64_t lsize;
|
|
||||||
SVArenaNode *pNode;
|
|
||||||
TD_SLIST(SVArenaNode) nlist;
|
|
||||||
} SVMemAllocator;
|
|
||||||
|
|
||||||
SVMemAllocator *vmaCreate(uint64_t capacity, uint64_t ssize, uint64_t lsize);
|
|
||||||
void vmaDestroy(SVMemAllocator *pVMA);
|
|
||||||
void vmaReset(SVMemAllocator *pVMA);
|
|
||||||
void * vmaMalloc(SVMemAllocator *pVMA, uint64_t size);
|
|
||||||
void vmaFree(SVMemAllocator *pVMA, void *ptr);
|
|
||||||
bool vmaIsFull(SVMemAllocator *pVMA);
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#endif /*_TD_VNODE_MEM_ALLOCATOR_H_*/
|
|
|
@ -1,33 +0,0 @@
|
||||||
/*
|
|
||||||
* 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/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifndef _TD_VNODE_STATE_MGR_H_
|
|
||||||
#define _TD_VNODE_STATE_MGR_H_
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
|
||||||
extern "C" {
|
|
||||||
#endif
|
|
||||||
|
|
||||||
typedef struct {
|
|
||||||
int64_t processed;
|
|
||||||
int64_t committed;
|
|
||||||
int64_t applied;
|
|
||||||
} SVState;
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#endif /*_TD_VNODE_STATE_MGR_H_*/
|
|
|
@ -1,31 +0,0 @@
|
||||||
/*
|
|
||||||
* 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/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifndef _TD_VNODE_WRITE_H_
|
|
||||||
#define _TD_VNODE_WRITE_H_
|
|
||||||
|
|
||||||
#include "vnode.h"
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
|
||||||
extern "C" {
|
|
||||||
#endif
|
|
||||||
|
|
||||||
void vnodeProcessWriteMsg(SVnode* pVnode, SVnodeMsg* pMsg);
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#endif /*_TD_VNODE_WRITE_H_*/
|
|
Loading…
Reference in New Issue