提交 9001468b 编写于 作者: H Hongze Cheng

refact

上级 416e6354
......@@ -18,6 +18,7 @@
#include "os.h"
#include "tbuffer.h"
#include "tdataformat.h"
#include "tdef.h"
#include "tschema.h"
......@@ -91,8 +92,8 @@ typedef struct {
} SRowBuilder;
typedef struct {
SSchema *pSchema;
SRow * pRow;
STSchema *pSchema;
SRow * pRow;
} SRowReader;
typedef struct {
......
......@@ -25,7 +25,8 @@ extern "C" {
typedef uint16_t col_id_t;
typedef struct SColumn {
#if 0
typedef struct STColumn {
/// column name
char *cname;
union {
......@@ -45,9 +46,9 @@ typedef struct SColumn {
};
/// comment about the column
char *comment;
} SColumn;
} STColumn;
typedef struct SSchema {
typedef struct STSchema {
/// schema version
uint16_t sver;
/// number of columns
......@@ -58,20 +59,22 @@ typedef struct SSchema {
SArray *smaArray;
};
/// column info
SColumn cols[];
} SSchema;
STColumn cols[];
} STSchema;
typedef struct {
uint64_t size;
SSchema *pSchema;
} SShemaBuilder;
uint64_t size;
STSchema *pSchema;
} STShemaBuilder;
#define tSchemaBuilderInit(target, capacity) \
{ .size = (capacity), .pSchema = (target) }
void tSchemaBuilderSetSver(SShemaBuilder *pSchemaBuilder, uint16_t sver);
void tSchemaBuilderSetSver(STShemaBuilder *pSchemaBuilder, uint16_t sver);
void tSchemaBuilderSetSMA(bool sma, SArray *smaArray);
int tSchemaBuilderPutColumn(char *cname, bool sma, uint8_t type, col_id_t cid, uint32_t bytes, char *comment);
#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_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)
typedef struct {
} SSMAOptions;
// super table options
typedef struct {
tb_uid_t uid;
STSchema* pSchema;
STSchema* pTagSchema;
} SSTbOptions;
// child table options
typedef struct {
tb_uid_t suid;
SKVRow tags;
} SCTbOptions;
// normal table options
typedef struct {
STSchema* pSchame;
} SNTbOptions;
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_META_IMPL_H_*/
\ No newline at end of file
......@@ -16,38 +16,75 @@
#ifndef _TD_META_H_
#define _TD_META_H_
#include "impl/metaImpl.h"
#include "os.h"
#include "trow.h"
#ifdef __cplusplus
extern "C" {
#endif
// Types exported
typedef struct SMeta SMeta;
typedef struct SMetaOptions SMetaOptions;
typedef struct STbOptions STbOptions;
typedef uint64_t tb_uid_t;
typedef struct SMeta SMeta;
typedef struct SMetaCfg {
/// LRU cache size
uint64_t lruSize;
} SMetaCfg;
typedef struct STbCfg {
/// name of the table
char *name;
/// time to live of the table
uint32_t ttl;
/// type of table
uint8_t type;
union {
/// super table configurations
struct {
/// super table UID
tb_uid_t suid;
/// row schema
STSchema *pSchema;
/// tag schema
STSchema *pTagSchema;
} stbCfg;
/// normal table configuration
struct {
/// row schema
STSchema *pSchema;
} ntbCfg;
/// child table configuration
struct {
/// super table UID
tb_uid_t suid;
SRow * pTag;
} ctbCfg;
};
} STbCfg;
// SMeta operations
SMeta *metaOpen(const char *path, const SMetaOptions *pOptions);
SMeta *metaOpen(const char *path, const SMetaCfg *pOptions);
void metaClose(SMeta *pMeta);
void metaRemove(const char *path);
int metaCreateTable(SMeta *pMeta, const STbOptions *pTbOptions);
int metaCreateTable(SMeta *pMeta, const STbCfg *pTbOptions);
int metaDropTable(SMeta *pMeta, tb_uid_t uid);
int metaCommit(SMeta *pMeta);
// Options
void metaOptionsInit(SMetaOptions *pOptions);
void metaOptionsClear(SMetaOptions *pOptions);
void metaOptionsInit(SMetaCfg *pOptions);
void metaOptionsClear(SMetaCfg *pOptions);
// STableOpts
#define META_TABLE_OPTS_DECLARE(name) STableOpts name = {0}
void metaNormalTableOptsInit(STbOptions *pTbOptions, const char *name, const STSchema *pSchema);
void metaSuperTableOptsInit(STbOptions *pTbOptions, const char *name, tb_uid_t uid, const STSchema *pSchema,
const STSchema *pTagSchema);
void metaChildTableOptsInit(STbOptions *pTbOptions, const char *name, tb_uid_t suid, const SKVRow tags);
void metaTableOptsClear(STbOptions *pTbOptions);
uint64_t metaEncodeTbOptions(void **pBuf, STbOptions *pTbOptions);
STbOptions *metaDecodeTbOptions(void *pBuf, size_t size, bool endian);
// #define META_TABLE_OPTS_DECLARE(name) STableOpts name = {0}
// void metaNormalTableOptsInit(STbCfg *pTbOptions, const char *name, const STSchema *pSchema);
// void metaSuperTableOptsInit(STbCfg *pTbOptions, const char *name, tb_uid_t uid, const STSchema *pSchema,
// const STSchema *pTagSchema);
// void metaChildTableOptsInit(STbCfg *pTbOptions, const char *name, tb_uid_t suid, const SKVRow tags);
// void metaTableOptsClear(STbCfg *pTbOptions);
// uint64_t metaEncodeTbOptions(void **pBuf, STbCfg *pTbOptions);
// STbCfg * metaDecodeTbOptions(void *pBuf, size_t size, bool endian);
#ifdef __cplusplus
}
......
......@@ -29,8 +29,8 @@ extern "C" {
#endif
/* ------------------------ TYPES EXPOSED ------------------------ */
typedef struct SVnode SVnode;
typedef struct SVnodeOptions SVnodeOptions;
typedef struct SVnode SVnode;
typedef struct SVnodeCfg SVnodeCfg;
/* ------------------------ SVnode ------------------------ */
/**
......@@ -40,7 +40,7 @@ typedef struct SVnodeOptions SVnodeOptions;
* @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 SVnodeCfg *pVnodeOptions);
/**
* @brief Close a VNODE
......@@ -85,23 +85,23 @@ int vnodeApplyWMsg(SVnode *pVnode, SRpcMsg *pMsg, SRpcMsg **pRsp);
*/
int vnodeProcessSyncReq(SVnode *pVnode, SRpcMsg *pMsg, SRpcMsg **pRsp);
/* ------------------------ SVnodeOptions ------------------------ */
/* ------------------------ SVnodeCfg ------------------------ */
/**
* @brief Initialize VNODE options.
*
* @param pOptions The options object to be initialized. It should not be NULL.
*/
void vnodeOptionsInit(SVnodeOptions *pOptions);
void vnodeOptionsInit(SVnodeCfg *pOptions);
/**
* @brief Clear VNODE options.
*
* @param pOptions Options to clear.
*/
void vnodeOptionsClear(SVnodeOptions *pOptions);
void vnodeOptionsClear(SVnodeCfg *pOptions);
/* ------------------------ STRUCT DEFINITIONS ------------------------ */
struct SVnodeOptions {
struct SVnodeCfg {
/**
* @brief write buffer size in BYTES
*
......@@ -137,7 +137,7 @@ struct SVnodeOptions {
* @brief META options
*
*/
SMetaOptions metaOptions;
SMetaCfg metaOptions;
// STqOptions tqOptions; // TODO
};
......@@ -148,27 +148,27 @@ struct SVnodeOptions {
#include "taosmsg.h"
#include "trpc.h"
typedef struct {
char db[TSDB_FULL_DB_NAME_LEN];
int32_t cacheBlockSize; // MB
int32_t totalBlocks;
int32_t daysPerFile;
int32_t daysToKeep0;
int32_t daysToKeep1;
int32_t daysToKeep2;
int32_t minRowsPerFileBlock;
int32_t maxRowsPerFileBlock;
int8_t precision; // time resolution
int8_t compression;
int8_t cacheLastRow;
int8_t update;
int8_t quorum;
int8_t replica;
int8_t selfIndex;
int8_t walLevel;
int32_t fsyncPeriod; // millisecond
SReplica replicas[TSDB_MAX_REPLICA];
} SVnodeCfg;
// typedef struct {
// char db[TSDB_FULL_DB_NAME_LEN];
// int32_t cacheBlockSize; // MB
// int32_t totalBlocks;
// int32_t daysPerFile;
// int32_t daysToKeep0;
// int32_t daysToKeep1;
// int32_t daysToKeep2;
// int32_t minRowsPerFileBlock;
// int32_t maxRowsPerFileBlock;
// int8_t precision; // time resolution
// int8_t compression;
// int8_t cacheLastRow;
// int8_t update;
// int8_t quorum;
// int8_t replica;
// int8_t selfIndex;
// int8_t walLevel;
// int32_t fsyncPeriod; // millisecond
// SReplica replicas[TSDB_MAX_REPLICA];
// } SVnodeCfg;
typedef enum {
VN_MSG_TYPE_WRITE = 1,
......
......@@ -15,8 +15,8 @@
#define _DEFAULT_SOURCE
#include "dnodeVnodes.h"
#include "dnodeTransport.h"
#include "cJSON.h"
#include "dnodeTransport.h"
#include "thash.h"
#include "tlockfree.h"
#include "tqueue.h"
......@@ -30,7 +30,7 @@ typedef struct {
int32_t refCount;
int8_t dropped;
int8_t accessState;
SVnode *pImpl;
SVnode * pImpl;
taos_queue pWriteQ;
taos_queue pSyncQ;
taos_queue pApplyQ;
......@@ -48,14 +48,14 @@ typedef struct {
} SVThread;
static struct {
SHashObj *hash;
SHashObj * hash;
SWorkerPool mgmtPool;
SWorkerPool queryPool;
SWorkerPool fetchPool;
SMWorkerPool syncPool;
SMWorkerPool writePool;
taos_queue pMgmtQ;
SSteps *pSteps;
SSteps * pSteps;
int32_t openVnodes;
int32_t totalVnodes;
SRWLatch latch;
......@@ -169,7 +169,7 @@ static SVnodeObj **dnodeGetVnodesFromHash(int32_t *numOfVnodes) {
void *pIter = taosHashIterate(tsVnodes.hash, NULL);
while (pIter) {
SVnodeObj **ppVnode = pIter;
SVnodeObj *pVnode = *ppVnode;
SVnodeObj * pVnode = *ppVnode;
if (pVnode) {
num++;
if (num < size) {
......@@ -191,14 +191,14 @@ static int32_t dnodeGetVnodesFromFile(SVnodeObj **ppVnodes, int32_t *numOfVnodes
int32_t code = TSDB_CODE_DND_PARSE_VNODE_FILE_ERROR;
int32_t len = 0;
int32_t maxLen = 30000;
char *content = calloc(1, maxLen + 1);
cJSON *root = NULL;
FILE *fp = NULL;
char * content = calloc(1, maxLen + 1);
cJSON * root = NULL;
FILE * fp = NULL;
char file[PATH_MAX + 20] = {0};
SVnodeObj *pVnodes = NULL;
snprintf(file, PATH_MAX + 20, "%s/vnodes.json", tsVnodeDir);
fp = fopen(file, "r");
if (!fp) {
dDebug("file %s not exist", file);
......@@ -238,7 +238,7 @@ static int32_t dnodeGetVnodesFromFile(SVnodeObj **ppVnodes, int32_t *numOfVnodes
}
for (int32_t i = 0; i < vnodesNum; ++i) {
cJSON *vnode = cJSON_GetArrayItem(vnodes, i);
cJSON * vnode = cJSON_GetArrayItem(vnodes, i);
SVnodeObj *pVnode = &pVnodes[i];
cJSON *vgId = cJSON_GetObjectItem(vnode, "vgId");
......@@ -281,7 +281,7 @@ static int32_t dnodeWriteVnodesToFile() {
int32_t len = 0;
int32_t maxLen = 30000;
char *content = calloc(1, maxLen + 1);
char * content = calloc(1, maxLen + 1);
int32_t numOfVnodes = 0;
SVnodeObj **pVnodes = dnodeGetVnodesFromHash(&numOfVnodes);
......@@ -322,7 +322,7 @@ static int32_t dnodeCreateVnode(int32_t vgId, SVnodeCfg *pCfg) {
int32_t code = 0;
char path[PATH_MAX + 20] = {0};
snprintf(path, sizeof(path),"%s/vnode%d", tsVnodeDir, vgId);
snprintf(path, sizeof(path), "%s/vnode%d", tsVnodeDir, vgId);
SVnode *pImpl = vnodeCreate(vgId, path, pCfg);
if (pImpl == NULL) {
......@@ -375,7 +375,7 @@ static void *dnodeOpenVnodeFunc(void *param) {
dnodeReportStartup("open-vnodes", stepDesc);
char path[PATH_MAX + 20] = {0};
snprintf(path, sizeof(path),"%s/vnode%d", tsVnodeDir, pVnode->vgId);
snprintf(path, sizeof(path), "%s/vnode%d", tsVnodeDir, pVnode->vgId);
SVnode *pImpl = vnodeOpen(path, NULL);
if (pImpl == NULL) {
dError("vgId:%d, failed to open vnode by thread:%d", pVnode->vgId, pThread->threadIndex);
......@@ -481,6 +481,7 @@ static int32_t dnodeParseCreateVnodeReq(SRpcMsg *rpcMsg, int32_t *vgId, SVnodeCf
SCreateVnodeMsg *pCreate = rpcMsg->pCont;
*vgId = htonl(pCreate->vgId);
#if 0
tstrncpy(pCfg->db, pCreate->db, TSDB_FULL_DB_NAME_LEN);
pCfg->cacheBlockSize = htonl(pCreate->cacheBlockSize);
pCfg->totalBlocks = htonl(pCreate->totalBlocks);
......@@ -503,6 +504,7 @@ static int32_t dnodeParseCreateVnodeReq(SRpcMsg *rpcMsg, int32_t *vgId, SVnodeCf
pCfg->replicas[i].port = htons(pCreate->replicas[i].port);
tstrncpy(pCfg->replicas[i].fqdn, pCreate->replicas[i].fqdn, TSDB_FQDN_LEN);
}
#endif
return 0;
}
......@@ -668,7 +670,7 @@ static void dnodeProcessVnodeMgmtQueue(void *unused, SRpcMsg *pMsg) {
break;
case TSDB_MSG_TYPE_AUTH_VNODE_IN:
code = vnodeProcessAuthVnodeReq(pMsg);
break;
break;
case TSDB_MSG_TYPE_SYNC_VNODE_IN:
code = vnodeProcessSyncVnodeReq(pMsg);
break;
......@@ -696,7 +698,7 @@ static void dnodeProcessVnodeFetchQueue(SVnodeObj *pVnode, SVnodeMsg *pMsg) {
static void dnodeProcessVnodeWriteQueue(SVnodeObj *pVnode, taos_qall qall, int32_t numOfMsgs) {
SVnodeMsg *pMsg = vnodeInitMsg(numOfMsgs);
SRpcMsg *pRpcMsg = NULL;
SRpcMsg * pRpcMsg = NULL;
for (int32_t i = 0; i < numOfMsgs; ++i) {
taosGetQitem(qall, (void **)&pRpcMsg);
......@@ -1008,7 +1010,7 @@ void dnodeGetVnodeLoads(SVnodeLoads *pLoads) {
pLoads->num = taosHashGetSize(tsVnodes.hash);
int32_t v = 0;
void *pIter = taosHashIterate(tsVnodes.hash, NULL);
void * pIter = taosHashIterate(tsVnodes.hash, NULL);
while (pIter) {
SVnodeObj **ppVnode = pIter;
if (ppVnode == NULL) continue;
......
......@@ -13,8 +13,8 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef _TD_VNODE_OPTIONS_H_
#define _TD_VNODE_OPTIONS_H_
#ifndef _TD_VNODE_CFG_H_
#define _TD_VNODE_CFG_H_
#include "vnode.h"
......@@ -22,13 +22,13 @@
extern "C" {
#endif
extern const SVnodeOptions defaultVnodeOptions;
extern const SVnodeCfg defaultVnodeOptions;
int vnodeValidateOptions(const SVnodeOptions *);
void vnodeOptionsCopy(SVnodeOptions *pDest, const SVnodeOptions *pSrc);
int vnodeValidateOptions(const SVnodeCfg *);
void vnodeOptionsCopy(SVnodeCfg *pDest, const SVnodeCfg *pSrc);
#ifdef __cplusplus
}
#endif
#endif /*_TD_VNODE_OPTIONS_H_*/
\ No newline at end of file
#endif /*_TD_VNODE_CFG_H_*/
\ No newline at end of file
......@@ -25,7 +25,7 @@
#include "vnodeBufferPool.h"
#include "vnodeCommit.h"
#include "vnodeFileSystem.h"
#include "vnodeOptions.h"
#include "vnodeCfg.h"
#include "vnodeStateMgr.h"
#include "vnodeSync.h"
......@@ -34,16 +34,16 @@ extern "C" {
#endif
struct SVnode {
char* path;
SVnodeOptions options;
SVState state;
SVBufPool* pBufPool;
SMeta* pMeta;
STsdb* pTsdb;
STQ* pTq;
SWal* pWal;
SVnodeSync* pSync;
SVnodeFS* pFs;
char* path;
SVnodeCfg config;
SVState state;
SVBufPool* pBufPool;
SMeta* pMeta;
STsdb* pTsdb;
STQ* pTq;
SWal* pWal;
SVnodeSync* pSync;
SVnodeFS* pFs;
};
#ifdef __cplusplus
......
......@@ -84,8 +84,8 @@ int vnodeOpenBufPool(SVnode *pVnode) {
tdListInit(&(pVnode->pBufPool->free), 0);
tdListInit(&(pVnode->pBufPool->incycle), 0);
capacity = pVnode->options.wsize / VNODE_BUF_POOL_SHARDS;
if (pVnode->options.isHeapAllocator) {
capacity = pVnode->config.wsize / VNODE_BUF_POOL_SHARDS;
if (pVnode->config.isHeapAllocator) {
type = E_V_HEAP_ALLOCATOR;
}
......
......@@ -15,20 +15,20 @@
#include "vnodeDef.h"
const SVnodeOptions defaultVnodeOptions = {0}; /* TODO */
const SVnodeCfg defaultVnodeOptions = {0}; /* TODO */
void vnodeOptionsInit(SVnodeOptions *pVnodeOptions) { /* TODO */
void vnodeOptionsInit(SVnodeCfg *pVnodeOptions) { /* TODO */
vnodeOptionsCopy(pVnodeOptions, &defaultVnodeOptions);
}
void vnodeOptionsClear(SVnodeOptions *pVnodeOptions) { /* TODO */
void vnodeOptionsClear(SVnodeCfg *pVnodeOptions) { /* TODO */
}
int vnodeValidateOptions(const SVnodeOptions *pVnodeOptions) {
int vnodeValidateOptions(const SVnodeCfg *pVnodeOptions) {
// TODO
return 0;
}
void vnodeOptionsCopy(SVnodeOptions *pDest, const SVnodeOptions *pSrc) {
memcpy((void *)pDest, (void *)pSrc, sizeof(SVnodeOptions));
void vnodeOptionsCopy(SVnodeCfg *pDest, const SVnodeCfg *pSrc) {
memcpy((void *)pDest, (void *)pSrc, sizeof(SVnodeCfg));
}
\ No newline at end of file
......@@ -15,27 +15,27 @@
#include "vnodeDef.h"
static SVnode *vnodeNew(const char *path, const SVnodeOptions *pVnodeOptions);
static SVnode *vnodeNew(const char *path, const SVnodeCfg *pVnodeCfg);
static void vnodeFree(SVnode *pVnode);
static int vnodeOpenImpl(SVnode *pVnode);
static void vnodeCloseImpl(SVnode *pVnode);
SVnode *vnodeOpen(const char *path, const SVnodeOptions *pVnodeOptions) {
SVnode *vnodeOpen(const char *path, const SVnodeCfg *pVnodeCfg) {
SVnode *pVnode = NULL;
// Set default options
if (pVnodeOptions == NULL) {
pVnodeOptions = &defaultVnodeOptions;
if (pVnodeCfg == NULL) {
pVnodeCfg = &defaultVnodeOptions;
}
// Validate options
if (vnodeValidateOptions(pVnodeOptions) < 0) {
if (vnodeValidateOptions(pVnodeCfg) < 0) {
// TODO
return NULL;
}
// Create the handle
pVnode = vnodeNew(path, pVnodeOptions);
pVnode = vnodeNew(path, pVnodeCfg);
if (pVnode == NULL) {
// TODO: handle error
return NULL;
......@@ -62,7 +62,7 @@ void vnodeClose(SVnode *pVnode) {
void vnodeDestroy(const char *path) { taosRemoveDir(path); }
/* ------------------------ STATIC METHODS ------------------------ */
static SVnode *vnodeNew(const char *path, const SVnodeOptions *pVnodeOptions) {
static SVnode *vnodeNew(const char *path, const SVnodeCfg *pVnodeCfg) {
SVnode *pVnode = NULL;
pVnode = (SVnode *)calloc(1, sizeof(*pVnode));
......@@ -72,7 +72,7 @@ static SVnode *vnodeNew(const char *path, const SVnodeOptions *pVnodeOptions) {
}
pVnode->path = strdup(path);
vnodeOptionsCopy(&(pVnode->options), pVnodeOptions);
vnodeOptionsCopy(&(pVnode->config), pVnodeCfg);
return pVnode;
}
......@@ -94,7 +94,7 @@ static int vnodeOpenImpl(SVnode *pVnode) {
// Open meta
sprintf(dir, "%s/meta", pVnode->path);
pVnode->pMeta = metaOpen(dir, &(pVnode->options.metaOptions));
pVnode->pMeta = metaOpen(dir, &(pVnode->config.metaOptions));
if (pVnode->pMeta == NULL) {
// TODO: handle error
return -1;
......@@ -102,7 +102,7 @@ static int vnodeOpenImpl(SVnode *pVnode) {
// Open tsdb
sprintf(dir, "%s/tsdb", pVnode->path);
pVnode->pTsdb = tsdbOpen(dir, &(pVnode->options.tsdbOptions));
pVnode->pTsdb = tsdbOpen(dir, &(pVnode->config.tsdbOptions));
if (pVnode->pTsdb == NULL) {
// TODO: handle error
return -1;
......
......@@ -13,8 +13,8 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef _TD_META_OPTIONS_H_
#define _TD_META_OPTIONS_H_
#ifndef _TD_META_CFG_H_
#define _TD_META_CFG_H_
#include "meta.h"
......@@ -22,13 +22,13 @@
extern "C" {
#endif
extern const SMetaOptions defaultMetaOptions;
extern const SMetaCfg defaultMetaOptions;
int metaValidateOptions(const SMetaOptions *);
void metaOptionsCopy(SMetaOptions *pDest, const SMetaOptions *pSrc);
int metaValidateOptions(const SMetaCfg *);
void metaOptionsCopy(SMetaCfg *pDest, const SMetaCfg *pSrc);
#ifdef __cplusplus
}
#endif
#endif /*_TD_META_OPTIONS_H_*/
\ No newline at end of file
#endif /*_TD_META_CFG_H_*/
\ No newline at end of file
......@@ -34,7 +34,7 @@ typedef struct {
int metaOpenDB(SMeta *pMeta);
void metaCloseDB(SMeta *pMeta);
int metaSaveTableToDB(SMeta *pMeta, const STbOptions *pTbOptions);
int metaSaveTableToDB(SMeta *pMeta, const STbCfg *pTbOptions);
int metaRemoveTableFromDb(SMeta *pMeta, tb_uid_t uid);
#ifdef __cplusplus
......
......@@ -20,10 +20,10 @@
#include "meta.h"
#include "metaCache.h"
#include "metaCfg.h"
#include "metaDB.h"
#include "metaIdx.h"
#include "metaOptions.h"
#include "metaTbOptions.h"
#include "metaTbCfg.h"
#include "metaTbTag.h"
#include "metaTbUid.h"
......@@ -33,7 +33,7 @@ extern "C" {
struct SMeta {
char* path;
SMetaOptions options;
SMetaCfg options;
meta_db_t* pDB;
meta_index_t* pIdx;
meta_cache_t* pCache;
......
......@@ -28,7 +28,7 @@ typedef rocksdb_t meta_index_t;
int metaOpenIdx(SMeta *pMeta);
void metaCloseIdx(SMeta *pMeta);
int metaSaveTableToIdx(SMeta *pMeta, const STbOptions *pTbOptions);
int metaSaveTableToIdx(SMeta *pMeta, const STbCfg *pTbOptions);
int metaRemoveTableFromIdx(SMeta *pMeta, tb_uid_t uid);
#ifdef __cplusplus
......
......@@ -13,8 +13,8 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef _TD_META_TABLE_OPTIONS_H_
#define _TD_META_TABLE_OPTIONS_H_
#ifndef _TD_META_TABLE_CFG_H_
#define _TD_META_TABLE_CFG_H_
#include "meta.h"
......@@ -22,11 +22,15 @@
extern "C" {
#endif
int metaValidateTbOptions(SMeta *pMeta, const STbOptions *);
size_t metaEncodeTbObjFromTbOptions(const STbOptions *, void *pBuf, size_t bsize);
#define META_SUPER_TABLE 0
#define META_CHILD_TABLE 1
#define META_NORMAL_TABLE 2
int metaValidateTbOptions(SMeta *pMeta, const STbCfg *);
size_t metaEncodeTbObjFromTbOptions(const STbCfg *, void *pBuf, size_t bsize);
#ifdef __cplusplus
}
#endif
#endif /*_TD_META_TABLE_OPTIONS_H_*/
\ No newline at end of file
#endif /*_TD_META_TABLE_CFG_H_*/
\ No newline at end of file
......@@ -18,8 +18,8 @@
int metaOpenCache(SMeta *pMeta) {
// TODO
if (pMeta->options.lruCacheSize) {
pMeta->pCache = rocksdb_cache_create_lru(pMeta->options.lruCacheSize);
if (pMeta->options.lruSize) {
pMeta->pCache = rocksdb_cache_create_lru(pMeta->options.lruSize);
if (pMeta->pCache == NULL) {
// TODO: handle error
return -1;
......
......@@ -15,20 +15,20 @@
#include "metaDef.h"
const SMetaOptions defaultMetaOptions = {.lruCacheSize = 0};
const SMetaCfg defaultMetaOptions = {.lruSize = 0};
/* ------------------------ EXPOSED METHODS ------------------------ */
void metaOptionsInit(SMetaOptions *pMetaOptions) { metaOptionsCopy(pMetaOptions, &defaultMetaOptions); }
void metaOptionsInit(SMetaCfg *pMetaOptions) { metaOptionsCopy(pMetaOptions, &defaultMetaOptions); }
void metaOptionsClear(SMetaOptions *pMetaOptions) {
void metaOptionsClear(SMetaCfg *pMetaOptions) {
// TODO
}
int metaValidateOptions(const SMetaOptions *pMetaOptions) {
int metaValidateOptions(const SMetaCfg *pMetaOptions) {
// TODO
return 0;
}
void metaOptionsCopy(SMetaOptions *pDest, const SMetaOptions *pSrc) { memcpy(pDest, pSrc, sizeof(*pSrc)); }
void metaOptionsCopy(SMetaCfg *pDest, const SMetaCfg *pSrc) { memcpy(pDest, pSrc, sizeof(*pSrc)); }
/* ------------------------ STATIC METHODS ------------------------ */
\ No newline at end of file
......@@ -92,7 +92,7 @@ void metaCloseDB(SMeta *pMeta) {
}
}
int metaSaveTableToDB(SMeta *pMeta, const STbOptions *pTbOptions) {
int metaSaveTableToDB(SMeta *pMeta, const STbCfg *pTbOptions) {
tb_uid_t uid;
char * err = NULL;
size_t size;
......@@ -102,7 +102,7 @@ int metaSaveTableToDB(SMeta *pMeta, const STbOptions *pTbOptions) {
// Generate a uid for child and normal table
if (pTbOptions->type == META_SUPER_TABLE) {
uid = pTbOptions->stbOptions.uid;
uid = pTbOptions->stbCfg.suid;
} else {
uid = metaGenerateUid(pMeta);
}
......@@ -117,22 +117,22 @@ int metaSaveTableToDB(SMeta *pMeta, const STbOptions *pTbOptions) {
switch (pTbOptions->type) {
case META_NORMAL_TABLE:
// save schemaDB
metaSaveSchemaDB(pMeta, uid, pTbOptions->ntbOptions.pSchame);
metaSaveSchemaDB(pMeta, uid, pTbOptions->ntbCfg.pSchema);
break;
case META_SUPER_TABLE:
// save schemaDB
metaSaveSchemaDB(pMeta, uid, pTbOptions->stbOptions.pSchema);
metaSaveSchemaDB(pMeta, uid, pTbOptions->stbCfg.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);
rocksdb_put(pMeta->pDB->tagDb, wopt, (char *)(&uid), sizeof(uid), pTbOptions->ctbCfg.pTag,
kvRowLen(pTbOptions->ctbCfg.pTag), &err);
// save mapDB
metaSaveMapDB(pMeta, pTbOptions->ctbOptions.suid, uid);
metaSaveMapDB(pMeta, pTbOptions->ctbCfg.suid, uid);
break;
default:
ASSERT(0);
......
......@@ -47,7 +47,7 @@ void metaCloseIdx(SMeta *pMeta) { /* TODO */
}
}
int metaSaveTableToIdx(SMeta *pMeta, const STbOptions *pTbOptions) {
int metaSaveTableToIdx(SMeta *pMeta, const STbCfg *pTbOptions) {
// TODO
return 0;
}
\ No newline at end of file
......@@ -15,17 +15,14 @@
#include "tcoding.h"
#include "meta.h"
#include "metaDB.h"
#include "metaDef.h"
#include "metaOptions.h"
static SMeta *metaNew(const char *path, const SMetaOptions *pMetaOptions);
static SMeta *metaNew(const char *path, const SMetaCfg *pMetaOptions);
static void metaFree(SMeta *pMeta);
static int metaOpenImpl(SMeta *pMeta);
static void metaCloseImpl(SMeta *pMeta);
SMeta *metaOpen(const char *path, const SMetaOptions *pMetaOptions) {
SMeta *metaOpen(const char *path, const SMetaCfg *pMetaOptions) {
SMeta *pMeta = NULL;
// Set default options
......@@ -68,7 +65,7 @@ void metaClose(SMeta *pMeta) {
void metaRemove(const char *path) { taosRemoveDir(path); }
/* ------------------------ STATIC METHODS ------------------------ */
static SMeta *metaNew(const char *path, const SMetaOptions *pMetaOptions) {
static SMeta *metaNew(const char *path, const SMetaCfg *pMetaOptions) {
SMeta *pMeta;
size_t psize = strlen(path);
......
......@@ -15,7 +15,7 @@
#include "metaDef.h"
int metaCreateTable(SMeta *pMeta, const STbOptions *pTbOptions) {
int metaCreateTable(SMeta *pMeta, const STbCfg *pTbOptions) {
// Validate the tbOptions
if (metaValidateTbOptions(pMeta, pTbOptions) < 0) {
// TODO: handle error
......
......@@ -16,12 +16,12 @@
#include "metaDef.h"
#include "tcoding.h"
int metaValidateTbOptions(SMeta *pMeta, const STbOptions *pTbOptions) {
int metaValidateTbOptions(SMeta *pMeta, const STbCfg *pTbOptions) {
// TODO
return 0;
}
size_t metaEncodeTbObjFromTbOptions(const STbOptions *pTbOptions, void *pBuf, size_t bsize) {
size_t metaEncodeTbObjFromTbOptions(const STbCfg *pTbOptions, void *pBuf, size_t bsize) {
void **ppBuf = &pBuf;
int tlen = 0;
......@@ -31,12 +31,12 @@ size_t metaEncodeTbObjFromTbOptions(const STbOptions *pTbOptions, void *pBuf, si
switch (pTbOptions->type) {
case META_SUPER_TABLE:
tlen += taosEncodeFixedU64(ppBuf, pTbOptions->stbOptions.uid);
tlen += tdEncodeSchema(ppBuf, pTbOptions->stbOptions.pTagSchema);
tlen += taosEncodeFixedU64(ppBuf, pTbOptions->stbCfg.suid);
tlen += tdEncodeSchema(ppBuf, pTbOptions->stbCfg.pTagSchema);
// TODO: encode schema version array
break;
case META_CHILD_TABLE:
tlen += taosEncodeFixedU64(ppBuf, pTbOptions->ctbOptions.suid);
tlen += taosEncodeFixedU64(ppBuf, pTbOptions->ctbCfg.suid);
break;
case META_NORMAL_TABLE:
// TODO: encode schema version array
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册