Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
fa257f50
TDengine
项目概览
taosdata
/
TDengine
1 年多 前同步成功
通知
1185
Star
22016
Fork
4786
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
1
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
TDengine
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
1
Issue
1
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
fa257f50
编写于
8月 23, 2022
作者:
H
Hongze Cheng
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
more code
上级
1ae53f1a
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
101 addition
and
77 deletion
+101
-77
source/dnode/vnode/src/inc/tsdb.h
source/dnode/vnode/src/inc/tsdb.h
+2
-2
source/dnode/vnode/src/tsdb/tsdbCommit.c
source/dnode/vnode/src/tsdb/tsdbCommit.c
+25
-13
source/dnode/vnode/src/tsdb/tsdbFS.c
source/dnode/vnode/src/tsdb/tsdbFS.c
+31
-9
source/dnode/vnode/src/tsdb/tsdbReaderWriter.c
source/dnode/vnode/src/tsdb/tsdbReaderWriter.c
+43
-53
未找到文件。
source/dnode/vnode/src/inc/tsdb.h
浏览文件 @
fa257f50
...
...
@@ -589,13 +589,13 @@ struct SDataFWriter {
TdFilePtr
pHeadFD
;
TdFilePtr
pDataFD
;
TdFilePtr
pLastFD
;
TdFilePtr
pSmaFD
;
TdFilePtr
pLastFD
;
SHeadFile
fHead
;
SDataFile
fData
;
SLastFile
fLast
;
SSmaFile
fSma
;
SLastFile
fLast
[
TSDB_MAX_LAST_FILE
];
uint8_t
*
aBuf
[
4
];
};
...
...
source/dnode/vnode/src/tsdb/tsdbCommit.c
浏览文件 @
fa257f50
...
...
@@ -437,31 +437,43 @@ static int32_t tsdbCommitFileDataStart(SCommitter *pCommitter) {
// Writer
SHeadFile
fHead
;
SDataFile
fData
;
SLastFile
fLast
;
SSmaFile
fSma
;
SDFileSet
wSet
=
{.
pHeadF
=
&
fHead
,
.
pDataF
=
&
fData
,
.
aLastF
[
0
]
=
&
fLast
,
.
pSmaF
=
&
fSma
};
SLastFile
fLast
;
SDFileSet
wSet
=
{
0
};
if
(
pRSet
)
{
wSet
.
diskId
=
pRSet
->
diskId
;
wSet
.
fid
=
pCommitter
->
commitFid
;
wSet
.
nLastF
=
1
;
fHead
=
(
SHeadFile
){.
commitID
=
pCommitter
->
commitID
,
.
size
=
0
,
.
offset
=
0
};
ASSERT
(
pRSet
->
nLastF
<
pCommitter
->
maxLast
);
fHead
=
(
SHeadFile
){.
commitID
=
pCommitter
->
commitID
};
fData
=
*
pRSet
->
pDataF
;
fLast
=
(
SLastFile
){.
commitID
=
pCommitter
->
commitID
,
.
size
=
0
,
.
offset
=
0
};
fSma
=
*
pRSet
->
pSmaF
;
fLast
=
(
SLastFile
){.
commitID
=
pCommitter
->
commitID
};
wSet
.
diskId
=
pRSet
->
diskId
;
wSet
.
fid
=
pCommitter
->
commitFid
;
wSet
.
pHeadF
=
&
fHead
;
wSet
.
pDataF
=
&
fData
;
wSet
.
pSmaF
=
&
fSma
;
for
(
int8_t
iLast
=
0
;
iLast
<
pRSet
->
nLastF
;
iLast
++
)
{
wSet
.
aLastF
[
iLast
]
=
pRSet
->
aLastF
[
iLast
];
}
wSet
.
nLastF
=
pRSet
->
nLastF
+
1
;
wSet
.
aLastF
[
wSet
.
nLastF
-
1
]
=
&
fLast
;
// todo
}
else
{
SDiskID
did
=
{
0
};
fHead
=
(
SHeadFile
){.
commitID
=
pCommitter
->
commitID
};
fData
=
(
SDataFile
){.
commitID
=
pCommitter
->
commitID
};
fSma
=
(
SSmaFile
){.
commitID
=
pCommitter
->
commitID
};
fLast
=
(
SLastFile
){.
commitID
=
pCommitter
->
commitID
};
SDiskID
did
=
{
0
};
tfsAllocDisk
(
pTsdb
->
pVnode
->
pTfs
,
0
,
&
did
);
tfsMkdirRecurAt
(
pTsdb
->
pVnode
->
pTfs
,
pTsdb
->
path
,
did
);
wSet
.
diskId
=
did
;
wSet
.
fid
=
pCommitter
->
commitFid
;
wSet
.
pHeadF
=
&
fHead
;
wSet
.
pDataF
=
&
fData
;
wSet
.
pSmaF
=
&
fSma
;
wSet
.
nLastF
=
1
;
fHead
=
(
SHeadFile
){.
commitID
=
pCommitter
->
commitID
,
.
size
=
0
,
.
offset
=
0
};
fData
=
(
SDataFile
){.
commitID
=
pCommitter
->
commitID
,
.
size
=
0
};
fLast
=
(
SLastFile
){.
commitID
=
pCommitter
->
commitID
,
.
size
=
0
,
.
offset
=
0
};
fSma
=
(
SSmaFile
){.
commitID
=
pCommitter
->
commitID
,
.
size
=
0
};
wSet
.
aLastF
[
0
]
=
&
fLast
;
}
code
=
tsdbDataFWriterOpen
(
&
pCommitter
->
dWriter
.
pWriter
,
pTsdb
,
&
wSet
);
if
(
code
)
goto
_err
;
...
...
source/dnode/vnode/src/tsdb/tsdbFS.c
浏览文件 @
fa257f50
...
...
@@ -629,13 +629,35 @@ int32_t tsdbFSUpsertFSet(STsdbFS *pFS, SDFileSet *pSet) {
if
(
c
==
0
)
{
*
pDFileSet
->
pHeadF
=
*
pSet
->
pHeadF
;
*
pDFileSet
->
pDataF
=
*
pSet
->
pDataF
;
*
pDFileSet
->
aLastF
[
0
]
=
*
pSet
->
aLastF
[
0
];
*
pDFileSet
->
pSmaF
=
*
pSet
->
pSmaF
;
// last
if
(
pSet
->
nLastF
>
pDFileSet
->
nLastF
)
{
ASSERT
(
pSet
->
nLastF
==
pDFileSet
->
nLastF
+
1
);
pDFileSet
->
aLastF
[
pDFileSet
->
nLastF
]
=
(
SLastFile
*
)
taosMemoryMalloc
(
sizeof
(
SLastFile
));
if
(
pDFileSet
->
aLastF
[
pDFileSet
->
nLastF
]
==
NULL
)
{
code
=
TSDB_CODE_OUT_OF_MEMORY
;
goto
_exit
;
}
*
pDFileSet
->
aLastF
[
pDFileSet
->
nLastF
]
=
*
pSet
->
aLastF
[
pSet
->
nLastF
-
1
];
pDFileSet
->
nLastF
++
;
}
else
if
(
pSet
->
nLastF
<
pDFileSet
->
nLastF
)
{
ASSERT
(
pSet
->
nLastF
==
1
);
for
(
int32_t
iLast
=
1
;
iLast
<
pDFileSet
->
nLastF
;
iLast
++
)
{
taosMemoryFree
(
pDFileSet
->
aLastF
[
iLast
]);
}
*
pDFileSet
->
aLastF
[
0
]
=
*
pSet
->
aLastF
[
0
];
pDFileSet
->
nLastF
=
1
;
}
else
{
ASSERT
(
0
);
}
goto
_exit
;
}
}
ASSERT
(
pSet
->
nLastF
==
1
);
SDFileSet
fSet
=
{.
diskId
=
pSet
->
diskId
,
.
fid
=
pSet
->
fid
,
.
nLastF
=
1
};
// head
...
...
@@ -654,14 +676,6 @@ int32_t tsdbFSUpsertFSet(STsdbFS *pFS, SDFileSet *pSet) {
}
*
fSet
.
pDataF
=
*
pSet
->
pDataF
;
// last
fSet
.
aLastF
[
0
]
=
(
SLastFile
*
)
taosMemoryMalloc
(
sizeof
(
SLastFile
));
if
(
fSet
.
aLastF
[
0
]
==
NULL
)
{
code
=
TSDB_CODE_OUT_OF_MEMORY
;
goto
_exit
;
}
*
fSet
.
aLastF
[
0
]
=
*
pSet
->
aLastF
[
0
];
// sma
fSet
.
pSmaF
=
(
SSmaFile
*
)
taosMemoryMalloc
(
sizeof
(
SSmaFile
));
if
(
fSet
.
pSmaF
==
NULL
)
{
...
...
@@ -670,6 +684,14 @@ int32_t tsdbFSUpsertFSet(STsdbFS *pFS, SDFileSet *pSet) {
}
*
fSet
.
pSmaF
=
*
pSet
->
pSmaF
;
// last
fSet
.
aLastF
[
0
]
=
(
SLastFile
*
)
taosMemoryMalloc
(
sizeof
(
SLastFile
));
if
(
fSet
.
aLastF
[
0
]
==
NULL
)
{
code
=
TSDB_CODE_OUT_OF_MEMORY
;
goto
_exit
;
}
*
fSet
.
aLastF
[
0
]
=
*
pSet
->
aLastF
[
0
];
if
(
taosArrayInsert
(
pFS
->
aDFileSet
,
idx
,
&
fSet
)
==
NULL
)
{
code
=
TSDB_CODE_OUT_OF_MEMORY
;
goto
_exit
;
...
...
source/dnode/vnode/src/tsdb/tsdbReaderWriter.c
浏览文件 @
fa257f50
...
...
@@ -936,18 +936,22 @@ int32_t tsdbDataFWriterOpen(SDataFWriter **ppWriter, STsdb *pTsdb, SDFileSet *pS
code
=
TSDB_CODE_OUT_OF_MEMORY
;
goto
_err
;
}
if
(
code
)
goto
_err
;
pWriter
->
pTsdb
=
pTsdb
;
pWriter
->
wSet
=
(
SDFileSet
){.
diskId
=
pSet
->
diskId
,
.
fid
=
pSet
->
fid
,
.
pHeadF
=
&
pWriter
->
fHead
,
.
pDataF
=
&
pWriter
->
fData
,
.
aLastF
[
0
]
=
&
pWriter
->
fLast
,
.
pSmaF
=
&
pWriter
->
fSma
};
pWriter
->
wSet
=
(
SDFileSet
){
.
diskId
=
pSet
->
diskId
,
.
fid
=
pSet
->
fid
,
.
pHeadF
=
&
pWriter
->
fHead
,
.
pDataF
=
&
pWriter
->
fData
,
.
pSmaF
=
&
pWriter
->
fSma
,
.
nLastF
=
pSet
->
nLastF
//
};
pWriter
->
fHead
=
*
pSet
->
pHeadF
;
pWriter
->
fData
=
*
pSet
->
pDataF
;
pWriter
->
fLast
=
*
pSet
->
aLastF
[
0
];
pWriter
->
fSma
=
*
pSet
->
pSmaF
;
for
(
int8_t
iLast
=
0
;
iLast
<
pSet
->
nLastF
;
iLast
++
)
{
pWriter
->
wSet
.
aLastF
[
iLast
]
=
&
pWriter
->
fLast
[
iLast
];
pWriter
->
fLast
[
iLast
]
=
*
pSet
->
aLastF
[
iLast
];
}
// head
flag
=
TD_FILE_WRITE
|
TD_FILE_CREATE
|
TD_FILE_TRUNC
;
...
...
@@ -998,36 +1002,6 @@ int32_t tsdbDataFWriterOpen(SDataFWriter **ppWriter, STsdb *pTsdb, SDFileSet *pS
ASSERT
(
n
==
pWriter
->
fData
.
size
);
}
// last
if
(
pWriter
->
fLast
.
size
==
0
)
{
flag
=
TD_FILE_WRITE
|
TD_FILE_CREATE
|
TD_FILE_TRUNC
;
}
else
{
flag
=
TD_FILE_WRITE
;
}
tsdbLastFileName
(
pTsdb
,
pWriter
->
wSet
.
diskId
,
pWriter
->
wSet
.
fid
,
&
pWriter
->
fLast
,
fname
);
pWriter
->
pLastFD
=
taosOpenFile
(
fname
,
flag
);
if
(
pWriter
->
pLastFD
==
NULL
)
{
code
=
TAOS_SYSTEM_ERROR
(
errno
);
goto
_err
;
}
if
(
pWriter
->
fLast
.
size
==
0
)
{
n
=
taosWriteFile
(
pWriter
->
pLastFD
,
hdr
,
TSDB_FHDR_SIZE
);
if
(
n
<
0
)
{
code
=
TAOS_SYSTEM_ERROR
(
errno
);
goto
_err
;
}
pWriter
->
fLast
.
size
+=
TSDB_FHDR_SIZE
;
}
else
{
n
=
taosLSeekFile
(
pWriter
->
pLastFD
,
0
,
SEEK_END
);
if
(
n
<
0
)
{
code
=
TAOS_SYSTEM_ERROR
(
errno
);
goto
_err
;
}
ASSERT
(
n
==
pWriter
->
fLast
.
size
);
}
// sma
if
(
pWriter
->
fSma
.
size
==
0
)
{
flag
=
TD_FILE_WRITE
|
TD_FILE_CREATE
|
TD_FILE_TRUNC
;
...
...
@@ -1058,6 +1032,22 @@ int32_t tsdbDataFWriterOpen(SDataFWriter **ppWriter, STsdb *pTsdb, SDFileSet *pS
ASSERT
(
n
==
pWriter
->
fSma
.
size
);
}
// last
ASSERT
(
pWriter
->
fLast
[
pSet
->
nLastF
-
1
].
size
==
0
);
flag
=
TD_FILE_WRITE
|
TD_FILE_CREATE
|
TD_FILE_TRUNC
;
tsdbLastFileName
(
pTsdb
,
pWriter
->
wSet
.
diskId
,
pWriter
->
wSet
.
fid
,
&
pWriter
->
fLast
[
pSet
->
nLastF
-
1
],
fname
);
pWriter
->
pLastFD
=
taosOpenFile
(
fname
,
flag
);
if
(
pWriter
->
pLastFD
==
NULL
)
{
code
=
TAOS_SYSTEM_ERROR
(
errno
);
goto
_err
;
}
n
=
taosWriteFile
(
pWriter
->
pLastFD
,
hdr
,
TSDB_FHDR_SIZE
);
if
(
n
<
0
)
{
code
=
TAOS_SYSTEM_ERROR
(
errno
);
goto
_err
;
}
pWriter
->
fLast
[
pWriter
->
wSet
.
nLastF
-
1
].
size
+=
TSDB_FHDR_SIZE
;
*
ppWriter
=
pWriter
;
return
code
;
...
...
@@ -1085,12 +1075,12 @@ int32_t tsdbDataFWriterClose(SDataFWriter **ppWriter, int8_t sync) {
goto
_err
;
}
if
(
taosFsyncFile
((
*
ppWriter
)
->
p
Last
FD
)
<
0
)
{
if
(
taosFsyncFile
((
*
ppWriter
)
->
p
Sma
FD
)
<
0
)
{
code
=
TAOS_SYSTEM_ERROR
(
errno
);
goto
_err
;
}
if
(
taosFsyncFile
((
*
ppWriter
)
->
p
Sma
FD
)
<
0
)
{
if
(
taosFsyncFile
((
*
ppWriter
)
->
p
Last
FD
)
<
0
)
{
code
=
TAOS_SYSTEM_ERROR
(
errno
);
goto
_err
;
}
...
...
@@ -1106,12 +1096,12 @@ int32_t tsdbDataFWriterClose(SDataFWriter **ppWriter, int8_t sync) {
goto
_err
;
}
if
(
taosCloseFile
(
&
(
*
ppWriter
)
->
p
Last
FD
)
<
0
)
{
if
(
taosCloseFile
(
&
(
*
ppWriter
)
->
p
Sma
FD
)
<
0
)
{
code
=
TAOS_SYSTEM_ERROR
(
errno
);
goto
_err
;
}
if
(
taosCloseFile
(
&
(
*
ppWriter
)
->
p
Sma
FD
)
<
0
)
{
if
(
taosCloseFile
(
&
(
*
ppWriter
)
->
p
Last
FD
)
<
0
)
{
code
=
TAOS_SYSTEM_ERROR
(
errno
);
goto
_err
;
}
...
...
@@ -1168,35 +1158,35 @@ int32_t tsdbUpdateDFileSetHeader(SDataFWriter *pWriter) {
goto
_err
;
}
//
last
==============
//
sma
==============
memset
(
hdr
,
0
,
TSDB_FHDR_SIZE
);
tPut
LastFile
(
hdr
,
&
pWriter
->
fLast
);
tPut
SmaFile
(
hdr
,
&
pWriter
->
fSma
);
taosCalcChecksumAppend
(
0
,
hdr
,
TSDB_FHDR_SIZE
);
n
=
taosLSeekFile
(
pWriter
->
p
Last
FD
,
0
,
SEEK_SET
);
n
=
taosLSeekFile
(
pWriter
->
p
Sma
FD
,
0
,
SEEK_SET
);
if
(
n
<
0
)
{
code
=
TAOS_SYSTEM_ERROR
(
errno
);
goto
_err
;
}
n
=
taosWriteFile
(
pWriter
->
p
Last
FD
,
hdr
,
TSDB_FHDR_SIZE
);
n
=
taosWriteFile
(
pWriter
->
p
Sma
FD
,
hdr
,
TSDB_FHDR_SIZE
);
if
(
n
<
0
)
{
code
=
TAOS_SYSTEM_ERROR
(
errno
);
goto
_err
;
}
//
sma
==============
//
last
==============
memset
(
hdr
,
0
,
TSDB_FHDR_SIZE
);
tPut
SmaFile
(
hdr
,
&
pWriter
->
fSma
);
tPut
LastFile
(
hdr
,
&
pWriter
->
fLast
[
pWriter
->
wSet
.
nLastF
-
1
]
);
taosCalcChecksumAppend
(
0
,
hdr
,
TSDB_FHDR_SIZE
);
n
=
taosLSeekFile
(
pWriter
->
p
Sma
FD
,
0
,
SEEK_SET
);
n
=
taosLSeekFile
(
pWriter
->
p
Last
FD
,
0
,
SEEK_SET
);
if
(
n
<
0
)
{
code
=
TAOS_SYSTEM_ERROR
(
errno
);
goto
_err
;
}
n
=
taosWriteFile
(
pWriter
->
p
Sma
FD
,
hdr
,
TSDB_FHDR_SIZE
);
n
=
taosWriteFile
(
pWriter
->
p
Last
FD
,
hdr
,
TSDB_FHDR_SIZE
);
if
(
n
<
0
)
{
code
=
TAOS_SYSTEM_ERROR
(
errno
);
goto
_err
;
...
...
@@ -1309,7 +1299,7 @@ _err:
int32_t
tsdbWriteBlockL
(
SDataFWriter
*
pWriter
,
SArray
*
aBlockL
)
{
int32_t
code
=
0
;
SLastFile
*
pLastFile
=
&
pWriter
->
fLast
;
SLastFile
*
pLastFile
=
&
pWriter
->
fLast
[
pWriter
->
wSet
.
nLastF
-
1
]
;
int64_t
size
;
int64_t
n
;
...
...
@@ -1437,7 +1427,7 @@ int32_t tsdbWriteBlockData(SDataFWriter *pWriter, SBlockData *pBlockData, SBlock
ASSERT
(
pBlockData
->
nRow
>
0
);
pBlkInfo
->
offset
=
toLast
?
pWriter
->
fLast
.
size
:
pWriter
->
fData
.
size
;
pBlkInfo
->
offset
=
toLast
?
pWriter
->
fLast
[
pWriter
->
wSet
.
nLastF
-
1
]
.
size
:
pWriter
->
fData
.
size
;
pBlkInfo
->
szBlock
=
0
;
pBlkInfo
->
szKey
=
0
;
...
...
@@ -1481,7 +1471,7 @@ int32_t tsdbWriteBlockData(SDataFWriter *pWriter, SBlockData *pBlockData, SBlock
// update info
if
(
toLast
)
{
pWriter
->
fLast
.
size
+=
pBlkInfo
->
szBlock
;
pWriter
->
fLast
[
pWriter
->
wSet
.
nLastF
-
1
]
.
size
+=
pBlkInfo
->
szBlock
;
}
else
{
pWriter
->
fData
.
size
+=
pBlkInfo
->
szBlock
;
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录