Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
0525b4fa
T
TDengine
项目概览
taosdata
/
TDengine
12 个月 前同步成功
通知
1181
Star
22014
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看板
体验新版 GitCode,发现更多精彩内容 >>
提交
0525b4fa
编写于
12月 01, 2022
作者:
H
Hongze Cheng
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
more code
上级
f9870c36
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
125 addition
and
238 deletion
+125
-238
include/common/tdataformat.h
include/common/tdataformat.h
+1
-1
include/util/tRealloc.h
include/util/tRealloc.h
+7
-5
source/common/src/tdataformat.c
source/common/src/tdataformat.c
+19
-19
source/dnode/vnode/src/inc/tsdb.h
source/dnode/vnode/src/inc/tsdb.h
+24
-26
source/dnode/vnode/src/tsdb/tsdbUtil.c
source/dnode/vnode/src/tsdb/tsdbUtil.c
+74
-187
未找到文件。
include/common/tdataformat.h
浏览文件 @
0525b4fa
...
...
@@ -94,7 +94,7 @@ int32_t tRowMerge(SArray *aRowP, STSchema *pTSchema, int8_t flag);
int32_t
tRowIterOpen
(
SRow
*
pRow
,
STSchema
*
pTSchema
,
SRowIter
**
ppIter
);
void
tRowIterClose
(
SRowIter
**
ppIter
);
SColVal
*
tRowIterNext
(
SRowIter
*
pIter
);
int32_t
tRowAppendToColData
(
SRow
*
pRow
,
STSchema
*
pTSchema
,
S
Array
*
aColData
,
int32_t
nColData
);
int32_t
tRowAppendToColData
(
SRow
*
pRow
,
STSchema
*
pTSchema
,
S
ColData
*
aColData
,
int32_t
nColData
);
// STag ================================
int32_t
tTagNew
(
SArray
*
pArray
,
int32_t
version
,
int8_t
isJson
,
STag
**
ppTag
);
...
...
include/util/tRealloc.h
浏览文件 @
0525b4fa
...
...
@@ -52,11 +52,13 @@ _exit:
return
code
;
}
static
FORCE_INLINE
void
tFree
(
uint8_t
*
pBuf
)
{
if
(
pBuf
)
{
taosMemoryFree
(
pBuf
-
sizeof
(
int64_t
));
}
}
#define tFree(BUF) \
do { \
if (BUF) { \
taosMemoryFree((uint8_t *)(BUF) - sizeof(int64_t)); \
(BUF) = NULL; \
} \
} while (0)
#ifdef __cplusplus
}
...
...
source/common/src/tdataformat.c
浏览文件 @
0525b4fa
...
...
@@ -841,11 +841,11 @@ _exit:
return
&
pIter
->
cv
;
}
static
int32_t
tRowAppendNoneToColData
(
S
Array
*
aColData
,
int32_t
nColData
)
{
static
int32_t
tRowAppendNoneToColData
(
S
ColData
*
aColData
,
int32_t
nColData
)
{
int32_t
code
=
0
;
for
(
int32_t
iColData
=
0
;
iColData
<
nColData
;
iColData
++
)
{
SColData
*
pColData
=
taosArrayGet
(
aColData
,
iColData
)
;
SColData
*
pColData
=
&
aColData
[
iColData
]
;
code
=
tColDataAppendValueImpl
[
pColData
->
flag
][
CV_FLAG_NONE
](
pColData
,
NULL
,
0
);
if
(
code
)
goto
_exit
;
}
...
...
@@ -853,11 +853,11 @@ static int32_t tRowAppendNoneToColData(SArray *aColData, int32_t nColData) {
_exit:
return
code
;
}
static
int32_t
tRowAppendNullToColData
(
S
Array
*
aColData
,
int32_t
nColData
,
STSchema
*
pSchema
)
{
static
int32_t
tRowAppendNullToColData
(
S
ColData
*
aColData
,
int32_t
nColData
,
STSchema
*
pSchema
)
{
int32_t
code
=
0
;
int32_t
iColData
=
0
;
SColData
*
pColData
=
taosArrayGet
(
aColData
,
iColData
)
;
SColData
*
pColData
=
&
aColData
[
iColData
]
;
int32_t
iTColumn
=
1
;
STColumn
*
pTColumn
=
&
pSchema
->
columns
[
iTColumn
];
...
...
@@ -866,12 +866,12 @@ static int32_t tRowAppendNullToColData(SArray *aColData, int32_t nColData, STSch
if
(
pTColumn
->
colId
==
pColData
->
cid
)
{
// NULL
code
=
tColDataAppendValueImpl
[
pColData
->
flag
][
CV_FLAG_NULL
](
pColData
,
NULL
,
0
);
if
(
code
)
goto
_exit
;
pColData
=
(
++
iColData
<
nColData
)
?
taosArrayGet
(
aColData
,
iColData
)
:
NULL
;
pColData
=
(
++
iColData
<
nColData
)
?
&
aColData
[
iColData
]
:
NULL
;
pTColumn
=
(
++
iTColumn
<
pSchema
->
numOfCols
)
?
&
pSchema
->
columns
[
iTColumn
]
:
NULL
;
}
else
if
(
pTColumn
->
colId
>
pColData
->
cid
)
{
// NONE
code
=
tColDataAppendValueImpl
[
pColData
->
flag
][
CV_FLAG_NONE
](
pColData
,
NULL
,
0
);
if
(
code
)
goto
_exit
;
pColData
=
(
++
iColData
<
nColData
)
?
taosArrayGet
(
aColData
,
iColData
)
:
NULL
;
pColData
=
(
++
iColData
<
nColData
)
?
&
aColData
[
iColData
]
:
NULL
;
}
else
{
pTColumn
=
(
++
iTColumn
<
pSchema
->
numOfCols
)
?
&
pSchema
->
columns
[
iTColumn
]
:
NULL
;
}
...
...
@@ -879,18 +879,18 @@ static int32_t tRowAppendNullToColData(SArray *aColData, int32_t nColData, STSch
code
=
tColDataAppendValueImpl
[
pColData
->
flag
][
CV_FLAG_NONE
](
pColData
,
NULL
,
0
);
if
(
code
)
goto
_exit
;
pColData
=
(
++
iColData
<
nColData
)
?
taosArrayGet
(
aColData
,
iColData
)
:
NULL
;
pColData
=
(
++
iColData
<
nColData
)
?
&
aColData
[
iColData
]
:
NULL
;
}
}
_exit:
return
code
;
}
static
int32_t
tRowAppendTupleToColData
(
SRow
*
pRow
,
STSchema
*
pTSchema
,
S
Array
*
aColData
,
int32_t
nColData
)
{
static
int32_t
tRowAppendTupleToColData
(
SRow
*
pRow
,
STSchema
*
pTSchema
,
S
ColData
*
aColData
,
int32_t
nColData
)
{
int32_t
code
=
0
;
int32_t
iColData
=
0
;
SColData
*
pColData
=
taosArrayGet
(
aColData
,
iColData
)
;
SColData
*
pColData
=
&
aColData
[
iColData
]
;
int32_t
iTColumn
=
1
;
STColumn
*
pTColumn
=
&
pTSchema
->
columns
[
iTColumn
];
...
...
@@ -971,13 +971,13 @@ static int32_t tRowAppendTupleToColData(SRow *pRow, STSchema *pTSchema, SArray *
}
_continue:
pColData
=
(
++
iColData
<
nColData
)
?
taosArrayGet
(
aColData
,
iColData
)
:
NULL
;
pColData
=
(
++
iColData
<
nColData
)
?
&
aColData
[
iColData
]
:
NULL
;
pTColumn
=
(
++
iTColumn
<
pTSchema
->
numOfCols
)
?
&
pTSchema
->
columns
[
iTColumn
]
:
NULL
;
}
else
if
(
pTColumn
->
colId
>
pColData
->
cid
)
{
// NONE
code
=
tColDataAppendValueImpl
[
pColData
->
flag
][
CV_FLAG_NONE
](
pColData
,
NULL
,
0
);
if
(
code
)
goto
_exit
;
pColData
=
(
++
iColData
<
nColData
)
?
taosArrayGet
(
aColData
,
iColData
)
:
NULL
;
pColData
=
(
++
iColData
<
nColData
)
?
&
aColData
[
iColData
]
:
NULL
;
}
else
{
pTColumn
=
(
++
iTColumn
<
pTSchema
->
numOfCols
)
?
&
pTSchema
->
columns
[
iTColumn
]
:
NULL
;
}
...
...
@@ -985,20 +985,20 @@ static int32_t tRowAppendTupleToColData(SRow *pRow, STSchema *pTSchema, SArray *
code
=
tColDataAppendValueImpl
[
pColData
->
flag
][
CV_FLAG_NONE
](
pColData
,
NULL
,
0
);
if
(
code
)
goto
_exit
;
pColData
=
(
++
iColData
<
nColData
)
?
taosArrayGet
(
aColData
,
iColData
)
:
NULL
;
pColData
=
(
++
iColData
<
nColData
)
?
&
aColData
[
iColData
]
:
NULL
;
}
}
_exit:
return
code
;
}
static
int32_t
tRowAppendKVToColData
(
SRow
*
pRow
,
STSchema
*
pTSchema
,
S
Array
*
aColData
,
int32_t
nColData
)
{
static
int32_t
tRowAppendKVToColData
(
SRow
*
pRow
,
STSchema
*
pTSchema
,
S
ColData
*
aColData
,
int32_t
nColData
)
{
int32_t
code
=
0
;
SKVIdx
*
pKVIdx
=
(
SKVIdx
*
)
pRow
->
data
;
uint8_t
*
pv
=
NULL
;
int32_t
iColData
=
0
;
SColData
*
pColData
=
taosArrayGet
(
aColData
,
iColData
)
;
SColData
*
pColData
=
&
aColData
[
iColData
]
;
int32_t
iTColumn
=
1
;
STColumn
*
pTColumn
=
&
pTSchema
->
columns
[
iTColumn
];
int32_t
iCol
=
0
;
...
...
@@ -1054,26 +1054,26 @@ static int32_t tRowAppendKVToColData(SRow *pRow, STSchema *pTSchema, SArray *aCo
if
(
code
)
goto
_exit
;
_continue:
pColData
=
(
++
iColData
<
nColData
)
?
taosArrayGet
(
aColData
,
iColData
)
:
NULL
;
pColData
=
(
++
iColData
<
nColData
)
?
&
aColData
[
iColData
]
:
NULL
;
pTColumn
=
(
++
iTColumn
<
pTSchema
->
numOfCols
)
?
&
pTSchema
->
columns
[
iTColumn
]
:
NULL
;
}
else
if
(
pTColumn
->
colId
>
pColData
->
cid
)
{
code
=
tColDataAppendValueImpl
[
pColData
->
flag
][
CV_FLAG_NONE
](
pColData
,
NULL
,
0
);
if
(
code
)
goto
_exit
;
pColData
=
(
++
iColData
<
nColData
)
?
taosArrayGet
(
aColData
,
iColData
)
:
NULL
;
pColData
=
(
++
iColData
<
nColData
)
?
&
aColData
[
iColData
]
:
NULL
;
}
else
{
pTColumn
=
(
++
iTColumn
<
pTSchema
->
numOfCols
)
?
&
pTSchema
->
columns
[
iTColumn
]
:
NULL
;
}
}
else
{
code
=
tColDataAppendValueImpl
[
pColData
->
flag
][
CV_FLAG_NONE
](
pColData
,
NULL
,
0
);
if
(
code
)
goto
_exit
;
pColData
=
(
++
iColData
<
nColData
)
?
taosArrayGet
(
aColData
,
iColData
)
:
NULL
;
pColData
=
(
++
iColData
<
nColData
)
?
&
aColData
[
iColData
]
:
NULL
;
}
}
_exit:
return
code
;
}
int32_t
tRowAppendToColData
(
SRow
*
pRow
,
STSchema
*
pTSchema
,
S
Array
*
aColData
,
int32_t
nColData
)
{
int32_t
tRowAppendToColData
(
SRow
*
pRow
,
STSchema
*
pTSchema
,
S
ColData
*
aColData
,
int32_t
nColData
)
{
ASSERT
(
pRow
->
sver
==
pTSchema
->
version
);
ASSERT
(
nColData
>
0
);
...
...
@@ -1529,7 +1529,7 @@ void tColDataDestroy(void *ph) {
SColData
*
pColData
=
(
SColData
*
)
ph
;
tFree
(
pColData
->
pBitMap
);
tFree
(
(
uint8_t
*
)
pColData
->
aOffset
);
tFree
(
pColData
->
aOffset
);
tFree
(
pColData
->
pData
);
}
...
...
source/dnode/vnode/src/inc/tsdb.h
浏览文件 @
0525b4fa
...
...
@@ -150,24 +150,22 @@ int32_t tGetBlockIdx(uint8_t *p, void *ph);
int32_t
tCmprBlockIdx
(
void
const
*
lhs
,
void
const
*
rhs
);
int32_t
tCmprBlockL
(
void
const
*
lhs
,
void
const
*
rhs
);
// SBlockData
#define tBlockDataFirstRow(PBLOCKDATA) tsdbRowFromBlockData(PBLOCKDATA, 0)
#define tBlockDataLastRow(PBLOCKDATA) tsdbRowFromBlockData(PBLOCKDATA, (PBLOCKDATA)->nRow - 1)
#define tBlockDataFirstKey(PBLOCKDATA) TSDBROW_KEY(&tBlockDataFirstRow(PBLOCKDATA))
#define tBlockDataLastKey(PBLOCKDATA) TSDBROW_KEY(&tBlockDataLastRow(PBLOCKDATA))
int32_t
tBlockDataCreate
(
SBlockData
*
pBlockData
);
void
tBlockDataDestroy
(
SBlockData
*
pBlockData
);
int32_t
tBlockDataInit
(
SBlockData
*
pBlockData
,
TABLEID
*
pId
,
STSchema
*
pTSchema
,
int16_t
*
aCid
,
int32_t
nCid
);
void
tBlockDataReset
(
SBlockData
*
pBlockData
);
int32_t
tBlockDataAppendRow
(
SBlockData
*
pBlockData
,
TSDBROW
*
pRow
,
STSchema
*
pTSchema
,
int64_t
uid
);
void
tBlockDataClear
(
SBlockData
*
pBlockData
);
SColData
*
tBlockDataGetColDataByIdx
(
SBlockData
*
pBlockData
,
int32_t
idx
);
void
tBlockDataGetColData
(
SBlockData
*
pBlockData
,
int16_t
cid
,
SColData
**
ppColData
);
int32_t
tBlockDataMerge
(
SBlockData
*
pBlockData1
,
SBlockData
*
pBlockData2
,
SBlockData
*
pBlockData
);
int32_t
tBlockDataAddColData
(
SBlockData
*
pBlockData
,
SColData
**
ppColData
);
int32_t
tCmprBlockData
(
SBlockData
*
pBlockData
,
int8_t
cmprAlg
,
uint8_t
**
ppOut
,
int32_t
*
szOut
,
uint8_t
*
aBuf
[],
int32_t
aBufN
[]);
int32_t
tDecmprBlockData
(
uint8_t
*
pIn
,
int32_t
szIn
,
SBlockData
*
pBlockData
,
uint8_t
*
aBuf
[]);
#define tBlockDataFirstRow(PBLOCKDATA) tsdbRowFromBlockData(PBLOCKDATA, 0)
#define tBlockDataLastRow(PBLOCKDATA) tsdbRowFromBlockData(PBLOCKDATA, (PBLOCKDATA)->nRow - 1)
#define tBlockDataFirstKey(PBLOCKDATA) TSDBROW_KEY(&tBlockDataFirstRow(PBLOCKDATA))
#define tBlockDataLastKey(PBLOCKDATA) TSDBROW_KEY(&tBlockDataLastRow(PBLOCKDATA))
#define tBlockDataGetColDataByIdx(PBLOCKDATA, IDX) (&(PBLOCKDATA)->aColData[IDX])
int32_t
tBlockDataCreate
(
SBlockData
*
pBlockData
);
void
tBlockDataDestroy
(
SBlockData
*
pBlockData
);
int32_t
tBlockDataInit
(
SBlockData
*
pBlockData
,
TABLEID
*
pId
,
STSchema
*
pTSchema
,
int16_t
*
aCid
,
int32_t
nCid
);
void
tBlockDataReset
(
SBlockData
*
pBlockData
);
int32_t
tBlockDataAppendRow
(
SBlockData
*
pBlockData
,
TSDBROW
*
pRow
,
STSchema
*
pTSchema
,
int64_t
uid
);
void
tBlockDataClear
(
SBlockData
*
pBlockData
);
void
tBlockDataGetColData
(
SBlockData
*
pBlockData
,
int16_t
cid
,
SColData
**
ppColData
);
int32_t
tCmprBlockData
(
SBlockData
*
pBlockData
,
int8_t
cmprAlg
,
uint8_t
**
ppOut
,
int32_t
*
szOut
,
uint8_t
*
aBuf
[],
int32_t
aBufN
[]);
int32_t
tDecmprBlockData
(
uint8_t
*
pIn
,
int32_t
szIn
,
SBlockData
*
pBlockData
,
uint8_t
*
aBuf
[]);
// SDiskDataHdr
int32_t
tPutDiskDataHdr
(
uint8_t
*
p
,
const
SDiskDataHdr
*
pHdr
);
int32_t
tGetDiskDataHdr
(
uint8_t
*
p
,
void
*
ph
);
...
...
@@ -473,14 +471,14 @@ struct SSttBlk {
// (SBlockData){.suid = suid, .uid = 0}: block data for N child tables int .last file
// (SBlockData){.suid = 0, .uid = uid}: block data for 1 normal table int .last/.data file
struct
SBlockData
{
int64_t
suid
;
// 0 means normal table block data, otherwise child table block data
int64_t
uid
;
// 0 means block data in .last file, otherwise in .data file
int32_t
nRow
;
// number of rows
int64_t
*
aUid
;
// uids of each row, only exist in block data in .last file (uid == 0)
int64_t
*
aVersion
;
// versions of each row
TSKEY
*
aTSKEY
;
// timestamp of each row
int32_t
nColData
;
S
Array
*
aColData
;
// SArray<SColData>
int64_t
suid
;
// 0 means normal table block data, otherwise child table block data
int64_t
uid
;
// 0 means block data in .last file, otherwise in .data file
int32_t
nRow
;
// number of rows
int64_t
*
aUid
;
// uids of each row, only exist in block data in .last file (uid == 0)
int64_t
*
aVersion
;
// versions of each row
TSKEY
*
aTSKEY
;
// timestamp of each row
int32_t
nColData
;
S
ColData
*
aColData
;
};
struct
TABLEID
{
...
...
source/dnode/vnode/src/tsdb/tsdbUtil.c
浏览文件 @
0525b4fa
...
...
@@ -23,7 +23,7 @@ void tMapDataReset(SMapData *pMapData) {
}
void
tMapDataClear
(
SMapData
*
pMapData
)
{
tFree
(
(
uint8_t
*
)
pMapData
->
aOffset
);
tFree
(
pMapData
->
aOffset
);
tFree
(
pMapData
->
pData
);
pMapData
->
pData
=
NULL
;
pMapData
->
aOffset
=
NULL
;
...
...
@@ -928,27 +928,49 @@ int32_t tBlockDataCreate(SBlockData *pBlockData) {
pBlockData
->
aVersion
=
NULL
;
pBlockData
->
aTSKEY
=
NULL
;
pBlockData
->
nColData
=
0
;
pBlockData
->
aColData
=
taosArrayInit
(
0
,
sizeof
(
SColData
));
if
(
pBlockData
->
aColData
==
NULL
)
{
code
=
TSDB_CODE_OUT_OF_MEMORY
;
goto
_exit
;
}
pBlockData
->
aColData
=
NULL
;
_exit:
return
code
;
}
void
tBlockDataDestroy
(
SBlockData
*
pBlockData
)
{
tFree
((
uint8_t
*
)
pBlockData
->
aUid
);
tFree
((
uint8_t
*
)
pBlockData
->
aVersion
);
tFree
((
uint8_t
*
)
pBlockData
->
aTSKEY
);
taosArrayDestroyEx
(
pBlockData
->
aColData
,
tColDataDestroy
);
pBlockData
->
aUid
=
NULL
;
pBlockData
->
aVersion
=
NULL
;
pBlockData
->
aTSKEY
=
NULL
;
pBlockData
->
aColData
=
NULL
;
tFree
(
pBlockData
->
aUid
);
tFree
(
pBlockData
->
aVersion
);
tFree
(
pBlockData
->
aTSKEY
);
for
(
int32_t
i
=
0
;
i
<
pBlockData
->
nColData
;
i
++
)
{
tColDataDestroy
(
&
pBlockData
->
aColData
[
i
]);
}
if
(
pBlockData
->
aColData
)
{
taosMemoryFree
(
pBlockData
->
aColData
);
pBlockData
->
aColData
=
NULL
;
}
}
static
int32_t
tBlockDataAdjustColData
(
SBlockData
*
pBlockData
,
int32_t
nColData
)
{
int32_t
code
=
0
;
if
(
pBlockData
->
nColData
>
nColData
)
{
for
(
int32_t
i
=
nColData
;
i
<
pBlockData
->
nColData
;
i
++
)
{
tColDataDestroy
(
&
pBlockData
->
aColData
[
i
]);
}
}
else
if
(
pBlockData
->
nColData
<
nColData
)
{
SColData
*
aColData
=
taosMemoryRealloc
(
pBlockData
->
aColData
,
sizeof
(
SBlockData
)
*
nColData
);
if
(
aColData
==
NULL
)
{
code
=
TSDB_CODE_OUT_OF_MEMORY
;
goto
_exit
;
}
pBlockData
->
aColData
=
aColData
;
memset
(
&
pBlockData
->
aColData
[
pBlockData
->
nColData
],
0
,
sizeof
(
SBlockData
)
*
(
nColData
-
pBlockData
->
nColData
));
}
pBlockData
->
nColData
=
nColData
;
_exit:
return
code
;
}
int32_t
tBlockDataInit
(
SBlockData
*
pBlockData
,
TABLEID
*
pId
,
STSchema
*
pTSchema
,
int16_t
*
aCid
,
int32_t
nCid
)
{
int32_t
code
=
0
;
...
...
@@ -958,37 +980,35 @@ int32_t tBlockDataInit(SBlockData *pBlockData, TABLEID *pId, STSchema *pTSchema,
pBlockData
->
uid
=
pId
->
uid
;
pBlockData
->
nRow
=
0
;
pBlockData
->
nColData
=
0
;
if
(
aCid
)
{
code
=
tBlockDataAdjustColData
(
pBlockData
,
nCid
);
if
(
code
)
goto
_exit
;
int32_t
iColumn
=
1
;
STColumn
*
pTColumn
=
&
pTSchema
->
columns
[
iColumn
];
for
(
int32_t
iCid
=
0
;
iCid
<
nCid
;
iCid
++
)
{
while
(
pTColumn
&&
pTColumn
->
colId
<
aCid
[
iCid
])
{
ASSERT
(
pTColumn
);
while
(
pTColumn
->
colId
<
aCid
[
iCid
])
{
iColumn
++
;
pTColumn
=
(
iColumn
<
pTSchema
->
numOfCols
)
?
&
pTSchema
->
columns
[
iColumn
]
:
NULL
;
ASSERT
(
iColumn
<
pTSchema
->
numOfCols
);
pTColumn
=
&
pTSchema
->
columns
[
iColumn
];
}
if
(
pTColumn
==
NULL
)
{
break
;
}
else
if
(
pTColumn
->
colId
==
aCid
[
iCid
])
{
SColData
*
pColData
;
code
=
tBlockDataAddColData
(
pBlockData
,
&
pColData
);
if
(
code
)
goto
_exit
;
tColDataInit
(
pColData
,
pTColumn
->
colId
,
pTColumn
->
type
,
(
pTColumn
->
flags
&
COL_SMA_ON
)
?
1
:
0
);
ASSERT
(
pTColumn
->
colId
==
aCid
[
iCid
]);
tColDataInit
(
&
pBlockData
->
aColData
[
iCid
],
pTColumn
->
colId
,
pTColumn
->
type
,
(
pTColumn
->
flags
&
COL_SMA_ON
)
?
1
:
0
);
iColumn
++
;
pTColumn
=
(
iColumn
<
pTSchema
->
numOfCols
)
?
&
pTSchema
->
columns
[
iColumn
]
:
NULL
;
}
iColumn
++
;
pTColumn
=
(
iColumn
<
pTSchema
->
numOfCols
)
?
&
pTSchema
->
columns
[
iColumn
]
:
NULL
;
}
}
else
{
for
(
int32_t
iColumn
=
1
;
iColumn
<
pTSchema
->
numOfCols
;
iColumn
++
)
{
STColumn
*
pTColumn
=
&
pTSchema
->
columns
[
iColumn
];
SColData
*
pColData
;
code
=
tBlockDataAddColData
(
pBlockData
,
&
pColData
);
if
(
code
)
goto
_exit
;
code
=
tBlockDataAdjustColData
(
pBlockData
,
pTSchema
->
numOfCols
-
1
);
if
(
code
)
goto
_exit
;
tColDataInit
(
pColData
,
pTColumn
->
colId
,
pTColumn
->
type
,
(
pTColumn
->
flags
&
COL_SMA_ON
)
?
1
:
0
);
for
(
int32_t
iColData
=
0
;
iColData
<
pBlockData
->
nColData
;
iColData
++
)
{
STColumn
*
pTColumn
=
&
pTSchema
->
columns
[
iColData
+
1
];
tColDataInit
(
&
pBlockData
->
aColData
[
iColData
],
pTColumn
->
colId
,
pTColumn
->
type
,
(
pTColumn
->
flags
&
COL_SMA_ON
)
?
1
:
0
);
}
}
...
...
@@ -999,8 +1019,6 @@ _exit:
void
tBlockDataReset
(
SBlockData
*
pBlockData
)
{
pBlockData
->
suid
=
0
;
pBlockData
->
uid
=
0
;
pBlockData
->
nRow
=
0
;
pBlockData
->
nColData
=
0
;
}
void
tBlockDataClear
(
SBlockData
*
pBlockData
)
{
...
...
@@ -1008,31 +1026,8 @@ void tBlockDataClear(SBlockData *pBlockData) {
pBlockData
->
nRow
=
0
;
for
(
int32_t
iColData
=
0
;
iColData
<
pBlockData
->
nColData
;
iColData
++
)
{
SColData
*
pColData
=
tBlockDataGetColDataByIdx
(
pBlockData
,
iColData
);
tColDataClear
(
pColData
);
}
}
int32_t
tBlockDataAddColData
(
SBlockData
*
pBlockData
,
SColData
**
ppColData
)
{
int32_t
code
=
0
;
SColData
*
pColData
=
NULL
;
if
(
pBlockData
->
nColData
>=
taosArrayGetSize
(
pBlockData
->
aColData
))
{
if
(
taosArrayPush
(
pBlockData
->
aColData
,
&
((
SColData
){
0
}))
==
NULL
)
{
code
=
TSDB_CODE_OUT_OF_MEMORY
;
goto
_err
;
}
tColDataClear
(
tBlockDataGetColDataByIdx
(
pBlockData
,
iColData
));
}
pColData
=
(
SColData
*
)
taosArrayGet
(
pBlockData
->
aColData
,
pBlockData
->
nColData
);
pBlockData
->
nColData
++
;
*
ppColData
=
pColData
;
return
code
;
_err:
*
ppColData
=
NULL
;
return
code
;
}
static
int32_t
tBlockDataAppendBlockRow
(
SBlockData
*
pBlockData
,
SBlockData
*
pBlockDataFrom
,
int32_t
iRow
)
{
...
...
@@ -1095,12 +1090,14 @@ int32_t tBlockDataAppendRow(SBlockData *pBlockData, TSDBROW *pRow, STSchema *pTS
pBlockData
->
aTSKEY
[
pBlockData
->
nRow
]
=
TSDBROW_TS
(
pRow
);
SColVal
cv
=
{
0
};
if
(
pRow
->
type
==
0
)
{
if
(
pRow
->
type
==
TSDBROW_ROW_FMT
)
{
code
=
tRowAppendToColData
(
pRow
->
pTSRow
,
pTSchema
,
pBlockData
->
aColData
,
pBlockData
->
nColData
);
if
(
code
)
goto
_err
;
}
else
{
}
else
if
(
pRow
->
type
==
TSDBROW_COL_FMT
)
{
code
=
tBlockDataAppendBlockRow
(
pBlockData
,
pRow
->
pBlockData
,
pRow
->
iRow
);
if
(
code
)
goto
_err
;
}
else
{
ASSERT
(
0
);
}
pBlockData
->
nRow
++
;
...
...
@@ -1110,133 +1107,13 @@ _err:
return
code
;
}
int32_t
tBlockDataCorrectSchema
(
SBlockData
*
pBlockData
,
SBlockData
*
pBlockDataFrom
)
{
int32_t
code
=
0
;
int32_t
iColData
=
0
;
for
(
int32_t
iColDataFrom
=
0
;
iColDataFrom
<
pBlockDataFrom
->
nColData
;
iColDataFrom
++
)
{
SColData
*
pColDataFrom
=
tBlockDataGetColDataByIdx
(
pBlockDataFrom
,
iColDataFrom
);
while
(
true
)
{
SColData
*
pColData
;
if
(
iColData
<
pBlockData
->
nColData
)
{
pColData
=
tBlockDataGetColDataByIdx
(
pBlockData
,
iColData
);
}
else
{
pColData
=
NULL
;
}
if
(
pColData
==
NULL
||
pColData
->
cid
>
pColDataFrom
->
cid
)
{
code
=
tBlockDataAddColData
(
pBlockData
,
&
pColData
);
if
(
code
)
goto
_exit
;
tColDataInit
(
pColData
,
pColDataFrom
->
cid
,
pColDataFrom
->
type
,
pColDataFrom
->
smaOn
);
for
(
int32_t
iRow
=
0
;
iRow
<
pBlockData
->
nRow
;
iRow
++
)
{
code
=
tColDataAppendValue
(
pColData
,
&
COL_VAL_NONE
(
pColData
->
cid
,
pColData
->
type
));
if
(
code
)
goto
_exit
;
}
iColData
++
;
break
;
}
else
if
(
pColData
->
cid
==
pColDataFrom
->
cid
)
{
iColData
++
;
break
;
}
else
{
iColData
++
;
}
}
}
_exit:
return
code
;
}
int32_t
tBlockDataMerge
(
SBlockData
*
pBlockData1
,
SBlockData
*
pBlockData2
,
SBlockData
*
pBlockData
)
{
int32_t
code
=
0
;
ASSERT
(
pBlockData
->
suid
==
pBlockData1
->
suid
);
ASSERT
(
pBlockData
->
uid
==
pBlockData1
->
uid
);
ASSERT
(
pBlockData1
->
nRow
>
0
);
ASSERT
(
pBlockData2
->
nRow
>
0
);
tBlockDataClear
(
pBlockData
);
TSDBROW
row1
=
tsdbRowFromBlockData
(
pBlockData1
,
0
);
TSDBROW
row2
=
tsdbRowFromBlockData
(
pBlockData2
,
0
);
TSDBROW
*
pRow1
=
&
row1
;
TSDBROW
*
pRow2
=
&
row2
;
while
(
pRow1
&&
pRow2
)
{
int32_t
c
=
tsdbRowCmprFn
(
pRow1
,
pRow2
);
if
(
c
<
0
)
{
code
=
tBlockDataAppendRow
(
pBlockData
,
pRow1
,
NULL
,
pBlockData1
->
uid
?
pBlockData1
->
uid
:
pBlockData1
->
aUid
[
pRow1
->
iRow
]);
if
(
code
)
goto
_exit
;
pRow1
->
iRow
++
;
if
(
pRow1
->
iRow
<
pBlockData1
->
nRow
)
{
*
pRow1
=
tsdbRowFromBlockData
(
pBlockData1
,
pRow1
->
iRow
);
}
else
{
pRow1
=
NULL
;
}
}
else
if
(
c
>
0
)
{
code
=
tBlockDataAppendRow
(
pBlockData
,
pRow2
,
NULL
,
pBlockData2
->
uid
?
pBlockData2
->
uid
:
pBlockData2
->
aUid
[
pRow2
->
iRow
]);
if
(
code
)
goto
_exit
;
pRow2
->
iRow
++
;
if
(
pRow2
->
iRow
<
pBlockData2
->
nRow
)
{
*
pRow2
=
tsdbRowFromBlockData
(
pBlockData2
,
pRow2
->
iRow
);
}
else
{
pRow2
=
NULL
;
}
}
else
{
ASSERT
(
0
);
}
}
while
(
pRow1
)
{
code
=
tBlockDataAppendRow
(
pBlockData
,
pRow1
,
NULL
,
pBlockData1
->
uid
?
pBlockData1
->
uid
:
pBlockData1
->
aUid
[
pRow1
->
iRow
]);
if
(
code
)
goto
_exit
;
pRow1
->
iRow
++
;
if
(
pRow1
->
iRow
<
pBlockData1
->
nRow
)
{
*
pRow1
=
tsdbRowFromBlockData
(
pBlockData1
,
pRow1
->
iRow
);
}
else
{
pRow1
=
NULL
;
}
}
while
(
pRow2
)
{
code
=
tBlockDataAppendRow
(
pBlockData
,
pRow2
,
NULL
,
pBlockData2
->
uid
?
pBlockData2
->
uid
:
pBlockData2
->
aUid
[
pRow2
->
iRow
]);
if
(
code
)
goto
_exit
;
pRow2
->
iRow
++
;
if
(
pRow2
->
iRow
<
pBlockData2
->
nRow
)
{
*
pRow2
=
tsdbRowFromBlockData
(
pBlockData2
,
pRow2
->
iRow
);
}
else
{
pRow2
=
NULL
;
}
}
_exit:
return
code
;
}
SColData
*
tBlockDataGetColDataByIdx
(
SBlockData
*
pBlockData
,
int32_t
idx
)
{
ASSERT
(
idx
>=
0
&&
idx
<
pBlockData
->
nColData
);
return
(
SColData
*
)
taosArrayGet
(
pBlockData
->
aColData
,
idx
);
}
void
tBlockDataGetColData
(
SBlockData
*
pBlockData
,
int16_t
cid
,
SColData
**
ppColData
)
{
ASSERT
(
cid
!=
PRIMARYKEY_TIMESTAMP_COL_ID
);
int32_t
lidx
=
0
;
int32_t
ridx
=
pBlockData
->
nColData
-
1
;
while
(
lidx
<=
ridx
)
{
int32_t
midx
=
(
lidx
+
ridx
)
/
2
;
int32_t
midx
=
(
lidx
+
ridx
)
>>
2
;
SColData
*
pColData
=
tBlockDataGetColDataByIdx
(
pBlockData
,
midx
);
int32_t
c
=
(
pColData
->
cid
==
cid
)
?
0
:
((
pColData
->
cid
>
cid
)
?
1
:
-
1
);
...
...
@@ -1383,15 +1260,25 @@ int32_t tDecmprBlockData(uint8_t *pIn, int32_t szIn, SBlockData *pBlockData, uin
// loop to decode each column data
if
(
hdr
.
szBlkCol
==
0
)
goto
_exit
;
int32_t
nColData
=
0
;
int32_t
nt
=
0
;
while
(
nt
<
hdr
.
szBlkCol
)
{
SBlockCol
blockCol
=
{
0
};
nt
+=
tGetBlockCol
(
pIn
+
n
+
nt
,
&
blockCol
);
ASSERT
(
nt
<=
hdr
.
szBlkCol
);
++
nColData
;
}
ASSERT
(
nt
==
hdr
.
szBlkCol
);
SColData
*
pColData
;
code
=
tBlockDataAddColData
(
pBlockData
,
&
pColData
);
if
(
code
)
goto
_exit
;
code
=
tBlockDataAdjustColData
(
pBlockData
,
nColData
);
if
(
code
)
goto
_exit
;
nt
=
0
;
int32_t
iColData
=
0
;
while
(
nt
<
hdr
.
szBlkCol
)
{
SBlockCol
blockCol
=
{
0
};
nt
+=
tGetBlockCol
(
pIn
+
n
+
nt
,
&
blockCol
);
SColData
*
pColData
=
&
pBlockData
->
aColData
[
iColData
++
];
tColDataInit
(
pColData
,
blockCol
.
cid
,
blockCol
.
type
,
blockCol
.
smaOn
);
if
(
blockCol
.
flag
==
HAS_NULL
)
{
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录