From 472d52a275b643508d03232fb00ede2499ebecfb Mon Sep 17 00:00:00 2001 From: Hongze Cheng Date: Wed, 12 Feb 2020 14:32:18 +0800 Subject: [PATCH] add more --- src/vnode/common/inc/dataformat.h | 3 ++- src/vnode/common/inc/schema.h | 4 +++- src/vnode/common/inc/type.h | 36 ++++++++++++++++++++---------- src/vnode/common/src/dataformat.c | 3 +++ src/vnode/common/src/schema.c | 19 +++++++++++++++- src/vnode/tsdb/inc/tsdbCache.h | 1 - src/vnode/tsdb/inc/tsdbFile.h | 22 ++++++++++-------- src/vnode/tsdb/src/tsdbFileStore.c | 6 +++++ 8 files changed, 69 insertions(+), 25 deletions(-) diff --git a/src/vnode/common/inc/dataformat.h b/src/vnode/common/inc/dataformat.h index 3db70c9569..dd8766f96a 100644 --- a/src/vnode/common/inc/dataformat.h +++ b/src/vnode/common/inc/dataformat.h @@ -3,7 +3,6 @@ #include -#include "type.h" #include "schema.h" // ----------------- Data row structure @@ -63,4 +62,6 @@ typedef char * SDataCols; #define TD_DATACOLS_LEN(pDataCols) (*(int32_t *)(pDataCols)) #define TD_DATACOLS_NPOINTS(pDataCols) (*(int32_t *)(pDataCols + sizeof(int32_t))) +// ---- + #endif // _TD_DATA_FORMAT_H_ diff --git a/src/vnode/common/inc/schema.h b/src/vnode/common/inc/schema.h index 869c069295..bda7e337c0 100644 --- a/src/vnode/common/inc/schema.h +++ b/src/vnode/common/inc/schema.h @@ -12,6 +12,7 @@ typedef struct { td_datatype_t type; // Column type int32_t colId; // column ID int32_t bytes; // column bytes + int32_t offset; // point offset in a row data char * colName; // the column name } SColumn; @@ -40,6 +41,7 @@ typedef char *SISchema; #define TD_COLUMN_TYPE(pCol) ((pCol)->type) // column type #define TD_COLUMN_ID(pCol) ((pCol)->colId) // column ID #define TD_COLUMN_BYTES(pCol) ((pCol)->bytes) // column bytes +#define TD_COLUMN_OFFSET(pCol) ((pCol)->offset) // column bytes #define TD_COLUMN_NAME(pCol) ((pCol)->colName) // column name #define TD_COLUMN_INLINE_SIZE(pCol) (sizeof(SColumn) + TD_COLUMN_NAME(pCol) + 1) @@ -66,6 +68,6 @@ SISchema tdConvertSchemaToInline(SSchema *pSchema); int32_t tdGetColumnIdxByName(SSchema *pSchema, char *colName); int32_t tdGetColumnIdxById(SSchema *pSchema, int32_t colId); -// ---- TODO: operations to change schema +// ---- TODO: operations to modify schema #endif // _TD_SCHEMA_H_ diff --git a/src/vnode/common/inc/type.h b/src/vnode/common/inc/type.h index f44bc982c1..685fc2e240 100644 --- a/src/vnode/common/inc/type.h +++ b/src/vnode/common/inc/type.h @@ -4,19 +4,31 @@ #include typedef enum { - TD_DATATYPE_INVLD = 0, // invalid data type - TD_DATATYPE_BOOL, - TD_DATATYPE_TINYINT, - TD_DATATYPE_SMALLINT, - TD_DATATYPE_INT, - TD_DATATYPE_BIGINT, - TD_DATATYPE_FLOAT, - TD_DATATYPE_DOUBLE, - TD_DATATYPE_VARCHAR, - TD_DATATYPE_NCHAR, - TD_DATATYPE_BINARY + TD_DATATYPE_BOOL = 0, + TD_DATATYPE_TINYINT, + TD_DATATYPE_SMALLINT, + TD_DATATYPE_INT, + TD_DATATYPE_BIGINT, + TD_DATATYPE_FLOAT, + TD_DATATYPE_DOUBLE, + TD_DATATYPE_VARCHAR, + TD_DATATYPE_NCHAR, + TD_DATATYPE_BINARY } td_datatype_t; +const int32_t rowDataLen[] = { + sizeof(int8_t), // TD_DATATYPE_BOOL, + sizeof(int8_t), // TD_DATATYPE_TINYINT, + sizeof(int16_t), // TD_DATATYPE_SMALLINT, + sizeof(int32_t), // TD_DATATYPE_INT, + sizeof(int64_t), // TD_DATATYPE_BIGINT, + sizeof(float), // TD_DATATYPE_FLOAT, + sizeof(double), // TD_DATATYPE_DOUBLE, + sizeof(int32_t), // TD_DATATYPE_VARCHAR, + sizeof(int32_t), // TD_DATATYPE_NCHAR, + sizeof(int32_t) // TD_DATATYPE_BINARY +}; + // TODO: finish below #define TD_DATATYPE_BOOL_NULL #define TD_DATATYPE_TINYINT_NULL @@ -31,4 +43,4 @@ typedef enum { #define TD_IS_VALID_DATATYPE(type) (((type) > TD_DATA_TYPE_INVLD) && ((type) <= TD_DATATYPE_BINARY)) -#endif // _TD_TYPE_H_ +#endif // _TD_TYPE_H_ diff --git a/src/vnode/common/src/dataformat.c b/src/vnode/common/src/dataformat.c index e69de29bb2..f0a2cefc21 100644 --- a/src/vnode/common/src/dataformat.c +++ b/src/vnode/common/src/dataformat.c @@ -0,0 +1,3 @@ +#include + +#include "dataformat.h" diff --git a/src/vnode/common/src/schema.c b/src/vnode/common/src/schema.c index 35374a4311..cf0664c7cc 100644 --- a/src/vnode/common/src/schema.c +++ b/src/vnode/common/src/schema.c @@ -15,6 +15,23 @@ static size_t tdGetEstimatedISchemaLen(SSchema *pSchema) { return TD_ISCHEMA_HEADER_SIZE + (size_t)TD_SCHEMA_TOTAL_COLS(pSchema) + colNameLen; } +static void tdUpdateColumnOffsets(SSchema *pSchema) { + int32_t offset = 0; + for (size_t i = 0; i < TD_SCHEMA_NCOLS(pSchema); i++) + { + SColumn *pCol = TD_SCHEMA_COLUMN_AT(pSchema, i); + TD_COLUMN_OFFSET(pCol) = offset; + offset += rowDataLen[TD_COLUMN_TYPE(pCol)]; + } + + offset = 0; + for (size_t i = 0; i < TD_SCHEMA_NTAGS(pSchema); i++) { + SColumn *pCol = TD_SCHEMA_TAG_AT(pSchema, i); + TD_COLUMN_OFFSET(pCol) = offset; + offset += rowDataLen[TD_COLUMN_TYPE(pCol)]; + } +} + SISchema tdConvertSchemaToInline(SSchema *pSchema) { size_t len = tdGetEstimatedISchemaLen(pSchema); int32_t totalCols = TD_SCHEMA_TOTAL_COLS(pSchema); @@ -61,7 +78,7 @@ int32_t tdGetColumnIdxById(SSchema *pSchema, int32_t colId) { for (int32_t i = 0; i < TD_SCHEMA_TOTAL_COLS(pSchema); i++) { SColumn *pCol = TD_SCHEMA_COLUMN_AT(pSchema, i); if (TD_COLUMN_ID(pCol) == colId) { - return i; + return i; } } return -1; diff --git a/src/vnode/tsdb/inc/tsdbCache.h b/src/vnode/tsdb/inc/tsdbCache.h index b9de8551bc..3b9aab027b 100644 --- a/src/vnode/tsdb/inc/tsdbCache.h +++ b/src/vnode/tsdb/inc/tsdbCache.h @@ -4,7 +4,6 @@ #include #include "cache.h" -#include "dlist.h" #define TSDB_DEFAULT_CACHE_BLOCK_SIZE 16*1024*1024 /* 16M */ diff --git a/src/vnode/tsdb/inc/tsdbFile.h b/src/vnode/tsdb/inc/tsdbFile.h index 2db4f21047..91abea076f 100644 --- a/src/vnode/tsdb/inc/tsdbFile.h +++ b/src/vnode/tsdb/inc/tsdbFile.h @@ -5,13 +5,20 @@ typedef int32_t file_id_t; -typedef enum : uint8_t { - TSDB_FILE_TYPE_HEAD, - TSDB_FILE_TYPE_DATA, - TSDB_FILE_TYPE_LAST, - TSDB_FILE_TYPE_META +typedef enum { + TSDB_FILE_TYPE_HEAD, // .head file type + TSDB_FILE_TYPE_DATA, // .data file type + TSDB_FILE_TYPE_LAST, // .last file type + TSDB_FILE_TYPE_META // .meta file type } TSDB_FILE_TYPE; +const char *tsdbFileSuffix[] = { + ".head", // TSDB_FILE_TYPE_HEAD + ".data", // TSDB_FILE_TYPE_DATA + ".last", // TSDB_FILE_TYPE_LAST + ".meta" // TSDB_FILE_TYPE_META +}; + typedef struct { int64_t fileSize; } SFileInfo; @@ -28,9 +35,6 @@ typedef struct { int16_t numOfBlocks; } SDataBlock; -tstring_t tdGetHeadFileName(/* TODO */); -tstring_t tdGetDataFileName(/* TODO */); -tstring_t tdGetLastFileName(/* TODO */); -tstring_t tdGetMetaFileName(/* TODO */); +char *tsdbGetFileName(char *dirName, char *fname, TSDB_FILE_TYPE type); #endif // _TD_TSDB_FILE_H_ diff --git a/src/vnode/tsdb/src/tsdbFileStore.c b/src/vnode/tsdb/src/tsdbFileStore.c index e69de29bb2..f6cc959f8f 100644 --- a/src/vnode/tsdb/src/tsdbFileStore.c +++ b/src/vnode/tsdb/src/tsdbFileStore.c @@ -0,0 +1,6 @@ +#include "tsdbFile.h" + +char *tsdbGetFileName(char *dirName, char *fname, TSDB_FILE_TYPE type){ + char *suffix = tsdbFileSuffix[type]; + // TODO +} \ No newline at end of file -- GitLab