Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
519b261c
T
TDengine
项目概览
taosdata
/
TDengine
1 年多 前同步成功
通知
1187
Star
22018
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看板
提交
519b261c
编写于
4月 26, 2020
作者:
H
hzcheng
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
TD-166
上级
a7a7ef79
变更
7
隐藏空白更改
内联
并排
Showing
7 changed file
with
101 addition
and
212 deletion
+101
-212
src/common/inc/tdataformat.h
src/common/inc/tdataformat.h
+22
-29
src/common/src/tdataformat.c
src/common/src/tdataformat.c
+61
-164
src/tsdb/src/tsdbMeta.c
src/tsdb/src/tsdbMeta.c
+1
-2
src/tsdb/src/tsdbRWHelper.c
src/tsdb/src/tsdbRWHelper.c
+6
-6
src/tsdb/tests/tsdbTests.cpp
src/tsdb/tests/tsdbTests.cpp
+4
-4
src/util/inc/tutil.h
src/util/inc/tutil.h
+1
-1
src/vnode/src/vnodeWrite.c
src/vnode/src/vnodeWrite.c
+6
-6
未找到文件。
src/common/inc/tdataformat.h
浏览文件 @
519b261c
...
...
@@ -30,7 +30,7 @@ typedef struct {
int8_t
type
;
// Column type
int16_t
colId
;
// column ID
int32_t
bytes
;
// column bytes
int32_t
offset
;
// point offset in
a row data
int32_t
offset
;
// point offset in
SDataRow after the header part
}
STColumn
;
#define colType(col) ((col)->type)
...
...
@@ -43,26 +43,25 @@ typedef struct {
#define colSetBytes(col, b) (colBytes(col) = (b))
#define colSetOffset(col, o) (colOffset(col) = (o))
STColumn
*
tdNewCol
(
int8_t
type
,
int16_t
colId
,
int16_t
bytes
);
void
tdFreeCol
(
STColumn
*
pCol
);
void
tdColCpy
(
STColumn
*
dst
,
STColumn
*
src
);
void
tdSetCol
(
STColumn
*
pCol
,
int8_t
type
,
int16_t
colId
,
int32_t
bytes
);
// ----------------- TSDB SCHEMA DEFINITION
typedef
struct
{
int
totalCols
;
// Total columns allocated
int
numOfCols
;
// Number of columns appended
int
padding
;
// Total columns allocated
int
tlen
;
// maximum length of a SDataRow without the header part
int
flen
;
// First part length in a SDataRow after the header part
STColumn
columns
[];
}
STSchema
;
#define schemaNCols(s) ((s)->numOfCols)
#define schemaTotalCols(s) ((s)->totalCols)
#define schemaTLen(s) ((s)->tlen)
#define schemaFLen(s) ((s)->flen)
#define schemaColAt(s, i) ((s)->columns + i)
STSchema
*
tdNewSchema
(
int32_t
nCols
);
int
tdSchemaAppendCol
(
STSchema
*
pSchema
,
int8_t
type
,
int16_t
colId
,
int32_t
bytes
);
#define tdFreeSchema(s) tfree((s))
int
tdSchemaAddCol
(
STSchema
*
pSchema
,
int8_t
type
,
int16_t
colId
,
int32_t
bytes
);
STSchema
*
tdDupSchema
(
STSchema
*
pSchema
);
void
tdFreeSchema
(
STSchema
*
pSchema
);
void
tdUpdateSchema
(
STSchema
*
pSchema
);
int
tdGetSchemaEncodeSize
(
STSchema
*
pSchema
);
void
*
tdEncodeSchema
(
void
*
dst
,
STSchema
*
pSchema
);
STSchema
*
tdDecodeSchema
(
void
**
psrc
);
...
...
@@ -70,36 +69,30 @@ STSchema *tdDecodeSchema(void **psrc);
// ----------------- Data row structure
/* A data row, the format is like below:
* +----------+---------+---------------------------------+---------------------------------+
* | int32_t | int32_t | | |
* +----------+---------+---------------------------------+---------------------------------+
* | len | flen | First part | Second part |
* +----------+---------+---------------------------------+---------------------------------+
* plen: first part length
* len: the length including sizeof(row) + sizeof(len)
* row: actual row data encoding
* |<------------------------------------- len ---------------------------------->|
* |<--Head ->|<--------- flen -------------->| |
* +----------+---------------------------------+---------------------------------+
* | int32_t | | |
* +----------+---------------------------------+---------------------------------+
* | len | First part | Second part |
* +----------+---------------------------------+---------------------------------+
*/
typedef
void
*
SDataRow
;
#define TD_DATA_ROW_HEAD_SIZE (2 * sizeof(int32_t))
#define TD_DATA_ROW_HEAD_SIZE sizeof(int32_t)
#define dataRowLen(r) (*(int32_t *)(r))
#define dataRow
FLen(r) (*(int32_t *)((char *)(r) + sizeof(int32_t)
))
#define dataRowTuple(r)
((char *)(r) +
TD_DATA_ROW_HEAD_SIZE)
#define dataRow
At(r, idx) ((char *)(r) + (idx
))
#define dataRowTuple(r)
dataRowAt(r,
TD_DATA_ROW_HEAD_SIZE)
#define dataRowKey(r) (*(TSKEY *)(dataRowTuple(r)))
#define dataRowSetLen(r, l) (dataRowLen(r) = (l))
#define dataRowSetFLen(r, l) (dataRowFLen(r) = (l))
#define dataRowIdx(r, i) ((char *)(r) + i)
#define dataRowCpy(dst, r) memcpy((dst), (r), dataRowLen(r))
#define dataRow
At(r, idx) ((char *)(r) + (idx)
)
#define dataRow
MaxBytesFromSchema(s) ((s)->tlen + TD_DATA_ROW_HEAD_SIZE
)
void
tdInitDataRow
(
SDataRow
row
,
STSchema
*
pSchema
);
int
tdMaxRowBytesFromSchema
(
STSchema
*
pSchema
);
SDataRow
tdNewDataRow
(
int32_t
bytes
,
STSchema
*
pSchema
);
SDataRow
tdNewDataRowFromSchema
(
STSchema
*
pSchema
);
void
tdFreeDataRow
(
SDataRow
row
);
int
tdAppendColVal
(
SDataRow
row
,
void
*
value
,
STColumn
*
pCol
);
void
tdInitDataRow
(
SDataRow
row
,
STSchema
*
pSchema
);
int
tdAppendColVal
(
SDataRow
row
,
void
*
value
,
STSchema
*
pSchema
,
int
col
);
void
tdDataRowReset
(
SDataRow
row
,
STSchema
*
pSchema
);
SDataRow
tdDataRowDup
(
SDataRow
row
);
...
...
src/common/src/tdataformat.c
浏览文件 @
519b261c
...
...
@@ -15,71 +15,6 @@
#include "tdataformat.h"
#include "tutil.h"
static
int
tdFLenFromSchema
(
STSchema
*
pSchema
);
/**
* Create a new STColumn object
* ASSUMPTIONS: VALID PARAMETERS
*
* @param type column type
* @param colId column ID
* @param bytes maximum bytes the col taken
*
* @return a STColumn object on success
* NULL for failure
*/
STColumn
*
tdNewCol
(
int8_t
type
,
int16_t
colId
,
int16_t
bytes
)
{
if
(
!
isValidDataType
(
type
,
0
))
return
NULL
;
STColumn
*
pCol
=
(
STColumn
*
)
calloc
(
1
,
sizeof
(
STColumn
));
if
(
pCol
==
NULL
)
return
NULL
;
colSetType
(
pCol
,
type
);
colSetColId
(
pCol
,
colId
);
colSetOffset
(
pCol
,
-
1
);
switch
(
type
)
{
case
TSDB_DATA_TYPE_BINARY
:
case
TSDB_DATA_TYPE_NCHAR
:
colSetBytes
(
pCol
,
bytes
);
break
;
default:
colSetBytes
(
pCol
,
TYPE_BYTES
[
type
]);
break
;
}
return
pCol
;
}
/**
* Free a STColumn object CREATED with tdNewCol
*/
void
tdFreeCol
(
STColumn
*
pCol
)
{
if
(
pCol
)
free
(
pCol
);
}
/**
* Copy from source to destinition
*/
void
tdColCpy
(
STColumn
*
dst
,
STColumn
*
src
)
{
memcpy
((
void
*
)
dst
,
(
void
*
)
src
,
sizeof
(
STColumn
));
}
/**
* Set the column
*/
void
tdSetCol
(
STColumn
*
pCol
,
int8_t
type
,
int16_t
colId
,
int32_t
bytes
)
{
colSetType
(
pCol
,
type
);
colSetColId
(
pCol
,
colId
);
switch
(
type
)
{
case
TSDB_DATA_TYPE_BINARY
:
case
TSDB_DATA_TYPE_NCHAR
:
colSetBytes
(
pCol
,
bytes
);
break
;
default:
colSetBytes
(
pCol
,
TYPE_BYTES
[
type
]);
break
;
}
}
/**
* Create a SSchema object with nCols columns
* ASSUMPTIONS: VALID PARAMETERS
...
...
@@ -90,11 +25,15 @@ void tdSetCol(STColumn *pCol, int8_t type, int16_t colId, int32_t bytes) {
* NULL for failure
*/
STSchema
*
tdNewSchema
(
int32_t
nCols
)
{
int32_t
size
=
sizeof
(
STSchema
)
+
sizeof
(
STColumn
)
*
nCols
;
int32_t
size
=
sizeof
(
STSchema
)
+
sizeof
(
STColumn
)
*
nCols
;
STSchema
*
pSchema
=
(
STSchema
*
)
calloc
(
1
,
size
);
if
(
pSchema
==
NULL
)
return
NULL
;
pSchema
->
numOfCols
=
0
;
pSchema
->
totalCols
=
nCols
;
pSchema
->
flen
=
0
;
pSchema
->
tlen
=
0
;
return
pSchema
;
}
...
...
@@ -102,25 +41,33 @@ STSchema *tdNewSchema(int32_t nCols) {
/**
* Append a column to the schema
*/
int
tdSchemaAppendCol
(
STSchema
*
pSchema
,
int8_t
type
,
int16_t
colId
,
int32_t
bytes
)
{
// if (pSchema->numOfCols >= pSchema->totalCols) return -1;
if
(
!
isValidDataType
(
type
,
0
))
return
-
1
;
int
tdSchemaAddCol
(
STSchema
*
pSchema
,
int8_t
type
,
int16_t
colId
,
int32_t
bytes
)
{
if
(
!
isValidDataType
(
type
,
0
)
||
pSchema
->
numOfCols
>=
pSchema
->
totalCols
)
return
-
1
;
STColumn
*
pCol
=
schemaColAt
(
pSchema
,
schemaNCols
(
pSchema
));
colSetType
(
pCol
,
type
);
colSetColId
(
pCol
,
colId
);
colSetOffset
(
pCol
,
-
1
);
if
(
pSchema
->
numOfCols
==
0
)
{
colSetOffset
(
pCol
,
0
);
}
else
{
colSetOffset
(
pCol
,
pSchema
->
columns
[
pSchema
->
numOfCols
-
1
].
offset
+
TYPE_BYTES
[
type
]);
}
switch
(
type
)
{
case
TSDB_DATA_TYPE_BINARY
:
case
TSDB_DATA_TYPE_NCHAR
:
colSetBytes
(
pCol
,
bytes
);
pSchema
->
tlen
+=
(
TYPE_BYTES
[
type
]
+
sizeof
(
int16_t
)
+
bytes
);
// TODO: remove int16_t here
break
;
default:
colSetBytes
(
pCol
,
TYPE_BYTES
[
type
]);
pSchema
->
tlen
+=
TYPE_BYTES
[
type
];
break
;
}
pSchema
->
numOfCols
++
;
pSchema
->
flen
+=
TYPE_BYTES
[
type
];
ASSERT
(
pCol
->
offset
<
pSchema
->
flen
);
return
0
;
}
...
...
@@ -138,40 +85,22 @@ STSchema *tdDupSchema(STSchema *pSchema) {
return
tSchema
;
}
/**
* Free the SSchema object created by tdNewSchema or tdDupSchema
*/
void
tdFreeSchema
(
STSchema
*
pSchema
)
{
if
(
pSchema
!=
NULL
)
free
(
pSchema
);
}
/**
* Function to update each columns's offset field in the schema.
* ASSUMPTIONS: VALID PARAMETERS
*/
void
tdUpdateSchema
(
STSchema
*
pSchema
)
{
STColumn
*
pCol
=
NULL
;
int32_t
offset
=
TD_DATA_ROW_HEAD_SIZE
;
for
(
int
i
=
0
;
i
<
schemaNCols
(
pSchema
);
i
++
)
{
pCol
=
schemaColAt
(
pSchema
,
i
);
colSetOffset
(
pCol
,
offset
);
offset
+=
TYPE_BYTES
[
pCol
->
type
];
}
}
/**
* 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
));
return
T_MEMBER_SIZE
(
STSchema
,
totalCols
)
+
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
);
ASSERT
(
pSchema
->
numOfCols
==
pSchema
->
totalCols
);
T_APPEND_MEMBER
(
dst
,
pSchema
,
STSchema
,
totalCols
);
for
(
int
i
=
0
;
i
<
schemaNCols
(
pSchema
);
i
++
)
{
STColumn
*
pCol
=
schemaColAt
(
pSchema
,
i
);
T_APPEND_MEMBER
(
dst
,
pCol
,
STColumn
,
type
);
...
...
@@ -186,13 +115,13 @@ void *tdEncodeSchema(void *dst, STSchema *pSchema) {
* Decode a schema from a binary.
*/
STSchema
*
tdDecodeSchema
(
void
**
psrc
)
{
int
numOf
Cols
=
0
;
int
total
Cols
=
0
;
T_READ_MEMBER
(
*
psrc
,
int
,
numOf
Cols
);
T_READ_MEMBER
(
*
psrc
,
int
,
total
Cols
);
STSchema
*
pSchema
=
tdNewSchema
(
numOf
Cols
);
STSchema
*
pSchema
=
tdNewSchema
(
total
Cols
);
if
(
pSchema
==
NULL
)
return
NULL
;
for
(
int
i
=
0
;
i
<
numOf
Cols
;
i
++
)
{
for
(
int
i
=
0
;
i
<
total
Cols
;
i
++
)
{
int8_t
type
=
0
;
int16_t
colId
=
0
;
int32_t
bytes
=
0
;
...
...
@@ -200,7 +129,7 @@ STSchema *tdDecodeSchema(void **psrc) {
T_READ_MEMBER
(
*
psrc
,
int16_t
,
colId
);
T_READ_MEMBER
(
*
psrc
,
int32_t
,
bytes
);
tdSchemaA
ppen
dCol
(
pSchema
,
type
,
colId
,
bytes
);
tdSchemaA
d
dCol
(
pSchema
,
type
,
colId
,
bytes
);
}
return
pSchema
;
...
...
@@ -209,53 +138,18 @@ STSchema *tdDecodeSchema(void **psrc) {
/**
* 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
));
}
void
tdInitDataRow
(
SDataRow
row
,
STSchema
*
pSchema
)
{
dataRowSetLen
(
row
,
TD_DATA_ROW_HEAD_SIZE
+
schemaFLen
(
pSchema
));
}
/**
* Create a data row with maximum row length bytes.
*
* NOTE: THE AAPLICATION SHOULD MAKE SURE BYTES IS LARGE ENOUGH TO
* HOLD THE WHOE ROW.
*
* @param bytes max bytes a row can take
* @return SDataRow object for success
* NULL for failure
*/
SDataRow
tdNewDataRow
(
int32_t
bytes
,
STSchema
*
pSchema
)
{
int32_t
size
=
sizeof
(
int32_t
)
+
bytes
;
SDataRow
tdNewDataRowFromSchema
(
STSchema
*
pSchema
)
{
int32_t
size
=
dataRowMaxBytesFromSchema
(
pSchema
);
SDataRow
row
=
malloc
(
size
);
if
(
row
==
NULL
)
return
NULL
;
tdInitDataRow
(
row
,
pSchema
);
return
row
;
}
/**
* Get maximum bytes a data row from a schema
* ASSUMPTIONS: VALID PARAMETER
*/
int
tdMaxRowBytesFromSchema
(
STSchema
*
pSchema
)
{
// TODO
int
bytes
=
TD_DATA_ROW_HEAD_SIZE
;
for
(
int
i
=
0
;
i
<
schemaNCols
(
pSchema
);
i
++
)
{
STColumn
*
pCol
=
schemaColAt
(
pSchema
,
i
);
bytes
+=
TYPE_BYTES
[
pCol
->
type
];
if
(
pCol
->
type
==
TSDB_DATA_TYPE_BINARY
||
pCol
->
type
==
TSDB_DATA_TYPE_NCHAR
)
{
bytes
+=
pCol
->
bytes
;
}
}
return
bytes
;
}
SDataRow
tdNewDataRowFromSchema
(
STSchema
*
pSchema
)
{
return
tdNewDataRow
(
tdMaxRowBytesFromSchema
(
pSchema
),
pSchema
);
}
/**
* Free the SDataRow object
*/
...
...
@@ -266,20 +160,36 @@ void tdFreeDataRow(SDataRow row) {
/**
* Append a column value to the data row
*/
int
tdAppendColVal
(
SDataRow
row
,
void
*
value
,
STColumn
*
pCol
)
{
switch
(
colType
(
pCol
))
{
case
TSDB_DATA_TYPE_BINARY
:
case
TSDB_DATA_TYPE_NCHAR
:
*
(
int32_t
*
)
dataRowAt
(
row
,
dataRowFLen
(
row
))
=
dataRowLen
(
row
);
dataRowFLen
(
row
)
+=
TYPE_BYTES
[
colType
(
pCol
)];
memcpy
((
void
*
)
dataRowAt
(
row
,
dataRowLen
(
row
)),
value
,
strlen
(
value
));
dataRowLen
(
row
)
+=
strlen
(
value
);
break
;
default:
memcpy
(
dataRowAt
(
row
,
dataRowFLen
(
row
)),
value
,
TYPE_BYTES
[
colType
(
pCol
)]);
dataRowFLen
(
row
)
+=
TYPE_BYTES
[
colType
(
pCol
)];
break
;
int
tdAppendColVal
(
SDataRow
row
,
void
*
value
,
STSchema
*
pSchema
,
int
col
)
{
ASSERT
(
schemaNCols
(
pSchema
)
>
col
);
STColumn
*
pCol
=
schemaColAt
(
pSchema
,
col
);
int32_t
toffset
=
pCol
->
offset
+
TD_DATA_ROW_HEAD_SIZE
;
char
*
ptr
=
dataRowAt
(
row
,
dataRowLen
(
row
));
switch
(
colType
(
pCol
))
{
case
TSDB_DATA_TYPE_BINARY
:
case
TSDB_DATA_TYPE_NCHAR
:
if
(
value
==
NULL
)
{
*
(
int32_t
*
)
dataRowAt
(
row
,
toffset
)
=
-
1
;
}
else
{
int16_t
slen
=
(
colType
(
pCol
)
==
TSDB_DATA_TYPE_BINARY
)
?
strlen
((
char
*
)
value
)
:
wcslen
((
wchar_t
*
)
value
)
*
TSDB_NCHAR_SIZE
;
if
(
slen
>
colBytes
(
pCol
))
return
-
1
;
*
(
int32_t
*
)
dataRowAt
(
row
,
toffset
)
=
dataRowLen
(
row
);
*
(
int16_t
*
)
ptr
=
slen
;
ptr
+=
sizeof
(
int16_t
);
memcpy
((
void
*
)
ptr
,
value
,
slen
);
dataRowLen
(
row
)
+=
(
sizeof
(
int16_t
)
+
slen
);
}
break
;
default:
if
(
value
==
NULL
)
{
setNull
(
dataRowAt
(
row
,
toffset
),
colType
(
pCol
),
colBytes
(
pCol
));
}
else
{
memcpy
(
dataRowAt
(
row
,
toffset
),
value
,
TYPE_BYTES
[
colType
(
pCol
)]);
}
break
;
}
return
0
;
...
...
@@ -392,19 +302,6 @@ void tdPopDataColsPoints(SDataCols *pCols, int pointsToPop) {
pCols
->
numOfPoints
=
pointsLeft
;
}
/**
* 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
;
}
int
tdMergeDataCols
(
SDataCols
*
target
,
SDataCols
*
source
,
int
rowsToMerge
)
{
ASSERT
(
rowsToMerge
>
0
&&
rowsToMerge
<=
source
->
numOfPoints
);
...
...
src/tsdb/src/tsdbMeta.c
浏览文件 @
519b261c
...
...
@@ -451,9 +451,8 @@ static int tsdbAddTableToMeta(STsdbMeta *pMeta, STable *pTable, bool addIdx) {
// Update the pMeta->maxCols and pMeta->maxRowBytes
if
(
pTable
->
type
==
TSDB_SUPER_TABLE
||
pTable
->
type
==
TSDB_NORMAL_TABLE
)
{
if
(
schemaNCols
(
pTable
->
schema
)
>
pMeta
->
maxCols
)
pMeta
->
maxCols
=
schemaNCols
(
pTable
->
schema
);
int
bytes
=
tdMaxRow
BytesFromSchema
(
pTable
->
schema
);
int
bytes
=
dataRowMax
BytesFromSchema
(
pTable
->
schema
);
if
(
bytes
>
pMeta
->
maxRowBytes
)
pMeta
->
maxRowBytes
=
bytes
;
tdUpdateSchema
(
pTable
->
schema
);
}
return
tsdbAddTableIntoMap
(
pMeta
,
pTable
);
...
...
src/tsdb/src/tsdbRWHelper.c
浏览文件 @
519b261c
...
...
@@ -330,7 +330,7 @@ int tsdbWriteDataBlock(SRWHelper *pHelper, SDataCols *pDataCols) {
int
blkIdx
=
(
pCompBlock
==
NULL
)
?
(
pIdx
->
numOfBlocks
-
1
)
:
(
pCompBlock
-
pHelper
->
pCompInfo
->
blocks
);
if
(
pCompBlock
==
NULL
)
{
// No key overlap, must has last block, just merge with the last block
ASSERT
(
pIdx
->
hasLast
&&
pHelper
->
pCompInfo
->
blocks
[
pIdx
->
numOf
Super
Blocks
-
1
].
last
);
ASSERT
(
pIdx
->
hasLast
&&
pHelper
->
pCompInfo
->
blocks
[
pIdx
->
numOfBlocks
-
1
].
last
);
rowsToWrite
=
tsdbMergeDataWithBlock
(
pHelper
,
blkIdx
,
pDataCols
);
if
(
rowsToWrite
<
0
)
goto
_err
;
}
else
{
// Has key overlap
...
...
@@ -782,7 +782,7 @@ static int tsdbMergeDataWithBlock(SRWHelper *pHelper, int blkIdx, SDataCols *pDa
TSKEY
keyFirst
=
dataColsKeyFirst
(
pDataCols
);
SCompIdx
*
pIdx
=
pHelper
->
pCompIdx
+
pHelper
->
tableInfo
.
tid
;
ASSERT
(
blkIdx
<
pIdx
->
numOf
Super
Blocks
);
ASSERT
(
blkIdx
<
pIdx
->
numOfBlocks
);
// SCompBlock *pCompBlock = pHelper->pCompInfo->blocks + blkIdx;
ASSERT
(
blockAtIdx
(
pHelper
,
blkIdx
)
->
numOfSubBlocks
>=
1
);
...
...
@@ -790,7 +790,7 @@ static int tsdbMergeDataWithBlock(SRWHelper *pHelper, int blkIdx, SDataCols *pDa
// ASSERT(compareKeyBlock((void *)&keyFirst, (void *)pCompBlock) == 0);
if
(
keyFirst
>
blockAtIdx
(
pHelper
,
blkIdx
)
->
keyLast
)
{
// Merge with the last block by append
ASSERT
(
blockAtIdx
(
pHelper
,
blkIdx
)
->
numOfPoints
<
pHelper
->
config
.
minRowsPerFileBlock
&&
blkIdx
==
pIdx
->
numOf
Super
Blocks
-
1
);
ASSERT
(
blockAtIdx
(
pHelper
,
blkIdx
)
->
numOfPoints
<
pHelper
->
config
.
minRowsPerFileBlock
&&
blkIdx
==
pIdx
->
numOfBlocks
-
1
);
int
defaultRowsToWrite
=
pHelper
->
config
.
maxRowsPerFileBlock
*
4
/
5
;
// TODO: make a interface
rowsWritten
=
MIN
((
defaultRowsToWrite
-
blockAtIdx
(
pHelper
,
blkIdx
)
->
numOfPoints
),
pDataCols
->
numOfPoints
);
...
...
@@ -961,7 +961,7 @@ static int tsdbAdjustInfoSizeIfNeeded(SRWHelper *pHelper, size_t esize) {
static
int
tsdbInsertSuperBlock
(
SRWHelper
*
pHelper
,
SCompBlock
*
pCompBlock
,
int
blkIdx
)
{
SCompIdx
*
pIdx
=
pHelper
->
pCompIdx
+
pHelper
->
tableInfo
.
tid
;
ASSERT
(
blkIdx
>=
0
&&
blkIdx
<=
pIdx
->
numOf
Super
Blocks
);
ASSERT
(
blkIdx
>=
0
&&
blkIdx
<=
pIdx
->
numOfBlocks
);
ASSERT
(
pCompBlock
->
numOfSubBlocks
==
1
);
// Adjust memory if no more room
...
...
@@ -1004,7 +1004,7 @@ static int tsdbAddSubBlock(SRWHelper *pHelper, SCompBlock *pCompBlock, int blkId
ASSERT
(
pCompBlock
->
numOfSubBlocks
==
0
);
SCompIdx
*
pIdx
=
pHelper
->
pCompIdx
+
pHelper
->
tableInfo
.
tid
;
ASSERT
(
blkIdx
>=
0
&&
blkIdx
<
pIdx
->
numOf
Super
Blocks
);
ASSERT
(
blkIdx
>=
0
&&
blkIdx
<
pIdx
->
numOfBlocks
);
SCompBlock
*
pSCompBlock
=
pHelper
->
pCompInfo
->
blocks
+
blkIdx
;
ASSERT
(
pSCompBlock
->
numOfSubBlocks
>=
1
&&
pSCompBlock
->
numOfSubBlocks
<
TSDB_MAX_SUBBLOCKS
);
...
...
@@ -1088,7 +1088,7 @@ static int tsdbUpdateSuperBlock(SRWHelper *pHelper, SCompBlock *pCompBlock, int
SCompIdx
*
pIdx
=
pHelper
->
pCompIdx
+
pHelper
->
tableInfo
.
tid
;
ASSERT
(
blkIdx
>=
0
&&
blkIdx
<
pIdx
->
numOf
Super
Blocks
);
ASSERT
(
blkIdx
>=
0
&&
blkIdx
<
pIdx
->
numOfBlocks
);
SCompBlock
*
pSCompBlock
=
pHelper
->
pCompInfo
->
blocks
+
blkIdx
;
...
...
src/tsdb/tests/tsdbTests.cpp
浏览文件 @
519b261c
...
...
@@ -105,9 +105,9 @@ TEST(TsdbTest, DISABLED_tableEncodeDecode) {
for
(
int
i
=
0
;
i
<
nCols
;
i
++
)
{
if
(
i
==
0
)
{
tdSchemaA
ppen
dCol
(
schema
,
TSDB_DATA_TYPE_TIMESTAMP
,
i
,
-
1
);
tdSchemaA
d
dCol
(
schema
,
TSDB_DATA_TYPE_TIMESTAMP
,
i
,
-
1
);
}
else
{
tdSchemaA
ppen
dCol
(
schema
,
TSDB_DATA_TYPE_INT
,
i
,
-
1
);
tdSchemaA
d
dCol
(
schema
,
TSDB_DATA_TYPE_INT
,
i
,
-
1
);
}
}
...
...
@@ -149,9 +149,9 @@ TEST(TsdbTest, createRepo) {
for
(
int
i
=
0
;
i
<
nCols
;
i
++
)
{
if
(
i
==
0
)
{
tdSchemaA
ppen
dCol
(
schema
,
TSDB_DATA_TYPE_TIMESTAMP
,
i
,
-
1
);
tdSchemaA
d
dCol
(
schema
,
TSDB_DATA_TYPE_TIMESTAMP
,
i
,
-
1
);
}
else
{
tdSchemaA
ppen
dCol
(
schema
,
TSDB_DATA_TYPE_INT
,
i
,
-
1
);
tdSchemaA
d
dCol
(
schema
,
TSDB_DATA_TYPE_INT
,
i
,
-
1
);
}
}
...
...
src/util/inc/tutil.h
浏览文件 @
519b261c
...
...
@@ -44,7 +44,7 @@ extern "C" {
#define tclose(x) taosCloseSocket(x)
#if
def ASSERTION
#if
ndef NDEBUG
#define ASSERT(x) assert(x)
#else
#define ASSERT(x)
...
...
src/vnode/src/vnodeWrite.c
浏览文件 @
519b261c
...
...
@@ -123,7 +123,7 @@ static int32_t vnodeProcessCreateTableMsg(SVnodeObj *pVnode, void *pCont, SRspRe
STSchema
*
pDestSchema
=
tdNewSchema
(
numOfColumns
);
for
(
int
i
=
0
;
i
<
numOfColumns
;
i
++
)
{
tdSchemaA
ppen
dCol
(
pDestSchema
,
pSchema
[
i
].
type
,
htons
(
pSchema
[
i
].
colId
),
htons
(
pSchema
[
i
].
bytes
));
tdSchemaA
d
dCol
(
pDestSchema
,
pSchema
[
i
].
type
,
htons
(
pSchema
[
i
].
colId
),
htons
(
pSchema
[
i
].
bytes
));
}
tsdbTableSetSchema
(
&
tCfg
,
pDestSchema
,
false
);
tsdbTableSetName
(
&
tCfg
,
pTable
->
tableId
,
false
);
...
...
@@ -131,7 +131,7 @@ static int32_t vnodeProcessCreateTableMsg(SVnodeObj *pVnode, void *pCont, SRspRe
if
(
numOfTags
!=
0
)
{
STSchema
*
pDestTagSchema
=
tdNewSchema
(
numOfTags
);
for
(
int
i
=
numOfColumns
;
i
<
totalCols
;
i
++
)
{
tdSchemaA
ppen
dCol
(
pDestTagSchema
,
pSchema
[
i
].
type
,
htons
(
pSchema
[
i
].
colId
),
htons
(
pSchema
[
i
].
bytes
));
tdSchemaA
d
dCol
(
pDestTagSchema
,
pSchema
[
i
].
type
,
htons
(
pSchema
[
i
].
colId
),
htons
(
pSchema
[
i
].
bytes
));
}
tsdbTableSetTagSchema
(
&
tCfg
,
pDestTagSchema
,
false
);
tsdbTableSetSName
(
&
tCfg
,
pTable
->
superTableId
,
false
);
...
...
@@ -141,7 +141,7 @@ static int32_t vnodeProcessCreateTableMsg(SVnodeObj *pVnode, void *pCont, SRspRe
SDataRow
dataRow
=
tdNewDataRowFromSchema
(
pDestTagSchema
);
for
(
int
i
=
0
;
i
<
numOfTags
;
i
++
)
{
tdAppendColVal
(
dataRow
,
pTagData
+
accumBytes
,
pDestTagSchema
->
columns
+
i
);
tdAppendColVal
(
dataRow
,
pTagData
+
accumBytes
,
pDestTagSchema
,
i
);
accumBytes
+=
htons
(
pSchema
[
i
+
numOfColumns
].
bytes
);
}
tsdbTableSetTagValue
(
&
tCfg
,
dataRow
,
false
);
...
...
@@ -188,14 +188,14 @@ static int32_t vnodeProcessAlterTableMsg(SVnodeObj *pVnode, void *pCont, SRspRet
STSchema
*
pDestSchema
=
tdNewSchema
(
numOfColumns
);
for
(
int
i
=
0
;
i
<
numOfColumns
;
i
++
)
{
tdSchemaA
ppen
dCol
(
pDestSchema
,
pSchema
[
i
].
type
,
htons
(
pSchema
[
i
].
colId
),
htons
(
pSchema
[
i
].
bytes
));
tdSchemaA
d
dCol
(
pDestSchema
,
pSchema
[
i
].
type
,
htons
(
pSchema
[
i
].
colId
),
htons
(
pSchema
[
i
].
bytes
));
}
tsdbTableSetSchema
(
&
tCfg
,
pDestSchema
,
false
);
if
(
numOfTags
!=
0
)
{
STSchema
*
pDestTagSchema
=
tdNewSchema
(
numOfTags
);
for
(
int
i
=
numOfColumns
;
i
<
totalCols
;
i
++
)
{
tdSchemaA
ppen
dCol
(
pDestTagSchema
,
pSchema
[
i
].
type
,
htons
(
pSchema
[
i
].
colId
),
htons
(
pSchema
[
i
].
bytes
));
tdSchemaA
d
dCol
(
pDestTagSchema
,
pSchema
[
i
].
type
,
htons
(
pSchema
[
i
].
colId
),
htons
(
pSchema
[
i
].
bytes
));
}
tsdbTableSetTagSchema
(
&
tCfg
,
pDestTagSchema
,
false
);
...
...
@@ -204,7 +204,7 @@ static int32_t vnodeProcessAlterTableMsg(SVnodeObj *pVnode, void *pCont, SRspRet
SDataRow
dataRow
=
tdNewDataRowFromSchema
(
pDestTagSchema
);
for
(
int
i
=
0
;
i
<
numOfTags
;
i
++
)
{
tdAppendColVal
(
dataRow
,
pTagData
+
accumBytes
,
pDestTagSchema
->
columns
+
i
);
tdAppendColVal
(
dataRow
,
pTagData
+
accumBytes
,
pDestTagSchema
,
i
);
accumBytes
+=
htons
(
pSchema
[
i
+
numOfColumns
].
bytes
);
}
tsdbTableSetTagValue
(
&
tCfg
,
dataRow
,
false
);
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录