Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
慢慢CG
TDengine
提交
0566dfbd
T
TDengine
项目概览
慢慢CG
/
TDengine
与 Fork 源项目一致
Fork自
taosdata / TDengine
通知
1
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看板
提交
0566dfbd
编写于
3月 06, 2020
作者:
H
hzcheng
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
add more code
上级
7ae3eebe
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
82 addition
and
28 deletion
+82
-28
src/vnode/common/inc/dataformat.h
src/vnode/common/inc/dataformat.h
+13
-5
src/vnode/common/src/dataformat.c
src/vnode/common/src/dataformat.c
+9
-2
src/vnode/tsdb/inc/tsdb.h
src/vnode/tsdb/inc/tsdb.h
+1
-0
src/vnode/tsdb/src/tsdbMeta.c
src/vnode/tsdb/src/tsdbMeta.c
+0
-1
src/vnode/tsdb/tests/tsdbTests.cpp
src/vnode/tsdb/tests/tsdbTests.cpp
+59
-20
未找到文件。
src/vnode/common/inc/dataformat.h
浏览文件 @
0566dfbd
...
...
@@ -16,6 +16,7 @@
#define _TD_DATA_FORMAT_H_
#include <stdint.h>
#include <stdlib.h>
#include "schema.h"
...
...
@@ -39,21 +40,28 @@ typedef void *SDataRow;
#define dataRowTuple(r) ((char *)(r) + sizeof(int32_t))
#define dataRowSetLen(r, l) (dataRowLen(r) = (l))
#define dataRowIdx(r, i) ((char *)(r) + i)
#define dataRowCpy(dst, r) memcpy((dst), (r), dataRowLen(r))
SDataRow
tdNewDataRow
(
int32_t
bytes
);
SDataRow
tdNewDdataFromSchema
(
SSchema
*
pSchema
);
void
tdFreeDataRow
(
SDataRow
row
);
int32_t
tdAppendColVal
(
SDataRow
row
,
void
*
value
,
SColumn
*
pCol
,
int32_t
suffixOffset
);
void
tdDataRowCpy
(
void
*
dst
,
SDataRow
row
);
void
tdDataRowReset
(
SDataRow
row
);
/* Data rows definition, the format of it is like below:
* +---------+---------
+---------
--------------+--------+-----------------------+
* | int32_t |
int32_t |
| | |
* +---------+---------
+---------
--------------+--------+-----------------------+
* | len |
nrows |
SDataRow | .... | SDataRow |
* +---------+---------
+---------
--------------+--------+-----------------------+
* +---------+-----------------------+--------+-----------------------+
* | int32_t | | | |
* +---------+-----------------------+--------+-----------------------+
* | len | SDataRow | .... | SDataRow |
* +---------+-----------------------+--------+-----------------------+
*/
typedef
void
*
SDataRows
;
#define dataRowsLen(rs) (*(int32_t *)(rs))
#define dataRowsSetLen(rs, l) (dataRowsLen(rs) = (l))
#define dataRowsInit(rs) dataRowsSetLen(rs, sizeof(int32_t))
/* Data column definition
* +---------+---------+-----------------------+
* | int32_t | int32_t | |
...
...
src/vnode/common/src/dataformat.c
浏览文件 @
0566dfbd
#include <stdlib.h>
#include "dataformat.h"
/**
...
...
@@ -76,6 +74,15 @@ int32_t tdAppendColVal(SDataRow row, void *value, SColumn *pCol, int32_t suffixO
return
0
;
}
/**
* Copy a data row to a destination
* ASSUMPTIONS: dst has enough room for a copy of row
*/
void
tdDataRowCpy
(
void
*
dst
,
SDataRow
row
)
{
memcpy
(
dst
,
row
,
dataRowLen
(
row
));
}
void
tdDataRowReset
(
SDataRow
row
)
{
dataRowSetLen
(
row
,
sizeof
(
int32_t
));
}
// ------ Codes below should be refactored
SDataRow
tdSDataRowDup
(
SDataRow
rdata
)
{
return
NULL
;
}
void
tdFreeSDataRow
(
SDataRow
rdata
)
{
if
(
rdata
==
NULL
)
return
;
...
...
src/vnode/tsdb/inc/tsdb.h
浏览文件 @
0566dfbd
...
...
@@ -46,6 +46,7 @@ typedef struct {
// Submit message for one table
typedef
struct
{
STableId
tableId
;
int32_t
padding
;
// TODO just for padding here
int32_t
sversion
;
// data schema version
int32_t
len
;
// message length
char
data
[];
...
...
src/vnode/tsdb/src/tsdbMeta.c
浏览文件 @
0566dfbd
...
...
@@ -184,7 +184,6 @@ static int tsdbFreeTable(STable *pTable) {
// TODO: finish this function
if
(
pTable
->
type
==
TSDB_STABLE
)
{
tdFreeSDataRow
(
pTable
->
pTagVal
);
}
else
{
tdFreeSchema
(
pTable
->
pSchema
);
}
...
...
src/vnode/tsdb/tests/tsdbTests.cpp
浏览文件 @
0566dfbd
...
...
@@ -4,35 +4,37 @@
#include "tsdb.h"
#include "tsdbMeta.h"
TEST
(
TsdbTest
,
createTable
)
{
STsdbMeta
*
pMeta
=
tsdbCreateMeta
(
100
);
ASSERT_NE
(
pMeta
,
nullptr
);
STableCfg
config
;
config
.
tableId
.
tid
=
0
;
config
.
tableId
.
uid
=
98868728187539L
;
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
;
TEST
(
TsdbTest
,
createTable
)
{
STsdbMeta
*
pMeta
=
tsdbCreateMeta
(
100
);
ASSERT_NE
(
pMeta
,
nullptr
);
tsdbCreateTableImpl
(
pMeta
,
&
config
);
STableCfg
config
;
config
.
tableId
.
tid
=
0
;
config
.
tableId
.
uid
=
98868728187539L
;
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
;
STable
*
pTable
=
tsdbGetTableByUid
(
pMeta
,
config
.
tableId
.
uid
);
ASSERT_NE
(
pTable
,
nullptr
);
tsdbCreateTableImpl
(
pMeta
,
&
config
);
STable
*
pTable
=
tsdbGetTableByUid
(
pMeta
,
config
.
tableId
.
uid
);
ASSERT_NE
(
pTable
,
nullptr
);
}
TEST
(
TsdbTest
,
createRepo
)
{
TEST
(
TsdbTest
,
createRepo
)
{
STsdbCfg
*
pCfg
=
tsdbCreateDefaultCfg
();
// Create a tsdb repository
tsdb_repo_t
*
pRepo
=
tsdbCreateRepo
(
"/root/mnt/test/vnode0"
,
pCfg
,
NULL
);
ASSERT_NE
(
pRepo
,
nullptr
);
tsdbFreeCfg
(
pCfg
);
// create a normal table in this repository
STableCfg
config
;
config
.
tableId
.
tid
=
0
;
config
.
tableId
.
uid
=
98868728187539L
;
...
...
@@ -48,7 +50,44 @@ TEST(TsdbTest, createRepo) {
}
tsdbCreateTable
(
pRepo
,
&
config
);
tdFreeSchema
(
config
.
schema
);
// Write some data
int32_t
size
=
sizeof
(
SSubmitMsg
)
+
sizeof
(
SSubmitBlock
)
+
tdMaxRowDataBytes
(
config
.
schema
)
*
10
+
sizeof
(
int32_t
);
SSubmitMsg
*
pMsg
=
(
SSubmitMsg
*
)
malloc
(
size
);
pMsg
->
numOfTables
=
1
;
// TODO: use api
SSubmitBlock
*
pBlock
=
(
SSubmitBlock
*
)
pMsg
->
data
;
pBlock
->
tableId
=
{.
uid
=
98868728187539L
,
.
tid
=
0
};
pBlock
->
sversion
=
0
;
pBlock
->
len
=
sizeof
(
SSubmitBlock
);
SDataRows
rows
=
pBlock
->
data
;
dataRowsInit
(
rows
);
SDataRow
row
=
tdNewDataRow
(
tdMaxRowDataBytes
(
config
.
schema
));
int64_t
ttime
=
1583508800000
;
void
*
pDst
=
pBlock
->
data
;
for
(
int
i
=
0
;
i
<
10
;
i
++
)
{
// loop over rows
ttime
+=
(
10000
*
i
);
tdDataRowReset
(
row
);
for
(
int
j
=
0
;
j
<
schemaNCols
(
config
.
schema
);
j
++
)
{
if
(
j
==
0
)
{
// set time stamp
tdAppendColVal
(
row
,
(
void
*
)(
&
ttime
),
schemaColAt
(
config
.
schema
,
j
),
24
);
}
else
{
// set other fields
int
val
=
10
;
tdAppendColVal
(
row
,
(
void
*
)(
&
val
),
schemaColAt
(
config
.
schema
,
j
),
24
);
}
}
dataRowCpy
((
void
*
)
pDst
,
row
);
pDst
+=
dataRowLen
(
row
);
}
tsdbInsertData
(
pRepo
,
pMsg
);
tdFreeDataRow
(
row
);
tdFreeSchema
(
config
.
schema
);
tsdbDropRepo
(
pRepo
);
}
\ No newline at end of file
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录