Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
ff4fda84
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看板
提交
ff4fda84
编写于
9月 02, 2022
作者:
H
Hongze Cheng
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
refact code
上级
7d23c830
变更
9
隐藏空白更改
内联
并排
Showing
9 changed file
with
201 addition
and
201 deletion
+201
-201
source/dnode/vnode/src/inc/tsdb.h
source/dnode/vnode/src/inc/tsdb.h
+8
-8
source/dnode/vnode/src/tsdb/tsdbCommit.c
source/dnode/vnode/src/tsdb/tsdbCommit.c
+37
-37
source/dnode/vnode/src/tsdb/tsdbFS.c
source/dnode/vnode/src/tsdb/tsdbFS.c
+31
-31
source/dnode/vnode/src/tsdb/tsdbFile.c
source/dnode/vnode/src/tsdb/tsdbFile.c
+7
-7
source/dnode/vnode/src/tsdb/tsdbMergeTree.c
source/dnode/vnode/src/tsdb/tsdbMergeTree.c
+30
-30
source/dnode/vnode/src/tsdb/tsdbRead.c
source/dnode/vnode/src/tsdb/tsdbRead.c
+3
-3
source/dnode/vnode/src/tsdb/tsdbReaderWriter.c
source/dnode/vnode/src/tsdb/tsdbReaderWriter.c
+29
-29
source/dnode/vnode/src/tsdb/tsdbSnapshot.c
source/dnode/vnode/src/tsdb/tsdbSnapshot.c
+26
-26
source/dnode/vnode/src/tsdb/tsdbUtil.c
source/dnode/vnode/src/tsdb/tsdbUtil.c
+30
-30
未找到文件。
source/dnode/vnode/src/inc/tsdb.h
浏览文件 @
ff4fda84
...
...
@@ -43,7 +43,7 @@ typedef struct STbDataIter STbDataIter;
typedef
struct
SMapData
SMapData
;
typedef
struct
SBlockIdx
SBlockIdx
;
typedef
struct
SBlock
SBlock
;
typedef
struct
S
BlockL
SBlockL
;
typedef
struct
S
SstBlk
SSstBlk
;
typedef
struct
SColData
SColData
;
typedef
struct
SDiskDataHdr
SDiskDataHdr
;
typedef
struct
SBlockData
SBlockData
;
...
...
@@ -120,9 +120,9 @@ 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
);
bool
tBlockHasSma
(
SBlock
*
pBlock
);
// S
BlockL
int32_t
tPut
BlockL
(
uint8_t
*
p
,
void
*
ph
);
int32_t
tGet
BlockL
(
uint8_t
*
p
,
void
*
ph
);
// S
SstBlk
int32_t
tPut
SstBlk
(
uint8_t
*
p
,
void
*
ph
);
int32_t
tGet
SstBlk
(
uint8_t
*
p
,
void
*
ph
);
// SBlockIdx
int32_t
tPutBlockIdx
(
uint8_t
*
p
,
void
*
ph
);
int32_t
tGetBlockIdx
(
uint8_t
*
p
,
void
*
ph
);
...
...
@@ -254,7 +254,7 @@ int32_t tsdbDataFWriterClose(SDataFWriter **ppWriter, int8_t sync);
int32_t
tsdbUpdateDFileSetHeader
(
SDataFWriter
*
pWriter
);
int32_t
tsdbWriteBlockIdx
(
SDataFWriter
*
pWriter
,
SArray
*
aBlockIdx
);
int32_t
tsdbWriteBlock
(
SDataFWriter
*
pWriter
,
SMapData
*
pMapData
,
SBlockIdx
*
pBlockIdx
);
int32_t
tsdbWrite
BlockL
(
SDataFWriter
*
pWriter
,
SArray
*
aBlockL
);
int32_t
tsdbWrite
SstBlk
(
SDataFWriter
*
pWriter
,
SArray
*
aSstBlk
);
int32_t
tsdbWriteBlockData
(
SDataFWriter
*
pWriter
,
SBlockData
*
pBlockData
,
SBlockInfo
*
pBlkInfo
,
SSmaInfo
*
pSmaInfo
,
int8_t
cmprAlg
,
int8_t
toLast
);
...
...
@@ -264,10 +264,10 @@ int32_t tsdbDataFReaderOpen(SDataFReader **ppReader, STsdb *pTsdb, SDFileSet *pS
int32_t
tsdbDataFReaderClose
(
SDataFReader
**
ppReader
);
int32_t
tsdbReadBlockIdx
(
SDataFReader
*
pReader
,
SArray
*
aBlockIdx
);
int32_t
tsdbReadBlock
(
SDataFReader
*
pReader
,
SBlockIdx
*
pBlockIdx
,
SMapData
*
pMapData
);
int32_t
tsdbRead
BlockL
(
SDataFReader
*
pReader
,
int32_t
iLast
,
SArray
*
aBlockL
);
int32_t
tsdbRead
SstBlk
(
SDataFReader
*
pReader
,
int32_t
iSst
,
SArray
*
aSstBlk
);
int32_t
tsdbReadBlockSma
(
SDataFReader
*
pReader
,
SBlock
*
pBlock
,
SArray
*
aColumnDataAgg
);
int32_t
tsdbReadDataBlock
(
SDataFReader
*
pReader
,
SBlock
*
pBlock
,
SBlockData
*
pBlockData
);
int32_t
tsdbRead
LastBlock
(
SDataFReader
*
pReader
,
int32_t
iLast
,
SBlockL
*
pBlockL
,
SBlockData
*
pBlockData
);
int32_t
tsdbRead
SstBlock
(
SDataFReader
*
pReader
,
int32_t
iSst
,
SSstBlk
*
pSstBlk
,
SBlockData
*
pBlockData
);
// SDelFWriter
int32_t
tsdbDelFWriterOpen
(
SDelFWriter
**
ppWriter
,
SDelFile
*
pFile
,
STsdb
*
pTsdb
);
int32_t
tsdbDelFWriterClose
(
SDelFWriter
**
ppWriter
,
int8_t
sync
);
...
...
@@ -439,7 +439,7 @@ struct SBlock {
SSmaInfo
smaInfo
;
};
struct
S
BlockL
{
struct
S
SstBlk
{
int64_t
suid
;
int64_t
minUid
;
int64_t
maxUid
;
...
...
source/dnode/vnode/src/tsdb/tsdbCommit.c
浏览文件 @
ff4fda84
...
...
@@ -32,9 +32,9 @@ typedef struct {
STbDataIter
iter
;
};
// memory data iter
struct
{
int32_t
i
La
st
;
SArray
*
a
BlockL
;
int32_t
i
BlockL
;
int32_t
i
S
st
;
SArray
*
a
SstBlk
;
int32_t
i
SstBlk
;
SBlockData
bData
;
int32_t
iRow
;
};
// sst file data iter
...
...
@@ -77,7 +77,7 @@ typedef struct {
struct
{
SDataFWriter
*
pWriter
;
SArray
*
aBlockIdx
;
// SArray<SBlockIdx>
SArray
*
a
BlockL
;
// SArray<SBlockL
>
SArray
*
a
SstBlk
;
// SArray<SSstBlk
>
SMapData
mBlock
;
// SMapData<SBlock>
SBlockData
bData
;
SBlockData
bDatal
;
...
...
@@ -92,8 +92,8 @@ typedef struct {
SArray
*
aDelData
;
// SArray<SDelData>
}
SCommitter
;
extern
int32_t
tsdbRead
LastBlockEx
(
SDataFReader
*
pReader
,
int32_t
iLast
,
SBlockL
*
pBlockL
,
SBlockData
*
pBlockData
);
// todo
extern
int32_t
tsdbRead
SstBlockEx
(
SDataFReader
*
pReader
,
int32_t
iSst
,
SSstBlk
*
aSstBlk
,
SBlockData
*
pBlockData
);
// todo
static
int32_t
tsdbStartCommit
(
STsdb
*
pTsdb
,
SCommitter
*
pCommitter
);
static
int32_t
tsdbCommitData
(
SCommitter
*
pCommitter
);
...
...
@@ -433,19 +433,19 @@ static int32_t tsdbOpenCommitIter(SCommitter *pCommitter) {
if
(
pReader
)
{
if
(
pReader
->
pSet
->
nSstF
>=
pCommitter
->
maxLast
)
{
int8_t
iIter
=
0
;
for
(
int32_t
i
Last
=
0
;
iLast
<
pReader
->
pSet
->
nSstF
;
iLa
st
++
)
{
for
(
int32_t
i
Sst
=
0
;
iSst
<
pReader
->
pSet
->
nSstF
;
iS
st
++
)
{
pIter
=
&
pCommitter
->
aDataIter
[
iIter
];
pIter
->
type
=
LAST_DATA_ITER
;
pIter
->
i
Last
=
iLa
st
;
pIter
->
i
Sst
=
iS
st
;
code
=
tsdbRead
BlockL
(
pCommitter
->
dReader
.
pReader
,
iLast
,
pIter
->
aBlockL
);
code
=
tsdbRead
SstBlk
(
pCommitter
->
dReader
.
pReader
,
iSst
,
pIter
->
aSstBlk
);
if
(
code
)
goto
_err
;
if
(
taosArrayGetSize
(
pIter
->
a
BlockL
)
==
0
)
continue
;
if
(
taosArrayGetSize
(
pIter
->
a
SstBlk
)
==
0
)
continue
;
pIter
->
i
BlockL
=
0
;
S
BlockL
*
pBlockL
=
(
SBlockL
*
)
taosArrayGet
(
pIter
->
aBlockL
,
0
);
code
=
tsdbRead
LastBlockEx
(
pCommitter
->
dReader
.
pReader
,
iLast
,
pBlockL
,
&
pIter
->
bData
);
pIter
->
i
SstBlk
=
0
;
S
SstBlk
*
pSstBlk
=
(
SSstBlk
*
)
taosArrayGet
(
pIter
->
aSstBlk
,
0
);
code
=
tsdbRead
SstBlockEx
(
pCommitter
->
dReader
.
pReader
,
iSst
,
pSstBlk
,
&
pIter
->
bData
);
if
(
code
)
goto
_err
;
pIter
->
iRow
=
0
;
...
...
@@ -457,8 +457,8 @@ static int32_t tsdbOpenCommitIter(SCommitter *pCommitter) {
iIter
++
;
}
}
else
{
for
(
int32_t
i
Last
=
0
;
iLast
<
pReader
->
pSet
->
nSstF
;
iLa
st
++
)
{
SSstFile
*
pSstFile
=
pReader
->
pSet
->
aSstF
[
i
La
st
];
for
(
int32_t
i
Sst
=
0
;
iSst
<
pReader
->
pSet
->
nSstF
;
iS
st
++
)
{
SSstFile
*
pSstFile
=
pReader
->
pSet
->
aSstF
[
i
S
st
];
if
(
pSstFile
->
size
>
pSstFile
->
offset
)
{
pCommitter
->
toLastOnly
=
1
;
break
;
...
...
@@ -523,8 +523,8 @@ static int32_t tsdbCommitFileDataStart(SCommitter *pCommitter) {
fSma
=
*
pRSet
->
pSmaF
;
wSet
.
diskId
=
pRSet
->
diskId
;
if
(
pRSet
->
nSstF
<
pCommitter
->
maxLast
)
{
for
(
int32_t
i
Last
=
0
;
iLast
<
pRSet
->
nSstF
;
iLa
st
++
)
{
wSet
.
aSstF
[
i
Last
]
=
pRSet
->
aSstF
[
iLa
st
];
for
(
int32_t
i
Sst
=
0
;
iSst
<
pRSet
->
nSstF
;
iS
st
++
)
{
wSet
.
aSstF
[
i
Sst
]
=
pRSet
->
aSstF
[
iS
st
];
}
wSet
.
nSstF
=
pRSet
->
nSstF
+
1
;
}
else
{
...
...
@@ -542,7 +542,7 @@ static int32_t tsdbCommitFileDataStart(SCommitter *pCommitter) {
if
(
code
)
goto
_err
;
taosArrayClear
(
pCommitter
->
dWriter
.
aBlockIdx
);
taosArrayClear
(
pCommitter
->
dWriter
.
a
BlockL
);
taosArrayClear
(
pCommitter
->
dWriter
.
a
SstBlk
);
tMapDataReset
(
&
pCommitter
->
dWriter
.
mBlock
);
tBlockDataReset
(
&
pCommitter
->
dWriter
.
bData
);
tBlockDataReset
(
&
pCommitter
->
dWriter
.
bDatal
);
...
...
@@ -613,7 +613,7 @@ _err:
static
int32_t
tsdbCommitLastBlock
(
SCommitter
*
pCommitter
)
{
int32_t
code
=
0
;
S
BlockL
blockL
;
S
SstBlk
blockL
;
SBlockData
*
pBlockData
=
&
pCommitter
->
dWriter
.
bDatal
;
ASSERT
(
pBlockData
->
nRow
>
0
);
...
...
@@ -638,8 +638,8 @@ static int32_t tsdbCommitLastBlock(SCommitter *pCommitter) {
code
=
tsdbWriteBlockData
(
pCommitter
->
dWriter
.
pWriter
,
pBlockData
,
&
blockL
.
bInfo
,
NULL
,
pCommitter
->
cmprAlg
,
1
);
if
(
code
)
goto
_err
;
// push S
BlockL
if
(
taosArrayPush
(
pCommitter
->
dWriter
.
a
BlockL
,
&
blockL
)
==
NULL
)
{
// push S
SstBlk
if
(
taosArrayPush
(
pCommitter
->
dWriter
.
a
SstBlk
,
&
blockL
)
==
NULL
)
{
code
=
TSDB_CODE_OUT_OF_MEMORY
;
goto
_err
;
}
...
...
@@ -661,8 +661,8 @@ static int32_t tsdbCommitFileDataEnd(SCommitter *pCommitter) {
code
=
tsdbWriteBlockIdx
(
pCommitter
->
dWriter
.
pWriter
,
pCommitter
->
dWriter
.
aBlockIdx
);
if
(
code
)
goto
_err
;
// write a
BlockL
code
=
tsdbWrite
BlockL
(
pCommitter
->
dWriter
.
pWriter
,
pCommitter
->
dWriter
.
aBlockL
);
// write a
SstBlk
code
=
tsdbWrite
SstBlk
(
pCommitter
->
dWriter
.
pWriter
,
pCommitter
->
dWriter
.
aSstBlk
);
if
(
code
)
goto
_err
;
// update file header
...
...
@@ -790,10 +790,10 @@ static int32_t tsdbCommitDataStart(SCommitter *pCommitter) {
if
(
code
)
goto
_exit
;
// merger
for
(
int32_t
i
Last
=
0
;
iLast
<
TSDB_MAX_LAST_FILE
;
iLa
st
++
)
{
SDataIter
*
pIter
=
&
pCommitter
->
aDataIter
[
i
La
st
];
pIter
->
a
BlockL
=
taosArrayInit
(
0
,
sizeof
(
SBlockL
));
if
(
pIter
->
a
BlockL
==
NULL
)
{
for
(
int32_t
i
Sst
=
0
;
iSst
<
TSDB_MAX_LAST_FILE
;
iS
st
++
)
{
SDataIter
*
pIter
=
&
pCommitter
->
aDataIter
[
i
S
st
];
pIter
->
a
SstBlk
=
taosArrayInit
(
0
,
sizeof
(
SSstBlk
));
if
(
pIter
->
a
SstBlk
==
NULL
)
{
code
=
TSDB_CODE_OUT_OF_MEMORY
;
goto
_exit
;
}
...
...
@@ -809,8 +809,8 @@ static int32_t tsdbCommitDataStart(SCommitter *pCommitter) {
goto
_exit
;
}
pCommitter
->
dWriter
.
a
BlockL
=
taosArrayInit
(
0
,
sizeof
(
SBlockL
));
if
(
pCommitter
->
dWriter
.
a
BlockL
==
NULL
)
{
pCommitter
->
dWriter
.
a
SstBlk
=
taosArrayInit
(
0
,
sizeof
(
SSstBlk
));
if
(
pCommitter
->
dWriter
.
a
SstBlk
==
NULL
)
{
code
=
TSDB_CODE_OUT_OF_MEMORY
;
goto
_exit
;
}
...
...
@@ -832,15 +832,15 @@ static void tsdbCommitDataEnd(SCommitter *pCommitter) {
tBlockDataDestroy
(
&
pCommitter
->
dReader
.
bData
,
1
);
// merger
for
(
int32_t
i
Last
=
0
;
iLast
<
TSDB_MAX_LAST_FILE
;
iLa
st
++
)
{
SDataIter
*
pIter
=
&
pCommitter
->
aDataIter
[
i
La
st
];
taosArrayDestroy
(
pIter
->
a
BlockL
);
for
(
int32_t
i
Sst
=
0
;
iSst
<
TSDB_MAX_LAST_FILE
;
iS
st
++
)
{
SDataIter
*
pIter
=
&
pCommitter
->
aDataIter
[
i
S
st
];
taosArrayDestroy
(
pIter
->
a
SstBlk
);
tBlockDataDestroy
(
&
pIter
->
bData
,
1
);
}
// writer
taosArrayDestroy
(
pCommitter
->
dWriter
.
aBlockIdx
);
taosArrayDestroy
(
pCommitter
->
dWriter
.
a
BlockL
);
taosArrayDestroy
(
pCommitter
->
dWriter
.
a
SstBlk
);
tMapDataClear
(
&
pCommitter
->
dWriter
.
mBlock
);
tBlockDataDestroy
(
&
pCommitter
->
dWriter
.
bData
,
1
);
tBlockDataDestroy
(
&
pCommitter
->
dWriter
.
bDatal
,
1
);
...
...
@@ -1055,11 +1055,11 @@ static int32_t tsdbNextCommitRow(SCommitter *pCommitter) {
pIter
->
r
.
uid
=
pIter
->
bData
.
uid
?
pIter
->
bData
.
uid
:
pIter
->
bData
.
aUid
[
pIter
->
iRow
];
pIter
->
r
.
row
=
tsdbRowFromBlockData
(
&
pIter
->
bData
,
pIter
->
iRow
);
}
else
{
pIter
->
i
BlockL
++
;
if
(
pIter
->
i
BlockL
<
taosArrayGetSize
(
pIter
->
aBlockL
))
{
S
BlockL
*
pBlockL
=
(
SBlockL
*
)
taosArrayGet
(
pIter
->
aBlockL
,
pIter
->
iBlockL
);
pIter
->
i
SstBlk
++
;
if
(
pIter
->
i
SstBlk
<
taosArrayGetSize
(
pIter
->
aSstBlk
))
{
S
SstBlk
*
pSstBlk
=
(
SSstBlk
*
)
taosArrayGet
(
pIter
->
aSstBlk
,
pIter
->
iSstBlk
);
code
=
tsdbRead
LastBlockEx
(
pCommitter
->
dReader
.
pReader
,
pIter
->
iLast
,
pBlockL
,
&
pIter
->
bData
);
code
=
tsdbRead
SstBlockEx
(
pCommitter
->
dReader
.
pReader
,
pIter
->
iSst
,
pSstBlk
,
&
pIter
->
bData
);
if
(
code
)
goto
_exit
;
pIter
->
iRow
=
0
;
...
...
source/dnode/vnode/src/tsdb/tsdbFS.c
浏览文件 @
ff4fda84
...
...
@@ -255,8 +255,8 @@ void tsdbFSDestroy(STsdbFS *pFS) {
taosMemoryFree
(
pSet
->
pHeadF
);
taosMemoryFree
(
pSet
->
pDataF
);
taosMemoryFree
(
pSet
->
pSmaF
);
for
(
int32_t
i
Last
=
0
;
iLast
<
pSet
->
nSstF
;
iLa
st
++
)
{
taosMemoryFree
(
pSet
->
aSstF
[
i
La
st
]);
for
(
int32_t
i
Sst
=
0
;
iSst
<
pSet
->
nSstF
;
iS
st
++
)
{
taosMemoryFree
(
pSet
->
aSstF
[
i
S
st
]);
}
}
...
...
@@ -645,15 +645,15 @@ int32_t tsdbFSUpsertFSet(STsdbFS *pFS, SDFileSet *pSet) {
pDFileSet
->
nSstF
++
;
}
else
if
(
pSet
->
nSstF
<
pDFileSet
->
nSstF
)
{
ASSERT
(
pSet
->
nSstF
==
1
);
for
(
int32_t
i
Last
=
1
;
iLast
<
pDFileSet
->
nSstF
;
iLa
st
++
)
{
taosMemoryFree
(
pDFileSet
->
aSstF
[
i
La
st
]);
for
(
int32_t
i
Sst
=
1
;
iSst
<
pDFileSet
->
nSstF
;
iS
st
++
)
{
taosMemoryFree
(
pDFileSet
->
aSstF
[
i
S
st
]);
}
*
pDFileSet
->
aSstF
[
0
]
=
*
pSet
->
aSstF
[
0
];
pDFileSet
->
nSstF
=
1
;
}
else
{
for
(
int32_t
i
Last
=
0
;
iLast
<
pSet
->
nSstF
;
iLa
st
++
)
{
*
pDFileSet
->
aSstF
[
i
Last
]
=
*
pSet
->
aSstF
[
iLa
st
];
for
(
int32_t
i
Sst
=
0
;
iSst
<
pSet
->
nSstF
;
iS
st
++
)
{
*
pDFileSet
->
aSstF
[
i
Sst
]
=
*
pSet
->
aSstF
[
iS
st
];
}
}
...
...
@@ -876,15 +876,15 @@ int32_t tsdbFSCommit2(STsdb *pTsdb, STsdbFS *pFSNew) {
pSetOld
->
nSstF
++
;
}
else
if
(
pSetNew
->
nSstF
<
pSetOld
->
nSstF
)
{
ASSERT
(
pSetNew
->
nSstF
==
1
);
for
(
int32_t
i
Last
=
0
;
iLast
<
pSetOld
->
nSstF
;
iLa
st
++
)
{
SSstFile
*
pSstFile
=
pSetOld
->
aSstF
[
i
La
st
];
for
(
int32_t
i
Sst
=
0
;
iSst
<
pSetOld
->
nSstF
;
iS
st
++
)
{
SSstFile
*
pSstFile
=
pSetOld
->
aSstF
[
i
S
st
];
nRef
=
atomic_sub_fetch_32
(
&
pSstFile
->
nRef
,
1
);
if
(
nRef
==
0
)
{
tsdbSstFileName
(
pTsdb
,
pSetOld
->
diskId
,
pSetOld
->
fid
,
pSstFile
,
fname
);
taosRemoveFile
(
fname
);
taosMemoryFree
(
pSstFile
);
}
pSetOld
->
aSstF
[
i
La
st
]
=
NULL
;
pSetOld
->
aSstF
[
i
S
st
]
=
NULL
;
}
pSetOld
->
nSstF
=
1
;
...
...
@@ -896,8 +896,8 @@ int32_t tsdbFSCommit2(STsdb *pTsdb, STsdbFS *pFSNew) {
*
pSetOld
->
aSstF
[
0
]
=
*
pSetNew
->
aSstF
[
0
];
pSetOld
->
aSstF
[
0
]
->
nRef
=
1
;
}
else
{
for
(
int32_t
i
Last
=
0
;
iLast
<
pSetOld
->
nSstF
;
iLa
st
++
)
{
SSstFile
*
pSstFile
=
pSetOld
->
aSstF
[
i
La
st
];
for
(
int32_t
i
Sst
=
0
;
iSst
<
pSetOld
->
nSstF
;
iS
st
++
)
{
SSstFile
*
pSstFile
=
pSetOld
->
aSstF
[
i
S
st
];
nRef
=
atomic_sub_fetch_32
(
&
pSstFile
->
nRef
,
1
);
if
(
nRef
==
0
)
{
tsdbSstFileName
(
pTsdb
,
pSetOld
->
diskId
,
pSetOld
->
fid
,
pSstFile
,
fname
);
...
...
@@ -905,19 +905,19 @@ int32_t tsdbFSCommit2(STsdb *pTsdb, STsdbFS *pFSNew) {
taosMemoryFree
(
pSstFile
);
}
pSetOld
->
aSstF
[
i
La
st
]
=
(
SSstFile
*
)
taosMemoryMalloc
(
sizeof
(
SSstFile
));
if
(
pSetOld
->
aSstF
[
i
La
st
]
==
NULL
)
{
pSetOld
->
aSstF
[
i
S
st
]
=
(
SSstFile
*
)
taosMemoryMalloc
(
sizeof
(
SSstFile
));
if
(
pSetOld
->
aSstF
[
i
S
st
]
==
NULL
)
{
code
=
TSDB_CODE_OUT_OF_MEMORY
;
goto
_err
;
}
*
pSetOld
->
aSstF
[
i
Last
]
=
*
pSetNew
->
aSstF
[
iLa
st
];
pSetOld
->
aSstF
[
i
La
st
]
->
nRef
=
1
;
*
pSetOld
->
aSstF
[
i
Sst
]
=
*
pSetNew
->
aSstF
[
iS
st
];
pSetOld
->
aSstF
[
i
S
st
]
->
nRef
=
1
;
}
}
}
else
{
ASSERT
(
pSetOld
->
nSstF
==
pSetNew
->
nSstF
);
for
(
int32_t
i
Last
=
0
;
iLast
<
pSetOld
->
nSstF
;
iLa
st
++
)
{
SSstFile
*
pSstFile
=
pSetOld
->
aSstF
[
i
La
st
];
for
(
int32_t
i
Sst
=
0
;
iSst
<
pSetOld
->
nSstF
;
iS
st
++
)
{
SSstFile
*
pSstFile
=
pSetOld
->
aSstF
[
i
S
st
];
nRef
=
atomic_sub_fetch_32
(
&
pSstFile
->
nRef
,
1
);
if
(
nRef
==
0
)
{
tsdbSstFileName
(
pTsdb
,
pSetOld
->
diskId
,
pSetOld
->
fid
,
pSstFile
,
fname
);
...
...
@@ -925,13 +925,13 @@ int32_t tsdbFSCommit2(STsdb *pTsdb, STsdbFS *pFSNew) {
taosMemoryFree
(
pSstFile
);
}
pSetOld
->
aSstF
[
i
La
st
]
=
(
SSstFile
*
)
taosMemoryMalloc
(
sizeof
(
SSstFile
));
if
(
pSetOld
->
aSstF
[
i
La
st
]
==
NULL
)
{
pSetOld
->
aSstF
[
i
S
st
]
=
(
SSstFile
*
)
taosMemoryMalloc
(
sizeof
(
SSstFile
));
if
(
pSetOld
->
aSstF
[
i
S
st
]
==
NULL
)
{
code
=
TSDB_CODE_OUT_OF_MEMORY
;
goto
_err
;
}
*
pSetOld
->
aSstF
[
i
Last
]
=
*
pSetNew
->
aSstF
[
iLa
st
];
pSetOld
->
aSstF
[
i
La
st
]
->
nRef
=
1
;
*
pSetOld
->
aSstF
[
i
Sst
]
=
*
pSetNew
->
aSstF
[
iS
st
];
pSetOld
->
aSstF
[
i
S
st
]
->
nRef
=
1
;
}
}
...
...
@@ -965,12 +965,12 @@ int32_t tsdbFSCommit2(STsdb *pTsdb, STsdbFS *pFSNew) {
taosMemoryFree
(
pSetOld
->
pSmaF
);
}
for
(
int8_t
i
Last
=
0
;
iLast
<
pSetOld
->
nSstF
;
iLa
st
++
)
{
nRef
=
atomic_sub_fetch_32
(
&
pSetOld
->
aSstF
[
i
La
st
]
->
nRef
,
1
);
for
(
int8_t
i
Sst
=
0
;
iSst
<
pSetOld
->
nSstF
;
iS
st
++
)
{
nRef
=
atomic_sub_fetch_32
(
&
pSetOld
->
aSstF
[
i
S
st
]
->
nRef
,
1
);
if
(
nRef
==
0
)
{
tsdbSstFileName
(
pTsdb
,
pSetOld
->
diskId
,
pSetOld
->
fid
,
pSetOld
->
aSstF
[
i
La
st
],
fname
);
tsdbSstFileName
(
pTsdb
,
pSetOld
->
diskId
,
pSetOld
->
fid
,
pSetOld
->
aSstF
[
i
S
st
],
fname
);
taosRemoveFile
(
fname
);
taosMemoryFree
(
pSetOld
->
aSstF
[
i
La
st
]);
taosMemoryFree
(
pSetOld
->
aSstF
[
i
S
st
]);
}
}
...
...
@@ -1063,8 +1063,8 @@ int32_t tsdbFSRef(STsdb *pTsdb, STsdbFS *pFS) {
nRef
=
atomic_fetch_add_32
(
&
pSet
->
pSmaF
->
nRef
,
1
);
ASSERT
(
nRef
>
0
);
for
(
int32_t
i
Last
=
0
;
iLast
<
pSet
->
nSstF
;
iLa
st
++
)
{
nRef
=
atomic_fetch_add_32
(
&
pSet
->
aSstF
[
i
La
st
]
->
nRef
,
1
);
for
(
int32_t
i
Sst
=
0
;
iSst
<
pSet
->
nSstF
;
iS
st
++
)
{
nRef
=
atomic_fetch_add_32
(
&
pSet
->
aSstF
[
i
S
st
]
->
nRef
,
1
);
ASSERT
(
nRef
>
0
);
}
...
...
@@ -1123,13 +1123,13 @@ void tsdbFSUnref(STsdb *pTsdb, STsdbFS *pFS) {
}
// sst
for
(
int32_t
i
Last
=
0
;
iLast
<
pSet
->
nSstF
;
iLa
st
++
)
{
nRef
=
atomic_sub_fetch_32
(
&
pSet
->
aSstF
[
i
La
st
]
->
nRef
,
1
);
for
(
int32_t
i
Sst
=
0
;
iSst
<
pSet
->
nSstF
;
iS
st
++
)
{
nRef
=
atomic_sub_fetch_32
(
&
pSet
->
aSstF
[
i
S
st
]
->
nRef
,
1
);
ASSERT
(
nRef
>=
0
);
if
(
nRef
==
0
)
{
tsdbSstFileName
(
pTsdb
,
pSet
->
diskId
,
pSet
->
fid
,
pSet
->
aSstF
[
i
La
st
],
fname
);
tsdbSstFileName
(
pTsdb
,
pSet
->
diskId
,
pSet
->
fid
,
pSet
->
aSstF
[
i
S
st
],
fname
);
taosRemoveFile
(
fname
);
taosMemoryFree
(
pSet
->
aSstF
[
i
La
st
]);
taosMemoryFree
(
pSet
->
aSstF
[
i
S
st
]);
/* code */
}
}
...
...
source/dnode/vnode/src/tsdb/tsdbFile.c
浏览文件 @
ff4fda84
...
...
@@ -196,8 +196,8 @@ int32_t tPutDFileSet(uint8_t *p, SDFileSet *pSet) {
// sst
n
+=
tPutU8
(
p
?
p
+
n
:
p
,
pSet
->
nSstF
);
for
(
int32_t
i
Last
=
0
;
iLast
<
pSet
->
nSstF
;
iLa
st
++
)
{
n
+=
tPutSstFile
(
p
?
p
+
n
:
p
,
pSet
->
aSstF
[
i
La
st
]);
for
(
int32_t
i
Sst
=
0
;
iSst
<
pSet
->
nSstF
;
iS
st
++
)
{
n
+=
tPutSstFile
(
p
?
p
+
n
:
p
,
pSet
->
aSstF
[
i
S
st
]);
}
return
n
;
...
...
@@ -236,13 +236,13 @@ int32_t tGetDFileSet(uint8_t *p, SDFileSet *pSet) {
// sst
n
+=
tGetU8
(
p
+
n
,
&
pSet
->
nSstF
);
for
(
int32_t
i
Last
=
0
;
iLast
<
pSet
->
nSstF
;
iLa
st
++
)
{
pSet
->
aSstF
[
i
La
st
]
=
(
SSstFile
*
)
taosMemoryCalloc
(
1
,
sizeof
(
SSstFile
));
if
(
pSet
->
aSstF
[
i
La
st
]
==
NULL
)
{
for
(
int32_t
i
Sst
=
0
;
iSst
<
pSet
->
nSstF
;
iS
st
++
)
{
pSet
->
aSstF
[
i
S
st
]
=
(
SSstFile
*
)
taosMemoryCalloc
(
1
,
sizeof
(
SSstFile
));
if
(
pSet
->
aSstF
[
i
S
st
]
==
NULL
)
{
return
-
1
;
}
pSet
->
aSstF
[
i
La
st
]
->
nRef
=
1
;
n
+=
tGetSstFile
(
p
+
n
,
pSet
->
aSstF
[
i
La
st
]);
pSet
->
aSstF
[
i
S
st
]
->
nRef
=
1
;
n
+=
tGetSstFile
(
p
+
n
,
pSet
->
aSstF
[
i
S
st
]);
}
return
n
;
...
...
source/dnode/vnode/src/tsdb/tsdbMergeTree.c
浏览文件 @
ff4fda84
...
...
@@ -18,12 +18,12 @@
// SLDataIter =================================================
typedef
struct
SLDataIter
{
SRBTreeNode
node
;
S
BlockL
*
pBlockL
;
S
SstBlk
*
pSstBlk
;
SDataFReader
*
pReader
;
int32_t
i
La
st
;
int32_t
i
S
st
;
int8_t
backward
;
SArray
*
a
BlockL
;
int32_t
i
BlockL
;
SArray
*
a
SstBlk
;
int32_t
i
SstBlk
;
SBlockData
bData
;
int32_t
iRow
;
SRowInfo
rInfo
;
...
...
@@ -32,7 +32,7 @@ typedef struct SLDataIter {
SVersionRange
verRange
;
}
SLDataIter
;
int32_t
tLDataIterOpen
(
struct
SLDataIter
**
pIter
,
SDataFReader
*
pReader
,
int32_t
i
La
st
,
int8_t
backward
,
uint64_t
uid
,
int32_t
tLDataIterOpen
(
struct
SLDataIter
**
pIter
,
SDataFReader
*
pReader
,
int32_t
i
S
st
,
int8_t
backward
,
uint64_t
uid
,
STimeWindow
*
pTimeWindow
,
SVersionRange
*
pRange
)
{
int32_t
code
=
0
;
*
pIter
=
taosMemoryCalloc
(
1
,
sizeof
(
SLDataIter
));
...
...
@@ -41,10 +41,10 @@ int32_t tLDataIterOpen(struct SLDataIter **pIter, SDataFReader *pReader, int32_t
(
*
pIter
)
->
timeWindow
=
*
pTimeWindow
;
(
*
pIter
)
->
verRange
=
*
pRange
;
(
*
pIter
)
->
pReader
=
pReader
;
(
*
pIter
)
->
i
Last
=
iLa
st
;
(
*
pIter
)
->
i
Sst
=
iS
st
;
(
*
pIter
)
->
backward
=
backward
;
(
*
pIter
)
->
a
BlockL
=
taosArrayInit
(
0
,
sizeof
(
SBlockL
));
if
((
*
pIter
)
->
a
BlockL
==
NULL
)
{
(
*
pIter
)
->
a
SstBlk
=
taosArrayInit
(
0
,
sizeof
(
SSstBlk
));
if
((
*
pIter
)
->
a
SstBlk
==
NULL
)
{
code
=
TSDB_CODE_OUT_OF_MEMORY
;
goto
_exit
;
}
...
...
@@ -54,18 +54,18 @@ int32_t tLDataIterOpen(struct SLDataIter **pIter, SDataFReader *pReader, int32_t
goto
_exit
;
}
code
=
tsdbRead
BlockL
(
pReader
,
iLast
,
(
*
pIter
)
->
aBlockL
);
code
=
tsdbRead
SstBlk
(
pReader
,
iSst
,
(
*
pIter
)
->
aSstBlk
);
if
(
code
)
{
goto
_exit
;
}
size_t
size
=
taosArrayGetSize
((
*
pIter
)
->
a
BlockL
);
size_t
size
=
taosArrayGetSize
((
*
pIter
)
->
a
SstBlk
);
// find the start block
int32_t
index
=
-
1
;
if
(
!
backward
)
{
// asc
for
(
int32_t
i
=
0
;
i
<
size
;
++
i
)
{
S
BlockL
*
p
=
taosArrayGet
((
*
pIter
)
->
aBlockL
,
i
);
S
SstBlk
*
p
=
taosArrayGet
((
*
pIter
)
->
aSstBlk
,
i
);
if
(
p
->
minUid
<=
uid
&&
p
->
maxUid
>=
uid
)
{
index
=
i
;
break
;
...
...
@@ -73,7 +73,7 @@ int32_t tLDataIterOpen(struct SLDataIter **pIter, SDataFReader *pReader, int32_t
}
}
else
{
// desc
for
(
int32_t
i
=
size
-
1
;
i
>=
0
;
--
i
)
{
S
BlockL
*
p
=
taosArrayGet
((
*
pIter
)
->
aBlockL
,
i
);
S
SstBlk
*
p
=
taosArrayGet
((
*
pIter
)
->
aSstBlk
,
i
);
if
(
p
->
minUid
<=
uid
&&
p
->
maxUid
>=
uid
)
{
index
=
i
;
break
;
...
...
@@ -81,9 +81,9 @@ int32_t tLDataIterOpen(struct SLDataIter **pIter, SDataFReader *pReader, int32_t
}
}
(
*
pIter
)
->
i
BlockL
=
index
;
(
*
pIter
)
->
i
SstBlk
=
index
;
if
(
index
!=
-
1
)
{
(
*
pIter
)
->
p
BlockL
=
taosArrayGet
((
*
pIter
)
->
aBlockL
,
(
*
pIter
)
->
iBlockL
);
(
*
pIter
)
->
p
SstBlk
=
taosArrayGet
((
*
pIter
)
->
aSstBlk
,
(
*
pIter
)
->
iSstBlk
);
}
_exit:
...
...
@@ -92,20 +92,20 @@ _exit:
void
tLDataIterClose
(
SLDataIter
*
pIter
)
{
tBlockDataDestroy
(
&
pIter
->
bData
,
1
);
taosArrayDestroy
(
pIter
->
a
BlockL
);
taosArrayDestroy
(
pIter
->
a
SstBlk
);
taosMemoryFree
(
pIter
);
}
extern
int32_t
tsdbRead
LastBlockEx
(
SDataFReader
*
pReader
,
int32_t
iLast
,
SBlockL
*
pBlockL
,
SBlockData
*
pBlockData
);
extern
int32_t
tsdbRead
SstBlockEx
(
SDataFReader
*
pReader
,
int32_t
iSst
,
SSstBlk
*
pSstBlk
,
SBlockData
*
pBlockData
);
void
tLDataIterNextBlock
(
SLDataIter
*
pIter
)
{
int32_t
step
=
pIter
->
backward
?
-
1
:
1
;
pIter
->
i
BlockL
+=
step
;
pIter
->
i
SstBlk
+=
step
;
int32_t
index
=
-
1
;
size_t
size
=
taosArrayGetSize
(
pIter
->
a
BlockL
);
for
(
int32_t
i
=
pIter
->
i
BlockL
;
i
<
size
&&
i
>=
0
;
i
+=
step
)
{
S
BlockL
*
p
=
taosArrayGet
(
pIter
->
aBlockL
,
i
);
size_t
size
=
taosArrayGetSize
(
pIter
->
a
SstBlk
);
for
(
int32_t
i
=
pIter
->
i
SstBlk
;
i
<
size
&&
i
>=
0
;
i
+=
step
)
{
S
SstBlk
*
p
=
taosArrayGet
(
pIter
->
aSstBlk
,
i
);
if
((
!
pIter
->
backward
)
&&
p
->
minUid
>
pIter
->
uid
)
{
break
;
}
...
...
@@ -121,9 +121,9 @@ void tLDataIterNextBlock(SLDataIter *pIter) {
}
if
(
index
==
-
1
)
{
pIter
->
p
BlockL
=
NULL
;
pIter
->
p
SstBlk
=
NULL
;
}
else
{
pIter
->
p
BlockL
=
(
SBlockL
*
)
taosArrayGet
(
pIter
->
aBlockL
,
pIter
->
iBlockL
);
pIter
->
p
SstBlk
=
(
SSstBlk
*
)
taosArrayGet
(
pIter
->
aSstBlk
,
pIter
->
iSstBlk
);
}
}
...
...
@@ -194,14 +194,14 @@ bool tLDataIterNextRow(SLDataIter *pIter) {
int32_t
step
=
pIter
->
backward
?
-
1
:
1
;
// no qualified last file block in current file, no need to fetch row
if
(
pIter
->
p
BlockL
==
NULL
)
{
if
(
pIter
->
p
SstBlk
==
NULL
)
{
return
false
;
}
int32_t
iBlockL
=
pIter
->
i
BlockL
;
int32_t
iBlockL
=
pIter
->
i
SstBlk
;
if
(
pIter
->
bData
.
nRow
==
0
&&
pIter
->
p
BlockL
!=
NULL
)
{
// current block not loaded yet
code
=
tsdbRead
LastBlockEx
(
pIter
->
pReader
,
pIter
->
iLast
,
pIter
->
pBlockL
,
&
pIter
->
bData
);
if
(
pIter
->
bData
.
nRow
==
0
&&
pIter
->
p
SstBlk
!=
NULL
)
{
// current block not loaded yet
code
=
tsdbRead
SstBlockEx
(
pIter
->
pReader
,
pIter
->
iSst
,
pIter
->
pSstBlk
,
&
pIter
->
bData
);
if
(
code
!=
TSDB_CODE_SUCCESS
)
{
goto
_exit
;
}
...
...
@@ -216,15 +216,15 @@ bool tLDataIterNextRow(SLDataIter *pIter) {
if
(
pIter
->
iRow
>=
pIter
->
bData
.
nRow
||
pIter
->
iRow
<
0
)
{
tLDataIterNextBlock
(
pIter
);
if
(
pIter
->
p
BlockL
==
NULL
)
{
// no more data
if
(
pIter
->
p
SstBlk
==
NULL
)
{
// no more data
goto
_exit
;
}
}
else
{
break
;
}
if
(
iBlockL
!=
pIter
->
i
BlockL
)
{
code
=
tsdbRead
LastBlockEx
(
pIter
->
pReader
,
pIter
->
iLast
,
pIter
->
pBlockL
,
&
pIter
->
bData
);
if
(
iBlockL
!=
pIter
->
i
SstBlk
)
{
code
=
tsdbRead
SstBlockEx
(
pIter
->
pReader
,
pIter
->
iSst
,
pIter
->
pSstBlk
,
&
pIter
->
bData
);
if
(
code
)
{
goto
_exit
;
}
...
...
@@ -241,7 +241,7 @@ _exit:
terrno
=
code
;
}
return
(
code
==
TSDB_CODE_SUCCESS
)
&&
(
pIter
->
p
BlockL
!=
NULL
);
return
(
code
==
TSDB_CODE_SUCCESS
)
&&
(
pIter
->
p
SstBlk
!=
NULL
);
}
SRowInfo
*
tLDataIterGet
(
SLDataIter
*
pIter
)
{
return
&
pIter
->
rInfo
;
}
...
...
source/dnode/vnode/src/tsdb/tsdbRead.c
浏览文件 @
ff4fda84
...
...
@@ -1158,9 +1158,9 @@ static bool fileBlockShouldLoad(STsdbReader* pReader, SFileDataBlockInfo* pFBloc
// todo
bool
overlapWithlastBlock
=
false
;
#if 0
if (taosArrayGetSize(pLastBlockReader->p
BlockL
) > 0 && (pLastBlockReader->currentBlockIndex != -1)) {
S
BlockL* pBlockL = taosArrayGet(pLastBlockReader->pBlockL
, pLastBlockReader->currentBlockIndex);
overlapWithlastBlock = !(pBlock->maxKey.ts < p
BlockL->minKey || pBlock->minKey.ts > pBlockL
->maxKey);
if (taosArrayGetSize(pLastBlockReader->p
SstBlk
) > 0 && (pLastBlockReader->currentBlockIndex != -1)) {
S
SstBlk* pSstBlk = taosArrayGet(pLastBlockReader->pSstBlk
, pLastBlockReader->currentBlockIndex);
overlapWithlastBlock = !(pBlock->maxKey.ts < p
SstBlk->minKey || pBlock->minKey.ts > pSstBlk
->maxKey);
}
#endif
...
...
source/dnode/vnode/src/tsdb/tsdbReaderWriter.c
浏览文件 @
ff4fda84
...
...
@@ -434,10 +434,10 @@ int32_t tsdbDataFReaderOpen(SDataFReader **ppReader, STsdb *pTsdb, SDFileSet *pS
}
// sst
for
(
int32_t
i
Last
=
0
;
iLast
<
pSet
->
nSstF
;
iLa
st
++
)
{
tsdbSstFileName
(
pTsdb
,
pSet
->
diskId
,
pSet
->
fid
,
pSet
->
aSstF
[
i
La
st
],
fname
);
pReader
->
aLastFD
[
i
La
st
]
=
taosOpenFile
(
fname
,
TD_FILE_READ
);
if
(
pReader
->
aLastFD
[
i
La
st
]
==
NULL
)
{
for
(
int32_t
i
Sst
=
0
;
iSst
<
pSet
->
nSstF
;
iS
st
++
)
{
tsdbSstFileName
(
pTsdb
,
pSet
->
diskId
,
pSet
->
fid
,
pSet
->
aSstF
[
i
S
st
],
fname
);
pReader
->
aLastFD
[
i
S
st
]
=
taosOpenFile
(
fname
,
TD_FILE_READ
);
if
(
pReader
->
aLastFD
[
i
S
st
]
==
NULL
)
{
code
=
TAOS_SYSTEM_ERROR
(
errno
);
goto
_err
;
}
...
...
@@ -475,8 +475,8 @@ int32_t tsdbDataFReaderClose(SDataFReader **ppReader) {
}
// sst
for
(
int32_t
i
Last
=
0
;
iLast
<
(
*
ppReader
)
->
pSet
->
nSstF
;
iLa
st
++
)
{
if
(
taosCloseFile
(
&
(
*
ppReader
)
->
aLastFD
[
i
La
st
])
<
0
)
{
for
(
int32_t
i
Sst
=
0
;
iSst
<
(
*
ppReader
)
->
pSet
->
nSstF
;
iS
st
++
)
{
if
(
taosCloseFile
(
&
(
*
ppReader
)
->
aLastFD
[
i
S
st
])
<
0
)
{
code
=
TAOS_SYSTEM_ERROR
(
errno
);
goto
_err
;
}
...
...
@@ -559,14 +559,14 @@ _err:
return
code
;
}
int32_t
tsdbRead
BlockL
(
SDataFReader
*
pReader
,
int32_t
iLast
,
SArray
*
aBlockL
)
{
int32_t
tsdbRead
SstBlk
(
SDataFReader
*
pReader
,
int32_t
iSst
,
SArray
*
aSstBlk
)
{
int32_t
code
=
0
;
int64_t
offset
=
pReader
->
pSet
->
aSstF
[
i
La
st
]
->
offset
;
int64_t
size
=
pReader
->
pSet
->
aSstF
[
i
La
st
]
->
size
-
offset
;
int64_t
offset
=
pReader
->
pSet
->
aSstF
[
i
S
st
]
->
offset
;
int64_t
size
=
pReader
->
pSet
->
aSstF
[
i
S
st
]
->
size
-
offset
;
int64_t
n
;
uint32_t
delimiter
;
taosArrayClear
(
a
BlockL
);
taosArrayClear
(
a
SstBlk
);
if
(
size
==
0
)
{
goto
_exit
;
}
...
...
@@ -576,13 +576,13 @@ int32_t tsdbReadBlockL(SDataFReader *pReader, int32_t iLast, SArray *aBlockL) {
if
(
code
)
goto
_err
;
// seek
if
(
taosLSeekFile
(
pReader
->
aLastFD
[
i
La
st
],
offset
,
SEEK_SET
)
<
0
)
{
if
(
taosLSeekFile
(
pReader
->
aLastFD
[
i
S
st
],
offset
,
SEEK_SET
)
<
0
)
{
code
=
TAOS_SYSTEM_ERROR
(
errno
);
goto
_err
;
}
// read
n
=
taosReadFile
(
pReader
->
aLastFD
[
i
La
st
],
pReader
->
aBuf
[
0
],
size
);
n
=
taosReadFile
(
pReader
->
aLastFD
[
i
S
st
],
pReader
->
aBuf
[
0
],
size
);
if
(
n
<
0
)
{
code
=
TAOS_SYSTEM_ERROR
(
errno
);
goto
_err
;
...
...
@@ -603,10 +603,10 @@ int32_t tsdbReadBlockL(SDataFReader *pReader, int32_t iLast, SArray *aBlockL) {
ASSERT
(
delimiter
==
TSDB_FILE_DLMT
);
while
(
n
<
size
-
sizeof
(
TSCKSUM
))
{
S
BlockL
blockl
;
n
+=
tGet
BlockL
(
pReader
->
aBuf
[
0
]
+
n
,
&
blockl
);
S
SstBlk
blockl
;
n
+=
tGet
SstBlk
(
pReader
->
aBuf
[
0
]
+
n
,
&
blockl
);
if
(
taosArrayPush
(
a
BlockL
,
&
blockl
)
==
NULL
)
{
if
(
taosArrayPush
(
a
SstBlk
,
&
blockl
)
==
NULL
)
{
code
=
TSDB_CODE_OUT_OF_MEMORY
;
goto
_err
;
}
...
...
@@ -897,10 +897,10 @@ _err:
return
code
;
}
int32_t
tsdbRead
LastBlock
(
SDataFReader
*
pReader
,
int32_t
iLast
,
SBlockL
*
pBlockL
,
SBlockData
*
pBlockData
)
{
int32_t
tsdbRead
SstBlock
(
SDataFReader
*
pReader
,
int32_t
iSst
,
SSstBlk
*
pSstBlk
,
SBlockData
*
pBlockData
)
{
int32_t
code
=
0
;
code
=
tsdbReadBlockDataImpl
(
pReader
,
&
p
BlockL
->
bInfo
,
1
,
pBlockData
);
code
=
tsdbReadBlockDataImpl
(
pReader
,
&
p
SstBlk
->
bInfo
,
1
,
pBlockData
);
if
(
code
)
goto
_err
;
return
code
;
...
...
@@ -910,15 +910,15 @@ _err:
return
code
;
}
int32_t
tsdbRead
LastBlockEx
(
SDataFReader
*
pReader
,
int32_t
iLast
,
SBlockL
*
pBlockL
,
SBlockData
*
pBlockData
)
{
int32_t
tsdbRead
SstBlockEx
(
SDataFReader
*
pReader
,
int32_t
iSst
,
SSstBlk
*
pSstBlk
,
SBlockData
*
pBlockData
)
{
int32_t
code
=
0
;
// read
code
=
tsdbReadAndCheck
(
pReader
->
aLastFD
[
i
Last
],
pBlockL
->
bInfo
.
offset
,
&
pReader
->
aBuf
[
0
],
pBlockL
->
bInfo
.
szBlock
,
0
);
code
=
tsdbReadAndCheck
(
pReader
->
aLastFD
[
i
Sst
],
pSstBlk
->
bInfo
.
offset
,
&
pReader
->
aBuf
[
0
],
pSstBlk
->
bInfo
.
szBlock
,
0
);
if
(
code
)
goto
_exit
;
// decmpr
code
=
tDecmprBlockData
(
pReader
->
aBuf
[
0
],
p
BlockL
->
bInfo
.
szBlock
,
pBlockData
,
&
pReader
->
aBuf
[
1
]);
code
=
tDecmprBlockData
(
pReader
->
aBuf
[
0
],
p
SstBlk
->
bInfo
.
szBlock
,
pBlockData
,
&
pReader
->
aBuf
[
1
]);
if
(
code
)
goto
_exit
;
_exit:
...
...
@@ -952,9 +952,9 @@ int32_t tsdbDataFWriterOpen(SDataFWriter **ppWriter, STsdb *pTsdb, SDFileSet *pS
pWriter
->
fHead
=
*
pSet
->
pHeadF
;
pWriter
->
fData
=
*
pSet
->
pDataF
;
pWriter
->
fSma
=
*
pSet
->
pSmaF
;
for
(
int8_t
i
Last
=
0
;
iLast
<
pSet
->
nSstF
;
iLa
st
++
)
{
pWriter
->
wSet
.
aSstF
[
i
Last
]
=
&
pWriter
->
fSst
[
iLa
st
];
pWriter
->
fSst
[
i
Last
]
=
*
pSet
->
aSstF
[
iLa
st
];
for
(
int8_t
i
Sst
=
0
;
iSst
<
pSet
->
nSstF
;
iS
st
++
)
{
pWriter
->
wSet
.
aSstF
[
i
Sst
]
=
&
pWriter
->
fSst
[
iS
st
];
pWriter
->
fSst
[
i
Sst
]
=
*
pSet
->
aSstF
[
iS
st
];
}
// head
...
...
@@ -1301,22 +1301,22 @@ _err:
return
code
;
}
int32_t
tsdbWrite
BlockL
(
SDataFWriter
*
pWriter
,
SArray
*
aBlockL
)
{
int32_t
tsdbWrite
SstBlk
(
SDataFWriter
*
pWriter
,
SArray
*
aSstBlk
)
{
int32_t
code
=
0
;
SSstFile
*
pSstFile
=
&
pWriter
->
fSst
[
pWriter
->
wSet
.
nSstF
-
1
];
int64_t
size
;
int64_t
n
;
// check
if
(
taosArrayGetSize
(
a
BlockL
)
==
0
)
{
if
(
taosArrayGetSize
(
a
SstBlk
)
==
0
)
{
pSstFile
->
offset
=
pSstFile
->
size
;
goto
_exit
;
}
// size
size
=
sizeof
(
uint32_t
);
// TSDB_FILE_DLMT
for
(
int32_t
iBlockL
=
0
;
iBlockL
<
taosArrayGetSize
(
a
BlockL
);
iBlockL
++
)
{
size
+=
tPut
BlockL
(
NULL
,
taosArrayGet
(
aBlockL
,
iBlockL
));
for
(
int32_t
iBlockL
=
0
;
iBlockL
<
taosArrayGetSize
(
a
SstBlk
);
iBlockL
++
)
{
size
+=
tPut
SstBlk
(
NULL
,
taosArrayGet
(
aSstBlk
,
iBlockL
));
}
size
+=
sizeof
(
TSCKSUM
);
...
...
@@ -1327,8 +1327,8 @@ int32_t tsdbWriteBlockL(SDataFWriter *pWriter, SArray *aBlockL) {
// encode
n
=
0
;
n
+=
tPutU32
(
pWriter
->
aBuf
[
0
]
+
n
,
TSDB_FILE_DLMT
);
for
(
int32_t
iBlockL
=
0
;
iBlockL
<
taosArrayGetSize
(
a
BlockL
);
iBlockL
++
)
{
n
+=
tPut
BlockL
(
pWriter
->
aBuf
[
0
]
+
n
,
taosArrayGet
(
aBlockL
,
iBlockL
));
for
(
int32_t
iBlockL
=
0
;
iBlockL
<
taosArrayGetSize
(
a
SstBlk
);
iBlockL
++
)
{
n
+=
tPut
SstBlk
(
pWriter
->
aBuf
[
0
]
+
n
,
taosArrayGet
(
aSstBlk
,
iBlockL
));
}
taosCalcChecksumAppend
(
0
,
pWriter
->
aBuf
[
0
],
size
);
...
...
source/dnode/vnode/src/tsdb/tsdbSnapshot.c
浏览文件 @
ff4fda84
...
...
@@ -27,9 +27,9 @@ struct STsdbSnapReader {
int32_t
fid
;
SDataFReader
*
pDataFReader
;
SArray
*
aBlockIdx
;
// SArray<SBlockIdx>
SArray
*
a
BlockL
;
// SArray<SBlockL
>
SArray
*
a
SstBlk
;
// SArray<SSstBlk
>
SBlockIdx
*
pBlockIdx
;
S
BlockL
*
pBlockL
;
S
SstBlk
*
pSstBlk
;
int32_t
iBlockIdx
;
int32_t
iBlockL
;
...
...
@@ -64,7 +64,7 @@ static int32_t tsdbSnapReadData(STsdbSnapReader* pReader, uint8_t** ppData) {
code
=
tsdbReadBlockIdx
(
pReader
->
pDataFReader
,
pReader
->
aBlockIdx
);
if
(
code
)
goto
_err
;
code
=
tsdbRead
BlockL
(
pReader
->
pDataFReader
,
0
,
pReader
->
aBlockL
);
code
=
tsdbRead
SstBlk
(
pReader
->
pDataFReader
,
0
,
pReader
->
aSstBlk
);
if
(
code
)
goto
_err
;
// init
...
...
@@ -82,13 +82,13 @@ static int32_t tsdbSnapReadData(STsdbSnapReader* pReader, uint8_t** ppData) {
pReader
->
iBlockL
=
0
;
while
(
true
)
{
if
(
pReader
->
iBlockL
>=
taosArrayGetSize
(
pReader
->
a
BlockL
))
{
pReader
->
p
BlockL
=
NULL
;
if
(
pReader
->
iBlockL
>=
taosArrayGetSize
(
pReader
->
a
SstBlk
))
{
pReader
->
p
SstBlk
=
NULL
;
break
;
}
pReader
->
p
BlockL
=
(
SBlockL
*
)
taosArrayGet
(
pReader
->
aBlockL
,
pReader
->
iBlockL
);
if
(
pReader
->
p
BlockL
->
minVer
<=
pReader
->
ever
&&
pReader
->
pBlockL
->
maxVer
>=
pReader
->
sver
)
{
pReader
->
p
SstBlk
=
(
SSstBlk
*
)
taosArrayGet
(
pReader
->
aSstBlk
,
pReader
->
iBlockL
);
if
(
pReader
->
p
SstBlk
->
minVer
<=
pReader
->
ever
&&
pReader
->
pSstBlk
->
maxVer
>=
pReader
->
sver
)
{
// TODO
break
;
}
...
...
@@ -101,8 +101,8 @@ static int32_t tsdbSnapReadData(STsdbSnapReader* pReader, uint8_t** ppData) {
}
while
(
true
)
{
if
(
pReader
->
pBlockIdx
&&
pReader
->
p
BlockL
)
{
TABLEID
id
=
{.
suid
=
pReader
->
p
BlockL
->
suid
,
.
uid
=
pReader
->
pBlockL
->
minUid
};
if
(
pReader
->
pBlockIdx
&&
pReader
->
p
SstBlk
)
{
TABLEID
id
=
{.
suid
=
pReader
->
p
SstBlk
->
suid
,
.
uid
=
pReader
->
pSstBlk
->
minUid
};
ASSERT
(
0
);
...
...
@@ -142,18 +142,18 @@ static int32_t tsdbSnapReadData(STsdbSnapReader* pReader, uint8_t** ppData) {
}
if
(
*
ppData
)
goto
_exit
;
}
else
if
(
pReader
->
p
BlockL
)
{
while
(
pReader
->
p
BlockL
)
{
if
(
pReader
->
p
BlockL
->
minVer
<=
pReader
->
ever
&&
pReader
->
pBlockL
->
maxVer
>=
pReader
->
sver
)
{
}
else
if
(
pReader
->
p
SstBlk
)
{
while
(
pReader
->
p
SstBlk
)
{
if
(
pReader
->
p
SstBlk
->
minVer
<=
pReader
->
ever
&&
pReader
->
pSstBlk
->
maxVer
>=
pReader
->
sver
)
{
// load data (todo)
}
// next
pReader
->
iBlockL
++
;
if
(
pReader
->
iBlockL
<
taosArrayGetSize
(
pReader
->
a
BlockL
))
{
pReader
->
p
BlockL
=
(
SBlockL
*
)
taosArrayGetSize
(
pReader
->
aBlockL
);
if
(
pReader
->
iBlockL
<
taosArrayGetSize
(
pReader
->
a
SstBlk
))
{
pReader
->
p
SstBlk
=
(
SSstBlk
*
)
taosArrayGetSize
(
pReader
->
aSstBlk
);
}
else
{
pReader
->
p
BlockL
=
NULL
;
pReader
->
p
SstBlk
=
NULL
;
}
if
(
*
ppData
)
goto
_exit
;
...
...
@@ -298,8 +298,8 @@ int32_t tsdbSnapReaderOpen(STsdb* pTsdb, int64_t sver, int64_t ever, int8_t type
code
=
TSDB_CODE_OUT_OF_MEMORY
;
goto
_err
;
}
pReader
->
a
BlockL
=
taosArrayInit
(
0
,
sizeof
(
SBlockL
));
if
(
pReader
->
a
BlockL
==
NULL
)
{
pReader
->
a
SstBlk
=
taosArrayInit
(
0
,
sizeof
(
SSstBlk
));
if
(
pReader
->
a
SstBlk
==
NULL
)
{
code
=
TSDB_CODE_OUT_OF_MEMORY
;
goto
_err
;
}
...
...
@@ -338,7 +338,7 @@ int32_t tsdbSnapReaderClose(STsdbSnapReader** ppReader) {
if
(
pReader
->
pDataFReader
)
{
tsdbDataFReaderClose
(
&
pReader
->
pDataFReader
);
}
taosArrayDestroy
(
pReader
->
a
BlockL
);
taosArrayDestroy
(
pReader
->
a
SstBlk
);
taosArrayDestroy
(
pReader
->
aBlockIdx
);
tMapDataClear
(
&
pReader
->
mBlock
);
tBlockDataDestroy
(
&
pReader
->
oBlockData
,
1
);
...
...
@@ -431,7 +431,7 @@ struct STsdbSnapWriter {
SBlockData
*
pBlockData
;
int32_t
iRow
;
SBlockData
bDataR
;
SArray
*
a
BlockL
;
// SArray<SBlockL
>
SArray
*
a
SstBlk
;
// SArray<SSstBlk
>
int32_t
iBlockL
;
SBlockData
lDataR
;
...
...
@@ -443,7 +443,7 @@ struct STsdbSnapWriter {
SMapData
mBlockW
;
// SMapData<SBlock>
SArray
*
aBlockIdxW
;
// SArray<SBlockIdx>
SArray
*
aBlockLW
;
// SArray<S
BlockL
>
SArray
*
aBlockLW
;
// SArray<S
SstBlk
>
// for del file
SDelFReader
*
pDelFReader
;
...
...
@@ -845,7 +845,7 @@ static int32_t tsdbSnapWriteDataEnd(STsdbSnapWriter* pWriter) {
// write remain stuff
if
(
taosArrayGetSize
(
pWriter
->
aBlockLW
)
>
0
)
{
code
=
tsdbWrite
BlockL
(
pWriter
->
pDataFWriter
,
pWriter
->
aBlockIdxW
);
code
=
tsdbWrite
SstBlk
(
pWriter
->
pDataFWriter
,
pWriter
->
aBlockIdxW
);
if
(
code
)
goto
_err
;
}
...
...
@@ -911,12 +911,12 @@ static int32_t tsdbSnapWriteData(STsdbSnapWriter* pWriter, uint8_t* pData, uint3
code
=
tsdbReadBlockIdx
(
pWriter
->
pDataFReader
,
pWriter
->
aBlockIdx
);
if
(
code
)
goto
_err
;
code
=
tsdbRead
BlockL
(
pWriter
->
pDataFReader
,
0
,
pWriter
->
aBlockL
);
code
=
tsdbRead
SstBlk
(
pWriter
->
pDataFReader
,
0
,
pWriter
->
aSstBlk
);
if
(
code
)
goto
_err
;
}
else
{
ASSERT
(
pWriter
->
pDataFReader
==
NULL
);
taosArrayClear
(
pWriter
->
aBlockIdx
);
taosArrayClear
(
pWriter
->
a
BlockL
);
taosArrayClear
(
pWriter
->
a
SstBlk
);
}
pWriter
->
iBlockIdx
=
0
;
pWriter
->
pBlockIdx
=
NULL
;
...
...
@@ -1147,8 +1147,8 @@ int32_t tsdbSnapWriterOpen(STsdb* pTsdb, int64_t sver, int64_t ever, STsdbSnapWr
code
=
tBlockDataCreate
(
&
pWriter
->
bDataR
);
if
(
code
)
goto
_err
;
pWriter
->
a
BlockL
=
taosArrayInit
(
0
,
sizeof
(
SBlockL
));
if
(
pWriter
->
a
BlockL
==
NULL
)
{
pWriter
->
a
SstBlk
=
taosArrayInit
(
0
,
sizeof
(
SSstBlk
));
if
(
pWriter
->
a
SstBlk
==
NULL
)
{
code
=
TSDB_CODE_OUT_OF_MEMORY
;
goto
_err
;
}
...
...
@@ -1161,7 +1161,7 @@ int32_t tsdbSnapWriterOpen(STsdb* pTsdb, int64_t sver, int64_t ever, STsdbSnapWr
code
=
tBlockDataCreate
(
&
pWriter
->
bDataW
);
if
(
code
)
goto
_err
;
pWriter
->
aBlockLW
=
taosArrayInit
(
0
,
sizeof
(
S
BlockL
));
pWriter
->
aBlockLW
=
taosArrayInit
(
0
,
sizeof
(
S
SstBlk
));
if
(
pWriter
->
aBlockLW
==
NULL
)
{
code
=
TSDB_CODE_OUT_OF_MEMORY
;
goto
_err
;
...
...
source/dnode/vnode/src/tsdb/tsdbUtil.c
浏览文件 @
ff4fda84
...
...
@@ -214,7 +214,7 @@ int32_t tCmprBlockIdx(void const *lhs, void const *rhs) {
int32_t
tCmprBlockL
(
void
const
*
lhs
,
void
const
*
rhs
)
{
SBlockIdx
*
lBlockIdx
=
(
SBlockIdx
*
)
lhs
;
S
BlockL
*
rBlockL
=
(
SBlockL
*
)
rhs
;
S
SstBlk
*
rBlockL
=
(
SSstBlk
*
)
rhs
;
if
(
lBlockIdx
->
suid
<
rBlockL
->
suid
)
{
return
-
1
;
...
...
@@ -311,41 +311,41 @@ bool tBlockHasSma(SBlock *pBlock) {
return
pBlock
->
smaInfo
.
size
>
0
;
}
// S
BlockL
======================================================
int32_t
tPut
BlockL
(
uint8_t
*
p
,
void
*
ph
)
{
// S
SstBlk
======================================================
int32_t
tPut
SstBlk
(
uint8_t
*
p
,
void
*
ph
)
{
int32_t
n
=
0
;
S
BlockL
*
pBlockL
=
(
SBlockL
*
)
ph
;
n
+=
tPutI64
(
p
?
p
+
n
:
p
,
p
BlockL
->
suid
);
n
+=
tPutI64
(
p
?
p
+
n
:
p
,
p
BlockL
->
minUid
);
n
+=
tPutI64
(
p
?
p
+
n
:
p
,
p
BlockL
->
maxUid
);
n
+=
tPutI64v
(
p
?
p
+
n
:
p
,
p
BlockL
->
minKey
);
n
+=
tPutI64v
(
p
?
p
+
n
:
p
,
p
BlockL
->
maxKey
);
n
+=
tPutI64v
(
p
?
p
+
n
:
p
,
p
BlockL
->
minVer
);
n
+=
tPutI64v
(
p
?
p
+
n
:
p
,
p
BlockL
->
maxVer
);
n
+=
tPutI32v
(
p
?
p
+
n
:
p
,
p
BlockL
->
nRow
);
n
+=
tPutI64v
(
p
?
p
+
n
:
p
,
p
BlockL
->
bInfo
.
offset
);
n
+=
tPutI32v
(
p
?
p
+
n
:
p
,
p
BlockL
->
bInfo
.
szBlock
);
n
+=
tPutI32v
(
p
?
p
+
n
:
p
,
p
BlockL
->
bInfo
.
szKey
);
S
SstBlk
*
pSstBlk
=
(
SSstBlk
*
)
ph
;
n
+=
tPutI64
(
p
?
p
+
n
:
p
,
p
SstBlk
->
suid
);
n
+=
tPutI64
(
p
?
p
+
n
:
p
,
p
SstBlk
->
minUid
);
n
+=
tPutI64
(
p
?
p
+
n
:
p
,
p
SstBlk
->
maxUid
);
n
+=
tPutI64v
(
p
?
p
+
n
:
p
,
p
SstBlk
->
minKey
);
n
+=
tPutI64v
(
p
?
p
+
n
:
p
,
p
SstBlk
->
maxKey
);
n
+=
tPutI64v
(
p
?
p
+
n
:
p
,
p
SstBlk
->
minVer
);
n
+=
tPutI64v
(
p
?
p
+
n
:
p
,
p
SstBlk
->
maxVer
);
n
+=
tPutI32v
(
p
?
p
+
n
:
p
,
p
SstBlk
->
nRow
);
n
+=
tPutI64v
(
p
?
p
+
n
:
p
,
p
SstBlk
->
bInfo
.
offset
);
n
+=
tPutI32v
(
p
?
p
+
n
:
p
,
p
SstBlk
->
bInfo
.
szBlock
);
n
+=
tPutI32v
(
p
?
p
+
n
:
p
,
p
SstBlk
->
bInfo
.
szKey
);
return
n
;
}
int32_t
tGet
BlockL
(
uint8_t
*
p
,
void
*
ph
)
{
int32_t
tGet
SstBlk
(
uint8_t
*
p
,
void
*
ph
)
{
int32_t
n
=
0
;
S
BlockL
*
pBlockL
=
(
SBlockL
*
)
ph
;
n
+=
tGetI64
(
p
+
n
,
&
p
BlockL
->
suid
);
n
+=
tGetI64
(
p
+
n
,
&
p
BlockL
->
minUid
);
n
+=
tGetI64
(
p
+
n
,
&
p
BlockL
->
maxUid
);
n
+=
tGetI64v
(
p
+
n
,
&
p
BlockL
->
minKey
);
n
+=
tGetI64v
(
p
+
n
,
&
p
BlockL
->
maxKey
);
n
+=
tGetI64v
(
p
+
n
,
&
p
BlockL
->
minVer
);
n
+=
tGetI64v
(
p
+
n
,
&
p
BlockL
->
maxVer
);
n
+=
tGetI32v
(
p
+
n
,
&
p
BlockL
->
nRow
);
n
+=
tGetI64v
(
p
+
n
,
&
p
BlockL
->
bInfo
.
offset
);
n
+=
tGetI32v
(
p
+
n
,
&
p
BlockL
->
bInfo
.
szBlock
);
n
+=
tGetI32v
(
p
+
n
,
&
p
BlockL
->
bInfo
.
szKey
);
S
SstBlk
*
pSstBlk
=
(
SSstBlk
*
)
ph
;
n
+=
tGetI64
(
p
+
n
,
&
p
SstBlk
->
suid
);
n
+=
tGetI64
(
p
+
n
,
&
p
SstBlk
->
minUid
);
n
+=
tGetI64
(
p
+
n
,
&
p
SstBlk
->
maxUid
);
n
+=
tGetI64v
(
p
+
n
,
&
p
SstBlk
->
minKey
);
n
+=
tGetI64v
(
p
+
n
,
&
p
SstBlk
->
maxKey
);
n
+=
tGetI64v
(
p
+
n
,
&
p
SstBlk
->
minVer
);
n
+=
tGetI64v
(
p
+
n
,
&
p
SstBlk
->
maxVer
);
n
+=
tGetI32v
(
p
+
n
,
&
p
SstBlk
->
nRow
);
n
+=
tGetI64v
(
p
+
n
,
&
p
SstBlk
->
bInfo
.
offset
);
n
+=
tGetI32v
(
p
+
n
,
&
p
SstBlk
->
bInfo
.
szBlock
);
n
+=
tGetI32v
(
p
+
n
,
&
p
SstBlk
->
bInfo
.
szKey
);
return
n
;
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录