Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
e99b33ed
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看板
提交
e99b33ed
编写于
6月 01, 2023
作者:
H
Hongze Cheng
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
more code
上级
bdc9fc47
变更
10
隐藏空白更改
内联
并排
Showing
10 changed file
with
166 addition
and
141 deletion
+166
-141
source/dnode/vnode/src/tsdb/dev/inc/tsdbFS.h
source/dnode/vnode/src/tsdb/dev/inc/tsdbFS.h
+1
-1
source/dnode/vnode/src/tsdb/dev/inc/tsdbFSet.h
source/dnode/vnode/src/tsdb/dev/inc/tsdbFSet.h
+1
-1
source/dnode/vnode/src/tsdb/dev/inc/tsdbIter.h
source/dnode/vnode/src/tsdb/dev/inc/tsdbIter.h
+2
-2
source/dnode/vnode/src/tsdb/dev/inc/tsdbSttFileRW.h
source/dnode/vnode/src/tsdb/dev/inc/tsdbSttFileRW.h
+0
-2
source/dnode/vnode/src/tsdb/dev/tsdbCommit.c
source/dnode/vnode/src/tsdb/dev/tsdbCommit.c
+140
-120
source/dnode/vnode/src/tsdb/dev/tsdbFS.c
source/dnode/vnode/src/tsdb/dev/tsdbFS.c
+5
-3
source/dnode/vnode/src/tsdb/dev/tsdbFSet.c
source/dnode/vnode/src/tsdb/dev/tsdbFSet.c
+6
-6
source/dnode/vnode/src/tsdb/dev/tsdbIter.c
source/dnode/vnode/src/tsdb/dev/tsdbIter.c
+2
-2
source/dnode/vnode/src/tsdb/dev/tsdbMerge.c
source/dnode/vnode/src/tsdb/dev/tsdbMerge.c
+4
-4
source/dnode/vnode/src/tsdb/dev/tsdbSttFileRW.c
source/dnode/vnode/src/tsdb/dev/tsdbSttFileRW.c
+5
-0
未找到文件。
source/dnode/vnode/src/tsdb/dev/inc/tsdbFS.h
浏览文件 @
e99b33ed
...
...
@@ -39,7 +39,7 @@ int32_t tsdbCloseFS(STFileSystem **fs);
int32_t
tsdbFSCreateCopySnapshot
(
STFileSystem
*
fs
,
TFileSetArray
**
fsetArr
);
int32_t
tsdbFSDestroyCopySnapshot
(
TFileSetArray
**
fsetArr
);
// txn
int
32_t
tsdbFSAllocEid
(
STFileSystem
*
fs
,
int64_t
*
eid
);
int
64_t
tsdbFSAllocEid
(
STFileSystem
*
fs
);
int32_t
tsdbFSEditBegin
(
STFileSystem
*
fs
,
const
TFileOpArray
*
opArray
,
EFEditT
etype
);
int32_t
tsdbFSEditCommit
(
STFileSystem
*
fs
);
int32_t
tsdbFSEditAbort
(
STFileSystem
*
fs
);
...
...
source/dnode/vnode/src/tsdb/dev/inc/tsdbFSet.h
浏览文件 @
e99b33ed
...
...
@@ -52,7 +52,7 @@ int32_t tsdbTFileSetApplyEdit(STsdb *pTsdb, const STFileSet *fset1, STFileSet *f
// max commit id
int64_t
tsdbTFileSetMaxCid
(
const
STFileSet
*
fset
);
// get
SSttLvl
*
tsdbTFileSetGetLvl
(
STFileSet
*
fset
,
int32_t
level
);
SSttLvl
*
tsdbTFileSetGet
Stt
Lvl
(
STFileSet
*
fset
,
int32_t
level
);
// is empty
bool
tsdbTFileSetIsEmpty
(
const
STFileSet
*
fset
);
...
...
source/dnode/vnode/src/tsdb/dev/inc/tsdbIter.h
浏览文件 @
e99b33ed
...
...
@@ -53,8 +53,8 @@ int32_t tsdbIterClose(STsdbIter **iter);
int32_t
tsdbIterNext
(
STsdbIter
*
iter
);
// SIterMerger ===============
int32_t
tsdbIterMerger
Init
(
const
TTsdbIterArray
*
iterArray
,
SIterMerger
**
merger
);
int32_t
tsdbIterMergerCl
ear
(
SIterMerger
**
merger
);
int32_t
tsdbIterMerger
Open
(
const
TTsdbIterArray
*
iterArray
,
SIterMerger
**
merger
);
int32_t
tsdbIterMergerCl
ose
(
SIterMerger
**
merger
);
int32_t
tsdbIterMergerNext
(
SIterMerger
*
merger
);
SRowInfo
*
tsdbIterMergerGet
(
SIterMerger
*
merger
);
int32_t
tsdbIterMergerSkipTableData
(
SIterMerger
*
merger
,
const
TABLEID
*
tbid
);
...
...
source/dnode/vnode/src/tsdb/dev/inc/tsdbSttFileRW.h
浏览文件 @
e99b33ed
...
...
@@ -52,8 +52,6 @@ struct SSttFileReaderConfig {
STsdb
*
tsdb
;
int32_t
szPage
;
STFile
file
[
1
];
SSkmInfo
*
skmTb
;
SSkmInfo
*
skmRow
;
uint8_t
**
bufArr
;
};
...
...
source/dnode/vnode/src/tsdb/dev/tsdbCommit.c
浏览文件 @
e99b33ed
...
...
@@ -17,16 +17,20 @@
// extern dependencies
typedef
struct
{
STsdb
*
tsdb
;
STsdb
*
tsdb
;
TFileSetArray
*
fsetArr
;
int32_t
minutes
;
int8_t
precision
;
int32_t
minRow
;
int32_t
maxRow
;
int8_t
cmprAlg
;
int8_t
sttTrigger
;
int32_t
sttTrigger
;
int32_t
szPage
;
int64_t
compactVersion
;
struct
{
int64_t
cid
;
int64_t
now
;
TSKEY
nextKey
;
int32_t
fid
;
...
...
@@ -37,111 +41,115 @@ typedef struct {
TABLEID
tbid
[
1
];
}
ctx
[
1
];
int64_t
eid
;
// edit id
TFileOpArray
fopArray
[
1
];
TTsdbIterArray
iterArray
[
1
];
SIterMerger
*
iterMerger
;
// writer
SDataFileWriter
*
dataWriter
;
SSttFileWriter
*
sttWriter
;
SDataFileWriter
*
dataWriter
;
}
SCommitter2
;
static
int32_t
tsdbCommitOpenNewSttWriter
(
SCommitter2
*
pC
ommitter
)
{
static
int32_t
tsdbCommitOpenNewSttWriter
(
SCommitter2
*
c
ommitter
)
{
int32_t
code
=
0
;
int32_t
lino
=
0
;
STsdb
*
pTsdb
=
pCommitter
->
tsdb
;
SVnode
*
pVnode
=
pTsdb
->
pVnode
;
int32_t
vid
=
TD_VID
(
pVnode
);
SSttFileWriterConfig
config
[
1
];
SDiskID
did
[
1
];
if
(
tfsAllocDisk
(
pVnode
->
pTfs
,
pCommitter
->
ctx
->
expLevel
,
did
)
<
0
)
{
SDiskID
did
[
1
];
if
(
tfsAllocDisk
(
committer
->
tsdb
->
pVnode
->
pTfs
,
committer
->
ctx
->
expLevel
,
did
)
<
0
)
{
code
=
TSDB_CODE_FS_NO_VALID_DISK
;
TSDB_CHECK_CODE
(
code
,
lino
,
_exit
);
}
config
->
tsdb
=
pTsdb
;
config
->
maxRow
=
pCommitter
->
maxRow
;
config
->
szPage
=
pVnode
->
config
.
tsdbPageSize
;
config
->
cmprAlg
=
pCommitter
->
cmprAlg
;
config
->
skmTb
=
NULL
;
config
->
skmRow
=
NULL
;
config
->
aBuf
=
NULL
;
config
->
file
.
type
=
TSDB_FTYPE_STT
;
config
->
file
.
did
=
did
[
0
];
config
->
file
.
fid
=
pCommitter
->
ctx
->
fid
;
config
->
file
.
cid
=
pCommitter
->
eid
;
config
->
file
.
size
=
0
;
config
->
file
.
stt
->
level
=
0
;
config
->
file
.
stt
->
nseg
=
0
;
code
=
tsdbSttFileWriterOpen
(
config
,
&
pC
ommitter
->
sttWriter
);
SSttFileWriterConfig
config
[
1
]
=
{{
.
tsdb
=
committer
->
tsdb
,
.
maxRow
=
committer
->
maxRow
,
.
szPage
=
committer
->
tsdb
->
pVnode
->
config
.
tsdbPageSize
,
.
cmprAlg
=
committer
->
cmprAlg
,
.
compactVersion
=
committer
->
compactVersion
,
.
file
=
{
.
type
=
TSDB_FTYPE_STT
,
.
did
=
did
[
0
],
.
fid
=
committer
->
ctx
->
fid
,
.
cid
=
committer
->
ctx
->
cid
,
},
}}
;
code
=
tsdbSttFileWriterOpen
(
config
,
&
c
ommitter
->
sttWriter
);
TSDB_CHECK_CODE
(
code
,
lino
,
_exit
);
_exit:
if
(
code
)
{
tsdbError
(
"vgId:%d %s failed at line %d since %s"
,
vid
,
__func__
,
lino
,
tstrerror
(
code
)
);
TSDB_ERROR_LOG
(
TD_VID
(
committer
->
tsdb
->
pVnode
),
lino
,
code
);
}
else
{
tsdbDebug
(
"vgId:%d %s success"
,
vid
,
__func__
);
tsdbDebug
(
"vgId:%d %s success"
,
TD_VID
(
committer
->
tsdb
->
pVnode
)
,
__func__
);
}
return
code
;
}
static
int32_t
tsdbCommitOpenExistSttWriter
(
SCommitter2
*
pCommitter
,
const
STFile
*
pFile
)
{
static
int32_t
tsdbCommitOpenExistSttWriter
(
SCommitter2
*
committer
,
const
STFile
*
f
)
{
int32_t
code
=
0
;
int32_t
lino
=
0
;
STsdb
*
pTsdb
=
pCommitter
->
tsdb
;
SVnode
*
pVnode
=
pTsdb
->
pVnode
;
int32_t
vid
=
TD_VID
(
pVnode
);
SSttFileWriterConfig
config
=
{
//
.
tsdb
=
pTsdb
,
.
maxRow
=
pCommitter
->
maxRow
,
.
szPage
=
pVnode
->
config
.
tsdbPageSize
,
.
cmprAlg
=
pCommitter
->
cmprAlg
,
.
skmTb
=
NULL
,
.
skmRow
=
NULL
,
.
aBuf
=
NULL
,
.
file
=
*
pFile
//
};
code
=
tsdbSttFileWriterOpen
(
&
config
,
&
pCommitter
->
sttWriter
);
SSttFileWriterConfig
config
[
1
]
=
{{
.
tsdb
=
committer
->
tsdb
,
.
maxRow
=
committer
->
maxRow
,
.
szPage
=
committer
->
szPage
,
.
cmprAlg
=
committer
->
cmprAlg
,
.
compactVersion
=
committer
->
compactVersion
,
.
file
=
f
[
0
],
}};
code
=
tsdbSttFileWriterOpen
(
config
,
&
committer
->
sttWriter
);
TSDB_CHECK_CODE
(
code
,
lino
,
_exit
);
_exit:
if
(
code
)
{
tsdbError
(
"vgId:%d %s failed at line %d since %s"
,
vid
,
__func__
,
lino
,
tstrerror
(
code
)
);
TSDB_ERROR_LOG
(
TD_VID
(
committer
->
tsdb
->
pVnode
),
lino
,
code
);
}
else
{
tsdbDebug
(
"vgId:%d %s success"
,
vid
,
__func__
);
tsdbDebug
(
"vgId:%d %s success"
,
TD_VID
(
committer
->
tsdb
->
pVnode
)
,
__func__
);
}
return
code
;
}
static
int32_t
tsdbCommitOpenWriter
(
SCommitter2
*
committer
)
{
int32_t
code
=
0
;
int32_t
lino
=
0
;
// stt writer
if
(
!
committer
->
ctx
->
fset
)
{
return
tsdbCommitOpenNewSttWriter
(
committer
);
code
=
tsdbCommitOpenNewSttWriter
(
committer
);
TSDB_CHECK_CODE
(
code
,
lino
,
_exit
);
}
const
SSttLvl
*
lvl0
=
tsdbTFileSetGetLvl
(
committer
->
ctx
->
fset
,
0
);
if
(
lvl0
==
NULL
)
{
return
tsdbCommitOpenNewSttWriter
(
committer
);
const
SSttLvl
*
lvl0
=
tsdbTFileSetGetSttLvl
(
committer
->
ctx
->
fset
,
0
);
if
(
lvl0
==
NULL
||
TARRAY2_SIZE
(
lvl0
->
fobjArr
)
==
0
)
{
code
=
tsdbCommitOpenNewSttWriter
(
committer
);
TSDB_CHECK_CODE
(
code
,
lino
,
_exit
);
}
ASSERT
(
TARRAY2_SIZE
(
lvl0
->
fobjArr
)
>
0
);
STFileObj
*
fobj
=
TARRAY2_LAST
(
lvl0
->
fobjArr
);
if
(
fobj
->
f
->
stt
->
nseg
>=
committer
->
sttTrigger
)
{
return
tsdbCommitOpenNewSttWriter
(
committer
);
code
=
tsdbCommitOpenNewSttWriter
(
committer
);
TSDB_CHECK_CODE
(
code
,
lino
,
_exit
);
}
else
{
return
tsdbCommitOpenExistSttWriter
(
committer
,
fobj
->
f
);
code
=
tsdbCommitOpenExistSttWriter
(
committer
,
fobj
->
f
);
TSDB_CHECK_CODE
(
code
,
lino
,
_exit
);
}
}
static
int32_t
tsdbCommitTSRow
(
SCommitter2
*
committer
,
SRowInfo
*
row
)
{
return
tsdbSttFileWriteTSData
(
committer
->
sttWriter
,
row
);
// data writer
if
(
0
)
{
// TODO
}
_exit:
if
(
code
)
{
TSDB_ERROR_LOG
(
TD_VID
(
committer
->
tsdb
->
pVnode
),
lino
,
code
);
}
return
code
;
}
static
int32_t
tsdbCommitWriteDelData
(
SCommitter2
*
pC
ommitter
,
int64_t
suid
,
int64_t
uid
,
int64_t
version
,
int64_t
sKey
,
static
int32_t
tsdbCommitWriteDelData
(
SCommitter2
*
c
ommitter
,
int64_t
suid
,
int64_t
uid
,
int64_t
version
,
int64_t
sKey
,
int64_t
eKey
)
{
int32_t
code
=
0
;
// TODO
...
...
@@ -174,7 +182,7 @@ static int32_t tsdbCommitTSData(SCommitter2 *committer) {
code
=
TARRAY2_APPEND
(
committer
->
iterArray
,
iter
);
TSDB_CHECK_CODE
(
code
,
lino
,
_exit
);
code
=
tsdbIterMerger
Init
(
committer
->
iterArray
,
&
committer
->
iterMerger
);
code
=
tsdbIterMerger
Open
(
committer
->
iterArray
,
&
committer
->
iterMerger
);
TSDB_CHECK_CODE
(
code
,
lino
,
_exit
);
// loop iter
...
...
@@ -183,7 +191,7 @@ static int32_t tsdbCommitTSData(SCommitter2 *committer) {
committer
->
ctx
->
tbid
->
suid
=
row
->
suid
;
committer
->
ctx
->
tbid
->
uid
=
row
->
uid
;
// Ignore
deleted tabl
e
// Ignore
table of obsolescenc
e
SMetaInfo
info
[
1
];
if
(
metaGetInfo
(
committer
->
tsdb
->
pVnode
->
pMeta
,
row
->
uid
,
info
,
NULL
)
!=
0
)
{
code
=
tsdbIterMergerSkipTableData
(
committer
->
iterMerger
,
committer
->
ctx
->
tbid
);
...
...
@@ -195,11 +203,10 @@ static int32_t tsdbCommitTSData(SCommitter2 *committer) {
TSKEY
ts
=
TSDBROW_TS
(
&
row
->
row
);
if
(
ts
>
committer
->
ctx
->
maxKey
)
{
committer
->
ctx
->
nextKey
=
TMIN
(
committer
->
ctx
->
nextKey
,
ts
);
code
=
tsdbIterMergerSkipTableData
(
committer
->
iterMerger
,
committer
->
ctx
->
tbid
);
TSDB_CHECK_CODE
(
code
,
lino
,
_exit
);
}
else
{
code
=
tsdb
CommitTSRow
(
commit
ter
,
row
);
code
=
tsdb
SttFileWriteTSData
(
committer
->
sttWri
ter
,
row
);
TSDB_CHECK_CODE
(
code
,
lino
,
_exit
);
code
=
tsdbIterMergerNext
(
committer
->
iterMerger
);
...
...
@@ -216,7 +223,7 @@ _exit:
return
code
;
}
static
int32_t
tsdbCommitDelData
(
SCommitter2
*
pC
ommitter
)
{
static
int32_t
tsdbCommitDelData
(
SCommitter2
*
c
ommitter
)
{
int32_t
code
=
0
;
int32_t
lino
;
...
...
@@ -226,23 +233,23 @@ static int32_t tsdbCommitDelData(SCommitter2 *pCommitter) {
ASSERTS(0, "TODO: Not implemented yet");
int64_t nDel = 0;
SMemTable *pMem =
pC
ommitter->tsdb->imem;
SMemTable *pMem =
c
ommitter->tsdb->imem;
if (pMem->nDel == 0) { // no del data
goto _exit;
}
for (int32_t iTbData = 0; iTbData < taosArrayGetSize(
pC
ommitter->aTbDataP); iTbData++) {
STbData *pTbData = (STbData *)taosArrayGetP(
pC
ommitter->aTbDataP, iTbData);
for (int32_t iTbData = 0; iTbData < taosArrayGetSize(
c
ommitter->aTbDataP); iTbData++) {
STbData *pTbData = (STbData *)taosArrayGetP(
c
ommitter->aTbDataP, iTbData);
for (SDelData *pDelData = pTbData->pHead; pDelData; pDelData = pDelData->pNext) {
if (pDelData->eKey <
pC
ommitter->ctx->minKey) continue;
if (pDelData->sKey >
pC
ommitter->ctx->maxKey) {
pCommitter->ctx->nextKey = TMIN(pC
ommitter->ctx->nextKey, pDelData->sKey);
if (pDelData->eKey <
c
ommitter->ctx->minKey) continue;
if (pDelData->sKey >
c
ommitter->ctx->maxKey) {
committer->ctx->nextKey = TMIN(c
ommitter->ctx->nextKey, pDelData->sKey);
continue;
}
code = tsdbCommitWriteDelData(
pC
ommitter, pTbData->suid, pTbData->uid, pDelData->version,
code = tsdbCommitWriteDelData(
c
ommitter, pTbData->suid, pTbData->uid, pDelData->version,
pDelData->sKey /* TODO */, pDelData->eKey /* TODO */);
TSDB_CHECK_CODE(code, lino, _exit);
}
...
...
@@ -250,9 +257,9 @@ static int32_t tsdbCommitDelData(SCommitter2 *pCommitter) {
_exit:
if (code) {
tsdbError("vgId:%d failed at line %d since %s", TD_VID(
pC
ommitter->tsdb->pVnode), lino, tstrerror(code));
tsdbError("vgId:%d failed at line %d since %s", TD_VID(
c
ommitter->tsdb->pVnode), lino, tstrerror(code));
} else {
tsdbDebug("vgId:%d %s done, fid:%d nDel:%" PRId64, TD_VID(
pCommitter->tsdb->pVnode), __func__, pC
ommitter->ctx->fid,
tsdbDebug("vgId:%d %s done, fid:%d nDel:%" PRId64, TD_VID(
committer->tsdb->pVnode), __func__, c
ommitter->ctx->fid,
pMem->nDel);
}
return code;
...
...
@@ -266,17 +273,26 @@ static int32_t tsdbCommitFileSetBegin(SCommitter2 *committer) {
int32_t
vid
=
TD_VID
(
tsdb
->
pVnode
);
committer
->
ctx
->
fid
=
tsdbKeyFid
(
committer
->
ctx
->
nextKey
,
committer
->
minutes
,
committer
->
precision
);
committer
->
ctx
->
expLevel
=
tsdbFidLevel
(
committer
->
ctx
->
fid
,
&
tsdb
->
keepCfg
,
committer
->
ctx
->
now
);
tsdbFidKeyRange
(
committer
->
ctx
->
fid
,
committer
->
minutes
,
committer
->
precision
,
&
committer
->
ctx
->
minKey
,
&
committer
->
ctx
->
maxKey
);
committer
->
ctx
->
expLevel
=
tsdbFidLevel
(
committer
->
ctx
->
fid
,
&
tsdb
->
keepCfg
,
committer
->
ctx
->
now
);
committer
->
ctx
->
nextKey
=
TSKEY_MAX
;
STFileSet
fset
=
{.
fid
=
committer
->
ctx
->
fid
};
committer
->
ctx
->
fset
=
&
fset
;
committer
->
ctx
->
fset
=
TARRAY2_SEARCH_EX
(
committer
->
fsetArr
,
&
committer
->
ctx
->
fset
,
tsdbTFileSetCmprFn
,
TD_EQ
);
committer
->
ctx
->
tbid
->
suid
=
0
;
committer
->
ctx
->
tbid
->
uid
=
0
;
// TODO: use a thread safe function to get fset
tsdbFSGetFSet
(
tsdb
->
pFS
,
committer
->
ctx
->
fid
,
&
committer
->
ctx
->
fset
);
ASSERT
(
TARRAY2_SIZE
(
committer
->
iterArray
)
==
0
);
ASSERT
(
committer
->
iterMerger
==
NULL
);
ASSERT
(
committer
->
sttWriter
==
NULL
);
ASSERT
(
committer
->
dataWriter
==
NULL
);
code
=
tsdbCommitOpenWriter
(
committer
);
TSDB_CHECK_CODE
(
code
,
lino
,
_exit
);
// reset nextKey
committer
->
ctx
->
nextKey
=
TSKEY_MAX
;
_exit:
if
(
code
)
{
TSDB_ERROR_LOG
(
vid
,
lino
,
code
);
...
...
@@ -287,27 +303,27 @@ _exit:
return
0
;
}
static
int32_t
tsdbCommitFileSetEnd
(
SCommitter2
*
pC
ommitter
)
{
static
int32_t
tsdbCommitFileSetEnd
(
SCommitter2
*
c
ommitter
)
{
int32_t
code
=
0
;
int32_t
lino
=
0
;
int32_t
vid
=
TD_VID
(
pCommitter
->
tsdb
->
pVnode
);
if
(
pCommitter
->
sttWriter
==
NULL
)
return
0
;
STFileOp
op
;
code
=
tsdbSttFileWriterClose
(
&
pCommitter
->
sttWriter
,
0
,
&
op
);
STFileOp
op
[
1
];
code
=
tsdbSttFileWriterClose
(
&
committer
->
sttWriter
,
0
,
op
);
TSDB_CHECK_CODE
(
code
,
lino
,
_exit
);
if
(
op
.
optype
!=
TSDB_FOP_NONE
)
{
code
=
TARRAY2_APPEND
(
pC
ommitter
->
fopArray
,
op
);
if
(
op
->
optype
!=
TSDB_FOP_NONE
)
{
code
=
TARRAY2_APPEND
_PTR
(
c
ommitter
->
fopArray
,
op
);
TSDB_CHECK_CODE
(
code
,
lino
,
_exit
);
}
tsdbIterMergerClose
(
&
committer
->
iterMerger
);
TARRAY2_CLEAR
(
committer
->
iterArray
,
tsdbIterClose
);
_exit:
if
(
code
)
{
tsdbError
(
"vgId:%d failed at line %d since %s"
,
vid
,
lino
,
tstrerror
(
code
)
);
TSDB_ERROR_LOG
(
TD_VID
(
committer
->
tsdb
->
pVnode
),
lino
,
code
);
}
else
{
tsdbDebug
(
"vgId:%d %s done, fid:%d"
,
vid
,
__func__
,
pC
ommitter
->
ctx
->
fid
);
tsdbDebug
(
"vgId:%d %s done, fid:%d"
,
TD_VID
(
committer
->
tsdb
->
pVnode
),
__func__
,
c
ommitter
->
ctx
->
fid
);
}
return
code
;
}
...
...
@@ -349,20 +365,24 @@ static int32_t tsdbOpenCommitter(STsdb *tsdb, SCommitInfo *info, SCommitter2 *co
memset
(
committer
,
0
,
sizeof
(
committer
[
0
]));
committer
->
tsdb
=
tsdb
;
code
=
tsdbFSCreateCopySnapshot
(
tsdb
->
pFS
,
&
committer
->
fsetArr
);
TSDB_CHECK_CODE
(
code
,
lino
,
_exit
);
committer
->
minutes
=
tsdb
->
keepCfg
.
days
;
committer
->
precision
=
tsdb
->
keepCfg
.
precision
;
committer
->
minRow
=
info
->
info
.
config
.
tsdbCfg
.
minRows
;
committer
->
maxRow
=
info
->
info
.
config
.
tsdbCfg
.
maxRows
;
committer
->
cmprAlg
=
info
->
info
.
config
.
tsdbCfg
.
compression
;
committer
->
sttTrigger
=
info
->
info
.
config
.
sttTrigger
;
committer
->
compactVersion
=
INT64_MAX
;
// TODO: use a function
TARRAY2_INIT
(
committer
->
fopArray
);
tsdbFSAllocEid
(
tsdb
->
pFS
,
&
committer
->
eid
);
committer
->
szPage
=
info
->
info
.
config
.
tsdbPageSize
;
committer
->
compactVersion
=
INT64_MAX
;
committer
->
ctx
->
cid
=
tsdbFSAllocEid
(
tsdb
->
pFS
);
committer
->
ctx
->
now
=
taosGetTimestampSec
();
committer
->
ctx
->
nextKey
=
tsdb
->
imem
->
minKey
;
// TODO
TARRAY2_INIT
(
committer
->
fopArray
);
_exit:
if
(
code
)
{
TSDB_ERROR_LOG
(
vid
,
lino
,
code
);
...
...
@@ -372,28 +392,32 @@ _exit:
return
code
;
}
static
int32_t
tsdbCloseCommitter
(
SCommitter2
*
pCommi
ter
,
int32_t
eno
)
{
static
int32_t
tsdbCloseCommitter
(
SCommitter2
*
commit
ter
,
int32_t
eno
)
{
int32_t
code
=
0
;
int32_t
lino
=
0
;
int32_t
vid
=
TD_VID
(
pCommi
ter
->
tsdb
->
pVnode
);
int32_t
vid
=
TD_VID
(
commit
ter
->
tsdb
->
pVnode
);
if
(
eno
==
0
)
{
code
=
tsdbFSEditBegin
(
pCommiter
->
tsdb
->
pFS
,
pCommi
ter
->
fopArray
,
TSDB_FEDIT_COMMIT
);
code
=
tsdbFSEditBegin
(
committer
->
tsdb
->
pFS
,
commit
ter
->
fopArray
,
TSDB_FEDIT_COMMIT
);
TSDB_CHECK_CODE
(
code
,
lino
,
_exit
);
}
else
{
// TODO
ASSERT
(
0
);
}
ASSERT
(
pCommiter
->
sttWriter
==
NULL
);
TARRAY2_FREE
(
pCommiter
->
fopArray
);
ASSERT
(
committer
->
dataWriter
==
NULL
);
ASSERT
(
committer
->
sttWriter
==
NULL
);
ASSERT
(
committer
->
iterMerger
==
NULL
);
TARRAY2_FREE
(
committer
->
iterArray
);
TARRAY2_FREE
(
committer
->
fopArray
);
tsdbFSDestroyCopySnapshot
(
&
committer
->
fsetArr
);
_exit:
if
(
code
)
{
tsdbError
(
"vgId:%d %s failed at line %d since %s, eid:%"
PRId64
,
vid
,
__func__
,
lino
,
tstrerror
(
code
),
pCommiter
->
e
id
);
committer
->
ctx
->
c
id
);
}
else
{
tsdbDebug
(
"vgId:%d %s done, eid:%"
PRId64
,
vid
,
__func__
,
pCommiter
->
e
id
);
tsdbDebug
(
"vgId:%d %s done, eid:%"
PRId64
,
vid
,
__func__
,
committer
->
ctx
->
c
id
);
}
return
code
;
}
...
...
@@ -413,15 +437,15 @@ int32_t tsdbCommitBegin(STsdb *tsdb, SCommitInfo *info) {
int32_t
code
=
0
;
int32_t
lino
=
0
;
int32_t
vid
=
TD_VID
(
tsdb
->
pVnode
);
SMemTable
*
memt
=
tsdb
->
imem
;
int64_t
nRow
=
memt
->
nRow
;
int64_t
nDel
=
memt
->
nDel
;
SMemTable
*
imem
=
tsdb
->
imem
;
int64_t
nRow
=
imem
->
nRow
;
int64_t
nDel
=
imem
->
nDel
;
if
(
!
nRow
&&
!
nDel
)
{
taosThreadRwlockWrlock
(
&
tsdb
->
rwLock
);
tsdb
->
imem
=
NULL
;
taosThreadRwlockUnlock
(
&
tsdb
->
rwLock
);
tsdbUnrefMemTable
(
memt
,
NULL
,
true
);
tsdbUnrefMemTable
(
imem
,
NULL
,
true
);
}
else
{
SCommitter2
committer
[
1
];
...
...
@@ -430,10 +454,7 @@ int32_t tsdbCommitBegin(STsdb *tsdb, SCommitInfo *info) {
while
(
committer
->
ctx
->
nextKey
!=
TSKEY_MAX
)
{
code
=
tsdbCommitFileSet
(
committer
);
if
(
code
)
{
lino
=
__LINE__
;
break
;
}
TSDB_CHECK_CODE
(
code
,
lino
,
_exit
);
}
code
=
tsdbCloseCommitter
(
committer
,
code
);
...
...
@@ -449,33 +470,32 @@ _exit:
return
code
;
}
int32_t
tsdbCommitCommit
(
STsdb
*
pT
sdb
)
{
int32_t
tsdbCommitCommit
(
STsdb
*
t
sdb
)
{
int32_t
code
=
0
;
int32_t
lino
=
0
;
int32_t
vid
=
TD_VID
(
pTsdb
->
pVnode
);
if
(
pT
sdb
->
imem
==
NULL
)
goto
_exit
;
if
(
t
sdb
->
imem
==
NULL
)
goto
_exit
;
SMemTable
*
pMemTable
=
pT
sdb
->
imem
;
taosThreadRwlockWrlock
(
&
pT
sdb
->
rwLock
);
code
=
tsdbFSEditCommit
(
pT
sdb
->
pFS
);
SMemTable
*
pMemTable
=
t
sdb
->
imem
;
taosThreadRwlockWrlock
(
&
t
sdb
->
rwLock
);
code
=
tsdbFSEditCommit
(
t
sdb
->
pFS
);
if
(
code
)
{
taosThreadRwlockUnlock
(
&
pT
sdb
->
rwLock
);
taosThreadRwlockUnlock
(
&
t
sdb
->
rwLock
);
TSDB_CHECK_CODE
(
code
,
lino
,
_exit
);
}
pT
sdb
->
imem
=
NULL
;
taosThreadRwlockUnlock
(
&
pT
sdb
->
rwLock
);
t
sdb
->
imem
=
NULL
;
taosThreadRwlockUnlock
(
&
t
sdb
->
rwLock
);
tsdbUnrefMemTable
(
pMemTable
,
NULL
,
true
);
// TODO: make this call async
code
=
tsdbMerge
(
pT
sdb
);
code
=
tsdbMerge
(
t
sdb
);
TSDB_CHECK_CODE
(
code
,
lino
,
_exit
);
_exit:
if
(
code
)
{
tsdbError
(
"vgId:%d, %s failed at line %d since %s"
,
vid
,
__func__
,
lino
,
tstrerror
(
code
)
);
TSDB_ERROR_LOG
(
TD_VID
(
tsdb
->
pVnode
),
lino
,
code
);
}
else
{
tsdbInfo
(
"vgId:%d %s done"
,
vid
,
__func__
);
tsdbInfo
(
"vgId:%d %s done"
,
TD_VID
(
tsdb
->
pVnode
)
,
__func__
);
}
return
code
;
}
...
...
source/dnode/vnode/src/tsdb/dev/tsdbFS.c
浏览文件 @
e99b33ed
...
...
@@ -538,9 +538,11 @@ int32_t tsdbCloseFS(STFileSystem **ppFS) {
return
0
;
}
int32_t
tsdbFSAllocEid
(
STFileSystem
*
pFS
,
int64_t
*
eid
)
{
eid
[
0
]
=
++
pFS
->
neid
;
// TODO: use atomic operation
return
0
;
int64_t
tsdbFSAllocEid
(
STFileSystem
*
fs
)
{
taosThreadRwlockRdlock
(
&
fs
->
tsdb
->
rwLock
);
int64_t
cid
=
++
fs
->
neid
;
taosThreadRwlockUnlock
(
&
fs
->
tsdb
->
rwLock
);
return
cid
;
}
int32_t
tsdbFSEditBegin
(
STFileSystem
*
fs
,
const
TFileOpArray
*
opArray
,
EFEditT
etype
)
{
...
...
source/dnode/vnode/src/tsdb/dev/tsdbFSet.c
浏览文件 @
e99b33ed
...
...
@@ -267,7 +267,7 @@ int32_t tsdbTFileSetEdit(STsdb *pTsdb, STFileSet *fset, const STFileOp *op) {
if
(
code
)
return
code
;
if
(
fobj
->
f
->
type
==
TSDB_FTYPE_STT
)
{
SSttLvl
*
lvl
=
tsdbTFileSetGetLvl
(
fset
,
fobj
->
f
->
stt
->
level
);
SSttLvl
*
lvl
=
tsdbTFileSetGet
Stt
Lvl
(
fset
,
fobj
->
f
->
stt
->
level
);
if
(
!
lvl
)
{
code
=
tsdbSttLvlInit
(
fobj
->
f
->
stt
->
level
,
&
lvl
);
if
(
code
)
return
code
;
...
...
@@ -285,7 +285,7 @@ int32_t tsdbTFileSetEdit(STsdb *pTsdb, STFileSet *fset, const STFileOp *op) {
}
else
if
(
op
->
optype
==
TSDB_FOP_REMOVE
)
{
// delete a file
if
(
op
->
of
.
type
==
TSDB_FTYPE_STT
)
{
SSttLvl
*
lvl
=
tsdbTFileSetGetLvl
(
fset
,
op
->
of
.
stt
->
level
);
SSttLvl
*
lvl
=
tsdbTFileSetGet
Stt
Lvl
(
fset
,
op
->
of
.
stt
->
level
);
ASSERT
(
lvl
);
STFileObj
tfobj
=
{.
f
[
0
]
=
{.
cid
=
op
->
of
.
cid
}};
...
...
@@ -305,7 +305,7 @@ int32_t tsdbTFileSetEdit(STsdb *pTsdb, STFileSet *fset, const STFileOp *op) {
}
}
else
{
if
(
op
->
nf
.
type
==
TSDB_FTYPE_STT
)
{
SSttLvl
*
lvl
=
tsdbTFileSetGetLvl
(
fset
,
op
->
of
.
stt
->
level
);
SSttLvl
*
lvl
=
tsdbTFileSetGet
Stt
Lvl
(
fset
,
op
->
of
.
stt
->
level
);
ASSERT
(
lvl
);
STFileObj
tfobj
=
{.
f
[
0
]
=
{.
cid
=
op
->
of
.
cid
}},
*
tfobjp
=
&
tfobj
;
...
...
@@ -463,9 +463,9 @@ int32_t tsdbTFileSetRemove(STFileSet **fset) {
return
0
;
}
SSttLvl
*
tsdbTFileSetGetLvl
(
STFileSet
*
fset
,
int32_t
level
)
{
SSttLvl
tl
vl
=
{.
level
=
level
};
SSttLvl
*
lvl
=
&
tl
vl
;
SSttLvl
*
tsdbTFileSetGet
Stt
Lvl
(
STFileSet
*
fset
,
int32_t
level
)
{
SSttLvl
sttL
vl
=
{.
level
=
level
};
SSttLvl
*
lvl
=
&
sttL
vl
;
return
TARRAY2_SEARCH_EX
(
fset
->
lvlArr
,
&
lvl
,
tsdbSttLvlCmprFn
,
TD_EQ
);
}
...
...
source/dnode/vnode/src/tsdb/dev/tsdbIter.c
浏览文件 @
e99b33ed
...
...
@@ -348,7 +348,7 @@ struct SIterMerger {
SRBTree
iterTree
[
1
];
};
int32_t
tsdbIterMerger
Init
(
const
TTsdbIterArray
*
iterArray
,
SIterMerger
**
merger
)
{
int32_t
tsdbIterMerger
Open
(
const
TTsdbIterArray
*
iterArray
,
SIterMerger
**
merger
)
{
STsdbIter
*
iter
;
SRBTreeNode
*
node
;
...
...
@@ -365,7 +365,7 @@ int32_t tsdbIterMergerInit(const TTsdbIterArray *iterArray, SIterMerger **merger
return
tsdbIterMergerNext
(
merger
[
0
]);
}
int32_t
tsdbIterMergerCl
ear
(
SIterMerger
**
merger
)
{
int32_t
tsdbIterMergerCl
ose
(
SIterMerger
**
merger
)
{
if
(
merger
[
0
])
{
taosMemoryFree
(
merger
[
0
]);
merger
[
0
]
=
NULL
;
...
...
source/dnode/vnode/src/tsdb/dev/tsdbMerge.c
浏览文件 @
e99b33ed
...
...
@@ -57,7 +57,7 @@ static int32_t tsdbMergerOpen(SMerger *merger) {
merger
->
szPage
=
merger
->
tsdb
->
pVnode
->
config
.
tsdbPageSize
;
merger
->
cmprAlg
=
merger
->
tsdb
->
pVnode
->
config
.
tsdbCfg
.
compression
;
merger
->
compactVersion
=
INT64_MAX
;
tsdbFSAllocEid
(
merger
->
tsdb
->
pFS
,
&
merger
->
cid
);
merger
->
cid
=
tsdbFSAllocEid
(
merger
->
tsdb
->
pFS
);
merger
->
ctx
->
opened
=
true
;
return
0
;
}
...
...
@@ -273,7 +273,7 @@ static int32_t tsdbMergeFileSetBeginOpenIter(SMerger *merger) {
}
}
code
=
tsdbIterMerger
Init
(
merger
->
iterArr
,
&
merger
->
iterMerger
);
code
=
tsdbIterMerger
Open
(
merger
->
iterArr
,
&
merger
->
iterMerger
);
TSDB_CHECK_CODE
(
code
,
lino
,
_exit
);
_exit:
...
...
@@ -444,7 +444,7 @@ _exit:
}
static
int32_t
tsdbMergeFileSetEndCloseIter
(
SMerger
*
merger
)
{
tsdbIterMergerCl
ear
(
&
merger
->
iterMerger
);
tsdbIterMergerCl
ose
(
&
merger
->
iterMerger
);
TARRAY2_CLEAR
(
merger
->
iterArr
,
tsdbIterClose
);
return
0
;
}
...
...
@@ -566,5 +566,5 @@ _exit:
}
else
if
(
merger
->
ctx
->
opened
)
{
tsdbDebug
(
"vgId:%d %s done"
,
vid
,
__func__
);
}
return
0
;
return
code
;
}
source/dnode/vnode/src/tsdb/dev/tsdbSttFileRW.c
浏览文件 @
e99b33ed
...
...
@@ -28,6 +28,7 @@ struct SSttFileReader {
SSttFileReaderConfig
config
[
1
];
TSttSegReaderArray
readerArray
[
1
];
STsdbFD
*
fd
;
uint8_t
*
bufArr
[
5
];
};
struct
SSttSegReader
{
...
...
@@ -87,6 +88,7 @@ int32_t tsdbSttFileReaderOpen(const char *fname, const SSttFileReaderConfig *con
if
(
reader
[
0
]
==
NULL
)
return
TSDB_CODE_OUT_OF_MEMORY
;
reader
[
0
]
->
config
[
0
]
=
config
[
0
];
if
(
!
reader
[
0
]
->
config
->
bufArr
)
reader
[
0
]
->
config
->
bufArr
=
reader
[
0
]
->
bufArr
;
// open file
code
=
tsdbOpenFile
(
fname
,
config
->
szPage
,
TD_FILE_READ
,
&
reader
[
0
]
->
fd
);
...
...
@@ -118,6 +120,9 @@ _exit:
int32_t
tsdbSttFileReaderClose
(
SSttFileReader
**
reader
)
{
if
(
reader
[
0
])
{
for
(
int32_t
i
=
0
;
i
<
ARRAY_SIZE
(
reader
[
0
]
->
bufArr
);
++
i
)
{
tFree
(
reader
[
0
]
->
bufArr
[
i
]);
}
tsdbCloseFile
(
&
reader
[
0
]
->
fd
);
TARRAY2_CLEAR_FREE
(
reader
[
0
]
->
readerArray
,
tsdbSttSegReaderClose
);
taosMemoryFree
(
reader
[
0
]);
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录