Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
e80611c1
T
TDengine
项目概览
taosdata
/
TDengine
1 年多 前同步成功
通知
1185
Star
22016
Fork
4786
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
1
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
T
TDengine
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
1
Issue
1
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
e80611c1
编写于
3月 13, 2020
作者:
H
hzcheng
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
refactor and add more code
上级
c8ed7d15
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
87 addition
and
78 deletion
+87
-78
src/common/inc/dataformat.h
src/common/inc/dataformat.h
+14
-10
src/common/src/dataformat.c
src/common/src/dataformat.c
+48
-57
src/vnode/tsdb/inc/tsdb.h
src/vnode/tsdb/inc/tsdb.h
+1
-1
src/vnode/tsdb/src/tsdbMain.c
src/vnode/tsdb/src/tsdbMain.c
+1
-1
src/vnode/tsdb/tests/tsdbTests.cpp
src/vnode/tsdb/tests/tsdbTests.cpp
+23
-9
未找到文件。
src/common/inc/dataformat.h
浏览文件 @
e80611c1
...
@@ -69,31 +69,35 @@ void tdUpdateSchema(STSchema *pSchema);
...
@@ -69,31 +69,35 @@ void tdUpdateSchema(STSchema *pSchema);
// ----------------- Data row structure
// ----------------- Data row structure
/* A data row, the format is like below:
/* A data row, the format is like below:
* +---------+---------------------------------+
* +----------+---------+---------------------------------+---------------------------------+
* | int32_t | |
* | int32_t | int32_t | | |
* +---------+---------------------------------+
* +----------+---------+---------------------------------+---------------------------------+
* | len | row |
* | len | flen | First part | Second part |
* +---------+---------------------------------+
* +----------+---------+---------------------------------+---------------------------------+
* plen: first part length
* len: the length including sizeof(row) + sizeof(len)
* len: the length including sizeof(row) + sizeof(len)
* row: actual row data encoding
* row: actual row data encoding
*/
*/
typedef
void
*
SDataRow
;
typedef
void
*
SDataRow
;
#define TD_DATA_ROW_HEAD_SIZE
sizeof(int32_t
)
#define TD_DATA_ROW_HEAD_SIZE
(2 * sizeof(int32_t)
)
#define dataRowLen(r) (*(int32_t *)(r))
#define dataRowLen(r) (*(int32_t *)(r))
#define dataRowFLen(r) (*(int32_t *)((char *)(r) + sizeof(int32_t)))
#define dataRowTuple(r) ((char *)(r) + TD_DATA_ROW_HEAD_SIZE)
#define dataRowTuple(r) ((char *)(r) + TD_DATA_ROW_HEAD_SIZE)
#define dataRowSetLen(r, l) (dataRowLen(r) = (l))
#define dataRowSetLen(r, l) (dataRowLen(r) = (l))
#define dataRowSetFLen(r, l) (dataRowFLen(r) = (l))
#define dataRowIdx(r, i) ((char *)(r) + i)
#define dataRowIdx(r, i) ((char *)(r) + i)
#define dataRowCpy(dst, r) memcpy((dst), (r), dataRowLen(r))
#define dataRowCpy(dst, r) memcpy((dst), (r), dataRowLen(r))
#define dataRowAt(r, idx) ((char *)(r) + (idx))
SDataRow
tdNewDataRow
(
int32_t
bytes
);
void
tdInitDataRow
(
SDataRow
row
,
STSchema
*
pSchema
);
int
tdMaxRowBytesFromSchema
(
STSchema
*
pSchema
);
int
tdMaxRowBytesFromSchema
(
STSchema
*
pSchema
);
SDataRow
tdNewDataRow
(
int32_t
bytes
,
STSchema
*
pSchema
);
SDataRow
tdNewDataRowFromSchema
(
STSchema
*
pSchema
);
SDataRow
tdNewDataRowFromSchema
(
STSchema
*
pSchema
);
void
tdFreeDataRow
(
SDataRow
row
);
void
tdFreeDataRow
(
SDataRow
row
);
int
tdAppendColVal
(
SDataRow
row
,
void
*
value
,
STColumn
*
pCol
,
int32_t
suffixOffset
);
int
tdAppendColVal
(
SDataRow
row
,
void
*
value
,
STColumn
*
pCol
);
void
tdDataRowCpy
(
void
*
dst
,
SDataRow
row
);
void
tdDataRowReset
(
SDataRow
row
,
STSchema
*
pSchema
);
void
tdDataRowReset
(
SDataRow
row
);
SDataRow
tdDataRowDup
(
SDataRow
row
);
SDataRow
tdDataRowDup
(
SDataRow
row
);
/* Data rows definition, the format of it is like below:
/* Data rows definition, the format of it is like below:
...
...
src/common/src/dataformat.c
浏览文件 @
e80611c1
...
@@ -14,6 +14,8 @@
...
@@ -14,6 +14,8 @@
*/
*/
#include "dataformat.h"
#include "dataformat.h"
static
int
tdFLenFromSchema
(
STSchema
*
pSchema
);
/**
/**
* Create a new STColumn object
* Create a new STColumn object
* ASSUMPTIONS: VALID PARAMETERS
* ASSUMPTIONS: VALID PARAMETERS
...
@@ -157,6 +159,14 @@ void tdUpdateSchema(STSchema *pSchema) {
...
@@ -157,6 +159,14 @@ void tdUpdateSchema(STSchema *pSchema) {
}
}
}
}
/**
* Initialize a data row
*/
void
tdInitDataRow
(
SDataRow
row
,
STSchema
*
pSchema
)
{
dataRowSetFLen
(
row
,
TD_DATA_ROW_HEAD_SIZE
);
dataRowSetLen
(
row
,
TD_DATA_ROW_HEAD_SIZE
+
tdFLenFromSchema
(
pSchema
));
}
/**
/**
* Create a data row with maximum row length bytes.
* Create a data row with maximum row length bytes.
*
*
...
@@ -167,13 +177,13 @@ void tdUpdateSchema(STSchema *pSchema) {
...
@@ -167,13 +177,13 @@ void tdUpdateSchema(STSchema *pSchema) {
* @return SDataRow object for success
* @return SDataRow object for success
* NULL for failure
* NULL for failure
*/
*/
SDataRow
tdNewDataRow
(
int32_t
bytes
)
{
SDataRow
tdNewDataRow
(
int32_t
bytes
,
STSchema
*
pSchema
)
{
int32_t
size
=
sizeof
(
int32_t
)
+
bytes
;
int32_t
size
=
sizeof
(
int32_t
)
+
bytes
;
SDataRow
row
=
malloc
(
size
);
SDataRow
row
=
malloc
(
size
);
if
(
row
==
NULL
)
return
NULL
;
if
(
row
==
NULL
)
return
NULL
;
dataRowSetLen
(
row
,
sizeof
(
int32_t
)
);
tdInitDataRow
(
row
,
pSchema
);
return
row
;
return
row
;
}
}
...
@@ -197,14 +207,7 @@ int tdMaxRowBytesFromSchema(STSchema *pSchema) {
...
@@ -197,14 +207,7 @@ int tdMaxRowBytesFromSchema(STSchema *pSchema) {
return
bytes
;
return
bytes
;
}
}
SDataRow
tdNewDataRowFromSchema
(
STSchema
*
pSchema
)
{
SDataRow
tdNewDataRowFromSchema
(
STSchema
*
pSchema
)
{
return
tdNewDataRow
(
tdMaxRowBytesFromSchema
(
pSchema
),
pSchema
);
}
int
bytes
=
0
;
{
// TODO: estimiate size from schema
}
return
tdNewDataRow
(
bytes
);
}
/**
/**
* Free the SDataRow object
* Free the SDataRow object
...
@@ -214,62 +217,37 @@ void tdFreeDataRow(SDataRow row) {
...
@@ -214,62 +217,37 @@ void tdFreeDataRow(SDataRow row) {
}
}
/**
/**
* Append a column value to a SDataRow object.
* Append a column value to the data row
* NOTE: THE APPLICATION SHOULD MAKE SURE VALID PARAMETERS. THE FUNCTION ASSUMES
* THE ROW OBJECT HAS ENOUGH SPACE TO HOLD THE VALUE.
*
* @param row the row to append value to
* @param value value pointer to append
* @param pSchema schema
* @param colIdx column index
*
* @return 0 for success and -1 for failure
*/
*/
// int32_t tdAppendColVal(SDataRow row, void *value, SColumn *pCol, int32_t suffixOffset) {
int
tdAppendColVal
(
SDataRow
row
,
void
*
value
,
STColumn
*
pCol
)
{
// int32_t offset;
switch
(
colType
(
pCol
))
{
// switch (pCol->type) {
case
TSDB_DATA_TYPE_BINARY
:
// case TD_DATATYPE_BOOL:
case
TSDB_DATA_TYPE_NCHAR
:
// case TD_DATATYPE_TINYINT:
*
(
int32_t
*
)
dataRowAt
(
row
,
dataRowFLen
(
row
))
=
dataRowLen
(
row
);
// case TD_DATATYPE_SMALLINT:
dataRowFLen
(
row
)
+=
TYPE_BYTES
[
colType
(
pCol
)];
// case TD_DATATYPE_INT:
memcpy
((
void
*
)
dataRowAt
(
row
,
dataRowLen
(
row
)),
value
,
strlen
(
value
));
// case TD_DATATYPE_BIGINT:
dataRowLen
(
row
)
+=
strlen
(
value
);
// case TD_DATATYPE_FLOAT:
break
;
// case TD_DATATYPE_DOUBLE:
default:
// case TD_DATATYPE_TIMESTAMP:
memcpy
(
dataRowAt
(
row
,
dataRowFLen
(
row
)),
value
,
TYPE_BYTES
[
colType
(
pCol
)]);
// memcpy(dataRowIdx(row, pCol->offset + sizeof(int32_t)), value, rowDataLen[pCol->type]);
dataRowFLen
(
row
)
+=
TYPE_BYTES
[
colType
(
pCol
)];
// if (dataRowLen(row) < suffixOffset + sizeof(int32_t))
break
;
// dataRowSetLen(row, dataRowLen(row) + rowDataLen[pCol->type]);
}
// break;
}
// case TD_DATATYPE_VARCHAR:
// offset = dataRowLen(row) > suffixOffset ? dataRowLen(row) : suffixOffset;
void
tdDataRowReset
(
SDataRow
row
,
STSchema
*
pSchema
)
{
tdInitDataRow
(
row
,
pSchema
);
}
// memcpy(dataRowIdx(row, pCol->offset+sizeof(int32_t)), (void *)(&offset), sizeof(offset));
// case TD_DATATYPE_NCHAR:
// case TD_DATATYPE_BINARY:
// break;
// default:
// return -1;
// }
// 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
));
}
SDataRow
tdDataRowDup
(
SDataRow
row
)
{
SDataRow
tdDataRowDup
(
SDataRow
row
)
{
SDataRow
trow
=
tdNewDataRow
(
dataRowLen
(
row
));
SDataRow
trow
=
malloc
(
dataRowLen
(
row
));
if
(
trow
==
NULL
)
return
NULL
;
if
(
trow
==
NULL
)
return
NULL
;
dataRowCpy
(
trow
,
row
);
dataRowCpy
(
trow
,
row
);
return
row
;
return
t
row
;
}
}
void
tdDataRowsAppendRow
(
SDataRows
rows
,
SDataRow
row
)
{
void
tdDataRowsAppendRow
(
SDataRows
rows
,
SDataRow
row
)
{
tdD
ataRowCpy
((
void
*
)((
char
*
)
rows
+
dataRowsLen
(
rows
)),
row
);
d
ataRowCpy
((
void
*
)((
char
*
)
rows
+
dataRowsLen
(
rows
)),
row
);
dataRowsSetLen
(
rows
,
dataRowsLen
(
rows
)
+
dataRowLen
(
row
));
dataRowsSetLen
(
rows
,
dataRowsLen
(
rows
)
+
dataRowLen
(
row
));
}
}
...
@@ -300,4 +278,17 @@ SDataRow tdDataRowsNext(SDataRowsIter *pIter) {
...
@@ -300,4 +278,17 @@ SDataRow tdDataRowsNext(SDataRowsIter *pIter) {
}
}
return
row
;
return
row
;
}
/**
* Return the first part length of a data row for a schema
*/
static
int
tdFLenFromSchema
(
STSchema
*
pSchema
)
{
int
ret
=
0
;
for
(
int
i
=
0
;
i
<
schemaNCols
(
pSchema
);
i
++
)
{
STColumn
*
pCol
=
schemaColAt
(
pSchema
,
i
);
ret
+=
TYPE_BYTES
[
pCol
->
type
];
}
return
ret
;
}
}
\ No newline at end of file
src/vnode/tsdb/inc/tsdb.h
浏览文件 @
e80611c1
...
@@ -96,7 +96,7 @@ typedef struct {
...
@@ -96,7 +96,7 @@ typedef struct {
STableId
tableId
;
STableId
tableId
;
int32_t
padding
;
// TODO just for padding here
int32_t
padding
;
// TODO just for padding here
int32_t
sversion
;
// data schema version
int32_t
sversion
;
// data schema version
int32_t
len
;
//
message length
int32_t
len
;
//
data part length, not including the SSubmitBlk head
char
data
[];
char
data
[];
}
SSubmitBlk
;
}
SSubmitBlk
;
...
...
src/vnode/tsdb/src/tsdbMain.c
浏览文件 @
e80611c1
...
@@ -621,7 +621,7 @@ static int32_t tdInsertRowToTable(STsdbRepo *pRepo, SDataRow row, STable *pTable
...
@@ -621,7 +621,7 @@ static int32_t tdInsertRowToTable(STsdbRepo *pRepo, SDataRow row, STable *pTable
}
}
pNode
->
level
=
level
;
pNode
->
level
=
level
;
tdD
ataRowCpy
(
SL_GET_NODE_DATA
(
pNode
),
row
);
d
ataRowCpy
(
SL_GET_NODE_DATA
(
pNode
),
row
);
// Insert the skiplist node into the data
// Insert the skiplist node into the data
tsdbInsertRowToTableImpl
(
pNode
,
pTable
);
tsdbInsertRowToTableImpl
(
pNode
,
pTable
);
...
...
src/vnode/tsdb/tests/tsdbTests.cpp
浏览文件 @
e80611c1
...
@@ -32,15 +32,29 @@ TEST(TsdbTest, createRepo) {
...
@@ -32,15 +32,29 @@ TEST(TsdbTest, createRepo) {
tsdbCreateTable
(
pRepo
,
&
tCfg
);
tsdbCreateTable
(
pRepo
,
&
tCfg
);
// 3. Loop to write some simple data
// // 3. Loop to write some simple data
// int size = tdMaxRowBytesFromSchema(schema);
// int nRows = 10;
// int nrows = 100;
// SSubmitMsg *pMsg = (SSubmitMsg *)malloc(sizeof(SSubmitMsg) + sizeof(SSubmitBlk) + tdMaxRowBytesFromSchema(schema) * nRows);
// SSubmitMsg *pMsg = (SSubmitMsg *)malloc(sizeof(SSubmitMsg) + sizeof(SSubmitBlk+ size * nrows);
// SSubmitBlk *pBlock = pMsg->blocks;
// {
// pBlock->tableId = {.uid = 987607499877672L, .tid = 0};
// // TODO
// pBlock->sversion = 0;
// pBlock->len = 0;
// int64_t start_time = 1584081000000;
// for (int i = 0; i < nRows; i++) {
// int64_t ttime = start_time + 1000 * i;
// SDataRow row = (SDataRow)(pBlock->data + pBlock->len);
// dataRowInit(row);
// for (int j; j < schemaNCols(schema); j++) {
// if (j == 0) { // Just for timestamp
// tdAppendColVal(row, (void *)(&time), schemaColAt(schema, i), );
// } else { // For int
// }
// }
// pBlock->len += dataRowLen(row);
// }
// }
// tsdbInsertData(pRepo, pMsg);
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录