Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
856b50eb
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看板
未验证
提交
856b50eb
编写于
9月 08, 2022
作者:
S
Shengliang Guan
提交者:
GitHub
9月 08, 2022
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #16746 from taosdata/refact/tsdb_new_snapshot
refact: tsdb new snapshot
上级
45f35211
bb0b1fda
变更
8
展开全部
隐藏空白更改
内联
并排
Showing
8 changed file
with
906 addition
and
720 deletion
+906
-720
source/dnode/vnode/src/inc/tsdb.h
source/dnode/vnode/src/inc/tsdb.h
+28
-20
source/dnode/vnode/src/inc/vnodeInt.h
source/dnode/vnode/src/inc/vnodeInt.h
+1
-1
source/dnode/vnode/src/tsdb/tsdbCache.c
source/dnode/vnode/src/tsdb/tsdbCache.c
+1
-1
source/dnode/vnode/src/tsdb/tsdbCommit.c
source/dnode/vnode/src/tsdb/tsdbCommit.c
+72
-84
source/dnode/vnode/src/tsdb/tsdbRead.c
source/dnode/vnode/src/tsdb/tsdbRead.c
+11
-11
source/dnode/vnode/src/tsdb/tsdbReaderWriter.c
source/dnode/vnode/src/tsdb/tsdbReaderWriter.c
+32
-9
source/dnode/vnode/src/tsdb/tsdbSnapshot.c
source/dnode/vnode/src/tsdb/tsdbSnapshot.c
+759
-593
source/dnode/vnode/src/vnd/vnodeSnapshot.c
source/dnode/vnode/src/vnd/vnodeSnapshot.c
+2
-1
未找到文件。
source/dnode/vnode/src/inc/tsdb.h
浏览文件 @
856b50eb
...
...
@@ -84,6 +84,8 @@ typedef struct SLDataIter SLDataIter;
#define TSDBKEY_MIN ((TSDBKEY){.ts = TSKEY_MIN, .version = VERSION_MIN})
#define TSDBKEY_MAX ((TSDBKEY){.ts = TSKEY_MAX, .version = VERSION_MAX})
#define TABLE_SAME_SCHEMA(SUID1, UID1, SUID2, UID2) ((SUID1) ? (SUID1) == (SUID2) : (UID1) == (UID2))
#define PAGE_CONTENT_SIZE(PAGE) ((PAGE) - sizeof(TSCKSUM))
#define LOGIC_TO_FILE_OFFSET(LOFFSET, PAGE) \
((LOFFSET) / PAGE_CONTENT_SIZE(PAGE) * (PAGE) + (LOFFSET) % PAGE_CONTENT_SIZE(PAGE))
...
...
@@ -262,7 +264,7 @@ int32_t tsdbDataFWriterOpen(SDataFWriter **ppWriter, STsdb *pTsdb, SDFileSet *pS
int32_t
tsdbDataFWriterClose
(
SDataFWriter
**
ppWriter
,
int8_t
sync
);
int32_t
tsdbUpdateDFileSetHeader
(
SDataFWriter
*
pWriter
);
int32_t
tsdbWriteBlockIdx
(
SDataFWriter
*
pWriter
,
SArray
*
aBlockIdx
);
int32_t
tsdbWrite
Block
(
SDataFWriter
*
pWriter
,
SMapData
*
pMapData
,
SBlockIdx
*
pBlockIdx
);
int32_t
tsdbWrite
DataBlk
(
SDataFWriter
*
pWriter
,
SMapData
*
mDataBlk
,
SBlockIdx
*
pBlockIdx
);
int32_t
tsdbWriteSttBlk
(
SDataFWriter
*
pWriter
,
SArray
*
aSttBlk
);
int32_t
tsdbWriteBlockData
(
SDataFWriter
*
pWriter
,
SBlockData
*
pBlockData
,
SBlockInfo
*
pBlkInfo
,
SSmaInfo
*
pSmaInfo
,
int8_t
cmprAlg
,
int8_t
toLast
);
...
...
@@ -272,7 +274,7 @@ int32_t tsdbDFileSetCopy(STsdb *pTsdb, SDFileSet *pSetFrom, SDFileSet *pSetTo);
int32_t
tsdbDataFReaderOpen
(
SDataFReader
**
ppReader
,
STsdb
*
pTsdb
,
SDFileSet
*
pSet
);
int32_t
tsdbDataFReaderClose
(
SDataFReader
**
ppReader
);
int32_t
tsdbReadBlockIdx
(
SDataFReader
*
pReader
,
SArray
*
aBlockIdx
);
int32_t
tsdbRead
Block
(
SDataFReader
*
pReader
,
SBlockIdx
*
pBlockIdx
,
SMapData
*
pMapData
);
int32_t
tsdbRead
DataBlk
(
SDataFReader
*
pReader
,
SBlockIdx
*
pBlockIdx
,
SMapData
*
mDataBlk
);
int32_t
tsdbReadSttBlk
(
SDataFReader
*
pReader
,
int32_t
iStt
,
SArray
*
aSttBlk
);
int32_t
tsdbReadBlockSma
(
SDataFReader
*
pReader
,
SDataBlk
*
pBlock
,
SArray
*
aColumnDataAgg
);
int32_t
tsdbReadDataBlock
(
SDataFReader
*
pReader
,
SDataBlk
*
pBlock
,
SBlockData
*
pBlockData
);
...
...
@@ -644,35 +646,41 @@ typedef struct {
}
SRowInfo
;
typedef
struct
SSttBlockLoadInfo
{
SBlockData
blockData
[
2
];
SArray
*
aSttBlk
;
int32_t
blockIndex
[
2
];
// to denote the loaded block in the corresponding position.
int32_t
currentLoadBlockIndex
;
int32_t
loadBlocks
;
double
elapsedTime
;
SBlockData
blockData
[
2
];
SArray
*
aSttBlk
;
int32_t
blockIndex
[
2
];
// to denote the loaded block in the corresponding position.
int32_t
currentLoadBlockIndex
;
int32_t
loadBlocks
;
double
elapsedTime
;
}
SSttBlockLoadInfo
;
typedef
struct
SMergeTree
{
int8_t
backward
;
SRBTree
rbt
;
SArray
*
pIterList
;
SLDataIter
*
pIter
;
bool
destroyLoadInfo
;
SSttBlockLoadInfo
*
pLoadInfo
;
const
char
*
idStr
;
int8_t
backward
;
SRBTree
rbt
;
SArray
*
pIterList
;
SLDataIter
*
pIter
;
bool
destroyLoadInfo
;
SSttBlockLoadInfo
*
pLoadInfo
;
const
char
*
idStr
;
}
SMergeTree
;
typedef
struct
{
int64_t
suid
;
int64_t
uid
;
STSchema
*
pTSchema
;
}
SSkmInfo
;
int32_t
tMergeTreeOpen
(
SMergeTree
*
pMTree
,
int8_t
backward
,
SDataFReader
*
pFReader
,
uint64_t
suid
,
uint64_t
uid
,
STimeWindow
*
pTimeWindow
,
SVersionRange
*
pVerRange
,
void
*
pLoadInfo
,
const
char
*
idStr
);
STimeWindow
*
pTimeWindow
,
SVersionRange
*
pVerRange
,
void
*
pLoadInfo
,
const
char
*
idStr
);
void
tMergeTreeAddIter
(
SMergeTree
*
pMTree
,
SLDataIter
*
pIter
);
bool
tMergeTreeNext
(
SMergeTree
*
pMTree
);
TSDBROW
tMergeTreeGetRow
(
SMergeTree
*
pMTree
);
void
tMergeTreeClose
(
SMergeTree
*
pMTree
);
SSttBlockLoadInfo
*
tCreateLastBlockLoadInfo
();
void
resetLastBlockLoadInfo
(
SSttBlockLoadInfo
*
pLoadInfo
);
void
getLastBlockLoadInfo
(
SSttBlockLoadInfo
*
pLoadInfo
,
int64_t
*
blocks
,
double
*
el
);
void
*
destroyLastBlockLoadInfo
(
SSttBlockLoadInfo
*
pLoadInfo
);
SSttBlockLoadInfo
*
tCreateLastBlockLoadInfo
();
void
resetLastBlockLoadInfo
(
SSttBlockLoadInfo
*
pLoadInfo
);
void
getLastBlockLoadInfo
(
SSttBlockLoadInfo
*
pLoadInfo
,
int64_t
*
blocks
,
double
*
el
);
void
*
destroyLastBlockLoadInfo
(
SSttBlockLoadInfo
*
pLoadInfo
);
// ========== inline functions ==========
static
FORCE_INLINE
int32_t
tsdbKeyCmprFn
(
const
void
*
p1
,
const
void
*
p2
)
{
...
...
source/dnode/vnode/src/inc/vnodeInt.h
浏览文件 @
856b50eb
...
...
@@ -104,7 +104,7 @@ int metaCreateSTable(SMeta* pMeta, int64_t version, SVCreateStbReq*
int
metaAlterSTable
(
SMeta
*
pMeta
,
int64_t
version
,
SVCreateStbReq
*
pReq
);
int
metaDropSTable
(
SMeta
*
pMeta
,
int64_t
verison
,
SVDropStbReq
*
pReq
,
SArray
*
tbUidList
);
int
metaCreateTable
(
SMeta
*
pMeta
,
int64_t
version
,
SVCreateTbReq
*
pReq
,
STableMetaRsp
**
pMetaRsp
);
int
metaDropTable
(
SMeta
*
pMeta
,
int64_t
version
,
SVDropTbReq
*
pReq
,
SArray
*
tbUids
,
int64_t
*
tbUid
);
int
metaDropTable
(
SMeta
*
pMeta
,
int64_t
version
,
SVDropTbReq
*
pReq
,
SArray
*
tbUids
,
int64_t
*
tbUid
);
int
metaTtlDropTable
(
SMeta
*
pMeta
,
int64_t
ttl
,
SArray
*
tbUids
);
int
metaAlterTable
(
SMeta
*
pMeta
,
int64_t
version
,
SVAlterTbReq
*
pReq
,
STableMetaRsp
*
pMetaRsp
);
SSchemaWrapper
*
metaGetTableSchema
(
SMeta
*
pMeta
,
tb_uid_t
uid
,
int32_t
sver
,
bool
isinline
);
...
...
source/dnode/vnode/src/tsdb/tsdbCache.c
浏览文件 @
856b50eb
...
...
@@ -589,7 +589,7 @@ static int32_t getNextRowFromFS(void *iter, TSDBROW **ppRow) {
}
tMapDataReset
(
&
state
->
blockMap
);
code
=
tsdbRead
Bloc
k
(
state
->
pDataFReader
,
state
->
pBlockIdx
,
&
state
->
blockMap
);
code
=
tsdbRead
DataBl
k
(
state
->
pDataFReader
,
state
->
pBlockIdx
,
&
state
->
blockMap
);
if
(
code
)
goto
_err
;
state
->
nBlock
=
state
->
blockMap
.
nItem
;
...
...
source/dnode/vnode/src/tsdb/tsdbCommit.c
浏览文件 @
856b50eb
...
...
@@ -14,13 +14,8 @@
*/
#include "tsdb.h"
typedef
struct
{
int64_t
suid
;
int64_t
uid
;
STSchema
*
pTSchema
;
}
SSkmInfo
;
typedef
enum
{
MEMORY_DATA_ITER
=
0
,
LAS
T_DATA_ITER
}
EDataIterT
;
typedef
enum
{
MEMORY_DATA_ITER
=
0
,
ST
T_DATA_ITER
}
EDataIterT
;
typedef
struct
{
SRBTreeNode
n
;
...
...
@@ -99,7 +94,7 @@ static int32_t tsdbCommitCache(SCommitter *pCommitter);
static
int32_t
tsdbEndCommit
(
SCommitter
*
pCommitter
,
int32_t
eno
);
static
int32_t
tsdbNextCommitRow
(
SCommitter
*
pCommitter
);
static
int32_t
tRowInfoCmprFn
(
const
void
*
p1
,
const
void
*
p2
)
{
int32_t
tRowInfoCmprFn
(
const
void
*
p1
,
const
void
*
p2
)
{
SRowInfo
*
pInfo1
=
(
SRowInfo
*
)
p1
;
SRowInfo
*
pInfo2
=
(
SRowInfo
*
)
p2
;
...
...
@@ -325,22 +320,22 @@ _err:
return
code
;
}
static
int32_t
tsdbCommitterUpdateTableSchema
(
SCommitter
*
pCommitter
,
int64_t
suid
,
int64_t
uid
)
{
int32_t
tsdbUpdateTableSchema
(
SMeta
*
pMeta
,
int64_t
suid
,
int64_t
uid
,
SSkmInfo
*
pSkmInfo
)
{
int32_t
code
=
0
;
if
(
suid
)
{
if
(
p
Committer
->
skmTable
.
suid
==
suid
)
{
p
Committer
->
skmTable
.
uid
=
uid
;
if
(
p
SkmInfo
->
suid
==
suid
)
{
p
SkmInfo
->
uid
=
uid
;
goto
_exit
;
}
}
else
{
if
(
p
Committer
->
skmTable
.
uid
==
uid
)
goto
_exit
;
if
(
p
SkmInfo
->
uid
==
uid
)
goto
_exit
;
}
p
Committer
->
skmTable
.
suid
=
suid
;
p
Committer
->
skmTable
.
uid
=
uid
;
tTSchemaDestroy
(
p
Committer
->
skmTable
.
pTSchema
);
code
=
metaGetTbTSchemaEx
(
p
Committer
->
pTsdb
->
pVnode
->
pMeta
,
suid
,
uid
,
-
1
,
&
pCommitter
->
skmTable
.
pTSchema
);
p
SkmInfo
->
suid
=
suid
;
p
SkmInfo
->
uid
=
uid
;
tTSchemaDestroy
(
p
SkmInfo
->
pTSchema
);
code
=
metaGetTbTSchemaEx
(
p
Meta
,
suid
,
uid
,
-
1
,
&
pSkmInfo
->
pTSchema
);
if
(
code
)
goto
_exit
;
_exit:
...
...
@@ -382,7 +377,7 @@ static int32_t tsdbCommitterNextTableData(SCommitter *pCommitter) {
pCommitter
->
dReader
.
pBlockIdx
=
(
SBlockIdx
*
)
taosArrayGet
(
pCommitter
->
dReader
.
aBlockIdx
,
pCommitter
->
dReader
.
iBlockIdx
);
code
=
tsdbRead
Bloc
k
(
pCommitter
->
dReader
.
pReader
,
pCommitter
->
dReader
.
pBlockIdx
,
&
pCommitter
->
dReader
.
mBlock
);
code
=
tsdbRead
DataBl
k
(
pCommitter
->
dReader
.
pReader
,
pCommitter
->
dReader
.
pBlockIdx
,
&
pCommitter
->
dReader
.
mBlock
);
if
(
code
)
goto
_exit
;
ASSERT
(
pCommitter
->
dReader
.
mBlock
.
nItem
>
0
);
...
...
@@ -432,7 +427,7 @@ static int32_t tsdbOpenCommitIter(SCommitter *pCommitter) {
int8_t
iIter
=
0
;
for
(
int32_t
iStt
=
0
;
iStt
<
pReader
->
pSet
->
nSttF
;
iStt
++
)
{
pIter
=
&
pCommitter
->
aDataIter
[
iIter
];
pIter
->
type
=
LAS
T_DATA_ITER
;
pIter
->
type
=
ST
T_DATA_ITER
;
pIter
->
iStt
=
iStt
;
code
=
tsdbReadSttBlk
(
pCommitter
->
dReader
.
pReader
,
iStt
,
pIter
->
aSttBlk
);
...
...
@@ -498,7 +493,7 @@ static int32_t tsdbCommitFileDataStart(SCommitter *pCommitter) {
pCommitter
->
dReader
.
iBlockIdx
=
0
;
if
(
taosArrayGetSize
(
pCommitter
->
dReader
.
aBlockIdx
)
>
0
)
{
pCommitter
->
dReader
.
pBlockIdx
=
(
SBlockIdx
*
)
taosArrayGet
(
pCommitter
->
dReader
.
aBlockIdx
,
0
);
code
=
tsdbRead
Bloc
k
(
pCommitter
->
dReader
.
pReader
,
pCommitter
->
dReader
.
pBlockIdx
,
&
pCommitter
->
dReader
.
mBlock
);
code
=
tsdbRead
DataBl
k
(
pCommitter
->
dReader
.
pReader
,
pCommitter
->
dReader
.
pBlockIdx
,
&
pCommitter
->
dReader
.
mBlock
);
if
(
code
)
goto
_err
;
}
else
{
pCommitter
->
dReader
.
pBlockIdx
=
NULL
;
...
...
@@ -556,46 +551,45 @@ _err:
return
code
;
}
static
int32_t
tsdbCommitDataBlock
(
SCommitter
*
pCommitter
)
{
int32_t
code
=
0
;
SBlockData
*
pBlockData
=
&
pCommitter
->
dWriter
.
bData
;
SDataBlk
block
;
int32_t
tsdbWriteDataBlock
(
SDataFWriter
*
pWriter
,
SBlockData
*
pBlockData
,
SMapData
*
mDataBlk
,
int8_t
cmprAlg
)
{
int32_t
code
=
0
;
ASSERT
(
pBlockData
->
nRow
>
0
)
;
if
(
pBlockData
->
nRow
==
0
)
return
code
;
tDataBlkReset
(
&
block
);
SDataBlk
dataBlk
;
tDataBlkReset
(
&
dataBlk
);
// info
bloc
k
.
nRow
+=
pBlockData
->
nRow
;
dataBl
k
.
nRow
+=
pBlockData
->
nRow
;
for
(
int32_t
iRow
=
0
;
iRow
<
pBlockData
->
nRow
;
iRow
++
)
{
TSDBKEY
key
=
{.
ts
=
pBlockData
->
aTSKEY
[
iRow
],
.
version
=
pBlockData
->
aVersion
[
iRow
]};
if
(
iRow
==
0
)
{
if
(
tsdbKeyCmprFn
(
&
bloc
k
.
minKey
,
&
key
)
>
0
)
{
bloc
k
.
minKey
=
key
;
if
(
tsdbKeyCmprFn
(
&
dataBl
k
.
minKey
,
&
key
)
>
0
)
{
dataBl
k
.
minKey
=
key
;
}
}
else
{
if
(
pBlockData
->
aTSKEY
[
iRow
]
==
pBlockData
->
aTSKEY
[
iRow
-
1
])
{
bloc
k
.
hasDup
=
1
;
dataBl
k
.
hasDup
=
1
;
}
}
if
(
iRow
==
pBlockData
->
nRow
-
1
&&
tsdbKeyCmprFn
(
&
bloc
k
.
maxKey
,
&
key
)
<
0
)
{
bloc
k
.
maxKey
=
key
;
if
(
iRow
==
pBlockData
->
nRow
-
1
&&
tsdbKeyCmprFn
(
&
dataBl
k
.
maxKey
,
&
key
)
<
0
)
{
dataBl
k
.
maxKey
=
key
;
}
block
.
minVer
=
TMIN
(
bloc
k
.
minVer
,
key
.
version
);
block
.
maxVer
=
TMAX
(
bloc
k
.
maxVer
,
key
.
version
);
dataBlk
.
minVer
=
TMIN
(
dataBl
k
.
minVer
,
key
.
version
);
dataBlk
.
maxVer
=
TMAX
(
dataBl
k
.
maxVer
,
key
.
version
);
}
// write
bloc
k
.
nSubBlock
++
;
code
=
tsdbWriteBlockData
(
p
Committer
->
dWriter
.
pWriter
,
pBlockData
,
&
block
.
aSubBlock
[
bloc
k
.
nSubBlock
-
1
],
((
block
.
nSubBlock
==
1
)
&&
!
block
.
hasDup
)
?
&
block
.
smaInfo
:
NULL
,
pCommitter
->
cmprAlg
,
0
);
dataBl
k
.
nSubBlock
++
;
code
=
tsdbWriteBlockData
(
p
Writer
,
pBlockData
,
&
dataBlk
.
aSubBlock
[
dataBl
k
.
nSubBlock
-
1
],
((
dataBlk
.
nSubBlock
==
1
)
&&
!
dataBlk
.
hasDup
)
?
&
dataBlk
.
smaInfo
:
NULL
,
cmprAlg
,
0
);
if
(
code
)
goto
_err
;
// put SDataBlk
code
=
tMapDataPutItem
(
&
pCommitter
->
dWriter
.
mBlock
,
&
bloc
k
,
tPutDataBlk
);
code
=
tMapDataPutItem
(
mDataBlk
,
&
dataBl
k
,
tPutDataBlk
);
if
(
code
)
goto
_err
;
// clear
...
...
@@ -604,39 +598,38 @@ static int32_t tsdbCommitDataBlock(SCommitter *pCommitter) {
return
code
;
_err:
tsdbError
(
"vgId:%d tsdb commit data block failed since %s"
,
TD_VID
(
p
Commit
ter
->
pTsdb
->
pVnode
),
tstrerror
(
code
));
tsdbError
(
"vgId:%d tsdb commit data block failed since %s"
,
TD_VID
(
p
Wri
ter
->
pTsdb
->
pVnode
),
tstrerror
(
code
));
return
code
;
}
static
int32_t
tsdbCommitLastBlock
(
SCommitter
*
pCommitter
)
{
int32_t
code
=
0
;
SSttBlk
blockL
;
SBlockData
*
pBlockData
=
&
pCommitter
->
dWriter
.
bDatal
;
int32_t
tsdbWriteSttBlock
(
SDataFWriter
*
pWriter
,
SBlockData
*
pBlockData
,
SArray
*
aSttBlk
,
int8_t
cmprAlg
)
{
int32_t
code
=
0
;
SSttBlk
sstBlk
;
ASSERT
(
pBlockData
->
nRow
>
0
)
;
if
(
pBlockData
->
nRow
==
0
)
return
code
;
// info
blockL
.
suid
=
pBlockData
->
suid
;
blockL
.
nRow
=
pBlockData
->
nRow
;
blockL
.
minKey
=
TSKEY_MAX
;
blockL
.
maxKey
=
TSKEY_MIN
;
blockL
.
minVer
=
VERSION_MAX
;
blockL
.
maxVer
=
VERSION_MIN
;
sstBlk
.
suid
=
pBlockData
->
suid
;
sstBlk
.
nRow
=
pBlockData
->
nRow
;
sstBlk
.
minKey
=
TSKEY_MAX
;
sstBlk
.
maxKey
=
TSKEY_MIN
;
sstBlk
.
minVer
=
VERSION_MAX
;
sstBlk
.
maxVer
=
VERSION_MIN
;
for
(
int32_t
iRow
=
0
;
iRow
<
pBlockData
->
nRow
;
iRow
++
)
{
blockL
.
minKey
=
TMIN
(
blockL
.
minKey
,
pBlockData
->
aTSKEY
[
iRow
]);
blockL
.
maxKey
=
TMAX
(
blockL
.
maxKey
,
pBlockData
->
aTSKEY
[
iRow
]);
blockL
.
minVer
=
TMIN
(
blockL
.
minVer
,
pBlockData
->
aVersion
[
iRow
]);
blockL
.
maxVer
=
TMAX
(
blockL
.
maxVer
,
pBlockData
->
aVersion
[
iRow
]);
sstBlk
.
minKey
=
TMIN
(
sstBlk
.
minKey
,
pBlockData
->
aTSKEY
[
iRow
]);
sstBlk
.
maxKey
=
TMAX
(
sstBlk
.
maxKey
,
pBlockData
->
aTSKEY
[
iRow
]);
sstBlk
.
minVer
=
TMIN
(
sstBlk
.
minVer
,
pBlockData
->
aVersion
[
iRow
]);
sstBlk
.
maxVer
=
TMAX
(
sstBlk
.
maxVer
,
pBlockData
->
aVersion
[
iRow
]);
}
blockL
.
minUid
=
pBlockData
->
uid
?
pBlockData
->
uid
:
pBlockData
->
aUid
[
0
];
blockL
.
maxUid
=
pBlockData
->
uid
?
pBlockData
->
uid
:
pBlockData
->
aUid
[
pBlockData
->
nRow
-
1
];
sstBlk
.
minUid
=
pBlockData
->
uid
?
pBlockData
->
uid
:
pBlockData
->
aUid
[
0
];
sstBlk
.
maxUid
=
pBlockData
->
uid
?
pBlockData
->
uid
:
pBlockData
->
aUid
[
pBlockData
->
nRow
-
1
];
// write
code
=
tsdbWriteBlockData
(
p
Committer
->
dWriter
.
pWriter
,
pBlockData
,
&
blockL
.
bInfo
,
NULL
,
pCommitter
->
cmprAlg
,
1
);
code
=
tsdbWriteBlockData
(
p
Writer
,
pBlockData
,
&
sstBlk
.
bInfo
,
NULL
,
cmprAlg
,
1
);
if
(
code
)
goto
_err
;
// push SSttBlk
if
(
taosArrayPush
(
pCommitter
->
dWriter
.
aSttBlk
,
&
blockL
)
==
NULL
)
{
if
(
taosArrayPush
(
aSttBlk
,
&
sstBlk
)
==
NULL
)
{
code
=
TSDB_CODE_OUT_OF_MEMORY
;
goto
_err
;
}
...
...
@@ -647,7 +640,7 @@ static int32_t tsdbCommitLastBlock(SCommitter *pCommitter) {
return
code
;
_err:
tsdbError
(
"vgId:%d tsdb commit last block failed since %s"
,
TD_VID
(
p
Commit
ter
->
pTsdb
->
pVnode
),
tstrerror
(
code
));
tsdbError
(
"vgId:%d tsdb commit last block failed since %s"
,
TD_VID
(
p
Wri
ter
->
pTsdb
->
pVnode
),
tstrerror
(
code
));
return
code
;
}
...
...
@@ -692,7 +685,7 @@ static int32_t tsdbMoveCommitData(SCommitter *pCommitter, TABLEID toTable) {
while
(
pCommitter
->
dReader
.
pBlockIdx
&&
tTABLEIDCmprFn
(
pCommitter
->
dReader
.
pBlockIdx
,
&
toTable
)
<
0
)
{
SBlockIdx
blockIdx
=
*
pCommitter
->
dReader
.
pBlockIdx
;
code
=
tsdbWrite
Bloc
k
(
pCommitter
->
dWriter
.
pWriter
,
&
pCommitter
->
dReader
.
mBlock
,
&
blockIdx
);
code
=
tsdbWrite
DataBl
k
(
pCommitter
->
dWriter
.
pWriter
,
&
pCommitter
->
dReader
.
mBlock
,
&
blockIdx
);
if
(
code
)
goto
_err
;
if
(
taosArrayPush
(
pCommitter
->
dWriter
.
aBlockIdx
,
&
blockIdx
)
==
NULL
)
{
...
...
@@ -1046,7 +1039,7 @@ static int32_t tsdbNextCommitRow(SCommitter *pCommitter) {
break
;
}
}
}
else
if
(
pCommitter
->
pIter
->
type
==
LAS
T_DATA_ITER
)
{
// last file
}
else
if
(
pCommitter
->
pIter
->
type
==
ST
T_DATA_ITER
)
{
// last file
pIter
->
iRow
++
;
if
(
pIter
->
iRow
<
pIter
->
bData
.
nRow
)
{
pIter
->
r
.
uid
=
pIter
->
bData
.
uid
?
pIter
->
bData
.
uid
:
pIter
->
bData
.
aUid
[
pIter
->
iRow
];
...
...
@@ -1124,15 +1117,14 @@ static int32_t tsdbCommitAheadBlock(SCommitter *pCommitter, SDataBlk *pDataBlk)
}
if
(
pBlockData
->
nRow
>=
pCommitter
->
maxRow
)
{
code
=
tsdbCommitDataBlock
(
pCommitter
);
code
=
tsdbWriteDataBlock
(
pCommitter
->
dWriter
.
pWriter
,
pBlockData
,
&
pCommitter
->
dWriter
.
mBlock
,
pCommitter
->
cmprAlg
);
if
(
code
)
goto
_err
;
}
}
if
(
pBlockData
->
nRow
)
{
code
=
tsdbCommitDataBlock
(
pCommitter
);
if
(
code
)
goto
_err
;
}
code
=
tsdbWriteDataBlock
(
pCommitter
->
dWriter
.
pWriter
,
pBlockData
,
&
pCommitter
->
dWriter
.
mBlock
,
pCommitter
->
cmprAlg
);
if
(
code
)
goto
_err
;
return
code
;
...
...
@@ -1193,7 +1185,7 @@ static int32_t tsdbCommitMergeBlock(SCommitter *pCommitter, SDataBlk *pDataBlk)
}
if
(
pBDataW
->
nRow
>=
pCommitter
->
maxRow
)
{
code
=
tsdb
CommitDataBlock
(
pCommitter
);
code
=
tsdb
WriteDataBlock
(
pCommitter
->
dWriter
.
pWriter
,
pBDataW
,
&
pCommitter
->
dWriter
.
mBlock
,
pCommitter
->
cmprAlg
);
if
(
code
)
goto
_err
;
}
}
...
...
@@ -1210,15 +1202,13 @@ static int32_t tsdbCommitMergeBlock(SCommitter *pCommitter, SDataBlk *pDataBlk)
}
if
(
pBDataW
->
nRow
>=
pCommitter
->
maxRow
)
{
code
=
tsdb
CommitDataBlock
(
pCommitter
);
code
=
tsdb
WriteDataBlock
(
pCommitter
->
dWriter
.
pWriter
,
pBDataW
,
&
pCommitter
->
dWriter
.
mBlock
,
pCommitter
->
cmprAlg
);
if
(
code
)
goto
_err
;
}
}
if
(
pBDataW
->
nRow
)
{
code
=
tsdbCommitDataBlock
(
pCommitter
);
if
(
code
)
goto
_err
;
}
code
=
tsdbWriteDataBlock
(
pCommitter
->
dWriter
.
pWriter
,
pBDataW
,
&
pCommitter
->
dWriter
.
mBlock
,
pCommitter
->
cmprAlg
);
if
(
code
)
goto
_err
;
return
code
;
...
...
@@ -1306,10 +1296,8 @@ static int32_t tsdbInitLastBlockIfNeed(SCommitter *pCommitter, TABLEID id) {
SBlockData
*
pBDatal
=
&
pCommitter
->
dWriter
.
bDatal
;
if
(
pBDatal
->
suid
||
pBDatal
->
uid
)
{
if
((
pBDatal
->
suid
!=
id
.
suid
)
||
(
id
.
suid
==
0
))
{
if
(
pBDatal
->
nRow
)
{
code
=
tsdbCommitLastBlock
(
pCommitter
);
if
(
code
)
goto
_exit
;
}
code
=
tsdbWriteSttBlock
(
pCommitter
->
dWriter
.
pWriter
,
pBDatal
,
pCommitter
->
dWriter
.
aSttBlk
,
pCommitter
->
cmprAlg
);
if
(
code
)
goto
_exit
;
tBlockDataReset
(
pBDatal
);
}
}
...
...
@@ -1341,7 +1329,7 @@ static int32_t tsdbAppendLastBlock(SCommitter *pCommitter) {
if
(
code
)
goto
_err
;
if
(
pBDatal
->
nRow
>=
pCommitter
->
maxRow
)
{
code
=
tsdb
CommitLastBlock
(
pCommitter
);
code
=
tsdb
WriteSttBlock
(
pCommitter
->
dWriter
.
pWriter
,
pBDatal
,
pCommitter
->
dWriter
.
aSttBlk
,
pCommitter
->
cmprAlg
);
if
(
code
)
goto
_err
;
}
}
...
...
@@ -1393,10 +1381,11 @@ static int32_t tsdbCommitTableData(SCommitter *pCommitter, TABLEID id) {
if
(
pBData
->
nRow
>=
pCommitter
->
maxRow
)
{
if
(
pCommitter
->
toLastOnly
)
{
code
=
tsdb
CommitLastBlock
(
pCommitter
);
code
=
tsdb
WriteSttBlock
(
pCommitter
->
dWriter
.
pWriter
,
pBData
,
pCommitter
->
dWriter
.
aSttBlk
,
pCommitter
->
cmprAlg
);
if
(
code
)
goto
_err
;
}
else
{
code
=
tsdbCommitDataBlock
(
pCommitter
);
code
=
tsdbWriteDataBlock
(
pCommitter
->
dWriter
.
pWriter
,
pBData
,
&
pCommitter
->
dWriter
.
mBlock
,
pCommitter
->
cmprAlg
);
if
(
code
)
goto
_err
;
}
}
...
...
@@ -1404,7 +1393,7 @@ static int32_t tsdbCommitTableData(SCommitter *pCommitter, TABLEID id) {
if
(
!
pCommitter
->
toLastOnly
&&
pBData
->
nRow
)
{
if
(
pBData
->
nRow
>
pCommitter
->
minRow
)
{
code
=
tsdb
CommitDataBlock
(
pCommitter
);
code
=
tsdb
WriteDataBlock
(
pCommitter
->
dWriter
.
pWriter
,
pBData
,
&
pCommitter
->
dWriter
.
mBlock
,
pCommitter
->
cmprAlg
);
if
(
code
)
goto
_err
;
}
else
{
code
=
tsdbAppendLastBlock
(
pCommitter
);
...
...
@@ -1437,7 +1426,7 @@ static int32_t tsdbCommitFileDataImpl(SCommitter *pCommitter) {
tMapDataReset
(
&
pCommitter
->
dWriter
.
mBlock
);
// impl
code
=
tsdb
CommitterUpdateTableSchema
(
pCommitter
,
id
.
suid
,
id
.
uid
);
code
=
tsdb
UpdateTableSchema
(
pCommitter
->
pTsdb
->
pVnode
->
pMeta
,
id
.
suid
,
id
.
uid
,
&
pCommitter
->
skmTable
);
if
(
code
)
goto
_err
;
code
=
tBlockDataInit
(
&
pCommitter
->
dReader
.
bData
,
id
.
suid
,
id
.
uid
,
pCommitter
->
skmTable
.
pTSchema
);
if
(
code
)
goto
_err
;
...
...
@@ -1455,7 +1444,7 @@ static int32_t tsdbCommitFileDataImpl(SCommitter *pCommitter) {
// end
if
(
pCommitter
->
dWriter
.
mBlock
.
nItem
>
0
)
{
SBlockIdx
blockIdx
=
{.
suid
=
id
.
suid
,
.
uid
=
id
.
uid
};
code
=
tsdbWrite
Bloc
k
(
pCommitter
->
dWriter
.
pWriter
,
&
pCommitter
->
dWriter
.
mBlock
,
&
blockIdx
);
code
=
tsdbWrite
DataBl
k
(
pCommitter
->
dWriter
.
pWriter
,
&
pCommitter
->
dWriter
.
mBlock
,
&
blockIdx
);
if
(
code
)
goto
_err
;
if
(
taosArrayPush
(
pCommitter
->
dWriter
.
aBlockIdx
,
&
blockIdx
)
==
NULL
)
{
...
...
@@ -1470,10 +1459,9 @@ static int32_t tsdbCommitFileDataImpl(SCommitter *pCommitter) {
code
=
tsdbMoveCommitData
(
pCommitter
,
id
);
if
(
code
)
goto
_err
;
if
(
pCommitter
->
dWriter
.
bDatal
.
nRow
>
0
)
{
code
=
tsdbCommitLastBlock
(
pCommitter
);
if
(
code
)
goto
_err
;
}
code
=
tsdbWriteSttBlock
(
pCommitter
->
dWriter
.
pWriter
,
&
pCommitter
->
dWriter
.
bDatal
,
pCommitter
->
dWriter
.
aSttBlk
,
pCommitter
->
cmprAlg
);
if
(
code
)
goto
_err
;
return
code
;
...
...
source/dnode/vnode/src/tsdb/tsdbRead.c
浏览文件 @
856b50eb
...
...
@@ -16,7 +16,7 @@
#include "osDef.h"
#include "tsdb.h"
#define ASCENDING_TRAVERSE(o)
(o == TSDB_ORDER_ASC)
#define ASCENDING_TRAVERSE(o) (o == TSDB_ORDER_ASC)
typedef
enum
{
EXTERNAL_ROWS_PREV
=
0x1
,
...
...
@@ -83,11 +83,11 @@ typedef struct SBlockLoadSuppInfo {
}
SBlockLoadSuppInfo
;
typedef
struct
SLastBlockReader
{
STimeWindow
window
;
SVersionRange
verRange
;
int32_t
order
;
uint64_t
uid
;
SMergeTree
mergeTree
;
STimeWindow
window
;
SVersionRange
verRange
;
int32_t
order
;
uint64_t
uid
;
SMergeTree
mergeTree
;
SSttBlockLoadInfo
*
pInfo
;
}
SLastBlockReader
;
...
...
@@ -231,10 +231,10 @@ static SHashObj* createDataBlockScanInfo(STsdbReader* pTsdbReader, const STableK
STableBlockScanInfo
info
=
{.
lastKey
=
0
,
.
uid
=
idList
[
j
].
uid
};
if
(
ASCENDING_TRAVERSE
(
pTsdbReader
->
order
))
{
int64_t
skey
=
pTsdbReader
->
window
.
skey
;
info
.
lastKey
=
(
skey
>
INT64_MIN
)
?
(
skey
-
1
)
:
skey
;
info
.
lastKey
=
(
skey
>
INT64_MIN
)
?
(
skey
-
1
)
:
skey
;
}
else
{
int64_t
ekey
=
pTsdbReader
->
window
.
ekey
;
info
.
lastKey
=
(
ekey
<
INT64_MAX
)
?
(
ekey
+
1
)
:
ekey
;
info
.
lastKey
=
(
ekey
<
INT64_MAX
)
?
(
ekey
+
1
)
:
ekey
;
}
taosHashPut
(
pTableMap
,
&
info
.
uid
,
sizeof
(
uint64_t
),
&
info
,
sizeof
(
info
));
...
...
@@ -601,7 +601,7 @@ static int32_t doLoadFileBlock(STsdbReader* pReader, SArray* pIndexList, SBlockN
STableBlockScanInfo
*
pScanInfo
=
taosHashGet
(
pReader
->
status
.
pTableMap
,
&
pBlockIdx
->
uid
,
sizeof
(
int64_t
));
tMapDataReset
(
&
pScanInfo
->
mapData
);
tsdbRead
Bloc
k
(
pReader
->
pFileReader
,
pBlockIdx
,
&
pScanInfo
->
mapData
);
tsdbRead
DataBl
k
(
pReader
->
pFileReader
,
pBlockIdx
,
&
pScanInfo
->
mapData
);
sizeInDisk
+=
pScanInfo
->
mapData
.
nData
;
for
(
int32_t
j
=
0
;
j
<
pScanInfo
->
mapData
.
nItem
;
++
j
)
{
...
...
@@ -1933,7 +1933,7 @@ static bool initLastBlockReader(SLastBlockReader* pLBlockReader, STableBlockScan
initMemDataIterator
(
pScanInfo
,
pReader
);
pLBlockReader
->
uid
=
pScanInfo
->
uid
;
int32_t
step
=
ASCENDING_TRAVERSE
(
pLBlockReader
->
order
)
?
1
:
-
1
;
int32_t
step
=
ASCENDING_TRAVERSE
(
pLBlockReader
->
order
)
?
1
:
-
1
;
STimeWindow
w
=
pLBlockReader
->
window
;
if
(
ASCENDING_TRAVERSE
(
pLBlockReader
->
order
))
{
w
.
skey
=
pScanInfo
->
lastKey
+
step
;
...
...
@@ -3621,7 +3621,7 @@ int32_t tsdbReaderReset(STsdbReader* pReader, SQueryTableDataCond* pCond) {
initFilesetIterator
(
&
pReader
->
status
.
fileIter
,
pReader
->
pReadSnap
->
fs
.
aDFileSet
,
pReader
);
resetDataBlockIterator
(
&
pReader
->
status
.
blockIter
,
pReader
->
order
);
int64_t
ts
=
ASCENDING_TRAVERSE
(
pReader
->
order
)
?
pReader
->
window
.
skey
-
1
:
pReader
->
window
.
ekey
+
1
;
int64_t
ts
=
ASCENDING_TRAVERSE
(
pReader
->
order
)
?
pReader
->
window
.
skey
-
1
:
pReader
->
window
.
ekey
+
1
;
resetDataBlockScanInfo
(
pReader
->
status
.
pTableMap
,
ts
);
int32_t
code
=
0
;
...
...
source/dnode/vnode/src/tsdb/tsdbReaderWriter.c
浏览文件 @
856b50eb
...
...
@@ -418,21 +418,21 @@ _err:
return
code
;
}
int32_t
tsdbWrite
Block
(
SDataFWriter
*
pWriter
,
SMapData
*
mBloc
k
,
SBlockIdx
*
pBlockIdx
)
{
int32_t
tsdbWrite
DataBlk
(
SDataFWriter
*
pWriter
,
SMapData
*
mDataBl
k
,
SBlockIdx
*
pBlockIdx
)
{
int32_t
code
=
0
;
SHeadFile
*
pHeadFile
=
&
pWriter
->
fHead
;
int64_t
size
;
int64_t
n
;
ASSERT
(
m
Bloc
k
->
nItem
>
0
);
ASSERT
(
m
DataBl
k
->
nItem
>
0
);
// alloc
size
=
tPutMapData
(
NULL
,
m
Bloc
k
);
size
=
tPutMapData
(
NULL
,
m
DataBl
k
);
code
=
tRealloc
(
&
pWriter
->
aBuf
[
0
],
size
);
if
(
code
)
goto
_err
;
// build
n
=
tPutMapData
(
pWriter
->
aBuf
[
0
],
m
Bloc
k
);
n
=
tPutMapData
(
pWriter
->
aBuf
[
0
],
m
DataBl
k
);
// write
code
=
tsdbWriteFile
(
pWriter
->
pHeadFD
,
pHeadFile
->
size
,
pWriter
->
aBuf
[
0
],
size
);
...
...
@@ -446,7 +446,7 @@ int32_t tsdbWriteBlock(SDataFWriter *pWriter, SMapData *mBlock, SBlockIdx *pBloc
tsdbTrace
(
"vgId:%d, write block, file ID:%d commit ID:%d suid:%"
PRId64
" uid:%"
PRId64
" offset:%"
PRId64
" size:%"
PRId64
" nItem:%d"
,
TD_VID
(
pWriter
->
pTsdb
->
pVnode
),
pWriter
->
wSet
.
fid
,
pHeadFile
->
commitID
,
pBlockIdx
->
suid
,
pBlockIdx
->
uid
,
pBlockIdx
->
offset
,
pBlockIdx
->
size
,
m
Bloc
k
->
nItem
);
pBlockIdx
->
offset
,
pBlockIdx
->
size
,
m
DataBl
k
->
nItem
);
return
code
;
_err:
...
...
@@ -872,7 +872,7 @@ _err:
return
code
;
}
int32_t
tsdbRead
Block
(
SDataFReader
*
pReader
,
SBlockIdx
*
pBlockIdx
,
SMapData
*
mBloc
k
)
{
int32_t
tsdbRead
DataBlk
(
SDataFReader
*
pReader
,
SBlockIdx
*
pBlockIdx
,
SMapData
*
mDataBl
k
)
{
int32_t
code
=
0
;
int64_t
offset
=
pBlockIdx
->
offset
;
int64_t
size
=
pBlockIdx
->
size
;
...
...
@@ -886,7 +886,7 @@ int32_t tsdbReadBlock(SDataFReader *pReader, SBlockIdx *pBlockIdx, SMapData *mBl
if
(
code
)
goto
_err
;
// decode
int64_t
n
=
tGetMapData
(
pReader
->
aBuf
[
0
],
m
Bloc
k
);
int64_t
n
=
tGetMapData
(
pReader
->
aBuf
[
0
],
m
DataBl
k
);
if
(
n
<
0
)
{
code
=
TSDB_CODE_OUT_OF_MEMORY
;
goto
_err
;
...
...
@@ -1053,6 +1053,29 @@ _err:
return
code
;
}
int32_t
tsdbReadDataBlockEx
(
SDataFReader
*
pReader
,
SDataBlk
*
pDataBlk
,
SBlockData
*
pBlockData
)
{
int32_t
code
=
0
;
SBlockInfo
*
pBlockInfo
=
&
pDataBlk
->
aSubBlock
[
0
];
// alloc
code
=
tRealloc
(
&
pReader
->
aBuf
[
0
],
pBlockInfo
->
szBlock
);
if
(
code
)
goto
_err
;
// read
code
=
tsdbReadFile
(
pReader
->
pDataFD
,
pBlockInfo
->
offset
,
pReader
->
aBuf
[
0
],
pBlockInfo
->
szBlock
);
if
(
code
)
goto
_err
;
// decmpr
code
=
tDecmprBlockData
(
pReader
->
aBuf
[
0
],
pBlockInfo
->
szBlock
,
pBlockData
,
&
pReader
->
aBuf
[
1
]);
if
(
code
)
goto
_err
;
return
code
;
_err:
tsdbError
(
"vgId:%d tsdb read data block ex failed since %s"
,
TD_VID
(
pReader
->
pTsdb
->
pVnode
),
tstrerror
(
code
));
return
code
;
}
int32_t
tsdbReadDataBlock
(
SDataFReader
*
pReader
,
SDataBlk
*
pDataBlk
,
SBlockData
*
pBlockData
)
{
int32_t
code
=
0
;
...
...
@@ -1147,8 +1170,8 @@ int32_t tsdbDelFWriterOpen(SDelFWriter **ppWriter, SDelFile *pFile, STsdb *pTsdb
pDelFWriter
->
fDel
=
*
pFile
;
tsdbDelFileName
(
pTsdb
,
pFile
,
fname
);
code
=
tsdbOpenFile
(
fname
,
TSDB_DEFAULT_PAGE_SIZE
,
TD_FILE_READ
|
TD_FILE_WRITE
|
TD_FILE_CREATE
,
&
pDelFWriter
->
pWriteH
);
int32_t
flag
=
TD_FILE_READ
|
TD_FILE_WRITE
|
TD_FILE_CREATE
;
code
=
tsdbOpenFile
(
fname
,
TSDB_DEFAULT_PAGE_SIZE
,
flag
,
&
pDelFWriter
->
pWriteH
);
if
(
code
)
goto
_err
;
// update header
...
...
source/dnode/vnode/src/tsdb/tsdbSnapshot.c
浏览文件 @
856b50eb
此差异已折叠。
点击以展开。
source/dnode/vnode/src/vnd/vnodeSnapshot.c
浏览文件 @
856b50eb
...
...
@@ -354,7 +354,8 @@ int32_t vnodeSnapWrite(SVSnapWriter *pWriter, uint8_t *pData, uint32_t nData) {
code
=
metaSnapWrite
(
pWriter
->
pMetaSnapWriter
,
pData
,
nData
);
if
(
code
)
goto
_err
;
}
break
;
case
SNAP_DATA_TSDB
:
{
case
SNAP_DATA_TSDB
:
case
SNAP_DATA_DEL
:
{
// tsdb
if
(
pWriter
->
pTsdbSnapWriter
==
NULL
)
{
code
=
tsdbSnapWriterOpen
(
pVnode
->
pTsdb
,
pWriter
->
sver
,
pWriter
->
ever
,
&
pWriter
->
pTsdbSnapWriter
);
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录