Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
7d50bfcb
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看板
提交
7d50bfcb
编写于
7月 01, 2022
作者:
H
Hongze Cheng
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
more code
上级
36fbf6d7
变更
6
展开全部
隐藏空白更改
内联
并排
Showing
6 changed file
with
632 addition
and
549 deletion
+632
-549
include/common/tcommon.h
include/common/tcommon.h
+4
-2
source/dnode/vnode/src/inc/tsdb.h
source/dnode/vnode/src/inc/tsdb.h
+20
-24
source/dnode/vnode/src/tsdb/tsdbCommit.c
source/dnode/vnode/src/tsdb/tsdbCommit.c
+30
-35
source/dnode/vnode/src/tsdb/tsdbRead.c
source/dnode/vnode/src/tsdb/tsdbRead.c
+1
-4
source/dnode/vnode/src/tsdb/tsdbReaderWriter.c
source/dnode/vnode/src/tsdb/tsdbReaderWriter.c
+483
-228
source/dnode/vnode/src/tsdb/tsdbUtil.c
source/dnode/vnode/src/tsdb/tsdbUtil.c
+94
-256
未找到文件。
include/common/tcommon.h
浏览文件 @
7d50bfcb
...
...
@@ -61,15 +61,17 @@ typedef struct {
uint64_t
suid
;
}
STableListInfo
;
#pragma pack(push, 1)
typedef
struct
SColumnDataAgg
{
int16_t
colId
;
int16_t
maxIndex
;
int16_t
minIndex
;
int16_t
maxIndex
;
int16_t
numOfNull
;
int64_t
sum
;
int64_t
max
;
int64_t
min
;
}
SColumnDataAgg
;
#pragma pack(pop)
typedef
struct
SDataBlockInfo
{
STimeWindow
window
;
...
...
@@ -114,7 +116,7 @@ typedef struct SQueryTableDataCond {
int32_t
order
;
// desc|asc order to iterate the data block
int32_t
numOfCols
;
SColumnInfo
*
colList
;
int32_t
type
;
// data block load type:
int32_t
type
;
// data block load type:
int32_t
numOfTWindows
;
STimeWindow
*
twindows
;
int64_t
startVersion
;
...
...
source/dnode/vnode/src/inc/tsdb.h
浏览文件 @
7d50bfcb
...
...
@@ -119,10 +119,7 @@ int32_t tPutBlockCol(uint8_t *p, void *ph);
int32_t
tGetBlockCol
(
uint8_t
*
p
,
void
*
ph
);
int32_t
tBlockColCmprFn
(
const
void
*
p1
,
const
void
*
p2
);
// SBlock
#define tBlockInit() ((SBlock){0})
void
tBlockReset
(
SBlock
*
pBlock
);
void
tBlockClear
(
SBlock
*
pBlock
);
int32_t
tBlockCopy
(
SBlock
*
pBlockSrc
,
SBlock
*
pBlockDest
);
int32_t
tPutBlock
(
uint8_t
*
p
,
void
*
ph
);
int32_t
tGetBlock
(
uint8_t
*
p
,
void
*
ph
);
int32_t
tBlockCmprFn
(
const
void
*
p1
,
const
void
*
p2
);
...
...
@@ -134,11 +131,11 @@ int32_t tGetBlockIdx(uint8_t *p, void *ph);
int32_t
tCmprBlockIdx
(
void
const
*
lhs
,
void
const
*
rhs
);
// SColdata
#define tColDataInit() ((SColData){0})
void
tColDataReset
(
SColData
*
pColData
,
int16_t
cid
,
int8_t
type
);
void
tColDataReset
(
SColData
*
pColData
,
int16_t
cid
,
int8_t
type
,
int8_t
smaOn
);
void
tColDataClear
(
void
*
ph
);
int32_t
tColDataAppendValue
(
SColData
*
pColData
,
SColVal
*
pColVal
);
int32_t
tColDataCopy
(
SColData
*
pColDataSrc
,
SColData
*
pColDataDest
);
int32_t
tColDataGetValue
(
SColData
*
pColData
,
int32_t
iRow
,
SColVal
*
pColVal
);
int32_t
tColDataCopy
(
SColData
*
pColDataSrc
,
SColData
*
pColDataDest
);
// SBlockData
#define tBlockDataFirstRow(PBLOCKDATA) tsdbRowFromBlockData(PBLOCKDATA, 0)
#define tBlockDataLastRow(PBLOCKDATA) tsdbRowFromBlockData(PBLOCKDATA, (PBLOCKDATA)->nRow - 1)
...
...
@@ -166,9 +163,8 @@ void tsdbFree(uint8_t *pBuf);
#define tMapDataInit() ((SMapData){0})
void
tMapDataReset
(
SMapData
*
pMapData
);
void
tMapDataClear
(
SMapData
*
pMapData
);
int32_t
tMapDataCopy
(
SMapData
*
pMapDataSrc
,
SMapData
*
pMapDataDest
);
int32_t
tMapDataPutItem
(
SMapData
*
pMapData
,
void
*
pItem
,
int32_t
(
*
tPutItemFn
)(
uint8_t
*
,
void
*
));
int32_t
tMapDataGetItemByIdx
(
SMapData
*
pMapData
,
int32_t
idx
,
void
*
pItem
,
int32_t
(
*
tGetItemFn
)(
uint8_t
*
,
void
*
));
void
tMapDataGetItemByIdx
(
SMapData
*
pMapData
,
int32_t
idx
,
void
*
pItem
,
int32_t
(
*
tGetItemFn
)(
uint8_t
*
,
void
*
));
int32_t
tMapDataSearch
(
SMapData
*
pMapData
,
void
*
pSearchItem
,
int32_t
(
*
tGetItemFn
)(
uint8_t
*
,
void
*
),
int32_t
(
*
tItemCmprFn
)(
const
void
*
,
const
void
*
),
void
*
pItem
);
int32_t
tPutMapData
(
uint8_t
*
p
,
SMapData
*
pMapData
);
...
...
@@ -223,7 +219,6 @@ int32_t tsdbWriteBlockIdx(SDataFWriter *pWriter, SArray *aBlockIdx, uint8_t **pp
int32_t
tsdbWriteBlock
(
SDataFWriter
*
pWriter
,
SMapData
*
pMapData
,
uint8_t
**
ppBuf
,
SBlockIdx
*
pBlockIdx
);
int32_t
tsdbWriteBlockData
(
SDataFWriter
*
pWriter
,
SBlockData
*
pBlockData
,
uint8_t
**
ppBuf1
,
uint8_t
**
ppBuf2
,
SBlockIdx
*
pBlockIdx
,
SBlock
*
pBlock
,
int8_t
cmprAlg
);
int32_t
tsdbWriteBlockSMA
(
SDataFWriter
*
pWriter
,
SBlockSMA
*
pBlockSMA
,
int64_t
*
rOffset
,
int64_t
*
rSize
);
SDFileSet
*
tsdbDataFWriterGetWSet
(
SDataFWriter
*
pWriter
);
// SDataFReader
...
...
@@ -373,31 +368,32 @@ struct SBlockIdx {
struct
SMapData
{
int32_t
nItem
;
uint8_t
flag
;
uint8_t
*
pOfst
;
uint32_t
nData
;
int32_t
*
aOffset
;
int32_t
nData
;
uint8_t
*
pData
;
uint8_t
*
pBuf
;
};
typedef
struct
{
int16_t
cid
;
int8_t
type
;
int8_t
flag
;
// HAS_NONE|HAS_NULL|HAS_VALUE
int64_t
offset
;
int64_t
bsize
;
// bitmap size
int64_t
csize
;
// compressed column value size
int64_t
osize
;
// original column value size (only save for variant data type)
int32_t
offset
;
int32_t
szBitmap
;
// bitmap size
int32_t
szOffset
;
// size of offset, only for variant-length data type
int32_t
szValue
;
// compressed column value size
int32_t
szOrigin
;
// original column value size (only save for variant data type)
}
SBlockCol
;
typedef
struct
{
int64_t
nRow
;
int8_t
cmprAlg
;
int64_t
offset
;
int64_t
szVersion
;
// VERSION size
int64_t
szTSKEY
;
// TSKEY size
int64_t
szBlock
;
// total block size
SMapData
mBlockCol
;
// SMapData<SBlockCol>
int32_t
nRow
;
int8_t
cmprAlg
;
int64_t
offset
;
// block data offset
int32_t
szBlockCol
;
// SBlockCol size
int32_t
szVersion
;
// VERSION size
int32_t
szTSKEY
;
// TSKEY size
int32_t
szBlock
;
// total block size
int64_t
sOffset
;
// sma offset
int32_t
nSma
;
// sma size
}
SSubBlock
;
struct
SBlock
{
...
...
@@ -425,7 +421,7 @@ struct SAggrBlkCol {
struct
SColData
{
int16_t
cid
;
int8_t
type
;
int8_t
offsetValid
;
int8_t
smaOn
;
int32_t
nVal
;
uint8_t
flag
;
uint8_t
*
pBitMap
;
...
...
source/dnode/vnode/src/tsdb/tsdbCommit.c
浏览文件 @
7d50bfcb
...
...
@@ -33,12 +33,10 @@ typedef struct {
SDataFReader
*
pReader
;
SArray
*
aBlockIdx
;
// SArray<SBlockIdx>
SMapData
oBlockMap
;
// SMapData<SBlock>, read from reader
SBlock
oBlock
;
SBlockData
oBlockData
;
SDataFWriter
*
pWriter
;
SArray
*
aBlockIdxN
;
// SArray<SBlockIdx>
SMapData
nBlockMap
;
// SMapData<SBlock>
SBlock
nBlock
;
SBlockData
nBlockData
;
int64_t
suid
;
int64_t
uid
;
...
...
@@ -260,7 +258,6 @@ static int32_t tsdbCommitFileDataStart(SCommitter *pCommitter) {
// old
taosArrayClear
(
pCommitter
->
aBlockIdx
);
tMapDataReset
(
&
pCommitter
->
oBlockMap
);
tBlockReset
(
&
pCommitter
->
oBlock
);
tBlockDataReset
(
&
pCommitter
->
oBlockData
);
pRSet
=
tsdbFSStateGetDFileSet
(
pTsdb
->
fs
->
nState
,
pCommitter
->
commitFid
);
if
(
pRSet
)
{
...
...
@@ -274,7 +271,6 @@ static int32_t tsdbCommitFileDataStart(SCommitter *pCommitter) {
// new
taosArrayClear
(
pCommitter
->
aBlockIdxN
);
tMapDataReset
(
&
pCommitter
->
nBlockMap
);
tBlockReset
(
&
pCommitter
->
nBlock
);
tBlockDataReset
(
&
pCommitter
->
nBlockData
);
if
(
pRSet
)
{
wSet
=
(
SDFileSet
){.
diskId
=
pRSet
->
diskId
,
...
...
@@ -351,11 +347,6 @@ static int32_t tsdbCommitBlockData(SCommitter *pCommitter, SBlockData *pBlockDat
code
=
tsdbWriteBlockData
(
pCommitter
->
pWriter
,
pBlockData
,
NULL
,
NULL
,
pBlockIdx
,
pBlock
,
pCommitter
->
cmprAlg
);
if
(
code
)
goto
_err
;
#if 0
code = tsdbWriteBlockSMA(pCommitter, pBlockData, pBlock);
if (code) goto _err;
#endif
code
=
tMapDataPutItem
(
&
pCommitter
->
nBlockMap
,
pBlock
,
tPutBlock
);
if
(
code
)
goto
_err
;
...
...
@@ -371,7 +362,8 @@ static int32_t tsdbMergeTableData(SCommitter *pCommitter, STbDataIter *pIter, SB
SBlockIdx
*
pBlockIdx
=
&
(
SBlockIdx
){.
suid
=
pIter
->
pTbData
->
suid
,
.
uid
=
pIter
->
pTbData
->
uid
};
SBlockData
*
pBlockDataMerge
=
&
pCommitter
->
oBlockData
;
SBlockData
*
pBlockData
=
&
pCommitter
->
nBlockData
;
SBlock
*
pBlock
=
&
pCommitter
->
nBlock
;
SBlock
block
;
SBlock
*
pBlock
=
&
block
;
TSDBROW
*
pRow1
;
TSDBROW
row2
;
TSDBROW
*
pRow2
=
&
row2
;
...
...
@@ -469,7 +461,8 @@ _err:
static
int32_t
tsdbCommitTableMemData
(
SCommitter
*
pCommitter
,
STbDataIter
*
pIter
,
TSDBKEY
toKey
,
int8_t
toDataOnly
)
{
int32_t
code
=
0
;
TSDBROW
*
pRow
;
SBlock
*
pBlock
=
&
pCommitter
->
nBlock
;
SBlock
block
;
SBlock
*
pBlock
=
&
block
;
SBlockData
*
pBlockData
=
&
pCommitter
->
nBlockData
;
int64_t
suid
=
pIter
->
pTbData
->
suid
;
int64_t
uid
=
pIter
->
pTbData
->
uid
;
...
...
@@ -519,13 +512,14 @@ _err:
static
int32_t
tsdbCommitTableDiskData
(
SCommitter
*
pCommitter
,
SBlock
*
pBlock
,
SBlockIdx
*
pBlockIdx
)
{
int32_t
code
=
0
;
SBlock
block
;
if
(
pBlock
->
last
)
{
code
=
tsdbReadBlockData
(
pCommitter
->
pReader
,
pBlockIdx
,
pBlock
,
&
pCommitter
->
oBlockData
,
NULL
,
NULL
);
if
(
code
)
goto
_err
;
tBlockReset
(
&
pCommitter
->
nB
lock
);
code
=
tsdbCommitBlockData
(
pCommitter
,
&
pCommitter
->
oBlockData
,
&
pCommitter
->
nB
lock
,
pBlockIdx
,
0
);
tBlockReset
(
&
b
lock
);
code
=
tsdbCommitBlockData
(
pCommitter
,
&
pCommitter
->
oBlockData
,
&
b
lock
,
pBlockIdx
,
0
);
if
(
code
)
goto
_err
;
}
else
{
code
=
tMapDataPutItem
(
&
pCommitter
->
nBlockMap
,
pBlock
,
tPutBlock
);
...
...
@@ -590,6 +584,7 @@ static int32_t tsdbMergeAsSubBlock(SCommitter *pCommitter, STbDataIter *pIter, S
int32_t
code
=
0
;
SBlockData
*
pBlockData
=
&
pCommitter
->
nBlockData
;
SBlockIdx
*
pBlockIdx
=
&
(
SBlockIdx
){.
suid
=
pIter
->
pTbData
->
suid
,
.
uid
=
pIter
->
pTbData
->
uid
};
SBlock
block
;
TSDBROW
*
pRow
;
tBlockDataReset
(
pBlockData
);
...
...
@@ -617,11 +612,8 @@ static int32_t tsdbMergeAsSubBlock(SCommitter *pCommitter, STbDataIter *pIter, S
}
}
// write as a subblock
code
=
tBlockCopy
(
pBlock
,
&
pCommitter
->
nBlock
);
if
(
code
)
goto
_err
;
code
=
tsdbCommitBlockData
(
pCommitter
,
pBlockData
,
&
pCommitter
->
nBlock
,
pBlockIdx
,
0
);
block
=
*
pBlock
;
code
=
tsdbCommitBlockData
(
pCommitter
,
pBlockData
,
&
block
,
pBlockIdx
,
0
);
if
(
code
)
goto
_err
;
return
code
;
...
...
@@ -670,7 +662,8 @@ static int32_t tsdbCommitTableData(SCommitter *pCommitter, STbData *pTbData, SBl
// start ===========
tMapDataReset
(
&
pCommitter
->
nBlockMap
);
SBlock
*
pBlock
=
&
pCommitter
->
oBlock
;
SBlock
block
;
SBlock
*
pBlock
=
&
block
;
iBlock
=
0
;
if
(
iBlock
<
nBlock
)
{
...
...
@@ -895,6 +888,8 @@ static int32_t tsdbCommitFileData(SCommitter *pCommitter) {
_err:
tsdbError
(
"vgId:%d commit file data failed since %s"
,
TD_VID
(
pTsdb
->
pVnode
),
tstrerror
(
code
));
tsdbDataFReaderClose
(
&
pCommitter
->
pReader
);
tsdbDataFWriterClose
(
&
pCommitter
->
pWriter
,
0
);
return
code
;
}
...
...
@@ -931,21 +926,23 @@ _err:
static
int32_t
tsdbCommitDataStart
(
SCommitter
*
pCommitter
)
{
int32_t
code
=
0
;
pCommitter
->
pReader
=
NULL
;
pCommitter
->
aBlockIdx
=
taosArrayInit
(
0
,
sizeof
(
SBlockIdx
));
pCommitter
->
oBlockMap
=
tMapDataInit
();
pCommitter
->
oBlock
=
tBlockInit
();
pCommitter
->
pWriter
=
NULL
;
if
(
pCommitter
->
aBlockIdx
==
NULL
)
{
code
=
TSDB_CODE_OUT_OF_MEMORY
;
goto
_exit
;
}
pCommitter
->
aBlockIdxN
=
taosArrayInit
(
0
,
sizeof
(
SBlockIdx
));
pCommitter
->
nBlockMap
=
tMapDataInit
();
pCommitter
->
nBlock
=
tBlockInit
();
if
(
pCommitter
->
aBlockIdxN
==
NULL
)
{
code
=
TSDB_CODE_OUT_OF_MEMORY
;
goto
_exit
;
}
code
=
tBlockDataInit
(
&
pCommitter
->
oBlockData
);
if
(
code
)
goto
_exit
;
code
=
tBlockDataInit
(
&
pCommitter
->
nBlockData
);
if
(
code
)
{
tBlockDataClear
(
&
pCommitter
->
oBlockData
);
goto
_exit
;
}
if
(
code
)
goto
_exit
;
_exit:
return
code
;
...
...
@@ -953,13 +950,11 @@ _exit:
static
void
tsdbCommitDataEnd
(
SCommitter
*
pCommitter
)
{
taosArrayDestroy
(
pCommitter
->
aBlockIdx
);
// tMapDataClear(&pCommitter->oBlockMap);
// tBlockClear(&pCommitter->oBlock);
// tBlockDataClear(&pCommitter->oBlockData);
tMapDataClear
(
&
pCommitter
->
oBlockMap
);
tBlockDataClear
(
&
pCommitter
->
oBlockData
);
taosArrayDestroy
(
pCommitter
->
aBlockIdxN
);
// tMapDataClear(&pCommitter->nBlockMap);
// tBlockClear(&pCommitter->nBlock);
// tBlockDataClear(&pCommitter->nBlockData);
tMapDataClear
(
&
pCommitter
->
nBlockMap
);
tBlockDataClear
(
&
pCommitter
->
nBlockData
);
}
static
int32_t
tsdbCommitData
(
SCommitter
*
pCommitter
)
{
...
...
source/dnode/vnode/src/tsdb/tsdbRead.c
浏览文件 @
7d50bfcb
...
...
@@ -807,10 +807,7 @@ static int32_t doLoadFileBlock(STsdbReader* pReader, SArray* pIndexList, uint32_
for
(
int32_t
j
=
0
;
j
<
mapData
.
nItem
;
++
j
)
{
SBlock
block
=
{
0
};
int32_t
code
=
tMapDataGetItemByIdx
(
&
mapData
,
j
,
&
block
,
tGetBlock
);
if
(
code
!=
TSDB_CODE_SUCCESS
)
{
return
code
;
}
tMapDataGetItemByIdx
(
&
mapData
,
j
,
&
block
,
tGetBlock
);
// 1. time range check
if
(
block
.
minKey
.
ts
>
pReader
->
window
.
ekey
||
block
.
maxKey
.
ts
<
pReader
->
window
.
skey
)
{
...
...
source/dnode/vnode/src/tsdb/tsdbReaderWriter.c
浏览文件 @
7d50bfcb
此差异已折叠。
点击以展开。
source/dnode/vnode/src/tsdb/tsdbUtil.c
浏览文件 @
7d50bfcb
...
...
@@ -15,57 +15,15 @@
#include "tsdb.h"
#define TSDB_OFFSET_I32 ((uint8_t)0)
#define TSDB_OFFSET_I16 ((uint8_t)1)
#define TSDB_OFFSET_I8 ((uint8_t)2)
// SMapData =======================================================================
void
tMapDataReset
(
SMapData
*
pMapData
)
{
pMapData
->
flag
=
TSDB_OFFSET_I32
;
pMapData
->
nItem
=
0
;
pMapData
->
nData
=
0
;
}
void
tMapDataClear
(
SMapData
*
pMapData
)
{
if
(
pMapData
->
pBuf
)
{
tsdbFree
(
pMapData
->
pBuf
);
}
else
{
tsdbFree
(
pMapData
->
pOfst
);
tsdbFree
(
pMapData
->
pData
);
}
}
int32_t
tMapDataCopy
(
SMapData
*
pMapDataSrc
,
SMapData
*
pMapDataDest
)
{
int32_t
code
=
0
;
int32_t
size
;
pMapDataDest
->
nItem
=
pMapDataSrc
->
nItem
;
pMapDataDest
->
flag
=
pMapDataSrc
->
flag
;
switch
(
pMapDataDest
->
flag
)
{
case
TSDB_OFFSET_I32
:
size
=
sizeof
(
int32_t
)
*
pMapDataDest
->
nItem
;
break
;
case
TSDB_OFFSET_I16
:
size
=
sizeof
(
int16_t
)
*
pMapDataDest
->
nItem
;
break
;
case
TSDB_OFFSET_I8
:
size
=
sizeof
(
int8_t
)
*
pMapDataDest
->
nItem
;
break
;
default:
ASSERT
(
0
);
}
code
=
tsdbRealloc
(
&
pMapDataDest
->
pOfst
,
size
);
if
(
code
)
goto
_exit
;
memcpy
(
pMapDataDest
->
pOfst
,
pMapDataSrc
->
pOfst
,
size
);
pMapDataDest
->
nData
=
pMapDataSrc
->
nData
;
code
=
tsdbRealloc
(
&
pMapDataDest
->
pData
,
pMapDataDest
->
nData
);
if
(
code
)
goto
_exit
;
memcpy
(
pMapDataDest
->
pData
,
pMapDataSrc
->
pData
,
pMapDataDest
->
nData
);
_exit:
return
code
;
tsdbFree
((
uint8_t
*
)
pMapData
->
aOffset
);
tsdbFree
(
pMapData
->
pData
);
}
int32_t
tMapDataPutItem
(
SMapData
*
pMapData
,
void
*
pItem
,
int32_t
(
*
tPutItemFn
)(
uint8_t
*
,
void
*
))
{
...
...
@@ -77,35 +35,19 @@ int32_t tMapDataPutItem(SMapData *pMapData, void *pItem, int32_t (*tPutItemFn)(u
pMapData
->
nData
+=
tPutItemFn
(
NULL
,
pItem
);
// alloc
code
=
tsdbRealloc
(
&
pMapData
->
pOfs
t
,
sizeof
(
int32_t
)
*
pMapData
->
nItem
);
code
=
tsdbRealloc
(
(
uint8_t
**
)
&
pMapData
->
aOffse
t
,
sizeof
(
int32_t
)
*
pMapData
->
nItem
);
if
(
code
)
goto
_err
;
code
=
tsdbRealloc
(
&
pMapData
->
pData
,
pMapData
->
nData
);
if
(
code
)
goto
_err
;
// put
ASSERT
(
pMapData
->
flag
==
TSDB_OFFSET_I32
);
((
int32_t
*
)
pMapData
->
pOfst
)[
nItem
]
=
offset
;
pMapData
->
aOffset
[
nItem
]
=
offset
;
tPutItemFn
(
pMapData
->
pData
+
offset
,
pItem
);
_err:
return
code
;
}
static
FORCE_INLINE
int32_t
tMapDataGetOffset
(
SMapData
*
pMapData
,
int32_t
idx
)
{
switch
(
pMapData
->
flag
)
{
case
TSDB_OFFSET_I8
:
return
((
int8_t
*
)
pMapData
->
pOfst
)[
idx
];
break
;
case
TSDB_OFFSET_I16
:
return
((
int16_t
*
)
pMapData
->
pOfst
)[
idx
];
break
;
case
TSDB_OFFSET_I32
:
return
((
int32_t
*
)
pMapData
->
pOfst
)[
idx
];
break
;
default:
ASSERT
(
0
);
}
}
int32_t
tMapDataSearch
(
SMapData
*
pMapData
,
void
*
pSearchItem
,
int32_t
(
*
tGetItemFn
)(
uint8_t
*
,
void
*
),
int32_t
(
*
tItemCmprFn
)(
const
void
*
,
const
void
*
),
void
*
pItem
)
{
int32_t
code
=
0
;
...
...
@@ -135,58 +77,25 @@ _exit:
return
code
;
}
int32_t
tMapDataGetItemByIdx
(
SMapData
*
pMapData
,
int32_t
idx
,
void
*
pItem
,
int32_t
(
*
tGetItemFn
)(
uint8_t
*
,
void
*
))
{
int32_t
code
=
0
;
if
(
idx
<
0
||
idx
>=
pMapData
->
nItem
)
{
code
=
TSDB_CODE_NOT_FOUND
;
goto
_exit
;
}
tGetItemFn
(
pMapData
->
pData
+
tMapDataGetOffset
(
pMapData
,
idx
),
pItem
);
_exit:
return
code
;
void
tMapDataGetItemByIdx
(
SMapData
*
pMapData
,
int32_t
idx
,
void
*
pItem
,
int32_t
(
*
tGetItemFn
)(
uint8_t
*
,
void
*
))
{
ASSERT
(
idx
>=
0
&&
idx
<
pMapData
->
nItem
);
tGetItemFn
(
pMapData
->
pData
+
pMapData
->
aOffset
[
idx
],
pItem
);
}
int32_t
tPutMapData
(
uint8_t
*
p
,
SMapData
*
pMapData
)
{
int32_t
n
=
0
;
ASSERT
(
pMapData
->
flag
==
TSDB_OFFSET_I32
);
n
+=
tPutI32v
(
p
?
p
+
n
:
p
,
pMapData
->
nItem
);
if
(
pMapData
->
nItem
)
{
int32_t
maxOffset
=
tMapDataGetOffset
(
pMapData
,
pMapData
->
nItem
-
1
);
if
(
maxOffset
<=
INT8_MAX
)
{
n
+=
tPutU8
(
p
?
p
+
n
:
p
,
TSDB_OFFSET_I8
);
if
(
p
)
{
for
(
int32_t
iItem
=
0
;
iItem
<
pMapData
->
nItem
;
iItem
++
)
{
n
+=
tPutI8
(
p
+
n
,
(
int8_t
)
tMapDataGetOffset
(
pMapData
,
iItem
));
}
}
else
{
n
=
n
+
sizeof
(
int8_t
)
*
pMapData
->
nItem
;
}
}
else
if
(
maxOffset
<=
INT16_MAX
)
{
n
+=
tPutU8
(
p
?
p
+
n
:
p
,
TSDB_OFFSET_I16
);
if
(
p
)
{
for
(
int32_t
iItem
=
0
;
iItem
<
pMapData
->
nItem
;
iItem
++
)
{
n
+=
tPutI16
(
p
+
n
,
(
int16_t
)
tMapDataGetOffset
(
pMapData
,
iItem
));
}
}
else
{
n
=
n
+
sizeof
(
int16_t
)
*
pMapData
->
nItem
;
}
}
else
{
n
+=
tPutU8
(
p
?
p
+
n
:
p
,
TSDB_OFFSET_I32
);
if
(
p
)
{
for
(
int32_t
iItem
=
0
;
iItem
<
pMapData
->
nItem
;
iItem
++
)
{
n
+=
tPutI32
(
p
+
n
,
tMapDataGetOffset
(
pMapData
,
iItem
));
}
}
else
{
n
=
n
+
sizeof
(
int32_t
)
*
pMapData
->
nItem
;
}
for
(
int32_t
iItem
=
0
;
iItem
<
pMapData
->
nItem
;
iItem
++
)
{
n
+=
tPutI32v
(
p
?
p
+
n
:
p
,
pMapData
->
aOffset
[
iItem
]);
}
n
+=
tPutBinary
(
p
?
p
+
n
:
p
,
pMapData
->
pData
,
pMapData
->
nData
);
n
+=
tPutI32v
(
p
?
p
+
n
:
p
,
pMapData
->
nData
);
if
(
p
)
{
memcpy
(
p
+
n
,
pMapData
->
pData
,
pMapData
->
nData
);
}
n
+=
pMapData
->
nData
;
}
return
n
;
...
...
@@ -194,26 +103,22 @@ int32_t tPutMapData(uint8_t *p, SMapData *pMapData) {
int32_t
tGetMapData
(
uint8_t
*
p
,
SMapData
*
pMapData
)
{
int32_t
n
=
0
;
int32_t
offset
;
tMapDataReset
(
pMapData
);
n
+=
tGetI32v
(
p
+
n
,
&
pMapData
->
nItem
);
if
(
pMapData
->
nItem
)
{
n
+=
tGetU8
(
p
+
n
,
&
pMapData
->
flag
);
pMapData
->
pOfst
=
p
+
n
;
switch
(
pMapData
->
flag
)
{
case
TSDB_OFFSET_I8
:
n
=
n
+
sizeof
(
int8_t
)
*
pMapData
->
nItem
;
break
;
case
TSDB_OFFSET_I16
:
n
=
n
+
sizeof
(
int16_t
)
*
pMapData
->
nItem
;
break
;
case
TSDB_OFFSET_I32
:
n
=
n
+
sizeof
(
int32_t
)
*
pMapData
->
nItem
;
break
;
default:
ASSERT
(
0
);
if
(
tsdbRealloc
((
uint8_t
**
)
&
pMapData
->
aOffset
,
sizeof
(
int32_t
)
*
pMapData
->
nItem
))
return
-
1
;
for
(
int32_t
iItem
=
0
;
iItem
<
pMapData
->
nItem
;
iItem
++
)
{
n
+=
tGetI32v
(
p
+
n
,
&
pMapData
->
aOffset
[
iItem
]);
}
n
+=
tGetBinary
(
p
+
n
,
&
pMapData
->
pData
,
&
pMapData
->
nData
);
n
+=
tGetI32v
(
p
+
n
,
&
pMapData
->
nData
);
if
(
tsdbRealloc
(
&
pMapData
->
pData
,
pMapData
->
nData
))
return
-
1
;
memcpy
(
pMapData
->
pData
,
p
+
n
,
pMapData
->
nData
);
n
+=
pMapData
->
nData
;
}
return
n
;
...
...
@@ -377,55 +282,8 @@ int32_t tCmprBlockIdx(void const *lhs, void const *rhs) {
// SBlock ======================================================
void
tBlockReset
(
SBlock
*
pBlock
)
{
pBlock
->
minKey
=
TSDBKEY_MAX
;
pBlock
->
maxKey
=
TSDBKEY_MIN
;
pBlock
->
minVersion
=
VERSION_MAX
;
pBlock
->
maxVersion
=
VERSION_MIN
;
pBlock
->
nRow
=
0
;
pBlock
->
last
=
-
1
;
pBlock
->
hasDup
=
0
;
for
(
int8_t
iSubBlock
=
0
;
iSubBlock
<
TSDB_MAX_SUBBLOCKS
;
iSubBlock
++
)
{
pBlock
->
aSubBlock
[
iSubBlock
].
nRow
=
0
;
pBlock
->
aSubBlock
[
iSubBlock
].
cmprAlg
=
-
1
;
pBlock
->
aSubBlock
[
iSubBlock
].
offset
=
-
1
;
pBlock
->
aSubBlock
[
iSubBlock
].
szVersion
=
-
1
;
pBlock
->
aSubBlock
[
iSubBlock
].
szTSKEY
=
-
1
;
pBlock
->
aSubBlock
[
iSubBlock
].
szBlock
=
-
1
;
tMapDataReset
(
&
pBlock
->
aSubBlock
->
mBlockCol
);
}
pBlock
->
nSubBlock
=
0
;
}
void
tBlockClear
(
SBlock
*
pBlock
)
{
for
(
int8_t
iSubBlock
=
0
;
iSubBlock
<
TSDB_MAX_SUBBLOCKS
;
iSubBlock
++
)
{
tMapDataClear
(
&
pBlock
->
aSubBlock
->
mBlockCol
);
}
}
int32_t
tBlockCopy
(
SBlock
*
pBlockSrc
,
SBlock
*
pBlockDest
)
{
int32_t
code
=
0
;
pBlockDest
->
minKey
=
pBlockSrc
->
minKey
;
pBlockDest
->
maxKey
=
pBlockSrc
->
maxKey
;
pBlockDest
->
minVersion
=
pBlockSrc
->
minVersion
;
pBlockDest
->
maxVersion
=
pBlockSrc
->
maxVersion
;
pBlockDest
->
nRow
=
pBlockSrc
->
nRow
;
pBlockDest
->
last
=
pBlockSrc
->
last
;
pBlockDest
->
hasDup
=
pBlockSrc
->
hasDup
;
pBlockDest
->
nSubBlock
=
pBlockSrc
->
nSubBlock
;
for
(
int32_t
iSubBlock
=
0
;
iSubBlock
<
pBlockSrc
->
nSubBlock
;
iSubBlock
++
)
{
pBlockDest
->
aSubBlock
[
iSubBlock
].
nRow
=
pBlockSrc
->
aSubBlock
[
iSubBlock
].
nRow
;
pBlockDest
->
aSubBlock
[
iSubBlock
].
cmprAlg
=
pBlockSrc
->
aSubBlock
[
iSubBlock
].
cmprAlg
;
pBlockDest
->
aSubBlock
[
iSubBlock
].
offset
=
pBlockSrc
->
aSubBlock
[
iSubBlock
].
offset
;
pBlockDest
->
aSubBlock
[
iSubBlock
].
szVersion
=
pBlockSrc
->
aSubBlock
[
iSubBlock
].
szVersion
;
pBlockDest
->
aSubBlock
[
iSubBlock
].
szTSKEY
=
pBlockSrc
->
aSubBlock
[
iSubBlock
].
szTSKEY
;
pBlockDest
->
aSubBlock
[
iSubBlock
].
szBlock
=
pBlockSrc
->
aSubBlock
[
iSubBlock
].
szBlock
;
code
=
tMapDataCopy
(
&
pBlockSrc
->
aSubBlock
[
iSubBlock
].
mBlockCol
,
&
pBlockDest
->
aSubBlock
[
iSubBlock
].
mBlockCol
);
if
(
code
)
goto
_exit
;
}
_exit:
return
code
;
*
pBlock
=
(
SBlock
){.
minKey
=
TSDBKEY_MAX
,
.
maxKey
=
TSDBKEY_MIN
,
.
minVersion
=
VERSION_MAX
,
.
maxVersion
=
VERSION_MIN
};
}
int32_t
tPutBlock
(
uint8_t
*
p
,
void
*
ph
)
{
...
...
@@ -441,13 +299,15 @@ int32_t tPutBlock(uint8_t *p, void *ph) {
n
+=
tPutI8
(
p
?
p
+
n
:
p
,
pBlock
->
hasDup
);
n
+=
tPutI8
(
p
?
p
+
n
:
p
,
pBlock
->
nSubBlock
);
for
(
int8_t
iSubBlock
=
0
;
iSubBlock
<
pBlock
->
nSubBlock
;
iSubBlock
++
)
{
n
+=
tPutI
64
v
(
p
?
p
+
n
:
p
,
pBlock
->
aSubBlock
[
iSubBlock
].
nRow
);
n
+=
tPutI
32
v
(
p
?
p
+
n
:
p
,
pBlock
->
aSubBlock
[
iSubBlock
].
nRow
);
n
+=
tPutI8
(
p
?
p
+
n
:
p
,
pBlock
->
aSubBlock
[
iSubBlock
].
cmprAlg
);
n
+=
tPutI64v
(
p
?
p
+
n
:
p
,
pBlock
->
aSubBlock
[
iSubBlock
].
offset
);
n
+=
tPutI64v
(
p
?
p
+
n
:
p
,
pBlock
->
aSubBlock
[
iSubBlock
].
szVersion
);
n
+=
tPutI64v
(
p
?
p
+
n
:
p
,
pBlock
->
aSubBlock
[
iSubBlock
].
szTSKEY
);
n
+=
tPutI64v
(
p
?
p
+
n
:
p
,
pBlock
->
aSubBlock
[
iSubBlock
].
szBlock
);
n
+=
tPutMapData
(
p
?
p
+
n
:
p
,
&
pBlock
->
aSubBlock
[
iSubBlock
].
mBlockCol
);
n
+=
tPutI32v
(
p
?
p
+
n
:
p
,
pBlock
->
aSubBlock
[
iSubBlock
].
szBlockCol
);
n
+=
tPutI32v
(
p
?
p
+
n
:
p
,
pBlock
->
aSubBlock
[
iSubBlock
].
szVersion
);
n
+=
tPutI32v
(
p
?
p
+
n
:
p
,
pBlock
->
aSubBlock
[
iSubBlock
].
szTSKEY
);
n
+=
tPutI32v
(
p
?
p
+
n
:
p
,
pBlock
->
aSubBlock
[
iSubBlock
].
szBlock
);
n
+=
tPutI64v
(
p
?
p
+
n
:
p
,
pBlock
->
aSubBlock
[
iSubBlock
].
sOffset
);
n
+=
tPutI32v
(
p
?
p
+
n
:
p
,
pBlock
->
aSubBlock
[
iSubBlock
].
nSma
);
}
return
n
;
...
...
@@ -466,20 +326,21 @@ int32_t tGetBlock(uint8_t *p, void *ph) {
n
+=
tGetI8
(
p
+
n
,
&
pBlock
->
hasDup
);
n
+=
tGetI8
(
p
+
n
,
&
pBlock
->
nSubBlock
);
for
(
int8_t
iSubBlock
=
0
;
iSubBlock
<
pBlock
->
nSubBlock
;
iSubBlock
++
)
{
n
+=
tGetI
64
v
(
p
+
n
,
&
pBlock
->
aSubBlock
[
iSubBlock
].
nRow
);
n
+=
tGetI
32
v
(
p
+
n
,
&
pBlock
->
aSubBlock
[
iSubBlock
].
nRow
);
n
+=
tGetI8
(
p
+
n
,
&
pBlock
->
aSubBlock
[
iSubBlock
].
cmprAlg
);
n
+=
tGetI64v
(
p
+
n
,
&
pBlock
->
aSubBlock
[
iSubBlock
].
offset
);
n
+=
tGetI64v
(
p
+
n
,
&
pBlock
->
aSubBlock
[
iSubBlock
].
szVersion
);
n
+=
tGetI64v
(
p
+
n
,
&
pBlock
->
aSubBlock
[
iSubBlock
].
szTSKEY
);
n
+=
tGetI64v
(
p
+
n
,
&
pBlock
->
aSubBlock
[
iSubBlock
].
szBlock
);
n
+=
tGetMapData
(
p
+
n
,
&
pBlock
->
aSubBlock
[
iSubBlock
].
mBlockCol
);
n
+=
tGetI32v
(
p
+
n
,
&
pBlock
->
aSubBlock
[
iSubBlock
].
szBlockCol
);
n
+=
tGetI32v
(
p
+
n
,
&
pBlock
->
aSubBlock
[
iSubBlock
].
szVersion
);
n
+=
tGetI32v
(
p
+
n
,
&
pBlock
->
aSubBlock
[
iSubBlock
].
szTSKEY
);
n
+=
tGetI32v
(
p
+
n
,
&
pBlock
->
aSubBlock
[
iSubBlock
].
szBlock
);
n
+=
tGetI64v
(
p
+
n
,
&
pBlock
->
aSubBlock
[
iSubBlock
].
sOffset
);
n
+=
tGetI32v
(
p
+
n
,
&
pBlock
->
aSubBlock
[
iSubBlock
].
nSma
);
}
return
n
;
}
int32_t
tBlockCmprFn
(
const
void
*
p1
,
const
void
*
p2
)
{
int32_t
c
;
SBlock
*
pBlock1
=
(
SBlock
*
)
p1
;
SBlock
*
pBlock2
=
(
SBlock
*
)
p2
;
...
...
@@ -504,14 +365,11 @@ int32_t tPutBlockCol(uint8_t *p, void *ph) {
n
+=
tPutI8
(
p
?
p
+
n
:
p
,
pBlockCol
->
flag
);
if
(
pBlockCol
->
flag
!=
HAS_NULL
)
{
n
+=
tPutI64v
(
p
?
p
+
n
:
p
,
pBlockCol
->
offset
);
if
(
pBlockCol
->
flag
!=
HAS_VALUE
)
{
n
+=
tPutI64v
(
p
?
p
+
n
:
p
,
pBlockCol
->
bsize
);
}
n
+=
tPutI64v
(
p
?
p
+
n
:
p
,
pBlockCol
->
csize
);
if
(
IS_VAR_DATA_TYPE
(
pBlockCol
->
type
))
{
n
+=
tPutI64v
(
p
?
p
+
n
:
p
,
pBlockCol
->
osize
);
}
n
+=
tPutI32v
(
p
?
p
+
n
:
p
,
pBlockCol
->
offset
);
n
+=
tPutI32v
(
p
?
p
+
n
:
p
,
pBlockCol
->
szBitmap
);
n
+=
tPutI32v
(
p
?
p
+
n
:
p
,
pBlockCol
->
szOffset
);
n
+=
tPutI32v
(
p
?
p
+
n
:
p
,
pBlockCol
->
szValue
);
n
+=
tPutI32v
(
p
?
p
+
n
:
p
,
pBlockCol
->
szOrigin
);
}
return
n
;
...
...
@@ -528,18 +386,11 @@ int32_t tGetBlockCol(uint8_t *p, void *ph) {
ASSERT
(
pBlockCol
->
flag
&&
(
pBlockCol
->
flag
!=
HAS_NONE
));
if
(
pBlockCol
->
flag
!=
HAS_NULL
)
{
n
+=
tGetI64v
(
p
+
n
,
&
pBlockCol
->
offset
);
if
(
pBlockCol
->
flag
!=
HAS_VALUE
)
{
n
+=
tGetI64v
(
p
+
n
,
&
pBlockCol
->
bsize
);
}
else
{
pBlockCol
->
bsize
=
0
;
}
n
+=
tGetI64v
(
p
+
n
,
&
pBlockCol
->
csize
);
if
(
IS_VAR_DATA_TYPE
(
pBlockCol
->
type
))
{
n
+=
tGetI64v
(
p
+
n
,
&
pBlockCol
->
osize
);
}
else
{
pBlockCol
->
osize
=
-
1
;
}
n
+=
tGetI32v
(
p
+
n
,
&
pBlockCol
->
offset
);
n
+=
tGetI32v
(
p
+
n
,
&
pBlockCol
->
szBitmap
);
n
+=
tGetI32v
(
p
+
n
,
&
pBlockCol
->
szOffset
);
n
+=
tGetI32v
(
p
+
n
,
&
pBlockCol
->
szValue
);
n
+=
tGetI32v
(
p
+
n
,
&
pBlockCol
->
szOrigin
);
}
return
n
;
...
...
@@ -942,12 +793,12 @@ int32_t tGetKEYINFO(uint8_t *p, KEYINFO *pKeyInfo) {
}
// SColData ========================================
void
tColDataReset
(
SColData
*
pColData
,
int16_t
cid
,
int8_t
type
)
{
void
tColDataReset
(
SColData
*
pColData
,
int16_t
cid
,
int8_t
type
,
int8_t
smaOn
)
{
pColData
->
cid
=
cid
;
pColData
->
type
=
type
;
pColData
->
smaOn
=
smaOn
;
pColData
->
nVal
=
0
;
pColData
->
flag
=
0
;
pColData
->
offsetValid
=
0
;
pColData
->
nData
=
0
;
}
...
...
@@ -977,26 +828,35 @@ int32_t tColDataAppendValue(SColData *pColData, SColVal *pColVal) {
if
(
pColVal
->
isNone
)
{
pColData
->
flag
|=
HAS_NONE
;
SET_BIT2
(
pColData
->
pBitMap
,
pColData
->
nVal
,
0
);
if
(
IS_VAR_DATA_TYPE
(
pColData
->
type
))
pValue
=
NULL
;
}
else
if
(
pColVal
->
isNull
)
{
pColData
->
flag
|=
HAS_NULL
;
SET_BIT2
(
pColData
->
pBitMap
,
pColData
->
nVal
,
1
);
if
(
IS_VAR_DATA_TYPE
(
pColData
->
type
))
pValue
=
NULL
;
}
else
{
pColData
->
flag
|=
HAS_VALUE
;
SET_BIT2
(
pColData
->
pBitMap
,
pColData
->
nVal
,
2
);
pValue
=
&
pColVal
->
value
;
}
if
(
pValue
)
{
code
=
tsdbRealloc
(
&
pColData
->
pData
,
pColData
->
nData
+
tPutValue
(
NULL
,
&
pColVal
->
value
,
pColVal
->
type
));
if
(
IS_VAR_DATA_TYPE
(
pColData
->
type
))
{
// offset
code
=
tsdbRealloc
((
uint8_t
**
)
&
pColData
->
aOffset
,
sizeof
(
int32_t
)
*
(
pColData
->
nVal
+
1
));
if
(
code
)
goto
_exit
;
pColData
->
aOffset
[
pColData
->
nVal
]
=
pColData
->
nData
;
pColData
->
nData
+=
tPutValue
(
pColData
->
pData
+
pColData
->
nData
,
&
pColVal
->
value
,
pColVal
->
type
);
// value
if
((
!
pColVal
->
isNone
)
&&
(
!
pColVal
->
isNull
))
{
code
=
tsdbRealloc
(
&
pColData
->
pData
,
pColData
->
nData
+
pColVal
->
value
.
nData
);
if
(
code
)
goto
_exit
;
memcpy
(
pColData
->
pData
+
pColData
->
nData
,
pColVal
->
value
.
pData
,
pColVal
->
value
.
nData
);
pColData
->
nData
+=
pColVal
->
value
.
nData
;
}
}
else
{
code
=
tsdbRealloc
(
&
pColData
->
pData
,
pColData
->
nData
+
tPutValue
(
NULL
,
pValue
,
pColVal
->
type
));
if
(
code
)
goto
_exit
;
pColData
->
nData
+=
tPutValue
(
pColData
->
pData
+
pColData
->
nData
,
pValue
,
pColVal
->
type
);
}
pColData
->
nVal
++
;
pColData
->
offsetValid
=
0
;
_exit:
return
code
;
...
...
@@ -1004,57 +864,33 @@ _exit:
int32_t
tColDataCopy
(
SColData
*
pColDataSrc
,
SColData
*
pColDataDest
)
{
int32_t
code
=
0
;
int32_t
size
;
pColDataDest
->
cid
=
pColData
Dest
->
cid
;
pColDataDest
->
type
=
pColData
Dest
->
type
;
pColDataDest
->
offsetValid
=
0
;
pColDataDest
->
cid
=
pColData
Src
->
cid
;
pColDataDest
->
type
=
pColData
Src
->
type
;
pColDataDest
->
smaOn
=
pColDataSrc
->
smaOn
;
pColDataDest
->
nVal
=
pColDataSrc
->
nVal
;
pColDataDest
->
flag
=
pColDataSrc
->
flag
;
if
(
pColDataSrc
->
flag
!=
HAS_NONE
&&
pColDataSrc
->
flag
!=
HAS_NULL
&&
pColDataSrc
->
flag
!=
HAS_VALUE
)
{
code
=
tsdbRealloc
(
&
pColDataDest
->
pBitMap
,
BIT2_SIZE
(
pColDataDest
->
nVal
));
if
(
code
)
goto
_exit
;
memcpy
(
pColDataDest
->
pBitMap
,
pColDataSrc
->
pBitMap
,
BIT2_SIZE
(
pColDataSrc
->
nVal
));
}
pColDataDest
->
nData
=
pColDataSrc
->
nData
;
code
=
tsdbRealloc
(
&
pColDataDest
->
pData
,
pColDataSrc
->
nData
);
size
=
BIT2_SIZE
(
pColDataSrc
->
nVal
);
code
=
tsdbRealloc
(
&
pColDataDest
->
pBitMap
,
size
);
if
(
code
)
goto
_exit
;
memcpy
(
pColDataDest
->
p
Data
,
pColDataSrc
->
pData
,
pColDataSrc
->
nData
);
memcpy
(
pColDataDest
->
p
BitMap
,
pColDataSrc
->
pBitMap
,
size
);
_exit:
return
code
;
}
if
(
IS_VAR_DATA_TYPE
(
pColDataDest
->
type
))
{
size
=
sizeof
(
int32_t
)
*
pColDataSrc
->
nVal
;
static
int32_t
tColDataUpdateOffset
(
SColData
*
pColData
)
{
int32_t
code
=
0
;
SValue
value
;
ASSERT
(
pColData
->
nVal
>
0
);
ASSERT
(
pColData
->
flag
);
ASSERT
(
IS_VAR_DATA_TYPE
(
pColData
->
type
));
if
((
pColData
->
flag
&
HAS_VALUE
))
{
code
=
tsdbRealloc
((
uint8_t
**
)
&
pColData
->
aOffset
,
sizeof
(
int32_t
)
*
pColData
->
nVal
);
code
=
tsdbRealloc
((
uint8_t
**
)
&
pColDataDest
->
aOffset
,
size
);
if
(
code
)
goto
_exit
;
int32_t
offset
=
0
;
for
(
int32_t
iVal
=
0
;
iVal
<
pColData
->
nVal
;
iVal
++
)
{
if
(
pColData
->
flag
!=
HAS_VALUE
)
{
uint8_t
v
=
GET_BIT2
(
pColData
->
pBitMap
,
iVal
);
if
(
v
==
0
||
v
==
1
)
{
pColData
->
aOffset
[
iVal
]
=
-
1
;
continue
;
}
}
pColData
->
aOffset
[
iVal
]
=
offset
;
offset
+=
tGetValue
(
pColData
->
pData
+
offset
,
&
value
,
pColData
->
type
);
}
ASSERT
(
offset
==
pColData
->
nData
);
pColData
->
offsetValid
=
1
;
memcpy
(
pColDataDest
->
aOffset
,
pColDataSrc
->
aOffset
,
size
);
}
code
=
tsdbRealloc
(
&
pColDataDest
->
pData
,
pColDataSrc
->
nData
);
if
(
code
)
goto
_exit
;
pColDataDest
->
nData
=
pColDataSrc
->
nData
;
memcpy
(
pColDataDest
->
pData
,
pColDataSrc
->
pData
,
pColDataDest
->
nData
);
_exit:
return
code
;
}
...
...
@@ -1085,11 +921,13 @@ int32_t tColDataGetValue(SColData *pColData, int32_t iVal, SColVal *pColVal) {
// get value
SValue
value
;
if
(
IS_VAR_DATA_TYPE
(
pColData
->
type
))
{
if
(
!
pColData
->
offsetValid
)
{
code
=
tColDataUpdateOffset
(
pColData
);
if
(
code
)
goto
_exit
;
if
(
iVal
+
1
<
pColData
->
nVal
)
{
value
.
nData
=
pColData
->
aOffset
[
iVal
+
1
]
-
pColData
->
aOffset
[
iVal
];
}
else
{
value
.
nData
=
pColData
->
nData
-
pColData
->
aOffset
[
iVal
];
}
tGetValue
(
pColData
->
pData
+
pColData
->
aOffset
[
iVal
],
&
value
,
pColData
->
type
);
value
.
pData
=
pColData
->
pData
+
pColData
->
aOffset
[
iVal
];
}
else
{
tGetValue
(
pColData
->
pData
+
tDataTypes
[
pColData
->
type
].
bytes
*
iVal
,
&
value
,
pColData
->
type
);
}
...
...
@@ -1210,7 +1048,7 @@ int32_t tBlockDataAppendRow(SBlockData *pBlockData, TSDBROW *pRow, STSchema *pTS
if
(
code
)
goto
_err
;
// append a NONE
tColDataReset
(
pColData
,
pColVal
->
cid
,
pColVal
->
type
);
tColDataReset
(
pColData
,
pColVal
->
cid
,
pColVal
->
type
,
0
);
for
(
int32_t
iRow
=
0
;
iRow
<
pBlockData
->
nRow
;
iRow
++
)
{
code
=
tColDataAppendValue
(
pColData
,
&
COL_VAL_NONE
(
pColVal
->
cid
,
pColVal
->
type
));
if
(
code
)
goto
_err
;
...
...
@@ -1240,7 +1078,7 @@ int32_t tBlockDataAppendRow(SBlockData *pBlockData, TSDBROW *pRow, STSchema *pTS
code
=
tBlockDataAddColData
(
pBlockData
,
iColData
,
&
pColData
);
if
(
code
)
goto
_err
;
tColDataReset
(
pColData
,
pColVal
->
cid
,
pColVal
->
type
);
tColDataReset
(
pColData
,
pColVal
->
cid
,
pColVal
->
type
,
0
);
for
(
int32_t
iRow
=
0
;
iRow
<
pBlockData
->
nRow
;
iRow
++
)
{
code
=
tColDataAppendValue
(
pColData
,
&
COL_VAL_NONE
(
pColVal
->
cid
,
pColVal
->
type
));
if
(
code
)
goto
_err
;
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录