Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
哥们要飞
TDengine
提交
31705da4
T
TDengine
项目概览
哥们要飞
/
TDengine
与 Fork 源项目一致
Fork自
taosdata / TDengine
通知
1
Star
1
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,发现更多精彩内容 >>
提交
31705da4
编写于
3月 17, 2020
作者:
H
hzcheng
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
TD-27
上级
04e0fa80
变更
7
隐藏空白更改
内联
并排
Showing
7 changed file
with
120 addition
and
75 deletion
+120
-75
src/common/inc/dataformat.h
src/common/inc/dataformat.h
+5
-30
src/common/src/dataformat.c
src/common/src/dataformat.c
+51
-37
src/inc/taosdef.h
src/inc/taosdef.h
+11
-0
src/vnode/tsdb/inc/tsdbMeta.h
src/vnode/tsdb/inc/tsdbMeta.h
+1
-1
src/vnode/tsdb/src/tsdbMain.c
src/vnode/tsdb/src/tsdbMain.c
+1
-1
src/vnode/tsdb/src/tsdbMeta.c
src/vnode/tsdb/src/tsdbMeta.c
+45
-6
src/vnode/tsdb/src/tsdbMetaFile.c
src/vnode/tsdb/src/tsdbMetaFile.c
+6
-0
未找到文件。
src/common/inc/dataformat.h
浏览文件 @
31705da4
...
@@ -51,19 +51,21 @@ void tdSetCol(STColumn *pCol, int8_t type, int16_t colId, int32_t bytes);
...
@@ -51,19 +51,21 @@ void tdSetCol(STColumn *pCol, int8_t type, int16_t colId, int32_t bytes);
// ----------------- TSDB SCHEMA DEFINITION
// ----------------- TSDB SCHEMA DEFINITION
typedef
struct
{
typedef
struct
{
int
numOfCols
;
// Number of columns appended
int
numOfCols
;
// Number of columns appended
int
totalCols
;
// Total columns allocated
int
padding
;
// Total columns allocated
STColumn
columns
[];
STColumn
columns
[];
}
STSchema
;
}
STSchema
;
#define schemaNCols(s) ((s)->numOfCols)
#define schemaNCols(s) ((s)->numOfCols)
#define schemaTCols(s) ((s)->totalCols)
#define schemaColAt(s, i) ((s)->columns + i)
#define schemaColAt(s, i) ((s)->columns + i)
STSchema
*
tdNewSchema
(
int32_t
nCols
);
STSchema
*
tdNewSchema
(
int32_t
nCols
);
int
tdSchemaAppendCol
(
STSchema
*
pSchema
,
int8_t
type
,
int16_t
colId
,
int
16
_t
bytes
);
int
tdSchemaAppendCol
(
STSchema
*
pSchema
,
int8_t
type
,
int16_t
colId
,
int
32
_t
bytes
);
STSchema
*
tdDupSchema
(
STSchema
*
pSchema
);
STSchema
*
tdDupSchema
(
STSchema
*
pSchema
);
void
tdFreeSchema
(
STSchema
*
pSchema
);
void
tdFreeSchema
(
STSchema
*
pSchema
);
void
tdUpdateSchema
(
STSchema
*
pSchema
);
void
tdUpdateSchema
(
STSchema
*
pSchema
);
int
tdGetSchemaEncodeSize
(
STSchema
*
pSchema
);
void
*
tdEncodeSchema
(
void
*
dst
,
STSchema
*
pSchema
);
STSchema
*
tdDecodeSchema
(
void
**
psrc
);
// ----------------- Data row structure
// ----------------- Data row structure
...
@@ -99,33 +101,6 @@ int tdAppendColVal(SDataRow row, void *value, STColumn *pCol);
...
@@ -99,33 +101,6 @@ int tdAppendColVal(SDataRow row, void *value, STColumn *pCol);
void
tdDataRowReset
(
SDataRow
row
,
STSchema
*
pSchema
);
void
tdDataRowReset
(
SDataRow
row
,
STSchema
*
pSchema
);
SDataRow
tdDataRowDup
(
SDataRow
row
);
SDataRow
tdDataRowDup
(
SDataRow
row
);
/* Data rows definition, the format of it is like below:
* +---------+-----------------------+--------+-----------------------+
* | int32_t | | | |
* +---------+-----------------------+--------+-----------------------+
* | len | SDataRow | .... | SDataRow |
* +---------+-----------------------+--------+-----------------------+
*/
typedef
void
*
SDataRows
;
#define TD_DATA_ROWS_HEAD_LEN sizeof(int32_t)
#define dataRowsLen(rs) (*(int32_t *)(rs))
#define dataRowsSetLen(rs, l) (dataRowsLen(rs) = (l))
#define dataRowsInit(rs) dataRowsSetLen(rs, sizeof(int32_t))
void
tdDataRowsAppendRow
(
SDataRows
rows
,
SDataRow
row
);
// Data rows iterator
typedef
struct
{
int32_t
totalLen
;
int32_t
len
;
SDataRow
row
;
}
SDataRowsIter
;
void
tdInitSDataRowsIter
(
SDataRows
rows
,
SDataRowsIter
*
pIter
);
SDataRow
tdDataRowsNext
(
SDataRowsIter
*
pIter
);
/* Data column definition
/* Data column definition
* +---------+---------+-----------------------+
* +---------+---------+-----------------------+
* | int32_t | int32_t | |
* | int32_t | int32_t | |
...
...
src/common/src/dataformat.c
浏览文件 @
31705da4
...
@@ -94,7 +94,6 @@ STSchema *tdNewSchema(int32_t nCols) {
...
@@ -94,7 +94,6 @@ STSchema *tdNewSchema(int32_t nCols) {
STSchema
*
pSchema
=
(
STSchema
*
)
malloc
(
size
);
STSchema
*
pSchema
=
(
STSchema
*
)
malloc
(
size
);
if
(
pSchema
==
NULL
)
return
NULL
;
if
(
pSchema
==
NULL
)
return
NULL
;
pSchema
->
numOfCols
=
0
;
pSchema
->
numOfCols
=
0
;
pSchema
->
totalCols
=
nCols
;
return
pSchema
;
return
pSchema
;
}
}
...
@@ -102,8 +101,8 @@ STSchema *tdNewSchema(int32_t nCols) {
...
@@ -102,8 +101,8 @@ STSchema *tdNewSchema(int32_t nCols) {
/**
/**
* Append a column to the schema
* Append a column to the schema
*/
*/
int
tdSchemaAppendCol
(
STSchema
*
pSchema
,
int8_t
type
,
int16_t
colId
,
int
16
_t
bytes
)
{
int
tdSchemaAppendCol
(
STSchema
*
pSchema
,
int8_t
type
,
int16_t
colId
,
int
32
_t
bytes
)
{
if
(
pSchema
->
numOfCols
>=
pSchema
->
totalCols
)
return
-
1
;
//
if (pSchema->numOfCols >= pSchema->totalCols) return -1;
if
(
!
isValidDataType
(
type
,
0
))
return
-
1
;
if
(
!
isValidDataType
(
type
,
0
))
return
-
1
;
STColumn
*
pCol
=
schemaColAt
(
pSchema
,
schemaNCols
(
pSchema
));
STColumn
*
pCol
=
schemaColAt
(
pSchema
,
schemaNCols
(
pSchema
));
...
@@ -159,6 +158,53 @@ void tdUpdateSchema(STSchema *pSchema) {
...
@@ -159,6 +158,53 @@ void tdUpdateSchema(STSchema *pSchema) {
}
}
}
}
/**
* Return the size of encoded schema
*/
int
tdGetSchemaEncodeSize
(
STSchema
*
pSchema
)
{
return
sizeof
(
STSchema
)
+
schemaNCols
(
pSchema
)
*
(
T_MEMBER_SIZE
(
STColumn
,
type
)
+
T_MEMBER_SIZE
(
STColumn
,
colId
)
+
T_MEMBER_SIZE
(
STColumn
,
bytes
));
}
/**
* Encode a schema to dst, and return the next pointer
*/
void
*
tdEncodeSchema
(
void
*
dst
,
STSchema
*
pSchema
)
{
T_APPEND_MEMBER
(
dst
,
pSchema
,
STSchema
,
numOfCols
);
for
(
int
i
=
0
;
i
<
schemaNCols
(
pSchema
);
i
++
)
{
STColumn
*
pCol
=
schemaColAt
(
pSchema
,
i
);
T_APPEND_MEMBER
(
dst
,
pCol
,
STColumn
,
type
);
T_APPEND_MEMBER
(
dst
,
pCol
,
STColumn
,
colId
);
T_APPEND_MEMBER
(
dst
,
pCol
,
STColumn
,
bytes
);
}
return
dst
;
}
/**
* Decode a schema from a binary.
*/
STSchema
*
tdDecodeSchema
(
void
**
psrc
)
{
int
numOfCols
=
0
;
T_READ_MEMBER
(
*
psrc
,
int
,
numOfCols
);
STSchema
*
pSchema
=
tdNewSchema
(
numOfCols
);
if
(
pSchema
==
NULL
)
return
NULL
;
for
(
int
i
=
0
;
i
<
numOfCols
;
i
++
)
{
int8_t
type
=
0
;
int16_t
colId
=
0
;
int32_t
bytes
=
0
;
T_READ_MEMBER
(
*
psrc
,
int8_t
,
type
);
T_READ_MEMBER
(
*
psrc
,
int16_t
,
colId
);
T_READ_MEMBER
(
*
psrc
,
int32_t
,
bytes
);
tdSchemaAppendCol
(
pSchema
,
type
,
colId
,
bytes
);
}
return
pSchema
;
}
/**
/**
* Initialize a data row
* Initialize a data row
*/
*/
...
@@ -234,6 +280,8 @@ int tdAppendColVal(SDataRow row, void *value, STColumn *pCol) {
...
@@ -234,6 +280,8 @@ int tdAppendColVal(SDataRow row, void *value, STColumn *pCol) {
dataRowFLen
(
row
)
+=
TYPE_BYTES
[
colType
(
pCol
)];
dataRowFLen
(
row
)
+=
TYPE_BYTES
[
colType
(
pCol
)];
break
;
break
;
}
}
return
0
;
}
}
void
tdDataRowReset
(
SDataRow
row
,
STSchema
*
pSchema
)
{
tdInitDataRow
(
row
,
pSchema
);
}
void
tdDataRowReset
(
SDataRow
row
,
STSchema
*
pSchema
)
{
tdInitDataRow
(
row
,
pSchema
);
}
...
@@ -246,40 +294,6 @@ SDataRow tdDataRowDup(SDataRow row) {
...
@@ -246,40 +294,6 @@ SDataRow tdDataRowDup(SDataRow row) {
return
trow
;
return
trow
;
}
}
void
tdDataRowsAppendRow
(
SDataRows
rows
,
SDataRow
row
)
{
dataRowCpy
((
void
*
)((
char
*
)
rows
+
dataRowsLen
(
rows
)),
row
);
dataRowsSetLen
(
rows
,
dataRowsLen
(
rows
)
+
dataRowLen
(
row
));
}
// Initialize the iterator
void
tdInitSDataRowsIter
(
SDataRows
rows
,
SDataRowsIter
*
pIter
)
{
if
(
pIter
==
NULL
)
return
;
pIter
->
totalLen
=
dataRowsLen
(
rows
);
if
(
pIter
->
totalLen
==
TD_DATA_ROWS_HEAD_LEN
)
{
pIter
->
row
=
NULL
;
return
;
}
pIter
->
row
=
(
SDataRow
)((
char
*
)
rows
+
TD_DATA_ROWS_HEAD_LEN
);
pIter
->
len
=
TD_DATA_ROWS_HEAD_LEN
+
dataRowLen
(
pIter
->
row
);
}
// Get the next row in Rows
SDataRow
tdDataRowsNext
(
SDataRowsIter
*
pIter
)
{
SDataRow
row
=
pIter
->
row
;
if
(
row
==
NULL
)
return
NULL
;
if
(
pIter
->
len
>=
pIter
->
totalLen
)
{
pIter
->
row
=
NULL
;
}
else
{
pIter
->
row
=
(
char
*
)
row
+
dataRowLen
(
row
);
pIter
->
len
+=
dataRowLen
(
row
);
}
return
row
;
}
/**
/**
* Return the first part length of a data row for a schema
* Return the first part length of a data row for a schema
*/
*/
...
...
src/inc/taosdef.h
浏览文件 @
31705da4
...
@@ -82,6 +82,17 @@ extern const int32_t TYPE_BYTES[11];
...
@@ -82,6 +82,17 @@ extern const int32_t TYPE_BYTES[11];
#define TSDB_TIME_PRECISION_MILLI_STR "ms"
#define TSDB_TIME_PRECISION_MILLI_STR "ms"
#define TSDB_TIME_PRECISION_MICRO_STR "us"
#define TSDB_TIME_PRECISION_MICRO_STR "us"
#define T_MEMBER_SIZE(type, member) sizeof(((type *)0)->member)
#define T_APPEND_MEMBER(dst, ptr, type, member) \
do {\
memcpy((void *)(dst), (void *)(&((ptr)->member)), T_MEMBER_SIZE(type, member));\
dst = (void *)((char *)(dst) + T_MEMBER_SIZE(type, member));\
} while(0)
#define T_READ_MEMBER(src, type, target) \
do { \
(target) = *(type *)(src); \
(src) = (void *)((char *)src + sizeof(type));\
} while(0)
#define TSDB_KEYSIZE sizeof(TSKEY)
#define TSDB_KEYSIZE sizeof(TSKEY)
...
...
src/vnode/tsdb/inc/tsdbMeta.h
浏览文件 @
31705da4
...
@@ -35,7 +35,7 @@ extern "C" {
...
@@ -35,7 +35,7 @@ extern "C" {
// ---------- TSDB TABLE DEFINITION
// ---------- TSDB TABLE DEFINITION
typedef
struct
STable
{
typedef
struct
STable
{
TSDB_TABLE_TYPE
type
;
int8_t
type
;
STableId
tableId
;
STableId
tableId
;
int32_t
superUid
;
// Super table UID
int32_t
superUid
;
// Super table UID
int32_t
sversion
;
int32_t
sversion
;
...
...
src/vnode/tsdb/src/tsdbMain.c
浏览文件 @
31705da4
...
@@ -459,7 +459,7 @@ SSubmitBlk *tsdbGetSubmitMsgNext(SSubmitMsgIter *pIter) {
...
@@ -459,7 +459,7 @@ SSubmitBlk *tsdbGetSubmitMsgNext(SSubmitMsgIter *pIter) {
if
(
pIter
->
len
>=
pIter
->
totalLen
)
{
if
(
pIter
->
len
>=
pIter
->
totalLen
)
{
pIter
->
pBlock
=
NULL
;
pIter
->
pBlock
=
NULL
;
}
else
{
}
else
{
pIter
->
pBlock
=
(
char
*
)
pBlock
+
pBlock
->
len
+
sizeof
(
SSubmitBlk
);
pIter
->
pBlock
=
(
SSubmitBlk
*
)((
char
*
)
pBlock
+
pBlock
->
len
+
sizeof
(
SSubmitBlk
)
);
}
}
return
pBlock
;
return
pBlock
;
...
...
src/vnode/tsdb/src/tsdbMeta.c
浏览文件 @
31705da4
...
@@ -39,8 +39,21 @@ void *tsdbEncodeTable(STable *pTable, int *contLen) {
...
@@ -39,8 +39,21 @@ void *tsdbEncodeTable(STable *pTable, int *contLen) {
void
*
ret
=
malloc
(
*
contLen
);
void
*
ret
=
malloc
(
*
contLen
);
if
(
ret
==
NULL
)
return
NULL
;
if
(
ret
==
NULL
)
return
NULL
;
// TODO: encode the object to the memory
void
*
ptr
=
ret
;
{}
T_APPEND_MEMBER
(
ptr
,
pTable
,
STable
,
type
);
T_APPEND_MEMBER
(
ptr
,
&
(
pTable
->
tableId
),
STableId
,
uid
);
T_APPEND_MEMBER
(
ptr
,
&
(
pTable
->
tableId
),
STableId
,
tid
);
T_APPEND_MEMBER
(
ptr
,
pTable
,
STable
,
superUid
);
T_APPEND_MEMBER
(
ptr
,
pTable
,
STable
,
sversion
);
if
(
pTable
->
type
==
TSDB_SUPER_TABLE
)
{
ptr
=
tdEncodeSchema
(
ptr
,
pTable
->
schema
);
ptr
=
tdEncodeSchema
(
ptr
,
pTable
->
tagSchema
);
}
else
if
(
pTable
->
type
==
TSDB_CHILD_TABLE
)
{
dataRowCpy
(
ptr
,
pTable
->
tagVal
);
}
else
{
ptr
=
tdEncodeSchema
(
ptr
,
pTable
->
schema
);
}
return
ret
;
return
ret
;
}
}
...
@@ -59,8 +72,20 @@ STable *tsdbDecodeTable(void *cont, int contLen) {
...
@@ -59,8 +72,20 @@ STable *tsdbDecodeTable(void *cont, int contLen) {
STable
*
pTable
=
(
STable
*
)
calloc
(
1
,
sizeof
(
STable
));
STable
*
pTable
=
(
STable
*
)
calloc
(
1
,
sizeof
(
STable
));
if
(
pTable
==
NULL
)
return
NULL
;
if
(
pTable
==
NULL
)
return
NULL
;
{
void
*
ptr
=
cont
;
// TODO recover from the binary content
T_READ_MEMBER
(
ptr
,
int8_t
,
pTable
->
type
);
T_READ_MEMBER
(
ptr
,
int64_t
,
pTable
->
tableId
.
uid
);
T_READ_MEMBER
(
ptr
,
int32_t
,
pTable
->
tableId
.
tid
);
T_READ_MEMBER
(
ptr
,
int32_t
,
pTable
->
superUid
);
T_READ_MEMBER
(
ptr
,
int32_t
,
pTable
->
sversion
);
if
(
pTable
->
type
=
TSDB_SUPER_TABLE
)
{
pTable
->
schema
=
tdDecodeSchema
(
&
ptr
);
pTable
->
tagSchema
=
tdDecodeSchema
(
&
ptr
);
}
else
if
(
pTable
->
type
==
TSDB_CHILD_TABLE
)
{
pTable
->
tagVal
=
tdDataRowDup
(
ptr
);
}
else
{
pTable
->
schema
=
tdDecodeSchema
(
&
ptr
);
}
}
return
pTable
;
return
pTable
;
...
@@ -318,8 +343,22 @@ static int tsdbRemoveTableFromIndex(STsdbMeta *pMeta, STable *pTable) {
...
@@ -318,8 +343,22 @@ static int tsdbRemoveTableFromIndex(STsdbMeta *pMeta, STable *pTable) {
}
}
static
int
tsdbEstimateTableEncodeSize
(
STable
*
pTable
)
{
static
int
tsdbEstimateTableEncodeSize
(
STable
*
pTable
)
{
// TODO
int
size
=
0
;
return
0
;
size
+=
T_MEMBER_SIZE
(
STable
,
type
);
size
+=
T_MEMBER_SIZE
(
STable
,
tableId
);
size
+=
T_MEMBER_SIZE
(
STable
,
superUid
);
size
+=
T_MEMBER_SIZE
(
STable
,
sversion
);
if
(
pTable
->
type
==
TSDB_SUPER_TABLE
)
{
size
+=
tdGetSchemaEncodeSize
(
pTable
->
schema
);
size
+=
tdGetSchemaEncodeSize
(
pTable
->
tagSchema
);
}
else
if
(
pTable
->
type
==
TSDB_CHILD_TABLE
)
{
size
+=
dataRowLen
(
pTable
->
tagVal
);
}
else
{
size
+=
tdGetSchemaEncodeSize
(
pTable
->
schema
);
}
return
size
;
}
}
static
char
*
getTupleKey
(
const
void
*
data
)
{
static
char
*
getTupleKey
(
const
void
*
data
)
{
...
...
src/vnode/tsdb/src/tsdbMetaFile.c
浏览文件 @
31705da4
...
@@ -19,6 +19,8 @@
...
@@ -19,6 +19,8 @@
#include "hash.h"
#include "hash.h"
#include "tsdbMetaFile.h"
#include "tsdbMetaFile.h"
#define TSDB_META_FILE_VERSION_MAJOR 1
#define TSDB_META_FILE_VERSION_MINOR 0
#define TSDB_META_FILE_HEADER_SIZE 512
#define TSDB_META_FILE_HEADER_SIZE 512
typedef
struct
{
typedef
struct
{
...
@@ -182,6 +184,10 @@ static int32_t tsdbCheckMetaHeader(int fd) {
...
@@ -182,6 +184,10 @@ static int32_t tsdbCheckMetaHeader(int fd) {
static
int32_t
tsdbWriteMetaHeader
(
int
fd
)
{
static
int32_t
tsdbWriteMetaHeader
(
int
fd
)
{
// TODO: write the meta file header to file
// TODO: write the meta file header to file
char
head
[
TSDB_META_FILE_HEADER_SIZE
]
=
"
\0
"
;
sprintf
(
head
,
"version: %d.%d"
,
TSDB_META_FILE_VERSION_MAJOR
,
TSDB_META_FILE_VERSION_MINOR
);
write
(
fd
,
(
void
*
)
head
,
TSDB_META_FILE_HEADER_SIZE
);
return
0
;
return
0
;
}
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录