Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
17efc22b
T
TDengine
项目概览
taosdata
/
TDengine
1 年多 前同步成功
通知
1185
Star
22017
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看板
提交
17efc22b
编写于
6月 10, 2022
作者:
H
Hongze Cheng
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
refact: 1
上级
9c1b1b45
变更
11
展开全部
隐藏空白更改
内联
并排
Showing
11 changed file
with
1021 addition
and
547 deletion
+1021
-547
source/dnode/vnode/CMakeLists.txt
source/dnode/vnode/CMakeLists.txt
+1
-0
source/dnode/vnode/src/inc/tsdb.h
source/dnode/vnode/src/inc/tsdb.h
+446
-438
source/dnode/vnode/src/tsdb/tsdbCommit.c
source/dnode/vnode/src/tsdb/tsdbCommit.c
+397
-69
source/dnode/vnode/src/tsdb/tsdbFS.c
source/dnode/vnode/src/tsdb/tsdbFS.c
+54
-5
source/dnode/vnode/src/tsdb/tsdbFile.c
source/dnode/vnode/src/tsdb/tsdbFile.c
+41
-1
source/dnode/vnode/src/tsdb/tsdbOpen.c
source/dnode/vnode/src/tsdb/tsdbOpen.c
+7
-8
source/dnode/vnode/src/tsdb/tsdbRead.c
source/dnode/vnode/src/tsdb/tsdbRead.c
+4
-0
source/dnode/vnode/src/tsdb/tsdbReadImpl.c
source/dnode/vnode/src/tsdb/tsdbReadImpl.c
+2
-0
source/dnode/vnode/src/tsdb/tsdbReaderWriter.c
source/dnode/vnode/src/tsdb/tsdbReaderWriter.c
+12
-23
source/dnode/vnode/src/tsdb/tsdbUtil.c
source/dnode/vnode/src/tsdb/tsdbUtil.c
+54
-0
source/dnode/vnode/src/tsdb/tsdbWrite.c
source/dnode/vnode/src/tsdb/tsdbWrite.c
+3
-3
未找到文件。
source/dnode/vnode/CMakeLists.txt
浏览文件 @
17efc22b
...
...
@@ -44,6 +44,7 @@ target_sources(
"src/tsdb/tsdbReadImpl.c"
"src/tsdb/tsdbWrite.c"
"src/tsdb/tsdbReaderWriter.c"
"src/tsdb/tsdbUtil.c"
"src/tsdb/tsdbSnapshot.c"
# tq
...
...
source/dnode/vnode/src/inc/tsdb.h
浏览文件 @
17efc22b
此差异已折叠。
点击以展开。
source/dnode/vnode/src/tsdb/tsdbCommit.c
浏览文件 @
17efc22b
...
...
@@ -15,58 +15,51 @@
#include "tsdb.h"
typedef
struct
SCommitIter
SCommitIter
;
typedef
struct
SCommitter
SCommitter
;
typedef
struct
SCommitter
SCommitter
;
struct
SCommitter
{
SRtn
rtn
;
// retention snapshot
SFSIter
fsIter
;
// tsdb file iterator
int
niters
;
// memory iterators
SCommitIter
*
iters
;
bool
isRFileSet
;
// read and commit FSET
int32_t
fid
;
SDFileSet
*
pSet
;
SReadH
readh
;
SDFileSet
wSet
;
bool
isDFileSame
;
bool
isLFileSame
;
TSKEY
minKey
;
TSKEY
maxKey
;
SArray
*
aBlkIdx
;
// SBlockIdx array
STable
*
pTable
;
SArray
*
aSupBlk
;
// Table super-block array
SArray
*
aSubBlk
;
// table sub-block array
SDataCols
*
pDataCols
;
STsdb
*
pTsdb
;
int32_t
minutes
;
int8_t
precision
;
TSKEY
nextCommitKey
;
// commit file data
int32_t
commitFid
;
TSKEY
minKey
;
TSKEY
maxKey
;
SDFileSetReader
*
pReader
;
SDFileSetWriter
*
pWriter
;
SArray
*
aOBlockIdx
;
SArray
*
aBlockIdx
;
// commit table data
STbData
*
pTbData
;
SBlockIdx
*
pBlockIdx
;
};
static
int32_t
tsdb
CommitData
(
SCommitter
*
pCommith
);
static
int32_t
tsdbCommitD
el
(
SCommitter
*
pCommith
);
static
int32_t
tsdbCommit
Cache
(
SCommitter
*
pCommith
);
static
int32_t
tsdb
StartCommit
(
STsdb
*
pTsdb
,
SCommitter
*
pCHandle
);
static
int32_t
tsdbEndCommit
(
SCommitter
*
pC
Handle
,
in
t
eno
);
static
int32_t
tsdb
StartCommit
(
STsdb
*
pTsdb
,
SCommitter
*
pCommitter
);
static
int32_t
tsdbCommitD
ata
(
SCommitter
*
pCommitter
);
static
int32_t
tsdbCommit
Del
(
SCommitter
*
pCommitter
);
static
int32_t
tsdb
CommitCache
(
SCommitter
*
pCommitter
);
static
int32_t
tsdbEndCommit
(
SCommitter
*
pC
ommitter
,
int32_
t
eno
);
int32_t
tsdbBegin
(
STsdb
*
pTsdb
)
{
if
(
!
pTsdb
)
return
0
;
SMemTable
*
pMem
;
int32_t
code
=
0
;
if
(
tsdbMemTableCreate
(
pTsdb
,
&
pTsdb
->
mem
)
<
0
)
{
return
-
1
;
code
=
tsdbMemTableCreate
(
pTsdb
,
&
pTsdb
->
mem
);
if
(
code
)
{
goto
_err
;
}
return
0
;
return
code
;
_err:
return
code
;
}
int32_t
tsdbCommit
(
STsdb
*
pTsdb
)
{
int32_t
code
=
0
;
SCommitter
commith
=
{
0
};
SDFileSet
*
pSet
=
NULL
;
int
fid
;
ASSERT
(
pTsdb
->
imem
==
NULL
&&
pTsdb
->
mem
);
pTsdb
->
imem
=
pTsdb
->
mem
;
pTsdb
->
mem
=
NULL
;
// start commit
code
=
tsdbStartCommit
(
pTsdb
,
&
commith
);
if
(
code
)
{
...
...
@@ -102,11 +95,348 @@ _err:
return
code
;
}
#ifdef USE_NEW
// ===================================== NEW ======================================
static
int32_t
tsdbStartCommit
(
STsdb
*
pTsdb
,
SCommitter
*
pCommitter
)
{
int32_t
code
=
0
;
ASSERT
(
pTsdb
->
mem
&&
pTsdb
->
imem
==
NULL
);
// lock();
pTsdb
->
imem
=
pTsdb
->
mem
;
pTsdb
->
mem
=
NULL
;
// unlock();
pCommitter
->
pTsdb
=
pTsdb
;
return
code
;
}
static
int32_t
tsdbCommitDataStart
(
SCommitter
*
pCommitter
);
static
int32_t
tsdbCommitDataImpl
(
SCommitter
*
pCommitter
);
static
int32_t
tsdbCommitDataEnd
(
SCommitter
*
pCommitter
);
static
int32_t
tsdbCommitData
(
SCommitter
*
pCommitter
)
{
int32_t
code
=
0
;
STsdb
*
pTsdb
=
pCommitter
->
pTsdb
;
SMemTable
*
pMemTable
=
pTsdb
->
imem
;
// no data, just return
if
(
pMemTable
->
nRow
==
0
)
{
tsdbDebug
(
"vgId:%d no data to commit"
,
TD_VID
(
pTsdb
->
pVnode
));
goto
_exit
;
}
#else
// ===================================== OLD ======================================
// start
code
=
tsdbCommitDataStart
(
pCommitter
);
if
(
code
)
{
goto
_err
;
}
// commit
code
=
tsdbCommitDataImpl
(
pCommitter
);
if
(
code
)
{
goto
_err
;
}
// end
code
=
tsdbCommitDataEnd
(
pCommitter
);
if
(
code
)
{
goto
_err
;
}
_exit:
tsdbDebug
(
"vgId:%d commit TSDB data, nRow:%"
PRId64
,
TD_VID
(
pTsdb
->
pVnode
),
pMemTable
->
nRow
);
return
code
;
_err:
tsdbError
(
"vgId:%d failed to commit TSDB data since %s"
,
TD_VID
(
pTsdb
->
pVnode
),
tstrerror
(
code
));
return
code
;
}
static
int32_t
tsdbCommitDelStart
(
SCommitter
*
pCommitter
)
{
int32_t
code
=
0
;
// TODO
return
code
;
}
static
int32_t
tsdbCommitDelImpl
(
SCommitter
*
pCommitter
)
{
int32_t
code
=
0
;
// TODO
return
code
;
}
static
int32_t
tsdbCommitDelEnd
(
SCommitter
*
pCommitter
)
{
int32_t
code
=
0
;
// TODO
return
code
;
}
static
int32_t
tsdbCommitDel
(
SCommitter
*
pCommitter
)
{
int32_t
code
=
0
;
STsdb
*
pTsdb
=
pCommitter
->
pTsdb
;
SMemTable
*
pMemTable
=
pTsdb
->
imem
;
if
(
pMemTable
->
nDelOp
==
0
)
{
goto
_exit
;
}
// start
code
=
tsdbCommitDelStart
(
pCommitter
);
if
(
code
)
{
goto
_err
;
}
// impl
code
=
tsdbCommitDelImpl
(
pCommitter
);
if
(
code
)
{
goto
_err
;
}
// end
code
=
tsdbCommitDelEnd
(
pCommitter
);
if
(
code
)
{
goto
_err
;
}
_exit:
return
code
;
_err:
return
code
;
}
static
int32_t
tsdbCommitCache
(
SCommitter
*
pCommitter
)
{
int32_t
code
=
0
;
// TODO
return
code
;
}
static
int32_t
tsdbEndCommit
(
SCommitter
*
pCommitter
,
int32_t
eno
)
{
int32_t
code
=
0
;
// TODO
return
code
;
}
static
int32_t
tsdbCommitDataStart
(
SCommitter
*
pCommitter
)
{
int32_t
code
=
0
;
STsdb
*
pTsdb
=
pCommitter
->
pTsdb
;
SMemTable
*
pMemTable
=
pTsdb
->
imem
;
pCommitter
->
nextCommitKey
=
pMemTable
->
minKey
.
ts
;
return
code
;
}
static
int32_t
tsdbCommitFileData
(
SCommitter
*
pCommitter
);
static
int32_t
tsdbCommitDataImpl
(
SCommitter
*
pCommitter
)
{
int32_t
code
=
0
;
for
(;;)
{
if
(
pCommitter
->
nextCommitKey
==
TSKEY_MAX
)
break
;
pCommitter
->
commitFid
=
TSDB_KEY_FID
(
pCommitter
->
nextCommitKey
,
pCommitter
->
minutes
,
pCommitter
->
precision
);
code
=
tsdbCommitFileData
(
pCommitter
);
if
(
code
)
{
goto
_err
;
}
}
_exit:
return
code
;
_err:
return
code
;
}
static
int32_t
tsdbCommitDataEnd
(
SCommitter
*
pCommitter
)
{
int32_t
code
=
0
;
// TODO
return
code
;
}
static
int32_t
tsdbCommitFileDataStart
(
SCommitter
*
pCommitter
);
static
int32_t
tsdbCommitFileDataImpl
(
SCommitter
*
pCommitter
);
static
int32_t
tsdbCommitFileDataEnd
(
SCommitter
*
pCommitter
);
static
int32_t
tsdbCommitFileData
(
SCommitter
*
pCommitter
)
{
int32_t
code
=
0
;
// commit file data start
code
=
tsdbCommitFileDataStart
(
pCommitter
);
if
(
code
)
{
goto
_err
;
}
// commit file data impl
code
=
tsdbCommitFileDataImpl
(
pCommitter
);
if
(
code
)
{
goto
_err
;
}
// commit file data end
code
=
tsdbCommitFileDataEnd
(
pCommitter
);
if
(
code
)
{
goto
_err
;
}
return
code
;
_err:
return
code
;
}
static
int32_t
tsdbCommitFileDataStart
(
SCommitter
*
pCommitter
)
{
int32_t
code
=
0
;
STsdb
*
pTsdb
=
pCommitter
->
pTsdb
;
SDFileSet
*
pRSet
=
NULL
;
SDFileSet
*
pWSet
=
NULL
;
taosArrayClear
(
pCommitter
->
aOBlockIdx
);
taosArrayClear
(
pCommitter
->
aBlockIdx
);
// search pRSet (todo)
// open file to read
if
(
pRSet
)
{
code
=
tsdbDFileSetReaderOpen
(
pCommitter
->
pReader
,
pTsdb
,
pRSet
);
if
(
code
)
goto
_err
;
// create/open the pWSet (todo)
}
else
{
// create the pWSet (todo)
}
// open file for write
code
=
tsdbDFileSetWriterOpen
(
pCommitter
->
pWriter
,
pTsdb
,
pWSet
);
if
(
code
)
goto
_err
;
// read the SBlockIdx part for merge purpose
code
=
tsdbLoadSBlockIdx
(
pCommitter
->
pReader
,
pCommitter
->
aOBlockIdx
);
if
(
code
)
goto
_err
;
_exit:
return
code
;
_err:
return
code
;
}
static
int32_t
tsdbCommitTableData
(
SCommitter
*
pCommitter
);
static
int32_t
tsdbCommitFileDataImpl
(
SCommitter
*
pCommitter
)
{
int32_t
code
=
0
;
STsdb
*
pTsdb
=
pCommitter
->
pTsdb
;
SMemTable
*
pMemTable
=
pTsdb
->
imem
;
int32_t
iBlockIdx
=
0
;
int32_t
nBlockIdx
=
taosArrayGetSize
(
pCommitter
->
aOBlockIdx
);
int32_t
iTbData
=
0
;
int32_t
nTbData
=
taosArrayGetSize
(
pMemTable
->
aTbData
);
SBlockIdx
*
pBlockIdx
;
STbData
*
pTbData
;
while
(
iTbData
<
nTbData
||
iBlockIdx
<
nBlockIdx
)
{
pTbData
=
NULL
;
pBlockIdx
=
NULL
;
if
(
iTbData
<
nTbData
)
{
pTbData
=
(
STbData
*
)
taosArrayGetP
(
pMemTable
->
aTbData
,
iTbData
);
}
if
(
iBlockIdx
<
nBlockIdx
)
{
pBlockIdx
=
(
SBlockIdx
*
)
taosArrayGet
(
pCommitter
->
aOBlockIdx
,
iBlockIdx
);
}
if
(
pTbData
&&
pBlockIdx
)
{
int32_t
c
=
tTABLEIDCmprFn
(
pTbData
,
pBlockIdx
);
if
(
c
==
0
)
{
iTbData
++
;
iBlockIdx
++
;
}
else
if
(
c
<
0
)
{
iTbData
++
;
pBlockIdx
=
NULL
;
}
else
{
iBlockIdx
++
;
pTbData
=
NULL
;
}
}
else
{
if
(
pTbData
)
{
iTbData
++
;
}
else
{
iBlockIdx
++
;
}
}
pCommitter
->
pTbData
=
pTbData
;
pCommitter
->
pBlockIdx
=
pBlockIdx
;
code
=
tsdbCommitTableData
(
pCommitter
);
if
(
code
)
{
goto
_err
;
}
}
return
code
;
_err:
return
code
;
}
static
int32_t
tsdbCommitFileDataEnd
(
SCommitter
*
pCommitter
)
{
int32_t
code
=
0
;
// TODO
return
code
;
}
static
int32_t
tsdbCommitTableDataStart
(
SCommitter
*
pCommitter
);
static
int32_t
tsdbCommitTableDataImpl
(
SCommitter
*
pCommitter
);
static
int32_t
tsdbCommitTableDataEnd
(
SCommitter
*
pCommitter
);
static
int32_t
tsdbCommitTableData
(
SCommitter
*
pCommitter
)
{
int32_t
code
=
0
;
// start
code
=
tsdbCommitTableDataStart
(
pCommitter
);
if
(
code
)
{
goto
_err
;
}
// impl
code
=
tsdbCommitTableDataImpl
(
pCommitter
);
if
(
code
)
{
goto
_err
;
}
// end
code
=
tsdbCommitTableDataEnd
(
pCommitter
);
if
(
code
)
{
goto
_err
;
}
_exit:
return
code
;
_err:
return
code
;
}
static
int32_t
tsdbCommitTableDataStart
(
SCommitter
*
pCommitter
)
{
int32_t
code
=
0
;
// TODO
return
code
;
}
static
int32_t
tsdbCommitTableDataImpl
(
SCommitter
*
pCommitter
)
{
int32_t
code
=
0
;
// TODO
return
code
;
}
static
int32_t
tsdbCommitTableDataEnd
(
SCommitter
*
pCommitter
)
{
int32_t
code
=
0
;
// TODO
return
code
;
}
// // ===================================== OLD ======================================
#if 0
struct SCommitIter {
STable *pTable;
STbDataIter *pIter;
...
...
@@ -146,8 +476,9 @@ static int tsdbWriteBlockInfo(SCommitter *pCommih);
static int tsdbCommitMemData(SCommitter *pCommith, SCommitIter *pIter, TSKEY keyLimit, bool toData);
static int tsdbMergeMemData(SCommitter *pCommith, SCommitIter *pIter, int bidx);
static int tsdbMoveBlock(SCommitter *pCommith, int bidx);
static
int
tsdbCommitAddBlock
(
SCommitter
*
pCommith
,
const
SBlock
*
pSupBlock
,
const
SBlock
*
pSubBlocks
,
int
nSubBlocks
);
static
int
tsdbMergeBlockData
(
SCommitter
*
pCommith
,
SCommitIter
*
pIter
,
SDataCols
*
pDataCols
,
TSKEY
keyLimit
,
static int tsdbCommitAddBlock(SCommitter *pCommith, const SBlock *pSupBlock, const SBlock *pSubBlocks, int
nSubBlocks); static int tsdbMergeBlockData(SCommitter *pCommith, SCommitIter *pIter, SDataCols *pDataCols, TSKEY
keyLimit,
bool isLastOneBlock);
static void tsdbResetCommitTable(SCommitter *pCommith);
static void tsdbCloseCommitFile(SCommitter *pCommith, bool hasError);
...
...
@@ -273,28 +604,14 @@ static int tsdbApplyRtnOnFSet(STsdb *pRepo, SDFileSet *pSet, SRtn *pRtn) {
return 0;
}
void
tsdbGetRtnSnap
(
STsdb
*
pRepo
,
SRtn
*
pRtn
)
{
STsdbKeepCfg
*
pCfg
=
REPO_KEEP_CFG
(
pRepo
);
TSKEY
minKey
,
midKey
,
maxKey
,
now
;
now
=
taosGetTimestamp
(
pCfg
->
precision
);
minKey
=
now
-
pCfg
->
keep2
*
tsTickPerMin
[
pCfg
->
precision
];
midKey
=
now
-
pCfg
->
keep1
*
tsTickPerMin
[
pCfg
->
precision
];
maxKey
=
now
-
pCfg
->
keep0
*
tsTickPerMin
[
pCfg
->
precision
];
pRtn
->
minKey
=
minKey
;
pRtn
->
minFid
=
(
int
)(
TSDB_KEY_FID
(
minKey
,
pCfg
->
days
,
pCfg
->
precision
));
pRtn
->
midFid
=
(
int
)(
TSDB_KEY_FID
(
midKey
,
pCfg
->
days
,
pCfg
->
precision
));
pRtn
->
maxFid
=
(
int
)(
TSDB_KEY_FID
(
maxKey
,
pCfg
->
days
,
pCfg
->
precision
));
tsdbDebug
(
"vgId:%d, now:%"
PRId64
" minKey:%"
PRId64
" minFid:%d, midFid:%d, maxFid:%d"
,
REPO_ID
(
pRepo
),
now
,
minKey
,
pRtn
->
minFid
,
pRtn
->
midFid
,
pRtn
->
maxFid
);
}
static int32_t tsdbStartCommit(STsdb *pTsdb, SCommitter *pCHandle) {
int32_t code = 0;
tsdbInfo("vgId:%d, start to commit", REPO_ID(pTsdb));
ASSERT(pTsdb->imem == NULL && pTsdb->mem);
pTsdb->imem = pTsdb->mem;
pTsdb->mem = NULL;
if (tsdbInitCommitH(pCHandle, pTsdb) < 0) {
return -1;
}
...
...
@@ -443,7 +760,8 @@ static int32_t tsdbCommitToFileEnd(SCommitter *pCommith) {
int32_t code = 0;
STsdb *pRepo = TSDB_COMMIT_REPO(pCommith);
if
(
tsdbWriteBlockIdx
(
TSDB_COMMIT_HEAD_FILE
(
pCommith
),
pCommith
->
aBlkIdx
,
(
void
**
)(
&
(
TSDB_COMMIT_BUF
(
pCommith
))))
<
if (tsdbWriteBlockIdx(TSDB_COMMIT_HEAD_FILE(pCommith), pCommith->aBlkIdx, (void **)(&(TSDB_COMMIT_BUF(pCommith))))
<
0) {
tsdbError("vgId:%d, failed to write SBlockIdx part to FSET %d since %s", REPO_ID(pRepo), pCommith->fid,
tstrerror(terrno));
...
...
@@ -499,7 +817,8 @@ static int32_t tsdbCommitToFile(SCommitter *pCommith, SDFileSet *pSet, int fid)
break;
}
if
(
pIter
&&
pIter
->
pTable
&&
(
!
pIdx
||
(
pIter
->
pTable
->
suid
<=
pIdx
->
suid
||
pIter
->
pTable
->
uid
<=
pIdx
->
uid
)))
{
if (pIter && pIter->pTable && (!pIdx || (pIter->pTable->suid <= pIdx->suid || pIter->pTable->uid <= pIdx->uid)))
{
if (tsdbCommitToTable(pCommith, mIter) < 0) {
tsdbCloseCommitFile(pCommith, true);
// revert the file change
...
...
@@ -701,7 +1020,8 @@ static int tsdbSetAndOpenCommitFile(SCommitter *pCommith, SDFileSet *pSet, int f
pCommith->isLFileSame = false;
if (tsdbCreateDFile(pRepo, pWLastf, true, TSDB_FILE_LAST) < 0) {
tsdbError
(
"vgId:%d, failed to create file %s to commit since %s"
,
REPO_ID
(
pRepo
),
TSDB_FILE_FULL_NAME
(
pWLastf
),
tsdbError("vgId:%d, failed to create file %s to commit since %s", REPO_ID(pRepo),
TSDB_FILE_FULL_NAME(pWLastf),
tstrerror(terrno));
tsdbCloseDFileSet(pWSet);
...
...
@@ -722,7 +1042,8 @@ static int tsdbSetAndOpenCommitFile(SCommitter *pCommith, SDFileSet *pSet, int f
tsdbInitDFile(pRepo, pWSmadF, did, fid, FS_TXN_VERSION(REPO_FS(pRepo)), TSDB_FILE_SMAD);
if (tsdbCreateDFile(pRepo, pWSmadF, true, TSDB_FILE_SMAD) < 0) {
tsdbError
(
"vgId:%d, failed to create file %s to commit since %s"
,
REPO_ID
(
pRepo
),
TSDB_FILE_FULL_NAME
(
pWSmadF
),
tsdbError("vgId:%d, failed to create file %s to commit since %s", REPO_ID(pRepo),
TSDB_FILE_FULL_NAME(pWSmadF),
tstrerror(terrno));
tsdbCloseDFileSet(pWSet);
...
...
@@ -769,7 +1090,8 @@ static int tsdbSetAndOpenCommitFile(SCommitter *pCommith, SDFileSet *pSet, int f
tsdbInitDFile(pRepo, pWSmalF, did, fid, FS_TXN_VERSION(REPO_FS(pRepo)), TSDB_FILE_SMAL);
if (tsdbCreateDFile(pRepo, pWSmalF, true, TSDB_FILE_SMAL) < 0) {
tsdbError
(
"vgId:%d, failed to create file %s to commit since %s"
,
REPO_ID
(
pRepo
),
TSDB_FILE_FULL_NAME
(
pWSmalF
),
tsdbError("vgId:%d, failed to create file %s to commit since %s", REPO_ID(pRepo),
TSDB_FILE_FULL_NAME(pWSmalF),
tstrerror(terrno));
tsdbCloseDFileSet(pWSet);
...
...
@@ -1084,7 +1406,8 @@ static int tsdbComparKeyBlock(const void *arg1, const void *arg2) {
* @return int
*/
static int tsdbWriteBlockImpl(STsdb *pRepo, STable *pTable, SDFile *pDFile, SDFile *pDFileAggr, SDataCols *pDataCols,
SBlock
*
pBlock
,
bool
isLast
,
bool
isSuper
,
void
**
ppBuf
,
void
**
ppCBuf
,
void
**
ppExBuf
)
{
SBlock *pBlock, bool isLast, bool isSuper, void **ppBuf, void **ppCBuf, void **ppExBuf)
{
STsdbCfg *pCfg = REPO_CFG(pRepo);
SBlockData *pBlockData = NULL;
SAggrBlkData *pAggrBlkData = NULL;
...
...
@@ -1132,7 +1455,8 @@ static int tsdbWriteBlockImpl(STsdb *pRepo, STable *pTable, SDFile *pDFile, SDFi
&(pBlockCol->sum), &(pBlockCol->minIndex), &(pBlockCol->maxIndex),
&(pBlockCol->numOfNull));
#endif
(
*
tDataTypes
[
pDataCol
->
type
].
statisFunc
)(
pDataCols
->
bitmapMode
,
pDataCol
->
pBitmap
,
pDataCol
->
pData
,
rowsToWrite
,
(*tDataTypes[pDataCol->type].statisFunc)(pDataCols->bitmapMode, pDataCol->pBitmap, pDataCol->pData,
rowsToWrite,
&(pAggrBlkCol->min), &(pAggrBlkCol->max), &(pAggrBlkCol->sum),
&(pAggrBlkCol->minIndex), &(pAggrBlkCol->maxIndex),
&(pAggrBlkCol->numOfNull));
...
...
@@ -1314,7 +1638,8 @@ static int tsdbWriteBlockInfo(SCommitter *pCommih) {
SBlockIdx blkIdx;
STable *pTable = TSDB_COMMIT_TABLE(pCommih);
if
(
tsdbWriteBlockInfoImpl
(
pHeadf
,
pTable
,
pCommih
->
aSupBlk
,
pCommih
->
aSubBlk
,
(
void
**
)(
&
(
TSDB_COMMIT_BUF
(
pCommih
))),
if (tsdbWriteBlockInfoImpl(pHeadf, pTable, pCommih->aSupBlk, pCommih->aSubBlk, (void
**)(&(TSDB_COMMIT_BUF(pCommih))),
&blkIdx) < 0) {
return -1;
}
...
...
@@ -1430,7 +1755,8 @@ static int tsdbMergeMemData(SCommitter *pCommith, SCommitIter *pIter, int bidx)
if (tsdbCommitAddBlock(pCommith, &supBlock, subBlocks, supBlock.numOfSubBlocks) < 0) return -1;
} else {
if (tsdbLoadBlockData(&(pCommith->readh), pBlock, NULL) < 0) return -1;
if
(
tsdbMergeBlockData
(
pCommith
,
pIter
,
pCommith
->
readh
.
pDCols
[
0
],
keyLimit
,
bidx
==
(
nBlocks
-
1
))
<
0
)
return
-
1
;
if (tsdbMergeBlockData(pCommith, pIter, pCommith->readh.pDCols[0], keyLimit, bidx == (nBlocks - 1)) < 0) return
-1;
}
return 0;
...
...
@@ -1483,7 +1809,8 @@ static int tsdbMoveBlock(SCommitter *pCommith, int bidx) {
return 0;
}
static
int
tsdbCommitAddBlock
(
SCommitter
*
pCommith
,
const
SBlock
*
pSupBlock
,
const
SBlock
*
pSubBlocks
,
int
nSubBlocks
)
{
static int tsdbCommitAddBlock(SCommitter *pCommith, const SBlock *pSupBlock, const SBlock *pSubBlocks, int
nSubBlocks) {
if (taosArrayPush(pCommith->aSupBlk, pSupBlock) == NULL) {
terrno = TSDB_CODE_TDB_OUT_OF_MEMORY;
return -1;
...
...
@@ -1508,7 +1835,8 @@ static int tsdbMergeBlockData(SCommitter *pCommith, SCommitIter *pIter, SDataCol
int biter = 0;
while (true) {
tsdbLoadAndMergeFromCache
(
TSDB_COMMIT_REPO
(
pCommith
),
pCommith
->
readh
.
pDCols
[
0
],
&
biter
,
pIter
,
pCommith
->
pDataCols
,
tsdbLoadAndMergeFromCache(TSDB_COMMIT_REPO(pCommith), pCommith->readh.pDCols[0], &biter, pIter,
pCommith->pDataCols,
keyLimit, defaultRows, pCfg->update);
if (pCommith->pDataCols->numOfRows == 0) break;
...
...
source/dnode/vnode/src/tsdb/tsdbFS.c
浏览文件 @
17efc22b
...
...
@@ -15,6 +15,41 @@
#include "tsdb.h"
struct
STsdbFS
{
STsdb
*
pTsdb
;
TdThreadRwlock
lock
;
int64_t
minVersion
;
int64_t
maxVersion
;
STsdbTombstoneFile
*
pTombstoneF
;
STsdbCacheFile
*
pCacheF
;
SArray
*
pArray
;
};
int32_t
tsdbFSOpen
(
STsdb
*
pTsdb
,
STsdbFS
**
ppFS
)
{
int32_t
code
=
0
;
// TODO
return
code
;
}
int32_t
tsdbFSClose
(
STsdbFS
*
pFS
)
{
int32_t
code
=
0
;
// TODO
return
code
;
}
int32_t
tsdbFSStart
(
STsdbFS
*
pFS
)
{
int32_t
code
=
0
;
// TODO
return
code
;
}
int32_t
tsdbFSEnd
(
STsdbFS
*
pFS
,
int8_t
rollback
)
{
int32_t
code
=
0
;
// TODO
return
code
;
}
#if 0
extern const char *TSDB_LEVEL_DNAME[];
typedef enum { TSDB_TXN_TEMP_FILE = 0, TSDB_TXN_CURR_FILE } TSDB_TXN_FILE_T;
...
...
@@ -300,8 +335,6 @@ void tsdbStartFSTxn(STsdb *pRepo, int64_t pointsAdd, int64_t storageAdd) {
pfs->nstatus->meta.totalStorage = pfs->cstatus->meta.totalStorage += storageAdd;
}
void
tsdbUpdateFSTxnMeta
(
STsdbFS
*
pfs
,
STsdbFSMeta
*
pMeta
)
{
pfs
->
nstatus
->
meta
=
*
pMeta
;
}
int tsdbEndFSTxn(STsdb *pRepo) {
STsdbFS *pfs = REPO_FS(pRepo);
ASSERT(FS_IN_TXN(pfs));
...
...
@@ -334,8 +367,6 @@ int tsdbEndFSTxnWithError(STsdbFS *pfs) {
return 0;
}
// void tsdbUpdateMFile(STsdbFS *pfs, const SMFile *pMFile) { tsdbSetStatusMFile(pfs->nstatus, pMFile); }
int tsdbUpdateDFileSet(STsdbFS *pfs, const SDFileSet *pSet) { return tsdbAddDFileSetToStatus(pfs->nstatus, pSet); }
static int tsdbSaveFSStatus(STsdb *pRepo, SFSStatus *pStatus) {
...
...
@@ -1060,4 +1091,22 @@ int tsdbUnLockFS(STsdbFS *pFs) {
return -1;
}
return 0;
}
\ No newline at end of file
}
void tsdbGetRtnSnap(STsdb *pRepo, SRtn *pRtn) {
STsdbKeepCfg *pCfg = REPO_KEEP_CFG(pRepo);
TSKEY minKey, midKey, maxKey, now;
now = taosGetTimestamp(pCfg->precision);
minKey = now - pCfg->keep2 * tsTickPerMin[pCfg->precision];
midKey = now - pCfg->keep1 * tsTickPerMin[pCfg->precision];
maxKey = now - pCfg->keep0 * tsTickPerMin[pCfg->precision];
pRtn->minKey = minKey;
pRtn->minFid = (int)(TSDB_KEY_FID(minKey, pCfg->days, pCfg->precision));
pRtn->midFid = (int)(TSDB_KEY_FID(midKey, pCfg->days, pCfg->precision));
pRtn->maxFid = (int)(TSDB_KEY_FID(maxKey, pCfg->days, pCfg->precision));
tsdbDebug("vgId:%d, now:%" PRId64 " minKey:%" PRId64 " minFid:%d, midFid:%d, maxFid:%d", REPO_ID(pRepo), now, minKey,
pRtn->minFid, pRtn->midFid, pRtn->maxFid);
}
#endif
\ No newline at end of file
source/dnode/vnode/src/tsdb/tsdbFile.c
浏览文件 @
17efc22b
...
...
@@ -15,6 +15,45 @@
#include "tsdb.h"
static
const
char
*
tsdbFileSuffix
[]
=
{
".tombstone"
,
".cache"
,
".index"
,
".data"
,
".last"
,
".sma"
,
""
};
// .tombstone
struct
STsdbTombstoneFile
{
TSKEY
minKey
;
TSKEY
maxKey
;
int64_t
minVersion
;
int64_t
maxVersion
;
};
struct
STsdbIndexFile
{
int64_t
size
;
int64_t
offset
;
int32_t
nRef
;
};
struct
STsdbDataFile
{
int64_t
size
;
int32_t
nRef
;
};
struct
STsdbLastFile
{
int64_t
size
;
int32_t
nRef
;
};
struct
STsdbSmaFile
{
int64_t
size
;
int32_t
nRef
;
};
struct
SDFileSet
{
STsdbIndexFile
*
pIndexF
;
STsdbDataFile
*
pDataF
;
STsdbLastFile
*
pLastF
;
STsdbSmaFile
*
pSmaF
;
};
#if 0
static const char *TSDB_FNAME_SUFFIX[] = {
"head", // TSDB_FILE_HEAD
"data", // TSDB_FILE_DATA
...
...
@@ -579,4 +618,5 @@ int tsdbCopyDFileSet(SDFileSet *pSrc, SDFileSet *pDest) {
void tsdbGetFidKeyRange(int days, int8_t precision, int fid, TSKEY *minKey, TSKEY *maxKey) {
*minKey = fid * days * tsTickPerMin[precision];
*maxKey = *minKey + days * tsTickPerMin[precision] - 1;
}
\ No newline at end of file
}
#endif
\ No newline at end of file
source/dnode/vnode/src/tsdb/tsdbOpen.c
浏览文件 @
17efc22b
...
...
@@ -17,7 +17,6 @@
static
int
tsdbSetKeepCfg
(
STsdbKeepCfg
*
pKeepCfg
,
STsdbCfg
*
pCfg
);
// implementation
static
int
tsdbSetKeepCfg
(
STsdbKeepCfg
*
pKeepCfg
,
STsdbCfg
*
pCfg
)
{
...
...
@@ -64,13 +63,13 @@ int tsdbOpen(SVnode *pVnode, STsdb **ppTsdb, const char *dir, STsdbKeepCfg *pKee
}
else
{
memcpy
(
&
pTsdb
->
keepCfg
,
pKeepCfg
,
sizeof
(
STsdbKeepCfg
));
}
pTsdb
->
fs
=
tsdbNewFS
(
REPO_KEEP_CFG
(
pTsdb
));
//
pTsdb->fs = tsdbNewFS(REPO_KEEP_CFG(pTsdb));
// create dir (TODO: use tfsMkdir)
taosMkDir
(
pTsdb
->
path
);
// open tsdb
if
(
tsdb
OpenFS
(
pTsdb
)
<
0
)
{
if
(
tsdb
FSOpen
(
pTsdb
,
&
pTsdb
->
fs
)
<
0
)
{
goto
_err
;
}
...
...
@@ -89,8 +88,8 @@ int tsdbClose(STsdb **pTsdb) {
if
(
*
pTsdb
)
{
// TODO: destroy mem/imem
taosThreadMutexDestroy
(
&
(
*
pTsdb
)
->
mutex
);
tsdb
CloseFS
(
*
pTsdb
);
tsdbFreeFS
((
*
pTsdb
)
->
fs
);
tsdb
FSClose
((
*
pTsdb
)
->
fs
);
//
tsdbFreeFS((*pTsdb)->fs);
taosMemoryFreeClear
(
*
pTsdb
);
}
return
0
;
...
...
@@ -99,7 +98,7 @@ int tsdbClose(STsdb **pTsdb) {
int
tsdbLockRepo
(
STsdb
*
pTsdb
)
{
int
code
=
taosThreadMutexLock
(
&
pTsdb
->
mutex
);
if
(
code
!=
0
)
{
tsdbError
(
"vgId:%d, failed to lock tsdb since %s"
,
REPO_ID
(
pTsdb
),
strerror
(
errno
));
tsdbError
(
"vgId:%d, failed to lock tsdb since %s"
,
TD_VID
(
pTsdb
->
pVnode
),
strerror
(
errno
));
terrno
=
TAOS_SYSTEM_ERROR
(
code
);
return
-
1
;
}
...
...
@@ -108,11 +107,11 @@ int tsdbLockRepo(STsdb *pTsdb) {
}
int
tsdbUnlockRepo
(
STsdb
*
pTsdb
)
{
ASSERT
(
IS_REPO_LOCKED
(
pTsdb
));
//
ASSERT(IS_REPO_LOCKED(pTsdb));
pTsdb
->
repoLocked
=
false
;
int
code
=
taosThreadMutexUnlock
(
&
pTsdb
->
mutex
);
if
(
code
!=
0
)
{
tsdbError
(
"vgId:%d, failed to unlock tsdb since %s"
,
REPO_ID
(
pTsdb
),
strerror
(
errno
));
tsdbError
(
"vgId:%d, failed to unlock tsdb since %s"
,
TD_VID
(
pTsdb
->
pVnode
),
strerror
(
errno
));
terrno
=
TAOS_SYSTEM_ERROR
(
code
);
return
-
1
;
}
...
...
source/dnode/vnode/src/tsdb/tsdbRead.c
浏览文件 @
17efc22b
...
...
@@ -14,6 +14,8 @@
*/
#include "tsdb.h"
#if 0
#include "vnode.h"
#define EXTRA_BYTES 2
...
...
@@ -3725,3 +3727,5 @@ void tsdbCleanupReadHandle(tsdbReaderT queryHandle) {
taosMemoryFreeClear(pTsdbReadHandle);
}
#endif
\ No newline at end of file
source/dnode/vnode/src/tsdb/tsdbReadImpl.c
浏览文件 @
17efc22b
...
...
@@ -15,6 +15,7 @@
#include "tsdb.h"
#if 0
#define TSDB_KEY_COL_OFFSET 0
static void tsdbResetReadTable(SReadH *pReadh);
...
...
@@ -975,3 +976,4 @@ static int tsdbLoadColData(SReadH *pReadh, SDFile *pDFile, SBlock *pBlock, SBloc
return
0
;
}
#endif
\ No newline at end of file
source/dnode/vnode/src/tsdb/tsdbReaderWriter.c
浏览文件 @
17efc22b
...
...
@@ -17,22 +17,20 @@
// SDFileSetWritter ====================================================
struct
SDFileSetWritter
{
STsdb
*
pTsdb
;
SDFileSet
wSet
;
int32_t
szBuf1
;
uint8_t
*
pBuf1
;
int32_t
szBuf2
;
uint8_t
*
pBuf2
;
STsdb
*
pTsdb
;
int32_t
szBuf1
;
uint8_t
*
pBuf1
;
int32_t
szBuf2
;
uint8_t
*
pBuf2
;
};
// SDFileSetReader ====================================================
struct
SDFileSetReader
{
STsdb
*
pTsdb
;
SDFileSet
rSet
;
int32_t
szBuf1
;
uint8_t
*
pBuf1
;
int32_t
szBuf2
;
uint8_t
*
pBuf2
;
STsdb
*
pTsdb
;
int32_t
szBuf1
;
uint8_t
*
pBuf1
;
int32_t
szBuf2
;
uint8_t
*
pBuf2
;
};
int32_t
tsdbDFileSetReaderOpen
(
SDFileSetReader
*
pReader
,
STsdb
*
pTsdb
,
SDFileSet
*
pSet
)
{
...
...
@@ -40,12 +38,6 @@ int32_t tsdbDFileSetReaderOpen(SDFileSetReader *pReader, STsdb *pTsdb, SDFileSet
memset
(
pReader
,
0
,
sizeof
(
*
pReader
));
pReader
->
pTsdb
=
pTsdb
;
pReader
->
rSet
=
*
pSet
;
code
=
tsdbOpenDFileSet
(
&
pReader
->
rSet
,
TD_FILE_READ
);
if
(
code
)
{
goto
_err
;
}
return
code
;
...
...
@@ -59,7 +51,6 @@ int32_t tsdbDFileSetReaderClose(SDFileSetReader *pReader) {
taosMemoryFreeClear
(
pReader
->
pBuf1
);
taosMemoryFreeClear
(
pReader
->
pBuf2
);
tsdbCloseDFileSet
(
&
pReader
->
rSet
);
return
code
;
}
...
...
@@ -84,12 +75,10 @@ int32_t tsdbLoadSBlockStatis(SDFileSetReader *pReader, SBlock *pBlock, SBlockSta
// STombstoneFileWriter ====================================================
struct
STombstoneFileWriter
{
STsdb
*
pTsdb
;
SDFile
*
pTombstoneF
;
STsdb
*
pTsdb
;
};
// STombstoneFileReader ====================================================
struct
STombstoneFileReader
{
STsdb
*
pTsdb
;
SDFile
*
pTombstoneF
;
STsdb
*
pTsdb
;
};
source/dnode/vnode/src/tsdb/tsdbUtil.c
0 → 100644
浏览文件 @
17efc22b
/*
* Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com>
*
* This program is free software: you can use, redistribute, and/or modify
* it under the terms of the GNU Affero General Public License, version 3
* or later ("AGPL"), as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "tsdb.h"
int32_t
tTABLEIDCmprFn
(
const
void
*
p1
,
const
void
*
p2
)
{
TABLEID
*
pId1
=
(
TABLEID
*
)
p1
;
TABLEID
*
pId2
=
(
TABLEID
*
)
p2
;
if
(
pId1
->
suid
<
pId2
->
suid
)
{
return
-
1
;
}
else
if
(
pId1
->
suid
>
pId2
->
suid
)
{
return
1
;
}
if
(
pId1
->
uid
<
pId2
->
uid
)
{
return
-
1
;
}
else
if
(
pId1
->
uid
>
pId2
->
uid
)
{
return
1
;
}
return
0
;
}
int32_t
tsdbKeyCmprFn
(
const
void
*
p1
,
const
void
*
p2
)
{
TSDBKEY
*
pKey1
=
(
TSDBKEY
*
)
p1
;
TSDBKEY
*
pKey2
=
(
TSDBKEY
*
)
p2
;
if
(
pKey1
->
ts
<
pKey2
->
ts
)
{
return
-
1
;
}
else
if
(
pKey1
->
ts
>
pKey2
->
ts
)
{
return
1
;
}
if
(
pKey1
->
version
<
pKey2
->
version
)
{
return
-
1
;
}
else
if
(
pKey1
->
version
>
pKey2
->
version
)
{
return
1
;
}
return
0
;
}
\ No newline at end of file
source/dnode/vnode/src/tsdb/tsdbWrite.c
浏览文件 @
17efc22b
...
...
@@ -28,7 +28,7 @@ int tsdbInsertData(STsdb *pTsdb, int64_t version, SSubmitReq *pMsg, SSubmitRsp *
// scan and convert
if
(
tsdbScanAndConvertSubmitMsg
(
pTsdb
,
pMsg
)
<
0
)
{
if
(
terrno
!=
TSDB_CODE_TDB_TABLE_RECONFIGURE
)
{
tsdbError
(
"vgId:%d, failed to insert data since %s"
,
REPO_ID
(
pTsdb
),
tstrerror
(
terrno
));
tsdbError
(
"vgId:%d, failed to insert data since %s"
,
TD_VID
(
pTsdb
->
pVnode
),
tstrerror
(
terrno
));
}
return
-
1
;
}
...
...
@@ -77,7 +77,7 @@ static FORCE_INLINE int tsdbCheckRowRange(STsdb *pTsdb, tb_uid_t uid, STSRow *ro
if
(
rowKey
<
minKey
||
rowKey
>
maxKey
)
{
tsdbError
(
"vgId:%d, table uid %"
PRIu64
" timestamp is out of range! now %"
PRId64
" minKey %"
PRId64
" maxKey %"
PRId64
" row key %"
PRId64
,
REPO_ID
(
pTsdb
),
uid
,
now
,
minKey
,
maxKey
,
rowKey
);
TD_VID
(
pTsdb
->
pVnode
),
uid
,
now
,
minKey
,
maxKey
,
rowKey
);
terrno
=
TSDB_CODE_TDB_TIMESTAMP_OUT_OF_RANGE
;
return
-
1
;
}
...
...
@@ -92,7 +92,7 @@ int tsdbScanAndConvertSubmitMsg(STsdb *pTsdb, SSubmitReq *pMsg) {
SSubmitBlk
*
pBlock
=
NULL
;
SSubmitBlkIter
blkIter
=
{
0
};
STSRow
*
row
=
NULL
;
STsdbKeepCfg
*
pCfg
=
REPO_KEEP_CFG
(
pTsdb
)
;
STsdbKeepCfg
*
pCfg
=
&
pTsdb
->
keepCfg
;
TSKEY
now
=
taosGetTimestamp
(
pCfg
->
precision
);
TSKEY
minKey
=
now
-
tsTickPerMin
[
pCfg
->
precision
]
*
pCfg
->
keep2
;
TSKEY
maxKey
=
now
+
tsTickPerMin
[
pCfg
->
precision
]
*
pCfg
->
days
;
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录