Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
21062f72
T
TDengine
项目概览
taosdata
/
TDengine
接近 2 年 前同步成功
通知
1192
Star
22018
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看板
提交
21062f72
编写于
6月 24, 2022
作者:
H
Hongze Cheng
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
more work
上级
bbf92eeb
变更
6
隐藏空白更改
内联
并排
Showing
6 changed file
with
287 addition
and
268 deletion
+287
-268
source/dnode/vnode/src/inc/tsdb.h
source/dnode/vnode/src/inc/tsdb.h
+4
-5
source/dnode/vnode/src/tsdb/tsdbCommit.c
source/dnode/vnode/src/tsdb/tsdbCommit.c
+72
-12
source/dnode/vnode/src/tsdb/tsdbFS.c
source/dnode/vnode/src/tsdb/tsdbFS.c
+72
-198
source/dnode/vnode/src/tsdb/tsdbFile.c
source/dnode/vnode/src/tsdb/tsdbFile.c
+138
-26
source/dnode/vnode/src/tsdb/tsdbReaderWriter.c
source/dnode/vnode/src/tsdb/tsdbReaderWriter.c
+1
-1
source/dnode/vnode/src/tsdb/tsdbUtil.c
source/dnode/vnode/src/tsdb/tsdbUtil.c
+0
-26
未找到文件。
source/dnode/vnode/src/inc/tsdb.h
浏览文件 @
21062f72
...
...
@@ -164,8 +164,6 @@ int32_t tGetMapData(uint8_t *p, SMapData *pMapData);
int32_t
tsdbKeyFid
(
TSKEY
key
,
int32_t
minutes
,
int8_t
precision
);
void
tsdbFidKeyRange
(
int32_t
fid
,
int32_t
minutes
,
int8_t
precision
,
TSKEY
*
minKey
,
TSKEY
*
maxKey
);
int32_t
tsdbBuildDeleteSkyline
(
SArray
*
aDelData
,
int32_t
sidx
,
int32_t
eidx
,
SArray
*
aSkyline
);
int32_t
tPutDelFileHdr
(
uint8_t
*
p
,
SDelFile
*
pDelFile
);
int32_t
tGetDelFileHdr
(
uint8_t
*
p
,
SDelFile
*
pDelFile
);
// tsdbMemTable ==============================================================================================
// SMemTable
int32_t
tsdbMemTableCreate
(
STsdb
*
pTsdb
,
SMemTable
**
ppMemTable
);
...
...
@@ -181,10 +179,11 @@ bool tsdbTbDataIterNext(STbDataIter *pIter);
typedef
enum
{
TSDB_HEAD_FILE
=
0
,
TSDB_DATA_FILE
,
TSDB_LAST_FILE
,
TSDB_SMA_FILE
}
EDataFileT
;
void
tsdbDataFileName
(
STsdb
*
pTsdb
,
SDFileSet
*
pDFileSet
,
EDataFileT
ftype
,
char
fname
[]);
int32_t
tPutDataFileHdr
(
uint8_t
*
p
,
SDFileSet
*
pSet
,
EDataFileT
ftype
);
int32_t
tPutDelFile
(
uint8_t
*
p
,
SDelFile
*
pDelFile
);
int32_t
tGetDelFile
(
uint8_t
*
p
,
SDelFile
*
pDelFile
);
int32_t
tPutDFileSet
(
uint8_t
*
p
,
SDFileSet
*
pSet
);
int32_t
tGetDFileSet
(
uint8_t
*
p
,
SDFileSet
*
pSet
);
// SDelFile
#define tsdbDelFileCreate() \
((SDelFile){ \
.maxKey = TSKEY_MIN, .minKey = TSKEY_MAX, .maxVersion = -1, .minVersion = INT64_MAX, .size = 0, .offset = 0})
void
tsdbDelFileName
(
STsdb
*
pTsdb
,
SDelFile
*
pFile
,
char
fname
[]);
// tsdbFS.c ==============================================================================================
int32_t
tsdbFSOpen
(
STsdb
*
pTsdb
,
STsdbFS
**
ppFS
);
...
...
source/dnode/vnode/src/tsdb/tsdbCommit.c
浏览文件 @
21062f72
...
...
@@ -816,6 +816,50 @@ _err:
return
code
;
}
static
int32_t
tsdbMergeMemDisk
(
SCommitter
*
pCommitter
,
STbData
*
pTbData
,
SBlockIdx
*
oBlockIdx
)
{
int32_t
code
=
0
;
STbDataIter
*
pIter
=
&
(
STbDataIter
){
0
};
TSDBROW
*
pRow
;
// create iter
tsdbTbDataIterOpen
(
pTbData
,
&
(
TSDBKEY
){.
ts
=
pCommitter
->
minKey
,
.
version
=
VERSION_MIN
},
0
,
pIter
);
pRow
==
tsdbTbDataIterGet
(
pIter
);
if
(
pRow
==
NULL
||
TSDBROW_TS
(
pRow
)
>
pCommitter
->
maxKey
)
{
return
tsdbCommitDiskData
(
pCommitter
,
oBlockIdx
);
}
// read
code
=
tsdbReadBlock
(
pCommitter
->
pReader
,
oBlockIdx
,
&
pCommitter
->
oBlockMap
,
NULL
);
if
(
code
)
goto
_err
;
// loop to merge
SBlockData
*
pBlockData
=
&
pCommitter
->
nBlockData
;
int32_t
iBlock
=
0
;
int32_t
nBlock
=
pCommitter
->
oBlockMap
.
nItem
;
tBlockDataReset
(
pBlockData
);
while
(
true
)
{
if
((
pRow
==
NULL
||
TSDBROW_TS
(
pRow
)
>
pCommitter
->
maxKey
)
&&
iBlock
>=
nBlock
)
break
;
}
while
(
iBlock
<
nBlock
)
{
/* code */
}
//
while
(
pRow
&&
TSDBROW_TS
(
pRow
)
<=
pCommitter
->
maxKey
)
{
/* code */
}
_exit:
if
(
pRow
)
pCommitter
->
nextKey
=
TMIN
(
pCommitter
->
nextKey
,
TSDBROW_TS
(
pRow
));
return
code
;
_err:
tsdbError
(
"vgId:%d tsdb merge mem disk data failed since %s"
,
TD_VID
(
pCommitter
->
pTsdb
->
pVnode
),
tstrerror
(
code
));
return
code
;
}
static
int32_t
tsdbCommitFileDataImpl
(
SCommitter
*
pCommitter
)
{
int32_t
code
=
0
;
int32_t
c
;
...
...
@@ -843,8 +887,8 @@ static int32_t tsdbCommitFileDataImpl(SCommitter *pCommitter) {
if
(
c
==
0
)
{
// merge commit
// code = tsdbMergeCommit
(pCommitter, pTbData, pBlockIdx);
//
if (code) goto _err;
code
=
tsdbMergeMemDisk
(
pCommitter
,
pTbData
,
pBlockIdx
);
if
(
code
)
goto
_err
;
iTbData
++
;
iBlockIdx
++
;
...
...
@@ -1026,14 +1070,14 @@ _exit:
}
static
void
tsdbCommitDataEnd
(
SCommitter
*
pCommitter
)
{
tMapDataClear
(
&
pCommitter
->
oBlockIdxMap
);
tMapDataClear
(
&
pCommitter
->
oBlockMap
);
tBlockClear
(
&
pCommitter
->
oBlock
);
tBlockDataClear
(
&
pCommitter
->
oBlockData
);
tMapDataClear
(
&
pCommitter
->
nBlockIdxMap
);
tMapDataClear
(
&
pCommitter
->
nBlockMap
);
tBlockClear
(
&
pCommitter
->
nBlock
);
tBlockDataClear
(
&
pCommitter
->
nBlockData
);
//
tMapDataClear(&pCommitter->oBlockIdxMap);
//
tMapDataClear(&pCommitter->oBlockMap);
//
tBlockClear(&pCommitter->oBlock);
//
tBlockDataClear(&pCommitter->oBlockData);
//
tMapDataClear(&pCommitter->nBlockIdxMap);
//
tMapDataClear(&pCommitter->nBlockMap);
//
tBlockClear(&pCommitter->nBlock);
//
tBlockDataClear(&pCommitter->nBlockData);
}
static
int32_t
tsdbCommitData
(
SCommitter
*
pCommitter
)
{
...
...
@@ -1114,7 +1158,23 @@ static int32_t tsdbCommitCache(SCommitter *pCommitter) {
}
static
int32_t
tsdbEndCommit
(
SCommitter
*
pCommitter
,
int32_t
eno
)
{
int32_t
code
=
0
;
// TODO
int32_t
code
=
0
;
STsdb
*
pTsdb
=
pCommitter
->
pTsdb
;
SMemTable
*
pMemTable
=
pTsdb
->
imem
;
if
(
eno
==
0
)
{
code
=
tsdbFSCommit
(
pTsdb
->
fs
);
}
else
{
code
=
tsdbFSRollback
(
pTsdb
->
fs
);
}
tsdbMemTableDestroy
(
pMemTable
);
pTsdb
->
imem
=
NULL
;
tsdbInfo
(
"vgId:%d tsdb end commit"
,
TD_VID
(
pTsdb
->
pVnode
));
return
code
;
_err:
tsdbError
(
"vgId:%d tsdb end commit failed since %s"
,
TD_VID
(
pTsdb
->
pVnode
),
tstrerror
(
code
));
return
code
;
}
source/dnode/vnode/src/tsdb/tsdbFS.c
浏览文件 @
21062f72
...
...
@@ -16,213 +16,77 @@
#include "tsdb.h"
// =================================================================================================
static
int32_t
tsdbDelFileToJson
(
const
void
*
pObj
,
SJson
*
pJson
)
{
int32_t
code
=
0
;
SDelFile
*
pDelFile
=
(
SDelFile
*
)
pObj
;
if
(
tjsonAddIntegerToObject
(
pJson
,
"minKey"
,
pDelFile
->
minKey
)
<
0
)
goto
_err
;
if
(
tjsonAddIntegerToObject
(
pJson
,
"maxKey"
,
pDelFile
->
maxKey
)
<
0
)
goto
_err
;
if
(
tjsonAddIntegerToObject
(
pJson
,
"minVer"
,
pDelFile
->
minVersion
)
<
0
)
goto
_err
;
if
(
tjsonAddIntegerToObject
(
pJson
,
"maxVer"
,
pDelFile
->
maxVersion
)
<
0
)
goto
_err
;
return
code
;
_err:
code
=
TSDB_CODE_OUT_OF_MEMORY
;
return
code
;
}
static
int32_t
tsdbHeadFileToJson
(
const
void
*
pObj
,
SJson
*
pJson
)
{
int32_t
code
=
0
;
SHeadFile
*
pHeadFile
=
(
SHeadFile
*
)
pObj
;
if
(
tjsonAddIntegerToObject
(
pJson
,
"size"
,
pHeadFile
->
size
)
<
0
)
goto
_err
;
if
(
tjsonAddIntegerToObject
(
pJson
,
"offset"
,
pHeadFile
->
offset
)
<
0
)
goto
_err
;
return
code
;
_err:
code
=
TSDB_CODE_OUT_OF_MEMORY
;
return
code
;
}
static
int32_t
tsdbDataFileToJson
(
const
void
*
pObj
,
SJson
*
pJson
)
{
int32_t
code
=
0
;
SDataFile
*
pDataFile
=
(
SDataFile
*
)
pObj
;
if
(
tjsonAddIntegerToObject
(
pJson
,
"size"
,
pDataFile
->
size
)
<
0
)
goto
_err
;
return
code
;
_err:
code
=
TSDB_CODE_OUT_OF_MEMORY
;
return
code
;
}
static
int32_t
tsdbLastFileToJson
(
const
void
*
pObj
,
SJson
*
pJson
)
{
int32_t
code
=
0
;
SLastFile
*
pLastFile
=
(
SLastFile
*
)
pObj
;
if
(
tjsonAddIntegerToObject
(
pJson
,
"size"
,
pLastFile
->
size
)
<
0
)
goto
_err
;
return
code
;
_err:
code
=
TSDB_CODE_OUT_OF_MEMORY
;
return
code
;
}
static
int32_t
tsdbSmaFileToJson
(
const
void
*
pObj
,
SJson
*
pJson
)
{
int32_t
code
=
0
;
SSmaFile
*
pSmaFile
=
(
SSmaFile
*
)
pObj
;
static
int32_t
tPutFSState
(
uint8_t
*
p
,
STsdbFSState
*
pState
)
{
int32_t
n
=
0
;
int8_t
hasDel
=
pState
->
pDelFile
?
1
:
0
;
uint32_t
nDFileSet
=
taosArrayGetSize
(
pState
->
aDFileSet
);
if
(
tjsonAddIntegerToObject
(
pJson
,
"size"
,
pSmaFile
->
size
)
<
0
)
goto
_err
;
return
code
;
_err:
code
=
TSDB_CODE_OUT_OF_MEMORY
;
return
code
;
}
static
int32_t
tsdbDFileSetToJson
(
const
void
*
pObj
,
SJson
*
pJson
)
{
int32_t
code
=
0
;
SDFileSet
*
pDFileSet
=
(
SDFileSet
*
)
pObj
;
if
(
tjsonAddIntegerToObject
(
pJson
,
"level"
,
pDFileSet
->
diskId
.
level
)
<
0
)
goto
_err
;
if
(
tjsonAddIntegerToObject
(
pJson
,
"id"
,
pDFileSet
->
diskId
.
id
)
<
0
)
goto
_err
;
if
(
tjsonAddIntegerToObject
(
pJson
,
"fid"
,
pDFileSet
->
fid
)
<
0
)
goto
_err
;
// if (tjsonAddObject(pJson, "head", tsdbHeadFileToJson, pDFileSet->pHeadFile) < 0) goto _err;
// if (tjsonAddObject(pJson, "data", tsdbDataFileToJson, pDFileSet->pDataFile) < 0) goto _err;
// if (tjsonAddObject(pJson, "last", tsdbLastFileToJson, pDFileSet->pLastFile) < 0) goto _err;
// if (tjsonAddObject(pJson, "sma", tsdbSmaFileToJson, pDFileSet->pSmaFile) < 0) goto _err;
return
code
;
_err:
code
=
TSDB_CODE_OUT_OF_MEMORY
;
return
code
;
}
static
int32_t
tsdbFSStateToJsonStr
(
STsdbFSState
*
pState
,
char
**
ppData
)
{
int32_t
code
=
0
;
SJson
*
pJson
=
NULL
;
pJson
=
tjsonCreateObject
();
if
(
pJson
==
NULL
)
{
code
=
TSDB_CODE_OUT_OF_MEMORY
;
goto
_err
;
}
if
(
tjsonAddObject
(
pJson
,
"DelFile"
,
tsdbDelFileToJson
,
pState
->
pDelFile
)
<
0
)
{
code
=
TSDB_CODE_OUT_OF_MEMORY
;
goto
_err
;
}
if
(
tjsonAddTArray
(
pJson
,
"DFileSet"
,
tsdbDFileSetToJson
,
pState
->
aDFileSet
)
<
0
)
{
code
=
TSDB_CODE_OUT_OF_MEMORY
;
goto
_err
;
// SDelFile
n
+=
tPutI8
(
p
?
p
+
n
:
p
,
hasDel
);
if
(
hasDel
)
{
n
+=
tPutDelFile
(
p
?
p
+
n
:
p
,
pState
->
pDelFile
);
}
*
ppData
=
tjsonToString
(
pJson
);
if
(
*
ppData
==
NULL
)
{
code
=
TSDB_CODE_OUT_OF_MEMORY
;
goto
_err
;
// SArray<SDFileSet>
n
+=
tPutU32v
(
p
?
p
+
n
:
p
,
nDFileSet
);
for
(
uint32_t
iDFileSet
=
0
;
iDFileSet
<
nDFileSet
;
iDFileSet
++
)
{
n
+=
tPutDFileSet
(
p
?
p
+
n
:
p
,
(
SDFileSet
*
)
taosArrayGet
(
pState
->
aDFileSet
,
iDFileSet
))
;
}
tjsonDelete
(
pJson
);
return
code
;
_err:
return
code
;
return
n
;
}
static
int32_t
tsdbJsonStrToFSState
(
char
*
pData
,
STsdbFSState
*
pState
)
{
int32_t
code
=
0
;
SJson
*
pJson
=
NULL
;
pJson
=
tjsonParse
(
pData
);
if
(
pJson
==
NULL
)
goto
_err
;
// if (tjsonToObject(pJson, "DelFile", tsdbJsonToDelFile, &pState->pDelFile) < 0) goto _err;
// if (tjsonToTArray(pJson, "DFIleSet", tsdbJsonToDFileSet, ) < 0) goto _err;
ASSERT
(
0
);
tjsonDelete
(
pJson
);
return
code
;
_err:
code
=
TSDB_CODE_OUT_OF_MEMORY
;
return
code
;
}
static
int32_t
tGetFSState
(
uint8_t
*
p
,
STsdbFSState
*
pState
)
{
int32_t
n
=
0
;
int8_t
hasDel
;
uint32_t
nDFileSet
;
SDFileSet
*
pSet
=
&
(
SDFileSet
){
0
};
static
int32_t
tsdbCreateEmptyCurrent
(
const
char
*
fname
,
STsdbFSState
*
pState
)
{
int32_t
code
=
0
;
int64_t
n
;
int64_t
size
;
char
*
pData
=
NULL
;
TdFilePtr
pFD
=
NULL
;
// to json str
code
=
tsdbFSStateToJsonStr
(
pState
,
&
pData
);
if
(
code
)
goto
_err
;
// create and write
pFD
=
taosOpenFile
(
fname
,
TD_FILE_WRITE
|
TD_FILE_CREATE
);
if
(
pFD
==
NULL
)
{
code
=
TAOS_SYSTEM_ERROR
(
errno
);
goto
_err
;
}
size
=
strlen
(
pData
);
n
=
taosWriteFile
(
pFD
,
pData
,
size
);
if
(
n
<
0
)
{
code
=
TAOS_SYSTEM_ERROR
(
errno
);
goto
_err
;
// SDelFile
n
+=
tGetI8
(
p
+
n
,
&
hasDel
);
if
(
hasDel
)
{
pState
->
pDelFile
=
&
pState
->
delFile
;
n
+=
tGetDelFile
(
p
+
n
,
pState
->
pDelFile
);
}
else
{
pState
->
pDelFile
=
NULL
;
}
if
(
taosFsyncFile
(
pFD
)
<
0
)
{
code
=
TAOS_SYSTEM_ERROR
(
errno
);
goto
_err
;
// SArray<SDFileSet>
taosArrayClear
(
pState
->
aDFileSet
);
n
+=
tGetU32v
(
p
+
n
,
&
nDFileSet
);
for
(
uint32_t
iDFileSet
=
0
;
iDFileSet
<
nDFileSet
;
iDFileSet
++
)
{
n
+=
tGetDFileSet
(
p
+
n
,
pSet
);
taosArrayPush
(
pState
->
aDFileSet
,
pSet
);
}
taosCloseFile
(
&
pFD
);
if
(
pData
)
taosMemoryFree
(
pData
);
return
code
;
_err:
tsdbError
(
"create empry current failed since %s"
,
tstrerror
(
code
));
if
(
pData
)
taosMemoryFree
(
pData
);
return
code
;
return
n
;
}
static
int32_t
tsdb
SaveCurrentState
(
STsdbFS
*
pFS
,
STsdbFSState
*
pState
)
{
static
int32_t
tsdb
GnrtCurrent
(
const
char
*
fname
,
STsdbFSState
*
pState
)
{
int32_t
code
=
0
;
int64_t
n
;
int64_t
size
;
char
tfname
[
TSDB_FILENAME_LEN
];
char
fname
[
TSDB_FILENAME_LEN
];
char
*
pData
=
NULL
;
uint8_t
*
pData
;
TdFilePtr
pFD
=
NULL
;
snprintf
(
tfname
,
TSDB_FILENAME_LEN
-
1
,
"%s/CURRENT.t"
,
pFS
->
pTsdb
->
path
);
snprintf
(
fname
,
TSDB_FILENAME_LEN
-
1
,
"%s/CURRENT"
,
pFS
->
pTsdb
->
path
);
// encode
code
=
tsdbFSStateToJsonStr
(
pState
,
&
pData
);
if
(
code
)
goto
_err
;
// to binary
size
=
tPutFSState
(
NULL
,
pState
)
+
sizeof
(
TSCKSUM
);
pData
=
taosMemoryMalloc
(
size
);
if
(
pData
==
NULL
)
{
code
=
TSDB_CODE_OUT_OF_MEMORY
;
goto
_err
;
}
n
=
tPutFSState
(
pData
,
pState
);
ASSERT
(
n
+
sizeof
(
TSCKSUM
)
==
size
);
taosCalcChecksumAppend
(
0
,
pData
,
size
);
// create and write
tfname
pFD
=
taosOpenFile
(
tfname
,
TD_FILE_WRITE
|
TD_FILE_CREATE
|
TD_FILE_TRUNC
);
// create and write
pFD
=
taosOpenFile
(
fname
,
TD_FILE_WRITE
|
TD_FILE_CREATE
);
if
(
pFD
==
NULL
)
{
code
=
TAOS_SYSTEM_ERROR
(
errno
);
goto
_err
;
}
size
=
strlen
(
pData
);
n
=
taosWriteFile
(
pFD
,
pData
,
size
);
if
(
n
<
0
)
{
code
=
TAOS_SYSTEM_ERROR
(
errno
);
...
...
@@ -236,18 +100,11 @@ static int32_t tsdbSaveCurrentState(STsdbFS *pFS, STsdbFSState *pState) {
taosCloseFile
(
&
pFD
);
// rename
code
=
taosRenameFile
(
tfname
,
fname
);
if
(
code
)
{
code
=
TAOS_SYSTEM_ERROR
(
code
);
goto
_err
;
}
if
(
pData
)
taosMemoryFree
(
pData
);
return
code
;
_err:
tsdbError
(
"
vgId:%d tsdb save current state failed since %s"
,
TD_VID
(
pFS
->
pTsdb
->
pVnode
)
,
tstrerror
(
code
));
tsdbError
(
"
tsdb gnrt current failed since %s"
,
tstrerror
(
code
));
if
(
pData
)
taosMemoryFree
(
pData
);
return
code
;
}
...
...
@@ -257,7 +114,7 @@ static int32_t tsdbLoadCurrentState(STsdbFS *pFS, STsdbFSState *pState) {
int64_t
size
;
int64_t
n
;
char
fname
[
TSDB_FILENAME_LEN
];
char
*
pData
=
NULL
;
uint8_t
*
pData
=
NULL
;
TdFilePtr
pFD
;
snprintf
(
fname
,
TSDB_FILENAME_LEN
-
1
,
"%s%s%s%sCURRENT"
,
tfsGetPrimaryPath
(
pFS
->
pTsdb
->
pVnode
->
pTfs
),
TD_DIRSEP
,
...
...
@@ -265,7 +122,7 @@ static int32_t tsdbLoadCurrentState(STsdbFS *pFS, STsdbFSState *pState) {
if
(
!
taosCheckExistFile
(
fname
))
{
// create an empry CURRENT file if not exists
code
=
tsdb
CreateEmpty
Current
(
fname
,
pState
);
code
=
tsdb
Gnrt
Current
(
fname
,
pState
);
if
(
code
)
goto
_err
;
}
else
{
// open the file and load
...
...
@@ -280,12 +137,11 @@ static int32_t tsdbLoadCurrentState(STsdbFS *pFS, STsdbFSState *pState) {
goto
_err
;
}
pData
=
taosMemoryMalloc
(
size
+
1
);
pData
=
taosMemoryMalloc
(
size
);
if
(
pData
==
NULL
)
{
code
=
TSDB_CODE_OUT_OF_MEMORY
;
goto
_err
;
}
pData
[
size
]
=
'\0'
;
n
=
taosReadFile
(
pFD
,
pData
,
size
);
if
(
n
<
0
)
{
...
...
@@ -293,11 +149,15 @@ static int32_t tsdbLoadCurrentState(STsdbFS *pFS, STsdbFSState *pState) {
goto
_err
;
}
if
(
!
taosCheckChecksumWhole
(
pData
,
size
))
{
code
=
TSDB_CODE_FILE_CORRUPTED
;
goto
_err
;
}
taosCloseFile
(
&
pFD
);
// decode
code
=
tsdbJsonStrToFSState
(
pData
,
pState
);
if
(
code
)
goto
_err
;
tGetFSState
(
pData
,
pState
);
}
if
(
pData
)
taosMemoryFree
(
pData
);
...
...
@@ -679,15 +539,29 @@ _err:
int32_t
tsdbFSCommit
(
STsdbFS
*
pFS
)
{
int32_t
code
=
0
;
STsdbFSState
*
pState
=
pFS
->
nState
;
char
tfname
[
TSDB_FILENAME_LEN
];
char
fname
[
TSDB_FILENAME_LEN
];
// need lock (todo)
pFS
->
nState
=
pFS
->
cState
;
pFS
->
cState
=
pState
;
// save
code
=
tsdbSaveCurrentState
(
pFS
,
pFS
->
cState
);
snprintf
(
tfname
,
TSDB_FILENAME_LEN
-
1
,
"%s%s%s%sCURRENT.t"
,
tfsGetPrimaryPath
(
pFS
->
pTsdb
->
pVnode
->
pTfs
),
TD_DIRSEP
,
pFS
->
pTsdb
->
path
,
TD_DIRSEP
);
snprintf
(
fname
,
TSDB_FILENAME_LEN
-
1
,
"%s%s%s%sCURRENT"
,
tfsGetPrimaryPath
(
pFS
->
pTsdb
->
pVnode
->
pTfs
),
TD_DIRSEP
,
pFS
->
pTsdb
->
path
,
TD_DIRSEP
);
// gnrt CURRENT.t
code
=
tsdbGnrtCurrent
(
tfname
,
pFS
->
cState
);
if
(
code
)
goto
_err
;
// rename
code
=
taosRenameFile
(
tfname
,
fname
);
if
(
code
)
{
code
=
TAOS_SYSTEM_ERROR
(
code
);
goto
_err
;
}
// apply commit on disk
code
=
tsdbFSApplyDiskChange
(
pFS
,
pFS
->
nState
,
pFS
->
cState
);
if
(
code
)
goto
_err
;
...
...
source/dnode/vnode/src/tsdb/tsdbFile.c
浏览文件 @
21062f72
...
...
@@ -15,6 +15,81 @@
#include "tsdb.h"
static
int32_t
tPutHeadFile
(
uint8_t
*
p
,
SHeadFile
*
pHeadFile
)
{
int32_t
n
=
0
;
n
+=
tPutI64v
(
p
?
p
+
n
:
p
,
pHeadFile
->
commitID
);
n
+=
tPutI64v
(
p
?
p
+
n
:
p
,
pHeadFile
->
size
);
n
+=
tPutI64v
(
p
?
p
+
n
:
p
,
pHeadFile
->
offset
);
return
n
;
}
static
int32_t
tGetHeadFile
(
uint8_t
*
p
,
SHeadFile
*
pHeadFile
)
{
int32_t
n
=
0
;
n
+=
tGetI64v
(
p
+
n
,
&
pHeadFile
->
commitID
);
n
+=
tGetI64v
(
p
+
n
,
&
pHeadFile
->
size
);
n
+=
tGetI64v
(
p
+
n
,
&
pHeadFile
->
offset
);
return
n
;
}
static
int32_t
tPutDataFile
(
uint8_t
*
p
,
SDataFile
*
pDataFile
)
{
int32_t
n
=
0
;
n
+=
tPutI64v
(
p
?
p
+
n
:
p
,
pDataFile
->
commitID
);
n
+=
tPutI64v
(
p
?
p
+
n
:
p
,
pDataFile
->
size
);
return
n
;
}
static
int32_t
tGetDataFile
(
uint8_t
*
p
,
SDataFile
*
pDataFile
)
{
int32_t
n
=
0
;
n
+=
tGetI64v
(
p
+
n
,
&
pDataFile
->
commitID
);
n
+=
tGetI64v
(
p
+
n
,
&
pDataFile
->
size
);
return
n
;
}
static
int32_t
tPutLastFile
(
uint8_t
*
p
,
SLastFile
*
pLastFile
)
{
int32_t
n
=
0
;
n
+=
tPutI64v
(
p
?
p
+
n
:
p
,
pLastFile
->
commitID
);
n
+=
tPutI64v
(
p
?
p
+
n
:
p
,
pLastFile
->
size
);
return
n
;
}
static
int32_t
tGetLastFile
(
uint8_t
*
p
,
SLastFile
*
pLastFile
)
{
int32_t
n
=
0
;
n
+=
tGetI64v
(
p
+
n
,
&
pLastFile
->
commitID
);
n
+=
tGetI64v
(
p
+
n
,
&
pLastFile
->
size
);
return
n
;
}
static
int32_t
tPutSmaFile
(
uint8_t
*
p
,
SSmaFile
*
pSmaFile
)
{
int32_t
n
=
0
;
n
+=
tPutI64v
(
p
?
p
+
n
:
p
,
pSmaFile
->
commitID
);
n
+=
tPutI64v
(
p
?
p
+
n
:
p
,
pSmaFile
->
size
);
return
n
;
}
static
int32_t
tGetSmaFile
(
uint8_t
*
p
,
SSmaFile
*
pSmaFile
)
{
int32_t
n
=
0
;
n
+=
tGetI64v
(
p
+
n
,
&
pSmaFile
->
commitID
);
n
+=
tGetI64v
(
p
+
n
,
&
pSmaFile
->
size
);
return
n
;
}
// EXPOSED APIS ==================================================
void
tsdbDataFileName
(
STsdb
*
pTsdb
,
SDFileSet
*
pDFileSet
,
EDataFileT
ftype
,
char
fname
[])
{
STfs
*
pTfs
=
pTsdb
->
pVnode
->
pTfs
;
...
...
@@ -49,27 +124,18 @@ int32_t tPutDataFileHdr(uint8_t *p, SDFileSet *pSet, EDataFileT ftype) {
int32_t
n
=
0
;
switch
(
ftype
)
{
case
TSDB_HEAD_FILE
:
{
SHeadFile
*
pHeadFile
=
&
pSet
->
fHead
;
n
+=
tPutI64
(
p
+
n
,
pHeadFile
->
commitID
);
n
+=
tPutI64
(
p
+
n
,
pHeadFile
->
size
);
n
+=
tPutI64
(
p
+
n
,
pHeadFile
->
offset
);
}
break
;
case
TSDB_DATA_FILE
:
{
SDataFile
*
pDataFile
=
&
pSet
->
fData
;
n
+=
tPutI64
(
p
+
n
,
pDataFile
->
commitID
);
n
+=
tPutI64
(
p
+
n
,
pDataFile
->
size
);
}
break
;
case
TSDB_LAST_FILE
:
{
SLastFile
*
pLastFile
=
&
pSet
->
fLast
;
n
+=
tPutI64
(
p
+
n
,
pLastFile
->
commitID
);
n
+=
tPutI64
(
p
+
n
,
pLastFile
->
size
);
}
break
;
case
TSDB_SMA_FILE
:
{
SSmaFile
*
pSmaFile
=
&
pSet
->
fSma
;
n
+=
tPutI64
(
p
+
n
,
pSmaFile
->
commitID
);
n
+=
tPutI64
(
p
+
n
,
pSmaFile
->
size
);
}
break
;
case
TSDB_HEAD_FILE
:
n
+=
tPutHeadFile
(
p
?
p
+
n
:
p
,
&
pSet
->
fHead
);
break
;
case
TSDB_DATA_FILE
:
n
+=
tPutDataFile
(
p
?
p
+
n
:
p
,
&
pSet
->
fData
);
break
;
case
TSDB_LAST_FILE
:
n
+=
tPutLastFile
(
p
?
p
+
n
:
p
,
&
pSet
->
fLast
);
break
;
case
TSDB_SMA_FILE
:
n
+=
tPutSmaFile
(
p
?
p
+
n
:
p
,
&
pSet
->
fSma
);
break
;
default:
ASSERT
(
0
);
}
...
...
@@ -77,13 +143,33 @@ int32_t tPutDataFileHdr(uint8_t *p, SDFileSet *pSet, EDataFileT ftype) {
return
n
;
}
// SHeadFile ===============================================
int32_t
tPutDFileSet
(
uint8_t
*
p
,
SDFileSet
*
pSet
)
{
int32_t
n
=
0
;
n
+=
tPutI32v
(
p
?
p
+
n
:
p
,
pSet
->
diskId
.
level
);
n
+=
tPutI32v
(
p
?
p
+
n
:
p
,
pSet
->
diskId
.
id
);
n
+=
tPutI32v
(
p
?
p
+
n
:
p
,
pSet
->
fid
);
n
+=
tPutHeadFile
(
p
?
p
+
n
:
p
,
&
pSet
->
fHead
);
n
+=
tPutDataFile
(
p
?
p
+
n
:
p
,
&
pSet
->
fData
);
n
+=
tPutLastFile
(
p
?
p
+
n
:
p
,
&
pSet
->
fLast
);
n
+=
tPutSmaFile
(
p
?
p
+
n
:
p
,
&
pSet
->
fSma
);
// SDataFile ===============================================
return
n
;
}
// SLastFile ===============================================
int32_t
tGetDFileSet
(
uint8_t
*
p
,
SDFileSet
*
pSet
)
{
int32_t
n
=
0
;
// SSmaFile ===============================================
n
+=
tGetI32v
(
p
+
n
,
&
pSet
->
diskId
.
level
);
n
+=
tGetI32v
(
p
+
n
,
&
pSet
->
diskId
.
id
);
n
+=
tGetI32v
(
p
+
n
,
&
pSet
->
fid
);
n
+=
tGetHeadFile
(
p
+
n
,
&
pSet
->
fHead
);
n
+=
tGetDataFile
(
p
+
n
,
&
pSet
->
fData
);
n
+=
tGetLastFile
(
p
+
n
,
&
pSet
->
fLast
);
n
+=
tGetSmaFile
(
p
+
n
,
&
pSet
->
fSma
);
return
n
;
}
// SDelFile ===============================================
void
tsdbDelFileName
(
STsdb
*
pTsdb
,
SDelFile
*
pFile
,
char
fname
[])
{
...
...
@@ -91,4 +177,30 @@ void tsdbDelFileName(STsdb *pTsdb, SDelFile *pFile, char fname[]) {
snprintf
(
fname
,
TSDB_FILENAME_LEN
-
1
,
"%s%s%s%sv%dver%"
PRId64
"%s"
,
tfsGetPrimaryPath
(
pTfs
),
TD_DIRSEP
,
pTsdb
->
path
,
TD_DIRSEP
,
TD_VID
(
pTsdb
->
pVnode
),
pFile
->
commitID
,
".del"
);
}
\ No newline at end of file
}
int32_t
tPutDelFile
(
uint8_t
*
p
,
SDelFile
*
pDelFile
)
{
int32_t
n
=
0
;
n
+=
tPutI64
(
p
?
p
+
n
:
p
,
pDelFile
->
minKey
);
n
+=
tPutI64
(
p
?
p
+
n
:
p
,
pDelFile
->
maxKey
);
n
+=
tPutI64v
(
p
?
p
+
n
:
p
,
pDelFile
->
minVersion
);
n
+=
tPutI64v
(
p
?
p
+
n
:
p
,
pDelFile
->
maxVersion
);
n
+=
tPutI64v
(
p
?
p
+
n
:
p
,
pDelFile
->
size
);
n
+=
tPutI64v
(
p
?
p
+
n
:
p
,
pDelFile
->
offset
);
return
n
;
}
int32_t
tGetDelFile
(
uint8_t
*
p
,
SDelFile
*
pDelFile
)
{
int32_t
n
=
0
;
n
+=
tGetI64
(
p
+
n
,
&
pDelFile
->
minKey
);
n
+=
tGetI64
(
p
+
n
,
&
pDelFile
->
maxKey
);
n
+=
tGetI64v
(
p
+
n
,
&
pDelFile
->
minVersion
);
n
+=
tGetI64v
(
p
+
n
,
&
pDelFile
->
maxVersion
);
n
+=
tGetI64v
(
p
+
n
,
&
pDelFile
->
size
);
n
+=
tGetI64v
(
p
+
n
,
&
pDelFile
->
offset
);
return
n
;
}
source/dnode/vnode/src/tsdb/tsdbReaderWriter.c
浏览文件 @
21062f72
...
...
@@ -187,7 +187,7 @@ int32_t tsdbUpdateDelFileHdr(SDelFWriter *pWriter, uint8_t **ppBuf) {
// build
memset
(
*
ppBuf
,
0
,
size
);
n
=
tPutDelFile
Hdr
(
*
ppBuf
,
pWriter
->
pFile
);
n
=
tPutDelFile
(
*
ppBuf
,
pWriter
->
pFile
);
taosCalcChecksumAppend
(
0
,
*
ppBuf
,
size
);
ASSERT
(
n
<=
size
-
sizeof
(
TSCKSUM
));
...
...
source/dnode/vnode/src/tsdb/tsdbUtil.c
浏览文件 @
21062f72
...
...
@@ -518,32 +518,6 @@ int32_t tGetDelData(uint8_t *p, void *ph) {
return
n
;
}
int32_t
tPutDelFileHdr
(
uint8_t
*
p
,
SDelFile
*
pDelFile
)
{
int32_t
n
=
0
;
n
+=
tPutI64
(
p
?
p
+
n
:
p
,
pDelFile
->
minKey
);
n
+=
tPutI64
(
p
?
p
+
n
:
p
,
pDelFile
->
maxKey
);
n
+=
tPutI64v
(
p
?
p
+
n
:
p
,
pDelFile
->
minVersion
);
n
+=
tPutI64v
(
p
?
p
+
n
:
p
,
pDelFile
->
maxVersion
);
n
+=
tPutI64v
(
p
?
p
+
n
:
p
,
pDelFile
->
size
);
n
+=
tPutI64v
(
p
?
p
+
n
:
p
,
pDelFile
->
offset
);
return
n
;
}
int32_t
tGetDelFileHdr
(
uint8_t
*
p
,
SDelFile
*
pDelFile
)
{
int32_t
n
=
0
;
n
+=
tGetI64
(
p
+
n
,
&
pDelFile
->
minKey
);
n
+=
tGetI64
(
p
+
n
,
&
pDelFile
->
maxKey
);
n
+=
tGetI64v
(
p
+
n
,
&
pDelFile
->
minVersion
);
n
+=
tGetI64v
(
p
+
n
,
&
pDelFile
->
maxVersion
);
n
+=
tGetI64v
(
p
+
n
,
&
pDelFile
->
size
);
n
+=
tGetI64v
(
p
+
n
,
&
pDelFile
->
offset
);
return
n
;
}
int32_t
tsdbKeyFid
(
TSKEY
key
,
int32_t
minutes
,
int8_t
precision
)
{
if
(
key
<
0
)
{
return
(
int
)((
key
+
1
)
/
tsTickPerMin
[
precision
]
/
minutes
-
1
);
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录