From aefd622e1ef51c84ab10fa65edeb4c0df2152ebd Mon Sep 17 00:00:00 2001 From: Hongze Cheng Date: Mon, 10 Feb 2020 22:10:00 +0800 Subject: [PATCH] more --- src/vnode/common/catalog/inc/schema.h | 8 +- src/vnode/tsdb/inc/tsdbFile.h | 9 ++- src/vnode/tsdb/inc/tsdbMeta.h | 108 ++++++++++++++++---------- src/vnode/tsdb/src/tsdbMeta.c | 5 ++ 4 files changed, 83 insertions(+), 47 deletions(-) diff --git a/src/vnode/common/catalog/inc/schema.h b/src/vnode/common/catalog/inc/schema.h index add0fdd9a1..62b642894e 100644 --- a/src/vnode/common/catalog/inc/schema.h +++ b/src/vnode/common/catalog/inc/schema.h @@ -7,8 +7,9 @@ #include "type.h" typedef struct _scolumn { - td_datatype_t type; - int32_t bytes; + tstring_t colName; // column name + td_datatype_t type; // data type + int32_t bytes; // number of bytes } SColumn; typedef struct SSchema { @@ -18,6 +19,7 @@ typedef struct SSchema { // Column with version typedef struct { + tstring_t colName; td_datatype_t type; int32_t colId; int32_t bytes; @@ -27,7 +29,7 @@ typedef struct { typedef struct { int32_t version; // Schema with version int32_t numOfCols; - int32_t columnId; + int32_t numOfTags; SVColumn *columns; } SVSchema; diff --git a/src/vnode/tsdb/inc/tsdbFile.h b/src/vnode/tsdb/inc/tsdbFile.h index a4cfa59555..2db4f21047 100644 --- a/src/vnode/tsdb/inc/tsdbFile.h +++ b/src/vnode/tsdb/inc/tsdbFile.h @@ -18,9 +18,16 @@ typedef struct { typedef struct { tstring_t fname; - SFileInfo; + SFileInfo fInfo; } SFILE; +typedef struct { + int64_t offset; + int64_t skey; + int64_t ekey; + int16_t numOfBlocks; +} SDataBlock; + tstring_t tdGetHeadFileName(/* TODO */); tstring_t tdGetDataFileName(/* TODO */); tstring_t tdGetLastFileName(/* TODO */); diff --git a/src/vnode/tsdb/inc/tsdbMeta.h b/src/vnode/tsdb/inc/tsdbMeta.h index 684e80160f..6642e29ad6 100644 --- a/src/vnode/tsdb/inc/tsdbMeta.h +++ b/src/vnode/tsdb/inc/tsdbMeta.h @@ -2,61 +2,83 @@ * For internal usage ************************************/ -#include "tsdb.h" +#include -typedef enum { - TSDB_TABLE_NORMAL, - TSDB_TABLE_STABLE, - TSDB_TABLE_SUPER -} TSDB_TABLE_TYPE; +#include "tsdb.h" -// Below is the struct definition of super table -// TODO: May merge all table definitions -typedef struct _super_table { - int64_t uid; - char *tableName; +// Initially, there are 4 tables +#define TSDB_INIT_NUMBER_OF_SUPER_TABLE 4 - int64_t createdTime; - - // TODO: try to merge the two schema into one - SSchema *pSchema; - SSchema *pTagSchema; - - // A index created for all tables created using this super table - SSkipList * pIndex; -} SSTable; - -// Normal table struct definition, table not -// created from super table -typedef struct SNTable -{ - tsdb_id_t tableId; - int64_t uid; - char *tableName; - - int64_t createdTime; - SSchema *pSchema -} SNTable; +typedef enum : uint8_t { + TSDB_SUPER_TABLE, // super table + TSDB_NTABLE, // table not created from super table + TSDB_STABLE // table created from super table +} TSDB_TABLE_TYPE; -// Table created from super table typedef struct STable { - tsdb_id_t tableId; - int64_t uid; - char *tableName; + tsdb_id_t tableId; + int64_t uid; + char * tableName; + TSDB_TABLE_TYPE type; int64_t createdTime; // super table UID - int64_t stableUid; + tsdb_id_t superTableId; - // Tag values for this table + // Schema for this table + // For TSDB_SUPER_TABLE, it is the schema including tags + // For TSDB_NTABLE, it is only the schema, not including tags + // For TSDB_STABLE, it is NULL + SVSchema *pSchema; + + // Tag value for this table + // For TSDB_SUPER_TABLE and TSDB_NTABLE, it is NULL + // For TSDB_STABLE, it is the tag value string char *pTagVal; - // Cached data - SSkipList *pData; + // Object content; + // For TSDB_SUPER_TABLE, it is the index of tables created from it + // For TSDB_STABLE and TSDB_NTABLE, it is the cache data + union { + void *pData; + void *pIndex; + } content; + + // A handle to deal with event + void *eventHandle; + + // A handle to deal with stream + void *streamHandle; + } STable; -#define TSDB_GET_TABLE_ID(pTable) (((STable *)pTable)->tid).tableId -#define TSDB_GET_TABLE_UID(pTable) (((STable *)pTable)->tid).uid +typedef struct { + int32_t numOfTables; // Number of tables not including TSDB_SUPER_TABLE (#TSDB_NTABLE + #TSDB_STABLE) + int32_t numOfSuperTables; // Number of super tables (#TSDB_SUPER_TABLE) + // An array of tables (TSDB_NTABLE and TSDB_STABLE) in this TSDB repository + STable **pTables; + + // A map of tableName->tableId + // TODO: May use hash table + void *pNameTableMap; +} SMetaHandle; + +// ---- Operation on STable +#define TSDB_TABLE_ID(pTable) ((pTable)->tableId) +#define TSDB_TABLE_UID(pTable) ((pTable)->uid) +#define TSDB_TABLE_NAME(pTable) ((pTable)->tableName) +#define TSDB_TABLE_TYPE(pTable) ((pTable)->type) +#define TSDB_TABLE_SUPER_TABLE_UID(pTable) ((pTable)->stableUid) +#define TSDB_TABLE_IS_SUPER_TABLE(pTable) (TSDB_TABLE_TYPE(pTable) == TSDB_SUPER_TABLE) +#define TSDB_TABLE_TAG_VALUE(pTable) ((pTable)->pTagVal) +#define TSDB_TABLE_CACHE_DATA(pTable) ((pTable)->content.pData) +#define TSDB_SUPER_TABLE_INDEX(pTable) ((pTable)->content.pIndex) + +SVSchema *tsdbGetTableSchema(STable *pTable); -#define TSDB_IS_SUPER_TABLE(pTable) +// ---- Operation on SMetaHandle +#define TSDB_NUM_OF_TABLES(pHandle) ((pHandle)->numOfTables) +#define TSDB_NUM_OF_SUPER_TABLES(pHandle) ((pHandle)->numOfSuperTables) +#define TSDB_TABLE_OF_ID(pHandle, id) ((pHandle)->pTables)[id] +#define TSDB_GET_TABLE_OF_NAME(pHandle, name) /* TODO */ \ No newline at end of file diff --git a/src/vnode/tsdb/src/tsdbMeta.c b/src/vnode/tsdb/src/tsdbMeta.c index c2a52c5026..a1ddc308a5 100644 --- a/src/vnode/tsdb/src/tsdbMeta.c +++ b/src/vnode/tsdb/src/tsdbMeta.c @@ -1,2 +1,7 @@ #include "tsdb.h" +#include "tsdbMeta.h" + +SVSchema *tsdbGetTableSchema(STable *pTable) { + +} -- GitLab