diff --git a/src/vnode/common/catalog/inc/schema.h b/src/vnode/common/catalog/inc/schema.h index add0fdd9a1c94bf64fcf698f28b9974deb897ce2..62b642894e3b89edba4d7160135d64e7f298eace 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 a4cfa595550252e506195875b0e41a245e465541..2db4f21047441345f4d66c87ccaa04999587de0c 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 684e80160f13bbadffb527cfb3eb8490aa1da136..6642e29ad69379b12bdb7f863cae79c756a0763f 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 c2a52c5026a35fea6c6404dbe4a384bcc7ec8736..a1ddc308a5b15a9a400dc48e32fb3526e0bce6e4 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) { + +}