From 9728ec02fe1508732c38a092201707e546128f5c Mon Sep 17 00:00:00 2001 From: Hongze Cheng Date: Tue, 12 Oct 2021 13:42:12 +0800 Subject: [PATCH] refact --- include/common/schema.h | 76 ----------------------------- include/server/vnode/meta/meta.h | 27 +++++----- source/server/vnode/meta/src/meta.c | 13 ++++- 3 files changed, 26 insertions(+), 90 deletions(-) diff --git a/include/common/schema.h b/include/common/schema.h index ccc91f09ff..5e9057520b 100644 --- a/include/common/schema.h +++ b/include/common/schema.h @@ -16,86 +16,10 @@ #ifndef _TD_COMMON_SCHEMA_H_ #define _TD_COMMON_SCHEMA_H_ -#include "os.h" - #ifdef __cplusplus extern "C" { #endif -// ----------------- TSDB COLUMN DEFINITION -typedef struct { - int8_t type; // Column type - int16_t colId; // column ID - int16_t bytes; // column bytes (restore to int16_t in case of misuse) - uint16_t offset; // point offset in SDataRow after the header part. -} STColumn; - -#define colType(col) ((col)->type) -#define colColId(col) ((col)->colId) -#define colBytes(col) ((col)->bytes) -#define colOffset(col) ((col)->offset) - -#define colSetType(col, t) (colType(col) = (t)) -#define colSetColId(col, id) (colColId(col) = (id)) -#define colSetBytes(col, b) (colBytes(col) = (b)) -#define colSetOffset(col, o) (colOffset(col) = (o)) - -// ----------------- TSDB SCHEMA DEFINITION -typedef struct { - int version; // version - int numOfCols; // Number of columns appended - int tlen; // maximum length of a SDataRow without the header part (sizeof(VarDataOffsetT) + sizeof(VarDataLenT) + // - // (bytes)) - uint16_t flen; // First part length in a SDataRow after the header part - uint16_t vlen; // pure value part length, excluded the overhead (bytes only) - STColumn columns[]; -} STSchema; - -#define schemaNCols(s) ((s)->numOfCols) -#define schemaVersion(s) ((s)->version) -#define schemaTLen(s) ((s)->tlen) -#define schemaFLen(s) ((s)->flen) -#define schemaVLen(s) ((s)->vlen) -#define schemaColAt(s, i) ((s)->columns + i) -#define tdFreeSchema(s) tfree((s)) - -STSchema *tdDupSchema(STSchema *pSchema); -int tdEncodeSchema(void **buf, STSchema *pSchema); -void * tdDecodeSchema(void *buf, STSchema **pRSchema); - -static FORCE_INLINE int comparColId(const void *key1, const void *key2) { - if (*(int16_t *)key1 > ((STColumn *)key2)->colId) { - return 1; - } else if (*(int16_t *)key1 < ((STColumn *)key2)->colId) { - return -1; - } else { - return 0; - } -} - -static FORCE_INLINE STColumn *tdGetColOfID(STSchema *pSchema, int16_t colId) { - void *ptr = bsearch(&colId, (void *)pSchema->columns, schemaNCols(pSchema), sizeof(STColumn), comparColId); - if (ptr == NULL) return NULL; - return (STColumn *)ptr; -} - -// ----------------- SCHEMA BUILDER DEFINITION -typedef struct { - int tCols; - int nCols; - int tlen; - uint16_t flen; - uint16_t vlen; - int version; - STColumn *columns; -} STSchemaBuilder; - -int tdInitTSchemaBuilder(STSchemaBuilder *pBuilder, int32_t version); -void tdDestroyTSchemaBuilder(STSchemaBuilder *pBuilder); -void tdResetTSchemaBuilder(STSchemaBuilder *pBuilder, int32_t version); -int tdAddColToSchema(STSchemaBuilder *pBuilder, int8_t type, int16_t colId, int16_t bytes); -STSchema *tdGetSchemaFromBuilder(STSchemaBuilder *pBuilder); - #ifdef __cplusplus } #endif diff --git a/include/server/vnode/meta/meta.h b/include/server/vnode/meta/meta.h index bfa11b9c39..f639ed243f 100644 --- a/include/server/vnode/meta/meta.h +++ b/include/server/vnode/meta/meta.h @@ -27,33 +27,34 @@ extern "C" { typedef uint64_t tuid_t; // Types exported -typedef struct SMeta SMeta; -typedef struct SMetaOptions SMetaOptions; -typedef struct SMetaQueryHandle SMetaQueryHandle; -typedef struct SMetaQueryOptions SMetaQueryOptions; +typedef struct SMeta SMeta; +typedef struct SMetaOpts SMetaOpts; +typedef struct SMetaQueryHandle SMetaQueryHandle; +typedef struct SMetaQueryOpts SMetaQueryOpts; +typedef struct STableOpts STableOpts; // SMeta operations int metaCreate(const char *path); void metaDestroy(const char *path); -SMeta *metaOpen(SMetaOptions *); +SMeta *metaOpen(SMetaOpts *); void metaClose(SMeta *); -int metaCreateTable(SMeta *, void *); +int metaCreateTable(SMeta *, STableOpts *); int metaDropTable(SMeta *, uint64_t tuid_t); int metaAlterTable(SMeta *, void *); int metaCommit(SMeta *); // Options -SMetaOptions *metaOptionsCreate(); -void metaOptionsDestroy(SMetaOptions *); -void metaOptionsSetCache(SMetaOptions *, size_t capacity); +SMetaOpts *metaOptionsCreate(); +void metaOptionsDestroy(SMetaOpts *); +void metaOptionsSetCache(SMetaOpts *, size_t capacity); // SMetaQueryHandle -SMetaQueryHandle *metaQueryHandleCreate(SMetaQueryOptions *); +SMetaQueryHandle *metaQueryHandleCreate(SMetaQueryOpts *); void metaQueryHandleDestroy(SMetaQueryHandle *); -// SMetaQueryOptions -SMetaQueryOptions *metaQueryOptionsCreate(); -void metaQueryOptionsDestroy(SMetaQueryOptions *); +// SMetaQueryOpts +SMetaQueryOpts *metaQueryOptionsCreate(); +void metaQueryOptionsDestroy(SMetaQueryOpts *); #ifdef __cplusplus } diff --git a/source/server/vnode/meta/src/meta.c b/source/server/vnode/meta/src/meta.c index e945e6eac4..a035fef205 100644 --- a/source/server/vnode/meta/src/meta.c +++ b/source/server/vnode/meta/src/meta.c @@ -51,9 +51,15 @@ struct SMeta { size_t totalUsed; }; +struct STableOpts { + int8_t type; + char * name; + STSchema *pSchema; +}; + /* -------------------- Methods -------------------- */ -SMeta *metaOpen(SMetaOptions *options) { +SMeta *metaOpen(SMetaOpts *options) { SMeta *pMeta = NULL; char * err = NULL; @@ -104,6 +110,11 @@ void metaClose(SMeta *pMeta) { } } +int metaCreateTable(SMeta *pMeta, STableOpts *pTableOpts) { + // TODO + return 0; +} + void metaDestroy(const char *path) { taosRemoveDir(path); } int metaCommit(SMeta *meta) { return 0; } \ No newline at end of file -- GitLab