提交 5a4f137b 编写于 作者: H Haojun Liao

Merge branch '3.0' of github.com:taosdata/tdengine into 3.0

......@@ -50,6 +50,11 @@ if(${BUILD_WITH_LUCENE})
cat("${CMAKE_SUPPORT_DIR}/lucene_CMakeLists.txt.in" ${DEPS_TMP_FILE})
endif(${BUILD_WITH_LUCENE})
## NuRaft
if(${BUILD_WITH_NURAFT})
cat("${CMAKE_SUPPORT_DIR}/nuraft_CMakeLists.txt.in" ${DEPS_TMP_FILE})
endif(${BUILD_WITH_NURAFT})
## download dependencies
configure_file(${DEPS_TMP_FILE} "${CMAKE_SOURCE_DIR}/deps/deps-download/CMakeLists.txt")
execute_process(COMMAND "${CMAKE_COMMAND}" -G "${CMAKE_GENERATOR}" .
......@@ -69,4 +74,7 @@ target_include_directories(api INTERFACE "include/client")
# src
add_subdirectory(source)
# docs
add_subdirectory(docs)
# tests (TODO)
......@@ -142,7 +142,7 @@ pipeline {
}
}
// stage('Parallel test stage') {
// //only build pr
// skip defaultCheckout
// options { skipDefaultCheckout() }
// when {
// allOf{
......
......@@ -16,7 +16,7 @@ option(
option(
BUILD_WITH_ROCKSDB
"If build with rocksdb"
OFF
ON
)
option(
......@@ -25,8 +25,20 @@ option(
OFF
)
option(
BUILD_WITH_NURAFT
"If build with NuRaft"
OFF
)
option(
BUILD_DEPENDENCY_TESTS
"If build dependency tests"
OFF
)
option(
BUILD_DOCS
"If use doxygen build documents"
ON
)
\ No newline at end of file
# NuRaft
ExternalProject_Add(NuRaft
GIT_REPOSITORY https://github.com/eBay/NuRaft.git
GIT_TAG v1.3.0
SOURCE_DIR "${CMAKE_SOURCE_DIR}/deps/nuraft"
BINARY_DIR "${CMAKE_SOURCE_DIR}/deps/nuraft"
CONFIGURE_COMMAND "./prepare.sh"
BUILD_COMMAND ""
INSTALL_COMMAND ""
TEST_COMMAND ""
)
\ No newline at end of file
......@@ -67,6 +67,12 @@ if(${BUILD_WITH_LUCENE})
add_subdirectory(lucene)
endif(${BUILD_WITH_LUCENE})
# NuRaft
if(${BUILD_WITH_NURAFT})
add_subdirectory(nuraft)
endif(${BUILD_WITH_NURAFT})
# ================================================================================================
# DEPENDENCY TEST
# ================================================================================================
......
# Generate API documentation
## https://vicrucann.github.io/tutorials/quick-cmake-doxygen/
if(${BUILD_DOCS})
find_package(Doxygen)
if (DOXYGEN_FOUND)
# Build the doc
set(DOXYGEN_IN ${CMAKE_SOURCE_DIR}/docs/Doxyfile.in)
set(DOXYGEN_OUT ${CMAKE_BINARY_DIR}/Doxyfile)
configure_file(${DOXYGEN_IN} ${DOXYGEN_OUT} @ONLY)
message("Doxygen build start")
add_custom_target(
tdengine_doxygen ALL
COMMAND ${DOXYGEN_EXECUTABLE} ${DOXYGEN_OUT}
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
COMMENT "Generating API doxumentation with Doxygen"
VERBATIM
)
else(DOXYGEN_FOUND)
message("Doxygen need to be installed to generate the doxygen documentation")
endif(DOXYGEN_FOUND)
endif(${BUILD_DOCS})
\ No newline at end of file
此差异已折叠。
/*
* 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_TREQUEST_H_
#define _TD_TREQUEST_H_
#ifdef __cplusplus
extern "C" {
#endif
/* ------------------------ TYPES EXPOSED ------------------------ */
typedef struct SRequest SRequest;
typedef struct SReqBatch SReqBatch;
typedef struct SReqBatchIter SReqBatchIter;
// SRequest
// SReqBatch
// SReqBatchIter
void tdInitRBIter(SReqBatchIter *pIter, SReqBatch *pReqBatch);
const SRequest *tdRBIterNext(SReqBatchIter *pIter);
void tdClearRBIter(SReqBatchIter *pIter);
/* ------------------------ TYPES DEFINITION ------------------------ */
struct SReqBatchIter {
int iReq;
SReqBatch *pReqBatch;
};
#ifdef __cplusplus
}
#endif
#endif /*_TD_TREQUEST_H_*/
\ No newline at end of file
......@@ -26,13 +26,13 @@ extern "C" {
typedef int32_t SyncNodeId;
typedef int32_t SyncGroupId;
typedef int64_t SyncIndex;
typedef uint64_t SSyncTerm;
typedef uint64_t SyncTerm;
typedef enum {
TAOS_SYNC_ROLE_FOLLOWER = 0,
TAOS_SYNC_ROLE_CANDIDATE = 1,
TAOS_SYNC_ROLE_LEADER = 2,
} ESyncRole;
TAOS_SYNC_STATE_FOLLOWER = 0,
TAOS_SYNC_STATE_CANDIDATE = 1,
TAOS_SYNC_STATE_LEADER = 2,
} ESyncState;
typedef struct {
void* data;
......@@ -55,19 +55,19 @@ typedef struct {
int32_t selfIndex;
int32_t replica;
SNodeInfo node[TSDB_MAX_REPLICA];
ESyncRole role[TSDB_MAX_REPLICA];
ESyncState role[TSDB_MAX_REPLICA];
} SNodesRole;
typedef struct SSyncFSM {
void* pData;
// apply committed log, bufs will be free by raft module
// apply committed log, bufs will be free by sync module
int32_t (*applyLog)(struct SSyncFSM* fsm, SyncIndex index, const SSyncBuffer* buf, void* pData);
// cluster commit callback
int32_t (*onClusterChanged)(struct SSyncFSM* fsm, const SSyncCluster* cluster, void* pData);
// fsm return snapshot in ppBuf, bufs will be free by raft module
// fsm return snapshot in ppBuf, bufs will be free by sync module
// TODO: getSnapshot SHOULD be async?
int32_t (*getSnapshot)(struct SSyncFSM* fsm, SSyncBuffer** ppBuf, int32_t* objId, bool* isLast);
......@@ -89,19 +89,30 @@ typedef struct SSyncLogStore {
// write log with given index
int32_t (*logWrite)(struct SSyncLogStore* logStore, SyncIndex index, SSyncBuffer* pBuf);
/**
* read log from given index(included) with limit, return the actual num in nBuf,
* pBuf will be free in sync module
**/
int32_t (*logRead)(struct SSyncLogStore* logStore, SyncIndex index, int limit,
SSyncBuffer* pBuf, int* nBuf);
// mark log with given index has been commtted
int32_t (*logCommit)(struct SSyncLogStore* logStore, SyncIndex index);
// prune log before given index
// prune log before given index(not included)
int32_t (*logPrune)(struct SSyncLogStore* logStore, SyncIndex index);
// rollback log after given index
// rollback log after given index(included)
int32_t (*logRollback)(struct SSyncLogStore* logStore, SyncIndex index);
// return last index of log
SyncIndex (*logLastIndex)(struct SSyncLogStore* logStore);
} SSyncLogStore;
typedef struct SSyncServerState {
SyncNodeId voteFor;
SSyncTerm term;
SyncTerm term;
SyncIndex commitIndex;
} SSyncServerState;
typedef struct SSyncClusterConfig {
......@@ -122,9 +133,9 @@ typedef struct SStateManager {
int32_t (*readServerState)(struct SStateManager* stateMng, SSyncServerState* state);
// void (*saveCluster)(struct SStateManager* stateMng, const SSyncClusterConfig* cluster);
void (*saveCluster)(struct SStateManager* stateMng, const SSyncClusterConfig* cluster);
// const SSyncClusterConfig* (*readCluster)(struct SStateManager* stateMng);
const SSyncClusterConfig* (*readCluster)(struct SStateManager* stateMng);
} SStateManager;
typedef struct {
......@@ -146,13 +157,13 @@ SSyncNode* syncStart(const SSyncInfo*);
void syncReconfig(const SSyncNode*, const SSyncCluster*);
void syncStop(const SSyncNode*);
int32_t syncPropose(SSyncNode* syncNode, SSyncBuffer buffer, void* pData, bool isWeak);
int32_t syncPropose(SSyncNode* syncNode, const SSyncBuffer* pBuf, void* pData, bool isWeak);
// int32_t syncAddNode(SSyncNode syncNode, const SNodeInfo *pNode);
int32_t syncAddNode(SSyncNode syncNode, const SNodeInfo *pNode);
// int32_t syncRemoveNode(SSyncNode syncNode, const SNodeInfo *pNode);
int32_t syncRemoveNode(SSyncNode syncNode, const SNodeInfo *pNode);
extern int32_t syncDebugFlag;
extern int32_t sDebugFlag;
#ifdef __cplusplus
}
......
......@@ -22,7 +22,7 @@ extern "C" {
void taosRemoveDir(const char *dirname);
bool taosDirExist(char *dirname);
bool taosMkDir(char *dirname);
bool taosMkDir(const char *dirname);
void taosRemoveOldFiles(char *dirname, int32_t keepDays);
bool taosExpandDir(char *dirname, char *outname, int32_t maxlen);
bool taosRealPath(char *dirname, int32_t maxlen);
......
......@@ -13,40 +13,63 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef _TD_AMALLOC_H_
#define _TD_AMALLOC_H_
#ifndef _TD_META_IMPL_H_
#define _TD_META_IMPL_H_
#include "os.h"
#include "taosmsg.h"
#ifdef __cplusplus
extern "C" {
#endif
typedef uint64_t tb_uid_t;
/* ------------------------ SMetaOptions ------------------------ */
struct SMetaOptions {
size_t lruCacheSize; // LRU cache size
};
/* ------------------------ STbOptions ------------------------ */
#define META_NORMAL_TABLE ((uint8_t)1)
#define META_SUPER_TABLE ((uint8_t)2)
#define META_CHILD_TABLE ((uint8_t)3)
#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);
typedef struct {
} SSMAOptions;
// super table options
typedef struct {
tb_uid_t uid;
STSchema* pSchema;
STSchema* pTagSchema;
} SSTbOptions;
// Interfaces to implement
// child table options
typedef struct {
AMALLOC_APIS
} SMemAllocatorIf;
tb_uid_t suid;
SKVRow tags;
} SCTbOptions;
// normal table options
typedef struct {
void *impl;
AMALLOC_APIS
} SMemAllocator;
STSchema* pSchame;
} SNTbOptions;
#define amalloc(allocator, size) ((allocator) ? (*((allocator)->malloc))((allocator)->impl, (size)) : malloc(size))
#define acalloc(allocator, nmemb, size) \
((allocator) ? (*((allocator)->calloc))((allocator)->impl, (nmemb), (size)) : calloc((nmemb), (size)))
#define arealloc(allocator, ptr, size) \
((allocator) ? (*((allocator)->realloc))((allocator)->impl, (ptr), (size)) : realloc((ptr), (size)))
#define afree(allocator, ptr, size) ((allocator) ? (*((allocator)->free))((allocator)->impl, (ptr), (size)) : free(ptr))
struct STbOptions {
uint8_t type;
char* name;
uint32_t ttl; // time to live in (SECONDS)
SSMAOptions bsma; // Block-wise sma
union {
SSTbOptions stbOptions;
SNTbOptions ntbOptions;
SCTbOptions ctbOptions;
};
};
#ifdef __cplusplus
}
#endif
#endif /*_TD_AMALLOC_H_*/
\ No newline at end of file
#endif /*_TD_META_IMPL_H_*/
\ No newline at end of file
......@@ -16,81 +16,36 @@
#ifndef _TD_META_H_
#define _TD_META_H_
#include "taosmsg.h"
#include "os.h"
#include "impl/metaImpl.h"
#ifdef __cplusplus
extern "C" {
#endif
/* ------------------------ APIs Exposed ------------------------ */
// Types exported
typedef uint64_t tb_uid_t;
typedef struct SMeta SMeta;
typedef struct SMetaOpts SMetaOpts;
typedef struct SMetaQueryHandle SMetaQueryHandle;
typedef struct SMetaQueryOpts SMetaQueryOpts;
typedef struct STableOpts STableOpts;
typedef struct SMeta SMeta;
typedef struct SMetaOptions SMetaOptions;
typedef struct STbOptions STbOptions;
// SMeta operations
int metaCreate(const char *path);
void metaDestroy(const char *path);
SMeta *metaOpen(SMetaOpts *);
SMeta *metaOpen(const char *path, const SMetaOptions *);
void metaClose(SMeta *);
int metaCreateTable(SMeta *, const STableOpts *);
int metaDropTable(SMeta *, uint64_t tuid_t);
int metaAlterTable(SMeta *, void *);
void metaRemove(const char *path);
int metaCreateTable(SMeta *pMeta, const STbOptions *);
int metaDropTable(SMeta *pMeta, tb_uid_t uid);
int metaCommit(SMeta *);
// Options
SMetaOpts *metaOptionsCreate();
void metaOptionsDestroy(SMetaOpts *);
void metaOptionsSetCache(SMetaOpts *, size_t capacity);
// SMetaQueryHandle
SMetaQueryHandle *metaQueryHandleCreate(SMetaQueryOpts *);
void metaQueryHandleDestroy(SMetaQueryHandle *);
// SMetaQueryOpts
SMetaQueryOpts *metaQueryOptionsCreate();
void metaQueryOptionsDestroy(SMetaQueryOpts *);
void metaOptionsInit(SMetaOptions *);
void metaOptionsClear(SMetaOptions *);
// STableOpts
#define META_TABLE_OPTS_DECLARE(name) STableOpts name = {0}
void metaNormalTableOptsInit(STableOpts *, const char *name, const STSchema *pSchema);
void metaSuperTableOptsInit(STableOpts *, const char *name, tb_uid_t uid, const STSchema *pSchema,
void metaNormalTableOptsInit(STbOptions *, const char *name, const STSchema *pSchema);
void metaSuperTableOptsInit(STbOptions *, const char *name, tb_uid_t uid, const STSchema *pSchema,
const STSchema *pTagSchema);
void metaChildTableOptsInit(STableOpts *, const char *name, tb_uid_t suid, const SKVRow tags);
void metaTableOptsClear(STableOpts *);
/* ------------------------ Impl should hidden ------------------------ */
typedef enum { META_INIT_TABLE = 0, META_SUPER_TABLE = 1, META_CHILD_TABLE = 2, META_NORMAL_TABLE = 3 } EMetaTableT;
typedef struct SSuperTableOpts {
tb_uid_t uid;
STSchema *pSchema; // (ts timestamp, a int)
STSchema *pTagSchema; // (tag1 binary(10), tag2 int)
} SSuperTableOpts;
typedef struct SChildTableOpts {
tb_uid_t suid; // super table uid
SKVRow tags; // tag value of the child table
} SChildTableOpts;
typedef struct SNormalTableOpts {
STSchema *pSchema;
} SNormalTableOpts;
struct STableOpts {
int8_t type;
char * name;
union {
SSuperTableOpts superOpts;
SChildTableOpts childOpts;
SNormalTableOpts normalOpts;
};
};
void metaChildTableOptsInit(STbOptions *, const char *name, tb_uid_t suid, const SKVRow tags);
void metaTableOptsClear(STbOptions *);
#ifdef __cplusplus
}
......
......@@ -23,6 +23,7 @@ extern "C" {
#endif
struct STsdbOptions {
size_t lruCacheSize;
/* TODO */
};
......
......@@ -17,14 +17,80 @@
#define _TD_VNODE_H_
#include "os.h"
#include "taosmsg.h"
#include "trpc.h"
#include "trequest.h"
#include "meta.h"
#include "tq.h"
#include "tsdb.h"
#ifdef __cplusplus
extern "C" {
#endif
typedef struct SVnode SVnode;
/* ------------------------ TYPES EXPOSED ------------------------ */
typedef struct SVnode SVnode;
typedef struct SVnodeOptions SVnodeOptions;
/* ------------------------ SVnode ------------------------ */
SVnode *vnodeOpen(const char *path, const SVnodeOptions *pVnodeOptions);
void vnodeClose(SVnode *pVnode);
void vnodeDestroy(const char *path);
int vnodeProcessWriteReqs(SVnode *pVnode, SReqBatch *pReqBatch);
int vnodeApplyWriteRequest(SVnode *pVnode, const SRequest *pRequest);
int vnodeProcessReadReq(SVnode *pVnode, SRequest *pReq);
int vnodeProcessSyncReq(SVnode *pVnode, SRequest *pReq);
/* ------------------------ SVnodeOptions ------------------------ */
void vnodeOptionsInit(SVnodeOptions *);
void vnodeOptionsClear(SVnodeOptions *);
/* ------------------------ STRUCT DEFINITIONS ------------------------ */
struct SVnodeOptions {
/**
* @brief write buffer size in BYTES
*
*/
uint64_t wsize;
/**
* @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
};
/* ------------------------ FOR COMPILE ------------------------ */
#if 1
#include "taosmsg.h"
#include "trpc.h"
typedef struct {
char db[TSDB_FULL_DB_NAME_LEN];
......@@ -71,8 +137,6 @@ typedef struct {
int32_t vnodeInit(SVnodePara);
void vnodeCleanup();
SVnode *vnodeOpen(int32_t vgId, const char *path);
void vnodeClose(SVnode *pVnode);
int32_t vnodeAlter(SVnode *pVnode, const SVnodeCfg *pCfg);
SVnode *vnodeCreate(int32_t vgId, const char *path, const SVnodeCfg *pCfg);
void vnodeDrop(SVnode *pVnode);
......@@ -86,6 +150,8 @@ int32_t vnodeAppendMsg(SVnodeMsg *pMsg, SRpcMsg *pRpcMsg);
void vnodeCleanupMsg(SVnodeMsg *pMsg);
void vnodeProcessMsg(SVnode *pVnode, SVnodeMsg *pMsg, EVnMsgType msgType);
#endif
#ifdef __cplusplus
}
#endif
......
/*
* 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_MALLOCATOR_H_
#define _TD_MALLOCATOR_H_
#include "os.h"
#ifdef __cplusplus
extern "C" {
#endif
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 {
void * impl;
size_t usize;
MALLOCATOR_APIS
};
// heap allocator
SMemAllocator *tdCreateHeapAllocator();
void tdDestroyHeapAllocator(SMemAllocator *pMemAllocator);
// arena allocator
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
}
#endif
#endif /*_TD_MALLOCATOR_H_*/
\ No newline at end of file
......@@ -376,7 +376,7 @@ static void *dnodeOpenVnodeFunc(void *param) {
char path[PATH_MAX + 20] = {0};
snprintf(path, sizeof(path),"%s/vnode%d", tsVnodeDir, pVnode->vgId);
SVnode *pImpl = vnodeOpen(pVnode->vgId, path);
SVnode *pImpl = vnodeOpen(path, NULL);
if (pImpl == NULL) {
dError("vgId:%d, failed to open vnode by thread:%d", pVnode->vgId, pThread->threadIndex);
pThread->failed++;
......
......@@ -7,6 +7,7 @@ target_include_directories(
)
target_link_libraries(
vnode
PUBLIC os
PUBLIC transport
PUBLIC meta
PUBLIC tq
......
/*
* 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_ALLOCATOR_POOL_H_
#define _TD_VNODE_ALLOCATOR_POOL_H_
#include "vnode.h"
#ifdef __cplusplus
extern "C" {
#endif
typedef struct {
int nexta;
int enda;
SMemAllocator *free[3];
SMemAllocator *used[3];
} SVAllocatorPool;
int vnodeOpenAllocatorPool(SVnode *pVnode);
void vnodeCloseAllocatorPool(SVnode *pVnode);
#ifdef __cplusplus
}
#endif
#endif /*_TD_VNODE_ALLOCATOR_POOL_H_*/
\ No newline at end of file
......@@ -16,13 +16,14 @@
#ifndef _TD_VNODE_COMMIT_H_
#define _TD_VNODE_COMMIT_H_
#include "vnodeInt.h"
#include "vnode.h"
#ifdef __cplusplus
extern "C" {
#endif
int vnodeAsyncCommit(SVnode *pVnode);
bool vnodeShouldCommit(SVnode *pVnode);
int vnodeAsyncCommit(SVnode *pVnode);
#ifdef __cplusplus
}
......
/*
* 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_DEF_H_
#define _TD_VNODE_DEF_H_
#include "mallocator.h"
#include "sync.h"
#include "tlockfree.h"
#include "vnode.h"
#include "vnodeAllocatorPool.h"
#include "vnodeCommit.h"
#include "vnodeFileSystem.h"
#include "vnodeOptions.h"
#include "vnodeStateMgr.h"
#include "vnodeSync.h"
#ifdef __cplusplus
extern "C" {
#endif
struct SVnode {
char* path;
SVnodeOptions options;
SVState state;
SVAllocatorPool* pool;
SMemAllocator* inuse;
SMeta* pMeta;
STsdb* pTsdb;
STQ* pTq;
SVnodeSync* pSync;
SVnodeFS* pFs;
};
#ifdef __cplusplus
}
#endif
#endif /*_TD_VNODE_DEF_H_*/
\ No newline at end of file
/*
* 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_FILE_SYSTEM_H_
#define _TD_VNODE_FILE_SYSTEM_H_
#ifdef __cplusplus
extern "C" {
#endif
typedef struct {
} SVnodeFS;
#ifdef __cplusplus
}
#endif
#endif /*_TD_VNODE_FILE_SYSTEM_H_*/
\ No newline at end of file
......@@ -18,7 +18,6 @@
#include "vnode.h"
#include "amalloc.h"
#include "meta.h"
#include "sync.h"
#include "tlog.h"
......@@ -39,16 +38,6 @@ extern int32_t vDebugFlag;
#define vDebug(...) { if (vDebugFlag & DEBUG_DEBUG) { taosPrintLog("VND ", vDebugFlag, __VA_ARGS__); }}
#define vTrace(...) { if (vDebugFlag & DEBUG_TRACE) { taosPrintLog("VND ", vDebugFlag, __VA_ARGS__); }}
typedef struct SVnode {
int32_t vgId;
SVnodeCfg cfg;
SMeta *pMeta;
STsdb *pTsdb;
STQ *pTQ;
SWal *pWal;
SSyncNode *pSync;
} SVnode;
#ifdef __cplusplus
}
#endif
......
......@@ -16,40 +16,12 @@
#ifndef _TD_VNODE_MEM_ALLOCATOR_H_
#define _TD_VNODE_MEM_ALLOCATOR_H_
#include "vnodeInt.h"
#ifdef __cplusplus
extern "C" {
#endif
typedef struct SVnodeMemAllocator SVnodeMemAllocator;
SVnodeMemAllocator *VMACreate(size_t size /* base size */, size_t ssize /* step size */,
size_t threshold /* threshold size when full*/);
void VMADestroy(SVnodeMemAllocator *pvma);
void VMAReset(SVnodeMemAllocator *pvma);
void * VMAMalloc(SVnodeMemAllocator *pvma, size_t size);
void VMAFree(SVnodeMemAllocator *pvma, void *ptr);
bool VMAIsFull(SVnodeMemAllocator *pvma);
// ------------------ FOR TEST ONLY ------------------
typedef struct SVMANode {
struct SVMANode *prev;
size_t tsize;
size_t used;
char data[];
} SVMANode;
struct SVnodeMemAllocator {
bool full; // if allocator is full
size_t threshold; // threshold;
size_t ssize; // step size to allocate
SVMANode *inuse; // inuse node to allocate
SVMANode node; // basic node to use
};
#ifdef __cplusplus
}
#endif
#endif /*_TD_VNODE_MEM_ALLOCATOR_H_*/
\ No newline at end of file
#endif /*_TD_VNODE_MEM_ALLOCATOR_H_*/
/*
* 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_OPTIONS_H_
#define _TD_VNODE_OPTIONS_H_
#include "vnode.h"
#ifdef __cplusplus
extern "C" {
#endif
extern const SVnodeOptions defaultVnodeOptions;
int vnodeValidateOptions(const SVnodeOptions *);
void vnodeOptionsCopy(SVnodeOptions *pDest, const SVnodeOptions *pSrc);
#ifdef __cplusplus
}
#endif
#endif /*_TD_VNODE_OPTIONS_H_*/
\ No newline at end of file
/*
* 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_REQUEST_H_
#define _TD_VNODE_REQUEST_H_
#ifdef __cplusplus
extern "C" {
#endif
#ifdef __cplusplus
}
#endif
#endif /*_TD_VNODE_REQUEST_H_*/
\ No newline at end of file
/*
* 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 {
} SVState;
#ifdef __cplusplus
}
#endif
#endif /*_TD_VNODE_STATE_MGR_H_*/
\ No newline at end of file
/*
* 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_SYNC_H_
#define _TD_VNODE_SYNC_H_
#include "sync.h"
#ifdef __cplusplus
extern "C" {
#endif
typedef struct {
/* data */
} SVnodeSync;
#ifdef __cplusplus
}
#endif
#endif /*_TD_VNODE_SYNC_H_*/
\ No newline at end of file
......@@ -16,10 +16,11 @@
#ifndef _TD_VNODE_WRITE_H_
#define _TD_VNODE_WRITE_H_
#include "vnode.h"
#ifdef __cplusplus
extern "C" {
#endif
#include "vnodeInt.h"
void vnodeProcessWriteMsg(SVnode* pVnode, SVnodeMsg* pMsg);
......
/*
* 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"
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
}
\ No newline at end of file
......@@ -13,13 +13,15 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "vnodeInt.h"
#include "vnodeDef.h"
static int vnodeStartCommit(SVnode *pVnode);
static int vnodeEndCommit(SVnode *pVnode);
bool vnodeShouldCommit(SVnode *pVnode) { return false; }
int vnodeAsyncCommit(SVnode *pVnode) {
#if 0
#if 0
if (vnodeStartCommit(pVnode) < 0) {
// TODO
}
......
/*
* 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"
\ No newline at end of file
......@@ -20,8 +20,6 @@
int32_t vnodeInit(SVnodePara para) { return 0; }
void vnodeCleanup() {}
SVnode *vnodeOpen(int32_t vgId, const char *path) { return NULL; }
void vnodeClose(SVnode *pVnode) {}
int32_t vnodeAlter(SVnode *pVnode, const SVnodeCfg *pCfg) { return 0; }
SVnode *vnodeCreate(int32_t vgId, const char *path, const SVnodeCfg *pCfg) { return NULL; }
void vnodeDrop(SVnode *pVnode) {}
......@@ -69,4 +67,4 @@ void vnodeProcessMsg(SVnode *pVnode, SVnodeMsg *pMsg, EVnMsgType msgType) {
case VN_MSG_TYPE_FETCH:
break;
}
}
}
\ No newline at end of file
/*
* 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"
static SVnode *vnodeNew(const char *path, const SVnodeOptions *pVnodeOptions);
static void vnodeFree(SVnode *pVnode);
static int vnodeOpenImpl(SVnode *pVnode);
static void vnodeCloseImpl(SVnode *pVnode);
SVnode *vnodeOpen(const char *path, const SVnodeOptions *pVnodeOptions) {
SVnode *pVnode = NULL;
// Set default options
if (pVnodeOptions == NULL) {
pVnodeOptions = &defaultVnodeOptions;
}
// Validate options
if (vnodeValidateOptions(pVnodeOptions) < 0) {
// TODO
return NULL;
}
// Create the handle
pVnode = vnodeNew(path, pVnodeOptions);
if (pVnode == NULL) {
// TODO: handle error
return NULL;
}
taosMkDir(path);
// Open the vnode
if (vnodeOpenImpl(pVnode) < 0) {
// TODO: handle error
return NULL;
}
return pVnode;
}
void vnodeClose(SVnode *pVnode) {
if (pVnode) {
vnodeCloseImpl(pVnode);
vnodeFree(pVnode);
}
}
void vnodeDestroy(const char *path) { taosRemoveDir(path); }
/* ------------------------ STATIC METHODS ------------------------ */
static SVnode *vnodeNew(const char *path, const SVnodeOptions *pVnodeOptions) {
SVnode *pVnode = NULL;
pVnode = (SVnode *)calloc(1, sizeof(*pVnode));
if (pVnode == NULL) {
// TODO
return NULL;
}
pVnode->path = strdup(path);
vnodeOptionsCopy(&(pVnode->options), pVnodeOptions);
return pVnode;
}
static void vnodeFree(SVnode *pVnode) {
if (pVnode) {
tfree(pVnode->path);
free(pVnode);
}
}
static int vnodeOpenImpl(SVnode *pVnode) {
char dir[TSDB_FILENAME_LEN];
// Open allocator pool
if (vnodeOpenAllocatorPool(pVnode) < 0) {
// TODO: handle error
return -1;
}
// Open meta
sprintf(dir, "%s/meta", pVnode->path);
pVnode->pMeta = metaOpen(dir, &(pVnode->options.metaOptions));
if (pVnode->pMeta == NULL) {
// TODO: handle error
return -1;
}
// Open tsdb
sprintf(dir, "%s/tsdb", pVnode->path);
pVnode->pTsdb = tsdbOpen(dir, &(pVnode->options.tsdbOptions));
if (pVnode->pTsdb == NULL) {
// TODO: handle error
return -1;
}
// TODO: Open TQ
// TODO
return 0;
}
static void vnodeCloseImpl(SVnode *pVnode) {
if (pVnode) {
vnodeCloseAllocatorPool(pVnode);
// TODO: Close TQ
tsdbClose(pVnode->pTsdb);
metaClose(pVnode->pMeta);
}
}
\ No newline at end of file
......@@ -13,112 +13,88 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "vnodeMemAllocator.h"
#define VMA_IS_FULL(pvma) \
(((pvma)->inuse != &((pvma)->node)) || ((pvma)->inuse->tsize - (pvma)->inuse->used < (pvma)->threshold))
static SVMANode *VMANodeNew(size_t size);
static void VMANodeFree(SVMANode *node);
SVnodeMemAllocator *VMACreate(size_t size, size_t ssize, size_t threshold) {
SVnodeMemAllocator *pvma = NULL;
#include "vnodeDef.h"
#define VNODE_HEAP_ALLOCATOR 0
#define VNODE_ARENA_ALLOCATOR 1
typedef struct {
uint64_t tsize;
uint64_t used;
} SVHeapAllocator;
typedef struct SVArenaNode {
struct SVArenaNode *prev;
void * nptr;
char data[];
} SVArenaNode;
typedef struct {
SVArenaNode *inuse;
SVArenaNode node;
} SVArenaAllocator;
typedef struct {
int8_t type;
uint64_t tsize;
T_REF_DECLARE()
union {
SVHeapAllocator vha;
SVArenaAllocator vaa;
};
} SVMemAllocator;
SMemAllocator *vnodeCreateMemAllocator(int8_t type, uint64_t tsize, uint64_t ssize /* step size only for arena */) {
SMemAllocator * pma;
uint64_t msize;
SVMemAllocator *pva;
msize = sizeof(*pma) + sizeof(SVMemAllocator);
if (type == VNODE_ARENA_ALLOCATOR) {
msize += tsize;
}
if (size < threshold) {
pma = (SMemAllocator *)calloc(1, msize);
if (pma == NULL) {
return NULL;
}
pvma = (SVnodeMemAllocator *)malloc(sizeof(*pvma) + size);
if (pvma) {
pvma->full = false;
pvma->threshold = threshold;
pvma->ssize = ssize;
pvma->inuse = &(pvma->node);
pvma->inuse->prev = NULL;
pvma->inuse->tsize = size;
pvma->inuse->used = 0;
pma->impl = POINTER_SHIFT(pma, sizeof(*pma));
pva = (SVMemAllocator *)(pma->impl);
pva->type = type;
pva->tsize = tsize;
if (type == VNODE_HEAP_ALLOCATOR) {
pma->malloc = NULL;
pma->calloc = NULL;
pma->realloc = NULL;
pma->free = NULL;
pma->usage = NULL;
} else if (type == VNODE_ARENA_ALLOCATOR) {
pma->malloc = NULL;
pma->calloc = NULL;
pma->realloc = NULL;
pma->free = NULL;
pma->usage = NULL;
} else {
ASSERT(0);
}
return pvma;
return pma;
}
void VMADestroy(SVnodeMemAllocator *pvma) {
if (pvma) {
VMAReset(pvma);
free(pvma);
}
void vnodeDestroyMemAllocator(SMemAllocator *pma) {
// TODO
}
void VMAReset(SVnodeMemAllocator *pvma) {
while (pvma->inuse != &(pvma->node)) {
SVMANode *node = pvma->inuse;
pvma->inuse = node->prev;
VMANodeFree(node);
}
pvma->inuse->used = 0;
pvma->full = false;
void vnodeRefMemAllocator(SMemAllocator *pma) {
// TODO
}
void *VMAMalloc(SVnodeMemAllocator *pvma, size_t size) {
void * ptr = NULL;
size_t tsize = size + sizeof(size_t);
if (pvma->inuse->tsize - pvma->inuse->used < tsize) {
SVMANode *pNode = VMANodeNew(MAX(pvma->ssize, tsize));
if (pNode == NULL) {
return NULL;
}
pNode->prev = pvma->inuse;
pvma->inuse = pNode;
}
ptr = pvma->inuse->data + pvma->inuse->used;
pvma->inuse->used += tsize;
*(size_t *)ptr = size;
ptr = POINTER_SHIFT(ptr, sizeof(size_t));
pvma->full = VMA_IS_FULL(pvma);
return ptr;
}
void VMAFree(SVnodeMemAllocator *pvma, void *ptr) {
if (ptr) {
size_t size = *(size_t *)POINTER_SHIFT(ptr, -sizeof(size_t));
if (POINTER_SHIFT(ptr, size) == pvma->inuse->data + pvma->inuse->used) {
pvma->inuse->used -= (size + sizeof(size_t));
if ((pvma->inuse->used == 0) && (pvma->inuse != &(pvma->node))) {
SVMANode *node = pvma->inuse;
pvma->inuse = node->prev;
VMANodeFree(node);
}
pvma->full = VMA_IS_FULL(pvma);
}
}
void vnodeUnrefMemAllocator(SMemAllocator *pma) {
// TODO
}
bool VMAIsFull(SVnodeMemAllocator *pvma) { return pvma->full; }
/* ------------------------ Heap Allocator IMPL ------------------------ */
static SVMANode *VMANodeNew(size_t size) {
SVMANode *node = NULL;
node = (SVMANode *)malloc(sizeof(*node) + size);
if (node) {
node->prev = NULL;
node->tsize = size;
node->used = 0;
}
return node;
}
static void VMANodeFree(SVMANode *node) {
if (node) {
free(node);
}
}
\ No newline at end of file
/* ------------------------ Arena Allocator IMPL ------------------------ */
\ No newline at end of file
/*
* 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"
const SVnodeOptions defaultVnodeOptions = {0}; /* TODO */
void vnodeOptionsInit(SVnodeOptions *pVnodeOptions) { /* TODO */
vnodeOptionsCopy(pVnodeOptions, &defaultVnodeOptions);
}
void vnodeOptionsClear(SVnodeOptions *pVnodeOptions) { /* TODO */
}
int vnodeValidateOptions(const SVnodeOptions *pVnodeOptions) {
// TODO
return 0;
}
void vnodeOptionsCopy(SVnodeOptions *pDest, const SVnodeOptions *pSrc) {
memcpy((void *)pDest, (void *)pSrc, sizeof(SVnodeOptions));
}
\ No newline at end of file
......@@ -13,5 +13,4 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#define _DEFAULT_SOURCE
#include "vnodeRead.h"
#include "vnodeDef.h"
\ No newline at end of file
/*
* 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/>.
*/
\ No newline at end of file
/*
* 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/>.
*/
\ No newline at end of file
/*
* 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/>.
*/
\ No newline at end of file
......@@ -13,5 +13,50 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#define _DEFAULT_SOURCE
#include "vnodeWrite.h"
#include "vnodeDef.h"
int vnodeProcessWriteReqs(SVnode *pVnode, SReqBatch *pReqBatch) {
/* TODO */
return 0;
}
int vnodeApplyWriteRequest(SVnode *pVnode, const SRequest *pRequest) {
int reqType; /* TODO */
size_t reqSize; /* TODO */
uint64_t reqVersion = 0; /* TODO */
int code = 0;
// Copy the request to vnode buffer
SRequest *pReq = mMalloc(pVnode->inuse, reqSize);
if (pReq == NULL) {
// TODO: handle error
}
memcpy(pReq, pRequest, reqSize);
// Push the request to TQ so consumers can consume
tqPushMsg(pVnode->pTq, pReq, 0);
// Process the request
switch (reqType) {
case TSDB_MSG_TYPE_CREATE_TABLE:
code = metaCreateTable(pVnode->pMeta, NULL /* TODO */);
break;
case TSDB_MSG_TYPE_DROP_TABLE:
code = metaDropTable(pVnode->pMeta, 0 /* TODO */);
break;
/* TODO */
default:
break;
}
if (vnodeShouldCommit(pVnode)) {
if (vnodeAsyncCommit(pVnode) < 0) {
// TODO: handle error
}
}
return code;
}
/* ------------------------ STATIC METHODS ------------------------ */
\ No newline at end of file
# vnodeMemAllocatorTest
add_executable(VMATest "")
target_sources(VMATest
# Vnode API test
add_executable(vnodeApiTests "")
target_sources(vnodeApiTests
PRIVATE
"../src/vnodeMemAllocator.c"
"vnodeMemAllocatorTest.cpp"
"vnodeApiTests.cpp"
)
target_include_directories(VMATest PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/../inc")
target_link_libraries(VMATest os gtest_main vnode)
\ No newline at end of file
target_link_libraries(vnodeApiTests vnode gtest gtest_main)
\ No newline at end of file
#include <gtest/gtest.h>
#include <iostream>
#include "vnode.h"
TEST(vnodeApiTest, vnodeOpen_vnodeClose_test) {
// Create and open a vnode
SVnode *pVnode = vnodeOpen("vnode1", NULL);
ASSERT_NE(pVnode, nullptr);
// Close the vnode
vnodeClose(pVnode);
}
#include <gtest/gtest.h>
#include <iostream>
#include "vnodeMemAllocator.h"
TEST(VMATest, basic_create_and_destroy_test) {
SVnodeMemAllocator *vma = VMACreate(1024, 512, 64);
EXPECT_TRUE(vma != nullptr);
EXPECT_EQ(vma->full, false);
EXPECT_EQ(vma->ssize, 512);
EXPECT_EQ(vma->threshold, 64);
EXPECT_EQ(vma->inuse->tsize, 1024);
VMADestroy(vma);
vma = VMACreate(1024, 512, 1024);
EXPECT_TRUE(vma != nullptr);
VMADestroy(vma);
vma = VMACreate(1024, 512, 1025);
EXPECT_TRUE(vma == nullptr);
VMADestroy(vma);
}
\ No newline at end of file
/*
* 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_META_CACHE_H_
#define _TD_META_CACHE_H_
#include "rocksdb/c.h"
#include "meta.h"
#ifdef __cplusplus
extern "C" {
#endif
typedef rocksdb_cache_t meta_cache_t;
int metaOpenCache(SMeta *pMeta);
void metaCloseCache(SMeta *pMeta);
#ifdef __cplusplus
}
#endif
#endif /*_TD_META_CACHE_H_*/
\ No newline at end of file
/*
* 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_META_DB_H_
#define _TD_META_DB_H_
#include "rocksdb/c.h"
#include "meta.h"
#ifdef __cplusplus
extern "C" {
#endif
typedef struct {
rocksdb_t *tbDb; // uid -> tb obj
rocksdb_t *nameDb; // name -> uid
rocksdb_t *tagDb; // uid -> tag
rocksdb_t *schemaDb; // uid+version -> schema
rocksdb_t *mapDb; // suid -> uid_list
} meta_db_t;
int metaOpenDB(SMeta *pMeta);
void metaCloseDB(SMeta *pMeta);
int metaSaveTableToDB(SMeta *pMeta, const STbOptions *pTbOptions);
int metaRemoveTableFromDb(SMeta *pMeta, tb_uid_t uid);
#ifdef __cplusplus
}
#endif
#endif /*_TD_META_DB_H_*/
\ No newline at end of file
......@@ -16,22 +16,26 @@
#ifndef _TD_META_DEF_H_
#define _TD_META_DEF_H_
#include "metaUid.h"
#include "tkv.h"
#include "meta.h"
#include "metaCache.h"
#include "metaDB.h"
#include "metaIdx.h"
#include "metaOptions.h"
#include "metaTbOptions.h"
#include "metaTbTag.h"
#include "metaTbUid.h"
#ifdef __cplusplus
extern "C" {
#endif
struct SMeta {
STableUidGenerator uidGenerator;
STkvDb* tableDb; // uid->table obj
STkvDb* tbnameDb; // tbname --> uid
STkvDb* schemaDb; // uid+version --> schema
STkvDb* tagDb; // uid --> tag
STkvDb* tagIdx; // TODO: need to integrate lucene or our own
// STkvCache* metaCache; // TODO: add a global cache here
char* path; // path of current meta
SMetaOptions options; // meta option
meta_db_t* pDB; // raw data db
meta_index_t* pIdx; // tag index
meta_cache_t* pCache; // LRU cache
STbUidGenerator uidGnrt; // meta table UID generator
};
#ifdef __cplusplus
......
/*
* 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_META_IDX_H_
#define _TD_META_IDX_H_
#include "rocksdb/c.h"
#include "meta.h"
#ifdef __cplusplus
extern "C" {
#endif
typedef rocksdb_t meta_index_t;
int metaOpenIdx(SMeta *pMeta);
void metaCloseIdx(SMeta *pMeta);
int metaSaveTableToIdx(SMeta *pMeta, const STbOptions *pTbOptions);
int metaRemoveTableFromIdx(SMeta *pMeta, tb_uid_t uid);
#ifdef __cplusplus
}
#endif
#endif /*_TD_META_IDX_H_*/
\ No newline at end of file
/*
* 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_META_OPTIONS_H_
#define _TD_META_OPTIONS_H_
#include "meta.h"
#ifdef __cplusplus
extern "C" {
#endif
extern const SMetaOptions defaultMetaOptions;
int metaValidateOptions(const SMetaOptions *);
void metaOptionsCopy(SMetaOptions *pDest, const SMetaOptions *pSrc);
#ifdef __cplusplus
}
#endif
#endif /*_TD_META_OPTIONS_H_*/
\ No newline at end of file
/*
* 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_META_QUERY_H_
#define _TD_META_QUERY_H_
#ifdef __cplusplus
extern "C" {
#endif
#ifdef __cplusplus
}
#endif
#endif /*_TD_META_QUERY_H_*/
\ No newline at end of file
/*
* 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_META_TABLE_OPTIONS_H_
#define _TD_META_TABLE_OPTIONS_H_
#include "meta.h"
#ifdef __cplusplus
extern "C" {
#endif
int metaValidateTbOptions(SMeta *pMeta, const STbOptions *);
size_t metaEncodeTbObjFromTbOptions(const STbOptions *, void *pBuf, size_t bsize);
#ifdef __cplusplus
}
#endif
#endif /*_TD_META_TABLE_OPTIONS_H_*/
\ No newline at end of file
/*
* 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_META_TB_TAG_H_
#define _TD_META_TB_TAG_H_
#ifdef __cplusplus
extern "C" {
#endif
#ifdef __cplusplus
}
#endif
#endif /*_TD_META_TB_TAG_H_*/
\ No newline at end of file
......@@ -23,20 +23,17 @@ extern "C" {
#endif
/* ------------------------ APIS EXPOSED ------------------------ */
typedef struct STableUidGenerator STableUidGenerator;
// tb_uid_t
#define IVLD_TB_UID 0
tb_uid_t generateUid(STableUidGenerator *);
typedef struct STbUidGenerator {
tb_uid_t nextUid;
} STbUidGenerator;
// STableUidGenerator
void tableUidGeneratorInit(STableUidGenerator *, tb_uid_t suid);
#define tableUidGeneratorClear(ug)
int metaOpenUidGnrt(SMeta *pMeta);
void metaCloseUidGnrt(SMeta *pMeta);
/* ------------------------ FOR TEST AND COMPILE ONLY ------------------------ */
struct STableUidGenerator {
tb_uid_t nextUid;
};
// tb_uid_t
#define IVLD_TB_UID 0
tb_uid_t metaGenerateUid(SMeta *pMeta);
#ifdef __cplusplus
}
......
/*
* 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 "meta.h"
#include "metaDef.h"
int metaOpenCache(SMeta *pMeta) {
// TODO
if (pMeta->options.lruCacheSize) {
pMeta->pCache = rocksdb_cache_create_lru(pMeta->options.lruCacheSize);
if (pMeta->pCache == NULL) {
// TODO: handle error
return -1;
}
}
return 0;
}
void metaCloseCache(SMeta *pMeta) {
if (pMeta->pCache) {
rocksdb_cache_destroy(pMeta->pCache);
pMeta->pCache = NULL;
}
}
\ No newline at end of file
/*
* 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 "meta.h"
int metaCommit(SMeta *pMeta) {
// TODO
return 0;
}
\ No newline at end of file
/*
* 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 "metaDef.h"
static void metaSaveSchemaDB(SMeta *pMeta, tb_uid_t uid, STSchema *pSchema);
static void metaGetSchemaDBKey(char key[], tb_uid_t uid, int sversion);
static int metaSaveMapDB(SMeta *pMeta, tb_uid_t suid, tb_uid_t uid);
#define SCHEMA_KEY_LEN (sizeof(tb_uid_t) + sizeof(int))
#define META_OPEN_DB_IMPL(pDB, options, dir, err) \
do { \
pDB = rocksdb_open(options, dir, &err); \
if (pDB == NULL) { \
metaCloseDB(pMeta); \
rocksdb_options_destroy(options); \
return -1; \
} \
} while (0)
int metaOpenDB(SMeta *pMeta) {
char dir[128];
char * err = NULL;
rocksdb_options_t *options = rocksdb_options_create();
if (pMeta->pCache) {
rocksdb_options_set_row_cache(options, pMeta->pCache);
}
rocksdb_options_set_create_if_missing(options, 1);
pMeta->pDB = (meta_db_t *)calloc(1, sizeof(*(pMeta->pDB)));
if (pMeta->pDB == NULL) {
// TODO: handle error
rocksdb_options_destroy(options);
return -1;
}
// tbDb
sprintf(dir, "%s/tb_db", pMeta->path);
META_OPEN_DB_IMPL(pMeta->pDB->tbDb, options, dir, err);
// nameDb
sprintf(dir, "%s/name_db", pMeta->path);
META_OPEN_DB_IMPL(pMeta->pDB->nameDb, options, dir, err);
// tagDb
sprintf(dir, "%s/tag_db", pMeta->path);
META_OPEN_DB_IMPL(pMeta->pDB->tagDb, options, dir, err);
// schemaDb
sprintf(dir, "%s/schema_db", pMeta->path);
META_OPEN_DB_IMPL(pMeta->pDB->schemaDb, options, dir, err);
// mapDb
sprintf(dir, "%s/map_db", pMeta->path);
META_OPEN_DB_IMPL(pMeta->pDB->mapDb, options, dir, err);
rocksdb_options_destroy(options);
return 0;
}
#define META_CLOSE_DB_IMPL(pDB) \
do { \
if (pDB) { \
rocksdb_close(pDB); \
pDB = NULL; \
} \
} while (0)
void metaCloseDB(SMeta *pMeta) {
if (pMeta->pDB) {
META_CLOSE_DB_IMPL(pMeta->pDB->mapDb);
META_CLOSE_DB_IMPL(pMeta->pDB->schemaDb);
META_CLOSE_DB_IMPL(pMeta->pDB->tagDb);
META_CLOSE_DB_IMPL(pMeta->pDB->nameDb);
META_CLOSE_DB_IMPL(pMeta->pDB->tbDb);
free(pMeta->pDB);
pMeta->pDB = NULL;
}
}
int metaSaveTableToDB(SMeta *pMeta, const STbOptions *pTbOptions) {
tb_uid_t uid;
char * err = NULL;
size_t size;
char pBuf[1024]; // TODO
rocksdb_writeoptions_t *wopt = rocksdb_writeoptions_create();
// Generate a uid for child and normal table
if (pTbOptions->type == META_SUPER_TABLE) {
uid = pTbOptions->stbOptions.uid;
} else {
uid = metaGenerateUid(pMeta);
}
// Save tbname -> uid to tbnameDB
rocksdb_put(pMeta->pDB->nameDb, wopt, pTbOptions->name, strlen(pTbOptions->name), (char *)(&uid), sizeof(uid), &err);
// Save uid -> tb_obj to tbDB
size = metaEncodeTbObjFromTbOptions(pTbOptions, pBuf, 1024);
rocksdb_put(pMeta->pDB->tbDb, wopt, (char *)(&uid), sizeof(uid), pBuf, size, &err);
switch (pTbOptions->type) {
case META_NORMAL_TABLE:
// save schemaDB
metaSaveSchemaDB(pMeta, uid, pTbOptions->ntbOptions.pSchame);
break;
case META_SUPER_TABLE:
// save schemaDB
metaSaveSchemaDB(pMeta, uid, pTbOptions->stbOptions.pSchema);
// save mapDB (really need?)
rocksdb_put(pMeta->pDB->mapDb, wopt, (char *)(&uid), sizeof(uid), "", 0, &err);
break;
case META_CHILD_TABLE:
// save tagDB
rocksdb_put(pMeta->pDB->tagDb, wopt, (char *)(&uid), sizeof(uid), pTbOptions->ctbOptions.tags,
kvRowLen(pTbOptions->ctbOptions.tags), &err);
// save mapDB
metaSaveMapDB(pMeta, pTbOptions->ctbOptions.suid, uid);
break;
default:
ASSERT(0);
}
rocksdb_writeoptions_destroy(wopt);
return 0;
}
int metaRemoveTableFromDb(SMeta *pMeta, tb_uid_t uid) {
/* TODO */
return 0;
}
/* ------------------------ STATIC METHODS ------------------------ */
static void metaSaveSchemaDB(SMeta *pMeta, tb_uid_t uid, STSchema *pSchema) {
char key[64];
char pBuf[1024];
char * ppBuf = pBuf;
size_t vsize;
char * err = NULL;
rocksdb_writeoptions_t *wopt = rocksdb_writeoptions_create();
metaGetSchemaDBKey(key, uid, schemaVersion(pSchema));
vsize = tdEncodeSchema((void **)(&ppBuf), pSchema);
rocksdb_put(pMeta->pDB->schemaDb, wopt, key, SCHEMA_KEY_LEN, pBuf, vsize, &err);
rocksdb_writeoptions_destroy(wopt);
}
static void metaGetSchemaDBKey(char *key, tb_uid_t uid, int sversion) {
*(tb_uid_t *)key = uid;
*(int *)POINTER_SHIFT(key, sizeof(tb_uid_t)) = sversion;
}
static int metaSaveMapDB(SMeta *pMeta, tb_uid_t suid, tb_uid_t uid) {
size_t vlen;
char * val;
char * err = NULL;
rocksdb_readoptions_t *ropt = rocksdb_readoptions_create();
val = rocksdb_get(pMeta->pDB->mapDb, ropt, (char *)(&suid), sizeof(suid), &vlen, &err);
rocksdb_readoptions_destroy(ropt);
void *nval = malloc(vlen + sizeof(uid));
if (nval == NULL) {
return -1;
}
if (vlen) {
memcpy(nval, val, vlen);
}
memcpy(POINTER_SHIFT(nval, vlen), (void *)(&uid), sizeof(uid));
rocksdb_writeoptions_t *wopt = rocksdb_writeoptions_create();
rocksdb_put(pMeta->pDB->mapDb, wopt, (char *)(&suid), sizeof(suid), nval, vlen + sizeof(uid), &err);
rocksdb_writeoptions_destroy(wopt);
return 0;
}
\ No newline at end of file
/*
* 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 "metaDef.h"
int metaOpenIdx(SMeta *pMeta) {
char idxDir[128]; // TODO
char * err = NULL;
rocksdb_options_t *options = rocksdb_options_create();
// TODO
sprintf(idxDir, "%s/index", pMeta->path);
if (pMeta->pCache) {
rocksdb_options_set_row_cache(options, pMeta->pCache);
}
rocksdb_options_set_create_if_missing(options, 1);
pMeta->pIdx = rocksdb_open(options, idxDir, &err);
if (pMeta->pIdx == NULL) {
// TODO: handle error
rocksdb_options_destroy(options);
return -1;
}
rocksdb_options_destroy(options);
return 0;
}
void metaCloseIdx(SMeta *pMeta) { /* TODO */
if (pMeta->pIdx) {
rocksdb_close(pMeta->pIdx);
pMeta->pIdx = NULL;
}
}
int metaSaveTableToIdx(SMeta *pMeta, const STbOptions *pTbOptions) {
// TODO
return 0;
}
\ No newline at end of file
......@@ -13,75 +13,134 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "tcoding.h"
#include "meta.h"
#include "metaDB.h"
#include "metaDef.h"
#include "tcoding.h"
#include "metaOptions.h"
static int metaCreateSuperTable(SMeta *pMeta, const char *tbname, const SSuperTableOpts *pSuperTableOpts);
static int metaCreateChildTable(SMeta *pMeta, const char *tbname, const SChildTableOpts *pChildTableOpts);
static int metaCreateNormalTable(SMeta *pMeta, const char *tbname, const SNormalTableOpts *pNormalTableOpts);
static SMeta *metaNew(const char *path, const SMetaOptions *pMetaOptions);
static void metaFree(SMeta *pMeta);
static int metaOpenImpl(SMeta *pMeta);
static void metaCloseImpl(SMeta *pMeta);
SMeta *metaOpen(SMetaOpts *pMetaOpts) {
SMeta *metaOpen(const char *path, const SMetaOptions *pMetaOptions) {
SMeta *pMeta = NULL;
pMeta = (SMeta *)calloc(1, sizeof(*pMeta));
// Set default options
if (pMetaOptions == NULL) {
pMetaOptions = &defaultMetaOptions;
}
// Validate the options
if (metaValidateOptions(pMetaOptions) < 0) {
// TODO: deal with error
return NULL;
}
// Allocate handle
pMeta = metaNew(path, pMetaOptions);
if (pMeta == NULL) {
// TODO: handle error
return NULL;
}
// Create META path (TODO)
taosMkDir(path);
// Open meta
if (metaOpenImpl(pMeta) < 0) {
metaFree(pMeta);
return NULL;
}
// TODO: check if file exists and handle the error
taosMkDir("meta");
// Open tableDb
STkvOpts *tableDbOpts = tkvOptsCreate();
tkvOptsSetCreateIfMissing(tableDbOpts, 1);
pMeta->tableDb = tkvOpen(tableDbOpts, "meta/table_db");
tkvOptsDestroy(tableDbOpts);
// Open tbnameDb
STkvOpts *tbnameDbOpts = tkvOptsCreate();
tkvOptsSetCreateIfMissing(tbnameDbOpts, 1);
pMeta->tbnameDb = tkvOpen(tbnameDbOpts, "meta/tbname_db");
tkvOptsDestroy(tbnameDbOpts);
// Open schemaDb
STkvOpts *schemaDbOpts = tkvOptsCreate();
tkvOptsSetCreateIfMissing(schemaDbOpts, 1);
pMeta->schemaDb = tkvOpen(schemaDbOpts, "meta/schema_db");
tkvOptsDestroy(schemaDbOpts);
// Open tagDb
STkvOpts *tagDbOpts = tkvOptsCreate();
tkvOptsSetCreateIfMissing(tagDbOpts, 1);
pMeta->tagDb = tkvOpen(tagDbOpts, "meta/tag_db");
tkvOptsDestroy(tagDbOpts);
// Open tagIdx
STkvOpts *tagIdxDbOpts = tkvOptsCreate();
tkvOptsSetCreateIfMissing(tagIdxDbOpts, 1);
pMeta->tagIdx = tkvOpen(tagIdxDbOpts, "meta/tag_idx_db");
tkvOptsDestroy(tagIdxDbOpts);
// TODO: need to figure out how to persist the START UID
tableUidGeneratorInit(&(pMeta->uidGenerator), IVLD_TB_UID);
return pMeta;
}
void metaClose(SMeta *pMeta) {
if (pMeta) {
tableUidGeneratorClear(&pMeta->uidGenerator);
metaCloseImpl(pMeta);
metaFree(pMeta);
}
}
void metaRemove(const char *path) { taosRemoveDir(path); }
/* ------------------------ STATIC METHODS ------------------------ */
static SMeta *metaNew(const char *path, const SMetaOptions *pMetaOptions) {
SMeta *pMeta;
size_t psize = strlen(path);
pMeta = (SMeta *)calloc(1, sizeof(*pMeta));
if (pMeta == NULL) {
return NULL;
}
tkvClose(pMeta->tagIdx);
tkvClose(pMeta->tagDb);
tkvClose(pMeta->schemaDb);
tkvClose(pMeta->tbnameDb);
tkvClose(pMeta->tableDb);
pMeta->path = strdup(path);
if (pMeta->path == NULL) {
metaFree(pMeta);
return NULL;
}
metaOptionsCopy(&(pMeta->options), pMetaOptions);
return pMeta;
};
static void metaFree(SMeta *pMeta) {
if (pMeta) {
tfree(pMeta->path);
free(pMeta);
}
}
int metaCreateTable(SMeta *pMeta, const STableOpts *pTableOpts) {
static int metaOpenImpl(SMeta *pMeta) {
// Open meta cache
if (metaOpenCache(pMeta) < 0) {
// TODO: handle error
metaCloseImpl(pMeta);
return -1;
}
// Open meta db
if (metaOpenDB(pMeta) < 0) {
// TODO: handle error
metaCloseImpl(pMeta);
return -1;
}
// Open meta index
if (metaOpenIdx(pMeta) < 0) {
// TODO: handle error
metaCloseImpl(pMeta);
return -1;
}
// Open meta table uid generator
if (metaOpenUidGnrt(pMeta) < 0) {
// TODO: handle error
metaCloseImpl(pMeta);
return -1;
}
return 0;
}
static void metaCloseImpl(SMeta *pMeta) {
metaCloseUidGnrt(pMeta);
metaCloseIdx(pMeta);
metaCloseDB(pMeta);
metaCloseCache(pMeta);
}
// OLD -------------------------------------------------------------------
#if 0
static int metaCreateSuperTable(SMeta *pMeta, const char *tbname, const SSuperTableOpts *pSuperTableOpts);
static int metaCreateChildTable(SMeta *pMeta, const char *tbname, const SChildTableOpts *pChildTableOpts);
static int metaCreateNormalTable(SMeta *pMeta, const char *tbname, const SNormalTableOpts *pNormalTableOpts);
int metaCreateTable(SMeta *pMeta, const STableOptions *pTableOpts) {
size_t vallen;
char * pUid;
......@@ -107,7 +166,6 @@ int metaCreateTable(SMeta *pMeta, const STableOpts *pTableOpts) {
return 0;
}
/* ------------------------ STATIC METHODS ------------------------ */
static int metaCreateSuperTable(SMeta *pMeta, const char *tbname, const SSuperTableOpts *pSuperTableOpts) {
size_t vallen;
size_t keylen;
......@@ -213,13 +271,13 @@ static int metaCreateNormalTable(SMeta *pMeta, const char *tbname, const SNormal
return 0;
}
void metaNormalTableOptsInit(STableOpts *pTableOpts, const char *name, const STSchema *pSchema) {
void metaNormalTableOptsInit(STableOptions *pTableOpts, const char *name, const STSchema *pSchema) {
pTableOpts->type = META_NORMAL_TABLE;
pTableOpts->name = strdup(name);
pTableOpts->normalOpts.pSchema = tdDupSchema(pSchema);
}
void metaSuperTableOptsInit(STableOpts *pTableOpts, const char *name, tb_uid_t uid, const STSchema *pSchema,
void metaSuperTableOptsInit(STableOptions *pTableOpts, const char *name, tb_uid_t uid, const STSchema *pSchema,
const STSchema *pTagSchema) {
pTableOpts->type = META_SUPER_TABLE;
pTableOpts->name = strdup(name);
......@@ -228,14 +286,14 @@ void metaSuperTableOptsInit(STableOpts *pTableOpts, const char *name, tb_uid_t u
pTableOpts->superOpts.pTagSchema = tdDupSchema(pTagSchema);
}
void metaChildTableOptsInit(STableOpts *pTableOpts, const char *name, tb_uid_t suid, const SKVRow tags) {
void metaChildTableOptsInit(STableOptions *pTableOpts, const char *name, tb_uid_t suid, const SKVRow tags) {
pTableOpts->type = META_CHILD_TABLE;
pTableOpts->name = strdup(name);
pTableOpts->childOpts.suid = suid;
pTableOpts->childOpts.tags = tdKVRowDup(tags);
}
void metaTableOptsClear(STableOpts *pTableOpts) {
void metaTableOptsClear(STableOptions *pTableOpts) {
switch (pTableOpts->type) {
case META_NORMAL_TABLE:
tfree(pTableOpts->name);
......@@ -258,3 +316,5 @@ void metaTableOptsClear(STableOpts *pTableOpts) {
}
void metaDestroy(const char *path) { taosRemoveDir(path); }
#endif
\ No newline at end of file
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
......@@ -22,6 +22,9 @@
//
//handle management message
//
int tqGetgHandleSSize(const TqGroupHandle *gHandle);
static int tqProtoCheck(TmqMsgHead *pMsg) {
return pMsg->protoVer == 0;
}
......
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册