Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
CSDN产品汪
TDengine
提交
6656c118
T
TDengine
项目概览
CSDN产品汪
/
TDengine
与 Fork 源项目一致
Fork自
taosdata / TDengine
通知
5
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
T
TDengine
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
6656c118
编写于
3月 06, 2020
作者:
H
hzcheng
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fix more code
上级
d0e32fbd
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
150 addition
and
197 deletion
+150
-197
src/vnode/common/inc/schema.h
src/vnode/common/inc/schema.h
+41
-48
src/vnode/common/src/dataformat.c
src/vnode/common/src/dataformat.c
+1
-32
src/vnode/common/src/schema.c
src/vnode/common/src/schema.c
+100
-70
src/vnode/tsdb/tests/CMakeLists.txt
src/vnode/tsdb/tests/CMakeLists.txt
+1
-1
src/vnode/tsdb/tests/tsdbTests.cpp
src/vnode/tsdb/tests/tsdbTests.cpp
+7
-46
未找到文件。
src/vnode/common/inc/schema.h
浏览文件 @
6656c118
#if
!defined(_TD_SCHEMA_H_)
#if
ndef _TD_SCHEMA_H_
#define _TD_SCHEMA_H_
#include <stdint.h>
...
...
@@ -6,25 +6,50 @@
#include "type.h"
// Column definition
// TODO: if we need to align the structure
#ifdef __cplusplus
extern
"C"
{
#endif
// ---- Column definition and operations
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
int8_t
type
;
// Column type
int16_t
colId
;
// column ID
int16_t
bytes
;
// column bytes
int32_t
offset
;
// point offset in a row data
}
SColumn
;
// Schema definition
#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))
SColumn
*
tdNewCol
(
int8_t
type
,
int16_t
colId
,
int16_t
bytes
);
void
tdFreeCol
(
SColumn
*
pCol
);
void
tdColCpy
(
SColumn
*
dst
,
SColumn
*
src
);
// ---- Schema definition and operations
typedef
struct
{
int32_t
version
;
// schema version, it is used to change the schema
int32_t
numOfCols
;
int32_t
numOfTags
;
int32_t
colIdCounter
;
int32_t
padding
;
// TODO: replace the padding for useful variable
SColumn
columns
[];
}
SSchema
;
#define schemaNCols(s) ((s)->numOfCols)
#define schemaColAt(s, i) ((s)->columns + i)
SSchema
*
tdNewSchema
(
int32_t
nCols
);
SSchema
*
tdDupSchema
(
SSchema
*
pSchema
);
void
tdFreeSchema
(
SSchema
*
pSchema
);
void
tdUpdateSchema
(
SSchema
*
pSchema
);
int32_t
tdMaxRowDataBytes
(
SSchema
*
pSchema
);
// ---- Inline schema definition and operations
/* Inline schema definition
* +---------+---------+---------+-----+---------+-----------+-----+-----------+
* | int32_t | | | | | | | |
...
...
@@ -34,42 +59,10 @@ typedef struct {
*/
typedef
char
*
SISchema
;
// TODO: decide if the space is allowed
#define TD_ISCHEMA_HEADER_SIZE sizeof(int32_t) + sizeof(SSchema)
// ---- operations on SColumn
#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)
// ---- operations on SSchema
#define TD_SCHEMA_VERSION(pSchema) ((pSchema)->version) // schema version
#define TD_SCHEMA_NCOLS(pSchema) ((pSchema)->numOfCols) // schema number of columns
#define TD_SCHEMA_NTAGS(pSchema) ((pSchema)->numOfTags) // schema number of tags
#define TD_SCHEMA_TOTAL_COLS(pSchema) (TD_SCHEMA_NCOLS(pSchema) + TD_SCHEMA_NTAGS(pSchema)) // schema total number of SColumns (#columns + #tags)
#define TD_SCHEMA_NEXT_COLID(pSchema) ((pSchema)->colIdCounter++)
#define TD_SCHEMA_COLS(pSchema) ((pSchema)->columns)
#define TD_SCHEMA_TAGS(pSchema) (TD_SCHEMA_COLS(pSchema) + TD_SCHEMA_NCOLS(pSchema))
#define TD_SCHEMA_COLUMN_AT(pSchema, idx) (TD_SCHEMA_COLS(pSchema) + idx)
#define TD_SCHEMA_TAG_AT(pSchema, idx) (TD_SCHEMA_TAGS(pSchema) + idx)
// ---- operations on SISchema
#define TD_ISCHEMA_LEN(pISchema) *((int32_t *)(pISchema))
#define TD_ISCHEMA_SCHEMA(pISchema) ((SSchema *)((pISchema) + sizeof(int32_t)))
#define TD_ISCHEMA_COL_NAMES(pISchema) ((pISchema) + TD_ISCHEMA_HEADER_SIZE + sizeof(SColumn) * TD_SCHEMA_TOTAL_COLS(TD_ISCHEMA_SCHEMA(pISchema)))
// ----
/* Convert a schema structure to an inline schema structure
*/
SISchema
tdConvertSchemaToInline
(
SSchema
*
pSchema
);
int32_t
tdGetColumnIdxByName
(
SSchema
*
pSchema
,
char
*
colName
);
int32_t
tdGetColumnIdxById
(
SSchema
*
pSchema
,
int32_t
colId
);
SSchema
*
tdDupSchema
(
SSchema
*
pSchema
);
void
tdFreeSchema
(
SSchema
*
pSchema
);
// TODO: add operations on SISchema
// ---- TODO: operations to modify schema
#ifdef __cplusplus
}
#endif
#endif // _TD_SCHEMA_H_
src/vnode/common/src/dataformat.c
浏览文件 @
6656c118
...
...
@@ -2,8 +2,6 @@
#include "dataformat.h"
static
int32_t
tdGetMaxDataRowSize
(
SSchema
*
pSchema
);
/**
* Create a data row with maximum row length bytes.
*
...
...
@@ -26,7 +24,7 @@ SDataRow tdNewDataRow(int32_t bytes) {
}
SDataRow
tdNewDdataFromSchema
(
SSchema
*
pSchema
)
{
int32_t
bytes
=
td
GetMaxDataRowSize
(
pSchema
);
int32_t
bytes
=
td
MaxRowDataBytes
(
pSchema
);
return
tdNewDataRow
(
bytes
);
}
...
...
@@ -77,35 +75,6 @@ int32_t tdAppendColVal(SDataRow row, void *value, SColumn *pCol, int32_t suffixO
return
0
;
}
static
int32_t
tdGetMaxDataRowSize
(
SSchema
*
pSchema
)
{
int32_t
nbytes
=
0
;
for
(
int32_t
i
=
0
;
i
<
TD_SCHEMA_NCOLS
(
pSchema
);
i
++
)
{
SColumn
*
pCol
=
TD_SCHEMA_COLUMN_AT
(
pSchema
,
i
);
td_datatype_t
type
=
TD_COLUMN_TYPE
(
pCol
);
nbytes
+=
rowDataLen
[
type
];
switch
(
type
)
{
case
TD_DATATYPE_VARCHAR
:
nbytes
+=
TD_COLUMN_BYTES
(
pCol
);
break
;
case
TD_DATATYPE_NCHAR
:
nbytes
+=
4
*
TD_COLUMN_BYTES
(
pCol
);
break
;
case
TD_DATATYPE_BINARY
:
nbytes
+=
TD_COLUMN_BYTES
(
pCol
);
break
;
default:
break
;
}
}
nbytes
+=
TD_DATA_ROW_HEADER_SIZE
;
return
nbytes
;
}
SDataRow
tdSDataRowDup
(
SDataRow
rdata
)
{
return
NULL
;
}
void
tdFreeSDataRow
(
SDataRow
rdata
)
{
if
(
rdata
==
NULL
)
return
;
...
...
src/vnode/common/src/schema.c
浏览文件 @
6656c118
#include <stdlib.h>
#include "schema.h"
const
int32_t
rowDataLen
[]
=
{
sizeof
(
int8_t
),
// TD_DATATYPE_BOOL,
sizeof
(
int8_t
),
// TD_DATATYPE_TINYINT,
...
...
@@ -13,93 +14,122 @@ const int32_t rowDataLen[] = {
sizeof
(
int32_t
),
// TD_DATATYPE_NCHAR,
sizeof
(
int32_t
)
// TD_DATATYPE_BINARY
};
void
tdFreeSchema
(
SSchema
*
pSchema
)
{
// TODO
return
;
}
static
size_t
tdGetEstimatedISchemaLen
(
SSchema
*
pSchema
)
{
size_t
colNameLen
=
0
;
for
(
size_t
i
=
0
;
i
<
TD_SCHEMA_NCOLS
(
pSchema
);
i
++
)
{
colNameLen
+=
(
strlen
(
TD_COLUMN_NAME
(
TD_SCHEMA_COLUMN_AT
(
pSchema
,
i
)))
+
1
);
/**
* Create a new SColumn object
* ASSUMPTIONS: VALID PARAMETERS
*
* @param type column type
* @param colId column ID
* @param bytes maximum bytes the col taken
*
* @return a SColumn object on success
* NULL for failure
*/
SColumn
*
tdNewCol
(
int8_t
type
,
int16_t
colId
,
int16_t
bytes
)
{
SColumn
*
pCol
=
(
SColumn
*
)
calloc
(
1
,
sizeof
(
SColumn
));
if
(
pCol
==
NULL
)
return
NULL
;
colSetType
(
pCol
,
type
);
colSetColId
(
pCol
,
colId
);
switch
(
type
)
{
case
TD_DATATYPE_VARCHAR
:
case
TD_DATATYPE_NCHAR
:
case
TD_DATATYPE_BINARY
:
colSetBytes
(
pCol
,
bytes
);
break
;
default:
colSetBytes
(
pCol
,
rowDataLen
[
type
]);
break
;
}
for
(
size_t
i
=
0
;
i
<
TD_SCHEMA_NCOLS
(
pSchema
);
i
++
)
{
colNameLen
+=
(
strlen
(
TD_COLUMN_NAME
(
TD_SCHEMA_COLUMN_AT
(
pSchema
,
i
)))
+
1
);
}
return
TD_ISCHEMA_HEADER_SIZE
+
(
size_t
)
TD_SCHEMA_TOTAL_COLS
(
pSchema
)
+
colNameLen
;
return
pCol
;
}
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
)];
}
/**
* Free a SColumn object CREATED with tdNewCol
*/
void
tdFreeCol
(
SColumn
*
pCol
)
{
if
(
pCol
)
free
(
pCol
);
}
SISchema
tdConvertSchemaToInline
(
SSchema
*
pSchema
)
{
size_t
len
=
tdGetEstimatedISchemaLen
(
pSchema
);
int32_t
totalCols
=
TD_SCHEMA_TOTAL_COLS
(
pSchema
);
// TODO: if use pISchema is reasonable?
SISchema
pISchema
=
malloc
(
len
);
if
(
pSchema
==
NULL
)
{
// TODO: add error handling
return
NULL
;
}
TD_ISCHEMA_LEN
(
pISchema
)
=
(
int32_t
)
len
;
memcpy
((
void
*
)
TD_ISCHEMA_SCHEMA
(
pISchema
),
(
void
*
)
pSchema
,
sizeof
(
SSchema
));
// TD_SCHEMA_COLS(TD_ISCHEMA_SCHEMA(pISchema)) = (SColumn *)(pISchema + TD_ISCHEMA_HEADER_SIZE);
memcpy
((
void
*
)
TD_SCHEMA_COLS
(
TD_ISCHEMA_SCHEMA
(
pISchema
)),
(
void
*
)
TD_SCHEMA_COLS
(
pSchema
),
sizeof
(
SColumn
)
*
totalCols
);
void
tdColCpy
(
SColumn
*
dst
,
SColumn
*
src
)
{
memcpy
((
void
*
)
dst
,
(
void
*
)
src
,
sizeof
(
SColumn
));
}
/**
* Create a SSchema object with nCols columns
* ASSUMPTIONS: VALID PARAMETERS
*
* @param nCols number of columns the schema has
*
* @return a SSchema object for success
* NULL for failure
*/
SSchema
*
tdNewSchema
(
int32_t
nCols
)
{
int32_t
size
=
sizeof
(
SSchema
)
+
sizeof
(
SColumn
)
*
nCols
;
SSchema
*
pSchema
=
(
SSchema
*
)
calloc
(
1
,
size
);
if
(
pSchema
==
NULL
)
return
NULL
;
pSchema
->
numOfCols
=
nCols
;
return
pSchema
;
}
char
*
pName
=
TD_ISCHEMA_COL_NAMES
(
pISchema
);
for
(
int32_t
i
=
0
;
i
<
totalCols
;
i
++
)
{
SColumn
*
pCol
=
TD_SCHEMA_COLUMN_AT
(
TD_ISCHEMA_SCHEMA
(
pISchema
),
i
);
char
*
colName
=
TD_COLUMN_NAME
(
TD_SCHEMA_COLUMN_AT
(
pSchema
,
i
));
/**
* Free the SSchema object created by tdNewSchema or tdDupSchema
*/
void
tdFreeSchema
(
SSchema
*
pSchema
)
{
if
(
pSchema
==
NULL
)
free
(
pSchema
);
}
TD_COLUMN_NAME
(
pCol
)
=
pName
;
SSchema
*
tdDupSchema
(
SSchema
*
pSchema
)
{
SSchema
*
tSchema
=
tdNewSchema
(
schemaNCols
(
pSchema
));
if
(
tSchema
==
NULL
)
return
NULL
;
size_t
tlen
=
strlen
(
colName
)
+
1
;
memcpy
((
void
*
)
pName
,
(
void
*
)
colName
,
tlen
);
pName
+=
tlen
;
}
int32_t
size
=
sizeof
(
SSchema
)
+
sizeof
(
SColumn
)
*
schemaNCols
(
pSchema
);
memcpy
((
void
*
)
tSchema
,
(
void
*
)
pSchema
,
size
);
return
pI
Schema
;
return
t
Schema
;
}
int32_t
tdGetColumnIdxByName
(
SSchema
*
pSchema
,
char
*
colName
)
{
for
(
int32_t
i
=
0
;
i
<
TD_SCHEMA_TOTAL_COLS
(
pSchema
);
i
++
)
{
SColumn
*
pCol
=
TD_SCHEMA_COLUMN_AT
(
pSchema
,
i
);
if
(
strcmp
(
colName
,
TD_COLUMN_NAME
(
pCol
))
==
0
)
{
return
i
;
}
/**
* Function to update each columns's offset field in the schema.
* ASSUMPTIONS: VALID PARAMETERS
*/
void
tdUpdateSchema
(
SSchema
*
pSchema
)
{
SColumn
*
pCol
=
NULL
;
int32_t
offset
=
0
;
for
(
int
i
=
0
;
i
<
schemaNCols
(
pSchema
);
i
++
)
{
pCol
=
schemaColAt
(
pSchema
,
i
);
colSetOffset
(
pCol
,
offset
);
offset
+=
rowDataLen
[
pCol
->
type
];
}
return
-
1
;
}
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
;
/**
* Get the maximum size of a row data with the schema
*/
int32_t
tdMaxRowDataBytes
(
SSchema
*
pSchema
)
{
int32_t
size
=
0
;
SColumn
*
pCol
=
NULL
;
for
(
int
i
=
0
;
i
<
schemaNCols
(
pSchema
);
i
++
)
{
pCol
=
schemaColAt
(
pSchema
,
i
);
size
+=
rowDataLen
[
pCol
->
type
];
switch
(
pCol
->
type
)
{
case
TD_DATATYPE_VARCHAR
:
size
+=
(
pCol
->
bytes
+
1
);
// TODO: remove literal here
break
;
case
TD_DATATYPE_NCHAR
:
size
+=
(
pCol
->
bytes
+
4
);
// TODO: check and remove literal here
break
;
case
TD_DATATYPE_BINARY
:
size
+=
pCol
->
bytes
;
break
;
default:
break
;
}
}
return
-
1
;
}
SSchema
*
tdDupSchema
(
SSchema
*
pSchema
)
{
return
NULL
;
return
size
;
}
\ No newline at end of file
src/vnode/tsdb/tests/CMakeLists.txt
浏览文件 @
6656c118
aux_source_directory
(
${
CMAKE_CURRENT_SOURCE_DIR
}
SOURCE_LIST
)
add_executable
(
tsdbTests
${
SOURCE_LIST
}
)
target_link_libraries
(
tsdbTests gtest gtest_main pthread tsdb
)
target_link_libraries
(
tsdbTests gtest gtest_main pthread
common
tsdb
)
add_test
(
NAME
...
...
src/vnode/tsdb/tests/tsdbTests.cpp
浏览文件 @
6656c118
...
...
@@ -10,56 +10,17 @@ TEST(TsdbTest, createTable) {
STableCfg
config
;
config
.
tableId
.
tid
=
0
;
config
.
tableId
.
uid
=
98868728187539L
;
config
.
numOfCols
=
2
;
config
.
schema
=
(
SSchema
*
)
malloc
(
sizeof
(
SSchema
)
+
sizeof
(
SColumn
)
*
config
.
numOfCols
);
config
.
schema
->
version
=
0
;
config
.
schema
->
numOfCols
=
2
;
config
.
schema
->
numOfTags
=
0
;
config
.
schema
->
colIdCounter
=
1
;
for
(
int
i
=
0
;
i
<
config
.
numOfCols
;
i
++
)
{
SColumn
*
pCol
=
config
.
schema
->
columns
+
i
;
pCol
->
type
=
TD_DATATYPE_BIGINT
;
pCol
->
colId
=
config
.
schema
->
colIdCounter
++
;
pCol
->
offset
=
10
;
pCol
->
colName
=
strdup
(
"col1"
);
config
.
numOfCols
=
5
;
config
.
schema
=
tdNewSchema
(
config
.
numOfCols
);
for
(
int
i
=
0
;
i
<
schemaNCols
(
config
.
schema
);
i
++
)
{
SColumn
*
pCol
=
tdNewCol
(
TD_DATATYPE_BIGINT
,
i
,
0
);
tdColCpy
(
schemaColAt
(
config
.
schema
,
i
),
pCol
);
tdFreeCol
(
pCol
);
}
config
.
tagValues
=
nullptr
;
tsdbCreateTableImpl
(
pMeta
,
&
config
)
,
0
;
tsdbCreateTableImpl
(
pMeta
,
&
config
);
STable
*
pTable
=
tsdbGetTableByUid
(
pMeta
,
config
.
tableId
.
uid
);
ASSERT_NE
(
pTable
,
nullptr
);
}
TEST
(
TsdbTest
,
DISABLED_createTsdbRepo
)
{
STsdbCfg
*
pCfg
=
tsdbCreateDefaultCfg
();
tsdb_repo_t
*
pRepo
=
tsdbCreateRepo
(
"/root/mnt/test/vnode0"
,
pCfg
,
NULL
);
tsdbFreeCfg
(
pCfg
);
ASSERT_NE
(
pRepo
,
nullptr
);
STableCfg
config
;
config
.
tableId
.
tid
=
0
;
config
.
tableId
.
uid
=
10889498868728187539
;
config
.
numOfCols
=
2
;
config
.
schema
=
(
SSchema
*
)
malloc
(
sizeof
(
SSchema
)
+
sizeof
(
SColumn
)
*
config
.
numOfCols
);
config
.
schema
->
version
=
0
;
config
.
schema
->
numOfCols
=
2
;
config
.
schema
->
numOfTags
=
0
;
config
.
schema
->
colIdCounter
=
1
;
for
(
int
i
=
0
;
i
<
config
.
numOfCols
;
i
++
)
{
SColumn
*
pCol
=
config
.
schema
->
columns
+
i
;
pCol
->
type
=
TD_DATATYPE_BIGINT
;
pCol
->
colId
=
config
.
schema
->
colIdCounter
++
;
pCol
->
offset
=
10
;
pCol
->
colName
=
strdup
(
"col1"
);
}
config
.
tagValues
=
NULL
;
tsdbCreateTable
(
pRepo
,
&
config
);
tsdbCloseRepo
(
pRepo
);
}
\ No newline at end of file
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录