diff --git a/src/vnode/common/inc/dataformat.h b/src/vnode/common/inc/dataformat.h index 3db70c956963248c40473e17b66da6fe5c46a9b9..dd8766f96ace09cb4ce69bd2c7eaa68d3151ad8a 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 869c069295cacc59fc5a5cffee8b393268f0b7e8..bda7e337c0b0350195360f21cc6424d6e52d38c2 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 f44bc982c111c4cad0fc90e6e32ce98808687dee..685fc2e24018d8a47227082e778c52fe70bee38a 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 e69de29bb2d1d6434b8b29ae775ad8c2e48c5391..f0a2cefc218a5b9bd38c9eec3e2d6edf9e9a5f29 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 35374a431172ec2842c92d8a502bcba7cca62504..cf0664c7cc0dee5542cc958921e01c60acb568ff 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 b9de8551bcb3f5254674f1abd32e2acb7c59c5ce..3b9aab027b0356c101e20763ee7e466286e6e798 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 2db4f21047441345f4d66c87ccaa04999587de0c..91abea076f4551257ec83620833c00045a084fb2 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 e69de29bb2d1d6434b8b29ae775ad8c2e48c5391..f6cc959f8f6dd24fb9ef4d65c23e5d8debf97929 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